@vue-storefront/next 6.0.0-rc.4 → 6.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/dist/client.d.mts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/index.d.mts +71 -30
- package/dist/index.d.ts +71 -30
- package/dist/index.js +18 -6
- package/dist/index.mjs +16 -5
- package/dist/{types-BCNzbTr2.d.mts → types-B9h_AU7R.d.mts} +7 -25
- package/dist/{types-BCNzbTr2.d.ts → types-B9h_AU7R.d.ts} +7 -25
- package/package.json +3 -3
package/dist/client.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SDKApi } from '@alokai/connect/sdk';
|
|
2
|
-
import { S as SfContract, C as CreateSdkContextReturn } from './types-
|
|
3
|
-
export { M as Maybe, b as SfState, a as SfStateProps, c as createSfStateProvider } from './types-
|
|
2
|
+
import { S as SfContract, C as CreateSdkContextReturn } from './types-B9h_AU7R.mjs';
|
|
3
|
+
export { M as Maybe, b as SfState, a as SfStateProps, c as createSfStateProvider } from './types-B9h_AU7R.mjs';
|
|
4
4
|
import 'next/headers';
|
|
5
5
|
import 'react';
|
|
6
6
|
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SDKApi } from '@alokai/connect/sdk';
|
|
2
|
-
import { S as SfContract, C as CreateSdkContextReturn } from './types-
|
|
3
|
-
export { M as Maybe, b as SfState, a as SfStateProps, c as createSfStateProvider } from './types-
|
|
2
|
+
import { S as SfContract, C as CreateSdkContextReturn } from './types-B9h_AU7R.js';
|
|
3
|
+
export { M as Maybe, b as SfState, a as SfStateProps, c as createSfStateProvider } from './types-B9h_AU7R.js';
|
|
4
4
|
import 'next/headers';
|
|
5
5
|
import 'react';
|
|
6
6
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as _alokai_connect_logger from '@alokai/connect/logger';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { buildModule } from '@alokai/connect/sdk';
|
|
4
|
+
export { defineGetConfigSwitcherHeader } from '@alokai/connect/sdk';
|
|
5
|
+
import { d as CreateSdkOptions, e as Config, f as CreateSdkReturn, I as InjectedContext } from './types-B9h_AU7R.mjs';
|
|
5
6
|
import 'next/headers';
|
|
6
7
|
import 'react';
|
|
7
8
|
|
|
@@ -32,24 +33,6 @@ type NextMiddleware = (request: NextRequest) => NextResponse | Promise<NextRespo
|
|
|
32
33
|
* @returns A wrapped middleware function that adds pathname to request headers
|
|
33
34
|
*/
|
|
34
35
|
declare function createAlokaiMiddleware(middleware: NextMiddleware): (request: NextRequest) => NextResponse<unknown> | Promise<NextResponse<unknown>>;
|
|
35
|
-
/**
|
|
36
|
-
* Retrieves the pathname from the request headers.
|
|
37
|
-
* This function requires the `createAlokaiMiddleware` to be used in the middleware.ts file.
|
|
38
|
-
*
|
|
39
|
-
* @note This function is available only on the server side.
|
|
40
|
-
* @note This function will return undefined for all non-matching requests https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
|
|
41
|
-
*
|
|
42
|
-
* @param headers - The request headers
|
|
43
|
-
* @returns The pathname from the request headers
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* import headers from "next/headers";
|
|
48
|
-
*
|
|
49
|
-
* const pathname = getPathnameFromRequestHeaders(headers());
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
declare function getPathnameFromRequestHeaders(headers: Record<string, string | string[] | undefined>): string | undefined;
|
|
53
36
|
|
|
54
37
|
/**
|
|
55
38
|
* Creates an SDK for the given configuration definition.
|
|
@@ -96,29 +79,59 @@ declare function getPathnameFromRequestHeaders(headers: Record<string, string |
|
|
|
96
79
|
declare function createSdk<TConfig extends Record<string, any>>(options: CreateSdkOptions, configDefinition: Config<TConfig>): CreateSdkReturn<TConfig>;
|
|
97
80
|
/**
|
|
98
81
|
* Creates a configuration definition for the SDK.
|
|
99
|
-
* @param config The configuration definition for the SDK
|
|
82
|
+
* @param config The configuration definition for the SDK or a record of SDK modules
|
|
100
83
|
* @returns An object containing SDK configuration
|
|
101
84
|
* @example
|
|
85
|
+
* Using a function:
|
|
102
86
|
* ```tsx
|
|
87
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
88
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
89
|
+
*
|
|
103
90
|
* const config = defineSdkConfig(
|
|
104
91
|
* ({ buildModule, middlewareModule, config, getRequestHeaders }) => ({
|
|
105
|
-
* unified: buildModule(middlewareModule<
|
|
106
|
-
* apiUrl: config.apiUrl
|
|
107
|
-
* ssrApiUrl: config.ssrApiUrl
|
|
92
|
+
* unified: buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
93
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
94
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
108
95
|
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
109
96
|
* defaultRequestConfig: {
|
|
97
|
+
* getConfigSwitcherHeader,
|
|
110
98
|
* headers: getRequestHeaders(),
|
|
111
99
|
* },
|
|
112
100
|
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
113
101
|
* }),
|
|
114
|
-
*
|
|
115
|
-
* apiUrl: config.apiUrl + "/cntf",
|
|
116
|
-
* ssrApiUrl: config.ssrApiUrl + "/cntf",
|
|
117
|
-
* }),
|
|
118
|
-
* })
|
|
102
|
+
* }),
|
|
119
103
|
* );
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* Using a record of modules:
|
|
108
|
+
* ```tsx
|
|
109
|
+
* import { defineSdkModule } from '@vue-storefront/next';
|
|
110
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
111
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
112
|
+
*
|
|
113
|
+
* const unified = defineSdkModule(({ buildModule, config, getRequestHeaders, middlewareModule }) =>
|
|
114
|
+
* buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
115
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
116
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
117
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
118
|
+
* defaultRequestConfig: {
|
|
119
|
+
* getConfigSwitcherHeader,
|
|
120
|
+
* headers: getRequestHeaders(),
|
|
121
|
+
* },
|
|
122
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
123
|
+
* }),
|
|
124
|
+
* );
|
|
125
|
+
*
|
|
126
|
+
* const config = defineSdkConfig({
|
|
127
|
+
* unified,
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
120
130
|
*/
|
|
121
131
|
declare function defineSdkConfig<TConfig extends Record<string, any>>(config: Config<TConfig>): Config<TConfig>;
|
|
132
|
+
declare function defineSdkConfig<TModules extends Record<string, DefineSdkModule>>(modules: TModules): (context: InjectedContext) => {
|
|
133
|
+
[K in keyof TModules]: ReturnType<TModules[K]>;
|
|
134
|
+
};
|
|
122
135
|
type ResolveSdkOptionsConfig = {
|
|
123
136
|
customSuffix: string;
|
|
124
137
|
};
|
|
@@ -135,5 +148,33 @@ type ResolveSdkOptionsConfig = {
|
|
|
135
148
|
* @returns The resolved SDK options.
|
|
136
149
|
*/
|
|
137
150
|
declare function resolveSdkOptions(input: CreateSdkOptions, _options?: Partial<ResolveSdkOptionsConfig>): CreateSdkOptions;
|
|
151
|
+
type DefineSdkModule = (context: InjectedContext) => ReturnType<typeof buildModule>;
|
|
152
|
+
/**
|
|
153
|
+
* Defines an SDK module that can be used with defineSdkConfig.
|
|
154
|
+
* Each module is a function that takes the InjectedContext and returns a built module.
|
|
155
|
+
*
|
|
156
|
+
* @param moduleDefinition - A function that takes InjectedContext and returns a built module
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```tsx
|
|
160
|
+
* import { defineSdkModule } from '@vue-storefront/next';
|
|
161
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
162
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
163
|
+
*
|
|
164
|
+
* export const unified = defineSdkModule(({ buildModule, config, getRequestHeaders, middlewareModule }) =>
|
|
165
|
+
* buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
166
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
167
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
168
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
169
|
+
* defaultRequestConfig: {
|
|
170
|
+
* getConfigSwitcherHeader,
|
|
171
|
+
* headers: getRequestHeaders(),
|
|
172
|
+
* },
|
|
173
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
174
|
+
* }),
|
|
175
|
+
* );
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
declare function defineSdkModule<TModuleDefinition extends DefineSdkModule>(moduleDefinition: TModuleDefinition): TModuleDefinition;
|
|
138
179
|
|
|
139
|
-
export { CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineSdkConfig,
|
|
180
|
+
export { CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineSdkConfig, defineSdkModule, resolveSdkOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as _alokai_connect_logger from '@alokai/connect/logger';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { buildModule } from '@alokai/connect/sdk';
|
|
4
|
+
export { defineGetConfigSwitcherHeader } from '@alokai/connect/sdk';
|
|
5
|
+
import { d as CreateSdkOptions, e as Config, f as CreateSdkReturn, I as InjectedContext } from './types-B9h_AU7R.js';
|
|
5
6
|
import 'next/headers';
|
|
6
7
|
import 'react';
|
|
7
8
|
|
|
@@ -32,24 +33,6 @@ type NextMiddleware = (request: NextRequest) => NextResponse | Promise<NextRespo
|
|
|
32
33
|
* @returns A wrapped middleware function that adds pathname to request headers
|
|
33
34
|
*/
|
|
34
35
|
declare function createAlokaiMiddleware(middleware: NextMiddleware): (request: NextRequest) => NextResponse<unknown> | Promise<NextResponse<unknown>>;
|
|
35
|
-
/**
|
|
36
|
-
* Retrieves the pathname from the request headers.
|
|
37
|
-
* This function requires the `createAlokaiMiddleware` to be used in the middleware.ts file.
|
|
38
|
-
*
|
|
39
|
-
* @note This function is available only on the server side.
|
|
40
|
-
* @note This function will return undefined for all non-matching requests https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
|
|
41
|
-
*
|
|
42
|
-
* @param headers - The request headers
|
|
43
|
-
* @returns The pathname from the request headers
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```ts
|
|
47
|
-
* import headers from "next/headers";
|
|
48
|
-
*
|
|
49
|
-
* const pathname = getPathnameFromRequestHeaders(headers());
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
declare function getPathnameFromRequestHeaders(headers: Record<string, string | string[] | undefined>): string | undefined;
|
|
53
36
|
|
|
54
37
|
/**
|
|
55
38
|
* Creates an SDK for the given configuration definition.
|
|
@@ -96,29 +79,59 @@ declare function getPathnameFromRequestHeaders(headers: Record<string, string |
|
|
|
96
79
|
declare function createSdk<TConfig extends Record<string, any>>(options: CreateSdkOptions, configDefinition: Config<TConfig>): CreateSdkReturn<TConfig>;
|
|
97
80
|
/**
|
|
98
81
|
* Creates a configuration definition for the SDK.
|
|
99
|
-
* @param config The configuration definition for the SDK
|
|
82
|
+
* @param config The configuration definition for the SDK or a record of SDK modules
|
|
100
83
|
* @returns An object containing SDK configuration
|
|
101
84
|
* @example
|
|
85
|
+
* Using a function:
|
|
102
86
|
* ```tsx
|
|
87
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
88
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
89
|
+
*
|
|
103
90
|
* const config = defineSdkConfig(
|
|
104
91
|
* ({ buildModule, middlewareModule, config, getRequestHeaders }) => ({
|
|
105
|
-
* unified: buildModule(middlewareModule<
|
|
106
|
-
* apiUrl: config.apiUrl
|
|
107
|
-
* ssrApiUrl: config.ssrApiUrl
|
|
92
|
+
* unified: buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
93
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
94
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
108
95
|
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
109
96
|
* defaultRequestConfig: {
|
|
97
|
+
* getConfigSwitcherHeader,
|
|
110
98
|
* headers: getRequestHeaders(),
|
|
111
99
|
* },
|
|
112
100
|
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
113
101
|
* }),
|
|
114
|
-
*
|
|
115
|
-
* apiUrl: config.apiUrl + "/cntf",
|
|
116
|
-
* ssrApiUrl: config.ssrApiUrl + "/cntf",
|
|
117
|
-
* }),
|
|
118
|
-
* })
|
|
102
|
+
* }),
|
|
119
103
|
* );
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* Using a record of modules:
|
|
108
|
+
* ```tsx
|
|
109
|
+
* import { defineSdkModule } from '@vue-storefront/next';
|
|
110
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
111
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
112
|
+
*
|
|
113
|
+
* const unified = defineSdkModule(({ buildModule, config, getRequestHeaders, middlewareModule }) =>
|
|
114
|
+
* buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
115
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
116
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
117
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
118
|
+
* defaultRequestConfig: {
|
|
119
|
+
* getConfigSwitcherHeader,
|
|
120
|
+
* headers: getRequestHeaders(),
|
|
121
|
+
* },
|
|
122
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
123
|
+
* }),
|
|
124
|
+
* );
|
|
125
|
+
*
|
|
126
|
+
* const config = defineSdkConfig({
|
|
127
|
+
* unified,
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
120
130
|
*/
|
|
121
131
|
declare function defineSdkConfig<TConfig extends Record<string, any>>(config: Config<TConfig>): Config<TConfig>;
|
|
132
|
+
declare function defineSdkConfig<TModules extends Record<string, DefineSdkModule>>(modules: TModules): (context: InjectedContext) => {
|
|
133
|
+
[K in keyof TModules]: ReturnType<TModules[K]>;
|
|
134
|
+
};
|
|
122
135
|
type ResolveSdkOptionsConfig = {
|
|
123
136
|
customSuffix: string;
|
|
124
137
|
};
|
|
@@ -135,5 +148,33 @@ type ResolveSdkOptionsConfig = {
|
|
|
135
148
|
* @returns The resolved SDK options.
|
|
136
149
|
*/
|
|
137
150
|
declare function resolveSdkOptions(input: CreateSdkOptions, _options?: Partial<ResolveSdkOptionsConfig>): CreateSdkOptions;
|
|
151
|
+
type DefineSdkModule = (context: InjectedContext) => ReturnType<typeof buildModule>;
|
|
152
|
+
/**
|
|
153
|
+
* Defines an SDK module that can be used with defineSdkConfig.
|
|
154
|
+
* Each module is a function that takes the InjectedContext and returns a built module.
|
|
155
|
+
*
|
|
156
|
+
* @param moduleDefinition - A function that takes InjectedContext and returns a built module
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```tsx
|
|
160
|
+
* import { defineSdkModule } from '@vue-storefront/next';
|
|
161
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
162
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
163
|
+
*
|
|
164
|
+
* export const unified = defineSdkModule(({ buildModule, config, getRequestHeaders, middlewareModule }) =>
|
|
165
|
+
* buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
166
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
167
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
168
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
169
|
+
* defaultRequestConfig: {
|
|
170
|
+
* getConfigSwitcherHeader,
|
|
171
|
+
* headers: getRequestHeaders(),
|
|
172
|
+
* },
|
|
173
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
174
|
+
* }),
|
|
175
|
+
* );
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
declare function defineSdkModule<TModuleDefinition extends DefineSdkModule>(moduleDefinition: TModuleDefinition): TModuleDefinition;
|
|
138
179
|
|
|
139
|
-
export { CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineSdkConfig,
|
|
180
|
+
export { CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineSdkConfig, defineSdkModule, resolveSdkOptions };
|
package/dist/index.js
CHANGED
|
@@ -40,8 +40,9 @@ __export(src_exports, {
|
|
|
40
40
|
createAlokaiMiddleware: () => createAlokaiMiddleware,
|
|
41
41
|
createLogger: () => createLogger,
|
|
42
42
|
createSdk: () => createSdk,
|
|
43
|
+
defineGetConfigSwitcherHeader: () => import_sdk2.defineGetConfigSwitcherHeader,
|
|
43
44
|
defineSdkConfig: () => defineSdkConfig,
|
|
44
|
-
|
|
45
|
+
defineSdkModule: () => defineSdkModule,
|
|
45
46
|
resolveSdkOptions: () => resolveSdkOptions
|
|
46
47
|
});
|
|
47
48
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -80,12 +81,10 @@ function createAlokaiMiddleware(middleware) {
|
|
|
80
81
|
return (request) => {
|
|
81
82
|
const nextUrl = request.nextUrl.clone();
|
|
82
83
|
request.headers.append("x-pathname", nextUrl.pathname);
|
|
84
|
+
request.headers.append("x-search", nextUrl.search);
|
|
83
85
|
return middleware(request);
|
|
84
86
|
};
|
|
85
87
|
}
|
|
86
|
-
function getPathnameFromRequestHeaders(headers) {
|
|
87
|
-
return headers["x-pathname"];
|
|
88
|
-
}
|
|
89
88
|
|
|
90
89
|
// src/sdk/index.tsx
|
|
91
90
|
var import_sdk = require("@alokai/connect/sdk");
|
|
@@ -151,6 +150,7 @@ function resolveDynamicContext(context) {
|
|
|
151
150
|
}
|
|
152
151
|
|
|
153
152
|
// src/sdk/index.tsx
|
|
153
|
+
var import_sdk2 = require("@alokai/connect/sdk");
|
|
154
154
|
function createSdk(options, configDefinition) {
|
|
155
155
|
function getSdk(dynamicContext = {}) {
|
|
156
156
|
var _a;
|
|
@@ -174,17 +174,29 @@ function createSdk(options, configDefinition) {
|
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
function defineSdkConfig(config) {
|
|
177
|
-
|
|
177
|
+
if (typeof config === "function") {
|
|
178
|
+
return config;
|
|
179
|
+
}
|
|
180
|
+
return buildModules(config);
|
|
178
181
|
}
|
|
179
182
|
function resolveSdkOptions(input, _options = {}) {
|
|
180
183
|
return input;
|
|
181
184
|
}
|
|
185
|
+
function defineSdkModule(moduleDefinition) {
|
|
186
|
+
return moduleDefinition;
|
|
187
|
+
}
|
|
188
|
+
function buildModules(modules) {
|
|
189
|
+
return (context) => Object.fromEntries(
|
|
190
|
+
Object.entries(modules).map(([key, module2]) => [key, module2(context)])
|
|
191
|
+
);
|
|
192
|
+
}
|
|
182
193
|
// Annotate the CommonJS export names for ESM import in node:
|
|
183
194
|
0 && (module.exports = {
|
|
184
195
|
createAlokaiMiddleware,
|
|
185
196
|
createLogger,
|
|
186
197
|
createSdk,
|
|
198
|
+
defineGetConfigSwitcherHeader,
|
|
187
199
|
defineSdkConfig,
|
|
188
|
-
|
|
200
|
+
defineSdkModule,
|
|
189
201
|
resolveSdkOptions
|
|
190
202
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -37,12 +37,10 @@ function createAlokaiMiddleware(middleware) {
|
|
|
37
37
|
return (request) => {
|
|
38
38
|
const nextUrl = request.nextUrl.clone();
|
|
39
39
|
request.headers.append("x-pathname", nextUrl.pathname);
|
|
40
|
+
request.headers.append("x-search", nextUrl.search);
|
|
40
41
|
return middleware(request);
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
|
-
function getPathnameFromRequestHeaders(headers) {
|
|
44
|
-
return headers["x-pathname"];
|
|
45
|
-
}
|
|
46
44
|
|
|
47
45
|
// src/sdk/index.tsx
|
|
48
46
|
import { buildModule, initSDK, middlewareModule } from "@alokai/connect/sdk";
|
|
@@ -108,6 +106,7 @@ function resolveDynamicContext(context) {
|
|
|
108
106
|
}
|
|
109
107
|
|
|
110
108
|
// src/sdk/index.tsx
|
|
109
|
+
import { defineGetConfigSwitcherHeader } from "@alokai/connect/sdk";
|
|
111
110
|
function createSdk(options, configDefinition) {
|
|
112
111
|
function getSdk(dynamicContext = {}) {
|
|
113
112
|
var _a;
|
|
@@ -131,16 +130,28 @@ function createSdk(options, configDefinition) {
|
|
|
131
130
|
};
|
|
132
131
|
}
|
|
133
132
|
function defineSdkConfig(config) {
|
|
134
|
-
|
|
133
|
+
if (typeof config === "function") {
|
|
134
|
+
return config;
|
|
135
|
+
}
|
|
136
|
+
return buildModules(config);
|
|
135
137
|
}
|
|
136
138
|
function resolveSdkOptions(input, _options = {}) {
|
|
137
139
|
return input;
|
|
138
140
|
}
|
|
141
|
+
function defineSdkModule(moduleDefinition) {
|
|
142
|
+
return moduleDefinition;
|
|
143
|
+
}
|
|
144
|
+
function buildModules(modules) {
|
|
145
|
+
return (context) => Object.fromEntries(
|
|
146
|
+
Object.entries(modules).map(([key, module]) => [key, module(context)])
|
|
147
|
+
);
|
|
148
|
+
}
|
|
139
149
|
export {
|
|
140
150
|
createAlokaiMiddleware,
|
|
141
151
|
createLogger,
|
|
142
152
|
createSdk,
|
|
153
|
+
defineGetConfigSwitcherHeader,
|
|
143
154
|
defineSdkConfig,
|
|
144
|
-
|
|
155
|
+
defineSdkModule,
|
|
145
156
|
resolveSdkOptions
|
|
146
157
|
};
|
|
@@ -30,30 +30,12 @@ declare function createSfStateProvider<TSfContract extends SfContract>(): {
|
|
|
30
30
|
SfStateProvider: ({ children, initialData, }: {
|
|
31
31
|
initialData: SfStateProps<TSfContract>;
|
|
32
32
|
} & PropsWithChildren) => React.JSX.Element;
|
|
33
|
-
useSfCartState: () => [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
(currencies: TSfContract["SfCurrency"][]) => void
|
|
40
|
-
];
|
|
41
|
-
useSfCurrencyState: () => [
|
|
42
|
-
TSfContract["SfCurrency"],
|
|
43
|
-
(currency: TSfContract["SfCurrency"]) => void
|
|
44
|
-
];
|
|
45
|
-
useSfCustomerState: () => [
|
|
46
|
-
null | TSfContract["SfCustomer"] | undefined,
|
|
47
|
-
(customer?: null | TSfContract["SfCustomer"]) => void
|
|
48
|
-
];
|
|
49
|
-
useSfLocalesState: () => [
|
|
50
|
-
TSfContract["SfLocale"][],
|
|
51
|
-
(locales: TSfContract["SfLocale"][]) => void
|
|
52
|
-
];
|
|
53
|
-
useSfLocaleState: () => [
|
|
54
|
-
TSfContract["SfLocale"],
|
|
55
|
-
(locale: TSfContract["SfLocale"]) => void
|
|
56
|
-
];
|
|
33
|
+
useSfCartState: () => [null | TSfContract["SfCart"] | undefined, (cart?: null | TSfContract["SfCart"]) => void];
|
|
34
|
+
useSfCurrenciesState: () => [TSfContract["SfCurrency"][], (currencies: TSfContract["SfCurrency"][]) => void];
|
|
35
|
+
useSfCurrencyState: () => [TSfContract["SfCurrency"], (currency: TSfContract["SfCurrency"]) => void];
|
|
36
|
+
useSfCustomerState: () => [null | TSfContract["SfCustomer"] | undefined, (customer?: null | TSfContract["SfCustomer"]) => void];
|
|
37
|
+
useSfLocalesState: () => [TSfContract["SfLocale"][], (locales: TSfContract["SfLocale"][]) => void];
|
|
38
|
+
useSfLocaleState: () => [TSfContract["SfLocale"], (locale: TSfContract["SfLocale"]) => void];
|
|
57
39
|
};
|
|
58
40
|
|
|
59
41
|
declare const defaultMethodsRequestConfig: {
|
|
@@ -224,4 +206,4 @@ type CreateSdkContextReturn<TSdk extends SDKApi<any>, TSfContract extends SfCont
|
|
|
224
206
|
useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
|
|
225
207
|
}>;
|
|
226
208
|
|
|
227
|
-
export { type CreateSdkContextReturn as C, type Maybe as M, type SfContract as S, type SfStateProps as a, type SfState as b, createSfStateProvider as c, type CreateSdkOptions as d, type Config as e, type CreateSdkReturn as f };
|
|
209
|
+
export { type CreateSdkContextReturn as C, type InjectedContext as I, type Maybe as M, type SfContract as S, type SfStateProps as a, type SfState as b, createSfStateProvider as c, type CreateSdkOptions as d, type Config as e, type CreateSdkReturn as f };
|
|
@@ -30,30 +30,12 @@ declare function createSfStateProvider<TSfContract extends SfContract>(): {
|
|
|
30
30
|
SfStateProvider: ({ children, initialData, }: {
|
|
31
31
|
initialData: SfStateProps<TSfContract>;
|
|
32
32
|
} & PropsWithChildren) => React.JSX.Element;
|
|
33
|
-
useSfCartState: () => [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
];
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
(currencies: TSfContract["SfCurrency"][]) => void
|
|
40
|
-
];
|
|
41
|
-
useSfCurrencyState: () => [
|
|
42
|
-
TSfContract["SfCurrency"],
|
|
43
|
-
(currency: TSfContract["SfCurrency"]) => void
|
|
44
|
-
];
|
|
45
|
-
useSfCustomerState: () => [
|
|
46
|
-
null | TSfContract["SfCustomer"] | undefined,
|
|
47
|
-
(customer?: null | TSfContract["SfCustomer"]) => void
|
|
48
|
-
];
|
|
49
|
-
useSfLocalesState: () => [
|
|
50
|
-
TSfContract["SfLocale"][],
|
|
51
|
-
(locales: TSfContract["SfLocale"][]) => void
|
|
52
|
-
];
|
|
53
|
-
useSfLocaleState: () => [
|
|
54
|
-
TSfContract["SfLocale"],
|
|
55
|
-
(locale: TSfContract["SfLocale"]) => void
|
|
56
|
-
];
|
|
33
|
+
useSfCartState: () => [null | TSfContract["SfCart"] | undefined, (cart?: null | TSfContract["SfCart"]) => void];
|
|
34
|
+
useSfCurrenciesState: () => [TSfContract["SfCurrency"][], (currencies: TSfContract["SfCurrency"][]) => void];
|
|
35
|
+
useSfCurrencyState: () => [TSfContract["SfCurrency"], (currency: TSfContract["SfCurrency"]) => void];
|
|
36
|
+
useSfCustomerState: () => [null | TSfContract["SfCustomer"] | undefined, (customer?: null | TSfContract["SfCustomer"]) => void];
|
|
37
|
+
useSfLocalesState: () => [TSfContract["SfLocale"][], (locales: TSfContract["SfLocale"][]) => void];
|
|
38
|
+
useSfLocaleState: () => [TSfContract["SfLocale"], (locale: TSfContract["SfLocale"]) => void];
|
|
57
39
|
};
|
|
58
40
|
|
|
59
41
|
declare const defaultMethodsRequestConfig: {
|
|
@@ -224,4 +206,4 @@ type CreateSdkContextReturn<TSdk extends SDKApi<any>, TSfContract extends SfCont
|
|
|
224
206
|
useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
|
|
225
207
|
}>;
|
|
226
208
|
|
|
227
|
-
export { type CreateSdkContextReturn as C, type Maybe as M, type SfContract as S, type SfStateProps as a, type SfState as b, createSfStateProvider as c, type CreateSdkOptions as d, type Config as e, type CreateSdkReturn as f };
|
|
209
|
+
export { type CreateSdkContextReturn as C, type InjectedContext as I, type Maybe as M, type SfContract as S, type SfStateProps as a, type SfState as b, createSfStateProvider as c, type CreateSdkOptions as d, type Config as e, type CreateSdkReturn as f };
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@vue-storefront/next",
|
|
3
3
|
"description": "Alokai dedicated features for Next.js",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "6.0.0
|
|
5
|
+
"version": "6.0.0",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"zustand": "^4.5.4"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@alokai/connect": "^1.0.0
|
|
33
|
+
"@alokai/connect": "^1.0.0",
|
|
34
34
|
"@types/react": "18.3.2",
|
|
35
35
|
"@types/react-dom": "18.3.0",
|
|
36
36
|
"react-dom": "18.3.1",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"next": "14.2.25"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@alokai/connect": "^1.0.0
|
|
44
|
+
"@alokai/connect": "^1.0.0",
|
|
45
45
|
"react": "^18.2.0",
|
|
46
46
|
"next": "^13.4.7 || ^14.0.0"
|
|
47
47
|
},
|