import {z} from 'zod' export type CarrierLabelEndOfDayUpdate = {carrierId: string, originCountry: string, originPostal: string, partnerManifestId: string, fromDateTime?: string | undefined, toDateTime?: string | undefined}; export type UpdateApiApiV1DeliveryexperienceShipmentCarrierSelectionLabelsEndOfDayManifestArgs = {body: CarrierLabelEndOfDayUpdate}; export type UpdateApiApiV1DeliveryexperienceShipmentCarrierSelectionLabelsEndOfDayManifestOptions = {baseUrl?: string | undefined, oauth2Scheme?: string | undefined, fetch?: typeof fetch | undefined}; export const updateResult = z.object({matched: z.number().int(), updated: z.number().int()}); 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 }; /** * Set the partner manifest id and timestamp for any (matching) labels that meet the supplied criteria, are eligible for manifesting, and have not been manifested. * * PUT /api/v1/deliveryexperience/shipment/carrierSelection/labels/endOfDayManifest */ export const updateApiApiV1DeliveryexperienceShipmentCarrierSelectionLabelsEndOfDayManifest = async (args: UpdateApiApiV1DeliveryexperienceShipmentCarrierSelectionLabelsEndOfDayManifestArgs, options?: UpdateApiApiV1DeliveryexperienceShipmentCarrierSelectionLabelsEndOfDayManifestOptions) => { const {baseUrl = "https://api.shipium.com", fetch: fetchFn = fetch, oauth2Scheme} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2Scheme !== undefined) headers.set('authorization', `Bearer ${oauth2Scheme}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/deliveryexperience/shipment/carrierSelection/labels/endOfDayManifest${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(updateResult, await res.json()) };