@scayle/storefront-nuxt 7.73.0 → 7.75.0

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.
Files changed (72) hide show
  1. package/CHANGELOG.md +55 -1
  2. package/dist/index.d.mts +12 -2
  3. package/dist/index.d.ts +12 -2
  4. package/dist/index.mjs +15 -0
  5. package/dist/module.d.mts +2 -2
  6. package/dist/module.d.ts +2 -2
  7. package/dist/module.json +1 -1
  8. package/dist/module.mjs +32 -1
  9. package/dist/rpc.d.mts +1 -1
  10. package/dist/rpc.d.ts +1 -1
  11. package/dist/runtime/composables/core/useIDP.d.ts +5 -5
  12. package/dist/runtime/composables/core/useIDP.mjs +2 -2
  13. package/dist/runtime/composables/core/useRpc.d.ts +38 -9
  14. package/dist/runtime/composables/core/useRpc.mjs +24 -49
  15. package/dist/runtime/composables/core/useUser.d.ts +15 -4
  16. package/dist/runtime/composables/core/useUser.mjs +12 -5
  17. package/dist/runtime/composables/storefront/useBasket.d.ts +69 -8
  18. package/dist/runtime/composables/storefront/useBasket.mjs +16 -18
  19. package/dist/runtime/composables/storefront/useBrand.d.ts +4 -9
  20. package/dist/runtime/composables/storefront/useBrand.mjs +5 -12
  21. package/dist/runtime/composables/storefront/useBrands.d.ts +4 -9
  22. package/dist/runtime/composables/storefront/useBrands.mjs +5 -12
  23. package/dist/runtime/composables/storefront/useCategories.d.ts +23 -13
  24. package/dist/runtime/composables/storefront/useCategories.mjs +8 -12
  25. package/dist/runtime/composables/storefront/useCategoryById.d.ts +4 -9
  26. package/dist/runtime/composables/storefront/useCategoryById.mjs +5 -12
  27. package/dist/runtime/composables/storefront/useCategoryByPath.d.ts +4 -9
  28. package/dist/runtime/composables/storefront/useCategoryByPath.mjs +5 -12
  29. package/dist/runtime/composables/storefront/useCurrentPromotions.d.ts +4 -9
  30. package/dist/runtime/composables/storefront/useCurrentPromotions.mjs +5 -12
  31. package/dist/runtime/composables/storefront/useFacet.d.ts +60 -15
  32. package/dist/runtime/composables/storefront/useFacet.mjs +117 -110
  33. package/dist/runtime/composables/storefront/useFilters.d.ts +4 -12
  34. package/dist/runtime/composables/storefront/useFilters.mjs +5 -12
  35. package/dist/runtime/composables/storefront/useNavigationTree.d.ts +4 -9
  36. package/dist/runtime/composables/storefront/useNavigationTree.mjs +5 -12
  37. package/dist/runtime/composables/storefront/useNavigationTrees.d.ts +4 -9
  38. package/dist/runtime/composables/storefront/useNavigationTrees.mjs +5 -12
  39. package/dist/runtime/composables/storefront/useOrder.d.ts +6 -5
  40. package/dist/runtime/composables/storefront/useOrder.mjs +2 -2
  41. package/dist/runtime/composables/storefront/useOrderConfirmation.d.ts +6 -5
  42. package/dist/runtime/composables/storefront/useOrderConfirmation.mjs +2 -2
  43. package/dist/runtime/composables/storefront/useProduct.d.ts +4 -9
  44. package/dist/runtime/composables/storefront/useProduct.mjs +5 -12
  45. package/dist/runtime/composables/storefront/useProducts.d.ts +4 -21
  46. package/dist/runtime/composables/storefront/useProducts.mjs +5 -12
  47. package/dist/runtime/composables/storefront/useProductsByIds.d.ts +4 -9
  48. package/dist/runtime/composables/storefront/useProductsByIds.mjs +5 -12
  49. package/dist/runtime/composables/storefront/useProductsByReferenceKeys.d.ts +4 -9
  50. package/dist/runtime/composables/storefront/useProductsByReferenceKeys.mjs +5 -12
  51. package/dist/runtime/composables/storefront/useProductsCount.d.ts +4 -11
  52. package/dist/runtime/composables/storefront/useProductsCount.mjs +5 -12
  53. package/dist/runtime/composables/storefront/usePromotions.d.ts +4 -9
  54. package/dist/runtime/composables/storefront/usePromotions.mjs +5 -12
  55. package/dist/runtime/composables/storefront/usePromotionsByIds.d.ts +4 -9
  56. package/dist/runtime/composables/storefront/usePromotionsByIds.mjs +5 -12
  57. package/dist/runtime/composables/storefront/useShopConfiguration.d.ts +4 -9
  58. package/dist/runtime/composables/storefront/useShopConfiguration.mjs +5 -12
  59. package/dist/runtime/composables/storefront/useUserAddresses.d.ts +4 -9
  60. package/dist/runtime/composables/storefront/useUserAddresses.mjs +5 -12
  61. package/dist/runtime/composables/storefront/useVariant.d.ts +4 -9
  62. package/dist/runtime/composables/storefront/useVariant.mjs +5 -12
  63. package/dist/runtime/composables/storefront/useWishlist.d.ts +42 -4
  64. package/dist/runtime/composables/storefront/useWishlist.mjs +17 -14
  65. package/dist/runtime/log.mjs +1 -1
  66. package/dist/runtime/utils/promise.d.ts +9 -0
  67. package/dist/runtime/utils/promise.mjs +12 -0
  68. package/dist/runtime/utils/zodSchema.d.ts +32 -32
  69. package/dist/runtime/utils/zodSchema.mjs +8 -5
  70. package/dist/shared/{storefront-nuxt.d9a4c377.d.mts → storefront-nuxt.257df9a6.d.mts} +11 -11
  71. package/dist/shared/{storefront-nuxt.d9a4c377.d.ts → storefront-nuxt.257df9a6.d.ts} +11 -11
  72. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,10 +1,64 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 7.75.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Configure `keyedComposables` to automatically create keys for `useRpc` wrapping composables instead of relying on hardcoded defaults
