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