@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.
- package/dist/client/index.cjs +210 -38
- 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 +207 -39
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +210 -38
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +19 -4
- package/dist/hooks/index.d.ts +19 -4
- package/dist/hooks/index.js +207 -39
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +174 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -12
- package/dist/index.d.ts +45 -12
- package/dist/index.js +171 -12
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +174 -11
- 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 +171 -12
- package/dist/server/index.js.map +1 -1
- package/dist/{types-DVzJO3P-.d.cts → types-DUmH-vcl.d.cts} +71 -16
- package/dist/{types-DVzJO3P-.d.ts → types-DUmH-vcl.d.ts} +71 -16
- package/package.json +1 -1
package/dist/client/index.d.cts
CHANGED
|
@@ -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, useSendPasswordResetEmail, 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, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats, useWishlist, useWishlists } from '../hooks/index.cjs';
|
|
2
2
|
import 'react';
|
|
3
|
-
import '../types-
|
|
3
|
+
import '../types-DUmH-vcl.cjs';
|
|
4
4
|
import 'swr/mutation';
|
|
5
5
|
import 'swr';
|
package/dist/client/index.d.ts
CHANGED
|
@@ -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, useSendPasswordResetEmail, 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, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats, useWishlist, useWishlists } from '../hooks/index.js';
|
|
2
2
|
import 'react';
|
|
3
|
-
import '../types-
|
|
3
|
+
import '../types-DUmH-vcl.js';
|
|
4
4
|
import 'swr/mutation';
|
|
5
5
|
import 'swr';
|
package/dist/client/index.js
CHANGED
|
@@ -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
|