import {z} from 'zod' export type GetApiApiV1CustomerTenantsIdArgs = {id: number}; export type GetApiApiV1CustomerTenantsIdOptions = {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 subscriptionPriceType = z.union([z.literal(1), z.literal(2), z.literal(3)]); export const agreementTypeConsent = z.union([z.literal(0), z.literal(1)]); export const customerTenantAgreement = z.object({firstName: z.string().nullable().optional(), lastName: z.string().nullable().optional(), phoneNumber: z.string().nullable().optional(), email: z.string().nullable().optional(), sameAsPrimaryContact: z.boolean().optional(), dateAgreed: z.string().nullable().optional(), accepted: z.boolean().optional(), agreementType: agreementTypeConsent.optional()}); export const customerTenantExtended = z.object({invoiceProfile: objectReference.optional(), id: z.number().int().optional(), name: z.string().nullable().optional(), publisher: objectReference.optional(), program: objectReference.optional(), publisherCustomerId: z.string().nullable().optional(), externalPublisherCustomerId: z.string().nullable().optional(), domain: z.string().nullable().optional(), domainPrefix: z.string().nullable().optional(), reference: z.string().nullable().optional(), customerTenantType: customerTenantType.optional(), entityStatus: entityStatus.optional(), organization: organization.optional(), consumer: objectReference.optional(), resellerMarkup: z.number().optional(), defaultSubscriptionPriceType: subscriptionPriceType.optional(), agreement: customerTenantAgreement.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 }; /** * GET /api/v1/CustomerTenants/{id} */ export const getApiApiV1CustomerTenantsId = async (args: GetApiApiV1CustomerTenantsIdArgs, options: GetApiApiV1CustomerTenantsIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/CustomerTenants/${encodeURIComponent(String(args.id))}${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(customerTenantExtended, await res.json()) };