@q2devel/q2-core 1.0.15 → 1.0.17
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/api/products/getProducts.d.ts +3 -2
- package/dist/api/products/getProducts.d.ts.map +1 -1
- package/dist/api/products/getProducts.js +20 -13
- package/dist/hooks/products/useGetProducts.d.ts +22 -0
- package/dist/hooks/products/useGetProducts.d.ts.map +1 -0
- package/dist/hooks/products/useGetProducts.js +35 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CoreContext } from '../../context';
|
|
2
2
|
import { Product } from '../../types/products/Product';
|
|
3
3
|
type GetProductsParams = {
|
|
4
|
+
locale?: string;
|
|
4
5
|
categoryId?: string[];
|
|
5
6
|
productId?: string;
|
|
6
7
|
searchTerm?: string;
|
|
@@ -17,12 +18,12 @@ type GetProductsParams = {
|
|
|
17
18
|
cache?: boolean;
|
|
18
19
|
mapFnVariations?: (base: Product, raw: any) => Product | Promise<Product>;
|
|
19
20
|
};
|
|
20
|
-
export declare const getProducts: (ctx: CoreContext, { categoryId, productId, searchTerm, limit, offset, filters, sort, tag, include, cache, mapFnVariations, }: GetProductsParams) => Promise<Product[]>;
|
|
21
|
+
export declare const getProducts: (ctx: CoreContext, { locale, categoryId, productId, searchTerm, limit, offset, filters, sort, tag, include, cache, mapFnVariations, }: GetProductsParams) => Promise<Product[]>;
|
|
21
22
|
type GetProductCountParams = {
|
|
22
23
|
categoryId?: string[];
|
|
23
24
|
tag?: string;
|
|
24
25
|
cache?: boolean;
|
|
25
26
|
};
|
|
26
|
-
export declare const getProductCount: (ctx: CoreContext, { categoryId, tag, cache
|
|
27
|
+
export declare const getProductCount: (ctx: CoreContext, { categoryId, tag, cache }: GetProductCountParams) => Promise<number>;
|
|
27
28
|
export {};
|
|
28
29
|
//# sourceMappingURL=getProducts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getProducts.d.ts","sourceRoot":"","sources":["../../../api/products/getProducts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getProducts.d.ts","sourceRoot":"","sources":["../../../api/products/getProducts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAKtD,KAAK,iBAAiB,GAAG;IACrB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAA;QAC/B,QAAQ,CAAC,EAAE,MAAM,CAAA;KACpB,CAAC,CAAA;IACF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAC5E,CAAA;AAED,eAAO,MAAM,WAAW,GACpB,KAAK,WAAW,EAChB,oHAmBG,iBAAiB,KACrB,OAAO,CAAC,OAAO,EAAE,CA8DnB,CAAA;AAED,KAAK,qBAAqB,GAAG;IACzB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED,eAAO,MAAM,eAAe,GACxB,KAAK,WAAW,EAChB,4BAA6C,qBAAqB,KACnE,OAAO,CAAC,MAAM,CAqChB,CAAA"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
|
|
2
|
-
import mapIncludedResources from '../../utils/mapIncludedResources';
|
|
3
2
|
import { handleSortChange } from '../../utils/generalHelper';
|
|
3
|
+
import mapIncludedResources from '../../utils/mapIncludedResources';
|
|
4
4
|
import { mapProduct } from '../../utils/mapProducts';
|
|
5
|
-
export const getProducts = async (ctx, { categoryId, productId, searchTerm, limit, offset, filters = [], sort = '', tag = '', include = [
|
|
5
|
+
export const getProducts = async (ctx, { locale, categoryId, productId, searchTerm, limit, offset, filters = [], sort = '', tag = '', include = [
|
|
6
6
|
'product_id',
|
|
7
7
|
'product_id.field_category',
|
|
8
8
|
'product_id.field_image',
|
|
9
9
|
'product_id.field_image.field_media_image',
|
|
10
10
|
'field_image.field_media_image',
|
|
11
11
|
], cache = true, mapFnVariations, }) => {
|
|
12
|
-
const
|
|
12
|
+
const currentLocale = locale || ctx.locale;
|
|
13
|
+
const cacheKey = [
|
|
14
|
+
'products',
|
|
15
|
+
currentLocale,
|
|
13
16
|
categoryId?.length ? `cat:${categoryId.join(',')}` : '',
|
|
14
17
|
productId ? `id:${productId}` : '',
|
|
15
18
|
searchTerm ? `search:${searchTerm}` : '',
|
|
@@ -18,7 +21,9 @@ export const getProducts = async (ctx, { categoryId, productId, searchTerm, limi
|
|
|
18
21
|
filters.length ? `filters:${JSON.stringify(filters)}` : '',
|
|
19
22
|
sort ? `sort:${sort}` : '',
|
|
20
23
|
// tag ? `tag:${tag}` : '',
|
|
21
|
-
]
|
|
24
|
+
]
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.join(':');
|
|
22
27
|
if (cache && ctx.getCache) {
|
|
23
28
|
const cached = await ctx.getCache(cacheKey);
|
|
24
29
|
if (cached)
|
|
@@ -26,7 +31,7 @@ export const getProducts = async (ctx, { categoryId, productId, searchTerm, limi
|
|
|
26
31
|
}
|
|
27
32
|
const params = new DrupalJsonApiParams()
|
|
28
33
|
.addInclude(include)
|
|
29
|
-
.addFilter('langcode',
|
|
34
|
+
.addFilter('langcode', currentLocale);
|
|
30
35
|
if (tag)
|
|
31
36
|
params.addFilter(`product_id.${tag}`, '1');
|
|
32
37
|
if (categoryId)
|
|
@@ -45,9 +50,9 @@ export const getProducts = async (ctx, { categoryId, productId, searchTerm, limi
|
|
|
45
50
|
params.addSort(sortData.title, sortData.direction);
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
|
-
const url =
|
|
53
|
+
const url = currentLocale === ctx.defaultLocale
|
|
49
54
|
? `/jsonapi/index/variation`
|
|
50
|
-
: `/${
|
|
55
|
+
: `/${currentLocale}/jsonapi/index/variation`;
|
|
51
56
|
const { data } = await ctx.axios.get(`${url}?${params.getQueryString()}`);
|
|
52
57
|
const resolvedProducts = mapIncludedResources(data, 5);
|
|
53
58
|
const mappedProducts = await Promise.all(resolvedProducts.map(async (item) => {
|
|
@@ -62,11 +67,15 @@ export const getProducts = async (ctx, { categoryId, productId, searchTerm, limi
|
|
|
62
67
|
}
|
|
63
68
|
return mappedProducts;
|
|
64
69
|
};
|
|
65
|
-
export const getProductCount = async (ctx, { categoryId = [], tag = '', cache = true
|
|
66
|
-
const cacheKey = [
|
|
70
|
+
export const getProductCount = async (ctx, { categoryId = [], tag = '', cache = true }) => {
|
|
71
|
+
const cacheKey = [
|
|
72
|
+
'productCount',
|
|
73
|
+
ctx.locale,
|
|
67
74
|
categoryId?.length ? `cat:${categoryId.join(',')}` : '',
|
|
68
75
|
tag ? `tag:${tag}` : '',
|
|
69
|
-
]
|
|
76
|
+
]
|
|
77
|
+
.filter(Boolean)
|
|
78
|
+
.join(':');
|
|
70
79
|
// if (cache && ctx.getCache) {
|
|
71
80
|
// const cached = await ctx.getCache<number>(cacheKey);
|
|
72
81
|
// if (cached !== null) return cached;
|
|
@@ -78,9 +87,7 @@ export const getProductCount = async (ctx, { categoryId = [], tag = '', cache =
|
|
|
78
87
|
if (tag) {
|
|
79
88
|
params.addFilter(`product_id.${tag}`, '1');
|
|
80
89
|
}
|
|
81
|
-
params
|
|
82
|
-
.addFilter('langcode', ctx.locale)
|
|
83
|
-
.addPageLimit(1);
|
|
90
|
+
params.addFilter('langcode', ctx.locale).addPageLimit(1);
|
|
84
91
|
const url = ctx.locale === ctx.defaultLocale
|
|
85
92
|
? `/jsonapi/index/variation`
|
|
86
93
|
: `/${ctx.locale}/jsonapi/index/variation`;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CoreContext } from '../../context';
|
|
2
|
+
type UseGetProductsOptions = {
|
|
3
|
+
categoryId?: string[];
|
|
4
|
+
productId?: string;
|
|
5
|
+
searchTerm?: string;
|
|
6
|
+
limit?: number;
|
|
7
|
+
offset?: number;
|
|
8
|
+
filters?: Array<{
|
|
9
|
+
path: string;
|
|
10
|
+
value: string | string[] | null;
|
|
11
|
+
operator?: string;
|
|
12
|
+
}>;
|
|
13
|
+
sort?: string;
|
|
14
|
+
tag?: string;
|
|
15
|
+
include?: string[];
|
|
16
|
+
cache?: boolean;
|
|
17
|
+
mapFnVariations?: (base: any, raw: any) => any;
|
|
18
|
+
enabled?: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare const useGetProducts: (ctx: CoreContext, locale: string, options?: UseGetProductsOptions) => import("@tanstack/react-query").UseQueryResult<import("../..").Product[], Error>;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=useGetProducts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGetProducts.d.ts","sourceRoot":"","sources":["../../../hooks/products/useGetProducts.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAE3C,KAAK,qBAAqB,GAAG;IACzB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,KAAK,CAAC;QACZ,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAA;QAC/B,QAAQ,CAAC,EAAE,MAAM,CAAA;KACpB,CAAC,CAAA;IACF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,GAAG,CAAA;IAC9C,OAAO,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,cAAc,GACvB,KAAK,WAAW,EAChB,QAAQ,MAAM,EACd,UAAU,qBAAqB,qFAgDlC,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { getProducts } from '../../api/products/getProducts';
|
|
3
|
+
export const useGetProducts = (ctx, locale, options) => {
|
|
4
|
+
const { categoryId, productId, searchTerm, limit, offset, filters, sort, tag, include, cache, mapFnVariations, enabled = true, } = options || {};
|
|
5
|
+
return useQuery({
|
|
6
|
+
queryKey: [
|
|
7
|
+
'products',
|
|
8
|
+
locale,
|
|
9
|
+
categoryId,
|
|
10
|
+
productId,
|
|
11
|
+
searchTerm,
|
|
12
|
+
limit,
|
|
13
|
+
offset,
|
|
14
|
+
filters,
|
|
15
|
+
sort,
|
|
16
|
+
tag,
|
|
17
|
+
include,
|
|
18
|
+
],
|
|
19
|
+
queryFn: () => getProducts(ctx, {
|
|
20
|
+
locale,
|
|
21
|
+
categoryId,
|
|
22
|
+
productId,
|
|
23
|
+
searchTerm,
|
|
24
|
+
limit,
|
|
25
|
+
offset,
|
|
26
|
+
filters,
|
|
27
|
+
sort,
|
|
28
|
+
tag,
|
|
29
|
+
include,
|
|
30
|
+
cache,
|
|
31
|
+
mapFnVariations,
|
|
32
|
+
}),
|
|
33
|
+
enabled,
|
|
34
|
+
});
|
|
35
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ export * from './api/checkout/Checkout.service';
|
|
|
26
26
|
export * from './api/checkout/CheckoutService.types';
|
|
27
27
|
export * from './hooks/cart/api/useGetOrderHistory';
|
|
28
28
|
export * from './hooks/wishlist/useWishlist';
|
|
29
|
+
export * from './hooks/products/useGetProducts';
|
|
29
30
|
export * from './context';
|
|
30
31
|
export * from './context/cart/BasketContext';
|
|
31
32
|
export * from './api/cart/Cart.service';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AAErC,cAAc,yBAAyB,CAAA;AACvC,cAAc,sBAAsB,CAAA;AAGpC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAG5B,cAAc,4BAA4B,CAAA;AAC1C,cAAc,0BAA0B,CAAA;AAGxC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,oCAAoC,CAAA;AAElD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kCAAkC,CAAA;AAEhD,cAAc,mCAAmC,CAAA;AACjD,cAAc,wCAAwC,CAAA;AAGtD,cAAc,sCAAsC,CAAA;AACpD,cAAc,gDAAgD,CAAA;AAC9D,cAAc,yBAAyB,CAAA;AAGvC,cAAc,kBAAkB,CAAA;AAChC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,c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6 +32,7 @@ export * from './api/checkout/Checkout.service';
|
|
|
32
32
|
export * from './api/checkout/CheckoutService.types';
|
|
33
33
|
export * from './hooks/cart/api/useGetOrderHistory';
|
|
34
34
|
export * from './hooks/wishlist/useWishlist';
|
|
35
|
+
export * from './hooks/products/useGetProducts';
|
|
35
36
|
export * from './context';
|
|
36
37
|
export * from './context/cart/BasketContext';
|
|
37
38
|
export * from './api/cart/Cart.service';
|