Heray-Was-Here
Server : Apache/2.4.52 (Debian)
System : Linux 1b21ca041b67 5.10.0-44-amd64 #1 SMP Debian 5.10.257-1 (2026-05-27) x86_64
User : www-data ( 33)
PHP Version : 7.4.28
Disable Function : NONE
Directory :  /var/www/html/wp-content/plugins/leadin/scripts/utils/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/html/wp-content/plugins/leadin/scripts/utils/backgroundAppUtils.ts
import {
  deviceId,
  hubspotBaseUrl,
  locale,
  portalId,
  leadinPluginVersion,
} from '../constants/leadinConfig';
import { initApp } from './appUtils';

type CallbackFn = (...args: any[]) => void;

export function initBackgroundApp(initFn: CallbackFn | CallbackFn[]) {
  function main() {
    if (Array.isArray(initFn)) {
      initFn.forEach(callback => callback());
    } else {
      initFn();
    }
  }
  initApp(main);
}

const getLeadinConfig = () => {
  return {
    leadinPluginVersion,
  };
};

export const getOrCreateBackgroundApp = (refreshToken = '') => {
  if ((window as any).LeadinBackgroundApp) {
    return (window as any).LeadinBackgroundApp;
  }
  const { IntegratedAppEmbedder, IntegratedAppOptions }: any = window;
  const options = new IntegratedAppOptions()
    .setLocale(locale)
    .setDeviceId(deviceId)
    .setLeadinConfig(getLeadinConfig())
    .setRefreshToken(refreshToken.trim());

  const embedder = new IntegratedAppEmbedder(
    'integrated-plugin-proxy',
    portalId,
    hubspotBaseUrl,
    () => {}
  ).setOptions(options);

  embedder.attachTo(document.body, false);
  embedder.postStartAppMessage(); // lets the app know all all data has been passed to it

  (window as any).LeadinBackgroundApp = embedder;
  return (window as any).LeadinBackgroundApp;
};

Hry