@vue-storefront/next 7.0.0-next.3 → 7.0.0-next.5

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.
@@ -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 };