@budibase/server 2.3.17-alpha.0 → 2.3.17-alpha.1
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/builder/assets/{index.e8838b62.js → index.2492f6c7.js} +207 -207
- package/builder/index.html +1 -1
- package/dist/package.json +6 -6
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/tsconfig.build.json +1 -0
- package/dist/api/routes/public/tests/utils.js +0 -60
- package/dist/api/routes/tests/utilities/index.js +0 -131
- package/dist/tests/utilities/TestConfiguration.js +0 -626
- package/dist/tests/utilities/controllers.js +0 -40
- package/dist/tests/utilities/structures.js +0 -234
|
@@ -1,626 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
35
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
36
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
37
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
38
|
-
};
|
|
39
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
40
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
41
|
-
};
|
|
42
|
-
var _TestConfiguration_setMultiTenancy, _TestConfiguration_setSelfHosted;
|
|
43
|
-
const tests_1 = require("@budibase/backend-core/tests");
|
|
44
|
-
// init the licensing mock
|
|
45
|
-
const pro = __importStar(require("@budibase/pro"));
|
|
46
|
-
tests_1.mocks.licenses.init(pro);
|
|
47
|
-
// use unlimited license by default
|
|
48
|
-
tests_1.mocks.licenses.useUnlimited();
|
|
49
|
-
const db_1 = require("../../db");
|
|
50
|
-
(0, db_1.init)();
|
|
51
|
-
const environment_1 = __importDefault(require("../../environment"));
|
|
52
|
-
const backend_core_1 = require("@budibase/backend-core");
|
|
53
|
-
const structures_1 = require("./structures");
|
|
54
|
-
const backend_core_2 = require("@budibase/backend-core");
|
|
55
|
-
const controllers = __importStar(require("./controllers"));
|
|
56
|
-
const fileSystem_1 = require("../../utilities/fileSystem");
|
|
57
|
-
const newid_1 = __importDefault(require("../../db/newid"));
|
|
58
|
-
const utils_1 = require("../../db/utils");
|
|
59
|
-
const startup_1 = require("../../startup");
|
|
60
|
-
const supertest_1 = __importDefault(require("supertest"));
|
|
61
|
-
const types_1 = require("@budibase/types");
|
|
62
|
-
class TestConfiguration {
|
|
63
|
-
constructor(openServer = true) {
|
|
64
|
-
// MODES
|
|
65
|
-
_TestConfiguration_setMultiTenancy.set(this, (value) => {
|
|
66
|
-
environment_1.default._set("MULTI_TENANCY", value);
|
|
67
|
-
backend_core_1.env._set("MULTI_TENANCY", value);
|
|
68
|
-
});
|
|
69
|
-
_TestConfiguration_setSelfHosted.set(this, (value) => {
|
|
70
|
-
environment_1.default._set("SELF_HOSTED", value);
|
|
71
|
-
backend_core_1.env._set("SELF_HOSTED", value);
|
|
72
|
-
});
|
|
73
|
-
this.modeCloud = () => {
|
|
74
|
-
__classPrivateFieldGet(this, _TestConfiguration_setSelfHosted, "f").call(this, false);
|
|
75
|
-
__classPrivateFieldGet(this, _TestConfiguration_setMultiTenancy, "f").call(this, true);
|
|
76
|
-
};
|
|
77
|
-
this.modeSelf = () => {
|
|
78
|
-
__classPrivateFieldGet(this, _TestConfiguration_setSelfHosted, "f").call(this, true);
|
|
79
|
-
__classPrivateFieldGet(this, _TestConfiguration_setMultiTenancy, "f").call(this, false);
|
|
80
|
-
};
|
|
81
|
-
if (openServer) {
|
|
82
|
-
// use a random port because it doesn't matter
|
|
83
|
-
environment_1.default.PORT = "0";
|
|
84
|
-
this.server = require("../../app").default;
|
|
85
|
-
// we need the request for logging in, involves cookies, hard to fake
|
|
86
|
-
this.request = (0, supertest_1.default)(this.server);
|
|
87
|
-
this.started = true;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
this.started = false;
|
|
91
|
-
}
|
|
92
|
-
this.appId = null;
|
|
93
|
-
this.allApps = [];
|
|
94
|
-
this.tenantId = null;
|
|
95
|
-
this.defaultUserValues = this.populateDefaultUserValues();
|
|
96
|
-
}
|
|
97
|
-
populateDefaultUserValues() {
|
|
98
|
-
return {
|
|
99
|
-
globalUserId: `us_${(0, newid_1.default)()}`,
|
|
100
|
-
email: tests_1.generator.email(),
|
|
101
|
-
firstName: tests_1.generator.first(),
|
|
102
|
-
lastName: tests_1.generator.last(),
|
|
103
|
-
csrfToken: tests_1.generator.hash(),
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
getRequest() {
|
|
107
|
-
return this.request;
|
|
108
|
-
}
|
|
109
|
-
getApp() {
|
|
110
|
-
return this.app;
|
|
111
|
-
}
|
|
112
|
-
getProdApp() {
|
|
113
|
-
return this.prodApp;
|
|
114
|
-
}
|
|
115
|
-
getAppId() {
|
|
116
|
-
return this.appId;
|
|
117
|
-
}
|
|
118
|
-
getProdAppId() {
|
|
119
|
-
return this.prodAppId;
|
|
120
|
-
}
|
|
121
|
-
getUserDetails() {
|
|
122
|
-
return {
|
|
123
|
-
globalId: this.defaultUserValues.globalUserId,
|
|
124
|
-
email: this.defaultUserValues.email,
|
|
125
|
-
firstName: this.defaultUserValues.firstName,
|
|
126
|
-
lastName: this.defaultUserValues.lastName,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
doInContext(appId, task) {
|
|
130
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
if (!appId) {
|
|
132
|
-
appId = this.appId;
|
|
133
|
-
}
|
|
134
|
-
const tenant = this.getTenantId();
|
|
135
|
-
return backend_core_2.tenancy.doInTenant(tenant, () => {
|
|
136
|
-
// check if already in a context
|
|
137
|
-
if (backend_core_2.context.getAppId() == null && appId !== null) {
|
|
138
|
-
return backend_core_2.context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
return task();
|
|
140
|
-
}));
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
return task();
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
// SETUP / TEARDOWN
|
|
149
|
-
// use a new id as the name to avoid name collisions
|
|
150
|
-
init(appName = (0, newid_1.default)()) {
|
|
151
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
this.defaultUserValues = this.populateDefaultUserValues();
|
|
153
|
-
if (backend_core_2.context.isMultiTenant()) {
|
|
154
|
-
this.tenantId = tests_1.structures.tenant.id();
|
|
155
|
-
}
|
|
156
|
-
if (!this.started) {
|
|
157
|
-
yield (0, startup_1.startup)();
|
|
158
|
-
}
|
|
159
|
-
this.user = yield this.globalUser();
|
|
160
|
-
this.globalUserId = this.user._id;
|
|
161
|
-
this.userMetadataId = (0, utils_1.generateUserMetadataID)(this.globalUserId);
|
|
162
|
-
return this.createApp(appName);
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
end() {
|
|
166
|
-
if (!this) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
if (this.server) {
|
|
170
|
-
this.server.close();
|
|
171
|
-
}
|
|
172
|
-
if (this.allApps) {
|
|
173
|
-
(0, fileSystem_1.cleanup)(this.allApps.map(app => app.appId));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
// UTILS
|
|
177
|
-
_req(body, params, controlFunc) {
|
|
178
|
-
// create a fake request ctx
|
|
179
|
-
const request = {};
|
|
180
|
-
const appId = this.appId;
|
|
181
|
-
request.appId = appId;
|
|
182
|
-
// fake cookies, we don't need them
|
|
183
|
-
request.cookies = { set: () => { }, get: () => { } };
|
|
184
|
-
request.config = { jwtSecret: environment_1.default.JWT_SECRET };
|
|
185
|
-
request.user = { appId, tenantId: this.getTenantId() };
|
|
186
|
-
request.query = {};
|
|
187
|
-
request.request = {
|
|
188
|
-
body,
|
|
189
|
-
};
|
|
190
|
-
if (params) {
|
|
191
|
-
request.params = params;
|
|
192
|
-
}
|
|
193
|
-
return this.doInContext(appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
194
|
-
yield controlFunc(request);
|
|
195
|
-
return request.body;
|
|
196
|
-
}));
|
|
197
|
-
}
|
|
198
|
-
// USER / AUTH
|
|
199
|
-
globalUser({ id = this.defaultUserValues.globalUserId, firstName = this.defaultUserValues.firstName, lastName = this.defaultUserValues.lastName, builder = true, admin = false, email = this.defaultUserValues.email, roles, } = {}) {
|
|
200
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
-
return backend_core_2.tenancy.doWithGlobalDB(this.getTenantId(), (db) => __awaiter(this, void 0, void 0, function* () {
|
|
202
|
-
let existing;
|
|
203
|
-
try {
|
|
204
|
-
existing = yield db.get(id);
|
|
205
|
-
}
|
|
206
|
-
catch (err) {
|
|
207
|
-
existing = { email };
|
|
208
|
-
}
|
|
209
|
-
const user = Object.assign(Object.assign({ _id: id }, existing), { roles: roles || {}, tenantId: this.getTenantId(), firstName,
|
|
210
|
-
lastName });
|
|
211
|
-
yield backend_core_2.sessions.createASession(id, {
|
|
212
|
-
sessionId: "sessionid",
|
|
213
|
-
tenantId: this.getTenantId(),
|
|
214
|
-
csrfToken: this.defaultUserValues.csrfToken,
|
|
215
|
-
});
|
|
216
|
-
if (builder) {
|
|
217
|
-
user.builder = { global: true };
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
user.builder = { global: false };
|
|
221
|
-
}
|
|
222
|
-
if (admin) {
|
|
223
|
-
user.admin = { global: true };
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
user.admin = { global: false };
|
|
227
|
-
}
|
|
228
|
-
const resp = yield db.put(user);
|
|
229
|
-
return Object.assign({ _rev: resp.rev }, user);
|
|
230
|
-
}));
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
createUser(user = {}) {
|
|
234
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
-
let { id, firstName, lastName, email, builder, admin, roles } = user;
|
|
236
|
-
firstName = firstName || this.defaultUserValues.firstName;
|
|
237
|
-
lastName = lastName || this.defaultUserValues.lastName;
|
|
238
|
-
email = email || this.defaultUserValues.email;
|
|
239
|
-
roles = roles || {};
|
|
240
|
-
if (builder == null) {
|
|
241
|
-
builder = true;
|
|
242
|
-
}
|
|
243
|
-
const globalId = !id ? `us_${Math.random()}` : `us_${id}`;
|
|
244
|
-
const resp = yield this.globalUser({
|
|
245
|
-
id: globalId,
|
|
246
|
-
firstName,
|
|
247
|
-
lastName,
|
|
248
|
-
email,
|
|
249
|
-
builder,
|
|
250
|
-
admin,
|
|
251
|
-
roles,
|
|
252
|
-
});
|
|
253
|
-
yield backend_core_2.cache.user.invalidateUser(globalId);
|
|
254
|
-
return Object.assign(Object.assign({}, resp), { globalId });
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
login({ roleId, userId, builder, prodApp = false } = {}) {
|
|
258
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
259
|
-
const appId = prodApp ? this.prodAppId : this.appId;
|
|
260
|
-
return backend_core_2.context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
261
|
-
userId = !userId ? `us_uuid1` : userId;
|
|
262
|
-
if (!this.request) {
|
|
263
|
-
throw "Server has not been opened, cannot login.";
|
|
264
|
-
}
|
|
265
|
-
// make sure the user exists in the global DB
|
|
266
|
-
if (roleId !== backend_core_2.roles.BUILTIN_ROLE_IDS.PUBLIC) {
|
|
267
|
-
yield this.globalUser({
|
|
268
|
-
id: userId,
|
|
269
|
-
builder,
|
|
270
|
-
roles: { [this.prodAppId]: roleId },
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
yield backend_core_2.sessions.createASession(userId, {
|
|
274
|
-
sessionId: "sessionid",
|
|
275
|
-
tenantId: this.getTenantId(),
|
|
276
|
-
});
|
|
277
|
-
// have to fake this
|
|
278
|
-
const authObj = {
|
|
279
|
-
userId,
|
|
280
|
-
sessionId: "sessionid",
|
|
281
|
-
tenantId: this.getTenantId(),
|
|
282
|
-
};
|
|
283
|
-
const app = {
|
|
284
|
-
roleId: roleId,
|
|
285
|
-
appId,
|
|
286
|
-
};
|
|
287
|
-
const authToken = backend_core_2.auth.jwt.sign(authObj, environment_1.default.JWT_SECRET);
|
|
288
|
-
const appToken = backend_core_2.auth.jwt.sign(app, environment_1.default.JWT_SECRET);
|
|
289
|
-
// returning necessary request headers
|
|
290
|
-
yield backend_core_2.cache.user.invalidateUser(userId);
|
|
291
|
-
return {
|
|
292
|
-
Accept: "application/json",
|
|
293
|
-
Cookie: [
|
|
294
|
-
`${backend_core_2.constants.Cookie.Auth}=${authToken}`,
|
|
295
|
-
`${backend_core_2.constants.Cookie.CurrentApp}=${appToken}`,
|
|
296
|
-
],
|
|
297
|
-
[backend_core_2.constants.Header.APP_ID]: appId,
|
|
298
|
-
};
|
|
299
|
-
}));
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
defaultHeaders(extras = {}) {
|
|
303
|
-
const tenantId = this.getTenantId();
|
|
304
|
-
const authObj = {
|
|
305
|
-
userId: this.defaultUserValues.globalUserId,
|
|
306
|
-
sessionId: "sessionid",
|
|
307
|
-
tenantId,
|
|
308
|
-
};
|
|
309
|
-
const app = {
|
|
310
|
-
roleId: backend_core_2.roles.BUILTIN_ROLE_IDS.ADMIN,
|
|
311
|
-
appId: this.appId,
|
|
312
|
-
};
|
|
313
|
-
const authToken = backend_core_2.auth.jwt.sign(authObj, environment_1.default.JWT_SECRET);
|
|
314
|
-
const appToken = backend_core_2.auth.jwt.sign(app, environment_1.default.JWT_SECRET);
|
|
315
|
-
const headers = Object.assign({ Accept: "application/json", Cookie: [
|
|
316
|
-
`${backend_core_2.constants.Cookie.Auth}=${authToken}`,
|
|
317
|
-
`${backend_core_2.constants.Cookie.CurrentApp}=${appToken}`,
|
|
318
|
-
], [backend_core_2.constants.Header.CSRF_TOKEN]: this.defaultUserValues.csrfToken }, extras);
|
|
319
|
-
if (this.appId) {
|
|
320
|
-
headers[backend_core_2.constants.Header.APP_ID] = this.appId;
|
|
321
|
-
}
|
|
322
|
-
return headers;
|
|
323
|
-
}
|
|
324
|
-
getTenantId() {
|
|
325
|
-
return this.tenantId || structures_1.TENANT_ID;
|
|
326
|
-
}
|
|
327
|
-
publicHeaders({ prodApp = true } = {}) {
|
|
328
|
-
const appId = prodApp ? this.prodAppId : this.appId;
|
|
329
|
-
const headers = {
|
|
330
|
-
Accept: "application/json",
|
|
331
|
-
};
|
|
332
|
-
if (appId) {
|
|
333
|
-
headers[backend_core_2.constants.Header.APP_ID] = appId;
|
|
334
|
-
}
|
|
335
|
-
if (this.tenantId) {
|
|
336
|
-
headers[backend_core_2.constants.Header.TENANT_ID] = this.tenantId;
|
|
337
|
-
}
|
|
338
|
-
return headers;
|
|
339
|
-
}
|
|
340
|
-
roleHeaders({ email = this.defaultUserValues.email, roleId = backend_core_2.roles.BUILTIN_ROLE_IDS.ADMIN, builder = false, prodApp = true, } = {}) {
|
|
341
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
342
|
-
return this.login({ email, roleId, builder, prodApp });
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
// API
|
|
346
|
-
generateApiKey(userId = this.defaultUserValues.globalUserId) {
|
|
347
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
348
|
-
return backend_core_2.tenancy.doWithGlobalDB(this.getTenantId(), (db) => __awaiter(this, void 0, void 0, function* () {
|
|
349
|
-
const id = backend_core_2.db.generateDevInfoID(userId);
|
|
350
|
-
let devInfo;
|
|
351
|
-
try {
|
|
352
|
-
devInfo = yield db.get(id);
|
|
353
|
-
}
|
|
354
|
-
catch (err) {
|
|
355
|
-
devInfo = { _id: id, userId };
|
|
356
|
-
}
|
|
357
|
-
devInfo.apiKey = backend_core_2.encryption.encrypt(`${this.getTenantId()}${backend_core_2.db.SEPARATOR}${(0, newid_1.default)()}`);
|
|
358
|
-
yield db.put(devInfo);
|
|
359
|
-
return devInfo.apiKey;
|
|
360
|
-
}));
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
// APP
|
|
364
|
-
createApp(appName) {
|
|
365
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
366
|
-
// create dev app
|
|
367
|
-
// clear any old app
|
|
368
|
-
this.appId = null;
|
|
369
|
-
yield backend_core_2.context.doInAppContext(null, () => __awaiter(this, void 0, void 0, function* () {
|
|
370
|
-
this.app = yield this._req({ name: appName }, null, controllers.app.create);
|
|
371
|
-
this.appId = this.app.appId;
|
|
372
|
-
}));
|
|
373
|
-
return yield backend_core_2.context.doInAppContext(this.appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
374
|
-
// create production app
|
|
375
|
-
this.prodApp = yield this.publish();
|
|
376
|
-
this.allApps.push(this.prodApp);
|
|
377
|
-
this.allApps.push(this.app);
|
|
378
|
-
return this.app;
|
|
379
|
-
}));
|
|
380
|
-
});
|
|
381
|
-
}
|
|
382
|
-
publish() {
|
|
383
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
384
|
-
yield this._req(null, null, controllers.deploy.publishApp);
|
|
385
|
-
// @ts-ignore
|
|
386
|
-
const prodAppId = this.getAppId().replace("_dev", "");
|
|
387
|
-
this.prodAppId = prodAppId;
|
|
388
|
-
return backend_core_2.context.doInAppContext(prodAppId, () => __awaiter(this, void 0, void 0, function* () {
|
|
389
|
-
const db = backend_core_2.context.getProdAppDB();
|
|
390
|
-
return yield db.get(backend_core_2.db.DocumentType.APP_METADATA);
|
|
391
|
-
}));
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
unpublish() {
|
|
395
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
396
|
-
const response = yield this._req(null, { appId: this.appId }, controllers.app.unpublish);
|
|
397
|
-
this.prodAppId = null;
|
|
398
|
-
this.prodApp = null;
|
|
399
|
-
return response;
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
// TABLE
|
|
403
|
-
updateTable(config) {
|
|
404
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
405
|
-
config = config || (0, structures_1.basicTable)();
|
|
406
|
-
this.table = yield this._req(config, null, controllers.table.save);
|
|
407
|
-
return this.table;
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
createTable(config) {
|
|
411
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
412
|
-
if (config != null && config._id) {
|
|
413
|
-
delete config._id;
|
|
414
|
-
}
|
|
415
|
-
return this.updateTable(config);
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
getTable(tableId) {
|
|
419
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
420
|
-
tableId = tableId || this.table._id;
|
|
421
|
-
return this._req(null, { tableId }, controllers.table.find);
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
createLinkedTable(relationshipType, links = ["link"]) {
|
|
425
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
426
|
-
if (!this.table) {
|
|
427
|
-
throw "Must have created a table first.";
|
|
428
|
-
}
|
|
429
|
-
const tableConfig = (0, structures_1.basicTable)();
|
|
430
|
-
tableConfig.primaryDisplay = "name";
|
|
431
|
-
for (let link of links) {
|
|
432
|
-
tableConfig.schema[link] = {
|
|
433
|
-
type: "link",
|
|
434
|
-
fieldName: link,
|
|
435
|
-
tableId: this.table._id,
|
|
436
|
-
name: link,
|
|
437
|
-
};
|
|
438
|
-
if (relationshipType) {
|
|
439
|
-
tableConfig.schema[link].relationshipType = relationshipType;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
const linkedTable = yield this.createTable(tableConfig);
|
|
443
|
-
this.linkedTable = linkedTable;
|
|
444
|
-
return linkedTable;
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
createAttachmentTable() {
|
|
448
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
449
|
-
const table = (0, structures_1.basicTable)();
|
|
450
|
-
table.schema.attachment = {
|
|
451
|
-
type: "attachment",
|
|
452
|
-
};
|
|
453
|
-
return this.createTable(table);
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
// ROW
|
|
457
|
-
createRow(config) {
|
|
458
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
459
|
-
if (!this.table) {
|
|
460
|
-
throw "Test requires table to be configured.";
|
|
461
|
-
}
|
|
462
|
-
const tableId = (config && config.tableId) || this.table._id;
|
|
463
|
-
config = config || (0, structures_1.basicRow)(tableId);
|
|
464
|
-
return this._req(config, { tableId }, controllers.row.save);
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
getRow(tableId, rowId) {
|
|
468
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
469
|
-
return this._req(null, { tableId, rowId }, controllers.row.find);
|
|
470
|
-
});
|
|
471
|
-
}
|
|
472
|
-
getRows(tableId) {
|
|
473
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
474
|
-
if (!tableId && this.table) {
|
|
475
|
-
tableId = this.table._id;
|
|
476
|
-
}
|
|
477
|
-
return this._req(null, { tableId }, controllers.row.fetch);
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
// ROLE
|
|
481
|
-
createRole(config) {
|
|
482
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
483
|
-
config = config || (0, structures_1.basicRole)();
|
|
484
|
-
return this._req(config, null, controllers.role.save);
|
|
485
|
-
});
|
|
486
|
-
}
|
|
487
|
-
addPermission(roleId, resourceId, level = "read") {
|
|
488
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
489
|
-
return this._req(null, {
|
|
490
|
-
roleId,
|
|
491
|
-
resourceId,
|
|
492
|
-
level,
|
|
493
|
-
}, controllers.perms.addPermission);
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
// VIEW
|
|
497
|
-
createView(config) {
|
|
498
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
499
|
-
if (!this.table) {
|
|
500
|
-
throw "Test requires table to be configured.";
|
|
501
|
-
}
|
|
502
|
-
const view = config || {
|
|
503
|
-
tableId: this.table._id,
|
|
504
|
-
name: "ViewTest",
|
|
505
|
-
};
|
|
506
|
-
return this._req(view, null, controllers.view.save);
|
|
507
|
-
});
|
|
508
|
-
}
|
|
509
|
-
// AUTOMATION
|
|
510
|
-
createAutomation(config) {
|
|
511
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
512
|
-
config = config || (0, structures_1.basicAutomation)();
|
|
513
|
-
if (config._rev) {
|
|
514
|
-
delete config._rev;
|
|
515
|
-
}
|
|
516
|
-
this.automation = (yield this._req(config, null, controllers.automation.create)).automation;
|
|
517
|
-
return this.automation;
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
getAllAutomations() {
|
|
521
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
522
|
-
return this._req(null, null, controllers.automation.fetch);
|
|
523
|
-
});
|
|
524
|
-
}
|
|
525
|
-
deleteAutomation(automation) {
|
|
526
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
527
|
-
automation = automation || this.automation;
|
|
528
|
-
if (!automation) {
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
return this._req(null, { id: automation._id, rev: automation._rev }, controllers.automation.destroy);
|
|
532
|
-
});
|
|
533
|
-
}
|
|
534
|
-
createWebhook(config) {
|
|
535
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
536
|
-
if (!this.automation) {
|
|
537
|
-
throw "Must create an automation before creating webhook.";
|
|
538
|
-
}
|
|
539
|
-
config = config || (0, structures_1.basicWebhook)(this.automation._id);
|
|
540
|
-
return (yield this._req(config, null, controllers.webhook.save)).webhook;
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
// DATASOURCE
|
|
544
|
-
createDatasource(config) {
|
|
545
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
546
|
-
config = config || (0, structures_1.basicDatasource)();
|
|
547
|
-
const response = yield this._req(config, null, controllers.datasource.save);
|
|
548
|
-
this.datasource = response.datasource;
|
|
549
|
-
return this.datasource;
|
|
550
|
-
});
|
|
551
|
-
}
|
|
552
|
-
updateDatasource(datasource) {
|
|
553
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
554
|
-
const response = yield this._req(datasource, { datasourceId: datasource._id }, controllers.datasource.update);
|
|
555
|
-
this.datasource = response.datasource;
|
|
556
|
-
return this.datasource;
|
|
557
|
-
});
|
|
558
|
-
}
|
|
559
|
-
restDatasource(cfg) {
|
|
560
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
561
|
-
return this.createDatasource({
|
|
562
|
-
datasource: Object.assign(Object.assign({}, (0, structures_1.basicDatasource)().datasource), { source: types_1.SourceName.REST, config: cfg || {} }),
|
|
563
|
-
});
|
|
564
|
-
});
|
|
565
|
-
}
|
|
566
|
-
dynamicVariableDatasource() {
|
|
567
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
568
|
-
let datasource = yield this.restDatasource();
|
|
569
|
-
const basedOnQuery = yield this.createQuery(Object.assign(Object.assign({}, (0, structures_1.basicQuery)(datasource._id)), { fields: {
|
|
570
|
-
path: "www.google.com",
|
|
571
|
-
} }));
|
|
572
|
-
datasource = yield this.updateDatasource(Object.assign(Object.assign({}, datasource), { config: {
|
|
573
|
-
dynamicVariables: [
|
|
574
|
-
{
|
|
575
|
-
queryId: basedOnQuery._id,
|
|
576
|
-
name: "variable3",
|
|
577
|
-
value: "{{ data.0.[value] }}",
|
|
578
|
-
},
|
|
579
|
-
],
|
|
580
|
-
} }));
|
|
581
|
-
return { datasource, query: basedOnQuery };
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
// QUERY
|
|
585
|
-
previewQuery(request, config, datasource, fields, params, verb) {
|
|
586
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
587
|
-
return request
|
|
588
|
-
.post(`/api/queries/preview`)
|
|
589
|
-
.send({
|
|
590
|
-
datasourceId: datasource._id,
|
|
591
|
-
parameters: params || {},
|
|
592
|
-
fields,
|
|
593
|
-
queryVerb: verb || "read",
|
|
594
|
-
name: datasource.name,
|
|
595
|
-
})
|
|
596
|
-
.set(config.defaultHeaders())
|
|
597
|
-
.expect("Content-Type", /json/)
|
|
598
|
-
.expect(200);
|
|
599
|
-
});
|
|
600
|
-
}
|
|
601
|
-
createQuery(config) {
|
|
602
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
603
|
-
if (!this.datasource && !config) {
|
|
604
|
-
throw "No datasource created for query.";
|
|
605
|
-
}
|
|
606
|
-
config = config || (0, structures_1.basicQuery)(this.datasource._id);
|
|
607
|
-
return this._req(config, null, controllers.query.save);
|
|
608
|
-
});
|
|
609
|
-
}
|
|
610
|
-
// SCREEN
|
|
611
|
-
createScreen(config) {
|
|
612
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
613
|
-
config = config || (0, structures_1.basicScreen)();
|
|
614
|
-
return this._req(config, null, controllers.screen.save);
|
|
615
|
-
});
|
|
616
|
-
}
|
|
617
|
-
// LAYOUT
|
|
618
|
-
createLayout(config) {
|
|
619
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
620
|
-
config = config || (0, structures_1.basicLayout)();
|
|
621
|
-
return yield this._req(config, null, controllers.layout.save);
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
_TestConfiguration_setMultiTenancy = new WeakMap(), _TestConfiguration_setSelfHosted = new WeakMap();
|
|
626
|
-
module.exports = TestConfiguration;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.deploy = exports.layout = exports.webhook = exports.screen = exports.query = exports.datasource = exports.automation = exports.user = exports.app = exports.view = exports.perms = exports.role = exports.row = exports.table = void 0;
|
|
27
|
-
exports.table = __importStar(require("../../api/controllers/table"));
|
|
28
|
-
exports.row = __importStar(require("../../api/controllers/row"));
|
|
29
|
-
exports.role = __importStar(require("../../api/controllers/role"));
|
|
30
|
-
exports.perms = __importStar(require("../../api/controllers/permission"));
|
|
31
|
-
exports.view = __importStar(require("../../api/controllers/view"));
|
|
32
|
-
exports.app = __importStar(require("../../api/controllers/application"));
|
|
33
|
-
exports.user = __importStar(require("../../api/controllers/user"));
|
|
34
|
-
exports.automation = __importStar(require("../../api/controllers/automation"));
|
|
35
|
-
exports.datasource = __importStar(require("../../api/controllers/datasource"));
|
|
36
|
-
exports.query = __importStar(require("../../api/controllers/query"));
|
|
37
|
-
exports.screen = __importStar(require("../../api/controllers/screen"));
|
|
38
|
-
exports.webhook = __importStar(require("../../api/controllers/webhook"));
|
|
39
|
-
exports.layout = __importStar(require("../../api/controllers/layout"));
|
|
40
|
-
exports.deploy = __importStar(require("../../api/controllers/deploy"));
|