@scayle/storefront-nuxt 7.78.1 → 7.79.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,52 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 7.79.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Import `useNitroApp` from `#imports`
8
+
9
+ ## 7.79.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Add hooks before and after RPC execution (`storefront:rpc:before` and `storefront:rpc:after`) and when an RPC fails (`storefront:rpc:error`)
14
+
15
+ These hooks allow you to execute extra logic before/after executing an RPC and even alter the properties of the RPC context/result.
16
+
17
+ Hooks can be registered by adding a nitro plugin inside ´server/plugins/´:
18
+
19
+ ```ts
20
+ import { defineNitroPlugin } from "#imports";
21
+
22
+ export default defineNitroPlugin((nitroApp) => {
23
+ nitroApp.hooks.hook("storefront:rpc:before", (rpcName, rpcContext) => {
24
+ rpcContext.log.debug(`Before: ${rpcName}`);
25
+ });
26
+
27
+ nitroApp.hooks.hook(
28
+ "storefront:rpc:after",
29
+ (rpcName, rpcContext, result) => {
30
+ rpcContext.log.debug(`After: ${rpcName} returned ${result}`);
31
+ }
32
+ );
33
+
34
+ nitroApp.hooks.hook(
35
+ "storefront:rpc:error",
36
+ (rpcName, rpcContext, error) => {
37
+ rpcContext.log.error(`ERROR: ${rpcName} did throw ${error}`);
38
+ }
39
+ );
40
+ });
41
+ ```
42
+
43
+ Added [`callHook`](https://github.com/unjs/hookable?tab=readme-ov-file#async-callhook-name-args), `callHookParallel` and [`callHookWith`](https://github.com/unjs/hookable?tab=readme-ov-file#callhookwith-name-callerfn) to `RpcContext` to allow triggering hooks within RPCs
44
+
45
+ ### Patch Changes
46
+
47
+ - Updated dependencies
48
+ - @scayle/storefront-core@7.59.0
49
+
3
50
  ## 7.78.1
4
51
 
5
52
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,12 +1,12 @@
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.b2288199.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.2c3f3a8a.mjs';
2
2
  export { rpcCall } from './rpc.mjs';
3
3
  export * from '@scayle/storefront-core';
4
4
  export { LogLevel } from '@scayle/storefront-core';
5
5
  export { unwrap } from '@scayle/storefront-core/dist/utils/response';
6
- import '@nuxt/schema';
7
6
  import '@scayle/unstorage-compression-driver';
8
7
  import 'unstorage';
9
8
  import 'zod';
9
+ import '@nuxt/schema';
10
10
  import 'nuxt/app';
11
11
 
12
12
  /**
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
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.b2288199.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.2c3f3a8a.js';
2
2
  export { rpcCall } from './rpc.js';
3
3
  export * from '@scayle/storefront-core';
4
4
  export { LogLevel } from '@scayle/storefront-core';
5
5
  export { unwrap } from '@scayle/storefront-core/dist/utils/response';
6
- import '@nuxt/schema';
7
6
  import '@scayle/unstorage-compression-driver';
8
7
  import 'unstorage';
9
8
  import 'zod';
9
+ import '@nuxt/schema';
10
10
  import 'nuxt/app';
11
11
 
12
12
  /**
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.b2288199.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.b2288199.mjs';
2
+ import { M as ModuleBaseOptions } from './shared/storefront-nuxt.2c3f3a8a.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.2c3f3a8a.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.b2288199.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.b2288199.js';
2
+ import { M as ModuleBaseOptions } from './shared/storefront-nuxt.2c3f3a8a.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.2c3f3a8a.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.78.0",
3
+ "version": "7.79.0",
4
4
  "configKey": "storefront",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.9.0"
package/dist/module.mjs CHANGED
@@ -65,7 +65,7 @@ export default {
65
65
  }`;
66
66
  }
67
67
  const PACKAGE_NAME = "@scayle/storefront-nuxt";
68
- const PACKAGE_VERSION = "7.78.0";
68
+ const PACKAGE_VERSION = "7.79.0";
69
69
  const logger = createConsola({
70
70
  fancy: true,
71
71
  formatOptions: {
package/dist/rpc.d.mts CHANGED
@@ -1,10 +1,10 @@
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.b2288199.mjs';
4
- import '@nuxt/schema';
3
+ import { P as PublicShopConfig } from './shared/storefront-nuxt.2c3f3a8a.mjs';
5
4
  import '@scayle/unstorage-compression-driver';
6
5
  import 'unstorage';
7
6
  import 'zod';
7
+ import '@nuxt/schema';
8
8
 
9
9
  /**
10
10
  * rpcCall can be used to invoke an RPC method either on the client or server
package/dist/rpc.d.ts CHANGED
@@ -1,10 +1,10 @@
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.b2288199.js';
4
- import '@nuxt/schema';
3
+ import { P as PublicShopConfig } from './shared/storefront-nuxt.2c3f3a8a.js';
5
4
  import '@scayle/unstorage-compression-driver';
6
5
  import 'unstorage';
7
6
  import 'zod';
7
+ import '@nuxt/schema';
8
8
 
9
9
  /**
10
10
  * rpcCall can be used to invoke an RPC method either on the client or server
@@ -3,6 +3,7 @@ import { purifySensitiveData } from "@scayle/storefront-core";
3
3
  import { trace, SpanStatusCode } from "@opentelemetry/api";
4
4
  import { handler } from "../handler.mjs";
5
5
  import { resolveError } from "../error/handler.mjs";
6
+ import { useNitroApp } from "#imports";
6
7
  const tracer = trace.getTracer(
7
8
  "storefront-nuxt",
8
9
  "__sfc_version"
@@ -21,6 +22,7 @@ export default defineEventHandler(async (event) => {
21
22
  )
22
23
  );
23
24
  event.context.$rpcContext.log.space("sfc").debug(`RPC Handler: ${method}, Payload: ${payloadToBeLogged}`);
25
+ const nitroApp = useNitroApp();
24
26
  return await tracer.startActiveSpan(
25
27
  `storefront-nuxt.rpc/${method}`,
26
28
  {
@@ -36,7 +38,19 @@ export default defineEventHandler(async (event) => {
36
38
  async (span) => {
37
39
  let result;
38
40
  try {
41
+ await nitroApp.hooks?.callHook(
42
+ "storefront:rpc:before",
43
+ method,
44
+ event.context.$rpcContext,
45
+ body?.payload
46
+ );
39
47
  result = await handler(method, body?.payload, event.context.$rpcContext);
48
+ await nitroApp.hooks.callHook(
49
+ "storefront:rpc:after",
50
+ method,
51
+ event.context.$rpcContext,
52
+ result
53
+ );
40
54
  if (result instanceof Response && !result.ok) {
41
55
  span.setStatus({ code: SpanStatusCode.ERROR });
42
56
  } else {
@@ -44,6 +58,12 @@ export default defineEventHandler(async (event) => {
44
58
  }
45
59
  } catch (e) {
46
60
  event.context.$rpcContext.log.space("sfc").error(`RPC Handler failed: ${method}`, e);
61
+ await nitroApp.hooks.callHook(
62
+ "storefront:rpc:error",
63
+ method,
64
+ event.context.$rpcContext,
65
+ e
66
+ );
47
67
  result = createError(resolveError(e));
48
68
  if (e instanceof Error) {
49
69
  span.recordException(e);
@@ -92,6 +92,7 @@ export const buildContext = async (context) => {
92
92
  }
93
93
  });
94
94
  const cached = new Cached($cache, $log, "", $storefront.cache?.enabled ?? true).execute;
95
+ const { hooks } = useNitroApp();
95
96
  const baseContext = {
96
97
  cached,
97
98
  bapiClient,
@@ -142,13 +143,15 @@ export const buildContext = async (context) => {
142
143
  ),
143
144
  runtimeConfiguration: config,
144
145
  ip: getRequestIP(event, { xForwardedFor: true }),
145
- headers: createAndPurifyHeaders(getRequestHeaders(event))
146
+ headers: createAndPurifyHeaders(getRequestHeaders(event)),
147
+ callHook: hooks.callHook,
148
+ callHookParallel: hooks.callHookParallel,
149
+ callHookWith: hooks.callHookWith
146
150
  };
147
151
  const rpcContext = Object.defineProperties({}, {
148
152
  ...Object.getOwnPropertyDescriptors(baseContext),
149
153
  ...Object.getOwnPropertyDescriptors(await sessionProperties(context))
150
154
  });
151
- const nitro = useNitroApp();
152
- await nitro.hooks?.callHook("storefront:context:created", rpcContext);
155
+ await hooks?.callHook("storefront:context:created", rpcContext);
153
156
  return rpcContext;
154
157
  };
@@ -1,8 +1,8 @@
1
- import { HookResult } from '@nuxt/schema';
2
- import { LogLevel, RpcContext, HashAlgorithm, WithParams, rpcMethods, ShopUser } from '@scayle/storefront-core';
1
+ import { LogLevel, StorefrontHooks, RpcContext, RpcMethodName, HashAlgorithm, WithParams, rpcMethods, ShopUser } from '@scayle/storefront-core';
3
2
  import { CompressionEncodings } from '@scayle/unstorage-compression-driver';
4
3
  import { BuiltinDriverName, BuiltinDriverOptions } from 'unstorage';
5
4
  import { z } from 'zod';
5
+ import { HookResult } from '@nuxt/schema';
6
6
 
7
7
  declare const RedirectsSchema: z.ZodObject<{
8
8
  enabled: z.ZodBoolean;
@@ -1128,8 +1128,11 @@ declare module '@nuxt/schema' {
1128
1128
  }
1129
1129
  }
1130
1130
  declare module 'nitropack' {
1131
- interface NitroRuntimeHooks {
1131
+ interface NitroRuntimeHooks extends StorefrontHooks {
1132
1132
  'storefront:context:created': (context: RpcContext) => HookResult;
1133
+ 'storefront:rpc:before': (rpcName: RpcMethodName, context: RpcContext, payload: unknown) => HookResult;
1134
+ 'storefront:rpc:after': (rpcName: RpcMethodName, context: RpcContext, result: unknown) => HookResult;
1135
+ 'storefront:rpc:error': (rpcName: RpcMethodName, context: RpcContext, error: unknown) => HookResult;
1133
1136
  }
1134
1137
  }
1135
1138
 
@@ -1,8 +1,8 @@
1
- import { HookResult } from '@nuxt/schema';
2
- import { LogLevel, RpcContext, HashAlgorithm, WithParams, rpcMethods, ShopUser } from '@scayle/storefront-core';
1
+ import { LogLevel, StorefrontHooks, RpcContext, RpcMethodName, HashAlgorithm, WithParams, rpcMethods, ShopUser } from '@scayle/storefront-core';
3
2
  import { CompressionEncodings } from '@scayle/unstorage-compression-driver';
4
3
  import { BuiltinDriverName, BuiltinDriverOptions } from 'unstorage';
5
4
  import { z } from 'zod';
5
+ import { HookResult } from '@nuxt/schema';
6
6
 
7
7
  declare const RedirectsSchema: z.ZodObject<{
8
8
  enabled: z.ZodBoolean;
@@ -1128,8 +1128,11 @@ declare module '@nuxt/schema' {
1128
1128
  }
1129
1129
  }
1130
1130
  declare module 'nitropack' {
1131
- interface NitroRuntimeHooks {
1131
+ interface NitroRuntimeHooks extends StorefrontHooks {
1132
1132
  'storefront:context:created': (context: RpcContext) => HookResult;
1133
+ 'storefront:rpc:before': (rpcName: RpcMethodName, context: RpcContext, payload: unknown) => HookResult;
1134
+ 'storefront:rpc:after': (rpcName: RpcMethodName, context: RpcContext, result: unknown) => HookResult;
1135
+ 'storefront:rpc:error': (rpcName: RpcMethodName, context: RpcContext, error: unknown) => HookResult;
1133
1136
  }
1134
1137
  }
1135
1138
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
3
  "type": "module",
4
- "version": "7.78.1",
4
+ "version": "7.79.1",
5
5
  "description": "Nuxt integration for the SCAYLE Commerce Engine and Storefront API",
6
6
  "author": "SCAYLE Commerce Engine",
7
7
  "license": "MIT",
@@ -60,12 +60,13 @@
60
60
  "@nuxt/kit": "3.11.2",
61
61
  "@opentelemetry/api": "1.9.0",
62
62
  "@scayle/h3-session": "0.4.0",
63
- "@scayle/storefront-core": "7.58.3",
63
+ "@scayle/storefront-core": "7.59.0",
64
64
  "@scayle/unstorage-compression-driver": "0.1.3",
65
65
  "@vueuse/core": "10.11.0",
66
66
  "consola": "3.2.3",
67
67
  "core-js": "3.37.1",
68
68
  "defu": "6.1.4",
69
+ "hookable": "5.5.3",
69
70
  "jose": "^5.2.0",
70
71
  "knitwork": "1.1.0",
71
72
  "nitropack": "2.9.7",
@@ -86,7 +87,7 @@
86
87
  "@scayle/eslint-config-storefront": "4.2.0",
87
88
  "@scayle/eslint-plugin-vue-composable": "0.2.0",
88
89
  "@types/node": "20.14.9",
89
- "dprint": "0.46.3",
90
+ "dprint": "0.47.0",
90
91
  "eslint": "9.6.0",
91
92
  "eslint-formatter-gitlab": "5.1.0",
92
93
  "fishery": "2.2.2",