import {z} from 'zod' export type BillingAddress = {address_line1: string, address_line2?: string | undefined, city: string, country: string, postal_code: string, state_or_region: string}; export type EntitiesPutPostRequest = {billing_addr?: BillingAddress | undefined, company_name?: string | undefined, organization_name?: string | undefined, tax_id?: string | undefined, tax_id_type?: ('EIN' | 'VAT') | undefined}; export type UpdateApiOrganizationsEntitiesArgs = {org_id: string, body: EntitiesPutPostRequest}; export type UpdateApiOrganizationsEntitiesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const billing = z.object({balance: z.string(), billing_method: z.enum(["stripe", "manual"]).optional(), delinquent: z.boolean(), has_valid_payment_method: z.boolean()}); export const billingAddress = z.object({address_line1: z.string(), address_line2: z.string().optional(), city: z.string(), country: z.string(), postal_code: z.string(), state_or_region: z.string()}); export const organizationMFA = z.object({created_at: z.string(), method: z.enum(["totp", "webauthn"])}); export const entity = z.object({billing: billing, billing_addr: billingAddress.optional(), company_name: z.string().optional(), features: z.record(z.string(), z.unknown()), id: z.string(), mfa_methods: z.array(organizationMFA).optional(), name: z.string(), organization_type: z.enum(["standard", "enterprise", "limited"]).optional(), registration_type: z.string().optional(), relation: z.string(), state: z.string(), state_reason: z.string(), tax_id: z.string().optional(), tax_id_type: z.enum(["EIN", "VAT"]).optional()}); export const entitiesPutPostResponse = z.object({entity: entity}); 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 }; /** * Update details for an organization that the logged in user owns. * * PUT /organizations/entities */ export const updateApiOrganizationsEntities = async (args: UpdateApiOrganizationsEntitiesArgs, options?: UpdateApiOrganizationsEntitiesOptions) => { const {baseUrl = "https://api.cloud.crusoe.ai/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.org_id != null) query.append("org_id", String(args.org_id)) const url = `${baseUrl.replace(/\/+$/, '')}/organizations/entities${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(entitiesPutPostResponse, await res.json()) };