@szymonpiatek/nextwordpress 0.0.13 → 0.0.15

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,8 +1,9 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { J as JwtAuthCredentials, N as NextWordpressConfig, C as CookieConsentCategories, P as Post, W as WordPressResponse, a as WooCommerceConfig, b as WCProduct, c as WCProductFilterParams, d as WooCommerceResponse, e as WCCreateOrderInput, f as WCOrder, g as WCCustomer, U as UpdateCustomerInput, h as WPGraphQLConfig, G as GQLPost, i as GQLPostFilter, j as GQLConnection, k as WPULikeStatsParams, l as WPULikeStats, m as WPULikeStatus, n as WPULikeVoteResponse, o as WPULikeCheckParams, p as WPULikeCheckResponse } from '../types-BELSHjQr.cjs';
3
+ import { J as JwtAuthCredentials, N as NextWordpressConfig, C as CookieConsentCategories, P as Post, W as WordPressResponse, a as WooCommerceConfig, b as WCProduct, c as WCProductFilterParams, d as WooCommerceResponse, e as WCCreateOrderInput, f as WCOrder, g as WCCustomer, U as UpdateCustomerInput, h as WPGraphQLConfig, G as GQLPost, i as GQLPostFilter, j as GQLConnection, k as WPULikeStatsParams, l as WPULikeStats, m as WPULikeStatus, n as WPULikeVoteResponse, o as WPULikeCheckParams, p as WPULikeCheckResponse, q as CF7SubmissionResponse } from '../types-D6rih4G8.cjs';
4
4
  import * as swr from 'swr';
5
5
  import { SWRConfiguration } from 'swr';
6
+ import * as swr_mutation from 'swr/mutation';
6
7
 
