import {z} from 'zod' export type CreateApiProfileByCustomIdClientIdCustomIdArgs = {client_id: string, custom_id: string, body: {nickname?: string | undefined, custom_data?: string | undefined, attributes?: Array<{key: string, value: string}> | undefined}}; export type CreateApiProfileByCustomIdClientIdCustomIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiProfileByCustomIdClientIdCustomIdResponse = z.object({created_at: z.string().optional(), client_id: z.string().optional(), redemption_keys_url: z.string().optional(), custom_id: z.string().optional(), attributes: z.array(z.unknown()).optional(), url: z.string().optional(), leaderboards_url: z.string().optional(), leaderboard_views_url: z.string().optional(), access_token: z.string().optional(), reward_item_balances_url: z.string().optional(), blocked_profile_ids_url: z.string().optional(), reward_item_credit_url: z.string().optional(), nickname: z.string().optional(), reward_item_debit_url: z.string().optional(), block_profile_url: z.string().optional(), reward_item_transfer_url: z.string().optional(), badge_progress_url: z.string().optional(), custom_data: z.unknown(), badges_url: z.string().optional(), points: z.number().int().optional(), badges: z.array(z.unknown()).optional(), reported_count: z.number().int().optional(), subscribe_channel: z.string().optional(), id: z.string().optional(), chat_room_memberships_url: z.string().optional(), chat_room_invitations_url_template: z.string().optional(), blocked_profiles_template_url: 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 }; /** * Create Profile by Custom ID * * POST /profile-by-custom-id/{client_id}/{custom_id}/ */ export const createApiProfileByCustomIdClientIdCustomId = async (args: CreateApiProfileByCustomIdClientIdCustomIdArgs, options?: CreateApiProfileByCustomIdClientIdCustomIdOptions) => { const {baseUrl = "https://cf-blast.livelikecdn.com/api/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/profile-by-custom-id/${encodeURIComponent(String(args.client_id))}/${encodeURIComponent(String(args.custom_id))}/${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(createApiProfileByCustomIdClientIdCustomIdResponse, await res.json()) };