@vue-storefront/nuxt 4.0.1 → 4.1.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/dist/module.d.mts CHANGED
@@ -11,6 +11,13 @@ interface MiddlewareConfig {
11
11
  * @example "http://localhost:4000"
12
12
  */
13
13
  ssrApiUrl?: string;
14
+ /**
15
+ * This is identifier used to invalidate the cache on CDN when the assets change.
16
+ * Usually it's a commit hash.
17
+ * @example "2c106d9619c71c3082c9b59b1d72817363c8ecb9"
18
+ * @default "no-cache-busting-id-set"
19
+ */
20
+ cdnCacheBustingId?: string;
14
21
  }
15
22
  interface MultistoreConfig {
16
23
  /**
package/dist/module.d.ts CHANGED
@@ -11,6 +11,13 @@ interface MiddlewareConfig {
11
11
  * @example "http://localhost:4000"
12
12
  */
13
13
  ssrApiUrl?: string;
14
+ /**
15
+ * This is identifier used to invalidate the cache on CDN when the assets change.
16
+ * Usually it's a commit hash.
17
+ * @example "2c106d9619c71c3082c9b59b1d72817363c8ecb9"
18
+ * @default "no-cache-busting-id-set"
19
+ */
20
+ cdnCacheBustingId?: string;
14
21
  }
15
22
  interface MultistoreConfig {
16
23
  /**
package/dist/module.json CHANGED
@@ -4,5 +4,9 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "4.0.1"
7
+ "version": "4.1.0",
8
+ "builder": {
9
+ "@nuxt/module-builder": "0.7.1",
10
+ "unbuild": "2.0.0"
11
+ }
8
12
  }
package/dist/module.mjs CHANGED
@@ -12,7 +12,8 @@ const module = defineNuxtModule({
12
12
  },
13
13
  defaults: {
14
14
  middleware: {
15
- apiUrl: "http://localhost:4000"
15
+ apiUrl: "http://localhost:4000",
16
+ cdnCacheBustingId: "no-cache-busting-id-set"
16
17
  },
17
18
  multistore: {
18
19
  enabled: false
@@ -21,12 +22,18 @@ const module = defineNuxtModule({
21
22
  setup(options, nuxt) {
22
23
  const projectLayer = nuxt.options._layers[0];
23
24
  const projectRootResolver = createResolver(projectLayer.config.rootDir);
24
- const buildDirResolver = createResolver(nuxt.options.buildDir);
25
+ const buildDirectoryResolver = createResolver(nuxt.options.buildDir);
25
26
  const localResolver = createResolver(import.meta.url);
26
27
  nuxt.options.runtimeConfig.public.vsf = defu(
27
28
  nuxt.options.runtimeConfig.public?.vsf,
28
29
  options
29
30
  );
31
+ nuxt.options.runtimeConfig.public.alokai = defu(
32
+ nuxt.options.runtimeConfig.public?.alokai,
33
+ { middleware: { cdnCacheBustingId: process.env?.GIT_SHA } },
34
+ nuxt.options.runtimeConfig.public?.vsf,
35
+ options
36
+ );
30
37
  nuxt.options.app.head.meta = [
31
38
  ...nuxt.options.app.head.meta ?? [],
32
39
  {
@@ -43,7 +50,7 @@ export type SdkConfig = ${genInlineTypeImport(
43
50
  `
44
51
  });
45
52
  addTypeTemplate({
46
- filename: "vsfModule.d.ts",
53
+ filename: "alokaiModule.d.ts",
47
54
  src: localResolver.resolve("./runtime/types.template")
48
55
  });
49
56
  addImports({
@@ -52,8 +59,8 @@ export type SdkConfig = ${genInlineTypeImport(
52
59
  from: localResolver.resolve("./runtime/utils/composeMiddlewareUrl")
53
60
  });
54
61
  addImports({
55
- name: "getDefaults",
56
- as: "getDefaults",
62
+ name: "getDefaultMethodsRequestConfig",
63
+ as: "getDefaultMethodsRequestConfig",
57
64
  from: localResolver.resolve("./runtime/utils/defaults")
58
65
  });
59
66
  addTemplate({
@@ -71,17 +78,17 @@ export type SdkConfig = ${genInlineTypeImport(
71
78
  });
72
79
  addPluginTemplate({
73
80
  src: localResolver.resolve("./runtime/plugin.template"),
74
- filename: "vsfSdkPlugin.ts",
81
+ filename: "alokaiSdkPlugin.ts",
75
82
  write: true
76
83
  });
77
84
  addImportsSources([
78
85
  {
79
86
  imports: ["useSdk"],
80
- from: buildDirResolver.resolve("useSdk.ts")
87
+ from: buildDirectoryResolver.resolve("useSdk.ts")
81
88
  },
82
89
  {
83
90
  imports: ["defineSdkConfig"],
84
- from: buildDirResolver.resolve("defineSdkConfig.ts")
91
+ from: buildDirectoryResolver.resolve("defineSdkConfig.ts")
85
92
  }
86
93
  ]);
87
94
  }
@@ -1,10 +1,14 @@
1
1
  import { buildModule, middlewareModule } from "@vue-storefront/sdk";
2
- import { composeMiddlewareUrl, useNuxtApp, useRequestHeaders, getDefaults } from "#imports";
3
- import { SdkModuleOptions } from "./vsfModule";
2
+ import { composeMiddlewareUrl, useNuxtApp, useRequestHeaders, getDefaultMethodsRequestConfig } from "#imports";
3
+ import { SdkModuleOptions } from "./alokaiModule";
4
4
 
5
5
  type InjectedContext = {
6
6
  buildModule: typeof buildModule;
7
7
  middlewareModule: typeof middlewareModule;
8
+ /**
9
+ * @deprecated
10
+ * Use `config.middlewareUrl` instead.
11
+ */
8
12
  middlewareUrl: string;
9
13
  /**
10
14
  * @deprecated
@@ -12,10 +16,15 @@ type InjectedContext = {
12
16
  */
13
17
  getCookieHeader: () => Record<string, string>;
14
18
  getRequestHeaders: () => Record<string, string>;
15
- defaults: ReturnType<typeof getDefaults>;
19
+ /**
20
+ * @deprecated
21
+ * Use `config.defaults` instead.
22
+ */
23
+ defaults: ReturnType<typeof getDefaultMethodsRequestConfig>;
16
24
  config: {
17
25
  middlewareUrl: string;
18
- defaults: ReturnType<typeof getDefaults>;
26
+ defaultMethodsRequestConfig: ReturnType<typeof getDefaultMethodsRequestConfig>;
27
+ cdnCacheBustingId: string;
19
28
  };
20
29
  };
