@vue-storefront/nuxt 9.0.0-rc.4 → 9.0.0-rc.6
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.json +1 -1
- package/dist/module.mjs +27 -2
- package/dist/runtime/defineGetConfigSwitcherHeader.template +1 -0
- package/dist/runtime/defineSdkConfig.template +102 -20
- package/dist/runtime/serverMiddleware.d.ts +2 -0
- package/dist/runtime/serverMiddleware.js +6 -0
- package/package.json +3 -3
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineNuxtModule, createResolver, installModule, addTypeTemplate, addImports, addTemplate, addPluginTemplate, addImportsSources } from '@nuxt/kit';
|
|
1
|
+
import { defineNuxtModule, createResolver, installModule, addTypeTemplate, addImports, addTemplate, addPluginTemplate, addImportsSources, addServerHandler } from '@nuxt/kit';
|
|
2
2
|
import { defu } from 'defu';
|
|
3
3
|
import { genInlineTypeImport } from 'knitwork';
|
|
4
4
|
|
|
@@ -48,6 +48,11 @@ const module = defineNuxtModule({
|
|
|
48
48
|
name: "generator"
|
|
49
49
|
}
|
|
50
50
|
];
|
|
51
|
+
nuxt.hooks.hook("nitro:config", async (nitroConfig) => {
|
|
52
|
+
nitroConfig.externals = nitroConfig.externals || {};
|
|
53
|
+
nitroConfig.externals.inline = nitroConfig.externals.inline || [];
|
|
54
|
+
nitroConfig.externals.inline.push(localResolver.resolve("./runtime"));
|
|
55
|
+
});
|
|
51
56
|
addTypeTemplate({
|
|
52
57
|
filename: "sdk.config.d.ts",
|
|
53
58
|
getContents: () => `
|
|
@@ -78,6 +83,16 @@ export type SdkConfig = ${genInlineTypeImport(
|
|
|
78
83
|
src: localResolver.resolve("./runtime/defineSdkConfig.template"),
|
|
79
84
|
write: true
|
|
80
85
|
});
|
|
86
|
+
addTemplate({
|
|
87
|
+
filename: "defineGetConfigSwitcherHeader.ts",
|
|
88
|
+
options: {
|
|
89
|
+
moduleConfig: JSON.stringify(options)
|
|
90
|
+
},
|
|
91
|
+
src: localResolver.resolve(
|
|
92
|
+
"./runtime/defineGetConfigSwitcherHeader.template"
|
|
93
|
+
),
|
|
94
|
+
write: true
|
|
95
|
+
});
|
|
81
96
|
addTemplate({
|
|
82
97
|
filename: "useSfState.ts",
|
|
83
98
|
src: localResolver.resolve("./runtime/useSfState.template"),
|
|
@@ -111,7 +126,13 @@ export type SdkConfig = ${genInlineTypeImport(
|
|
|
111
126
|
},
|
|
112
127
|
{
|
|
113
128
|
from: buildDirectoryResolver.resolve("defineSdkConfig.ts"),
|
|
114
|
-
imports: ["defineSdkConfig"]
|
|
129
|
+
imports: ["defineSdkConfig", "defineSdkModule"]
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
from: buildDirectoryResolver.resolve(
|
|
133
|
+
"defineGetConfigSwitcherHeader.ts"
|
|
134
|
+
),
|
|
135
|
+
imports: ["defineGetConfigSwitcherHeader"]
|
|
115
136
|
},
|
|
116
137
|
{
|
|
117
138
|
from: buildDirectoryResolver.resolve("useSfState.ts"),
|
|
@@ -122,6 +143,10 @@ export type SdkConfig = ${genInlineTypeImport(
|
|
|
122
143
|
imports: ["logger"]
|
|
123
144
|
}
|
|
124
145
|
]);
|
|
146
|
+
addServerHandler({
|
|
147
|
+
handler: localResolver.resolve("./runtime/serverMiddleware"),
|
|
148
|
+
middleware: true
|
|
149
|
+
});
|
|
125
150
|
}
|
|
126
151
|
});
|
|
127
152
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineGetConfigSwitcherHeader } from '@alokai/connect/sdk';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Extension, Module } from "@alokai/connect/sdk";
|
|
1
2
|
import { buildModule, middlewareModule } from "@alokai/connect/sdk";
|
|
2
3
|
import { useNuxtApp, useRequestHeaders, getDefaultMethodsRequestConfig } from "#imports";
|
|
3
4
|
import type { Composer } from '#i18n';
|
|
@@ -32,34 +33,62 @@ const moduleConfig: AlokaiModuleOptions = <%= options.moduleConfig %>;
|
|
|
32
33
|
/**
|
|
33
34
|
* Define SDK config function
|
|
34
35
|
*
|
|
35
|
-
* @param config - Function that returns SDK config
|
|
36
|
+
* @param config - Function that returns SDK config or a record of SDK modules
|
|
36
37
|
*
|
|
37
|
-
* @example
|
|
38
|
+
* @example Using a function:
|
|
38
39
|
* ```ts
|
|
39
|
-
* import {
|
|
40
|
-
*
|
|
41
|
-
* ContentfulModuleType,
|
|
42
|
-
* } from "@vsf-enterprise/contentful-sdk";
|
|
43
|
-
* import type { UnifiedApiEndpoints } from "../storefront-middleware/types";
|
|
40
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
41
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
44
42
|
*
|
|
45
43
|
* export default defineSdkConfig(
|
|
46
|
-
* ({ buildModule, middlewareModule, config,
|
|
47
|
-
* unified: buildModule(middlewareModule<
|
|
48
|
-
* apiUrl: config.apiUrl + "/commerce",
|
|
49
|
-
* ssrApiUrl: config.ssrApiUrl + "/commerce",
|
|
50
|
-
* defaultRequestConfig: { headers: { ...getCookieHeader() } },
|
|
44
|
+
* ({ buildModule, middlewareModule, config, getRequestHeaders }) => ({
|
|
45
|
+
* unified: buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
46
|
+
* apiUrl: config.apiUrl + "/commerce/unified",
|
|
47
|
+
* ssrApiUrl: config.ssrApiUrl + "/commerce/unified",
|
|
51
48
|
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
49
|
+
* defaultRequestConfig: {
|
|
50
|
+
* getConfigSwitcherHeader,
|
|
51
|
+
* headers: getRequestHeaders(),
|
|
52
|
+
* },
|
|
52
53
|
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
53
54
|
* }),
|
|
54
|
-
* contentful: buildModule(contentfulModule, {
|
|
55
|
-
* apiUrl: config.apiUrl + "/cntf",
|
|
56
|
-
* ssrApiUrl: config.ssrApiUrl + "/cntf",
|
|
57
|
-
* })
|
|
58
55
|
* }),
|
|
59
56
|
* );
|
|
60
57
|
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example Using a record of modules:
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { defineSdkModule } from '@vue-storefront/nuxt';
|
|
62
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
63
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
64
|
+
*
|
|
65
|
+
* const unified = defineSdkModule(({ buildModule, config, getRequestHeaders, middlewareModule }) =>
|
|
66
|
+
* buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
67
|
+
* apiUrl: config.apiUrl + "/commerce/unified",
|
|
68
|
+
* ssrApiUrl: config.ssrApiUrl + "/commerce/unified",
|
|
69
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
70
|
+
* defaultRequestConfig: {
|
|
71
|
+
* getConfigSwitcherHeader,
|
|
72
|
+
* headers: getRequestHeaders(),
|
|
73
|
+
* },
|
|
74
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
75
|
+
* }),
|
|
76
|
+
* );
|
|
77
|
+
*
|
|
78
|
+
* export default defineSdkConfig({
|
|
79
|
+
* unified,
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
61
82
|
*/
|
|
62
|
-
export function defineSdkConfig<TConfig>(config: Config<TConfig>)
|
|
83
|
+
export function defineSdkConfig<TConfig>(config: Config<TConfig>): () => TConfig;
|
|
84
|
+
export function defineSdkConfig<TModules extends Record<string, DefineSdkModule>>(
|
|
85
|
+
modules: TModules,
|
|
86
|
+
): () => {
|
|
87
|
+
[K in keyof TModules]: ReturnType<TModules[K]>;
|
|
88
|
+
};
|
|
89
|
+
export function defineSdkConfig<TConfig>(
|
|
90
|
+
config: Config<TConfig> | Record<string, DefineSdkModule>,
|
|
91
|
+
) {
|
|
63
92
|
return () => {
|
|
64
93
|
const nuxtApp = useNuxtApp()
|
|
65
94
|
const runtimeConfig = useRuntimeConfig();
|
|
@@ -73,7 +102,7 @@ export function defineSdkConfig<TConfig>(config: Config<TConfig>) {
|
|
|
73
102
|
...useRequestHeaders()
|
|
74
103
|
});
|
|
75
104
|
|
|
76
|
-
|
|
105
|
+
const context = {
|
|
77
106
|
buildModule,
|
|
78
107
|
middlewareModule,
|
|
79
108
|
getCookieHeader,
|
|
@@ -85,10 +114,63 @@ export function defineSdkConfig<TConfig>(config: Config<TConfig>) {
|
|
|
85
114
|
defaultMethodsRequestConfig: getDefaultMethodsRequestConfig(),
|
|
86
115
|
cdnCacheBustingId: runtimeConfig.public.alokai.middleware.cdnCacheBustingId,
|
|
87
116
|
}
|
|
88
|
-
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
if (typeof config === 'function') {
|
|
120
|
+
return config(context);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return buildModules(config)(context);
|
|
89
124
|
}
|
|
90
125
|
}
|
|
91
126
|
|
|
127
|
+
type DefineSdkModule = (
|
|
128
|
+
context: InjectedContext,
|
|
129
|
+
) => ReturnType<typeof buildModule>;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Defines an SDK module that can be used with defineSdkConfig.
|
|
133
|
+
* Each module is a function that takes the InjectedContext and returns a built module.
|
|
134
|
+
*
|
|
135
|
+
* @param moduleDefinition - A function that takes InjectedContext and returns a built module
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* import { defineSdkModule } from '@vue-storefront/nuxt';
|
|
140
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
141
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
142
|
+
*
|
|
143
|
+
* export const unified = defineSdkModule(({ buildModule, config, getRequestHeaders, middlewareModule }) =>
|
|
144
|
+
* buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
145
|
+
* apiUrl: config.apiUrl + "/commerce/unified",
|
|
146
|
+
* ssrApiUrl: config.ssrApiUrl + "/commerce/unified",
|
|
147
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
148
|
+
* defaultRequestConfig: {
|
|
149
|
+
* getConfigSwitcherHeader,
|
|
150
|
+
* headers: getRequestHeaders(),
|
|
151
|
+
* },
|
|
152
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
153
|
+
* }),
|
|
154
|
+
* );
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export function defineSdkModule<TModuleDefinition extends DefineSdkModule>(
|
|
158
|
+
moduleDefinition: TModuleDefinition,
|
|
159
|
+
) {
|
|
160
|
+
return moduleDefinition;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function buildModules<TModules extends Record<string, DefineSdkModule>>(
|
|
164
|
+
modules: TModules,
|
|
165
|
+
) {
|
|
166
|
+
return (context: InjectedContext) =>
|
|
167
|
+
Object.fromEntries(
|
|
168
|
+
Object.entries(modules).map(([key, module]) => [key, module(context)]),
|
|
169
|
+
) as {
|
|
170
|
+
[K in keyof TModules]: ReturnType<TModules[K]>;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
92
174
|
/**
|
|
93
175
|
* Helper function to resolve the SDK options based on the configuration.
|
|
94
176
|
*
|
|
@@ -110,4 +192,4 @@ function resolveOptions(
|
|
|
110
192
|
|
|
111
193
|
type ResolveSdkOptionsConfig = {
|
|
112
194
|
customSuffix: string;
|
|
113
|
-
}
|
|
195
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue-storefront/nuxt",
|
|
3
|
-
"version": "9.0.0-rc.
|
|
3
|
+
"version": "9.0.0-rc.6",
|
|
4
4
|
"description": "Alokai dedicated features for Nuxt",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"pinia": "^2.1.7"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@alokai/connect": "^1.0.0-rc.
|
|
36
|
+
"@alokai/connect": "^1.0.0-rc.4",
|
|
37
37
|
"@types/node": "^18.11.17",
|
|
38
38
|
"@nuxt/devtools": "1.3.8",
|
|
39
39
|
"@nuxt/module-builder": "0.7.1",
|
|
40
40
|
"nuxt": "3.12.2"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@alokai/connect": "^1.0.0-rc.
|
|
43
|
+
"@alokai/connect": "^1.0.0-rc.4"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|