PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.75
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.75
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
← All changes | scripts/iframe/messageMiddleware.ts +149 -11 11.0.711.3.75 View file →
@@ -1,5 +1,5 @@
1 -import { MessageType, PluginMessages } from '../iframe/integratedMessages';
1 +import { MessageType, PluginMessages } from './integratedMessages';
2 2 import {
3 3 fetchDisableInternalTracking,
4 4 trackConsent,
5 5 disableInternalTracking,
@@ -5,13 +5,42 @@
5 5 disableInternalTracking,
6 6 getBusinessUnitId,
7 7 setBusinessUnitId,
8 8 skipReview,
9 + refreshProxyMappingsCache,
10 + fetchProxyMappingsEnabled,
11 + toggleProxyMappingsEnabled,
9 12 } from '../api/wordpressApiClient';
10 13 import { removeQueryParamFromLocation } from '../utils/queryParams';
14 +import { startActivation, startInstall } from '../utils/contentEmbedInstaller';
11 15
12 16 export type Message = { key: MessageType; payload?: any };
13 17
18 +/*
19 + * We cannot postMessage error objects. We will run into serialization errors
20 + * Extract some properties we care about from the errors and create an error object from these
21 + */
22 +function createSafeErrorPayload(
23 + error: any,
24 + defaultMessage: string = 'An error occurred'
25 +) {
26 + const safePayload: any = {
27 + status: (error && error.status) || 500,
28 + statusText: (error && error.statusText) || 'Error',
29 + message:
30 + (error && error.responseJSON && error.responseJSON.message) ||
31 + (error && error.message) ||
32 + defaultMessage,
33 + code: error && error.responseJSON && error.responseJSON.code,
34 + };
35 +
36 + if (error && error.responseJSON && error.responseJSON.data) {
37 + safePayload.data = error.responseJSON.data;
38 + }
39 +
40 + return safePayload;
41 +}
42 +
14 43 const messageMapper: Map<MessageType, Function> = new Map([
15 44 [
16 45 PluginMessages.TrackConsent,
17 46 (message: Message) => {
@@ -27,12 +56,13 @@
27 56 key: PluginMessages.InternalTrackingFetchResponse,
28 57 payload: message.payload,
29 58 });
30 59 })
31 - .catch(payload => {
60 + .catch(error => {
61 + // Extract only serializable properties from error. You cannot postMessage raw error obj with prototype methods
32 62 embedder.postMessage({
33 63 key: PluginMessages.InternalTrackingChangeError,
34 - payload,
64 + payload: createSafeErrorPayload(error),
35 65 });
36 66 });
37 67 },
38 68 ],
@@ -45,12 +75,12 @@
45 75 key: PluginMessages.InternalTrackingFetchResponse,
46 76 payload,
47 77 });
48 78 })
49 - .catch(payload => {
79 + .catch(error => {
50 80 embedder.postMessage({
51 81 key: PluginMessages.InternalTrackingFetchError,
52 - payload,
82 + payload: createSafeErrorPayload(error, 'Fetch error occurred'),
53 83 });
54 84 });
55 85 },
56 86 ],
@@ -63,12 +93,12 @@
63 93 key: PluginMessages.BusinessUnitFetchResponse,
64 94 payload,
65 95 });
66 96 })
67 - .catch(payload => {
97 + .catch(error => {
68 98 embedder.postMessage({
69 99 key: PluginMessages.BusinessUnitFetchError,
70 - payload,
100 + payload: createSafeErrorPayload(error, 'Business unit fetch error'),
71 101 });
72 102 });
73 103 },
74 104 ],
@@ -81,12 +111,15 @@
81 111 key: PluginMessages.BusinessUnitFetchResponse,
82 112 payload,
83 113 });
84 114 })
85 - .catch(payload => {
115 + .catch(error => {
86 116 embedder.postMessage({
87 117 key: PluginMessages.BusinessUnitChangeError,
88 - payload,
118 + payload: createSafeErrorPayload(
119 + error,
120 + 'Business unit change error'
121 + ),
89 122 });
90 123 });
91 124 },
92 125 ],
@@ -99,12 +132,12 @@
99 132 key: PluginMessages.SkipReviewResponse,
100 133 payload,
101 134 });
102 135 })
103 - .catch(payload => {
136 + .catch(error => {
104 137 embedder.postMessage({
105 138 key: PluginMessages.SkipReviewError,
106 - payload,
139 + payload: createSafeErrorPayload(error, 'Skip review error'),
107 140 });
108 141 });
109 142 },
110 143 ],
@@ -111,8 +144,113 @@
111 144 [
112 145 PluginMessages.RemoveParentQueryParam,
113 146 (message: Message) => {
114 147 removeQueryParamFromLocation(message.payload);
148 + },
149 + ],
150 + [
151 + PluginMessages.ContentEmbedInstallRequest,
152 + (message: Message, embedder: any) => {
153 + startInstall(message.payload.nonce)
154 + .then(payload => {
155 + embedder.postMessage({
156 + key: PluginMessages.ContentEmbedInstallResponse,
157 + payload: payload,
158 + });
159 + })
160 + .catch(error => {
161 + embedder.postMessage({
162 + key: PluginMessages.ContentEmbedInstallError,
163 + payload: createSafeErrorPayload(
164 + error,
165 + 'Content embed install error'
166 + ),
167 + });
168 + });
169 + },
170 + ],
171 + [
172 + PluginMessages.ContentEmbedActivationRequest,
173 + (message: Message, embedder: any) => {
174 + startActivation(message.payload.activateAjaxUrl)
175 + .then(payload => {
176 + embedder.postMessage({
177 + key: PluginMessages.ContentEmbedActivationResponse,
178 + payload: payload,
179 + });
180 + })
181 + .catch(error => {
182 + embedder.postMessage({
183 + key: PluginMessages.ContentEmbedActivationError,
184 + payload: createSafeErrorPayload(
185 + error,
186 + 'Content embed activation error'
187 + ),
188 + });
189 + });
190 + },
191 + ],
192 + [
193 + PluginMessages.RefreshProxyMappingsRequest,
194 + (__message: Message, embedder: any) => {
195 + refreshProxyMappingsCache()
196 + .then(() => {
197 + embedder.postMessage({
198 + key: PluginMessages.RefreshProxyMappingsResponse,
199 + payload: {},
200 + });
201 + })
202 + .catch(error => {
203 + embedder.postMessage({
204 + key: PluginMessages.RefreshProxyMappingsError,
205 + payload: createSafeErrorPayload(
206 + error,
207 + 'Refresh proxy mappings error'
208 + ),
209 + });
210 + });
211 + },
212 + ],
213 + [
214 + PluginMessages.ProxyMappingsEnabledRequest,
215 + (__message: Message, embedder: any) => {
216 + fetchProxyMappingsEnabled()
217 + .then(payload => {
218 + embedder.postMessage({
219 + key: PluginMessages.ProxyMappingsEnabledResponse,
220 + payload,
221 + });
222 + })
223 + .catch(error => {
224 + embedder.postMessage({
225 + key: PluginMessages.ProxyMappingsEnabledError,
226 + payload: createSafeErrorPayload(
227 + error,
228 + 'Proxy mappings enabled fetch error'
229 + ),
230 + });
231 + });
232 + },
233 + ],
234 + [
235 + PluginMessages.ProxyMappingsEnabledChangeRequest,
236 + ({ payload }: Message, embedder: any) => {
237 + toggleProxyMappingsEnabled(payload)
238 + .then(() => {
239 + embedder.postMessage({
240 + key: PluginMessages.ProxyMappingsEnabledResponse,
241 + payload,
242 + });
243 + })
244 + .catch(error => {
245 + embedder.postMessage({
246 + key: PluginMessages.ProxyMappingsEnabledChangeError,
247 + payload: createSafeErrorPayload(
248 + error,
249 + 'Proxy mappings enabled change error'
250 + ),
251 + });
252 + });
115 253 },
116 254 ],
117 255 ]);
118 256