@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.d.mts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import * as _alokai_connect_logger from '@alokai/connect/logger';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
import { buildModule } from '@alokai/connect/sdk';
|
|
4
|
+
export { defineGetConfigSwitcherHeader } from '@alokai/connect/sdk';
|
|
5
|
+
import { d as CreateSdkOptions, e as Config, f as CreateSdkReturn, I as InjectedContext } from './types-B9h_AU7R.mjs';
|
|
6
|
+
import 'next/headers';
|
|
7
|
+
import 'react';
|
|
8
|
+
|
|
9
|
+
type LogVerbosity = "alert" | "critical" | "debug" | "emergency" | "error" | "info" | "notice" | "warning";
|
|
10
|
+
type LoggerOptions = Partial<{
|
|
11
|
+
includeStackTrace: boolean;
|
|
12
|
+
verbosity: LogVerbosity;
|
|
13
|
+
}>;
|
|
14
|
+
|
|
15
|
+
declare const createLogger: (options?: LoggerOptions) => _alokai_connect_logger.LoggerInterface;
|
|
16
|
+
|
|
17
|
+
type NextMiddleware = (request: NextRequest) => NextResponse | Promise<NextResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an Alokai middleware wrapper that adds pathname information to request headers.
|
|
20
|
+
* This is required for proper pathname handling during SSR in Next.js.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* // middleware.ts
|
|
25
|
+
* import { createAlokaiMiddleware } from '@alokai/next';
|
|
26
|
+
*
|
|
27
|
+
* export default createAlokaiMiddleware((request) => {
|
|
28
|
+
* // Your middleware logic here
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param middleware - The Next.js middleware function to wrap
|
|
33
|
+
* @returns A wrapped middleware function that adds pathname to request headers
|
|
34
|
+
*/
|
|
35
|
+
declare function createAlokaiMiddleware(middleware: NextMiddleware): (request: NextRequest) => NextResponse<unknown> | Promise<NextResponse<unknown>>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates an SDK for the given configuration definition.
|
|
39
|
+
* @param options - The options for creating the SDK.
|
|
40
|
+
* @param configDefinition - The configuration definition for the SDK.
|
|
41
|
+
* @returns An object containing the `getSdk` function.
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* import { contentfulModule } from "@vsf-enterprise/contentful-sdk";
|
|
45
|
+
* import { CreateSdkOptions, createSdk } from "@vue-storefront/next";
|
|
46
|
+
* import type { UnifiedApiEndpoints } from "../storefront-middleware/types";
|
|
47
|
+
*
|
|
48
|
+
* const options: CreateSdkOptions = {
|
|
49
|
+
* middleware: {
|
|
50
|
+
* apiUrl: "http://localhost:4000",
|
|
51
|
+
* ssrApiUrl: "http://localhost:4000",
|
|
52
|
+
* cdnCacheBustingId: "no-cache-busting-id-set",
|
|
53
|
+
* },
|
|
54
|
+
* multistore: {
|
|
55
|
+
* enabled: false,
|
|
56
|
+
* },
|
|
57
|
+
* };
|
|
58
|
+
*
|
|
59
|
+
* export const { getSdk, createSdkContext } = createSdk(
|
|
60
|
+
* options,
|
|
61
|
+
* ({ buildModule, middlewareModule, config, getRequestHeaders }) => ({
|
|
62
|
+
* unified: buildModule(middlewareModule<UnifiedApiEndpoints>, {
|
|
63
|
+
* apiUrl: config.apiUrl + "/commerce",
|
|
64
|
+
* ssrApiUrl: config.ssrApiUrl + "/commerce",
|
|
65
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
66
|
+
* defaultRequestConfig: {
|
|
67
|
+
* headers: getRequestHeaders(),
|
|
68
|
+
* },
|
|
69
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
70
|
+
* }),
|
|
71
|
+
* contentful: buildModule(contentfulModule, {
|
|
72
|
+
* apiUrl: config.apiUrl + "/cntf",
|
|
73
|
+
* ssrApiUrl: config.ssrApiUrl + "/cntf",
|
|
74
|
+
* }),
|
|
75
|
+
* }),
|
|
76
|
+
* );
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function createSdk<TConfig extends Record<string, any>>(options: CreateSdkOptions, configDefinition: Config<TConfig>): CreateSdkReturn<TConfig>;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a configuration definition for the SDK.
|
|
82
|
+
* @param config The configuration definition for the SDK or a record of SDK modules
|
|
83
|
+
* @returns An object containing SDK configuration
|
|
84
|
+
* @example
|
|
85
|
+
* Using a function:
|
|
86
|
+
* ```tsx
|
|
87
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
88
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
89
|
+
*
|
|
90
|
+
* const config = defineSdkConfig(
|
|
91
|
+
* ({ buildModule, middlewareModule, config, getRequestHeaders }) => ({
|
|
92
|
+
* unified: buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
93
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
94
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
95
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
96
|
+
* defaultRequestConfig: {
|
|
97
|
+
* getConfigSwitcherHeader,
|
|
98
|
+
* headers: getRequestHeaders(),
|
|
99
|
+
* },
|
|
100
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
101
|
+
* }),
|
|
102
|
+
* }),
|
|
103
|
+
* );
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* Using a record of modules:
|
|
108
|
+
* ```tsx
|
|
109
|
+
* import { defineSdkModule } from '@vue-storefront/next';
|
|
110
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
111
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
112
|
+
*
|
|
113
|
+
* const unified = defineSdkModule(({ buildModule, config, getRequestHeaders, middlewareModule }) =>
|
|
114
|
+
* buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
115
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
116
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
117
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
118
|
+
* defaultRequestConfig: {
|
|
119
|
+
* getConfigSwitcherHeader,
|
|
120
|
+
* headers: getRequestHeaders(),
|
|
121
|
+
* },
|
|
122
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
123
|
+
* }),
|
|
124
|
+
* );
|
|
125
|
+
*
|
|
126
|
+
* const config = defineSdkConfig({
|
|
127
|
+
* unified,
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare function defineSdkConfig<TConfig extends Record<string, any>>(config: Config<TConfig>): Config<TConfig>;
|
|
132
|
+
declare function defineSdkConfig<TModules extends Record<string, DefineSdkModule>>(modules: TModules): (context: InjectedContext) => {
|
|
133
|
+
[K in keyof TModules]: ReturnType<TModules[K]>;
|
|
134
|
+
};
|
|
135
|
+
type ResolveSdkOptionsConfig = {
|
|
136
|
+
customSuffix: string;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Helper function to resolve the SDK options based on the configuration.
|
|
140
|
+
*
|
|
141
|
+
* @privateRemarks
|
|
142
|
+
* For now this file only verifies the type of the input and simply returns it.
|
|
143
|
+
* However, in the future we might need it to perform true input resolution.
|
|
144
|
+
*
|
|
145
|
+
* @param input - The options for creating the SDK.
|
|
146
|
+
* @param options - The configuration object, that allows to customize the API Url creation on enabled multistore.
|
|
147
|
+
*
|
|
148
|
+
* @returns The resolved SDK options.
|
|
149
|
+
*/
|
|
150
|
+
declare function resolveSdkOptions(input: CreateSdkOptions, _options?: Partial<ResolveSdkOptionsConfig>): CreateSdkOptions;
|
|
151
|
+
type DefineSdkModule = (context: InjectedContext) => ReturnType<typeof buildModule>;
|
|
152
|
+
/**
|
|
153
|
+
* Defines an SDK module that can be used with defineSdkConfig.
|
|
154
|
+
* Each module is a function that takes the InjectedContext and returns a built module.
|
|
155
|
+
*
|
|
156
|
+
* @param moduleDefinition - A function that takes InjectedContext and returns a built module
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```tsx
|
|
160
|
+
* import { defineSdkModule } from '@vue-storefront/next';
|
|
161
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
162
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
163
|
+
*
|
|
164
|
+
* export const unified = defineSdkModule(({ buildModule, config, getRequestHeaders, middlewareModule }) =>
|
|
165
|
+
* buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
166
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
167
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
168
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
169
|
+
* defaultRequestConfig: {
|
|
170
|
+
* getConfigSwitcherHeader,
|
|
171
|
+
* headers: getRequestHeaders(),
|
|
172
|
+
* },
|
|
173
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
174
|
+
* }),
|
|
175
|
+
* );
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
declare function defineSdkModule<TModuleDefinition extends DefineSdkModule>(moduleDefinition: TModuleDefinition): TModuleDefinition;
|
|
179
|
+
|
|
180
|
+
export { CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineSdkConfig, defineSdkModule, resolveSdkOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import * as _alokai_connect_logger from '@alokai/connect/logger';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
import { buildModule } from '@alokai/connect/sdk';
|
|
4
|
+
export { defineGetConfigSwitcherHeader } from '@alokai/connect/sdk';
|
|
5
|
+
import { d as CreateSdkOptions, e as Config, f as CreateSdkReturn, I as InjectedContext } from './types-B9h_AU7R.js';
|
|
6
|
+
import 'next/headers';
|
|
7
|
+
import 'react';
|
|
8
|
+
|
|
9
|
+
type LogVerbosity = "alert" | "critical" | "debug" | "emergency" | "error" | "info" | "notice" | "warning";
|
|
10
|
+
type LoggerOptions = Partial<{
|
|
11
|
+
includeStackTrace: boolean;
|
|
12
|
+
verbosity: LogVerbosity;
|
|
13
|
+
}>;
|
|
14
|
+
|
|
15
|
+
declare const createLogger: (options?: LoggerOptions) => _alokai_connect_logger.LoggerInterface;
|
|
16
|
+
|
|
17
|
+
type NextMiddleware = (request: NextRequest) => NextResponse | Promise<NextResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an Alokai middleware wrapper that adds pathname information to request headers.
|
|
20
|
+
* This is required for proper pathname handling during SSR in Next.js.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* // middleware.ts
|
|
25
|
+
* import { createAlokaiMiddleware } from '@alokai/next';
|
|
26
|
+
*
|
|
27
|
+
* export default createAlokaiMiddleware((request) => {
|
|
28
|
+
* // Your middleware logic here
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @param middleware - The Next.js middleware function to wrap
|
|
33
|
+
* @returns A wrapped middleware function that adds pathname to request headers
|
|
34
|
+
*/
|
|
35
|
+
declare function createAlokaiMiddleware(middleware: NextMiddleware): (request: NextRequest) => NextResponse<unknown> | Promise<NextResponse<unknown>>;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Creates an SDK for the given configuration definition.
|
|
39
|
+
* @param options - The options for creating the SDK.
|
|
40
|
+
* @param configDefinition - The configuration definition for the SDK.
|
|
41
|
+
* @returns An object containing the `getSdk` function.
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* import { contentfulModule } from "@vsf-enterprise/contentful-sdk";
|
|
45
|
+
* import { CreateSdkOptions, createSdk } from "@vue-storefront/next";
|
|
46
|
+
* import type { UnifiedApiEndpoints } from "../storefront-middleware/types";
|
|
47
|
+
*
|
|
48
|
+
* const options: CreateSdkOptions = {
|
|
49
|
+
* middleware: {
|
|
50
|
+
* apiUrl: "http://localhost:4000",
|
|
51
|
+
* ssrApiUrl: "http://localhost:4000",
|
|
52
|
+
* cdnCacheBustingId: "no-cache-busting-id-set",
|
|
53
|
+
* },
|
|
54
|
+
* multistore: {
|
|
55
|
+
* enabled: false,
|
|
56
|
+
* },
|
|
57
|
+
* };
|
|
58
|
+
*
|
|
59
|
+
* export const { getSdk, createSdkContext } = createSdk(
|
|
60
|
+
* options,
|
|
61
|
+
* ({ buildModule, middlewareModule, config, getRequestHeaders }) => ({
|
|
62
|
+
* unified: buildModule(middlewareModule<UnifiedApiEndpoints>, {
|
|
63
|
+
* apiUrl: config.apiUrl + "/commerce",
|
|
64
|
+
* ssrApiUrl: config.ssrApiUrl + "/commerce",
|
|
65
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
66
|
+
* defaultRequestConfig: {
|
|
67
|
+
* headers: getRequestHeaders(),
|
|
68
|
+
* },
|
|
69
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
70
|
+
* }),
|
|
71
|
+
* contentful: buildModule(contentfulModule, {
|
|
72
|
+
* apiUrl: config.apiUrl + "/cntf",
|
|
73
|
+
* ssrApiUrl: config.ssrApiUrl + "/cntf",
|
|
74
|
+
* }),
|
|
75
|
+
* }),
|
|
76
|
+
* );
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function createSdk<TConfig extends Record<string, any>>(options: CreateSdkOptions, configDefinition: Config<TConfig>): CreateSdkReturn<TConfig>;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a configuration definition for the SDK.
|
|
82
|
+
* @param config The configuration definition for the SDK or a record of SDK modules
|
|
83
|
+
* @returns An object containing SDK configuration
|
|
84
|
+
* @example
|
|
85
|
+
* Using a function:
|
|
86
|
+
* ```tsx
|
|
87
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
88
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
89
|
+
*
|
|
90
|
+
* const config = defineSdkConfig(
|
|
91
|
+
* ({ buildModule, middlewareModule, config, getRequestHeaders }) => ({
|
|
92
|
+
* unified: buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
93
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
94
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
95
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
96
|
+
* defaultRequestConfig: {
|
|
97
|
+
* getConfigSwitcherHeader,
|
|
98
|
+
* headers: getRequestHeaders(),
|
|
99
|
+
* },
|
|
100
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
101
|
+
* }),
|
|
102
|
+
* }),
|
|
103
|
+
* );
|
|
104
|
+
* ```
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* Using a record of modules:
|
|
108
|
+
* ```tsx
|
|
109
|
+
* import { defineSdkModule } from '@vue-storefront/next';
|
|
110
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
111
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
112
|
+
*
|
|
113
|
+
* const unified = defineSdkModule(({ buildModule, config, getRequestHeaders, middlewareModule }) =>
|
|
114
|
+
* buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
115
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
116
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
117
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
118
|
+
* defaultRequestConfig: {
|
|
119
|
+
* getConfigSwitcherHeader,
|
|
120
|
+
* headers: getRequestHeaders(),
|
|
121
|
+
* },
|
|
122
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
123
|
+
* }),
|
|
124
|
+
* );
|
|
125
|
+
*
|
|
126
|
+
* const config = defineSdkConfig({
|
|
127
|
+
* unified,
|
|
128
|
+
* });
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
declare function defineSdkConfig<TConfig extends Record<string, any>>(config: Config<TConfig>): Config<TConfig>;
|
|
132
|
+
declare function defineSdkConfig<TModules extends Record<string, DefineSdkModule>>(modules: TModules): (context: InjectedContext) => {
|
|
133
|
+
[K in keyof TModules]: ReturnType<TModules[K]>;
|
|
134
|
+
};
|
|
135
|
+
type ResolveSdkOptionsConfig = {
|
|
136
|
+
customSuffix: string;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Helper function to resolve the SDK options based on the configuration.
|
|
140
|
+
*
|
|
141
|
+
* @privateRemarks
|
|
142
|
+
* For now this file only verifies the type of the input and simply returns it.
|
|
143
|
+
* However, in the future we might need it to perform true input resolution.
|
|
144
|
+
*
|
|
145
|
+
* @param input - The options for creating the SDK.
|
|
146
|
+
* @param options - The configuration object, that allows to customize the API Url creation on enabled multistore.
|
|
147
|
+
*
|
|
148
|
+
* @returns The resolved SDK options.
|
|
149
|
+
*/
|
|
150
|
+
declare function resolveSdkOptions(input: CreateSdkOptions, _options?: Partial<ResolveSdkOptionsConfig>): CreateSdkOptions;
|
|
151
|
+
type DefineSdkModule = (context: InjectedContext) => ReturnType<typeof buildModule>;
|
|
152
|
+
/**
|
|
153
|
+
* Defines an SDK module that can be used with defineSdkConfig.
|
|
154
|
+
* Each module is a function that takes the InjectedContext and returns a built module.
|
|
155
|
+
*
|
|
156
|
+
* @param moduleDefinition - A function that takes InjectedContext and returns a built module
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```tsx
|
|
160
|
+
* import { defineSdkModule } from '@vue-storefront/next';
|
|
161
|
+
* import type { UnifiedEndpoints } from 'storefront-middleware/types';
|
|
162
|
+
* import { getConfigSwitcherHeader } from './utils';
|
|
163
|
+
*
|
|
164
|
+
* export const unified = defineSdkModule(({ buildModule, config, getRequestHeaders, middlewareModule }) =>
|
|
165
|
+
* buildModule(middlewareModule<UnifiedEndpoints>, {
|
|
166
|
+
* apiUrl: `${config.apiUrl}/commerce/unified`,
|
|
167
|
+
* ssrApiUrl: `${config.ssrApiUrl}/commerce/unified`,
|
|
168
|
+
* cdnCacheBustingId: config.cdnCacheBustingId,
|
|
169
|
+
* defaultRequestConfig: {
|
|
170
|
+
* getConfigSwitcherHeader,
|
|
171
|
+
* headers: getRequestHeaders(),
|
|
172
|
+
* },
|
|
173
|
+
* methodsRequestConfig: config.defaultMethodsRequestConfig.unifiedCommerce.middlewareModule,
|
|
174
|
+
* }),
|
|
175
|
+
* );
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
declare function defineSdkModule<TModuleDefinition extends DefineSdkModule>(moduleDefinition: TModuleDefinition): TModuleDefinition;
|
|
179
|
+
|
|
180
|
+
export { CreateSdkOptions, createAlokaiMiddleware, createLogger, createSdk, defineSdkConfig, defineSdkModule, resolveSdkOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
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
|
+
|
|
37
|
+
// src/index.ts
|
|
38
|
+
var src_exports = {};
|
|
39
|
+
__export(src_exports, {
|
|
40
|
+
createAlokaiMiddleware: () => createAlokaiMiddleware,
|
|
41
|
+
createLogger: () => createLogger,
|
|
42
|
+
createSdk: () => createSdk,
|
|
43
|
+
defineGetConfigSwitcherHeader: () => import_sdk2.defineGetConfigSwitcherHeader,
|
|
44
|
+
defineSdkConfig: () => defineSdkConfig,
|
|
45
|
+
defineSdkModule: () => defineSdkModule,
|
|
46
|
+
resolveSdkOptions: () => resolveSdkOptions
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(src_exports);
|
|
49
|
+
|
|
50
|
+
// src/logger/index.ts
|
|
51
|
+
var import_logger = require("@alokai/connect/logger");
|
|
52
|
+
|
|
53
|
+
// src/logger/injectMetadata.ts
|
|
54
|
+
function injectMetadata(logger, externalData) {
|
|
55
|
+
return new Proxy(logger, {
|
|
56
|
+
get(target, prop) {
|
|
57
|
+
const targetProp = target[prop];
|
|
58
|
+
if (typeof targetProp === "function") {
|
|
59
|
+
return (...args) => {
|
|
60
|
+
const [logData, metadata] = args;
|
|
61
|
+
targetProp(logData, __spreadValues(__spreadValues({}, metadata), externalData));
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return targetProp;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/logger/index.ts
|
|
70
|
+
var createLogger = (options) => {
|
|
71
|
+
const logger = import_logger.LoggerFactory.create(import_logger.LoggerType.ConsolaGcp, options);
|
|
72
|
+
return injectMetadata(logger, {
|
|
73
|
+
alokai: {
|
|
74
|
+
context: "storefront"
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/middleware.ts
|
|
80
|
+
function createAlokaiMiddleware(middleware) {
|
|
81
|
+
return (request) => {
|
|
82
|
+
const nextUrl = request.nextUrl.clone();
|
|
83
|
+
request.headers.append("x-pathname", nextUrl.pathname);
|
|
84
|
+
request.headers.append("x-search", nextUrl.search);
|
|
85
|
+
return middleware(request);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/sdk/index.tsx
|
|
90
|
+
var import_sdk = require("@alokai/connect/sdk");
|
|
91
|
+
|
|
92
|
+
// src/sdk/helpers/defaultConfigs.ts
|
|
93
|
+
var defaultMethodsRequestConfig = {
|
|
94
|
+
unifiedCms: {
|
|
95
|
+
middlewareModule: {
|
|
96
|
+
getEntries: { method: "GET" },
|
|
97
|
+
getPage: { method: "GET" }
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
unifiedCommerce: {
|
|
101
|
+
middlewareModule: {
|
|
102
|
+
getCategories: { method: "GET" },
|
|
103
|
+
getCategory: { method: "GET" },
|
|
104
|
+
getCurrencies: { method: "GET" },
|
|
105
|
+
getProductDetails: { method: "GET" },
|
|
106
|
+
getProductReviews: { method: "GET" },
|
|
107
|
+
getProducts: { method: "GET" },
|
|
108
|
+
searchProducts: { method: "GET" }
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// src/sdk/helpers/resolveDynamicContext.ts
|
|
114
|
+
var BLACKLISTED_HEADERS = /* @__PURE__ */ new Set(["host"]);
|
|
115
|
+
function isAppRouterHeaders(headers) {
|
|
116
|
+
return !!headers && "entries" in headers;
|
|
117
|
+
}
|
|
118
|
+
function isFlatNextHeaders(headers) {
|
|
119
|
+
return !!headers && !("headers" in headers);
|
|
120
|
+
}
|
|
121
|
+
function normalizeRequestHeaders(requestHeaders) {
|
|
122
|
+
const { cookies, headers = {} } = isFlatNextHeaders(requestHeaders) ? { cookies: void 0, headers: requestHeaders } : {
|
|
123
|
+
cookies: requestHeaders == null ? void 0 : requestHeaders.cookies,
|
|
124
|
+
headers: requestHeaders == null ? void 0 : requestHeaders.headers
|
|
125
|
+
};
|
|
126
|
+
const normalizedHeaders = isAppRouterHeaders(headers) ? Object.fromEntries(headers.entries()) : headers;
|
|
127
|
+
if (cookies) {
|
|
128
|
+
normalizedHeaders.cookie = cookies.toString();
|
|
129
|
+
}
|
|
130
|
+
return normalizedHeaders;
|
|
131
|
+
}
|
|
132
|
+
function resolveDynamicContext(context) {
|
|
133
|
+
return __spreadProps(__spreadValues({}, context), {
|
|
134
|
+
getRequestHeaders() {
|
|
135
|
+
var _a;
|
|
136
|
+
const normalizedHeaders = normalizeRequestHeaders(
|
|
137
|
+
(_a = context.getRequestHeaders) == null ? void 0 : _a.call(context)
|
|
138
|
+
);
|
|
139
|
+
const requestHeaders = Object.fromEntries(
|
|
140
|
+
Object.entries(normalizedHeaders).filter(
|
|
141
|
+
([key]) => !BLACKLISTED_HEADERS.has(key)
|
|
142
|
+
)
|
|
143
|
+
);
|
|
144
|
+
if (context.getLocale) {
|
|
145
|
+
requestHeaders["x-alokai-locale"] = context.getLocale();
|
|
146
|
+
}
|
|
147
|
+
return requestHeaders;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/sdk/index.tsx
|
|
153
|
+
var import_sdk2 = require("@alokai/connect/sdk");
|
|
154
|
+
function createSdk(options, configDefinition) {
|
|
155
|
+
function getSdk(dynamicContext = {}) {
|
|
156
|
+
var _a;
|
|
157
|
+
const { getRequestHeaders } = resolveDynamicContext(dynamicContext);
|
|
158
|
+
const resolvedConfig = configDefinition({
|
|
159
|
+
buildModule: import_sdk.buildModule,
|
|
160
|
+
config: {
|
|
161
|
+
apiUrl: options.middleware.apiUrl,
|
|
162
|
+
cdnCacheBustingId: (_a = options.middleware.cdnCacheBustingId) != null ? _a : "no-cache-busting-id-set",
|
|
163
|
+
defaultMethodsRequestConfig,
|
|
164
|
+
ssrApiUrl: options.middleware.ssrApiUrl
|
|
165
|
+
},
|
|
166
|
+
defaults: defaultMethodsRequestConfig,
|
|
167
|
+
getRequestHeaders,
|
|
168
|
+
middlewareModule: import_sdk.middlewareModule
|
|
169
|
+
});
|
|
170
|
+
return (0, import_sdk.initSDK)(resolvedConfig);
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
getSdk
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function defineSdkConfig(config) {
|
|
177
|
+
if (typeof config === "function") {
|
|
178
|
+
return config;
|
|
179
|
+
}
|
|
180
|
+
return buildModules(config);
|
|
181
|
+
}
|
|
182
|
+
function resolveSdkOptions(input, _options = {}) {
|
|
183
|
+
return input;
|
|
184
|
+
}
|
|
185
|
+
function defineSdkModule(moduleDefinition) {
|
|
186
|
+
return moduleDefinition;
|
|
187
|
+
}
|
|
188
|
+
function buildModules(modules) {
|
|
189
|
+
return (context) => Object.fromEntries(
|
|
190
|
+
Object.entries(modules).map(([key, module2]) => [key, module2(context)])
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
194
|
+
0 && (module.exports = {
|
|
195
|
+
createAlokaiMiddleware,
|
|
196
|
+
createLogger,
|
|
197
|
+
createSdk,
|
|
198
|
+
defineGetConfigSwitcherHeader,
|
|
199
|
+
defineSdkConfig,
|
|
200
|
+
defineSdkModule,
|
|
201
|
+
resolveSdkOptions
|
|
202
|
+
});
|