@szymonpiatek/nextwordpress 0.0.12 → 0.0.13
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 +45 -6
- 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 +45 -7
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +45 -6
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +9 -2
- package/dist/hooks/index.d.ts +9 -2
- package/dist/hooks/index.js +45 -7
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +55 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +54 -1
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +55 -0
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +54 -1
- package/dist/server/index.js.map +1 -1
- package/dist/{types-WcyioRuq.d.cts → types-BELSHjQr.d.cts} +13 -1
- package/dist/{types-WcyioRuq.d.ts → types-BELSHjQr.d.ts} +13 -1
- package/package.json +1 -1
package/dist/hooks/index.cjs
CHANGED
|
@@ -183,6 +183,44 @@ function useAuth() {
|
|
|
183
183
|
if (!ctx) throw new Error("useAuth must be used within an AuthProvider");
|
|
184
184
|
return ctx;
|
|
185
185
|
}
|
|
186
|
+
function readConsentFromDocument(cookieName) {
|
|
187
|
+
if (typeof document === "undefined") return null;
|
|
188
|
+
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
|
|
189
|
+
if (!match) return null;
|
|
190
|
+
if (match[1] === "1") return { necessary: true, analytics: true, marketing: true };
|
|
191
|
+
try {
|
|
192
|
+
const parsed = JSON.parse(decodeURIComponent(match[1]));
|
|
193
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
194
|
+
return parsed;
|
|
195
|
+
} catch {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
function useCookieConsent(consentPath = "/api/cookie-consent", cookieName = "cookie_notice_accepted") {
|
|
200
|
+
const [consent, setConsentState] = react.useState(null);
|
|
201
|
+
const [isLoaded, setIsLoaded] = react.useState(false);
|
|
202
|
+
react.useEffect(() => {
|
|
203
|
+
setConsentState(readConsentFromDocument(cookieName));
|
|
204
|
+
setIsLoaded(true);
|
|
205
|
+
}, [cookieName]);
|
|
206
|
+
const setConsent = react.useCallback(
|
|
207
|
+
async (categories) => {
|
|
208
|
+
const res = await fetch(consentPath, {
|
|
209
|
+
method: "POST",
|
|
210
|
+
headers: { "Content-Type": "application/json" },
|
|
211
|
+
body: JSON.stringify(categories)
|
|
212
|
+
});
|
|
213
|
+
const data = await res.json();
|
|
214
|
+
setConsentState(data);
|
|
215
|
+
},
|
|
216
|
+
[consentPath]
|
|
217
|
+
);
|
|
218
|
+
const clearConsent = react.useCallback(async () => {
|
|
219
|
+
await fetch(consentPath, { method: "DELETE" });
|
|
220
|
+
setConsentState(null);
|
|
221
|
+
}, [consentPath]);
|
|
222
|
+
return { consent, isLoaded, setConsent, clearConsent };
|
|
223
|
+
}
|
|
186
224
|
|
|
187
225
|
// src/integrations/restApi/core/client/types.ts
|
|
188
226
|
var WordPressAPIError = class extends Error {
|
|
@@ -1063,14 +1101,14 @@ var USER_AGENT3 = "NextWordpress WPGraphQL Client";
|
|
|
1063
1101
|
function createWPGraphQLFetcher(config) {
|
|
1064
1102
|
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
1065
1103
|
const cacheTTL = config.cacheTTL ?? 300;
|
|
1066
|
-
async function gqlFetch(
|
|
1104
|
+
async function gqlFetch(document2, variables, tags = ["wpgraphql"]) {
|
|
1067
1105
|
const response = await fetch(url, {
|
|
1068
1106
|
method: "POST",
|
|
1069
1107
|
headers: {
|
|
1070
1108
|
"Content-Type": "application/json",
|
|
1071
1109
|
"User-Agent": USER_AGENT3
|
|
1072
1110
|
},
|
|
1073
|
-
body: JSON.stringify({ query:
|
|
1111
|
+
body: JSON.stringify({ query: document2, variables }),
|
|
1074
1112
|
next: { tags, revalidate: cacheTTL }
|
|
1075
1113
|
});
|
|
1076
1114
|
if (!response.ok) {
|
|
@@ -1101,15 +1139,15 @@ function createWPGraphQLFetcher(config) {
|
|
|
1101
1139
|
}
|
|
1102
1140
|
return parsed.data;
|
|
1103
1141
|
}
|
|
1104
|
-
async function gqlFetchGraceful(
|
|
1142
|
+
async function gqlFetchGraceful(document2, fallback, variables, tags = ["wpgraphql"]) {
|
|
1105
1143
|
try {
|
|
1106
|
-
return await gqlFetch(
|
|
1144
|
+
return await gqlFetch(document2, variables, tags);
|
|
1107
1145
|
} catch {
|
|
1108
1146
|
console.warn(`WPGraphQL fetch failed for query`);
|
|
1109
1147
|
return fallback;
|
|
1110
1148
|
}
|
|
1111
1149
|
}
|
|
1112
|
-
async function gqlMutate(
|
|
1150
|
+
async function gqlMutate(document2, variables, authToken) {
|
|
1113
1151
|
const headers = {
|
|
1114
1152
|
"Content-Type": "application/json",
|
|
1115
1153
|
"User-Agent": USER_AGENT3
|
|
@@ -1120,7 +1158,7 @@ function createWPGraphQLFetcher(config) {
|
|
|
1120
1158
|
const response = await fetch(url, {
|
|
1121
1159
|
method: "POST",
|
|
1122
1160
|
headers,
|
|
1123
|
-
body: JSON.stringify({ query:
|
|
1161
|
+
body: JSON.stringify({ query: document2, variables }),
|
|
1124
1162
|
cache: "no-store"
|
|
1125
1163
|
});
|
|
1126
1164
|
if (!response.ok) {
|
|
@@ -1425,6 +1463,7 @@ exports.WooCommerceCustomerProvider = WooCommerceCustomerProvider;
|
|
|
1425
1463
|
exports.cartReducer = cartReducer;
|
|
1426
1464
|
exports.useAuth = useAuth;
|
|
1427
1465
|
exports.useCart = useCart;
|
|
1466
|
+
exports.useCookieConsent = useCookieConsent;
|
|
1428
1467
|
exports.useCustomer = useCustomer;
|
|
1429
1468
|
exports.useFeaturedProducts = useFeaturedProducts;
|
|
1430
1469
|
exports.useGQLPostBySlug = useGQLPostBySlug;
|