import {z} from 'zod' export type CustomerTenantType = 0 | 1 | 2; export type GetApiApiV1CrayonAccountsArgs = {OrganizationId?: number | undefined, PublisherId?: number | undefined, ConsumerId?: number | undefined, CustomerTenantType?: CustomerTenantType | undefined, Page?: number | undefined, PageSize?: number | undefined, Search?: (string | null) | undefined}; export type GetApiApiV1CrayonAccountsOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const objectReference = z.object({id: z.number().int().optional(), name: z.string().nullable().optional()}); export const customerTenantType = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const entityStatus = z.union([z.literal(0), z.literal(1)]); export const organization = z.object({id: z.number().int().optional(), name: z.string().nullable().optional(), parentId: z.number().int().optional(), crayonCompanyName: z.string().nullable().optional(), accountNumber: z.string().nullable().optional()}); export const customerTenantContact = z.object({firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), email: z.string().nullable().optional(), phoneNumber: z.string().nullable().optional()}); export const crayonAccountExtended = z.object({invoiceProfile: objectReference.optional(), id: z.number().int().optional(), name: z.string().nullable().optional(), email: z.string().nullable().optional(), publisher: objectReference.optional(), externalPublisherCustomerId: z.string().nullable().optional(), reference: z.string().nullable().optional(), customerTenantType: customerTenantType.optional(), entityStatus: entityStatus.optional(), organization: organization.optional(), isActivated: z.boolean().optional(), contact: customerTenantContact.optional(), program: objectReference.optional(), resellerMarkup: z.number().optional()}); export const getApiApiV1CrayonAccountsResponse = z.array(crayonAccountExtended); 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 }; /** * GET /api/v1/CrayonAccounts */ export const getApiApiV1CrayonAccounts = async (args: GetApiApiV1CrayonAccountsArgs, options: GetApiApiV1CrayonAccountsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.OrganizationId != null) query.append("OrganizationId", String(args.OrganizationId)) if (args.PublisherId != null) query.append("PublisherId", String(args.PublisherId)) if (args.ConsumerId != null) query.append("ConsumerId", String(args.ConsumerId)) if (args.CustomerTenantType != null) query.append("CustomerTenantType", String(args.CustomerTenantType)) if (args.Page != null) query.append("Page", String(args.Page)) if (args.PageSize != null) query.append("PageSize", String(args.PageSize)) if (args.Search != null) query.append("Search", String(args.Search)) if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/CrayonAccounts${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(getApiApiV1CrayonAccountsResponse, await res.json()) };