import {z} from 'zod' export type GetApiV1OrganizationsOrganizationIdHoldersArgs = {organization_id: string, 'X-Request-Id'?: string | undefined, Authorization?: string | undefined, metadata?: string | undefined, limit?: string | undefined, page?: string | undefined, sort_order?: string | undefined, include_deleted?: string | undefined, external_id?: string | undefined, document?: string | undefined}; export type GetApiV1OrganizationsOrganizationIdHoldersOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const pagination = z.object({items: z.unknown(), limit: z.number().int(), next_cursor: z.string().optional(), page: z.number().int().optional(), prev_cursor: 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 }; /** * List Holders * * GET /v1/organizations/{organization_id}/holders */ export const getApiV1OrganizationsOrganizationIdHolders = async (args: GetApiV1OrganizationsOrganizationIdHoldersArgs, options?: GetApiV1OrganizationsOrganizationIdHoldersOptions) => { const {baseUrl = "https://identity.sandbox.lerian.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-Request-Id'] != null) headers.set("X-Request-Id", String(args['X-Request-Id'])) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.metadata != null) query.append("metadata", String(args.metadata)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.page != null) query.append("page", String(args.page)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.include_deleted != null) query.append("include_deleted", String(args.include_deleted)) if (args.external_id != null) query.append("external_id", String(args.external_id)) if (args.document != null) query.append("document", String(args.document)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/organizations/${encodeURIComponent(String(args.organization_id))}/holders${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(pagination, await res.json()) };