forked from tsai/budibase
7 changed files with 222 additions and 52 deletions
@ -0,0 +1,35 @@ |
|||||
|
const {common, getAppApis} = require("budibase-core"); |
||||
|
const {getDatabaseManager} = require("./helpers"); |
||||
|
|
||||
|
module.exports = async (productSetId, productId, versionId) => { |
||||
|
const databaseManager = getDatabaseManager(datastoreModule); |
||||
|
const masterDatastore = datastoreModule.getDatastore( |
||||
|
databaseManager.masterDatastoreConfig |
||||
|
); |
||||
|
|
||||
|
const master = await getAppApis(masterDatastore); |
||||
|
|
||||
|
const productSet = await master.recordApi.load( |
||||
|
common.joinKey("ProductSets", productSetId) |
||||
|
); |
||||
|
|
||||
|
const prodcutSetDatastore = datastoreModule.getDatastore( |
||||
|
productSet.datastoreConfig |
||||
|
); |
||||
|
|
||||
|
const productSetApis = await getAppApis(prodcutSetDatastore); |
||||
|
const product = await productSetApis.recordApi.load( |
||||
|
common.joinKey("Products", productId) |
||||
|
); |
||||
|
|
||||
|
const version = await productSetApis.recordApi.load( |
||||
|
common.joinKey("Products", productId, "Versions", versionId) |
||||
|
); |
||||
|
|
||||
|
const instance = await productSetApis.recordApi.getNew( |
||||
|
common.joinKey(product.key, "Versions", ) |
||||
|
); |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -1,8 +1,78 @@ |
|||||
|
const {initialiseData, getTemplateApi, |
||||
|
getAppApis} = require("budibase-core"); |
||||
|
const {newField, getDatabaseManager} = require("./helpers"); |
||||
|
|
||||
|
module.exports = async (datastoreModule, productSetName, |
||||
|
username, password) => { |
||||
|
|
||||
module.exports = async (datastoreFactory, productDbOpts) => { |
const databaseManager = getDatabaseManager(datastoreModule); |
||||
|
const masterDatastore = datastoreModule.getDatastore( |
||||
|
databaseManager.masterDatastoreConfig |
||||
|
); |
||||
|
|
||||
|
const masterApi = await getAppApis(masterDatastore); |
||||
|
const ps = masterApi.recordApi.getNew("/ProductSets", "ProductSet"); |
||||
|
|
||||
|
const psDatastoreConfig = await databaseManager.createEmptyProductSetDb(ps.id); |
||||
|
ps.datastoreConfig = psDatastoreConfig; |
||||
|
ps.name = productSetName; |
||||
|
await bb.recordApi.save(ps); |
||||
|
|
||||
|
const datastore = datastoreFactory(psDatastoreConfig); |
||||
|
const templateApi = getTemplateApi(); |
||||
|
|
||||
|
const root = templateApi.getNewRootLevel(); |
||||
|
const products = templateApi.getNewCollectionTemplate(root, "Products"); |
||||
|
|
||||
|
const product = templateApi.getNewRecordTemplate(products); |
||||
|
product.name = "Product"; |
||||
|
|
||||
|
const newProductField = newField(templateApi, product); |
||||
|
newProductField("name", "string", true); |
||||
|
newProductField("domain", "string", true); |
||||
|
newProductField("certificate", "string", true); |
||||
|
|
||||
|
var productVersionsRefIndex = templateApi.getNewIndexTemplate(products); |
||||
|
|
||||
|
const versions = templateApi.getNewCollectionTemplate(product, "versions", false); |
||||
|
const version = templateApi.getNewRecordTemplate(versions); |
||||
|
const newVersionField = newField(templateApi, version); |
||||
|
newVersionField("date", "datetime", true); |
||||
|
newVersionField("description", "string", false); |
||||
|
newVersionField("appDefinition", "file", false); |
||||
|
newVersionField("publicFiles", "array<file>", false); |
||||
|
const deployable = newVersionField("deployable", "bool", false) |
||||
|
deployable.getInitialValue = "false"; |
||||
|
deployable.typeOptions.allowNulls = false; |
||||
|
|
||||
|
const versionLookup = templateApi.getNewIndexTemplate(product); |
||||
|
versionLookup.name = "versionLookup"; |
||||
|
versionLookup.map = "return ({description:record.description, deployable:record.deployable});"; |
||||
|
versionLookup.allowedRecordNodeIds = [version.recordNodeId]; |
||||
|
|
||||
|
|
||||
|
|
||||
|
const productInstances = templateApi.getNewCollectionTemplate(product); |
||||
|
productInstances.name = "ProductInstances"; |
||||
|
const productInstance = templateApi.getNewRecordTemplate(productInstances); |
||||
|
productInstance.name = "ProductInstance"; |
||||
|
const newProductInstanceField = newField(templateApi, productInstance); |
||||
|
newProductInstanceField("description", "string", true); |
||||
|
const versionReference = newProductInstanceField("version", "reference"); |
||||
|
versionReference.typeOptions.indexNodeKey = versions.indexes[0].nodeKey(); |
||||
|
|
||||
|
await initialiseData(datastore, { |
||||
|
heirarchy:root, actions:[], triggers:[] |
||||
|
}); |
||||
|
|
||||
|
const bb = await getApisWithFullAccess(datastore); |
||||
|
const fullAccess = bb.authApi.getNewAccessLevel(); |
||||
|
fullAccess.permissions = bb.authApi.generateFullPermissions(); |
||||
|
fullAccess.name = "Full Access"; |
||||
|
await bb.authApi.saveAccessLevels([fullAccess]); |
||||
|
const seedUser = bb.authApi.getNewUser(); |
||||
|
seedUser.name = username; |
||||
|
seedUser.accessLevels = ["Full Access"]; |
||||
|
await bb.authApi.createUser(seedUser, password); |
||||
|
|
||||
}; |
}; |
||||
@ -0,0 +1,29 @@ |
|||||
|
const crypto = require("../server/nodeCrypto"); |
||||
|
const { |
||||
|
getDatabaseFactory} = require("budibase-core"); |
||||
|
|
||||
|
module.exports.newField = (templateApi, recordNode) => (name, type, mandatory=false) => { |
||||
|
const field = templateApi.getNewField(type); |
||||
|
field.name = name; |
||||
|
templateApi.addField(recordNode, field); |
||||
|
if(mandatory) { |
||||
|
templateApi.addRecordValidationRule(recordNode) |
||||
|
(templateApi.commonValidationRules.fieldNotEmpty) |
||||
|
} |
||||
|
return field; |
||||
|
}; |
||||
|
|
||||
|
module.exports.getApisWithFullAccess = async (datastore) => { |
||||
|
const bb = await getAppApis( |
||||
|
datastore, |
||||
|
null, null, null, |
||||
|
crypto |
||||
|
); |
||||
|
|
||||
|
bb.asFullAccess(); |
||||
|
|
||||
|
return bb; |
||||
|
}; |
||||
|
|
||||
|
module.exports.getDatabaseManager = (datastoreModule) => |
||||
|
getDatabaseFactory(datastoreModule.databaseManager); |
||||
@ -0,0 +1,41 @@ |
|||||
|
const {getAppApis} = require("budibase-core"); |
||||
|
|
||||
|
module.exports = (datastoreConfig, datastoreModule, method, path) => { |
||||
|
|
||||
|
const datastore = datastoreModule.getDatastore( |
||||
|
datastoreConfig); |
||||
|
|
||||
|
const bb = getAppApis( |
||||
|
datastore |
||||
|
) |
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
/* api Routes (all /api/..) |
||||
|
|
||||
|
POST executeAction/<name> {} |
||||
|
POST authenticate {} |
||||
|
POST authenticateTemporaryAccess {} |
||||
|
POST createUser {} |
||||
|
POST enabledUser {} |
||||
|
POST disableUser {} |
||||
|
GET users |
||||
|
GET accessLevels |
||||
|
POST accessLevels {} |
||||
|
POST changeMyPassword {} |
||||
|
POST setPasswordFromTemporaryCode {} |
||||
|
POST listItems/index/key {} |
||||
|
POST aggregates/index/key {} |
||||
|
POST record/key/to/rec {} |
||||
|
GET record/key/to/rec |
||||
|
DELETE record/key/to/rec |
||||
|
POST appHeirarchy {} |
||||
|
POST actionsAndTriggers {} |
||||
|
GET appDefinition |
||||
|
|
||||
|
*/ |
||||
Loading…
Reference in new issue