@budibase/server 2.7.16-alpha.0 → 2.7.16-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builder/assets/{index.55a50076.js → index.0d7ff400.js} +301 -301
- package/builder/index.html +1 -1
- package/dist/automation.js +459 -460
- package/dist/automation.js.map +3 -3
- package/dist/index.js +671 -672
- package/dist/index.js.map +3 -3
- package/dist/query.js +700 -701
- package/dist/query.js.map +3 -3
- package/package.json +8 -8
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
|
});
|
|
@@ -1955,27 +1955,27 @@ function init(opts) {
|
|
|
1955
1955
|
}
|
|
1956
1956
|
function getPouchDB(dbName, opts) {
|
|
1957
1957
|
checkInitialised();
|
|
1958
|
-
const
|
|
1959
|
-
const dbPut =
|
|
1960
|
-
|
|
1961
|
-
if (!
|
|
1962
|
-
|
|
1963
|
-
}
|
|
1964
|
-
|
|
1965
|
-
return dbPut(
|
|
1958
|
+
const db2 = new Pouch(dbName, opts);
|
|
1959
|
+
const dbPut = db2.put;
|
|
1960
|
+
db2.put = async (doc2, options2 = {}) => {
|
|
1961
|
+
if (!doc2.createdAt) {
|
|
1962
|
+
doc2.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1963
|
+
}
|
|
1964
|
+
doc2.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
1965
|
+
return dbPut(doc2, options2);
|
|
1966
1966
|
};
|
|
1967
|
-
|
|
1968
|
-
const info = await
|
|
1967
|
+
db2.exists = async () => {
|
|
1968
|
+
const info = await db2.info();
|
|
1969
1969
|
return !info.error;
|
|
1970
1970
|
};
|
|
1971
|
-
return
|
|
1971
|
+
return db2;
|
|
1972
1972
|
}
|
|
1973
|
-
async function closePouchDB(
|
|
1974
|
-
if (!
|
|
1973
|
+
async function closePouchDB(db2) {
|
|
1974
|
+
if (!db2 || environment_default2.isTest()) {
|
|
1975
1975
|
return;
|
|
1976
1976
|
}
|
|
1977
1977
|
try {
|
|
1978
|
-
return await
|
|
1978
|
+
return await db2.close();
|
|
1979
1979
|
} catch (err) {
|
|
1980
1980
|
}
|
|
1981
1981
|
}
|
|
@@ -2126,14 +2126,14 @@ var init_DatabaseImpl = __esm({
|
|
|
2126
2126
|
}
|
|
2127
2127
|
}
|
|
2128
2128
|
async get(id) {
|
|
2129
|
-
const
|
|
2129
|
+
const db2 = await this.checkSetup();
|
|
2130
2130
|
if (!id) {
|
|
2131
2131
|
throw new Error("Unable to get doc without a valid _id.");
|
|
2132
2132
|
}
|
|
2133
|
-
return this.updateOutput(() =>
|
|
2133
|
+
return this.updateOutput(() => db2.get(id));
|
|
2134
2134
|
}
|
|
2135
|
-
async remove(idOrDoc,
|
|
2136
|
-
const
|
|
2135
|
+
async remove(idOrDoc, rev2) {
|
|
2136
|
+
const db2 = await this.checkSetup();
|
|
2137
2137
|
let _id;
|
|
2138
2138
|
let _rev;
|
|
2139
2139
|
if (isDocument(idOrDoc)) {
|
|
@@ -2141,12 +2141,12 @@ var init_DatabaseImpl = __esm({
|
|
|
2141
2141
|
_rev = idOrDoc._rev;
|
|
2142
2142
|
} else {
|
|
2143
2143
|
_id = idOrDoc;
|
|
2144
|
-
_rev =
|
|
2144
|
+
_rev = rev2;
|
|
2145
2145
|
}
|
|
2146
2146
|
if (!_id || !_rev) {
|
|
2147
2147
|
throw new Error("Unable to remove doc without a valid _id and _rev.");
|
|
2148
2148
|
}
|
|
2149
|
-
return this.updateOutput(() =>
|
|
2149
|
+
return this.updateOutput(() => db2.destroy(_id, _rev));
|
|
2150
2150
|
}
|
|
2151
2151
|
async post(document, opts) {
|
|
2152
2152
|
if (!document._id) {
|
|
@@ -2158,7 +2158,7 @@ var init_DatabaseImpl = __esm({
|
|
|
2158
2158
|
if (!document._id) {
|
|
2159
2159
|
throw new Error("Cannot store document without _id field.");
|
|
2160
2160
|
}
|
|
2161
|
-
const
|
|
2161
|
+
const db2 = await this.checkSetup();
|
|
2162
2162
|
if (!document.createdAt) {
|
|
2163
2163
|
document.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2164
2164
|
}
|
|
@@ -2175,20 +2175,20 @@ var init_DatabaseImpl = __esm({
|
|
|
2175
2175
|
}
|
|
2176
2176
|
}
|
|
2177
2177
|
}
|
|
2178
|
-
return this.updateOutput(() =>
|
|
2178
|
+
return this.updateOutput(() => db2.insert(document));
|
|
2179
2179
|
}
|
|
2180
2180
|
async bulkDocs(documents) {
|
|
2181
|
-
const
|
|
2182
|
-
return this.updateOutput(() =>
|
|
2181
|
+
const db2 = await this.checkSetup();
|
|
2182
|
+
return this.updateOutput(() => db2.bulk({ docs: documents }));
|
|
2183
2183
|
}
|
|
2184
2184
|
async allDocs(params2) {
|
|
2185
|
-
const
|
|
2186
|
-
return this.updateOutput(() =>
|
|
2185
|
+
const db2 = await this.checkSetup();
|
|
2186
|
+
return this.updateOutput(() => db2.list(params2));
|
|
2187
2187
|
}
|
|
2188
2188
|
async query(viewName, params2) {
|
|
2189
|
-
const
|
|
2189
|
+
const db2 = await this.checkSetup();
|
|
2190
2190
|
const [database, view] = viewName.split("/");
|
|
2191
|
-
return this.updateOutput(() =>
|
|
2191
|
+
return this.updateOutput(() => db2.view(database, view, params2));
|
|
2192
2192
|
}
|
|
2193
2193
|
async destroy() {
|
|
2194
2194
|
try {
|
|
@@ -2202,8 +2202,8 @@ var init_DatabaseImpl = __esm({
|
|
|
2202
2202
|
}
|
|
2203
2203
|
}
|
|
2204
2204
|
async compact() {
|
|
2205
|
-
const
|
|
2206
|
-
return this.updateOutput(() =>
|
|
2205
|
+
const db2 = await this.checkSetup();
|
|
2206
|
+
return this.updateOutput(() => db2.compact());
|
|
2207
2207
|
}
|
|
2208
2208
|
// All below functions are in-frequently called, just utilise PouchDB
|
|
2209
2209
|
// for them as it implements them better than we can
|
|
@@ -2246,8 +2246,8 @@ function getDB(dbName, opts) {
|
|
|
2246
2246
|
return new DatabaseImpl(dbName, opts);
|
|
2247
2247
|
}
|
|
2248
2248
|
async function doWithDB(dbName, cb, opts = {}) {
|
|
2249
|
-
const
|
|
2250
|
-
return await cb(
|
|
2249
|
+
const db2 = getDB(dbName, opts);
|
|
2250
|
+
return await cb(db2);
|
|
2251
2251
|
}
|
|
2252
2252
|
function allDbs() {
|
|
2253
2253
|
if (!environment_default2.isTest()) {
|
|
@@ -2595,11 +2595,11 @@ function getRedisOptions() {
|
|
|
2595
2595
|
}
|
|
2596
2596
|
return { opts, host, port: parseInt(port), redisProtocolUrl };
|
|
2597
2597
|
}
|
|
2598
|
-
function addDbPrefix(
|
|
2599
|
-
if (key.includes(
|
|
2598
|
+
function addDbPrefix(db2, key) {
|
|
2599
|
+
if (key.includes(db2)) {
|
|
2600
2600
|
return key;
|
|
2601
2601
|
}
|
|
2602
|
-
return `${
|
|
2602
|
+
return `${db2}${SEPARATOR2}${key}`;
|
|
2603
2603
|
}
|
|
2604
2604
|
function removeDbPrefix(key) {
|
|
2605
2605
|
let parts = key.split(SEPARATOR2);
|
|
@@ -2819,8 +2819,8 @@ var init_redis = __esm({
|
|
|
2819
2819
|
CONNECTED = true;
|
|
2820
2820
|
}
|
|
2821
2821
|
RedisWrapper = class {
|
|
2822
|
-
constructor(
|
|
2823
|
-
this._db =
|
|
2822
|
+
constructor(db2, selectDb = null) {
|
|
2823
|
+
this._db = db2;
|
|
2824
2824
|
this._select = selectDb || DEFAULT_SELECT_DB;
|
|
2825
2825
|
}
|
|
2826
2826
|
getClient() {
|
|
@@ -2840,8 +2840,8 @@ var init_redis = __esm({
|
|
|
2840
2840
|
this.getClient().disconnect();
|
|
2841
2841
|
}
|
|
2842
2842
|
async scan(key = "") {
|
|
2843
|
-
const
|
|
2844
|
-
key = `${
|
|
2843
|
+
const db2 = this._db;
|
|
2844
|
+
key = `${db2}${SEPARATOR2}${key}`;
|
|
2845
2845
|
let stream3;
|
|
2846
2846
|
if (CLUSTERED) {
|
|
2847
2847
|
let node = this.getClient().nodes("master");
|
|
@@ -2852,16 +2852,16 @@ var init_redis = __esm({
|
|
|
2852
2852
|
return promisifyStream(stream3, this.getClient());
|
|
2853
2853
|
}
|
|
2854
2854
|
async keys(pattern) {
|
|
2855
|
-
const
|
|
2856
|
-
return this.getClient().keys(addDbPrefix(
|
|
2855
|
+
const db2 = this._db;
|
|
2856
|
+
return this.getClient().keys(addDbPrefix(db2, pattern));
|
|
2857
2857
|
}
|
|
2858
2858
|
async exists(key) {
|
|
2859
|
-
const
|
|
2860
|
-
return await this.getClient().exists(addDbPrefix(
|
|
2859
|
+
const db2 = this._db;
|
|
2860
|
+
return await this.getClient().exists(addDbPrefix(db2, key));
|
|
2861
2861
|
}
|
|
2862
2862
|
async get(key) {
|
|
2863
|
-
const
|
|
2864
|
-
let response = await this.getClient().get(addDbPrefix(
|
|
2863
|
+
const db2 = this._db;
|
|
2864
|
+
let response = await this.getClient().get(addDbPrefix(db2, key));
|
|
2865
2865
|
if (response != null && response.key) {
|
|
2866
2866
|
response.key = key;
|
|
2867
2867
|
}
|
|
@@ -2872,11 +2872,11 @@ var init_redis = __esm({
|
|
|
2872
2872
|
}
|
|
2873
2873
|
}
|
|
2874
2874
|
async bulkGet(keys2) {
|
|
2875
|
-
const
|
|
2875
|
+
const db2 = this._db;
|
|
2876
2876
|
if (keys2.length === 0) {
|
|
2877
2877
|
return {};
|
|
2878
2878
|
}
|
|
2879
|
-
const prefixedKeys = keys2.map((key) => addDbPrefix(
|
|
2879
|
+
const prefixedKeys = keys2.map((key) => addDbPrefix(db2, key));
|
|
2880
2880
|
let response = await this.getClient().mget(prefixedKeys);
|
|
2881
2881
|
if (Array.isArray(response)) {
|
|
2882
2882
|
let final = {};
|
|
@@ -2899,29 +2899,29 @@ var init_redis = __esm({
|
|
|
2899
2899
|
}
|
|
2900
2900
|
}
|
|
2901
2901
|
async store(key, value, expirySeconds = null) {
|
|
2902
|
-
const
|
|
2902
|
+
const db2 = this._db;
|
|
2903
2903
|
if (typeof value === "object") {
|
|
2904
2904
|
value = JSON.stringify(value);
|
|
2905
2905
|
}
|
|
2906
|
-
const prefixedKey = addDbPrefix(
|
|
2906
|
+
const prefixedKey = addDbPrefix(db2, key);
|
|
2907
2907
|
await this.getClient().set(prefixedKey, value);
|
|
2908
2908
|
if (expirySeconds) {
|
|
2909
2909
|
await this.getClient().expire(prefixedKey, expirySeconds);
|
|
2910
2910
|
}
|
|
2911
2911
|
}
|
|
2912
2912
|
async getTTL(key) {
|
|
2913
|
-
const
|
|
2914
|
-
const prefixedKey = addDbPrefix(
|
|
2913
|
+
const db2 = this._db;
|
|
2914
|
+
const prefixedKey = addDbPrefix(db2, key);
|
|
2915
2915
|
return this.getClient().ttl(prefixedKey);
|
|
2916
2916
|
}
|
|
2917
2917
|
async setExpiry(key, expirySeconds) {
|
|
2918
|
-
const
|
|
2919
|
-
const prefixedKey = addDbPrefix(
|
|
2918
|
+
const db2 = this._db;
|
|
2919
|
+
const prefixedKey = addDbPrefix(db2, key);
|
|
2920
2920
|
await this.getClient().expire(prefixedKey, expirySeconds);
|
|
2921
2921
|
}
|
|
2922
2922
|
async delete(key) {
|
|
2923
|
-
const
|
|
2924
|
-
await this.getClient().del(addDbPrefix(
|
|
2923
|
+
const db2 = this._db;
|
|
2924
|
+
await this.getClient().del(addDbPrefix(db2, key));
|
|
2925
2925
|
}
|
|
2926
2926
|
async clear() {
|
|
2927
2927
|
let items = await this.scan();
|
|
@@ -3297,8 +3297,8 @@ function logAlert(message, e) {
|
|
|
3297
3297
|
}
|
|
3298
3298
|
console.error(`bb-alert: ${message}`, e);
|
|
3299
3299
|
}
|
|
3300
|
-
function logAlertWithInfo(message,
|
|
3301
|
-
message = `${message} - db: ${
|
|
3300
|
+
function logAlertWithInfo(message, db2, id, error) {
|
|
3301
|
+
message = `${message} - db: ${db2} - doc: ${id} - error: `;
|
|
3302
3302
|
logAlert(message, error);
|
|
3303
3303
|
}
|
|
3304
3304
|
function logWarn(message) {
|
|
@@ -3335,8 +3335,8 @@ var init_logging = __esm({
|
|
|
3335
3335
|
var require_Helper = __commonJS({
|
|
3336
3336
|
"../string-templates/src/helpers/Helper.js"(exports2, module2) {
|
|
3337
3337
|
var Helper = class {
|
|
3338
|
-
constructor(
|
|
3339
|
-
this.name =
|
|
3338
|
+
constructor(name2, fn, useValueFallback = true) {
|
|
3339
|
+
this.name = name2;
|
|
3340
3340
|
this.fn = fn;
|
|
3341
3341
|
this.useValueFallback = useValueFallback;
|
|
3342
3342
|
}
|
|
@@ -3505,18 +3505,18 @@ var require_external = __commonJS({
|
|
|
3505
3505
|
exports2.externalCollections = EXTERNAL_FUNCTION_COLLECTIONS;
|
|
3506
3506
|
exports2.addedHelpers = ADDED_HELPERS;
|
|
3507
3507
|
exports2.registerAll = (handlebars) => {
|
|
3508
|
-
for (let [
|
|
3509
|
-
handlebars.registerHelper(
|
|
3508
|
+
for (let [name2, helper] of Object.entries(ADDED_HELPERS)) {
|
|
3509
|
+
handlebars.registerHelper(name2, helper);
|
|
3510
3510
|
}
|
|
3511
3511
|
let externalNames = [];
|
|
3512
3512
|
for (let collection of EXTERNAL_FUNCTION_COLLECTIONS) {
|
|
3513
3513
|
let hbsHelperInfo = helpers[collection]();
|
|
3514
3514
|
for (let entry of Object.entries(hbsHelperInfo)) {
|
|
3515
|
-
const
|
|
3516
|
-
if (HelperFunctionBuiltin.indexOf(
|
|
3515
|
+
const name2 = entry[0];
|
|
3516
|
+
if (HelperFunctionBuiltin.indexOf(name2) !== -1 || externalNames.indexOf(name2) !== -1) {
|
|
3517
3517
|
continue;
|
|
3518
3518
|
}
|
|
3519
|
-
externalNames.push(
|
|
3519
|
+
externalNames.push(name2);
|
|
3520
3520
|
}
|
|
3521
3521
|
helpers[collection]({
|
|
3522
3522
|
handlebars
|
|
@@ -3525,11 +3525,11 @@ var require_external = __commonJS({
|
|
|
3525
3525
|
exports2.externalHelperNames = externalNames.concat(Object.keys(ADDED_HELPERS));
|
|
3526
3526
|
};
|
|
3527
3527
|
exports2.unregisterAll = (handlebars) => {
|
|
3528
|
-
for (let
|
|
3529
|
-
handlebars.unregisterHelper(
|
|
3528
|
+
for (let name2 of Object.keys(ADDED_HELPERS)) {
|
|
3529
|
+
handlebars.unregisterHelper(name2);
|
|
3530
3530
|
}
|
|
3531
|
-
for (let
|
|
3532
|
-
handlebars.unregisterHelper(
|
|
3531
|
+
for (let name2 of module2.exports.externalHelperNames) {
|
|
3532
|
+
handlebars.unregisterHelper(name2);
|
|
3533
3533
|
}
|
|
3534
3534
|
exports2.externalHelperNames = [];
|
|
3535
3535
|
};
|
|
@@ -3643,12 +3643,12 @@ var require_javascript = __commonJS({
|
|
|
3643
3643
|
throw new Error("JS disabled in environment.");
|
|
3644
3644
|
}
|
|
3645
3645
|
try {
|
|
3646
|
-
const
|
|
3646
|
+
const js2 = `function run(){${atob(handlebars)}};run();`;
|
|
3647
3647
|
const sandboxContext = {
|
|
3648
3648
|
$: (path2) => getContextValue(path2, cloneDeep7(context)),
|
|
3649
3649
|
helpers: getHelperList()
|
|
3650
3650
|
};
|
|
3651
|
-
const res = { data: runJS(
|
|
3651
|
+
const res = { data: runJS(js2, sandboxContext) };
|
|
3652
3652
|
return `{{${LITERAL_MARKER} js_result-${JSON.stringify(res)}}}`;
|
|
3653
3653
|
} catch (error) {
|
|
3654
3654
|
return "Error while executing JS";
|
|
@@ -3761,8 +3761,8 @@ var require_preprocessor = __commonJS({
|
|
|
3761
3761
|
FINALISE: "finalise"
|
|
3762
3762
|
};
|
|
3763
3763
|
var Preprocessor = class {
|
|
3764
|
-
constructor(
|
|
3765
|
-
this.name =
|
|
3764
|
+
constructor(name2, fn) {
|
|
3765
|
+
this.name = name2;
|
|
3766
3766
|
this.fn = fn;
|
|
3767
3767
|
}
|
|
3768
3768
|
process(fullString, statement, opts) {
|
|
@@ -3826,8 +3826,8 @@ var require_postprocessor = __commonJS({
|
|
|
3826
3826
|
CONVERT_LITERALS: "convert-literals"
|
|
3827
3827
|
};
|
|
3828
3828
|
var Postprocessor = class {
|
|
3829
|
-
constructor(
|
|
3830
|
-
this.name =
|
|
3829
|
+
constructor(name2, fn) {
|
|
3830
|
+
this.name = name2;
|
|
3831
3831
|
this.fn = fn;
|
|
3832
3832
|
}
|
|
3833
3833
|
process(statement) {
|
|
@@ -5469,10 +5469,10 @@ var require_src = __commonJS({
|
|
|
5469
5469
|
};
|
|
5470
5470
|
module2.exports.convertToJS = (hbs) => {
|
|
5471
5471
|
const blocks = exports2.findHBSBlocks(hbs);
|
|
5472
|
-
let
|
|
5472
|
+
let js2 = "return `", prevBlock = null;
|
|
5473
5473
|
const variables = {};
|
|
5474
5474
|
if (blocks.length === 0) {
|
|
5475
|
-
|
|
5475
|
+
js2 += hbs;
|
|
5476
5476
|
}
|
|
5477
5477
|
let count = 1;
|
|
5478
5478
|
for (let block of blocks) {
|
|
@@ -5484,15 +5484,15 @@ var require_src = __commonJS({
|
|
|
5484
5484
|
prevBlock = block;
|
|
5485
5485
|
const { variable, value } = convertHBSBlock(block, count++);
|
|
5486
5486
|
variables[variable] = value;
|
|
5487
|
-
|
|
5487
|
+
js2 += `${stringPart.split()}\${${variable}}`;
|
|
5488
5488
|
}
|
|
5489
5489
|
let varBlock = "";
|
|
5490
5490
|
for (let [variable, value] of Object.entries(variables)) {
|
|
5491
5491
|
varBlock += `const ${variable} = ${value};
|
|
5492
5492
|
`;
|
|
5493
5493
|
}
|
|
5494
|
-
|
|
5495
|
-
return `${varBlock}${
|
|
5494
|
+
js2 += "`;";
|
|
5495
|
+
return `${varBlock}${js2}`;
|
|
5496
5496
|
};
|
|
5497
5497
|
}
|
|
5498
5498
|
});
|
|
@@ -5519,12 +5519,12 @@ var require_src2 = __commonJS({
|
|
|
5519
5519
|
if (!process.env.NO_JS) {
|
|
5520
5520
|
const { VM: VM2 } = require("vm2");
|
|
5521
5521
|
const { setJSRunner } = require_javascript();
|
|
5522
|
-
setJSRunner((
|
|
5522
|
+
setJSRunner((js2, context) => {
|
|
5523
5523
|
const vm = new VM2({
|
|
5524
5524
|
sandbox: context,
|
|
5525
5525
|
timeout: 1e3
|
|
5526
5526
|
});
|
|
5527
|
-
return vm.run(
|
|
5527
|
+
return vm.run(js2);
|
|
5528
5528
|
});
|
|
5529
5529
|
}
|
|
5530
5530
|
}
|
|
@@ -5875,8 +5875,8 @@ async function lookupTenantId(userId) {
|
|
|
5875
5875
|
return user.tenantId;
|
|
5876
5876
|
}
|
|
5877
5877
|
async function getUserDoc(emailOrId) {
|
|
5878
|
-
const
|
|
5879
|
-
return
|
|
5878
|
+
const db2 = getPlatformDB();
|
|
5879
|
+
return db2.get(emailOrId);
|
|
5880
5880
|
}
|
|
5881
5881
|
function newUserIdDoc(id, tenantId) {
|
|
5882
5882
|
return {
|
|
@@ -5892,14 +5892,14 @@ function newUserEmailDoc(userId, email, tenantId) {
|
|
|
5892
5892
|
};
|
|
5893
5893
|
}
|
|
5894
5894
|
async function addUserDoc(emailOrId, newDocFn) {
|
|
5895
|
-
const
|
|
5895
|
+
const db2 = getPlatformDB();
|
|
5896
5896
|
let user;
|
|
5897
5897
|
try {
|
|
5898
|
-
await
|
|
5898
|
+
await db2.get(emailOrId);
|
|
5899
5899
|
} catch (e) {
|
|
5900
5900
|
if (e.status === 404) {
|
|
5901
5901
|
user = newDocFn();
|
|
5902
|
-
await
|
|
5902
|
+
await db2.put(user);
|
|
5903
5903
|
} else {
|
|
5904
5904
|
throw e;
|
|
5905
5905
|
}
|
|
@@ -5912,9 +5912,9 @@ async function addUser(tenantId, userId, email) {
|
|
|
5912
5912
|
]);
|
|
5913
5913
|
}
|
|
5914
5914
|
async function removeUser(user) {
|
|
5915
|
-
const
|
|
5915
|
+
const db2 = getPlatformDB();
|
|
5916
5916
|
const keys2 = [user._id, user.email];
|
|
5917
|
-
const userDocs = await
|
|
5917
|
+
const userDocs = await db2.allDocs({
|
|
5918
5918
|
keys: keys2,
|
|
5919
5919
|
include_docs: true
|
|
5920
5920
|
});
|
|
@@ -5924,7 +5924,7 @@ async function removeUser(user) {
|
|
|
5924
5924
|
_deleted: true
|
|
5925
5925
|
};
|
|
5926
5926
|
});
|
|
5927
|
-
await
|
|
5927
|
+
await db2.bulkDocs(toDelete);
|
|
5928
5928
|
}
|
|
5929
5929
|
|
|
5930
5930
|
// ../backend-core/src/platform/tenants.ts
|
|
@@ -6009,18 +6009,18 @@ async function newRedlock(opts = {}) {
|
|
|
6009
6009
|
}
|
|
6010
6010
|
function getLockName(opts) {
|
|
6011
6011
|
const prefix = opts.systemLock ? "system" : getTenantId();
|
|
6012
|
-
let
|
|
6012
|
+
let name2 = `lock:${prefix}_${opts.name}`;
|
|
6013
6013
|
if (opts.resource) {
|
|
6014
|
-
|
|
6014
|
+
name2 = name2 + `_${opts.resource}`;
|
|
6015
6015
|
}
|
|
6016
|
-
return
|
|
6016
|
+
return name2;
|
|
6017
6017
|
}
|
|
6018
6018
|
async function doWithLock(opts, task) {
|
|
6019
6019
|
const redlock = await getClient(opts.type, opts.customOptions);
|
|
6020
6020
|
let lock;
|
|
6021
6021
|
try {
|
|
6022
|
-
const
|
|
6023
|
-
lock = await redlock.lock(
|
|
6022
|
+
const name2 = getLockName(opts);
|
|
6023
|
+
lock = await redlock.lock(name2, opts.ttl);
|
|
6024
6024
|
const result = await task();
|
|
6025
6025
|
return { executed: true, result };
|
|
6026
6026
|
} catch (e) {
|
|
@@ -6130,8 +6130,8 @@ var getAccount = async (email) => {
|
|
|
6130
6130
|
// ../backend-core/src/cache/user.ts
|
|
6131
6131
|
var EXPIRY_SECONDS = 3600;
|
|
6132
6132
|
async function populateFromDB(userId, tenantId) {
|
|
6133
|
-
const
|
|
6134
|
-
const user = await
|
|
6133
|
+
const db2 = getTenantDB(tenantId);
|
|
6134
|
+
const user = await db2.get(userId);
|
|
6135
6135
|
user.budibaseAccess = true;
|
|
6136
6136
|
if (!environment_default2.SELF_HOSTED && !environment_default2.DISABLE_ACCOUNT_PORTAL) {
|
|
6137
6137
|
const account = await getAccount(user.email);
|
|
@@ -6320,8 +6320,8 @@ function generateRoleID(id) {
|
|
|
6320
6320
|
var generateDevInfoID = (userId) => {
|
|
6321
6321
|
return `${"devinfo" /* DEV_INFO */}${SEPARATOR}${userId}`;
|
|
6322
6322
|
};
|
|
6323
|
-
var generatePluginID = (
|
|
6324
|
-
return `${"plg" /* PLUGIN */}${SEPARATOR}${
|
|
6323
|
+
var generatePluginID = (name2) => {
|
|
6324
|
+
return `${"plg" /* PLUGIN */}${SEPARATOR}${name2}`;
|
|
6325
6325
|
};
|
|
6326
6326
|
|
|
6327
6327
|
// ../backend-core/src/docIds/params.ts
|
|
@@ -6406,8 +6406,8 @@ function getStartEndKeyURL(baseKey, tenantId) {
|
|
|
6406
6406
|
const tenancy2 = tenantId ? `${SEPARATOR}${tenantId}` : "";
|
|
6407
6407
|
return `startkey="${baseKey}${tenancy2}"&endkey="${baseKey}${tenancy2}${UNICODE_MAX}"`;
|
|
6408
6408
|
}
|
|
6409
|
-
var getPluginParams = (
|
|
6410
|
-
return getDocParams("plg" /* PLUGIN */,
|
|
6409
|
+
var getPluginParams = (pluginId2, otherProps = {}) => {
|
|
6410
|
+
return getDocParams("plg" /* PLUGIN */, pluginId2, otherProps);
|
|
6411
6411
|
};
|
|
6412
6412
|
|
|
6413
6413
|
// ../backend-core/src/db/utils.ts
|
|
@@ -6514,8 +6514,8 @@ function isSameAppID(appId1, appId2) {
|
|
|
6514
6514
|
async function dbExists(dbName) {
|
|
6515
6515
|
return doWithDB(
|
|
6516
6516
|
dbName,
|
|
6517
|
-
async (
|
|
6518
|
-
return await
|
|
6517
|
+
async (db2) => {
|
|
6518
|
+
return await db2.exists();
|
|
6519
6519
|
},
|
|
6520
6520
|
{ skip_setup: true }
|
|
6521
6521
|
);
|
|
@@ -6534,7 +6534,7 @@ function pagination(data, pageSize, {
|
|
|
6534
6534
|
const hasNextPage = data.length > pageSize;
|
|
6535
6535
|
let nextPage = void 0;
|
|
6536
6536
|
if (!getKey) {
|
|
6537
|
-
getKey = (
|
|
6537
|
+
getKey = (doc2) => property ? doc2 == null ? void 0 : doc2[property] : doc2 == null ? void 0 : doc2._id;
|
|
6538
6538
|
}
|
|
6539
6539
|
if (hasNextPage) {
|
|
6540
6540
|
nextPage = getKey(data[pageSize]);
|
|
@@ -6559,23 +6559,23 @@ function DesignDoc() {
|
|
|
6559
6559
|
views: {}
|
|
6560
6560
|
};
|
|
6561
6561
|
}
|
|
6562
|
-
async function removeDeprecated(
|
|
6562
|
+
async function removeDeprecated(db2, viewName) {
|
|
6563
6563
|
if (!DeprecatedViews[viewName]) {
|
|
6564
6564
|
return;
|
|
6565
6565
|
}
|
|
6566
6566
|
try {
|
|
6567
|
-
const designDoc = await
|
|
6567
|
+
const designDoc = await db2.get(DESIGN_DB);
|
|
6568
6568
|
for (let deprecatedNames of DeprecatedViews[viewName]) {
|
|
6569
6569
|
delete designDoc.views[deprecatedNames];
|
|
6570
6570
|
}
|
|
6571
|
-
await
|
|
6571
|
+
await db2.put(designDoc);
|
|
6572
6572
|
} catch (err) {
|
|
6573
6573
|
}
|
|
6574
6574
|
}
|
|
6575
|
-
async function createView(
|
|
6575
|
+
async function createView(db2, viewJs, viewName) {
|
|
6576
6576
|
let designDoc;
|
|
6577
6577
|
try {
|
|
6578
|
-
designDoc = await
|
|
6578
|
+
designDoc = await db2.get(DESIGN_DB);
|
|
6579
6579
|
} catch (err) {
|
|
6580
6580
|
designDoc = DesignDoc();
|
|
6581
6581
|
}
|
|
@@ -6587,26 +6587,26 @@ async function createView(db, viewJs, viewName) {
|
|
|
6587
6587
|
[viewName]: view
|
|
6588
6588
|
};
|
|
6589
6589
|
try {
|
|
6590
|
-
await
|
|
6590
|
+
await db2.put(designDoc);
|
|
6591
6591
|
} catch (err) {
|
|
6592
6592
|
if (err.status === 409) {
|
|
6593
|
-
return await createView(
|
|
6593
|
+
return await createView(db2, viewJs, viewName);
|
|
6594
6594
|
} else {
|
|
6595
6595
|
throw err;
|
|
6596
6596
|
}
|
|
6597
6597
|
}
|
|
6598
6598
|
}
|
|
6599
6599
|
var createNewUserEmailView = async () => {
|
|
6600
|
-
const
|
|
6600
|
+
const db2 = getGlobalDB();
|
|
6601
6601
|
const viewJs = `function(doc) {
|
|
6602
6602
|
if (doc._id.startsWith("${"us" /* USER */}${SEPARATOR}")) {
|
|
6603
6603
|
emit(doc.email.toLowerCase(), doc._id)
|
|
6604
6604
|
}
|
|
6605
6605
|
}`;
|
|
6606
|
-
await createView(
|
|
6606
|
+
await createView(db2, viewJs, "by_email2" /* USER_BY_EMAIL */);
|
|
6607
6607
|
};
|
|
6608
6608
|
var createUserAppView = async () => {
|
|
6609
|
-
const
|
|
6609
|
+
const db2 = getGlobalDB();
|
|
6610
6610
|
const viewJs = `function(doc) {
|
|
6611
6611
|
if (doc._id.startsWith("${"us" /* USER */}${SEPARATOR}") && doc.roles) {
|
|
6612
6612
|
for (let prodAppId of Object.keys(doc.roles)) {
|
|
@@ -6615,46 +6615,46 @@ var createUserAppView = async () => {
|
|
|
6615
6615
|
}
|
|
6616
6616
|
}
|
|
6617
6617
|
}`;
|
|
6618
|
-
await createView(
|
|
6618
|
+
await createView(db2, viewJs, "by_app" /* USER_BY_APP */);
|
|
6619
6619
|
};
|
|
6620
6620
|
var createApiKeyView = async () => {
|
|
6621
|
-
const
|
|
6621
|
+
const db2 = getGlobalDB();
|
|
6622
6622
|
const viewJs = `function(doc) {
|
|
6623
6623
|
if (doc._id.startsWith("${"devinfo" /* DEV_INFO */}") && doc.apiKey) {
|
|
6624
6624
|
emit(doc.apiKey, doc.userId)
|
|
6625
6625
|
}
|
|
6626
6626
|
}`;
|
|
6627
|
-
await createView(
|
|
6627
|
+
await createView(db2, viewJs, "by_api_key" /* BY_API_KEY */);
|
|
6628
6628
|
};
|
|
6629
6629
|
var createUserBuildersView = async () => {
|
|
6630
|
-
const
|
|
6630
|
+
const db2 = getGlobalDB();
|
|
6631
6631
|
const viewJs = `function(doc) {
|
|
6632
6632
|
if (doc.builder && doc.builder.global === true) {
|
|
6633
6633
|
emit(doc._id, doc._id)
|
|
6634
6634
|
}
|
|
6635
6635
|
}`;
|
|
6636
|
-
await createView(
|
|
6636
|
+
await createView(db2, viewJs, "by_builders" /* USER_BY_BUILDERS */);
|
|
6637
6637
|
};
|
|
6638
|
-
async function queryViewRaw(viewName, params2,
|
|
6638
|
+
async function queryViewRaw(viewName, params2, db2, createFunc, opts) {
|
|
6639
6639
|
try {
|
|
6640
|
-
const response = await
|
|
6640
|
+
const response = await db2.query(`database/${viewName}`, params2);
|
|
6641
6641
|
return response;
|
|
6642
6642
|
} catch (err) {
|
|
6643
6643
|
const pouchNotFound = err && err.name === "not_found";
|
|
6644
6644
|
const couchNotFound = err && err.status === 404;
|
|
6645
6645
|
if (pouchNotFound || couchNotFound) {
|
|
6646
|
-
await removeDeprecated(
|
|
6646
|
+
await removeDeprecated(db2, viewName);
|
|
6647
6647
|
await createFunc();
|
|
6648
|
-
return queryViewRaw(viewName, params2,
|
|
6648
|
+
return queryViewRaw(viewName, params2, db2, createFunc, opts);
|
|
6649
6649
|
} else if (err.status === 409) {
|
|
6650
|
-
return queryViewRaw(viewName, params2,
|
|
6650
|
+
return queryViewRaw(viewName, params2, db2, createFunc, opts);
|
|
6651
6651
|
} else {
|
|
6652
6652
|
throw err;
|
|
6653
6653
|
}
|
|
6654
6654
|
}
|
|
6655
6655
|
}
|
|
6656
|
-
var queryView = async (viewName, params2,
|
|
6657
|
-
const response = await queryViewRaw(viewName, params2,
|
|
6656
|
+
var queryView = async (viewName, params2, db2, createFunc, opts) => {
|
|
6657
|
+
const response = await queryViewRaw(viewName, params2, db2, createFunc, opts);
|
|
6658
6658
|
const rows2 = response.rows;
|
|
6659
6659
|
const docs = rows2.map(
|
|
6660
6660
|
(row) => params2.include_docs ? row.doc : row.value
|
|
@@ -6667,8 +6667,8 @@ var queryView = async (viewName, params2, db, createFunc, opts) => {
|
|
|
6667
6667
|
};
|
|
6668
6668
|
async function createPlatformView(viewJs, viewName) {
|
|
6669
6669
|
try {
|
|
6670
|
-
await doWithDB(StaticDatabases.PLATFORM_INFO.name, async (
|
|
6671
|
-
await createView(
|
|
6670
|
+
await doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db2) => {
|
|
6671
|
+
await createView(db2, viewJs, viewName);
|
|
6672
6672
|
});
|
|
6673
6673
|
} catch (e) {
|
|
6674
6674
|
if (e.status === 409 && environment_default2.isTest()) {
|
|
@@ -6698,9 +6698,9 @@ var queryPlatformView = async (viewName, params2, opts) => {
|
|
|
6698
6698
|
["account_by_email" /* ACCOUNT_BY_EMAIL */]: createPlatformAccountEmailView,
|
|
6699
6699
|
["platform_users_lowercase" /* PLATFORM_USERS_LOWERCASE */]: createPlatformUserView
|
|
6700
6700
|
};
|
|
6701
|
-
return doWithDB(StaticDatabases.PLATFORM_INFO.name, async (
|
|
6701
|
+
return doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db2) => {
|
|
6702
6702
|
const createFn = CreateFuncByName2[viewName];
|
|
6703
|
-
return queryView(viewName, params2,
|
|
6703
|
+
return queryView(viewName, params2, db2, createFn, opts);
|
|
6704
6704
|
});
|
|
6705
6705
|
};
|
|
6706
6706
|
var CreateFuncByName = {
|
|
@@ -6709,17 +6709,17 @@ var CreateFuncByName = {
|
|
|
6709
6709
|
["by_builders" /* USER_BY_BUILDERS */]: createUserBuildersView,
|
|
6710
6710
|
["by_app" /* USER_BY_APP */]: createUserAppView
|
|
6711
6711
|
};
|
|
6712
|
-
var queryGlobalView = async (viewName, params2,
|
|
6713
|
-
if (!
|
|
6714
|
-
|
|
6712
|
+
var queryGlobalView = async (viewName, params2, db2, opts) => {
|
|
6713
|
+
if (!db2) {
|
|
6714
|
+
db2 = getGlobalDB();
|
|
6715
6715
|
}
|
|
6716
6716
|
const createFn = CreateFuncByName[viewName];
|
|
6717
|
-
return queryView(viewName, params2,
|
|
6717
|
+
return queryView(viewName, params2, db2, createFn, opts);
|
|
6718
6718
|
};
|
|
6719
6719
|
async function queryGlobalViewRaw(viewName, params2, opts) {
|
|
6720
|
-
const
|
|
6720
|
+
const db2 = getGlobalDB();
|
|
6721
6721
|
const createFn = CreateFuncByName[viewName];
|
|
6722
|
-
return queryViewRaw(viewName, params2,
|
|
6722
|
+
return queryViewRaw(viewName, params2, db2, createFn, opts);
|
|
6723
6723
|
}
|
|
6724
6724
|
|
|
6725
6725
|
// ../backend-core/src/db/index.ts
|
|
@@ -6734,8 +6734,8 @@ var Replication = class {
|
|
|
6734
6734
|
* @param {String} source - the DB you want to replicate or rollback to
|
|
6735
6735
|
* @param {String} target - the DB you want to replicate to, or rollback from
|
|
6736
6736
|
*/
|
|
6737
|
-
constructor({ source, target }) {
|
|
6738
|
-
this.source = getPouchDB(
|
|
6737
|
+
constructor({ source: source2, target }) {
|
|
6738
|
+
this.source = getPouchDB(source2);
|
|
6739
6739
|
this.target = getPouchDB(target);
|
|
6740
6740
|
}
|
|
6741
6741
|
close() {
|
|
@@ -6770,8 +6770,8 @@ var Replication = class {
|
|
|
6770
6770
|
}
|
|
6771
6771
|
appReplicateOpts() {
|
|
6772
6772
|
return {
|
|
6773
|
-
filter: (
|
|
6774
|
-
return
|
|
6773
|
+
filter: (doc2) => {
|
|
6774
|
+
return doc2._id !== "app_metadata" /* APP_METADATA */;
|
|
6775
6775
|
}
|
|
6776
6776
|
};
|
|
6777
6777
|
}
|
|
@@ -6859,9 +6859,9 @@ var _QueryBuilder = class {
|
|
|
6859
6859
|
__privateSet(this, _indexBuilder, builderFn);
|
|
6860
6860
|
return this;
|
|
6861
6861
|
}
|
|
6862
|
-
setVersion(
|
|
6863
|
-
if (
|
|
6864
|
-
__privateSet(this, _version,
|
|
6862
|
+
setVersion(version2) {
|
|
6863
|
+
if (version2 != null) {
|
|
6864
|
+
__privateSet(this, _version, version2);
|
|
6865
6865
|
}
|
|
6866
6866
|
return this;
|
|
6867
6867
|
}
|
|
@@ -7354,10 +7354,10 @@ __export(searchIndexes_exports, {
|
|
|
7354
7354
|
init_src();
|
|
7355
7355
|
init_context2();
|
|
7356
7356
|
async function createUserIndex() {
|
|
7357
|
-
const
|
|
7357
|
+
const db2 = getGlobalDB();
|
|
7358
7358
|
let designDoc;
|
|
7359
7359
|
try {
|
|
7360
|
-
designDoc = await
|
|
7360
|
+
designDoc = await db2.get("_design/database");
|
|
7361
7361
|
} catch (err) {
|
|
7362
7362
|
if (err.status === 404) {
|
|
7363
7363
|
designDoc = { _id: "_design/database" };
|
|
@@ -7403,7 +7403,7 @@ async function createUserIndex() {
|
|
|
7403
7403
|
}
|
|
7404
7404
|
}
|
|
7405
7405
|
};
|
|
7406
|
-
await
|
|
7406
|
+
await db2.put(designDoc);
|
|
7407
7407
|
}
|
|
7408
7408
|
|
|
7409
7409
|
// ../backend-core/src/cache/appMetadata.ts
|
|
@@ -7414,42 +7414,42 @@ var EXPIRY_SECONDS2 = 3600;
|
|
|
7414
7414
|
async function populateFromDB2(appId) {
|
|
7415
7415
|
return doWithDB(
|
|
7416
7416
|
appId,
|
|
7417
|
-
(
|
|
7418
|
-
return
|
|
7417
|
+
(db2) => {
|
|
7418
|
+
return db2.get("app_metadata" /* APP_METADATA */);
|
|
7419
7419
|
},
|
|
7420
7420
|
{ skip_setup: true }
|
|
7421
7421
|
);
|
|
7422
7422
|
}
|
|
7423
|
-
function isInvalid(
|
|
7424
|
-
return !
|
|
7423
|
+
function isInvalid(metadata2) {
|
|
7424
|
+
return !metadata2 || metadata2.state === AppState.INVALID;
|
|
7425
7425
|
}
|
|
7426
7426
|
async function getAppMetadata(appId) {
|
|
7427
7427
|
const client3 = await getAppClient();
|
|
7428
|
-
let
|
|
7429
|
-
if (!
|
|
7428
|
+
let metadata2 = await client3.get(appId);
|
|
7429
|
+
if (!metadata2) {
|
|
7430
7430
|
let expiry = EXPIRY_SECONDS2;
|
|
7431
7431
|
try {
|
|
7432
|
-
|
|
7432
|
+
metadata2 = await populateFromDB2(appId);
|
|
7433
7433
|
} catch (err) {
|
|
7434
7434
|
if (err && err.status === 404) {
|
|
7435
|
-
|
|
7435
|
+
metadata2 = { state: AppState.INVALID };
|
|
7436
7436
|
expiry = void 0;
|
|
7437
7437
|
} else {
|
|
7438
7438
|
throw err;
|
|
7439
7439
|
}
|
|
7440
7440
|
}
|
|
7441
|
-
if (isInvalid(
|
|
7441
|
+
if (isInvalid(metadata2)) {
|
|
7442
7442
|
const temp = await client3.get(appId);
|
|
7443
7443
|
if (temp) {
|
|
7444
|
-
|
|
7444
|
+
metadata2 = temp;
|
|
7445
7445
|
}
|
|
7446
7446
|
}
|
|
7447
|
-
await client3.store(appId,
|
|
7447
|
+
await client3.store(appId, metadata2, expiry);
|
|
7448
7448
|
}
|
|
7449
|
-
if (isInvalid(
|
|
7449
|
+
if (isInvalid(metadata2)) {
|
|
7450
7450
|
throw { status: 404, message: "No app metadata found" };
|
|
7451
7451
|
}
|
|
7452
|
-
return
|
|
7452
|
+
return metadata2;
|
|
7453
7453
|
}
|
|
7454
7454
|
async function invalidateAppMetadata(appId, newMetadata) {
|
|
7455
7455
|
if (!appId) {
|
|
@@ -7480,21 +7480,21 @@ async function getCache() {
|
|
|
7480
7480
|
}
|
|
7481
7481
|
return CACHE;
|
|
7482
7482
|
}
|
|
7483
|
-
function makeCacheKey(
|
|
7484
|
-
return
|
|
7483
|
+
function makeCacheKey(db2, key) {
|
|
7484
|
+
return db2.name + key;
|
|
7485
7485
|
}
|
|
7486
|
-
function makeCacheItem(
|
|
7487
|
-
return { doc, lastWrite: lastWrite || Date.now() };
|
|
7486
|
+
function makeCacheItem(doc2, lastWrite = null) {
|
|
7487
|
+
return { doc: doc2, lastWrite: lastWrite || Date.now() };
|
|
7488
7488
|
}
|
|
7489
|
-
async function put(
|
|
7489
|
+
async function put(db2, doc2, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
7490
7490
|
const cache2 = await getCache();
|
|
7491
|
-
const key =
|
|
7491
|
+
const key = doc2._id;
|
|
7492
7492
|
let cacheItem;
|
|
7493
7493
|
if (key) {
|
|
7494
|
-
cacheItem = await cache2.get(makeCacheKey(
|
|
7494
|
+
cacheItem = await cache2.get(makeCacheKey(db2, key));
|
|
7495
7495
|
}
|
|
7496
7496
|
const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs;
|
|
7497
|
-
let output =
|
|
7497
|
+
let output = doc2;
|
|
7498
7498
|
if (updateDb) {
|
|
7499
7499
|
const lockResponse = await doWithLock(
|
|
7500
7500
|
{
|
|
@@ -7505,15 +7505,15 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
|
7505
7505
|
},
|
|
7506
7506
|
async () => {
|
|
7507
7507
|
const writeDb = async (toWrite) => {
|
|
7508
|
-
const response = await
|
|
7508
|
+
const response = await db2.put(toWrite, { force: true });
|
|
7509
7509
|
output = {
|
|
7510
|
-
...
|
|
7510
|
+
...doc2,
|
|
7511
7511
|
_id: response.id,
|
|
7512
7512
|
_rev: response.rev
|
|
7513
7513
|
};
|
|
7514
7514
|
};
|
|
7515
7515
|
try {
|
|
7516
|
-
await writeDb(
|
|
7516
|
+
await writeDb(doc2);
|
|
7517
7517
|
} catch (err) {
|
|
7518
7518
|
if (err.status !== 409) {
|
|
7519
7519
|
throw err;
|
|
@@ -7529,47 +7529,47 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
|
7529
7529
|
}
|
|
7530
7530
|
cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
|
|
7531
7531
|
if (output._id) {
|
|
7532
|
-
await cache2.store(makeCacheKey(
|
|
7532
|
+
await cache2.store(makeCacheKey(db2, output._id), cacheItem);
|
|
7533
7533
|
}
|
|
7534
7534
|
return { ok: true, id: output._id, rev: output._rev };
|
|
7535
7535
|
}
|
|
7536
|
-
async function get2(
|
|
7536
|
+
async function get2(db2, id) {
|
|
7537
7537
|
const cache2 = await getCache();
|
|
7538
|
-
const cacheKey = makeCacheKey(
|
|
7538
|
+
const cacheKey = makeCacheKey(db2, id);
|
|
7539
7539
|
let cacheItem = await cache2.get(cacheKey);
|
|
7540
7540
|
if (!cacheItem) {
|
|
7541
|
-
const
|
|
7542
|
-
cacheItem = makeCacheItem(
|
|
7541
|
+
const doc2 = await db2.get(id);
|
|
7542
|
+
cacheItem = makeCacheItem(doc2);
|
|
7543
7543
|
await cache2.store(cacheKey, cacheItem);
|
|
7544
7544
|
}
|
|
7545
7545
|
return cacheItem.doc;
|
|
7546
7546
|
}
|
|
7547
|
-
async function remove(
|
|
7547
|
+
async function remove(db2, docOrId, rev2) {
|
|
7548
7548
|
const cache2 = await getCache();
|
|
7549
7549
|
if (!docOrId) {
|
|
7550
7550
|
throw new Error("No ID/Rev provided.");
|
|
7551
7551
|
}
|
|
7552
7552
|
const id = typeof docOrId === "string" ? docOrId : docOrId._id;
|
|
7553
|
-
|
|
7553
|
+
rev2 = typeof docOrId === "string" ? rev2 : docOrId._rev;
|
|
7554
7554
|
try {
|
|
7555
|
-
await cache2.delete(makeCacheKey(
|
|
7555
|
+
await cache2.delete(makeCacheKey(db2, id));
|
|
7556
7556
|
} finally {
|
|
7557
|
-
await
|
|
7557
|
+
await db2.remove(id, rev2);
|
|
7558
7558
|
}
|
|
7559
7559
|
}
|
|
7560
7560
|
var Writethrough = class {
|
|
7561
|
-
constructor(
|
|
7562
|
-
this.db =
|
|
7561
|
+
constructor(db2, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
7562
|
+
this.db = db2;
|
|
7563
7563
|
this.writeRateMs = writeRateMs;
|
|
7564
7564
|
}
|
|
7565
|
-
async put(
|
|
7566
|
-
return put(this.db,
|
|
7565
|
+
async put(doc2) {
|
|
7566
|
+
return put(this.db, doc2, this.writeRateMs);
|
|
7567
7567
|
}
|
|
7568
7568
|
async get(id) {
|
|
7569
7569
|
return get2(this.db, id);
|
|
7570
7570
|
}
|
|
7571
|
-
async remove(docOrId,
|
|
7572
|
-
return remove(this.db, docOrId,
|
|
7571
|
+
async remove(docOrId, rev2) {
|
|
7572
|
+
return remove(this.db, docOrId, rev2);
|
|
7573
7573
|
}
|
|
7574
7574
|
};
|
|
7575
7575
|
|
|
@@ -7581,9 +7581,9 @@ function generateConfigID(type) {
|
|
|
7581
7581
|
return `${"config" /* CONFIG */}${SEPARATOR}${type}`;
|
|
7582
7582
|
}
|
|
7583
7583
|
async function getConfig(type) {
|
|
7584
|
-
const
|
|
7584
|
+
const db2 = getGlobalDB();
|
|
7585
7585
|
try {
|
|
7586
|
-
return await
|
|
7586
|
+
return await db2.get(generateConfigID(type));
|
|
7587
7587
|
} catch (e) {
|
|
7588
7588
|
if (e.status === 404) {
|
|
7589
7589
|
return;
|
|
@@ -7592,8 +7592,8 @@ async function getConfig(type) {
|
|
|
7592
7592
|
}
|
|
7593
7593
|
}
|
|
7594
7594
|
async function save(config) {
|
|
7595
|
-
const
|
|
7596
|
-
return
|
|
7595
|
+
const db2 = getGlobalDB();
|
|
7596
|
+
return db2.put(config);
|
|
7597
7597
|
}
|
|
7598
7598
|
async function getSettingsConfigDoc() {
|
|
7599
7599
|
let config = await getConfig("settings" /* SETTINGS */);
|
|
@@ -8042,7 +8042,7 @@ __export(utils_exports2, {
|
|
|
8042
8042
|
compare: () => compare,
|
|
8043
8043
|
getAppIdFromCtx: () => getAppIdFromCtx,
|
|
8044
8044
|
getCookie: () => getCookie,
|
|
8045
|
-
hash: () =>
|
|
8045
|
+
hash: () => hash2,
|
|
8046
8046
|
isAudited: () => isAudited,
|
|
8047
8047
|
isClient: () => isClient,
|
|
8048
8048
|
isPublicApiRequest: () => isPublicApiRequest,
|
|
@@ -8063,7 +8063,7 @@ init_environment2();
|
|
|
8063
8063
|
init_newid();
|
|
8064
8064
|
var bcrypt = environment_default2.JS_BCRYPT ? require("bcryptjs") : require("bcrypt");
|
|
8065
8065
|
var SALT_ROUNDS = environment_default2.SALT_ROUNDS || 10;
|
|
8066
|
-
async function
|
|
8066
|
+
async function hash2(data) {
|
|
8067
8067
|
const salt = await bcrypt.genSalt(SALT_ROUNDS);
|
|
8068
8068
|
return bcrypt.hash(data, salt);
|
|
8069
8069
|
}
|
|
@@ -8179,14 +8179,14 @@ function isValidInternalAPIKey(apiKey) {
|
|
|
8179
8179
|
}
|
|
8180
8180
|
return false;
|
|
8181
8181
|
}
|
|
8182
|
-
function getCookie(ctx,
|
|
8183
|
-
const cookie = ctx.cookies.get(
|
|
8182
|
+
function getCookie(ctx, name2) {
|
|
8183
|
+
const cookie = ctx.cookies.get(name2);
|
|
8184
8184
|
if (!cookie) {
|
|
8185
8185
|
return cookie;
|
|
8186
8186
|
}
|
|
8187
8187
|
return openJwt(cookie);
|
|
8188
8188
|
}
|
|
8189
|
-
function setCookie(ctx, value,
|
|
8189
|
+
function setCookie(ctx, value, name2 = "builder", opts = { sign: true }) {
|
|
8190
8190
|
if (value && opts && opts.sign) {
|
|
8191
8191
|
value = jwt.sign(value, environment_default2.JWT_SECRET);
|
|
8192
8192
|
}
|
|
@@ -8199,10 +8199,10 @@ function setCookie(ctx, value, name = "builder", opts = { sign: true }) {
|
|
|
8199
8199
|
if (environment_default2.COOKIE_DOMAIN) {
|
|
8200
8200
|
config.domain = environment_default2.COOKIE_DOMAIN;
|
|
8201
8201
|
}
|
|
8202
|
-
ctx.cookies.set(
|
|
8202
|
+
ctx.cookies.set(name2, value, config);
|
|
8203
8203
|
}
|
|
8204
|
-
function clearCookie(ctx,
|
|
8205
|
-
setCookie(ctx, null,
|
|
8204
|
+
function clearCookie(ctx, name2) {
|
|
8205
|
+
setCookie(ctx, null, name2);
|
|
8206
8206
|
}
|
|
8207
8207
|
function isClient(ctx) {
|
|
8208
8208
|
return ctx.headers["x-budibase-type" /* TYPE */] === "client";
|
|
@@ -8236,8 +8236,8 @@ var InMemoryQueue = class {
|
|
|
8236
8236
|
* @param {object|null} opts This is not used by the in memory queue as there is no real use
|
|
8237
8237
|
* case when in memory, but is the same API as Bull
|
|
8238
8238
|
*/
|
|
8239
|
-
constructor(
|
|
8240
|
-
this._name =
|
|
8239
|
+
constructor(name2, opts = null) {
|
|
8240
|
+
this._name = name2;
|
|
8241
8241
|
this._opts = opts;
|
|
8242
8242
|
this._messages = [];
|
|
8243
8243
|
this._emitter = new import_events2.default.EventEmitter();
|
|
@@ -8670,13 +8670,13 @@ var getInstallFromDB = async () => {
|
|
|
8670
8670
|
}
|
|
8671
8671
|
);
|
|
8672
8672
|
};
|
|
8673
|
-
var updateVersion = async (
|
|
8673
|
+
var updateVersion = async (version2) => {
|
|
8674
8674
|
try {
|
|
8675
8675
|
await doWithDB(
|
|
8676
8676
|
StaticDatabases.PLATFORM_INFO.name,
|
|
8677
8677
|
async (platformDb) => {
|
|
8678
8678
|
const install = await getInstall();
|
|
8679
|
-
install.version =
|
|
8679
|
+
install.version = version2;
|
|
8680
8680
|
await platformDb.put(install);
|
|
8681
8681
|
await bustCache("installation" /* INSTALLATION */);
|
|
8682
8682
|
}
|
|
@@ -8778,13 +8778,13 @@ var identifyInstallationGroup = async (installId, timestamp) => {
|
|
|
8778
8778
|
const id = installId;
|
|
8779
8779
|
const type = "installation" /* INSTALLATION */;
|
|
8780
8780
|
const hosting = getHostingFromEnv();
|
|
8781
|
-
const
|
|
8781
|
+
const version2 = environment_default2.VERSION;
|
|
8782
8782
|
const environment3 = getDeploymentEnvironment();
|
|
8783
8783
|
const group = {
|
|
8784
8784
|
id,
|
|
8785
8785
|
type,
|
|
8786
8786
|
hosting,
|
|
8787
|
-
version,
|
|
8787
|
+
version: version2,
|
|
8788
8788
|
environment: environment3
|
|
8789
8789
|
};
|
|
8790
8790
|
await identifyGroup(group, timestamp);
|
|
@@ -8909,7 +8909,7 @@ var getEventTenantId = async (tenantId) => {
|
|
|
8909
8909
|
var getUniqueTenantId = async (tenantId) => {
|
|
8910
8910
|
return doInTenant(tenantId, () => {
|
|
8911
8911
|
return withCache("uniqueTenantId" /* UNIQUE_TENANT_ID */, 86400 /* ONE_DAY */, async () => {
|
|
8912
|
-
const
|
|
8912
|
+
const db2 = getGlobalDB();
|
|
8913
8913
|
const config = await getSettingsConfigDoc();
|
|
8914
8914
|
let uniqueTenantId;
|
|
8915
8915
|
if (config.config.uniqueTenantId) {
|
|
@@ -8917,7 +8917,7 @@ var getUniqueTenantId = async (tenantId) => {
|
|
|
8917
8917
|
} else {
|
|
8918
8918
|
uniqueTenantId = `${newid()}_${tenantId}`;
|
|
8919
8919
|
config.config.uniqueTenantId = uniqueTenantId;
|
|
8920
|
-
await
|
|
8920
|
+
await db2.put(config);
|
|
8921
8921
|
return uniqueTenantId;
|
|
8922
8922
|
}
|
|
8923
8923
|
});
|
|
@@ -8957,10 +8957,10 @@ __export(backfill_exports, {
|
|
|
8957
8957
|
init_src();
|
|
8958
8958
|
init_context2();
|
|
8959
8959
|
var start = async (events2) => {
|
|
8960
|
-
const
|
|
8960
|
+
const metadata2 = {
|
|
8961
8961
|
eventWhitelist: events2
|
|
8962
8962
|
};
|
|
8963
|
-
return saveBackfillMetadata(
|
|
8963
|
+
return saveBackfillMetadata(metadata2);
|
|
8964
8964
|
};
|
|
8965
8965
|
var recordEvent2 = async (event, properties) => {
|
|
8966
8966
|
const eventKey2 = getEventKey(event, properties);
|
|
@@ -9270,11 +9270,11 @@ var app_default = {
|
|
|
9270
9270
|
|
|
9271
9271
|
// ../backend-core/src/events/publishers/auth.ts
|
|
9272
9272
|
init_src();
|
|
9273
|
-
async function login(
|
|
9273
|
+
async function login(source2, email) {
|
|
9274
9274
|
const identity = await identification_default.getCurrentIdentity();
|
|
9275
9275
|
const properties = {
|
|
9276
9276
|
userId: identity.id,
|
|
9277
|
-
source,
|
|
9277
|
+
source: source2,
|
|
9278
9278
|
audited: {
|
|
9279
9279
|
email
|
|
9280
9280
|
}
|
|
@@ -10063,9 +10063,9 @@ var view_default = {
|
|
|
10063
10063
|
|
|
10064
10064
|
// ../backend-core/src/events/publishers/installation.ts
|
|
10065
10065
|
init_src();
|
|
10066
|
-
async function versionChecked(
|
|
10066
|
+
async function versionChecked(version2) {
|
|
10067
10067
|
const properties = {
|
|
10068
|
-
currentVersion:
|
|
10068
|
+
currentVersion: version2
|
|
10069
10069
|
};
|
|
10070
10070
|
await publishEvent("installation:version:checked" /* INSTALLATION_VERSION_CHECKED */, properties);
|
|
10071
10071
|
}
|
|
@@ -10284,13 +10284,13 @@ async function appBackupRestored(backup) {
|
|
|
10284
10284
|
};
|
|
10285
10285
|
await publishEvent("app:backup:restored" /* APP_BACKUP_RESTORED */, properties);
|
|
10286
10286
|
}
|
|
10287
|
-
async function appBackupTriggered(appId, backupId, type, trigger,
|
|
10287
|
+
async function appBackupTriggered(appId, backupId, type, trigger, name2) {
|
|
10288
10288
|
const properties = {
|
|
10289
10289
|
appId,
|
|
10290
10290
|
backupId,
|
|
10291
10291
|
type,
|
|
10292
10292
|
trigger,
|
|
10293
|
-
name
|
|
10293
|
+
name: name2
|
|
10294
10294
|
};
|
|
10295
10295
|
await publishEvent("app:backup:triggered" /* APP_BACKUP_TRIGGERED */, properties);
|
|
10296
10296
|
}
|
|
@@ -10301,16 +10301,16 @@ var backup_default = {
|
|
|
10301
10301
|
|
|
10302
10302
|
// ../backend-core/src/events/publishers/environmentVariable.ts
|
|
10303
10303
|
init_src();
|
|
10304
|
-
async function created14(
|
|
10304
|
+
async function created14(name2, environments) {
|
|
10305
10305
|
const properties = {
|
|
10306
|
-
name,
|
|
10306
|
+
name: name2,
|
|
10307
10307
|
environments
|
|
10308
10308
|
};
|
|
10309
10309
|
await publishEvent("environment_variable:created" /* ENVIRONMENT_VARIABLE_CREATED */, properties);
|
|
10310
10310
|
}
|
|
10311
|
-
async function deleted14(
|
|
10311
|
+
async function deleted14(name2) {
|
|
10312
10312
|
const properties = {
|
|
10313
|
-
name
|
|
10313
|
+
name: name2
|
|
10314
10314
|
};
|
|
10315
10315
|
await publishEvent("environment_variable:deleted" /* ENVIRONMENT_VARIABLE_DELETED */, properties);
|
|
10316
10316
|
}
|
|
@@ -10431,8 +10431,8 @@ function removeUserPassword(users2) {
|
|
|
10431
10431
|
return users2;
|
|
10432
10432
|
}
|
|
10433
10433
|
var bulkGetGlobalUsersById = async (userIds, opts) => {
|
|
10434
|
-
const
|
|
10435
|
-
let users2 = (await
|
|
10434
|
+
const db2 = getGlobalDB();
|
|
10435
|
+
let users2 = (await db2.allDocs({
|
|
10436
10436
|
keys: userIds,
|
|
10437
10437
|
include_docs: true
|
|
10438
10438
|
})).rows.map((row) => row.doc);
|
|
@@ -10442,21 +10442,21 @@ var bulkGetGlobalUsersById = async (userIds, opts) => {
|
|
|
10442
10442
|
return users2;
|
|
10443
10443
|
};
|
|
10444
10444
|
var getAllUserIds = async () => {
|
|
10445
|
-
const
|
|
10445
|
+
const db2 = getGlobalDB();
|
|
10446
10446
|
const startKey = `${"us" /* USER */}${SEPARATOR}`;
|
|
10447
|
-
const response = await
|
|
10447
|
+
const response = await db2.allDocs({
|
|
10448
10448
|
startkey: startKey,
|
|
10449
10449
|
endkey: `${startKey}${UNICODE_MAX}`
|
|
10450
10450
|
});
|
|
10451
10451
|
return response.rows.map((row) => row.id);
|
|
10452
10452
|
};
|
|
10453
10453
|
var bulkUpdateGlobalUsers = async (users2) => {
|
|
10454
|
-
const
|
|
10455
|
-
return await
|
|
10454
|
+
const db2 = getGlobalDB();
|
|
10455
|
+
return await db2.bulkDocs(users2);
|
|
10456
10456
|
};
|
|
10457
10457
|
async function getById(id, opts) {
|
|
10458
|
-
const
|
|
10459
|
-
let user = await
|
|
10458
|
+
const db2 = getGlobalDB();
|
|
10459
|
+
let user = await db2.get(id);
|
|
10460
10460
|
if (opts == null ? void 0 : opts.cleanup) {
|
|
10461
10461
|
user = removeUserPassword(user);
|
|
10462
10462
|
}
|
|
@@ -10559,7 +10559,7 @@ var paginatedUsers = async ({
|
|
|
10559
10559
|
email,
|
|
10560
10560
|
appId
|
|
10561
10561
|
} = {}) => {
|
|
10562
|
-
const
|
|
10562
|
+
const db2 = getGlobalDB();
|
|
10563
10563
|
const opts = {
|
|
10564
10564
|
include_docs: true,
|
|
10565
10565
|
limit: PAGE_LIMIT + 1
|
|
@@ -10570,12 +10570,12 @@ var paginatedUsers = async ({
|
|
|
10570
10570
|
let userList, property = "_id", getKey;
|
|
10571
10571
|
if (appId) {
|
|
10572
10572
|
userList = await searchGlobalUsersByApp(appId, opts);
|
|
10573
|
-
getKey = (
|
|
10573
|
+
getKey = (doc2) => getGlobalUserByAppPage(appId, doc2);
|
|
10574
10574
|
} else if (email) {
|
|
10575
10575
|
userList = await searchGlobalUsersByEmail(email, opts);
|
|
10576
10576
|
property = "email";
|
|
10577
10577
|
} else {
|
|
10578
|
-
const response = await
|
|
10578
|
+
const response = await db2.allDocs(getGlobalUserParams(null, opts));
|
|
10579
10579
|
userList = response.rows.map((row) => row.doc);
|
|
10580
10580
|
}
|
|
10581
10581
|
return pagination(userList, PAGE_LIMIT, {
|
|
@@ -10696,10 +10696,10 @@ var EXTERNAL_BUILTIN_ROLE_IDS = [
|
|
|
10696
10696
|
BUILTIN_IDS.PUBLIC
|
|
10697
10697
|
];
|
|
10698
10698
|
var Role2 = class {
|
|
10699
|
-
constructor(id,
|
|
10699
|
+
constructor(id, name2, permissionId) {
|
|
10700
10700
|
this.permissions = {};
|
|
10701
10701
|
this._id = id;
|
|
10702
|
-
this.name =
|
|
10702
|
+
this.name = name2;
|
|
10703
10703
|
this.permissionId = permissionId;
|
|
10704
10704
|
}
|
|
10705
10705
|
addInheritance(inherits) {
|
|
@@ -10789,8 +10789,8 @@ async function getRole(roleId, opts) {
|
|
|
10789
10789
|
);
|
|
10790
10790
|
}
|
|
10791
10791
|
try {
|
|
10792
|
-
const
|
|
10793
|
-
const dbRole = await
|
|
10792
|
+
const db2 = getAppDB();
|
|
10793
|
+
const dbRole = await db2.get(getDBRoleID(roleId));
|
|
10794
10794
|
role = Object.assign(role, dbRole);
|
|
10795
10795
|
role._id = getExternalRoleID(role._id);
|
|
10796
10796
|
} catch (err) {
|
|
@@ -10844,10 +10844,10 @@ async function getAllRoles(appId) {
|
|
|
10844
10844
|
}
|
|
10845
10845
|
return internal(appDB);
|
|
10846
10846
|
}
|
|
10847
|
-
async function internal(
|
|
10847
|
+
async function internal(db2) {
|
|
10848
10848
|
let roles = [];
|
|
10849
|
-
if (
|
|
10850
|
-
const body2 = await
|
|
10849
|
+
if (db2) {
|
|
10850
|
+
const body2 = await db2.allDocs(
|
|
10851
10851
|
getRoleParams(null, {
|
|
10852
10852
|
include_docs: true
|
|
10853
10853
|
})
|
|
@@ -11283,12 +11283,12 @@ async function syncUser(user, details) {
|
|
|
11283
11283
|
if (details.profile) {
|
|
11284
11284
|
const profile = details.profile;
|
|
11285
11285
|
if (profile.name) {
|
|
11286
|
-
const
|
|
11287
|
-
if (
|
|
11288
|
-
firstName =
|
|
11286
|
+
const name2 = profile.name;
|
|
11287
|
+
if (name2.givenName) {
|
|
11288
|
+
firstName = name2.givenName;
|
|
11289
11289
|
}
|
|
11290
|
-
if (
|
|
11291
|
-
lastName =
|
|
11290
|
+
if (name2.familyName) {
|
|
11291
|
+
lastName = name2.familyName;
|
|
11292
11292
|
}
|
|
11293
11293
|
}
|
|
11294
11294
|
pictureUrl = await getProfilePictureUrl(user, details);
|
|
@@ -11803,13 +11803,13 @@ async function checkApiKey(apiKey, populateUser) {
|
|
|
11803
11803
|
return doInTenant(tenantId, async () => {
|
|
11804
11804
|
let userId;
|
|
11805
11805
|
try {
|
|
11806
|
-
const
|
|
11806
|
+
const db2 = getGlobalDB();
|
|
11807
11807
|
userId = await queryGlobalView(
|
|
11808
11808
|
"by_api_key" /* BY_API_KEY */,
|
|
11809
11809
|
{
|
|
11810
11810
|
key: apiKey
|
|
11811
11811
|
},
|
|
11812
|
-
|
|
11812
|
+
db2
|
|
11813
11813
|
);
|
|
11814
11814
|
} catch (err) {
|
|
11815
11815
|
userId = void 0;
|
|
@@ -11830,7 +11830,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
|
|
|
11830
11830
|
const noAuthOptions = noAuthPatterns ? buildMatcherRegex(noAuthPatterns) : [];
|
|
11831
11831
|
return async (ctx, next) => {
|
|
11832
11832
|
let publicEndpoint = false;
|
|
11833
|
-
const
|
|
11833
|
+
const version2 = ctx.request.headers["x-budibase-api-version" /* API_VER */];
|
|
11834
11834
|
const found = matches(ctx, noAuthOptions);
|
|
11835
11835
|
if (found) {
|
|
11836
11836
|
publicEndpoint = true;
|
|
@@ -11893,7 +11893,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
|
|
|
11893
11893
|
if (!authenticated) {
|
|
11894
11894
|
authenticated = false;
|
|
11895
11895
|
}
|
|
11896
|
-
finalise(ctx, { authenticated, user, internal, version, publicEndpoint });
|
|
11896
|
+
finalise(ctx, { authenticated, user, internal, version: version2, publicEndpoint });
|
|
11897
11897
|
if (user && user.email) {
|
|
11898
11898
|
return doInUserContext(user, ctx, next);
|
|
11899
11899
|
} else {
|
|
@@ -11908,7 +11908,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
|
|
|
11908
11908
|
ctx.throw(403, err.message);
|
|
11909
11909
|
}
|
|
11910
11910
|
if (opts && opts.publicAllowed || publicEndpoint) {
|
|
11911
|
-
finalise(ctx, { authenticated: false, version, publicEndpoint });
|
|
11911
|
+
finalise(ctx, { authenticated: false, version: version2, publicEndpoint });
|
|
11912
11912
|
return next();
|
|
11913
11913
|
} else {
|
|
11914
11914
|
ctx.throw(err.status || 403, err);
|
|
@@ -12265,8 +12265,8 @@ async function updateUserOAuth(userId, oAuthConfig) {
|
|
|
12265
12265
|
refreshToken: oAuthConfig.refreshToken
|
|
12266
12266
|
};
|
|
12267
12267
|
try {
|
|
12268
|
-
const
|
|
12269
|
-
const dbUser = await
|
|
12268
|
+
const db2 = getGlobalDB();
|
|
12269
|
+
const dbUser = await db2.get(userId);
|
|
12270
12270
|
if (typeof details.refreshToken !== "string") {
|
|
12271
12271
|
delete details.refreshToken;
|
|
12272
12272
|
}
|
|
@@ -12274,7 +12274,7 @@ async function updateUserOAuth(userId, oAuthConfig) {
|
|
|
12274
12274
|
...dbUser.oauth2,
|
|
12275
12275
|
...details
|
|
12276
12276
|
};
|
|
12277
|
-
await
|
|
12277
|
+
await db2.put(dbUser);
|
|
12278
12278
|
await invalidateUser(userId);
|
|
12279
12279
|
} catch (e) {
|
|
12280
12280
|
console.error("Could not update OAuth details for current user", e);
|
|
@@ -12574,7 +12574,7 @@ var upload = async ({
|
|
|
12574
12574
|
filename,
|
|
12575
12575
|
path: path2,
|
|
12576
12576
|
type,
|
|
12577
|
-
metadata
|
|
12577
|
+
metadata: metadata2
|
|
12578
12578
|
}) => {
|
|
12579
12579
|
const extension = filename.split(".").pop();
|
|
12580
12580
|
const fileBytes = import_fs4.default.readFileSync(path2);
|
|
@@ -12590,13 +12590,13 @@ var upload = async ({
|
|
|
12590
12590
|
Body: fileBytes,
|
|
12591
12591
|
ContentType: contentType
|
|
12592
12592
|
};
|
|
12593
|
-
if (
|
|
12594
|
-
for (let key of Object.keys(
|
|
12595
|
-
if (!
|
|
12596
|
-
delete
|
|
12593
|
+
if (metadata2 && typeof metadata2 === "object") {
|
|
12594
|
+
for (let key of Object.keys(metadata2)) {
|
|
12595
|
+
if (!metadata2[key] || typeof metadata2[key] !== "string") {
|
|
12596
|
+
delete metadata2[key];
|
|
12597
12597
|
}
|
|
12598
12598
|
}
|
|
12599
|
-
config.Metadata =
|
|
12599
|
+
config.Metadata = metadata2;
|
|
12600
12600
|
}
|
|
12601
12601
|
return objectStore.upload(config).promise();
|
|
12602
12602
|
};
|
|
@@ -12750,12 +12750,12 @@ var deleteFolder = async (bucketName, folder) => {
|
|
|
12750
12750
|
return deleteFolder(bucketName, folder);
|
|
12751
12751
|
}
|
|
12752
12752
|
};
|
|
12753
|
-
var uploadDirectory = async (bucketName, localPath,
|
|
12753
|
+
var uploadDirectory = async (bucketName, localPath, bucketPath2) => {
|
|
12754
12754
|
bucketName = sanitizeBucket(bucketName);
|
|
12755
12755
|
let uploads = [];
|
|
12756
|
-
const
|
|
12757
|
-
for (let file of
|
|
12758
|
-
const path2 = sanitizeKey((0, import_path4.join)(
|
|
12756
|
+
const files2 = import_fs4.default.readdirSync(localPath, { withFileTypes: true });
|
|
12757
|
+
for (let file of files2) {
|
|
12758
|
+
const path2 = sanitizeKey((0, import_path4.join)(bucketPath2, file.name));
|
|
12759
12759
|
const local = (0, import_path4.join)(localPath, file.name);
|
|
12760
12760
|
if (file.isDirectory()) {
|
|
12761
12761
|
uploads.push(uploadDirectory(bucketName, local, path2));
|
|
@@ -12764,7 +12764,7 @@ var uploadDirectory = async (bucketName, localPath, bucketPath) => {
|
|
|
12764
12764
|
}
|
|
12765
12765
|
}
|
|
12766
12766
|
await Promise.all(uploads);
|
|
12767
|
-
return
|
|
12767
|
+
return files2;
|
|
12768
12768
|
};
|
|
12769
12769
|
var downloadTarballDirect = async (url, path2, headers = {}) => {
|
|
12770
12770
|
path2 = sanitizeKey(path2);
|
|
@@ -12829,12 +12829,12 @@ var getUrl = (s3Key) => {
|
|
|
12829
12829
|
};
|
|
12830
12830
|
|
|
12831
12831
|
// ../backend-core/src/objectStore/buckets/app.ts
|
|
12832
|
-
var clientLibraryUrl = (appId,
|
|
12832
|
+
var clientLibraryUrl = (appId, version2) => {
|
|
12833
12833
|
if (environment_default2.isProd()) {
|
|
12834
12834
|
let file = `${sanitizeKey(appId)}/budibase-client.js`;
|
|
12835
12835
|
if (environment_default2.CLOUDFRONT_CDN) {
|
|
12836
|
-
if (
|
|
12837
|
-
file += `?v=${
|
|
12836
|
+
if (version2) {
|
|
12837
|
+
file += `?v=${version2}`;
|
|
12838
12838
|
}
|
|
12839
12839
|
return getUrl(file);
|
|
12840
12840
|
} else {
|
|
@@ -12855,8 +12855,8 @@ var getAppFileUrl = (s3Key) => {
|
|
|
12855
12855
|
// ../backend-core/src/objectStore/buckets/global.ts
|
|
12856
12856
|
init_environment2();
|
|
12857
12857
|
init_context2();
|
|
12858
|
-
var getGlobalFileUrl = (type,
|
|
12859
|
-
let file = getGlobalFileS3Key(type,
|
|
12858
|
+
var getGlobalFileUrl = (type, name2, etag) => {
|
|
12859
|
+
let file = getGlobalFileS3Key(type, name2);
|
|
12860
12860
|
if (environment_default2.CLOUDFRONT_CDN) {
|
|
12861
12861
|
if (etag) {
|
|
12862
12862
|
file = `${file}?etag=${etag}`;
|
|
@@ -12866,8 +12866,8 @@ var getGlobalFileUrl = (type, name, etag) => {
|
|
|
12866
12866
|
return getPresignedUrl(environment_default2.GLOBAL_BUCKET_NAME, file);
|
|
12867
12867
|
}
|
|
12868
12868
|
};
|
|
12869
|
-
var getGlobalFileS3Key = (type,
|
|
12870
|
-
let file = `${type}/${
|
|
12869
|
+
var getGlobalFileS3Key = (type, name2) => {
|
|
12870
|
+
let file = `${type}/${name2}`;
|
|
12871
12871
|
if (environment_default2.MULTI_TENANCY) {
|
|
12872
12872
|
const tenantId = getTenantId();
|
|
12873
12873
|
file = `${tenantId}/${file}`;
|
|
@@ -12910,11 +12910,11 @@ var getPluginJSKey = (plugin) => {
|
|
|
12910
12910
|
return getPluginS3Key(plugin, "plugin.min.js");
|
|
12911
12911
|
};
|
|
12912
12912
|
var getPluginIconKey = (plugin) => {
|
|
12913
|
-
const
|
|
12914
|
-
if (!
|
|
12913
|
+
const iconFileName2 = plugin.iconUrl ? "icon.svg" : plugin.iconFileName;
|
|
12914
|
+
if (!iconFileName2) {
|
|
12915
12915
|
return;
|
|
12916
12916
|
}
|
|
12917
|
-
return getPluginS3Key(plugin,
|
|
12917
|
+
return getPluginS3Key(plugin, iconFileName2);
|
|
12918
12918
|
};
|
|
12919
12919
|
var getPluginS3Key = (plugin, fileName) => {
|
|
12920
12920
|
const s3Key = getPluginS3Dir(plugin.name);
|
|
@@ -13467,18 +13467,18 @@ function finaliseExternalTables(tables, entities) {
|
|
|
13467
13467
|
let finalTables = {};
|
|
13468
13468
|
const errors = {};
|
|
13469
13469
|
const tableIds = Object.values(tables).map((table) => table._id);
|
|
13470
|
-
for (let [
|
|
13470
|
+
for (let [name2, table] of Object.entries(tables)) {
|
|
13471
13471
|
const schemaFields = Object.keys(table.schema);
|
|
13472
13472
|
if (table.primary == null || table.primary.length === 0) {
|
|
13473
|
-
errors[
|
|
13473
|
+
errors[name2] = "no_key" /* NO_KEY */;
|
|
13474
13474
|
continue;
|
|
13475
13475
|
} else if (schemaFields.find(
|
|
13476
13476
|
(field) => invalidColumns.includes(field)
|
|
13477
13477
|
)) {
|
|
13478
|
-
errors[
|
|
13478
|
+
errors[name2] = "invalid_column" /* INVALID_COLUMN */;
|
|
13479
13479
|
continue;
|
|
13480
13480
|
}
|
|
13481
|
-
finalTables[
|
|
13481
|
+
finalTables[name2] = copyExistingPropsOver(name2, table, entities, tableIds);
|
|
13482
13482
|
}
|
|
13483
13483
|
finalTables = Object.entries(finalTables).sort(([a], [b]) => a.localeCompare(b)).reduce((r, [k, v]) => ({ ...r, [k]: v }), {});
|
|
13484
13484
|
return { tables: finalTables, errors };
|
|
@@ -15126,8 +15126,8 @@ var MongoIntegration = class {
|
|
|
15126
15126
|
async create(query) {
|
|
15127
15127
|
try {
|
|
15128
15128
|
await this.connect();
|
|
15129
|
-
const
|
|
15130
|
-
const collection =
|
|
15129
|
+
const db2 = this.client.db(this.config.db);
|
|
15130
|
+
const collection = db2.collection(query.extra.collection);
|
|
15131
15131
|
let json = this.createObjectIds(query.json);
|
|
15132
15132
|
switch (query.extra.actionType) {
|
|
15133
15133
|
case "insertOne": {
|
|
@@ -15152,8 +15152,8 @@ var MongoIntegration = class {
|
|
|
15152
15152
|
async read(query) {
|
|
15153
15153
|
try {
|
|
15154
15154
|
await this.connect();
|
|
15155
|
-
const
|
|
15156
|
-
const collection =
|
|
15155
|
+
const db2 = this.client.db(this.config.db);
|
|
15156
|
+
const collection = db2.collection(query.extra.collection);
|
|
15157
15157
|
let json = this.createObjectIds(query.json);
|
|
15158
15158
|
switch (query.extra.actionType) {
|
|
15159
15159
|
case "find": {
|
|
@@ -15195,8 +15195,8 @@ var MongoIntegration = class {
|
|
|
15195
15195
|
async update(query) {
|
|
15196
15196
|
try {
|
|
15197
15197
|
await this.connect();
|
|
15198
|
-
const
|
|
15199
|
-
const collection =
|
|
15198
|
+
const db2 = this.client.db(this.config.db);
|
|
15199
|
+
const collection = db2.collection(query.extra.collection);
|
|
15200
15200
|
let queryJson = query.json;
|
|
15201
15201
|
if (typeof queryJson === "string") {
|
|
15202
15202
|
queryJson = this.parseQueryParams(queryJson, "update");
|
|
@@ -15233,8 +15233,8 @@ var MongoIntegration = class {
|
|
|
15233
15233
|
async delete(query) {
|
|
15234
15234
|
try {
|
|
15235
15235
|
await this.connect();
|
|
15236
|
-
const
|
|
15237
|
-
const collection =
|
|
15236
|
+
const db2 = this.client.db(this.config.db);
|
|
15237
|
+
const collection = db2.collection(query.extra.collection);
|
|
15238
15238
|
let queryJson = query.json;
|
|
15239
15239
|
if (typeof queryJson === "string") {
|
|
15240
15240
|
queryJson = this.parseQueryParams(queryJson, "delete");
|
|
@@ -15270,25 +15270,25 @@ var MongoIntegration = class {
|
|
|
15270
15270
|
var _a;
|
|
15271
15271
|
try {
|
|
15272
15272
|
await this.connect();
|
|
15273
|
-
const
|
|
15274
|
-
const collection =
|
|
15273
|
+
const db2 = this.client.db(this.config.db);
|
|
15274
|
+
const collection = db2.collection(query.extra.collection);
|
|
15275
15275
|
let response = [];
|
|
15276
15276
|
if (((_a = query.extra) == null ? void 0 : _a.actionType) === "pipeline") {
|
|
15277
|
-
for await (const
|
|
15277
|
+
for await (const doc2 of collection.aggregate(
|
|
15278
15278
|
query.steps.map(({ key, value }) => {
|
|
15279
15279
|
let temp = {};
|
|
15280
15280
|
temp[key] = JSON.parse(value.value);
|
|
15281
15281
|
return this.createObjectIds(temp);
|
|
15282
15282
|
})
|
|
15283
15283
|
)) {
|
|
15284
|
-
response.push(
|
|
15284
|
+
response.push(doc2);
|
|
15285
15285
|
}
|
|
15286
15286
|
} else {
|
|
15287
15287
|
const stages = query.json;
|
|
15288
|
-
for await (const
|
|
15288
|
+
for await (const doc2 of collection.aggregate(
|
|
15289
15289
|
stages ? this.createObjectIds(stages) : []
|
|
15290
15290
|
)) {
|
|
15291
|
-
response.push(
|
|
15291
|
+
response.push(doc2);
|
|
15292
15292
|
}
|
|
15293
15293
|
}
|
|
15294
15294
|
return response;
|
|
@@ -15588,9 +15588,9 @@ var CouchDBIntegration = class {
|
|
|
15588
15588
|
});
|
|
15589
15589
|
}
|
|
15590
15590
|
async delete(query) {
|
|
15591
|
-
const
|
|
15591
|
+
const doc2 = await this.query("get", "Cannot find doc to be deleted", query);
|
|
15592
15592
|
return this.query("remove", "Error deleting couchDB document", {
|
|
15593
|
-
json:
|
|
15593
|
+
json: doc2
|
|
15594
15594
|
});
|
|
15595
15595
|
}
|
|
15596
15596
|
};
|
|
@@ -15769,7 +15769,7 @@ var SqlServerIntegration = class extends sql_default {
|
|
|
15769
15769
|
throw "Unable to get list of tables in database";
|
|
15770
15770
|
}
|
|
15771
15771
|
const schema = this.config.schema || DEFAULT_SCHEMA;
|
|
15772
|
-
const tableNames = tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((
|
|
15772
|
+
const tableNames = tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name2) => this.MASTER_TABLES.indexOf(name2) === -1);
|
|
15773
15773
|
const tables = {};
|
|
15774
15774
|
for (let tableName of tableNames) {
|
|
15775
15775
|
const definition = await this.runSQL(this.getDefinitionSQL(tableName));
|
|
@@ -15784,16 +15784,16 @@ var SqlServerIntegration = class extends sql_default {
|
|
|
15784
15784
|
const requiredColumns = columns.filter((col) => col.IS_NULLABLE === "NO").map((col) => col.COLUMN_NAME);
|
|
15785
15785
|
let schema2 = {};
|
|
15786
15786
|
for (let def of definition) {
|
|
15787
|
-
const
|
|
15788
|
-
if (typeof
|
|
15787
|
+
const name2 = def.COLUMN_NAME;
|
|
15788
|
+
if (typeof name2 !== "string") {
|
|
15789
15789
|
continue;
|
|
15790
15790
|
}
|
|
15791
15791
|
const hasDefault = def.COLUMN_DEFAULT;
|
|
15792
|
-
const isAuto = !!autoColumns.find((col) => col ===
|
|
15793
|
-
const required = !!requiredColumns.find((col) => col ===
|
|
15794
|
-
schema2[
|
|
15792
|
+
const isAuto = !!autoColumns.find((col) => col === name2);
|
|
15793
|
+
const required = !!requiredColumns.find((col) => col === name2);
|
|
15794
|
+
schema2[name2] = {
|
|
15795
15795
|
autocolumn: isAuto,
|
|
15796
|
-
name,
|
|
15796
|
+
name: name2,
|
|
15797
15797
|
constraints: {
|
|
15798
15798
|
presence: required && !isAuto && !hasDefault
|
|
15799
15799
|
},
|
|
@@ -15815,7 +15815,7 @@ var SqlServerIntegration = class extends sql_default {
|
|
|
15815
15815
|
async queryTableNames() {
|
|
15816
15816
|
let tableInfo = await this.runSQL(this.TABLES_SQL);
|
|
15817
15817
|
const schema = this.config.schema || DEFAULT_SCHEMA;
|
|
15818
|
-
return tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((
|
|
15818
|
+
return tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name2) => this.MASTER_TABLES.indexOf(name2) === -1);
|
|
15819
15819
|
}
|
|
15820
15820
|
async getTableNames() {
|
|
15821
15821
|
await this.connect();
|
|
@@ -17205,11 +17205,11 @@ var runLuceneQuery = (docs, query) => {
|
|
|
17205
17205
|
return docs;
|
|
17206
17206
|
}
|
|
17207
17207
|
query = cleanupQuery(query);
|
|
17208
|
-
const match = (type, failFn) => (
|
|
17208
|
+
const match = (type, failFn) => (doc2) => {
|
|
17209
17209
|
const filters = Object.entries(query[type] || {});
|
|
17210
17210
|
for (let i = 0; i < filters.length; i++) {
|
|
17211
17211
|
const [key, testValue] = filters[i];
|
|
17212
|
-
const docValue = deepGet(
|
|
17212
|
+
const docValue = deepGet(doc2, removeKeyNumbering2(key));
|
|
17213
17213
|
if (failFn(docValue, testValue)) {
|
|
17214
17214
|
return false;
|
|
17215
17215
|
}
|
|
@@ -17270,8 +17270,8 @@ var runLuceneQuery = (docs, query) => {
|
|
|
17270
17270
|
return testValue == null ? void 0 : testValue.every((item) => docValue == null ? void 0 : docValue.includes(item));
|
|
17271
17271
|
}
|
|
17272
17272
|
);
|
|
17273
|
-
const docMatch = (
|
|
17274
|
-
return stringMatch(
|
|
17273
|
+
const docMatch = (doc2) => {
|
|
17274
|
+
return stringMatch(doc2) && fuzzyMatch(doc2) && rangeMatch(doc2) && equalMatch(doc2) && notEqualMatch(doc2) && emptyMatch(doc2) && notEmptyMatch(doc2) && oneOf(doc2) && contains(doc2) && containsAny(doc2) && notContains(doc2);
|
|
17275
17275
|
};
|
|
17276
17276
|
return docs.filter(docMatch);
|
|
17277
17277
|
};
|
|
@@ -17612,13 +17612,13 @@ var GoogleSheetsIntegration = class {
|
|
|
17612
17612
|
}
|
|
17613
17613
|
return rowObject;
|
|
17614
17614
|
}
|
|
17615
|
-
async createTable(
|
|
17616
|
-
if (!
|
|
17615
|
+
async createTable(name2) {
|
|
17616
|
+
if (!name2) {
|
|
17617
17617
|
throw new Error("Must provide name for new sheet.");
|
|
17618
17618
|
}
|
|
17619
17619
|
try {
|
|
17620
17620
|
await this.connect();
|
|
17621
|
-
return await this.client.addSheet({ title:
|
|
17621
|
+
return await this.client.addSheet({ title: name2, headerValues: [name2] });
|
|
17622
17622
|
} catch (err) {
|
|
17623
17623
|
console.error("Error creating new table in google sheets", err);
|
|
17624
17624
|
throw err;
|
|
@@ -17949,7 +17949,7 @@ var FirebaseIntegration = class {
|
|
|
17949
17949
|
snapshot = await collectionRef.get();
|
|
17950
17950
|
}
|
|
17951
17951
|
const result = [];
|
|
17952
|
-
snapshot.forEach((
|
|
17952
|
+
snapshot.forEach((doc2) => result.push(doc2.data()));
|
|
17953
17953
|
return result;
|
|
17954
17954
|
} catch (err) {
|
|
17955
17955
|
console.error("Error querying Firestore", err);
|
|
@@ -18637,13 +18637,13 @@ var import_path7 = require("path");
|
|
|
18637
18637
|
var DATASOURCE_PATH = (0, import_path7.join)(budibaseTempDir2(), "datasource");
|
|
18638
18638
|
var AUTOMATION_PATH = (0, import_path7.join)(budibaseTempDir2(), "automation");
|
|
18639
18639
|
var getPluginMetadata = async (path2) => {
|
|
18640
|
-
let
|
|
18640
|
+
let metadata2 = {};
|
|
18641
18641
|
try {
|
|
18642
18642
|
const pkg2 = import_fs6.default.readFileSync((0, import_path7.join)(path2, "package.json"), "utf8");
|
|
18643
18643
|
const schema = import_fs6.default.readFileSync((0, import_path7.join)(path2, "schema.json"), "utf8");
|
|
18644
|
-
|
|
18645
|
-
|
|
18646
|
-
if (!
|
|
18644
|
+
metadata2.schema = JSON.parse(schema);
|
|
18645
|
+
metadata2.package = JSON.parse(pkg2);
|
|
18646
|
+
if (!metadata2.package.name || !metadata2.package.version || !metadata2.package.description) {
|
|
18647
18647
|
throw new Error(
|
|
18648
18648
|
"package.json is missing one of 'name', 'version' or 'description'."
|
|
18649
18649
|
);
|
|
@@ -18653,11 +18653,11 @@ var getPluginMetadata = async (path2) => {
|
|
|
18653
18653
|
`Unable to process schema.json/package.json in plugin. ${err.message}`
|
|
18654
18654
|
);
|
|
18655
18655
|
}
|
|
18656
|
-
return { metadata, directory: path2 };
|
|
18656
|
+
return { metadata: metadata2, directory: path2 };
|
|
18657
18657
|
};
|
|
18658
18658
|
async function getPluginImpl(path2, plugin) {
|
|
18659
18659
|
var _a;
|
|
18660
|
-
const
|
|
18660
|
+
const hash3 = (_a = plugin.schema) == null ? void 0 : _a.hash;
|
|
18661
18661
|
if (!import_fs6.default.existsSync(path2)) {
|
|
18662
18662
|
import_fs6.default.mkdirSync(path2);
|
|
18663
18663
|
}
|
|
@@ -18665,7 +18665,7 @@ async function getPluginImpl(path2, plugin) {
|
|
|
18665
18665
|
const metadataName = `${filename}.bbmetadata`;
|
|
18666
18666
|
if (import_fs6.default.existsSync(filename)) {
|
|
18667
18667
|
const currentHash = import_fs6.default.readFileSync(metadataName, "utf8");
|
|
18668
|
-
if (currentHash ===
|
|
18668
|
+
if (currentHash === hash3) {
|
|
18669
18669
|
return require(filename);
|
|
18670
18670
|
} else {
|
|
18671
18671
|
console.log(`Updating plugin: ${plugin.name}`);
|
|
@@ -18679,7 +18679,7 @@ async function getPluginImpl(path2, plugin) {
|
|
|
18679
18679
|
pluginKey
|
|
18680
18680
|
);
|
|
18681
18681
|
import_fs6.default.writeFileSync(filename, pluginJs);
|
|
18682
|
-
import_fs6.default.writeFileSync(metadataName,
|
|
18682
|
+
import_fs6.default.writeFileSync(metadataName, hash3);
|
|
18683
18683
|
return require(filename);
|
|
18684
18684
|
}
|
|
18685
18685
|
var getDatasourcePlugin = async (plugin) => {
|
|
@@ -18687,9 +18687,9 @@ var getDatasourcePlugin = async (plugin) => {
|
|
|
18687
18687
|
};
|
|
18688
18688
|
|
|
18689
18689
|
// src/utilities/fileSystem/template.ts
|
|
18690
|
-
var downloadTemplate = async (type,
|
|
18690
|
+
var downloadTemplate = async (type, name2) => {
|
|
18691
18691
|
const DEFAULT_TEMPLATES_BUCKET = "prod-budi-templates.s3-eu-west-1.amazonaws.com";
|
|
18692
|
-
const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${
|
|
18692
|
+
const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${name2}.tar.gz`;
|
|
18693
18693
|
return objectStore_exports2.downloadTarball(
|
|
18694
18694
|
templateUrl,
|
|
18695
18695
|
ObjectStoreBuckets2.TEMPLATES,
|
|
@@ -18719,7 +18719,7 @@ var import_path8 = require("path");
|
|
|
18719
18719
|
var import_tar2 = __toESM(require("tar"));
|
|
18720
18720
|
var uuid3 = require("uuid/v4");
|
|
18721
18721
|
var MemoryStream = require("memorystream");
|
|
18722
|
-
function tarFilesToTmp(tmpDir,
|
|
18722
|
+
function tarFilesToTmp(tmpDir, files2) {
|
|
18723
18723
|
const fileName = `${uuid3()}.tar.gz`;
|
|
18724
18724
|
const exportFile = (0, import_path8.join)(budibaseTempDir2(), fileName);
|
|
18725
18725
|
import_tar2.default.create(
|
|
@@ -18730,7 +18730,7 @@ function tarFilesToTmp(tmpDir, files) {
|
|
|
18730
18730
|
noDirRecurse: false,
|
|
18731
18731
|
cwd: tmpDir
|
|
18732
18732
|
},
|
|
18733
|
-
|
|
18733
|
+
files2
|
|
18734
18734
|
);
|
|
18735
18735
|
return exportFile;
|
|
18736
18736
|
}
|
|
@@ -18741,11 +18741,11 @@ async function exportDB(dbName, opts = {}) {
|
|
|
18741
18741
|
batch_limit: 5,
|
|
18742
18742
|
style: "main_only"
|
|
18743
18743
|
};
|
|
18744
|
-
return db_exports.doWithDB(dbName, async (
|
|
18744
|
+
return db_exports.doWithDB(dbName, async (db2) => {
|
|
18745
18745
|
if (opts == null ? void 0 : opts.exportPath) {
|
|
18746
18746
|
const path2 = opts == null ? void 0 : opts.exportPath;
|
|
18747
18747
|
const writeStream = import_fs7.default.createWriteStream(path2);
|
|
18748
|
-
await
|
|
18748
|
+
await db2.dump(writeStream, exportOpts);
|
|
18749
18749
|
return path2;
|
|
18750
18750
|
} else {
|
|
18751
18751
|
const memStream = new MemoryStream();
|
|
@@ -18753,7 +18753,7 @@ async function exportDB(dbName, opts = {}) {
|
|
|
18753
18753
|
memStream.on("data", (chunk) => {
|
|
18754
18754
|
appString += chunk.toString();
|
|
18755
18755
|
});
|
|
18756
|
-
await
|
|
18756
|
+
await db2.dump(memStream, exportOpts);
|
|
18757
18757
|
return appString;
|
|
18758
18758
|
}
|
|
18759
18759
|
});
|
|
@@ -18766,7 +18766,7 @@ function defineFilter(excludeRows, excludeLogs) {
|
|
|
18766
18766
|
if (excludeLogs) {
|
|
18767
18767
|
ids.push(AUTOMATION_LOG_PREFIX);
|
|
18768
18768
|
}
|
|
18769
|
-
return (
|
|
18769
|
+
return (doc2) => !ids.map((key) => doc2._id.includes(key)).reduce((prev, curr) => prev || curr);
|
|
18770
18770
|
}
|
|
18771
18771
|
async function exportApp(appId, config) {
|
|
18772
18772
|
const prodAppId = db_exports.getProdAppID(appId);
|
|
@@ -18860,12 +18860,12 @@ function rewriteAttachmentUrl(appId, attachment) {
|
|
|
18860
18860
|
// calculated on retrieval using key
|
|
18861
18861
|
};
|
|
18862
18862
|
}
|
|
18863
|
-
async function updateAttachmentColumns(prodAppId,
|
|
18864
|
-
const tables = await sdk_default.tables.getAllInternalTables(
|
|
18863
|
+
async function updateAttachmentColumns(prodAppId, db2) {
|
|
18864
|
+
const tables = await sdk_default.tables.getAllInternalTables(db2);
|
|
18865
18865
|
let updatedRows = [];
|
|
18866
18866
|
for (let table of tables) {
|
|
18867
18867
|
const { rows: rows2, columns } = await sdk_default.rows.getRowsWithAttachments(
|
|
18868
|
-
|
|
18868
|
+
db2.name,
|
|
18869
18869
|
table
|
|
18870
18870
|
);
|
|
18871
18871
|
updatedRows = updatedRows.concat(
|
|
@@ -18881,11 +18881,11 @@ async function updateAttachmentColumns(prodAppId, db) {
|
|
|
18881
18881
|
})
|
|
18882
18882
|
);
|
|
18883
18883
|
}
|
|
18884
|
-
await
|
|
18884
|
+
await db2.bulkDocs(updatedRows);
|
|
18885
18885
|
}
|
|
18886
|
-
async function updateAutomations(prodAppId,
|
|
18886
|
+
async function updateAutomations(prodAppId, db2) {
|
|
18887
18887
|
var _a;
|
|
18888
|
-
const automations2 = (await
|
|
18888
|
+
const automations2 = (await db2.allDocs(
|
|
18889
18889
|
getAutomationParams(null, {
|
|
18890
18890
|
include_docs: true
|
|
18891
18891
|
})
|
|
@@ -18904,7 +18904,7 @@ async function updateAutomations(prodAppId, db) {
|
|
|
18904
18904
|
automation.appId = devAppId;
|
|
18905
18905
|
toSave.push(automation);
|
|
18906
18906
|
}
|
|
18907
|
-
await
|
|
18907
|
+
await db2.bulkDocs(toSave);
|
|
18908
18908
|
}
|
|
18909
18909
|
async function getTemplateStream(template) {
|
|
18910
18910
|
if (template.file && template.file.type !== "text/plain") {
|
|
@@ -18913,9 +18913,9 @@ async function getTemplateStream(template) {
|
|
|
18913
18913
|
if (template.file) {
|
|
18914
18914
|
return import_fs8.default.createReadStream(template.file.path);
|
|
18915
18915
|
} else if (template.key) {
|
|
18916
|
-
const [type,
|
|
18917
|
-
const tmpPath = await downloadTemplate(type,
|
|
18918
|
-
return import_fs8.default.createReadStream((0, import_path9.join)(tmpPath,
|
|
18916
|
+
const [type, name2] = template.key.split("/");
|
|
18917
|
+
const tmpPath = await downloadTemplate(type, name2);
|
|
18918
|
+
return import_fs8.default.createReadStream((0, import_path9.join)(tmpPath, name2, "db", "dump.txt"));
|
|
18919
18919
|
}
|
|
18920
18920
|
}
|
|
18921
18921
|
function untarFile(file) {
|
|
@@ -18949,7 +18949,7 @@ function getGlobalDBFile(tmpPath) {
|
|
|
18949
18949
|
function getListOfAppsInMulti(tmpPath) {
|
|
18950
18950
|
return import_fs8.default.readdirSync(tmpPath).filter((dir) => dir !== GLOBAL_DB_EXPORT_FILE);
|
|
18951
18951
|
}
|
|
18952
|
-
async function importApp(appId,
|
|
18952
|
+
async function importApp(appId, db2, template) {
|
|
18953
18953
|
var _a, _b;
|
|
18954
18954
|
let prodAppId = db_exports.getProdAppID(appId);
|
|
18955
18955
|
let dbStream;
|
|
@@ -18990,12 +18990,12 @@ async function importApp(appId, db, template) {
|
|
|
18990
18990
|
} else {
|
|
18991
18991
|
dbStream = await getTemplateStream(template);
|
|
18992
18992
|
}
|
|
18993
|
-
const { ok } = await
|
|
18993
|
+
const { ok } = await db2.load(dbStream);
|
|
18994
18994
|
if (!ok) {
|
|
18995
18995
|
throw "Error loading database dump from template.";
|
|
18996
18996
|
}
|
|
18997
|
-
await updateAttachmentColumns(prodAppId,
|
|
18998
|
-
await updateAutomations(prodAppId,
|
|
18997
|
+
await updateAttachmentColumns(prodAppId, db2);
|
|
18998
|
+
await updateAutomations(prodAppId, db2);
|
|
18999
18999
|
return ok;
|
|
19000
19000
|
}
|
|
19001
19001
|
|
|
@@ -19007,54 +19007,54 @@ __export(statistics_exports, {
|
|
|
19007
19007
|
calculateDatasourceCount: () => calculateDatasourceCount,
|
|
19008
19008
|
calculateScreenCount: () => calculateScreenCount
|
|
19009
19009
|
});
|
|
19010
|
-
async function runInContext(appId, cb,
|
|
19011
|
-
if (
|
|
19012
|
-
return cb(
|
|
19010
|
+
async function runInContext(appId, cb, db2) {
|
|
19011
|
+
if (db2) {
|
|
19012
|
+
return cb(db2);
|
|
19013
19013
|
} else {
|
|
19014
19014
|
const devAppId = db_exports.getDevAppID(appId);
|
|
19015
19015
|
return context_exports.doInAppContext(devAppId, () => {
|
|
19016
|
-
const
|
|
19017
|
-
return cb(
|
|
19016
|
+
const db3 = context_exports.getAppDB();
|
|
19017
|
+
return cb(db3);
|
|
19018
19018
|
});
|
|
19019
19019
|
}
|
|
19020
19020
|
}
|
|
19021
|
-
async function calculateDatasourceCount(appId,
|
|
19021
|
+
async function calculateDatasourceCount(appId, db2) {
|
|
19022
19022
|
return runInContext(
|
|
19023
19023
|
appId,
|
|
19024
|
-
async (
|
|
19025
|
-
const datasourceList = await
|
|
19026
|
-
const tableList = await
|
|
19024
|
+
async (db3) => {
|
|
19025
|
+
const datasourceList = await db3.allDocs(getDatasourceParams());
|
|
19026
|
+
const tableList = await db3.allDocs(getTableParams());
|
|
19027
19027
|
return datasourceList.rows.length + tableList.rows.length;
|
|
19028
19028
|
},
|
|
19029
|
-
|
|
19029
|
+
db2
|
|
19030
19030
|
);
|
|
19031
19031
|
}
|
|
19032
|
-
async function calculateAutomationCount(appId,
|
|
19032
|
+
async function calculateAutomationCount(appId, db2) {
|
|
19033
19033
|
return runInContext(
|
|
19034
19034
|
appId,
|
|
19035
|
-
async (
|
|
19036
|
-
const automationList = await
|
|
19035
|
+
async (db3) => {
|
|
19036
|
+
const automationList = await db3.allDocs(getAutomationParams());
|
|
19037
19037
|
return automationList.rows.length;
|
|
19038
19038
|
},
|
|
19039
|
-
|
|
19039
|
+
db2
|
|
19040
19040
|
);
|
|
19041
19041
|
}
|
|
19042
|
-
async function calculateScreenCount(appId,
|
|
19042
|
+
async function calculateScreenCount(appId, db2) {
|
|
19043
19043
|
return runInContext(
|
|
19044
19044
|
appId,
|
|
19045
|
-
async (
|
|
19046
|
-
const screenList = await
|
|
19045
|
+
async (db3) => {
|
|
19046
|
+
const screenList = await db3.allDocs(getScreenParams());
|
|
19047
19047
|
return screenList.rows.length;
|
|
19048
19048
|
},
|
|
19049
|
-
|
|
19049
|
+
db2
|
|
19050
19050
|
);
|
|
19051
19051
|
}
|
|
19052
19052
|
async function calculateBackupStats(appId) {
|
|
19053
|
-
return runInContext(appId, async (
|
|
19053
|
+
return runInContext(appId, async (db2) => {
|
|
19054
19054
|
const promises = [];
|
|
19055
|
-
promises.push(calculateDatasourceCount(appId,
|
|
19056
|
-
promises.push(calculateAutomationCount(appId,
|
|
19057
|
-
promises.push(calculateScreenCount(appId,
|
|
19055
|
+
promises.push(calculateDatasourceCount(appId, db2));
|
|
19056
|
+
promises.push(calculateAutomationCount(appId, db2));
|
|
19057
|
+
promises.push(calculateScreenCount(appId, db2));
|
|
19058
19058
|
const responses = await Promise.all(promises);
|
|
19059
19059
|
return {
|
|
19060
19060
|
datasources: responses[0],
|
|
@@ -19300,11 +19300,11 @@ var setCurrentMonth = (usage) => {
|
|
|
19300
19300
|
}
|
|
19301
19301
|
usage.monthly.current = usage.monthly[currentMonth];
|
|
19302
19302
|
};
|
|
19303
|
-
var getBreakdownName = (
|
|
19304
|
-
if (!id || !
|
|
19303
|
+
var getBreakdownName = (name2, id) => {
|
|
19304
|
+
if (!id || !name2) {
|
|
19305
19305
|
return;
|
|
19306
19306
|
}
|
|
19307
|
-
switch (
|
|
19307
|
+
switch (name2) {
|
|
19308
19308
|
case "automations" /* AUTOMATIONS */:
|
|
19309
19309
|
return "automations" /* AUTOMATIONS */;
|
|
19310
19310
|
case "queries" /* QUERIES */:
|
|
@@ -19318,11 +19318,11 @@ var getDB2 = () => {
|
|
|
19318
19318
|
return new Writethrough2(tenancy.getGlobalDB());
|
|
19319
19319
|
};
|
|
19320
19320
|
var bustCache2 = async () => {
|
|
19321
|
-
const
|
|
19321
|
+
const db2 = getDB2();
|
|
19322
19322
|
try {
|
|
19323
|
-
const usage = await
|
|
19323
|
+
const usage = await db2.get(db_exports.StaticDatabases.GLOBAL.docs.usageQuota);
|
|
19324
19324
|
if (usage == null ? void 0 : usage._rev) {
|
|
19325
|
-
await
|
|
19325
|
+
await db2.remove(
|
|
19326
19326
|
db_exports.StaticDatabases.GLOBAL.docs.usageQuota,
|
|
19327
19327
|
usage == null ? void 0 : usage._rev
|
|
19328
19328
|
);
|
|
@@ -19334,16 +19334,16 @@ var bustCache2 = async () => {
|
|
|
19334
19334
|
}
|
|
19335
19335
|
};
|
|
19336
19336
|
var getQuotaUsage = async () => {
|
|
19337
|
-
const
|
|
19337
|
+
const db2 = getDB2();
|
|
19338
19338
|
let usage;
|
|
19339
19339
|
try {
|
|
19340
|
-
usage = await
|
|
19340
|
+
usage = await db2.get(db_exports.StaticDatabases.GLOBAL.docs.usageQuota);
|
|
19341
19341
|
setCurrentMonth(usage);
|
|
19342
19342
|
setQuotaReset(usage);
|
|
19343
19343
|
} catch (err) {
|
|
19344
19344
|
if (err.status === 404) {
|
|
19345
19345
|
usage = generateNewQuotaUsage();
|
|
19346
|
-
const response = await
|
|
19346
|
+
const response = await db2.put(usage);
|
|
19347
19347
|
usage._rev = response.rev;
|
|
19348
19348
|
} else {
|
|
19349
19349
|
throw err;
|
|
@@ -19358,17 +19358,17 @@ var getQuotaUsage = async () => {
|
|
|
19358
19358
|
delete usage.usageQuota.developers;
|
|
19359
19359
|
return usage;
|
|
19360
19360
|
};
|
|
19361
|
-
var setUsage = async (value,
|
|
19362
|
-
return setAllUsage(
|
|
19361
|
+
var setUsage = async (value, name2, type) => {
|
|
19362
|
+
return setAllUsage(name2, type, { total: value });
|
|
19363
19363
|
};
|
|
19364
|
-
var setUsagePerApp = async (appValues,
|
|
19365
|
-
const
|
|
19364
|
+
var setUsagePerApp = async (appValues, name2, type) => {
|
|
19365
|
+
const db2 = getDB2();
|
|
19366
19366
|
let quotaUsage = await getQuotaUsage();
|
|
19367
19367
|
const total = Object.values(appValues).reduce((sum, num) => sum + num, 0);
|
|
19368
19368
|
for (let [appId, value] of Object.entries(appValues)) {
|
|
19369
19369
|
quotaUsage = coreUsageUpdate(
|
|
19370
19370
|
quotaUsage,
|
|
19371
|
-
|
|
19371
|
+
name2,
|
|
19372
19372
|
type,
|
|
19373
19373
|
{
|
|
19374
19374
|
total,
|
|
@@ -19379,12 +19379,12 @@ var setUsagePerApp = async (appValues, name, type) => {
|
|
|
19379
19379
|
}
|
|
19380
19380
|
);
|
|
19381
19381
|
}
|
|
19382
|
-
const response = await
|
|
19382
|
+
const response = await db2.put(quotaUsage);
|
|
19383
19383
|
quotaUsage._rev = response.rev;
|
|
19384
19384
|
return quotaUsage;
|
|
19385
19385
|
};
|
|
19386
|
-
var setBreakdown = (monthUsage,
|
|
19387
|
-
const breakdownName = getBreakdownName(
|
|
19386
|
+
var setBreakdown = (monthUsage, name2, id, values) => {
|
|
19387
|
+
const breakdownName = getBreakdownName(name2, id);
|
|
19388
19388
|
if (!breakdownName || !(values == null ? void 0 : values.breakdown)) {
|
|
19389
19389
|
return monthUsage;
|
|
19390
19390
|
}
|
|
@@ -19393,7 +19393,7 @@ var setBreakdown = (monthUsage, name, id, values) => {
|
|
|
19393
19393
|
}
|
|
19394
19394
|
if (!monthUsage.breakdown[breakdownName]) {
|
|
19395
19395
|
monthUsage.breakdown[breakdownName] = {
|
|
19396
|
-
parent:
|
|
19396
|
+
parent: name2,
|
|
19397
19397
|
values: {}
|
|
19398
19398
|
};
|
|
19399
19399
|
}
|
|
@@ -19401,14 +19401,14 @@ var setBreakdown = (monthUsage, name, id, values) => {
|
|
|
19401
19401
|
breakdown.values[id] = values.breakdown;
|
|
19402
19402
|
return monthUsage;
|
|
19403
19403
|
};
|
|
19404
|
-
var setAppUsageValue = (quotaUsage,
|
|
19404
|
+
var setAppUsageValue = (quotaUsage, name2, type, opts = {}, values) => {
|
|
19405
19405
|
var _a;
|
|
19406
19406
|
let appId;
|
|
19407
19407
|
try {
|
|
19408
19408
|
appId = db_exports.getProdAppID((opts == null ? void 0 : opts.appId) || context_exports.getAppId());
|
|
19409
19409
|
} catch (err) {
|
|
19410
19410
|
}
|
|
19411
|
-
if (!appId || !values.app || !APP_QUOTA_NAMES.includes(
|
|
19411
|
+
if (!appId || !values.app || !APP_QUOTA_NAMES.includes(name2)) {
|
|
19412
19412
|
return quotaUsage;
|
|
19413
19413
|
}
|
|
19414
19414
|
if (!((_a = quotaUsage.apps) == null ? void 0 : _a[appId])) {
|
|
@@ -19420,11 +19420,11 @@ var setAppUsageValue = (quotaUsage, name, type, opts = {}, values) => {
|
|
|
19420
19420
|
const appUsage = quotaUsage.apps[appId];
|
|
19421
19421
|
switch (type) {
|
|
19422
19422
|
case "static" /* STATIC */:
|
|
19423
|
-
appUsage.usageQuota[
|
|
19423
|
+
appUsage.usageQuota[name2] = values.app;
|
|
19424
19424
|
break;
|
|
19425
19425
|
case "monthly" /* MONTHLY */:
|
|
19426
19426
|
const currentMonth = getCurrentMonthString();
|
|
19427
|
-
const monthlyName =
|
|
19427
|
+
const monthlyName = name2;
|
|
19428
19428
|
let monthUsage = appUsage.monthly[currentMonth];
|
|
19429
19429
|
if (!monthUsage) {
|
|
19430
19430
|
appUsage.monthly[currentMonth] = generateNewMonthlyQuotas();
|
|
@@ -19438,9 +19438,9 @@ var setAppUsageValue = (quotaUsage, name, type, opts = {}, values) => {
|
|
|
19438
19438
|
}
|
|
19439
19439
|
return quotaUsage;
|
|
19440
19440
|
};
|
|
19441
|
-
var getAppUsageValue = (quotaUsage, type,
|
|
19441
|
+
var getAppUsageValue = (quotaUsage, type, name2, id) => {
|
|
19442
19442
|
var _a, _b, _c, _d, _e;
|
|
19443
|
-
if (!APP_QUOTA_NAMES.includes(
|
|
19443
|
+
if (!APP_QUOTA_NAMES.includes(name2)) {
|
|
19444
19444
|
return {};
|
|
19445
19445
|
}
|
|
19446
19446
|
let appId;
|
|
@@ -19454,13 +19454,13 @@ var getAppUsageValue = (quotaUsage, type, name, id) => {
|
|
|
19454
19454
|
const appUsage = quotaUsage.apps[appId];
|
|
19455
19455
|
switch (type) {
|
|
19456
19456
|
case "static" /* STATIC */:
|
|
19457
|
-
if ((_a = appUsage.usageQuota) == null ? void 0 : _a[
|
|
19458
|
-
return { app: appUsage.usageQuota[
|
|
19457
|
+
if ((_a = appUsage.usageQuota) == null ? void 0 : _a[name2]) {
|
|
19458
|
+
return { app: appUsage.usageQuota[name2] };
|
|
19459
19459
|
}
|
|
19460
19460
|
break;
|
|
19461
19461
|
case "monthly" /* MONTHLY */:
|
|
19462
19462
|
const currentMonth = getCurrentMonthString();
|
|
19463
|
-
const monthlyName =
|
|
19463
|
+
const monthlyName = name2;
|
|
19464
19464
|
if (!((_c = (_b = appUsage.monthly) == null ? void 0 : _b[currentMonth]) == null ? void 0 : _c[monthlyName])) {
|
|
19465
19465
|
break;
|
|
19466
19466
|
}
|
|
@@ -19475,68 +19475,68 @@ var getAppUsageValue = (quotaUsage, type, name, id) => {
|
|
|
19475
19475
|
}
|
|
19476
19476
|
return { app: 0 };
|
|
19477
19477
|
};
|
|
19478
|
-
var setStaticTriggers = (
|
|
19478
|
+
var setStaticTriggers = (name2, quotaUsage, triggers) => {
|
|
19479
19479
|
if (!quotaUsage.usageQuota.triggers) {
|
|
19480
19480
|
quotaUsage.usageQuota.triggers = {};
|
|
19481
19481
|
}
|
|
19482
19482
|
if (triggers) {
|
|
19483
|
-
quotaUsage.usageQuota.triggers[
|
|
19483
|
+
quotaUsage.usageQuota.triggers[name2] = triggers;
|
|
19484
19484
|
}
|
|
19485
19485
|
};
|
|
19486
|
-
var setMonthlyTriggers = (
|
|
19486
|
+
var setMonthlyTriggers = (name2, currentMonth, quotaUsage, triggers) => {
|
|
19487
19487
|
if (!quotaUsage.monthly[currentMonth].triggers) {
|
|
19488
19488
|
quotaUsage.monthly[currentMonth].triggers = {};
|
|
19489
19489
|
}
|
|
19490
19490
|
if (triggers) {
|
|
19491
|
-
quotaUsage.monthly[currentMonth].triggers[
|
|
19491
|
+
quotaUsage.monthly[currentMonth].triggers[name2] = triggers;
|
|
19492
19492
|
}
|
|
19493
19493
|
};
|
|
19494
|
-
var coreUsageUpdate = (quotaUsage,
|
|
19494
|
+
var coreUsageUpdate = (quotaUsage, name2, type, values, opts = {}) => {
|
|
19495
19495
|
if (type === "static" /* STATIC */) {
|
|
19496
|
-
|
|
19497
|
-
quotaUsage.usageQuota[
|
|
19498
|
-
setStaticTriggers(
|
|
19496
|
+
name2 = name2;
|
|
19497
|
+
quotaUsage.usageQuota[name2] = values.total;
|
|
19498
|
+
setStaticTriggers(name2, quotaUsage, values.triggers);
|
|
19499
19499
|
} else if (type === "monthly" /* MONTHLY */) {
|
|
19500
|
-
|
|
19500
|
+
name2 = name2;
|
|
19501
19501
|
const currentMonth = getCurrentMonthString();
|
|
19502
|
-
quotaUsage.monthly[currentMonth][
|
|
19503
|
-
setMonthlyTriggers(
|
|
19502
|
+
quotaUsage.monthly[currentMonth][name2] = values.total;
|
|
19503
|
+
setMonthlyTriggers(name2, currentMonth, quotaUsage, values.triggers);
|
|
19504
19504
|
} else {
|
|
19505
19505
|
throw new Error(`Invalid usage type: ${type}`);
|
|
19506
19506
|
}
|
|
19507
|
-
return setAppUsageValue(quotaUsage,
|
|
19507
|
+
return setAppUsageValue(quotaUsage, name2, type, opts, values);
|
|
19508
19508
|
};
|
|
19509
|
-
var setAllUsage = async (
|
|
19510
|
-
const
|
|
19509
|
+
var setAllUsage = async (name2, type, values, opts = {}) => {
|
|
19510
|
+
const db2 = getDB2();
|
|
19511
19511
|
let quotaUsage = await getQuotaUsage();
|
|
19512
|
-
quotaUsage = coreUsageUpdate(quotaUsage,
|
|
19513
|
-
const response = await
|
|
19512
|
+
quotaUsage = coreUsageUpdate(quotaUsage, name2, type, values, opts);
|
|
19513
|
+
const response = await db2.put(quotaUsage);
|
|
19514
19514
|
quotaUsage._rev = response.rev;
|
|
19515
19515
|
return quotaUsage;
|
|
19516
19516
|
};
|
|
19517
|
-
var getCurrentUsageValues = async (type,
|
|
19517
|
+
var getCurrentUsageValues = async (type, name2, id) => {
|
|
19518
19518
|
const quotaUsage = await getQuotaUsage();
|
|
19519
19519
|
let total = 0, appValues = {};
|
|
19520
19520
|
switch (type) {
|
|
19521
19521
|
case "static" /* STATIC */:
|
|
19522
|
-
if (quotaUsage.usageQuota[
|
|
19523
|
-
const staticName =
|
|
19522
|
+
if (quotaUsage.usageQuota[name2]) {
|
|
19523
|
+
const staticName = name2;
|
|
19524
19524
|
total = quotaUsage.usageQuota[staticName];
|
|
19525
|
-
appValues = getAppUsageValue(quotaUsage, type,
|
|
19525
|
+
appValues = getAppUsageValue(quotaUsage, type, name2, id);
|
|
19526
19526
|
}
|
|
19527
19527
|
break;
|
|
19528
19528
|
case "monthly" /* MONTHLY */:
|
|
19529
19529
|
const currentMonth = getCurrentMonthString();
|
|
19530
|
-
const monthlyName =
|
|
19530
|
+
const monthlyName = name2;
|
|
19531
19531
|
if (quotaUsage.monthly[currentMonth][monthlyName]) {
|
|
19532
19532
|
total = quotaUsage.monthly[currentMonth][monthlyName];
|
|
19533
|
-
appValues = getAppUsageValue(quotaUsage, type,
|
|
19533
|
+
appValues = getAppUsageValue(quotaUsage, type, name2, id);
|
|
19534
19534
|
}
|
|
19535
19535
|
break;
|
|
19536
19536
|
default:
|
|
19537
19537
|
throw new Error(`Invalid usage type: ${type}`);
|
|
19538
19538
|
}
|
|
19539
|
-
if (APP_QUOTA_NAMES.includes(
|
|
19539
|
+
if (APP_QUOTA_NAMES.includes(name2) && !(appValues.app || appValues.breakdown)) {
|
|
19540
19540
|
appValues.app = appValues.app || 0;
|
|
19541
19541
|
appValues.breakdown = appValues.breakdown || 0;
|
|
19542
19542
|
}
|
|
@@ -19557,8 +19557,8 @@ var newLicenseInfo = (licenseKey) => {
|
|
|
19557
19557
|
};
|
|
19558
19558
|
};
|
|
19559
19559
|
var save2 = async (licenseInfo) => {
|
|
19560
|
-
const
|
|
19561
|
-
const response = await
|
|
19560
|
+
const db2 = tenancy.getGlobalDB();
|
|
19561
|
+
const response = await db2.put(licenseInfo);
|
|
19562
19562
|
licenseInfo._rev = response.rev;
|
|
19563
19563
|
return licenseInfo;
|
|
19564
19564
|
};
|
|
@@ -19567,9 +19567,9 @@ var create = async (licenseKey) => {
|
|
|
19567
19567
|
return save2(licenseInfo);
|
|
19568
19568
|
};
|
|
19569
19569
|
var get4 = async () => {
|
|
19570
|
-
const
|
|
19570
|
+
const db2 = tenancy.getGlobalDB();
|
|
19571
19571
|
try {
|
|
19572
|
-
return await
|
|
19572
|
+
return await db2.get(StaticDatabases.GLOBAL.docs.licenseInfo);
|
|
19573
19573
|
} catch (err) {
|
|
19574
19574
|
if (err.status === 404) {
|
|
19575
19575
|
return void 0;
|
|
@@ -19582,8 +19582,8 @@ var destroy2 = async () => {
|
|
|
19582
19582
|
if (!info) {
|
|
19583
19583
|
return;
|
|
19584
19584
|
}
|
|
19585
|
-
const
|
|
19586
|
-
return
|
|
19585
|
+
const db2 = tenancy.getGlobalDB();
|
|
19586
|
+
return db2.remove(StaticDatabases.GLOBAL.docs.licenseInfo, info._rev);
|
|
19587
19587
|
};
|
|
19588
19588
|
|
|
19589
19589
|
// ../pro/packages/pro/src/db/groups.ts
|
|
@@ -19605,10 +19605,10 @@ __export(groups_exports, {
|
|
|
19605
19605
|
// ../pro/packages/pro/src/db/views/staticViews.ts
|
|
19606
19606
|
init_src();
|
|
19607
19607
|
async function createAuditLogSearchIndex() {
|
|
19608
|
-
const
|
|
19608
|
+
const db2 = context_exports.getAuditLogsDB();
|
|
19609
19609
|
let designDoc;
|
|
19610
19610
|
try {
|
|
19611
|
-
designDoc = await
|
|
19611
|
+
designDoc = await db2.get("_design/database");
|
|
19612
19612
|
} catch (err) {
|
|
19613
19613
|
if (err.status === 404) {
|
|
19614
19614
|
designDoc = { _id: "_design/database" };
|
|
@@ -19651,14 +19651,14 @@ async function createAuditLogSearchIndex() {
|
|
|
19651
19651
|
}
|
|
19652
19652
|
}
|
|
19653
19653
|
};
|
|
19654
|
-
await
|
|
19654
|
+
await db2.put(designDoc);
|
|
19655
19655
|
}
|
|
19656
19656
|
|
|
19657
19657
|
// ../pro/packages/pro/src/db/views/groups.ts
|
|
19658
19658
|
var { ViewName: ViewName4, SEPARATOR: SEPARATOR5, DocumentType: DocumentType3, createView: createView2 } = db_exports;
|
|
19659
19659
|
var USER_PREFIX = DocumentType3.USER + SEPARATOR5;
|
|
19660
19660
|
async function createGroupUserLookupView() {
|
|
19661
|
-
const
|
|
19661
|
+
const db2 = tenancy.getGlobalDB();
|
|
19662
19662
|
const viewJs = `function(doc) {
|
|
19663
19663
|
if (doc._id.startsWith("${USER_PREFIX}") && Array.isArray(doc.userGroups)) {
|
|
19664
19664
|
for (let groupId of doc.userGroups) {
|
|
@@ -19667,7 +19667,7 @@ async function createGroupUserLookupView() {
|
|
|
19667
19667
|
}
|
|
19668
19668
|
}
|
|
19669
19669
|
}`;
|
|
19670
|
-
await createView2(
|
|
19670
|
+
await createView2(db2, viewJs, ViewName4.USER_BY_GROUP);
|
|
19671
19671
|
}
|
|
19672
19672
|
|
|
19673
19673
|
// ../pro/packages/pro/src/db/groups.ts
|
|
@@ -19707,17 +19707,17 @@ function generateUserGroupID() {
|
|
|
19707
19707
|
return `${GROUP_PREFIX}${utils_exports2.newid()}`;
|
|
19708
19708
|
}
|
|
19709
19709
|
async function getGroupUsers(groupId, params2) {
|
|
19710
|
-
const
|
|
19710
|
+
const db2 = tenancy.getGlobalDB();
|
|
19711
19711
|
const userDocs = await db_exports.queryView(
|
|
19712
19712
|
db_exports.ViewName.USER_BY_GROUP,
|
|
19713
19713
|
getGroupUsersParams(groupId, params2),
|
|
19714
|
-
|
|
19714
|
+
db2,
|
|
19715
19715
|
createGroupUserLookupView,
|
|
19716
19716
|
{ arrayResponse: true }
|
|
19717
19717
|
);
|
|
19718
|
-
const users2 = userDocs.map((
|
|
19719
|
-
_id:
|
|
19720
|
-
email:
|
|
19718
|
+
const users2 = userDocs.map((doc2) => ({
|
|
19719
|
+
_id: doc2.userId,
|
|
19720
|
+
email: doc2.email
|
|
19721
19721
|
})) || [];
|
|
19722
19722
|
return users2;
|
|
19723
19723
|
}
|
|
@@ -19746,9 +19746,9 @@ async function cleanupUsers(group) {
|
|
|
19746
19746
|
}
|
|
19747
19747
|
}
|
|
19748
19748
|
async function fetch11() {
|
|
19749
|
-
const
|
|
19749
|
+
const db2 = tenancy.getGlobalDB();
|
|
19750
19750
|
try {
|
|
19751
|
-
const groups = (await
|
|
19751
|
+
const groups = (await db2.allDocs(
|
|
19752
19752
|
getUserGroupsParams(null, {
|
|
19753
19753
|
include_docs: true
|
|
19754
19754
|
})
|
|
@@ -19763,18 +19763,18 @@ async function fetch11() {
|
|
|
19763
19763
|
}
|
|
19764
19764
|
}
|
|
19765
19765
|
async function get5(groupId) {
|
|
19766
|
-
const
|
|
19766
|
+
const db2 = tenancy.getGlobalDB();
|
|
19767
19767
|
try {
|
|
19768
|
-
const group = await
|
|
19768
|
+
const group = await db2.get(groupId);
|
|
19769
19769
|
return await enrichGroup(group);
|
|
19770
19770
|
} catch (err) {
|
|
19771
19771
|
throw err;
|
|
19772
19772
|
}
|
|
19773
19773
|
}
|
|
19774
19774
|
async function getBulk(groupIds, opts = { enriched: true }) {
|
|
19775
|
-
const
|
|
19775
|
+
const db2 = tenancy.getGlobalDB();
|
|
19776
19776
|
try {
|
|
19777
|
-
const groups = (await
|
|
19777
|
+
const groups = (await db2.allDocs({
|
|
19778
19778
|
keys: groupIds,
|
|
19779
19779
|
include_docs: true
|
|
19780
19780
|
})).rows.map((row) => row.doc);
|
|
@@ -19792,26 +19792,26 @@ async function getBulk(groupIds, opts = { enriched: true }) {
|
|
|
19792
19792
|
}
|
|
19793
19793
|
}
|
|
19794
19794
|
async function save3(group) {
|
|
19795
|
-
const
|
|
19796
|
-
return await
|
|
19795
|
+
const db2 = tenancy.getGlobalDB();
|
|
19796
|
+
return await db2.put(group);
|
|
19797
19797
|
}
|
|
19798
19798
|
async function bulkSave(groups) {
|
|
19799
|
-
const
|
|
19800
|
-
return await
|
|
19799
|
+
const db2 = tenancy.getGlobalDB();
|
|
19800
|
+
return await db2.bulkDocs(groups);
|
|
19801
19801
|
}
|
|
19802
19802
|
async function destroy3(groupId, revision) {
|
|
19803
|
-
const
|
|
19804
|
-
const group = await
|
|
19805
|
-
let resp = await
|
|
19803
|
+
const db2 = tenancy.getGlobalDB();
|
|
19804
|
+
const group = await db2.get(groupId);
|
|
19805
|
+
let resp = await db2.remove(groupId, revision);
|
|
19806
19806
|
await cleanupUsers(group);
|
|
19807
19807
|
return resp;
|
|
19808
19808
|
}
|
|
19809
|
-
async function getByName(
|
|
19809
|
+
async function getByName(name2) {
|
|
19810
19810
|
try {
|
|
19811
19811
|
const groups = await db_exports.directCouchFind(tenancy.getGlobalDBName(), {
|
|
19812
19812
|
selector: {
|
|
19813
19813
|
name: {
|
|
19814
|
-
$regex: `^(?i)${
|
|
19814
|
+
$regex: `^(?i)${name2}$`
|
|
19815
19815
|
}
|
|
19816
19816
|
},
|
|
19817
19817
|
limit: 1
|
|
@@ -19861,7 +19861,7 @@ var { ViewName: ViewName5, AutomationViewMode: AutomationViewMode2, SEPARATOR: S
|
|
|
19861
19861
|
var LOG_PREFIX = DocumentType4.AUTOMATION_LOG + SEPARATOR6;
|
|
19862
19862
|
var APP_BACKUP_PREFIX = DocumentType4.APP_BACKUP + SEPARATOR6;
|
|
19863
19863
|
async function createLogByAutomationView() {
|
|
19864
|
-
const
|
|
19864
|
+
const db2 = context_exports.getProdAppDB();
|
|
19865
19865
|
const viewJs = `function(doc) {
|
|
19866
19866
|
if (doc._id.startsWith("${LOG_PREFIX}")) {
|
|
19867
19867
|
let autoId = doc.automationId + "${SEPARATOR6}"
|
|
@@ -19874,10 +19874,10 @@ async function createLogByAutomationView() {
|
|
|
19874
19874
|
emit(allKey)
|
|
19875
19875
|
}
|
|
19876
19876
|
}`;
|
|
19877
|
-
await createView3(
|
|
19877
|
+
await createView3(db2, viewJs, ViewName5.AUTOMATION_LOGS);
|
|
19878
19878
|
}
|
|
19879
19879
|
async function createAppBackupTriggerView() {
|
|
19880
|
-
const
|
|
19880
|
+
const db2 = tenancy.getGlobalDB();
|
|
19881
19881
|
const viewJs = `function(doc) {
|
|
19882
19882
|
if (doc._id.startsWith("${APP_BACKUP_PREFIX}") && doc.type && doc.trigger) {
|
|
19883
19883
|
let full = doc.appId + "${SEPARATOR6}"
|
|
@@ -19886,7 +19886,7 @@ async function createAppBackupTriggerView() {
|
|
|
19886
19886
|
emit("${APP_BACKUP_PREFIX}" + full + doc.timestamp)
|
|
19887
19887
|
}
|
|
19888
19888
|
}`;
|
|
19889
|
-
await createView3(
|
|
19889
|
+
await createView3(db2, viewJs, ViewName5.APP_BACKUP_BY_TRIGGER);
|
|
19890
19890
|
}
|
|
19891
19891
|
|
|
19892
19892
|
// ../pro/packages/pro/src/db/utils/retention.ts
|
|
@@ -20123,11 +20123,11 @@ var getLicenseVersion = () => {
|
|
|
20123
20123
|
}
|
|
20124
20124
|
};
|
|
20125
20125
|
var getProVersion = () => {
|
|
20126
|
-
const
|
|
20127
|
-
if (!
|
|
20126
|
+
const version2 = environment_default2.VERSION;
|
|
20127
|
+
if (!version2) {
|
|
20128
20128
|
throw new Error("No budibase pro version was specified");
|
|
20129
20129
|
}
|
|
20130
|
-
return
|
|
20130
|
+
return version2;
|
|
20131
20131
|
};
|
|
20132
20132
|
|
|
20133
20133
|
// ../pro/packages/pro/src/constants/misc.ts
|
|
@@ -20180,17 +20180,17 @@ async function getAppBackupParams(appId, filters, otherProps = {}) {
|
|
|
20180
20180
|
endkey: `${APP_BACKUP_PREFIX2}${endKey}`
|
|
20181
20181
|
};
|
|
20182
20182
|
}
|
|
20183
|
-
async function getAppBackupsByTrigger(
|
|
20183
|
+
async function getAppBackupsByTrigger(db2, params2) {
|
|
20184
20184
|
let backups = [];
|
|
20185
20185
|
try {
|
|
20186
20186
|
const queryIndex = db_exports.getQueryIndex(
|
|
20187
20187
|
db_exports.ViewName.APP_BACKUP_BY_TRIGGER
|
|
20188
20188
|
);
|
|
20189
|
-
backups = await
|
|
20189
|
+
backups = await db2.query(queryIndex, params2);
|
|
20190
20190
|
} catch (err) {
|
|
20191
20191
|
if (err != null && err.error === "not_found") {
|
|
20192
20192
|
await createAppBackupTriggerView();
|
|
20193
|
-
return getAppBackupsByTrigger(
|
|
20193
|
+
return getAppBackupsByTrigger(db2, params2);
|
|
20194
20194
|
} else {
|
|
20195
20195
|
throw err;
|
|
20196
20196
|
}
|
|
@@ -20201,7 +20201,7 @@ function generateAppBackupID(appId, timestamp) {
|
|
|
20201
20201
|
return `${APP_BACKUP_PREFIX2}${appId}${db_exports.SEPARATOR}${timestamp}`;
|
|
20202
20202
|
}
|
|
20203
20203
|
async function fetchAppBackups(appId, opts = {}) {
|
|
20204
|
-
const
|
|
20204
|
+
const db2 = tenancy.getGlobalDB();
|
|
20205
20205
|
let backups;
|
|
20206
20206
|
const pageSize = opts.limit || GENERIC_PAGE_SIZE;
|
|
20207
20207
|
const params2 = await getAppBackupParams(appId, opts, {
|
|
@@ -20212,9 +20212,9 @@ async function fetchAppBackups(appId, opts = {}) {
|
|
|
20212
20212
|
params2.startkey = opts.page;
|
|
20213
20213
|
}
|
|
20214
20214
|
if (!opts.trigger || !opts.type) {
|
|
20215
|
-
backups = await
|
|
20215
|
+
backups = await db2.allDocs(params2);
|
|
20216
20216
|
} else {
|
|
20217
|
-
backups = await getAppBackupsByTrigger(
|
|
20217
|
+
backups = await getAppBackupsByTrigger(db2, params2);
|
|
20218
20218
|
}
|
|
20219
20219
|
const pageData = pagination2(backups, {
|
|
20220
20220
|
paginate: opts.paginate,
|
|
@@ -20237,15 +20237,15 @@ async function fetchAppBackups(appId, opts = {}) {
|
|
|
20237
20237
|
}
|
|
20238
20238
|
return pageData;
|
|
20239
20239
|
}
|
|
20240
|
-
async function storeAppBackupMetadata(
|
|
20241
|
-
const
|
|
20242
|
-
const prodAppId = db_exports.getProdAppID(
|
|
20243
|
-
let _id = generateAppBackupID(prodAppId,
|
|
20240
|
+
async function storeAppBackupMetadata(metadata2, opts = {}) {
|
|
20241
|
+
const db2 = tenancy.getGlobalDB();
|
|
20242
|
+
const prodAppId = db_exports.getProdAppID(metadata2.appId);
|
|
20243
|
+
let _id = generateAppBackupID(prodAppId, metadata2.timestamp);
|
|
20244
20244
|
const appBackupDoc = {
|
|
20245
|
-
...
|
|
20245
|
+
...metadata2,
|
|
20246
20246
|
_id,
|
|
20247
20247
|
appId: prodAppId,
|
|
20248
|
-
name:
|
|
20248
|
+
name: metadata2.name
|
|
20249
20249
|
};
|
|
20250
20250
|
if (opts.filename) {
|
|
20251
20251
|
appBackupDoc.filename = opts.filename;
|
|
@@ -20254,27 +20254,27 @@ async function storeAppBackupMetadata(metadata, opts = {}) {
|
|
|
20254
20254
|
appBackupDoc._id = opts.docId;
|
|
20255
20255
|
appBackupDoc._rev = opts.docRev;
|
|
20256
20256
|
}
|
|
20257
|
-
if (
|
|
20257
|
+
if (metadata2.createdBy) {
|
|
20258
20258
|
appBackupDoc.createdBy = db_exports.getGlobalIDFromUserMetadataID(
|
|
20259
|
-
|
|
20259
|
+
metadata2.createdBy
|
|
20260
20260
|
);
|
|
20261
20261
|
}
|
|
20262
|
-
return await
|
|
20262
|
+
return await db2.put(appBackupDoc);
|
|
20263
20263
|
}
|
|
20264
|
-
async function updateAppBackupMetadata(backupId,
|
|
20265
|
-
const
|
|
20266
|
-
const
|
|
20267
|
-
|
|
20268
|
-
return await
|
|
20264
|
+
async function updateAppBackupMetadata(backupId, name2) {
|
|
20265
|
+
const db2 = tenancy.getGlobalDB();
|
|
20266
|
+
const metadata2 = await db2.get(backupId);
|
|
20267
|
+
metadata2.name = name2;
|
|
20268
|
+
return await db2.put(metadata2);
|
|
20269
20269
|
}
|
|
20270
20270
|
async function deleteAppBackupMetadata(backupId) {
|
|
20271
|
-
const
|
|
20272
|
-
const backupDoc = await
|
|
20273
|
-
await
|
|
20271
|
+
const db2 = tenancy.getGlobalDB();
|
|
20272
|
+
const backupDoc = await db2.get(backupId);
|
|
20273
|
+
await db2.remove(backupDoc._id, backupDoc._rev);
|
|
20274
20274
|
}
|
|
20275
20275
|
async function getAppBackupMetadata(backupId) {
|
|
20276
|
-
const
|
|
20277
|
-
return await
|
|
20276
|
+
const db2 = tenancy.getGlobalDB();
|
|
20277
|
+
return await db2.get(backupId);
|
|
20278
20278
|
}
|
|
20279
20279
|
|
|
20280
20280
|
// ../pro/packages/pro/src/db/environmentVariables.ts
|
|
@@ -20293,16 +20293,16 @@ var cache = new import_lru_cache.default({
|
|
|
20293
20293
|
function getEnvVarID() {
|
|
20294
20294
|
return StaticDatabases.GLOBAL.docs.environmentVariables;
|
|
20295
20295
|
}
|
|
20296
|
-
function getCacheEnvVarID(
|
|
20296
|
+
function getCacheEnvVarID(rev2) {
|
|
20297
20297
|
const tenantId = tenancy.getTenantId();
|
|
20298
|
-
return `${tenantId}/${getEnvVarID()}/${
|
|
20298
|
+
return `${tenantId}/${getEnvVarID()}/${rev2 || ""}`;
|
|
20299
20299
|
}
|
|
20300
20300
|
async function get6() {
|
|
20301
20301
|
const id = getEnvVarID();
|
|
20302
|
-
const
|
|
20302
|
+
const db2 = tenancy.getGlobalDB();
|
|
20303
20303
|
let encrypted, notFound = false;
|
|
20304
20304
|
try {
|
|
20305
|
-
encrypted = await
|
|
20305
|
+
encrypted = await db2.get(id);
|
|
20306
20306
|
} catch (err) {
|
|
20307
20307
|
if (err.status == 404) {
|
|
20308
20308
|
notFound = true;
|
|
@@ -20335,14 +20335,14 @@ async function get6() {
|
|
|
20335
20335
|
cache.set(cacheKey, finalDoc);
|
|
20336
20336
|
return finalDoc;
|
|
20337
20337
|
}
|
|
20338
|
-
async function update(
|
|
20338
|
+
async function update(doc2) {
|
|
20339
20339
|
const id = getEnvVarID();
|
|
20340
|
-
const
|
|
20341
|
-
return await
|
|
20342
|
-
_id:
|
|
20343
|
-
_rev:
|
|
20340
|
+
const db2 = tenancy.getGlobalDB();
|
|
20341
|
+
return await db2.put({
|
|
20342
|
+
_id: doc2._id || id,
|
|
20343
|
+
_rev: doc2._rev || void 0,
|
|
20344
20344
|
variables: encryption_exports.encrypt(
|
|
20345
|
-
JSON.stringify(
|
|
20345
|
+
JSON.stringify(doc2.variables),
|
|
20346
20346
|
encryption_exports.SecretOption.ENCRYPTION
|
|
20347
20347
|
)
|
|
20348
20348
|
});
|
|
@@ -20706,14 +20706,14 @@ __export(quotas_exports4, {
|
|
|
20706
20706
|
|
|
20707
20707
|
// ../pro/packages/pro/src/sdk/quotas/quotas.ts
|
|
20708
20708
|
init_src();
|
|
20709
|
-
var increment = (
|
|
20710
|
-
return tryIncrement(1,
|
|
20709
|
+
var increment = (name2, type, opts) => {
|
|
20710
|
+
return tryIncrement(1, name2, type, opts);
|
|
20711
20711
|
};
|
|
20712
|
-
var incrementMany = (change,
|
|
20713
|
-
return tryIncrement(change,
|
|
20712
|
+
var incrementMany = (change, name2, type, opts) => {
|
|
20713
|
+
return tryIncrement(change, name2, type, opts);
|
|
20714
20714
|
};
|
|
20715
|
-
var tryIncrement = async (change,
|
|
20716
|
-
await updateUsage(change,
|
|
20715
|
+
var tryIncrement = async (change, name2, type, opts = {}) => {
|
|
20716
|
+
await updateUsage(change, name2, type, {
|
|
20717
20717
|
dryRun: true,
|
|
20718
20718
|
suppressErrorLog: opts.suppressErrorLog,
|
|
20719
20719
|
id: opts.id
|
|
@@ -20722,7 +20722,7 @@ var tryIncrement = async (change, name, type, opts = {}) => {
|
|
|
20722
20722
|
if (opts.fn) {
|
|
20723
20723
|
result = await opts.fn();
|
|
20724
20724
|
}
|
|
20725
|
-
await updateUsage(change,
|
|
20725
|
+
await updateUsage(change, name2, type, {
|
|
20726
20726
|
dryRun: false,
|
|
20727
20727
|
valueFn: opts.valueFn,
|
|
20728
20728
|
suppressErrorLog: opts.suppressErrorLog,
|
|
@@ -20730,32 +20730,32 @@ var tryIncrement = async (change, name, type, opts = {}) => {
|
|
|
20730
20730
|
});
|
|
20731
20731
|
return result;
|
|
20732
20732
|
};
|
|
20733
|
-
var decrement = (
|
|
20734
|
-
return updateUsage(-1,
|
|
20733
|
+
var decrement = (name2, type, opts = {}) => {
|
|
20734
|
+
return updateUsage(-1, name2, type, opts);
|
|
20735
20735
|
};
|
|
20736
|
-
var decrementMany = (change,
|
|
20737
|
-
return updateUsage(-change,
|
|
20736
|
+
var decrementMany = (change, name2, type, opts = {}) => {
|
|
20737
|
+
return updateUsage(-change, name2, type, opts);
|
|
20738
20738
|
};
|
|
20739
|
-
var set2 = async (
|
|
20740
|
-
return quotas_exports.setUsage(value,
|
|
20739
|
+
var set2 = async (name2, type, value) => {
|
|
20740
|
+
return quotas_exports.setUsage(value, name2, type);
|
|
20741
20741
|
};
|
|
20742
|
-
var getExistingTriggers = (type,
|
|
20742
|
+
var getExistingTriggers = (type, name2, quotaUsage) => {
|
|
20743
20743
|
if (type == "static" /* STATIC */) {
|
|
20744
20744
|
const triggers = quotaUsage.usageQuota.triggers;
|
|
20745
|
-
return triggers ? triggers[
|
|
20745
|
+
return triggers ? triggers[name2] || {} : {};
|
|
20746
20746
|
} else {
|
|
20747
20747
|
const currentMonthString = quotas_exports.utils.getCurrentMonthString();
|
|
20748
20748
|
const triggers = quotaUsage.monthly[currentMonthString].triggers;
|
|
20749
|
-
return triggers ? triggers[
|
|
20749
|
+
return triggers ? triggers[name2] || {} : {};
|
|
20750
20750
|
}
|
|
20751
20751
|
};
|
|
20752
|
-
var triggerQuota2 = async (
|
|
20752
|
+
var triggerQuota2 = async (name2, quota, percentage, resetDate) => {
|
|
20753
20753
|
try {
|
|
20754
20754
|
await redlockImpl_exports.doWithLock(
|
|
20755
20755
|
{
|
|
20756
20756
|
type: "try_once" /* TRY_ONCE */,
|
|
20757
20757
|
name: "trigger_quota" /* TRIGGER_QUOTA */,
|
|
20758
|
-
resource:
|
|
20758
|
+
resource: name2,
|
|
20759
20759
|
// use the quota name for extra uniqueness on the lock
|
|
20760
20760
|
ttl: 1e4
|
|
20761
20761
|
// auto expire after 10 seconds
|
|
@@ -20775,10 +20775,10 @@ var triggerQuota2 = async (name, quota, percentage, resetDate) => {
|
|
|
20775
20775
|
logging_exports.logAlert("Error triggering quota", e);
|
|
20776
20776
|
}
|
|
20777
20777
|
};
|
|
20778
|
-
var checkTriggers = async (type,
|
|
20778
|
+
var checkTriggers = async (type, name2, totalValue, quota) => {
|
|
20779
20779
|
const usage = await getQuotaUsage();
|
|
20780
20780
|
const resetDate = type === "monthly" /* MONTHLY */ ? usage.quotaReset : void 0;
|
|
20781
|
-
const triggers = await getExistingTriggers(type,
|
|
20781
|
+
const triggers = await getExistingTriggers(type, name2, usage);
|
|
20782
20782
|
const quotaTriggers = quota.triggers;
|
|
20783
20783
|
let percentage = totalValue / quota.value * 100;
|
|
20784
20784
|
if (percentage > 100) {
|
|
@@ -20794,7 +20794,7 @@ var checkTriggers = async (type, name, totalValue, quota) => {
|
|
|
20794
20794
|
const isAtTrigger = percentage === triggerPercentage;
|
|
20795
20795
|
const sendNotification = !nextIsTriggered || isAtTrigger;
|
|
20796
20796
|
if (sendNotification) {
|
|
20797
|
-
await triggerQuota2(
|
|
20797
|
+
await triggerQuota2(name2, quota, percentage, resetDate);
|
|
20798
20798
|
}
|
|
20799
20799
|
}
|
|
20800
20800
|
} else {
|
|
@@ -20803,23 +20803,23 @@ var checkTriggers = async (type, name, totalValue, quota) => {
|
|
|
20803
20803
|
}
|
|
20804
20804
|
return triggers;
|
|
20805
20805
|
};
|
|
20806
|
-
var updateUsage = async (usageChange,
|
|
20806
|
+
var updateUsage = async (usageChange, name2, type, opts = {}) => {
|
|
20807
20807
|
let appId = null;
|
|
20808
20808
|
try {
|
|
20809
20809
|
appId = context_exports.getAppId();
|
|
20810
20810
|
} catch (err) {
|
|
20811
20811
|
}
|
|
20812
|
-
const isAppQuota = APP_QUOTA_NAMES.includes(
|
|
20812
|
+
const isAppQuota = APP_QUOTA_NAMES.includes(name2);
|
|
20813
20813
|
if (isAppQuota && !appId) {
|
|
20814
20814
|
throw new Error("App context required for quota update");
|
|
20815
20815
|
}
|
|
20816
20816
|
try {
|
|
20817
|
-
const licensedQuota = await getLicensedQuota("usage" /* USAGE */,
|
|
20817
|
+
const licensedQuota = await getLicensedQuota("usage" /* USAGE */, name2, type);
|
|
20818
20818
|
let {
|
|
20819
20819
|
total: totalValue,
|
|
20820
20820
|
app: appValue,
|
|
20821
20821
|
breakdown: breakdownValue
|
|
20822
|
-
} = await quotas_exports.getCurrentUsageValues(type,
|
|
20822
|
+
} = await quotas_exports.getCurrentUsageValues(type, name2, opts.id);
|
|
20823
20823
|
totalValue += usageChange;
|
|
20824
20824
|
if (appValue != null) {
|
|
20825
20825
|
appValue += usageChange;
|
|
@@ -20829,7 +20829,7 @@ var updateUsage = async (usageChange, name, type, opts = {}) => {
|
|
|
20829
20829
|
}
|
|
20830
20830
|
let triggers = {};
|
|
20831
20831
|
if (!opts.dryRun) {
|
|
20832
|
-
triggers = await checkTriggers(type,
|
|
20832
|
+
triggers = await checkTriggers(type, name2, totalValue, licensedQuota);
|
|
20833
20833
|
}
|
|
20834
20834
|
if (licensedQuota.value !== quotas_exports2.UNLIMITED && totalValue > licensedQuota.value && usageChange > 0) {
|
|
20835
20835
|
throw new UsageLimitError(
|
|
@@ -20852,7 +20852,7 @@ var updateUsage = async (usageChange, name, type, opts = {}) => {
|
|
|
20852
20852
|
appValue = totalValue;
|
|
20853
20853
|
}
|
|
20854
20854
|
await quotas_exports.setAllUsage(
|
|
20855
|
-
|
|
20855
|
+
name2,
|
|
20856
20856
|
type,
|
|
20857
20857
|
{
|
|
20858
20858
|
total: totalValue,
|
|
@@ -20864,30 +20864,30 @@ var updateUsage = async (usageChange, name, type, opts = {}) => {
|
|
|
20864
20864
|
);
|
|
20865
20865
|
} catch (err) {
|
|
20866
20866
|
if (!opts.suppressErrorLog) {
|
|
20867
|
-
console.error(`Error updating usage quotas for ${
|
|
20867
|
+
console.error(`Error updating usage quotas for ${name2}`, err);
|
|
20868
20868
|
}
|
|
20869
20869
|
throw err;
|
|
20870
20870
|
}
|
|
20871
20871
|
};
|
|
20872
|
-
var getLicensedQuota = async (quotaType,
|
|
20872
|
+
var getLicensedQuota = async (quotaType, name2, usageType) => {
|
|
20873
20873
|
const license = await cache_exports2.getCachedLicense();
|
|
20874
20874
|
if (!license) {
|
|
20875
20875
|
const tenantId = tenancy.getTenantId();
|
|
20876
20876
|
throw new Error("License not found for tenant id " + tenantId);
|
|
20877
20877
|
}
|
|
20878
|
-
if (usageType && isStaticQuota(quotaType, usageType,
|
|
20879
|
-
return license.quotas[quotaType][usageType][
|
|
20880
|
-
} else if (usageType && isMonthlyQuota(quotaType, usageType,
|
|
20881
|
-
return license.quotas[quotaType][usageType][
|
|
20882
|
-
} else if (isConstantQuota(quotaType,
|
|
20883
|
-
return license.quotas[quotaType][
|
|
20878
|
+
if (usageType && isStaticQuota(quotaType, usageType, name2)) {
|
|
20879
|
+
return license.quotas[quotaType][usageType][name2];
|
|
20880
|
+
} else if (usageType && isMonthlyQuota(quotaType, usageType, name2)) {
|
|
20881
|
+
return license.quotas[quotaType][usageType][name2];
|
|
20882
|
+
} else if (isConstantQuota(quotaType, name2)) {
|
|
20883
|
+
return license.quotas[quotaType][name2];
|
|
20884
20884
|
} else {
|
|
20885
20885
|
throw new Error("Invalid quota type");
|
|
20886
20886
|
}
|
|
20887
20887
|
};
|
|
20888
|
-
var usageLimitIsExceeded = async (
|
|
20888
|
+
var usageLimitIsExceeded = async (name2, type) => {
|
|
20889
20889
|
try {
|
|
20890
|
-
await updateUsage(1,
|
|
20890
|
+
await updateUsage(1, name2, type, { dryRun: true });
|
|
20891
20891
|
return false;
|
|
20892
20892
|
} catch (e) {
|
|
20893
20893
|
if (e.code === "usage_limit_exceeded" /* USAGE_LIMIT_EXCEEDED */) {
|
|
@@ -21001,19 +21001,19 @@ async function recordDayPassOnQuotas() {
|
|
|
21001
21001
|
});
|
|
21002
21002
|
}
|
|
21003
21003
|
async function recordDayPassTimeOnUser(user) {
|
|
21004
|
-
const
|
|
21005
|
-
let dbUser = await
|
|
21004
|
+
const db2 = tenancy.getGlobalDB();
|
|
21005
|
+
let dbUser = await db2.get(user._id);
|
|
21006
21006
|
const now = /* @__PURE__ */ new Date();
|
|
21007
21007
|
const nowString = (/* @__PURE__ */ new Date()).toISOString();
|
|
21008
21008
|
user.dayPassRecordedAt = nowString;
|
|
21009
21009
|
dbUser.dayPassRecordedAt = nowString;
|
|
21010
21010
|
try {
|
|
21011
21011
|
console.log(`Recording day pass for user=${user._id}`);
|
|
21012
|
-
await
|
|
21012
|
+
await db2.put(dbUser);
|
|
21013
21013
|
} catch (e) {
|
|
21014
21014
|
if (e.status === 409) {
|
|
21015
21015
|
console.warn(`Conflict recording day pass for user=${user._id}`);
|
|
21016
|
-
dbUser = await
|
|
21016
|
+
dbUser = await db2.get(user._id);
|
|
21017
21017
|
if (!dbUser.dayPassRecordedAt || new Date(dbUser.dayPassRecordedAt).getDay() !== now.getDay()) {
|
|
21018
21018
|
console.error(`Day pass not recorded for user=${user._id}`);
|
|
21019
21019
|
throw e;
|
|
@@ -21262,9 +21262,9 @@ function generateAutomationLogID(isoDate, status2, automationId) {
|
|
|
21262
21262
|
return `${DocumentType5.AUTOMATION_LOG}${SEPARATOR7}${isoDate}${SEPARATOR7}${automationId}${SEPARATOR7}${status2}`;
|
|
21263
21263
|
}
|
|
21264
21264
|
async function getAllLogs(startDate, endDate, opts = { docs: true }) {
|
|
21265
|
-
let
|
|
21266
|
-
if (!await
|
|
21267
|
-
|
|
21265
|
+
let db2 = context_exports.getProdAppDB();
|
|
21266
|
+
if (!await db2.exists()) {
|
|
21267
|
+
db2 = context_exports.getDevAppDB();
|
|
21268
21268
|
}
|
|
21269
21269
|
let optional = { status: opts.status };
|
|
21270
21270
|
let limit = (opts == null ? void 0 : opts.limit) ? opts.limit : (opts == null ? void 0 : opts.paginate) ? GENERIC_PAGE_SIZE + 1 : void 0;
|
|
@@ -21275,16 +21275,16 @@ async function getAllLogs(startDate, endDate, opts = { docs: true }) {
|
|
|
21275
21275
|
if (opts == null ? void 0 : opts.page) {
|
|
21276
21276
|
params2.startkey = opts.page;
|
|
21277
21277
|
}
|
|
21278
|
-
let response = await
|
|
21278
|
+
let response = await db2.allDocs(params2);
|
|
21279
21279
|
return pagination2(response, {
|
|
21280
21280
|
paginate: opts == null ? void 0 : opts.paginate,
|
|
21281
21281
|
pageSize: GENERIC_PAGE_SIZE
|
|
21282
21282
|
});
|
|
21283
21283
|
}
|
|
21284
21284
|
async function getLogsByView(startDate, endDate, viewParams = {}) {
|
|
21285
|
-
let
|
|
21286
|
-
if (!await
|
|
21287
|
-
|
|
21285
|
+
let db2 = context_exports.getProdAppDB();
|
|
21286
|
+
if (!await db2.exists()) {
|
|
21287
|
+
db2 = context_exports.getDevAppDB();
|
|
21288
21288
|
}
|
|
21289
21289
|
let response;
|
|
21290
21290
|
try {
|
|
@@ -21299,7 +21299,7 @@ async function getLogsByView(startDate, endDate, viewParams = {}) {
|
|
|
21299
21299
|
if (viewParams == null ? void 0 : viewParams.page) {
|
|
21300
21300
|
params2.startkey = viewParams.page;
|
|
21301
21301
|
}
|
|
21302
|
-
response = await
|
|
21302
|
+
response = await db2.query(getQueryIndex3(ViewName6.AUTOMATION_LOGS), params2);
|
|
21303
21303
|
} catch (err) {
|
|
21304
21304
|
if (err != null && (err.name === "not_found" || err.error === "not_found")) {
|
|
21305
21305
|
await createLogByAutomationView();
|
|
@@ -21311,9 +21311,9 @@ async function getLogsByView(startDate, endDate, viewParams = {}) {
|
|
|
21311
21311
|
return pagination2(response);
|
|
21312
21312
|
}
|
|
21313
21313
|
async function writeLog(automation, results) {
|
|
21314
|
-
const
|
|
21314
|
+
const db2 = context_exports.getProdAppDB();
|
|
21315
21315
|
const automationId = automation._id;
|
|
21316
|
-
const
|
|
21316
|
+
const name2 = automation.name;
|
|
21317
21317
|
const status2 = getStatus(results);
|
|
21318
21318
|
const isoDate = (/* @__PURE__ */ new Date()).toISOString();
|
|
21319
21319
|
const id = generateAutomationLogID(isoDate, status2, automationId);
|
|
@@ -21322,23 +21322,23 @@ async function writeLog(automation, results) {
|
|
|
21322
21322
|
...results,
|
|
21323
21323
|
automationId,
|
|
21324
21324
|
status: status2,
|
|
21325
|
-
automationName:
|
|
21325
|
+
automationName: name2,
|
|
21326
21326
|
createdAt: isoDate,
|
|
21327
21327
|
_id: id
|
|
21328
21328
|
};
|
|
21329
|
-
await
|
|
21329
|
+
await db2.put(log);
|
|
21330
21330
|
return id;
|
|
21331
21331
|
}
|
|
21332
21332
|
async function updateAppMetadataWithErrors(logIds, { clearing } = { clearing: false }) {
|
|
21333
|
-
const
|
|
21333
|
+
const db2 = context_exports.getProdAppDB();
|
|
21334
21334
|
await backOff(async () => {
|
|
21335
|
-
const
|
|
21335
|
+
const metadata2 = await db2.get(db_exports.DocumentType.APP_METADATA);
|
|
21336
21336
|
for (let logId of logIds) {
|
|
21337
21337
|
const parts = logId.split(db_exports.SEPARATOR);
|
|
21338
21338
|
const autoId = `${parts[parts.length - 3]}${db_exports.SEPARATOR}${parts[parts.length - 2]}`;
|
|
21339
21339
|
let errors = {};
|
|
21340
|
-
if (
|
|
21341
|
-
errors =
|
|
21340
|
+
if (metadata2.automationErrors) {
|
|
21341
|
+
errors = metadata2.automationErrors;
|
|
21342
21342
|
}
|
|
21343
21343
|
if (!Array.isArray(errors[autoId])) {
|
|
21344
21344
|
errors[autoId] = [];
|
|
@@ -21352,10 +21352,10 @@ async function updateAppMetadataWithErrors(logIds, { clearing } = { clearing: fa
|
|
|
21352
21352
|
if (errors[autoId].length === 0) {
|
|
21353
21353
|
delete errors[autoId];
|
|
21354
21354
|
}
|
|
21355
|
-
|
|
21355
|
+
metadata2.automationErrors = errors;
|
|
21356
21356
|
}
|
|
21357
|
-
await
|
|
21358
|
-
await cache_exports.app.invalidateAppMetadata(
|
|
21357
|
+
await db2.put(metadata2);
|
|
21358
|
+
await cache_exports.app.invalidateAppMetadata(metadata2.appId, metadata2);
|
|
21359
21359
|
}, "Failed to update app metadata with automation log error");
|
|
21360
21360
|
}
|
|
21361
21361
|
async function getExpiredLogs() {
|
|
@@ -21371,29 +21371,29 @@ async function getExpiredLogs() {
|
|
|
21371
21371
|
}
|
|
21372
21372
|
}
|
|
21373
21373
|
async function clearOldHistory() {
|
|
21374
|
-
const
|
|
21374
|
+
const db2 = context_exports.getProdAppDB();
|
|
21375
21375
|
try {
|
|
21376
21376
|
const expired = await getExpiredLogs();
|
|
21377
21377
|
if (!expired.data || expired.data.length === 0) {
|
|
21378
21378
|
return;
|
|
21379
21379
|
}
|
|
21380
|
-
const toDelete = expired.data.map((
|
|
21381
|
-
_id:
|
|
21382
|
-
_rev:
|
|
21380
|
+
const toDelete = expired.data.map((doc2) => ({
|
|
21381
|
+
_id: doc2.id,
|
|
21382
|
+
_rev: doc2.value.rev,
|
|
21383
21383
|
_deleted: true
|
|
21384
21384
|
}));
|
|
21385
|
-
const errorLogIds = expired.data.filter((
|
|
21386
|
-
const parts =
|
|
21385
|
+
const errorLogIds = expired.data.filter((doc2) => {
|
|
21386
|
+
const parts = doc2.id.split(db_exports.SEPARATOR);
|
|
21387
21387
|
const status2 = parts[parts.length - 1];
|
|
21388
21388
|
return status2 === "error" /* ERROR */;
|
|
21389
|
-
}).map((
|
|
21390
|
-
await
|
|
21389
|
+
}).map((doc2) => doc2.id);
|
|
21390
|
+
await db2.bulkDocs(toDelete);
|
|
21391
21391
|
if (errorLogIds.length) {
|
|
21392
21392
|
await updateAppMetadataWithErrors(errorLogIds, { clearing: true });
|
|
21393
21393
|
}
|
|
21394
21394
|
} catch (err) {
|
|
21395
21395
|
logging_exports.logAlert(
|
|
21396
|
-
`Failed to cleanup automation log history - Database "${
|
|
21396
|
+
`Failed to cleanup automation log history - Database "${db2.name}"`,
|
|
21397
21397
|
err
|
|
21398
21398
|
);
|
|
21399
21399
|
}
|
|
@@ -21566,10 +21566,10 @@ async function get7(id) {
|
|
|
21566
21566
|
async function getBulk2(ids, opts = { enriched: true }) {
|
|
21567
21567
|
return await groups_exports.getBulk(ids, opts);
|
|
21568
21568
|
}
|
|
21569
|
-
async function guardNameAvailility(
|
|
21570
|
-
const existingGroup = await groups_exports.getByName(
|
|
21569
|
+
async function guardNameAvailility(name2) {
|
|
21570
|
+
const existingGroup = await groups_exports.getByName(name2);
|
|
21571
21571
|
if (existingGroup) {
|
|
21572
|
-
throw new GroupNameUnavailableError(
|
|
21572
|
+
throw new GroupNameUnavailableError(name2);
|
|
21573
21573
|
}
|
|
21574
21574
|
}
|
|
21575
21575
|
async function save4(group) {
|
|
@@ -21710,14 +21710,14 @@ init_src();
|
|
|
21710
21710
|
// ../pro/packages/pro/src/utilities/fileSystem.ts
|
|
21711
21711
|
var import_fs11 = __toESM(require("fs"));
|
|
21712
21712
|
var import_path12 = require("path");
|
|
21713
|
-
function loadJSFile(
|
|
21714
|
-
return import_fs11.default.readFileSync((0, import_path12.join)(
|
|
21713
|
+
function loadJSFile(directory2, name2) {
|
|
21714
|
+
return import_fs11.default.readFileSync((0, import_path12.join)(directory2, name2), "utf8");
|
|
21715
21715
|
}
|
|
21716
21716
|
|
|
21717
21717
|
// ../pro/packages/pro/src/sdk/plugins/index.ts
|
|
21718
21718
|
async function storePlugin(metadata, directory, source) {
|
|
21719
21719
|
const db = tenancy.getGlobalDB();
|
|
21720
|
-
const version = metadata.package.version, name = metadata.package.name, description = metadata.package.description,
|
|
21720
|
+
const version = metadata.package.version, name = metadata.package.name, description = metadata.package.description, hash = metadata.schema.hash;
|
|
21721
21721
|
const bucketPath = objectStore_exports2.getPluginS3Dir(name);
|
|
21722
21722
|
const files = await objectStore_exports2.uploadDirectory(
|
|
21723
21723
|
objectStore_exports2.ObjectStoreBuckets.PLUGINS,
|
|
@@ -21732,8 +21732,7 @@ async function storePlugin(metadata, directory, source) {
|
|
|
21732
21732
|
if (metadata.schema.type === "datasource" /* DATASOURCE */) {
|
|
21733
21733
|
const js = loadJSFile(directory, jsFile.name);
|
|
21734
21734
|
try {
|
|
21735
|
-
;
|
|
21736
|
-
(0, eval)(js);
|
|
21735
|
+
eval(js);
|
|
21737
21736
|
} catch (err) {
|
|
21738
21737
|
const message = (err == null ? void 0 : err.message) ? err.message : JSON.stringify(err);
|
|
21739
21738
|
throw new Error(`JS invalid: ${message}`);
|
|
@@ -21754,7 +21753,7 @@ async function storePlugin(metadata, directory, source) {
|
|
|
21754
21753
|
...metadata,
|
|
21755
21754
|
name,
|
|
21756
21755
|
version,
|
|
21757
|
-
hash
|
|
21756
|
+
hash,
|
|
21758
21757
|
description
|
|
21759
21758
|
};
|
|
21760
21759
|
if (iconFileName) {
|
|
@@ -21766,7 +21765,7 @@ async function storePlugin(metadata, directory, source) {
|
|
|
21766
21765
|
source
|
|
21767
21766
|
};
|
|
21768
21767
|
}
|
|
21769
|
-
const
|
|
21768
|
+
const write = async () => {
|
|
21770
21769
|
const response = await db.put(doc);
|
|
21771
21770
|
await events_exports.plugin.imported(doc);
|
|
21772
21771
|
return {
|
|
@@ -21775,21 +21774,21 @@ async function storePlugin(metadata, directory, source) {
|
|
|
21775
21774
|
};
|
|
21776
21775
|
};
|
|
21777
21776
|
if (!rev) {
|
|
21778
|
-
return await addPlugin(
|
|
21777
|
+
return await addPlugin(write);
|
|
21779
21778
|
} else {
|
|
21780
|
-
return await
|
|
21779
|
+
return await write();
|
|
21781
21780
|
}
|
|
21782
21781
|
}
|
|
21783
|
-
async function deletePlugin(
|
|
21784
|
-
const
|
|
21782
|
+
async function deletePlugin(pluginId2) {
|
|
21783
|
+
const db2 = tenancy.getGlobalDB();
|
|
21785
21784
|
try {
|
|
21786
|
-
const plugin = await
|
|
21787
|
-
const
|
|
21785
|
+
const plugin = await db2.get(pluginId2);
|
|
21786
|
+
const bucketPath2 = objectStore_exports2.getPluginS3Dir(plugin.name);
|
|
21788
21787
|
await objectStore_exports2.deleteFolder(
|
|
21789
21788
|
objectStore_exports2.ObjectStoreBuckets.PLUGINS,
|
|
21790
|
-
|
|
21789
|
+
bucketPath2
|
|
21791
21790
|
);
|
|
21792
|
-
await
|
|
21791
|
+
await db2.remove(pluginId2, plugin._rev);
|
|
21793
21792
|
await events_exports.plugin.deleted(plugin);
|
|
21794
21793
|
await removePlugin();
|
|
21795
21794
|
} catch (err) {
|
|
@@ -21798,9 +21797,9 @@ async function deletePlugin(pluginId) {
|
|
|
21798
21797
|
}
|
|
21799
21798
|
}
|
|
21800
21799
|
async function checkPluginQuotas() {
|
|
21801
|
-
const
|
|
21800
|
+
const db2 = tenancy.getGlobalDB();
|
|
21802
21801
|
try {
|
|
21803
|
-
const allPlugins = await
|
|
21802
|
+
const allPlugins = await db2.allDocs(db_exports.getPluginParams());
|
|
21804
21803
|
const pluginCount = allPlugins.rows.length;
|
|
21805
21804
|
console.log(`Syncing plugin count: ${pluginCount}`);
|
|
21806
21805
|
await updatePluginCount(pluginCount);
|
|
@@ -21826,12 +21825,12 @@ function isEncryptionKeyAvailable() {
|
|
|
21826
21825
|
return !!environment_default2.ENCRYPTION_KEY;
|
|
21827
21826
|
}
|
|
21828
21827
|
async function fetch13() {
|
|
21829
|
-
const
|
|
21830
|
-
return Object.keys(
|
|
21828
|
+
const doc2 = await environmentVariables_exports.get();
|
|
21829
|
+
return Object.keys(doc2.variables);
|
|
21831
21830
|
}
|
|
21832
21831
|
async function fetchValues(environment3) {
|
|
21833
|
-
const
|
|
21834
|
-
const decrypted =
|
|
21832
|
+
const doc2 = await environmentVariables_exports.get();
|
|
21833
|
+
const decrypted = doc2.variables;
|
|
21835
21834
|
const output = {};
|
|
21836
21835
|
for (let [key, value] of Object.entries(decrypted)) {
|
|
21837
21836
|
switch (environment3) {
|
|
@@ -21853,9 +21852,9 @@ async function changeValues(cb) {
|
|
|
21853
21852
|
"User does not have access to environment variables feature."
|
|
21854
21853
|
);
|
|
21855
21854
|
}
|
|
21856
|
-
const
|
|
21857
|
-
|
|
21858
|
-
await environmentVariables_exports.update(
|
|
21855
|
+
const doc2 = await environmentVariables_exports.get();
|
|
21856
|
+
doc2.variables = cb(doc2.variables);
|
|
21857
|
+
await environmentVariables_exports.update(doc2);
|
|
21859
21858
|
}
|
|
21860
21859
|
async function update2(varName, value) {
|
|
21861
21860
|
const checkName = isValid(varName);
|
|
@@ -21884,7 +21883,7 @@ __export(auditLogs_exports2, {
|
|
|
21884
21883
|
definitions: () => definitions,
|
|
21885
21884
|
download: () => download,
|
|
21886
21885
|
fetch: () => fetch14,
|
|
21887
|
-
write: () =>
|
|
21886
|
+
write: () => write2
|
|
21888
21887
|
});
|
|
21889
21888
|
|
|
21890
21889
|
// ../pro/packages/pro/src/sdk/auditLogs/auditLogs.ts
|
|
@@ -21896,15 +21895,15 @@ var MemoryStream2 = require("memorystream");
|
|
|
21896
21895
|
function generateAuditLogID(timestamp) {
|
|
21897
21896
|
return `${"al" /* AUDIT_LOG */}${SEPARATOR}${timestamp}${SEPARATOR}${utils_exports2.newid()}`;
|
|
21898
21897
|
}
|
|
21899
|
-
async function save5(
|
|
21900
|
-
if (!
|
|
21901
|
-
|
|
21898
|
+
async function save5(doc2) {
|
|
21899
|
+
if (!doc2._id) {
|
|
21900
|
+
doc2._id = generateAuditLogID(doc2.timestamp);
|
|
21902
21901
|
}
|
|
21903
21902
|
try {
|
|
21904
|
-
const
|
|
21905
|
-
const response = await
|
|
21903
|
+
const db2 = context_exports.getAuditLogsDB();
|
|
21904
|
+
const response = await db2.put(doc2);
|
|
21906
21905
|
return {
|
|
21907
|
-
...
|
|
21906
|
+
...doc2,
|
|
21908
21907
|
_rev: response.rev
|
|
21909
21908
|
};
|
|
21910
21909
|
} catch (err) {
|
|
@@ -21929,12 +21928,12 @@ async function search(search3, bookmark) {
|
|
|
21929
21928
|
);
|
|
21930
21929
|
}
|
|
21931
21930
|
function dump(params2) {
|
|
21932
|
-
const
|
|
21931
|
+
const db2 = context_exports.getAuditLogsDB();
|
|
21933
21932
|
const stream3 = new MemoryStream2();
|
|
21934
|
-
const promise =
|
|
21935
|
-
filter: (
|
|
21933
|
+
const promise = db2.dump(stream3, {
|
|
21934
|
+
filter: (doc2) => {
|
|
21936
21935
|
var _a;
|
|
21937
|
-
const auditLog =
|
|
21936
|
+
const auditLog = doc2;
|
|
21938
21937
|
if (!((_a = auditLog._id) == null ? void 0 : _a.startsWith("al" /* AUDIT_LOG */))) {
|
|
21939
21938
|
return false;
|
|
21940
21939
|
}
|
|
@@ -21952,7 +21951,7 @@ function dump(params2) {
|
|
|
21952
21951
|
allMatched = allMatched && auditLog.timestamp >= params2.startDate && auditLog.timestamp <= params2.endDate;
|
|
21953
21952
|
}
|
|
21954
21953
|
if (params2.fullSearch) {
|
|
21955
|
-
const json = JSON.stringify(
|
|
21954
|
+
const json = JSON.stringify(doc2);
|
|
21956
21955
|
allMatched = allMatched && json.includes(params2.fullSearch);
|
|
21957
21956
|
}
|
|
21958
21957
|
return allMatched;
|
|
@@ -21963,8 +21962,8 @@ function dump(params2) {
|
|
|
21963
21962
|
const json = JSON.parse(Buffer.from(data).toString());
|
|
21964
21963
|
if (Array.isArray(json.docs)) {
|
|
21965
21964
|
let str = "";
|
|
21966
|
-
for (let
|
|
21967
|
-
str += JSON.stringify(
|
|
21965
|
+
for (let doc2 of json.docs) {
|
|
21966
|
+
str += JSON.stringify(doc2) + "\n";
|
|
21968
21967
|
}
|
|
21969
21968
|
returnStream.write(str);
|
|
21970
21969
|
}
|
|
@@ -22070,12 +22069,12 @@ async function auditLogsEnabled() {
|
|
|
22070
22069
|
const license = await licensing_exports.cache.getCachedLicense();
|
|
22071
22070
|
return license.features.includes("auditLogs" /* AUDIT_LOGS */);
|
|
22072
22071
|
}
|
|
22073
|
-
function getEventFriendlyName(event,
|
|
22072
|
+
function getEventFriendlyName(event, metadata2) {
|
|
22074
22073
|
const friendly = AuditedEventFriendlyName[event];
|
|
22075
22074
|
if (!friendly) {
|
|
22076
22075
|
throw new Error("No friendly name found.");
|
|
22077
22076
|
}
|
|
22078
|
-
let processed = processStringSync(friendly,
|
|
22077
|
+
let processed = processStringSync(friendly, metadata2);
|
|
22079
22078
|
if (processed.includes(`""`)) {
|
|
22080
22079
|
processed = removeTemplateStrings(friendly);
|
|
22081
22080
|
}
|
|
@@ -22083,29 +22082,29 @@ function getEventFriendlyName(event, metadata) {
|
|
|
22083
22082
|
}
|
|
22084
22083
|
|
|
22085
22084
|
// ../pro/packages/pro/src/sdk/auditLogs/auditLogs.ts
|
|
22086
|
-
async function
|
|
22085
|
+
async function write2(event, metadata2, opts) {
|
|
22087
22086
|
if (!await auditLogsEnabled() || !utils_exports2.isAudited(event)) {
|
|
22088
22087
|
return;
|
|
22089
22088
|
}
|
|
22090
|
-
const friendly = getEventFriendlyName(event,
|
|
22089
|
+
const friendly = getEventFriendlyName(event, metadata2);
|
|
22091
22090
|
let date = /* @__PURE__ */ new Date();
|
|
22092
22091
|
if (opts == null ? void 0 : opts.timestamp) {
|
|
22093
22092
|
date = new Date(opts.timestamp);
|
|
22094
22093
|
}
|
|
22095
|
-
const
|
|
22094
|
+
const doc2 = {
|
|
22096
22095
|
timestamp: date.toISOString(),
|
|
22097
22096
|
event,
|
|
22098
22097
|
name: friendly,
|
|
22099
22098
|
userId: (opts == null ? void 0 : opts.userId) || AuditLogSystemUser,
|
|
22100
22099
|
metadata: {
|
|
22101
|
-
...
|
|
22100
|
+
...metadata2,
|
|
22102
22101
|
...opts == null ? void 0 : opts.hostInfo
|
|
22103
22102
|
}
|
|
22104
22103
|
};
|
|
22105
22104
|
const fallback = {};
|
|
22106
22105
|
try {
|
|
22107
22106
|
if (opts == null ? void 0 : opts.appId) {
|
|
22108
|
-
|
|
22107
|
+
doc2.appId = db_exports.getProdAppID(opts.appId);
|
|
22109
22108
|
const appMetadata = await cache_exports.app.getAppMetadata(opts.appId);
|
|
22110
22109
|
fallback.appName = appMetadata.name;
|
|
22111
22110
|
}
|
|
@@ -22119,8 +22118,8 @@ async function write(event, metadata, opts) {
|
|
|
22119
22118
|
err
|
|
22120
22119
|
);
|
|
22121
22120
|
}
|
|
22122
|
-
|
|
22123
|
-
return await save5(
|
|
22121
|
+
doc2.fallback = fallback;
|
|
22122
|
+
return await save5(doc2);
|
|
22124
22123
|
}
|
|
22125
22124
|
async function enrich(logs) {
|
|
22126
22125
|
const allUserIds = logs.map((log) => log.userId);
|
|
@@ -22191,8 +22190,8 @@ function getBackupQueue() {
|
|
|
22191
22190
|
}
|
|
22192
22191
|
|
|
22193
22192
|
// ../pro/packages/pro/src/sdk/backups/backup.ts
|
|
22194
|
-
async function storeAppBackupMetadata2(
|
|
22195
|
-
return backups_exports.storeAppBackupMetadata(
|
|
22193
|
+
async function storeAppBackupMetadata2(metadata2, opts = {}) {
|
|
22194
|
+
return backups_exports.storeAppBackupMetadata(metadata2, opts);
|
|
22196
22195
|
}
|
|
22197
22196
|
function getTimestamps(status2) {
|
|
22198
22197
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -22206,7 +22205,7 @@ function getTimestamps(status2) {
|
|
|
22206
22205
|
return { timestamp, createdAt: timestamp };
|
|
22207
22206
|
}
|
|
22208
22207
|
}
|
|
22209
|
-
async function updateBackupStatus(id,
|
|
22208
|
+
async function updateBackupStatus(id, rev2, status2, contents, filename) {
|
|
22210
22209
|
const backup = await getAppBackup(id);
|
|
22211
22210
|
return await backups_exports.storeAppBackupMetadata(
|
|
22212
22211
|
{
|
|
@@ -22216,10 +22215,10 @@ async function updateBackupStatus(id, rev, status2, contents, filename) {
|
|
|
22216
22215
|
status: status2,
|
|
22217
22216
|
type: "backup" /* BACKUP */
|
|
22218
22217
|
},
|
|
22219
|
-
{ filename, docId: id, docRev:
|
|
22218
|
+
{ filename, docId: id, docRev: rev2 }
|
|
22220
22219
|
);
|
|
22221
22220
|
}
|
|
22222
|
-
async function updateRestoreStatus(id,
|
|
22221
|
+
async function updateRestoreStatus(id, rev2, status2) {
|
|
22223
22222
|
const restore = await getAppBackup(id);
|
|
22224
22223
|
return await backups_exports.storeAppBackupMetadata(
|
|
22225
22224
|
{
|
|
@@ -22229,7 +22228,7 @@ async function updateRestoreStatus(id, rev, status2) {
|
|
|
22229
22228
|
type: "restore" /* RESTORE */,
|
|
22230
22229
|
trigger: "manual" /* MANUAL */
|
|
22231
22230
|
},
|
|
22232
|
-
{ docId: id, docRev:
|
|
22231
|
+
{ docId: id, docRev: rev2 }
|
|
22233
22232
|
);
|
|
22234
22233
|
}
|
|
22235
22234
|
async function getAppBackup(backupId) {
|
|
@@ -22239,11 +22238,11 @@ async function updateAppBackup(backupId, backupName) {
|
|
|
22239
22238
|
return backups_exports.updateAppBackupMetadata(backupId, backupName);
|
|
22240
22239
|
}
|
|
22241
22240
|
async function deleteAppBackup(backupId) {
|
|
22242
|
-
const
|
|
22243
|
-
if (
|
|
22241
|
+
const metadata2 = await backups_exports.getAppBackupMetadata(backupId);
|
|
22242
|
+
if (metadata2.filename) {
|
|
22244
22243
|
await objectStore_exports2.deleteFile(
|
|
22245
22244
|
objectStore_exports2.ObjectStoreBuckets.BACKUPS,
|
|
22246
|
-
|
|
22245
|
+
metadata2.filename
|
|
22247
22246
|
);
|
|
22248
22247
|
}
|
|
22249
22248
|
return backups_exports.deleteAppBackupMetadata(backupId);
|
|
@@ -22252,15 +22251,15 @@ async function fetchAppBackups2(appId, opts) {
|
|
|
22252
22251
|
return backups_exports.fetchAppBackups(appId, opts);
|
|
22253
22252
|
}
|
|
22254
22253
|
async function downloadAppBackup(backupId) {
|
|
22255
|
-
const
|
|
22256
|
-
if (!
|
|
22254
|
+
const metadata2 = await backups_exports.getAppBackupMetadata(backupId);
|
|
22255
|
+
if (!metadata2.filename) {
|
|
22257
22256
|
throw new Error("Backup incomplete - cannot download.");
|
|
22258
22257
|
}
|
|
22259
22258
|
const path2 = await objectStore_exports2.retrieveToTmp(
|
|
22260
22259
|
objectStore_exports2.ObjectStoreBuckets.BACKUPS,
|
|
22261
|
-
|
|
22260
|
+
metadata2.filename
|
|
22262
22261
|
);
|
|
22263
|
-
return { metadata, path: path2 };
|
|
22262
|
+
return { metadata: metadata2, path: path2 };
|
|
22264
22263
|
}
|
|
22265
22264
|
async function triggerAppBackup(appId, trigger, opts = {}) {
|
|
22266
22265
|
let backup;
|
|
@@ -22299,7 +22298,7 @@ async function triggerAppBackup(appId, trigger, opts = {}) {
|
|
|
22299
22298
|
return backup.id;
|
|
22300
22299
|
}
|
|
22301
22300
|
async function triggerAppRestore(appId, backupId, nameForBackup, createdBy) {
|
|
22302
|
-
const
|
|
22301
|
+
const metadata2 = await getAppBackup(backupId);
|
|
22303
22302
|
let restore;
|
|
22304
22303
|
try {
|
|
22305
22304
|
restore = await storeAppBackupMetadata2({
|
|
@@ -22326,7 +22325,7 @@ async function triggerAppRestore(appId, backupId, nameForBackup, createdBy) {
|
|
|
22326
22325
|
createdBy
|
|
22327
22326
|
}
|
|
22328
22327
|
});
|
|
22329
|
-
return { restoreId: restore.id, metadata };
|
|
22328
|
+
return { restoreId: restore.id, metadata: metadata2 };
|
|
22330
22329
|
}
|
|
22331
22330
|
var pkg = {
|
|
22332
22331
|
isEnabled: isBackupsEnabled,
|
|
@@ -22431,7 +22430,7 @@ async function importProcessor(job, opts) {
|
|
|
22431
22430
|
const tenantId = tenancy.getTenantIDFromAppID(appId);
|
|
22432
22431
|
return tenancy.doInTenant(tenantId, async () => {
|
|
22433
22432
|
const devAppId = db_exports.getDevAppID(appId);
|
|
22434
|
-
const { rev } = await backup_default2.updateRestoreStatus(
|
|
22433
|
+
const { rev: rev2 } = await backup_default2.updateRestoreStatus(
|
|
22435
22434
|
data.docId,
|
|
22436
22435
|
data.docRev,
|
|
22437
22436
|
"started" /* STARTED */
|
|
@@ -22456,23 +22455,23 @@ async function importProcessor(job, opts) {
|
|
|
22456
22455
|
logging_exports.logAlert("App restore error", err);
|
|
22457
22456
|
status2 = "failed" /* FAILED */;
|
|
22458
22457
|
}
|
|
22459
|
-
await backup_default2.updateRestoreStatus(data.docId,
|
|
22458
|
+
await backup_default2.updateRestoreStatus(data.docId, rev2, status2);
|
|
22460
22459
|
});
|
|
22461
22460
|
}
|
|
22462
22461
|
async function exportProcessor(job, opts) {
|
|
22463
22462
|
const data = job.data;
|
|
22464
|
-
const appId = data.appId, trigger = data.export.trigger,
|
|
22463
|
+
const appId = data.appId, trigger = data.export.trigger, name2 = data.export.name;
|
|
22465
22464
|
const tenantId = tenancy.getTenantIDFromAppID(appId);
|
|
22466
22465
|
await tenancy.doInTenant(tenantId, async () => {
|
|
22467
|
-
const { rev } = await backup_default2.updateBackupStatus(
|
|
22466
|
+
const { rev: rev2 } = await backup_default2.updateBackupStatus(
|
|
22468
22467
|
data.docId,
|
|
22469
22468
|
data.docRev,
|
|
22470
22469
|
"started" /* STARTED */
|
|
22471
22470
|
);
|
|
22472
22471
|
return runBackup(trigger, tenantId, appId, {
|
|
22473
22472
|
processing: opts,
|
|
22474
|
-
doc: { id: data.docId, rev },
|
|
22475
|
-
name
|
|
22473
|
+
doc: { id: data.docId, rev: rev2 },
|
|
22474
|
+
name: name2
|
|
22476
22475
|
});
|
|
22477
22476
|
});
|
|
22478
22477
|
}
|
|
@@ -22519,8 +22518,8 @@ var ScimUserService = class {
|
|
|
22519
22518
|
constructor(config) {
|
|
22520
22519
|
this.get = async (params2) => {
|
|
22521
22520
|
var _a;
|
|
22522
|
-
const
|
|
22523
|
-
const builder2 = new db_exports.QueryBuilder(
|
|
22521
|
+
const db2 = tenancy.getGlobalDB();
|
|
22522
|
+
const builder2 = new db_exports.QueryBuilder(db2.name, "user" /* USER */);
|
|
22524
22523
|
builder2.setIndexBuilder(db_exports.searchIndexes.createUserIndex);
|
|
22525
22524
|
builder2.setLimit(params2.pageSize);
|
|
22526
22525
|
builder2.addEqual("scimInfo.isSync", true);
|
|
@@ -22656,9 +22655,9 @@ var fetch15 = async (ctx) => {
|
|
|
22656
22655
|
ctx.body = { data: await fetch12() };
|
|
22657
22656
|
};
|
|
22658
22657
|
var destroy4 = async (ctx) => {
|
|
22659
|
-
const { id, rev } = ctx.params;
|
|
22658
|
+
const { id, rev: rev2 } = ctx.params;
|
|
22660
22659
|
try {
|
|
22661
|
-
await remove2(id,
|
|
22660
|
+
await remove2(id, rev2);
|
|
22662
22661
|
ctx.body = { message: "Group deleted successfully" };
|
|
22663
22662
|
} catch (err) {
|
|
22664
22663
|
ctx.throw(err.status, err);
|
|
@@ -22703,13 +22702,13 @@ async function fetch16(ctx) {
|
|
|
22703
22702
|
};
|
|
22704
22703
|
}
|
|
22705
22704
|
async function create3(ctx) {
|
|
22706
|
-
const { name, production, development } = ctx.request.body;
|
|
22707
|
-
await environmentVariables_exports2.update(
|
|
22705
|
+
const { name: name2, production, development } = ctx.request.body;
|
|
22706
|
+
await environmentVariables_exports2.update(name2, { production, development });
|
|
22708
22707
|
const environments = ["production" /* PRODUCTION */];
|
|
22709
22708
|
if (production !== development) {
|
|
22710
22709
|
environments.push("development" /* DEVELOPMENT */);
|
|
22711
22710
|
}
|
|
22712
|
-
await events_exports.environmentVariable.created(
|
|
22711
|
+
await events_exports.environmentVariable.created(name2, environments);
|
|
22713
22712
|
ctx.status = 200;
|
|
22714
22713
|
}
|
|
22715
22714
|
async function update4(ctx) {
|
|
@@ -22955,8 +22954,8 @@ async function downloadBackup(ctx) {
|
|
|
22955
22954
|
const appId = ctx.params.appId;
|
|
22956
22955
|
await checkAppID(ctx, appId);
|
|
22957
22956
|
const backupId = ctx.params.backupId;
|
|
22958
|
-
const { metadata, path: path2 } = await backups_default2.downloadAppBackup(backupId);
|
|
22959
|
-
ctx.attachment(`backup-${
|
|
22957
|
+
const { metadata: metadata2, path: path2 } = await backups_default2.downloadAppBackup(backupId);
|
|
22958
|
+
ctx.attachment(`backup-${metadata2.timestamp}.tar.gz`);
|
|
22960
22959
|
ctx.body = import_fs13.default.createReadStream(path2);
|
|
22961
22960
|
}
|
|
22962
22961
|
|
|
@@ -23072,8 +23071,8 @@ var import_router6 = __toESM(require("@koa/router"));
|
|
|
23072
23071
|
|
|
23073
23072
|
// ../pro/packages/pro/src/api/controllers/global/scim/users.ts
|
|
23074
23073
|
var import_scim_patch = require("scim-patch");
|
|
23075
|
-
function tryGetQueryAsNumber(ctx,
|
|
23076
|
-
const value = ctx.request.query[
|
|
23074
|
+
function tryGetQueryAsNumber(ctx, name2) {
|
|
23075
|
+
const value = ctx.request.query[name2];
|
|
23077
23076
|
if (value === void 0) {
|
|
23078
23077
|
return void 0;
|
|
23079
23078
|
}
|
|
@@ -23619,11 +23618,11 @@ var datasources_default = {
|
|
|
23619
23618
|
};
|
|
23620
23619
|
|
|
23621
23620
|
// src/sdk/app/tables/index.ts
|
|
23622
|
-
async function getAllInternalTables(
|
|
23623
|
-
if (!
|
|
23624
|
-
|
|
23621
|
+
async function getAllInternalTables(db2) {
|
|
23622
|
+
if (!db2) {
|
|
23623
|
+
db2 = context_exports.getAppDB();
|
|
23625
23624
|
}
|
|
23626
|
-
const internalTables = await
|
|
23625
|
+
const internalTables = await db2.allDocs(
|
|
23627
23626
|
getTableParams(null, {
|
|
23628
23627
|
include_docs: true
|
|
23629
23628
|
})
|
|
@@ -23635,7 +23634,7 @@ async function getAllInternalTables(db) {
|
|
|
23635
23634
|
}));
|
|
23636
23635
|
}
|
|
23637
23636
|
async function getAllExternalTables(datasourceId) {
|
|
23638
|
-
const
|
|
23637
|
+
const db2 = context_exports.getAppDB();
|
|
23639
23638
|
const datasource2 = await datasources_default.get(datasourceId, { enriched: true });
|
|
23640
23639
|
if (!datasource2 || !datasource2.entities) {
|
|
23641
23640
|
throw "Datasource is not configured fully.";
|
|
@@ -23647,14 +23646,14 @@ async function getExternalTable(datasourceId, tableName) {
|
|
|
23647
23646
|
return entities[tableName];
|
|
23648
23647
|
}
|
|
23649
23648
|
async function getTable(tableId) {
|
|
23650
|
-
const
|
|
23649
|
+
const db2 = context_exports.getAppDB();
|
|
23651
23650
|
if (isExternalTable(tableId)) {
|
|
23652
23651
|
let { datasourceId, tableName } = breakExternalTableId(tableId);
|
|
23653
23652
|
const datasource2 = await datasources_default.get(datasourceId);
|
|
23654
23653
|
const table = await getExternalTable(datasourceId, tableName);
|
|
23655
23654
|
return { ...table, sql: isSQL(datasource2) };
|
|
23656
23655
|
} else {
|
|
23657
|
-
return
|
|
23656
|
+
return db2.get(tableId);
|
|
23658
23657
|
}
|
|
23659
23658
|
}
|
|
23660
23659
|
var tables_default = {
|
|
@@ -23674,10 +23673,10 @@ __export(webhook_exports, {
|
|
|
23674
23673
|
function isWebhookID(id) {
|
|
23675
23674
|
return id.startsWith(db_exports.DocumentType.WEBHOOK);
|
|
23676
23675
|
}
|
|
23677
|
-
function newDoc(
|
|
23676
|
+
function newDoc(name2, type, target) {
|
|
23678
23677
|
return {
|
|
23679
23678
|
live: true,
|
|
23680
|
-
name,
|
|
23679
|
+
name: name2,
|
|
23681
23680
|
action: {
|
|
23682
23681
|
type,
|
|
23683
23682
|
target
|
|
@@ -23685,22 +23684,22 @@ function newDoc(name, type, target) {
|
|
|
23685
23684
|
};
|
|
23686
23685
|
}
|
|
23687
23686
|
async function save7(webhook) {
|
|
23688
|
-
const
|
|
23687
|
+
const db2 = context_exports.getAppDB();
|
|
23689
23688
|
if (webhook._id && isWebhookID(webhook._id)) {
|
|
23690
|
-
await
|
|
23689
|
+
await db2.get(webhook._id);
|
|
23691
23690
|
} else {
|
|
23692
23691
|
webhook._id = generateWebhookID();
|
|
23693
23692
|
}
|
|
23694
|
-
const response = await
|
|
23693
|
+
const response = await db2.put(webhook);
|
|
23695
23694
|
webhook._rev = response.rev;
|
|
23696
23695
|
return webhook;
|
|
23697
23696
|
}
|
|
23698
|
-
async function destroy6(id,
|
|
23699
|
-
const
|
|
23697
|
+
async function destroy6(id, rev2) {
|
|
23698
|
+
const db2 = context_exports.getAppDB();
|
|
23700
23699
|
if (!id || !isWebhookID(id)) {
|
|
23701
23700
|
throw new Error("Provided webhook ID is not valid.");
|
|
23702
23701
|
}
|
|
23703
|
-
return await
|
|
23702
|
+
return await db2.remove(id, rev2);
|
|
23704
23703
|
}
|
|
23705
23704
|
|
|
23706
23705
|
// src/sdk/app/automations/utils.ts
|
|
@@ -23780,14 +23779,14 @@ async function processUser(user, opts = {}) {
|
|
|
23780
23779
|
}
|
|
23781
23780
|
async function getGlobalUsers(userIds, opts) {
|
|
23782
23781
|
const appId = context_exports.getAppId();
|
|
23783
|
-
const
|
|
23782
|
+
const db2 = tenancy.getGlobalDB();
|
|
23784
23783
|
let globalUsers;
|
|
23785
23784
|
if (userIds) {
|
|
23786
|
-
globalUsers = (await
|
|
23785
|
+
globalUsers = (await db2.allDocs(getMultiIDParams(userIds))).rows.map(
|
|
23787
23786
|
(row) => row.doc
|
|
23788
23787
|
);
|
|
23789
23788
|
} else {
|
|
23790
|
-
globalUsers = (await
|
|
23789
|
+
globalUsers = (await db2.allDocs(
|
|
23791
23790
|
db_exports.getGlobalUserParams(null, {
|
|
23792
23791
|
include_docs: true
|
|
23793
23792
|
})
|
|
@@ -23814,7 +23813,7 @@ async function syncUsersToApp(appId, users2, groups) {
|
|
|
23814
23813
|
return;
|
|
23815
23814
|
}
|
|
23816
23815
|
await context_exports.doInAppContext(appId, async () => {
|
|
23817
|
-
const
|
|
23816
|
+
const db2 = context_exports.getAppDB();
|
|
23818
23817
|
for (let user of users2) {
|
|
23819
23818
|
let ctxUser = user;
|
|
23820
23819
|
let deletedUser = false;
|
|
@@ -23829,9 +23828,9 @@ async function syncUsersToApp(appId, users2, groups) {
|
|
|
23829
23828
|
if (roleId === roles_exports.BUILTIN_ROLE_IDS.PUBLIC) {
|
|
23830
23829
|
roleId = void 0;
|
|
23831
23830
|
}
|
|
23832
|
-
let
|
|
23831
|
+
let metadata2;
|
|
23833
23832
|
try {
|
|
23834
|
-
|
|
23833
|
+
metadata2 = await db2.get(metadataId);
|
|
23835
23834
|
} catch (err) {
|
|
23836
23835
|
if (err.status !== 404) {
|
|
23837
23836
|
throw err;
|
|
@@ -23839,21 +23838,21 @@ async function syncUsersToApp(appId, users2, groups) {
|
|
|
23839
23838
|
if (!roleId) {
|
|
23840
23839
|
continue;
|
|
23841
23840
|
} else if (!deletedUser) {
|
|
23842
|
-
|
|
23841
|
+
metadata2 = {
|
|
23843
23842
|
tableId: InternalTables.USER_METADATA
|
|
23844
23843
|
};
|
|
23845
23844
|
}
|
|
23846
23845
|
}
|
|
23847
23846
|
if (deletedUser || !roleId) {
|
|
23848
|
-
await
|
|
23847
|
+
await db2.remove(metadata2);
|
|
23849
23848
|
continue;
|
|
23850
23849
|
}
|
|
23851
23850
|
if (roleId) {
|
|
23852
|
-
|
|
23851
|
+
metadata2.roleId = roleId;
|
|
23853
23852
|
}
|
|
23854
|
-
let combined = sdk_default.users.combineMetadataAndUser(ctxUser,
|
|
23853
|
+
let combined = sdk_default.users.combineMetadataAndUser(ctxUser, metadata2);
|
|
23855
23854
|
if (combined) {
|
|
23856
|
-
await
|
|
23855
|
+
await db2.put(combined);
|
|
23857
23856
|
}
|
|
23858
23857
|
}
|
|
23859
23858
|
});
|
|
@@ -23908,7 +23907,7 @@ async function syncApp(appId, opts) {
|
|
|
23908
23907
|
try {
|
|
23909
23908
|
const replOpts = replication.appReplicateOpts();
|
|
23910
23909
|
if (opts == null ? void 0 : opts.automationOnly) {
|
|
23911
|
-
replOpts.filter = (
|
|
23910
|
+
replOpts.filter = (doc2) => doc2._id.startsWith(db_exports.DocumentType.AUTOMATION);
|
|
23912
23911
|
}
|
|
23913
23912
|
await replication.replicate(replOpts);
|
|
23914
23913
|
} catch (err) {
|
|
@@ -24021,7 +24020,7 @@ function generateAttachmentFindParams(tableId, attachmentCols, bookmark) {
|
|
|
24021
24020
|
return params2;
|
|
24022
24021
|
}
|
|
24023
24022
|
async function getRowsWithAttachments(appId, table) {
|
|
24024
|
-
const
|
|
24023
|
+
const db2 = db_exports.getDB(appId);
|
|
24025
24024
|
const attachmentCols = [];
|
|
24026
24025
|
for (let [key, column] of Object.entries(table.schema)) {
|
|
24027
24026
|
if (column.type === "attachment" /* ATTACHMENT */) {
|
|
@@ -24038,7 +24037,7 @@ async function getRowsWithAttachments(appId, table) {
|
|
|
24038
24037
|
attachmentCols,
|
|
24039
24038
|
bookmark
|
|
24040
24039
|
);
|
|
24041
|
-
const resp = await db_exports.directCouchFind(
|
|
24040
|
+
const resp = await db_exports.directCouchFind(db2.name, params2);
|
|
24042
24041
|
bookmark = resp.bookmark;
|
|
24043
24042
|
rowsLength = resp.rows.length;
|
|
24044
24043
|
const rows2 = resp.rows;
|
|
@@ -24053,13 +24052,13 @@ __export(rows_exports, {
|
|
|
24053
24052
|
getAllInternalRows: () => getAllInternalRows
|
|
24054
24053
|
});
|
|
24055
24054
|
async function getAllInternalRows(appId) {
|
|
24056
|
-
let
|
|
24055
|
+
let db2;
|
|
24057
24056
|
if (appId) {
|
|
24058
|
-
|
|
24057
|
+
db2 = db_exports.getDB(appId);
|
|
24059
24058
|
} else {
|
|
24060
|
-
|
|
24059
|
+
db2 = context_exports.getAppDB();
|
|
24061
24060
|
}
|
|
24062
|
-
const response = await
|
|
24061
|
+
const response = await db2.allDocs(
|
|
24063
24062
|
getRowParams2(null, null, {
|
|
24064
24063
|
include_docs: true
|
|
24065
24064
|
})
|
|
@@ -24081,9 +24080,9 @@ __export(utils_exports8, {
|
|
|
24081
24080
|
syncGlobalUsers: () => syncGlobalUsers
|
|
24082
24081
|
});
|
|
24083
24082
|
var import_lodash5 = require("lodash");
|
|
24084
|
-
function combineMetadataAndUser(user,
|
|
24083
|
+
function combineMetadataAndUser(user, metadata2) {
|
|
24085
24084
|
const metadataId = generateUserMetadataID2(user._id);
|
|
24086
|
-
const found = Array.isArray(
|
|
24085
|
+
const found = Array.isArray(metadata2) ? metadata2.find((doc2) => doc2._id === metadataId) : metadata2;
|
|
24087
24086
|
if (user.roleId == null || user.roleId === roles_exports.BUILTIN_ROLE_IDS.PUBLIC) {
|
|
24088
24087
|
if (found == null ? void 0 : found._id) {
|
|
24089
24088
|
return { ...found, _deleted: true };
|
|
@@ -24110,11 +24109,11 @@ function combineMetadataAndUser(user, metadata) {
|
|
|
24110
24109
|
}
|
|
24111
24110
|
return null;
|
|
24112
24111
|
}
|
|
24113
|
-
async function rawUserMetadata(
|
|
24114
|
-
if (!
|
|
24115
|
-
|
|
24112
|
+
async function rawUserMetadata(db2) {
|
|
24113
|
+
if (!db2) {
|
|
24114
|
+
db2 = context_exports.getAppDB();
|
|
24116
24115
|
}
|
|
24117
|
-
return (await
|
|
24116
|
+
return (await db2.allDocs(
|
|
24118
24117
|
getUserMetadataParams2(null, {
|
|
24119
24118
|
include_docs: true
|
|
24120
24119
|
})
|
|
@@ -24122,22 +24121,22 @@ async function rawUserMetadata(db) {
|
|
|
24122
24121
|
}
|
|
24123
24122
|
async function syncGlobalUsers() {
|
|
24124
24123
|
const dbs = [context_exports.getDevAppDB(), context_exports.getProdAppDB()];
|
|
24125
|
-
for (let
|
|
24126
|
-
if (!await
|
|
24124
|
+
for (let db2 of dbs) {
|
|
24125
|
+
if (!await db2.exists()) {
|
|
24127
24126
|
continue;
|
|
24128
24127
|
}
|
|
24129
|
-
const resp = await Promise.all([getGlobalUsers(), rawUserMetadata(
|
|
24128
|
+
const resp = await Promise.all([getGlobalUsers(), rawUserMetadata(db2)]);
|
|
24130
24129
|
const users2 = resp[0];
|
|
24131
|
-
const
|
|
24130
|
+
const metadata2 = resp[1];
|
|
24132
24131
|
const toWrite = [];
|
|
24133
24132
|
for (let user of users2) {
|
|
24134
|
-
const combined = combineMetadataAndUser(user,
|
|
24133
|
+
const combined = combineMetadataAndUser(user, metadata2);
|
|
24135
24134
|
if (combined) {
|
|
24136
24135
|
toWrite.push(combined);
|
|
24137
24136
|
}
|
|
24138
24137
|
}
|
|
24139
24138
|
let foundEmails = [];
|
|
24140
|
-
for (let data of
|
|
24139
|
+
for (let data of metadata2) {
|
|
24141
24140
|
if (!data._id) {
|
|
24142
24141
|
continue;
|
|
24143
24142
|
}
|
|
@@ -24150,7 +24149,7 @@ async function syncGlobalUsers() {
|
|
|
24150
24149
|
foundEmails.push(data.email);
|
|
24151
24150
|
}
|
|
24152
24151
|
}
|
|
24153
|
-
await
|
|
24152
|
+
await db2.bulkDocs(toWrite);
|
|
24154
24153
|
}
|
|
24155
24154
|
}
|
|
24156
24155
|
|
|
@@ -24211,8 +24210,8 @@ var clientAppSocket;
|
|
|
24211
24210
|
|
|
24212
24211
|
// src/sdk/plugins/plugins.ts
|
|
24213
24212
|
async function fetch17(type) {
|
|
24214
|
-
const
|
|
24215
|
-
const response = await
|
|
24213
|
+
const db2 = tenancy.getGlobalDB();
|
|
24214
|
+
const response = await db2.allDocs(
|
|
24216
24215
|
db_exports.getPluginParams(null, {
|
|
24217
24216
|
include_docs: true
|
|
24218
24217
|
})
|
|
@@ -24228,16 +24227,16 @@ async function fetch17(type) {
|
|
|
24228
24227
|
return plugins2;
|
|
24229
24228
|
}
|
|
24230
24229
|
}
|
|
24231
|
-
async function processUploaded(plugin,
|
|
24230
|
+
async function processUploaded(plugin, source2) {
|
|
24232
24231
|
var _a, _b;
|
|
24233
|
-
const { metadata, directory } = await fileUpload(plugin);
|
|
24234
|
-
plugin_exports.validate(
|
|
24235
|
-
if (!environment_default.SELF_HOSTED && ((_a =
|
|
24232
|
+
const { metadata: metadata2, directory: directory2 } = await fileUpload(plugin);
|
|
24233
|
+
plugin_exports.validate(metadata2 == null ? void 0 : metadata2.schema);
|
|
24234
|
+
if (!environment_default.SELF_HOSTED && ((_a = metadata2 == null ? void 0 : metadata2.schema) == null ? void 0 : _a.type) !== "component" /* COMPONENT */) {
|
|
24236
24235
|
throw new Error("Only component plugins are supported outside of self-host");
|
|
24237
24236
|
}
|
|
24238
|
-
const
|
|
24239
|
-
(_b = clientAppSocket) == null ? void 0 : _b.emit("plugin-update", { name:
|
|
24240
|
-
return
|
|
24237
|
+
const doc2 = await sdk_exports.plugins.storePlugin(metadata2, directory2, source2);
|
|
24238
|
+
(_b = clientAppSocket) == null ? void 0 : _b.emit("plugin-update", { name: doc2.name, hash: doc2.hash });
|
|
24239
|
+
return doc2;
|
|
24241
24240
|
}
|
|
24242
24241
|
|
|
24243
24242
|
// src/sdk/plugins/index.ts
|
|
@@ -24301,13 +24300,13 @@ if (process.arch && !process.arch.startsWith("arm") && oracle_default.integratio
|
|
|
24301
24300
|
DEFINITIONS2["ORACLE" /* ORACLE */] = oracle_default.schema;
|
|
24302
24301
|
INTEGRATIONS["ORACLE" /* ORACLE */] = oracle_default.integration;
|
|
24303
24302
|
}
|
|
24304
|
-
async function getDefinition(
|
|
24305
|
-
const definition = DEFINITIONS2[
|
|
24303
|
+
async function getDefinition(source2) {
|
|
24304
|
+
const definition = DEFINITIONS2[source2];
|
|
24306
24305
|
if (definition) {
|
|
24307
24306
|
return definition;
|
|
24308
24307
|
}
|
|
24309
24308
|
const allDefinitions = await getDefinitions();
|
|
24310
|
-
return allDefinitions[
|
|
24309
|
+
return allDefinitions[source2];
|
|
24311
24310
|
}
|
|
24312
24311
|
async function getDefinitions() {
|
|
24313
24312
|
const pluginSchemas = {};
|
|
@@ -24510,8 +24509,8 @@ var QueryRunner = class {
|
|
|
24510
24509
|
return { rows: rows2, keys: keys2, info, extra, pagination: pagination3 };
|
|
24511
24510
|
}
|
|
24512
24511
|
async runAnotherQuery(queryId, parameters) {
|
|
24513
|
-
const
|
|
24514
|
-
const query = await
|
|
24512
|
+
const db2 = context_exports.getAppDB();
|
|
24513
|
+
const query = await db2.get(queryId);
|
|
24515
24514
|
const datasource2 = await sdk_default.datasources.get(query.datasourceId, {
|
|
24516
24515
|
enriched: true
|
|
24517
24516
|
});
|
|
@@ -24553,14 +24552,14 @@ var QueryRunner = class {
|
|
|
24553
24552
|
}
|
|
24554
24553
|
async getDynamicVariable(variable) {
|
|
24555
24554
|
let { parameters } = this;
|
|
24556
|
-
const queryId = variable.queryId,
|
|
24557
|
-
let value = await utils_default.checkCacheForDynamicVariable(queryId,
|
|
24555
|
+
const queryId = variable.queryId, name2 = variable.name;
|
|
24556
|
+
let value = await utils_default.checkCacheForDynamicVariable(queryId, name2);
|
|
24558
24557
|
if (!value) {
|
|
24559
24558
|
value = this.queryResponse[queryId] ? this.queryResponse[queryId] : await this.runAnotherQuery(queryId, parameters);
|
|
24560
24559
|
this.queryResponse[queryId] = value;
|
|
24561
|
-
await utils_default.storeDynamicVariable(queryId,
|
|
24560
|
+
await utils_default.storeDynamicVariable(queryId, name2, value);
|
|
24562
24561
|
} else {
|
|
24563
|
-
this.cachedVariables.push({ queryId, name });
|
|
24562
|
+
this.cachedVariables.push({ queryId, name: name2 });
|
|
24564
24563
|
}
|
|
24565
24564
|
return value;
|
|
24566
24565
|
}
|