@vue-storefront/next 6.0.0-rc.3 → 6.0.0-rc.5
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/client.d.mts +3 -3
- package/dist/client.d.ts +3 -3
- package/dist/client.js +7 -7
- package/dist/client.mjs +7 -7
- package/dist/index.d.mts +101 -21
- package/dist/index.d.ts +101 -21
- package/dist/index.js +95 -61
- package/dist/index.mjs +92 -61
- package/dist/{types-C90MV4A8.d.mts → types-glZZCnsn.d.mts} +92 -85
- package/dist/{types-C90MV4A8.d.ts → types-glZZCnsn.d.ts} +92 -85
- package/package.json +6 -5
package/README.md
CHANGED
package/dist/client.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SDKApi } from '@alokai/connect/sdk';
|
|
2
|
-
import { S as SfContract,
|
|
3
|
-
export { M as Maybe,
|
|
4
|
-
import 'react';
|
|
2
|
+
import { S as SfContract, C as CreateSdkContextReturn } from './types-glZZCnsn.mjs';
|
|
3
|
+
export { M as Maybe, b as SfState, a as SfStateProps, c as createSfStateProvider } from './types-glZZCnsn.mjs';
|
|
5
4
|
import 'next/headers';
|
|
5
|
+
import 'react';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Creates a new Alokai context which is a combination of SDK and state contexts.
|
package/dist/client.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SDKApi } from '@alokai/connect/sdk';
|
|
2
|
-
import { S as SfContract,
|
|
3
|
-
export { M as Maybe,
|
|
4
|
-
import 'react';
|
|
2
|
+
import { S as SfContract, C as CreateSdkContextReturn } from './types-glZZCnsn.js';
|
|
3
|
+
export { M as Maybe, b as SfState, a as SfStateProps, c as createSfStateProvider } from './types-glZZCnsn.js';
|
|
5
4
|
import 'next/headers';
|
|
5
|
+
import 'react';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Creates a new Alokai context which is a combination of SDK and state contexts.
|
package/dist/client.js
CHANGED
|
@@ -156,12 +156,12 @@ function createSfStateProvider() {
|
|
|
156
156
|
}
|
|
157
157
|
return {
|
|
158
158
|
SfStateProvider,
|
|
159
|
-
|
|
159
|
+
useSfCartState,
|
|
160
160
|
useSfCurrenciesState,
|
|
161
|
-
|
|
161
|
+
useSfCurrencyState,
|
|
162
|
+
useSfCustomerState,
|
|
162
163
|
useSfLocalesState,
|
|
163
|
-
|
|
164
|
-
useSfCustomerState
|
|
164
|
+
useSfLocaleState
|
|
165
165
|
};
|
|
166
166
|
}
|
|
167
167
|
|
|
@@ -171,10 +171,10 @@ function createAlokaiContext() {
|
|
|
171
171
|
const _a = createSfStateProvider(), { SfStateProvider } = _a, rest = __objRest(_a, ["SfStateProvider"]);
|
|
172
172
|
function AlokaiProvider({
|
|
173
173
|
children,
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
initialData,
|
|
175
|
+
sdk
|
|
176
176
|
}) {
|
|
177
|
-
return /* @__PURE__ */ import_react2.default.createElement(SdkContext.Provider, { value: sdk }, /* @__PURE__ */ import_react2.default.createElement(import_script.default, {
|
|
177
|
+
return /* @__PURE__ */ import_react2.default.createElement(SdkContext.Provider, { value: sdk }, /* @__PURE__ */ import_react2.default.createElement(import_script.default, { id: "vsfMetaTag", strategy: "beforeInteractive" }, `
|
|
178
178
|
const vsfMetaTag = document.createElement("meta");
|
|
179
179
|
vsfMetaTag.setAttribute("name", "generator");
|
|
180
180
|
vsfMetaTag.setAttribute("content", "Alokai Storefront");
|
package/dist/client.mjs
CHANGED
|
@@ -100,12 +100,12 @@ function createSfStateProvider() {
|
|
|
100
100
|
}
|
|
101
101
|
return {
|
|
102
102
|
SfStateProvider,
|
|
103
|
-
|
|
103
|
+
useSfCartState,
|
|
104
104
|
useSfCurrenciesState,
|
|
105
|
-
|
|
105
|
+
useSfCurrencyState,
|
|
106
|
+
useSfCustomerState,
|
|
106
107
|
useSfLocalesState,
|
|
107
|
-
|
|
108
|
-
useSfCustomerState
|
|
108
|
+
useSfLocaleState
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
|
|
@@ -115,10 +115,10 @@ function createAlokaiContext() {
|
|
|
115
115
|
const _a = createSfStateProvider(), { SfStateProvider } = _a, rest = __objRest(_a, ["SfStateProvider"]);
|
|
116
116
|
function AlokaiProvider({
|
|
117
117
|
children,
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
initialData,
|
|
119
|
+
sdk
|
|
120
120
|
}) {
|
|
121
|
-
return /* @__PURE__ */ React2.createElement(SdkContext.Provider, { value: sdk }, /* @__PURE__ */ React2.createElement(Script, {
|
|
121
|
+
return /* @__PURE__ */ React2.createElement(SdkContext.Provider, { value: sdk }, /* @__PURE__ */ React2.createElement(Script, { id: "vsfMetaTag", strategy: "beforeInteractive" }, `
|
|
122
122
|
const vsfMetaTag = document.createElement("meta");
|
|
123
123
|
vsfMetaTag.setAttribute("name", "generator");
|
|
124
124
|
vsfMetaTag.setAttribute("content", "Alokai Storefront");
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,38 @@
|
|
|
1
|
-
import { C as CreateSdkOptions, a as Config, b as CreateSdkReturn } from './types-C90MV4A8.mjs';
|
|
2
1
|
import * as _alokai_connect_logger from '@alokai/connect/logger';
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
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-glZZCnsn.mjs';
|
|
5
6
|
import 'next/headers';
|
|
7
|
+
import 'react';
|
|
8
|
+
|
|
9
|
+
type LogVerbosity = "alert" | "critical" | "debug" | "emergency" | "error" | "info" | "notice" | "warning";
|
|
10
|
+
type LoggerOptions = Partial<{
|
|
11
|
+
includeStackTrace: boolean;
|
|
12
|
+
verbosity: LogVerbosity;
|
|
13
|
+
}>;
|
|
14
|
+
|
|
15
|
+
declare const createLogger: (options?: LoggerOptions) => _alokai_connect_logger.LoggerInterface;
|
|
16
|
+
|
|
17
|
+
type NextMiddleware = (request: NextRequest) => NextResponse | Promise<NextResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an Alokai middleware wrapper that adds pathname information to request headers.
|
|
20
|
+
* This is required for proper pathname handling during SSR in Next.js.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* // middleware.ts
|
|
25
|
+
* import { createAlokaiMiddleware } from '@alokai/next';
|
|
26
|
+
*
|
|
27
|
+
* export default createAlokaiMiddleware((request) => {
|
|
28
|
+
* // Your middleware logic here
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param middleware - The Next.js middleware function to wrap
|
|
33
|
+
* @returns A wrapped middleware function that adds pathname to request headers
|
|
34
|
+
*/
|
|
35
|
+
declare function createAlokaiMiddleware(middleware: NextMiddleware): (request: NextRequest) => NextResponse<unknown> | Promise<NextResponse<unknown>>;
|
|
6
36
|
|
|
7
37
|
/**
|
|
8
38
|
* Creates an SDK for the given configuration definition.
|
|
@@ -49,29 +79,59 @@ import 'next/headers';
|
|
|
49
79
|
declare function createSdk<TConfig extends Record<string, any>>(options: CreateSdkOptions, configDefinition: Config<TConfig>): CreateSdkReturn<TConfig>;
|
|
50
80
|
/**
|
|
51
81
|
* Creates a configuration definition for the SDK.
|
|
52
|
-
* @param config The configuration definition for the SDK
|
|
82
|
+
* @param config The configuration definition for the SDK or a record of SDK modules
|
|
53
83
|
* @returns An object containing SDK configuration
|
|
54
84
|
* @example
|
|
85
|
+
* Using a function:
|
|
55
86
|
* ```tsx
|
|
87
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
88
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
89
|
+
*
|
|
56
90
|
* const config = defineSdkConfig(
|
|
57
91
|
* ({ buildModule, middlewareModule, config, getRequestHeaders }) => ({
|
|
58
|
-
* unified: buildModule(middlewareModule<
|
|
59
|
-
* apiUrl: config.apiUrl
|
|
60
|
-
* ssrApiUrl: config.ssrApiUrl
|
|
92
|
+
* unified: buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
93
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
94
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
61
95
|
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
62
96
|
* defaultRequestConfig: {
|
|
97
|
+
* getConfigSwitcherHeader,
|
|
63
98
|
* headers: getRequestHeaders(),
|
|
64
99
|
* },
|
|
65
100
|
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
66
101
|
* }),
|
|
67
|
-
*
|
|
68
|
-
* apiUrl: config.apiUrl + "/cntf",
|
|
69
|
-
* ssrApiUrl: config.ssrApiUrl + "/cntf",
|
|
70
|
-
* }),
|
|
71
|
-
* })
|
|
102
|
+
* }),
|
|
72
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
|
+
* ```
|
|
73
130
|
*/
|
|
74
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
|
+
};
|
|
75
135
|
type ResolveSdkOptionsConfig = {
|
|
76
136
|
customSuffix: string;
|
|
77
137
|
};
|
|
@@ -88,13 +148,33 @@ type ResolveSdkOptionsConfig = {
|
|
|
88
148
|
* @returns The resolved SDK options.
|
|
89
149
|
*/
|
|
90
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;
|
|
91
179
|
|
|
92
|
-
|
|
93
|
-
type LoggerOptions = Partial<{
|
|
94
|
-
verbosity: LogVerbosity;
|
|
95
|
-
includeStackTrace: boolean;
|
|
96
|
-
}>;
|
|
97
|
-
|
|
98
|
-
declare const createLogger: (options?: LoggerOptions) => _alokai_connect_logger.LoggerInterface;
|
|
99
|
-
|
|
100
|
-
export { CreateSdkOptions, createLogger, createSdk, defineSdkConfig, resolveSdkOptions };
|
|
180
|
+
export { CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineSdkConfig, defineSdkModule, resolveSdkOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,38 @@
|
|
|
1
|
-
import { C as CreateSdkOptions, a as Config, b as CreateSdkReturn } from './types-C90MV4A8.js';
|
|
2
1
|
import * as _alokai_connect_logger from '@alokai/connect/logger';
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
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-glZZCnsn.js';
|
|
5
6
|
import 'next/headers';
|
|
7
|
+
import 'react';
|
|
8
|
+
|
|
9
|
+
type LogVerbosity = "alert" | "critical" | "debug" | "emergency" | "error" | "info" | "notice" | "warning";
|
|
10
|
+
type LoggerOptions = Partial<{
|
|
11
|
+
includeStackTrace: boolean;
|
|
12
|
+
verbosity: LogVerbosity;
|
|
13
|
+
}>;
|
|
14
|
+
|
|
15
|
+
declare const createLogger: (options?: LoggerOptions) => _alokai_connect_logger.LoggerInterface;
|
|
16
|
+
|
|
17
|
+
type NextMiddleware = (request: NextRequest) => NextResponse | Promise<NextResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an Alokai middleware wrapper that adds pathname information to request headers.
|
|
20
|
+
* This is required for proper pathname handling during SSR in Next.js.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* // middleware.ts
|
|
25
|
+
* import { createAlokaiMiddleware } from '@alokai/next';
|
|
26
|
+
*
|
|
27
|
+
* export default createAlokaiMiddleware((request) => {
|
|
28
|
+
* // Your middleware logic here
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param middleware - The Next.js middleware function to wrap
|
|
33
|
+
* @returns A wrapped middleware function that adds pathname to request headers
|
|
34
|
+
*/
|
|
35
|
+
declare function createAlokaiMiddleware(middleware: NextMiddleware): (request: NextRequest) => NextResponse<unknown> | Promise<NextResponse<unknown>>;
|
|
6
36
|
|
|
7
37
|
/**
|
|
8
38
|
* Creates an SDK for the given configuration definition.
|
|
@@ -49,29 +79,59 @@ import 'next/headers';
|
|
|
49
79
|
declare function createSdk<TConfig extends Record<string, any>>(options: CreateSdkOptions, configDefinition: Config<TConfig>): CreateSdkReturn<TConfig>;
|
|
50
80
|
/**
|
|
51
81
|
* Creates a configuration definition for the SDK.
|
|
52
|
-
* @param config The configuration definition for the SDK
|
|
82
|
+
* @param config The configuration definition for the SDK or a record of SDK modules
|
|
53
83
|
* @returns An object containing SDK configuration
|
|
54
84
|
* @example
|
|
85
|
+
* Using a function:
|
|
55
86
|
* ```tsx
|
|
87
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
88
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
89
|
+
*
|
|
56
90
|
* const config = defineSdkConfig(
|
|
57
91
|
* ({ buildModule, middlewareModule, config, getRequestHeaders }) => ({
|
|
58
|
-
* unified: buildModule(middlewareModule<
|
|
59
|
-
* apiUrl: config.apiUrl
|
|
60
|
-
* ssrApiUrl: config.ssrApiUrl
|
|
92
|
+
* unified: buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
93
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
94
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
61
95
|
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
62
96
|
* defaultRequestConfig: {
|
|
97
|
+
* getConfigSwitcherHeader,
|
|
63
98
|
* headers: getRequestHeaders(),
|
|
64
99
|
* },
|
|
65
100
|
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
66
101
|
* }),
|
|
67
|
-
*
|
|
68
|
-
* apiUrl: config.apiUrl + "/cntf",
|
|
69
|
-
* ssrApiUrl: config.ssrApiUrl + "/cntf",
|
|
70
|
-
* }),
|
|
71
|
-
* })
|
|
102
|
+
* }),
|
|
72
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
|
+
* ```
|
|
73
130
|
*/
|
|
74
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
|
+
};
|
|
75
135
|
type ResolveSdkOptionsConfig = {
|
|
76
136
|
customSuffix: string;
|
|
77
137
|
};
|
|
@@ -88,13 +148,33 @@ type ResolveSdkOptionsConfig = {
|
|
|
88
148
|
* @returns The resolved SDK options.
|
|
89
149
|
*/
|
|
90
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;
|
|
91
179
|
|
|
92
|
-
|
|
93
|
-
type LoggerOptions = Partial<{
|
|
94
|
-
verbosity: LogVerbosity;
|
|
95
|
-
includeStackTrace: boolean;
|
|
96
|
-
}>;
|
|
97
|
-
|
|
98
|
-
declare const createLogger: (options?: LoggerOptions) => _alokai_connect_logger.LoggerInterface;
|
|
99
|
-
|
|
100
|
-
export { CreateSdkOptions, createLogger, createSdk, defineSdkConfig, resolveSdkOptions };
|
|
180
|
+
export { CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineSdkConfig, defineSdkModule, resolveSdkOptions };
|
package/dist/index.js
CHANGED
|
@@ -37,13 +37,79 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
37
37
|
// src/index.ts
|
|
38
38
|
var src_exports = {};
|
|
39
39
|
__export(src_exports, {
|
|
40
|
+
createAlokaiMiddleware: () => createAlokaiMiddleware,
|
|
40
41
|
createLogger: () => createLogger,
|
|
41
42
|
createSdk: () => createSdk,
|
|
43
|
+
defineGetConfigSwitcherHeader: () => import_sdk2.defineGetConfigSwitcherHeader,
|
|
42
44
|
defineSdkConfig: () => defineSdkConfig,
|
|
45
|
+
defineSdkModule: () => defineSdkModule,
|
|
43
46
|
resolveSdkOptions: () => resolveSdkOptions
|
|
44
47
|
});
|
|
45
48
|
module.exports = __toCommonJS(src_exports);
|
|
46
49
|
|
|
50
|
+
// src/logger/index.ts
|
|
51
|
+
var import_logger = require("@alokai/connect/logger");
|
|
52
|
+
|
|
53
|
+
// src/logger/injectMetadata.ts
|
|
54
|
+
function injectMetadata(logger, externalData) {
|
|
55
|
+
return new Proxy(logger, {
|
|
56
|
+
get(target, prop) {
|
|
57
|
+
const targetProp = target[prop];
|
|
58
|
+
if (typeof targetProp === "function") {
|
|
59
|
+
return (...args) => {
|
|
60
|
+
const [logData, metadata] = args;
|
|
61
|
+
targetProp(logData, __spreadValues(__spreadValues({}, metadata), externalData));
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return targetProp;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/logger/index.ts
|
|
70
|
+
var createLogger = (options) => {
|
|
71
|
+
const logger = import_logger.LoggerFactory.create(import_logger.LoggerType.ConsolaGcp, options);
|
|
72
|
+
return injectMetadata(logger, {
|
|
73
|
+
alokai: {
|
|
74
|
+
context: "storefront"
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/middleware.ts
|
|
80
|
+
function createAlokaiMiddleware(middleware) {
|
|
81
|
+
return (request) => {
|
|
82
|
+
const nextUrl = request.nextUrl.clone();
|
|
83
|
+
request.headers.append("x-pathname", nextUrl.pathname);
|
|
84
|
+
request.headers.append("x-search", nextUrl.search);
|
|
85
|
+
return middleware(request);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/sdk/index.tsx
|
|
90
|
+
var import_sdk = require("@alokai/connect/sdk");
|
|
91
|
+
|
|
92
|
+
// src/sdk/helpers/defaultConfigs.ts
|
|
93
|
+
var defaultMethodsRequestConfig = {
|
|
94
|
+
unifiedCms: {
|
|
95
|
+
middlewareModule: {
|
|
96
|
+
getEntries: { method: "GET" },
|
|
97
|
+
getPage: { method: "GET" }
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
unifiedCommerce: {
|
|
101
|
+
middlewareModule: {
|
|
102
|
+
getCategories: { method: "GET" },
|
|
103
|
+
getCategory: { method: "GET" },
|
|
104
|
+
getCurrencies: { method: "GET" },
|
|
105
|
+
getProductDetails: { method: "GET" },
|
|
106
|
+
getProductReviews: { method: "GET" },
|
|
107
|
+
getProducts: { method: "GET" },
|
|
108
|
+
searchProducts: { method: "GET" }
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
47
113
|
// src/sdk/helpers/resolveDynamicContext.ts
|
|
48
114
|
var BLACKLISTED_HEADERS = /* @__PURE__ */ new Set(["host"]);
|
|
49
115
|
function isAppRouterHeaders(headers) {
|
|
@@ -53,9 +119,9 @@ function isFlatNextHeaders(headers) {
|
|
|
53
119
|
return !!headers && !("headers" in headers);
|
|
54
120
|
}
|
|
55
121
|
function normalizeRequestHeaders(requestHeaders) {
|
|
56
|
-
const { headers = {}
|
|
57
|
-
|
|
58
|
-
|
|
122
|
+
const { cookies, headers = {} } = isFlatNextHeaders(requestHeaders) ? { cookies: void 0, headers: requestHeaders } : {
|
|
123
|
+
cookies: requestHeaders == null ? void 0 : requestHeaders.cookies,
|
|
124
|
+
headers: requestHeaders == null ? void 0 : requestHeaders.headers
|
|
59
125
|
};
|
|
60
126
|
const normalizedHeaders = isAppRouterHeaders(headers) ? Object.fromEntries(headers.entries()) : headers;
|
|
61
127
|
if (cookies) {
|
|
@@ -70,53 +136,36 @@ function resolveDynamicContext(context) {
|
|
|
70
136
|
const normalizedHeaders = normalizeRequestHeaders(
|
|
71
137
|
(_a = context.getRequestHeaders) == null ? void 0 : _a.call(context)
|
|
72
138
|
);
|
|
73
|
-
|
|
139
|
+
const requestHeaders = Object.fromEntries(
|
|
74
140
|
Object.entries(normalizedHeaders).filter(
|
|
75
141
|
([key]) => !BLACKLISTED_HEADERS.has(key)
|
|
76
142
|
)
|
|
77
143
|
);
|
|
144
|
+
if (context.getLocale) {
|
|
145
|
+
requestHeaders["x-alokai-locale"] = context.getLocale();
|
|
146
|
+
}
|
|
147
|
+
return requestHeaders;
|
|
78
148
|
}
|
|
79
149
|
});
|
|
80
150
|
}
|
|
81
151
|
|
|
82
|
-
// src/sdk/helpers/defaultConfigs.ts
|
|
83
|
-
var defaultMethodsRequestConfig = {
|
|
84
|
-
unifiedCommerce: {
|
|
85
|
-
middlewareModule: {
|
|
86
|
-
getCategory: { method: "GET" },
|
|
87
|
-
getCategories: { method: "GET" },
|
|
88
|
-
getProductDetails: { method: "GET" },
|
|
89
|
-
getProductReviews: { method: "GET" },
|
|
90
|
-
getProducts: { method: "GET" },
|
|
91
|
-
getCurrencies: { method: "GET" },
|
|
92
|
-
searchProducts: { method: "GET" }
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
unifiedCms: {
|
|
96
|
-
middlewareModule: {
|
|
97
|
-
getPage: { method: "GET" },
|
|
98
|
-
getEntries: { method: "GET" }
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
|
|
103
152
|
// src/sdk/index.tsx
|
|
104
|
-
var
|
|
153
|
+
var import_sdk2 = require("@alokai/connect/sdk");
|
|
105
154
|
function createSdk(options, configDefinition) {
|
|
106
155
|
function getSdk(dynamicContext = {}) {
|
|
107
156
|
var _a;
|
|
108
157
|
const { getRequestHeaders } = resolveDynamicContext(dynamicContext);
|
|
109
158
|
const resolvedConfig = configDefinition({
|
|
110
|
-
defaults: defaultMethodsRequestConfig,
|
|
111
159
|
buildModule: import_sdk.buildModule,
|
|
112
|
-
middlewareModule: import_sdk.middlewareModule,
|
|
113
|
-
getRequestHeaders,
|
|
114
160
|
config: {
|
|
115
161
|
apiUrl: options.middleware.apiUrl,
|
|
116
|
-
|
|
162
|
+
cdnCacheBustingId: (_a = options.middleware.cdnCacheBustingId) != null ? _a : "no-cache-busting-id-set",
|
|
117
163
|
defaultMethodsRequestConfig,
|
|
118
|
-
|
|
119
|
-
}
|
|
164
|
+
ssrApiUrl: options.middleware.ssrApiUrl
|
|
165
|
+
},
|
|
166
|
+
defaults: defaultMethodsRequestConfig,
|
|
167
|
+
getRequestHeaders,
|
|
168
|
+
middlewareModule: import_sdk.middlewareModule
|
|
120
169
|
});
|
|
121
170
|
return (0, import_sdk.initSDK)(resolvedConfig);
|
|
122
171
|
}
|
|
@@ -125,44 +174,29 @@ function createSdk(options, configDefinition) {
|
|
|
125
174
|
};
|
|
126
175
|
}
|
|
127
176
|
function defineSdkConfig(config) {
|
|
128
|
-
|
|
177
|
+
if (typeof config === "function") {
|
|
178
|
+
return config;
|
|
179
|
+
}
|
|
180
|
+
return buildModules(config);
|
|
129
181
|
}
|
|
130
182
|
function resolveSdkOptions(input, _options = {}) {
|
|
131
183
|
return input;
|
|
132
184
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
get(target, prop) {
|
|
141
|
-
const targetProp = target[prop];
|
|
142
|
-
if (typeof targetProp === "function") {
|
|
143
|
-
return (...args) => {
|
|
144
|
-
const [logData, metadata] = args;
|
|
145
|
-
targetProp(logData, __spreadValues(__spreadValues({}, metadata), externalData));
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
return targetProp;
|
|
149
|
-
}
|
|
150
|
-
});
|
|
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
|
+
);
|
|
151
192
|
}
|
|
152
|
-
|
|
153
|
-
// src/logger/index.ts
|
|
154
|
-
var createLogger = (options) => {
|
|
155
|
-
const logger = import_logger.LoggerFactory.create(import_logger.LoggerType.ConsolaGcp, options);
|
|
156
|
-
return injectMetadata(logger, {
|
|
157
|
-
alokai: {
|
|
158
|
-
context: "storefront"
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
};
|
|
162
193
|
// Annotate the CommonJS export names for ESM import in node:
|
|
163
194
|
0 && (module.exports = {
|
|
195
|
+
createAlokaiMiddleware,
|
|
164
196
|
createLogger,
|
|
165
197
|
createSdk,
|
|
198
|
+
defineGetConfigSwitcherHeader,
|
|
166
199
|
defineSdkConfig,
|
|
200
|
+
defineSdkModule,
|
|
167
201
|
resolveSdkOptions
|
|
168
202
|
});
|