@budibase/server 2.7.15 → 2.7.16-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.d9b46807.css → index.2e9069f3.css} +1 -1
- package/builder/assets/{index.717d69a6.js → index.3801a6c5.js} +371 -371
- package/builder/index.html +2 -2
- package/dist/automation.js +859 -634
- package/dist/automation.js.map +3 -3
- package/dist/index.js +1180 -947
- package/dist/index.js.map +3 -3
- package/dist/query.js +996 -837
- package/dist/query.js.map +3 -3
- package/package.json +11 -11
- package/src/api/controllers/backup.ts +22 -8
- package/src/api/controllers/datasource.ts +41 -24
- package/src/api/controllers/role.ts +5 -5
- package/src/api/controllers/routing.ts +3 -3
- package/src/api/routes/backup.ts +1 -1
- package/src/api/routes/tests/backup.spec.ts +18 -2
- package/src/automations/steps/sendSmtpEmail.ts +55 -4
- package/src/automations/tests/sendSmtpEmail.spec.ts +74 -0
- package/src/events/docUpdates/syncUsers.ts +4 -0
- package/src/integrations/googlesheets.ts +35 -18
- package/src/integrations/mongodb.ts +4 -2
- package/src/integrations/postgres.ts +2 -1
- package/src/middleware/currentapp.ts +1 -1
- package/src/sdk/app/backups/exports.ts +33 -5
- package/src/sdk/app/backups/imports.ts +21 -1
- package/src/sdk/app/datasources/datasources.ts +1 -0
- package/src/utilities/workerRequests.ts +20 -9
- package/src/automations/tests/sendSmtpEmail.spec.js +0 -71
package/dist/automation.js
CHANGED
|
@@ -11,8 +11,8 @@ var __commonJS = (cb, mod) => function __require() {
|
|
|
11
11
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
12
|
};
|
|
13
13
|
var __export = (target, all) => {
|
|
14
|
-
for (var
|
|
15
|
-
__defProp(target,
|
|
14
|
+
for (var name2 in all)
|
|
15
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
16
16
|
};
|
|
17
17
|
var __copyProps = (to, from, except, desc) => {
|
|
18
18
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -671,13 +671,13 @@ var init_plan = __esm({
|
|
|
671
671
|
var isStaticQuota, isMonthlyQuota, isConstantQuota;
|
|
672
672
|
var init_quota = __esm({
|
|
673
673
|
"../types/src/sdk/licensing/quota.ts"() {
|
|
674
|
-
isStaticQuota = (quotaType, usageType,
|
|
674
|
+
isStaticQuota = (quotaType, usageType, name2) => {
|
|
675
675
|
return quotaType === "usage" /* USAGE */ && usageType === "static" /* STATIC */;
|
|
676
676
|
};
|
|
677
|
-
isMonthlyQuota = (quotaType, usageType,
|
|
677
|
+
isMonthlyQuota = (quotaType, usageType, name2) => {
|
|
678
678
|
return quotaType === "usage" /* USAGE */ && usageType === "monthly" /* MONTHLY */;
|
|
679
679
|
};
|
|
680
|
-
isConstantQuota = (quotaType,
|
|
680
|
+
isConstantQuota = (quotaType, name2) => {
|
|
681
681
|
return quotaType === "constant" /* CONSTANT */;
|
|
682
682
|
};
|
|
683
683
|
}
|
|
@@ -787,8 +787,8 @@ var init_locks = __esm({
|
|
|
787
787
|
var isDocument;
|
|
788
788
|
var init_db = __esm({
|
|
789
789
|
"../types/src/sdk/db.ts"() {
|
|
790
|
-
isDocument = (
|
|
791
|
-
return typeof
|
|
790
|
+
isDocument = (doc2) => {
|
|
791
|
+
return typeof doc2 === "object" && doc2._id && doc2._rev;
|
|
792
792
|
};
|
|
793
793
|
}
|
|
794
794
|
});
|
|
@@ -946,6 +946,7 @@ var init_automation2 = __esm({
|
|
|
946
946
|
AutomationIOType2["NUMBER"] = "number";
|
|
947
947
|
AutomationIOType2["ARRAY"] = "array";
|
|
948
948
|
AutomationIOType2["JSON"] = "json";
|
|
949
|
+
AutomationIOType2["DATE"] = "date";
|
|
949
950
|
return AutomationIOType2;
|
|
950
951
|
})(AutomationIOType || {});
|
|
951
952
|
AutomationCustomIOType = /* @__PURE__ */ ((AutomationCustomIOType2) => {
|
|
@@ -2064,12 +2065,12 @@ function getPouchDB(dbName, opts) {
|
|
|
2064
2065
|
checkInitialised();
|
|
2065
2066
|
const db2 = new Pouch(dbName, opts);
|
|
2066
2067
|
const dbPut = db2.put;
|
|
2067
|
-
db2.put = async (
|
|
2068
|
-
if (!
|
|
2069
|
-
|
|
2068
|
+
db2.put = async (doc2, options2 = {}) => {
|
|
2069
|
+
if (!doc2.createdAt) {
|
|
2070
|
+
doc2.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2070
2071
|
}
|
|
2071
|
-
|
|
2072
|
-
return dbPut(
|
|
2072
|
+
doc2.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2073
|
+
return dbPut(doc2, options2);
|
|
2073
2074
|
};
|
|
2074
2075
|
db2.exists = async () => {
|
|
2075
2076
|
const info = await db2.info();
|
|
@@ -2239,7 +2240,7 @@ var init_DatabaseImpl = __esm({
|
|
|
2239
2240
|
}
|
|
2240
2241
|
return this.updateOutput(() => db2.get(id));
|
|
2241
2242
|
}
|
|
2242
|
-
async remove(idOrDoc,
|
|
2243
|
+
async remove(idOrDoc, rev2) {
|
|
2243
2244
|
const db2 = await this.checkSetup();
|
|
2244
2245
|
let _id;
|
|
2245
2246
|
let _rev;
|
|
@@ -2248,7 +2249,7 @@ var init_DatabaseImpl = __esm({
|
|
|
2248
2249
|
_rev = idOrDoc._rev;
|
|
2249
2250
|
} else {
|
|
2250
2251
|
_id = idOrDoc;
|
|
2251
|
-
_rev =
|
|
2252
|
+
_rev = rev2;
|
|
2252
2253
|
}
|
|
2253
2254
|
if (!_id || !_rev) {
|
|
2254
2255
|
throw new Error("Unable to remove doc without a valid _id and _rev.");
|
|
@@ -3512,18 +3513,18 @@ async function newRedlock(opts = {}) {
|
|
|
3512
3513
|
}
|
|
3513
3514
|
function getLockName(opts) {
|
|
3514
3515
|
const prefix = opts.systemLock ? "system" : getTenantId();
|
|
3515
|
-
let
|
|
3516
|
+
let name2 = `lock:${prefix}_${opts.name}`;
|
|
3516
3517
|
if (opts.resource) {
|
|
3517
|
-
|
|
3518
|
+
name2 = name2 + `_${opts.resource}`;
|
|
3518
3519
|
}
|
|
3519
|
-
return
|
|
3520
|
+
return name2;
|
|
3520
3521
|
}
|
|
3521
3522
|
async function doWithLock(opts, task) {
|
|
3522
3523
|
const redlock = await getClient(opts.type, opts.customOptions);
|
|
3523
3524
|
let lock;
|
|
3524
3525
|
try {
|
|
3525
|
-
const
|
|
3526
|
-
lock = await redlock.lock(
|
|
3526
|
+
const name2 = getLockName(opts);
|
|
3527
|
+
lock = await redlock.lock(name2, opts.ttl);
|
|
3527
3528
|
const result = await task();
|
|
3528
3529
|
return { executed: true, result };
|
|
3529
3530
|
} catch (e) {
|
|
@@ -4037,8 +4038,8 @@ var init_ids = __esm({
|
|
|
4037
4038
|
generateDevInfoID = (userId) => {
|
|
4038
4039
|
return `${"devinfo" /* DEV_INFO */}${SEPARATOR}${userId}`;
|
|
4039
4040
|
};
|
|
4040
|
-
generatePluginID = (
|
|
4041
|
-
return `${"plg" /* PLUGIN */}${SEPARATOR}${
|
|
4041
|
+
generatePluginID = (name2) => {
|
|
4042
|
+
return `${"plg" /* PLUGIN */}${SEPARATOR}${name2}`;
|
|
4042
4043
|
};
|
|
4043
4044
|
}
|
|
4044
4045
|
});
|
|
@@ -4128,8 +4129,8 @@ var init_params = __esm({
|
|
|
4128
4129
|
isDatasourceId = (id) => {
|
|
4129
4130
|
return id && id.startsWith(`${"datasource" /* DATASOURCE */}${SEPARATOR}`);
|
|
4130
4131
|
};
|
|
4131
|
-
getPluginParams = (
|
|
4132
|
-
return getDocParams("plg" /* PLUGIN */,
|
|
4132
|
+
getPluginParams = (pluginId2, otherProps = {}) => {
|
|
4133
|
+
return getDocParams("plg" /* PLUGIN */, pluginId2, otherProps);
|
|
4133
4134
|
};
|
|
4134
4135
|
}
|
|
4135
4136
|
});
|
|
@@ -4266,7 +4267,7 @@ function pagination(data2, pageSize, {
|
|
|
4266
4267
|
const hasNextPage = data2.length > pageSize;
|
|
4267
4268
|
let nextPage = void 0;
|
|
4268
4269
|
if (!getKey) {
|
|
4269
|
-
getKey = (
|
|
4270
|
+
getKey = (doc2) => property ? doc2 == null ? void 0 : doc2[property] : doc2 == null ? void 0 : doc2._id;
|
|
4270
4271
|
}
|
|
4271
4272
|
if (hasNextPage) {
|
|
4272
4273
|
nextPage = getKey(data2[pageSize]);
|
|
@@ -4484,8 +4485,8 @@ var init_Replication = __esm({
|
|
|
4484
4485
|
* @param {String} source - the DB you want to replicate or rollback to
|
|
4485
4486
|
* @param {String} target - the DB you want to replicate to, or rollback from
|
|
4486
4487
|
*/
|
|
4487
|
-
constructor({ source, target }) {
|
|
4488
|
-
this.source = getPouchDB(
|
|
4488
|
+
constructor({ source: source2, target }) {
|
|
4489
|
+
this.source = getPouchDB(source2);
|
|
4489
4490
|
this.target = getPouchDB(target);
|
|
4490
4491
|
}
|
|
4491
4492
|
close() {
|
|
@@ -4520,8 +4521,8 @@ var init_Replication = __esm({
|
|
|
4520
4521
|
}
|
|
4521
4522
|
appReplicateOpts() {
|
|
4522
4523
|
return {
|
|
4523
|
-
filter: (
|
|
4524
|
-
return
|
|
4524
|
+
filter: (doc2) => {
|
|
4525
|
+
return doc2._id !== "app_metadata" /* APP_METADATA */;
|
|
4525
4526
|
}
|
|
4526
4527
|
};
|
|
4527
4528
|
}
|
|
@@ -4702,9 +4703,9 @@ var init_lucene = __esm({
|
|
|
4702
4703
|
__privateSet(this, _indexBuilder, builderFn);
|
|
4703
4704
|
return this;
|
|
4704
4705
|
}
|
|
4705
|
-
setVersion(
|
|
4706
|
-
if (
|
|
4707
|
-
__privateSet(this, _version,
|
|
4706
|
+
setVersion(version2) {
|
|
4707
|
+
if (version2 != null) {
|
|
4708
|
+
__privateSet(this, _version, version2);
|
|
4708
4709
|
}
|
|
4709
4710
|
return this;
|
|
4710
4711
|
}
|
|
@@ -5288,36 +5289,36 @@ async function populateFromDB2(appId) {
|
|
|
5288
5289
|
{ skip_setup: true }
|
|
5289
5290
|
);
|
|
5290
5291
|
}
|
|
5291
|
-
function isInvalid(
|
|
5292
|
-
return !
|
|
5292
|
+
function isInvalid(metadata2) {
|
|
5293
|
+
return !metadata2 || metadata2.state === AppState.INVALID;
|
|
5293
5294
|
}
|
|
5294
5295
|
async function getAppMetadata(appId) {
|
|
5295
5296
|
const client3 = await getAppClient();
|
|
5296
|
-
let
|
|
5297
|
-
if (!
|
|
5297
|
+
let metadata2 = await client3.get(appId);
|
|
5298
|
+
if (!metadata2) {
|
|
5298
5299
|
let expiry = EXPIRY_SECONDS2;
|
|
5299
5300
|
try {
|
|
5300
|
-
|
|
5301
|
+
metadata2 = await populateFromDB2(appId);
|
|
5301
5302
|
} catch (err) {
|
|
5302
5303
|
if (err && err.status === 404) {
|
|
5303
|
-
|
|
5304
|
+
metadata2 = { state: AppState.INVALID };
|
|
5304
5305
|
expiry = void 0;
|
|
5305
5306
|
} else {
|
|
5306
5307
|
throw err;
|
|
5307
5308
|
}
|
|
5308
5309
|
}
|
|
5309
|
-
if (isInvalid(
|
|
5310
|
+
if (isInvalid(metadata2)) {
|
|
5310
5311
|
const temp = await client3.get(appId);
|
|
5311
5312
|
if (temp) {
|
|
5312
|
-
|
|
5313
|
+
metadata2 = temp;
|
|
5313
5314
|
}
|
|
5314
5315
|
}
|
|
5315
|
-
await client3.store(appId,
|
|
5316
|
+
await client3.store(appId, metadata2, expiry);
|
|
5316
5317
|
}
|
|
5317
|
-
if (isInvalid(
|
|
5318
|
+
if (isInvalid(metadata2)) {
|
|
5318
5319
|
throw { status: 404, message: "No app metadata found" };
|
|
5319
5320
|
}
|
|
5320
|
-
return
|
|
5321
|
+
return metadata2;
|
|
5321
5322
|
}
|
|
5322
5323
|
async function invalidateAppMetadata(appId, newMetadata) {
|
|
5323
5324
|
if (!appId) {
|
|
@@ -5356,18 +5357,18 @@ async function getCache() {
|
|
|
5356
5357
|
function makeCacheKey(db2, key) {
|
|
5357
5358
|
return db2.name + key;
|
|
5358
5359
|
}
|
|
5359
|
-
function makeCacheItem(
|
|
5360
|
-
return { doc, lastWrite: lastWrite || Date.now() };
|
|
5360
|
+
function makeCacheItem(doc2, lastWrite = null) {
|
|
5361
|
+
return { doc: doc2, lastWrite: lastWrite || Date.now() };
|
|
5361
5362
|
}
|
|
5362
|
-
async function put(db2,
|
|
5363
|
-
const
|
|
5364
|
-
const key =
|
|
5363
|
+
async function put(db2, doc2, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
5364
|
+
const cache3 = await getCache();
|
|
5365
|
+
const key = doc2._id;
|
|
5365
5366
|
let cacheItem;
|
|
5366
5367
|
if (key) {
|
|
5367
|
-
cacheItem = await
|
|
5368
|
+
cacheItem = await cache3.get(makeCacheKey(db2, key));
|
|
5368
5369
|
}
|
|
5369
5370
|
const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs;
|
|
5370
|
-
let output =
|
|
5371
|
+
let output = doc2;
|
|
5371
5372
|
if (updateDb) {
|
|
5372
5373
|
const lockResponse = await doWithLock(
|
|
5373
5374
|
{
|
|
@@ -5380,13 +5381,13 @@ async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
|
5380
5381
|
const writeDb = async (toWrite) => {
|
|
5381
5382
|
const response2 = await db2.put(toWrite, { force: true });
|
|
5382
5383
|
output = {
|
|
5383
|
-
...
|
|
5384
|
+
...doc2,
|
|
5384
5385
|
_id: response2.id,
|
|
5385
5386
|
_rev: response2.rev
|
|
5386
5387
|
};
|
|
5387
5388
|
};
|
|
5388
5389
|
try {
|
|
5389
|
-
await writeDb(
|
|
5390
|
+
await writeDb(doc2);
|
|
5390
5391
|
} catch (err) {
|
|
5391
5392
|
if (err.status !== 409) {
|
|
5392
5393
|
throw err;
|
|
@@ -5402,32 +5403,32 @@ async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
|
5402
5403
|
}
|
|
5403
5404
|
cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
|
|
5404
5405
|
if (output._id) {
|
|
5405
|
-
await
|
|
5406
|
+
await cache3.store(makeCacheKey(db2, output._id), cacheItem);
|
|
5406
5407
|
}
|
|
5407
5408
|
return { ok: true, id: output._id, rev: output._rev };
|
|
5408
5409
|
}
|
|
5409
5410
|
async function get2(db2, id) {
|
|
5410
|
-
const
|
|
5411
|
+
const cache3 = await getCache();
|
|
5411
5412
|
const cacheKey = makeCacheKey(db2, id);
|
|
5412
|
-
let cacheItem = await
|
|
5413
|
+
let cacheItem = await cache3.get(cacheKey);
|
|
5413
5414
|
if (!cacheItem) {
|
|
5414
|
-
const
|
|
5415
|
-
cacheItem = makeCacheItem(
|
|
5416
|
-
await
|
|
5415
|
+
const doc2 = await db2.get(id);
|
|
5416
|
+
cacheItem = makeCacheItem(doc2);
|
|
5417
|
+
await cache3.store(cacheKey, cacheItem);
|
|
5417
5418
|
}
|
|
5418
5419
|
return cacheItem.doc;
|
|
5419
5420
|
}
|
|
5420
|
-
async function remove(db2, docOrId,
|
|
5421
|
-
const
|
|
5421
|
+
async function remove(db2, docOrId, rev2) {
|
|
5422
|
+
const cache3 = await getCache();
|
|
5422
5423
|
if (!docOrId) {
|
|
5423
5424
|
throw new Error("No ID/Rev provided.");
|
|
5424
5425
|
}
|
|
5425
5426
|
const id = typeof docOrId === "string" ? docOrId : docOrId._id;
|
|
5426
|
-
|
|
5427
|
+
rev2 = typeof docOrId === "string" ? rev2 : docOrId._rev;
|
|
5427
5428
|
try {
|
|
5428
|
-
await
|
|
5429
|
+
await cache3.delete(makeCacheKey(db2, id));
|
|
5429
5430
|
} finally {
|
|
5430
|
-
await db2.remove(id,
|
|
5431
|
+
await db2.remove(id, rev2);
|
|
5431
5432
|
}
|
|
5432
5433
|
}
|
|
5433
5434
|
var DEFAULT_WRITE_RATE_MS, CACHE, Writethrough;
|
|
@@ -5445,14 +5446,14 @@ var init_writethrough = __esm({
|
|
|
5445
5446
|
this.db = db2;
|
|
5446
5447
|
this.writeRateMs = writeRateMs;
|
|
5447
5448
|
}
|
|
5448
|
-
async put(
|
|
5449
|
-
return put(this.db,
|
|
5449
|
+
async put(doc2) {
|
|
5450
|
+
return put(this.db, doc2, this.writeRateMs);
|
|
5450
5451
|
}
|
|
5451
5452
|
async get(id) {
|
|
5452
5453
|
return get2(this.db, id);
|
|
5453
5454
|
}
|
|
5454
|
-
async remove(docOrId,
|
|
5455
|
-
return remove(this.db, docOrId,
|
|
5455
|
+
async remove(docOrId, rev2) {
|
|
5456
|
+
return remove(this.db, docOrId, rev2);
|
|
5456
5457
|
}
|
|
5457
5458
|
};
|
|
5458
5459
|
}
|
|
@@ -5951,7 +5952,7 @@ var init_LoggingProcessor = __esm({
|
|
|
5951
5952
|
});
|
|
5952
5953
|
|
|
5953
5954
|
// ../backend-core/src/utils/hashing.ts
|
|
5954
|
-
async function
|
|
5955
|
+
async function hash2(data2) {
|
|
5955
5956
|
const salt = await bcrypt.genSalt(SALT_ROUNDS);
|
|
5956
5957
|
return bcrypt.hash(data2, salt);
|
|
5957
5958
|
}
|
|
@@ -6065,14 +6066,14 @@ function isValidInternalAPIKey(apiKey) {
|
|
|
6065
6066
|
}
|
|
6066
6067
|
return false;
|
|
6067
6068
|
}
|
|
6068
|
-
function getCookie(ctx,
|
|
6069
|
-
const cookie = ctx.cookies.get(
|
|
6069
|
+
function getCookie(ctx, name2) {
|
|
6070
|
+
const cookie = ctx.cookies.get(name2);
|
|
6070
6071
|
if (!cookie) {
|
|
6071
6072
|
return cookie;
|
|
6072
6073
|
}
|
|
6073
6074
|
return openJwt(cookie);
|
|
6074
6075
|
}
|
|
6075
|
-
function setCookie(ctx, value,
|
|
6076
|
+
function setCookie(ctx, value, name2 = "builder", opts = { sign: true }) {
|
|
6076
6077
|
if (value && opts && opts.sign) {
|
|
6077
6078
|
value = jwt.sign(value, environment_default2.JWT_SECRET);
|
|
6078
6079
|
}
|
|
@@ -6085,10 +6086,10 @@ function setCookie(ctx, value, name = "builder", opts = { sign: true }) {
|
|
|
6085
6086
|
if (environment_default2.COOKIE_DOMAIN) {
|
|
6086
6087
|
config.domain = environment_default2.COOKIE_DOMAIN;
|
|
6087
6088
|
}
|
|
6088
|
-
ctx.cookies.set(
|
|
6089
|
+
ctx.cookies.set(name2, value, config);
|
|
6089
6090
|
}
|
|
6090
|
-
function clearCookie(ctx,
|
|
6091
|
-
setCookie(ctx, null,
|
|
6091
|
+
function clearCookie(ctx, name2) {
|
|
6092
|
+
setCookie(ctx, null, name2);
|
|
6092
6093
|
}
|
|
6093
6094
|
function isClient(ctx) {
|
|
6094
6095
|
return ctx.headers["x-budibase-type" /* TYPE */] === "client";
|
|
@@ -6136,7 +6137,7 @@ __export(utils_exports2, {
|
|
|
6136
6137
|
compare: () => compare,
|
|
6137
6138
|
getAppIdFromCtx: () => getAppIdFromCtx,
|
|
6138
6139
|
getCookie: () => getCookie,
|
|
6139
|
-
hash: () =>
|
|
6140
|
+
hash: () => hash2,
|
|
6140
6141
|
isAudited: () => isAudited,
|
|
6141
6142
|
isClient: () => isClient,
|
|
6142
6143
|
isPublicApiRequest: () => isPublicApiRequest,
|
|
@@ -6179,8 +6180,8 @@ var init_inMemoryQueue = __esm({
|
|
|
6179
6180
|
* @param {object|null} opts This is not used by the in memory queue as there is no real use
|
|
6180
6181
|
* case when in memory, but is the same API as Bull
|
|
6181
6182
|
*/
|
|
6182
|
-
constructor(
|
|
6183
|
-
this._name =
|
|
6183
|
+
constructor(name2, opts = null) {
|
|
6184
|
+
this._name = name2;
|
|
6184
6185
|
this._opts = opts;
|
|
6185
6186
|
this._messages = [];
|
|
6186
6187
|
this._emitter = new import_events2.default.EventEmitter();
|
|
@@ -6677,13 +6678,13 @@ var init_installation = __esm({
|
|
|
6677
6678
|
}
|
|
6678
6679
|
);
|
|
6679
6680
|
};
|
|
6680
|
-
updateVersion = async (
|
|
6681
|
+
updateVersion = async (version2) => {
|
|
6681
6682
|
try {
|
|
6682
6683
|
await doWithDB(
|
|
6683
6684
|
StaticDatabases.PLATFORM_INFO.name,
|
|
6684
6685
|
async (platformDb) => {
|
|
6685
6686
|
const install = await getInstall();
|
|
6686
|
-
install.version =
|
|
6687
|
+
install.version = version2;
|
|
6687
6688
|
await platformDb.put(install);
|
|
6688
6689
|
await bustCache("installation" /* INSTALLATION */);
|
|
6689
6690
|
}
|
|
@@ -6799,13 +6800,13 @@ var init_identification2 = __esm({
|
|
|
6799
6800
|
const id = installId;
|
|
6800
6801
|
const type = "installation" /* INSTALLATION */;
|
|
6801
6802
|
const hosting = getHostingFromEnv();
|
|
6802
|
-
const
|
|
6803
|
+
const version2 = environment_default2.VERSION;
|
|
6803
6804
|
const environment3 = getDeploymentEnvironment();
|
|
6804
6805
|
const group2 = {
|
|
6805
6806
|
id,
|
|
6806
6807
|
type,
|
|
6807
6808
|
hosting,
|
|
6808
|
-
version,
|
|
6809
|
+
version: version2,
|
|
6809
6810
|
environment: environment3
|
|
6810
6811
|
};
|
|
6811
6812
|
await identifyGroup(group2, timestamp);
|
|
@@ -6985,10 +6986,10 @@ var init_backfill2 = __esm({
|
|
|
6985
6986
|
init_generic();
|
|
6986
6987
|
init_generic();
|
|
6987
6988
|
start = async (events2) => {
|
|
6988
|
-
const
|
|
6989
|
+
const metadata2 = {
|
|
6989
6990
|
eventWhitelist: events2
|
|
6990
6991
|
};
|
|
6991
|
-
return saveBackfillMetadata(
|
|
6992
|
+
return saveBackfillMetadata(metadata2);
|
|
6992
6993
|
};
|
|
6993
6994
|
recordEvent2 = async (event, properties) => {
|
|
6994
6995
|
const eventKey2 = getEventKey(event, properties);
|
|
@@ -7338,11 +7339,11 @@ var init_app5 = __esm({
|
|
|
7338
7339
|
});
|
|
7339
7340
|
|
|
7340
7341
|
// ../backend-core/src/events/publishers/auth.ts
|
|
7341
|
-
async function login(
|
|
7342
|
+
async function login(source2, email) {
|
|
7342
7343
|
const identity = await identification_default.getCurrentIdentity();
|
|
7343
7344
|
const properties = {
|
|
7344
7345
|
userId: identity.id,
|
|
7345
|
-
source,
|
|
7346
|
+
source: source2,
|
|
7346
7347
|
audited: {
|
|
7347
7348
|
email
|
|
7348
7349
|
}
|
|
@@ -8222,9 +8223,9 @@ var init_view3 = __esm({
|
|
|
8222
8223
|
});
|
|
8223
8224
|
|
|
8224
8225
|
// ../backend-core/src/events/publishers/installation.ts
|
|
8225
|
-
async function versionChecked(
|
|
8226
|
+
async function versionChecked(version2) {
|
|
8226
8227
|
const properties = {
|
|
8227
|
-
currentVersion:
|
|
8228
|
+
currentVersion: version2
|
|
8228
8229
|
};
|
|
8229
8230
|
await publishEvent("installation:version:checked" /* INSTALLATION_VERSION_CHECKED */, properties);
|
|
8230
8231
|
}
|
|
@@ -8467,13 +8468,13 @@ async function appBackupRestored(backup) {
|
|
|
8467
8468
|
};
|
|
8468
8469
|
await publishEvent("app:backup:restored" /* APP_BACKUP_RESTORED */, properties);
|
|
8469
8470
|
}
|
|
8470
|
-
async function appBackupTriggered(appId, backupId, type, trigger,
|
|
8471
|
+
async function appBackupTriggered(appId, backupId, type, trigger, name2) {
|
|
8471
8472
|
const properties = {
|
|
8472
8473
|
appId,
|
|
8473
8474
|
backupId,
|
|
8474
8475
|
type,
|
|
8475
8476
|
trigger,
|
|
8476
|
-
name
|
|
8477
|
+
name: name2
|
|
8477
8478
|
};
|
|
8478
8479
|
await publishEvent("app:backup:triggered" /* APP_BACKUP_TRIGGERED */, properties);
|
|
8479
8480
|
}
|
|
@@ -8490,16 +8491,16 @@ var init_backup4 = __esm({
|
|
|
8490
8491
|
});
|
|
8491
8492
|
|
|
8492
8493
|
// ../backend-core/src/events/publishers/environmentVariable.ts
|
|
8493
|
-
async function created14(
|
|
8494
|
+
async function created14(name2, environments) {
|
|
8494
8495
|
const properties = {
|
|
8495
|
-
name,
|
|
8496
|
+
name: name2,
|
|
8496
8497
|
environments
|
|
8497
8498
|
};
|
|
8498
8499
|
await publishEvent("environment_variable:created" /* ENVIRONMENT_VARIABLE_CREATED */, properties);
|
|
8499
8500
|
}
|
|
8500
|
-
async function deleted14(
|
|
8501
|
+
async function deleted14(name2) {
|
|
8501
8502
|
const properties = {
|
|
8502
|
-
name
|
|
8503
|
+
name: name2
|
|
8503
8504
|
};
|
|
8504
8505
|
await publishEvent("environment_variable:deleted" /* ENVIRONMENT_VARIABLE_DELETED */, properties);
|
|
8505
8506
|
}
|
|
@@ -8878,7 +8879,7 @@ var init_users4 = __esm({
|
|
|
8878
8879
|
let userList, property = "_id", getKey;
|
|
8879
8880
|
if (appId) {
|
|
8880
8881
|
userList = await searchGlobalUsersByApp(appId, opts);
|
|
8881
|
-
getKey = (
|
|
8882
|
+
getKey = (doc2) => getGlobalUserByAppPage(appId, doc2);
|
|
8882
8883
|
} else if (email) {
|
|
8883
8884
|
userList = await searchGlobalUsersByEmail(email, opts);
|
|
8884
8885
|
property = "email";
|
|
@@ -9028,7 +9029,7 @@ function lowerBuiltinRoleID(roleId1, roleId2) {
|
|
|
9028
9029
|
}
|
|
9029
9030
|
return builtinRoleToNumber(roleId1) > builtinRoleToNumber(roleId2) ? roleId2 : roleId1;
|
|
9030
9031
|
}
|
|
9031
|
-
async function getRole(roleId) {
|
|
9032
|
+
async function getRole(roleId, opts) {
|
|
9032
9033
|
if (!roleId) {
|
|
9033
9034
|
return void 0;
|
|
9034
9035
|
}
|
|
@@ -9044,6 +9045,9 @@ async function getRole(roleId) {
|
|
|
9044
9045
|
role = Object.assign(role, dbRole);
|
|
9045
9046
|
role._id = getExternalRoleID(role._id);
|
|
9046
9047
|
} catch (err) {
|
|
9048
|
+
if (!isBuiltin(roleId) && (opts == null ? void 0 : opts.defaultPublic)) {
|
|
9049
|
+
return cloneDeep2(BUILTIN_ROLES.PUBLIC);
|
|
9050
|
+
}
|
|
9047
9051
|
if (Object.keys(role).length === 0) {
|
|
9048
9052
|
throw err;
|
|
9049
9053
|
}
|
|
@@ -9183,10 +9187,10 @@ var init_roles = __esm({
|
|
|
9183
9187
|
BUILTIN_IDS.PUBLIC
|
|
9184
9188
|
];
|
|
9185
9189
|
Role2 = class {
|
|
9186
|
-
constructor(id,
|
|
9190
|
+
constructor(id, name2, permissionId) {
|
|
9187
9191
|
this.permissions = {};
|
|
9188
9192
|
this._id = id;
|
|
9189
|
-
this.name =
|
|
9193
|
+
this.name = name2;
|
|
9190
9194
|
this.permissionId = permissionId;
|
|
9191
9195
|
}
|
|
9192
9196
|
addInheritance(inherits) {
|
|
@@ -9552,12 +9556,12 @@ async function syncUser(user, details) {
|
|
|
9552
9556
|
if (details.profile) {
|
|
9553
9557
|
const profile = details.profile;
|
|
9554
9558
|
if (profile.name) {
|
|
9555
|
-
const
|
|
9556
|
-
if (
|
|
9557
|
-
firstName =
|
|
9559
|
+
const name2 = profile.name;
|
|
9560
|
+
if (name2.givenName) {
|
|
9561
|
+
firstName = name2.givenName;
|
|
9558
9562
|
}
|
|
9559
|
-
if (
|
|
9560
|
-
lastName =
|
|
9563
|
+
if (name2.familyName) {
|
|
9564
|
+
lastName = name2.familyName;
|
|
9561
9565
|
}
|
|
9562
9566
|
}
|
|
9563
9567
|
pictureUrl = await getProfilePictureUrl(user, details);
|
|
@@ -9784,8 +9788,8 @@ async function preAuth(passport2, ctx, next) {
|
|
|
9784
9788
|
callbackUrl,
|
|
9785
9789
|
ssoSaveUserNoOp
|
|
9786
9790
|
);
|
|
9787
|
-
if (!ctx.query.appId
|
|
9788
|
-
ctx.throw(400, "appId
|
|
9791
|
+
if (!ctx.query.appId) {
|
|
9792
|
+
ctx.throw(400, "appId query param not present.");
|
|
9789
9793
|
}
|
|
9790
9794
|
return passport2.authenticate(strategy, {
|
|
9791
9795
|
scope: ["profile", "email", "https://www.googleapis.com/auth/spreadsheets"],
|
|
@@ -9805,7 +9809,7 @@ async function postAuth(passport2, ctx, next) {
|
|
|
9805
9809
|
clientSecret: config.clientSecret,
|
|
9806
9810
|
callbackURL: callbackUrl
|
|
9807
9811
|
},
|
|
9808
|
-
(accessToken, refreshToken,
|
|
9812
|
+
(accessToken, refreshToken, _profile, done) => {
|
|
9809
9813
|
clearCookie(ctx, "budibase:datasourceauth" /* DatasourceAuth */);
|
|
9810
9814
|
done(null, { accessToken, refreshToken });
|
|
9811
9815
|
}
|
|
@@ -9813,22 +9817,14 @@ async function postAuth(passport2, ctx, next) {
|
|
|
9813
9817
|
{ successRedirect: "/", failureRedirect: "/error" },
|
|
9814
9818
|
async (err, tokens) => {
|
|
9815
9819
|
const baseUrl = `/builder/app/${authStateCookie.appId}/data`;
|
|
9816
|
-
|
|
9817
|
-
|
|
9818
|
-
|
|
9819
|
-
|
|
9820
|
-
|
|
9821
|
-
if (err2.status === 404) {
|
|
9822
|
-
ctx.redirect(baseUrl);
|
|
9823
|
-
}
|
|
9824
|
-
}
|
|
9825
|
-
if (!datasource2.config) {
|
|
9826
|
-
datasource2.config = {};
|
|
9820
|
+
const id = newid();
|
|
9821
|
+
await store(
|
|
9822
|
+
`datasource:creation:${authStateCookie.appId}:google:${id}`,
|
|
9823
|
+
{
|
|
9824
|
+
tokens
|
|
9827
9825
|
}
|
|
9828
|
-
|
|
9829
|
-
|
|
9830
|
-
ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
|
|
9831
|
-
});
|
|
9826
|
+
);
|
|
9827
|
+
ctx.redirect(`${baseUrl}/new?continue_google_setup=${id}`);
|
|
9832
9828
|
}
|
|
9833
9829
|
)(ctx, next);
|
|
9834
9830
|
}
|
|
@@ -9837,9 +9833,9 @@ var init_google2 = __esm({
|
|
|
9837
9833
|
"../backend-core/src/middleware/passport/datasource/google.ts"() {
|
|
9838
9834
|
init_google();
|
|
9839
9835
|
init_constants2();
|
|
9840
|
-
init_utils5();
|
|
9841
|
-
init_db5();
|
|
9842
9836
|
init_configs3();
|
|
9837
|
+
init_cache();
|
|
9838
|
+
init_utils5();
|
|
9843
9839
|
init_sso2();
|
|
9844
9840
|
GoogleStrategy2 = require("passport-google-oauth").OAuth2Strategy;
|
|
9845
9841
|
}
|
|
@@ -9889,7 +9885,9 @@ var encryption_exports = {};
|
|
|
9889
9885
|
__export(encryption_exports, {
|
|
9890
9886
|
SecretOption: () => SecretOption,
|
|
9891
9887
|
decrypt: () => decrypt,
|
|
9888
|
+
decryptFile: () => decryptFile,
|
|
9892
9889
|
encrypt: () => encrypt,
|
|
9890
|
+
encryptFile: () => encryptFile,
|
|
9893
9891
|
getSecret: () => getSecret
|
|
9894
9892
|
});
|
|
9895
9893
|
function getSecret(secretOption) {
|
|
@@ -9910,11 +9908,11 @@ function getSecret(secretOption) {
|
|
|
9910
9908
|
}
|
|
9911
9909
|
return secret;
|
|
9912
9910
|
}
|
|
9913
|
-
function stretchString(
|
|
9914
|
-
return import_crypto.default.pbkdf2Sync(
|
|
9911
|
+
function stretchString(secret, salt) {
|
|
9912
|
+
return import_crypto.default.pbkdf2Sync(secret, salt, ITERATIONS, STRETCH_LENGTH, "sha512");
|
|
9915
9913
|
}
|
|
9916
9914
|
function encrypt(input, secretOption = "api" /* API */) {
|
|
9917
|
-
const salt = import_crypto.default.randomBytes(
|
|
9915
|
+
const salt = import_crypto.default.randomBytes(SALT_LENGTH);
|
|
9918
9916
|
const stretched = stretchString(getSecret(secretOption), salt);
|
|
9919
9917
|
const cipher = import_crypto.default.createCipheriv(ALGO, stretched, salt);
|
|
9920
9918
|
const base = cipher.update(input);
|
|
@@ -9931,16 +9929,101 @@ function decrypt(input, secretOption = "api" /* API */) {
|
|
|
9931
9929
|
const final = decipher.final();
|
|
9932
9930
|
return Buffer.concat([base, final]).toString();
|
|
9933
9931
|
}
|
|
9934
|
-
|
|
9932
|
+
async function encryptFile({ dir, filename }, secret) {
|
|
9933
|
+
const outputFileName = `${filename}.enc`;
|
|
9934
|
+
const filePath = (0, import_path2.join)(dir, filename);
|
|
9935
|
+
const inputFile = import_fs2.default.createReadStream(filePath);
|
|
9936
|
+
const outputFile = import_fs2.default.createWriteStream((0, import_path2.join)(dir, outputFileName));
|
|
9937
|
+
const salt = import_crypto.default.randomBytes(SALT_LENGTH);
|
|
9938
|
+
const iv = import_crypto.default.randomBytes(IV_LENGTH);
|
|
9939
|
+
const stretched = stretchString(secret, salt);
|
|
9940
|
+
const cipher = import_crypto.default.createCipheriv(ALGO, stretched, iv);
|
|
9941
|
+
outputFile.write(salt);
|
|
9942
|
+
outputFile.write(iv);
|
|
9943
|
+
inputFile.pipe(import_zlib.default.createGzip()).pipe(cipher).pipe(outputFile);
|
|
9944
|
+
return new Promise((r) => {
|
|
9945
|
+
outputFile.on("finish", () => {
|
|
9946
|
+
r({
|
|
9947
|
+
filename: outputFileName,
|
|
9948
|
+
dir
|
|
9949
|
+
});
|
|
9950
|
+
});
|
|
9951
|
+
});
|
|
9952
|
+
}
|
|
9953
|
+
async function getSaltAndIV(path2) {
|
|
9954
|
+
const fileStream = import_fs2.default.createReadStream(path2);
|
|
9955
|
+
const salt = await readBytes(fileStream, SALT_LENGTH);
|
|
9956
|
+
const iv = await readBytes(fileStream, IV_LENGTH);
|
|
9957
|
+
fileStream.close();
|
|
9958
|
+
return { salt, iv };
|
|
9959
|
+
}
|
|
9960
|
+
async function decryptFile(inputPath, outputPath, secret) {
|
|
9961
|
+
const { salt, iv } = await getSaltAndIV(inputPath);
|
|
9962
|
+
const inputFile = import_fs2.default.createReadStream(inputPath, {
|
|
9963
|
+
start: SALT_LENGTH + IV_LENGTH
|
|
9964
|
+
});
|
|
9965
|
+
const outputFile = import_fs2.default.createWriteStream(outputPath);
|
|
9966
|
+
const stretched = stretchString(secret, salt);
|
|
9967
|
+
const decipher = import_crypto.default.createDecipheriv(ALGO, stretched, iv);
|
|
9968
|
+
const unzip = import_zlib.default.createGunzip();
|
|
9969
|
+
inputFile.pipe(decipher).pipe(unzip).pipe(outputFile);
|
|
9970
|
+
return new Promise((res, rej) => {
|
|
9971
|
+
outputFile.on("finish", () => {
|
|
9972
|
+
outputFile.close();
|
|
9973
|
+
res();
|
|
9974
|
+
});
|
|
9975
|
+
inputFile.on("error", (e) => {
|
|
9976
|
+
outputFile.close();
|
|
9977
|
+
rej(e);
|
|
9978
|
+
});
|
|
9979
|
+
decipher.on("error", (e) => {
|
|
9980
|
+
outputFile.close();
|
|
9981
|
+
rej(e);
|
|
9982
|
+
});
|
|
9983
|
+
unzip.on("error", (e) => {
|
|
9984
|
+
outputFile.close();
|
|
9985
|
+
rej(e);
|
|
9986
|
+
});
|
|
9987
|
+
outputFile.on("error", (e) => {
|
|
9988
|
+
outputFile.close();
|
|
9989
|
+
rej(e);
|
|
9990
|
+
});
|
|
9991
|
+
});
|
|
9992
|
+
}
|
|
9993
|
+
function readBytes(stream3, length) {
|
|
9994
|
+
return new Promise((resolve3, reject) => {
|
|
9995
|
+
let bytesRead = 0;
|
|
9996
|
+
const data2 = [];
|
|
9997
|
+
stream3.on("readable", () => {
|
|
9998
|
+
let chunk;
|
|
9999
|
+
while ((chunk = stream3.read(length - bytesRead)) !== null) {
|
|
10000
|
+
data2.push(chunk);
|
|
10001
|
+
bytesRead += chunk.length;
|
|
10002
|
+
}
|
|
10003
|
+
resolve3(Buffer.concat(data2));
|
|
10004
|
+
});
|
|
10005
|
+
stream3.on("end", () => {
|
|
10006
|
+
reject(new Error("Insufficient data in the stream."));
|
|
10007
|
+
});
|
|
10008
|
+
stream3.on("error", (error) => {
|
|
10009
|
+
reject(error);
|
|
10010
|
+
});
|
|
10011
|
+
});
|
|
10012
|
+
}
|
|
10013
|
+
var import_crypto, import_fs2, import_zlib, import_path2, ALGO, SEPARATOR3, ITERATIONS, STRETCH_LENGTH, SALT_LENGTH, IV_LENGTH, SecretOption;
|
|
9935
10014
|
var init_encryption = __esm({
|
|
9936
10015
|
"../backend-core/src/security/encryption.ts"() {
|
|
9937
10016
|
import_crypto = __toESM(require("crypto"));
|
|
10017
|
+
import_fs2 = __toESM(require("fs"));
|
|
10018
|
+
import_zlib = __toESM(require("zlib"));
|
|
9938
10019
|
init_environment3();
|
|
10020
|
+
import_path2 = require("path");
|
|
9939
10021
|
ALGO = "aes-256-ctr";
|
|
9940
10022
|
SEPARATOR3 = "-";
|
|
9941
10023
|
ITERATIONS = 1e4;
|
|
9942
|
-
RANDOM_BYTES = 16;
|
|
9943
10024
|
STRETCH_LENGTH = 32;
|
|
10025
|
+
SALT_LENGTH = 16;
|
|
10026
|
+
IV_LENGTH = 16;
|
|
9944
10027
|
SecretOption = /* @__PURE__ */ ((SecretOption2) => {
|
|
9945
10028
|
SecretOption2["API"] = "api";
|
|
9946
10029
|
SecretOption2["ENCRYPTION"] = "encryption";
|
|
@@ -10073,7 +10156,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
|
|
|
10073
10156
|
const noAuthOptions = noAuthPatterns ? buildMatcherRegex(noAuthPatterns) : [];
|
|
10074
10157
|
return async (ctx, next) => {
|
|
10075
10158
|
let publicEndpoint = false;
|
|
10076
|
-
const
|
|
10159
|
+
const version2 = ctx.request.headers["x-budibase-api-version" /* API_VER */];
|
|
10077
10160
|
const found = matches(ctx, noAuthOptions);
|
|
10078
10161
|
if (found) {
|
|
10079
10162
|
publicEndpoint = true;
|
|
@@ -10136,7 +10219,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
|
|
|
10136
10219
|
if (!authenticated) {
|
|
10137
10220
|
authenticated = false;
|
|
10138
10221
|
}
|
|
10139
|
-
finalise(ctx, { authenticated, user, internal, version, publicEndpoint });
|
|
10222
|
+
finalise(ctx, { authenticated, user, internal, version: version2, publicEndpoint });
|
|
10140
10223
|
if (user && user.email) {
|
|
10141
10224
|
return doInUserContext(user, ctx, next);
|
|
10142
10225
|
} else {
|
|
@@ -10151,7 +10234,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
|
|
|
10151
10234
|
ctx.throw(403, err.message);
|
|
10152
10235
|
}
|
|
10153
10236
|
if (opts && opts.publicAllowed || publicEndpoint) {
|
|
10154
|
-
finalise(ctx, { authenticated: false, version, publicEndpoint });
|
|
10237
|
+
finalise(ctx, { authenticated: false, version: version2, publicEndpoint });
|
|
10155
10238
|
return next();
|
|
10156
10239
|
} else {
|
|
10157
10240
|
ctx.throw(err.status || 403, err);
|
|
@@ -10851,12 +10934,12 @@ var init_plugin4 = __esm({
|
|
|
10851
10934
|
function budibaseTempDir() {
|
|
10852
10935
|
return bbTmp;
|
|
10853
10936
|
}
|
|
10854
|
-
var
|
|
10937
|
+
var import_path3, import_os, import_fs3, ObjectStoreBuckets, bbTmp;
|
|
10855
10938
|
var init_utils8 = __esm({
|
|
10856
10939
|
"../backend-core/src/objectStore/utils.ts"() {
|
|
10857
|
-
|
|
10940
|
+
import_path3 = require("path");
|
|
10858
10941
|
import_os = require("os");
|
|
10859
|
-
|
|
10942
|
+
import_fs3 = __toESM(require("fs"));
|
|
10860
10943
|
init_environment3();
|
|
10861
10944
|
ObjectStoreBuckets = {
|
|
10862
10945
|
BACKUPS: environment_default2.BACKUPS_BUCKET_NAME,
|
|
@@ -10865,9 +10948,9 @@ var init_utils8 = __esm({
|
|
|
10865
10948
|
GLOBAL: environment_default2.GLOBAL_BUCKET_NAME,
|
|
10866
10949
|
PLUGINS: environment_default2.PLUGIN_BUCKET_NAME
|
|
10867
10950
|
};
|
|
10868
|
-
bbTmp = (0,
|
|
10869
|
-
if (!
|
|
10870
|
-
|
|
10951
|
+
bbTmp = (0, import_path3.join)((0, import_os.tmpdir)(), ".budibase");
|
|
10952
|
+
if (!import_fs3.default.existsSync(bbTmp)) {
|
|
10953
|
+
import_fs3.default.mkdirSync(bbTmp);
|
|
10871
10954
|
}
|
|
10872
10955
|
}
|
|
10873
10956
|
});
|
|
@@ -10879,17 +10962,17 @@ function sanitizeKey(input) {
|
|
|
10879
10962
|
function sanitizeBucket(input) {
|
|
10880
10963
|
return input.replace(new RegExp(APP_DEV_PREFIX, "g"), APP_PREFIX);
|
|
10881
10964
|
}
|
|
10882
|
-
var import_aws_sdk, import_stream, import_node_fetch6, import_tar_fs,
|
|
10965
|
+
var import_aws_sdk, import_stream, import_node_fetch6, import_tar_fs, import_zlib2, import_util, import_path4, import_fs4, import_uuid3, sanitize, streamPipeline, STATE, CONTENT_TYPE_MAP, STRING_CONTENT_TYPES, ObjectStore, makeSureBucketExists, upload, streamUpload, retrieve, listAllObjects, getPresignedUrl, retrieveToTmp, retrieveDirectory, deleteFile, deleteFiles, deleteFolder, uploadDirectory, downloadTarballDirect, downloadTarball;
|
|
10883
10966
|
var init_objectStore = __esm({
|
|
10884
10967
|
"../backend-core/src/objectStore/objectStore.ts"() {
|
|
10885
10968
|
import_aws_sdk = __toESM(require("aws-sdk"));
|
|
10886
10969
|
import_stream = __toESM(require("stream"));
|
|
10887
10970
|
import_node_fetch6 = __toESM(require("node-fetch"));
|
|
10888
10971
|
import_tar_fs = __toESM(require("tar-fs"));
|
|
10889
|
-
|
|
10972
|
+
import_zlib2 = __toESM(require("zlib"));
|
|
10890
10973
|
import_util = require("util");
|
|
10891
|
-
|
|
10892
|
-
|
|
10974
|
+
import_path4 = require("path");
|
|
10975
|
+
import_fs4 = __toESM(require("fs"));
|
|
10893
10976
|
init_environment3();
|
|
10894
10977
|
init_utils8();
|
|
10895
10978
|
import_uuid3 = require("uuid");
|
|
@@ -10965,10 +11048,10 @@ var init_objectStore = __esm({
|
|
|
10965
11048
|
filename,
|
|
10966
11049
|
path: path2,
|
|
10967
11050
|
type,
|
|
10968
|
-
metadata
|
|
11051
|
+
metadata: metadata2
|
|
10969
11052
|
}) => {
|
|
10970
11053
|
const extension = filename.split(".").pop();
|
|
10971
|
-
const fileBytes =
|
|
11054
|
+
const fileBytes = import_fs4.default.readFileSync(path2);
|
|
10972
11055
|
const objectStore = ObjectStore(bucketName);
|
|
10973
11056
|
await makeSureBucketExists(objectStore, bucketName);
|
|
10974
11057
|
let contentType = type;
|
|
@@ -10981,13 +11064,13 @@ var init_objectStore = __esm({
|
|
|
10981
11064
|
Body: fileBytes,
|
|
10982
11065
|
ContentType: contentType
|
|
10983
11066
|
};
|
|
10984
|
-
if (
|
|
10985
|
-
for (let key of Object.keys(
|
|
10986
|
-
if (!
|
|
10987
|
-
delete
|
|
11067
|
+
if (metadata2 && typeof metadata2 === "object") {
|
|
11068
|
+
for (let key of Object.keys(metadata2)) {
|
|
11069
|
+
if (!metadata2[key] || typeof metadata2[key] !== "string") {
|
|
11070
|
+
delete metadata2[key];
|
|
10988
11071
|
}
|
|
10989
11072
|
}
|
|
10990
|
-
config.Metadata =
|
|
11073
|
+
config.Metadata = metadata2;
|
|
10991
11074
|
}
|
|
10992
11075
|
return objectStore.upload(config).promise();
|
|
10993
11076
|
};
|
|
@@ -11070,13 +11153,13 @@ var init_objectStore = __esm({
|
|
|
11070
11153
|
bucketName = sanitizeBucket(bucketName);
|
|
11071
11154
|
filepath = sanitizeKey(filepath);
|
|
11072
11155
|
const data2 = await retrieve(bucketName, filepath);
|
|
11073
|
-
const outputPath = (0,
|
|
11074
|
-
|
|
11156
|
+
const outputPath = (0, import_path4.join)(budibaseTempDir(), (0, import_uuid3.v4)());
|
|
11157
|
+
import_fs4.default.writeFileSync(outputPath, data2);
|
|
11075
11158
|
return outputPath;
|
|
11076
11159
|
};
|
|
11077
11160
|
retrieveDirectory = async (bucketName, path2) => {
|
|
11078
|
-
let writePath = (0,
|
|
11079
|
-
|
|
11161
|
+
let writePath = (0, import_path4.join)(budibaseTempDir(), (0, import_uuid3.v4)());
|
|
11162
|
+
import_fs4.default.mkdirSync(writePath);
|
|
11080
11163
|
const objects = await listAllObjects(bucketName, path2);
|
|
11081
11164
|
let fullObjects = await Promise.all(
|
|
11082
11165
|
objects.map((obj) => retrieve(bucketName, obj.Key))
|
|
@@ -11088,9 +11171,9 @@ var init_objectStore = __esm({
|
|
|
11088
11171
|
const possiblePath = filename.split("/");
|
|
11089
11172
|
if (possiblePath.length > 1) {
|
|
11090
11173
|
const dirs = possiblePath.slice(0, possiblePath.length - 1);
|
|
11091
|
-
|
|
11174
|
+
import_fs4.default.mkdirSync((0, import_path4.join)(writePath, ...dirs), { recursive: true });
|
|
11092
11175
|
}
|
|
11093
|
-
|
|
11176
|
+
import_fs4.default.writeFileSync((0, import_path4.join)(writePath, ...possiblePath), data2);
|
|
11094
11177
|
}
|
|
11095
11178
|
return writePath;
|
|
11096
11179
|
};
|
|
@@ -11141,21 +11224,21 @@ var init_objectStore = __esm({
|
|
|
11141
11224
|
return deleteFolder(bucketName, folder);
|
|
11142
11225
|
}
|
|
11143
11226
|
};
|
|
11144
|
-
uploadDirectory = async (bucketName, localPath,
|
|
11227
|
+
uploadDirectory = async (bucketName, localPath, bucketPath2) => {
|
|
11145
11228
|
bucketName = sanitizeBucket(bucketName);
|
|
11146
11229
|
let uploads = [];
|
|
11147
|
-
const
|
|
11148
|
-
for (let file of
|
|
11149
|
-
const path2 = sanitizeKey((0,
|
|
11150
|
-
const local = (0,
|
|
11230
|
+
const files2 = import_fs4.default.readdirSync(localPath, { withFileTypes: true });
|
|
11231
|
+
for (let file of files2) {
|
|
11232
|
+
const path2 = sanitizeKey((0, import_path4.join)(bucketPath2, file.name));
|
|
11233
|
+
const local = (0, import_path4.join)(localPath, file.name);
|
|
11151
11234
|
if (file.isDirectory()) {
|
|
11152
11235
|
uploads.push(uploadDirectory(bucketName, local, path2));
|
|
11153
11236
|
} else {
|
|
11154
|
-
uploads.push(streamUpload(bucketName, path2,
|
|
11237
|
+
uploads.push(streamUpload(bucketName, path2, import_fs4.default.createReadStream(local)));
|
|
11155
11238
|
}
|
|
11156
11239
|
}
|
|
11157
11240
|
await Promise.all(uploads);
|
|
11158
|
-
return
|
|
11241
|
+
return files2;
|
|
11159
11242
|
};
|
|
11160
11243
|
downloadTarballDirect = async (url, path2, headers = {}) => {
|
|
11161
11244
|
path2 = sanitizeKey(path2);
|
|
@@ -11163,7 +11246,7 @@ var init_objectStore = __esm({
|
|
|
11163
11246
|
if (!response2.ok) {
|
|
11164
11247
|
throw new Error(`unexpected response ${response2.statusText}`);
|
|
11165
11248
|
}
|
|
11166
|
-
await streamPipeline(response2.body,
|
|
11249
|
+
await streamPipeline(response2.body, import_zlib2.default.createUnzip(), import_tar_fs.default.extract(path2));
|
|
11167
11250
|
};
|
|
11168
11251
|
downloadTarball = async (url, bucketName, path2) => {
|
|
11169
11252
|
bucketName = sanitizeBucket(bucketName);
|
|
@@ -11172,8 +11255,8 @@ var init_objectStore = __esm({
|
|
|
11172
11255
|
if (!response2.ok) {
|
|
11173
11256
|
throw new Error(`unexpected response ${response2.statusText}`);
|
|
11174
11257
|
}
|
|
11175
|
-
const tmpPath = (0,
|
|
11176
|
-
await streamPipeline(response2.body,
|
|
11258
|
+
const tmpPath = (0, import_path4.join)(budibaseTempDir(), path2);
|
|
11259
|
+
await streamPipeline(response2.body, import_zlib2.default.createUnzip(), import_tar_fs.default.extract(tmpPath));
|
|
11177
11260
|
if (!environment_default2.isTest() && environment_default2.SELF_HOSTED) {
|
|
11178
11261
|
await uploadDirectory(bucketName, tmpPath, path2);
|
|
11179
11262
|
}
|
|
@@ -11229,12 +11312,12 @@ var init_app6 = __esm({
|
|
|
11229
11312
|
init_environment3();
|
|
11230
11313
|
init_objectStore();
|
|
11231
11314
|
init_cloudfront();
|
|
11232
|
-
clientLibraryUrl = (appId,
|
|
11315
|
+
clientLibraryUrl = (appId, version2) => {
|
|
11233
11316
|
if (environment_default2.isProd()) {
|
|
11234
11317
|
let file = `${sanitizeKey(appId)}/budibase-client.js`;
|
|
11235
11318
|
if (environment_default2.CLOUDFRONT_CDN) {
|
|
11236
|
-
if (
|
|
11237
|
-
file += `?v=${
|
|
11319
|
+
if (version2) {
|
|
11320
|
+
file += `?v=${version2}`;
|
|
11238
11321
|
}
|
|
11239
11322
|
return getUrl(file);
|
|
11240
11323
|
} else {
|
|
@@ -11262,8 +11345,8 @@ var init_global3 = __esm({
|
|
|
11262
11345
|
init_context2();
|
|
11263
11346
|
init_objectStore();
|
|
11264
11347
|
init_cloudfront();
|
|
11265
|
-
getGlobalFileUrl = (type,
|
|
11266
|
-
let file = getGlobalFileS3Key(type,
|
|
11348
|
+
getGlobalFileUrl = (type, name2, etag) => {
|
|
11349
|
+
let file = getGlobalFileS3Key(type, name2);
|
|
11267
11350
|
if (environment_default2.CLOUDFRONT_CDN) {
|
|
11268
11351
|
if (etag) {
|
|
11269
11352
|
file = `${file}?etag=${etag}`;
|
|
@@ -11273,8 +11356,8 @@ var init_global3 = __esm({
|
|
|
11273
11356
|
return getPresignedUrl(environment_default2.GLOBAL_BUCKET_NAME, file);
|
|
11274
11357
|
}
|
|
11275
11358
|
};
|
|
11276
|
-
getGlobalFileS3Key = (type,
|
|
11277
|
-
let file = `${type}/${
|
|
11359
|
+
getGlobalFileS3Key = (type, name2) => {
|
|
11360
|
+
let file = `${type}/${name2}`;
|
|
11278
11361
|
if (environment_default2.MULTI_TENANCY) {
|
|
11279
11362
|
const tenantId = getTenantId();
|
|
11280
11363
|
file = `${tenantId}/${file}`;
|
|
@@ -11324,11 +11407,11 @@ var init_plugins = __esm({
|
|
|
11324
11407
|
return getPluginS3Key(plugin, "plugin.min.js");
|
|
11325
11408
|
};
|
|
11326
11409
|
getPluginIconKey = (plugin) => {
|
|
11327
|
-
const
|
|
11328
|
-
if (!
|
|
11410
|
+
const iconFileName2 = plugin.iconUrl ? "icon.svg" : plugin.iconFileName;
|
|
11411
|
+
if (!iconFileName2) {
|
|
11329
11412
|
return;
|
|
11330
11413
|
}
|
|
11331
|
-
return getPluginS3Key(plugin,
|
|
11414
|
+
return getPluginS3Key(plugin, iconFileName2);
|
|
11332
11415
|
};
|
|
11333
11416
|
getPluginS3Key = (plugin, fileName) => {
|
|
11334
11417
|
const s3Key = getPluginS3Dir(plugin.name);
|
|
@@ -11759,11 +11842,11 @@ var init_utils9 = __esm({
|
|
|
11759
11842
|
}
|
|
11760
11843
|
usage.monthly.current = usage.monthly[currentMonth];
|
|
11761
11844
|
};
|
|
11762
|
-
getBreakdownName = (
|
|
11763
|
-
if (!id || !
|
|
11845
|
+
getBreakdownName = (name2, id) => {
|
|
11846
|
+
if (!id || !name2) {
|
|
11764
11847
|
return;
|
|
11765
11848
|
}
|
|
11766
|
-
switch (
|
|
11849
|
+
switch (name2) {
|
|
11767
11850
|
case "automations" /* AUTOMATIONS */:
|
|
11768
11851
|
return "automations" /* AUTOMATIONS */;
|
|
11769
11852
|
case "queries" /* QUERIES */:
|
|
@@ -11825,17 +11908,17 @@ var init_quotas2 = __esm({
|
|
|
11825
11908
|
delete usage.usageQuota.developers;
|
|
11826
11909
|
return usage;
|
|
11827
11910
|
};
|
|
11828
|
-
setUsage = async (value,
|
|
11829
|
-
return setAllUsage(
|
|
11911
|
+
setUsage = async (value, name2, type) => {
|
|
11912
|
+
return setAllUsage(name2, type, { total: value });
|
|
11830
11913
|
};
|
|
11831
|
-
setUsagePerApp = async (appValues,
|
|
11914
|
+
setUsagePerApp = async (appValues, name2, type) => {
|
|
11832
11915
|
const db2 = getDB2();
|
|
11833
11916
|
let quotaUsage = await getQuotaUsage();
|
|
11834
11917
|
const total = Object.values(appValues).reduce((sum, num) => sum + num, 0);
|
|
11835
11918
|
for (let [appId, value] of Object.entries(appValues)) {
|
|
11836
11919
|
quotaUsage = coreUsageUpdate(
|
|
11837
11920
|
quotaUsage,
|
|
11838
|
-
|
|
11921
|
+
name2,
|
|
11839
11922
|
type,
|
|
11840
11923
|
{
|
|
11841
11924
|
total,
|
|
@@ -11850,8 +11933,8 @@ var init_quotas2 = __esm({
|
|
|
11850
11933
|
quotaUsage._rev = response2.rev;
|
|
11851
11934
|
return quotaUsage;
|
|
11852
11935
|
};
|
|
11853
|
-
setBreakdown = (monthUsage,
|
|
11854
|
-
const breakdownName = getBreakdownName(
|
|
11936
|
+
setBreakdown = (monthUsage, name2, id, values) => {
|
|
11937
|
+
const breakdownName = getBreakdownName(name2, id);
|
|
11855
11938
|
if (!breakdownName || !(values == null ? void 0 : values.breakdown)) {
|
|
11856
11939
|
return monthUsage;
|
|
11857
11940
|
}
|
|
@@ -11860,7 +11943,7 @@ var init_quotas2 = __esm({
|
|
|
11860
11943
|
}
|
|
11861
11944
|
if (!monthUsage.breakdown[breakdownName]) {
|
|
11862
11945
|
monthUsage.breakdown[breakdownName] = {
|
|
11863
|
-
parent:
|
|
11946
|
+
parent: name2,
|
|
11864
11947
|
values: {}
|
|
11865
11948
|
};
|
|
11866
11949
|
}
|
|
@@ -11868,14 +11951,14 @@ var init_quotas2 = __esm({
|
|
|
11868
11951
|
breakdown.values[id] = values.breakdown;
|
|
11869
11952
|
return monthUsage;
|
|
11870
11953
|
};
|
|
11871
|
-
setAppUsageValue = (quotaUsage,
|
|
11954
|
+
setAppUsageValue = (quotaUsage, name2, type, opts = {}, values) => {
|
|
11872
11955
|
var _a;
|
|
11873
11956
|
let appId;
|
|
11874
11957
|
try {
|
|
11875
11958
|
appId = db_exports.getProdAppID((opts == null ? void 0 : opts.appId) || context_exports.getAppId());
|
|
11876
11959
|
} catch (err) {
|
|
11877
11960
|
}
|
|
11878
|
-
if (!appId || !values.app || !APP_QUOTA_NAMES.includes(
|
|
11961
|
+
if (!appId || !values.app || !APP_QUOTA_NAMES.includes(name2)) {
|
|
11879
11962
|
return quotaUsage;
|
|
11880
11963
|
}
|
|
11881
11964
|
if (!((_a = quotaUsage.apps) == null ? void 0 : _a[appId])) {
|
|
@@ -11887,11 +11970,11 @@ var init_quotas2 = __esm({
|
|
|
11887
11970
|
const appUsage = quotaUsage.apps[appId];
|
|
11888
11971
|
switch (type) {
|
|
11889
11972
|
case "static" /* STATIC */:
|
|
11890
|
-
appUsage.usageQuota[
|
|
11973
|
+
appUsage.usageQuota[name2] = values.app;
|
|
11891
11974
|
break;
|
|
11892
11975
|
case "monthly" /* MONTHLY */:
|
|
11893
11976
|
const currentMonth = getCurrentMonthString();
|
|
11894
|
-
const monthlyName =
|
|
11977
|
+
const monthlyName = name2;
|
|
11895
11978
|
let monthUsage = appUsage.monthly[currentMonth];
|
|
11896
11979
|
if (!monthUsage) {
|
|
11897
11980
|
appUsage.monthly[currentMonth] = generateNewMonthlyQuotas();
|
|
@@ -11905,9 +11988,9 @@ var init_quotas2 = __esm({
|
|
|
11905
11988
|
}
|
|
11906
11989
|
return quotaUsage;
|
|
11907
11990
|
};
|
|
11908
|
-
getAppUsageValue = (quotaUsage, type,
|
|
11991
|
+
getAppUsageValue = (quotaUsage, type, name2, id) => {
|
|
11909
11992
|
var _a, _b, _c, _d, _e;
|
|
11910
|
-
if (!APP_QUOTA_NAMES.includes(
|
|
11993
|
+
if (!APP_QUOTA_NAMES.includes(name2)) {
|
|
11911
11994
|
return {};
|
|
11912
11995
|
}
|
|
11913
11996
|
let appId;
|
|
@@ -11921,13 +12004,13 @@ var init_quotas2 = __esm({
|
|
|
11921
12004
|
const appUsage = quotaUsage.apps[appId];
|
|
11922
12005
|
switch (type) {
|
|
11923
12006
|
case "static" /* STATIC */:
|
|
11924
|
-
if ((_a = appUsage.usageQuota) == null ? void 0 : _a[
|
|
11925
|
-
return { app: appUsage.usageQuota[
|
|
12007
|
+
if ((_a = appUsage.usageQuota) == null ? void 0 : _a[name2]) {
|
|
12008
|
+
return { app: appUsage.usageQuota[name2] };
|
|
11926
12009
|
}
|
|
11927
12010
|
break;
|
|
11928
12011
|
case "monthly" /* MONTHLY */:
|
|
11929
12012
|
const currentMonth = getCurrentMonthString();
|
|
11930
|
-
const monthlyName =
|
|
12013
|
+
const monthlyName = name2;
|
|
11931
12014
|
if (!((_c = (_b = appUsage.monthly) == null ? void 0 : _b[currentMonth]) == null ? void 0 : _c[monthlyName])) {
|
|
11932
12015
|
break;
|
|
11933
12016
|
}
|
|
@@ -11942,68 +12025,68 @@ var init_quotas2 = __esm({
|
|
|
11942
12025
|
}
|
|
11943
12026
|
return { app: 0 };
|
|
11944
12027
|
};
|
|
11945
|
-
setStaticTriggers = (
|
|
12028
|
+
setStaticTriggers = (name2, quotaUsage, triggers) => {
|
|
11946
12029
|
if (!quotaUsage.usageQuota.triggers) {
|
|
11947
12030
|
quotaUsage.usageQuota.triggers = {};
|
|
11948
12031
|
}
|
|
11949
12032
|
if (triggers) {
|
|
11950
|
-
quotaUsage.usageQuota.triggers[
|
|
12033
|
+
quotaUsage.usageQuota.triggers[name2] = triggers;
|
|
11951
12034
|
}
|
|
11952
12035
|
};
|
|
11953
|
-
setMonthlyTriggers = (
|
|
12036
|
+
setMonthlyTriggers = (name2, currentMonth, quotaUsage, triggers) => {
|
|
11954
12037
|
if (!quotaUsage.monthly[currentMonth].triggers) {
|
|
11955
12038
|
quotaUsage.monthly[currentMonth].triggers = {};
|
|
11956
12039
|
}
|
|
11957
12040
|
if (triggers) {
|
|
11958
|
-
quotaUsage.monthly[currentMonth].triggers[
|
|
12041
|
+
quotaUsage.monthly[currentMonth].triggers[name2] = triggers;
|
|
11959
12042
|
}
|
|
11960
12043
|
};
|
|
11961
|
-
coreUsageUpdate = (quotaUsage,
|
|
12044
|
+
coreUsageUpdate = (quotaUsage, name2, type, values, opts = {}) => {
|
|
11962
12045
|
if (type === "static" /* STATIC */) {
|
|
11963
|
-
|
|
11964
|
-
quotaUsage.usageQuota[
|
|
11965
|
-
setStaticTriggers(
|
|
12046
|
+
name2 = name2;
|
|
12047
|
+
quotaUsage.usageQuota[name2] = values.total;
|
|
12048
|
+
setStaticTriggers(name2, quotaUsage, values.triggers);
|
|
11966
12049
|
} else if (type === "monthly" /* MONTHLY */) {
|
|
11967
|
-
|
|
12050
|
+
name2 = name2;
|
|
11968
12051
|
const currentMonth = getCurrentMonthString();
|
|
11969
|
-
quotaUsage.monthly[currentMonth][
|
|
11970
|
-
setMonthlyTriggers(
|
|
12052
|
+
quotaUsage.monthly[currentMonth][name2] = values.total;
|
|
12053
|
+
setMonthlyTriggers(name2, currentMonth, quotaUsage, values.triggers);
|
|
11971
12054
|
} else {
|
|
11972
12055
|
throw new Error(`Invalid usage type: ${type}`);
|
|
11973
12056
|
}
|
|
11974
|
-
return setAppUsageValue(quotaUsage,
|
|
12057
|
+
return setAppUsageValue(quotaUsage, name2, type, opts, values);
|
|
11975
12058
|
};
|
|
11976
|
-
setAllUsage = async (
|
|
12059
|
+
setAllUsage = async (name2, type, values, opts = {}) => {
|
|
11977
12060
|
const db2 = getDB2();
|
|
11978
12061
|
let quotaUsage = await getQuotaUsage();
|
|
11979
|
-
quotaUsage = coreUsageUpdate(quotaUsage,
|
|
12062
|
+
quotaUsage = coreUsageUpdate(quotaUsage, name2, type, values, opts);
|
|
11980
12063
|
const response2 = await db2.put(quotaUsage);
|
|
11981
12064
|
quotaUsage._rev = response2.rev;
|
|
11982
12065
|
return quotaUsage;
|
|
11983
12066
|
};
|
|
11984
|
-
getCurrentUsageValues = async (type,
|
|
12067
|
+
getCurrentUsageValues = async (type, name2, id) => {
|
|
11985
12068
|
const quotaUsage = await getQuotaUsage();
|
|
11986
12069
|
let total = 0, appValues = {};
|
|
11987
12070
|
switch (type) {
|
|
11988
12071
|
case "static" /* STATIC */:
|
|
11989
|
-
if (quotaUsage.usageQuota[
|
|
11990
|
-
const staticName =
|
|
12072
|
+
if (quotaUsage.usageQuota[name2]) {
|
|
12073
|
+
const staticName = name2;
|
|
11991
12074
|
total = quotaUsage.usageQuota[staticName];
|
|
11992
|
-
appValues = getAppUsageValue(quotaUsage, type,
|
|
12075
|
+
appValues = getAppUsageValue(quotaUsage, type, name2, id);
|
|
11993
12076
|
}
|
|
11994
12077
|
break;
|
|
11995
12078
|
case "monthly" /* MONTHLY */:
|
|
11996
12079
|
const currentMonth = getCurrentMonthString();
|
|
11997
|
-
const monthlyName =
|
|
12080
|
+
const monthlyName = name2;
|
|
11998
12081
|
if (quotaUsage.monthly[currentMonth][monthlyName]) {
|
|
11999
12082
|
total = quotaUsage.monthly[currentMonth][monthlyName];
|
|
12000
|
-
appValues = getAppUsageValue(quotaUsage, type,
|
|
12083
|
+
appValues = getAppUsageValue(quotaUsage, type, name2, id);
|
|
12001
12084
|
}
|
|
12002
12085
|
break;
|
|
12003
12086
|
default:
|
|
12004
12087
|
throw new Error(`Invalid usage type: ${type}`);
|
|
12005
12088
|
}
|
|
12006
|
-
if (APP_QUOTA_NAMES.includes(
|
|
12089
|
+
if (APP_QUOTA_NAMES.includes(name2) && !(appValues.app || appValues.breakdown)) {
|
|
12007
12090
|
appValues.app = appValues.app || 0;
|
|
12008
12091
|
appValues.breakdown = appValues.breakdown || 0;
|
|
12009
12092
|
}
|
|
@@ -12225,9 +12308,9 @@ async function getGroupUsers(groupId, params2) {
|
|
|
12225
12308
|
createGroupUserLookupView,
|
|
12226
12309
|
{ arrayResponse: true }
|
|
12227
12310
|
);
|
|
12228
|
-
const users2 = userDocs.map((
|
|
12229
|
-
_id:
|
|
12230
|
-
email:
|
|
12311
|
+
const users2 = userDocs.map((doc2) => ({
|
|
12312
|
+
_id: doc2.userId,
|
|
12313
|
+
email: doc2.email
|
|
12231
12314
|
})) || [];
|
|
12232
12315
|
return users2;
|
|
12233
12316
|
}
|
|
@@ -12316,12 +12399,12 @@ async function destroy3(groupId, revision) {
|
|
|
12316
12399
|
await cleanupUsers(group2);
|
|
12317
12400
|
return resp;
|
|
12318
12401
|
}
|
|
12319
|
-
async function getByName(
|
|
12402
|
+
async function getByName(name2) {
|
|
12320
12403
|
try {
|
|
12321
12404
|
const groups = await db_exports.directCouchFind(tenancy.getGlobalDBName(), {
|
|
12322
12405
|
selector: {
|
|
12323
12406
|
name: {
|
|
12324
|
-
$regex: `^(?i)${
|
|
12407
|
+
$regex: `^(?i)${name2}$`
|
|
12325
12408
|
}
|
|
12326
12409
|
},
|
|
12327
12410
|
limit: 1
|
|
@@ -12626,21 +12709,21 @@ __export(version_exports, {
|
|
|
12626
12709
|
getLicenseVersion: () => getLicenseVersion,
|
|
12627
12710
|
getProVersion: () => getProVersion
|
|
12628
12711
|
});
|
|
12629
|
-
var
|
|
12712
|
+
var import_fs5, import_path5, getLicenseVersion, getProVersion;
|
|
12630
12713
|
var init_version2 = __esm({
|
|
12631
12714
|
"../pro/packages/pro/src/constants/version.ts"() {
|
|
12632
12715
|
init_src2();
|
|
12633
|
-
|
|
12634
|
-
|
|
12716
|
+
import_fs5 = __toESM(require("fs"));
|
|
12717
|
+
import_path5 = __toESM(require("path"));
|
|
12635
12718
|
getLicenseVersion = () => {
|
|
12636
12719
|
if (environment_default2.isDev()) {
|
|
12637
12720
|
const DEV_VER_FILENAME = "dev-version.txt";
|
|
12638
|
-
const verFile =
|
|
12639
|
-
if (
|
|
12640
|
-
return
|
|
12721
|
+
const verFile = import_path5.default.join(objectStore_exports2.budibaseTempDir(), DEV_VER_FILENAME);
|
|
12722
|
+
if (import_fs5.default.existsSync(verFile)) {
|
|
12723
|
+
return import_fs5.default.readFileSync(verFile, "utf8");
|
|
12641
12724
|
} else {
|
|
12642
12725
|
const devVer = utils_exports2.newid();
|
|
12643
|
-
|
|
12726
|
+
import_fs5.default.writeFileSync(verFile, devVer);
|
|
12644
12727
|
return devVer;
|
|
12645
12728
|
}
|
|
12646
12729
|
} else {
|
|
@@ -12648,11 +12731,11 @@ var init_version2 = __esm({
|
|
|
12648
12731
|
}
|
|
12649
12732
|
};
|
|
12650
12733
|
getProVersion = () => {
|
|
12651
|
-
const
|
|
12652
|
-
if (!
|
|
12734
|
+
const version2 = environment_default2.VERSION;
|
|
12735
|
+
if (!version2) {
|
|
12653
12736
|
throw new Error("No budibase pro version was specified");
|
|
12654
12737
|
}
|
|
12655
|
-
return
|
|
12738
|
+
return version2;
|
|
12656
12739
|
};
|
|
12657
12740
|
}
|
|
12658
12741
|
});
|
|
@@ -12796,15 +12879,15 @@ async function fetchAppBackups(appId, opts = {}) {
|
|
|
12796
12879
|
}
|
|
12797
12880
|
return pageData;
|
|
12798
12881
|
}
|
|
12799
|
-
async function storeAppBackupMetadata(
|
|
12882
|
+
async function storeAppBackupMetadata(metadata2, opts = {}) {
|
|
12800
12883
|
const db2 = tenancy.getGlobalDB();
|
|
12801
|
-
const prodAppId = db_exports.getProdAppID(
|
|
12802
|
-
let _id = generateAppBackupID(prodAppId,
|
|
12884
|
+
const prodAppId = db_exports.getProdAppID(metadata2.appId);
|
|
12885
|
+
let _id = generateAppBackupID(prodAppId, metadata2.timestamp);
|
|
12803
12886
|
const appBackupDoc = {
|
|
12804
|
-
...
|
|
12887
|
+
...metadata2,
|
|
12805
12888
|
_id,
|
|
12806
12889
|
appId: prodAppId,
|
|
12807
|
-
name:
|
|
12890
|
+
name: metadata2.name
|
|
12808
12891
|
};
|
|
12809
12892
|
if (opts.filename) {
|
|
12810
12893
|
appBackupDoc.filename = opts.filename;
|
|
@@ -12813,18 +12896,18 @@ async function storeAppBackupMetadata(metadata, opts = {}) {
|
|
|
12813
12896
|
appBackupDoc._id = opts.docId;
|
|
12814
12897
|
appBackupDoc._rev = opts.docRev;
|
|
12815
12898
|
}
|
|
12816
|
-
if (
|
|
12899
|
+
if (metadata2.createdBy) {
|
|
12817
12900
|
appBackupDoc.createdBy = db_exports.getGlobalIDFromUserMetadataID(
|
|
12818
|
-
|
|
12901
|
+
metadata2.createdBy
|
|
12819
12902
|
);
|
|
12820
12903
|
}
|
|
12821
12904
|
return await db2.put(appBackupDoc);
|
|
12822
12905
|
}
|
|
12823
|
-
async function updateAppBackupMetadata(backupId,
|
|
12906
|
+
async function updateAppBackupMetadata(backupId, name2) {
|
|
12824
12907
|
const db2 = tenancy.getGlobalDB();
|
|
12825
|
-
const
|
|
12826
|
-
|
|
12827
|
-
return await db2.put(
|
|
12908
|
+
const metadata2 = await db2.get(backupId);
|
|
12909
|
+
metadata2.name = name2;
|
|
12910
|
+
return await db2.put(metadata2);
|
|
12828
12911
|
}
|
|
12829
12912
|
async function deleteAppBackupMetadata(backupId) {
|
|
12830
12913
|
const db2 = tenancy.getGlobalDB();
|
|
@@ -12859,9 +12942,9 @@ __export(environmentVariables_exports, {
|
|
|
12859
12942
|
function getEnvVarID() {
|
|
12860
12943
|
return StaticDatabases.GLOBAL.docs.environmentVariables;
|
|
12861
12944
|
}
|
|
12862
|
-
function getCacheEnvVarID(
|
|
12945
|
+
function getCacheEnvVarID(rev2) {
|
|
12863
12946
|
const tenantId = tenancy.getTenantId();
|
|
12864
|
-
return `${tenantId}/${getEnvVarID()}/${
|
|
12947
|
+
return `${tenantId}/${getEnvVarID()}/${rev2 || ""}`;
|
|
12865
12948
|
}
|
|
12866
12949
|
async function get5() {
|
|
12867
12950
|
const id = getEnvVarID();
|
|
@@ -12901,14 +12984,14 @@ async function get5() {
|
|
|
12901
12984
|
cache.set(cacheKey, finalDoc);
|
|
12902
12985
|
return finalDoc;
|
|
12903
12986
|
}
|
|
12904
|
-
async function update(
|
|
12987
|
+
async function update(doc2) {
|
|
12905
12988
|
const id = getEnvVarID();
|
|
12906
12989
|
const db2 = tenancy.getGlobalDB();
|
|
12907
12990
|
return await db2.put({
|
|
12908
|
-
_id:
|
|
12909
|
-
_rev:
|
|
12991
|
+
_id: doc2._id || id,
|
|
12992
|
+
_rev: doc2._rev || void 0,
|
|
12910
12993
|
variables: encryption_exports.encrypt(
|
|
12911
|
-
JSON.stringify(
|
|
12994
|
+
JSON.stringify(doc2.variables),
|
|
12912
12995
|
encryption_exports.SecretOption.ENCRYPTION
|
|
12913
12996
|
)
|
|
12914
12997
|
});
|
|
@@ -13086,31 +13169,31 @@ function getOfflineLicense() {
|
|
|
13086
13169
|
}
|
|
13087
13170
|
}
|
|
13088
13171
|
function getOfflineLicenseFromDisk() {
|
|
13089
|
-
if (
|
|
13090
|
-
const token =
|
|
13172
|
+
if (import_fs6.default.existsSync(LICENSE_FILE_PATH)) {
|
|
13173
|
+
const token = import_fs6.default.readFileSync(LICENSE_FILE_PATH, { encoding: "utf-8" });
|
|
13091
13174
|
return import_jsonwebtoken.default.verify(token, PUBLIC_KEY, { algorithms: ["RS256"] });
|
|
13092
13175
|
}
|
|
13093
13176
|
}
|
|
13094
13177
|
function writeOfflineLicenseToDisk(signedLicense) {
|
|
13095
|
-
|
|
13178
|
+
import_fs6.default.writeFileSync(LICENSE_FILE_PATH, signedLicense, { encoding: "utf-8" });
|
|
13096
13179
|
}
|
|
13097
13180
|
function deleteOfflineLicense() {
|
|
13098
|
-
|
|
13181
|
+
import_fs6.default.rmSync(LICENSE_FILE_PATH, { force: true });
|
|
13099
13182
|
}
|
|
13100
|
-
var
|
|
13183
|
+
var import_fs6, import_path6, import_os2, import_jsonwebtoken, SUB_DIRECTORY, DIRECTORY, OFFLINE_LICENSE_FILE, LICENSE_FILE_PATH, PUBLIC_KEY;
|
|
13101
13184
|
var init_offline = __esm({
|
|
13102
13185
|
"../pro/packages/pro/src/sdk/licensing/licenses/offline.ts"() {
|
|
13103
|
-
|
|
13104
|
-
|
|
13186
|
+
import_fs6 = __toESM(require("fs"));
|
|
13187
|
+
import_path6 = require("path");
|
|
13105
13188
|
import_os2 = require("os");
|
|
13106
13189
|
import_jsonwebtoken = __toESM(require("jsonwebtoken"));
|
|
13107
13190
|
init_src2();
|
|
13108
13191
|
SUB_DIRECTORY = environment_default2.isTest() ? ".budibase-test" : ".budibase";
|
|
13109
|
-
DIRECTORY = (0,
|
|
13192
|
+
DIRECTORY = (0, import_path6.join)((0, import_os2.tmpdir)(), SUB_DIRECTORY);
|
|
13110
13193
|
OFFLINE_LICENSE_FILE = "offline_license.txt";
|
|
13111
|
-
LICENSE_FILE_PATH = (0,
|
|
13112
|
-
if (!
|
|
13113
|
-
|
|
13194
|
+
LICENSE_FILE_PATH = (0, import_path6.join)(DIRECTORY, OFFLINE_LICENSE_FILE);
|
|
13195
|
+
if (!import_fs6.default.existsSync(DIRECTORY)) {
|
|
13196
|
+
import_fs6.default.mkdirSync(DIRECTORY);
|
|
13114
13197
|
}
|
|
13115
13198
|
PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvz3jePLCFBXZ19c8Dpkv\nXtSgOhKFOcvQdo/LV0KJRUzQWDPWuO4ILtBtnqhjtIzZH4CH0qCYBet5L6Qr4CM1\nl2HXiAD1Q2rlHNW9wDaYyKb1F5f+v4RyqCAyzlkwRdksmkLeECTboojNnmRCrE3C\n8suunQP5bEScqEY2kclqzSf8e6xqMzPUg3mL/pNa1iEv7TuLbU9nJfgR36l0WmZY\n94fWnSaT8OSXSqcxsaByf06gfS3HAoTJNc7eqz1Hf9fUORQGPUAnFK8cT3SfdA36\nd/o3ZWE1TTj1zYwlCLN5qRKr3hU8nC3xEYNEbkB9SfTRaOq9Q7P8WmfLkoCPm3pR\nmwIDAQAB\n-----END PUBLIC KEY-----\n";
|
|
13116
13199
|
}
|
|
@@ -13391,14 +13474,14 @@ var init_quotas5 = __esm({
|
|
|
13391
13474
|
init_db6();
|
|
13392
13475
|
init_src2();
|
|
13393
13476
|
init_quotas3();
|
|
13394
|
-
increment = (
|
|
13395
|
-
return tryIncrement(1,
|
|
13477
|
+
increment = (name2, type, opts) => {
|
|
13478
|
+
return tryIncrement(1, name2, type, opts);
|
|
13396
13479
|
};
|
|
13397
|
-
incrementMany = (change,
|
|
13398
|
-
return tryIncrement(change,
|
|
13480
|
+
incrementMany = (change, name2, type, opts) => {
|
|
13481
|
+
return tryIncrement(change, name2, type, opts);
|
|
13399
13482
|
};
|
|
13400
|
-
tryIncrement = async (change,
|
|
13401
|
-
await updateUsage(change,
|
|
13483
|
+
tryIncrement = async (change, name2, type, opts = {}) => {
|
|
13484
|
+
await updateUsage(change, name2, type, {
|
|
13402
13485
|
dryRun: true,
|
|
13403
13486
|
suppressErrorLog: opts.suppressErrorLog,
|
|
13404
13487
|
id: opts.id
|
|
@@ -13407,7 +13490,7 @@ var init_quotas5 = __esm({
|
|
|
13407
13490
|
if (opts.fn) {
|
|
13408
13491
|
result = await opts.fn();
|
|
13409
13492
|
}
|
|
13410
|
-
await updateUsage(change,
|
|
13493
|
+
await updateUsage(change, name2, type, {
|
|
13411
13494
|
dryRun: false,
|
|
13412
13495
|
valueFn: opts.valueFn,
|
|
13413
13496
|
suppressErrorLog: opts.suppressErrorLog,
|
|
@@ -13415,32 +13498,32 @@ var init_quotas5 = __esm({
|
|
|
13415
13498
|
});
|
|
13416
13499
|
return result;
|
|
13417
13500
|
};
|
|
13418
|
-
decrement = (
|
|
13419
|
-
return updateUsage(-1,
|
|
13501
|
+
decrement = (name2, type, opts = {}) => {
|
|
13502
|
+
return updateUsage(-1, name2, type, opts);
|
|
13420
13503
|
};
|
|
13421
|
-
decrementMany = (change,
|
|
13422
|
-
return updateUsage(-change,
|
|
13504
|
+
decrementMany = (change, name2, type, opts = {}) => {
|
|
13505
|
+
return updateUsage(-change, name2, type, opts);
|
|
13423
13506
|
};
|
|
13424
|
-
set2 = async (
|
|
13425
|
-
return quotas_exports.setUsage(value,
|
|
13507
|
+
set2 = async (name2, type, value) => {
|
|
13508
|
+
return quotas_exports.setUsage(value, name2, type);
|
|
13426
13509
|
};
|
|
13427
|
-
getExistingTriggers = (type,
|
|
13510
|
+
getExistingTriggers = (type, name2, quotaUsage) => {
|
|
13428
13511
|
if (type == "static" /* STATIC */) {
|
|
13429
13512
|
const triggers = quotaUsage.usageQuota.triggers;
|
|
13430
|
-
return triggers ? triggers[
|
|
13513
|
+
return triggers ? triggers[name2] || {} : {};
|
|
13431
13514
|
} else {
|
|
13432
13515
|
const currentMonthString = quotas_exports.utils.getCurrentMonthString();
|
|
13433
13516
|
const triggers = quotaUsage.monthly[currentMonthString].triggers;
|
|
13434
|
-
return triggers ? triggers[
|
|
13517
|
+
return triggers ? triggers[name2] || {} : {};
|
|
13435
13518
|
}
|
|
13436
13519
|
};
|
|
13437
|
-
triggerQuota2 = async (
|
|
13520
|
+
triggerQuota2 = async (name2, quota, percentage, resetDate) => {
|
|
13438
13521
|
try {
|
|
13439
13522
|
await redlockImpl_exports.doWithLock(
|
|
13440
13523
|
{
|
|
13441
13524
|
type: "try_once" /* TRY_ONCE */,
|
|
13442
13525
|
name: "trigger_quota" /* TRIGGER_QUOTA */,
|
|
13443
|
-
resource:
|
|
13526
|
+
resource: name2,
|
|
13444
13527
|
// use the quota name for extra uniqueness on the lock
|
|
13445
13528
|
ttl: 1e4
|
|
13446
13529
|
// auto expire after 10 seconds
|
|
@@ -13460,10 +13543,10 @@ var init_quotas5 = __esm({
|
|
|
13460
13543
|
logging_exports.logAlert("Error triggering quota", e);
|
|
13461
13544
|
}
|
|
13462
13545
|
};
|
|
13463
|
-
checkTriggers = async (type,
|
|
13546
|
+
checkTriggers = async (type, name2, totalValue, quota) => {
|
|
13464
13547
|
const usage = await getQuotaUsage();
|
|
13465
13548
|
const resetDate = type === "monthly" /* MONTHLY */ ? usage.quotaReset : void 0;
|
|
13466
|
-
const triggers = await getExistingTriggers(type,
|
|
13549
|
+
const triggers = await getExistingTriggers(type, name2, usage);
|
|
13467
13550
|
const quotaTriggers = quota.triggers;
|
|
13468
13551
|
let percentage = totalValue / quota.value * 100;
|
|
13469
13552
|
if (percentage > 100) {
|
|
@@ -13479,7 +13562,7 @@ var init_quotas5 = __esm({
|
|
|
13479
13562
|
const isAtTrigger = percentage === triggerPercentage;
|
|
13480
13563
|
const sendNotification = !nextIsTriggered || isAtTrigger;
|
|
13481
13564
|
if (sendNotification) {
|
|
13482
|
-
await triggerQuota2(
|
|
13565
|
+
await triggerQuota2(name2, quota, percentage, resetDate);
|
|
13483
13566
|
}
|
|
13484
13567
|
}
|
|
13485
13568
|
} else {
|
|
@@ -13488,23 +13571,23 @@ var init_quotas5 = __esm({
|
|
|
13488
13571
|
}
|
|
13489
13572
|
return triggers;
|
|
13490
13573
|
};
|
|
13491
|
-
updateUsage = async (usageChange,
|
|
13574
|
+
updateUsage = async (usageChange, name2, type, opts = {}) => {
|
|
13492
13575
|
let appId = null;
|
|
13493
13576
|
try {
|
|
13494
13577
|
appId = context_exports.getAppId();
|
|
13495
13578
|
} catch (err) {
|
|
13496
13579
|
}
|
|
13497
|
-
const isAppQuota = APP_QUOTA_NAMES.includes(
|
|
13580
|
+
const isAppQuota = APP_QUOTA_NAMES.includes(name2);
|
|
13498
13581
|
if (isAppQuota && !appId) {
|
|
13499
13582
|
throw new Error("App context required for quota update");
|
|
13500
13583
|
}
|
|
13501
13584
|
try {
|
|
13502
|
-
const licensedQuota = await getLicensedQuota("usage" /* USAGE */,
|
|
13585
|
+
const licensedQuota = await getLicensedQuota("usage" /* USAGE */, name2, type);
|
|
13503
13586
|
let {
|
|
13504
13587
|
total: totalValue,
|
|
13505
13588
|
app: appValue,
|
|
13506
13589
|
breakdown: breakdownValue
|
|
13507
|
-
} = await quotas_exports.getCurrentUsageValues(type,
|
|
13590
|
+
} = await quotas_exports.getCurrentUsageValues(type, name2, opts.id);
|
|
13508
13591
|
totalValue += usageChange;
|
|
13509
13592
|
if (appValue != null) {
|
|
13510
13593
|
appValue += usageChange;
|
|
@@ -13514,7 +13597,7 @@ var init_quotas5 = __esm({
|
|
|
13514
13597
|
}
|
|
13515
13598
|
let triggers = {};
|
|
13516
13599
|
if (!opts.dryRun) {
|
|
13517
|
-
triggers = await checkTriggers(type,
|
|
13600
|
+
triggers = await checkTriggers(type, name2, totalValue, licensedQuota);
|
|
13518
13601
|
}
|
|
13519
13602
|
if (licensedQuota.value !== quotas_exports2.UNLIMITED && totalValue > licensedQuota.value && usageChange > 0) {
|
|
13520
13603
|
throw new UsageLimitError(
|
|
@@ -13537,7 +13620,7 @@ var init_quotas5 = __esm({
|
|
|
13537
13620
|
appValue = totalValue;
|
|
13538
13621
|
}
|
|
13539
13622
|
await quotas_exports.setAllUsage(
|
|
13540
|
-
|
|
13623
|
+
name2,
|
|
13541
13624
|
type,
|
|
13542
13625
|
{
|
|
13543
13626
|
total: totalValue,
|
|
@@ -13549,30 +13632,30 @@ var init_quotas5 = __esm({
|
|
|
13549
13632
|
);
|
|
13550
13633
|
} catch (err) {
|
|
13551
13634
|
if (!opts.suppressErrorLog) {
|
|
13552
|
-
console.error(`Error updating usage quotas for ${
|
|
13635
|
+
console.error(`Error updating usage quotas for ${name2}`, err);
|
|
13553
13636
|
}
|
|
13554
13637
|
throw err;
|
|
13555
13638
|
}
|
|
13556
13639
|
};
|
|
13557
|
-
getLicensedQuota = async (quotaType,
|
|
13640
|
+
getLicensedQuota = async (quotaType, name2, usageType) => {
|
|
13558
13641
|
const license = await cache_exports2.getCachedLicense();
|
|
13559
13642
|
if (!license) {
|
|
13560
13643
|
const tenantId = tenancy.getTenantId();
|
|
13561
13644
|
throw new Error("License not found for tenant id " + tenantId);
|
|
13562
13645
|
}
|
|
13563
|
-
if (usageType && isStaticQuota(quotaType, usageType,
|
|
13564
|
-
return license.quotas[quotaType][usageType][
|
|
13565
|
-
} else if (usageType && isMonthlyQuota(quotaType, usageType,
|
|
13566
|
-
return license.quotas[quotaType][usageType][
|
|
13567
|
-
} else if (isConstantQuota(quotaType,
|
|
13568
|
-
return license.quotas[quotaType][
|
|
13646
|
+
if (usageType && isStaticQuota(quotaType, usageType, name2)) {
|
|
13647
|
+
return license.quotas[quotaType][usageType][name2];
|
|
13648
|
+
} else if (usageType && isMonthlyQuota(quotaType, usageType, name2)) {
|
|
13649
|
+
return license.quotas[quotaType][usageType][name2];
|
|
13650
|
+
} else if (isConstantQuota(quotaType, name2)) {
|
|
13651
|
+
return license.quotas[quotaType][name2];
|
|
13569
13652
|
} else {
|
|
13570
13653
|
throw new Error("Invalid quota type");
|
|
13571
13654
|
}
|
|
13572
13655
|
};
|
|
13573
|
-
usageLimitIsExceeded = async (
|
|
13656
|
+
usageLimitIsExceeded = async (name2, type) => {
|
|
13574
13657
|
try {
|
|
13575
|
-
await updateUsage(1,
|
|
13658
|
+
await updateUsage(1, name2, type, { dryRun: true });
|
|
13576
13659
|
return false;
|
|
13577
13660
|
} catch (e) {
|
|
13578
13661
|
if (e.code === "usage_limit_exceeded" /* USAGE_LIMIT_EXCEEDED */) {
|
|
@@ -14111,7 +14194,7 @@ async function getLogsByView(startDate, endDate, viewParams = {}) {
|
|
|
14111
14194
|
async function writeLog(automation, results) {
|
|
14112
14195
|
const db2 = context_exports.getProdAppDB();
|
|
14113
14196
|
const automationId = automation._id;
|
|
14114
|
-
const
|
|
14197
|
+
const name2 = automation.name;
|
|
14115
14198
|
const status2 = getStatus(results);
|
|
14116
14199
|
const isoDate = (/* @__PURE__ */ new Date()).toISOString();
|
|
14117
14200
|
const id = generateAutomationLogID(isoDate, status2, automationId);
|
|
@@ -14120,7 +14203,7 @@ async function writeLog(automation, results) {
|
|
|
14120
14203
|
...results,
|
|
14121
14204
|
automationId,
|
|
14122
14205
|
status: status2,
|
|
14123
|
-
automationName:
|
|
14206
|
+
automationName: name2,
|
|
14124
14207
|
createdAt: isoDate,
|
|
14125
14208
|
_id: id
|
|
14126
14209
|
};
|
|
@@ -14130,13 +14213,13 @@ async function writeLog(automation, results) {
|
|
|
14130
14213
|
async function updateAppMetadataWithErrors(logIds, { clearing } = { clearing: false }) {
|
|
14131
14214
|
const db2 = context_exports.getProdAppDB();
|
|
14132
14215
|
await backOff(async () => {
|
|
14133
|
-
const
|
|
14216
|
+
const metadata2 = await db2.get(db_exports.DocumentType.APP_METADATA);
|
|
14134
14217
|
for (let logId of logIds) {
|
|
14135
14218
|
const parts = logId.split(db_exports.SEPARATOR);
|
|
14136
14219
|
const autoId = `${parts[parts.length - 3]}${db_exports.SEPARATOR}${parts[parts.length - 2]}`;
|
|
14137
14220
|
let errors = {};
|
|
14138
|
-
if (
|
|
14139
|
-
errors =
|
|
14221
|
+
if (metadata2.automationErrors) {
|
|
14222
|
+
errors = metadata2.automationErrors;
|
|
14140
14223
|
}
|
|
14141
14224
|
if (!Array.isArray(errors[autoId])) {
|
|
14142
14225
|
errors[autoId] = [];
|
|
@@ -14150,10 +14233,10 @@ async function updateAppMetadataWithErrors(logIds, { clearing } = { clearing: fa
|
|
|
14150
14233
|
if (errors[autoId].length === 0) {
|
|
14151
14234
|
delete errors[autoId];
|
|
14152
14235
|
}
|
|
14153
|
-
|
|
14236
|
+
metadata2.automationErrors = errors;
|
|
14154
14237
|
}
|
|
14155
|
-
await db2.put(
|
|
14156
|
-
await cache_exports.app.invalidateAppMetadata(
|
|
14238
|
+
await db2.put(metadata2);
|
|
14239
|
+
await cache_exports.app.invalidateAppMetadata(metadata2.appId, metadata2);
|
|
14157
14240
|
}, "Failed to update app metadata with automation log error");
|
|
14158
14241
|
}
|
|
14159
14242
|
async function getExpiredLogs() {
|
|
@@ -14175,16 +14258,16 @@ async function clearOldHistory() {
|
|
|
14175
14258
|
if (!expired.data || expired.data.length === 0) {
|
|
14176
14259
|
return;
|
|
14177
14260
|
}
|
|
14178
|
-
const toDelete = expired.data.map((
|
|
14179
|
-
_id:
|
|
14180
|
-
_rev:
|
|
14261
|
+
const toDelete = expired.data.map((doc2) => ({
|
|
14262
|
+
_id: doc2.id,
|
|
14263
|
+
_rev: doc2.value.rev,
|
|
14181
14264
|
_deleted: true
|
|
14182
14265
|
}));
|
|
14183
|
-
const errorLogIds = expired.data.filter((
|
|
14184
|
-
const parts =
|
|
14266
|
+
const errorLogIds = expired.data.filter((doc2) => {
|
|
14267
|
+
const parts = doc2.id.split(db_exports.SEPARATOR);
|
|
14185
14268
|
const status2 = parts[parts.length - 1];
|
|
14186
14269
|
return status2 === "error" /* ERROR */;
|
|
14187
|
-
}).map((
|
|
14270
|
+
}).map((doc2) => doc2.id);
|
|
14188
14271
|
await db2.bulkDocs(toDelete);
|
|
14189
14272
|
if (errorLogIds.length) {
|
|
14190
14273
|
await updateAppMetadataWithErrors(errorLogIds, { clearing: true });
|
|
@@ -14404,10 +14487,10 @@ async function get6(id) {
|
|
|
14404
14487
|
async function getBulk2(ids, opts = { enriched: true }) {
|
|
14405
14488
|
return await groups_exports.getBulk(ids, opts);
|
|
14406
14489
|
}
|
|
14407
|
-
async function guardNameAvailility(
|
|
14408
|
-
const existingGroup = await groups_exports.getByName(
|
|
14490
|
+
async function guardNameAvailility(name2) {
|
|
14491
|
+
const existingGroup = await groups_exports.getByName(name2);
|
|
14409
14492
|
if (existingGroup) {
|
|
14410
|
-
throw new GroupNameUnavailableError(
|
|
14493
|
+
throw new GroupNameUnavailableError(name2);
|
|
14411
14494
|
}
|
|
14412
14495
|
}
|
|
14413
14496
|
async function save4(group2) {
|
|
@@ -14566,14 +14649,14 @@ var init_groups6 = __esm({
|
|
|
14566
14649
|
});
|
|
14567
14650
|
|
|
14568
14651
|
// ../pro/packages/pro/src/utilities/fileSystem.ts
|
|
14569
|
-
function loadJSFile(
|
|
14570
|
-
return
|
|
14652
|
+
function loadJSFile(directory2, name2) {
|
|
14653
|
+
return import_fs7.default.readFileSync((0, import_path7.join)(directory2, name2), "utf8");
|
|
14571
14654
|
}
|
|
14572
|
-
var
|
|
14655
|
+
var import_fs7, import_path7;
|
|
14573
14656
|
var init_fileSystem = __esm({
|
|
14574
14657
|
"../pro/packages/pro/src/utilities/fileSystem.ts"() {
|
|
14575
|
-
|
|
14576
|
-
|
|
14658
|
+
import_fs7 = __toESM(require("fs"));
|
|
14659
|
+
import_path7 = require("path");
|
|
14577
14660
|
}
|
|
14578
14661
|
});
|
|
14579
14662
|
|
|
@@ -14585,8 +14668,8 @@ __export(plugins_exports, {
|
|
|
14585
14668
|
storePlugin: () => storePlugin
|
|
14586
14669
|
});
|
|
14587
14670
|
async function storePlugin(metadata, directory, source) {
|
|
14588
|
-
const
|
|
14589
|
-
const version = metadata.package.version, name = metadata.package.name, description = metadata.package.description,
|
|
14671
|
+
const db = tenancy.getGlobalDB();
|
|
14672
|
+
const version = metadata.package.version, name = metadata.package.name, description = metadata.package.description, hash = metadata.schema.hash;
|
|
14590
14673
|
const bucketPath = objectStore_exports2.getPluginS3Dir(name);
|
|
14591
14674
|
const files = await objectStore_exports2.uploadDirectory(
|
|
14592
14675
|
objectStore_exports2.ObjectStoreBuckets.PLUGINS,
|
|
@@ -14601,8 +14684,7 @@ async function storePlugin(metadata, directory, source) {
|
|
|
14601
14684
|
if (metadata.schema.type === "datasource" /* DATASOURCE */) {
|
|
14602
14685
|
const js = loadJSFile(directory, jsFile.name);
|
|
14603
14686
|
try {
|
|
14604
|
-
;
|
|
14605
|
-
(0, eval)(js);
|
|
14687
|
+
eval(js);
|
|
14606
14688
|
} catch (err) {
|
|
14607
14689
|
const message = (err == null ? void 0 : err.message) ? err.message : JSON.stringify(err);
|
|
14608
14690
|
throw new Error(`JS invalid: ${message}`);
|
|
@@ -14612,7 +14694,7 @@ async function storePlugin(metadata, directory, source) {
|
|
|
14612
14694
|
const pluginId = db_exports.generatePluginID(name);
|
|
14613
14695
|
let rev;
|
|
14614
14696
|
try {
|
|
14615
|
-
const existing = await
|
|
14697
|
+
const existing = await db.get(pluginId);
|
|
14616
14698
|
rev = existing._rev;
|
|
14617
14699
|
} catch (err) {
|
|
14618
14700
|
rev = void 0;
|
|
@@ -14623,7 +14705,7 @@ async function storePlugin(metadata, directory, source) {
|
|
|
14623
14705
|
...metadata,
|
|
14624
14706
|
name,
|
|
14625
14707
|
version,
|
|
14626
|
-
hash
|
|
14708
|
+
hash,
|
|
14627
14709
|
description
|
|
14628
14710
|
};
|
|
14629
14711
|
if (iconFileName) {
|
|
@@ -14635,8 +14717,8 @@ async function storePlugin(metadata, directory, source) {
|
|
|
14635
14717
|
source
|
|
14636
14718
|
};
|
|
14637
14719
|
}
|
|
14638
|
-
const
|
|
14639
|
-
const response2 = await
|
|
14720
|
+
const write = async () => {
|
|
14721
|
+
const response2 = await db.put(doc);
|
|
14640
14722
|
await events_exports.plugin.imported(doc);
|
|
14641
14723
|
return {
|
|
14642
14724
|
...doc,
|
|
@@ -14644,21 +14726,21 @@ async function storePlugin(metadata, directory, source) {
|
|
|
14644
14726
|
};
|
|
14645
14727
|
};
|
|
14646
14728
|
if (!rev) {
|
|
14647
|
-
return await addPlugin(
|
|
14729
|
+
return await addPlugin(write);
|
|
14648
14730
|
} else {
|
|
14649
|
-
return await
|
|
14731
|
+
return await write();
|
|
14650
14732
|
}
|
|
14651
14733
|
}
|
|
14652
|
-
async function deletePlugin(
|
|
14734
|
+
async function deletePlugin(pluginId2) {
|
|
14653
14735
|
const db2 = tenancy.getGlobalDB();
|
|
14654
14736
|
try {
|
|
14655
|
-
const plugin = await db2.get(
|
|
14656
|
-
const
|
|
14737
|
+
const plugin = await db2.get(pluginId2);
|
|
14738
|
+
const bucketPath2 = objectStore_exports2.getPluginS3Dir(plugin.name);
|
|
14657
14739
|
await objectStore_exports2.deleteFolder(
|
|
14658
14740
|
objectStore_exports2.ObjectStoreBuckets.PLUGINS,
|
|
14659
|
-
|
|
14741
|
+
bucketPath2
|
|
14660
14742
|
);
|
|
14661
|
-
await db2.remove(
|
|
14743
|
+
await db2.remove(pluginId2, plugin._rev);
|
|
14662
14744
|
await events_exports.plugin.deleted(plugin);
|
|
14663
14745
|
await removePlugin();
|
|
14664
14746
|
} catch (err) {
|
|
@@ -14692,12 +14774,12 @@ function isEncryptionKeyAvailable() {
|
|
|
14692
14774
|
return !!environment_default2.ENCRYPTION_KEY;
|
|
14693
14775
|
}
|
|
14694
14776
|
async function fetch10() {
|
|
14695
|
-
const
|
|
14696
|
-
return Object.keys(
|
|
14777
|
+
const doc2 = await environmentVariables_exports.get();
|
|
14778
|
+
return Object.keys(doc2.variables);
|
|
14697
14779
|
}
|
|
14698
14780
|
async function fetchValues(environment3) {
|
|
14699
|
-
const
|
|
14700
|
-
const decrypted =
|
|
14781
|
+
const doc2 = await environmentVariables_exports.get();
|
|
14782
|
+
const decrypted = doc2.variables;
|
|
14701
14783
|
const output = {};
|
|
14702
14784
|
for (let [key, value] of Object.entries(decrypted)) {
|
|
14703
14785
|
switch (environment3) {
|
|
@@ -14719,9 +14801,9 @@ async function changeValues(cb) {
|
|
|
14719
14801
|
"User does not have access to environment variables feature."
|
|
14720
14802
|
);
|
|
14721
14803
|
}
|
|
14722
|
-
const
|
|
14723
|
-
|
|
14724
|
-
await environmentVariables_exports.update(
|
|
14804
|
+
const doc2 = await environmentVariables_exports.get();
|
|
14805
|
+
doc2.variables = cb(doc2.variables);
|
|
14806
|
+
await environmentVariables_exports.update(doc2);
|
|
14725
14807
|
}
|
|
14726
14808
|
async function update2(varName, value) {
|
|
14727
14809
|
const checkName = isValid(varName);
|
|
@@ -14772,15 +14854,15 @@ var init_environmentVariables6 = __esm({
|
|
|
14772
14854
|
function generateAuditLogID(timestamp) {
|
|
14773
14855
|
return `${"al" /* AUDIT_LOG */}${SEPARATOR}${timestamp}${SEPARATOR}${utils_exports2.newid()}`;
|
|
14774
14856
|
}
|
|
14775
|
-
async function save5(
|
|
14776
|
-
if (!
|
|
14777
|
-
|
|
14857
|
+
async function save5(doc2) {
|
|
14858
|
+
if (!doc2._id) {
|
|
14859
|
+
doc2._id = generateAuditLogID(doc2.timestamp);
|
|
14778
14860
|
}
|
|
14779
14861
|
try {
|
|
14780
14862
|
const db2 = context_exports.getAuditLogsDB();
|
|
14781
|
-
const response2 = await db2.put(
|
|
14863
|
+
const response2 = await db2.put(doc2);
|
|
14782
14864
|
return {
|
|
14783
|
-
...
|
|
14865
|
+
...doc2,
|
|
14784
14866
|
_rev: response2.rev
|
|
14785
14867
|
};
|
|
14786
14868
|
} catch (err) {
|
|
@@ -14808,9 +14890,9 @@ function dump(params2) {
|
|
|
14808
14890
|
const db2 = context_exports.getAuditLogsDB();
|
|
14809
14891
|
const stream3 = new MemoryStream();
|
|
14810
14892
|
const promise = db2.dump(stream3, {
|
|
14811
|
-
filter: (
|
|
14893
|
+
filter: (doc2) => {
|
|
14812
14894
|
var _a;
|
|
14813
|
-
const auditLog =
|
|
14895
|
+
const auditLog = doc2;
|
|
14814
14896
|
if (!((_a = auditLog._id) == null ? void 0 : _a.startsWith("al" /* AUDIT_LOG */))) {
|
|
14815
14897
|
return false;
|
|
14816
14898
|
}
|
|
@@ -14828,7 +14910,7 @@ function dump(params2) {
|
|
|
14828
14910
|
allMatched = allMatched && auditLog.timestamp >= params2.startDate && auditLog.timestamp <= params2.endDate;
|
|
14829
14911
|
}
|
|
14830
14912
|
if (params2.fullSearch) {
|
|
14831
|
-
const json2 = JSON.stringify(
|
|
14913
|
+
const json2 = JSON.stringify(doc2);
|
|
14832
14914
|
allMatched = allMatched && json2.includes(params2.fullSearch);
|
|
14833
14915
|
}
|
|
14834
14916
|
return allMatched;
|
|
@@ -14839,8 +14921,8 @@ function dump(params2) {
|
|
|
14839
14921
|
const json2 = JSON.parse(Buffer.from(data2).toString());
|
|
14840
14922
|
if (Array.isArray(json2.docs)) {
|
|
14841
14923
|
let str = "";
|
|
14842
|
-
for (let
|
|
14843
|
-
str += JSON.stringify(
|
|
14924
|
+
for (let doc2 of json2.docs) {
|
|
14925
|
+
str += JSON.stringify(doc2) + "\n";
|
|
14844
14926
|
}
|
|
14845
14927
|
returnStream.write(str);
|
|
14846
14928
|
}
|
|
@@ -14865,8 +14947,8 @@ var init_auditLogs4 = __esm({
|
|
|
14865
14947
|
var require_Helper = __commonJS({
|
|
14866
14948
|
"../string-templates/src/helpers/Helper.js"(exports2, module2) {
|
|
14867
14949
|
var Helper = class {
|
|
14868
|
-
constructor(
|
|
14869
|
-
this.name =
|
|
14950
|
+
constructor(name2, fn2, useValueFallback = true) {
|
|
14951
|
+
this.name = name2;
|
|
14870
14952
|
this.fn = fn2;
|
|
14871
14953
|
this.useValueFallback = useValueFallback;
|
|
14872
14954
|
}
|
|
@@ -15035,18 +15117,18 @@ var require_external = __commonJS({
|
|
|
15035
15117
|
exports2.externalCollections = EXTERNAL_FUNCTION_COLLECTIONS;
|
|
15036
15118
|
exports2.addedHelpers = ADDED_HELPERS;
|
|
15037
15119
|
exports2.registerAll = (handlebars) => {
|
|
15038
|
-
for (let [
|
|
15039
|
-
handlebars.registerHelper(
|
|
15120
|
+
for (let [name2, helper] of Object.entries(ADDED_HELPERS)) {
|
|
15121
|
+
handlebars.registerHelper(name2, helper);
|
|
15040
15122
|
}
|
|
15041
15123
|
let externalNames = [];
|
|
15042
15124
|
for (let collection of EXTERNAL_FUNCTION_COLLECTIONS) {
|
|
15043
15125
|
let hbsHelperInfo = helpers[collection]();
|
|
15044
15126
|
for (let entry of Object.entries(hbsHelperInfo)) {
|
|
15045
|
-
const
|
|
15046
|
-
if (HelperFunctionBuiltin.indexOf(
|
|
15127
|
+
const name2 = entry[0];
|
|
15128
|
+
if (HelperFunctionBuiltin.indexOf(name2) !== -1 || externalNames.indexOf(name2) !== -1) {
|
|
15047
15129
|
continue;
|
|
15048
15130
|
}
|
|
15049
|
-
externalNames.push(
|
|
15131
|
+
externalNames.push(name2);
|
|
15050
15132
|
}
|
|
15051
15133
|
helpers[collection]({
|
|
15052
15134
|
handlebars
|
|
@@ -15055,11 +15137,11 @@ var require_external = __commonJS({
|
|
|
15055
15137
|
exports2.externalHelperNames = externalNames.concat(Object.keys(ADDED_HELPERS));
|
|
15056
15138
|
};
|
|
15057
15139
|
exports2.unregisterAll = (handlebars) => {
|
|
15058
|
-
for (let
|
|
15059
|
-
handlebars.unregisterHelper(
|
|
15140
|
+
for (let name2 of Object.keys(ADDED_HELPERS)) {
|
|
15141
|
+
handlebars.unregisterHelper(name2);
|
|
15060
15142
|
}
|
|
15061
|
-
for (let
|
|
15062
|
-
handlebars.unregisterHelper(
|
|
15143
|
+
for (let name2 of module2.exports.externalHelperNames) {
|
|
15144
|
+
handlebars.unregisterHelper(name2);
|
|
15063
15145
|
}
|
|
15064
15146
|
exports2.externalHelperNames = [];
|
|
15065
15147
|
};
|
|
@@ -15173,12 +15255,12 @@ var require_javascript = __commonJS({
|
|
|
15173
15255
|
throw new Error("JS disabled in environment.");
|
|
15174
15256
|
}
|
|
15175
15257
|
try {
|
|
15176
|
-
const
|
|
15258
|
+
const js2 = `function run(){${atob(handlebars)}};run();`;
|
|
15177
15259
|
const sandboxContext = {
|
|
15178
15260
|
$: (path2) => getContextValue(path2, cloneDeep16(context)),
|
|
15179
15261
|
helpers: getHelperList()
|
|
15180
15262
|
};
|
|
15181
|
-
const res = { data: runJS(
|
|
15263
|
+
const res = { data: runJS(js2, sandboxContext) };
|
|
15182
15264
|
return `{{${LITERAL_MARKER} js_result-${JSON.stringify(res)}}}`;
|
|
15183
15265
|
} catch (error) {
|
|
15184
15266
|
return "Error while executing JS";
|
|
@@ -15291,8 +15373,8 @@ var require_preprocessor = __commonJS({
|
|
|
15291
15373
|
FINALISE: "finalise"
|
|
15292
15374
|
};
|
|
15293
15375
|
var Preprocessor = class {
|
|
15294
|
-
constructor(
|
|
15295
|
-
this.name =
|
|
15376
|
+
constructor(name2, fn2) {
|
|
15377
|
+
this.name = name2;
|
|
15296
15378
|
this.fn = fn2;
|
|
15297
15379
|
}
|
|
15298
15380
|
process(fullString, statement, opts) {
|
|
@@ -15356,8 +15438,8 @@ var require_postprocessor = __commonJS({
|
|
|
15356
15438
|
CONVERT_LITERALS: "convert-literals"
|
|
15357
15439
|
};
|
|
15358
15440
|
var Postprocessor = class {
|
|
15359
|
-
constructor(
|
|
15360
|
-
this.name =
|
|
15441
|
+
constructor(name2, fn2) {
|
|
15442
|
+
this.name = name2;
|
|
15361
15443
|
this.fn = fn2;
|
|
15362
15444
|
}
|
|
15363
15445
|
process(statement) {
|
|
@@ -16999,10 +17081,10 @@ var require_src = __commonJS({
|
|
|
16999
17081
|
};
|
|
17000
17082
|
module2.exports.convertToJS = (hbs) => {
|
|
17001
17083
|
const blocks = exports2.findHBSBlocks(hbs);
|
|
17002
|
-
let
|
|
17084
|
+
let js2 = "return `", prevBlock = null;
|
|
17003
17085
|
const variables = {};
|
|
17004
17086
|
if (blocks.length === 0) {
|
|
17005
|
-
|
|
17087
|
+
js2 += hbs;
|
|
17006
17088
|
}
|
|
17007
17089
|
let count = 1;
|
|
17008
17090
|
for (let block of blocks) {
|
|
@@ -17014,15 +17096,15 @@ var require_src = __commonJS({
|
|
|
17014
17096
|
prevBlock = block;
|
|
17015
17097
|
const { variable, value } = convertHBSBlock(block, count++);
|
|
17016
17098
|
variables[variable] = value;
|
|
17017
|
-
|
|
17099
|
+
js2 += `${stringPart.split()}\${${variable}}`;
|
|
17018
17100
|
}
|
|
17019
17101
|
let varBlock = "";
|
|
17020
17102
|
for (let [variable, value] of Object.entries(variables)) {
|
|
17021
17103
|
varBlock += `const ${variable} = ${value};
|
|
17022
17104
|
`;
|
|
17023
17105
|
}
|
|
17024
|
-
|
|
17025
|
-
return `${varBlock}${
|
|
17106
|
+
js2 += "`;";
|
|
17107
|
+
return `${varBlock}${js2}`;
|
|
17026
17108
|
};
|
|
17027
17109
|
}
|
|
17028
17110
|
});
|
|
@@ -17049,12 +17131,12 @@ var require_src2 = __commonJS({
|
|
|
17049
17131
|
if (!process.env.NO_JS) {
|
|
17050
17132
|
const { VM: VM2 } = require("vm2");
|
|
17051
17133
|
const { setJSRunner } = require_javascript();
|
|
17052
|
-
setJSRunner((
|
|
17134
|
+
setJSRunner((js2, context) => {
|
|
17053
17135
|
const vm = new VM2({
|
|
17054
17136
|
sandbox: context,
|
|
17055
17137
|
timeout: 1e3
|
|
17056
17138
|
});
|
|
17057
|
-
return vm.run(
|
|
17139
|
+
return vm.run(js2);
|
|
17058
17140
|
});
|
|
17059
17141
|
}
|
|
17060
17142
|
}
|
|
@@ -17148,12 +17230,12 @@ async function auditLogsEnabled() {
|
|
|
17148
17230
|
const license = await licensing_exports.cache.getCachedLicense();
|
|
17149
17231
|
return license.features.includes("auditLogs" /* AUDIT_LOGS */);
|
|
17150
17232
|
}
|
|
17151
|
-
function getEventFriendlyName(event,
|
|
17233
|
+
function getEventFriendlyName(event, metadata2) {
|
|
17152
17234
|
const friendly = AuditedEventFriendlyName[event];
|
|
17153
17235
|
if (!friendly) {
|
|
17154
17236
|
throw new Error("No friendly name found.");
|
|
17155
17237
|
}
|
|
17156
|
-
let processed = processStringSync(friendly,
|
|
17238
|
+
let processed = processStringSync(friendly, metadata2);
|
|
17157
17239
|
if (processed.includes(`""`)) {
|
|
17158
17240
|
processed = removeTemplateStrings(friendly);
|
|
17159
17241
|
}
|
|
@@ -17175,29 +17257,29 @@ var init_utils10 = __esm({
|
|
|
17175
17257
|
});
|
|
17176
17258
|
|
|
17177
17259
|
// ../pro/packages/pro/src/sdk/auditLogs/auditLogs.ts
|
|
17178
|
-
async function
|
|
17260
|
+
async function write2(event, metadata2, opts) {
|
|
17179
17261
|
if (!await auditLogsEnabled() || !utils_exports2.isAudited(event)) {
|
|
17180
17262
|
return;
|
|
17181
17263
|
}
|
|
17182
|
-
const friendly = getEventFriendlyName(event,
|
|
17264
|
+
const friendly = getEventFriendlyName(event, metadata2);
|
|
17183
17265
|
let date = /* @__PURE__ */ new Date();
|
|
17184
17266
|
if (opts == null ? void 0 : opts.timestamp) {
|
|
17185
17267
|
date = new Date(opts.timestamp);
|
|
17186
17268
|
}
|
|
17187
|
-
const
|
|
17269
|
+
const doc2 = {
|
|
17188
17270
|
timestamp: date.toISOString(),
|
|
17189
17271
|
event,
|
|
17190
17272
|
name: friendly,
|
|
17191
17273
|
userId: (opts == null ? void 0 : opts.userId) || AuditLogSystemUser,
|
|
17192
17274
|
metadata: {
|
|
17193
|
-
...
|
|
17275
|
+
...metadata2,
|
|
17194
17276
|
...opts == null ? void 0 : opts.hostInfo
|
|
17195
17277
|
}
|
|
17196
17278
|
};
|
|
17197
17279
|
const fallback = {};
|
|
17198
17280
|
try {
|
|
17199
17281
|
if (opts == null ? void 0 : opts.appId) {
|
|
17200
|
-
|
|
17282
|
+
doc2.appId = db_exports.getProdAppID(opts.appId);
|
|
17201
17283
|
const appMetadata = await cache_exports.app.getAppMetadata(opts.appId);
|
|
17202
17284
|
fallback.appName = appMetadata.name;
|
|
17203
17285
|
}
|
|
@@ -17211,8 +17293,8 @@ async function write(event, metadata, opts) {
|
|
|
17211
17293
|
err
|
|
17212
17294
|
);
|
|
17213
17295
|
}
|
|
17214
|
-
|
|
17215
|
-
return await save5(
|
|
17296
|
+
doc2.fallback = fallback;
|
|
17297
|
+
return await save5(doc2);
|
|
17216
17298
|
}
|
|
17217
17299
|
async function enrich(logs) {
|
|
17218
17300
|
const allUserIds = logs.map((log) => log.userId);
|
|
@@ -17284,7 +17366,7 @@ __export(auditLogs_exports2, {
|
|
|
17284
17366
|
definitions: () => definitions2,
|
|
17285
17367
|
download: () => download,
|
|
17286
17368
|
fetch: () => fetch11,
|
|
17287
|
-
write: () =>
|
|
17369
|
+
write: () => write2
|
|
17288
17370
|
});
|
|
17289
17371
|
var init_auditLogs6 = __esm({
|
|
17290
17372
|
"../pro/packages/pro/src/sdk/auditLogs/index.ts"() {
|
|
@@ -17307,8 +17389,8 @@ var init_queue4 = __esm({
|
|
|
17307
17389
|
});
|
|
17308
17390
|
|
|
17309
17391
|
// ../pro/packages/pro/src/sdk/backups/backup.ts
|
|
17310
|
-
async function storeAppBackupMetadata2(
|
|
17311
|
-
return backups_exports.storeAppBackupMetadata(
|
|
17392
|
+
async function storeAppBackupMetadata2(metadata2, opts = {}) {
|
|
17393
|
+
return backups_exports.storeAppBackupMetadata(metadata2, opts);
|
|
17312
17394
|
}
|
|
17313
17395
|
function getTimestamps(status2) {
|
|
17314
17396
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -17322,7 +17404,7 @@ function getTimestamps(status2) {
|
|
|
17322
17404
|
return { timestamp, createdAt: timestamp };
|
|
17323
17405
|
}
|
|
17324
17406
|
}
|
|
17325
|
-
async function updateBackupStatus(id,
|
|
17407
|
+
async function updateBackupStatus(id, rev2, status2, contents, filename) {
|
|
17326
17408
|
const backup = await getAppBackup(id);
|
|
17327
17409
|
return await backups_exports.storeAppBackupMetadata(
|
|
17328
17410
|
{
|
|
@@ -17332,10 +17414,10 @@ async function updateBackupStatus(id, rev, status2, contents, filename) {
|
|
|
17332
17414
|
status: status2,
|
|
17333
17415
|
type: "backup" /* BACKUP */
|
|
17334
17416
|
},
|
|
17335
|
-
{ filename, docId: id, docRev:
|
|
17417
|
+
{ filename, docId: id, docRev: rev2 }
|
|
17336
17418
|
);
|
|
17337
17419
|
}
|
|
17338
|
-
async function updateRestoreStatus(id,
|
|
17420
|
+
async function updateRestoreStatus(id, rev2, status2) {
|
|
17339
17421
|
const restore = await getAppBackup(id);
|
|
17340
17422
|
return await backups_exports.storeAppBackupMetadata(
|
|
17341
17423
|
{
|
|
@@ -17345,7 +17427,7 @@ async function updateRestoreStatus(id, rev, status2) {
|
|
|
17345
17427
|
type: "restore" /* RESTORE */,
|
|
17346
17428
|
trigger: "manual" /* MANUAL */
|
|
17347
17429
|
},
|
|
17348
|
-
{ docId: id, docRev:
|
|
17430
|
+
{ docId: id, docRev: rev2 }
|
|
17349
17431
|
);
|
|
17350
17432
|
}
|
|
17351
17433
|
async function getAppBackup(backupId) {
|
|
@@ -17355,11 +17437,11 @@ async function updateAppBackup(backupId, backupName) {
|
|
|
17355
17437
|
return backups_exports.updateAppBackupMetadata(backupId, backupName);
|
|
17356
17438
|
}
|
|
17357
17439
|
async function deleteAppBackup(backupId) {
|
|
17358
|
-
const
|
|
17359
|
-
if (
|
|
17440
|
+
const metadata2 = await backups_exports.getAppBackupMetadata(backupId);
|
|
17441
|
+
if (metadata2.filename) {
|
|
17360
17442
|
await objectStore_exports2.deleteFile(
|
|
17361
17443
|
objectStore_exports2.ObjectStoreBuckets.BACKUPS,
|
|
17362
|
-
|
|
17444
|
+
metadata2.filename
|
|
17363
17445
|
);
|
|
17364
17446
|
}
|
|
17365
17447
|
return backups_exports.deleteAppBackupMetadata(backupId);
|
|
@@ -17368,15 +17450,15 @@ async function fetchAppBackups2(appId, opts) {
|
|
|
17368
17450
|
return backups_exports.fetchAppBackups(appId, opts);
|
|
17369
17451
|
}
|
|
17370
17452
|
async function downloadAppBackup(backupId) {
|
|
17371
|
-
const
|
|
17372
|
-
if (!
|
|
17453
|
+
const metadata2 = await backups_exports.getAppBackupMetadata(backupId);
|
|
17454
|
+
if (!metadata2.filename) {
|
|
17373
17455
|
throw new Error("Backup incomplete - cannot download.");
|
|
17374
17456
|
}
|
|
17375
17457
|
const path2 = await objectStore_exports2.retrieveToTmp(
|
|
17376
17458
|
objectStore_exports2.ObjectStoreBuckets.BACKUPS,
|
|
17377
|
-
|
|
17459
|
+
metadata2.filename
|
|
17378
17460
|
);
|
|
17379
|
-
return { metadata, path: path2 };
|
|
17461
|
+
return { metadata: metadata2, path: path2 };
|
|
17380
17462
|
}
|
|
17381
17463
|
async function triggerAppBackup(appId, trigger, opts = {}) {
|
|
17382
17464
|
let backup;
|
|
@@ -17415,7 +17497,7 @@ async function triggerAppBackup(appId, trigger, opts = {}) {
|
|
|
17415
17497
|
return backup.id;
|
|
17416
17498
|
}
|
|
17417
17499
|
async function triggerAppRestore(appId, backupId, nameForBackup, createdBy) {
|
|
17418
|
-
const
|
|
17500
|
+
const metadata2 = await getAppBackup(backupId);
|
|
17419
17501
|
let restore;
|
|
17420
17502
|
try {
|
|
17421
17503
|
restore = await storeAppBackupMetadata2({
|
|
@@ -17442,7 +17524,7 @@ async function triggerAppRestore(appId, backupId, nameForBackup, createdBy) {
|
|
|
17442
17524
|
createdBy
|
|
17443
17525
|
}
|
|
17444
17526
|
});
|
|
17445
|
-
return { restoreId: restore.id, metadata };
|
|
17527
|
+
return { restoreId: restore.id, metadata: metadata2 };
|
|
17446
17528
|
}
|
|
17447
17529
|
var pkg, backup_default2;
|
|
17448
17530
|
var init_backup5 = __esm({
|
|
@@ -17541,8 +17623,8 @@ async function runBackup(trigger, tenantId, appId, opts) {
|
|
|
17541
17623
|
}
|
|
17542
17624
|
});
|
|
17543
17625
|
await updateMetadata2("complete" /* COMPLETE */, { filename, contents });
|
|
17544
|
-
if (
|
|
17545
|
-
|
|
17626
|
+
if (import_fs8.default.existsSync(tarPath)) {
|
|
17627
|
+
import_fs8.default.rmSync(tarPath);
|
|
17546
17628
|
}
|
|
17547
17629
|
} catch (err) {
|
|
17548
17630
|
logging_exports.logAlert("App backup error", err);
|
|
@@ -17555,7 +17637,7 @@ async function importProcessor(job, opts) {
|
|
|
17555
17637
|
const tenantId = tenancy.getTenantIDFromAppID(appId);
|
|
17556
17638
|
return tenancy.doInTenant(tenantId, async () => {
|
|
17557
17639
|
const devAppId = db_exports.getDevAppID(appId);
|
|
17558
|
-
const { rev } = await backup_default2.updateRestoreStatus(
|
|
17640
|
+
const { rev: rev2 } = await backup_default2.updateRestoreStatus(
|
|
17559
17641
|
data2.docId,
|
|
17560
17642
|
data2.docRev,
|
|
17561
17643
|
"started" /* STARTED */
|
|
@@ -17580,34 +17662,34 @@ async function importProcessor(job, opts) {
|
|
|
17580
17662
|
logging_exports.logAlert("App restore error", err);
|
|
17581
17663
|
status2 = "failed" /* FAILED */;
|
|
17582
17664
|
}
|
|
17583
|
-
await backup_default2.updateRestoreStatus(data2.docId,
|
|
17665
|
+
await backup_default2.updateRestoreStatus(data2.docId, rev2, status2);
|
|
17584
17666
|
});
|
|
17585
17667
|
}
|
|
17586
17668
|
async function exportProcessor(job, opts) {
|
|
17587
17669
|
const data2 = job.data;
|
|
17588
|
-
const appId = data2.appId, trigger = data2.export.trigger,
|
|
17670
|
+
const appId = data2.appId, trigger = data2.export.trigger, name2 = data2.export.name;
|
|
17589
17671
|
const tenantId = tenancy.getTenantIDFromAppID(appId);
|
|
17590
17672
|
await tenancy.doInTenant(tenantId, async () => {
|
|
17591
|
-
const { rev } = await backup_default2.updateBackupStatus(
|
|
17673
|
+
const { rev: rev2 } = await backup_default2.updateBackupStatus(
|
|
17592
17674
|
data2.docId,
|
|
17593
17675
|
data2.docRev,
|
|
17594
17676
|
"started" /* STARTED */
|
|
17595
17677
|
);
|
|
17596
17678
|
return runBackup(trigger, tenantId, appId, {
|
|
17597
17679
|
processing: opts,
|
|
17598
|
-
doc: { id: data2.docId, rev },
|
|
17599
|
-
name
|
|
17680
|
+
doc: { id: data2.docId, rev: rev2 },
|
|
17681
|
+
name: name2
|
|
17600
17682
|
});
|
|
17601
17683
|
});
|
|
17602
17684
|
}
|
|
17603
|
-
var
|
|
17685
|
+
var import_fs8;
|
|
17604
17686
|
var init_processing = __esm({
|
|
17605
17687
|
"../pro/packages/pro/src/sdk/backups/processing.ts"() {
|
|
17606
17688
|
init_src2();
|
|
17607
17689
|
init_backup5();
|
|
17608
17690
|
init_src();
|
|
17609
17691
|
init_queue4();
|
|
17610
|
-
|
|
17692
|
+
import_fs8 = __toESM(require("fs"));
|
|
17611
17693
|
}
|
|
17612
17694
|
});
|
|
17613
17695
|
|
|
@@ -17905,9 +17987,9 @@ var init_groups7 = __esm({
|
|
|
17905
17987
|
ctx.body = { data: await fetch9() };
|
|
17906
17988
|
};
|
|
17907
17989
|
destroy4 = async (ctx) => {
|
|
17908
|
-
const { id, rev } = ctx.params;
|
|
17990
|
+
const { id, rev: rev2 } = ctx.params;
|
|
17909
17991
|
try {
|
|
17910
|
-
await remove2(id,
|
|
17992
|
+
await remove2(id, rev2);
|
|
17911
17993
|
ctx.body = { message: "Group deleted successfully" };
|
|
17912
17994
|
} catch (err) {
|
|
17913
17995
|
ctx.throw(err.status, err);
|
|
@@ -17953,13 +18035,13 @@ async function fetch13(ctx) {
|
|
|
17953
18035
|
};
|
|
17954
18036
|
}
|
|
17955
18037
|
async function create3(ctx) {
|
|
17956
|
-
const { name, production, development } = ctx.request.body;
|
|
17957
|
-
await environmentVariables_exports2.update(
|
|
18038
|
+
const { name: name2, production, development } = ctx.request.body;
|
|
18039
|
+
await environmentVariables_exports2.update(name2, { production, development });
|
|
17958
18040
|
const environments = ["production" /* PRODUCTION */];
|
|
17959
18041
|
if (production !== development) {
|
|
17960
18042
|
environments.push("development" /* DEVELOPMENT */);
|
|
17961
18043
|
}
|
|
17962
|
-
await events_exports.environmentVariable.created(
|
|
18044
|
+
await events_exports.environmentVariable.created(name2, environments);
|
|
17963
18045
|
ctx.status = 200;
|
|
17964
18046
|
}
|
|
17965
18047
|
async function update4(ctx) {
|
|
@@ -18246,17 +18328,17 @@ async function downloadBackup(ctx) {
|
|
|
18246
18328
|
const appId = ctx.params.appId;
|
|
18247
18329
|
await checkAppID(ctx, appId);
|
|
18248
18330
|
const backupId = ctx.params.backupId;
|
|
18249
|
-
const { metadata, path: path2 } = await backups_default.downloadAppBackup(backupId);
|
|
18250
|
-
ctx.attachment(`backup-${
|
|
18251
|
-
ctx.body =
|
|
18331
|
+
const { metadata: metadata2, path: path2 } = await backups_default.downloadAppBackup(backupId);
|
|
18332
|
+
ctx.attachment(`backup-${metadata2.timestamp}.tar.gz`);
|
|
18333
|
+
ctx.body = import_fs9.default.createReadStream(path2);
|
|
18252
18334
|
}
|
|
18253
|
-
var
|
|
18335
|
+
var import_fs9;
|
|
18254
18336
|
var init_backups3 = __esm({
|
|
18255
18337
|
"../pro/packages/pro/src/api/controllers/apps/backups.ts"() {
|
|
18256
18338
|
init_src();
|
|
18257
18339
|
init_sdk2();
|
|
18258
18340
|
init_src2();
|
|
18259
|
-
|
|
18341
|
+
import_fs9 = __toESM(require("fs"));
|
|
18260
18342
|
}
|
|
18261
18343
|
});
|
|
18262
18344
|
|
|
@@ -18387,8 +18469,8 @@ var init_schedules2 = __esm({
|
|
|
18387
18469
|
});
|
|
18388
18470
|
|
|
18389
18471
|
// ../pro/packages/pro/src/api/controllers/global/scim/users.ts
|
|
18390
|
-
function tryGetQueryAsNumber(ctx,
|
|
18391
|
-
const value = ctx.request.query[
|
|
18472
|
+
function tryGetQueryAsNumber(ctx, name2) {
|
|
18473
|
+
const value = ctx.request.query[name2];
|
|
18392
18474
|
if (value === void 0) {
|
|
18393
18475
|
return void 0;
|
|
18394
18476
|
}
|
|
@@ -18779,11 +18861,11 @@ var init_filters = __esm({
|
|
|
18779
18861
|
return docs;
|
|
18780
18862
|
}
|
|
18781
18863
|
query = cleanupQuery(query);
|
|
18782
|
-
const match = (type, failFn) => (
|
|
18864
|
+
const match = (type, failFn) => (doc2) => {
|
|
18783
18865
|
const filters = Object.entries(query[type] || {});
|
|
18784
18866
|
for (let i = 0; i < filters.length; i++) {
|
|
18785
18867
|
const [key, testValue] = filters[i];
|
|
18786
|
-
const docValue = deepGet(
|
|
18868
|
+
const docValue = deepGet(doc2, removeKeyNumbering2(key));
|
|
18787
18869
|
if (failFn(docValue, testValue)) {
|
|
18788
18870
|
return false;
|
|
18789
18871
|
}
|
|
@@ -18844,8 +18926,8 @@ var init_filters = __esm({
|
|
|
18844
18926
|
return testValue == null ? void 0 : testValue.every((item) => docValue == null ? void 0 : docValue.includes(item));
|
|
18845
18927
|
}
|
|
18846
18928
|
);
|
|
18847
|
-
const docMatch = (
|
|
18848
|
-
return stringMatch(
|
|
18929
|
+
const docMatch = (doc2) => {
|
|
18930
|
+
return stringMatch(doc2) && fuzzyMatch(doc2) && rangeMatch(doc2) && equalMatch(doc2) && notEqualMatch(doc2) && emptyMatch(doc2) && notEmptyMatch(doc2) && oneOf(doc2) && contains(doc2) && containsAny(doc2) && notContains(doc2);
|
|
18849
18931
|
};
|
|
18850
18932
|
return docs.filter(docMatch);
|
|
18851
18933
|
};
|
|
@@ -18892,11 +18974,39 @@ var init_filters = __esm({
|
|
|
18892
18974
|
// ../shared-core/src/utils.ts
|
|
18893
18975
|
var utils_exports5 = {};
|
|
18894
18976
|
__export(utils_exports5, {
|
|
18977
|
+
parallelForeach: () => parallelForeach,
|
|
18895
18978
|
unreachable: () => unreachable
|
|
18896
18979
|
});
|
|
18897
18980
|
function unreachable(value, message = `No such case in exhaustive switch: ${value}`) {
|
|
18898
18981
|
throw new Error(message);
|
|
18899
18982
|
}
|
|
18983
|
+
async function parallelForeach(items, task, maxConcurrency) {
|
|
18984
|
+
const promises = [];
|
|
18985
|
+
let index2 = 0;
|
|
18986
|
+
const processItem = async (item) => {
|
|
18987
|
+
try {
|
|
18988
|
+
await task(item);
|
|
18989
|
+
} finally {
|
|
18990
|
+
processNext();
|
|
18991
|
+
}
|
|
18992
|
+
};
|
|
18993
|
+
const processNext = () => {
|
|
18994
|
+
if (index2 >= items.length) {
|
|
18995
|
+
return;
|
|
18996
|
+
}
|
|
18997
|
+
const item = items[index2];
|
|
18998
|
+
index2++;
|
|
18999
|
+
const promise = processItem(item);
|
|
19000
|
+
promises.push(promise);
|
|
19001
|
+
if (promises.length >= maxConcurrency) {
|
|
19002
|
+
Promise.race(promises).then(processNext);
|
|
19003
|
+
} else {
|
|
19004
|
+
processNext();
|
|
19005
|
+
}
|
|
19006
|
+
};
|
|
19007
|
+
processNext();
|
|
19008
|
+
await Promise.all(promises);
|
|
19009
|
+
}
|
|
18900
19010
|
var init_utils12 = __esm({
|
|
18901
19011
|
"../shared-core/src/utils.ts"() {
|
|
18902
19012
|
}
|
|
@@ -19520,32 +19630,32 @@ var init_centralPath = __esm({
|
|
|
19520
19630
|
});
|
|
19521
19631
|
|
|
19522
19632
|
// src/utilities/fileSystem/filesystem.ts
|
|
19523
|
-
var
|
|
19633
|
+
var import_fs10, import_path8, import_tar, uuid2, TOP_LEVEL_PATH, apiFileReturn, streamFile, createTempFolder, extractTarball;
|
|
19524
19634
|
var init_filesystem = __esm({
|
|
19525
19635
|
"src/utilities/fileSystem/filesystem.ts"() {
|
|
19526
|
-
|
|
19636
|
+
import_fs10 = __toESM(require("fs"));
|
|
19527
19637
|
init_budibaseDir();
|
|
19528
|
-
|
|
19638
|
+
import_path8 = require("path");
|
|
19529
19639
|
init_environment();
|
|
19530
19640
|
import_tar = __toESM(require("tar"));
|
|
19531
19641
|
init_environment();
|
|
19532
19642
|
uuid2 = require("uuid/v4");
|
|
19533
|
-
TOP_LEVEL_PATH = environment_default.TOP_LEVEL_PATH || (0,
|
|
19643
|
+
TOP_LEVEL_PATH = environment_default.TOP_LEVEL_PATH || (0, import_path8.resolve)((0, import_path8.join)(__dirname, "..", "..", ".."));
|
|
19534
19644
|
apiFileReturn = (contents) => {
|
|
19535
|
-
const path2 = (0,
|
|
19536
|
-
|
|
19537
|
-
return
|
|
19645
|
+
const path2 = (0, import_path8.join)(budibaseTempDir2(), uuid2());
|
|
19646
|
+
import_fs10.default.writeFileSync(path2, contents);
|
|
19647
|
+
return import_fs10.default.createReadStream(path2);
|
|
19538
19648
|
};
|
|
19539
19649
|
streamFile = (path2) => {
|
|
19540
|
-
return
|
|
19650
|
+
return import_fs10.default.createReadStream(path2);
|
|
19541
19651
|
};
|
|
19542
19652
|
createTempFolder = (item) => {
|
|
19543
|
-
const path2 = (0,
|
|
19653
|
+
const path2 = (0, import_path8.join)(budibaseTempDir2(), item);
|
|
19544
19654
|
try {
|
|
19545
|
-
if (
|
|
19546
|
-
|
|
19655
|
+
if (import_fs10.default.existsSync(path2)) {
|
|
19656
|
+
import_fs10.default.rmSync(path2, { recursive: true, force: true });
|
|
19547
19657
|
}
|
|
19548
|
-
|
|
19658
|
+
import_fs10.default.mkdirSync(path2);
|
|
19549
19659
|
} catch (err) {
|
|
19550
19660
|
throw new Error(`Path cannot be created: ${err.message}`);
|
|
19551
19661
|
}
|
|
@@ -19572,37 +19682,37 @@ var init_clientLibrary = __esm({
|
|
|
19572
19682
|
});
|
|
19573
19683
|
|
|
19574
19684
|
// src/utilities/fileSystem/app.ts
|
|
19575
|
-
var
|
|
19685
|
+
var import_path9, NODE_MODULES_PATH;
|
|
19576
19686
|
var init_app7 = __esm({
|
|
19577
19687
|
"src/utilities/fileSystem/app.ts"() {
|
|
19578
19688
|
init_budibaseDir();
|
|
19579
|
-
|
|
19689
|
+
import_path9 = require("path");
|
|
19580
19690
|
init_constants6();
|
|
19581
19691
|
init_clientLibrary();
|
|
19582
19692
|
init_environment();
|
|
19583
19693
|
init_src2();
|
|
19584
19694
|
init_filesystem();
|
|
19585
|
-
NODE_MODULES_PATH = (0,
|
|
19695
|
+
NODE_MODULES_PATH = (0, import_path9.join)(TOP_LEVEL_PATH, "node_modules");
|
|
19586
19696
|
}
|
|
19587
19697
|
});
|
|
19588
19698
|
|
|
19589
19699
|
// src/utilities/fileSystem/plugin.ts
|
|
19590
19700
|
async function getPluginImpl(path2, plugin) {
|
|
19591
19701
|
var _a;
|
|
19592
|
-
const
|
|
19593
|
-
if (!
|
|
19594
|
-
|
|
19702
|
+
const hash3 = (_a = plugin.schema) == null ? void 0 : _a.hash;
|
|
19703
|
+
if (!import_fs11.default.existsSync(path2)) {
|
|
19704
|
+
import_fs11.default.mkdirSync(path2);
|
|
19595
19705
|
}
|
|
19596
|
-
const filename = (0,
|
|
19706
|
+
const filename = (0, import_path10.join)(path2, plugin.name);
|
|
19597
19707
|
const metadataName = `${filename}.bbmetadata`;
|
|
19598
|
-
if (
|
|
19599
|
-
const currentHash =
|
|
19600
|
-
if (currentHash ===
|
|
19708
|
+
if (import_fs11.default.existsSync(filename)) {
|
|
19709
|
+
const currentHash = import_fs11.default.readFileSync(metadataName, "utf8");
|
|
19710
|
+
if (currentHash === hash3) {
|
|
19601
19711
|
return require(filename);
|
|
19602
19712
|
} else {
|
|
19603
19713
|
console.log(`Updating plugin: ${plugin.name}`);
|
|
19604
19714
|
delete require.cache[require.resolve(filename)];
|
|
19605
|
-
|
|
19715
|
+
import_fs11.default.unlinkSync(filename);
|
|
19606
19716
|
}
|
|
19607
19717
|
}
|
|
19608
19718
|
const pluginKey = objectStore_exports2.getPluginJSKey(plugin);
|
|
@@ -19610,27 +19720,27 @@ async function getPluginImpl(path2, plugin) {
|
|
|
19610
19720
|
objectStore_exports2.ObjectStoreBuckets.PLUGINS,
|
|
19611
19721
|
pluginKey
|
|
19612
19722
|
);
|
|
19613
|
-
|
|
19614
|
-
|
|
19723
|
+
import_fs11.default.writeFileSync(filename, pluginJs);
|
|
19724
|
+
import_fs11.default.writeFileSync(metadataName, hash3);
|
|
19615
19725
|
return require(filename);
|
|
19616
19726
|
}
|
|
19617
|
-
var
|
|
19727
|
+
var import_fs11, import_path10, DATASOURCE_PATH, AUTOMATION_PATH, getPluginMetadata, getDatasourcePlugin, getAutomationPlugin;
|
|
19618
19728
|
var init_plugin5 = __esm({
|
|
19619
19729
|
"src/utilities/fileSystem/plugin.ts"() {
|
|
19620
19730
|
init_budibaseDir();
|
|
19621
|
-
|
|
19622
|
-
|
|
19731
|
+
import_fs11 = __toESM(require("fs"));
|
|
19732
|
+
import_path10 = require("path");
|
|
19623
19733
|
init_src2();
|
|
19624
|
-
DATASOURCE_PATH = (0,
|
|
19625
|
-
AUTOMATION_PATH = (0,
|
|
19734
|
+
DATASOURCE_PATH = (0, import_path10.join)(budibaseTempDir2(), "datasource");
|
|
19735
|
+
AUTOMATION_PATH = (0, import_path10.join)(budibaseTempDir2(), "automation");
|
|
19626
19736
|
getPluginMetadata = async (path2) => {
|
|
19627
|
-
let
|
|
19737
|
+
let metadata2 = {};
|
|
19628
19738
|
try {
|
|
19629
|
-
const pkg2 =
|
|
19630
|
-
const schema =
|
|
19631
|
-
|
|
19632
|
-
|
|
19633
|
-
if (!
|
|
19739
|
+
const pkg2 = import_fs11.default.readFileSync((0, import_path10.join)(path2, "package.json"), "utf8");
|
|
19740
|
+
const schema = import_fs11.default.readFileSync((0, import_path10.join)(path2, "schema.json"), "utf8");
|
|
19741
|
+
metadata2.schema = JSON.parse(schema);
|
|
19742
|
+
metadata2.package = JSON.parse(pkg2);
|
|
19743
|
+
if (!metadata2.package.name || !metadata2.package.version || !metadata2.package.description) {
|
|
19634
19744
|
throw new Error(
|
|
19635
19745
|
"package.json is missing one of 'name', 'version' or 'description'."
|
|
19636
19746
|
);
|
|
@@ -19640,7 +19750,7 @@ var init_plugin5 = __esm({
|
|
|
19640
19750
|
`Unable to process schema.json/package.json in plugin. ${err.message}`
|
|
19641
19751
|
);
|
|
19642
19752
|
}
|
|
19643
|
-
return { metadata, directory: path2 };
|
|
19753
|
+
return { metadata: metadata2, directory: path2 };
|
|
19644
19754
|
};
|
|
19645
19755
|
getDatasourcePlugin = async (plugin) => {
|
|
19646
19756
|
return getPluginImpl(DATASOURCE_PATH, plugin);
|
|
@@ -19657,9 +19767,9 @@ var init_template = __esm({
|
|
|
19657
19767
|
"src/utilities/fileSystem/template.ts"() {
|
|
19658
19768
|
init_constants6();
|
|
19659
19769
|
init_src2();
|
|
19660
|
-
downloadTemplate = async (type,
|
|
19770
|
+
downloadTemplate = async (type, name2) => {
|
|
19661
19771
|
const DEFAULT_TEMPLATES_BUCKET = "prod-budi-templates.s3-eu-west-1.amazonaws.com";
|
|
19662
|
-
const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${
|
|
19772
|
+
const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${name2}.tar.gz`;
|
|
19663
19773
|
return objectStore_exports2.downloadTarball(
|
|
19664
19774
|
templateUrl,
|
|
19665
19775
|
ObjectStoreBuckets2.TEMPLATES,
|
|
@@ -19697,17 +19807,18 @@ __export(exports_exports, {
|
|
|
19697
19807
|
exportDB: () => exportDB,
|
|
19698
19808
|
streamExportApp: () => streamExportApp
|
|
19699
19809
|
});
|
|
19700
|
-
function tarFilesToTmp(tmpDir,
|
|
19701
|
-
const
|
|
19702
|
-
|
|
19810
|
+
function tarFilesToTmp(tmpDir, files2) {
|
|
19811
|
+
const fileName = `${uuid3()}.tar.gz`;
|
|
19812
|
+
const exportFile = (0, import_path11.join)(budibaseTempDir2(), fileName);
|
|
19813
|
+
import_tar2.default.create(
|
|
19703
19814
|
{
|
|
19704
19815
|
sync: true,
|
|
19705
19816
|
gzip: true,
|
|
19706
19817
|
file: exportFile,
|
|
19707
|
-
|
|
19818
|
+
noDirRecurse: false,
|
|
19708
19819
|
cwd: tmpDir
|
|
19709
19820
|
},
|
|
19710
|
-
|
|
19821
|
+
files2
|
|
19711
19822
|
);
|
|
19712
19823
|
return exportFile;
|
|
19713
19824
|
}
|
|
@@ -19721,7 +19832,7 @@ async function exportDB(dbName, opts = {}) {
|
|
|
19721
19832
|
return db_exports.doWithDB(dbName, async (db2) => {
|
|
19722
19833
|
if (opts == null ? void 0 : opts.exportPath) {
|
|
19723
19834
|
const path2 = opts == null ? void 0 : opts.exportPath;
|
|
19724
|
-
const writeStream =
|
|
19835
|
+
const writeStream = import_fs12.default.createWriteStream(path2);
|
|
19725
19836
|
await db2.dump(writeStream, exportOpts);
|
|
19726
19837
|
return path2;
|
|
19727
19838
|
} else {
|
|
@@ -19743,7 +19854,7 @@ function defineFilter(excludeRows, excludeLogs) {
|
|
|
19743
19854
|
if (excludeLogs) {
|
|
19744
19855
|
ids.push(AUTOMATION_LOG_PREFIX);
|
|
19745
19856
|
}
|
|
19746
|
-
return (
|
|
19857
|
+
return (doc2) => !ids.map((key) => doc2._id.includes(key)).reduce((prev, curr) => prev || curr);
|
|
19747
19858
|
}
|
|
19748
19859
|
async function exportApp(appId, config) {
|
|
19749
19860
|
const prodAppId = db_exports.getProdAppID(appId);
|
|
@@ -19754,9 +19865,9 @@ async function exportApp(appId, config) {
|
|
|
19754
19865
|
for (let path2 of STATIC_APP_FILES) {
|
|
19755
19866
|
const contents = await objectStore_exports2.retrieve(
|
|
19756
19867
|
ObjectStoreBuckets2.APPS,
|
|
19757
|
-
(0,
|
|
19868
|
+
(0, import_path11.join)(appPath, path2)
|
|
19758
19869
|
);
|
|
19759
|
-
|
|
19870
|
+
import_fs12.default.writeFileSync((0, import_path11.join)(tmpPath, path2), contents);
|
|
19760
19871
|
}
|
|
19761
19872
|
} else {
|
|
19762
19873
|
tmpPath = await objectStore_exports2.retrieveDirectory(
|
|
@@ -19765,37 +19876,52 @@ async function exportApp(appId, config) {
|
|
|
19765
19876
|
);
|
|
19766
19877
|
}
|
|
19767
19878
|
}
|
|
19768
|
-
const downloadedPath = (0,
|
|
19769
|
-
if (
|
|
19770
|
-
const allFiles =
|
|
19879
|
+
const downloadedPath = (0, import_path11.join)(tmpPath, appPath);
|
|
19880
|
+
if (import_fs12.default.existsSync(downloadedPath)) {
|
|
19881
|
+
const allFiles = import_fs12.default.readdirSync(downloadedPath);
|
|
19771
19882
|
for (let file of allFiles) {
|
|
19772
|
-
const path2 = (0,
|
|
19773
|
-
|
|
19883
|
+
const path2 = (0, import_path11.join)(downloadedPath, file);
|
|
19884
|
+
import_fs12.default.renameSync(path2, (0, import_path11.join)(downloadedPath, "..", file));
|
|
19774
19885
|
}
|
|
19775
|
-
|
|
19886
|
+
import_fs12.default.rmdirSync(downloadedPath);
|
|
19776
19887
|
}
|
|
19777
|
-
const dbPath = (0,
|
|
19888
|
+
const dbPath = (0, import_path11.join)(tmpPath, DB_EXPORT_FILE);
|
|
19778
19889
|
await exportDB(appId, {
|
|
19779
19890
|
filter: defineFilter(config == null ? void 0 : config.excludeRows, config == null ? void 0 : config.excludeLogs),
|
|
19780
19891
|
exportPath: dbPath
|
|
19781
19892
|
});
|
|
19893
|
+
if (config == null ? void 0 : config.encryptPassword) {
|
|
19894
|
+
for (let file of import_fs12.default.readdirSync(tmpPath)) {
|
|
19895
|
+
const path2 = (0, import_path11.join)(tmpPath, file);
|
|
19896
|
+
await encryption_exports.encryptFile(
|
|
19897
|
+
{ dir: tmpPath, filename: file },
|
|
19898
|
+
config.encryptPassword
|
|
19899
|
+
);
|
|
19900
|
+
import_fs12.default.rmSync(path2);
|
|
19901
|
+
}
|
|
19902
|
+
}
|
|
19782
19903
|
if (config == null ? void 0 : config.tar) {
|
|
19783
|
-
const tarPath = tarFilesToTmp(tmpPath,
|
|
19784
|
-
|
|
19904
|
+
const tarPath = tarFilesToTmp(tmpPath, import_fs12.default.readdirSync(tmpPath));
|
|
19905
|
+
import_fs12.default.rmSync(tmpPath, { recursive: true, force: true });
|
|
19785
19906
|
return tarPath;
|
|
19786
19907
|
} else {
|
|
19787
19908
|
return tmpPath;
|
|
19788
19909
|
}
|
|
19789
19910
|
}
|
|
19790
|
-
async function streamExportApp(
|
|
19911
|
+
async function streamExportApp({
|
|
19912
|
+
appId,
|
|
19913
|
+
excludeRows,
|
|
19914
|
+
encryptPassword
|
|
19915
|
+
}) {
|
|
19791
19916
|
const tmpPath = await exportApp(appId, {
|
|
19792
19917
|
excludeRows,
|
|
19793
19918
|
excludeLogs: true,
|
|
19794
|
-
tar: true
|
|
19919
|
+
tar: true,
|
|
19920
|
+
encryptPassword
|
|
19795
19921
|
});
|
|
19796
19922
|
return streamFile(tmpPath);
|
|
19797
19923
|
}
|
|
19798
|
-
var
|
|
19924
|
+
var import_fs12, import_path11, import_tar2, uuid3, MemoryStream2;
|
|
19799
19925
|
var init_exports2 = __esm({
|
|
19800
19926
|
"src/sdk/app/backups/exports.ts"() {
|
|
19801
19927
|
init_src2();
|
|
@@ -19804,11 +19930,11 @@ var init_exports2 = __esm({
|
|
|
19804
19930
|
init_constants6();
|
|
19805
19931
|
init_utils13();
|
|
19806
19932
|
init_constants7();
|
|
19807
|
-
|
|
19808
|
-
|
|
19933
|
+
import_fs12 = __toESM(require("fs"));
|
|
19934
|
+
import_path11 = require("path");
|
|
19809
19935
|
init_environment();
|
|
19936
|
+
import_tar2 = __toESM(require("tar"));
|
|
19810
19937
|
uuid3 = require("uuid/v4");
|
|
19811
|
-
tar3 = require("tar");
|
|
19812
19938
|
MemoryStream2 = require("memorystream");
|
|
19813
19939
|
}
|
|
19814
19940
|
});
|
|
@@ -19885,16 +20011,16 @@ async function getTemplateStream(template) {
|
|
|
19885
20011
|
throw new Error("Cannot import a non-text based file.");
|
|
19886
20012
|
}
|
|
19887
20013
|
if (template.file) {
|
|
19888
|
-
return
|
|
20014
|
+
return import_fs13.default.createReadStream(template.file.path);
|
|
19889
20015
|
} else if (template.key) {
|
|
19890
|
-
const [type,
|
|
19891
|
-
const tmpPath = await downloadTemplate(type,
|
|
19892
|
-
return
|
|
20016
|
+
const [type, name2] = template.key.split("/");
|
|
20017
|
+
const tmpPath = await downloadTemplate(type, name2);
|
|
20018
|
+
return import_fs13.default.createReadStream((0, import_path12.join)(tmpPath, name2, "db", "dump.txt"));
|
|
19893
20019
|
}
|
|
19894
20020
|
}
|
|
19895
20021
|
function untarFile(file) {
|
|
19896
|
-
const tmpPath = (0,
|
|
19897
|
-
|
|
20022
|
+
const tmpPath = (0, import_path12.join)(budibaseTempDir2(), uuid4());
|
|
20023
|
+
import_fs13.default.mkdirSync(tmpPath);
|
|
19898
20024
|
tar4.extract({
|
|
19899
20025
|
sync: true,
|
|
19900
20026
|
cwd: tmpPath,
|
|
@@ -19902,31 +20028,49 @@ function untarFile(file) {
|
|
|
19902
20028
|
});
|
|
19903
20029
|
return tmpPath;
|
|
19904
20030
|
}
|
|
20031
|
+
async function decryptFiles(path2, password) {
|
|
20032
|
+
try {
|
|
20033
|
+
for (let file of import_fs13.default.readdirSync(path2)) {
|
|
20034
|
+
const inputPath = (0, import_path12.join)(path2, file);
|
|
20035
|
+
const outputPath = inputPath.replace(/\.enc$/, "");
|
|
20036
|
+
await encryption_exports.decryptFile(inputPath, outputPath, password);
|
|
20037
|
+
import_fs13.default.rmSync(inputPath);
|
|
20038
|
+
}
|
|
20039
|
+
} catch (err) {
|
|
20040
|
+
if (err.message === "incorrect header check") {
|
|
20041
|
+
throw new Error("File cannot be imported");
|
|
20042
|
+
}
|
|
20043
|
+
throw err;
|
|
20044
|
+
}
|
|
20045
|
+
}
|
|
19905
20046
|
function getGlobalDBFile(tmpPath) {
|
|
19906
|
-
return
|
|
20047
|
+
return import_fs13.default.readFileSync((0, import_path12.join)(tmpPath, GLOBAL_DB_EXPORT_FILE), "utf8");
|
|
19907
20048
|
}
|
|
19908
20049
|
function getListOfAppsInMulti(tmpPath) {
|
|
19909
|
-
return
|
|
20050
|
+
return import_fs13.default.readdirSync(tmpPath).filter((dir) => dir !== GLOBAL_DB_EXPORT_FILE);
|
|
19910
20051
|
}
|
|
19911
20052
|
async function importApp(appId, db2, template) {
|
|
19912
20053
|
var _a, _b;
|
|
19913
20054
|
let prodAppId = db_exports.getProdAppID(appId);
|
|
19914
20055
|
let dbStream;
|
|
19915
20056
|
const isTar = template.file && ((_b = (_a = template == null ? void 0 : template.file) == null ? void 0 : _a.type) == null ? void 0 : _b.endsWith("gzip"));
|
|
19916
|
-
const isDirectory = template.file &&
|
|
20057
|
+
const isDirectory = template.file && import_fs13.default.lstatSync(template.file.path).isDirectory();
|
|
19917
20058
|
if (template.file && (isTar || isDirectory)) {
|
|
19918
20059
|
const tmpPath = isTar ? untarFile(template.file) : template.file.path;
|
|
19919
|
-
|
|
20060
|
+
if (isTar && template.file.password) {
|
|
20061
|
+
await decryptFiles(tmpPath, template.file.password);
|
|
20062
|
+
}
|
|
20063
|
+
const contents = import_fs13.default.readdirSync(tmpPath);
|
|
19920
20064
|
if (contents.length) {
|
|
19921
20065
|
let promises = [];
|
|
19922
20066
|
let excludedFiles = [GLOBAL_DB_EXPORT_FILE, DB_EXPORT_FILE];
|
|
19923
20067
|
for (let filename of contents) {
|
|
19924
|
-
const path2 = (0,
|
|
20068
|
+
const path2 = (0, import_path12.join)(tmpPath, filename);
|
|
19925
20069
|
if (excludedFiles.includes(filename)) {
|
|
19926
20070
|
continue;
|
|
19927
20071
|
}
|
|
19928
|
-
filename = (0,
|
|
19929
|
-
if (
|
|
20072
|
+
filename = (0, import_path12.join)(prodAppId, filename);
|
|
20073
|
+
if (import_fs13.default.lstatSync(path2).isDirectory()) {
|
|
19930
20074
|
promises.push(
|
|
19931
20075
|
objectStore_exports2.uploadDirectory(ObjectStoreBuckets2.APPS, path2, filename)
|
|
19932
20076
|
);
|
|
@@ -19942,7 +20086,7 @@ async function importApp(appId, db2, template) {
|
|
|
19942
20086
|
}
|
|
19943
20087
|
await Promise.all(promises);
|
|
19944
20088
|
}
|
|
19945
|
-
dbStream =
|
|
20089
|
+
dbStream = import_fs13.default.createReadStream((0, import_path12.join)(tmpPath, DB_EXPORT_FILE));
|
|
19946
20090
|
} else {
|
|
19947
20091
|
dbStream = await getTemplateStream(template);
|
|
19948
20092
|
}
|
|
@@ -19954,7 +20098,7 @@ async function importApp(appId, db2, template) {
|
|
|
19954
20098
|
await updateAutomations(prodAppId, db2);
|
|
19955
20099
|
return ok;
|
|
19956
20100
|
}
|
|
19957
|
-
var
|
|
20101
|
+
var import_path12, import_fs13, uuid4, tar4;
|
|
19958
20102
|
var init_imports = __esm({
|
|
19959
20103
|
"src/sdk/app/backups/imports.ts"() {
|
|
19960
20104
|
init_src2();
|
|
@@ -19963,8 +20107,8 @@ var init_imports = __esm({
|
|
|
19963
20107
|
init_constants7();
|
|
19964
20108
|
init_fileSystem2();
|
|
19965
20109
|
init_constants6();
|
|
19966
|
-
|
|
19967
|
-
|
|
20110
|
+
import_path12 = require("path");
|
|
20111
|
+
import_fs13 = __toESM(require("fs"));
|
|
19968
20112
|
init_sdk3();
|
|
19969
20113
|
init_src();
|
|
19970
20114
|
uuid4 = require("uuid/v4");
|
|
@@ -20202,18 +20346,18 @@ function finaliseExternalTables(tables, entities) {
|
|
|
20202
20346
|
let finalTables = {};
|
|
20203
20347
|
const errors = {};
|
|
20204
20348
|
const tableIds = Object.values(tables).map((table) => table._id);
|
|
20205
|
-
for (let [
|
|
20349
|
+
for (let [name2, table] of Object.entries(tables)) {
|
|
20206
20350
|
const schemaFields = Object.keys(table.schema);
|
|
20207
20351
|
if (table.primary == null || table.primary.length === 0) {
|
|
20208
|
-
errors[
|
|
20352
|
+
errors[name2] = "no_key" /* NO_KEY */;
|
|
20209
20353
|
continue;
|
|
20210
20354
|
} else if (schemaFields.find(
|
|
20211
20355
|
(field) => invalidColumns.includes(field)
|
|
20212
20356
|
)) {
|
|
20213
|
-
errors[
|
|
20357
|
+
errors[name2] = "invalid_column" /* INVALID_COLUMN */;
|
|
20214
20358
|
continue;
|
|
20215
20359
|
}
|
|
20216
|
-
finalTables[
|
|
20360
|
+
finalTables[name2] = copyExistingPropsOver(name2, table, entities, tableIds);
|
|
20217
20361
|
}
|
|
20218
20362
|
finalTables = Object.entries(finalTables).sort(([a], [b]) => a.localeCompare(b)).reduce((r, [k, v]) => ({ ...r, [k]: v }), {});
|
|
20219
20363
|
return { tables: finalTables, errors };
|
|
@@ -21259,7 +21403,8 @@ var init_postgres = __esm({
|
|
|
21259
21403
|
try {
|
|
21260
21404
|
await this.openConnection();
|
|
21261
21405
|
const columnsResponse = await this.client.query(this.COLUMNS_SQL);
|
|
21262
|
-
|
|
21406
|
+
const names = columnsResponse.rows.map((row) => row.table_name);
|
|
21407
|
+
return [...new Set(names)];
|
|
21263
21408
|
} finally {
|
|
21264
21409
|
await this.closeConnection();
|
|
21265
21410
|
}
|
|
@@ -21888,6 +22033,8 @@ var init_mongodb = __esm({
|
|
|
21888
22033
|
response2.connected = true;
|
|
21889
22034
|
} catch (e) {
|
|
21890
22035
|
response2.error = e.message;
|
|
22036
|
+
} finally {
|
|
22037
|
+
await this.client.close();
|
|
21891
22038
|
}
|
|
21892
22039
|
return response2;
|
|
21893
22040
|
}
|
|
@@ -22108,21 +22255,21 @@ var init_mongodb = __esm({
|
|
|
22108
22255
|
const collection = db2.collection(query.extra.collection);
|
|
22109
22256
|
let response2 = [];
|
|
22110
22257
|
if (((_a = query.extra) == null ? void 0 : _a.actionType) === "pipeline") {
|
|
22111
|
-
for await (const
|
|
22258
|
+
for await (const doc2 of collection.aggregate(
|
|
22112
22259
|
query.steps.map(({ key, value }) => {
|
|
22113
22260
|
let temp = {};
|
|
22114
22261
|
temp[key] = JSON.parse(value.value);
|
|
22115
22262
|
return this.createObjectIds(temp);
|
|
22116
22263
|
})
|
|
22117
22264
|
)) {
|
|
22118
|
-
response2.push(
|
|
22265
|
+
response2.push(doc2);
|
|
22119
22266
|
}
|
|
22120
22267
|
} else {
|
|
22121
22268
|
const stages = query.json;
|
|
22122
|
-
for await (const
|
|
22269
|
+
for await (const doc2 of collection.aggregate(
|
|
22123
22270
|
stages ? this.createObjectIds(stages) : []
|
|
22124
22271
|
)) {
|
|
22125
|
-
response2.push(
|
|
22272
|
+
response2.push(doc2);
|
|
22126
22273
|
}
|
|
22127
22274
|
}
|
|
22128
22275
|
return response2;
|
|
@@ -22433,9 +22580,9 @@ var init_couchdb = __esm({
|
|
|
22433
22580
|
});
|
|
22434
22581
|
}
|
|
22435
22582
|
async delete(query) {
|
|
22436
|
-
const
|
|
22583
|
+
const doc2 = await this.query("get", "Cannot find doc to be deleted", query);
|
|
22437
22584
|
return this.query("remove", "Error deleting couchDB document", {
|
|
22438
|
-
json:
|
|
22585
|
+
json: doc2
|
|
22439
22586
|
});
|
|
22440
22587
|
}
|
|
22441
22588
|
};
|
|
@@ -22621,7 +22768,7 @@ var init_microsoftSqlServer = __esm({
|
|
|
22621
22768
|
throw "Unable to get list of tables in database";
|
|
22622
22769
|
}
|
|
22623
22770
|
const schema = this.config.schema || DEFAULT_SCHEMA;
|
|
22624
|
-
const tableNames = tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((
|
|
22771
|
+
const tableNames = tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name2) => this.MASTER_TABLES.indexOf(name2) === -1);
|
|
22625
22772
|
const tables = {};
|
|
22626
22773
|
for (let tableName of tableNames) {
|
|
22627
22774
|
const definition26 = await this.runSQL(this.getDefinitionSQL(tableName));
|
|
@@ -22636,16 +22783,16 @@ var init_microsoftSqlServer = __esm({
|
|
|
22636
22783
|
const requiredColumns = columns.filter((col) => col.IS_NULLABLE === "NO").map((col) => col.COLUMN_NAME);
|
|
22637
22784
|
let schema2 = {};
|
|
22638
22785
|
for (let def of definition26) {
|
|
22639
|
-
const
|
|
22640
|
-
if (typeof
|
|
22786
|
+
const name2 = def.COLUMN_NAME;
|
|
22787
|
+
if (typeof name2 !== "string") {
|
|
22641
22788
|
continue;
|
|
22642
22789
|
}
|
|
22643
22790
|
const hasDefault = def.COLUMN_DEFAULT;
|
|
22644
|
-
const isAuto = !!autoColumns.find((col) => col ===
|
|
22645
|
-
const required = !!requiredColumns.find((col) => col ===
|
|
22646
|
-
schema2[
|
|
22791
|
+
const isAuto = !!autoColumns.find((col) => col === name2);
|
|
22792
|
+
const required = !!requiredColumns.find((col) => col === name2);
|
|
22793
|
+
schema2[name2] = {
|
|
22647
22794
|
autocolumn: isAuto,
|
|
22648
|
-
name,
|
|
22795
|
+
name: name2,
|
|
22649
22796
|
constraints: {
|
|
22650
22797
|
presence: required && !isAuto && !hasDefault
|
|
22651
22798
|
},
|
|
@@ -22667,7 +22814,7 @@ var init_microsoftSqlServer = __esm({
|
|
|
22667
22814
|
async queryTableNames() {
|
|
22668
22815
|
let tableInfo = await this.runSQL(this.TABLES_SQL);
|
|
22669
22816
|
const schema = this.config.schema || DEFAULT_SCHEMA;
|
|
22670
|
-
return tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((
|
|
22817
|
+
return tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name2) => this.MASTER_TABLES.indexOf(name2) === -1);
|
|
22671
22818
|
}
|
|
22672
22819
|
async getTableNames() {
|
|
22673
22820
|
await this.connect();
|
|
@@ -23814,6 +23961,16 @@ var init_rest = __esm({
|
|
|
23814
23961
|
});
|
|
23815
23962
|
|
|
23816
23963
|
// src/integrations/googlesheets.ts
|
|
23964
|
+
async function setupCreationAuth(datasouce) {
|
|
23965
|
+
if (datasouce.continueSetupId) {
|
|
23966
|
+
const appId = context_exports.getAppId();
|
|
23967
|
+
const tokens = await cache_exports.get(
|
|
23968
|
+
`datasource:creation:${appId}:google:${datasouce.continueSetupId}`
|
|
23969
|
+
);
|
|
23970
|
+
datasouce.auth = tokens.tokens;
|
|
23971
|
+
delete datasouce.continueSetupId;
|
|
23972
|
+
}
|
|
23973
|
+
}
|
|
23817
23974
|
var import_google_auth_library, import_google_spreadsheet, import_node_fetch9, ALLOWED_TYPES, SCHEMA12, GoogleSheetsIntegration, googlesheets_default;
|
|
23818
23975
|
var init_googlesheets = __esm({
|
|
23819
23976
|
"src/integrations/googlesheets.ts"() {
|
|
@@ -23851,7 +24008,7 @@ var init_googlesheets = __esm({
|
|
|
23851
24008
|
},
|
|
23852
24009
|
datasource: {
|
|
23853
24010
|
spreadsheetId: {
|
|
23854
|
-
display: "
|
|
24011
|
+
display: "Spreadsheet URL",
|
|
23855
24012
|
type: "string" /* STRING */,
|
|
23856
24013
|
required: true
|
|
23857
24014
|
}
|
|
@@ -23972,6 +24129,7 @@ var init_googlesheets = __esm({
|
|
|
23972
24129
|
async connect() {
|
|
23973
24130
|
var _a;
|
|
23974
24131
|
try {
|
|
24132
|
+
await setupCreationAuth(this.config);
|
|
23975
24133
|
let googleConfig = await configs_exports.getGoogleDatasourceConfig();
|
|
23976
24134
|
if (!googleConfig) {
|
|
23977
24135
|
throw new HTTPError("Google config not found", 400);
|
|
@@ -24022,21 +24180,22 @@ var init_googlesheets = __esm({
|
|
|
24022
24180
|
return table;
|
|
24023
24181
|
}
|
|
24024
24182
|
async buildSchema(datasourceId, entities) {
|
|
24025
|
-
if (!this.config.auth) {
|
|
24026
|
-
return;
|
|
24027
|
-
}
|
|
24028
24183
|
await this.connect();
|
|
24029
24184
|
const sheets = this.client.sheetsByIndex;
|
|
24030
24185
|
const tables = {};
|
|
24031
|
-
|
|
24032
|
-
|
|
24033
|
-
|
|
24034
|
-
|
|
24035
|
-
sheet.title
|
|
24036
|
-
sheet.
|
|
24037
|
-
|
|
24038
|
-
|
|
24039
|
-
|
|
24186
|
+
await utils_exports5.parallelForeach(
|
|
24187
|
+
sheets,
|
|
24188
|
+
async (sheet) => {
|
|
24189
|
+
await sheet.getRows({ limit: 0, offset: 0 });
|
|
24190
|
+
const id = buildExternalTableId(datasourceId, sheet.title);
|
|
24191
|
+
tables[sheet.title] = this.getTableSchema(
|
|
24192
|
+
sheet.title,
|
|
24193
|
+
sheet.headerValues,
|
|
24194
|
+
id
|
|
24195
|
+
);
|
|
24196
|
+
},
|
|
24197
|
+
10
|
|
24198
|
+
);
|
|
24040
24199
|
const final = finaliseExternalTables(tables, entities);
|
|
24041
24200
|
this.tables = final.tables;
|
|
24042
24201
|
this.schemaErrors = final.errors;
|
|
@@ -24084,13 +24243,13 @@ var init_googlesheets = __esm({
|
|
|
24084
24243
|
}
|
|
24085
24244
|
return rowObject;
|
|
24086
24245
|
}
|
|
24087
|
-
async createTable(
|
|
24088
|
-
if (!
|
|
24246
|
+
async createTable(name2) {
|
|
24247
|
+
if (!name2) {
|
|
24089
24248
|
throw new Error("Must provide name for new sheet.");
|
|
24090
24249
|
}
|
|
24091
24250
|
try {
|
|
24092
24251
|
await this.connect();
|
|
24093
|
-
return await this.client.addSheet({ title:
|
|
24252
|
+
return await this.client.addSheet({ title: name2, headerValues: [name2] });
|
|
24094
24253
|
} catch (err) {
|
|
24095
24254
|
console.error("Error creating new table in google sheets", err);
|
|
24096
24255
|
throw err;
|
|
@@ -24416,7 +24575,7 @@ var init_firebase = __esm({
|
|
|
24416
24575
|
snapshot = await collectionRef.get();
|
|
24417
24576
|
}
|
|
24418
24577
|
const result = [];
|
|
24419
|
-
snapshot.forEach((
|
|
24578
|
+
snapshot.forEach((doc2) => result.push(doc2.data()));
|
|
24420
24579
|
return result;
|
|
24421
24580
|
} catch (err) {
|
|
24422
24581
|
console.error("Error querying Firestore", err);
|
|
@@ -25078,13 +25237,13 @@ var init_oracle = __esm({
|
|
|
25078
25237
|
});
|
|
25079
25238
|
|
|
25080
25239
|
// src/integrations/index.ts
|
|
25081
|
-
async function getDefinition(
|
|
25082
|
-
const definition26 = DEFINITIONS2[
|
|
25240
|
+
async function getDefinition(source2) {
|
|
25241
|
+
const definition26 = DEFINITIONS2[source2];
|
|
25083
25242
|
if (definition26) {
|
|
25084
25243
|
return definition26;
|
|
25085
25244
|
}
|
|
25086
25245
|
const allDefinitions = await getDefinitions();
|
|
25087
|
-
return allDefinitions[
|
|
25246
|
+
return allDefinitions[source2];
|
|
25088
25247
|
}
|
|
25089
25248
|
async function getDefinitions() {
|
|
25090
25249
|
const pluginSchemas = {};
|
|
@@ -25420,10 +25579,10 @@ __export(webhook_exports2, {
|
|
|
25420
25579
|
function isWebhookID(id) {
|
|
25421
25580
|
return id.startsWith(db_exports.DocumentType.WEBHOOK);
|
|
25422
25581
|
}
|
|
25423
|
-
function newDoc(
|
|
25582
|
+
function newDoc(name2, type, target) {
|
|
25424
25583
|
return {
|
|
25425
25584
|
live: true,
|
|
25426
|
-
name,
|
|
25585
|
+
name: name2,
|
|
25427
25586
|
action: {
|
|
25428
25587
|
type,
|
|
25429
25588
|
target
|
|
@@ -25441,12 +25600,12 @@ async function save7(webhook) {
|
|
|
25441
25600
|
webhook._rev = response2.rev;
|
|
25442
25601
|
return webhook;
|
|
25443
25602
|
}
|
|
25444
|
-
async function destroy6(id,
|
|
25603
|
+
async function destroy6(id, rev2) {
|
|
25445
25604
|
const db2 = context_exports.getAppDB();
|
|
25446
25605
|
if (!id || !isWebhookID(id)) {
|
|
25447
25606
|
throw new Error("Provided webhook ID is not valid.");
|
|
25448
25607
|
}
|
|
25449
|
-
return await db2.remove(id,
|
|
25608
|
+
return await db2.remove(id, rev2);
|
|
25450
25609
|
}
|
|
25451
25610
|
var init_webhook2 = __esm({
|
|
25452
25611
|
"src/sdk/app/automations/webhook.ts"() {
|
|
@@ -25623,9 +25782,9 @@ async function syncUsersToApp(appId, users2, groups) {
|
|
|
25623
25782
|
if (roleId === roles_exports.BUILTIN_ROLE_IDS.PUBLIC) {
|
|
25624
25783
|
roleId = void 0;
|
|
25625
25784
|
}
|
|
25626
|
-
let
|
|
25785
|
+
let metadata2;
|
|
25627
25786
|
try {
|
|
25628
|
-
|
|
25787
|
+
metadata2 = await db2.get(metadataId);
|
|
25629
25788
|
} catch (err) {
|
|
25630
25789
|
if (err.status !== 404) {
|
|
25631
25790
|
throw err;
|
|
@@ -25633,19 +25792,19 @@ async function syncUsersToApp(appId, users2, groups) {
|
|
|
25633
25792
|
if (!roleId) {
|
|
25634
25793
|
continue;
|
|
25635
25794
|
} else if (!deletedUser) {
|
|
25636
|
-
|
|
25795
|
+
metadata2 = {
|
|
25637
25796
|
tableId: InternalTables.USER_METADATA
|
|
25638
25797
|
};
|
|
25639
25798
|
}
|
|
25640
25799
|
}
|
|
25641
25800
|
if (deletedUser || !roleId) {
|
|
25642
|
-
await db2.remove(
|
|
25801
|
+
await db2.remove(metadata2);
|
|
25643
25802
|
continue;
|
|
25644
25803
|
}
|
|
25645
25804
|
if (roleId) {
|
|
25646
|
-
|
|
25805
|
+
metadata2.roleId = roleId;
|
|
25647
25806
|
}
|
|
25648
|
-
let combined = sdk_default.users.combineMetadataAndUser(ctxUser,
|
|
25807
|
+
let combined = sdk_default.users.combineMetadataAndUser(ctxUser, metadata2);
|
|
25649
25808
|
if (combined) {
|
|
25650
25809
|
await db2.put(combined);
|
|
25651
25810
|
}
|
|
@@ -25702,7 +25861,7 @@ async function syncApp(appId, opts) {
|
|
|
25702
25861
|
try {
|
|
25703
25862
|
const replOpts = replication.appReplicateOpts();
|
|
25704
25863
|
if (opts == null ? void 0 : opts.automationOnly) {
|
|
25705
|
-
replOpts.filter = (
|
|
25864
|
+
replOpts.filter = (doc2) => doc2._id.startsWith(db_exports.DocumentType.AUTOMATION);
|
|
25706
25865
|
}
|
|
25707
25866
|
await replication.replicate(replOpts);
|
|
25708
25867
|
} catch (err) {
|
|
@@ -25929,9 +26088,9 @@ __export(utils_exports8, {
|
|
|
25929
26088
|
rawUserMetadata: () => rawUserMetadata,
|
|
25930
26089
|
syncGlobalUsers: () => syncGlobalUsers
|
|
25931
26090
|
});
|
|
25932
|
-
function combineMetadataAndUser(user,
|
|
26091
|
+
function combineMetadataAndUser(user, metadata2) {
|
|
25933
26092
|
const metadataId = generateUserMetadataID2(user._id);
|
|
25934
|
-
const found = Array.isArray(
|
|
26093
|
+
const found = Array.isArray(metadata2) ? metadata2.find((doc2) => doc2._id === metadataId) : metadata2;
|
|
25935
26094
|
if (user.roleId == null || user.roleId === roles_exports.BUILTIN_ROLE_IDS.PUBLIC) {
|
|
25936
26095
|
if (found == null ? void 0 : found._id) {
|
|
25937
26096
|
return { ...found, _deleted: true };
|
|
@@ -25976,16 +26135,16 @@ async function syncGlobalUsers() {
|
|
|
25976
26135
|
}
|
|
25977
26136
|
const resp = await Promise.all([getGlobalUsers(), rawUserMetadata(db2)]);
|
|
25978
26137
|
const users2 = resp[0];
|
|
25979
|
-
const
|
|
26138
|
+
const metadata2 = resp[1];
|
|
25980
26139
|
const toWrite = [];
|
|
25981
26140
|
for (let user of users2) {
|
|
25982
|
-
const combined = combineMetadataAndUser(user,
|
|
26141
|
+
const combined = combineMetadataAndUser(user, metadata2);
|
|
25983
26142
|
if (combined) {
|
|
25984
26143
|
toWrite.push(combined);
|
|
25985
26144
|
}
|
|
25986
26145
|
}
|
|
25987
26146
|
let foundEmails = [];
|
|
25988
|
-
for (let data2 of
|
|
26147
|
+
for (let data2 of metadata2) {
|
|
25989
26148
|
if (!data2._id) {
|
|
25990
26149
|
continue;
|
|
25991
26150
|
}
|
|
@@ -26114,17 +26273,17 @@ var init_client2 = __esm({
|
|
|
26114
26273
|
// src/utilities/users.ts
|
|
26115
26274
|
async function getFullUser(ctx, userId) {
|
|
26116
26275
|
const global = await getGlobalUser(userId);
|
|
26117
|
-
let
|
|
26276
|
+
let metadata2 = {};
|
|
26118
26277
|
delete global._id;
|
|
26119
26278
|
delete global._rev;
|
|
26120
26279
|
try {
|
|
26121
26280
|
const db2 = context_exports.getAppDB();
|
|
26122
|
-
|
|
26281
|
+
metadata2 = await db2.get(userId);
|
|
26123
26282
|
} catch (err) {
|
|
26124
26283
|
}
|
|
26125
|
-
delete
|
|
26284
|
+
delete metadata2.csrfToken;
|
|
26126
26285
|
return {
|
|
26127
|
-
...
|
|
26286
|
+
...metadata2,
|
|
26128
26287
|
...global,
|
|
26129
26288
|
roleId: global.roleId || roles_exports.BUILTIN_ROLE_IDS.PUBLIC,
|
|
26130
26289
|
tableId: InternalTables.USER_METADATA,
|
|
@@ -26143,10 +26302,10 @@ var init_users12 = __esm({
|
|
|
26143
26302
|
// src/api/controllers/user.ts
|
|
26144
26303
|
async function fetchMetadata(ctx) {
|
|
26145
26304
|
const global = await getGlobalUsers();
|
|
26146
|
-
const
|
|
26305
|
+
const metadata2 = await sdk_default.users.rawUserMetadata();
|
|
26147
26306
|
const users2 = [];
|
|
26148
26307
|
for (let user of global) {
|
|
26149
|
-
const info =
|
|
26308
|
+
const info = metadata2.find((meta) => meta._id.includes(user._id));
|
|
26150
26309
|
users2.push({
|
|
26151
26310
|
...user,
|
|
26152
26311
|
...info,
|
|
@@ -26161,11 +26320,11 @@ async function updateMetadata(ctx) {
|
|
|
26161
26320
|
const db2 = context_exports.getAppDB();
|
|
26162
26321
|
const user = ctx.request.body;
|
|
26163
26322
|
delete user.roles;
|
|
26164
|
-
const
|
|
26323
|
+
const metadata2 = {
|
|
26165
26324
|
tableId: InternalTables.USER_METADATA,
|
|
26166
26325
|
...user
|
|
26167
26326
|
};
|
|
26168
|
-
ctx.body = await db2.put(
|
|
26327
|
+
ctx.body = await db2.put(metadata2);
|
|
26169
26328
|
}
|
|
26170
26329
|
async function destroyMetadata(ctx) {
|
|
26171
26330
|
const db2 = context_exports.getAppDB();
|
|
@@ -26463,16 +26622,16 @@ async function fetch16(type) {
|
|
|
26463
26622
|
return plugins2;
|
|
26464
26623
|
}
|
|
26465
26624
|
}
|
|
26466
|
-
async function processUploaded(plugin,
|
|
26625
|
+
async function processUploaded(plugin, source2) {
|
|
26467
26626
|
var _a, _b;
|
|
26468
|
-
const { metadata, directory } = await fileUpload(plugin);
|
|
26469
|
-
plugin_exports.validate(
|
|
26470
|
-
if (!environment_default.SELF_HOSTED && ((_a =
|
|
26627
|
+
const { metadata: metadata2, directory: directory2 } = await fileUpload(plugin);
|
|
26628
|
+
plugin_exports.validate(metadata2 == null ? void 0 : metadata2.schema);
|
|
26629
|
+
if (!environment_default.SELF_HOSTED && ((_a = metadata2 == null ? void 0 : metadata2.schema) == null ? void 0 : _a.type) !== "component" /* COMPONENT */) {
|
|
26471
26630
|
throw new Error("Only component plugins are supported outside of self-host");
|
|
26472
26631
|
}
|
|
26473
|
-
const
|
|
26474
|
-
(_b = clientAppSocket) == null ? void 0 : _b.emit("plugin-update", { name:
|
|
26475
|
-
return
|
|
26632
|
+
const doc2 = await sdk_exports.plugins.storePlugin(metadata2, directory2, source2);
|
|
26633
|
+
(_b = clientAppSocket) == null ? void 0 : _b.emit("plugin-update", { name: doc2.name, hash: doc2.hash });
|
|
26634
|
+
return doc2;
|
|
26476
26635
|
}
|
|
26477
26636
|
var init_plugins4 = __esm({
|
|
26478
26637
|
"src/sdk/plugins/plugins.ts"() {
|
|
@@ -26892,22 +27051,22 @@ function threadSetup() {
|
|
|
26892
27051
|
init8();
|
|
26893
27052
|
}
|
|
26894
27053
|
async function checkCacheForDynamicVariable(queryId, variable) {
|
|
26895
|
-
const
|
|
26896
|
-
return
|
|
27054
|
+
const cache3 = await getClient2();
|
|
27055
|
+
return cache3.get(makeVariableKey(queryId, variable));
|
|
26897
27056
|
}
|
|
26898
27057
|
async function invalidateDynamicVariables(cachedVars) {
|
|
26899
|
-
const
|
|
27058
|
+
const cache3 = await getClient2();
|
|
26900
27059
|
let promises = [];
|
|
26901
27060
|
for (let variable of cachedVars) {
|
|
26902
27061
|
promises.push(
|
|
26903
|
-
|
|
27062
|
+
cache3.delete(makeVariableKey(variable.queryId, variable.name))
|
|
26904
27063
|
);
|
|
26905
27064
|
}
|
|
26906
27065
|
await Promise.all(promises);
|
|
26907
27066
|
}
|
|
26908
27067
|
async function storeDynamicVariable(queryId, variable, value) {
|
|
26909
|
-
const
|
|
26910
|
-
await
|
|
27068
|
+
const cache3 = await getClient2();
|
|
27069
|
+
await cache3.store(
|
|
26911
27070
|
makeVariableKey(queryId, variable),
|
|
26912
27071
|
value,
|
|
26913
27072
|
VARIABLE_TTL_SECONDS
|
|
@@ -27375,7 +27534,16 @@ async function checkResponse(response2, errorMsg, { ctx } = {}) {
|
|
|
27375
27534
|
}
|
|
27376
27535
|
return response2.json();
|
|
27377
27536
|
}
|
|
27378
|
-
async function sendSmtpEmail(
|
|
27537
|
+
async function sendSmtpEmail({
|
|
27538
|
+
to,
|
|
27539
|
+
from,
|
|
27540
|
+
subject,
|
|
27541
|
+
contents,
|
|
27542
|
+
cc,
|
|
27543
|
+
bcc,
|
|
27544
|
+
automation,
|
|
27545
|
+
invite
|
|
27546
|
+
}) {
|
|
27379
27547
|
const response2 = await (0, import_node_fetch10.default)(
|
|
27380
27548
|
checkSlashesInUrl2(environment_default.WORKER_URL + `/api/global/email/send`),
|
|
27381
27549
|
request(void 0, {
|
|
@@ -27388,7 +27556,8 @@ async function sendSmtpEmail(to, from, subject, contents, cc, bcc, automation) {
|
|
|
27388
27556
|
cc,
|
|
27389
27557
|
bcc,
|
|
27390
27558
|
purpose: "custom",
|
|
27391
|
-
automation
|
|
27559
|
+
automation,
|
|
27560
|
+
invite
|
|
27392
27561
|
}
|
|
27393
27562
|
})
|
|
27394
27563
|
);
|
|
@@ -27436,6 +27605,35 @@ var definition7 = {
|
|
|
27436
27605
|
contents: {
|
|
27437
27606
|
type: "string" /* STRING */,
|
|
27438
27607
|
title: "HTML Contents"
|
|
27608
|
+
},
|
|
27609
|
+
addInvite: {
|
|
27610
|
+
type: "boolean" /* BOOLEAN */,
|
|
27611
|
+
title: "Add calendar invite"
|
|
27612
|
+
},
|
|
27613
|
+
startTime: {
|
|
27614
|
+
type: "date" /* DATE */,
|
|
27615
|
+
title: "Start Time",
|
|
27616
|
+
dependsOn: "addInvite"
|
|
27617
|
+
},
|
|
27618
|
+
endTime: {
|
|
27619
|
+
type: "date" /* DATE */,
|
|
27620
|
+
title: "End Time",
|
|
27621
|
+
dependsOn: "addInvite"
|
|
27622
|
+
},
|
|
27623
|
+
summary: {
|
|
27624
|
+
type: "string" /* STRING */,
|
|
27625
|
+
title: "Meeting Summary",
|
|
27626
|
+
dependsOn: "addInvite"
|
|
27627
|
+
},
|
|
27628
|
+
location: {
|
|
27629
|
+
type: "string" /* STRING */,
|
|
27630
|
+
title: "Location",
|
|
27631
|
+
dependsOn: "addInvite"
|
|
27632
|
+
},
|
|
27633
|
+
url: {
|
|
27634
|
+
type: "string" /* STRING */,
|
|
27635
|
+
title: "URL",
|
|
27636
|
+
dependsOn: "addInvite"
|
|
27439
27637
|
}
|
|
27440
27638
|
},
|
|
27441
27639
|
required: ["to", "from", "subject", "contents"]
|
|
@@ -27456,21 +27654,41 @@ var definition7 = {
|
|
|
27456
27654
|
}
|
|
27457
27655
|
};
|
|
27458
27656
|
async function run3({ inputs }) {
|
|
27459
|
-
let {
|
|
27657
|
+
let {
|
|
27658
|
+
to,
|
|
27659
|
+
from,
|
|
27660
|
+
subject,
|
|
27661
|
+
contents,
|
|
27662
|
+
cc,
|
|
27663
|
+
bcc,
|
|
27664
|
+
addInvite,
|
|
27665
|
+
startTime,
|
|
27666
|
+
endTime,
|
|
27667
|
+
summary,
|
|
27668
|
+
location,
|
|
27669
|
+
url
|
|
27670
|
+
} = inputs;
|
|
27460
27671
|
if (!contents) {
|
|
27461
27672
|
contents = "<h1>No content</h1>";
|
|
27462
27673
|
}
|
|
27463
27674
|
to = to || void 0;
|
|
27464
27675
|
try {
|
|
27465
|
-
let response2 = await sendSmtpEmail(
|
|
27676
|
+
let response2 = await sendSmtpEmail({
|
|
27466
27677
|
to,
|
|
27467
27678
|
from,
|
|
27468
27679
|
subject,
|
|
27469
27680
|
contents,
|
|
27470
27681
|
cc,
|
|
27471
27682
|
bcc,
|
|
27472
|
-
true
|
|
27473
|
-
|
|
27683
|
+
automation: true,
|
|
27684
|
+
invite: addInvite ? {
|
|
27685
|
+
startTime,
|
|
27686
|
+
endTime,
|
|
27687
|
+
summary,
|
|
27688
|
+
location,
|
|
27689
|
+
url
|
|
27690
|
+
} : void 0
|
|
27691
|
+
});
|
|
27474
27692
|
return {
|
|
27475
27693
|
success: true,
|
|
27476
27694
|
response: response2
|
|
@@ -27514,20 +27732,20 @@ async function createLinkView() {
|
|
|
27514
27732
|
const db2 = context_exports.getAppDB();
|
|
27515
27733
|
const designDoc = await db2.get("_design/database");
|
|
27516
27734
|
const view2 = {
|
|
27517
|
-
map: function(
|
|
27518
|
-
if (
|
|
27519
|
-
let doc1 =
|
|
27520
|
-
let
|
|
27735
|
+
map: function(doc2) {
|
|
27736
|
+
if (doc2.type === "link") {
|
|
27737
|
+
let doc1 = doc2.doc1;
|
|
27738
|
+
let doc22 = doc2.doc2;
|
|
27521
27739
|
emit([doc1.tableId, doc1.rowId], {
|
|
27522
|
-
id:
|
|
27740
|
+
id: doc22.rowId,
|
|
27523
27741
|
thisId: doc1.rowId,
|
|
27524
27742
|
fieldName: doc1.fieldName
|
|
27525
27743
|
});
|
|
27526
|
-
if (doc1.tableId !==
|
|
27527
|
-
emit([
|
|
27744
|
+
if (doc1.tableId !== doc22.tableId) {
|
|
27745
|
+
emit([doc22.tableId, doc22.rowId], {
|
|
27528
27746
|
id: doc1.rowId,
|
|
27529
|
-
thisId:
|
|
27530
|
-
fieldName:
|
|
27747
|
+
thisId: doc22.rowId,
|
|
27748
|
+
fieldName: doc22.fieldName
|
|
27531
27749
|
});
|
|
27532
27750
|
}
|
|
27533
27751
|
}
|
|
@@ -27829,11 +28047,11 @@ var LinkController = class {
|
|
|
27829
28047
|
);
|
|
27830
28048
|
}
|
|
27831
28049
|
}
|
|
27832
|
-
let toDeleteDocs = thisFieldLinkDocs.filter((
|
|
27833
|
-
let correctDoc =
|
|
28050
|
+
let toDeleteDocs = thisFieldLinkDocs.filter((doc2) => {
|
|
28051
|
+
let correctDoc = doc2.doc1.fieldName === fieldName ? doc2.doc2 : doc2.doc1;
|
|
27834
28052
|
return rowField.indexOf(correctDoc.rowId) === -1;
|
|
27835
|
-
}).map((
|
|
27836
|
-
return { ...
|
|
28053
|
+
}).map((doc2) => {
|
|
28054
|
+
return { ...doc2, _deleted: true };
|
|
27837
28055
|
});
|
|
27838
28056
|
operations.push(...toDeleteDocs);
|
|
27839
28057
|
delete row[fieldName];
|
|
@@ -27854,9 +28072,9 @@ var LinkController = class {
|
|
|
27854
28072
|
if (linkDocs.length === 0) {
|
|
27855
28073
|
return null;
|
|
27856
28074
|
}
|
|
27857
|
-
const toDelete = linkDocs.map((
|
|
28075
|
+
const toDelete = linkDocs.map((doc2) => {
|
|
27858
28076
|
return {
|
|
27859
|
-
...
|
|
28077
|
+
...doc2,
|
|
27860
28078
|
_deleted: true
|
|
27861
28079
|
};
|
|
27862
28080
|
});
|
|
@@ -27877,9 +28095,9 @@ var LinkController = class {
|
|
|
27877
28095
|
return correctFieldName === fieldName;
|
|
27878
28096
|
});
|
|
27879
28097
|
await this._db.bulkDocs(
|
|
27880
|
-
toDelete.map((
|
|
28098
|
+
toDelete.map((doc2) => {
|
|
27881
28099
|
return {
|
|
27882
|
-
...
|
|
28100
|
+
...doc2,
|
|
27883
28101
|
_deleted: true
|
|
27884
28102
|
};
|
|
27885
28103
|
})
|
|
@@ -27977,9 +28195,9 @@ var LinkController = class {
|
|
|
27977
28195
|
if (linkDocs.length === 0) {
|
|
27978
28196
|
return null;
|
|
27979
28197
|
}
|
|
27980
|
-
const toDelete = linkDocs.map((
|
|
28198
|
+
const toDelete = linkDocs.map((doc2) => {
|
|
27981
28199
|
return {
|
|
27982
|
-
...
|
|
28200
|
+
...doc2,
|
|
27983
28201
|
_deleted: true
|
|
27984
28202
|
};
|
|
27985
28203
|
});
|
|
@@ -28318,10 +28536,10 @@ async function cleanupAttachments(table, {
|
|
|
28318
28536
|
return;
|
|
28319
28537
|
}
|
|
28320
28538
|
}
|
|
28321
|
-
let
|
|
28539
|
+
let files2 = [];
|
|
28322
28540
|
function addFiles(row2, key) {
|
|
28323
28541
|
if (row2[key]) {
|
|
28324
|
-
|
|
28542
|
+
files2 = files2.concat(row2[key].map((attachment) => attachment.key));
|
|
28325
28543
|
}
|
|
28326
28544
|
}
|
|
28327
28545
|
const schemaToUse = oldTable ? oldTable.schema : table.schema;
|
|
@@ -28332,15 +28550,15 @@ async function cleanupAttachments(table, {
|
|
|
28332
28550
|
if (rows2 && oldTable && !table.schema[key]) {
|
|
28333
28551
|
rows2.forEach((row2) => addFiles(row2, key));
|
|
28334
28552
|
} else if (oldRow && row) {
|
|
28335
|
-
|
|
28553
|
+
files2 = files2.concat(getRemovedAttachmentKeys(oldRow, row, key));
|
|
28336
28554
|
} else if (row) {
|
|
28337
28555
|
addFiles(row, key);
|
|
28338
28556
|
} else if (rows2) {
|
|
28339
28557
|
rows2.forEach((row2) => addFiles(row2, key));
|
|
28340
28558
|
}
|
|
28341
28559
|
}
|
|
28342
|
-
if (
|
|
28343
|
-
await objectStore_exports2.deleteFiles(ObjectStoreBuckets2.APPS,
|
|
28560
|
+
if (files2.length > 0) {
|
|
28561
|
+
await objectStore_exports2.deleteFiles(ObjectStoreBuckets2.APPS, files2);
|
|
28344
28562
|
}
|
|
28345
28563
|
}
|
|
28346
28564
|
|
|
@@ -28515,7 +28733,7 @@ async function runView(view, calculation, group, data) {
|
|
|
28515
28733
|
_rev: void 0
|
|
28516
28734
|
}))
|
|
28517
28735
|
);
|
|
28518
|
-
let fn = (
|
|
28736
|
+
let fn = (doc2, emit2) => emit2(doc2._id);
|
|
28519
28737
|
eval("fn = " + ((_a = view == null ? void 0 : view.map) == null ? void 0 : _a.replace("function (doc)", "function (doc, emit)")));
|
|
28520
28738
|
const queryFns = {
|
|
28521
28739
|
meta: view.meta,
|
|
@@ -29281,7 +29499,7 @@ function cleanupConfig(config, table) {
|
|
|
29281
29499
|
const fieldNames = Object.entries(table.schema).filter((schema) => primaryOptions.find((val) => val === schema[1].type)).map(([fieldName]) => fieldName);
|
|
29282
29500
|
const iterateObject = (obj) => {
|
|
29283
29501
|
for (let [field, value] of Object.entries(obj)) {
|
|
29284
|
-
if (fieldNames.find((
|
|
29502
|
+
if (fieldNames.find((name2) => name2 === field) && isRowId(value)) {
|
|
29285
29503
|
obj[field] = convertRowId(value);
|
|
29286
29504
|
}
|
|
29287
29505
|
}
|
|
@@ -30691,8 +30909,15 @@ init_constants6();
|
|
|
30691
30909
|
init_integrations2();
|
|
30692
30910
|
init_utils20();
|
|
30693
30911
|
init_src2();
|
|
30912
|
+
init_src();
|
|
30694
30913
|
init_sdk3();
|
|
30695
30914
|
init_websockets();
|
|
30915
|
+
init_googlesheets();
|
|
30916
|
+
var preSaveAction = {
|
|
30917
|
+
["GOOGLE_SHEETS" /* GOOGLE_SHEETS */]: async (datasource2) => {
|
|
30918
|
+
await setupCreationAuth(datasource2.config);
|
|
30919
|
+
}
|
|
30920
|
+
};
|
|
30696
30921
|
|
|
30697
30922
|
// src/api/controllers/query/validation.ts
|
|
30698
30923
|
init_src2();
|
|
@@ -31987,7 +32212,7 @@ function rowEmission({
|
|
|
31987
32212
|
appId,
|
|
31988
32213
|
row,
|
|
31989
32214
|
table,
|
|
31990
|
-
metadata
|
|
32215
|
+
metadata: metadata2
|
|
31991
32216
|
}) {
|
|
31992
32217
|
let event = {
|
|
31993
32218
|
row,
|
|
@@ -32001,8 +32226,8 @@ function rowEmission({
|
|
|
32001
32226
|
if (row == null ? void 0 : row._rev) {
|
|
32002
32227
|
event.revision = row._rev;
|
|
32003
32228
|
}
|
|
32004
|
-
if (
|
|
32005
|
-
event.metadata =
|
|
32229
|
+
if (metadata2) {
|
|
32230
|
+
event.metadata = metadata2;
|
|
32006
32231
|
}
|
|
32007
32232
|
emitter2.emit(eventName, event);
|
|
32008
32233
|
}
|
|
@@ -32011,7 +32236,7 @@ function tableEmission({
|
|
|
32011
32236
|
eventName,
|
|
32012
32237
|
appId,
|
|
32013
32238
|
table,
|
|
32014
|
-
metadata
|
|
32239
|
+
metadata: metadata2
|
|
32015
32240
|
}) {
|
|
32016
32241
|
const tableId = table == null ? void 0 : table._id;
|
|
32017
32242
|
const inputTable = table;
|
|
@@ -32027,8 +32252,8 @@ function tableEmission({
|
|
|
32027
32252
|
if (table == null ? void 0 : table._rev) {
|
|
32028
32253
|
event.revision = table._rev;
|
|
32029
32254
|
}
|
|
32030
|
-
if (
|
|
32031
|
-
event.metadata =
|
|
32255
|
+
if (metadata2) {
|
|
32256
|
+
event.metadata = metadata2;
|
|
32032
32257
|
}
|
|
32033
32258
|
emitter2.emit(eventName, event);
|
|
32034
32259
|
}
|
|
@@ -32170,8 +32395,8 @@ var Orchestrator = class {
|
|
|
32170
32395
|
constructor(job) {
|
|
32171
32396
|
let automation = job.data.automation;
|
|
32172
32397
|
let triggerOutput = job.data.event;
|
|
32173
|
-
const
|
|
32174
|
-
this._chainCount =
|
|
32398
|
+
const metadata2 = triggerOutput.metadata;
|
|
32399
|
+
this._chainCount = metadata2 ? metadata2.automationChainCount : 0;
|
|
32175
32400
|
this._appId = triggerOutput.appId;
|
|
32176
32401
|
this._job = job;
|
|
32177
32402
|
const triggerStepId = automation.definition.trigger.stepId;
|
|
@@ -32201,16 +32426,16 @@ var Orchestrator = class {
|
|
|
32201
32426
|
async getMetadata() {
|
|
32202
32427
|
const metadataId = generateAutomationMetadataID(this._automation._id);
|
|
32203
32428
|
const db2 = context_exports.getAppDB();
|
|
32204
|
-
let
|
|
32429
|
+
let metadata2;
|
|
32205
32430
|
try {
|
|
32206
|
-
|
|
32431
|
+
metadata2 = await db2.get(metadataId);
|
|
32207
32432
|
} catch (err) {
|
|
32208
|
-
|
|
32433
|
+
metadata2 = {
|
|
32209
32434
|
_id: metadataId,
|
|
32210
32435
|
errorCount: 0
|
|
32211
32436
|
};
|
|
32212
32437
|
}
|
|
32213
|
-
return
|
|
32438
|
+
return metadata2;
|
|
32214
32439
|
}
|
|
32215
32440
|
async stopCron(reason) {
|
|
32216
32441
|
if (!this._job.opts.repeat) {
|
|
@@ -32233,34 +32458,34 @@ var Orchestrator = class {
|
|
|
32233
32458
|
);
|
|
32234
32459
|
await storeLog2(automation, this.executionOutput);
|
|
32235
32460
|
}
|
|
32236
|
-
async checkIfShouldStop(
|
|
32237
|
-
if (!
|
|
32461
|
+
async checkIfShouldStop(metadata2) {
|
|
32462
|
+
if (!metadata2.errorCount || !this._job.opts.repeat) {
|
|
32238
32463
|
return false;
|
|
32239
32464
|
}
|
|
32240
|
-
if (
|
|
32465
|
+
if (metadata2.errorCount >= MAX_AUTOMATION_RECURRING_ERRORS) {
|
|
32241
32466
|
await this.stopCron("errors");
|
|
32242
32467
|
return true;
|
|
32243
32468
|
}
|
|
32244
32469
|
return false;
|
|
32245
32470
|
}
|
|
32246
|
-
async updateMetadata(
|
|
32471
|
+
async updateMetadata(metadata2) {
|
|
32247
32472
|
const output = this.executionOutput, automation = this._automation;
|
|
32248
32473
|
if (!output || !isRecurring(automation)) {
|
|
32249
32474
|
return;
|
|
32250
32475
|
}
|
|
32251
|
-
const count =
|
|
32476
|
+
const count = metadata2.errorCount;
|
|
32252
32477
|
const isError = isErrorInOutput(output);
|
|
32253
32478
|
if (!count && !isError) {
|
|
32254
32479
|
return;
|
|
32255
32480
|
}
|
|
32256
32481
|
if (isError) {
|
|
32257
|
-
|
|
32482
|
+
metadata2.errorCount = count ? count + 1 : 1;
|
|
32258
32483
|
} else {
|
|
32259
|
-
|
|
32484
|
+
metadata2.errorCount = 0;
|
|
32260
32485
|
}
|
|
32261
32486
|
const db2 = context_exports.getAppDB();
|
|
32262
32487
|
try {
|
|
32263
|
-
await db2.put(
|
|
32488
|
+
await db2.put(metadata2);
|
|
32264
32489
|
} catch (err) {
|
|
32265
32490
|
logging_exports.logAlertWithInfo(
|
|
32266
32491
|
"Failed to write automation metadata",
|
|
@@ -32311,13 +32536,13 @@ var Orchestrator = class {
|
|
|
32311
32536
|
let stepCount = 0;
|
|
32312
32537
|
let loopStepNumber = void 0;
|
|
32313
32538
|
let loopSteps = [];
|
|
32314
|
-
let
|
|
32539
|
+
let metadata2;
|
|
32315
32540
|
let timeoutFlag = false;
|
|
32316
32541
|
let wasLoopStep = false;
|
|
32317
32542
|
let timeout2 = this._job.data.event.timeout;
|
|
32318
32543
|
if (isProdAppID2(this._appId) && isRecurring(automation)) {
|
|
32319
|
-
|
|
32320
|
-
const shouldStop = await this.checkIfShouldStop(
|
|
32544
|
+
metadata2 = await this.getMetadata();
|
|
32545
|
+
const shouldStop = await this.checkIfShouldStop(metadata2);
|
|
32321
32546
|
if (shouldStop) {
|
|
32322
32547
|
return;
|
|
32323
32548
|
}
|
|
@@ -32521,8 +32746,8 @@ var Orchestrator = class {
|
|
|
32521
32746
|
}
|
|
32522
32747
|
logging_exports.logAlert("Error writing automation log", e);
|
|
32523
32748
|
}
|
|
32524
|
-
if (isProdAppID2(this._appId) && isRecurring(automation) &&
|
|
32525
|
-
await this.updateMetadata(
|
|
32749
|
+
if (isProdAppID2(this._appId) && isRecurring(automation) && metadata2) {
|
|
32750
|
+
await this.updateMetadata(metadata2);
|
|
32526
32751
|
}
|
|
32527
32752
|
return this.executionOutput;
|
|
32528
32753
|
}
|