8
+ - Export the `extendPromise` util
9
+ - Restore the `useAsyncData` implementation of `useRpc`
10
+
11
+ Originally, `useRpc` was based on `useAsyncData` but in order to fix an issue with wishlists, we restricted the API and changed it to a rough emulation of `useAsyncData`. Because this emulation was similar, but not the same as `useAsyncData` it caused additional confusion. This change brings back the `useAsyncData` implementation.
12
+
13
+ For developers, this means that `useRpc` will behave in the same manner as `useAsyncData`, be subject to the same restrictions and allow the same options.
14
+
15
+ This also means that `useRpc` is now optionally awaitable. `const { data } = await useRpc()` now works as well as `const { data } = useRpc()`. The difference is that the former will wait for the data to load, while the latter will initially be set to the default value.
16
+
17
+ Composables which are simply wrappers around `useRpc` also inherit this new behavior. They accept the same options as `useAsyncData`, return the same properties (and possibly some additional ones) and are optionally awaitable.
18
+
19
+ This includes the following composables:
20
+
21
+ - `useBrand`
22
+ - `useBrands`
23
+ - `useCategories`
24
+ - `useCategoryById`
25
+ - `useCategoryByPath`
26
+ - `useCurrentPromotions`
27
+ - `useFilters`
28
+ - `useNavigationTree`
29
+ - `useNavigationTrees`
30
+ - `useProduct`
31
+ - `useProducts`
32
+ - `useProductsByIds`
33
+ - `useProductsByReferenceKeys`
34
+ - `useProductsCount`
35
+ - `usePromotions`
36
+ - `usePromotionsByIds`
37
+ - `useShopConfiguration`
38
+ - `useUserAddresses`
39
+ - `useVariant`
40
+
41
+ ### Patch Changes
42
+
43
+ - It is no longer mandatory to `await` calls to `useFacet`, `useUser`, `useWishlist` and `useBasket`
44
+
45
+ ## 7.74.0
46
+
47
+ ### Minor Changes
48
+
49
+ - Support for `isDefault` to be an empty string.
50
+ This resolves an issue where an `undefined` value of `isDefault` within a shop config is changed to an empty string during build-time and fails the config validation.
51
+
52
+ ### Patch Changes
53
+
54
+ - Updated dependencies
55
+ - @scayle/storefront-core@7.55.0
56
+
3
57
  ## 7.73.0
4
58
 
5
59
  ### Minor Changes
6
60
 
7
- - Renamed ModuleOptions to ModuleBaseOptions to differentiate it from other ModuleOptions used in different modules.
61
+ - Breaking: Renamed ModuleOptions to ModuleBaseOptions to differentiate it from other ModuleOptions used in different modules.
8
62
 
9
63
  ### Patch Changes
10
64
 
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, M as ModuleBaseOptions, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.d9a4c377.mjs';
1
+ export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, M as ModuleBaseOptions, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.257df9a6.mjs';
2
2
  export { rpcCall } from './rpc.mjs';
3
3
  export * from '@scayle/storefront-core';
4
4
  export { LogLevel } from '@scayle/storefront-core';
@@ -9,6 +9,16 @@ import 'unstorage';
9
9
  import 'zod';
10
10
  import 'nuxt/app';
11
11
 
