@scayle/storefront-nuxt 7.51.2 → 7.53.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,32 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 7.53.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Nest public `runtimeConfig` properties under the `storefront` key
8
+
9
+ Breaking: `useRuntimeConfig().public.log` and `useRuntimeConfig().public.auth` should be replaced by `useRuntimeConfig().public.storefront.log` and `useRuntimeConfig().public.storefront.log`
10
+
11
+ ## 7.52.0
12
+
13
+ ### Minor Changes
14
+
15
+ - Allow the session of an `RpcContext` to be undefined
16
+
17
+ BREAKING: This changes the structure of the `RpcContext`, so it may be a breaking change if you have written custom RPC methods.
18
+
19
+ The affected properties on the `RpcContext` are `sessionId`, `wishlistKey` and `basketKey` and the affected methods are `destroySession`, `createUserBoundSession`, `updateUser`, and `updateTokens`. If you use these methods or properties in a custom RPC method, make sure that you handle the case where they might be undefined. TypeScript will also catch these cases if you have `strictNullChecks` enabled.
20
+
21
+ You can check `context.sessionId` (or another session-dependent property) to determine if the session is present. If one of these properties is present, all will be. Alternatively, you can call `assertSession(context)` before referencing any properties on the context. If the session is not present, an error will be thrown. For any usage of `context` after `assertSession` is called, TypeScript will understand that the session properties are present.
22
+
23
+ - Do not attach session for cached request
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies
28
+ - @scayle/storefront-core@7.38.0
29
+
3
30
  ## 7.51.2
4
31
 
5
32
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- export { g as AdditionalShopConfig, A as AppKeys, f as AuthenticationConfig, B as BapiConfig, b as CacheConfig, k as CheckoutEvent, C as CheckoutShopConfig, M as ModuleOptions, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, h as ShopConfig, i as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, j as StorefrontConfig } from './shared/storefront-nuxt.8b6c06b3.mjs';
1
+ export { g as AdditionalShopConfig, A as AppKeys, f as AuthenticationConfig, B as BapiConfig, b as CacheConfig, k as CheckoutEvent, C as CheckoutShopConfig, M as ModuleOptions, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, h as ShopConfig, i as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, j as StorefrontConfig } from './shared/storefront-nuxt.32ffc293.mjs';
2
2
  export { rpcCall } from './rpc.mjs';
3
3
  export * from '@scayle/storefront-core';
4
4
  export { LogLevel } from '@scayle/storefront-core';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { g as AdditionalShopConfig, A as AppKeys, f as AuthenticationConfig, B as BapiConfig, b as CacheConfig, k as CheckoutEvent, C as CheckoutShopConfig, M as ModuleOptions, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, h as ShopConfig, i as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, j as StorefrontConfig } from './shared/storefront-nuxt.8b6c06b3.js';
1
+ export { g as AdditionalShopConfig, A as AppKeys, f as AuthenticationConfig, B as BapiConfig, b as CacheConfig, k as CheckoutEvent, C as CheckoutShopConfig, M as ModuleOptions, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, h as ShopConfig, i as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, j as StorefrontConfig } from './shared/storefront-nuxt.32ffc293.js';
2
2
  export { rpcCall } from './rpc.js';
3
3
  export * from '@scayle/storefront-core';
4
4
  export { LogLevel } from '@scayle/storefront-core';
