@vue-storefront/next 6.0.0-rc.0 → 6.0.0-rc.1

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.
@@ -0,0 +1,223 @@
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 };
@@ -0,0 +1,220 @@
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.defaultMethodsRequestConfig` instead.
147
+ */
148
+ defaults: typeof defaultMethodsRequestConfig;
149
+ config: {
150
+ apiUrl: string;
151
+ ssrApiUrl: string;
152
+ defaultMethodsRequestConfig: typeof defaultMethodsRequestConfig;
153
+ cdnCacheBustingId: string;
154
+ };
155
+ };
156
+ type InjectedContext = DynamicContext & StaticContext;
157
+ type Config<TConfig> = (context: InjectedContext) => TConfig;
158
+ type AlokaiProviderProps<TSdk, TSfContract extends SfContract> = {
159
+ children: ReactNode;
160
+ sdk: TSdk;
161
+ initialData: SfStateProps<TSfContract>;
162
+ };
163
+ interface CreateSdkReturn<TConfig extends Record<string, any>> {
164
+ /**
165
+ * Creates a new SDK instance. This function is dedicated for server-side usage,
166
+ * where a new SDK instance should be created for each request.
167
+ * For the client side usage, use the `createSdkContext` function instead.
168
+ *
169
+ * @param dynamicContext - The dynamic, request-specific, context
170
+ *
171
+ * @returns The SDK instance.
172
+ *
173
+ * @example
174
+ * For the Pages Router, you can use the `getSdk` function in the `getServerSideProps` function:
175
+ * ```tsx
176
+ * import type { GetServerSideProps } from "next";
177
+ * import { getSdk } from "../../sdk.config";
178
+ *
179
+ * export const getServerSideProps: GetServerSideProps = async ({ req }) => {
180
+ * const sdk = getSdk({
181
+ * getRequestHeaders: () => req.headers,
182
+ * });
183
+ * const { products } = await sdk.unified.getProducts();
184
+ *
185
+ * return {
186
+ * props: {...}
187
+ * }
188
+ * };
189
+ * ```
190
+ *
191
+ * @example
192
+ * For the App Router, you can use the `getSdk` function in your React Server Component:
193
+ * ```tsx
194
+ * import { headers } from "next/headers";
195
+ * import { getSdk } from "../../sdk.config";
196
+ *
197
+ * export default async function SsrPage() {
198
+ * const sdk = getSdk({
199
+ * getRequestHeaders: () => headers(),
200
+ * });
201
+ * const { products } = await sdk.unified.getProducts();
202
+ *
203
+ * return <div>...</div>
204
+ * };
205
+ * ```
206
+ */
207
+ getSdk: (dynamicContext?: GetSdkContext) => SDKApi<TConfig>;
208
+ }
209
+ type CreateSdkContextReturn<TSdk extends SDKApi<any>, TSfContract extends SfContract> = Readonly<{
210
+ AlokaiProvider: ({ children, }: AlokaiProviderProps<TSdk, TSfContract>) => JSX.Element;
211
+ useSdk: () => TSdk;
212
+ useSfCurrencyState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrencyState"];
213
+ useSfCurrenciesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrenciesState"];
214
+ useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
215
+ useSfLocalesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocalesState"];
216
+ useSfCartState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCartState"];
217
+ useSfCustomerState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCustomerState"];
218
+ }>;
219
+
220
+ 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 };
@@ -0,0 +1,220 @@
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.defaultMethodsRequestConfig` instead.
147
+ */
148
+ defaults: typeof defaultMethodsRequestConfig;
149
+ config: {
150
+ apiUrl: string;
151
+ ssrApiUrl: string;
152
+ defaultMethodsRequestConfig: typeof defaultMethodsRequestConfig;
153
+ cdnCacheBustingId: string;
154
+ };
155
+ };
156
+ type InjectedContext = DynamicContext & StaticContext;
157
+ type Config<TConfig> = (context: InjectedContext) => TConfig;
158
+ type AlokaiProviderProps<TSdk, TSfContract extends SfContract> = {
159
+ children: ReactNode;
160
+ sdk: TSdk;
161
+ initialData: SfStateProps<TSfContract>;
162
+ };
163
+ interface CreateSdkReturn<TConfig extends Record<string, any>> {
164
+ /**
165
+ * Creates a new SDK instance. This function is dedicated for server-side usage,
166
+ * where a new SDK instance should be created for each request.
167
+ * For the client side usage, use the `createSdkContext` function instead.
168
+ *
169
+ * @param dynamicContext - The dynamic, request-specific, context
170
+ *
171
+ * @returns The SDK instance.
172
+ *
173
+ * @example
174
+ * For the Pages Router, you can use the `getSdk` function in the `getServerSideProps` function:
175
+ * ```tsx
176
+ * import type { GetServerSideProps } from "next";
177
+ * import { getSdk } from "../../sdk.config";
178
+ *
179
+ * export const getServerSideProps: GetServerSideProps = async ({ req }) => {
180
+ * const sdk = getSdk({
181
+ * getRequestHeaders: () => req.headers,
182
+ * });
183
+ * const { products } = await sdk.unified.getProducts();
184
+ *
185
+ * return {
186
+ * props: {...}
187
+ * }
188
+ * };
189
+ * ```
190
+ *
191
+ * @example
192
+ * For the App Router, you can use the `getSdk` function in your React Server Component:
193
+ * ```tsx
194
+ * import { headers } from "next/headers";
195
+ * import { getSdk } from "../../sdk.config";
196
+ *
197
+ * export default async function SsrPage() {
198
+ * const sdk = getSdk({
199
+ * getRequestHeaders: () => headers(),
200
+ * });
201
+ * const { products } = await sdk.unified.getProducts();
202
+ *
203
+ * return <div>...</div>
204
+ * };
205
+ * ```
206
+ */
207
+ getSdk: (dynamicContext?: GetSdkContext) => SDKApi<TConfig>;
208
+ }
209
+ type CreateSdkContextReturn<TSdk extends SDKApi<any>, TSfContract extends SfContract> = Readonly<{
210
+ AlokaiProvider: ({ children, }: AlokaiProviderProps<TSdk, TSfContract>) => JSX.Element;
211
+ useSdk: () => TSdk;
212
+ useSfCurrencyState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrencyState"];
213
+ useSfCurrenciesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCurrenciesState"];
214
+ useSfLocaleState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocaleState"];
215
+ useSfLocalesState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfLocalesState"];
216
+ useSfCartState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCartState"];
217
+ useSfCustomerState: ReturnType<typeof createSfStateProvider<TSfContract>>["useSfCustomerState"];
218
+ }>;
219
+
220
+ 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 };