import {z} from 'zod' export type PWAStoreEnum = 'App Store' | 'Google Play'; export type ScreenshotRefDTO = {assetId?: (string | null) | undefined, key?: (string | null) | undefined}; export type UpdatePWADTO = {pwaName?: (string | null) | undefined, store?: (PWAStoreEnum | null) | undefined, systemName?: (string | null) | undefined, pwaLanguage?: (string | null) | undefined, forceLanguage?: (string | null) | undefined, tagsList?: (Array | null) | undefined, developer?: (string | null) | undefined, verified?: (boolean | null) | undefined, ad?: (boolean | null) | undefined, purchase?: (boolean | null) | undefined, editorsChoice?: (boolean | null) | undefined, rating?: (number | null) | undefined, ratingAbove5?: (number | null) | undefined, ratingAbove4?: (number | null) | undefined, ratingAbove3?: (number | null) | undefined, ratingAbove2?: (number | null) | undefined, ratingAbove1?: (number | null) | undefined, reviewsCount?: (number | null) | undefined, downloadCount?: (number | null) | undefined, ageRating?: (number | null) | undefined, description?: (string | null) | undefined, version?: (string | null) | undefined, releasedAt?: (string | null) | undefined, androidVersion?: (number | null) | undefined, interactiveElements?: (string | null) | undefined, whatsNew?: (string | null) | undefined, categoryList?: (Array | null) | undefined, safetyDescription?: (string | null) | undefined, dataTransfer?: (string | null) | undefined, dataCollection?: (string | null) | undefined, dataEncryption?: (string | null) | undefined, dataDeletion?: (string | null) | undefined, appSize?: (string | null) | undefined, comments?: (Array<{[key: string]: unknown}> | null) | undefined, userComment?: (string | null) | undefined, updatedAppAt?: (string | null) | undefined, logoAssetId?: (string | null) | undefined, backgroundAssetId?: (string | null) | undefined, removeLogo?: boolean | undefined, removeBackground?: boolean | undefined, screenshots?: (Array | null) | undefined}; export type PatchApiApiV1PwaUpdatePwaIdArgs = {pwa_id: string, body: UpdatePWADTO}; export type PatchApiApiV1PwaUpdatePwaIdOptions = {baseUrl: string, OAuth2PasswordBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const patchApiApiV1PwaUpdatePwaIdResponse = z.unknown(); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Update PWA * * PATCH /api/v1/pwa/update/{pwa_id} */ export const patchApiApiV1PwaUpdatePwaId = async (args: PatchApiApiV1PwaUpdatePwaIdArgs, options: PatchApiApiV1PwaUpdatePwaIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, OAuth2PasswordBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (OAuth2PasswordBearer !== undefined) headers.set('authorization', `Bearer ${OAuth2PasswordBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/pwa/update/${encodeURIComponent(String(args.pwa_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(patchApiApiV1PwaUpdatePwaIdResponse, await res.json()) };