import {z} from 'zod' export type CreditPolicyInput = {limit?: (number | null) | undefined}; export type CompanyReferenceNumbers = {eori_number?: (string | null) | undefined, duns_number?: (string | null) | undefined, scac_code?: (string | null) | undefined, company_registration_number?: (string | null) | undefined, tss_registration_number?: (string | null) | undefined}; export type TaxTypeEnum = 'VAT' | 'REVERSE_CHARGE' | 'UK_REVERSE_CHARGE' | 'TRANSIT' | 'NO_VAT' | 'CO_CONTRACTING' | 'OTHER'; export type BankAccount = {bic_code?: (string | null) | undefined, iban_code?: (string | null) | undefined}; export type BillingLocation = {code?: (string | null) | undefined, display_name?: (string | null) | undefined, external_id?: (string | null) | undefined, address?: (string | null) | undefined, address_second_line?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, country?: (string | null) | undefined, postal_code?: (string | null) | undefined, name?: (string | null) | undefined}; export type PaymentTermCode = 'END_OF_MONTH_2' | 'END_OF_MONTH_1' | 'END_OF_MONTH_0_NET_90' | 'END_OF_MONTH_0_NET_75' | 'END_OF_MONTH_0_NET_70' | 'END_OF_MONTH_0_NET_65' | 'END_OF_MONTH_0_NET_60' | 'END_OF_MONTH_0_NET_50' | 'END_OF_MONTH_0_NET_45' | 'END_OF_MONTH_0_NET_35' | 'END_OF_MONTH_0_NET_31' | 'END_OF_MONTH_0_NET_30' | 'END_OF_MONTH_0_NET_25' | 'END_OF_MONTH_0_NET_21' | 'END_OF_MONTH_0_NET_20' | 'END_OF_MONTH_0_NET_14' | 'END_OF_MONTH_0_NET_7' | 'END_OF_MONTH_0_NET_1' | 'END_OF_MONTH_0' | 'PREPAID' | 'CUSTOM_DUE_DATE' | 'UPON_RECEIPT' | 'NET_1' | 'NET_2' | 'NET_3' | 'NET_5' | 'NET_7' | 'NET_8' | 'NET_10' | 'NET_12' | 'NET_14' | 'NET_15' | 'NET_20' | 'NET_21' | 'NET_28' | 'NET_30' | 'NET_35' | 'NET_40' | 'NET_42' | 'NET_45' | 'NET_48' | 'NET_49' | 'NET_50' | 'NET_52' | 'NET_55' | 'NET_56' | 'NET_60' | 'NET_63' | 'NET_70' | 'NET_75' | 'NET_77' | 'NET_80' | 'NET_84' | 'NET_90' | 'NET_91' | 'NET_98' | 'NET_120'; export type BasePaymentTerm = {code: PaymentTermCode}; export type ContactType = 'BILLING' | 'OPERATIONS' | 'BOOKINGS' | 'NOTIFICATIONS' | 'CLEANING' | 'HEATING' | 'STORAGE' | 'CONTAINER_RELEASE' | 'DRIVER' | 'OTHER' | 'CMR_PROCESSING' | 'PAYMENT_REMINDERS' | 'CLAIMS_INSURANCE' | 'CUSTOMS' | 'IT' | 'QUALITY' | 'SALES' | 'CUSTOMER_CONTACT'; export type CompanyContactInput = {id?: (string | null) | undefined, is_archived?: boolean | undefined, roles?: Array | undefined, name?: (string | null) | undefined, note?: (string | null) | undefined, email?: (string | null) | undefined, phone_number?: (string | null) | undefined}; export type CompanyBillingEntity = {id?: (string | null) | undefined, code?: (string | null) | undefined, accounting_code?: (string | null) | undefined}; export type CustomerStatus = 'PROSPECT' | 'NOT_APPROVED' | 'APPROVED' | 'WARNING' | 'BLOCKED'; export type SalesCompanyFieldsInput = {payment_term?: (BasePaymentTerm | null) | undefined, billing_entities?: (Array | null) | undefined, status?: (CustomerStatus | null) | undefined}; export type SubcontractorStatus = 'NOT_APPROVED' | 'APPROVED' | 'WARNING' | 'BLOCKED'; export type PurchaseCompanyFieldsInput = {payment_term?: (BasePaymentTerm | null) | undefined, billing_entities?: (Array | null) | undefined, status?: (SubcontractorStatus | null) | undefined}; export type CompanyInput = {is_customer?: boolean | undefined, is_buyer_or_seller?: (boolean | null) | undefined, name?: (string | null) | undefined, code?: (string | null) | undefined, currency: string, custom_fields?: (Record | null) | undefined, credit_policy?: (CreditPolicyInput | null) | undefined, default_invoice_customer_id?: (string | null) | undefined, is_subcontractor?: boolean | undefined, archived_customer?: (boolean | null) | undefined, archived_subcontractor?: (boolean | null) | undefined, legal_name?: (string | null) | undefined, locale?: (string | null) | undefined, vat_number?: (string | null) | undefined, reference_numbers?: (CompanyReferenceNumbers | null) | undefined, note?: (string | null) | undefined, tax_type?: (TaxTypeEnum | null) | undefined, bank_accounts?: (Array | null) | undefined, accounting_code?: (string | null) | undefined, billing_location?: (BillingLocation | null) | undefined, payment_term?: (BasePaymentTerm | null) | undefined, contacts?: (Array | null) | undefined, sales?: SalesCompanyFieldsInput | undefined, purchase?: PurchaseCompanyFieldsInput | undefined, credit_limit_total?: (number | null) | undefined, is_blocked?: (boolean | null) | undefined, status?: (CustomerStatus | null) | undefined}; export type CreateApiV1AccountingCompanyArgs = {body: CompanyInput}; export type CreateApiV1AccountingCompanyOptions = {baseUrl?: string | undefined, oAuth2ClientCredentials?: string | undefined, fetch?: typeof fetch | undefined}; export const taxTypeEnum = z.enum(["VAT", "REVERSE_CHARGE", "UK_REVERSE_CHARGE", "TRANSIT", "NO_VAT", "CO_CONTRACTING", "OTHER"]); export const customerStatus = z.enum(["PROSPECT", "NOT_APPROVED", "APPROVED", "WARNING", "BLOCKED"]); export const locationOutput = z.object({code: z.string().nullable().optional(), display_name: z.string().nullable().optional(), external_id: z.string().nullable().optional(), address: z.string().nullable().optional(), address_second_line: z.string().nullable().optional(), city: z.string().nullable().optional(), state: z.string().nullable().optional(), country: z.string().nullable().optional(), postal_code: z.string().nullable().optional(), name: z.string().nullable().optional(), id: z.string().nullable().optional(), latitude: z.number().nullable().optional(), longitude: z.number().nullable().optional()}); export const paymentTermCode = z.enum(["END_OF_MONTH_2", "END_OF_MONTH_1", "END_OF_MONTH_0_NET_90", "END_OF_MONTH_0_NET_75", "END_OF_MONTH_0_NET_70", "END_OF_MONTH_0_NET_65", "END_OF_MONTH_0_NET_60", "END_OF_MONTH_0_NET_50", "END_OF_MONTH_0_NET_45", "END_OF_MONTH_0_NET_35", "END_OF_MONTH_0_NET_31", "END_OF_MONTH_0_NET_30", "END_OF_MONTH_0_NET_25", "END_OF_MONTH_0_NET_21", "END_OF_MONTH_0_NET_20", "END_OF_MONTH_0_NET_14", "END_OF_MONTH_0_NET_7", "END_OF_MONTH_0_NET_1", "END_OF_MONTH_0", "PREPAID", "CUSTOM_DUE_DATE", "UPON_RECEIPT", "NET_1", "NET_2", "NET_3", "NET_5", "NET_7", "NET_8", "NET_10", "NET_12", "NET_14", "NET_15", "NET_20", "NET_21", "NET_28", "NET_30", "NET_35", "NET_40", "NET_42", "NET_45", "NET_48", "NET_49", "NET_50", "NET_52", "NET_55", "NET_56", "NET_60", "NET_63", "NET_70", "NET_75", "NET_77", "NET_80", "NET_84", "NET_90", "NET_91", "NET_98", "NET_120"]); export const basePaymentTerm = z.object({code: paymentTermCode}); export const creditPolicyOutput = z.object({limit: z.number().nullable().optional()}); export const apiAccountingModelsCompanyCompanyReferenceOutput = z.object({id: z.string(), name: z.string(), code: z.string().nullable().optional()}); export const companyReferenceNumbers = z.object({eori_number: z.string().nullable().optional(), duns_number: z.string().nullable().optional(), scac_code: z.string().nullable().optional(), company_registration_number: z.string().nullable().optional(), tss_registration_number: z.string().nullable().optional()}); export const bankAccount = z.object({bic_code: z.string().nullable().optional(), iban_code: z.string().nullable().optional()}); export const contactType = z.enum(["BILLING", "OPERATIONS", "BOOKINGS", "NOTIFICATIONS", "CLEANING", "HEATING", "STORAGE", "CONTAINER_RELEASE", "DRIVER", "OTHER", "CMR_PROCESSING", "PAYMENT_REMINDERS", "CLAIMS_INSURANCE", "CUSTOMS", "IT", "QUALITY", "SALES", "CUSTOMER_CONTACT"]); export const companyContactOutput = z.object({id: z.string().nullable().optional(), roles: z.array(contactType).optional(), name: z.string().nullable().optional(), note: z.string().nullable().optional(), email: z.string().nullable().optional(), phone_number: z.string().nullable().optional()}); export const companyBillingEntity = z.object({id: z.string().nullable().optional(), code: z.string().nullable().optional(), accounting_code: z.string().nullable().optional()}); export const salesCompanyFieldsOutput = z.object({payment_term: basePaymentTerm.nullable().optional(), billing_entities: z.array(companyBillingEntity).nullable().optional(), status: customerStatus.nullable().optional()}); export const subcontractorStatus = z.enum(["NOT_APPROVED", "APPROVED", "WARNING", "BLOCKED"]); export const purchaseCompanyFieldsOutput = z.object({payment_term: basePaymentTerm.nullable().optional(), billing_entities: z.array(companyBillingEntity).nullable().optional(), status: subcontractorStatus.nullable().optional()}); export const companyDetailOutput = z.object({id: z.string(), code: z.string().nullable().optional(), currency: z.string(), custom_fields: z.object({}).nullable().optional(), is_customer: z.boolean().optional(), is_subcontractor: z.boolean().optional(), is_buyer_or_seller: z.boolean().nullable().optional(), name: z.string(), legal_name: z.string().nullable().optional(), vat_number: z.string().nullable().optional(), note: z.string().nullable().optional(), tax_type: taxTypeEnum.nullable().optional(), status: customerStatus.optional(), accounting_code: z.string().nullable().optional(), billing_location: locationOutput.nullable().optional(), payment_term: basePaymentTerm.nullable().optional(), locale: z.string(), archived_customer: z.boolean(), archived_subcontractor: z.boolean(), archived_buyer_or_seller: z.boolean(), credit_policy: creditPolicyOutput.nullable().optional(), default_invoice_customer: apiAccountingModelsCompanyCompanyReferenceOutput.nullable().optional(), reference_numbers: companyReferenceNumbers.optional(), bank_accounts: z.array(bankAccount).optional(), contacts: z.array(companyContactOutput).nullable().optional(), sales: salesCompanyFieldsOutput.optional(), purchase: purchaseCompanyFieldsOutput.optional(), timestamp_updated: z.string(), is_blocked: z.boolean().optional(), credit_limit_total: z.number().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 }; /** * Create Company (Deprecated) * * POST /v1/accounting/company */ export const createApiV1AccountingCompany = async (args: CreateApiV1AccountingCompanyArgs, options?: CreateApiV1AccountingCompanyOptions) => { const {baseUrl = "https://api.qargo.com", fetch: fetchFn = fetch, oAuth2ClientCredentials} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oAuth2ClientCredentials !== undefined) headers.set('authorization', `Bearer ${oAuth2ClientCredentials}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/accounting/company${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(companyDetailOutput, await res.json()) };