@vue-storefront/nuxt 6.2.0 → 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.
- package/README.md +1 -1
- package/dist/module.d.mts +1 -1
- package/dist/module.d.ts +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +11 -8
- package/dist/runtime/defineSdkConfig.template +22 -32
- package/dist/runtime/plugin.template +18 -9
- package/dist/runtime/types.template +1 -1
- package/dist/runtime/useSdk.template +2 -2
- package/dist/types.d.mts +4 -1
- package/dist/types.d.ts +4 -1
- package/package.json +6 -4
- package/dist/runtime/utils/composeMiddlewareUrl.d.ts +0 -10
- package/dist/runtime/utils/composeMiddlewareUrl.js +0 -34
package/README.md
CHANGED
package/dist/module.d.mts
CHANGED
|
@@ -10,7 +10,7 @@ interface MiddlewareConfig {
|
|
|
10
10
|
* The URL of the middleware for server-side rendering.
|
|
11
11
|
* @example "http://localhost:4000"
|
|
12
12
|
*/
|
|
13
|
-
ssrApiUrl
|
|
13
|
+
ssrApiUrl: string;
|
|
14
14
|
/**
|
|
15
15
|
* This is identifier used to invalidate the cache on CDN when the assets change.
|
|
16
16
|
* Usually it's a commit hash.
|
package/dist/module.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ interface MiddlewareConfig {
|
|
|
10
10
|
* The URL of the middleware for server-side rendering.
|
|
11
11
|
* @example "http://localhost:4000"
|
|
12
12
|
*/
|
|
13
|
-
ssrApiUrl
|
|
13
|
+
ssrApiUrl: string;
|
|
14
14
|
/**
|
|
15
15
|
* This is identifier used to invalidate the cache on CDN when the assets change.
|
|
16
16
|
* Usually it's a commit hash.
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -11,9 +11,17 @@ const module = defineNuxtModule({
|
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
defaults: {
|
|
14
|
+
/**
|
|
15
|
+
* In the `middleware` object, both `apiUrl` and `ssrApiUrl` keys have to be
|
|
16
|
+
* present to allow Nuxt replacing them with the actual values from the
|
|
17
|
+
* .env file at runtime.
|
|
18
|
+
*
|
|
19
|
+
* https://nuxt.com/docs/guide/going-further/runtime-config
|
|
20
|
+
*/
|
|
14
21
|
middleware: {
|
|
15
|
-
apiUrl: "
|
|
16
|
-
cdnCacheBustingId: "no-cache-busting-id-set"
|
|
22
|
+
apiUrl: "",
|
|
23
|
+
cdnCacheBustingId: "no-cache-busting-id-set",
|
|
24
|
+
ssrApiUrl: ""
|
|
17
25
|
},
|
|
18
26
|
multistore: {
|
|
19
27
|
enabled: false
|
|
@@ -37,7 +45,7 @@ const module = defineNuxtModule({
|
|
|
37
45
|
...nuxt.options.app.head.meta ?? [],
|
|
38
46
|
{
|
|
39
47
|
name: "generator",
|
|
40
|
-
content: "
|
|
48
|
+
content: "Alokai Storefront"
|
|
41
49
|
}
|
|
42
50
|
];
|
|
43
51
|
addTypeTemplate({
|
|
@@ -52,11 +60,6 @@ export type SdkConfig = ${genInlineTypeImport(
|
|
|
52
60
|
filename: "alokaiModule.d.ts",
|
|
53
61
|
src: localResolver.resolve("./runtime/types.template")
|
|
54
62
|
});
|
|
55
|
-
addImports({
|
|
56
|
-
name: "composeMiddlewareUrl",
|
|
57
|
-
as: "composeMiddlewareUrl",
|
|
58
|
-
from: localResolver.resolve("./runtime/utils/composeMiddlewareUrl")
|
|
59
|
-
});
|
|
60
63
|
addImports({
|
|
61
64
|
name: "getDefaultMethodsRequestConfig",
|
|
62
65
|
as: "getDefaultMethodsRequestConfig",
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { buildModule, middlewareModule } from "@vue-storefront/sdk";
|
|
2
|
-
import {
|
|
2
|
+
import { useNuxtApp, useRequestHeaders, getDefaultMethodsRequestConfig } from "#imports";
|
|
3
3
|
import type { AlokaiModuleOptions } 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
|
-
*/
|
|
12
|
-
middlewareUrl: string;
|
|
13
8
|
/**
|
|
14
9
|
* @deprecated
|
|
15
10
|
* Use `getRequestHeaders` instead.
|
|
@@ -22,7 +17,8 @@ type InjectedContext = {
|
|
|
22
17
|
*/
|
|
23
18
|
defaults: ReturnType<typeof getDefaultMethodsRequestConfig>;
|
|
24
19
|
config: {
|
|
25
|
-
|
|
20
|
+
apiUrl: string;
|
|
21
|
+
ssrApiUrl: string;
|
|
26
22
|
defaultMethodsRequestConfig: ReturnType<typeof getDefaultMethodsRequestConfig>;
|
|
27
23
|
cdnCacheBustingId: string;
|
|
28
24
|
};
|
|
@@ -48,13 +44,15 @@ const moduleConfig: AlokaiModuleOptions = <%= options.moduleConfig %>;
|
|
|
48
44
|
* export default defineSdkConfig(
|
|
49
45
|
* ({ buildModule, middlewareModule, config, getCookieHeader }) => ({
|
|
50
46
|
* unified: buildModule(middlewareModule<UnifiedApiEndpoints>, {
|
|
51
|
-
* apiUrl: config.
|
|
47
|
+
* apiUrl: config.apiUrl + "/commerce",
|
|
48
|
+
* ssrApiUrl: config.ssrApiUrl + "/commerce",
|
|
52
49
|
* defaultRequestConfig: { headers: { ...getCookieHeader() } },
|
|
53
50
|
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
54
51
|
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
55
52
|
* }),
|
|
56
53
|
* contentful: buildModule(contentfulModule, {
|
|
57
|
-
* apiUrl: config.
|
|
54
|
+
* apiUrl: config.apiUrl + "/cntf",
|
|
55
|
+
* ssrApiUrl: config.ssrApiUrl + "/cntf",
|
|
58
56
|
* })
|
|
59
57
|
* }),
|
|
60
58
|
* );
|
|
@@ -68,11 +66,6 @@ export function defineSdkConfig<TConfig>(config: Config<TConfig>) {
|
|
|
68
66
|
const requestHeaders = useRequestHeaders(["x-forwarded-host", "host"]);
|
|
69
67
|
const resolvedOptions = resolveOptions(runtimeConfig.public.alokai);
|
|
70
68
|
|
|
71
|
-
const middlewareUrl = composeMiddlewareUrl({
|
|
72
|
-
options: resolvedOptions,
|
|
73
|
-
headers: requestHeaders,
|
|
74
|
-
});
|
|
75
|
-
|
|
76
69
|
const getCookieHeader = () => useRequestHeaders(["cookie"]);
|
|
77
70
|
const getRequestHeaders = () => useRequestHeaders();
|
|
78
71
|
|
|
@@ -82,35 +75,32 @@ export function defineSdkConfig<TConfig>(config: Config<TConfig>) {
|
|
|
82
75
|
getCookieHeader,
|
|
83
76
|
getRequestHeaders,
|
|
84
77
|
defaults: getDefaultMethodsRequestConfig(),
|
|
85
|
-
middlewareUrl,
|
|
86
78
|
config: {
|
|
79
|
+
apiUrl: resolvedOptions.middleware.apiUrl,
|
|
80
|
+
ssrApiUrl: resolvedOptions.middleware.ssrApiUrl,
|
|
87
81
|
defaultMethodsRequestConfig: getDefaultMethodsRequestConfig(),
|
|
88
|
-
middlewareUrl,
|
|
89
82
|
cdnCacheBustingId: runtimeConfig.public.alokai.middleware.cdnCacheBustingId,
|
|
90
83
|
}
|
|
91
84
|
});
|
|
92
85
|
}
|
|
93
86
|
}
|
|
94
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Helper function to resolve the SDK options based on the configuration.
|
|
90
|
+
*
|
|
91
|
+
* @privateRemarks
|
|
92
|
+
* For now this file only verifies the type of the input and simply returns it.
|
|
93
|
+
* However, in the future we might need it to perform true input resolution.
|
|
94
|
+
*
|
|
95
|
+
* @param input - The options for creating the SDK.
|
|
96
|
+
* @param options - The configuration object, that allows to customize the API Url creation on enabled multistore.
|
|
97
|
+
*
|
|
98
|
+
* @returns The resolved SDK options.
|
|
99
|
+
*/
|
|
95
100
|
function resolveOptions(
|
|
96
101
|
input: Omit<AlokaiModuleOptions, 'logger'>,
|
|
97
|
-
|
|
102
|
+
_options: Partial<ResolveSdkOptionsConfig> = {}
|
|
98
103
|
): AlokaiModuleOptions {
|
|
99
|
-
if (input?.multistore?.enabled) {
|
|
100
|
-
return {
|
|
101
|
-
middleware: {
|
|
102
|
-
// This is a dummy URL, the localhost domain will be replaced by the actual domain in the browser
|
|
103
|
-
// in composeMiddlewareUrl function. The server-side rendering will use ssrApiUrl.
|
|
104
|
-
apiUrl: `https://localhost/${options?.customSuffix ?? "api"}`,
|
|
105
|
-
cdnCacheBustingId: input.middleware?.cdnCacheBustingId,
|
|
106
|
-
ssrApiUrl: input.middleware?.ssrApiUrl ?? input.middleware.apiUrl,
|
|
107
|
-
},
|
|
108
|
-
multistore: {
|
|
109
|
-
enabled: true,
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
|
|
114
104
|
return input;
|
|
115
105
|
}
|
|
116
106
|
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import { initSDK } from "@vue-storefront/sdk"
|
|
2
|
-
import sdkConfig from "~/sdk.config"
|
|
3
|
-
import {
|
|
1
|
+
import { initSDK, type SDKApi } from "@vue-storefront/sdk";
|
|
2
|
+
import sdkConfig from "~/sdk.config";
|
|
3
|
+
import type { SdkConfig } from "./sdk.config";
|
|
4
|
+
import { defineNuxtPlugin } from '#app';
|
|
4
5
|
|
|
5
6
|
export default defineNuxtPlugin(() => {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
let sdk: SDKApi<ReturnType<SdkConfig>>;
|
|
8
|
+
|
|
9
|
+
const getSdk = () => {
|
|
10
|
+
if (!sdk) {
|
|
11
|
+
const config = sdkConfig();
|
|
12
|
+
sdk = initSDK(config);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return sdk;
|
|
16
|
+
};
|
|
8
17
|
|
|
9
18
|
return {
|
|
10
19
|
provide: {
|
|
11
|
-
alokai: {
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
})
|
|
20
|
+
alokai: { getSdk },
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
});
|
|
@@ -8,7 +8,7 @@ export interface MiddlewareConfig {
|
|
|
8
8
|
* The URL of the middleware for server-side rendering.
|
|
9
9
|
* @example "http://localhost:4000"
|
|
10
10
|
*/
|
|
11
|
-
ssrApiUrl
|
|
11
|
+
ssrApiUrl: string;
|
|
12
12
|
/**
|
|
13
13
|
* This is identifier used to invalidate the cache on CDN when the assets change.
|
|
14
14
|
* Usually it's a commit hash.
|
|
@@ -4,7 +4,7 @@ import { useNuxtApp } from "#imports";
|
|
|
4
4
|
|
|
5
5
|
export const useSdk = () => {
|
|
6
6
|
const nuxtApp = useNuxtApp();
|
|
7
|
-
const {
|
|
7
|
+
const { getSdk } = nuxtApp.$alokai as { getSdk: ()=> SDKApi<ReturnType<SdkConfig>> };
|
|
8
8
|
|
|
9
|
-
return
|
|
9
|
+
return getSdk();
|
|
10
10
|
};
|
package/dist/types.d.mts
CHANGED
|
@@ -3,11 +3,14 @@ import type { } from './module.js'
|
|
|
3
3
|
|
|
4
4
|
export interface ModuleOptions {
|
|
5
5
|
middleware: {
|
|
6
|
-
/** @default "
|
|
6
|
+
/** @default "" */
|
|
7
7
|
apiUrl: string,
|
|
8
8
|
|
|
9
9
|
/** @default "no-cache-busting-id-set" */
|
|
10
10
|
cdnCacheBustingId: string,
|
|
11
|
+
|
|
12
|
+
/** @default "" */
|
|
13
|
+
ssrApiUrl: string,
|
|
11
14
|
},
|
|
12
15
|
|
|
13
16
|
multistore: {
|
package/dist/types.d.ts
CHANGED
|
@@ -3,11 +3,14 @@ import type { } from './module'
|
|
|
3
3
|
|
|
4
4
|
export interface ModuleOptions {
|
|
5
5
|
middleware: {
|
|
6
|
-
/** @default "
|
|
6
|
+
/** @default "" */
|
|
7
7
|
apiUrl: string,
|
|
8
8
|
|
|
9
9
|
/** @default "no-cache-busting-id-set" */
|
|
10
10
|
cdnCacheBustingId: string,
|
|
11
|
+
|
|
12
|
+
/** @default "" */
|
|
13
|
+
ssrApiUrl: string,
|
|
11
14
|
},
|
|
12
15
|
|
|
13
16
|
multistore: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue-storefront/nuxt",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Alokai dedicated features for Nuxt",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
"build": "nuxt-module-build build",
|
|
21
21
|
"lint": "biome ci .",
|
|
22
22
|
"format": "prettier --write .",
|
|
23
|
-
"prepare": "nuxi prepare"
|
|
23
|
+
"prepare": "nuxi prepare",
|
|
24
|
+
"test:unit": "vitest run",
|
|
25
|
+
"version": "cp CHANGELOG.md ../../docs/content/storefront/6.change-log/nuxt.md"
|
|
24
26
|
},
|
|
25
27
|
"dependencies": {
|
|
26
28
|
"@nuxt/kit": "^3.7.4",
|
|
@@ -35,13 +37,13 @@
|
|
|
35
37
|
"@types/node": "^18.11.17",
|
|
36
38
|
"@nuxt/devtools": "1.3.8",
|
|
37
39
|
"@nuxt/module-builder": "0.7.1",
|
|
38
|
-
"@vue-storefront/sdk": "3.
|
|
40
|
+
"@vue-storefront/sdk": "3.4.1",
|
|
39
41
|
"@vue-storefront/unified-data-model": "*",
|
|
40
42
|
"@biomejs/biome": "1.9.2",
|
|
41
43
|
"nuxt": "3.12.2"
|
|
42
44
|
},
|
|
43
45
|
"peerDependencies": {
|
|
44
|
-
"@vue-storefront/sdk": "3.
|
|
46
|
+
"@vue-storefront/sdk": "3.4.1"
|
|
45
47
|
},
|
|
46
48
|
"publishConfig": {
|
|
47
49
|
"access": "public"
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { AlokaiModuleOptions } from "~/src/types";
|
|
2
|
-
interface ComposeMiddlewareUrlParams {
|
|
3
|
-
options: AlokaiModuleOptions;
|
|
4
|
-
headers: Record<string, string | string[]>;
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* @description A helper function to compute the middleware url. It will be used only internally in the package
|
|
8
|
-
*/
|
|
9
|
-
export declare function composeMiddlewareUrl({ options, headers, }: ComposeMiddlewareUrlParams): string;
|
|
10
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
function calculateMiddlewareUrl({
|
|
2
|
-
options,
|
|
3
|
-
headers
|
|
4
|
-
}) {
|
|
5
|
-
const { apiUrl, ssrApiUrl } = options.middleware;
|
|
6
|
-
if (typeof window !== "undefined") {
|
|
7
|
-
if (options.multistore?.enabled) {
|
|
8
|
-
const url2 = new URL(apiUrl);
|
|
9
|
-
url2.host = window.location.host;
|
|
10
|
-
return url2.href;
|
|
11
|
-
}
|
|
12
|
-
return apiUrl;
|
|
13
|
-
}
|
|
14
|
-
if (ssrApiUrl) {
|
|
15
|
-
return ssrApiUrl;
|
|
16
|
-
}
|
|
17
|
-
if (!options.multistore?.enabled) {
|
|
18
|
-
return apiUrl;
|
|
19
|
-
}
|
|
20
|
-
const forwardedHost = headers["x-forwarded-host"] ?? headers.host;
|
|
21
|
-
const url = new URL(apiUrl);
|
|
22
|
-
url.host = forwardedHost && [...forwardedHost].join("") || new URL(apiUrl).host;
|
|
23
|
-
return url.href;
|
|
24
|
-
}
|
|
25
|
-
function removeTrailingSlash(url) {
|
|
26
|
-
return url.replace(/\/$/, "");
|
|
27
|
-
}
|
|
28
|
-
export function composeMiddlewareUrl({
|
|
29
|
-
options,
|
|
30
|
-
headers
|
|
31
|
-
}) {
|
|
32
|
-
const url = calculateMiddlewareUrl({ options, headers });
|
|
33
|
-
return removeTrailingSlash(url);
|
|
34
|
-
}
|