@scayle/storefront-nuxt 8.10.4 → 8.11.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +1 -1
  4. package/dist/runtime/api/cacheAuth.d.ts +20 -5
  5. package/dist/runtime/api/purgeAll.d.ts +12 -0
  6. package/dist/runtime/api/purgeTags.d.ts +14 -0
  7. package/dist/runtime/api/rpcHandler.d.ts +17 -22
  8. package/dist/runtime/api/up.d.ts +8 -0
  9. package/dist/runtime/cached.d.ts +13 -0
  10. package/dist/runtime/campaignKey.d.ts +18 -0
  11. package/dist/runtime/composables/core/useAvailableShops.d.ts +10 -0
  12. package/dist/runtime/composables/core/useCurrentShop.d.ts +10 -0
  13. package/dist/runtime/composables/core/useFormatHelpers.d.ts +57 -6
  14. package/dist/runtime/composables/core/useIDP.d.ts +17 -0
  15. package/dist/runtime/composables/core/useLog.d.ts +12 -0
  16. package/dist/runtime/composables/core/useRpc.d.ts +76 -24
  17. package/dist/runtime/composables/core/useRpcCall.d.ts +40 -0
  18. package/dist/runtime/composables/core/useSession.d.ts +10 -0
  19. package/dist/runtime/composables/core/useUser.d.ts +24 -0
  20. package/dist/runtime/composables/storefront/useBasket.d.ts +24 -0
  21. package/dist/runtime/composables/storefront/useBrand.d.ts +21 -0
  22. package/dist/runtime/composables/storefront/useBrands.d.ts +21 -0
  23. package/dist/runtime/composables/storefront/useCategories.d.ts +28 -0
  24. package/dist/runtime/composables/storefront/useCategoryById.d.ts +21 -0
  25. package/dist/runtime/composables/storefront/useCategoryByPath.d.ts +21 -0
  26. package/dist/runtime/composables/storefront/useCurrentPromotions.d.ts +24 -0
  27. package/dist/runtime/composables/storefront/useFilters.d.ts +21 -0
  28. package/dist/runtime/composables/storefront/useNavigationTree.d.ts +42 -0
  29. package/dist/runtime/composables/storefront/useNavigationTrees.d.ts +21 -0
  30. package/dist/runtime/composables/storefront/useOrder.d.ts +23 -0
  31. package/dist/runtime/composables/storefront/useOrderConfirmation.d.ts +21 -0
  32. package/dist/runtime/composables/storefront/useProduct.d.ts +21 -0
  33. package/dist/runtime/composables/storefront/useProducts.d.ts +21 -0
  34. package/dist/runtime/composables/storefront/useProductsByIds.d.ts +21 -0
  35. package/dist/runtime/composables/storefront/useProductsByReferenceKeys.d.ts +21 -0
  36. package/dist/runtime/composables/storefront/useProductsCount.d.ts +19 -0
  37. package/dist/runtime/composables/storefront/usePromotions.d.ts +21 -0
  38. package/dist/runtime/composables/storefront/usePromotionsByIds.d.ts +21 -0
  39. package/dist/runtime/composables/storefront/useShopConfiguration.d.ts +21 -0
  40. package/dist/runtime/composables/storefront/useStorefrontSearch.d.ts +11 -1
  41. package/dist/runtime/composables/storefront/useUserAddresses.d.ts +21 -0
  42. package/dist/runtime/composables/storefront/useVariant.d.ts +21 -0
  43. package/dist/runtime/composables/storefront/useWishlist.d.ts +29 -0
  44. package/dist/runtime/composables/useCoreLog.d.ts +13 -0
  45. package/dist/runtime/context.d.ts +25 -0
  46. package/dist/runtime/context.js +25 -1
  47. package/dist/runtime/createLog.d.ts +16 -0
  48. package/dist/runtime/handler.d.ts +18 -4
  49. package/dist/runtime/rpc/rpcCall.d.ts +15 -3
  50. package/dist/runtime/server/middleware/bootstrap-utils.d.ts +1 -1
  51. package/dist/runtime/utils/promise.d.ts +30 -6
  52. package/dist/runtime/utils/route.d.ts +11 -0
  53. package/dist/runtime/utils/seo.d.ts +13 -0
  54. package/package.json +7 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 8.11.1
4
+
5
+ ### Patch Changes
6
+
7
+ **Dependencies**
8
+
9
+ - Updated dependency to @scayle/storefront-core@8.10.0
10
+
11
+ ## 8.11.0
12
+
13
+ ### Minor Changes
14
+
15
+ - Include `rpcCall` when building the context. This utility function can be used within RPC methods to invoke another RPC method.
16
+
17
+ ### Patch Changes
18
+
19
+ **Dependencies**
20
+
21
+ - Updated dependency to @scayle/unstorage-compression-driver@0.2.4
22
+ - Updated dependency to @scayle/storefront-core@8.9.0
23
+
3
24
  ## 8.10.4
