@budibase/server 2.7.15 → 2.7.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/builder/assets/{index.717d69a6.js → index.532bda47.js} +288 -288
- package/builder/index.html +1 -1
- package/dist/automation.js +481 -462
- package/dist/automation.js.map +3 -3
- package/dist/index.js +693 -674
- package/dist/index.js.map +3 -3
- package/dist/query.js +709 -705
- package/dist/query.js.map +3 -3
- package/package.json +8 -8
- package/src/api/controllers/row/ExternalRequest.ts +5 -1
- package/src/integrations/mysql.ts +7 -2
- package/src/integrations/tests/mysql.spec.ts +19 -1
- package/src/integrations/utils.ts +24 -0
package/dist/query.js
CHANGED
|
@@ -11,8 +11,8 @@ var __commonJS = (cb, mod) => function __require() {
|
|
|
11
11
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
12
12
|
};
|
|
13
13
|
var __export = (target, all) => {
|
|
14
|
-
for (var
|
|
15
|
-
__defProp(target,
|
|
14
|
+
for (var name2 in all)
|
|
15
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
16
16
|
};
|
|
17
17
|
var __copyProps = (to, from, except, desc) => {
|
|
18
18
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
@@ -563,13 +563,13 @@ var init_plan = __esm({
|
|
|
563
563
|
var isStaticQuota, isMonthlyQuota, isConstantQuota;
|
|
564
564
|
var init_quota = __esm({
|
|
565
565
|
"../types/src/sdk/licensing/quota.ts"() {
|
|
566
|
-
isStaticQuota = (quotaType, usageType,
|
|
566
|
+
isStaticQuota = (quotaType, usageType, name2) => {
|
|
567
567
|
return quotaType === "usage" /* USAGE */ && usageType === "static" /* STATIC */;
|
|
568
568
|
};
|
|
569
|
-
isMonthlyQuota = (quotaType, usageType,
|
|
569
|
+
isMonthlyQuota = (quotaType, usageType, name2) => {
|
|
570
570
|
return quotaType === "usage" /* USAGE */ && usageType === "monthly" /* MONTHLY */;
|
|
571
571
|
};
|
|
572
|
-
isConstantQuota = (quotaType,
|
|
572
|
+
isConstantQuota = (quotaType, name2) => {
|
|
573
573
|
return quotaType === "constant" /* CONSTANT */;
|
|
574
574
|
};
|
|
575
575
|
}
|
|
@@ -679,8 +679,8 @@ var init_locks = __esm({
|
|
|
679
679
|
var isDocument;
|
|
680
680
|
var init_db = __esm({
|
|
681
681
|
"../types/src/sdk/db.ts"() {
|
|
682
|
-
isDocument = (
|
|
683
|
-
return typeof
|
|
682
|
+
isDocument = (doc2) => {
|
|
683
|
+
return typeof doc2 === "object" && doc2._id && doc2._rev;
|
|
684
684
|
};
|
|
685
685
|
}
|
|
686
686
|
});
|
|
@@ -1954,27 +1954,27 @@ function init(opts) {
|
|
|
1954
1954
|
}
|
|
1955
1955
|
function getPouchDB(dbName, opts) {
|
|
1956
1956
|
checkInitialised();
|
|
1957
|
-
const
|
|
1958
|
-
const dbPut =
|
|
1959
|
-
|
|
1960
|
-
if (!
|
|
1961
|
-
|
|
1962
|
-
}
|
|
1963
|
-
|
|
1964
|
-
return dbPut(
|
|
1957
|
+
const db2 = new Pouch(dbName, opts);
|
|
1958
|
+
const dbPut = db2.put;
|
|
1959
|
+
db2.put = async (doc2, options2 = {}) => {
|
|
1960
|
+
if (!doc2.createdAt) {
|
|
1961
|
+
doc2.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1962
|
+
}
|
|
1963
|
+
doc2.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1964
|
+
return dbPut(doc2, options2);
|
|
1965
1965
|
};
|
|
1966
|
-
|
|
1967
|
-
const info = await
|
|
1966
|
+
db2.exists = async () => {
|
|
1967
|
+
const info = await db2.info();
|
|
1968
1968
|
return !info.error;
|
|
1969
1969
|
};
|
|
1970
|
-
return
|
|
1970
|
+
return db2;
|
|
1971
1971
|
}
|
|
1972
|
-
async function closePouchDB(
|
|
1973
|
-
if (!
|
|
1972
|
+
async function closePouchDB(db2) {
|
|
1973
|
+
if (!db2 || environment_default2.isTest()) {
|
|
1974
1974
|
return;
|
|
1975
1975
|
}
|
|
1976
1976
|
try {
|
|
1977
|
-
return await
|
|
1977
|
+
return await db2.close();
|
|
1978
1978
|
} catch (err) {
|
|
1979
1979
|
}
|
|
1980
1980
|
}
|
|
@@ -2125,14 +2125,14 @@ var init_DatabaseImpl = __esm({
|
|
|
2125
2125
|
}
|
|
2126
2126
|
}
|
|
2127
2127
|
async get(id) {
|
|
2128
|
-
const
|
|
2128
|
+
const db2 = await this.checkSetup();
|
|
2129
2129
|
if (!id) {
|
|
2130
2130
|
throw new Error("Unable to get doc without a valid _id.");
|
|
2131
2131
|
}
|
|
2132
|
-
return this.updateOutput(() =>
|
|
2132
|
+
return this.updateOutput(() => db2.get(id));
|
|
2133
2133
|
}
|
|
2134
|
-
async remove(idOrDoc,
|
|
2135
|
-
const
|
|
2134
|
+
async remove(idOrDoc, rev2) {
|
|
2135
|
+
const db2 = await this.checkSetup();
|
|
2136
2136
|
let _id;
|
|
2137
2137
|
let _rev;
|
|
2138
2138
|
if (isDocument(idOrDoc)) {
|
|
@@ -2140,12 +2140,12 @@ var init_DatabaseImpl = __esm({
|
|
|
2140
2140
|
_rev = idOrDoc._rev;
|
|
2141
2141
|
} else {
|
|
2142
2142
|
_id = idOrDoc;
|
|
2143
|
-
_rev =
|
|
2143
|
+
_rev = rev2;
|
|
2144
2144
|
}
|
|
2145
2145
|
if (!_id || !_rev) {
|
|
2146
2146
|
throw new Error("Unable to remove doc without a valid _id and _rev.");
|
|
2147
2147
|
}
|
|
2148
|
-
return this.updateOutput(() =>
|
|
2148
|
+
return this.updateOutput(() => db2.destroy(_id, _rev));
|
|
2149
2149
|
}
|
|
2150
2150
|
async post(document, opts) {
|
|
2151
2151
|
if (!document._id) {
|
|
@@ -2157,7 +2157,7 @@ var init_DatabaseImpl = __esm({
|
|
|
2157
2157
|
if (!document._id) {
|
|
2158
2158
|
throw new Error("Cannot store document without _id field.");
|
|
2159
2159
|
}
|
|
2160
|
-
const
|
|
2160
|
+
const db2 = await this.checkSetup();
|
|
2161
2161
|
if (!document.createdAt) {
|
|
2162
2162
|
document.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2163
2163
|
}
|
|
@@ -2174,20 +2174,20 @@ var init_DatabaseImpl = __esm({
|
|
|
2174
2174
|
}
|
|
2175
2175
|
}
|
|
2176
2176
|
}
|
|
2177
|
-
return this.updateOutput(() =>
|
|
2177
|
+
return this.updateOutput(() => db2.insert(document));
|
|
2178
2178
|
}
|
|
2179
2179
|
async bulkDocs(documents) {
|
|
2180
|
-
const
|
|
2181
|
-
return this.updateOutput(() =>
|
|
2180
|
+
const db2 = await this.checkSetup();
|
|
2181
|
+
return this.updateOutput(() => db2.bulk({ docs: documents }));
|
|
2182
2182
|
}
|
|
2183
2183
|
async allDocs(params2) {
|
|
2184
|
-
const
|
|
2185
|
-
return this.updateOutput(() =>
|
|
2184
|
+
const db2 = await this.checkSetup();
|
|
2185
|
+
return this.updateOutput(() => db2.list(params2));
|
|
2186
2186
|
}
|
|
2187
2187
|
async query(viewName, params2) {
|
|
2188
|
-
const
|
|
2188
|
+
const db2 = await this.checkSetup();
|
|
2189
2189
|
const [database, view] = viewName.split("/");
|
|
2190
|
-
return this.updateOutput(() =>
|
|
2190
|
+
return this.updateOutput(() => db2.view(database, view, params2));
|
|
2191
2191
|
}
|
|
2192
2192
|
async destroy() {
|
|
2193
2193
|
try {
|
|
@@ -2201,8 +2201,8 @@ var init_DatabaseImpl = __esm({
|
|
|
2201
2201
|
}
|
|
2202
2202
|
}
|
|
2203
2203
|
async compact() {
|
|
2204
|
-
const
|
|
2205
|
-
return this.updateOutput(() =>
|
|
2204
|
+
const db2 = await this.checkSetup();
|
|
2205
|
+
return this.updateOutput(() => db2.compact());
|
|
2206
2206
|
}
|
|
2207
2207
|
// All below functions are in-frequently called, just utilise PouchDB
|
|
2208
2208
|
// for them as it implements them better than we can
|
|
@@ -2245,8 +2245,8 @@ function getDB(dbName, opts) {
|
|
|
2245
2245
|
return new DatabaseImpl(dbName, opts);
|
|
2246
2246
|
}
|
|
2247
2247
|
async function doWithDB(dbName, cb, opts = {}) {
|
|
2248
|
-
const
|
|
2249
|
-
return await cb(
|
|
2248
|
+
const db2 = getDB(dbName, opts);
|
|
2249
|
+
return await cb(db2);
|
|
2250
2250
|
}
|
|
2251
2251
|
function allDbs() {
|
|
2252
2252
|
if (!environment_default2.isTest()) {
|
|
@@ -2594,11 +2594,11 @@ function getRedisOptions() {
|
|
|
2594
2594
|
}
|
|
2595
2595
|
return { opts, host, port: parseInt(port), redisProtocolUrl };
|
|
2596
2596
|
}
|
|
2597
|
-
function addDbPrefix(
|
|
2598
|
-
if (key.includes(
|
|
2597
|
+
function addDbPrefix(db2, key) {
|
|
2598
|
+
if (key.includes(db2)) {
|
|
2599
2599
|
return key;
|
|
2600
2600
|
}
|
|
2601
|
-
return `${
|
|
2601
|
+
return `${db2}${SEPARATOR2}${key}`;
|
|
2602
2602
|
}
|
|
2603
2603
|
function removeDbPrefix(key) {
|
|
2604
2604
|
let parts = key.split(SEPARATOR2);
|
|
@@ -2818,8 +2818,8 @@ var init_redis = __esm({
|
|
|
2818
2818
|
CONNECTED = true;
|
|
2819
2819
|
}
|
|
2820
2820
|
RedisWrapper = class {
|
|
2821
|
-
constructor(
|
|
2822
|
-
this._db =
|
|
2821
|
+
constructor(db2, selectDb = null) {
|
|
2822
|
+
this._db = db2;
|
|
2823
2823
|
this._select = selectDb || DEFAULT_SELECT_DB;
|
|
2824
2824
|
}
|
|
2825
2825
|
getClient() {
|
|
@@ -2839,8 +2839,8 @@ var init_redis = __esm({
|
|
|
2839
2839
|
this.getClient().disconnect();
|
|
2840
2840
|
}
|
|
2841
2841
|
async scan(key = "") {
|
|
2842
|
-
const
|
|
2843
|
-
key = `${
|
|
2842
|
+
const db2 = this._db;
|
|
2843
|
+
key = `${db2}${SEPARATOR2}${key}`;
|
|
2844
2844
|
let stream3;
|
|
2845
2845
|
if (CLUSTERED) {
|
|
2846
2846
|
let node = this.getClient().nodes("master");
|
|
@@ -2851,16 +2851,16 @@ var init_redis = __esm({
|
|
|
2851
2851
|
return promisifyStream(stream3, this.getClient());
|
|
2852
2852
|
}
|
|
2853
2853
|
async keys(pattern) {
|
|
2854
|
-
const
|
|
2855
|
-
return this.getClient().keys(addDbPrefix(
|
|
2854
|
+
const db2 = this._db;
|
|
2855
|
+
return this.getClient().keys(addDbPrefix(db2, pattern));
|
|
2856
2856
|
}
|
|
2857
2857
|
async exists(key) {
|
|
2858
|
-
const
|
|
2859
|
-
return await this.getClient().exists(addDbPrefix(
|
|
2858
|
+
const db2 = this._db;
|
|
2859
|
+
return await this.getClient().exists(addDbPrefix(db2, key));
|
|
2860
2860
|
}
|
|
2861
2861
|
async get(key) {
|
|
2862
|
-
const
|
|
2863
|
-
let response = await this.getClient().get(addDbPrefix(
|
|
2862
|
+
const db2 = this._db;
|
|
2863
|
+
let response = await this.getClient().get(addDbPrefix(db2, key));
|
|
2864
2864
|
if (response != null && response.key) {
|
|
2865
2865
|
response.key = key;
|
|
2866
2866
|
}
|
|
@@ -2871,11 +2871,11 @@ var init_redis = __esm({
|
|
|
2871
2871
|
}
|
|
2872
2872
|
}
|
|
2873
2873
|
async bulkGet(keys2) {
|
|
2874
|
-
const
|
|
2874
|
+
const db2 = this._db;
|
|
2875
2875
|
if (keys2.length === 0) {
|
|
2876
2876
|
return {};
|
|
2877
2877
|
}
|
|
2878
|
-
const prefixedKeys = keys2.map((key) => addDbPrefix(
|
|
2878
|
+
const prefixedKeys = keys2.map((key) => addDbPrefix(db2, key));
|
|
2879
2879
|
let response = await this.getClient().mget(prefixedKeys);
|
|
2880
2880
|
if (Array.isArray(response)) {
|
|
2881
2881
|
let final = {};
|
|
@@ -2898,29 +2898,29 @@ var init_redis = __esm({
|
|
|
2898
2898
|
}
|
|
2899
2899
|
}
|
|
2900
2900
|
async store(key, value, expirySeconds = null) {
|
|
2901
|
-
const
|
|
2901
|
+
const db2 = this._db;
|
|
2902
2902
|
if (typeof value === "object") {
|
|
2903
2903
|
value = JSON.stringify(value);
|
|
2904
2904
|
}
|
|
2905
|
-
const prefixedKey = addDbPrefix(
|
|
2905
|
+
const prefixedKey = addDbPrefix(db2, key);
|
|
2906
2906
|
await this.getClient().set(prefixedKey, value);
|
|
2907
2907
|
if (expirySeconds) {
|
|
2908
2908
|
await this.getClient().expire(prefixedKey, expirySeconds);
|
|
2909
2909
|
}
|
|
2910
2910
|
}
|
|
2911
2911
|
async getTTL(key) {
|
|
2912
|
-
const
|
|
2913
|
-
const prefixedKey = addDbPrefix(
|
|
2912
|
+
const db2 = this._db;
|
|
2913
|
+
const prefixedKey = addDbPrefix(db2, key);
|
|
2914
2914
|
return this.getClient().ttl(prefixedKey);
|
|
2915
2915
|
}
|
|
2916
2916
|
async setExpiry(key, expirySeconds) {
|
|
2917
|
-
const
|
|
2918
|
-
const prefixedKey = addDbPrefix(
|
|
2917
|
+
const db2 = this._db;
|
|
2918
|
+
const prefixedKey = addDbPrefix(db2, key);
|
|
2919
2919
|
await this.getClient().expire(prefixedKey, expirySeconds);
|
|
2920
2920
|
}
|
|
2921
2921
|
async delete(key) {
|
|
2922
|
-
const
|
|
2923
|
-
await this.getClient().del(addDbPrefix(
|
|
2922
|
+
const db2 = this._db;
|
|
2923
|
+
await this.getClient().del(addDbPrefix(db2, key));
|
|
2924
2924
|
}
|
|
2925
2925
|
async clear() {
|
|
2926
2926
|
let items = await this.scan();
|
|
@@ -3296,8 +3296,8 @@ function logAlert(message, e) {
|
|
|
3296
3296
|
}
|
|
3297
3297
|
console.error(`bb-alert: ${message}`, e);
|
|
3298
3298
|
}
|
|
3299
|
-
function logAlertWithInfo(message,
|
|
3300
|
-
message = `${message} - db: ${
|
|
3299
|
+
function logAlertWithInfo(message, db2, id, error) {
|
|
3300
|
+
message = `${message} - db: ${db2} - doc: ${id} - error: `;
|
|
3301
3301
|
logAlert(message, error);
|
|
3302
3302
|
}
|
|
3303
3303
|
function logWarn(message) {
|
|
@@ -3334,8 +3334,8 @@ var init_logging = __esm({
|
|
|
3334
3334
|
var require_Helper = __commonJS({
|
|
3335
3335
|
"../string-templates/src/helpers/Helper.js"(exports2, module2) {
|
|
3336
3336
|
var Helper = class {
|
|
3337
|
-
constructor(
|
|
3338
|
-
this.name =
|
|
3337
|
+
constructor(name2, fn, useValueFallback = true) {
|
|
3338
|
+
this.name = name2;
|
|
3339
3339
|
this.fn = fn;
|
|
3340
3340
|
this.useValueFallback = useValueFallback;
|
|
3341
3341
|
}
|
|
@@ -3504,18 +3504,18 @@ var require_external = __commonJS({
|
|
|
3504
3504
|
exports2.externalCollections = EXTERNAL_FUNCTION_COLLECTIONS;
|
|
3505
3505
|
exports2.addedHelpers = ADDED_HELPERS;
|
|
3506
3506
|
exports2.registerAll = (handlebars) => {
|
|
3507
|
-
for (let [
|
|
3508
|
-
handlebars.registerHelper(
|
|
3507
|
+
for (let [name2, helper] of Object.entries(ADDED_HELPERS)) {
|
|
3508
|
+
handlebars.registerHelper(name2, helper);
|
|
3509
3509
|
}
|
|
3510
3510
|
let externalNames = [];
|
|
3511
3511
|
for (let collection of EXTERNAL_FUNCTION_COLLECTIONS) {
|
|
3512
3512
|
let hbsHelperInfo = helpers[collection]();
|
|
3513
3513
|
for (let entry of Object.entries(hbsHelperInfo)) {
|
|
3514
|
-
const
|
|
3515
|
-
if (HelperFunctionBuiltin.indexOf(
|
|
3514
|
+
const name2 = entry[0];
|
|
3515
|
+
if (HelperFunctionBuiltin.indexOf(name2) !== -1 || externalNames.indexOf(name2) !== -1) {
|
|
3516
3516
|
continue;
|
|
3517
3517
|
}
|
|
3518
|
-
externalNames.push(
|
|
3518
|
+
externalNames.push(name2);
|
|
3519
3519
|
}
|
|
3520
3520
|
helpers[collection]({
|
|
3521
3521
|
handlebars
|
|
@@ -3524,11 +3524,11 @@ var require_external = __commonJS({
|
|
|
3524
3524
|
exports2.externalHelperNames = externalNames.concat(Object.keys(ADDED_HELPERS));
|
|
3525
3525
|
};
|
|
3526
3526
|
exports2.unregisterAll = (handlebars) => {
|
|
3527
|
-
for (let
|
|
3528
|
-
handlebars.unregisterHelper(
|
|
3527
|
+
for (let name2 of Object.keys(ADDED_HELPERS)) {
|
|
3528
|
+
handlebars.unregisterHelper(name2);
|
|
3529
3529
|
}
|
|
3530
|
-
for (let
|
|
3531
|
-
handlebars.unregisterHelper(
|
|
3530
|
+
for (let name2 of module2.exports.externalHelperNames) {
|
|
3531
|
+
handlebars.unregisterHelper(name2);
|
|
3532
3532
|
}
|
|
3533
3533
|
exports2.externalHelperNames = [];
|
|
3534
3534
|
};
|
|
@@ -3642,12 +3642,12 @@ var require_javascript = __commonJS({
|
|
|
3642
3642
|
throw new Error("JS disabled in environment.");
|
|
3643
3643
|
}
|
|
3644
3644
|
try {
|
|
3645
|
-
const
|
|
3645
|
+
const js2 = `function run(){${atob(handlebars)}};run();`;
|
|
3646
3646
|
const sandboxContext = {
|
|
3647
3647
|
$: (path2) => getContextValue(path2, cloneDeep7(context)),
|
|
3648
3648
|
helpers: getHelperList()
|
|
3649
3649
|
};
|
|
3650
|
-
const res = { data: runJS(
|
|
3650
|
+
const res = { data: runJS(js2, sandboxContext) };
|
|
3651
3651
|
return `{{${LITERAL_MARKER} js_result-${JSON.stringify(res)}}}`;
|
|
3652
3652
|
} catch (error) {
|
|
3653
3653
|
return "Error while executing JS";
|
|
@@ -3760,8 +3760,8 @@ var require_preprocessor = __commonJS({
|
|
|
3760
3760
|
FINALISE: "finalise"
|
|
3761
3761
|
};
|
|
3762
3762
|
var Preprocessor = class {
|
|
3763
|
-
constructor(
|
|
3764
|
-
this.name =
|
|
3763
|
+
constructor(name2, fn) {
|
|
3764
|
+
this.name = name2;
|
|
3765
3765
|
this.fn = fn;
|
|
3766
3766
|
}
|
|
3767
3767
|
process(fullString, statement, opts) {
|
|
@@ -3825,8 +3825,8 @@ var require_postprocessor = __commonJS({
|
|
|
3825
3825
|
CONVERT_LITERALS: "convert-literals"
|
|
3826
3826
|
};
|
|
3827
3827
|
var Postprocessor = class {
|
|
3828
|
-
constructor(
|
|
3829
|
-
this.name =
|
|
3828
|
+
constructor(name2, fn) {
|
|
3829
|
+
this.name = name2;
|
|
3830
3830
|
this.fn = fn;
|
|
3831
3831
|
}
|
|
3832
3832
|
process(statement) {
|
|
@@ -5468,10 +5468,10 @@ var require_src = __commonJS({
|
|
|
5468
5468
|
};
|
|
5469
5469
|
module2.exports.convertToJS = (hbs) => {
|
|
5470
5470
|
const blocks = exports2.findHBSBlocks(hbs);
|
|
5471
|
-
let
|
|
5471
|
+
let js2 = "return `", prevBlock = null;
|
|
5472
5472
|
const variables = {};
|
|
5473
5473
|
if (blocks.length === 0) {
|
|
5474
|
-
|
|
5474
|
+
js2 += hbs;
|
|
5475
5475
|
}
|
|
5476
5476
|
let count = 1;
|
|
5477
5477
|
for (let block of blocks) {
|
|
@@ -5483,15 +5483,15 @@ var require_src = __commonJS({
|
|
|
5483
5483
|
prevBlock = block;
|
|
5484
5484
|
const { variable, value } = convertHBSBlock(block, count++);
|
|
5485
5485
|
variables[variable] = value;
|
|
5486
|
-
|
|
5486
|
+
js2 += `${stringPart.split()}\${${variable}}`;
|
|
5487
5487
|
}
|
|
5488
5488
|
let varBlock = "";
|
|
5489
5489
|
for (let [variable, value] of Object.entries(variables)) {
|
|
5490
5490
|
varBlock += `const ${variable} = ${value};
|
|
5491
5491
|
`;
|
|
5492
5492
|
}
|
|
5493
|
-
|
|
5494
|
-
return `${varBlock}${
|
|
5493
|
+
js2 += "`;";
|
|
5494
|
+
return `${varBlock}${js2}`;
|
|
5495
5495
|
};
|
|
5496
5496
|
}
|
|
5497
5497
|
});
|
|
@@ -5518,12 +5518,12 @@ var require_src2 = __commonJS({
|
|
|
5518
5518
|
if (!process.env.NO_JS) {
|
|
5519
5519
|
const { VM: VM2 } = require("vm2");
|
|
5520
5520
|
const { setJSRunner } = require_javascript();
|
|
5521
|
-
setJSRunner((
|
|
5521
|
+
setJSRunner((js2, context) => {
|
|
5522
5522
|
const vm = new VM2({
|
|
5523
5523
|
sandbox: context,
|
|
5524
5524
|
timeout: 1e3
|
|
5525
5525
|
});
|
|
5526
|
-
return vm.run(
|
|
5526
|
+
return vm.run(js2);
|
|
5527
5527
|
});
|
|
5528
5528
|
}
|
|
5529
5529
|
}
|
|
@@ -5874,8 +5874,8 @@ async function lookupTenantId(userId) {
|
|
|
5874
5874
|
return user.tenantId;
|
|
5875
5875
|
}
|
|
5876
5876
|
async function getUserDoc(emailOrId) {
|
|
5877
|
-
const
|
|
5878
|
-
return
|
|
5877
|
+
const db2 = getPlatformDB();
|
|
5878
|
+
return db2.get(emailOrId);
|
|
5879
5879
|
}
|
|
5880
5880
|
function newUserIdDoc(id, tenantId) {
|
|
5881
5881
|
return {
|
|
@@ -5891,14 +5891,14 @@ function newUserEmailDoc(userId, email, tenantId) {
|
|
|
5891
5891
|
};
|
|
5892
5892
|
}
|
|
5893
5893
|
async function addUserDoc(emailOrId, newDocFn) {
|
|
5894
|
-
const
|
|
5894
|
+
const db2 = getPlatformDB();
|
|
5895
5895
|
let user;
|
|
5896
5896
|
try {
|
|
5897
|
-
await
|
|
5897
|
+
await db2.get(emailOrId);
|
|
5898
5898
|
} catch (e) {
|
|
5899
5899
|
if (e.status === 404) {
|
|
5900
5900
|
user = newDocFn();
|
|
5901
|
-
await
|
|
5901
|
+
await db2.put(user);
|
|
5902
5902
|
} else {
|
|
5903
5903
|
throw e;
|
|
5904
5904
|
}
|
|
@@ -5911,9 +5911,9 @@ async function addUser(tenantId, userId, email) {
|
|
|
5911
5911
|
]);
|
|
5912
5912
|
}
|
|
5913
5913
|
async function removeUser(user) {
|
|
5914
|
-
const
|
|
5914
|
+
const db2 = getPlatformDB();
|
|
5915
5915
|
const keys2 = [user._id, user.email];
|
|
5916
|
-
const userDocs = await
|
|
5916
|
+
const userDocs = await db2.allDocs({
|
|
5917
5917
|
keys: keys2,
|
|
5918
5918
|
include_docs: true
|
|
5919
5919
|
});
|
|
@@ -5923,7 +5923,7 @@ async function removeUser(user) {
|
|
|
5923
5923
|
_deleted: true
|
|
5924
5924
|
};
|
|
5925
5925
|
});
|
|
5926
|
-
await
|
|
5926
|
+
await db2.bulkDocs(toDelete);
|
|
5927
5927
|
}
|
|
5928
5928
|
|
|
5929
5929
|
// ../backend-core/src/platform/tenants.ts
|
|
@@ -6008,18 +6008,18 @@ async function newRedlock(opts = {}) {
|
|
|
6008
6008
|
}
|
|
6009
6009
|
function getLockName(opts) {
|
|
6010
6010
|
const prefix = opts.systemLock ? "system" : getTenantId();
|
|
6011
|
-
let
|
|
6011
|
+
let name2 = `lock:${prefix}_${opts.name}`;
|
|
6012
6012
|
if (opts.resource) {
|
|
6013
|
-
|
|
6013
|
+
name2 = name2 + `_${opts.resource}`;
|
|
6014
6014
|
}
|
|
6015
|
-
return
|
|
6015
|
+
return name2;
|
|
6016
6016
|
}
|
|
6017
6017
|
async function doWithLock(opts, task) {
|
|
6018
6018
|
const redlock = await getClient(opts.type, opts.customOptions);
|
|
6019
6019
|
let lock;
|
|
6020
6020
|
try {
|
|
6021
|
-
const
|
|
6022
|
-
lock = await redlock.lock(
|
|
6021
|
+
const name2 = getLockName(opts);
|
|
6022
|
+
lock = await redlock.lock(name2, opts.ttl);
|
|
6023
6023
|
const result = await task();
|
|
6024
6024
|
return { executed: true, result };
|
|
6025
6025
|
} catch (e) {
|
|
@@ -6129,8 +6129,8 @@ var getAccount = async (email) => {
|
|
|
6129
6129
|
// ../backend-core/src/cache/user.ts
|
|
6130
6130
|
var EXPIRY_SECONDS = 3600;
|
|
6131
6131
|
async function populateFromDB(userId, tenantId) {
|
|
6132
|
-
const
|
|
6133
|
-
const user = await
|
|
6132
|
+
const db2 = getTenantDB(tenantId);
|
|
6133
|
+
const user = await db2.get(userId);
|
|
6134
6134
|
user.budibaseAccess = true;
|
|
6135
6135
|
if (!environment_default2.SELF_HOSTED && !environment_default2.DISABLE_ACCOUNT_PORTAL) {
|
|
6136
6136
|
const account = await getAccount(user.email);
|
|
@@ -6319,8 +6319,8 @@ function generateRoleID(id) {
|
|
|
6319
6319
|
var generateDevInfoID = (userId) => {
|
|
6320
6320
|
return `${"devinfo" /* DEV_INFO */}${SEPARATOR}${userId}`;
|
|
6321
6321
|
};
|
|
6322
|
-
var generatePluginID = (
|
|
6323
|
-
return `${"plg" /* PLUGIN */}${SEPARATOR}${
|
|
6322
|
+
var generatePluginID = (name2) => {
|
|
6323
|
+
return `${"plg" /* PLUGIN */}${SEPARATOR}${name2}`;
|
|
6324
6324
|
};
|
|
6325
6325
|
|
|
6326
6326
|
// ../backend-core/src/docIds/params.ts
|
|
@@ -6405,8 +6405,8 @@ function getStartEndKeyURL(baseKey, tenantId) {
|
|
|
6405
6405
|
const tenancy2 = tenantId ? `${SEPARATOR}${tenantId}` : "";
|
|
6406
6406
|
return `startkey="${baseKey}${tenancy2}"&endkey="${baseKey}${tenancy2}${UNICODE_MAX}"`;
|
|
6407
6407
|
}
|
|
6408
|
-
var getPluginParams = (
|
|
6409
|
-
return getDocParams("plg" /* PLUGIN */,
|
|
6408
|
+
var getPluginParams = (pluginId2, otherProps = {}) => {
|
|
6409
|
+
return getDocParams("plg" /* PLUGIN */, pluginId2, otherProps);
|
|
6410
6410
|
};
|
|
6411
6411
|
|
|
6412
6412
|
// ../backend-core/src/db/utils.ts
|
|
@@ -6513,8 +6513,8 @@ function isSameAppID(appId1, appId2) {
|
|
|
6513
6513
|
async function dbExists(dbName) {
|
|
6514
6514
|
return doWithDB(
|
|
6515
6515
|
dbName,
|
|
6516
|
-
async (
|
|
6517
|
-
return await
|
|
6516
|
+
async (db2) => {
|
|
6517
|
+
return await db2.exists();
|
|
6518
6518
|
},
|
|
6519
6519
|
{ skip_setup: true }
|
|
6520
6520
|
);
|
|
@@ -6533,7 +6533,7 @@ function pagination(data, pageSize, {
|
|
|
6533
6533
|
const hasNextPage = data.length > pageSize;
|
|
6534
6534
|
let nextPage = void 0;
|
|
6535
6535
|
if (!getKey) {
|
|
6536
|
-
getKey = (
|
|
6536
|
+
getKey = (doc2) => property ? doc2 == null ? void 0 : doc2[property] : doc2 == null ? void 0 : doc2._id;
|
|
6537
6537
|
}
|
|
6538
6538
|
if (hasNextPage) {
|
|
6539
6539
|
nextPage = getKey(data[pageSize]);
|
|
@@ -6558,23 +6558,23 @@ function DesignDoc() {
|
|
|
6558
6558
|
views: {}
|
|
6559
6559
|
};
|
|
6560
6560
|
}
|
|
6561
|
-
async function removeDeprecated(
|
|
6561
|
+
async function removeDeprecated(db2, viewName) {
|
|
6562
6562
|
if (!DeprecatedViews[viewName]) {
|
|
6563
6563
|
return;
|
|
6564
6564
|
}
|
|
6565
6565
|
try {
|
|
6566
|
-
const designDoc = await
|
|
6566
|
+
const designDoc = await db2.get(DESIGN_DB);
|
|
6567
6567
|
for (let deprecatedNames of DeprecatedViews[viewName]) {
|
|
6568
6568
|
delete designDoc.views[deprecatedNames];
|
|
6569
6569
|
}
|
|
6570
|
-
await
|
|
6570
|
+
await db2.put(designDoc);
|
|
6571
6571
|
} catch (err) {
|
|
6572
6572
|
}
|
|
6573
6573
|
}
|
|
6574
|
-
async function createView(
|
|
6574
|
+
async function createView(db2, viewJs, viewName) {
|
|
6575
6575
|
let designDoc;
|
|
6576
6576
|
try {
|
|
6577
|
-
designDoc = await
|
|
6577
|
+
designDoc = await db2.get(DESIGN_DB);
|
|
6578
6578
|
} catch (err) {
|
|
6579
6579
|
designDoc = DesignDoc();
|
|
6580
6580
|
}
|
|
@@ -6586,26 +6586,26 @@ async function createView(db, viewJs, viewName) {
|
|
|
6586
6586
|
[viewName]: view
|
|
6587
6587
|
};
|
|
6588
6588
|
try {
|
|
6589
|
-
await
|
|
6589
|
+
await db2.put(designDoc);
|
|
6590
6590
|
} catch (err) {
|
|
6591
6591
|
if (err.status === 409) {
|
|
6592
|
-
return await createView(
|
|
6592
|
+
return await createView(db2, viewJs, viewName);
|
|
6593
6593
|
} else {
|
|
6594
6594
|
throw err;
|
|
6595
6595
|
}
|
|
6596
6596
|
}
|
|
6597
6597
|
}
|
|
6598
6598
|
var createNewUserEmailView = async () => {
|
|
6599
|
-
const
|
|
6599
|
+
const db2 = getGlobalDB();
|
|
6600
6600
|
const viewJs = `function(doc) {
|
|
6601
6601
|
if (doc._id.startsWith("${"us" /* USER */}${SEPARATOR}")) {
|
|
6602
6602
|
emit(doc.email.toLowerCase(), doc._id)
|
|
6603
6603
|
}
|
|
6604
6604
|
}`;
|
|
6605
|
-
await createView(
|
|
6605
|
+
await createView(db2, viewJs, "by_email2" /* USER_BY_EMAIL */);
|
|
6606
6606
|
};
|
|
6607
6607
|
var createUserAppView = async () => {
|
|
6608
|
-
const
|
|
6608
|
+
const db2 = getGlobalDB();
|
|
6609
6609
|
const viewJs = `function(doc) {
|
|
6610
6610
|
if (doc._id.startsWith("${"us" /* USER */}${SEPARATOR}") && doc.roles) {
|
|
6611
6611
|
for (let prodAppId of Object.keys(doc.roles)) {
|
|
@@ -6614,46 +6614,46 @@ var createUserAppView = async () => {
|
|
|
6614
6614
|
}
|
|
6615
6615
|
}
|
|
6616
6616
|
}`;
|
|
6617
|
-
await createView(
|
|
6617
|
+
await createView(db2, viewJs, "by_app" /* USER_BY_APP */);
|
|
6618
6618
|
};
|
|
6619
6619
|
var createApiKeyView = async () => {
|
|
6620
|
-
const
|
|
6620
|
+
const db2 = getGlobalDB();
|
|
6621
6621
|
const viewJs = `function(doc) {
|
|
6622
6622
|
if (doc._id.startsWith("${"devinfo" /* DEV_INFO */}") && doc.apiKey) {
|
|
6623
6623
|
emit(doc.apiKey, doc.userId)
|
|
6624
6624
|
}
|
|
6625
6625
|
}`;
|
|
6626
|
-
await createView(
|
|
6626
|
+
await createView(db2, viewJs, "by_api_key" /* BY_API_KEY */);
|
|
6627
6627
|
};
|
|
6628
6628
|
var createUserBuildersView = async () => {
|
|
6629
|
-
const
|
|
6629
|
+
const db2 = getGlobalDB();
|
|
6630
6630
|
const viewJs = `function(doc) {
|
|
6631
6631
|
if (doc.builder && doc.builder.global === true) {
|
|
6632
6632
|
emit(doc._id, doc._id)
|
|
6633
6633
|
}
|
|
6634
6634
|
}`;
|
|
6635
|
-
await createView(
|
|
6635
|
+
await createView(db2, viewJs, "by_builders" /* USER_BY_BUILDERS */);
|
|
6636
6636
|
};
|
|
6637
|
-
async function queryViewRaw(viewName, params2,
|
|
6637
|
+
async function queryViewRaw(viewName, params2, db2, createFunc, opts) {
|
|
6638
6638
|
try {
|
|
6639
|
-
const response = await
|
|
6639
|
+
const response = await db2.query(`database/${viewName}`, params2);
|
|
6640
6640
|
return response;
|
|
6641
6641
|
} catch (err) {
|
|
6642
6642
|
const pouchNotFound = err && err.name === "not_found";
|
|
6643
6643
|
const couchNotFound = err && err.status === 404;
|
|
6644
6644
|
if (pouchNotFound || couchNotFound) {
|
|
6645
|
-
await removeDeprecated(
|
|
6645
|
+
await removeDeprecated(db2, viewName);
|
|
6646
6646
|
await createFunc();
|
|
6647
|
-
return queryViewRaw(viewName, params2,
|
|
6647
|
+
return queryViewRaw(viewName, params2, db2, createFunc, opts);
|
|
6648
6648
|
} else if (err.status === 409) {
|
|
6649
|
-
return queryViewRaw(viewName, params2,
|
|
6649
|
+
return queryViewRaw(viewName, params2, db2, createFunc, opts);
|
|
6650
6650
|
} else {
|
|
6651
6651
|
throw err;
|
|
6652
6652
|
}
|
|
6653
6653
|
}
|
|
6654
6654
|
}
|
|
6655
|
-
var queryView = async (viewName, params2,
|
|
6656
|
-
const response = await queryViewRaw(viewName, params2,
|
|
6655
|
+
var queryView = async (viewName, params2, db2, createFunc, opts) => {
|
|
6656
|
+
const response = await queryViewRaw(viewName, params2, db2, createFunc, opts);
|
|
6657
6657
|
const rows2 = response.rows;
|
|
6658
6658
|
const docs = rows2.map(
|
|
6659
6659
|
(row) => params2.include_docs ? row.doc : row.value
|
|
@@ -6666,8 +6666,8 @@ var queryView = async (viewName, params2, db, createFunc, opts) => {
|
|
|
6666
6666
|
};
|
|
6667
6667
|
async function createPlatformView(viewJs, viewName) {
|
|
6668
6668
|
try {
|
|
6669
|
-
await doWithDB(StaticDatabases.PLATFORM_INFO.name, async (
|
|
6670
|
-
await createView(
|
|
6669
|
+
await doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db2) => {
|
|
6670
|
+
await createView(db2, viewJs, viewName);
|
|
6671
6671
|
});
|
|
6672
6672
|
} catch (e) {
|
|
6673
6673
|
if (e.status === 409 && environment_default2.isTest()) {
|
|
@@ -6697,9 +6697,9 @@ var queryPlatformView = async (viewName, params2, opts) => {
|
|
|
6697
6697
|
["account_by_email" /* ACCOUNT_BY_EMAIL */]: createPlatformAccountEmailView,
|
|
6698
6698
|
["platform_users_lowercase" /* PLATFORM_USERS_LOWERCASE */]: createPlatformUserView
|
|
6699
6699
|
};
|
|
6700
|
-
return doWithDB(StaticDatabases.PLATFORM_INFO.name, async (
|
|
6700
|
+
return doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db2) => {
|
|
6701
6701
|
const createFn = CreateFuncByName2[viewName];
|
|
6702
|
-
return queryView(viewName, params2,
|
|
6702
|
+
return queryView(viewName, params2, db2, createFn, opts);
|
|
6703
6703
|
});
|
|
6704
6704
|
};
|
|
6705
6705
|
var CreateFuncByName = {
|
|
@@ -6708,17 +6708,17 @@ var CreateFuncByName = {
|
|
|
6708
6708
|
["by_builders" /* USER_BY_BUILDERS */]: createUserBuildersView,
|
|
6709
6709
|
["by_app" /* USER_BY_APP */]: createUserAppView
|
|
6710
6710
|
};
|
|
6711
|
-
var queryGlobalView = async (viewName, params2,
|
|
6712
|
-
if (!
|
|
6713
|
-
|
|
6711
|
+
var queryGlobalView = async (viewName, params2, db2, opts) => {
|
|
6712
|
+
if (!db2) {
|
|
6713
|
+
db2 = getGlobalDB();
|
|
6714
6714
|
}
|
|
6715
6715
|
const createFn = CreateFuncByName[viewName];
|
|
6716
|
-
return queryView(viewName, params2,
|
|
6716
|
+
return queryView(viewName, params2, db2, createFn, opts);
|
|
6717
6717
|
};
|
|
6718
6718
|
async function queryGlobalViewRaw(viewName, params2, opts) {
|
|
6719
|
-
const
|
|
6719
|
+
const db2 = getGlobalDB();
|
|
6720
6720
|
const createFn = CreateFuncByName[viewName];
|
|
6721
|
-
return queryViewRaw(viewName, params2,
|
|
6721
|
+
return queryViewRaw(viewName, params2, db2, createFn, opts);
|
|
6722
6722
|
}
|
|
6723
6723
|
|
|
6724
6724
|
// ../backend-core/src/db/index.ts
|
|
@@ -6733,8 +6733,8 @@ var Replication = class {
|
|
|
6733
6733
|
* @param {String} source - the DB you want to replicate or rollback to
|
|
6734
6734
|
* @param {String} target - the DB you want to replicate to, or rollback from
|
|
6735
6735
|
*/
|
|
6736
|
-
constructor({ source, target }) {
|
|
6737
|
-
this.source = getPouchDB(
|
|
6736
|
+
constructor({ source: source2, target }) {
|
|
6737
|
+
this.source = getPouchDB(source2);
|
|
6738
6738
|
this.target = getPouchDB(target);
|
|
6739
6739
|
}
|
|
6740
6740
|
close() {
|
|
@@ -6769,8 +6769,8 @@ var Replication = class {
|
|
|
6769
6769
|
}
|
|
6770
6770
|
appReplicateOpts() {
|
|
6771
6771
|
return {
|
|
6772
|
-
filter: (
|
|
6773
|
-
return
|
|
6772
|
+
filter: (doc2) => {
|
|
6773
|
+
return doc2._id !== "app_metadata" /* APP_METADATA */;
|
|
6774
6774
|
}
|
|
6775
6775
|
};
|
|
6776
6776
|
}
|
|
@@ -6858,9 +6858,9 @@ var _QueryBuilder = class {
|
|
|
6858
6858
|
__privateSet(this, _indexBuilder, builderFn);
|
|
6859
6859
|
return this;
|
|
6860
6860
|
}
|
|
6861
|
-
setVersion(
|
|
6862
|
-
if (
|
|
6863
|
-
__privateSet(this, _version,
|
|
6861
|
+
setVersion(version2) {
|
|
6862
|
+
if (version2 != null) {
|
|
6863
|
+
__privateSet(this, _version, version2);
|
|
6864
6864
|
}
|
|
6865
6865
|
return this;
|
|
6866
6866
|
}
|
|
@@ -7353,10 +7353,10 @@ __export(searchIndexes_exports, {
|
|
|
7353
7353
|
init_src();
|
|
7354
7354
|
init_context2();
|
|
7355
7355
|
async function createUserIndex() {
|
|
7356
|
-
const
|
|
7356
|
+
const db2 = getGlobalDB();
|
|
7357
7357
|
let designDoc;
|
|
7358
7358
|
try {
|
|
7359
|
-
designDoc = await
|
|
7359
|
+
designDoc = await db2.get("_design/database");
|
|
7360
7360
|
} catch (err) {
|
|
7361
7361
|
if (err.status === 404) {
|
|
7362
7362
|
designDoc = { _id: "_design/database" };
|
|
@@ -7402,7 +7402,7 @@ async function createUserIndex() {
|
|
|
7402
7402
|
}
|
|
7403
7403
|
}
|
|
7404
7404
|
};
|
|
7405
|
-
await
|
|
7405
|
+
await db2.put(designDoc);
|
|
7406
7406
|
}
|
|
7407
7407
|
|
|
7408
7408
|
// ../backend-core/src/cache/appMetadata.ts
|
|
@@ -7413,42 +7413,42 @@ var EXPIRY_SECONDS2 = 3600;
|
|
|
7413
7413
|
async function populateFromDB2(appId) {
|
|
7414
7414
|
return doWithDB(
|
|
7415
7415
|
appId,
|
|
7416
|
-
(
|
|
7417
|
-
return
|
|
7416
|
+
(db2) => {
|
|
7417
|
+
return db2.get("app_metadata" /* APP_METADATA */);
|
|
7418
7418
|
},
|
|
7419
7419
|
{ skip_setup: true }
|
|
7420
7420
|
);
|
|
7421
7421
|
}
|
|
7422
|
-
function isInvalid(
|
|
7423
|
-
return !
|
|
7422
|
+
function isInvalid(metadata2) {
|
|
7423
|
+
return !metadata2 || metadata2.state === AppState.INVALID;
|
|
7424
7424
|
}
|
|
7425
7425
|
async function getAppMetadata(appId) {
|
|
7426
7426
|
const client3 = await getAppClient();
|
|
7427
|
-
let
|
|
7428
|
-
if (!
|
|
7427
|
+
let metadata2 = await client3.get(appId);
|
|
7428
|
+
if (!metadata2) {
|
|
7429
7429
|
let expiry = EXPIRY_SECONDS2;
|
|
7430
7430
|
try {
|
|
7431
|
-
|
|
7431
|
+
metadata2 = await populateFromDB2(appId);
|
|
7432
7432
|
} catch (err) {
|
|
7433
7433
|
if (err && err.status === 404) {
|
|
7434
|
-
|
|
7434
|
+
metadata2 = { state: AppState.INVALID };
|
|
7435
7435
|
expiry = void 0;
|
|
7436
7436
|
} else {
|
|
7437
7437
|
throw err;
|
|
7438
7438
|
}
|
|
7439
7439
|
}
|
|
7440
|
-
if (isInvalid(
|
|
7440
|
+
if (isInvalid(metadata2)) {
|
|
7441
7441
|
const temp = await client3.get(appId);
|
|
7442
7442
|
if (temp) {
|
|
7443
|
-
|
|
7443
|
+
metadata2 = temp;
|
|
7444
7444
|
}
|
|
7445
7445
|
}
|
|
7446
|
-
await client3.store(appId,
|
|
7446
|
+
await client3.store(appId, metadata2, expiry);
|
|
7447
7447
|
}
|
|
7448
|
-
if (isInvalid(
|
|
7448
|
+
if (isInvalid(metadata2)) {
|
|
7449
7449
|
throw { status: 404, message: "No app metadata found" };
|
|
7450
7450
|
}
|
|
7451
|
-
return
|
|
7451
|
+
return metadata2;
|
|
7452
7452
|
}
|
|
7453
7453
|
async function invalidateAppMetadata(appId, newMetadata) {
|
|
7454
7454
|
if (!appId) {
|
|
@@ -7479,21 +7479,21 @@ async function getCache() {
|
|
|
7479
7479
|
}
|
|
7480
7480
|
return CACHE;
|
|
7481
7481
|
}
|
|
7482
|
-
function makeCacheKey(
|
|
7483
|
-
return
|
|
7482
|
+
function makeCacheKey(db2, key) {
|
|
7483
|
+
return db2.name + key;
|
|
7484
7484
|
}
|
|
7485
|
-
function makeCacheItem(
|
|
7486
|
-
return { doc, lastWrite: lastWrite || Date.now() };
|
|
7485
|
+
function makeCacheItem(doc2, lastWrite = null) {
|
|
7486
|
+
return { doc: doc2, lastWrite: lastWrite || Date.now() };
|
|
7487
7487
|
}
|
|
7488
|
-
async function put(
|
|
7488
|
+
async function put(db2, doc2, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
7489
7489
|
const cache2 = await getCache();
|
|
7490
|
-
const key =
|
|
7490
|
+
const key = doc2._id;
|
|
7491
7491
|
let cacheItem;
|
|
7492
7492
|
if (key) {
|
|
7493
|
-
cacheItem = await cache2.get(makeCacheKey(
|
|
7493
|
+
cacheItem = await cache2.get(makeCacheKey(db2, key));
|
|
7494
7494
|
}
|
|
7495
7495
|
const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs;
|
|
7496
|
-
let output =
|
|
7496
|
+
let output = doc2;
|
|
7497
7497
|
if (updateDb) {
|
|
7498
7498
|
const lockResponse = await doWithLock(
|
|
7499
7499
|
{
|
|
@@ -7504,15 +7504,15 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
|
7504
7504
|
},
|
|
7505
7505
|
async () => {
|
|
7506
7506
|
const writeDb = async (toWrite) => {
|
|
7507
|
-
const response = await
|
|
7507
|
+
const response = await db2.put(toWrite, { force: true });
|
|
7508
7508
|
output = {
|
|
7509
|
-
...
|
|
7509
|
+
...doc2,
|
|
7510
7510
|
_id: response.id,
|
|
7511
7511
|
_rev: response.rev
|
|
7512
7512
|
};
|
|
7513
7513
|
};
|
|
7514
7514
|
try {
|
|
7515
|
-
await writeDb(
|
|
7515
|
+
await writeDb(doc2);
|
|
7516
7516
|
} catch (err) {
|
|
7517
7517
|
if (err.status !== 409) {
|
|
7518
7518
|
throw err;
|
|
@@ -7528,47 +7528,47 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
|
7528
7528
|
}
|
|
7529
7529
|
cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
|
|
7530
7530
|
if (output._id) {
|
|
7531
|
-
await cache2.store(makeCacheKey(
|
|
7531
|
+
await cache2.store(makeCacheKey(db2, output._id), cacheItem);
|
|
7532
7532
|
}
|
|
7533
7533
|
return { ok: true, id: output._id, rev: output._rev };
|
|
7534
7534
|
}
|
|
7535
|
-
async function get2(
|
|
7535
|
+
async function get2(db2, id) {
|
|
7536
7536
|
const cache2 = await getCache();
|
|
7537
|
-
const cacheKey = makeCacheKey(
|
|
7537
|
+
const cacheKey = makeCacheKey(db2, id);
|
|
7538
7538
|
let cacheItem = await cache2.get(cacheKey);
|
|
7539
7539
|
if (!cacheItem) {
|
|
7540
|
-
const
|
|
7541
|
-
cacheItem = makeCacheItem(
|
|
7540
|
+
const doc2 = await db2.get(id);
|
|
7541
|
+
cacheItem = makeCacheItem(doc2);
|
|
7542
7542
|
await cache2.store(cacheKey, cacheItem);
|
|
7543
7543
|
}
|
|
7544
7544
|
return cacheItem.doc;
|
|
7545
7545
|
}
|
|
7546
|
-
async function remove(
|
|
7546
|
+
async function remove(db2, docOrId, rev2) {
|
|
7547
7547
|
const cache2 = await getCache();
|
|
7548
7548
|
if (!docOrId) {
|
|
7549
7549
|
throw new Error("No ID/Rev provided.");
|
|
7550
7550
|
}
|
|
7551
7551
|
const id = typeof docOrId === "string" ? docOrId : docOrId._id;
|
|
7552
|
-
|
|
7552
|
+
rev2 = typeof docOrId === "string" ? rev2 : docOrId._rev;
|
|
7553
7553
|
try {
|
|
7554
|
-
await cache2.delete(makeCacheKey(
|
|
7554
|
+
await cache2.delete(makeCacheKey(db2, id));
|
|
7555
7555
|
} finally {
|
|
7556
|
-
await
|
|
7556
|
+
await db2.remove(id, rev2);
|
|
7557
7557
|
}
|
|
7558
7558
|
}
|
|
7559
7559
|
var Writethrough = class {
|
|
7560
|
-
constructor(
|
|
7561
|
-
this.db =
|
|
7560
|
+
constructor(db2, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
7561
|
+
this.db = db2;
|
|
7562
7562
|
this.writeRateMs = writeRateMs;
|
|
7563
7563
|
}
|
|
7564
|
-
async put(
|
|
7565
|
-
return put(this.db,
|
|
7564
|
+
async put(doc2) {
|
|
7565
|
+
return put(this.db, doc2, this.writeRateMs);
|
|
7566
7566
|
}
|
|
7567
7567
|
async get(id) {
|
|
7568
7568
|
return get2(this.db, id);
|
|
7569
7569
|
}
|
|
7570
|
-
async remove(docOrId,
|
|
7571
|
-
return remove(this.db, docOrId,
|
|
7570
|
+
async remove(docOrId, rev2) {
|
|
7571
|
+
return remove(this.db, docOrId, rev2);
|
|
7572
7572
|
}
|
|
7573
7573
|
};
|
|
7574
7574
|
|
|
@@ -7580,9 +7580,9 @@ function generateConfigID(type) {
|
|
|
7580
7580
|
return `${"config" /* CONFIG */}${SEPARATOR}${type}`;
|
|
7581
7581
|
}
|
|
7582
7582
|
async function getConfig(type) {
|
|
7583
|
-
const
|
|
7583
|
+
const db2 = getGlobalDB();
|
|
7584
7584
|
try {
|
|
7585
|
-
return await
|
|
7585
|
+
return await db2.get(generateConfigID(type));
|
|
7586
7586
|
} catch (e) {
|
|
7587
7587
|
if (e.status === 404) {
|
|
7588
7588
|
return;
|
|
@@ -7591,8 +7591,8 @@ async function getConfig(type) {
|
|
|
7591
7591
|
}
|
|
7592
7592
|
}
|
|
7593
7593
|
async function save(config) {
|
|
7594
|
-
const
|
|
7595
|
-
return
|
|
7594
|
+
const db2 = getGlobalDB();
|
|
7595
|
+
return db2.put(config);
|
|
7596
7596
|
}
|
|
7597
7597
|
async function getSettingsConfigDoc() {
|
|
7598
7598
|
let config = await getConfig("settings" /* SETTINGS */);
|
|
@@ -8041,7 +8041,7 @@ __export(utils_exports2, {
|
|
|
8041
8041
|
compare: () => compare,
|
|
8042
8042
|
getAppIdFromCtx: () => getAppIdFromCtx,
|
|
8043
8043
|
getCookie: () => getCookie,
|
|
8044
|
-
hash: () =>
|
|
8044
|
+
hash: () => hash2,
|
|
8045
8045
|
isAudited: () => isAudited,
|
|
8046
8046
|
isClient: () => isClient,
|
|
8047
8047
|
isPublicApiRequest: () => isPublicApiRequest,
|
|
@@ -8062,7 +8062,7 @@ init_environment2();
|
|
|
8062
8062
|
init_newid();
|
|
8063
8063
|
var bcrypt = environment_default2.JS_BCRYPT ? require("bcryptjs") : require("bcrypt");
|
|
8064
8064
|
var SALT_ROUNDS = environment_default2.SALT_ROUNDS || 10;
|
|
8065
|
-
async function
|
|
8065
|
+
async function hash2(data) {
|
|
8066
8066
|
const salt = await bcrypt.genSalt(SALT_ROUNDS);
|
|
8067
8067
|
return bcrypt.hash(data, salt);
|
|
8068
8068
|
}
|
|
@@ -8178,14 +8178,14 @@ function isValidInternalAPIKey(apiKey) {
|
|
|
8178
8178
|
}
|
|
8179
8179
|
return false;
|
|
8180
8180
|
}
|
|
8181
|
-
function getCookie(ctx,
|
|
8182
|
-
const cookie = ctx.cookies.get(
|
|
8181
|
+
function getCookie(ctx, name2) {
|
|
8182
|
+
const cookie = ctx.cookies.get(name2);
|
|
8183
8183
|
if (!cookie) {
|
|
8184
8184
|
return cookie;
|
|
8185
8185
|
}
|
|
8186
8186
|
return openJwt(cookie);
|
|
8187
8187
|
}
|
|
8188
|
-
function setCookie(ctx, value,
|
|
8188
|
+
function setCookie(ctx, value, name2 = "builder", opts = { sign: true }) {
|
|
8189
8189
|
if (value && opts && opts.sign) {
|
|
8190
8190
|
value = jwt.sign(value, environment_default2.JWT_SECRET);
|
|
8191
8191
|
}
|
|
@@ -8198,10 +8198,10 @@ function setCookie(ctx, value, name = "builder", opts = { sign: true }) {
|
|
|
8198
8198
|
if (environment_default2.COOKIE_DOMAIN) {
|
|
8199
8199
|
config.domain = environment_default2.COOKIE_DOMAIN;
|
|
8200
8200
|
}
|
|
8201
|
-
ctx.cookies.set(
|
|
8201
|
+
ctx.cookies.set(name2, value, config);
|
|
8202
8202
|
}
|
|
8203
|
-
function clearCookie(ctx,
|
|
8204
|
-
setCookie(ctx, null,
|
|
8203
|
+
function clearCookie(ctx, name2) {
|
|
8204
|
+
setCookie(ctx, null, name2);
|
|
8205
8205
|
}
|
|
8206
8206
|
function isClient(ctx) {
|
|
8207
8207
|
return ctx.headers["x-budibase-type" /* TYPE */] === "client";
|
|
@@ -8235,8 +8235,8 @@ var InMemoryQueue = class {
|
|
|
8235
8235
|
* @param {object|null} opts This is not used by the in memory queue as there is no real use
|
|
8236
8236
|
* case when in memory, but is the same API as Bull
|
|
8237
8237
|
*/
|
|
8238
|
-
constructor(
|
|
8239
|
-
this._name =
|
|
8238
|
+
constructor(name2, opts = null) {
|
|
8239
|
+
this._name = name2;
|
|
8240
8240
|
this._opts = opts;
|
|
8241
8241
|
this._messages = [];
|
|
8242
8242
|
this._emitter = new import_events2.default.EventEmitter();
|
|
@@ -8669,13 +8669,13 @@ var getInstallFromDB = async () => {
|
|
|
8669
8669
|
}
|
|
8670
8670
|
);
|
|
8671
8671
|
};
|
|
8672
|
-
var updateVersion = async (
|
|
8672
|
+
var updateVersion = async (version2) => {
|
|
8673
8673
|
try {
|
|
8674
8674
|
await doWithDB(
|
|
8675
8675
|
StaticDatabases.PLATFORM_INFO.name,
|
|
8676
8676
|
async (platformDb) => {
|
|
8677
8677
|
const install = await getInstall();
|
|
8678
|
-
install.version =
|
|
8678
|
+
install.version = version2;
|
|
8679
8679
|
await platformDb.put(install);
|
|
8680
8680
|
await bustCache("installation" /* INSTALLATION */);
|
|
8681
8681
|
}
|
|
@@ -8777,13 +8777,13 @@ var identifyInstallationGroup = async (installId, timestamp) => {
|
|
|
8777
8777
|
const id = installId;
|
|
8778
8778
|
const type = "installation" /* INSTALLATION */;
|
|
8779
8779
|
const hosting = getHostingFromEnv();
|
|
8780
|
-
const
|
|
8780
|
+
const version2 = environment_default2.VERSION;
|
|
8781
8781
|
const environment3 = getDeploymentEnvironment();
|
|
8782
8782
|
const group = {
|
|
8783
8783
|
id,
|
|
8784
8784
|
type,
|
|
8785
8785
|
hosting,
|
|
8786
|
-
version,
|
|
8786
|
+
version: version2,
|
|
8787
8787
|
environment: environment3
|
|
8788
8788
|
};
|
|
8789
8789
|
await identifyGroup(group, timestamp);
|
|
@@ -8908,7 +8908,7 @@ var getEventTenantId = async (tenantId) => {
|
|
|
8908
8908
|
var getUniqueTenantId = async (tenantId) => {
|
|
8909
8909
|
return doInTenant(tenantId, () => {
|
|
8910
8910
|
return withCache("uniqueTenantId" /* UNIQUE_TENANT_ID */, 86400 /* ONE_DAY */, async () => {
|
|
8911
|
-
const
|
|
8911
|
+
const db2 = getGlobalDB();
|
|
8912
8912
|
const config = await getSettingsConfigDoc();
|
|
8913
8913
|
let uniqueTenantId;
|
|
8914
8914
|
if (config.config.uniqueTenantId) {
|
|
@@ -8916,7 +8916,7 @@ var getUniqueTenantId = async (tenantId) => {
|
|
|
8916
8916
|
} else {
|
|
8917
8917
|
uniqueTenantId = `${newid()}_${tenantId}`;
|
|
8918
8918
|
config.config.uniqueTenantId = uniqueTenantId;
|
|
8919
|
-
await
|
|
8919
|
+
await db2.put(config);
|
|
8920
8920
|
return uniqueTenantId;
|
|
8921
8921
|
}
|
|
8922
8922
|
});
|
|
@@ -8956,10 +8956,10 @@ __export(backfill_exports, {
|
|
|
8956
8956
|
init_src();
|
|
8957
8957
|
init_context2();
|
|
8958
8958
|
var start = async (events2) => {
|
|
8959
|
-
const
|
|
8959
|
+
const metadata2 = {
|
|
8960
8960
|
eventWhitelist: events2
|
|
8961
8961
|
};
|
|
8962
|
-
return saveBackfillMetadata(
|
|
8962
|
+
return saveBackfillMetadata(metadata2);
|
|
8963
8963
|
};
|
|
8964
8964
|
var recordEvent2 = async (event, properties) => {
|
|
8965
8965
|
const eventKey2 = getEventKey(event, properties);
|
|
@@ -9269,11 +9269,11 @@ var app_default = {
|
|
|
9269
9269
|
|
|
9270
9270
|
// ../backend-core/src/events/publishers/auth.ts
|
|
9271
9271
|
init_src();
|
|
9272
|
-
async function login(
|
|
9272
|
+
async function login(source2, email) {
|
|
9273
9273
|
const identity = await identification_default.getCurrentIdentity();
|
|
9274
9274
|
const properties = {
|
|
9275
9275
|
userId: identity.id,
|
|
9276
|
-
source,
|
|
9276
|
+
source: source2,
|
|
9277
9277
|
audited: {
|
|
9278
9278
|
email
|
|
9279
9279
|
}
|
|
@@ -10062,9 +10062,9 @@ var view_default = {
|
|
|
10062
10062
|
|
|
10063
10063
|
// ../backend-core/src/events/publishers/installation.ts
|
|
10064
10064
|
init_src();
|
|
10065
|
-
async function versionChecked(
|
|
10065
|
+
async function versionChecked(version2) {
|
|
10066
10066
|
const properties = {
|
|
10067
|
-
currentVersion:
|
|
10067
|
+
currentVersion: version2
|
|
10068
10068
|
};
|
|
10069
10069
|
await publishEvent("installation:version:checked" /* INSTALLATION_VERSION_CHECKED */, properties);
|
|
10070
10070
|
}
|
|
@@ -10283,13 +10283,13 @@ async function appBackupRestored(backup) {
|
|
|
10283
10283
|
};
|
|
10284
10284
|
await publishEvent("app:backup:restored" /* APP_BACKUP_RESTORED */, properties);
|
|
10285
10285
|
}
|
|
10286
|
-
async function appBackupTriggered(appId, backupId, type, trigger,
|
|
10286
|
+
async function appBackupTriggered(appId, backupId, type, trigger, name2) {
|
|
10287
10287
|
const properties = {
|
|
10288
10288
|
appId,
|
|
10289
10289
|
backupId,
|
|
10290
10290
|
type,
|
|
10291
10291
|
trigger,
|
|
10292
|
-
name
|
|
10292
|
+
name: name2
|
|
10293
10293
|
};
|
|
10294
10294
|
await publishEvent("app:backup:triggered" /* APP_BACKUP_TRIGGERED */, properties);
|
|
10295
10295
|
}
|
|
@@ -10300,16 +10300,16 @@ var backup_default = {
|
|
|
10300
10300
|
|
|
10301
10301
|
// ../backend-core/src/events/publishers/environmentVariable.ts
|
|
10302
10302
|
init_src();
|
|
10303
|
-
async function created14(
|
|
10303
|
+
async function created14(name2, environments) {
|
|
10304
10304
|
const properties = {
|
|
10305
|
-
name,
|
|
10305
|
+
name: name2,
|
|
10306
10306
|
environments
|
|
10307
10307
|
};
|
|
10308
10308
|
await publishEvent("environment_variable:created" /* ENVIRONMENT_VARIABLE_CREATED */, properties);
|
|
10309
10309
|
}
|
|
10310
|
-
async function deleted14(
|
|
10310
|
+
async function deleted14(name2) {
|
|
10311
10311
|
const properties = {
|
|
10312
|
-
name
|
|
10312
|
+
name: name2
|
|
10313
10313
|
};
|
|
10314
10314
|
await publishEvent("environment_variable:deleted" /* ENVIRONMENT_VARIABLE_DELETED */, properties);
|
|
10315
10315
|
}
|
|
@@ -10430,8 +10430,8 @@ function removeUserPassword(users2) {
|
|
|
10430
10430
|
return users2;
|
|
10431
10431
|
}
|
|
10432
10432
|
var bulkGetGlobalUsersById = async (userIds, opts) => {
|
|
10433
|
-
const
|
|
10434
|
-
let users2 = (await
|
|
10433
|
+
const db2 = getGlobalDB();
|
|
10434
|
+
let users2 = (await db2.allDocs({
|
|
10435
10435
|
keys: userIds,
|
|
10436
10436
|
include_docs: true
|
|
10437
10437
|
})).rows.map((row) => row.doc);
|
|
@@ -10441,21 +10441,21 @@ var bulkGetGlobalUsersById = async (userIds, opts) => {
|
|
|
10441
10441
|
return users2;
|
|
10442
10442
|
};
|
|
10443
10443
|
var getAllUserIds = async () => {
|
|
10444
|
-
const
|
|
10444
|
+
const db2 = getGlobalDB();
|
|
10445
10445
|
const startKey = `${"us" /* USER */}${SEPARATOR}`;
|
|
10446
|
-
const response = await
|
|
10446
|
+
const response = await db2.allDocs({
|
|
10447
10447
|
startkey: startKey,
|
|
10448
10448
|
endkey: `${startKey}${UNICODE_MAX}`
|
|
10449
10449
|
});
|
|
10450
10450
|
return response.rows.map((row) => row.id);
|
|
10451
10451
|
};
|
|
10452
10452
|
var bulkUpdateGlobalUsers = async (users2) => {
|
|
10453
|
-
const
|
|
10454
|
-
return await
|
|
10453
|
+
const db2 = getGlobalDB();
|
|
10454
|
+
return await db2.bulkDocs(users2);
|
|
10455
10455
|
};
|
|
10456
10456
|
async function getById(id, opts) {
|
|
10457
|
-
const
|
|
10458
|
-
let user = await
|
|
10457
|
+
const db2 = getGlobalDB();
|
|
10458
|
+
let user = await db2.get(id);
|
|
10459
10459
|
if (opts == null ? void 0 : opts.cleanup) {
|
|
10460
10460
|
user = removeUserPassword(user);
|
|
10461
10461
|
}
|
|
@@ -10558,7 +10558,7 @@ var paginatedUsers = async ({
|
|
|
10558
10558
|
email,
|
|
10559
10559
|
appId
|
|
10560
10560
|
} = {}) => {
|
|
10561
|
-
const
|
|
10561
|
+
const db2 = getGlobalDB();
|
|
10562
10562
|
const opts = {
|
|
10563
10563
|
include_docs: true,
|
|
10564
10564
|
limit: PAGE_LIMIT + 1
|
|
@@ -10569,12 +10569,12 @@ var paginatedUsers = async ({
|
|
|
10569
10569
|
let userList, property = "_id", getKey;
|
|
10570
10570
|
if (appId) {
|
|
10571
10571
|
userList = await searchGlobalUsersByApp(appId, opts);
|
|
10572
|
-
getKey = (
|
|
10572
|
+
getKey = (doc2) => getGlobalUserByAppPage(appId, doc2);
|
|
10573
10573
|
} else if (email) {
|
|
10574
10574
|
userList = await searchGlobalUsersByEmail(email, opts);
|
|
10575
10575
|
property = "email";
|
|
10576
10576
|
} else {
|
|
10577
|
-
const response = await
|
|
10577
|
+
const response = await db2.allDocs(getGlobalUserParams(null, opts));
|
|
10578
10578
|
userList = response.rows.map((row) => row.doc);
|
|
10579
10579
|
}
|
|
10580
10580
|
return pagination(userList, PAGE_LIMIT, {
|
|
@@ -10695,10 +10695,10 @@ var EXTERNAL_BUILTIN_ROLE_IDS = [
|
|
|
10695
10695
|
BUILTIN_IDS.PUBLIC
|
|
10696
10696
|
];
|
|
10697
10697
|
var Role2 = class {
|
|
10698
|
-
constructor(id,
|
|
10698
|
+
constructor(id, name2, permissionId) {
|
|
10699
10699
|
this.permissions = {};
|
|
10700
10700
|
this._id = id;
|
|
10701
|
-
this.name =
|
|
10701
|
+
this.name = name2;
|
|
10702
10702
|
this.permissionId = permissionId;
|
|
10703
10703
|
}
|
|
10704
10704
|
addInheritance(inherits) {
|
|
@@ -10788,8 +10788,8 @@ async function getRole(roleId) {
|
|
|
10788
10788
|
);
|
|
10789
10789
|
}
|
|
10790
10790
|
try {
|
|
10791
|
-
const
|
|
10792
|
-
const dbRole = await
|
|
10791
|
+
const db2 = getAppDB();
|
|
10792
|
+
const dbRole = await db2.get(getDBRoleID(roleId));
|
|
10793
10793
|
role = Object.assign(role, dbRole);
|
|
10794
10794
|
role._id = getExternalRoleID(role._id);
|
|
10795
10795
|
} catch (err) {
|
|
@@ -10840,10 +10840,10 @@ async function getAllRoles(appId) {
|
|
|
10840
10840
|
}
|
|
10841
10841
|
return internal(appDB);
|
|
10842
10842
|
}
|
|
10843
|
-
async function internal(
|
|
10843
|
+
async function internal(db2) {
|
|
10844
10844
|
let roles = [];
|
|
10845
|
-
if (
|
|
10846
|
-
const body2 = await
|
|
10845
|
+
if (db2) {
|
|
10846
|
+
const body2 = await db2.allDocs(
|
|
10847
10847
|
getRoleParams(null, {
|
|
10848
10848
|
include_docs: true
|
|
10849
10849
|
})
|
|
@@ -11279,12 +11279,12 @@ async function syncUser(user, details) {
|
|
|
11279
11279
|
if (details.profile) {
|
|
11280
11280
|
const profile = details.profile;
|
|
11281
11281
|
if (profile.name) {
|
|
11282
|
-
const
|
|
11283
|
-
if (
|
|
11284
|
-
firstName =
|
|
11282
|
+
const name2 = profile.name;
|
|
11283
|
+
if (name2.givenName) {
|
|
11284
|
+
firstName = name2.givenName;
|
|
11285
11285
|
}
|
|
11286
|
-
if (
|
|
11287
|
-
lastName =
|
|
11286
|
+
if (name2.familyName) {
|
|
11287
|
+
lastName = name2.familyName;
|
|
11288
11288
|
}
|
|
11289
11289
|
}
|
|
11290
11290
|
pictureUrl = await getProfilePictureUrl(user, details);
|
|
@@ -11510,10 +11510,10 @@ async function postAuth(passport2, ctx, next) {
|
|
|
11510
11510
|
{ successRedirect: "/", failureRedirect: "/error" },
|
|
11511
11511
|
async (err, tokens) => {
|
|
11512
11512
|
const baseUrl = `/builder/app/${authStateCookie.appId}/data`;
|
|
11513
|
-
await doWithDB(authStateCookie.appId, async (
|
|
11513
|
+
await doWithDB(authStateCookie.appId, async (db2) => {
|
|
11514
11514
|
let datasource2;
|
|
11515
11515
|
try {
|
|
11516
|
-
datasource2 = await
|
|
11516
|
+
datasource2 = await db2.get(authStateCookie.datasourceId);
|
|
11517
11517
|
} catch (err2) {
|
|
11518
11518
|
if (err2.status === 404) {
|
|
11519
11519
|
ctx.redirect(baseUrl);
|
|
@@ -11523,7 +11523,7 @@ async function postAuth(passport2, ctx, next) {
|
|
|
11523
11523
|
datasource2.config = {};
|
|
11524
11524
|
}
|
|
11525
11525
|
datasource2.config.auth = { type: "google", ...tokens };
|
|
11526
|
-
await
|
|
11526
|
+
await db2.put(datasource2);
|
|
11527
11527
|
ctx.redirect(`${baseUrl}/datasource/${authStateCookie.datasourceId}`);
|
|
11528
11528
|
});
|
|
11529
11529
|
}
|
|
@@ -11720,13 +11720,13 @@ async function checkApiKey(apiKey, populateUser) {
|
|
|
11720
11720
|
return doInTenant(tenantId, async () => {
|
|
11721
11721
|
let userId;
|
|
11722
11722
|
try {
|
|
11723
|
-
const
|
|
11723
|
+
const db2 = getGlobalDB();
|
|
11724
11724
|
userId = await queryGlobalView(
|
|
11725
11725
|
"by_api_key" /* BY_API_KEY */,
|
|
11726
11726
|
{
|
|
11727
11727
|
key: apiKey
|
|
11728
11728
|
},
|
|
11729
|
-
|
|
11729
|
+
db2
|
|
11730
11730
|
);
|
|
11731
11731
|
} catch (err) {
|
|
11732
11732
|
userId = void 0;
|
|
@@ -11747,7 +11747,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
|
|
|
11747
11747
|
const noAuthOptions = noAuthPatterns ? buildMatcherRegex(noAuthPatterns) : [];
|
|
11748
11748
|
return async (ctx, next) => {
|
|
11749
11749
|
let publicEndpoint = false;
|
|
11750
|
-
const
|
|
11750
|
+
const version2 = ctx.request.headers["x-budibase-api-version" /* API_VER */];
|
|
11751
11751
|
const found = matches(ctx, noAuthOptions);
|
|
11752
11752
|
if (found) {
|
|
11753
11753
|
publicEndpoint = true;
|
|
@@ -11810,7 +11810,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
|
|
|
11810
11810
|
if (!authenticated) {
|
|
11811
11811
|
authenticated = false;
|
|
11812
11812
|
}
|
|
11813
|
-
finalise(ctx, { authenticated, user, internal, version, publicEndpoint });
|
|
11813
|
+
finalise(ctx, { authenticated, user, internal, version: version2, publicEndpoint });
|
|
11814
11814
|
if (user && user.email) {
|
|
11815
11815
|
return doInUserContext(user, ctx, next);
|
|
11816
11816
|
} else {
|
|
@@ -11825,7 +11825,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
|
|
|
11825
11825
|
ctx.throw(403, err.message);
|
|
11826
11826
|
}
|
|
11827
11827
|
if (opts && opts.publicAllowed || publicEndpoint) {
|
|
11828
|
-
finalise(ctx, { authenticated: false, version, publicEndpoint });
|
|
11828
|
+
finalise(ctx, { authenticated: false, version: version2, publicEndpoint });
|
|
11829
11829
|
return next();
|
|
11830
11830
|
} else {
|
|
11831
11831
|
ctx.throw(err.status || 403, err);
|
|
@@ -12182,8 +12182,8 @@ async function updateUserOAuth(userId, oAuthConfig) {
|
|
|
12182
12182
|
refreshToken: oAuthConfig.refreshToken
|
|
12183
12183
|
};
|
|
12184
12184
|
try {
|
|
12185
|
-
const
|
|
12186
|
-
const dbUser = await
|
|
12185
|
+
const db2 = getGlobalDB();
|
|
12186
|
+
const dbUser = await db2.get(userId);
|
|
12187
12187
|
if (typeof details.refreshToken !== "string") {
|
|
12188
12188
|
delete details.refreshToken;
|
|
12189
12189
|
}
|
|
@@ -12191,7 +12191,7 @@ async function updateUserOAuth(userId, oAuthConfig) {
|
|
|
12191
12191
|
...dbUser.oauth2,
|
|
12192
12192
|
...details
|
|
12193
12193
|
};
|
|
12194
|
-
await
|
|
12194
|
+
await db2.put(dbUser);
|
|
12195
12195
|
await invalidateUser(userId);
|
|
12196
12196
|
} catch (e) {
|
|
12197
12197
|
console.error("Could not update OAuth details for current user", e);
|
|
@@ -12491,7 +12491,7 @@ var upload = async ({
|
|
|
12491
12491
|
filename,
|
|
12492
12492
|
path: path2,
|
|
12493
12493
|
type,
|
|
12494
|
-
metadata
|
|
12494
|
+
metadata: metadata2
|
|
12495
12495
|
}) => {
|
|
12496
12496
|
const extension = filename.split(".").pop();
|
|
12497
12497
|
const fileBytes = import_fs3.default.readFileSync(path2);
|
|
@@ -12507,13 +12507,13 @@ var upload = async ({
|
|
|
12507
12507
|
Body: fileBytes,
|
|
12508
12508
|
ContentType: contentType
|
|
12509
12509
|
};
|
|
12510
|
-
if (
|
|
12511
|
-
for (let key of Object.keys(
|
|
12512
|
-
if (!
|
|
12513
|
-
delete
|
|
12510
|
+
if (metadata2 && typeof metadata2 === "object") {
|
|
12511
|
+
for (let key of Object.keys(metadata2)) {
|
|
12512
|
+
if (!metadata2[key] || typeof metadata2[key] !== "string") {
|
|
12513
|
+
delete metadata2[key];
|
|
12514
12514
|
}
|
|
12515
12515
|
}
|
|
12516
|
-
config.Metadata =
|
|
12516
|
+
config.Metadata = metadata2;
|
|
12517
12517
|
}
|
|
12518
12518
|
return objectStore.upload(config).promise();
|
|
12519
12519
|
};
|
|
@@ -12667,12 +12667,12 @@ var deleteFolder = async (bucketName, folder) => {
|
|
|
12667
12667
|
return deleteFolder(bucketName, folder);
|
|
12668
12668
|
}
|
|
12669
12669
|
};
|
|
12670
|
-
var uploadDirectory = async (bucketName, localPath,
|
|
12670
|
+
var uploadDirectory = async (bucketName, localPath, bucketPath2) => {
|
|
12671
12671
|
bucketName = sanitizeBucket(bucketName);
|
|
12672
12672
|
let uploads = [];
|
|
12673
|
-
const
|
|
12674
|
-
for (let file of
|
|
12675
|
-
const path2 = sanitizeKey((0, import_path3.join)(
|
|
12673
|
+
const files2 = import_fs3.default.readdirSync(localPath, { withFileTypes: true });
|
|
12674
|
+
for (let file of files2) {
|
|
12675
|
+
const path2 = sanitizeKey((0, import_path3.join)(bucketPath2, file.name));
|
|
12676
12676
|
const local = (0, import_path3.join)(localPath, file.name);
|
|
12677
12677
|
if (file.isDirectory()) {
|
|
12678
12678
|
uploads.push(uploadDirectory(bucketName, local, path2));
|
|
@@ -12681,7 +12681,7 @@ var uploadDirectory = async (bucketName, localPath, bucketPath) => {
|
|
|
12681
12681
|
}
|
|
12682
12682
|
}
|
|
12683
12683
|
await Promise.all(uploads);
|
|
12684
|
-
return
|
|
12684
|
+
return files2;
|
|
12685
12685
|
};
|
|
12686
12686
|
var downloadTarballDirect = async (url, path2, headers = {}) => {
|
|
12687
12687
|
path2 = sanitizeKey(path2);
|
|
@@ -12746,12 +12746,12 @@ var getUrl = (s3Key) => {
|
|
|
12746
12746
|
};
|
|
12747
12747
|
|
|
12748
12748
|
// ../backend-core/src/objectStore/buckets/app.ts
|
|
12749
|
-
var clientLibraryUrl = (appId,
|
|
12749
|
+
var clientLibraryUrl = (appId, version2) => {
|
|
12750
12750
|
if (environment_default2.isProd()) {
|
|
12751
12751
|
let file = `${sanitizeKey(appId)}/budibase-client.js`;
|
|
12752
12752
|
if (environment_default2.CLOUDFRONT_CDN) {
|
|
12753
|
-
if (
|
|
12754
|
-
file += `?v=${
|
|
12753
|
+
if (version2) {
|
|
12754
|
+
file += `?v=${version2}`;
|
|
12755
12755
|
}
|
|
12756
12756
|
return getUrl(file);
|
|
12757
12757
|
} else {
|
|
@@ -12772,8 +12772,8 @@ var getAppFileUrl = (s3Key) => {
|
|
|
12772
12772
|
// ../backend-core/src/objectStore/buckets/global.ts
|
|
12773
12773
|
init_environment2();
|
|
12774
12774
|
init_context2();
|
|
12775
|
-
var getGlobalFileUrl = (type,
|
|
12776
|
-
let file = getGlobalFileS3Key(type,
|
|
12775
|
+
var getGlobalFileUrl = (type, name2, etag) => {
|
|
12776
|
+
let file = getGlobalFileS3Key(type, name2);
|
|
12777
12777
|
if (environment_default2.CLOUDFRONT_CDN) {
|
|
12778
12778
|
if (etag) {
|
|
12779
12779
|
file = `${file}?etag=${etag}`;
|
|
@@ -12783,8 +12783,8 @@ var getGlobalFileUrl = (type, name, etag) => {
|
|
|
12783
12783
|
return getPresignedUrl(environment_default2.GLOBAL_BUCKET_NAME, file);
|
|
12784
12784
|
}
|
|
12785
12785
|
};
|
|
12786
|
-
var getGlobalFileS3Key = (type,
|
|
12787
|
-
let file = `${type}/${
|
|
12786
|
+
var getGlobalFileS3Key = (type, name2) => {
|
|
12787
|
+
let file = `${type}/${name2}`;
|
|
12788
12788
|
if (environment_default2.MULTI_TENANCY) {
|
|
12789
12789
|
const tenantId = getTenantId();
|
|
12790
12790
|
file = `${tenantId}/${file}`;
|
|
@@ -12827,11 +12827,11 @@ var getPluginJSKey = (plugin) => {
|
|
|
12827
12827
|
return getPluginS3Key(plugin, "plugin.min.js");
|
|
12828
12828
|
};
|
|
12829
12829
|
var getPluginIconKey = (plugin) => {
|
|
12830
|
-
const
|
|
12831
|
-
if (!
|
|
12830
|
+
const iconFileName2 = plugin.iconUrl ? "icon.svg" : plugin.iconFileName;
|
|
12831
|
+
if (!iconFileName2) {
|
|
12832
12832
|
return;
|
|
12833
12833
|
}
|
|
12834
|
-
return getPluginS3Key(plugin,
|
|
12834
|
+
return getPluginS3Key(plugin, iconFileName2);
|
|
12835
12835
|
};
|
|
12836
12836
|
var getPluginS3Key = (plugin, fileName) => {
|
|
12837
12837
|
const s3Key = getPluginS3Dir(plugin.name);
|
|
@@ -13384,18 +13384,18 @@ function finaliseExternalTables(tables, entities) {
|
|
|
13384
13384
|
let finalTables = {};
|
|
13385
13385
|
const errors = {};
|
|
13386
13386
|
const tableIds = Object.values(tables).map((table) => table._id);
|
|
13387
|
-
for (let [
|
|
13387
|
+
for (let [name2, table] of Object.entries(tables)) {
|
|
13388
13388
|
const schemaFields = Object.keys(table.schema);
|
|
13389
13389
|
if (table.primary == null || table.primary.length === 0) {
|
|
13390
|
-
errors[
|
|
13390
|
+
errors[name2] = "no_key" /* NO_KEY */;
|
|
13391
13391
|
continue;
|
|
13392
13392
|
} else if (schemaFields.find(
|
|
13393
13393
|
(field) => invalidColumns.includes(field)
|
|
13394
13394
|
)) {
|
|
13395
|
-
errors[
|
|
13395
|
+
errors[name2] = "invalid_column" /* INVALID_COLUMN */;
|
|
13396
13396
|
continue;
|
|
13397
13397
|
}
|
|
13398
|
-
finalTables[
|
|
13398
|
+
finalTables[name2] = copyExistingPropsOver(name2, table, entities, tableIds);
|
|
13399
13399
|
}
|
|
13400
13400
|
finalTables = Object.entries(finalTables).sort(([a], [b]) => a.localeCompare(b)).reduce((r, [k, v]) => ({ ...r, [k]: v }), {});
|
|
13401
13401
|
return { tables: finalTables, errors };
|
|
@@ -15040,8 +15040,8 @@ var MongoIntegration = class {
|
|
|
15040
15040
|
async create(query) {
|
|
15041
15041
|
try {
|
|
15042
15042
|
await this.connect();
|
|
15043
|
-
const
|
|
15044
|
-
const collection =
|
|
15043
|
+
const db2 = this.client.db(this.config.db);
|
|
15044
|
+
const collection = db2.collection(query.extra.collection);
|
|
15045
15045
|
let json = this.createObjectIds(query.json);
|
|
15046
15046
|
switch (query.extra.actionType) {
|
|
15047
15047
|
case "insertOne": {
|
|
@@ -15066,8 +15066,8 @@ var MongoIntegration = class {
|
|
|
15066
15066
|
async read(query) {
|
|
15067
15067
|
try {
|
|
15068
15068
|
await this.connect();
|
|
15069
|
-
const
|
|
15070
|
-
const collection =
|
|
15069
|
+
const db2 = this.client.db(this.config.db);
|
|
15070
|
+
const collection = db2.collection(query.extra.collection);
|
|
15071
15071
|
let json = this.createObjectIds(query.json);
|
|
15072
15072
|
switch (query.extra.actionType) {
|
|
15073
15073
|
case "find": {
|
|
@@ -15109,8 +15109,8 @@ var MongoIntegration = class {
|
|
|
15109
15109
|
async update(query) {
|
|
15110
15110
|
try {
|
|
15111
15111
|
await this.connect();
|
|
15112
|
-
const
|
|
15113
|
-
const collection =
|
|
15112
|
+
const db2 = this.client.db(this.config.db);
|
|
15113
|
+
const collection = db2.collection(query.extra.collection);
|
|
15114
15114
|
let queryJson = query.json;
|
|
15115
15115
|
if (typeof queryJson === "string") {
|
|
15116
15116
|
queryJson = this.parseQueryParams(queryJson, "update");
|
|
@@ -15147,8 +15147,8 @@ var MongoIntegration = class {
|
|
|
15147
15147
|
async delete(query) {
|
|
15148
15148
|
try {
|
|
15149
15149
|
await this.connect();
|
|
15150
|
-
const
|
|
15151
|
-
const collection =
|
|
15150
|
+
const db2 = this.client.db(this.config.db);
|
|
15151
|
+
const collection = db2.collection(query.extra.collection);
|
|
15152
15152
|
let queryJson = query.json;
|
|
15153
15153
|
if (typeof queryJson === "string") {
|
|
15154
15154
|
queryJson = this.parseQueryParams(queryJson, "delete");
|
|
@@ -15184,25 +15184,25 @@ var MongoIntegration = class {
|
|
|
15184
15184
|
var _a;
|
|
15185
15185
|
try {
|
|
15186
15186
|
await this.connect();
|
|
15187
|
-
const
|
|
15188
|
-
const collection =
|
|
15187
|
+
const db2 = this.client.db(this.config.db);
|
|
15188
|
+
const collection = db2.collection(query.extra.collection);
|
|
15189
15189
|
let response = [];
|
|
15190
15190
|
if (((_a = query.extra) == null ? void 0 : _a.actionType) === "pipeline") {
|
|
15191
|
-
for await (const
|
|
15191
|
+
for await (const doc2 of collection.aggregate(
|
|
15192
15192
|
query.steps.map(({ key, value }) => {
|
|
15193
15193
|
let temp = {};
|
|
15194
15194
|
temp[key] = JSON.parse(value.value);
|
|
15195
15195
|
return this.createObjectIds(temp);
|
|
15196
15196
|
})
|
|
15197
15197
|
)) {
|
|
15198
|
-
response.push(
|
|
15198
|
+
response.push(doc2);
|
|
15199
15199
|
}
|
|
15200
15200
|
} else {
|
|
15201
15201
|
const stages = query.json;
|
|
15202
|
-
for await (const
|
|
15202
|
+
for await (const doc2 of collection.aggregate(
|
|
15203
15203
|
stages ? this.createObjectIds(stages) : []
|
|
15204
15204
|
)) {
|
|
15205
|
-
response.push(
|
|
15205
|
+
response.push(doc2);
|
|
15206
15206
|
}
|
|
15207
15207
|
}
|
|
15208
15208
|
return response;
|
|
@@ -15502,9 +15502,9 @@ var CouchDBIntegration = class {
|
|
|
15502
15502
|
});
|
|
15503
15503
|
}
|
|
15504
15504
|
async delete(query) {
|
|
15505
|
-
const
|
|
15505
|
+
const doc2 = await this.query("get", "Cannot find doc to be deleted", query);
|
|
15506
15506
|
return this.query("remove", "Error deleting couchDB document", {
|
|
15507
|
-
json:
|
|
15507
|
+
json: doc2
|
|
15508
15508
|
});
|
|
15509
15509
|
}
|
|
15510
15510
|
};
|
|
@@ -15683,7 +15683,7 @@ var SqlServerIntegration = class extends sql_default {
|
|
|
15683
15683
|
throw "Unable to get list of tables in database";
|
|
15684
15684
|
}
|
|
15685
15685
|
const schema = this.config.schema || DEFAULT_SCHEMA;
|
|
15686
|
-
const tableNames = tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((
|
|
15686
|
+
const tableNames = tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name2) => this.MASTER_TABLES.indexOf(name2) === -1);
|
|
15687
15687
|
const tables = {};
|
|
15688
15688
|
for (let tableName of tableNames) {
|
|
15689
15689
|
const definition = await this.runSQL(this.getDefinitionSQL(tableName));
|
|
@@ -15698,16 +15698,16 @@ var SqlServerIntegration = class extends sql_default {
|
|
|
15698
15698
|
const requiredColumns = columns.filter((col) => col.IS_NULLABLE === "NO").map((col) => col.COLUMN_NAME);
|
|
15699
15699
|
let schema2 = {};
|
|
15700
15700
|
for (let def of definition) {
|
|
15701
|
-
const
|
|
15702
|
-
if (typeof
|
|
15701
|
+
const name2 = def.COLUMN_NAME;
|
|
15702
|
+
if (typeof name2 !== "string") {
|
|
15703
15703
|
continue;
|
|
15704
15704
|
}
|
|
15705
15705
|
const hasDefault = def.COLUMN_DEFAULT;
|
|
15706
|
-
const isAuto = !!autoColumns.find((col) => col ===
|
|
15707
|
-
const required = !!requiredColumns.find((col) => col ===
|
|
15708
|
-
schema2[
|
|
15706
|
+
const isAuto = !!autoColumns.find((col) => col === name2);
|
|
15707
|
+
const required = !!requiredColumns.find((col) => col === name2);
|
|
15708
|
+
schema2[name2] = {
|
|
15709
15709
|
autocolumn: isAuto,
|
|
15710
|
-
name,
|
|
15710
|
+
name: name2,
|
|
15711
15711
|
constraints: {
|
|
15712
15712
|
presence: required && !isAuto && !hasDefault
|
|
15713
15713
|
},
|
|
@@ -15729,7 +15729,7 @@ var SqlServerIntegration = class extends sql_default {
|
|
|
15729
15729
|
async queryTableNames() {
|
|
15730
15730
|
let tableInfo = await this.runSQL(this.TABLES_SQL);
|
|
15731
15731
|
const schema = this.config.schema || DEFAULT_SCHEMA;
|
|
15732
|
-
return tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((
|
|
15732
|
+
return tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name2) => this.MASTER_TABLES.indexOf(name2) === -1);
|
|
15733
15733
|
}
|
|
15734
15734
|
async getTableNames() {
|
|
15735
15735
|
await this.connect();
|
|
@@ -16214,7 +16214,12 @@ function bindingTypeCoerce(bindings) {
|
|
|
16214
16214
|
if (matches2 && matches2[0] !== "" && !isNaN(Number(matches2[0]))) {
|
|
16215
16215
|
bindings[i] = parseFloat(binding);
|
|
16216
16216
|
} else if (/^\d/.test(binding) && (0, import_dayjs.default)(binding).isValid() && !binding.includes(",")) {
|
|
16217
|
-
|
|
16217
|
+
let value;
|
|
16218
|
+
value = new Date(binding);
|
|
16219
|
+
if (isNaN(value)) {
|
|
16220
|
+
value = binding;
|
|
16221
|
+
}
|
|
16222
|
+
bindings[i] = value;
|
|
16218
16223
|
}
|
|
16219
16224
|
}
|
|
16220
16225
|
return bindings;
|
|
@@ -17119,11 +17124,11 @@ var runLuceneQuery = (docs, query) => {
|
|
|
17119
17124
|
return docs;
|
|
17120
17125
|
}
|
|
17121
17126
|
query = cleanupQuery(query);
|
|
17122
|
-
const match = (type, failFn) => (
|
|
17127
|
+
const match = (type, failFn) => (doc2) => {
|
|
17123
17128
|
const filters = Object.entries(query[type] || {});
|
|
17124
17129
|
for (let i = 0; i < filters.length; i++) {
|
|
17125
17130
|
const [key, testValue] = filters[i];
|
|
17126
|
-
const docValue = deepGet(
|
|
17131
|
+
const docValue = deepGet(doc2, removeKeyNumbering2(key));
|
|
17127
17132
|
if (failFn(docValue, testValue)) {
|
|
17128
17133
|
return false;
|
|
17129
17134
|
}
|
|
@@ -17184,8 +17189,8 @@ var runLuceneQuery = (docs, query) => {
|
|
|
17184
17189
|
return testValue == null ? void 0 : testValue.every((item) => docValue == null ? void 0 : docValue.includes(item));
|
|
17185
17190
|
}
|
|
17186
17191
|
);
|
|
17187
|
-
const docMatch = (
|
|
17188
|
-
return stringMatch(
|
|
17192
|
+
const docMatch = (doc2) => {
|
|
17193
|
+
return stringMatch(doc2) && fuzzyMatch(doc2) && rangeMatch(doc2) && equalMatch(doc2) && notEqualMatch(doc2) && emptyMatch(doc2) && notEmptyMatch(doc2) && oneOf(doc2) && contains(doc2) && containsAny(doc2) && notContains(doc2);
|
|
17189
17194
|
};
|
|
17190
17195
|
return docs.filter(docMatch);
|
|
17191
17196
|
};
|
|
@@ -17496,13 +17501,13 @@ var GoogleSheetsIntegration = class {
|
|
|
17496
17501
|
}
|
|
17497
17502
|
return rowObject;
|
|
17498
17503
|
}
|
|
17499
|
-
async createTable(
|
|
17500
|
-
if (!
|
|
17504
|
+
async createTable(name2) {
|
|
17505
|
+
if (!name2) {
|
|
17501
17506
|
throw new Error("Must provide name for new sheet.");
|
|
17502
17507
|
}
|
|
17503
17508
|
try {
|
|
17504
17509
|
await this.connect();
|
|
17505
|
-
return await this.client.addSheet({ title:
|
|
17510
|
+
return await this.client.addSheet({ title: name2, headerValues: [name2] });
|
|
17506
17511
|
} catch (err) {
|
|
17507
17512
|
console.error("Error creating new table in google sheets", err);
|
|
17508
17513
|
throw err;
|
|
@@ -17823,7 +17828,7 @@ var FirebaseIntegration = class {
|
|
|
17823
17828
|
snapshot = await collectionRef.get();
|
|
17824
17829
|
}
|
|
17825
17830
|
const result = [];
|
|
17826
|
-
snapshot.forEach((
|
|
17831
|
+
snapshot.forEach((doc2) => result.push(doc2.data()));
|
|
17827
17832
|
return result;
|
|
17828
17833
|
} catch (err) {
|
|
17829
17834
|
console.error("Error querying Firestore", err);
|
|
@@ -18511,13 +18516,13 @@ var import_path6 = require("path");
|
|
|
18511
18516
|
var DATASOURCE_PATH = (0, import_path6.join)(budibaseTempDir2(), "datasource");
|
|
18512
18517
|
var AUTOMATION_PATH = (0, import_path6.join)(budibaseTempDir2(), "automation");
|
|
18513
18518
|
var getPluginMetadata = async (path2) => {
|
|
18514
|
-
let
|
|
18519
|
+
let metadata2 = {};
|
|
18515
18520
|
try {
|
|
18516
18521
|
const pkg2 = import_fs5.default.readFileSync((0, import_path6.join)(path2, "package.json"), "utf8");
|
|
18517
18522
|
const schema = import_fs5.default.readFileSync((0, import_path6.join)(path2, "schema.json"), "utf8");
|
|
18518
|
-
|
|
18519
|
-
|
|
18520
|
-
if (!
|
|
18523
|
+
metadata2.schema = JSON.parse(schema);
|
|
18524
|
+
metadata2.package = JSON.parse(pkg2);
|
|
18525
|
+
if (!metadata2.package.name || !metadata2.package.version || !metadata2.package.description) {
|
|
18521
18526
|
throw new Error(
|
|
18522
18527
|
"package.json is missing one of 'name', 'version' or 'description'."
|
|
18523
18528
|
);
|
|
@@ -18527,11 +18532,11 @@ var getPluginMetadata = async (path2) => {
|
|
|
18527
18532
|
`Unable to process schema.json/package.json in plugin. ${err.message}`
|
|
18528
18533
|
);
|
|
18529
18534
|
}
|
|
18530
|
-
return { metadata, directory: path2 };
|
|
18535
|
+
return { metadata: metadata2, directory: path2 };
|
|
18531
18536
|
};
|
|
18532
18537
|
async function getPluginImpl(path2, plugin) {
|
|
18533
18538
|
var _a;
|
|
18534
|
-
const
|
|
18539
|
+
const hash3 = (_a = plugin.schema) == null ? void 0 : _a.hash;
|
|
18535
18540
|
if (!import_fs5.default.existsSync(path2)) {
|
|
18536
18541
|
import_fs5.default.mkdirSync(path2);
|
|
18537
18542
|
}
|
|
@@ -18539,7 +18544,7 @@ async function getPluginImpl(path2, plugin) {
|
|
|
18539
18544
|
const metadataName = `${filename}.bbmetadata`;
|
|
18540
18545
|
if (import_fs5.default.existsSync(filename)) {
|
|
18541
18546
|
const currentHash = import_fs5.default.readFileSync(metadataName, "utf8");
|
|
18542
|
-
if (currentHash ===
|
|
18547
|
+
if (currentHash === hash3) {
|
|
18543
18548
|
return require(filename);
|
|
18544
18549
|
} else {
|
|
18545
18550
|
console.log(`Updating plugin: ${plugin.name}`);
|
|
@@ -18553,7 +18558,7 @@ async function getPluginImpl(path2, plugin) {
|
|
|
18553
18558
|
pluginKey
|
|
18554
18559
|
);
|
|
18555
18560
|
import_fs5.default.writeFileSync(filename, pluginJs);
|
|
18556
|
-
import_fs5.default.writeFileSync(metadataName,
|
|
18561
|
+
import_fs5.default.writeFileSync(metadataName, hash3);
|
|
18557
18562
|
return require(filename);
|
|
18558
18563
|
}
|
|
18559
18564
|
var getDatasourcePlugin = async (plugin) => {
|
|
@@ -18561,9 +18566,9 @@ var getDatasourcePlugin = async (plugin) => {
|
|
|
18561
18566
|
};
|
|
18562
18567
|
|
|
18563
18568
|
// src/utilities/fileSystem/template.ts
|
|
18564
|
-
var downloadTemplate = async (type,
|
|
18569
|
+
var downloadTemplate = async (type, name2) => {
|
|
18565
18570
|
const DEFAULT_TEMPLATES_BUCKET = "prod-budi-templates.s3-eu-west-1.amazonaws.com";
|
|
18566
|
-
const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${
|
|
18571
|
+
const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${name2}.tar.gz`;
|
|
18567
18572
|
return objectStore_exports2.downloadTarball(
|
|
18568
18573
|
templateUrl,
|
|
18569
18574
|
ObjectStoreBuckets2.TEMPLATES,
|
|
@@ -18593,7 +18598,7 @@ var import_path7 = require("path");
|
|
|
18593
18598
|
var uuid3 = require("uuid/v4");
|
|
18594
18599
|
var tar3 = require("tar");
|
|
18595
18600
|
var MemoryStream = require("memorystream");
|
|
18596
|
-
function tarFilesToTmp(tmpDir,
|
|
18601
|
+
function tarFilesToTmp(tmpDir, files2) {
|
|
18597
18602
|
const exportFile = (0, import_path7.join)(budibaseTempDir2(), `${uuid3()}.tar.gz`);
|
|
18598
18603
|
tar3.create(
|
|
18599
18604
|
{
|
|
@@ -18603,7 +18608,7 @@ function tarFilesToTmp(tmpDir, files) {
|
|
|
18603
18608
|
recursive: true,
|
|
18604
18609
|
cwd: tmpDir
|
|
18605
18610
|
},
|
|
18606
|
-
|
|
18611
|
+
files2
|
|
18607
18612
|
);
|
|
18608
18613
|
return exportFile;
|
|
18609
18614
|
}
|
|
@@ -18614,11 +18619,11 @@ async function exportDB(dbName, opts = {}) {
|
|
|
18614
18619
|
batch_limit: 5,
|
|
18615
18620
|
style: "main_only"
|
|
18616
18621
|
};
|
|
18617
|
-
return db_exports.doWithDB(dbName, async (
|
|
18622
|
+
return db_exports.doWithDB(dbName, async (db2) => {
|
|
18618
18623
|
if (opts == null ? void 0 : opts.exportPath) {
|
|
18619
18624
|
const path2 = opts == null ? void 0 : opts.exportPath;
|
|
18620
18625
|
const writeStream = import_fs6.default.createWriteStream(path2);
|
|
18621
|
-
await
|
|
18626
|
+
await db2.dump(writeStream, exportOpts);
|
|
18622
18627
|
return path2;
|
|
18623
18628
|
} else {
|
|
18624
18629
|
const memStream = new MemoryStream();
|
|
@@ -18626,7 +18631,7 @@ async function exportDB(dbName, opts = {}) {
|
|
|
18626
18631
|
memStream.on("data", (chunk) => {
|
|
18627
18632
|
appString += chunk.toString();
|
|
18628
18633
|
});
|
|
18629
|
-
await
|
|
18634
|
+
await db2.dump(memStream, exportOpts);
|
|
18630
18635
|
return appString;
|
|
18631
18636
|
}
|
|
18632
18637
|
});
|
|
@@ -18639,7 +18644,7 @@ function defineFilter(excludeRows, excludeLogs) {
|
|
|
18639
18644
|
if (excludeLogs) {
|
|
18640
18645
|
ids.push(AUTOMATION_LOG_PREFIX);
|
|
18641
18646
|
}
|
|
18642
|
-
return (
|
|
18647
|
+
return (doc2) => !ids.map((key) => doc2._id.includes(key)).reduce((prev, curr) => prev || curr);
|
|
18643
18648
|
}
|
|
18644
18649
|
async function exportApp(appId, config) {
|
|
18645
18650
|
const prodAppId = db_exports.getProdAppID(appId);
|
|
@@ -18718,12 +18723,12 @@ function rewriteAttachmentUrl(appId, attachment) {
|
|
|
18718
18723
|
// calculated on retrieval using key
|
|
18719
18724
|
};
|
|
18720
18725
|
}
|
|
18721
|
-
async function updateAttachmentColumns(prodAppId,
|
|
18722
|
-
const tables = await sdk_default.tables.getAllInternalTables(
|
|
18726
|
+
async function updateAttachmentColumns(prodAppId, db2) {
|
|
18727
|
+
const tables = await sdk_default.tables.getAllInternalTables(db2);
|
|
18723
18728
|
let updatedRows = [];
|
|
18724
18729
|
for (let table of tables) {
|
|
18725
18730
|
const { rows: rows2, columns } = await sdk_default.rows.getRowsWithAttachments(
|
|
18726
|
-
|
|
18731
|
+
db2.name,
|
|
18727
18732
|
table
|
|
18728
18733
|
);
|
|
18729
18734
|
updatedRows = updatedRows.concat(
|
|
@@ -18739,11 +18744,11 @@ async function updateAttachmentColumns(prodAppId, db) {
|
|
|
18739
18744
|
})
|
|
18740
18745
|
);
|
|
18741
18746
|
}
|
|
18742
|
-
await
|
|
18747
|
+
await db2.bulkDocs(updatedRows);
|
|
18743
18748
|
}
|
|
18744
|
-
async function updateAutomations(prodAppId,
|
|
18749
|
+
async function updateAutomations(prodAppId, db2) {
|
|
18745
18750
|
var _a;
|
|
18746
|
-
const automations2 = (await
|
|
18751
|
+
const automations2 = (await db2.allDocs(
|
|
18747
18752
|
getAutomationParams(null, {
|
|
18748
18753
|
include_docs: true
|
|
18749
18754
|
})
|
|
@@ -18762,7 +18767,7 @@ async function updateAutomations(prodAppId, db) {
|
|
|
18762
18767
|
automation.appId = devAppId;
|
|
18763
18768
|
toSave.push(automation);
|
|
18764
18769
|
}
|
|
18765
|
-
await
|
|
18770
|
+
await db2.bulkDocs(toSave);
|
|
18766
18771
|
}
|
|
18767
18772
|
async function getTemplateStream(template) {
|
|
18768
18773
|
if (template.file && template.file.type !== "text/plain") {
|
|
@@ -18771,9 +18776,9 @@ async function getTemplateStream(template) {
|
|
|
18771
18776
|
if (template.file) {
|
|
18772
18777
|
return import_fs7.default.createReadStream(template.file.path);
|
|
18773
18778
|
} else if (template.key) {
|
|
18774
|
-
const [type,
|
|
18775
|
-
const tmpPath = await downloadTemplate(type,
|
|
18776
|
-
return import_fs7.default.createReadStream((0, import_path8.join)(tmpPath,
|
|
18779
|
+
const [type, name2] = template.key.split("/");
|
|
18780
|
+
const tmpPath = await downloadTemplate(type, name2);
|
|
18781
|
+
return import_fs7.default.createReadStream((0, import_path8.join)(tmpPath, name2, "db", "dump.txt"));
|
|
18777
18782
|
}
|
|
18778
18783
|
}
|
|
18779
18784
|
function untarFile(file) {
|
|
@@ -18792,7 +18797,7 @@ function getGlobalDBFile(tmpPath) {
|
|
|
18792
18797
|
function getListOfAppsInMulti(tmpPath) {
|
|
18793
18798
|
return import_fs7.default.readdirSync(tmpPath).filter((dir) => dir !== GLOBAL_DB_EXPORT_FILE);
|
|
18794
18799
|
}
|
|
18795
|
-
async function importApp(appId,
|
|
18800
|
+
async function importApp(appId, db2, template) {
|
|
18796
18801
|
var _a, _b;
|
|
18797
18802
|
let prodAppId = db_exports.getProdAppID(appId);
|
|
18798
18803
|
let dbStream;
|
|
@@ -18830,12 +18835,12 @@ async function importApp(appId, db, template) {
|
|
|
18830
18835
|
} else {
|
|
18831
18836
|
dbStream = await getTemplateStream(template);
|
|
18832
18837
|
}
|
|
18833
|
-
const { ok } = await
|
|
18838
|
+
const { ok } = await db2.load(dbStream);
|
|
18834
18839
|
if (!ok) {
|
|
18835
18840
|
throw "Error loading database dump from template.";
|
|
18836
18841
|
}
|
|
18837
|
-
await updateAttachmentColumns(prodAppId,
|
|
18838
|
-
await updateAutomations(prodAppId,
|
|
18842
|
+
await updateAttachmentColumns(prodAppId, db2);
|
|
18843
|
+
await updateAutomations(prodAppId, db2);
|
|
18839
18844
|
return ok;
|
|
18840
18845
|
}
|
|
18841
18846
|
|
|
@@ -18847,54 +18852,54 @@ __export(statistics_exports, {
|
|
|
18847
18852
|
calculateDatasourceCount: () => calculateDatasourceCount,
|
|
18848
18853
|
calculateScreenCount: () => calculateScreenCount
|
|
18849
18854
|
});
|
|
18850
|
-
async function runInContext(appId, cb,
|
|
18851
|
-
if (
|
|
18852
|
-
return cb(
|
|
18855
|
+
async function runInContext(appId, cb, db2) {
|
|
18856
|
+
if (db2) {
|
|
18857
|
+
return cb(db2);
|
|
18853
18858
|
} else {
|
|
18854
18859
|
const devAppId = db_exports.getDevAppID(appId);
|
|
18855
18860
|
return context_exports.doInAppContext(devAppId, () => {
|
|
18856
|
-
const
|
|
18857
|
-
return cb(
|
|
18861
|
+
const db3 = context_exports.getAppDB();
|
|
18862
|
+
return cb(db3);
|
|
18858
18863
|
});
|
|
18859
18864
|
}
|
|
18860
18865
|
}
|
|
18861
|
-
async function calculateDatasourceCount(appId,
|
|
18866
|
+
async function calculateDatasourceCount(appId, db2) {
|
|
18862
18867
|
return runInContext(
|
|
18863
18868
|
appId,
|
|
18864
|
-
async (
|
|
18865
|
-
const datasourceList = await
|
|
18866
|
-
const tableList = await
|
|
18869
|
+
async (db3) => {
|
|
18870
|
+
const datasourceList = await db3.allDocs(getDatasourceParams());
|
|
18871
|
+
const tableList = await db3.allDocs(getTableParams());
|
|
18867
18872
|
return datasourceList.rows.length + tableList.rows.length;
|
|
18868
18873
|
},
|
|
18869
|
-
|
|
18874
|
+
db2
|
|
18870
18875
|
);
|
|
18871
18876
|
}
|
|
18872
|
-
async function calculateAutomationCount(appId,
|
|
18877
|
+
async function calculateAutomationCount(appId, db2) {
|
|
18873
18878
|
return runInContext(
|
|
18874
18879
|
appId,
|
|
18875
|
-
async (
|
|
18876
|
-
const automationList = await
|
|
18880
|
+
async (db3) => {
|
|
18881
|
+
const automationList = await db3.allDocs(getAutomationParams());
|
|
18877
18882
|
return automationList.rows.length;
|
|
18878
18883
|
},
|
|
18879
|
-
|
|
18884
|
+
db2
|
|
18880
18885
|
);
|
|
18881
18886
|
}
|
|
18882
|
-
async function calculateScreenCount(appId,
|
|
18887
|
+
async function calculateScreenCount(appId, db2) {
|
|
18883
18888
|
return runInContext(
|
|
18884
18889
|
appId,
|
|
18885
|
-
async (
|
|
18886
|
-
const screenList = await
|
|
18890
|
+
async (db3) => {
|
|
18891
|
+
const screenList = await db3.allDocs(getScreenParams());
|
|
18887
18892
|
return screenList.rows.length;
|
|
18888
18893
|
},
|
|
18889
|
-
|
|
18894
|
+
db2
|
|
18890
18895
|
);
|
|
18891
18896
|
}
|
|
18892
18897
|
async function calculateBackupStats(appId) {
|
|
18893
|
-
return runInContext(appId, async (
|
|
18898
|
+
return runInContext(appId, async (db2) => {
|
|
18894
18899
|
const promises = [];
|
|
18895
|
-
promises.push(calculateDatasourceCount(appId,
|
|
18896
|
-
promises.push(calculateAutomationCount(appId,
|
|
18897
|
-
promises.push(calculateScreenCount(appId,
|
|
18900
|
+
promises.push(calculateDatasourceCount(appId, db2));
|
|
18901
|
+
promises.push(calculateAutomationCount(appId, db2));
|
|
18902
|
+
promises.push(calculateScreenCount(appId, db2));
|
|
18898
18903
|
const responses = await Promise.all(promises);
|
|
18899
18904
|
return {
|
|
18900
18905
|
datasources: responses[0],
|
|
@@ -19140,11 +19145,11 @@ var setCurrentMonth = (usage) => {
|
|
|
19140
19145
|
}
|
|
19141
19146
|
usage.monthly.current = usage.monthly[currentMonth];
|
|
19142
19147
|
};
|
|
19143
|
-
var getBreakdownName = (
|
|
19144
|
-
if (!id || !
|
|
19148
|
+
var getBreakdownName = (name2, id) => {
|
|
19149
|
+
if (!id || !name2) {
|
|
19145
19150
|
return;
|
|
19146
19151
|
}
|
|
19147
|
-
switch (
|
|
19152
|
+
switch (name2) {
|
|
19148
19153
|
case "automations" /* AUTOMATIONS */:
|
|
19149
19154
|
return "automations" /* AUTOMATIONS */;
|
|
19150
19155
|
case "queries" /* QUERIES */:
|
|
@@ -19158,11 +19163,11 @@ var getDB2 = () => {
|
|
|
19158
19163
|
return new Writethrough2(tenancy.getGlobalDB());
|
|
19159
19164
|
};
|
|
19160
19165
|
var bustCache2 = async () => {
|
|
19161
|
-
const
|
|
19166
|
+
const db2 = getDB2();
|
|
19162
19167
|
try {
|
|
19163
|
-
const usage = await
|
|
19168
|
+
const usage = await db2.get(db_exports.StaticDatabases.GLOBAL.docs.usageQuota);
|
|
19164
19169
|
if (usage == null ? void 0 : usage._rev) {
|
|
19165
|
-
await
|
|
19170
|
+
await db2.remove(
|
|
19166
19171
|
db_exports.StaticDatabases.GLOBAL.docs.usageQuota,
|
|
19167
19172
|
usage == null ? void 0 : usage._rev
|
|
19168
19173
|
);
|
|
@@ -19174,16 +19179,16 @@ var bustCache2 = async () => {
|
|
|
19174
19179
|
}
|
|
19175
19180
|
};
|
|
19176
19181
|
var getQuotaUsage = async () => {
|
|
19177
|
-
const
|
|
19182
|
+
const db2 = getDB2();
|
|
19178
19183
|
let usage;
|
|
19179
19184
|
try {
|
|
19180
|
-
usage = await
|
|
19185
|
+
usage = await db2.get(db_exports.StaticDatabases.GLOBAL.docs.usageQuota);
|
|
19181
19186
|
setCurrentMonth(usage);
|
|
19182
19187
|
setQuotaReset(usage);
|
|
19183
19188
|
} catch (err) {
|
|
19184
19189
|
if (err.status === 404) {
|
|
19185
19190
|
usage = generateNewQuotaUsage();
|
|
19186
|
-
const response = await
|
|
19191
|
+
const response = await db2.put(usage);
|
|
19187
19192
|
usage._rev = response.rev;
|
|
19188
19193
|
} else {
|
|
19189
19194
|
throw err;
|
|
@@ -19198,17 +19203,17 @@ var getQuotaUsage = async () => {
|
|
|
19198
19203
|
delete usage.usageQuota.developers;
|
|
19199
19204
|
return usage;
|
|
19200
19205
|
};
|
|
19201
|
-
var setUsage = async (value,
|
|
19202
|
-
return setAllUsage(
|
|
19206
|
+
var setUsage = async (value, name2, type) => {
|
|
19207
|
+
return setAllUsage(name2, type, { total: value });
|
|
19203
19208
|
};
|
|
19204
|
-
var setUsagePerApp = async (appValues,
|
|
19205
|
-
const
|
|
19209
|
+
var setUsagePerApp = async (appValues, name2, type) => {
|
|
19210
|
+
const db2 = getDB2();
|
|
19206
19211
|
let quotaUsage = await getQuotaUsage();
|
|
19207
19212
|
const total = Object.values(appValues).reduce((sum, num) => sum + num, 0);
|
|
19208
19213
|
for (let [appId, value] of Object.entries(appValues)) {
|
|
19209
19214
|
quotaUsage = coreUsageUpdate(
|
|
19210
19215
|
quotaUsage,
|
|
19211
|
-
|
|
19216
|
+
name2,
|
|
19212
19217
|
type,
|
|
19213
19218
|
{
|
|
19214
19219
|
total,
|
|
@@ -19219,12 +19224,12 @@ var setUsagePerApp = async (appValues, name, type) => {
|
|
|
19219
19224
|
}
|
|
19220
19225
|
);
|
|
19221
19226
|
}
|
|
19222
|
-
const response = await
|
|
19227
|
+
const response = await db2.put(quotaUsage);
|
|
19223
19228
|
quotaUsage._rev = response.rev;
|
|
19224
19229
|
return quotaUsage;
|
|
19225
19230
|
};
|
|
19226
|
-
var setBreakdown = (monthUsage,
|
|
19227
|
-
const breakdownName = getBreakdownName(
|
|
19231
|
+
var setBreakdown = (monthUsage, name2, id, values) => {
|
|
19232
|
+
const breakdownName = getBreakdownName(name2, id);
|
|
19228
19233
|
if (!breakdownName || !(values == null ? void 0 : values.breakdown)) {
|
|
19229
19234
|
return monthUsage;
|
|
19230
19235
|
}
|
|
@@ -19233,7 +19238,7 @@ var setBreakdown = (monthUsage, name, id, values) => {
|
|
|
19233
19238
|
}
|
|
19234
19239
|
if (!monthUsage.breakdown[breakdownName]) {
|
|
19235
19240
|
monthUsage.breakdown[breakdownName] = {
|
|
19236
|
-
parent:
|
|
19241
|
+
parent: name2,
|
|
19237
19242
|
values: {}
|
|
19238
19243
|
};
|
|
19239
19244
|
}
|
|
@@ -19241,14 +19246,14 @@ var setBreakdown = (monthUsage, name, id, values) => {
|
|
|
19241
19246
|
breakdown.values[id] = values.breakdown;
|
|
19242
19247
|
return monthUsage;
|
|
19243
19248
|
};
|
|
19244
|
-
var setAppUsageValue = (quotaUsage,
|
|
19249
|
+
var setAppUsageValue = (quotaUsage, name2, type, opts = {}, values) => {
|
|
19245
19250
|
var _a;
|
|
19246
19251
|
let appId;
|
|
19247
19252
|
try {
|
|
19248
19253
|
appId = db_exports.getProdAppID((opts == null ? void 0 : opts.appId) || context_exports.getAppId());
|
|
19249
19254
|
} catch (err) {
|
|
19250
19255
|
}
|
|
19251
|
-
if (!appId || !values.app || !APP_QUOTA_NAMES.includes(
|
|
19256
|
+
if (!appId || !values.app || !APP_QUOTA_NAMES.includes(name2)) {
|
|
19252
19257
|
return quotaUsage;
|
|
19253
19258
|
}
|
|
19254
19259
|
if (!((_a = quotaUsage.apps) == null ? void 0 : _a[appId])) {
|
|
@@ -19260,11 +19265,11 @@ var setAppUsageValue = (quotaUsage, name, type, opts = {}, values) => {
|
|
|
19260
19265
|
const appUsage = quotaUsage.apps[appId];
|
|
19261
19266
|
switch (type) {
|
|
19262
19267
|
case "static" /* STATIC */:
|
|
19263
|
-
appUsage.usageQuota[
|
|
19268
|
+
appUsage.usageQuota[name2] = values.app;
|
|
19264
19269
|
break;
|
|
19265
19270
|
case "monthly" /* MONTHLY */:
|
|
19266
19271
|
const currentMonth = getCurrentMonthString();
|
|
19267
|
-
const monthlyName =
|
|
19272
|
+
const monthlyName = name2;
|
|
19268
19273
|
let monthUsage = appUsage.monthly[currentMonth];
|
|
19269
19274
|
if (!monthUsage) {
|
|
19270
19275
|
appUsage.monthly[currentMonth] = generateNewMonthlyQuotas();
|
|
@@ -19278,9 +19283,9 @@ var setAppUsageValue = (quotaUsage, name, type, opts = {}, values) => {
|
|
|
19278
19283
|
}
|
|
19279
19284
|
return quotaUsage;
|
|
19280
19285
|
};
|
|
19281
|
-
var getAppUsageValue = (quotaUsage, type,
|
|
19286
|
+
var getAppUsageValue = (quotaUsage, type, name2, id) => {
|
|
19282
19287
|
var _a, _b, _c, _d, _e;
|
|
19283
|
-
if (!APP_QUOTA_NAMES.includes(
|
|
19288
|
+
if (!APP_QUOTA_NAMES.includes(name2)) {
|
|
19284
19289
|
return {};
|
|
19285
19290
|
}
|
|
19286
19291
|
let appId;
|
|
@@ -19294,13 +19299,13 @@ var getAppUsageValue = (quotaUsage, type, name, id) => {
|
|
|
19294
19299
|
const appUsage = quotaUsage.apps[appId];
|
|
19295
19300
|
switch (type) {
|
|
19296
19301
|
case "static" /* STATIC */:
|
|
19297
|
-
if ((_a = appUsage.usageQuota) == null ? void 0 : _a[
|
|
19298
|
-
return { app: appUsage.usageQuota[
|
|
19302
|
+
if ((_a = appUsage.usageQuota) == null ? void 0 : _a[name2]) {
|
|
19303
|
+
return { app: appUsage.usageQuota[name2] };
|
|
19299
19304
|
}
|
|
19300
19305
|
break;
|
|
19301
19306
|
case "monthly" /* MONTHLY */:
|
|
19302
19307
|
const currentMonth = getCurrentMonthString();
|
|
19303
|
-
const monthlyName =
|
|
19308
|
+
const monthlyName = name2;
|
|
19304
19309
|
if (!((_c = (_b = appUsage.monthly) == null ? void 0 : _b[currentMonth]) == null ? void 0 : _c[monthlyName])) {
|
|
19305
19310
|
break;
|
|
19306
19311
|
}
|
|
@@ -19315,68 +19320,68 @@ var getAppUsageValue = (quotaUsage, type, name, id) => {
|
|
|
19315
19320
|
}
|
|
19316
19321
|
return { app: 0 };
|
|
19317
19322
|
};
|
|
19318
|
-
var setStaticTriggers = (
|
|
19323
|
+
var setStaticTriggers = (name2, quotaUsage, triggers) => {
|
|
19319
19324
|
if (!quotaUsage.usageQuota.triggers) {
|
|
19320
19325
|
quotaUsage.usageQuota.triggers = {};
|
|
19321
19326
|
}
|
|
19322
19327
|
if (triggers) {
|
|
19323
|
-
quotaUsage.usageQuota.triggers[
|
|
19328
|
+
quotaUsage.usageQuota.triggers[name2] = triggers;
|
|
19324
19329
|
}
|
|
19325
19330
|
};
|
|
19326
|
-
var setMonthlyTriggers = (
|
|
19331
|
+
var setMonthlyTriggers = (name2, currentMonth, quotaUsage, triggers) => {
|
|
19327
19332
|
if (!quotaUsage.monthly[currentMonth].triggers) {
|
|
19328
19333
|
quotaUsage.monthly[currentMonth].triggers = {};
|
|
19329
19334
|
}
|
|
19330
19335
|
if (triggers) {
|
|
19331
|
-
quotaUsage.monthly[currentMonth].triggers[
|
|
19336
|
+
quotaUsage.monthly[currentMonth].triggers[name2] = triggers;
|
|
19332
19337
|
}
|
|
19333
19338
|
};
|
|
19334
|
-
var coreUsageUpdate = (quotaUsage,
|
|
19339
|
+
var coreUsageUpdate = (quotaUsage, name2, type, values, opts = {}) => {
|
|
19335
19340
|
if (type === "static" /* STATIC */) {
|
|
19336
|
-
|
|
19337
|
-
quotaUsage.usageQuota[
|
|
19338
|
-
setStaticTriggers(
|
|
19341
|
+
name2 = name2;
|
|
19342
|
+
quotaUsage.usageQuota[name2] = values.total;
|
|
19343
|
+
setStaticTriggers(name2, quotaUsage, values.triggers);
|
|
19339
19344
|
} else if (type === "monthly" /* MONTHLY */) {
|
|
19340
|
-
|
|
19345
|
+
name2 = name2;
|
|
19341
19346
|
const currentMonth = getCurrentMonthString();
|
|
19342
|
-
quotaUsage.monthly[currentMonth][
|
|
19343
|
-
setMonthlyTriggers(
|
|
19347
|
+
quotaUsage.monthly[currentMonth][name2] = values.total;
|
|
19348
|
+
setMonthlyTriggers(name2, currentMonth, quotaUsage, values.triggers);
|
|
19344
19349
|
} else {
|
|
19345
19350
|
throw new Error(`Invalid usage type: ${type}`);
|
|
19346
19351
|
}
|
|
19347
|
-
return setAppUsageValue(quotaUsage,
|
|
19352
|
+
return setAppUsageValue(quotaUsage, name2, type, opts, values);
|
|
19348
19353
|
};
|
|
19349
|
-
var setAllUsage = async (
|
|
19350
|
-
const
|
|
19354
|
+
var setAllUsage = async (name2, type, values, opts = {}) => {
|
|
19355
|
+
const db2 = getDB2();
|
|
19351
19356
|
let quotaUsage = await getQuotaUsage();
|
|
19352
|
-
quotaUsage = coreUsageUpdate(quotaUsage,
|
|
19353
|
-
const response = await
|
|
19357
|
+
quotaUsage = coreUsageUpdate(quotaUsage, name2, type, values, opts);
|
|
19358
|
+
const response = await db2.put(quotaUsage);
|
|
19354
19359
|
quotaUsage._rev = response.rev;
|
|
19355
19360
|
return quotaUsage;
|
|
19356
19361
|
};
|
|
19357
|
-
var getCurrentUsageValues = async (type,
|
|
19362
|
+
var getCurrentUsageValues = async (type, name2, id) => {
|
|
19358
19363
|
const quotaUsage = await getQuotaUsage();
|
|
19359
19364
|
let total = 0, appValues = {};
|
|
19360
19365
|
switch (type) {
|
|
19361
19366
|
case "static" /* STATIC */:
|
|
19362
|
-
if (quotaUsage.usageQuota[
|
|
19363
|
-
const staticName =
|
|
19367
|
+
if (quotaUsage.usageQuota[name2]) {
|
|
19368
|
+
const staticName = name2;
|
|
19364
19369
|
total = quotaUsage.usageQuota[staticName];
|
|
19365
|
-
appValues = getAppUsageValue(quotaUsage, type,
|
|
19370
|
+
appValues = getAppUsageValue(quotaUsage, type, name2, id);
|
|
19366
19371
|
}
|
|
19367
19372
|
break;
|
|
19368
19373
|
case "monthly" /* MONTHLY */:
|
|
19369
19374
|
const currentMonth = getCurrentMonthString();
|
|
19370
|
-
const monthlyName =
|
|
19375
|
+
const monthlyName = name2;
|
|
19371
19376
|
if (quotaUsage.monthly[currentMonth][monthlyName]) {
|
|
19372
19377
|
total = quotaUsage.monthly[currentMonth][monthlyName];
|
|
19373
|
-
appValues = getAppUsageValue(quotaUsage, type,
|
|
19378
|
+
appValues = getAppUsageValue(quotaUsage, type, name2, id);
|
|
19374
19379
|
}
|
|
19375
19380
|
break;
|
|
19376
19381
|
default:
|
|
19377
19382
|
throw new Error(`Invalid usage type: ${type}`);
|
|
19378
19383
|
}
|
|
19379
|
-
if (APP_QUOTA_NAMES.includes(
|
|
19384
|
+
if (APP_QUOTA_NAMES.includes(name2) && !(appValues.app || appValues.breakdown)) {
|
|
19380
19385
|
appValues.app = appValues.app || 0;
|
|
19381
19386
|
appValues.breakdown = appValues.breakdown || 0;
|
|
19382
19387
|
}
|
|
@@ -19397,8 +19402,8 @@ var newLicenseInfo = (licenseKey) => {
|
|
|
19397
19402
|
};
|
|
19398
19403
|
};
|
|
19399
19404
|
var save2 = async (licenseInfo) => {
|
|
19400
|
-
const
|
|
19401
|
-
const response = await
|
|
19405
|
+
const db2 = tenancy.getGlobalDB();
|
|
19406
|
+
const response = await db2.put(licenseInfo);
|
|
19402
19407
|
licenseInfo._rev = response.rev;
|
|
19403
19408
|
return licenseInfo;
|
|
19404
19409
|
};
|
|
@@ -19407,9 +19412,9 @@ var create = async (licenseKey) => {
|
|
|
19407
19412
|
return save2(licenseInfo);
|
|
19408
19413
|
};
|
|
19409
19414
|
var get4 = async () => {
|
|
19410
|
-
const
|
|
19415
|
+
const db2 = tenancy.getGlobalDB();
|
|
19411
19416
|
try {
|
|
19412
|
-
return await
|
|
19417
|
+
return await db2.get(StaticDatabases.GLOBAL.docs.licenseInfo);
|
|
19413
19418
|
} catch (err) {
|
|
19414
19419
|
if (err.status === 404) {
|
|
19415
19420
|
return void 0;
|
|
@@ -19422,8 +19427,8 @@ var destroy2 = async () => {
|
|
|
19422
19427
|
if (!info) {
|
|
19423
19428
|
return;
|
|
19424
19429
|
}
|
|
19425
|
-
const
|
|
19426
|
-
return
|
|
19430
|
+
const db2 = tenancy.getGlobalDB();
|
|
19431
|
+
return db2.remove(StaticDatabases.GLOBAL.docs.licenseInfo, info._rev);
|
|
19427
19432
|
};
|
|
19428
19433
|
|
|
19429
19434
|
// ../pro/packages/pro/src/db/groups.ts
|
|
@@ -19445,10 +19450,10 @@ __export(groups_exports, {
|
|
|
19445
19450
|
// ../pro/packages/pro/src/db/views/staticViews.ts
|
|
19446
19451
|
init_src();
|
|
19447
19452
|
async function createAuditLogSearchIndex() {
|
|
19448
|
-
const
|
|
19453
|
+
const db2 = context_exports.getAuditLogsDB();
|
|
19449
19454
|
let designDoc;
|
|
19450
19455
|
try {
|
|
19451
|
-
designDoc = await
|
|
19456
|
+
designDoc = await db2.get("_design/database");
|
|
19452
19457
|
} catch (err) {
|
|
19453
19458
|
if (err.status === 404) {
|
|
19454
19459
|
designDoc = { _id: "_design/database" };
|
|
@@ -19491,14 +19496,14 @@ async function createAuditLogSearchIndex() {
|
|
|
19491
19496
|
}
|
|
19492
19497
|
}
|
|
19493
19498
|
};
|
|
19494
|
-
await
|
|
19499
|
+
await db2.put(designDoc);
|
|
19495
19500
|
}
|
|
19496
19501
|
|
|
19497
19502
|
// ../pro/packages/pro/src/db/views/groups.ts
|
|
19498
19503
|
var { ViewName: ViewName4, SEPARATOR: SEPARATOR5, DocumentType: DocumentType3, createView: createView2 } = db_exports;
|
|
19499
19504
|
var USER_PREFIX = DocumentType3.USER + SEPARATOR5;
|
|
19500
19505
|
async function createGroupUserLookupView() {
|
|
19501
|
-
const
|
|
19506
|
+
const db2 = tenancy.getGlobalDB();
|
|
19502
19507
|
const viewJs = `function(doc) {
|
|
19503
19508
|
if (doc._id.startsWith("${USER_PREFIX}") && Array.isArray(doc.userGroups)) {
|
|
19504
19509
|
for (let groupId of doc.userGroups) {
|
|
@@ -19507,7 +19512,7 @@ async function createGroupUserLookupView() {
|
|
|
19507
19512
|
}
|
|
19508
19513
|
}
|
|
19509
19514
|
}`;
|
|
19510
|
-
await createView2(
|
|
19515
|
+
await createView2(db2, viewJs, ViewName4.USER_BY_GROUP);
|
|
19511
19516
|
}
|
|
19512
19517
|
|
|
19513
19518
|
// ../pro/packages/pro/src/db/groups.ts
|
|
@@ -19547,17 +19552,17 @@ function generateUserGroupID() {
|
|
|
19547
19552
|
return `${GROUP_PREFIX}${utils_exports2.newid()}`;
|
|
19548
19553
|
}
|
|
19549
19554
|
async function getGroupUsers(groupId, params2) {
|
|
19550
|
-
const
|
|
19555
|
+
const db2 = tenancy.getGlobalDB();
|
|
19551
19556
|
const userDocs = await db_exports.queryView(
|
|
19552
19557
|
db_exports.ViewName.USER_BY_GROUP,
|
|
19553
19558
|
getGroupUsersParams(groupId, params2),
|
|
19554
|
-
|
|
19559
|
+
db2,
|
|
19555
19560
|
createGroupUserLookupView,
|
|
19556
19561
|
{ arrayResponse: true }
|
|
19557
19562
|
);
|
|
19558
|
-
const users2 = userDocs.map((
|
|
19559
|
-
_id:
|
|
19560
|
-
email:
|
|
19563
|
+
const users2 = userDocs.map((doc2) => ({
|
|
19564
|
+
_id: doc2.userId,
|
|
19565
|
+
email: doc2.email
|
|
19561
19566
|
})) || [];
|
|
19562
19567
|
return users2;
|
|
19563
19568
|
}
|
|
@@ -19586,9 +19591,9 @@ async function cleanupUsers(group) {
|
|
|
19586
19591
|
}
|
|
19587
19592
|
}
|
|
19588
19593
|
async function fetch11() {
|
|
19589
|
-
const
|
|
19594
|
+
const db2 = tenancy.getGlobalDB();
|
|
19590
19595
|
try {
|
|
19591
|
-
const groups = (await
|
|
19596
|
+
const groups = (await db2.allDocs(
|
|
19592
19597
|
getUserGroupsParams(null, {
|
|
19593
19598
|
include_docs: true
|
|
19594
19599
|
})
|
|
@@ -19603,18 +19608,18 @@ async function fetch11() {
|
|
|
19603
19608
|
}
|
|
19604
19609
|
}
|
|
19605
19610
|
async function get5(groupId) {
|
|
19606
|
-
const
|
|
19611
|
+
const db2 = tenancy.getGlobalDB();
|
|
19607
19612
|
try {
|
|
19608
|
-
const group = await
|
|
19613
|
+
const group = await db2.get(groupId);
|
|
19609
19614
|
return await enrichGroup(group);
|
|
19610
19615
|
} catch (err) {
|
|
19611
19616
|
throw err;
|
|
19612
19617
|
}
|
|
19613
19618
|
}
|
|
19614
19619
|
async function getBulk(groupIds, opts = { enriched: true }) {
|
|
19615
|
-
const
|
|
19620
|
+
const db2 = tenancy.getGlobalDB();
|
|
19616
19621
|
try {
|
|
19617
|
-
const groups = (await
|
|
19622
|
+
const groups = (await db2.allDocs({
|
|
19618
19623
|
keys: groupIds,
|
|
19619
19624
|
include_docs: true
|
|
19620
19625
|
})).rows.map((row) => row.doc);
|
|
@@ -19632,26 +19637,26 @@ async function getBulk(groupIds, opts = { enriched: true }) {
|
|
|
19632
19637
|
}
|
|
19633
19638
|
}
|
|
19634
19639
|
async function save3(group) {
|
|
19635
|
-
const
|
|
19636
|
-
return await
|
|
19640
|
+
const db2 = tenancy.getGlobalDB();
|
|
19641
|
+
return await db2.put(group);
|
|
19637
19642
|
}
|
|
19638
19643
|
async function bulkSave(groups) {
|
|
19639
|
-
const
|
|
19640
|
-
return await
|
|
19644
|
+
const db2 = tenancy.getGlobalDB();
|
|
19645
|
+
return await db2.bulkDocs(groups);
|
|
19641
19646
|
}
|
|
19642
19647
|
async function destroy3(groupId, revision) {
|
|
19643
|
-
const
|
|
19644
|
-
const group = await
|
|
19645
|
-
let resp = await
|
|
19648
|
+
const db2 = tenancy.getGlobalDB();
|
|
19649
|
+
const group = await db2.get(groupId);
|
|
19650
|
+
let resp = await db2.remove(groupId, revision);
|
|
19646
19651
|
await cleanupUsers(group);
|
|
19647
19652
|
return resp;
|
|
19648
19653
|
}
|
|
19649
|
-
async function getByName(
|
|
19654
|
+
async function getByName(name2) {
|
|
19650
19655
|
try {
|
|
19651
19656
|
const groups = await db_exports.directCouchFind(tenancy.getGlobalDBName(), {
|
|
19652
19657
|
selector: {
|
|
19653
19658
|
name: {
|
|
19654
|
-
$regex: `^(?i)${
|
|
19659
|
+
$regex: `^(?i)${name2}$`
|
|
19655
19660
|
}
|
|
19656
19661
|
},
|
|
19657
19662
|
limit: 1
|
|
@@ -19701,7 +19706,7 @@ var { ViewName: ViewName5, AutomationViewMode: AutomationViewMode2, SEPARATOR: S
|
|
|
19701
19706
|
var LOG_PREFIX = DocumentType4.AUTOMATION_LOG + SEPARATOR6;
|
|
19702
19707
|
var APP_BACKUP_PREFIX = DocumentType4.APP_BACKUP + SEPARATOR6;
|
|
19703
19708
|
async function createLogByAutomationView() {
|
|
19704
|
-
const
|
|
19709
|
+
const db2 = context_exports.getProdAppDB();
|
|
19705
19710
|
const viewJs = `function(doc) {
|
|
19706
19711
|
if (doc._id.startsWith("${LOG_PREFIX}")) {
|
|
19707
19712
|
let autoId = doc.automationId + "${SEPARATOR6}"
|
|
@@ -19714,10 +19719,10 @@ async function createLogByAutomationView() {
|
|
|
19714
19719
|
emit(allKey)
|
|
19715
19720
|
}
|
|
19716
19721
|
}`;
|
|
19717
|
-
await createView3(
|
|
19722
|
+
await createView3(db2, viewJs, ViewName5.AUTOMATION_LOGS);
|
|
19718
19723
|
}
|
|
19719
19724
|
async function createAppBackupTriggerView() {
|
|
19720
|
-
const
|
|
19725
|
+
const db2 = tenancy.getGlobalDB();
|
|
19721
19726
|
const viewJs = `function(doc) {
|
|
19722
19727
|
if (doc._id.startsWith("${APP_BACKUP_PREFIX}") && doc.type && doc.trigger) {
|
|
19723
19728
|
let full = doc.appId + "${SEPARATOR6}"
|
|
@@ -19726,7 +19731,7 @@ async function createAppBackupTriggerView() {
|
|
|
19726
19731
|
emit("${APP_BACKUP_PREFIX}" + full + doc.timestamp)
|
|
19727
19732
|
}
|
|
19728
19733
|
}`;
|
|
19729
|
-
await createView3(
|
|
19734
|
+
await createView3(db2, viewJs, ViewName5.APP_BACKUP_BY_TRIGGER);
|
|
19730
19735
|
}
|
|
19731
19736
|
|
|
19732
19737
|
// ../pro/packages/pro/src/db/utils/retention.ts
|
|
@@ -19963,11 +19968,11 @@ var getLicenseVersion = () => {
|
|
|
19963
19968
|
}
|
|
19964
19969
|
};
|
|
19965
19970
|
var getProVersion = () => {
|
|
19966
|
-
const
|
|
19967
|
-
if (!
|
|
19971
|
+
const version2 = environment_default2.VERSION;
|
|
19972
|
+
if (!version2) {
|
|
19968
19973
|
throw new Error("No budibase pro version was specified");
|
|
19969
19974
|
}
|
|
19970
|
-
return
|
|
19975
|
+
return version2;
|
|
19971
19976
|
};
|
|
19972
19977
|
|
|
19973
19978
|
// ../pro/packages/pro/src/constants/misc.ts
|
|
@@ -20020,17 +20025,17 @@ async function getAppBackupParams(appId, filters, otherProps = {}) {
|
|
|
20020
20025
|
endkey: `${APP_BACKUP_PREFIX2}${endKey}`
|
|
20021
20026
|
};
|
|
20022
20027
|
}
|
|
20023
|
-
async function getAppBackupsByTrigger(
|
|
20028
|
+
async function getAppBackupsByTrigger(db2, params2) {
|
|
20024
20029
|
let backups = [];
|
|
20025
20030
|
try {
|
|
20026
20031
|
const queryIndex = db_exports.getQueryIndex(
|
|
20027
20032
|
db_exports.ViewName.APP_BACKUP_BY_TRIGGER
|
|
20028
20033
|
);
|
|
20029
|
-
backups = await
|
|
20034
|
+
backups = await db2.query(queryIndex, params2);
|
|
20030
20035
|
} catch (err) {
|
|
20031
20036
|
if (err != null && err.error === "not_found") {
|
|
20032
20037
|
await createAppBackupTriggerView();
|
|
20033
|
-
return getAppBackupsByTrigger(
|
|
20038
|
+
return getAppBackupsByTrigger(db2, params2);
|
|
20034
20039
|
} else {
|
|
20035
20040
|
throw err;
|
|
20036
20041
|
}
|
|
@@ -20041,7 +20046,7 @@ function generateAppBackupID(appId, timestamp) {
|
|
|
20041
20046
|
return `${APP_BACKUP_PREFIX2}${appId}${db_exports.SEPARATOR}${timestamp}`;
|
|
20042
20047
|
}
|
|
20043
20048
|
async function fetchAppBackups(appId, opts = {}) {
|
|
20044
|
-
const
|
|
20049
|
+
const db2 = tenancy.getGlobalDB();
|
|
20045
20050
|
let backups;
|
|
20046
20051
|
const pageSize = opts.limit || GENERIC_PAGE_SIZE;
|
|
20047
20052
|
const params2 = await getAppBackupParams(appId, opts, {
|
|
@@ -20052,9 +20057,9 @@ async function fetchAppBackups(appId, opts = {}) {
|
|
|
20052
20057
|
params2.startkey = opts.page;
|
|
20053
20058
|
}
|
|
20054
20059
|
if (!opts.trigger || !opts.type) {
|
|
20055
|
-
backups = await
|
|
20060
|
+
backups = await db2.allDocs(params2);
|
|
20056
20061
|
} else {
|
|
20057
|
-
backups = await getAppBackupsByTrigger(
|
|
20062
|
+
backups = await getAppBackupsByTrigger(db2, params2);
|
|
20058
20063
|
}
|
|
20059
20064
|
const pageData = pagination2(backups, {
|
|
20060
20065
|
paginate: opts.paginate,
|
|
@@ -20077,15 +20082,15 @@ async function fetchAppBackups(appId, opts = {}) {
|
|
|
20077
20082
|
}
|
|
20078
20083
|
return pageData;
|
|
20079
20084
|
}
|
|
20080
|
-
async function storeAppBackupMetadata(
|
|
20081
|
-
const
|
|
20082
|
-
const prodAppId = db_exports.getProdAppID(
|
|
20083
|
-
let _id = generateAppBackupID(prodAppId,
|
|
20085
|
+
async function storeAppBackupMetadata(metadata2, opts = {}) {
|
|
20086
|
+
const db2 = tenancy.getGlobalDB();
|
|
20087
|
+
const prodAppId = db_exports.getProdAppID(metadata2.appId);
|
|
20088
|
+
let _id = generateAppBackupID(prodAppId, metadata2.timestamp);
|
|
20084
20089
|
const appBackupDoc = {
|
|
20085
|
-
...
|
|
20090
|
+
...metadata2,
|
|
20086
20091
|
_id,
|
|
20087
20092
|
appId: prodAppId,
|
|
20088
|
-
name:
|
|
20093
|
+
name: metadata2.name
|
|
20089
20094
|
};
|
|
20090
20095
|
if (opts.filename) {
|
|
20091
20096
|
appBackupDoc.filename = opts.filename;
|
|
@@ -20094,27 +20099,27 @@ async function storeAppBackupMetadata(metadata, opts = {}) {
|
|
|
20094
20099
|
appBackupDoc._id = opts.docId;
|
|
20095
20100
|
appBackupDoc._rev = opts.docRev;
|
|
20096
20101
|
}
|
|
20097
|
-
if (
|
|
20102
|
+
if (metadata2.createdBy) {
|
|
20098
20103
|
appBackupDoc.createdBy = db_exports.getGlobalIDFromUserMetadataID(
|
|
20099
|
-
|
|
20104
|
+
metadata2.createdBy
|
|
20100
20105
|
);
|
|
20101
20106
|
}
|
|
20102
|
-
return await
|
|
20107
|
+
return await db2.put(appBackupDoc);
|
|
20103
20108
|
}
|
|
20104
|
-
async function updateAppBackupMetadata(backupId,
|
|
20105
|
-
const
|
|
20106
|
-
const
|
|
20107
|
-
|
|
20108
|
-
return await
|
|
20109
|
+
async function updateAppBackupMetadata(backupId, name2) {
|
|
20110
|
+
const db2 = tenancy.getGlobalDB();
|
|
20111
|
+
const metadata2 = await db2.get(backupId);
|
|
20112
|
+
metadata2.name = name2;
|
|
20113
|
+
return await db2.put(metadata2);
|
|
20109
20114
|
}
|
|
20110
20115
|
async function deleteAppBackupMetadata(backupId) {
|
|
20111
|
-
const
|
|
20112
|
-
const backupDoc = await
|
|
20113
|
-
await
|
|
20116
|
+
const db2 = tenancy.getGlobalDB();
|
|
20117
|
+
const backupDoc = await db2.get(backupId);
|
|
20118
|
+
await db2.remove(backupDoc._id, backupDoc._rev);
|
|
20114
20119
|
}
|
|
20115
20120
|
async function getAppBackupMetadata(backupId) {
|
|
20116
|
-
const
|
|
20117
|
-
return await
|
|
20121
|
+
const db2 = tenancy.getGlobalDB();
|
|
20122
|
+
return await db2.get(backupId);
|
|
20118
20123
|
}
|
|
20119
20124
|
|
|
20120
20125
|
// ../pro/packages/pro/src/db/environmentVariables.ts
|
|
@@ -20133,16 +20138,16 @@ var cache = new import_lru_cache.default({
|
|
|
20133
20138
|
function getEnvVarID() {
|
|
20134
20139
|
return StaticDatabases.GLOBAL.docs.environmentVariables;
|
|
20135
20140
|
}
|
|
20136
|
-
function getCacheEnvVarID(
|
|
20141
|
+
function getCacheEnvVarID(rev2) {
|
|
20137
20142
|
const tenantId = tenancy.getTenantId();
|
|
20138
|
-
return `${tenantId}/${getEnvVarID()}/${
|
|
20143
|
+
return `${tenantId}/${getEnvVarID()}/${rev2 || ""}`;
|
|
20139
20144
|
}
|
|
20140
20145
|
async function get6() {
|
|
20141
20146
|
const id = getEnvVarID();
|
|
20142
|
-
const
|
|
20147
|
+
const db2 = tenancy.getGlobalDB();
|
|
20143
20148
|
let encrypted, notFound = false;
|
|
20144
20149
|
try {
|
|
20145
|
-
encrypted = await
|
|
20150
|
+
encrypted = await db2.get(id);
|
|
20146
20151
|
} catch (err) {
|
|
20147
20152
|
if (err.status == 404) {
|
|
20148
20153
|
notFound = true;
|
|
@@ -20175,14 +20180,14 @@ async function get6() {
|
|
|
20175
20180
|
cache.set(cacheKey, finalDoc);
|
|
20176
20181
|
return finalDoc;
|
|
20177
20182
|
}
|
|
20178
|
-
async function update(
|
|
20183
|
+
async function update(doc2) {
|
|
20179
20184
|
const id = getEnvVarID();
|
|
20180
|
-
const
|
|
20181
|
-
return await
|
|
20182
|
-
_id:
|
|
20183
|
-
_rev:
|
|
20185
|
+
const db2 = tenancy.getGlobalDB();
|
|
20186
|
+
return await db2.put({
|
|
20187
|
+
_id: doc2._id || id,
|
|
20188
|
+
_rev: doc2._rev || void 0,
|
|
20184
20189
|
variables: encryption_exports.encrypt(
|
|
20185
|
-
JSON.stringify(
|
|
20190
|
+
JSON.stringify(doc2.variables),
|
|
20186
20191
|
encryption_exports.SecretOption.ENCRYPTION
|
|
20187
20192
|
)
|
|
20188
20193
|
});
|
|
@@ -20546,14 +20551,14 @@ __export(quotas_exports4, {
|
|
|
20546
20551
|
|
|
20547
20552
|
// ../pro/packages/pro/src/sdk/quotas/quotas.ts
|
|
20548
20553
|
init_src();
|
|
20549
|
-
var increment = (
|
|
20550
|
-
return tryIncrement(1,
|
|
20554
|
+
var increment = (name2, type, opts) => {
|
|
20555
|
+
return tryIncrement(1, name2, type, opts);
|
|
20551
20556
|
};
|
|
20552
|
-
var incrementMany = (change,
|
|
20553
|
-
return tryIncrement(change,
|
|
20557
|
+
var incrementMany = (change, name2, type, opts) => {
|
|
20558
|
+
return tryIncrement(change, name2, type, opts);
|
|
20554
20559
|
};
|
|
20555
|
-
var tryIncrement = async (change,
|
|
20556
|
-
await updateUsage(change,
|
|
20560
|
+
var tryIncrement = async (change, name2, type, opts = {}) => {
|
|
20561
|
+
await updateUsage(change, name2, type, {
|
|
20557
20562
|
dryRun: true,
|
|
20558
20563
|
suppressErrorLog: opts.suppressErrorLog,
|
|
20559
20564
|
id: opts.id
|
|
@@ -20562,7 +20567,7 @@ var tryIncrement = async (change, name, type, opts = {}) => {
|
|
|
20562
20567
|
if (opts.fn) {
|
|
20563
20568
|
result = await opts.fn();
|
|
20564
20569
|
}
|
|
20565
|
-
await updateUsage(change,
|
|
20570
|
+
await updateUsage(change, name2, type, {
|
|
20566
20571
|
dryRun: false,
|
|
20567
20572
|
valueFn: opts.valueFn,
|
|
20568
20573
|
suppressErrorLog: opts.suppressErrorLog,
|
|
@@ -20570,32 +20575,32 @@ var tryIncrement = async (change, name, type, opts = {}) => {
|
|
|
20570
20575
|
});
|
|
20571
20576
|
return result;
|
|
20572
20577
|
};
|
|
20573
|
-
var decrement = (
|
|
20574
|
-
return updateUsage(-1,
|
|
20578
|
+
var decrement = (name2, type, opts = {}) => {
|
|
20579
|
+
return updateUsage(-1, name2, type, opts);
|
|
20575
20580
|
};
|
|
20576
|
-
var decrementMany = (change,
|
|
20577
|
-
return updateUsage(-change,
|
|
20581
|
+
var decrementMany = (change, name2, type, opts = {}) => {
|
|
20582
|
+
return updateUsage(-change, name2, type, opts);
|
|
20578
20583
|
};
|
|
20579
|
-
var set2 = async (
|
|
20580
|
-
return quotas_exports.setUsage(value,
|
|
20584
|
+
var set2 = async (name2, type, value) => {
|
|
20585
|
+
return quotas_exports.setUsage(value, name2, type);
|
|
20581
20586
|
};
|
|
20582
|
-
var getExistingTriggers = (type,
|
|
20587
|
+
var getExistingTriggers = (type, name2, quotaUsage) => {
|
|
20583
20588
|
if (type == "static" /* STATIC */) {
|
|
20584
20589
|
const triggers = quotaUsage.usageQuota.triggers;
|
|
20585
|
-
return triggers ? triggers[
|
|
20590
|
+
return triggers ? triggers[name2] || {} : {};
|
|
20586
20591
|
} else {
|
|
20587
20592
|
const currentMonthString = quotas_exports.utils.getCurrentMonthString();
|
|
20588
20593
|
const triggers = quotaUsage.monthly[currentMonthString].triggers;
|
|
20589
|
-
return triggers ? triggers[
|
|
20594
|
+
return triggers ? triggers[name2] || {} : {};
|
|
20590
20595
|
}
|
|
20591
20596
|
};
|
|
20592
|
-
var triggerQuota2 = async (
|
|
20597
|
+
var triggerQuota2 = async (name2, quota, percentage, resetDate) => {
|
|
20593
20598
|
try {
|
|
20594
20599
|
await redlockImpl_exports.doWithLock(
|
|
20595
20600
|
{
|
|
20596
20601
|
type: "try_once" /* TRY_ONCE */,
|
|
20597
20602
|
name: "trigger_quota" /* TRIGGER_QUOTA */,
|
|
20598
|
-
resource:
|
|
20603
|
+
resource: name2,
|
|
20599
20604
|
// use the quota name for extra uniqueness on the lock
|
|
20600
20605
|
ttl: 1e4
|
|
20601
20606
|
// auto expire after 10 seconds
|
|
@@ -20615,10 +20620,10 @@ var triggerQuota2 = async (name, quota, percentage, resetDate) => {
|
|
|
20615
20620
|
logging_exports.logAlert("Error triggering quota", e);
|
|
20616
20621
|
}
|
|
20617
20622
|
};
|
|
20618
|
-
var checkTriggers = async (type,
|
|
20623
|
+
var checkTriggers = async (type, name2, totalValue, quota) => {
|
|
20619
20624
|
const usage = await getQuotaUsage();
|
|
20620
20625
|
const resetDate = type === "monthly" /* MONTHLY */ ? usage.quotaReset : void 0;
|
|
20621
|
-
const triggers = await getExistingTriggers(type,
|
|
20626
|
+
const triggers = await getExistingTriggers(type, name2, usage);
|
|
20622
20627
|
const quotaTriggers = quota.triggers;
|
|
20623
20628
|
let percentage = totalValue / quota.value * 100;
|
|
20624
20629
|
if (percentage > 100) {
|
|
@@ -20634,7 +20639,7 @@ var checkTriggers = async (type, name, totalValue, quota) => {
|
|
|
20634
20639
|
const isAtTrigger = percentage === triggerPercentage;
|
|
20635
20640
|
const sendNotification = !nextIsTriggered || isAtTrigger;
|
|
20636
20641
|
if (sendNotification) {
|
|
20637
|
-
await triggerQuota2(
|
|
20642
|
+
await triggerQuota2(name2, quota, percentage, resetDate);
|
|
20638
20643
|
}
|
|
20639
20644
|
}
|
|
20640
20645
|
} else {
|
|
@@ -20643,23 +20648,23 @@ var checkTriggers = async (type, name, totalValue, quota) => {
|
|
|
20643
20648
|
}
|
|
20644
20649
|
return triggers;
|
|
20645
20650
|
};
|
|
20646
|
-
var updateUsage = async (usageChange,
|
|
20651
|
+
var updateUsage = async (usageChange, name2, type, opts = {}) => {
|
|
20647
20652
|
let appId = null;
|
|
20648
20653
|
try {
|
|
20649
20654
|
appId = context_exports.getAppId();
|
|
20650
20655
|
} catch (err) {
|
|
20651
20656
|
}
|
|
20652
|
-
const isAppQuota = APP_QUOTA_NAMES.includes(
|
|
20657
|
+
const isAppQuota = APP_QUOTA_NAMES.includes(name2);
|
|
20653
20658
|
if (isAppQuota && !appId) {
|
|
20654
20659
|
throw new Error("App context required for quota update");
|
|
20655
20660
|
}
|
|
20656
20661
|
try {
|
|
20657
|
-
const licensedQuota = await getLicensedQuota("usage" /* USAGE */,
|
|
20662
|
+
const licensedQuota = await getLicensedQuota("usage" /* USAGE */, name2, type);
|
|
20658
20663
|
let {
|
|
20659
20664
|
total: totalValue,
|
|
20660
20665
|
app: appValue,
|
|
20661
20666
|
breakdown: breakdownValue
|
|
20662
|
-
} = await quotas_exports.getCurrentUsageValues(type,
|
|
20667
|
+
} = await quotas_exports.getCurrentUsageValues(type, name2, opts.id);
|
|
20663
20668
|
totalValue += usageChange;
|
|
20664
20669
|
if (appValue != null) {
|
|
20665
20670
|
appValue += usageChange;
|
|
@@ -20669,7 +20674,7 @@ var updateUsage = async (usageChange, name, type, opts = {}) => {
|
|
|
20669
20674
|
}
|
|
20670
20675
|
let triggers = {};
|
|
20671
20676
|
if (!opts.dryRun) {
|
|
20672
|
-
triggers = await checkTriggers(type,
|
|
20677
|
+
triggers = await checkTriggers(type, name2, totalValue, licensedQuota);
|
|
20673
20678
|
}
|
|
20674
20679
|
if (licensedQuota.value !== quotas_exports2.UNLIMITED && totalValue > licensedQuota.value && usageChange > 0) {
|
|
20675
20680
|
throw new UsageLimitError(
|
|
@@ -20692,7 +20697,7 @@ var updateUsage = async (usageChange, name, type, opts = {}) => {
|
|
|
20692
20697
|
appValue = totalValue;
|
|
20693
20698
|
}
|
|
20694
20699
|
await quotas_exports.setAllUsage(
|
|
20695
|
-
|
|
20700
|
+
name2,
|
|
20696
20701
|
type,
|
|
20697
20702
|
{
|
|
20698
20703
|
total: totalValue,
|
|
@@ -20704,30 +20709,30 @@ var updateUsage = async (usageChange, name, type, opts = {}) => {
|
|
|
20704
20709
|
);
|
|
20705
20710
|
} catch (err) {
|
|
20706
20711
|
if (!opts.suppressErrorLog) {
|
|
20707
|
-
console.error(`Error updating usage quotas for ${
|
|
20712
|
+
console.error(`Error updating usage quotas for ${name2}`, err);
|
|
20708
20713
|
}
|
|
20709
20714
|
throw err;
|
|
20710
20715
|
}
|
|
20711
20716
|
};
|
|
20712
|
-
var getLicensedQuota = async (quotaType,
|
|
20717
|
+
var getLicensedQuota = async (quotaType, name2, usageType) => {
|
|
20713
20718
|
const license = await cache_exports2.getCachedLicense();
|
|
20714
20719
|
if (!license) {
|
|
20715
20720
|
const tenantId = tenancy.getTenantId();
|
|
20716
20721
|
throw new Error("License not found for tenant id " + tenantId);
|
|
20717
20722
|
}
|
|
20718
|
-
if (usageType && isStaticQuota(quotaType, usageType,
|
|
20719
|
-
return license.quotas[quotaType][usageType][
|
|
20720
|
-
} else if (usageType && isMonthlyQuota(quotaType, usageType,
|
|
20721
|
-
return license.quotas[quotaType][usageType][
|
|
20722
|
-
} else if (isConstantQuota(quotaType,
|
|
20723
|
-
return license.quotas[quotaType][
|
|
20723
|
+
if (usageType && isStaticQuota(quotaType, usageType, name2)) {
|
|
20724
|
+
return license.quotas[quotaType][usageType][name2];
|
|
20725
|
+
} else if (usageType && isMonthlyQuota(quotaType, usageType, name2)) {
|
|
20726
|
+
return license.quotas[quotaType][usageType][name2];
|
|
20727
|
+
} else if (isConstantQuota(quotaType, name2)) {
|
|
20728
|
+
return license.quotas[quotaType][name2];
|
|
20724
20729
|
} else {
|
|
20725
20730
|
throw new Error("Invalid quota type");
|
|
20726
20731
|
}
|
|
20727
20732
|
};
|
|
20728
|
-
var usageLimitIsExceeded = async (
|
|
20733
|
+
var usageLimitIsExceeded = async (name2, type) => {
|
|
20729
20734
|
try {
|
|
20730
|
-
await updateUsage(1,
|
|
20735
|
+
await updateUsage(1, name2, type, { dryRun: true });
|
|
20731
20736
|
return false;
|
|
20732
20737
|
} catch (e) {
|
|
20733
20738
|
if (e.code === "usage_limit_exceeded" /* USAGE_LIMIT_EXCEEDED */) {
|
|
@@ -20841,19 +20846,19 @@ async function recordDayPassOnQuotas() {
|
|
|
20841
20846
|
});
|
|
20842
20847
|
}
|
|
20843
20848
|
async function recordDayPassTimeOnUser(user) {
|
|
20844
|
-
const
|
|
20845
|
-
let dbUser = await
|
|
20849
|
+
const db2 = tenancy.getGlobalDB();
|
|
20850
|
+
let dbUser = await db2.get(user._id);
|
|
20846
20851
|
const now = /* @__PURE__ */ new Date();
|
|
20847
20852
|
const nowString = (/* @__PURE__ */ new Date()).toISOString();
|
|
20848
20853
|
user.dayPassRecordedAt = nowString;
|
|
20849
20854
|
dbUser.dayPassRecordedAt = nowString;
|
|
20850
20855
|
try {
|
|
20851
20856
|
console.log(`Recording day pass for user=${user._id}`);
|
|
20852
|
-
await
|
|
20857
|
+
await db2.put(dbUser);
|
|
20853
20858
|
} catch (e) {
|
|
20854
20859
|
if (e.status === 409) {
|
|
20855
20860
|
console.warn(`Conflict recording day pass for user=${user._id}`);
|
|
20856
|
-
dbUser = await
|
|
20861
|
+
dbUser = await db2.get(user._id);
|
|
20857
20862
|
if (!dbUser.dayPassRecordedAt || new Date(dbUser.dayPassRecordedAt).getDay() !== now.getDay()) {
|
|
20858
20863
|
console.error(`Day pass not recorded for user=${user._id}`);
|
|
20859
20864
|
throw e;
|
|
@@ -21102,9 +21107,9 @@ function generateAutomationLogID(isoDate, status2, automationId) {
|
|
|
21102
21107
|
return `${DocumentType5.AUTOMATION_LOG}${SEPARATOR7}${isoDate}${SEPARATOR7}${automationId}${SEPARATOR7}${status2}`;
|
|
21103
21108
|
}
|
|
21104
21109
|
async function getAllLogs(startDate, endDate, opts = { docs: true }) {
|
|
21105
|
-
let
|
|
21106
|
-
if (!await
|
|
21107
|
-
|
|
21110
|
+
let db2 = context_exports.getProdAppDB();
|
|
21111
|
+
if (!await db2.exists()) {
|
|
21112
|
+
db2 = context_exports.getDevAppDB();
|
|
21108
21113
|
}
|
|
21109
21114
|
let optional = { status: opts.status };
|
|
21110
21115
|
let limit = (opts == null ? void 0 : opts.limit) ? opts.limit : (opts == null ? void 0 : opts.paginate) ? GENERIC_PAGE_SIZE + 1 : void 0;
|
|
@@ -21115,16 +21120,16 @@ async function getAllLogs(startDate, endDate, opts = { docs: true }) {
|
|
|
21115
21120
|
if (opts == null ? void 0 : opts.page) {
|
|
21116
21121
|
params2.startkey = opts.page;
|
|
21117
21122
|
}
|
|
21118
|
-
let response = await
|
|
21123
|
+
let response = await db2.allDocs(params2);
|
|
21119
21124
|
return pagination2(response, {
|
|
21120
21125
|
paginate: opts == null ? void 0 : opts.paginate,
|
|
21121
21126
|
pageSize: GENERIC_PAGE_SIZE
|
|
21122
21127
|
});
|
|
21123
21128
|
}
|
|
21124
21129
|
async function getLogsByView(startDate, endDate, viewParams = {}) {
|
|
21125
|
-
let
|
|
21126
|
-
if (!await
|
|
21127
|
-
|
|
21130
|
+
let db2 = context_exports.getProdAppDB();
|
|
21131
|
+
if (!await db2.exists()) {
|
|
21132
|
+
db2 = context_exports.getDevAppDB();
|
|
21128
21133
|
}
|
|
21129
21134
|
let response;
|
|
21130
21135
|
try {
|
|
@@ -21139,7 +21144,7 @@ async function getLogsByView(startDate, endDate, viewParams = {}) {
|
|
|
21139
21144
|
if (viewParams == null ? void 0 : viewParams.page) {
|
|
21140
21145
|
params2.startkey = viewParams.page;
|
|
21141
21146
|
}
|
|
21142
|
-
response = await
|
|
21147
|
+
response = await db2.query(getQueryIndex3(ViewName6.AUTOMATION_LOGS), params2);
|
|
21143
21148
|
} catch (err) {
|
|
21144
21149
|
if (err != null && (err.name === "not_found" || err.error === "not_found")) {
|
|
21145
21150
|
await createLogByAutomationView();
|
|
@@ -21151,9 +21156,9 @@ async function getLogsByView(startDate, endDate, viewParams = {}) {
|
|
|
21151
21156
|
return pagination2(response);
|
|
21152
21157
|
}
|
|
21153
21158
|
async function writeLog(automation, results) {
|
|
21154
|
-
const
|
|
21159
|
+
const db2 = context_exports.getProdAppDB();
|
|
21155
21160
|
const automationId = automation._id;
|
|
21156
|
-
const
|
|
21161
|
+
const name2 = automation.name;
|
|
21157
21162
|
const status2 = getStatus(results);
|
|
21158
21163
|
const isoDate = (/* @__PURE__ */ new Date()).toISOString();
|
|
21159
21164
|
const id = generateAutomationLogID(isoDate, status2, automationId);
|
|
@@ -21162,23 +21167,23 @@ async function writeLog(automation, results) {
|
|
|
21162
21167
|
...results,
|
|
21163
21168
|
automationId,
|
|
21164
21169
|
status: status2,
|
|
21165
|
-
automationName:
|
|
21170
|
+
automationName: name2,
|
|
21166
21171
|
createdAt: isoDate,
|
|
21167
21172
|
_id: id
|
|
21168
21173
|
};
|
|
21169
|
-
await
|
|
21174
|
+
await db2.put(log);
|
|
21170
21175
|
return id;
|
|
21171
21176
|
}
|
|
21172
21177
|
async function updateAppMetadataWithErrors(logIds, { clearing } = { clearing: false }) {
|
|
21173
|
-
const
|
|
21178
|
+
const db2 = context_exports.getProdAppDB();
|
|
21174
21179
|
await backOff(async () => {
|
|
21175
|
-
const
|
|
21180
|
+
const metadata2 = await db2.get(db_exports.DocumentType.APP_METADATA);
|
|
21176
21181
|
for (let logId of logIds) {
|
|
21177
21182
|
const parts = logId.split(db_exports.SEPARATOR);
|
|
21178
21183
|
const autoId = `${parts[parts.length - 3]}${db_exports.SEPARATOR}${parts[parts.length - 2]}`;
|
|
21179
21184
|
let errors = {};
|
|
21180
|
-
if (
|
|
21181
|
-
errors =
|
|
21185
|
+
if (metadata2.automationErrors) {
|
|
21186
|
+
errors = metadata2.automationErrors;
|
|
21182
21187
|
}
|
|
21183
21188
|
if (!Array.isArray(errors[autoId])) {
|
|
21184
21189
|
errors[autoId] = [];
|
|
@@ -21192,10 +21197,10 @@ async function updateAppMetadataWithErrors(logIds, { clearing } = { clearing: fa
|
|
|
21192
21197
|
if (errors[autoId].length === 0) {
|
|
21193
21198
|
delete errors[autoId];
|
|
21194
21199
|
}
|
|
21195
|
-
|
|
21200
|
+
metadata2.automationErrors = errors;
|
|
21196
21201
|
}
|
|
21197
|
-
await
|
|
21198
|
-
await cache_exports.app.invalidateAppMetadata(
|
|
21202
|
+
await db2.put(metadata2);
|
|
21203
|
+
await cache_exports.app.invalidateAppMetadata(metadata2.appId, metadata2);
|
|
21199
21204
|
}, "Failed to update app metadata with automation log error");
|
|
21200
21205
|
}
|
|
21201
21206
|
async function getExpiredLogs() {
|
|
@@ -21211,29 +21216,29 @@ async function getExpiredLogs() {
|
|
|
21211
21216
|
}
|
|
21212
21217
|
}
|
|
21213
21218
|
async function clearOldHistory() {
|
|
21214
|
-
const
|
|
21219
|
+
const db2 = context_exports.getProdAppDB();
|
|
21215
21220
|
try {
|
|
21216
21221
|
const expired = await getExpiredLogs();
|
|
21217
21222
|
if (!expired.data || expired.data.length === 0) {
|
|
21218
21223
|
return;
|
|
21219
21224
|
}
|
|
21220
|
-
const toDelete = expired.data.map((
|
|
21221
|
-
_id:
|
|
21222
|
-
_rev:
|
|
21225
|
+
const toDelete = expired.data.map((doc2) => ({
|
|
21226
|
+
_id: doc2.id,
|
|
21227
|
+
_rev: doc2.value.rev,
|
|
21223
21228
|
_deleted: true
|
|
21224
21229
|
}));
|
|
21225
|
-
const errorLogIds = expired.data.filter((
|
|
21226
|
-
const parts =
|
|
21230
|
+
const errorLogIds = expired.data.filter((doc2) => {
|
|
21231
|
+
const parts = doc2.id.split(db_exports.SEPARATOR);
|
|
21227
21232
|
const status2 = parts[parts.length - 1];
|
|
21228
21233
|
return status2 === "error" /* ERROR */;
|
|
21229
|
-
}).map((
|
|
21230
|
-
await
|
|
21234
|
+
}).map((doc2) => doc2.id);
|
|
21235
|
+
await db2.bulkDocs(toDelete);
|
|
21231
21236
|
if (errorLogIds.length) {
|
|
21232
21237
|
await updateAppMetadataWithErrors(errorLogIds, { clearing: true });
|
|
21233
21238
|
}
|
|
21234
21239
|
} catch (err) {
|
|
21235
21240
|
logging_exports.logAlert(
|
|
21236
|
-
`Failed to cleanup automation log history - Database "${
|
|
21241
|
+
`Failed to cleanup automation log history - Database "${db2.name}"`,
|
|
21237
21242
|
err
|
|
21238
21243
|
);
|
|
21239
21244
|
}
|
|
@@ -21406,10 +21411,10 @@ async function get7(id) {
|
|
|
21406
21411
|
async function getBulk2(ids, opts = { enriched: true }) {
|
|
21407
21412
|
return await groups_exports.getBulk(ids, opts);
|
|
21408
21413
|
}
|
|
21409
|
-
async function guardNameAvailility(
|
|
21410
|
-
const existingGroup = await groups_exports.getByName(
|
|
21414
|
+
async function guardNameAvailility(name2) {
|
|
21415
|
+
const existingGroup = await groups_exports.getByName(name2);
|
|
21411
21416
|
if (existingGroup) {
|
|
21412
|
-
throw new GroupNameUnavailableError(
|
|
21417
|
+
throw new GroupNameUnavailableError(name2);
|
|
21413
21418
|
}
|
|
21414
21419
|
}
|
|
21415
21420
|
async function save4(group) {
|
|
@@ -21550,14 +21555,14 @@ init_src();
|
|
|
21550
21555
|
// ../pro/packages/pro/src/utilities/fileSystem.ts
|
|
21551
21556
|
var import_fs10 = __toESM(require("fs"));
|
|
21552
21557
|
var import_path11 = require("path");
|
|
21553
|
-
function loadJSFile(
|
|
21554
|
-
return import_fs10.default.readFileSync((0, import_path11.join)(
|
|
21558
|
+
function loadJSFile(directory2, name2) {
|
|
21559
|
+
return import_fs10.default.readFileSync((0, import_path11.join)(directory2, name2), "utf8");
|
|
21555
21560
|
}
|
|
21556
21561
|
|
|
21557
21562
|
// ../pro/packages/pro/src/sdk/plugins/index.ts
|
|
21558
21563
|
async function storePlugin(metadata, directory, source) {
|
|
21559
21564
|
const db = tenancy.getGlobalDB();
|
|
21560
|
-
const version = metadata.package.version, name = metadata.package.name, description = metadata.package.description,
|
|
21565
|
+
const version = metadata.package.version, name = metadata.package.name, description = metadata.package.description, hash = metadata.schema.hash;
|
|
21561
21566
|
const bucketPath = objectStore_exports2.getPluginS3Dir(name);
|
|
21562
21567
|
const files = await objectStore_exports2.uploadDirectory(
|
|
21563
21568
|
objectStore_exports2.ObjectStoreBuckets.PLUGINS,
|
|
@@ -21572,8 +21577,7 @@ async function storePlugin(metadata, directory, source) {
|
|
|
21572
21577
|
if (metadata.schema.type === "datasource" /* DATASOURCE */) {
|
|
21573
21578
|
const js = loadJSFile(directory, jsFile.name);
|
|
21574
21579
|
try {
|
|
21575
|
-
;
|
|
21576
|
-
(0, eval)(js);
|
|
21580
|
+
eval(js);
|
|
21577
21581
|
} catch (err) {
|
|
21578
21582
|
const message = (err == null ? void 0 : err.message) ? err.message : JSON.stringify(err);
|
|
21579
21583
|
throw new Error(`JS invalid: ${message}`);
|
|
@@ -21594,7 +21598,7 @@ async function storePlugin(metadata, directory, source) {
|
|
|
21594
21598
|
...metadata,
|
|
21595
21599
|
name,
|
|
21596
21600
|
version,
|
|
21597
|
-
hash
|
|
21601
|
+
hash,
|
|
21598
21602
|
description
|
|
21599
21603
|
};
|
|
21600
21604
|
if (iconFileName) {
|
|
@@ -21606,7 +21610,7 @@ async function storePlugin(metadata, directory, source) {
|
|
|
21606
21610
|
source
|
|
21607
21611
|
};
|
|
21608
21612
|
}
|
|
21609
|
-
const
|
|
21613
|
+
const write = async () => {
|
|
21610
21614
|
const response = await db.put(doc);
|
|
21611
21615
|
await events_exports.plugin.imported(doc);
|
|
21612
21616
|
return {
|
|
@@ -21615,21 +21619,21 @@ async function storePlugin(metadata, directory, source) {
|
|
|
21615
21619
|
};
|
|
21616
21620
|
};
|
|
21617
21621
|
if (!rev) {
|
|
21618
|
-
return await addPlugin(
|
|
21622
|
+
return await addPlugin(write);
|
|
21619
21623
|
} else {
|
|
21620
|
-
return await
|
|
21624
|
+
return await write();
|
|
21621
21625
|
}
|
|
21622
21626
|
}
|
|
21623
|
-
async function deletePlugin(
|
|
21624
|
-
const
|
|
21627
|
+
async function deletePlugin(pluginId2) {
|
|
21628
|
+
const db2 = tenancy.getGlobalDB();
|
|
21625
21629
|
try {
|
|
21626
|
-
const plugin = await
|
|
21627
|
-
const
|
|
21630
|
+
const plugin = await db2.get(pluginId2);
|
|
21631
|
+
const bucketPath2 = objectStore_exports2.getPluginS3Dir(plugin.name);
|
|
21628
21632
|
await objectStore_exports2.deleteFolder(
|
|
21629
21633
|
objectStore_exports2.ObjectStoreBuckets.PLUGINS,
|
|
21630
|
-
|
|
21634
|
+
bucketPath2
|
|
21631
21635
|
);
|
|
21632
|
-
await
|
|
21636
|
+
await db2.remove(pluginId2, plugin._rev);
|
|
21633
21637
|
await events_exports.plugin.deleted(plugin);
|
|
21634
21638
|
await removePlugin();
|
|
21635
21639
|
} catch (err) {
|
|
@@ -21638,9 +21642,9 @@ async function deletePlugin(pluginId) {
|
|
|
21638
21642
|
}
|
|
21639
21643
|
}
|
|
21640
21644
|
async function checkPluginQuotas() {
|
|
21641
|
-
const
|
|
21645
|
+
const db2 = tenancy.getGlobalDB();
|
|
21642
21646
|
try {
|
|
21643
|
-
const allPlugins = await
|
|
21647
|
+
const allPlugins = await db2.allDocs(db_exports.getPluginParams());
|
|
21644
21648
|
const pluginCount = allPlugins.rows.length;
|
|
21645
21649
|
console.log(`Syncing plugin count: ${pluginCount}`);
|
|
21646
21650
|
await updatePluginCount(pluginCount);
|
|
@@ -21666,12 +21670,12 @@ function isEncryptionKeyAvailable() {
|
|
|
21666
21670
|
return !!environment_default2.ENCRYPTION_KEY;
|
|
21667
21671
|
}
|
|
21668
21672
|
async function fetch13() {
|
|
21669
|
-
const
|
|
21670
|
-
return Object.keys(
|
|
21673
|
+
const doc2 = await environmentVariables_exports.get();
|
|
21674
|
+
return Object.keys(doc2.variables);
|
|
21671
21675
|
}
|
|
21672
21676
|
async function fetchValues(environment3) {
|
|
21673
|
-
const
|
|
21674
|
-
const decrypted =
|
|
21677
|
+
const doc2 = await environmentVariables_exports.get();
|
|
21678
|
+
const decrypted = doc2.variables;
|
|
21675
21679
|
const output = {};
|
|
21676
21680
|
for (let [key, value] of Object.entries(decrypted)) {
|
|
21677
21681
|
switch (environment3) {
|
|
@@ -21693,9 +21697,9 @@ async function changeValues(cb) {
|
|
|
21693
21697
|
"User does not have access to environment variables feature."
|
|
21694
21698
|
);
|
|
21695
21699
|
}
|
|
21696
|
-
const
|
|
21697
|
-
|
|
21698
|
-
await environmentVariables_exports.update(
|
|
21700
|
+
const doc2 = await environmentVariables_exports.get();
|
|
21701
|
+
doc2.variables = cb(doc2.variables);
|
|
21702
|
+
await environmentVariables_exports.update(doc2);
|
|
21699
21703
|
}
|
|
21700
21704
|
async function update2(varName, value) {
|
|
21701
21705
|
const checkName = isValid(varName);
|
|
@@ -21724,7 +21728,7 @@ __export(auditLogs_exports2, {
|
|
|
21724
21728
|
definitions: () => definitions,
|
|
21725
21729
|
download: () => download,
|
|
21726
21730
|
fetch: () => fetch14,
|
|
21727
|
-
write: () =>
|
|
21731
|
+
write: () => write2
|
|
21728
21732
|
});
|
|
21729
21733
|
|
|
21730
21734
|
// ../pro/packages/pro/src/sdk/auditLogs/auditLogs.ts
|
|
@@ -21736,15 +21740,15 @@ var MemoryStream2 = require("memorystream");
|
|
|
21736
21740
|
function generateAuditLogID(timestamp) {
|
|
21737
21741
|
return `${"al" /* AUDIT_LOG */}${SEPARATOR}${timestamp}${SEPARATOR}${utils_exports2.newid()}`;
|
|
21738
21742
|
}
|
|
21739
|
-
async function save5(
|
|
21740
|
-
if (!
|
|
21741
|
-
|
|
21743
|
+
async function save5(doc2) {
|
|
21744
|
+
if (!doc2._id) {
|
|
21745
|
+
doc2._id = generateAuditLogID(doc2.timestamp);
|
|
21742
21746
|
}
|
|
21743
21747
|
try {
|
|
21744
|
-
const
|
|
21745
|
-
const response = await
|
|
21748
|
+
const db2 = context_exports.getAuditLogsDB();
|
|
21749
|
+
const response = await db2.put(doc2);
|
|
21746
21750
|
return {
|
|
21747
|
-
...
|
|
21751
|
+
...doc2,
|
|
21748
21752
|
_rev: response.rev
|
|
21749
21753
|
};
|
|
21750
21754
|
} catch (err) {
|
|
@@ -21769,12 +21773,12 @@ async function search(search3, bookmark) {
|
|
|
21769
21773
|
);
|
|
21770
21774
|
}
|
|
21771
21775
|
function dump(params2) {
|
|
21772
|
-
const
|
|
21776
|
+
const db2 = context_exports.getAuditLogsDB();
|
|
21773
21777
|
const stream3 = new MemoryStream2();
|
|
21774
|
-
const promise =
|
|
21775
|
-
filter: (
|
|
21778
|
+
const promise = db2.dump(stream3, {
|
|
21779
|
+
filter: (doc2) => {
|
|
21776
21780
|
var _a;
|
|
21777
|
-
const auditLog =
|
|
21781
|
+
const auditLog = doc2;
|
|
21778
21782
|
if (!((_a = auditLog._id) == null ? void 0 : _a.startsWith("al" /* AUDIT_LOG */))) {
|
|
21779
21783
|
return false;
|
|
21780
21784
|
}
|
|
@@ -21792,7 +21796,7 @@ function dump(params2) {
|
|
|
21792
21796
|
allMatched = allMatched && auditLog.timestamp >= params2.startDate && auditLog.timestamp <= params2.endDate;
|
|
21793
21797
|
}
|
|
21794
21798
|
if (params2.fullSearch) {
|
|
21795
|
-
const json = JSON.stringify(
|
|
21799
|
+
const json = JSON.stringify(doc2);
|
|
21796
21800
|
allMatched = allMatched && json.includes(params2.fullSearch);
|
|
21797
21801
|
}
|
|
21798
21802
|
return allMatched;
|
|
@@ -21803,8 +21807,8 @@ function dump(params2) {
|
|
|
21803
21807
|
const json = JSON.parse(Buffer.from(data).toString());
|
|
21804
21808
|
if (Array.isArray(json.docs)) {
|
|
21805
21809
|
let str = "";
|
|
21806
|
-
for (let
|
|
21807
|
-
str += JSON.stringify(
|
|
21810
|
+
for (let doc2 of json.docs) {
|
|
21811
|
+
str += JSON.stringify(doc2) + "\n";
|
|
21808
21812
|
}
|
|
21809
21813
|
returnStream.write(str);
|
|
21810
21814
|
}
|
|
@@ -21910,12 +21914,12 @@ async function auditLogsEnabled() {
|
|
|
21910
21914
|
const license = await licensing_exports.cache.getCachedLicense();
|
|
21911
21915
|
return license.features.includes("auditLogs" /* AUDIT_LOGS */);
|
|
21912
21916
|
}
|
|
21913
|
-
function getEventFriendlyName(event,
|
|
21917
|
+
function getEventFriendlyName(event, metadata2) {
|
|
21914
21918
|
const friendly = AuditedEventFriendlyName[event];
|
|
21915
21919
|
if (!friendly) {
|
|
21916
21920
|
throw new Error("No friendly name found.");
|
|
21917
21921
|
}
|
|
21918
|
-
let processed = processStringSync(friendly,
|
|
21922
|
+
let processed = processStringSync(friendly, metadata2);
|
|
21919
21923
|
if (processed.includes(`""`)) {
|
|
21920
21924
|
processed = removeTemplateStrings(friendly);
|
|
21921
21925
|
}
|
|
@@ -21923,29 +21927,29 @@ function getEventFriendlyName(event, metadata) {
|
|
|
21923
21927
|
}
|
|
21924
21928
|
|
|
21925
21929
|
// ../pro/packages/pro/src/sdk/auditLogs/auditLogs.ts
|
|
21926
|
-
async function
|
|
21930
|
+
async function write2(event, metadata2, opts) {
|
|
21927
21931
|
if (!await auditLogsEnabled() || !utils_exports2.isAudited(event)) {
|
|
21928
21932
|
return;
|
|
21929
21933
|
}
|
|
21930
|
-
const friendly = getEventFriendlyName(event,
|
|
21934
|
+
const friendly = getEventFriendlyName(event, metadata2);
|
|
21931
21935
|
let date = /* @__PURE__ */ new Date();
|
|
21932
21936
|
if (opts == null ? void 0 : opts.timestamp) {
|
|
21933
21937
|
date = new Date(opts.timestamp);
|
|
21934
21938
|
}
|
|
21935
|
-
const
|
|
21939
|
+
const doc2 = {
|
|
21936
21940
|
timestamp: date.toISOString(),
|
|
21937
21941
|
event,
|
|
21938
21942
|
name: friendly,
|
|
21939
21943
|
userId: (opts == null ? void 0 : opts.userId) || AuditLogSystemUser,
|
|
21940
21944
|
metadata: {
|
|
21941
|
-
...
|
|
21945
|
+
...metadata2,
|
|
21942
21946
|
...opts == null ? void 0 : opts.hostInfo
|
|
21943
21947
|
}
|
|
21944
21948
|
};
|
|
21945
21949
|
const fallback = {};
|
|
21946
21950
|
try {
|
|
21947
21951
|
if (opts == null ? void 0 : opts.appId) {
|
|
21948
|
-
|
|
21952
|
+
doc2.appId = db_exports.getProdAppID(opts.appId);
|
|
21949
21953
|
const appMetadata = await cache_exports.app.getAppMetadata(opts.appId);
|
|
21950
21954
|
fallback.appName = appMetadata.name;
|
|
21951
21955
|
}
|
|
@@ -21959,8 +21963,8 @@ async function write(event, metadata, opts) {
|
|
|
21959
21963
|
err
|
|
21960
21964
|
);
|
|
21961
21965
|
}
|
|
21962
|
-
|
|
21963
|
-
return await save5(
|
|
21966
|
+
doc2.fallback = fallback;
|
|
21967
|
+
return await save5(doc2);
|
|
21964
21968
|
}
|
|
21965
21969
|
async function enrich(logs) {
|
|
21966
21970
|
const allUserIds = logs.map((log) => log.userId);
|
|
@@ -22031,8 +22035,8 @@ function getBackupQueue() {
|
|
|
22031
22035
|
}
|
|
22032
22036
|
|
|
22033
22037
|
// ../pro/packages/pro/src/sdk/backups/backup.ts
|
|
22034
|
-
async function storeAppBackupMetadata2(
|
|
22035
|
-
return backups_exports.storeAppBackupMetadata(
|
|
22038
|
+
async function storeAppBackupMetadata2(metadata2, opts = {}) {
|
|
22039
|
+
return backups_exports.storeAppBackupMetadata(metadata2, opts);
|
|
22036
22040
|
}
|
|
22037
22041
|
function getTimestamps(status2) {
|
|
22038
22042
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -22046,7 +22050,7 @@ function getTimestamps(status2) {
|
|
|
22046
22050
|
return { timestamp, createdAt: timestamp };
|
|
22047
22051
|
}
|
|
22048
22052
|
}
|
|
22049
|
-
async function updateBackupStatus(id,
|
|
22053
|
+
async function updateBackupStatus(id, rev2, status2, contents, filename) {
|
|
22050
22054
|
const backup = await getAppBackup(id);
|
|
22051
22055
|
return await backups_exports.storeAppBackupMetadata(
|
|
22052
22056
|
{
|
|
@@ -22056,10 +22060,10 @@ async function updateBackupStatus(id, rev, status2, contents, filename) {
|
|
|
22056
22060
|
status: status2,
|
|
22057
22061
|
type: "backup" /* BACKUP */
|
|
22058
22062
|
},
|
|
22059
|
-
{ filename, docId: id, docRev:
|
|
22063
|
+
{ filename, docId: id, docRev: rev2 }
|
|
22060
22064
|
);
|
|
22061
22065
|
}
|
|
22062
|
-
async function updateRestoreStatus(id,
|
|
22066
|
+
async function updateRestoreStatus(id, rev2, status2) {
|
|
22063
22067
|
const restore = await getAppBackup(id);
|
|
22064
22068
|
return await backups_exports.storeAppBackupMetadata(
|
|
22065
22069
|
{
|
|
@@ -22069,7 +22073,7 @@ async function updateRestoreStatus(id, rev, status2) {
|
|
|
22069
22073
|
type: "restore" /* RESTORE */,
|
|
22070
22074
|
trigger: "manual" /* MANUAL */
|
|
22071
22075
|
},
|
|
22072
|
-
{ docId: id, docRev:
|
|
22076
|
+
{ docId: id, docRev: rev2 }
|
|
22073
22077
|
);
|
|
22074
22078
|
}
|
|
22075
22079
|
async function getAppBackup(backupId) {
|
|
@@ -22079,11 +22083,11 @@ async function updateAppBackup(backupId, backupName) {
|
|
|
22079
22083
|
return backups_exports.updateAppBackupMetadata(backupId, backupName);
|
|
22080
22084
|
}
|
|
22081
22085
|
async function deleteAppBackup(backupId) {
|
|
22082
|
-
const
|
|
22083
|
-
if (
|
|
22086
|
+
const metadata2 = await backups_exports.getAppBackupMetadata(backupId);
|
|
22087
|
+
if (metadata2.filename) {
|
|
22084
22088
|
await objectStore_exports2.deleteFile(
|
|
22085
22089
|
objectStore_exports2.ObjectStoreBuckets.BACKUPS,
|
|
22086
|
-
|
|
22090
|
+
metadata2.filename
|
|
22087
22091
|
);
|
|
22088
22092
|
}
|
|
22089
22093
|
return backups_exports.deleteAppBackupMetadata(backupId);
|
|
@@ -22092,15 +22096,15 @@ async function fetchAppBackups2(appId, opts) {
|
|
|
22092
22096
|
return backups_exports.fetchAppBackups(appId, opts);
|
|
22093
22097
|
}
|
|
22094
22098
|
async function downloadAppBackup(backupId) {
|
|
22095
|
-
const
|
|
22096
|
-
if (!
|
|
22099
|
+
const metadata2 = await backups_exports.getAppBackupMetadata(backupId);
|
|
22100
|
+
if (!metadata2.filename) {
|
|
22097
22101
|
throw new Error("Backup incomplete - cannot download.");
|
|
22098
22102
|
}
|
|
22099
22103
|
const path2 = await objectStore_exports2.retrieveToTmp(
|
|
22100
22104
|
objectStore_exports2.ObjectStoreBuckets.BACKUPS,
|
|
22101
|
-
|
|
22105
|
+
metadata2.filename
|
|
22102
22106
|
);
|
|
22103
|
-
return { metadata, path: path2 };
|
|
22107
|
+
return { metadata: metadata2, path: path2 };
|
|
22104
22108
|
}
|
|
22105
22109
|
async function triggerAppBackup(appId, trigger, opts = {}) {
|
|
22106
22110
|
let backup;
|
|
@@ -22139,7 +22143,7 @@ async function triggerAppBackup(appId, trigger, opts = {}) {
|
|
|
22139
22143
|
return backup.id;
|
|
22140
22144
|
}
|
|
22141
22145
|
async function triggerAppRestore(appId, backupId, nameForBackup, createdBy) {
|
|
22142
|
-
const
|
|
22146
|
+
const metadata2 = await getAppBackup(backupId);
|
|
22143
22147
|
let restore;
|
|
22144
22148
|
try {
|
|
22145
22149
|
restore = await storeAppBackupMetadata2({
|
|
@@ -22166,7 +22170,7 @@ async function triggerAppRestore(appId, backupId, nameForBackup, createdBy) {
|
|
|
22166
22170
|
createdBy
|
|
22167
22171
|
}
|
|
22168
22172
|
});
|
|
22169
|
-
return { restoreId: restore.id, metadata };
|
|
22173
|
+
return { restoreId: restore.id, metadata: metadata2 };
|
|
22170
22174
|
}
|
|
22171
22175
|
var pkg = {
|
|
22172
22176
|
isEnabled: isBackupsEnabled,
|
|
@@ -22271,7 +22275,7 @@ async function importProcessor(job, opts) {
|
|
|
22271
22275
|
const tenantId = tenancy.getTenantIDFromAppID(appId);
|
|
22272
22276
|
return tenancy.doInTenant(tenantId, async () => {
|
|
22273
22277
|
const devAppId = db_exports.getDevAppID(appId);
|
|
22274
|
-
const { rev } = await backup_default2.updateRestoreStatus(
|
|
22278
|
+
const { rev: rev2 } = await backup_default2.updateRestoreStatus(
|
|
22275
22279
|
data.docId,
|
|
22276
22280
|
data.docRev,
|
|
22277
22281
|
"started" /* STARTED */
|
|
@@ -22296,23 +22300,23 @@ async function importProcessor(job, opts) {
|
|
|
22296
22300
|
logging_exports.logAlert("App restore error", err);
|
|
22297
22301
|
status2 = "failed" /* FAILED */;
|
|
22298
22302
|
}
|
|
22299
|
-
await backup_default2.updateRestoreStatus(data.docId,
|
|
22303
|
+
await backup_default2.updateRestoreStatus(data.docId, rev2, status2);
|
|
22300
22304
|
});
|
|
22301
22305
|
}
|
|
22302
22306
|
async function exportProcessor(job, opts) {
|
|
22303
22307
|
const data = job.data;
|
|
22304
|
-
const appId = data.appId, trigger = data.export.trigger,
|
|
22308
|
+
const appId = data.appId, trigger = data.export.trigger, name2 = data.export.name;
|
|
22305
22309
|
const tenantId = tenancy.getTenantIDFromAppID(appId);
|
|
22306
22310
|
await tenancy.doInTenant(tenantId, async () => {
|
|
22307
|
-
const { rev } = await backup_default2.updateBackupStatus(
|
|
22311
|
+
const { rev: rev2 } = await backup_default2.updateBackupStatus(
|
|
22308
22312
|
data.docId,
|
|
22309
22313
|
data.docRev,
|
|
22310
22314
|
"started" /* STARTED */
|
|
22311
22315
|
);
|
|
22312
22316
|
return runBackup(trigger, tenantId, appId, {
|
|
22313
22317
|
processing: opts,
|
|
22314
|
-
doc: { id: data.docId, rev },
|
|
22315
|
-
name
|
|
22318
|
+
doc: { id: data.docId, rev: rev2 },
|
|
22319
|
+
name: name2
|
|
22316
22320
|
});
|
|
22317
22321
|
});
|
|
22318
22322
|
}
|
|
@@ -22359,8 +22363,8 @@ var ScimUserService = class {
|
|
|
22359
22363
|
constructor(config) {
|
|
22360
22364
|
this.get = async (params2) => {
|
|
22361
22365
|
var _a;
|
|
22362
|
-
const
|
|
22363
|
-
const builder2 = new db_exports.QueryBuilder(
|
|
22366
|
+
const db2 = tenancy.getGlobalDB();
|
|
22367
|
+
const builder2 = new db_exports.QueryBuilder(db2.name, "user" /* USER */);
|
|
22364
22368
|
builder2.setIndexBuilder(db_exports.searchIndexes.createUserIndex);
|
|
22365
22369
|
builder2.setLimit(params2.pageSize);
|
|
22366
22370
|
builder2.addEqual("scimInfo.isSync", true);
|
|
@@ -22496,9 +22500,9 @@ var fetch15 = async (ctx) => {
|
|
|
22496
22500
|
ctx.body = { data: await fetch12() };
|
|
22497
22501
|
};
|
|
22498
22502
|
var destroy4 = async (ctx) => {
|
|
22499
|
-
const { id, rev } = ctx.params;
|
|
22503
|
+
const { id, rev: rev2 } = ctx.params;
|
|
22500
22504
|
try {
|
|
22501
|
-
await remove2(id,
|
|
22505
|
+
await remove2(id, rev2);
|
|
22502
22506
|
ctx.body = { message: "Group deleted successfully" };
|
|
22503
22507
|
} catch (err) {
|
|
22504
22508
|
ctx.throw(err.status, err);
|
|
@@ -22543,13 +22547,13 @@ async function fetch16(ctx) {
|
|
|
22543
22547
|
};
|
|
22544
22548
|
}
|
|
22545
22549
|
async function create3(ctx) {
|
|
22546
|
-
const { name, production, development } = ctx.request.body;
|
|
22547
|
-
await environmentVariables_exports2.update(
|
|
22550
|
+
const { name: name2, production, development } = ctx.request.body;
|
|
22551
|
+
await environmentVariables_exports2.update(name2, { production, development });
|
|
22548
22552
|
const environments = ["production" /* PRODUCTION */];
|
|
22549
22553
|
if (production !== development) {
|
|
22550
22554
|
environments.push("development" /* DEVELOPMENT */);
|
|
22551
22555
|
}
|
|
22552
|
-
await events_exports.environmentVariable.created(
|
|
22556
|
+
await events_exports.environmentVariable.created(name2, environments);
|
|
22553
22557
|
ctx.status = 200;
|
|
22554
22558
|
}
|
|
22555
22559
|
async function update4(ctx) {
|
|
@@ -22795,8 +22799,8 @@ async function downloadBackup(ctx) {
|
|
|
22795
22799
|
const appId = ctx.params.appId;
|
|
22796
22800
|
await checkAppID(ctx, appId);
|
|
22797
22801
|
const backupId = ctx.params.backupId;
|
|
22798
|
-
const { metadata, path: path2 } = await backups_default2.downloadAppBackup(backupId);
|
|
22799
|
-
ctx.attachment(`backup-${
|
|
22802
|
+
const { metadata: metadata2, path: path2 } = await backups_default2.downloadAppBackup(backupId);
|
|
22803
|
+
ctx.attachment(`backup-${metadata2.timestamp}.tar.gz`);
|
|
22800
22804
|
ctx.body = import_fs12.default.createReadStream(path2);
|
|
22801
22805
|
}
|
|
22802
22806
|
|
|
@@ -22912,8 +22916,8 @@ var import_router6 = __toESM(require("@koa/router"));
|
|
|
22912
22916
|
|
|
22913
22917
|
// ../pro/packages/pro/src/api/controllers/global/scim/users.ts
|
|
22914
22918
|
var import_scim_patch = require("scim-patch");
|
|
22915
|
-
function tryGetQueryAsNumber(ctx,
|
|
22916
|
-
const value = ctx.request.query[
|
|
22919
|
+
function tryGetQueryAsNumber(ctx, name2) {
|
|
22920
|
+
const value = ctx.request.query[name2];
|
|
22917
22921
|
if (value === void 0) {
|
|
22918
22922
|
return void 0;
|
|
22919
22923
|
}
|
|
@@ -23459,11 +23463,11 @@ var datasources_default = {
|
|
|
23459
23463
|
};
|
|
23460
23464
|
|
|
23461
23465
|
// src/sdk/app/tables/index.ts
|
|
23462
|
-
async function getAllInternalTables(
|
|
23463
|
-
if (!
|
|
23464
|
-
|
|
23466
|
+
async function getAllInternalTables(db2) {
|
|
23467
|
+
if (!db2) {
|
|
23468
|
+
db2 = context_exports.getAppDB();
|
|
23465
23469
|
}
|
|
23466
|
-
const internalTables = await
|
|
23470
|
+
const internalTables = await db2.allDocs(
|
|
23467
23471
|
getTableParams(null, {
|
|
23468
23472
|
include_docs: true
|
|
23469
23473
|
})
|
|
@@ -23475,7 +23479,7 @@ async function getAllInternalTables(db) {
|
|
|
23475
23479
|
}));
|
|
23476
23480
|
}
|
|
23477
23481
|
async function getAllExternalTables(datasourceId) {
|
|
23478
|
-
const
|
|
23482
|
+
const db2 = context_exports.getAppDB();
|
|
23479
23483
|
const datasource2 = await datasources_default.get(datasourceId, { enriched: true });
|
|
23480
23484
|
if (!datasource2 || !datasource2.entities) {
|
|
23481
23485
|
throw "Datasource is not configured fully.";
|
|
@@ -23487,14 +23491,14 @@ async function getExternalTable(datasourceId, tableName) {
|
|
|
23487
23491
|
return entities[tableName];
|
|
23488
23492
|
}
|
|
23489
23493
|
async function getTable(tableId) {
|
|
23490
|
-
const
|
|
23494
|
+
const db2 = context_exports.getAppDB();
|
|
23491
23495
|
if (isExternalTable(tableId)) {
|
|
23492
23496
|
let { datasourceId, tableName } = breakExternalTableId(tableId);
|
|
23493
23497
|
const datasource2 = await datasources_default.get(datasourceId);
|
|
23494
23498
|
const table = await getExternalTable(datasourceId, tableName);
|
|
23495
23499
|
return { ...table, sql: isSQL(datasource2) };
|
|
23496
23500
|
} else {
|
|
23497
|
-
return
|
|
23501
|
+
return db2.get(tableId);
|
|
23498
23502
|
}
|
|
23499
23503
|
}
|
|
23500
23504
|
var tables_default = {
|
|
@@ -23514,10 +23518,10 @@ __export(webhook_exports, {
|
|
|
23514
23518
|
function isWebhookID(id) {
|
|
23515
23519
|
return id.startsWith(db_exports.DocumentType.WEBHOOK);
|
|
23516
23520
|
}
|
|
23517
|
-
function newDoc(
|
|
23521
|
+
function newDoc(name2, type, target) {
|
|
23518
23522
|
return {
|
|
23519
23523
|
live: true,
|
|
23520
|
-
name,
|
|
23524
|
+
name: name2,
|
|
23521
23525
|
action: {
|
|
23522
23526
|
type,
|
|
23523
23527
|
target
|
|
@@ -23525,22 +23529,22 @@ function newDoc(name, type, target) {
|
|
|
23525
23529
|
};
|
|
23526
23530
|
}
|
|
23527
23531
|
async function save7(webhook) {
|
|
23528
|
-
const
|
|
23532
|
+
const db2 = context_exports.getAppDB();
|
|
23529
23533
|
if (webhook._id && isWebhookID(webhook._id)) {
|
|
23530
|
-
await
|
|
23534
|
+
await db2.get(webhook._id);
|
|
23531
23535
|
} else {
|
|
23532
23536
|
webhook._id = generateWebhookID();
|
|
23533
23537
|
}
|
|
23534
|
-
const response = await
|
|
23538
|
+
const response = await db2.put(webhook);
|
|
23535
23539
|
webhook._rev = response.rev;
|
|
23536
23540
|
return webhook;
|
|
23537
23541
|
}
|
|
23538
|
-
async function destroy6(id,
|
|
23539
|
-
const
|
|
23542
|
+
async function destroy6(id, rev2) {
|
|
23543
|
+
const db2 = context_exports.getAppDB();
|
|
23540
23544
|
if (!id || !isWebhookID(id)) {
|
|
23541
23545
|
throw new Error("Provided webhook ID is not valid.");
|
|
23542
23546
|
}
|
|
23543
|
-
return await
|
|
23547
|
+
return await db2.remove(id, rev2);
|
|
23544
23548
|
}
|
|
23545
23549
|
|
|
23546
23550
|
// src/sdk/app/automations/utils.ts
|
|
@@ -23620,14 +23624,14 @@ async function processUser(user, opts = {}) {
|
|
|
23620
23624
|
}
|
|
23621
23625
|
async function getGlobalUsers(userIds, opts) {
|
|
23622
23626
|
const appId = context_exports.getAppId();
|
|
23623
|
-
const
|
|
23627
|
+
const db2 = tenancy.getGlobalDB();
|
|
23624
23628
|
let globalUsers;
|
|
23625
23629
|
if (userIds) {
|
|
23626
|
-
globalUsers = (await
|
|
23630
|
+
globalUsers = (await db2.allDocs(getMultiIDParams(userIds))).rows.map(
|
|
23627
23631
|
(row) => row.doc
|
|
23628
23632
|
);
|
|
23629
23633
|
} else {
|
|
23630
|
-
globalUsers = (await
|
|
23634
|
+
globalUsers = (await db2.allDocs(
|
|
23631
23635
|
db_exports.getGlobalUserParams(null, {
|
|
23632
23636
|
include_docs: true
|
|
23633
23637
|
})
|
|
@@ -23654,7 +23658,7 @@ async function syncUsersToApp(appId, users2, groups) {
|
|
|
23654
23658
|
return;
|
|
23655
23659
|
}
|
|
23656
23660
|
await context_exports.doInAppContext(appId, async () => {
|
|
23657
|
-
const
|
|
23661
|
+
const db2 = context_exports.getAppDB();
|
|
23658
23662
|
for (let user of users2) {
|
|
23659
23663
|
let ctxUser = user;
|
|
23660
23664
|
let deletedUser = false;
|
|
@@ -23669,9 +23673,9 @@ async function syncUsersToApp(appId, users2, groups) {
|
|
|
23669
23673
|
if (roleId === roles_exports.BUILTIN_ROLE_IDS.PUBLIC) {
|
|
23670
23674
|
roleId = void 0;
|
|
23671
23675
|
}
|
|
23672
|
-
let
|
|
23676
|
+
let metadata2;
|
|
23673
23677
|
try {
|
|
23674
|
-
|
|
23678
|
+
metadata2 = await db2.get(metadataId);
|
|
23675
23679
|
} catch (err) {
|
|
23676
23680
|
if (err.status !== 404) {
|
|
23677
23681
|
throw err;
|
|
@@ -23679,21 +23683,21 @@ async function syncUsersToApp(appId, users2, groups) {
|
|
|
23679
23683
|
if (!roleId) {
|
|
23680
23684
|
continue;
|
|
23681
23685
|
} else if (!deletedUser) {
|
|
23682
|
-
|
|
23686
|
+
metadata2 = {
|
|
23683
23687
|
tableId: InternalTables.USER_METADATA
|
|
23684
23688
|
};
|
|
23685
23689
|
}
|
|
23686
23690
|
}
|
|
23687
23691
|
if (deletedUser || !roleId) {
|
|
23688
|
-
await
|
|
23692
|
+
await db2.remove(metadata2);
|
|
23689
23693
|
continue;
|
|
23690
23694
|
}
|
|
23691
23695
|
if (roleId) {
|
|
23692
|
-
|
|
23696
|
+
metadata2.roleId = roleId;
|
|
23693
23697
|
}
|
|
23694
|
-
let combined = sdk_default.users.combineMetadataAndUser(ctxUser,
|
|
23698
|
+
let combined = sdk_default.users.combineMetadataAndUser(ctxUser, metadata2);
|
|
23695
23699
|
if (combined) {
|
|
23696
|
-
await
|
|
23700
|
+
await db2.put(combined);
|
|
23697
23701
|
}
|
|
23698
23702
|
}
|
|
23699
23703
|
});
|
|
@@ -23748,7 +23752,7 @@ async function syncApp(appId, opts) {
|
|
|
23748
23752
|
try {
|
|
23749
23753
|
const replOpts = replication.appReplicateOpts();
|
|
23750
23754
|
if (opts == null ? void 0 : opts.automationOnly) {
|
|
23751
|
-
replOpts.filter = (
|
|
23755
|
+
replOpts.filter = (doc2) => doc2._id.startsWith(db_exports.DocumentType.AUTOMATION);
|
|
23752
23756
|
}
|
|
23753
23757
|
await replication.replicate(replOpts);
|
|
23754
23758
|
} catch (err) {
|
|
@@ -23861,7 +23865,7 @@ function generateAttachmentFindParams(tableId, attachmentCols, bookmark) {
|
|
|
23861
23865
|
return params2;
|
|
23862
23866
|
}
|
|
23863
23867
|
async function getRowsWithAttachments(appId, table) {
|
|
23864
|
-
const
|
|
23868
|
+
const db2 = db_exports.getDB(appId);
|
|
23865
23869
|
const attachmentCols = [];
|
|
23866
23870
|
for (let [key, column] of Object.entries(table.schema)) {
|
|
23867
23871
|
if (column.type === "attachment" /* ATTACHMENT */) {
|
|
@@ -23878,7 +23882,7 @@ async function getRowsWithAttachments(appId, table) {
|
|
|
23878
23882
|
attachmentCols,
|
|
23879
23883
|
bookmark
|
|
23880
23884
|
);
|
|
23881
|
-
const resp = await db_exports.directCouchFind(
|
|
23885
|
+
const resp = await db_exports.directCouchFind(db2.name, params2);
|
|
23882
23886
|
bookmark = resp.bookmark;
|
|
23883
23887
|
rowsLength = resp.rows.length;
|
|
23884
23888
|
const rows2 = resp.rows;
|
|
@@ -23893,13 +23897,13 @@ __export(rows_exports, {
|
|
|
23893
23897
|
getAllInternalRows: () => getAllInternalRows
|
|
23894
23898
|
});
|
|
23895
23899
|
async function getAllInternalRows(appId) {
|
|
23896
|
-
let
|
|
23900
|
+
let db2;
|
|
23897
23901
|
if (appId) {
|
|
23898
|
-
|
|
23902
|
+
db2 = db_exports.getDB(appId);
|
|
23899
23903
|
} else {
|
|
23900
|
-
|
|
23904
|
+
db2 = context_exports.getAppDB();
|
|
23901
23905
|
}
|
|
23902
|
-
const response = await
|
|
23906
|
+
const response = await db2.allDocs(
|
|
23903
23907
|
getRowParams2(null, null, {
|
|
23904
23908
|
include_docs: true
|
|
23905
23909
|
})
|
|
@@ -23921,9 +23925,9 @@ __export(utils_exports8, {
|
|
|
23921
23925
|
syncGlobalUsers: () => syncGlobalUsers
|
|
23922
23926
|
});
|
|
23923
23927
|
var import_lodash5 = require("lodash");
|
|
23924
|
-
function combineMetadataAndUser(user,
|
|
23928
|
+
function combineMetadataAndUser(user, metadata2) {
|
|
23925
23929
|
const metadataId = generateUserMetadataID2(user._id);
|
|
23926
|
-
const found = Array.isArray(
|
|
23930
|
+
const found = Array.isArray(metadata2) ? metadata2.find((doc2) => doc2._id === metadataId) : metadata2;
|
|
23927
23931
|
if (user.roleId == null || user.roleId === roles_exports.BUILTIN_ROLE_IDS.PUBLIC) {
|
|
23928
23932
|
if (found == null ? void 0 : found._id) {
|
|
23929
23933
|
return { ...found, _deleted: true };
|
|
@@ -23950,11 +23954,11 @@ function combineMetadataAndUser(user, metadata) {
|
|
|
23950
23954
|
}
|
|
23951
23955
|
return null;
|
|
23952
23956
|
}
|
|
23953
|
-
async function rawUserMetadata(
|
|
23954
|
-
if (!
|
|
23955
|
-
|
|
23957
|
+
async function rawUserMetadata(db2) {
|
|
23958
|
+
if (!db2) {
|
|
23959
|
+
db2 = context_exports.getAppDB();
|
|
23956
23960
|
}
|
|
23957
|
-
return (await
|
|
23961
|
+
return (await db2.allDocs(
|
|
23958
23962
|
getUserMetadataParams2(null, {
|
|
23959
23963
|
include_docs: true
|
|
23960
23964
|
})
|
|
@@ -23962,22 +23966,22 @@ async function rawUserMetadata(db) {
|
|
|
23962
23966
|
}
|
|
23963
23967
|
async function syncGlobalUsers() {
|
|
23964
23968
|
const dbs = [context_exports.getDevAppDB(), context_exports.getProdAppDB()];
|
|
23965
|
-
for (let
|
|
23966
|
-
if (!await
|
|
23969
|
+
for (let db2 of dbs) {
|
|
23970
|
+
if (!await db2.exists()) {
|
|
23967
23971
|
continue;
|
|
23968
23972
|
}
|
|
23969
|
-
const resp = await Promise.all([getGlobalUsers(), rawUserMetadata(
|
|
23973
|
+
const resp = await Promise.all([getGlobalUsers(), rawUserMetadata(db2)]);
|
|
23970
23974
|
const users2 = resp[0];
|
|
23971
|
-
const
|
|
23975
|
+
const metadata2 = resp[1];
|
|
23972
23976
|
const toWrite = [];
|
|
23973
23977
|
for (let user of users2) {
|
|
23974
|
-
const combined = combineMetadataAndUser(user,
|
|
23978
|
+
const combined = combineMetadataAndUser(user, metadata2);
|
|
23975
23979
|
if (combined) {
|
|
23976
23980
|
toWrite.push(combined);
|
|
23977
23981
|
}
|
|
23978
23982
|
}
|
|
23979
23983
|
let foundEmails = [];
|
|
23980
|
-
for (let data of
|
|
23984
|
+
for (let data of metadata2) {
|
|
23981
23985
|
if (!data._id) {
|
|
23982
23986
|
continue;
|
|
23983
23987
|
}
|
|
@@ -23990,7 +23994,7 @@ async function syncGlobalUsers() {
|
|
|
23990
23994
|
foundEmails.push(data.email);
|
|
23991
23995
|
}
|
|
23992
23996
|
}
|
|
23993
|
-
await
|
|
23997
|
+
await db2.bulkDocs(toWrite);
|
|
23994
23998
|
}
|
|
23995
23999
|
}
|
|
23996
24000
|
|
|
@@ -24051,8 +24055,8 @@ var clientAppSocket;
|
|
|
24051
24055
|
|
|
24052
24056
|
// src/sdk/plugins/plugins.ts
|
|
24053
24057
|
async function fetch17(type) {
|
|
24054
|
-
const
|
|
24055
|
-
const response = await
|
|
24058
|
+
const db2 = tenancy.getGlobalDB();
|
|
24059
|
+
const response = await db2.allDocs(
|
|
24056
24060
|
db_exports.getPluginParams(null, {
|
|
24057
24061
|
include_docs: true
|
|
24058
24062
|
})
|
|
@@ -24068,16 +24072,16 @@ async function fetch17(type) {
|
|
|
24068
24072
|
return plugins2;
|
|
24069
24073
|
}
|
|
24070
24074
|
}
|
|
24071
|
-
async function processUploaded(plugin,
|
|
24075
|
+
async function processUploaded(plugin, source2) {
|
|
24072
24076
|
var _a, _b;
|
|
24073
|
-
const { metadata, directory } = await fileUpload(plugin);
|
|
24074
|
-
plugin_exports.validate(
|
|
24075
|
-
if (!environment_default.SELF_HOSTED && ((_a =
|
|
24077
|
+
const { metadata: metadata2, directory: directory2 } = await fileUpload(plugin);
|
|
24078
|
+
plugin_exports.validate(metadata2 == null ? void 0 : metadata2.schema);
|
|
24079
|
+
if (!environment_default.SELF_HOSTED && ((_a = metadata2 == null ? void 0 : metadata2.schema) == null ? void 0 : _a.type) !== "component" /* COMPONENT */) {
|
|
24076
24080
|
throw new Error("Only component plugins are supported outside of self-host");
|
|
24077
24081
|
}
|
|
24078
|
-
const
|
|
24079
|
-
(_b = clientAppSocket) == null ? void 0 : _b.emit("plugin-update", { name:
|
|
24080
|
-
return
|
|
24082
|
+
const doc2 = await sdk_exports.plugins.storePlugin(metadata2, directory2, source2);
|
|
24083
|
+
(_b = clientAppSocket) == null ? void 0 : _b.emit("plugin-update", { name: doc2.name, hash: doc2.hash });
|
|
24084
|
+
return doc2;
|
|
24081
24085
|
}
|
|
24082
24086
|
|
|
24083
24087
|
// src/sdk/plugins/index.ts
|
|
@@ -24141,13 +24145,13 @@ if (process.arch && !process.arch.startsWith("arm") && oracle_default.integratio
|
|
|
24141
24145
|
DEFINITIONS2["ORACLE" /* ORACLE */] = oracle_default.schema;
|
|
24142
24146
|
INTEGRATIONS["ORACLE" /* ORACLE */] = oracle_default.integration;
|
|
24143
24147
|
}
|
|
24144
|
-
async function getDefinition(
|
|
24145
|
-
const definition = DEFINITIONS2[
|
|
24148
|
+
async function getDefinition(source2) {
|
|
24149
|
+
const definition = DEFINITIONS2[source2];
|
|
24146
24150
|
if (definition) {
|
|
24147
24151
|
return definition;
|
|
24148
24152
|
}
|
|
24149
24153
|
const allDefinitions = await getDefinitions();
|
|
24150
|
-
return allDefinitions[
|
|
24154
|
+
return allDefinitions[source2];
|
|
24151
24155
|
}
|
|
24152
24156
|
async function getDefinitions() {
|
|
24153
24157
|
const pluginSchemas = {};
|
|
@@ -24350,8 +24354,8 @@ var QueryRunner = class {
|
|
|
24350
24354
|
return { rows: rows2, keys: keys2, info, extra, pagination: pagination3 };
|
|
24351
24355
|
}
|
|
24352
24356
|
async runAnotherQuery(queryId, parameters) {
|
|
24353
|
-
const
|
|
24354
|
-
const query = await
|
|
24357
|
+
const db2 = context_exports.getAppDB();
|
|
24358
|
+
const query = await db2.get(queryId);
|
|
24355
24359
|
const datasource2 = await sdk_default.datasources.get(query.datasourceId, {
|
|
24356
24360
|
enriched: true
|
|
24357
24361
|
});
|
|
@@ -24393,14 +24397,14 @@ var QueryRunner = class {
|
|
|
24393
24397
|
}
|
|
24394
24398
|
async getDynamicVariable(variable) {
|
|
24395
24399
|
let { parameters } = this;
|
|
24396
|
-
const queryId = variable.queryId,
|
|
24397
|
-
let value = await utils_default.checkCacheForDynamicVariable(queryId,
|
|
24400
|
+
const queryId = variable.queryId, name2 = variable.name;
|
|
24401
|
+
let value = await utils_default.checkCacheForDynamicVariable(queryId, name2);
|
|
24398
24402
|
if (!value) {
|
|
24399
24403
|
value = this.queryResponse[queryId] ? this.queryResponse[queryId] : await this.runAnotherQuery(queryId, parameters);
|
|
24400
24404
|
this.queryResponse[queryId] = value;
|
|
24401
|
-
await utils_default.storeDynamicVariable(queryId,
|
|
24405
|
+
await utils_default.storeDynamicVariable(queryId, name2, value);
|
|
24402
24406
|
} else {
|
|
24403
|
-
this.cachedVariables.push({ queryId, name });
|
|
24407
|
+
this.cachedVariables.push({ queryId, name: name2 });
|
|
24404
24408
|
}
|
|
24405
24409
|
return value;
|
|
24406
24410
|
}
|