@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.
@@ -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, 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';
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, T as TIWishlistConfig, l as TIWishlist, m as GetTIWishlistProductsParams, n as TIWishlistItem, o as GQLPost, p as GQLPostFilter, q as GQLConnection, r as WPULikeStatsParams, s as WPULikeStats, t as WPULikeStatus, u as WPULikeVoteResponse, v as WPULikeCheckParams, w as WPULikeCheckResponse, x as CF7SubmissionResponse } from '../types-DmNIXJNR.cjs';
4
4
  import * as swr_mutation from 'swr/mutation';
5
5
  import * as swr from 'swr';
6
6
  import { SWRConfiguration } from 'swr';
@@ -144,6 +144,10 @@ declare function useCustomer(): CustomerContextValue;
144
144
  declare function useWishlists(config: YithWishlistConfig, swrOptions?: SWRConfiguration<WCWishlist[]>): swr.SWRResponse<WCWishlist[], any, SWRConfiguration<WCWishlist[], any, swr.BareFetcher<WCWishlist[]>> | undefined>;
145
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
146
 
147
+ declare function useTIWishlistsByUser(config: TIWishlistConfig, userId: number, swrOptions?: SWRConfiguration<TIWishlist[]>): swr.SWRResponse<TIWishlist[], any, SWRConfiguration<TIWishlist[], any, swr.BareFetcher<TIWishlist[]>> | undefined>;
148
+ declare function useTIWishlistByShareKey(config: TIWishlistConfig, shareKey: string | null | undefined, swrOptions?: SWRConfiguration<TIWishlist>): swr.SWRResponse<TIWishlist, any, SWRConfiguration<TIWishlist, any, swr.BareFetcher<TIWishlist>> | undefined>;
149
+ declare function useTIWishlistProducts(config: TIWishlistConfig, shareKey: string | null | undefined, params?: GetTIWishlistProductsParams, swrOptions?: SWRConfiguration<TIWishlistItem[]>): swr.SWRResponse<TIWishlistItem[], any, SWRConfiguration<TIWishlistItem[], any, swr.BareFetcher<TIWishlistItem[]>> | undefined>;
150
+
147
151
  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>;
148
152
  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>;
149
153
  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>;
@@ -163,4 +167,4 @@ type CF7SubmitArg = {
163
167
  };
164
168
  declare function useCF7Submit(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<CF7SubmissionResponse, Error, string, CF7SubmitArg>;
165
169
 
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 };
170
+ 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, useTIWishlistByShareKey, useTIWishlistProducts, useTIWishlistsByUser, 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, 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';
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, T as TIWishlistConfig, l as TIWishlist, m as GetTIWishlistProductsParams, n as TIWishlistItem, o as GQLPost, p as GQLPostFilter, q as GQLConnection, r as WPULikeStatsParams, s as WPULikeStats, t as WPULikeStatus, u as WPULikeVoteResponse, v as WPULikeCheckParams, w as WPULikeCheckResponse, x as CF7SubmissionResponse } from '../types-DmNIXJNR.js';
4
4
  import * as swr_mutation from 'swr/mutation';
5
5
  import * as swr from 'swr';
6
6
  import { SWRConfiguration } from 'swr';
@@ -144,6 +144,10 @@ declare function useCustomer(): CustomerContextValue;
144
144
  declare function useWishlists(config: YithWishlistConfig, swrOptions?: SWRConfiguration<WCWishlist[]>): swr.SWRResponse<WCWishlist[], any, SWRConfiguration<WCWishlist[], any, swr.BareFetcher<WCWishlist[]>> | undefined>;
145
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
146
 
147
+ declare function useTIWishlistsByUser(config: TIWishlistConfig, userId: number, swrOptions?: SWRConfiguration<TIWishlist[]>): swr.SWRResponse<TIWishlist[], any, SWRConfiguration<TIWishlist[], any, swr.BareFetcher<TIWishlist[]>> | undefined>;
148
+ declare function useTIWishlistByShareKey(config: TIWishlistConfig, shareKey: string | null | undefined, swrOptions?: SWRConfiguration<TIWishlist>): swr.SWRResponse<TIWishlist, any, SWRConfiguration<TIWishlist, any, swr.BareFetcher<TIWishlist>> | undefined>;
149
+ declare function useTIWishlistProducts(config: TIWishlistConfig, shareKey: string | null | undefined, params?: GetTIWishlistProductsParams, swrOptions?: SWRConfiguration<TIWishlistItem[]>): swr.SWRResponse<TIWishlistItem[], any, SWRConfiguration<TIWishlistItem[], any, swr.BareFetcher<TIWishlistItem[]>> | undefined>;
150
+
147
151
  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>;
