import {z} from 'zod' export type CapacityProviderAccountInfo = {accountDefinitionIdentifier?: string | undefined, accountFlag1?: boolean | undefined, accountNumber1?: string | undefined, accountNumber2?: string | undefined, billToLocationId?: string | undefined, credential1?: string | undefined, credential2?: string | undefined, credential3?: string | undefined, directionCode?: ('SHIPPER' | 'CONSIGNEE' | 'THIRD_PARTY') | undefined, enableDirectionOverride?: boolean | undefined, enablePaymentTermsOverride?: boolean | undefined, id?: number | undefined, oAuth2LoginUrl?: string | undefined, oAuth2SignupUrl?: string | undefined, paymentTermsCode?: ('PREPAID' | 'COLLECT' | 'THIRD_PARTY') | undefined, username1?: string | undefined}; export type CapacityProviderIdentifier = {type?: ('SCAC' | 'DOT_NUMBER' | 'MC_NUMBER' | 'P44_EU' | 'SYSTEM' | 'P44_GLOBAL' | 'VAT') | undefined, value?: string | undefined}; export type CapacityProviderAccountGroupInfo = {code?: string | undefined, id?: number | undefined, name?: string | undefined}; export type CapacityProviderAccountInfos = {accounts?: Array | undefined, capacityProviderIdentifier?: CapacityProviderIdentifier | undefined, code?: string | undefined, group?: CapacityProviderAccountGroupInfo | undefined, id?: number | undefined}; export type UpdateApiApiV4CapacityprovideraccountsIdArgs = {id: number, body: CapacityProviderAccountInfos}; export type UpdateApiApiV4CapacityprovideraccountsIdOptions = {baseUrl?: string | undefined, oAuth2?: string | undefined, fetch?: typeof fetch | undefined}; export const capacityProviderAccountInfo = z.object({accountDefinitionIdentifier: z.string().optional(), accountFlag1: z.boolean().optional(), accountNumber1: z.string().optional(), accountNumber2: z.string().optional(), billToLocationId: z.string().optional(), credential1: z.string().optional(), credential2: z.string().optional(), credential3: z.string().optional(), directionCode: z.enum(["SHIPPER", "CONSIGNEE", "THIRD_PARTY"]).optional(), enableDirectionOverride: z.boolean().optional(), enablePaymentTermsOverride: z.boolean().optional(), id: z.number().int().optional(), oAuth2LoginUrl: z.string().optional(), oAuth2SignupUrl: z.string().optional(), paymentTermsCode: z.enum(["PREPAID", "COLLECT", "THIRD_PARTY"]).optional(), username1: z.string().optional()}); export const capacityProviderIdentifier = z.object({type: z.enum(["SCAC", "DOT_NUMBER", "MC_NUMBER", "P44_EU", "SYSTEM", "P44_GLOBAL", "VAT"]).optional(), value: z.string().optional()}); export const capacityProviderAccountGroupInfo = z.object({code: z.string().optional(), id: z.number().int().optional(), name: z.string().optional()}); export const capacityProviderAccountInfos = z.object({accounts: z.array(capacityProviderAccountInfo).optional(), capacityProviderIdentifier: capacityProviderIdentifier.optional(), code: z.string().optional(), group: capacityProviderAccountGroupInfo.optional(), id: z.number().int().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 }; /** * Update the capacity provider account. * * PUT /api/v4/capacityprovideraccounts/{id} */ export const updateApiApiV4CapacityprovideraccountsId = async (args: UpdateApiApiV4CapacityprovideraccountsIdArgs, options?: UpdateApiApiV4CapacityprovideraccountsIdOptions) => { const {baseUrl = "https://na12.api.project44.com", fetch: fetchFn = fetch, oAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oAuth2 !== undefined) headers.set('authorization', `Bearer ${oAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v4/capacityprovideraccounts/${encodeURIComponent(String(args.id))}${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(capacityProviderAccountInfos, await res.json()) };