@szymonpiatek/nextwordpress 0.0.13 → 0.0.15
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 +68 -2
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +3 -2
- package/dist/client/index.d.ts +3 -2
- package/dist/client/index.js +67 -3
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +68 -2
- 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 +67 -3
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +185 -140
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -19
- package/dist/index.d.ts +7 -19
- package/dist/index.js +185 -141
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +185 -140
- 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 +185 -141
- package/dist/server/index.js.map +1 -1
- package/dist/{types-BELSHjQr.d.cts → types-D6rih4G8.d.cts} +24 -1
- package/dist/{types-BELSHjQr.d.ts → types-D6rih4G8.d.ts} +24 -1
- package/package.json +1 -1
package/dist/client/index.cjs
CHANGED
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var jsxRuntime = require('react/jsx-runtime');
|
|
5
5
|
var useSWR2 = require('swr');
|
|
6
|
+
var useSWRMutation = require('swr/mutation');
|
|
6
7
|
|
|
7
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
9
|
|
|
9
10
|
var useSWR2__default = /*#__PURE__*/_interopDefault(useSWR2);
|
|
11
|
+
var useSWRMutation__default = /*#__PURE__*/_interopDefault(useSWRMutation);
|
|
10
12
|
|
|
11
13
|
var __defProp = Object.defineProperty;
|
|
12
14
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -45,7 +47,13 @@ var ErrorCode = {
|
|
|
45
47
|
// Auth
|
|
46
48
|
AUTH_JWT_FAILED: "AUTH_JWT_FAILED",
|
|
47
49
|
AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID",
|
|
48
|
-
AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID"
|
|
50
|
+
AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID",
|
|
51
|
+
// Contact Form 7
|
|
52
|
+
CF7_MAIL_SENT: "CF7_MAIL_SENT",
|
|
53
|
+
CF7_MAIL_FAILED: "CF7_MAIL_FAILED",
|
|
54
|
+
CF7_VALIDATION_FAILED: "CF7_VALIDATION_FAILED",
|
|
55
|
+
CF7_SPAM: "CF7_SPAM",
|
|
56
|
+
CF7_ABORTED: "CF7_ABORTED"
|
|
49
57
|
};
|
|
50
58
|
var defaultMessages = {
|
|
51
59
|
WP_REQUEST_FAILED: "WordPress API request failed",
|
|
@@ -70,7 +78,12 @@ var defaultMessages = {
|
|
|
70
78
|
WOO_SHIPPING_ZONE_NOT_FOUND: "Shipping zone not found",
|
|
71
79
|
AUTH_JWT_FAILED: "JWT authentication failed",
|
|
72
80
|
AUTH_CREDENTIALS_INVALID: "Invalid credentials",
|
|
73
|
-
AUTH_TOKEN_INVALID: "JWT token is invalid or expired"
|
|
81
|
+
AUTH_TOKEN_INVALID: "JWT token is invalid or expired",
|
|
82
|
+
CF7_MAIL_SENT: "Thank you for your message.",
|
|
83
|
+
CF7_MAIL_FAILED: "There was an error trying to send your message.",
|
|
84
|
+
CF7_VALIDATION_FAILED: "One or more fields have an error. Please check and try again.",
|
|
85
|
+
CF7_SPAM: "There was an error trying to send your message. Please try later.",
|
|
86
|
+
CF7_ABORTED: "Message submission has been aborted."
|
|
74
87
|
};
|
|
75
88
|
function resolveMessage(code, overrides) {
|
|
76
89
|
return overrides?.[code] ?? defaultMessages[code];
|
|
@@ -1457,11 +1470,64 @@ function useWPULike(config, params, swrOptions) {
|
|
|
1457
1470
|
return { data, error, isLoading, vote };
|
|
1458
1471
|
}
|
|
1459
1472
|
|
|
1473
|
+
// src/integrations/restApi/contactForm7/types.ts
|
|
1474
|
+
var CF7Error = class extends Error {
|
|
1475
|
+
constructor(code, status, endpoint, message) {
|
|
1476
|
+
super(message);
|
|
1477
|
+
__publicField(this, "code", code);
|
|
1478
|
+
__publicField(this, "status", status);
|
|
1479
|
+
__publicField(this, "endpoint", endpoint);
|
|
1480
|
+
this.name = "CF7Error";
|
|
1481
|
+
}
|
|
1482
|
+
};
|
|
1483
|
+
|
|
1484
|
+
// src/integrations/restApi/contactForm7/queries.ts
|
|
1485
|
+
var statusToCode = {
|
|
1486
|
+
mail_sent: ErrorCode.CF7_MAIL_SENT,
|
|
1487
|
+
mail_failed: ErrorCode.CF7_MAIL_FAILED,
|
|
1488
|
+
validation_failed: ErrorCode.CF7_VALIDATION_FAILED,
|
|
1489
|
+
spam: ErrorCode.CF7_SPAM,
|
|
1490
|
+
aborted: ErrorCode.CF7_ABORTED
|
|
1491
|
+
};
|
|
1492
|
+
function createCF7Queries(config) {
|
|
1493
|
+
async function submitForm(formId, data) {
|
|
1494
|
+
const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
|
|
1495
|
+
const body = new FormData();
|
|
1496
|
+
for (const [key, value] of Object.entries(data)) {
|
|
1497
|
+
body.append(key, value);
|
|
1498
|
+
}
|
|
1499
|
+
const res = await fetch(url, { method: "POST", body, cache: "no-store" });
|
|
1500
|
+
if (!res.ok) {
|
|
1501
|
+
throw new CF7Error(
|
|
1502
|
+
ErrorCode.CF7_MAIL_FAILED,
|
|
1503
|
+
res.status,
|
|
1504
|
+
url,
|
|
1505
|
+
resolveMessage(ErrorCode.CF7_MAIL_FAILED, config.errorMessages)
|
|
1506
|
+
);
|
|
1507
|
+
}
|
|
1508
|
+
const result = await res.json();
|
|
1509
|
+
const code = statusToCode[result.status];
|
|
1510
|
+
return { ...result, message: resolveMessage(code, config.errorMessages) };
|
|
1511
|
+
}
|
|
1512
|
+
return { submitForm };
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
// src/hooks/contactForm7/useCF7Submit.ts
|
|
1516
|
+
function useCF7Submit(config) {
|
|
1517
|
+
return useSWRMutation__default.default(
|
|
1518
|
+
`cf7-submit:${config.serverURL}`,
|
|
1519
|
+
async (_, { arg }) => {
|
|
1520
|
+
return createCF7Queries(config).submitForm(arg.formId, arg.fields);
|
|
1521
|
+
}
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1460
1525
|
exports.AuthProvider = AuthProvider;
|
|
1461
1526
|
exports.CartProvider = CartProvider;
|
|
1462
1527
|
exports.WooCommerceCustomerProvider = WooCommerceCustomerProvider;
|
|
1463
1528
|
exports.cartReducer = cartReducer;
|
|
1464
1529
|
exports.useAuth = useAuth;
|
|
1530
|
+
exports.useCF7Submit = useCF7Submit;
|
|
1465
1531
|
exports.useCart = useCart;
|
|
1466
1532
|
exports.useCookieConsent = useCookieConsent;
|
|
1467
1533
|
exports.useCustomer = useCustomer;
|