import {z} from 'zod' export type CreateApiYOURAUTHENTICATEPLAYERENDPOINTArgs = {'x-publisher-token'?: string | undefined, signature?: string | undefined, body: {authMethod?: ('facebook' | 'apple' | 'google' | 'userToken' | 'userPassword' | 'otp') | undefined, token?: (string | null) | undefined, date?: string | undefined, appId?: string | undefined, userName?: (string | null) | undefined, password?: (string | null) | undefined, otp?: ({playerCode?: string | undefined, accessToken?: string | undefined} | null) | undefined, os?: ('ios' | 'android' | 'web') | undefined, utmSource?: string | undefined, utmMedium?: string | undefined, utmCampaign?: string | undefined, sessionId?: string | undefined, playerLocation?: ({countryCode2?: string | undefined, playerIp?: string | undefined, state?: string | undefined}) | undefined}}; export type CreateApiYOURAUTHENTICATEPLAYERENDPOINTOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiYOURAUTHENTICATEPLAYERENDPOINTResponse = z.object({status: z.literal("valid"), playerProfileImage: z.string().optional(), publisherPlayerId: z.string(), playerName: z.string(), sessionMetadata: z.object({}).optional(), publisherErrorMessageType: z.enum(["none", "plainText", "enrichedText"]).optional(), publisherErrorMessage: z.string().optional(), publisherErrorMessageTitle: z.string().optional(), playerOverrideCountry: z.string().optional()}); 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 }; /** * Authenticate Player * * POST /{YOUR_AUTHENTICATE_PLAYER_ENDPOINT} */ export const createApiYOURAUTHENTICATEPLAYERENDPOINT = async (args: CreateApiYOURAUTHENTICATEPLAYERENDPOINTArgs, options: CreateApiYOURAUTHENTICATEPLAYERENDPOINTOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['x-publisher-token'] != null) headers.set("x-publisher-token", String(args['x-publisher-token'])) if (args.signature != null) headers.set("signature", String(args.signature)) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.YOUR_AUTHENTICATE_PLAYER_ENDPOINT))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(createApiYOURAUTHENTICATEPLAYERENDPOINTResponse, await res.json()) };