@budibase/server 2.6.19-alpha.15 → 2.6.19-alpha.17
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/dist/automation.js +967 -969
- package/dist/automation.js.map +3 -3
- package/dist/index.js +1436 -1438
- package/dist/index.js.map +3 -3
- package/package.json +8 -8
- package/src/db/inMemoryView.ts +2 -3
package/dist/automation.js
CHANGED
|
@@ -4,8 +4,8 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __esm = (
|
|
8
|
-
return
|
|
7
|
+
var __esm = (fn2, res) => function __init() {
|
|
8
|
+
return fn2 && (res = (0, fn2[__getOwnPropNames(fn2)[0]])(fn2 = 0)), res;
|
|
9
9
|
};
|
|
10
10
|
var __commonJS = (cb, mod) => function __require() {
|
|
11
11
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
@@ -2027,9 +2027,9 @@ async function directCouchUrlCall({
|
|
|
2027
2027
|
return await (0, import_node_fetch.default)(checkSlashesInUrl(encodeURI(url)), params2);
|
|
2028
2028
|
}
|
|
2029
2029
|
async function directCouchQuery(path2, method = "GET", body2) {
|
|
2030
|
-
const
|
|
2031
|
-
if (
|
|
2032
|
-
return await
|
|
2030
|
+
const response2 = await directCouchCall(path2, method, body2);
|
|
2031
|
+
if (response2.status < 300) {
|
|
2032
|
+
return await response2.json();
|
|
2033
2033
|
} else {
|
|
2034
2034
|
throw "Cannot connect to CouchDB instance";
|
|
2035
2035
|
}
|
|
@@ -2050,27 +2050,27 @@ function init(opts) {
|
|
|
2050
2050
|
}
|
|
2051
2051
|
function getPouchDB(dbName, opts) {
|
|
2052
2052
|
checkInitialised();
|
|
2053
|
-
const
|
|
2054
|
-
const dbPut =
|
|
2055
|
-
|
|
2053
|
+
const db2 = new Pouch(dbName, opts);
|
|
2054
|
+
const dbPut = db2.put;
|
|
2055
|
+
db2.put = async (doc, options2 = {}) => {
|
|
2056
2056
|
if (!doc.createdAt) {
|
|
2057
2057
|
doc.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2058
2058
|
}
|
|
2059
2059
|
doc.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2060
2060
|
return dbPut(doc, options2);
|
|
2061
2061
|
};
|
|
2062
|
-
|
|
2063
|
-
const info = await
|
|
2062
|
+
db2.exists = async () => {
|
|
2063
|
+
const info = await db2.info();
|
|
2064
2064
|
return !info.error;
|
|
2065
2065
|
};
|
|
2066
|
-
return
|
|
2066
|
+
return db2;
|
|
2067
2067
|
}
|
|
2068
|
-
async function closePouchDB(
|
|
2069
|
-
if (!
|
|
2068
|
+
async function closePouchDB(db2) {
|
|
2069
|
+
if (!db2 || environment_default2.isTest()) {
|
|
2070
2070
|
return;
|
|
2071
2071
|
}
|
|
2072
2072
|
try {
|
|
2073
|
-
return await
|
|
2073
|
+
return await db2.close();
|
|
2074
2074
|
} catch (err) {
|
|
2075
2075
|
}
|
|
2076
2076
|
}
|
|
@@ -2182,12 +2182,12 @@ var init_DatabaseImpl = __esm({
|
|
|
2182
2182
|
DatabaseImpl.nano = buildNano(couchInfo);
|
|
2183
2183
|
}
|
|
2184
2184
|
async exists() {
|
|
2185
|
-
const
|
|
2185
|
+
const response2 = await directCouchUrlCall({
|
|
2186
2186
|
url: `${this.couchInfo.url}/${this.name}`,
|
|
2187
2187
|
method: "HEAD",
|
|
2188
2188
|
cookie: this.couchInfo.cookie
|
|
2189
2189
|
});
|
|
2190
|
-
return
|
|
2190
|
+
return response2.status === 200;
|
|
2191
2191
|
}
|
|
2192
2192
|
nano() {
|
|
2193
2193
|
return this.instanceNano || DatabaseImpl.nano;
|
|
@@ -2221,14 +2221,14 @@ var init_DatabaseImpl = __esm({
|
|
|
2221
2221
|
}
|
|
2222
2222
|
}
|
|
2223
2223
|
async get(id) {
|
|
2224
|
-
const
|
|
2224
|
+
const db2 = await this.checkSetup();
|
|
2225
2225
|
if (!id) {
|
|
2226
2226
|
throw new Error("Unable to get doc without a valid _id.");
|
|
2227
2227
|
}
|
|
2228
|
-
return this.updateOutput(() =>
|
|
2228
|
+
return this.updateOutput(() => db2.get(id));
|
|
2229
2229
|
}
|
|
2230
2230
|
async remove(idOrDoc, rev) {
|
|
2231
|
-
const
|
|
2231
|
+
const db2 = await this.checkSetup();
|
|
2232
2232
|
let _id;
|
|
2233
2233
|
let _rev;
|
|
2234
2234
|
if (isDocument(idOrDoc)) {
|
|
@@ -2241,7 +2241,7 @@ var init_DatabaseImpl = __esm({
|
|
|
2241
2241
|
if (!_id || !_rev) {
|
|
2242
2242
|
throw new Error("Unable to remove doc without a valid _id and _rev.");
|
|
2243
2243
|
}
|
|
2244
|
-
return this.updateOutput(() =>
|
|
2244
|
+
return this.updateOutput(() => db2.destroy(_id, _rev));
|
|
2245
2245
|
}
|
|
2246
2246
|
async post(document, opts) {
|
|
2247
2247
|
if (!document._id) {
|
|
@@ -2253,7 +2253,7 @@ var init_DatabaseImpl = __esm({
|
|
|
2253
2253
|
if (!document._id) {
|
|
2254
2254
|
throw new Error("Cannot store document without _id field.");
|
|
2255
2255
|
}
|
|
2256
|
-
const
|
|
2256
|
+
const db2 = await this.checkSetup();
|
|
2257
2257
|
if (!document.createdAt) {
|
|
2258
2258
|
document.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2259
2259
|
}
|
|
@@ -2270,20 +2270,20 @@ var init_DatabaseImpl = __esm({
|
|
|
2270
2270
|
}
|
|
2271
2271
|
}
|
|
2272
2272
|
}
|
|
2273
|
-
return this.updateOutput(() =>
|
|
2273
|
+
return this.updateOutput(() => db2.insert(document));
|
|
2274
2274
|
}
|
|
2275
2275
|
async bulkDocs(documents) {
|
|
2276
|
-
const
|
|
2277
|
-
return this.updateOutput(() =>
|
|
2276
|
+
const db2 = await this.checkSetup();
|
|
2277
|
+
return this.updateOutput(() => db2.bulk({ docs: documents }));
|
|
2278
2278
|
}
|
|
2279
2279
|
async allDocs(params2) {
|
|
2280
|
-
const
|
|
2281
|
-
return this.updateOutput(() =>
|
|
2280
|
+
const db2 = await this.checkSetup();
|
|
2281
|
+
return this.updateOutput(() => db2.list(params2));
|
|
2282
2282
|
}
|
|
2283
2283
|
async query(viewName, params2) {
|
|
2284
|
-
const
|
|
2285
|
-
const [database,
|
|
2286
|
-
return this.updateOutput(() =>
|
|
2284
|
+
const db2 = await this.checkSetup();
|
|
2285
|
+
const [database, view2] = viewName.split("/");
|
|
2286
|
+
return this.updateOutput(() => db2.view(database, view2, params2));
|
|
2287
2287
|
}
|
|
2288
2288
|
async destroy() {
|
|
2289
2289
|
try {
|
|
@@ -2297,8 +2297,8 @@ var init_DatabaseImpl = __esm({
|
|
|
2297
2297
|
}
|
|
2298
2298
|
}
|
|
2299
2299
|
async compact() {
|
|
2300
|
-
const
|
|
2301
|
-
return this.updateOutput(() =>
|
|
2300
|
+
const db2 = await this.checkSetup();
|
|
2301
|
+
return this.updateOutput(() => db2.compact());
|
|
2302
2302
|
}
|
|
2303
2303
|
// All below functions are in-frequently called, just utilise PouchDB
|
|
2304
2304
|
// for them as it implements them better than we can
|
|
@@ -2341,8 +2341,8 @@ function getDB(dbName, opts) {
|
|
|
2341
2341
|
return new DatabaseImpl(dbName, opts);
|
|
2342
2342
|
}
|
|
2343
2343
|
async function doWithDB(dbName, cb, opts = {}) {
|
|
2344
|
-
const
|
|
2345
|
-
return await cb(
|
|
2344
|
+
const db2 = getDB(dbName, opts);
|
|
2345
|
+
return await cb(db2);
|
|
2346
2346
|
}
|
|
2347
2347
|
function allDbs() {
|
|
2348
2348
|
if (!environment_default2.isTest()) {
|
|
@@ -2690,11 +2690,11 @@ function getRedisOptions() {
|
|
|
2690
2690
|
}
|
|
2691
2691
|
return { opts, host, port, redisProtocolUrl };
|
|
2692
2692
|
}
|
|
2693
|
-
function addDbPrefix(
|
|
2694
|
-
if (key.includes(
|
|
2693
|
+
function addDbPrefix(db2, key) {
|
|
2694
|
+
if (key.includes(db2)) {
|
|
2695
2695
|
return key;
|
|
2696
2696
|
}
|
|
2697
|
-
return `${
|
|
2697
|
+
return `${db2}${SEPARATOR2}${key}`;
|
|
2698
2698
|
}
|
|
2699
2699
|
function removeDbPrefix(key) {
|
|
2700
2700
|
let parts = key.split(SEPARATOR2);
|
|
@@ -2905,8 +2905,8 @@ var init_redis = __esm({
|
|
|
2905
2905
|
CONNECTED = true;
|
|
2906
2906
|
}
|
|
2907
2907
|
RedisWrapper = class {
|
|
2908
|
-
constructor(
|
|
2909
|
-
this._db =
|
|
2908
|
+
constructor(db2, selectDb = null) {
|
|
2909
|
+
this._db = db2;
|
|
2910
2910
|
this._select = selectDb || DEFAULT_SELECT_DB;
|
|
2911
2911
|
}
|
|
2912
2912
|
getClient() {
|
|
@@ -2923,8 +2923,8 @@ var init_redis = __esm({
|
|
|
2923
2923
|
this.getClient().disconnect();
|
|
2924
2924
|
}
|
|
2925
2925
|
async scan(key = "") {
|
|
2926
|
-
const
|
|
2927
|
-
key = `${
|
|
2926
|
+
const db2 = this._db;
|
|
2927
|
+
key = `${db2}${SEPARATOR2}${key}`;
|
|
2928
2928
|
let stream3;
|
|
2929
2929
|
if (CLUSTERED) {
|
|
2930
2930
|
let node = this.getClient().nodes("master");
|
|
@@ -2935,32 +2935,32 @@ var init_redis = __esm({
|
|
|
2935
2935
|
return promisifyStream(stream3, this.getClient());
|
|
2936
2936
|
}
|
|
2937
2937
|
async keys(pattern) {
|
|
2938
|
-
const
|
|
2939
|
-
return this.getClient().keys(addDbPrefix(
|
|
2938
|
+
const db2 = this._db;
|
|
2939
|
+
return this.getClient().keys(addDbPrefix(db2, pattern));
|
|
2940
2940
|
}
|
|
2941
2941
|
async get(key) {
|
|
2942
|
-
const
|
|
2943
|
-
let
|
|
2944
|
-
if (
|
|
2945
|
-
|
|
2942
|
+
const db2 = this._db;
|
|
2943
|
+
let response2 = await this.getClient().get(addDbPrefix(db2, key));
|
|
2944
|
+
if (response2 != null && response2.key) {
|
|
2945
|
+
response2.key = key;
|
|
2946
2946
|
}
|
|
2947
2947
|
try {
|
|
2948
|
-
return JSON.parse(
|
|
2948
|
+
return JSON.parse(response2);
|
|
2949
2949
|
} catch (err) {
|
|
2950
|
-
return
|
|
2950
|
+
return response2;
|
|
2951
2951
|
}
|
|
2952
2952
|
}
|
|
2953
2953
|
async bulkGet(keys2) {
|
|
2954
|
-
const
|
|
2954
|
+
const db2 = this._db;
|
|
2955
2955
|
if (keys2.length === 0) {
|
|
2956
2956
|
return {};
|
|
2957
2957
|
}
|
|
2958
|
-
const prefixedKeys = keys2.map((key) => addDbPrefix(
|
|
2959
|
-
let
|
|
2960
|
-
if (Array.isArray(
|
|
2958
|
+
const prefixedKeys = keys2.map((key) => addDbPrefix(db2, key));
|
|
2959
|
+
let response2 = await this.getClient().mget(prefixedKeys);
|
|
2960
|
+
if (Array.isArray(response2)) {
|
|
2961
2961
|
let final = {};
|
|
2962
2962
|
let count = 0;
|
|
2963
|
-
for (let result of
|
|
2963
|
+
for (let result of response2) {
|
|
2964
2964
|
if (result) {
|
|
2965
2965
|
let parsed;
|
|
2966
2966
|
try {
|
|
@@ -2974,33 +2974,33 @@ var init_redis = __esm({
|
|
|
2974
2974
|
}
|
|
2975
2975
|
return final;
|
|
2976
2976
|
} else {
|
|
2977
|
-
throw new Error(`Invalid response: ${
|
|
2977
|
+
throw new Error(`Invalid response: ${response2}`);
|
|
2978
2978
|
}
|
|
2979
2979
|
}
|
|
2980
2980
|
async store(key, value, expirySeconds = null) {
|
|
2981
|
-
const
|
|
2981
|
+
const db2 = this._db;
|
|
2982
2982
|
if (typeof value === "object") {
|
|
2983
2983
|
value = JSON.stringify(value);
|
|
2984
2984
|
}
|
|
2985
|
-
const prefixedKey = addDbPrefix(
|
|
2985
|
+
const prefixedKey = addDbPrefix(db2, key);
|
|
2986
2986
|
await this.getClient().set(prefixedKey, value);
|
|
2987
2987
|
if (expirySeconds) {
|
|
2988
2988
|
await this.getClient().expire(prefixedKey, expirySeconds);
|
|
2989
2989
|
}
|
|
2990
2990
|
}
|
|
2991
2991
|
async getTTL(key) {
|
|
2992
|
-
const
|
|
2993
|
-
const prefixedKey = addDbPrefix(
|
|
2992
|
+
const db2 = this._db;
|
|
2993
|
+
const prefixedKey = addDbPrefix(db2, key);
|
|
2994
2994
|
return this.getClient().ttl(prefixedKey);
|
|
2995
2995
|
}
|
|
2996
2996
|
async setExpiry(key, expirySeconds) {
|
|
2997
|
-
const
|
|
2998
|
-
const prefixedKey = addDbPrefix(
|
|
2997
|
+
const db2 = this._db;
|
|
2998
|
+
const prefixedKey = addDbPrefix(db2, key);
|
|
2999
2999
|
await this.getClient().expire(prefixedKey, expirySeconds);
|
|
3000
3000
|
}
|
|
3001
3001
|
async delete(key) {
|
|
3002
|
-
const
|
|
3003
|
-
await this.getClient().del(addDbPrefix(
|
|
3002
|
+
const db2 = this._db;
|
|
3003
|
+
await this.getClient().del(addDbPrefix(db2, key));
|
|
3004
3004
|
}
|
|
3005
3005
|
async clear() {
|
|
3006
3006
|
let items = await this.scan();
|
|
@@ -3376,8 +3376,8 @@ async function lookupTenantId(userId) {
|
|
|
3376
3376
|
return user.tenantId;
|
|
3377
3377
|
}
|
|
3378
3378
|
async function getUserDoc(emailOrId) {
|
|
3379
|
-
const
|
|
3380
|
-
return
|
|
3379
|
+
const db2 = getPlatformDB();
|
|
3380
|
+
return db2.get(emailOrId);
|
|
3381
3381
|
}
|
|
3382
3382
|
function newUserIdDoc(id, tenantId) {
|
|
3383
3383
|
return {
|
|
@@ -3393,14 +3393,14 @@ function newUserEmailDoc(userId, email, tenantId) {
|
|
|
3393
3393
|
};
|
|
3394
3394
|
}
|
|
3395
3395
|
async function addUserDoc(emailOrId, newDocFn) {
|
|
3396
|
-
const
|
|
3396
|
+
const db2 = getPlatformDB();
|
|
3397
3397
|
let user;
|
|
3398
3398
|
try {
|
|
3399
|
-
await
|
|
3399
|
+
await db2.get(emailOrId);
|
|
3400
3400
|
} catch (e) {
|
|
3401
3401
|
if (e.status === 404) {
|
|
3402
3402
|
user = newDocFn();
|
|
3403
|
-
await
|
|
3403
|
+
await db2.put(user);
|
|
3404
3404
|
} else {
|
|
3405
3405
|
throw e;
|
|
3406
3406
|
}
|
|
@@ -3413,9 +3413,9 @@ async function addUser(tenantId, userId, email) {
|
|
|
3413
3413
|
]);
|
|
3414
3414
|
}
|
|
3415
3415
|
async function removeUser(user) {
|
|
3416
|
-
const
|
|
3416
|
+
const db2 = getPlatformDB();
|
|
3417
3417
|
const keys2 = [user._id, user.email];
|
|
3418
|
-
const userDocs = await
|
|
3418
|
+
const userDocs = await db2.allDocs({
|
|
3419
3419
|
keys: keys2,
|
|
3420
3420
|
include_docs: true
|
|
3421
3421
|
});
|
|
@@ -3425,7 +3425,7 @@ async function removeUser(user) {
|
|
|
3425
3425
|
_deleted: true
|
|
3426
3426
|
};
|
|
3427
3427
|
});
|
|
3428
|
-
await
|
|
3428
|
+
await db2.bulkDocs(toDelete);
|
|
3429
3429
|
}
|
|
3430
3430
|
var init_users3 = __esm({
|
|
3431
3431
|
"../backend-core/src/platform/users.ts"() {
|
|
@@ -3648,7 +3648,7 @@ var init_logger = __esm({
|
|
|
3648
3648
|
...contextObject
|
|
3649
3649
|
};
|
|
3650
3650
|
if (objects.length) {
|
|
3651
|
-
const
|
|
3651
|
+
const data2 = {};
|
|
3652
3652
|
let dataIndex = 0;
|
|
3653
3653
|
for (let i = 0; i < objects.length; i++) {
|
|
3654
3654
|
const object = objects[i];
|
|
@@ -3657,12 +3657,12 @@ var init_logger = __esm({
|
|
|
3657
3657
|
delete object._logKey;
|
|
3658
3658
|
mergingObject[logKey] = object;
|
|
3659
3659
|
} else {
|
|
3660
|
-
|
|
3660
|
+
data2[dataIndex] = object;
|
|
3661
3661
|
dataIndex++;
|
|
3662
3662
|
}
|
|
3663
3663
|
}
|
|
3664
|
-
if (Object.keys(
|
|
3665
|
-
mergingObject.data =
|
|
3664
|
+
if (Object.keys(data2).length) {
|
|
3665
|
+
mergingObject.data = data2;
|
|
3666
3666
|
}
|
|
3667
3667
|
}
|
|
3668
3668
|
return [mergingObject, message];
|
|
@@ -3762,8 +3762,8 @@ function logAlert(message, e) {
|
|
|
3762
3762
|
}
|
|
3763
3763
|
console.error(`bb-alert: ${message}`, e);
|
|
3764
3764
|
}
|
|
3765
|
-
function logAlertWithInfo(message,
|
|
3766
|
-
message = `${message} - db: ${
|
|
3765
|
+
function logAlertWithInfo(message, db2, id, error) {
|
|
3766
|
+
message = `${message} - db: ${db2} - doc: ${id} - error: `;
|
|
3767
3767
|
logAlert(message, error);
|
|
3768
3768
|
}
|
|
3769
3769
|
function logWarn(message) {
|
|
@@ -3863,16 +3863,16 @@ var init_accounts3 = __esm({
|
|
|
3863
3863
|
const payload = {
|
|
3864
3864
|
email
|
|
3865
3865
|
};
|
|
3866
|
-
const
|
|
3866
|
+
const response2 = await api.post(`/api/accounts/search`, {
|
|
3867
3867
|
body: payload,
|
|
3868
3868
|
headers: {
|
|
3869
3869
|
["x-budibase-api-key" /* API_KEY */]: environment_default2.ACCOUNT_PORTAL_API_KEY
|
|
3870
3870
|
}
|
|
3871
3871
|
});
|
|
3872
|
-
if (
|
|
3872
|
+
if (response2.status !== 200) {
|
|
3873
3873
|
throw new Error(`Error getting account by email ${email}`);
|
|
3874
3874
|
}
|
|
3875
|
-
const json2 = await
|
|
3875
|
+
const json2 = await response2.json();
|
|
3876
3876
|
return json2[0];
|
|
3877
3877
|
};
|
|
3878
3878
|
}
|
|
@@ -3892,8 +3892,8 @@ __export(user_exports, {
|
|
|
3892
3892
|
invalidateUser: () => invalidateUser
|
|
3893
3893
|
});
|
|
3894
3894
|
async function populateFromDB(userId, tenantId) {
|
|
3895
|
-
const
|
|
3896
|
-
const user = await
|
|
3895
|
+
const db2 = getTenantDB(tenantId);
|
|
3896
|
+
const user = await db2.get(userId);
|
|
3897
3897
|
user.budibaseAccess = true;
|
|
3898
3898
|
if (!environment_default2.SELF_HOSTED && !environment_default2.DISABLE_ACCOUNT_PORTAL) {
|
|
3899
3899
|
const account = await getAccount(user.email);
|
|
@@ -4155,8 +4155,8 @@ async function getAllApps({
|
|
|
4155
4155
|
if (appPromises.length === 0) {
|
|
4156
4156
|
return [];
|
|
4157
4157
|
} else {
|
|
4158
|
-
const
|
|
4159
|
-
const apps2 =
|
|
4158
|
+
const response2 = await Promise.allSettled(appPromises);
|
|
4159
|
+
const apps2 = response2.filter(
|
|
4160
4160
|
(result) => result.status === "fulfilled" && result.value != null
|
|
4161
4161
|
).map(({ value }) => value);
|
|
4162
4162
|
if (!all) {
|
|
@@ -4197,13 +4197,13 @@ function isSameAppID(appId1, appId2) {
|
|
|
4197
4197
|
async function dbExists(dbName) {
|
|
4198
4198
|
return doWithDB(
|
|
4199
4199
|
dbName,
|
|
4200
|
-
async (
|
|
4201
|
-
return await
|
|
4200
|
+
async (db2) => {
|
|
4201
|
+
return await db2.exists();
|
|
4202
4202
|
},
|
|
4203
4203
|
{ skip_setup: true }
|
|
4204
4204
|
);
|
|
4205
4205
|
}
|
|
4206
|
-
function pagination(
|
|
4206
|
+
function pagination(data2, pageSize, {
|
|
4207
4207
|
paginate,
|
|
4208
4208
|
property,
|
|
4209
4209
|
getKey
|
|
@@ -4212,18 +4212,18 @@ function pagination(data, pageSize, {
|
|
|
4212
4212
|
property: "_id"
|
|
4213
4213
|
}) {
|
|
4214
4214
|
if (!paginate) {
|
|
4215
|
-
return { data, hasNextPage: false };
|
|
4215
|
+
return { data: data2, hasNextPage: false };
|
|
4216
4216
|
}
|
|
4217
|
-
const hasNextPage =
|
|
4217
|
+
const hasNextPage = data2.length > pageSize;
|
|
4218
4218
|
let nextPage = void 0;
|
|
4219
4219
|
if (!getKey) {
|
|
4220
4220
|
getKey = (doc) => property ? doc == null ? void 0 : doc[property] : doc == null ? void 0 : doc._id;
|
|
4221
4221
|
}
|
|
4222
4222
|
if (hasNextPage) {
|
|
4223
|
-
nextPage = getKey(
|
|
4223
|
+
nextPage = getKey(data2[pageSize]);
|
|
4224
4224
|
}
|
|
4225
4225
|
return {
|
|
4226
|
-
data:
|
|
4226
|
+
data: data2.slice(0, pageSize),
|
|
4227
4227
|
hasNextPage,
|
|
4228
4228
|
nextPage
|
|
4229
4229
|
};
|
|
@@ -4250,56 +4250,56 @@ function DesignDoc() {
|
|
|
4250
4250
|
views: {}
|
|
4251
4251
|
};
|
|
4252
4252
|
}
|
|
4253
|
-
async function removeDeprecated(
|
|
4253
|
+
async function removeDeprecated(db2, viewName) {
|
|
4254
4254
|
if (!DeprecatedViews[viewName]) {
|
|
4255
4255
|
return;
|
|
4256
4256
|
}
|
|
4257
4257
|
try {
|
|
4258
|
-
const designDoc = await
|
|
4258
|
+
const designDoc = await db2.get(DESIGN_DB);
|
|
4259
4259
|
for (let deprecatedNames of DeprecatedViews[viewName]) {
|
|
4260
4260
|
delete designDoc.views[deprecatedNames];
|
|
4261
4261
|
}
|
|
4262
|
-
await
|
|
4262
|
+
await db2.put(designDoc);
|
|
4263
4263
|
} catch (err) {
|
|
4264
4264
|
}
|
|
4265
4265
|
}
|
|
4266
|
-
async function createView(
|
|
4266
|
+
async function createView(db2, viewJs, viewName) {
|
|
4267
4267
|
let designDoc;
|
|
4268
4268
|
try {
|
|
4269
|
-
designDoc = await
|
|
4269
|
+
designDoc = await db2.get(DESIGN_DB);
|
|
4270
4270
|
} catch (err) {
|
|
4271
4271
|
designDoc = DesignDoc();
|
|
4272
4272
|
}
|
|
4273
|
-
const
|
|
4273
|
+
const view2 = {
|
|
4274
4274
|
map: viewJs
|
|
4275
4275
|
};
|
|
4276
4276
|
designDoc.views = {
|
|
4277
4277
|
...designDoc.views,
|
|
4278
|
-
[viewName]:
|
|
4278
|
+
[viewName]: view2
|
|
4279
4279
|
};
|
|
4280
4280
|
try {
|
|
4281
|
-
await
|
|
4281
|
+
await db2.put(designDoc);
|
|
4282
4282
|
} catch (err) {
|
|
4283
4283
|
if (err.status === 409) {
|
|
4284
|
-
return await createView(
|
|
4284
|
+
return await createView(db2, viewJs, viewName);
|
|
4285
4285
|
} else {
|
|
4286
4286
|
throw err;
|
|
4287
4287
|
}
|
|
4288
4288
|
}
|
|
4289
4289
|
}
|
|
4290
|
-
async function queryViewRaw(viewName, params2,
|
|
4290
|
+
async function queryViewRaw(viewName, params2, db2, createFunc, opts) {
|
|
4291
4291
|
try {
|
|
4292
|
-
const
|
|
4293
|
-
return
|
|
4292
|
+
const response2 = await db2.query(`database/${viewName}`, params2);
|
|
4293
|
+
return response2;
|
|
4294
4294
|
} catch (err) {
|
|
4295
4295
|
const pouchNotFound = err && err.name === "not_found";
|
|
4296
4296
|
const couchNotFound = err && err.status === 404;
|
|
4297
4297
|
if (pouchNotFound || couchNotFound) {
|
|
4298
|
-
await removeDeprecated(
|
|
4298
|
+
await removeDeprecated(db2, viewName);
|
|
4299
4299
|
await createFunc();
|
|
4300
|
-
return queryViewRaw(viewName, params2,
|
|
4300
|
+
return queryViewRaw(viewName, params2, db2, createFunc, opts);
|
|
4301
4301
|
} else if (err.status === 409) {
|
|
4302
|
-
return queryViewRaw(viewName, params2,
|
|
4302
|
+
return queryViewRaw(viewName, params2, db2, createFunc, opts);
|
|
4303
4303
|
} else {
|
|
4304
4304
|
throw err;
|
|
4305
4305
|
}
|
|
@@ -4307,8 +4307,8 @@ async function queryViewRaw(viewName, params2, db, createFunc, opts) {
|
|
|
4307
4307
|
}
|
|
4308
4308
|
async function createPlatformView(viewJs, viewName) {
|
|
4309
4309
|
try {
|
|
4310
|
-
await doWithDB(StaticDatabases.PLATFORM_INFO.name, async (
|
|
4311
|
-
await createView(
|
|
4310
|
+
await doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db2) => {
|
|
4311
|
+
await createView(db2, viewJs, viewName);
|
|
4312
4312
|
});
|
|
4313
4313
|
} catch (e) {
|
|
4314
4314
|
if (e.status === 409 && environment_default2.isTest()) {
|
|
@@ -4318,9 +4318,9 @@ async function createPlatformView(viewJs, viewName) {
|
|
|
4318
4318
|
}
|
|
4319
4319
|
}
|
|
4320
4320
|
async function queryGlobalViewRaw(viewName, params2, opts) {
|
|
4321
|
-
const
|
|
4321
|
+
const db2 = getGlobalDB();
|
|
4322
4322
|
const createFn = CreateFuncByName[viewName];
|
|
4323
|
-
return queryViewRaw(viewName, params2,
|
|
4323
|
+
return queryViewRaw(viewName, params2, db2, createFn, opts);
|
|
4324
4324
|
}
|
|
4325
4325
|
var DESIGN_DB, createNewUserEmailView, createUserAppView, createApiKeyView, createUserBuildersView, queryView, createPlatformAccountEmailView, createPlatformUserView, queryPlatformView, CreateFuncByName, queryGlobalView;
|
|
4326
4326
|
var init_views = __esm({
|
|
@@ -4331,16 +4331,16 @@ var init_views = __esm({
|
|
|
4331
4331
|
init_environment3();
|
|
4332
4332
|
DESIGN_DB = "_design/database";
|
|
4333
4333
|
createNewUserEmailView = async () => {
|
|
4334
|
-
const
|
|
4334
|
+
const db2 = getGlobalDB();
|
|
4335
4335
|
const viewJs = `function(doc) {
|
|
4336
4336
|
if (doc._id.startsWith("${"us" /* USER */}${SEPARATOR}")) {
|
|
4337
4337
|
emit(doc.email.toLowerCase(), doc._id)
|
|
4338
4338
|
}
|
|
4339
4339
|
}`;
|
|
4340
|
-
await createView(
|
|
4340
|
+
await createView(db2, viewJs, "by_email2" /* USER_BY_EMAIL */);
|
|
4341
4341
|
};
|
|
4342
4342
|
createUserAppView = async () => {
|
|
4343
|
-
const
|
|
4343
|
+
const db2 = getGlobalDB();
|
|
4344
4344
|
const viewJs = `function(doc) {
|
|
4345
4345
|
if (doc._id.startsWith("${"us" /* USER */}${SEPARATOR}") && doc.roles) {
|
|
4346
4346
|
for (let prodAppId of Object.keys(doc.roles)) {
|
|
@@ -4349,29 +4349,29 @@ var init_views = __esm({
|
|
|
4349
4349
|
}
|
|
4350
4350
|
}
|
|
4351
4351
|
}`;
|
|
4352
|
-
await createView(
|
|
4352
|
+
await createView(db2, viewJs, "by_app" /* USER_BY_APP */);
|
|
4353
4353
|
};
|
|
4354
4354
|
createApiKeyView = async () => {
|
|
4355
|
-
const
|
|
4355
|
+
const db2 = getGlobalDB();
|
|
4356
4356
|
const viewJs = `function(doc) {
|
|
4357
4357
|
if (doc._id.startsWith("${"devinfo" /* DEV_INFO */}") && doc.apiKey) {
|
|
4358
4358
|
emit(doc.apiKey, doc.userId)
|
|
4359
4359
|
}
|
|
4360
4360
|
}`;
|
|
4361
|
-
await createView(
|
|
4361
|
+
await createView(db2, viewJs, "by_api_key" /* BY_API_KEY */);
|
|
4362
4362
|
};
|
|
4363
4363
|
createUserBuildersView = async () => {
|
|
4364
|
-
const
|
|
4364
|
+
const db2 = getGlobalDB();
|
|
4365
4365
|
const viewJs = `function(doc) {
|
|
4366
4366
|
if (doc.builder && doc.builder.global === true) {
|
|
4367
4367
|
emit(doc._id, doc._id)
|
|
4368
4368
|
}
|
|
4369
4369
|
}`;
|
|
4370
|
-
await createView(
|
|
4370
|
+
await createView(db2, viewJs, "by_builders" /* USER_BY_BUILDERS */);
|
|
4371
4371
|
};
|
|
4372
|
-
queryView = async (viewName, params2,
|
|
4373
|
-
const
|
|
4374
|
-
const rows2 =
|
|
4372
|
+
queryView = async (viewName, params2, db2, createFunc, opts) => {
|
|
4373
|
+
const response2 = await queryViewRaw(viewName, params2, db2, createFunc, opts);
|
|
4374
|
+
const rows2 = response2.rows;
|
|
4375
4375
|
const docs = rows2.map(
|
|
4376
4376
|
(row) => params2.include_docs ? row.doc : row.value
|
|
4377
4377
|
);
|
|
@@ -4402,9 +4402,9 @@ var init_views = __esm({
|
|
|
4402
4402
|
["account_by_email" /* ACCOUNT_BY_EMAIL */]: createPlatformAccountEmailView,
|
|
4403
4403
|
["platform_users_lowercase" /* PLATFORM_USERS_LOWERCASE */]: createPlatformUserView
|
|
4404
4404
|
};
|
|
4405
|
-
return doWithDB(StaticDatabases.PLATFORM_INFO.name, async (
|
|
4405
|
+
return doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db2) => {
|
|
4406
4406
|
const createFn = CreateFuncByName2[viewName];
|
|
4407
|
-
return queryView(viewName, params2,
|
|
4407
|
+
return queryView(viewName, params2, db2, createFn, opts);
|
|
4408
4408
|
});
|
|
4409
4409
|
};
|
|
4410
4410
|
CreateFuncByName = {
|
|
@@ -4413,12 +4413,12 @@ var init_views = __esm({
|
|
|
4413
4413
|
["by_builders" /* USER_BY_BUILDERS */]: createUserBuildersView,
|
|
4414
4414
|
["by_app" /* USER_BY_APP */]: createUserAppView
|
|
4415
4415
|
};
|
|
4416
|
-
queryGlobalView = async (viewName, params2,
|
|
4417
|
-
if (!
|
|
4418
|
-
|
|
4416
|
+
queryGlobalView = async (viewName, params2, db2, opts) => {
|
|
4417
|
+
if (!db2) {
|
|
4418
|
+
db2 = getGlobalDB();
|
|
4419
4419
|
}
|
|
4420
4420
|
const createFn = CreateFuncByName[viewName];
|
|
4421
|
-
return queryView(viewName, params2,
|
|
4421
|
+
return queryView(viewName, params2, db2, createFn, opts);
|
|
4422
4422
|
};
|
|
4423
4423
|
}
|
|
4424
4424
|
});
|
|
@@ -4503,17 +4503,17 @@ function removeKeyNumbering(key) {
|
|
|
4503
4503
|
}
|
|
4504
4504
|
}
|
|
4505
4505
|
async function runQuery(url, body2, cookie) {
|
|
4506
|
-
const
|
|
4506
|
+
const response2 = await (0, import_node_fetch3.default)(url, {
|
|
4507
4507
|
body: JSON.stringify(body2),
|
|
4508
4508
|
method: "POST",
|
|
4509
4509
|
headers: {
|
|
4510
4510
|
Authorization: cookie
|
|
4511
4511
|
}
|
|
4512
4512
|
});
|
|
4513
|
-
if (
|
|
4514
|
-
throw
|
|
4513
|
+
if (response2.status === 404) {
|
|
4514
|
+
throw response2;
|
|
4515
4515
|
}
|
|
4516
|
-
const json2 = await
|
|
4516
|
+
const json2 = await response2.json();
|
|
4517
4517
|
let output = {
|
|
4518
4518
|
rows: [],
|
|
4519
4519
|
totalRows: 0
|
|
@@ -5046,16 +5046,16 @@ var init_lucene = __esm({
|
|
|
5046
5046
|
|
|
5047
5047
|
// ../backend-core/src/db/searchIndexes/searchIndexes.ts
|
|
5048
5048
|
async function createUserIndex() {
|
|
5049
|
-
const
|
|
5049
|
+
const db2 = getGlobalDB();
|
|
5050
5050
|
let designDoc;
|
|
5051
5051
|
try {
|
|
5052
|
-
designDoc = await
|
|
5052
|
+
designDoc = await db2.get("_design/database");
|
|
5053
5053
|
} catch (err) {
|
|
5054
5054
|
if (err.status === 404) {
|
|
5055
5055
|
designDoc = { _id: "_design/database" };
|
|
5056
5056
|
}
|
|
5057
5057
|
}
|
|
5058
|
-
const
|
|
5058
|
+
const fn2 = function(user) {
|
|
5059
5059
|
if (user._id && !user._id.startsWith("us_")) {
|
|
5060
5060
|
return;
|
|
5061
5061
|
}
|
|
@@ -5088,14 +5088,14 @@ async function createUserIndex() {
|
|
|
5088
5088
|
};
|
|
5089
5089
|
designDoc.indexes = {
|
|
5090
5090
|
["user" /* USER */]: {
|
|
5091
|
-
index:
|
|
5091
|
+
index: fn2.toString(),
|
|
5092
5092
|
analyzer: {
|
|
5093
5093
|
default: "keyword",
|
|
5094
5094
|
name: "perfield"
|
|
5095
5095
|
}
|
|
5096
5096
|
}
|
|
5097
5097
|
};
|
|
5098
|
-
await
|
|
5098
|
+
await db2.put(designDoc);
|
|
5099
5099
|
}
|
|
5100
5100
|
var init_searchIndexes = __esm({
|
|
5101
5101
|
"../backend-core/src/db/searchIndexes/searchIndexes.ts"() {
|
|
@@ -5230,8 +5230,8 @@ __export(appMetadata_exports, {
|
|
|
5230
5230
|
async function populateFromDB2(appId) {
|
|
5231
5231
|
return doWithDB(
|
|
5232
5232
|
appId,
|
|
5233
|
-
(
|
|
5234
|
-
return
|
|
5233
|
+
(db2) => {
|
|
5234
|
+
return db2.get("app_metadata" /* APP_METADATA */);
|
|
5235
5235
|
},
|
|
5236
5236
|
{ skip_setup: true }
|
|
5237
5237
|
);
|
|
@@ -5301,18 +5301,18 @@ async function getCache() {
|
|
|
5301
5301
|
}
|
|
5302
5302
|
return CACHE;
|
|
5303
5303
|
}
|
|
5304
|
-
function makeCacheKey(
|
|
5305
|
-
return
|
|
5304
|
+
function makeCacheKey(db2, key) {
|
|
5305
|
+
return db2.name + key;
|
|
5306
5306
|
}
|
|
5307
5307
|
function makeCacheItem(doc, lastWrite = null) {
|
|
5308
5308
|
return { doc, lastWrite: lastWrite || Date.now() };
|
|
5309
5309
|
}
|
|
5310
|
-
async function put(
|
|
5310
|
+
async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
5311
5311
|
const cache2 = await getCache();
|
|
5312
5312
|
const key = doc._id;
|
|
5313
5313
|
let cacheItem;
|
|
5314
5314
|
if (key) {
|
|
5315
|
-
cacheItem = await cache2.get(makeCacheKey(
|
|
5315
|
+
cacheItem = await cache2.get(makeCacheKey(db2, key));
|
|
5316
5316
|
}
|
|
5317
5317
|
const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs;
|
|
5318
5318
|
let output = doc;
|
|
@@ -5326,11 +5326,11 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
|
5326
5326
|
},
|
|
5327
5327
|
async () => {
|
|
5328
5328
|
const writeDb = async (toWrite) => {
|
|
5329
|
-
const
|
|
5329
|
+
const response2 = await db2.put(toWrite, { force: true });
|
|
5330
5330
|
output = {
|
|
5331
5331
|
...doc,
|
|
5332
|
-
_id:
|
|
5333
|
-
_rev:
|
|
5332
|
+
_id: response2.id,
|
|
5333
|
+
_rev: response2.rev
|
|
5334
5334
|
};
|
|
5335
5335
|
};
|
|
5336
5336
|
try {
|
|
@@ -5350,22 +5350,22 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
|
5350
5350
|
}
|
|
5351
5351
|
cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
|
|
5352
5352
|
if (output._id) {
|
|
5353
|
-
await cache2.store(makeCacheKey(
|
|
5353
|
+
await cache2.store(makeCacheKey(db2, output._id), cacheItem);
|
|
5354
5354
|
}
|
|
5355
5355
|
return { ok: true, id: output._id, rev: output._rev };
|
|
5356
5356
|
}
|
|
5357
|
-
async function get2(
|
|
5357
|
+
async function get2(db2, id) {
|
|
5358
5358
|
const cache2 = await getCache();
|
|
5359
|
-
const cacheKey = makeCacheKey(
|
|
5359
|
+
const cacheKey = makeCacheKey(db2, id);
|
|
5360
5360
|
let cacheItem = await cache2.get(cacheKey);
|
|
5361
5361
|
if (!cacheItem) {
|
|
5362
|
-
const doc = await
|
|
5362
|
+
const doc = await db2.get(id);
|
|
5363
5363
|
cacheItem = makeCacheItem(doc);
|
|
5364
5364
|
await cache2.store(cacheKey, cacheItem);
|
|
5365
5365
|
}
|
|
5366
5366
|
return cacheItem.doc;
|
|
5367
5367
|
}
|
|
5368
|
-
async function remove(
|
|
5368
|
+
async function remove(db2, docOrId, rev) {
|
|
5369
5369
|
const cache2 = await getCache();
|
|
5370
5370
|
if (!docOrId) {
|
|
5371
5371
|
throw new Error("No ID/Rev provided.");
|
|
@@ -5373,9 +5373,9 @@ async function remove(db, docOrId, rev) {
|
|
|
5373
5373
|
const id = typeof docOrId === "string" ? docOrId : docOrId._id;
|
|
5374
5374
|
rev = typeof docOrId === "string" ? rev : docOrId._rev;
|
|
5375
5375
|
try {
|
|
5376
|
-
await cache2.delete(makeCacheKey(
|
|
5376
|
+
await cache2.delete(makeCacheKey(db2, id));
|
|
5377
5377
|
} finally {
|
|
5378
|
-
await
|
|
5378
|
+
await db2.remove(id, rev);
|
|
5379
5379
|
}
|
|
5380
5380
|
}
|
|
5381
5381
|
var DEFAULT_WRITE_RATE_MS, CACHE, Writethrough;
|
|
@@ -5389,8 +5389,8 @@ var init_writethrough = __esm({
|
|
|
5389
5389
|
DEFAULT_WRITE_RATE_MS = 1e4;
|
|
5390
5390
|
CACHE = null;
|
|
5391
5391
|
Writethrough = class {
|
|
5392
|
-
constructor(
|
|
5393
|
-
this.db =
|
|
5392
|
+
constructor(db2, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
5393
|
+
this.db = db2;
|
|
5394
5394
|
this.writeRateMs = writeRateMs;
|
|
5395
5395
|
}
|
|
5396
5396
|
async put(doc) {
|
|
@@ -5437,9 +5437,9 @@ function generateConfigID(type) {
|
|
|
5437
5437
|
return `${"config" /* CONFIG */}${SEPARATOR}${type}`;
|
|
5438
5438
|
}
|
|
5439
5439
|
async function getConfig(type) {
|
|
5440
|
-
const
|
|
5440
|
+
const db2 = getGlobalDB();
|
|
5441
5441
|
try {
|
|
5442
|
-
return await
|
|
5442
|
+
return await db2.get(generateConfigID(type));
|
|
5443
5443
|
} catch (e) {
|
|
5444
5444
|
if (e.status === 404) {
|
|
5445
5445
|
return;
|
|
@@ -5448,8 +5448,8 @@ async function getConfig(type) {
|
|
|
5448
5448
|
}
|
|
5449
5449
|
}
|
|
5450
5450
|
async function save(config) {
|
|
5451
|
-
const
|
|
5452
|
-
return
|
|
5451
|
+
const db2 = getGlobalDB();
|
|
5452
|
+
return db2.put(config);
|
|
5453
5453
|
}
|
|
5454
5454
|
async function getSettingsConfigDoc() {
|
|
5455
5455
|
let config = await getConfig("settings" /* SETTINGS */);
|
|
@@ -5790,12 +5790,12 @@ var init_PosthogProcessor = __esm({
|
|
|
5790
5790
|
}
|
|
5791
5791
|
this.posthog.identify(payload);
|
|
5792
5792
|
}
|
|
5793
|
-
async identifyGroup(
|
|
5793
|
+
async identifyGroup(group2, timestamp) {
|
|
5794
5794
|
const payload = {
|
|
5795
|
-
distinctId:
|
|
5796
|
-
groupType:
|
|
5797
|
-
groupKey:
|
|
5798
|
-
properties:
|
|
5795
|
+
distinctId: group2.id,
|
|
5796
|
+
groupType: group2.type,
|
|
5797
|
+
groupKey: group2.id,
|
|
5798
|
+
properties: group2
|
|
5799
5799
|
};
|
|
5800
5800
|
if (timestamp) {
|
|
5801
5801
|
payload.timestamp = new Date(timestamp);
|
|
@@ -5853,9 +5853,9 @@ var init_AnalyticsProcessor = __esm({
|
|
|
5853
5853
|
await this.posthog.identify(identity, timestamp);
|
|
5854
5854
|
}
|
|
5855
5855
|
}
|
|
5856
|
-
async identifyGroup(
|
|
5856
|
+
async identifyGroup(group2, timestamp) {
|
|
5857
5857
|
if (this.posthog) {
|
|
5858
|
-
await this.posthog.identifyGroup(
|
|
5858
|
+
await this.posthog.identifyGroup(group2, timestamp);
|
|
5859
5859
|
}
|
|
5860
5860
|
}
|
|
5861
5861
|
shutdown() {
|
|
@@ -5886,11 +5886,11 @@ var init_LoggingProcessor = __esm({
|
|
|
5886
5886
|
}
|
|
5887
5887
|
console.log(`[audit] identified`, identity);
|
|
5888
5888
|
}
|
|
5889
|
-
async identifyGroup(
|
|
5889
|
+
async identifyGroup(group2, timestamp) {
|
|
5890
5890
|
if (skipLogging) {
|
|
5891
5891
|
return;
|
|
5892
5892
|
}
|
|
5893
|
-
console.log(`[audit] group identified`,
|
|
5893
|
+
console.log(`[audit] group identified`, group2);
|
|
5894
5894
|
}
|
|
5895
5895
|
shutdown() {
|
|
5896
5896
|
}
|
|
@@ -5899,12 +5899,12 @@ var init_LoggingProcessor = __esm({
|
|
|
5899
5899
|
});
|
|
5900
5900
|
|
|
5901
5901
|
// ../backend-core/src/utils/hashing.ts
|
|
5902
|
-
async function hash(
|
|
5902
|
+
async function hash(data2) {
|
|
5903
5903
|
const salt = await bcrypt.genSalt(SALT_ROUNDS);
|
|
5904
|
-
return bcrypt.hash(
|
|
5904
|
+
return bcrypt.hash(data2, salt);
|
|
5905
5905
|
}
|
|
5906
|
-
async function compare(
|
|
5907
|
-
return bcrypt.compare(
|
|
5906
|
+
async function compare(data2, encrypted) {
|
|
5907
|
+
return bcrypt.compare(data2, encrypted);
|
|
5908
5908
|
}
|
|
5909
5909
|
var bcrypt, SALT_ROUNDS;
|
|
5910
5910
|
var init_hashing = __esm({
|
|
@@ -6436,9 +6436,9 @@ var init_AuditLogsProcessor = __esm({
|
|
|
6436
6436
|
init_environment3();
|
|
6437
6437
|
_AuditLogsProcessor = class {
|
|
6438
6438
|
// can't use constructor as need to return promise
|
|
6439
|
-
static init(
|
|
6439
|
+
static init(fn2) {
|
|
6440
6440
|
_AuditLogsProcessor.auditLogsEnabled = true;
|
|
6441
|
-
const writeAuditLogs =
|
|
6441
|
+
const writeAuditLogs = fn2;
|
|
6442
6442
|
_AuditLogsProcessor.auditLogQueue = createQueue(
|
|
6443
6443
|
"auditLogQueue" /* AUDIT_LOG */
|
|
6444
6444
|
);
|
|
@@ -6483,7 +6483,7 @@ var init_AuditLogsProcessor = __esm({
|
|
|
6483
6483
|
}
|
|
6484
6484
|
async identify(identity, timestamp) {
|
|
6485
6485
|
}
|
|
6486
|
-
async identifyGroup(
|
|
6486
|
+
async identifyGroup(group2, timestamp) {
|
|
6487
6487
|
}
|
|
6488
6488
|
shutdown() {
|
|
6489
6489
|
var _a;
|
|
@@ -6748,15 +6748,15 @@ var init_identification2 = __esm({
|
|
|
6748
6748
|
const hosting = getHostingFromEnv();
|
|
6749
6749
|
const version = environment_default2.VERSION;
|
|
6750
6750
|
const environment3 = getDeploymentEnvironment();
|
|
6751
|
-
const
|
|
6751
|
+
const group2 = {
|
|
6752
6752
|
id,
|
|
6753
6753
|
type,
|
|
6754
6754
|
hosting,
|
|
6755
6755
|
version,
|
|
6756
6756
|
environment: environment3
|
|
6757
6757
|
};
|
|
6758
|
-
await identifyGroup(
|
|
6759
|
-
await identify({ ...
|
|
6758
|
+
await identifyGroup(group2, timestamp);
|
|
6759
|
+
await identify({ ...group2, id: `$${type}_${id}` }, timestamp);
|
|
6760
6760
|
};
|
|
6761
6761
|
identifyTenantGroup = async (tenantId, account, timestamp) => {
|
|
6762
6762
|
const id = await getEventTenantId(tenantId);
|
|
@@ -6773,7 +6773,7 @@ var init_identification2 = __esm({
|
|
|
6773
6773
|
} else {
|
|
6774
6774
|
hosting = getHostingFromEnv();
|
|
6775
6775
|
}
|
|
6776
|
-
const
|
|
6776
|
+
const group2 = {
|
|
6777
6777
|
id,
|
|
6778
6778
|
type,
|
|
6779
6779
|
hosting,
|
|
@@ -6782,8 +6782,8 @@ var init_identification2 = __esm({
|
|
|
6782
6782
|
profession,
|
|
6783
6783
|
companySize
|
|
6784
6784
|
};
|
|
6785
|
-
await identifyGroup(
|
|
6786
|
-
await identify({ ...
|
|
6785
|
+
await identifyGroup(group2, timestamp);
|
|
6786
|
+
await identify({ ...group2, id: `$${type}_${id}` }, timestamp);
|
|
6787
6787
|
};
|
|
6788
6788
|
identifyUser = async (user, account, timestamp) => {
|
|
6789
6789
|
var _a, _b;
|
|
@@ -6847,8 +6847,8 @@ var init_identification2 = __esm({
|
|
|
6847
6847
|
identify = async (identity, timestamp) => {
|
|
6848
6848
|
await processors.identify(identity, timestamp);
|
|
6849
6849
|
};
|
|
6850
|
-
identifyGroup = async (
|
|
6851
|
-
await processors.identifyGroup(
|
|
6850
|
+
identifyGroup = async (group2, timestamp) => {
|
|
6851
|
+
await processors.identifyGroup(group2, timestamp);
|
|
6852
6852
|
};
|
|
6853
6853
|
getDeploymentEnvironment = () => {
|
|
6854
6854
|
if (environment_default2.isDev()) {
|
|
@@ -6877,7 +6877,7 @@ var init_identification2 = __esm({
|
|
|
6877
6877
|
getUniqueTenantId = async (tenantId) => {
|
|
6878
6878
|
return doInTenant(tenantId, () => {
|
|
6879
6879
|
return withCache("uniqueTenantId" /* UNIQUE_TENANT_ID */, 86400 /* ONE_DAY */, async () => {
|
|
6880
|
-
const
|
|
6880
|
+
const db2 = getGlobalDB();
|
|
6881
6881
|
const config = await getSettingsConfigDoc();
|
|
6882
6882
|
let uniqueTenantId;
|
|
6883
6883
|
if (config.config.uniqueTenantId) {
|
|
@@ -6885,7 +6885,7 @@ var init_identification2 = __esm({
|
|
|
6885
6885
|
} else {
|
|
6886
6886
|
uniqueTenantId = `${newid()}_${tenantId}`;
|
|
6887
6887
|
config.config.uniqueTenantId = uniqueTenantId;
|
|
6888
|
-
await
|
|
6888
|
+
await db2.put(config);
|
|
6889
6889
|
return uniqueTenantId;
|
|
6890
6890
|
}
|
|
6891
6891
|
});
|
|
@@ -8077,21 +8077,21 @@ var init_user9 = __esm({
|
|
|
8077
8077
|
});
|
|
8078
8078
|
|
|
8079
8079
|
// ../backend-core/src/events/publishers/view.ts
|
|
8080
|
-
async function created12(
|
|
8080
|
+
async function created12(view2, timestamp) {
|
|
8081
8081
|
const properties = {
|
|
8082
|
-
tableId:
|
|
8082
|
+
tableId: view2.tableId
|
|
8083
8083
|
};
|
|
8084
8084
|
await publishEvent("view:created" /* VIEW_CREATED */, properties, timestamp);
|
|
8085
8085
|
}
|
|
8086
|
-
async function updated7(
|
|
8086
|
+
async function updated7(view2) {
|
|
8087
8087
|
const properties = {
|
|
8088
|
-
tableId:
|
|
8088
|
+
tableId: view2.tableId
|
|
8089
8089
|
};
|
|
8090
8090
|
await publishEvent("view:updated" /* VIEW_UPDATED */, properties);
|
|
8091
8091
|
}
|
|
8092
|
-
async function deleted11(
|
|
8092
|
+
async function deleted11(view2) {
|
|
8093
8093
|
const properties = {
|
|
8094
|
-
tableId:
|
|
8094
|
+
tableId: view2.tableId
|
|
8095
8095
|
};
|
|
8096
8096
|
await publishEvent("view:deleted" /* VIEW_DELETED */, properties);
|
|
8097
8097
|
}
|
|
@@ -8102,35 +8102,35 @@ async function exported3(table, format) {
|
|
|
8102
8102
|
};
|
|
8103
8103
|
await publishEvent("view:exported" /* VIEW_EXPORTED */, properties);
|
|
8104
8104
|
}
|
|
8105
|
-
async function filterCreated(
|
|
8105
|
+
async function filterCreated(view2, timestamp) {
|
|
8106
8106
|
const properties = {
|
|
8107
|
-
tableId:
|
|
8107
|
+
tableId: view2.tableId
|
|
8108
8108
|
};
|
|
8109
8109
|
await publishEvent("view:filter:created" /* VIEW_FILTER_CREATED */, properties, timestamp);
|
|
8110
8110
|
}
|
|
8111
|
-
async function filterUpdated(
|
|
8111
|
+
async function filterUpdated(view2) {
|
|
8112
8112
|
const properties = {
|
|
8113
|
-
tableId:
|
|
8113
|
+
tableId: view2.tableId
|
|
8114
8114
|
};
|
|
8115
8115
|
await publishEvent("view:filter:updated" /* VIEW_FILTER_UPDATED */, properties);
|
|
8116
8116
|
}
|
|
8117
|
-
async function filterDeleted(
|
|
8117
|
+
async function filterDeleted(view2) {
|
|
8118
8118
|
const properties = {
|
|
8119
|
-
tableId:
|
|
8119
|
+
tableId: view2.tableId
|
|
8120
8120
|
};
|
|
8121
8121
|
await publishEvent("view:filter:deleted" /* VIEW_FILTER_DELETED */, properties);
|
|
8122
8122
|
}
|
|
8123
|
-
async function calculationCreated(
|
|
8123
|
+
async function calculationCreated(view2, timestamp) {
|
|
8124
8124
|
const properties = {
|
|
8125
|
-
tableId:
|
|
8126
|
-
calculation:
|
|
8125
|
+
tableId: view2.tableId,
|
|
8126
|
+
calculation: view2.calculation
|
|
8127
8127
|
};
|
|
8128
8128
|
await publishEvent("view:calculation:created" /* VIEW_CALCULATION_CREATED */, properties, timestamp);
|
|
8129
8129
|
}
|
|
8130
|
-
async function calculationUpdated(
|
|
8130
|
+
async function calculationUpdated(view2) {
|
|
8131
8131
|
const properties = {
|
|
8132
|
-
tableId:
|
|
8133
|
-
calculation:
|
|
8132
|
+
tableId: view2.tableId,
|
|
8133
|
+
calculation: view2.calculation
|
|
8134
8134
|
};
|
|
8135
8135
|
await publishEvent("view:calculation:updated" /* VIEW_CALCULATION_UPDATED */, properties);
|
|
8136
8136
|
}
|
|
@@ -8266,54 +8266,54 @@ var init_backfill3 = __esm({
|
|
|
8266
8266
|
});
|
|
8267
8267
|
|
|
8268
8268
|
// ../backend-core/src/events/publishers/group.ts
|
|
8269
|
-
async function created13(
|
|
8269
|
+
async function created13(group2, timestamp) {
|
|
8270
8270
|
const properties = {
|
|
8271
|
-
groupId:
|
|
8271
|
+
groupId: group2._id,
|
|
8272
8272
|
viaScim: isScim(),
|
|
8273
8273
|
audited: {
|
|
8274
|
-
name:
|
|
8274
|
+
name: group2.name
|
|
8275
8275
|
}
|
|
8276
8276
|
};
|
|
8277
8277
|
await publishEvent("user_group:created" /* USER_GROUP_CREATED */, properties, timestamp);
|
|
8278
8278
|
}
|
|
8279
|
-
async function updated8(
|
|
8279
|
+
async function updated8(group2) {
|
|
8280
8280
|
const properties = {
|
|
8281
|
-
groupId:
|
|
8281
|
+
groupId: group2._id,
|
|
8282
8282
|
viaScim: isScim(),
|
|
8283
8283
|
audited: {
|
|
8284
|
-
name:
|
|
8284
|
+
name: group2.name
|
|
8285
8285
|
}
|
|
8286
8286
|
};
|
|
8287
8287
|
await publishEvent("user_group:updated" /* USER_GROUP_UPDATED */, properties);
|
|
8288
8288
|
}
|
|
8289
|
-
async function deleted12(
|
|
8289
|
+
async function deleted12(group2) {
|
|
8290
8290
|
const properties = {
|
|
8291
|
-
groupId:
|
|
8291
|
+
groupId: group2._id,
|
|
8292
8292
|
viaScim: isScim(),
|
|
8293
8293
|
audited: {
|
|
8294
|
-
name:
|
|
8294
|
+
name: group2.name
|
|
8295
8295
|
}
|
|
8296
8296
|
};
|
|
8297
8297
|
await publishEvent("user_group:deleted" /* USER_GROUP_DELETED */, properties);
|
|
8298
8298
|
}
|
|
8299
|
-
async function usersAdded(count,
|
|
8299
|
+
async function usersAdded(count, group2) {
|
|
8300
8300
|
const properties = {
|
|
8301
8301
|
count,
|
|
8302
|
-
groupId:
|
|
8302
|
+
groupId: group2._id,
|
|
8303
8303
|
viaScim: isScim(),
|
|
8304
8304
|
audited: {
|
|
8305
|
-
name:
|
|
8305
|
+
name: group2.name
|
|
8306
8306
|
}
|
|
8307
8307
|
};
|
|
8308
8308
|
await publishEvent("user_group:user_added" /* USER_GROUP_USERS_ADDED */, properties);
|
|
8309
8309
|
}
|
|
8310
|
-
async function usersDeleted(count,
|
|
8310
|
+
async function usersDeleted(count, group2) {
|
|
8311
8311
|
const properties = {
|
|
8312
8312
|
count,
|
|
8313
|
-
groupId:
|
|
8313
|
+
groupId: group2._id,
|
|
8314
8314
|
viaScim: isScim(),
|
|
8315
8315
|
audited: {
|
|
8316
|
-
name:
|
|
8316
|
+
name: group2.name
|
|
8317
8317
|
}
|
|
8318
8318
|
};
|
|
8319
8319
|
await publishEvent("user_group:users_deleted" /* USER_GROUP_USERS_REMOVED */, properties);
|
|
@@ -8325,12 +8325,12 @@ async function createdOnboarding(groupId) {
|
|
|
8325
8325
|
};
|
|
8326
8326
|
await publishEvent("user_group:onboarding_added" /* USER_GROUP_ONBOARDING */, properties);
|
|
8327
8327
|
}
|
|
8328
|
-
async function permissionsEdited(
|
|
8328
|
+
async function permissionsEdited(group2) {
|
|
8329
8329
|
const properties = {
|
|
8330
|
-
permissions:
|
|
8331
|
-
groupId:
|
|
8330
|
+
permissions: group2.roles,
|
|
8331
|
+
groupId: group2._id,
|
|
8332
8332
|
audited: {
|
|
8333
|
-
name:
|
|
8333
|
+
name: group2.name
|
|
8334
8334
|
}
|
|
8335
8335
|
};
|
|
8336
8336
|
await publishEvent("user_group:permissions_edited" /* USER_GROUP_PERMISSIONS_EDITED */, properties);
|
|
@@ -8665,20 +8665,20 @@ function removeUserPassword(users2) {
|
|
|
8665
8665
|
return users2;
|
|
8666
8666
|
}
|
|
8667
8667
|
async function getById(id, opts) {
|
|
8668
|
-
const
|
|
8669
|
-
let user = await
|
|
8668
|
+
const db2 = getGlobalDB();
|
|
8669
|
+
let user = await db2.get(id);
|
|
8670
8670
|
if (opts == null ? void 0 : opts.cleanup) {
|
|
8671
8671
|
user = removeUserPassword(user);
|
|
8672
8672
|
}
|
|
8673
8673
|
return user;
|
|
8674
8674
|
}
|
|
8675
8675
|
async function getUserCount() {
|
|
8676
|
-
const
|
|
8676
|
+
const response2 = await queryGlobalViewRaw("by_email2" /* USER_BY_EMAIL */, {
|
|
8677
8677
|
limit: 0,
|
|
8678
8678
|
// to be as fast as possible - we just want the total rows count
|
|
8679
8679
|
include_docs: false
|
|
8680
8680
|
});
|
|
8681
|
-
return
|
|
8681
|
+
return response2.total_rows;
|
|
8682
8682
|
}
|
|
8683
8683
|
var bulkGetGlobalUsersById, getAllUserIds, bulkUpdateGlobalUsers, getGlobalUserByEmail, searchGlobalUsersByApp, searchGlobalUsersByAppAccess, getGlobalUserByAppPage, searchGlobalUsersByEmail, PAGE_LIMIT, paginatedUsers;
|
|
8684
8684
|
var init_users4 = __esm({
|
|
@@ -8687,8 +8687,8 @@ var init_users4 = __esm({
|
|
|
8687
8687
|
init_context2();
|
|
8688
8688
|
init_context2();
|
|
8689
8689
|
bulkGetGlobalUsersById = async (userIds, opts) => {
|
|
8690
|
-
const
|
|
8691
|
-
let users2 = (await
|
|
8690
|
+
const db2 = getGlobalDB();
|
|
8691
|
+
let users2 = (await db2.allDocs({
|
|
8692
8692
|
keys: userIds,
|
|
8693
8693
|
include_docs: true
|
|
8694
8694
|
})).rows.map((row) => row.doc);
|
|
@@ -8698,30 +8698,30 @@ var init_users4 = __esm({
|
|
|
8698
8698
|
return users2;
|
|
8699
8699
|
};
|
|
8700
8700
|
getAllUserIds = async () => {
|
|
8701
|
-
const
|
|
8701
|
+
const db2 = getGlobalDB();
|
|
8702
8702
|
const startKey = `${"us" /* USER */}${SEPARATOR}`;
|
|
8703
|
-
const
|
|
8703
|
+
const response2 = await db2.allDocs({
|
|
8704
8704
|
startkey: startKey,
|
|
8705
8705
|
endkey: `${startKey}${UNICODE_MAX}`
|
|
8706
8706
|
});
|
|
8707
|
-
return
|
|
8707
|
+
return response2.rows.map((row) => row.id);
|
|
8708
8708
|
};
|
|
8709
8709
|
bulkUpdateGlobalUsers = async (users2) => {
|
|
8710
|
-
const
|
|
8711
|
-
return await
|
|
8710
|
+
const db2 = getGlobalDB();
|
|
8711
|
+
return await db2.bulkDocs(users2);
|
|
8712
8712
|
};
|
|
8713
8713
|
getGlobalUserByEmail = async (email, opts) => {
|
|
8714
8714
|
if (email == null) {
|
|
8715
8715
|
throw "Must supply an email address to view";
|
|
8716
8716
|
}
|
|
8717
|
-
const
|
|
8717
|
+
const response2 = await queryGlobalView("by_email2" /* USER_BY_EMAIL */, {
|
|
8718
8718
|
key: email.toLowerCase(),
|
|
8719
8719
|
include_docs: true
|
|
8720
8720
|
});
|
|
8721
|
-
if (Array.isArray(
|
|
8721
|
+
if (Array.isArray(response2)) {
|
|
8722
8722
|
throw new Error(`Multiple users found with email address: ${email}`);
|
|
8723
8723
|
}
|
|
8724
|
-
let user =
|
|
8724
|
+
let user = response2;
|
|
8725
8725
|
if (opts == null ? void 0 : opts.cleanup) {
|
|
8726
8726
|
user = removeUserPassword(user);
|
|
8727
8727
|
}
|
|
@@ -8735,11 +8735,11 @@ var init_users4 = __esm({
|
|
|
8735
8735
|
include_docs: true
|
|
8736
8736
|
});
|
|
8737
8737
|
params2.startkey = opts && opts.startkey ? opts.startkey : params2.startkey;
|
|
8738
|
-
let
|
|
8739
|
-
if (!
|
|
8740
|
-
|
|
8738
|
+
let response2 = await queryGlobalView("by_app" /* USER_BY_APP */, params2);
|
|
8739
|
+
if (!response2) {
|
|
8740
|
+
response2 = [];
|
|
8741
8741
|
}
|
|
8742
|
-
let users2 = Array.isArray(
|
|
8742
|
+
let users2 = Array.isArray(response2) ? response2 : [response2];
|
|
8743
8743
|
if (getOpts == null ? void 0 : getOpts.cleanup) {
|
|
8744
8744
|
users2 = removeUserPassword(users2);
|
|
8745
8745
|
}
|
|
@@ -8787,15 +8787,15 @@ var init_users4 = __esm({
|
|
|
8787
8787
|
}
|
|
8788
8788
|
const lcEmail = email.toLowerCase();
|
|
8789
8789
|
const startkey = opts && opts.startkey ? opts.startkey : lcEmail;
|
|
8790
|
-
let
|
|
8790
|
+
let response2 = await queryGlobalView("by_email2" /* USER_BY_EMAIL */, {
|
|
8791
8791
|
...opts,
|
|
8792
8792
|
startkey,
|
|
8793
8793
|
endkey: `${lcEmail}${UNICODE_MAX}`
|
|
8794
8794
|
});
|
|
8795
|
-
if (!
|
|
8796
|
-
|
|
8795
|
+
if (!response2) {
|
|
8796
|
+
response2 = [];
|
|
8797
8797
|
}
|
|
8798
|
-
let users2 = Array.isArray(
|
|
8798
|
+
let users2 = Array.isArray(response2) ? response2 : [response2];
|
|
8799
8799
|
if (getOpts == null ? void 0 : getOpts.cleanup) {
|
|
8800
8800
|
users2 = removeUserPassword(users2);
|
|
8801
8801
|
}
|
|
@@ -8807,7 +8807,7 @@ var init_users4 = __esm({
|
|
|
8807
8807
|
email,
|
|
8808
8808
|
appId
|
|
8809
8809
|
} = {}) => {
|
|
8810
|
-
const
|
|
8810
|
+
const db2 = getGlobalDB();
|
|
8811
8811
|
const opts = {
|
|
8812
8812
|
include_docs: true,
|
|
8813
8813
|
limit: PAGE_LIMIT + 1
|
|
@@ -8823,8 +8823,8 @@ var init_users4 = __esm({
|
|
|
8823
8823
|
userList = await searchGlobalUsersByEmail(email, opts);
|
|
8824
8824
|
property = "email";
|
|
8825
8825
|
} else {
|
|
8826
|
-
const
|
|
8827
|
-
userList =
|
|
8826
|
+
const response2 = await db2.allDocs(getGlobalUserParams(null, opts));
|
|
8827
|
+
userList = response2.rows.map((row) => row.doc);
|
|
8828
8828
|
}
|
|
8829
8829
|
return pagination(userList, PAGE_LIMIT, {
|
|
8830
8830
|
paginate: true,
|
|
@@ -8979,8 +8979,8 @@ async function getRole(roleId) {
|
|
|
8979
8979
|
);
|
|
8980
8980
|
}
|
|
8981
8981
|
try {
|
|
8982
|
-
const
|
|
8983
|
-
const dbRole = await
|
|
8982
|
+
const db2 = getAppDB();
|
|
8983
|
+
const dbRole = await db2.get(getDBRoleID(roleId));
|
|
8984
8984
|
role = Object.assign(role, dbRole);
|
|
8985
8985
|
role._id = getExternalRoleID(role._id);
|
|
8986
8986
|
} catch (err) {
|
|
@@ -9031,10 +9031,10 @@ async function getAllRoles(appId) {
|
|
|
9031
9031
|
}
|
|
9032
9032
|
return internal(appDB);
|
|
9033
9033
|
}
|
|
9034
|
-
async function internal(
|
|
9034
|
+
async function internal(db2) {
|
|
9035
9035
|
let roles = [];
|
|
9036
|
-
if (
|
|
9037
|
-
const body2 = await
|
|
9036
|
+
if (db2) {
|
|
9037
|
+
const body2 = await db2.allDocs(
|
|
9038
9038
|
getRoleParams(null, {
|
|
9039
9039
|
include_docs: true
|
|
9040
9040
|
})
|
|
@@ -9474,9 +9474,9 @@ async function getProfilePictureUrl(user, details) {
|
|
|
9474
9474
|
var _a;
|
|
9475
9475
|
const pictureUrl = (_a = details.profile) == null ? void 0 : _a._json.picture;
|
|
9476
9476
|
if (pictureUrl) {
|
|
9477
|
-
const
|
|
9478
|
-
if (
|
|
9479
|
-
const type =
|
|
9477
|
+
const response2 = await (0, import_node_fetch4.default)(pictureUrl);
|
|
9478
|
+
if (response2.status === 200) {
|
|
9479
|
+
const type = response2.headers.get("content-type");
|
|
9480
9480
|
if (type.startsWith("image/")) {
|
|
9481
9481
|
return pictureUrl;
|
|
9482
9482
|
}
|
|
@@ -9664,13 +9664,13 @@ async function fetchStrategyConfig(oidcConfig, callbackUrl) {
|
|
|
9664
9664
|
"Configuration invalid. Must contain clientID, clientSecret, callbackUrl and configUrl"
|
|
9665
9665
|
);
|
|
9666
9666
|
}
|
|
9667
|
-
const
|
|
9668
|
-
if (!
|
|
9667
|
+
const response2 = await (0, import_node_fetch5.default)(configUrl);
|
|
9668
|
+
if (!response2.ok) {
|
|
9669
9669
|
throw new Error(
|
|
9670
|
-
`Unexpected response when fetching openid-configuration: ${
|
|
9670
|
+
`Unexpected response when fetching openid-configuration: ${response2.statusText}`
|
|
9671
9671
|
);
|
|
9672
9672
|
}
|
|
9673
|
-
const body2 = await
|
|
9673
|
+
const body2 = await response2.json();
|
|
9674
9674
|
return {
|
|
9675
9675
|
issuer: body2.issuer,
|
|
9676
9676
|
authorizationURL: body2.authorization_endpoint,
|
|
@@ -9753,10 +9753,10 @@ async function postAuth(passport2, ctx, next) {
|
|
|
9753
9753
|
{ successRedirect: "/", failureRedirect: "/error" },
|
|
9754
9754
|
async (err, tokens) => {
|
|
9755
9755
|
const baseUrl = `/builder/app/${authStateCookie.appId}/data`;
|
|
9756
|
-
await doWithDB(authStateCookie.appId, async (
|
|
9756
|
+
await doWithDB(authStateCookie.appId, async (db2) => {
|
|
9757
9757
|
let datasource2;
|
|
9758
9758
|
try {
|
|
9759
|
-
datasource2 = await
|
|
9759
|
+
datasource2 = await db2.get(authStateCookie.datasourceId);
|
|
9760
9760
|
} catch (err2) {
|
|
9761
9761
|
if (err2.status === 404) {
|
|
9762
9762
|
ctx.redirect(baseUrl);
|
|
@@ -9766,7 +9766,7 @@ async function postAuth(passport2, ctx, next) {
|
|
|
9766
9766
|
datasource2.config = {};
|
|
9767
9767
|
}
|
|
9768
9768
|
datasource2.config.auth = { type: "google", ...tokens };
|
|
9769
|
-
await
|
|
9769
|
+
await db2.put(datasource2);
|
|
9770
9770
|
ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
|
|
9771
9771
|
});
|
|
9772
9772
|
}
|
|
@@ -9986,13 +9986,13 @@ async function checkApiKey(apiKey, populateUser) {
|
|
|
9986
9986
|
return doInTenant(tenantId, async () => {
|
|
9987
9987
|
let userId;
|
|
9988
9988
|
try {
|
|
9989
|
-
const
|
|
9989
|
+
const db2 = getGlobalDB();
|
|
9990
9990
|
userId = await queryGlobalView(
|
|
9991
9991
|
"by_api_key" /* BY_API_KEY */,
|
|
9992
9992
|
{
|
|
9993
9993
|
key: apiKey
|
|
9994
9994
|
},
|
|
9995
|
-
|
|
9995
|
+
db2
|
|
9996
9996
|
);
|
|
9997
9997
|
} catch (err) {
|
|
9998
9998
|
userId = void 0;
|
|
@@ -10563,8 +10563,8 @@ async function updateUserOAuth(userId, oAuthConfig) {
|
|
|
10563
10563
|
refreshToken: oAuthConfig.refreshToken
|
|
10564
10564
|
};
|
|
10565
10565
|
try {
|
|
10566
|
-
const
|
|
10567
|
-
const dbUser = await
|
|
10566
|
+
const db2 = getGlobalDB();
|
|
10567
|
+
const dbUser = await db2.get(userId);
|
|
10568
10568
|
if (typeof details.refreshToken !== "string") {
|
|
10569
10569
|
delete details.refreshToken;
|
|
10570
10570
|
}
|
|
@@ -10572,7 +10572,7 @@ async function updateUserOAuth(userId, oAuthConfig) {
|
|
|
10572
10572
|
...dbUser.oauth2,
|
|
10573
10573
|
...details
|
|
10574
10574
|
};
|
|
10575
|
-
await
|
|
10575
|
+
await db2.put(dbUser);
|
|
10576
10576
|
await invalidateUser(userId);
|
|
10577
10577
|
} catch (e) {
|
|
10578
10578
|
console.error("Could not update OAuth details for current user", e);
|
|
@@ -10959,11 +10959,11 @@ var init_objectStore = __esm({
|
|
|
10959
10959
|
Bucket: sanitizeBucket(bucketName),
|
|
10960
10960
|
Key: sanitizeKey(filepath)
|
|
10961
10961
|
};
|
|
10962
|
-
const
|
|
10963
|
-
if (STRING_CONTENT_TYPES.includes(
|
|
10964
|
-
return
|
|
10962
|
+
const response2 = await objectStore.getObject(params2).promise();
|
|
10963
|
+
if (STRING_CONTENT_TYPES.includes(response2.ContentType)) {
|
|
10964
|
+
return response2.Body.toString("utf8");
|
|
10965
10965
|
} else {
|
|
10966
|
-
return
|
|
10966
|
+
return response2.Body;
|
|
10967
10967
|
}
|
|
10968
10968
|
};
|
|
10969
10969
|
listAllObjects = async (bucketName, path2) => {
|
|
@@ -10981,11 +10981,11 @@ var init_objectStore = __esm({
|
|
|
10981
10981
|
if (token) {
|
|
10982
10982
|
params2.ContinuationToken = token;
|
|
10983
10983
|
}
|
|
10984
|
-
const
|
|
10985
|
-
if (
|
|
10986
|
-
objects = objects.concat(
|
|
10984
|
+
const response2 = await list(params2);
|
|
10985
|
+
if (response2.Contents) {
|
|
10986
|
+
objects = objects.concat(response2.Contents);
|
|
10987
10987
|
}
|
|
10988
|
-
isTruncated = !!
|
|
10988
|
+
isTruncated = !!response2.IsTruncated;
|
|
10989
10989
|
} while (isTruncated);
|
|
10990
10990
|
return objects;
|
|
10991
10991
|
};
|
|
@@ -11009,9 +11009,9 @@ var init_objectStore = __esm({
|
|
|
11009
11009
|
retrieveToTmp = async (bucketName, filepath) => {
|
|
11010
11010
|
bucketName = sanitizeBucket(bucketName);
|
|
11011
11011
|
filepath = sanitizeKey(filepath);
|
|
11012
|
-
const
|
|
11012
|
+
const data2 = await retrieve(bucketName, filepath);
|
|
11013
11013
|
const outputPath = (0, import_path3.join)(budibaseTempDir(), (0, import_uuid3.v4)());
|
|
11014
|
-
import_fs3.default.writeFileSync(outputPath,
|
|
11014
|
+
import_fs3.default.writeFileSync(outputPath, data2);
|
|
11015
11015
|
return outputPath;
|
|
11016
11016
|
};
|
|
11017
11017
|
retrieveDirectory = async (bucketName, path2) => {
|
|
@@ -11024,13 +11024,13 @@ var init_objectStore = __esm({
|
|
|
11024
11024
|
let count = 0;
|
|
11025
11025
|
for (let obj of objects) {
|
|
11026
11026
|
const filename = obj.Key;
|
|
11027
|
-
const
|
|
11027
|
+
const data2 = fullObjects[count++];
|
|
11028
11028
|
const possiblePath = filename.split("/");
|
|
11029
11029
|
if (possiblePath.length > 1) {
|
|
11030
11030
|
const dirs = possiblePath.slice(0, possiblePath.length - 1);
|
|
11031
11031
|
import_fs3.default.mkdirSync((0, import_path3.join)(writePath, ...dirs), { recursive: true });
|
|
11032
11032
|
}
|
|
11033
|
-
import_fs3.default.writeFileSync((0, import_path3.join)(writePath, ...possiblePath),
|
|
11033
|
+
import_fs3.default.writeFileSync((0, import_path3.join)(writePath, ...possiblePath), data2);
|
|
11034
11034
|
}
|
|
11035
11035
|
return writePath;
|
|
11036
11036
|
};
|
|
@@ -11099,21 +11099,21 @@ var init_objectStore = __esm({
|
|
|
11099
11099
|
};
|
|
11100
11100
|
downloadTarballDirect = async (url, path2, headers = {}) => {
|
|
11101
11101
|
path2 = sanitizeKey(path2);
|
|
11102
|
-
const
|
|
11103
|
-
if (!
|
|
11104
|
-
throw new Error(`unexpected response ${
|
|
11102
|
+
const response2 = await (0, import_node_fetch6.default)(url, { headers });
|
|
11103
|
+
if (!response2.ok) {
|
|
11104
|
+
throw new Error(`unexpected response ${response2.statusText}`);
|
|
11105
11105
|
}
|
|
11106
|
-
await streamPipeline(
|
|
11106
|
+
await streamPipeline(response2.body, import_zlib.default.createUnzip(), import_tar_fs.default.extract(path2));
|
|
11107
11107
|
};
|
|
11108
11108
|
downloadTarball = async (url, bucketName, path2) => {
|
|
11109
11109
|
bucketName = sanitizeBucket(bucketName);
|
|
11110
11110
|
path2 = sanitizeKey(path2);
|
|
11111
|
-
const
|
|
11112
|
-
if (!
|
|
11113
|
-
throw new Error(`unexpected response ${
|
|
11111
|
+
const response2 = await (0, import_node_fetch6.default)(url);
|
|
11112
|
+
if (!response2.ok) {
|
|
11113
|
+
throw new Error(`unexpected response ${response2.statusText}`);
|
|
11114
11114
|
}
|
|
11115
11115
|
const tmpPath = (0, import_path3.join)(budibaseTempDir(), path2);
|
|
11116
|
-
await streamPipeline(
|
|
11116
|
+
await streamPipeline(response2.body, import_zlib.default.createUnzip(), import_tar_fs.default.extract(tmpPath));
|
|
11117
11117
|
if (!environment_default2.isTest() && environment_default2.SELF_HOSTED) {
|
|
11118
11118
|
await uploadDirectory(bucketName, tmpPath, path2);
|
|
11119
11119
|
}
|
|
@@ -11724,11 +11724,11 @@ var init_quotas2 = __esm({
|
|
|
11724
11724
|
return new Writethrough2(tenancy.getGlobalDB());
|
|
11725
11725
|
};
|
|
11726
11726
|
bustCache2 = async () => {
|
|
11727
|
-
const
|
|
11727
|
+
const db2 = getDB2();
|
|
11728
11728
|
try {
|
|
11729
|
-
const usage = await
|
|
11729
|
+
const usage = await db2.get(db_exports.StaticDatabases.GLOBAL.docs.usageQuota);
|
|
11730
11730
|
if (usage == null ? void 0 : usage._rev) {
|
|
11731
|
-
await
|
|
11731
|
+
await db2.remove(
|
|
11732
11732
|
db_exports.StaticDatabases.GLOBAL.docs.usageQuota,
|
|
11733
11733
|
usage == null ? void 0 : usage._rev
|
|
11734
11734
|
);
|
|
@@ -11740,17 +11740,17 @@ var init_quotas2 = __esm({
|
|
|
11740
11740
|
}
|
|
11741
11741
|
};
|
|
11742
11742
|
getQuotaUsage = async () => {
|
|
11743
|
-
const
|
|
11743
|
+
const db2 = getDB2();
|
|
11744
11744
|
let usage;
|
|
11745
11745
|
try {
|
|
11746
|
-
usage = await
|
|
11746
|
+
usage = await db2.get(db_exports.StaticDatabases.GLOBAL.docs.usageQuota);
|
|
11747
11747
|
setCurrentMonth(usage);
|
|
11748
11748
|
setQuotaReset(usage);
|
|
11749
11749
|
} catch (err) {
|
|
11750
11750
|
if (err.status === 404) {
|
|
11751
11751
|
usage = generateNewQuotaUsage();
|
|
11752
|
-
const
|
|
11753
|
-
usage._rev =
|
|
11752
|
+
const response2 = await db2.put(usage);
|
|
11753
|
+
usage._rev = response2.rev;
|
|
11754
11754
|
} else {
|
|
11755
11755
|
throw err;
|
|
11756
11756
|
}
|
|
@@ -11768,7 +11768,7 @@ var init_quotas2 = __esm({
|
|
|
11768
11768
|
return setAllUsage(name, type, { total: value });
|
|
11769
11769
|
};
|
|
11770
11770
|
setUsagePerApp = async (appValues, name, type) => {
|
|
11771
|
-
const
|
|
11771
|
+
const db2 = getDB2();
|
|
11772
11772
|
let quotaUsage = await getQuotaUsage();
|
|
11773
11773
|
const total = Object.values(appValues).reduce((sum, num) => sum + num, 0);
|
|
11774
11774
|
for (let [appId, value] of Object.entries(appValues)) {
|
|
@@ -11785,8 +11785,8 @@ var init_quotas2 = __esm({
|
|
|
11785
11785
|
}
|
|
11786
11786
|
);
|
|
11787
11787
|
}
|
|
11788
|
-
const
|
|
11789
|
-
quotaUsage._rev =
|
|
11788
|
+
const response2 = await db2.put(quotaUsage);
|
|
11789
|
+
quotaUsage._rev = response2.rev;
|
|
11790
11790
|
return quotaUsage;
|
|
11791
11791
|
};
|
|
11792
11792
|
setBreakdown = (monthUsage, name, id, values) => {
|
|
@@ -11913,11 +11913,11 @@ var init_quotas2 = __esm({
|
|
|
11913
11913
|
return setAppUsageValue(quotaUsage, name, type, opts, values);
|
|
11914
11914
|
};
|
|
11915
11915
|
setAllUsage = async (name, type, values, opts = {}) => {
|
|
11916
|
-
const
|
|
11916
|
+
const db2 = getDB2();
|
|
11917
11917
|
let quotaUsage = await getQuotaUsage();
|
|
11918
11918
|
quotaUsage = coreUsageUpdate(quotaUsage, name, type, values, opts);
|
|
11919
|
-
const
|
|
11920
|
-
quotaUsage._rev =
|
|
11919
|
+
const response2 = await db2.put(quotaUsage);
|
|
11920
|
+
quotaUsage._rev = response2.rev;
|
|
11921
11921
|
return quotaUsage;
|
|
11922
11922
|
};
|
|
11923
11923
|
getCurrentUsageValues = async (type, name, id) => {
|
|
@@ -11988,9 +11988,9 @@ var init_licenseInfo = __esm({
|
|
|
11988
11988
|
};
|
|
11989
11989
|
};
|
|
11990
11990
|
save2 = async (licenseInfo) => {
|
|
11991
|
-
const
|
|
11992
|
-
const
|
|
11993
|
-
licenseInfo._rev =
|
|
11991
|
+
const db2 = tenancy.getGlobalDB();
|
|
11992
|
+
const response2 = await db2.put(licenseInfo);
|
|
11993
|
+
licenseInfo._rev = response2.rev;
|
|
11994
11994
|
return licenseInfo;
|
|
11995
11995
|
};
|
|
11996
11996
|
create = async (licenseKey) => {
|
|
@@ -11998,9 +11998,9 @@ var init_licenseInfo = __esm({
|
|
|
11998
11998
|
return save2(licenseInfo);
|
|
11999
11999
|
};
|
|
12000
12000
|
get3 = async () => {
|
|
12001
|
-
const
|
|
12001
|
+
const db2 = tenancy.getGlobalDB();
|
|
12002
12002
|
try {
|
|
12003
|
-
return await
|
|
12003
|
+
return await db2.get(StaticDatabases.GLOBAL.docs.licenseInfo);
|
|
12004
12004
|
} catch (err) {
|
|
12005
12005
|
if (err.status === 404) {
|
|
12006
12006
|
return void 0;
|
|
@@ -12013,24 +12013,24 @@ var init_licenseInfo = __esm({
|
|
|
12013
12013
|
if (!info) {
|
|
12014
12014
|
return;
|
|
12015
12015
|
}
|
|
12016
|
-
const
|
|
12017
|
-
return
|
|
12016
|
+
const db2 = tenancy.getGlobalDB();
|
|
12017
|
+
return db2.remove(StaticDatabases.GLOBAL.docs.licenseInfo, info._rev);
|
|
12018
12018
|
};
|
|
12019
12019
|
}
|
|
12020
12020
|
});
|
|
12021
12021
|
|
|
12022
12022
|
// ../pro/packages/pro/src/db/views/staticViews.ts
|
|
12023
12023
|
async function createAuditLogSearchIndex() {
|
|
12024
|
-
const
|
|
12024
|
+
const db2 = context_exports.getAuditLogsDB();
|
|
12025
12025
|
let designDoc;
|
|
12026
12026
|
try {
|
|
12027
|
-
designDoc = await
|
|
12027
|
+
designDoc = await db2.get("_design/database");
|
|
12028
12028
|
} catch (err) {
|
|
12029
12029
|
if (err.status === 404) {
|
|
12030
12030
|
designDoc = { _id: "_design/database" };
|
|
12031
12031
|
}
|
|
12032
12032
|
}
|
|
12033
|
-
const
|
|
12033
|
+
const fn2 = function(auditLog) {
|
|
12034
12034
|
if (auditLog._id && !auditLog._id.startsWith("al_")) {
|
|
12035
12035
|
return;
|
|
12036
12036
|
}
|
|
@@ -12057,7 +12057,7 @@ async function createAuditLogSearchIndex() {
|
|
|
12057
12057
|
};
|
|
12058
12058
|
designDoc.indexes = {
|
|
12059
12059
|
["audit" /* AUDIT */]: {
|
|
12060
|
-
index:
|
|
12060
|
+
index: fn2.toString(),
|
|
12061
12061
|
analyzer: {
|
|
12062
12062
|
default: "whitespace",
|
|
12063
12063
|
fields: {
|
|
@@ -12067,7 +12067,7 @@ async function createAuditLogSearchIndex() {
|
|
|
12067
12067
|
}
|
|
12068
12068
|
}
|
|
12069
12069
|
};
|
|
12070
|
-
await
|
|
12070
|
+
await db2.put(designDoc);
|
|
12071
12071
|
}
|
|
12072
12072
|
var init_staticViews = __esm({
|
|
12073
12073
|
"../pro/packages/pro/src/db/views/staticViews.ts"() {
|
|
@@ -12078,7 +12078,7 @@ var init_staticViews = __esm({
|
|
|
12078
12078
|
|
|
12079
12079
|
// ../pro/packages/pro/src/db/views/groups.ts
|
|
12080
12080
|
async function createGroupUserLookupView() {
|
|
12081
|
-
const
|
|
12081
|
+
const db2 = tenancy.getGlobalDB();
|
|
12082
12082
|
const viewJs = `function(doc) {
|
|
12083
12083
|
if (doc._id.startsWith("${USER_PREFIX}") && Array.isArray(doc.userGroups)) {
|
|
12084
12084
|
for (let groupId of doc.userGroups) {
|
|
@@ -12087,7 +12087,7 @@ async function createGroupUserLookupView() {
|
|
|
12087
12087
|
}
|
|
12088
12088
|
}
|
|
12089
12089
|
}`;
|
|
12090
|
-
await createView2(
|
|
12090
|
+
await createView2(db2, viewJs, ViewName3.USER_BY_GROUP);
|
|
12091
12091
|
}
|
|
12092
12092
|
var ViewName3, SEPARATOR4, DocumentType2, createView2, USER_PREFIX;
|
|
12093
12093
|
var init_groups2 = __esm({
|
|
@@ -12156,11 +12156,11 @@ function generateUserGroupID() {
|
|
|
12156
12156
|
return `${GROUP_PREFIX}${utils_exports2.newid()}`;
|
|
12157
12157
|
}
|
|
12158
12158
|
async function getGroupUsers(groupId, params2) {
|
|
12159
|
-
const
|
|
12159
|
+
const db2 = tenancy.getGlobalDB();
|
|
12160
12160
|
const userDocs = await db_exports.queryView(
|
|
12161
12161
|
db_exports.ViewName.USER_BY_GROUP,
|
|
12162
12162
|
getGroupUsersParams(groupId, params2),
|
|
12163
|
-
|
|
12163
|
+
db2,
|
|
12164
12164
|
createGroupUserLookupView,
|
|
12165
12165
|
{ arrayResponse: true }
|
|
12166
12166
|
);
|
|
@@ -12170,13 +12170,13 @@ async function getGroupUsers(groupId, params2) {
|
|
|
12170
12170
|
})) || [];
|
|
12171
12171
|
return users2;
|
|
12172
12172
|
}
|
|
12173
|
-
async function enrichGroup(
|
|
12174
|
-
|
|
12175
|
-
return
|
|
12173
|
+
async function enrichGroup(group2) {
|
|
12174
|
+
group2.users = await getGroupUsers(group2._id);
|
|
12175
|
+
return group2;
|
|
12176
12176
|
}
|
|
12177
|
-
async function cleanupUsers(
|
|
12177
|
+
async function cleanupUsers(group2) {
|
|
12178
12178
|
var _a;
|
|
12179
|
-
const enriched = await enrichGroup(
|
|
12179
|
+
const enriched = await enrichGroup(group2);
|
|
12180
12180
|
const userIds = (_a = enriched.users) == null ? void 0 : _a.map((user) => user._id);
|
|
12181
12181
|
const users2 = await users_exports2.bulkGetGlobalUsersById(userIds);
|
|
12182
12182
|
const toUpdate = [];
|
|
@@ -12185,7 +12185,7 @@ async function cleanupUsers(group) {
|
|
|
12185
12185
|
continue;
|
|
12186
12186
|
}
|
|
12187
12187
|
const lengthBefore = user.userGroups.length;
|
|
12188
|
-
user.userGroups = user.userGroups.filter((groupId) => groupId !==
|
|
12188
|
+
user.userGroups = user.userGroups.filter((groupId) => groupId !== group2._id);
|
|
12189
12189
|
if (user.userGroups.length !== lengthBefore) {
|
|
12190
12190
|
toUpdate.push(user);
|
|
12191
12191
|
}
|
|
@@ -12195,16 +12195,16 @@ async function cleanupUsers(group) {
|
|
|
12195
12195
|
}
|
|
12196
12196
|
}
|
|
12197
12197
|
async function fetch8() {
|
|
12198
|
-
const
|
|
12198
|
+
const db2 = tenancy.getGlobalDB();
|
|
12199
12199
|
try {
|
|
12200
|
-
const groups = (await
|
|
12200
|
+
const groups = (await db2.allDocs(
|
|
12201
12201
|
getUserGroupsParams(null, {
|
|
12202
12202
|
include_docs: true
|
|
12203
12203
|
})
|
|
12204
12204
|
)).rows.map((row) => row.doc);
|
|
12205
12205
|
const enrichedGroups = [];
|
|
12206
|
-
for (let
|
|
12207
|
-
enrichedGroups.push(enrichGroup(
|
|
12206
|
+
for (let group2 of groups) {
|
|
12207
|
+
enrichedGroups.push(enrichGroup(group2));
|
|
12208
12208
|
}
|
|
12209
12209
|
return await Promise.all(enrichedGroups);
|
|
12210
12210
|
} catch (err) {
|
|
@@ -12212,25 +12212,25 @@ async function fetch8() {
|
|
|
12212
12212
|
}
|
|
12213
12213
|
}
|
|
12214
12214
|
async function get4(groupId) {
|
|
12215
|
-
const
|
|
12215
|
+
const db2 = tenancy.getGlobalDB();
|
|
12216
12216
|
try {
|
|
12217
|
-
const
|
|
12218
|
-
return await enrichGroup(
|
|
12217
|
+
const group2 = await db2.get(groupId);
|
|
12218
|
+
return await enrichGroup(group2);
|
|
12219
12219
|
} catch (err) {
|
|
12220
12220
|
throw err;
|
|
12221
12221
|
}
|
|
12222
12222
|
}
|
|
12223
12223
|
async function getBulk(groupIds, opts = { enriched: true }) {
|
|
12224
|
-
const
|
|
12224
|
+
const db2 = tenancy.getGlobalDB();
|
|
12225
12225
|
try {
|
|
12226
|
-
const groups = (await
|
|
12226
|
+
const groups = (await db2.allDocs({
|
|
12227
12227
|
keys: groupIds,
|
|
12228
12228
|
include_docs: true
|
|
12229
12229
|
})).rows.map((row) => row.doc);
|
|
12230
12230
|
if (opts == null ? void 0 : opts.enriched) {
|
|
12231
12231
|
const enrichedGroups = [];
|
|
12232
|
-
for (let
|
|
12233
|
-
enrichedGroups.push(enrichGroup(
|
|
12232
|
+
for (let group2 of groups) {
|
|
12233
|
+
enrichedGroups.push(enrichGroup(group2));
|
|
12234
12234
|
}
|
|
12235
12235
|
return await Promise.all(enrichedGroups);
|
|
12236
12236
|
} else {
|
|
@@ -12240,19 +12240,19 @@ async function getBulk(groupIds, opts = { enriched: true }) {
|
|
|
12240
12240
|
throw err;
|
|
12241
12241
|
}
|
|
12242
12242
|
}
|
|
12243
|
-
async function save3(
|
|
12244
|
-
const
|
|
12245
|
-
return await
|
|
12243
|
+
async function save3(group2) {
|
|
12244
|
+
const db2 = tenancy.getGlobalDB();
|
|
12245
|
+
return await db2.put(group2);
|
|
12246
12246
|
}
|
|
12247
12247
|
async function bulkSave(groups) {
|
|
12248
|
-
const
|
|
12249
|
-
return await
|
|
12248
|
+
const db2 = tenancy.getGlobalDB();
|
|
12249
|
+
return await db2.bulkDocs(groups);
|
|
12250
12250
|
}
|
|
12251
12251
|
async function destroy3(groupId, revision) {
|
|
12252
|
-
const
|
|
12253
|
-
const
|
|
12254
|
-
let resp = await
|
|
12255
|
-
await cleanupUsers(
|
|
12252
|
+
const db2 = tenancy.getGlobalDB();
|
|
12253
|
+
const group2 = await db2.get(groupId);
|
|
12254
|
+
let resp = await db2.remove(groupId, revision);
|
|
12255
|
+
await cleanupUsers(group2);
|
|
12256
12256
|
return resp;
|
|
12257
12257
|
}
|
|
12258
12258
|
async function getByName(name) {
|
|
@@ -12265,11 +12265,11 @@ async function getByName(name) {
|
|
|
12265
12265
|
},
|
|
12266
12266
|
limit: 1
|
|
12267
12267
|
});
|
|
12268
|
-
const [
|
|
12269
|
-
if (!
|
|
12268
|
+
const [group2] = groups.rows;
|
|
12269
|
+
if (!group2) {
|
|
12270
12270
|
return;
|
|
12271
12271
|
}
|
|
12272
|
-
return await enrichGroup(
|
|
12272
|
+
return await enrichGroup(group2);
|
|
12273
12273
|
} catch (err) {
|
|
12274
12274
|
throw err;
|
|
12275
12275
|
}
|
|
@@ -12284,19 +12284,19 @@ var init_groups3 = __esm({
|
|
|
12284
12284
|
});
|
|
12285
12285
|
|
|
12286
12286
|
// ../pro/packages/pro/src/db/utils/pagination.ts
|
|
12287
|
-
function pagination2(
|
|
12287
|
+
function pagination2(response2, opts) {
|
|
12288
12288
|
var _a;
|
|
12289
|
-
const
|
|
12289
|
+
const data2 = response2.rows.map((row) => {
|
|
12290
12290
|
return row.doc ? row.doc : row;
|
|
12291
12291
|
});
|
|
12292
12292
|
if (!(opts == null ? void 0 : opts.paginate)) {
|
|
12293
|
-
return { data, hasNextPage: false };
|
|
12293
|
+
return { data: data2, hasNextPage: false };
|
|
12294
12294
|
}
|
|
12295
|
-
const hasNextPage =
|
|
12295
|
+
const hasNextPage = data2.length > (opts == null ? void 0 : opts.pageSize);
|
|
12296
12296
|
return {
|
|
12297
|
-
data:
|
|
12297
|
+
data: data2.slice(0, opts == null ? void 0 : opts.pageSize),
|
|
12298
12298
|
hasNextPage,
|
|
12299
|
-
nextPage: hasNextPage ? (_a =
|
|
12299
|
+
nextPage: hasNextPage ? (_a = data2[opts == null ? void 0 : opts.pageSize]) == null ? void 0 : _a._id : void 0
|
|
12300
12300
|
};
|
|
12301
12301
|
}
|
|
12302
12302
|
var init_pagination2 = __esm({
|
|
@@ -12306,7 +12306,7 @@ var init_pagination2 = __esm({
|
|
|
12306
12306
|
|
|
12307
12307
|
// ../pro/packages/pro/src/db/utils/views.ts
|
|
12308
12308
|
async function createLogByAutomationView() {
|
|
12309
|
-
const
|
|
12309
|
+
const db2 = context_exports.getProdAppDB();
|
|
12310
12310
|
const viewJs = `function(doc) {
|
|
12311
12311
|
if (doc._id.startsWith("${LOG_PREFIX}")) {
|
|
12312
12312
|
let autoId = doc.automationId + "${SEPARATOR5}"
|
|
@@ -12319,10 +12319,10 @@ async function createLogByAutomationView() {
|
|
|
12319
12319
|
emit(allKey)
|
|
12320
12320
|
}
|
|
12321
12321
|
}`;
|
|
12322
|
-
await createView3(
|
|
12322
|
+
await createView3(db2, viewJs, ViewName4.AUTOMATION_LOGS);
|
|
12323
12323
|
}
|
|
12324
12324
|
async function createAppBackupTriggerView() {
|
|
12325
|
-
const
|
|
12325
|
+
const db2 = tenancy.getGlobalDB();
|
|
12326
12326
|
const viewJs = `function(doc) {
|
|
12327
12327
|
if (doc._id.startsWith("${APP_BACKUP_PREFIX}") && doc.type && doc.trigger) {
|
|
12328
12328
|
let full = doc.appId + "${SEPARATOR5}"
|
|
@@ -12331,7 +12331,7 @@ async function createAppBackupTriggerView() {
|
|
|
12331
12331
|
emit("${APP_BACKUP_PREFIX}" + full + doc.timestamp)
|
|
12332
12332
|
}
|
|
12333
12333
|
}`;
|
|
12334
|
-
await createView3(
|
|
12334
|
+
await createView3(db2, viewJs, ViewName4.APP_BACKUP_BY_TRIGGER);
|
|
12335
12335
|
}
|
|
12336
12336
|
var ViewName4, AutomationViewMode2, SEPARATOR5, DocumentType3, createView3, LOG_PREFIX, APP_BACKUP_PREFIX;
|
|
12337
12337
|
var init_views3 = __esm({
|
|
@@ -12678,17 +12678,17 @@ async function getAppBackupParams(appId, filters, otherProps = {}) {
|
|
|
12678
12678
|
endkey: `${APP_BACKUP_PREFIX2}${endKey}`
|
|
12679
12679
|
};
|
|
12680
12680
|
}
|
|
12681
|
-
async function getAppBackupsByTrigger(
|
|
12681
|
+
async function getAppBackupsByTrigger(db2, params2) {
|
|
12682
12682
|
let backups = [];
|
|
12683
12683
|
try {
|
|
12684
12684
|
const queryIndex = db_exports.getQueryIndex(
|
|
12685
12685
|
db_exports.ViewName.APP_BACKUP_BY_TRIGGER
|
|
12686
12686
|
);
|
|
12687
|
-
backups = await
|
|
12687
|
+
backups = await db2.query(queryIndex, params2);
|
|
12688
12688
|
} catch (err) {
|
|
12689
12689
|
if (err != null && err.error === "not_found") {
|
|
12690
12690
|
await createAppBackupTriggerView();
|
|
12691
|
-
return getAppBackupsByTrigger(
|
|
12691
|
+
return getAppBackupsByTrigger(db2, params2);
|
|
12692
12692
|
} else {
|
|
12693
12693
|
throw err;
|
|
12694
12694
|
}
|
|
@@ -12699,7 +12699,7 @@ function generateAppBackupID(appId, timestamp) {
|
|
|
12699
12699
|
return `${APP_BACKUP_PREFIX2}${appId}${db_exports.SEPARATOR}${timestamp}`;
|
|
12700
12700
|
}
|
|
12701
12701
|
async function fetchAppBackups(appId, opts = {}) {
|
|
12702
|
-
const
|
|
12702
|
+
const db2 = tenancy.getGlobalDB();
|
|
12703
12703
|
let backups;
|
|
12704
12704
|
const pageSize = opts.limit || GENERIC_PAGE_SIZE;
|
|
12705
12705
|
const params2 = await getAppBackupParams(appId, opts, {
|
|
@@ -12710,9 +12710,9 @@ async function fetchAppBackups(appId, opts = {}) {
|
|
|
12710
12710
|
params2.startkey = opts.page;
|
|
12711
12711
|
}
|
|
12712
12712
|
if (!opts.trigger || !opts.type) {
|
|
12713
|
-
backups = await
|
|
12713
|
+
backups = await db2.allDocs(params2);
|
|
12714
12714
|
} else {
|
|
12715
|
-
backups = await getAppBackupsByTrigger(
|
|
12715
|
+
backups = await getAppBackupsByTrigger(db2, params2);
|
|
12716
12716
|
}
|
|
12717
12717
|
const pageData = pagination2(backups, {
|
|
12718
12718
|
paginate: opts.paginate,
|
|
@@ -12727,16 +12727,16 @@ async function fetchAppBackups(appId, opts = {}) {
|
|
|
12727
12727
|
cleanup: true
|
|
12728
12728
|
});
|
|
12729
12729
|
for (let user of users2) {
|
|
12730
|
-
for (let
|
|
12731
|
-
if ((user == null ? void 0 : user._id) ===
|
|
12732
|
-
|
|
12730
|
+
for (let data2 of pageData.data) {
|
|
12731
|
+
if ((user == null ? void 0 : user._id) === data2.createdBy) {
|
|
12732
|
+
data2.createdBy = user;
|
|
12733
12733
|
}
|
|
12734
12734
|
}
|
|
12735
12735
|
}
|
|
12736
12736
|
return pageData;
|
|
12737
12737
|
}
|
|
12738
12738
|
async function storeAppBackupMetadata(metadata, opts = {}) {
|
|
12739
|
-
const
|
|
12739
|
+
const db2 = tenancy.getGlobalDB();
|
|
12740
12740
|
const prodAppId = db_exports.getProdAppID(metadata.appId);
|
|
12741
12741
|
let _id = generateAppBackupID(prodAppId, metadata.timestamp);
|
|
12742
12742
|
const appBackupDoc = {
|
|
@@ -12757,22 +12757,22 @@ async function storeAppBackupMetadata(metadata, opts = {}) {
|
|
|
12757
12757
|
metadata.createdBy
|
|
12758
12758
|
);
|
|
12759
12759
|
}
|
|
12760
|
-
return await
|
|
12760
|
+
return await db2.put(appBackupDoc);
|
|
12761
12761
|
}
|
|
12762
12762
|
async function updateAppBackupMetadata(backupId, name) {
|
|
12763
|
-
const
|
|
12764
|
-
const metadata = await
|
|
12763
|
+
const db2 = tenancy.getGlobalDB();
|
|
12764
|
+
const metadata = await db2.get(backupId);
|
|
12765
12765
|
metadata.name = name;
|
|
12766
|
-
return await
|
|
12766
|
+
return await db2.put(metadata);
|
|
12767
12767
|
}
|
|
12768
12768
|
async function deleteAppBackupMetadata(backupId) {
|
|
12769
|
-
const
|
|
12770
|
-
const backupDoc = await
|
|
12771
|
-
await
|
|
12769
|
+
const db2 = tenancy.getGlobalDB();
|
|
12770
|
+
const backupDoc = await db2.get(backupId);
|
|
12771
|
+
await db2.remove(backupDoc._id, backupDoc._rev);
|
|
12772
12772
|
}
|
|
12773
12773
|
async function getAppBackupMetadata(backupId) {
|
|
12774
|
-
const
|
|
12775
|
-
return await
|
|
12774
|
+
const db2 = tenancy.getGlobalDB();
|
|
12775
|
+
return await db2.get(backupId);
|
|
12776
12776
|
}
|
|
12777
12777
|
var APP_BACKUP_PREFIX2;
|
|
12778
12778
|
var init_backups = __esm({
|
|
@@ -12804,10 +12804,10 @@ function getCacheEnvVarID(rev) {
|
|
|
12804
12804
|
}
|
|
12805
12805
|
async function get5() {
|
|
12806
12806
|
const id = getEnvVarID();
|
|
12807
|
-
const
|
|
12807
|
+
const db2 = tenancy.getGlobalDB();
|
|
12808
12808
|
let encrypted, notFound = false;
|
|
12809
12809
|
try {
|
|
12810
|
-
encrypted = await
|
|
12810
|
+
encrypted = await db2.get(id);
|
|
12811
12811
|
} catch (err) {
|
|
12812
12812
|
if (err.status == 404) {
|
|
12813
12813
|
notFound = true;
|
|
@@ -12842,8 +12842,8 @@ async function get5() {
|
|
|
12842
12842
|
}
|
|
12843
12843
|
async function update(doc) {
|
|
12844
12844
|
const id = getEnvVarID();
|
|
12845
|
-
const
|
|
12846
|
-
return await
|
|
12845
|
+
const db2 = tenancy.getGlobalDB();
|
|
12846
|
+
return await db2.put({
|
|
12847
12847
|
_id: doc._id || id,
|
|
12848
12848
|
_rev: doc._rev || void 0,
|
|
12849
12849
|
variables: encryption_exports.encrypt(
|
|
@@ -12891,23 +12891,23 @@ var init_client = __esm({
|
|
|
12891
12891
|
init_db6();
|
|
12892
12892
|
init_constants4();
|
|
12893
12893
|
api2 = new api_default(environment_default2.ACCOUNT_PORTAL_URL);
|
|
12894
|
-
getResponseErrorMessage = async (
|
|
12894
|
+
getResponseErrorMessage = async (response2) => {
|
|
12895
12895
|
try {
|
|
12896
|
-
const json2 = await
|
|
12896
|
+
const json2 = await response2.json();
|
|
12897
12897
|
if (json2.message) {
|
|
12898
12898
|
return json2.message;
|
|
12899
12899
|
}
|
|
12900
12900
|
} catch (e) {
|
|
12901
12901
|
}
|
|
12902
12902
|
try {
|
|
12903
|
-
const text = await
|
|
12903
|
+
const text = await response2.text();
|
|
12904
12904
|
if (text) {
|
|
12905
12905
|
return text;
|
|
12906
12906
|
}
|
|
12907
12907
|
} catch (e) {
|
|
12908
12908
|
}
|
|
12909
12909
|
};
|
|
12910
|
-
authAware = async (
|
|
12910
|
+
authAware = async (fn2) => {
|
|
12911
12911
|
let licenseInfo;
|
|
12912
12912
|
let authHeader;
|
|
12913
12913
|
if (environment_default2.SELF_HOSTED) {
|
|
@@ -12925,7 +12925,7 @@ var init_client = __esm({
|
|
|
12925
12925
|
[constants_exports.Header.TENANT_ID]: tenantId
|
|
12926
12926
|
};
|
|
12927
12927
|
}
|
|
12928
|
-
return
|
|
12928
|
+
return fn2(authHeader);
|
|
12929
12929
|
};
|
|
12930
12930
|
_getLicense = async () => {
|
|
12931
12931
|
return authAware(async (authHeader) => {
|
|
@@ -12954,18 +12954,18 @@ var init_client = __esm({
|
|
|
12954
12954
|
version: installVersion
|
|
12955
12955
|
}
|
|
12956
12956
|
};
|
|
12957
|
-
const
|
|
12957
|
+
const response2 = await api2.post(`/api/license`, {
|
|
12958
12958
|
headers: { ...authHeader },
|
|
12959
12959
|
body: body2
|
|
12960
12960
|
});
|
|
12961
|
-
if (
|
|
12961
|
+
if (response2.status === 404 || response2.status === 403) {
|
|
12962
12962
|
return;
|
|
12963
12963
|
}
|
|
12964
|
-
if (
|
|
12965
|
-
const message = await getResponseErrorMessage(
|
|
12966
|
-
throw new HTTPError(`Error getting license: ${message}`,
|
|
12964
|
+
if (response2.status !== 200) {
|
|
12965
|
+
const message = await getResponseErrorMessage(response2);
|
|
12966
|
+
throw new HTTPError(`Error getting license: ${message}`, response2.status);
|
|
12967
12967
|
}
|
|
12968
|
-
return
|
|
12968
|
+
return response2.json();
|
|
12969
12969
|
});
|
|
12970
12970
|
};
|
|
12971
12971
|
if (environment_default2.isJest()) {
|
|
@@ -12974,12 +12974,12 @@ var init_client = __esm({
|
|
|
12974
12974
|
getLicense = _getLicense;
|
|
12975
12975
|
triggerQuota = (body2) => {
|
|
12976
12976
|
return authAware(async (authHeader) => {
|
|
12977
|
-
const
|
|
12977
|
+
const response2 = await api2.post(`/api/license/usage/triggered`, {
|
|
12978
12978
|
headers: { ...authHeader },
|
|
12979
12979
|
body: body2
|
|
12980
12980
|
});
|
|
12981
|
-
if (
|
|
12982
|
-
const message = await getResponseErrorMessage(
|
|
12981
|
+
if (response2.status !== 200) {
|
|
12982
|
+
const message = await getResponseErrorMessage(response2);
|
|
12983
12983
|
logging_exports.logAlert(`Error triggering quota usage: ${message}`);
|
|
12984
12984
|
}
|
|
12985
12985
|
});
|
|
@@ -12989,23 +12989,23 @@ var init_client = __esm({
|
|
|
12989
12989
|
const body2 = {
|
|
12990
12990
|
installVersion
|
|
12991
12991
|
};
|
|
12992
|
-
const
|
|
12992
|
+
const response2 = await api2.post(`/api/license/activate`, {
|
|
12993
12993
|
headers: {
|
|
12994
12994
|
[constants_exports.Header.LICENSE_KEY]: licenseKey
|
|
12995
12995
|
},
|
|
12996
12996
|
body: body2
|
|
12997
12997
|
});
|
|
12998
|
-
if (
|
|
12998
|
+
if (response2.status === 403) {
|
|
12999
12999
|
throw new HTTPError("Invalid license key", 400);
|
|
13000
13000
|
}
|
|
13001
|
-
if (
|
|
13002
|
-
const message = await getResponseErrorMessage(
|
|
13001
|
+
if (response2.status !== 200) {
|
|
13002
|
+
const message = await getResponseErrorMessage(response2);
|
|
13003
13003
|
throw new HTTPError(
|
|
13004
13004
|
`Error activating license key: ${message}`,
|
|
13005
|
-
|
|
13005
|
+
response2.status
|
|
13006
13006
|
);
|
|
13007
13007
|
}
|
|
13008
|
-
return
|
|
13008
|
+
return response2.json();
|
|
13009
13009
|
};
|
|
13010
13010
|
}
|
|
13011
13011
|
});
|
|
@@ -13646,19 +13646,19 @@ async function recordDayPassOnQuotas() {
|
|
|
13646
13646
|
});
|
|
13647
13647
|
}
|
|
13648
13648
|
async function recordDayPassTimeOnUser(user) {
|
|
13649
|
-
const
|
|
13650
|
-
let dbUser = await
|
|
13649
|
+
const db2 = tenancy.getGlobalDB();
|
|
13650
|
+
let dbUser = await db2.get(user._id);
|
|
13651
13651
|
const now = /* @__PURE__ */ new Date();
|
|
13652
13652
|
const nowString = (/* @__PURE__ */ new Date()).toISOString();
|
|
13653
13653
|
user.dayPassRecordedAt = nowString;
|
|
13654
13654
|
dbUser.dayPassRecordedAt = nowString;
|
|
13655
13655
|
try {
|
|
13656
13656
|
console.log(`Recording day pass for user=${user._id}`);
|
|
13657
|
-
await
|
|
13657
|
+
await db2.put(dbUser);
|
|
13658
13658
|
} catch (e) {
|
|
13659
13659
|
if (e.status === 409) {
|
|
13660
13660
|
console.warn(`Conflict recording day pass for user=${user._id}`);
|
|
13661
|
-
dbUser = await
|
|
13661
|
+
dbUser = await db2.get(user._id);
|
|
13662
13662
|
if (!dbUser.dayPassRecordedAt || new Date(dbUser.dayPassRecordedAt).getDay() !== now.getDay()) {
|
|
13663
13663
|
console.error(`Day pass not recorded for user=${user._id}`);
|
|
13664
13664
|
throw e;
|
|
@@ -13830,23 +13830,23 @@ var init_api5 = __esm({
|
|
|
13830
13830
|
init_db6();
|
|
13831
13831
|
init_src2();
|
|
13832
13832
|
api3 = new api_default(environment_default2.ACCOUNT_PORTAL_URL);
|
|
13833
|
-
createActivity = async (userId,
|
|
13834
|
-
const
|
|
13833
|
+
createActivity = async (userId, data2) => {
|
|
13834
|
+
const response2 = await send(
|
|
13835
13835
|
(options2) => api3.post(`/api/users/${userId}/activity`, options2),
|
|
13836
13836
|
{
|
|
13837
|
-
body:
|
|
13837
|
+
body: data2
|
|
13838
13838
|
}
|
|
13839
13839
|
);
|
|
13840
|
-
if (!
|
|
13840
|
+
if (!response2) {
|
|
13841
13841
|
return;
|
|
13842
13842
|
}
|
|
13843
|
-
if (
|
|
13844
|
-
const text = await
|
|
13843
|
+
if (response2.status !== 201) {
|
|
13844
|
+
const text = await response2.text();
|
|
13845
13845
|
const message = `Error creating account user activity: ${text}`;
|
|
13846
13846
|
logging_exports.logAlert(message);
|
|
13847
13847
|
throw new Error(message);
|
|
13848
13848
|
}
|
|
13849
|
-
return
|
|
13849
|
+
return response2.json();
|
|
13850
13850
|
};
|
|
13851
13851
|
send = async (requestFn, baseOptions) => {
|
|
13852
13852
|
const isLicensingEnabled = await featureFlags_exports.isEnabled(
|
|
@@ -13899,10 +13899,10 @@ var init_users6 = __esm({
|
|
|
13899
13899
|
"../pro/packages/pro/src/sdk/users/users.ts"() {
|
|
13900
13900
|
init_api6();
|
|
13901
13901
|
createActivity2 = async (userId) => {
|
|
13902
|
-
const
|
|
13902
|
+
const data2 = {
|
|
13903
13903
|
timestamp: Date.now()
|
|
13904
13904
|
};
|
|
13905
|
-
return createActivity(userId,
|
|
13905
|
+
return createActivity(userId, data2);
|
|
13906
13906
|
};
|
|
13907
13907
|
}
|
|
13908
13908
|
});
|
|
@@ -13919,14 +13919,14 @@ var init_users7 = __esm({
|
|
|
13919
13919
|
});
|
|
13920
13920
|
|
|
13921
13921
|
// ../pro/packages/pro/src/utilities/delay.ts
|
|
13922
|
-
async function backOff(
|
|
13923
|
-
let attempts = 5, success = false,
|
|
13922
|
+
async function backOff(fn2, errMsg) {
|
|
13923
|
+
let attempts = 5, success = false, response2, first = true;
|
|
13924
13924
|
for (; attempts > 0; attempts--) {
|
|
13925
13925
|
try {
|
|
13926
13926
|
if (first) {
|
|
13927
|
-
|
|
13927
|
+
response2 = await fn2();
|
|
13928
13928
|
} else {
|
|
13929
|
-
|
|
13929
|
+
response2 = await exports.randomDelay(fn2);
|
|
13930
13930
|
}
|
|
13931
13931
|
success = true;
|
|
13932
13932
|
break;
|
|
@@ -13936,7 +13936,7 @@ async function backOff(fn, errMsg) {
|
|
|
13936
13936
|
if (!success) {
|
|
13937
13937
|
logging_exports.logAlert(`Failed to backoff`, errMsg);
|
|
13938
13938
|
}
|
|
13939
|
-
return
|
|
13939
|
+
return response2;
|
|
13940
13940
|
}
|
|
13941
13941
|
var init_delay = __esm({
|
|
13942
13942
|
"../pro/packages/pro/src/utilities/delay.ts"() {
|
|
@@ -13993,9 +13993,9 @@ function generateAutomationLogID(isoDate, status2, automationId) {
|
|
|
13993
13993
|
return `${DocumentType4.AUTOMATION_LOG}${SEPARATOR6}${isoDate}${SEPARATOR6}${automationId}${SEPARATOR6}${status2}`;
|
|
13994
13994
|
}
|
|
13995
13995
|
async function getAllLogs(startDate, endDate, opts = { docs: true }) {
|
|
13996
|
-
let
|
|
13997
|
-
if (!await
|
|
13998
|
-
|
|
13996
|
+
let db2 = context_exports.getProdAppDB();
|
|
13997
|
+
if (!await db2.exists()) {
|
|
13998
|
+
db2 = context_exports.getDevAppDB();
|
|
13999
13999
|
}
|
|
14000
14000
|
let optional = { status: opts.status };
|
|
14001
14001
|
let limit = (opts == null ? void 0 : opts.limit) ? opts.limit : (opts == null ? void 0 : opts.paginate) ? GENERIC_PAGE_SIZE + 1 : void 0;
|
|
@@ -14006,18 +14006,18 @@ async function getAllLogs(startDate, endDate, opts = { docs: true }) {
|
|
|
14006
14006
|
if (opts == null ? void 0 : opts.page) {
|
|
14007
14007
|
params2.startkey = opts.page;
|
|
14008
14008
|
}
|
|
14009
|
-
let
|
|
14010
|
-
return pagination2(
|
|
14009
|
+
let response2 = await db2.allDocs(params2);
|
|
14010
|
+
return pagination2(response2, {
|
|
14011
14011
|
paginate: opts == null ? void 0 : opts.paginate,
|
|
14012
14012
|
pageSize: GENERIC_PAGE_SIZE
|
|
14013
14013
|
});
|
|
14014
14014
|
}
|
|
14015
14015
|
async function getLogsByView(startDate, endDate, viewParams = {}) {
|
|
14016
|
-
let
|
|
14017
|
-
if (!await
|
|
14018
|
-
|
|
14016
|
+
let db2 = context_exports.getProdAppDB();
|
|
14017
|
+
if (!await db2.exists()) {
|
|
14018
|
+
db2 = context_exports.getDevAppDB();
|
|
14019
14019
|
}
|
|
14020
|
-
let
|
|
14020
|
+
let response2;
|
|
14021
14021
|
try {
|
|
14022
14022
|
let optional = {
|
|
14023
14023
|
automationId: viewParams == null ? void 0 : viewParams.automationId,
|
|
@@ -14030,7 +14030,7 @@ async function getLogsByView(startDate, endDate, viewParams = {}) {
|
|
|
14030
14030
|
if (viewParams == null ? void 0 : viewParams.page) {
|
|
14031
14031
|
params2.startkey = viewParams.page;
|
|
14032
14032
|
}
|
|
14033
|
-
|
|
14033
|
+
response2 = await db2.query(getQueryIndex2(ViewName5.AUTOMATION_LOGS), params2);
|
|
14034
14034
|
} catch (err) {
|
|
14035
14035
|
if (err != null && (err.name === "not_found" || err.error === "not_found")) {
|
|
14036
14036
|
await createLogByAutomationView();
|
|
@@ -14039,10 +14039,10 @@ async function getLogsByView(startDate, endDate, viewParams = {}) {
|
|
|
14039
14039
|
throw err;
|
|
14040
14040
|
}
|
|
14041
14041
|
}
|
|
14042
|
-
return pagination2(
|
|
14042
|
+
return pagination2(response2);
|
|
14043
14043
|
}
|
|
14044
14044
|
async function writeLog(automation, results) {
|
|
14045
|
-
const
|
|
14045
|
+
const db2 = context_exports.getProdAppDB();
|
|
14046
14046
|
const automationId = automation._id;
|
|
14047
14047
|
const name = automation.name;
|
|
14048
14048
|
const status2 = getStatus(results);
|
|
@@ -14057,13 +14057,13 @@ async function writeLog(automation, results) {
|
|
|
14057
14057
|
createdAt: isoDate,
|
|
14058
14058
|
_id: id
|
|
14059
14059
|
};
|
|
14060
|
-
await
|
|
14060
|
+
await db2.put(log);
|
|
14061
14061
|
return id;
|
|
14062
14062
|
}
|
|
14063
14063
|
async function updateAppMetadataWithErrors(logIds, { clearing } = { clearing: false }) {
|
|
14064
|
-
const
|
|
14064
|
+
const db2 = context_exports.getProdAppDB();
|
|
14065
14065
|
await backOff(async () => {
|
|
14066
|
-
const metadata = await
|
|
14066
|
+
const metadata = await db2.get(db_exports.DocumentType.APP_METADATA);
|
|
14067
14067
|
for (let logId of logIds) {
|
|
14068
14068
|
const parts = logId.split(db_exports.SEPARATOR);
|
|
14069
14069
|
const autoId = `${parts[parts.length - 3]}${db_exports.SEPARATOR}${parts[parts.length - 2]}`;
|
|
@@ -14085,7 +14085,7 @@ async function updateAppMetadataWithErrors(logIds, { clearing } = { clearing: fa
|
|
|
14085
14085
|
}
|
|
14086
14086
|
metadata.automationErrors = errors;
|
|
14087
14087
|
}
|
|
14088
|
-
await
|
|
14088
|
+
await db2.put(metadata);
|
|
14089
14089
|
await cache_exports.app.invalidateAppMetadata(metadata.appId, metadata);
|
|
14090
14090
|
}, "Failed to update app metadata with automation log error");
|
|
14091
14091
|
}
|
|
@@ -14102,7 +14102,7 @@ async function getExpiredLogs() {
|
|
|
14102
14102
|
}
|
|
14103
14103
|
}
|
|
14104
14104
|
async function clearOldHistory() {
|
|
14105
|
-
const
|
|
14105
|
+
const db2 = context_exports.getProdAppDB();
|
|
14106
14106
|
try {
|
|
14107
14107
|
const expired = await getExpiredLogs();
|
|
14108
14108
|
if (!expired.data || expired.data.length === 0) {
|
|
@@ -14118,13 +14118,13 @@ async function clearOldHistory() {
|
|
|
14118
14118
|
const status2 = parts[parts.length - 1];
|
|
14119
14119
|
return status2 === "error" /* ERROR */;
|
|
14120
14120
|
}).map((doc) => doc.id);
|
|
14121
|
-
await
|
|
14121
|
+
await db2.bulkDocs(toDelete);
|
|
14122
14122
|
if (errorLogIds.length) {
|
|
14123
14123
|
await updateAppMetadataWithErrors(errorLogIds, { clearing: true });
|
|
14124
14124
|
}
|
|
14125
14125
|
} catch (err) {
|
|
14126
14126
|
logging_exports.logAlert(
|
|
14127
|
-
`Failed to cleanup automation log history - Database "${
|
|
14127
|
+
`Failed to cleanup automation log history - Database "${db2.name}"`,
|
|
14128
14128
|
err
|
|
14129
14129
|
);
|
|
14130
14130
|
}
|
|
@@ -14163,27 +14163,27 @@ __export(logging_exports2, {
|
|
|
14163
14163
|
storeLog: () => storeLog
|
|
14164
14164
|
});
|
|
14165
14165
|
async function getLogs(startDate, status2, automationId, page) {
|
|
14166
|
-
let
|
|
14166
|
+
let response2;
|
|
14167
14167
|
let endDate = (/* @__PURE__ */ new Date()).toISOString();
|
|
14168
14168
|
const maxStartDate = await oldestLogDate2();
|
|
14169
14169
|
if (!startDate || startDate < maxStartDate) {
|
|
14170
14170
|
startDate = maxStartDate;
|
|
14171
14171
|
}
|
|
14172
14172
|
if (automationId || status2) {
|
|
14173
|
-
|
|
14173
|
+
response2 = await getLogsByView(startDate, endDate, {
|
|
14174
14174
|
automationId,
|
|
14175
14175
|
status: status2,
|
|
14176
14176
|
page
|
|
14177
14177
|
});
|
|
14178
14178
|
} else {
|
|
14179
|
-
|
|
14179
|
+
response2 = await getAllLogs(startDate, endDate, {
|
|
14180
14180
|
status: status2,
|
|
14181
14181
|
page,
|
|
14182
14182
|
docs: true,
|
|
14183
14183
|
paginate: true
|
|
14184
14184
|
});
|
|
14185
14185
|
}
|
|
14186
|
-
return
|
|
14186
|
+
return response2;
|
|
14187
14187
|
}
|
|
14188
14188
|
async function logSearch(options2) {
|
|
14189
14189
|
await clearOldHistory();
|
|
@@ -14243,9 +14243,9 @@ var init_errors4 = __esm({
|
|
|
14243
14243
|
async function findHighestRole(groups, appId) {
|
|
14244
14244
|
try {
|
|
14245
14245
|
let potentialRoles = [];
|
|
14246
|
-
for (let
|
|
14247
|
-
if (
|
|
14248
|
-
potentialRoles.push(
|
|
14246
|
+
for (let group2 of groups) {
|
|
14247
|
+
if (group2.roles) {
|
|
14248
|
+
potentialRoles.push(group2.roles[db_exports.getProdAppID(appId)]);
|
|
14249
14249
|
}
|
|
14250
14250
|
}
|
|
14251
14251
|
const allRoleNumbersArr = await Promise.all(
|
|
@@ -14285,7 +14285,7 @@ async function getGroupRoleId(user, appId, opts) {
|
|
|
14285
14285
|
let groupsToAdd;
|
|
14286
14286
|
if (opts == null ? void 0 : opts.groups) {
|
|
14287
14287
|
groupsToAdd = opts.groups.filter(
|
|
14288
|
-
(
|
|
14288
|
+
(group2) => user.userGroups.includes(group2._id)
|
|
14289
14289
|
);
|
|
14290
14290
|
} else {
|
|
14291
14291
|
groupsToAdd = await groups_exports.getBulk(user.userGroups, {
|
|
@@ -14296,11 +14296,11 @@ async function getGroupRoleId(user, appId, opts) {
|
|
|
14296
14296
|
if ((_a = user.roles) == null ? void 0 : _a[prodAppId]) {
|
|
14297
14297
|
return user.roles[prodAppId];
|
|
14298
14298
|
}
|
|
14299
|
-
groupsToAdd = groupsToAdd.filter((
|
|
14300
|
-
if (!(
|
|
14299
|
+
groupsToAdd = groupsToAdd.filter((group2) => {
|
|
14300
|
+
if (!(group2 == null ? void 0 : group2.roles)) {
|
|
14301
14301
|
return false;
|
|
14302
14302
|
}
|
|
14303
|
-
const appIds = Object.keys(
|
|
14303
|
+
const appIds = Object.keys(group2.roles);
|
|
14304
14304
|
return appIds.includes(prodAppId);
|
|
14305
14305
|
});
|
|
14306
14306
|
return await findHighestRole(groupsToAdd, appId);
|
|
@@ -14311,9 +14311,9 @@ async function enrichUserRolesFromGroups(user) {
|
|
|
14311
14311
|
}
|
|
14312
14312
|
const retrievedGroups = await getBulk2(user.userGroups, { enriched: false });
|
|
14313
14313
|
let allGroupAppIds = [];
|
|
14314
|
-
for (let
|
|
14315
|
-
if (
|
|
14316
|
-
allGroupAppIds = allGroupAppIds.concat(Object.keys(
|
|
14314
|
+
for (let group2 of retrievedGroups) {
|
|
14315
|
+
if (group2 == null ? void 0 : group2.roles) {
|
|
14316
|
+
allGroupAppIds = allGroupAppIds.concat(Object.keys(group2.roles));
|
|
14317
14317
|
}
|
|
14318
14318
|
}
|
|
14319
14319
|
allGroupAppIds = [...new Set(allGroupAppIds)];
|
|
@@ -14343,29 +14343,29 @@ async function guardNameAvailility(name) {
|
|
|
14343
14343
|
throw new GroupNameUnavailableError(name);
|
|
14344
14344
|
}
|
|
14345
14345
|
}
|
|
14346
|
-
async function save4(
|
|
14346
|
+
async function save4(group2) {
|
|
14347
14347
|
let eventPromises = [];
|
|
14348
|
-
let isCreate = !
|
|
14349
|
-
delete
|
|
14348
|
+
let isCreate = !group2._id;
|
|
14349
|
+
delete group2.users;
|
|
14350
14350
|
groups_exports.getUserGroupsParams;
|
|
14351
|
-
if (!
|
|
14352
|
-
|
|
14353
|
-
await guardNameAvailility(
|
|
14354
|
-
eventPromises.push(events_exports.group.created(
|
|
14351
|
+
if (!group2._id) {
|
|
14352
|
+
group2._id = groups_exports.generateUserGroupID();
|
|
14353
|
+
await guardNameAvailility(group2.name);
|
|
14354
|
+
eventPromises.push(events_exports.group.created(group2));
|
|
14355
14355
|
} else {
|
|
14356
|
-
const oldGroup = await groups_exports.get(
|
|
14357
|
-
if (oldGroup.name !==
|
|
14358
|
-
await guardNameAvailility(
|
|
14356
|
+
const oldGroup = await groups_exports.get(group2._id);
|
|
14357
|
+
if (oldGroup.name !== group2.name) {
|
|
14358
|
+
await guardNameAvailility(group2.name);
|
|
14359
14359
|
}
|
|
14360
|
-
eventPromises.push(events_exports.group.updated(
|
|
14361
|
-
if (JSON.stringify(oldGroup.roles) !== JSON.stringify(
|
|
14362
|
-
eventPromises.push(events_exports.group.permissionsEdited(
|
|
14360
|
+
eventPromises.push(events_exports.group.updated(group2));
|
|
14361
|
+
if (JSON.stringify(oldGroup.roles) !== JSON.stringify(group2.roles)) {
|
|
14362
|
+
eventPromises.push(events_exports.group.permissionsEdited(group2));
|
|
14363
14363
|
}
|
|
14364
14364
|
}
|
|
14365
14365
|
try {
|
|
14366
14366
|
await Promise.all(eventPromises);
|
|
14367
14367
|
const saveGroup = () => {
|
|
14368
|
-
return groups_exports.save(
|
|
14368
|
+
return groups_exports.save(group2);
|
|
14369
14369
|
};
|
|
14370
14370
|
if (isCreate) {
|
|
14371
14371
|
return await addGroup(saveGroup);
|
|
@@ -14377,15 +14377,15 @@ async function save4(group) {
|
|
|
14377
14377
|
}
|
|
14378
14378
|
}
|
|
14379
14379
|
async function remove2(groupId, revision) {
|
|
14380
|
-
let
|
|
14380
|
+
let group2;
|
|
14381
14381
|
try {
|
|
14382
|
-
|
|
14382
|
+
group2 = await groups_exports.get(groupId);
|
|
14383
14383
|
} catch (err) {
|
|
14384
14384
|
throw new Error("Group not found");
|
|
14385
14385
|
}
|
|
14386
14386
|
try {
|
|
14387
14387
|
let resp = await groups_exports.destroy(groupId, revision);
|
|
14388
|
-
await events_exports.group.deleted(
|
|
14388
|
+
await events_exports.group.deleted(group2);
|
|
14389
14389
|
await removeGroup();
|
|
14390
14390
|
return resp;
|
|
14391
14391
|
} catch (err) {
|
|
@@ -14393,7 +14393,7 @@ async function remove2(groupId, revision) {
|
|
|
14393
14393
|
}
|
|
14394
14394
|
}
|
|
14395
14395
|
async function addUsers2(groupId, userIds) {
|
|
14396
|
-
const
|
|
14396
|
+
const group2 = await groups_exports.get(groupId);
|
|
14397
14397
|
const users2 = await users_exports2.bulkGetGlobalUsersById(userIds);
|
|
14398
14398
|
let toUpdate = [];
|
|
14399
14399
|
for (let user of users2) {
|
|
@@ -14412,12 +14412,12 @@ async function addUsers2(groupId, userIds) {
|
|
|
14412
14412
|
}
|
|
14413
14413
|
await Promise.all(promises);
|
|
14414
14414
|
if (toUpdate.length) {
|
|
14415
|
-
await events_exports.group.usersAdded(toUpdate.length,
|
|
14415
|
+
await events_exports.group.usersAdded(toUpdate.length, group2);
|
|
14416
14416
|
}
|
|
14417
14417
|
return toUpdate;
|
|
14418
14418
|
}
|
|
14419
14419
|
async function removeUsers2(groupId, userIds) {
|
|
14420
|
-
const
|
|
14420
|
+
const group2 = await groups_exports.get(groupId);
|
|
14421
14421
|
const users2 = await users_exports2.bulkGetGlobalUsersById(userIds);
|
|
14422
14422
|
let toUpdate = [];
|
|
14423
14423
|
for (let user of users2) {
|
|
@@ -14435,36 +14435,36 @@ async function removeUsers2(groupId, userIds) {
|
|
|
14435
14435
|
}
|
|
14436
14436
|
await Promise.all(promises);
|
|
14437
14437
|
if (toUpdate.length) {
|
|
14438
|
-
await events_exports.group.usersDeleted(toUpdate.length,
|
|
14438
|
+
await events_exports.group.usersDeleted(toUpdate.length, group2);
|
|
14439
14439
|
}
|
|
14440
14440
|
return toUpdate;
|
|
14441
14441
|
}
|
|
14442
14442
|
async function updateGroupApps(groupId, opts) {
|
|
14443
|
-
const
|
|
14444
|
-
if (!
|
|
14445
|
-
|
|
14443
|
+
const group2 = await get6(groupId);
|
|
14444
|
+
if (!group2.roles) {
|
|
14445
|
+
group2.roles = {};
|
|
14446
14446
|
}
|
|
14447
14447
|
if (opts.appsToAdd) {
|
|
14448
14448
|
for (let add of opts.appsToAdd) {
|
|
14449
|
-
|
|
14449
|
+
group2.roles[add.appId] = add.roleId;
|
|
14450
14450
|
}
|
|
14451
14451
|
}
|
|
14452
14452
|
if (opts.appsToRemove) {
|
|
14453
14453
|
for (let remove7 of opts.appsToRemove) {
|
|
14454
|
-
delete
|
|
14454
|
+
delete group2.roles[remove7.appId];
|
|
14455
14455
|
}
|
|
14456
14456
|
}
|
|
14457
|
-
return await save4(
|
|
14457
|
+
return await save4(group2);
|
|
14458
14458
|
}
|
|
14459
14459
|
async function cleanupApp(appId) {
|
|
14460
14460
|
const groupList = await fetch9();
|
|
14461
14461
|
const toUpdate = [];
|
|
14462
|
-
for (let
|
|
14463
|
-
if (!
|
|
14462
|
+
for (let group2 of groupList) {
|
|
14463
|
+
if (!group2.roles || !group2.roles[appId]) {
|
|
14464
14464
|
continue;
|
|
14465
14465
|
}
|
|
14466
|
-
delete
|
|
14467
|
-
toUpdate.push(
|
|
14466
|
+
delete group2.roles[appId];
|
|
14467
|
+
toUpdate.push(group2);
|
|
14468
14468
|
}
|
|
14469
14469
|
return await groups_exports.bulkSave(toUpdate);
|
|
14470
14470
|
}
|
|
@@ -14518,7 +14518,7 @@ __export(plugins_exports, {
|
|
|
14518
14518
|
storePlugin: () => storePlugin
|
|
14519
14519
|
});
|
|
14520
14520
|
async function storePlugin(metadata, directory, source) {
|
|
14521
|
-
const
|
|
14521
|
+
const db2 = tenancy.getGlobalDB();
|
|
14522
14522
|
const version = metadata.package.version, name = metadata.package.name, description = metadata.package.description, hash2 = metadata.schema.hash;
|
|
14523
14523
|
const bucketPath = objectStore_exports2.getPluginS3Dir(name);
|
|
14524
14524
|
const files = await objectStore_exports2.uploadDirectory(
|
|
@@ -14545,7 +14545,7 @@ async function storePlugin(metadata, directory, source) {
|
|
|
14545
14545
|
const pluginId = db_exports.generatePluginID(name);
|
|
14546
14546
|
let rev;
|
|
14547
14547
|
try {
|
|
14548
|
-
const existing = await
|
|
14548
|
+
const existing = await db2.get(pluginId);
|
|
14549
14549
|
rev = existing._rev;
|
|
14550
14550
|
} catch (err) {
|
|
14551
14551
|
rev = void 0;
|
|
@@ -14569,11 +14569,11 @@ async function storePlugin(metadata, directory, source) {
|
|
|
14569
14569
|
};
|
|
14570
14570
|
}
|
|
14571
14571
|
const write2 = async () => {
|
|
14572
|
-
const
|
|
14572
|
+
const response2 = await db2.put(doc);
|
|
14573
14573
|
await events_exports.plugin.imported(doc);
|
|
14574
14574
|
return {
|
|
14575
14575
|
...doc,
|
|
14576
|
-
_rev:
|
|
14576
|
+
_rev: response2.rev
|
|
14577
14577
|
};
|
|
14578
14578
|
};
|
|
14579
14579
|
if (!rev) {
|
|
@@ -14583,15 +14583,15 @@ async function storePlugin(metadata, directory, source) {
|
|
|
14583
14583
|
}
|
|
14584
14584
|
}
|
|
14585
14585
|
async function deletePlugin(pluginId) {
|
|
14586
|
-
const
|
|
14586
|
+
const db2 = tenancy.getGlobalDB();
|
|
14587
14587
|
try {
|
|
14588
|
-
const plugin = await
|
|
14588
|
+
const plugin = await db2.get(pluginId);
|
|
14589
14589
|
const bucketPath = objectStore_exports2.getPluginS3Dir(plugin.name);
|
|
14590
14590
|
await objectStore_exports2.deleteFolder(
|
|
14591
14591
|
objectStore_exports2.ObjectStoreBuckets.PLUGINS,
|
|
14592
14592
|
bucketPath
|
|
14593
14593
|
);
|
|
14594
|
-
await
|
|
14594
|
+
await db2.remove(pluginId, plugin._rev);
|
|
14595
14595
|
await events_exports.plugin.deleted(plugin);
|
|
14596
14596
|
await removePlugin();
|
|
14597
14597
|
} catch (err) {
|
|
@@ -14600,9 +14600,9 @@ async function deletePlugin(pluginId) {
|
|
|
14600
14600
|
}
|
|
14601
14601
|
}
|
|
14602
14602
|
async function checkPluginQuotas() {
|
|
14603
|
-
const
|
|
14603
|
+
const db2 = tenancy.getGlobalDB();
|
|
14604
14604
|
try {
|
|
14605
|
-
const allPlugins = await
|
|
14605
|
+
const allPlugins = await db2.allDocs(db_exports.getPluginParams());
|
|
14606
14606
|
const pluginCount = allPlugins.rows.length;
|
|
14607
14607
|
console.log(`Syncing plugin count: ${pluginCount}`);
|
|
14608
14608
|
await updatePluginCount(pluginCount);
|
|
@@ -14710,11 +14710,11 @@ async function save5(doc) {
|
|
|
14710
14710
|
doc._id = generateAuditLogID(doc.timestamp);
|
|
14711
14711
|
}
|
|
14712
14712
|
try {
|
|
14713
|
-
const
|
|
14714
|
-
const
|
|
14713
|
+
const db2 = context_exports.getAuditLogsDB();
|
|
14714
|
+
const response2 = await db2.put(doc);
|
|
14715
14715
|
return {
|
|
14716
14716
|
...doc,
|
|
14717
|
-
_rev:
|
|
14717
|
+
_rev: response2.rev
|
|
14718
14718
|
};
|
|
14719
14719
|
} catch (err) {
|
|
14720
14720
|
logging_exports.logAlert("Failed to write audit log", err);
|
|
@@ -14738,9 +14738,9 @@ async function search(search6, bookmark) {
|
|
|
14738
14738
|
);
|
|
14739
14739
|
}
|
|
14740
14740
|
function dump(params2) {
|
|
14741
|
-
const
|
|
14741
|
+
const db2 = context_exports.getAuditLogsDB();
|
|
14742
14742
|
const stream3 = new MemoryStream();
|
|
14743
|
-
const promise =
|
|
14743
|
+
const promise = db2.dump(stream3, {
|
|
14744
14744
|
filter: (doc) => {
|
|
14745
14745
|
var _a;
|
|
14746
14746
|
const auditLog = doc;
|
|
@@ -14768,8 +14768,8 @@ function dump(params2) {
|
|
|
14768
14768
|
}
|
|
14769
14769
|
});
|
|
14770
14770
|
const returnStream = new MemoryStream();
|
|
14771
|
-
stream3.on("data", (
|
|
14772
|
-
const json2 = JSON.parse(Buffer.from(
|
|
14771
|
+
stream3.on("data", (data2) => {
|
|
14772
|
+
const json2 = JSON.parse(Buffer.from(data2).toString());
|
|
14773
14773
|
if (Array.isArray(json2.docs)) {
|
|
14774
14774
|
let str = "";
|
|
14775
14775
|
for (let doc of json2.docs) {
|
|
@@ -14798,9 +14798,9 @@ var init_auditLogs4 = __esm({
|
|
|
14798
14798
|
var require_Helper = __commonJS({
|
|
14799
14799
|
"../string-templates/src/helpers/Helper.js"(exports2, module2) {
|
|
14800
14800
|
var Helper = class {
|
|
14801
|
-
constructor(name,
|
|
14801
|
+
constructor(name, fn2, useValueFallback = true) {
|
|
14802
14802
|
this.name = name;
|
|
14803
|
-
this.fn =
|
|
14803
|
+
this.fn = fn2;
|
|
14804
14804
|
this.useValueFallback = useValueFallback;
|
|
14805
14805
|
}
|
|
14806
14806
|
register(handlebars) {
|
|
@@ -15092,14 +15092,14 @@ var require_javascript = __commonJS({
|
|
|
15092
15092
|
return value;
|
|
15093
15093
|
};
|
|
15094
15094
|
var getContextValue = (path2, context) => {
|
|
15095
|
-
let
|
|
15095
|
+
let data2 = context;
|
|
15096
15096
|
path2.split(".").forEach((key) => {
|
|
15097
|
-
if (
|
|
15097
|
+
if (data2 == null || typeof data2 !== "object") {
|
|
15098
15098
|
return null;
|
|
15099
15099
|
}
|
|
15100
|
-
|
|
15100
|
+
data2 = data2[removeSquareBrackets(key)];
|
|
15101
15101
|
});
|
|
15102
|
-
return
|
|
15102
|
+
return data2;
|
|
15103
15103
|
};
|
|
15104
15104
|
module2.exports.processJS = (handlebars, context) => {
|
|
15105
15105
|
if (process && process.env.NO_JS) {
|
|
@@ -15224,9 +15224,9 @@ var require_preprocessor = __commonJS({
|
|
|
15224
15224
|
FINALISE: "finalise"
|
|
15225
15225
|
};
|
|
15226
15226
|
var Preprocessor = class {
|
|
15227
|
-
constructor(name,
|
|
15227
|
+
constructor(name, fn2) {
|
|
15228
15228
|
this.name = name;
|
|
15229
|
-
this.fn =
|
|
15229
|
+
this.fn = fn2;
|
|
15230
15230
|
}
|
|
15231
15231
|
process(fullString, statement, opts) {
|
|
15232
15232
|
const output = this.fn(statement, opts);
|
|
@@ -15289,9 +15289,9 @@ var require_postprocessor = __commonJS({
|
|
|
15289
15289
|
CONVERT_LITERALS: "convert-literals"
|
|
15290
15290
|
};
|
|
15291
15291
|
var Postprocessor = class {
|
|
15292
|
-
constructor(name,
|
|
15292
|
+
constructor(name, fn2) {
|
|
15293
15293
|
this.name = name;
|
|
15294
|
-
this.fn =
|
|
15294
|
+
this.fn = fn2;
|
|
15295
15295
|
}
|
|
15296
15296
|
process(statement) {
|
|
15297
15297
|
return this.fn(statement);
|
|
@@ -17181,11 +17181,11 @@ async function fetch11(params2) {
|
|
|
17181
17181
|
throw new Error("Audit logs not available - license required.");
|
|
17182
17182
|
}
|
|
17183
17183
|
const filter2 = getSearchFilters(params2);
|
|
17184
|
-
const
|
|
17184
|
+
const response2 = await search(filter2, params2.bookmark);
|
|
17185
17185
|
return {
|
|
17186
|
-
hasNextPage:
|
|
17187
|
-
bookmark:
|
|
17188
|
-
data: await enrich(
|
|
17186
|
+
hasNextPage: response2.hasNextPage,
|
|
17187
|
+
bookmark: response2.bookmark,
|
|
17188
|
+
data: await enrich(response2.rows)
|
|
17189
17189
|
};
|
|
17190
17190
|
}
|
|
17191
17191
|
function download(params2) {
|
|
@@ -17409,16 +17409,16 @@ __export(processing_exports, {
|
|
|
17409
17409
|
});
|
|
17410
17410
|
async function init11(opts) {
|
|
17411
17411
|
await getBackupQueue().process(async (job) => {
|
|
17412
|
-
const
|
|
17412
|
+
const data2 = job.data;
|
|
17413
17413
|
try {
|
|
17414
|
-
if (
|
|
17414
|
+
if (data2.export) {
|
|
17415
17415
|
return exportProcessor(job, opts);
|
|
17416
|
-
} else if (
|
|
17416
|
+
} else if (data2.import) {
|
|
17417
17417
|
return importProcessor(job, opts);
|
|
17418
17418
|
}
|
|
17419
17419
|
} catch (err) {
|
|
17420
17420
|
logging_exports.logAlert(
|
|
17421
|
-
`Failed to perform backup for app ID: ${
|
|
17421
|
+
`Failed to perform backup for app ID: ${data2.appId}`,
|
|
17422
17422
|
err
|
|
17423
17423
|
);
|
|
17424
17424
|
}
|
|
@@ -17483,14 +17483,14 @@ async function runBackup(trigger, tenantId, appId, opts) {
|
|
|
17483
17483
|
}
|
|
17484
17484
|
}
|
|
17485
17485
|
async function importProcessor(job, opts) {
|
|
17486
|
-
const
|
|
17487
|
-
const appId =
|
|
17486
|
+
const data2 = job.data;
|
|
17487
|
+
const appId = data2.appId, backupId = data2.import.backupId, nameForBackup = data2.import.nameForBackup, createdBy = data2.import.createdBy;
|
|
17488
17488
|
const tenantId = tenancy.getTenantIDFromAppID(appId);
|
|
17489
17489
|
return tenancy.doInTenant(tenantId, async () => {
|
|
17490
17490
|
const devAppId = db_exports.getDevAppID(appId);
|
|
17491
17491
|
const { rev } = await backup_default2.updateRestoreStatus(
|
|
17492
|
-
|
|
17493
|
-
|
|
17492
|
+
data2.docId,
|
|
17493
|
+
data2.docRev,
|
|
17494
17494
|
"started" /* STARTED */
|
|
17495
17495
|
);
|
|
17496
17496
|
await runBackup("restoring" /* RESTORING */, tenantId, appId, {
|
|
@@ -17513,22 +17513,22 @@ async function importProcessor(job, opts) {
|
|
|
17513
17513
|
logging_exports.logAlert("App restore error", err);
|
|
17514
17514
|
status2 = "failed" /* FAILED */;
|
|
17515
17515
|
}
|
|
17516
|
-
await backup_default2.updateRestoreStatus(
|
|
17516
|
+
await backup_default2.updateRestoreStatus(data2.docId, rev, status2);
|
|
17517
17517
|
});
|
|
17518
17518
|
}
|
|
17519
17519
|
async function exportProcessor(job, opts) {
|
|
17520
|
-
const
|
|
17521
|
-
const appId =
|
|
17520
|
+
const data2 = job.data;
|
|
17521
|
+
const appId = data2.appId, trigger = data2.export.trigger, name = data2.export.name;
|
|
17522
17522
|
const tenantId = tenancy.getTenantIDFromAppID(appId);
|
|
17523
17523
|
await tenancy.doInTenant(tenantId, async () => {
|
|
17524
17524
|
const { rev } = await backup_default2.updateBackupStatus(
|
|
17525
|
-
|
|
17526
|
-
|
|
17525
|
+
data2.docId,
|
|
17526
|
+
data2.docRev,
|
|
17527
17527
|
"started" /* STARTED */
|
|
17528
17528
|
);
|
|
17529
17529
|
return runBackup(trigger, tenantId, appId, {
|
|
17530
17530
|
processing: opts,
|
|
17531
|
-
doc: { id:
|
|
17531
|
+
doc: { id: data2.docId, rev },
|
|
17532
17532
|
name
|
|
17533
17533
|
});
|
|
17534
17534
|
});
|
|
@@ -17608,8 +17608,8 @@ var init_users8 = __esm({
|
|
|
17608
17608
|
constructor(config) {
|
|
17609
17609
|
this.get = async (params2) => {
|
|
17610
17610
|
var _a;
|
|
17611
|
-
const
|
|
17612
|
-
const builder2 = new db_exports.QueryBuilder(
|
|
17611
|
+
const db2 = tenancy.getGlobalDB();
|
|
17612
|
+
const builder2 = new db_exports.QueryBuilder(db2.name, "user" /* USER */);
|
|
17613
17613
|
builder2.setIndexBuilder(db_exports.searchIndexes.createUserIndex);
|
|
17614
17614
|
builder2.setLimit(params2.pageSize);
|
|
17615
17615
|
builder2.addEqual("scimInfo.isSync", true);
|
|
@@ -17792,17 +17792,17 @@ var init_groups7 = __esm({
|
|
|
17792
17792
|
init_groups6();
|
|
17793
17793
|
init_groups3();
|
|
17794
17794
|
save6 = async (ctx) => {
|
|
17795
|
-
const
|
|
17796
|
-
|
|
17797
|
-
delete
|
|
17798
|
-
if (
|
|
17799
|
-
const oldGroup = await get6(
|
|
17800
|
-
|
|
17801
|
-
}
|
|
17802
|
-
const
|
|
17795
|
+
const group2 = ctx.request.body;
|
|
17796
|
+
group2.name = group2.name.trim();
|
|
17797
|
+
delete group2.roles;
|
|
17798
|
+
if (group2._id) {
|
|
17799
|
+
const oldGroup = await get6(group2._id);
|
|
17800
|
+
group2.roles = oldGroup.roles;
|
|
17801
|
+
}
|
|
17802
|
+
const response2 = await save4(group2);
|
|
17803
17803
|
ctx.body = {
|
|
17804
|
-
_id:
|
|
17805
|
-
_rev:
|
|
17804
|
+
_id: response2.id,
|
|
17805
|
+
_rev: response2.rev
|
|
17806
17806
|
};
|
|
17807
17807
|
};
|
|
17808
17808
|
updateGroupUsers = async (ctx) => {
|
|
@@ -18129,18 +18129,18 @@ async function importBackup(ctx) {
|
|
|
18129
18129
|
await checkAppID(ctx, appId);
|
|
18130
18130
|
const backupId = ctx.params.backupId;
|
|
18131
18131
|
const nameForBackup = ctx.request.body.name;
|
|
18132
|
-
const
|
|
18132
|
+
const response2 = await backups_default.triggerAppRestore(
|
|
18133
18133
|
appId,
|
|
18134
18134
|
backupId,
|
|
18135
18135
|
nameForBackup,
|
|
18136
18136
|
(_a = ctx.user) == null ? void 0 : _a._id
|
|
18137
18137
|
);
|
|
18138
|
-
if (!
|
|
18138
|
+
if (!response2) {
|
|
18139
18139
|
ctx.throw(500, "Unable to start restore.");
|
|
18140
18140
|
}
|
|
18141
|
-
await events_exports.backup.appBackupRestored(
|
|
18141
|
+
await events_exports.backup.appBackupRestored(response2.metadata);
|
|
18142
18142
|
ctx.body = {
|
|
18143
|
-
restoredId:
|
|
18143
|
+
restoredId: response2 == null ? void 0 : response2.restoreId,
|
|
18144
18144
|
message: "Restore triggered - process starting."
|
|
18145
18145
|
};
|
|
18146
18146
|
}
|
|
@@ -18830,9 +18830,9 @@ var init_src3 = __esm({
|
|
|
18830
18830
|
});
|
|
18831
18831
|
|
|
18832
18832
|
// ../pro/packages/pro/src/api/controllers/global/scim/groups.ts
|
|
18833
|
-
function cleanResponse(
|
|
18833
|
+
function cleanResponse(group2, excludedAttributes) {
|
|
18834
18834
|
for (const attr of excludedAttributes.split(",")) {
|
|
18835
|
-
delete
|
|
18835
|
+
delete group2[attr];
|
|
18836
18836
|
}
|
|
18837
18837
|
}
|
|
18838
18838
|
var import_lodash, import_scim_patch2, import_scim2_parse_filter, get9, create5, find4, remove6, update6;
|
|
@@ -18867,21 +18867,21 @@ var init_groups9 = __esm({
|
|
|
18867
18867
|
create5 = async (ctx) => {
|
|
18868
18868
|
const groupToCreate = mappers_exports.group.fromScimGroup(ctx.request.body);
|
|
18869
18869
|
const createdGroup = await groups_exports2.save(groupToCreate);
|
|
18870
|
-
const
|
|
18871
|
-
ctx.body = mappers_exports.group.toScimGroupResponse(
|
|
18870
|
+
const group2 = await groups_exports2.get(createdGroup.id);
|
|
18871
|
+
ctx.body = mappers_exports.group.toScimGroupResponse(group2);
|
|
18872
18872
|
};
|
|
18873
18873
|
find4 = async (ctx) => {
|
|
18874
18874
|
const { id } = ctx.params;
|
|
18875
18875
|
if (typeof id !== "string") {
|
|
18876
18876
|
ctx.throw(404);
|
|
18877
18877
|
}
|
|
18878
|
-
const
|
|
18879
|
-
const
|
|
18878
|
+
const group2 = await groups_exports2.get(id);
|
|
18879
|
+
const response2 = mappers_exports.group.toScimGroupResponse(group2);
|
|
18880
18880
|
const { excludedAttributes } = ctx.request.query;
|
|
18881
18881
|
if (excludedAttributes) {
|
|
18882
|
-
cleanResponse(
|
|
18882
|
+
cleanResponse(response2, excludedAttributes);
|
|
18883
18883
|
}
|
|
18884
|
-
ctx.body =
|
|
18884
|
+
ctx.body = response2;
|
|
18885
18885
|
};
|
|
18886
18886
|
remove6 = async (ctx) => {
|
|
18887
18887
|
const { id } = ctx.params;
|
|
@@ -18894,11 +18894,11 @@ var init_groups9 = __esm({
|
|
|
18894
18894
|
};
|
|
18895
18895
|
update6 = async (ctx) => {
|
|
18896
18896
|
const { id } = ctx.params;
|
|
18897
|
-
const
|
|
18898
|
-
if (!
|
|
18897
|
+
const group2 = await groups_exports2.get(id);
|
|
18898
|
+
if (!group2) {
|
|
18899
18899
|
ctx.throw(404);
|
|
18900
18900
|
}
|
|
18901
|
-
const scimGroup = mappers_exports.group.toScimGroupResponse(
|
|
18901
|
+
const scimGroup = mappers_exports.group.toScimGroupResponse(group2);
|
|
18902
18902
|
const patchs = ctx.request.body;
|
|
18903
18903
|
try {
|
|
18904
18904
|
(0, import_scim_patch2.patchBodyValidation)(patchs);
|
|
@@ -18916,7 +18916,7 @@ var init_groups9 = __esm({
|
|
|
18916
18916
|
}
|
|
18917
18917
|
const groupToUpdate = {
|
|
18918
18918
|
...mappers_exports.group.fromScimGroup(patchedScimGroup),
|
|
18919
|
-
_rev:
|
|
18919
|
+
_rev: group2._rev
|
|
18920
18920
|
};
|
|
18921
18921
|
await groups_exports2.save(groupToUpdate);
|
|
18922
18922
|
}
|
|
@@ -19025,7 +19025,7 @@ var init_users10 = __esm({
|
|
|
19025
19025
|
init_src2();
|
|
19026
19026
|
toScimUserResponse = (user) => {
|
|
19027
19027
|
const { isSync, roles, ...scimInfo } = user.scimInfo || {};
|
|
19028
|
-
const
|
|
19028
|
+
const response2 = {
|
|
19029
19029
|
...scimInfo,
|
|
19030
19030
|
schemas: ["urn:ietf:params:scim:schemas:core:2.0:User"],
|
|
19031
19031
|
id: user._id,
|
|
@@ -19037,13 +19037,13 @@ var init_users10 = __esm({
|
|
|
19037
19037
|
active: user.status === "active" /* ACTIVE */
|
|
19038
19038
|
};
|
|
19039
19039
|
if (user.firstName || user.lastName) {
|
|
19040
|
-
|
|
19040
|
+
response2.name = {
|
|
19041
19041
|
formatted: [user.firstName, user.lastName].filter((s) => s).join(" "),
|
|
19042
19042
|
familyName: user.lastName,
|
|
19043
19043
|
givenName: user.firstName
|
|
19044
19044
|
};
|
|
19045
19045
|
}
|
|
19046
|
-
return
|
|
19046
|
+
return response2;
|
|
19047
19047
|
};
|
|
19048
19048
|
isScimUserResponse = (user) => {
|
|
19049
19049
|
return !!(user == null ? void 0 : user.id);
|
|
@@ -19135,31 +19135,31 @@ __export(groups_exports5, {
|
|
|
19135
19135
|
var toScimGroupResponse, isScimGroup, fromScimGroup;
|
|
19136
19136
|
var init_groups10 = __esm({
|
|
19137
19137
|
"../pro/packages/pro/src/mappers/groups.ts"() {
|
|
19138
|
-
toScimGroupResponse = (
|
|
19138
|
+
toScimGroupResponse = (group2) => {
|
|
19139
19139
|
var _a;
|
|
19140
19140
|
return {
|
|
19141
19141
|
schemas: ["urn:ietf:params:scim:schemas:core:2.0:Group"],
|
|
19142
|
-
id:
|
|
19143
|
-
externalId:
|
|
19142
|
+
id: group2._id,
|
|
19143
|
+
externalId: group2.scimInfo.externalId,
|
|
19144
19144
|
meta: {
|
|
19145
19145
|
resourceType: "Group",
|
|
19146
|
-
created: new Date(
|
|
19147
|
-
lastModified: new Date(
|
|
19146
|
+
created: new Date(group2.createdAt),
|
|
19147
|
+
lastModified: new Date(group2.updatedAt)
|
|
19148
19148
|
},
|
|
19149
|
-
displayName:
|
|
19150
|
-
members: (_a =
|
|
19149
|
+
displayName: group2.name,
|
|
19150
|
+
members: (_a = group2.users) == null ? void 0 : _a.map((u) => ({ value: u._id }))
|
|
19151
19151
|
};
|
|
19152
19152
|
};
|
|
19153
|
-
isScimGroup = (
|
|
19154
|
-
return !!(
|
|
19153
|
+
isScimGroup = (group2) => {
|
|
19154
|
+
return !!(group2 == null ? void 0 : group2.id);
|
|
19155
19155
|
};
|
|
19156
|
-
fromScimGroup = (
|
|
19157
|
-
const existingGroup = isScimGroup(
|
|
19156
|
+
fromScimGroup = (group2) => {
|
|
19157
|
+
const existingGroup = isScimGroup(group2) ? group2 : void 0;
|
|
19158
19158
|
const g = {
|
|
19159
19159
|
_id: existingGroup == null ? void 0 : existingGroup.id,
|
|
19160
|
-
name:
|
|
19160
|
+
name: group2.displayName,
|
|
19161
19161
|
scimInfo: {
|
|
19162
|
-
externalId:
|
|
19162
|
+
externalId: group2.externalId,
|
|
19163
19163
|
isSync: true
|
|
19164
19164
|
},
|
|
19165
19165
|
icon: "UserGroup",
|
|
@@ -19635,11 +19635,11 @@ async function exportDB(dbName, opts = {}) {
|
|
|
19635
19635
|
batch_limit: 5,
|
|
19636
19636
|
style: "main_only"
|
|
19637
19637
|
};
|
|
19638
|
-
return db_exports.doWithDB(dbName, async (
|
|
19638
|
+
return db_exports.doWithDB(dbName, async (db2) => {
|
|
19639
19639
|
if (opts == null ? void 0 : opts.exportPath) {
|
|
19640
19640
|
const path2 = opts == null ? void 0 : opts.exportPath;
|
|
19641
19641
|
const writeStream = import_fs11.default.createWriteStream(path2);
|
|
19642
|
-
await
|
|
19642
|
+
await db2.dump(writeStream, exportOpts);
|
|
19643
19643
|
return path2;
|
|
19644
19644
|
} else {
|
|
19645
19645
|
const memStream = new MemoryStream2();
|
|
@@ -19647,7 +19647,7 @@ async function exportDB(dbName, opts = {}) {
|
|
|
19647
19647
|
memStream.on("data", (chunk) => {
|
|
19648
19648
|
appString += chunk.toString();
|
|
19649
19649
|
});
|
|
19650
|
-
await
|
|
19650
|
+
await db2.dump(memStream, exportOpts);
|
|
19651
19651
|
return appString;
|
|
19652
19652
|
}
|
|
19653
19653
|
});
|
|
@@ -19751,12 +19751,12 @@ function rewriteAttachmentUrl(appId, attachment) {
|
|
|
19751
19751
|
// calculated on retrieval using key
|
|
19752
19752
|
};
|
|
19753
19753
|
}
|
|
19754
|
-
async function updateAttachmentColumns(prodAppId,
|
|
19755
|
-
const tables = await sdk_default.tables.getAllInternalTables(
|
|
19754
|
+
async function updateAttachmentColumns(prodAppId, db2) {
|
|
19755
|
+
const tables = await sdk_default.tables.getAllInternalTables(db2);
|
|
19756
19756
|
let updatedRows = [];
|
|
19757
19757
|
for (let table of tables) {
|
|
19758
19758
|
const { rows: rows2, columns } = await sdk_default.rows.getRowsWithAttachments(
|
|
19759
|
-
|
|
19759
|
+
db2.name,
|
|
19760
19760
|
table
|
|
19761
19761
|
);
|
|
19762
19762
|
updatedRows = updatedRows.concat(
|
|
@@ -19772,11 +19772,11 @@ async function updateAttachmentColumns(prodAppId, db) {
|
|
|
19772
19772
|
})
|
|
19773
19773
|
);
|
|
19774
19774
|
}
|
|
19775
|
-
await
|
|
19775
|
+
await db2.bulkDocs(updatedRows);
|
|
19776
19776
|
}
|
|
19777
|
-
async function updateAutomations(prodAppId,
|
|
19777
|
+
async function updateAutomations(prodAppId, db2) {
|
|
19778
19778
|
var _a;
|
|
19779
|
-
const automations2 = (await
|
|
19779
|
+
const automations2 = (await db2.allDocs(
|
|
19780
19780
|
getAutomationParams(null, {
|
|
19781
19781
|
include_docs: true
|
|
19782
19782
|
})
|
|
@@ -19795,7 +19795,7 @@ async function updateAutomations(prodAppId, db) {
|
|
|
19795
19795
|
automation.appId = devAppId;
|
|
19796
19796
|
toSave.push(automation);
|
|
19797
19797
|
}
|
|
19798
|
-
await
|
|
19798
|
+
await db2.bulkDocs(toSave);
|
|
19799
19799
|
}
|
|
19800
19800
|
async function getTemplateStream(template) {
|
|
19801
19801
|
if (template.file && template.file.type !== "text/plain") {
|
|
@@ -19825,7 +19825,7 @@ function getGlobalDBFile(tmpPath) {
|
|
|
19825
19825
|
function getListOfAppsInMulti(tmpPath) {
|
|
19826
19826
|
return import_fs12.default.readdirSync(tmpPath).filter((dir) => dir !== GLOBAL_DB_EXPORT_FILE);
|
|
19827
19827
|
}
|
|
19828
|
-
async function importApp(appId,
|
|
19828
|
+
async function importApp(appId, db2, template) {
|
|
19829
19829
|
var _a, _b;
|
|
19830
19830
|
let prodAppId = db_exports.getProdAppID(appId);
|
|
19831
19831
|
let dbStream;
|
|
@@ -19863,12 +19863,12 @@ async function importApp(appId, db, template) {
|
|
|
19863
19863
|
} else {
|
|
19864
19864
|
dbStream = await getTemplateStream(template);
|
|
19865
19865
|
}
|
|
19866
|
-
const { ok } = await
|
|
19866
|
+
const { ok } = await db2.load(dbStream);
|
|
19867
19867
|
if (!ok) {
|
|
19868
19868
|
throw "Error loading database dump from template.";
|
|
19869
19869
|
}
|
|
19870
|
-
await updateAttachmentColumns(prodAppId,
|
|
19871
|
-
await updateAutomations(prodAppId,
|
|
19870
|
+
await updateAttachmentColumns(prodAppId, db2);
|
|
19871
|
+
await updateAutomations(prodAppId, db2);
|
|
19872
19872
|
return ok;
|
|
19873
19873
|
}
|
|
19874
19874
|
var import_path11, import_fs12, uuid4, tar4;
|
|
@@ -19897,54 +19897,54 @@ __export(statistics_exports, {
|
|
|
19897
19897
|
calculateDatasourceCount: () => calculateDatasourceCount,
|
|
19898
19898
|
calculateScreenCount: () => calculateScreenCount
|
|
19899
19899
|
});
|
|
19900
|
-
async function runInContext(appId, cb,
|
|
19901
|
-
if (
|
|
19902
|
-
return cb(
|
|
19900
|
+
async function runInContext(appId, cb, db2) {
|
|
19901
|
+
if (db2) {
|
|
19902
|
+
return cb(db2);
|
|
19903
19903
|
} else {
|
|
19904
19904
|
const devAppId = db_exports.getDevAppID(appId);
|
|
19905
19905
|
return context_exports.doInAppContext(devAppId, () => {
|
|
19906
|
-
const
|
|
19907
|
-
return cb(
|
|
19906
|
+
const db3 = context_exports.getAppDB();
|
|
19907
|
+
return cb(db3);
|
|
19908
19908
|
});
|
|
19909
19909
|
}
|
|
19910
19910
|
}
|
|
19911
|
-
async function calculateDatasourceCount(appId,
|
|
19911
|
+
async function calculateDatasourceCount(appId, db2) {
|
|
19912
19912
|
return runInContext(
|
|
19913
19913
|
appId,
|
|
19914
|
-
async (
|
|
19915
|
-
const datasourceList = await
|
|
19916
|
-
const tableList = await
|
|
19914
|
+
async (db3) => {
|
|
19915
|
+
const datasourceList = await db3.allDocs(getDatasourceParams());
|
|
19916
|
+
const tableList = await db3.allDocs(getTableParams());
|
|
19917
19917
|
return datasourceList.rows.length + tableList.rows.length;
|
|
19918
19918
|
},
|
|
19919
|
-
|
|
19919
|
+
db2
|
|
19920
19920
|
);
|
|
19921
19921
|
}
|
|
19922
|
-
async function calculateAutomationCount(appId,
|
|
19922
|
+
async function calculateAutomationCount(appId, db2) {
|
|
19923
19923
|
return runInContext(
|
|
19924
19924
|
appId,
|
|
19925
|
-
async (
|
|
19926
|
-
const automationList = await
|
|
19925
|
+
async (db3) => {
|
|
19926
|
+
const automationList = await db3.allDocs(getAutomationParams());
|
|
19927
19927
|
return automationList.rows.length;
|
|
19928
19928
|
},
|
|
19929
|
-
|
|
19929
|
+
db2
|
|
19930
19930
|
);
|
|
19931
19931
|
}
|
|
19932
|
-
async function calculateScreenCount(appId,
|
|
19932
|
+
async function calculateScreenCount(appId, db2) {
|
|
19933
19933
|
return runInContext(
|
|
19934
19934
|
appId,
|
|
19935
|
-
async (
|
|
19936
|
-
const screenList = await
|
|
19935
|
+
async (db3) => {
|
|
19936
|
+
const screenList = await db3.allDocs(getScreenParams());
|
|
19937
19937
|
return screenList.rows.length;
|
|
19938
19938
|
},
|
|
19939
|
-
|
|
19939
|
+
db2
|
|
19940
19940
|
);
|
|
19941
19941
|
}
|
|
19942
19942
|
async function calculateBackupStats(appId) {
|
|
19943
|
-
return runInContext(appId, async (
|
|
19943
|
+
return runInContext(appId, async (db2) => {
|
|
19944
19944
|
const promises = [];
|
|
19945
|
-
promises.push(calculateDatasourceCount(appId,
|
|
19946
|
-
promises.push(calculateAutomationCount(appId,
|
|
19947
|
-
promises.push(calculateScreenCount(appId,
|
|
19945
|
+
promises.push(calculateDatasourceCount(appId, db2));
|
|
19946
|
+
promises.push(calculateAutomationCount(appId, db2));
|
|
19947
|
+
promises.push(calculateScreenCount(appId, db2));
|
|
19948
19948
|
const responses = await Promise.all(promises);
|
|
19949
19949
|
return {
|
|
19950
19950
|
datasources: responses[0],
|
|
@@ -20481,15 +20481,15 @@ var init_sql = __esm({
|
|
|
20481
20481
|
}
|
|
20482
20482
|
// right now we only do filters on the specific table being queried
|
|
20483
20483
|
addFilters(query, filters, opts) {
|
|
20484
|
-
function iterate(structure,
|
|
20484
|
+
function iterate(structure, fn2) {
|
|
20485
20485
|
for (let [key, value] of Object.entries(structure)) {
|
|
20486
20486
|
const updatedKey = db_exports.removeKeyNumbering(key);
|
|
20487
20487
|
const isRelationshipField = updatedKey.includes(".");
|
|
20488
20488
|
if (!opts.relationship && !isRelationshipField) {
|
|
20489
|
-
|
|
20489
|
+
fn2(`${opts.tableName}.${updatedKey}`, value);
|
|
20490
20490
|
}
|
|
20491
20491
|
if (opts.relationship && isRelationshipField) {
|
|
20492
|
-
|
|
20492
|
+
fn2(updatedKey, value);
|
|
20493
20493
|
}
|
|
20494
20494
|
}
|
|
20495
20495
|
}
|
|
@@ -20902,8 +20902,8 @@ var init_sql = __esm({
|
|
|
20902
20902
|
if (operation === "DELETE" /* DELETE */) {
|
|
20903
20903
|
row = processFn(await this.getReturningRow(queryFn, json2));
|
|
20904
20904
|
}
|
|
20905
|
-
const
|
|
20906
|
-
const results = processFn(
|
|
20905
|
+
const response2 = await queryFn(input, operation);
|
|
20906
|
+
const results = processFn(response2);
|
|
20907
20907
|
if (operation === "CREATE" /* CREATE */ || operation === "UPDATE" /* UPDATE */) {
|
|
20908
20908
|
let id;
|
|
20909
20909
|
if (sqlClient === "mssql" /* MS_SQL */) {
|
|
@@ -21040,18 +21040,18 @@ var init_postgres = __esm({
|
|
|
21040
21040
|
this.open = false;
|
|
21041
21041
|
}
|
|
21042
21042
|
async testConnection() {
|
|
21043
|
-
const
|
|
21043
|
+
const response2 = {
|
|
21044
21044
|
connected: false
|
|
21045
21045
|
};
|
|
21046
21046
|
try {
|
|
21047
21047
|
await this.openConnection();
|
|
21048
|
-
|
|
21048
|
+
response2.connected = true;
|
|
21049
21049
|
} catch (e) {
|
|
21050
|
-
|
|
21050
|
+
response2.error = e.message;
|
|
21051
21051
|
} finally {
|
|
21052
21052
|
await this.closeConnection();
|
|
21053
21053
|
}
|
|
21054
|
-
return
|
|
21054
|
+
return response2;
|
|
21055
21055
|
}
|
|
21056
21056
|
getBindingIdentifier() {
|
|
21057
21057
|
return `$${this.index++}`;
|
|
@@ -21182,20 +21182,20 @@ var init_postgres = __esm({
|
|
|
21182
21182
|
}
|
|
21183
21183
|
}
|
|
21184
21184
|
async create(query) {
|
|
21185
|
-
const
|
|
21186
|
-
return
|
|
21185
|
+
const response2 = await this.internalQuery(getSqlQuery(query));
|
|
21186
|
+
return response2.rows.length ? response2.rows : [{ created: true }];
|
|
21187
21187
|
}
|
|
21188
21188
|
async read(query) {
|
|
21189
|
-
const
|
|
21190
|
-
return
|
|
21189
|
+
const response2 = await this.internalQuery(getSqlQuery(query));
|
|
21190
|
+
return response2.rows;
|
|
21191
21191
|
}
|
|
21192
21192
|
async update(query) {
|
|
21193
|
-
const
|
|
21194
|
-
return
|
|
21193
|
+
const response2 = await this.internalQuery(getSqlQuery(query));
|
|
21194
|
+
return response2.rows.length ? response2.rows : [{ updated: true }];
|
|
21195
21195
|
}
|
|
21196
21196
|
async delete(query) {
|
|
21197
|
-
const
|
|
21198
|
-
return
|
|
21197
|
+
const response2 = await this.internalQuery(getSqlQuery(query));
|
|
21198
|
+
return response2.rows.length ? response2.rows : [{ deleted: true }];
|
|
21199
21199
|
}
|
|
21200
21200
|
async query(json2) {
|
|
21201
21201
|
const operation = this._operation(json2).toLowerCase();
|
|
@@ -21208,8 +21208,8 @@ var init_postgres = __esm({
|
|
|
21208
21208
|
await this.closeConnection();
|
|
21209
21209
|
return responses;
|
|
21210
21210
|
} else {
|
|
21211
|
-
const
|
|
21212
|
-
return
|
|
21211
|
+
const response2 = await this.internalQuery(input);
|
|
21212
|
+
return response2.rows.length ? response2.rows : [{ [operation]: true }];
|
|
21213
21213
|
}
|
|
21214
21214
|
}
|
|
21215
21215
|
};
|
|
@@ -21383,16 +21383,16 @@ var init_dynamodb = __esm({
|
|
|
21383
21383
|
this.client = new import_aws_sdk2.default.DynamoDB.DocumentClient(this.config);
|
|
21384
21384
|
}
|
|
21385
21385
|
async testConnection() {
|
|
21386
|
-
const
|
|
21386
|
+
const response2 = {
|
|
21387
21387
|
connected: false
|
|
21388
21388
|
};
|
|
21389
21389
|
try {
|
|
21390
21390
|
const scanRes = await new import_aws_sdk2.default.DynamoDB(this.config).listTables().promise();
|
|
21391
|
-
|
|
21391
|
+
response2.connected = !!scanRes.$response;
|
|
21392
21392
|
} catch (e) {
|
|
21393
|
-
|
|
21393
|
+
response2.error = e.message;
|
|
21394
21394
|
}
|
|
21395
|
-
return
|
|
21395
|
+
return response2;
|
|
21396
21396
|
}
|
|
21397
21397
|
async create(query) {
|
|
21398
21398
|
const params2 = {
|
|
@@ -21407,11 +21407,11 @@ var init_dynamodb = __esm({
|
|
|
21407
21407
|
IndexName: query.index ? query.index : void 0,
|
|
21408
21408
|
...query.json
|
|
21409
21409
|
};
|
|
21410
|
-
const
|
|
21411
|
-
if (
|
|
21412
|
-
return
|
|
21410
|
+
const response2 = await this.client.query(params2).promise();
|
|
21411
|
+
if (response2.Items) {
|
|
21412
|
+
return response2.Items;
|
|
21413
21413
|
}
|
|
21414
|
-
return
|
|
21414
|
+
return response2;
|
|
21415
21415
|
}
|
|
21416
21416
|
async scan(query) {
|
|
21417
21417
|
const params2 = {
|
|
@@ -21419,11 +21419,11 @@ var init_dynamodb = __esm({
|
|
|
21419
21419
|
IndexName: query.index ? query.index : void 0,
|
|
21420
21420
|
...query.json
|
|
21421
21421
|
};
|
|
21422
|
-
const
|
|
21423
|
-
if (
|
|
21424
|
-
return
|
|
21422
|
+
const response2 = await this.client.scan(params2).promise();
|
|
21423
|
+
if (response2.Items) {
|
|
21424
|
+
return response2.Items;
|
|
21425
21425
|
}
|
|
21426
|
-
return
|
|
21426
|
+
return response2;
|
|
21427
21427
|
}
|
|
21428
21428
|
async describe(query) {
|
|
21429
21429
|
const params2 = {
|
|
@@ -21797,16 +21797,16 @@ var init_mongodb = __esm({
|
|
|
21797
21797
|
this.client = new import_mongodb.MongoClient(config.connectionString, options2);
|
|
21798
21798
|
}
|
|
21799
21799
|
async testConnection() {
|
|
21800
|
-
const
|
|
21800
|
+
const response2 = {
|
|
21801
21801
|
connected: false
|
|
21802
21802
|
};
|
|
21803
21803
|
try {
|
|
21804
21804
|
await this.connect();
|
|
21805
|
-
|
|
21805
|
+
response2.connected = true;
|
|
21806
21806
|
} catch (e) {
|
|
21807
|
-
|
|
21807
|
+
response2.error = e.message;
|
|
21808
21808
|
}
|
|
21809
|
-
return
|
|
21809
|
+
return response2;
|
|
21810
21810
|
}
|
|
21811
21811
|
async connect() {
|
|
21812
21812
|
return this.client.connect();
|
|
@@ -21877,8 +21877,8 @@ var init_mongodb = __esm({
|
|
|
21877
21877
|
async create(query) {
|
|
21878
21878
|
try {
|
|
21879
21879
|
await this.connect();
|
|
21880
|
-
const
|
|
21881
|
-
const collection =
|
|
21880
|
+
const db2 = this.client.db(this.config.db);
|
|
21881
|
+
const collection = db2.collection(query.extra.collection);
|
|
21882
21882
|
let json2 = this.createObjectIds(query.json);
|
|
21883
21883
|
switch (query.extra.actionType) {
|
|
21884
21884
|
case "insertOne": {
|
|
@@ -21903,8 +21903,8 @@ var init_mongodb = __esm({
|
|
|
21903
21903
|
async read(query) {
|
|
21904
21904
|
try {
|
|
21905
21905
|
await this.connect();
|
|
21906
|
-
const
|
|
21907
|
-
const collection =
|
|
21906
|
+
const db2 = this.client.db(this.config.db);
|
|
21907
|
+
const collection = db2.collection(query.extra.collection);
|
|
21908
21908
|
let json2 = this.createObjectIds(query.json);
|
|
21909
21909
|
switch (query.extra.actionType) {
|
|
21910
21910
|
case "find": {
|
|
@@ -21946,8 +21946,8 @@ var init_mongodb = __esm({
|
|
|
21946
21946
|
async update(query) {
|
|
21947
21947
|
try {
|
|
21948
21948
|
await this.connect();
|
|
21949
|
-
const
|
|
21950
|
-
const collection =
|
|
21949
|
+
const db2 = this.client.db(this.config.db);
|
|
21950
|
+
const collection = db2.collection(query.extra.collection);
|
|
21951
21951
|
let queryJson = query.json;
|
|
21952
21952
|
if (typeof queryJson === "string") {
|
|
21953
21953
|
queryJson = this.parseQueryParams(queryJson, "update");
|
|
@@ -21984,8 +21984,8 @@ var init_mongodb = __esm({
|
|
|
21984
21984
|
async delete(query) {
|
|
21985
21985
|
try {
|
|
21986
21986
|
await this.connect();
|
|
21987
|
-
const
|
|
21988
|
-
const collection =
|
|
21987
|
+
const db2 = this.client.db(this.config.db);
|
|
21988
|
+
const collection = db2.collection(query.extra.collection);
|
|
21989
21989
|
let queryJson = query.json;
|
|
21990
21990
|
if (typeof queryJson === "string") {
|
|
21991
21991
|
queryJson = this.parseQueryParams(queryJson, "delete");
|
|
@@ -22021,9 +22021,9 @@ var init_mongodb = __esm({
|
|
|
22021
22021
|
var _a;
|
|
22022
22022
|
try {
|
|
22023
22023
|
await this.connect();
|
|
22024
|
-
const
|
|
22025
|
-
const collection =
|
|
22026
|
-
let
|
|
22024
|
+
const db2 = this.client.db(this.config.db);
|
|
22025
|
+
const collection = db2.collection(query.extra.collection);
|
|
22026
|
+
let response2 = [];
|
|
22027
22027
|
if (((_a = query.extra) == null ? void 0 : _a.actionType) === "pipeline") {
|
|
22028
22028
|
for await (const doc of collection.aggregate(
|
|
22029
22029
|
query.steps.map(({ key, value }) => {
|
|
@@ -22032,17 +22032,17 @@ var init_mongodb = __esm({
|
|
|
22032
22032
|
return this.createObjectIds(temp);
|
|
22033
22033
|
})
|
|
22034
22034
|
)) {
|
|
22035
|
-
|
|
22035
|
+
response2.push(doc);
|
|
22036
22036
|
}
|
|
22037
22037
|
} else {
|
|
22038
22038
|
const stages = query.json;
|
|
22039
22039
|
for await (const doc of collection.aggregate(
|
|
22040
22040
|
stages ? this.createObjectIds(stages) : []
|
|
22041
22041
|
)) {
|
|
22042
|
-
|
|
22042
|
+
response2.push(doc);
|
|
22043
22043
|
}
|
|
22044
22044
|
}
|
|
22045
|
-
return
|
|
22045
|
+
return response2;
|
|
22046
22046
|
} catch (err) {
|
|
22047
22047
|
console.error("Error writing to mongodb", err);
|
|
22048
22048
|
throw err;
|
|
@@ -22298,16 +22298,16 @@ var init_couchdb = __esm({
|
|
|
22298
22298
|
this.client = db_exports.DatabaseWithConnection(config.database, config.url);
|
|
22299
22299
|
}
|
|
22300
22300
|
async testConnection() {
|
|
22301
|
-
const
|
|
22301
|
+
const response2 = {
|
|
22302
22302
|
connected: false
|
|
22303
22303
|
};
|
|
22304
22304
|
try {
|
|
22305
22305
|
const result = await this.query("exists", "validation error", {});
|
|
22306
|
-
|
|
22306
|
+
response2.connected = result === true;
|
|
22307
22307
|
} catch (e) {
|
|
22308
|
-
|
|
22308
|
+
response2.error = e.message;
|
|
22309
22309
|
}
|
|
22310
|
-
return
|
|
22310
|
+
return response2;
|
|
22311
22311
|
}
|
|
22312
22312
|
async query(command, errorMsg, query) {
|
|
22313
22313
|
try {
|
|
@@ -22457,16 +22457,16 @@ var init_microsoftSqlServer = __esm({
|
|
|
22457
22457
|
}
|
|
22458
22458
|
}
|
|
22459
22459
|
async testConnection() {
|
|
22460
|
-
const
|
|
22460
|
+
const response2 = {
|
|
22461
22461
|
connected: false
|
|
22462
22462
|
};
|
|
22463
22463
|
try {
|
|
22464
22464
|
await this.connect();
|
|
22465
|
-
|
|
22465
|
+
response2.connected = true;
|
|
22466
22466
|
} catch (e) {
|
|
22467
|
-
|
|
22467
|
+
response2.error = e.message;
|
|
22468
22468
|
}
|
|
22469
|
-
return
|
|
22469
|
+
return response2;
|
|
22470
22470
|
}
|
|
22471
22471
|
getBindingIdentifier() {
|
|
22472
22472
|
return `@p${this.index++}`;
|
|
@@ -22592,23 +22592,23 @@ var init_microsoftSqlServer = __esm({
|
|
|
22592
22592
|
}
|
|
22593
22593
|
async read(query) {
|
|
22594
22594
|
await this.connect();
|
|
22595
|
-
const
|
|
22596
|
-
return
|
|
22595
|
+
const response2 = await this.internalQuery(getSqlQuery(query));
|
|
22596
|
+
return response2.recordset;
|
|
22597
22597
|
}
|
|
22598
22598
|
async create(query) {
|
|
22599
22599
|
await this.connect();
|
|
22600
|
-
const
|
|
22601
|
-
return
|
|
22600
|
+
const response2 = await this.internalQuery(getSqlQuery(query));
|
|
22601
|
+
return response2.recordset || [{ created: true }];
|
|
22602
22602
|
}
|
|
22603
22603
|
async update(query) {
|
|
22604
22604
|
await this.connect();
|
|
22605
|
-
const
|
|
22606
|
-
return
|
|
22605
|
+
const response2 = await this.internalQuery(getSqlQuery(query));
|
|
22606
|
+
return response2.recordset || [{ updated: true }];
|
|
22607
22607
|
}
|
|
22608
22608
|
async delete(query) {
|
|
22609
22609
|
await this.connect();
|
|
22610
|
-
const
|
|
22611
|
-
return
|
|
22610
|
+
const response2 = await this.internalQuery(getSqlQuery(query));
|
|
22611
|
+
return response2.recordset || [{ deleted: true }];
|
|
22612
22612
|
}
|
|
22613
22613
|
async query(json2) {
|
|
22614
22614
|
const schema = this.config.schema;
|
|
@@ -22782,16 +22782,16 @@ var init_s3 = __esm({
|
|
|
22782
22782
|
this.client = new import_aws_sdk3.default.S3(this.config);
|
|
22783
22783
|
}
|
|
22784
22784
|
async testConnection() {
|
|
22785
|
-
const
|
|
22785
|
+
const response2 = {
|
|
22786
22786
|
connected: false
|
|
22787
22787
|
};
|
|
22788
22788
|
try {
|
|
22789
22789
|
await this.client.listBuckets().promise();
|
|
22790
|
-
|
|
22790
|
+
response2.connected = true;
|
|
22791
22791
|
} catch (e) {
|
|
22792
|
-
|
|
22792
|
+
response2.error = e.message;
|
|
22793
22793
|
}
|
|
22794
|
-
return
|
|
22794
|
+
return response2;
|
|
22795
22795
|
}
|
|
22796
22796
|
async create(query) {
|
|
22797
22797
|
var _a;
|
|
@@ -22812,14 +22812,14 @@ var init_s3 = __esm({
|
|
|
22812
22812
|
return await this.client.createBucket(params2).promise();
|
|
22813
22813
|
}
|
|
22814
22814
|
async read(query) {
|
|
22815
|
-
const
|
|
22815
|
+
const response2 = await this.client.listObjects({
|
|
22816
22816
|
Bucket: query.bucket,
|
|
22817
22817
|
Delimiter: query.delimiter,
|
|
22818
22818
|
Marker: query.marker,
|
|
22819
22819
|
MaxKeys: query.maxKeys,
|
|
22820
22820
|
Prefix: query.prefix
|
|
22821
22821
|
}).promise();
|
|
22822
|
-
return
|
|
22822
|
+
return response2.Contents;
|
|
22823
22823
|
}
|
|
22824
22824
|
async readCsv(query) {
|
|
22825
22825
|
const stream3 = this.client.getObject({
|
|
@@ -22831,11 +22831,11 @@ var init_s3 = __esm({
|
|
|
22831
22831
|
stream3.on("error", (err) => {
|
|
22832
22832
|
reject(err);
|
|
22833
22833
|
});
|
|
22834
|
-
const
|
|
22834
|
+
const response2 = (0, import_csvtojson.default)().fromStream(stream3).on("error", () => {
|
|
22835
22835
|
csvError = true;
|
|
22836
22836
|
});
|
|
22837
22837
|
stream3.on("finish", () => {
|
|
22838
|
-
resolve2(
|
|
22838
|
+
resolve2(response2);
|
|
22839
22839
|
});
|
|
22840
22840
|
}).catch((err) => {
|
|
22841
22841
|
if (csvError) {
|
|
@@ -23121,7 +23121,7 @@ var init_mysql = __esm({
|
|
|
23121
23121
|
};
|
|
23122
23122
|
}
|
|
23123
23123
|
async testConnection() {
|
|
23124
|
-
const
|
|
23124
|
+
const response2 = {
|
|
23125
23125
|
connected: false
|
|
23126
23126
|
};
|
|
23127
23127
|
try {
|
|
@@ -23129,11 +23129,11 @@ var init_mysql = __esm({
|
|
|
23129
23129
|
{ sql: "SELECT 1+1 AS checkRes" },
|
|
23130
23130
|
{ connect: true }
|
|
23131
23131
|
);
|
|
23132
|
-
|
|
23132
|
+
response2.connected = (result == null ? void 0 : result.checkRes) == 2;
|
|
23133
23133
|
} catch (e) {
|
|
23134
|
-
|
|
23134
|
+
response2.error = e.message;
|
|
23135
23135
|
}
|
|
23136
|
-
return
|
|
23136
|
+
return response2;
|
|
23137
23137
|
}
|
|
23138
23138
|
getBindingIdentifier() {
|
|
23139
23139
|
return "?";
|
|
@@ -23157,8 +23157,8 @@ var init_mysql = __esm({
|
|
|
23157
23157
|
}
|
|
23158
23158
|
const baseBindings = query.bindings || [];
|
|
23159
23159
|
const bindings = (opts == null ? void 0 : opts.disableCoercion) ? baseBindings : bindingTypeCoerce(baseBindings);
|
|
23160
|
-
const
|
|
23161
|
-
return
|
|
23160
|
+
const response2 = await this.client.query(query.sql, bindings);
|
|
23161
|
+
return response2[0];
|
|
23162
23162
|
} finally {
|
|
23163
23163
|
if ((opts == null ? void 0 : opts.connect) && this.client) {
|
|
23164
23164
|
await this.disconnect();
|
|
@@ -23324,16 +23324,16 @@ var init_arangodb = __esm({
|
|
|
23324
23324
|
this.client = new import_arangojs.Database(newConfig);
|
|
23325
23325
|
}
|
|
23326
23326
|
async testConnection() {
|
|
23327
|
-
const
|
|
23327
|
+
const response2 = {
|
|
23328
23328
|
connected: false
|
|
23329
23329
|
};
|
|
23330
23330
|
try {
|
|
23331
23331
|
await this.client.get();
|
|
23332
|
-
|
|
23332
|
+
response2.connected = true;
|
|
23333
23333
|
} catch (e) {
|
|
23334
|
-
|
|
23334
|
+
response2.error = e.message;
|
|
23335
23335
|
}
|
|
23336
|
-
return
|
|
23336
|
+
return response2;
|
|
23337
23337
|
}
|
|
23338
23338
|
async read(query) {
|
|
23339
23339
|
try {
|
|
@@ -23478,51 +23478,51 @@ var init_rest = __esm({
|
|
|
23478
23478
|
this.startTimeMs = import_perf_hooks.performance.now();
|
|
23479
23479
|
this.config = config;
|
|
23480
23480
|
}
|
|
23481
|
-
async parseResponse(
|
|
23482
|
-
let
|
|
23483
|
-
const contentType =
|
|
23481
|
+
async parseResponse(response2, pagination3) {
|
|
23482
|
+
let data2, raw, headers;
|
|
23483
|
+
const contentType = response2.headers.get("content-type") || "";
|
|
23484
23484
|
try {
|
|
23485
23485
|
if (contentType.includes("application/json")) {
|
|
23486
|
-
|
|
23487
|
-
raw = JSON.stringify(
|
|
23486
|
+
data2 = await response2.json();
|
|
23487
|
+
raw = JSON.stringify(data2);
|
|
23488
23488
|
} else if (contentType.includes("text/xml") || contentType.includes("application/xml")) {
|
|
23489
|
-
const rawXml = await
|
|
23490
|
-
|
|
23489
|
+
const rawXml = await response2.text();
|
|
23490
|
+
data2 = await xmlParser(rawXml, {
|
|
23491
23491
|
explicitArray: false,
|
|
23492
23492
|
trim: true,
|
|
23493
23493
|
explicitRoot: false
|
|
23494
23494
|
}) || {};
|
|
23495
|
-
const keys2 = Object.keys(
|
|
23496
|
-
if (keys2.length === 1 && Array.isArray(
|
|
23497
|
-
|
|
23495
|
+
const keys2 = Object.keys(data2);
|
|
23496
|
+
if (keys2.length === 1 && Array.isArray(data2[keys2[0]])) {
|
|
23497
|
+
data2 = data2[keys2[0]];
|
|
23498
23498
|
}
|
|
23499
23499
|
raw = rawXml;
|
|
23500
23500
|
} else if (contentType.includes("application/pdf")) {
|
|
23501
|
-
|
|
23502
|
-
raw = Buffer.from(
|
|
23501
|
+
data2 = await response2.arrayBuffer();
|
|
23502
|
+
raw = Buffer.from(data2);
|
|
23503
23503
|
} else {
|
|
23504
|
-
|
|
23505
|
-
raw =
|
|
23504
|
+
data2 = await response2.text();
|
|
23505
|
+
raw = data2;
|
|
23506
23506
|
}
|
|
23507
23507
|
} catch (err) {
|
|
23508
23508
|
throw "Failed to parse response body.";
|
|
23509
23509
|
}
|
|
23510
23510
|
const size = formatBytes(
|
|
23511
|
-
|
|
23511
|
+
response2.headers.get("content-length") || Buffer.byteLength(raw, "utf8")
|
|
23512
23512
|
);
|
|
23513
23513
|
const time = `${Math.round(import_perf_hooks.performance.now() - this.startTimeMs)}ms`;
|
|
23514
|
-
headers =
|
|
23514
|
+
headers = response2.headers.raw();
|
|
23515
23515
|
for (let [key, value] of Object.entries(headers)) {
|
|
23516
23516
|
headers[key] = Array.isArray(value) ? value[0] : value;
|
|
23517
23517
|
}
|
|
23518
23518
|
let nextCursor = null;
|
|
23519
23519
|
if (pagination3 == null ? void 0 : pagination3.responseParam) {
|
|
23520
|
-
nextCursor = (0, import_lodash3.get)(
|
|
23520
|
+
nextCursor = (0, import_lodash3.get)(data2, pagination3.responseParam);
|
|
23521
23521
|
}
|
|
23522
23522
|
return {
|
|
23523
|
-
data,
|
|
23523
|
+
data: data2,
|
|
23524
23524
|
info: {
|
|
23525
|
-
code:
|
|
23525
|
+
code: response2.status,
|
|
23526
23526
|
size,
|
|
23527
23527
|
time
|
|
23528
23528
|
},
|
|
@@ -23704,8 +23704,8 @@ var init_rest = __esm({
|
|
|
23704
23704
|
if (await blacklist_exports.isBlacklisted(url)) {
|
|
23705
23705
|
throw new Error("Cannot connect to URL.");
|
|
23706
23706
|
}
|
|
23707
|
-
const
|
|
23708
|
-
return await this.parseResponse(
|
|
23707
|
+
const response2 = await (0, import_node_fetch8.default)(url, input);
|
|
23708
|
+
return await this.parseResponse(response2, pagination3);
|
|
23709
23709
|
}
|
|
23710
23710
|
async create(opts) {
|
|
23711
23711
|
return this._req({ ...opts, method: "POST" });
|
|
@@ -23868,7 +23868,7 @@ var init_googlesheets = __esm({
|
|
|
23868
23868
|
return parts.length > 5 ? parts[5] : spreadsheetId;
|
|
23869
23869
|
}
|
|
23870
23870
|
async fetchAccessToken(payload) {
|
|
23871
|
-
const
|
|
23871
|
+
const response2 = await (0, import_node_fetch9.default)("https://www.googleapis.com/oauth2/v4/token", {
|
|
23872
23872
|
method: "POST",
|
|
23873
23873
|
body: JSON.stringify({
|
|
23874
23874
|
...payload,
|
|
@@ -23878,8 +23878,8 @@ var init_googlesheets = __esm({
|
|
|
23878
23878
|
"Content-Type": "application/json"
|
|
23879
23879
|
}
|
|
23880
23880
|
});
|
|
23881
|
-
const json2 = await
|
|
23882
|
-
if (
|
|
23881
|
+
const json2 = await response2.json();
|
|
23882
|
+
if (response2.status !== 200) {
|
|
23883
23883
|
throw new Error(
|
|
23884
23884
|
`Error authenticating with google sheets. ${json2.error_description}`
|
|
23885
23885
|
);
|
|
@@ -24116,9 +24116,9 @@ var init_googlesheets = __esm({
|
|
|
24116
24116
|
}
|
|
24117
24117
|
const filtered2 = filters_exports.runLuceneQuery(rows2, query.filters);
|
|
24118
24118
|
const headerValues = sheet.headerValues;
|
|
24119
|
-
let
|
|
24119
|
+
let response2 = [];
|
|
24120
24120
|
for (let row of filtered2) {
|
|
24121
|
-
|
|
24121
|
+
response2.push(
|
|
24122
24122
|
this.buildRowObject(headerValues, row._rawData, row._rowNumber)
|
|
24123
24123
|
);
|
|
24124
24124
|
}
|
|
@@ -24129,14 +24129,14 @@ var init_googlesheets = __esm({
|
|
|
24129
24129
|
});
|
|
24130
24130
|
}
|
|
24131
24131
|
const [sortField, sortInfo] = Object.entries(query.sort)[0];
|
|
24132
|
-
|
|
24133
|
-
|
|
24132
|
+
response2 = filters_exports.luceneSort(
|
|
24133
|
+
response2,
|
|
24134
24134
|
sortField,
|
|
24135
24135
|
sortInfo.direction,
|
|
24136
24136
|
sortInfo.type
|
|
24137
24137
|
);
|
|
24138
24138
|
}
|
|
24139
|
-
return
|
|
24139
|
+
return response2;
|
|
24140
24140
|
} catch (err) {
|
|
24141
24141
|
console.error("Error reading from google sheets", err);
|
|
24142
24142
|
throw err;
|
|
@@ -24440,18 +24440,18 @@ var init_redis4 = __esm({
|
|
|
24440
24440
|
});
|
|
24441
24441
|
}
|
|
24442
24442
|
async testConnection() {
|
|
24443
|
-
const
|
|
24443
|
+
const response2 = {
|
|
24444
24444
|
connected: false
|
|
24445
24445
|
};
|
|
24446
24446
|
try {
|
|
24447
24447
|
await this.client.ping();
|
|
24448
|
-
|
|
24448
|
+
response2.connected = true;
|
|
24449
24449
|
} catch (e) {
|
|
24450
|
-
|
|
24450
|
+
response2.error = e.message;
|
|
24451
24451
|
} finally {
|
|
24452
24452
|
await this.disconnect();
|
|
24453
24453
|
}
|
|
24454
|
-
return
|
|
24454
|
+
return response2;
|
|
24455
24455
|
}
|
|
24456
24456
|
async disconnect() {
|
|
24457
24457
|
return this.client.quit();
|
|
@@ -24467,11 +24467,11 @@ var init_redis4 = __esm({
|
|
|
24467
24467
|
}
|
|
24468
24468
|
async create(query) {
|
|
24469
24469
|
return this.redisContext(async () => {
|
|
24470
|
-
const
|
|
24470
|
+
const response2 = await this.client.set(query.key, query.value);
|
|
24471
24471
|
if (query.ttl) {
|
|
24472
24472
|
await this.client.expire(query.key, query.ttl);
|
|
24473
24473
|
}
|
|
24474
|
-
return
|
|
24474
|
+
return response2;
|
|
24475
24475
|
});
|
|
24476
24476
|
}
|
|
24477
24477
|
async read(query) {
|
|
@@ -24867,27 +24867,27 @@ var init_oracle = __esm({
|
|
|
24867
24867
|
return (columnsResponse.rows || []).map((row) => row.TABLE_NAME);
|
|
24868
24868
|
}
|
|
24869
24869
|
async testConnection() {
|
|
24870
|
-
const
|
|
24870
|
+
const response2 = {
|
|
24871
24871
|
connected: false
|
|
24872
24872
|
};
|
|
24873
24873
|
let connection;
|
|
24874
24874
|
try {
|
|
24875
24875
|
connection = await this.getConnection();
|
|
24876
|
-
|
|
24876
|
+
response2.connected = true;
|
|
24877
24877
|
} catch (err) {
|
|
24878
|
-
|
|
24879
|
-
|
|
24878
|
+
response2.connected = false;
|
|
24879
|
+
response2.error = err.message;
|
|
24880
24880
|
} finally {
|
|
24881
24881
|
if (connection) {
|
|
24882
24882
|
try {
|
|
24883
24883
|
await connection.close();
|
|
24884
24884
|
} catch (err) {
|
|
24885
|
-
|
|
24886
|
-
|
|
24885
|
+
response2.connected = false;
|
|
24886
|
+
response2.error = err.message;
|
|
24887
24887
|
}
|
|
24888
24888
|
}
|
|
24889
24889
|
}
|
|
24890
|
-
return
|
|
24890
|
+
return response2;
|
|
24891
24891
|
}
|
|
24892
24892
|
async internalQuery(query) {
|
|
24893
24893
|
let connection;
|
|
@@ -24908,20 +24908,20 @@ var init_oracle = __esm({
|
|
|
24908
24908
|
}
|
|
24909
24909
|
}
|
|
24910
24910
|
async create(query) {
|
|
24911
|
-
const
|
|
24912
|
-
return
|
|
24911
|
+
const response2 = await this.internalQuery(getSqlQuery(query));
|
|
24912
|
+
return response2.rows && response2.rows.length ? response2.rows : [{ created: true }];
|
|
24913
24913
|
}
|
|
24914
24914
|
async read(query) {
|
|
24915
|
-
const
|
|
24916
|
-
return
|
|
24915
|
+
const response2 = await this.internalQuery(getSqlQuery(query));
|
|
24916
|
+
return response2.rows ? response2.rows : [];
|
|
24917
24917
|
}
|
|
24918
24918
|
async update(query) {
|
|
24919
|
-
const
|
|
24920
|
-
return
|
|
24919
|
+
const response2 = await this.internalQuery(getSqlQuery(query));
|
|
24920
|
+
return response2.rows && response2.rows.length ? response2.rows : [{ updated: true }];
|
|
24921
24921
|
}
|
|
24922
24922
|
async delete(query) {
|
|
24923
|
-
const
|
|
24924
|
-
return
|
|
24923
|
+
const response2 = await this.internalQuery(getSqlQuery(query));
|
|
24924
|
+
return response2.rows && response2.rows.length ? response2.rows : [{ deleted: true }];
|
|
24925
24925
|
}
|
|
24926
24926
|
async query(json2) {
|
|
24927
24927
|
var _a, _b, _c;
|
|
@@ -24939,15 +24939,15 @@ var init_oracle = __esm({
|
|
|
24939
24939
|
const queryFn = (query) => this.internalQuery(query);
|
|
24940
24940
|
deletedRows = await this.getReturningRow(queryFn, json2);
|
|
24941
24941
|
}
|
|
24942
|
-
const
|
|
24942
|
+
const response2 = await this.internalQuery(input);
|
|
24943
24943
|
if ((_a = deletedRows == null ? void 0 : deletedRows.rows) == null ? void 0 : _a.length) {
|
|
24944
24944
|
return deletedRows.rows;
|
|
24945
|
-
} else if ((_b =
|
|
24946
|
-
return
|
|
24945
|
+
} else if ((_b = response2.rows) == null ? void 0 : _b.length) {
|
|
24946
|
+
return response2.rows;
|
|
24947
24947
|
} else {
|
|
24948
|
-
if (
|
|
24948
|
+
if (response2.lastRowid && ((_c = json2.endpoint) == null ? void 0 : _c.entityId) && operation !== "DELETE" /* DELETE */) {
|
|
24949
24949
|
const lastRow = await this.internalQuery({
|
|
24950
|
-
sql: `SELECT * FROM "${json2.endpoint.entityId}" WHERE ROWID = '${
|
|
24950
|
+
sql: `SELECT * FROM "${json2.endpoint.entityId}" WHERE ROWID = '${response2.lastRowid}'`
|
|
24951
24951
|
});
|
|
24952
24952
|
return lastRow.rows;
|
|
24953
24953
|
} else {
|
|
@@ -25119,8 +25119,8 @@ async function enrichDatasourceWithValues(datasource2) {
|
|
|
25119
25119
|
};
|
|
25120
25120
|
}
|
|
25121
25121
|
async function enrich2(datasource2) {
|
|
25122
|
-
const { datasource:
|
|
25123
|
-
return
|
|
25122
|
+
const { datasource: response2 } = await enrichDatasourceWithValues(datasource2);
|
|
25123
|
+
return response2;
|
|
25124
25124
|
}
|
|
25125
25125
|
async function get11(datasourceId, opts) {
|
|
25126
25126
|
const appDb = context_exports.getAppDB();
|
|
@@ -25243,11 +25243,11 @@ var init_datasources3 = __esm({
|
|
|
25243
25243
|
});
|
|
25244
25244
|
|
|
25245
25245
|
// src/sdk/app/tables/index.ts
|
|
25246
|
-
async function getAllInternalTables(
|
|
25247
|
-
if (!
|
|
25248
|
-
|
|
25246
|
+
async function getAllInternalTables(db2) {
|
|
25247
|
+
if (!db2) {
|
|
25248
|
+
db2 = context_exports.getAppDB();
|
|
25249
25249
|
}
|
|
25250
|
-
const internalTables = await
|
|
25250
|
+
const internalTables = await db2.allDocs(
|
|
25251
25251
|
getTableParams(null, {
|
|
25252
25252
|
include_docs: true
|
|
25253
25253
|
})
|
|
@@ -25259,7 +25259,7 @@ async function getAllInternalTables(db) {
|
|
|
25259
25259
|
}));
|
|
25260
25260
|
}
|
|
25261
25261
|
async function getAllExternalTables(datasourceId) {
|
|
25262
|
-
const
|
|
25262
|
+
const db2 = context_exports.getAppDB();
|
|
25263
25263
|
const datasource2 = await datasources_default.get(datasourceId, { enriched: true });
|
|
25264
25264
|
if (!datasource2 || !datasource2.entities) {
|
|
25265
25265
|
throw "Datasource is not configured fully.";
|
|
@@ -25271,14 +25271,14 @@ async function getExternalTable(datasourceId, tableName) {
|
|
|
25271
25271
|
return entities[tableName];
|
|
25272
25272
|
}
|
|
25273
25273
|
async function getTable(tableId) {
|
|
25274
|
-
const
|
|
25274
|
+
const db2 = context_exports.getAppDB();
|
|
25275
25275
|
if (isExternalTable(tableId)) {
|
|
25276
25276
|
let { datasourceId, tableName } = breakExternalTableId(tableId);
|
|
25277
25277
|
const datasource2 = await datasources_default.get(datasourceId);
|
|
25278
25278
|
const table = await getExternalTable(datasourceId, tableName);
|
|
25279
25279
|
return { ...table, sql: isSQL(datasource2) };
|
|
25280
25280
|
} else {
|
|
25281
|
-
return
|
|
25281
|
+
return db2.get(tableId);
|
|
25282
25282
|
}
|
|
25283
25283
|
}
|
|
25284
25284
|
var tables_default;
|
|
@@ -25318,22 +25318,22 @@ function newDoc(name, type, target) {
|
|
|
25318
25318
|
};
|
|
25319
25319
|
}
|
|
25320
25320
|
async function save7(webhook) {
|
|
25321
|
-
const
|
|
25321
|
+
const db2 = context_exports.getAppDB();
|
|
25322
25322
|
if (webhook._id && isWebhookID(webhook._id)) {
|
|
25323
|
-
await
|
|
25323
|
+
await db2.get(webhook._id);
|
|
25324
25324
|
} else {
|
|
25325
25325
|
webhook._id = generateWebhookID();
|
|
25326
25326
|
}
|
|
25327
|
-
const
|
|
25328
|
-
webhook._rev =
|
|
25327
|
+
const response2 = await db2.put(webhook);
|
|
25328
|
+
webhook._rev = response2.rev;
|
|
25329
25329
|
return webhook;
|
|
25330
25330
|
}
|
|
25331
25331
|
async function destroy6(id, rev) {
|
|
25332
|
-
const
|
|
25332
|
+
const db2 = context_exports.getAppDB();
|
|
25333
25333
|
if (!id || !isWebhookID(id)) {
|
|
25334
25334
|
throw new Error("Provided webhook ID is not valid.");
|
|
25335
25335
|
}
|
|
25336
|
-
return await
|
|
25336
|
+
return await db2.remove(id, rev);
|
|
25337
25337
|
}
|
|
25338
25338
|
var init_webhook2 = __esm({
|
|
25339
25339
|
"src/sdk/app/automations/webhook.ts"() {
|
|
@@ -25404,8 +25404,8 @@ async function processUser(user, opts = {}) {
|
|
|
25404
25404
|
return user;
|
|
25405
25405
|
}
|
|
25406
25406
|
async function getRawGlobalUser(userId) {
|
|
25407
|
-
const
|
|
25408
|
-
return
|
|
25407
|
+
const db2 = tenancy.getGlobalDB();
|
|
25408
|
+
return db2.get(getGlobalIDFromUserMetadataID2(userId));
|
|
25409
25409
|
}
|
|
25410
25410
|
async function getGlobalUser(userId) {
|
|
25411
25411
|
const appId = context_exports.getAppId();
|
|
@@ -25414,14 +25414,14 @@ async function getGlobalUser(userId) {
|
|
|
25414
25414
|
}
|
|
25415
25415
|
async function getGlobalUsers(userIds, opts) {
|
|
25416
25416
|
const appId = context_exports.getAppId();
|
|
25417
|
-
const
|
|
25417
|
+
const db2 = tenancy.getGlobalDB();
|
|
25418
25418
|
let globalUsers;
|
|
25419
25419
|
if (userIds) {
|
|
25420
|
-
globalUsers = (await
|
|
25420
|
+
globalUsers = (await db2.allDocs(getMultiIDParams(userIds))).rows.map(
|
|
25421
25421
|
(row) => row.doc
|
|
25422
25422
|
);
|
|
25423
25423
|
} else {
|
|
25424
|
-
globalUsers = (await
|
|
25424
|
+
globalUsers = (await db2.allDocs(
|
|
25425
25425
|
db_exports.getGlobalUserParams(null, {
|
|
25426
25426
|
include_docs: true
|
|
25427
25427
|
})
|
|
@@ -25480,7 +25480,7 @@ async function syncUsersToApp(appId, users2, groups) {
|
|
|
25480
25480
|
return;
|
|
25481
25481
|
}
|
|
25482
25482
|
await context_exports.doInAppContext(appId, async () => {
|
|
25483
|
-
const
|
|
25483
|
+
const db2 = context_exports.getAppDB();
|
|
25484
25484
|
for (let user of users2) {
|
|
25485
25485
|
let ctxUser = user;
|
|
25486
25486
|
let deletedUser = false;
|
|
@@ -25497,7 +25497,7 @@ async function syncUsersToApp(appId, users2, groups) {
|
|
|
25497
25497
|
}
|
|
25498
25498
|
let metadata;
|
|
25499
25499
|
try {
|
|
25500
|
-
metadata = await
|
|
25500
|
+
metadata = await db2.get(metadataId);
|
|
25501
25501
|
} catch (err) {
|
|
25502
25502
|
if (err.status !== 404) {
|
|
25503
25503
|
throw err;
|
|
@@ -25511,7 +25511,7 @@ async function syncUsersToApp(appId, users2, groups) {
|
|
|
25511
25511
|
}
|
|
25512
25512
|
}
|
|
25513
25513
|
if (deletedUser || !roleId) {
|
|
25514
|
-
await
|
|
25514
|
+
await db2.remove(metadata);
|
|
25515
25515
|
continue;
|
|
25516
25516
|
}
|
|
25517
25517
|
if (roleId) {
|
|
@@ -25519,7 +25519,7 @@ async function syncUsersToApp(appId, users2, groups) {
|
|
|
25519
25519
|
}
|
|
25520
25520
|
let combined = sdk_default.users.combineMetadataAndUser(ctxUser, metadata);
|
|
25521
25521
|
if (combined) {
|
|
25522
|
-
await
|
|
25522
|
+
await db2.put(combined);
|
|
25523
25523
|
}
|
|
25524
25524
|
}
|
|
25525
25525
|
});
|
|
@@ -25720,7 +25720,7 @@ function generateAttachmentFindParams(tableId, attachmentCols, bookmark) {
|
|
|
25720
25720
|
return params2;
|
|
25721
25721
|
}
|
|
25722
25722
|
async function getRowsWithAttachments(appId, table) {
|
|
25723
|
-
const
|
|
25723
|
+
const db2 = db_exports.getDB(appId);
|
|
25724
25724
|
const attachmentCols = [];
|
|
25725
25725
|
for (let [key, column] of Object.entries(table.schema)) {
|
|
25726
25726
|
if (column.type === "attachment" /* ATTACHMENT */) {
|
|
@@ -25737,7 +25737,7 @@ async function getRowsWithAttachments(appId, table) {
|
|
|
25737
25737
|
attachmentCols,
|
|
25738
25738
|
bookmark
|
|
25739
25739
|
);
|
|
25740
|
-
const resp = await db_exports.directCouchFind(
|
|
25740
|
+
const resp = await db_exports.directCouchFind(db2.name, params2);
|
|
25741
25741
|
bookmark = resp.bookmark;
|
|
25742
25742
|
rowsLength = resp.rows.length;
|
|
25743
25743
|
const rows2 = resp.rows;
|
|
@@ -25761,18 +25761,18 @@ __export(rows_exports, {
|
|
|
25761
25761
|
getAllInternalRows: () => getAllInternalRows
|
|
25762
25762
|
});
|
|
25763
25763
|
async function getAllInternalRows(appId) {
|
|
25764
|
-
let
|
|
25764
|
+
let db2;
|
|
25765
25765
|
if (appId) {
|
|
25766
|
-
|
|
25766
|
+
db2 = db_exports.getDB(appId);
|
|
25767
25767
|
} else {
|
|
25768
|
-
|
|
25768
|
+
db2 = context_exports.getAppDB();
|
|
25769
25769
|
}
|
|
25770
|
-
const
|
|
25770
|
+
const response2 = await db2.allDocs(
|
|
25771
25771
|
getRowParams2(null, null, {
|
|
25772
25772
|
include_docs: true
|
|
25773
25773
|
})
|
|
25774
25774
|
);
|
|
25775
|
-
return
|
|
25775
|
+
return response2.rows.map((row) => row.doc);
|
|
25776
25776
|
}
|
|
25777
25777
|
var init_rows4 = __esm({
|
|
25778
25778
|
"src/sdk/app/rows/rows.ts"() {
|
|
@@ -25831,15 +25831,15 @@ function combineMetadataAndUser(user, metadata) {
|
|
|
25831
25831
|
return null;
|
|
25832
25832
|
}
|
|
25833
25833
|
async function rawUserMetadata() {
|
|
25834
|
-
const
|
|
25835
|
-
return (await
|
|
25834
|
+
const db2 = context_exports.getAppDB();
|
|
25835
|
+
return (await db2.allDocs(
|
|
25836
25836
|
getUserMetadataParams2(null, {
|
|
25837
25837
|
include_docs: true
|
|
25838
25838
|
})
|
|
25839
25839
|
)).rows.map((row) => row.doc);
|
|
25840
25840
|
}
|
|
25841
25841
|
async function syncGlobalUsers() {
|
|
25842
|
-
const
|
|
25842
|
+
const db2 = context_exports.getAppDB();
|
|
25843
25843
|
const resp = await Promise.all([getGlobalUsers(), rawUserMetadata()]);
|
|
25844
25844
|
const users2 = resp[0];
|
|
25845
25845
|
const metadata = resp[1];
|
|
@@ -25851,20 +25851,20 @@ async function syncGlobalUsers() {
|
|
|
25851
25851
|
}
|
|
25852
25852
|
}
|
|
25853
25853
|
let foundEmails = [];
|
|
25854
|
-
for (let
|
|
25855
|
-
if (!
|
|
25854
|
+
for (let data2 of metadata) {
|
|
25855
|
+
if (!data2._id) {
|
|
25856
25856
|
continue;
|
|
25857
25857
|
}
|
|
25858
|
-
const alreadyExisting =
|
|
25859
|
-
const globalId = getGlobalIDFromUserMetadataID2(
|
|
25858
|
+
const alreadyExisting = data2.email && foundEmails.indexOf(data2.email) !== -1;
|
|
25859
|
+
const globalId = getGlobalIDFromUserMetadataID2(data2._id);
|
|
25860
25860
|
if (!users2.find((user) => user._id === globalId) || alreadyExisting) {
|
|
25861
|
-
toWrite.push({ ...
|
|
25861
|
+
toWrite.push({ ...data2, _deleted: true });
|
|
25862
25862
|
}
|
|
25863
|
-
if (
|
|
25864
|
-
foundEmails.push(
|
|
25863
|
+
if (data2.email) {
|
|
25864
|
+
foundEmails.push(data2.email);
|
|
25865
25865
|
}
|
|
25866
25866
|
}
|
|
25867
|
-
await
|
|
25867
|
+
await db2.bulkDocs(toWrite);
|
|
25868
25868
|
}
|
|
25869
25869
|
var import_lodash6;
|
|
25870
25870
|
var init_utils17 = __esm({
|
|
@@ -25997,13 +25997,13 @@ __export(plugins_exports2, {
|
|
|
25997
25997
|
processUploaded: () => processUploaded
|
|
25998
25998
|
});
|
|
25999
25999
|
async function fetch16(type) {
|
|
26000
|
-
const
|
|
26001
|
-
const
|
|
26000
|
+
const db2 = tenancy.getGlobalDB();
|
|
26001
|
+
const response2 = await db2.allDocs(
|
|
26002
26002
|
db_exports.getPluginParams(null, {
|
|
26003
26003
|
include_docs: true
|
|
26004
26004
|
})
|
|
26005
26005
|
);
|
|
26006
|
-
let plugins2 =
|
|
26006
|
+
let plugins2 = response2.rows.map((row) => row.doc);
|
|
26007
26007
|
plugins2 = objectStore_exports2.enrichPluginURLs(plugins2);
|
|
26008
26008
|
if (type) {
|
|
26009
26009
|
return plugins2.filter((plugin) => {
|
|
@@ -26210,8 +26210,8 @@ async function getFullUser(ctx, userId) {
|
|
|
26210
26210
|
delete global._id;
|
|
26211
26211
|
delete global._rev;
|
|
26212
26212
|
try {
|
|
26213
|
-
const
|
|
26214
|
-
metadata = await
|
|
26213
|
+
const db2 = context_exports.getAppDB();
|
|
26214
|
+
metadata = await db2.get(userId);
|
|
26215
26215
|
} catch (err) {
|
|
26216
26216
|
}
|
|
26217
26217
|
delete metadata.csrfToken;
|
|
@@ -26250,20 +26250,20 @@ async function fetchMetadata(ctx) {
|
|
|
26250
26250
|
ctx.body = users2;
|
|
26251
26251
|
}
|
|
26252
26252
|
async function updateMetadata(ctx) {
|
|
26253
|
-
const
|
|
26253
|
+
const db2 = context_exports.getAppDB();
|
|
26254
26254
|
const user = ctx.request.body;
|
|
26255
26255
|
delete user.roles;
|
|
26256
26256
|
const metadata = {
|
|
26257
26257
|
tableId: InternalTables.USER_METADATA,
|
|
26258
26258
|
...user
|
|
26259
26259
|
};
|
|
26260
|
-
ctx.body = await
|
|
26260
|
+
ctx.body = await db2.put(metadata);
|
|
26261
26261
|
}
|
|
26262
26262
|
async function destroyMetadata(ctx) {
|
|
26263
|
-
const
|
|
26263
|
+
const db2 = context_exports.getAppDB();
|
|
26264
26264
|
try {
|
|
26265
|
-
const dbUser = await
|
|
26266
|
-
await
|
|
26265
|
+
const dbUser = await db2.get(ctx.params.id);
|
|
26266
|
+
await db2.remove(dbUser._id, dbUser._rev);
|
|
26267
26267
|
} catch (err) {
|
|
26268
26268
|
}
|
|
26269
26269
|
ctx.body = {
|
|
@@ -26364,7 +26364,7 @@ async function getDatasourceAndQuery(json2) {
|
|
|
26364
26364
|
return makeExternalQuery(datasource2, json2);
|
|
26365
26365
|
}
|
|
26366
26366
|
async function findRow(ctx, tableId, rowId) {
|
|
26367
|
-
const
|
|
26367
|
+
const db2 = context_exports.getAppDB();
|
|
26368
26368
|
let row;
|
|
26369
26369
|
if (tableId === InternalTables.USER_METADATA) {
|
|
26370
26370
|
ctx.params = {
|
|
@@ -26373,7 +26373,7 @@ async function findRow(ctx, tableId, rowId) {
|
|
|
26373
26373
|
await findMetadata(ctx);
|
|
26374
26374
|
row = ctx.body;
|
|
26375
26375
|
} else {
|
|
26376
|
-
row = await
|
|
26376
|
+
row = await db2.get(rowId);
|
|
26377
26377
|
}
|
|
26378
26378
|
if (row.tableId !== tableId) {
|
|
26379
26379
|
throw "Supplied tableId does not match the rows tableId";
|
|
@@ -26599,9 +26599,9 @@ async function run19({ inputs, context }) {
|
|
|
26599
26599
|
}
|
|
26600
26600
|
]
|
|
26601
26601
|
});
|
|
26602
|
-
const
|
|
26602
|
+
const response2 = (_c = (_b = (_a = completion == null ? void 0 : completion.data) == null ? void 0 : _a.choices[0]) == null ? void 0 : _b.message) == null ? void 0 : _c.content;
|
|
26603
26603
|
return {
|
|
26604
|
-
response,
|
|
26604
|
+
response: response2,
|
|
26605
26605
|
success: true
|
|
26606
26606
|
};
|
|
26607
26607
|
} catch (err) {
|
|
@@ -26749,8 +26749,8 @@ function formatResponse(resp) {
|
|
|
26749
26749
|
}
|
|
26750
26750
|
return resp;
|
|
26751
26751
|
}
|
|
26752
|
-
function hasExtraData(
|
|
26753
|
-
return typeof
|
|
26752
|
+
function hasExtraData(response2) {
|
|
26753
|
+
return typeof response2 === "object" && !Array.isArray(response2) && response2 && response2.data != null && response2.info != null;
|
|
26754
26754
|
}
|
|
26755
26755
|
var utils_default = {
|
|
26756
26756
|
hasExtraData,
|
|
@@ -26813,7 +26813,7 @@ var _Thread = class {
|
|
|
26813
26813
|
const timeout2 = this.timeoutMs;
|
|
26814
26814
|
return new Promise((resolve2, reject) => {
|
|
26815
26815
|
function fire(worker) {
|
|
26816
|
-
worker.execute(job, (err,
|
|
26816
|
+
worker.execute(job, (err, response2) => {
|
|
26817
26817
|
if (err && err.type === "TimeoutError") {
|
|
26818
26818
|
reject(
|
|
26819
26819
|
new Error(`Query response time exceeded ${timeout2}ms timeout.`)
|
|
@@ -26821,7 +26821,7 @@ var _Thread = class {
|
|
|
26821
26821
|
} else if (err) {
|
|
26822
26822
|
reject(err);
|
|
26823
26823
|
} else {
|
|
26824
|
-
resolve2(
|
|
26824
|
+
resolve2(response2);
|
|
26825
26825
|
}
|
|
26826
26826
|
});
|
|
26827
26827
|
}
|
|
@@ -27178,13 +27178,13 @@ function request(ctx, request2) {
|
|
|
27178
27178
|
logging_exports.correlation.setHeader(request2.headers);
|
|
27179
27179
|
return request2;
|
|
27180
27180
|
}
|
|
27181
|
-
async function checkResponse(
|
|
27182
|
-
if (
|
|
27181
|
+
async function checkResponse(response2, errorMsg, { ctx } = {}) {
|
|
27182
|
+
if (response2.status !== 200) {
|
|
27183
27183
|
let error;
|
|
27184
27184
|
try {
|
|
27185
|
-
error = await
|
|
27185
|
+
error = await response2.json();
|
|
27186
27186
|
} catch (err) {
|
|
27187
|
-
error = await
|
|
27187
|
+
error = await response2.text();
|
|
27188
27188
|
}
|
|
27189
27189
|
const msg = `Unable to ${errorMsg} - ${error.message ? error.message : error}`;
|
|
27190
27190
|
if (ctx) {
|
|
@@ -27193,10 +27193,10 @@ async function checkResponse(response, errorMsg, { ctx } = {}) {
|
|
|
27193
27193
|
throw msg;
|
|
27194
27194
|
}
|
|
27195
27195
|
}
|
|
27196
|
-
return
|
|
27196
|
+
return response2.json();
|
|
27197
27197
|
}
|
|
27198
27198
|
async function sendSmtpEmail(to, from, subject, contents, cc, bcc, automation) {
|
|
27199
|
-
const
|
|
27199
|
+
const response2 = await (0, import_node_fetch10.default)(
|
|
27200
27200
|
checkSlashesInUrl2(environment_default.WORKER_URL + `/api/global/email/send`),
|
|
27201
27201
|
request(void 0, {
|
|
27202
27202
|
method: "POST",
|
|
@@ -27212,7 +27212,7 @@ async function sendSmtpEmail(to, from, subject, contents, cc, bcc, automation) {
|
|
|
27212
27212
|
}
|
|
27213
27213
|
})
|
|
27214
27214
|
);
|
|
27215
|
-
return checkResponse(
|
|
27215
|
+
return checkResponse(response2, "send email");
|
|
27216
27216
|
}
|
|
27217
27217
|
|
|
27218
27218
|
// src/automations/steps/sendSmtpEmail.ts
|
|
@@ -27279,7 +27279,7 @@ async function run3({ inputs }) {
|
|
|
27279
27279
|
}
|
|
27280
27280
|
to = to || void 0;
|
|
27281
27281
|
try {
|
|
27282
|
-
let
|
|
27282
|
+
let response2 = await sendSmtpEmail(
|
|
27283
27283
|
to,
|
|
27284
27284
|
from,
|
|
27285
27285
|
subject,
|
|
@@ -27290,7 +27290,7 @@ async function run3({ inputs }) {
|
|
|
27290
27290
|
);
|
|
27291
27291
|
return {
|
|
27292
27292
|
success: true,
|
|
27293
|
-
response
|
|
27293
|
+
response: response2
|
|
27294
27294
|
};
|
|
27295
27295
|
} catch (err) {
|
|
27296
27296
|
return {
|
|
@@ -27328,9 +27328,9 @@ init_utils13();
|
|
|
27328
27328
|
init_src();
|
|
27329
27329
|
var SCREEN_PREFIX = DocumentType5.SCREEN + SEPARATOR7;
|
|
27330
27330
|
async function createLinkView() {
|
|
27331
|
-
const
|
|
27332
|
-
const designDoc = await
|
|
27333
|
-
const
|
|
27331
|
+
const db2 = context_exports.getAppDB();
|
|
27332
|
+
const designDoc = await db2.get("_design/database");
|
|
27333
|
+
const view2 = {
|
|
27334
27334
|
map: function(doc) {
|
|
27335
27335
|
if (doc.type === "link") {
|
|
27336
27336
|
let doc1 = doc.doc1;
|
|
@@ -27352,9 +27352,9 @@ async function createLinkView() {
|
|
|
27352
27352
|
};
|
|
27353
27353
|
designDoc.views = {
|
|
27354
27354
|
...designDoc.views,
|
|
27355
|
-
[ViewName6.LINK]:
|
|
27355
|
+
[ViewName6.LINK]: view2
|
|
27356
27356
|
};
|
|
27357
|
-
await
|
|
27357
|
+
await db2.put(designDoc);
|
|
27358
27358
|
}
|
|
27359
27359
|
|
|
27360
27360
|
// src/db/linkedRows/linkUtils.ts
|
|
@@ -27365,7 +27365,7 @@ var IncludeDocs = {
|
|
|
27365
27365
|
};
|
|
27366
27366
|
async function getLinkDocuments(args) {
|
|
27367
27367
|
const { tableId, rowId, includeDocs } = args;
|
|
27368
|
-
const
|
|
27368
|
+
const db2 = context_exports.getAppDB();
|
|
27369
27369
|
let params2;
|
|
27370
27370
|
if (rowId != null) {
|
|
27371
27371
|
params2 = { key: [tableId, rowId] };
|
|
@@ -27374,7 +27374,7 @@ async function getLinkDocuments(args) {
|
|
|
27374
27374
|
}
|
|
27375
27375
|
params2.include_docs = !!includeDocs;
|
|
27376
27376
|
try {
|
|
27377
|
-
let linkRows = (await
|
|
27377
|
+
let linkRows = (await db2.query(getQueryIndex3(ViewName6.LINK), params2)).rows;
|
|
27378
27378
|
const foundIds = [];
|
|
27379
27379
|
linkRows = linkRows.filter((link) => {
|
|
27380
27380
|
if (tableId && link.key[0] !== tableId || rowId && link.key[1] !== rowId) {
|
|
@@ -27410,12 +27410,12 @@ function getLinkedTableIDs(table) {
|
|
|
27410
27410
|
return Object.values(table.schema).filter((column) => column.type === "link" /* LINK */).map((column) => column.tableId);
|
|
27411
27411
|
}
|
|
27412
27412
|
async function getLinkedTable(id, tables) {
|
|
27413
|
-
const
|
|
27413
|
+
const db2 = context_exports.getAppDB();
|
|
27414
27414
|
let linkedTable = tables.find((table) => table._id === id);
|
|
27415
27415
|
if (linkedTable) {
|
|
27416
27416
|
return linkedTable;
|
|
27417
27417
|
}
|
|
27418
|
-
linkedTable = await
|
|
27418
|
+
linkedTable = await db2.get(id);
|
|
27419
27419
|
if (linkedTable) {
|
|
27420
27420
|
tables.push(linkedTable);
|
|
27421
27421
|
}
|
|
@@ -27744,9 +27744,9 @@ var LinkController = class {
|
|
|
27744
27744
|
throw new Error("Cannot overwrite existing column.");
|
|
27745
27745
|
}
|
|
27746
27746
|
linkedTable.schema[field.fieldName] = linkedField;
|
|
27747
|
-
const
|
|
27747
|
+
const response2 = await this._db.put(linkedTable);
|
|
27748
27748
|
if (linkedTable._id === table._id) {
|
|
27749
|
-
table._rev =
|
|
27749
|
+
table._rev = response2.rev;
|
|
27750
27750
|
}
|
|
27751
27751
|
}
|
|
27752
27752
|
}
|
|
@@ -28196,10 +28196,10 @@ async function getLinksForRows(rows2) {
|
|
|
28196
28196
|
);
|
|
28197
28197
|
}
|
|
28198
28198
|
async function getFullLinkedDocs(links) {
|
|
28199
|
-
const
|
|
28199
|
+
const db2 = context_exports.getAppDB();
|
|
28200
28200
|
const linkedRowIds = links.map((link) => link.id);
|
|
28201
28201
|
const uniqueRowIds = [...new Set(linkedRowIds)];
|
|
28202
|
-
let dbRows = (await
|
|
28202
|
+
let dbRows = (await db2.allDocs(getMultiIDParams(uniqueRowIds))).rows.map(
|
|
28203
28203
|
(row) => row.doc
|
|
28204
28204
|
);
|
|
28205
28205
|
const linked = linkedRowIds.map((id) => dbRows.find((row) => row && row._id === id)).filter((row) => row != null);
|
|
@@ -28328,9 +28328,7 @@ async function runView(view, calculation, group, data) {
|
|
|
28328
28328
|
}))
|
|
28329
28329
|
);
|
|
28330
28330
|
let fn = (doc, emit2) => emit2(doc._id);
|
|
28331
|
-
(0,
|
|
28332
|
-
"fn = " + ((_a = view == null ? void 0 : view.map) == null ? void 0 : _a.replace("function (doc)", "function (doc, emit)"))
|
|
28333
|
-
);
|
|
28331
|
+
eval("fn = " + ((_a = view == null ? void 0 : view.map) == null ? void 0 : _a.replace("function (doc)", "function (doc, emit)")));
|
|
28334
28332
|
const queryFns = {
|
|
28335
28333
|
meta: view.meta,
|
|
28336
28334
|
map: fn
|
|
@@ -28464,16 +28462,16 @@ function parseFilterExpression(filters) {
|
|
|
28464
28462
|
function parseEmitExpression(field, groupBy) {
|
|
28465
28463
|
return `emit(doc["${groupBy || "_id"}"], doc["${field}"]);`;
|
|
28466
28464
|
}
|
|
28467
|
-
function viewBuilder_default({ field, tableId, groupBy, filters = [], calculation }, groupByMulti) {
|
|
28465
|
+
function viewBuilder_default({ field, tableId, groupBy, filters = [], calculation: calculation2 }, groupByMulti) {
|
|
28468
28466
|
if (filters && filters.length > 0 && filters[0].conjunction) {
|
|
28469
28467
|
delete filters[0].conjunction;
|
|
28470
28468
|
}
|
|
28471
28469
|
let schema = null, statFilter = null;
|
|
28472
28470
|
let groupBySchema = groupByMulti ? GROUP_PROPERTY_MULTI : GROUP_PROPERTY;
|
|
28473
|
-
if (
|
|
28471
|
+
if (calculation2) {
|
|
28474
28472
|
schema = {
|
|
28475
28473
|
...groupBy ? groupBySchema : FIELD_PROPERTY,
|
|
28476
|
-
...SCHEMA_MAP[
|
|
28474
|
+
...SCHEMA_MAP[calculation2]
|
|
28477
28475
|
};
|
|
28478
28476
|
if (!filters.find(
|
|
28479
28477
|
(filter2) => filter2.key === field && filter2.condition === CONDITIONS.NOT_EMPTY
|
|
@@ -28488,7 +28486,7 @@ function viewBuilder_default({ field, tableId, groupBy, filters = [], calculatio
|
|
|
28488
28486
|
const emitExpression = parseEmitExpression(field, groupBy);
|
|
28489
28487
|
const tableExpression = `doc.tableId === "${tableId}"`;
|
|
28490
28488
|
const coreExpression = statFilter ? `(${tableExpression} && ${statFilter})` : tableExpression;
|
|
28491
|
-
const reduction = field &&
|
|
28489
|
+
const reduction = field && calculation2 ? { reduce: `_${calculation2}` } : {};
|
|
28492
28490
|
return {
|
|
28493
28491
|
meta: {
|
|
28494
28492
|
field,
|
|
@@ -28496,7 +28494,7 @@ function viewBuilder_default({ field, tableId, groupBy, filters = [], calculatio
|
|
|
28496
28494
|
groupBy,
|
|
28497
28495
|
filters,
|
|
28498
28496
|
schema,
|
|
28499
|
-
calculation
|
|
28497
|
+
calculation: calculation2
|
|
28500
28498
|
},
|
|
28501
28499
|
map: `function (doc) {
|
|
28502
28500
|
if (${coreExpression} ${filterExpression}) {
|
|
@@ -28508,36 +28506,36 @@ function viewBuilder_default({ field, tableId, groupBy, filters = [], calculatio
|
|
|
28508
28506
|
}
|
|
28509
28507
|
|
|
28510
28508
|
// src/api/controllers/view/utils.ts
|
|
28511
|
-
async function migrateToInMemoryView(
|
|
28512
|
-
const designDoc = await
|
|
28513
|
-
const
|
|
28509
|
+
async function migrateToInMemoryView(db2, viewName) {
|
|
28510
|
+
const designDoc = await db2.get("_design/database");
|
|
28511
|
+
const view2 = viewBuilder_default(designDoc.views[viewName].meta);
|
|
28514
28512
|
delete designDoc.views[viewName];
|
|
28515
|
-
await
|
|
28516
|
-
await exports.saveView(
|
|
28517
|
-
}
|
|
28518
|
-
async function migrateToDesignView(
|
|
28519
|
-
let
|
|
28520
|
-
const designDoc = await
|
|
28521
|
-
designDoc.views[viewName] = viewBuilder_default(
|
|
28522
|
-
await
|
|
28523
|
-
await
|
|
28524
|
-
}
|
|
28525
|
-
async function getFromDesignDoc(
|
|
28526
|
-
const designDoc = await
|
|
28527
|
-
let
|
|
28528
|
-
if (
|
|
28513
|
+
await db2.put(designDoc);
|
|
28514
|
+
await exports.saveView(db2, null, viewName, view2);
|
|
28515
|
+
}
|
|
28516
|
+
async function migrateToDesignView(db2, viewName) {
|
|
28517
|
+
let view2 = await db2.get(generateMemoryViewID(viewName));
|
|
28518
|
+
const designDoc = await db2.get("_design/database");
|
|
28519
|
+
designDoc.views[viewName] = viewBuilder_default(view2.view.meta);
|
|
28520
|
+
await db2.put(designDoc);
|
|
28521
|
+
await db2.remove(view2._id, view2._rev);
|
|
28522
|
+
}
|
|
28523
|
+
async function getFromDesignDoc(db2, viewName) {
|
|
28524
|
+
const designDoc = await db2.get("_design/database");
|
|
28525
|
+
let view2 = designDoc.views[viewName];
|
|
28526
|
+
if (view2 == null) {
|
|
28529
28527
|
throw { status: 404, message: "Unable to get view" };
|
|
28530
28528
|
}
|
|
28531
|
-
return
|
|
28529
|
+
return view2;
|
|
28532
28530
|
}
|
|
28533
|
-
async function getFromMemoryDoc(
|
|
28534
|
-
let
|
|
28535
|
-
if (
|
|
28536
|
-
|
|
28531
|
+
async function getFromMemoryDoc(db2, viewName) {
|
|
28532
|
+
let view2 = await db2.get(generateMemoryViewID(viewName));
|
|
28533
|
+
if (view2) {
|
|
28534
|
+
view2 = view2.view;
|
|
28537
28535
|
} else {
|
|
28538
28536
|
throw { status: 404, message: "Unable to get view" };
|
|
28539
28537
|
}
|
|
28540
|
-
return
|
|
28538
|
+
return view2;
|
|
28541
28539
|
}
|
|
28542
28540
|
|
|
28543
28541
|
// src/api/controllers/row/internal.ts
|
|
@@ -28551,7 +28549,7 @@ init_src2();
|
|
|
28551
28549
|
var { isEqual: isEqual2 } = require("lodash");
|
|
28552
28550
|
var { cloneDeep: cloneDeep8 } = require("lodash/fp");
|
|
28553
28551
|
async function updateRelatedFormula(table, enrichedRows) {
|
|
28554
|
-
const
|
|
28552
|
+
const db2 = context_exports.getAppDB();
|
|
28555
28553
|
if (!table.relatedFormula) {
|
|
28556
28554
|
return;
|
|
28557
28555
|
}
|
|
@@ -28578,7 +28576,7 @@ async function updateRelatedFormula(table, enrichedRows) {
|
|
|
28578
28576
|
if (!relatedRows[tableId] || relatedRows[tableId].length === 0) {
|
|
28579
28577
|
continue;
|
|
28580
28578
|
}
|
|
28581
|
-
relatedTable = await
|
|
28579
|
+
relatedTable = await db2.get(tableId);
|
|
28582
28580
|
} catch (err) {
|
|
28583
28581
|
}
|
|
28584
28582
|
for (let column of Object.values(relatedTable.schema)) {
|
|
@@ -28600,7 +28598,7 @@ async function updateRelatedFormula(table, enrichedRows) {
|
|
|
28600
28598
|
async function finaliseRow(table, row, { oldTable, updateFormula } = {
|
|
28601
28599
|
updateFormula: true
|
|
28602
28600
|
}) {
|
|
28603
|
-
const
|
|
28601
|
+
const db2 = context_exports.getAppDB();
|
|
28604
28602
|
row.type = "row";
|
|
28605
28603
|
let enrichedRow = await outputProcessing(table, cloneDeep8(row), {
|
|
28606
28604
|
squash: false
|
|
@@ -28611,22 +28609,22 @@ async function finaliseRow(table, row, { oldTable, updateFormula } = {
|
|
|
28611
28609
|
});
|
|
28612
28610
|
if (oldTable && !isEqual2(oldTable, table)) {
|
|
28613
28611
|
try {
|
|
28614
|
-
await
|
|
28612
|
+
await db2.put(table);
|
|
28615
28613
|
} catch (err) {
|
|
28616
28614
|
if (err.status === 409) {
|
|
28617
|
-
const updatedTable = await
|
|
28618
|
-
let
|
|
28615
|
+
const updatedTable = await db2.get(table._id);
|
|
28616
|
+
let response3 = processAutoColumn(null, updatedTable, row, {
|
|
28619
28617
|
reprocessing: true
|
|
28620
28618
|
});
|
|
28621
|
-
await
|
|
28622
|
-
row =
|
|
28619
|
+
await db2.put(response3.table);
|
|
28620
|
+
row = response3.row;
|
|
28623
28621
|
} else {
|
|
28624
28622
|
throw err;
|
|
28625
28623
|
}
|
|
28626
28624
|
}
|
|
28627
28625
|
}
|
|
28628
|
-
const
|
|
28629
|
-
enrichedRow._rev =
|
|
28626
|
+
const response2 = await db2.put(row);
|
|
28627
|
+
enrichedRow._rev = response2.rev;
|
|
28630
28628
|
enrichedRow = await processFormulas(table, enrichedRow, { dynamic: false });
|
|
28631
28629
|
if (updateFormula) {
|
|
28632
28630
|
await updateRelatedFormula(table, enrichedRow);
|
|
@@ -28643,52 +28641,52 @@ var CALCULATION_TYPES = {
|
|
|
28643
28641
|
COUNT: "count",
|
|
28644
28642
|
STATS: "stats"
|
|
28645
28643
|
};
|
|
28646
|
-
async function getView(
|
|
28644
|
+
async function getView(db2, viewName) {
|
|
28647
28645
|
let mainGetter = environment_default.SELF_HOSTED ? getFromDesignDoc : getFromMemoryDoc;
|
|
28648
28646
|
let secondaryGetter = environment_default.SELF_HOSTED ? getFromMemoryDoc : getFromDesignDoc;
|
|
28649
28647
|
let migration = environment_default.SELF_HOSTED ? migrateToDesignView : migrateToInMemoryView;
|
|
28650
28648
|
let viewInfo, migrate = false;
|
|
28651
28649
|
try {
|
|
28652
|
-
viewInfo = await mainGetter(
|
|
28650
|
+
viewInfo = await mainGetter(db2, viewName);
|
|
28653
28651
|
} catch (err) {
|
|
28654
28652
|
if (err.status !== 404) {
|
|
28655
28653
|
viewInfo = null;
|
|
28656
28654
|
} else {
|
|
28657
|
-
viewInfo = await secondaryGetter(
|
|
28655
|
+
viewInfo = await secondaryGetter(db2, viewName);
|
|
28658
28656
|
migrate = !!viewInfo;
|
|
28659
28657
|
}
|
|
28660
28658
|
}
|
|
28661
28659
|
if (migrate) {
|
|
28662
|
-
await migration(
|
|
28660
|
+
await migration(db2, viewName);
|
|
28663
28661
|
}
|
|
28664
28662
|
if (!viewInfo) {
|
|
28665
28663
|
throw "View does not exist.";
|
|
28666
28664
|
}
|
|
28667
28665
|
return viewInfo;
|
|
28668
28666
|
}
|
|
28669
|
-
async function getRawTableData(ctx,
|
|
28667
|
+
async function getRawTableData(ctx, db2, tableId) {
|
|
28670
28668
|
let rows2;
|
|
28671
28669
|
if (tableId === InternalTables.USER_METADATA) {
|
|
28672
28670
|
await fetchMetadata(ctx);
|
|
28673
28671
|
rows2 = ctx.body;
|
|
28674
28672
|
} else {
|
|
28675
|
-
const
|
|
28673
|
+
const response2 = await db2.allDocs(
|
|
28676
28674
|
getRowParams2(tableId, null, {
|
|
28677
28675
|
include_docs: true
|
|
28678
28676
|
})
|
|
28679
28677
|
);
|
|
28680
|
-
rows2 =
|
|
28678
|
+
rows2 = response2.rows.map((row) => row.doc);
|
|
28681
28679
|
}
|
|
28682
28680
|
return rows2;
|
|
28683
28681
|
}
|
|
28684
28682
|
async function patch(ctx) {
|
|
28685
|
-
const
|
|
28683
|
+
const db2 = context_exports.getAppDB();
|
|
28686
28684
|
const inputs = ctx.request.body;
|
|
28687
28685
|
const tableId = inputs.tableId;
|
|
28688
28686
|
const isUserTable = tableId === InternalTables.USER_METADATA;
|
|
28689
28687
|
let oldRow;
|
|
28690
28688
|
try {
|
|
28691
|
-
let dbTable2 = await
|
|
28689
|
+
let dbTable2 = await db2.get(tableId);
|
|
28692
28690
|
oldRow = await outputProcessing(
|
|
28693
28691
|
dbTable2,
|
|
28694
28692
|
await findRow(ctx, tableId, inputs._id)
|
|
@@ -28702,7 +28700,7 @@ async function patch(ctx) {
|
|
|
28702
28700
|
throw "Row does not exist";
|
|
28703
28701
|
}
|
|
28704
28702
|
}
|
|
28705
|
-
let dbTable = await
|
|
28703
|
+
let dbTable = await db2.get(tableId);
|
|
28706
28704
|
let combinedRow = (0, import_fp3.cloneDeep)(oldRow);
|
|
28707
28705
|
for (let key of Object.keys(inputs)) {
|
|
28708
28706
|
if (!dbTable.schema[key])
|
|
@@ -28736,13 +28734,13 @@ async function patch(ctx) {
|
|
|
28736
28734
|
});
|
|
28737
28735
|
}
|
|
28738
28736
|
async function save8(ctx) {
|
|
28739
|
-
const
|
|
28737
|
+
const db2 = context_exports.getAppDB();
|
|
28740
28738
|
let inputs = ctx.request.body;
|
|
28741
28739
|
inputs.tableId = ctx.params.tableId;
|
|
28742
28740
|
if (!inputs._rev && !inputs._id) {
|
|
28743
28741
|
inputs._id = generateRowID2(inputs.tableId);
|
|
28744
28742
|
}
|
|
28745
|
-
const dbTable = await
|
|
28743
|
+
const dbTable = await db2.get(inputs.tableId);
|
|
28746
28744
|
const tableClone = (0, import_fp3.cloneDeep)(dbTable);
|
|
28747
28745
|
let { table, row } = inputProcessing(ctx.user, tableClone, inputs);
|
|
28748
28746
|
const validateResult = await validate3({
|
|
@@ -28769,49 +28767,49 @@ async function fetchView(ctx) {
|
|
|
28769
28767
|
ctx.params.tableId = viewName;
|
|
28770
28768
|
return fetch18(ctx);
|
|
28771
28769
|
}
|
|
28772
|
-
const
|
|
28773
|
-
const { calculation, group, field } = ctx.query;
|
|
28774
|
-
const viewInfo = await getView(
|
|
28775
|
-
let
|
|
28770
|
+
const db2 = context_exports.getAppDB();
|
|
28771
|
+
const { calculation: calculation2, group: group2, field } = ctx.query;
|
|
28772
|
+
const viewInfo = await getView(db2, viewName);
|
|
28773
|
+
let response2;
|
|
28776
28774
|
if (environment_default.SELF_HOSTED) {
|
|
28777
|
-
|
|
28778
|
-
include_docs: !
|
|
28779
|
-
group: !!
|
|
28775
|
+
response2 = await db2.query(`database/${viewName}`, {
|
|
28776
|
+
include_docs: !calculation2,
|
|
28777
|
+
group: !!group2
|
|
28780
28778
|
});
|
|
28781
28779
|
} else {
|
|
28782
28780
|
const tableId = viewInfo.meta.tableId;
|
|
28783
|
-
const
|
|
28784
|
-
|
|
28781
|
+
const data2 = await getRawTableData(ctx, db2, tableId);
|
|
28782
|
+
response2 = await runView(
|
|
28785
28783
|
viewInfo,
|
|
28786
|
-
|
|
28787
|
-
!!
|
|
28788
|
-
|
|
28784
|
+
calculation2,
|
|
28785
|
+
!!group2,
|
|
28786
|
+
data2
|
|
28789
28787
|
);
|
|
28790
28788
|
}
|
|
28791
28789
|
let rows2;
|
|
28792
|
-
if (!
|
|
28793
|
-
|
|
28790
|
+
if (!calculation2) {
|
|
28791
|
+
response2.rows = response2.rows.map((row) => row.doc);
|
|
28794
28792
|
let table;
|
|
28795
28793
|
try {
|
|
28796
|
-
table = await
|
|
28794
|
+
table = await db2.get(viewInfo.meta.tableId);
|
|
28797
28795
|
} catch (err) {
|
|
28798
28796
|
table = {
|
|
28799
28797
|
schema: {}
|
|
28800
28798
|
};
|
|
28801
28799
|
}
|
|
28802
|
-
rows2 = await outputProcessing(table,
|
|
28800
|
+
rows2 = await outputProcessing(table, response2.rows);
|
|
28803
28801
|
}
|
|
28804
|
-
if (
|
|
28805
|
-
|
|
28802
|
+
if (calculation2 === CALCULATION_TYPES.STATS) {
|
|
28803
|
+
response2.rows = response2.rows.map((row) => ({
|
|
28806
28804
|
group: row.key,
|
|
28807
28805
|
field,
|
|
28808
28806
|
...row.value,
|
|
28809
28807
|
avg: row.value.sum / row.value.count
|
|
28810
28808
|
}));
|
|
28811
|
-
rows2 =
|
|
28809
|
+
rows2 = response2.rows;
|
|
28812
28810
|
}
|
|
28813
|
-
if (
|
|
28814
|
-
rows2 =
|
|
28811
|
+
if (calculation2 === CALCULATION_TYPES.COUNT || calculation2 === CALCULATION_TYPES.SUM) {
|
|
28812
|
+
rows2 = response2.rows.map((row) => ({
|
|
28815
28813
|
group: row.key,
|
|
28816
28814
|
field,
|
|
28817
28815
|
value: row.value
|
|
@@ -28820,28 +28818,28 @@ async function fetchView(ctx) {
|
|
|
28820
28818
|
return rows2;
|
|
28821
28819
|
}
|
|
28822
28820
|
async function fetch18(ctx) {
|
|
28823
|
-
const
|
|
28821
|
+
const db2 = context_exports.getAppDB();
|
|
28824
28822
|
const tableId = ctx.params.tableId;
|
|
28825
|
-
let table = await
|
|
28826
|
-
let rows2 = await getRawTableData(ctx,
|
|
28823
|
+
let table = await db2.get(tableId);
|
|
28824
|
+
let rows2 = await getRawTableData(ctx, db2, tableId);
|
|
28827
28825
|
return outputProcessing(table, rows2);
|
|
28828
28826
|
}
|
|
28829
28827
|
async function find5(ctx) {
|
|
28830
|
-
const
|
|
28831
|
-
const table = await
|
|
28828
|
+
const db2 = db_exports.getDB(ctx.appId);
|
|
28829
|
+
const table = await db2.get(ctx.params.tableId);
|
|
28832
28830
|
let row = await findRow(ctx, ctx.params.tableId, ctx.params.rowId);
|
|
28833
28831
|
row = await outputProcessing(table, row);
|
|
28834
28832
|
return row;
|
|
28835
28833
|
}
|
|
28836
28834
|
async function destroy7(ctx) {
|
|
28837
|
-
const
|
|
28835
|
+
const db2 = context_exports.getAppDB();
|
|
28838
28836
|
const { _id } = ctx.request.body;
|
|
28839
|
-
let row = await
|
|
28837
|
+
let row = await db2.get(_id);
|
|
28840
28838
|
let _rev = ctx.request.body._rev || row._rev;
|
|
28841
28839
|
if (row.tableId !== ctx.params.tableId) {
|
|
28842
28840
|
throw "Supplied tableId doesn't match the row's tableId";
|
|
28843
28841
|
}
|
|
28844
|
-
const table = await
|
|
28842
|
+
const table = await db2.get(row.tableId);
|
|
28845
28843
|
row = await outputProcessing(table, row, { squash: false });
|
|
28846
28844
|
await updateLinks({
|
|
28847
28845
|
eventType: EventType.ROW_DELETE,
|
|
@@ -28850,22 +28848,22 @@ async function destroy7(ctx) {
|
|
|
28850
28848
|
});
|
|
28851
28849
|
await cleanupAttachments(table, { row });
|
|
28852
28850
|
await updateRelatedFormula(table, row);
|
|
28853
|
-
let
|
|
28851
|
+
let response2;
|
|
28854
28852
|
if (ctx.params.tableId === InternalTables.USER_METADATA) {
|
|
28855
28853
|
ctx.params = {
|
|
28856
28854
|
id: _id
|
|
28857
28855
|
};
|
|
28858
28856
|
await destroyMetadata(ctx);
|
|
28859
|
-
|
|
28857
|
+
response2 = ctx.body;
|
|
28860
28858
|
} else {
|
|
28861
|
-
|
|
28859
|
+
response2 = await db2.remove(_id, _rev);
|
|
28862
28860
|
}
|
|
28863
|
-
return { response, row };
|
|
28861
|
+
return { response: response2, row };
|
|
28864
28862
|
}
|
|
28865
28863
|
async function bulkDestroy(ctx) {
|
|
28866
|
-
const
|
|
28864
|
+
const db2 = context_exports.getAppDB();
|
|
28867
28865
|
const tableId = ctx.params.tableId;
|
|
28868
|
-
const table = await
|
|
28866
|
+
const table = await db2.get(tableId);
|
|
28869
28867
|
let { rows: rows2 } = ctx.request.body;
|
|
28870
28868
|
const processedRows = await outputProcessing(table, rows2, {
|
|
28871
28869
|
squash: false
|
|
@@ -28887,7 +28885,7 @@ async function bulkDestroy(ctx) {
|
|
|
28887
28885
|
})
|
|
28888
28886
|
);
|
|
28889
28887
|
} else {
|
|
28890
|
-
await
|
|
28888
|
+
await db2.bulkDocs(processedRows.map((row) => ({ ...row, _deleted: true })));
|
|
28891
28889
|
}
|
|
28892
28890
|
await cleanupAttachments(table, { rows: processedRows });
|
|
28893
28891
|
await updateRelatedFormula(table, processedRows);
|
|
@@ -28899,35 +28897,35 @@ async function search3(ctx) {
|
|
|
28899
28897
|
return { rows: await fetch18(ctx) };
|
|
28900
28898
|
}
|
|
28901
28899
|
const { tableId } = ctx.params;
|
|
28902
|
-
const
|
|
28900
|
+
const db2 = context_exports.getAppDB();
|
|
28903
28901
|
const { paginate, query, ...params2 } = ctx.request.body;
|
|
28904
28902
|
params2.version = ctx.version;
|
|
28905
28903
|
params2.tableId = tableId;
|
|
28906
28904
|
let table;
|
|
28907
28905
|
if (params2.sort && !params2.sortType) {
|
|
28908
|
-
table = await
|
|
28906
|
+
table = await db2.get(tableId);
|
|
28909
28907
|
const schema = table.schema;
|
|
28910
28908
|
const sortField = schema[params2.sort];
|
|
28911
28909
|
params2.sortType = sortField.type == "number" ? "number" : "string";
|
|
28912
28910
|
}
|
|
28913
|
-
let
|
|
28911
|
+
let response2;
|
|
28914
28912
|
if (paginate) {
|
|
28915
|
-
|
|
28913
|
+
response2 = await paginatedSearch2(query, params2);
|
|
28916
28914
|
} else {
|
|
28917
|
-
|
|
28915
|
+
response2 = await fullSearch2(query, params2);
|
|
28918
28916
|
}
|
|
28919
|
-
if (
|
|
28917
|
+
if (response2.rows && response2.rows.length) {
|
|
28920
28918
|
if (tableId === InternalTables.USER_METADATA) {
|
|
28921
|
-
|
|
28919
|
+
response2.rows = await getGlobalUsersFromMetadata(response2.rows);
|
|
28922
28920
|
}
|
|
28923
|
-
table = table || await
|
|
28924
|
-
|
|
28921
|
+
table = table || await db2.get(tableId);
|
|
28922
|
+
response2.rows = await outputProcessing(table, response2.rows);
|
|
28925
28923
|
}
|
|
28926
|
-
return
|
|
28924
|
+
return response2;
|
|
28927
28925
|
}
|
|
28928
28926
|
async function exportRows(ctx) {
|
|
28929
|
-
const
|
|
28930
|
-
const table = await
|
|
28927
|
+
const db2 = context_exports.getAppDB();
|
|
28928
|
+
const table = await db2.get(ctx.params.tableId);
|
|
28931
28929
|
const rowIds = ctx.request.body.rows;
|
|
28932
28930
|
let format = ctx.query.format;
|
|
28933
28931
|
if (typeof format !== "string") {
|
|
@@ -28936,11 +28934,11 @@ async function exportRows(ctx) {
|
|
|
28936
28934
|
const { columns, query } = ctx.request.body;
|
|
28937
28935
|
let result;
|
|
28938
28936
|
if (rowIds) {
|
|
28939
|
-
let
|
|
28937
|
+
let response2 = (await db2.allDocs({
|
|
28940
28938
|
include_docs: true,
|
|
28941
28939
|
keys: rowIds
|
|
28942
28940
|
})).rows.map((row) => row.doc);
|
|
28943
|
-
result = await outputProcessing(table,
|
|
28941
|
+
result = await outputProcessing(table, response2);
|
|
28944
28942
|
} else if (query) {
|
|
28945
28943
|
let searchResponse = await search3(ctx);
|
|
28946
28944
|
result = searchResponse.rows;
|
|
@@ -28972,30 +28970,30 @@ async function exportRows(ctx) {
|
|
|
28972
28970
|
}
|
|
28973
28971
|
}
|
|
28974
28972
|
async function fetchEnrichedRow(ctx) {
|
|
28975
|
-
const
|
|
28973
|
+
const db2 = context_exports.getAppDB();
|
|
28976
28974
|
const tableId = ctx.params.tableId;
|
|
28977
28975
|
const rowId = ctx.params.rowId;
|
|
28978
28976
|
let [table, row] = await Promise.all([
|
|
28979
|
-
|
|
28977
|
+
db2.get(tableId),
|
|
28980
28978
|
findRow(ctx, tableId, rowId)
|
|
28981
28979
|
]);
|
|
28982
28980
|
const linkVals = await getLinkDocuments({
|
|
28983
28981
|
tableId,
|
|
28984
28982
|
rowId
|
|
28985
28983
|
});
|
|
28986
|
-
let
|
|
28984
|
+
let response2 = (await db2.allDocs({
|
|
28987
28985
|
include_docs: true,
|
|
28988
28986
|
keys: linkVals.map((linkVal) => linkVal.id)
|
|
28989
28987
|
})).rows.map((row2) => row2.doc);
|
|
28990
28988
|
let groups = {}, tables = {};
|
|
28991
|
-
for (let row2 of
|
|
28989
|
+
for (let row2 of response2) {
|
|
28992
28990
|
if (!row2.tableId) {
|
|
28993
28991
|
row2.tableId = getTableIDFromRowID(row2._id);
|
|
28994
28992
|
}
|
|
28995
28993
|
const linkedTableId = row2.tableId;
|
|
28996
28994
|
if (groups[linkedTableId] == null) {
|
|
28997
28995
|
groups[linkedTableId] = [row2];
|
|
28998
|
-
tables[linkedTableId] = await
|
|
28996
|
+
tables[linkedTableId] = await db2.get(linkedTableId);
|
|
28999
28997
|
} else {
|
|
29000
28998
|
groups[linkedTableId].push(row2);
|
|
29001
28999
|
}
|
|
@@ -29448,7 +29446,7 @@ var ExternalRequest = class {
|
|
|
29448
29446
|
if (!lookupField || !row[lookupField]) {
|
|
29449
29447
|
continue;
|
|
29450
29448
|
}
|
|
29451
|
-
const
|
|
29449
|
+
const response2 = await getDatasourceAndQuery({
|
|
29452
29450
|
endpoint: getEndpoint(tableId2, "READ" /* READ */),
|
|
29453
29451
|
filters: {
|
|
29454
29452
|
equal: {
|
|
@@ -29456,7 +29454,7 @@ var ExternalRequest = class {
|
|
|
29456
29454
|
}
|
|
29457
29455
|
}
|
|
29458
29456
|
});
|
|
29459
|
-
const rows2 = !
|
|
29457
|
+
const rows2 = !response2[0].read ? response2 : [];
|
|
29460
29458
|
const storeTo = isMany ? field.throughFrom || linkPrimaryKey : fieldName;
|
|
29461
29459
|
related[storeTo] = { rows: rows2, isMany, tableId: tableId2 };
|
|
29462
29460
|
}
|
|
@@ -29634,16 +29632,16 @@ var ExternalRequest = class {
|
|
|
29634
29632
|
table
|
|
29635
29633
|
}
|
|
29636
29634
|
};
|
|
29637
|
-
const
|
|
29635
|
+
const response2 = await getDatasourceAndQuery(json2);
|
|
29638
29636
|
if (operation !== "READ" /* READ */ && processed.manyRelationships) {
|
|
29639
29637
|
await this.handleManyRelationships(
|
|
29640
29638
|
table._id || "",
|
|
29641
|
-
|
|
29639
|
+
response2[0],
|
|
29642
29640
|
processed.manyRelationships
|
|
29643
29641
|
);
|
|
29644
29642
|
}
|
|
29645
|
-
const output = this.outputProcessing(
|
|
29646
|
-
return operation === "READ" /* READ */ && Array.isArray(
|
|
29643
|
+
const output = this.outputProcessing(response2, table, relationships);
|
|
29644
|
+
return operation === "READ" /* READ */ && Array.isArray(response2) ? output : { row: output[0], table };
|
|
29647
29645
|
}
|
|
29648
29646
|
};
|
|
29649
29647
|
|
|
@@ -29718,11 +29716,11 @@ async function fetch19(ctx) {
|
|
|
29718
29716
|
async function find6(ctx) {
|
|
29719
29717
|
const id = ctx.params.rowId;
|
|
29720
29718
|
const tableId = ctx.params.tableId;
|
|
29721
|
-
const
|
|
29719
|
+
const response2 = await handleRequest("READ" /* READ */, tableId, {
|
|
29722
29720
|
id: breakRowIdField(id),
|
|
29723
29721
|
includeSqlRelationships: 0 /* EXCLUDE */
|
|
29724
29722
|
});
|
|
29725
|
-
return
|
|
29723
|
+
return response2 ? response2[0] : response2;
|
|
29726
29724
|
}
|
|
29727
29725
|
async function destroy8(ctx) {
|
|
29728
29726
|
const tableId = ctx.params.tableId;
|
|
@@ -29860,13 +29858,13 @@ async function fetchEnrichedRow2(ctx) {
|
|
|
29860
29858
|
ctx.throw(400, "Datasource has not been configured for plus API.");
|
|
29861
29859
|
}
|
|
29862
29860
|
const tables = datasource2.entities;
|
|
29863
|
-
const
|
|
29861
|
+
const response2 = await handleRequest("READ" /* READ */, tableId, {
|
|
29864
29862
|
id,
|
|
29865
29863
|
datasource: datasource2,
|
|
29866
29864
|
includeSqlRelationships: 1 /* INCLUDE */
|
|
29867
29865
|
});
|
|
29868
29866
|
const table = tables[tableName];
|
|
29869
|
-
const row =
|
|
29867
|
+
const row = response2[0];
|
|
29870
29868
|
for (let [fieldName, field] of Object.entries(table.schema)) {
|
|
29871
29869
|
if (field.type !== "link" /* LINK */ || !row[fieldName] || row[fieldName].length === 0) {
|
|
29872
29870
|
continue;
|
|
@@ -29956,7 +29954,7 @@ async function destroy9(ctx) {
|
|
|
29956
29954
|
const appId = ctx.appId;
|
|
29957
29955
|
const inputs = ctx.request.body;
|
|
29958
29956
|
const tableId = getTableId(ctx);
|
|
29959
|
-
let
|
|
29957
|
+
let response2, row;
|
|
29960
29958
|
if (inputs.rows) {
|
|
29961
29959
|
let { rows: rows2 } = await quotas_exports4.addQuery(
|
|
29962
29960
|
() => pickApi(tableId).bulkDestroy(ctx),
|
|
@@ -29965,7 +29963,7 @@ async function destroy9(ctx) {
|
|
|
29965
29963
|
}
|
|
29966
29964
|
);
|
|
29967
29965
|
await quotas_exports4.removeRows(rows2.length);
|
|
29968
|
-
|
|
29966
|
+
response2 = rows2;
|
|
29969
29967
|
for (let row2 of rows2) {
|
|
29970
29968
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row2);
|
|
29971
29969
|
}
|
|
@@ -29974,13 +29972,13 @@ async function destroy9(ctx) {
|
|
|
29974
29972
|
datasourceId: tableId
|
|
29975
29973
|
});
|
|
29976
29974
|
await quotas_exports4.removeRow();
|
|
29977
|
-
|
|
29975
|
+
response2 = resp.response;
|
|
29978
29976
|
row = resp.row;
|
|
29979
29977
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row);
|
|
29980
29978
|
}
|
|
29981
29979
|
ctx.status = 200;
|
|
29982
29980
|
ctx.row = row || {};
|
|
29983
|
-
ctx.body =
|
|
29981
|
+
ctx.body = response2;
|
|
29984
29982
|
}
|
|
29985
29983
|
async function search5(ctx) {
|
|
29986
29984
|
const tableId = getTableId(ctx);
|
|
@@ -30520,8 +30518,8 @@ function getAuthConfig(ctx) {
|
|
|
30520
30518
|
return authConfigCtx;
|
|
30521
30519
|
}
|
|
30522
30520
|
async function execute2(ctx, opts = { rowsOnly: false, isAutomation: false }) {
|
|
30523
|
-
const
|
|
30524
|
-
const query = await
|
|
30521
|
+
const db2 = context_exports.getAppDB();
|
|
30522
|
+
const query = await db2.get(ctx.params.queryId);
|
|
30525
30523
|
const { datasource: datasource2, envVars } = await sdk_default.datasources.getWithEnvVars(
|
|
30526
30524
|
query.datasourceId
|
|
30527
30525
|
);
|
|
@@ -30643,9 +30641,9 @@ async function run8({ inputs, appId, emitter: emitter2 }) {
|
|
|
30643
30641
|
});
|
|
30644
30642
|
try {
|
|
30645
30643
|
await executeV2(ctx, { isAutomation: true });
|
|
30646
|
-
const { data, ...rest2 } = ctx.body;
|
|
30644
|
+
const { data: data2, ...rest2 } = ctx.body;
|
|
30647
30645
|
return {
|
|
30648
|
-
response:
|
|
30646
|
+
response: data2,
|
|
30649
30647
|
info: rest2,
|
|
30650
30648
|
success: true
|
|
30651
30649
|
};
|
|
@@ -30760,8 +30758,8 @@ async function run9({ inputs }) {
|
|
|
30760
30758
|
if (request2.body) {
|
|
30761
30759
|
JSON.parse(request2.body);
|
|
30762
30760
|
}
|
|
30763
|
-
const
|
|
30764
|
-
const { status: status2, message } = await getFetchResponse(
|
|
30761
|
+
const response2 = await (0, import_node_fetch12.default)(url, request2);
|
|
30762
|
+
const { status: status2, message } = await getFetchResponse(response2);
|
|
30765
30763
|
return {
|
|
30766
30764
|
httpStatus: status2,
|
|
30767
30765
|
response: message,
|
|
@@ -30892,9 +30890,9 @@ async function run11({ inputs }) {
|
|
|
30892
30890
|
success: false
|
|
30893
30891
|
};
|
|
30894
30892
|
}
|
|
30895
|
-
let
|
|
30893
|
+
let response2;
|
|
30896
30894
|
try {
|
|
30897
|
-
|
|
30895
|
+
response2 = await (0, import_node_fetch13.default)(url, {
|
|
30898
30896
|
method: "post",
|
|
30899
30897
|
body: JSON.stringify({
|
|
30900
30898
|
username,
|
|
@@ -30912,7 +30910,7 @@ async function run11({ inputs }) {
|
|
|
30912
30910
|
success: false
|
|
30913
30911
|
};
|
|
30914
30912
|
}
|
|
30915
|
-
const { status: status2, message } = await getFetchResponse(
|
|
30913
|
+
const { status: status2, message } = await getFetchResponse(response2);
|
|
30916
30914
|
return {
|
|
30917
30915
|
httpStatus: status2,
|
|
30918
30916
|
success: status2 === 200 || status2 === 204,
|
|
@@ -30974,9 +30972,9 @@ async function run12({ inputs }) {
|
|
|
30974
30972
|
success: false
|
|
30975
30973
|
};
|
|
30976
30974
|
}
|
|
30977
|
-
let
|
|
30975
|
+
let response2;
|
|
30978
30976
|
try {
|
|
30979
|
-
|
|
30977
|
+
response2 = await (0, import_node_fetch14.default)(url, {
|
|
30980
30978
|
method: "post",
|
|
30981
30979
|
body: JSON.stringify({
|
|
30982
30980
|
text
|
|
@@ -30992,7 +30990,7 @@ async function run12({ inputs }) {
|
|
|
30992
30990
|
success: false
|
|
30993
30991
|
};
|
|
30994
30992
|
}
|
|
30995
|
-
const { status: status2, message } = await getFetchResponse(
|
|
30993
|
+
const { status: status2, message } = await getFetchResponse(response2);
|
|
30996
30994
|
return {
|
|
30997
30995
|
httpStatus: status2,
|
|
30998
30996
|
response: message,
|
|
@@ -31080,9 +31078,9 @@ async function run13({ inputs }) {
|
|
|
31080
31078
|
success: false
|
|
31081
31079
|
};
|
|
31082
31080
|
}
|
|
31083
|
-
let
|
|
31081
|
+
let response2;
|
|
31084
31082
|
try {
|
|
31085
|
-
|
|
31083
|
+
response2 = await (0, import_node_fetch15.default)(url, {
|
|
31086
31084
|
method: "post",
|
|
31087
31085
|
body: JSON.stringify({
|
|
31088
31086
|
platform: "budibase",
|
|
@@ -31104,7 +31102,7 @@ async function run13({ inputs }) {
|
|
|
31104
31102
|
success: false
|
|
31105
31103
|
};
|
|
31106
31104
|
}
|
|
31107
|
-
const { status: status2, message } = await getFetchResponse(
|
|
31105
|
+
const { status: status2, message } = await getFetchResponse(response2);
|
|
31108
31106
|
return {
|
|
31109
31107
|
success: status2 === 200,
|
|
31110
31108
|
httpStatus: status2,
|
|
@@ -31198,9 +31196,9 @@ async function run14({ inputs }) {
|
|
|
31198
31196
|
success: false
|
|
31199
31197
|
};
|
|
31200
31198
|
}
|
|
31201
|
-
let
|
|
31199
|
+
let response2;
|
|
31202
31200
|
try {
|
|
31203
|
-
|
|
31201
|
+
response2 = await (0, import_node_fetch16.default)(url, {
|
|
31204
31202
|
method: "post",
|
|
31205
31203
|
body: JSON.stringify({
|
|
31206
31204
|
value1,
|
|
@@ -31221,7 +31219,7 @@ async function run14({ inputs }) {
|
|
|
31221
31219
|
success: false
|
|
31222
31220
|
};
|
|
31223
31221
|
}
|
|
31224
|
-
const { status: status2, message } = await getFetchResponse(
|
|
31222
|
+
const { status: status2, message } = await getFetchResponse(response2);
|
|
31225
31223
|
return {
|
|
31226
31224
|
httpStatus: status2,
|
|
31227
31225
|
success: status2 === 200,
|
|
@@ -31868,10 +31866,10 @@ var Orchestrator = class {
|
|
|
31868
31866
|
}
|
|
31869
31867
|
async getMetadata() {
|
|
31870
31868
|
const metadataId = generateAutomationMetadataID(this._automation._id);
|
|
31871
|
-
const
|
|
31869
|
+
const db2 = context_exports.getAppDB();
|
|
31872
31870
|
let metadata;
|
|
31873
31871
|
try {
|
|
31874
|
-
metadata = await
|
|
31872
|
+
metadata = await db2.get(metadataId);
|
|
31875
31873
|
} catch (err) {
|
|
31876
31874
|
metadata = {
|
|
31877
31875
|
_id: metadataId,
|
|
@@ -31926,13 +31924,13 @@ var Orchestrator = class {
|
|
|
31926
31924
|
} else {
|
|
31927
31925
|
metadata.errorCount = 0;
|
|
31928
31926
|
}
|
|
31929
|
-
const
|
|
31927
|
+
const db2 = context_exports.getAppDB();
|
|
31930
31928
|
try {
|
|
31931
|
-
await
|
|
31929
|
+
await db2.put(metadata);
|
|
31932
31930
|
} catch (err) {
|
|
31933
31931
|
logging_exports.logAlertWithInfo(
|
|
31934
31932
|
"Failed to write automation metadata",
|
|
31935
|
-
|
|
31933
|
+
db2.name,
|
|
31936
31934
|
automation._id,
|
|
31937
31935
|
err
|
|
31938
31936
|
);
|
|
@@ -32184,8 +32182,8 @@ function execute3(job, callback) {
|
|
|
32184
32182
|
await context_exports.doInEnvironmentContext(envVars, async () => {
|
|
32185
32183
|
const automationOrchestrator = new Orchestrator(job);
|
|
32186
32184
|
try {
|
|
32187
|
-
const
|
|
32188
|
-
callback(null,
|
|
32185
|
+
const response2 = await automationOrchestrator.execute();
|
|
32186
|
+
callback(null, response2);
|
|
32189
32187
|
} catch (err) {
|
|
32190
32188
|
callback(err);
|
|
32191
32189
|
}
|