@scayle/storefront-nuxt 7.61.0 → 7.61.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 7.61.1
4
+
5
+ ### Patch Changes
6
+
7
+ - `useBasket` and `useWishlist` should no longer trigger duplicate requests when used in multiple components
8
+
3
9
  ## 7.61.0
4
10
 
5
11
  ### Minor Changes
package/dist/module.json CHANGED
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.9.0"
6
6
  },
7
- "version": "7.60.1"
7
+ "version": "7.61.0"
8
8
  }
@@ -1,24 +1,22 @@
1
1
  import type { AddOrUpdateItemType, RpcMethodParameters } from '@scayle/storefront-core';
2
2
  import { ExistingItemHandling } from '@scayle/storefront-core';
3
- import type { RpcOptions } from '../core/useRpc';
4
3
  import { type MaybeRefOrGetter } from '#imports';
5
4
  type UseBasketOptions = Partial<{
6
5
  params: MaybeRefOrGetter<RpcMethodParameters<'getBasket'>>;
7
- options: RpcOptions;
8
6
  key: string;
9
7
  }>;
10
- export declare function useBasket({ params, options, key, }?: UseBasketOptions): Promise<{
11
- data: import("vue").Ref<import("@scayle/storefront-core").BasketResponseData<import("@scayle/storefront-core").Product, import("@scayle/storefront-core").Variant>>;
12
- items: import("vue").ComputedRef<import("@scayle/storefront-core").BasketItem<import("@scayle/storefront-core").Product, import("@scayle/storefront-core").Variant>[]>;
13
- cost: import("vue").ComputedRef<import("@scayle/storefront-core").BasketTotalPrice>;
14
- key: import("vue").ComputedRef<import("@aboutyou/backbone").BasketKey>;
15
- packages: import("vue").ComputedRef<import("@aboutyou/backbone").BasketPackageInformation[]>;
8
+ export declare function useBasket({ params, key, }?: UseBasketOptions): Promise<{
9
+ data: any;
10
+ items: import("vue").ComputedRef<any>;
11
+ cost: import("vue").ComputedRef<any>;
12
+ key: import("vue").ComputedRef<any>;
13
+ packages: import("vue").ComputedRef<any>;
16
14
  shippingDates: import("vue").ComputedRef<(string | null)[] | undefined>;
17
15
  isEmpty: import("vue").ComputedRef<boolean>;
18
- fetching: import("vue").Ref<boolean>;
19
- fetch: () => Promise<void>;
20
- count: import("vue").ComputedRef<number>;
21
- countWithoutSoldOutItems: import("vue").ComputedRef<number>;
16
+ fetching: any;
17
+ fetch: any;
18
+ count: import("vue").ComputedRef<any>;
19
+ countWithoutSoldOutItems: import("vue").ComputedRef<any>;
22
20
  addItem: ({ variantId, promotionId, quantity, existingItemHandling, displayData, customData, itemGroup, }: AddOrUpdateItemType & {
23
21
  existingItemHandling?: 0 | 1 | 2 | 3 | undefined;
24
22
  }) => Promise<void>;
@@ -32,12 +30,12 @@ export declare function useBasket({ params, options, key, }?: UseBasketOptions):
32
30
  } | {
33
31
  productId: number;
34
32
  }) => boolean;
35
- products: import("vue").ComputedRef<import("@scayle/storefront-core").Product[]>;
33
+ products: import("vue").ComputedRef<any>;
36
34
  findItem: (item: {
37
35
  variantId: number;
38
36
  } | {
39
37
  productId: number;
40
- }) => import("@scayle/storefront-core").BasketItem<import("@scayle/storefront-core").Product, import("@scayle/storefront-core").Variant> | undefined;
38
+ }) => any;
41
39
  generateBasketKey: ({ keyTemplate, hashAlgorithm, shopId, userId, log, }: {
42
40
  keyTemplate: string;
43
41
  hashAlgorithm: import("@scayle/storefront-core").HashAlgorithm;
@@ -49,7 +47,7 @@ export declare function useBasket({ params, options, key, }?: UseBasketOptions):
49
47
  fromBasketKey: string;
50
48
  toBasketKey: string;
51
49
  }) => Promise<any>;
