import {z} from 'zod' export type GetApiV5PersonsPersonIdShareablesArgs = {person_id: string, labels?: Array | undefined, data_keys?: Array | undefined, data_values?: Array | undefined, offset?: number | undefined, limit?: number | undefined}; export type GetApiV5PersonsPersonIdShareablesOptions = {baseUrl?: string | undefined, HEADER?: string | undefined, fetch?: typeof fetch | undefined}; export const personShareableContentResponse = z.object({description: z.string().optional(), image_url: z.string().optional(), partner_content_id: z.string().optional(), title: z.string().optional(), url: z.string().optional()}); export const zonedDateTime = z.string(); export const personShareableDataResponse = z.object({name: z.string().optional(), value: z.object({}).optional()}); export const personShareableResponse = z.object({code: z.string(), content: personShareableContentResponse, created_date: zonedDateTime, data: z.record(z.string(), personShareableDataResponse), key: z.string(), label: z.string(), link: z.string(), updated_date: zonedDateTime}); export const getApiV5PersonsPersonIdShareablesResponse = z.array(personShareableResponse); 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 person shareables * * GET /v5/persons/{person_id}/shareables * * Also accepts auth: QUERY, COOKIE */ export const getApiV5PersonsPersonIdShareables = async (args: GetApiV5PersonsPersonIdShareablesArgs, options?: GetApiV5PersonsPersonIdShareablesOptions) => { const {baseUrl = "https://api.extole.io", fetch: fetchFn = fetch, HEADER} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.labels ?? []) query.append("labels", String(item)) for (const item of args.data_keys ?? []) query.append("data_keys", String(item)) for (const item of args.data_values ?? []) query.append("data_values", String(item)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (HEADER !== undefined) headers.set("Authorization", HEADER) const url = `${baseUrl.replace(/\/+$/, '')}/v5/persons/${encodeURIComponent(String(args.person_id))}/shareables${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(getApiV5PersonsPersonIdShareablesResponse, await res.json()) };