import {z} from 'zod' export type BusinessTripTag = {tag_id?: string | undefined, dictionary_id?: string | undefined}; export type BusinessTripMoneyTransferMode = 'SPLIT' | 'FULL'; export type BusinessTripPreAction = 'CARD_ACTIVATE' | 'CARD_KEEP_BLOCKED' | 'FUNDS_TRANSFER_ON_WALLET' | 'UNLOCK_COUNTRIES_ON_CARD'; export type PreAction = {requested_action?: Array | undefined}; export type BusinessTripUnusedFunds = 'LEAVE' | 'REMOVE'; export type BusinessTripCardHandling = 'KEEP_ACTIVE' | 'BLOCK'; export type PostAction = {unused_funds?: BusinessTripUnusedFunds | undefined, card_handling?: BusinessTripCardHandling | undefined}; export type BusinessTripExpenseSpendPeriod = 'BEFORE_TRIP' | 'DURING_TRIP'; export type ISO4217Currency = 'AED' | 'AFN' | 'ALL' | 'AMD' | 'ANG' | 'AOA' | 'ARS' | 'AUD' | 'AWG' | 'AZN' | 'BAM' | 'BBD' | 'BDT' | 'BGN' | 'BHD' | 'BIF' | 'BMD' | 'BND' | 'BOB' | 'BOV' | 'BRL' | 'BSD' | 'BTN' | 'BWP' | 'BYN' | 'BZD' | 'CAD' | 'CDF' | 'CHE' | 'CHF' | 'CHW' | 'CLF' | 'CLP' | 'CNY' | 'COP' | 'COU' | 'CRC' | 'CUC' | 'CUP' | 'CVE' | 'CZK' | 'DJF' | 'DKK' | 'DOP' | 'DZD' | 'EGP' | 'ERN' | 'ETB' | 'EUR' | 'FJD' | 'FKP' | 'GBP' | 'GEL' | 'GHS' | 'GIP' | 'GMD' | 'GNF' | 'GTQ' | 'GYD' | 'HKD' | 'HNL' | 'HRK' | 'HTG' | 'HUF' | 'IDR' | 'ILS' | 'INR' | 'IQD' | 'IRR' | 'ISK' | 'JMD' | 'JOD' | 'JPY' | 'KES' | 'KGS' | 'KHR' | 'KMF' | 'KPW' | 'KRW' | 'KWD' | 'KYD' | 'KZT' | 'LAK' | 'LBP' | 'LKR' | 'LRD' | 'LSL' | 'LYD' | 'MAD' | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MNT' | 'MOP' | 'MRO' | 'MRU' | 'MUR' | 'MVR' | 'MWK' | 'MXN' | 'MXV' | 'MYR' | 'MZN' | 'NAD' | 'NGN' | 'NIO' | 'NOK' | 'NPR' | 'NZD' | 'OMR' | 'PAB' | 'PEN' | 'PGK' | 'PHP' | 'PKR' | 'PLN' | 'PYG' | 'QAR' | 'RON' | 'RSD' | 'RUB' | 'RWF' | 'SAR' | 'SBD' | 'SCR' | 'SDG' | 'SEK' | 'SGD' | 'SHP' | 'SLE' | 'SLL' | 'SOS' | 'SRD' | 'SSP' | 'STD' | 'STN' | 'SVC' | 'SYP' | 'SZL' | 'THB' | 'TJS' | 'TMT' | 'TND' | 'TOP' | 'TRY' | 'TTD' | 'TWD' | 'TZS' | 'UAH' | 'UGX' | 'USD' | 'USN' | 'UYI' | 'UYU' | 'UYW' | 'UZS' | 'VED' | 'VEF' | 'VES' | 'VND' | 'VUV' | 'WST' | 'XAF' | 'XAG' | 'XAU' | 'XBA' | 'XBB' | 'XBC' | 'XBD' | 'XCD' | 'XDR' | 'XOF' | 'XPD' | 'XPF' | 'XPT' | 'XSU' | 'XTS' | 'XUA' | 'XXX' | 'YER' | 'ZAR' | 'ZMW' | 'ZWL'; export type BusinessTripExpense = {expense_category_id?: string | undefined, spend_period: BusinessTripExpenseSpendPeriod, amount: number, amount_currency: ISO4217Currency, description?: string | undefined}; export type CreateBusinessTrip = {request_timestamp: number, name: string, description: string, destination: string, traveller_user_id: string, traveller_card_id: string, wallet_id: string, tags?: Array | undefined, from_date: string, to_date: string, money_transfer_mode: BusinessTripMoneyTransferMode, pre_action?: PreAction | undefined, post_action: PostAction, expense_allocation?: Array | undefined}; export type CreateApiBusinessV2BusinessTripsArgs = {'X-Soldo-Fingerprint': string, 'X-Soldo-Fingerprint-Signature': string, body: CreateBusinessTrip}; export type CreateApiBusinessV2BusinessTripsOptions = {baseUrl?: string | undefined, standardAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const businessTripMoneyTransferMode = z.enum(["SPLIT", "FULL"]); export const businessTripStatus = z.enum(["SCHEDULED", "COMPLETED", "ONGOING", "DELETED", "FINISHED"]); export const businessTripPurchaseStatus = z.enum(["SUCCESSFUL", "ACTIVE", "ASSIGNED", "DELETED", "EXPIRED", "REQUEST_EXTENSION"]); export const iSO4217Currency = z.enum(["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MRU", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLE", "SLL", "SOS", "SRD", "SSP", "STD", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "USN", "UYI", "UYU", "UYW", "UZS", "VED", "VEF", "VES", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "XSU", "XTS", "XUA", "XXX", "YER", "ZAR", "ZMW", "ZWL"]); export const businessTripPreAction = z.enum(["CARD_ACTIVATE", "CARD_KEEP_BLOCKED", "FUNDS_TRANSFER_ON_WALLET", "UNLOCK_COUNTRIES_ON_CARD"]); export const preAction = z.object({requested_action: z.array(businessTripPreAction).optional()}); export const businessTripUnusedFunds = z.enum(["LEAVE", "REMOVE"]); export const businessTripCardHandling = z.enum(["KEEP_ACTIVE", "BLOCK"]); export const postAction = z.object({unused_funds: businessTripUnusedFunds.optional(), card_handling: businessTripCardHandling.optional()}); export const businessTripExpenseSpendPeriod = z.enum(["BEFORE_TRIP", "DURING_TRIP"]); export const businessTripExpense = z.object({expense_category_id: z.string().optional(), spend_period: businessTripExpenseSpendPeriod, amount: z.number(), amount_currency: iSO4217Currency, description: z.string().optional()}); export const businessTripTag = z.object({tag_id: z.string().optional(), dictionary_id: z.string().optional()}); export const businessTrip = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), destination: z.string().optional(), date_from: z.string().optional(), date_to: z.string().optional(), author_user_id: z.string().optional(), approver_user_id: z.string().optional(), traveller_user_id: z.string().optional(), traveller_card_id: z.string().optional(), money_transfer_mode: businessTripMoneyTransferMode.optional(), status: businessTripStatus.optional(), purchase_state: businessTripPurchaseStatus.optional(), total_amount: z.number().optional(), total_amount_currency: iSO4217Currency.optional(), received_amount: z.number().optional(), received_amount_currency: iSO4217Currency.optional(), scheduled_amount: z.number().optional(), scheduled_amount_currency: iSO4217Currency.optional(), pre_action: preAction.optional(), post_action: postAction.optional(), wallet_id: z.string().optional(), creation_time: z.string().optional(), last_update_time: z.string().optional(), expense_allocation: z.array(businessTripExpense).optional(), tags: z.array(businessTripTag).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 }; /** * Add Business Trip * * POST /business/v2/business-trips */ export const createApiBusinessV2BusinessTrips = async (args: CreateApiBusinessV2BusinessTripsArgs, options?: CreateApiBusinessV2BusinessTripsOptions) => { const {baseUrl = "https://api.soldo.com", fetch: fetchFn = fetch, standardAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['X-Soldo-Fingerprint'] != null) headers.set("X-Soldo-Fingerprint", String(args['X-Soldo-Fingerprint'])) if (args['X-Soldo-Fingerprint-Signature'] != null) headers.set("X-Soldo-Fingerprint-Signature", String(args['X-Soldo-Fingerprint-Signature'])) if (standardAuth !== undefined) headers.set('authorization', `Bearer ${standardAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/business/v2/business-trips${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(businessTrip, await res.json()) };