@szymonpiatek/nextwordpress 0.0.11 → 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 +118 -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 +115 -7
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +118 -6
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +18 -2
- package/dist/hooks/index.d.ts +18 -2
- package/dist/hooks/index.js +115 -7
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +89 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +86 -1
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +89 -0
- 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 +86 -1
- package/dist/server/index.js.map +1 -1
- package/dist/{types-Dxb6tuW_.d.cts → types-BELSHjQr.d.cts} +45 -1
- package/dist/{types-Dxb6tuW_.d.ts → types-BELSHjQr.d.ts} +45 -1
- package/package.json +1 -1
package/dist/client/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) {
|
|
@@ -1349,12 +1387,83 @@ function useGQLPostBySlug(config, slug, swrOptions) {
|
|
|
1349
1387
|
);
|
|
1350
1388
|
}
|
|
1351
1389
|
|
|
1390
|
+
// src/integrations/restApi/wpulike/queries.ts
|
|
1391
|
+
function createWPULikeQueries(fetcher) {
|
|
1392
|
+
const { wpFetch, wpMutate } = fetcher;
|
|
1393
|
+
async function getLikeStats(params, tags) {
|
|
1394
|
+
return wpFetch(
|
|
1395
|
+
"/wp-json/wp-ulike/v1/stats",
|
|
1396
|
+
params,
|
|
1397
|
+
tags ?? ["wpulike", `wpulike-${params.id}`]
|
|
1398
|
+
);
|
|
1399
|
+
}
|
|
1400
|
+
async function checkLikeStatus(params, tags) {
|
|
1401
|
+
return wpFetch(
|
|
1402
|
+
"/wp-json/wp-ulike/v1/check",
|
|
1403
|
+
params,
|
|
1404
|
+
tags ?? ["wpulike", `wpulike-${params.id}`]
|
|
1405
|
+
);
|
|
1406
|
+
}
|
|
1407
|
+
async function vote(params, authToken) {
|
|
1408
|
+
return wpMutate(
|
|
1409
|
+
"/wp-json/wp-ulike/v1/vote",
|
|
1410
|
+
params,
|
|
1411
|
+
"POST",
|
|
1412
|
+
authToken
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
return { getLikeStats, checkLikeStatus, vote };
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
// src/hooks/wpulike/useWPULike.ts
|
|
1419
|
+
function useWPULikeStats(config, params, swrOptions) {
|
|
1420
|
+
const key = params ? ["wpulike-stats", config.clientURL, params.id, params.type ?? "post"] : null;
|
|
1421
|
+
return useSWR2__default.default(
|
|
1422
|
+
key,
|
|
1423
|
+
() => {
|
|
1424
|
+
const fetcher = createFetcher(config);
|
|
1425
|
+
return createWPULikeQueries(fetcher).getLikeStats(params);
|
|
1426
|
+
},
|
|
1427
|
+
swrOptions
|
|
1428
|
+
);
|
|
1429
|
+
}
|
|
1430
|
+
function useWPULikeCheck(config, params, swrOptions) {
|
|
1431
|
+
const key = params ? ["wpulike-check", config.clientURL, params.id, params.type ?? "post"] : null;
|
|
1432
|
+
return useSWR2__default.default(
|
|
1433
|
+
key,
|
|
1434
|
+
() => {
|
|
1435
|
+
const fetcher = createFetcher(config);
|
|
1436
|
+
return createWPULikeQueries(fetcher).checkLikeStatus(params);
|
|
1437
|
+
},
|
|
1438
|
+
swrOptions
|
|
1439
|
+
);
|
|
1440
|
+
}
|
|
1441
|
+
function useWPULike(config, params, swrOptions) {
|
|
1442
|
+
const key = params ? ["wpulike-stats", config.clientURL, params.id, params.type ?? "post"] : null;
|
|
1443
|
+
const { data, error, isLoading, mutate } = useSWR2__default.default(
|
|
1444
|
+
key,
|
|
1445
|
+
() => {
|
|
1446
|
+
const fetcher = createFetcher(config);
|
|
1447
|
+
return createWPULikeQueries(fetcher).getLikeStats(params);
|
|
1448
|
+
},
|
|
1449
|
+
swrOptions
|
|
1450
|
+
);
|
|
1451
|
+
async function vote(status, authToken) {
|
|
1452
|
+
const fetcher = createFetcher(config);
|
|
1453
|
+
const result = await createWPULikeQueries(fetcher).vote({ ...params, status }, authToken);
|
|
1454
|
+
await mutate();
|
|
1455
|
+
return result;
|
|
1456
|
+
}
|
|
1457
|
+
return { data, error, isLoading, vote };
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1352
1460
|
exports.AuthProvider = AuthProvider;
|
|
1353
1461
|
exports.CartProvider = CartProvider;
|
|
1354
1462
|
exports.WooCommerceCustomerProvider = WooCommerceCustomerProvider;
|
|
1355
1463
|
exports.cartReducer = cartReducer;
|
|
1356
1464
|
exports.useAuth = useAuth;
|
|
1357
1465
|
exports.useCart = useCart;
|
|
1466
|
+
exports.useCookieConsent = useCookieConsent;
|
|
1358
1467
|
exports.useCustomer = useCustomer;
|
|
1359
1468
|
exports.useFeaturedProducts = useFeaturedProducts;
|
|
1360
1469
|
exports.useGQLPostBySlug = useGQLPostBySlug;
|
|
@@ -1368,5 +1477,8 @@ exports.useProductBySlug = useProductBySlug;
|
|
|
1368
1477
|
exports.useProducts = useProducts;
|
|
1369
1478
|
exports.useProductsPaginated = useProductsPaginated;
|
|
1370
1479
|
exports.useWPGraphQL = useWPGraphQL;
|
|
1480
|
+
exports.useWPULike = useWPULike;
|
|
1481
|
+
exports.useWPULikeCheck = useWPULikeCheck;
|
|
1482
|
+
exports.useWPULikeStats = useWPULikeStats;
|
|
1371
1483
|
//# sourceMappingURL=index.cjs.map
|
|
1372
1484
|
//# sourceMappingURL=index.cjs.map
|