@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.
- package/dist/client/index.cjs +94 -8
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +3 -2
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.js +92 -9
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +94 -8
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +16 -2
- package/dist/hooks/index.d.ts +16 -2
- package/dist/hooks/index.js +92 -9
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +211 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -19
- package/dist/index.d.ts +7 -19
- package/dist/index.js +210 -141
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +211 -140
- 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 +210 -141
- package/dist/server/index.js.map +1 -1
- package/dist/{types-WcyioRuq.d.cts → types-COJWPg77.d.cts} +30 -1
- package/dist/{types-WcyioRuq.d.ts → types-COJWPg77.d.ts} +30 -1
- package/package.json +1 -1
package/dist/client/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { AuthContextValue, AuthProvider, AuthUser, CartAction, CartContextValue, CartItem, CartProvider, CheckoutOptions, CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCart, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, 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, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats } from '../hooks/index.js';
|
|
2
2
|
import 'react';
|
|
3
|
-
import '../types-
|
|
3
|
+
import '../types-COJWPg77.js';
|
|
4
4
|
import 'swr';
|
|
5
|
+
import 'swr/mutation';
|
package/dist/client/index.js
CHANGED
|
@@ -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(
|
|
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:
|
|
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(
|
|
1148
|
+
async function gqlFetchGraceful(document2, fallback, variables, tags = ["wpgraphql"]) {
|
|
1099
1149
|
try {
|
|
1100
|
-
return await gqlFetch(
|
|
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(
|
|
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:
|
|
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
|
-
|
|
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
|