import {z} from 'zod' export type GetApiUserProfileV1UsersArgs = {'external-id'?: string | undefined, 'privacy-notice'?: string | undefined, offset?: unknown | undefined, limit?: unknown | undefined, include?: string | undefined}; export type GetApiUserProfileV1UsersOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const getApiUserProfileV1UsersResponse = z.object({links: z.object({self: z.object({href: z.string(), methods: z.array(z.enum(["GET", "POST", "PUT", "DELETE"])), name: z.object({}).optional()}), first: z.object({href: z.string()}), prev: z.object({href: z.string()}).optional(), next: z.object({href: z.string()}).optional()}).optional(), offset: z.number().int(), limit: z.number().int()}); 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 }; /** * Find all users. * * GET /user-profile/v1/users */ export const getApiUserProfileV1Users = async (args: GetApiUserProfileV1UsersArgs, options: GetApiUserProfileV1UsersOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['external-id'] != null) query.append("external-id", String(args['external-id'])) if (args['privacy-notice'] != null) query.append("privacy-notice", String(args['privacy-notice'])) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.include != null) query.append("include", String(args.include)) const url = `${baseUrl.replace(/\/+$/, '')}/user-profile/v1/users${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(getApiUserProfileV1UsersResponse, await res.json()) };