@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.cjs
CHANGED
|
@@ -44,6 +44,8 @@ var ErrorCode = {
|
|
|
44
44
|
WOO_REVIEW_NOT_FOUND: "WOO_REVIEW_NOT_FOUND",
|
|
45
45
|
WOO_WEBHOOK_NOT_FOUND: "WOO_WEBHOOK_NOT_FOUND",
|
|
46
46
|
WOO_SHIPPING_ZONE_NOT_FOUND: "WOO_SHIPPING_ZONE_NOT_FOUND",
|
|
47
|
+
WOO_WISHLIST_NOT_FOUND: "WOO_WISHLIST_NOT_FOUND",
|
|
48
|
+
WOO_WISHLIST_ITEM_NOT_FOUND: "WOO_WISHLIST_ITEM_NOT_FOUND",
|
|
47
49
|
// Auth
|
|
48
50
|
AUTH_JWT_FAILED: "AUTH_JWT_FAILED",
|
|
49
51
|
AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID",
|
|
@@ -76,6 +78,8 @@ var defaultMessages = {
|
|
|
76
78
|
WOO_REVIEW_NOT_FOUND: "Product review not found",
|
|
77
79
|
WOO_WEBHOOK_NOT_FOUND: "Webhook not found",
|
|
78
80
|
WOO_SHIPPING_ZONE_NOT_FOUND: "Shipping zone not found",
|
|
81
|
+
WOO_WISHLIST_NOT_FOUND: "Wishlist not found",
|
|
82
|
+
WOO_WISHLIST_ITEM_NOT_FOUND: "Wishlist item not found",
|
|
79
83
|
AUTH_JWT_FAILED: "JWT authentication failed",
|
|
80
84
|
AUTH_CREDENTIALS_INVALID: "Invalid credentials",
|
|
81
85
|
AUTH_TOKEN_INVALID: "JWT token is invalid or expired",
|
|
@@ -366,44 +370,6 @@ function useResetUserPassword(config) {
|
|
|
366
370
|
}
|
|
367
371
|
);
|
|
368
372
|
}
|
|
369
|
-
function readConsentFromDocument(cookieName) {
|
|
370
|
-
if (typeof document === "undefined") return null;
|
|
371
|
-
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
|
|
372
|
-
if (!match) return null;
|
|
373
|
-
if (match[1] === "1") return { necessary: true, analytics: true, marketing: true };
|
|
374
|
-
try {
|
|
375
|
-
const parsed = JSON.parse(decodeURIComponent(match[1]));
|
|
376
|
-
if (typeof parsed !== "object" || parsed === null) return null;
|
|
377
|
-
return parsed;
|
|
378
|
-
} catch {
|
|
379
|
-
return null;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
function useCookieConsent(consentPath = "/api/cookie-consent", cookieName = "cookie_notice_accepted") {
|
|
383
|
-
const [consent, setConsentState] = react.useState(null);
|
|
384
|
-
const [isLoaded, setIsLoaded] = react.useState(false);
|
|
385
|
-
react.useEffect(() => {
|
|
386
|
-
setConsentState(readConsentFromDocument(cookieName));
|
|
387
|
-
setIsLoaded(true);
|
|
388
|
-
}, [cookieName]);
|
|
389
|
-
const setConsent = react.useCallback(
|
|
390
|
-
async (categories) => {
|
|
391
|
-
const res = await fetch(consentPath, {
|
|
392
|
-
method: "POST",
|
|
393
|
-
headers: { "Content-Type": "application/json" },
|
|
394
|
-
body: JSON.stringify(categories)
|
|
395
|
-
});
|
|
396
|
-
const data = await res.json();
|
|
397
|
-
setConsentState(data);
|
|
398
|
-
},
|
|
399
|
-
[consentPath]
|
|
400
|
-
);
|
|
401
|
-
const clearConsent = react.useCallback(async () => {
|
|
402
|
-
await fetch(consentPath, { method: "DELETE" });
|
|
403
|
-
setConsentState(null);
|
|
404
|
-
}, [consentPath]);
|
|
405
|
-
return { consent, isLoaded, setConsent, clearConsent };
|
|
406
|
-
}
|
|
407
373
|
|
|
408
374
|
// src/integrations/restApi/core/client/types.ts
|
|
409
375
|
var WordPressAPIError = class extends Error {
|
|
@@ -528,6 +494,88 @@ function createFetcher(config) {
|
|
|
528
494
|
return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate, wpUpload };
|
|
529
495
|
}
|
|
530
496
|
|
|
497
|
+
// src/integrations/restApi/core/mutations/passwordReset/mutations.ts
|
|
498
|
+
function createPasswordResetMutations2(fetcher) {
|
|
499
|
+
const { wpMutate } = fetcher;
|
|
500
|
+
async function sendPasswordResetEmail(input) {
|
|
501
|
+
return wpMutate(
|
|
502
|
+
"/wp-json/wp/v2/users/lost-password",
|
|
503
|
+
input,
|
|
504
|
+
"POST"
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
async function resetUserPassword(input) {
|
|
508
|
+
return wpMutate(
|
|
509
|
+
"/wp-json/wp/v2/users/reset-password",
|
|
510
|
+
input,
|
|
511
|
+
"POST"
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
return { sendPasswordResetEmail, resetUserPassword };
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// src/hooks/auth/useSendPasswordResetEmailRest.ts
|
|
518
|
+
function useSendPasswordResetEmailRest(config) {
|
|
519
|
+
return useSWRMutation__default.default(
|
|
520
|
+
`send-password-reset-rest:${config.serverURL}`,
|
|
521
|
+
async (_, { arg }) => {
|
|
522
|
+
return createPasswordResetMutations2(createFetcher(config)).sendPasswordResetEmail({
|
|
523
|
+
username: arg.username
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
function useResetUserPasswordRest(config) {
|
|
529
|
+
return useSWRMutation__default.default(
|
|
530
|
+
`reset-user-password-rest:${config.serverURL}`,
|
|
531
|
+
async (_, { arg }) => {
|
|
532
|
+
return createPasswordResetMutations2(createFetcher(config)).resetUserPassword({
|
|
533
|
+
key: arg.key,
|
|
534
|
+
login: arg.login,
|
|
535
|
+
password: arg.password
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
function readConsentFromDocument(cookieName) {
|
|
541
|
+
if (typeof document === "undefined") return null;
|
|
542
|
+
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
|
|
543
|
+
if (!match) return null;
|
|
544
|
+
if (match[1] === "1") return { necessary: true, analytics: true, marketing: true };
|
|
545
|
+
try {
|
|
546
|
+
const parsed = JSON.parse(decodeURIComponent(match[1]));
|
|
547
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
548
|
+
return parsed;
|
|
549
|
+
} catch {
|
|
550
|
+
return null;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
function useCookieConsent(consentPath = "/api/cookie-consent", cookieName = "cookie_notice_accepted") {
|
|
554
|
+
const [consent, setConsentState] = react.useState(null);
|
|
555
|
+
const [isLoaded, setIsLoaded] = react.useState(false);
|
|
556
|
+
react.useEffect(() => {
|
|
557
|
+
setConsentState(readConsentFromDocument(cookieName));
|
|
558
|
+
setIsLoaded(true);
|
|
559
|
+
}, [cookieName]);
|
|
560
|
+
const setConsent = react.useCallback(
|
|
561
|
+
async (categories) => {
|
|
562
|
+
const res = await fetch(consentPath, {
|
|
563
|
+
method: "POST",
|
|
564
|
+
headers: { "Content-Type": "application/json" },
|
|
565
|
+
body: JSON.stringify(categories)
|
|
566
|
+
});
|
|
567
|
+
const data = await res.json();
|
|
568
|
+
setConsentState(data);
|
|
569
|
+
},
|
|
570
|
+
[consentPath]
|
|
571
|
+
);
|
|
572
|
+
const clearConsent = react.useCallback(async () => {
|
|
573
|
+
await fetch(consentPath, { method: "DELETE" });
|
|
574
|
+
setConsentState(null);
|
|
575
|
+
}, [consentPath]);
|
|
576
|
+
return { consent, isLoaded, setConsent, clearConsent };
|
|
577
|
+
}
|
|
578
|
+
|
|
531
579
|
// src/integrations/restApi/core/posts/queries.ts
|
|
532
580
|
function createPostsQueries(fetcher) {
|
|
533
581
|
const { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful } = fetcher;
|
|
@@ -1267,6 +1315,126 @@ function useCustomer() {
|
|
|
1267
1315
|
return ctx;
|
|
1268
1316
|
}
|
|
1269
1317
|
|
|
1318
|
+
// src/integrations/restApi/woocommerce/wishlist/fetcher.ts
|
|
1319
|
+
var USER_AGENT4 = "NextWordpress YITH Wishlist Client";
|
|
1320
|
+
var DEFAULT_CACHE_TTL2 = 3600;
|
|
1321
|
+
var YithWishlistError = class extends Error {
|
|
1322
|
+
constructor(code, status, url, message, upstreamCode, upstreamMessage) {
|
|
1323
|
+
super(message);
|
|
1324
|
+
__publicField(this, "code", code);
|
|
1325
|
+
__publicField(this, "status", status);
|
|
1326
|
+
__publicField(this, "url", url);
|
|
1327
|
+
__publicField(this, "upstreamCode", upstreamCode);
|
|
1328
|
+
__publicField(this, "upstreamMessage", upstreamMessage);
|
|
1329
|
+
this.name = "YithWishlistError";
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
function resolveYithErrorCode(status, upstreamCode) {
|
|
1333
|
+
if (status === 401) return ErrorCode.WOO_UNAUTHORIZED;
|
|
1334
|
+
if (status === 403) return ErrorCode.WOO_FORBIDDEN;
|
|
1335
|
+
if (status === 404) {
|
|
1336
|
+
if (upstreamCode === "yith_wcwl_wishlist_not_found") return ErrorCode.WOO_WISHLIST_NOT_FOUND;
|
|
1337
|
+
if (upstreamCode === "yith_wcwl_wishlist_item_not_found")
|
|
1338
|
+
return ErrorCode.WOO_WISHLIST_ITEM_NOT_FOUND;
|
|
1339
|
+
return ErrorCode.WOO_NOT_FOUND;
|
|
1340
|
+
}
|
|
1341
|
+
return ErrorCode.WOO_REQUEST_FAILED;
|
|
1342
|
+
}
|
|
1343
|
+
function createYithWishlistFetcher(config) {
|
|
1344
|
+
const cacheTTL = config.cacheTTL ?? DEFAULT_CACHE_TTL2;
|
|
1345
|
+
function buildUrl2(path) {
|
|
1346
|
+
const base = typeof window !== "undefined" && config.clientURL ? config.clientURL : config.serverURL;
|
|
1347
|
+
return `${base}${path}`;
|
|
1348
|
+
}
|
|
1349
|
+
function authHeaders() {
|
|
1350
|
+
return {
|
|
1351
|
+
"User-Agent": USER_AGENT4,
|
|
1352
|
+
"Content-Type": "application/json",
|
|
1353
|
+
Authorization: `Bearer ${config.token}`
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
async function throwYithError(response, url) {
|
|
1357
|
+
const body = await response.json().catch(() => ({}));
|
|
1358
|
+
const errorCode = resolveYithErrorCode(response.status, body.code);
|
|
1359
|
+
throw new YithWishlistError(
|
|
1360
|
+
errorCode,
|
|
1361
|
+
response.status,
|
|
1362
|
+
url,
|
|
1363
|
+
resolveMessage(errorCode, config.errorMessages),
|
|
1364
|
+
body.code,
|
|
1365
|
+
body.message
|
|
1366
|
+
);
|
|
1367
|
+
}
|
|
1368
|
+
async function yithFetch(path, tags = ["yith-wishlist"], options) {
|
|
1369
|
+
const url = buildUrl2(path);
|
|
1370
|
+
const isMutation = options?.method && options.method !== "GET";
|
|
1371
|
+
const response = await fetch(url, {
|
|
1372
|
+
...options,
|
|
1373
|
+
headers: {
|
|
1374
|
+
...authHeaders(),
|
|
1375
|
+
...options?.headers
|
|
1376
|
+
},
|
|
1377
|
+
next: isMutation ? void 0 : { tags, revalidate: cacheTTL }
|
|
1378
|
+
});
|
|
1379
|
+
if (!response.ok) {
|
|
1380
|
+
await throwYithError(response, url);
|
|
1381
|
+
}
|
|
1382
|
+
return response.json();
|
|
1383
|
+
}
|
|
1384
|
+
async function yithFetchGraceful(path, fallback, tags = ["yith-wishlist"]) {
|
|
1385
|
+
try {
|
|
1386
|
+
return await yithFetch(path, tags);
|
|
1387
|
+
} catch (err) {
|
|
1388
|
+
console.warn(`YITH Wishlist fetch failed for ${path}`, err);
|
|
1389
|
+
return fallback;
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
async function yithMutate(path, body, method = "POST") {
|
|
1393
|
+
return yithFetch(path, ["yith-wishlist"], {
|
|
1394
|
+
method,
|
|
1395
|
+
body: JSON.stringify(body)
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
return { yithFetch, yithFetchGraceful, yithMutate };
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
// src/integrations/restApi/woocommerce/wishlist/queries.ts
|
|
1402
|
+
var BASE = "/wp-json/yith/wishlist/v1/wishlists";
|
|
1403
|
+
function createWishlistQueries(fetcher) {
|
|
1404
|
+
const { yithFetch, yithFetchGraceful } = fetcher;
|
|
1405
|
+
async function getWishlists() {
|
|
1406
|
+
return yithFetchGraceful(BASE, [], ["yith-wishlist", "wishlists"]);
|
|
1407
|
+
}
|
|
1408
|
+
async function getWishlistByToken(token) {
|
|
1409
|
+
return yithFetch(`${BASE}/${token}`, ["yith-wishlist", "wishlists", `wishlist-${token}`]);
|
|
1410
|
+
}
|
|
1411
|
+
return { getWishlists, getWishlistByToken };
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
// src/hooks/woocommerce/useWishlist.ts
|
|
1415
|
+
function useWishlists(config, swrOptions) {
|
|
1416
|
+
const key = ["yith-wishlists", config.serverURL, config.token];
|
|
1417
|
+
return useSWR2__default.default(
|
|
1418
|
+
key,
|
|
1419
|
+
() => {
|
|
1420
|
+
const fetcher = createYithWishlistFetcher(config);
|
|
1421
|
+
return createWishlistQueries(fetcher).getWishlists();
|
|
1422
|
+
},
|
|
1423
|
+
swrOptions
|
|
1424
|
+
);
|
|
1425
|
+
}
|
|
1426
|
+
function useWishlist(config, wishlistToken, swrOptions) {
|
|
1427
|
+
const key = wishlistToken != null ? ["yith-wishlist", config.serverURL, config.token, wishlistToken] : null;
|
|
1428
|
+
return useSWR2__default.default(
|
|
1429
|
+
key,
|
|
1430
|
+
() => {
|
|
1431
|
+
const fetcher = createYithWishlistFetcher(config);
|
|
1432
|
+
return createWishlistQueries(fetcher).getWishlistByToken(wishlistToken);
|
|
1433
|
+
},
|
|
1434
|
+
swrOptions
|
|
1435
|
+
);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1270
1438
|
// src/integrations/wpGraphQL/core/posts/queries.ts
|
|
1271
1439
|
var DEFAULT_FIRST = 10;
|
|
1272
1440
|
var BATCH_FIRST = 100;
|
|
@@ -1605,10 +1773,14 @@ exports.useProductBySlug = useProductBySlug;
|
|
|
1605
1773
|
exports.useProducts = useProducts;
|
|
1606
1774
|
exports.useProductsPaginated = useProductsPaginated;
|
|
1607
1775
|
exports.useResetUserPassword = useResetUserPassword;
|
|
1776
|
+
exports.useResetUserPasswordRest = useResetUserPasswordRest;
|
|
1608
1777
|
exports.useSendPasswordResetEmail = useSendPasswordResetEmail;
|
|
1778
|
+
exports.useSendPasswordResetEmailRest = useSendPasswordResetEmailRest;
|
|
1609
1779
|
exports.useWPGraphQL = useWPGraphQL;
|
|
1610
1780
|
exports.useWPULike = useWPULike;
|
|
1611
1781
|
exports.useWPULikeCheck = useWPULikeCheck;
|
|
1612
1782
|
exports.useWPULikeStats = useWPULikeStats;
|
|
1783
|
+
exports.useWishlist = useWishlist;
|
|
1784
|
+
exports.useWishlists = useWishlists;
|
|
1613
1785
|
//# sourceMappingURL=index.cjs.map
|
|
1614
1786
|
//# sourceMappingURL=index.cjs.map
|