@q2devel/q2-core 1.0.1 → 1.0.3

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/README.md ADDED
@@ -0,0 +1,93 @@
1
+ # Q2 Core
2
+
3
+
4
+
5
+ ## Getting started
6
+
7
+ To make it easy for you to get started with GitLab, here's a list of recommended next steps.
8
+
9
+ Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
10
+
11
+ ## Add your files
12
+
13
+ - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
14
+ - [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
15
+
16
+ ```
17
+ cd existing_repo
18
+ git remote add origin https://gitlab.pegasus.q2.cz/q2-extensions/q2-core.git
19
+ git branch -M main
20
+ git push -uf origin main
21
+ ```
22
+
23
+ ## Integrate with your tools
24
+
25
+ - [ ] [Set up project integrations](http://gitlab.q2cz.local/q2-extensions/q2-core/-/settings/integrations)
26
+
27
+ ## Collaborate with your team
28
+
29
+ - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
30
+ - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
31
+ - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
32
+ - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
33
+ - [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
34
+
35
+ ## Test and Deploy
36
+
37
+ Use the built-in continuous integration in GitLab.
38
+
39
+ - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
40
+ - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
41
+ - [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
42
+ - [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
43
+ - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
44
+
45
+ ***
46
+
47
+ # Editing this README
48
+
49
+ When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
50
+
51
+ ## Suggestions for a good README
52
+
53
+ Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
54
+
55
+ ## Name
56
+ Choose a self-explaining name for your project.
57
+
58
+ ## Description
59
+ Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
60
+
61
+ ## Badges
62
+ On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
63
+
64
+ ## Visuals
65
+ Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
66
+
67
+ ## Installation
68
+ Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
69
+
70
+ ## Usage
71
+ Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
72
+
73
+ ## Support
74
+ Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
75
+
76
+ ## Roadmap
77
+ If you have ideas for releases in the future, it is a good idea to list them in the README.
78
+
79
+ ## Contributing
80
+ State if you are open to contributions and what your requirements are for accepting them.
81
+
82
+ For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
83
+
84
+ You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
85
+
86
+ ## Authors and acknowledgment
87
+ Show your appreciation to those who have contributed to the project.
88
+
89
+ ## License
90
+ For open source projects, say how it is licensed.
91
+
92
+ ## Project status
93
+ If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
@@ -1,6 +1,6 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
2
  import { CoreContext } from '../../context';
3
- import { AddToCartRequest, AddToCartResponse, Cart, CartItem, DeleteCartItemRequest, UpdateCartItemRequest } from './CartService.types';
3
+ import { AddToCartRequest, AddToCartResponse, Cart, CartItem, DeleteCartItemRequest, UpdateCartItemRequest, OrderHistoryResponse } from './CartService.types';
4
4
  export declare const getUserCart: (ctx: CoreContext, config?: AxiosRequestConfig) => Promise<Cart>;
5
5
  export declare const getCurrentCart: (ctx: CoreContext, activeToken: string, config?: AxiosRequestConfig) => Promise<Cart>;
6
6
  export declare const addToCart: (ctx: CoreContext, activeToken: string | undefined, request: AddToCartRequest, config?: AxiosRequestConfig) => Promise<AddToCartResponse>;
@@ -10,18 +10,5 @@ export declare const clearCart: (ctx: CoreContext, cartId: string, config?: Axio
10
10
  export declare const applyCoupon: (ctx: CoreContext, cartId: string, couponCode: string, config?: AxiosRequestConfig) => Promise<Cart>;
11
11
  export declare const removeCoupon: (ctx: CoreContext, cartId: string, couponId: string, config?: AxiosRequestConfig) => Promise<void>;
12
12
  export declare const getCartToken: (ctx: CoreContext, config?: AxiosRequestConfig) => Promise<string>;
13
- export type OrderHistoryResponse = {
14
- data: Array<{
15
- id: string;
16
- drupalOrderId: number;
17
- cartItems: CartItem[];
18
- total: {
19
- number: string;
20
- currency_code: string;
21
- formatted: string;
22
- };
23
- completed: string;
24
- }>;
25
- };
26
13
  export declare const getOrderHistory: (ctx: CoreContext, config?: AxiosRequestConfig) => Promise<OrderHistoryResponse>;
27
14
  //# sourceMappingURL=Cart.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Cart.service.d.ts","sourceRoot":"","sources":["../../../api/cart/Cart.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAG3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,IAAI,EACJ,QAAQ,EACR,qBAAqB,EAErB,qBAAqB,EACtB,MAAM,qBAAqB,CAAC;AAQ7B,eAAO,MAAM,WAAW,GACtB,KAAK,WAAW,EAChB,SAAQ,kBAAuB,KAC9B,OAAO,CAAC,IAAI,CAkEd,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,KAAK,WAAW,EAChB,aAAa,MAAM,EACnB,SAAQ,kBAAuB,KAC9B,OAAO,CAAC,IAAI,CAuDd,CAAC;AAEF,eAAO,MAAM,SAAS,GACpB,KAAK,WAAW,EAChB,aAAa,MAAM,GAAG,SAAS,EAC/B,SAAS,gBAAgB,EACzB,SAAQ,kBAAuB,KAC9B,OAAO,CAAC,iBAAiB,CAmB3B,CAAC;AAGF,eAAO,MAAM,cAAc,GACzB,KAAK,WAAW,EAChB,SAAS,MAAM,EACf,QAAQ,MAAM,EACd,SAAS,qBAAqB,EAC9B,SAAQ,kBAAuB,KAC9B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KAC9B,OAAO,CAAC,IAAI,CAKd,CAAC;AAEF,eAAO,MAAM,YAAY,GACvB,KAAK,WAAW,EAChB,SAAQ,kBAAuB,KAC9B,OAAO,CAAC,MAAM,CAQhB,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,KAAK,WAAW,EAChB,SAAQ,kBAAuB,KAC9B,OAAO,CAAC,oBAAoB,CA6C9B,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
2
2
  import { mapIncludedResources } from '../../utils/mapIncludedResources';
3
+ import { mapProduct } from '../../utils/mapProducts';
3
4
  const getHeaders = (ctx, customHeaders = {}) => ({
4
5
  'Content-Type': 'application/vnd.api+json',
5
6
  ...(ctx.accessToken && { Authorization: `Bearer ${ctx.accessToken}` }),
@@ -14,9 +15,11 @@ export const getUserCart = async (ctx, config = {}) => {
14
15
  .addInclude([
15
16
  'order_items',
16
17
  'order_items.purchased_entity',
18
+ 'order_items.purchased_entity.field_image',
19
+ 'order_items.purchased_entity.field_image.field_media_image',
17
20
  'order_items.purchased_entity.product_id',
18
- 'order_items.purchased_entity.product_id.field_image',
19
- 'order_items.purchased_entity.product_id.field_image.field_media_image',
21
+ // 'order_items.purchased_entity.product_id.field_image',
22
+ // 'order_items.purchased_entity.product_id.field_image.field_media_image',
20
23
  ]);
21
24
  const { data } = await ctx.axios.get(`/jsonapi/commerce_order/default?${params.getQueryString()}`, { ...config, headers: getHeaders(ctx, config.headers) });
22
25
  if (!data.data || (Array.isArray(data.data) && data.data.length === 0)) {
@@ -29,31 +32,27 @@ export const getUserCart = async (ctx, config = {}) => {
29
32
  },
30
33
  };
31
34
  }
32
- const resolvedOrders = mapIncludedResources(data, 5);
35
+ const resolvedOrders = mapIncludedResources(data, 6);
33
36
  const orderData = Array.isArray(resolvedOrders) ? resolvedOrders[0] : resolvedOrders;
34
- const cartItems = (orderData.order_items || []).map((item) => {
35
- const defaultProduct = item.purchased_entity?.product_id || {};
36
- const variationProduct = defaultProduct?.default_variation || {};
37
- const images = defaultProduct?.field_image || [];
37
+ const cartItems = (orderData.order_items || [])
38
+ .map((item) => {
39
+ const defaultProduct = item.purchased_entity?.product_id;
40
+ const variationProduct = item.purchased_entity;
41
+ const variations = defaultProduct?.variations ?? [];
42
+ if (!defaultProduct || !variationProduct) {
43
+ console.warn('Invalid order item structure', item);
44
+ return null;
45
+ }
46
+ const baseProduct = mapProduct(defaultProduct, variationProduct, variations, ctx);
38
47
  return {
39
- variation_id: variationProduct.drupal_internal__variation_id,
40
- variation_uuid: variationProduct.id,
41
- drupalOrderItemId: item.drupal_internal__order_item_id || 0,
42
- type: variationProduct.type,
43
- variation_name: variationProduct.title || '',
44
- variation_images: images.length
45
- ? images.map((img) => ({
46
- href: ctx.makeAbsoluteUrl(img.field_media_image?.uri?.url),
47
- alt: img.name,
48
- }))
49
- : [{ href: '/q2_logo.png', alt: 'Q2' }],
50
- price: parseFloat(item.unit_price?.number || '0'),
48
+ ...baseProduct,
51
49
  quantity: parseFloat(item.quantity || '0'),
52
- product_name: defaultProduct.title || '',
53
- product_id: defaultProduct.drupal_internal__product_id || '',
50
+ price: parseFloat(item.unit_price?.number || '0'), // override price from order item
51
+ drupalOrderItemId: item.drupal_internal__order_item_id || 0,
54
52
  order_item_id: item.id || '',
55
53
  };
56
- });
54
+ })
55
+ .filter(Boolean);
57
56
  return {
58
57
  data: {
59
58
  id: orderData.id || '',
@@ -66,7 +65,7 @@ export const getUserCart = async (ctx, config = {}) => {
66
65
  export const getCurrentCart = async (ctx, activeToken, config = {}) => {
67
66
  if (!activeToken)
68
67
  throw new Error('Missing activeToken in context');
69
- const { data } = await ctx.axios.get(`/jsonapi/carts?cartToken=${activeToken}&include=order_items,order_items.purchased_entity,order_items.purchased_entity.product_id,order_items.purchased_entity.product_id.field_image,order_items.purchased_entity.product_id.field_image.field_media_image`, { ...config, headers: getHeaders(ctx, config.headers) });
68
+ const { data } = await ctx.axios.get(`/jsonapi/carts?cartToken=${activeToken}&include=order_items,order_items.purchased_entity,order_items.purchased_entity.product_id,order_items.purchased_entity.field_image,order_items.purchased_entity.field_image.field_media_image`, { ...config, headers: getHeaders(ctx, config.headers) });
70
69
  if (!data.data || data.data.length === 0) {
71
70
  return {
72
71
  data: {
@@ -77,31 +76,27 @@ export const getCurrentCart = async (ctx, activeToken, config = {}) => {
77
76
  },
78
77
  };
79
78
  }
80
- const resolvedOrders = mapIncludedResources(data, 5);
81
- const orderData = resolvedOrders[0];
82
- const cartItems = (orderData.order_items || []).map((item) => {
83
- const defaultProduct = item.purchased_entity?.product_id || {};
84
- const variationProduct = defaultProduct?.default_variation || {};
85
- const images = defaultProduct?.field_image || [];
79
+ const resolvedOrders = mapIncludedResources(data, 6);
80
+ const orderData = Array.isArray(resolvedOrders) ? resolvedOrders[0] : resolvedOrders;
81
+ const cartItems = (orderData.order_items || [])
82
+ .map((item) => {
83
+ const defaultProduct = item.purchased_entity?.product_id;
84
+ const variationProduct = item.purchased_entity;
85
+ const variations = defaultProduct?.variations ?? [];
86
+ if (!defaultProduct || !variationProduct) {
87
+ console.warn('Invalid order item structure', item);
88
+ return null;
89
+ }
90
+ const baseProduct = mapProduct(defaultProduct, variationProduct, variations, ctx);
86
91
  return {
87
- variation_id: variationProduct.drupal_internal__variation_id,
88
- variation_uuid: variationProduct.id,
89
- drupalOrderItemId: item.drupal_internal__order_item_id || 0,
90
- type: variationProduct.type,
91
- variation_name: variationProduct.title || '',
92
- variation_images: images.length
93
- ? images.map((img) => ({
94
- href: ctx.makeAbsoluteUrl(img.field_media_image?.uri?.url),
95
- alt: img.name,
96
- }))
97
- : [{ href: '/q2_logo.png', alt: 'Q2' }],
98
- price: parseFloat(item.unit_price?.number || '0'),
92
+ ...baseProduct,
99
93
  quantity: parseFloat(item.quantity || '0'),
100
- product_name: defaultProduct.title || '',
101
- product_id: defaultProduct.drupal_internal__product_id || '',
94
+ price: parseFloat(item.unit_price?.number || '0'), // override price from order item
95
+ drupalOrderItemId: item.drupal_internal__order_item_id || 0,
102
96
  order_item_id: item.id || '',
103
97
  };
104
- });
98
+ })
99
+ .filter(Boolean);
105
100
  return {
106
101
  data: {
107
102
  id: orderData.id || '',
@@ -1 +1 @@
1
- {"version":3,"file":"getTerms.d.ts","sourceRoot":"","sources":["../../api/getTerms.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAIrC,KAAK,aAAa,GAAG;IACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD,CAAC;AAEF,eAAO,MAAM,QAAQ,GACnB,KAAK,WAAW,EAChB,gCAA6C,aAAa,KACzD,OAAO,CAAC,IAAI,EAAE,CA0ChB,CAAC"}
1
+ {"version":3,"file":"getTerms.d.ts","sourceRoot":"","sources":["../../api/getTerms.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAIrC,KAAK,aAAa,GAAG;IACnB,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD,CAAC;AAEF,eAAO,MAAM,QAAQ,GACnB,KAAK,WAAW,EAChB,gCAA6C,aAAa,KACzD,OAAO,CAAC,IAAI,EAAE,CAsEhB,CAAC"}
@@ -3,23 +3,43 @@ import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
3
3
  import mapIncludedResources from '../utils/mapIncludedResources';
4
4
  export const getTerms = async (ctx, { categoryId, include = ['parent'], mapFn }) => {
5
5
  const cacheKey = ['terms', ctx.locale, ...(categoryId ?? []), ...(include ?? [])].join(':');
6
- if (ctx.getCache) {
7
- const cached = await ctx.getCache(cacheKey);
8
- if (cached)
9
- return cached;
10
- }
6
+ // const cached = await ctx.getCache?.<Term[]>(cacheKey);
7
+ // if (cached) return cached;
8
+ const baseUrl = ctx.locale === ctx.defaultLocale
9
+ ? `/jsonapi/taxonomy_term/produktykategorie`
10
+ : `/${ctx.locale}/jsonapi/taxonomy_term/produktykategorie`;
11
11
  const params = new DrupalJsonApiParams()
12
12
  .addInclude(include)
13
- .addFilter('langcode', ctx.locale);
13
+ .addFilter('langcode', ctx.locale)
14
+ .addPageLimit(50); // důležité
14
15
  if (categoryId) {
15
16
  params.addFilter('drupal_internal__tid', categoryId, 'IN');
16
17
  }
17
- const url = ctx.locale === ctx.defaultLocale
18
- ? `/jsonapi/taxonomy_term/produktykategorie`
19
- : `/${ctx.locale}/jsonapi/taxonomy_term/produktykategorie`;
20
- const { data } = await ctx.axios.get(`${url}?${params.getQueryString()}`);
21
- const resources = mapIncludedResources(data);
22
- // awaitujeme mapFn u každého elementu, pokud je zadán
18
+ // Pole pro akumulaci všech stránek dat
19
+ const allData = [];
20
+ const allIncluded = [];
21
+ let nextUrl = `${baseUrl}?${params.getQueryString()}`;
22
+ let pageCounter = 0;
23
+ while (nextUrl && pageCounter < 50) {
24
+ const response = await ctx.axios.get(nextUrl);
25
+ const data = response.data;
26
+ if (Array.isArray(data.data)) {
27
+ allData.push(...data.data);
28
+ }
29
+ else {
30
+ allData.push(data.data);
31
+ }
32
+ if (Array.isArray(data.included)) {
33
+ allIncluded.push(...data.included);
34
+ }
35
+ nextUrl = data.links?.next?.href || null;
36
+ pageCounter++;
37
+ }
38
+ const combinedResponse = {
39
+ data: allData,
40
+ included: allIncluded,
41
+ };
42
+ const resources = mapIncludedResources(combinedResponse);
23
43
  const mapped = await Promise.all(resources.map(async (item) => {
24
44
  const base = {
25
45
  uuid: item.id,
@@ -31,8 +51,6 @@ export const getTerms = async (ctx, { categoryId, include = ['parent'], mapFn })
31
51
  };
32
52
  return mapFn ? await mapFn(base, item) : base;
33
53
  }));
34
- if (ctx.setCache) {
35
- await ctx.setCache(cacheKey, mapped);
36
- }
54
+ // await ctx.setCache?.(cacheKey, mapped);
37
55
  return mapped;
38
56
  };
@@ -15,8 +15,9 @@ type GetProductsParams = {
15
15
  tag?: string;
16
16
  include?: string[];
17
17
  cache?: boolean;
18
+ mapFnVariations?: (base: Product, raw: any) => Product | Promise<Product>;
18
19
  };
19
- export declare const getProducts: (ctx: CoreContext, { categoryId, productId, searchTerm, limit, offset, filters, sort, tag, include, cache, }: GetProductsParams) => Promise<Product[]>;
20
+ export declare const getProducts: (ctx: CoreContext, { categoryId, productId, searchTerm, limit, offset, filters, sort, tag, include, cache, mapFnVariations, }: GetProductsParams) => Promise<Product[]>;
20
21
  type GetProductCountParams = {
21
22
  categoryId?: string[];
22
23
  tag?: string;
@@ -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,EAAuB,MAAM,8BAA8B,CAAC;AAE5E,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,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC;QAChC,QAAQ,CAAC,EAAE,MAAM,C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B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3E,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,KAAK,WAAW,EAChB,4GAkBG,iBAAiB,KACnB,OAAO,CAAC,OAAO,EAAE,CAwDnB,CAAC;AAGF,KAAK,qBAAqB,GAAG;IAC3B,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,KAAK,WAAW,EAChB,6BAIG,qBAAqB,KACvB,OAAO,CAAC,MAAM,CAkChB,CAAC"}
@@ -1,13 +1,14 @@
1
1
  import { DrupalJsonApiParams } from 'drupal-jsonapi-params';
2
2
  import mapIncludedResources from '../../utils/mapIncludedResources';
3
- import { getDiscountPercent, handleSortChange } from '../../utils/generalHelper';
3
+ import { handleSortChange } from '../../utils/generalHelper';
4
+ import { mapProduct } from '../../utils/mapProducts';
4
5
  export const getProducts = async (ctx, { categoryId, productId, searchTerm, limit, offset, filters = [], sort = '', tag = '', include = [
5
6
  'product_id',
6
7
  'product_id.field_category',
7
8
  'product_id.field_image',
8
9
  'product_id.field_image.field_media_image',
9
10
  'field_image.field_media_image',
10
- ], cache = true, }) => {
11
+ ], cache = true, mapFnVariations, }) => {
11
12
  const cacheKey = ['products', ctx.locale,
12
13
  categoryId?.length ? `cat:${categoryId.join(',')}` : '',
13
14
  productId ? `id:${productId}` : '',
@@ -32,7 +33,7 @@ export const getProducts = async (ctx, { categoryId, productId, searchTerm, limi
32
33
  if (productId)
33
34
  params.addFilter('variation_id', productId);
34
35
  if (searchTerm)
35
- params.addFilter('title', searchTerm);
36
+ params.addFilter('title_1', searchTerm);
36
37
  if (limit)
37
38
  params.addPageLimit(limit);
38
39
  if (offset)
@@ -48,60 +49,13 @@ export const getProducts = async (ctx, { categoryId, productId, searchTerm, limi
48
49
  : `/${ctx.locale}/jsonapi/index/variation`;
49
50
  const { data } = await ctx.axios.get(`${url}?${params.getQueryString()}`);
50
51
  const resolvedProducts = mapIncludedResources(data);
51
- const mappedProducts = resolvedProducts.map((item) => {
52
- const default_product = item.product_id;
53
- const default_images = default_product.field_image ?? [];
54
- const variation_images = item.field_image ?? [];
55
- const discountPercent = getDiscountPercent(item.price, item.list_price);
56
- //optional badges -demo purposes
57
- const badges = [
58
- ...(item.field_news ? [{ text: 'Novinka', color: 'bg-green-100 text-green-800' }] : []),
59
- ...(item.field_aftersale ? [{ text: 'Doprodej', color: 'bg-red-100 text-red-800' }] : []),
60
- ];
61
- const variations = default_product.variations?.map((v) => {
62
- const discountPercentVariation = getDiscountPercent(v.price, v.list_price);
63
- return {
64
- uuid: v.id,
65
- id: v.drupal_internal__variation_id,
66
- title: v.title,
67
- sku: v.sku,
68
- price: v?.list_price?.number ? v.list_price.number : v.price?.number ?? 0,
69
- discountPercentVariation,
70
- ean: v.field_ean,
71
- stock: v?.field_stock_level?.available_stock ?? 0,
72
- };
73
- }) ?? [];
74
- return {
75
- variation_id: item.drupal_internal__variation_id,
76
- variation_uuid: item.id,
77
- type: item.type,
78
- variation_name: item.title,
79
- sku: item.field_sku ?? '',
80
- description: default_product.field_description?.processed ?? '',
81
- price: item?.list_price?.number ? item.list_price.number : item.price?.number ?? 0,
82
- discountPercent,
83
- product_id: default_product.drupal_internal__product_id,
84
- product_name: default_product.title,
85
- changed: item.changed,
86
- category: default_product.field_category ?? '',
87
- variation_images: variation_images.field_media_image?.uri?.url ? [{ href: ctx.makeAbsoluteUrl(variation_images.field_media_image?.uri?.url), alt: item.title }] : [{ href: '/q2_logo.png', alt: 'Q2' }],
88
- default_images: default_images.length > 0
89
- ? default_images.map((img) => ({
90
- href: ctx.makeAbsoluteUrl(img.field_media_image?.uri?.url),
91
- alt: img.name,
92
- }))
93
- : [{ href: '/q2_logo.png', alt: 'Q2' }],
94
- badges,
95
- variations,
96
- // Additional fields can be added here if needed - demo purposes
97
- field_news: item.field_news ?? false,
98
- field_aftersale: item.field_aftersale ?? false,
99
- field_care: default_product.field_care ?? [],
100
- field_features: default_product.field_features ?? [],
101
- field_returns: default_product.field_returns ?? [],
102
- field_shipping: default_product.field_shipping ?? [],
103
- };
104
- });
52
+ const mappedProducts = await Promise.all(resolvedProducts.map(async (item) => {
53
+ const base = mapProduct(item.product_id, item, item.product_id.variations ?? [], ctx);
54
+ if (mapFnVariations) {
55
+ return await mapFnVariations(base, item);
56
+ }
57
+ return base;
58
+ }));
105
59
  // if (cache && ctx.setCache) {
106
60
  // await ctx.setCache(cacheKey, mappedProducts);
107
61
  // }
@@ -1 +1 @@
1
- {"version":3,"file":"BasketContext.d.ts","sourceRoot":"","sources":["../../../context/cart/BasketContext.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAA;AAUhE,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAA;AAC/F,OAAO,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAA;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,EAAiB,SAAS,EAA2C,MAAM,OAAO,CAAA;AACzF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAM3C,KAAK,iBAAiB,GAAG;IACrB,cAAc,EAAE,aAAa,EAAE,CAAA;IAC/B,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACnE,mBAAmB,EAAE,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,OAAO,CA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CAAC,IAAI,CAAC,CAAA;IAClB,gBAAgB,EAAE,MAAM,MAAM,GAAG,IAAI,CAAA;IACrC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACtC,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACxC,cAAc,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,KAAK,iBAAiB,GAAG;IACrB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,KAAK,IAAI,CAAA;CAC7C,CAAA;AAID,KAAK,mBAAmB,GAAG;IACvB,QAAQ,EAAE,SAAS,CAAA;IACnB,GAAG,EAAE,WAAW,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,mBAAmB,mBAAmB,4CAobpE,CAAA;AAED,eAAO,MAAM,SAAS,QAAO,iBAM5B,CAAA"}
@@ -8,7 +8,6 @@ import { useGetCurrentCart } from '../../hooks/cart/api/useGetCurrentCart';
8
8
  import { useGetUserCart } from '../../hooks/cart/api/useGetUserCart';
9
9
  import { useUpdateCartItem } from '../../hooks/cart/api/useUpdateCart';
10
10
  import { useUpdateCheckout } from '../../hooks/checkout/useUpdateCheckout';
11
- import { formatPrice } from '../../utils/generalHelper';
12
11
  import { createContext, useContext, useEffect, useRef, useState } from 'react';
13
12
  const BasketContext = createContext(undefined);
14
13
  export const BasketProvider = ({ children, ctx }) => {
@@ -24,6 +23,7 @@ export const BasketProvider = ({ children, ctx }) => {
24
23
  const isLoading = ctx.userId ? isUserCartLoading : isGuestCartLoading;
25
24
  const isFetching = ctx.userId ? isUserCartFetching : isGuestCartFetching;
26
25
  const refetchCart = ctx.userId ? refetchUserCart : refetchGuestCart;
26
+ console.debug('Aktuální košík:', cartData);
27
27
  const { mutateAsync: addToCartMutation, isPending: isAddingToCart } = useAddToCart(ctx, activeToken ?? undefined);
28
28
  const { mutateAsync: updateCartItemMutation } = useUpdateCartItem(ctx);
29
29
  const { mutateAsync: deleteCartItemMutation } = useDeleteCartItem(ctx);
@@ -56,32 +56,7 @@ export const BasketProvider = ({ children, ctx }) => {
56
56
  // Synchronizace data z API
57
57
  useEffect(() => {
58
58
  if (cartData?.data?.cartItems) {
59
- const transformedProducts = cartData.data.cartItems.map((item) => {
60
- const priceNumber = parseFloat(item.price.toString());
61
- return {
62
- variation_id: item.variation_id,
63
- variation_uuid: item.variation_uuid,
64
- type: 'product',
65
- variation_name: item.variation_name,
66
- product_name: item.product_name,
67
- description: '',
68
- price: priceNumber,
69
- formattedPrice: formatPrice(priceNumber, ctx.locale),
70
- quantity: item.quantity,
71
- variation_images: item.images || [],
72
- category: '',
73
- field_news: item.field_news || false,
74
- field_aftersale: item.field_aftersale || false,
75
- field_care: [],
76
- field_features: [],
77
- field_returns: [],
78
- field_shipping: [],
79
- href: '/',
80
- drupalOrderItemId: item.drupalOrderItemId?.toString(),
81
- order_item_id: item.order_item_id,
82
- };
83
- });
84
- setBasketProducts(transformedProducts);
59
+ setBasketProducts(cartData.data.cartItems);
85
60
  if (cartData.data.drupalOrderId) {
86
61
  setDrupalOrderId(cartData.data.drupalOrderId);
87
62
  }
@@ -0,0 +1,4 @@
1
+ import { OrderHistoryResponse } from '../../../api/cart/CartService.types';
2
+ import { CoreContext } from '../../../context';
3
+ export declare const useGetOrderHistory: (ctx: CoreContext) => import("@tanstack/react-query").UseQueryResult<OrderHistoryResponse, Error>;
4
+ //# sourceMappingURL=useGetOrderHistory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGetOrderHistory.d.ts","sourceRoot":"","sources":["../../../../hooks/cart/api/useGetOrderHistory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAE3E,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,eAAO,MAAM,kBAAkB,GAAI,KAAK,WAAW,gFAYlD,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { getOrderHistory } from '../../../api/cart/Cart.service';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ export const useGetOrderHistory = (ctx) => {
4
+ return useQuery({
5
+ queryKey: ['orderHistory', ctx.userId],
6
+ queryFn: async ({ signal }) => {
7
+ if (!ctx.userId) {
8
+ throw new Error('User ID is required to get order history');
9
+ }
10
+ console.debug('Fetching order history for user:', ctx.userId);
11
+ return getOrderHistory(ctx, { signal });
12
+ },
13
+ enabled: !!ctx.userId,
14
+ });
15
+ };
@@ -1,6 +1,6 @@
1
1
  import { CheckoutRequest, UserCheckoutRequest } from '../../api/checkout/CheckoutService.types';
2
2
  import { CoreContext } from '../../context';
3
- export declare const useUpdateCheckout: (ctx: CoreContext) => import("@tanstack/react-query").UseMutationResult<import("../../api/cart/CartService.types").Cart, Error, {
3
+ export declare const useUpdateCheckout: (ctx: CoreContext) => import("@tanstack/react-query").UseMutationResult<import("../..").Cart, Error, {
4
4
  orderId: string;
5
5
  request: CheckoutRequest | UserCheckoutRequest;
6
6
  }, unknown>;
package/dist/index.d.ts CHANGED
@@ -8,7 +8,11 @@ export * from './api/products/getProducts';
8
8
  export * from './types/products/Product';
9
9
  export * from './api/checkout/Checkout.service';
10
10
  export * from './api/checkout/CheckoutService.types';
11
+ export * from './hooks/cart/api/useGetOrderHistory';
11
12
  export * from './hooks/wishlist/useWishlist';
12
13
  export * from './context';
13
14
  export * from './context/cart/BasketContext';
15
+ export * from './api/cart/CartService.types';
16
+ export * from './api/cart/Cart.service';
17
+ export * from './utils/mapProducts';
14
18
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AAErC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAE7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AAErD,cAAc,8BAA8B,CAAC;AAE7C,cAAc,WAAW,CAAC;AAC1B,cAAc,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AAErC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAE7B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AAEzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AAEpD,cAAc,8BAA8B,CAAC;AAE7C,cAAc,WAAW,CAAC;AAC1B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yBAAyB,CAAC;AAGxC,cAAc,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -8,6 +8,10 @@ export * from './api/products/getProducts';
8
8
  export * from './types/products/Product';
9
9
  export * from './api/checkout/Checkout.service';
10
10
  export * from './api/checkout/CheckoutService.types';
11
+ export * from './hooks/cart/api/useGetOrderHistory';
11
12
  export * from './hooks/wishlist/useWishlist';
12
13
  export * from './context';
13
14
  export * from './context/cart/BasketContext';
15
+ export * from './api/cart/CartService.types';
16
+ export * from './api/cart/Cart.service';
17
+ export * from './utils/mapProducts';
@@ -69,5 +69,6 @@ export type ProductVariation = {
69
69
  href: string;
70
70
  alt: string;
71
71
  }[];
72
+ href?: string;
72
73
  };
73
74
  //# sourceMappingURL=Product.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Product.d.ts","sourceRoot":"","sources":["../../../types/products/Product.ts"],"names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AAC;KACf,EAAE,CAAC;CACL,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,wBAAwB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;KACb,EAAE,CAAC;IACJ,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC"}
@@ -8,9 +8,9 @@ export function getDiscountPercent(price, listPrice) {
8
8
  export function handleSortChange(id) {
9
9
  switch (id) {
10
10
  case 'title-ASC':
11
- return { title: 'title', direction: 'ASC' };
11
+ return { title: 'title_1', direction: 'ASC' };
12
12
  case 'title-DESC':
13
- return { title: 'title', direction: 'DESC' };
13
+ return { title: 'title_1', direction: 'DESC' };
14
14
  case 'price-ASC':
15
15
  return { title: 'number', direction: 'ASC' };
16
16
  case 'price-DESC':
@@ -0,0 +1,3 @@
1
+ import { RawProductVariation, Product } from '../types/products/Product';
2
+ export declare function mapProduct(defaultProduct: any, variationProduct: any, allVariations: RawProductVariation[], ctx: any): Product;
3
+ //# sourceMappingURL=mapProducts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapProducts.d.ts","sourceRoot":"","sources":["../../utils/mapProducts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAoCzE,wBAAgB,UAAU,CACxB,cAAc,EAAE,GAAG,EACnB,gBAAgB,EAAE,GAAG,EACrB,aAAa,EAAE,mBAAmB,EAAE,EACpC,GAAG,EAAE,GAAG,GACP,OAAO,CAmCT"}
@@ -0,0 +1,63 @@
1
+ import { getDiscountPercent } from '../utils/generalHelper';
2
+ // Pomocná funkce na mapování obrázků
3
+ function mapImages(images, ctx) {
4
+ if (!images?.length)
5
+ return [{ href: '/q2_logo.png', alt: 'Q2' }];
6
+ return images.map((img) => ({
7
+ href: ctx.makeAbsoluteUrl(img.field_media_image?.uri?.url),
8
+ alt: img.name ?? 'Image',
9
+ }));
10
+ }
11
+ // Pomocná funkce na mapování variant
12
+ function mapVariations(variations = []) {
13
+ return variations.map((v) => {
14
+ const discountPercentVariation = getDiscountPercent(v.price, v.list_price);
15
+ return {
16
+ uuid: v.id,
17
+ id: v.drupal_internal__variation_id,
18
+ title: v.title,
19
+ sku: v.sku,
20
+ price: v?.list_price?.number ? v.list_price.number : v.price?.number ?? 0,
21
+ discountPercentVariation,
22
+ ean: v.field_ean,
23
+ stock: v?.field_stock_level?.available_stock ?? 0,
24
+ href: ''
25
+ };
26
+ });
27
+ }
28
+ // Hlavní mapovací funkce
29
+ export function mapProduct(defaultProduct, variationProduct, allVariations, ctx) {
30
+ const defaultImages = defaultProduct.field_image ?? [];
31
+ const variationImages = variationProduct.field_image ?? [];
32
+ const discountPercent = getDiscountPercent(variationProduct.price, variationProduct.list_price);
33
+ const badges = [
34
+ ...(variationProduct.field_news ? [{ text: 'Novinka', color: 'bg-green-100 text-green-800' }] : []),
35
+ ...(variationProduct.field_aftersale ? [{ text: 'Doprodej', color: 'bg-red-100 text-red-800' }] : []),
36
+ ];
37
+ return {
38
+ variation_id: variationProduct.drupal_internal__variation_id,
39
+ variation_uuid: variationProduct.id,
40
+ type: variationProduct.type,
41
+ variation_name: variationProduct.title,
42
+ sku: variationProduct.field_sku ?? '',
43
+ description: defaultProduct.field_description?.processed ?? '',
44
+ price: variationProduct?.list_price?.number ? variationProduct.list_price.number : variationProduct.price?.number ?? 0,
45
+ discountPercent,
46
+ product_id: defaultProduct.drupal_internal__product_id,
47
+ product_name: defaultProduct.title,
48
+ changed: variationProduct.changed,
49
+ category: defaultProduct.field_category ?? '',
50
+ variation_images: variationImages.field_media_image?.uri?.url
51
+ ? [{ href: ctx.makeAbsoluteUrl(variationImages.field_media_image.uri.url), alt: variationProduct.title }]
52
+ : [{ href: '/ks_logo.png', alt: 'Q2' }],
53
+ default_images: mapImages(defaultImages, ctx),
54
+ badges,
55
+ variations: mapVariations(defaultProduct.variations),
56
+ field_news: variationProduct.field_news ?? false,
57
+ field_aftersale: variationProduct.field_aftersale ?? false,
58
+ field_care: defaultProduct.field_care ?? [],
59
+ field_features: defaultProduct.field_features ?? [],
60
+ field_returns: defaultProduct.field_returns ?? [],
61
+ field_shipping: defaultProduct.field_shipping ?? [],
62
+ };
63
+ }
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
- {
2
- "name": "@q2devel/q2-core",
3
- "version": "1.0.1",
4
- "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
6
- "exports": {
7
- ".": {
8
- "import": "./dist/index.js",
9
- "types": "./dist/index.d.ts"
10
- }
11
- },
12
- "scripts": {
13
- "build": "tsc",
14
- "prepare": "npm run build"
15
- },
16
- "files": [
17
- "dist"
18
- ],
19
- "license": "MIT",
20
- "devDependencies": {
21
- "@types/react": "^19.1.7",
22
- "@types/react-dom": "^19.1.6",
23
- "typescript": "^5.8.3"
24
- },
25
- "dependencies": {
26
- "@tanstack/react-query": "^5.80.6",
27
- "axios": "^1.9.0",
28
- "drupal-jsonapi-params": "^2.3.2",
29
- "react": "^19.1.0"
30
- }
31
- }
1
+ {
2
+ "name": "@q2devel/q2-core",
3
+ "version": "1.0.3",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "types": "./dist/index.d.ts"
10
+ }
11
+ },
12
+ "scripts": {
13
+ "build": "tsc",
14
+ "prepare": "npm run build"
15
+ },
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "license": "MIT",
20
+ "devDependencies": {
21
+ "@types/react": "^19.1.7",
22
+ "@types/react-dom": "^19.1.6",
23
+ "typescript": "^5.8.3"
24
+ },
25
+ "dependencies": {
26
+ "@tanstack/react-query": "^5.80.6",
27
+ "axios": "^1.9.0",
28
+ "drupal-jsonapi-params": "^2.3.2",
29
+ "react": "^19.1.0"
30
+ }
31
+ }