1
0
Fork 0
mirror of synced 2024-07-12 17:56:07 +12:00
budibase/packages/server/utilities/budibaseApi.js

65 lines
1.6 KiB
JavaScript
Raw Normal View History

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