@vue-storefront/next 7.0.0-next.3 → 7.0.0-next.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/dist/client.cjs +223 -0
- package/dist/{client.d.ts → client.d.cts} +6 -7
- package/dist/client.d.mts +6 -7
- package/dist/client.mjs +180 -139
- package/dist/env-Be9N7zqo.cjs +115 -0
- package/dist/env-XPpRDRcE.mjs +97 -0
- package/dist/index-BXYjHxeC.d.mts +250 -0
- package/dist/index-D1weTw7N.d.cts +250 -0
- package/dist/index.cjs +258 -0
- package/dist/{index.d.ts → index.d.cts} +18 -20
- package/dist/index.d.mts +18 -20
- package/dist/index.mjs +214 -131
- package/package.json +12 -12
- package/dist/chunk-NSPLXZD5.mjs +0 -84
- package/dist/client.js +0 -228
- package/dist/index.js +0 -238
- package/dist/types-FGnrBhjy.d.mts +0 -241
- package/dist/types-FGnrBhjy.d.ts +0 -241
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { SDKApi, buildModule, middlewareModule } from "@alokai/connect/sdk";
|
|
2
|
+
import { cookies } from "next/headers";
|
|
3
|
+
import React, { JSX, PropsWithChildren, ReactNode } from "react";
|
|
4
|
+
|
|
5
|
+
//#region src/state.d.ts
|
|
6
|
+
type Maybe<TType> = null | TType;
|
|
7
|
+
type SfContract = {
|
|
8
|
+
SfCart: unknown;
|
|
9
|
+
SfCurrency: unknown;
|
|
10
|
+
SfCustomer: unknown;
|
|
11
|
+
SfLocale: unknown;
|
|
12
|
+
};
|
|
13
|
+
interface SfStateProps<TSfContract extends SfContract> {
|
|
14
|
+
currencies: TSfContract["SfCurrency"][];
|
|
15
|
+
currency: TSfContract["SfCurrency"];
|
|
16
|
+
locale: TSfContract["SfLocale"];
|
|
17
|
+
locales: TSfContract["SfLocale"][];
|
|
18
|
+
}
|
|
19
|
+
interface SfState<TSfContract extends SfContract> extends SfStateProps<TSfContract> {
|
|
20
|
+
cart: null | TSfContract["SfCart"] | undefined;
|
|
21
|
+
customer: null | TSfContract["SfCustomer"] | undefined;
|
|
22
|
+
setCart: (cart?: null | TSfContract["SfCart"]) => void;
|
|
23
|
+
setCurrencies: (currencies: TSfContract["SfCurrency"][]) => void;
|
|
24
|
+
setCurrency: (currency: TSfContract["SfCurrency"]) => void;
|
|
25
|
+
setCustomer: (customer?: null | TSfContract["SfCustomer"]) => void;
|
|
26
|
+
setLocale: (locale: TSfContract["SfLocale"]) => void;
|
|
27
|
+
setLocales: (locales: TSfContract["SfLocale"][]) => void;
|
|
28
|
+
}
|
|
29
|
+
declare function createSfStateProvider<TSfContract extends SfContract>(): {
|
|
30
|
+
SfStateProvider: ({
|
|
31
|
+
children,
|
|
32
|
+
initialData
|
|
33
|
+
}: {
|
|
34
|
+
initialData: SfStateProps<TSfContract>;
|
|
35
|
+
} & PropsWithChildren) => React.JSX.Element;
|
|
36
|
+
useSfCartState: () => [null | TSfContract["SfCart"] | undefined, (cart?: null | TSfContract["SfCart"]) => void];
|
|
37
|
+
useSfCurrenciesState: () => [TSfContract["SfCurrency"][], (currencies: TSfContract["SfCurrency"][]) => void];
|
|
38
|
+
useSfCurrencyState: () => [TSfContract["SfCurrency"], (currency: TSfContract["SfCurrency"]) => void];
|
|
39
|
+
useSfCustomerState: () => [null | TSfContract["SfCustomer"] | undefined, (customer?: null | TSfContract["SfCustomer"]) => void];
|
|
40
|
+
useSfLocalesState: () => [TSfContract["SfLocale"][], (locales: TSfContract["SfLocale"][]) => void];
|
|
41
|
+
useSfLocaleState: () => [TSfContract["SfLocale"], (locale: TSfContract["SfLocale"]) => void];
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/sdk/helpers/defaultConfigs.d.ts
|
|
45
|
+
declare const defaultMethodsRequestConfig: {
|
|
46
|
+
readonly unifiedCms: {
|
|
47
|
+
readonly middlewareModule: {
|
|
48
|
+
readonly getEntries: {
|
|
49
|
+
readonly method: "GET";
|
|
50
|
+
};
|
|
51
|
+
readonly getPage: {
|
|
52
|
+
readonly method: "GET";
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
readonly unifiedCommerce: {
|
|
57
|
+
readonly middlewareModule: {
|
|
58
|
+
readonly getCategories: {
|
|
59
|
+
readonly method: "GET";
|
|
60
|
+
};
|
|
61
|
+
readonly getCategory: {
|
|
62
|
+
readonly method: "GET";
|
|
63
|
+
};
|
|
64
|
+
readonly getCurrencies: {
|
|
65
|
+
readonly method: "GET";
|
|
66
|
+
};
|
|
67
|
+
readonly getProductDetails: {
|
|
68
|
+
readonly method: "GET";
|
|
69
|
+
};
|
|
70
|
+
readonly getProductReviews: {
|
|
71
|
+
readonly method: "GET";
|
|
72
|
+
};
|
|
73
|
+
readonly getProducts: {
|
|
74
|
+
readonly method: "GET";
|
|
75
|
+
};
|
|
76
|
+
readonly searchProducts: {
|
|
77
|
+
readonly method: "GET";
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
//#endregion
|
|
83
|
+
//#region src/sdk/types.d.ts
|
|
84
|
+
interface MiddlewareConfig {
|
|
85
|
+
/**
|
|
86
|
+
* The URL of the middleware.
|
|
87
|
+
* @example "http://localhost:4000"
|
|
88
|
+
*/
|
|
89
|
+
apiUrl: string;
|
|
90
|
+
/**
|
|
91
|
+
* This is identifier used to invalidate the cache on CDN when the assets change.
|
|
92
|
+
* Usually it's a commit hash.
|
|
93
|
+
* @example "2c106d9619c71c3082c9b59b1d72817363c8ecb9"
|
|
94
|
+
* @default "no-cache-busting-id-set"
|
|
95
|
+
*/
|
|
96
|
+
cdnCacheBustingId?: string;
|
|
97
|
+
/**
|
|
98
|
+
* The URL of the middleware for server-side rendering.
|
|
99
|
+
* @example "http://localhost:4000"
|
|
100
|
+
*/
|
|
101
|
+
ssrApiUrl: string;
|
|
102
|
+
}
|
|
103
|
+
interface MultistoreConfig {
|
|
104
|
+
/**
|
|
105
|
+
* Whether the multistore is enabled or not.
|
|
106
|
+
* @example false
|
|
107
|
+
* @default false
|
|
108
|
+
*/
|
|
109
|
+
enabled: boolean;
|
|
110
|
+
}
|
|
111
|
+
interface CreateSdkOptions {
|
|
112
|
+
middleware: MiddlewareConfig;
|
|
113
|
+
multistore?: MultistoreConfig;
|
|
114
|
+
}
|
|
115
|
+
type Cookies = Awaited<ReturnType<typeof cookies>>;
|
|
116
|
+
type RequestHeaders = {
|
|
117
|
+
cookies: Cookies;
|
|
118
|
+
headers: Headers;
|
|
119
|
+
} | Headers | undefined;
|
|
120
|
+
type GetSdkContext = {
|
|
121
|
+
/**
|
|
122
|
+
* A function that returns the current locale string;
|
|
123
|
+
*/
|
|
124
|
+
getLocale?: () => string;
|
|
125
|
+
/**
|
|
126
|
+
* A function that returns the request headers.
|
|
127
|
+
*/
|
|
128
|
+
getRequestHeaders?: () => Promise<RequestHeaders> | RequestHeaders;
|
|
129
|
+
};
|
|
130
|
+
type DynamicContext = {
|
|
131
|
+
getRequestHeaders: () => Promise<Record<string, string | string[]>>;
|
|
132
|
+
};
|
|
133
|
+
type StaticContext = {
|
|
134
|
+
buildModule: typeof buildModule;
|
|
135
|
+
config: {
|
|
136
|
+
apiUrl: string;
|
|
137
|
+
cdnCacheBustingId: string;
|
|
138
|
+
defaultMethodsRequestConfig: typeof defaultMethodsRequestConfig;
|
|
139
|
+
ssrApiUrl: string;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* @deprecated Use `config.defaultMethodsRequestConfig` instead.
|
|
143
|
+
*/
|
|
144
|
+
defaults: typeof defaultMethodsRequestConfig;
|
|
145
|
+
middlewareModule: typeof middlewareModule;
|
|
146
|
+
};
|
|
147
|
+
type InjectedContext = DynamicContext & StaticContext;
|
|
148
|
+
type Config<TConfig> = (context: InjectedContext) => TConfig;
|
|
149
|
+
type AlokaiProviderProps<TSdk, TSfContract extends SfContract> = {
|
|
150
|
+
children: ReactNode;
|
|
151
|
+
initialData: SfStateProps<TSfContract>;
|
|
152
|
+
sdk: TSdk;
|
|
153
|
+
};
|
|
154
|
+
interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
155
|
+
/**
|
|
156
|
+
* Creates a new SDK instance. This function is dedicated for server-side usage,
|
|
157
|
+
* where a new SDK instance should be created for each request.
|
|
158
|
+
* For the client side usage, use the `createSdkContext` function instead.
|
|
159
|
+
*
|
|
160
|
+
* @param dynamicContext - The dynamic, request-specific, context
|
|
161
|
+
*
|
|
162
|
+
* @returns The SDK instance.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* For the Pages Router, you can use the `getSdk` function in the `getServerSideProps` function:
|
|
166
|
+
* ```tsx
|
|
167
|
+
* import type { GetServerSideProps } from "next";
|
|
168
|
+
* import { getSdk } from "../../sdk.config";
|
|
169
|
+
*
|
|
170
|
+
* export const getServerSideProps: GetServerSideProps = async ({ req, locale }) => {
|
|
171
|
+
* const sdk = await getSdk({
|
|
172
|
+
* getRequestHeaders: () => Promise.resolve(req.headers),
|
|
173
|
+
* getLocale: () => locale,
|
|
174
|
+
* });
|
|
175
|
+
* const { products } = await sdk.unified.getProducts();
|
|
176
|
+
*
|
|
177
|
+
* return {
|
|
178
|
+
* props: {...}
|
|
179
|
+
* }
|
|
180
|
+
* };
|
|
181
|
+
* ```
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* For the App Router, you can use the `getSdk` function in your React Server Component:
|
|
185
|
+
* ```tsx
|
|
186
|
+
* import { headers } from "next/headers";
|
|
187
|
+
* import { getSdk } from "../../sdk.config";
|
|
188
|
+
*
|
|
189
|
+
* export default async function SsrPage() {
|
|
190
|
+
* const locale = await getLocale();
|
|
191
|
+
* const sdk = await getSdk({
|
|
192
|
+
* getRequestHeaders: () => headers(),
|
|
193
|
+
* getLocale: () => locale,
|
|
194
|
+
* });
|
|
195
|
+
* const { products } = await sdk.unified.getProducts();
|
|
196
|
+
*
|
|
197
|
+
* return <div>...</div>
|
|
198
|
+
* };
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
getSdk: (dynamicContext?: GetSdkContext) => SDKApi<TConfig>;
|
|
202
|
+
}
|
|
203
|
+
type CreateSdkContextReturn<TSdk extends SDKApi<any>, TSfContract extends SfContract> = Readonly<{
|
|
204
|
+
AlokaiProvider: ({
|
|
205
|
+
children
|
|
206
|
+
}: AlokaiProviderProps<TSdk, TSfContract>) => JSX.Element;
|
|
207
|
+
useSdk: () => TSdk;
|
|
208
|
+
useSfCartState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCartState"];
|
|
209
|
+
useSfCurrenciesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrenciesState"];
|
|
210
|
+
useSfCurrencyState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrencyState"];
|
|
211
|
+
useSfCustomerState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCustomerState"];
|
|
212
|
+
useSfLocalesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocalesState"];
|
|
213
|
+
useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
|
|
214
|
+
}>;
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/env/env.d.ts
|
|
217
|
+
/**
|
|
218
|
+
* Retrieves an environment variable value.
|
|
219
|
+
* On the server side, it reads from process.env.
|
|
220
|
+
* On the client side, it reads from window.__ALOKAI_ENV__ to support runtime environment variables.
|
|
221
|
+
*
|
|
222
|
+
* @param key - The environment variable key (e.g., "NEXT_PUBLIC_API_URL")
|
|
223
|
+
* @returns The environment variable value or undefined if not found
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```tsx
|
|
227
|
+
* import { env } from "@vue-storefront/next/client";
|
|
228
|
+
*
|
|
229
|
+
* const apiUrl = env("NEXT_PUBLIC_API_URL");
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
declare function env(key: string): string | undefined;
|
|
233
|
+
//#endregion
|
|
234
|
+
//#region src/env/types.d.ts
|
|
235
|
+
/**
|
|
236
|
+
* Type representing environment variables as key-value pairs
|
|
237
|
+
*/
|
|
238
|
+
interface PublicEnv {
|
|
239
|
+
[key: string]: string | undefined;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Extended window interface to include Alokai environment variables
|
|
243
|
+
*/
|
|
244
|
+
declare global {
|
|
245
|
+
interface Window {
|
|
246
|
+
__ALOKAI_ENV__?: PublicEnv;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
export { CreateSdkReturn as a, SfContract as c, createSfStateProvider as d, CreateSdkOptions as i, SfState as l, Config as n, InjectedContext as o, CreateSdkContextReturn as r, Maybe as s, env as t, SfStateProps as u };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
const require_env = require('./env-Be9N7zqo.cjs');
|
|
2
|
+
const require_client = require('./client.cjs');
|
|
3
|
+
let __alokai_connect_logger = require("@alokai/connect/logger");
|
|
4
|
+
let __alokai_connect_sdk = require("@alokai/connect/sdk");
|
|
5
|
+
|
|
6
|
+
//#region src/logger/injectMetadata.ts
|
|
7
|
+
function injectMetadata(logger, externalData) {
|
|
8
|
+
return new Proxy(logger, { get(target, prop) {
|
|
9
|
+
const targetProp = target[prop];
|
|
10
|
+
if (typeof targetProp === "function") return (...args) => {
|
|
11
|
+
const [logData, metadata] = args;
|
|
12
|
+
targetProp(logData, require_env._objectSpread2(require_env._objectSpread2({}, metadata), externalData));
|
|
13
|
+
};
|
|
14
|
+
return targetProp;
|
|
15
|
+
} });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/logger/index.ts
|
|
20
|
+
const createLogger = (options) => {
|
|
21
|
+
return injectMetadata(__alokai_connect_logger.LoggerFactory.create(__alokai_connect_logger.LoggerType.ConsolaGcp, options), { alokai: { context: "storefront" } });
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/middleware.ts
|
|
26
|
+
/**
|
|
27
|
+
* Creates an Alokai middleware wrapper that adds pathname information to request headers.
|
|
28
|
+
* This is required for proper pathname handling during SSR in Next.js.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* // middleware.ts
|
|
33
|
+
* import { createAlokaiMiddleware } from '@alokai/next';
|
|
34
|
+
*
|
|
35
|
+
* export default createAlokaiMiddleware((request) => {
|
|
36
|
+
* // Your middleware logic here
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param middleware - The Next.js middleware function to wrap
|
|
41
|
+
* @returns A wrapped middleware function that adds pathname to request headers
|
|
42
|
+
*/
|
|
43
|
+
function createAlokaiMiddleware(middleware) {
|
|
44
|
+
return (request) => {
|
|
45
|
+
const nextUrl = request.nextUrl.clone();
|
|
46
|
+
request.headers.append("x-pathname", nextUrl.pathname);
|
|
47
|
+
request.headers.append("x-search", nextUrl.search);
|
|
48
|
+
return middleware(request);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/sdk/helpers/defaultConfigs.ts
|
|
54
|
+
const defaultMethodsRequestConfig = {
|
|
55
|
+
unifiedCms: { middlewareModule: {
|
|
56
|
+
getEntries: { method: "GET" },
|
|
57
|
+
getPage: { method: "GET" }
|
|
58
|
+
} },
|
|
59
|
+
unifiedCommerce: { 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
|
+
//#endregion
|
|
71
|
+
//#region \0@oxc-project+runtime@0.101.0/helpers/asyncToGenerator.js
|
|
72
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
73
|
+
try {
|
|
74
|
+
var i = n[a](c), u = i.value;
|
|
75
|
+
} catch (n$1) {
|
|
76
|
+
e(n$1);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
80
|
+
}
|
|
81
|
+
function _asyncToGenerator(n) {
|
|
82
|
+
return function() {
|
|
83
|
+
var t = this, e = arguments;
|
|
84
|
+
return new Promise(function(r, o) {
|
|
85
|
+
var a = n.apply(t, e);
|
|
86
|
+
function _next(n$1) {
|
|
87
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n$1);
|
|
88
|
+
}
|
|
89
|
+
function _throw(n$1) {
|
|
90
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n$1);
|
|
91
|
+
}
|
|
92
|
+
_next(void 0);
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/sdk/helpers/resolveDynamicContext.ts
|
|
99
|
+
const BLACKLISTED_HEADERS = new Set(["host"]);
|
|
100
|
+
function isAppRouterHeaders(headers) {
|
|
101
|
+
return !!headers && "entries" in headers;
|
|
102
|
+
}
|
|
103
|
+
function isFlatNextHeaders(headers) {
|
|
104
|
+
return !!headers && !("headers" in headers);
|
|
105
|
+
}
|
|
106
|
+
function normalizeRequestHeaders(requestHeaders) {
|
|
107
|
+
const { cookies, headers = {} } = isFlatNextHeaders(requestHeaders) ? {
|
|
108
|
+
cookies: void 0,
|
|
109
|
+
headers: requestHeaders
|
|
110
|
+
} : {
|
|
111
|
+
cookies: requestHeaders === null || requestHeaders === void 0 ? void 0 : requestHeaders.cookies,
|
|
112
|
+
headers: requestHeaders === null || requestHeaders === void 0 ? void 0 : requestHeaders.headers
|
|
113
|
+
};
|
|
114
|
+
const normalizedHeaders = isAppRouterHeaders(headers) ? Object.fromEntries(headers.entries()) : headers;
|
|
115
|
+
if (cookies) normalizedHeaders.cookie = cookies.toString();
|
|
116
|
+
return normalizedHeaders;
|
|
117
|
+
}
|
|
118
|
+
function resolveDynamicContext(context) {
|
|
119
|
+
return require_env._objectSpread2(require_env._objectSpread2({}, context), {}, { getRequestHeaders() {
|
|
120
|
+
return _asyncToGenerator(function* () {
|
|
121
|
+
var _context$getRequestHe;
|
|
122
|
+
const normalizedHeaders = normalizeRequestHeaders(yield (_context$getRequestHe = context.getRequestHeaders) === null || _context$getRequestHe === void 0 ? void 0 : _context$getRequestHe.call(context));
|
|
123
|
+
const requestHeaders = Object.fromEntries(Object.entries(normalizedHeaders).filter(([key]) => !BLACKLISTED_HEADERS.has(key)));
|
|
124
|
+
if (context.getLocale) requestHeaders["x-alokai-locale"] = context.getLocale();
|
|
125
|
+
return requestHeaders;
|
|
126
|
+
})();
|
|
127
|
+
} });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/sdk/index.tsx
|
|
132
|
+
/**
|
|
133
|
+
* Creates an SDK for the given configuration definition.
|
|
134
|
+
* @param options - The options for creating the SDK.
|
|
135
|
+
* @param configDefinition - The configuration definition for the SDK.
|
|
136
|
+
* @returns An object containing the `getSdk` function.
|
|
137
|
+
* @example
|
|
138
|
+
* ```tsx
|
|
139
|
+
* import { contentfulModule } from "@vsf-enterprise/contentful-sdk";
|
|
140
|
+
* import { CreateSdkOptions, createSdk } from "@vue-storefront/next";
|
|
141
|
+
* import type { UnifiedApiEndpoints } from "../storefront-middleware/types";
|
|
142
|
+
*
|
|
143
|
+
* const options: CreateSdkOptions = {
|
|
144
|
+
* middleware: {
|
|
145
|
+
* apiUrl: "http://localhost:4000",
|
|
146
|
+
* ssrApiUrl: "http://localhost:4000",
|
|
147
|
+
* cdnCacheBustingId: "no-cache-busting-id-set",
|
|
148
|
+
* },
|
|
149
|
+
* multistore: {
|
|
150
|
+
* enabled: false,
|
|
151
|
+
* },
|
|
152
|
+
* };
|
|
153
|
+
*
|
|
154
|
+
* export const { getSdk, createSdkContext } = createSdk(
|
|
155
|
+
* options,
|
|
156
|
+
* ({ buildModule, middlewareModule, config, getRequestHeaders }) => ({
|
|
157
|
+
* unified: buildModule(middlewareModule<UnifiedApiEndpoints>, {
|
|
158
|
+
* apiUrl: config.apiUrl + "/commerce",
|
|
159
|
+
* ssrApiUrl: config.ssrApiUrl + "/commerce",
|
|
160
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
161
|
+
* defaultRequestConfig: {
|
|
162
|
+
* headers: getRequestHeaders(),
|
|
163
|
+
* },
|
|
164
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
165
|
+
* }),
|
|
166
|
+
* contentful: buildModule(contentfulModule, {
|
|
167
|
+
* apiUrl: config.apiUrl + "/cntf",
|
|
168
|
+
* ssrApiUrl: config.ssrApiUrl + "/cntf",
|
|
169
|
+
* }),
|
|
170
|
+
* }),
|
|
171
|
+
* );
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
function createSdk(options, configDefinition) {
|
|
175
|
+
function getSdk(dynamicContext = {}) {
|
|
176
|
+
var _options$middleware$c;
|
|
177
|
+
const { getRequestHeaders } = resolveDynamicContext(dynamicContext);
|
|
178
|
+
return (0, __alokai_connect_sdk.initSDK)(configDefinition({
|
|
179
|
+
buildModule: __alokai_connect_sdk.buildModule,
|
|
180
|
+
config: {
|
|
181
|
+
apiUrl: options.middleware.apiUrl,
|
|
182
|
+
cdnCacheBustingId: (_options$middleware$c = options.middleware.cdnCacheBustingId) !== null && _options$middleware$c !== void 0 ? _options$middleware$c : "no-cache-busting-id-set",
|
|
183
|
+
defaultMethodsRequestConfig,
|
|
184
|
+
ssrApiUrl: options.middleware.ssrApiUrl
|
|
185
|
+
},
|
|
186
|
+
defaults: defaultMethodsRequestConfig,
|
|
187
|
+
getRequestHeaders,
|
|
188
|
+
middlewareModule: __alokai_connect_sdk.middlewareModule
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
return { getSdk };
|
|
192
|
+
}
|
|
193
|
+
function defineSdkConfig(config) {
|
|
194
|
+
if (typeof config === "function") return config;
|
|
195
|
+
return buildModules(config);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Helper function to resolve the SDK options based on the configuration.
|
|
199
|
+
*
|
|
200
|
+
* @privateRemarks
|
|
201
|
+
* For now this file only verifies the type of the input and simply returns it.
|
|
202
|
+
* However, in the future we might need it to perform true input resolution.
|
|
203
|
+
*
|
|
204
|
+
* @param input - The options for creating the SDK.
|
|
205
|
+
* @param options - The configuration object, that allows to customize the API Url creation on enabled multistore.
|
|
206
|
+
*
|
|
207
|
+
* @returns The resolved SDK options.
|
|
208
|
+
*/
|
|
209
|
+
function resolveSdkOptions(input, _options = {}) {
|
|
210
|
+
return input;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Defines an SDK module that can be used with defineSdkConfig.
|
|
214
|
+
* Each module is a function that takes the InjectedContext and returns a built module.
|
|
215
|
+
*
|
|
216
|
+
* @param moduleDefinition - A function that takes InjectedContext and returns a built module
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```tsx
|
|
220
|
+
* import { defineSdkModule } from '@vue-storefront/next';
|
|
221
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
222
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
223
|
+
*
|
|
224
|
+
* export const unified = defineSdkModule(({ buildModule, config, getRequestHeaders, middlewareModule }) =>
|
|
225
|
+
* buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
226
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
227
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
228
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
229
|
+
* defaultRequestConfig: {
|
|
230
|
+
* getConfigSwitcherHeader,
|
|
231
|
+
* headers: getRequestHeaders(),
|
|
232
|
+
* },
|
|
233
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
234
|
+
* }),
|
|
235
|
+
* );
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
function defineSdkModule(moduleDefinition) {
|
|
239
|
+
return moduleDefinition;
|
|
240
|
+
}
|
|
241
|
+
function buildModules(modules) {
|
|
242
|
+
return (context) => Object.fromEntries(Object.entries(modules).map(([key, module$1]) => [key, module$1(context)]));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
//#endregion
|
|
246
|
+
exports.createAlokaiMiddleware = createAlokaiMiddleware;
|
|
247
|
+
exports.createLogger = createLogger;
|
|
248
|
+
exports.createSdk = createSdk;
|
|
249
|
+
Object.defineProperty(exports, 'defineGetConfigSwitcherHeader', {
|
|
250
|
+
enumerable: true,
|
|
251
|
+
get: function () {
|
|
252
|
+
return __alokai_connect_sdk.defineGetConfigSwitcherHeader;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
exports.defineSdkConfig = defineSdkConfig;
|
|
256
|
+
exports.defineSdkModule = defineSdkModule;
|
|
257
|
+
exports.env = require_env.env;
|
|
258
|
+
exports.resolveSdkOptions = resolveSdkOptions;
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import * as
|
|
4
|
-
import { NextRequest, NextResponse } from
|
|
5
|
-
import { buildModule } from '@alokai/connect/sdk';
|
|
6
|
-
export { defineGetConfigSwitcherHeader } from '@alokai/connect/sdk';
|
|
7
|
-
import 'next/headers';
|
|
8
|
-
import 'react';
|
|
1
|
+
import { a as CreateSdkReturn, i as CreateSdkOptions, n as Config, o as InjectedContext, t as env } from "./index-D1weTw7N.cjs";
|
|
2
|
+
import { buildModule, defineGetConfigSwitcherHeader } from "@alokai/connect/sdk";
|
|
3
|
+
import * as _alokai_connect_logger0 from "@alokai/connect/logger";
|
|
4
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
9
5
|
|
|
6
|
+
//#region src/logger/types.d.ts
|
|
10
7
|
type LogVerbosity = "alert" | "critical" | "debug" | "emergency" | "error" | "info" | "notice" | "warning";
|
|
11
8
|
type LoggerOptions = Partial<{
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
includeStackTrace: boolean;
|
|
10
|
+
verbosity: LogVerbosity;
|
|
14
11
|
}>;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/logger/index.d.ts
|
|
14
|
+
declare const createLogger: (options?: LoggerOptions) => _alokai_connect_logger0.LoggerInterface;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/middleware.d.ts
|
|
18
17
|
type NextMiddleware = (request: NextRequest) => NextResponse | Promise<NextResponse>;
|
|
19
18
|
/**
|
|
20
19
|
* Creates an Alokai middleware wrapper that adds pathname information to request headers.
|
|
@@ -34,7 +33,8 @@ type NextMiddleware = (request: NextRequest) => NextResponse | Promise<NextRespo
|
|
|
34
33
|
* @returns A wrapped middleware function that adds pathname to request headers
|
|
35
34
|
*/
|
|
36
35
|
declare function createAlokaiMiddleware(middleware: NextMiddleware): (request: NextRequest) => NextResponse<unknown> | Promise<NextResponse<unknown>>;
|
|
37
|
-
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/sdk/index.d.ts
|
|
38
38
|
/**
|
|
39
39
|
* Creates an SDK for the given configuration definition.
|
|
40
40
|
* @param options - The options for creating the SDK.
|
|
@@ -130,11 +130,9 @@ declare function createSdk<TConfig extends Record<string, any>>(options: CreateS
|
|
|
130
130
|
* ```
|
|
131
131
|
*/
|
|
132
132
|
declare function defineSdkConfig<TConfig extends Record<string, any>>(config: Config<TConfig>): Config<TConfig>;
|
|
133
|
-
declare function defineSdkConfig<TModules extends Record<string, DefineSdkModule>>(modules: TModules): (context: InjectedContext) => {
|
|
134
|
-
[K in keyof TModules]: ReturnType<TModules[K]>;
|
|
135
|
-
};
|
|
133
|
+
declare function defineSdkConfig<TModules extends Record<string, DefineSdkModule>>(modules: TModules): (context: InjectedContext) => { [K in keyof TModules]: ReturnType<TModules[K]> };
|
|
136
134
|
type ResolveSdkOptionsConfig = {
|
|
137
|
-
|
|
135
|
+
customSuffix: string;
|
|
138
136
|
};
|
|
139
137
|
/**
|
|
140
138
|
* Helper function to resolve the SDK options based on the configuration.
|
|
@@ -177,5 +175,5 @@ type DefineSdkModule = (context: InjectedContext) => ReturnType<typeof buildModu
|
|
|
177
175
|
* ```
|
|
178
176
|
*/
|
|
179
177
|
declare function defineSdkModule<TModuleDefinition extends DefineSdkModule>(moduleDefinition: TModuleDefinition): TModuleDefinition;
|
|
180
|
-
|
|
181
|
-
export { CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineSdkConfig, defineSdkModule, resolveSdkOptions };
|
|
178
|
+
//#endregion
|
|
179
|
+
export { type CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineGetConfigSwitcherHeader, defineSdkConfig, defineSdkModule, env, resolveSdkOptions };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import { NextRequest, NextResponse } from
|
|
5
|
-
import { buildModule } from '@alokai/connect/sdk';
|
|
6
|
-
export { defineGetConfigSwitcherHeader } from '@alokai/connect/sdk';
|
|
7
|
-
import 'next/headers';
|
|
8
|
-
import 'react';
|
|
1
|
+
import { a as CreateSdkReturn, i as CreateSdkOptions, n as Config, o as InjectedContext, t as env } from "./index-BXYjHxeC.mjs";
|
|
2
|
+
import * as _alokai_connect_logger0 from "@alokai/connect/logger";
|
|
3
|
+
import { buildModule, defineGetConfigSwitcherHeader } from "@alokai/connect/sdk";
|
|
4
|
+
import { NextRequest, NextResponse } from "next/server";
|
|
9
5
|
|
|
6
|
+
//#region src/logger/types.d.ts
|
|
10
7
|
type LogVerbosity = "alert" | "critical" | "debug" | "emergency" | "error" | "info" | "notice" | "warning";
|
|
11
8
|
type LoggerOptions = Partial<{
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
includeStackTrace: boolean;
|
|
10
|
+
verbosity: LogVerbosity;
|
|
14
11
|
}>;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/logger/index.d.ts
|
|
14
|
+
declare const createLogger: (options?: LoggerOptions) => _alokai_connect_logger0.LoggerInterface;
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/middleware.d.ts
|
|
18
17
|
type NextMiddleware = (request: NextRequest) => NextResponse | Promise<NextResponse>;
|
|
19
18
|
/**
|
|
20
19
|
* Creates an Alokai middleware wrapper that adds pathname information to request headers.
|
|
@@ -34,7 +33,8 @@ type NextMiddleware = (request: NextRequest) => NextResponse | Promise<NextRespo
|
|
|
34
33
|
* @returns A wrapped middleware function that adds pathname to request headers
|
|
35
34
|
*/
|
|
36
35
|
declare function createAlokaiMiddleware(middleware: NextMiddleware): (request: NextRequest) => NextResponse<unknown> | Promise<NextResponse<unknown>>;
|
|
37
|
-
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/sdk/index.d.ts
|
|
38
38
|
/**
|
|
39
39
|
* Creates an SDK for the given configuration definition.
|
|
40
40
|
* @param options - The options for creating the SDK.
|
|
@@ -130,11 +130,9 @@ declare function createSdk<TConfig extends Record<string, any>>(options: CreateS
|
|
|
130
130
|
* ```
|
|
131
131
|
*/
|
|
132
132
|
declare function defineSdkConfig<TConfig extends Record<string, any>>(config: Config<TConfig>): Config<TConfig>;
|
|
133
|
-
declare function defineSdkConfig<TModules extends Record<string, DefineSdkModule>>(modules: TModules): (context: InjectedContext) => {
|
|
134
|
-
[K in keyof TModules]: ReturnType<TModules[K]>;
|
|
135
|
-
};
|
|
133
|
+
declare function defineSdkConfig<TModules extends Record<string, DefineSdkModule>>(modules: TModules): (context: InjectedContext) => { [K in keyof TModules]: ReturnType<TModules[K]> };
|
|
136
134
|
type ResolveSdkOptionsConfig = {
|
|
137
|
-
|
|
135
|
+
customSuffix: string;
|
|
138
136
|
};
|
|
139
137
|
/**
|
|
140
138
|
* Helper function to resolve the SDK options based on the configuration.
|
|
@@ -177,5 +175,5 @@ type DefineSdkModule = (context: InjectedContext) => ReturnType<typeof buildModu
|
|
|
177
175
|
* ```
|
|
178
176
|
*/
|
|
179
177
|
declare function defineSdkModule<TModuleDefinition extends DefineSdkModule>(moduleDefinition: TModuleDefinition): TModuleDefinition;
|
|
180
|
-
|
|
181
|
-
export { CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineSdkConfig, defineSdkModule, resolveSdkOptions };
|
|
178
|
+
//#endregion
|
|
179
|
+
export { type CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineGetConfigSwitcherHeader, defineSdkConfig, defineSdkModule, env, resolveSdkOptions };
|