@vtex/faststore-plugin-buyer-portal 2.0.3 → 2.0.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.
package/CHANGELOG.md CHANGED
@@ -7,9 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.0.5] - 2026-06-17
11
+
12
+ ### Fixed
13
+
14
+ - Use useRouter insted of window.location on OrderEntry handshake
15
+
16
+ ## [2.0.4] - 2026-06-17
17
+
18
+ ### Added
19
+
20
+ - Add handler for message that sends buyer to checkout and sets orderForm cookie
21
+
10
22
  ## [2.0.3] - 2026-06-04
11
23
 
12
24
  ### Fixed
25
+
13
26
  - Turn filterByUnit flag to false on create an accounting field value to search for all all units in a contract.
14
27
 
15
28
  ## [2.0.2] - 2026-06-03
@@ -689,7 +702,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
689
702
  - Add CHANGELOG file
690
703
  - Add README file
691
704
 
692
- [unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v2.0.3...HEAD
705
+ [unreleased]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v2.0.5...HEAD
693
706
  [1.3.55]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.54...v1.3.55
694
707
  [1.3.54]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.53...v1.3.54
695
708
  [1.3.53]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.52...v1.3.53
@@ -775,7 +788,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
775
788
  [1.3.85]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.3.85
776
789
  [1.3.87]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v1.3.86...v1.3.87
777
790
  [1.3.86]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/1.3.86
778
-
791
+ [2.0.5]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v2.0.4...v2.0.5
792
+ [2.0.4]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v2.0.3...v2.0.4
779
793
  [2.0.3]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v2.0.2...v2.0.3
780
794
  [2.0.2]: https://github.com/vtex/faststore-plugin-buyer-portal/compare/v2.0.1...v2.0.2
781
795
  [2.0.1]: https://github.com/vtex/faststore-plugin-buyer-portal/releases/tag/2.0.1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/faststore-plugin-buyer-portal",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,5 +1,9 @@
1
1
  import { useEffect, useMemo, useRef } from "react";
2
2
 
3
+ import storeConfig from "discovery.config";
4
+
5
+ import { useRouter } from "next/router";
6
+
3
7
  import { isDevelopment } from "../../shared/utils/environment";
4
8
 
5
9
  const B2B_AGENT_URL = isDevelopment()
@@ -43,12 +47,15 @@ export const OrderEntryLayout = ({
43
47
  userId,
44
48
  }: OrderEntryLayoutProps) => {
45
49
  const iframeRef = useRef<HTMLIFrameElement>(null);
50
+ const router = useRouter();
46
51
 
47
52
  const agentOrigin = useMemo(() => new URL(B2B_AGENT_URL).origin, []);
48
53
 
49
54
  useEffect(() => {
50
55
  function postAuthToIframe() {
51
56
  const targetWindow = iframeRef.current?.contentWindow;
57
+ const quoteId = router.query.quoteId ?? "";
58
+
52
59
  if (!targetWindow) return;
53
60
 
54
61
  // We send only the token (not the full Cookie header) to reduce exposure.
@@ -63,11 +70,30 @@ export const OrderEntryLayout = ({
63
70
  locale,
64
71
  customerId,
65
72
  userId,
73
+ quoteId,
66
74
  },
67
75
  agentOrigin
68
76
  );
69
77
  }
70
78
 
79
+ function primeOrderFormCookie(orderFormId: string) {
80
+ const secureSubdomain = storeConfig?.secureSubdomain;
81
+ if (!secureSubdomain) return Promise.resolve(false);
82
+
83
+ const url = new URL(
84
+ `/api/checkout/pub/orderForm/${encodeURIComponent(
85
+ orderFormId
86
+ )}?refreshOutdatedData=true`,
87
+ secureSubdomain
88
+ );
89
+
90
+ return fetch(url.toString(), {
91
+ method: "GET",
92
+ credentials: "include",
93
+ cache: "no-store",
94
+ }).then((res) => res.ok);
95
+ }
96
+
71
97
  function onMessage(event: MessageEvent) {
72
98
  // Only accept messages coming from the iframe's origin.
73
99
  if (event.origin !== agentOrigin) return;
@@ -79,6 +105,29 @@ export const OrderEntryLayout = ({
79
105
  if (event.data?.type === "B2B_AGENT_READY") {
80
106
  postAuthToIframe();
81
107
  }
108
+
109
+ if (event.data?.type === "B2B_GO_TO_CHECKOUT") {
110
+ const orderFormId = event.data?.orderFormId;
111
+ const secureSubdomain = storeConfig?.secureSubdomain;
112
+ if (
113
+ !secureSubdomain ||
114
+ typeof orderFormId !== "string" ||
115
+ !orderFormId
116
+ ) {
117
+ return;
118
+ }
119
+ primeOrderFormCookie(orderFormId)
120
+ .then((ok) => {
121
+ if (!ok) return;
122
+ window.location.assign(`${secureSubdomain}/checkout/payment`);
123
+ })
124
+ .catch((error) => {
125
+ console.warn(
126
+ "Failed to prime orderForm cookie before checkout",
127
+ error
128
+ );
129
+ });
130
+ }
82
131
  }
83
132
 
84
133
  window.addEventListener("message", onMessage);
@@ -22,7 +22,7 @@ export const SCOPE_KEYS = {
22
22
  CREDIT_CARDS: "creditCards",
23
23
  } as const;
24
24
 
25
- export const CURRENT_VERSION = "2.0.3";
25
+ export const CURRENT_VERSION = "2.0.5";
26
26
 
27
27
  export const CHANGES_TIMEOUT_MESSAGE =
28
28
  "Changes may take up to 10 minutes to apply.";