@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,5 +1,6 @@
1
- import { S as StoreApiVersion, C as CartHeadersAdapter, J as JwtTokenAdapter } from '../types-aYzN4O5x.mjs';
1
+ import { S as StoreApiVersion, C as CartHeadersAdapter, J as JwtTokenAdapter } from '../types-9I6oS_83.mjs';
2
2
  import 'axios';
3
+ import '@atomic-solutions/errors';
3
4
  import 'zod';
4
5
 
5
6
  type DescribeFn = (name: string, fn: () => void) => void;
@@ -1,5 +1,6 @@
1
- import { S as StoreApiVersion, C as CartHeadersAdapter, J as JwtTokenAdapter } from '../types-aYzN4O5x.js';
1
+ import { S as StoreApiVersion, C as CartHeadersAdapter, J as JwtTokenAdapter } from '../types-9I6oS_83.js';
2
2
  import 'axios';
3
+ import '@atomic-solutions/errors';
3
4
  import 'zod';
4
5
 
5
6
  type DescribeFn = (name: string, fn: () => void) => void;
@@ -1,13 +1,20 @@
1
1
  'use strict';
2
2
 
3
3
  var axios = require('axios');
4
+ var errors = require('@atomic-solutions/errors');
4
5
  var zod = require('zod');
5
6
 
6
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
8
 
8
9
  var axios__default = /*#__PURE__*/_interopDefault(axios);
9
10
 
10
- // src/client/createClient.ts
11
+ var __typeError = (msg) => {
12
+ throw TypeError(msg);
13
+ };
14
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
15
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
16
+ 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);
17
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
11
18
 
12
19
  // src/errors/classes/BaseError.ts
13
20
  var BaseError = class extends Error {
@@ -136,8 +143,16 @@ var WOOCOMMERCE_ERROR_METADATA = {
136
143
  }
137
144
  };
138
145
 
146
+ // src/errors/classes/http-error.ts
147
+ 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("/");
148
+ var classifyHttpStatus = (status) => ({
149
+ domain: status === void 0 ? "network" : status === 401 || status === 403 ? "auth" : "integration",
150
+ severity: status !== void 0 && status < 500 ? "warning" : "error"
151
+ });
152
+
139
153
  // src/errors/classes/WooCommerceApiError.ts
140
- var WooCommerceApiError = class extends BaseError {
154
+ var _options;
155
+ var WooCommerceApiError = class extends errors.BaseError {
141
156
  constructor(options) {
142
157
  const metadata = WOOCOMMERCE_ERROR_METADATA[options.code] ?? {
143
158
  operation: "woocommerce_api_request",
@@ -149,7 +164,30 @@ var WooCommerceApiError = class extends BaseError {
149
164
  userMessage: options.userMessage || metadata.userMessage,
150
165
  retryable: options.retryable ?? metadata.retryable
151
166
  };
152
- super(enrichedOptions);
167
+ const status = enrichedOptions.statusCode;
168
+ const { domain, severity } = classifyHttpStatus(status);
169
+ super({
170
+ domain,
171
+ severity,
172
+ operation: enrichedOptions.operation,
173
+ message: enrichedOptions.message,
174
+ code: enrichedOptions.code,
175
+ retryable: enrichedOptions.retryable,
176
+ userMessage: enrichedOptions.userMessage,
177
+ cause: enrichedOptions.cause,
178
+ fingerprint: [domain, enrichedOptions.code, String(status ?? "network")],
179
+ extras: {
180
+ originalCode: enrichedOptions.originalCode,
181
+ statusCode: status,
182
+ path: redactPath(enrichedOptions.url),
183
+ method: enrichedOptions.method
184
+ }
185
+ });
186
+ __privateAdd(this, _options);
187
+ __privateSet(this, _options, enrichedOptions);
188
+ }
189
+ get options() {
190
+ return __privateGet(this, _options);
153
191
  }
154
192
  // Convenient getters for frequently accessed fields (no duplication)
155
193
  get wooCode() {
@@ -176,24 +214,8 @@ var WooCommerceApiError = class extends BaseError {
176
214
  get data() {
177
215
  return this.options.data;
178
216
  }
179
- /**
180
- * Get reportable data for error tracking/logging
181
- * Includes HTTP context and WooCommerce-specific fields
182
- */
183
- getReportableData() {
184
- return {
185
- code: this.options.code,
186
- operation: this.options.operation,
187
- userMessage: this.options.userMessage,
188
- retryable: this.options.retryable,
189
- statusCode: this.options.statusCode,
190
- url: this.options.url,
191
- method: this.options.method,
192
- wooCode: this.options.code,
193
- originalCode: this.options.originalCode
194
- };
195
- }
196
217
  };
218
+ _options = new WeakMap();
197
219
 
198
220
  // src/errors/classes/WooCommerceDataValidationError.ts
199
221
  var WooCommerceDataValidationError = class _WooCommerceDataValidationError extends BaseError {
@@ -586,12 +608,15 @@ var setupErrorInterceptor = (axiosInstance, config, client) => {
586
608
  axiosInstance.interceptors.response.use(
587
609
  (response) => response,
588
610
  async (axiosError) => {
589
- const status = axiosError.response?.status || 500;
611
+ if (axios.isCancel(axiosError)) {
612
+ return Promise.reject(axiosError);
613
+ }
614
+ const status = axiosError.response?.status;
590
615
  const errorData = axiosError.response?.data;
616
+ const isNetworkError = axios.isAxiosError(axiosError) && !axiosError.response;
591
617
  const apiCode = errorData?.code || "unknown_error";
592
618
  const wpMessage = errorData?.message || axiosError.message || "Unknown error";
593
- const errorCode = mapWooCommerceCode(apiCode);
594
- const errorMetadata = WOOCOMMERCE_ERROR_METADATA[errorCode];
619
+ const errorCode = isNetworkError ? "network_error" : mapWooCommerceCode(apiCode);
595
620
  const wcError = new WooCommerceApiError({
596
621
  message: wpMessage,
597
622
  statusCode: status,
@@ -599,9 +624,6 @@ var setupErrorInterceptor = (axiosInstance, config, client) => {
599
624
  // Transformed app-level code
600
625
  originalCode: apiCode,
601
626
  // Original WooCommerce API code
602
- retryable: errorMetadata.retryable,
603
- userMessage: errorMetadata.userMessage,
604
- operation: errorMetadata.operation,
605
627
  url: axiosError.config?.url || "",
606
628
  method: axiosError.config?.method?.toUpperCase() || "GET",
607
629
  requestBody: axiosError.config?.data,