@vue-storefront/next 4.3.0 → 4.3.2

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/README.md CHANGED
@@ -51,7 +51,7 @@ export const { getSdk, createSdkContext } = createSdk(
51
51
  contentful: buildModule<ContentfulModuleType>(contentfulModule, {
52
52
  apiUrl: middlewareUrl + "/cntf",
53
53
  }),
54
- }),
54
+ })
55
55
  );
56
56
  ```
57
57
 
package/dist/client.d.mts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { SDKApi } from '@vue-storefront/sdk';
2
- import { S as SfContract, c as CreateSdkContextReturn } from './types-FxigqFRO.mjs';
3
- export { M as Maybe, e as SfState, d as SfStateProps, f as createSfStateProvider } from './types-FxigqFRO.mjs';
2
+ import { S as SfContract, c as CreateSdkContextReturn } from './types-BdDsK6en.mjs';
3
+ export { M as Maybe, e as SfState, d as SfStateProps, f as createSfStateProvider } from './types-BdDsK6en.mjs';
4
4
  import 'react';
5
+ import 'next/headers';
5
6
 
6
7
  /**
7
8
  * Creates a new Alokai context which is a combination of SDK and state contexts.
@@ -11,16 +12,33 @@ import 'react';
11
12
  * Create a new Alokai context somewhere in your application. It may be the `hooks/sdk.ts` file.
12
13
  *
13
14
  * ```tsx
15
+ * 'use client';
16
+ *
14
17
  * import { createAlokaiContext } from "@vue-storefront/next/client";
15
18
  * import type { Sdk } from './sdk.server';
19
+ * import type { SfContract } from 'storefront-middleware/types';
16
20
  *
17
- * export const [AlokaiProvider, useSdk] = createAlokaiContext<Sdk>();
21
+ * export const {
22
+ * AlokaiProvider,
23
+ * useSdk,
24
+ * useSfCartState,
25
+ * useSfCurrenciesState,
26
+ * useSfCurrencyState,
27
+ * useSfCustomerState,
28
+ * } = createAlokaiContext<Sdk, SfContract>();
18
29
  * ```
30
+ * This is also a place where you can import hooks for handling the state management.
31
+ * You can read more about the state management in the documentation https://docs.alokai.com/sdk/getting-started/state-management.
19
32
  * Then use the `AlokaiProvider` in the root component of your application.
20
33
  * For Pages Router it would be the `pages/_app.tsx` file,
21
34
  * and for the App Router it would be the `app/layout.tsx` file.
22
35
  * Finally, you can use the `useSdk` in any client component of your application.
23
- * @returns [AlokaiProvider, useSdk] - The SDK provider and the `useSdk` hook.
36
+ * @returns AlokaiProvider - The Alokai Context Provider.
37
+ * @returns useSdk - The SDK provider and the `useSdk` hook.
38
+ * @returns useSfCartState - Hook that return Cart state with `SfCart` type.
39
+ * @returns useSfCurrenciesState - Hook that return Currencies state with `SfCurrency` type.
40
+ * @returns useSfCurrencyState - Hook that return Currency state with `SfCurrency[]` type.
41
+ * @returns useSfCustomerState - Hook that return Customer state with `SfCustomer` type.
24
42
  */
25
43
  declare function createAlokaiContext<TSdk extends SDKApi<any>, TSfContract extends SfContract>(): CreateSdkContextReturn<TSdk, TSfContract>;
26
44
 
package/dist/client.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { SDKApi } from '@vue-storefront/sdk';
2
- import { S as SfContract, c as CreateSdkContextReturn } from './types-FxigqFRO.js';
3
- export { M as Maybe, e as SfState, d as SfStateProps, f as createSfStateProvider } from './types-FxigqFRO.js';
2
+ import { S as SfContract, c as CreateSdkContextReturn } from './types-BdDsK6en.js';
3
+ export { M as Maybe, e as SfState, d as SfStateProps, f as createSfStateProvider } from './types-BdDsK6en.js';
4
4
  import 'react';
5
+ import 'next/headers';
5
6
 
6
7
  /**
7
8
  * Creates a new Alokai context which is a combination of SDK and state contexts.
@@ -11,16 +12,33 @@ import 'react';
11
12
  * Create a new Alokai context somewhere in your application. It may be the `hooks/sdk.ts` file.
12
13
  *
13
14
  * ```tsx
