@szymonpiatek/nextwordpress 0.0.6 → 0.0.8
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/hooks/index.cjs +170 -30
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +170 -30
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +934 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +577 -3
- package/dist/index.d.ts +577 -3
- package/dist/index.js +929 -32
- package/dist/index.js.map +1 -1
- package/dist/{types-soq-mA1E.d.cts → types-Dxb6tuW_.d.cts} +54 -4
- package/dist/{types-soq-mA1E.d.ts → types-Dxb6tuW_.d.ts} +54 -4
- package/package.json +15 -5
package/dist/index.cjs
CHANGED
|
@@ -9,10 +9,96 @@ function resolveBaseUrl(config) {
|
|
|
9
9
|
return typeof window === "undefined" ? config.serverURL : config.clientURL;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
// src/shared/errors/codes.ts
|
|
13
|
+
var ErrorCode = {
|
|
14
|
+
// WordPress REST API
|
|
15
|
+
WP_REQUEST_FAILED: "WP_REQUEST_FAILED",
|
|
16
|
+
WP_NOT_FOUND: "WP_NOT_FOUND",
|
|
17
|
+
WP_UNAUTHORIZED: "WP_UNAUTHORIZED",
|
|
18
|
+
WP_FORBIDDEN: "WP_FORBIDDEN",
|
|
19
|
+
// WPGraphQL
|
|
20
|
+
GQL_REQUEST_FAILED: "GQL_REQUEST_FAILED",
|
|
21
|
+
GQL_NO_DATA: "GQL_NO_DATA",
|
|
22
|
+
GQL_ERRORS_IN_RESPONSE: "GQL_ERRORS_IN_RESPONSE",
|
|
23
|
+
// WooCommerce — generic
|
|
24
|
+
WOO_REQUEST_FAILED: "WOO_REQUEST_FAILED",
|
|
25
|
+
WOO_NOT_FOUND: "WOO_NOT_FOUND",
|
|
26
|
+
WOO_UNAUTHORIZED: "WOO_UNAUTHORIZED",
|
|
27
|
+
WOO_FORBIDDEN: "WOO_FORBIDDEN",
|
|
28
|
+
// WooCommerce — resource-specific
|
|
29
|
+
WOO_COUPON_NOT_FOUND: "WOO_COUPON_NOT_FOUND",
|
|
30
|
+
WOO_PRODUCT_NOT_FOUND: "WOO_PRODUCT_NOT_FOUND",
|
|
31
|
+
WOO_ORDER_NOT_FOUND: "WOO_ORDER_NOT_FOUND",
|
|
32
|
+
WOO_CUSTOMER_NOT_FOUND: "WOO_CUSTOMER_NOT_FOUND",
|
|
33
|
+
WOO_CATEGORY_NOT_FOUND: "WOO_CATEGORY_NOT_FOUND",
|
|
34
|
+
WOO_TAG_NOT_FOUND: "WOO_TAG_NOT_FOUND",
|
|
35
|
+
WOO_REVIEW_NOT_FOUND: "WOO_REVIEW_NOT_FOUND",
|
|
36
|
+
WOO_WEBHOOK_NOT_FOUND: "WOO_WEBHOOK_NOT_FOUND",
|
|
37
|
+
WOO_SHIPPING_ZONE_NOT_FOUND: "WOO_SHIPPING_ZONE_NOT_FOUND",
|
|
38
|
+
// Auth
|
|
39
|
+
AUTH_JWT_FAILED: "AUTH_JWT_FAILED",
|
|
40
|
+
AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID",
|
|
41
|
+
AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID"
|
|
42
|
+
};
|
|
43
|
+
var defaultMessages = {
|
|
44
|
+
WP_REQUEST_FAILED: "WordPress API request failed",
|
|
45
|
+
WP_NOT_FOUND: "WordPress resource not found",
|
|
46
|
+
WP_UNAUTHORIZED: "WordPress authentication required",
|
|
47
|
+
WP_FORBIDDEN: "WordPress access denied",
|
|
48
|
+
GQL_REQUEST_FAILED: "WPGraphQL request failed",
|
|
49
|
+
GQL_NO_DATA: "No data returned from WPGraphQL",
|
|
50
|
+
GQL_ERRORS_IN_RESPONSE: "WPGraphQL returned errors",
|
|
51
|
+
WOO_REQUEST_FAILED: "WooCommerce API request failed",
|
|
52
|
+
WOO_NOT_FOUND: "WooCommerce resource not found",
|
|
53
|
+
WOO_UNAUTHORIZED: "WooCommerce authentication required",
|
|
54
|
+
WOO_FORBIDDEN: "WooCommerce access denied",
|
|
55
|
+
WOO_COUPON_NOT_FOUND: "Coupon not found",
|
|
56
|
+
WOO_PRODUCT_NOT_FOUND: "Product not found",
|
|
57
|
+
WOO_ORDER_NOT_FOUND: "Order not found",
|
|
58
|
+
WOO_CUSTOMER_NOT_FOUND: "Customer not found",
|
|
59
|
+
WOO_CATEGORY_NOT_FOUND: "Category not found",
|
|
60
|
+
WOO_TAG_NOT_FOUND: "Tag not found",
|
|
61
|
+
WOO_REVIEW_NOT_FOUND: "Product review not found",
|
|
62
|
+
WOO_WEBHOOK_NOT_FOUND: "Webhook not found",
|
|
63
|
+
WOO_SHIPPING_ZONE_NOT_FOUND: "Shipping zone not found",
|
|
64
|
+
AUTH_JWT_FAILED: "JWT authentication failed",
|
|
65
|
+
AUTH_CREDENTIALS_INVALID: "Invalid credentials",
|
|
66
|
+
AUTH_TOKEN_INVALID: "JWT token is invalid or expired"
|
|
67
|
+
};
|
|
68
|
+
var defaultMessagesPl = {
|
|
69
|
+
WP_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania do WordPress API",
|
|
70
|
+
WP_NOT_FOUND: "Zas\xF3b WordPress nie istnieje",
|
|
71
|
+
WP_UNAUTHORIZED: "Wymagane uwierzytelnienie WordPress",
|
|
72
|
+
WP_FORBIDDEN: "Brak dost\u0119pu do zasobu WordPress",
|
|
73
|
+
GQL_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania WPGraphQL",
|
|
74
|
+
GQL_NO_DATA: "WPGraphQL nie zwr\xF3ci\u0142o danych",
|
|
75
|
+
GQL_ERRORS_IN_RESPONSE: "WPGraphQL zwr\xF3ci\u0142o b\u0142\u0119dy",
|
|
76
|
+
WOO_REQUEST_FAILED: "B\u0142\u0105d \u017C\u0105dania do WooCommerce API",
|
|
77
|
+
WOO_NOT_FOUND: "Zas\xF3b WooCommerce nie istnieje",
|
|
78
|
+
WOO_UNAUTHORIZED: "Wymagane uwierzytelnienie WooCommerce",
|
|
79
|
+
WOO_FORBIDDEN: "Brak dost\u0119pu do zasobu WooCommerce",
|
|
80
|
+
WOO_COUPON_NOT_FOUND: "Kupon nie istnieje",
|
|
81
|
+
WOO_PRODUCT_NOT_FOUND: "Produkt nie istnieje",
|
|
82
|
+
WOO_ORDER_NOT_FOUND: "Zam\xF3wienie nie istnieje",
|
|
83
|
+
WOO_CUSTOMER_NOT_FOUND: "Klient nie istnieje",
|
|
84
|
+
WOO_CATEGORY_NOT_FOUND: "Kategoria produkt\xF3w nie istnieje",
|
|
85
|
+
WOO_TAG_NOT_FOUND: "Tag produkt\xF3w nie istnieje",
|
|
86
|
+
WOO_REVIEW_NOT_FOUND: "Opinia o produkcie nie istnieje",
|
|
87
|
+
WOO_WEBHOOK_NOT_FOUND: "Webhook nie istnieje",
|
|
88
|
+
WOO_SHIPPING_ZONE_NOT_FOUND: "Strefa wysy\u0142ki nie istnieje",
|
|
89
|
+
AUTH_JWT_FAILED: "B\u0142\u0105d uwierzytelnienia JWT",
|
|
90
|
+
AUTH_CREDENTIALS_INVALID: "Nieprawid\u0142owe dane logowania",
|
|
91
|
+
AUTH_TOKEN_INVALID: "Token JWT jest nieprawid\u0142owy lub wygas\u0142"
|
|
92
|
+
};
|
|
93
|
+
function resolveMessage(code, overrides) {
|
|
94
|
+
return overrides?.[code] ?? defaultMessages[code];
|
|
95
|
+
}
|
|
96
|
+
|
|
12
97
|
// src/integrations/restApi/core/client/types.ts
|
|
13
98
|
var WordPressAPIError = class extends Error {
|
|
14
|
-
constructor(
|
|
15
|
-
super(message);
|
|
99
|
+
constructor(code, status, endpoint, message, detail) {
|
|
100
|
+
super(detail ? `${message}: ${detail}` : message);
|
|
101
|
+
__publicField(this, "code", code);
|
|
16
102
|
__publicField(this, "status", status);
|
|
17
103
|
__publicField(this, "endpoint", endpoint);
|
|
18
104
|
this.name = "WordPressAPIError";
|
|
@@ -35,19 +121,28 @@ function buildUrl(config, path, query) {
|
|
|
35
121
|
|
|
36
122
|
// src/integrations/restApi/core/client/fetcher.ts
|
|
37
123
|
var USER_AGENT = "NextWordpress Client";
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
response.status,
|
|
44
|
-
url
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
return response;
|
|
124
|
+
function resolveWpErrorCode(status) {
|
|
125
|
+
if (status === 401) return ErrorCode.WP_UNAUTHORIZED;
|
|
126
|
+
if (status === 403) return ErrorCode.WP_FORBIDDEN;
|
|
127
|
+
if (status === 404) return ErrorCode.WP_NOT_FOUND;
|
|
128
|
+
return ErrorCode.WP_REQUEST_FAILED;
|
|
48
129
|
}
|
|
49
130
|
function createFetcher(config) {
|
|
50
131
|
const cacheTtl = config.cacheTTL ?? 300;
|
|
132
|
+
async function doFetch(url, init = {}) {
|
|
133
|
+
const response = await fetch(url, init);
|
|
134
|
+
if (!response.ok) {
|
|
135
|
+
const code = resolveWpErrorCode(response.status);
|
|
136
|
+
throw new WordPressAPIError(
|
|
137
|
+
code,
|
|
138
|
+
response.status,
|
|
139
|
+
url,
|
|
140
|
+
resolveMessage(code, config.errorMessages),
|
|
141
|
+
response.statusText
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
return response;
|
|
145
|
+
}
|
|
51
146
|
async function wpFetch(path, query, tags = ["wordpress"]) {
|
|
52
147
|
const url = buildUrl(config, path, query);
|
|
53
148
|
const res = await doFetch(url, {
|
|
@@ -710,6 +805,42 @@ function withOmnibusVariation(variation) {
|
|
|
710
805
|
};
|
|
711
806
|
}
|
|
712
807
|
|
|
808
|
+
// src/integrations/restApi/woocommerce/client/types.ts
|
|
809
|
+
var WooCommerceError = class extends Error {
|
|
810
|
+
constructor(code, status, endpoint, message, upstreamCode, detail) {
|
|
811
|
+
super(detail ? `${message}: ${detail}` : message);
|
|
812
|
+
__publicField(this, "code", code);
|
|
813
|
+
__publicField(this, "status", status);
|
|
814
|
+
__publicField(this, "endpoint", endpoint);
|
|
815
|
+
__publicField(this, "upstreamCode", upstreamCode);
|
|
816
|
+
this.name = "WooCommerceError";
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
// src/integrations/restApi/woocommerce/client/errorMap.ts
|
|
821
|
+
var upstreamToErrorCode = {
|
|
822
|
+
woocommerce_rest_coupon_invalid_id: ErrorCode.WOO_COUPON_NOT_FOUND,
|
|
823
|
+
woocommerce_rest_product_invalid_id: ErrorCode.WOO_PRODUCT_NOT_FOUND,
|
|
824
|
+
woocommerce_rest_order_invalid_id: ErrorCode.WOO_ORDER_NOT_FOUND,
|
|
825
|
+
woocommerce_rest_customer_invalid_id: ErrorCode.WOO_CUSTOMER_NOT_FOUND,
|
|
826
|
+
woocommerce_rest_term_invalid: ErrorCode.WOO_CATEGORY_NOT_FOUND,
|
|
827
|
+
woocommerce_rest_review_invalid_id: ErrorCode.WOO_REVIEW_NOT_FOUND,
|
|
828
|
+
woocommerce_rest_webhook_invalid_id: ErrorCode.WOO_WEBHOOK_NOT_FOUND,
|
|
829
|
+
woocommerce_rest_shipping_zone_invalid_id: ErrorCode.WOO_SHIPPING_ZONE_NOT_FOUND
|
|
830
|
+
};
|
|
831
|
+
function resolveWooErrorCode(status, upstreamCode) {
|
|
832
|
+
if (status === 401) return ErrorCode.WOO_UNAUTHORIZED;
|
|
833
|
+
if (status === 403) return ErrorCode.WOO_FORBIDDEN;
|
|
834
|
+
if (status === 404) {
|
|
835
|
+
if (upstreamCode) {
|
|
836
|
+
const mapped = upstreamToErrorCode[upstreamCode];
|
|
837
|
+
if (mapped) return mapped;
|
|
838
|
+
}
|
|
839
|
+
return ErrorCode.WOO_NOT_FOUND;
|
|
840
|
+
}
|
|
841
|
+
return ErrorCode.WOO_REQUEST_FAILED;
|
|
842
|
+
}
|
|
843
|
+
|
|
713
844
|
// src/integrations/restApi/woocommerce/client/fetcher.ts
|
|
714
845
|
var USER_AGENT2 = "NextWordpress WooCommerce Client";
|
|
715
846
|
var DEFAULT_CACHE_TTL = 3600;
|
|
@@ -727,7 +858,20 @@ function createWooCommerceFetcher(config) {
|
|
|
727
858
|
return { ...query, consumer_key: config.consumerKey, consumer_secret: config.consumerSecret };
|
|
728
859
|
}
|
|
729
860
|
function buildUrl2(path, query) {
|
|
730
|
-
|
|
861
|
+
const base = typeof window !== "undefined" && config.clientURL ? config.clientURL : config.serverURL;
|
|
862
|
+
return `${base}${path}?${toQueryString(withAuth(query))}`;
|
|
863
|
+
}
|
|
864
|
+
async function throwWooError(response, url) {
|
|
865
|
+
const body = await response.json().catch(() => ({}));
|
|
866
|
+
const errorCode = resolveWooErrorCode(response.status, body.code);
|
|
867
|
+
throw new WooCommerceError(
|
|
868
|
+
errorCode,
|
|
869
|
+
response.status,
|
|
870
|
+
url,
|
|
871
|
+
resolveMessage(errorCode, config.errorMessages),
|
|
872
|
+
body.code,
|
|
873
|
+
body.message
|
|
874
|
+
);
|
|
731
875
|
}
|
|
732
876
|
async function wcFetch(path, query, tags = ["woocommerce"], options) {
|
|
733
877
|
const url = buildUrl2(path, query);
|
|
@@ -743,9 +887,7 @@ function createWooCommerceFetcher(config) {
|
|
|
743
887
|
next: isMutation || noStore ? void 0 : { tags, revalidate: cacheTTL }
|
|
744
888
|
});
|
|
745
889
|
if (!response.ok) {
|
|
746
|
-
|
|
747
|
-
const detail = body.message ? ` \u2013 ${body.message}` : "";
|
|
748
|
-
throw new Error(`WooCommerce API ${response.status}: ${response.statusText}${detail} [${url}]`);
|
|
890
|
+
await throwWooError(response, url);
|
|
749
891
|
}
|
|
750
892
|
return response.json();
|
|
751
893
|
}
|
|
@@ -764,7 +906,7 @@ function createWooCommerceFetcher(config) {
|
|
|
764
906
|
next: { tags, revalidate: cacheTTL }
|
|
765
907
|
});
|
|
766
908
|
if (!response.ok) {
|
|
767
|
-
|
|
909
|
+
await throwWooError(response, url);
|
|
768
910
|
}
|
|
769
911
|
return {
|
|
770
912
|
data: await response.json(),
|
|
@@ -1211,6 +1353,725 @@ function createCustomersQueries(fetcher) {
|
|
|
1211
1353
|
};
|
|
1212
1354
|
}
|
|
1213
1355
|
|
|
1356
|
+
// src/integrations/restApi/woocommerce/payment_gateways/queries.ts
|
|
1357
|
+
function createPaymentGatewaysQueries(fetcher) {
|
|
1358
|
+
const { wcFetch, wcFetchGraceful } = fetcher;
|
|
1359
|
+
async function getPaymentGateways() {
|
|
1360
|
+
return wcFetchGraceful(
|
|
1361
|
+
"/wp-json/wc/v3/payment_gateways",
|
|
1362
|
+
[],
|
|
1363
|
+
void 0,
|
|
1364
|
+
["woocommerce", "payment_gateways"]
|
|
1365
|
+
);
|
|
1366
|
+
}
|
|
1367
|
+
async function getEnabledPaymentGateways() {
|
|
1368
|
+
const gateways = await wcFetchGraceful(
|
|
1369
|
+
"/wp-json/wc/v3/payment_gateways",
|
|
1370
|
+
[],
|
|
1371
|
+
void 0,
|
|
1372
|
+
["woocommerce", "payment_gateways"]
|
|
1373
|
+
);
|
|
1374
|
+
return gateways.filter((g) => g.enabled);
|
|
1375
|
+
}
|
|
1376
|
+
async function getPaymentGatewayById(id) {
|
|
1377
|
+
return wcFetch(
|
|
1378
|
+
`/wp-json/wc/v3/payment_gateways/${id}`,
|
|
1379
|
+
void 0,
|
|
1380
|
+
["woocommerce", "payment_gateways", `payment_gateway-${id}`]
|
|
1381
|
+
);
|
|
1382
|
+
}
|
|
1383
|
+
return {
|
|
1384
|
+
getPaymentGateways,
|
|
1385
|
+
getEnabledPaymentGateways,
|
|
1386
|
+
getPaymentGatewayById
|
|
1387
|
+
};
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
// src/integrations/restApi/woocommerce/order_notes/queries.ts
|
|
1391
|
+
function createOrderNotesQueries(fetcher) {
|
|
1392
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1393
|
+
async function getNotesByOrderId(orderId) {
|
|
1394
|
+
return wcFetchGraceful(
|
|
1395
|
+
`/wp-json/wc/v3/orders/${orderId}/notes`,
|
|
1396
|
+
[],
|
|
1397
|
+
void 0,
|
|
1398
|
+
["woocommerce", "order_notes", `order-${orderId}-notes`]
|
|
1399
|
+
);
|
|
1400
|
+
}
|
|
1401
|
+
async function getOrderNoteById(orderId, noteId) {
|
|
1402
|
+
return wcFetch(
|
|
1403
|
+
`/wp-json/wc/v3/orders/${orderId}/notes/${noteId}`,
|
|
1404
|
+
void 0,
|
|
1405
|
+
["woocommerce", "order_notes", `order-${orderId}-note-${noteId}`]
|
|
1406
|
+
);
|
|
1407
|
+
}
|
|
1408
|
+
async function createOrderNote(orderId, input) {
|
|
1409
|
+
return wcMutate(
|
|
1410
|
+
`/wp-json/wc/v3/orders/${orderId}/notes`,
|
|
1411
|
+
input,
|
|
1412
|
+
"POST"
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
async function deleteOrderNote(orderId, noteId, force = true) {
|
|
1416
|
+
return wcMutate(
|
|
1417
|
+
`/wp-json/wc/v3/orders/${orderId}/notes/${noteId}`,
|
|
1418
|
+
{ force },
|
|
1419
|
+
"DELETE"
|
|
1420
|
+
);
|
|
1421
|
+
}
|
|
1422
|
+
return {
|
|
1423
|
+
getNotesByOrderId,
|
|
1424
|
+
getOrderNoteById,
|
|
1425
|
+
createOrderNote,
|
|
1426
|
+
deleteOrderNote
|
|
1427
|
+
};
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
// src/integrations/restApi/woocommerce/order_refunds/queries.ts
|
|
1431
|
+
function createOrderRefundsQueries(fetcher) {
|
|
1432
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1433
|
+
async function getRefundsByOrderId(orderId) {
|
|
1434
|
+
return wcFetchGraceful(
|
|
1435
|
+
`/wp-json/wc/v3/orders/${orderId}/refunds`,
|
|
1436
|
+
[],
|
|
1437
|
+
void 0,
|
|
1438
|
+
["woocommerce", "order_refunds", `order-${orderId}-refunds`]
|
|
1439
|
+
);
|
|
1440
|
+
}
|
|
1441
|
+
async function getOrderRefundById(orderId, refundId) {
|
|
1442
|
+
return wcFetch(
|
|
1443
|
+
`/wp-json/wc/v3/orders/${orderId}/refunds/${refundId}`,
|
|
1444
|
+
void 0,
|
|
1445
|
+
["woocommerce", "order_refunds", `order-${orderId}-refund-${refundId}`]
|
|
1446
|
+
);
|
|
1447
|
+
}
|
|
1448
|
+
async function createOrderRefund(orderId, input) {
|
|
1449
|
+
return wcMutate(
|
|
1450
|
+
`/wp-json/wc/v3/orders/${orderId}/refunds`,
|
|
1451
|
+
input,
|
|
1452
|
+
"POST"
|
|
1453
|
+
);
|
|
1454
|
+
}
|
|
1455
|
+
async function deleteOrderRefund(orderId, refundId, force = true) {
|
|
1456
|
+
return wcMutate(
|
|
1457
|
+
`/wp-json/wc/v3/orders/${orderId}/refunds/${refundId}`,
|
|
1458
|
+
{ force },
|
|
1459
|
+
"DELETE"
|
|
1460
|
+
);
|
|
1461
|
+
}
|
|
1462
|
+
return {
|
|
1463
|
+
getRefundsByOrderId,
|
|
1464
|
+
getOrderRefundById,
|
|
1465
|
+
createOrderRefund,
|
|
1466
|
+
deleteOrderRefund
|
|
1467
|
+
};
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
// src/integrations/restApi/woocommerce/product_attributes/queries.ts
|
|
1471
|
+
function createProductAttributesQueries(fetcher) {
|
|
1472
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1473
|
+
async function getProductAttributes() {
|
|
1474
|
+
return wcFetchGraceful(
|
|
1475
|
+
"/wp-json/wc/v3/products/attributes",
|
|
1476
|
+
[],
|
|
1477
|
+
void 0,
|
|
1478
|
+
["woocommerce", "product_attributes"]
|
|
1479
|
+
);
|
|
1480
|
+
}
|
|
1481
|
+
async function getProductAttributeById(id) {
|
|
1482
|
+
return wcFetch(
|
|
1483
|
+
`/wp-json/wc/v3/products/attributes/${id}`,
|
|
1484
|
+
void 0,
|
|
1485
|
+
["woocommerce", "product_attributes", `attribute-${id}`]
|
|
1486
|
+
);
|
|
1487
|
+
}
|
|
1488
|
+
async function createProductAttribute(input) {
|
|
1489
|
+
return wcMutate("/wp-json/wc/v3/products/attributes", input, "POST");
|
|
1490
|
+
}
|
|
1491
|
+
async function updateProductAttribute(id, input) {
|
|
1492
|
+
return wcMutate(
|
|
1493
|
+
`/wp-json/wc/v3/products/attributes/${id}`,
|
|
1494
|
+
input,
|
|
1495
|
+
"PUT"
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1498
|
+
async function deleteProductAttribute(id, force = true) {
|
|
1499
|
+
return wcMutate(
|
|
1500
|
+
`/wp-json/wc/v3/products/attributes/${id}`,
|
|
1501
|
+
{ force },
|
|
1502
|
+
"DELETE"
|
|
1503
|
+
);
|
|
1504
|
+
}
|
|
1505
|
+
async function getAttributeTerms(attributeId) {
|
|
1506
|
+
return wcFetchGraceful(
|
|
1507
|
+
`/wp-json/wc/v3/products/attributes/${attributeId}/terms`,
|
|
1508
|
+
[],
|
|
1509
|
+
void 0,
|
|
1510
|
+
["woocommerce", "attribute_terms", `attribute-${attributeId}-terms`]
|
|
1511
|
+
);
|
|
1512
|
+
}
|
|
1513
|
+
async function getAttributeTermById(attributeId, termId) {
|
|
1514
|
+
return wcFetch(
|
|
1515
|
+
`/wp-json/wc/v3/products/attributes/${attributeId}/terms/${termId}`,
|
|
1516
|
+
void 0,
|
|
1517
|
+
["woocommerce", "attribute_terms", `attribute-${attributeId}-term-${termId}`]
|
|
1518
|
+
);
|
|
1519
|
+
}
|
|
1520
|
+
async function createAttributeTerm(attributeId, input) {
|
|
1521
|
+
return wcMutate(
|
|
1522
|
+
`/wp-json/wc/v3/products/attributes/${attributeId}/terms`,
|
|
1523
|
+
input,
|
|
1524
|
+
"POST"
|
|
1525
|
+
);
|
|
1526
|
+
}
|
|
1527
|
+
async function updateAttributeTerm(attributeId, termId, input) {
|
|
1528
|
+
return wcMutate(
|
|
1529
|
+
`/wp-json/wc/v3/products/attributes/${attributeId}/terms/${termId}`,
|
|
1530
|
+
input,
|
|
1531
|
+
"PUT"
|
|
1532
|
+
);
|
|
1533
|
+
}
|
|
1534
|
+
async function deleteAttributeTerm(attributeId, termId, force = true) {
|
|
1535
|
+
return wcMutate(
|
|
1536
|
+
`/wp-json/wc/v3/products/attributes/${attributeId}/terms/${termId}`,
|
|
1537
|
+
{ force },
|
|
1538
|
+
"DELETE"
|
|
1539
|
+
);
|
|
1540
|
+
}
|
|
1541
|
+
return {
|
|
1542
|
+
getProductAttributes,
|
|
1543
|
+
getProductAttributeById,
|
|
1544
|
+
createProductAttribute,
|
|
1545
|
+
updateProductAttribute,
|
|
1546
|
+
deleteProductAttribute,
|
|
1547
|
+
getAttributeTerms,
|
|
1548
|
+
getAttributeTermById,
|
|
1549
|
+
createAttributeTerm,
|
|
1550
|
+
updateAttributeTerm,
|
|
1551
|
+
deleteAttributeTerm
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
// src/integrations/restApi/woocommerce/product_reviews/queries.ts
|
|
1556
|
+
function createProductReviewsQueries(fetcher) {
|
|
1557
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1558
|
+
async function getProductReviews(params) {
|
|
1559
|
+
return wcFetchGraceful(
|
|
1560
|
+
"/wp-json/wc/v3/products/reviews",
|
|
1561
|
+
[],
|
|
1562
|
+
params,
|
|
1563
|
+
["woocommerce", "product_reviews"]
|
|
1564
|
+
);
|
|
1565
|
+
}
|
|
1566
|
+
async function getProductReviewsByProductId(productId) {
|
|
1567
|
+
return wcFetchGraceful(
|
|
1568
|
+
"/wp-json/wc/v3/products/reviews",
|
|
1569
|
+
[],
|
|
1570
|
+
{ product: [productId] },
|
|
1571
|
+
["woocommerce", "product_reviews", `reviews-product-${productId}`]
|
|
1572
|
+
);
|
|
1573
|
+
}
|
|
1574
|
+
async function getProductReviewById(id) {
|
|
1575
|
+
return wcFetch(
|
|
1576
|
+
`/wp-json/wc/v3/products/reviews/${id}`,
|
|
1577
|
+
void 0,
|
|
1578
|
+
["woocommerce", "product_reviews", `review-${id}`]
|
|
1579
|
+
);
|
|
1580
|
+
}
|
|
1581
|
+
async function createProductReview(input) {
|
|
1582
|
+
return wcMutate("/wp-json/wc/v3/products/reviews", input, "POST");
|
|
1583
|
+
}
|
|
1584
|
+
async function updateProductReview(id, input) {
|
|
1585
|
+
return wcMutate(`/wp-json/wc/v3/products/reviews/${id}`, input, "PUT");
|
|
1586
|
+
}
|
|
1587
|
+
async function deleteProductReview(id, force = true) {
|
|
1588
|
+
return wcMutate(
|
|
1589
|
+
`/wp-json/wc/v3/products/reviews/${id}`,
|
|
1590
|
+
{ force },
|
|
1591
|
+
"DELETE"
|
|
1592
|
+
);
|
|
1593
|
+
}
|
|
1594
|
+
return {
|
|
1595
|
+
getProductReviews,
|
|
1596
|
+
getProductReviewsByProductId,
|
|
1597
|
+
getProductReviewById,
|
|
1598
|
+
createProductReview,
|
|
1599
|
+
updateProductReview,
|
|
1600
|
+
deleteProductReview
|
|
1601
|
+
};
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
// src/integrations/restApi/woocommerce/shipping_classes/queries.ts
|
|
1605
|
+
function createShippingClassesQueries(fetcher) {
|
|
1606
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1607
|
+
async function getShippingClasses() {
|
|
1608
|
+
return wcFetchGraceful(
|
|
1609
|
+
"/wp-json/wc/v3/products/shipping_classes",
|
|
1610
|
+
[],
|
|
1611
|
+
void 0,
|
|
1612
|
+
["woocommerce", "shipping_classes"]
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
async function getShippingClassById(id) {
|
|
1616
|
+
return wcFetch(
|
|
1617
|
+
`/wp-json/wc/v3/products/shipping_classes/${id}`,
|
|
1618
|
+
void 0,
|
|
1619
|
+
["woocommerce", "shipping_classes", `shipping-class-${id}`]
|
|
1620
|
+
);
|
|
1621
|
+
}
|
|
1622
|
+
async function createShippingClass(input) {
|
|
1623
|
+
return wcMutate("/wp-json/wc/v3/products/shipping_classes", input, "POST");
|
|
1624
|
+
}
|
|
1625
|
+
async function updateShippingClass(id, input) {
|
|
1626
|
+
return wcMutate(
|
|
1627
|
+
`/wp-json/wc/v3/products/shipping_classes/${id}`,
|
|
1628
|
+
input,
|
|
1629
|
+
"PUT"
|
|
1630
|
+
);
|
|
1631
|
+
}
|
|
1632
|
+
async function deleteShippingClass(id, force = true) {
|
|
1633
|
+
return wcMutate(
|
|
1634
|
+
`/wp-json/wc/v3/products/shipping_classes/${id}`,
|
|
1635
|
+
{ force },
|
|
1636
|
+
"DELETE"
|
|
1637
|
+
);
|
|
1638
|
+
}
|
|
1639
|
+
return {
|
|
1640
|
+
getShippingClasses,
|
|
1641
|
+
getShippingClassById,
|
|
1642
|
+
createShippingClass,
|
|
1643
|
+
updateShippingClass,
|
|
1644
|
+
deleteShippingClass
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
// src/integrations/restApi/woocommerce/taxes/queries.ts
|
|
1649
|
+
function createTaxesQueries(fetcher) {
|
|
1650
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1651
|
+
async function getTaxRates(params) {
|
|
1652
|
+
return wcFetchGraceful(
|
|
1653
|
+
"/wp-json/wc/v3/taxes",
|
|
1654
|
+
[],
|
|
1655
|
+
params,
|
|
1656
|
+
["woocommerce", "tax_rates"]
|
|
1657
|
+
);
|
|
1658
|
+
}
|
|
1659
|
+
async function getTaxRateById(id) {
|
|
1660
|
+
return wcFetch(
|
|
1661
|
+
`/wp-json/wc/v3/taxes/${id}`,
|
|
1662
|
+
void 0,
|
|
1663
|
+
["woocommerce", "tax_rates", `tax-rate-${id}`]
|
|
1664
|
+
);
|
|
1665
|
+
}
|
|
1666
|
+
async function createTaxRate(input) {
|
|
1667
|
+
return wcMutate("/wp-json/wc/v3/taxes", input, "POST");
|
|
1668
|
+
}
|
|
1669
|
+
async function updateTaxRate(id, input) {
|
|
1670
|
+
return wcMutate(`/wp-json/wc/v3/taxes/${id}`, input, "PUT");
|
|
1671
|
+
}
|
|
1672
|
+
async function deleteTaxRate(id, force = true) {
|
|
1673
|
+
return wcMutate(
|
|
1674
|
+
`/wp-json/wc/v3/taxes/${id}`,
|
|
1675
|
+
{ force },
|
|
1676
|
+
"DELETE"
|
|
1677
|
+
);
|
|
1678
|
+
}
|
|
1679
|
+
async function getTaxClasses() {
|
|
1680
|
+
return wcFetchGraceful(
|
|
1681
|
+
"/wp-json/wc/v3/taxes/classes",
|
|
1682
|
+
[],
|
|
1683
|
+
void 0,
|
|
1684
|
+
["woocommerce", "tax_classes"]
|
|
1685
|
+
);
|
|
1686
|
+
}
|
|
1687
|
+
async function createTaxClass(input) {
|
|
1688
|
+
return wcMutate("/wp-json/wc/v3/taxes/classes", input, "POST");
|
|
1689
|
+
}
|
|
1690
|
+
async function deleteTaxClass(slug, force = true) {
|
|
1691
|
+
return wcMutate(
|
|
1692
|
+
`/wp-json/wc/v3/taxes/classes/${slug}`,
|
|
1693
|
+
{ force },
|
|
1694
|
+
"DELETE"
|
|
1695
|
+
);
|
|
1696
|
+
}
|
|
1697
|
+
return {
|
|
1698
|
+
getTaxRates,
|
|
1699
|
+
getTaxRateById,
|
|
1700
|
+
createTaxRate,
|
|
1701
|
+
updateTaxRate,
|
|
1702
|
+
deleteTaxRate,
|
|
1703
|
+
getTaxClasses,
|
|
1704
|
+
createTaxClass,
|
|
1705
|
+
deleteTaxClass
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
|
|
1709
|
+
// src/integrations/restApi/woocommerce/shipping/queries.ts
|
|
1710
|
+
function createShippingQueries(fetcher) {
|
|
1711
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1712
|
+
async function getShippingZones() {
|
|
1713
|
+
return wcFetchGraceful(
|
|
1714
|
+
"/wp-json/wc/v3/shipping/zones",
|
|
1715
|
+
[],
|
|
1716
|
+
void 0,
|
|
1717
|
+
["woocommerce", "shipping_zones"]
|
|
1718
|
+
);
|
|
1719
|
+
}
|
|
1720
|
+
async function getShippingZoneById(id) {
|
|
1721
|
+
return wcFetch(
|
|
1722
|
+
`/wp-json/wc/v3/shipping/zones/${id}`,
|
|
1723
|
+
void 0,
|
|
1724
|
+
["woocommerce", "shipping_zones", `zone-${id}`]
|
|
1725
|
+
);
|
|
1726
|
+
}
|
|
1727
|
+
async function createShippingZone(input) {
|
|
1728
|
+
return wcMutate("/wp-json/wc/v3/shipping/zones", input, "POST");
|
|
1729
|
+
}
|
|
1730
|
+
async function updateShippingZone(id, input) {
|
|
1731
|
+
return wcMutate(`/wp-json/wc/v3/shipping/zones/${id}`, input, "PUT");
|
|
1732
|
+
}
|
|
1733
|
+
async function deleteShippingZone(id, force = true) {
|
|
1734
|
+
return wcMutate(
|
|
1735
|
+
`/wp-json/wc/v3/shipping/zones/${id}`,
|
|
1736
|
+
{ force },
|
|
1737
|
+
"DELETE"
|
|
1738
|
+
);
|
|
1739
|
+
}
|
|
1740
|
+
async function getShippingZoneLocations(zoneId) {
|
|
1741
|
+
return wcFetchGraceful(
|
|
1742
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/locations`,
|
|
1743
|
+
[],
|
|
1744
|
+
void 0,
|
|
1745
|
+
["woocommerce", "shipping_zone_locations", `zone-${zoneId}-locations`]
|
|
1746
|
+
);
|
|
1747
|
+
}
|
|
1748
|
+
async function updateShippingZoneLocations(zoneId, locations) {
|
|
1749
|
+
return wcMutate(
|
|
1750
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/locations`,
|
|
1751
|
+
locations,
|
|
1752
|
+
"PUT"
|
|
1753
|
+
);
|
|
1754
|
+
}
|
|
1755
|
+
async function getShippingZoneMethods(zoneId) {
|
|
1756
|
+
return wcFetchGraceful(
|
|
1757
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/methods`,
|
|
1758
|
+
[],
|
|
1759
|
+
void 0,
|
|
1760
|
+
["woocommerce", "shipping_zone_methods", `zone-${zoneId}-methods`]
|
|
1761
|
+
);
|
|
1762
|
+
}
|
|
1763
|
+
async function getShippingZoneMethodById(zoneId, instanceId) {
|
|
1764
|
+
return wcFetch(
|
|
1765
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/methods/${instanceId}`,
|
|
1766
|
+
void 0,
|
|
1767
|
+
["woocommerce", "shipping_zone_methods", `zone-${zoneId}-method-${instanceId}`]
|
|
1768
|
+
);
|
|
1769
|
+
}
|
|
1770
|
+
async function createShippingZoneMethod(zoneId, input) {
|
|
1771
|
+
return wcMutate(
|
|
1772
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/methods`,
|
|
1773
|
+
input,
|
|
1774
|
+
"POST"
|
|
1775
|
+
);
|
|
1776
|
+
}
|
|
1777
|
+
async function updateShippingZoneMethod(zoneId, instanceId, input) {
|
|
1778
|
+
return wcMutate(
|
|
1779
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/methods/${instanceId}`,
|
|
1780
|
+
input,
|
|
1781
|
+
"PUT"
|
|
1782
|
+
);
|
|
1783
|
+
}
|
|
1784
|
+
async function deleteShippingZoneMethod(zoneId, instanceId, force = true) {
|
|
1785
|
+
return wcMutate(
|
|
1786
|
+
`/wp-json/wc/v3/shipping/zones/${zoneId}/methods/${instanceId}`,
|
|
1787
|
+
{ force },
|
|
1788
|
+
"DELETE"
|
|
1789
|
+
);
|
|
1790
|
+
}
|
|
1791
|
+
async function getShippingMethods() {
|
|
1792
|
+
return wcFetchGraceful(
|
|
1793
|
+
"/wp-json/wc/v3/shipping_methods",
|
|
1794
|
+
[],
|
|
1795
|
+
void 0,
|
|
1796
|
+
["woocommerce", "shipping_methods"]
|
|
1797
|
+
);
|
|
1798
|
+
}
|
|
1799
|
+
async function getShippingMethodById(id) {
|
|
1800
|
+
return wcFetch(
|
|
1801
|
+
`/wp-json/wc/v3/shipping_methods/${id}`,
|
|
1802
|
+
void 0,
|
|
1803
|
+
["woocommerce", "shipping_methods", `shipping-method-${id}`]
|
|
1804
|
+
);
|
|
1805
|
+
}
|
|
1806
|
+
return {
|
|
1807
|
+
getShippingZones,
|
|
1808
|
+
getShippingZoneById,
|
|
1809
|
+
createShippingZone,
|
|
1810
|
+
updateShippingZone,
|
|
1811
|
+
deleteShippingZone,
|
|
1812
|
+
getShippingZoneLocations,
|
|
1813
|
+
updateShippingZoneLocations,
|
|
1814
|
+
getShippingZoneMethods,
|
|
1815
|
+
getShippingZoneMethodById,
|
|
1816
|
+
createShippingZoneMethod,
|
|
1817
|
+
updateShippingZoneMethod,
|
|
1818
|
+
deleteShippingZoneMethod,
|
|
1819
|
+
getShippingMethods,
|
|
1820
|
+
getShippingMethodById
|
|
1821
|
+
};
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
// src/integrations/restApi/woocommerce/webhooks/queries.ts
|
|
1825
|
+
function createWebhooksQueries(fetcher) {
|
|
1826
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1827
|
+
async function getWebhooks(params) {
|
|
1828
|
+
return wcFetchGraceful(
|
|
1829
|
+
"/wp-json/wc/v3/webhooks",
|
|
1830
|
+
[],
|
|
1831
|
+
params,
|
|
1832
|
+
["woocommerce", "webhooks"]
|
|
1833
|
+
);
|
|
1834
|
+
}
|
|
1835
|
+
async function getWebhookById(id) {
|
|
1836
|
+
return wcFetch(
|
|
1837
|
+
`/wp-json/wc/v3/webhooks/${id}`,
|
|
1838
|
+
void 0,
|
|
1839
|
+
["woocommerce", "webhooks", `webhook-${id}`]
|
|
1840
|
+
);
|
|
1841
|
+
}
|
|
1842
|
+
async function createWebhook(input) {
|
|
1843
|
+
return wcMutate("/wp-json/wc/v3/webhooks", input, "POST");
|
|
1844
|
+
}
|
|
1845
|
+
async function updateWebhook(id, input) {
|
|
1846
|
+
return wcMutate(`/wp-json/wc/v3/webhooks/${id}`, input, "PUT");
|
|
1847
|
+
}
|
|
1848
|
+
async function deleteWebhook(id, force = true) {
|
|
1849
|
+
return wcMutate(
|
|
1850
|
+
`/wp-json/wc/v3/webhooks/${id}`,
|
|
1851
|
+
{ force },
|
|
1852
|
+
"DELETE"
|
|
1853
|
+
);
|
|
1854
|
+
}
|
|
1855
|
+
return {
|
|
1856
|
+
getWebhooks,
|
|
1857
|
+
getWebhookById,
|
|
1858
|
+
createWebhook,
|
|
1859
|
+
updateWebhook,
|
|
1860
|
+
deleteWebhook
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1863
|
+
|
|
1864
|
+
// src/integrations/restApi/woocommerce/settings/queries.ts
|
|
1865
|
+
function createSettingsQueries(fetcher) {
|
|
1866
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1867
|
+
async function getSettingGroups() {
|
|
1868
|
+
return wcFetchGraceful(
|
|
1869
|
+
"/wp-json/wc/v3/settings",
|
|
1870
|
+
[],
|
|
1871
|
+
void 0,
|
|
1872
|
+
["woocommerce", "settings"]
|
|
1873
|
+
);
|
|
1874
|
+
}
|
|
1875
|
+
async function getSettingOptions(groupId) {
|
|
1876
|
+
return wcFetchGraceful(
|
|
1877
|
+
`/wp-json/wc/v3/settings/${groupId}`,
|
|
1878
|
+
[],
|
|
1879
|
+
void 0,
|
|
1880
|
+
["woocommerce", "settings", `settings-${groupId}`]
|
|
1881
|
+
);
|
|
1882
|
+
}
|
|
1883
|
+
async function getSettingOption(groupId, optionId) {
|
|
1884
|
+
return wcFetch(
|
|
1885
|
+
`/wp-json/wc/v3/settings/${groupId}/${optionId}`,
|
|
1886
|
+
void 0,
|
|
1887
|
+
["woocommerce", "settings", `settings-${groupId}-${optionId}`]
|
|
1888
|
+
);
|
|
1889
|
+
}
|
|
1890
|
+
async function updateSettingOption(groupId, optionId, value) {
|
|
1891
|
+
return wcMutate(
|
|
1892
|
+
`/wp-json/wc/v3/settings/${groupId}/${optionId}`,
|
|
1893
|
+
{ value },
|
|
1894
|
+
"PUT"
|
|
1895
|
+
);
|
|
1896
|
+
}
|
|
1897
|
+
return {
|
|
1898
|
+
getSettingGroups,
|
|
1899
|
+
getSettingOptions,
|
|
1900
|
+
getSettingOption,
|
|
1901
|
+
updateSettingOption
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
// src/integrations/restApi/woocommerce/reports/queries.ts
|
|
1906
|
+
function createReportsQueries(fetcher) {
|
|
1907
|
+
const { wcFetchGraceful } = fetcher;
|
|
1908
|
+
async function getSalesReport(params) {
|
|
1909
|
+
return wcFetchGraceful(
|
|
1910
|
+
"/wp-json/wc/v3/reports/sales",
|
|
1911
|
+
[],
|
|
1912
|
+
params,
|
|
1913
|
+
["woocommerce", "reports", "sales"]
|
|
1914
|
+
);
|
|
1915
|
+
}
|
|
1916
|
+
async function getTopSellers(params) {
|
|
1917
|
+
return wcFetchGraceful(
|
|
1918
|
+
"/wp-json/wc/v3/reports/top_sellers",
|
|
1919
|
+
[],
|
|
1920
|
+
params,
|
|
1921
|
+
["woocommerce", "reports", "top_sellers"]
|
|
1922
|
+
);
|
|
1923
|
+
}
|
|
1924
|
+
async function getOrdersTotals() {
|
|
1925
|
+
return wcFetchGraceful(
|
|
1926
|
+
"/wp-json/wc/v3/reports/orders/totals",
|
|
1927
|
+
[],
|
|
1928
|
+
void 0,
|
|
1929
|
+
["woocommerce", "reports", "orders_totals"]
|
|
1930
|
+
);
|
|
1931
|
+
}
|
|
1932
|
+
async function getProductsTotals() {
|
|
1933
|
+
return wcFetchGraceful(
|
|
1934
|
+
"/wp-json/wc/v3/reports/products/totals",
|
|
1935
|
+
[],
|
|
1936
|
+
void 0,
|
|
1937
|
+
["woocommerce", "reports", "products_totals"]
|
|
1938
|
+
);
|
|
1939
|
+
}
|
|
1940
|
+
async function getCustomersTotals() {
|
|
1941
|
+
return wcFetchGraceful(
|
|
1942
|
+
"/wp-json/wc/v3/reports/customers/totals",
|
|
1943
|
+
[],
|
|
1944
|
+
void 0,
|
|
1945
|
+
["woocommerce", "reports", "customers_totals"]
|
|
1946
|
+
);
|
|
1947
|
+
}
|
|
1948
|
+
async function getCouponsTotals() {
|
|
1949
|
+
return wcFetchGraceful(
|
|
1950
|
+
"/wp-json/wc/v3/reports/coupons/totals",
|
|
1951
|
+
[],
|
|
1952
|
+
void 0,
|
|
1953
|
+
["woocommerce", "reports", "coupons_totals"]
|
|
1954
|
+
);
|
|
1955
|
+
}
|
|
1956
|
+
async function getReviewsTotals() {
|
|
1957
|
+
return wcFetchGraceful(
|
|
1958
|
+
"/wp-json/wc/v3/reports/reviews/totals",
|
|
1959
|
+
[],
|
|
1960
|
+
void 0,
|
|
1961
|
+
["woocommerce", "reports", "reviews_totals"]
|
|
1962
|
+
);
|
|
1963
|
+
}
|
|
1964
|
+
return {
|
|
1965
|
+
getSalesReport,
|
|
1966
|
+
getTopSellers,
|
|
1967
|
+
getOrdersTotals,
|
|
1968
|
+
getProductsTotals,
|
|
1969
|
+
getCustomersTotals,
|
|
1970
|
+
getCouponsTotals,
|
|
1971
|
+
getReviewsTotals
|
|
1972
|
+
};
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1975
|
+
// src/integrations/restApi/woocommerce/data/queries.ts
|
|
1976
|
+
function createDataQueries(fetcher) {
|
|
1977
|
+
const { wcFetch, wcFetchGraceful, wcMutate } = fetcher;
|
|
1978
|
+
async function getCurrencies() {
|
|
1979
|
+
return wcFetchGraceful(
|
|
1980
|
+
"/wp-json/wc/v3/data/currencies",
|
|
1981
|
+
[],
|
|
1982
|
+
void 0,
|
|
1983
|
+
["woocommerce", "data", "currencies"]
|
|
1984
|
+
);
|
|
1985
|
+
}
|
|
1986
|
+
async function getCurrentCurrency() {
|
|
1987
|
+
return wcFetch(
|
|
1988
|
+
"/wp-json/wc/v3/data/currencies/current",
|
|
1989
|
+
void 0,
|
|
1990
|
+
["woocommerce", "data", "currency_current"]
|
|
1991
|
+
);
|
|
1992
|
+
}
|
|
1993
|
+
async function getCurrencyByCode(code) {
|
|
1994
|
+
return wcFetch(
|
|
1995
|
+
`/wp-json/wc/v3/data/currencies/${code.toUpperCase()}`,
|
|
1996
|
+
void 0,
|
|
1997
|
+
["woocommerce", "data", `currency-${code}`]
|
|
1998
|
+
);
|
|
1999
|
+
}
|
|
2000
|
+
async function getContinents() {
|
|
2001
|
+
return wcFetchGraceful(
|
|
2002
|
+
"/wp-json/wc/v3/data/continents",
|
|
2003
|
+
[],
|
|
2004
|
+
void 0,
|
|
2005
|
+
["woocommerce", "data", "continents"]
|
|
2006
|
+
);
|
|
2007
|
+
}
|
|
2008
|
+
async function getContinentByCode(code) {
|
|
2009
|
+
return wcFetch(
|
|
2010
|
+
`/wp-json/wc/v3/data/continents/${code.toUpperCase()}`,
|
|
2011
|
+
void 0,
|
|
2012
|
+
["woocommerce", "data", `continent-${code}`]
|
|
2013
|
+
);
|
|
2014
|
+
}
|
|
2015
|
+
async function getCountries() {
|
|
2016
|
+
return wcFetchGraceful(
|
|
2017
|
+
"/wp-json/wc/v3/data/countries",
|
|
2018
|
+
[],
|
|
2019
|
+
void 0,
|
|
2020
|
+
["woocommerce", "data", "countries"]
|
|
2021
|
+
);
|
|
2022
|
+
}
|
|
2023
|
+
async function getCountryByCode(code) {
|
|
2024
|
+
return wcFetch(
|
|
2025
|
+
`/wp-json/wc/v3/data/countries/${code.toUpperCase()}`,
|
|
2026
|
+
void 0,
|
|
2027
|
+
["woocommerce", "data", `country-${code}`]
|
|
2028
|
+
);
|
|
2029
|
+
}
|
|
2030
|
+
async function getTimeZones() {
|
|
2031
|
+
return wcFetchGraceful(
|
|
2032
|
+
"/wp-json/wc/v3/data/time_zones",
|
|
2033
|
+
{},
|
|
2034
|
+
void 0,
|
|
2035
|
+
["woocommerce", "data", "time_zones"]
|
|
2036
|
+
);
|
|
2037
|
+
}
|
|
2038
|
+
async function getSystemStatus() {
|
|
2039
|
+
return wcFetch(
|
|
2040
|
+
"/wp-json/wc/v3/system_status",
|
|
2041
|
+
void 0,
|
|
2042
|
+
["woocommerce", "system_status"]
|
|
2043
|
+
);
|
|
2044
|
+
}
|
|
2045
|
+
async function getSystemStatusTools() {
|
|
2046
|
+
return wcFetchGraceful(
|
|
2047
|
+
"/wp-json/wc/v3/system_status/tools",
|
|
2048
|
+
[],
|
|
2049
|
+
void 0,
|
|
2050
|
+
["woocommerce", "system_status_tools"]
|
|
2051
|
+
);
|
|
2052
|
+
}
|
|
2053
|
+
async function runSystemStatusTool(toolId) {
|
|
2054
|
+
return wcMutate(
|
|
2055
|
+
`/wp-json/wc/v3/system_status/tools/${toolId}`,
|
|
2056
|
+
{},
|
|
2057
|
+
"PUT"
|
|
2058
|
+
);
|
|
2059
|
+
}
|
|
2060
|
+
return {
|
|
2061
|
+
getCurrencies,
|
|
2062
|
+
getCurrentCurrency,
|
|
2063
|
+
getCurrencyByCode,
|
|
2064
|
+
getContinents,
|
|
2065
|
+
getContinentByCode,
|
|
2066
|
+
getCountries,
|
|
2067
|
+
getCountryByCode,
|
|
2068
|
+
getTimeZones,
|
|
2069
|
+
getSystemStatus,
|
|
2070
|
+
getSystemStatusTools,
|
|
2071
|
+
runSystemStatusTool
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
|
|
1214
2075
|
// src/integrations/restApi/woocommerce/index.ts
|
|
1215
2076
|
function createWooCommerceClient(config) {
|
|
1216
2077
|
const fetcher = createWooCommerceFetcher(config);
|
|
@@ -1222,16 +2083,29 @@ function createWooCommerceClient(config) {
|
|
|
1222
2083
|
...createTagsQueries2(fetcher),
|
|
1223
2084
|
...createTagsMutations2(fetcher),
|
|
1224
2085
|
...createOrdersQueries(fetcher),
|
|
2086
|
+
...createOrderNotesQueries(fetcher),
|
|
2087
|
+
...createOrderRefundsQueries(fetcher),
|
|
2088
|
+
...createProductAttributesQueries(fetcher),
|
|
2089
|
+
...createProductReviewsQueries(fetcher),
|
|
2090
|
+
...createShippingClassesQueries(fetcher),
|
|
2091
|
+
...createTaxesQueries(fetcher),
|
|
2092
|
+
...createShippingQueries(fetcher),
|
|
2093
|
+
...createWebhooksQueries(fetcher),
|
|
2094
|
+
...createSettingsQueries(fetcher),
|
|
2095
|
+
...createReportsQueries(fetcher),
|
|
2096
|
+
...createDataQueries(fetcher),
|
|
1225
2097
|
...createCouponsQueries(fetcher),
|
|
1226
2098
|
...createCouponsMutations(fetcher),
|
|
1227
|
-
...createCustomersQueries(fetcher)
|
|
2099
|
+
...createCustomersQueries(fetcher),
|
|
2100
|
+
...createPaymentGatewaysQueries(fetcher)
|
|
1228
2101
|
};
|
|
1229
2102
|
}
|
|
1230
2103
|
|
|
1231
2104
|
// src/integrations/wpGraphQL/client/types.ts
|
|
1232
2105
|
var WPGraphQLError = class extends Error {
|
|
1233
|
-
constructor(
|
|
2106
|
+
constructor(code, status, endpoint, message, gqlErrors) {
|
|
1234
2107
|
super(message);
|
|
2108
|
+
__publicField(this, "code", code);
|
|
1235
2109
|
__publicField(this, "status", status);
|
|
1236
2110
|
__publicField(this, "endpoint", endpoint);
|
|
1237
2111
|
__publicField(this, "gqlErrors", gqlErrors);
|
|
@@ -1256,22 +2130,29 @@ function createWPGraphQLFetcher(config) {
|
|
|
1256
2130
|
});
|
|
1257
2131
|
if (!response.ok) {
|
|
1258
2132
|
throw new WPGraphQLError(
|
|
1259
|
-
|
|
2133
|
+
ErrorCode.GQL_REQUEST_FAILED,
|
|
1260
2134
|
response.status,
|
|
1261
|
-
url
|
|
2135
|
+
url,
|
|
2136
|
+
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
1262
2137
|
);
|
|
1263
2138
|
}
|
|
1264
2139
|
const parsed = await response.json();
|
|
1265
2140
|
if (parsed.errors && parsed.errors.length > 0) {
|
|
1266
2141
|
throw new WPGraphQLError(
|
|
1267
|
-
|
|
2142
|
+
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
1268
2143
|
200,
|
|
1269
2144
|
url,
|
|
2145
|
+
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
1270
2146
|
parsed.errors
|
|
1271
2147
|
);
|
|
1272
2148
|
}
|
|
1273
2149
|
if (parsed.data === void 0) {
|
|
1274
|
-
throw new WPGraphQLError(
|
|
2150
|
+
throw new WPGraphQLError(
|
|
2151
|
+
ErrorCode.GQL_NO_DATA,
|
|
2152
|
+
200,
|
|
2153
|
+
url,
|
|
2154
|
+
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
2155
|
+
);
|
|
1275
2156
|
}
|
|
1276
2157
|
return parsed.data;
|
|
1277
2158
|
}
|
|
@@ -1299,22 +2180,29 @@ function createWPGraphQLFetcher(config) {
|
|
|
1299
2180
|
});
|
|
1300
2181
|
if (!response.ok) {
|
|
1301
2182
|
throw new WPGraphQLError(
|
|
1302
|
-
|
|
2183
|
+
ErrorCode.GQL_REQUEST_FAILED,
|
|
1303
2184
|
response.status,
|
|
1304
|
-
url
|
|
2185
|
+
url,
|
|
2186
|
+
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
1305
2187
|
);
|
|
1306
2188
|
}
|
|
1307
2189
|
const parsed = await response.json();
|
|
1308
2190
|
if (parsed.errors && parsed.errors.length > 0) {
|
|
1309
2191
|
throw new WPGraphQLError(
|
|
1310
|
-
|
|
2192
|
+
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
1311
2193
|
200,
|
|
1312
2194
|
url,
|
|
2195
|
+
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
1313
2196
|
parsed.errors
|
|
1314
2197
|
);
|
|
1315
2198
|
}
|
|
1316
2199
|
if (parsed.data === void 0) {
|
|
1317
|
-
throw new WPGraphQLError(
|
|
2200
|
+
throw new WPGraphQLError(
|
|
2201
|
+
ErrorCode.GQL_NO_DATA,
|
|
2202
|
+
200,
|
|
2203
|
+
url,
|
|
2204
|
+
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
2205
|
+
);
|
|
1318
2206
|
}
|
|
1319
2207
|
return parsed.data;
|
|
1320
2208
|
}
|
|
@@ -3297,14 +4185,20 @@ function createApplicationPasswordToken(username, appPassword) {
|
|
|
3297
4185
|
|
|
3298
4186
|
// src/auth/types.ts
|
|
3299
4187
|
var AuthenticationError = class extends Error {
|
|
3300
|
-
constructor(message,
|
|
3301
|
-
super(message);
|
|
4188
|
+
constructor(code, status, message, detail) {
|
|
4189
|
+
super(detail ? `${message}: ${detail}` : message);
|
|
4190
|
+
__publicField(this, "code", code);
|
|
3302
4191
|
__publicField(this, "status", status);
|
|
3303
4192
|
this.name = "AuthenticationError";
|
|
3304
4193
|
}
|
|
3305
4194
|
};
|
|
3306
4195
|
|
|
3307
4196
|
// src/auth/jwt.ts
|
|
4197
|
+
function resolveAuthErrorCode(status) {
|
|
4198
|
+
if (status === 401) return ErrorCode.AUTH_CREDENTIALS_INVALID;
|
|
4199
|
+
if (status === 403) return ErrorCode.AUTH_TOKEN_INVALID;
|
|
4200
|
+
return ErrorCode.AUTH_JWT_FAILED;
|
|
4201
|
+
}
|
|
3308
4202
|
async function authenticateJwt(config, credentials) {
|
|
3309
4203
|
const url = `${resolveBaseUrl(config)}/wp-json/jwt-auth/v1/token`;
|
|
3310
4204
|
const response = await fetch(url, {
|
|
@@ -3314,9 +4208,12 @@ async function authenticateJwt(config, credentials) {
|
|
|
3314
4208
|
cache: "no-store"
|
|
3315
4209
|
});
|
|
3316
4210
|
if (!response.ok) {
|
|
4211
|
+
const code = resolveAuthErrorCode(response.status);
|
|
3317
4212
|
throw new AuthenticationError(
|
|
3318
|
-
|
|
3319
|
-
response.status
|
|
4213
|
+
code,
|
|
4214
|
+
response.status,
|
|
4215
|
+
resolveMessage(code, config.errorMessages),
|
|
4216
|
+
response.statusText
|
|
3320
4217
|
);
|
|
3321
4218
|
}
|
|
3322
4219
|
return response.json();
|
|
@@ -3332,7 +4229,10 @@ async function validateJwtToken(config, token) {
|
|
|
3332
4229
|
}
|
|
3333
4230
|
|
|
3334
4231
|
exports.AuthenticationError = AuthenticationError;
|
|
4232
|
+
exports.ErrorCode = ErrorCode;
|
|
3335
4233
|
exports.WPGraphQLError = WPGraphQLError;
|
|
4234
|
+
exports.WooCommerceError = WooCommerceError;
|
|
4235
|
+
exports.WordPressAPIError = WordPressAPIError;
|
|
3336
4236
|
exports.authenticateJwt = authenticateJwt;
|
|
3337
4237
|
exports.buildACFFragment = buildACFFragment;
|
|
3338
4238
|
exports.buildPageWithACFQuery = buildPageWithACFQuery;
|
|
@@ -3362,8 +4262,11 @@ exports.createWooCommerceFetcher = createWooCommerceFetcher;
|
|
|
3362
4262
|
exports.createWordPressClient = createWordPressClient;
|
|
3363
4263
|
exports.createWordPressMutationsClient = createWordPressMutationsClient;
|
|
3364
4264
|
exports.createYoastQueries = createYoastQueries;
|
|
4265
|
+
exports.defaultMessages = defaultMessages;
|
|
4266
|
+
exports.defaultMessagesPl = defaultMessagesPl;
|
|
3365
4267
|
exports.extractOmnibusData = extractOmnibusData;
|
|
3366
4268
|
exports.resolveBaseUrl = resolveBaseUrl;
|
|
4269
|
+
exports.resolveMessage = resolveMessage;
|
|
3367
4270
|
exports.validateJwtToken = validateJwtToken;
|
|
3368
4271
|
exports.withOmnibus = withOmnibus;
|
|
3369
4272
|
exports.withOmnibusVariation = withOmnibusVariation;
|