@scayle/storefront-nuxt 7.69.1 → 7.71.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,46 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 7.71.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add new shopSelector mode `path_or_default`
8
+
9
+ The `path_or_default` mode is similar to `path`, but loading the root will open the default shop instead of redirecting to the first shop. So you can have a shop at `example.com/` and `example.com/de` instead of `example.com/en` and `example.com/de`. To set a default shop, add `isDefault: true` to the shop's configuration in the `nuxt.config`. When using `nuxt-i18n` the `strategy` option should be set to `prefix_except_default`. (This is the default value.)
10
+
11
+ ## 7.70.0
12
+
13
+ ### Minor Changes
14
+
15
+ - `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.
16
+
17
+ This behavior, is now similar to the nuxt 2 implementation.
18
+
19
+ - It is now also possible to extend the RPCContext using the `storefront:context:created` nitro runtime hook.
20
+
21
+ ```ts
22
+ import { defineNitroPlugin } from "nitropack/runtime/plugin";
23
+ // Augment RpxContext type
24
+ declare module "@scayle/storefront-nuxt" {
25
+ interface AdditionalRpcContext {
26
+ myNewProp: string;
27
+ }
28
+ }
29
+
30
+ // Set new value on rpcContext
31
+ export default defineNitroPlugin((nitroApp) => {
32
+ nitroApp.hooks.hook("storefront:context:created", (rpcContext) => {
33
+ rpcContext.myNewProp = "My campaign key";
34
+ });
35
+ });
36
+ ```
37
+
38
+ ### Patch Changes
39
+
40
+ - Add campaignKey dependency to nitro
41
+ - Updated dependencies
42
+ - @scayle/storefront-core@7.51.0
43
+
3
44
  ## 7.69.1
4
45
 
5
46
  ### 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.b9f5584c.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.b9f5584c.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.b9f5584c.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.b9f5584c.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.b9f5584c.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.b9f5584c.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.70.0",
4
4
  "configKey": "storefront",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.9.0"
package/dist/module.mjs CHANGED
@@ -4,6 +4,26 @@ import { rpcMethods } from '@scayle/storefront-core';
4
4
  import { defu } from 'defu';
5
5
  import { genImport, genSafeVariableName } from 'knitwork';
6
6
  import { builtinDrivers } from 'unstorage';
7
+ import 'h3';
8
+
9
+ const convertShopsToList = (stores) => {
10
+ if (Array.isArray(stores)) {
11
+ return stores;
12
+ }
13
+ return Object.values(stores);
14
+ };
15
+ function getApiBasePath(storefrontConfig, shop) {
16
+ const apiPath = shop.apiBasePath || storefrontConfig.apiBasePath || "/api";
17
+ if (storefrontConfig.shopSelector === "path") {
18
+ return `/${shop.path}${apiPath}`;
19
+ } else if (storefrontConfig.shopSelector === "path_or_default") {
20
+ if (shop.isDefault) {
21
+ return apiPath;
22
+ }
23
+ return `/${shop.path}${apiPath}`;
24
+ }
25
+ return apiPath;
26
+ }
7
27
 
8
28
  function getUsedDrivers(options) {
9
29
  const drivers = /* @__PURE__ */ new Set();
@@ -40,7 +60,7 @@ export default {
40
60
  }`;
41
61
  }
42
62
  const PACKAGE_NAME = "@scayle/storefront-nuxt";
