@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.
- package/dist/client/index.d.mts +3 -2
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.js +48 -26
- package/dist/client/index.js.map +1 -1
- package/dist/client/index.mjs +49 -27
- package/dist/client/index.mjs.map +1 -1
- package/dist/http/index.d.mts +3 -2
- package/dist/http/index.d.ts +3 -2
- package/dist/http/index.js +49 -25
- package/dist/http/index.js.map +1 -1
- package/dist/http/index.mjs +50 -26
- package/dist/http/index.mjs.map +1 -1
- package/dist/index.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +48 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -27
- package/dist/index.mjs.map +1 -1
- package/dist/testing/index.d.mts +2 -1
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.js +48 -26
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/index.mjs +49 -27
- package/dist/testing/index.mjs.map +1 -1
- package/dist/{types-aYzN4O5x.d.mts → types-9I6oS_83.d.mts} +7 -19
- package/dist/{types-aYzN4O5x.d.ts → types-9I6oS_83.d.ts} +7 -19
- package/dist/utils/index.d.mts +3 -2
- package/dist/utils/index.d.ts +3 -2
- package/package.json +3 -1
package/dist/client/index.mjs
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
|
-
import axios, { AxiosError, isAxiosError } from 'axios';
|
|
1
|
+
import axios, { AxiosError, isCancel, isAxiosError } from 'axios';
|
|
2
|
+
import { BaseError as BaseError$1 } from '@atomic-solutions/errors';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
var __typeError = (msg) => {
|
|
6
|
+
throw TypeError(msg);
|
|
7
|
+
};
|
|
8
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
9
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
10
|
+
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);
|
|
11
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
5
12
|
|
|
6
13
|
// src/errors/classes/BaseError.ts
|
|
7
14
|
var BaseError = class extends Error {
|
|
@@ -130,8 +137,16 @@ var WOOCOMMERCE_ERROR_METADATA = {
|
|
|
130
137
|
}
|
|
131
138
|
};
|
|
132
139
|
|
|
140
|
+
// src/errors/classes/http-error.ts
|
|
141
|
+
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("/");
|
|
142
|
+
var classifyHttpStatus = (status) => ({
|
|
143
|
+
domain: status === void 0 ? "network" : status === 401 || status === 403 ? "auth" : "integration",
|
|
144
|
+
severity: status !== void 0 && status < 500 ? "warning" : "error"
|
|
145
|
+
});
|
|
146
|
+
|
|
133
147
|
// src/errors/classes/WooCommerceApiError.ts
|
|
134
|
-
var
|
|
148
|
+
var _options;
|
|
149
|
+
var WooCommerceApiError = class extends BaseError$1 {
|
|
135
150
|
constructor(options) {
|
|
136
151
|
const metadata = WOOCOMMERCE_ERROR_METADATA[options.code] ?? {
|
|
137
152
|
operation: "woocommerce_api_request",
|
|
@@ -143,7 +158,30 @@ var WooCommerceApiError = class extends BaseError {
|
|
|
143
158
|
userMessage: options.userMessage || metadata.userMessage,
|
|
144
159
|
retryable: options.retryable ?? metadata.retryable
|
|
145
160
|
};
|
|
146
|
-
|
|
161
|
+
const status = enrichedOptions.statusCode;
|
|
162
|
+
const { domain, severity } = classifyHttpStatus(status);
|
|
163
|
+
super({
|
|
164
|
+
domain,
|
|
165
|
+
severity,
|
|
166
|
+
operation: enrichedOptions.operation,
|
|
167
|
+
message: enrichedOptions.message,
|
|
168
|
+
code: enrichedOptions.code,
|
|
169
|
+
retryable: enrichedOptions.retryable,
|
|
170
|
+
userMessage: enrichedOptions.userMessage,
|
|
171
|
+
cause: enrichedOptions.cause,
|
|
172
|
+
fingerprint: [domain, enrichedOptions.code, String(status ?? "network")],
|
|
173
|
+
extras: {
|
|
174
|
+
originalCode: enrichedOptions.originalCode,
|
|
175
|
+
statusCode: status,
|
|
176
|
+
path: redactPath(enrichedOptions.url),
|
|
177
|
+
method: enrichedOptions.method
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
__privateAdd(this, _options);
|
|
181
|
+
__privateSet(this, _options, enrichedOptions);
|
|
182
|
+
}
|
|
183
|
+
get options() {
|
|
184
|
+
return __privateGet(this, _options);
|
|
147
185
|
}
|
|
148
186
|
// Convenient getters for frequently accessed fields (no duplication)
|
|
149
187
|
get wooCode() {
|
|
@@ -170,24 +208,8 @@ var WooCommerceApiError = class extends BaseError {
|
|
|
170
208
|
get data() {
|
|
171
209
|
return this.options.data;
|
|
172
210
|
}
|
|
173
|
-
/**
|
|
174
|
-
* Get reportable data for error tracking/logging
|
|
175
|
-
* Includes HTTP context and WooCommerce-specific fields
|
|
176
|
-
*/
|
|
177
|
-
getReportableData() {
|
|
178
|
-
return {
|
|
179
|
-
code: this.options.code,
|
|
180
|
-
operation: this.options.operation,
|
|
181
|
-
userMessage: this.options.userMessage,
|
|
182
|
-
retryable: this.options.retryable,
|
|
183
|
-
statusCode: this.options.statusCode,
|
|
184
|
-
url: this.options.url,
|
|
185
|
-
method: this.options.method,
|
|
186
|
-
wooCode: this.options.code,
|
|
187
|
-
originalCode: this.options.originalCode
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
211
|
};
|
|
212
|
+
_options = new WeakMap();
|
|
191
213
|
|
|
192
214
|
// src/errors/classes/WooCommerceDataValidationError.ts
|
|
193
215
|
var WooCommerceDataValidationError = class _WooCommerceDataValidationError extends BaseError {
|
|
@@ -580,12 +602,15 @@ var setupErrorInterceptor = (axiosInstance, config, client) => {
|
|
|
580
602
|
axiosInstance.interceptors.response.use(
|
|
581
603
|
(response) => response,
|
|
582
604
|
async (axiosError) => {
|
|
583
|
-
|
|
605
|
+
if (isCancel(axiosError)) {
|
|
606
|
+
return Promise.reject(axiosError);
|
|
607
|
+
}
|
|
608
|
+
const status = axiosError.response?.status;
|
|
584
609
|
const errorData = axiosError.response?.data;
|
|
610
|
+
const isNetworkError = isAxiosError(axiosError) && !axiosError.response;
|
|
585
611
|
const apiCode = errorData?.code || "unknown_error";
|
|
586
612
|
const wpMessage = errorData?.message || axiosError.message || "Unknown error";
|
|
587
|
-
const errorCode = mapWooCommerceCode(apiCode);
|
|
588
|
-
const errorMetadata = WOOCOMMERCE_ERROR_METADATA[errorCode];
|
|
613
|
+
const errorCode = isNetworkError ? "network_error" : mapWooCommerceCode(apiCode);
|
|
589
614
|
const wcError = new WooCommerceApiError({
|
|
590
615
|
message: wpMessage,
|
|
591
616
|
statusCode: status,
|
|
@@ -593,9 +618,6 @@ var setupErrorInterceptor = (axiosInstance, config, client) => {
|
|
|
593
618
|
// Transformed app-level code
|
|
594
619
|
originalCode: apiCode,
|
|
595
620
|
// Original WooCommerce API code
|
|
596
|
-
retryable: errorMetadata.retryable,
|
|
597
|
-
userMessage: errorMetadata.userMessage,
|
|
598
|
-
operation: errorMetadata.operation,
|
|
599
621
|
url: axiosError.config?.url || "",
|
|
600
622
|
method: axiosError.config?.method?.toUpperCase() || "GET",
|
|
601
623
|
requestBody: axiosError.config?.data,
|