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
leadin / scripts / utils / backgroundAppUtils.ts

backgroundAppUtils.ts in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.3.75, at scripts/utils/backgroundAppUtils.ts

59 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {
2 deviceId,
3 hubspotBaseUrl,
4 locale,
5 portalId,
6 leadinPluginVersion,
7 } from '../constants/leadinConfig';
8 import { initApp } from './appUtils';
9 import { fetchAccessToken } from '../api/wordpressApiClient';
10 import { isEmbedderReady } from './embedderReady';
11
12 type CallbackFn = (...args: any[]) => void;
13
14 export function initBackgroundApp(initFn: CallbackFn | CallbackFn[]) {
15 function main() {
16 if (Array.isArray(initFn)) {
17 initFn.forEach(callback => callback());
18 } else {
19 initFn();
20 }
21 }
22 initApp(main);
23 }
24
25 const getLeadinConfig = () => {
26 return {
27 leadinPluginVersion,
28 };
29 };
30
31 export const getOrCreateBackgroundApp = (accessToken = '', expiresIn = 0) => {
32 if ((window as any).LeadinBackgroundApp) {
33 return (window as any).LeadinBackgroundApp;
34 }
35 if (!isEmbedderReady()) {
36 return null;
37 }
38 const { IntegratedAppEmbedder, IntegratedAppOptions }: any = window;
39 const options = new IntegratedAppOptions()
40 .setLocale(locale)
41 .setDeviceId(deviceId)
42 .setLeadinConfig(getLeadinConfig())
43 .setAccessToken(accessToken, expiresIn);
44
45 const embedder = new IntegratedAppEmbedder(
46 'integrated-plugin-proxy',
47 portalId,
48 hubspotBaseUrl,
49 () => {}
50 ).setOptions(options);
51
52 embedder.attachTo(document.body, false);
53 embedder.setTokenRenewalCallback(fetchAccessToken);
54 embedder.postStartAppMessage(); // lets the app know all data has been passed to it
55
56 (window as any).LeadinBackgroundApp = embedder;
57 return (window as any).LeadinBackgroundApp;
58 };
59