@scayle/storefront-nuxt 8.29.0 → 8.30.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,58 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 8.30.1
4
+
5
+ ### Patch Changes
6
+
7
+ **Dependencies**
8
+
9
+ **@scayle/storefront-core v8.30.1**
10
+
11
+ - No changes in this release.
12
+
13
+ ## 8.30.0
14
+
15
+ ### Patch Changes
16
+
17
+ **Dependencies**
18
+
19
+ **@scayle/storefront-core v8.30.0**
20
+
21
+ - Minor
22
+
23
+ - 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.
24
+
25
+ Existing RPC handlers can be easily migrated to use `defineRpcHandler` by passing the existing handler to `defineRpcHandler`.
26
+
27
+ ```ts
28
+ export const existingHandlerWithoutParams = async (_context: RpcContext) => {
29
+ return 'existing handler'
30
+ }
31
+
32
+ export const existingHandlerWithParams = async (
33
+ { name }: { name: string },
34
+ _context: RpcContext,
35
+ ) => {
36
+ return name
37
+ }
38
+
39
+ // will become
40
+
41
+ export const existingHandlerWithoutParams = defineRpcHandler(
42
+ async (_context: RpcContext) => {
43
+ return 'existing handler'
44
+ },
45
+ )
46
+ export const existingHandlerWithParams = defineRpcHandler(
47
+ async ({ name }: { name: string }, _context: RpcContext) => {
48
+ return name
49
+ },
50
+ )
51
+ ```
52
+
53
+ - Patch
54
+ - Removed unused `Awaited` and `PromiseReturnType` types.
55
+
3
56
  ## 8.29.0
4
57
 
5
58
  ### 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.1",
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.1";
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.1",
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.1",
85
85
  "@scayle/unstorage-compression-driver": "^1.0.0",
86
86
  "@vercel/nft": "0.29.4",
87
87
  "@vueuse/core": "13.3.0",
@@ -108,11 +108,11 @@
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.7",
112
112
  "@scayle/eslint-plugin-vue-composable": "0.2.1",
113
- "@scayle/unstorage-scayle-kv-driver": "1.0.1",
113
+ "@scayle/unstorage-scayle-kv-driver": "1.0.2",
114
114
  "@types/node": "22.15.32",
115
- "@vitest/coverage-v8": "3.2.3",
115
+ "@vitest/coverage-v8": "3.2.4",
116
116
  "dprint": "0.50.0",
117
117
  "eslint-formatter-gitlab": "6.0.1",
118
118
  "eslint": "9.29.0",
@@ -125,7 +125,7 @@
125
125
  "publint": "0.2.12",
126
126
  "typescript": "5.8.3",
127
127
  "unbuild": "3.5.0",
128
- "vitest": "3.2.3",
128
+ "vitest": "3.2.4",
129
129
  "vue-tsc": "2.2.10"
130
130
  },
131
131
  "peerDependencies": {