1
0
Fork 0
mirror of synced 2024-08-04 12:51:47 +12:00
budibase/packages/server/utilities/budibaseApi.js
2019-06-25 22:48:22 +01:00

65 lines
1.6 KiB
JavaScript

const crypto = require("../nodeCrypto");
const {getAppApis, getTemplateApi} = require("budibase-core");
const constructHierarchy = (datastore, appDefinition) => {
appDefinition.hierarchy = getTemplateApi({datastore})
.constructHierarchy(appDefinition.hierarchy);
return appDefinition;
}
module.exports.getApisWithFullAccess = async (datastore, appPackage) => {
const appDefinition = constructHierarchy(
datastore,
appPackage.appDefinition);
const bb = await getAppApis(
datastore,
appPackage.behaviourSources,
null, //cleanupTransations
null, // getEpochTime
crypto,
appDefinition
);
bb.withFullAccess();
return bb;
};
module.exports.getApisForUser = async (datastore, appPackage, username, password) => {
const bb = await getAppApis(
datastore,
appPackage.behaviourSources,
null, //cleanupTransations
null, // getEpochTime
crypto,
constructHierarchy(
datastore,
appPackage.appDefinition)
);
await bb.authenticateAs(username, password);
return bb;
}
module.exports.getApisForSession = async (datastore, appPackage, session) => {
const user = JSON.parse(session.user_json);
const bb = await getAppApis(
datastore,
appPackage.behaviourSources,
null, //cleanupTransations
null, // getEpochTime
crypto,
constructHierarchy(
datastore,
appPackage.appDefinition)
);
bb.asUser(user);
return bb;
}