|
| 1 | +import { buildScreenshotUrl } from "../urls"; |
| 2 | + |
| 3 | +export interface EdgeApi { |
| 4 | + getAddon(crxid: string): Promise<Gql.EdgeAddon>; |
| 5 | +} |
| 6 | + |
| 7 | +export function createEdgeApi(): EdgeApi { |
| 8 | + const toGqlEdgeAddon = ( |
| 9 | + res: GetProductDetailsByCrxId200Response, |
| 10 | + ): Gql.EdgeAddon => ({ |
| 11 | + id: res.crxId, |
| 12 | + iconUrl: `https:${res.logoUrl}`, // URL without the schema (ex: "//store-images.s-microsoft.com/image/...") |
| 13 | + lastUpdated: new Date(res.lastUpdateDate * 1000).toISOString(), |
| 14 | + longDescription: res.description, |
| 15 | + shortDescription: res.shortDescription, |
| 16 | + name: res.name, |
| 17 | + rating: res.averageRating, |
| 18 | + reviewCount: res.ratingCount, |
| 19 | + version: res.version, |
| 20 | + users: res.activeInstallCount, |
| 21 | + activeInstallCount: res.activeInstallCount, |
| 22 | + storeUrl: `https://microsoftedge.microsoft.com/addons/detail/${res.crxId}`, |
| 23 | + screenshots: res.screenshots.map((ss, i) => ({ |
| 24 | + index: i, |
| 25 | + indexUrl: buildScreenshotUrl("edge-addons", res.crxId, i), |
| 26 | + rawUrl: `https:${ss.uri}`, // URL without the schema (ex: "//store-images.s-microsoft.com/image/...") |
| 27 | + })), |
| 28 | + }); |
| 29 | + |
| 30 | + const getAddon: EdgeApi["getAddon"] = async (crxid) => { |
| 31 | + const res = await fetch( |
| 32 | + `https://microsoftedge.microsoft.com/addons/getproductdetailsbycrxid/${crxid}`, |
| 33 | + ); |
| 34 | + if (res.status !== 200) { |
| 35 | + throw Error("Edge API request failed", { cause: res }); |
| 36 | + } |
| 37 | + |
| 38 | + const json = (await res.json()) as GetProductDetailsByCrxId200Response; |
| 39 | + |
| 40 | + return toGqlEdgeAddon(json); |
| 41 | + }; |
| 42 | + |
| 43 | + return { |
| 44 | + getAddon, |
| 45 | + }; |
| 46 | +} |
| 47 | + |
| 48 | +type GetProductDetailsByCrxId200Response = { |
| 49 | + availability: string[]; |
| 50 | + activeInstallCount: number; |
| 51 | + storeProductId: string; |
| 52 | + name: string; |
| 53 | + logoUrl: string; |
| 54 | + thumbnailUrl: string; |
| 55 | + description: string; |
| 56 | + developer: string; |
| 57 | + category: string; |
| 58 | + isInstalled: boolean; |
| 59 | + crxId: string; |
| 60 | + manifest: string; |
| 61 | + isHavingMatureContent: boolean; |
| 62 | + version: string; |
| 63 | + lastUpdateDate: number; |
| 64 | + privacyUrl: string; |
| 65 | + availabilityId: string; |
| 66 | + skuId: string; |
| 67 | + locale: string; |
| 68 | + market: string; |
| 69 | + averageRating: number; |
| 70 | + ratingCount: number; |
| 71 | + availableLanguages: string[]; |
| 72 | + metadata: { |
| 73 | + publisherId: string; |
| 74 | + }; |
| 75 | + shortDescription: string; |
| 76 | + searchKeywords: string; |
| 77 | + screenshots: Array<{ |
| 78 | + caption: string; |
| 79 | + imagePurpose: string; |
| 80 | + uri: string; |
| 81 | + }>; |
| 82 | + videos: unknown[]; |
| 83 | + largePromotionImage: { |
| 84 | + caption: string; |
| 85 | + imagePurpose: string; |
| 86 | + uri: string; |
| 87 | + }; |
| 88 | + publisherWebsiteUri: string; |
| 89 | + isBadgedAsFeatured: boolean; |
| 90 | + privacyData: { |
| 91 | + privacyPolicyRequired: boolean; |
| 92 | + }; |
| 93 | +}; |
0 commit comments