148
152
  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>;
149
153
  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>;
@@ -163,4 +167,4 @@ type CF7SubmitArg = {
163
167
  };
164
168
  declare function useCF7Submit(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<CF7SubmissionResponse, Error, string, CF7SubmitArg>;
165
169
 
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 };
170
+ 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, useTIWishlistByShareKey, useTIWishlistProducts, useTIWishlistsByUser, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats, useWishlist, useWishlists };
@@ -1428,6 +1428,145 @@ function useWishlist(config, wishlistToken, swrOptions) {
1428
1428
  );
1429
1429
  }
1430
1430
 
1431
+ // src/integrations/restApi/woocommerce/ti_wishlist/fetcher.ts
1432
+ var USER_AGENT5 = "NextWordpress TI Wishlist Client";
1433
+ var DEFAULT_CACHE_TTL3 = 3600;
1434
+ var TIWishlistError = class extends Error {
1435
+ constructor(code, status, url, message) {
1436
+ super(message);
1437
+ __publicField(this, "code", code);
1438
+ __publicField(this, "status", status);
1439
+ __publicField(this, "url", url);
1440
+ this.name = "TIWishlistError";
1441
+ }
1442
+ };
1443
+ function resolveTIErrorCode(status) {
1444
+ if (status === 401) return ErrorCode.WOO_UNAUTHORIZED;
1445
+ if (status === 403) return ErrorCode.WOO_FORBIDDEN;
1446
+ if (status === 404) return ErrorCode.WOO_WISHLIST_NOT_FOUND;
1447
+ return ErrorCode.WOO_REQUEST_FAILED;
1448
+ }
1449
+ function createTIWishlistFetcher(config) {
1450
+ const cacheTTL = config.cacheTTL ?? DEFAULT_CACHE_TTL3;
1451
+ function buildUrl2(path) {
1452
+ const base = typeof window !== "undefined" && config.clientURL ? config.clientURL : config.serverURL;
1453
+ return `${base}${path}`;
1454
+ }
1455
+ function authHeaders() {
1456
+ return {
1457
+ "User-Agent": USER_AGENT5,
1458
+ "Content-Type": "application/json",
1459
+ Authorization: `Bearer ${config.token}`
1460
+ };
1461
+ }
1462
+ async function throwTIError(response, url) {
1463
+ const errorCode = resolveTIErrorCode(response.status);
1464
+ throw new TIWishlistError(
1465
+ errorCode,
1466
+ response.status,
1467
+ url,
1468
+ resolveMessage(errorCode, config.errorMessages)
1469
+ );
1470
+ }
1471
+ async function tiFetch(path, tags = ["ti-wishlist"], options) {
1472
+ const url = buildUrl2(path);
1473
+ const isMutation = options?.method && options.method !== "GET";
1474
+ const response = await fetch(url, {
1475
+ ...options,
1476
+ headers: {
1477
+ ...authHeaders(),
1478
+ ...options?.headers
1479
+ },
1480
+ next: isMutation ? void 0 : { tags, revalidate: cacheTTL }
1481
+ });
1482
+ if (!response.ok) {
1483
+ await throwTIError(response, url);
1484
+ }
1485
+ return response.json();
1486
+ }
1487
+ async function tiFetchGraceful(path, fallback, tags = ["ti-wishlist"]) {
1488
+ try {
1489
+ return await tiFetch(path, tags);
1490
+ } catch (err) {
1491
+ console.warn(`TI Wishlist fetch failed for ${path}`, err);
1492
+ return fallback;
1493
+ }
1494
+ }
1495
+ async function tiMutate(path, body, method = "POST") {
1496
+ return tiFetch(path, ["ti-wishlist"], {
1497
+ method,
1498
+ body: JSON.stringify(body)
1499
+ });
1500
+ }
1501
+ return { tiFetch, tiFetchGraceful, tiMutate };
1502
+ }
1503
+
1504
+ // src/integrations/restApi/woocommerce/ti_wishlist/queries.ts
1505
+ var BASE2 = "/wp-json/wc/v3/wishlist";
1506
+ function createTIWishlistQueries(fetcher) {
1507
+ const { tiFetch, tiFetchGraceful } = fetcher;
1508
+ async function getWishlistsByUser(userId) {
1509
+ return tiFetchGraceful(
1510
+ `${BASE2}/get_by_user/${userId}`,
1511
+ [],
1512
+ ["ti-wishlist", `ti-wishlists-user-${userId}`]
1513
+ );
1514
+ }
1515
+ async function getWishlistByShareKey(shareKey) {
1516
+ return tiFetch(`${BASE2}/get_by_share_key/${shareKey}`, [
1517
+ "ti-wishlist",
1518
+ `ti-wishlist-${shareKey}`
1519
+ ]);
1520
+ }
1521
+ async function getWishlistProducts(shareKey, params) {
1522
+ const query = new URLSearchParams();
1523
+ if (params?.count != null) query.set("count", String(params.count));
1524
+ if (params?.offset != null) query.set("offset", String(params.offset));
1525
+ if (params?.order != null) query.set("order", params.order);
1526
+ const qs = query.toString() ? `?${query.toString()}` : "";
1527
+ return tiFetch(`${BASE2}/${shareKey}/get_products${qs}`, [
1528
+ "ti-wishlist",
1529
+ `ti-wishlist-products-${shareKey}`
1530
+ ]);
1531
+ }
1532
+ return { getWishlistsByUser, getWishlistByShareKey, getWishlistProducts };
1533
+ }
1534
+
1535
+ // src/hooks/woocommerce/useTIWishlist.ts
1536
+ function useTIWishlistsByUser(config, userId, swrOptions) {
1537
+ const key = ["ti-wishlists", config.serverURL, config.token, userId];
1538
+ return useSWR2(
1539
+ key,
1540
+ () => {
1541
+ const fetcher = createTIWishlistFetcher(config);
1542
+ return createTIWishlistQueries(fetcher).getWishlistsByUser(userId);
1543
+ },
1544
+ swrOptions
1545
+ );
1546
+ }
1547
+ function useTIWishlistByShareKey(config, shareKey, swrOptions) {
1548
+ const key = shareKey != null ? ["ti-wishlist", config.serverURL, config.token, shareKey] : null;
1549
+ return useSWR2(
1550
+ key,
1551
+ () => {
1552
+ const fetcher = createTIWishlistFetcher(config);
1553
+ return createTIWishlistQueries(fetcher).getWishlistByShareKey(shareKey);
1554
+ },
1555
+ swrOptions
1556
+ );
1557
+ }
1558
+ function useTIWishlistProducts(config, shareKey, params, swrOptions) {
1559
+ const key = shareKey != null ? ["ti-wishlist-products", config.serverURL, config.token, shareKey, params] : null;
1560
+ return useSWR2(
1561
+ key,
1562
+ () => {
1563
+ const fetcher = createTIWishlistFetcher(config);
1564
+ return createTIWishlistQueries(fetcher).getWishlistProducts(shareKey, params);
1565
+ },
1566
+ swrOptions
1567
+ );
1568
+ }
1569
+
1431
1570
  // src/integrations/wpGraphQL/core/posts/queries.ts
1432
1571
  var DEFAULT_FIRST = 10;
1433
1572
  var BATCH_FIRST = 100;
@@ -1745,6 +1884,6 @@ function useCF7Submit(config) {
1745
1884
  );
1746
1885
  }
1747
1886
 
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 };
1887
+ 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, useTIWishlistByShareKey, useTIWishlistProducts, useTIWishlistsByUser, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats, useWishlist, useWishlists };
1749
1888
  //# sourceMappingURL=index.js.map
1750
1889
  //# sourceMappingURL=index.js.map