web/src/utils/fetch-ios-info.ts
73 lines · 2026 bytes
1import { error } from './logger';
2import { safeFetch } from './safe-fetch';
3import { apiBase, enrichHeaders } from './api-config';
4
5// Pull the id from an App Store URL's `/id123` segment, else pass it through.
6const extractId = (iosUrl: string): string => {
7 const match = iosUrl.match(/\/id(\d+)/);
8 return match ? match[1] : iosUrl;
9};
10
11export const fetchIosInfo = async (
12 iosUrl: string,
13): Promise<IoSApiResponse | null> => {
14 const endpoint = `${apiBase}/v1/enrich/ios/${extractId(iosUrl)}`;
15 try {
16 const res = await safeFetch(endpoint, { headers: enrichHeaders() });
17 if (!res.ok) {
18 error('iOS', `HTTP ${res.status} for ${iosUrl} (${endpoint})`);
19 return null;
20 }
21 return await res.json();
22 } catch (err) {
23 error('iOS', `Network error for ${iosUrl}: ${err}`);
24 return null;
25 }
26};
27
28export interface IoSApiResponse {
29 artistViewUrl: string;
30 releaseNotes: string;
31 artworkUrl60: string;
32 artworkUrl100: string;
33 artworkUrl512: string;
34 supportedDevices: string[];
35 features: string[];
36 screenshotUrls: string[];
37 ipadScreenshotUrls: string[];
38 appletvScreenshotUrls: string[];
39 advisories: string[];
40 isGameCenterEnabled: boolean;
41 kind: string;
42 fileSizeBytes: number;
43 sellerUrl: string;
44 formattedPrice: string;
45 userRatingCountForCurrentVersion: number;
46 trackContentRating: string;
47 trackCensoredName: string;
48 trackViewUrl: string;
49 contentAdvisoryRating: string;
50 artistId: number;
51 artistName: string;
52 genres: string[];
53 price: number;
54 trackId: number;
55 trackName: string;
56 description: string;
57 currentVersionReleaseDate: string;
58 averageUserRatingForCurrentVersion: number;
59 isVppDeviceBasedLicensingEnabled: boolean;
60 genreIds: string[];
61 sellerName: string;
62 languageCodesISO2A: string[];
63 releaseDate: string;
64 bundleId: string;
65 currency: string;
66 averageUserRating: number;
67 minimumOsVersion: string;
68 primaryGenreName: string;
69 primaryGenreId: number;
70 version: string;
71 wrapperType: string;
72 userRatingCount: number;
73}