import {z} from 'zod' export type CreateTenantRequestDto = {business_legal_name: string, business_dba?: (string | null) | undefined, business_address_country?: (string | null) | undefined, webhook_url?: (string | null) | undefined, business_street_address1?: (string | null) | undefined, business_street_address2?: (string | null) | undefined, business_city?: (string | null) | undefined, business_state?: (string | null) | undefined, business_postal_code?: (string | null) | undefined, business_legal_entity_identifier?: (string | null) | undefined}; export type CreateApiV1EntitiesTenantsArgs = {body: CreateTenantRequestDto}; export type CreateApiV1EntitiesTenantsOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const tenantData = z.object({id: z.string(), workspace_id: z.string(), name: z.string(), business_legal_name: z.string().nullable().optional(), business_dba: z.string().nullable().optional(), business_address_country: z.string().nullable().optional(), webhook_url: z.string().nullable().optional(), business_street_address1: z.string().nullable().optional(), business_street_address2: z.string().nullable().optional(), business_city: z.string().nullable().optional(), business_state: z.string().nullable().optional(), business_postal_code: z.string().nullable().optional(), business_legal_entity_identifier: z.string().nullable().optional(), created_at: z.string(), updated_at: z.string()}); export const createTenantData = z.object({tenant: tenantData}); export const createTenantResponseDto = z.object({data: createTenantData}); 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 }; /** * Create a new tenant * * POST /v1/entities/tenants */ export const createApiV1EntitiesTenants = async (args: CreateApiV1EntitiesTenantsArgs, options?: CreateApiV1EntitiesTenantsOptions) => { const {baseUrl = "https://api.tesser.xyz", 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 ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/entities/tenants${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(createTenantResponseDto, await res.json()) };