-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathedge-api.ts
More file actions
102 lines (95 loc) · 2.79 KB
/
edge-api.ts
File metadata and controls
102 lines (95 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { createLogger } from "@aklinker1/logger";
import { ExtensionStoreName } from "../enums";
import { buildScreenshotUrl } from "../utils/urls";
import { FetchError } from "../utils/errors";
const logger = createLogger("edge-api");
export interface EdgeApi {
getAddon(crxid: string): Promise<Gql.EdgeAddon>;
}
export function createEdgeApi(): EdgeApi {
const toGqlEdgeAddon = (
res: GetProductDetailsByCrxId200Response,
): Gql.EdgeAddon => ({
id: res.crxId,
productId: res.storeProductId,
iconUrl: `https:${res.logoUrl}`, // URL without the schema (ex: "//store-images.s-microsoft.com/image/...")
lastUpdated: new Date(res.lastUpdateDate * 1000).toISOString(),
longDescription: res.description,
shortDescription: res.shortDescription,
name: res.name,
rating: res.averageRating,
reviewCount: res.ratingCount,
version: res.version,
users: res.activeInstallCount,
activeInstallCount: res.activeInstallCount,
storeUrl: `https://microsoftedge.microsoft.com/addons/detail/${res.crxId}`,
screenshots: res.screenshots.map((ss, i) => ({
index: i,
indexUrl: buildScreenshotUrl(
ExtensionStoreName.EdgeAddonStore,
res.crxId,
i,
),
rawUrl: `https:${ss.uri}`, // URL without the schema (ex: "//store-images.s-microsoft.com/image/...")
})),
});
const getAddon: EdgeApi["getAddon"] = async (crxid) => {
logger.info("Get addon", { crxid });
const res = await fetch(
`https://microsoftedge.microsoft.com/addons/getproductdetailsbycrxid/${crxid}`,
);
if (res.status !== 200) throw new FetchError(res, await res.text());
const json = (await res.json()) as GetProductDetailsByCrxId200Response;
logger.debug("Addon result", { crxid, json });
return toGqlEdgeAddon(json);
};
return {
getAddon,
};
}
type GetProductDetailsByCrxId200Response = {
availability: string[];
activeInstallCount: number;
storeProductId: string;
name: string;
logoUrl: string;
thumbnailUrl: string;
description: string;
developer: string;
category: string;
isInstalled: boolean;
crxId: string;
manifest: string;
isHavingMatureContent: boolean;
version: string;
lastUpdateDate: number;
privacyUrl: string;
availabilityId: string;
skuId: string;
locale: string;
market: string;
averageRating: number;
ratingCount: number;
availableLanguages: string[];
metadata: {
publisherId: string;
};
shortDescription: string;
searchKeywords: string;
screenshots: Array<{
caption: string;
imagePurpose: string;
uri: string;
}>;
videos: unknown[];
largePromotionImage: {
caption: string;
imagePurpose: string;
uri: string;
};
publisherWebsiteUri: string;
isBadgedAsFeatured: boolean;
privacyData: {
privacyPolicyRequired: boolean;
};
};