@scayle/storefront-nuxt 8.29.0 → 8.30.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 8.30.0
4
+
5
+ ### Patch Changes
6
+
7
+ **Dependencies**
8
+
9
+ **@scayle/storefront-core v8.30.0**
10
+
11
+ - Minor
12
+
13
+ - Added `defineRpcHandler` utility function that enhances RPC handlers with type-safe metadata for improved registration and invocation of RPC handlers. While defining RPC handlers without this utility remains supported, its usage is recommended and may become mandatory in a future major release.
14
+
15
+ Existing RPC handlers can be easily migrated to use `defineRpcHandler` by passing the existing handler to `defineRpcHandler`.
16
+
17
+ ```ts
18
+ export const existingHandlerWithoutParams = async (_context: RpcContext) => {
19
+ return 'existing handler'
20
+ }
21
+
22
+ export const existingHandlerWithParams = async (
23
+ { name }: { name: string },
24
+ _context: RpcContext,
25
+ ) => {
26
+ return name
27
+ }
28
+
29
+ // will become
30
+
31
+ export const existingHandlerWithoutParams = defineRpcHandler(
32
+ async (_context: RpcContext) => {
33
+ return 'existing handler'
34
+ },
35
+ )
36
+ export const existingHandlerWithParams = defineRpcHandler(
37
+ async ({ name }: { name: string }, _context: RpcContext) => {
38
+ return name
39
+ },
40
+ )
41
+ ```
42
+
43
+ - Patch
44
+ - Removed unused `Awaited` and `PromiseReturnType` types.
45
+
3
46
  ## 8.29.0
4
47
 
5
48
  ### Patch Changes
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
- "version": "8.29.0",
3
+ "version": "8.30.0",
4
4
  "configKey": "storefront",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.9.0"
package/dist/module.mjs CHANGED
@@ -54,7 +54,7 @@ export default {
54
54
  }`;
55
55
  }
56
56
  const PACKAGE_NAME = "@scayle/storefront-nuxt";
57
- const PACKAGE_VERSION = "8.29.0";
57
+ const PACKAGE_VERSION = "8.30.0";
58
58
  const logger = createConsola({
59
59
  fancy: true,
60
60
  formatOptions: {
@@ -19,4 +19,4 @@ import type { RpcContext, RpcMethodName, RpcMethodParameters, RpcMethodReturnTyp
19
19
  *
20
20
  * @throws {Error} If the specified RPC method is not found.
21
21
  */
22
- export declare const invokeRpc: <N extends RpcMethodName, P extends RpcMethodParameters<N>, TResult extends Awaited<RpcMethodReturnType<N>>, TakesParameters = P extends RpcContext ? undefined : boolean, TParams = TakesParameters extends undefined ? null : P>(method: N, payload: TParams, rpcContext: RpcContext) => Promise<TResult | Response>;
22
+ export declare const invokeRpc: <N extends RpcMethodName, P extends RpcMethodParameters<N>, TResult extends Awaited<RpcMethodReturnType<N>>, TakesParameters = P extends RpcContext ? undefined : boolean, TParams = TakesParameters extends undefined ? null : P>(method: N, payload: TParams, rpcContext: RpcContext) => Promise<TResult>;
@@ -1,24 +1,22 @@
1
1
  import { rpcMethods as coreRpcMethods } from "@scayle/storefront-core";
2
2
  import * as storefrontRpcMethods from "#virtual/customRpcMethods";
3
- export const invokeRpc = async (method, payload, rpcContext) => {
4
- const rpcMethods = {
3
+ import { normalizeRpcHandler } from "./utils/rpc.js";
4
+ const rpcMethods = Object.fromEntries(
5
+ Object.entries({
5
6
  ...coreRpcMethods,
6
7
  ...storefrontRpcMethods
7
- };
8
+ }).map(([key, value]) => [key, normalizeRpcHandler(value)])
9
+ );
10
+ export const invokeRpc = async (method, payload, rpcContext) => {
8
11
  if (!Object.hasOwn(rpcMethods, method)) {
9
12
  throw new Error(`RPC Method [${method}] was not found`);
10
13
  }
11
14
  const log = rpcContext.log.space("sfc").space("rpc");
15
+ const handlerFunction = rpcMethods[method];
12
16
  return await log.time(`Calling RPC method: ${method}`, async () => {
13
- const fun = rpcMethods[method];
14
- if (fun.length === 1) {
15
- return await fun(
16
- rpcContext
17
- );
17
+ if (handlerFunction.rpcType === "NoParam") {
18
+ return await handlerFunction(rpcContext);
18
19
  }
19
- return await fun(
20
- payload,
21
- rpcContext
22
- );
20
+ return await handlerFunction(payload, rpcContext);
23
21
  });
24
22
  };
@@ -0,0 +1,10 @@
1
+ import { type RpcMethods, type RpcMethodName, type RpcHandler } from '@scayle/storefront-core';
2
+ /**
3
+ * Normalizes a rpc handler function that are not defined with `defineRpcHandler`.
4
+ * Normalization sets the `rpcType` property to `WithParam` or `NoParam` based on the number of parameters the handler function takes.
5
+ * Handlers that already have this property set are returned without modification.
6
+ *
7
+ * @param handler - The handler function to normalize.
8
+ * @returns The normalized handler function with an `rpcType` property.
9
+ */
10
+ export declare const normalizeRpcHandler: <T extends RpcMethods[RpcMethodName], NormalizedHandler = T extends RpcHandler<infer R> ? RpcHandler<R> & Required<Pick<RpcHandler<R>, "rpcType">> : T extends RpcHandler<infer P, infer R> ? RpcHandler<P, R> & Required<Pick<RpcHandler<P, R>, "rpcType">> : never>(handler: T) => NormalizedHandler;
@@ -0,0 +1,9 @@
1
+ import {
2
+ defineRpcHandler
3
+ } from "@scayle/storefront-core";
4
+ export const normalizeRpcHandler = (handler) => {
5
+ if (handler && !("rpcType" in handler)) {
6
+ return defineRpcHandler(handler);
7
+ }
8
+ return handler;
9
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
3
  "type": "module",
4
- "version": "8.29.0",
4
+ "version": "8.30.0",
5
5
  "description": "Nuxt integration for the SCAYLE Commerce Engine and Storefront API",
6
6
  "author": "SCAYLE Commerce Engine",
7
7
  "license": "MIT",
@@ -81,7 +81,7 @@
81
81
  "dependencies": {
82
82
  "@opentelemetry/api": "^1.9.0",
83
83
  "@scayle/h3-session": "0.6.1",
84
- "@scayle/storefront-core": "8.29.0",
84
+ "@scayle/storefront-core": "8.30.0",
85
85
  "@scayle/unstorage-compression-driver": "^1.0.0",
86
86
  "@vercel/nft": "0.29.4",
87
87
  "@vueuse/core": "13.3.0",
@@ -108,7 +108,7 @@
108
108
  "@nuxt/module-builder": "1.0.1",
109
109
  "@nuxt/schema": "3.16.2",
110
110
  "@nuxt/test-utils": "3.18.0",
111
- "@scayle/eslint-config-storefront": "4.5.5",
111
+ "@scayle/eslint-config-storefront": "4.5.6",
112
112
  "@scayle/eslint-plugin-vue-composable": "0.2.1",
113
113
  "@scayle/unstorage-scayle-kv-driver": "1.0.1",
114
114
  "@types/node": "22.15.32",