@atomic-solutions/woocommerce-api-client 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
- import { W as WooCommerceConfig, a as WooCommerceClient } from '../types-aYzN4O5x.mjs';
2
- export { P as PaginatedResponse, R as ResponseOptions, V as ValidationMode, h as handleApiData, b as handleApiResponse, c as handlePaginatedApiResponse, i as isZodError, s as setupErrorInterceptor } from '../types-aYzN4O5x.mjs';
1
+ import { W as WooCommerceConfig, a as WooCommerceClient } from '../types-9I6oS_83.mjs';
2
+ export { P as PaginatedResponse, R as ResponseOptions, V as ValidationMode, h as handleApiData, b as handleApiResponse, c as handlePaginatedApiResponse, i as isZodError, s as setupErrorInterceptor } from '../types-9I6oS_83.mjs';
3
3
  import { AxiosInstance } from 'axios';
4
+ import '@atomic-solutions/errors';
4
5
  import 'zod';
5
6
 
6
7
  declare const setupRequestInterceptor: (axiosInstance: AxiosInstance, config: WooCommerceConfig, client: WooCommerceClient) => void;
@@ -1,6 +1,7 @@
1
- import { W as WooCommerceConfig, a as WooCommerceClient } from '../types-aYzN4O5x.js';
2
- export { P as PaginatedResponse, R as ResponseOptions, V as ValidationMode, h as handleApiData, b as handleApiResponse, c as handlePaginatedApiResponse, i as isZodError, s as setupErrorInterceptor } from '../types-aYzN4O5x.js';
1
+ import { W as WooCommerceConfig, a as WooCommerceClient } from '../types-9I6oS_83.js';
2
+ export { P as PaginatedResponse, R as ResponseOptions, V as ValidationMode, h as handleApiData, b as handleApiResponse, c as handlePaginatedApiResponse, i as isZodError, s as setupErrorInterceptor } from '../types-9I6oS_83.js';
3
3
  import { AxiosInstance } from 'axios';
4
+ import '@atomic-solutions/errors';
4
5
  import 'zod';
5
6
 
6
7
  declare const setupRequestInterceptor: (axiosInstance: AxiosInstance, config: WooCommerceConfig, client: WooCommerceClient) => void;
@@ -1,7 +1,16 @@
1
1
  'use strict';
2
2
 
3
+ var errors = require('@atomic-solutions/errors');
3
4
  var axios = require('axios');
4
5
 
6
+ var __typeError = (msg) => {
7
+ throw TypeError(msg);
8
+ };
9
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
10
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
11
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
12
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
13
+
5
14
  // src/errors/classes/BaseError.ts
