@szymonpiatek/nextwordpress 0.0.19 → 0.0.21
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 +142 -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 +140 -1
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +142 -0
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +6 -2
- package/dist/hooks/index.d.ts +6 -2
- package/dist/hooks/index.js +140 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +138 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -3
- package/dist/index.d.ts +30 -3
- package/dist/index.js +135 -9
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +138 -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 +135 -9
- package/dist/server/index.js.map +1 -1
- package/dist/{types-DUmH-vcl.d.cts → types-DmNIXJNR.d.cts} +45 -1
- package/dist/{types-DUmH-vcl.d.ts → types-DmNIXJNR.d.ts} +45 -1
- package/package.json +1 -1
package/dist/server/index.cjs
CHANGED
|
@@ -943,6 +943,132 @@ function createWishlistMutations(fetcher) {
|
|
|
943
943
|
};
|
|
944
944
|
}
|
|
945
945
|
|
|
946
|
+
// src/integrations/restApi/woocommerce/ti_wishlist/fetcher.ts
|
|
947
|
+
var USER_AGENT3 = "NextWordpress TI Wishlist Client";
|
|
948
|
+
var DEFAULT_CACHE_TTL2 = 3600;
|
|
949
|
+
var TIWishlistError = class extends Error {
|
|
950
|
+
constructor(code, status, url, message) {
|
|
951
|
+
super(message);
|
|
952
|
+
__publicField(this, "code", code);
|
|
953
|
+
__publicField(this, "status", status);
|
|
954
|
+
__publicField(this, "url", url);
|
|
955
|
+
this.name = "TIWishlistError";
|
|
956
|
+
}
|
|
957
|
+
};
|
|
958
|
+
function resolveTIErrorCode(status) {
|
|
959
|
+
if (status === 401) return ErrorCode.WOO_UNAUTHORIZED;
|
|
960
|
+
if (status === 403) return ErrorCode.WOO_FORBIDDEN;
|
|
961
|
+
if (status === 404) return ErrorCode.WOO_WISHLIST_NOT_FOUND;
|
|
962
|
+
return ErrorCode.WOO_REQUEST_FAILED;
|
|
963
|
+
}
|
|
964
|
+
function createTIWishlistFetcher(config) {
|
|
965
|
+
const cacheTTL = config.cacheTTL ?? DEFAULT_CACHE_TTL2;
|
|
966
|
+
function buildUrl2(path) {
|
|
967
|
+
const base = typeof window !== "undefined" && config.clientURL ? config.clientURL : config.serverURL;
|
|
968
|
+
return `${base}${path}`;
|
|
969
|
+
}
|
|
970
|
+
function authHeaders() {
|
|
971
|
+
return {
|
|
972
|
+
"User-Agent": USER_AGENT3,
|
|
973
|
+
"Content-Type": "application/json",
|
|
974
|
+
Authorization: `Bearer ${config.token}`
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
async function throwTIError(response, url) {
|
|
978
|
+
const errorCode = resolveTIErrorCode(response.status);
|
|
979
|
+
throw new TIWishlistError(
|
|
980
|
+
errorCode,
|
|
981
|
+
response.status,
|
|
982
|
+
url,
|
|
983
|
+
resolveMessage(errorCode, config.errorMessages)
|
|
984
|
+
);
|
|
985
|
+
}
|
|
986
|
+
async function tiFetch(path, tags = ["ti-wishlist"], options) {
|
|
987
|
+
const url = buildUrl2(path);
|
|
988
|
+
const isMutation = options?.method && options.method !== "GET";
|
|
989
|
+
const response = await fetch(url, {
|
|
990
|
+
...options,
|
|
991
|
+
headers: {
|
|
992
|
+
...authHeaders(),
|
|
993
|
+
...options?.headers
|
|
994
|
+
},
|
|
995
|
+
next: isMutation ? void 0 : { tags, revalidate: cacheTTL }
|
|
996
|
+
});
|
|
997
|
+
if (!response.ok) {
|
|
998
|
+
await throwTIError(response, url);
|
|
999
|
+
}
|
|
1000
|
+
return response.json();
|
|
1001
|
+
}
|
|
1002
|
+
async function tiFetchGraceful(path, fallback, tags = ["ti-wishlist"]) {
|
|
1003
|
+
try {
|
|
1004
|
+
return await tiFetch(path, tags);
|
|
1005
|
+
} catch (err) {
|
|
1006
|
+
console.warn(`TI Wishlist fetch failed for ${path}`, err);
|
|
1007
|
+
return fallback;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
async function tiMutate(path, body, method = "POST") {
|
|
1011
|
+
return tiFetch(path, ["ti-wishlist"], {
|
|
1012
|
+
method,
|
|
1013
|
+
body: JSON.stringify(body)
|
|
1014
|
+
});
|
|
1015
|
+
}
|
|
1016
|
+
return { tiFetch, tiFetchGraceful, tiMutate };
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
// src/integrations/restApi/woocommerce/ti_wishlist/queries.ts
|
|
1020
|
+
var BASE3 = "/wp-json/wc/v3/wishlist";
|
|
1021
|
+
function createTIWishlistQueries(fetcher) {
|
|
1022
|
+
const { tiFetch, tiFetchGraceful } = fetcher;
|
|
1023
|
+
async function getWishlistsByUser(userId) {
|
|
1024
|
+
return tiFetchGraceful(
|
|
1025
|
+
`${BASE3}/get_by_user/${userId}`,
|
|
1026
|
+
[],
|
|
1027
|
+
["ti-wishlist", `ti-wishlists-user-${userId}`]
|
|
1028
|
+
);
|
|
1029
|
+
}
|
|
1030
|
+
async function getWishlistByShareKey(shareKey) {
|
|
1031
|
+
return tiFetch(`${BASE3}/get_by_share_key/${shareKey}`, [
|
|
1032
|
+
"ti-wishlist",
|
|
1033
|
+
`ti-wishlist-${shareKey}`
|
|
1034
|
+
]);
|
|
1035
|
+
}
|
|
1036
|
+
async function getWishlistProducts(shareKey, params) {
|
|
1037
|
+
const query = new URLSearchParams();
|
|
1038
|
+
if (params?.count != null) query.set("count", String(params.count));
|
|
1039
|
+
if (params?.offset != null) query.set("offset", String(params.offset));
|
|
1040
|
+
if (params?.order != null) query.set("order", params.order);
|
|
1041
|
+
const qs = query.toString() ? `?${query.toString()}` : "";
|
|
1042
|
+
return tiFetch(`${BASE3}/${shareKey}/get_products${qs}`, [
|
|
1043
|
+
"ti-wishlist",
|
|
1044
|
+
`ti-wishlist-products-${shareKey}`
|
|
1045
|
+
]);
|
|
1046
|
+
}
|
|
1047
|
+
return { getWishlistsByUser, getWishlistByShareKey, getWishlistProducts };
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
// src/integrations/restApi/woocommerce/ti_wishlist/mutations.ts
|
|
1051
|
+
var BASE4 = "/wp-json/wc/v3/wishlist";
|
|
1052
|
+
function createTIWishlistMutations(fetcher) {
|
|
1053
|
+
const { tiFetch, tiMutate } = fetcher;
|
|
1054
|
+
async function createWishlist(input) {
|
|
1055
|
+
return tiMutate(`${BASE4}/create`, input);
|
|
1056
|
+
}
|
|
1057
|
+
async function updateWishlist(shareKey, input) {
|
|
1058
|
+
return tiMutate(`${BASE4}/update/${shareKey}`, input);
|
|
1059
|
+
}
|
|
1060
|
+
async function deleteWishlist(shareKey) {
|
|
1061
|
+
return tiFetch(`${BASE4}/delete/${shareKey}`, ["ti-wishlist"]);
|
|
1062
|
+
}
|
|
1063
|
+
async function addProduct(shareKey, input) {
|
|
1064
|
+
return tiMutate(`${BASE4}/${shareKey}/add_product`, input);
|
|
1065
|
+
}
|
|
1066
|
+
async function removeProduct(shareKey, itemId) {
|
|
1067
|
+
return tiMutate(`${BASE4}/${shareKey}/remove_product/${itemId}`, {}, "DELETE");
|
|
1068
|
+
}
|
|
1069
|
+
return { createWishlist, updateWishlist, deleteWishlist, addProduct, removeProduct };
|
|
1070
|
+
}
|
|
1071
|
+
|
|
946
1072
|
// src/integrations/restApi/woocommerce/omnibus/queries.ts
|
|
947
1073
|
var META_KEY_LOWEST_PRICE = "wpo_lowest_price";
|
|
948
1074
|
var META_KEY_PRICE_HISTORY = "_alg_wc_price_history";
|
|
@@ -1009,8 +1135,8 @@ function resolveWooErrorCode(status, upstreamCode) {
|
|
|
1009
1135
|
}
|
|
1010
1136
|
|
|
1011
1137
|
// src/integrations/restApi/woocommerce/client/fetcher.ts
|
|
1012
|
-
var
|
|
1013
|
-
var
|
|
1138
|
+
var USER_AGENT4 = "NextWordpress WooCommerce Client";
|
|
1139
|
+
var DEFAULT_CACHE_TTL3 = 3600;
|
|
1014
1140
|
function toQueryString(params) {
|
|
1015
1141
|
const pairs = [];
|
|
1016
1142
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -1020,7 +1146,7 @@ function toQueryString(params) {
|
|
|
1020
1146
|
return pairs.join("&");
|
|
1021
1147
|
}
|
|
1022
1148
|
function createWooCommerceFetcher(config) {
|
|
1023
|
-
const cacheTTL = config.cacheTTL ??
|
|
1149
|
+
const cacheTTL = config.cacheTTL ?? DEFAULT_CACHE_TTL3;
|
|
1024
1150
|
function withAuth(query) {
|
|
1025
1151
|
return { ...query, consumer_key: config.consumerKey, consumer_secret: config.consumerSecret };
|
|
1026
1152
|
}
|
|
@@ -1047,7 +1173,7 @@ function createWooCommerceFetcher(config) {
|
|
|
1047
1173
|
const response = await fetch(url, {
|
|
1048
1174
|
...options,
|
|
1049
1175
|
headers: {
|
|
1050
|
-
"User-Agent":
|
|
1176
|
+
"User-Agent": USER_AGENT4,
|
|
1051
1177
|
"Content-Type": "application/json",
|
|
1052
1178
|
...options?.headers
|
|
1053
1179
|
},
|
|
@@ -1069,7 +1195,7 @@ function createWooCommerceFetcher(config) {
|
|
|
1069
1195
|
async function wcFetchPaginated(path, query, tags = ["woocommerce"]) {
|
|
1070
1196
|
const url = buildUrl2(path, query);
|
|
1071
1197
|
const response = await fetch(url, {
|
|
1072
|
-
headers: { "User-Agent":
|
|
1198
|
+
headers: { "User-Agent": USER_AGENT4 },
|
|
1073
1199
|
next: { tags, revalidate: cacheTTL }
|
|
1074
1200
|
});
|
|
1075
1201
|
if (!response.ok) {
|
|
@@ -2355,7 +2481,7 @@ var WPGraphQLError = class extends Error {
|
|
|
2355
2481
|
};
|
|
2356
2482
|
|
|
2357
2483
|
// src/integrations/wpGraphQL/client/fetcher.ts
|
|
2358
|
-
var
|
|
2484
|
+
var USER_AGENT5 = "NextWordpress WPGraphQL Client";
|
|
2359
2485
|
function createWPGraphQLFetcher(config) {
|
|
2360
2486
|
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
2361
2487
|
const cacheTTL = config.cacheTTL ?? 300;
|
|
@@ -2364,7 +2490,7 @@ function createWPGraphQLFetcher(config) {
|
|
|
2364
2490
|
method: "POST",
|
|
2365
2491
|
headers: {
|
|
2366
2492
|
"Content-Type": "application/json",
|
|
2367
|
-
"User-Agent":
|
|
2493
|
+
"User-Agent": USER_AGENT5
|
|
2368
2494
|
},
|
|
2369
2495
|
body: JSON.stringify({ query: document, variables }),
|
|
2370
2496
|
next: { tags, revalidate: cacheTTL }
|
|
@@ -2408,7 +2534,7 @@ function createWPGraphQLFetcher(config) {
|
|
|
2408
2534
|
async function gqlMutate(document, variables, authToken) {
|
|
2409
2535
|
const headers = {
|
|
2410
2536
|
"Content-Type": "application/json",
|
|
2411
|
-
"User-Agent":
|
|
2537
|
+
"User-Agent": USER_AGENT5
|
|
2412
2538
|
};
|
|
2413
2539
|
if (authToken) {
|
|
2414
2540
|
headers["Authorization"] = authToken;
|
|
@@ -4562,6 +4688,7 @@ async function validateJwtToken(config, token) {
|
|
|
4562
4688
|
exports.AuthenticationError = AuthenticationError;
|
|
4563
4689
|
exports.CF7Error = CF7Error;
|
|
4564
4690
|
exports.ErrorCode = ErrorCode;
|
|
4691
|
+
exports.TIWishlistError = TIWishlistError;
|
|
4565
4692
|
exports.WPGraphQLError = WPGraphQLError;
|
|
4566
4693
|
exports.WooCommerceError = WooCommerceError;
|
|
4567
4694
|
exports.WordPressAPIError = WordPressAPIError;
|
|
@@ -4585,6 +4712,9 @@ exports.createPagesMutations = createPagesMutations;
|
|
|
4585
4712
|
exports.createPostsMutations = createPostsMutations;
|
|
4586
4713
|
exports.createPreviewHandler = createPreviewHandler;
|
|
4587
4714
|
exports.createRevalidationHandler = createRevalidationHandler;
|
|
4715
|
+
exports.createTIWishlistFetcher = createTIWishlistFetcher;
|
|
4716
|
+
exports.createTIWishlistMutations = createTIWishlistMutations;
|
|
4717
|
+
exports.createTIWishlistQueries = createTIWishlistQueries;
|
|
4588
4718
|
exports.createTagsMutations = createTagsMutations;
|
|
4589
4719
|
exports.createWPGraphQLClient = createWPGraphQLCoreClient;
|
|
4590
4720
|
exports.createWPGraphQLCoreClient = createWPGraphQLCoreClient;
|