12
+ /**
13
+ * This function accepts a Promise which has the same interface as its resolved value.
14
+ * It returns a new Promise which extends the original Promise and the original Promise's resolve value
15
+ * with all the properties in source.
16
+ * @param promise
17
+ * @param source
18
+ * @returns
19
+ */
20
+ declare function extendPromise<T extends object, U>(promise: T & Promise<T>, source: U): T & U & Promise<T & U>;
21
+
12
22
  interface RpcMethodsStorefront {
13
23
  }
14
24
  declare module '@scayle/storefront-core' {
@@ -16,4 +26,4 @@ declare module '@scayle/storefront-core' {
16
26
  }
17
27
  }
18
28
 
19
- export type { RpcMethodsStorefront };
29
+ export { type RpcMethodsStorefront, extendPromise };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, M as ModuleBaseOptions, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.d9a4c377.js';
1
+ export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, M as ModuleBaseOptions, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.257df9a6.js';
2
2
  export { rpcCall } from './rpc.js';
3
3
  export * from '@scayle/storefront-core';
4
4
  export { LogLevel } from '@scayle/storefront-core';
@@ -9,6 +9,16 @@ import 'unstorage';
9
9
  import 'zod';
10
10
  import 'nuxt/app';
11
11
 
12
+ /**
13
+ * This function accepts a Promise which has the same interface as its resolved value.
14
+ * It returns a new Promise which extends the original Promise and the original Promise's resolve value
15
+ * with all the properties in source.
16
+ * @param promise
17
+ * @param source
18
+ * @returns
19
+ */
20
+ declare function extendPromise<T extends object, U>(promise: T & Promise<T>, source: U): T & U & Promise<T & U>;
21
+
12
22
  interface RpcMethodsStorefront {
13
23
  }
14
24
  declare module '@scayle/storefront-core' {
@@ -16,4 +26,4 @@ declare module '@scayle/storefront-core' {
16
26
  }
17
27
  }
18
28
 
19
- export type { RpcMethodsStorefront };
29
+ export { type RpcMethodsStorefront, extendPromise };
package/dist/index.mjs CHANGED
@@ -1,3 +1,18 @@
1
1
  export { rpcCall } from './rpc.mjs';
2
2
  export * from '@scayle/storefront-core';
3
3
  export { unwrap } from '@scayle/storefront-core/dist/utils/response';
4
+
5
+ function extendPromise(promise, source) {
6
+ const newPromise = promise.then(
7
+ (result) => Object.assign(result, source)
8
+ );
9
+ const withoutPromise = Object.assign({}, promise);
10
+ for (const key of Object.getOwnPropertyNames(
11
+ Promise.prototype
12
+ )) {
13
+ delete withoutPromise[key];
14
+ }
15
+ return Object.assign(newPromise, Object.assign(withoutPromise, source));
16
+ }
17
+
18
+ export { extendPromise };
package/dist/module.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { M as ModuleBaseOptions } from './shared/storefront-nuxt.d9a4c377.mjs';
3
- export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.d9a4c377.mjs';
2
+ import { M as ModuleBaseOptions } from './shared/storefront-nuxt.257df9a6.mjs';
3
+ export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.257df9a6.mjs';
4
4
  export { LogLevel } from '@scayle/storefront-core';
5
5
  import '@scayle/unstorage-compression-driver';
6
6
  import 'unstorage';
package/dist/module.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { M as ModuleBaseOptions } from './shared/storefront-nuxt.d9a4c377.js';
3
- export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.d9a4c377.js';
2
+ import { M as ModuleBaseOptions } from './shared/storefront-nuxt.257df9a6.js';
3
+ export { d as AdditionalShopConfig, A as AppKeys, B as BapiConfig, h as CheckoutEvent, C as CheckoutShopConfig, i as ModulePublicRuntimeConfig, P as PublicShopConfig, R as RedisConfig, a as SessionConfig, e as ShopConfig, f as ShopConfigIndexed, c as StorageConfig, b as StorageEntity, S as StorageProvider, g as StorefrontConfig } from './shared/storefront-nuxt.257df9a6.js';
4
4
  export { LogLevel } from '@scayle/storefront-core';
5
5
  import '@scayle/unstorage-compression-driver';
6
6
  import 'unstorage';
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
- "version": "7.72.5",
3
+ "version": "7.74.0",
4
4
  "configKey": "storefront",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.9.0"
package/dist/module.mjs CHANGED
@@ -64,7 +64,7 @@ export default {
64
64
  }`;
65
65
  }
66
66
  const PACKAGE_NAME = "@scayle/storefront-nuxt";
67
- const PACKAGE_VERSION = "7.72.5";
67
+ const PACKAGE_VERSION = "7.74.0";
68
68
  const logger = createConsola({
69
69
  fancy: true,
70
70
  formatOptions: {
@@ -315,6 +315,37 @@ Missing RPC Overrides: ${Array.from(overridenRPCMethodNames).map((name) => `'${n
315
315
  addImportsDir(resolve("runtime/composables/storefront"));