21
30
 
@@ -37,13 +46,15 @@ const moduleConfig: SdkModuleOptions = <%= options.moduleConfig %>;
37
46
  * import type { UnifiedApiEndpoints } from "../storefront-middleware/types";
38
47
  *
39
48
  * export default defineSdkConfig(
40
- * ({ buildModule, middlewareModule, middlewareUrl, getCookieHeader }) => ({
49
+ * ({ buildModule, middlewareModule, config, getCookieHeader }) => ({
41
50
  * unified: buildModule(middlewareModule<UnifiedApiEndpoints>, {
42
- * apiUrl: middlewareUrl + "/commerce",
51
+ * apiUrl: config.middlewareUrl + "/commerce",
43
52
  * defaultRequestConfig: { headers: { ...getCookieHeader() } },
53
+ * cdnCacheBustingId: config.cdnCacheBustingId,
54
+ * methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
44
55
  * }),
45
56
  * contentful: buildModule(contentfulModule, {
46
- * apiUrl: middlewareUrl + "/cntf",
57
+ * apiUrl: config.middlewareUrl + "/cntf",
47
58
  * }),
48
59
  * }),
49
60
  * );
@@ -56,7 +67,7 @@ export function defineSdkConfig<TConfig>(config: Config<TConfig>) {
56
67
 
57
68
  const requestHeaders = useRequestHeaders(["x-forwarded-host", "host"]);
58
69
  const middlewareUrl = composeMiddlewareUrl({
59
- options: runtimeConfig.public.vsf,
70
+ options: runtimeConfig.public.alokai,
60
71
  headers: requestHeaders,
61
72
  });
62
73
 
@@ -68,11 +79,12 @@ export function defineSdkConfig<TConfig>(config: Config<TConfig>) {
68
79
  middlewareModule,
69
80
  getCookieHeader,
70
81
  getRequestHeaders,
71
- defaults: getDefaults(),
82
+ defaults: getDefaultMethodsRequestConfig(),
72
83
  middlewareUrl,
73
84
  config: {
74
- defaults: getDefaults(),
85
+ defaultMethodsRequestConfig: getDefaultMethodsRequestConfig(),
75
86
  middlewareUrl,
87
+ cdnCacheBustingId: runtimeConfig.public.alokai.middleware.cdnCacheBustingId,
76
88
  }
77
89
  });
78
90
  }
@@ -8,7 +8,7 @@ export default defineNuxtPlugin(() => {
8
8
 
9
9
  return {
10
10
  provide: {
11
- vsf: { sdk }
11
+ alokai: { sdk }
12
12
  }
13
13
  }
14
14
  })
@@ -1,13 +1,33 @@
1
1
  export interface MiddlewareConfig {
2
+ /**
3
+ * The URL of the middleware.
4
+ * @example "http://localhost:4000"
5
+ */
2
6
  apiUrl: string;
7
+ /**
8
+ * The URL of the middleware for server-side rendering.
9
+ * @example "http://localhost:4000"
10
+ */
3
11
  ssrApiUrl?: string;
12
+ /**
13
+ * This is identifier used to invalidate the cache on CDN when the assets change.
14
+ * Usually it's a commit hash.
15
+ * @example "2c106d9619c71c3082c9b59b1d72817363c8ecb9"
16
+ * @default "no-cache-busting-id-set"
17
+ */
18
+ cdnCacheBustingId?: string;
4
19
  }
5
20
 
6
21
  export interface MultistoreConfig {
22
+ /**
23
+ * Whether the multistore is enabled or not.
24
+ * @example false
25
+ * @default false
26
+ */
7
27
  enabled: boolean;
8
28
  }
9
29
 
10
30
  export interface SdkModuleOptions {
11
31
  middleware: MiddlewareConfig;
12
32
  multistore?: MultistoreConfig;
13
- }
33
+ }
@@ -4,7 +4,7 @@ import { useNuxtApp } from "#imports";
4
4
 
