@budibase/backend-core 2.13.50 → 2.13.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +654 -657
- package/dist/index.js.map +4 -4
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +4 -4
- package/dist/src/queue/queue.js +1 -1
- package/dist/src/queue/queue.js.map +1 -1
- package/dist/src/redis/redis.js +7 -6
- package/dist/src/redis/redis.js.map +1 -1
- package/package.json +4 -4
- package/src/queue/queue.ts +1 -1
- package/src/redis/redis.ts +7 -14
package/dist/index.js
CHANGED
|
@@ -3590,555 +3590,175 @@ var init_utils3 = __esm({
|
|
|
3590
3590
|
}
|
|
3591
3591
|
});
|
|
3592
3592
|
|
|
3593
|
-
// src/
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
}
|
|
3599
|
-
function
|
|
3600
|
-
|
|
3601
|
-
if (idx !== -1) {
|
|
3602
|
-
intervals.splice(idx, 1);
|
|
3603
|
-
}
|
|
3604
|
-
clearInterval(interval);
|
|
3605
|
-
}
|
|
3606
|
-
function cleanup() {
|
|
3607
|
-
for (let interval of intervals) {
|
|
3608
|
-
clearInterval(interval);
|
|
3609
|
-
}
|
|
3610
|
-
intervals = [];
|
|
3593
|
+
// src/logging/correlation/correlation.ts
|
|
3594
|
+
var correlation_exports = {};
|
|
3595
|
+
__export(correlation_exports, {
|
|
3596
|
+
getId: () => getId,
|
|
3597
|
+
setHeader: () => setHeader
|
|
3598
|
+
});
|
|
3599
|
+
function getId() {
|
|
3600
|
+
return correlator.getId();
|
|
3611
3601
|
}
|
|
3612
|
-
var
|
|
3613
|
-
var
|
|
3614
|
-
"src/
|
|
3602
|
+
var correlator, setHeader;
|
|
3603
|
+
var init_correlation = __esm({
|
|
3604
|
+
"src/logging/correlation/correlation.ts"() {
|
|
3615
3605
|
"use strict";
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
};
|
|
3623
|
-
ExecutionTimeTracker = class _ExecutionTimeTracker {
|
|
3624
|
-
constructor(limitMs) {
|
|
3625
|
-
this.limitMs = limitMs;
|
|
3626
|
-
this.totalTimeMs = 0;
|
|
3627
|
-
}
|
|
3628
|
-
static withLimit(limitMs) {
|
|
3629
|
-
return new _ExecutionTimeTracker(limitMs);
|
|
3630
|
-
}
|
|
3631
|
-
track(f) {
|
|
3632
|
-
this.checkLimit();
|
|
3633
|
-
const start2 = process.hrtime.bigint();
|
|
3634
|
-
try {
|
|
3635
|
-
return f();
|
|
3636
|
-
} finally {
|
|
3637
|
-
const end2 = process.hrtime.bigint();
|
|
3638
|
-
this.totalTimeMs += Number(end2 - start2) / 1e6;
|
|
3639
|
-
this.checkLimit();
|
|
3640
|
-
}
|
|
3641
|
-
}
|
|
3642
|
-
get elapsedMS() {
|
|
3643
|
-
return this.totalTimeMs;
|
|
3644
|
-
}
|
|
3645
|
-
checkLimit() {
|
|
3646
|
-
if (this.totalTimeMs > this.limitMs) {
|
|
3647
|
-
throw new ExecutionTimeoutError(
|
|
3648
|
-
`Execution time limit of ${this.limitMs}ms exceeded: ${this.totalTimeMs}ms`
|
|
3649
|
-
);
|
|
3650
|
-
}
|
|
3606
|
+
init_constants4();
|
|
3607
|
+
correlator = require("correlation-id");
|
|
3608
|
+
setHeader = (headers) => {
|
|
3609
|
+
const correlationId = correlator.getId();
|
|
3610
|
+
if (correlationId) {
|
|
3611
|
+
headers["x-budibase-correlation-id" /* CORRELATION_ID */] = correlationId;
|
|
3651
3612
|
}
|
|
3652
3613
|
};
|
|
3653
3614
|
}
|
|
3654
3615
|
});
|
|
3655
3616
|
|
|
3656
|
-
// src/
|
|
3657
|
-
var
|
|
3658
|
-
|
|
3659
|
-
ExecutionTimeTracker: () => ExecutionTimeTracker,
|
|
3660
|
-
ExecutionTimeoutError: () => ExecutionTimeoutError,
|
|
3661
|
-
cleanup: () => cleanup,
|
|
3662
|
-
clear: () => clear,
|
|
3663
|
-
set: () => set
|
|
3664
|
-
});
|
|
3665
|
-
var init_timers2 = __esm({
|
|
3666
|
-
"src/timers/index.ts"() {
|
|
3617
|
+
// src/logging/correlation/index.ts
|
|
3618
|
+
var init_correlation2 = __esm({
|
|
3619
|
+
"src/logging/correlation/index.ts"() {
|
|
3667
3620
|
"use strict";
|
|
3668
|
-
|
|
3621
|
+
init_correlation();
|
|
3669
3622
|
}
|
|
3670
3623
|
});
|
|
3671
3624
|
|
|
3672
|
-
// src/
|
|
3673
|
-
function
|
|
3674
|
-
return
|
|
3625
|
+
// src/objectStore/utils.ts
|
|
3626
|
+
function budibaseTempDir() {
|
|
3627
|
+
return bbTmp;
|
|
3675
3628
|
}
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3629
|
+
var import_path, import_os, import_fs2, ObjectStoreBuckets, bbTmp;
|
|
3630
|
+
var init_utils4 = __esm({
|
|
3631
|
+
"src/objectStore/utils.ts"() {
|
|
3632
|
+
"use strict";
|
|
3633
|
+
import_path = require("path");
|
|
3634
|
+
import_os = require("os");
|
|
3635
|
+
import_fs2 = __toESM(require("fs"));
|
|
3636
|
+
init_environment2();
|
|
3637
|
+
ObjectStoreBuckets = {
|
|
3638
|
+
BACKUPS: environment_default.BACKUPS_BUCKET_NAME,
|
|
3639
|
+
APPS: environment_default.APPS_BUCKET_NAME,
|
|
3640
|
+
TEMPLATES: environment_default.TEMPLATES_BUCKET_NAME,
|
|
3641
|
+
GLOBAL: environment_default.GLOBAL_BUCKET_NAME,
|
|
3642
|
+
PLUGINS: environment_default.PLUGIN_BUCKET_NAME
|
|
3643
|
+
};
|
|
3644
|
+
bbTmp = (0, import_path.join)((0, import_os.tmpdir)(), ".budibase");
|
|
3645
|
+
try {
|
|
3646
|
+
import_fs2.default.mkdirSync(bbTmp);
|
|
3647
|
+
} catch (e) {
|
|
3648
|
+
if (e.code !== "EEXIST") {
|
|
3649
|
+
throw e;
|
|
3650
|
+
}
|
|
3651
|
+
}
|
|
3679
3652
|
}
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3653
|
+
});
|
|
3654
|
+
|
|
3655
|
+
// src/cache/appMetadata.ts
|
|
3656
|
+
var appMetadata_exports = {};
|
|
3657
|
+
__export(appMetadata_exports, {
|
|
3658
|
+
AppState: () => AppState,
|
|
3659
|
+
getAppMetadata: () => getAppMetadata,
|
|
3660
|
+
invalidateAppMetadata: () => invalidateAppMetadata
|
|
3661
|
+
});
|
|
3662
|
+
async function populateFromDB(appId) {
|
|
3663
|
+
return doWithDB(
|
|
3664
|
+
appId,
|
|
3665
|
+
(db) => {
|
|
3666
|
+
return db.get("app_metadata" /* APP_METADATA */);
|
|
3667
|
+
},
|
|
3668
|
+
{ skip_setup: true }
|
|
3669
|
+
);
|
|
3688
3670
|
}
|
|
3689
|
-
function
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3671
|
+
function isInvalid(metadata) {
|
|
3672
|
+
return !metadata || metadata.state === "invalid" /* INVALID */;
|
|
3673
|
+
}
|
|
3674
|
+
async function getAppMetadata(appId) {
|
|
3675
|
+
const client = await getAppClient();
|
|
3676
|
+
let metadata = await client.get(appId);
|
|
3677
|
+
if (!metadata) {
|
|
3678
|
+
let expiry = EXPIRY_SECONDS;
|
|
3679
|
+
try {
|
|
3680
|
+
metadata = await populateFromDB(appId);
|
|
3681
|
+
} catch (err) {
|
|
3682
|
+
if (err && err.status === 404) {
|
|
3683
|
+
metadata = { state: "invalid" /* INVALID */ };
|
|
3684
|
+
expiry = void 0;
|
|
3685
|
+
} else {
|
|
3686
|
+
throw err;
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
if (isInvalid(metadata)) {
|
|
3690
|
+
const temp = await client.get(appId);
|
|
3691
|
+
if (temp) {
|
|
3692
|
+
metadata = temp;
|
|
3693
|
+
}
|
|
3694
|
+
}
|
|
3695
|
+
await client.store(appId, metadata, expiry);
|
|
3696
3696
|
}
|
|
3697
|
-
|
|
3698
|
-
|
|
3697
|
+
return metadata;
|
|
3698
|
+
}
|
|
3699
|
+
async function invalidateAppMetadata(appId, newMetadata) {
|
|
3700
|
+
if (!appId) {
|
|
3701
|
+
throw "Cannot invalidate if no app ID provided.";
|
|
3699
3702
|
}
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
timeout2,
|
|
3705
|
-
"Did not successfully connect in timeout"
|
|
3706
|
-
);
|
|
3707
|
-
}
|
|
3708
|
-
}, STARTUP_TIMEOUT_MS);
|
|
3709
|
-
if (client) {
|
|
3710
|
-
client.disconnect();
|
|
3703
|
+
const client = await getAppClient();
|
|
3704
|
+
await client.delete(appId);
|
|
3705
|
+
if (newMetadata) {
|
|
3706
|
+
await client.store(appId, newMetadata, EXPIRY_SECONDS);
|
|
3711
3707
|
}
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3708
|
+
}
|
|
3709
|
+
var AppState, EXPIRY_SECONDS;
|
|
3710
|
+
var init_appMetadata = __esm({
|
|
3711
|
+
"src/cache/appMetadata.ts"() {
|
|
3712
|
+
"use strict";
|
|
3713
|
+
init_init();
|
|
3714
|
+
init_db4();
|
|
3715
|
+
AppState = /* @__PURE__ */ ((AppState2) => {
|
|
3716
|
+
AppState2["INVALID"] = "invalid";
|
|
3717
|
+
return AppState2;
|
|
3718
|
+
})(AppState || {});
|
|
3719
|
+
EXPIRY_SECONDS = 3600;
|
|
3718
3720
|
}
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
}
|
|
3725
|
-
client.on("error", (err) => {
|
|
3726
|
-
connectionError(selectDb, timeout2, err);
|
|
3727
|
-
});
|
|
3728
|
-
client.on("connect", () => {
|
|
3729
|
-
clearTimeout(timeout2);
|
|
3730
|
-
CONNECTED = true;
|
|
3731
|
-
});
|
|
3732
|
-
CLIENTS[selectDb] = client;
|
|
3721
|
+
});
|
|
3722
|
+
|
|
3723
|
+
// src/docIds/ids.ts
|
|
3724
|
+
function generateRowID(tableId, id) {
|
|
3725
|
+
id = id || newid();
|
|
3726
|
+
return `${"ro" /* ROW */}${SEPARATOR}${tableId}${SEPARATOR}${id}`;
|
|
3733
3727
|
}
|
|
3734
|
-
function
|
|
3735
|
-
return
|
|
3736
|
-
if (pickClient(selectDb) == null) {
|
|
3737
|
-
init2();
|
|
3738
|
-
} else if (CONNECTED) {
|
|
3739
|
-
resolve("");
|
|
3740
|
-
return;
|
|
3741
|
-
}
|
|
3742
|
-
const interval = set(() => {
|
|
3743
|
-
if (CONNECTED) {
|
|
3744
|
-
clear(interval);
|
|
3745
|
-
resolve("");
|
|
3746
|
-
}
|
|
3747
|
-
}, 500);
|
|
3748
|
-
});
|
|
3728
|
+
function generateWorkspaceID() {
|
|
3729
|
+
return `${"workspace" /* WORKSPACE */}${SEPARATOR}${newid()}`;
|
|
3749
3730
|
}
|
|
3750
|
-
function
|
|
3751
|
-
return
|
|
3752
|
-
const outputKeys = /* @__PURE__ */ new Set();
|
|
3753
|
-
stream2.on("data", (keys2) => {
|
|
3754
|
-
keys2.forEach((key) => {
|
|
3755
|
-
outputKeys.add(key);
|
|
3756
|
-
});
|
|
3757
|
-
});
|
|
3758
|
-
stream2.on("error", (err) => {
|
|
3759
|
-
reject(err);
|
|
3760
|
-
});
|
|
3761
|
-
stream2.on("end", async () => {
|
|
3762
|
-
const keysArray = Array.from(outputKeys);
|
|
3763
|
-
try {
|
|
3764
|
-
let getPromises = [];
|
|
3765
|
-
for (let key of keysArray) {
|
|
3766
|
-
getPromises.push(client.get(key));
|
|
3767
|
-
}
|
|
3768
|
-
const jsonArray = await Promise.all(getPromises);
|
|
3769
|
-
resolve(
|
|
3770
|
-
keysArray.map((key) => ({
|
|
3771
|
-
key: removeDbPrefix(key),
|
|
3772
|
-
value: JSON.parse(jsonArray.shift())
|
|
3773
|
-
}))
|
|
3774
|
-
);
|
|
3775
|
-
} catch (err) {
|
|
3776
|
-
reject(err);
|
|
3777
|
-
}
|
|
3778
|
-
});
|
|
3779
|
-
});
|
|
3731
|
+
function generateGlobalUserID(id) {
|
|
3732
|
+
return `${"us" /* USER */}${SEPARATOR}${id || newid()}`;
|
|
3780
3733
|
}
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
"src/redis/redis.ts"() {
|
|
3784
|
-
"use strict";
|
|
3785
|
-
init_environment2();
|
|
3786
|
-
import_ioredis = __toESM(require("ioredis"));
|
|
3787
|
-
init_utils3();
|
|
3788
|
-
init_timers2();
|
|
3789
|
-
if (environment_default.MOCK_REDIS) {
|
|
3790
|
-
try {
|
|
3791
|
-
MockRedis = require("ioredis-mock");
|
|
3792
|
-
} catch (err) {
|
|
3793
|
-
console.log("Mock redis unavailable");
|
|
3794
|
-
}
|
|
3795
|
-
}
|
|
3796
|
-
RETRY_PERIOD_MS = 2e3;
|
|
3797
|
-
STARTUP_TIMEOUT_MS = 5e3;
|
|
3798
|
-
CLUSTERED = environment_default.REDIS_CLUSTERED;
|
|
3799
|
-
DEFAULT_SELECT_DB = 0 /* DEFAULT */;
|
|
3800
|
-
CLOSED = false;
|
|
3801
|
-
CLIENTS = {};
|
|
3802
|
-
CONNECTED = false;
|
|
3803
|
-
if (environment_default.MOCK_REDIS) {
|
|
3804
|
-
CONNECTED = true;
|
|
3805
|
-
}
|
|
3806
|
-
RedisWrapper = class {
|
|
3807
|
-
constructor(db, selectDb = null) {
|
|
3808
|
-
this._db = db;
|
|
3809
|
-
this._select = selectDb || DEFAULT_SELECT_DB;
|
|
3810
|
-
}
|
|
3811
|
-
getClient() {
|
|
3812
|
-
return pickClient(this._select);
|
|
3813
|
-
}
|
|
3814
|
-
async init() {
|
|
3815
|
-
CLOSED = false;
|
|
3816
|
-
init2(this._select);
|
|
3817
|
-
await waitForConnection(this._select);
|
|
3818
|
-
if (this._select && !environment_default.isTest()) {
|
|
3819
|
-
this.getClient().select(this._select);
|
|
3820
|
-
}
|
|
3821
|
-
return this;
|
|
3822
|
-
}
|
|
3823
|
-
async finish() {
|
|
3824
|
-
CLOSED = true;
|
|
3825
|
-
this.getClient().disconnect();
|
|
3826
|
-
}
|
|
3827
|
-
async scan(key = "") {
|
|
3828
|
-
const db = this._db;
|
|
3829
|
-
key = `${db}${SEPARATOR2}${key}`;
|
|
3830
|
-
let stream2;
|
|
3831
|
-
if (CLUSTERED) {
|
|
3832
|
-
let node = this.getClient().nodes("master");
|
|
3833
|
-
stream2 = node[0].scanStream({ match: key + "*", count: 100 });
|
|
3834
|
-
} else {
|
|
3835
|
-
stream2 = this.getClient().scanStream({ match: key + "*", count: 100 });
|
|
3836
|
-
}
|
|
3837
|
-
return promisifyStream(stream2, this.getClient());
|
|
3838
|
-
}
|
|
3839
|
-
async keys(pattern) {
|
|
3840
|
-
const db = this._db;
|
|
3841
|
-
return this.getClient().keys(addDbPrefix(db, pattern));
|
|
3842
|
-
}
|
|
3843
|
-
async exists(key) {
|
|
3844
|
-
const db = this._db;
|
|
3845
|
-
return await this.getClient().exists(addDbPrefix(db, key));
|
|
3846
|
-
}
|
|
3847
|
-
async get(key) {
|
|
3848
|
-
const db = this._db;
|
|
3849
|
-
let response = await this.getClient().get(addDbPrefix(db, key));
|
|
3850
|
-
if (response != null && response.key) {
|
|
3851
|
-
response.key = key;
|
|
3852
|
-
}
|
|
3853
|
-
try {
|
|
3854
|
-
return JSON.parse(response);
|
|
3855
|
-
} catch (err) {
|
|
3856
|
-
return response;
|
|
3857
|
-
}
|
|
3858
|
-
}
|
|
3859
|
-
async bulkGet(keys2) {
|
|
3860
|
-
const db = this._db;
|
|
3861
|
-
if (keys2.length === 0) {
|
|
3862
|
-
return {};
|
|
3863
|
-
}
|
|
3864
|
-
const prefixedKeys = keys2.map((key) => addDbPrefix(db, key));
|
|
3865
|
-
let response = await this.getClient().mget(prefixedKeys);
|
|
3866
|
-
if (Array.isArray(response)) {
|
|
3867
|
-
let final = {};
|
|
3868
|
-
let count = 0;
|
|
3869
|
-
for (let result of response) {
|
|
3870
|
-
if (result) {
|
|
3871
|
-
let parsed;
|
|
3872
|
-
try {
|
|
3873
|
-
parsed = JSON.parse(result);
|
|
3874
|
-
} catch (err) {
|
|
3875
|
-
parsed = result;
|
|
3876
|
-
}
|
|
3877
|
-
final[keys2[count]] = parsed;
|
|
3878
|
-
}
|
|
3879
|
-
count++;
|
|
3880
|
-
}
|
|
3881
|
-
return final;
|
|
3882
|
-
} else {
|
|
3883
|
-
throw new Error(`Invalid response: ${response}`);
|
|
3884
|
-
}
|
|
3885
|
-
}
|
|
3886
|
-
async store(key, value, expirySeconds = null) {
|
|
3887
|
-
const db = this._db;
|
|
3888
|
-
if (typeof value === "object") {
|
|
3889
|
-
value = JSON.stringify(value);
|
|
3890
|
-
}
|
|
3891
|
-
const prefixedKey = addDbPrefix(db, key);
|
|
3892
|
-
await this.getClient().set(prefixedKey, value);
|
|
3893
|
-
if (expirySeconds) {
|
|
3894
|
-
await this.getClient().expire(prefixedKey, expirySeconds);
|
|
3895
|
-
}
|
|
3896
|
-
}
|
|
3897
|
-
async getTTL(key) {
|
|
3898
|
-
const db = this._db;
|
|
3899
|
-
const prefixedKey = addDbPrefix(db, key);
|
|
3900
|
-
return this.getClient().ttl(prefixedKey);
|
|
3901
|
-
}
|
|
3902
|
-
async setExpiry(key, expirySeconds) {
|
|
3903
|
-
const db = this._db;
|
|
3904
|
-
const prefixedKey = addDbPrefix(db, key);
|
|
3905
|
-
await this.getClient().expire(prefixedKey, expirySeconds);
|
|
3906
|
-
}
|
|
3907
|
-
async delete(key) {
|
|
3908
|
-
const db = this._db;
|
|
3909
|
-
await this.getClient().del(addDbPrefix(db, key));
|
|
3910
|
-
}
|
|
3911
|
-
async clear() {
|
|
3912
|
-
let items = await this.scan();
|
|
3913
|
-
await Promise.all(items.map((obj) => this.delete(obj.key)));
|
|
3914
|
-
}
|
|
3915
|
-
};
|
|
3916
|
-
redis_default = RedisWrapper;
|
|
3917
|
-
}
|
|
3918
|
-
});
|
|
3919
|
-
|
|
3920
|
-
// src/redis/init.ts
|
|
3921
|
-
var init_exports = {};
|
|
3922
|
-
__export(init_exports, {
|
|
3923
|
-
getAppClient: () => getAppClient,
|
|
3924
|
-
getCacheClient: () => getCacheClient,
|
|
3925
|
-
getInviteClient: () => getInviteClient,
|
|
3926
|
-
getLockClient: () => getLockClient,
|
|
3927
|
-
getPasswordResetClient: () => getPasswordResetClient,
|
|
3928
|
-
getSessionClient: () => getSessionClient,
|
|
3929
|
-
getSocketClient: () => getSocketClient,
|
|
3930
|
-
getUserClient: () => getUserClient,
|
|
3931
|
-
getWritethroughClient: () => getWritethroughClient,
|
|
3932
|
-
init: () => init3,
|
|
3933
|
-
shutdown: () => shutdown
|
|
3934
|
-
});
|
|
3935
|
-
async function init3() {
|
|
3936
|
-
userClient = await new redis_default("users" /* USER_CACHE */).init();
|
|
3937
|
-
sessionClient = await new redis_default("session" /* SESSIONS */).init();
|
|
3938
|
-
appClient = await new redis_default("appMetadata" /* APP_METADATA */).init();
|
|
3939
|
-
cacheClient = await new redis_default("data_cache" /* GENERIC_CACHE */).init();
|
|
3940
|
-
lockClient = await new redis_default("locks" /* LOCKS */).init();
|
|
3941
|
-
writethroughClient = await new redis_default("writeThrough" /* WRITE_THROUGH */).init();
|
|
3942
|
-
inviteClient = await new redis_default("invitation" /* INVITATIONS */).init();
|
|
3943
|
-
passwordResetClient = await new redis_default("pwReset" /* PW_RESETS */).init();
|
|
3944
|
-
socketClient = await new redis_default(
|
|
3945
|
-
"socket_io" /* SOCKET_IO */,
|
|
3946
|
-
1 /* SOCKET_IO */
|
|
3947
|
-
).init();
|
|
3734
|
+
function isGlobalUserID(id) {
|
|
3735
|
+
return isGlobalUserIDRegex.test(id);
|
|
3948
3736
|
}
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
await userClient.finish();
|
|
3952
|
-
if (sessionClient)
|
|
3953
|
-
await sessionClient.finish();
|
|
3954
|
-
if (appClient)
|
|
3955
|
-
await appClient.finish();
|
|
3956
|
-
if (cacheClient)
|
|
3957
|
-
await cacheClient.finish();
|
|
3958
|
-
if (writethroughClient)
|
|
3959
|
-
await writethroughClient.finish();
|
|
3960
|
-
if (lockClient)
|
|
3961
|
-
await lockClient.finish();
|
|
3962
|
-
if (inviteClient)
|
|
3963
|
-
await inviteClient.finish();
|
|
3964
|
-
if (passwordResetClient)
|
|
3965
|
-
await passwordResetClient.finish();
|
|
3966
|
-
if (socketClient)
|
|
3967
|
-
await socketClient.finish();
|
|
3737
|
+
function generateUserMetadataID(globalId) {
|
|
3738
|
+
return generateRowID("ta_users" /* USER_METADATA */, globalId);
|
|
3968
3739
|
}
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3740
|
+
function getGlobalIDFromUserMetadataID(id) {
|
|
3741
|
+
const prefix = `${"ro" /* ROW */}${SEPARATOR}${"ta_users" /* USER_METADATA */}${SEPARATOR}`;
|
|
3742
|
+
if (!id || !id.includes(prefix)) {
|
|
3743
|
+
return id;
|
|
3972
3744
|
}
|
|
3973
|
-
return
|
|
3745
|
+
return id.split(prefix)[1];
|
|
3974
3746
|
}
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
await init3();
|
|
3978
|
-
}
|
|
3979
|
-
return sessionClient;
|
|
3747
|
+
function generateTemplateID(ownerId) {
|
|
3748
|
+
return `${"template" /* TEMPLATE */}${SEPARATOR}${ownerId}${SEPARATOR}${newid()}`;
|
|
3980
3749
|
}
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
await init3();
|
|
3984
|
-
}
|
|
3985
|
-
return appClient;
|
|
3750
|
+
function generateAppUserID(prodAppId, userId) {
|
|
3751
|
+
return `${prodAppId}${SEPARATOR}${userId}`;
|
|
3986
3752
|
}
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3753
|
+
function generateRoleID(name) {
|
|
3754
|
+
const prefix = `${"role" /* ROLE */}${SEPARATOR}`;
|
|
3755
|
+
if (name.startsWith(prefix)) {
|
|
3756
|
+
return name;
|
|
3990
3757
|
}
|
|
3991
|
-
return
|
|
3758
|
+
return `${prefix}${name}`;
|
|
3992
3759
|
}
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
await init3();
|
|
3996
|
-
}
|
|
3997
|
-
return writethroughClient;
|
|
3998
|
-
}
|
|
3999
|
-
async function getLockClient() {
|
|
4000
|
-
if (!lockClient) {
|
|
4001
|
-
await init3();
|
|
4002
|
-
}
|
|
4003
|
-
return lockClient;
|
|
4004
|
-
}
|
|
4005
|
-
async function getSocketClient() {
|
|
4006
|
-
if (!socketClient) {
|
|
4007
|
-
await init3();
|
|
4008
|
-
}
|
|
4009
|
-
return socketClient;
|
|
4010
|
-
}
|
|
4011
|
-
async function getInviteClient() {
|
|
4012
|
-
if (!inviteClient) {
|
|
4013
|
-
await init3();
|
|
4014
|
-
}
|
|
4015
|
-
return inviteClient;
|
|
4016
|
-
}
|
|
4017
|
-
async function getPasswordResetClient() {
|
|
4018
|
-
if (!passwordResetClient) {
|
|
4019
|
-
await init3();
|
|
4020
|
-
}
|
|
4021
|
-
return passwordResetClient;
|
|
4022
|
-
}
|
|
4023
|
-
var userClient, sessionClient, appClient, cacheClient, writethroughClient, lockClient, socketClient, inviteClient, passwordResetClient;
|
|
4024
|
-
var init_init = __esm({
|
|
4025
|
-
"src/redis/init.ts"() {
|
|
4026
|
-
"use strict";
|
|
4027
|
-
init_redis();
|
|
4028
|
-
init_utils3();
|
|
4029
|
-
process.on("exit", async () => {
|
|
4030
|
-
await shutdown();
|
|
4031
|
-
});
|
|
4032
|
-
}
|
|
4033
|
-
});
|
|
4034
|
-
|
|
4035
|
-
// src/cache/appMetadata.ts
|
|
4036
|
-
var appMetadata_exports = {};
|
|
4037
|
-
__export(appMetadata_exports, {
|
|
4038
|
-
AppState: () => AppState,
|
|
4039
|
-
getAppMetadata: () => getAppMetadata,
|
|
4040
|
-
invalidateAppMetadata: () => invalidateAppMetadata
|
|
4041
|
-
});
|
|
4042
|
-
async function populateFromDB(appId) {
|
|
4043
|
-
return doWithDB(
|
|
4044
|
-
appId,
|
|
4045
|
-
(db) => {
|
|
4046
|
-
return db.get("app_metadata" /* APP_METADATA */);
|
|
4047
|
-
},
|
|
4048
|
-
{ skip_setup: true }
|
|
4049
|
-
);
|
|
4050
|
-
}
|
|
4051
|
-
function isInvalid(metadata) {
|
|
4052
|
-
return !metadata || metadata.state === "invalid" /* INVALID */;
|
|
4053
|
-
}
|
|
4054
|
-
async function getAppMetadata(appId) {
|
|
4055
|
-
const client = await getAppClient();
|
|
4056
|
-
let metadata = await client.get(appId);
|
|
4057
|
-
if (!metadata) {
|
|
4058
|
-
let expiry = EXPIRY_SECONDS;
|
|
4059
|
-
try {
|
|
4060
|
-
metadata = await populateFromDB(appId);
|
|
4061
|
-
} catch (err) {
|
|
4062
|
-
if (err && err.status === 404) {
|
|
4063
|
-
metadata = { state: "invalid" /* INVALID */ };
|
|
4064
|
-
expiry = void 0;
|
|
4065
|
-
} else {
|
|
4066
|
-
throw err;
|
|
4067
|
-
}
|
|
4068
|
-
}
|
|
4069
|
-
if (isInvalid(metadata)) {
|
|
4070
|
-
const temp = await client.get(appId);
|
|
4071
|
-
if (temp) {
|
|
4072
|
-
metadata = temp;
|
|
4073
|
-
}
|
|
4074
|
-
}
|
|
4075
|
-
await client.store(appId, metadata, expiry);
|
|
4076
|
-
}
|
|
4077
|
-
return metadata;
|
|
4078
|
-
}
|
|
4079
|
-
async function invalidateAppMetadata(appId, newMetadata) {
|
|
4080
|
-
if (!appId) {
|
|
4081
|
-
throw "Cannot invalidate if no app ID provided.";
|
|
4082
|
-
}
|
|
4083
|
-
const client = await getAppClient();
|
|
4084
|
-
await client.delete(appId);
|
|
4085
|
-
if (newMetadata) {
|
|
4086
|
-
await client.store(appId, newMetadata, EXPIRY_SECONDS);
|
|
4087
|
-
}
|
|
4088
|
-
}
|
|
4089
|
-
var AppState, EXPIRY_SECONDS;
|
|
4090
|
-
var init_appMetadata = __esm({
|
|
4091
|
-
"src/cache/appMetadata.ts"() {
|
|
4092
|
-
"use strict";
|
|
4093
|
-
init_init();
|
|
4094
|
-
init_db4();
|
|
4095
|
-
AppState = /* @__PURE__ */ ((AppState2) => {
|
|
4096
|
-
AppState2["INVALID"] = "invalid";
|
|
4097
|
-
return AppState2;
|
|
4098
|
-
})(AppState || {});
|
|
4099
|
-
EXPIRY_SECONDS = 3600;
|
|
4100
|
-
}
|
|
4101
|
-
});
|
|
4102
|
-
|
|
4103
|
-
// src/docIds/ids.ts
|
|
4104
|
-
function generateRowID(tableId, id) {
|
|
4105
|
-
id = id || newid();
|
|
4106
|
-
return `${"ro" /* ROW */}${SEPARATOR}${tableId}${SEPARATOR}${id}`;
|
|
4107
|
-
}
|
|
4108
|
-
function generateWorkspaceID() {
|
|
4109
|
-
return `${"workspace" /* WORKSPACE */}${SEPARATOR}${newid()}`;
|
|
4110
|
-
}
|
|
4111
|
-
function generateGlobalUserID(id) {
|
|
4112
|
-
return `${"us" /* USER */}${SEPARATOR}${id || newid()}`;
|
|
4113
|
-
}
|
|
4114
|
-
function isGlobalUserID(id) {
|
|
4115
|
-
return isGlobalUserIDRegex.test(id);
|
|
4116
|
-
}
|
|
4117
|
-
function generateUserMetadataID(globalId) {
|
|
4118
|
-
return generateRowID("ta_users" /* USER_METADATA */, globalId);
|
|
4119
|
-
}
|
|
4120
|
-
function getGlobalIDFromUserMetadataID(id) {
|
|
4121
|
-
const prefix = `${"ro" /* ROW */}${SEPARATOR}${"ta_users" /* USER_METADATA */}${SEPARATOR}`;
|
|
4122
|
-
if (!id || !id.includes(prefix)) {
|
|
4123
|
-
return id;
|
|
4124
|
-
}
|
|
4125
|
-
return id.split(prefix)[1];
|
|
4126
|
-
}
|
|
4127
|
-
function generateTemplateID(ownerId) {
|
|
4128
|
-
return `${"template" /* TEMPLATE */}${SEPARATOR}${ownerId}${SEPARATOR}${newid()}`;
|
|
4129
|
-
}
|
|
4130
|
-
function generateAppUserID(prodAppId, userId) {
|
|
4131
|
-
return `${prodAppId}${SEPARATOR}${userId}`;
|
|
4132
|
-
}
|
|
4133
|
-
function generateRoleID(name) {
|
|
4134
|
-
const prefix = `${"role" /* ROLE */}${SEPARATOR}`;
|
|
4135
|
-
if (name.startsWith(prefix)) {
|
|
4136
|
-
return name;
|
|
4137
|
-
}
|
|
4138
|
-
return `${prefix}${name}`;
|
|
4139
|
-
}
|
|
4140
|
-
function prefixRoleID(name) {
|
|
4141
|
-
return generateRoleID(name);
|
|
3760
|
+
function prefixRoleID(name) {
|
|
3761
|
+
return generateRoleID(name);
|
|
4142
3762
|
}
|
|
4143
3763
|
var generateAppID, isGlobalUserIDRegex, generateDevInfoID, generatePluginID;
|
|
4144
3764
|
var init_ids = __esm({
|
|
@@ -4430,7 +4050,7 @@ function pagination(data, pageSize, {
|
|
|
4430
4050
|
nextPage
|
|
4431
4051
|
};
|
|
4432
4052
|
}
|
|
4433
|
-
var
|
|
4053
|
+
var init_utils5 = __esm({
|
|
4434
4054
|
"src/db/utils.ts"() {
|
|
4435
4055
|
"use strict";
|
|
4436
4056
|
init_environment2();
|
|
@@ -5445,7 +5065,7 @@ var init_db4 = __esm({
|
|
|
5445
5065
|
"use strict";
|
|
5446
5066
|
init_couch();
|
|
5447
5067
|
init_db3();
|
|
5448
|
-
|
|
5068
|
+
init_utils5();
|
|
5449
5069
|
init_views();
|
|
5450
5070
|
init_conversions();
|
|
5451
5071
|
init_Replication();
|
|
@@ -5457,68 +5077,6 @@ var init_db4 = __esm({
|
|
|
5457
5077
|
}
|
|
5458
5078
|
});
|
|
5459
5079
|
|
|
5460
|
-
// src/logging/correlation/correlation.ts
|
|
5461
|
-
var correlation_exports = {};
|
|
5462
|
-
__export(correlation_exports, {
|
|
5463
|
-
getId: () => getId,
|
|
5464
|
-
setHeader: () => setHeader
|
|
5465
|
-
});
|
|
5466
|
-
function getId() {
|
|
5467
|
-
return correlator.getId();
|
|
5468
|
-
}
|
|
5469
|
-
var correlator, setHeader;
|
|
5470
|
-
var init_correlation = __esm({
|
|
5471
|
-
"src/logging/correlation/correlation.ts"() {
|
|
5472
|
-
"use strict";
|
|
5473
|
-
init_constants4();
|
|
5474
|
-
correlator = require("correlation-id");
|
|
5475
|
-
setHeader = (headers) => {
|
|
5476
|
-
const correlationId = correlator.getId();
|
|
5477
|
-
if (correlationId) {
|
|
5478
|
-
headers["x-budibase-correlation-id" /* CORRELATION_ID */] = correlationId;
|
|
5479
|
-
}
|
|
5480
|
-
};
|
|
5481
|
-
}
|
|
5482
|
-
});
|
|
5483
|
-
|
|
5484
|
-
// src/logging/correlation/index.ts
|
|
5485
|
-
var init_correlation2 = __esm({
|
|
5486
|
-
"src/logging/correlation/index.ts"() {
|
|
5487
|
-
"use strict";
|
|
5488
|
-
init_correlation();
|
|
5489
|
-
}
|
|
5490
|
-
});
|
|
5491
|
-
|
|
5492
|
-
// src/objectStore/utils.ts
|
|
5493
|
-
function budibaseTempDir() {
|
|
5494
|
-
return bbTmp;
|
|
5495
|
-
}
|
|
5496
|
-
var import_path, import_os, import_fs2, ObjectStoreBuckets, bbTmp;
|
|
5497
|
-
var init_utils5 = __esm({
|
|
5498
|
-
"src/objectStore/utils.ts"() {
|
|
5499
|
-
"use strict";
|
|
5500
|
-
import_path = require("path");
|
|
5501
|
-
import_os = require("os");
|
|
5502
|
-
import_fs2 = __toESM(require("fs"));
|
|
5503
|
-
init_environment2();
|
|
5504
|
-
ObjectStoreBuckets = {
|
|
5505
|
-
BACKUPS: environment_default.BACKUPS_BUCKET_NAME,
|
|
5506
|
-
APPS: environment_default.APPS_BUCKET_NAME,
|
|
5507
|
-
TEMPLATES: environment_default.TEMPLATES_BUCKET_NAME,
|
|
5508
|
-
GLOBAL: environment_default.GLOBAL_BUCKET_NAME,
|
|
5509
|
-
PLUGINS: environment_default.PLUGIN_BUCKET_NAME
|
|
5510
|
-
};
|
|
5511
|
-
bbTmp = (0, import_path.join)((0, import_os.tmpdir)(), ".budibase");
|
|
5512
|
-
try {
|
|
5513
|
-
import_fs2.default.mkdirSync(bbTmp);
|
|
5514
|
-
} catch (e) {
|
|
5515
|
-
if (e.code !== "EEXIST") {
|
|
5516
|
-
throw e;
|
|
5517
|
-
}
|
|
5518
|
-
}
|
|
5519
|
-
}
|
|
5520
|
-
});
|
|
5521
|
-
|
|
5522
5080
|
// src/objectStore/objectStore.ts
|
|
5523
5081
|
function sanitizeKey(input) {
|
|
5524
5082
|
return sanitize(sanitizeBucket(input)).replace(/\\/g, "/");
|
|
@@ -5827,7 +5385,7 @@ var init_objectStore = __esm({
|
|
|
5827
5385
|
import_path2 = require("path");
|
|
5828
5386
|
import_fs3 = __toESM(require("fs"));
|
|
5829
5387
|
init_environment2();
|
|
5830
|
-
|
|
5388
|
+
init_utils4();
|
|
5831
5389
|
import_uuid2 = require("uuid");
|
|
5832
5390
|
init_db4();
|
|
5833
5391
|
sanitize = require("sanitize-s3-objectkey");
|
|
@@ -6085,7 +5643,7 @@ var init_objectStore2 = __esm({
|
|
|
6085
5643
|
"src/objectStore/index.ts"() {
|
|
6086
5644
|
"use strict";
|
|
6087
5645
|
init_objectStore();
|
|
6088
|
-
|
|
5646
|
+
init_utils4();
|
|
6089
5647
|
init_buckets();
|
|
6090
5648
|
}
|
|
6091
5649
|
});
|
|
@@ -6295,91 +5853,530 @@ var init_logger = __esm({
|
|
|
6295
5853
|
if (!obj.err) {
|
|
6296
5854
|
obj.err = new Error();
|
|
6297
5855
|
}
|
|
6298
|
-
pinoInstance?.trace(obj, msg);
|
|
6299
|
-
};
|
|
6300
|
-
console.debug = (...arg) => {
|
|
6301
|
-
const [obj, msg] = getLogParams2(arg);
|
|
6302
|
-
pinoInstance?.debug(obj, msg);
|
|
6303
|
-
};
|
|
6304
|
-
const getTenantId2 = () => {
|
|
6305
|
-
let tenantId;
|
|
6306
|
-
try {
|
|
6307
|
-
tenantId = getTenantId();
|
|
6308
|
-
} catch (e) {
|
|
5856
|
+
pinoInstance?.trace(obj, msg);
|
|
5857
|
+
};
|
|
5858
|
+
console.debug = (...arg) => {
|
|
5859
|
+
const [obj, msg] = getLogParams2(arg);
|
|
5860
|
+
pinoInstance?.debug(obj, msg);
|
|
5861
|
+
};
|
|
5862
|
+
const getTenantId2 = () => {
|
|
5863
|
+
let tenantId;
|
|
5864
|
+
try {
|
|
5865
|
+
tenantId = getTenantId();
|
|
5866
|
+
} catch (e) {
|
|
5867
|
+
}
|
|
5868
|
+
return tenantId;
|
|
5869
|
+
};
|
|
5870
|
+
const getAppId2 = () => {
|
|
5871
|
+
let appId;
|
|
5872
|
+
try {
|
|
5873
|
+
appId = getAppId();
|
|
5874
|
+
} catch (e) {
|
|
5875
|
+
}
|
|
5876
|
+
return appId;
|
|
5877
|
+
};
|
|
5878
|
+
const getAutomationId2 = () => {
|
|
5879
|
+
let appId;
|
|
5880
|
+
try {
|
|
5881
|
+
appId = getAutomationId();
|
|
5882
|
+
} catch (e) {
|
|
5883
|
+
}
|
|
5884
|
+
return appId;
|
|
5885
|
+
};
|
|
5886
|
+
const getIdentity3 = () => {
|
|
5887
|
+
let identity;
|
|
5888
|
+
try {
|
|
5889
|
+
identity = getIdentity();
|
|
5890
|
+
} catch (e) {
|
|
5891
|
+
}
|
|
5892
|
+
return identity;
|
|
5893
|
+
};
|
|
5894
|
+
}
|
|
5895
|
+
logger = pinoInstance;
|
|
5896
|
+
}
|
|
5897
|
+
});
|
|
5898
|
+
|
|
5899
|
+
// src/logging/alerts.ts
|
|
5900
|
+
function isSuppressed(e) {
|
|
5901
|
+
return e && e["suppressAlert"];
|
|
5902
|
+
}
|
|
5903
|
+
function logAlert(message, e) {
|
|
5904
|
+
if (e && NonErrors.includes(e.name) && isSuppressed(e)) {
|
|
5905
|
+
return;
|
|
5906
|
+
}
|
|
5907
|
+
console.error(`bb-alert: ${message}`, e);
|
|
5908
|
+
}
|
|
5909
|
+
function logAlertWithInfo(message, db, id, error) {
|
|
5910
|
+
message = `${message} - db: ${db} - doc: ${id} - error: `;
|
|
5911
|
+
logAlert(message, error);
|
|
5912
|
+
}
|
|
5913
|
+
function logWarn(message, e) {
|
|
5914
|
+
console.warn(`bb-warn: ${message}`, e);
|
|
5915
|
+
}
|
|
5916
|
+
var NonErrors;
|
|
5917
|
+
var init_alerts = __esm({
|
|
5918
|
+
"src/logging/alerts.ts"() {
|
|
5919
|
+
"use strict";
|
|
5920
|
+
NonErrors = ["AccountError"];
|
|
5921
|
+
}
|
|
5922
|
+
});
|
|
5923
|
+
|
|
5924
|
+
// src/logging/index.ts
|
|
5925
|
+
var logging_exports = {};
|
|
5926
|
+
__export(logging_exports, {
|
|
5927
|
+
correlation: () => correlation_exports,
|
|
5928
|
+
logAlert: () => logAlert,
|
|
5929
|
+
logAlertWithInfo: () => logAlertWithInfo,
|
|
5930
|
+
logWarn: () => logWarn,
|
|
5931
|
+
logger: () => logger,
|
|
5932
|
+
system: () => system_exports
|
|
5933
|
+
});
|
|
5934
|
+
var init_logging = __esm({
|
|
5935
|
+
"src/logging/index.ts"() {
|
|
5936
|
+
"use strict";
|
|
5937
|
+
init_correlation();
|
|
5938
|
+
init_logger();
|
|
5939
|
+
init_alerts();
|
|
5940
|
+
init_system2();
|
|
5941
|
+
}
|
|
5942
|
+
});
|
|
5943
|
+
|
|
5944
|
+
// src/timers/timers.ts
|
|
5945
|
+
function set(callback, period) {
|
|
5946
|
+
const interval = setInterval(callback, period);
|
|
5947
|
+
intervals.push(interval);
|
|
5948
|
+
return interval;
|
|
5949
|
+
}
|
|
5950
|
+
function clear(interval) {
|
|
5951
|
+
const idx = intervals.indexOf(interval);
|
|
5952
|
+
if (idx !== -1) {
|
|
5953
|
+
intervals.splice(idx, 1);
|
|
5954
|
+
}
|
|
5955
|
+
clearInterval(interval);
|
|
5956
|
+
}
|
|
5957
|
+
function cleanup() {
|
|
5958
|
+
for (let interval of intervals) {
|
|
5959
|
+
clearInterval(interval);
|
|
5960
|
+
}
|
|
5961
|
+
intervals = [];
|
|
5962
|
+
}
|
|
5963
|
+
var intervals, ExecutionTimeoutError, ExecutionTimeTracker;
|
|
5964
|
+
var init_timers = __esm({
|
|
5965
|
+
"src/timers/timers.ts"() {
|
|
5966
|
+
"use strict";
|
|
5967
|
+
intervals = [];
|
|
5968
|
+
ExecutionTimeoutError = class extends Error {
|
|
5969
|
+
constructor() {
|
|
5970
|
+
super(...arguments);
|
|
5971
|
+
this.name = "ExecutionTimeoutError";
|
|
5972
|
+
}
|
|
5973
|
+
};
|
|
5974
|
+
ExecutionTimeTracker = class _ExecutionTimeTracker {
|
|
5975
|
+
constructor(limitMs) {
|
|
5976
|
+
this.limitMs = limitMs;
|
|
5977
|
+
this.totalTimeMs = 0;
|
|
5978
|
+
}
|
|
5979
|
+
static withLimit(limitMs) {
|
|
5980
|
+
return new _ExecutionTimeTracker(limitMs);
|
|
5981
|
+
}
|
|
5982
|
+
track(f) {
|
|
5983
|
+
this.checkLimit();
|
|
5984
|
+
const start2 = process.hrtime.bigint();
|
|
5985
|
+
try {
|
|
5986
|
+
return f();
|
|
5987
|
+
} finally {
|
|
5988
|
+
const end2 = process.hrtime.bigint();
|
|
5989
|
+
this.totalTimeMs += Number(end2 - start2) / 1e6;
|
|
5990
|
+
this.checkLimit();
|
|
5991
|
+
}
|
|
5992
|
+
}
|
|
5993
|
+
get elapsedMS() {
|
|
5994
|
+
return this.totalTimeMs;
|
|
5995
|
+
}
|
|
5996
|
+
checkLimit() {
|
|
5997
|
+
if (this.totalTimeMs > this.limitMs) {
|
|
5998
|
+
throw new ExecutionTimeoutError(
|
|
5999
|
+
`Execution time limit of ${this.limitMs}ms exceeded: ${this.totalTimeMs}ms`
|
|
6000
|
+
);
|
|
6001
|
+
}
|
|
6002
|
+
}
|
|
6003
|
+
};
|
|
6004
|
+
}
|
|
6005
|
+
});
|
|
6006
|
+
|
|
6007
|
+
// src/timers/index.ts
|
|
6008
|
+
var timers_exports = {};
|
|
6009
|
+
__export(timers_exports, {
|
|
6010
|
+
ExecutionTimeTracker: () => ExecutionTimeTracker,
|
|
6011
|
+
ExecutionTimeoutError: () => ExecutionTimeoutError,
|
|
6012
|
+
cleanup: () => cleanup,
|
|
6013
|
+
clear: () => clear,
|
|
6014
|
+
set: () => set
|
|
6015
|
+
});
|
|
6016
|
+
var init_timers2 = __esm({
|
|
6017
|
+
"src/timers/index.ts"() {
|
|
6018
|
+
"use strict";
|
|
6019
|
+
init_timers();
|
|
6020
|
+
}
|
|
6021
|
+
});
|
|
6022
|
+
|
|
6023
|
+
// src/redis/redis.ts
|
|
6024
|
+
function pickClient(selectDb) {
|
|
6025
|
+
return CLIENTS[selectDb];
|
|
6026
|
+
}
|
|
6027
|
+
function connectionError(timeout2, err) {
|
|
6028
|
+
if (CLOSED) {
|
|
6029
|
+
return;
|
|
6030
|
+
}
|
|
6031
|
+
CLOSED = true;
|
|
6032
|
+
clearTimeout(timeout2);
|
|
6033
|
+
CONNECTED = false;
|
|
6034
|
+
logAlert("Redis connection failed", err);
|
|
6035
|
+
setTimeout(() => {
|
|
6036
|
+
init2();
|
|
6037
|
+
}, RETRY_PERIOD_MS);
|
|
6038
|
+
}
|
|
6039
|
+
function init2(selectDb = DEFAULT_SELECT_DB) {
|
|
6040
|
+
const RedisCore = environment_default.MOCK_REDIS && MockRedis ? MockRedis : import_ioredis.default;
|
|
6041
|
+
let timeout2;
|
|
6042
|
+
CLOSED = false;
|
|
6043
|
+
let client = pickClient(selectDb);
|
|
6044
|
+
if (client && CONNECTED) {
|
|
6045
|
+
return;
|
|
6046
|
+
}
|
|
6047
|
+
if (environment_default.MOCK_REDIS) {
|
|
6048
|
+
CLIENTS[selectDb] = new RedisCore(getRedisOptions());
|
|
6049
|
+
}
|
|
6050
|
+
timeout2 = setTimeout(() => {
|
|
6051
|
+
if (!CONNECTED) {
|
|
6052
|
+
connectionError(timeout2, "Did not successfully connect in timeout");
|
|
6053
|
+
}
|
|
6054
|
+
}, STARTUP_TIMEOUT_MS);
|
|
6055
|
+
if (client) {
|
|
6056
|
+
client.disconnect();
|
|
6057
|
+
}
|
|
6058
|
+
const { host, port } = getRedisConnectionDetails();
|
|
6059
|
+
const opts = getRedisOptions();
|
|
6060
|
+
if (CLUSTERED) {
|
|
6061
|
+
client = new RedisCore.Cluster([{ host, port }], opts);
|
|
6062
|
+
} else {
|
|
6063
|
+
client = new RedisCore(opts);
|
|
6064
|
+
}
|
|
6065
|
+
client.on("end", (err) => {
|
|
6066
|
+
if (environment_default.isTest()) {
|
|
6067
|
+
return;
|
|
6068
|
+
}
|
|
6069
|
+
connectionError(timeout2, err);
|
|
6070
|
+
});
|
|
6071
|
+
client.on("error", (err) => {
|
|
6072
|
+
connectionError(timeout2, err);
|
|
6073
|
+
});
|
|
6074
|
+
client.on("connect", () => {
|
|
6075
|
+
console.log(`Connected to Redis DB: ${selectDb}`);
|
|
6076
|
+
clearTimeout(timeout2);
|
|
6077
|
+
CONNECTED = true;
|
|
6078
|
+
});
|
|
6079
|
+
CLIENTS[selectDb] = client;
|
|
6080
|
+
}
|
|
6081
|
+
function waitForConnection(selectDb = DEFAULT_SELECT_DB) {
|
|
6082
|
+
return new Promise((resolve) => {
|
|
6083
|
+
if (pickClient(selectDb) == null) {
|
|
6084
|
+
init2();
|
|
6085
|
+
} else if (CONNECTED) {
|
|
6086
|
+
resolve("");
|
|
6087
|
+
return;
|
|
6088
|
+
}
|
|
6089
|
+
const interval = set(() => {
|
|
6090
|
+
if (CONNECTED) {
|
|
6091
|
+
clear(interval);
|
|
6092
|
+
resolve("");
|
|
6093
|
+
}
|
|
6094
|
+
}, 500);
|
|
6095
|
+
});
|
|
6096
|
+
}
|
|
6097
|
+
function promisifyStream(stream2, client) {
|
|
6098
|
+
return new Promise((resolve, reject) => {
|
|
6099
|
+
const outputKeys = /* @__PURE__ */ new Set();
|
|
6100
|
+
stream2.on("data", (keys2) => {
|
|
6101
|
+
keys2.forEach((key) => {
|
|
6102
|
+
outputKeys.add(key);
|
|
6103
|
+
});
|
|
6104
|
+
});
|
|
6105
|
+
stream2.on("error", (err) => {
|
|
6106
|
+
reject(err);
|
|
6107
|
+
});
|
|
6108
|
+
stream2.on("end", async () => {
|
|
6109
|
+
const keysArray = Array.from(outputKeys);
|
|
6110
|
+
try {
|
|
6111
|
+
let getPromises = [];
|
|
6112
|
+
for (let key of keysArray) {
|
|
6113
|
+
getPromises.push(client.get(key));
|
|
6114
|
+
}
|
|
6115
|
+
const jsonArray = await Promise.all(getPromises);
|
|
6116
|
+
resolve(
|
|
6117
|
+
keysArray.map((key) => ({
|
|
6118
|
+
key: removeDbPrefix(key),
|
|
6119
|
+
value: JSON.parse(jsonArray.shift())
|
|
6120
|
+
}))
|
|
6121
|
+
);
|
|
6122
|
+
} catch (err) {
|
|
6123
|
+
reject(err);
|
|
6124
|
+
}
|
|
6125
|
+
});
|
|
6126
|
+
});
|
|
6127
|
+
}
|
|
6128
|
+
var import_ioredis, MockRedis, RETRY_PERIOD_MS, STARTUP_TIMEOUT_MS, CLUSTERED, DEFAULT_SELECT_DB, CLOSED, CLIENTS, CONNECTED, RedisWrapper, redis_default;
|
|
6129
|
+
var init_redis = __esm({
|
|
6130
|
+
"src/redis/redis.ts"() {
|
|
6131
|
+
"use strict";
|
|
6132
|
+
init_environment2();
|
|
6133
|
+
import_ioredis = __toESM(require("ioredis"));
|
|
6134
|
+
init_utils3();
|
|
6135
|
+
init_logging();
|
|
6136
|
+
init_timers2();
|
|
6137
|
+
if (environment_default.MOCK_REDIS) {
|
|
6138
|
+
try {
|
|
6139
|
+
MockRedis = require("ioredis-mock");
|
|
6140
|
+
} catch (err) {
|
|
6141
|
+
console.log("Mock redis unavailable");
|
|
6142
|
+
}
|
|
6143
|
+
}
|
|
6144
|
+
RETRY_PERIOD_MS = 2e3;
|
|
6145
|
+
STARTUP_TIMEOUT_MS = 5e3;
|
|
6146
|
+
CLUSTERED = environment_default.REDIS_CLUSTERED;
|
|
6147
|
+
DEFAULT_SELECT_DB = 0 /* DEFAULT */;
|
|
6148
|
+
CLOSED = false;
|
|
6149
|
+
CLIENTS = {};
|
|
6150
|
+
CONNECTED = false;
|
|
6151
|
+
if (environment_default.MOCK_REDIS) {
|
|
6152
|
+
CONNECTED = true;
|
|
6153
|
+
}
|
|
6154
|
+
RedisWrapper = class {
|
|
6155
|
+
constructor(db, selectDb = null) {
|
|
6156
|
+
this._db = db;
|
|
6157
|
+
this._select = selectDb || DEFAULT_SELECT_DB;
|
|
6158
|
+
}
|
|
6159
|
+
getClient() {
|
|
6160
|
+
return pickClient(this._select);
|
|
6161
|
+
}
|
|
6162
|
+
async init() {
|
|
6163
|
+
CLOSED = false;
|
|
6164
|
+
init2(this._select);
|
|
6165
|
+
await waitForConnection(this._select);
|
|
6166
|
+
if (this._select && !environment_default.isTest()) {
|
|
6167
|
+
this.getClient().select(this._select);
|
|
6168
|
+
}
|
|
6169
|
+
return this;
|
|
6170
|
+
}
|
|
6171
|
+
async finish() {
|
|
6172
|
+
CLOSED = true;
|
|
6173
|
+
this.getClient().disconnect();
|
|
6174
|
+
}
|
|
6175
|
+
async scan(key = "") {
|
|
6176
|
+
const db = this._db;
|
|
6177
|
+
key = `${db}${SEPARATOR2}${key}`;
|
|
6178
|
+
let stream2;
|
|
6179
|
+
if (CLUSTERED) {
|
|
6180
|
+
let node = this.getClient().nodes("master");
|
|
6181
|
+
stream2 = node[0].scanStream({ match: key + "*", count: 100 });
|
|
6182
|
+
} else {
|
|
6183
|
+
stream2 = this.getClient().scanStream({ match: key + "*", count: 100 });
|
|
6184
|
+
}
|
|
6185
|
+
return promisifyStream(stream2, this.getClient());
|
|
6186
|
+
}
|
|
6187
|
+
async keys(pattern) {
|
|
6188
|
+
const db = this._db;
|
|
6189
|
+
return this.getClient().keys(addDbPrefix(db, pattern));
|
|
6190
|
+
}
|
|
6191
|
+
async exists(key) {
|
|
6192
|
+
const db = this._db;
|
|
6193
|
+
return await this.getClient().exists(addDbPrefix(db, key));
|
|
6194
|
+
}
|
|
6195
|
+
async get(key) {
|
|
6196
|
+
const db = this._db;
|
|
6197
|
+
let response = await this.getClient().get(addDbPrefix(db, key));
|
|
6198
|
+
if (response != null && response.key) {
|
|
6199
|
+
response.key = key;
|
|
6309
6200
|
}
|
|
6310
|
-
return tenantId;
|
|
6311
|
-
};
|
|
6312
|
-
const getAppId2 = () => {
|
|
6313
|
-
let appId;
|
|
6314
6201
|
try {
|
|
6315
|
-
|
|
6316
|
-
} catch (
|
|
6202
|
+
return JSON.parse(response);
|
|
6203
|
+
} catch (err) {
|
|
6204
|
+
return response;
|
|
6317
6205
|
}
|
|
6318
|
-
|
|
6319
|
-
|
|
6320
|
-
|
|
6321
|
-
|
|
6322
|
-
|
|
6323
|
-
appId = getAutomationId();
|
|
6324
|
-
} catch (e) {
|
|
6206
|
+
}
|
|
6207
|
+
async bulkGet(keys2) {
|
|
6208
|
+
const db = this._db;
|
|
6209
|
+
if (keys2.length === 0) {
|
|
6210
|
+
return {};
|
|
6325
6211
|
}
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
6332
|
-
|
|
6212
|
+
const prefixedKeys = keys2.map((key) => addDbPrefix(db, key));
|
|
6213
|
+
let response = await this.getClient().mget(prefixedKeys);
|
|
6214
|
+
if (Array.isArray(response)) {
|
|
6215
|
+
let final = {};
|
|
6216
|
+
let count = 0;
|
|
6217
|
+
for (let result of response) {
|
|
6218
|
+
if (result) {
|
|
6219
|
+
let parsed;
|
|
6220
|
+
try {
|
|
6221
|
+
parsed = JSON.parse(result);
|
|
6222
|
+
} catch (err) {
|
|
6223
|
+
parsed = result;
|
|
6224
|
+
}
|
|
6225
|
+
final[keys2[count]] = parsed;
|
|
6226
|
+
}
|
|
6227
|
+
count++;
|
|
6228
|
+
}
|
|
6229
|
+
return final;
|
|
6230
|
+
} else {
|
|
6231
|
+
throw new Error(`Invalid response: ${response}`);
|
|
6333
6232
|
}
|
|
6334
|
-
|
|
6335
|
-
|
|
6336
|
-
|
|
6337
|
-
|
|
6233
|
+
}
|
|
6234
|
+
async store(key, value, expirySeconds = null) {
|
|
6235
|
+
const db = this._db;
|
|
6236
|
+
if (typeof value === "object") {
|
|
6237
|
+
value = JSON.stringify(value);
|
|
6238
|
+
}
|
|
6239
|
+
const prefixedKey = addDbPrefix(db, key);
|
|
6240
|
+
await this.getClient().set(prefixedKey, value);
|
|
6241
|
+
if (expirySeconds) {
|
|
6242
|
+
await this.getClient().expire(prefixedKey, expirySeconds);
|
|
6243
|
+
}
|
|
6244
|
+
}
|
|
6245
|
+
async getTTL(key) {
|
|
6246
|
+
const db = this._db;
|
|
6247
|
+
const prefixedKey = addDbPrefix(db, key);
|
|
6248
|
+
return this.getClient().ttl(prefixedKey);
|
|
6249
|
+
}
|
|
6250
|
+
async setExpiry(key, expirySeconds) {
|
|
6251
|
+
const db = this._db;
|
|
6252
|
+
const prefixedKey = addDbPrefix(db, key);
|
|
6253
|
+
await this.getClient().expire(prefixedKey, expirySeconds);
|
|
6254
|
+
}
|
|
6255
|
+
async delete(key) {
|
|
6256
|
+
const db = this._db;
|
|
6257
|
+
await this.getClient().del(addDbPrefix(db, key));
|
|
6258
|
+
}
|
|
6259
|
+
async clear() {
|
|
6260
|
+
let items = await this.scan();
|
|
6261
|
+
await Promise.all(items.map((obj) => this.delete(obj.key)));
|
|
6262
|
+
}
|
|
6263
|
+
};
|
|
6264
|
+
redis_default = RedisWrapper;
|
|
6338
6265
|
}
|
|
6339
6266
|
});
|
|
6340
6267
|
|
|
6341
|
-
// src/
|
|
6342
|
-
|
|
6343
|
-
|
|
6268
|
+
// src/redis/init.ts
|
|
6269
|
+
var init_exports = {};
|
|
6270
|
+
__export(init_exports, {
|
|
6271
|
+
getAppClient: () => getAppClient,
|
|
6272
|
+
getCacheClient: () => getCacheClient,
|
|
6273
|
+
getInviteClient: () => getInviteClient,
|
|
6274
|
+
getLockClient: () => getLockClient,
|
|
6275
|
+
getPasswordResetClient: () => getPasswordResetClient,
|
|
6276
|
+
getSessionClient: () => getSessionClient,
|
|
6277
|
+
getSocketClient: () => getSocketClient,
|
|
6278
|
+
getUserClient: () => getUserClient,
|
|
6279
|
+
getWritethroughClient: () => getWritethroughClient,
|
|
6280
|
+
init: () => init3,
|
|
6281
|
+
shutdown: () => shutdown
|
|
6282
|
+
});
|
|
6283
|
+
async function init3() {
|
|
6284
|
+
userClient = await new redis_default("users" /* USER_CACHE */).init();
|
|
6285
|
+
sessionClient = await new redis_default("session" /* SESSIONS */).init();
|
|
6286
|
+
appClient = await new redis_default("appMetadata" /* APP_METADATA */).init();
|
|
6287
|
+
cacheClient = await new redis_default("data_cache" /* GENERIC_CACHE */).init();
|
|
6288
|
+
lockClient = await new redis_default("locks" /* LOCKS */).init();
|
|
6289
|
+
writethroughClient = await new redis_default("writeThrough" /* WRITE_THROUGH */).init();
|
|
6290
|
+
inviteClient = await new redis_default("invitation" /* INVITATIONS */).init();
|
|
6291
|
+
passwordResetClient = await new redis_default("pwReset" /* PW_RESETS */).init();
|
|
6292
|
+
socketClient = await new redis_default(
|
|
6293
|
+
"socket_io" /* SOCKET_IO */,
|
|
6294
|
+
1 /* SOCKET_IO */
|
|
6295
|
+
).init();
|
|
6344
6296
|
}
|
|
6345
|
-
function
|
|
6346
|
-
if (
|
|
6347
|
-
|
|
6297
|
+
async function shutdown() {
|
|
6298
|
+
if (userClient)
|
|
6299
|
+
await userClient.finish();
|
|
6300
|
+
if (sessionClient)
|
|
6301
|
+
await sessionClient.finish();
|
|
6302
|
+
if (appClient)
|
|
6303
|
+
await appClient.finish();
|
|
6304
|
+
if (cacheClient)
|
|
6305
|
+
await cacheClient.finish();
|
|
6306
|
+
if (writethroughClient)
|
|
6307
|
+
await writethroughClient.finish();
|
|
6308
|
+
if (lockClient)
|
|
6309
|
+
await lockClient.finish();
|
|
6310
|
+
if (inviteClient)
|
|
6311
|
+
await inviteClient.finish();
|
|
6312
|
+
if (passwordResetClient)
|
|
6313
|
+
await passwordResetClient.finish();
|
|
6314
|
+
if (socketClient)
|
|
6315
|
+
await socketClient.finish();
|
|
6316
|
+
}
|
|
6317
|
+
async function getUserClient() {
|
|
6318
|
+
if (!userClient) {
|
|
6319
|
+
await init3();
|
|
6348
6320
|
}
|
|
6349
|
-
|
|
6321
|
+
return userClient;
|
|
6350
6322
|
}
|
|
6351
|
-
function
|
|
6352
|
-
|
|
6353
|
-
|
|
6323
|
+
async function getSessionClient() {
|
|
6324
|
+
if (!sessionClient) {
|
|
6325
|
+
await init3();
|
|
6326
|
+
}
|
|
6327
|
+
return sessionClient;
|
|
6354
6328
|
}
|
|
6355
|
-
function
|
|
6356
|
-
|
|
6329
|
+
async function getAppClient() {
|
|
6330
|
+
if (!appClient) {
|
|
6331
|
+
await init3();
|
|
6332
|
+
}
|
|
6333
|
+
return appClient;
|
|
6357
6334
|
}
|
|
6358
|
-
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
"use strict";
|
|
6362
|
-
NonErrors = ["AccountError"];
|
|
6335
|
+
async function getCacheClient() {
|
|
6336
|
+
if (!cacheClient) {
|
|
6337
|
+
await init3();
|
|
6363
6338
|
}
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6367
|
-
|
|
6368
|
-
|
|
6369
|
-
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
}
|
|
6376
|
-
|
|
6377
|
-
|
|
6339
|
+
return cacheClient;
|
|
6340
|
+
}
|
|
6341
|
+
async function getWritethroughClient() {
|
|
6342
|
+
if (!writethroughClient) {
|
|
6343
|
+
await init3();
|
|
6344
|
+
}
|
|
6345
|
+
return writethroughClient;
|
|
6346
|
+
}
|
|
6347
|
+
async function getLockClient() {
|
|
6348
|
+
if (!lockClient) {
|
|
6349
|
+
await init3();
|
|
6350
|
+
}
|
|
6351
|
+
return lockClient;
|
|
6352
|
+
}
|
|
6353
|
+
async function getSocketClient() {
|
|
6354
|
+
if (!socketClient) {
|
|
6355
|
+
await init3();
|
|
6356
|
+
}
|
|
6357
|
+
return socketClient;
|
|
6358
|
+
}
|
|
6359
|
+
async function getInviteClient() {
|
|
6360
|
+
if (!inviteClient) {
|
|
6361
|
+
await init3();
|
|
6362
|
+
}
|
|
6363
|
+
return inviteClient;
|
|
6364
|
+
}
|
|
6365
|
+
async function getPasswordResetClient() {
|
|
6366
|
+
if (!passwordResetClient) {
|
|
6367
|
+
await init3();
|
|
6368
|
+
}
|
|
6369
|
+
return passwordResetClient;
|
|
6370
|
+
}
|
|
6371
|
+
var userClient, sessionClient, appClient, cacheClient, writethroughClient, lockClient, socketClient, inviteClient, passwordResetClient;
|
|
6372
|
+
var init_init = __esm({
|
|
6373
|
+
"src/redis/init.ts"() {
|
|
6378
6374
|
"use strict";
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6382
|
-
|
|
6375
|
+
init_redis();
|
|
6376
|
+
init_utils3();
|
|
6377
|
+
process.on("exit", async () => {
|
|
6378
|
+
await shutdown();
|
|
6379
|
+
});
|
|
6383
6380
|
}
|
|
6384
6381
|
});
|
|
6385
6382
|
|
|
@@ -8309,7 +8306,7 @@ function createQueue(jobQueue, opts = {}) {
|
|
|
8309
8306
|
if (!cleanupInterval && !environment_default.isTest()) {
|
|
8310
8307
|
cleanupInterval = set(cleanup2, CLEANUP_PERIOD_MS);
|
|
8311
8308
|
cleanup2().catch((err) => {
|
|
8312
|
-
console.error(`Unable to cleanup
|
|
8309
|
+
console.error(`Unable to cleanup ${jobQueue} initially - ${err}`);
|
|
8313
8310
|
});
|
|
8314
8311
|
}
|
|
8315
8312
|
return queue;
|