actual/packages/api/index.js

36 lines
629 B
JavaScript
Raw Permalink Normal View History

2022-04-29 02:44:38 +00:00
let bundle = require('./app/bundle.api.js');
let methods = require('./methods');
let utils = require('./utils');
let injected = require('./injected');
let actualApp;
async function init({ budgetId, config } = {}) {
if (actualApp) {
return;
}
global.fetch = require('node-fetch');
await bundle.init({ budgetId, config });
actualApp = bundle.lib;
injected.send = bundle.lib.send;
return bundle.lib;
}
async function shutdown() {
if (actualApp) {
await actualApp.send('close-budget');
actualApp = null;
}
}
module.exports = {
init,
shutdown,
utils,
internal: bundle.lib,
...methods
};