import {z} from 'zod' export type JsonValue = unknown; export type DocumentContentRequest = {fields: {[key: string]: JsonValue}}; export type UpdateApiDocumentsDocumentIdContentArgs = {documentId: string, 'Idempotency-Key'?: (string | null) | undefined, 'X-Hevn-Account'?: (string | null) | undefined, body: DocumentContentRequest}; export type UpdateApiDocumentsDocumentIdContentOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const documentType = z.enum(["certificate_of_incorporation", "certificate_of_registration", "formation_document", "articles_of_incorporation", "power_of_attorney", "corporate_structure", "org_structure_chart", "company_registry_extract", "corporate_registry_extract", "shareholder_registry", "cap_table", "director_structure", "proof_of_address", "utility_bill", "aml_policy", "annual_financial_statements", "articles_of_association", "audit_report", "independent_aml_audit_report", "identity_verification_attestation", "institutional_investor_documentation", "audited_financial_statement", "bank_reference_letter", "bank_verification_letter", "bank_statement", "banking_details", "birth_certificate", "business_license", "operating_license", "business_plan", "certificate_of_good_standing", "corporate_resolution", "proof_of_registered_address", "proof_of_operating_address", "crypto_statement", "credit_report", "criminal_record_check", "cv_resume", "driving_license", "education_certificate", "financial_projections", "investment_statement", "insurance_policy", "lease_agreement", "marriage_certificate", "national_id", "national_id_front", "national_id_back", "operating_agreement", "partnership_agreement", "professional_license", "regulatory_license", "reference_letter", "register_of_members", "residence_permit", "shareholding_structure", "shareholders_agreement", "social_security_document", "source_of_funds_declaration", "tax_identification_document", "ein_letter", "tax_certificate", "tax_compliance_form", "tax_returns", "payslip", "pitch_deck", "savings_statement", "trade_references", "vat_registration", "vendor_contracts", "visa", "wealth_statement", "contract", "invoice", "loan_agreement", "subscription_agreement", "safe_agreement", "convertible_note", "promissory_note", "marketing_material", "employment_contract", "authorization_to_act", "authority_to_bind", "ubo_declaration", "income_verification_letter", "source_of_funds", "flow_of_funds", "payroll_register", "investment_agreement", "source_of_wealth", "supporting_document", "memorandum", "passport_front", "passport_back", "id_card_front", "id_card_back", "drivers_license_front", "drivers_license_back", "residence_permit_front", "residence_permit_back", "other"]); export const documentResponse = z.object({id: z.string(), slot: documentType, name: z.string().nullable().optional(), fileName: z.string().nullable().optional(), createdAt: z.string().nullable().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 }; /** * Fill the typed fields read off a document * * PUT /documents/{documentId}/content */ export const updateApiDocumentsDocumentIdContent = async (args: UpdateApiDocumentsDocumentIdContentArgs, options: UpdateApiDocumentsDocumentIdContentOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (args['X-Hevn-Account'] != null) headers.set("X-Hevn-Account", String(args['X-Hevn-Account'])) if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/documents/${encodeURIComponent(String(args.documentId))}/content${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(documentResponse, await res.json()) };