52
- error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> | undefined>;
53
- status: import("vue").Ref<import("../core/useRpc").Status>;
50
+ error: any;
51
+ status: any;
54
52
  }>;
55
53
  export {};
@@ -10,9 +10,8 @@ import { useNuxtApp } from "nuxt/app";
10
10
  import { computed } from "vue";
11
11
  import { useEventListener } from "@vueuse/core";
12
12
  import { rpcCall } from "../../rpc/rpcCall.mjs";
13
- import { useRpc } from "../core/useRpc.mjs";
14
13
  import { useCurrentShop } from "../core/useCurrentShop.mjs";
15
- import { toValue } from "#imports";
14
+ import { toValue, toRef, useAsyncData } from "#imports";
16
15
  const onCheckoutUpdate = async (event, fetching, fetchCallback) => {
17
16
  if (fetching) {
18
17
  return;
@@ -26,16 +25,28 @@ const onCheckoutUpdate = async (event, fetching, fetchCallback) => {
26
25
  };
27
26
  export async function useBasket({
28
27
  params,
29
- options,
30
28
  key = "useBasket"
31
29
  } = {}) {
32
30
  const nuxtApp = useNuxtApp();
33
31
  const shop = useCurrentShop();
34
- const { data, fetch, fetching, error, status } = await useRpc(
35
- "getBasket",
32
+ const {
33
+ data,
34
+ pending: fetching,
35
+ error,
36
+ refresh: fetch,
37
+ status
38
+ } = await useAsyncData(
36
39
  key,
37
- params,
38
- options
40
+ () => rpcCall(nuxtApp, "getBasket", toValue(shop))(toValue(params)),
41
+ {
42
+ server: false,
43
+ // TODO: In some cases it might be ok to fetch on server
44
+ watch: [toRef(params)],
45
+ dedupe: "defer",
46
+ getCachedData: (key2) => {
47
+ return toValue(nuxtApp._asyncData[key2]?.data);
48
+ }
49
+ }
39
50
  );
40
51
  useEventListener(
41
52
  "message",
@@ -1,16 +1,14 @@
1
- import type { Product, WishlistItem, RpcMethodParameters } from '@scayle/storefront-core';
2
- import type { RpcOptions } from '../core/useRpc';
1
+ import type { RpcMethodParameters } from '@scayle/storefront-core';
3
2
  import type { MaybeRefOrGetter } from '#imports';
4
3
  type Options = Partial<{
5
4
  params: MaybeRefOrGetter<RpcMethodParameters<'getWishlist'>>;
6
- options: RpcOptions;
7
5
  key: string;
8
6
  }>;
9
- export declare function useWishlist({ params, options, key, }?: Options): Promise<{
10
- data: import("vue").Ref<import("@scayle/storefront-core").WishlistResponseData>;
11
- count: import("vue").ComputedRef<number>;
12
- items: import("vue").ComputedRef<WishlistItem[]>;
13
- products: import("vue").ComputedRef<Product[]>;
7
+ export declare function useWishlist({ params, key, }?: Options): Promise<{
8
+ data: any;
9
+ count: import("vue").ComputedRef<any>;
10
+ items: import("vue").ComputedRef<any>;
11
+ products: import("vue").ComputedRef<any>;
14
12
  addItem: (item: {
15
13
  variantId?: number;
16
14
  productId?: number;
@@ -27,8 +25,8 @@ export declare function useWishlist({ params, options, key, }?: Options): Promis
27
25
  productId?: number;
28
26
  }) => Promise<void>;
29
27
  clear: () => Promise<void>;
30
- fetching: import("vue").Ref<boolean>;
31
- fetch: () => Promise<void>;
28
+ fetching: any;
29
+ fetch: any;
32
30
  toggleItem: (item: {
33
31
  variantId?: number;
34
32
  productId?: number;
@@ -36,13 +34,13 @@ export declare function useWishlist({ params, options, key, }?: Options): Promis
36
34
  findItem: (item: {
37
35
  variantId?: number;
38
36
  productId?: number;
39
- }) => WishlistItem | undefined;
37
+ }) => any;
40
38
  contains: (item: {
41
39
  variantId: number;
42
40
  } | {
43
41
  productId: number;
44
42
  }) => boolean;
45
- error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> | undefined>;
46
- status: import("vue").Ref<import("../core/useRpc").Status>;
43
+ error: any;
44
+ status: any;
47
45
  }>;
48
46
  export {};
@@ -7,20 +7,31 @@ import { useNuxtApp } from "nuxt/app";
7
7
  import { computed } from "vue";
8
8
  import { rpcCall } from "../../rpc/rpcCall.mjs";
9
9
  import { useCurrentShop } from "../core/useCurrentShop.mjs";
10
- import { useRpc } from "../core/useRpc.mjs";
11
- import { toValue } from "#imports";
10
+ import { toValue, toRef, useAsyncData } from "#imports";
12
11
  export async function useWishlist({
13
12
  params,
14
- options,
15
13
  key = "useWishlist"
16
14
  } = {}) {
17
15
  const nuxtApp = useNuxtApp();
18
16
  const shop = useCurrentShop();
19
- const { data, fetching, fetch, error, status } = await useRpc(
20
- "getWishlist",
17
+ const {
18
+ data,
19
+ pending: fetching,
20
+ error,
21
+ refresh: fetch,
22
+ status
23
+ } = await useAsyncData(
21
24
  key,
22
- params,
23
- options
25
+ () => rpcCall(nuxtApp, "getWishlist", toValue(shop))(toValue(params)),
26
+ {
27
+ server: false,
28
+ // TODO: In some cases it might be ok to fetch on server
29
+ watch: [toRef(params)],
30
+ dedupe: "defer",
31
+ getCachedData: (key2) => {
32
+ return toValue(nuxtApp._asyncData[key2]?.data);
33
+ }
34
+ }
24
35
  );
25
36
  const addItem = async (item) => {
26
37
  data.value = await rpcCall(
@@ -1,5 +1,5 @@
1
1
  declare const resolveError: (error: Error | unknown) => {
2
- statusCode: 500 | 401 | 400 | 100 | 101 | 102 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 426 | 428 | 429 | 431 | 451 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
2
+ statusCode: 401 | 500 | 400 | 100 | 101 | 102 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 426 | 428 | 429 | 431 | 451 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
3
3
  statusMessage: string;
4
4
  name: string;
5
5
  };
@@ -11,24 +11,14 @@ export const handler = async (method, payload, rpcContext) => {
11
11
  const log = rpcContext.log.space("sfc").space("rpc");
12
12
  return await log.time(`Calling RPC method: ${method}`, async () => {
13
13
  const fun = rpcMethods[method];
14
- try {
15
- if (fun.length === 1) {
16
- return await fun(
17
- rpcContext
18
- );
19
- }
14
+ if (fun.length === 1) {
20
15
  return await fun(
21
- payload,
22
16
  rpcContext
23
17
  );
24
- } catch (e) {
25
- if (e instanceof Error) {
26
- return new Response(JSON.stringify({ message: e.message }), {
27
- status: 500
28
- });
29
- } else {
30
- return new Response(null, { status: 500 });
31
- }
32
18
  }
19
+ return await fun(
20
+ payload,
21
+ rpcContext
22
+ );
33
23
  });
34
24
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
3
  "type": "module",
4
- "version": "7.61.0",
4
+ "version": "7.61.1",
5
5
  "description": "Nuxt integration for the SCAYLE Commerce Engine and Storefront API",
6
6
  "author": "SCAYLE Commerce Engine",
7
7
  "license": "MIT",
@@ -84,7 +84,7 @@
84
84
  "@nuxt/test-utils": "3.11.0",
85
85
  "@scayle/eslint-config-storefront": "3.2.6",
86
86
  "@scayle/prettier-config-storefront": "2.0.2",
87
- "@types/node": "20.11.24",
87
+ "@types/node": "20.11.25",
88
88
  "eslint": "8.57.0",
89
89
  "eslint-formatter-gitlab": "5.1.0",
90
90
  "h3": "1.11.1",
@@ -93,7 +93,7 @@
93
93
  "prettier": "3.0.0",
94
94
  "publint": "0.2.7",
95
95
  "vitest": "1.3.1",
96
- "vue-tsc": "1.8.27"
96
+ "vue-tsc": "2.0.6"
97
97
  },
98
98
  "peerDependencies": {
99
99
  "h3": "^1.10.0",