budibase/packages/server/utilities/budibaseApi.js

65 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-06-07 15:18:10 +02:00
const crypto = require("../nodeCrypto");
2019-06-25 23:48:22 +02:00
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);
2019-06-07 15:18:10 +02:00
const bb = await getAppApis(
datastore,
2019-06-25 23:48:22 +02:00
appPackage.behaviourSources,
null, //cleanupTransations
null, // getEpochTime
crypto,
appDefinition
2019-06-07 15:18:10 +02:00
);
bb.withFullAccess();
return bb;
};
2019-06-25 23:48:22 +02:00
module.exports.getApisForUser = async (datastore, appPackage, username, password) => {
2019-06-07 15:18:10 +02:00
const bb = await getAppApis(
datastore,
2019-06-25 23:48:22 +02:00
appPackage.behaviourSources,
null, //cleanupTransations
null, // getEpochTime
crypto,
constructHierarchy(
datastore,
appPackage.appDefinition)
2019-06-07 15:18:10 +02:00
);
await bb.authenticateAs(username, password);
return bb;
}
2019-06-25 23:48:22 +02:00
module.exports.getApisForSession = async (datastore, appPackage, session) => {
2019-06-14 11:05:46 +02:00
const user = JSON.parse(session.user_json);
const bb = await getAppApis(
datastore,
2019-06-25 23:48:22 +02:00
appPackage.behaviourSources,
null, //cleanupTransations
null, // getEpochTime
crypto,
constructHierarchy(
datastore,
appPackage.appDefinition)
2019-06-14 11:05:46 +02:00
);
bb.asUser(user);
return bb;
}