@scayle/storefront-nuxt 7.69.1 → 7.70.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,38 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 7.70.0
4
+
5
+ ### Minor Changes
6
+
7
+ - `rpcContext.campaignKey` will now be set to the key of the first active campaign matching `$shopConfig.storeCampaignKeyword`. When `$shopConfig.storeCampaignKeyword` is set, campaign keys not starting with `$shopConfig.storeCampaignKeyword` will be ignored.
8
+
9
+ This behavior, is now similar to the nuxt 2 implementation.
10
+
11
+ - It is now also possible to extend the RPCContext using the `storefront:context:created` nitro runtime hook.
12
+
13
+ ```ts
14
+ import { defineNitroPlugin } from "nitropack/runtime/plugin";
15
+ // Augment RpxContext type
16
+ declare module "@scayle/storefront-nuxt" {
17
+ interface AdditionalRpcContext {
18
+ myNewProp: string;
19
+ }
20
+ }
21
+
22
+ // Set new value on rpcContext
23
+ export default defineNitroPlugin((nitroApp) => {
24
+ nitroApp.hooks.hook("storefront:context:created", (rpcContext) => {
25
+ rpcContext.myNewProp = "My campaign key";
26
+ });
27
+ });
28
+ ```
29
+
30
+ ### Patch Changes
31
+
32
+ - Add campaignKey dependency to nitro
33
+ - Updated dependencies
34
+ - @scayle/storefront-core@7.51.0
35
+
3
36
  ## 7.69.1
4
37
 
5
38
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,8 +1,9 @@
1
- export { f as AdditionalShopConfig, A as AppKeys, B as BapiConfig, b as CacheConfig, j as CheckoutEvent, C as CheckoutShopConfig, M as ModuleOptions, k as ModulePublicRuntimeConfig, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, g as ShopConfig, h as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, i as StorefrontConfig } from './shared/storefront-nuxt.747e8a0a.mjs';
1
+ export { f as AdditionalShopConfig, A as AppKeys, B as BapiConfig, b as CacheConfig, j as CheckoutEvent, C as CheckoutShopConfig, M as ModuleOptions, k as ModulePublicRuntimeConfig, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, g as ShopConfig, h as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, i as StorefrontConfig } from './shared/storefront-nuxt.c7df291d.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';
6
7
  import '@scayle/unstorage-compression-driver';
7
8
  import 'unstorage';
8
9
  import 'nuxt/app';
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- export { f as AdditionalShopConfig, A as AppKeys, B as BapiConfig, b as CacheConfig, j as CheckoutEvent, C as CheckoutShopConfig, M as ModuleOptions, k as ModulePublicRuntimeConfig, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, g as ShopConfig, h as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, i as StorefrontConfig } from './shared/storefront-nuxt.747e8a0a.js';
1
+ export { f as AdditionalShopConfig, A as AppKeys, B as BapiConfig, b as CacheConfig, j as CheckoutEvent, C as CheckoutShopConfig, M as ModuleOptions, k as ModulePublicRuntimeConfig, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, g as ShopConfig, h as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, i as StorefrontConfig } from './shared/storefront-nuxt.c7df291d.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';
6
7
  import '@scayle/unstorage-compression-driver';
7
8
  import 'unstorage';
8
9
  import 'nuxt/app';
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.747e8a0a.mjs';
3
- export { f as AdditionalShopConfig, A as AppKeys, B as BapiConfig, b as CacheConfig, j as CheckoutEvent, C as CheckoutShopConfig, k as ModulePublicRuntimeConfig, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, g as ShopConfig, h as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, i as StorefrontConfig } from './shared/storefront-nuxt.747e8a0a.mjs';
2
+ import { M as ModuleOptions } from './shared/storefront-nuxt.c7df291d.mjs';
3
+ export { f as AdditionalShopConfig, A as AppKeys, B as BapiConfig, b as CacheConfig, j as CheckoutEvent, C as CheckoutShopConfig, k as ModulePublicRuntimeConfig, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, g as ShopConfig, h as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, i as StorefrontConfig } from './shared/storefront-nuxt.c7df291d.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.747e8a0a.js';
3
- export { f as AdditionalShopConfig, A as AppKeys, B as BapiConfig, b as CacheConfig, j as CheckoutEvent, C as CheckoutShopConfig, k as ModulePublicRuntimeConfig, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, g as ShopConfig, h as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, i as StorefrontConfig } from './shared/storefront-nuxt.747e8a0a.js';
2
+ import { M as ModuleOptions } from './shared/storefront-nuxt.c7df291d.js';
3
+ export { f as AdditionalShopConfig, A as AppKeys, B as BapiConfig, b as CacheConfig, j as CheckoutEvent, C as CheckoutShopConfig, k as ModulePublicRuntimeConfig, O as OauthConfig, P as PublicShopConfig, e as RedirectsConfig, R as RedisConfig, a as SessionConfig, g as ShopConfig, h as ShopConfigIndexed, d as StorageConfig, c as StorageEntity, S as StorageProvider, i as StorefrontConfig } from './shared/storefront-nuxt.c7df291d.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.69.0",
3
+ "version": "7.69.1",
4
4
  "configKey": "storefront",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.9.0"
