@budibase/backend-core 2.9.30-alpha.1 → 2.9.30-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/dist/index.js +262 -334
- package/dist/index.js.map +4 -4
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +4 -4
- package/dist/plugins.js +1 -1
- package/dist/plugins.js.map +2 -2
- package/dist/plugins.js.meta.json +1 -1
- package/dist/tests.js +217 -264
- package/dist/tests.js.map +4 -4
- package/dist/tests.js.meta.json +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -29,28 +29,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
mod
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
-
var __accessCheck = (obj, member, msg) => {
|
|
33
|
-
if (!member.has(obj))
|
|
34
|
-
throw TypeError("Cannot " + msg);
|
|
35
|
-
};
|
|
36
|
-
var __privateGet = (obj, member, getter) => {
|
|
37
|
-
__accessCheck(obj, member, "read from private field");
|
|
38
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
39
|
-
};
|
|
40
|
-
var __privateAdd = (obj, member, value) => {
|
|
41
|
-
if (member.has(obj))
|
|
42
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
43
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
44
|
-
};
|
|
45
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
46
|
-
__accessCheck(obj, member, "write to private field");
|
|
47
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
48
|
-
return value;
|
|
49
|
-
};
|
|
50
|
-
var __privateMethod = (obj, member, method) => {
|
|
51
|
-
__accessCheck(obj, member, "access private method");
|
|
52
|
-
return method;
|
|
53
|
-
};
|
|
54
32
|
|
|
55
33
|
// ../types/src/sdk/automations/index.ts
|
|
56
34
|
var init_automations = __esm({
|
|
@@ -705,13 +683,19 @@ var init_permissions = __esm({
|
|
|
705
683
|
PermissionType2["WEBHOOK"] = "webhook";
|
|
706
684
|
PermissionType2["BUILDER"] = "builder";
|
|
707
685
|
PermissionType2["GLOBAL_BUILDER"] = "globalBuilder";
|
|
708
|
-
PermissionType2["VIEW"] = "view";
|
|
709
686
|
PermissionType2["QUERY"] = "query";
|
|
710
687
|
return PermissionType2;
|
|
711
688
|
})(PermissionType || {});
|
|
712
689
|
}
|
|
713
690
|
});
|
|
714
691
|
|
|
692
|
+
// ../types/src/sdk/row.ts
|
|
693
|
+
var init_row = __esm({
|
|
694
|
+
"../types/src/sdk/row.ts"() {
|
|
695
|
+
"use strict";
|
|
696
|
+
}
|
|
697
|
+
});
|
|
698
|
+
|
|
715
699
|
// ../types/src/sdk/index.ts
|
|
716
700
|
var init_sdk = __esm({
|
|
717
701
|
"../types/src/sdk/index.ts"() {
|
|
@@ -737,6 +721,7 @@ var init_sdk = __esm({
|
|
|
737
721
|
init_cli();
|
|
738
722
|
init_websocket();
|
|
739
723
|
init_permissions();
|
|
724
|
+
init_row();
|
|
740
725
|
}
|
|
741
726
|
});
|
|
742
727
|
|
|
@@ -966,7 +951,7 @@ var init_document = __esm({
|
|
|
966
951
|
});
|
|
967
952
|
|
|
968
953
|
// ../types/src/documents/app/row.ts
|
|
969
|
-
var
|
|
954
|
+
var init_row2 = __esm({
|
|
970
955
|
"../types/src/documents/app/row.ts"() {
|
|
971
956
|
"use strict";
|
|
972
957
|
}
|
|
@@ -1021,7 +1006,7 @@ var init_app3 = __esm({
|
|
|
1021
1006
|
init_screen2();
|
|
1022
1007
|
init_view2();
|
|
1023
1008
|
init_document();
|
|
1024
|
-
|
|
1009
|
+
init_row2();
|
|
1025
1010
|
init_user4();
|
|
1026
1011
|
init_backup2();
|
|
1027
1012
|
init_webhook();
|
|
@@ -1301,7 +1286,7 @@ var init_datasource3 = __esm({
|
|
|
1301
1286
|
});
|
|
1302
1287
|
|
|
1303
1288
|
// ../types/src/api/web/app/row.ts
|
|
1304
|
-
var
|
|
1289
|
+
var init_row3 = __esm({
|
|
1305
1290
|
"../types/src/api/web/app/row.ts"() {
|
|
1306
1291
|
"use strict";
|
|
1307
1292
|
}
|
|
@@ -1334,7 +1319,7 @@ var init_app4 = __esm({
|
|
|
1334
1319
|
"use strict";
|
|
1335
1320
|
init_backup3();
|
|
1336
1321
|
init_datasource3();
|
|
1337
|
-
|
|
1322
|
+
init_row3();
|
|
1338
1323
|
init_view3();
|
|
1339
1324
|
init_rows2();
|
|
1340
1325
|
init_table4();
|
|
@@ -1880,12 +1865,15 @@ var init_environment2 = __esm({
|
|
|
1880
1865
|
});
|
|
1881
1866
|
|
|
1882
1867
|
// src/context/Context.ts
|
|
1883
|
-
var import_async_hooks,
|
|
1868
|
+
var import_async_hooks, Context;
|
|
1884
1869
|
var init_Context = __esm({
|
|
1885
1870
|
"src/context/Context.ts"() {
|
|
1886
1871
|
"use strict";
|
|
1887
1872
|
import_async_hooks = require("async_hooks");
|
|
1888
|
-
|
|
1873
|
+
Context = class _Context {
|
|
1874
|
+
static {
|
|
1875
|
+
this.storage = new import_async_hooks.AsyncLocalStorage();
|
|
1876
|
+
}
|
|
1889
1877
|
static run(context, func) {
|
|
1890
1878
|
return _Context.storage.run(context, () => func());
|
|
1891
1879
|
}
|
|
@@ -1893,8 +1881,6 @@ var init_Context = __esm({
|
|
|
1893
1881
|
return _Context.storage.getStore();
|
|
1894
1882
|
}
|
|
1895
1883
|
};
|
|
1896
|
-
_Context.storage = new import_async_hooks.AsyncLocalStorage();
|
|
1897
|
-
Context = _Context;
|
|
1898
1884
|
}
|
|
1899
1885
|
});
|
|
1900
1886
|
|
|
@@ -1936,7 +1922,7 @@ function getProdAppID(appId) {
|
|
|
1936
1922
|
return `${APP_PREFIX}${rest}`;
|
|
1937
1923
|
}
|
|
1938
1924
|
function extractAppUUID(id) {
|
|
1939
|
-
const split =
|
|
1925
|
+
const split = id?.split("_") || [];
|
|
1940
1926
|
return split.length ? split[split.length - 1] : null;
|
|
1941
1927
|
}
|
|
1942
1928
|
var NO_APP_ERROR, getDevAppID;
|
|
@@ -1956,18 +1942,17 @@ var init_connections = __esm({
|
|
|
1956
1942
|
"use strict";
|
|
1957
1943
|
init_environment2();
|
|
1958
1944
|
getCouchInfo = (connection) => {
|
|
1959
|
-
var _a, _b;
|
|
1960
1945
|
const urlInfo = getUrlInfo(connection);
|
|
1961
1946
|
let username;
|
|
1962
1947
|
let password;
|
|
1963
|
-
if (
|
|
1948
|
+
if (urlInfo.auth?.username) {
|
|
1964
1949
|
username = urlInfo.auth.username;
|
|
1965
1950
|
} else if (environment_default.COUCH_DB_USERNAME) {
|
|
1966
1951
|
username = environment_default.COUCH_DB_USERNAME;
|
|
1967
1952
|
} else if (!environment_default.isTest()) {
|
|
1968
1953
|
throw new Error("CouchDB username not set");
|
|
1969
1954
|
}
|
|
1970
|
-
if (
|
|
1955
|
+
if (urlInfo.auth?.password) {
|
|
1971
1956
|
password = urlInfo.auth.password;
|
|
1972
1957
|
} else if (environment_default.COUCH_DB_PASSWORD) {
|
|
1973
1958
|
password = environment_default.COUCH_DB_PASSWORD;
|
|
@@ -2226,8 +2211,7 @@ var init_DatabaseImpl = __esm({
|
|
|
2226
2211
|
return this.instanceNano || _DatabaseImpl.nano;
|
|
2227
2212
|
}
|
|
2228
2213
|
async checkSetup() {
|
|
2229
|
-
|
|
2230
|
-
let shouldCreate = !((_a = this.pouchOpts) == null ? void 0 : _a.skip_setup);
|
|
2214
|
+
let shouldCreate = !this.pouchOpts?.skip_setup;
|
|
2231
2215
|
let exists2 = await this.exists();
|
|
2232
2216
|
if (!shouldCreate && !exists2) {
|
|
2233
2217
|
throw new Error("DB does not exist");
|
|
@@ -2303,7 +2287,7 @@ var init_DatabaseImpl = __esm({
|
|
|
2303
2287
|
document.createdAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2304
2288
|
}
|
|
2305
2289
|
document.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
2306
|
-
if (
|
|
2290
|
+
if (opts?.force && document._id) {
|
|
2307
2291
|
try {
|
|
2308
2292
|
const existing = await this.get(document._id);
|
|
2309
2293
|
if (existing) {
|
|
@@ -2467,7 +2451,7 @@ function isMultiTenant() {
|
|
|
2467
2451
|
}
|
|
2468
2452
|
function isTenantIdSet() {
|
|
2469
2453
|
const context = Context.get();
|
|
2470
|
-
return !!
|
|
2454
|
+
return !!context?.tenantId;
|
|
2471
2455
|
}
|
|
2472
2456
|
function isTenancyEnabled() {
|
|
2473
2457
|
return environment_default.MULTI_TENANCY;
|
|
@@ -2566,7 +2550,7 @@ async function doInIdentityContext(identity, task) {
|
|
|
2566
2550
|
function getIdentity() {
|
|
2567
2551
|
try {
|
|
2568
2552
|
const context = Context.get();
|
|
2569
|
-
return context
|
|
2553
|
+
return context?.identity;
|
|
2570
2554
|
} catch (e) {
|
|
2571
2555
|
}
|
|
2572
2556
|
}
|
|
@@ -2575,7 +2559,7 @@ function getTenantId() {
|
|
|
2575
2559
|
return DEFAULT_TENANT_ID;
|
|
2576
2560
|
}
|
|
2577
2561
|
const context = Context.get();
|
|
2578
|
-
const tenantId = context
|
|
2562
|
+
const tenantId = context?.tenantId;
|
|
2579
2563
|
if (!tenantId) {
|
|
2580
2564
|
throw new Error("Tenant id not found");
|
|
2581
2565
|
}
|
|
@@ -2583,11 +2567,11 @@ function getTenantId() {
|
|
|
2583
2567
|
}
|
|
2584
2568
|
function getAutomationId() {
|
|
2585
2569
|
const context = Context.get();
|
|
2586
|
-
return context
|
|
2570
|
+
return context?.automationId;
|
|
2587
2571
|
}
|
|
2588
2572
|
function getAppId() {
|
|
2589
2573
|
const context = Context.get();
|
|
2590
|
-
const foundId = context
|
|
2574
|
+
const foundId = context?.appId;
|
|
2591
2575
|
if (!foundId && environment_default.isTest() && TEST_APP_ID) {
|
|
2592
2576
|
return TEST_APP_ID;
|
|
2593
2577
|
} else {
|
|
@@ -2622,7 +2606,7 @@ function getGlobalDB() {
|
|
|
2622
2606
|
if (!context || environment_default.MULTI_TENANCY && !context.tenantId) {
|
|
2623
2607
|
throw new Error("Global DB not found");
|
|
2624
2608
|
}
|
|
2625
|
-
return getDB(baseGlobalDBName(context
|
|
2609
|
+
return getDB(baseGlobalDBName(context?.tenantId));
|
|
2626
2610
|
}
|
|
2627
2611
|
function getAuditLogsDB() {
|
|
2628
2612
|
if (!getTenantId()) {
|
|
@@ -2650,7 +2634,7 @@ function getDevAppDB(opts) {
|
|
|
2650
2634
|
}
|
|
2651
2635
|
function isScim() {
|
|
2652
2636
|
const context = Context.get();
|
|
2653
|
-
const scimCall = context
|
|
2637
|
+
const scimCall = context?.isScim;
|
|
2654
2638
|
return !!scimCall;
|
|
2655
2639
|
}
|
|
2656
2640
|
var TEST_APP_ID, getProdAppId;
|
|
@@ -3501,7 +3485,7 @@ function getGlobalUserParams(globalId, otherProps = {}) {
|
|
|
3501
3485
|
if (!globalId) {
|
|
3502
3486
|
globalId = "";
|
|
3503
3487
|
}
|
|
3504
|
-
const startkey = otherProps
|
|
3488
|
+
const startkey = otherProps?.startkey;
|
|
3505
3489
|
return {
|
|
3506
3490
|
...otherProps,
|
|
3507
3491
|
// need to include this incase pagination
|
|
@@ -3634,10 +3618,7 @@ async function getAllApps({
|
|
|
3634
3618
|
} else {
|
|
3635
3619
|
const response = await Promise.allSettled(appPromises);
|
|
3636
3620
|
const apps = response.filter(
|
|
3637
|
-
(result) =>
|
|
3638
|
-
var _a;
|
|
3639
|
-
return result.status === "fulfilled" && ((_a = result.value) == null ? void 0 : _a.state) !== "invalid" /* INVALID */;
|
|
3640
|
-
}
|
|
3621
|
+
(result) => result.status === "fulfilled" && result.value?.state !== "invalid" /* INVALID */
|
|
3641
3622
|
).map(({ value }) => value);
|
|
3642
3623
|
if (!all) {
|
|
3643
3624
|
return apps.filter((app) => {
|
|
@@ -3699,7 +3680,7 @@ function pagination(data, pageSize, {
|
|
|
3699
3680
|
const hasNextPage = data.length > pageSize;
|
|
3700
3681
|
let nextPage = void 0;
|
|
3701
3682
|
if (!getKey) {
|
|
3702
|
-
getKey = (doc) => property ? doc
|
|
3683
|
+
getKey = (doc) => property ? doc?.[property] : doc?._id;
|
|
3703
3684
|
}
|
|
3704
3685
|
if (hasNextPage) {
|
|
3705
3686
|
nextPage = getKey(data[pageSize]);
|
|
@@ -3850,7 +3831,7 @@ var init_views = __esm({
|
|
|
3850
3831
|
const docs = rows.map(
|
|
3851
3832
|
(row) => params2.include_docs ? row.doc : row.value
|
|
3852
3833
|
);
|
|
3853
|
-
if (opts
|
|
3834
|
+
if (opts?.arrayResponse) {
|
|
3854
3835
|
return docs;
|
|
3855
3836
|
} else {
|
|
3856
3837
|
return docs.length <= 1 ? docs[0] : docs;
|
|
@@ -4073,7 +4054,7 @@ async function fullSearch(dbName, index2, query, params2) {
|
|
|
4073
4054
|
const rows = await recursiveSearch(dbName, index2, query, params2);
|
|
4074
4055
|
return { rows };
|
|
4075
4056
|
}
|
|
4076
|
-
var import_node_fetch2, QUERY_START_REGEX,
|
|
4057
|
+
var import_node_fetch2, QUERY_START_REGEX, QueryBuilder;
|
|
4077
4058
|
var init_lucene = __esm({
|
|
4078
4059
|
"src/db/lucene.ts"() {
|
|
4079
4060
|
"use strict";
|
|
@@ -4081,31 +4062,27 @@ var init_lucene = __esm({
|
|
|
4081
4062
|
init_couch();
|
|
4082
4063
|
init_src();
|
|
4083
4064
|
QUERY_START_REGEX = /\d[0-9]*:/g;
|
|
4084
|
-
|
|
4065
|
+
QueryBuilder = class _QueryBuilder {
|
|
4066
|
+
#dbName;
|
|
4067
|
+
#index;
|
|
4068
|
+
#query;
|
|
4069
|
+
#limit;
|
|
4070
|
+
#sort;
|
|
4071
|
+
#bookmark;
|
|
4072
|
+
#sortOrder;
|
|
4073
|
+
#sortType;
|
|
4074
|
+
#includeDocs;
|
|
4075
|
+
#version;
|
|
4076
|
+
#indexBuilder;
|
|
4077
|
+
#noEscaping = false;
|
|
4078
|
+
#skip;
|
|
4079
|
+
static {
|
|
4080
|
+
this.maxLimit = 200;
|
|
4081
|
+
}
|
|
4085
4082
|
constructor(dbName, index2, base) {
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
* page has been met.
|
|
4090
|
-
*/
|
|
4091
|
-
__privateAdd(this, _skipItems);
|
|
4092
|
-
__privateAdd(this, _execute);
|
|
4093
|
-
__privateAdd(this, _dbName, void 0);
|
|
4094
|
-
__privateAdd(this, _index, void 0);
|
|
4095
|
-
__privateAdd(this, _query, void 0);
|
|
4096
|
-
__privateAdd(this, _limit, void 0);
|
|
4097
|
-
__privateAdd(this, _sort, void 0);
|
|
4098
|
-
__privateAdd(this, _bookmark, void 0);
|
|
4099
|
-
__privateAdd(this, _sortOrder, void 0);
|
|
4100
|
-
__privateAdd(this, _sortType, void 0);
|
|
4101
|
-
__privateAdd(this, _includeDocs, void 0);
|
|
4102
|
-
__privateAdd(this, _version, void 0);
|
|
4103
|
-
__privateAdd(this, _indexBuilder, void 0);
|
|
4104
|
-
__privateAdd(this, _noEscaping, false);
|
|
4105
|
-
__privateAdd(this, _skip, void 0);
|
|
4106
|
-
__privateSet(this, _dbName, dbName);
|
|
4107
|
-
__privateSet(this, _index, index2);
|
|
4108
|
-
__privateSet(this, _query, {
|
|
4083
|
+
this.#dbName = dbName;
|
|
4084
|
+
this.#index = index2;
|
|
4085
|
+
this.#query = {
|
|
4109
4086
|
allOr: false,
|
|
4110
4087
|
onEmptyFilter: "all" /* RETURN_ALL */,
|
|
4111
4088
|
string: {},
|
|
@@ -4120,127 +4097,127 @@ var init_lucene = __esm({
|
|
|
4120
4097
|
notContains: {},
|
|
4121
4098
|
containsAny: {},
|
|
4122
4099
|
...base
|
|
4123
|
-
}
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4100
|
+
};
|
|
4101
|
+
this.#limit = 50;
|
|
4102
|
+
this.#sortOrder = "ascending";
|
|
4103
|
+
this.#sortType = "string";
|
|
4104
|
+
this.#includeDocs = true;
|
|
4128
4105
|
}
|
|
4129
4106
|
disableEscaping() {
|
|
4130
|
-
|
|
4107
|
+
this.#noEscaping = true;
|
|
4131
4108
|
return this;
|
|
4132
4109
|
}
|
|
4133
4110
|
setIndexBuilder(builderFn) {
|
|
4134
|
-
|
|
4111
|
+
this.#indexBuilder = builderFn;
|
|
4135
4112
|
return this;
|
|
4136
4113
|
}
|
|
4137
4114
|
setVersion(version) {
|
|
4138
4115
|
if (version != null) {
|
|
4139
|
-
|
|
4116
|
+
this.#version = version;
|
|
4140
4117
|
}
|
|
4141
4118
|
return this;
|
|
4142
4119
|
}
|
|
4143
4120
|
setTable(tableId) {
|
|
4144
|
-
|
|
4121
|
+
this.#query.equal.tableId = tableId;
|
|
4145
4122
|
return this;
|
|
4146
4123
|
}
|
|
4147
4124
|
setLimit(limit) {
|
|
4148
4125
|
if (limit != null) {
|
|
4149
|
-
|
|
4126
|
+
this.#limit = limit;
|
|
4150
4127
|
}
|
|
4151
4128
|
return this;
|
|
4152
4129
|
}
|
|
4153
4130
|
setSort(sort) {
|
|
4154
4131
|
if (sort != null) {
|
|
4155
|
-
|
|
4132
|
+
this.#sort = sort;
|
|
4156
4133
|
}
|
|
4157
4134
|
return this;
|
|
4158
4135
|
}
|
|
4159
4136
|
setSortOrder(sortOrder) {
|
|
4160
4137
|
if (sortOrder != null) {
|
|
4161
|
-
|
|
4138
|
+
this.#sortOrder = sortOrder;
|
|
4162
4139
|
}
|
|
4163
4140
|
return this;
|
|
4164
4141
|
}
|
|
4165
4142
|
setSortType(sortType) {
|
|
4166
4143
|
if (sortType != null) {
|
|
4167
|
-
|
|
4144
|
+
this.#sortType = sortType;
|
|
4168
4145
|
}
|
|
4169
4146
|
return this;
|
|
4170
4147
|
}
|
|
4171
4148
|
setBookmark(bookmark) {
|
|
4172
4149
|
if (bookmark != null) {
|
|
4173
|
-
|
|
4150
|
+
this.#bookmark = bookmark;
|
|
4174
4151
|
}
|
|
4175
4152
|
return this;
|
|
4176
4153
|
}
|
|
4177
4154
|
setSkip(skip) {
|
|
4178
|
-
|
|
4155
|
+
this.#skip = skip;
|
|
4179
4156
|
return this;
|
|
4180
4157
|
}
|
|
4181
4158
|
excludeDocs() {
|
|
4182
|
-
|
|
4159
|
+
this.#includeDocs = false;
|
|
4183
4160
|
return this;
|
|
4184
4161
|
}
|
|
4185
4162
|
includeDocs() {
|
|
4186
|
-
|
|
4163
|
+
this.#includeDocs = true;
|
|
4187
4164
|
return this;
|
|
4188
4165
|
}
|
|
4189
4166
|
addString(key, partial) {
|
|
4190
|
-
|
|
4167
|
+
this.#query.string[key] = partial;
|
|
4191
4168
|
return this;
|
|
4192
4169
|
}
|
|
4193
4170
|
addFuzzy(key, fuzzy) {
|
|
4194
|
-
|
|
4171
|
+
this.#query.fuzzy[key] = fuzzy;
|
|
4195
4172
|
return this;
|
|
4196
4173
|
}
|
|
4197
4174
|
addRange(key, low, high) {
|
|
4198
|
-
|
|
4175
|
+
this.#query.range[key] = {
|
|
4199
4176
|
low,
|
|
4200
4177
|
high
|
|
4201
4178
|
};
|
|
4202
4179
|
return this;
|
|
4203
4180
|
}
|
|
4204
4181
|
addEqual(key, value) {
|
|
4205
|
-
|
|
4182
|
+
this.#query.equal[key] = value;
|
|
4206
4183
|
return this;
|
|
4207
4184
|
}
|
|
4208
4185
|
addNotEqual(key, value) {
|
|
4209
|
-
|
|
4186
|
+
this.#query.notEqual[key] = value;
|
|
4210
4187
|
return this;
|
|
4211
4188
|
}
|
|
4212
4189
|
addEmpty(key, value) {
|
|
4213
|
-
|
|
4190
|
+
this.#query.empty[key] = value;
|
|
4214
4191
|
return this;
|
|
4215
4192
|
}
|
|
4216
4193
|
addNotEmpty(key, value) {
|
|
4217
|
-
|
|
4194
|
+
this.#query.notEmpty[key] = value;
|
|
4218
4195
|
return this;
|
|
4219
4196
|
}
|
|
4220
4197
|
addOneOf(key, value) {
|
|
4221
|
-
|
|
4198
|
+
this.#query.oneOf[key] = value;
|
|
4222
4199
|
return this;
|
|
4223
4200
|
}
|
|
4224
4201
|
addContains(key, value) {
|
|
4225
|
-
|
|
4202
|
+
this.#query.contains[key] = value;
|
|
4226
4203
|
return this;
|
|
4227
4204
|
}
|
|
4228
4205
|
addNotContains(key, value) {
|
|
4229
|
-
|
|
4206
|
+
this.#query.notContains[key] = value;
|
|
4230
4207
|
return this;
|
|
4231
4208
|
}
|
|
4232
4209
|
addContainsAny(key, value) {
|
|
4233
|
-
|
|
4210
|
+
this.#query.containsAny[key] = value;
|
|
4234
4211
|
return this;
|
|
4235
4212
|
}
|
|
4236
4213
|
setAllOr() {
|
|
4237
|
-
|
|
4214
|
+
this.#query.allOr = true;
|
|
4238
4215
|
}
|
|
4239
4216
|
setOnEmptyFilter(value) {
|
|
4240
|
-
|
|
4217
|
+
this.#query.onEmptyFilter = value;
|
|
4241
4218
|
}
|
|
4242
4219
|
handleSpaces(input) {
|
|
4243
|
-
if (
|
|
4220
|
+
if (this.#noEscaping) {
|
|
4244
4221
|
return input;
|
|
4245
4222
|
} else {
|
|
4246
4223
|
return input.replace(/ /g, "_");
|
|
@@ -4254,12 +4231,12 @@ var init_lucene = __esm({
|
|
|
4254
4231
|
* @returns {string|*}
|
|
4255
4232
|
*/
|
|
4256
4233
|
preprocess(value, { escape, lowercase, wrap, type } = {}) {
|
|
4257
|
-
const hasVersion = !!
|
|
4234
|
+
const hasVersion = !!this.#version;
|
|
4258
4235
|
const originalType = typeof value;
|
|
4259
4236
|
if (value && lowercase) {
|
|
4260
4237
|
value = value.toLowerCase ? value.toLowerCase() : value;
|
|
4261
4238
|
}
|
|
4262
|
-
if (!
|
|
4239
|
+
if (!this.#noEscaping && escape && originalType === "string") {
|
|
4263
4240
|
value = `${value}`.replace(/[ \/#+\-&|!(){}\]^"~*?:\\]/g, "\\$&");
|
|
4264
4241
|
}
|
|
4265
4242
|
if (originalType === "string" && !isNaN(value) && !type) {
|
|
@@ -4271,7 +4248,7 @@ var init_lucene = __esm({
|
|
|
4271
4248
|
}
|
|
4272
4249
|
isMultiCondition() {
|
|
4273
4250
|
let count = 0;
|
|
4274
|
-
for (let filters of Object.values(
|
|
4251
|
+
for (let filters of Object.values(this.#query)) {
|
|
4275
4252
|
if (typeof filters === "object") {
|
|
4276
4253
|
count += Object.keys(filters).length;
|
|
4277
4254
|
}
|
|
@@ -4296,16 +4273,15 @@ var init_lucene = __esm({
|
|
|
4296
4273
|
return final;
|
|
4297
4274
|
}
|
|
4298
4275
|
buildSearchQuery() {
|
|
4299
|
-
var _a;
|
|
4300
4276
|
const builder = this;
|
|
4301
|
-
let allOr =
|
|
4277
|
+
let allOr = this.#query && this.#query.allOr;
|
|
4302
4278
|
let query = allOr ? "" : "*:*";
|
|
4303
4279
|
let allFiltersEmpty = true;
|
|
4304
4280
|
const allPreProcessingOpts = { escape: true, lowercase: true, wrap: true };
|
|
4305
4281
|
let tableId = "";
|
|
4306
|
-
if (
|
|
4307
|
-
tableId =
|
|
4308
|
-
delete
|
|
4282
|
+
if (this.#query.equal.tableId) {
|
|
4283
|
+
tableId = this.#query.equal.tableId;
|
|
4284
|
+
delete this.#query.equal.tableId;
|
|
4309
4285
|
}
|
|
4310
4286
|
const equal = (key, value) => {
|
|
4311
4287
|
if (!value && value !== 0) {
|
|
@@ -4379,7 +4355,7 @@ var init_lucene = __esm({
|
|
|
4379
4355
|
continue;
|
|
4380
4356
|
}
|
|
4381
4357
|
if (built.length > 0 || query.length > 0) {
|
|
4382
|
-
const mode =
|
|
4358
|
+
const mode = opts?.mode ? opts.mode : allOr ? "OR" : "AND";
|
|
4383
4359
|
built += ` ${mode} `;
|
|
4384
4360
|
}
|
|
4385
4361
|
built += expression;
|
|
@@ -4387,14 +4363,14 @@ var init_lucene = __esm({
|
|
|
4387
4363
|
allFiltersEmpty = false;
|
|
4388
4364
|
}
|
|
4389
4365
|
}
|
|
4390
|
-
if (opts
|
|
4366
|
+
if (opts?.returnBuilt) {
|
|
4391
4367
|
return built;
|
|
4392
4368
|
} else {
|
|
4393
4369
|
query += built;
|
|
4394
4370
|
}
|
|
4395
4371
|
}
|
|
4396
|
-
if (
|
|
4397
|
-
build(
|
|
4372
|
+
if (this.#query.string) {
|
|
4373
|
+
build(this.#query.string, (key, value) => {
|
|
4398
4374
|
if (!value) {
|
|
4399
4375
|
return null;
|
|
4400
4376
|
}
|
|
@@ -4406,8 +4382,8 @@ var init_lucene = __esm({
|
|
|
4406
4382
|
return `${key}:${value}*`;
|
|
4407
4383
|
});
|
|
4408
4384
|
}
|
|
4409
|
-
if (
|
|
4410
|
-
build(
|
|
4385
|
+
if (this.#query.range) {
|
|
4386
|
+
build(this.#query.range, (key, value) => {
|
|
4411
4387
|
if (!value) {
|
|
4412
4388
|
return null;
|
|
4413
4389
|
}
|
|
@@ -4422,14 +4398,14 @@ var init_lucene = __esm({
|
|
|
4422
4398
|
return `${key}:[${low} TO ${high}]`;
|
|
4423
4399
|
});
|
|
4424
4400
|
}
|
|
4425
|
-
if (
|
|
4426
|
-
build(
|
|
4401
|
+
if (this.#query.fuzzy) {
|
|
4402
|
+
build(this.#query.fuzzy, fuzzy);
|
|
4427
4403
|
}
|
|
4428
|
-
if (
|
|
4429
|
-
build(
|
|
4404
|
+
if (this.#query.equal) {
|
|
4405
|
+
build(this.#query.equal, equal);
|
|
4430
4406
|
}
|
|
4431
|
-
if (
|
|
4432
|
-
build(
|
|
4407
|
+
if (this.#query.notEqual) {
|
|
4408
|
+
build(this.#query.notEqual, (key, value) => {
|
|
4433
4409
|
if (!value) {
|
|
4434
4410
|
return null;
|
|
4435
4411
|
}
|
|
@@ -4439,23 +4415,23 @@ var init_lucene = __esm({
|
|
|
4439
4415
|
return `!${key}:${builder.preprocess(value, allPreProcessingOpts)}`;
|
|
4440
4416
|
});
|
|
4441
4417
|
}
|
|
4442
|
-
if (
|
|
4443
|
-
build(
|
|
4418
|
+
if (this.#query.empty) {
|
|
4419
|
+
build(this.#query.empty, (key) => `(*:* -${key}:["" TO *])`);
|
|
4444
4420
|
}
|
|
4445
|
-
if (
|
|
4446
|
-
build(
|
|
4421
|
+
if (this.#query.notEmpty) {
|
|
4422
|
+
build(this.#query.notEmpty, (key) => `${key}:["" TO *]`);
|
|
4447
4423
|
}
|
|
4448
|
-
if (
|
|
4449
|
-
build(
|
|
4424
|
+
if (this.#query.oneOf) {
|
|
4425
|
+
build(this.#query.oneOf, oneOf);
|
|
4450
4426
|
}
|
|
4451
|
-
if (
|
|
4452
|
-
build(
|
|
4427
|
+
if (this.#query.contains) {
|
|
4428
|
+
build(this.#query.contains, contains);
|
|
4453
4429
|
}
|
|
4454
|
-
if (
|
|
4455
|
-
build(this.compressFilters(
|
|
4430
|
+
if (this.#query.notContains) {
|
|
4431
|
+
build(this.compressFilters(this.#query.notContains), notContains);
|
|
4456
4432
|
}
|
|
4457
|
-
if (
|
|
4458
|
-
build(
|
|
4433
|
+
if (this.#query.containsAny) {
|
|
4434
|
+
build(this.#query.containsAny, containsAny);
|
|
4459
4435
|
}
|
|
4460
4436
|
if (tableId) {
|
|
4461
4437
|
query = this.isMultiCondition() ? `(${query})` : query;
|
|
@@ -4463,9 +4439,9 @@ var init_lucene = __esm({
|
|
|
4463
4439
|
build({ tableId }, equal);
|
|
4464
4440
|
}
|
|
4465
4441
|
if (allFiltersEmpty) {
|
|
4466
|
-
if (
|
|
4442
|
+
if (this.#query.onEmptyFilter === "none" /* RETURN_NONE */) {
|
|
4467
4443
|
return "";
|
|
4468
|
-
} else if (
|
|
4444
|
+
} else if (this.#query?.allOr) {
|
|
4469
4445
|
return query.replace("()", "(*:*)");
|
|
4470
4446
|
}
|
|
4471
4447
|
}
|
|
@@ -4474,75 +4450,63 @@ var init_lucene = __esm({
|
|
|
4474
4450
|
buildSearchBody() {
|
|
4475
4451
|
let body2 = {
|
|
4476
4452
|
q: this.buildSearchQuery(),
|
|
4477
|
-
limit: Math.min(
|
|
4478
|
-
include_docs:
|
|
4453
|
+
limit: Math.min(this.#limit, _QueryBuilder.maxLimit),
|
|
4454
|
+
include_docs: this.#includeDocs
|
|
4479
4455
|
};
|
|
4480
|
-
if (
|
|
4481
|
-
body2.bookmark =
|
|
4456
|
+
if (this.#bookmark) {
|
|
4457
|
+
body2.bookmark = this.#bookmark;
|
|
4482
4458
|
}
|
|
4483
|
-
if (
|
|
4484
|
-
const order =
|
|
4485
|
-
const type = `<${
|
|
4486
|
-
body2.sort = `${order}${this.handleSpaces(
|
|
4459
|
+
if (this.#sort) {
|
|
4460
|
+
const order = this.#sortOrder === "descending" ? "-" : "";
|
|
4461
|
+
const type = `<${this.#sortType}>`;
|
|
4462
|
+
body2.sort = `${order}${this.handleSpaces(this.#sort)}${type}`;
|
|
4487
4463
|
}
|
|
4488
4464
|
return body2;
|
|
4489
4465
|
}
|
|
4490
4466
|
async run() {
|
|
4491
|
-
if (
|
|
4492
|
-
await
|
|
4467
|
+
if (this.#skip) {
|
|
4468
|
+
await this.#skipItems(this.#skip);
|
|
4493
4469
|
}
|
|
4494
|
-
return await
|
|
4470
|
+
return await this.#execute();
|
|
4495
4471
|
}
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4505
|
-
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
const
|
|
4521
|
-
this.
|
|
4522
|
-
|
|
4523
|
-
skipRemaining -= rows.length;
|
|
4524
|
-
} while (skipRemaining > 0 && iterationFetched > 0);
|
|
4525
|
-
__privateSet(this, _includeDocs, prevIncludeDocs);
|
|
4526
|
-
__privateSet(this, _limit, prevLimit);
|
|
4527
|
-
};
|
|
4528
|
-
_execute = new WeakSet();
|
|
4529
|
-
execute_fn = async function() {
|
|
4530
|
-
const { url, cookie } = getCouchInfo();
|
|
4531
|
-
const fullPath = `${url}/${__privateGet(this, _dbName)}/_design/database/_search/${__privateGet(this, _index)}`;
|
|
4532
|
-
const body2 = this.buildSearchBody();
|
|
4533
|
-
try {
|
|
4534
|
-
return await runQuery(fullPath, body2, cookie);
|
|
4535
|
-
} catch (err) {
|
|
4536
|
-
if (err.status === 404 && __privateGet(this, _indexBuilder)) {
|
|
4537
|
-
await __privateGet(this, _indexBuilder).call(this);
|
|
4472
|
+
/**
|
|
4473
|
+
* Lucene queries do not support pagination and use bookmarks instead.
|
|
4474
|
+
* For the given builder, walk through pages using bookmarks until the desired
|
|
4475
|
+
* page has been met.
|
|
4476
|
+
*/
|
|
4477
|
+
async #skipItems(skip) {
|
|
4478
|
+
const prevIncludeDocs = this.#includeDocs;
|
|
4479
|
+
const prevLimit = this.#limit;
|
|
4480
|
+
this.excludeDocs();
|
|
4481
|
+
let skipRemaining = skip;
|
|
4482
|
+
let iterationFetched = 0;
|
|
4483
|
+
do {
|
|
4484
|
+
const toSkip = Math.min(_QueryBuilder.maxLimit, skipRemaining);
|
|
4485
|
+
this.setLimit(toSkip);
|
|
4486
|
+
const { bookmark, rows } = await this.#execute();
|
|
4487
|
+
this.setBookmark(bookmark);
|
|
4488
|
+
iterationFetched = rows.length;
|
|
4489
|
+
skipRemaining -= rows.length;
|
|
4490
|
+
} while (skipRemaining > 0 && iterationFetched > 0);
|
|
4491
|
+
this.#includeDocs = prevIncludeDocs;
|
|
4492
|
+
this.#limit = prevLimit;
|
|
4493
|
+
}
|
|
4494
|
+
async #execute() {
|
|
4495
|
+
const { url, cookie } = getCouchInfo();
|
|
4496
|
+
const fullPath = `${url}/${this.#dbName}/_design/database/_search/${this.#index}`;
|
|
4497
|
+
const body2 = this.buildSearchBody();
|
|
4498
|
+
try {
|
|
4538
4499
|
return await runQuery(fullPath, body2, cookie);
|
|
4539
|
-
}
|
|
4540
|
-
|
|
4500
|
+
} catch (err) {
|
|
4501
|
+
if (err.status === 404 && this.#indexBuilder) {
|
|
4502
|
+
await this.#indexBuilder();
|
|
4503
|
+
return await runQuery(fullPath, body2, cookie);
|
|
4504
|
+
} else {
|
|
4505
|
+
throw err;
|
|
4506
|
+
}
|
|
4541
4507
|
}
|
|
4542
4508
|
}
|
|
4543
4509
|
};
|
|
4544
|
-
_QueryBuilder.maxLimit = 200;
|
|
4545
|
-
QueryBuilder = _QueryBuilder;
|
|
4546
4510
|
}
|
|
4547
4511
|
});
|
|
4548
4512
|
|
|
@@ -4621,10 +4585,9 @@ var init_searchIndexes2 = __esm({
|
|
|
4621
4585
|
|
|
4622
4586
|
// src/db/errors.ts
|
|
4623
4587
|
function checkErrorCode(error, code) {
|
|
4624
|
-
var _a;
|
|
4625
4588
|
const stringCode = code.toString();
|
|
4626
4589
|
if (typeof error === "object") {
|
|
4627
|
-
return error.status === code ||
|
|
4590
|
+
return error.status === code || error.message?.includes(stringCode);
|
|
4628
4591
|
} else if (typeof error === "number") {
|
|
4629
4592
|
return error === code;
|
|
4630
4593
|
} else if (typeof error === "string") {
|
|
@@ -4875,12 +4838,12 @@ var init_objectStore = __esm({
|
|
|
4875
4838
|
streamUpload = async (bucketName, filename, stream2, extra = {}) => {
|
|
4876
4839
|
const objectStore = ObjectStore(bucketName);
|
|
4877
4840
|
await makeSureBucketExists(objectStore, bucketName);
|
|
4878
|
-
if (filename
|
|
4841
|
+
if (filename?.endsWith(".js")) {
|
|
4879
4842
|
extra = {
|
|
4880
4843
|
...extra,
|
|
4881
4844
|
ContentType: "application/javascript"
|
|
4882
4845
|
};
|
|
4883
|
-
} else if (filename
|
|
4846
|
+
} else if (filename?.endsWith(".svg")) {
|
|
4884
4847
|
extra = {
|
|
4885
4848
|
...extra,
|
|
4886
4849
|
ContentType: "image"
|
|
@@ -4996,7 +4959,6 @@ var init_objectStore = __esm({
|
|
|
4996
4959
|
return objectStore.deleteObjects(params2).promise();
|
|
4997
4960
|
};
|
|
4998
4961
|
deleteFolder = async (bucketName, folder) => {
|
|
4999
|
-
var _a, _b, _c;
|
|
5000
4962
|
bucketName = sanitizeBucket(bucketName);
|
|
5001
4963
|
folder = sanitizeKey(folder);
|
|
5002
4964
|
const client = ObjectStore(bucketName);
|
|
@@ -5005,7 +4967,7 @@ var init_objectStore = __esm({
|
|
|
5005
4967
|
Prefix: folder
|
|
5006
4968
|
};
|
|
5007
4969
|
const existingObjectsResponse = await client.listObjects(listParams).promise();
|
|
5008
|
-
if (
|
|
4970
|
+
if (existingObjectsResponse.Contents?.length === 0) {
|
|
5009
4971
|
return;
|
|
5010
4972
|
}
|
|
5011
4973
|
const deleteParams = {
|
|
@@ -5014,11 +4976,11 @@ var init_objectStore = __esm({
|
|
|
5014
4976
|
Objects: []
|
|
5015
4977
|
}
|
|
5016
4978
|
};
|
|
5017
|
-
|
|
4979
|
+
existingObjectsResponse.Contents?.forEach((content) => {
|
|
5018
4980
|
deleteParams.Delete.Objects.push({ Key: content.Key });
|
|
5019
4981
|
});
|
|
5020
4982
|
const deleteResponse = await client.deleteObjects(deleteParams).promise();
|
|
5021
|
-
if (
|
|
4983
|
+
if (deleteResponse.Deleted?.length === 1e3) {
|
|
5022
4984
|
return deleteFolder(bucketName, folder);
|
|
5023
4985
|
}
|
|
5024
4986
|
};
|
|
@@ -5295,7 +5257,7 @@ function getFullPath(fileName) {
|
|
|
5295
5257
|
}
|
|
5296
5258
|
function getSingleFileMaxSizeInfo(totalMaxSize) {
|
|
5297
5259
|
const regex = /(\d+)([A-Za-z])/;
|
|
5298
|
-
const match = totalMaxSize
|
|
5260
|
+
const match = totalMaxSize?.match(regex);
|
|
5299
5261
|
if (!match) {
|
|
5300
5262
|
console.warn(`totalMaxSize does not have a valid value`, {
|
|
5301
5263
|
totalMaxSize
|
|
@@ -5327,9 +5289,9 @@ function localFileDestination() {
|
|
|
5327
5289
|
const fileInfo = getSingleFileMaxSizeInfo(environment_default.ROLLING_LOG_MAX_SIZE);
|
|
5328
5290
|
const outFile = rfs.createStream(logsFileName, {
|
|
5329
5291
|
// As we have a rolling size, we want to half the max size
|
|
5330
|
-
size: fileInfo
|
|
5292
|
+
size: fileInfo?.size,
|
|
5331
5293
|
path: logsPath,
|
|
5332
|
-
maxFiles:
|
|
5294
|
+
maxFiles: fileInfo?.totalHistoryFiles || 1,
|
|
5333
5295
|
immutable: true,
|
|
5334
5296
|
history: budibaseLogsHistoryFileName,
|
|
5335
5297
|
initialRotation: false
|
|
@@ -5404,8 +5366,8 @@ var init_logger = __esm({
|
|
|
5404
5366
|
tenantId: getTenantId2(),
|
|
5405
5367
|
appId: getAppId2(),
|
|
5406
5368
|
automationId: getAutomationId2(),
|
|
5407
|
-
identityId: identity
|
|
5408
|
-
identityType: identity
|
|
5369
|
+
identityId: identity?._id,
|
|
5370
|
+
identityType: identity?.type,
|
|
5409
5371
|
correlationId: getId()
|
|
5410
5372
|
};
|
|
5411
5373
|
const mergingObject = {
|
|
@@ -5469,30 +5431,30 @@ var init_logger = __esm({
|
|
|
5469
5431
|
pinoInstance = destinations.length ? (0, import_pino.default)(pinoOptions, import_pino.default.multistream(destinations)) : (0, import_pino.default)(pinoOptions);
|
|
5470
5432
|
console.log = (...arg) => {
|
|
5471
5433
|
const [obj, msg] = getLogParams2(arg);
|
|
5472
|
-
pinoInstance
|
|
5434
|
+
pinoInstance?.info(obj, msg);
|
|
5473
5435
|
};
|
|
5474
5436
|
console.info = (...arg) => {
|
|
5475
5437
|
const [obj, msg] = getLogParams2(arg);
|
|
5476
|
-
pinoInstance
|
|
5438
|
+
pinoInstance?.info(obj, msg);
|
|
5477
5439
|
};
|
|
5478
5440
|
console.warn = (...arg) => {
|
|
5479
5441
|
const [obj, msg] = getLogParams2(arg);
|
|
5480
|
-
pinoInstance
|
|
5442
|
+
pinoInstance?.warn(obj, msg);
|
|
5481
5443
|
};
|
|
5482
5444
|
console.error = (...arg) => {
|
|
5483
5445
|
const [obj, msg] = getLogParams2(arg);
|
|
5484
|
-
pinoInstance
|
|
5446
|
+
pinoInstance?.error(obj, msg);
|
|
5485
5447
|
};
|
|
5486
5448
|
console.trace = (...arg) => {
|
|
5487
5449
|
const [obj, msg] = getLogParams2(arg);
|
|
5488
5450
|
if (!obj.err) {
|
|
5489
5451
|
obj.err = new Error();
|
|
5490
5452
|
}
|
|
5491
|
-
pinoInstance
|
|
5453
|
+
pinoInstance?.trace(obj, msg);
|
|
5492
5454
|
};
|
|
5493
5455
|
console.debug = (...arg) => {
|
|
5494
5456
|
const [obj, msg] = getLogParams2(arg);
|
|
5495
|
-
pinoInstance
|
|
5457
|
+
pinoInstance?.debug(obj, msg);
|
|
5496
5458
|
};
|
|
5497
5459
|
const getTenantId2 = () => {
|
|
5498
5460
|
let tenantId;
|
|
@@ -5776,7 +5738,6 @@ var isUserInAppTenant = (appId, user) => {
|
|
|
5776
5738
|
};
|
|
5777
5739
|
var ALL_STRATEGIES = Object.values(TenantResolutionStrategy);
|
|
5778
5740
|
var getTenantIDFromCtx = (ctx, opts) => {
|
|
5779
|
-
var _a;
|
|
5780
5741
|
if (!isMultiTenant()) {
|
|
5781
5742
|
return DEFAULT_TENANT_ID;
|
|
5782
5743
|
}
|
|
@@ -5790,16 +5751,15 @@ var getTenantIDFromCtx = (ctx, opts) => {
|
|
|
5790
5751
|
opts.excludeStrategies = [];
|
|
5791
5752
|
}
|
|
5792
5753
|
const isAllowed = (strategy) => {
|
|
5793
|
-
|
|
5794
|
-
if ((_a2 = opts.excludeStrategies) == null ? void 0 : _a2.includes(strategy)) {
|
|
5754
|
+
if (opts.excludeStrategies?.includes(strategy)) {
|
|
5795
5755
|
return false;
|
|
5796
5756
|
}
|
|
5797
|
-
if (
|
|
5757
|
+
if (opts.includeStrategies?.includes(strategy)) {
|
|
5798
5758
|
return true;
|
|
5799
5759
|
}
|
|
5800
5760
|
};
|
|
5801
5761
|
if (isAllowed("user" /* USER */)) {
|
|
5802
|
-
const userTenantId =
|
|
5762
|
+
const userTenantId = ctx.user?.tenantId;
|
|
5803
5763
|
if (userTenantId) {
|
|
5804
5764
|
return userTenantId;
|
|
5805
5765
|
}
|
|
@@ -6367,7 +6327,7 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
|
6367
6327
|
logWarn(`Ignoring redlock conflict in write-through cache`);
|
|
6368
6328
|
}
|
|
6369
6329
|
}
|
|
6370
|
-
cacheItem = makeCacheItem(output, updateDb ? null : cacheItem
|
|
6330
|
+
cacheItem = makeCacheItem(output, updateDb ? null : cacheItem?.lastWrite);
|
|
6371
6331
|
if (output._id) {
|
|
6372
6332
|
await cache.store(makeCacheKey(db, output._id), cacheItem);
|
|
6373
6333
|
}
|
|
@@ -6459,7 +6419,6 @@ async function getSettingsConfig() {
|
|
|
6459
6419
|
async function getPlatformUrl(opts = {
|
|
6460
6420
|
tenantAware: true
|
|
6461
6421
|
}) {
|
|
6462
|
-
var _a;
|
|
6463
6422
|
let platformUrl = environment_default.PLATFORM_URL || "http://localhost:10000";
|
|
6464
6423
|
if (!environment_default.SELF_HOSTED && environment_default.MULTI_TENANCY && opts.tenantAware) {
|
|
6465
6424
|
const tenantId = getTenantId();
|
|
@@ -6467,11 +6426,11 @@ async function getPlatformUrl(opts = {
|
|
|
6467
6426
|
platformUrl = platformUrl.replace("://", `://${tenantId}.`);
|
|
6468
6427
|
}
|
|
6469
6428
|
} else if (environment_default.SELF_HOSTED) {
|
|
6470
|
-
const config =
|
|
6429
|
+
const config = opts?.config ? opts.config : (
|
|
6471
6430
|
// direct to db to prevent infinite loop
|
|
6472
|
-
(
|
|
6431
|
+
(await getConfig("settings" /* SETTINGS */))?.config
|
|
6473
6432
|
);
|
|
6474
|
-
if (config
|
|
6433
|
+
if (config?.platformUrl) {
|
|
6475
6434
|
platformUrl = config.platformUrl;
|
|
6476
6435
|
}
|
|
6477
6436
|
}
|
|
@@ -6485,14 +6444,13 @@ var analyticsEnabled = async (opts) => {
|
|
|
6485
6444
|
"analyticsEnabled" /* ANALYTICS_ENABLED */,
|
|
6486
6445
|
86400 /* ONE_DAY */,
|
|
6487
6446
|
async () => {
|
|
6488
|
-
|
|
6489
|
-
const config = (opts == null ? void 0 : opts.config) ? opts.config : (
|
|
6447
|
+
const config = opts?.config ? opts.config : (
|
|
6490
6448
|
// direct to db to prevent infinite loop
|
|
6491
|
-
(
|
|
6449
|
+
(await getConfig("settings" /* SETTINGS */))?.config
|
|
6492
6450
|
);
|
|
6493
|
-
if (
|
|
6451
|
+
if (config?.analyticsEnabled === false) {
|
|
6494
6452
|
return false;
|
|
6495
|
-
} else if (
|
|
6453
|
+
} else if (config?.analyticsEnabled === true) {
|
|
6496
6454
|
return true;
|
|
6497
6455
|
}
|
|
6498
6456
|
}
|
|
@@ -6512,7 +6470,7 @@ async function getGoogleConfigDoc() {
|
|
|
6512
6470
|
}
|
|
6513
6471
|
async function getGoogleConfig() {
|
|
6514
6472
|
const config = await getGoogleConfigDoc();
|
|
6515
|
-
return config
|
|
6473
|
+
return config?.config;
|
|
6516
6474
|
}
|
|
6517
6475
|
async function getGoogleDatasourceConfig() {
|
|
6518
6476
|
if (!environment_default.SELF_HOSTED) {
|
|
@@ -6540,13 +6498,11 @@ async function getOIDCConfigDoc() {
|
|
|
6540
6498
|
return getConfig("oidc" /* OIDC */);
|
|
6541
6499
|
}
|
|
6542
6500
|
async function getOIDCConfig() {
|
|
6543
|
-
|
|
6544
|
-
|
|
6545
|
-
return (config == null ? void 0 : config.configs) && config.configs[0];
|
|
6501
|
+
const config = (await getOIDCConfigDoc())?.config;
|
|
6502
|
+
return config?.configs && config.configs[0];
|
|
6546
6503
|
}
|
|
6547
6504
|
async function getOIDCConfigById(configId) {
|
|
6548
|
-
|
|
6549
|
-
const config = (_a = await getConfig("oidc" /* OIDC */)) == null ? void 0 : _a.config;
|
|
6505
|
+
const config = (await getConfig("oidc" /* OIDC */))?.config;
|
|
6550
6506
|
return config && config.configs.filter((c) => c.uuid === configId)[0];
|
|
6551
6507
|
}
|
|
6552
6508
|
async function getSMTPConfigDoc() {
|
|
@@ -6573,7 +6529,7 @@ async function getSMTPConfig(isAutomation) {
|
|
|
6573
6529
|
}
|
|
6574
6530
|
async function getSCIMConfig() {
|
|
6575
6531
|
const config = await getConfig("scim" /* SCIM */);
|
|
6576
|
-
return config
|
|
6532
|
+
return config?.config;
|
|
6577
6533
|
}
|
|
6578
6534
|
|
|
6579
6535
|
// src/events/index.ts
|
|
@@ -6988,7 +6944,7 @@ async function getAppIdFromCtx(ctx) {
|
|
|
6988
6944
|
appId = confirmAppId(await resolveAppUrl(ctx));
|
|
6989
6945
|
}
|
|
6990
6946
|
const referer = ctx.request.headers.referer;
|
|
6991
|
-
if (!appId &&
|
|
6947
|
+
if (!appId && referer?.includes(BUILDER_APP_PREFIX)) {
|
|
6992
6948
|
const refererId = parseAppIdFromUrl(ctx.request.headers.referer);
|
|
6993
6949
|
appId = confirmAppId(refererId);
|
|
6994
6950
|
}
|
|
@@ -7207,7 +7163,6 @@ function handleStalled(queue, removeStalledCb) {
|
|
|
7207
7163
|
});
|
|
7208
7164
|
}
|
|
7209
7165
|
function getLogParams(eventType, event, opts = {}, extra = {}) {
|
|
7210
|
-
var _a, _b, _c;
|
|
7211
7166
|
const message = `[BULL] ${eventType}=${event}`;
|
|
7212
7167
|
const err = opts.error;
|
|
7213
7168
|
const bullLog = {
|
|
@@ -7215,11 +7170,11 @@ function getLogParams(eventType, event, opts = {}, extra = {}) {
|
|
|
7215
7170
|
eventType,
|
|
7216
7171
|
event,
|
|
7217
7172
|
job: opts.job,
|
|
7218
|
-
jobId: opts.jobId ||
|
|
7173
|
+
jobId: opts.jobId || opts.job?.id,
|
|
7219
7174
|
...extra
|
|
7220
7175
|
};
|
|
7221
7176
|
let automationLog;
|
|
7222
|
-
if (
|
|
7177
|
+
if (opts.job?.data?.automation) {
|
|
7223
7178
|
automationLog = {
|
|
7224
7179
|
_logKey: "automation",
|
|
7225
7180
|
trigger: opts.job ? opts.job.data.automation.definition.trigger.event : void 0
|
|
@@ -7234,11 +7189,9 @@ var EventTypeMap = {
|
|
|
7234
7189
|
["systemEventQueue" /* SYSTEM_EVENT_QUEUE */]: "system-event" /* SYSTEM_EVENT */
|
|
7235
7190
|
};
|
|
7236
7191
|
function logging(queue, jobQueue) {
|
|
7237
|
-
var _a;
|
|
7238
7192
|
const eventType = EventTypeMap[jobQueue];
|
|
7239
7193
|
function doInJobContext(job, task) {
|
|
7240
|
-
|
|
7241
|
-
const appId = (_a2 = job.data.event) == null ? void 0 : _a2.appId;
|
|
7194
|
+
const appId = job.data.event?.appId;
|
|
7242
7195
|
if (appId) {
|
|
7243
7196
|
return doInContext(appId, task);
|
|
7244
7197
|
} else {
|
|
@@ -7252,7 +7205,7 @@ function logging(queue, jobQueue) {
|
|
|
7252
7205
|
}).on("error" /* ERROR */, (error) => {
|
|
7253
7206
|
console.error(...getLogParams(eventType, "error" /* ERROR */, { error }));
|
|
7254
7207
|
});
|
|
7255
|
-
if (
|
|
7208
|
+
if (process.env.NODE_DEBUG?.includes("bull")) {
|
|
7256
7209
|
queue.on("waiting" /* WAITING */, (jobId) => {
|
|
7257
7210
|
console.info(...getLogParams(eventType, "waiting" /* WAITING */, { jobId }));
|
|
7258
7211
|
}).on("active" /* ACTIVE */, async (job, jobPromise) => {
|
|
@@ -7322,7 +7275,7 @@ function createQueue(jobQueue, opts = {}) {
|
|
|
7322
7275
|
} else {
|
|
7323
7276
|
queue = new inMemoryQueue_default(jobQueue, queueConfig);
|
|
7324
7277
|
}
|
|
7325
|
-
addListeners(queue, jobQueue, opts
|
|
7278
|
+
addListeners(queue, jobQueue, opts?.removeStalledCb);
|
|
7326
7279
|
QUEUES.push(queue);
|
|
7327
7280
|
if (!cleanupInterval && !environment_default.isTest()) {
|
|
7328
7281
|
cleanupInterval = set(cleanup2, CLEANUP_PERIOD_MS);
|
|
@@ -7347,7 +7300,10 @@ async function shutdown2() {
|
|
|
7347
7300
|
|
|
7348
7301
|
// src/events/processors/AuditLogsProcessor.ts
|
|
7349
7302
|
init_environment2();
|
|
7350
|
-
var
|
|
7303
|
+
var AuditLogsProcessor = class _AuditLogsProcessor {
|
|
7304
|
+
static {
|
|
7305
|
+
this.auditLogsEnabled = false;
|
|
7306
|
+
}
|
|
7351
7307
|
// can't use constructor as need to return promise
|
|
7352
7308
|
static init(fn) {
|
|
7353
7309
|
_AuditLogsProcessor.auditLogsEnabled = true;
|
|
@@ -7399,12 +7355,9 @@ var _AuditLogsProcessor = class _AuditLogsProcessor {
|
|
|
7399
7355
|
async identifyGroup(group, timestamp) {
|
|
7400
7356
|
}
|
|
7401
7357
|
shutdown() {
|
|
7402
|
-
|
|
7403
|
-
(_a = _AuditLogsProcessor.auditLogQueue) == null ? void 0 : _a.close();
|
|
7358
|
+
_AuditLogsProcessor.auditLogQueue?.close();
|
|
7404
7359
|
}
|
|
7405
7360
|
};
|
|
7406
|
-
_AuditLogsProcessor.auditLogsEnabled = false;
|
|
7407
|
-
var AuditLogsProcessor = _AuditLogsProcessor;
|
|
7408
7361
|
|
|
7409
7362
|
// src/events/processors/Processors.ts
|
|
7410
7363
|
var Processor = class {
|
|
@@ -7619,7 +7572,7 @@ var bulkGetGlobalUsersById = async (userIds, opts) => {
|
|
|
7619
7572
|
keys: userIds,
|
|
7620
7573
|
include_docs: true
|
|
7621
7574
|
})).rows.map((row) => row.doc);
|
|
7622
|
-
if (opts
|
|
7575
|
+
if (opts?.cleanup) {
|
|
7623
7576
|
users = removeUserPassword(users);
|
|
7624
7577
|
}
|
|
7625
7578
|
return users;
|
|
@@ -7640,7 +7593,7 @@ var bulkUpdateGlobalUsers = async (users) => {
|
|
|
7640
7593
|
async function getById(id, opts) {
|
|
7641
7594
|
const db = getGlobalDB();
|
|
7642
7595
|
let user = await db.get(id);
|
|
7643
|
-
if (opts
|
|
7596
|
+
if (opts?.cleanup) {
|
|
7644
7597
|
user = removeUserPassword(user);
|
|
7645
7598
|
}
|
|
7646
7599
|
return user;
|
|
@@ -7657,7 +7610,7 @@ var getGlobalUserByEmail = async (email, opts) => {
|
|
|
7657
7610
|
throw new Error(`Multiple users found with email address: ${email}`);
|
|
7658
7611
|
}
|
|
7659
7612
|
let user = response;
|
|
7660
|
-
if (opts
|
|
7613
|
+
if (opts?.cleanup) {
|
|
7661
7614
|
user = removeUserPassword(user);
|
|
7662
7615
|
}
|
|
7663
7616
|
return user;
|
|
@@ -7675,7 +7628,7 @@ var searchGlobalUsersByApp = async (appId, opts, getOpts) => {
|
|
|
7675
7628
|
response = [];
|
|
7676
7629
|
}
|
|
7677
7630
|
let users = Array.isArray(response) ? response : [response];
|
|
7678
|
-
if (getOpts
|
|
7631
|
+
if (getOpts?.cleanup) {
|
|
7679
7632
|
users = removeUserPassword(users);
|
|
7680
7633
|
}
|
|
7681
7634
|
return users;
|
|
@@ -7705,10 +7658,10 @@ var searchGlobalUsersByAppAccess = async (appId, opts) => {
|
|
|
7705
7658
|
$regex: "^us_"
|
|
7706
7659
|
}
|
|
7707
7660
|
},
|
|
7708
|
-
limit:
|
|
7661
|
+
limit: opts?.limit || 50
|
|
7709
7662
|
};
|
|
7710
7663
|
const resp = await directCouchFind(getGlobalDBName(), searchOptions);
|
|
7711
|
-
return resp
|
|
7664
|
+
return resp?.rows;
|
|
7712
7665
|
};
|
|
7713
7666
|
var getGlobalUserByAppPage = (appId, user) => {
|
|
7714
7667
|
if (!user) {
|
|
@@ -7731,7 +7684,7 @@ var searchGlobalUsersByEmail = async (email, opts, getOpts) => {
|
|
|
7731
7684
|
response = [];
|
|
7732
7685
|
}
|
|
7733
7686
|
let users = Array.isArray(response) ? response : [response];
|
|
7734
|
-
if (getOpts
|
|
7687
|
+
if (getOpts?.cleanup) {
|
|
7735
7688
|
users = removeUserPassword(users);
|
|
7736
7689
|
}
|
|
7737
7690
|
return users;
|
|
@@ -8082,13 +8035,12 @@ __export(users_exports2, {
|
|
|
8082
8035
|
isGlobalBuilder: () => isGlobalBuilder
|
|
8083
8036
|
});
|
|
8084
8037
|
function isBuilder(user, appId) {
|
|
8085
|
-
var _a, _b, _c;
|
|
8086
8038
|
if (!user) {
|
|
8087
8039
|
return false;
|
|
8088
8040
|
}
|
|
8089
|
-
if (
|
|
8041
|
+
if (user.builder?.global) {
|
|
8090
8042
|
return true;
|
|
8091
|
-
} else if (appId &&
|
|
8043
|
+
} else if (appId && user.builder?.apps?.includes(getProdAppID2(appId))) {
|
|
8092
8044
|
return true;
|
|
8093
8045
|
}
|
|
8094
8046
|
return false;
|
|
@@ -8106,27 +8058,24 @@ function isAdminOrBuilder(user, appId) {
|
|
|
8106
8058
|
return isBuilder(user, appId) || isAdmin(user);
|
|
8107
8059
|
}
|
|
8108
8060
|
function hasAppBuilderPermissions(user) {
|
|
8109
|
-
var _a, _b, _c;
|
|
8110
8061
|
if (!user) {
|
|
8111
8062
|
return false;
|
|
8112
8063
|
}
|
|
8113
|
-
const appLength =
|
|
8114
|
-
const isGlobalBuilder3 = !!
|
|
8064
|
+
const appLength = user.builder?.apps?.length;
|
|
8065
|
+
const isGlobalBuilder3 = !!user.builder?.global;
|
|
8115
8066
|
return !isGlobalBuilder3 && appLength != null && appLength > 0;
|
|
8116
8067
|
}
|
|
8117
8068
|
function hasBuilderPermissions(user) {
|
|
8118
|
-
var _a;
|
|
8119
8069
|
if (!user) {
|
|
8120
8070
|
return false;
|
|
8121
8071
|
}
|
|
8122
|
-
return
|
|
8072
|
+
return user.builder?.global || hasAppBuilderPermissions(user);
|
|
8123
8073
|
}
|
|
8124
8074
|
function hasAdminPermissions(user) {
|
|
8125
|
-
var _a;
|
|
8126
8075
|
if (!user) {
|
|
8127
8076
|
return false;
|
|
8128
8077
|
}
|
|
8129
|
-
return !!
|
|
8078
|
+
return !!user.admin?.global;
|
|
8130
8079
|
}
|
|
8131
8080
|
|
|
8132
8081
|
// src/users/utils.ts
|
|
@@ -8199,7 +8148,7 @@ var unassignAppRoleEvents = async (user, roles, existingRoles) => {
|
|
|
8199
8148
|
};
|
|
8200
8149
|
var handleAppRoleEvents = async (user, existingUser) => {
|
|
8201
8150
|
const roles = user.roles;
|
|
8202
|
-
const existingRoles = existingUser
|
|
8151
|
+
const existingRoles = existingUser?.roles;
|
|
8203
8152
|
await assignAppRoleEvents(user, roles, existingRoles);
|
|
8204
8153
|
await unassignAppRoleEvents(user, roles, existingRoles);
|
|
8205
8154
|
};
|
|
@@ -8251,7 +8200,7 @@ var isRemovingAdmin = (user, existingUser) => {
|
|
|
8251
8200
|
return isRemovingPermission(user, existingUser, hasAdminPermissions2);
|
|
8252
8201
|
};
|
|
8253
8202
|
var isOnboardingComplete = (user, existingUser) => {
|
|
8254
|
-
return !
|
|
8203
|
+
return !existingUser?.onboardedAt && typeof user.onboardedAt === "string";
|
|
8255
8204
|
};
|
|
8256
8205
|
var isAddingPermission = (user, existingUser, hasPermission) => {
|
|
8257
8206
|
if (!hasPermission(user)) {
|
|
@@ -8308,7 +8257,7 @@ async function getSessionsForUser(userId) {
|
|
|
8308
8257
|
}
|
|
8309
8258
|
async function invalidateSessions(userId, opts = {}) {
|
|
8310
8259
|
try {
|
|
8311
|
-
const reason =
|
|
8260
|
+
const reason = opts?.reason || "unknown";
|
|
8312
8261
|
let sessionIds = opts.sessionIds || [];
|
|
8313
8262
|
let sessionKeys;
|
|
8314
8263
|
if (sessionIds.length === 0) {
|
|
@@ -8485,7 +8434,6 @@ var UserDB = class _UserDB {
|
|
|
8485
8434
|
return user;
|
|
8486
8435
|
}
|
|
8487
8436
|
static async save(user, opts = {}) {
|
|
8488
|
-
var _a, _b;
|
|
8489
8437
|
if (opts.hashPassword == null) {
|
|
8490
8438
|
opts.hashPassword = true;
|
|
8491
8439
|
}
|
|
@@ -8498,7 +8446,7 @@ var UserDB = class _UserDB {
|
|
|
8498
8446
|
if (!email && !_id) {
|
|
8499
8447
|
throw new Error("_id or email is required");
|
|
8500
8448
|
}
|
|
8501
|
-
if (
|
|
8449
|
+
if (user.builder?.apps?.length && !await _UserDB.features.isAppBuildersEnabled()) {
|
|
8502
8450
|
throw new Error("Unable to update app builders, please check license");
|
|
8503
8451
|
}
|
|
8504
8452
|
let dbUser;
|
|
@@ -8526,10 +8474,10 @@ var UserDB = class _UserDB {
|
|
|
8526
8474
|
return _UserDB.quotas.addUsers(change, async () => {
|
|
8527
8475
|
await validateUniqueUser(email, tenantId);
|
|
8528
8476
|
let builtUser = await _UserDB.buildUser(user, opts, tenantId, dbUser);
|
|
8529
|
-
if (opts.currentUserId && opts.currentUserId ===
|
|
8477
|
+
if (opts.currentUserId && opts.currentUserId === dbUser?._id) {
|
|
8530
8478
|
builtUser = cleanseUserObject(builtUser, dbUser);
|
|
8531
8479
|
}
|
|
8532
|
-
if (!dbUser &&
|
|
8480
|
+
if (!dbUser && roles?.length) {
|
|
8533
8481
|
builtUser.roles = { ...roles };
|
|
8534
8482
|
}
|
|
8535
8483
|
let groupPromises = [];
|
|
@@ -8808,8 +8756,8 @@ var identifyUser = async (user, account, timestamp) => {
|
|
|
8808
8756
|
if (isSSOUser(user)) {
|
|
8809
8757
|
providerType = user.providerType;
|
|
8810
8758
|
}
|
|
8811
|
-
const accountHolder =
|
|
8812
|
-
const verified2 = account &&
|
|
8759
|
+
const accountHolder = account?.budibaseUserId === user._id || false;
|
|
8760
|
+
const verified2 = account && account?.budibaseUserId === user._id ? account.verified : false;
|
|
8813
8761
|
const installationId = await getInstallationId();
|
|
8814
8762
|
const hosting = account ? account.hosting : getHostingFromEnv();
|
|
8815
8763
|
const environment2 = getDeploymentEnvironment();
|
|
@@ -8968,7 +8916,7 @@ var clearEvents = async () => {
|
|
|
8968
8916
|
};
|
|
8969
8917
|
var isBackfillingEvent = async (event) => {
|
|
8970
8918
|
const backfill = await getBackfillMetadata();
|
|
8971
|
-
const events2 = backfill
|
|
8919
|
+
const events2 = backfill?.eventWhitelist;
|
|
8972
8920
|
if (events2 && events2.includes(event)) {
|
|
8973
8921
|
return true;
|
|
8974
8922
|
} else {
|
|
@@ -9312,12 +9260,11 @@ var auth_default = {
|
|
|
9312
9260
|
// src/events/publishers/automation.ts
|
|
9313
9261
|
init_src();
|
|
9314
9262
|
async function created3(automation, timestamp) {
|
|
9315
|
-
var _a, _b, _c, _d;
|
|
9316
9263
|
const properties = {
|
|
9317
9264
|
appId: automation.appId,
|
|
9318
9265
|
automationId: automation._id,
|
|
9319
|
-
triggerId:
|
|
9320
|
-
triggerType:
|
|
9266
|
+
triggerId: automation.definition?.trigger?.id,
|
|
9267
|
+
triggerType: automation.definition?.trigger?.stepId,
|
|
9321
9268
|
audited: {
|
|
9322
9269
|
name: automation.name
|
|
9323
9270
|
}
|
|
@@ -9325,22 +9272,20 @@ async function created3(automation, timestamp) {
|
|
|
9325
9272
|
await publishEvent("automation:created" /* AUTOMATION_CREATED */, properties, timestamp);
|
|
9326
9273
|
}
|
|
9327
9274
|
async function triggerUpdated(automation) {
|
|
9328
|
-
var _a, _b, _c, _d;
|
|
9329
9275
|
const properties = {
|
|
9330
9276
|
appId: automation.appId,
|
|
9331
9277
|
automationId: automation._id,
|
|
9332
|
-
triggerId:
|
|
9333
|
-
triggerType:
|
|
9278
|
+
triggerId: automation.definition?.trigger?.id,
|
|
9279
|
+
triggerType: automation.definition?.trigger?.stepId
|
|
9334
9280
|
};
|
|
9335
9281
|
await publishEvent("automation:trigger:updated" /* AUTOMATION_TRIGGER_UPDATED */, properties);
|
|
9336
9282
|
}
|
|
9337
9283
|
async function deleted3(automation) {
|
|
9338
|
-
var _a, _b, _c, _d;
|
|
9339
9284
|
const properties = {
|
|
9340
9285
|
appId: automation.appId,
|
|
9341
9286
|
automationId: automation._id,
|
|
9342
|
-
triggerId:
|
|
9343
|
-
triggerType:
|
|
9287
|
+
triggerId: automation.definition?.trigger?.id,
|
|
9288
|
+
triggerType: automation.definition?.trigger?.stepId,
|
|
9344
9289
|
audited: {
|
|
9345
9290
|
name: automation.name
|
|
9346
9291
|
}
|
|
@@ -9348,12 +9293,11 @@ async function deleted3(automation) {
|
|
|
9348
9293
|
await publishEvent("automation:deleted" /* AUTOMATION_DELETED */, properties);
|
|
9349
9294
|
}
|
|
9350
9295
|
async function tested(automation) {
|
|
9351
|
-
var _a, _b, _c, _d;
|
|
9352
9296
|
const properties = {
|
|
9353
9297
|
appId: automation.appId,
|
|
9354
9298
|
automationId: automation._id,
|
|
9355
|
-
triggerId:
|
|
9356
|
-
triggerType:
|
|
9299
|
+
triggerId: automation.definition?.trigger?.id,
|
|
9300
|
+
triggerType: automation.definition?.trigger?.stepId
|
|
9357
9301
|
};
|
|
9358
9302
|
await publishEvent("automation:tested" /* AUTOMATION_TESTED */, properties);
|
|
9359
9303
|
}
|
|
@@ -9364,12 +9308,11 @@ var run = async (count, timestamp) => {
|
|
|
9364
9308
|
await publishEvent("automations:run" /* AUTOMATIONS_RUN */, properties, timestamp);
|
|
9365
9309
|
};
|
|
9366
9310
|
async function stepCreated(automation, step, timestamp) {
|
|
9367
|
-
var _a, _b, _c, _d;
|
|
9368
9311
|
const properties = {
|
|
9369
9312
|
appId: automation.appId,
|
|
9370
9313
|
automationId: automation._id,
|
|
9371
|
-
triggerId:
|
|
9372
|
-
triggerType:
|
|
9314
|
+
triggerId: automation.definition?.trigger?.id,
|
|
9315
|
+
triggerType: automation.definition?.trigger?.stepId,
|
|
9373
9316
|
stepId: step.id,
|
|
9374
9317
|
stepType: step.stepId,
|
|
9375
9318
|
audited: {
|
|
@@ -9379,12 +9322,11 @@ async function stepCreated(automation, step, timestamp) {
|
|
|
9379
9322
|
await publishEvent("automation:step:created" /* AUTOMATION_STEP_CREATED */, properties, timestamp);
|
|
9380
9323
|
}
|
|
9381
9324
|
async function stepDeleted(automation, step) {
|
|
9382
|
-
var _a, _b, _c, _d;
|
|
9383
9325
|
const properties = {
|
|
9384
9326
|
appId: automation.appId,
|
|
9385
9327
|
automationId: automation._id,
|
|
9386
|
-
triggerId:
|
|
9387
|
-
triggerType:
|
|
9328
|
+
triggerId: automation.definition?.trigger?.id,
|
|
9329
|
+
triggerType: automation.definition?.trigger?.stepId,
|
|
9388
9330
|
stepId: step.id,
|
|
9389
9331
|
stepType: step.stepId,
|
|
9390
9332
|
audited: {
|
|
@@ -9671,25 +9613,23 @@ var role_default = {
|
|
|
9671
9613
|
// src/events/publishers/screen.ts
|
|
9672
9614
|
init_src();
|
|
9673
9615
|
async function created8(screen, timestamp) {
|
|
9674
|
-
var _a;
|
|
9675
9616
|
const properties = {
|
|
9676
9617
|
layoutId: screen.layoutId,
|
|
9677
9618
|
screenId: screen._id,
|
|
9678
9619
|
roleId: screen.routing.roleId,
|
|
9679
9620
|
audited: {
|
|
9680
|
-
name:
|
|
9621
|
+
name: screen.routing?.route
|
|
9681
9622
|
}
|
|
9682
9623
|
};
|
|
9683
9624
|
await publishEvent("screen:created" /* SCREEN_CREATED */, properties, timestamp);
|
|
9684
9625
|
}
|
|
9685
9626
|
async function deleted8(screen) {
|
|
9686
|
-
var _a;
|
|
9687
9627
|
const properties = {
|
|
9688
9628
|
layoutId: screen.layoutId,
|
|
9689
9629
|
screenId: screen._id,
|
|
9690
9630
|
roleId: screen.routing.roleId,
|
|
9691
9631
|
audited: {
|
|
9692
|
-
name:
|
|
9632
|
+
name: screen.routing?.route
|
|
9693
9633
|
}
|
|
9694
9634
|
};
|
|
9695
9635
|
await publishEvent("screen:deleted" /* SCREEN_DELETED */, properties);
|
|
@@ -10625,8 +10565,7 @@ var BUILTIN_PERMISSIONS = {
|
|
|
10625
10565
|
name: "Read only",
|
|
10626
10566
|
permissions: [
|
|
10627
10567
|
new Permission("query" /* QUERY */, "read" /* READ */),
|
|
10628
|
-
new Permission("table" /* TABLE */, "read" /* READ */)
|
|
10629
|
-
new Permission("view" /* VIEW */, "read" /* READ */)
|
|
10568
|
+
new Permission("table" /* TABLE */, "read" /* READ */)
|
|
10630
10569
|
]
|
|
10631
10570
|
},
|
|
10632
10571
|
WRITE: {
|
|
@@ -10635,7 +10574,6 @@ var BUILTIN_PERMISSIONS = {
|
|
|
10635
10574
|
permissions: [
|
|
10636
10575
|
new Permission("query" /* QUERY */, "write" /* WRITE */),
|
|
10637
10576
|
new Permission("table" /* TABLE */, "write" /* WRITE */),
|
|
10638
|
-
new Permission("view" /* VIEW */, "read" /* READ */),
|
|
10639
10577
|
new Permission("automation" /* AUTOMATION */, "execute" /* EXECUTE */)
|
|
10640
10578
|
]
|
|
10641
10579
|
},
|
|
@@ -10646,7 +10584,6 @@ var BUILTIN_PERMISSIONS = {
|
|
|
10646
10584
|
new Permission("table" /* TABLE */, "write" /* WRITE */),
|
|
10647
10585
|
new Permission("user" /* USER */, "read" /* READ */),
|
|
10648
10586
|
new Permission("automation" /* AUTOMATION */, "execute" /* EXECUTE */),
|
|
10649
|
-
new Permission("view" /* VIEW */, "read" /* READ */),
|
|
10650
10587
|
new Permission("webhook" /* WEBHOOK */, "read" /* READ */)
|
|
10651
10588
|
]
|
|
10652
10589
|
},
|
|
@@ -10657,7 +10594,6 @@ var BUILTIN_PERMISSIONS = {
|
|
|
10657
10594
|
new Permission("table" /* TABLE */, "admin" /* ADMIN */),
|
|
10658
10595
|
new Permission("user" /* USER */, "admin" /* ADMIN */),
|
|
10659
10596
|
new Permission("automation" /* AUTOMATION */, "admin" /* ADMIN */),
|
|
10660
|
-
new Permission("view" /* VIEW */, "admin" /* ADMIN */),
|
|
10661
10597
|
new Permission("webhook" /* WEBHOOK */, "read" /* READ */),
|
|
10662
10598
|
new Permission("query" /* QUERY */, "admin" /* ADMIN */)
|
|
10663
10599
|
]
|
|
@@ -10760,7 +10696,7 @@ var BUILTIN_ROLE_NAME_ARRAY = Object.values(BUILTIN_ROLES).map(
|
|
|
10760
10696
|
(role) => role.name
|
|
10761
10697
|
);
|
|
10762
10698
|
function isBuiltin(role) {
|
|
10763
|
-
return BUILTIN_ROLE_ID_ARRAY.some((builtin) => role
|
|
10699
|
+
return BUILTIN_ROLE_ID_ARRAY.some((builtin) => role?.includes(builtin));
|
|
10764
10700
|
}
|
|
10765
10701
|
function builtinRoleToNumber(id) {
|
|
10766
10702
|
if (!id) {
|
|
@@ -10787,7 +10723,7 @@ async function roleToNumber(id) {
|
|
|
10787
10723
|
}
|
|
10788
10724
|
const hierarchy = await getUserRoleHierarchy(id);
|
|
10789
10725
|
for (let role of hierarchy) {
|
|
10790
|
-
if (isBuiltin(role
|
|
10726
|
+
if (isBuiltin(role?.inherits)) {
|
|
10791
10727
|
return builtinRoleToNumber(role.inherits) + 1;
|
|
10792
10728
|
}
|
|
10793
10729
|
}
|
|
@@ -10820,7 +10756,7 @@ async function getRole(roleId, opts) {
|
|
|
10820
10756
|
role = Object.assign(role, dbRole);
|
|
10821
10757
|
role._id = getExternalRoleID(role._id, role.version);
|
|
10822
10758
|
} catch (err) {
|
|
10823
|
-
if (!isBuiltin(roleId) &&
|
|
10759
|
+
if (!isBuiltin(roleId) && opts?.defaultPublic) {
|
|
10824
10760
|
return (0, import_cloneDeep2.default)(BUILTIN_ROLES.PUBLIC);
|
|
10825
10761
|
}
|
|
10826
10762
|
if (Object.keys(role).length === 0) {
|
|
@@ -10943,7 +10879,7 @@ var AccessController = class {
|
|
|
10943
10879
|
});
|
|
10944
10880
|
this.userHierarchies[userRoleId] = roleIds;
|
|
10945
10881
|
}
|
|
10946
|
-
return
|
|
10882
|
+
return roleIds?.indexOf(tryingRoleId) !== -1;
|
|
10947
10883
|
}
|
|
10948
10884
|
async checkScreensAccess(screens, userRoleId) {
|
|
10949
10885
|
let accessibleScreens = [];
|
|
@@ -10964,7 +10900,7 @@ var AccessController = class {
|
|
|
10964
10900
|
}
|
|
10965
10901
|
};
|
|
10966
10902
|
function getDBRoleID(roleName) {
|
|
10967
|
-
if (roleName
|
|
10903
|
+
if (roleName?.startsWith("role" /* ROLE */)) {
|
|
10968
10904
|
return roleName;
|
|
10969
10905
|
}
|
|
10970
10906
|
return prefixRoleID(roleName);
|
|
@@ -11246,8 +11182,7 @@ async function authenticate2(details, requireLocalAccount = true, done, saveUser
|
|
|
11246
11182
|
return done(null, ssoUser);
|
|
11247
11183
|
}
|
|
11248
11184
|
async function getProfilePictureUrl(user, details) {
|
|
11249
|
-
|
|
11250
|
-
const pictureUrl = (_a = details.profile) == null ? void 0 : _a._json.picture;
|
|
11185
|
+
const pictureUrl = details.profile?._json.picture;
|
|
11251
11186
|
if (pictureUrl) {
|
|
11252
11187
|
const response = await (0, import_node_fetch5.default)(pictureUrl);
|
|
11253
11188
|
if (response.status === 200) {
|
|
@@ -11778,7 +11713,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
|
|
|
11778
11713
|
user = await getUser(userId, session.tenantId);
|
|
11779
11714
|
}
|
|
11780
11715
|
user.csrfToken = session.csrfToken;
|
|
11781
|
-
if (
|
|
11716
|
+
if (session?.lastAccessedAt < timeMinusOneMinute()) {
|
|
11782
11717
|
await updateSessionTTL(session);
|
|
11783
11718
|
}
|
|
11784
11719
|
authenticated = true;
|
|
@@ -11820,9 +11755,9 @@ function authenticated_default(noAuthPatterns = [], opts = {
|
|
|
11820
11755
|
} catch (err) {
|
|
11821
11756
|
console.error(`Auth Error: ${err.message}`);
|
|
11822
11757
|
console.error(err);
|
|
11823
|
-
if (
|
|
11758
|
+
if (err?.name === "JsonWebTokenError") {
|
|
11824
11759
|
clearCookie(ctx, "budibase:auth" /* Auth */);
|
|
11825
|
-
} else if (
|
|
11760
|
+
} else if (err?.code === "invalid_api_key" /* INVALID_API_KEY */) {
|
|
11826
11761
|
ctx.throw(403, err.message);
|
|
11827
11762
|
}
|
|
11828
11763
|
if (opts && opts.publicAllowed || publicEndpoint) {
|
|
@@ -11889,7 +11824,6 @@ var INCLUDED_CONTENT_TYPES = [
|
|
|
11889
11824
|
function csrf_default(opts = { noCsrfPatterns: [] }) {
|
|
11890
11825
|
const noCsrfOptions = buildMatcherRegex(opts.noCsrfPatterns);
|
|
11891
11826
|
return async (ctx, next) => {
|
|
11892
|
-
var _a;
|
|
11893
11827
|
const found = matches(ctx, noCsrfOptions);
|
|
11894
11828
|
if (found) {
|
|
11895
11829
|
return next();
|
|
@@ -11904,7 +11838,7 @@ function csrf_default(opts = { noCsrfPatterns: [] }) {
|
|
|
11904
11838
|
if (ctx.internal) {
|
|
11905
11839
|
return next();
|
|
11906
11840
|
}
|
|
11907
|
-
const userToken =
|
|
11841
|
+
const userToken = ctx.user?.csrfToken;
|
|
11908
11842
|
if (!userToken) {
|
|
11909
11843
|
return next();
|
|
11910
11844
|
}
|
|
@@ -11964,10 +11898,7 @@ function pinoSettings() {
|
|
|
11964
11898
|
logger,
|
|
11965
11899
|
genReqId: correlator2.getId,
|
|
11966
11900
|
autoLogging: {
|
|
11967
|
-
ignore: (req) =>
|
|
11968
|
-
var _a;
|
|
11969
|
-
return !!((_a = req.url) == null ? void 0 : _a.includes("/health"));
|
|
11970
|
-
}
|
|
11901
|
+
ignore: (req) => !!req.url?.includes("/health")
|
|
11971
11902
|
},
|
|
11972
11903
|
serializers: {
|
|
11973
11904
|
req: (req) => {
|
|
@@ -12038,8 +11969,7 @@ var errorHandling_default = errorHandling;
|
|
|
12038
11969
|
|
|
12039
11970
|
// src/middleware/querystringToBody.ts
|
|
12040
11971
|
function querystringToBody_default(ctx, next) {
|
|
12041
|
-
|
|
12042
|
-
const queryString = (_a = ctx.request.query) == null ? void 0 : _a.query;
|
|
11972
|
+
const queryString = ctx.request.query?.query;
|
|
12043
11973
|
if (ctx.request.method.toLowerCase() !== "get") {
|
|
12044
11974
|
ctx.throw(
|
|
12045
11975
|
500,
|
|
@@ -12069,12 +11999,11 @@ __export(joi_validator_exports, {
|
|
|
12069
11999
|
var import_joi = __toESM(require("joi"));
|
|
12070
12000
|
function validate(schema, property) {
|
|
12071
12001
|
return (ctx, next) => {
|
|
12072
|
-
var _a;
|
|
12073
12002
|
if (!schema) {
|
|
12074
12003
|
return next();
|
|
12075
12004
|
}
|
|
12076
12005
|
let params2 = null;
|
|
12077
|
-
let reqProp =
|
|
12006
|
+
let reqProp = ctx.request?.[property];
|
|
12078
12007
|
if (ctx[property] != null) {
|
|
12079
12008
|
params2 = ctx[property];
|
|
12080
12009
|
} else if (reqProp != null) {
|
|
@@ -12213,7 +12142,6 @@ async function updateUserOAuth(userId, oAuthConfig) {
|
|
|
12213
12142
|
}
|
|
12214
12143
|
}
|
|
12215
12144
|
async function platformLogout(opts) {
|
|
12216
|
-
var _a;
|
|
12217
12145
|
const ctx = opts.ctx;
|
|
12218
12146
|
const userId = opts.userId;
|
|
12219
12147
|
const keepActiveSession = opts.keepActiveSession;
|
|
@@ -12230,7 +12158,7 @@ async function platformLogout(opts) {
|
|
|
12230
12158
|
}
|
|
12231
12159
|
const sessionIds = sessions.map(({ sessionId }) => sessionId);
|
|
12232
12160
|
await invalidateSessions(userId, { sessionIds, reason: "logout" });
|
|
12233
|
-
await auth_default.logout(
|
|
12161
|
+
await auth_default.logout(ctx.user?.email);
|
|
12234
12162
|
await invalidateUser(userId);
|
|
12235
12163
|
}
|
|
12236
12164
|
|
|
@@ -12346,7 +12274,7 @@ function validateAutomation(schema) {
|
|
|
12346
12274
|
runJoi(validator, schema);
|
|
12347
12275
|
}
|
|
12348
12276
|
function validate2(schema) {
|
|
12349
|
-
switch (schema
|
|
12277
|
+
switch (schema?.type) {
|
|
12350
12278
|
case "component" /* COMPONENT */:
|
|
12351
12279
|
validateComponent(schema);
|
|
12352
12280
|
break;
|
|
@@ -12410,7 +12338,7 @@ async function lookup(address) {
|
|
|
12410
12338
|
}
|
|
12411
12339
|
async function refreshBlacklist() {
|
|
12412
12340
|
const blacklist = environment_default.BLACKLIST_IPS;
|
|
12413
|
-
const list =
|
|
12341
|
+
const list = blacklist?.split(",") || [];
|
|
12414
12342
|
let final = [];
|
|
12415
12343
|
for (let addr of list) {
|
|
12416
12344
|
const trimmed = addr.trim();
|
|
@@ -12427,7 +12355,7 @@ async function isBlacklisted(address) {
|
|
|
12427
12355
|
if (!blackListArray) {
|
|
12428
12356
|
await refreshBlacklist();
|
|
12429
12357
|
}
|
|
12430
|
-
if (
|
|
12358
|
+
if (blackListArray?.length === 0) {
|
|
12431
12359
|
return false;
|
|
12432
12360
|
}
|
|
12433
12361
|
let ips;
|
|
@@ -12436,7 +12364,7 @@ async function isBlacklisted(address) {
|
|
|
12436
12364
|
} else {
|
|
12437
12365
|
ips = [address];
|
|
12438
12366
|
}
|
|
12439
|
-
return !!
|
|
12367
|
+
return !!blackListArray?.find((addr) => ips.includes(addr));
|
|
12440
12368
|
}
|
|
12441
12369
|
|
|
12442
12370
|
// src/docUpdates/index.ts
|