@szymonpiatek/nextwordpress 0.0.14 → 0.0.16
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 +211 -129
- 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 +209 -129
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +211 -129
- 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 +209 -129
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +73 -2
- 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 +73 -3
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +73 -2
- 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 +73 -3
- package/dist/server/index.js.map +1 -1
- package/dist/{types-COJWPg77.d.cts → types-CvO7Ijbs.d.cts} +58 -28
- package/dist/{types-COJWPg77.d.ts → types-CvO7Ijbs.d.ts} +58 -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-CvO7Ijbs.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-CvO7Ijbs.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,173 @@ 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
|
+
user {
|
|
309
|
+
email
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
`;
|
|
314
|
+
var GQL_RESET_USER_PASSWORD = `
|
|
315
|
+
mutation ResetUserPassword($input: ResetUserPasswordInput!) {
|
|
316
|
+
resetUserPassword(input: $input) {
|
|
317
|
+
user {
|
|
318
|
+
id
|
|
319
|
+
databaseId
|
|
320
|
+
email
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
`;
|
|
325
|
+
function createPasswordResetMutations(fetcher) {
|
|
326
|
+
const { gqlMutate } = fetcher;
|
|
327
|
+
async function sendPasswordResetEmail(input) {
|
|
328
|
+
const data = await gqlMutate(GQL_SEND_PASSWORD_RESET_EMAIL, { input });
|
|
329
|
+
return data.sendPasswordResetEmail;
|
|
330
|
+
}
|
|
331
|
+
async function resetUserPassword(input) {
|
|
332
|
+
const data = await gqlMutate(GQL_RESET_USER_PASSWORD, { input });
|
|
333
|
+
return data.resetUserPassword;
|
|
334
|
+
}
|
|
335
|
+
return { sendPasswordResetEmail, resetUserPassword };
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// src/hooks/auth/useSendPasswordResetEmail.ts
|
|
339
|
+
function useSendPasswordResetEmail(config) {
|
|
340
|
+
return useSWRMutation(
|
|
341
|
+
`send-password-reset:${config.serverURL}`,
|
|
342
|
+
async (_, { arg }) => {
|
|
343
|
+
return createPasswordResetMutations(createWPGraphQLFetcher(config)).sendPasswordResetEmail({
|
|
344
|
+
username: arg.username
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
);
|
|
348
|
+
}
|
|
349
|
+
function useResetUserPassword(config) {
|
|
350
|
+
return useSWRMutation(
|
|
351
|
+
`reset-user-password:${config.serverURL}`,
|
|
352
|
+
async (_, { arg }) => {
|
|
353
|
+
return createPasswordResetMutations(createWPGraphQLFetcher(config)).resetUserPassword({
|
|
354
|
+
key: arg.key,
|
|
355
|
+
login: arg.login,
|
|
356
|
+
password: arg.password
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
);
|
|
360
|
+
}
|
|
192
361
|
function readConsentFromDocument(cookieName) {
|
|
193
362
|
if (typeof document === "undefined") return null;
|
|
194
363
|
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
|
|
@@ -254,7 +423,7 @@ function buildUrl(config, path, query) {
|
|
|
254
423
|
}
|
|
255
424
|
|
|
256
425
|
// src/integrations/restApi/core/client/fetcher.ts
|
|
257
|
-
var
|
|
426
|
+
var USER_AGENT2 = "NextWordpress Client";
|
|
258
427
|
function resolveWpErrorCode(status) {
|
|
259
428
|
if (status === 401) return ErrorCode.WP_UNAUTHORIZED;
|
|
260
429
|
if (status === 403) return ErrorCode.WP_FORBIDDEN;
|
|
@@ -280,7 +449,7 @@ function createFetcher(config) {
|
|
|
280
449
|
async function wpFetch(path, query, tags = ["wordpress"]) {
|
|
281
450
|
const url = buildUrl(config, path, query);
|
|
282
451
|
const res = await doFetch(url, {
|
|
283
|
-
headers: { "User-Agent":
|
|
452
|
+
headers: { "User-Agent": USER_AGENT2 },
|
|
284
453
|
next: { tags, revalidate: cacheTtl }
|
|
285
454
|
});
|
|
286
455
|
return await res.json();
|
|
@@ -296,7 +465,7 @@ function createFetcher(config) {
|
|
|
296
465
|
async function wpFetchPaginated(path, query, tags = ["wordpress"]) {
|
|
297
466
|
const url = buildUrl(config, path, query);
|
|
298
467
|
const res = await doFetch(url, {
|
|
299
|
-
headers: { "User-Agent":
|
|
468
|
+
headers: { "User-Agent": USER_AGENT2 },
|
|
300
469
|
next: { tags, revalidate: cacheTtl }
|
|
301
470
|
});
|
|
302
471
|
return {
|
|
@@ -320,7 +489,7 @@ function createFetcher(config) {
|
|
|
320
489
|
const url = buildUrl(config, path);
|
|
321
490
|
const headers = {
|
|
322
491
|
"Content-Type": "application/json",
|
|
323
|
-
"User-Agent":
|
|
492
|
+
"User-Agent": USER_AGENT2
|
|
324
493
|
};
|
|
325
494
|
if (authToken) {
|
|
326
495
|
headers["Authorization"] = authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`;
|
|
@@ -340,7 +509,7 @@ function createFetcher(config) {
|
|
|
340
509
|
headers: {
|
|
341
510
|
"Content-Disposition": `attachment; filename="${filename}"`,
|
|
342
511
|
"Content-Type": mimeType,
|
|
343
|
-
"User-Agent":
|
|
512
|
+
"User-Agent": USER_AGENT2,
|
|
344
513
|
"Authorization": authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`
|
|
345
514
|
},
|
|
346
515
|
body: file,
|
|
@@ -562,7 +731,7 @@ function resolveWooErrorCode(status, upstreamCode) {
|
|
|
562
731
|
}
|
|
563
732
|
|
|
564
733
|
// src/integrations/restApi/woocommerce/client/fetcher.ts
|
|
565
|
-
var
|
|
734
|
+
var USER_AGENT3 = "NextWordpress WooCommerce Client";
|
|
566
735
|
var DEFAULT_CACHE_TTL = 3600;
|
|
567
736
|
function toQueryString(params) {
|
|
568
737
|
const pairs = [];
|
|
@@ -600,7 +769,7 @@ function createWooCommerceFetcher(config) {
|
|
|
600
769
|
const response = await fetch(url, {
|
|
601
770
|
...options,
|
|
602
771
|
headers: {
|
|
603
|
-
"User-Agent":
|
|
772
|
+
"User-Agent": USER_AGENT3,
|
|
604
773
|
"Content-Type": "application/json",
|
|
605
774
|
...options?.headers
|
|
606
775
|
},
|
|
@@ -622,7 +791,7 @@ function createWooCommerceFetcher(config) {
|
|
|
622
791
|
async function wcFetchPaginated(path, query, tags = ["woocommerce"]) {
|
|
623
792
|
const url = buildUrl2(path, query);
|
|
624
793
|
const response = await fetch(url, {
|
|
625
|
-
headers: { "User-Agent":
|
|
794
|
+
headers: { "User-Agent": USER_AGENT3 },
|
|
626
795
|
next: { tags, revalidate: cacheTTL }
|
|
627
796
|
});
|
|
628
797
|
if (!response.ok) {
|
|
@@ -1090,114 +1259,6 @@ function useCustomer() {
|
|
|
1090
1259
|
return ctx;
|
|
1091
1260
|
}
|
|
1092
1261
|
|
|
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
1262
|
// src/integrations/wpGraphQL/core/posts/queries.ts
|
|
1202
1263
|
var DEFAULT_FIRST = 10;
|
|
1203
1264
|
var BATCH_FIRST = 100;
|
|
@@ -1463,7 +1524,25 @@ function useWPULike(config, params, swrOptions) {
|
|
|
1463
1524
|
return { data, error, isLoading, vote };
|
|
1464
1525
|
}
|
|
1465
1526
|
|
|
1527
|
+
// src/integrations/restApi/contactForm7/types.ts
|
|
1528
|
+
var CF7Error = class extends Error {
|
|
1529
|
+
constructor(code, status, endpoint, message) {
|
|
1530
|
+
super(message);
|
|
1531
|
+
__publicField(this, "code", code);
|
|
1532
|
+
__publicField(this, "status", status);
|
|
1533
|
+
__publicField(this, "endpoint", endpoint);
|
|
1534
|
+
this.name = "CF7Error";
|
|
1535
|
+
}
|
|
1536
|
+
};
|
|
1537
|
+
|
|
1466
1538
|
// src/integrations/restApi/contactForm7/queries.ts
|
|
1539
|
+
var statusToCode = {
|
|
1540
|
+
mail_sent: ErrorCode.CF7_MAIL_SENT,
|
|
1541
|
+
mail_failed: ErrorCode.CF7_MAIL_FAILED,
|
|
1542
|
+
validation_failed: ErrorCode.CF7_VALIDATION_FAILED,
|
|
1543
|
+
spam: ErrorCode.CF7_SPAM,
|
|
1544
|
+
aborted: ErrorCode.CF7_ABORTED
|
|
1545
|
+
};
|
|
1467
1546
|
function createCF7Queries(config) {
|
|
1468
1547
|
async function submitForm(formId, data) {
|
|
1469
1548
|
const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
|
|
@@ -1472,30 +1551,31 @@ function createCF7Queries(config) {
|
|
|
1472
1551
|
body.append(key, value);
|
|
1473
1552
|
}
|
|
1474
1553
|
const res = await fetch(url, { method: "POST", body, cache: "no-store" });
|
|
1475
|
-
|
|
1554
|
+
if (!res.ok) {
|
|
1555
|
+
throw new CF7Error(
|
|
1556
|
+
ErrorCode.CF7_MAIL_FAILED,
|
|
1557
|
+
res.status,
|
|
1558
|
+
url,
|
|
1559
|
+
resolveMessage(ErrorCode.CF7_MAIL_FAILED, config.errorMessages)
|
|
1560
|
+
);
|
|
1561
|
+
}
|
|
1562
|
+
const result = await res.json();
|
|
1563
|
+
const code = statusToCode[result.status];
|
|
1564
|
+
return { ...result, message: resolveMessage(code, config.errorMessages) };
|
|
1476
1565
|
}
|
|
1477
1566
|
return { submitForm };
|
|
1478
1567
|
}
|
|
1479
1568
|
|
|
1480
1569
|
// src/hooks/contactForm7/useCF7Submit.ts
|
|
1481
|
-
var statusToCode = {
|
|
1482
|
-
mail_sent: ErrorCode.CF7_MAIL_SENT,
|
|
1483
|
-
mail_failed: ErrorCode.CF7_MAIL_FAILED,
|
|
1484
|
-
validation_failed: ErrorCode.CF7_VALIDATION_FAILED,
|
|
1485
|
-
spam: ErrorCode.CF7_SPAM,
|
|
1486
|
-
aborted: ErrorCode.CF7_ABORTED
|
|
1487
|
-
};
|
|
1488
1570
|
function useCF7Submit(config) {
|
|
1489
1571
|
return useSWRMutation(
|
|
1490
1572
|
`cf7-submit:${config.serverURL}`,
|
|
1491
1573
|
async (_, { arg }) => {
|
|
1492
|
-
|
|
1493
|
-
const override = config.errorMessages?.[statusToCode[result.status]];
|
|
1494
|
-
return override ? { ...result, message: override } : result;
|
|
1574
|
+
return createCF7Queries(config).submitForm(arg.formId, arg.fields);
|
|
1495
1575
|
}
|
|
1496
1576
|
);
|
|
1497
1577
|
}
|
|
1498
1578
|
|
|
1499
|
-
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 };
|
|
1579
|
+
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 };
|
|
1500
1580
|
//# sourceMappingURL=index.js.map
|
|
1501
1581
|
//# sourceMappingURL=index.js.map
|