@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.
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { J as JwtAuthCredentials, N as NextWordpressConfig, W as WPGraphQLConfig, G as GQLSendPasswordResetEmailResult, a as GQLResetUserPasswordResult, C as CookieConsentCategories, P as Post, b as WordPressResponse, c as WooCommerceConfig, d as WCProduct, e as WCProductFilterParams, f as WooCommerceResponse, g as WCCreateOrderInput, h as WCOrder, i as WCCustomer, U as UpdateCustomerInput, j as GQLPost, k as GQLPostFilter, l as GQLConnection, m as WPULikeStatsParams, n as WPULikeStats, o as WPULikeStatus, p as WPULikeVoteResponse, q as WPULikeCheckParams, r as WPULikeCheckResponse, s as CF7SubmissionResponse } from '../types-DVzJO3P-.cjs';
3
+ import { J as JwtAuthCredentials, N as NextWordpressConfig, W as WPGraphQLConfig, G as GQLSendPasswordResetEmailResult, a as GQLResetUserPasswordResult, R as RestSendPasswordResetEmailResult, b as RestResetUserPasswordResult, C as CookieConsentCategories, P as Post, c as WordPressResponse, d as WooCommerceConfig, e as WCProduct, f as WCProductFilterParams, g as WooCommerceResponse, h as WCCreateOrderInput, i as WCOrder, j as WCCustomer, U as UpdateCustomerInput, Y as YithWishlistConfig, k as WCWishlist, l as GQLPost, m as GQLPostFilter, n as GQLConnection, o as WPULikeStatsParams, p as WPULikeStats, q as WPULikeStatus, r as WPULikeVoteResponse, s as WPULikeCheckParams, t as WPULikeCheckResponse, u as CF7SubmissionResponse } from '../types-DUmH-vcl.cjs';
4
4
  import * as swr_mutation from 'swr/mutation';
5
5
  import * as swr from 'swr';
6
6
  import { SWRConfiguration } from 'swr';
@@ -25,17 +25,29 @@ declare function AuthProvider({ config, children, }: {
25
25
  }): react.JSX.Element;
26
26
  declare function useAuth(): AuthContextValue;
27
27
 
28
+ type SendPasswordResetEmailArg$1 = {
29
+ username: string;
30
+ };
31
+ declare function useSendPasswordResetEmail(config: WPGraphQLConfig): swr_mutation.SWRMutationResponse<GQLSendPasswordResetEmailResult, Error, string, SendPasswordResetEmailArg$1>;
32
+
33
+ type ResetUserPasswordArg$1 = {
34
+ key: string;
35
+ login: string;
36
+ password: string;
37
+ };
38
+ declare function useResetUserPassword(config: WPGraphQLConfig): swr_mutation.SWRMutationResponse<GQLResetUserPasswordResult, Error, string, ResetUserPasswordArg$1>;
39
+
28
40
  type SendPasswordResetEmailArg = {
29
41
  username: string;
30
42
  };
