@szymonpiatek/nextwordpress 0.0.18 → 0.0.20

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/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,264 @@ 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
+
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(itemId) {
1067
+ return tiFetch(`${BASE4}/remove_product/${itemId}`, ["ti-wishlist"]);
1068
+ }
1069
+ return { createWishlist, updateWishlist, deleteWishlist, addProduct, removeProduct };
1070
+ }
1071
+
808
1072
  // src/integrations/restApi/woocommerce/omnibus/queries.ts
809
1073
  var META_KEY_LOWEST_PRICE = "wpo_lowest_price";
810
1074
  var META_KEY_PRICE_HISTORY = "_alg_wc_price_history";
@@ -871,8 +1135,8 @@ function resolveWooErrorCode(status, upstreamCode) {
871
1135
  }
872
1136
 
873
1137
  // src/integrations/restApi/woocommerce/client/fetcher.ts
874
- var USER_AGENT2 = "NextWordpress WooCommerce Client";
875
- var DEFAULT_CACHE_TTL = 3600;
1138
+ var USER_AGENT4 = "NextWordpress WooCommerce Client";
1139
+ var DEFAULT_CACHE_TTL3 = 3600;
876
1140
  function toQueryString(params) {
877
1141
  const pairs = [];
878
1142
  for (const [key, value] of Object.entries(params)) {
@@ -882,7 +1146,7 @@ function toQueryString(params) {
882
1146
  return pairs.join("&");
883
1147
  }
884
1148
  function createWooCommerceFetcher(config) {
885
- const cacheTTL = config.cacheTTL ?? DEFAULT_CACHE_TTL;
1149
+ const cacheTTL = config.cacheTTL ?? DEFAULT_CACHE_TTL3;
886
1150
  function withAuth(query) {
887
1151
  return { ...query, consumer_key: config.consumerKey, consumer_secret: config.consumerSecret };
888
1152
  }
@@ -909,7 +1173,7 @@ function createWooCommerceFetcher(config) {
909
1173
  const response = await fetch(url, {
910
1174
  ...options,
911
1175
  headers: {
912
- "User-Agent": USER_AGENT2,
1176
+ "User-Agent": USER_AGENT4,
913
1177
  "Content-Type": "application/json",
914
1178
  ...options?.headers
915
1179
  },
@@ -931,7 +1195,7 @@ function createWooCommerceFetcher(config) {
931
1195
  async function wcFetchPaginated(path, query, tags = ["woocommerce"]) {
932
1196
  const url = buildUrl2(path, query);
933
1197
  const response = await fetch(url, {
934
- headers: { "User-Agent": USER_AGENT2 },
1198
+ headers: { "User-Agent": USER_AGENT4 },
935
1199
  next: { tags, revalidate: cacheTTL }
936
1200
  });
937
1201
  if (!response.ok) {
@@ -2217,7 +2481,7 @@ var WPGraphQLError = class extends Error {
2217
2481
  };
2218
2482
 
2219
2483
  // src/integrations/wpGraphQL/client/fetcher.ts
2220
- var USER_AGENT3 = "NextWordpress WPGraphQL Client";
2484
+ var USER_AGENT5 = "NextWordpress WPGraphQL Client";
2221
2485
  function createWPGraphQLFetcher(config) {
2222
2486
  const url = `${resolveBaseUrl(config)}/graphql`;
2223
2487
  const cacheTTL = config.cacheTTL ?? 300;
@@ -2226,7 +2490,7 @@ function createWPGraphQLFetcher(config) {
2226
2490
  method: "POST",
2227
2491
  headers: {
2228
2492
  "Content-Type": "application/json",
2229
- "User-Agent": USER_AGENT3
2493
+ "User-Agent": USER_AGENT5
2230
2494
  },
2231
2495
  body: JSON.stringify({ query: document, variables }),
2232
2496
  next: { tags, revalidate: cacheTTL }
@@ -2270,7 +2534,7 @@ function createWPGraphQLFetcher(config) {
2270
2534
  async function gqlMutate(document, variables, authToken) {
2271
2535
  const headers = {
2272
2536
  "Content-Type": "application/json",
2273
- "User-Agent": USER_AGENT3
2537
+ "User-Agent": USER_AGENT5
2274
2538
  };
2275
2539
  if (authToken) {
2276
2540
  headers["Authorization"] = authToken;
@@ -4424,9 +4688,11 @@ async function validateJwtToken(config, token) {
4424
4688
  exports.AuthenticationError = AuthenticationError;
4425
4689
  exports.CF7Error = CF7Error;
4426
4690
  exports.ErrorCode = ErrorCode;
4691
+ exports.TIWishlistError = TIWishlistError;
4427
4692
  exports.WPGraphQLError = WPGraphQLError;
4428
4693
  exports.WooCommerceError = WooCommerceError;
4429
4694
  exports.WordPressAPIError = WordPressAPIError;
4695
+ exports.YithWishlistError = YithWishlistError;
4430
4696
  exports.authenticateJwt = authenticateJwt;
4431
4697
  exports.buildACFFragment = buildACFFragment;
4432
4698
  exports.buildPageWithACFQuery = buildPageWithACFQuery;
@@ -4446,6 +4712,9 @@ exports.createPagesMutations = createPagesMutations;
4446
4712
  exports.createPostsMutations = createPostsMutations;
4447
4713
  exports.createPreviewHandler = createPreviewHandler;
4448
4714
  exports.createRevalidationHandler = createRevalidationHandler;
4715
+ exports.createTIWishlistFetcher = createTIWishlistFetcher;
4716
+ exports.createTIWishlistMutations = createTIWishlistMutations;
4717
+ exports.createTIWishlistQueries = createTIWishlistQueries;
4449
4718
  exports.createTagsMutations = createTagsMutations;
4450
4719
  exports.createWPGraphQLClient = createWPGraphQLCoreClient;
4451
4720
  exports.createWPGraphQLCoreClient = createWPGraphQLCoreClient;
@@ -4454,10 +4723,13 @@ exports.createWPGraphQLMutationsClient = createWPGraphQLMutationsClient;
4454
4723
  exports.createWPGraphQLWooCommerceClient = createWPGraphQLWooCommerceClient;
4455
4724
  exports.createWPULikeClient = createWPULikeClient;
4456
4725
  exports.createWPULikeQueries = createWPULikeQueries;
4726
+ exports.createWishlistMutations = createWishlistMutations;
4727
+ exports.createWishlistQueries = createWishlistQueries;
4457
4728
  exports.createWooCommerceClient = createWooCommerceClient;
4458
4729
  exports.createWooCommerceFetcher = createWooCommerceFetcher;
4459
4730
  exports.createWordPressClient = createWordPressClient;
4460
4731
  exports.createWordPressMutationsClient = createWordPressMutationsClient;
4732
+ exports.createYithWishlistFetcher = createYithWishlistFetcher;
4461
4733
  exports.createYoastQueries = createYoastQueries;
4462
4734
  exports.defaultMessages = defaultMessages;
4463
4735
  exports.defaultMessagesPl = defaultMessagesPl;