7
8
  interface AuthUser {
8
9
  token: string;
@@ -129,4 +130,10 @@ declare function useWPULike(config: NextWordpressConfig, params: WPULikeStatsPar
129
130
  vote: (status: WPULikeStatus, authToken?: string) => Promise<WPULikeVoteResponse>;
130
131
  };
131
132
 
132
- export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
133
+ type CF7SubmitArg = {
134
+ formId: number;
135
+ fields: Record<string, string>;
136
+ };
137
+ declare function useCF7Submit(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<CF7SubmissionResponse, Error, string, CF7SubmitArg>;
138
+
139
+ 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, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
@@ -1,8 +1,9 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { J as JwtAuthCredentials, N as NextWordpressConfig, C as CookieConsentCategories, P as Post, W as WordPressResponse, a as WooCommerceConfig, b as WCProduct, c as WCProductFilterParams, d as WooCommerceResponse, e as WCCreateOrderInput, f as WCOrder, g as WCCustomer, U as UpdateCustomerInput, h as WPGraphQLConfig, G as GQLPost, i as GQLPostFilter, j as GQLConnection, k as WPULikeStatsParams, l as WPULikeStats, m as WPULikeStatus, n as WPULikeVoteResponse, o as WPULikeCheckParams, p as WPULikeCheckResponse } from '../types-BELSHjQr.js';
3
+ import { J as JwtAuthCredentials, N as NextWordpressConfig, C as CookieConsentCategories, P as Post, W as WordPressResponse, a as WooCommerceConfig, b as WCProduct, c as WCProductFilterParams, d as WooCommerceResponse, e as WCCreateOrderInput, f as WCOrder, g as WCCustomer, U as UpdateCustomerInput, h as WPGraphQLConfig, G as GQLPost, i as GQLPostFilter, j as GQLConnection, k as WPULikeStatsParams, l as WPULikeStats, m as WPULikeStatus, n as WPULikeVoteResponse, o as WPULikeCheckParams, p as WPULikeCheckResponse, q as CF7SubmissionResponse } from '../types-D6rih4G8.js';
4
4
  import * as swr from 'swr';
5
5
  import { SWRConfiguration } from 'swr';
6
+ import * as swr_mutation from 'swr/mutation';
6
7
 
7
8
  interface AuthUser {
8
9
  token: string;
@@ -129,4 +130,10 @@ declare function useWPULike(config: NextWordpressConfig, params: WPULikeStatsPar
129
130
  vote: (status: WPULikeStatus, authToken?: string) => Promise<WPULikeVoteResponse>;
130
131
  };
131
132
 
132
- export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
133
+ type CF7SubmitArg = {
134
+ formId: number;
135
+ fields: Record<string, string>;
136
+ };
137
+ declare function useCF7Submit(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<CF7SubmissionResponse, Error, string, CF7SubmitArg>;
138
+
139
+ 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, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
@@ -1,6 +1,7 @@
1
1
  import { createContext, useState, useCallback, useEffect, useContext, useReducer } from 'react';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import useSWR2 from 'swr';
4
+ import useSWRMutation from 'swr/mutation';
4
5
 
5
6
  var __defProp = Object.defineProperty;
6
7
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -39,7 +40,13 @@ var ErrorCode = {
39
40
  // Auth
40
41
  AUTH_JWT_FAILED: "AUTH_JWT_FAILED",
41
42
  AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID",
42
- AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID"
43
+ AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID",
44
+ // Contact Form 7
45
+ CF7_MAIL_SENT: "CF7_MAIL_SENT",
46
+ CF7_MAIL_FAILED: "CF7_MAIL_FAILED",
47
+ CF7_VALIDATION_FAILED: "CF7_VALIDATION_FAILED",
48
+ CF7_SPAM: "CF7_SPAM",
49
+ CF7_ABORTED: "CF7_ABORTED"
43
50
  };
44
51
  var defaultMessages = {
45
52
  WP_REQUEST_FAILED: "WordPress API request failed",
@@ -64,7 +71,12 @@ var defaultMessages = {
64
71
  WOO_SHIPPING_ZONE_NOT_FOUND: "Shipping zone not found",
65
72
  AUTH_JWT_FAILED: "JWT authentication failed",
66
73
  AUTH_CREDENTIALS_INVALID: "Invalid credentials",
67
- AUTH_TOKEN_INVALID: "JWT token is invalid or expired"
74
+ AUTH_TOKEN_INVALID: "JWT token is invalid or expired",
75
+ CF7_MAIL_SENT: "Thank you for your message.",
76
+ CF7_MAIL_FAILED: "There was an error trying to send your message.",
77
+ CF7_VALIDATION_FAILED: "One or more fields have an error. Please check and try again.",
78
+ CF7_SPAM: "There was an error trying to send your message. Please try later.",
79
+ CF7_ABORTED: "Message submission has been aborted."
68
80
  };
69
81
  function resolveMessage(code, overrides) {
70
82
  return overrides?.[code] ?? defaultMessages[code];
@@ -1451,6 +1463,58 @@ function useWPULike(config, params, swrOptions) {
1451
1463
  return { data, error, isLoading, vote };
1452
1464
  }
1453
1465
 
1454
- export { AuthProvider, CartProvider, WooCommerceCustomerProvider, cartReducer, useAuth, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
1466
+ // src/integrations/restApi/contactForm7/types.ts
1467
+ var CF7Error = class extends Error {
1468
+ constructor(code, status, endpoint, message) {
1469
+ super(message);
1470
+ __publicField(this, "code", code);
1471
+ __publicField(this, "status", status);
1472
+ __publicField(this, "endpoint", endpoint);
1473
+ this.name = "CF7Error";
1474
+ }
1475
+ };
1476
+
1477
+ // src/integrations/restApi/contactForm7/queries.ts
1478
+ var statusToCode = {
1479
+ mail_sent: ErrorCode.CF7_MAIL_SENT,
1480
+ mail_failed: ErrorCode.CF7_MAIL_FAILED,
1481
+ validation_failed: ErrorCode.CF7_VALIDATION_FAILED,
1482
+ spam: ErrorCode.CF7_SPAM,
1483
+ aborted: ErrorCode.CF7_ABORTED
1484
+ };
1485
+ function createCF7Queries(config) {
1486
+ async function submitForm(formId, data) {
1487
+ const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
1488
+ const body = new FormData();
1489
+ for (const [key, value] of Object.entries(data)) {
1490
+ body.append(key, value);
1491
+ }
1492
+ const res = await fetch(url, { method: "POST", body, cache: "no-store" });
1493
+ if (!res.ok) {
1494
+ throw new CF7Error(
1495
+ ErrorCode.CF7_MAIL_FAILED,
1496
+ res.status,
1497
+ url,
1498
+ resolveMessage(ErrorCode.CF7_MAIL_FAILED, config.errorMessages)
1499
+ );
1500
+ }
1501
+ const result = await res.json();
1502
+ const code = statusToCode[result.status];
1503
+ return { ...result, message: resolveMessage(code, config.errorMessages) };
1504
+ }
1505
+ return { submitForm };
1506
+ }
1507
+
1508
+ // src/hooks/contactForm7/useCF7Submit.ts
1509
+ function useCF7Submit(config) {
1510
+ return useSWRMutation(
1511
+ `cf7-submit:${config.serverURL}`,
1512
+ async (_, { arg }) => {
1513
+ return createCF7Queries(config).submitForm(arg.formId, arg.fields);
1514
+ }
1515
+ );
1516
+ }
1517
+
1518
+ export { AuthProvider, CartProvider, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
1455
1519
  //# sourceMappingURL=index.js.map
1456
1520
  //# sourceMappingURL=index.js.map