@atomic-solutions/wordpress-api-client 0.1.0

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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +295 -0
  3. package/dist/calculatePagination-WUlN3OdM.d.cts +19 -0
  4. package/dist/calculatePagination-WUlN3OdM.d.ts +19 -0
  5. package/dist/client/index.cjs +1143 -0
  6. package/dist/client/index.cjs.map +1 -0
  7. package/dist/client/index.d.cts +10 -0
  8. package/dist/client/index.d.ts +10 -0
  9. package/dist/client/index.js +1137 -0
  10. package/dist/client/index.js.map +1 -0
  11. package/dist/http/index.cjs +674 -0
  12. package/dist/http/index.cjs.map +1 -0
  13. package/dist/http/index.d.cts +12 -0
  14. package/dist/http/index.d.ts +12 -0
  15. package/dist/http/index.js +667 -0
  16. package/dist/http/index.js.map +1 -0
  17. package/dist/index.cjs +1251 -0
  18. package/dist/index.cjs.map +1 -0
  19. package/dist/index.d.cts +51 -0
  20. package/dist/index.d.ts +51 -0
  21. package/dist/index.js +1205 -0
  22. package/dist/index.js.map +1 -0
  23. package/dist/schemas/index.cjs +414 -0
  24. package/dist/schemas/index.cjs.map +1 -0
  25. package/dist/schemas/index.d.cts +1339 -0
  26. package/dist/schemas/index.d.ts +1339 -0
  27. package/dist/schemas/index.js +376 -0
  28. package/dist/schemas/index.js.map +1 -0
  29. package/dist/testing/index.cjs +1435 -0
  30. package/dist/testing/index.cjs.map +1 -0
  31. package/dist/testing/index.d.cts +50 -0
  32. package/dist/testing/index.d.ts +50 -0
  33. package/dist/testing/index.js +1426 -0
  34. package/dist/testing/index.js.map +1 -0
  35. package/dist/types-8pbwmNdu.d.ts +154 -0
  36. package/dist/types-BTo088EY.d.cts +154 -0
  37. package/dist/user.schema-eeUHQ4sI.d.cts +10614 -0
  38. package/dist/user.schema-eeUHQ4sI.d.ts +10614 -0
  39. package/dist/utils/index.cjs +47 -0
  40. package/dist/utils/index.cjs.map +1 -0
  41. package/dist/utils/index.d.cts +10 -0
  42. package/dist/utils/index.d.ts +10 -0
  43. package/dist/utils/index.js +44 -0
  44. package/dist/utils/index.js.map +1 -0
  45. package/package.json +103 -0