316
316
  addImportsDir(resolve("runtime/composables/core"));
317
317
  addImportsDir(resolve("runtime/utils"));
318
+ const keyedComposables = [
319
+ "useBrand",
320
+ "useBrands",
321
+ "useCategories",
322
+ "useCategoryById",
323
+ "useCategoryByPath",
324
+ "useCurrentPromotions",
325
+ "useFacet",
326
+ "useFilters",
327
+ "useIDP",
328
+ "useNavigationTree",
329
+ "useNavigationTrees",
330
+ "useOrder",
331
+ "useOrderConfirmation",
332
+ "useProduct",
333
+ "useProducts",
334
+ "useProductsByIds",
335
+ "useProductsByReferenceKeys",
336
+ "useProductsCount",
337
+ "usePromotions",
338
+ "usePromotionsByIds",
339
+ "useShopConfiguration",
340
+ "useUserAddresses",
341
+ "useVariant"
342
+ ];
343
+ nuxt.options.optimization.keyedComposables.push(
344
+ ...keyedComposables.map((name) => ({
345
+ name,
346
+ argumentLength: 2
347
+ }))
348
+ );
318
349
  nuxt.options.build.transpile = [
319
350
  ...nuxt.options.build?.transpile || [],
320
351
  PACKAGE_NAME,
package/dist/rpc.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RpcMethodName, RpcMethodParameters, RpcMethodReturnType, RpcContext } from '@scayle/storefront-core';
2
2
  import { NuxtApp } from 'nuxt/app';
3
- import { P as PublicShopConfig } from './shared/storefront-nuxt.d9a4c377.mjs';
3
+ import { P as PublicShopConfig } from './shared/storefront-nuxt.257df9a6.mjs';
4
4
  import '@nuxt/schema';
5
5
  import '@scayle/unstorage-compression-driver';
6
6
  import 'unstorage';
package/dist/rpc.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RpcMethodName, RpcMethodParameters, RpcMethodReturnType, RpcContext } from '@scayle/storefront-core';
2
2
  import { NuxtApp } from 'nuxt/app';
3
- import { P as PublicShopConfig } from './shared/storefront-nuxt.d9a4c377.js';
3
+ import { P as PublicShopConfig } from './shared/storefront-nuxt.257df9a6.js';
4
4
  import '@nuxt/schema';
5
5
  import '@scayle/unstorage-compression-driver';
6
6
  import 'unstorage';
@@ -1,13 +1,13 @@
1
1
  import { type MaybeRefOrGetter } from 'vue';
2
2
  import type { RpcMethodParameters } from '@scayle/storefront-core';
