import {z} from 'zod' export type ObjectReference = {id?: number | undefined, name?: (string | null) | undefined}; export type CustomerTenantType = 0 | 1 | 2; export type EntityStatus = 0 | 1; export type Organization = {id?: number | undefined, name?: (string | null) | undefined, parentId?: number | undefined, crayonCompanyName?: (string | null) | undefined, accountNumber?: (string | null) | undefined}; export type CustomerTenantContact = {firstName?: (string | null) | undefined, lastName?: (string | null) | undefined, email?: (string | null) | undefined, phoneNumber?: (string | null) | undefined}; export type CrayonAccount = {id?: number | undefined, name?: (string | null) | undefined, email?: (string | null) | undefined, publisher?: ObjectReference | undefined, externalPublisherCustomerId?: (string | null) | undefined, reference?: (string | null) | undefined, customerTenantType?: CustomerTenantType | undefined, entityStatus?: EntityStatus | undefined, organization?: Organization | undefined, invoiceProfile?: ObjectReference | undefined, isActivated?: boolean | undefined, contact?: CustomerTenantContact | undefined, program?: ObjectReference | undefined, resellerMarkup?: number | undefined}; export type CreateApiApiV1CrayonAccountsArgs = {body: CrayonAccount}; export type CreateApiApiV1CrayonAccountsOptions = {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 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 }; /** * POST /api/v1/CrayonAccounts */ export const createApiApiV1CrayonAccounts = async (args: CreateApiApiV1CrayonAccountsArgs, options: CreateApiApiV1CrayonAccountsOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/CrayonAccounts${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(crayonAccountExtended, await res.json()) };