5
5
  export const useSdk = () => {
6
6
  const nuxtApp = useNuxtApp();
7
- const { sdk } = nuxtApp.$vsf as { sdk: SDKApi<ReturnType<SdkConfig>> };
7
+ const { sdk } = nuxtApp.$alokai as { sdk: SDKApi<ReturnType<SdkConfig>> };
8
8
 
9
9
  return sdk;
10
10
  };
@@ -4,7 +4,6 @@ interface ComposeMiddlewareUrlParams {
4
4
  headers: Record<string, string | string[]>;
5
5
  }
6
6
  /**
7
- *
8
7
  * @description A helper function to compute the middleware url. It will be used only internally in the package
9
8
  */
10
9
  export declare function composeMiddlewareUrl({ options, headers, }: ComposeMiddlewareUrlParams): string;
@@ -1,31 +1,27 @@
1
- export declare function getDefaults(): {
1
+ export declare function getDefaultMethodsRequestConfig(): {
2
2
  readonly unifiedCommerce: {
3
3
  readonly middlewareModule: {
4
- readonly defaultMethodsRequestConfig: {
5
- readonly getCategories: {
6
- readonly method: "GET";
7
- };
8
- readonly getProductDetails: {
9
- readonly method: "GET";
10
- };
11
- readonly getProductReviews: {
12
- readonly method: "GET";
13
- };
14
- readonly getProducts: {
15
- readonly method: "GET";
16
- };
17
- readonly searchProducts: {
18
- readonly method: "GET";
19
- };
4
+ readonly getCategories: {
5
+ readonly method: "GET";
6
+ };
7
+ readonly getProductDetails: {
8
+ readonly method: "GET";
9
+ };
10
+ readonly getProductReviews: {
11
+ readonly method: "GET";
12
+ };
13
+ readonly getProducts: {
14
+ readonly method: "GET";
15
+ };
16
+ readonly searchProducts: {
17
+ readonly method: "GET";
20
18
  };
21
19
  };
22
20
  };
23
21
  readonly unifiedCms: {
24
22
  readonly middlewareModule: {
25
- readonly defaultMethodsRequestConfig: {
26
- readonly getEntries: {
27
- readonly method: "GET";
28
- };
23
+ readonly getEntries: {
24
+ readonly method: "GET";
29
25
  };
30
26
  };
31
27
  };
@@ -0,0 +1,18 @@
1
+ export function getDefaultMethodsRequestConfig() {
2
+ return {
3
+ unifiedCommerce: {
4
+ middlewareModule: {
5
+ getCategories: { method: "GET" },
6
+ getProductDetails: { method: "GET" },
7
+ getProductReviews: { method: "GET" },
8
+ getProducts: { method: "GET" },
9
+ searchProducts: { method: "GET" }
10
+ }
11
+ },
12
+ unifiedCms: {
13
+ middlewareModule: {
14
+ getEntries: { method: "GET" }
15
+ }
16
+ }
17
+ };
18
+ }
package/dist/types.d.mts CHANGED
@@ -1,7 +1,30 @@
1
1
 
2
- import { } from './module'
2
+ import type { } from './module.js'
3
3
 
4
+ export interface ModuleOptions {
5
+ middleware: {
6
+ /** @default "http://localhost:4000" */
7
+ apiUrl: string,
4
8
 
9
+ /** @default "no-cache-busting-id-set" */
10
+ cdnCacheBustingId: string,
11
+ },
5
12
 
13
+ multistore: {
14
+ /** @default false */
15
+ enabled: boolean,
16
+ },
17
+ }
6
18
 
7
- export { default } from './module'
19
+ declare module '@nuxt/schema' {
20
+ interface NuxtConfig { ['vsf']?: Partial<ModuleOptions> }
21
+ interface NuxtOptions { ['vsf']?: ModuleOptions }
22
+ }
23
+
24
+ declare module 'nuxt/schema' {
25
+ interface NuxtConfig { ['vsf']?: Partial<ModuleOptions> }
26
+ interface NuxtOptions { ['vsf']?: ModuleOptions }
27
+ }
28
+
29
+
30
+ export type { default } from './module.js'
package/dist/types.d.ts CHANGED
@@ -1,7 +1,30 @@
1
1
 
2
- import { } from './module'
2
+ import type { } from './module'
3
3
 
4
+ export interface ModuleOptions {
5
+ middleware: {
6
+ /** @default "http://localhost:4000" */
7
+ apiUrl: string,
4
8
 
9
+ /** @default "no-cache-busting-id-set" */
10
+ cdnCacheBustingId: string,
11
+ },
5
12
 
13
+ multistore: {
14
+ /** @default false */
15
+ enabled: boolean,
16
+ },
17
+ }
6
18
 
7
- export { default } from './module'
19
+ declare module '@nuxt/schema' {
20
+ interface NuxtConfig { ['vsf']?: Partial<ModuleOptions> }
21
+ interface NuxtOptions { ['vsf']?: ModuleOptions }
22
+ }
23
+
24
+ declare module 'nuxt/schema' {
25
+ interface NuxtConfig { ['vsf']?: Partial<ModuleOptions> }
26
+ interface NuxtOptions { ['vsf']?: ModuleOptions }
27
+ }
28
+
29
+
30
+ export type { default } from './module'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-storefront/nuxt",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "description": "Vue Storefront dedicated features for Nuxt",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,7 +17,7 @@
17
17
  "dist"
18
18
  ],
19
19
  "scripts": {
20
- "build": "nuxt-module-build build && yarn build:app",
20
+ "build": "nuxt-module-build build",
21
21
  "build:app": "cd __tests__/app && yarn build",
22
22
  "dev": "cd __tests__/app && yarn dev",
23
23
  "dev:middleware": "cd ../shared/src/__tests__/middleware && yarn dev",
@@ -36,11 +36,11 @@
36
36
  },
37
37
  "devDependencies": {
38
38
  "@types/node": "^18.11.17",
39
- "@nuxt/devtools": "^1.0.0",
40
- "@nuxt/module-builder": "0.5.2",
41
- "@nuxt/test-utils": "3.7.4",
42
- "nuxt": "3.7.4",
39
+ "@nuxt/devtools": "1.3.3",
40
+ "@nuxt/module-builder": "0.7.1",
41
+ "@nuxt/test-utils": "3.13.1",
42
+ "nuxt": "3.12.2",
43
43
  "start-server-and-test": "^2.0.3",
44
- "vitest": "^0.34.6"
44
+ "vitest": "1.6.0"
45
45
  }
46
46
  }
@@ -1,22 +0,0 @@
1
- export function getDefaults() {
2
- return {
3
- unifiedCommerce: {
4
- middlewareModule: {
5
- defaultMethodsRequestConfig: {
6
- getCategories: { method: "GET" },
7
- getProductDetails: { method: "GET" },
8
- getProductReviews: { method: "GET" },
9
- getProducts: { method: "GET" },
10
- searchProducts: { method: "GET" }
11
- }
12
- }
13
- },
14
- unifiedCms: {
15
- middlewareModule: {
16
- defaultMethodsRequestConfig: {
17
- getEntries: { method: "GET" }
18
- }
19
- }
20
- }
21
- };
22
- }