43
- const PACKAGE_VERSION = "7.69.0";
63
+ const PACKAGE_VERSION = "7.70.0";
44
64
  const module = defineNuxtModule({
45
65
  meta: {
46
66
  name: PACKAGE_NAME,
@@ -138,10 +158,13 @@ const module = defineNuxtModule({
138
158
  method: "post"
139
159
  });
140
160
  }
141
- if (nuxt.options.runtimeConfig.storefront.shopSelector === "path") {
142
- const stores = Array.isArray(nuxt.options.runtimeConfig.storefront.stores) ? nuxt.options.runtimeConfig.storefront.stores : Object.values(nuxt.options.runtimeConfig.storefront.stores);
143
- stores.forEach((iteratedStore) => {
144
- const base = `/${iteratedStore.path}${apiBasePath}`;
161
+ const shops = convertShopsToList(
162
+ nuxt.options.runtimeConfig.storefront.stores
163
+ );
164
+ const shopSelector = nuxt.options.runtimeConfig.storefront.shopSelector;
165
+ if (shopSelector === "path" || shopSelector === "path_or_default") {
166
+ shops.forEach((shop) => {
167
+ const base = getApiBasePath(nuxt.options.runtimeConfig.storefront, shop);
145
168
  addCacheServerHandlers(base);
146
169
  addRPCServerHandlers(base);
147
170
  });
@@ -153,7 +176,7 @@ const module = defineNuxtModule({
153
176
  route: `${apiBasePath}/up`,
154
177
  handler: resolve("./runtime/api/up")
155
178
  });
156
- const template = addTypeTemplate({
179
+ addTypeTemplate({
157
180
  filename: "types/storefront-bootstrap.d.ts",
158
181
  getContents: () => `// Auto-generated
159
182
  import type { RuntimeConfig } from '@nuxt/schema'
@@ -173,9 +196,6 @@ const module = defineNuxtModule({
173
196
  }
174
197
  export {}`
175
198
  });
176
- nuxt.hook("prepare:types", ({ references }) => {
177
- references.push({ path: template.dst });
178
- });
179
199
  addServerPlugin(resolve("./runtime/nitro/plugins/nitroLogger"));
180
200
  addServerPlugin(
181
201
  resolve("./runtime/nitro/plugins/nitroRuntimeStorageConfig")
@@ -187,6 +207,7 @@ const module = defineNuxtModule({
187
207
  const runtimePaths = [
188
208
  "handler",
189
209
  "error/handler",
210
+ "campaignKey",
190
211
  "context",
191
212
  "createLog",
192
213
  "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.b9f5584c.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.b9f5584c.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
  };
@@ -8,10 +8,11 @@ import {
8
8
  import { buildContext } from "../../context.mjs";
9
9
  import { useCacheStorage, useSessionStorage } from "../utils/cacheStorage.mjs";
10
10
  import {
11
- convertStoresToList,
11
+ convertShopsToList,
12
12
  getCurrentShopConfigForRequest,
13
13
  getPublicShopData,
14
- getBootstrapPath
14
+ getBootstrapPath,
15
+ getApiBasePath
15
16
  } from "./bootstrap.utils.mjs";
16
17
  import { useRedirects } from "./redirects.mjs";
17
18
  import { useRuntimeConfig } from "#imports";
@@ -100,7 +101,7 @@ async function bootstrap(event, $shopConfig, $storefrontConfig, apiBasePath, con
100
101
  apiBasePath,
101
102
  $storefrontConfig.publicShopData
102
103
  );
103
- event.context.$availableShops = convertStoresToList($storefrontConfig.stores).filter((store) => store.isEnabled !== false).map(
104
+ event.context.$availableShops = convertShopsToList($storefrontConfig.stores).filter((store) => store.isEnabled !== false).map(
104
105
  (config2) => getPublicShopData(
105
106
  config2,
106
107
  $shopConfig.shopId,
@@ -150,7 +151,7 @@ export default defineEventHandler(async (event) => {
150
151
  );
151
152
  return;
152
153
  }
153
- const apiBasePath = ($storefrontConfig.shopSelector === "path" && $shopConfig.path ? `/${$shopConfig.path}` : "") + ($shopConfig.apiBasePath || $storefrontConfig.apiBasePath || "/api");
154
+ const apiBasePath = getApiBasePath($storefrontConfig, $shopConfig);
154
155
  if (!event.context.$rpcContext) {
155
156
  event.context.$log.debug("Bootstrapping request: " + path);
156
157
  await bootstrap(
@@ -5,7 +5,8 @@ type BootstrapPath = {
5
5
  originalPath: string;
6
6
  };
7
7
  export declare function getBootstrapPath(event: H3Event): BootstrapPath;
8
- export declare const convertStoresToList: (stores: ShopConfig[] | ShopConfigIndexed) => ShopConfig[];
8
+ export declare const convertShopsToList: (stores: ShopConfig[] | ShopConfigIndexed) => ShopConfig[];
9
+ export declare function getApiBasePath(storefrontConfig: ModuleOptions, shop: ShopConfig): string;
9
10
  export declare function getCurrentShopConfigForRequest(event: H3Event, config: Pick<ModuleOptions, 'stores' | 'shopSelector'>): ShopConfig | undefined;
10
11
  export declare function getPublicShopData(data: ShopConfig, currentShopId: number, apiBasePath: string, publicShopData?: (keyof ShopConfig)[]): PublicShopConfig & {
11
12
  isActive: boolean;
@@ -3,39 +3,57 @@ import {
3
3
  getRequestHost,
4
4
  getRequestURL
5
5
  } from "h3";
6
- import { isArray, listify } from "radash";
7
6
  export function getBootstrapPath(event) {
8
7
  const url = getRequestURL(event);
9
8
  const path = url.pathname === "/__nuxt_error" ? url.searchParams.get("url") ?? url.pathname : url.pathname;
10
9
  return { path, originalPath: url.pathname };
11
10
  }
12
- const getStoreByDomain = (event, stores) => {
11
+ const getShopByDomain = (event, shops) => {
13
12
  const host = getRequestHost(event, { xForwardedHost: true });
14
- return stores.find((s) => s.domain === host);
13
+ return shops.find((s) => s.domain === host);
15
14
  };
16
- const getStoreByPath = (event, stores) => {
15
+ const getShopByPath = (event, shops) => {
17
16
  const { path } = getBootstrapPath(event);
18
17
  const prefix = path.split("/")[1];
19
- return stores.find((shop) => prefix === shop.path);
18
+ return shops.find((shop) => prefix === shop.path);
20
19
  };
21
- export const convertStoresToList = (stores) => {
22
- if (isArray(stores)) {
20
+ const getShopByPathOrDefault = (event, shops) => {
21
+ const defaultShop = shops.find((shop) => shop.isDefault);
22
+ const otherShops = shops.filter((shop) => !shop.isDefault);
23
+ return getShopByPath(event, otherShops) ?? defaultShop;
24
+ };
25
+ export const convertShopsToList = (stores) => {
26
+ if (Array.isArray(stores)) {
23
27
  return stores;
24
28
  }
25
- return listify(stores, (_key, value) => ({ ...value }));
29
+ return Object.values(stores);
26
30
  };
31
+ export function getApiBasePath(storefrontConfig, shop) {
32
+ const apiPath = shop.apiBasePath || storefrontConfig.apiBasePath || "/api";
33
+ if (storefrontConfig.shopSelector === "path") {
34
+ return `/${shop.path}${apiPath}`;
35
+ } else if (storefrontConfig.shopSelector === "path_or_default") {
36
+ if (shop.isDefault) {
37
+ return apiPath;
38
+ }
39
+ return `/${shop.path}${apiPath}`;
40
+ }
41
+ return apiPath;
42
+ }
27
43
  export function getCurrentShopConfigForRequest(event, config) {
28
44
  let $shopConfig;
29
45
  const { shopSelector, stores } = config;
30
- const storesList = convertStoresToList(stores);
46
+ const shopsList = convertShopsToList(stores);
31
47
  const headers = getRequestHeaders(event);
32
48
  const shopId = headers["x-shop-id"];
33
49
  if (shopId) {
34
- $shopConfig = storesList.find((s) => s.shopId === Number(shopId));
50
+ $shopConfig = shopsList.find((s) => s.shopId === Number(shopId));
35
51
  } else if (shopSelector === "domain") {
36
- $shopConfig = getStoreByDomain(event, storesList);
52
+ $shopConfig = getShopByDomain(event, shopsList);
37
53
  } else if (shopSelector === "path") {
38
- $shopConfig = getStoreByPath(event, storesList);
54
+ $shopConfig = getShopByPath(event, shopsList);
55
+ } else if (shopSelector === "path_or_default") {
56
+ $shopConfig = getShopByPathOrDefault(event, shopsList);
39
57
  }
40
58
  return $shopConfig;
41
59
  }
@@ -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
 
@@ -110,6 +111,7 @@ interface ShopConfig extends AdditionalShopConfig {
110
111
  currencyFractionDigits?: number;
111
112
  storeCampaignKeyword?: string;
112
113
  isEnabled?: boolean;
114
+ isDefault?: boolean;
113
115
  checkout: CheckoutShopConfig;
114
116
  sessionConfig?: SessionConfig;
115
117
  auth: {
@@ -143,7 +145,7 @@ interface StorefrontConfig {
143
145
  idp?: IDPConfig;
144
146
  }
145
147
  type ModuleOptions = StorefrontConfig & {
146
- shopSelector: 'domain' | 'path';
148
+ shopSelector: 'domain' | 'path' | 'path_or_default';
147
149
  stores: ShopConfigIndexed;
148
150
  rpcDir?: string;
149
151
  rpcMethodNames?: string[];
@@ -173,5 +175,10 @@ declare module '@nuxt/schema' {
173
175
  storefront: ModulePublicRuntimeConfig;
174
176
  }
175
177
  }
178
+ declare module 'nitropack' {
179
+ interface NitroRuntimeHooks {
180
+ 'storefront:context:created': (context: RpcContext) => HookResult;
181
+ }
182
+ }
176
183
 
177
184
  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
 
@@ -110,6 +111,7 @@ interface ShopConfig extends AdditionalShopConfig {
110
111
  currencyFractionDigits?: number;
111
112
  storeCampaignKeyword?: string;
112
113
  isEnabled?: boolean;
114
+ isDefault?: boolean;
113
115
  checkout: CheckoutShopConfig;
114
116
  sessionConfig?: SessionConfig;
115
117
  auth: {
@@ -143,7 +145,7 @@ interface StorefrontConfig {
143
145
  idp?: IDPConfig;
144
146
  }
145
147
  type ModuleOptions = StorefrontConfig & {
146
- shopSelector: 'domain' | 'path';
148
+ shopSelector: 'domain' | 'path' | 'path_or_default';
147
149
  stores: ShopConfigIndexed;
148
150
  rpcDir?: string;
149
151
  rpcMethodNames?: string[];
@@ -173,5 +175,10 @@ declare module '@nuxt/schema' {
173
175
  storefront: ModulePublicRuntimeConfig;
174
176
  }
175
177
  }
178
+ declare module 'nitropack' {
179
+ interface NitroRuntimeHooks {
180
+ 'storefront:context:created': (context: RpcContext) => HookResult;
181
+ }
182
+ }
176
183
 
177
184
  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.71.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",