@scayle/storefront-nuxt 7.95.4 → 8.0.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.
Files changed (95) hide show
  1. package/CHANGELOG.md +476 -0
  2. package/dist/index.d.mts +1 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/module.d.mts +2 -2
  5. package/dist/module.d.ts +2 -2
  6. package/dist/module.json +1 -1
  7. package/dist/module.mjs +6 -6
  8. package/dist/runtime/api/rpcHandler.d.ts +4 -6
  9. package/dist/runtime/campaignKey.d.ts +1 -2
  10. package/dist/runtime/campaignKey.js +3 -9
  11. package/dist/runtime/composables/core/useIDP.d.ts +2 -4
  12. package/dist/runtime/composables/core/useIDP.js +1 -8
  13. package/dist/runtime/composables/core/useRpc.d.ts +4 -17
  14. package/dist/runtime/composables/core/useRpc.js +11 -20
  15. package/dist/runtime/composables/core/useSession.d.ts +1 -1
  16. package/dist/runtime/composables/core/useUser.d.ts +2 -4
  17. package/dist/runtime/composables/core/useUser.js +3 -12
  18. package/dist/runtime/composables/index.d.ts +0 -3
  19. package/dist/runtime/composables/index.js +0 -3
  20. package/dist/runtime/composables/storefront/useBasket.d.ts +6 -4
  21. package/dist/runtime/composables/storefront/useBasket.js +68 -38
  22. package/dist/runtime/composables/storefront/useBrand.d.ts +2 -4
  23. package/dist/runtime/composables/storefront/useBrand.js +3 -4
  24. package/dist/runtime/composables/storefront/useBrands.d.ts +2 -4
  25. package/dist/runtime/composables/storefront/useBrands.js +3 -4
  26. package/dist/runtime/composables/storefront/useCategories.d.ts +3 -5
  27. package/dist/runtime/composables/storefront/useCategories.js +3 -8
  28. package/dist/runtime/composables/storefront/useCategoryById.d.ts +2 -4
  29. package/dist/runtime/composables/storefront/useCategoryById.js +3 -4
  30. package/dist/runtime/composables/storefront/useCategoryByPath.d.ts +2 -4
  31. package/dist/runtime/composables/storefront/useCategoryByPath.js +3 -4
  32. package/dist/runtime/composables/storefront/useCurrentPromotions.d.ts +2 -4
  33. package/dist/runtime/composables/storefront/useCurrentPromotions.js +3 -4
  34. package/dist/runtime/composables/storefront/useFilters.d.ts +2 -4
  35. package/dist/runtime/composables/storefront/useFilters.js +3 -4
  36. package/dist/runtime/composables/storefront/useNavigationTree.d.ts +3 -11
  37. package/dist/runtime/composables/storefront/useNavigationTree.js +6 -9
  38. package/dist/runtime/composables/storefront/useNavigationTrees.d.ts +2 -4
  39. package/dist/runtime/composables/storefront/useNavigationTrees.js +3 -4
  40. package/dist/runtime/composables/storefront/useOrder.d.ts +3 -5
  41. package/dist/runtime/composables/storefront/useOrder.js +3 -5
  42. package/dist/runtime/composables/storefront/useOrderConfirmation.d.ts +3 -5
  43. package/dist/runtime/composables/storefront/useOrderConfirmation.js +2 -2
  44. package/dist/runtime/composables/storefront/useProduct.d.ts +2 -4
  45. package/dist/runtime/composables/storefront/useProduct.js +3 -4
  46. package/dist/runtime/composables/storefront/useProducts.d.ts +2 -4
  47. package/dist/runtime/composables/storefront/useProducts.js +3 -4
  48. package/dist/runtime/composables/storefront/useProductsByIds.d.ts +2 -4
  49. package/dist/runtime/composables/storefront/useProductsByIds.js +3 -4
  50. package/dist/runtime/composables/storefront/useProductsByReferenceKeys.d.ts +2 -4
  51. package/dist/runtime/composables/storefront/useProductsByReferenceKeys.js +3 -4
  52. package/dist/runtime/composables/storefront/useProductsCount.d.ts +2 -4
  53. package/dist/runtime/composables/storefront/useProductsCount.js +3 -4
  54. package/dist/runtime/composables/storefront/usePromotions.d.ts +2 -4
  55. package/dist/runtime/composables/storefront/usePromotions.js +3 -4
  56. package/dist/runtime/composables/storefront/usePromotionsByIds.d.ts +2 -4
  57. package/dist/runtime/composables/storefront/usePromotionsByIds.js +3 -4
  58. package/dist/runtime/composables/storefront/useShopConfiguration.d.ts +1 -3
  59. package/dist/runtime/composables/storefront/useShopConfiguration.js +3 -4
  60. package/dist/runtime/composables/storefront/useStorefrontSearch.d.ts +5 -3
  61. package/dist/runtime/composables/storefront/useStorefrontSearch.js +3 -5
  62. package/dist/runtime/composables/storefront/useUserAddresses.d.ts +1 -3
  63. package/dist/runtime/composables/storefront/useUserAddresses.js +3 -4
  64. package/dist/runtime/composables/storefront/useVariant.d.ts +2 -4
  65. package/dist/runtime/composables/storefront/useVariant.js +3 -4
  66. package/dist/runtime/composables/storefront/useWishlist.d.ts +2 -3
  67. package/dist/runtime/composables/storefront/useWishlist.js +12 -21
  68. package/dist/runtime/context.js +1 -5
  69. package/dist/runtime/createLog.d.ts +1 -1
  70. package/dist/runtime/error/handler.d.ts +1 -1
  71. package/dist/runtime/error/handler.js +1 -28
  72. package/dist/runtime/nitro/plugins/nitroRuntimeStorageConfig.js +5 -93
  73. package/dist/runtime/plugin/shop.d.ts +4 -4
  74. package/dist/runtime/rpc/rpcCall.d.ts +1 -1
  75. package/dist/runtime/server/middleware/bootstrap-utils.d.ts +1 -5
  76. package/dist/runtime/server/middleware/bootstrap-utils.js +2 -4
  77. package/dist/runtime/server/middleware/bootstrap.js +3 -5
  78. package/dist/runtime/server/utils/cacheStorage.d.ts +1 -1
  79. package/dist/runtime/server/utils/cacheStorage.js +2 -2
  80. package/dist/runtime/utils/zodSchema.d.ts +467 -1840
  81. package/dist/runtime/utils/zodSchema.js +34 -83
  82. package/dist/shared/{storefront-nuxt.80aa5060.d.ts → storefront-nuxt.a816664e.d.mts} +4 -25
  83. package/dist/shared/{storefront-nuxt.80aa5060.d.mts → storefront-nuxt.a816664e.d.ts} +4 -25
  84. package/dist/test/factories.d.mts +1 -1
  85. package/dist/test/factories.d.ts +1 -1
  86. package/dist/test/factories.mjs +0 -2
  87. package/dist/types.d.mts +1 -1
  88. package/dist/types.d.ts +1 -1
  89. package/package.json +8 -8
  90. package/dist/runtime/composables/storefront/useFacet.d.ts +0 -100
  91. package/dist/runtime/composables/storefront/useFacet.js +0 -210
  92. package/dist/runtime/composables/storefront/useQueryFilterState.d.ts +0 -13
  93. package/dist/runtime/composables/storefront/useQueryFilterState.js +0 -78
  94. package/dist/runtime/composables/storefront/useSearch.d.ts +0 -14
  95. package/dist/runtime/composables/storefront/useSearch.js +0 -44
