@szymonpiatek/nextwordpress 0.0.18 → 0.0.19
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 +126 -0
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +2 -2
- package/dist/client/index.d.ts +2 -2
- package/dist/client/index.js +125 -1
- package/dist/client/index.js.map +1 -1
- package/dist/hooks/index.cjs +126 -0
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +5 -2
- package/dist/hooks/index.d.ts +5 -2
- package/dist/hooks/index.js +125 -1
- package/dist/hooks/index.js.map +1 -1
- package/dist/index.cjs +150 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -3
- package/dist/index.d.ts +34 -3
- package/dist/index.js +147 -9
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +150 -8
- 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 +147 -9
- package/dist/server/index.js.map +1 -1
- package/dist/{types-CM3v08Fh.d.cts → types-DUmH-vcl.d.cts} +41 -1
- package/dist/{types-CM3v08Fh.d.ts → types-DUmH-vcl.d.ts} +41 -1
- package/package.json +1 -1
package/dist/hooks/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { J as JwtAuthCredentials, N as NextWordpressConfig, W as WPGraphQLConfig, G as GQLSendPasswordResetEmailResult, a as GQLResetUserPasswordResult, R as RestSendPasswordResetEmailResult, b as RestResetUserPasswordResult, C as CookieConsentCategories, P as Post, c as WordPressResponse, d as WooCommerceConfig, e as WCProduct, f as WCProductFilterParams, g as WooCommerceResponse, h as WCCreateOrderInput, i as WCOrder, j as WCCustomer, U as UpdateCustomerInput, k as
|
|
3
|
+
import { J as JwtAuthCredentials, N as NextWordpressConfig, W as WPGraphQLConfig, G as GQLSendPasswordResetEmailResult, a as GQLResetUserPasswordResult, R as RestSendPasswordResetEmailResult, b as RestResetUserPasswordResult, C as CookieConsentCategories, P as Post, c as WordPressResponse, d as WooCommerceConfig, e as WCProduct, f as WCProductFilterParams, g as WooCommerceResponse, h as WCCreateOrderInput, i as WCOrder, j as WCCustomer, U as UpdateCustomerInput, Y as YithWishlistConfig, k as WCWishlist, l as GQLPost, m as GQLPostFilter, n as GQLConnection, o as WPULikeStatsParams, p as WPULikeStats, q as WPULikeStatus, r as WPULikeVoteResponse, s as WPULikeCheckParams, t as WPULikeCheckResponse, u as CF7SubmissionResponse } from '../types-DUmH-vcl.cjs';
|
|
4
4
|
import * as swr_mutation from 'swr/mutation';
|
|
5
5
|
import * as swr from 'swr';
|
|
6
6
|
import { SWRConfiguration } from 'swr';
|
|
@@ -141,6 +141,9 @@ declare function WooCommerceCustomerProvider({ config, children, }: {
|
|
|
141
141
|
}): react.JSX.Element;
|
|
142
142
|
declare function useCustomer(): CustomerContextValue;
|
|
143
143
|
|
|
144
|
+
declare function useWishlists(config: YithWishlistConfig, swrOptions?: SWRConfiguration<WCWishlist[]>): swr.SWRResponse<WCWishlist[], any, SWRConfiguration<WCWishlist[], any, swr.BareFetcher<WCWishlist[]>> | undefined>;
|
|
145
|
+
declare function useWishlist(config: YithWishlistConfig, wishlistToken: string | null | undefined, swrOptions?: SWRConfiguration<WCWishlist>): swr.SWRResponse<WCWishlist, any, SWRConfiguration<WCWishlist, any, swr.BareFetcher<WCWishlist>> | undefined>;
|
|
146
|
+
|
|
144
147
|
declare function useWPGraphQL<TData>(config: WPGraphQLConfig, query: string, variables?: Record<string, unknown>, tags?: string[], swrOptions?: SWRConfiguration<TData>): swr.SWRResponse<TData, any, SWRConfiguration<TData, any, swr.BareFetcher<TData>> | undefined>;
|
|
145
148
|
declare function useGQLPosts(config: WPGraphQLConfig, first?: number, after?: string, filter?: GQLPostFilter, swrOptions?: SWRConfiguration<GQLConnection<GQLPost>>): swr.SWRResponse<GQLConnection<GQLPost>, any, SWRConfiguration<GQLConnection<GQLPost>, any, swr.BareFetcher<GQLConnection<GQLPost>>> | undefined>;
|
|
146
149
|
declare function useGQLPostBySlug(config: WPGraphQLConfig, slug: string | null | undefined, swrOptions?: SWRConfiguration<GQLPost | null>): swr.SWRResponse<GQLPost | null, any, SWRConfiguration<GQLPost | null, any, swr.BareFetcher<GQLPost | null>> | undefined>;
|
|
@@ -160,4 +163,4 @@ type CF7SubmitArg = {
|
|
|
160
163
|
};
|
|
161
164
|
declare function useCF7Submit(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<CF7SubmissionResponse, Error, string, CF7SubmitArg>;
|
|
162
165
|
|
|
163
|
-
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, useResetUserPasswordRest, useSendPasswordResetEmail, useSendPasswordResetEmailRest, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
|
|
166
|
+
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, useResetUserPasswordRest, useSendPasswordResetEmail, useSendPasswordResetEmailRest, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats, useWishlist, useWishlists };
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { J as JwtAuthCredentials, N as NextWordpressConfig, W as WPGraphQLConfig, G as GQLSendPasswordResetEmailResult, a as GQLResetUserPasswordResult, R as RestSendPasswordResetEmailResult, b as RestResetUserPasswordResult, C as CookieConsentCategories, P as Post, c as WordPressResponse, d as WooCommerceConfig, e as WCProduct, f as WCProductFilterParams, g as WooCommerceResponse, h as WCCreateOrderInput, i as WCOrder, j as WCCustomer, U as UpdateCustomerInput, k as
|
|
3
|
+
import { J as JwtAuthCredentials, N as NextWordpressConfig, W as WPGraphQLConfig, G as GQLSendPasswordResetEmailResult, a as GQLResetUserPasswordResult, R as RestSendPasswordResetEmailResult, b as RestResetUserPasswordResult, C as CookieConsentCategories, P as Post, c as WordPressResponse, d as WooCommerceConfig, e as WCProduct, f as WCProductFilterParams, g as WooCommerceResponse, h as WCCreateOrderInput, i as WCOrder, j as WCCustomer, U as UpdateCustomerInput, Y as YithWishlistConfig, k as WCWishlist, l as GQLPost, m as GQLPostFilter, n as GQLConnection, o as WPULikeStatsParams, p as WPULikeStats, q as WPULikeStatus, r as WPULikeVoteResponse, s as WPULikeCheckParams, t as WPULikeCheckResponse, u as CF7SubmissionResponse } from '../types-DUmH-vcl.js';
|
|
4
4
|
import * as swr_mutation from 'swr/mutation';
|
|
5
5
|
import * as swr from 'swr';
|
|
6
6
|
import { SWRConfiguration } from 'swr';
|
|
@@ -141,6 +141,9 @@ declare function WooCommerceCustomerProvider({ config, children, }: {
|
|
|
141
141
|
}): react.JSX.Element;
|
|
142
142
|
declare function useCustomer(): CustomerContextValue;
|
|
143
143
|
|
|
144
|
+
declare function useWishlists(config: YithWishlistConfig, swrOptions?: SWRConfiguration<WCWishlist[]>): swr.SWRResponse<WCWishlist[], any, SWRConfiguration<WCWishlist[], any, swr.BareFetcher<WCWishlist[]>> | undefined>;
|
|
145
|
+
declare function useWishlist(config: YithWishlistConfig, wishlistToken: string | null | undefined, swrOptions?: SWRConfiguration<WCWishlist>): swr.SWRResponse<WCWishlist, any, SWRConfiguration<WCWishlist, any, swr.BareFetcher<WCWishlist>> | undefined>;
|
|
146
|
+
|
|
144
147
|
declare function useWPGraphQL<TData>(config: WPGraphQLConfig, query: string, variables?: Record<string, unknown>, tags?: string[], swrOptions?: SWRConfiguration<TData>): swr.SWRResponse<TData, any, SWRConfiguration<TData, any, swr.BareFetcher<TData>> | undefined>;
|
|
145
148
|
declare function useGQLPosts(config: WPGraphQLConfig, first?: number, after?: string, filter?: GQLPostFilter, swrOptions?: SWRConfiguration<GQLConnection<GQLPost>>): swr.SWRResponse<GQLConnection<GQLPost>, any, SWRConfiguration<GQLConnection<GQLPost>, any, swr.BareFetcher<GQLConnection<GQLPost>>> | undefined>;
|
|
146
149
|
declare function useGQLPostBySlug(config: WPGraphQLConfig, slug: string | null | undefined, swrOptions?: SWRConfiguration<GQLPost | null>): swr.SWRResponse<GQLPost | null, any, SWRConfiguration<GQLPost | null, any, swr.BareFetcher<GQLPost | null>> | undefined>;
|
|
@@ -160,4 +163,4 @@ type CF7SubmitArg = {
|
|
|
160
163
|
};
|
|
161
164
|
declare function useCF7Submit(config: NextWordpressConfig): swr_mutation.SWRMutationResponse<CF7SubmissionResponse, Error, string, CF7SubmitArg>;
|
|
162
165
|
|
|
163
|
-
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, useResetUserPasswordRest, useSendPasswordResetEmail, useSendPasswordResetEmailRest, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
|
|
166
|
+
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, useResetUserPasswordRest, useSendPasswordResetEmail, useSendPasswordResetEmailRest, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats, useWishlist, useWishlists };
|
package/dist/hooks/index.js
CHANGED
|
@@ -37,6 +37,8 @@ var ErrorCode = {
|
|
|
37
37
|
WOO_REVIEW_NOT_FOUND: "WOO_REVIEW_NOT_FOUND",
|
|
38
38
|
WOO_WEBHOOK_NOT_FOUND: "WOO_WEBHOOK_NOT_FOUND",
|
|
39
39
|
WOO_SHIPPING_ZONE_NOT_FOUND: "WOO_SHIPPING_ZONE_NOT_FOUND",
|
|
40
|
+
WOO_WISHLIST_NOT_FOUND: "WOO_WISHLIST_NOT_FOUND",
|
|
41
|
+
WOO_WISHLIST_ITEM_NOT_FOUND: "WOO_WISHLIST_ITEM_NOT_FOUND",
|
|
40
42
|
// Auth
|
|
41
43
|
AUTH_JWT_FAILED: "AUTH_JWT_FAILED",
|
|
42
44
|
AUTH_CREDENTIALS_INVALID: "AUTH_CREDENTIALS_INVALID",
|
|
@@ -69,6 +71,8 @@ var defaultMessages = {
|
|
|
69
71
|
WOO_REVIEW_NOT_FOUND: "Product review not found",
|
|
70
72
|
WOO_WEBHOOK_NOT_FOUND: "Webhook not found",
|
|
71
73
|
WOO_SHIPPING_ZONE_NOT_FOUND: "Shipping zone not found",
|
|
74
|
+
WOO_WISHLIST_NOT_FOUND: "Wishlist not found",
|
|
75
|
+
WOO_WISHLIST_ITEM_NOT_FOUND: "Wishlist item not found",
|
|
72
76
|
AUTH_JWT_FAILED: "JWT authentication failed",
|
|
73
77
|
AUTH_CREDENTIALS_INVALID: "Invalid credentials",
|
|
74
78
|
AUTH_TOKEN_INVALID: "JWT token is invalid or expired",
|
|
@@ -1304,6 +1308,126 @@ function useCustomer() {
|
|
|
1304
1308
|
return ctx;
|
|
1305
1309
|
}
|
|
1306
1310
|
|
|
1311
|
+
// src/integrations/restApi/woocommerce/wishlist/fetcher.ts
|
|
1312
|
+
var USER_AGENT4 = "NextWordpress YITH Wishlist Client";
|
|
1313
|
+
var DEFAULT_CACHE_TTL2 = 3600;
|
|
1314
|
+
var YithWishlistError = class extends Error {
|
|
1315
|
+
constructor(code, status, url, message, upstreamCode, upstreamMessage) {
|
|
1316
|
+
super(message);
|
|
1317
|
+
__publicField(this, "code", code);
|
|
1318
|
+
__publicField(this, "status", status);
|
|
1319
|
+
__publicField(this, "url", url);
|
|
1320
|
+
__publicField(this, "upstreamCode", upstreamCode);
|
|
1321
|
+
__publicField(this, "upstreamMessage", upstreamMessage);
|
|
1322
|
+
this.name = "YithWishlistError";
|
|
1323
|
+
}
|
|
1324
|
+
};
|
|
1325
|
+
function resolveYithErrorCode(status, upstreamCode) {
|
|
1326
|
+
if (status === 401) return ErrorCode.WOO_UNAUTHORIZED;
|
|
1327
|
+
if (status === 403) return ErrorCode.WOO_FORBIDDEN;
|
|
1328
|
+
if (status === 404) {
|
|
1329
|
+
if (upstreamCode === "yith_wcwl_wishlist_not_found") return ErrorCode.WOO_WISHLIST_NOT_FOUND;
|
|
1330
|
+
if (upstreamCode === "yith_wcwl_wishlist_item_not_found")
|
|
1331
|
+
return ErrorCode.WOO_WISHLIST_ITEM_NOT_FOUND;
|
|
1332
|
+
return ErrorCode.WOO_NOT_FOUND;
|
|
1333
|
+
}
|
|
1334
|
+
return ErrorCode.WOO_REQUEST_FAILED;
|
|
1335
|
+
}
|
|
1336
|
+
function createYithWishlistFetcher(config) {
|
|
1337
|
+
const cacheTTL = config.cacheTTL ?? DEFAULT_CACHE_TTL2;
|
|
1338
|
+
function buildUrl2(path) {
|
|
1339
|
+
const base = typeof window !== "undefined" && config.clientURL ? config.clientURL : config.serverURL;
|
|
1340
|
+
return `${base}${path}`;
|
|
1341
|
+
}
|
|
1342
|
+
function authHeaders() {
|
|
1343
|
+
return {
|
|
1344
|
+
"User-Agent": USER_AGENT4,
|
|
1345
|
+
"Content-Type": "application/json",
|
|
1346
|
+
Authorization: `Bearer ${config.token}`
|
|
1347
|
+
};
|
|
1348
|
+
}
|
|
1349
|
+
async function throwYithError(response, url) {
|
|
1350
|
+
const body = await response.json().catch(() => ({}));
|
|
1351
|
+
const errorCode = resolveYithErrorCode(response.status, body.code);
|
|
1352
|
+
throw new YithWishlistError(
|
|
1353
|
+
errorCode,
|
|
1354
|
+
response.status,
|
|
1355
|
+
url,
|
|
1356
|
+
resolveMessage(errorCode, config.errorMessages),
|
|
1357
|
+
body.code,
|
|
1358
|
+
body.message
|
|
1359
|
+
);
|
|
1360
|
+
}
|
|
1361
|
+
async function yithFetch(path, tags = ["yith-wishlist"], options) {
|
|
1362
|
+
const url = buildUrl2(path);
|
|
1363
|
+
const isMutation = options?.method && options.method !== "GET";
|
|
1364
|
+
const response = await fetch(url, {
|
|
1365
|
+
...options,
|
|
1366
|
+
headers: {
|
|
1367
|
+
...authHeaders(),
|
|
1368
|
+
...options?.headers
|
|
1369
|
+
},
|
|
1370
|
+
next: isMutation ? void 0 : { tags, revalidate: cacheTTL }
|
|
1371
|
+
});
|
|
1372
|
+
if (!response.ok) {
|
|
1373
|
+
await throwYithError(response, url);
|
|
1374
|
+
}
|
|
1375
|
+
return response.json();
|
|
1376
|
+
}
|
|
1377
|
+
async function yithFetchGraceful(path, fallback, tags = ["yith-wishlist"]) {
|
|
1378
|
+
try {
|
|
1379
|
+
return await yithFetch(path, tags);
|
|
1380
|
+
} catch (err) {
|
|
1381
|
+
console.warn(`YITH Wishlist fetch failed for ${path}`, err);
|
|
1382
|
+
return fallback;
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
async function yithMutate(path, body, method = "POST") {
|
|
1386
|
+
return yithFetch(path, ["yith-wishlist"], {
|
|
1387
|
+
method,
|
|
1388
|
+
body: JSON.stringify(body)
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
return { yithFetch, yithFetchGraceful, yithMutate };
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
// src/integrations/restApi/woocommerce/wishlist/queries.ts
|
|
1395
|
+
var BASE = "/wp-json/yith/wishlist/v1/wishlists";
|
|
1396
|
+
function createWishlistQueries(fetcher) {
|
|
1397
|
+
const { yithFetch, yithFetchGraceful } = fetcher;
|
|
1398
|
+
async function getWishlists() {
|
|
1399
|
+
return yithFetchGraceful(BASE, [], ["yith-wishlist", "wishlists"]);
|
|
1400
|
+
}
|
|
1401
|
+
async function getWishlistByToken(token) {
|
|
1402
|
+
return yithFetch(`${BASE}/${token}`, ["yith-wishlist", "wishlists", `wishlist-${token}`]);
|
|
1403
|
+
}
|
|
1404
|
+
return { getWishlists, getWishlistByToken };
|
|
1405
|
+
}
|
|
1406
|
+
|
|
1407
|
+
// src/hooks/woocommerce/useWishlist.ts
|
|
1408
|
+
function useWishlists(config, swrOptions) {
|
|
1409
|
+
const key = ["yith-wishlists", config.serverURL, config.token];
|
|
1410
|
+
return useSWR2(
|
|
1411
|
+
key,
|
|
1412
|
+
() => {
|
|
1413
|
+
const fetcher = createYithWishlistFetcher(config);
|
|
1414
|
+
return createWishlistQueries(fetcher).getWishlists();
|
|
1415
|
+
},
|
|
1416
|
+
swrOptions
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
function useWishlist(config, wishlistToken, swrOptions) {
|
|
1420
|
+
const key = wishlistToken != null ? ["yith-wishlist", config.serverURL, config.token, wishlistToken] : null;
|
|
1421
|
+
return useSWR2(
|
|
1422
|
+
key,
|
|
1423
|
+
() => {
|
|
1424
|
+
const fetcher = createYithWishlistFetcher(config);
|
|
1425
|
+
return createWishlistQueries(fetcher).getWishlistByToken(wishlistToken);
|
|
1426
|
+
},
|
|
1427
|
+
swrOptions
|
|
1428
|
+
);
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1307
1431
|
// src/integrations/wpGraphQL/core/posts/queries.ts
|
|
1308
1432
|
var DEFAULT_FIRST = 10;
|
|
1309
1433
|
var BATCH_FIRST = 100;
|
|
@@ -1621,6 +1745,6 @@ function useCF7Submit(config) {
|
|
|
1621
1745
|
);
|
|
1622
1746
|
}
|
|
1623
1747
|
|
|
1624
|
-
export { AuthProvider, CartProvider, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useResetUserPassword, useResetUserPasswordRest, useSendPasswordResetEmail, useSendPasswordResetEmailRest, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats };
|
|
1748
|
+
export { AuthProvider, CartProvider, WooCommerceCustomerProvider, cartReducer, useAuth, useCF7Submit, useCart, useCookieConsent, useCustomer, useFeaturedProducts, useGQLPostBySlug, useGQLPosts, usePost, usePostBySlug, usePosts, usePostsPaginated, useProduct, useProductBySlug, useProducts, useProductsPaginated, useResetUserPassword, useResetUserPasswordRest, useSendPasswordResetEmail, useSendPasswordResetEmailRest, useWPGraphQL, useWPULike, useWPULikeCheck, useWPULikeStats, useWishlist, useWishlists };
|
|
1625
1749
|
//# sourceMappingURL=index.js.map
|
|
1626
1750
|
//# sourceMappingURL=index.js.map
|