4
25
 
5
26
  ### Patch Changes
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
- "version": "8.10.4",
3
+ "version": "8.11.1",
4
4
  "configKey": "storefront",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.9.0"
package/dist/module.mjs CHANGED
@@ -46,7 +46,7 @@ export default {
46
46
  }`;
47
47
  }
48
48
  const PACKAGE_NAME = "@scayle/storefront-nuxt";
49
- const PACKAGE_VERSION = "8.10.4";
49
+ const PACKAGE_VERSION = "8.11.1";
50
50
  const logger = createConsola({
51
51
  fancy: true,
52
52
  formatOptions: {
@@ -1,12 +1,27 @@
1
1
  import type { EventHandler } from 'h3';
2
2
  /**
3
- * Wrap an event handler protected by the authentication specified in `cache.auth`
4
- * @param handler
3
+ * Wraps an event handler with cache authentication.
4
+ *
5
+ * It takes an event handler and returns a new handler that is protected by
6
+ * basic authentication if cache authentication is configured in the runtime config (`cache.auth`).
7
+ * If cache authentication is not configured, the original handler is returned.
8
+ *
9
+ * @param handler The event handler to wrap.
10
+ *
11
+ * @returns The wrapped event handler.
5
12
  */
6
13
  export declare const eventHandlerWithCacheAuth: (handler: EventHandler) => EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
7
14
  /**
8
- * Wrap an event handler with basic auth
9
- * @param handler
10
- * @param auth
15
+ * Wraps an event handler with basic authentication.
16
+ *
17
+ * This function enhances a given event handler with basic authentication functionality.
18
+ * It checks for an Authorization header in the request and compares the decoded
19
+ * credentials with the provided authentication string. If the credentials match,
20
+ * the original handler is executed.
21
+ *
22
+ * @param handler The event handler to be wrapped.
23
+ * @param auth The authentication string in the format 'username:password'.
24
+ *
25
+ * @returns The wrapped and awaited event handler, else an authentication failure response is returned.
11
26
  */
12
27
  export declare const eventHandlerWithBasicAuth: (handler: EventHandler, auth: string) => EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
@@ -1,2 +1,14 @@
1
+ /**
2
+ * Purges the entire cache.
3
+ *
4
+ * This event handler purges all entries from the configured cache.
5
+ * It requires both `$rpcContext` and `$cache` to be present in the event context.
6
+ * If either is missing, it returns a 500 Internal Server Error.
7
+ * If the purge operation is successful, it returns a 200 OK with `{ success: true }`.
8
+ * If an error occurs during purging, it returns a 500 Internal Server Error with `{ success: false }`
9
+ * and logs the error using the logger provided by `$rpcContext`.
10
+ *
11
+ * @returns A promise that resolves to either an object indicating success or a `Response` object indicating an error.
12
+ */
1
13
  declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
2
14
  export default _default;
@@ -1,2 +1,16 @@
1
+ /**
2
+ * Purges cache entries by tags.
3
+ *
4
+ * This event handler purges cache entries associated with the provided tags.
5
+ * It requires both `$rpcContext` and `$cache` to be present in the event context.
6
+ * If either is missing, it returns a 500 Internal Server Error.
7
+ * It reads an array of tags from the request body.
8
+ * If the body is empty or no tags are provided, it returns a 400 Bad Request.
9
+ * If the purge operation is successful, it returns 200 OK with `{ success: true }`.
10
+ * If an error occurs during the purge, it returns a 500 Internal Server Error with `{ success: false }`
11
+ * and logs the error using the logger provided by the `$rpcContext`.
12
+ *
13
+ * @returns A promise resolving to an object indicating success or a `Response` object with an error status.
14
+ */
1
15
  declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
2
16
  export default _default;
@@ -1,21 +1,19 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<string | true | string[] | import("@scayle/storefront-core").ShopUser | Response | import("@scayle/storefront-api").Product | import("@scayle/storefront-api").Product[] | {
2
- count: number;
3
- } | {
4
- filters: import("@scayle/storefront-api").FiltersEndpointResponseData;
5
- unfilteredCount: number;
6
- } | {
7
- products: import("@scayle/storefront-api").Product[];
8
- pagination: {
9
- current: number;
10
- total: number;
11
- perPage: number;
12
- page: number;
13
- first: number;
14
- prev: number;
15
- next: number;
16
- last: number;
17
- };
18
- } | {
1
+ /**
2
+ * Generic event handler for RPC methods.
3
+ *
4
+ * It retrieves the RPC method name from the request path,
5
+ * reads the payload from the request body.
6
+ * It utilizes hooks provided by Nitro to allow for custom logic before,
7
+ * after, and in case of errors during RPC calls.
8
+ *
9
+ * @param event The H3 event object.
10
+ *
11
+ * @returns The result of the RPC call or a `Response` object with an error status.
12
+ */
13
+ declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<string | true | string[] | import("@scayle/storefront-core").ShopUser | Response | import("@scayle/storefront-api").Product | import("@scayle/storefront-api").Product[] | import("@scayle/storefront-core").FetchProductsCountResponse | import("@scayle/storefront-core").FetchFiltersResponse | import("@scayle/storefront-core").FetchProductsByCategoryResponse | import("@scayle/storefront-api").Wishlist | {
14
+ accessToken: string;
15
+ checkoutJwt: string;
16
+ } | import("@scayle/storefront-api").VariantDetail[] | {
19
17
  basket: import("@scayle/storefront-api").BasketResponseData<import("@scayle/storefront-api").Product, import("@scayle/storefront-api").Variant>;
20
18
  } | {
21
19
  readonly type: "success";
@@ -32,10 +30,7 @@ declare const _default: import("h3").EventHandler<import("h3").EventHandlerReque
32
30
  activeNode: import("@scayle/storefront-api").Category;
33
31
  } | import("@scayle/storefront-core").Order | import("@scayle/storefront-api").SearchV2SuggestionsEndpointResponseData | import("@scayle/storefront-api").SearchEntity | import("@scayle/storefront-api").ShopConfiguration | {
34
32
  user: import("@scayle/storefront-core").ShopUser | undefined;
35
- } | import("@scayle/storefront-api").Wishlist | import("@scayle/storefront-core").ShopUserAddress[] | {
36
- accessToken: string;
37
- checkoutJwt: string;
38
- } | import("@scayle/storefront-api").VariantDetail[] | import("@scayle/storefront-api").NavigationAllEndpointResponseData | import("@scayle/storefront-api").NavigationTree | {
33
+ } | import("@scayle/storefront-core").ShopUserAddress[] | import("@scayle/storefront-api").NavigationAllEndpointResponseData | import("@scayle/storefront-api").NavigationTree | {
39
34
  success: true;
40
35
  } | {
41
36
  success: false;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Health check endpoint.
3
+ *
4
+ * This simple endpoint returns a JSON object indicating that the service is up.
5
+ * It is typically used for monitoring and health checks.
6
+ *
7
+ * @returns An object with a status property set to 'up'.
8
+ */
1
9
  declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, {
2
10
  status: string;
3
11
  }>;
@@ -1,2 +1,15 @@
1
1
  import { type Log, type CacheInterface } from '@scayle/storefront-core';
2
+ /**
3
+ * Creates and returns a bound cached function.
4
+ *
5
+ * It initializes a new `Cached` instance with provided parameters and
6
+ * returns its `execute` method bound to the instance.
7
+ * This allows for easy use of the caching functionality provided by `@scayle/storefront-core`.
8
+ *
9
+ * @param $cache The cache interface instance.
10
+ * @param $log The logging instance.
11
+ * @param enabled Whether caching is enabled or not. Defaults to true if undefined.
12
+ *
13
+ * @returns A bound function that can be used to execute cached operations.
14
+ */
2
15
  export declare function getCachedFunction($cache: CacheInterface, $log: Log, enabled: boolean | undefined): <TArgs extends unknown[], TResult>(fn: (...args: TArgs) => Promise<TResult>, options?: import("@scayle/storefront-core").CacheOptions) => Awaited<(...args: TArgs) => Promise<TResult>>;
@@ -1,2 +1,20 @@
1
1
  import type { StorefrontAPIClient, CachedType, Log } from '@scayle/storefront-core';
2
+ /**
3
+ * Fetches the key of the first active campaign.
4
+ *
5
+ * Retrieves campaigns from the Storefront API, filters for non-ended campaigns,
6
+ * sorts them, and returns the key of the first active one.
7
+ * The retrieved campaigns are cached for a specified duration.
8
+ *
9
+ * @see https://scayle.dev/en/user-guide/shops/promotions/discounts-and-offers/price-campaigns
10
+ * @see https://scayle.dev/en/api-guides/storefront-api/resources/campaigns/list-campaigns
11
+ *
12
+ * @param sapiClient The Storefront API client.
13
+ * @param cached The caching function.
14
+ * @param log The logging instance.
15
+ *
16
+ * @throws {Error} If fetching or processing campaigns fails.
17
+ *
18
+ * @returns The key of the first active campaign, or undefined if no active campaign is found or an error occurs.
19
+ */
2
20
  export declare const fetchCampaignKey: (sapiClient: StorefrontAPIClient, cached: CachedType, log: Log) => Promise<string | undefined>;
@@ -1,2 +1,12 @@
1
1
  import type { PublicShopConfig } from '../../../module.js';
2
+ /**
3
+ * Provides a reactive list of available shops.
4
+ *
5
+ * This composable uses [`useState`](https://nuxt.com/docs/api/composables/use-state)
6
+ * to create a reactive state variable that holds an array of `PublicShopConfig` objects.
7
+ * The initial value of the state is an empty array. This state can be used to
8
+ * dynamically display data of the available shops within the application.
9
+ *
10
+ * @returns A reactive `ref` containing an array of available shop configurations.
11
+ */
2
12
  export declare function useAvailableShops(): import("vue").Ref<PublicShopConfig[], PublicShopConfig[]>;
@@ -1,3 +1,13 @@
1
1
  import type { Ref } from 'vue';
2
2
  import type { PublicShopConfig } from '../../../module.js';
3
+ /**
4
+ * Provides a reactive reference to the current shop configuration.
5
+ *
6
+ * This composable retrieves the current shop configuration from the Nuxt app instance.
7
+ * It then uses [`useState`](https://nuxt.com/docs/api/composables/use-state) to
8
+ * create a reactive reference to this configuration, allowing components
9
+ * to reactively update when the current shop changes.
10
+ *
11
+ * @returns A reactive `ref` to the current shop's configuration.
12
+ */
3
13
  export declare const useCurrentShop: () => Ref<PublicShopConfig>;
@@ -1,20 +1,71 @@
1
+ /**
2
+ * Representation of options for formatting currencies.
3
+ *
4
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
5
+ */
1
6
  type FormatCurrencyOptions = {
7
+ /**
8
+ * The locale to use for formatting.
9
+ */
2
10
  locale?: string;
11
+ /**
12
+ * The number of fraction digits to use for the currency.
13
+ */
3
14
  currencyFractionDigits?: number;
15
+ /**
16
+ * The style ('currency' or 'decimal') to use for formatting. Defaults to 'currency'.
17
+ */
4
18
  style?: 'currency';
19
+ /**
20
+ * The currency code (e.g., 'EUR', 'USD') to use for formatting.
21
+ */
5
22
  currency: string;
6
23
  } | {
24
+ /**
25
+ * The locale to use for formatting.
26
+ */
7
27
  locale?: string;
28
+ /**
29
+ * The number of fraction digits to use for the currency.
30
+ */
8
31
  currencyFractionDigits?: number;
32
+ /**
33
+ * The style to use for formatting.
34
+ */
9
35
  style: 'decimal';
10
36
  };
37
+ /**
38
+ * Representation of options for formatting percentages.
39
+ *
40
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat
41
+ */
42
+ type FormatPercentageOptions = {
43
+ /**
44
+ * The locale to use for formatting.
45
+ */
46
+ locale?: string;
47
+ /**
48
+ * The minimum number of fraction digits to use.
49
+ */
50
+ minimumFractionDigits?: number;
51
+ /**
52
+ * The maximum number of fraction digits to use.
53
+ */
54
+ maximumFractionDigits?: number;
55
+ /**
56
+ * How to display the sign for the percentage.
57
+ */
58
+ signDisplay?: Intl.NumberFormatOptions['signDisplay'];
59
+ };
60
+ /**
61
+ * Provides currency and percentage formatting helpers.
62
+ *
63
+ * It leverages the current shop's locale and currency settings.
64
+ *
65
+ * @returns An object containing the formatCurrency and formatPercentage functions.
66
+ */
11
67
  export declare function useFormatHelpers(): {
12
68
  formatCurrency: (value: number, options?: FormatCurrencyOptions) => string;
13
- formatPercentage: (value: number, options?: {
14
- locale?: string;
15
- minimumFractionDigits?: number;
16
- maximumFractionDigits?: number;
17
- signDisplay?: Intl.NumberFormatOptions["signDisplay"];
18
- }) => string;
69
+ formatPercentage: (value: number, options?: FormatPercentageOptions) => string;
19
70
  };
20
71
  export {};
@@ -1,6 +1,23 @@
1
1
  import type { MaybeRefOrGetter } from 'vue';
2
2
  import type { RpcMethodParameters } from '@scayle/storefront-core';
3
3
  import { type UseRpcReturn } from '../core/useRpc.js';
4
+ /**
5
+ * The shape of the data returned by the `getExternalIdpRedirect` RPC call.
6
+ */
4
7
  type UseIDPBaseReturn = Pick<Awaited<UseRpcReturn<'getExternalIdpRedirect'>>, 'data' | 'error' | 'status' | 'refresh'>;
8
+ /**
9
+ * Retrieves an external IDP redirect URL.
10
+ *
11
+ * This composables uses the `useRpc` composable to call the `getExternalIdpRedirect` RPC method.
12
+ *
13
+ * @see https://scayle.dev/en/storefront-guide/developer-guide/basic-setup/authentication#redirect-url
14
+ *
15
+ * @param params The parameters for the `getExternalIdpRedirect` RPC call.
16
+ * @param key A unique key for the RPC call. Used for caching and invalidation. Defaults to 'useIDP'.
17
+
18
+ * @returns An object containing the `data` returned from, any `error` encountered within,
19
+ the current `status` and a function to manually `refresh` the RPC call.
20
+ * It also acts as a promise that resolves to the same object.
21
+ */
5
22
  export declare function useIDP(params?: MaybeRefOrGetter<RpcMethodParameters<'getExternalIdpRedirect'>>, key?: string): UseIDPBaseReturn & Promise<UseIDPBaseReturn>;
6
23
  export {};
@@ -1,2 +1,14 @@
1
1
  import type { Log } from '@scayle/storefront-core';
2
+ /**
3
+ * Retrieves a logging instance.
4
+ *
5
+ * It allows for creating a namespaced logger using the provided `subSpace` argument.
6
+ * If a namespace is specified, the function will return a logger scoped to that subspace.
7
+ * Otherwise, it returns the root logger.
8
+ *
9
+ * @param subSpace The namespace to create the logger for.
10
+ *
11
+ * @returns The log instance, a namespace is specified, a logger scoped to that subspace.
12
+ * Otherwise, it returns the root logger.
13
+ */
2
14
  export declare function useLog(subSpace?: string): Log;
@@ -1,41 +1,93 @@
1
1
  import type { RpcContext, RpcMethodName, RpcMethodParameters, RpcMethodReturnType } from '@scayle/storefront-core';
2
2
  import { type AsyncDataOptions, useAsyncData } from 'nuxt/app';
3
3
  import { type MaybeRefOrGetter } from 'vue';
4
+ /**
5
+ * Extracts keys from a type `T` as an array of strings.
6
+ *
7
+ * @template T The type from which to extract keys.
8
+ */
4
9
  export type KeysOf<T> = Array<T extends T ? (keyof T extends string ? keyof T : never) : never>;
5
- /** The normalized return type of an RPC */
10
+ /**
11
+ * Normalized return type of a RPC method, excluding its `Response` object.
12
+ *
13
+ * @template N The RPC Method Name.
14
+ */
6
15
  export type NormalizedRpcResponse<N extends RpcMethodName> = Exclude<Awaited<RpcMethodReturnType<N>>, Response>;
16
+ /**
17
+ * Representation of options for the `useRpc` composable, extending `AsyncDataOptions`.
18
+ *
19
+ * @template N The RPC Method Name.
20
+ * @template DataT The data type. Defaults to `NormalizedRpcResponse<N>`.
21
+ * @template PickKeys The keys to pick from `DataT`. Defaults to all keys of `DataT`.
22
+ * @template DefaultT The default value type. Defaults to `null`.
23
+ * @template ResponseT The response type. Defaults to `NormalizedRpcResponse<N>`.
24
+ */
7
25
  export type UseRpcOptions<N extends RpcMethodName, DataT = NormalizedRpcResponse<N>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null, ResponseT = NormalizedRpcResponse<N>> = AsyncDataOptions<ResponseT, DataT, PickKeys, DefaultT>;
8
26
  /**
9
- * The return type of a composable based on useRpc
27
+ * Return type of the `useRpc` composable, extending `ExtendedAsyncData`.
28
+ *
29
+ * @template N The RPC Method Name.
30
+ * @template DataT The data type. Defaults to `NormalizedRpcResponse<N>`.
31
+ * @template PickKeys The keys to pick from `DataT.` Defaults to all keys of `DataT`.
32
+ * @template DefaultT The default value type. Defaults to `null`.
33
+ * @template ResponseT The response type. Defaults to `NormalizedRpcResponse<N>`.
10
34
  */
11
35
  export type UseRpcReturn<N extends RpcMethodName, DataT = NormalizedRpcResponse<N>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null, ResponseT = NormalizedRpcResponse<N>> = ExtendedAsyncData<ResponseT, unknown, DataT, PickKeys, DefaultT>;
12
36
  export type Status = 'idle' | 'pending' | 'success' | 'error';
13
37
  type AsyncData<ResT, ErrorT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null> = ReturnType<typeof useAsyncData<ResT, ErrorT, DataT, PickKeys, DefaultT>>;
14
38
  type AwaitedAsyncData<ResT, ErrorT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null> = Awaited<AsyncData<ResT, ErrorT, DataT, PickKeys, DefaultT>>;
39
+ /**
40
+ * Extended `AsyncData` type, adding a promise to the result.
41
+ *
42
+ * @template ResT The response type.
43
+ * @template ErrorT The error type. Defaults to `unknown`.
44
+ * @template DataT The data type. Defaults to `ResT`.
45
+ * @template PickKeys The keys to pick from `DataT`. Defaults to all keys of `DataT`.
46
+ * @template DefaultT The default value type. Defaults to `null`.
47
+ */
15
48
  export type ExtendedAsyncData<ResT, ErrorT = unknown, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null> = AwaitedAsyncData<ResT, ErrorT, DataT, PickKeys, DefaultT> & Promise<AwaitedAsyncData<ResT, ErrorT, DataT, PickKeys, DefaultT>>;
16
49
  /**
17
- * `useRpc` is a wrapper around `useAsyncData` for registered RPC methods
18
- *
19
- * This is slightly different from the useRpc we have in Nuxt2
20
- * It is built on top of useAsyncData and matches its API more than the Nuxt2 API
21
- * Notably, fetch is now refresh. The fetching property remains the same.
22
- * It also doesn't directly use rpcCall, instead calling $fetch directly
23
- * The main difference regards how params are passed:
24
- * In Nuxt2 for an RPC with params, the params are passed when calling `fetch`.
25
- * In Nuxt3 for an RPC with params, the params are passed to `useRpc`.
26
- * Additionally, in Nuxt3 the params can be `Params`, `Ref<Params>` or `() => Params`
27
- *
28
- * @param method - the RPC method name
29
- * @param key - a unique key for persisting the data between server and client and de-duplicating requests
30
- * @param params - parameters to pass to the RPC method.
31
- * This can be specified in three ways: as a raw value, a `Ref` or a function that returns the params
32
- * - When passed as a raw value, the parameters are set at the point `useRpc` is called. Subsequent `refresh` calls will use the same params.
33
- * - When passed as a function, the function will be invoked each time `refresh` is called to get the params.
34
- * - When passed as a Ref, a watcher wil be added that calls `refresh` each time params change.
35
- * @param options - Override the options passed to `useAsyncData`.
36
- * By default, `useRpc` will set `immediate` to `false` and will pass `[params]` to `watch` if `params` is a `Ref`.
37
- * But anything passed here will take precedence.
38
- * @see {@link https://nuxt.com/docs/api/composables/use-async-data#params}
50
+ * `useRpc` is a wrapper around `useAsyncData` for registered RPC methods.
51
+ *
52
+ * This composable provides a declarative approach to data fetching by wrapping
53
+ * `useAsyncData` for registered RPC methods. It handles the fetch state,
54
+ * automatically executes the RPC method, and returns the result or any errors.
55
+ * Many Storefront composables utilize `useRpc` as lightweight wrappers around provided RPC methods.
56
+ *
57
+ * The parameters for the RPC call can be passed as a raw value, a ref, or a function. If a reactive ref or function is provided,
58
+ * `useRpc` will automatically re-fetch the data when the parameters change.
59
+ *
60
+ * By default, `useRpc` utilizes a shared cache, so all instances called with the same key will share the same data. This behavior can be
61
+ * disabled globally via the `disableDefaultGetCachedDataOverride` option in the public runtime config, or individually per call using the `options` parameter.
62
+ *
63
+ * @see https://nuxt.com/docs/api/composables/use-async-data#params
64
+ * @see https://scayle.dev/en/storefront-guide/developer-guide/basic-setup/rpc-methods#userpc
65
+ *
66
+ * @param method The name of the RPC method to call (e.g., 'useBrand).
67
+ * @param key A unique key for caching, persisting the data between server and client,
68
+ * and de-duplicating requests (e.g., 'use-brand').
69
+ * @param params The parameters for the RPC method. Can be a value, a `Ref`,
70
+ * or a function. If reactive, changes will trigger a re-fetch.
71
+ * - When passed as a raw value, the parameters are set at the point
72
+ * `useRpc` is called. Subsequent `refresh` calls will use the same params.
73
+ * - When passed as a function, the function will be invoked each
74
+ * time `refresh` is called to get the params.
75
+ * - When passed as a Ref, a watcher wil be added that
76
+ * calls `refresh` each time params change.
77
+ * @param options Options for `useAsyncData`, including `watch`, `getCachedData`,
78
+ * and more. Can be used to control caching behavior. By default,
79
+ * `useRpc` will set `immediate` to `false` and will pass `[params]`
80
+ * to `watch` if `params` is a `Ref`.
81
+ *
82
+ * @returns An object containing the `data`, `status`, and other properties from
83
+ * `useAsyncData`, as well as a promise that resolves to the data.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * import { useRpc } from '#storefront/composables'
88
+ *
89
+ * const { data: shopId, fetching } = useRpc('getShopId', 'current-shop-id')
90
+ * ```
39
91
  */
