@szymonpiatek/nextwordpress 0.0.16 → 0.0.18

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.
@@ -312,9 +312,6 @@ var GQL_SEND_PASSWORD_RESET_EMAIL = `
312
312
  mutation SendPasswordResetEmail($input: SendPasswordResetEmailInput!) {
313
313
  sendPasswordResetEmail(input: $input) {
314
314
  success
315
- user {
316
- email
317
- }
318
315
  }
319
316
  }
320
317
  `;
@@ -333,7 +330,11 @@ function createPasswordResetMutations(fetcher) {
333
330
  const { gqlMutate } = fetcher;
334
331
  async function sendPasswordResetEmail(input) {
335
332
  const data = await gqlMutate(GQL_SEND_PASSWORD_RESET_EMAIL, { input });
336
- return data.sendPasswordResetEmail;
333
+ const result = data.sendPasswordResetEmail;
334
+ if (!result.success) {
335
+ throw new WPGraphQLError(ErrorCode.GQL_ERRORS_IN_RESPONSE, 200, "sendPasswordResetEmail", "User not found");
336
+ }
337
+ return result;
337
338
  }
338
339
  async function resetUserPassword(input) {
339
340
  const data = await gqlMutate(GQL_RESET_USER_PASSWORD, { input });
@@ -365,44 +366,6 @@ function useResetUserPassword(config) {
365
366
  }
366
367
  );
367
368
  }
368
- function readConsentFromDocument(cookieName) {
369
- if (typeof document === "undefined") return null;
370
- const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
371
- if (!match) return null;
372
- if (match[1] === "1") return { necessary: true, analytics: true, marketing: true };
373
- try {
374
- const parsed = JSON.parse(decodeURIComponent(match[1]));
375
- if (typeof parsed !== "object" || parsed === null) return null;
376
- return parsed;
377
- } catch {
378
- return null;
379
- }
380
- }
381
- function useCookieConsent(consentPath = "/api/cookie-consent", cookieName = "cookie_notice_accepted") {
382
- const [consent, setConsentState] = react.useState(null);
383
- const [isLoaded, setIsLoaded] = react.useState(false);
384
- react.useEffect(() => {
385
- setConsentState(readConsentFromDocument(cookieName));
386
- setIsLoaded(true);
387
- }, [cookieName]);
388
- const setConsent = react.useCallback(
389
- async (categories) => {
390
- const res = await fetch(consentPath, {
391
- method: "POST",
392
- headers: { "Content-Type": "application/json" },
393
- body: JSON.stringify(categories)
394
- });
395
- const data = await res.json();
396
- setConsentState(data);
397
- },
398
- [consentPath]
399
- );
400
- const clearConsent = react.useCallback(async () => {
401
- await fetch(consentPath, { method: "DELETE" });
402
- setConsentState(null);
403
- }, [consentPath]);
404
- return { consent, isLoaded, setConsent, clearConsent };
405
- }
406
369
 
407
370
  // src/integrations/restApi/core/client/types.ts
408
371
  var WordPressAPIError = class extends Error {
@@ -527,6 +490,88 @@ function createFetcher(config) {
527
490
  return { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful, wpMutate, wpUpload };
528
491
  }
529
492
 
493
+ // src/integrations/restApi/core/mutations/passwordReset/mutations.ts
494
+ function createPasswordResetMutations2(fetcher) {
495
+ const { wpMutate } = fetcher;
496
+ async function sendPasswordResetEmail(input) {
497
+ return wpMutate(
498
+ "/wp-json/wp/v2/users/lost-password",
499
+ input,
500
+ "POST"
501
+ );
502
+ }
503
+ async function resetUserPassword(input) {
504
+ return wpMutate(
505
+ "/wp-json/wp/v2/users/reset-password",
506
+ input,
507
+ "POST"
508
+ );
509
+ }
510
+ return { sendPasswordResetEmail, resetUserPassword };
511
+ }
512
+
513
+ // src/hooks/auth/useSendPasswordResetEmailRest.ts
514
+ function useSendPasswordResetEmailRest(config) {
515
+ return useSWRMutation__default.default(
516
+ `send-password-reset-rest:${config.serverURL}`,
517
+ async (_, { arg }) => {
518
+ return createPasswordResetMutations2(createFetcher(config)).sendPasswordResetEmail({
519
+ username: arg.username
520
+ });
521
+ }
522
+ );
523
+ }
524
+ function useResetUserPasswordRest(config) {
525
+ return useSWRMutation__default.default(
526
+ `reset-user-password-rest:${config.serverURL}`,
527
+ async (_, { arg }) => {
528
+ return createPasswordResetMutations2(createFetcher(config)).resetUserPassword({
529
+ key: arg.key,
530
+ login: arg.login,
531
+ password: arg.password
532
+ });
533
+ }
534
+ );
535
+ }
536
+ function readConsentFromDocument(cookieName) {
537
+ if (typeof document === "undefined") return null;
538
+ const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
539
+ if (!match) return null;
540
+ if (match[1] === "1") return { necessary: true, analytics: true, marketing: true };
541
+ try {
542
+ const parsed = JSON.parse(decodeURIComponent(match[1]));
543
+ if (typeof parsed !== "object" || parsed === null) return null;
544
+ return parsed;
545
+ } catch {
546
+ return null;
547
+ }
548
+ }
549
+ function useCookieConsent(consentPath = "/api/cookie-consent", cookieName = "cookie_notice_accepted") {
550
+ const [consent, setConsentState] = react.useState(null);
551
+ const [isLoaded, setIsLoaded] = react.useState(false);
552
+ react.useEffect(() => {
553
+ setConsentState(readConsentFromDocument(cookieName));
554
+ setIsLoaded(true);
555
+ }, [cookieName]);
556
+ const setConsent = react.useCallback(
557
+ async (categories) => {
558
+ const res = await fetch(consentPath, {
559
+ method: "POST",
560
+ headers: { "Content-Type": "application/json" },
561
+ body: JSON.stringify(categories)
562
+ });
563
+ const data = await res.json();
564
+ setConsentState(data);
565
+ },
566
+ [consentPath]
567
+ );
568
+ const clearConsent = react.useCallback(async () => {
569
+ await fetch(consentPath, { method: "DELETE" });
570
+ setConsentState(null);
571
+ }, [consentPath]);
572
+ return { consent, isLoaded, setConsent, clearConsent };
573
+ }
574
+
530
575
  // src/integrations/restApi/core/posts/queries.ts
531
576
  function createPostsQueries(fetcher) {
532
577
  const { wpFetch, wpFetchGraceful, wpFetchPaginated, wpFetchPaginatedGraceful } = fetcher;
@@ -1604,7 +1649,9 @@ exports.useProductBySlug = useProductBySlug;
1604
1649
  exports.useProducts = useProducts;
1605
1650
  exports.useProductsPaginated = useProductsPaginated;
1606
1651
  exports.useResetUserPassword = useResetUserPassword;
1652
+ exports.useResetUserPasswordRest = useResetUserPasswordRest;
1607
1653
  exports.useSendPasswordResetEmail = useSendPasswordResetEmail;
1654
+ exports.useSendPasswordResetEmailRest = useSendPasswordResetEmailRest;
1608
1655
  exports.useWPGraphQL = useWPGraphQL;
1609
1656
  exports.useWPULike = useWPULike;
1610
1657
  exports.useWPULikeCheck = useWPULikeCheck;