package/dist/module.mjs CHANGED
@@ -40,7 +40,7 @@ export default {
40
40
  }`;
41
41
  }
42
42
  const PACKAGE_NAME = "@scayle/storefront-nuxt";
43
- const PACKAGE_VERSION = "7.69.0";
43
+ const PACKAGE_VERSION = "7.69.1";
44
44
  const module = defineNuxtModule({
45
45
  meta: {
46
46
  name: PACKAGE_NAME,
@@ -153,7 +153,7 @@ const module = defineNuxtModule({
153
153
  route: `${apiBasePath}/up`,
154
154
  handler: resolve("./runtime/api/up")
155
155
  });
156
- const template = addTypeTemplate({
156
+ addTypeTemplate({
157
157
  filename: "types/storefront-bootstrap.d.ts",
158
158
  getContents: () => `// Auto-generated
159
159
  import type { RuntimeConfig } from '@nuxt/schema'
@@ -173,9 +173,6 @@ const module = defineNuxtModule({
173
173
  }
174
174
  export {}`
175
175
  });
176
- nuxt.hook("prepare:types", ({ references }) => {
177
- references.push({ path: template.dst });
178
- });
179
176
  addServerPlugin(resolve("./runtime/nitro/plugins/nitroLogger"));
180
177
  addServerPlugin(
181
178
  resolve("./runtime/nitro/plugins/nitroRuntimeStorageConfig")
@@ -187,6 +184,7 @@ const module = defineNuxtModule({
187
184
  const runtimePaths = [
188
185
  "handler",
189
186
  "error/handler",
187
+ "campaignKey",
190
188
  "context",
191
189
  "createLog",
192
190
  "log",
package/dist/rpc.d.mts CHANGED
@@ -1,6 +1,7 @@
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.747e8a0a.mjs';
3
+ import { P as PublicShopConfig } from './shared/storefront-nuxt.c7df291d.mjs';
4
+ import '@nuxt/schema';
4
5
  import '@scayle/unstorage-compression-driver';
5
6
  import 'unstorage';
6
7
 
package/dist/rpc.d.ts CHANGED
@@ -1,6 +1,7 @@
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.747e8a0a.js';
3
+ import { P as PublicShopConfig } from './shared/storefront-nuxt.c7df291d.js';
4
+ import '@nuxt/schema';
4
5
  import '@scayle/unstorage-compression-driver';
5
6
  import 'unstorage';
6
7
 
@@ -0,0 +1,6 @@
1
+ import type { StorefrontAPIClient, CachedType, Campaign, Log } from '@scayle/storefront-core';
2
+ export declare const isCampaignActive: (campaign?: Campaign) => boolean;
3
+ export declare const campaignHasNotEnded: (campaign: Campaign) => boolean;
4
+ export declare const campaignKeyMatchesKeyword: (campaign: Campaign, keyword?: string) => boolean;
5
+ export declare const sortCampaignsByDateAscending: (a: Campaign, b: Campaign) => number;
6
+ export declare const fetchCampaignKey: (bapiClient: StorefrontAPIClient, cached: CachedType, storeCampaignKeyword: string | undefined, log: Log) => Promise<string | undefined>;
@@ -0,0 +1,44 @@
1
+ export const isCampaignActive = (campaign) => {
2
+ if (!campaign) {
3
+ return false;
4
+ }
5
+ const timeNow = Date.now();
6
+ const campaignStart = new Date(campaign.start_at).getTime();
7
+ const hasStarted = timeNow >= campaignStart;
8
+ const campaignEnd = new Date(campaign.end_at).getTime();
9
+ const hasEnded = timeNow >= campaignEnd;
10
+ return hasStarted && !hasEnded;
11
+ };
12
+ export const campaignHasNotEnded = (campaign) => {
13
+ return new Date(campaign.end_at).getTime() > Date.now();
14
+ };
15
+ export const campaignKeyMatchesKeyword = (campaign, keyword) => {
16
+ if (!keyword) {
17
+ return true;
18
+ }
19
+ return campaign.key.toLowerCase().startsWith(keyword.toLowerCase());
20
+ };
21
+ export const sortCampaignsByDateAscending = (a, b) => {
22
+ return new Date(a.start_at).getTime() - new Date(b.start_at).getTime();
23
+ };
24
+ export const fetchCampaignKey = async (bapiClient, cached, storeCampaignKeyword, log) => {
25
+ try {
26
+ const { campaigns } = await cached(async () => {
27
+ const { entities } = await bapiClient.campaigns.get();
28
+ return {
29
+ campaigns: entities.filter((campaign) => {
30
+ return campaignHasNotEnded(campaign) && campaignKeyMatchesKeyword(campaign, storeCampaignKeyword);
31
+ }).sort(sortCampaignsByDateAscending)
32
+ };
33
+ }, {
34
+ cacheKeyPrefix: storeCampaignKeyword ? `fetch-campaignKey-${storeCampaignKeyword}` : "fetch-campaignKey",
35
+ ttl: 5 * 60
36
+ })();
37
+ return campaigns.find(isCampaignActive)?.key;
38
+ } catch (error) {
39
+ log.error(
40
+ "Failed to get or process the campaigns from SAPI.",
41
+ error
42
+ );
43
+ }
44
+ };
@@ -8,6 +8,8 @@ import {
8
8
  generateBasketKey,
9
9
  generateWishlistKey
10
10
  } from "@scayle/storefront-core/dist/utils/keys";
11
+ import { useNitroApp } from "nitropack/runtime/app";
12
+ import { fetchCampaignKey } from "./campaignKey.mjs";
11
13
  async function getWishlistKey(appKeys, session, $log, $shopConfig) {
12
14
  return session.data.user ? await generateWishlistKey({
13
15
  keyTemplate: appKeys.wishlistKey,
@@ -81,16 +83,18 @@ export const buildContext = async (context) => {
81
83
  const bapiConfig = $shopConfig.bapi ?? $storefront.bapi;
82
84
  const appKeys = $shopConfig.appKeys ?? $storefront.appKeys;
83
85
  const idpConfig = $shopConfig.idp ?? $storefront.idp;
86
+ const bapiClient = new StorefrontAPIClient({
87
+ host: bapiConfig.host,
88
+ shopId: $shopConfig.shopId,
89
+ auth: {
90
+ type: "token",
91
+ token: bapiConfig.token
92
+ }
93
+ });
94
+ const cached = new Cached($cache, $log, "", $storefront.cache?.enabled ?? true).execute;
84
95
  const baseContext = {
85
- cached: new Cached($cache, $log, "", $storefront.cache?.enabled ?? true).execute,
86
- bapiClient: new StorefrontAPIClient({
87
- host: bapiConfig.host,
88
- shopId: $shopConfig.shopId,
89
- auth: {
90
- type: "token",
91
- token: bapiConfig.token
92
- }
93
- }),
96
+ cached,
97
+ bapiClient,
94
98
  auth: {
95
99
  resetPasswordUrl: $shopConfig.auth?.resetPasswordUrl
96
100
  },
@@ -129,13 +133,22 @@ export const buildContext = async (context) => {
129
133
  shopId: $shopConfig.shopId,
130
134
  domain: $shopConfig.domain,
131
135
  withParams: $storefront.withParams,
132
- campaignKey: $shopConfig.storeCampaignKeyword,
136
+ storeCampaignKeyword: $shopConfig.storeCampaignKeyword,
137
+ campaignKey: await fetchCampaignKey(
138
+ bapiClient,
139
+ cached,
140
+ $shopConfig.storeCampaignKeyword,
141
+ $log
142
+ ),
133
143
  runtimeConfiguration: config,
134
144
  ip: getRequestIP(event, { xForwardedFor: true }),
135
145
  headers: createAndPurifyHeaders(getRequestHeaders(event))
136
146
  };
137
- return Object.defineProperties({}, {
147
+ const rpcContext = Object.defineProperties({}, {
138
148
  ...Object.getOwnPropertyDescriptors(baseContext),
139
149
  ...Object.getOwnPropertyDescriptors(await sessionProperties(context))
140
150
  });
151
+ const nitro = useNitroApp();
152
+ await nitro.hooks?.callHook("storefront:context:created", rpcContext);
153
+ return rpcContext;
141
154
  };
@@ -1,4 +1,5 @@
1
- import { HashAlgorithm, IDPConfig, WithParams, ShopUser, LogLevel } from '@scayle/storefront-core';
1
+ import { HookResult } from '@nuxt/schema';
2
+ import { RpcContext, HashAlgorithm, IDPConfig, WithParams, ShopUser, LogLevel } from '@scayle/storefront-core';
2
3
  import { CompressionEncodings } from '@scayle/unstorage-compression-driver';
3
4
  import { BuiltinDriverName, BuiltinDriverOptions } from 'unstorage';
4
5
 
@@ -173,5 +174,10 @@ declare module '@nuxt/schema' {
173
174
  storefront: ModulePublicRuntimeConfig;
174
175
  }
175
176
  }
177
+ declare module 'nitropack' {
178
+ interface NitroRuntimeHooks {
179
+ 'storefront:context:created': (context: RpcContext) => HookResult;
180
+ }
181
+ }
176
182
 
177
183
  export type { AppKeys as A, BapiConfig as B, CheckoutShopConfig as C, ModuleOptions as M, OauthConfig as O, PublicShopConfig as P, RedisConfig as R, StorageProvider as S, SessionConfig as a, CacheConfig as b, StorageEntity as c, StorageConfig as d, RedirectsConfig as e, AdditionalShopConfig as f, ShopConfig as g, ShopConfigIndexed as h, StorefrontConfig as i, CheckoutEvent as j, ModulePublicRuntimeConfig as k };
@@ -1,4 +1,5 @@
1
- import { HashAlgorithm, IDPConfig, WithParams, ShopUser, LogLevel } from '@scayle/storefront-core';
1
+ import { HookResult } from '@nuxt/schema';
2
+ import { RpcContext, HashAlgorithm, IDPConfig, WithParams, ShopUser, LogLevel } from '@scayle/storefront-core';
2
3
  import { CompressionEncodings } from '@scayle/unstorage-compression-driver';
3
4
  import { BuiltinDriverName, BuiltinDriverOptions } from 'unstorage';
4
5
 
@@ -173,5 +174,10 @@ declare module '@nuxt/schema' {
173
174
  storefront: ModulePublicRuntimeConfig;
174
175
  }
175
176
  }
177
+ declare module 'nitropack' {
178
+ interface NitroRuntimeHooks {
179
+ 'storefront:context:created': (context: RpcContext) => HookResult;
180
+ }
181
+ }
176
182
 
177
183
  export type { AppKeys as A, BapiConfig as B, CheckoutShopConfig as C, ModuleOptions as M, OauthConfig as O, PublicShopConfig as P, RedisConfig as R, StorageProvider as S, SessionConfig as a, CacheConfig as b, StorageEntity as c, StorageConfig as d, RedirectsConfig as e, AdditionalShopConfig as f, ShopConfig as g, ShopConfigIndexed as h, StorefrontConfig as i, CheckoutEvent as j, ModulePublicRuntimeConfig as k };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
3
  "type": "module",
4
- "version": "7.69.1",
4
+ "version": "7.70.0",
5
5
  "description": "Nuxt integration for the SCAYLE Commerce Engine and Storefront API",
6
6
  "author": "SCAYLE Commerce Engine",
7
7
  "license": "MIT",
@@ -63,7 +63,7 @@
63
63
  "@nuxt/kit": "3.11.1",
64
64
  "@opentelemetry/api": "1.8.0",
65
65
  "@scayle/h3-session": "0.4.0",
66
- "@scayle/storefront-core": "7.50.1",
66
+ "@scayle/storefront-core": "7.51.0",
67
67
  "@scayle/unstorage-compression-driver": "0.1.3",
68
68
  "@vueuse/core": "10.9.0",
69
69
  "consola": "3.2.3",
@@ -90,13 +90,14 @@
90
90
  "dprint": "0.45.1",
91
91
  "eslint": "9.2.0",
92
92
  "eslint-formatter-gitlab": "5.1.0",
93
+ "fishery": "2.2.2",
93
94
  "h3": "1.11.1",
94
95
  "node-mocks-http": "1.14.1",
95
96
  "nuxi": "3.11.1",
96
97
  "nuxt": "3.11.1",
97
98
  "publint": "0.2.7",
98
99
  "vitest": "1.6.0",
99
- "vue-tsc": "2.0.17"
100
+ "vue-tsc": "2.0.19"
100
101
  },
101
102
  "peerDependencies": {
102
103
  "h3": "^1.10.0",