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