@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.
@@ -1,5 +1,5 @@
1
- export { AuthContextValue, AuthProvider, AuthUser, CartAction, CartContextValue, CartItem, CartProvider, CheckoutOptions, 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 } from '../hooks/index.cjs';
1
+ export { AuthContextValue, AuthProvider, AuthUser, CartAction, CartContextValue, CartItem, CartProvider, CheckoutOptions, 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 } from '../hooks/index.cjs';
2
2
  import 'react';
3
- import '../types-CM3v08Fh.cjs';
3
+ import '../types-DmNIXJNR.cjs';
4
4
  import 'swr/mutation';
5
5
  import 'swr';
@@ -1,5 +1,5 @@
1
- export { AuthContextValue, AuthProvider, AuthUser, CartAction, CartContextValue, CartItem, CartProvider, CheckoutOptions, 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 } from '../hooks/index.js';
1
+ export { AuthContextValue, AuthProvider, AuthUser, CartAction, CartContextValue, CartItem, CartProvider, CheckoutOptions, 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 } from '../hooks/index.js';
2
2
  import 'react';
3
- import '../types-CM3v08Fh.js';
3
+ import '../types-DmNIXJNR.js';
4
4
  import 'swr/mutation';
5
5
  import 'swr';
@@ -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",
@@ -1304,6 +1308,265 @@ function useCustomer() {
1304
1308
  return ctx;
1305
1309
  }
1306
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
+
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
+
1307
1570
  // src/integrations/wpGraphQL/core/posts/queries.ts
1308
1571
  var DEFAULT_FIRST = 10;
1309
1572
  var BATCH_FIRST = 100;
@@ -1621,6 +1884,6 @@ function useCF7Submit(config) {
1621
1884
  );
1622
1885
  }
1623
1886
 
1624
- 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 };
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 };
1625
1888
  //# sourceMappingURL=index.js.map
1626
1889
  //# sourceMappingURL=index.js.map