@vue-storefront/next 0.0.0-20250722194236
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/LICENSE.md +21 -0
- package/README.md +124 -0
- package/dist/chunk-FWCSY2DS.mjs +37 -0
- package/dist/client.d.mts +45 -0
- package/dist/client.d.ts +45 -0
- package/dist/client.js +201 -0
- package/dist/client.mjs +144 -0
- package/dist/index.d.mts +180 -0
- package/dist/index.d.ts +180 -0
- package/dist/index.js +202 -0
- package/dist/index.mjs +157 -0
- package/dist/types-B9h_AU7R.d.mts +209 -0
- package/dist/types-B9h_AU7R.d.ts +209 -0
- package/package.json +58 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__spreadProps,
|
|
3
|
+
__spreadValues
|
|
4
|
+
} from "./chunk-FWCSY2DS.mjs";
|
|
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
|
+
request.headers.append("x-search", nextUrl.search);
|
|
41
|
+
return middleware(request);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/sdk/index.tsx
|
|
46
|
+
import { buildModule, initSDK, middlewareModule } from "@alokai/connect/sdk";
|
|
47
|
+
|
|
48
|
+
// src/sdk/helpers/defaultConfigs.ts
|
|
49
|
+
var defaultMethodsRequestConfig = {
|
|
50
|
+
unifiedCms: {
|
|
51
|
+
middlewareModule: {
|
|
52
|
+
getEntries: { method: "GET" },
|
|
53
|
+
getPage: { method: "GET" }
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
unifiedCommerce: {
|
|
57
|
+
middlewareModule: {
|
|
58
|
+
getCategories: { method: "GET" },
|
|
59
|
+
getCategory: { method: "GET" },
|
|
60
|
+
getCurrencies: { method: "GET" },
|
|
61
|
+
getProductDetails: { method: "GET" },
|
|
62
|
+
getProductReviews: { method: "GET" },
|
|
63
|
+
getProducts: { method: "GET" },
|
|
64
|
+
searchProducts: { method: "GET" }
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/sdk/helpers/resolveDynamicContext.ts
|
|
70
|
+
var BLACKLISTED_HEADERS = /* @__PURE__ */ new Set(["host"]);
|
|
71
|
+
function isAppRouterHeaders(headers) {
|
|
72
|
+
return !!headers && "entries" in headers;
|
|
73
|
+
}
|
|
74
|
+
function isFlatNextHeaders(headers) {
|
|
75
|
+
return !!headers && !("headers" in headers);
|
|
76
|
+
}
|
|
77
|
+
function normalizeRequestHeaders(requestHeaders) {
|
|
78
|
+
const { cookies, headers = {} } = isFlatNextHeaders(requestHeaders) ? { cookies: void 0, headers: requestHeaders } : {
|
|
79
|
+
cookies: requestHeaders == null ? void 0 : requestHeaders.cookies,
|
|
80
|
+
headers: requestHeaders == null ? void 0 : requestHeaders.headers
|
|
81
|
+
};
|
|
82
|
+
const normalizedHeaders = isAppRouterHeaders(headers) ? Object.fromEntries(headers.entries()) : headers;
|
|
83
|
+
if (cookies) {
|
|
84
|
+
normalizedHeaders.cookie = cookies.toString();
|
|
85
|
+
}
|
|
86
|
+
return normalizedHeaders;
|
|
87
|
+
}
|
|
88
|
+
function resolveDynamicContext(context) {
|
|
89
|
+
return __spreadProps(__spreadValues({}, context), {
|
|
90
|
+
getRequestHeaders() {
|
|
91
|
+
var _a;
|
|
92
|
+
const normalizedHeaders = normalizeRequestHeaders(
|
|
93
|
+
(_a = context.getRequestHeaders) == null ? void 0 : _a.call(context)
|
|
94
|
+
);
|
|
95
|
+
const requestHeaders = Object.fromEntries(
|
|
96
|
+
Object.entries(normalizedHeaders).filter(
|
|
97
|
+
([key]) => !BLACKLISTED_HEADERS.has(key)
|
|
98
|
+
)
|
|
99
|
+
);
|
|
100
|
+
if (context.getLocale) {
|
|
101
|
+
requestHeaders["x-alokai-locale"] = context.getLocale();
|
|
102
|
+
}
|
|
103
|
+
return requestHeaders;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// src/sdk/index.tsx
|
|
109
|
+
import { defineGetConfigSwitcherHeader } from "@alokai/connect/sdk";
|
|
110
|
+
function createSdk(options, configDefinition) {
|
|
111
|
+
function getSdk(dynamicContext = {}) {
|
|
112
|
+
var _a;
|
|
113
|
+
const { getRequestHeaders } = resolveDynamicContext(dynamicContext);
|
|
114
|
+
const resolvedConfig = configDefinition({
|
|
115
|
+
buildModule,
|
|
116
|
+
config: {
|
|
117
|
+
apiUrl: options.middleware.apiUrl,
|
|
118
|
+
cdnCacheBustingId: (_a = options.middleware.cdnCacheBustingId) != null ? _a : "no-cache-busting-id-set",
|
|
119
|
+
defaultMethodsRequestConfig,
|
|
120
|
+
ssrApiUrl: options.middleware.ssrApiUrl
|
|
121
|
+
},
|
|
122
|
+
defaults: defaultMethodsRequestConfig,
|
|
123
|
+
getRequestHeaders,
|
|
124
|
+
middlewareModule
|
|
125
|
+
});
|
|
126
|
+
return initSDK(resolvedConfig);
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
getSdk
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function defineSdkConfig(config) {
|
|
133
|
+
if (typeof config === "function") {
|
|
134
|
+
return config;
|
|
135
|
+
}
|
|
136
|
+
return buildModules(config);
|
|
137
|
+
}
|
|
138
|
+
function resolveSdkOptions(input, _options = {}) {
|
|
139
|
+
return input;
|
|
140
|
+
}
|
|
141
|
+
function defineSdkModule(moduleDefinition) {
|
|
142
|
+
return moduleDefinition;
|
|
143
|
+
}
|
|
144
|
+
function buildModules(modules) {
|
|
145
|
+
return (context) => Object.fromEntries(
|
|
146
|
+
Object.entries(modules).map(([key, module]) => [key, module(context)])
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
export {
|
|
150
|
+
createAlokaiMiddleware,
|
|
151
|
+
createLogger,
|
|
152
|
+
createSdk,
|
|
153
|
+
defineGetConfigSwitcherHeader,
|
|
154
|
+
defineSdkConfig,
|
|
155
|
+
defineSdkModule,
|
|
156
|
+
resolveSdkOptions
|
|
157
|
+
};
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { SDKApi, buildModule, middlewareModule } from '@alokai/connect/sdk';
|
|
2
|
+
import { cookies } from 'next/headers';
|
|
3
|
+
import React, { PropsWithChildren, ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
type Maybe<TType> = null | TType;
|
|
6
|
+
|
|
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: ({ children, initialData, }: {
|
|
31
|
+
initialData: SfStateProps<TSfContract>;
|
|
32
|
+
} & PropsWithChildren) => React.JSX.Element;
|
|
33
|
+
useSfCartState: () => [null | TSfContract["SfCart"] | undefined, (cart?: null | TSfContract["SfCart"]) => void];
|
|
34
|
+
useSfCurrenciesState: () => [TSfContract["SfCurrency"][], (currencies: TSfContract["SfCurrency"][]) => void];
|
|
35
|
+
useSfCurrencyState: () => [TSfContract["SfCurrency"], (currency: TSfContract["SfCurrency"]) => void];
|
|
36
|
+
useSfCustomerState: () => [null | TSfContract["SfCustomer"] | undefined, (customer?: null | TSfContract["SfCustomer"]) => void];
|
|
37
|
+
useSfLocalesState: () => [TSfContract["SfLocale"][], (locales: TSfContract["SfLocale"][]) => void];
|
|
38
|
+
useSfLocaleState: () => [TSfContract["SfLocale"], (locale: TSfContract["SfLocale"]) => void];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
declare const defaultMethodsRequestConfig: {
|
|
42
|
+
readonly unifiedCms: {
|
|
43
|
+
readonly middlewareModule: {
|
|
44
|
+
readonly getEntries: {
|
|
45
|
+
readonly method: "GET";
|
|
46
|
+
};
|
|
47
|
+
readonly getPage: {
|
|
48
|
+
readonly method: "GET";
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
readonly unifiedCommerce: {
|
|
53
|
+
readonly middlewareModule: {
|
|
54
|
+
readonly getCategories: {
|
|
55
|
+
readonly method: "GET";
|
|
56
|
+
};
|
|
57
|
+
readonly getCategory: {
|
|
58
|
+
readonly method: "GET";
|
|
59
|
+
};
|
|
60
|
+
readonly getCurrencies: {
|
|
61
|
+
readonly method: "GET";
|
|
62
|
+
};
|
|
63
|
+
readonly getProductDetails: {
|
|
64
|
+
readonly method: "GET";
|
|
65
|
+
};
|
|
66
|
+
readonly getProductReviews: {
|
|
67
|
+
readonly method: "GET";
|
|
68
|
+
};
|
|
69
|
+
readonly getProducts: {
|
|
70
|
+
readonly method: "GET";
|
|
71
|
+
};
|
|
72
|
+
readonly searchProducts: {
|
|
73
|
+
readonly method: "GET";
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
interface MiddlewareConfig {
|
|
80
|
+
/**
|
|
81
|
+
* The URL of the middleware.
|
|
82
|
+
* @example "http://localhost:4000"
|
|
83
|
+
*/
|
|
84
|
+
apiUrl: string;
|
|
85
|
+
/**
|
|
86
|
+
* This is identifier used to invalidate the cache on CDN when the assets change.
|
|
87
|
+
* Usually it's a commit hash.
|
|
88
|
+
* @example "2c106d9619c71c3082c9b59b1d72817363c8ecb9"
|
|
89
|
+
* @default "no-cache-busting-id-set"
|
|
90
|
+
*/
|
|
91
|
+
cdnCacheBustingId?: string;
|
|
92
|
+
/**
|
|
93
|
+
* The URL of the middleware for server-side rendering.
|
|
94
|
+
* @example "http://localhost:4000"
|
|
95
|
+
*/
|
|
96
|
+
ssrApiUrl: string;
|
|
97
|
+
}
|
|
98
|
+
interface MultistoreConfig {
|
|
99
|
+
/**
|
|
100
|
+
* Whether the multistore is enabled or not.
|
|
101
|
+
* @example false
|
|
102
|
+
* @default false
|
|
103
|
+
*/
|
|
104
|
+
enabled: boolean;
|
|
105
|
+
}
|
|
106
|
+
interface CreateSdkOptions {
|
|
107
|
+
middleware: MiddlewareConfig;
|
|
108
|
+
multistore?: MultistoreConfig;
|
|
109
|
+
}
|
|
110
|
+
type Cookies = ReturnType<typeof cookies>;
|
|
111
|
+
type NextHeaders = Headers | Record<string, string | string[] | undefined>;
|
|
112
|
+
type GetSdkContext = {
|
|
113
|
+
/**
|
|
114
|
+
* A function that returns the current locale string;
|
|
115
|
+
*/
|
|
116
|
+
getLocale?: () => string;
|
|
117
|
+
/**
|
|
118
|
+
* A function that returns the request headers.
|
|
119
|
+
*/
|
|
120
|
+
getRequestHeaders?: () => {
|
|
121
|
+
cookies: Cookies;
|
|
122
|
+
headers: NextHeaders;
|
|
123
|
+
} | NextHeaders;
|
|
124
|
+
};
|
|
125
|
+
type DynamicContext = {
|
|
126
|
+
getRequestHeaders: () => Record<string, string | string[]>;
|
|
127
|
+
};
|
|
128
|
+
type StaticContext = {
|
|
129
|
+
buildModule: typeof buildModule;
|
|
130
|
+
config: {
|
|
131
|
+
apiUrl: string;
|
|
132
|
+
cdnCacheBustingId: string;
|
|
133
|
+
defaultMethodsRequestConfig: typeof defaultMethodsRequestConfig;
|
|
134
|
+
ssrApiUrl: string;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* @deprecated Use `config.defaultMethodsRequestConfig` instead.
|
|
138
|
+
*/
|
|
139
|
+
defaults: typeof defaultMethodsRequestConfig;
|
|
140
|
+
middlewareModule: typeof middlewareModule;
|
|
141
|
+
};
|
|
142
|
+
type InjectedContext = DynamicContext & StaticContext;
|
|
143
|
+
type Config<TConfig> = (context: InjectedContext) => TConfig;
|
|
144
|
+
type AlokaiProviderProps<TSdk, TSfContract extends SfContract> = {
|
|
145
|
+
children: ReactNode;
|
|
146
|
+
initialData: SfStateProps<TSfContract>;
|
|
147
|
+
sdk: TSdk;
|
|
148
|
+
};
|
|
149
|
+
interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
150
|
+
/**
|
|
151
|
+
* Creates a new SDK instance. This function is dedicated for server-side usage,
|
|
152
|
+
* where a new SDK instance should be created for each request.
|
|
153
|
+
* For the client side usage, use the `createSdkContext` function instead.
|
|
154
|
+
*
|
|
155
|
+
* @param dynamicContext - The dynamic, request-specific, context
|
|
156
|
+
*
|
|
157
|
+
* @returns The SDK instance.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* For the Pages Router, you can use the `getSdk` function in the `getServerSideProps` function:
|
|
161
|
+
* ```tsx
|
|
162
|
+
* import type { GetServerSideProps } from "next";
|
|
163
|
+
* import { getSdk } from "../../sdk.config";
|
|
164
|
+
*
|
|
165
|
+
* export const getServerSideProps: GetServerSideProps = async ({ req, locale }) => {
|
|
166
|
+
* const sdk = await getSdk({
|
|
167
|
+
* getRequestHeaders: () => req.headers,
|
|
168
|
+
* getLocale: () => locale,
|
|
169
|
+
* });
|
|
170
|
+
* const { products } = await sdk.unified.getProducts();
|
|
171
|
+
*
|
|
172
|
+
* return {
|
|
173
|
+
* props: {...}
|
|
174
|
+
* }
|
|
175
|
+
* };
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* For the App Router, you can use the `getSdk` function in your React Server Component:
|
|
180
|
+
* ```tsx
|
|
181
|
+
* import { headers } from "next/headers";
|
|
182
|
+
* import { getSdk } from "../../sdk.config";
|
|
183
|
+
*
|
|
184
|
+
* export default async function SsrPage() {
|
|
185
|
+
* const locale = await getLocale();
|
|
186
|
+
* const sdk = await getSdk({
|
|
187
|
+
* getRequestHeaders: () => headers(),
|
|
188
|
+
* getLocale: () => locale,
|
|
189
|
+
* });
|
|
190
|
+
* const { products } = await sdk.unified.getProducts();
|
|
191
|
+
*
|
|
192
|
+
* return <div>...</div>
|
|
193
|
+
* };
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
getSdk: (dynamicContext?: GetSdkContext) => SDKApi<TConfig>;
|
|
197
|
+
}
|
|
198
|
+
type CreateSdkContextReturn<TSdk extends SDKApi<any>, TSfContract extends SfContract> = Readonly<{
|
|
199
|
+
AlokaiProvider: ({ children, }: AlokaiProviderProps<TSdk, TSfContract>) => JSX.Element;
|
|
200
|
+
useSdk: () => TSdk;
|
|
201
|
+
useSfCartState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCartState"];
|
|
202
|
+
useSfCurrenciesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrenciesState"];
|
|
203
|
+
useSfCurrencyState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrencyState"];
|
|
204
|
+
useSfCustomerState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCustomerState"];
|
|
205
|
+
useSfLocalesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocalesState"];
|
|
206
|
+
useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
|
|
207
|
+
}>;
|
|
208
|
+
|
|
209
|
+
export { type CreateSdkContextReturn as C, type InjectedContext as I, type Maybe as M, type SfContract as S, type SfStateProps as a, type SfState as b, createSfStateProvider as c, type CreateSdkOptions as d, type Config as e, type CreateSdkReturn as f };
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { SDKApi, buildModule, middlewareModule } from '@alokai/connect/sdk';
|
|
2
|
+
import { cookies } from 'next/headers';
|
|
3
|
+
import React, { PropsWithChildren, ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
type Maybe<TType> = null | TType;
|
|
6
|
+
|
|
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: ({ children, initialData, }: {
|
|
31
|
+
initialData: SfStateProps<TSfContract>;
|
|
32
|
+
} & PropsWithChildren) => React.JSX.Element;
|
|
33
|
+
useSfCartState: () => [null | TSfContract["SfCart"] | undefined, (cart?: null | TSfContract["SfCart"]) => void];
|
|
34
|
+
useSfCurrenciesState: () => [TSfContract["SfCurrency"][], (currencies: TSfContract["SfCurrency"][]) => void];
|
|
35
|
+
useSfCurrencyState: () => [TSfContract["SfCurrency"], (currency: TSfContract["SfCurrency"]) => void];
|
|
36
|
+
useSfCustomerState: () => [null | TSfContract["SfCustomer"] | undefined, (customer?: null | TSfContract["SfCustomer"]) => void];
|
|
37
|
+
useSfLocalesState: () => [TSfContract["SfLocale"][], (locales: TSfContract["SfLocale"][]) => void];
|
|
38
|
+
useSfLocaleState: () => [TSfContract["SfLocale"], (locale: TSfContract["SfLocale"]) => void];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
declare const defaultMethodsRequestConfig: {
|
|
42
|
+
readonly unifiedCms: {
|
|
43
|
+
readonly middlewareModule: {
|
|
44
|
+
readonly getEntries: {
|
|
45
|
+
readonly method: "GET";
|
|
46
|
+
};
|
|
47
|
+
readonly getPage: {
|
|
48
|
+
readonly method: "GET";
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
readonly unifiedCommerce: {
|
|
53
|
+
readonly middlewareModule: {
|
|
54
|
+
readonly getCategories: {
|
|
55
|
+
readonly method: "GET";
|
|
56
|
+
};
|
|
57
|
+
readonly getCategory: {
|
|
58
|
+
readonly method: "GET";
|
|
59
|
+
};
|
|
60
|
+
readonly getCurrencies: {
|
|
61
|
+
readonly method: "GET";
|
|
62
|
+
};
|
|
63
|
+
readonly getProductDetails: {
|
|
64
|
+
readonly method: "GET";
|
|
65
|
+
};
|
|
66
|
+
readonly getProductReviews: {
|
|
67
|
+
readonly method: "GET";
|
|
68
|
+
};
|
|
69
|
+
readonly getProducts: {
|
|
70
|
+
readonly method: "GET";
|
|
71
|
+
};
|
|
72
|
+
readonly searchProducts: {
|
|
73
|
+
readonly method: "GET";
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
interface MiddlewareConfig {
|
|
80
|
+
/**
|
|
81
|
+
* The URL of the middleware.
|
|
82
|
+
* @example "http://localhost:4000"
|
|
83
|
+
*/
|
|
84
|
+
apiUrl: string;
|
|
85
|
+
/**
|
|
86
|
+
* This is identifier used to invalidate the cache on CDN when the assets change.
|
|
87
|
+
* Usually it's a commit hash.
|
|
88
|
+
* @example "2c106d9619c71c3082c9b59b1d72817363c8ecb9"
|
|
89
|
+
* @default "no-cache-busting-id-set"
|
|
90
|
+
*/
|
|
91
|
+
cdnCacheBustingId?: string;
|
|
92
|
+
/**
|
|
93
|
+
* The URL of the middleware for server-side rendering.
|
|
94
|
+
* @example "http://localhost:4000"
|
|
95
|
+
*/
|
|
96
|
+
ssrApiUrl: string;
|
|
97
|
+
}
|
|
98
|
+
interface MultistoreConfig {
|
|
99
|
+
/**
|
|
100
|
+
* Whether the multistore is enabled or not.
|
|
101
|
+
* @example false
|
|
102
|
+
* @default false
|
|
103
|
+
*/
|
|
104
|
+
enabled: boolean;
|
|
105
|
+
}
|
|
106
|
+
interface CreateSdkOptions {
|
|
107
|
+
middleware: MiddlewareConfig;
|
|
108
|
+
multistore?: MultistoreConfig;
|
|
109
|
+
}
|
|
110
|
+
type Cookies = ReturnType<typeof cookies>;
|
|
111
|
+
type NextHeaders = Headers | Record<string, string | string[] | undefined>;
|
|
112
|
+
type GetSdkContext = {
|
|
113
|
+
/**
|
|
114
|
+
* A function that returns the current locale string;
|
|
115
|
+
*/
|
|
116
|
+
getLocale?: () => string;
|
|
117
|
+
/**
|
|
118
|
+
* A function that returns the request headers.
|
|
119
|
+
*/
|
|
120
|
+
getRequestHeaders?: () => {
|
|
121
|
+
cookies: Cookies;
|
|
122
|
+
headers: NextHeaders;
|
|
123
|
+
} | NextHeaders;
|
|
124
|
+
};
|
|
125
|
+
type DynamicContext = {
|
|
126
|
+
getRequestHeaders: () => Record<string, string | string[]>;
|
|
127
|
+
};
|
|
128
|
+
type StaticContext = {
|
|
129
|
+
buildModule: typeof buildModule;
|
|
130
|
+
config: {
|
|
131
|
+
apiUrl: string;
|
|
132
|
+
cdnCacheBustingId: string;
|
|
133
|
+
defaultMethodsRequestConfig: typeof defaultMethodsRequestConfig;
|
|
134
|
+
ssrApiUrl: string;
|
|
135
|
+
};
|
|
136
|
+
/**
|
|
137
|
+
* @deprecated Use `config.defaultMethodsRequestConfig` instead.
|
|
138
|
+
*/
|
|
139
|
+
defaults: typeof defaultMethodsRequestConfig;
|
|
140
|
+
middlewareModule: typeof middlewareModule;
|
|
141
|
+
};
|
|
142
|
+
type InjectedContext = DynamicContext & StaticContext;
|
|
143
|
+
type Config<TConfig> = (context: InjectedContext) => TConfig;
|
|
144
|
+
type AlokaiProviderProps<TSdk, TSfContract extends SfContract> = {
|
|
145
|
+
children: ReactNode;
|
|
146
|
+
initialData: SfStateProps<TSfContract>;
|
|
147
|
+
sdk: TSdk;
|
|
148
|
+
};
|
|
149
|
+
interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
150
|
+
/**
|
|
151
|
+
* Creates a new SDK instance. This function is dedicated for server-side usage,
|
|
152
|
+
* where a new SDK instance should be created for each request.
|
|
153
|
+
* For the client side usage, use the `createSdkContext` function instead.
|
|
154
|
+
*
|
|
155
|
+
* @param dynamicContext - The dynamic, request-specific, context
|
|
156
|
+
*
|
|
157
|
+
* @returns The SDK instance.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* For the Pages Router, you can use the `getSdk` function in the `getServerSideProps` function:
|
|
161
|
+
* ```tsx
|
|
162
|
+
* import type { GetServerSideProps } from "next";
|
|
163
|
+
* import { getSdk } from "../../sdk.config";
|
|
164
|
+
*
|
|
165
|
+
* export const getServerSideProps: GetServerSideProps = async ({ req, locale }) => {
|
|
166
|
+
* const sdk = await getSdk({
|
|
167
|
+
* getRequestHeaders: () => req.headers,
|
|
168
|
+
* getLocale: () => locale,
|
|
169
|
+
* });
|
|
170
|
+
* const { products } = await sdk.unified.getProducts();
|
|
171
|
+
*
|
|
172
|
+
* return {
|
|
173
|
+
* props: {...}
|
|
174
|
+
* }
|
|
175
|
+
* };
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* For the App Router, you can use the `getSdk` function in your React Server Component:
|
|
180
|
+
* ```tsx
|
|
181
|
+
* import { headers } from "next/headers";
|
|
182
|
+
* import { getSdk } from "../../sdk.config";
|
|
183
|
+
*
|
|
184
|
+
* export default async function SsrPage() {
|
|
185
|
+
* const locale = await getLocale();
|
|
186
|
+
* const sdk = await getSdk({
|
|
187
|
+
* getRequestHeaders: () => headers(),
|
|
188
|
+
* getLocale: () => locale,
|
|
189
|
+
* });
|
|
190
|
+
* const { products } = await sdk.unified.getProducts();
|
|
191
|
+
*
|
|
192
|
+
* return <div>...</div>
|
|
193
|
+
* };
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
getSdk: (dynamicContext?: GetSdkContext) => SDKApi<TConfig>;
|
|
197
|
+
}
|
|
198
|
+
type CreateSdkContextReturn<TSdk extends SDKApi<any>, TSfContract extends SfContract> = Readonly<{
|
|
199
|
+
AlokaiProvider: ({ children, }: AlokaiProviderProps<TSdk, TSfContract>) => JSX.Element;
|
|
200
|
+
useSdk: () => TSdk;
|
|
201
|
+
useSfCartState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCartState"];
|
|
202
|
+
useSfCurrenciesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrenciesState"];
|
|
203
|
+
useSfCurrencyState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrencyState"];
|
|
204
|
+
useSfCustomerState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCustomerState"];
|
|
205
|
+
useSfLocalesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocalesState"];
|
|
206
|
+
useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
|
|
207
|
+
}>;
|
|
208
|
+
|
|
209
|
+
export { type CreateSdkContextReturn as C, type InjectedContext as I, type Maybe as M, type SfContract as S, type SfStateProps as a, type SfState as b, createSfStateProvider as c, type CreateSdkOptions as d, type Config as e, type CreateSdkReturn as f };
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vue-storefront/next",
|
|
3
|
+
"description": "Alokai dedicated features for Next.js",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"version": "0.0.0-20250722194236",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"require": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./client": {
|
|
13
|
+
"types": "./dist/client.d.ts",
|
|
14
|
+
"import": "./dist/client.js",
|
|
15
|
+
"require": "./dist/client.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"lint": "eslint",
|
|
24
|
+
"lint:fix": "eslint --fix",
|
|
25
|
+
"format": "prettier --write .",
|
|
26
|
+
"test:unit": "vitest run",
|
|
27
|
+
"version": "cp CHANGELOG.md ../../docs/enterprise/content/storefront/6.change-log/next.md"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@alokai/instrumentation-next-component": "0.0.0-20250722194236",
|
|
31
|
+
"zustand": "^4.5.4"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@alokai/connect": "0.0.0-20250722194236",
|
|
35
|
+
"@types/react": "18.3.2",
|
|
36
|
+
"@types/react-dom": "18.3.0",
|
|
37
|
+
"eslint": "9.23.0",
|
|
38
|
+
"next": "14.2.25",
|
|
39
|
+
"prettier": "3.3.2",
|
|
40
|
+
"react": "18.3.1",
|
|
41
|
+
"react-dom": "18.3.1",
|
|
42
|
+
"start-server-and-test": "^2.0.11",
|
|
43
|
+
"tsup": "8.3.0",
|
|
44
|
+
"vitest": "2.1.9"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@alokai/connect": "0.0.0-20250722194236",
|
|
48
|
+
"next": "^13.4.7 || ^14.0.0",
|
|
49
|
+
"react": "^18.2.0"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"npm": ">=8.0.0",
|
|
53
|
+
"node": ">=18.0.0"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
}
|
|
58
|
+
}
|