@szymonpiatek/nextwordpress 0.0.12 → 0.0.14

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, 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-WcyioRuq.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-COJWPg77.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;
@@ -24,6 +25,13 @@ declare function AuthProvider({ config, children, }: {
24
25
  }): react.JSX.Element;
25
26
  declare function useAuth(): AuthContextValue;
26
27
 
28
+ declare function useCookieConsent(consentPath?: string, cookieName?: string): {
29
+ consent: CookieConsentCategories | null;
30
+ isLoaded: boolean;
31
+ setConsent: (categories: Omit<CookieConsentCategories, "necessary">) => Promise<void>;
32
+ clearConsent: () => Promise<void>;
33
+ };
34
+
27
35
  type PostFilterParams = {
28
36
  author?: string;
29
37
  tag?: string;
@@ -122,4 +130,10 @@ declare function useWPULike(config: NextWordpressConfig, params: WPULikeStatsPar
122
130
  vote: (status: WPULikeStatus, authToken?: string) => Promise<WPULikeVoteResponse>;
123
131
  };
124
132
 
125
- export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCart, 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, 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-WcyioRuq.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-COJWPg77.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;
@@ -24,6 +25,13 @@ declare function AuthProvider({ config, children, }: {
24
25
  }): react.JSX.Element;
25
26
  declare function useAuth(): AuthContextValue;
26
27
 
28
+ declare function useCookieConsent(consentPath?: string, cookieName?: string): {
29
+ consent: CookieConsentCategories | null;
30
+ isLoaded: boolean;
31
+ setConsent: (categories: Omit<CookieConsentCategories, "necessary">) => Promise<void>;
32
+ clearConsent: () => Promise<void>;
33
+ };
34
+
27
35
  type PostFilterParams = {
28
36
  author?: string;
29
37
  tag?: string;
@@ -122,4 +130,10 @@ declare function useWPULike(config: NextWordpressConfig, params: WPULikeStatsPar
122
130
  vote: (status: WPULikeStatus, authToken?: string) => Promise<WPULikeVoteResponse>;
123
131
  };
124
132
 
125
- export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCart, 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];
@@ -177,6 +189,44 @@ function useAuth() {
177
189
  if (!ctx) throw new Error("useAuth must be used within an AuthProvider");
178
190
  return ctx;
179
191
  }
192
+ function readConsentFromDocument(cookieName) {
193
+ if (typeof document === "undefined") return null;
194
+ const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
195
+ if (!match) return null;
196
+ if (match[1] === "1") return { necessary: true, analytics: true, marketing: true };
197
+ try {
198
+ const parsed = JSON.parse(decodeURIComponent(match[1]));
199
+ if (typeof parsed !== "object" || parsed === null) return null;
200
+ return parsed;
201
+ } catch {
202
+ return null;
203
+ }
204
+ }
205
+ function useCookieConsent(consentPath = "/api/cookie-consent", cookieName = "cookie_notice_accepted") {
206
+ const [consent, setConsentState] = useState(null);
207
+ const [isLoaded, setIsLoaded] = useState(false);
208
+ useEffect(() => {
209
+ setConsentState(readConsentFromDocument(cookieName));
210
+ setIsLoaded(true);
211
+ }, [cookieName]);
212
+ const setConsent = useCallback(
213
+ async (categories) => {
214
+ const res = await fetch(consentPath, {
215
+ method: "POST",
216
+ headers: { "Content-Type": "application/json" },
217
+ body: JSON.stringify(categories)
218
+ });
219
+ const data = await res.json();
220
+ setConsentState(data);
221
+ },
222
+ [consentPath]
223
+ );
224
+ const clearConsent = useCallback(async () => {
225
+ await fetch(consentPath, { method: "DELETE" });
226
+ setConsentState(null);
227
+ }, [consentPath]);
228
+ return { consent, isLoaded, setConsent, clearConsent };
229
+ }
180
230
 
181
231
  // src/integrations/restApi/core/client/types.ts
182
232
  var WordPressAPIError = class extends Error {
@@ -1057,14 +1107,14 @@ var USER_AGENT3 = "NextWordpress WPGraphQL Client";
1057
1107
  function createWPGraphQLFetcher(config) {
1058
1108
  const url = `${resolveBaseUrl(config)}/graphql`;
1059
1109
  const cacheTTL = config.cacheTTL ?? 300;
1060
- async function gqlFetch(document, variables, tags = ["wpgraphql"]) {
1110
+ async function gqlFetch(document2, variables, tags = ["wpgraphql"]) {
1061
1111
  const response = await fetch(url, {
1062
1112
  method: "POST",
1063
1113
  headers: {
1064
1114
  "Content-Type": "application/json",
1065
1115
  "User-Agent": USER_AGENT3
1066
1116
  },
1067
- body: JSON.stringify({ query: document, variables }),
1117
+ body: JSON.stringify({ query: document2, variables }),
1068
1118
  next: { tags, revalidate: cacheTTL }
1069
1119
  });
1070
1120
  if (!response.ok) {
@@ -1095,15 +1145,15 @@ function createWPGraphQLFetcher(config) {
1095
1145
  }
1096
1146
  return parsed.data;
1097
1147
  }
1098
- async function gqlFetchGraceful(document, fallback, variables, tags = ["wpgraphql"]) {
1148
+ async function gqlFetchGraceful(document2, fallback, variables, tags = ["wpgraphql"]) {
1099
1149
  try {
1100
- return await gqlFetch(document, variables, tags);
1150
+ return await gqlFetch(document2, variables, tags);
1101
1151
  } catch {
1102
1152
  console.warn(`WPGraphQL fetch failed for query`);
1103
1153
  return fallback;
1104
1154
  }
1105
1155
  }
1106
- async function gqlMutate(document, variables, authToken) {
1156
+ async function gqlMutate(document2, variables, authToken) {
1107
1157
  const headers = {
1108
1158
  "Content-Type": "application/json",
1109
1159
  "User-Agent": USER_AGENT3
@@ -1114,7 +1164,7 @@ function createWPGraphQLFetcher(config) {
1114
1164
  const response = await fetch(url, {
1115
1165
  method: "POST",
1116
1166
  headers,
1117
- body: JSON.stringify({ query: document, variables }),
1167
+ body: JSON.stringify({ query: document2, variables }),
1118
1168
  cache: "no-store"
1119
1169
  });
1120
1170
  if (!response.ok) {
@@ -1413,6 +1463,39 @@ function useWPULike(config, params, swrOptions) {
1413
1463
  return { data, error, isLoading, vote };
1414
1464
  }
1415
1465
 
1416
- export { AuthProvider, CartProvider, WooCommerceCustomerProvider, cartReducer, useAuth, useCart, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
1466
+ // src/integrations/restApi/contactForm7/queries.ts
1467
+ function createCF7Queries(config) {
1468
+ async function submitForm(formId, data) {
1469
+ const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
1470
+ const body = new FormData();
1471
+ for (const [key, value] of Object.entries(data)) {
1472
+ body.append(key, value);
1473
+ }
1474
+ const res = await fetch(url, { method: "POST", body, cache: "no-store" });
1475
+ return res.json();
1476
+ }
1477
+ return { submitForm };
1478
+ }
1479
+
1480
+ // src/hooks/contactForm7/useCF7Submit.ts
1481
+ var statusToCode = {
1482
+ mail_sent: ErrorCode.CF7_MAIL_SENT,
1483
+ mail_failed: ErrorCode.CF7_MAIL_FAILED,
1484
+ validation_failed: ErrorCode.CF7_VALIDATION_FAILED,
1485
+ spam: ErrorCode.CF7_SPAM,
1486
+ aborted: ErrorCode.CF7_ABORTED
1487
+ };
1488
+ function useCF7Submit(config) {
1489
+ return useSWRMutation(
1490
+ `cf7-submit:${config.serverURL}`,
1491
+ async (_, { arg }) => {
1492
+ const result = await createCF7Queries(config).submitForm(arg.formId, arg.fields);
1493
+ const override = config.errorMessages?.[statusToCode[result.status]];
1494
+ return override ? { ...result, message: override } : result;
1495
+ }
1496
+ );
1497
+ }
1498
+
1499
+ 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 };
1417
1500
  //# sourceMappingURL=index.js.map
1418
1501
  //# sourceMappingURL=index.js.map