@@ -0,0 +1,667 @@
1
+ import { isAxiosError } from 'axios';
2
+
3
+ // src/errors/classes/BaseError.ts
4
+ var BaseError = class extends Error {
5
+ constructor(options) {
6
+ super(options.message);
7
+ this.options = options;
8
+ Object.setPrototypeOf(this, new.target.prototype);
9
+ this.name = this.constructor.name;
10
+ if (Error.captureStackTrace) {
11
+ Error.captureStackTrace(this, this.constructor);
12
+ }
13
+ if (this.options.cause instanceof Error && this.options.cause.stack) {
14
+ this.stack = `${this.stack}
15
+ Caused by: ${this.options.cause.stack}`;
16
+ }
17
+ }
18
+ /**
19
+ * Get reportable data for error tracking/logging
20
+ * Subclasses should override this to add their own reportable fields
21
+ */
22
+ getReportableData() {
23
+ const { code, operation, userMessage, retryable } = this.options;
24
+ return {
25
+ code,
26
+ operation,
27
+ userMessage,
28
+ retryable
29
+ };
30
+ }
31
+ /**
32
+ * Custom JSON serialization
33
+ * Makes the error properly serializable for logging/reporting
34
+ */
35
+ toJSON() {
36
+ return {
37
+ ...this.getReportableData(),
38
+ name: this.name,
39
+ message: this.message,
40
+ stack: this.stack
41
+ };
42
+ }
43
+ };
44
+
45
+ // src/errors/mapping/auth.ts
46
+ var AUTH_CODE_TRANSFORMATIONS = {
47
+ // Authentication
48
+ jwt_auth_failed: "auth_failed",
49
+ jwt_auth_invalid_token: "token_expired",
50
+ jwt_auth_bad_request: "invalid_auth_request",
51
+ // Authorization
52
+ rest_forbidden: "forbidden",
53
+ rest_cannot_read: "cannot_read",
54
+ rest_cannot_edit: "cannot_edit",
55
+ rest_cannot_create: "cannot_create",
56
+ rest_cannot_delete: "cannot_delete"
57
+ };
58
+ var AUTH_ERROR_METADATA = {
59
+ // Authentication
60
+ auth_failed: {
61
+ operation: "authenticate",
62
+ retryable: false,
63
+ userMessage: "Invalid username or password"
64
+ },
65
+ token_expired: {
66
+ operation: "validate_token",
67
+ retryable: false,
68
+ userMessage: "Your session has expired. Please sign in again."
69
+ },
70
+ invalid_auth_request: {
71
+ operation: "authenticate",
72
+ retryable: false,
73
+ userMessage: "Invalid login request"
74
+ },
75
+ // Authorization
76
+ forbidden: {
77
+ operation: "authorize",
78
+ retryable: false,
79
+ userMessage: "You do not have permission to access this resource"
80
+ },
81
+ cannot_read: {
82
+ operation: "read_resource",
83
+ retryable: false,
84
+ userMessage: "You do not have permission to view this content"
85
+ },
86
+ cannot_edit: {
87
+ operation: "edit_resource",
88
+ retryable: false,
89
+ userMessage: "You do not have permission to edit this content"
90
+ },
91
+ cannot_create: {
92
+ operation: "create_resource",
93
+ retryable: false,
94
+ userMessage: "You do not have permission to create content"
95
+ },
96
+ cannot_delete: {
97
+ operation: "delete_resource",
98
+ retryable: false,
99
+ userMessage: "You do not have permission to delete this content"
100
+ }
101
+ };
102
+
103
+ // src/errors/mapping/resources.ts
104
+ var RESOURCE_CODE_TRANSFORMATIONS = {
105
+ rest_post_invalid_id: "post_not_found",
106
+ rest_term_invalid: "term_not_found",
107
+ rest_user_invalid_id: "user_not_found",
108
+ rest_no_route: "route_not_found"
109
+ };
110
+ var RESOURCE_ERROR_METADATA = {
111
+ post_not_found: {
112
+ operation: "get_post",
113
+ retryable: false,
114
+ userMessage: "Post not found"
115
+ },
116
+ term_not_found: {
117
+ operation: "get_term",
118
+ retryable: false,
119
+ userMessage: "Category or tag not found"
120
+ },
121
+ user_not_found: {
122
+ operation: "get_user",
123
+ retryable: false,
124
+ userMessage: "User not found"
125
+ },
126
+ route_not_found: {
127
+ operation: "api_request",
128
+ retryable: false,
129
+ userMessage: "The requested resource was not found"
130
+ }
131
+ };
132
+
133
+ // src/errors/mapping/server.ts
134
+ var SERVER_CODE_TRANSFORMATIONS = {
135
+ rest_cookie_invalid_nonce: "invalid_nonce",
136
+ internal_error: "server_error"
137
+ };
138
+ var SERVER_ERROR_METADATA = {
139
+ invalid_nonce: {
140
+ operation: "api_request",
141
+ retryable: true,
142
+ userMessage: "Session expired. Please try again."
143
+ },
144
+ server_error: {
145
+ operation: "api_request",
146
+ retryable: true,
147
+ userMessage: "An unexpected error occurred. Please try again."
148
+ },
149
+ unknown_error: {
150
+ operation: "api_request",
151
+ retryable: false,
152
+ userMessage: "An error occurred"
153
+ }
154
+ };
155
+
156
+ // src/errors/mapping/constants.ts
157
+ var VALIDATION_CODE_TRANSFORMATIONS = {
158
+ rest_invalid_param: "invalid_params",
159
+ rest_missing_callback_param: "missing_params"
160
+ };
161
+ var VALIDATION_ERROR_METADATA = {
162
+ invalid_params: {
163
+ operation: "api_request",
164
+ retryable: false,
165
+ userMessage: "Invalid request parameters"
166
+ },
167
+ missing_params: {
168
+ operation: "api_request",
169
+ retryable: false,
170
+ userMessage: "Missing required parameters"
171
+ }
172
+ };
173
+ var WORDPRESS_ERROR_METADATA = {
174
+ ...AUTH_ERROR_METADATA,
175
+ ...RESOURCE_ERROR_METADATA,
176
+ ...VALIDATION_ERROR_METADATA,
177
+ ...SERVER_ERROR_METADATA
178
+ };
179
+
180
+ // src/errors/mapping/index.ts
181
+ var CODE_TRANSFORMATIONS = {
182
+ ...AUTH_CODE_TRANSFORMATIONS,
183
+ ...RESOURCE_CODE_TRANSFORMATIONS,
184
+ ...VALIDATION_CODE_TRANSFORMATIONS,
185
+ ...SERVER_CODE_TRANSFORMATIONS
186
+ };
187
+ var ERROR_METADATA = {
188
+ ...AUTH_ERROR_METADATA,
189
+ ...RESOURCE_ERROR_METADATA,
190
+ ...VALIDATION_ERROR_METADATA,
191
+ ...SERVER_ERROR_METADATA
192
+ };
193
+ var mapWordPressCode = (apiCode, status) => {
194
+ const appCode = CODE_TRANSFORMATIONS[apiCode];
195
+ if (appCode) {
196
+ const metadata = ERROR_METADATA[appCode];
197
+ return {
198
+ code: appCode,
199
+ ...metadata
200
+ };
201
+ }
202
+ if (apiCode.includes("invalid_id") || apiCode.includes("not_found")) {
203
+ return {
204
+ code: "route_not_found",
205
+ ...ERROR_METADATA.route_not_found
206
+ };
207
+ }
208
+ if (apiCode.includes("cannot_") || apiCode.includes("forbidden")) {
209
+ return {
210
+ code: "forbidden",
211
+ ...ERROR_METADATA.forbidden
212
+ };
213
+ }
214
+ if (apiCode.includes("invalid_param") || apiCode.includes("missing_")) {
215
+ return {
216
+ code: "invalid_params",
217
+ ...ERROR_METADATA.invalid_params
218
+ };
219
+ }
220
+ if (apiCode.includes("nonce")) {
221
+ return {
222
+ code: "invalid_nonce",
223
+ ...ERROR_METADATA.invalid_nonce
224
+ };
225
+ }
226
+ if (status === 401) {
227
+ return {
228
+ code: "auth_failed",
229
+ retryable: false,
230
+ userMessage: "Authentication required"
231
+ };
232
+ }
233
+ if (status === 403) {
234
+ return {
235
+ code: "forbidden",
236
+ ...ERROR_METADATA.forbidden
237
+ };
238
+ }
239
+ if (status === 404) {
240
+ return {
241
+ code: "route_not_found",
242
+ ...ERROR_METADATA.route_not_found
243
+ };
244
+ }
245
+ if (status >= 500) {
246
+ return {
247
+ code: "server_error",
248
+ ...ERROR_METADATA.server_error
249
+ };
250
+ }
251
+ return {
252
+ code: "unknown_error",
253
+ ...ERROR_METADATA.unknown_error
254
+ };
255
+ };
256
+
257
+ // src/errors/classes/WordPressApiError.ts
258
+ var WordPressApiError = class extends BaseError {
259
+ constructor(options) {
260
+ const metadata = WORDPRESS_ERROR_METADATA[options.code] ?? {
261
+ operation: "wordpress_api_request",
262
+ retryable: false
263
+ };
264
+ const enrichedOptions = {
265
+ ...options,
266
+ operation: options.operation || metadata.operation,
267
+ userMessage: options.userMessage || metadata.userMessage,
268
+ retryable: options.retryable ?? metadata.retryable
269
+ };
270
+ super(enrichedOptions);
271
+ }
272
+ // Convenient getters for frequently accessed fields (no duplication)
273
+ get wpCode() {
274
+ return this.options.code;
275
+ }
276
+ get originalCode() {
277
+ return this.options.originalCode;
278
+ }
279
+ get statusCode() {
280
+ return this.options.statusCode;
281
+ }
282
+ get url() {
283
+ return this.options.url;
284
+ }
285
+ get method() {
286
+ return this.options.method;
287
+ }
288
+ get requestBody() {
289
+ return this.options.requestBody;
290
+ }
291
+ get responseBody() {
292
+ return this.options.responseBody;
293
+ }
294
+ get data() {
295
+ return this.options.data;
296
+ }
297
+ /**
298
+ * Check if error is an authentication error
299
+ */
300
+ get isAuthError() {
301
+ return this.statusCode === 401 || this.wpCode === "auth_failed" || this.wpCode === "token_expired" || this.wpCode === "invalid_auth_request";
302
+ }
303
+ /**
304
+ * Check if error is a not found error
305
+ */
306
+ get isNotFoundError() {
307
+ return this.statusCode === 404 || this.wpCode === "route_not_found" || this.wpCode === "post_not_found" || this.wpCode === "term_not_found" || this.wpCode === "user_not_found";
308
+ }
309
+ /**
310
+ * Get reportable data for error tracking/logging
311
+ * Includes HTTP context and WordPress-specific fields
312
+ */
313
+ getReportableData() {
314
+ return {
315
+ code: this.options.code,
316
+ operation: this.options.operation,
317
+ userMessage: this.options.userMessage,
318
+ retryable: this.options.retryable,
319
+ statusCode: this.options.statusCode,
320
+ url: this.options.url,
321
+ method: this.options.method,
322
+ wpCode: this.options.code,
323
+ originalCode: this.options.originalCode
324
+ };
325
+ }
326
+ };
327
+
328
+ // src/errors/classes/WordPressDataValidationError.ts
329
+ var WordPressDataValidationError = class _WordPressDataValidationError extends BaseError {
330
+ constructor(options) {
331
+ const fieldErrors = options.zodError ? _WordPressDataValidationError.extractFieldErrorsFromZod(options.zodError) : void 0;
332
+ super({
333
+ code: "validation_error",
334
+ message: options.message,
335
+ operation: options.operation,
336
+ userMessage: options.userMessage || "Received unexpected data from WordPress",
337
+ retryable: false,
338
+ cause: options.cause,
339
+ url: options.url,
340
+ zodError: options.zodError,
341
+ value: options.value,
342
+ fieldErrors
343
+ });
344
+ }
345
+ // Convenient getters for validation-specific fields (no duplication)
346
+ get url() {
347
+ return this.options.url;
348
+ }
349
+ get zodError() {
350
+ return this.options.zodError;
351
+ }
352
+ get invalidValue() {
353
+ return this.options.value;
354
+ }
355
+ get fieldErrors() {
356
+ return this.options.fieldErrors;
357
+ }
358
+ /**
359
+ * Get reportable data for error tracking/logging
360
+ * Includes validation-specific fields
361
+ */
362
+ getReportableData() {
363
+ return {
364
+ code: this.options.code,
365
+ operation: this.options.operation,
366
+ userMessage: this.options.userMessage,
367
+ retryable: false,
368
+ fieldErrors: this.options.fieldErrors,
369
+ url: this.options.url
370
+ };
371
+ }
372
+ /**
373
+ * Extract field errors from Zod error
374
+ */
375
+ static extractFieldErrorsFromZod(zodError) {
376
+ if (!zodError?.errors) {
377
+ return void 0;
378
+ }
379
+ const fieldErrors = {};
380
+ for (const issue of zodError.errors) {
381
+ const path = issue.path.join(".");
382
+ if (!fieldErrors[path]) {
383
+ fieldErrors[path] = [];
384
+ }
385
+ fieldErrors[path].push(issue.message);
386
+ }
387
+ return fieldErrors;
388
+ }
389
+ /**
390
+ * Get all error messages as a flat array
391
+ */
392
+ getMessages() {
393
+ if (!this.fieldErrors) {
394
+ return [this.message];
395
+ }
396
+ const messages = [];
397
+ for (const fieldMessages of Object.values(this.fieldErrors)) {
398
+ messages.push(...fieldMessages);
399
+ }
400
+ return messages;
401
+ }
402
+ /**
403
+ * Check if a specific field has errors
404
+ */
405
+ hasFieldError(field) {
406
+ return this.fieldErrors ? field in this.fieldErrors : false;
407
+ }
408
+ /**
409
+ * Get error messages for a specific field
410
+ */
411
+ getFieldError(field) {
412
+ return this.fieldErrors?.[field];
413
+ }
414
+ };
415
+
416
+ // src/http/handleApiResponse.ts
417
+ var handleApiResponse = (response, schema, options) => {
418
+ const validationMode = options?.validationMode ?? "strict";
419
+ if (validationMode === "warn") {
420
+ const result = schema.safeParse(response.data);
421
+ if (!result.success) {
422
+ const validationError = new WordPressDataValidationError({
423
+ message: `WordPress API response validation failed for ${response.config.url || "unknown endpoint"}`,
424
+ url: response.config.url,
425
+ zodError: result.error,
426
+ value: response.data,
427
+ userMessage: "Received unexpected data from WordPress"
428
+ });
429
+ options?.onValidationError?.(validationError);
430
+ options?.errorReporter?.(validationError);
431
+ console.warn("[wordpress-utils] Validation warning:", validationError.message);
432
+ return response.data;
433
+ }
434
+ return result.data;
435
+ }
436
+ try {
437
+ return schema.parse(response.data);
438
+ } catch (error2) {
439
+ if (error2 && typeof error2 === "object" && "issues" in error2) {
440
+ const validationError = new WordPressDataValidationError({
441
+ message: `WordPress API response validation failed for ${response.config.url || "unknown endpoint"}`,
442
+ url: response.config.url,
443
+ zodError: error2,
444
+ value: response.data,
445
+ userMessage: "Received unexpected data from WordPress"
446
+ });
447
+ options?.onValidationError?.(validationError);
448
+ options?.errorReporter?.(validationError);
449
+ throw validationError;
450
+ }
451
+ throw error2;
452
+ }
453
+ };
454
+ var isZodError = (error2) => {
455
+ return error2 instanceof Error && error2.name === "ZodError";
456
+ };
457
+
458
+ // src/utils/calculatePagination.ts
459
+ var calculatePagination = (input) => {
460
+ const { page, perPage, total, totalPages } = input;
461
+ const hasNextPage = page < totalPages;
462
+ const hasPrevPage = page > 1;
463
+ return {
464
+ page,
465
+ perPage,
466
+ total,
467
+ totalPages,
468
+ hasNextPage,
469
+ hasPrevPage,
470
+ nextPage: hasNextPage ? page + 1 : null,
471
+ prevPage: hasPrevPage ? page - 1 : null
472
+ };
473
+ };
474
+
475
+ // src/utils/getPaginationMeta.ts
476
+ var getPaginationMeta = (headers) => {
477
+ if (!headers) {
478
+ return {
479
+ total: 0,
480
+ totalPages: 0
481
+ };
482
+ }
483
+ const wpTotal = headers["x-wp-total"];
484
+ const wpTotalPages = headers["x-wp-totalpages"];
485
+ if (!wpTotal || !wpTotalPages) {
486
+ return {
487
+ total: 0,
488
+ totalPages: 0
489
+ };
490
+ }
491
+ const total = parseInt(wpTotal, 10);
492
+ const totalPages = parseInt(wpTotalPages, 10);
493
+ return {
494
+ total,
495
+ totalPages
496
+ };
497
+ };
498
+
499
+ // src/http/handlePaginatedApiResponse.ts
500
+ var handlePaginatedApiResponse = (response, schema, params = {}, options) => {
501
+ const validationMode = options?.validationMode ?? "strict";
502
+ let data;
503
+ if (validationMode === "warn") {
504
+ const result = schema.safeParse(response.data);
505
+ if (!result.success) {
506
+ const validationError = new WordPressDataValidationError({
507
+ message: `WordPress API response validation failed for ${response.config.url || "unknown endpoint"}`,
508
+ url: response.config.url,
509
+ zodError: result.error,
510
+ value: response.data,
511
+ userMessage: "Received unexpected data from WordPress"
512
+ });
513
+ options?.onValidationError?.(validationError);
514
+ options?.errorReporter?.(validationError);
515
+ console.warn("[wordpress-utils] Validation warning:", validationError.message);
516
+ data = Array.isArray(response.data) ? response.data : [];
517
+ } else {
518
+ data = result.data;
519
+ }
520
+ } else {
521
+ try {
522
+ data = schema.parse(response.data);
523
+ } catch (error2) {
524
+ if (error2 && typeof error2 === "object" && "issues" in error2) {
525
+ const validationError = new WordPressDataValidationError({
526
+ message: `WordPress API response validation failed for ${response.config.url || "unknown endpoint"}`,
527
+ url: response.config.url,
528
+ zodError: error2,
529
+ value: response.data,
530
+ userMessage: "Received unexpected data from WordPress"
531
+ });
532
+ options?.onValidationError?.(validationError);
533
+ options?.errorReporter?.(validationError);
534
+ throw validationError;
535
+ }
536
+ throw error2;
537
+ }
538
+ }
539
+ const { total, totalPages } = getPaginationMeta(response.headers);
540
+ const page = params.page || 1;
541
+ const perPage = params.per_page || 10;
542
+ const pagination = calculatePagination({
543
+ page,
544
+ perPage,
545
+ total,
546
+ totalPages
547
+ });
548
+ return {
549
+ data,
550
+ pagination
551
+ };
552
+ };
553
+
554
+ // src/logging/logger.ts
555
+ var DEBUG_PREFIX = "[wordpress-utils]";
556
+ var isDebugEnabled = () => {
557
+ if (typeof process !== "undefined" && process.env) {
558
+ return process.env.DEBUG === "true" || process.env.DEBUG === "1";
559
+ }
560
+ return false;
561
+ };
562
+ var debug = (...args) => {
563
+ if (isDebugEnabled()) {
564
+ console.log(DEBUG_PREFIX, ...args);
565
+ }
566
+ };
567
+ var error = (...args) => {
568
+ console.error(DEBUG_PREFIX, ...args);
569
+ };
570
+
571
+ // src/http/interceptors/request.ts
572
+ var setupRequestInterceptor = (axiosInstance, config, client) => {
573
+ axiosInstance.interceptors.request.use(
574
+ async (requestConfig) => {
575
+ if (config.jwtToken) {
576
+ const token = await config.jwtToken.get();
577
+ if (token) {
578
+ requestConfig.headers.Authorization = `Bearer ${token}`;
579
+ debug("JWT token injected");
580
+ }
581
+ }
582
+ if (config.onRequest) {
583
+ return config.onRequest(requestConfig, client);
584
+ }
585
+ return requestConfig;
586
+ },
587
+ (error2) => {
588
+ return Promise.reject(error2);
589
+ }
590
+ );
591
+ };
592
+
593
+ // src/http/interceptors/response.ts
594
+ var setupResponseInterceptor = (axiosInstance, config, client) => {
595
+ axiosInstance.interceptors.response.use(
596
+ async (response) => {
597
+ debug("Response:", response.config.url, response.status);
598
+ if (config.onResponse) {
599
+ return config.onResponse(response, client);
600
+ }
601
+ return response;
602
+ },
603
+ (error2) => {
604
+ return Promise.reject(error2);
605
+ }
606
+ );
607
+ };
608
+ var setupErrorInterceptor = (axiosInstance, config, client) => {
609
+ axiosInstance.interceptors.response.use(
610
+ (response) => response,
611
+ async (axiosError) => {
612
+ const status = axiosError.response?.status || 500;
613
+ const errorData = axiosError.response?.data;
614
+ const apiCode = errorData?.code || "unknown_error";
615
+ const wpMessage = errorData?.message || axiosError.message || "Unknown error";
616
+ const mappedError = mapWordPressCode(apiCode, status);
617
+ const wpError = new WordPressApiError({
618
+ message: wpMessage,
619
+ statusCode: status,
620
+ code: mappedError.code,
621
+ // Transformed app-level code
622
+ originalCode: apiCode,
623
+ // Original WordPress API code
624
+ retryable: mappedError.retryable,
625
+ userMessage: mappedError.userMessage,
626
+ operation: axiosError.config?.url || "wordpress_api_request",
627
+ url: axiosError.config?.url || "",
628
+ method: axiosError.config?.method?.toUpperCase() || "GET",
629
+ requestBody: axiosError.config?.data,
630
+ responseBody: errorData,
631
+ cause: axiosError
632
+ });
633
+ if (config.debug) {
634
+ debug("WordPress error:", apiCode, status, wpMessage);
635
+ error(wpError);
636
+ }
637
+ if ((status === 401 || status === 403) && config.onAuthError && isAxiosError(axiosError) && !axiosError.config?._retry) {
638
+ if (config.debug) {
639
+ debug("Auth error detected, calling onAuthError handler");
640
+ }
641
+ try {
642
+ const shouldRetry = await config.onAuthError(wpError, client);
643
+ if (shouldRetry) {
644
+ if (config.debug) {
645
+ debug("Retrying request after auth error");
646
+ }
647
+ axiosError.config._retry = true;
648
+ return axiosInstance.request(axiosError.config);
649
+ }
650
+ } catch (authErrorHandlerError) {
651
+ if (config.debug) {
652
+ debug("onAuthError handler threw error", authErrorHandlerError);
653
+ }
654
+ }
655
+ }
656
+ if (config.onError) {
657
+ config.onError(wpError, client);
658
+ }
659
+ config.errorReporter?.report(wpError);
660
+ return Promise.reject(wpError);
661
+ }
662
+ );
663
+ };
664
+
665
+ export { handleApiResponse, handlePaginatedApiResponse, isZodError, setupErrorInterceptor, setupRequestInterceptor, setupResponseInterceptor };
666
+ //# sourceMappingURL=index.js.map
667
+ //# sourceMappingURL=index.js.map