@vue-storefront/next 6.0.0-rc.1 → 6.0.0-rc.3
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/package.json +4 -4
- package/dist/types-BdDsK6en.d.mts +0 -223
- package/dist/types-BdDsK6en.d.ts +0 -223
- package/dist/types-D-IdwoWb.d.mts +0 -223
- package/dist/types-D-IdwoWb.d.ts +0 -223
- package/dist/types-DGN1ZAgC.d.mts +0 -220
- package/dist/types-DGN1ZAgC.d.ts +0 -220
- package/dist/types-Dw2Ev7Da.d.mts +0 -220
- package/dist/types-Dw2Ev7Da.d.ts +0 -220
- package/dist/types-SbOpJvFm.d.mts +0 -220
- package/dist/types-SbOpJvFm.d.ts +0 -220
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@vue-storefront/next",
|
|
3
3
|
"description": "Alokai dedicated features for Next.js",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "6.0.0-rc.
|
|
5
|
+
"version": "6.0.0-rc.3",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
@@ -29,18 +29,18 @@
|
|
|
29
29
|
"zustand": "^4.5.4"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@alokai/connect": "^1.0.0-rc.
|
|
32
|
+
"@alokai/connect": "^1.0.0-rc.2",
|
|
33
33
|
"@types/react": "18.3.2",
|
|
34
34
|
"@types/react-dom": "18.3.0",
|
|
35
35
|
"react-dom": "18.3.1",
|
|
36
|
-
"start-server-and-test": "^2.0.
|
|
36
|
+
"start-server-and-test": "^2.0.11",
|
|
37
37
|
"tsup": "8.3.0",
|
|
38
38
|
"vitest": "2.1.5",
|
|
39
39
|
"react": "18.3.1",
|
|
40
40
|
"next": "14.2.23"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@alokai/connect": "^1.0.0-rc.
|
|
43
|
+
"@alokai/connect": "^1.0.0-rc.2",
|
|
44
44
|
"react": "^18.2.0",
|
|
45
45
|
"next": "^13.4.7 || ^14.0.0"
|
|
46
46
|
},
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { SDKApi, buildModule, middlewareModule } from '@vue-storefront/sdk';
|
|
2
|
-
import React, { PropsWithChildren, ReactNode } from 'react';
|
|
3
|
-
import { cookies } from 'next/headers';
|
|
4
|
-
|
|
5
|
-
declare const defaultMethodsRequestConfig: {
|
|
6
|
-
readonly unifiedCommerce: {
|
|
7
|
-
readonly middlewareModule: {
|
|
8
|
-
readonly getCategory: {
|
|
9
|
-
readonly method: "GET";
|
|
10
|
-
};
|
|
11
|
-
readonly getCategories: {
|
|
12
|
-
readonly method: "GET";
|
|
13
|
-
};
|
|
14
|
-
readonly getProductDetails: {
|
|
15
|
-
readonly method: "GET";
|
|
16
|
-
};
|
|
17
|
-
readonly getProductReviews: {
|
|
18
|
-
readonly method: "GET";
|
|
19
|
-
};
|
|
20
|
-
readonly getProducts: {
|
|
21
|
-
readonly method: "GET";
|
|
22
|
-
};
|
|
23
|
-
readonly getCurrencies: {
|
|
24
|
-
readonly method: "GET";
|
|
25
|
-
};
|
|
26
|
-
readonly searchProducts: {
|
|
27
|
-
readonly method: "GET";
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
readonly unifiedCms: {
|
|
32
|
-
readonly middlewareModule: {
|
|
33
|
-
readonly getPage: {
|
|
34
|
-
readonly method: "GET";
|
|
35
|
-
};
|
|
36
|
-
readonly getEntries: {
|
|
37
|
-
readonly method: "GET";
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
type Maybe<TType> = TType | null;
|
|
44
|
-
|
|
45
|
-
type SfContract = {
|
|
46
|
-
SfCart: unknown;
|
|
47
|
-
SfCustomer: unknown;
|
|
48
|
-
SfCurrency: unknown;
|
|
49
|
-
SfLocale: unknown;
|
|
50
|
-
};
|
|
51
|
-
interface SfStateProps<TSfContract extends SfContract> {
|
|
52
|
-
currencies: TSfContract["SfCurrency"][];
|
|
53
|
-
currency: TSfContract["SfCurrency"];
|
|
54
|
-
locale: TSfContract["SfLocale"];
|
|
55
|
-
locales: TSfContract["SfLocale"][];
|
|
56
|
-
}
|
|
57
|
-
interface SfState<TSfContract extends SfContract> extends SfStateProps<TSfContract> {
|
|
58
|
-
cart: TSfContract["SfCart"] | null | undefined;
|
|
59
|
-
customer: TSfContract["SfCustomer"] | null | undefined;
|
|
60
|
-
setCart: (cart?: TSfContract["SfCart"] | null) => void;
|
|
61
|
-
setCurrencies: (currencies: TSfContract["SfCurrency"][]) => void;
|
|
62
|
-
setCurrency: (currency: TSfContract["SfCurrency"]) => void;
|
|
63
|
-
setCustomer: (customer?: TSfContract["SfCustomer"] | null) => void;
|
|
64
|
-
setLocale: (locale: TSfContract["SfLocale"]) => void;
|
|
65
|
-
setLocales: (locales: TSfContract["SfLocale"][]) => void;
|
|
66
|
-
}
|
|
67
|
-
declare function createSfStateProvider<TSfContract extends SfContract>(): {
|
|
68
|
-
SfStateProvider: ({ children, initialData, }: {
|
|
69
|
-
initialData: SfStateProps<TSfContract>;
|
|
70
|
-
} & PropsWithChildren) => React.JSX.Element;
|
|
71
|
-
useSfCurrencyState: () => [
|
|
72
|
-
TSfContract["SfCurrency"],
|
|
73
|
-
(currency: TSfContract["SfCurrency"]) => void
|
|
74
|
-
];
|
|
75
|
-
useSfCurrenciesState: () => [
|
|
76
|
-
TSfContract["SfCurrency"][],
|
|
77
|
-
(currencies: TSfContract["SfCurrency"][]) => void
|
|
78
|
-
];
|
|
79
|
-
useSfLocaleState: () => [
|
|
80
|
-
TSfContract["SfLocale"],
|
|
81
|
-
(locale: TSfContract["SfLocale"]) => void
|
|
82
|
-
];
|
|
83
|
-
useSfLocalesState: () => [
|
|
84
|
-
TSfContract["SfLocale"][],
|
|
85
|
-
(locales: TSfContract["SfLocale"][]) => void
|
|
86
|
-
];
|
|
87
|
-
useSfCartState: () => [
|
|
88
|
-
TSfContract["SfCart"] | null | undefined,
|
|
89
|
-
(cart?: TSfContract["SfCart"] | null) => void
|
|
90
|
-
];
|
|
91
|
-
useSfCustomerState: () => [
|
|
92
|
-
TSfContract["SfCustomer"] | null | undefined,
|
|
93
|
-
(customer?: TSfContract["SfCustomer"] | null) => void
|
|
94
|
-
];
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
interface MiddlewareConfig {
|
|
98
|
-
/**
|
|
99
|
-
* The URL of the middleware.
|
|
100
|
-
* @example "http://localhost:4000"
|
|
101
|
-
*/
|
|
102
|
-
apiUrl: string;
|
|
103
|
-
/**
|
|
104
|
-
* The URL of the middleware for server-side rendering.
|
|
105
|
-
* @example "http://localhost:4000"
|
|
106
|
-
*/
|
|
107
|
-
ssrApiUrl?: string;
|
|
108
|
-
/**
|
|
109
|
-
* This is identifier used to invalidate the cache on CDN when the assets change.
|
|
110
|
-
* Usually it's a commit hash.
|
|
111
|
-
* @example "2c106d9619c71c3082c9b59b1d72817363c8ecb9"
|
|
112
|
-
* @default "no-cache-busting-id-set"
|
|
113
|
-
*/
|
|
114
|
-
cdnCacheBustingId?: string;
|
|
115
|
-
}
|
|
116
|
-
interface MultistoreConfig {
|
|
117
|
-
/**
|
|
118
|
-
* Whether the multistore is enabled or not.
|
|
119
|
-
* @example false
|
|
120
|
-
* @default false
|
|
121
|
-
*/
|
|
122
|
-
enabled: boolean;
|
|
123
|
-
}
|
|
124
|
-
interface CreateSdkOptions {
|
|
125
|
-
multistore?: MultistoreConfig;
|
|
126
|
-
middleware: MiddlewareConfig;
|
|
127
|
-
}
|
|
128
|
-
type Cookies = ReturnType<typeof cookies>;
|
|
129
|
-
type NextHeaders = Record<string, string | string[] | undefined> | Headers;
|
|
130
|
-
type GetSdkContext = {
|
|
131
|
-
/**
|
|
132
|
-
* A function that returns the request headers.
|
|
133
|
-
*/
|
|
134
|
-
getRequestHeaders?: () => NextHeaders | {
|
|
135
|
-
headers: NextHeaders;
|
|
136
|
-
cookies: Cookies;
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
type DynamicContext = {
|
|
140
|
-
getRequestHeaders: () => Record<string, string | string[]>;
|
|
141
|
-
};
|
|
142
|
-
type StaticContext = {
|
|
143
|
-
buildModule: typeof buildModule;
|
|
144
|
-
middlewareModule: typeof middlewareModule;
|
|
145
|
-
/**
|
|
146
|
-
* @deprecated Use `config.middlewareUrl` instead.
|
|
147
|
-
*/
|
|
148
|
-
middlewareUrl: string;
|
|
149
|
-
/**
|
|
150
|
-
* @deprecated Use `config.defaultMethodsRequestConfig` instead.
|
|
151
|
-
*/
|
|
152
|
-
defaults: typeof defaultMethodsRequestConfig;
|
|
153
|
-
config: {
|
|
154
|
-
middlewareUrl: string;
|
|
155
|
-
defaultMethodsRequestConfig: typeof defaultMethodsRequestConfig;
|
|
156
|
-
cdnCacheBustingId: string;
|
|
157
|
-
};
|
|
158
|
-
};
|
|
159
|
-
type InjectedContext = DynamicContext & StaticContext;
|
|
160
|
-
type Config<TConfig> = (context: InjectedContext) => TConfig;
|
|
161
|
-
type AlokaiProviderProps<TSdk, TSfContract extends SfContract> = {
|
|
162
|
-
children: ReactNode;
|
|
163
|
-
sdk: TSdk;
|
|
164
|
-
initialData: SfStateProps<TSfContract>;
|
|
165
|
-
};
|
|
166
|
-
interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
167
|
-
/**
|
|
168
|
-
* Creates a new SDK instance. This function is dedicated for server-side usage,
|
|
169
|
-
* where a new SDK instance should be created for each request.
|
|
170
|
-
* For the client side usage, use the `createSdkContext` function instead.
|
|
171
|
-
*
|
|
172
|
-
* @param dynamicContext - The dynamic, request-specific, context
|
|
173
|
-
*
|
|
174
|
-
* @returns The SDK instance.
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* For the Pages Router, you can use the `getSdk` function in the `getServerSideProps` function:
|
|
178
|
-
* ```tsx
|
|
179
|
-
* import type { GetServerSideProps } from "next";
|
|
180
|
-
* import { getSdk } from "../../sdk.config";
|
|
181
|
-
*
|
|
182
|
-
* export const getServerSideProps: GetServerSideProps = async ({ req }) => {
|
|
183
|
-
* const sdk = getSdk({
|
|
184
|
-
* getRequestHeaders: () => req.headers,
|
|
185
|
-
* });
|
|
186
|
-
* const { products } = await sdk.unified.getProducts();
|
|
187
|
-
*
|
|
188
|
-
* return {
|
|
189
|
-
* props: {...}
|
|
190
|
-
* }
|
|
191
|
-
* };
|
|
192
|
-
* ```
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* For the App Router, you can use the `getSdk` function in your React Server Component:
|
|
196
|
-
* ```tsx
|
|
197
|
-
* import { headers } from "next/headers";
|
|
198
|
-
* import { getSdk } from "../../sdk.config";
|
|
199
|
-
*
|
|
200
|
-
* export default async function SsrPage() {
|
|
201
|
-
* const sdk = getSdk({
|
|
202
|
-
* getRequestHeaders: () => headers(),
|
|
203
|
-
* });
|
|
204
|
-
* const { products } = await sdk.unified.getProducts();
|
|
205
|
-
*
|
|
206
|
-
* return <div>...</div>
|
|
207
|
-
* };
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
getSdk: (dynamicContext?: GetSdkContext) => SDKApi<TConfig>;
|
|
211
|
-
}
|
|
212
|
-
type CreateSdkContextReturn<TSdk extends SDKApi<any>, TSfContract extends SfContract> = Readonly<{
|
|
213
|
-
AlokaiProvider: ({ children, }: AlokaiProviderProps<TSdk, TSfContract>) => JSX.Element;
|
|
214
|
-
useSdk: () => TSdk;
|
|
215
|
-
useSfCurrencyState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrencyState"];
|
|
216
|
-
useSfCurrenciesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrenciesState"];
|
|
217
|
-
useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
|
|
218
|
-
useSfLocalesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocalesState"];
|
|
219
|
-
useSfCartState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCartState"];
|
|
220
|
-
useSfCustomerState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCustomerState"];
|
|
221
|
-
}>;
|
|
222
|
-
|
|
223
|
-
export { type CreateSdkOptions as C, type Maybe as M, type SfContract as S, type Config as a, type CreateSdkReturn as b, type CreateSdkContextReturn as c, type SfStateProps as d, type SfState as e, createSfStateProvider as f };
|
package/dist/types-BdDsK6en.d.ts
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { SDKApi, buildModule, middlewareModule } from '@vue-storefront/sdk';
|
|
2
|
-
import React, { PropsWithChildren, ReactNode } from 'react';
|
|
3
|
-
import { cookies } from 'next/headers';
|
|
4
|
-
|
|
5
|
-
declare const defaultMethodsRequestConfig: {
|
|
6
|
-
readonly unifiedCommerce: {
|
|
7
|
-
readonly middlewareModule: {
|
|
8
|
-
readonly getCategory: {
|
|
9
|
-
readonly method: "GET";
|
|
10
|
-
};
|
|
11
|
-
readonly getCategories: {
|
|
12
|
-
readonly method: "GET";
|
|
13
|
-
};
|
|
14
|
-
readonly getProductDetails: {
|
|
15
|
-
readonly method: "GET";
|
|
16
|
-
};
|
|
17
|
-
readonly getProductReviews: {
|
|
18
|
-
readonly method: "GET";
|
|
19
|
-
};
|
|
20
|
-
readonly getProducts: {
|
|
21
|
-
readonly method: "GET";
|
|
22
|
-
};
|
|
23
|
-
readonly getCurrencies: {
|
|
24
|
-
readonly method: "GET";
|
|
25
|
-
};
|
|
26
|
-
readonly searchProducts: {
|
|
27
|
-
readonly method: "GET";
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
readonly unifiedCms: {
|
|
32
|
-
readonly middlewareModule: {
|
|
33
|
-
readonly getPage: {
|
|
34
|
-
readonly method: "GET";
|
|
35
|
-
};
|
|
36
|
-
readonly getEntries: {
|
|
37
|
-
readonly method: "GET";
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
type Maybe<TType> = TType | null;
|
|
44
|
-
|
|
45
|
-
type SfContract = {
|
|
46
|
-
SfCart: unknown;
|
|
47
|
-
SfCustomer: unknown;
|
|
48
|
-
SfCurrency: unknown;
|
|
49
|
-
SfLocale: unknown;
|
|
50
|
-
};
|
|
51
|
-
interface SfStateProps<TSfContract extends SfContract> {
|
|
52
|
-
currencies: TSfContract["SfCurrency"][];
|
|
53
|
-
currency: TSfContract["SfCurrency"];
|
|
54
|
-
locale: TSfContract["SfLocale"];
|
|
55
|
-
locales: TSfContract["SfLocale"][];
|
|
56
|
-
}
|
|
57
|
-
interface SfState<TSfContract extends SfContract> extends SfStateProps<TSfContract> {
|
|
58
|
-
cart: TSfContract["SfCart"] | null | undefined;
|
|
59
|
-
customer: TSfContract["SfCustomer"] | null | undefined;
|
|
60
|
-
setCart: (cart?: TSfContract["SfCart"] | null) => void;
|
|
61
|
-
setCurrencies: (currencies: TSfContract["SfCurrency"][]) => void;
|
|
62
|
-
setCurrency: (currency: TSfContract["SfCurrency"]) => void;
|
|
63
|
-
setCustomer: (customer?: TSfContract["SfCustomer"] | null) => void;
|
|
64
|
-
setLocale: (locale: TSfContract["SfLocale"]) => void;
|
|
65
|
-
setLocales: (locales: TSfContract["SfLocale"][]) => void;
|
|
66
|
-
}
|
|
67
|
-
declare function createSfStateProvider<TSfContract extends SfContract>(): {
|
|
68
|
-
SfStateProvider: ({ children, initialData, }: {
|
|
69
|
-
initialData: SfStateProps<TSfContract>;
|
|
70
|
-
} & PropsWithChildren) => React.JSX.Element;
|
|
71
|
-
useSfCurrencyState: () => [
|
|
72
|
-
TSfContract["SfCurrency"],
|
|
73
|
-
(currency: TSfContract["SfCurrency"]) => void
|
|
74
|
-
];
|
|
75
|
-
useSfCurrenciesState: () => [
|
|
76
|
-
TSfContract["SfCurrency"][],
|
|
77
|
-
(currencies: TSfContract["SfCurrency"][]) => void
|
|
78
|
-
];
|
|
79
|
-
useSfLocaleState: () => [
|
|
80
|
-
TSfContract["SfLocale"],
|
|
81
|
-
(locale: TSfContract["SfLocale"]) => void
|
|
82
|
-
];
|
|
83
|
-
useSfLocalesState: () => [
|
|
84
|
-
TSfContract["SfLocale"][],
|
|
85
|
-
(locales: TSfContract["SfLocale"][]) => void
|
|
86
|
-
];
|
|
87
|
-
useSfCartState: () => [
|
|
88
|
-
TSfContract["SfCart"] | null | undefined,
|
|
89
|
-
(cart?: TSfContract["SfCart"] | null) => void
|
|
90
|
-
];
|
|
91
|
-
useSfCustomerState: () => [
|
|
92
|
-
TSfContract["SfCustomer"] | null | undefined,
|
|
93
|
-
(customer?: TSfContract["SfCustomer"] | null) => void
|
|
94
|
-
];
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
interface MiddlewareConfig {
|
|
98
|
-
/**
|
|
99
|
-
* The URL of the middleware.
|
|
100
|
-
* @example "http://localhost:4000"
|
|
101
|
-
*/
|
|
102
|
-
apiUrl: string;
|
|
103
|
-
/**
|
|
104
|
-
* The URL of the middleware for server-side rendering.
|
|
105
|
-
* @example "http://localhost:4000"
|
|
106
|
-
*/
|
|
107
|
-
ssrApiUrl?: string;
|
|
108
|
-
/**
|
|
109
|
-
* This is identifier used to invalidate the cache on CDN when the assets change.
|
|
110
|
-
* Usually it's a commit hash.
|
|
111
|
-
* @example "2c106d9619c71c3082c9b59b1d72817363c8ecb9"
|
|
112
|
-
* @default "no-cache-busting-id-set"
|
|
113
|
-
*/
|
|
114
|
-
cdnCacheBustingId?: string;
|
|
115
|
-
}
|
|
116
|
-
interface MultistoreConfig {
|
|
117
|
-
/**
|
|
118
|
-
* Whether the multistore is enabled or not.
|
|
119
|
-
* @example false
|
|
120
|
-
* @default false
|
|
121
|
-
*/
|
|
122
|
-
enabled: boolean;
|
|
123
|
-
}
|
|
124
|
-
interface CreateSdkOptions {
|
|
125
|
-
multistore?: MultistoreConfig;
|
|
126
|
-
middleware: MiddlewareConfig;
|
|
127
|
-
}
|
|
128
|
-
type Cookies = ReturnType<typeof cookies>;
|
|
129
|
-
type NextHeaders = Record<string, string | string[] | undefined> | Headers;
|
|
130
|
-
type GetSdkContext = {
|
|
131
|
-
/**
|
|
132
|
-
* A function that returns the request headers.
|
|
133
|
-
*/
|
|
134
|
-
getRequestHeaders?: () => NextHeaders | {
|
|
135
|
-
headers: NextHeaders;
|
|
136
|
-
cookies: Cookies;
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
type DynamicContext = {
|
|
140
|
-
getRequestHeaders: () => Record<string, string | string[]>;
|
|
141
|
-
};
|
|
142
|
-
type StaticContext = {
|
|
143
|
-
buildModule: typeof buildModule;
|
|
144
|
-
middlewareModule: typeof middlewareModule;
|
|
145
|
-
/**
|
|
146
|
-
* @deprecated Use `config.middlewareUrl` instead.
|
|
147
|
-
*/
|
|
148
|
-
middlewareUrl: string;
|
|
149
|
-
/**
|
|
150
|
-
* @deprecated Use `config.defaultMethodsRequestConfig` instead.
|
|
151
|
-
*/
|
|
152
|
-
defaults: typeof defaultMethodsRequestConfig;
|
|
153
|
-
config: {
|
|
154
|
-
middlewareUrl: string;
|
|
155
|
-
defaultMethodsRequestConfig: typeof defaultMethodsRequestConfig;
|
|
156
|
-
cdnCacheBustingId: string;
|
|
157
|
-
};
|
|
158
|
-
};
|
|
159
|
-
type InjectedContext = DynamicContext & StaticContext;
|
|
160
|
-
type Config<TConfig> = (context: InjectedContext) => TConfig;
|
|
161
|
-
type AlokaiProviderProps<TSdk, TSfContract extends SfContract> = {
|
|
162
|
-
children: ReactNode;
|
|
163
|
-
sdk: TSdk;
|
|
164
|
-
initialData: SfStateProps<TSfContract>;
|
|
165
|
-
};
|
|
166
|
-
interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
167
|
-
/**
|
|
168
|
-
* Creates a new SDK instance. This function is dedicated for server-side usage,
|
|
169
|
-
* where a new SDK instance should be created for each request.
|
|
170
|
-
* For the client side usage, use the `createSdkContext` function instead.
|
|
171
|
-
*
|
|
172
|
-
* @param dynamicContext - The dynamic, request-specific, context
|
|
173
|
-
*
|
|
174
|
-
* @returns The SDK instance.
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* For the Pages Router, you can use the `getSdk` function in the `getServerSideProps` function:
|
|
178
|
-
* ```tsx
|
|
179
|
-
* import type { GetServerSideProps } from "next";
|
|
180
|
-
* import { getSdk } from "../../sdk.config";
|
|
181
|
-
*
|
|
182
|
-
* export const getServerSideProps: GetServerSideProps = async ({ req }) => {
|
|
183
|
-
* const sdk = getSdk({
|
|
184
|
-
* getRequestHeaders: () => req.headers,
|
|
185
|
-
* });
|
|
186
|
-
* const { products } = await sdk.unified.getProducts();
|
|
187
|
-
*
|
|
188
|
-
* return {
|
|
189
|
-
* props: {...}
|
|
190
|
-
* }
|
|
191
|
-
* };
|
|
192
|
-
* ```
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* For the App Router, you can use the `getSdk` function in your React Server Component:
|
|
196
|
-
* ```tsx
|
|
197
|
-
* import { headers } from "next/headers";
|
|
198
|
-
* import { getSdk } from "../../sdk.config";
|
|
199
|
-
*
|
|
200
|
-
* export default async function SsrPage() {
|
|
201
|
-
* const sdk = getSdk({
|
|
202
|
-
* getRequestHeaders: () => headers(),
|
|
203
|
-
* });
|
|
204
|
-
* const { products } = await sdk.unified.getProducts();
|
|
205
|
-
*
|
|
206
|
-
* return <div>...</div>
|
|
207
|
-
* };
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
getSdk: (dynamicContext?: GetSdkContext) => SDKApi<TConfig>;
|
|
211
|
-
}
|
|
212
|
-
type CreateSdkContextReturn<TSdk extends SDKApi<any>, TSfContract extends SfContract> = Readonly<{
|
|
213
|
-
AlokaiProvider: ({ children, }: AlokaiProviderProps<TSdk, TSfContract>) => JSX.Element;
|
|
214
|
-
useSdk: () => TSdk;
|
|
215
|
-
useSfCurrencyState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrencyState"];
|
|
216
|
-
useSfCurrenciesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrenciesState"];
|
|
217
|
-
useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
|
|
218
|
-
useSfLocalesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocalesState"];
|
|
219
|
-
useSfCartState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCartState"];
|
|
220
|
-
useSfCustomerState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCustomerState"];
|
|
221
|
-
}>;
|
|
222
|
-
|
|
223
|
-
export { type CreateSdkOptions as C, type Maybe as M, type SfContract as S, type Config as a, type CreateSdkReturn as b, type CreateSdkContextReturn as c, type SfStateProps as d, type SfState as e, createSfStateProvider as f };
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { SDKApi, buildModule, middlewareModule } from '@alokai/connect/sdk';
|
|
2
|
-
import React, { PropsWithChildren, ReactNode } from 'react';
|
|
3
|
-
import { cookies } from 'next/headers';
|
|
4
|
-
|
|
5
|
-
declare const defaultMethodsRequestConfig: {
|
|
6
|
-
readonly unifiedCommerce: {
|
|
7
|
-
readonly middlewareModule: {
|
|
8
|
-
readonly getCategory: {
|
|
9
|
-
readonly method: "GET";
|
|
10
|
-
};
|
|
11
|
-
readonly getCategories: {
|
|
12
|
-
readonly method: "GET";
|
|
13
|
-
};
|
|
14
|
-
readonly getProductDetails: {
|
|
15
|
-
readonly method: "GET";
|
|
16
|
-
};
|
|
17
|
-
readonly getProductReviews: {
|
|
18
|
-
readonly method: "GET";
|
|
19
|
-
};
|
|
20
|
-
readonly getProducts: {
|
|
21
|
-
readonly method: "GET";
|
|
22
|
-
};
|
|
23
|
-
readonly getCurrencies: {
|
|
24
|
-
readonly method: "GET";
|
|
25
|
-
};
|
|
26
|
-
readonly searchProducts: {
|
|
27
|
-
readonly method: "GET";
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
readonly unifiedCms: {
|
|
32
|
-
readonly middlewareModule: {
|
|
33
|
-
readonly getPage: {
|
|
34
|
-
readonly method: "GET";
|
|
35
|
-
};
|
|
36
|
-
readonly getEntries: {
|
|
37
|
-
readonly method: "GET";
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
type Maybe<TType> = TType | null;
|
|
44
|
-
|
|
45
|
-
type SfContract = {
|
|
46
|
-
SfCart: unknown;
|
|
47
|
-
SfCustomer: unknown;
|
|
48
|
-
SfCurrency: unknown;
|
|
49
|
-
SfLocale: unknown;
|
|
50
|
-
};
|
|
51
|
-
interface SfStateProps<TSfContract extends SfContract> {
|
|
52
|
-
currencies: TSfContract["SfCurrency"][];
|
|
53
|
-
currency: TSfContract["SfCurrency"];
|
|
54
|
-
locale: TSfContract["SfLocale"];
|
|
55
|
-
locales: TSfContract["SfLocale"][];
|
|
56
|
-
}
|
|
57
|
-
interface SfState<TSfContract extends SfContract> extends SfStateProps<TSfContract> {
|
|
58
|
-
cart: TSfContract["SfCart"] | null | undefined;
|
|
59
|
-
customer: TSfContract["SfCustomer"] | null | undefined;
|
|
60
|
-
setCart: (cart?: TSfContract["SfCart"] | null) => void;
|
|
61
|
-
setCurrencies: (currencies: TSfContract["SfCurrency"][]) => void;
|
|
62
|
-
setCurrency: (currency: TSfContract["SfCurrency"]) => void;
|
|
63
|
-
setCustomer: (customer?: TSfContract["SfCustomer"] | null) => void;
|
|
64
|
-
setLocale: (locale: TSfContract["SfLocale"]) => void;
|
|
65
|
-
setLocales: (locales: TSfContract["SfLocale"][]) => void;
|
|
66
|
-
}
|
|
67
|
-
declare function createSfStateProvider<TSfContract extends SfContract>(): {
|
|
68
|
-
SfStateProvider: ({ children, initialData, }: {
|
|
69
|
-
initialData: SfStateProps<TSfContract>;
|
|
70
|
-
} & PropsWithChildren) => React.JSX.Element;
|
|
71
|
-
useSfCurrencyState: () => [
|
|
72
|
-
TSfContract["SfCurrency"],
|
|
73
|
-
(currency: TSfContract["SfCurrency"]) => void
|
|
74
|
-
];
|
|
75
|
-
useSfCurrenciesState: () => [
|
|
76
|
-
TSfContract["SfCurrency"][],
|
|
77
|
-
(currencies: TSfContract["SfCurrency"][]) => void
|
|
78
|
-
];
|
|
79
|
-
useSfLocaleState: () => [
|
|
80
|
-
TSfContract["SfLocale"],
|
|
81
|
-
(locale: TSfContract["SfLocale"]) => void
|
|
82
|
-
];
|
|
83
|
-
useSfLocalesState: () => [
|
|
84
|
-
TSfContract["SfLocale"][],
|
|
85
|
-
(locales: TSfContract["SfLocale"][]) => void
|
|
86
|
-
];
|
|
87
|
-
useSfCartState: () => [
|
|
88
|
-
TSfContract["SfCart"] | null | undefined,
|
|
89
|
-
(cart?: TSfContract["SfCart"] | null) => void
|
|
90
|
-
];
|
|
91
|
-
useSfCustomerState: () => [
|
|
92
|
-
TSfContract["SfCustomer"] | null | undefined,
|
|
93
|
-
(customer?: TSfContract["SfCustomer"] | null) => void
|
|
94
|
-
];
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
interface MiddlewareConfig {
|
|
98
|
-
/**
|
|
99
|
-
* The URL of the middleware.
|
|
100
|
-
* @example "http://localhost:4000"
|
|
101
|
-
*/
|
|
102
|
-
apiUrl: string;
|
|
103
|
-
/**
|
|
104
|
-
* The URL of the middleware for server-side rendering.
|
|
105
|
-
* @example "http://localhost:4000"
|
|
106
|
-
*/
|
|
107
|
-
ssrApiUrl?: string;
|
|
108
|
-
/**
|
|
109
|
-
* This is identifier used to invalidate the cache on CDN when the assets change.
|
|
110
|
-
* Usually it's a commit hash.
|
|
111
|
-
* @example "2c106d9619c71c3082c9b59b1d72817363c8ecb9"
|
|
112
|
-
* @default "no-cache-busting-id-set"
|
|
113
|
-
*/
|
|
114
|
-
cdnCacheBustingId?: string;
|
|
115
|
-
}
|
|
116
|
-
interface MultistoreConfig {
|
|
117
|
-
/**
|
|
118
|
-
* Whether the multistore is enabled or not.
|
|
119
|
-
* @example false
|
|
120
|
-
* @default false
|
|
121
|
-
*/
|
|
122
|
-
enabled: boolean;
|
|
123
|
-
}
|
|
124
|
-
interface CreateSdkOptions {
|
|
125
|
-
multistore?: MultistoreConfig;
|
|
126
|
-
middleware: MiddlewareConfig;
|
|
127
|
-
}
|
|
128
|
-
type Cookies = ReturnType<typeof cookies>;
|
|
129
|
-
type NextHeaders = Record<string, string | string[] | undefined> | Headers;
|
|
130
|
-
type GetSdkContext = {
|
|
131
|
-
/**
|
|
132
|
-
* A function that returns the request headers.
|
|
133
|
-
*/
|
|
134
|
-
getRequestHeaders?: () => NextHeaders | {
|
|
135
|
-
headers: NextHeaders;
|
|
136
|
-
cookies: Cookies;
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
type DynamicContext = {
|
|
140
|
-
getRequestHeaders: () => Record<string, string | string[]>;
|
|
141
|
-
};
|
|
142
|
-
type StaticContext = {
|
|
143
|
-
buildModule: typeof buildModule;
|
|
144
|
-
middlewareModule: typeof middlewareModule;
|
|
145
|
-
/**
|
|
146
|
-
* @deprecated Use `config.middlewareUrl` instead.
|
|
147
|
-
*/
|
|
148
|
-
middlewareUrl: string;
|
|
149
|
-
/**
|
|
150
|
-
* @deprecated Use `config.defaultMethodsRequestConfig` instead.
|
|
151
|
-
*/
|
|
152
|
-
defaults: typeof defaultMethodsRequestConfig;
|
|
153
|
-
config: {
|
|
154
|
-
middlewareUrl: string;
|
|
155
|
-
defaultMethodsRequestConfig: typeof defaultMethodsRequestConfig;
|
|
156
|
-
cdnCacheBustingId: string;
|
|
157
|
-
};
|
|
158
|
-
};
|
|
159
|
-
type InjectedContext = DynamicContext & StaticContext;
|
|
160
|
-
type Config<TConfig> = (context: InjectedContext) => TConfig;
|
|
161
|
-
type AlokaiProviderProps<TSdk, TSfContract extends SfContract> = {
|
|
162
|
-
children: ReactNode;
|
|
163
|
-
sdk: TSdk;
|
|
164
|
-
initialData: SfStateProps<TSfContract>;
|
|
165
|
-
};
|
|
166
|
-
interface CreateSdkReturn<TConfig extends Record<string, any>> {
|
|
167
|
-
/**
|
|
168
|
-
* Creates a new SDK instance. This function is dedicated for server-side usage,
|
|
169
|
-
* where a new SDK instance should be created for each request.
|
|
170
|
-
* For the client side usage, use the `createSdkContext` function instead.
|
|
171
|
-
*
|
|
172
|
-
* @param dynamicContext - The dynamic, request-specific, context
|
|
173
|
-
*
|
|
174
|
-
* @returns The SDK instance.
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* For the Pages Router, you can use the `getSdk` function in the `getServerSideProps` function:
|
|
178
|
-
* ```tsx
|
|
179
|
-
* import type { GetServerSideProps } from "next";
|
|
180
|
-
* import { getSdk } from "../../sdk.config";
|
|
181
|
-
*
|
|
182
|
-
* export const getServerSideProps: GetServerSideProps = async ({ req }) => {
|
|
183
|
-
* const sdk = getSdk({
|
|
184
|
-
* getRequestHeaders: () => req.headers,
|
|
185
|
-
* });
|
|
186
|
-
* const { products } = await sdk.unified.getProducts();
|
|
187
|
-
*
|
|
188
|
-
* return {
|
|
189
|
-
* props: {...}
|
|
190
|
-
* }
|
|
191
|
-
* };
|
|
192
|
-
* ```
|
|
193
|
-
*
|
|
194
|
-
* @example
|
|
195
|
-
* For the App Router, you can use the `getSdk` function in your React Server Component:
|
|
196
|
-
* ```tsx
|
|
197
|
-
* import { headers } from "next/headers";
|
|
198
|
-
* import { getSdk } from "../../sdk.config";
|
|
199
|
-
*
|
|
200
|
-
* export default async function SsrPage() {
|
|
201
|
-
* const sdk = getSdk({
|
|
202
|
-
* getRequestHeaders: () => headers(),
|
|
203
|
-
* });
|
|
204
|
-
* const { products } = await sdk.unified.getProducts();
|
|
205
|
-
*
|
|
206
|
-
* return <div>...</div>
|
|
207
|
-
* };
|
|
208
|
-
* ```
|
|
209
|
-
*/
|
|
210
|
-
getSdk: (dynamicContext?: GetSdkContext) => SDKApi<TConfig>;
|
|
211
|
-
}
|
|
212
|
-
type CreateSdkContextReturn<TSdk extends SDKApi<any>, TSfContract extends SfContract> = Readonly<{
|
|
213
|
-
AlokaiProvider: ({ children, }: AlokaiProviderProps<TSdk, TSfContract>) => JSX.Element;
|
|
214
|
-
useSdk: () => TSdk;
|
|
215
|
-
useSfCurrencyState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrencyState"];
|
|
216
|
-
useSfCurrenciesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrenciesState"];
|
|
217
|
-
useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
|
|
218
|
-
useSfLocalesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocalesState"];
|
|
219
|
-
useSfCartState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCartState"];
|
|
220
|
-
useSfCustomerState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCustomerState"];
|
|
221
|
-
}>;
|
|
222
|
-
|
|
223
|
-
export { type CreateSdkOptions as C, type Maybe as M, type SfContract as S, type Config as a, type CreateSdkReturn as b, type CreateSdkContextReturn as c, type SfStateProps as d, type SfState as e, createSfStateProvider as f };
|