@vue-storefront/next 6.0.0-rc.3 → 6.0.0-rc.4
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 +50 -11
- package/dist/index.d.ts +50 -11
- package/dist/index.js +83 -61
- package/dist/index.mjs +81 -61
- package/dist/{types-C90MV4A8.d.mts → types-BCNzbTr2.d.mts} +92 -85
- package/dist/{types-C90MV4A8.d.ts → types-BCNzbTr2.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-BCNzbTr2.mjs';
|
|
3
|
+
export { M as Maybe, b as SfState, a as SfStateProps, c as createSfStateProvider } from './types-BCNzbTr2.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-BCNzbTr2.js';
|
|
3
|
+
export { M as Maybe, b as SfState, a as SfStateProps, c as createSfStateProvider } from './types-BCNzbTr2.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,55 @@
|
|
|
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';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
import { d as CreateSdkOptions, e as Config, f as CreateSdkReturn } from './types-BCNzbTr2.mjs';
|
|
3
4
|
import '@alokai/connect/sdk';
|
|
4
|
-
import 'react';
|
|
5
5
|
import 'next/headers';
|
|
6
|
+
import 'react';
|
|
7
|
+
|
|
8
|
+
type LogVerbosity = "alert" | "critical" | "debug" | "emergency" | "error" | "info" | "notice" | "warning";
|
|
9
|
+
type LoggerOptions = Partial<{
|
|
10
|
+
includeStackTrace: boolean;
|
|
11
|
+
verbosity: LogVerbosity;
|
|
12
|
+
}>;
|
|
13
|
+
|
|
14
|
+
declare const createLogger: (options?: LoggerOptions) => _alokai_connect_logger.LoggerInterface;
|
|
15
|
+
|
|
16
|
+
type NextMiddleware = (request: NextRequest) => NextResponse | Promise<NextResponse>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates an Alokai middleware wrapper that adds pathname information to request headers.
|
|
19
|
+
* This is required for proper pathname handling during SSR in Next.js.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* // middleware.ts
|
|
24
|
+
* import { createAlokaiMiddleware } from '@alokai/next';
|
|
25
|
+
*
|
|
26
|
+
* export default createAlokaiMiddleware((request) => {
|
|
27
|
+
* // Your middleware logic here
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param middleware - The Next.js middleware function to wrap
|
|
32
|
+
* @returns A wrapped middleware function that adds pathname to request headers
|
|
33
|
+
*/
|
|
34
|
+
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;
|
|
6
53
|
|
|
7
54
|
/**
|
|
8
55
|
* Creates an SDK for the given configuration definition.
|
|
@@ -89,12 +136,4 @@ type ResolveSdkOptionsConfig = {
|
|
|
89
136
|
*/
|
|
90
137
|
declare function resolveSdkOptions(input: CreateSdkOptions, _options?: Partial<ResolveSdkOptionsConfig>): CreateSdkOptions;
|
|
91
138
|
|
|
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 };
|
|
139
|
+
export { CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineSdkConfig, getPathnameFromRequestHeaders, resolveSdkOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,55 @@
|
|
|
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';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
import { d as CreateSdkOptions, e as Config, f as CreateSdkReturn } from './types-BCNzbTr2.js';
|
|
3
4
|
import '@alokai/connect/sdk';
|
|
4
|
-
import 'react';
|
|
5
5
|
import 'next/headers';
|
|
6
|
+
import 'react';
|
|
7
|
+
|
|
8
|
+
type LogVerbosity = "alert" | "critical" | "debug" | "emergency" | "error" | "info" | "notice" | "warning";
|
|
9
|
+
type LoggerOptions = Partial<{
|
|
10
|
+
includeStackTrace: boolean;
|
|
11
|
+
verbosity: LogVerbosity;
|
|
12
|
+
}>;
|
|
13
|
+
|
|
14
|
+
declare const createLogger: (options?: LoggerOptions) => _alokai_connect_logger.LoggerInterface;
|
|
15
|
+
|
|
16
|
+
type NextMiddleware = (request: NextRequest) => NextResponse | Promise<NextResponse>;
|
|
17
|
+
/**
|
|
18
|
+
* Creates an Alokai middleware wrapper that adds pathname information to request headers.
|
|
19
|
+
* This is required for proper pathname handling during SSR in Next.js.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* // middleware.ts
|
|
24
|
+
* import { createAlokaiMiddleware } from '@alokai/next';
|
|
25
|
+
*
|
|
26
|
+
* export default createAlokaiMiddleware((request) => {
|
|
27
|
+
* // Your middleware logic here
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param middleware - The Next.js middleware function to wrap
|
|
32
|
+
* @returns A wrapped middleware function that adds pathname to request headers
|
|
33
|
+
*/
|
|
34
|
+
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;
|
|
6
53
|
|
|
7
54
|
/**
|
|
8
55
|
* Creates an SDK for the given configuration definition.
|
|
@@ -89,12 +136,4 @@ type ResolveSdkOptionsConfig = {
|
|
|
89
136
|
*/
|
|
90
137
|
declare function resolveSdkOptions(input: CreateSdkOptions, _options?: Partial<ResolveSdkOptionsConfig>): CreateSdkOptions;
|
|
91
138
|
|
|
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 };
|
|
139
|
+
export { CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineSdkConfig, getPathnameFromRequestHeaders, resolveSdkOptions };
|
package/dist/index.js
CHANGED
|
@@ -37,13 +37,80 @@ 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,
|
|
42
43
|
defineSdkConfig: () => defineSdkConfig,
|
|
44
|
+
getPathnameFromRequestHeaders: () => getPathnameFromRequestHeaders,
|
|
43
45
|
resolveSdkOptions: () => resolveSdkOptions
|
|
44
46
|
});
|
|
45
47
|
module.exports = __toCommonJS(src_exports);
|
|
46
48
|
|
|
49
|
+
// src/logger/index.ts
|
|
50
|
+
var import_logger = require("@alokai/connect/logger");
|
|
51
|
+
|
|
52
|
+
// src/logger/injectMetadata.ts
|
|
53
|
+
function injectMetadata(logger, externalData) {
|
|
54
|
+
return new Proxy(logger, {
|
|
55
|
+
get(target, prop) {
|
|
56
|
+
const targetProp = target[prop];
|
|
57
|
+
if (typeof targetProp === "function") {
|
|
58
|
+
return (...args) => {
|
|
59
|
+
const [logData, metadata] = args;
|
|
60
|
+
targetProp(logData, __spreadValues(__spreadValues({}, metadata), externalData));
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return targetProp;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/logger/index.ts
|
|
69
|
+
var createLogger = (options) => {
|
|
70
|
+
const logger = import_logger.LoggerFactory.create(import_logger.LoggerType.ConsolaGcp, options);
|
|
71
|
+
return injectMetadata(logger, {
|
|
72
|
+
alokai: {
|
|
73
|
+
context: "storefront"
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// src/middleware.ts
|
|
79
|
+
function createAlokaiMiddleware(middleware) {
|
|
80
|
+
return (request) => {
|
|
81
|
+
const nextUrl = request.nextUrl.clone();
|
|
82
|
+
request.headers.append("x-pathname", nextUrl.pathname);
|
|
83
|
+
return middleware(request);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function getPathnameFromRequestHeaders(headers) {
|
|
87
|
+
return headers["x-pathname"];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/sdk/index.tsx
|
|
91
|
+
var import_sdk = require("@alokai/connect/sdk");
|
|
92
|
+
|
|
93
|
+
// src/sdk/helpers/defaultConfigs.ts
|
|
94
|
+
var defaultMethodsRequestConfig = {
|
|
95
|
+
unifiedCms: {
|
|
96
|
+
middlewareModule: {
|
|
97
|
+
getEntries: { method: "GET" },
|
|
98
|
+
getPage: { method: "GET" }
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
unifiedCommerce: {
|
|
102
|
+
middlewareModule: {
|
|
103
|
+
getCategories: { method: "GET" },
|
|
104
|
+
getCategory: { method: "GET" },
|
|
105
|
+
getCurrencies: { method: "GET" },
|
|
106
|
+
getProductDetails: { method: "GET" },
|
|
107
|
+
getProductReviews: { method: "GET" },
|
|
108
|
+
getProducts: { method: "GET" },
|
|
109
|
+
searchProducts: { method: "GET" }
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
47
114
|
// src/sdk/helpers/resolveDynamicContext.ts
|
|
48
115
|
var BLACKLISTED_HEADERS = /* @__PURE__ */ new Set(["host"]);
|
|
49
116
|
function isAppRouterHeaders(headers) {
|
|
@@ -53,9 +120,9 @@ function isFlatNextHeaders(headers) {
|
|
|
53
120
|
return !!headers && !("headers" in headers);
|
|
54
121
|
}
|
|
55
122
|
function normalizeRequestHeaders(requestHeaders) {
|
|
56
|
-
const { headers = {}
|
|
57
|
-
|
|
58
|
-
|
|
123
|
+
const { cookies, headers = {} } = isFlatNextHeaders(requestHeaders) ? { cookies: void 0, headers: requestHeaders } : {
|
|
124
|
+
cookies: requestHeaders == null ? void 0 : requestHeaders.cookies,
|
|
125
|
+
headers: requestHeaders == null ? void 0 : requestHeaders.headers
|
|
59
126
|
};
|
|
60
127
|
const normalizedHeaders = isAppRouterHeaders(headers) ? Object.fromEntries(headers.entries()) : headers;
|
|
61
128
|
if (cookies) {
|
|
@@ -70,53 +137,35 @@ function resolveDynamicContext(context) {
|
|
|
70
137
|
const normalizedHeaders = normalizeRequestHeaders(
|
|
71
138
|
(_a = context.getRequestHeaders) == null ? void 0 : _a.call(context)
|
|
72
139
|
);
|
|
73
|
-
|
|
140
|
+
const requestHeaders = Object.fromEntries(
|
|
74
141
|
Object.entries(normalizedHeaders).filter(
|
|
75
142
|
([key]) => !BLACKLISTED_HEADERS.has(key)
|
|
76
143
|
)
|
|
77
144
|
);
|
|
145
|
+
if (context.getLocale) {
|
|
146
|
+
requestHeaders["x-alokai-locale"] = context.getLocale();
|
|
147
|
+
}
|
|
148
|
+
return requestHeaders;
|
|
78
149
|
}
|
|
79
150
|
});
|
|
80
151
|
}
|
|
81
152
|
|
|
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
153
|
// src/sdk/index.tsx
|
|
104
|
-
var import_sdk = 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
|
}
|
|
@@ -130,39 +179,12 @@ function defineSdkConfig(config) {
|
|
|
130
179
|
function resolveSdkOptions(input, _options = {}) {
|
|
131
180
|
return input;
|
|
132
181
|
}
|
|
133
|
-
|
|
134
|
-
// src/logger/index.ts
|
|
135
|
-
var import_logger = require("@alokai/connect/logger");
|
|
136
|
-
|
|
137
|
-
// src/logger/injectMetadata.ts
|
|
138
|
-
function injectMetadata(logger, externalData) {
|
|
139
|
-
return new Proxy(logger, {
|
|
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
|
-
});
|
|
151
|
-
}
|
|
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
182
|
// Annotate the CommonJS export names for ESM import in node:
|
|
163
183
|
0 && (module.exports = {
|
|
184
|
+
createAlokaiMiddleware,
|
|
164
185
|
createLogger,
|
|
165
186
|
createSdk,
|
|
166
187
|
defineSdkConfig,
|
|
188
|
+
getPathnameFromRequestHeaders,
|
|
167
189
|
resolveSdkOptions
|
|
168
190
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,71 @@ import {
|
|
|
3
3
|
__spreadValues
|
|
4
4
|
} from "./chunk-FWCSY2DS.mjs";
|
|
5
5
|
|
|
6
|
+
// src/logger/index.ts
|
|
7
|
+
import { LoggerFactory, LoggerType } from "@alokai/connect/logger";
|
|
8
|
+
|
|
9
|
+
// src/logger/injectMetadata.ts
|
|
10
|
+
function injectMetadata(logger, externalData) {
|
|
11
|
+
return new Proxy(logger, {
|
|
12
|
+
get(target, prop) {
|
|
13
|
+
const targetProp = target[prop];
|
|
14
|
+
if (typeof targetProp === "function") {
|
|
15
|
+
return (...args) => {
|
|
16
|
+
const [logData, metadata] = args;
|
|
17
|
+
targetProp(logData, __spreadValues(__spreadValues({}, metadata), externalData));
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
return targetProp;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/logger/index.ts
|
|
26
|
+
var createLogger = (options) => {
|
|
27
|
+
const logger = LoggerFactory.create(LoggerType.ConsolaGcp, options);
|
|
28
|
+
return injectMetadata(logger, {
|
|
29
|
+
alokai: {
|
|
30
|
+
context: "storefront"
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/middleware.ts
|
|
36
|
+
function createAlokaiMiddleware(middleware) {
|
|
37
|
+
return (request) => {
|
|
38
|
+
const nextUrl = request.nextUrl.clone();
|
|
39
|
+
request.headers.append("x-pathname", nextUrl.pathname);
|
|
40
|
+
return middleware(request);
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function getPathnameFromRequestHeaders(headers) {
|
|
44
|
+
return headers["x-pathname"];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/sdk/index.tsx
|
|
48
|
+
import { buildModule, initSDK, middlewareModule } from "@alokai/connect/sdk";
|
|
49
|
+
|
|
50
|
+
// src/sdk/helpers/defaultConfigs.ts
|
|
51
|
+
var defaultMethodsRequestConfig = {
|
|
52
|
+
unifiedCms: {
|
|
53
|
+
middlewareModule: {
|
|
54
|
+
getEntries: { method: "GET" },
|
|
55
|
+
getPage: { method: "GET" }
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
unifiedCommerce: {
|
|
59
|
+
middlewareModule: {
|
|
60
|
+
getCategories: { method: "GET" },
|
|
61
|
+
getCategory: { method: "GET" },
|
|
62
|
+
getCurrencies: { method: "GET" },
|
|
63
|
+
getProductDetails: { method: "GET" },
|
|
64
|
+
getProductReviews: { method: "GET" },
|
|
65
|
+
getProducts: { method: "GET" },
|
|
66
|
+
searchProducts: { method: "GET" }
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
6
71
|
// src/sdk/helpers/resolveDynamicContext.ts
|
|
7
72
|
var BLACKLISTED_HEADERS = /* @__PURE__ */ new Set(["host"]);
|
|
8
73
|
function isAppRouterHeaders(headers) {
|
|
@@ -12,9 +77,9 @@ function isFlatNextHeaders(headers) {
|
|
|
12
77
|
return !!headers && !("headers" in headers);
|
|
13
78
|
}
|
|
14
79
|
function normalizeRequestHeaders(requestHeaders) {
|
|
15
|
-
const { headers = {}
|
|
16
|
-
|
|
17
|
-
|
|
80
|
+
const { cookies, headers = {} } = isFlatNextHeaders(requestHeaders) ? { cookies: void 0, headers: requestHeaders } : {
|
|
81
|
+
cookies: requestHeaders == null ? void 0 : requestHeaders.cookies,
|
|
82
|
+
headers: requestHeaders == null ? void 0 : requestHeaders.headers
|
|
18
83
|
};
|
|
19
84
|
const normalizedHeaders = isAppRouterHeaders(headers) ? Object.fromEntries(headers.entries()) : headers;
|
|
20
85
|
if (cookies) {
|
|
@@ -29,53 +94,35 @@ function resolveDynamicContext(context) {
|
|
|
29
94
|
const normalizedHeaders = normalizeRequestHeaders(
|
|
30
95
|
(_a = context.getRequestHeaders) == null ? void 0 : _a.call(context)
|
|
31
96
|
);
|
|
32
|
-
|
|
97
|
+
const requestHeaders = Object.fromEntries(
|
|
33
98
|
Object.entries(normalizedHeaders).filter(
|
|
34
99
|
([key]) => !BLACKLISTED_HEADERS.has(key)
|
|
35
100
|
)
|
|
36
101
|
);
|
|
102
|
+
if (context.getLocale) {
|
|
103
|
+
requestHeaders["x-alokai-locale"] = context.getLocale();
|
|
104
|
+
}
|
|
105
|
+
return requestHeaders;
|
|
37
106
|
}
|
|
38
107
|
});
|
|
39
108
|
}
|
|
40
109
|
|
|
41
|
-
// src/sdk/helpers/defaultConfigs.ts
|
|
42
|
-
var defaultMethodsRequestConfig = {
|
|
43
|
-
unifiedCommerce: {
|
|
44
|
-
middlewareModule: {
|
|
45
|
-
getCategory: { method: "GET" },
|
|
46
|
-
getCategories: { method: "GET" },
|
|
47
|
-
getProductDetails: { method: "GET" },
|
|
48
|
-
getProductReviews: { method: "GET" },
|
|
49
|
-
getProducts: { method: "GET" },
|
|
50
|
-
getCurrencies: { method: "GET" },
|
|
51
|
-
searchProducts: { method: "GET" }
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
unifiedCms: {
|
|
55
|
-
middlewareModule: {
|
|
56
|
-
getPage: { method: "GET" },
|
|
57
|
-
getEntries: { method: "GET" }
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
110
|
// src/sdk/index.tsx
|
|
63
|
-
import { buildModule, initSDK, middlewareModule } from "@alokai/connect/sdk";
|
|
64
111
|
function createSdk(options, configDefinition) {
|
|
65
112
|
function getSdk(dynamicContext = {}) {
|
|
66
113
|
var _a;
|
|
67
114
|
const { getRequestHeaders } = resolveDynamicContext(dynamicContext);
|
|
68
115
|
const resolvedConfig = configDefinition({
|
|
69
|
-
defaults: defaultMethodsRequestConfig,
|
|
70
116
|
buildModule,
|
|
71
|
-
middlewareModule,
|
|
72
|
-
getRequestHeaders,
|
|
73
117
|
config: {
|
|
74
118
|
apiUrl: options.middleware.apiUrl,
|
|
75
|
-
|
|
119
|
+
cdnCacheBustingId: (_a = options.middleware.cdnCacheBustingId) != null ? _a : "no-cache-busting-id-set",
|
|
76
120
|
defaultMethodsRequestConfig,
|
|
77
|
-
|
|
78
|
-
}
|
|
121
|
+
ssrApiUrl: options.middleware.ssrApiUrl
|
|
122
|
+
},
|
|
123
|
+
defaults: defaultMethodsRequestConfig,
|
|
124
|
+
getRequestHeaders,
|
|
125
|
+
middlewareModule
|
|
79
126
|
});
|
|
80
127
|
return initSDK(resolvedConfig);
|
|
81
128
|
}
|
|
@@ -89,38 +136,11 @@ function defineSdkConfig(config) {
|
|
|
89
136
|
function resolveSdkOptions(input, _options = {}) {
|
|
90
137
|
return input;
|
|
91
138
|
}
|
|
92
|
-
|
|
93
|
-
// src/logger/index.ts
|
|
94
|
-
import { LoggerFactory, LoggerType } from "@alokai/connect/logger";
|
|
95
|
-
|
|
96
|
-
// src/logger/injectMetadata.ts
|
|
97
|
-
function injectMetadata(logger, externalData) {
|
|
98
|
-
return new Proxy(logger, {
|
|
99
|
-
get(target, prop) {
|
|
100
|
-
const targetProp = target[prop];
|
|
101
|
-
if (typeof targetProp === "function") {
|
|
102
|
-
return (...args) => {
|
|
103
|
-
const [logData, metadata] = args;
|
|
104
|
-
targetProp(logData, __spreadValues(__spreadValues({}, metadata), externalData));
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
return targetProp;
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/logger/index.ts
|
|
113
|
-
var createLogger = (options) => {
|
|
114
|
-
const logger = LoggerFactory.create(LoggerType.ConsolaGcp, options);
|
|
115
|
-
return injectMetadata(logger, {
|
|
116
|
-
alokai: {
|
|
117
|
-
context: "storefront"
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
};
|
|
121
139
|
export {
|
|
140
|
+
createAlokaiMiddleware,
|
|
122
141
|
createLogger,
|
|
123
142
|
createSdk,
|
|
124
143
|
defineSdkConfig,
|
|
144
|
+
getPathnameFromRequestHeaders,
|
|
125
145
|
resolveSdkOptions
|
|
126
146
|
};
|
|
@@ -1,51 +1,13 @@
|
|
|
1
|
-
import { buildModule, middlewareModule
|
|
2
|
-
import React, { PropsWithChildren, ReactNode } from 'react';
|
|
1
|
+
import { SDKApi, buildModule, middlewareModule } from '@alokai/connect/sdk';
|
|
3
2
|
import { cookies } from 'next/headers';
|
|
3
|
+
import React, { PropsWithChildren, ReactNode } from 'react';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
readonly unifiedCommerce: {
|
|
7
|
-
readonly middlewareModule: {
|
|
8
|
-
readonly getCategory: {
|
|
9
|
-
readonly method: "GET";
|
|
10
|
-
};
|
|
11
|
-
readonly getCategories: {
|
|
12
|
-
readonly method: "GET";
|
|
13
|
-
};
|
|
14
|
-
readonly getProductDetails: {
|
|
15
|
-
readonly method: "GET";
|
|
16
|
-
};
|
|
17
|
-
readonly getProductReviews: {
|
|
18
|
-
readonly method: "GET";
|
|
19
|
-
};
|
|
20
|
-
readonly getProducts: {
|
|
21
|
-
readonly method: "GET";
|
|
22
|
-
};
|
|
23
|
-
readonly getCurrencies: {
|
|
24
|
-
readonly method: "GET";
|
|
25
|
-
};
|
|
26
|
-
readonly searchProducts: {
|
|
27
|
-
readonly method: "GET";
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
readonly unifiedCms: {
|
|
32
|
-
readonly middlewareModule: {
|
|
33
|
-
readonly getPage: {
|
|
34
|
-
readonly method: "GET";
|
|
35
|
-
};
|
|
36
|
-
readonly getEntries: {
|
|
37
|
-
readonly method: "GET";
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
type Maybe<TType> = TType | null;
|
|
5
|
+
type Maybe<TType> = null | TType;
|
|
44
6
|
|
|
45
7
|
type SfContract = {
|
|
46
8
|
SfCart: unknown;
|
|
47
|
-
SfCustomer: unknown;
|
|
48
9
|
SfCurrency: unknown;
|
|
10
|
+
SfCustomer: unknown;
|
|
49
11
|
SfLocale: unknown;
|
|
50
12
|
};
|
|
51
13
|
interface SfStateProps<TSfContract extends SfContract> {
|
|
@@ -55,12 +17,12 @@ interface SfStateProps<TSfContract extends SfContract> {
|
|
|
55
17
|
locales: TSfContract["SfLocale"][];
|
|
56
18
|
}
|
|
57
19
|
interface SfState<TSfContract extends SfContract> extends SfStateProps<TSfContract> {
|
|
58
|
-
cart: TSfContract["SfCart"] |
|
|
59
|
-
customer: TSfContract["SfCustomer"] |
|
|
60
|
-
setCart: (cart?: TSfContract["SfCart"]
|
|
20
|
+
cart: null | TSfContract["SfCart"] | undefined;
|
|
21
|
+
customer: null | TSfContract["SfCustomer"] | undefined;
|
|
22
|
+
setCart: (cart?: null | TSfContract["SfCart"]) => void;
|
|
61
23
|
setCurrencies: (currencies: TSfContract["SfCurrency"][]) => void;
|
|
62
24
|
setCurrency: (currency: TSfContract["SfCurrency"]) => void;
|
|
63
|
-
setCustomer: (customer?: TSfContract["SfCustomer"]
|
|
25
|
+
setCustomer: (customer?: null | TSfContract["SfCustomer"]) => void;
|
|
64
26
|
setLocale: (locale: TSfContract["SfLocale"]) => void;
|
|
65
27
|
setLocales: (locales: TSfContract["SfLocale"][]) => void;
|
|
66
28
|
}
|
|
@@ -68,43 +30,76 @@ declare function createSfStateProvider<TSfContract extends SfContract>(): {
|
|
|
68
30
|
SfStateProvider: ({ children, initialData, }: {
|
|
69
31
|
initialData: SfStateProps<TSfContract>;
|
|
70
32
|
} & PropsWithChildren) => React.JSX.Element;
|
|
71
|
-
|
|
72
|
-
TSfContract["
|
|
73
|
-
(
|
|
33
|
+
useSfCartState: () => [
|
|
34
|
+
null | TSfContract["SfCart"] | undefined,
|
|
35
|
+
(cart?: null | TSfContract["SfCart"]) => void
|
|
74
36
|
];
|
|
75
37
|
useSfCurrenciesState: () => [
|
|
76
38
|
TSfContract["SfCurrency"][],
|
|
77
39
|
(currencies: TSfContract["SfCurrency"][]) => void
|
|
78
40
|
];
|
|
79
|
-
|
|
80
|
-
TSfContract["
|
|
81
|
-
(
|
|
41
|
+
useSfCurrencyState: () => [
|
|
42
|
+
TSfContract["SfCurrency"],
|
|
43
|
+
(currency: TSfContract["SfCurrency"]) => void
|
|
44
|
+
];
|
|
45
|
+
useSfCustomerState: () => [
|
|
46
|
+
null | TSfContract["SfCustomer"] | undefined,
|
|
47
|
+
(customer?: null | TSfContract["SfCustomer"]) => void
|
|
82
48
|
];
|
|
83
49
|
useSfLocalesState: () => [
|
|
84
50
|
TSfContract["SfLocale"][],
|
|
85
51
|
(locales: TSfContract["SfLocale"][]) => void
|
|
86
52
|
];
|
|
87
|
-
|
|
88
|
-
TSfContract["
|
|
89
|
-
(
|
|
90
|
-
];
|
|
91
|
-
useSfCustomerState: () => [
|
|
92
|
-
TSfContract["SfCustomer"] | null | undefined,
|
|
93
|
-
(customer?: TSfContract["SfCustomer"] | null) => void
|
|
53
|
+
useSfLocaleState: () => [
|
|
54
|
+
TSfContract["SfLocale"],
|
|
55
|
+
(locale: TSfContract["SfLocale"]) => void
|
|
94
56
|
];
|
|
95
57
|
};
|
|
96
58
|
|
|
59
|
+
declare const defaultMethodsRequestConfig: {
|
|
60
|
+
readonly unifiedCms: {
|
|
61
|
+
readonly middlewareModule: {
|
|
62
|
+
readonly getEntries: {
|
|
63
|
+
readonly method: "GET";
|
|
64
|
+
};
|
|
65
|
+
readonly getPage: {
|
|
66
|
+
readonly method: "GET";
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
readonly unifiedCommerce: {
|
|
71
|
+
readonly middlewareModule: {
|
|
72
|
+
readonly getCategories: {
|
|
73
|
+
readonly method: "GET";
|
|
74
|
+
};
|
|
75
|
+
readonly getCategory: {
|
|
76
|
+
readonly method: "GET";
|
|
77
|
+
};
|
|
78
|
+
readonly getCurrencies: {
|
|
79
|
+
readonly method: "GET";
|
|
80
|
+
};
|
|
81
|
+
readonly getProductDetails: {
|
|
82
|
+
readonly method: "GET";
|
|
83
|
+
};
|
|
84
|
+
readonly getProductReviews: {
|
|
85
|
+
readonly method: "GET";
|
|
86
|
+
};
|
|
87
|
+
readonly getProducts: {
|
|
88
|
+
readonly method: "GET";
|
|
89
|
+
};
|
|
90
|
+
readonly searchProducts: {
|
|
91
|
+
readonly method: "GET";
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
97
|
interface MiddlewareConfig {
|
|
98
98
|
/**
|
|
99
99
|
* The URL of the middleware.
|
|
100
100
|
* @example "http://localhost:4000"
|
|
101
101
|
*/
|
|
102
102
|
apiUrl: string;
|
|
103
|
-
/**
|
|
104
|
-
* The URL of the middleware for server-side rendering.
|
|
105
|
-
* @example "http://localhost:4000"
|
|
106
|
-
*/
|
|
107
|
-
ssrApiUrl: string;
|
|
108
103
|
/**
|
|
109
104
|
* This is identifier used to invalidate the cache on CDN when the assets change.
|
|
110
105
|
* Usually it's a commit hash.
|
|
@@ -112,6 +107,11 @@ interface MiddlewareConfig {
|
|
|
112
107
|
* @default "no-cache-busting-id-set"
|
|
113
108
|
*/
|
|
114
109
|
cdnCacheBustingId?: string;
|
|
110
|
+
/**
|
|
111
|
+
* The URL of the middleware for server-side rendering.
|
|
112
|
+
* @example "http://localhost:4000"
|
|
113
|
+
*/
|
|
114
|
+
ssrApiUrl: string;
|
|
115
115
|
}
|
|
116
116
|
interface MultistoreConfig {
|
|
117
117
|
/**
|
|
@@ -122,43 +122,47 @@ interface MultistoreConfig {
|
|
|
122
122
|
enabled: boolean;
|
|
123
123
|
}
|
|
124
124
|
interface CreateSdkOptions {
|
|
125
|
-
multistore?: MultistoreConfig;
|
|
126
125
|
middleware: MiddlewareConfig;
|
|
126
|
+
multistore?: MultistoreConfig;
|
|
127
127
|
}
|
|
128
128
|
type Cookies = ReturnType<typeof cookies>;
|
|
129
|
-
type NextHeaders = Record<string, string | string[] | undefined
|
|
129
|
+
type NextHeaders = Headers | Record<string, string | string[] | undefined>;
|
|
130
130
|
type GetSdkContext = {
|
|
131
|
+
/**
|
|
132
|
+
* A function that returns the current locale string;
|
|
133
|
+
*/
|
|
134
|
+
getLocale?: () => string;
|
|
131
135
|
/**
|
|
132
136
|
* A function that returns the request headers.
|
|
133
137
|
*/
|
|
134
|
-
getRequestHeaders?: () =>
|
|
135
|
-
headers: NextHeaders;
|
|
138
|
+
getRequestHeaders?: () => {
|
|
136
139
|
cookies: Cookies;
|
|
137
|
-
|
|
140
|
+
headers: NextHeaders;
|
|
141
|
+
} | NextHeaders;
|
|
138
142
|
};
|
|
139
143
|
type DynamicContext = {
|
|
140
144
|
getRequestHeaders: () => Record<string, string | string[]>;
|
|
141
145
|
};
|
|
142
146
|
type StaticContext = {
|
|
143
147
|
buildModule: typeof buildModule;
|
|
144
|
-
middlewareModule: typeof middlewareModule;
|
|
145
|
-
/**
|
|
146
|
-
* @deprecated Use `config.defaultMethodsRequestConfig` instead.
|
|
147
|
-
*/
|
|
148
|
-
defaults: typeof defaultMethodsRequestConfig;
|
|
149
148
|
config: {
|
|
150
149
|
apiUrl: string;
|
|
151
|
-
ssrApiUrl: string;
|
|
152
|
-
defaultMethodsRequestConfig: typeof defaultMethodsRequestConfig;
|
|
153
150
|
cdnCacheBustingId: string;
|
|
151
|
+
defaultMethodsRequestConfig: typeof defaultMethodsRequestConfig;
|
|
152
|
+
ssrApiUrl: string;
|
|
154
153
|
};
|
|
154
|
+
/**
|
|
155
|
+
* @deprecated Use `config.defaultMethodsRequestConfig` instead.
|
|
156
|
+
*/
|
|
157
|
+
defaults: typeof defaultMethodsRequestConfig;
|
|
158
|
+
middlewareModule: typeof middlewareModule;
|
|
155
159
|
};
|
|
156
160
|
type InjectedContext = DynamicContext & StaticContext;
|
|
157
161
|
type Config<TConfig> = (context: InjectedContext) => TConfig;
|
|
158
162
|
type AlokaiProviderProps<TSdk, TSfContract extends SfContract> = {
|
|
159
163
|
children: ReactNode;
|
|
160
|
-
sdk: TSdk;
|
|
161
164
|
initialData: SfStateProps<TSfContract>;
|
|
165
|
+
sdk: TSdk;
|
|
162
166
|
};
|
|
163
167
|
interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
164
168
|
/**
|
|
@@ -176,9 +180,10 @@ interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
|
176
180
|
* import type { GetServerSideProps } from "next";
|
|
177
181
|
* import { getSdk } from "../../sdk.config";
|
|
178
182
|
*
|
|
179
|
-
* export const getServerSideProps: GetServerSideProps = async ({ req }) => {
|
|
180
|
-
* const sdk = getSdk({
|
|
183
|
+
* export const getServerSideProps: GetServerSideProps = async ({ req, locale }) => {
|
|
184
|
+
* const sdk = await getSdk({
|
|
181
185
|
* getRequestHeaders: () => req.headers,
|
|
186
|
+
* getLocale: () => locale,
|
|
182
187
|
* });
|
|
183
188
|
* const { products } = await sdk.unified.getProducts();
|
|
184
189
|
*
|
|
@@ -195,8 +200,10 @@ interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
|
195
200
|
* import { getSdk } from "../../sdk.config";
|
|
196
201
|
*
|
|
197
202
|
* export default async function SsrPage() {
|
|
198
|
-
* const
|
|
203
|
+
* const locale = await getLocale();
|
|
204
|
+
* const sdk = await getSdk({
|
|
199
205
|
* getRequestHeaders: () => headers(),
|
|
206
|
+
* getLocale: () => locale,
|
|
200
207
|
* });
|
|
201
208
|
* const { products } = await sdk.unified.getProducts();
|
|
202
209
|
*
|
|
@@ -209,12 +216,12 @@ interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
|
209
216
|
type CreateSdkContextReturn<TSdk extends SDKApi<any>, TSfContract extends SfContract> = Readonly<{
|
|
210
217
|
AlokaiProvider: ({ children, }: AlokaiProviderProps<TSdk, TSfContract>) => JSX.Element;
|
|
211
218
|
useSdk: () => TSdk;
|
|
212
|
-
useSfCurrencyState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrencyState"];
|
|
213
|
-
useSfCurrenciesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrenciesState"];
|
|
214
|
-
useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
|
|
215
|
-
useSfLocalesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocalesState"];
|
|
216
219
|
useSfCartState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCartState"];
|
|
220
|
+
useSfCurrenciesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrenciesState"];
|
|
221
|
+
useSfCurrencyState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrencyState"];
|
|
217
222
|
useSfCustomerState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCustomerState"];
|
|
223
|
+
useSfLocalesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocalesState"];
|
|
224
|
+
useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
|
|
218
225
|
}>;
|
|
219
226
|
|
|
220
|
-
export { type
|
|
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 };
|
|
@@ -1,51 +1,13 @@
|
|
|
1
|
-
import { buildModule, middlewareModule
|
|
2
|
-
import React, { PropsWithChildren, ReactNode } from 'react';
|
|
1
|
+
import { SDKApi, buildModule, middlewareModule } from '@alokai/connect/sdk';
|
|
3
2
|
import { cookies } from 'next/headers';
|
|
3
|
+
import React, { PropsWithChildren, ReactNode } from 'react';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
readonly unifiedCommerce: {
|
|
7
|
-
readonly middlewareModule: {
|
|
8
|
-
readonly getCategory: {
|
|
9
|
-
readonly method: "GET";
|
|
10
|
-
};
|
|
11
|
-
readonly getCategories: {
|
|
12
|
-
readonly method: "GET";
|
|
13
|
-
};
|
|
14
|
-
readonly getProductDetails: {
|
|
15
|
-
readonly method: "GET";
|
|
16
|
-
};
|
|
17
|
-
readonly getProductReviews: {
|
|
18
|
-
readonly method: "GET";
|
|
19
|
-
};
|
|
20
|
-
readonly getProducts: {
|
|
21
|
-
readonly method: "GET";
|
|
22
|
-
};
|
|
23
|
-
readonly getCurrencies: {
|
|
24
|
-
readonly method: "GET";
|
|
25
|
-
};
|
|
26
|
-
readonly searchProducts: {
|
|
27
|
-
readonly method: "GET";
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
readonly unifiedCms: {
|
|
32
|
-
readonly middlewareModule: {
|
|
33
|
-
readonly getPage: {
|
|
34
|
-
readonly method: "GET";
|
|
35
|
-
};
|
|
36
|
-
readonly getEntries: {
|
|
37
|
-
readonly method: "GET";
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
type Maybe<TType> = TType | null;
|
|
5
|
+
type Maybe<TType> = null | TType;
|
|
44
6
|
|
|
45
7
|
type SfContract = {
|
|
46
8
|
SfCart: unknown;
|
|
47
|
-
SfCustomer: unknown;
|
|
48
9
|
SfCurrency: unknown;
|
|
10
|
+
SfCustomer: unknown;
|
|
49
11
|
SfLocale: unknown;
|
|
50
12
|
};
|
|
51
13
|
interface SfStateProps<TSfContract extends SfContract> {
|
|
@@ -55,12 +17,12 @@ interface SfStateProps<TSfContract extends SfContract> {
|
|
|
55
17
|
locales: TSfContract["SfLocale"][];
|
|
56
18
|
}
|
|
57
19
|
interface SfState<TSfContract extends SfContract> extends SfStateProps<TSfContract> {
|
|
58
|
-
cart: TSfContract["SfCart"] |
|
|
59
|
-
customer: TSfContract["SfCustomer"] |
|
|
60
|
-
setCart: (cart?: TSfContract["SfCart"]
|
|
20
|
+
cart: null | TSfContract["SfCart"] | undefined;
|
|
21
|
+
customer: null | TSfContract["SfCustomer"] | undefined;
|
|
22
|
+
setCart: (cart?: null | TSfContract["SfCart"]) => void;
|
|
61
23
|
setCurrencies: (currencies: TSfContract["SfCurrency"][]) => void;
|
|
62
24
|
setCurrency: (currency: TSfContract["SfCurrency"]) => void;
|
|
63
|
-
setCustomer: (customer?: TSfContract["SfCustomer"]
|
|
25
|
+
setCustomer: (customer?: null | TSfContract["SfCustomer"]) => void;
|
|
64
26
|
setLocale: (locale: TSfContract["SfLocale"]) => void;
|
|
65
27
|
setLocales: (locales: TSfContract["SfLocale"][]) => void;
|
|
66
28
|
}
|
|
@@ -68,43 +30,76 @@ declare function createSfStateProvider<TSfContract extends SfContract>(): {
|
|
|
68
30
|
SfStateProvider: ({ children, initialData, }: {
|
|
69
31
|
initialData: SfStateProps<TSfContract>;
|
|
70
32
|
} & PropsWithChildren) => React.JSX.Element;
|
|
71
|
-
|
|
72
|
-
TSfContract["
|
|
73
|
-
(
|
|
33
|
+
useSfCartState: () => [
|
|
34
|
+
null | TSfContract["SfCart"] | undefined,
|
|
35
|
+
(cart?: null | TSfContract["SfCart"]) => void
|
|
74
36
|
];
|
|
75
37
|
useSfCurrenciesState: () => [
|
|
76
38
|
TSfContract["SfCurrency"][],
|
|
77
39
|
(currencies: TSfContract["SfCurrency"][]) => void
|
|
78
40
|
];
|
|
79
|
-
|
|
80
|
-
TSfContract["
|
|
81
|
-
(
|
|
41
|
+
useSfCurrencyState: () => [
|
|
42
|
+
TSfContract["SfCurrency"],
|
|
43
|
+
(currency: TSfContract["SfCurrency"]) => void
|
|
44
|
+
];
|
|
45
|
+
useSfCustomerState: () => [
|
|
46
|
+
null | TSfContract["SfCustomer"] | undefined,
|
|
47
|
+
(customer?: null | TSfContract["SfCustomer"]) => void
|
|
82
48
|
];
|
|
83
49
|
useSfLocalesState: () => [
|
|
84
50
|
TSfContract["SfLocale"][],
|
|
85
51
|
(locales: TSfContract["SfLocale"][]) => void
|
|
86
52
|
];
|
|
87
|
-
|
|
88
|
-
TSfContract["
|
|
89
|
-
(
|
|
90
|
-
];
|
|
91
|
-
useSfCustomerState: () => [
|
|
92
|
-
TSfContract["SfCustomer"] | null | undefined,
|
|
93
|
-
(customer?: TSfContract["SfCustomer"] | null) => void
|
|
53
|
+
useSfLocaleState: () => [
|
|
54
|
+
TSfContract["SfLocale"],
|
|
55
|
+
(locale: TSfContract["SfLocale"]) => void
|
|
94
56
|
];
|
|
95
57
|
};
|
|
96
58
|
|
|
59
|
+
declare const defaultMethodsRequestConfig: {
|
|
60
|
+
readonly unifiedCms: {
|
|
61
|
+
readonly middlewareModule: {
|
|
62
|
+
readonly getEntries: {
|
|
63
|
+
readonly method: "GET";
|
|
64
|
+
};
|
|
65
|
+
readonly getPage: {
|
|
66
|
+
readonly method: "GET";
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
readonly unifiedCommerce: {
|
|
71
|
+
readonly middlewareModule: {
|
|
72
|
+
readonly getCategories: {
|
|
73
|
+
readonly method: "GET";
|
|
74
|
+
};
|
|
75
|
+
readonly getCategory: {
|
|
76
|
+
readonly method: "GET";
|
|
77
|
+
};
|
|
78
|
+
readonly getCurrencies: {
|
|
79
|
+
readonly method: "GET";
|
|
80
|
+
};
|
|
81
|
+
readonly getProductDetails: {
|
|
82
|
+
readonly method: "GET";
|
|
83
|
+
};
|
|
84
|
+
readonly getProductReviews: {
|
|
85
|
+
readonly method: "GET";
|
|
86
|
+
};
|
|
87
|
+
readonly getProducts: {
|
|
88
|
+
readonly method: "GET";
|
|
89
|
+
};
|
|
90
|
+
readonly searchProducts: {
|
|
91
|
+
readonly method: "GET";
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
97
|
interface MiddlewareConfig {
|
|
98
98
|
/**
|
|
99
99
|
* The URL of the middleware.
|
|
100
100
|
* @example "http://localhost:4000"
|
|
101
101
|
*/
|
|
102
102
|
apiUrl: string;
|
|
103
|
-
/**
|
|
104
|
-
* The URL of the middleware for server-side rendering.
|
|
105
|
-
* @example "http://localhost:4000"
|
|
106
|
-
*/
|
|
107
|
-
ssrApiUrl: string;
|
|
108
103
|
/**
|
|
109
104
|
* This is identifier used to invalidate the cache on CDN when the assets change.
|
|
110
105
|
* Usually it's a commit hash.
|
|
@@ -112,6 +107,11 @@ interface MiddlewareConfig {
|
|
|
112
107
|
* @default "no-cache-busting-id-set"
|
|
113
108
|
*/
|
|
114
109
|
cdnCacheBustingId?: string;
|
|
110
|
+
/**
|
|
111
|
+
* The URL of the middleware for server-side rendering.
|
|
112
|
+
* @example "http://localhost:4000"
|
|
113
|
+
*/
|
|
114
|
+
ssrApiUrl: string;
|
|
115
115
|
}
|
|
116
116
|
interface MultistoreConfig {
|
|
117
117
|
/**
|
|
@@ -122,43 +122,47 @@ interface MultistoreConfig {
|
|
|
122
122
|
enabled: boolean;
|
|
123
123
|
}
|
|
124
124
|
interface CreateSdkOptions {
|
|
125
|
-
multistore?: MultistoreConfig;
|
|
126
125
|
middleware: MiddlewareConfig;
|
|
126
|
+
multistore?: MultistoreConfig;
|
|
127
127
|
}
|
|
128
128
|
type Cookies = ReturnType<typeof cookies>;
|
|
129
|
-
type NextHeaders = Record<string, string | string[] | undefined
|
|
129
|
+
type NextHeaders = Headers | Record<string, string | string[] | undefined>;
|
|
130
130
|
type GetSdkContext = {
|
|
131
|
+
/**
|
|
132
|
+
* A function that returns the current locale string;
|
|
133
|
+
*/
|
|
134
|
+
getLocale?: () => string;
|
|
131
135
|
/**
|
|
132
136
|
* A function that returns the request headers.
|
|
133
137
|
*/
|
|
134
|
-
getRequestHeaders?: () =>
|
|
135
|
-
headers: NextHeaders;
|
|
138
|
+
getRequestHeaders?: () => {
|
|
136
139
|
cookies: Cookies;
|
|
137
|
-
|
|
140
|
+
headers: NextHeaders;
|
|
141
|
+
} | NextHeaders;
|
|
138
142
|
};
|
|
139
143
|
type DynamicContext = {
|
|
140
144
|
getRequestHeaders: () => Record<string, string | string[]>;
|
|
141
145
|
};
|
|
142
146
|
type StaticContext = {
|
|
143
147
|
buildModule: typeof buildModule;
|
|
144
|
-
middlewareModule: typeof middlewareModule;
|
|
145
|
-
/**
|
|
146
|
-
* @deprecated Use `config.defaultMethodsRequestConfig` instead.
|
|
147
|
-
*/
|
|
148
|
-
defaults: typeof defaultMethodsRequestConfig;
|
|
149
148
|
config: {
|
|
150
149
|
apiUrl: string;
|
|
151
|
-
ssrApiUrl: string;
|
|
152
|
-
defaultMethodsRequestConfig: typeof defaultMethodsRequestConfig;
|
|
153
150
|
cdnCacheBustingId: string;
|
|
151
|
+
defaultMethodsRequestConfig: typeof defaultMethodsRequestConfig;
|
|
152
|
+
ssrApiUrl: string;
|
|
154
153
|
};
|
|
154
|
+
/**
|
|
155
|
+
* @deprecated Use `config.defaultMethodsRequestConfig` instead.
|
|
156
|
+
*/
|
|
157
|
+
defaults: typeof defaultMethodsRequestConfig;
|
|
158
|
+
middlewareModule: typeof middlewareModule;
|
|
155
159
|
};
|
|
156
160
|
type InjectedContext = DynamicContext & StaticContext;
|
|
157
161
|
type Config<TConfig> = (context: InjectedContext) => TConfig;
|
|
158
162
|
type AlokaiProviderProps<TSdk, TSfContract extends SfContract> = {
|
|
159
163
|
children: ReactNode;
|
|
160
|
-
sdk: TSdk;
|
|
161
164
|
initialData: SfStateProps<TSfContract>;
|
|
165
|
+
sdk: TSdk;
|
|
162
166
|
};
|
|
163
167
|
interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
164
168
|
/**
|
|
@@ -176,9 +180,10 @@ interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
|
176
180
|
* import type { GetServerSideProps } from "next";
|
|
177
181
|
* import { getSdk } from "../../sdk.config";
|
|
178
182
|
*
|
|
179
|
-
* export const getServerSideProps: GetServerSideProps = async ({ req }) => {
|
|
180
|
-
* const sdk = getSdk({
|
|
183
|
+
* export const getServerSideProps: GetServerSideProps = async ({ req, locale }) => {
|
|
184
|
+
* const sdk = await getSdk({
|
|
181
185
|
* getRequestHeaders: () => req.headers,
|
|
186
|
+
* getLocale: () => locale,
|
|
182
187
|
* });
|
|
183
188
|
* const { products } = await sdk.unified.getProducts();
|
|
184
189
|
*
|
|
@@ -195,8 +200,10 @@ interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
|
195
200
|
* import { getSdk } from "../../sdk.config";
|
|
196
201
|
*
|
|
197
202
|
* export default async function SsrPage() {
|
|
198
|
-
* const
|
|
203
|
+
* const locale = await getLocale();
|
|
204
|
+
* const sdk = await getSdk({
|
|
199
205
|
* getRequestHeaders: () => headers(),
|
|
206
|
+
* getLocale: () => locale,
|
|
200
207
|
* });
|
|
201
208
|
* const { products } = await sdk.unified.getProducts();
|
|
202
209
|
*
|
|
@@ -209,12 +216,12 @@ interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
|
209
216
|
type CreateSdkContextReturn<TSdk extends SDKApi<any>, TSfContract extends SfContract> = Readonly<{
|
|
210
217
|
AlokaiProvider: ({ children, }: AlokaiProviderProps<TSdk, TSfContract>) => JSX.Element;
|
|
211
218
|
useSdk: () => TSdk;
|
|
212
|
-
useSfCurrencyState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrencyState"];
|
|
213
|
-
useSfCurrenciesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrenciesState"];
|
|
214
|
-
useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
|
|
215
|
-
useSfLocalesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocalesState"];
|
|
216
219
|
useSfCartState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCartState"];
|
|
220
|
+
useSfCurrenciesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrenciesState"];
|
|
221
|
+
useSfCurrencyState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrencyState"];
|
|
217
222
|
useSfCustomerState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCustomerState"];
|
|
223
|
+
useSfLocalesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocalesState"];
|
|
224
|
+
useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
|
|
218
225
|
}>;
|
|
219
226
|
|
|
220
|
-
export { type
|
|
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 };
|
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-rc.
|
|
5
|
+
"version": "6.0.0-rc.4",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsup",
|
|
23
|
-
"lint": "
|
|
23
|
+
"lint": "eslint",
|
|
24
|
+
"lint:fix": "eslint --fix",
|
|
24
25
|
"format": "prettier --write .",
|
|
25
26
|
"test:unit": "vitest run",
|
|
26
27
|
"version": "cp CHANGELOG.md ../../docs/enterprise/content/storefront/6.change-log/next.md"
|
|
@@ -29,7 +30,7 @@
|
|
|
29
30
|
"zustand": "^4.5.4"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@alokai/connect": "^1.0.0-rc.
|
|
33
|
+
"@alokai/connect": "^1.0.0-rc.3",
|
|
33
34
|
"@types/react": "18.3.2",
|
|
34
35
|
"@types/react-dom": "18.3.0",
|
|
35
36
|
"react-dom": "18.3.1",
|
|
@@ -37,10 +38,10 @@
|
|
|
37
38
|
"tsup": "8.3.0",
|
|
38
39
|
"vitest": "2.1.5",
|
|
39
40
|
"react": "18.3.1",
|
|
40
|
-
"next": "14.2.
|
|
41
|
+
"next": "14.2.25"
|
|
41
42
|
},
|
|
42
43
|
"peerDependencies": {
|
|
43
|
-
"@alokai/connect": "^1.0.0-rc.
|
|
44
|
+
"@alokai/connect": "^1.0.0-rc.3",
|
|
44
45
|
"react": "^18.2.0",
|
|
45
46
|
"next": "^13.4.7 || ^14.0.0"
|
|
46
47
|
},
|