import {z} from 'zod' export type CreateApiWarehouseIdIdActivateArgs = {id: string, body: Record}; export type CreateApiWarehouseIdIdActivateOptions = {baseUrl: string, APIToken?: string | undefined, fetch?: typeof fetch | undefined}; export const entityReference = z.object({entityId: z.string().optional(), entityName: z.string().optional()}); export const onlyId = z.object({id: z.string().optional()}); export const customAttribute = z.object({attributeDefinitionId: z.string().optional(), booleanValue: z.boolean().optional(), dateValue: z.number().int().optional(), entityId: z.string().optional(), entityReferences: z.array(entityReference).optional(), numberValue: z.string().optional(), selectedValueId: z.string().optional(), selectedValues: z.array(onlyId).optional(), stringValue: z.string().optional()}); export const address = z.object({id: z.string().optional(), version: z.string().optional(), city: z.string().optional(), company: z.string().optional(), company2: z.string().optional(), countryCode: z.enum(["AC", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AN", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CS", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DG", "DJ", "DK", "DM", "DO", "DZ", "EA", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "EU", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "IC", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TA", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "UNKNOWN", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "XI", "XK", "YE", "YT", "ZA", "ZM", "ZW"]), createdDate: z.number().int().optional(), deliveryAddress: z.boolean().optional(), firstName: z.string().optional(), globalLocationNumber: z.string().optional(), invoiceAddress: z.boolean().optional(), lastModifiedDate: z.number().int().optional(), lastName: z.string().optional(), phoneNumber: z.string().optional(), postOfficeBoxCity: z.string().optional(), postOfficeBoxNumber: z.string().optional(), postOfficeBoxZipCode: z.string().optional(), primaryAddress: z.boolean().optional(), salutation: z.enum(["COMPANY", "FAMILY", "MR", "MRS", "NO_SALUTATION"]).optional(), state: z.string().optional(), street1: z.string().optional(), street2: z.string().optional(), titleId: z.string().optional(), zipcode: z.string().optional()}); export const minimalStoragePlace = z.object({id: z.string().optional(), version: z.string().optional(), createdDate: z.number().int().optional(), customAttributes: z.array(customAttribute).optional(), lastModifiedDate: z.number().int().optional(), name: z.string()}); export const warehouse = z.object({id: z.string().optional(), version: z.string().optional(), active: z.boolean().optional(), createdDate: z.number().int().optional(), customAttributes: z.array(customAttribute).optional(), defaultConsolidationStoragePlaceId: z.string().optional(), defaultProductionStoragePlaceId: z.string().optional(), defaultReturnsStoragePlaceId: z.string().optional(), defaultStoragePlaceId: z.string().optional(), deliveryAddress: address.optional(), directBookingInternalTransportReferenceId: z.string().optional(), invoiceAddress: address.optional(), lastModifiedDate: z.number().int().optional(), loadingEquipmentStoragePlace: minimalStoragePlace.optional(), name: z.string(), primaryAddress: address.optional(), shortIdentifier: z.string().optional(), standard: z.boolean().optional(), transitStoragePlace: minimalStoragePlace.optional(), warehouseType: z.enum(["CONSIGNMENT", "DROP_SHIPPING", "STANDARD"]).optional()}); export const createApiWarehouseIdIdActivateResponse = z.object({result: warehouse.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 }; /** * POST /warehouse/id/{id}/activate */ export const createApiWarehouseIdIdActivate = async (args: CreateApiWarehouseIdIdActivateArgs, options: CreateApiWarehouseIdIdActivateOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIToken !== undefined) headers.set("AuthenticationToken", APIToken) const url = `${baseUrl.replace(/\/+$/, '')}/warehouse/id/${encodeURIComponent(String(args.id))}/activate${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(createApiWarehouseIdIdActivateResponse, await res.json()) };