@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
package/dist/client.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __defProps = Object.defineProperties;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
-
var __spreadValues = (a, b) => {
|
|
15
|
-
for (var prop in b || (b = {}))
|
|
16
|
-
if (__hasOwnProp.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
if (__getOwnPropSymbols)
|
|
19
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
-
if (__propIsEnum.call(b, prop))
|
|
21
|
-
__defNormalProp(a, prop, b[prop]);
|
|
22
|
-
}
|
|
23
|
-
return a;
|
|
24
|
-
};
|
|
25
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
-
var __objRest = (source, exclude) => {
|
|
27
|
-
var target = {};
|
|
28
|
-
for (var prop in source)
|
|
29
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
30
|
-
target[prop] = source[prop];
|
|
31
|
-
if (source != null && __getOwnPropSymbols)
|
|
32
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
33
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
34
|
-
target[prop] = source[prop];
|
|
35
|
-
}
|
|
36
|
-
return target;
|
|
37
|
-
};
|
|
38
|
-
var __export = (target, all) => {
|
|
39
|
-
for (var name in all)
|
|
40
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
41
|
-
};
|
|
42
|
-
var __copyProps = (to, from, except, desc) => {
|
|
43
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
44
|
-
for (let key of __getOwnPropNames(from))
|
|
45
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
46
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
47
|
-
}
|
|
48
|
-
return to;
|
|
49
|
-
};
|
|
50
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
51
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
52
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
53
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
54
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
55
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
56
|
-
mod
|
|
57
|
-
));
|
|
58
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
59
|
-
|
|
60
|
-
// src/client.ts
|
|
61
|
-
var client_exports = {};
|
|
62
|
-
__export(client_exports, {
|
|
63
|
-
createAlokaiContext: () => createAlokaiContext,
|
|
64
|
-
createSfStateProvider: () => createSfStateProvider,
|
|
65
|
-
env: () => env
|
|
66
|
-
});
|
|
67
|
-
module.exports = __toCommonJS(client_exports);
|
|
68
|
-
|
|
69
|
-
// src/alokai-provider.tsx
|
|
70
|
-
var import_instrumentation_next_component = require("@alokai/instrumentation-next-component");
|
|
71
|
-
var import_script = __toESM(require("next/script"));
|
|
72
|
-
var import_react2 = __toESM(require("react"));
|
|
73
|
-
|
|
74
|
-
// src/env/constants.ts
|
|
75
|
-
var PUBLIC_ENV_KEY = "__ALOKAI_ENV__";
|
|
76
|
-
|
|
77
|
-
// src/env/get-public-env.ts
|
|
78
|
-
function getPublicEnv() {
|
|
79
|
-
const publicEnv = {};
|
|
80
|
-
for (const key in process.env) {
|
|
81
|
-
if (key.startsWith("NEXT_PUBLIC_")) {
|
|
82
|
-
publicEnv[key] = process.env[key];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return publicEnv;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// src/state.tsx
|
|
89
|
-
var import_react = __toESM(require("react"));
|
|
90
|
-
var import_zustand = require("zustand");
|
|
91
|
-
var createSfState = (initialData) => {
|
|
92
|
-
return (0, import_zustand.createStore)()((set) => __spreadProps(__spreadValues({
|
|
93
|
-
cart: null,
|
|
94
|
-
customer: null
|
|
95
|
-
}, initialData), {
|
|
96
|
-
setCart: (cart) => set({ cart }),
|
|
97
|
-
setCurrencies: (currencies) => set({ currencies }),
|
|
98
|
-
setCurrency: (currency) => set({ currency }),
|
|
99
|
-
setCustomer: (customer) => set({ customer }),
|
|
100
|
-
setLocale: (locale) => set({ locale }),
|
|
101
|
-
setLocales: (locales) => set({ locales })
|
|
102
|
-
}));
|
|
103
|
-
};
|
|
104
|
-
function createSfStateProvider() {
|
|
105
|
-
const SfStateContext = (0, import_react.createContext)(null);
|
|
106
|
-
function SfStateProvider({
|
|
107
|
-
children,
|
|
108
|
-
initialData
|
|
109
|
-
}) {
|
|
110
|
-
const stateReference = (0, import_react.useRef)();
|
|
111
|
-
if (!stateReference.current) {
|
|
112
|
-
stateReference.current = createSfState(initialData);
|
|
113
|
-
}
|
|
114
|
-
return /* @__PURE__ */ import_react.default.createElement(SfStateContext.Provider, { value: stateReference.current }, children);
|
|
115
|
-
}
|
|
116
|
-
function getSfStateContext() {
|
|
117
|
-
const context = (0, import_react.useContext)(SfStateContext);
|
|
118
|
-
if (!context)
|
|
119
|
-
throw new Error("Missing SfStateContext.Provider in the tree");
|
|
120
|
-
return context;
|
|
121
|
-
}
|
|
122
|
-
function useSfCurrencyState() {
|
|
123
|
-
const { currency, setCurrency } = (0, import_zustand.useStore)(
|
|
124
|
-
getSfStateContext(),
|
|
125
|
-
(state) => ({
|
|
126
|
-
currency: state.currency,
|
|
127
|
-
setCurrency: state.setCurrency
|
|
128
|
-
})
|
|
129
|
-
);
|
|
130
|
-
return [currency, setCurrency];
|
|
131
|
-
}
|
|
132
|
-
function useSfCurrenciesState() {
|
|
133
|
-
const { currencies, setCurrencies } = (0, import_zustand.useStore)(
|
|
134
|
-
getSfStateContext(),
|
|
135
|
-
(state) => ({
|
|
136
|
-
currencies: state.currencies,
|
|
137
|
-
setCurrencies: state.setCurrencies
|
|
138
|
-
})
|
|
139
|
-
);
|
|
140
|
-
return [currencies, setCurrencies];
|
|
141
|
-
}
|
|
142
|
-
function useSfLocaleState() {
|
|
143
|
-
const { locale, setLocale } = (0, import_zustand.useStore)(getSfStateContext(), (state) => ({
|
|
144
|
-
locale: state.locale,
|
|
145
|
-
setLocale: state.setLocale
|
|
146
|
-
}));
|
|
147
|
-
return [locale, setLocale];
|
|
148
|
-
}
|
|
149
|
-
function useSfLocalesState() {
|
|
150
|
-
const { locales, setLocales } = (0, import_zustand.useStore)(getSfStateContext(), (state) => ({
|
|
151
|
-
locales: state.locales,
|
|
152
|
-
setLocales: state.setLocales
|
|
153
|
-
}));
|
|
154
|
-
return [locales, setLocales];
|
|
155
|
-
}
|
|
156
|
-
function useSfCartState() {
|
|
157
|
-
const { cart, setCart } = (0, import_zustand.useStore)(getSfStateContext(), (state) => ({
|
|
158
|
-
cart: state.cart,
|
|
159
|
-
setCart: state.setCart
|
|
160
|
-
}));
|
|
161
|
-
return [cart, setCart];
|
|
162
|
-
}
|
|
163
|
-
function useSfCustomerState() {
|
|
164
|
-
const { customer, setCustomer } = (0, import_zustand.useStore)(
|
|
165
|
-
getSfStateContext(),
|
|
166
|
-
(state) => ({
|
|
167
|
-
customer: state.customer,
|
|
168
|
-
setCustomer: state.setCustomer
|
|
169
|
-
})
|
|
170
|
-
);
|
|
171
|
-
return [customer, setCustomer];
|
|
172
|
-
}
|
|
173
|
-
return {
|
|
174
|
-
SfStateProvider,
|
|
175
|
-
useSfCartState,
|
|
176
|
-
useSfCurrenciesState,
|
|
177
|
-
useSfCurrencyState,
|
|
178
|
-
useSfCustomerState,
|
|
179
|
-
useSfLocalesState,
|
|
180
|
-
useSfLocaleState
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// src/alokai-provider.tsx
|
|
185
|
-
function createAlokaiContext() {
|
|
186
|
-
const SdkContext = (0, import_react2.createContext)(null);
|
|
187
|
-
const _a = createSfStateProvider(), { SfStateProvider } = _a, rest = __objRest(_a, ["SfStateProvider"]);
|
|
188
|
-
function AlokaiProvider({
|
|
189
|
-
children,
|
|
190
|
-
initialData,
|
|
191
|
-
sdk
|
|
192
|
-
}) {
|
|
193
|
-
const metaTagScript = `
|
|
194
|
-
const vsfMetaTag = document.createElement("meta");
|
|
195
|
-
vsfMetaTag.setAttribute("name", "generator");
|
|
196
|
-
vsfMetaTag.setAttribute("content", "Alokai Storefront");
|
|
197
|
-
document.head.appendChild(vsfMetaTag);
|
|
198
|
-
`;
|
|
199
|
-
const publicEnv = typeof window === "undefined" ? getPublicEnv() : void 0;
|
|
200
|
-
const envScript = publicEnv ? `window['${PUBLIC_ENV_KEY}'] = ${JSON.stringify(publicEnv)};` : "";
|
|
201
|
-
return /* @__PURE__ */ import_react2.default.createElement(SdkContext.Provider, { value: sdk }, publicEnv && /* @__PURE__ */ import_react2.default.createElement(import_script.default, { id: "alokaiEnv", strategy: "beforeInteractive" }, envScript), /* @__PURE__ */ import_react2.default.createElement(import_script.default, { id: "vsfMetaTag", strategy: "beforeInteractive" }, `
|
|
202
|
-
${metaTagScript}
|
|
203
|
-
`), /* @__PURE__ */ import_react2.default.createElement(import_instrumentation_next_component.AlokaiInstrumentation, null), /* @__PURE__ */ import_react2.default.createElement(SfStateProvider, { initialData }, children));
|
|
204
|
-
}
|
|
205
|
-
const useSdk = () => {
|
|
206
|
-
const contextSdk = (0, import_react2.useContext)(SdkContext);
|
|
207
|
-
if (!contextSdk) {
|
|
208
|
-
throw new Error("useSdk must be used within a AlokaiProvider");
|
|
209
|
-
}
|
|
210
|
-
return contextSdk;
|
|
211
|
-
};
|
|
212
|
-
return __spreadValues({ AlokaiProvider, useSdk }, rest);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// src/env/env.ts
|
|
216
|
-
function env(key) {
|
|
217
|
-
var _a;
|
|
218
|
-
if (typeof window === "undefined") {
|
|
219
|
-
return process.env[key];
|
|
220
|
-
}
|
|
221
|
-
return (_a = window[PUBLIC_ENV_KEY]) == null ? void 0 : _a[key];
|
|
222
|
-
}
|
|
223
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
224
|
-
0 && (module.exports = {
|
|
225
|
-
createAlokaiContext,
|
|
226
|
-
createSfStateProvider,
|
|
227
|
-
env
|
|
228
|
-
});
|
package/dist/index.js
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
-
var __export = (target, all) => {
|
|
24
|
-
for (var name in all)
|
|
25
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
-
};
|
|
27
|
-
var __copyProps = (to, from, except, desc) => {
|
|
28
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
-
for (let key of __getOwnPropNames(from))
|
|
30
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
-
}
|
|
33
|
-
return to;
|
|
34
|
-
};
|
|
35
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
-
var __async = (__this, __arguments, generator) => {
|
|
37
|
-
return new Promise((resolve, reject) => {
|
|
38
|
-
var fulfilled = (value) => {
|
|
39
|
-
try {
|
|
40
|
-
step(generator.next(value));
|
|
41
|
-
} catch (e) {
|
|
42
|
-
reject(e);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
var rejected = (value) => {
|
|
46
|
-
try {
|
|
47
|
-
step(generator.throw(value));
|
|
48
|
-
} catch (e) {
|
|
49
|
-
reject(e);
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
53
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
// src/index.ts
|
|
58
|
-
var src_exports = {};
|
|
59
|
-
__export(src_exports, {
|
|
60
|
-
createAlokaiMiddleware: () => createAlokaiMiddleware,
|
|
61
|
-
createLogger: () => createLogger,
|
|
62
|
-
createSdk: () => createSdk,
|
|
63
|
-
defineGetConfigSwitcherHeader: () => import_sdk2.defineGetConfigSwitcherHeader,
|
|
64
|
-
defineSdkConfig: () => defineSdkConfig,
|
|
65
|
-
defineSdkModule: () => defineSdkModule,
|
|
66
|
-
env: () => env,
|
|
67
|
-
resolveSdkOptions: () => resolveSdkOptions
|
|
68
|
-
});
|
|
69
|
-
module.exports = __toCommonJS(src_exports);
|
|
70
|
-
|
|
71
|
-
// src/env/constants.ts
|
|
72
|
-
var PUBLIC_ENV_KEY = "__ALOKAI_ENV__";
|
|
73
|
-
|
|
74
|
-
// src/env/env.ts
|
|
75
|
-
function env(key) {
|
|
76
|
-
var _a;
|
|
77
|
-
if (typeof window === "undefined") {
|
|
78
|
-
return process.env[key];
|
|
79
|
-
}
|
|
80
|
-
return (_a = window[PUBLIC_ENV_KEY]) == null ? void 0 : _a[key];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// src/logger/index.ts
|
|
84
|
-
var import_logger = require("@alokai/connect/logger");
|
|
85
|
-
|
|
86
|
-
// src/logger/injectMetadata.ts
|
|
87
|
-
function injectMetadata(logger, externalData) {
|
|
88
|
-
return new Proxy(logger, {
|
|
89
|
-
get(target, prop) {
|
|
90
|
-
const targetProp = target[prop];
|
|
91
|
-
if (typeof targetProp === "function") {
|
|
92
|
-
return (...args) => {
|
|
93
|
-
const [logData, metadata] = args;
|
|
94
|
-
targetProp(logData, __spreadValues(__spreadValues({}, metadata), externalData));
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
return targetProp;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// src/logger/index.ts
|
|
103
|
-
var createLogger = (options) => {
|
|
104
|
-
const logger = import_logger.LoggerFactory.create(import_logger.LoggerType.ConsolaGcp, options);
|
|
105
|
-
return injectMetadata(logger, {
|
|
106
|
-
alokai: {
|
|
107
|
-
context: "storefront"
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
// src/middleware.ts
|
|
113
|
-
function createAlokaiMiddleware(middleware) {
|
|
114
|
-
return (request) => {
|
|
115
|
-
const nextUrl = request.nextUrl.clone();
|
|
116
|
-
request.headers.append("x-pathname", nextUrl.pathname);
|
|
117
|
-
request.headers.append("x-search", nextUrl.search);
|
|
118
|
-
return middleware(request);
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// src/sdk/index.tsx
|
|
123
|
-
var import_sdk = require("@alokai/connect/sdk");
|
|
124
|
-
|
|
125
|
-
// src/sdk/helpers/defaultConfigs.ts
|
|
126
|
-
var defaultMethodsRequestConfig = {
|
|
127
|
-
unifiedCms: {
|
|
128
|
-
middlewareModule: {
|
|
129
|
-
getEntries: { method: "GET" },
|
|
130
|
-
getPage: { method: "GET" }
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
unifiedCommerce: {
|
|
134
|
-
middlewareModule: {
|
|
135
|
-
getCategories: { method: "GET" },
|
|
136
|
-
getCategory: { method: "GET" },
|
|
137
|
-
getCurrencies: { method: "GET" },
|
|
138
|
-
getProductDetails: { method: "GET" },
|
|
139
|
-
getProductReviews: { method: "GET" },
|
|
140
|
-
getProducts: { method: "GET" },
|
|
141
|
-
searchProducts: { method: "GET" }
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
// src/sdk/helpers/resolveDynamicContext.ts
|
|
147
|
-
var BLACKLISTED_HEADERS = /* @__PURE__ */ new Set(["host"]);
|
|
148
|
-
function isAppRouterHeaders(headers) {
|
|
149
|
-
return !!headers && "entries" in headers;
|
|
150
|
-
}
|
|
151
|
-
function isFlatNextHeaders(headers) {
|
|
152
|
-
return !!headers && !("headers" in headers);
|
|
153
|
-
}
|
|
154
|
-
function normalizeRequestHeaders(requestHeaders) {
|
|
155
|
-
const { cookies, headers = {} } = isFlatNextHeaders(requestHeaders) ? { cookies: void 0, headers: requestHeaders } : {
|
|
156
|
-
cookies: requestHeaders == null ? void 0 : requestHeaders.cookies,
|
|
157
|
-
headers: requestHeaders == null ? void 0 : requestHeaders.headers
|
|
158
|
-
};
|
|
159
|
-
const normalizedHeaders = isAppRouterHeaders(headers) ? Object.fromEntries(headers.entries()) : headers;
|
|
160
|
-
if (cookies) {
|
|
161
|
-
normalizedHeaders.cookie = cookies.toString();
|
|
162
|
-
}
|
|
163
|
-
return normalizedHeaders;
|
|
164
|
-
}
|
|
165
|
-
function resolveDynamicContext(context) {
|
|
166
|
-
return __spreadProps(__spreadValues({}, context), {
|
|
167
|
-
getRequestHeaders() {
|
|
168
|
-
return __async(this, null, function* () {
|
|
169
|
-
var _a2;
|
|
170
|
-
const normalizedHeaders = normalizeRequestHeaders(
|
|
171
|
-
yield (_a2 = context.getRequestHeaders) == null ? void 0 : _a2.call(context)
|
|
172
|
-
);
|
|
173
|
-
const requestHeaders = Object.fromEntries(
|
|
174
|
-
Object.entries(normalizedHeaders).filter(
|
|
175
|
-
([key]) => !BLACKLISTED_HEADERS.has(key)
|
|
176
|
-
)
|
|
177
|
-
);
|
|
178
|
-
if (context.getLocale) {
|
|
179
|
-
requestHeaders["x-alokai-locale"] = context.getLocale();
|
|
180
|
-
}
|
|
181
|
-
return requestHeaders;
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// src/sdk/index.tsx
|
|
188
|
-
var import_sdk2 = require("@alokai/connect/sdk");
|
|
189
|
-
function createSdk(options, configDefinition) {
|
|
190
|
-
function getSdk(dynamicContext = {}) {
|
|
191
|
-
var _a;
|
|
192
|
-
const { getRequestHeaders } = resolveDynamicContext(dynamicContext);
|
|
193
|
-
const resolvedConfig = configDefinition({
|
|
194
|
-
buildModule: import_sdk.buildModule,
|
|
195
|
-
config: {
|
|
196
|
-
apiUrl: options.middleware.apiUrl,
|
|
197
|
-
cdnCacheBustingId: (_a = options.middleware.cdnCacheBustingId) != null ? _a : "no-cache-busting-id-set",
|
|
198
|
-
defaultMethodsRequestConfig,
|
|
199
|
-
ssrApiUrl: options.middleware.ssrApiUrl
|
|
200
|
-
},
|
|
201
|
-
defaults: defaultMethodsRequestConfig,
|
|
202
|
-
getRequestHeaders,
|
|
203
|
-
middlewareModule: import_sdk.middlewareModule
|
|
204
|
-
});
|
|
205
|
-
return (0, import_sdk.initSDK)(resolvedConfig);
|
|
206
|
-
}
|
|
207
|
-
return {
|
|
208
|
-
getSdk
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
function defineSdkConfig(config) {
|
|
212
|
-
if (typeof config === "function") {
|
|
213
|
-
return config;
|
|
214
|
-
}
|
|
215
|
-
return buildModules(config);
|
|
216
|
-
}
|
|
217
|
-
function resolveSdkOptions(input, _options = {}) {
|
|
218
|
-
return input;
|
|
219
|
-
}
|
|
220
|
-
function defineSdkModule(moduleDefinition) {
|
|
221
|
-
return moduleDefinition;
|
|
222
|
-
}
|
|
223
|
-
function buildModules(modules) {
|
|
224
|
-
return (context) => Object.fromEntries(
|
|
225
|
-
Object.entries(modules).map(([key, module2]) => [key, module2(context)])
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
229
|
-
0 && (module.exports = {
|
|
230
|
-
createAlokaiMiddleware,
|
|
231
|
-
createLogger,
|
|
232
|
-
createSdk,
|
|
233
|
-
defineGetConfigSwitcherHeader,
|
|
234
|
-
defineSdkConfig,
|
|
235
|
-
defineSdkModule,
|
|
236
|
-
env,
|
|
237
|
-
resolveSdkOptions
|
|
238
|
-
});
|
|
@@ -1,241 +0,0 @@
|
|
|
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 = Awaited<ReturnType<typeof cookies>>;
|
|
111
|
-
type RequestHeaders = {
|
|
112
|
-
cookies: Cookies;
|
|
113
|
-
headers: Headers;
|
|
114
|
-
} | Headers | undefined;
|
|
115
|
-
type GetSdkContext = {
|
|
116
|
-
/**
|
|
117
|
-
* A function that returns the current locale string;
|
|
118
|
-
*/
|
|
119
|
-
getLocale?: () => string;
|
|
120
|
-
/**
|
|
121
|
-
* A function that returns the request headers.
|
|
122
|
-
*/
|
|
123
|
-
getRequestHeaders?: () => Promise<RequestHeaders> | RequestHeaders;
|
|
124
|
-
};
|
|
125
|
-
type DynamicContext = {
|
|
126
|
-
getRequestHeaders: () => Promise<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: () => Promise.resolve(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
|
-
/**
|
|
210
|
-
* Retrieves an environment variable value.
|
|
211
|
-
* On the server side, it reads from process.env.
|
|
212
|
-
* On the client side, it reads from window.__ALOKAI_ENV__ to support runtime environment variables.
|
|
213
|
-
*
|
|
214
|
-
* @param key - The environment variable key (e.g., "NEXT_PUBLIC_API_URL")
|
|
215
|
-
* @returns The environment variable value or undefined if not found
|
|
216
|
-
*
|
|
217
|
-
* @example
|
|
218
|
-
* ```tsx
|
|
219
|
-
* import { env } from "@vue-storefront/next/client";
|
|
220
|
-
*
|
|
221
|
-
* const apiUrl = env("NEXT_PUBLIC_API_URL");
|
|
222
|
-
* ```
|
|
223
|
-
*/
|
|
224
|
-
declare function env(key: string): string | undefined;
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Type representing environment variables as key-value pairs
|
|
228
|
-
*/
|
|
229
|
-
interface PublicEnv {
|
|
230
|
-
[key: string]: string | undefined;
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Extended window interface to include Alokai environment variables
|
|
234
|
-
*/
|
|
235
|
-
declare global {
|
|
236
|
-
interface Window {
|
|
237
|
-
__ALOKAI_ENV__?: PublicEnv;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
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, env as e, type Config as f, type CreateSdkReturn as g };
|