6
15
  var BaseError = class extends Error {
7
16
  constructor(options) {
@@ -129,8 +138,16 @@ var WOOCOMMERCE_ERROR_METADATA = {
129
138
  }
130
139
  };
131
140
 
141
+ // src/errors/classes/http-error.ts
142
+ var redactPath = (url) => url.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/]+/i, "").replace(/[?#].*$/, "").split("/").map((segment) => /^(\d+|[0-9a-f]{16,}|[0-9a-f-]{36})$/i.test(segment) ? ":id" : segment).join("/");
143
+ var classifyHttpStatus = (status) => ({
144
+ domain: status === void 0 ? "network" : status === 401 || status === 403 ? "auth" : "integration",
145
+ severity: status !== void 0 && status < 500 ? "warning" : "error"
146
+ });
147
+
132
148
  // src/errors/classes/WooCommerceApiError.ts
133
- var WooCommerceApiError = class extends BaseError {
149
+ var _options;
150
+ var WooCommerceApiError = class extends errors.BaseError {
134
151
  constructor(options) {
135
152
  const metadata = WOOCOMMERCE_ERROR_METADATA[options.code] ?? {
136
153
  operation: "woocommerce_api_request",
@@ -142,7 +159,30 @@ var WooCommerceApiError = class extends BaseError {
142
159
  userMessage: options.userMessage || metadata.userMessage,
143
160
  retryable: options.retryable ?? metadata.retryable
144
161
  };
145
- super(enrichedOptions);
162
+ const status = enrichedOptions.statusCode;
163
+ const { domain, severity } = classifyHttpStatus(status);
164
+ super({
165
+ domain,
166
+ severity,
167
+ operation: enrichedOptions.operation,
168
+ message: enrichedOptions.message,
169
+ code: enrichedOptions.code,
170
+ retryable: enrichedOptions.retryable,
171
+ userMessage: enrichedOptions.userMessage,
172
+ cause: enrichedOptions.cause,
173
+ fingerprint: [domain, enrichedOptions.code, String(status ?? "network")],
174
+ extras: {
175
+ originalCode: enrichedOptions.originalCode,
176
+ statusCode: status,
177
+ path: redactPath(enrichedOptions.url),
178
+ method: enrichedOptions.method
179
+ }
180
+ });
181
+ __privateAdd(this, _options);
182
+ __privateSet(this, _options, enrichedOptions);
183
+ }
184
+ get options() {
185
+ return __privateGet(this, _options);
146
186
  }
147
187
  // Convenient getters for frequently accessed fields (no duplication)
148
188
  get wooCode() {
@@ -169,24 +209,8 @@ var WooCommerceApiError = class extends BaseError {
169
209
  get data() {
170
210
  return this.options.data;
171
211
  }
172
- /**
173
- * Get reportable data for error tracking/logging
174
- * Includes HTTP context and WooCommerce-specific fields
175
- */
176
- getReportableData() {
177
- return {
178
- code: this.options.code,
179
- operation: this.options.operation,
180
- userMessage: this.options.userMessage,
181
- retryable: this.options.retryable,
182
- statusCode: this.options.statusCode,
183
- url: this.options.url,
184
- method: this.options.method,
185
- wooCode: this.options.code,
186
- originalCode: this.options.originalCode
187
- };
188
- }
189
212
  };
213
+ _options = new WeakMap();
190
214
 
191
215
  // src/errors/classes/WooCommerceDataValidationError.ts
192
216
  var WooCommerceDataValidationError = class _WooCommerceDataValidationError extends BaseError {
@@ -582,12 +606,15 @@ var setupErrorInterceptor = (axiosInstance, config, client) => {
582
606
  axiosInstance.interceptors.response.use(
583
607
  (response) => response,
584
608
  async (axiosError) => {
585
- const status = axiosError.response?.status || 500;
609
+ if (axios.isCancel(axiosError)) {
610
+ return Promise.reject(axiosError);
611
+ }
612
+ const status = axiosError.response?.status;
586
613
  const errorData = axiosError.response?.data;
614
+ const isNetworkError = axios.isAxiosError(axiosError) && !axiosError.response;
587
615
  const apiCode = errorData?.code || "unknown_error";
588
616
  const wpMessage = errorData?.message || axiosError.message || "Unknown error";
589
- const errorCode = mapWooCommerceCode(apiCode);
590
- const errorMetadata = WOOCOMMERCE_ERROR_METADATA[errorCode];
617
+ const errorCode = isNetworkError ? "network_error" : mapWooCommerceCode(apiCode);
591
618
  const wcError = new WooCommerceApiError({
592
619
  message: wpMessage,
593
620
  statusCode: status,
@@ -595,9 +622,6 @@ var setupErrorInterceptor = (axiosInstance, config, client) => {
595
622
  // Transformed app-level code
596
623
  originalCode: apiCode,
597
624
  // Original WooCommerce API code
598
- retryable: errorMetadata.retryable,
599
- userMessage: errorMetadata.userMessage,
600
- operation: errorMetadata.operation,
601
625
  url: axiosError.config?.url || "",
602
626
  method: axiosError.config?.method?.toUpperCase() || "GET",
603
627
  requestBody: axiosError.config?.data,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/errors/classes/BaseError.ts","../../src/errors/mapping/mapWooCommerceCode.ts","../../src/errors/mapping/constants.ts","../../src/errors/classes/WooCommerceApiError.ts","../../src/errors/classes/WooCommerceDataValidationError.ts","../../src/http/handleApiResponse.ts","../../src/utils/calculatePagination.ts","../../src/utils/getPaginationMeta.ts","../../src/http/handlePaginatedApiResponse.ts","../../src/logging/logger.ts","../../src/http/storeRoutes.ts","../../src/http/interceptors/request.ts","../../src/http/interceptors/response.ts","../../src/utils/initializeCartSession.ts","../../src/http/interceptors/error.ts"],"names":["error","AxiosError","isAxiosError"],"mappings":";;;;;AASO,IAAM,SAAA,GAAN,cAGG,KAAA,CAAM;AAAA,EACd,YAA4B,OAAA,EAAmB;AAC7C,IAAA,KAAA,CAAM,QAAQ,OAAO,CAAA;AADK,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAI1B,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,GAAA,CAAA,MAAA,CAAW,SAAS,CAAA;AAGhD,IAAA,IAAA,CAAK,IAAA,GAAO,KAAK,WAAA,CAAY,IAAA;AAG7B,IAAA,IAAI,MAAM,iBAAA,EAAmB;AAC3B,M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AAO,CAAA;AAEpC,MAAA,OAAO,OAAA,CAAQ,OAAO,OAAO,CAAA;AAAA,IAC/B;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * Base error class for all package errors\n *\n * Generic over:\n * - TOptions: The options type for this error class\n * - TReportable: The reportable data structure for error tracking\n */\nimport type { BaseErrorOptions, BaseReportableData } from './types';\n\nexport class BaseError<\n TOptions extends BaseErrorOptions = BaseErrorOptions,\n TReportable extends BaseReportableData = BaseReportableData,\n> extends Error {\n constructor(public readonly options: TOptions) {\n super(options.message);\n\n // Maintain proper prototype chain\n Object.setPrototypeOf(this, new.target.prototype);\n\n // Set error name\n this.name = this.constructor.name;\n\n // Capture stack trace (excluding constructor call)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n\n // If there's a cause with a stack, preserve it\n if (this.options.cause instanceof Error && this.options.cause.stack) {\n this.stack = `${this.stack}\\nCaused by: ${this.options.cause.stack}`;\n }\n }\n\n /**\n * Get reportable data for error tracking/logging\n * Subclasses should override this to add their own reportable fields\n */\n getReportableData(): TReportable {\n const { code, operation, userMessage, retryable } = this.options;\n return {\n code,\n operation,\n userMessage,\n retryable,\n } as TReportable;\n }\n\n /**\n * Custom JSON serialization\n * Makes the error properly serializable for logging/reporting\n */\n toJSON(): Record<string, unknown> {\n return {\n ...this.getReportableData(),\n name: this.name,\n message: this.message,\n stack: this.stack,\n } as unknown as Record<string, unknown>;\n }\n}\n","import type { WooCommerceApiErrorCode } from './types';\n\nexport const mapWooCommerceCode = (apiCode?: string): WooCommerceApiErrorCode => {\n if (!apiCode) return 'unknown_error';\n\n // Direct matches\n const directMatches: Record<string, WooCommerceApiErrorCode> = {\n woocommerce_rest_cart_empty: 'cart_empty',\n woocommerce_rest_cart_coupon_error: 'invalid_coupon',\n woocommerce_rest_missing_nonce: 'missing_nonce',\n woocommerce_rest_invalid_nonce: 'invalid_nonce',\n rest_invalid_param: 'invalid_params',\n woocommerce_rest_product_invalid_id: 'product_not_found',\n woocommerce_rest_product_out_of_stock: 'out_of_stock',\n woocommerce_rest_product_not_enough_stock: 'insufficient_stock',\n woocommerce_rest_checkout_invalid_payment_method: 'invalid_payment_method',\n };\n\n if (directMatches[apiCode]) {\n return directMatches[apiCode];\n }\n\n // Pattern matches\n if (apiCode.includes('nonce')) return 'invalid_nonce';\n if (apiCode.includes('coupon')) return 'invalid_coupon';\n if (apiCode.includes('stock')) return 'insufficient_stock';\n if (apiCode.includes('checkout')) return 'checkout_error';\n if (apiCode.includes('payment')) return 'invalid_payment_method';\n\n return 'unknown_error';\n};\n","import type { WooCommerceApiErrorCode, WooCommerceApiErrorMetaData } from './types';\n\nexport const WOOCOMMERCE_ERROR_METADATA: Record<\n WooCommerceApiErrorCode,\n WooCommerceApiErrorMetaData\n> = {\n cart_empty: {\n operation: 'get_cart',\n retryable: false,\n userMessage: 'Your cart is empty',\n },\n invalid_coupon: {\n operation: 'apply_coupon',\n retryable: false,\n userMessage: 'Invalid coupon code',\n },\n missing_nonce: {\n operation: 'cart_request',\n retryable: true, // Auto-retry with new nonce\n },\n invalid_nonce: {\n operation: 'cart_request',\n retryable: true, // Auto-retry with new nonce\n },\n invalid_params: {\n operation: 'api_request',\n retryable: false,\n userMessage: 'Invalid request parameters',\n },\n product_not_found: {\n operation: 'get_product',\n retryable: false,\n userMessage: 'Product not found',\n },\n out_of_stock: {\n operation: 'add_to_cart',\n retryable: false,\n userMessage: 'This product is out of stock',\n },\n insufficient_stock: {\n operation: 'add_to_cart',\n retryable: false,\n userMessage: 'Not enough stock available',\n },\n invalid_payment_method: {\n operation: 'process_checkout',\n retryable: false,\n userMessage: 'Invalid payment method',\n },\n checkout_error: {\n operation: 'process_checkout',\n retryable: false,\n },\n network_error: {\n operation: 'network_request',\n retryable: true,\n },\n unknown_error: {\n operation: 'unknown',\n retryable: false,\n },\n};\n","/**\n * WooCommerce API Error\n */\n\nimport { WOOCOMMERCE_ERROR_METADATA, type WooCommerceApiErrorCode } from '../mapping';\nimport { BaseError } from './BaseError';\nimport type { ApiReportableData, WooCommerceApiErrorOptions } from './types';\n\n/**\n * WooCommerce-specific error class\n *\n * Extends BaseError to provide:\n * - Code transformation (WooCommerce API codes → clean app codes)\n * - WooCommerce-specific error categorization\n * - HTTP context (status, URL, method)\n */\nexport class WooCommerceApiError extends BaseError<WooCommerceApiErrorOptions, ApiReportableData> {\n constructor(options: WooCommerceApiErrorOptions) {\n const metadata = WOOCOMMERCE_ERROR_METADATA[options.code] ?? {\n operation: 'woocommerce_api_request',\n retryable: false,\n };\n\n // Enrich options with metadata defaults\n const enrichedOptions: WooCommerceApiErrorOptions = {\n ...options,\n operation: options.operation || metadata.operation,\n userMessage: options.userMessage || metadata.userMessage,\n retryable: options.retryable ?? metadata.retryable,\n };\n\n super(enrichedOptions);\n }\n\n // Convenient getters for frequently accessed fields (no duplication)\n get wooCode(): WooCommerceApiErrorCode {\n return this.options.code;\n }\n\n get originalCode(): string {\n return this.options.originalCode;\n }\n\n get statusCode(): number {\n return this.options.statusCode;\n }\n\n get url(): string {\n return this.options.url;\n }\n\n get method(): string {\n return this.options.method;\n }\n\n get requestBody(): unknown | undefined {\n return this.options.requestBody;\n }\n\n get responseBody(): unknown | undefined {\n return this.options.responseBody;\n }\n\n get data(): Record<string, unknown> | undefined {\n return this.options.data;\n }\n\n /**\n * Get reportable data for error tracking/logging\n * Includes HTTP context and WooCommerce-specific fields\n */\n override getReportableData(): ApiReportableData {\n return {\n code: this.options.code,\n operation: this.options.operation,\n userMessage: this.options.userMessage,\n retryable: this.options.retryable,\n statusCode: this.options.statusCode,\n url: this.options.url,\n method: this.options.method,\n wooCode: this.options.code,\n originalCode: this.options.originalCode,\n };\n }\n}\n","/**\n * WooCommerce validation error class\n * Thrown when API response validation fails\n */\n\nimport type { ZodError } from 'zod';\n\nimport { BaseError } from './BaseError';\nimport type {\n BaseErrorOptions,\n ValidationReportableData,\n WooCommerceDataValidationErrorOptions,\n} from './types';\n\n/**\n * Internal options type that combines user options with computed fields\n */\ninterface WooCommerceDataValidationErrorInternalOptions extends BaseErrorOptions {\n url?: string;\n zodError?: ZodError;\n value?: unknown;\n fieldErrors?: Record<string, string[]>;\n}\n\n/**\n * WooCommerce validation error\n *\n * Thrown when API response validation fails using Zod schemas\n */\nexport class WooCommerceDataValidationError extends BaseError<\n WooCommerceDataValidationErrorInternalOptions,\n ValidationReportableData\n> {\n constructor(options: WooCommerceDataValidationErrorOptions) {\n // Extract field errors from Zod error if provided\n const fieldErrors = options.zodError\n ? WooCommerceDataValidationError.extractFieldErrorsFromZod(options.zodError)\n : undefined;\n\n super({\n code: 'validation_error',\n message: options.message,\n operation: options.operation,\n userMessage: options.userMessage || 'Received unexpected data from WooCommerce',\n retryable: false,\n cause: options.cause,\n url: options.url,\n zodError: options.zodError,\n value: options.value,\n fieldErrors,\n });\n }\n\n // Convenient getters for validation-specific fields (no duplication)\n get url(): string | undefined {\n return this.options.url;\n }\n\n get zodError(): ZodError | undefined {\n return this.options.zodError;\n }\n\n get invalidValue(): unknown | undefined {\n return this.options.value;\n }\n\n get fieldErrors(): Record<string, string[]> | undefined {\n return this.options.fieldErrors;\n }\n\n /**\n * Get reportable data for error tracking/logging\n * Includes validation-specific fields\n */\n override getReportableData(): ValidationReportableData {\n return {\n code: this.options.code,\n operation: this.options.operation,\n userMessage: this.options.userMessage,\n retryable: false,\n fieldErrors: this.options.fieldErrors,\n url: this.options.url,\n };\n }\n\n /**\n * Extract field errors from Zod error\n */\n private static extractFieldErrorsFromZod(\n zodError: ZodError\n ): Record<string, string[]> | undefined {\n if (!zodError?.errors) {\n return undefined;\n }\n\n const fieldErrors: Record<string, string[]> = {};\n\n for (const issue of zodError.errors) {\n const path = issue.path.join('.');\n if (!fieldErrors[path]) {\n fieldErrors[path] = [];\n }\n fieldErrors[path].push(issue.message);\n }\n\n return fieldErrors;\n }\n\n /**\n * Get all error messages as a flat array\n */\n getMessages(): string[] {\n if (!this.fieldErrors) {\n return [this.message];\n }\n\n const messages: string[] = [];\n for (const fieldMessages of Object.values(this.fieldErrors)) {\n messages.push(...fieldMessages);\n }\n\n return messages;\n }\n\n /**\n * Check if a specific field has errors\n */\n hasFieldError(field: string): boolean {\n return this.fieldErrors ? field in this.fieldErrors : false;\n }\n\n /**\n * Get error messages for a specific field\n */\n getFieldError(field: string): string[] | undefined {\n return this.fieldErrors?.[field];\n }\n}\n","/**\n * Response validation utilities\n */\n\nimport type { AxiosResponse } from 'axios';\nimport type { ZodError, ZodSchema } from 'zod';\n\nimport { WooCommerceDataValidationError } from '@/errors';\n\n/**\n * Validation mode for API responses\n * - 'strict': Throw error on validation failure (default)\n * - 'warn': Log warning and continue on validation failure\n */\nexport type ValidationMode = 'strict' | 'warn';\n\n/**\n * Options for response handling\n */\nexport interface ResponseOptions {\n /** Validation mode */\n validationMode?: ValidationMode;\n\n /** Error reporter for validation errors */\n errorReporter?: (error: Error) => void;\n\n /** Optional validation error handler (called before errorReporter) */\n onValidationError?: (error: Error) => void;\n}\n\n/**\n * Handle and validate API response\n *\n * @param response - Axios response\n * @param schema - Zod schema for validation\n * @param options - Response handling options\n * @returns Validated data\n * @throws ValidationError if validation fails in strict mode\n */\nexport const handleApiData = <T>(\n data: unknown,\n schema: ZodSchema<T>,\n options?: ResponseOptions,\n url?: string\n): T => {\n const validationMode = options?.validationMode ?? 'strict';\n\n // Warn mode - use safeParse and continue on validation failure\n if (validationMode === 'warn') {\n const result = schema.safeParse(data);\n\n if (!result.success) {\n const validationError = new WooCommerceDataValidationError({\n message: `WooCommerce API response validation failed for ${url || 'unknown endpoint'}`,\n url,\n zodError: result.error,\n value: data,\n userMessage: 'Received unexpected data from WooCommerce',\n });\n\n // Call optional validation error handler\n options?.onValidationError?.(validationError);\n\n // Report to error tracker (if provided)\n options?.errorReporter?.(validationError);\n\n // Log warning to console in warn mode\n console.warn('[woocommerce-utils] Validation warning:', validationError.message);\n\n // Return raw data to allow app to continue\n return data as T;\n }\n\n return result.data;\n }\n\n // Strict mode - throw on validation failure\n try {\n return schema.parse(data);\n } catch (error) {\n if (error && typeof error === 'object' && 'issues' in error) {\n const validationError = new WooCommerceDataValidationError({\n message: `WooCommerce API response validation failed for ${url || 'unknown endpoint'}`,\n url,\n zodError: error as ZodError,\n value: data,\n userMessage: 'Received unexpected data from WooCommerce',\n });\n\n // Call optional validation error handler\n options?.onValidationError?.(validationError);\n\n // Report to error tracker (if provided)\n options?.errorReporter?.(validationError);\n\n throw validationError;\n }\n throw error;\n }\n};\n\nexport const handleApiResponse = <T>(\n response: AxiosResponse,\n schema: ZodSchema<T>,\n options?: ResponseOptions\n): T => handleApiData(response.data, schema, options, response.config.url);\n\n/**\n * Check if error is a Zod validation error\n */\nexport const isZodError = (error: unknown): error is ZodError => {\n return error instanceof Error && error.name === 'ZodError';\n};\n","/**\n * Calculate pagination navigation\n */\n\nexport interface Pagination {\n page: number;\n perPage: number;\n total: number;\n totalPages: number;\n hasNextPage: boolean;\n hasPrevPage: boolean;\n nextPage: number | null;\n prevPage: number | null;\n}\n\nexport interface CalculatePaginationInput {\n page: number;\n perPage: number;\n total: number;\n totalPages: number;\n}\n\n/**\n * Calculate pagination navigation from WooCommerce pagination metadata\n *\n * @param input - Current pagination state\n * @returns Full pagination object with navigation helpers\n */\nexport const calculatePagination = (input: CalculatePaginationInput): Pagination => {\n const { page, perPage, total, totalPages } = input;\n\n const hasNextPage = page < totalPages;\n const hasPrevPage = page > 1;\n\n return {\n page,\n perPage,\n total,\n totalPages,\n hasNextPage,\n hasPrevPage,\n nextPage: hasNextPage ? page + 1 : null,\n prevPage: hasPrevPage ? page - 1 : null,\n };\n};\n","/**\n * Extract pagination metadata from WooCommerce response headers\n */\n\nimport type { AxiosResponse } from 'axios';\n\nexport interface PaginationMeta {\n total: number;\n totalPages: number;\n}\n\nexport const getPaginationMeta = (headers: AxiosResponse['headers']): PaginationMeta => {\n // Handle undefined/null headers\n if (!headers) {\n return {\n total: 0,\n totalPages: 0,\n };\n }\n\n const wpTotal = headers['x-wp-total'];\n const wpTotalPages = headers['x-wp-totalpages'];\n\n if (!wpTotal || !wpTotalPages) {\n return {\n total: 0,\n totalPages: 0,\n };\n }\n\n const total = parseInt(wpTotal, 10);\n const totalPages = parseInt(wpTotalPages, 10);\n\n return {\n total,\n totalPages,\n };\n};\n","/**\n * Pagination utilities for WooCommerce API responses\n */\n\nimport type { AxiosResponse } from 'axios';\nimport type { ZodError, ZodSchema } from 'zod';\n\nimport { WooCommerceDataValidationError } from '../errors';\nimport { calculatePagination, type Pagination } from '../utils/calculatePagination';\nimport { getPaginationMeta } from '../utils/getPaginationMeta';\nimport type { ResponseOptions } from './handleApiResponse';\n\n/**\n * Paginated response wrapper\n */\nexport interface PaginatedResponse<T> {\n data: T[];\n pagination: Pagination;\n}\n\n/**\n * Handle paginated API response\n *\n * @param response - Axios response\n * @param schema - Zod schema for validating array items\n * @param params - Request parameters (page, per_page)\n * @param options - Response handling options\n * @returns Paginated response with validated data\n * @throws ValidationError if validation fails in strict mode\n */\nexport const handlePaginatedApiResponse = <T>(\n response: AxiosResponse,\n schema: ZodSchema<T[]>,\n params: { page?: number; per_page?: number } = {},\n options?: ResponseOptions\n): PaginatedResponse<T> => {\n const validationMode = options?.validationMode ?? 'strict';\n let data: T[];\n\n // Warn mode - use safeParse and continue on validation failure\n if (validationMode === 'warn') {\n const result = schema.safeParse(response.data);\n\n if (!result.success) {\n const validationError = new WooCommerceDataValidationError({\n message: `WooCommerce API response validation failed for ${response.config.url || 'unknown endpoint'}`,\n url: response.config.url,\n zodError: result.error,\n value: response.data,\n userMessage: 'Received unexpected data from WooCommerce',\n });\n\n // Call optional validation error handler\n options?.onValidationError?.(validationError);\n\n // Report to error tracker (if provided)\n options?.errorReporter?.(validationError);\n\n // Log warning to console in warn mode\n console.warn('[woocommerce-utils] Validation warning:', validationError.message);\n\n // Return raw data as array (best effort)\n data = Array.isArray(response.data) ? response.data : [];\n } else {\n data = result.data;\n }\n } else {\n // Strict mode - throw on validation failure\n try {\n data = schema.parse(response.data);\n } catch (error) {\n if (error && typeof error === 'object' && 'issues' in error) {\n const validationError = new WooCommerceDataValidationError({\n message: `WooCommerce API response validation failed for ${response.config.url || 'unknown endpoint'}`,\n url: response.config.url,\n zodError: error as ZodError,\n value: response.data,\n userMessage: 'Received unexpected data from WooCommerce',\n });\n\n // Call optional validation error handler\n options?.onValidationError?.(validationError);\n\n // Report to error tracker (if provided)\n options?.errorReporter?.(validationError);\n\n throw validationError;\n }\n throw error;\n }\n }\n\n const { total, totalPages } = getPaginationMeta(response.headers);\n const page = params.page || 1;\n const perPage = params.per_page || 10;\n\n const pagination = calculatePagination({\n page,\n perPage,\n total,\n totalPages,\n });\n\n return {\n data,\n pagination,\n };\n};\n","/**\n * Debug logger for WooCommerce utils\n */\n\nconst DEBUG_PREFIX = '[woocommerce-utils]';\n\n/**\n * Check if debug mode is enabled\n */\nexport const isDebugEnabled = (): boolean => {\n if (typeof process !== 'undefined' && process.env) {\n return process.env.DEBUG === 'true' || process.env.DEBUG === '1';\n }\n return false;\n};\n\n/**\n * Log debug message (only if DEBUG is enabled)\n */\nexport const debug = (...args: unknown[]): void => {\n if (isDebugEnabled()) {\n console.log(DEBUG_PREFIX, ...args);\n }\n};\n\n/**\n * Log warning message\n */\nexport const warn = (...args: unknown[]): void => {\n console.warn(DEBUG_PREFIX, ...args);\n};\n\n/**\n * Log error message\n */\nexport const error = (...args: unknown[]): void => {\n console.error(DEBUG_PREFIX, ...args);\n};\n","const CART_ROUTE = /\\/wc\\/store\\/(v\\d+\\/)?(cart|checkout|batch)/;\nconst BATCH_ROUTE = /\\/wc\\/store\\/(v\\d+\\/)?batch/;\n\nexport const isCartRoute = (url?: string): boolean => !!url && CART_ROUTE.test(url);\n\nexport const isBatchRoute = (url?: string): boolean => !!url && BATCH_ROUTE.test(url);\n","/**\n * Request interceptor\n *\n * Handles:\n * - JWT authentication for protected endpoints\n * - Nonce/Cart-Token injection for cart/checkout endpoints\n * - Cache-Control headers for cart/checkout to prevent Android caching bugs\n * - Debug logging\n */\n\nimport type { AxiosInstance, InternalAxiosRequestConfig } from 'axios';\n\nimport type { WooCommerceClient, WooCommerceConfig } from '../../client/types';\nimport { debug } from '../../logging/logger';\nimport { isBatchRoute, isCartRoute } from '../storeRoutes';\n\n/**\n * Check if endpoint requires JWT authentication\n */\nconst requiresAuth = (url?: string): boolean => {\n if (!url) return false;\n\n const authEndpoints = [\n '/jwt-auth/',\n '/customers/me',\n '/wp/v2/users/me',\n // Store API non-cart endpoints: inject JWT when available so authenticated\n // users can access their own resources (e.g. orders, personalised product data)\n '/wc/store/v1/order',\n ];\n\n return authEndpoints.some((endpoint) => url.includes(endpoint));\n};\n\n/**\n * Setup request interceptor\n *\n * - Injects JWT Bearer token for authenticated requests\n * - Injects Nonce/Cart-Token headers for cart/checkout requests\n * - Adds Cache-Control headers to prevent Android caching bugs\n * - Calls optional onRequest hook\n * - Passes client instance to callbacks\n */\nexport const setupRequestInterceptor = (\n axiosInstance: AxiosInstance,\n config: WooCommerceConfig,\n client: WooCommerceClient\n): void => {\n axiosInstance.interceptors.request.use(\n async (requestConfig: InternalAxiosRequestConfig) => {\n const url = requestConfig.url;\n\n // Inject JWT token for authenticated endpoints\n if (config.jwtToken) {\n const token = await config.jwtToken.get();\n if (token && (requiresAuth(url) || isCartRoute(url))) {\n requestConfig.headers.Authorization = `Bearer ${token}`;\n if (config.debug) {\n debug('Injected JWT token for', url);\n }\n }\n }\n\n // Inject nonce/cart-token for cart endpoints\n // When JWT is present, skip Cart-Token: WooCommerce prioritizes Cart-Token over JWT\n // for session identification, which would route requests to a separate API session\n // instead of the user's persistent cart.\n //\n // /batch is the exception. WP core rebuilds every sub-request as a fresh\n // WP_REST_Request, so none of them inherit the Nonce header and each one fails\n // AbstractCartRoute::check_nonce(). WooCommerce waives the nonce when\n // has_cart_token() is set, and that helper reads the outer HTTP header precisely\n // so it survives batch dispatch — so Cart-Token is the only credential a batch\n // sub-request can present.\n if (isCartRoute(url)) {\n const headers = await config.cartHeaders.get();\n const isAuthenticated = !!(await config.jwtToken?.get());\n\n if (headers.nonce) {\n requestConfig.headers.Nonce = headers.nonce;\n }\n if (headers.cartToken && (!isAuthenticated || isBatchRoute(url))) {\n requestConfig.headers['Cart-Token'] = headers.cartToken;\n }\n\n // CRITICAL: Disable HTTP caching for cart/checkout endpoints\n // WooCommerce sends aggressive cache headers (max-age=2419200, 28 days) which\n // can cause Android HTTP clients to serve stale cart data from cache.\n // This was causing empty carts to be returned after successful add-item operations\n // because the cached GET /cart response (from before items were added) was being\n // served instead of fetching fresh data from the server.\n // iOS URLSession happened to work because it handles expired cache differently.\n requestConfig.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate';\n requestConfig.headers.Pragma = 'no-cache';\n requestConfig.headers.Expires = '0';\n\n if (config.debug) {\n debug('Injected cart headers for', url, {\n hasNonce: !!headers.nonce,\n hasCartToken: !!headers.cartToken,\n });\n }\n }\n\n // Debug logging\n if (config.debug) {\n debug(\n `${requestConfig.method?.toUpperCase()} ${requestConfig.url}`,\n requestConfig.params || requestConfig.data\n );\n }\n\n // Call optional onRequest hook\n if (config.onRequest) {\n return config.onRequest(requestConfig, client);\n }\n\n return requestConfig;\n },\n (error) => {\n return Promise.reject(error);\n }\n );\n};\n","/**\n * Axios response interceptor for WooCommerce API\n */\n\nimport { AxiosError, type AxiosInstance, type AxiosResponse } from 'axios';\n\nimport type { WooCommerceClient, WooCommerceConfig } from '../../client/types';\nimport { debug } from '../../logging/logger';\nimport { isBatchRoute, isCartRoute } from '../storeRoutes';\n\nconst NONCE_ERROR_CODES = ['woocommerce_rest_missing_nonce', 'woocommerce_rest_invalid_nonce'];\n\nconst isNonceRejectedBatch = (data: unknown): boolean => {\n const responses = (data as { responses?: unknown } | null | undefined)?.responses;\n\n if (!Array.isArray(responses) || responses.length === 0) return false;\n\n return responses.every((response) => {\n const code = (response as { body?: { code?: unknown } } | null)?.body?.code;\n return typeof code === 'string' && NONCE_ERROR_CODES.includes(code);\n });\n};\n\n/**\n * Setup response interceptor\n *\n * - Extracts and saves cart headers (nonce rotation)\n * - Logs responses in debug mode\n * - Calls optional onResponse hook\n * - Passes client instance to callbacks\n */\nexport const setupResponseInterceptor = (\n axiosInstance: AxiosInstance,\n config: WooCommerceConfig,\n client: WooCommerceClient\n): void => {\n axiosInstance.interceptors.response.use(\n async (response: AxiosResponse) => {\n // Extract and save cart headers (nonce rotation)\n if (isCartRoute(response.config.url)) {\n const nonce = response.headers['nonce'] || response.headers['Nonce'];\n const cartToken = response.headers['cart-token'] || response.headers['Cart-Token'];\n\n if (nonce || cartToken) {\n await config.cartHeaders.save({\n nonce: nonce || undefined,\n cartToken: cartToken || undefined,\n });\n\n if (config.debug) {\n debug(\n 'Saved updated cart headers:',\n response.config.url,\n 'nonce:',\n !!nonce,\n 'cartToken:',\n !!cartToken\n );\n }\n }\n }\n\n if (isBatchRoute(response.config.url) && isNonceRejectedBatch(response.data)) {\n throw new AxiosError(\n 'Batch rejected for a nonce error',\n AxiosError.ERR_BAD_REQUEST,\n response.config,\n response.request,\n { ...response, status: 401, data: { code: 'woocommerce_rest_missing_nonce' } }\n );\n }\n\n if (config.debug) {\n debug('Response:', response.config.url, response.status);\n }\n\n // Call optional onResponse hook\n if (config.onResponse) {\n return config.onResponse(response, client);\n }\n\n return response;\n },\n (error) => {\n return Promise.reject(error);\n }\n );\n};\n","/**\n * Cart session initialization utility\n */\n\nimport type { AxiosInstance } from 'axios';\n\nimport type { CartHeadersAdapter } from '../client/types';\nimport { debug } from '../logging/logger';\n\n/**\n * Initialize cart session by fetching cart and saving headers\n *\n * This is called when nonce errors occur to get a fresh nonce/cart-token\n *\n * @param client - Axios instance\n * @param cartHeaders - Cart headers adapter\n */\nexport const initializeCartSession = async (\n client: AxiosInstance,\n cartHeaders: CartHeadersAdapter\n): Promise<void> => {\n try {\n debug('session', 'Initializing cart session');\n\n // Make GET request to cart endpoint\n const response = await client.get('/wc/store/v1/cart');\n\n // Extract headers\n const nonce = response.headers['nonce'] || response.headers['Nonce'];\n const cartToken = response.headers['cart-token'] || response.headers['Cart-Token'];\n\n // Save headers\n if (nonce || cartToken) {\n await cartHeaders.save({\n nonce: nonce || undefined,\n cartToken: cartToken || undefined,\n });\n\n debug('session', 'Cart session initialized', {\n hasNonce: !!nonce,\n hasCartToken: !!cartToken,\n });\n }\n } catch (error) {\n debug('session', 'Failed to initialize cart session', error);\n throw error;\n }\n};\n","/**\n * Axios error interceptor for WooCommerce API\n */\n\nimport { isAxiosError, type AxiosError, type AxiosInstance } from 'axios';\n\nimport type { WooCommerceClient, WooCommerceConfig } from '../../client/types';\nimport { WooCommerceApiError } from '../../errors/classes/WooCommerceApiError';\nimport { mapWooCommerceCode, WOOCOMMERCE_ERROR_METADATA } from '../../errors/mapping';\nimport { debug, error as logError } from '../../logging/logger';\nimport { initializeCartSession } from '../../utils/initializeCartSession';\n\ninterface WooCommerceErrorData {\n code?: string;\n message?: string;\n data?: {\n status?: number;\n };\n}\n\n/**\n * Setup error interceptor\n *\n * - Transforms WooCommerce errors into WooCommerceApiError instances\n * - Calls optional onError hook\n * - Passes client instance to callbacks\n */\nexport const setupErrorInterceptor = (\n axiosInstance: AxiosInstance,\n config: WooCommerceConfig,\n client: WooCommerceClient\n): void => {\n axiosInstance.interceptors.response.use(\n (response) => response,\n async (axiosError: AxiosError<WooCommerceErrorData>) => {\n const status = axiosError.response?.status || 500;\n const errorData = axiosError.response?.data;\n\n // Extract WooCommerce error details\n const apiCode = errorData?.code || 'unknown_error';\n const wpMessage = errorData?.message || axiosError.message || 'Unknown error';\n\n // Transform WooCommerce API code to application-level code\n // e.g., \"woocommerce_rest_cart_empty\" → \"cart_empty\"\n const errorCode = mapWooCommerceCode(apiCode);\n const errorMetadata = WOOCOMMERCE_ERROR_METADATA[errorCode];\n\n // Create WooCommerceError with full context\n const wcError = new WooCommerceApiError({\n message: wpMessage,\n statusCode: status,\n code: errorCode, // Transformed app-level code\n originalCode: apiCode, // Original WooCommerce API code\n retryable: errorMetadata.retryable,\n userMessage: errorMetadata.userMessage,\n operation: errorMetadata.operation,\n url: axiosError.config?.url || '',\n method: axiosError.config?.method?.toUpperCase() || 'GET',\n requestBody: axiosError.config?.data,\n responseBody: errorData,\n data: errorData?.data as Record<string, unknown> | undefined,\n cause: axiosError,\n });\n\n if (config.debug) {\n debug('WooCommerce error:', apiCode, status, wpMessage);\n logError(wcError);\n }\n\n // Handle authentication errors (401/403)\n if (\n (status === 401 || status === 403) &&\n config.onAuthError &&\n isAxiosError(axiosError) &&\n !axiosError.config?._retry\n ) {\n if (config.debug) {\n debug('Auth error detected, calling onAuthError handler');\n }\n\n try {\n const shouldRetry = await config.onAuthError(wcError, client);\n\n if (shouldRetry) {\n if (config.debug) {\n debug('Retrying request after auth error');\n }\n\n // Mark as retry to prevent infinite loops\n axiosError.config!._retry = true;\n\n // Retry the request\n return axiosInstance.request(axiosError.config!);\n }\n } catch (authErrorHandlerError) {\n // If onAuthError handler throws, fall through to error reporting\n if (config.debug) {\n debug('onAuthError handler threw error', authErrorHandlerError);\n }\n }\n }\n\n // Call optional onError hook first (even for retryable errors)\n if (config.onError) {\n config.onError(wcError, client);\n }\n\n // Auto-retry nonce errors\n const isNonceError = errorCode === 'missing_nonce' || errorCode === 'invalid_nonce';\n if (isNonceError && isAxiosError(axiosError) && !axiosError.config?._retry) {\n if (config.debug) {\n debug('Nonce error detected, retrying with new session');\n }\n\n try {\n // Initialize new cart session\n await initializeCartSession(axiosInstance, config.cartHeaders);\n\n // Mark as retry to prevent infinite loops\n axiosError.config!._retry = true;\n\n // Retry the request\n return axiosInstance.request(axiosError.config!);\n } catch (_retryError) {\n // If retry fails, report and throw original error\n config.errorReporter?.report(wcError);\n return Promise.reject(wcError);\n }\n }\n\n // Report error to configured error reporter (Sentry, etc.)\n config.errorReporter?.report(wcError);\n\n return Promise.reject(wcError);\n }\n );\n};\n\n// Augment AxiosRequestConfig to include _retry flag\ndeclare module 'axios' {\n export interface AxiosRequestConfig {\n _retry?: boolean;\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/errors/classes/BaseError.ts","../../src/errors/mapping/mapWooCommerceCode.ts","../../src/errors/mapping/constants.ts","../../src/errors/classes/http-error.ts","../../src/errors/classes/WooCommerceApiError.ts","../../src/errors/classes/WooCommerceDataValidationError.ts","../../src/http/handleApiResponse.ts","../../src/utils/calculatePagination.ts","../../src/utils/getPaginationMeta.ts","../../src/http/handlePaginatedApiResponse.ts","../../src/logging/logger.ts","../../src/http/storeRoutes.ts","../../src/http/interceptors/request.ts","../../src/http/interceptors/response.ts","../../src/utils/initializeCartSession.ts","../../src/http/interceptors/error.ts"],"names":["BaseError","error","AxiosError","isCancel","isAxiosError"],"mappings":";;;;;;;;;;;;;;AASO,IAAM,SAAA,GAAN,cAGG,KAAA,CAAM;AAAA,EACd,YAA4B,OAAA,EAAmB;AAC7C,IAAA,KAAA,CAAM,QAAQ,OAAO,CAAA;AADK,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAI1B,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,GAAA,CAAA,MAAA,CAAW,SAAS,CAAA;AAGhD,IAAA,IAAA,CAAK,IAAA,GAAO,KAAK,WAAA,CAAY,IAAA;AAG7B,IAAA,IAAI,MAAM,iBAAA,EAAmB;AAC3B,MAAA,KAAA,CAAM,iBAAA,CAAkB,IAAA,EAAM,IAAA,CAAK,WAAW,CAAA;AAAA,IAChD;AAGA,IAAA,IAAI,KAAK,OAAA,CAAQ,KAAA,YAAiB,SAAS,IAAA,CAAK,OAAA,CAAQ,MAAM,KAAA,EAAO;AACnE,MAAA,IAAA,CAAK,KAAA,GAAQ,CAAA,EAAG,IAAA,CAAK,KAAK;AAAA,WAAA,EAAgB,IAAA,CAAK,OAAA,CAAQ,KAAA,CAAM,KAAK,CAAA,CAAA;AAAA,IACpE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,iBAAA,GAAiC;AAC/B,IAAA,MAAM,EAAE,IAAA,EAAM,SAAA,EAAW,WAAA,EAAa,SAAA,K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kBAAA,CAAa,UAAU,KAAK,CAAC,UAAA,CAAW,QAAQ,MAAA,EAAQ;AAC1E,QAAA,IAAI,OAAO,KAAA,EAAO;AAChB,UAAA,KAAA,CAAM,iDAAiD,CAAA;AAAA,QACzD;AAEA,QAAA,IAAI;AAEF,UAAA,MAAM,qBAAA,CAAsB,aAAA,EAAe,MAAA,CAAO,WAAW,CAAA;AAG7D,UAAA,UAAA,CAAW,OAAQ,MAAA,GAAS,IAAA;AAG5B,UAAA,OAAO,aAAA,CAAc,OAAA,CAAQ,UAAA,CAAW,MAAO,CAAA;AAAA,QACjD,SAAS,WAAA,EAAa;AAEpB,UAAA,MAAA,CAAO,aAAA,EAAe,OAAO,OAAO,CAAA;AACpC,UAAA,OAAO,OAAA,CAAQ,OAAO,OAAO,CAAA;AAAA,QAC/B;AAAA,MACF;AAGA,MAAA,MAAA,CAAO,aAAA,EAAe,OAAO,OAAO,CAAA;AAEpC,MAAA,OAAO,OAAA,CAAQ,OAAO,OAAO,CAAA;AAAA,IAC/B;AAAA,GACF;AACF","file":"index.js","sourcesContent":["/**\n * Base error class for all package errors\n *\n * Generic over:\n * - TOptions: The options type for this error class\n * - TReportable: The reportable data structure for error tracking\n */\nimport type { BaseErrorOptions, BaseReportableData } from './types';\n\nexport class BaseError<\n TOptions extends BaseErrorOptions = BaseErrorOptions,\n TReportable extends BaseReportableData = BaseReportableData,\n> extends Error {\n constructor(public readonly options: TOptions) {\n super(options.message);\n\n // Maintain proper prototype chain\n Object.setPrototypeOf(this, new.target.prototype);\n\n // Set error name\n this.name = this.constructor.name;\n\n // Capture stack trace (excluding constructor call)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, this.constructor);\n }\n\n // If there's a cause with a stack, preserve it\n if (this.options.cause instanceof Error && this.options.cause.stack) {\n this.stack = `${this.stack}\\nCaused by: ${this.options.cause.stack}`;\n }\n }\n\n /**\n * Get reportable data for error tracking/logging\n * Subclasses should override this to add their own reportable fields\n */\n getReportableData(): TReportable {\n const { code, operation, userMessage, retryable } = this.options;\n return {\n code,\n operation,\n userMessage,\n retryable,\n } as TReportable;\n }\n\n /**\n * Custom JSON serialization\n * Makes the error properly serializable for logging/reporting\n */\n toJSON(): Record<string, unknown> {\n return {\n ...this.getReportableData(),\n name: this.name,\n message: this.message,\n stack: this.stack,\n } as unknown as Record<string, unknown>;\n }\n}\n","import type { WooCommerceApiErrorCode } from './types';\n\nexport const mapWooCommerceCode = (apiCode?: string): WooCommerceApiErrorCode => {\n if (!apiCode) return 'unknown_error';\n\n // Direct matches\n const directMatches: Record<string, WooCommerceApiErrorCode> = {\n woocommerce_rest_cart_empty: 'cart_empty',\n woocommerce_rest_cart_coupon_error: 'invalid_coupon',\n woocommerce_rest_missing_nonce: 'missing_nonce',\n woocommerce_rest_invalid_nonce: 'invalid_nonce',\n rest_invalid_param: 'invalid_params',\n woocommerce_rest_product_invalid_id: 'product_not_found',\n woocommerce_rest_product_out_of_stock: 'out_of_stock',\n woocommerce_rest_product_not_enough_stock: 'insufficient_stock',\n woocommerce_rest_checkout_invalid_payment_method: 'invalid_payment_method',\n };\n\n if (directMatches[apiCode]) {\n return directMatches[apiCode];\n }\n\n // Pattern matches\n if (apiCode.includes('nonce')) return 'invalid_nonce';\n if (apiCode.includes('coupon')) return 'invalid_coupon';\n if (apiCode.includes('stock')) return 'insufficient_stock';\n if (apiCode.includes('checkout')) return 'checkout_error';\n if (apiCode.includes('payment')) return 'invalid_payment_method';\n\n return 'unknown_error';\n};\n","import type { WooCommerceApiErrorCode, WooCommerceApiErrorMetaData } from './types';\n\nexport const WOOCOMMERCE_ERROR_METADATA: Record<\n WooCommerceApiErrorCode,\n WooCommerceApiErrorMetaData\n> = {\n cart_empty: {\n operation: 'get_cart',\n retryable: false,\n userMessage: 'Your cart is empty',\n },\n invalid_coupon: {\n operation: 'apply_coupon',\n retryable: false,\n userMessage: 'Invalid coupon code',\n },\n missing_nonce: {\n operation: 'cart_request',\n retryable: true, // Auto-retry with new nonce\n },\n invalid_nonce: {\n operation: 'cart_request',\n retryable: true, // Auto-retry with new nonce\n },\n invalid_params: {\n operation: 'api_request',\n retryable: false,\n userMessage: 'Invalid request parameters',\n },\n product_not_found: {\n operation: 'get_product',\n retryable: false,\n userMessage: 'Product not found',\n },\n out_of_stock: {\n operation: 'add_to_cart',\n retryable: false,\n userMessage: 'This product is out of stock',\n },\n insufficient_stock: {\n operation: 'add_to_cart',\n retryable: false,\n userMessage: 'Not enough stock available',\n },\n invalid_payment_method: {\n operation: 'process_checkout',\n retryable: false,\n userMessage: 'Invalid payment method',\n },\n checkout_error: {\n operation: 'process_checkout',\n retryable: false,\n },\n network_error: {\n operation: 'network_request',\n retryable: true,\n },\n unknown_error: {\n operation: 'unknown',\n retryable: false,\n },\n};\n","export const redactPath = (url: string): string =>\n url\n .replace(/^[a-z][a-z0-9+.-]*:\\/\\/[^/]+/i, '')\n .replace(/[?#].*$/, '')\n .split('/')\n .map((segment) => (/^(\\d+|[0-9a-f]{16,}|[0-9a-f-]{36})$/i.test(segment) ? ':id' : segment))\n .join('/');\n\nexport const classifyHttpStatus = (status?: number) =>\n ({\n domain:\n status === undefined ? 'network' : status === 401 || status === 403 ? 'auth' : 'integration',\n severity: status !== undefined && status < 500 ? 'warning' : 'error',\n }) as const;\n","/**\n * WooCommerce API Error\n */\n\nimport { BaseError } from '@atomic-solutions/errors';\n\nimport { WOOCOMMERCE_ERROR_METADATA, type WooCommerceApiErrorCode } from '../mapping';\nimport { classifyHttpStatus, redactPath } from './http-error';\nimport type { WooCommerceApiErrorOptions } from './types';\n\n/**\n * WooCommerce-specific error class\n *\n * Extends BaseError to provide:\n * - Code transformation (WooCommerce API codes → clean app codes)\n * - WooCommerce-specific error categorization\n * - HTTP context (status, URL, method)\n */\nexport class WooCommerceApiError extends BaseError {\n readonly #options: WooCommerceApiErrorOptions;\n\n constructor(options: WooCommerceApiErrorOptions) {\n const metadata = WOOCOMMERCE_ERROR_METADATA[options.code] ?? {\n operation: 'woocommerce_api_request',\n retryable: false,\n };\n\n // Enrich options with metadata defaults\n const enrichedOptions: WooCommerceApiErrorOptions = {\n ...options,\n operation: options.operation || metadata.operation,\n userMessage: options.userMessage || metadata.userMessage,\n retryable: options.retryable ?? metadata.retryable,\n };\n\n const status = enrichedOptions.statusCode;\n const { domain, severity } = classifyHttpStatus(status);\n\n super({\n domain,\n severity,\n operation: enrichedOptions.operation as string,\n message: enrichedOptions.message,\n code: enrichedOptions.code,\n retryable: enrichedOptions.retryable,\n userMessage: enrichedOptions.userMessage,\n cause: enrichedOptions.cause,\n fingerprint: [domain, enrichedOptions.code, String(status ?? 'network')],\n extras: {\n originalCode: enrichedOptions.originalCode,\n statusCode: status,\n path: redactPath(enrichedOptions.url),\n method: enrichedOptions.method,\n },\n });\n\n this.#options = enrichedOptions;\n }\n\n get options(): WooCommerceApiErrorOptions {\n return this.#options;\n }\n\n // Convenient getters for frequently accessed fields (no duplication)\n get wooCode(): WooCommerceApiErrorCode {\n return this.options.code;\n }\n\n get originalCode(): string {\n return this.options.originalCode;\n }\n\n get statusCode(): number | undefined {\n return this.options.statusCode;\n }\n\n get url(): string {\n return this.options.url;\n }\n\n get method(): string {\n return this.options.method;\n }\n\n get requestBody(): unknown | undefined {\n return this.options.requestBody;\n }\n\n get responseBody(): unknown | undefined {\n return this.options.responseBody;\n }\n\n get data(): Record<string, unknown> | undefined {\n return this.options.data;\n }\n}\n","/**\n * WooCommerce validation error class\n * Thrown when API response validation fails\n */\n\nimport type { ZodError } from 'zod';\n\nimport { BaseError } from './BaseError';\nimport type {\n BaseErrorOptions,\n ValidationReportableData,\n WooCommerceDataValidationErrorOptions,\n} from './types';\n\n/**\n * Internal options type that combines user options with computed fields\n */\ninterface WooCommerceDataValidationErrorInternalOptions extends BaseErrorOptions {\n url?: string;\n zodError?: ZodError;\n value?: unknown;\n fieldErrors?: Record<string, string[]>;\n}\n\n/**\n * WooCommerce validation error\n *\n * Thrown when API response validation fails using Zod schemas\n */\nexport class WooCommerceDataValidationError extends BaseError<\n WooCommerceDataValidationErrorInternalOptions,\n ValidationReportableData\n> {\n constructor(options: WooCommerceDataValidationErrorOptions) {\n // Extract field errors from Zod error if provided\n const fieldErrors = options.zodError\n ? WooCommerceDataValidationError.extractFieldErrorsFromZod(options.zodError)\n : undefined;\n\n super({\n code: 'validation_error',\n message: options.message,\n operation: options.operation,\n userMessage: options.userMessage || 'Received unexpected data from WooCommerce',\n retryable: false,\n cause: options.cause,\n url: options.url,\n zodError: options.zodError,\n value: options.value,\n fieldErrors,\n });\n }\n\n // Convenient getters for validation-specific fields (no duplication)\n get url(): string | undefined {\n return this.options.url;\n }\n\n get zodError(): ZodError | undefined {\n return this.options.zodError;\n }\n\n get invalidValue(): unknown | undefined {\n return this.options.value;\n }\n\n get fieldErrors(): Record<string, string[]> | undefined {\n return this.options.fieldErrors;\n }\n\n /**\n * Get reportable data for error tracking/logging\n * Includes validation-specific fields\n */\n override getReportableData(): ValidationReportableData {\n return {\n code: this.options.code,\n operation: this.options.operation,\n userMessage: this.options.userMessage,\n retryable: false,\n fieldErrors: this.options.fieldErrors,\n url: this.options.url,\n };\n }\n\n /**\n * Extract field errors from Zod error\n */\n private static extractFieldErrorsFromZod(\n zodError: ZodError\n ): Record<string, string[]> | undefined {\n if (!zodError?.errors) {\n return undefined;\n }\n\n const fieldErrors: Record<string, string[]> = {};\n\n for (const issue of zodError.errors) {\n const path = issue.path.join('.');\n if (!fieldErrors[path]) {\n fieldErrors[path] = [];\n }\n fieldErrors[path].push(issue.message);\n }\n\n return fieldErrors;\n }\n\n /**\n * Get all error messages as a flat array\n */\n getMessages(): string[] {\n if (!this.fieldErrors) {\n return [this.message];\n }\n\n const messages: string[] = [];\n for (const fieldMessages of Object.values(this.fieldErrors)) {\n messages.push(...fieldMessages);\n }\n\n return messages;\n }\n\n /**\n * Check if a specific field has errors\n */\n hasFieldError(field: string): boolean {\n return this.fieldErrors ? field in this.fieldErrors : false;\n }\n\n /**\n * Get error messages for a specific field\n */\n getFieldError(field: string): string[] | undefined {\n return this.fieldErrors?.[field];\n }\n}\n","/**\n * Response validation utilities\n */\n\nimport type { AxiosResponse } from 'axios';\nimport type { ZodError, ZodSchema } from 'zod';\n\nimport { WooCommerceDataValidationError } from '@/errors';\n\n/**\n * Validation mode for API responses\n * - 'strict': Throw error on validation failure (default)\n * - 'warn': Log warning and continue on validation failure\n */\nexport type ValidationMode = 'strict' | 'warn';\n\n/**\n * Options for response handling\n */\nexport interface ResponseOptions {\n /** Validation mode */\n validationMode?: ValidationMode;\n\n /** Error reporter for validation errors */\n errorReporter?: (error: Error) => void;\n\n /** Optional validation error handler (called before errorReporter) */\n onValidationError?: (error: Error) => void;\n}\n\n/**\n * Handle and validate API response\n *\n * @param response - Axios response\n * @param schema - Zod schema for validation\n * @param options - Response handling options\n * @returns Validated data\n * @throws ValidationError if validation fails in strict mode\n */\nexport const handleApiData = <T>(\n data: unknown,\n schema: ZodSchema<T>,\n options?: ResponseOptions,\n url?: string\n): T => {\n const validationMode = options?.validationMode ?? 'strict';\n\n // Warn mode - use safeParse and continue on validation failure\n if (validationMode === 'warn') {\n const result = schema.safeParse(data);\n\n if (!result.success) {\n const validationError = new WooCommerceDataValidationError({\n message: `WooCommerce API response validation failed for ${url || 'unknown endpoint'}`,\n url,\n zodError: result.error,\n value: data,\n userMessage: 'Received unexpected data from WooCommerce',\n });\n\n // Call optional validation error handler\n options?.onValidationError?.(validationError);\n\n // Report to error tracker (if provided)\n options?.errorReporter?.(validationError);\n\n // Log warning to console in warn mode\n console.warn('[woocommerce-utils] Validation warning:', validationError.message);\n\n // Return raw data to allow app to continue\n return data as T;\n }\n\n return result.data;\n }\n\n // Strict mode - throw on validation failure\n try {\n return schema.parse(data);\n } catch (error) {\n if (error && typeof error === 'object' && 'issues' in error) {\n const validationError = new WooCommerceDataValidationError({\n message: `WooCommerce API response validation failed for ${url || 'unknown endpoint'}`,\n url,\n zodError: error as ZodError,\n value: data,\n userMessage: 'Received unexpected data from WooCommerce',\n });\n\n // Call optional validation error handler\n options?.onValidationError?.(validationError);\n\n // Report to error tracker (if provided)\n options?.errorReporter?.(validationError);\n\n throw validationError;\n }\n throw error;\n }\n};\n\nexport const handleApiResponse = <T>(\n response: AxiosResponse,\n schema: ZodSchema<T>,\n options?: ResponseOptions\n): T => handleApiData(response.data, schema, options, response.config.url);\n\n/**\n * Check if error is a Zod validation error\n */\nexport const isZodError = (error: unknown): error is ZodError => {\n return error instanceof Error && error.name === 'ZodError';\n};\n","/**\n * Calculate pagination navigation\n */\n\nexport interface Pagination {\n page: number;\n perPage: number;\n total: number;\n totalPages: number;\n hasNextPage: boolean;\n hasPrevPage: boolean;\n nextPage: number | null;\n prevPage: number | null;\n}\n\nexport interface CalculatePaginationInput {\n page: number;\n perPage: number;\n total: number;\n totalPages: number;\n}\n\n/**\n * Calculate pagination navigation from WooCommerce pagination metadata\n *\n * @param input - Current pagination state\n * @returns Full pagination object with navigation helpers\n */\nexport const calculatePagination = (input: CalculatePaginationInput): Pagination => {\n const { page, perPage, total, totalPages } = input;\n\n const hasNextPage = page < totalPages;\n const hasPrevPage = page > 1;\n\n return {\n page,\n perPage,\n total,\n totalPages,\n hasNextPage,\n hasPrevPage,\n nextPage: hasNextPage ? page + 1 : null,\n prevPage: hasPrevPage ? page - 1 : null,\n };\n};\n","/**\n * Extract pagination metadata from WooCommerce response headers\n */\n\nimport type { AxiosResponse } from 'axios';\n\nexport interface PaginationMeta {\n total: number;\n totalPages: number;\n}\n\nexport const getPaginationMeta = (headers: AxiosResponse['headers']): PaginationMeta => {\n // Handle undefined/null headers\n if (!headers) {\n return {\n total: 0,\n totalPages: 0,\n };\n }\n\n const wpTotal = headers['x-wp-total'];\n const wpTotalPages = headers['x-wp-totalpages'];\n\n if (!wpTotal || !wpTotalPages) {\n return {\n total: 0,\n totalPages: 0,\n };\n }\n\n const total = parseInt(wpTotal, 10);\n const totalPages = parseInt(wpTotalPages, 10);\n\n return {\n total,\n totalPages,\n };\n};\n","/**\n * Pagination utilities for WooCommerce API responses\n */\n\nimport type { AxiosResponse } from 'axios';\nimport type { ZodError, ZodSchema } from 'zod';\n\nimport { WooCommerceDataValidationError } from '../errors';\nimport { calculatePagination, type Pagination } from '../utils/calculatePagination';\nimport { getPaginationMeta } from '../utils/getPaginationMeta';\nimport type { ResponseOptions } from './handleApiResponse';\n\n/**\n * Paginated response wrapper\n */\nexport interface PaginatedResponse<T> {\n data: T[];\n pagination: Pagination;\n}\n\n/**\n * Handle paginated API response\n *\n * @param response - Axios response\n * @param schema - Zod schema for validating array items\n * @param params - Request parameters (page, per_page)\n * @param options - Response handling options\n * @returns Paginated response with validated data\n * @throws ValidationError if validation fails in strict mode\n */\nexport const handlePaginatedApiResponse = <T>(\n response: AxiosResponse,\n schema: ZodSchema<T[]>,\n params: { page?: number; per_page?: number } = {},\n options?: ResponseOptions\n): PaginatedResponse<T> => {\n const validationMode = options?.validationMode ?? 'strict';\n let data: T[];\n\n // Warn mode - use safeParse and continue on validation failure\n if (validationMode === 'warn') {\n const result = schema.safeParse(response.data);\n\n if (!result.success) {\n const validationError = new WooCommerceDataValidationError({\n message: `WooCommerce API response validation failed for ${response.config.url || 'unknown endpoint'}`,\n url: response.config.url,\n zodError: result.error,\n value: response.data,\n userMessage: 'Received unexpected data from WooCommerce',\n });\n\n // Call optional validation error handler\n options?.onValidationError?.(validationError);\n\n // Report to error tracker (if provided)\n options?.errorReporter?.(validationError);\n\n // Log warning to console in warn mode\n console.warn('[woocommerce-utils] Validation warning:', validationError.message);\n\n // Return raw data as array (best effort)\n data = Array.isArray(response.data) ? response.data : [];\n } else {\n data = result.data;\n }\n } else {\n // Strict mode - throw on validation failure\n try {\n data = schema.parse(response.data);\n } catch (error) {\n if (error && typeof error === 'object' && 'issues' in error) {\n const validationError = new WooCommerceDataValidationError({\n message: `WooCommerce API response validation failed for ${response.config.url || 'unknown endpoint'}`,\n url: response.config.url,\n zodError: error as ZodError,\n value: response.data,\n userMessage: 'Received unexpected data from WooCommerce',\n });\n\n // Call optional validation error handler\n options?.onValidationError?.(validationError);\n\n // Report to error tracker (if provided)\n options?.errorReporter?.(validationError);\n\n throw validationError;\n }\n throw error;\n }\n }\n\n const { total, totalPages } = getPaginationMeta(response.headers);\n const page = params.page || 1;\n const perPage = params.per_page || 10;\n\n const pagination = calculatePagination({\n page,\n perPage,\n total,\n totalPages,\n });\n\n return {\n data,\n pagination,\n };\n};\n","/**\n * Debug logger for WooCommerce utils\n */\n\nconst DEBUG_PREFIX = '[woocommerce-utils]';\n\n/**\n * Check if debug mode is enabled\n */\nexport const isDebugEnabled = (): boolean => {\n if (typeof process !== 'undefined' && process.env) {\n return process.env.DEBUG === 'true' || process.env.DEBUG === '1';\n }\n return false;\n};\n\n/**\n * Log debug message (only if DEBUG is enabled)\n */\nexport const debug = (...args: unknown[]): void => {\n if (isDebugEnabled()) {\n console.log(DEBUG_PREFIX, ...args);\n }\n};\n\n/**\n * Log warning message\n */\nexport const warn = (...args: unknown[]): void => {\n console.warn(DEBUG_PREFIX, ...args);\n};\n\n/**\n * Log error message\n */\nexport const error = (...args: unknown[]): void => {\n console.error(DEBUG_PREFIX, ...args);\n};\n","const CART_ROUTE = /\\/wc\\/store\\/(v\\d+\\/)?(cart|checkout|batch)/;\nconst BATCH_ROUTE = /\\/wc\\/store\\/(v\\d+\\/)?batch/;\n\nexport const isCartRoute = (url?: string): boolean => !!url && CART_ROUTE.test(url);\n\nexport const isBatchRoute = (url?: string): boolean => !!url && BATCH_ROUTE.test(url);\n","/**\n * Request interceptor\n *\n * Handles:\n * - JWT authentication for protected endpoints\n * - Nonce/Cart-Token injection for cart/checkout endpoints\n * - Cache-Control headers for cart/checkout to prevent Android caching bugs\n * - Debug logging\n */\n\nimport type { AxiosInstance, InternalAxiosRequestConfig } from 'axios';\n\nimport type { WooCommerceClient, WooCommerceConfig } from '../../client/types';\nimport { debug } from '../../logging/logger';\nimport { isBatchRoute, isCartRoute } from '../storeRoutes';\n\n/**\n * Check if endpoint requires JWT authentication\n */\nconst requiresAuth = (url?: string): boolean => {\n if (!url) return false;\n\n const authEndpoints = [\n '/jwt-auth/',\n '/customers/me',\n '/wp/v2/users/me',\n // Store API non-cart endpoints: inject JWT when available so authenticated\n // users can access their own resources (e.g. orders, personalised product data)\n '/wc/store/v1/order',\n ];\n\n return authEndpoints.some((endpoint) => url.includes(endpoint));\n};\n\n/**\n * Setup request interceptor\n *\n * - Injects JWT Bearer token for authenticated requests\n * - Injects Nonce/Cart-Token headers for cart/checkout requests\n * - Adds Cache-Control headers to prevent Android caching bugs\n * - Calls optional onRequest hook\n * - Passes client instance to callbacks\n */\nexport const setupRequestInterceptor = (\n axiosInstance: AxiosInstance,\n config: WooCommerceConfig,\n client: WooCommerceClient\n): void => {\n axiosInstance.interceptors.request.use(\n async (requestConfig: InternalAxiosRequestConfig) => {\n const url = requestConfig.url;\n\n // Inject JWT token for authenticated endpoints\n if (config.jwtToken) {\n const token = await config.jwtToken.get();\n if (token && (requiresAuth(url) || isCartRoute(url))) {\n requestConfig.headers.Authorization = `Bearer ${token}`;\n if (config.debug) {\n debug('Injected JWT token for', url);\n }\n }\n }\n\n // Inject nonce/cart-token for cart endpoints\n // When JWT is present, skip Cart-Token: WooCommerce prioritizes Cart-Token over JWT\n // for session identification, which would route requests to a separate API session\n // instead of the user's persistent cart.\n //\n // /batch is the exception. WP core rebuilds every sub-request as a fresh\n // WP_REST_Request, so none of them inherit the Nonce header and each one fails\n // AbstractCartRoute::check_nonce(). WooCommerce waives the nonce when\n // has_cart_token() is set, and that helper reads the outer HTTP header precisely\n // so it survives batch dispatch — so Cart-Token is the only credential a batch\n // sub-request can present.\n if (isCartRoute(url)) {\n const headers = await config.cartHeaders.get();\n const isAuthenticated = !!(await config.jwtToken?.get());\n\n if (headers.nonce) {\n requestConfig.headers.Nonce = headers.nonce;\n }\n if (headers.cartToken && (!isAuthenticated || isBatchRoute(url))) {\n requestConfig.headers['Cart-Token'] = headers.cartToken;\n }\n\n // CRITICAL: Disable HTTP caching for cart/checkout endpoints\n // WooCommerce sends aggressive cache headers (max-age=2419200, 28 days) which\n // can cause Android HTTP clients to serve stale cart data from cache.\n // This was causing empty carts to be returned after successful add-item operations\n // because the cached GET /cart response (from before items were added) was being\n // served instead of fetching fresh data from the server.\n // iOS URLSession happened to work because it handles expired cache differently.\n requestConfig.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate';\n requestConfig.headers.Pragma = 'no-cache';\n requestConfig.headers.Expires = '0';\n\n if (config.debug) {\n debug('Injected cart headers for', url, {\n hasNonce: !!headers.nonce,\n hasCartToken: !!headers.cartToken,\n });\n }\n }\n\n // Debug logging\n if (config.debug) {\n debug(\n `${requestConfig.method?.toUpperCase()} ${requestConfig.url}`,\n requestConfig.params || requestConfig.data\n );\n }\n\n // Call optional onRequest hook\n if (config.onRequest) {\n return config.onRequest(requestConfig, client);\n }\n\n return requestConfig;\n },\n (error) => {\n return Promise.reject(error);\n }\n );\n};\n","/**\n * Axios response interceptor for WooCommerce API\n */\n\nimport { AxiosError, type AxiosInstance, type AxiosResponse } from 'axios';\n\nimport type { WooCommerceClient, WooCommerceConfig } from '../../client/types';\nimport { debug } from '../../logging/logger';\nimport { isBatchRoute, isCartRoute } from '../storeRoutes';\n\nconst NONCE_ERROR_CODES = ['woocommerce_rest_missing_nonce', 'woocommerce_rest_invalid_nonce'];\n\nconst isNonceRejectedBatch = (data: unknown): boolean => {\n const responses = (data as { responses?: unknown } | null | undefined)?.responses;\n\n if (!Array.isArray(responses) || responses.length === 0) return false;\n\n return responses.every((response) => {\n const code = (response as { body?: { code?: unknown } } | null)?.body?.code;\n return typeof code === 'string' && NONCE_ERROR_CODES.includes(code);\n });\n};\n\n/**\n * Setup response interceptor\n *\n * - Extracts and saves cart headers (nonce rotation)\n * - Logs responses in debug mode\n * - Calls optional onResponse hook\n * - Passes client instance to callbacks\n */\nexport const setupResponseInterceptor = (\n axiosInstance: AxiosInstance,\n config: WooCommerceConfig,\n client: WooCommerceClient\n): void => {\n axiosInstance.interceptors.response.use(\n async (response: AxiosResponse) => {\n // Extract and save cart headers (nonce rotation)\n if (isCartRoute(response.config.url)) {\n const nonce = response.headers['nonce'] || response.headers['Nonce'];\n const cartToken = response.headers['cart-token'] || response.headers['Cart-Token'];\n\n if (nonce || cartToken) {\n await config.cartHeaders.save({\n nonce: nonce || undefined,\n cartToken: cartToken || undefined,\n });\n\n if (config.debug) {\n debug(\n 'Saved updated cart headers:',\n response.config.url,\n 'nonce:',\n !!nonce,\n 'cartToken:',\n !!cartToken\n );\n }\n }\n }\n\n if (isBatchRoute(response.config.url) && isNonceRejectedBatch(response.data)) {\n throw new AxiosError(\n 'Batch rejected for a nonce error',\n AxiosError.ERR_BAD_REQUEST,\n response.config,\n response.request,\n { ...response, status: 401, data: { code: 'woocommerce_rest_missing_nonce' } }\n );\n }\n\n if (config.debug) {\n debug('Response:', response.config.url, response.status);\n }\n\n // Call optional onResponse hook\n if (config.onResponse) {\n return config.onResponse(response, client);\n }\n\n return response;\n },\n (error) => {\n return Promise.reject(error);\n }\n );\n};\n","/**\n * Cart session initialization utility\n */\n\nimport type { AxiosInstance } from 'axios';\n\nimport type { CartHeadersAdapter } from '../client/types';\nimport { debug } from '../logging/logger';\n\n/**\n * Initialize cart session by fetching cart and saving headers\n *\n * This is called when nonce errors occur to get a fresh nonce/cart-token\n *\n * @param client - Axios instance\n * @param cartHeaders - Cart headers adapter\n */\nexport const initializeCartSession = async (\n client: AxiosInstance,\n cartHeaders: CartHeadersAdapter\n): Promise<void> => {\n try {\n debug('session', 'Initializing cart session');\n\n // Make GET request to cart endpoint\n const response = await client.get('/wc/store/v1/cart');\n\n // Extract headers\n const nonce = response.headers['nonce'] || response.headers['Nonce'];\n const cartToken = response.headers['cart-token'] || response.headers['Cart-Token'];\n\n // Save headers\n if (nonce || cartToken) {\n await cartHeaders.save({\n nonce: nonce || undefined,\n cartToken: cartToken || undefined,\n });\n\n debug('session', 'Cart session initialized', {\n hasNonce: !!nonce,\n hasCartToken: !!cartToken,\n });\n }\n } catch (error) {\n debug('session', 'Failed to initialize cart session', error);\n throw error;\n }\n};\n","/**\n * Axios error interceptor for WooCommerce API\n */\n\nimport { isAxiosError, isCancel, type AxiosError, type AxiosInstance } from 'axios';\n\nimport type { WooCommerceClient, WooCommerceConfig } from '../../client/types';\nimport { WooCommerceApiError } from '../../errors/classes/WooCommerceApiError';\nimport { mapWooCommerceCode } from '../../errors/mapping';\nimport { debug, error as logError } from '../../logging/logger';\nimport { initializeCartSession } from '../../utils/initializeCartSession';\n\ninterface WooCommerceErrorData {\n code?: string;\n message?: string;\n data?: {\n status?: number;\n };\n}\n\n/**\n * Setup error interceptor\n *\n * - Transforms WooCommerce errors into WooCommerceApiError instances\n * - Calls optional onError hook\n * - Passes client instance to callbacks\n */\nexport const setupErrorInterceptor = (\n axiosInstance: AxiosInstance,\n config: WooCommerceConfig,\n client: WooCommerceClient\n): void => {\n axiosInstance.interceptors.response.use(\n (response) => response,\n async (axiosError: AxiosError<WooCommerceErrorData>) => {\n if (isCancel(axiosError)) {\n return Promise.reject(axiosError);\n }\n\n const status = axiosError.response?.status;\n const errorData = axiosError.response?.data;\n const isNetworkError = isAxiosError(axiosError) && !axiosError.response;\n\n // Extract WooCommerce error details\n const apiCode = errorData?.code || 'unknown_error';\n const wpMessage = errorData?.message || axiosError.message || 'Unknown error';\n\n // Transform WooCommerce API code to application-level code\n // e.g., \"woocommerce_rest_cart_empty\" → \"cart_empty\"\n const errorCode = isNetworkError ? 'network_error' : mapWooCommerceCode(apiCode);\n\n // Create WooCommerceError with full context\n const wcError = new WooCommerceApiError({\n message: wpMessage,\n statusCode: status,\n code: errorCode, // Transformed app-level code\n originalCode: apiCode, // Original WooCommerce API code\n url: axiosError.config?.url || '',\n method: axiosError.config?.method?.toUpperCase() || 'GET',\n requestBody: axiosError.config?.data,\n responseBody: errorData,\n data: errorData?.data as Record<string, unknown> | undefined,\n cause: axiosError,\n });\n\n if (config.debug) {\n debug('WooCommerce error:', apiCode, status, wpMessage);\n logError(wcError);\n }\n\n // Handle authentication errors (401/403)\n if (\n (status === 401 || status === 403) &&\n config.onAuthError &&\n isAxiosError(axiosError) &&\n !axiosError.config?._retry\n ) {\n if (config.debug) {\n debug('Auth error detected, calling onAuthError handler');\n }\n\n try {\n const shouldRetry = await config.onAuthError(wcError, client);\n\n if (shouldRetry) {\n if (config.debug) {\n debug('Retrying request after auth error');\n }\n\n // Mark as retry to prevent infinite loops\n axiosError.config!._retry = true;\n\n // Retry the request\n return axiosInstance.request(axiosError.config!);\n }\n } catch (authErrorHandlerError) {\n // If onAuthError handler throws, fall through to error reporting\n if (config.debug) {\n debug('onAuthError handler threw error', authErrorHandlerError);\n }\n }\n }\n\n // Call optional onError hook first (even for retryable errors)\n if (config.onError) {\n config.onError(wcError, client);\n }\n\n // Auto-retry nonce errors\n const isNonceError = errorCode === 'missing_nonce' || errorCode === 'invalid_nonce';\n if (isNonceError && isAxiosError(axiosError) && !axiosError.config?._retry) {\n if (config.debug) {\n debug('Nonce error detected, retrying with new session');\n }\n\n try {\n // Initialize new cart session\n await initializeCartSession(axiosInstance, config.cartHeaders);\n\n // Mark as retry to prevent infinite loops\n axiosError.config!._retry = true;\n\n // Retry the request\n return axiosInstance.request(axiosError.config!);\n } catch (_retryError) {\n // If retry fails, report and throw original error\n config.errorReporter?.report(wcError);\n return Promise.reject(wcError);\n }\n }\n\n // Report error to configured error reporter (Sentry, etc.)\n config.errorReporter?.report(wcError);\n\n return Promise.reject(wcError);\n }\n );\n};\n\n// Augment AxiosRequestConfig to include _retry flag\ndeclare module 'axios' {\n export interface AxiosRequestConfig {\n _retry?: boolean;\n }\n}\n"]}
@@ -1,4 +1,13 @@
1
- import { AxiosError, isAxiosError } from 'axios';
1
+ import { BaseError as BaseError$1 } from '@atomic-solutions/errors';
2
+ import { AxiosError, isCancel, isAxiosError } from 'axios';
3
+
4
+ var __typeError = (msg) => {
5
+ throw TypeError(msg);
6
+ };
7
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
8
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
9
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
10
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
2
11
 
3
12
  // src/errors/classes/BaseError.ts
4
13
  var BaseError = class extends Error {
@@ -127,8 +136,16 @@ var WOOCOMMERCE_ERROR_METADATA = {
127
136
  }
128
137
  };
129
138
 
139
+ // src/errors/classes/http-error.ts
140
+ var redactPath = (url) => url.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/]+/i, "").replace(/[?#].*$/, "").split("/").map((segment) => /^(\d+|[0-9a-f]{16,}|[0-9a-f-]{36})$/i.test(segment) ? ":id" : segment).join("/");
141
+ var classifyHttpStatus = (status) => ({
142
+ domain: status === void 0 ? "network" : status === 401 || status === 403 ? "auth" : "integration",
143
+ severity: status !== void 0 && status < 500 ? "warning" : "error"
144
+ });
145
+
130
146
  // src/errors/classes/WooCommerceApiError.ts
131
- var WooCommerceApiError = class extends BaseError {
147
+ var _options;
148
+ var WooCommerceApiError = class extends BaseError$1 {
132
149
  constructor(options) {
133
150
  const metadata = WOOCOMMERCE_ERROR_METADATA[options.code] ?? {
134
151
  operation: "woocommerce_api_request",
@@ -140,7 +157,30 @@ var WooCommerceApiError = class extends BaseError {
140
157
  userMessage: options.userMessage || metadata.userMessage,
141
158
  retryable: options.retryable ?? metadata.retryable
142
159
  };
143
- super(enrichedOptions);
160
+ const status = enrichedOptions.statusCode;
161
+ const { domain, severity } = classifyHttpStatus(status);
162
+ super({
163
+ domain,
164
+ severity,
165
+ operation: enrichedOptions.operation,
166
+ message: enrichedOptions.message,
167
+ code: enrichedOptions.code,
168
+ retryable: enrichedOptions.retryable,
169
+ userMessage: enrichedOptions.userMessage,
170
+ cause: enrichedOptions.cause,
171
+ fingerprint: [domain, enrichedOptions.code, String(status ?? "network")],
172
+ extras: {
173
+ originalCode: enrichedOptions.originalCode,
174
+ statusCode: status,
175
+ path: redactPath(enrichedOptions.url),
176
+ method: enrichedOptions.method
177
+ }
178
+ });
179
+ __privateAdd(this, _options);
180
+ __privateSet(this, _options, enrichedOptions);
181
+ }
182
+ get options() {
183
+ return __privateGet(this, _options);
144
184
  }
145
185
  // Convenient getters for frequently accessed fields (no duplication)
146
186
  get wooCode() {
@@ -167,24 +207,8 @@ var WooCommerceApiError = class extends BaseError {
167
207
  get data() {
168
208
  return this.options.data;
169
209
  }
170
- /**
171
- * Get reportable data for error tracking/logging
172
- * Includes HTTP context and WooCommerce-specific fields
173
- */
174
- getReportableData() {
175
- return {
176
- code: this.options.code,
177
- operation: this.options.operation,
178
- userMessage: this.options.userMessage,
179
- retryable: this.options.retryable,
180
- statusCode: this.options.statusCode,
181
- url: this.options.url,
182
- method: this.options.method,
183
- wooCode: this.options.code,
184
- originalCode: this.options.originalCode
185
- };
186
- }
187
210
  };
211
+ _options = new WeakMap();
188
212
 
189
213
  // src/errors/classes/WooCommerceDataValidationError.ts
190
214
  var WooCommerceDataValidationError = class _WooCommerceDataValidationError extends BaseError {
@@ -580,12 +604,15 @@ var setupErrorInterceptor = (axiosInstance, config, client) => {
580
604
  axiosInstance.interceptors.response.use(
581
605
  (response) => response,
582
606
  async (axiosError) => {
583
- const status = axiosError.response?.status || 500;
607
+ if (isCancel(axiosError)) {
608
+ return Promise.reject(axiosError);
609
+ }
610
+ const status = axiosError.response?.status;
584
611
  const errorData = axiosError.response?.data;
612
+ const isNetworkError = isAxiosError(axiosError) && !axiosError.response;
585
613
  const apiCode = errorData?.code || "unknown_error";
586
614
  const wpMessage = errorData?.message || axiosError.message || "Unknown error";
587
- const errorCode = mapWooCommerceCode(apiCode);
588
- const errorMetadata = WOOCOMMERCE_ERROR_METADATA[errorCode];
615
+ const errorCode = isNetworkError ? "network_error" : mapWooCommerceCode(apiCode);
589
616
  const wcError = new WooCommerceApiError({
590
617
  message: wpMessage,
591
618
  statusCode: status,
@@ -593,9 +620,6 @@ var setupErrorInterceptor = (axiosInstance, config, client) => {
593
620
  // Transformed app-level code
594
621
  originalCode: apiCode,
595
622
  // Original WooCommerce API code
596
- retryable: errorMetadata.retryable,
597
- userMessage: errorMetadata.userMessage,
598
- operation: errorMetadata.operation,
599
623
  url: axiosError.config?.url || "",
600
624
  method: axiosError.config?.method?.toUpperCase() || "GET",
601
625
  requestBody: axiosError.config?.data,