@szymonpiatek/nextwordpress 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.cjs +126 -0
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +125 -1
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +126 -0
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +5 -2
- package/dist/hooks/index.d.ts +5 -2
- package/dist/hooks/index.js +125 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +150 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -3
- package/dist/index.d.ts +34 -3
- package/dist/index.js +147 -9
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +150 -8
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +147 -9
- package/dist/server/index.js.map +1 -1
- package/dist/{types-CM3v08Fh.d.cts → types-DUmH-vcl.d.cts} +41 -1
- package/dist/{types-CM3v08Fh.d.ts → types-DUmH-vcl.d.ts} +41 -1
- package/package.json +1 -1
package/dist/server/index.cjs
CHANGED
|
@@ -35,6 +35,8 @@ var ErrorCode = {
|
|
|
35
35
|
WOO_REVIEW_NOT_FOUND: "WOO_REVIEW_NOT_FOUND",
|
|
36
36
|
WOO_WEBHOOK_NOT_FOUND: "WOO_WEBHOOK_NOT_FOUND",
|
|
37
37
|
WOO_SHIPPING_ZONE_NOT_FOUND: "WOO_SHIPPING_ZONE_NOT_FOUND",
|
|
38
|
+
WOO_WISHLIST_NOT_FOUND: "WOO_WISHLIST_NOT_FOUND",
|
|
39
|
+
WOO_WISHLIST_ITEM_NOT_FOUND: "WOO_WISHLIST_ITEM_NOT_FOUND",
|
|
38
40
|
// Auth
|
|
39
41
|
AUTH_JWT_FAILED: "AUTH_JWT_FAILED",
|
|
40
42
|
AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID",
|
|
@@ -69,6 +71,8 @@ var defaultMessages = {
|
|
|
69
71
|
WOO_REVIEW_NOT_FOUND: "Product review not found",
|
|
70
72
|
WOO_WEBHOOK_NOT_FOUND: "Webhook not found",
|
|
71
73
|
WOO_SHIPPING_ZONE_NOT_FOUND: "Shipping zone not found",
|
|
74
|
+
WOO_WISHLIST_NOT_FOUND: "Wishlist not found",
|
|
75
|
+
WOO_WISHLIST_ITEM_NOT_FOUND: "Wishlist item not found",
|
|
72
76
|
AUTH_JWT_FAILED: "JWT authentication failed",
|
|
73
77
|
AUTH_CREDENTIALS_INVALID: "Invalid credentials",
|
|
74
78
|
AUTH_TOKEN_INVALID: "JWT token is invalid or expired",
|
|
@@ -101,6 +105,8 @@ var defaultMessagesPl = {
|
|
|
101
105
|
WOO_REVIEW_NOT_FOUND: "Opinia o produkcie nie istnieje",
|
|
102
106
|
WOO_WEBHOOK_NOT_FOUND: "Webhook nie istnieje",
|
|
103
107
|
WOO_SHIPPING_ZONE_NOT_FOUND: "Strefa wysy\u0142ki nie istnieje",
|
|
108
|
+
WOO_WISHLIST_NOT_FOUND: "Lista \u017Cycze\u0144 nie istnieje",
|
|
109
|
+
WOO_WISHLIST_ITEM_NOT_FOUND: "Element listy \u017Cycze\u0144 nie istnieje",
|
|
104
110
|
AUTH_JWT_FAILED: "B\u0142\u0105d uwierzytelnienia JWT",
|
|
105
111
|
AUTH_CREDENTIALS_INVALID: "Nieprawid\u0142owe dane logowania",
|
|
106
112
|
AUTH_TOKEN_INVALID: "Token JWT jest nieprawid\u0142owy lub wygas\u0142",
|
|
@@ -805,6 +811,138 @@ function createWordPressClient(config) {
|
|
|
805
811
|
};
|
|
806
812
|
}
|
|
807
813
|
|
|
814
|
+
// src/integrations/restApi/woocommerce/wishlist/fetcher.ts
|
|
815
|
+
var USER_AGENT2 = "NextWordpress YITH Wishlist Client";
|
|
816
|
+
var DEFAULT_CACHE_TTL = 3600;
|
|
817
|
+
var YithWishlistError = class extends Error {
|
|
818
|
+
constructor(code, status, url, message, upstreamCode, upstreamMessage) {
|
|
819
|
+
super(message);
|
|
820
|
+
__publicField(this, "code", code);
|
|
821
|
+
__publicField(this, "status", status);
|
|
822
|
+
__publicField(this, "url", url);
|
|
823
|
+
__publicField(this, "upstreamCode", upstreamCode);
|
|
824
|
+
__publicField(this, "upstreamMessage", upstreamMessage);
|
|
825
|
+
this.name = "YithWishlistError";
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
function resolveYithErrorCode(status, upstreamCode) {
|
|
829
|
+
if (status === 401) return ErrorCode.WOO_UNAUTHORIZED;
|
|
830
|
+
if (status === 403) return ErrorCode.WOO_FORBIDDEN;
|
|
831
|
+
if (status === 404) {
|
|
832
|
+
if (upstreamCode === "yith_wcwl_wishlist_not_found") return ErrorCode.WOO_WISHLIST_NOT_FOUND;
|
|
833
|
+
if (upstreamCode === "yith_wcwl_wishlist_item_not_found")
|
|
834
|
+
return ErrorCode.WOO_WISHLIST_ITEM_NOT_FOUND;
|
|
835
|
+
return ErrorCode.WOO_NOT_FOUND;
|
|
836
|
+
}
|
|
837
|
+
return ErrorCode.WOO_REQUEST_FAILED;
|
|
838
|
+
}
|
|
839
|
+
function createYithWishlistFetcher(config) {
|
|
840
|
+
const cacheTTL = config.cacheTTL ?? DEFAULT_CACHE_TTL;
|
|
841
|
+
function buildUrl2(path) {
|
|
842
|
+
const base = typeof window !== "undefined" && config.clientURL ? config.clientURL : config.serverURL;
|
|
843
|
+
return `${base}${path}`;
|
|
844
|
+
}
|
|
845
|
+
function authHeaders() {
|
|
846
|
+
return {
|
|
847
|
+
"User-Agent": USER_AGENT2,
|
|
848
|
+
"Content-Type": "application/json",
|
|
849
|
+
Authorization: `Bearer ${config.token}`
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
async function throwYithError(response, url) {
|
|
853
|
+
const body = await response.json().catch(() => ({}));
|
|
854
|
+
const errorCode = resolveYithErrorCode(response.status, body.code);
|
|
855
|
+
throw new YithWishlistError(
|
|
856
|
+
errorCode,
|
|
857
|
+
response.status,
|
|
858
|
+
url,
|
|
859
|
+
resolveMessage(errorCode, config.errorMessages),
|
|
860
|
+
body.code,
|
|
861
|
+
body.message
|
|
862
|
+
);
|
|
863
|
+
}
|
|
864
|
+
async function yithFetch(path, tags = ["yith-wishlist"], options) {
|
|
865
|
+
const url = buildUrl2(path);
|
|
866
|
+
const isMutation = options?.method && options.method !== "GET";
|
|
867
|
+
const response = await fetch(url, {
|
|
868
|
+
...options,
|
|
869
|
+
headers: {
|
|
870
|
+
...authHeaders(),
|
|
871
|
+
...options?.headers
|
|
872
|
+
},
|
|
873
|
+
next: isMutation ? void 0 : { tags, revalidate: cacheTTL }
|
|
874
|
+
});
|
|
875
|
+
if (!response.ok) {
|
|
876
|
+
await throwYithError(response, url);
|
|
877
|
+
}
|
|
878
|
+
return response.json();
|
|
879
|
+
}
|
|
880
|
+
async function yithFetchGraceful(path, fallback, tags = ["yith-wishlist"]) {
|
|
881
|
+
try {
|
|
882
|
+
return await yithFetch(path, tags);
|
|
883
|
+
} catch (err) {
|
|
884
|
+
console.warn(`YITH Wishlist fetch failed for ${path}`, err);
|
|
885
|
+
return fallback;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
async function yithMutate(path, body, method = "POST") {
|
|
889
|
+
return yithFetch(path, ["yith-wishlist"], {
|
|
890
|
+
method,
|
|
891
|
+
body: JSON.stringify(body)
|
|
892
|
+
});
|
|
893
|
+
}
|
|
894
|
+
return { yithFetch, yithFetchGraceful, yithMutate };
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
// src/integrations/restApi/woocommerce/wishlist/queries.ts
|
|
898
|
+
var BASE = "/wp-json/yith/wishlist/v1/wishlists";
|
|
899
|
+
function createWishlistQueries(fetcher) {
|
|
900
|
+
const { yithFetch, yithFetchGraceful } = fetcher;
|
|
901
|
+
async function getWishlists() {
|
|
902
|
+
return yithFetchGraceful(BASE, [], ["yith-wishlist", "wishlists"]);
|
|
903
|
+
}
|
|
904
|
+
async function getWishlistByToken(token) {
|
|
905
|
+
return yithFetch(`${BASE}/${token}`, ["yith-wishlist", "wishlists", `wishlist-${token}`]);
|
|
906
|
+
}
|
|
907
|
+
return { getWishlists, getWishlistByToken };
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
// src/integrations/restApi/woocommerce/wishlist/mutations.ts
|
|
911
|
+
var BASE2 = "/wp-json/yith/wishlist/v1/wishlists";
|
|
912
|
+
function createWishlistMutations(fetcher) {
|
|
913
|
+
const { yithMutate } = fetcher;
|
|
914
|
+
async function createWishlist(input) {
|
|
915
|
+
return yithMutate(BASE2, input, "POST");
|
|
916
|
+
}
|
|
917
|
+
async function updateWishlist(token, input) {
|
|
918
|
+
return yithMutate(`${BASE2}/${token}`, input, "PATCH");
|
|
919
|
+
}
|
|
920
|
+
async function deleteWishlist(token) {
|
|
921
|
+
return yithMutate(
|
|
922
|
+
`${BASE2}/${token}`,
|
|
923
|
+
{},
|
|
924
|
+
"DELETE"
|
|
925
|
+
);
|
|
926
|
+
}
|
|
927
|
+
async function addProductToWishlist(token, input) {
|
|
928
|
+
return yithMutate(`${BASE2}/${token}/add-product`, input, "POST");
|
|
929
|
+
}
|
|
930
|
+
async function removeProductFromWishlist(token, productId) {
|
|
931
|
+
return yithMutate(
|
|
932
|
+
`${BASE2}/${token}/remove-product/${productId}`,
|
|
933
|
+
{},
|
|
934
|
+
"DELETE"
|
|
935
|
+
);
|
|
936
|
+
}
|
|
937
|
+
return {
|
|
938
|
+
createWishlist,
|
|
939
|
+
updateWishlist,
|
|
940
|
+
deleteWishlist,
|
|
941
|
+
addProductToWishlist,
|
|
942
|
+
removeProductFromWishlist
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
|
|
808
946
|
// src/integrations/restApi/woocommerce/omnibus/queries.ts
|
|
809
947
|
var META_KEY_LOWEST_PRICE = "wpo_lowest_price";
|
|
810
948
|
var META_KEY_PRICE_HISTORY = "_alg_wc_price_history";
|
|
@@ -871,8 +1009,8 @@ function resolveWooErrorCode(status, upstreamCode) {
|
|
|
871
1009
|
}
|
|
872
1010
|
|
|
873
1011
|
// src/integrations/restApi/woocommerce/client/fetcher.ts
|
|
874
|
-
var
|
|
875
|
-
var
|
|
1012
|
+
var USER_AGENT3 = "NextWordpress WooCommerce Client";
|
|
1013
|
+
var DEFAULT_CACHE_TTL2 = 3600;
|
|
876
1014
|
function toQueryString(params) {
|
|
877
1015
|
const pairs = [];
|
|
878
1016
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -882,7 +1020,7 @@ function toQueryString(params) {
|
|
|
882
1020
|
return pairs.join("&");
|
|
883
1021
|
}
|
|
884
1022
|
function createWooCommerceFetcher(config) {
|
|
885
|
-
const cacheTTL = config.cacheTTL ??
|
|
1023
|
+
const cacheTTL = config.cacheTTL ?? DEFAULT_CACHE_TTL2;
|
|
886
1024
|
function withAuth(query) {
|
|
887
1025
|
return { ...query, consumer_key: config.consumerKey, consumer_secret: config.consumerSecret };
|
|
888
1026
|
}
|
|
@@ -909,7 +1047,7 @@ function createWooCommerceFetcher(config) {
|
|
|
909
1047
|
const response = await fetch(url, {
|
|
910
1048
|
...options,
|
|
911
1049
|
headers: {
|
|
912
|
-
"User-Agent":
|
|
1050
|
+
"User-Agent": USER_AGENT3,
|
|
913
1051
|
"Content-Type": "application/json",
|
|
914
1052
|
...options?.headers
|
|
915
1053
|
},
|
|
@@ -931,7 +1069,7 @@ function createWooCommerceFetcher(config) {
|
|
|
931
1069
|
async function wcFetchPaginated(path, query, tags = ["woocommerce"]) {
|
|
932
1070
|
const url = buildUrl2(path, query);
|
|
933
1071
|
const response = await fetch(url, {
|
|
934
|
-
headers: { "User-Agent":
|
|
1072
|
+
headers: { "User-Agent": USER_AGENT3 },
|
|
935
1073
|
next: { tags, revalidate: cacheTTL }
|
|
936
1074
|
});
|
|
937
1075
|
if (!response.ok) {
|
|
@@ -2217,7 +2355,7 @@ var WPGraphQLError = class extends Error {
|
|
|
2217
2355
|
};
|
|
2218
2356
|
|
|
2219
2357
|
// src/integrations/wpGraphQL/client/fetcher.ts
|
|
2220
|
-
var
|
|
2358
|
+
var USER_AGENT4 = "NextWordpress WPGraphQL Client";
|
|
2221
2359
|
function createWPGraphQLFetcher(config) {
|
|
2222
2360
|
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
2223
2361
|
const cacheTTL = config.cacheTTL ?? 300;
|
|
@@ -2226,7 +2364,7 @@ function createWPGraphQLFetcher(config) {
|
|
|
2226
2364
|
method: "POST",
|
|
2227
2365
|
headers: {
|
|
2228
2366
|
"Content-Type": "application/json",
|
|
2229
|
-
"User-Agent":
|
|
2367
|
+
"User-Agent": USER_AGENT4
|
|
2230
2368
|
},
|
|
2231
2369
|
body: JSON.stringify({ query: document, variables }),
|
|
2232
2370
|
next: { tags, revalidate: cacheTTL }
|
|
@@ -2270,7 +2408,7 @@ function createWPGraphQLFetcher(config) {
|
|
|
2270
2408
|
async function gqlMutate(document, variables, authToken) {
|
|
2271
2409
|
const headers = {
|
|
2272
2410
|
"Content-Type": "application/json",
|
|
2273
|
-
"User-Agent":
|
|
2411
|
+
"User-Agent": USER_AGENT4
|
|
2274
2412
|
};
|
|
2275
2413
|
if (authToken) {
|
|
2276
2414
|
headers["Authorization"] = authToken;
|
|
@@ -4427,6 +4565,7 @@ exports.ErrorCode = ErrorCode;
|
|
|
4427
4565
|
exports.WPGraphQLError = WPGraphQLError;
|
|
4428
4566
|
exports.WooCommerceError = WooCommerceError;
|
|
4429
4567
|
exports.WordPressAPIError = WordPressAPIError;
|
|
4568
|
+
exports.YithWishlistError = YithWishlistError;
|
|
4430
4569
|
exports.authenticateJwt = authenticateJwt;
|
|
4431
4570
|
exports.buildACFFragment = buildACFFragment;
|
|
4432
4571
|
exports.buildPageWithACFQuery = buildPageWithACFQuery;
|
|
@@ -4454,10 +4593,13 @@ exports.createWPGraphQLMutationsClient = createWPGraphQLMutationsClient;
|
|
|
4454
4593
|
exports.createWPGraphQLWooCommerceClient = createWPGraphQLWooCommerceClient;
|
|
4455
4594
|
exports.createWPULikeClient = createWPULikeClient;
|
|
4456
4595
|
exports.createWPULikeQueries = createWPULikeQueries;
|
|
4596
|
+
exports.createWishlistMutations = createWishlistMutations;
|
|
4597
|
+
exports.createWishlistQueries = createWishlistQueries;
|
|
4457
4598
|
exports.createWooCommerceClient = createWooCommerceClient;
|
|
4458
4599
|
exports.createWooCommerceFetcher = createWooCommerceFetcher;
|
|
4459
4600
|
exports.createWordPressClient = createWordPressClient;
|
|
4460
4601
|
exports.createWordPressMutationsClient = createWordPressMutationsClient;
|
|
4602
|
+
exports.createYithWishlistFetcher = createYithWishlistFetcher;
|
|
4461
4603
|
exports.createYoastQueries = createYoastQueries;
|
|
4462
4604
|
exports.defaultMessages = defaultMessages;
|
|
4463
4605
|
exports.defaultMessagesPl = defaultMessagesPl;
|