@szymonpiatek/nextwordpress 0.0.17 → 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 +210 -38
- 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 +207 -39
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +210 -38
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +19 -4
- package/dist/hooks/index.d.ts +19 -4
- package/dist/hooks/index.js +207 -39
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +174 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -12
- package/dist/index.d.ts +45 -12
- package/dist/index.js +171 -12
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +174 -11
- 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 +171 -12
- package/dist/server/index.js.map +1 -1
- package/dist/{types-DVzJO3P-.d.cts → types-DUmH-vcl.d.cts} +71 -16
- package/dist/{types-DVzJO3P-.d.ts → types-DUmH-vcl.d.ts} +71 -16
- package/package.json +1 -1
package/dist/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",
|
|
@@ -309,6 +315,26 @@ function createMediaMutations(fetcher) {
|
|
|
309
315
|
return { uploadMedia, updateMedia, deleteMedia };
|
|
310
316
|
}
|
|
311
317
|
|
|
318
|
+
// src/integrations/restApi/core/mutations/passwordReset/mutations.ts
|
|
319
|
+
function createPasswordResetMutations(fetcher) {
|
|
320
|
+
const { wpMutate } = fetcher;
|
|
321
|
+
async function sendPasswordResetEmail(input) {
|
|
322
|
+
return wpMutate(
|
|
323
|
+
"/wp-json/wp/v2/users/lost-password",
|
|
324
|
+
input,
|
|
325
|
+
"POST"
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
async function resetUserPassword(input) {
|
|
329
|
+
return wpMutate(
|
|
330
|
+
"/wp-json/wp/v2/users/reset-password",
|
|
331
|
+
input,
|
|
332
|
+
"POST"
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
return { sendPasswordResetEmail, resetUserPassword };
|
|
336
|
+
}
|
|
337
|
+
|
|
312
338
|
// src/integrations/restApi/core/client/types.ts
|
|
313
339
|
var WordPressAPIError = class extends Error {
|
|
314
340
|
constructor(code, status, endpoint, message, detail) {
|
|
@@ -443,7 +469,8 @@ function createWordPressMutationsClient(config) {
|
|
|
443
469
|
...createTagsMutations(fetcher),
|
|
444
470
|
...createAuthorsMutations(fetcher),
|
|
445
471
|
...createMenusMutations(fetcher),
|
|
446
|
-
...createMediaMutations(fetcher)
|
|
472
|
+
...createMediaMutations(fetcher),
|
|
473
|
+
...createPasswordResetMutations(fetcher)
|
|
447
474
|
};
|
|
448
475
|
}
|
|
449
476
|
|
|
@@ -784,6 +811,138 @@ function createWordPressClient(config) {
|
|
|
784
811
|
};
|
|
785
812
|
}
|
|
786
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
|
+
|
|
787
946
|
// src/integrations/restApi/woocommerce/omnibus/queries.ts
|
|
788
947
|
var META_KEY_LOWEST_PRICE = "wpo_lowest_price";
|
|
789
948
|
var META_KEY_PRICE_HISTORY = "_alg_wc_price_history";
|
|
@@ -850,8 +1009,8 @@ function resolveWooErrorCode(status, upstreamCode) {
|
|
|
850
1009
|
}
|
|
851
1010
|
|
|
852
1011
|
// src/integrations/restApi/woocommerce/client/fetcher.ts
|
|
853
|
-
var
|
|
854
|
-
var
|
|
1012
|
+
var USER_AGENT3 = "NextWordpress WooCommerce Client";
|
|
1013
|
+
var DEFAULT_CACHE_TTL2 = 3600;
|
|
855
1014
|
function toQueryString(params) {
|
|
856
1015
|
const pairs = [];
|
|
857
1016
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -861,7 +1020,7 @@ function toQueryString(params) {
|
|
|
861
1020
|
return pairs.join("&");
|
|
862
1021
|
}
|
|
863
1022
|
function createWooCommerceFetcher(config) {
|
|
864
|
-
const cacheTTL = config.cacheTTL ??
|
|
1023
|
+
const cacheTTL = config.cacheTTL ?? DEFAULT_CACHE_TTL2;
|
|
865
1024
|
function withAuth(query) {
|
|
866
1025
|
return { ...query, consumer_key: config.consumerKey, consumer_secret: config.consumerSecret };
|
|
867
1026
|
}
|
|
@@ -888,7 +1047,7 @@ function createWooCommerceFetcher(config) {
|
|
|
888
1047
|
const response = await fetch(url, {
|
|
889
1048
|
...options,
|
|
890
1049
|
headers: {
|
|
891
|
-
"User-Agent":
|
|
1050
|
+
"User-Agent": USER_AGENT3,
|
|
892
1051
|
"Content-Type": "application/json",
|
|
893
1052
|
...options?.headers
|
|
894
1053
|
},
|
|
@@ -910,7 +1069,7 @@ function createWooCommerceFetcher(config) {
|
|
|
910
1069
|
async function wcFetchPaginated(path, query, tags = ["woocommerce"]) {
|
|
911
1070
|
const url = buildUrl2(path, query);
|
|
912
1071
|
const response = await fetch(url, {
|
|
913
|
-
headers: { "User-Agent":
|
|
1072
|
+
headers: { "User-Agent": USER_AGENT3 },
|
|
914
1073
|
next: { tags, revalidate: cacheTTL }
|
|
915
1074
|
});
|
|
916
1075
|
if (!response.ok) {
|
|
@@ -2196,7 +2355,7 @@ var WPGraphQLError = class extends Error {
|
|
|
2196
2355
|
};
|
|
2197
2356
|
|
|
2198
2357
|
// src/integrations/wpGraphQL/client/fetcher.ts
|
|
2199
|
-
var
|
|
2358
|
+
var USER_AGENT4 = "NextWordpress WPGraphQL Client";
|
|
2200
2359
|
function createWPGraphQLFetcher(config) {
|
|
2201
2360
|
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
2202
2361
|
const cacheTTL = config.cacheTTL ?? 300;
|
|
@@ -2205,7 +2364,7 @@ function createWPGraphQLFetcher(config) {
|
|
|
2205
2364
|
method: "POST",
|
|
2206
2365
|
headers: {
|
|
2207
2366
|
"Content-Type": "application/json",
|
|
2208
|
-
"User-Agent":
|
|
2367
|
+
"User-Agent": USER_AGENT4
|
|
2209
2368
|
},
|
|
2210
2369
|
body: JSON.stringify({ query: document, variables }),
|
|
2211
2370
|
next: { tags, revalidate: cacheTTL }
|
|
@@ -2249,7 +2408,7 @@ function createWPGraphQLFetcher(config) {
|
|
|
2249
2408
|
async function gqlMutate(document, variables, authToken) {
|
|
2250
2409
|
const headers = {
|
|
2251
2410
|
"Content-Type": "application/json",
|
|
2252
|
-
"User-Agent":
|
|
2411
|
+
"User-Agent": USER_AGENT4
|
|
2253
2412
|
};
|
|
2254
2413
|
if (authToken) {
|
|
2255
2414
|
headers["Authorization"] = authToken;
|
|
@@ -3413,7 +3572,7 @@ var GQL_RESET_USER_PASSWORD = `
|
|
|
3413
3572
|
}
|
|
3414
3573
|
}
|
|
3415
3574
|
`;
|
|
3416
|
-
function
|
|
3575
|
+
function createPasswordResetMutations2(fetcher) {
|
|
3417
3576
|
const { gqlMutate } = fetcher;
|
|
3418
3577
|
async function sendPasswordResetEmail(input) {
|
|
3419
3578
|
const data = await gqlMutate(GQL_SEND_PASSWORD_RESET_EMAIL, { input });
|
|
@@ -3441,7 +3600,7 @@ function createWPGraphQLMutationsClient(config) {
|
|
|
3441
3600
|
...createTagsMutations3(fetcher),
|
|
3442
3601
|
...createAuthorsMutations2(fetcher),
|
|
3443
3602
|
...createMediaMutations2(fetcher),
|
|
3444
|
-
...
|
|
3603
|
+
...createPasswordResetMutations2(fetcher)
|
|
3445
3604
|
};
|
|
3446
3605
|
}
|
|
3447
3606
|
|
|
@@ -4406,6 +4565,7 @@ exports.ErrorCode = ErrorCode;
|
|
|
4406
4565
|
exports.WPGraphQLError = WPGraphQLError;
|
|
4407
4566
|
exports.WooCommerceError = WooCommerceError;
|
|
4408
4567
|
exports.WordPressAPIError = WordPressAPIError;
|
|
4568
|
+
exports.YithWishlistError = YithWishlistError;
|
|
4409
4569
|
exports.authenticateJwt = authenticateJwt;
|
|
4410
4570
|
exports.buildACFFragment = buildACFFragment;
|
|
4411
4571
|
exports.buildPageWithACFQuery = buildPageWithACFQuery;
|
|
@@ -4433,10 +4593,13 @@ exports.createWPGraphQLMutationsClient = createWPGraphQLMutationsClient;
|
|
|
4433
4593
|
exports.createWPGraphQLWooCommerceClient = createWPGraphQLWooCommerceClient;
|
|
4434
4594
|
exports.createWPULikeClient = createWPULikeClient;
|
|
4435
4595
|
exports.createWPULikeQueries = createWPULikeQueries;
|
|
4596
|
+
exports.createWishlistMutations = createWishlistMutations;
|
|
4597
|
+
exports.createWishlistQueries = createWishlistQueries;
|
|
4436
4598
|
exports.createWooCommerceClient = createWooCommerceClient;
|
|
4437
4599
|
exports.createWooCommerceFetcher = createWooCommerceFetcher;
|
|
4438
4600
|
exports.createWordPressClient = createWordPressClient;
|
|
4439
4601
|
exports.createWordPressMutationsClient = createWordPressMutationsClient;
|
|
4602
|
+
exports.createYithWishlistFetcher = createYithWishlistFetcher;
|
|
4440
4603
|
exports.createYoastQueries = createYoastQueries;
|
|
4441
4604
|
exports.defaultMessages = defaultMessages;
|
|
4442
4605
|
exports.defaultMessagesPl = defaultMessagesPl;
|