import {z} from 'zod' export type DeleteApiOrchestratorCartsCartIdItemsArgs = {'x-fabric-tenant-id': string, 'x-fabric-request-id'?: string | undefined, 'x-fabric-channel-id': string, cartId: string, itemId: string}; export type DeleteApiOrchestratorCartsCartIdItemsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const attributes = z.record(z.string(), z.string()); export const orderValidateConfiguration = z.object({paymentsRemaining: z.enum(["BLOCK", "NONE"]).optional(), taxRemaining: z.enum(["BLOCK", "NONE"]).optional(), invalidItem: z.enum(["BLOCK", "NONE"]).optional(), itemOutOfStock: z.enum(["BLOCK", "NONE"]).optional()}); export const orderConfiguration = z.object({validate: orderValidateConfiguration.optional()}); export const productBehaviour = z.object({add: z.enum(["WARN", "DROP", "REJECT", "NONE"]).optional(), update: z.enum(["WARN", "DROP", "REJECT", "NONE"]).optional(), get: z.enum(["WARN", "DROP", "REJECT", "NONE"]).optional(), cacheExpiry: z.enum(["WARN", "DROP", "REJECT", "NONE"]).optional()}); export const maxQtyBehaviour = z.object({add: z.enum(["WARN", "DROP", "REJECT", "NONE"]).optional(), update: z.enum(["WARN", "DROP", "REJECT", "NONE"]).optional(), get: z.enum(["WARN", "DROP", "REJECT", "NONE"]).optional()}); export const maxQtyConfiguration = z.object({limit: z.number().int().optional(), behaviors: maxQtyBehaviour.optional()}); export const productConfiguration = z.object({cacheExpiry: z.number().int().optional(), behaviors: productBehaviour.optional(), maxQuantity: maxQtyConfiguration.optional()}); export const inventoryBehaviour = z.object({add: z.enum(["WARN", "DROP", "REJECT", "NONE"]).optional(), update: z.enum(["WARN", "DROP", "REJECT", "NONE"]).optional(), get: z.enum(["WARN", "DROP", "REJECT", "NONE"]).optional(), cacheExpiry: z.enum(["WARN", "DROP", "REJECT", "NONE"]).optional()}); export const inventoryConfiguration = z.object({cacheExpiry: z.number().int().optional(), behaviors: inventoryBehaviour.optional(), check: z.enum(["SKU", "LINE_ITEM"]).optional()}); export const taxBehaviour = z.object({cacheExpiry: z.enum(["WARN", "NONE"]).optional()}); export const taxConfiguration = z.object({cacheExpiry: z.number().int().optional(), behaviors: taxBehaviour.optional()}); export const configurationValue = z.enum(["BLOCK", "REJECT", "WARN", "NONE"]); export const behavior = z.object({add: configurationValue.optional(), update: configurationValue.optional(), get: configurationValue.optional(), cacheExpiry: configurationValue.optional()}); export const promotionsConfiguration = z.object({cacheExpiry: z.number().int().optional(), behaviors: behavior.optional()}); export const cartConfiguration = z.object({order: orderConfiguration.optional(), product: productConfiguration.optional(), inventory: inventoryConfiguration.optional(), tax: taxConfiguration.optional(), promotions: promotionsConfiguration.optional()}); export const segmentObject = z.object({name: z.string().optional(), value: z.array(z.string()).optional()}); export const customerContext = z.object({id: z.string().optional(), segments: z.array(segmentObject).optional(), attributes: z.record(z.string(), z.object({})).optional(), sessionId: z.string().optional()}); export const state = z.object({resource: z.enum(["ITEM", "CART", "FULFILLMENT", "PAYMENT", "FEE", "VALIDATION"]).optional(), resourceId: z.string().optional(), key: z.string().optional(), description: z.string().optional()}); export const priceDetail = z.object({total: z.number().optional(), subtotal: z.number().optional(), tax: z.number().optional(), fulfillments: z.number().optional(), discounts: z.number().optional(), fees: z.number().optional(), adjustments: z.number().optional()}); export const promotion = z.object({id: z.string().optional(), title: z.string().optional(), type: z.string().optional(), value: z.number().optional(), attributes: z.record(z.string(), z.string()).optional()}); export const promotions = z.object({total: z.number().optional(), collection: z.array(promotion).optional()}); export const resourcePrice = z.object({amount: z.number().gte(0)}); export const tax = z.object({amount: z.number().optional(), attributes: z.record(z.string(), z.object({})).optional()}); export const taxCollection = z.object({total: z.number().optional(), collection: z.array(tax).optional()}); export const feeTaxDetails = z.object({destinationAddress: z.string().optional(), originAddress: z.string().optional()}); export const fee = z.object({id: z.string().optional(), name: z.string().optional(), price: resourcePrice.optional(), taxable: z.boolean().optional(), attributes: z.record(z.string(), z.object({})).optional(), tax: taxCollection.optional(), updatedAt: z.string().optional(), createdAt: z.string().optional(), taxDetails: feeTaxDetails.optional()}); export const adjustment = z.object({id: z.string().optional(), price: resourcePrice.optional(), reason: z.string().optional(), attributes: z.record(z.string(), z.object({})).optional(), updatedAt: z.string().optional(), createdAt: z.string().optional()}); export const adjustmentCollection = z.object({total: z.number().optional(), collection: z.array(adjustment).optional()}); export const name = z.object({first: z.string().optional(), last: z.string().optional()}); export const phone = z.object({number: z.string().optional(), type: z.string().optional()}); export const address = z.object({id: z.string().optional(), name: name.optional(), email: z.string().optional(), phone: phone.optional(), addressLine1: z.string().optional(), addressLine2: z.string().optional(), addressLine3: z.string().optional(), addressLine4: z.string().optional(), city: z.string().optional(), region: z.string().optional(), country: z.string().optional(), postalCode: z.string().optional(), updatedAt: z.string().optional(), createdAt: z.string().optional()}); export const itemPrice = z.object({unit: z.number().optional(), amount: z.number().optional()}); export const feesCollection = z.object({total: z.number().optional(), collection: z.array(fee).optional()}); export const proration = z.object({amount: z.number().optional(), quantity: z.number().int().optional()}); export const prorationSpread = z.object({spread: z.array(proration).optional()}); export const itemPromotion = z.object({id: z.string().optional(), amount: z.number().optional(), quantity: z.number().int().optional(), proration: prorationSpread.optional()}); export const itemPromotionsCollection = z.object({total: z.number().optional(), collection: z.array(itemPromotion).optional()}); export const inventory = z.object({channels: z.object({type: z.string().optional(), locationNumber: z.string().optional(), channelId: z.string().optional(), networkCode: z.string().optional()}).optional(), type: z.string().optional()}); export const itemFulfillment = z.object({id: z.string().optional(), price: resourcePrice.optional(), inventory: inventory.optional(), tax: taxCollection.optional()}); export const itemResponseDto = z.object({id: z.string().optional(), sku: z.string().optional(), refId: z.string().optional(), quantity: z.number().int().optional(), priceListId: z.string().optional(), position: z.number().int().optional(), price: itemPrice.optional(), fees: feesCollection.optional(), promotions: itemPromotionsCollection.optional(), adjustments: adjustmentCollection.optional(), fulfillment: itemFulfillment.optional(), attributes: z.record(z.string(), z.object({})).optional(), tax: taxCollection.optional(), taxCode: z.string().optional(), updatedAt: z.string().optional(), createdAt: z.string().optional()}); export const itemCollection = z.object({total: z.number().optional(), collection: z.array(itemResponseDto).optional()}); export const summary = z.object({totalItems: z.number().int().optional(), totalUniqueItems: z.number().int().optional()}); export const person = z.object({name: name, email: z.string().optional(), phone: phone.optional()}); export const pickupPerson = z.object({primary: person.optional(), secondary: z.array(person).optional()}); export const fulfillmentPromotion = z.object({id: z.string().optional(), amount: z.number().optional()}); export const fulfillmentPromotionCollection = z.object({total: z.number().optional(), collection: z.array(fulfillmentPromotion).optional()}); export const fulfillment = z.object({id: z.string().optional(), type: z.enum(["SHIP_TO", "BOPIS", "ROPIS"]).optional(), refId: z.string().optional(), attributes: z.record(z.string(), z.object({})).optional(), originAddress: z.string().optional(), destinationAddress: z.string().optional(), locationId: z.string().optional(), pickupPerson: pickupPerson.optional(), price: resourcePrice.optional(), promotions: fulfillmentPromotionCollection.optional(), fees: feesCollection.optional(), adjustments: adjustmentCollection.optional(), tax: taxCollection.optional()}); export const coupon = z.object({code: z.string().optional(), updatedAt: z.string().optional()}); export const promotionValidationData = z.object({updatedAt: z.string().optional(), appliedCoupons: z.array(z.string()).optional(), refreshRequired: z.boolean().optional()}); export const inventoryValidationData = z.object({channels: z.record(z.string(), z.string()).optional(), counters: z.record(z.string(), z.number().int()).optional(), updatedAt: z.string().optional()}); export const lineItemValidationData = z.object({sku: z.string().optional(), inventory: inventoryValidationData.optional()}); export const sKUValidationData = z.object({sku: z.string().optional(), updatedAt: z.string().optional(), maxQuantity: z.number().int().optional()}); export const pIMValidationData = z.object({availableSkus: z.array(sKUValidationData).optional()}); export const taxValidationData = z.object({updatedAt: z.string().optional()}); export const validationData = z.object({promotions: promotionValidationData.optional(), lineItems: z.array(lineItemValidationData).optional(), product: pIMValidationData.optional(), tax: taxValidationData.optional()}); export const verifier = z.object({type: z.string().optional(), key: z.string().optional()}); export const paymentAuthorization = z.object({amount: z.number().gt(0), expiry: z.string().optional(), verifier: verifier.optional()}); export const payment = z.object({id: z.string().optional(), provider: z.string().optional(), processor: z.string().optional(), method: z.string().optional(), methodType: z.string().optional(), state: z.enum(["PENDING", "AUTHORIZED", "CAPTURED", "FAILED"]).optional(), authorization: paymentAuthorization.optional(), billToAddress: z.string().optional(), cardDetails: z.record(z.string(), z.object({})).optional(), attributes: z.record(z.string(), z.object({})).optional()}); export const paymentCollection = z.object({authorized: z.number().optional(), collection: z.array(payment).optional()}); export const suggestedProduct = z.object({id: z.string().optional(), name: z.string().optional(), description: z.string().optional(), price: z.number().optional()}); export const promotionMessage = z.object({message: z.string().optional(), code: z.string().optional()}); export const error = z.object({code: z.string().optional(), message: z.string().optional()}); export const cartResponse = z.object({id: z.string().optional(), attributes: attributes.optional(), configuration: cartConfiguration.optional(), customerContext: customerContext.optional(), status: z.enum(["ACTIVE", "SOFT_DELETE"]).optional(), state: z.array(state).optional(), price: priceDetail.optional(), promotions: promotions.optional(), fees: fee.optional(), adjustments: adjustmentCollection.optional(), addresses: z.object({a8577d7f0d4d4b228e857b4a2e90dc93: address.optional()}).optional(), lineItems: itemCollection.optional(), summary: summary.optional(), fulfillments: z.object({d6229cdb0c5b4885b1b213b94d02488e: fulfillment.optional()}).optional(), coupons: z.array(coupon).optional(), appliedCoupons: z.array(coupon).optional(), notAppliedCoupons: z.array(coupon).optional(), validations: validationData.optional(), payments: paymentCollection.optional(), channelId: z.string().optional(), currency: z.string().optional(), updatedAt: z.string().optional(), createdAt: z.string().optional(), suggestedProducts: z.array(suggestedProduct).optional(), promotionMessages: z.array(promotionMessage).optional(), errors: z.array(error).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 }; /** * Delete items * * DELETE /orchestrator/carts/{cartId}/items */ export const deleteApiOrchestratorCartsCartIdItems = async (args: DeleteApiOrchestratorCartsCartIdItemsArgs, options?: DeleteApiOrchestratorCartsCartIdItemsOptions) => { const {baseUrl = "https://api.fabric.inc/v3", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['x-fabric-tenant-id'] != null) headers.set("x-fabric-tenant-id", String(args['x-fabric-tenant-id'])) if (args['x-fabric-request-id'] != null) headers.set("x-fabric-request-id", String(args['x-fabric-request-id'])) if (args['x-fabric-channel-id'] != null) headers.set("x-fabric-channel-id", String(args['x-fabric-channel-id'])) if (args.itemId != null) query.append("itemId", String(args.itemId)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/orchestrator/carts/${encodeURIComponent(String(args.cartId))}/items${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "DELETE", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(cartResponse, await res.json()) };