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