@budibase/server 1.0.199 → 1.0.200-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile +2 -0
- package/builder/assets/index.359da19e.js +1315 -0
- package/builder/index.html +1 -1
- package/coverage/clover.xml +2089 -2001
- package/coverage/coverage-final.json +121 -122
- package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
- package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
- package/coverage/lcov-report/api/controllers/automation.js.html +174 -72
- package/coverage/lcov-report/api/controllers/backup.js.html +30 -6
- package/coverage/lcov-report/api/controllers/cloud.js.html +11 -11
- package/coverage/lcov-report/api/controllers/component.js.html +5 -5
- package/coverage/lcov-report/api/controllers/datasource.js.html +53 -41
- package/coverage/lcov-report/api/controllers/dev.js.html +94 -70
- package/coverage/lcov-report/api/controllers/index.html +57 -72
- package/coverage/lcov-report/api/controllers/integration.js.html +8 -8
- package/coverage/lcov-report/api/controllers/layout.js.html +28 -19
- package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
- package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
- package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +10 -10
- package/coverage/lcov-report/api/controllers/role.js.html +78 -48
- package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/external.js.html +19 -19
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +54 -54
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -24
- package/coverage/lcov-report/api/controllers/row/utils.js.html +24 -24
- package/coverage/lcov-report/api/controllers/screen.js.html +56 -20
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +49 -49
- package/coverage/lcov-report/api/controllers/table/external.js.html +23 -17
- package/coverage/lcov-report/api/controllers/table/index.html +26 -26
- package/coverage/lcov-report/api/controllers/table/index.js.html +85 -49
- package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
- package/coverage/lcov-report/api/controllers/user.js.html +19 -19
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +11 -11
- package/coverage/lcov-report/api/controllers/view/index.html +21 -21
- package/coverage/lcov-report/api/controllers/view/index.js.html +275 -65
- package/coverage/lcov-report/api/controllers/view/utils.js.html +23 -23
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +40 -40
- package/coverage/lcov-report/api/controllers/webhook.js.html +17 -17
- package/coverage/lcov-report/api/index.html +15 -15
- package/coverage/lcov-report/api/index.js.html +39 -45
- package/coverage/lcov-report/api/routes/analytics.js.html +7 -13
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
- package/coverage/lcov-report/api/routes/auth.js.html +6 -6
- package/coverage/lcov-report/api/routes/automation.js.html +11 -11
- package/coverage/lcov-report/api/routes/backup.js.html +8 -8
- package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
- package/coverage/lcov-report/api/routes/component.js.html +8 -8
- package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
- package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
- package/coverage/lcov-report/api/routes/dev.js.html +13 -13
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +8 -8
- package/coverage/lcov-report/api/routes/layout.js.html +8 -8
- package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
- package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
- package/coverage/lcov-report/api/routes/permission.js.html +9 -9
- package/coverage/lcov-report/api/routes/query.js.html +10 -10
- package/coverage/lcov-report/api/routes/role.js.html +9 -9
- package/coverage/lcov-report/api/routes/routing.js.html +8 -8
- package/coverage/lcov-report/api/routes/screen.js.html +9 -9
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +10 -10
- package/coverage/lcov-report/api/routes/templates.js.html +8 -8
- package/coverage/lcov-report/api/routes/user.js.html +8 -8
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +36 -36
- package/coverage/lcov-report/api/routes/view.js.html +10 -10
- package/coverage/lcov-report/api/routes/webhook.js.html +9 -9
- package/coverage/lcov-report/automations/actions.js.html +25 -25
- package/coverage/lcov-report/automations/automationUtils.js.html +8 -8
- package/coverage/lcov-report/automations/bullboard.js.html +35 -35
- package/coverage/lcov-report/automations/index.html +29 -29
- package/coverage/lcov-report/automations/index.js.html +29 -17
- package/coverage/lcov-report/automations/steps/bash.js.html +7 -7
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
- package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
- package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
- package/coverage/lcov-report/automations/steps/loop.js.html +2 -2
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
- package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
- package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
- package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
- package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
- package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
- package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
- package/coverage/lcov-report/automations/triggers.js.html +18 -18
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +30 -30
- package/coverage/lcov-report/constants/layouts.js.html +5 -5
- package/coverage/lcov-report/constants/screens.js.html +4 -4
- package/coverage/lcov-report/db/inMemoryView.js.html +5 -5
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +9 -9
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +17 -17
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +36 -36
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +19 -19
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +81 -81
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +7 -7
- package/coverage/lcov-report/events/utils.js.html +10 -10
- package/coverage/lcov-report/index.html +74 -74
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
- package/coverage/lcov-report/middleware/builder.js.html +20 -20
- package/coverage/lcov-report/middleware/currentapp.js.html +49 -49
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +14 -14
- package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
- package/coverage/lcov-report/middleware/resourceId.js.html +29 -29
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +4 -4
- package/coverage/lcov-report/threads/automation.js.html +1 -1
- package/coverage/lcov-report/threads/index.html +1 -1
- package/coverage/lcov-report/threads/query.js.html +1 -1
- package/coverage/lcov-report/threads/utils.js.html +13 -13
- package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
- package/coverage/lcov-report/utilities/centralPath.js.html +14 -14
- package/coverage/lcov-report/utilities/csvParser.js.html +34 -34
- package/coverage/lcov-report/utilities/global.js.html +28 -28
- package/coverage/lcov-report/utilities/index.html +25 -25
- package/coverage/lcov-report/utilities/index.js.html +41 -41
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +18 -18
- package/coverage/lcov-report/utilities/queue/index.html +15 -15
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +59 -59
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +15 -15
- package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
- package/coverage/lcov-report/utilities/security.js.html +8 -8
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +30 -30
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +7 -7
- package/coverage/lcov-report/utilities/workerRequests.js.html +29 -29
- package/coverage/lcov.info +2903 -2762
- package/dist/api/controllers/analytics.js +7 -30
- package/dist/api/controllers/application.js +56 -16
- package/dist/api/controllers/automation.js +31 -2
- package/dist/api/controllers/backup.js +7 -0
- package/dist/api/controllers/datasource.js +8 -2
- package/dist/api/controllers/deploy/index.js +6 -2
- package/dist/api/controllers/dev.js +9 -2
- package/dist/api/controllers/layout.js +3 -0
- package/dist/api/controllers/query/import/index.js +12 -2
- package/dist/api/controllers/query/import/sources/curl.js +3 -0
- package/dist/api/controllers/query/import/sources/openapi2.js +3 -0
- package/dist/api/controllers/query/import/sources/openapi3.js +3 -0
- package/dist/api/controllers/query/index.js +16 -2
- package/dist/api/controllers/role.js +11 -0
- package/dist/api/controllers/screen.js +10 -1
- package/dist/api/controllers/static/index.js +29 -15
- package/dist/api/controllers/table/external.js +2 -0
- package/dist/api/controllers/table/index.js +12 -0
- package/dist/api/controllers/table/utils.js +3 -3
- package/dist/api/controllers/view/index.js +62 -6
- package/dist/api/index.js +2 -4
- package/dist/api/routes/analytics.js +1 -3
- package/dist/app.js +16 -8
- package/dist/automations/index.js +4 -0
- package/dist/environment.js +4 -2
- package/dist/migrations/functions/backfill/app/automations.js +31 -0
- package/dist/migrations/functions/backfill/app/datasources.js +28 -0
- package/dist/migrations/functions/backfill/app/layouts.js +33 -0
- package/dist/migrations/functions/backfill/app/queries.js +32 -0
- package/dist/migrations/functions/backfill/app/roles.js +28 -0
- package/dist/migrations/functions/backfill/app/screens.js +28 -0
- package/dist/migrations/functions/backfill/app/tables.js +40 -0
- package/dist/migrations/functions/backfill/app.js +175 -0
- package/dist/migrations/functions/backfill/global/configs.js +61 -0
- package/dist/migrations/functions/backfill/global/quotas.js +60 -0
- package/dist/migrations/functions/backfill/global/users.js +50 -0
- package/dist/migrations/functions/backfill/global.js +189 -0
- package/dist/migrations/functions/backfill/index.js +32 -0
- package/dist/migrations/functions/backfill/installation.js +81 -0
- package/dist/migrations/index.js +95 -31
- package/dist/migrations/tests/helpers.js +72 -0
- package/dist/migrations/tests/structures.js +37 -0
- package/dist/package.json +79 -69
- package/dist/tests/utilities/TestConfiguration.js +121 -93
- package/dist/tests/utilities/structures.js +45 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/nodemon.json +1 -1
- package/package.json +80 -70
- package/scripts/dev/manage.js +2 -0
- package/scripts/jestSetup.js +7 -0
- package/scripts/likeCypress.ts +1 -1
- package/src/api/controllers/analytics.ts +8 -0
- package/src/api/controllers/application.ts +60 -18
- package/src/api/controllers/automation.js +36 -2
- package/src/api/controllers/backup.js +8 -0
- package/src/api/controllers/datasource.js +8 -4
- package/src/api/controllers/deploy/index.ts +6 -2
- package/src/api/controllers/dev.js +10 -2
- package/src/api/controllers/layout.js +3 -0
- package/src/api/controllers/query/import/index.ts +16 -3
- package/src/api/controllers/query/import/sources/base/index.ts +2 -1
- package/src/api/controllers/query/import/sources/curl.ts +4 -0
- package/src/api/controllers/query/import/sources/openapi2.ts +4 -0
- package/src/api/controllers/query/import/sources/openapi3.ts +4 -0
- package/src/api/controllers/query/import/tests/index.spec.js +20 -7
- package/src/api/controllers/query/index.ts +16 -3
- package/src/api/controllers/role.js +10 -0
- package/src/api/controllers/screen.js +13 -1
- package/src/api/controllers/static/index.js +28 -15
- package/src/api/controllers/table/external.js +2 -0
- package/src/api/controllers/table/index.js +12 -0
- package/src/api/controllers/table/utils.ts +4 -4
- package/src/api/controllers/view/index.js +76 -6
- package/src/api/index.js +2 -4
- package/src/api/routes/analytics.js +1 -3
- package/src/api/routes/public/utils/Endpoint.ts +1 -1
- package/src/api/routes/tests/__snapshots__/datasource.spec.js.snap +5 -1
- package/src/api/routes/tests/application.spec.js +64 -4
- package/src/api/routes/tests/automation.spec.js +168 -60
- package/src/api/routes/tests/backup.spec.js +2 -0
- package/src/api/routes/tests/data/export.txt +1 -0
- package/src/api/routes/tests/datasource.spec.js +5 -0
- package/src/api/routes/tests/deployment.spec.js +25 -0
- package/src/api/routes/tests/dev.spec.js +40 -0
- package/src/api/routes/tests/layout.spec.js +4 -0
- package/src/api/routes/tests/query.spec.js +56 -13
- package/src/api/routes/tests/role.spec.js +40 -7
- package/src/api/routes/tests/row.spec.js +2 -3
- package/src/api/routes/tests/screen.spec.js +30 -4
- package/src/api/routes/tests/static.spec.js +120 -54
- package/src/api/routes/tests/table.spec.js +102 -38
- package/src/api/routes/tests/view.spec.js +222 -43
- package/src/app.ts +18 -9
- package/src/automations/index.js +4 -0
- package/src/automations/tests/delay.spec.js +4 -0
- package/src/environment.js +5 -2
- package/src/migrations/functions/backfill/app/automations.ts +26 -0
- package/src/migrations/functions/backfill/app/datasources.ts +22 -0
- package/src/migrations/functions/backfill/app/layouts.ts +29 -0
- package/src/migrations/functions/backfill/app/queries.ts +33 -0
- package/src/migrations/functions/backfill/app/roles.ts +22 -0
- package/src/migrations/functions/backfill/app/screens.ts +22 -0
- package/src/migrations/functions/backfill/app/tables.ts +36 -0
- package/src/migrations/functions/backfill/app.ts +148 -0
- package/src/migrations/functions/backfill/global/configs.ts +66 -0
- package/src/migrations/functions/backfill/global/quotas.ts +60 -0
- package/src/migrations/functions/backfill/global/users.ts +49 -0
- package/src/migrations/functions/backfill/global.ts +194 -0
- package/src/migrations/functions/backfill/index.ts +7 -0
- package/src/migrations/functions/backfill/installation.ts +51 -0
- package/src/migrations/index.ts +120 -51
- package/src/migrations/tests/helpers.ts +40 -0
- package/src/migrations/tests/index.spec.ts +132 -0
- package/src/migrations/tests/structures.ts +66 -0
- package/src/module.d.ts +0 -1
- package/src/tests/utilities/TestConfiguration.js +138 -90
- package/src/tests/utilities/structures.js +71 -0
- package/tsconfig.build.json +20 -5
- package/tsconfig.json +22 -17
- package/builder/assets/index.107ba2e5.js +0 -1315
- package/coverage/lcov-report/api/controllers/analytics.js.html +0 -202
- package/src/api/controllers/analytics.js +0 -39
|
@@ -48,6 +48,9 @@ class TestConfiguration {
|
|
|
48
48
|
getAppId() {
|
|
49
49
|
return this.appId;
|
|
50
50
|
}
|
|
51
|
+
getProdAppId() {
|
|
52
|
+
return this.prodAppId;
|
|
53
|
+
}
|
|
51
54
|
doInContext(appId, task) {
|
|
52
55
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
56
|
if (!appId) {
|
|
@@ -66,6 +69,24 @@ class TestConfiguration {
|
|
|
66
69
|
});
|
|
67
70
|
});
|
|
68
71
|
}
|
|
72
|
+
// SETUP / TEARDOWN
|
|
73
|
+
// use a new id as the name to avoid name collisions
|
|
74
|
+
init(appName = newid()) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
yield this.globalUser();
|
|
77
|
+
return this.createApp(appName);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
end() {
|
|
81
|
+
if (!this) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (this.server) {
|
|
85
|
+
this.server.close();
|
|
86
|
+
}
|
|
87
|
+
cleanup(this.allApps.map(app => app.appId));
|
|
88
|
+
}
|
|
89
|
+
// UTILS
|
|
69
90
|
_req(config, params, controlFunc) {
|
|
70
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
92
|
const request = {};
|
|
@@ -87,24 +108,8 @@ class TestConfiguration {
|
|
|
87
108
|
}));
|
|
88
109
|
});
|
|
89
110
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return doWithGlobalDB(TENANT_ID, (db) => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const id = generateDevInfoID(userId);
|
|
94
|
-
let devInfo;
|
|
95
|
-
try {
|
|
96
|
-
devInfo = yield db.get(id);
|
|
97
|
-
}
|
|
98
|
-
catch (err) {
|
|
99
|
-
devInfo = { _id: id, userId };
|
|
100
|
-
}
|
|
101
|
-
devInfo.apiKey = encrypt(`${TENANT_ID}${SEPARATOR}${newid()}`);
|
|
102
|
-
yield db.put(devInfo);
|
|
103
|
-
return devInfo.apiKey;
|
|
104
|
-
}));
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
globalUser({ id = GLOBAL_USER_ID, builder = true, email = EMAIL, roles, } = {}) {
|
|
111
|
+
// USER / AUTH
|
|
112
|
+
globalUser({ id = GLOBAL_USER_ID, builder = true, admin = false, email = EMAIL, roles, } = {}) {
|
|
108
113
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
114
|
return doWithGlobalDB(TENANT_ID, (db) => __awaiter(this, void 0, void 0, function* () {
|
|
110
115
|
let existing;
|
|
@@ -126,26 +131,75 @@ class TestConfiguration {
|
|
|
126
131
|
else {
|
|
127
132
|
user.builder = { global: false };
|
|
128
133
|
}
|
|
134
|
+
if (admin) {
|
|
135
|
+
user.admin = { global: true };
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
user.admin = { global: false };
|
|
139
|
+
}
|
|
129
140
|
const resp = yield db.put(user);
|
|
130
141
|
return Object.assign({ _rev: resp._rev }, user);
|
|
131
142
|
}));
|
|
132
143
|
});
|
|
133
144
|
}
|
|
134
|
-
|
|
135
|
-
init(appName = newid()) {
|
|
145
|
+
createUser(id = null, email = EMAIL, builder = true, admin = false, roles = {}) {
|
|
136
146
|
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
-
|
|
138
|
-
|
|
147
|
+
const globalId = !id ? `us_${Math.random()}` : `us_${id}`;
|
|
148
|
+
const resp = yield this.globalUser({
|
|
149
|
+
id: globalId,
|
|
150
|
+
email,
|
|
151
|
+
builder,
|
|
152
|
+
admin,
|
|
153
|
+
roles,
|
|
154
|
+
});
|
|
155
|
+
yield userCache.invalidateUser(globalId);
|
|
156
|
+
return Object.assign(Object.assign({}, resp), { globalId });
|
|
139
157
|
});
|
|
140
158
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
159
|
+
login({ roleId, userId, builder, prodApp = false } = {}) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
const appId = prodApp ? this.prodAppId : this.appId;
|
|
162
|
+
return context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
163
|
+
userId = !userId ? `us_uuid1` : userId;
|
|
164
|
+
if (!this.request) {
|
|
165
|
+
throw "Server has not been opened, cannot login.";
|
|
166
|
+
}
|
|
167
|
+
// make sure the user exists in the global DB
|
|
168
|
+
if (roleId !== BUILTIN_ROLE_IDS.PUBLIC) {
|
|
169
|
+
yield this.globalUser({
|
|
170
|
+
id: userId,
|
|
171
|
+
builder,
|
|
172
|
+
roles: { [this.prodAppId]: roleId },
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
yield createASession(userId, {
|
|
176
|
+
sessionId: "sessionid",
|
|
177
|
+
tenantId: TENANT_ID,
|
|
178
|
+
});
|
|
179
|
+
// have to fake this
|
|
180
|
+
const auth = {
|
|
181
|
+
userId,
|
|
182
|
+
sessionId: "sessionid",
|
|
183
|
+
tenantId: TENANT_ID,
|
|
184
|
+
};
|
|
185
|
+
const app = {
|
|
186
|
+
roleId: roleId,
|
|
187
|
+
appId,
|
|
188
|
+
};
|
|
189
|
+
const authToken = jwt.sign(auth, env.JWT_SECRET);
|
|
190
|
+
const appToken = jwt.sign(app, env.JWT_SECRET);
|
|
191
|
+
// returning necessary request headers
|
|
192
|
+
yield userCache.invalidateUser(userId);
|
|
193
|
+
return {
|
|
194
|
+
Accept: "application/json",
|
|
195
|
+
Cookie: [
|
|
196
|
+
`${Cookies.Auth}=${authToken}`,
|
|
197
|
+
`${Cookies.CurrentApp}=${appToken}`,
|
|
198
|
+
],
|
|
199
|
+
[Headers.APP_ID]: appId,
|
|
200
|
+
};
|
|
201
|
+
}));
|
|
202
|
+
});
|
|
149
203
|
}
|
|
150
204
|
defaultHeaders(extras = {}) {
|
|
151
205
|
const auth = {
|
|
@@ -183,6 +237,25 @@ class TestConfiguration {
|
|
|
183
237
|
return this.login({ email, roleId, builder, prodApp });
|
|
184
238
|
});
|
|
185
239
|
}
|
|
240
|
+
// API
|
|
241
|
+
generateApiKey(userId = GLOBAL_USER_ID) {
|
|
242
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
243
|
+
return doWithGlobalDB(TENANT_ID, (db) => __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
const id = generateDevInfoID(userId);
|
|
245
|
+
let devInfo;
|
|
246
|
+
try {
|
|
247
|
+
devInfo = yield db.get(id);
|
|
248
|
+
}
|
|
249
|
+
catch (err) {
|
|
250
|
+
devInfo = { _id: id, userId };
|
|
251
|
+
}
|
|
252
|
+
devInfo.apiKey = encrypt(`${TENANT_ID}${SEPARATOR}${newid()}`);
|
|
253
|
+
yield db.put(devInfo);
|
|
254
|
+
return devInfo.apiKey;
|
|
255
|
+
}));
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
// APP
|
|
186
259
|
createApp(appName) {
|
|
187
260
|
return __awaiter(this, void 0, void 0, function* () {
|
|
188
261
|
// create dev app
|
|
@@ -210,6 +283,7 @@ class TestConfiguration {
|
|
|
210
283
|
}));
|
|
211
284
|
});
|
|
212
285
|
}
|
|
286
|
+
// TABLE
|
|
213
287
|
updateTable(config = null) {
|
|
214
288
|
return __awaiter(this, void 0, void 0, function* () {
|
|
215
289
|
config = config || basicTable();
|
|
@@ -263,6 +337,7 @@ class TestConfiguration {
|
|
|
263
337
|
return this.createTable(table);
|
|
264
338
|
});
|
|
265
339
|
}
|
|
340
|
+
// ROW
|
|
266
341
|
createRow(config = null) {
|
|
267
342
|
return __awaiter(this, void 0, void 0, function* () {
|
|
268
343
|
if (!this.table) {
|
|
@@ -286,6 +361,7 @@ class TestConfiguration {
|
|
|
286
361
|
return this._req(null, { tableId }, controllers.row.fetch);
|
|
287
362
|
});
|
|
288
363
|
}
|
|
364
|
+
// ROLE
|
|
289
365
|
createRole(config = null) {
|
|
290
366
|
return __awaiter(this, void 0, void 0, function* () {
|
|
291
367
|
config = config || basicRole();
|
|
@@ -301,19 +377,20 @@ class TestConfiguration {
|
|
|
301
377
|
}, controllers.perms.addPermission);
|
|
302
378
|
});
|
|
303
379
|
}
|
|
380
|
+
// VIEW
|
|
304
381
|
createView(config) {
|
|
305
382
|
return __awaiter(this, void 0, void 0, function* () {
|
|
306
383
|
if (!this.table) {
|
|
307
384
|
throw "Test requires table to be configured.";
|
|
308
385
|
}
|
|
309
386
|
const view = config || {
|
|
310
|
-
map: "function(doc) { emit(doc[doc.key], doc._id); } ",
|
|
311
387
|
tableId: this.table._id,
|
|
312
388
|
name: "ViewTest",
|
|
313
389
|
};
|
|
314
390
|
return this._req(view, null, controllers.view.save);
|
|
315
391
|
});
|
|
316
392
|
}
|
|
393
|
+
// AUTOMATION
|
|
317
394
|
createAutomation(config) {
|
|
318
395
|
return __awaiter(this, void 0, void 0, function* () {
|
|
319
396
|
config = config || basicAutomation();
|
|
@@ -338,6 +415,16 @@ class TestConfiguration {
|
|
|
338
415
|
return this._req(null, { id: automation._id, rev: automation._rev }, controllers.automation.destroy);
|
|
339
416
|
});
|
|
340
417
|
}
|
|
418
|
+
createWebhook(config = null) {
|
|
419
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
420
|
+
if (!this.automation) {
|
|
421
|
+
throw "Must create an automation before creating webhook.";
|
|
422
|
+
}
|
|
423
|
+
config = config || basicWebhook(this.automation._id);
|
|
424
|
+
return (yield this._req(config, null, controllers.webhook.save)).webhook;
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
// DATASOURCE
|
|
341
428
|
createDatasource(config = null) {
|
|
342
429
|
return __awaiter(this, void 0, void 0, function* () {
|
|
343
430
|
config = config || basicDatasource();
|
|
@@ -378,6 +465,7 @@ class TestConfiguration {
|
|
|
378
465
|
return { datasource, query: basedOnQuery };
|
|
379
466
|
});
|
|
380
467
|
}
|
|
468
|
+
// QUERY
|
|
381
469
|
previewQuery(request, config, datasource, fields) {
|
|
382
470
|
return __awaiter(this, void 0, void 0, function* () {
|
|
383
471
|
return request
|
|
@@ -403,79 +491,19 @@ class TestConfiguration {
|
|
|
403
491
|
return this._req(config, null, controllers.query.save);
|
|
404
492
|
});
|
|
405
493
|
}
|
|
494
|
+
// SCREEN
|
|
406
495
|
createScreen(config = null) {
|
|
407
496
|
return __awaiter(this, void 0, void 0, function* () {
|
|
408
497
|
config = config || basicScreen();
|
|
409
498
|
return this._req(config, null, controllers.screen.save);
|
|
410
499
|
});
|
|
411
500
|
}
|
|
412
|
-
|
|
413
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
414
|
-
if (!this.automation) {
|
|
415
|
-
throw "Must create an automation before creating webhook.";
|
|
416
|
-
}
|
|
417
|
-
config = config || basicWebhook(this.automation._id);
|
|
418
|
-
return (yield this._req(config, null, controllers.webhook.save)).webhook;
|
|
419
|
-
});
|
|
420
|
-
}
|
|
501
|
+
// LAYOUT
|
|
421
502
|
createLayout(config = null) {
|
|
422
503
|
return __awaiter(this, void 0, void 0, function* () {
|
|
423
504
|
config = config || basicLayout();
|
|
424
505
|
return yield this._req(config, null, controllers.layout.save);
|
|
425
506
|
});
|
|
426
507
|
}
|
|
427
|
-
createUser(id = null, email = EMAIL) {
|
|
428
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
429
|
-
const globalId = !id ? `us_${Math.random()}` : `us_${id}`;
|
|
430
|
-
const resp = yield this.globalUser({ id: globalId, email });
|
|
431
|
-
yield userCache.invalidateUser(globalId);
|
|
432
|
-
return Object.assign(Object.assign({}, resp), { globalId });
|
|
433
|
-
});
|
|
434
|
-
}
|
|
435
|
-
login({ roleId, userId, builder, prodApp = false } = {}) {
|
|
436
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
437
|
-
const appId = prodApp ? this.prodAppId : this.appId;
|
|
438
|
-
return context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
439
|
-
userId = !userId ? `us_uuid1` : userId;
|
|
440
|
-
if (!this.request) {
|
|
441
|
-
throw "Server has not been opened, cannot login.";
|
|
442
|
-
}
|
|
443
|
-
// make sure the user exists in the global DB
|
|
444
|
-
if (roleId !== BUILTIN_ROLE_IDS.PUBLIC) {
|
|
445
|
-
yield this.globalUser({
|
|
446
|
-
id: userId,
|
|
447
|
-
builder,
|
|
448
|
-
roles: { [this.prodAppId]: roleId },
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
yield createASession(userId, {
|
|
452
|
-
sessionId: "sessionid",
|
|
453
|
-
tenantId: TENANT_ID,
|
|
454
|
-
});
|
|
455
|
-
// have to fake this
|
|
456
|
-
const auth = {
|
|
457
|
-
userId,
|
|
458
|
-
sessionId: "sessionid",
|
|
459
|
-
tenantId: TENANT_ID,
|
|
460
|
-
};
|
|
461
|
-
const app = {
|
|
462
|
-
roleId: roleId,
|
|
463
|
-
appId,
|
|
464
|
-
};
|
|
465
|
-
const authToken = jwt.sign(auth, env.JWT_SECRET);
|
|
466
|
-
const appToken = jwt.sign(app, env.JWT_SECRET);
|
|
467
|
-
// returning necessary request headers
|
|
468
|
-
yield userCache.invalidateUser(userId);
|
|
469
|
-
return {
|
|
470
|
-
Accept: "application/json",
|
|
471
|
-
Cookie: [
|
|
472
|
-
`${Cookies.Auth}=${authToken}`,
|
|
473
|
-
`${Cookies.CurrentApp}=${appToken}`,
|
|
474
|
-
],
|
|
475
|
-
[Headers.APP_ID]: appId,
|
|
476
|
-
};
|
|
477
|
-
}));
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
508
|
}
|
|
481
509
|
module.exports = TestConfiguration;
|
|
@@ -4,6 +4,8 @@ const { BUILTIN_PERMISSION_IDS } = require("@budibase/backend-core/permissions")
|
|
|
4
4
|
const { createHomeScreen } = require("../../constants/screens");
|
|
5
5
|
const { EMPTY_LAYOUT } = require("../../constants/layouts");
|
|
6
6
|
const { cloneDeep } = require("lodash/fp");
|
|
7
|
+
const { v4: uuidv4 } = require("uuid");
|
|
8
|
+
const { TRIGGER_DEFINITIONS, ACTION_DEFINITIONS } = require("../../automations");
|
|
7
9
|
exports.TENANT_ID = "default";
|
|
8
10
|
exports.basicTable = () => {
|
|
9
11
|
return {
|
|
@@ -26,6 +28,49 @@ exports.basicTable = () => {
|
|
|
26
28
|
},
|
|
27
29
|
};
|
|
28
30
|
};
|
|
31
|
+
exports.basicView = tableId => {
|
|
32
|
+
return {
|
|
33
|
+
tableId,
|
|
34
|
+
name: "ViewTest",
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.filterView = tableId => {
|
|
38
|
+
return Object.assign(Object.assign({}, this.basicView(tableId)), { filters: [
|
|
39
|
+
{
|
|
40
|
+
value: 0,
|
|
41
|
+
condition: "MT",
|
|
42
|
+
key: "count",
|
|
43
|
+
},
|
|
44
|
+
] });
|
|
45
|
+
};
|
|
46
|
+
exports.calculationView = tableId => {
|
|
47
|
+
return Object.assign(Object.assign({}, this.basicView(tableId)), { field: "count", calculation: "sum" });
|
|
48
|
+
};
|
|
49
|
+
exports.view = tableId => {
|
|
50
|
+
return Object.assign(Object.assign({}, this.filterView(tableId)), this.calculationView(tableId));
|
|
51
|
+
};
|
|
52
|
+
exports.automationStep = (actionDefinition = ACTION_DEFINITIONS.CREATE_ROW) => {
|
|
53
|
+
return Object.assign({ id: uuidv4() }, actionDefinition);
|
|
54
|
+
};
|
|
55
|
+
exports.automationTrigger = (triggerDefinition = TRIGGER_DEFINITIONS.ROW_SAVED) => {
|
|
56
|
+
return Object.assign({ id: uuidv4() }, triggerDefinition);
|
|
57
|
+
};
|
|
58
|
+
exports.newAutomation = ({ steps, trigger } = {}) => {
|
|
59
|
+
const automation = exports.basicAutomation();
|
|
60
|
+
if (trigger) {
|
|
61
|
+
automation.definition.trigger = trigger;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
automation.definition.trigger = exports.automationTrigger();
|
|
65
|
+
}
|
|
66
|
+
if (steps) {
|
|
67
|
+
automation.definition.steps = steps;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
automation.definition.steps = [exports.automationStep()];
|
|
71
|
+
}
|
|
72
|
+
return automation;
|
|
73
|
+
};
|
|
29
74
|
exports.basicAutomation = () => {
|
|
30
75
|
return {
|
|
31
76
|
name: "My Automation",
|