@scayle/storefront-nuxt 7.37.2 → 7.38.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,11 @@
1
1
  # @scayle/storefront-nuxt
2
2
 
3
+ ## 7.38.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Ensure the session is not shared between different country shops
8
+
3
9
  ## 7.37.2
4
10
 
5
11
  ### Patch Changes
package/dist/module.json CHANGED
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.7.0"
6
6
  },
7
- "version": "7.37.1"
7
+ "version": "7.37.2"
8
8
  }
package/dist/module.mjs CHANGED
@@ -82,16 +82,42 @@ const module = defineNuxtModule({
82
82
  handler: resolve("./runtime/server/middleware/bootstrap")
83
83
  });
84
84
  const apiBasePath = nuxt.options.runtimeConfig.storefront.apiBasePath || "/api";
85
- addServerHandler({
86
- route: `${apiBasePath}/purge/all`,
87
- handler: resolve("./runtime/api/purgeAll"),
88
- method: "post"
89
- });
90
- addServerHandler({
91
- route: `${apiBasePath}/purge/tags`,
92
- handler: resolve("./runtime/api/purgeTags"),
93
- method: "post"
94
- });
85
+ const rpcMethodNames = /* @__PURE__ */ new Set([
86
+ ...Object.keys(rpcMethods),
87
+ ...options.rpcMethodNames ?? []
88
+ ]);
89
+ function addRPCServerHandlers(base) {
90
+ rpcMethodNames.forEach((methodName) => {
91
+ addServerHandler({
92
+ route: `${base}/rpc/${methodName}`,
93
+ handler: resolve("./runtime/api/rpcHandler"),
94
+ method: "post"
95
+ });
96
+ });
97
+ }
98
+ function addCacheServerHandlers(base) {
99
+ addServerHandler({
100
+ route: `${base}/purge/all`,
101
+ handler: resolve("./runtime/api/purgeAll"),
102
+ method: "post"
103
+ });
104
+ addServerHandler({
105
+ route: `${base}/purge/tags`,
106
+ handler: resolve("./runtime/api/purgeTags"),
107
+ method: "post"
108
+ });
109
+ }
110
+ if (nuxt.options.runtimeConfig.storefront.shopSelector === "path") {
111
+ const stores = Array.isArray(nuxt.options.runtimeConfig.storefront.stores) ? nuxt.options.runtimeConfig.storefront.stores : Object.values(nuxt.options.runtimeConfig.storefront.stores);
112
+ stores.forEach((s) => {
113
+ const base = `/${s.path}${apiBasePath}`;
114
+ addCacheServerHandlers(base);
115
+ addRPCServerHandlers(base);
116
+ });
117
+ } else {
118
+ addCacheServerHandlers(apiBasePath);
119
+ addRPCServerHandlers(apiBasePath);
120
+ }
95
121
  addServerHandler({
96
122
  route: `${apiBasePath}/up`,
97
123
  handler: resolve("./runtime/api/up"),
@@ -119,17 +145,6 @@ const module = defineNuxtModule({
119
145
  nuxt.hook("prepare:types", ({ references }) => {
120
146
  references.push({ path: template.dst });
121
147
  });
122
- const rpcMethodNames = /* @__PURE__ */ new Set([
123
- ...Object.keys(rpcMethods),
124
- ...options.rpcMethodNames ?? []
125
- ]);
126
- rpcMethodNames.forEach((methodName) => {
127
- addServerHandler({
128
- route: `${apiBasePath}/rpc/${methodName}`,
129
- handler: resolve("./runtime/api/rpcHandler"),
130
- method: "post"
131
- });
132
- });
133
148
  nuxt.hooks.hook("nitro:config", (nitroConfig) => {
134
149
  nitroConfig.externals = nitroConfig.externals || {};
135
150
  nitroConfig.externals.inline = nitroConfig.externals.inline || [];
@@ -5,7 +5,7 @@ export default defineEventHandler(async (event) => {
5
5
  const pathComponents = event.path.split("?")[0].split("/");
6
6
  const method = pathComponents[pathComponents.length - 1];
7
7
  const body = await readBody(event);
8
- event.context.$rpcContext.log.space("sfc").debug(`RPC Handler: ${method}`);
8
+ event.context.$rpcContext.log.space("sfc").debug(`RPC Handler: ${method}, Payload: ${JSON.stringify(body?.payload)}`);
9
9
  try {
10
10
  return await handler(method, body?.payload, event.context.$rpcContext);
11
11
  } catch (e) {
@@ -1,8 +1,18 @@
1
- import { useNuxtApp, useState } from "nuxt/app";
1
+ import {
2
+ useNuxtApp,
3
+ useState
4
+ } from "nuxt/app";
2
5
  import { useCoreLog } from "../useCoreLog.mjs";
3
6
  import { handleError } from "../../utils/error.mjs";
4
7
  import { useCurrentShop } from "./useCurrentShop.mjs";
5
8
  import { toValue } from "#imports";
9
+ function getFetch(nuxtApp, log) {
10
+ const fetch = nuxtApp.ssrContext?.event.$fetch ?? $fetch;
11
+ if (nuxtApp.ssrContext?.event && !nuxtApp.ssrContext?.event.$fetch) {
12
+ log.error("event.$fetch was not found!");
13
+ }
14
+ return fetch;
15
+ }
6
16
  export const useRpc = async (method, key, params, options = { autoFetch: true, lazy: false }) => {
7
17
  const currentShop = useCurrentShop();
8
18
  const log = useCoreLog("rpc");
@@ -20,7 +30,7 @@ export const useRpc = async (method, key, params, options = { autoFetch: true, l
20
30
  status.value = "pending";
21
31
  fetching.value = true;
22
32
  const apiBasePath = currentShop.value?.apiBasePath ?? "/api";
23
- const fetch2 = useNuxtApp().ssrContext?.event.$fetch ?? $fetch;
33
+ const fetch2 = getFetch(useNuxtApp(), log);
24
34
  data.value = await fetch2(`/rpc/${method}`, {
25
35
  // @ts-ignore
26
36
  method: "POST",
@@ -124,7 +124,8 @@ async function bootstrap(event, log, url, $shopConfig, $storefrontConfig, apiBas
124
124
  maxAge: sessionConfig?.maxAge,
125
125
  // secure: sessionConfig.isHttps, TODO
126
126
  sameSite: sessionConfig.sameSite,
127
- domain: sessionConfig?.domain
127
+ domain: sessionConfig?.domain,
128
+ path: $storefrontConfig.shopSelector === "path" && $shopConfig.path ? `/${$shopConfig.path}` : void 0
128
129
  },
129
130
  name: sessionConfig?.cookieName ?? "$session",
130
131
  secret: sessionConfig?.secret ?? "current-secret"
@@ -164,7 +165,7 @@ export default defineEventHandler(async (event) => {
164
165
  const config = useRuntimeConfig();
165
166
  const $storefrontConfig = config.storefront;
166
167
  const $shopConfig = getShopConfig(event, config);
167
- const apiBasePath = $shopConfig.apiBasePath || $storefrontConfig.apiBasePath || "/api";
168
+ const apiBasePath = ($storefrontConfig.shopSelector === "path" && $shopConfig.path ? `/${$shopConfig.path}` : "") + ($shopConfig.apiBasePath || $storefrontConfig.apiBasePath || "/api");
168
169
  if (url.pathname === `${apiBasePath}/up`) {
169
170
  return;
170
171
  }
package/dist/types.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
- import { ModuleOptions } from './module'
2
+ import type { ModuleOptions } from './module'
3
+
3
4
 
4
5
  declare module '@nuxt/schema' {
5
6
  interface NuxtConfig { ['storefront']?: Partial<ModuleOptions> }
@@ -12,4 +13,4 @@ declare module 'nuxt/schema' {
12
13
  }
13
14
 
14
15
 
15
- export { AdditionalShopConfig, AppKeys, AuthenticationConfig, BapiConfig, CacheConfig, CheckoutEvent, CheckoutShopConfig, OauthConfig, PublicShopConfig, RedirectsConfig, RedisConfig, SessionConfig, ShopConfig, ShopConfigIndexed, StorageProvider, StorefrontConfig } from './module'
16
+ export type { AdditionalShopConfig, AppKeys, AuthenticationConfig, BapiConfig, CacheConfig, CheckoutEvent, CheckoutShopConfig, OauthConfig, PublicShopConfig, RedirectsConfig, RedisConfig, SessionConfig, ShopConfig, ShopConfigIndexed, StorageProvider, StorefrontConfig } from './module'
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
 
2
- import { ModuleOptions } from './module'
2
+ import type { ModuleOptions } from './module'
3
+
3
4
 
4
5
  declare module '@nuxt/schema' {
5
6
  interface NuxtConfig { ['storefront']?: Partial<ModuleOptions> }
@@ -12,4 +13,4 @@ declare module 'nuxt/schema' {
12
13
  }
13
14
 
14
15
 
15
- export { AdditionalShopConfig, AppKeys, AuthenticationConfig, BapiConfig, CacheConfig, CheckoutEvent, CheckoutShopConfig, OauthConfig, PublicShopConfig, RedirectsConfig, RedisConfig, SessionConfig, ShopConfig, ShopConfigIndexed, StorageProvider, StorefrontConfig } from './module'
16
+ export type { AdditionalShopConfig, AppKeys, AuthenticationConfig, BapiConfig, CacheConfig, CheckoutEvent, CheckoutShopConfig, OauthConfig, PublicShopConfig, RedirectsConfig, RedisConfig, SessionConfig, ShopConfig, ShopConfigIndexed, StorageProvider, StorefrontConfig } from './module'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@scayle/storefront-nuxt",
3
3
  "type": "module",
4
- "version": "7.37.2",
4
+ "version": "7.38.0",
5
5
  "description": "Nuxt integration for the SCAYLE Commerce Engine and Storefront API",
6
6
  "author": "SCAYLE Commerce Engine",
7
7
  "license": "MIT",
@@ -76,14 +76,14 @@
76
76
  "yn": "^5.0.0"
77
77
  },
78
78
  "devDependencies": {
79
- "@nuxt/module-builder": "0.5.3",
79
+ "@nuxt/module-builder": "0.5.4",
80
80
  "@nuxt/schema": "3.7.4",
81
81
  "@nuxt/test-utils": "3.7.4",
82
82
  "@scayle/eslint-config-storefront": "3.2.5",
83
83
  "@scayle/prettier-config-storefront": "2.0.2",
84
- "@types/node": "20.8.10",
84
+ "@types/node": "20.9.0",
85
85
  "eslint": "8.53.0",
86
- "eslint-formatter-gitlab": "5.0.0",
86
+ "eslint-formatter-gitlab": "5.1.0",
87
87
  "node-mocks-http": "1.13.0",
88
88
  "nuxt": "3.7.4",
89
89
  "prettier": "3.0.0",