package/dist/module.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { M as ModuleOptions } from './shared/storefront-nuxt.8b6c06b3.mjs';
3
- export { g as AdditionalShopConfig, A as AppKeys, f as AuthenticationConfig, B as BapiConfig, b as CacheConfig, k as CheckoutEvent, C as CheckoutShopConfig, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, h as ShopConfig, i as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, j as StorefrontConfig } from './shared/storefront-nuxt.8b6c06b3.mjs';
2
+ import { M as ModuleOptions } from './shared/storefront-nuxt.32ffc293.mjs';
3
+ export { g as AdditionalShopConfig, A as AppKeys, f as AuthenticationConfig, B as BapiConfig, b as CacheConfig, k as CheckoutEvent, C as CheckoutShopConfig, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, h as ShopConfig, i as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, j as StorefrontConfig } from './shared/storefront-nuxt.32ffc293.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 ModuleOptions } from './shared/storefront-nuxt.8b6c06b3.js';
3
- export { g as AdditionalShopConfig, A as AppKeys, f as AuthenticationConfig, B as BapiConfig, b as CacheConfig, k as CheckoutEvent, C as CheckoutShopConfig, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, h as ShopConfig, i as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, j as StorefrontConfig } from './shared/storefront-nuxt.8b6c06b3.js';
2
+ import { M as ModuleOptions } from './shared/storefront-nuxt.32ffc293.js';
3
+ export { g as AdditionalShopConfig, A as AppKeys, f as AuthenticationConfig, B as BapiConfig, b as CacheConfig, k as CheckoutEvent, C as CheckoutShopConfig, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, h as ShopConfig, i as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, j as StorefrontConfig } from './shared/storefront-nuxt.32ffc293.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
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.9.0"
6
6
  },
7
- "version": "7.51.1"
7
+ "version": "7.52.0"
8
8
  }