40
92
  export declare function useRpc<N extends RpcMethodName, DataT = NormalizedRpcResponse<N>, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null, ResponseT = NormalizedRpcResponse<N>>(method: N, key: string, params?: MaybeRefOrGetter<RpcMethodParameters<N> extends RpcContext ? undefined : RpcMethodParameters<N>>, options?: UseRpcOptions<N, DataT, PickKeys, DefaultT, ResponseT>): ExtendedAsyncData<ResponseT, unknown, DataT, PickKeys, DefaultT>;
41
93
  export {};
@@ -1,2 +1,42 @@
1
1
  import type { RpcContext, RpcMethodName, RpcMethodParameters, RpcMethodReturnType } from '@scayle/storefront-core';
2
+ /**
3
+ * Provides a function for calling a specified RPC method.
4
+ *
5
+ * This function acts as a factory, returning a function that can be used to
6
+ * call the given RPC method. It's designed for calling RPCs in response to
7
+ * events or user interactions, such as clicking a button or submitting a form.
8
+ * `useRpcCall` accepts the RPC method name and returns a callback function.
9
+ * When invoked, this callback receives the RPC parameters, makes the request,
10
+ * and returns a promise that resolves with the RPC's response.
11
+ *
12
+ * @template N The RPC Method Name.
13
+ * @template P The RPC Method Parameters.
14
+ * @template TResult The result type of the RPC method, excluding its`Response` object.
15
+ * @template TakesParameters A boolean indicating whether the RPC method takes parameters.
16
+ * It's `undefined` if the parameters extend `RpcContext`.
17
+ *
18
+ * @param method The name of the RPC method.
19
+ *
20
+ * @returns A function to call the specified RPC method. This returned function
21
+ * will accept the RPC method parameters (if any) and return a Promise
22
+ * that resolves with the result of the RPC call.
23
+ *
24
+ * @example
25
+ * ```html
26
+ * <!-- Example of a `subscribeToNewsletter` RPC method, triggered by a form submission -->
27
+ * <script setup lang="ts">
28
+ * import { useRpcCall } from '#storefront/composables'
29
+ * import { ref } from 'vue';
30
+ *
31
+ * const subscribeToNewsletter = useRpcCall('subscribeToNewsletter')
32
+ * const email = ref('hello@scayle.com')
33
+ *
34
+ * const onSubmit = async () => {
35
+ * const res = await subscribeToNewsletter({ email: email.value })
36
+ *
37
+ * console.log(res)
38
+ * }
39
+ * </script>
40
+ * ```
41
+ */
2
42
  export declare function useRpcCall<N extends RpcMethodName, P extends RpcMethodParameters<N>, TResult extends Exclude<Awaited<RpcMethodReturnType<N>>, Response>, TakesParameters = P extends RpcContext ? undefined : boolean>(method: N): TakesParameters extends undefined ? () => Promise<TResult> : (params: P) => Promise<TResult>;
