@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.cjs
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
|
-
var useSWR2 = require('swr');
|
|
6
5
|
var useSWRMutation = require('swr/mutation');
|
|
6
|
+
var useSWR2 = require('swr');
|
|
7
7
|
|
|
8
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
|
|
10
|
-
var useSWR2__default = /*#__PURE__*/_interopDefault(useSWR2);
|
|
11
10
|
var useSWRMutation__default = /*#__PURE__*/_interopDefault(useSWRMutation);
|
|
11
|
+
var useSWR2__default = /*#__PURE__*/_interopDefault(useSWR2);
|
|
12
12
|
|
|
13
13
|
var __defProp = Object.defineProperty;
|
|
14
14
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -79,6 +79,8 @@ var defaultMessages = {
|
|
|
79
79
|
AUTH_JWT_FAILED: "JWT authentication failed",
|
|
80
80
|
AUTH_CREDENTIALS_INVALID: "Invalid credentials",
|
|
81
81
|
AUTH_TOKEN_INVALID: "JWT token is invalid or expired",
|
|
82
|
+
AUTH_PASSWORD_RESET_REQUESTED: "Password reset email sent. Check your inbox.",
|
|
83
|
+
AUTH_PASSWORD_RESET_FAILED: "Password reset failed. The link may be invalid or expired.",
|
|
82
84
|
CF7_MAIL_SENT: "Thank you for your message.",
|
|
83
85
|
CF7_MAIL_FAILED: "There was an error trying to send your message.",
|
|
84
86
|
CF7_VALIDATION_FAILED: "One or more fields have an error. Please check and try again.",
|
|
@@ -196,6 +198,173 @@ function useAuth() {
|
|
|
196
198
|
if (!ctx) throw new Error("useAuth must be used within an AuthProvider");
|
|
197
199
|
return ctx;
|
|
198
200
|
}
|
|
201
|
+
|
|
202
|
+
// src/integrations/wpGraphQL/client/types.ts
|
|
203
|
+
var WPGraphQLError = class extends Error {
|
|
204
|
+
constructor(code, status, endpoint, message, gqlErrors) {
|
|
205
|
+
super(message);
|
|
206
|
+
__publicField(this, "code", code);
|
|
207
|
+
__publicField(this, "status", status);
|
|
208
|
+
__publicField(this, "endpoint", endpoint);
|
|
209
|
+
__publicField(this, "gqlErrors", gqlErrors);
|
|
210
|
+
this.name = "WPGraphQLError";
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
// src/integrations/wpGraphQL/client/fetcher.ts
|
|
215
|
+
var USER_AGENT = "NextWordpress WPGraphQL Client";
|
|
216
|
+
function createWPGraphQLFetcher(config) {
|
|
217
|
+
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
218
|
+
const cacheTTL = config.cacheTTL ?? 300;
|
|
219
|
+
async function gqlFetch(document2, variables, tags = ["wpgraphql"]) {
|
|
220
|
+
const response = await fetch(url, {
|
|
221
|
+
method: "POST",
|
|
222
|
+
headers: {
|
|
223
|
+
"Content-Type": "application/json",
|
|
224
|
+
"User-Agent": USER_AGENT
|
|
225
|
+
},
|
|
226
|
+
body: JSON.stringify({ query: document2, variables }),
|
|
227
|
+
next: { tags, revalidate: cacheTTL }
|
|
228
|
+
});
|
|
229
|
+
if (!response.ok) {
|
|
230
|
+
throw new WPGraphQLError(
|
|
231
|
+
ErrorCode.GQL_REQUEST_FAILED,
|
|
232
|
+
response.status,
|
|
233
|
+
url,
|
|
234
|
+
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
const parsed = await response.json();
|
|
238
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
239
|
+
throw new WPGraphQLError(
|
|
240
|
+
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
241
|
+
200,
|
|
242
|
+
url,
|
|
243
|
+
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
244
|
+
parsed.errors
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
if (parsed.data === void 0) {
|
|
248
|
+
throw new WPGraphQLError(
|
|
249
|
+
ErrorCode.GQL_NO_DATA,
|
|
250
|
+
200,
|
|
251
|
+
url,
|
|
252
|
+
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
return parsed.data;
|
|
256
|
+
}
|
|
257
|
+
async function gqlFetchGraceful(document2, fallback, variables, tags = ["wpgraphql"]) {
|
|
258
|
+
try {
|
|
259
|
+
return await gqlFetch(document2, variables, tags);
|
|
260
|
+
} catch {
|
|
261
|
+
console.warn(`WPGraphQL fetch failed for query`);
|
|
262
|
+
return fallback;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
async function gqlMutate(document2, variables, authToken) {
|
|
266
|
+
const headers = {
|
|
267
|
+
"Content-Type": "application/json",
|
|
268
|
+
"User-Agent": USER_AGENT
|
|
269
|
+
};
|
|
270
|
+
if (authToken) {
|
|
271
|
+
headers["Authorization"] = authToken;
|
|
272
|
+
}
|
|
273
|
+
const response = await fetch(url, {
|
|
274
|
+
method: "POST",
|
|
275
|
+
headers,
|
|
276
|
+
body: JSON.stringify({ query: document2, variables }),
|
|
277
|
+
cache: "no-store"
|
|
278
|
+
});
|
|
279
|
+
if (!response.ok) {
|
|
280
|
+
throw new WPGraphQLError(
|
|
281
|
+
ErrorCode.GQL_REQUEST_FAILED,
|
|
282
|
+
response.status,
|
|
283
|
+
url,
|
|
284
|
+
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
const parsed = await response.json();
|
|
288
|
+
if (parsed.errors && parsed.errors.length > 0) {
|
|
289
|
+
throw new WPGraphQLError(
|
|
290
|
+
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
291
|
+
200,
|
|
292
|
+
url,
|
|
293
|
+
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
294
|
+
parsed.errors
|
|
295
|
+
);
|
|
296
|
+
}
|
|
297
|
+
if (parsed.data === void 0) {
|
|
298
|
+
throw new WPGraphQLError(
|
|
299
|
+
ErrorCode.GQL_NO_DATA,
|
|
300
|
+
200,
|
|
301
|
+
url,
|
|
302
|
+
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
303
|
+
);
|
|
304
|
+
}
|
|
305
|
+
return parsed.data;
|
|
306
|
+
}
|
|
307
|
+
return { gqlFetch, gqlFetchGraceful, gqlMutate };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// src/integrations/wpGraphQL/core/mutations/passwordReset/mutations.ts
|
|
311
|
+
var GQL_SEND_PASSWORD_RESET_EMAIL = `
|
|
312
|
+
mutation SendPasswordResetEmail($input: SendPasswordResetEmailInput!) {
|
|
313
|
+
sendPasswordResetEmail(input: $input) {
|
|
314
|
+
success
|
|
315
|
+
user {
|
|
316
|
+
email
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
`;
|
|
321
|
+
var GQL_RESET_USER_PASSWORD = `
|
|
322
|
+
mutation ResetUserPassword($input: ResetUserPasswordInput!) {
|
|
323
|
+
resetUserPassword(input: $input) {
|
|
324
|
+
user {
|
|
325
|
+
id
|
|
326
|
+
databaseId
|
|
327
|
+
email
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
`;
|
|
332
|
+
function createPasswordResetMutations(fetcher) {
|
|
333
|
+
const { gqlMutate } = fetcher;
|
|
334
|
+
async function sendPasswordResetEmail(input) {
|
|
335
|
+
const data = await gqlMutate(GQL_SEND_PASSWORD_RESET_EMAIL, { input });
|
|
336
|
+
return data.sendPasswordResetEmail;
|
|
337
|
+
}
|
|
338
|
+
async function resetUserPassword(input) {
|
|
339
|
+
const data = await gqlMutate(GQL_RESET_USER_PASSWORD, { input });
|
|
340
|
+
return data.resetUserPassword;
|
|
341
|
+
}
|
|
342
|
+
return { sendPasswordResetEmail, resetUserPassword };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// src/hooks/auth/useSendPasswordResetEmail.ts
|
|
346
|
+
function useSendPasswordResetEmail(config) {
|
|
347
|
+
return useSWRMutation__default.default(
|
|
348
|
+
`send-password-reset:${config.serverURL}`,
|
|
349
|
+
async (_, { arg }) => {
|
|
350
|
+
return createPasswordResetMutations(createWPGraphQLFetcher(config)).sendPasswordResetEmail({
|
|
351
|
+
username: arg.username
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
function useResetUserPassword(config) {
|
|
357
|
+
return useSWRMutation__default.default(
|
|
358
|
+
`reset-user-password:${config.serverURL}`,
|
|
359
|
+
async (_, { arg }) => {
|
|
360
|
+
return createPasswordResetMutations(createWPGraphQLFetcher(config)).resetUserPassword({
|
|
361
|
+
key: arg.key,
|
|
362
|
+
login: arg.login,
|
|
363
|
+
password: arg.password
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
);
|
|
367
|
+
}
|
|
199
368
|
function readConsentFromDocument(cookieName) {
|
|
200
369
|
if (typeof document === "undefined") return null;
|
|
201
370
|
const match = document.cookie.match(new RegExp(`(?:^|;\\s*)${cookieName}=([^;]*)`));
|
|
@@ -261,7 +430,7 @@ function buildUrl(config, path, query) {
|
|
|
261
430
|
}
|
|
262
431
|
|
|
263
432
|
// src/integrations/restApi/core/client/fetcher.ts
|
|
264
|
-
var
|
|
433
|
+
var USER_AGENT2 = "NextWordpress Client";
|
|
265
434
|
function resolveWpErrorCode(status) {
|
|
266
435
|
if (status === 401) return ErrorCode.WP_UNAUTHORIZED;
|
|
267
436
|
if (status === 403) return ErrorCode.WP_FORBIDDEN;
|
|
@@ -287,7 +456,7 @@ function createFetcher(config) {
|
|
|
287
456
|
async function wpFetch(path, query, tags = ["wordpress"]) {
|
|
288
457
|
const url = buildUrl(config, path, query);
|
|
289
458
|
const res = await doFetch(url, {
|
|
290
|
-
headers: { "User-Agent":
|
|
459
|
+
headers: { "User-Agent": USER_AGENT2 },
|
|
291
460
|
next: { tags, revalidate: cacheTtl }
|
|
292
461
|
});
|
|
293
462
|
return await res.json();
|
|
@@ -303,7 +472,7 @@ function createFetcher(config) {
|
|
|
303
472
|
async function wpFetchPaginated(path, query, tags = ["wordpress"]) {
|
|
304
473
|
const url = buildUrl(config, path, query);
|
|
305
474
|
const res = await doFetch(url, {
|
|
306
|
-
headers: { "User-Agent":
|
|
475
|
+
headers: { "User-Agent": USER_AGENT2 },
|
|
307
476
|
next: { tags, revalidate: cacheTtl }
|
|
308
477
|
});
|
|
309
478
|
return {
|
|
@@ -327,7 +496,7 @@ function createFetcher(config) {
|
|
|
327
496
|
const url = buildUrl(config, path);
|
|
328
497
|
const headers = {
|
|
329
498
|
"Content-Type": "application/json",
|
|
330
|
-
"User-Agent":
|
|
499
|
+
"User-Agent": USER_AGENT2
|
|
331
500
|
};
|
|
332
501
|
if (authToken) {
|
|
333
502
|
headers["Authorization"] = authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`;
|
|
@@ -347,7 +516,7 @@ function createFetcher(config) {
|
|
|
347
516
|
headers: {
|
|
348
517
|
"Content-Disposition": `attachment; filename="${filename}"`,
|
|
349
518
|
"Content-Type": mimeType,
|
|
350
|
-
"User-Agent":
|
|
519
|
+
"User-Agent": USER_AGENT2,
|
|
351
520
|
"Authorization": authToken.startsWith("Basic ") || authToken.startsWith("Bearer ") ? authToken : `Bearer ${authToken}`
|
|
352
521
|
},
|
|
353
522
|
body: file,
|
|
@@ -569,7 +738,7 @@ function resolveWooErrorCode(status, upstreamCode) {
|
|
|
569
738
|
}
|
|
570
739
|
|
|
571
740
|
// src/integrations/restApi/woocommerce/client/fetcher.ts
|
|
572
|
-
var
|
|
741
|
+
var USER_AGENT3 = "NextWordpress WooCommerce Client";
|
|
573
742
|
var DEFAULT_CACHE_TTL = 3600;
|
|
574
743
|
function toQueryString(params) {
|
|
575
744
|
const pairs = [];
|
|
@@ -607,7 +776,7 @@ function createWooCommerceFetcher(config) {
|
|
|
607
776
|
const response = await fetch(url, {
|
|
608
777
|
...options,
|
|
609
778
|
headers: {
|
|
610
|
-
"User-Agent":
|
|
779
|
+
"User-Agent": USER_AGENT3,
|
|
611
780
|
"Content-Type": "application/json",
|
|
612
781
|
...options?.headers
|
|
613
782
|
},
|
|
@@ -629,7 +798,7 @@ function createWooCommerceFetcher(config) {
|
|
|
629
798
|
async function wcFetchPaginated(path, query, tags = ["woocommerce"]) {
|
|
630
799
|
const url = buildUrl2(path, query);
|
|
631
800
|
const response = await fetch(url, {
|
|
632
|
-
headers: { "User-Agent":
|
|
801
|
+
headers: { "User-Agent": USER_AGENT3 },
|
|
633
802
|
next: { tags, revalidate: cacheTTL }
|
|
634
803
|
});
|
|
635
804
|
if (!response.ok) {
|
|
@@ -1097,114 +1266,6 @@ function useCustomer() {
|
|
|
1097
1266
|
return ctx;
|
|
1098
1267
|
}
|
|
1099
1268
|
|
|
1100
|
-
// src/integrations/wpGraphQL/client/types.ts
|
|
1101
|
-
var WPGraphQLError = class extends Error {
|
|
1102
|
-
constructor(code, status, endpoint, message, gqlErrors) {
|
|
1103
|
-
super(message);
|
|
1104
|
-
__publicField(this, "code", code);
|
|
1105
|
-
__publicField(this, "status", status);
|
|
1106
|
-
__publicField(this, "endpoint", endpoint);
|
|
1107
|
-
__publicField(this, "gqlErrors", gqlErrors);
|
|
1108
|
-
this.name = "WPGraphQLError";
|
|
1109
|
-
}
|
|
1110
|
-
};
|
|
1111
|
-
|
|
1112
|
-
// src/integrations/wpGraphQL/client/fetcher.ts
|
|
1113
|
-
var USER_AGENT3 = "NextWordpress WPGraphQL Client";
|
|
1114
|
-
function createWPGraphQLFetcher(config) {
|
|
1115
|
-
const url = `${resolveBaseUrl(config)}/graphql`;
|
|
1116
|
-
const cacheTTL = config.cacheTTL ?? 300;
|
|
1117
|
-
async function gqlFetch(document2, variables, tags = ["wpgraphql"]) {
|
|
1118
|
-
const response = await fetch(url, {
|
|
1119
|
-
method: "POST",
|
|
1120
|
-
headers: {
|
|
1121
|
-
"Content-Type": "application/json",
|
|
1122
|
-
"User-Agent": USER_AGENT3
|
|
1123
|
-
},
|
|
1124
|
-
body: JSON.stringify({ query: document2, variables }),
|
|
1125
|
-
next: { tags, revalidate: cacheTTL }
|
|
1126
|
-
});
|
|
1127
|
-
if (!response.ok) {
|
|
1128
|
-
throw new WPGraphQLError(
|
|
1129
|
-
ErrorCode.GQL_REQUEST_FAILED,
|
|
1130
|
-
response.status,
|
|
1131
|
-
url,
|
|
1132
|
-
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
1133
|
-
);
|
|
1134
|
-
}
|
|
1135
|
-
const parsed = await response.json();
|
|
1136
|
-
if (parsed.errors && parsed.errors.length > 0) {
|
|
1137
|
-
throw new WPGraphQLError(
|
|
1138
|
-
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
1139
|
-
200,
|
|
1140
|
-
url,
|
|
1141
|
-
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
1142
|
-
parsed.errors
|
|
1143
|
-
);
|
|
1144
|
-
}
|
|
1145
|
-
if (parsed.data === void 0) {
|
|
1146
|
-
throw new WPGraphQLError(
|
|
1147
|
-
ErrorCode.GQL_NO_DATA,
|
|
1148
|
-
200,
|
|
1149
|
-
url,
|
|
1150
|
-
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
1151
|
-
);
|
|
1152
|
-
}
|
|
1153
|
-
return parsed.data;
|
|
1154
|
-
}
|
|
1155
|
-
async function gqlFetchGraceful(document2, fallback, variables, tags = ["wpgraphql"]) {
|
|
1156
|
-
try {
|
|
1157
|
-
return await gqlFetch(document2, variables, tags);
|
|
1158
|
-
} catch {
|
|
1159
|
-
console.warn(`WPGraphQL fetch failed for query`);
|
|
1160
|
-
return fallback;
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
async function gqlMutate(document2, variables, authToken) {
|
|
1164
|
-
const headers = {
|
|
1165
|
-
"Content-Type": "application/json",
|
|
1166
|
-
"User-Agent": USER_AGENT3
|
|
1167
|
-
};
|
|
1168
|
-
if (authToken) {
|
|
1169
|
-
headers["Authorization"] = authToken;
|
|
1170
|
-
}
|
|
1171
|
-
const response = await fetch(url, {
|
|
1172
|
-
method: "POST",
|
|
1173
|
-
headers,
|
|
1174
|
-
body: JSON.stringify({ query: document2, variables }),
|
|
1175
|
-
cache: "no-store"
|
|
1176
|
-
});
|
|
1177
|
-
if (!response.ok) {
|
|
1178
|
-
throw new WPGraphQLError(
|
|
1179
|
-
ErrorCode.GQL_REQUEST_FAILED,
|
|
1180
|
-
response.status,
|
|
1181
|
-
url,
|
|
1182
|
-
resolveMessage(ErrorCode.GQL_REQUEST_FAILED, config.errorMessages)
|
|
1183
|
-
);
|
|
1184
|
-
}
|
|
1185
|
-
const parsed = await response.json();
|
|
1186
|
-
if (parsed.errors && parsed.errors.length > 0) {
|
|
1187
|
-
throw new WPGraphQLError(
|
|
1188
|
-
ErrorCode.GQL_ERRORS_IN_RESPONSE,
|
|
1189
|
-
200,
|
|
1190
|
-
url,
|
|
1191
|
-
resolveMessage(ErrorCode.GQL_ERRORS_IN_RESPONSE, config.errorMessages),
|
|
1192
|
-
parsed.errors
|
|
1193
|
-
);
|
|
1194
|
-
}
|
|
1195
|
-
if (parsed.data === void 0) {
|
|
1196
|
-
throw new WPGraphQLError(
|
|
1197
|
-
ErrorCode.GQL_NO_DATA,
|
|
1198
|
-
200,
|
|
1199
|
-
url,
|
|
1200
|
-
resolveMessage(ErrorCode.GQL_NO_DATA, config.errorMessages)
|
|
1201
|
-
);
|
|
1202
|
-
}
|
|
1203
|
-
return parsed.data;
|
|
1204
|
-
}
|
|
1205
|
-
return { gqlFetch, gqlFetchGraceful, gqlMutate };
|
|
1206
|
-
}
|
|
1207
|
-
|
|
1208
1269
|
// src/integrations/wpGraphQL/core/posts/queries.ts
|
|
1209
1270
|
var DEFAULT_FIRST = 10;
|
|
1210
1271
|
var BATCH_FIRST = 100;
|
|
@@ -1470,7 +1531,25 @@ function useWPULike(config, params, swrOptions) {
|
|
|
1470
1531
|
return { data, error, isLoading, vote };
|
|
1471
1532
|
}
|
|
1472
1533
|
|
|
1534
|
+
// src/integrations/restApi/contactForm7/types.ts
|
|
1535
|
+
var CF7Error = class extends Error {
|
|
1536
|
+
constructor(code, status, endpoint, message) {
|
|
1537
|
+
super(message);
|
|
1538
|
+
__publicField(this, "code", code);
|
|
1539
|
+
__publicField(this, "status", status);
|
|
1540
|
+
__publicField(this, "endpoint", endpoint);
|
|
1541
|
+
this.name = "CF7Error";
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
|
|
1473
1545
|
// src/integrations/restApi/contactForm7/queries.ts
|
|
1546
|
+
var statusToCode = {
|
|
1547
|
+
mail_sent: ErrorCode.CF7_MAIL_SENT,
|
|
1548
|
+
mail_failed: ErrorCode.CF7_MAIL_FAILED,
|
|
1549
|
+
validation_failed: ErrorCode.CF7_VALIDATION_FAILED,
|
|
1550
|
+
spam: ErrorCode.CF7_SPAM,
|
|
1551
|
+
aborted: ErrorCode.CF7_ABORTED
|
|
1552
|
+
};
|
|
1474
1553
|
function createCF7Queries(config) {
|
|
1475
1554
|
async function submitForm(formId, data) {
|
|
1476
1555
|
const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
|
|
@@ -1479,26 +1558,27 @@ function createCF7Queries(config) {
|
|
|
1479
1558
|
body.append(key, value);
|
|
1480
1559
|
}
|
|
1481
1560
|
const res = await fetch(url, { method: "POST", body, cache: "no-store" });
|
|
1482
|
-
|
|
1561
|
+
if (!res.ok) {
|
|
1562
|
+
throw new CF7Error(
|
|
1563
|
+
ErrorCode.CF7_MAIL_FAILED,
|
|
1564
|
+
res.status,
|
|
1565
|
+
url,
|
|
1566
|
+
resolveMessage(ErrorCode.CF7_MAIL_FAILED, config.errorMessages)
|
|
1567
|
+
);
|
|
1568
|
+
}
|
|
1569
|
+
const result = await res.json();
|
|
1570
|
+
const code = statusToCode[result.status];
|
|
1571
|
+
return { ...result, message: resolveMessage(code, config.errorMessages) };
|
|
1483
1572
|
}
|
|
1484
1573
|
return { submitForm };
|
|
1485
1574
|
}
|
|
1486
1575
|
|
|
1487
1576
|
// src/hooks/contactForm7/useCF7Submit.ts
|
|
1488
|
-
var statusToCode = {
|
|
1489
|
-
mail_sent: ErrorCode.CF7_MAIL_SENT,
|
|
1490
|
-
mail_failed: ErrorCode.CF7_MAIL_FAILED,
|
|
1491
|
-
validation_failed: ErrorCode.CF7_VALIDATION_FAILED,
|
|
1492
|
-
spam: ErrorCode.CF7_SPAM,
|
|
1493
|
-
aborted: ErrorCode.CF7_ABORTED
|
|
1494
|
-
};
|
|
1495
1577
|
function useCF7Submit(config) {
|
|
1496
1578
|
return useSWRMutation__default.default(
|
|
1497
1579
|
`cf7-submit:${config.serverURL}`,
|
|
1498
1580
|
async (_, { arg }) => {
|
|
1499
|
-
|
|
1500
|
-
const override = config.errorMessages?.[statusToCode[result.status]];
|
|
1501
|
-
return override ? { ...result, message: override } : result;
|
|
1581
|
+
return createCF7Queries(config).submitForm(arg.formId, arg.fields);
|
|
1502
1582
|
}
|
|
1503
1583
|
);
|
|
1504
1584
|
}
|
|
@@ -1523,6 +1603,8 @@ exports.useProduct = useProduct;
|
|
|
1523
1603
|
exports.useProductBySlug = useProductBySlug;
|
|
1524
1604
|
exports.useProducts = useProducts;
|
|
1525
1605
|
exports.useProductsPaginated = useProductsPaginated;
|
|
1606
|
+
exports.useResetUserPassword = useResetUserPassword;
|
|
1607
|
+
exports.useSendPasswordResetEmail = useSendPasswordResetEmail;
|
|
1526
1608
|
exports.useWPGraphQL = useWPGraphQL;
|
|
1527
1609
|
exports.useWPULike = useWPULike;
|
|
1528
1610
|
exports.useWPULikeCheck = useWPULikeCheck;
|