@scayle/storefront-nuxt 7.72.4 → 7.73.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,24 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 7.73.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Renamed ModuleOptions to ModuleBaseOptions to differentiate it from other ModuleOptions used in different modules.
8
+
9
+ ### Patch Changes
10
+
11
+ - Fix construction of API base path: When setting up a `baseURL` in combination with path based shop selection, the `baseURL` is now the first path segment of the API base path.
12
+ - Updated dependencies
13
+ - @scayle/storefront-core@7.54.0
14
+
15
+ ## 7.72.5
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies
20
+ - @scayle/storefront-core@7.53.0
21
+
3
22
  ## 7.72.4
4
23
 
5
24
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
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.20d8641a.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.d9a4c377.mjs';
2
2
  export { rpcCall } from './rpc.mjs';
3
3
  export * from '@scayle/storefront-core';
4
4
  export { LogLevel } from '@scayle/storefront-core';
@@ -6,6 +6,7 @@ export { unwrap } from '@scayle/storefront-core/dist/utils/response';
6
6
  import '@nuxt/schema';
7
7
  import '@scayle/unstorage-compression-driver';
8
8
  import 'unstorage';
9
+ import 'zod';
9
10
  import 'nuxt/app';
10
11
 
11
12
  interface RpcMethodsStorefront {
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
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.20d8641a.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.d9a4c377.js';
2
2
  export { rpcCall } from './rpc.js';
3
3
  export * from '@scayle/storefront-core';
4
4
  export { LogLevel } from '@scayle/storefront-core';
@@ -6,6 +6,7 @@ export { unwrap } from '@scayle/storefront-core/dist/utils/response';
6
6
  import '@nuxt/schema';
7
7
  import '@scayle/unstorage-compression-driver';
8
8
  import 'unstorage';
9
+ import 'zod';
9
10
  import 'nuxt/app';
10
11
 
11
12
  interface RpcMethodsStorefront {
package/dist/module.d.mts CHANGED
@@ -1,10 +1,11 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { M as ModuleOptions } from './shared/storefront-nuxt.20d8641a.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.20d8641a.mjs';
2
+ import { M as ModuleBaseOptions } from './shared/storefront-nuxt.d9a4c377.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.d9a4c377.mjs';
4
4
  export { LogLevel } from '@scayle/storefront-core';
5
5
  import '@scayle/unstorage-compression-driver';
6
6
  import 'unstorage';
7
+ import 'zod';
7
8
 
8
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
9
+ declare const _default: _nuxt_schema.NuxtModule<ModuleBaseOptions>;
9
10
 
10
- export { ModuleOptions, _default as default };
11
+ export { ModuleBaseOptions, _default as default };
package/dist/module.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { M as ModuleOptions } from './shared/storefront-nuxt.20d8641a.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.20d8641a.js';
2
+ import { M as ModuleBaseOptions } from './shared/storefront-nuxt.d9a4c377.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.d9a4c377.js';
4
4
  export { LogLevel } from '@scayle/storefront-core';
5
5
  import '@scayle/unstorage-compression-driver';
6
6
  import 'unstorage';
7
+ import 'zod';
7
8
 
8
- declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
9
+ declare const _default: _nuxt_schema.NuxtModule<ModuleBaseOptions>;
9
10
 
10
- export { ModuleOptions, _default as default };
11
+ export { ModuleBaseOptions, _default as default };
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
- "version": "7.72.3",
3
+ "version": "7.72.5",
4
4
  "configKey": "storefront",
5
5
  "compatibility": {
6
6
  "nuxt": "^3.9.0"
package/dist/module.mjs CHANGED
@@ -6,6 +6,7 @@ import { genImport, genSafeVariableName } from 'knitwork';
6
6
  import { builtinDrivers } from 'unstorage';
7
7
  import { createConsola } from 'consola';
8
8
  import 'h3';
9
+ import { joinURL } from 'ufo';
9
10
 
10
11
  const convertShopsToList = (stores) => {
11
12
  if (Array.isArray(stores)) {
@@ -13,17 +14,19 @@ const convertShopsToList = (stores) => {
13
14
  }
14
15
  return Object.values(stores);
15
16
  };
16
- function getApiBasePath(storefrontConfig, shop) {
17
+ function getApiBasePath(storefrontConfig, shop, baseUrl) {
17
18
  const apiPath = shop.apiBasePath || storefrontConfig.apiBasePath || "/api";
18
19
  if (storefrontConfig.shopSelector === "path") {
19
- return `/${shop.path}${apiPath}`;
20
+ const pathElements = [shop.path, apiPath].filter(Boolean);
21
+ return joinURL(baseUrl, ...pathElements);
20
22
  } else if (storefrontConfig.shopSelector === "path_or_default") {
21
23
  if (shop.isDefault) {
22
- return apiPath;
24
+ return joinURL(baseUrl, apiPath);
23
25
  }
24
- return `/${shop.path}${apiPath}`;
26
+ const pathElements = [shop.path, apiPath].filter(Boolean);
27
+ return joinURL(baseUrl, ...pathElements);
25
28
  }
26
- return apiPath;
29
+ return joinURL(baseUrl, apiPath);
27
30
  }
28
31
 
29
32
  function getUsedDrivers(options) {
@@ -61,7 +64,7 @@ export default {
61
64
  }`;
62
65
  }
63
66
  const PACKAGE_NAME = "@scayle/storefront-nuxt";
64
- const PACKAGE_VERSION = "7.72.3";
67
+ const PACKAGE_VERSION = "7.72.5";
65
68
  const logger = createConsola({
66
69
  fancy: true,
67
70
  formatOptions: {
@@ -195,7 +198,13 @@ Missing RPC Overrides: ${Array.from(overridenRPCMethodNames).map((name) => `'${n
195
198
  const shopSelector = nuxt.options.runtimeConfig.storefront.shopSelector;
196
199
  if (shopSelector === "path" || shopSelector === "path_or_default") {
197
200
  shops.forEach((shop) => {
198
- const base = getApiBasePath(nuxt.options.runtimeConfig.storefront, shop);
201
+ const base = getApiBasePath(
202
+ nuxt.options.runtimeConfig.storefront,
203
+ shop,
204
+ // Nuxt/Nitro automatically adds `NUXT_APP_BASE_URL` to the path when registering the handler, so we don't need to pass it here.
205
+ // https://github.com/unjs/nitro/blob/011280178d59fa863b90d63f89f29beb47b520b7/src/runtime/internal/app.ts#L149C13-L149C27
206
+ "/"
207
+ );
199
208
  addCacheServerHandlers(base);
200
209
  addRPCServerHandlers(base);
201
210
  });
package/dist/rpc.d.mts CHANGED
@@ -1,9 +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.20d8641a.mjs';
3
+ import { P as PublicShopConfig } from './shared/storefront-nuxt.d9a4c377.mjs';
4
4
  import '@nuxt/schema';
5
5
  import '@scayle/unstorage-compression-driver';
6
6
  import 'unstorage';
7
+ import 'zod';
7
8
 
8
9
  /**
9
10
  * rpcCall can be used to invoke an RPC method either on the client or server
package/dist/rpc.d.ts CHANGED
@@ -1,9 +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.20d8641a.js';
3
+ import { P as PublicShopConfig } from './shared/storefront-nuxt.d9a4c377.js';
4
4
  import '@nuxt/schema';
5
5
  import '@scayle/unstorage-compression-driver';
6
6
  import 'unstorage';
7
+ import 'zod';
7
8
 
8
9
  /**
9
10
  * rpcCall can be used to invoke an RPC method either on the client or server
@@ -1,2 +1,3 @@
1
+ export declare const sensitiveKeys: string[];
1
2
  declare const _default: any;
2
3
  export default _default;
@@ -1,16 +1,51 @@
1
1
  import { defineNitroPlugin, useRuntimeConfig } from "#imports";
2
- import { runtimeConfigSchema } from "../../utils/zodSchema.mjs";
2
+ import { RuntimeConfigSchema } from "../../utils/zodSchema.mjs";
3
+ import { purifySensitiveValue } from "@scayle/storefront-core";
4
+ export const sensitiveKeys = [
5
+ "token",
6
+ "password",
7
+ "clientSecret",
8
+ "apiToken",
9
+ "secret"
10
+ ];
11
+ const getValue = (object, pathArray) => {
12
+ return String(pathArray.reduce((acc, key) => {
13
+ return acc ? acc[key] : void 0;
14
+ }, object));
15
+ };
16
+ const formatZodError = (issues, runtimeConfig) => {
17
+ const errorMessages = [];
18
+ issues.forEach((issue) => {
19
+ if (issue.code === "invalid_union") {
20
+ return issue.unionErrors.forEach((unionError) => {
21
+ errorMessages.push(...formatZodError(unionError.errors, runtimeConfig));
22
+ });
23
+ }
24
+ const key = issue.path[issue.path.length - 1];
25
+ let value;
26
+ if (sensitiveKeys.includes(key)) {
27
+ value = purifySensitiveValue(getValue(runtimeConfig, issue.path), true);
28
+ } else if (issue.code !== "too_small") {
29
+ value = getValue(runtimeConfig, issue.path);
30
+ }
31
+ const errorMessage = {
32
+ code: issue.code,
33
+ path: issue.path.join("."),
34
+ message: issue.message
35
+ };
36
+ if (value) {
37
+ errorMessage.value = value;
38
+ }
39
+ errorMessages.push(errorMessage);
40
+ });
41
+ return errorMessages;
42
+ };
3
43
  export default defineNitroPlugin(() => {
4
44
  const runtimeConfig = useRuntimeConfig();
5
- const { success, error } = runtimeConfigSchema.safeParse(runtimeConfig);
45
+ const { success, error } = RuntimeConfigSchema.safeParse(runtimeConfig);
6
46
  if (!success) {
7
- error.errors.forEach((e) => {
8
- console.error("[storefront-nuxt] configValidation:", {
9
- code: e.code,
10
- path: e.path.join("."),
11
- message: e.message
12
- });
13
- });
47
+ const errorMessages = formatZodError(error.errors, runtimeConfig);
48
+ console.error("[storefront-nuxt] configValidation:", errorMessages);
14
49
  throw Error("[storefront-nuxt] configValidation: Runtime config invalid");
15
50
  }
16
51
  console.log("[storefront-nuxt] configValidation: Runtime config valid");
@@ -135,14 +135,15 @@ export default defineEventHandler(async (event) => {
135
135
  if (path === "/favicon.ico") {
136
136
  return;
137
137
  }
138
- const config = useRuntimeConfig();
138
+ const config = useRuntimeConfig(event);
139
139
  const $storefrontConfig = config.storefront;
140
140
  if (path === `${$storefrontConfig.apiBasePath ?? "/api"}/up`) {
141
141
  return;
142
142
  }
143
143
  const $shopConfig = getCurrentShopConfigForRequest(
144
144
  event,
145
- $storefrontConfig
145
+ $storefrontConfig,
146
+ config
146
147
  );
147
148
  if (!$shopConfig) {
148
149
  event.context.$log.debug(
@@ -151,7 +152,11 @@ export default defineEventHandler(async (event) => {
151
152
  );
152
153
  return;
153
154
  }
154
- const apiBasePath = getApiBasePath($storefrontConfig, $shopConfig);
155
+ const apiBasePath = getApiBasePath(
156
+ $storefrontConfig,
157
+ $shopConfig,
158
+ config.app.baseURL
159
+ );
155
160
  if (!event.context.$rpcContext) {
156
161
  event.context.$log.debug("Bootstrapping request: " + path);
157
162
  await bootstrap(
@@ -1,13 +1,14 @@
1
1
  import { type H3Event } from 'h3';
2
- import type { ModuleOptions, PublicShopConfig, ShopConfig, ShopConfigIndexed } from '../../../module';
2
+ import type { ModuleBaseOptions, PublicShopConfig, ShopConfig, ShopConfigIndexed } from '../../../module';
3
+ import type { NitroRuntimeConfig } from 'nitropack';
3
4
  type BootstrapPath = {
4
5
  path: string;
5
6
  originalPath: string;
6
7
  };
7
8
  export declare function getBootstrapPath(event: H3Event): BootstrapPath;
8
9
  export declare const convertShopsToList: (stores: ShopConfig[] | ShopConfigIndexed) => ShopConfig[];
9
- export declare function getApiBasePath(storefrontConfig: ModuleOptions, shop: ShopConfig): string;
10
- export declare function getCurrentShopConfigForRequest(event: H3Event, config: Pick<ModuleOptions, 'stores' | 'shopSelector'>): ShopConfig | undefined;
10
+ export declare function getApiBasePath(storefrontConfig: ModuleBaseOptions, shop: ShopConfig, baseUrl: string): string;
11
+ export declare function getCurrentShopConfigForRequest(event: H3Event, config: Pick<ModuleBaseOptions, 'stores' | 'shopSelector'>, runtimeConfig: NitroRuntimeConfig): ShopConfig | undefined;
11
12
  export declare function getPublicShopData(data: ShopConfig, currentShopId: number, apiBasePath: string, publicShopData?: (keyof ShopConfig)[]): PublicShopConfig & {
12
13
  isActive: boolean;
13
14
  };
@@ -3,6 +3,7 @@ import {
3
3
  getRequestHost,
4
4
  getRequestURL
5
5
  } from "h3";
6
+ import { joinURL } from "ufo";
6
7
  export function getBootstrapPath(event) {
7
8
  const url = getRequestURL(event);
8
9
  const path = url.pathname === "/__nuxt_error" ? url.searchParams.get("url") ?? url.pathname : url.pathname;
@@ -12,15 +13,16 @@ const getShopByDomain = (event, shops) => {
12
13
  const host = getRequestHost(event, { xForwardedHost: true });
13
14
  return shops.find((s) => s.domain === host);
14
15
  };
15
- const getShopByPath = (event, shops) => {
16
+ const getShopByPath = (event, shops, appBasePath) => {
16
17
  const { path } = getBootstrapPath(event);
17
- const prefix = path.split("/")[1];
18
+ const localeIndex = appBasePath !== "/" ? 2 : 1;
19
+ const prefix = path.split("/")?.[localeIndex];
18
20
  return shops.find((shop) => prefix === shop.path);
19
21
  };
20
- const getShopByPathOrDefault = (event, shops) => {
22
+ const getShopByPathOrDefault = (event, shops, appBasePath) => {
21
23
  const defaultShop = shops.find((shop) => shop.isDefault);
22
24
  const otherShops = shops.filter((shop) => !shop.isDefault);
23
- return getShopByPath(event, otherShops) ?? defaultShop;
25
+ return getShopByPath(event, otherShops, appBasePath) ?? defaultShop;
24
26
  };
25
27
  export const convertShopsToList = (stores) => {
26
28
  if (Array.isArray(stores)) {
@@ -28,19 +30,21 @@ export const convertShopsToList = (stores) => {
28
30
  }
29
31
  return Object.values(stores);
30
32
  };
31
- export function getApiBasePath(storefrontConfig, shop) {
33
+ export function getApiBasePath(storefrontConfig, shop, baseUrl) {
32
34
  const apiPath = shop.apiBasePath || storefrontConfig.apiBasePath || "/api";
33
35
  if (storefrontConfig.shopSelector === "path") {
34
- return `/${shop.path}${apiPath}`;
36
+ const pathElements = [shop.path, apiPath].filter(Boolean);
37
+ return joinURL(baseUrl, ...pathElements);
35
38
  } else if (storefrontConfig.shopSelector === "path_or_default") {
36
39
  if (shop.isDefault) {
37
- return apiPath;
40
+ return joinURL(baseUrl, apiPath);
38
41
  }
39
- return `/${shop.path}${apiPath}`;
42
+ const pathElements = [shop.path, apiPath].filter(Boolean);
43
+ return joinURL(baseUrl, ...pathElements);
40
44
  }
41
- return apiPath;
45
+ return joinURL(baseUrl, apiPath);
42
46
  }
43
- export function getCurrentShopConfigForRequest(event, config) {
47
+ export function getCurrentShopConfigForRequest(event, config, runtimeConfig) {
44
48
  let $shopConfig;
45
49
  const { shopSelector, stores } = config;
46
50
  const shopsList = convertShopsToList(stores);
@@ -51,9 +55,13 @@ export function getCurrentShopConfigForRequest(event, config) {
51
55
  } else if (shopSelector === "domain") {
52
56
  $shopConfig = getShopByDomain(event, shopsList);
53
57
  } else if (shopSelector === "path") {
54
- $shopConfig = getShopByPath(event, shopsList);
58
+ $shopConfig = getShopByPath(event, shopsList, runtimeConfig.app.baseURL);
55
59
  } else if (shopSelector === "path_or_default") {
56
- $shopConfig = getShopByPathOrDefault(event, shopsList);
60
+ $shopConfig = getShopByPathOrDefault(
61
+ event,
62
+ shopsList,
63
+ runtimeConfig.app.baseURL
64
+ );
57
65
  }
58
66
  return $shopConfig;
59
67
  }