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/useAppEmbedder.ts +49 -14 11.1.1511.3.75 View file →
@@ -13,9 +13,8 @@
13 13 portalDomain,
14 14 portalEmail,
15 15 portalId,
16 16 reviewSkippedDate,
17 - refreshToken,
18 17 impactLink,
19 18 theme,
20 19 lastAuthorizeTime,
21 20 lastDeauthorizeTime,
@@ -24,11 +23,12 @@
24 23 phpVersion,
25 24 wpVersion,
26 25 contentEmbed,
27 26 requiresContentEmbedScope,
28 - refreshTokenError,
27 + decryptError,
29 28 LeadinConfig,
30 29 } from '../constants/leadinConfig';
30 +import { fetchAccessToken } from '../api/wordpressApiClient';
31 31 import { App, AppIframe } from './constants';
32 32 import { messageMiddleware } from './messageMiddleware';
33 33 import { resizeWindow, useIframeNotRendered } from '../utils/iframe';
34 34
@@ -54,11 +54,19 @@
54 54 | 'phpVersion'
55 55 | 'wpVersion'
56 56 | 'contentEmbed'
57 57 | 'requiresContentEmbedScope'
58 - | 'refreshTokenError'
58 + | 'decryptError'
59 59 >;
60 60
61 +type AppIntegrationConfig = Pick<LeadinConfig, 'adminUrl'>;
62 +
63 +const getIntegrationConfig = (): AppIntegrationConfig => {
64 + return {
65 + adminUrl: leadinQueryParams.adminUrl,
66 + };
67 +};
68 +
61 69 /**
62 70 * A modified version of the original leadinConfig that is passed to some integrated apps.
63 71 *
64 72 * Important:
@@ -119,9 +127,9 @@
119 127 websiteName: leadinQueryParams.websiteName,
120 128 wpVersion,
121 129 contentEmbed,
122 130 requiresContentEmbedScope,
123 - refreshTokenError,
131 + decryptError,
124 132 ...utm_query_params,
125 133 };
126 134 };
127 135
@@ -134,17 +142,17 @@
134 142 }: any = window;
135 143 let options;
136 144 switch (app) {
137 145 case App.Plugin:
138 - options = new PluginAppOptions().setLeadinConfig(getLeadinConfig());
146 + options = new PluginAppOptions();
139 147 break;
140 148 case App.PluginSettings:
141 - options = new PluginAppOptions()
142 - .setLeadinConfig(getLeadinConfig())
143 - .setPluginSettingsInit();
149 + options = new PluginAppOptions().setPluginSettingsInit();
144 150 break;
145 151 case App.Forms:
146 - options = new FormsAppOptions();
152 + options = new FormsAppOptions().setIntegratedAppConfig(
153 + getIntegrationConfig()
154 + );
147 155 if (createRoute) {
148 156 options = options.setCreateFormAppInit();
149 157 }
150 158 break;
@@ -175,13 +183,18 @@
175 183
176 184 useEffect(() => {
177 185 const { IntegratedAppEmbedder }: any = window;
178 186
179 - if (IntegratedAppEmbedder) {
187 + if (!IntegratedAppEmbedder) {
188 + return;
189 + }
190 +
191 + const createEmbedder = (accessToken = '', expiresIn = 0) => {
180 192 const options = getAppOptions(app, createRoute)
181 193 .setLocale(locale)
182 194 .setDeviceId(deviceId)
183 - .setRefreshToken(refreshToken);
195 + .setAccessToken(accessToken, expiresIn)
196 + .setLeadinConfig(getLeadinConfig());
184 197
185 198 const embedder = new IntegratedAppEmbedder(
186 199 AppIframe[app],
187 200 portalId,
@@ -186,16 +199,38 @@
186 199 AppIframe[app],
187 200 portalId,
188 201 hubspotBaseUrl,
189 202 resizeWindow,
190 - refreshToken ? '' : impactLink
203 + accessToken ? '' : impactLink
191 204 ).setOptions(options);
192 205
193 - embedder.subscribe(messageMiddleware(embedder));
206 + embedder.subscribe((message: any) => {
207 + messageMiddleware(embedder)(message);
208 + });
209 + embedder.setTokenRenewalCallback(fetchAccessToken);
210 +
194 211 embedder.attachTo(container, true);
195 212 embedder.postStartAppMessage(); // lets the app know all all data has been passed to it
196 213
197 214 (window as any).embedder = embedder;
215 + };
216 +
217 + if (connectionStatus === 'Connected') {
218 + fetchAccessToken()
219 + .then(
220 + ({
221 + accessToken,
222 + expiresIn,
223 + }: {
224 + accessToken: string;
225 + expiresIn: number;
226 + }) => {
227 + createEmbedder(accessToken, expiresIn);
228 + }
229 + )
230 + .catch(() => {});
231 + } else {
232 + createEmbedder();
198 233 }
199 234 }, []);
200 235
201 236 if (iframeNotRendered) {
@@ -213,9 +248,9 @@
213 248 app,
214 249 hubspotBaseUrl,
215 250 impactLink,
216 251 appName: AppIframe[app],
217 - hasRefreshToken: !!refreshToken,
252 + isConnected: connectionStatus === 'Connected',
218 253 },
219 254 });
220 255 }
221 256