@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.js
CHANGED
|
@@ -177,6 +177,44 @@ function useAuth() {
|
|
|
177
177
|
if (!ctx) throw new Error("useAuth must be used within an AuthProvider");
|
|
178
178
|
return ctx;
|
|
179
179
|
}
|
|
180
|
+
function readConsentFromDocument(cookieName) {
|
|
181
|
+
if (typeof document === "undefined") return null;
|
|
182
|
+
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
|
|
183
|
+
if (!match) return null;
|
|
184
|
+
if (match[1] === "1") return { necessary: true, analytics: true, marketing: true };
|
|
185
|
+
try {
|
|
186
|
+
const parsed = JSON.parse(decodeURIComponent(match[1]));
|
|
187
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
188
|
+
return parsed;
|
|
189
|
+
} catch {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function useCookieConsent(consentPath = "/api/cookie-consent", cookieName = "cookie_notice_accepted") {
|
|
194
|
+
const [consent, setConsentState] = useState(null);
|
|
195
|
+
const [isLoaded, setIsLoaded] = useState(false);
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
setConsentState(readConsentFromDocument(cookieName));
|
|
198
|
+
setIsLoaded(true);
|
|
199
|
+
}, [cookieName]);
|
|
200
|
+
const setConsent = useCallback(
|
|
201
|
+
async (categories) => {
|
|
202
|
+
const res = await fetch(consentPath, {
|
|
203
|
+
method: "POST",
|
|
204
|
+
headers: { "Content-Type": "application/json" },
|
|
205
|
+
body: JSON.stringify(categories)
|
|
206
|
+
});
|
|
207
|
+
const data = await res.json();
|
|
208
|
+
setConsentState(data);
|
|
209
|
+
},
|
|
210
|
+
[consentPath]
|
|
211
|
+
);
|
|
212
|
+
const clearConsent = useCallback(async () => {
|
|
213
|
+
await fetch(consentPath, { method: "DELETE" });
|
|
214
|
+
setConsentState(null);
|
|
215
|
+
}, [consentPath]);
|
|
216
|
+
return { consent, isLoaded, setConsent, clearConsent };
|
|
217
|
+
}
|
|
180
218
|
|
|
181
219
|
// src/integrations/restApi/core/client/types.ts
|
|
182
220
|
var WordPressAPIError = class extends Error {
|
|
@@ -1057,14 +1095,14 @@ var USER_AGENT3 = "NextWordpress WPGraphQL Client";
|
|
|
1057
1095
|
function createWPGraphQLFetcher(config) {
|
|
1058
1096
|
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
1059
1097
|
const cacheTTL = config.cacheTTL ?? 300;
|
|
1060
|
-
async function gqlFetch(
|
|
1098
|
+
async function gqlFetch(document2, variables, tags = ["wpgraphql"]) {
|
|
1061
1099
|
const response = await fetch(url, {
|
|
1062
1100
|
method: "POST",
|
|
1063
1101
|
headers: {
|
|
1064
1102
|
"Content-Type": "application/json",
|
|
1065
1103
|
"User-Agent": USER_AGENT3
|
|
1066
1104
|
},
|
|
1067
|
-
body: JSON.stringify({ query:
|
|
1105
|
+
body: JSON.stringify({ query: document2, variables }),
|
|
1068
1106
|
next: { tags, revalidate: cacheTTL }
|
|
1069
1107
|
});
|
|
1070
1108
|
if (!response.ok) {
|
|
@@ -1095,15 +1133,15 @@ function createWPGraphQLFetcher(config) {
|
|
|
1095
1133
|
}
|
|
1096
1134
|
return parsed.data;
|
|
1097
1135
|
}
|
|
1098
|
-
async function gqlFetchGraceful(
|
|
1136
|
+
async function gqlFetchGraceful(document2, fallback, variables, tags = ["wpgraphql"]) {
|
|
1099
1137
|
try {
|
|
1100
|
-
return await gqlFetch(
|
|
1138
|
+
return await gqlFetch(document2, variables, tags);
|
|
1101
1139
|
} catch {
|
|
1102
1140
|
console.warn(`WPGraphQL fetch failed for query`);
|
|
1103
1141
|
return fallback;
|
|
1104
1142
|
}
|
|
1105
1143
|
}
|
|
1106
|
-
async function gqlMutate(
|
|
1144
|
+
async function gqlMutate(document2, variables, authToken) {
|
|
1107
1145
|
const headers = {
|
|
1108
1146
|
"Content-Type": "application/json",
|
|
1109
1147
|
"User-Agent": USER_AGENT3
|
|
@@ -1114,7 +1152,7 @@ function createWPGraphQLFetcher(config) {
|
|
|
1114
1152
|
const response = await fetch(url, {
|
|
1115
1153
|
method: "POST",
|
|
1116
1154
|
headers,
|
|
1117
|
-
body: JSON.stringify({ query:
|
|
1155
|
+
body: JSON.stringify({ query: document2, variables }),
|
|
1118
1156
|
cache: "no-store"
|
|
1119
1157
|
});
|
|
1120
1158
|
if (!response.ok) {
|
|
@@ -1343,6 +1381,76 @@ function useGQLPostBySlug(config, slug, swrOptions) {
|
|
|
1343
1381
|
);
|
|
1344
1382
|
}
|
|
1345
1383
|
|
|
1346
|
-
|
|
1384
|
+
// src/integrations/restApi/wpulike/queries.ts
|
|
1385
|
+
function createWPULikeQueries(fetcher) {
|
|
1386
|
+
const { wpFetch, wpMutate } = fetcher;
|
|
1387
|
+
async function getLikeStats(params, tags) {
|
|
1388
|
+
return wpFetch(
|
|
1389
|
+
"/wp-json/wp-ulike/v1/stats",
|
|
1390
|
+
params,
|
|
1391
|
+
tags ?? ["wpulike", `wpulike-${params.id}`]
|
|
1392
|
+
);
|
|
1393
|
+
}
|
|
1394
|
+
async function checkLikeStatus(params, tags) {
|
|
1395
|
+
return wpFetch(
|
|
1396
|
+
"/wp-json/wp-ulike/v1/check",
|
|
1397
|
+
params,
|
|
1398
|
+
tags ?? ["wpulike", `wpulike-${params.id}`]
|
|
1399
|
+
);
|
|
1400
|
+
}
|
|
1401
|
+
async function vote(params, authToken) {
|
|
1402
|
+
return wpMutate(
|
|
1403
|
+
"/wp-json/wp-ulike/v1/vote",
|
|
1404
|
+
params,
|
|
1405
|
+
"POST",
|
|
1406
|
+
authToken
|
|
1407
|
+
);
|
|
1408
|
+
}
|
|
1409
|
+
return { getLikeStats, checkLikeStatus, vote };
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
// src/hooks/wpulike/useWPULike.ts
|
|
1413
|
+
function useWPULikeStats(config, params, swrOptions) {
|
|
1414
|
+
const key = params ? ["wpulike-stats", config.clientURL, params.id, params.type ?? "post"] : null;
|
|
1415
|
+
return useSWR2(
|
|
1416
|
+
key,
|
|
1417
|
+
() => {
|
|
1418
|
+
const fetcher = createFetcher(config);
|
|
1419
|
+
return createWPULikeQueries(fetcher).getLikeStats(params);
|
|
1420
|
+
},
|
|
1421
|
+
swrOptions
|
|
1422
|
+
);
|
|
1423
|
+
}
|
|
1424
|
+
function useWPULikeCheck(config, params, swrOptions) {
|
|
1425
|
+
const key = params ? ["wpulike-check", config.clientURL, params.id, params.type ?? "post"] : null;
|
|
1426
|
+
return useSWR2(
|
|
1427
|
+
key,
|
|
1428
|
+
() => {
|
|
1429
|
+
const fetcher = createFetcher(config);
|
|
1430
|
+
return createWPULikeQueries(fetcher).checkLikeStatus(params);
|
|
1431
|
+
},
|
|
1432
|
+
swrOptions
|
|
1433
|
+
);
|
|
1434
|
+
}
|
|
1435
|
+
function useWPULike(config, params, swrOptions) {
|
|
1436
|
+
const key = params ? ["wpulike-stats", config.clientURL, params.id, params.type ?? "post"] : null;
|
|
1437
|
+
const { data, error, isLoading, mutate } = useSWR2(
|
|
1438
|
+
key,
|
|
1439
|
+
() => {
|
|
1440
|
+
const fetcher = createFetcher(config);
|
|
1441
|
+
return createWPULikeQueries(fetcher).getLikeStats(params);
|
|
1442
|
+
},
|
|
1443
|
+
swrOptions
|
|
1444
|
+
);
|
|
1445
|
+
async function vote(status, authToken) {
|
|
1446
|
+
const fetcher = createFetcher(config);
|
|
1447
|
+
const result = await createWPULikeQueries(fetcher).vote({ ...params, status }, authToken);
|
|
1448
|
+
await mutate();
|
|
1449
|
+
return result;
|
|
1450
|
+
}
|
|
1451
|
+
return { data, error, isLoading, vote };
|
|
1452
|
+
}
|
|
1453
|
+
|
|
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 };
|
|
1347
1455
|
//# sourceMappingURL=index.js.map
|
|
1348
1456
|
//# sourceMappingURL=index.js.map
|