@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.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { AuthContextValue, AuthProvider, AuthUser, CartAction, CartContextValue, CartItem, CartProvider, CheckoutOptions, CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats } from '../hooks/index.cjs';
|
|
1
|
+
export { AuthContextValue, AuthProvider, AuthUser, CartAction, CartContextValue, CartItem, CartProvider, CheckoutOptions, CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats } from '../hooks/index.cjs';
|
|
2
2
|
import 'react';
|
|
3
|
-
import '../types-
|
|
3
|
+
import '../types-D6rih4G8.cjs';
|
|
4
4
|
import 'swr';
|
|
5
|
+
import 'swr/mutation';
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { AuthContextValue, AuthProvider, AuthUser, CartAction, CartContextValue, CartItem, CartProvider, CheckoutOptions, CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats } from '../hooks/index.js';
|
|
1
|
+
export { AuthContextValue, AuthProvider, AuthUser, CartAction, CartContextValue, CartItem, CartProvider, CheckoutOptions, CustomerContextValue, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats } from '../hooks/index.js';
|
|
2
2
|
import 'react';
|
|
3
|
-
import '../types-
|
|
3
|
+
import '../types-D6rih4G8.js';
|
|
4
4
|
import 'swr';
|
|
5
|
+
import 'swr/mutation';
|
package/dist/client/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createContext, useState, useCallback, useEffect, useContext, useReducer } from 'react';
|
|
2
2
|
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
import useSWR2 from 'swr';
|
|
4
|
+
import useSWRMutation from 'swr/mutation';
|
|
4
5
|
|
|
5
6
|
var __defProp = Object.defineProperty;
|
|
6
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -39,7 +40,13 @@ var ErrorCode = {
|
|
|
39
40
|
// Auth
|
|
40
41
|
AUTH_JWT_FAILED: "AUTH_JWT_FAILED",
|
|
41
42
|
AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID",
|
|
42
|
-
AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID"
|
|
43
|
+
AUTH_TOKEN_INVALID: "AUTH_TOKEN_INVALID",
|
|
44
|
+
// Contact Form 7
|
|
45
|
+
CF7_MAIL_SENT: "CF7_MAIL_SENT",
|
|
46
|
+
CF7_MAIL_FAILED: "CF7_MAIL_FAILED",
|
|
47
|
+
CF7_VALIDATION_FAILED: "CF7_VALIDATION_FAILED",
|
|
48
|
+
CF7_SPAM: "CF7_SPAM",
|
|
49
|
+
CF7_ABORTED: "CF7_ABORTED"
|
|
43
50
|
};
|
|
44
51
|
var defaultMessages = {
|
|
45
52
|
WP_REQUEST_FAILED: "WordPress API request failed",
|
|
@@ -64,7 +71,12 @@ var defaultMessages = {
|
|
|
64
71
|
WOO_SHIPPING_ZONE_NOT_FOUND: "Shipping zone not found",
|
|
65
72
|
AUTH_JWT_FAILED: "JWT authentication failed",
|
|
66
73
|
AUTH_CREDENTIALS_INVALID: "Invalid credentials",
|
|
67
|
-
AUTH_TOKEN_INVALID: "JWT token is invalid or expired"
|
|
74
|
+
AUTH_TOKEN_INVALID: "JWT token is invalid or expired",
|
|
75
|
+
CF7_MAIL_SENT: "Thank you for your message.",
|
|
76
|
+
CF7_MAIL_FAILED: "There was an error trying to send your message.",
|
|
77
|
+
CF7_VALIDATION_FAILED: "One or more fields have an error. Please check and try again.",
|
|
78
|
+
CF7_SPAM: "There was an error trying to send your message. Please try later.",
|
|
79
|
+
CF7_ABORTED: "Message submission has been aborted."
|
|
68
80
|
};
|
|
69
81
|
function resolveMessage(code, overrides) {
|
|
70
82
|
return overrides?.[code] ?? defaultMessages[code];
|
|
@@ -1451,6 +1463,58 @@ function useWPULike(config, params, swrOptions) {
|
|
|
1451
1463
|
return { data, error, isLoading, vote };
|
|
1452
1464
|
}
|
|
1453
1465
|
|
|
1454
|
-
|
|
1466
|
+
// src/integrations/restApi/contactForm7/types.ts
|
|
1467
|
+
var CF7Error = class extends Error {
|
|
1468
|
+
constructor(code, status, endpoint, message) {
|
|
1469
|
+
super(message);
|
|
1470
|
+
__publicField(this, "code", code);
|
|
1471
|
+
__publicField(this, "status", status);
|
|
1472
|
+
__publicField(this, "endpoint", endpoint);
|
|
1473
|
+
this.name = "CF7Error";
|
|
1474
|
+
}
|
|
1475
|
+
};
|
|
1476
|
+
|
|
1477
|
+
// src/integrations/restApi/contactForm7/queries.ts
|
|
1478
|
+
var statusToCode = {
|
|
1479
|
+
mail_sent: ErrorCode.CF7_MAIL_SENT,
|
|
1480
|
+
mail_failed: ErrorCode.CF7_MAIL_FAILED,
|
|
1481
|
+
validation_failed: ErrorCode.CF7_VALIDATION_FAILED,
|
|
1482
|
+
spam: ErrorCode.CF7_SPAM,
|
|
1483
|
+
aborted: ErrorCode.CF7_ABORTED
|
|
1484
|
+
};
|
|
1485
|
+
function createCF7Queries(config) {
|
|
1486
|
+
async function submitForm(formId, data) {
|
|
1487
|
+
const url = buildUrl(config, `/wp-json/contact-form-7/v1/contact-forms/${formId}/feedback`);
|
|
1488
|
+
const body = new FormData();
|
|
1489
|
+
for (const [key, value] of Object.entries(data)) {
|
|
1490
|
+
body.append(key, value);
|
|
1491
|
+
}
|
|
1492
|
+
const res = await fetch(url, { method: "POST", body, cache: "no-store" });
|
|
1493
|
+
if (!res.ok) {
|
|
1494
|
+
throw new CF7Error(
|
|
1495
|
+
ErrorCode.CF7_MAIL_FAILED,
|
|
1496
|
+
res.status,
|
|
1497
|
+
url,
|
|
1498
|
+
resolveMessage(ErrorCode.CF7_MAIL_FAILED, config.errorMessages)
|
|
1499
|
+
);
|
|
1500
|
+
}
|
|
1501
|
+
const result = await res.json();
|
|
1502
|
+
const code = statusToCode[result.status];
|
|
1503
|
+
return { ...result, message: resolveMessage(code, config.errorMessages) };
|
|
1504
|
+
}
|
|
1505
|
+
return { submitForm };
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
// src/hooks/contactForm7/useCF7Submit.ts
|
|
1509
|
+
function useCF7Submit(config) {
|
|
1510
|
+
return useSWRMutation(
|
|
1511
|
+
`cf7-submit:${config.serverURL}`,
|
|
1512
|
+
async (_, { arg }) => {
|
|
1513
|
+
return createCF7Queries(config).submitForm(arg.formId, arg.fields);
|
|
1514
|
+
}
|
|
1515
|
+
);
|
|
1516
|
+
}
|
|
1517
|
+
|
|
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 };
|
|
1455
1519
|
//# sourceMappingURL=index.js.map
|
|
1456
1520
|
//# sourceMappingURL=index.js.map
|