import {z} from 'zod' export type GetApiV1ApplicationsApplicationIdProfileIntegrationIdFriendsArgs = {pageSize?: number | undefined, skip?: number | undefined, sort?: string | undefined, applicationId: number, withTotalResultSize?: boolean | undefined, integrationId: string}; export type GetApiV1ApplicationsApplicationIdProfileIntegrationIdFriendsOptions = {baseUrl?: string | undefined, managerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const applicationReferee = z.object({applicationId: z.number().int(), sessionId: z.string(), advancedEventIntegrationId: z.string().max(1000).optional(), advocateIntegrationId: z.string().max(1000), friendIntegrationId: z.string().max(1000), code: z.string(), created: z.string()}); export const getApiV1ApplicationsApplicationIdProfileIntegrationIdFriendsResponse = z.object({hasMore: z.boolean().optional(), totalResultSize: z.number().int().optional(), data: z.array(applicationReferee)}); 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 }; /** * List friends referred by customer profile * * GET /v1/applications/{applicationId}/profile/{integrationId}/friends * * Also accepts auth: management_key */ export const getApiV1ApplicationsApplicationIdProfileIntegrationIdFriends = async (args: GetApiV1ApplicationsApplicationIdProfileIntegrationIdFriendsArgs, options?: GetApiV1ApplicationsApplicationIdProfileIntegrationIdFriendsOptions) => { const {baseUrl = "https://yourbaseurl.talon.one", fetch: fetchFn = fetch, managerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.skip != null) query.append("skip", String(args.skip)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.withTotalResultSize != null) query.append("withTotalResultSize", String(args.withTotalResultSize)) if (managerAuth !== undefined) headers.set("Authorization", managerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/applications/${encodeURIComponent(String(args.applicationId))}/profile/${encodeURIComponent(String(args.integrationId))}/friends${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV1ApplicationsApplicationIdProfileIntegrationIdFriendsResponse, await res.json()) };