package/dist/module.mjs CHANGED
@@ -100,12 +100,10 @@ const module = defineNuxtModule({
100
100
  nuxt.options.runtimeConfig.storefront,
101
101
  options
102
102
  );
103
- nuxt.options.runtimeConfig.cache = {
104
- auth: options.cache?.auth
103
+ nuxt.options.runtimeConfig.public.storefront = {
104
+ log: options.log,
105
+ auth: options.auth
105
106
  };
106
- nuxt.options.runtimeConfig.public.publicShopData = options.publicShopData;
107
- nuxt.options.runtimeConfig.public.log = options.log;
108
- nuxt.options.runtimeConfig.public.auth = options.auth;
109
107
  extendViteConfig((config) => {
110
108
  config.optimizeDeps = config.optimizeDeps || {};
111
109
  config.optimizeDeps.include = config.optimizeDeps.include || [];
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.8b6c06b3.mjs';
3
+ import { P as PublicShopConfig } from './shared/storefront-nuxt.32ffc293.mjs';
4
4
  import '@scayle/unstorage-compression-driver';
5
5
  import 'unstorage';
6
6
 
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.8b6c06b3.js';
3
+ import { P as PublicShopConfig } from './shared/storefront-nuxt.32ffc293.js';
4
4
  import '@scayle/unstorage-compression-driver';
5
5
  import 'unstorage';
6
6
 
@@ -44,7 +44,7 @@ export declare function useBasket({ params, options, key, }?: UseBasketOptions):
44
44
  shopId: string;
45
45
  userId: string;
46
46
  log?: import("@scayle/storefront-core").Log | undefined;
47
- }) => Promise<any>;
47
+ }) => Promise<string>;
48
48
  mergeBaskets: (args: {
49
49
  fromBasketKey: string;
50
50
  toBasketKey: string;
@@ -7,8 +7,8 @@ export interface ContextBuilderOptions {
7
7
  $shopConfig: ShopConfig;
8
8
  $storefront: StorefrontConfig;
9
9
  $log: Log;
10
- sessionId: string;
11
- session: Session;
10
+ sessionId?: string;
11
+ session?: Session;
12
12
  config: RuntimeConfig;
13
13
  }
14
14
  export declare const buildContext: (context: ContextBuilderOptions) => Promise<RpcContext>;
@@ -4,8 +4,72 @@ import {
4
4
  generateBasketKey,
5
5
  generateWishlistKey
6
6
  } from "@scayle/storefront-core/dist/utils/keys";
7
+ async function getWishlistKey(appKeys, session, $log, $shopConfig) {
8
+ return session.data.user ? await generateWishlistKey({
9
+ keyTemplate: appKeys.wishlistKey,
10
+ userId: String(session.data.user.id),
11
+ shopId: String($shopConfig.shopId),
12
+ hashAlgorithm: appKeys.hashAlgorithm,
13
+ log: $log
14
+ }) : session.id;
15
+ }
16
+ async function getBasketKey(appKeys, session, $log, $shopConfig) {
17
+ return session.data.user ? await generateBasketKey({
18
+ keyTemplate: appKeys.basketKey,
19
+ userId: String(session.data.user.id),
20
+ shopId: String($shopConfig.shopId),
21
+ hashAlgorithm: appKeys.hashAlgorithm,
22
+ log: $log
23
+ }) : session?.id;
24
+ }
25
+ async function sessionProperties(context) {
26
+ const { $shopConfig, $storefront, $log, session } = context;
27
+ const appKeys = $shopConfig.appKeys ?? $storefront.appKeys;
28
+ if (session) {
29
+ return {
30
+ wishlistKey: await getWishlistKey(appKeys, session, $log, $shopConfig),
31
+ basketKey: await getBasketKey(appKeys, session, $log, $shopConfig),
32
+ sessionId: session.id,
33
+ get user() {
34
+ return session.data?.user ?? void 0;
35
+ },
36
+ get accessToken() {
37
+ return session.data?.accessToken ?? void 0;
38
+ },
39
+ destroySession: async () => {
40
+ await session.destroy();
41
+ },
42
+ createUserBoundSession: async () => {
43
+ $log.debug("creating user bound session");
44
+ const data = session.data;
45
+ await session.regenerate();
46
+ session.data = data;
47
+ await session.save();
48
+ },
49
+ updateUser: async (user) => {
50
+ session.data.user = user;
51
+ await session.save();
52
+ },
53
+ updateTokens: async (tokens) => {
54
+ Object.assign(session.data, tokens);
55
+ await session.save();
56
+ }
57
+ };
58
+ }
59
+ return {
60
+ wishlistKey: void 0,
61
+ basketKey: void 0,
62
+ sessionId: void 0,
63
+ user: void 0,
64
+ accessToken: void 0,
65
+ destroySession: void 0,
66
+ createUserBoundSession: void 0,
67
+ updateUser: void 0,
68
+ updateTokens: void 0
69
+ };
70
+ }
7
71
  export const buildContext = async (context) => {
8
- const { $cache, $shopConfig, $storefront, $log, session, config } = context;
72
+ const { $cache, $shopConfig, $storefront, $log, config } = context;
9
73
  const bapiConfig = $shopConfig.bapi ?? $storefront.bapi;
10
74
  const appKeys = $shopConfig.appKeys ?? $storefront.appKeys;
11
75
  const idpConfig = $shopConfig.idp ?? $storefront.idp;
@@ -17,20 +81,7 @@ export const buildContext = async (context) => {
17
81
  authentication: "token",
18
82
  token: bapiConfig.token
19
83
  }),
20
- wishlistKey: session.data.user ? await generateWishlistKey({
21
- keyTemplate: appKeys.wishlistKey,
22
- userId: String(session.data.user.id),
23
- shopId: String($shopConfig.shopId),
24
- hashAlgorithm: appKeys.hashAlgorithm,
25
- log: $log
26
- }) : session.id,
27
- basketKey: session.data.user ? await generateBasketKey({
28
- keyTemplate: appKeys.basketKey,
29
- userId: String(session.data.user.id),
30
- shopId: String($shopConfig.shopId),
31
- hashAlgorithm: appKeys.hashAlgorithm,
32
- log: $log
33
- }) : session.id,
84
+ ...await sessionProperties(context),
34
85
  auth: {
35
86
  resetPasswordUrl: $shopConfig.auth?.resetPasswordUrl
36
87
  },
@@ -48,21 +99,8 @@ export const buildContext = async (context) => {
48
99
  },
49
100
  idp: idpConfig,
50
101
  log: $log,
51
- get user() {
52
- return session.data?.user ?? void 0;
53
- },
54
- destroySession: async () => {
55
- await session.destroy();
56
- },
57
102
  destroySessionsForUserId: async () => {
58
103
  },
59
- createUserBoundSession: async () => {
60
- $log.debug("creating user bound session");
61
- const data = session.data;
62
- await session.regenerate();
63
- session.data = data;
64
- await session.save();
65
- },
66
104
  generateBasketKeyForUserId: (userId) => generateBasketKey({
67
105
  keyTemplate: appKeys.basketKey,
68
106
  userId,
@@ -83,18 +121,6 @@ export const buildContext = async (context) => {
83
121
  domain: $shopConfig.domain,
84
122
  withParams: $storefront.withParams,
85
123
  campaignKey: $shopConfig.storeCampaignKeyword,
86
- updateUser: async (user) => {
87
- session.data.user = user;
88
- await session.save();
89
- },
90
- sessionId: context.sessionId,
91
- get accessToken() {
92
- return session.data?.accessToken ?? void 0;
93
- },
94
- updateTokens: async (tokens) => {
95
- Object.assign(session.data, tokens);
96
- await session.save();
97
- },
98
124
  runtimeConfiguration: config
99
125
  };
100
126
  };
@@ -3,7 +3,11 @@ import { createConsola } from "consola/browser";
3
3
  import createLog from "../createLog.mjs";
4
4
  export default defineNuxtPlugin((nuxtApp) => {
5
5
  const config = useRuntimeConfig().public;
6
- const log = createLog(createConsola, config.log.name, config.log.level);
6
+ const log = createLog(
7
+ createConsola,
8
+ config.storefront.log.name,
9
+ config.storefront.log.level
10
+ );
7
11
  const coreLog = log.space("sfc");
8
12
  coreLog.debug("Attached client-side logger");
9
13
  addClientSideErrorHandling(log, nuxtApp.vueApp);
@@ -85,13 +85,17 @@ async function bootstrap(event, url, $shopConfig, $storefrontConfig, apiBasePath
85
85
  );
86
86
  event.context.$cache = $cache;
87
87
  bootstrapLog.debug("Building context for request");
88
+ const cacheableRoute = !!event.context._nitro.routeRules.cache;
89
+ if (cacheableRoute) {
90
+ bootstrapLog.debug("Skipping session for cached request");
91
+ }
88
92
  event.context.$rpcContext = await buildContext({
89
93
  $cache,
90
94
  $shopConfig,
91
95
  $storefront: $storefrontConfig,
92
96
  $log: log,
93
- sessionId: event.context.sessionId,
94
- session: event.context.session,
97
+ sessionId: cacheableRoute ? void 0 : event.context.sessionId,
98
+ session: cacheableRoute ? void 0 : event.context.session,
95
99
  config
96
100
  });
97
101
  }
@@ -175,12 +175,13 @@ declare module '@nuxt/schema' {
175
175
  storefront: ModuleOptions;
176
176
  }
177
177
  interface PublicRuntimeConfig {
178
- imageBaseUrl: string;
179
- log: {
180
- name: string;
181
- level: LogLevel;
178
+ storefront: {
179
+ log: {
180
+ name: string;
181
+ level: LogLevel;
182
+ };
183
+ auth: AuthenticationConfig;
182
184
  };
183
- auth: AuthenticationConfig;
184
185
  }
185
186
  }
186
187
 
@@ -175,12 +175,13 @@ declare module '@nuxt/schema' {
175
175
  storefront: ModuleOptions;
176
176
  }
177
177
  interface PublicRuntimeConfig {
178
- imageBaseUrl: string;
179
- log: {
180
- name: string;
181
- level: LogLevel;
178
+ storefront: {
179
+ log: {
180
+ name: string;
181
+ level: LogLevel;
182
+ };
183
+ auth: AuthenticationConfig;
182
184
  };
183
- auth: AuthenticationConfig;
184
185
  }
185
186
  }
186
187
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
3
  "type": "module",
4
- "version": "7.51.2",
4
+ "version": "7.53.0",
5
5
  "description": "Nuxt integration for the SCAYLE Commerce Engine and Storefront API",
6
6
  "author": "SCAYLE Commerce Engine",
7
7
  "license": "MIT",
@@ -62,11 +62,11 @@
62
62
  "dependencies": {
63
63
  "@nuxt/kit": "3.9.3",
64
64
  "@scayle/h3-session": "0.3.5",
65
- "@scayle/storefront-core": "7.37.0",
65
+ "@scayle/storefront-core": "7.38.0",
66
66
  "@scayle/unstorage-compression-driver": "0.1.1",
67
67
  "@vueuse/core": "10.7.2",
68
68
  "consola": "3.2.3",
69
- "core-js": "3.35.0",
69
+ "core-js": "3.35.1",
70
70
  "defu": "6.1.4",
71
71
  "h3": "1.10.0",
72
72
  "jose": "^5.2.0",