15
+ * 'use client';
16
+ *
14
17
  * import { createAlokaiContext } from "@vue-storefront/next/client";
15
18
  * import type { Sdk } from './sdk.server';
19
+ * import type { SfContract } from 'storefront-middleware/types';
16
20
  *
17
- * export const [AlokaiProvider, useSdk] = createAlokaiContext<Sdk>();
21
+ * export const {
22
+ * AlokaiProvider,
23
+ * useSdk,
24
+ * useSfCartState,
25
+ * useSfCurrenciesState,
26
+ * useSfCurrencyState,
27
+ * useSfCustomerState,
28
+ * } = createAlokaiContext<Sdk, SfContract>();
18
29
  * ```
30
+ * This is also a place where you can import hooks for handling the state management.
31
+ * You can read more about the state management in the documentation https://docs.alokai.com/sdk/getting-started/state-management.
19
32
  * Then use the `AlokaiProvider` in the root component of your application.
20
33
  * For Pages Router it would be the `pages/_app.tsx` file,
21
34
  * and for the App Router it would be the `app/layout.tsx` file.
22
35
  * Finally, you can use the `useSdk` in any client component of your application.
23
- * @returns [AlokaiProvider, useSdk] - The SDK provider and the `useSdk` hook.
36
+ * @returns AlokaiProvider - The Alokai Context Provider.
37
+ * @returns useSdk - The SDK provider and the `useSdk` hook.
38
+ * @returns useSfCartState - Hook that return Cart state with `SfCart` type.
39
+ * @returns useSfCurrenciesState - Hook that return Currencies state with `SfCurrency` type.
40
+ * @returns useSfCurrencyState - Hook that return Currency state with `SfCurrency[]` type.
41
+ * @returns useSfCustomerState - Hook that return Customer state with `SfCustomer` type.
24
42
  */
25
43
  declare function createAlokaiContext<TSdk extends SDKApi<any>, TSfContract extends SfContract>(): CreateSdkContextReturn<TSdk, TSfContract>;
26
44
 
package/dist/index.d.mts CHANGED
@@ -1,7 +1,8 @@
1
- import { C as CreateSdkOptions, a as Config, b as CreateSdkReturn } from './types-FxigqFRO.mjs';
1
+ import { C as CreateSdkOptions, a as Config, b as CreateSdkReturn } from './types-BdDsK6en.mjs';
2
2
  import * as _vue_storefront_logger from '@vue-storefront/logger';
3
3
  import '@vue-storefront/sdk';
4
4
  import 'react';
5
+ import 'next/headers';
5
6
 
6
7
  /**
7
8
  * Creates an SDK for the given configuration definition.
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { C as CreateSdkOptions, a as Config, b as CreateSdkReturn } from './types-FxigqFRO.js';
1
+ import { C as CreateSdkOptions, a as Config, b as CreateSdkReturn } from './types-BdDsK6en.js';
2
2
  import * as _vue_storefront_logger from '@vue-storefront/logger';
3
3
  import '@vue-storefront/sdk';
4
4
  import 'react';
5
+ import 'next/headers';
5
6
 
6
7
  /**
7
8
  * Creates an SDK for the given configuration definition.
package/dist/index.js CHANGED
@@ -47,16 +47,31 @@ module.exports = __toCommonJS(src_exports);
47
47
  // src/sdk/helpers/resolveDynamicContext.ts
48
48
  var BLACKLISTED_HEADERS = /* @__PURE__ */ new Set(["host"]);
49
49
  function isAppRouterHeaders(headers) {
50
- return headers && "entries" in headers;
50
+ return !!headers && "entries" in headers;
51
+ }
52
+ function isFlatNextHeaders(headers) {
53
+ return !!headers && !("headers" in headers);
54
+ }
55
+ function normalizeRequestHeaders(requestHeaders) {
56
+ const { headers = {}, cookies } = isFlatNextHeaders(requestHeaders) ? { headers: requestHeaders, cookies: void 0 } : {
57
+ headers: requestHeaders == null ? void 0 : requestHeaders.headers,
58
+ cookies: requestHeaders == null ? void 0 : requestHeaders.cookies
59
+ };
60
+ const normalizedHeaders = isAppRouterHeaders(headers) ? Object.fromEntries(headers.entries()) : headers;
61
+ if (cookies) {
62
+ normalizedHeaders.cookie = cookies.toString();
63
+ }
64
+ return normalizedHeaders;
51
65
  }
52
66
  function resolveDynamicContext(context) {
53
67
  return __spreadProps(__spreadValues({}, context), {
54
68
  getRequestHeaders() {
55
69
  var _a;
56
- const headers = ((_a = context.getRequestHeaders) == null ? void 0 : _a.call(context)) || {};
57
- const resolvedHeaders = isAppRouterHeaders(headers) ? Object.fromEntries(headers.entries()) : headers;
70
+ const normalizedHeaders = normalizeRequestHeaders(
71
+ (_a = context.getRequestHeaders) == null ? void 0 : _a.call(context)
72
+ );
58
73
  return Object.fromEntries(
59
- Object.entries(resolvedHeaders).filter(
74
+ Object.entries(normalizedHeaders).filter(
60
75
  ([key]) => !BLACKLISTED_HEADERS.has(key)
61
76
  )
62
77
  );
package/dist/index.mjs CHANGED
@@ -6,16 +6,31 @@ import {
6
6
  // src/sdk/helpers/resolveDynamicContext.ts
7
7
  var BLACKLISTED_HEADERS = /* @__PURE__ */ new Set(["host"]);
8
8
  function isAppRouterHeaders(headers) {
9
- return headers && "entries" in headers;
9
+ return !!headers && "entries" in headers;
10
+ }
11
+ function isFlatNextHeaders(headers) {
12
+ return !!headers && !("headers" in headers);
13
+ }
14
+ function normalizeRequestHeaders(requestHeaders) {
15
+ const { headers = {}, cookies } = isFlatNextHeaders(requestHeaders) ? { headers: requestHeaders, cookies: void 0 } : {
16
+ headers: requestHeaders == null ? void 0 : requestHeaders.headers,
17
+ cookies: requestHeaders == null ? void 0 : requestHeaders.cookies
18
+ };
19
+ const normalizedHeaders = isAppRouterHeaders(headers) ? Object.fromEntries(headers.entries()) : headers;
20
+ if (cookies) {
21
+ normalizedHeaders.cookie = cookies.toString();
22
+ }
23
+ return normalizedHeaders;
10
24
  }
11
25
  function resolveDynamicContext(context) {
12
26
  return __spreadProps(__spreadValues({}, context), {
13
27
  getRequestHeaders() {
14
28
  var _a;
15
- const headers = ((_a = context.getRequestHeaders) == null ? void 0 : _a.call(context)) || {};
16
- const resolvedHeaders = isAppRouterHeaders(headers) ? Object.fromEntries(headers.entries()) : headers;
29
+ const normalizedHeaders = normalizeRequestHeaders(
30
+ (_a = context.getRequestHeaders) == null ? void 0 : _a.call(context)
31
+ );
17
32
  return Object.fromEntries(
18
- Object.entries(resolvedHeaders).filter(
33
+ Object.entries(normalizedHeaders).filter(
19
34
  ([key]) => !BLACKLISTED_HEADERS.has(key)
20
35
  )
21
36
  );
@@ -1,5 +1,6 @@
1
1
  import { SDKApi, buildModule, middlewareModule } from '@vue-storefront/sdk';
2
2
  import React, { PropsWithChildren, ReactNode } from 'react';
3
+ import { cookies } from 'next/headers';
3
4
 
4
5
  declare const defaultMethodsRequestConfig: {
5
6
  readonly unifiedCommerce: {
@@ -124,11 +125,16 @@ interface CreateSdkOptions {
124
125
  multistore?: MultistoreConfig;
125
126
  middleware: MiddlewareConfig;
126
127
  }
128
+ type Cookies = ReturnType<typeof cookies>;
129
+ type NextHeaders = Record<string, string | string[] | undefined> | Headers;
127
130
  type GetSdkContext = {
128
131
  /**
129
132
  * A function that returns the request headers.
130
133
  */
131
- getRequestHeaders?: () => Record<string, string | string[] | undefined> | Headers;
134
+ getRequestHeaders?: () => NextHeaders | {
135
+ headers: NextHeaders;
136
+ cookies: Cookies;
137
+ };
132
138
  };
133
139
  type DynamicContext = {
134
140
  getRequestHeaders: () => Record<string, string | string[]>;
@@ -1,5 +1,6 @@
1
1
  import { SDKApi, buildModule, middlewareModule } from '@vue-storefront/sdk';
2
2
  import React, { PropsWithChildren, ReactNode } from 'react';
3
+ import { cookies } from 'next/headers';
3
4
 
4
5
  declare const defaultMethodsRequestConfig: {
5
6
  readonly unifiedCommerce: {
@@ -124,11 +125,16 @@ interface CreateSdkOptions {
124
125
  multistore?: MultistoreConfig;
125
126
  middleware: MiddlewareConfig;
126
127
  }
128
+ type Cookies = ReturnType<typeof cookies>;
129
+ type NextHeaders = Record<string, string | string[] | undefined> | Headers;
127
130
  type GetSdkContext = {
128
131
  /**
129
132
  * A function that returns the request headers.
130
133
  */
131
- getRequestHeaders?: () => Record<string, string | string[] | undefined> | Headers;
134
+ getRequestHeaders?: () => NextHeaders | {
135
+ headers: NextHeaders;
136
+ cookies: Cookies;
137
+ };
132
138
  };
133
139
  type DynamicContext = {
134
140
  getRequestHeaders: () => Record<string, string | string[]>;
package/package.json CHANGED
@@ -2,17 +2,17 @@
2
2
  "name": "@vue-storefront/next",
3
3
  "description": "Alokai dedicated features for Next.js",
4
4
  "license": "MIT",
5
- "version": "4.3.0",
5
+ "version": "4.3.2",
6
6
  "exports": {
7
7
  ".": {
8
+ "types": "./dist/index.d.ts",
8
9
  "import": "./dist/index.mjs",
9
- "require": "./dist/index.js",
10
- "types": "./dist/index.d.ts"
10
+ "require": "./dist/index.js"
11
11
  },
12
12
  "./client": {
13
+ "types": "./dist/client.d.ts",
13
14
  "import": "./dist/client.js",
14
- "require": "./dist/client.js",
15
- "types": "./dist/client.d.ts"
15
+ "require": "./dist/client.js"
16
16
  }
17
17
  },
18
18
  "files": [
@@ -22,7 +22,8 @@
22
22
  "build": "tsup",
23
23
  "lint": "biome ci .",
24
24
  "format": "prettier --write .",
25
- "test:unit": "vitest run"
25
+ "test:unit": "vitest run",
26
+ "version": "cp CHANGELOG.md ../../docs/content/storefront/6.change-log/next.md"
26
27
  },
27
28
  "dependencies": {
28
29
  "zustand": "^4.5.4",
@@ -31,16 +32,16 @@
31
32
  "devDependencies": {
32
33
  "@types/react": "18.3.2",
33
34
  "@types/react-dom": "18.3.0",
34
- "@vue-storefront/sdk": "3.3.0",
35
- "react-dom": "18.3.0",
35
+ "@vue-storefront/sdk": "3.4.1",
36
+ "react-dom": "18.3.1",
36
37
  "start-server-and-test": "^2.0.3",
37
38
  "tsup": "8.3.0",
38
- "vitest": "2.0.3",
39
+ "vitest": "2.1.5",
39
40
  "react": "18.3.1",
40
- "next": "14.2.5"
41
+ "next": "14.2.23"
41
42
  },
42
43
  "peerDependencies": {
43
- "@vue-storefront/sdk": "3.3.0",
44
+ "@vue-storefront/sdk": "3.4.1",
44
45
  "react": "^18.2.0",
45
46
  "next": "^13.4.7 || ^14.0.0"
46
47
  },