@q2devel/q2-core 1.0.16 → 1.0.18

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.
@@ -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, }: GetProductCountParams) => Promise<number>;
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":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5C,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAGvD,KAAK,iBAAiB,GAAG;IACvB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAA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d,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 cacheKey = ['products', ctx.locale,
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}` : '',
@@ -17,8 +20,10 @@ export const getProducts = async (ctx, { categoryId, productId, searchTerm, limi
17
20
  offset ? `offset:${offset}` : '',
18
21
  filters.length ? `filters:${JSON.stringify(filters)}` : '',
19
22
  sort ? `sort:${sort}` : '',
20
- // tag ? `tag:${tag}` : '',
21
- ].filter(Boolean).join(':');
23
+ tag ? `tag:${tag}` : '',
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', ctx.locale);
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 = ctx.locale === ctx.defaultLocale
53
+ const url = currentLocale === ctx.defaultLocale
49
54
  ? `/jsonapi/index/variation`
50
- : `/${ctx.locale}/jsonapi/index/variation`;
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 = ['productCount', ctx.locale,
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
- ].filter(Boolean).join(':');
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`;
@@ -1 +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,C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CAAA;AAED,eAAO,MAAM,cAAc,GACvB,KAAK,WAAW,EAChB,QAAQ,MAAM,EACd,UAAU,qBAAqB,qFAgDlC,CAAA"}
@@ -17,6 +17,7 @@ export const useGetProducts = (ctx, locale, options) => {
17
17
  include,
18
18
  ],
19
19
  queryFn: () => getProducts(ctx, {
20
+ locale,
20
21
  categoryId,
21
22
  productId,
22
23
  searchTerm,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@q2devel/q2-core",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {