import {z} from 'zod' export type SubAccountsSubAccountCreateParamProductsItem = 'identity' | 'liens' | 'adverse_media' | 'bankruptcies' | 'business_enrichment' | 'documents' | 'enhanced_screenings' | 'kyc_doc_v' | 'kyc' | 'litigations' | 'people_litigations' | 'people_bankruptcies' | 'people_tax_liens' | 'people_ucc_liens' | 'people_criminal_history' | 'tin' | 'website' | 'business_verification_qualify' | 'business_verification_verify' | 'tax_liens' | 'ucc_liens' | 'merchant_risk' | 'risk' | 'email_risk' | 'phone_risk' | 'international_business_verification'; export type SubAccountsSubAccountCreateParamVertical = 'fintech_non_bank_financial_services' | 'banks' | 'manufacturing_industrial' | 'technology_companies' | 'freight_logistics' | 'other' | 'government'; export type SubAccountsSubAccountCreateParamSubVertical = 'digital_banking_neobanks' | 'insurance' | 'lending_non_bank_digital' | 'lending_non_bank_traditional' | 'payments_acquiring_issuing' | 'payroll_benefits_management' | 'other_fintech_non_bank_financial_services' | 'community_banks' | 'credit_unions' | 'national_banks' | 'regional_banks' | 'automotive' | 'construction' | 'healthcare_medical' | 'other_manufacturing_industrial' | 'b2b_software_vertical_saas' | 'data_services' | 'ecommerce' | 'hardware' | 'marketplaces' | 'telecomm' | 'other_technology_companies' | 'freight_logistics' | 'government' | 'other'; export type SubAccountsSubAccountCreateParamUseCase = 'banking' | 'lending' | 'payments' | 'business_marketplace' | 'agent' | 'tax_registrations' | 'less_regulated_kyb' | 'account_opening' | 'term_loans' | 'working_capital_loans' | 'equipment_finance' | 'line_of_credit' | 'invoice_factoring' | 'merchant_cash_advance' | 'trade_credit' | 'expense_management' | 'payroll_tax_account' | 'compliance_for_bank_account_opening' | 'compliance_for_commercial_mortgages' | 'compliance_for_issuing_an_insurance_policy' | 'compliance_for_loan_origination' | 'compliance_for_payments_merchant_onboarding' | 'compliance_for_treasury_management' | 'compliance_other' | 'credit_decisioning_for_loan_origination' | 'filing_a_lien_for_loan_origination' | 'filing_a_lien_other' | 'fraud_prevention_for_bank_account_opening' | 'fraud_prevention_for_issuing_an_insurance_policy' | 'fraud_prevention_for_loan_origination' | 'fraud_prevention_for_payments_merchant_onboarding' | 'fraud_prevention_for_un_regulated_business_onboarding' | 'fraud_prevention_other' | 'tax_compliance_requirements_for_processing_payroll' | 'underwriting_for_issuing_an_insurance_policy' | 'other'; export type SubAccountsSubAccountCreateParamContact = {first_name: string, middle_name?: string | undefined, last_name: string, email: string}; export type CreateApiV1SubAccountsArgs = {body: {name: string, external_id: string, products?: Array | undefined, inherit_products_from_parent?: boolean | undefined, website?: string | undefined, vertical?: SubAccountsSubAccountCreateParamVertical | undefined, sub_vertical?: SubAccountsSubAccountCreateParamSubVertical | undefined, use_case?: SubAccountsSubAccountCreateParamUseCase | undefined, contact?: SubAccountsSubAccountCreateParamContact | undefined, deal_name?: string | undefined, estimated_volume?: number | undefined, go_live_date?: string | undefined}}; export type CreateApiV1SubAccountsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const subAccountObject = z.literal("sub_account"); export const subAccount = z.object({object: subAccountObject, id: z.string(), name: z.string(), external_id: z.string().nullable(), enabled: z.boolean(), products: z.array(z.string()), created_at: z.string()}); 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 sub-account * * POST /v1/sub_accounts */ export const createApiV1SubAccounts = async (args: CreateApiV1SubAccountsArgs, options?: CreateApiV1SubAccountsOptions) => { const {baseUrl = "https://api.middesk.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/sub_accounts${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(subAccount, await res.json()) };