@szymonpiatek/nextwordpress 0.0.15 → 0.0.17
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 +182 -118
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +3 -3
- package/dist/client/index.d.ts +3 -3
- package/dist/client/index.js +180 -118
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +182 -118
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +15 -3
- package/dist/hooks/index.d.ts +15 -3
- package/dist/hooks/index.js +180 -118
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +44 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -10
- package/dist/index.d.ts +12 -10
- package/dist/index.js +44 -1
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +44 -1
- 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 +44 -1
- package/dist/server/index.js.map +1 -1
- package/dist/{types-D6rih4G8.d.cts → types-DVzJO3P-.d.cts} +49 -28
- package/dist/{types-D6rih4G8.d.ts → types-DVzJO3P-.d.ts} +49 -28
- package/package.json +1 -1
package/dist/hooks/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { J as JwtAuthCredentials, N as NextWordpressConfig, C as CookieConsentCategories, P as Post,
|
|
3
|
+
import { J as JwtAuthCredentials, N as NextWordpressConfig, W as WPGraphQLConfig, G as GQLSendPasswordResetEmailResult, a as GQLResetUserPasswordResult, C as CookieConsentCategories, P as Post, b as WordPressResponse, c as WooCommerceConfig, d as WCProduct, e as WCProductFilterParams, f as WooCommerceResponse, g as WCCreateOrderInput, h as WCOrder, i as WCCustomer, U as UpdateCustomerInput, j as GQLPost, k as GQLPostFilter, l as GQLConnection, m as WPULikeStatsParams, n as WPULikeStats, o as WPULikeStatus, p as WPULikeVoteResponse, q as WPULikeCheckParams, r as WPULikeCheckResponse, s as CF7SubmissionResponse } from '../types-DVzJO3P-.cjs';
|
|
4
|
+
import * as swr_mutation from 'swr/mutation';
|
|
4
5
|
import * as swr from 'swr';
|
|
5
6
|
import { SWRConfiguration } from 'swr';
|
|
6
|
-
import * as swr_mutation from 'swr/mutation';
|
|
7
7
|
|
|
8
8
|
interface AuthUser {
|
|
9
9
|
token: string;
|
|
@@ -25,6 +25,18 @@ declare function AuthProvider({ config, children, }: {
|
|
|
25
25
|
}): react.JSX.Element;
|
|
26
26
|
declare function useAuth(): AuthContextValue;
|
|
27
27
|
|
|
28
|
+
type SendPasswordResetEmailArg = {
|
|
29
|
+
username: string;
|
|
30
|
+
};
|
|
31
|
+
declare function useSendPasswordResetEmail(config: WPGraphQLConfig): swr_mutation.SWRMutationResponse<GQLSendPasswordResetEmailResult, Error, string, SendPasswordResetEmailArg>;
|
|
32
|
+
|
|
33
|
+
type ResetUserPasswordArg = {
|
|
34
|
+
key: string;
|
|
35
|
+
login: string;
|
|
36
|
+
password: string;
|
|
37
|
+
};
|
|
38
|
+
declare function useResetUserPassword(config: WPGraphQLConfig): swr_mutation.SWRMutationResponse<GQLResetUserPasswordResult, Error, string, ResetUserPasswordArg>;
|
|
39
|
+
|
|
28
40
|
declare function useCookieConsent(consentPath?: string, cookieName?: string): {
|
|
29
41
|
consent: CookieConsentCategories | null;
|
|
30
42
|
isLoaded: boolean;
|
|
@@ -136,4 +148,4 @@ type CF7SubmitArg = {
|
|
|
136
148
|
};
|
|
137
149
|
declare function useCF7Submit(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<CF7SubmissionResponse, Error, string, CF7SubmitArg>;
|
|
138
150
|
|
|
139
|
-
export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
|
|
151
|
+
export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useResetUserPassword, useSendPasswordResetEmail, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { J as JwtAuthCredentials, N as NextWordpressConfig, C as CookieConsentCategories, P as Post,
|
|
3
|
+
import { J as JwtAuthCredentials, N as NextWordpressConfig, W as WPGraphQLConfig, G as GQLSendPasswordResetEmailResult, a as GQLResetUserPasswordResult, C as CookieConsentCategories, P as Post, b as WordPressResponse, c as WooCommerceConfig, d as WCProduct, e as WCProductFilterParams, f as WooCommerceResponse, g as WCCreateOrderInput, h as WCOrder, i as WCCustomer, U as UpdateCustomerInput, j as GQLPost, k as GQLPostFilter, l as GQLConnection, m as WPULikeStatsParams, n as WPULikeStats, o as WPULikeStatus, p as WPULikeVoteResponse, q as WPULikeCheckParams, r as WPULikeCheckResponse, s as CF7SubmissionResponse } from '../types-DVzJO3P-.js';
|
|
4
|
+
import * as swr_mutation from 'swr/mutation';
|
|
4
5
|
import * as swr from 'swr';
|
|
5
6
|
import { SWRConfiguration } from 'swr';
|
|
6
|
-
import * as swr_mutation from 'swr/mutation';
|
|
7
7
|
|
|
8
8
|
interface AuthUser {
|
|
9
9
|
token: string;
|
|
@@ -25,6 +25,18 @@ declare function AuthProvider({ config, children, }: {
|
|
|
25
25
|
}): react.JSX.Element;
|
|
26
26
|
declare function useAuth(): AuthContextValue;
|
|
27
27
|
|
|
28
|
+
type SendPasswordResetEmailArg = {
|
|
29
|
+
username: string;
|
|
30
|
+
};
|
|
31
|
+
declare function useSendPasswordResetEmail(config: WPGraphQLConfig): swr_mutation.SWRMutationResponse<GQLSendPasswordResetEmailResult, Error, string, SendPasswordResetEmailArg>;
|
|
32
|
+
|
|
33
|
+
type ResetUserPasswordArg = {
|
|
34
|
+
key: string;
|
|
35
|
+
login: string;
|
|
36
|
+
password: string;
|
|
37
|
+
};
|
|
38
|
+
declare function useResetUserPassword(config: WPGraphQLConfig): swr_mutation.SWRMutationResponse<GQLResetUserPasswordResult, Error, string, ResetUserPasswordArg>;
|
|
39
|
+
|
|
28
40
|
declare function useCookieConsent(consentPath?: string, cookieName?: string): {
|
|
29
41
|
consent: CookieConsentCategories | null;
|
|
30
42
|
isLoaded: boolean;
|
|
@@ -136,4 +148,4 @@ type CF7SubmitArg = {
|
|
|
136
148
|
};
|
|
137
149
|
declare function useCF7Submit(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<CF7SubmissionResponse, Error, string, CF7SubmitArg>;
|
|
138
150
|
|
|
139
|
-
export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
|
|
151
|
+
export { type AuthContextValue, AuthProvider, type AuthUser, type CartAction, type CartContextValue, type CartItem, CartProvider, type CheckoutOptions, type CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useResetUserPassword, useSendPasswordResetEmail, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createContext, useState, useCallback, useEffect, useContext, useReducer } from 'react';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
|
-
import useSWR2 from 'swr';
|
|
4
3
|
import useSWRMutation from 'swr/mutation';
|
|
4
|
+
import useSWR2 from 'swr';
|
|
5
5
|
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
7
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -72,6 +72,8 @@ var defaultMessages = {
|
|
|
72
72
|
AUTH_JWT_FAILED: "JWT authentication failed",
|
|
73
73
|
AUTH_CREDENTIALS_INVALID: "Invalid credentials",
|
|
74
74
|
AUTH_TOKEN_INVALID: "JWT token is invalid or expired",
|
|
75
|
+
AUTH_PASSWORD_RESET_REQUESTED: "Password reset email sent. Check your inbox.",
|
|
76
|
+
AUTH_PASSWORD_RESET_FAILED: "Password reset failed. The link may be invalid or expired.",
|
|
75
77
|
CF7_MAIL_SENT: "Thank you for your message.",
|
|
76
78
|
CF7_MAIL_FAILED: "There was an error trying to send your message.",
|
|
77
79
|
CF7_VALIDATION_FAILED: "One or more fields have an error. Please check and try again.",
|
|
@@ -189,6 +191,174 @@ function useAuth() {
|
|
|
189
191
|
if (!ctx) throw new Error("useAuth must be used within an AuthProvider");
|
|
190
192
|
return ctx;
|
|
191
193
|
}
|
|
194
|
+
|
|
195
|
+
// src/integrations/wpGraphQL/client/types.ts
|
|
196
|
+
var WPGraphQLError = class extends Error {
|
|
197
|
+
constructor(code, status, endpoint, message, gqlErrors) {
|
|
198
|
+
super(message);
|
|
199
|
+
__publicField(this, "code", code);
|
|
200
|
+
__publicField(this, "status", status);
|
|
201
|
+
__publicField(this, "endpoint", endpoint);
|
|
202
|
+
__publicField(this, "gqlErrors", gqlErrors);
|
|
203
|
+
this.name = "WPGraphQLError";
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
// src/integrations/wpGraphQL/client/fetcher.ts
|
|
208
|
+
var USER_AGENT = "NextWordpress WPGraphQL Client";
|
|
209
|
+
function createWPGraphQLFetcher(config) {
|
|
210
|
+
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
211
|
+
const cacheTTL = config.cacheTTL ?? 300;
|
|
212
|
+
async function gqlFetch(document2, variables, tags = ["wpgraphql"]) {
|
|
213
|
+
const response = await fetch(url, {
|
|
214
|
+
method: "POST",
|
|
215
|
+
headers: {
|
|
216
|
+
"Content-Type": "application/json",
|
|
217
|
+
"User-Agent": USER_AGENT
|
|
218
|
+
},
|
|
219
|
+
body: JSON.stringify({ query: document2, variables }),
|
|
220
|
+
next: { tags, revalidate: cacheTTL }
|
|
221
|
+
});
|
|
222
|
+
if (!response.ok) {
|
|
223
|
+
throw new WPGraphQLError(
|
|
224
|
+
ErrorCode.GQL_REQUEST_FAILED,
|
|
225
|
+
response.status,
|
|
226
|
+
url,
|
|
227
|
+
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
const parsed = await response.json();
|
|
231
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
232
|
+
throw new WPGraphQLError(
|
|
233
|
+
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
234
|
+
200,
|
|
235
|
+
url,
|
|
236
|
+
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
237
|
+
parsed.errors
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
if (parsed.data === void 0) {
|
|
241
|
+
throw new WPGraphQLError(
|
|
242
|
+
ErrorCode.GQL_NO_DATA,
|
|
243
|
+
200,
|
|
244
|
+
url,
|
|
245
|
+
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
return parsed.data;
|
|
249
|
+
}
|
|
250
|
+
async function gqlFetchGraceful(document2, fallback, variables, tags = ["wpgraphql"]) {
|
|
251
|
+
try {
|
|
252
|
+
return await gqlFetch(document2, variables, tags);
|
|
253
|
+
} catch {
|
|
254
|
+
console.warn(`WPGraphQL fetch failed for query`);
|
|
255
|
+
return fallback;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
async function gqlMutate(document2, variables, authToken) {
|
|
259
|
+
const headers = {
|
|
260
|
+
"Content-Type": "application/json",
|
|
261
|
+
"User-Agent": USER_AGENT
|
|
262
|
+
};
|
|
263
|
+
if (authToken) {
|
|
264
|
+
headers["Authorization"] = authToken;
|
|
265
|
+
}
|
|
266
|
+
const response = await fetch(url, {
|
|
267
|
+
method: "POST",
|
|
268
|
+
headers,
|
|
269
|
+
body: JSON.stringify({ query: document2, variables }),
|
|
270
|
+
cache: "no-store"
|
|
271
|
+
});
|
|
272
|
+
if (!response.ok) {
|
|
273
|
+
throw new WPGraphQLError(
|
|
274
|
+
ErrorCode.GQL_REQUEST_FAILED,
|
|
275
|
+
response.status,
|
|
276
|
+
url,
|
|
277
|
+
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
const parsed = await response.json();
|
|
281
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
282
|
+
throw new WPGraphQLError(
|
|
283
|
+
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
284
|
+
200,
|
|
285
|
+
url,
|
|
286
|
+
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
287
|
+
parsed.errors
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
if (parsed.data === void 0) {
|
|
291
|
+
throw new WPGraphQLError(
|
|
292
|
+
ErrorCode.GQL_NO_DATA,
|
|
293
|
+
200,
|
|
294
|
+
url,
|
|
295
|
+
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
return parsed.data;
|
|
299
|
+
}
|
|
300
|
+
return { gqlFetch, gqlFetchGraceful, gqlMutate };
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// src/integrations/wpGraphQL/core/mutations/passwordReset/mutations.ts
|
|
304
|
+
var GQL_SEND_PASSWORD_RESET_EMAIL = `
|
|
305
|
+
mutation SendPasswordResetEmail($input: SendPasswordResetEmailInput!) {
|
|
306
|
+
sendPasswordResetEmail(input: $input) {
|
|
307
|
+
success
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
`;
|
|
311
|
+
var GQL_RESET_USER_PASSWORD = `
|
|
312
|
+
mutation ResetUserPassword($input: ResetUserPasswordInput!) {
|
|
313
|
+
resetUserPassword(input: $input) {
|
|
314
|
+
user {
|
|
315
|
+
id
|
|
316
|
+
databaseId
|
|
317
|
+
email
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
`;
|
|
322
|
+
function createPasswordResetMutations(fetcher) {
|
|
323
|
+
const { gqlMutate } = fetcher;
|
|
324
|
+
async function sendPasswordResetEmail(input) {
|
|
325
|
+
const data = await gqlMutate(GQL_SEND_PASSWORD_RESET_EMAIL, { input });
|
|
326
|
+
const result = data.sendPasswordResetEmail;
|
|
327
|
+
if (!result.success) {
|
|
328
|
+
throw new WPGraphQLError(ErrorCode.GQL_ERRORS_IN_RESPONSE, 200, "sendPasswordResetEmail", "User not found");
|
|
329
|
+
}
|
|
330
|
+
return result;
|
|
331
|
+
}
|
|
332
|
+
async function resetUserPassword(input) {
|
|
333
|
+
const data = await gqlMutate(GQL_RESET_USER_PASSWORD, { input });
|
|
334
|
+
return data.resetUserPassword;
|
|
335
|
+
}
|
|
336
|
+
return { sendPasswordResetEmail, resetUserPassword };
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// src/hooks/auth/useSendPasswordResetEmail.ts
|
|
340
|
+
function useSendPasswordResetEmail(config) {
|
|
341
|
+
return useSWRMutation(
|
|
342
|
+
`send-password-reset:${config.serverURL}`,
|
|
343
|
+
async (_, { arg }) => {
|
|
344
|
+
return createPasswordResetMutations(createWPGraphQLFetcher(config)).sendPasswordResetEmail({
|
|
345
|
+
username: arg.username
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
function useResetUserPassword(config) {
|
|
351
|
+
return useSWRMutation(
|
|
352
|
+
`reset-user-password:${config.serverURL}`,
|
|
353
|
+
async (_, { arg }) => {
|
|
354
|
+
return createPasswordResetMutations(createWPGraphQLFetcher(config)).resetUserPassword({
|
|
355
|
+
key: arg.key,
|
|
356
|
+
login: arg.login,
|
|
357
|
+
password: arg.password
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
);
|
|
361
|
+
}
|
|
192
362
|
function readConsentFromDocument(cookieName) {
|
|
193
363
|
if (typeof document === "undefined") return null;
|
|
194
364
|
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
|
|
@@ -254,7 +424,7 @@ function buildUrl(config, path, query) {
|
|
|
254
424
|
}
|
|
255
425
|
|
|
256
426
|
// src/integrations/restApi/core/client/fetcher.ts
|
|
257
|
-
var
|
|
427
|
+
var USER_AGENT2 = "NextWordpress Client";
|
|
258
428
|
function resolveWpErrorCode(status) {
|
|
259
429
|
if (status === 401) return ErrorCode.WP_UNAUTHORIZED;
|
|
260
430
|
if (status === 403) return ErrorCode.WP_FORBIDDEN;
|
|
@@ -280,7 +450,7 @@ function createFetcher(config) {
|
|
|
280
450
|
async function wpFetch(path, query, tags = ["wordpress"]) {
|
|
281
451
|
const url = buildUrl(config, path, query);
|
|
282
452
|
const res = await doFetch(url, {
|
|
283
|
-
headers: { "User-Agent":
|
|
453
|
+
headers: { "User-Agent": USER_AGENT2 },
|
|
284
454
|
next: { tags, revalidate: cacheTtl }
|
|
285
455
|
});
|
|
286
456
|
return await res.json();
|
|
@@ -296,7 +466,7 @@ function createFetcher(config) {
|
|
|
296
466
|
async function wpFetchPaginated(path, query, tags = ["wordpress"]) {
|
|
297
467
|
const url = buildUrl(config, path, query);
|
|
298
468
|
const res = await doFetch(url, {
|
|
299
|
-
headers: { "User-Agent":
|
|
469
|
+
headers: { "User-Agent": USER_AGENT2 },
|
|
300
470
|
next: { tags, revalidate: cacheTtl }
|
|
301
471
|
});
|
|
302
472
|
return {
|
|
@@ -320,7 +490,7 @@ function createFetcher(config) {
|
|
|
320
490
|
const url = buildUrl(config, path);
|
|
321
491
|
const headers = {
|
|
322
492
|
"Content-Type": "application/json",
|
|
323
|
-
"User-Agent":
|
|
493
|
+
"User-Agent": USER_AGENT2
|
|
324
494
|
};
|
|
325
495
|
if (authToken) {
|
|
326
496
|
headers["Authorization"] = authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`;
|
|
@@ -340,7 +510,7 @@ function createFetcher(config) {
|
|
|
340
510
|
headers: {
|
|
341
511
|
"Content-Disposition": `attachment; filename="${filename}"`,
|
|
342
512
|
"Content-Type": mimeType,
|
|
343
|
-
"User-Agent":
|
|
513
|
+
"User-Agent": USER_AGENT2,
|
|
344
514
|
"Authorization": authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`
|
|
345
515
|
},
|
|
346
516
|
body: file,
|
|
@@ -562,7 +732,7 @@ function resolveWooErrorCode(status, upstreamCode) {
|
|
|
562
732
|
}
|
|
563
733
|
|
|
564
734
|
// src/integrations/restApi/woocommerce/client/fetcher.ts
|
|
565
|
-
var
|
|
735
|
+
var USER_AGENT3 = "NextWordpress WooCommerce Client";
|
|
566
736
|
var DEFAULT_CACHE_TTL = 3600;
|
|
567
737
|
function toQueryString(params) {
|
|
568
738
|
const pairs = [];
|
|
@@ -600,7 +770,7 @@ function createWooCommerceFetcher(config) {
|
|
|
600
770
|
const response = await fetch(url, {
|
|
601
771
|
...options,
|
|
602
772
|
headers: {
|
|
603
|
-
"User-Agent":
|
|
773
|
+
"User-Agent": USER_AGENT3,
|
|
604
774
|
"Content-Type": "application/json",
|
|
605
775
|
...options?.headers
|
|
606
776
|
},
|
|
@@ -622,7 +792,7 @@ function createWooCommerceFetcher(config) {
|
|
|
622
792
|
async function wcFetchPaginated(path, query, tags = ["woocommerce"]) {
|
|
623
793
|
const url = buildUrl2(path, query);
|
|
624
794
|
const response = await fetch(url, {
|
|
625
|
-
headers: { "User-Agent":
|
|
795
|
+
headers: { "User-Agent": USER_AGENT3 },
|
|
626
796
|
next: { tags, revalidate: cacheTTL }
|
|
627
797
|
});
|
|
628
798
|
if (!response.ok) {
|
|
@@ -1090,114 +1260,6 @@ function useCustomer() {
|
|
|
1090
1260
|
return ctx;
|
|
1091
1261
|
}
|
|
1092
1262
|
|
|
1093
|
-
// src/integrations/wpGraphQL/client/types.ts
|
|
1094
|
-
var WPGraphQLError = class extends Error {
|
|
1095
|
-
constructor(code, status, endpoint, message, gqlErrors) {
|
|
1096
|
-
super(message);
|
|
1097
|
-
__publicField(this, "code", code);
|
|
1098
|
-
__publicField(this, "status", status);
|
|
1099
|
-
__publicField(this, "endpoint", endpoint);
|
|
1100
|
-
__publicField(this, "gqlErrors", gqlErrors);
|
|
1101
|
-
this.name = "WPGraphQLError";
|
|
1102
|
-
}
|
|
1103
|
-
};
|
|
1104
|
-
|
|
1105
|
-
// src/integrations/wpGraphQL/client/fetcher.ts
|
|
1106
|
-
var USER_AGENT3 = "NextWordpress WPGraphQL Client";
|
|
1107
|
-
function createWPGraphQLFetcher(config) {
|
|
1108
|
-
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
1109
|
-
const cacheTTL = config.cacheTTL ?? 300;
|
|
1110
|
-
async function gqlFetch(document2, variables, tags = ["wpgraphql"]) {
|
|
1111
|
-
const response = await fetch(url, {
|
|
1112
|
-
method: "POST",
|
|
1113
|
-
headers: {
|
|
1114
|
-
"Content-Type": "application/json",
|
|
1115
|
-
"User-Agent": USER_AGENT3
|
|
1116
|
-
},
|
|
1117
|
-
body: JSON.stringify({ query: document2, variables }),
|
|
1118
|
-
next: { tags, revalidate: cacheTTL }
|
|
1119
|
-
});
|
|
1120
|
-
if (!response.ok) {
|
|
1121
|
-
throw new WPGraphQLError(
|
|
1122
|
-
ErrorCode.GQL_REQUEST_FAILED,
|
|
1123
|
-
response.status,
|
|
1124
|
-
url,
|
|
1125
|
-
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
1126
|
-
);
|
|
1127
|
-
}
|
|
1128
|
-
const parsed = await response.json();
|
|
1129
|
-
if (parsed.errors && parsed.errors.length > 0) {
|
|
1130
|
-
throw new WPGraphQLError(
|
|
1131
|
-
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
1132
|
-
200,
|
|
1133
|
-
url,
|
|
1134
|
-
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
1135
|
-
parsed.errors
|
|
1136
|
-
);
|
|
1137
|
-
}
|
|
1138
|
-
if (parsed.data === void 0) {
|
|
1139
|
-
throw new WPGraphQLError(
|
|
1140
|
-
ErrorCode.GQL_NO_DATA,
|
|
1141
|
-
200,
|
|
1142
|
-
url,
|
|
1143
|
-
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
1144
|
-
);
|
|
1145
|
-
}
|
|
1146
|
-
return parsed.data;
|
|
1147
|
-
}
|
|
1148
|
-
async function gqlFetchGraceful(document2, fallback, variables, tags = ["wpgraphql"]) {
|
|
1149
|
-
try {
|
|
1150
|
-
return await gqlFetch(document2, variables, tags);
|
|
1151
|
-
} catch {
|
|
1152
|
-
console.warn(`WPGraphQL fetch failed for query`);
|
|
1153
|
-
return fallback;
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
async function gqlMutate(document2, variables, authToken) {
|
|
1157
|
-
const headers = {
|
|
1158
|
-
"Content-Type": "application/json",
|
|
1159
|
-
"User-Agent": USER_AGENT3
|
|
1160
|
-
};
|
|
1161
|
-
if (authToken) {
|
|
1162
|
-
headers["Authorization"] = authToken;
|
|
1163
|
-
}
|
|
1164
|
-
const response = await fetch(url, {
|
|
1165
|
-
method: "POST",
|
|
1166
|
-
headers,
|
|
1167
|
-
body: JSON.stringify({ query: document2, variables }),
|
|
1168
|
-
cache: "no-store"
|
|
1169
|
-
});
|
|
1170
|
-
if (!response.ok) {
|
|
1171
|
-
throw new WPGraphQLError(
|
|
1172
|
-
ErrorCode.GQL_REQUEST_FAILED,
|
|
1173
|
-
response.status,
|
|
1174
|
-
url,
|
|
1175
|
-
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
1176
|
-
);
|
|
1177
|
-
}
|
|
1178
|
-
const parsed = await response.json();
|
|
1179
|
-
if (parsed.errors && parsed.errors.length > 0) {
|
|
1180
|
-
throw new WPGraphQLError(
|
|
1181
|
-
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
1182
|
-
200,
|
|
1183
|
-
url,
|
|
1184
|
-
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
1185
|
-
parsed.errors
|
|
1186
|
-
);
|
|
1187
|
-
}
|
|
1188
|
-
if (parsed.data === void 0) {
|
|
1189
|
-
throw new WPGraphQLError(
|
|
1190
|
-
ErrorCode.GQL_NO_DATA,
|
|
1191
|
-
200,
|
|
1192
|
-
url,
|
|
1193
|
-
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
1194
|
-
);
|
|
1195
|
-
}
|
|
1196
|
-
return parsed.data;
|
|
1197
|
-
}
|
|
1198
|
-
return { gqlFetch, gqlFetchGraceful, gqlMutate };
|
|
1199
|
-
}
|
|
1200
|
-
|
|
1201
1263
|
// src/integrations/wpGraphQL/core/posts/queries.ts
|
|
1202
1264
|
var DEFAULT_FIRST = 10;
|
|
1203
1265
|
var BATCH_FIRST = 100;
|
|
@@ -1515,6 +1577,6 @@ function useCF7Submit(config) {
|
|
|
1515
1577
|
);
|
|
1516
1578
|
}
|
|
1517
1579
|
|
|
1518
|
-
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 };
|
|
1580
|
+
export { AuthProvider, CartProvider, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useResetUserPassword, useSendPasswordResetEmail, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
|
|
1519
1581
|
//# sourceMappingURL=index.js.map
|
|
1520
1582
|
//# sourceMappingURL=index.js.map
|