@@ -1,3 +1,13 @@
1
+ /**
2
+ * Provides functions for managing user sessions, including login, registration, guest login, token refresh, revocation, password reset, and IDP login.
3
+ *
4
+ * This composable leverages `useRpcCall` to interact with corresponding RPC methods.
5
+ *
6
+ * @see https://scayle.dev/en/storefront-guide/developer-guide/basic-setup/sessions
7
+ * @see https://scayle.dev/en/storefront-guide/developer-guide/basic-setup/authentication
8
+ *
9
+ * @returns An object containing functions for various session management operations.
10
+ */
1
11
  export declare function useSession(): {
2
12
  login: (params: import("utility-types").Optional<import("@scayle/storefront-core").LoginRequest, "shop_id">) => Promise<never>;
3
13
  register: (params: import("utility-types").Optional<import("@scayle/storefront-core").RegisterRequest, "shop_id">) => Promise<never>;
@@ -1,9 +1,15 @@
1
1
  import type { ShopUser, UpdatePasswordParams } from '@scayle/storefront-core';
2
2
  import { type UseRpcReturn } from './useRpc.js';
3
3
  import { type ComputedRef } from 'vue';
4
+ /**
5
+ * Extended parameters for the `useUser` composable.
6
+ */
4
7
  export type ExtendedUseUserParams = {
8
+ /** The key used for caching the user data. Defaults to 'useUser'. */
5
9
  key?: string;
10
+ /** Whether to fetch the user data immediately. Defaults to `true`. */
6
11
  immediate?: boolean;
12
+ /** Whether to enable lazy loading of user data. Defaults to `false`. */
7
13
  lazy?: boolean;
8
14
  };
9
15
  type UseUserBaseReturn = Pick<Awaited<UseRpcReturn<'getUser'>>, 'error' | 'status' | 'refresh'> & {
@@ -14,5 +20,23 @@ type UseUserBaseReturn = Pick<Awaited<UseRpcReturn<'getUser'>>, 'error' | 'statu
14
20
  customerType: ComputedRef<'new' | 'guest' | 'existing'>;
15
21
  forceRefresh: () => Promise<void>;
16
22
  };
23
+ /**
24
+ * Provides user information and related actions.
25
+ *
26
+ * This composable retrieves user data via the `getUser` RPC method and offers
27
+ * functionalities to update user details, change passwords, and force-refresh user data.
28
+ * It uses `useRpc` for data fetching and provides computed properties for user status,
29
+ * login status, and customer type.
30
+ *
31
+ * The composable also handles caching of user data and allows for lazy loading
32
+ * and immediate fetching based on the provided options.
33
+ *
34
+ * @param options Options to customize the behavior of the composable,
35
+ * such as caching key, immediate fetching, and lazy loading.
36
+ *
37
+ * @returns A promise that resolves to an object containing user information,
38
+ * update functions, and status properties. It also includes the resolved
39
+ * object directly as properties.
40
+ */
17
41
  export declare function useUser(options?: ExtendedUseUserParams): UseUserBaseReturn & Promise<UseUserBaseReturn>;
18
42
  export {};
@@ -5,6 +5,9 @@ import { type NormalizedRpcResponse, type UseRpcReturn } from '../core/useRpc.js
5
5
  import { type MaybeRefOrGetter, type ComputedRef, type Ref } from 'vue';
6
6
  import type { BasketKey, BasketPackageInformation } from '@scayle/storefront-api';
7
7
  import type { BasketItemUpdateData } from '@scayle/storefront-core/dist/rpc/methods/index';
8
+ /**
9
+ * Representation of options for configuring the `useBasket` composable.
10
+ */
8
11
  type UseBasketOptions = Partial<{
9
12
  params: MaybeRefOrGetter<Omit<RpcMethodParameters<'getBasket'>, 'orderCustomData'>>;
10
13
  key: string;
@@ -58,5 +61,26 @@ type UseBasketBaseReturn = Omit<Awaited<UseRpcReturn<'getBasket'>>, 'data'> & {
58
61
  /** @deprecated In a future release `shippingDates` will be removed. Consider using {@link getShippingDates} instead. */
59
62
  shippingDates: ComputedRef<(string | null)[] | undefined>;
60
63
  };
64
+ /**
65
+ * Manages basket interactions. Provides functionalities for adding, removing, updating, and clearing
66
+ * basket items, as well as accessing basket information like items, cost, and count.
67
+ *
68
+ * This function acts as a wrapper around the `useRpc` composable for basket data,
69
+ * simplifying the process of fetching brand data. It internally calls `useRpc`
70
+ * with the provided parameters and options. It utilizes the `getCachedData` option
71
+ * within `useRpc` to retrieve cached basket data during hydration or from async data otherwise.
72
+ * This helps avoid unnecessary re-fetches and improves performance. Specifically,
73
+ * it checks `nuxtApp._asyncData` for existing data associated with the provided key.
74
+ * This approach addresses a [Nuxt typing issue](https://github.com/nuxt/nuxt/issues/26093)
75
+ * requiring a type assertion to `WishlistResponseData`.
76
+ *
77
+ * @param options An object containing parameters and options for all basket-related RPC calls.
78
+ * @param options.params Parameters for the 'getBasket' RPC call (excluding `orderCustomData`).
79
+ * @param key A unique key for identifying the basket instance. Defaults to 'useBasket'.
80
+ *
81
+ * @returns A promise resolving to an object with basket data, methods, and reactive properties.
82
+ *
83
+ * @throws {Error} If an item cannot be found during removal or if an item is added with a reduced quantity. Also throws FetchError if RPC calls fail.
84
+ */
61
85
  export declare function useBasket({ params, }?: UseBasketOptions, key?: string): UseBasketBaseReturn & Promise<UseBasketBaseReturn>;
62
86
  export {};