@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.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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-
|
|
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 } from '../types-BELSHjQr.cjs';
|
|
4
4
|
import * as swr from 'swr';
|
|
5
5
|
import { SWRConfiguration } from 'swr';
|
|
6
6
|
|
|
@@ -24,6 +24,13 @@ declare function AuthProvider({ config, children, }: {
|
|
|
24
24
|
}): react.JSX.Element;
|
|
25
25
|
declare function useAuth(): AuthContextValue;
|
|
26
26
|
|
|
27
|
+
declare function useCookieConsent(consentPath?: string, cookieName?: string): {
|
|
28
|
+
consent: CookieConsentCategories | null;
|
|
29
|
+
isLoaded: boolean;
|
|
30
|
+
setConsent: (categories: Omit<CookieConsentCategories, "necessary">) => Promise<void>;
|
|
31
|
+
clearConsent: () => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
|
|
27
34
|
type PostFilterParams = {
|
|
28
35
|
author?: string;
|
|
29
36
|
tag?: string;
|
|
@@ -122,4 +129,4 @@ declare function useWPULike(config: NextWordpressConfig, params: WPULikeStatsPar
|
|
|
122
129
|
vote: (status: WPULikeStatus, authToken?: string) => Promise<WPULikeVoteResponse>;
|
|
123
130
|
};
|
|
124
131
|
|
|
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 };
|
|
132
|
+
export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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-
|
|
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 } from '../types-BELSHjQr.js';
|
|
4
4
|
import * as swr from 'swr';
|
|
5
5
|
import { SWRConfiguration } from 'swr';
|
|
6
6
|
|
|
@@ -24,6 +24,13 @@ declare function AuthProvider({ config, children, }: {
|
|
|
24
24
|
}): react.JSX.Element;
|
|
25
25
|
declare function useAuth(): AuthContextValue;
|
|
26
26
|
|
|
27
|
+
declare function useCookieConsent(consentPath?: string, cookieName?: string): {
|
|
28
|
+
consent: CookieConsentCategories | null;
|
|
29
|
+
isLoaded: boolean;
|
|
30
|
+
setConsent: (categories: Omit<CookieConsentCategories, "necessary">) => Promise<void>;
|
|
31
|
+
clearConsent: () => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
|
|
27
34
|
type PostFilterParams = {
|
|
28
35
|
author?: string;
|
|
29
36
|
tag?: string;
|
|
@@ -122,4 +129,4 @@ declare function useWPULike(config: NextWordpressConfig, params: WPULikeStatsPar
|
|
|
122
129
|
vote: (status: WPULikeStatus, authToken?: string) => Promise<WPULikeVoteResponse>;
|
|
123
130
|
};
|
|
124
131
|
|
|
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 };
|
|
132
|
+
export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
|
package/dist/hooks/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) {
|
|
@@ -1413,6 +1451,6 @@ function useWPULike(config, params, swrOptions) {
|
|
|
1413
1451
|
return { data, error, isLoading, vote };
|
|
1414
1452
|
}
|
|
1415
1453
|
|
|
1416
|
-
export { AuthProvider, CartProvider, WooCommerceCustomerProvider, cartReducer, useAuth, useCart, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
|
|
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 };
|
|
1417
1455
|
//# sourceMappingURL=index.js.map
|
|
1418
1456
|
//# sourceMappingURL=index.js.map
|