31
- declare function useSendPasswordResetEmail(config: WPGraphQLConfig): swr_mutation.SWRMutationResponse<GQLSendPasswordResetEmailResult, Error, string, SendPasswordResetEmailArg>;
43
+ declare function useSendPasswordResetEmailRest(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<RestSendPasswordResetEmailResult, Error, string, SendPasswordResetEmailArg>;
32
44
 
33
45
  type ResetUserPasswordArg = {
34
46
  key: string;
35
47
  login: string;
36
48
  password: string;
37
49
  };
38
- declare function useResetUserPassword(config: WPGraphQLConfig): swr_mutation.SWRMutationResponse<GQLResetUserPasswordResult, Error, string, ResetUserPasswordArg>;
50
+ declare function useResetUserPasswordRest(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<RestResetUserPasswordResult, Error, string, ResetUserPasswordArg>;
39
51
 
40
52
  declare function useCookieConsent(consentPath?: string, cookieName?: string): {
41
53
  consent: CookieConsentCategories | null;
@@ -129,6 +141,9 @@ declare function WooCommerceCustomerProvider({ config, children, }: {
129
141
  }): react.JSX.Element;
130
142
  declare function useCustomer(): CustomerContextValue;
131
143
 
144
+ declare function useWishlists(config: YithWishlistConfig, swrOptions?: SWRConfiguration<WCWishlist[]>): swr.SWRResponse<WCWishlist[], any, SWRConfiguration<WCWishlist[], any, swr.BareFetcher<WCWishlist[]>> | undefined>;
145
+ declare function useWishlist(config: YithWishlistConfig, wishlistToken: string | null | undefined, swrOptions?: SWRConfiguration<WCWishlist>): swr.SWRResponse<WCWishlist, any, SWRConfiguration<WCWishlist, any, swr.BareFetcher<WCWishlist>> | undefined>;
146
+
132
147
  declare function useWPGraphQL<TData>(config: WPGraphQLConfig, query: string, variables?: Record<string, unknown>, tags?: string[], swrOptions?: SWRConfiguration<TData>): swr.SWRResponse<TData, any, SWRConfiguration<TData, any, swr.BareFetcher<TData>> | undefined>;
133
148
  declare function useGQLPosts(config: WPGraphQLConfig, first?: number, after?: string, filter?: GQLPostFilter, swrOptions?: SWRConfiguration<GQLConnection<GQLPost>>): swr.SWRResponse<GQLConnection<GQLPost>, any, SWRConfiguration<GQLConnection<GQLPost>, any, swr.BareFetcher<GQLConnection<GQLPost>>> | undefined>;
134
149
  declare function useGQLPostBySlug(config: WPGraphQLConfig, slug: string | null | undefined, swrOptions?: SWRConfiguration<GQLPost | null>): swr.SWRResponse<GQLPost | null, any, SWRConfiguration<GQLPost | null, any, swr.BareFetcher<GQLPost | null>> | undefined>;
@@ -148,4 +163,4 @@ type CF7SubmitArg = {
148
163
  };
149
164
  declare function useCF7Submit(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<CF7SubmissionResponse, Error, string, CF7SubmitArg>;
150
165
 
151
- export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useResetUserPassword, useSendPasswordResetEmail, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
166
+ export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useResetUserPassword, useResetUserPasswordRest, useSendPasswordResetEmail, useSendPasswordResetEmailRest, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats, useWishlist, useWishlists };
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { J as JwtAuthCredentials, N as NextWordpressConfig, W as WPGraphQLConfig, G as GQLSendPasswordResetEmailResult, a as GQLResetUserPasswordResult, C as CookieConsentCategories, P as Post, b as WordPressResponse, c as WooCommerceConfig, d as WCProduct, e as WCProductFilterParams, f as WooCommerceResponse, g as WCCreateOrderInput, h as WCOrder, i as WCCustomer, U as UpdateCustomerInput, j as GQLPost, k as GQLPostFilter, l as GQLConnection, m as WPULikeStatsParams, n as WPULikeStats, o as WPULikeStatus, p as WPULikeVoteResponse, q as WPULikeCheckParams, r as WPULikeCheckResponse, s as CF7SubmissionResponse } from '../types-DVzJO3P-.js';
3
+ import { J as JwtAuthCredentials, N as NextWordpressConfig, W as WPGraphQLConfig, G as GQLSendPasswordResetEmailResult, a as GQLResetUserPasswordResult, R as RestSendPasswordResetEmailResult, b as RestResetUserPasswordResult, C as CookieConsentCategories, P as Post, c as WordPressResponse, d as WooCommerceConfig, e as WCProduct, f as WCProductFilterParams, g as WooCommerceResponse, h as WCCreateOrderInput, i as WCOrder, j as WCCustomer, U as UpdateCustomerInput, Y as YithWishlistConfig, k as WCWishlist, l as GQLPost, m as GQLPostFilter, n as GQLConnection, o as WPULikeStatsParams, p as WPULikeStats, q as WPULikeStatus, r as WPULikeVoteResponse, s as WPULikeCheckParams, t as WPULikeCheckResponse, u as CF7SubmissionResponse } from '../types-DUmH-vcl.js';
4
4
  import * as swr_mutation from 'swr/mutation';
5
5
  import * as swr from 'swr';
6
6
  import { SWRConfiguration } from 'swr';
@@ -25,17 +25,29 @@ declare function AuthProvider({ config, children, }: {
25
25
  }): react.JSX.Element;
26
26
  declare function useAuth(): AuthContextValue;
27
27
 
28
+ type SendPasswordResetEmailArg$1 = {
29
+ username: string;
30
+ };
31
+ declare function useSendPasswordResetEmail(config: WPGraphQLConfig): swr_mutation.SWRMutationResponse<GQLSendPasswordResetEmailResult, Error, string, SendPasswordResetEmailArg$1>;
32
+
33
+ type ResetUserPasswordArg$1 = {
34
+ key: string;
35
+ login: string;
36
+ password: string;
37
+ };
38
+ declare function useResetUserPassword(config: WPGraphQLConfig): swr_mutation.SWRMutationResponse<GQLResetUserPasswordResult, Error, string, ResetUserPasswordArg$1>;
39
+
28
40
  type SendPasswordResetEmailArg = {
29
41
  username: string;
30
42
  };
31
- declare function useSendPasswordResetEmail(config: WPGraphQLConfig): swr_mutation.SWRMutationResponse<GQLSendPasswordResetEmailResult, Error, string, SendPasswordResetEmailArg>;
43
+ declare function useSendPasswordResetEmailRest(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<RestSendPasswordResetEmailResult, Error, string, SendPasswordResetEmailArg>;
32
44
 
33
45
  type ResetUserPasswordArg = {
34
46
  key: string;
35
47
  login: string;
36
48
  password: string;
37
49
  };
38
- declare function useResetUserPassword(config: WPGraphQLConfig): swr_mutation.SWRMutationResponse<GQLResetUserPasswordResult, Error, string, ResetUserPasswordArg>;
50
+ declare function useResetUserPasswordRest(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<RestResetUserPasswordResult, Error, string, ResetUserPasswordArg>;
39
51
 
40
52
  declare function useCookieConsent(consentPath?: string, cookieName?: string): {
41
53
  consent: CookieConsentCategories | null;
@@ -129,6 +141,9 @@ declare function WooCommerceCustomerProvider({ config, children, }: {
129
141
  }): react.JSX.Element;
130
142
  declare function useCustomer(): CustomerContextValue;
131
143
 
144
+ declare function useWishlists(config: YithWishlistConfig, swrOptions?: SWRConfiguration<WCWishlist[]>): swr.SWRResponse<WCWishlist[], any, SWRConfiguration<WCWishlist[], any, swr.BareFetcher<WCWishlist[]>> | undefined>;
145
+ declare function useWishlist(config: YithWishlistConfig, wishlistToken: string | null | undefined, swrOptions?: SWRConfiguration<WCWishlist>): swr.SWRResponse<WCWishlist, any, SWRConfiguration<WCWishlist, any, swr.BareFetcher<WCWishlist>> | undefined>;
146
+
132
147
  declare function useWPGraphQL<TData>(config: WPGraphQLConfig, query: string, variables?: Record<string, unknown>, tags?: string[], swrOptions?: SWRConfiguration<TData>): swr.SWRResponse<TData, any, SWRConfiguration<TData, any, swr.BareFetcher<TData>> | undefined>;
133
148
  declare function useGQLPosts(config: WPGraphQLConfig, first?: number, after?: string, filter?: GQLPostFilter, swrOptions?: SWRConfiguration<GQLConnection<GQLPost>>): swr.SWRResponse<GQLConnection<GQLPost>, any, SWRConfiguration<GQLConnection<GQLPost>, any, swr.BareFetcher<GQLConnection<GQLPost>>> | undefined>;
134
149
  declare function useGQLPostBySlug(config: WPGraphQLConfig, slug: string | null | undefined, swrOptions?: SWRConfiguration<GQLPost | null>): swr.SWRResponse<GQLPost | null, any, SWRConfiguration<GQLPost | null, any, swr.BareFetcher<GQLPost | null>> | undefined>;
@@ -148,4 +163,4 @@ type CF7SubmitArg = {
148
163
  };
149
164
  declare function useCF7Submit(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<CF7SubmissionResponse, Error, string, CF7SubmitArg>;
150
165
 
151
- export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useResetUserPassword, useSendPasswordResetEmail, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
166
+ export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useResetUserPassword, useResetUserPasswordRest, useSendPasswordResetEmail, useSendPasswordResetEmailRest, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats, useWishlist, useWishlists };
@@ -37,6 +37,8 @@ var ErrorCode = {
37
37
  WOO_REVIEW_NOT_FOUND: "WOO_REVIEW_NOT_FOUND",
38
38
  WOO_WEBHOOK_NOT_FOUND: "WOO_WEBHOOK_NOT_FOUND",
39
39
  WOO_SHIPPING_ZONE_NOT_FOUND: "WOO_SHIPPING_ZONE_NOT_FOUND",
40
+ WOO_WISHLIST_NOT_FOUND: "WOO_WISHLIST_NOT_FOUND",
41
+ WOO_WISHLIST_ITEM_NOT_FOUND: "WOO_WISHLIST_ITEM_NOT_FOUND",
40
42
  // Auth
41
43
  AUTH_JWT_FAILED: "AUTH_JWT_FAILED",
42
44
  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",
@@ -359,44 +363,6 @@ function useResetUserPassword(config) {
359
363
  }
360
364
  );
361
365
  }
362
- function readConsentFromDocument(cookieName) {
363
- if (typeof document === "undefined") return null;
364
- const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
365
- if (!match) return null;
366
- if (match[1] === "1") return { necessary: true, analytics: true, marketing: true };
367
- try {
368
- const parsed = JSON.parse(decodeURIComponent(match[1]));
369
- if (typeof parsed !== "object" || parsed === null) return null;
370
- return parsed;
371
- } catch {
372
- return null;
373
- }
374
- }
375
- function useCookieConsent(consentPath = "/api/cookie-consent", cookieName = "cookie_notice_accepted") {
376
- const [consent, setConsentState] = useState(null);
377
- const [isLoaded, setIsLoaded] = useState(false);
378
- useEffect(() => {
379
- setConsentState(readConsentFromDocument(cookieName));
380
- setIsLoaded(true);
381
- }, [cookieName]);
382
- const setConsent = useCallback(
383
- async (categories) => {
384
- const res = await fetch(consentPath, {
385
- method: "POST",
386
- headers: { "Content-Type": "application/json" },
387
- body: JSON.stringify(categories)
388
- });
389
- const data = await res.json();
390
- setConsentState(data);
391
- },
392
- [consentPath]
393
- );
394
- const clearConsent = useCallback(async () => {
395
- await fetch(consentPath, { method: "DELETE" });
396
- setConsentState(null);
397
- }, [consentPath]);
398
- return { consent, isLoaded, setConsent, clearConsent };
399
- }
400
366
 
401
367
  // src/integrations/restApi/core/client/types.ts
402
368
  var WordPressAPIError = class extends Error {
@@ -521,6 +487,88 @@ function createFetcher(config) {
521
487
  return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate, wpUpload };
522
488
  }
523
489
 
490
+ // src/integrations/restApi/core/mutations/passwordReset/mutations.ts
491
+ function createPasswordResetMutations2(fetcher) {
492
+ const { wpMutate } = fetcher;
493
+ async function sendPasswordResetEmail(input) {
494
+ return wpMutate(
495
+ "/wp-json/wp/v2/users/lost-password",
496
+ input,
497
+ "POST"
498
+ );
499
+ }
500
+ async function resetUserPassword(input) {
501
+ return wpMutate(
502
+ "/wp-json/wp/v2/users/reset-password",
503
+ input,
504
+ "POST"
505
+ );
506
+ }
507
+ return { sendPasswordResetEmail, resetUserPassword };
508
+ }
509
+
510
+ // src/hooks/auth/useSendPasswordResetEmailRest.ts
511
+ function useSendPasswordResetEmailRest(config) {
512
+ return useSWRMutation(
513
+ `send-password-reset-rest:${config.serverURL}`,
514
+ async (_, { arg }) => {
515
+ return createPasswordResetMutations2(createFetcher(config)).sendPasswordResetEmail({
516
+ username: arg.username
517
+ });
518
+ }
519
+ );
520
+ }
521
+ function useResetUserPasswordRest(config) {
522
+ return useSWRMutation(
523
+ `reset-user-password-rest:${config.serverURL}`,
524
+ async (_, { arg }) => {
525
+ return createPasswordResetMutations2(createFetcher(config)).resetUserPassword({
526
+ key: arg.key,
527
+ login: arg.login,
528
+ password: arg.password
529
+ });
530
+ }
531
+ );
532
+ }
533
+ function readConsentFromDocument(cookieName) {
534
+ if (typeof document === "undefined") return null;
535
+ const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
536
+ if (!match) return null;
537
+ if (match[1] === "1") return { necessary: true, analytics: true, marketing: true };
538
+ try {
539
+ const parsed = JSON.parse(decodeURIComponent(match[1]));
540
+ if (typeof parsed !== "object" || parsed === null) return null;
541
+ return parsed;
542
+ } catch {
543
+ return null;
544
+ }
545
+ }
546
+ function useCookieConsent(consentPath = "/api/cookie-consent", cookieName = "cookie_notice_accepted") {
547
+ const [consent, setConsentState] = useState(null);
548
+ const [isLoaded, setIsLoaded] = useState(false);
549
+ useEffect(() => {
550
+ setConsentState(readConsentFromDocument(cookieName));
551
+ setIsLoaded(true);
552
+ }, [cookieName]);
553
+ const setConsent = useCallback(
554
+ async (categories) => {
555
+ const res = await fetch(consentPath, {
556
+ method: "POST",
557
+ headers: { "Content-Type": "application/json" },
558
+ body: JSON.stringify(categories)
559
+ });
560
+ const data = await res.json();
561
+ setConsentState(data);
562
+ },
563
+ [consentPath]
564
+ );
565
+ const clearConsent = useCallback(async () => {
566
+ await fetch(consentPath, { method: "DELETE" });
567
+ setConsentState(null);
568
+ }, [consentPath]);
569
+ return { consent, isLoaded, setConsent, clearConsent };
570
+ }
571
+
524
572
  // src/integrations/restApi/core/posts/queries.ts
525
573
  function createPostsQueries(fetcher) {
526
574
  const { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful } = fetcher;
@@ -1260,6 +1308,126 @@ function useCustomer() {
1260
1308
  return ctx;
1261
1309
  }
1262
1310
 
1311
+ // src/integrations/restApi/woocommerce/wishlist/fetcher.ts
1312
+ var USER_AGENT4 = "NextWordpress YITH Wishlist Client";
1313
+ var DEFAULT_CACHE_TTL2 = 3600;
1314
+ var YithWishlistError = class extends Error {
1315
+ constructor(code, status, url, message, upstreamCode, upstreamMessage) {
1316
+ super(message);
1317
+ __publicField(this, "code", code);
1318
+ __publicField(this, "status", status);
1319
+ __publicField(this, "url", url);
1320
+ __publicField(this, "upstreamCode", upstreamCode);
1321
+ __publicField(this, "upstreamMessage", upstreamMessage);
1322
+ this.name = "YithWishlistError";
1323
+ }
1324
+ };
1325
+ function resolveYithErrorCode(status, upstreamCode) {
1326
+ if (status === 401) return ErrorCode.WOO_UNAUTHORIZED;
1327
+ if (status === 403) return ErrorCode.WOO_FORBIDDEN;
1328
+ if (status === 404) {
1329
+ if (upstreamCode === "yith_wcwl_wishlist_not_found") return ErrorCode.WOO_WISHLIST_NOT_FOUND;
1330
+ if (upstreamCode === "yith_wcwl_wishlist_item_not_found")
1331
+ return ErrorCode.WOO_WISHLIST_ITEM_NOT_FOUND;
1332
+ return ErrorCode.WOO_NOT_FOUND;
1333
+ }
1334
+ return ErrorCode.WOO_REQUEST_FAILED;
1335
+ }
1336
+ function createYithWishlistFetcher(config) {
1337
+ const cacheTTL = config.cacheTTL ?? DEFAULT_CACHE_TTL2;
1338
+ function buildUrl2(path) {
1339
+ const base = typeof window !== "undefined" && config.clientURL ? config.clientURL : config.serverURL;
1340
+ return `${base}${path}`;
1341
+ }
1342
+ function authHeaders() {
1343
+ return {
1344
+ "User-Agent": USER_AGENT4,
1345
+ "Content-Type": "application/json",
1346
+ Authorization: `Bearer ${config.token}`
1347
+ };
1348
+ }
1349
+ async function throwYithError(response, url) {
1350
+ const body = await response.json().catch(() => ({}));
1351
+ const errorCode = resolveYithErrorCode(response.status, body.code);
1352
+ throw new YithWishlistError(
1353
+ errorCode,
1354
+ response.status,
1355
+ url,
1356
+ resolveMessage(errorCode, config.errorMessages),
1357
+ body.code,
1358
+ body.message
1359
+ );
1360
+ }
1361
+ async function yithFetch(path, tags = ["yith-wishlist"], options) {
1362
+ const url = buildUrl2(path);
1363
+ const isMutation = options?.method && options.method !== "GET";
1364
+ const response = await fetch(url, {
1365
+ ...options,
1366
+ headers: {
1367
+ ...authHeaders(),
1368
+ ...options?.headers
1369
+ },
1370
+ next: isMutation ? void 0 : { tags, revalidate: cacheTTL }
1371
+ });
1372
+ if (!response.ok) {
1373
+ await throwYithError(response, url);
1374
+ }
1375
+ return response.json();
1376
+ }
1377
+ async function yithFetchGraceful(path, fallback, tags = ["yith-wishlist"]) {
1378
+ try {
1379
+ return await yithFetch(path, tags);
1380
+ } catch (err) {
1381
+ console.warn(`YITH Wishlist fetch failed for ${path}`, err);
1382
+ return fallback;
1383
+ }
1384
+ }
1385
+ async function yithMutate(path, body, method = "POST") {
1386
+ return yithFetch(path, ["yith-wishlist"], {
1387
+ method,
1388
+ body: JSON.stringify(body)
1389
+ });
1390
+ }
1391
+ return { yithFetch, yithFetchGraceful, yithMutate };
1392
+ }
1393
+
1394
+ // src/integrations/restApi/woocommerce/wishlist/queries.ts
1395
+ var BASE = "/wp-json/yith/wishlist/v1/wishlists";
1396
+ function createWishlistQueries(fetcher) {
1397
+ const { yithFetch, yithFetchGraceful } = fetcher;
1398
+ async function getWishlists() {
1399
+ return yithFetchGraceful(BASE, [], ["yith-wishlist", "wishlists"]);
1400
+ }
1401
+ async function getWishlistByToken(token) {
1402
+ return yithFetch(`${BASE}/${token}`, ["yith-wishlist", "wishlists", `wishlist-${token}`]);
1403
+ }
1404
+ return { getWishlists, getWishlistByToken };
1405
+ }
1406
+
1407
+ // src/hooks/woocommerce/useWishlist.ts
1408
+ function useWishlists(config, swrOptions) {
1409
+ const key = ["yith-wishlists", config.serverURL, config.token];
1410
+ return useSWR2(
1411
+ key,
1412
+ () => {
1413
+ const fetcher = createYithWishlistFetcher(config);
1414
+ return createWishlistQueries(fetcher).getWishlists();
1415
+ },
1416
+ swrOptions
1417
+ );
1418
+ }
1419
+ function useWishlist(config, wishlistToken, swrOptions) {
1420
+ const key = wishlistToken != null ? ["yith-wishlist", config.serverURL, config.token, wishlistToken] : null;
1421
+ return useSWR2(
1422
+ key,
1423
+ () => {
1424
+ const fetcher = createYithWishlistFetcher(config);
1425
+ return createWishlistQueries(fetcher).getWishlistByToken(wishlistToken);
1426
+ },
1427
+ swrOptions
1428
+ );
1429
+ }
1430
+
1263
1431
  // src/integrations/wpGraphQL/core/posts/queries.ts
1264
1432
  var DEFAULT_FIRST = 10;
1265
1433
  var BATCH_FIRST = 100;
@@ -1577,6 +1745,6 @@ function useCF7Submit(config) {
1577
1745
  );
1578
1746
  }
1579
1747
 
1580
- export { AuthProvider, CartProvider, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useResetUserPassword, useSendPasswordResetEmail, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
1748
+ export { AuthProvider, CartProvider, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useResetUserPassword, useResetUserPasswordRest, useSendPasswordResetEmail, useSendPasswordResetEmailRest, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats, useWishlist, useWishlists };
1581
1749
  //# sourceMappingURL=index.js.map
1582
1750
  //# sourceMappingURL=index.js.map