@@ -80,7 +80,7 @@ async function sessionProperties(context) {
80
80
  }
81
81
  export const buildContext = async (context) => {
82
82
  const { $cache, $shopConfig, $storefront, $log, config, event } = context;
83
- const sapiConfig = $shopConfig.sapi ?? $shopConfig.bapi ?? $storefront.sapi ?? $storefront.bapi;
83
+ const sapiConfig = $shopConfig.sapi ?? $storefront.sapi;
84
84
  const appKeys = $shopConfig.appKeys ?? $storefront.appKeys;
85
85
  const idpConfig = $shopConfig.idp ?? $storefront.idp;
86
86
  const sapiClient = new StorefrontAPIClient({
@@ -98,7 +98,6 @@ export const buildContext = async (context) => {
98
98
  const { hooks } = useNitroApp();
99
99
  const baseContext = {
100
100
  cached,
101
- bapiClient: sapiClient,
102
101
  sapiClient,
103
102
  auth: {
104
103
  resetPasswordUrl: $shopConfig.auth?.resetPasswordUrl
@@ -133,16 +132,13 @@ export const buildContext = async (context) => {
133
132
  hashAlgorithm: appKeys.hashAlgorithm,
134
133
  log: $log
135
134
  }),
136
- isCmsPreview: false,
137
135
  locale: $shopConfig.locale,
138
136
  shopId: $shopConfig.shopId,
139
137
  domain: $shopConfig.domain,
140
138
  withParams: $storefront.withParams,
141
- storeCampaignKeyword: $shopConfig.storeCampaignKeyword,
142
139
  campaignKey: await fetchCampaignKey(
143
140
  sapiClient,
144
141
  cached,
145
- $shopConfig.storeCampaignKeyword,
146
142
  $log
147
143
  ),
148
144
  runtimeConfiguration: config,
@@ -1,4 +1,4 @@
1
1
  import type { ConsolaInstance, ConsolaOptions } from 'consola';
2
- import type { LogLevel } from '../types/module.js';
2
+ import type { LogLevel } from '../index.js';
3
3
  import { Log } from '@scayle/storefront-core';
4
4
  export default function createLog(createConsola: (options?: Partial<ConsolaOptions>) => ConsolaInstance, space: string | undefined, level: LogLevel): Log;
@@ -1,5 +1,5 @@
1
1
  declare const resolveError: (error: Error | unknown) => {
2
- statusCode: 100 | 101 | 102 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
2
+ statusCode: 100 | 101 | 102 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 506 | 507 | 508 | 510 | 511 | 306 | 505;
3
3
  statusMessage: string;
4
4
  name: string;
5
5
  };
@@ -1,10 +1,4 @@
1
- import {
2
- BAPIError,
3
- BaseError,
4
- HttpStatusCode,
5
- HttpStatusMessage,
6
- BAPIFetchError
7
- } from "@scayle/storefront-core";
1
+ import { HttpStatusCode, HttpStatusMessage } from "@scayle/storefront-core";
8
2
  import { FetchError } from "ofetch";
9
3
  const parseErrorData = (error) => {
10
4
  if (error instanceof FetchError) {
@@ -15,27 +9,6 @@ const parseErrorData = (error) => {
15
9
  url
16
10
  };
17
11
  }
18
- if (error instanceof BAPIFetchError) {
19
- const url = error.response.url;
20
- return {
21
- statusCode: error.response.status ?? HttpStatusCode.INTERNAL_SERVER_ERROR,
22
- statusMessage: error.response.statusText ?? HttpStatusMessage.INTERNAL_SERVER_ERROR,
23
- url
24
- };
25
- }
26
- if (error instanceof BAPIError) {
27
- return {
28
- statusCode: error.statusCode ?? HttpStatusCode.INTERNAL_SERVER_ERROR,
29
- statusMessage: error.message ?? HttpStatusMessage.INTERNAL_SERVER_ERROR,
30
- url: error.url
31
- };
32
- }
33
- if (error instanceof BaseError) {
34
- return {
35
- statusCode: error.statusCode ?? HttpStatusCode.INTERNAL_SERVER_ERROR,
36
- statusMessage: error.message ?? HttpStatusMessage.INTERNAL_SERVER_ERROR
37
- };
38
- }
39
12
  if (error instanceof Error) {
40
13
  return {
41
14
  statusCode: HttpStatusCode.INTERNAL_SERVER_ERROR,
@@ -33,107 +33,19 @@ function mountStorage(storage, options) {
33
33
  }
34
34
  }
35
35
  }
36
- function transformLegacyConfig(provider = "redis", mode, log, redis, shopId = void 0) {
37
- log.warn(
38
- `${shopId ? "Shop " + shopId + " Storage" : "Global Storage"}: Using legacy storage config for ${mode}. The \`provider\` and \`redis\` options are deprecated.`
39
- );
40
- return {
41
- driver: provider,
42
- ...redis,
43
- // For backwards compatability. Sessions previously used a hardcoded db 1 for sessions
44
- ...mode === "session" ? { db: 1 } : {}
45
- };
46
- }
47
- function getCacheConfig(config, log) {
48
- if (config.storefront.storage?.cache) {
49
- return config.storefront.storage?.cache;
50
- }
51
- if (!config.storefront.cache?.provider && !config.storefront?.redis) {
52
- log.error(
53
- `Failed to initialize global cache storage configuration. Neither new 'storefront.storage.cache' option nor legacy 'storefront.cache.provider' is set.`
54
- );
55
- return void 0;
56
- }
57
- return transformLegacyConfig(
58
- config.storefront.cache?.provider,
59
- "cache",
60
- log,
61
- config.storefront?.redis ?? {}
62
- );
63
- }
64
- function getSessionConfig(config, log) {
65
- if (config.storefront.storage?.session) {
66
- return config.storefront.storage?.session;
67
- }
68
- if (!config.storefront.session?.provider && !config.storefront?.redis) {
69
- log.error(
70
- `Failed to initialize global session storage configuration. Neither new 'storefront.storage.session' option nor legacy 'storefront.session.provider' is set.`
71
- );
72
- return void 0;
73
- }
74
- return transformLegacyConfig(
75
- config.storefront.session?.provider,
76
- "session",
77
- log,
78
- config.storefront?.redis ?? {}
79
- );
80
- }
81
- function getShopCacheConfig(config, shop, log) {
82
- const storageConfig = shop.storage?.cache ?? config.storefront.storage?.cache;
83
- if (storageConfig) {
84
- return storageConfig;
85
- }
86
- const cacheProvider = config.storefront.cache?.provider;
87
- const useLegacyShopConfig = !!cacheProvider || !!shop.redis || !!config.storefront.redis;
88
- if (!useLegacyShopConfig) {
89
- log.error(
90
- `Failed to initialize shop ${shop.shopId} cache storage configuration. Neither new 'storefront.storage.session' option nor legacy 'storefront.session.provider' is set.`
91
- );
92
- return void 0;
93
- }
94
- return transformLegacyConfig(
95
- cacheProvider,
96
- "cache",
97
- log,
98
- shop.redis ?? config.storefront.redis ?? {},
99
- shop.shopId
100
- );
101
- }
102
- function getShopSessionConfig(config, shop, log) {
103
- const storageConfig = shop.storage?.session ?? config.storefront.storage?.session;
104
- if (storageConfig) {
105
- return storageConfig;
106
- }
107
- const sessionProvider = shop.sessionConfig?.provider ?? config.storefront.session?.provider;
108
- const useLegacyShopConfig = !!sessionProvider || !!shop.redis || !!config.storefront.redis;
109
- if (!useLegacyShopConfig) {
110
- log.error(
111
- `Failed to initialize shop ${shop.shopId} session storage configuration. Neither new 'storefront.storage.session' option nor legacy 'storefront.session.provider' is set.`
112
- );
113
- return void 0;
114
- }
115
- return transformLegacyConfig(
116
- sessionProvider,
117
- "session",
118
- log,
119
- shop.redis ?? config.storefront.redis ?? {},
120
- shop.shopId
121
- );
122
- }
123
36
  export default defineNitroPlugin(() => {
124
37
  const storage = useStorage();
125
38
  const config = useRuntimeConfig();
126
- const storefront = config.storefront;
39
+ const { shops } = config.storefront;
127
40
  const logConfig = config.public.storefront.log;
128
41
  const log = createLog(createConsola, logConfig.name, logConfig.level);
129
- const shops = "shops" in storefront ? storefront.shops : storefront.stores;
130
42
  try {
131
- const globalCacheConfig = getCacheConfig(config, log);
43
+ const globalCacheConfig = config.storefront.storage?.cache;
132
44
  mountStorage(storage, {
133
45
  base: STORAGE_MOUNT_CACHE,
134
46
  config: globalCacheConfig
135
47
  });
136
- const globalSessionConfig = getSessionConfig(config, log);
48
+ const globalSessionConfig = config.storefront.storage?.session;
137
49
  mountStorage(storage, {
138
50
  base: STORAGE_MOUNT_SESSION,
139
51
  config: globalSessionConfig
@@ -141,14 +53,14 @@ export default defineNitroPlugin(() => {
141
53
  for (const shop of Object.values(shops)) {
142
54
  const shopCacheMount = `${STORAGE_MOUNT_CACHE}:${shop.shopId}`;
143
55
  const shopSessionMount = `${STORAGE_MOUNT_SESSION}:${shop.shopId}`;
144
- const cacheConfig = getShopCacheConfig(config, shop, log);
56
+ const cacheConfig = shop.storage?.cache ?? config.storefront.storage?.cache;
145
57
  if (cacheConfig) {
146
58
  mountStorage(storage, {
147
59
  base: shopCacheMount,
148
60
  config: cacheConfig
149
61
  });
150
62
  }
151
- const sessionConfig = getShopSessionConfig(config, shop, log);
63
+ const sessionConfig = shop.storage?.session ?? config.storefront.storage?.session;
152
64
  if (sessionConfig) {
153
65
  mountStorage(storage, {
154
66
  base: shopSessionMount,
@@ -1,8 +1,8 @@
1
1
  declare const _default: import("nuxt/app").Plugin<{
2
- currentShop: import("../../module").PublicShopConfig;
3
- availableShops: import("../../module").PublicShopConfig[];
2
+ currentShop: import("../..").PublicShopConfig;
3
+ availableShops: import("../..").PublicShopConfig[];
4
4
  }> & import("nuxt/app").ObjectPlugin<{
5
- currentShop: import("../../module").PublicShopConfig;
6
- availableShops: import("../../module").PublicShopConfig[];
5
+ currentShop: import("../..").PublicShopConfig;
6
+ availableShops: import("../..").PublicShopConfig[];
7
7
  }>;
8
8
  export default _default;
@@ -1,6 +1,6 @@
1
1
  import type { RpcContext, RpcMethodName, RpcMethodParameters, RpcMethodReturnType } from '@scayle/storefront-core';
2
2
  import type { NuxtApp } from 'nuxt/app';
3
- import type { PublicShopConfig } from '../../types/module.js';
3
+ import type { PublicShopConfig } from '../../index.js';
4
4
  /**
5
5
  * rpcCall can be used to invoke an RPC method either on the client or server
6
6
  * It makes an HTTP request on the client and direct call on the server using $fetch
@@ -9,11 +9,7 @@ export declare function getBootstrapPath(event: H3Event): BootstrapPath;
9
9
  export declare const getShopByPath: (event: H3Event, shops: ShopConfig[], appBasePath: string) => ShopConfig | undefined;
10
10
  export declare const convertShopsToList: (shops: ShopConfig[] | ShopConfigIndexed) => ShopConfig[];
11
11
  export declare function getApiBasePath(storefrontConfig: ModuleBaseOptions, shop: ShopConfig, baseUrl: string): string;
12
- export declare function getCurrentShopConfigForRequest(event: H3Event, storefrontConfig: Pick<Extract<ModuleBaseOptions, {
13
- shops: ShopConfigIndexed;
14
- }>, 'shops' | 'shopSelector'> | Pick<Extract<ModuleBaseOptions, {
15
- stores: ShopConfigIndexed;
16
- }>, 'stores' | 'shopSelector'>, runtimeConfig: NitroRuntimeConfigApp): ShopConfig | undefined;
12
+ export declare function getCurrentShopConfigForRequest(event: H3Event, storefrontConfig: Pick<ModuleBaseOptions, 'shops' | 'shopSelector'>, runtimeConfig: NitroRuntimeConfigApp): ShopConfig | undefined;
17
13
  export declare function getPublicShopData(data: ShopConfig, currentShopId: number, apiBasePath: string, publicShopData?: (keyof ShopConfig)[]): PublicShopConfig & {
18
14
  isActive: boolean;
19
15
  };
@@ -48,10 +48,8 @@ export function getApiBasePath(storefrontConfig, shop, baseUrl) {
48
48
  }
49
49
  export function getCurrentShopConfigForRequest(event, storefrontConfig, runtimeConfig) {
50
50
  let $shopConfig;
51
- const { shopSelector } = storefrontConfig;
52
- const shopsList = convertShopsToList(
53
- "shops" in storefrontConfig ? storefrontConfig.shops : storefrontConfig.stores
54
- );
51
+ const { shopSelector, shops } = storefrontConfig;
52
+ const shopsList = convertShopsToList(shops);
55
53
  const headers = getRequestHeaders(event);
56
54
  const shopId = headers["x-shop-id"];
57
55
  if (shopId) {
@@ -70,12 +70,12 @@ async function bootstrap(event, $shopConfig, $storefrontConfig, apiBasePath, con
70
70
  try {
71
71
  const cookieName = sessionConfig?.cookieName ?? "$session";
72
72
  const secret = sessionConfig?.secret ?? "current-secret";
73
- const oldSessionData = await getOldSessionData(
73
+ const oldSessionData = $storefrontConfig.legacy?.enableSessionMigration ? await getOldSessionData(
74
74
  event,
75
75
  cookieName,
76
76
  sessionStorage,
77
77
  secret
78
- );
78
+ ) : void 0;
79
79
  await useSession(event, {
80
80
  ...sessionConfig,
81
81
  store: sessionStorage,
@@ -112,9 +112,7 @@ async function bootstrap(event, $shopConfig, $storefrontConfig, apiBasePath, con
112
112
  apiBasePath,
113
113
  $storefrontConfig.publicShopData
114
114
  );
115
- event.context.$availableShops = convertShopsToList(
116
- "shops" in $storefrontConfig ? $storefrontConfig.shops : $storefrontConfig.stores
117
- ).filter((store) => store.isEnabled !== false).map(
115
+ event.context.$availableShops = convertShopsToList($storefrontConfig.shops).filter((store) => store.isEnabled !== false).map(
118
116
  (config2) => getPublicShopData(
119
117
  config2,
120
118
  $shopConfig.shopId,
@@ -1,7 +1,7 @@
1
1
  import type { Log } from '@scayle/storefront-core';
2
2
  import { UnstorageCache } from '@scayle/storefront-core/dist/cache/providers/unstorage';
3
3
  import { type SessionStore } from '@scayle/h3-session';
4
- import type { SessionConfig } from '../../../types/module.js';
4
+ import type { SessionConfig } from '../../../index.js';
5
5
  export declare const STORAGE_MOUNT_BASE = "storefront";
6
6
  export declare const STORAGE_MOUNT_CACHE = "storefront-cache";
7
7
  export declare const STORAGE_MOUNT_SESSION = "storefront-session";
@@ -1,11 +1,11 @@
1
1
  import { UnstorageCache } from "@scayle/storefront-core/dist/cache/providers/unstorage";
2
2
  import { UnstorageSessionStore } from "@scayle/h3-session";
3
- import { useStorage } from "#imports";
3
+ import { useStorage } from "nitropack/runtime/storage";
4
4
  export const STORAGE_MOUNT_BASE = "storefront";
5
5
  export const STORAGE_MOUNT_CACHE = `${STORAGE_MOUNT_BASE}-cache`;
6
6
  export const STORAGE_MOUNT_SESSION = `${STORAGE_MOUNT_BASE}-session`;
7
7
  function checkInMemoryProviderAndShowWarning(provider, mountpoint, log) {
8
- if (provider !== "memory") {
8
+ if (!provider || provider !== "memory") {
9
9
  return;
10
10
  }
11
11
  log.warn(