import {z} from 'zod' export type GetApiV1PartnerCustomersCustomerIdUsersArgs = {customerId: Record, page?: Record | undefined, pageSize?: Record | undefined}; export type GetApiV1PartnerCustomersCustomerIdUsersOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const strategicPartnerCustomerUserResponse = z.object({id: z.string(), firstName: z.string().optional(), lastName: z.string().optional(), email: z.string(), role: z.enum(["ADMIN", "BILLING_ADMIN", "PAYROLL_ADMIN", "HR_ADMIN", "MANAGER"]), customerId: z.string()}); export const strategicPartnerPagination = z.object({page: z.number().int().gte(1), pageSize: z.number().int().gte(1).lte(100), totalCount: z.number().int().gte(0), totalPages: z.number().int().gte(0).optional()}); export const strategicPartnerCustomerUserListResponse = z.object({data: z.array(strategicPartnerCustomerUserResponse), pagination: strategicPartnerPagination}); 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 all customer users * * GET /v1/partner/customers/{customerId}/users */ export const getApiV1PartnerCustomersCustomerIdUsers = async (args: GetApiV1PartnerCustomersCustomerIdUsersArgs, options?: GetApiV1PartnerCustomersCustomerIdUsersOptions) => { const {baseUrl = "https://api.usemultiplier.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", JSON.stringify(args.page)) if (args.pageSize != null) query.append("pageSize", JSON.stringify(args.pageSize)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/partner/customers/${encodeURIComponent(String(args.customerId))}/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(strategicPartnerCustomerUserListResponse, await res.json()) };