Skip to content
Snippets Groups Projects
index.js 888 B
Newer Older
  • Learn to ignore specific revisions
  • // eslint-disable-next-line import/extensions
    import * as bundle from './app/bundle.api.js';
    
    import * as injected from './injected';
    
    import { validateNodeVersion } from './validateNodeVersion';
    
    James Long's avatar
    James Long committed
    let actualApp;
    
    export const internal = bundle.lib;
    
    James Long's avatar
    James Long committed
    
    
    // DEPRECATED: remove the next line in @actual-app/api v7
    
    export * as methods from './methods';
    
    
    export * from './methods';
    
    export * as utils from './utils';
    
    export async function init(config = {}) {
    
    James Long's avatar
    James Long committed
      if (actualApp) {
        return;
      }
    
    
      global.fetch = (...args) =>
        import('node-fetch').then(({ default: fetch }) => fetch(...args));
    
    James Long's avatar
    James Long committed
    
    
      await bundle.init(config);
    
    James Long's avatar
    James Long committed
      actualApp = bundle.lib;
    
    
      injected.override(bundle.lib.send);
    
    James Long's avatar
    James Long committed
      return bundle.lib;
    }
    
    
    export async function shutdown() {
    
    James Long's avatar
    James Long committed
      if (actualApp) {
    
        await actualApp.send('sync');
    
    James Long's avatar
    James Long committed
        await actualApp.send('close-budget');
        actualApp = null;
      }
    }