import {z} from 'zod' export type Zoom2u = {api_key: string}; export type UspsWtInternational = {username: string, password: string, mailer_id?: string | undefined, customer_registration_id?: string | undefined, logistics_manager_mailer_id?: string | undefined}; export type UspsWt = {username: string, password: string, mailer_id?: string | undefined, customer_registration_id?: string | undefined, logistics_manager_mailer_id?: string | undefined}; export type UspsInternational = {client_id: string, client_secret: string, account_number?: string | undefined, account_type?: ('EPS' | 'PERMIT' | 'METER') | undefined, manifest_MID?: string | undefined, CRID?: string | undefined, MID?: string | undefined}; export type Usps = {client_id: string, client_secret: string, account_number?: string | undefined, account_type?: ('EPS' | 'PERMIT' | 'METER') | undefined, manifest_MID?: string | undefined, CRID?: string | undefined, MID?: string | undefined}; export type Ups = {client_id: string, client_secret: string, account_number?: string | undefined, account_country_code?: string | undefined}; export type Tnt = {username: string, password: string, account_number?: string | undefined, account_country_code?: string | undefined}; export type Tge = {username: string, password: string, api_key: string, toll_username: string, toll_password: string, my_toll_token: string, my_toll_identity: string, account_code?: string | undefined, sscc_count?: number | undefined, shipment_count?: number | undefined}; export type Sendle = {sendle_id: string, api_key: string, account_country_code?: string | undefined}; export type Seko = {access_key: string}; export type Sapient = {client_id: string, client_secret: string, shipping_account_id: string, sapient_carrier_code?: ('DX' | 'EVRI' | 'RM' | 'UPS' | 'YODEL') | undefined}; export type Royalmail = {client_id: string, client_secret: string}; export type Roadie = {api_key: string}; export type Purolator = {username: string, password: string, account_number: string, user_token?: string | undefined, language?: ('en' | 'fr') | undefined}; export type Nationex = {api_key: string, customer_id: string, billing_account?: string | undefined, language?: ('en' | 'fr') | undefined}; export type Locate2u = {client_id?: string | undefined, client_secret?: string | undefined}; export type Laposte = {api_key: string, lang?: ('fr_FR' | 'en_US') | undefined}; export type HayPost = {username: string, password: string, customer_id: string, customer_type: string}; export type Geodis = {api_key: string, identifier: string, code_client?: string | undefined, language?: ('fr' | 'en') | undefined}; export type Generic = {display_name: string, custom_carrier_name: string, account_country_code?: string | undefined, account_number?: string | undefined}; export type Freightcom = {username: string, password: string}; export type FedexWs = {password: string, meter_number: string, account_number: string, user_key?: string | undefined, language_code?: string | undefined, account_country_code?: string | undefined}; export type Fedex = {api_key?: string | undefined, secret_key?: string | undefined, account_number?: string | undefined, track_api_key?: string | undefined, track_secret_key?: string | undefined, account_country_code?: string | undefined}; export type Eshipper = {principal: string, credential: string}; export type Easyship = {access_token: string}; export type Easypost = {api_key: string}; export type Dpdhl = {username: string, password: string, app_id?: string | undefined, app_token?: string | undefined, zt_id?: string | undefined, zt_password?: string | undefined, account_number?: string | undefined}; export type Dpd = {delis_id: string, password: string, depot?: string | undefined, message_language?: string | undefined, account_country_code?: string | undefined}; export type Dicom = {username: string, password: string, billing_account?: string | undefined}; export type DhlUniversal = {consumer_key: string, consumer_secret: string, language?: ('en' | 'de') | undefined}; export type DhlPoland = {username: string, password: string, account_number?: string | undefined}; export type DhlParcelDe = {username: string, password: string, dhl_api_key: string, customer_number?: string | undefined, tracking_consumer_key?: string | undefined, tracking_consumer_secret?: string | undefined}; export type DhlExpress = {site_id: string, password: string, account_number?: string | undefined, account_country_code?: string | undefined}; export type Colissimo = {password: string, contract_number: string, laposte_api_key?: string | undefined}; export type Chronopost = {account_number: string, password: string, id_emit?: string | undefined, language?: ('en_GB' | 'fr_FR') | undefined}; export type Canpar = {username: string, password: string, language?: ('en' | 'fr') | undefined}; export type Canadapost = {username: string, password: string, customer_number?: string | undefined, contract_id?: string | undefined, language?: ('en' | 'fr') | undefined}; export type Bpost = {account_id: string, passphrase: string}; export type Boxknight = {username: string, password: string}; export type Australiapost = {api_key: string, password: string, account_number: string}; export type AsendiaUs = {username: string, password: string, api_key: string, account_number?: string | undefined}; export type Aramex = {username: string, password: string, account_pin: string, account_entity: string, account_number: string, account_country_code: string}; export type AmazonShipping = {seller_id: string, developer_id: string, mws_auth_token: string, aws_region?: string | undefined, account_country_code?: string | undefined}; export type AlliedExpressLocal = {username: string, password: string, account?: string | undefined, service_type?: ('R' | 'P' | 'PT' | 'PT2') | undefined}; export type AlliedExpress = {username: string, password: string, account?: string | undefined, service_type?: ('R' | 'P' | 'PT' | 'PT2') | undefined}; export type ConnectionCredentialsField = Zoom2u | UspsWtInternational | UspsWt | UspsInternational | Usps | Ups | Tnt | Tge | Sendle | Seko | Sapient | Royalmail | Roadie | Purolator | Nationex | Locate2u | Laposte | HayPost | Geodis | Generic | Freightcom | FedexWs | Fedex | Eshipper | Easyship | Easypost | Dpdhl | Dpd | Dicom | DhlUniversal | DhlPoland | DhlParcelDe | DhlExpress | Colissimo | Chronopost | Canpar | Canadapost | Bpost | Boxknight | Australiapost | AsendiaUs | Aramex | AmazonShipping | AlliedExpressLocal | AlliedExpress; export type PatchedCarrierConnectionData = {carrier_name?: ('allied_express' | 'allied_express_local' | 'amazon_shipping' | 'aramex' | 'asendia_us' | 'australiapost' | 'boxknight' | 'bpost' | 'canadapost' | 'canpar' | 'chronopost' | 'colissimo' | 'dhl_express' | 'dhl_parcel_de' | 'dhl_poland' | 'dhl_universal' | 'dicom' | 'dpd' | 'dpdhl' | 'easypost' | 'easyship' | 'eshipper' | 'fedex' | 'fedex_ws' | 'freightcom' | 'generic' | 'geodis' | 'hay_post' | 'laposte' | 'locate2u' | 'nationex' | 'purolator' | 'roadie' | 'royalmail' | 'sapient' | 'seko' | 'sendle' | 'tge' | 'tnt' | 'ups' | 'usps' | 'usps_international' | 'usps_wt' | 'usps_wt_international' | 'zoom2u') | undefined, carrier_id?: string | undefined, credentials?: ConnectionCredentialsField | undefined, capabilities?: (Array | null) | undefined, config?: {[key: string]: unknown} | undefined, metadata?: {[key: string]: unknown} | undefined, active?: boolean | undefined}; export type PatchApiV1ConnectionsIdArgs = {id: string, body: PatchedCarrierConnectionData}; export type PatchApiV1ConnectionsIdOptions = {baseUrl: string, TokenBasic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const zoom2u = z.object({api_key: z.string()}); export const uspsWtInternational = z.object({username: z.string(), password: z.string(), mailer_id: z.string().optional(), customer_registration_id: z.string().optional(), logistics_manager_mailer_id: z.string().optional()}); export const uspsWt = z.object({username: z.string(), password: z.string(), mailer_id: z.string().optional(), customer_registration_id: z.string().optional(), logistics_manager_mailer_id: z.string().optional()}); export const uspsInternational = z.object({client_id: z.string(), client_secret: z.string(), account_number: z.string().optional(), account_type: z.enum(["EPS", "PERMIT", "METER"]).optional(), manifest_MID: z.string().optional(), CRID: z.string().optional(), MID: z.string().optional()}); export const usps = z.object({client_id: z.string(), client_secret: z.string(), account_number: z.string().optional(), account_type: z.enum(["EPS", "PERMIT", "METER"]).optional(), manifest_MID: z.string().optional(), CRID: z.string().optional(), MID: z.string().optional()}); export const ups = z.object({client_id: z.string(), client_secret: z.string(), account_number: z.string().optional(), account_country_code: z.string().optional()}); export const tnt = z.object({username: z.string(), password: z.string(), account_number: z.string().optional(), account_country_code: z.string().optional()}); export const tge = z.object({username: z.string(), password: z.string(), api_key: z.string(), toll_username: z.string(), toll_password: z.string(), my_toll_token: z.string(), my_toll_identity: z.string(), account_code: z.string().optional(), sscc_count: z.number().int().optional(), shipment_count: z.number().int().optional()}); export const sendle = z.object({sendle_id: z.string(), api_key: z.string(), account_country_code: z.string().optional()}); export const seko = z.object({access_key: z.string()}); export const sapient = z.object({client_id: z.string(), client_secret: z.string(), shipping_account_id: z.string(), sapient_carrier_code: z.enum(["DX", "EVRI", "RM", "UPS", "YODEL"]).optional()}); export const royalmail = z.object({client_id: z.string(), client_secret: z.string()}); export const roadie = z.object({api_key: z.string()}); export const purolator = z.object({username: z.string(), password: z.string(), account_number: z.string(), user_token: z.string().optional(), language: z.enum(["en", "fr"]).optional()}); export const nationex = z.object({api_key: z.string(), customer_id: z.string(), billing_account: z.string().optional(), language: z.enum(["en", "fr"]).optional()}); export const locate2u = z.object({client_id: z.string().optional(), client_secret: z.string().optional()}); export const laposte = z.object({api_key: z.string(), lang: z.enum(["fr_FR", "en_US"]).optional()}); export const hayPost = z.object({username: z.string(), password: z.string(), customer_id: z.string(), customer_type: z.string()}); export const geodis = z.object({api_key: z.string(), identifier: z.string(), code_client: z.string().optional(), language: z.enum(["fr", "en"]).optional()}); export const generic = z.object({display_name: z.string(), custom_carrier_name: z.string(), account_country_code: z.string().optional(), account_number: z.string().optional()}); export const freightcom = z.object({username: z.string(), password: z.string()}); export const fedexWs = z.object({password: z.string(), meter_number: z.string(), account_number: z.string(), user_key: z.string().optional(), language_code: z.string().optional(), account_country_code: z.string().optional()}); export const fedex = z.object({api_key: z.string().optional(), secret_key: z.string().optional(), account_number: z.string().optional(), track_api_key: z.string().optional(), track_secret_key: z.string().optional(), account_country_code: z.string().optional()}); export const eshipper = z.object({principal: z.string(), credential: z.string()}); export const easyship = z.object({access_token: z.string()}); export const easypost = z.object({api_key: z.string()}); export const dpdhl = z.object({username: z.string(), password: z.string(), app_id: z.string().optional(), app_token: z.string().optional(), zt_id: z.string().optional(), zt_password: z.string().optional(), account_number: z.string().optional()}); export const dpd = z.object({delis_id: z.string(), password: z.string(), depot: z.string().optional(), message_language: z.string().optional(), account_country_code: z.string().optional()}); export const dicom = z.object({username: z.string(), password: z.string(), billing_account: z.string().optional()}); export const dhlUniversal = z.object({consumer_key: z.string(), consumer_secret: z.string(), language: z.enum(["en", "de"]).optional()}); export const dhlPoland = z.object({username: z.string(), password: z.string(), account_number: z.string().optional()}); export const dhlParcelDe = z.object({username: z.string(), password: z.string(), dhl_api_key: z.string(), customer_number: z.string().optional(), tracking_consumer_key: z.string().optional(), tracking_consumer_secret: z.string().optional()}); export const dhlExpress = z.object({site_id: z.string(), password: z.string(), account_number: z.string().optional(), account_country_code: z.string().optional()}); export const colissimo = z.object({password: z.string(), contract_number: z.string(), laposte_api_key: z.string().optional()}); export const chronopost = z.object({account_number: z.string(), password: z.string(), id_emit: z.string().optional(), language: z.enum(["en_GB", "fr_FR"]).optional()}); export const canpar = z.object({username: z.string(), password: z.string(), language: z.enum(["en", "fr"]).optional()}); export const canadapost = z.object({username: z.string(), password: z.string(), customer_number: z.string().optional(), contract_id: z.string().optional(), language: z.enum(["en", "fr"]).optional()}); export const bpost = z.object({account_id: z.string(), passphrase: z.string()}); export const boxknight = z.object({username: z.string(), password: z.string()}); export const australiapost = z.object({api_key: z.string(), password: z.string(), account_number: z.string()}); export const asendiaUs = z.object({username: z.string(), password: z.string(), api_key: z.string(), account_number: z.string().optional()}); export const aramex = z.object({username: z.string(), password: z.string(), account_pin: z.string(), account_entity: z.string(), account_number: z.string(), account_country_code: z.string()}); export const amazonShipping = z.object({seller_id: z.string(), developer_id: z.string(), mws_auth_token: z.string(), aws_region: z.string().optional(), account_country_code: z.string().optional()}); export const alliedExpressLocal = z.object({username: z.string(), password: z.string(), account: z.string().optional(), service_type: z.enum(["R", "P", "PT", "PT2"]).optional()}); export const alliedExpress = z.object({username: z.string(), password: z.string(), account: z.string().optional(), service_type: z.enum(["R", "P", "PT", "PT2"]).optional()}); export const connectionCredentialsField = z.union([zoom2u, uspsWtInternational, uspsWt, uspsInternational, usps, ups, tnt, tge, sendle, seko, sapient, royalmail, roadie, purolator, nationex, locate2u, laposte, hayPost, geodis, generic, freightcom, fedexWs, fedex, eshipper, easyship, easypost, dpdhl, dpd, dicom, dhlUniversal, dhlPoland, dhlParcelDe, dhlExpress, colissimo, chronopost, canpar, canadapost, bpost, boxknight, australiapost, asendiaUs, aramex, amazonShipping, alliedExpressLocal, alliedExpress]); export const carrierConnection = z.object({id: z.string(), object_type: z.string().optional(), carrier_name: z.enum(["allied_express", "allied_express_local", "amazon_shipping", "aramex", "asendia_us", "australiapost", "boxknight", "bpost", "canadapost", "canpar", "chronopost", "colissimo", "dhl_express", "dhl_parcel_de", "dhl_poland", "dhl_universal", "dicom", "dpd", "dpdhl", "easypost", "easyship", "eshipper", "fedex", "fedex_ws", "freightcom", "generic", "geodis", "hay_post", "laposte", "locate2u", "nationex", "purolator", "roadie", "royalmail", "sapient", "seko", "sendle", "tge", "tnt", "ups", "usps", "usps_international", "usps_wt", "usps_wt_international", "zoom2u"]), display_name: z.string().optional(), carrier_id: z.string(), credentials: connectionCredentialsField.optional(), capabilities: z.array(z.string()).nullable().optional(), config: z.record(z.string(), z.unknown()).optional(), metadata: z.record(z.string(), z.unknown()).optional(), is_system: z.boolean(), active: z.boolean(), test_mode: z.boolean()}); 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 a connection * * PATCH /v1/connections/{id} * * Also accepts auth: Token, OAuth2, JWT */ export const patchApiV1ConnectionsId = async (args: PatchApiV1ConnectionsIdArgs, options: PatchApiV1ConnectionsIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, TokenBasic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (TokenBasic !== undefined) headers.set('authorization', `Basic ${btoa(`${TokenBasic.username}:${TokenBasic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/connections/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(carrierConnection, await res.json()) };