3
- export declare function useIDP(params?: MaybeRefOrGetter<RpcMethodParameters<'getExternalIdpRedirect'>>): Promise<{
3
+ export declare function useIDP(params?: MaybeRefOrGetter<RpcMethodParameters<'getExternalIdpRedirect'>>, key?: string): Promise<{
4
4
  data: import("vue").Ref<{
5
5
  [k: string]: string;
6
- } | undefined>;
6
+ }>;
7
7
  fetching: import("vue").Ref<boolean>;
8
- fetch: () => Promise<void>;
9
- error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> | undefined>;
10
- status: import("vue").Ref<import("../core/useRpc").Status>;
8
+ fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
9
+ error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> | null>;
10
+ status: import("vue").Ref<import("nuxt/app").AsyncDataRequestStatus>;
11
11
  handleIDPLoginCallback: (params: string | {
12
12
  code: string;
13
13
  }) => Promise<{
@@ -3,12 +3,12 @@ import { useRpc } from "../core/useRpc.mjs";
3
3
  import { rpcCall } from "./../../rpc/rpcCall.mjs";
4
4
  import { useCurrentShop } from "./useCurrentShop.mjs";
5
5
  import { toValue } from "#imports";
6
- export async function useIDP(params = {}) {
6
+ export async function useIDP(params = {}, key) {
7
7
  const nuxtApp = useNuxtApp();
8
8
  const shop = useCurrentShop();
9
9
  const { data, fetching, fetch, error, status } = await useRpc(
10
10
  "getExternalIdpRedirect",
11
- `getExternalIdpRedirect-${JSON.stringify(toValue(params))}`,
11
+ key ?? "useIDP",
12
12
  params
13
13
  );
14
14
  const handleIDPLoginCallback = rpcCall(
@@ -1,18 +1,47 @@
1
1
  import type { RpcContext, RpcMethodName, RpcMethodParameters, RpcMethodReturnType } from '@scayle/storefront-core';
2
- import type { AsyncDataOptions, NuxtError } from 'nuxt/app';
3
- import { type MaybeRefOrGetter } from '#imports';
2
+ import type { AsyncDataOptions } from 'nuxt/app';
3
+ import { useAsyncData } from 'nuxt/app';
4
+ import type { MaybeRefOrGetter } from '#imports';
4
5
  type KeysOf<T> = Array<T extends T ? (keyof T extends string ? keyof T : never) : never>;
5
6
  export type RpcAsyncDataOptions<TResult> = AsyncDataOptions<TResult, TResult, KeysOf<TResult>, TResult>;
6
7
  export interface RpcOptions {
8
+ /** @deprecated use immediate instead */
7
9
  autoFetch?: boolean;
8
10
  lazy?: boolean;
9
11
  }
12
+ export type UseRpcOptions<N extends RpcMethodName> = RpcOptions & RpcAsyncDataOptions<Exclude<Awaited<RpcMethodReturnType<N>>, Response>>;
13
+ export type UseRpcReturn<N extends RpcMethodName> = ExtendedAsyncData<Exclude<Awaited<RpcMethodReturnType<N>>, Response>>;
10
14
  export type Status = 'idle' | 'pending' | 'success' | 'error';
11
- export declare function useRpc<N extends RpcMethodName, P extends RpcMethodParameters<N>, TResult extends Exclude<Awaited<RpcMethodReturnType<N>>, Response>, TParams = P extends RpcContext ? undefined : P>(method: N, key: string, params?: MaybeRefOrGetter<TParams>, options?: RpcOptions): Promise<{
12
- data: import("vue").Ref<TResult | undefined>;
13
- fetching: import("vue").Ref<boolean>;
14
- fetch: () => Promise<void>;
15
- error: import("vue").Ref<NuxtError<unknown> | undefined>;
16
- status: import("vue").Ref<Status>;
17
- }>;
15
+ type AsyncData<T> = ReturnType<typeof useAsyncData<T>>;
16
+ type AwaitedAsyncData<T> = Awaited<AsyncData<T>>;
17
+ type _ExtendedAsyncData<T> = AwaitedAsyncData<T> & {
18
+ fetching: AwaitedAsyncData<T>['pending'];
19
+ fetch: AwaitedAsyncData<T>['refresh'];
20
+ };
21
+ export type ExtendedAsyncData<T> = _ExtendedAsyncData<T> & Promise<_ExtendedAsyncData<T>>;
22
+ /**
23
+ * `useRpc` is a wrapper around `useAsyncData` for registered RPC methods
24
+ *
25
+ * This is slightly different from the useRpc we have in Nuxt2
26
+ * It is built on top of useAsyncData and matches its API more than the Nuxt2 API
27
+ * Notably, fetch is now refresh. The fetching property remains the same.
28
+ * It also doesn't directly use rpcCall, instead calling $fetch directly
29
+ * The main difference regards how params are passed:
30
+ * In Nuxt2 for an RPC with params, the params are passed when calling `fetch`.
31
+ * In Nuxt3 for an RPC with params, the params are passed to `useRpc`.
32
+ * Additionally, in Nuxt3 the params can be `Params`, `Ref<Params>` or `() => Params`
33
+ *
34
+ * @param method - the RPC method name
35
+ * @param key - a unique key for persisting the data between server and client and de-duplicating requests
36
+ * @param params - parameters to pass to the RPC method.
37
+ * This can be specified in three ways: as a raw value, a `Ref` or a function that returns the params
38
+ * - When passed as a raw value, the parameters are set at the point `useRpc` is called. Subsequent `refresh` calls will use the same params.
39
+ * - When passed as a function, the function will be invoked each time `refresh` is called to get the params.
40
+ * - When passed as a Ref, a watcher wil be added that calls `refresh` each time params change.
41
+ * @param options - Override the options passed to `useAsyncData`.
42
+ * By default, `useRpc` will set `immediate` to `false` and will pass `[params]` to `watch` if `params` is a `Ref`.
43
+ * But anything passed here will take precedence.
44
+ * @see {@link https://nuxt.com/docs/api/composables/use-async-data#params}
45
+ */
46
+ export declare function useRpc<N extends RpcMethodName, P extends RpcMethodParameters<N>, TResult extends Exclude<Awaited<RpcMethodReturnType<N>>, Response>, TParams = P extends RpcContext ? undefined : P>(method: N, key: string, params?: MaybeRefOrGetter<TParams>, options?: RpcAsyncDataOptions<TResult> & RpcOptions): ExtendedAsyncData<TResult>;
18
47
  export {};
@@ -1,9 +1,9 @@
1
1
  import { unwrap } from "@scayle/storefront-core/dist/utils/response";
2
- import { useNuxtApp, useState, createError } from "nuxt/app";
2
+ import { useNuxtApp, useAsyncData } from "nuxt/app";
3
3
  import { useCoreLog } from "../useCoreLog.mjs";
4
- import { resolveError } from "../../error/handler.mjs";
5
4
  import { useCurrentShop } from "./useCurrentShop.mjs";
6
- import { toValue } from "#imports";
5
+ import { extendPromise } from "../../utils/promise.mjs";
6
+ import { toValue, computed, isRef } from "#imports";
7
7
  function getFetch(nuxtApp, log) {
8
8
  const fetch = nuxtApp.ssrContext?.event.$fetch ?? $fetch;
9
9
  if (nuxtApp.ssrContext?.event && !nuxtApp.ssrContext?.event.$fetch) {
@@ -11,36 +11,20 @@ function getFetch(nuxtApp, log) {
11
11
  }
12
12
  return fetch;
13
13
  }
14
- const handleError = (error) => {
15
- const data = resolveError(error);
16
- return createError(data);
17
- };
18
- export async function useRpc(method, key, params, options = { autoFetch: true, lazy: false }) {
14
+ export function useRpc(method, key, params, options) {
19
15
  const currentShop = useCurrentShop();
20
16
  const log = useCoreLog("rpc");
21
17
  const nuxtApp = useNuxtApp();
22
- const isAutoFetchEnabled = options?.autoFetch ?? true;
23
- log.debug(`useRpc: ${method}`);
24
- const keyPrefix = `${method}-${key}`;
25
- const data = useState(
26
- `${keyPrefix}-data`,
27
- () => void 0
28
- );
29
- const fetching = useState(`${keyPrefix}-fetching`, () => false);
30
- const error = useState(
31
- `${keyPrefix}-error`,
32
- () => void 0
33
- );
34
- const status = useState(`${keyPrefix}-status`, () => "idle");
35
- const fetch = async () => {
36
- try {
37
- status.value = "pending";
38
- fetching.value = true;
39
- error.value = void 0;
18
+ if (options && options.autoFetch !== void 0 && options.immediate === void 0) {
19
+ options.immediate = options.autoFetch;
20
+ }
21
+ const asyncData = useAsyncData(
22
+ key,
23
+ async () => {
40
24
  const apiBasePath = currentShop.value?.apiBasePath ?? "/api";
41
- const fetch2 = getFetch(nuxtApp, log);
42
- data.value = await unwrap(
43
- await fetch2(`/rpc/${method}`, {
25
+ const fetch = getFetch(nuxtApp, log);
26
+ return await unwrap(
27
+ await fetch(`/rpc/${method}`, {
44
28
  // @ts-expect-error Type '"POST"' is not assignable to type 'AvailableRouterMethod<`/rpc/${N}`> | Uppercase<AvailableRouterMethod<`/rpc/${N}`>> | undefined'.ts(2322)
45
29
  method: "POST",
46
30
  body: {
@@ -52,25 +36,16 @@ export async function useRpc(method, key, params, options = { autoFetch: true, l
52
36
  }
53
37
  })
54
38
  );
55
- } catch (e) {
56
- error.value = handleError(e);
57
- } finally {
58
- fetching.value = false;
59
- status.value = error.value ? "error" : "success";
39
+ },
40
+ {
41
+ ...isRef(params) ? { watch: [params] } : {},
42
+ ...options
60
43
  }
61
- };
62
- if (isAutoFetchEnabled && status.value === "idle") {
63
- if (import.meta.server) {
64
- await fetch();
65
- } else {
66
- options.lazy ? fetch() : await fetch();
67
- }
68
- }
69
- return {
70
- data,
71
- fetching,
72
- fetch,
73
- error,
74
- status
75
- };
44
+ );
45
+ return extendPromise(asyncData, {
46
+ /** @deprecated - use refresh instead */
47
+ fetch: asyncData.refresh,
48
+ /** @deprecated - use `status.value === 'pending'´ instead */
49
+ fetching: computed(() => asyncData.status.value === "pending")
50
+ });
76
51
  }
@@ -2,15 +2,26 @@ import type { ShopUser, UpdatePasswordParams, UseUserParams } from '@scayle/stor
2
2
  export type ExtendedUseUserParams = UseUserParams & {
3
3
  lazy?: boolean;
4
4
  };
5
- export declare function useUser({ autoFetch, lazy, key, }?: ExtendedUseUserParams): Promise<{
5
+ export declare function useUser({ autoFetch, lazy, key, }?: ExtendedUseUserParams): {
6
6
  user: import("vue").ComputedRef<ShopUser | undefined>;
7
7
  isLoggedIn: import("vue").ComputedRef<boolean>;
8
8
  customerType: import("vue").ComputedRef<"guest" | "new" | "existing">;
9
9
  fetching: import("vue").Ref<boolean>;
10
- fetch: () => Promise<void>;
10
+ fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
11
11
  forceRefresh: () => Promise<void>;
12
12
  updateUser: (payload: Partial<ShopUser>) => Promise<void>;
13
13
  updatePassword: (payload: UpdatePasswordParams) => Promise<void>;
14
- error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> | undefined>;
15
- status: import("vue").Ref<import("./useRpc").Status>;
14
+ error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> | null>;
15
+ status: import("vue").Ref<import("nuxt/app").AsyncDataRequestStatus>;
16
+ } & Promise<{
17
+ user: import("vue").ComputedRef<ShopUser | undefined>;
18
+ isLoggedIn: import("vue").ComputedRef<boolean>;
19
+ customerType: import("vue").ComputedRef<"guest" | "new" | "existing">;
20
+ fetching: import("vue").Ref<boolean>;
21
+ fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
22
+ forceRefresh: () => Promise<void>;
23
+ updateUser: (payload: Partial<ShopUser>) => Promise<void>;
24
+ updatePassword: (payload: UpdatePasswordParams) => Promise<void>;
25
+ error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> | null>;
26
+ status: import("vue").Ref<import("nuxt/app").AsyncDataRequestStatus>;
16
27
  }>;
@@ -2,10 +2,11 @@ import { useNuxtApp } from "nuxt/app";
2
2
  import { computed } from "vue";
3
3
  import { rpcCall } from "../../rpc/rpcCall.mjs";
4
4
  import { useCoreLog } from "../useCoreLog.mjs";
5
+ import { extendPromise } from "../../utils/promise.mjs";
5
6
  import { useRpc } from "./useRpc.mjs";
6
7
  import { useCurrentShop } from "./useCurrentShop.mjs";
7
8
  import { toValue } from "#imports";
8
- export async function useUser({
9
+ export function useUser({
9
10
  autoFetch = true,
10
11
  lazy = false,
11
12
  key = "useUser"
@@ -13,15 +14,21 @@ export async function useUser({
13
14
  const nuxtApp = useNuxtApp();
14
15
  const shop = useCurrentShop();
15
16
  const log = useCoreLog("useUser");
16
- const { data, fetching, fetch, error, status } = await useRpc(
17
+ const asyncDataPromise = useRpc(
17
18
  "getUser",
18
19
  key,
19
20
  void 0,
20
21
  {
21
22
  autoFetch,
22
- lazy
23
+ lazy,
24
+ server: false,
25
+ dedupe: "defer",
26
+ getCachedData: (key2) => {
27
+ return toValue(nuxtApp._asyncData[key2]?.data) ?? void 0;
28
+ }
23
29
  }
24
30
  );
31
+ const { data, fetching, fetch, error, status } = asyncDataPromise;
25
32
  const updateUser = async (payload) => {
26
33
  log.debug("Update user");
27
34
  data.value = await rpcCall(
@@ -53,7 +60,7 @@ export async function useUser({
53
60
  log.debug("Refresh user");
54
61
  data.value = await rpcCall(nuxtApp, "refreshUser", toValue(shop))();
55
62
  };
56
- return {
63
+ return extendPromise(asyncDataPromise.then(() => ({})), {
57
64
  user,
58
65
  isLoggedIn,
59
66
  customerType,
@@ -64,5 +71,5 @@ export async function useUser({
64
71
  updatePassword,
65
72
  error,
66
73
  status
67
- };
74
+ });
68
75
  }
@@ -5,18 +5,79 @@ type UseBasketOptions = Partial<{
5
5
  params: MaybeRefOrGetter<RpcMethodParameters<'getBasket'>>;
6
6
  key: string;
7
7
  }>;
8
- export declare function useBasket({ params, key, }?: UseBasketOptions): Promise<{
9
- data: import("vue").Ref<BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant> | undefined>;
10
- items: import("vue").ComputedRef<import("@scayle/storefront-api").BasketItem<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>[] | undefined>;
11
- cost: import("vue").ComputedRef<import("@scayle/storefront-api").BasketTotalPrice | undefined>;
12
- key: import("vue").ComputedRef<import("@scayle/storefront-api").BasketKey | undefined>;
13
- packages: import("vue").ComputedRef<import("@scayle/storefront-api").BasketPackageInformation[] | undefined>;
8
+ export declare function useBasket({ params, key, }?: UseBasketOptions): import("nuxt/dist/app/composables/asyncData")._AsyncData<BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>, import("nuxt/app").NuxtError<unknown> | null> & {
9
+ fetching: import("vue").Ref<boolean>;
10
+ fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
11
+ } & {
12
+ data: import("vue").Ref<BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>>;
13
+ items: import("vue").ComputedRef<import("@scayle/storefront-api").BasketItem<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>[]>;
14
+ cost: import("vue").ComputedRef<import("@scayle/storefront-api").BasketTotalPrice>;
15
+ key: import("vue").ComputedRef<import("@scayle/storefront-api").BasketKey>;
16
+ packages: import("vue").ComputedRef<import("@scayle/storefront-api").BasketPackageInformation[]>;
17
+ shippingDates: import("vue").ComputedRef<(string | null)[] | undefined>;
18
+ isEmpty: import("vue").ComputedRef<boolean>;
19
+ fetching: import("vue").Ref<boolean>;
20
+ fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
21
+ count: import("vue").ComputedRef<number>;
22
+ countWithoutSoldOutItems: import("vue").ComputedRef<number>;
23
+ addItem: ({ variantId, promotionId, quantity, existingItemHandling, displayData, customData, itemGroup, }: AddOrUpdateItemType & {
24
+ existingItemHandling?: ExistingItemHandling;
25
+ }) => Promise<void>;
26
+ addItems: (items: AddOrUpdateItemType[], existingItemHandling?: 1) => Promise<void>;
27
+ removeItem: (item: {
28
+ variantId: number;
29
+ }) => Promise<void>;
30
+ clear: () => Promise<void>;
31
+ contains: (item: {
32
+ variantId: number;
33
+ } | {
34
+ productId: number;
35
+ }) => boolean;
36
+ products: import("vue").ComputedRef<import("@scayle/storefront-api").Product[]>;
37
+ findItem: (item: {
38
+ variantId: number;
39
+ } | {
40
+ productId: number;
41
+ }) => import("@scayle/storefront-api").BasketItem<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant> | undefined;
42
+ generateBasketKey: ({ keyTemplate, hashAlgorithm, shopId, userId, log, }: {
43
+ keyTemplate: string;
44
+ hashAlgorithm: import("@scayle/storefront-core").HashAlgorithm;
45
+ shopId: string;
46
+ userId: string;
47
+ log?: import("@scayle/storefront-core").Log | undefined;
48
+ }) => Promise<string>;
49
+ mergeBaskets: (args: {
50
+ fromBasketKey: string;
51
+ toBasketKey: string;
52
+ }) => Promise<{
53
+ type: "failure";
54
+ statusCode: number;
55
+ basket: BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
56
+ } | {
57
+ readonly type: "success";
58
+ readonly basket: BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
59
+ } | {
60
+ readonly type: "failure";
61
+ readonly basket: BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
62
+ readonly errors: import("@scayle/storefront-api").AddOrUpdateItemError[];
63
+ } | undefined>;
64
+ error: import("vue").Ref<import("nuxt/app").NuxtError<unknown> | null>;
65
+ status: import("vue").Ref<import("nuxt/app").AsyncDataRequestStatus>;
66
+ } & Promise<import("nuxt/dist/app/composables/asyncData")._AsyncData<BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>, import("nuxt/app").NuxtError<unknown> | null> & {
67
+ fetching: import("vue").Ref<boolean>;
68
+ fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
69
+ } & {
70
+ data: import("vue").Ref<BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>>;
71
+ items: import("vue").ComputedRef<import("@scayle/storefront-api").BasketItem<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>[]>;
72
+ cost: import("vue").ComputedRef<import("@scayle/storefront-api").BasketTotalPrice>;
73
+ key: import("vue").ComputedRef<import("@scayle/storefront-api").BasketKey>;
74
+ packages: import("vue").ComputedRef<import("@scayle/storefront-api").BasketPackageInformation[]>;
14
75
  shippingDates: import("vue").ComputedRef<(string | null)[] | undefined>;
15
76
  isEmpty: import("vue").ComputedRef<boolean>;
16
77
  fetching: import("vue").Ref<boolean>;
17
78
  fetch: (opts?: import("nuxt/dist/app/composables/asyncData").AsyncDataExecuteOptions | undefined) => Promise<void>;
18
- count: import("vue").ComputedRef<number | undefined>;
19
- countWithoutSoldOutItems: import("vue").ComputedRef<number | undefined>;
79
+ count: import("vue").ComputedRef<number>;
80
+ countWithoutSoldOutItems: import("vue").ComputedRef<number>;
20
81
  addItem: ({ variantId, promotionId, quantity, existingItemHandling, displayData, customData, itemGroup, }: AddOrUpdateItemType & {
21
82
  existingItemHandling?: ExistingItemHandling;
22
83
  }) => Promise<void>;