@budibase/backend-core 2.9.30-alpha.9 → 2.9.31

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 CHANGED
@@ -29,6 +29,28 @@ 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
+ };
32
54
 
33
55
  // ../types/src/sdk/automations/index.ts
34
56
  var init_automations = __esm({
@@ -683,19 +705,13 @@ var init_permissions = __esm({
683
705
  PermissionType2["WEBHOOK"] = "webhook";
684
706
  PermissionType2["BUILDER"] = "builder";
685
707
  PermissionType2["GLOBAL_BUILDER"] = "globalBuilder";
708
+ PermissionType2["VIEW"] = "view";
686
709
  PermissionType2["QUERY"] = "query";
687
710
  return PermissionType2;
688
711
  })(PermissionType || {});
689
712
  }
690
713
  });
691
714
 
692
- // ../types/src/sdk/row.ts
693
- var init_row = __esm({
694
- "../types/src/sdk/row.ts"() {
695
- "use strict";
696
- }
697
- });
698
-
699
715
  // ../types/src/sdk/index.ts
700
716
  var init_sdk = __esm({
701
717
  "../types/src/sdk/index.ts"() {
@@ -721,7 +737,6 @@ var init_sdk = __esm({
721
737
  init_cli();
722
738
  init_websocket();
723
739
  init_permissions();
724
- init_row();
725
740
  }
726
741
  });
727
742
 
@@ -951,7 +966,7 @@ var init_document = __esm({
951
966
  });
952
967
 
953
968
  // ../types/src/documents/app/row.ts
954
- var init_row2 = __esm({
969
+ var init_row = __esm({
955
970
  "../types/src/documents/app/row.ts"() {
956
971
  "use strict";
957
972
  }
@@ -1006,7 +1021,7 @@ var init_app3 = __esm({
1006
1021
  init_screen2();
1007
1022
  init_view2();
1008
1023
  init_document();
1009
- init_row2();
1024
+ init_row();
1010
1025
  init_user4();
1011
1026
  init_backup2();
1012
1027
  init_webhook();
@@ -1286,7 +1301,7 @@ var init_datasource3 = __esm({
1286
1301
  });
1287
1302
 
1288
1303
  // ../types/src/api/web/app/row.ts
1289
- var init_row3 = __esm({
1304
+ var init_row2 = __esm({
1290
1305
  "../types/src/api/web/app/row.ts"() {
1291
1306
  "use strict";
1292
1307
  }
@@ -1319,7 +1334,7 @@ var init_app4 = __esm({
1319
1334
  "use strict";
1320
1335
  init_backup3();
1321
1336
  init_datasource3();
1322
- init_row3();
1337
+ init_row2();
1323
1338
  init_view3();
1324
1339
  init_rows2();
1325
1340
  init_table4();
@@ -1412,13 +1427,6 @@ var init_pagination = __esm({
1412
1427
  }
1413
1428
  });
1414
1429
 
1415
- // ../types/src/api/web/searchFilter.ts
1416
- var init_searchFilter = __esm({
1417
- "../types/src/api/web/searchFilter.ts"() {
1418
- "use strict";
1419
- }
1420
- });
1421
-
1422
1430
  // ../types/src/api/web/index.ts
1423
1431
  var init_web = __esm({
1424
1432
  "../types/src/api/web/index.ts"() {
@@ -1433,7 +1441,6 @@ var init_web = __esm({
1433
1441
  init_app4();
1434
1442
  init_global2();
1435
1443
  init_pagination();
1436
- init_searchFilter();
1437
1444
  }
1438
1445
  });
1439
1446
 
@@ -1865,15 +1872,12 @@ var init_environment2 = __esm({
1865
1872
  });
1866
1873
 
1867
1874
  // src/context/Context.ts
1868
- var import_async_hooks, Context;
1875
+ var import_async_hooks, _Context, Context;
1869
1876
  var init_Context = __esm({
1870
1877
  "src/context/Context.ts"() {
1871
1878
  "use strict";
1872
1879
  import_async_hooks = require("async_hooks");
1873
- Context = class _Context {
1874
- static {
1875
- this.storage = new import_async_hooks.AsyncLocalStorage();
1876
- }
1880
+ _Context = class _Context {
1877
1881
  static run(context, func) {
1878
1882
  return _Context.storage.run(context, () => func());
1879
1883
  }
@@ -1881,6 +1885,8 @@ var init_Context = __esm({
1881
1885
  return _Context.storage.getStore();
1882
1886
  }
1883
1887
  };
1888
+ _Context.storage = new import_async_hooks.AsyncLocalStorage();
1889
+ Context = _Context;
1884
1890
  }
1885
1891
  });
1886
1892
 
@@ -1922,7 +1928,7 @@ function getProdAppID(appId) {
1922
1928
  return `${APP_PREFIX}${rest}`;
1923
1929
  }
1924
1930
  function extractAppUUID(id) {
1925
- const split = id?.split("_") || [];
1931
+ const split = (id == null ? void 0 : id.split("_")) || [];
1926
1932
  return split.length ? split[split.length - 1] : null;
1927
1933
  }
1928
1934
  var NO_APP_ERROR, getDevAppID;
@@ -1942,17 +1948,18 @@ var init_connections = __esm({
1942
1948
  "use strict";
1943
1949
  init_environment2();
1944
1950
  getCouchInfo = (connection) => {
1951
+ var _a, _b;
1945
1952
  const urlInfo = getUrlInfo(connection);
1946
1953
  let username;
1947
1954
  let password;
1948
- if (urlInfo.auth?.username) {
1955
+ if ((_a = urlInfo.auth) == null ? void 0 : _a.username) {
1949
1956
  username = urlInfo.auth.username;
1950
1957
  } else if (environment_default.COUCH_DB_USERNAME) {
1951
1958
  username = environment_default.COUCH_DB_USERNAME;
1952
1959
  } else if (!environment_default.isTest()) {
1953
1960
  throw new Error("CouchDB username not set");
1954
1961
  }
1955
- if (urlInfo.auth?.password) {
1962
+ if ((_b = urlInfo.auth) == null ? void 0 : _b.password) {
1956
1963
  password = urlInfo.auth.password;
1957
1964
  } else if (environment_default.COUCH_DB_PASSWORD) {
1958
1965
  password = environment_default.COUCH_DB_PASSWORD;
@@ -2211,7 +2218,8 @@ var init_DatabaseImpl = __esm({
2211
2218
  return this.instanceNano || _DatabaseImpl.nano;
2212
2219
  }
2213
2220
  async checkSetup() {
2214
- let shouldCreate = !this.pouchOpts?.skip_setup;
2221
+ var _a;
2222
+ let shouldCreate = !((_a = this.pouchOpts) == null ? void 0 : _a.skip_setup);
2215
2223
  let exists2 = await this.exists();
2216
2224
  if (!shouldCreate && !exists2) {
2217
2225
  throw new Error("DB does not exist");
@@ -2287,7 +2295,7 @@ var init_DatabaseImpl = __esm({
2287
2295
  document.createdAt = (/* @__PURE__ */ new Date()).toISOString();
2288
2296
  }
2289
2297
  document.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
2290
- if (opts?.force && document._id) {
2298
+ if ((opts == null ? void 0 : opts.force) && document._id) {
2291
2299
  try {
2292
2300
  const existing = await this.get(document._id);
2293
2301
  if (existing) {
@@ -2451,7 +2459,7 @@ function isMultiTenant() {
2451
2459
  }
2452
2460
  function isTenantIdSet() {
2453
2461
  const context = Context.get();
2454
- return !!context?.tenantId;
2462
+ return !!(context == null ? void 0 : context.tenantId);
2455
2463
  }
2456
2464
  function isTenancyEnabled() {
2457
2465
  return environment_default.MULTI_TENANCY;
@@ -2550,7 +2558,7 @@ async function doInIdentityContext(identity, task) {
2550
2558
  function getIdentity() {
2551
2559
  try {
2552
2560
  const context = Context.get();
2553
- return context?.identity;
2561
+ return context == null ? void 0 : context.identity;
2554
2562
  } catch (e) {
2555
2563
  }
2556
2564
  }
@@ -2559,7 +2567,7 @@ function getTenantId() {
2559
2567
  return DEFAULT_TENANT_ID;
2560
2568
  }
2561
2569
  const context = Context.get();
2562
- const tenantId = context?.tenantId;
2570
+ const tenantId = context == null ? void 0 : context.tenantId;
2563
2571
  if (!tenantId) {
2564
2572
  throw new Error("Tenant id not found");
2565
2573
  }
@@ -2567,11 +2575,11 @@ function getTenantId() {
2567
2575
  }
2568
2576
  function getAutomationId() {
2569
2577
  const context = Context.get();
2570
- return context?.automationId;
2578
+ return context == null ? void 0 : context.automationId;
2571
2579
  }
2572
2580
  function getAppId() {
2573
2581
  const context = Context.get();
2574
- const foundId = context?.appId;
2582
+ const foundId = context == null ? void 0 : context.appId;
2575
2583
  if (!foundId && environment_default.isTest() && TEST_APP_ID) {
2576
2584
  return TEST_APP_ID;
2577
2585
  } else {
@@ -2606,7 +2614,7 @@ function getGlobalDB() {
2606
2614
  if (!context || environment_default.MULTI_TENANCY && !context.tenantId) {
2607
2615
  throw new Error("Global DB not found");
2608
2616
  }
2609
- return getDB(baseGlobalDBName(context?.tenantId));
2617
+ return getDB(baseGlobalDBName(context == null ? void 0 : context.tenantId));
2610
2618
  }
2611
2619
  function getAuditLogsDB() {
2612
2620
  if (!getTenantId()) {
@@ -2634,7 +2642,7 @@ function getDevAppDB(opts) {
2634
2642
  }
2635
2643
  function isScim() {
2636
2644
  const context = Context.get();
2637
- const scimCall = context?.isScim;
2645
+ const scimCall = context == null ? void 0 : context.isScim;
2638
2646
  return !!scimCall;
2639
2647
  }
2640
2648
  var TEST_APP_ID, getProdAppId;
@@ -3485,7 +3493,7 @@ function getGlobalUserParams(globalId, otherProps = {}) {
3485
3493
  if (!globalId) {
3486
3494
  globalId = "";
3487
3495
  }
3488
- const startkey = otherProps?.startkey;
3496
+ const startkey = otherProps == null ? void 0 : otherProps.startkey;
3489
3497
  return {
3490
3498
  ...otherProps,
3491
3499
  // need to include this incase pagination
@@ -3618,7 +3626,10 @@ async function getAllApps({
3618
3626
  } else {
3619
3627
  const response = await Promise.allSettled(appPromises);
3620
3628
  const apps = response.filter(
3621
- (result) => result.status === "fulfilled" && result.value?.state !== "invalid" /* INVALID */
3629
+ (result) => {
3630
+ var _a;
3631
+ return result.status === "fulfilled" && ((_a = result.value) == null ? void 0 : _a.state) !== "invalid" /* INVALID */;
3632
+ }
3622
3633
  ).map(({ value }) => value);
3623
3634
  if (!all) {
3624
3635
  return apps.filter((app) => {
@@ -3680,7 +3691,7 @@ function pagination(data, pageSize, {
3680
3691
  const hasNextPage = data.length > pageSize;
3681
3692
  let nextPage = void 0;
3682
3693
  if (!getKey) {
3683
- getKey = (doc) => property ? doc?.[property] : doc?._id;
3694
+ getKey = (doc) => property ? doc == null ? void 0 : doc[property] : doc == null ? void 0 : doc._id;
3684
3695
  }
3685
3696
  if (hasNextPage) {
3686
3697
  nextPage = getKey(data[pageSize]);
@@ -3831,7 +3842,7 @@ var init_views = __esm({
3831
3842
  const docs = rows.map(
3832
3843
  (row) => params2.include_docs ? row.doc : row.value
3833
3844
  );
3834
- if (opts?.arrayResponse) {
3845
+ if (opts == null ? void 0 : opts.arrayResponse) {
3835
3846
  return docs;
3836
3847
  } else {
3837
3848
  return docs.length <= 1 ? docs[0] : docs;
@@ -4054,37 +4065,39 @@ async function fullSearch(dbName, index2, query, params2) {
4054
4065
  const rows = await recursiveSearch(dbName, index2, query, params2);
4055
4066
  return { rows };
4056
4067
  }
4057
- var import_node_fetch2, QUERY_START_REGEX, QueryBuilder;
4068
+ var import_node_fetch2, QUERY_START_REGEX, _dbName, _index, _query, _limit, _sort, _bookmark, _sortOrder, _sortType, _includeDocs, _version, _indexBuilder, _noEscaping, _skip, _skipItems, skipItems_fn, _execute, execute_fn, _QueryBuilder, QueryBuilder;
4058
4069
  var init_lucene = __esm({
4059
4070
  "src/db/lucene.ts"() {
4060
4071
  "use strict";
4061
4072
  import_node_fetch2 = __toESM(require("node-fetch"));
4062
4073
  init_couch();
4063
- init_src();
4064
4074
  QUERY_START_REGEX = /\d[0-9]*:/g;
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
- }
4075
+ _QueryBuilder = class _QueryBuilder {
4082
4076
  constructor(dbName, index2, base) {
4083
- this.#dbName = dbName;
4084
- this.#index = index2;
4085
- this.#query = {
4077
+ /**
4078
+ * Lucene queries do not support pagination and use bookmarks instead.
4079
+ * For the given builder, walk through pages using bookmarks until the desired
4080
+ * page has been met.
4081
+ */
4082
+ __privateAdd(this, _skipItems);
4083
+ __privateAdd(this, _execute);
4084
+ __privateAdd(this, _dbName, void 0);
4085
+ __privateAdd(this, _index, void 0);
4086
+ __privateAdd(this, _query, void 0);
4087
+ __privateAdd(this, _limit, void 0);
4088
+ __privateAdd(this, _sort, void 0);
4089
+ __privateAdd(this, _bookmark, void 0);
4090
+ __privateAdd(this, _sortOrder, void 0);
4091
+ __privateAdd(this, _sortType, void 0);
4092
+ __privateAdd(this, _includeDocs, void 0);
4093
+ __privateAdd(this, _version, void 0);
4094
+ __privateAdd(this, _indexBuilder, void 0);
4095
+ __privateAdd(this, _noEscaping, false);
4096
+ __privateAdd(this, _skip, void 0);
4097
+ __privateSet(this, _dbName, dbName);
4098
+ __privateSet(this, _index, index2);
4099
+ __privateSet(this, _query, {
4086
4100
  allOr: false,
4087
- onEmptyFilter: "all" /* RETURN_ALL */,
4088
4101
  string: {},
4089
4102
  fuzzy: {},
4090
4103
  range: {},
@@ -4097,127 +4110,124 @@ var init_lucene = __esm({
4097
4110
  notContains: {},
4098
4111
  containsAny: {},
4099
4112
  ...base
4100
- };
4101
- this.#limit = 50;
4102
- this.#sortOrder = "ascending";
4103
- this.#sortType = "string";
4104
- this.#includeDocs = true;
4113
+ });
4114
+ __privateSet(this, _limit, 50);
4115
+ __privateSet(this, _sortOrder, "ascending");
4116
+ __privateSet(this, _sortType, "string");
4117
+ __privateSet(this, _includeDocs, true);
4105
4118
  }
4106
4119
  disableEscaping() {
4107
- this.#noEscaping = true;
4120
+ __privateSet(this, _noEscaping, true);
4108
4121
  return this;
4109
4122
  }
4110
4123
  setIndexBuilder(builderFn) {
4111
- this.#indexBuilder = builderFn;
4124
+ __privateSet(this, _indexBuilder, builderFn);
4112
4125
  return this;
4113
4126
  }
4114
4127
  setVersion(version) {
4115
4128
  if (version != null) {
4116
- this.#version = version;
4129
+ __privateSet(this, _version, version);
4117
4130
  }
4118
4131
  return this;
4119
4132
  }
4120
4133
  setTable(tableId) {
4121
- this.#query.equal.tableId = tableId;
4134
+ __privateGet(this, _query).equal.tableId = tableId;
4122
4135
  return this;
4123
4136
  }
4124
4137
  setLimit(limit) {
4125
4138
  if (limit != null) {
4126
- this.#limit = limit;
4139
+ __privateSet(this, _limit, limit);
4127
4140
  }
4128
4141
  return this;
4129
4142
  }
4130
4143
  setSort(sort) {
4131
4144
  if (sort != null) {
4132
- this.#sort = sort;
4145
+ __privateSet(this, _sort, sort);
4133
4146
  }
4134
4147
  return this;
4135
4148
  }
4136
4149
  setSortOrder(sortOrder) {
4137
4150
  if (sortOrder != null) {
4138
- this.#sortOrder = sortOrder;
4151
+ __privateSet(this, _sortOrder, sortOrder);
4139
4152
  }
4140
4153
  return this;
4141
4154
  }
4142
4155
  setSortType(sortType) {
4143
4156
  if (sortType != null) {
4144
- this.#sortType = sortType;
4157
+ __privateSet(this, _sortType, sortType);
4145
4158
  }
4146
4159
  return this;
4147
4160
  }
4148
4161
  setBookmark(bookmark) {
4149
4162
  if (bookmark != null) {
4150
- this.#bookmark = bookmark;
4163
+ __privateSet(this, _bookmark, bookmark);
4151
4164
  }
4152
4165
  return this;
4153
4166
  }
4154
4167
  setSkip(skip) {
4155
- this.#skip = skip;
4168
+ __privateSet(this, _skip, skip);
4156
4169
  return this;
4157
4170
  }
4158
4171
  excludeDocs() {
4159
- this.#includeDocs = false;
4172
+ __privateSet(this, _includeDocs, false);
4160
4173
  return this;
4161
4174
  }
4162
4175
  includeDocs() {
4163
- this.#includeDocs = true;
4176
+ __privateSet(this, _includeDocs, true);
4164
4177
  return this;
4165
4178
  }
4166
4179
  addString(key, partial) {
4167
- this.#query.string[key] = partial;
4180
+ __privateGet(this, _query).string[key] = partial;
4168
4181
  return this;
4169
4182
  }
4170
4183
  addFuzzy(key, fuzzy) {
4171
- this.#query.fuzzy[key] = fuzzy;
4184
+ __privateGet(this, _query).fuzzy[key] = fuzzy;
4172
4185
  return this;
4173
4186
  }
4174
4187
  addRange(key, low, high) {
4175
- this.#query.range[key] = {
4188
+ __privateGet(this, _query).range[key] = {
4176
4189
  low,
4177
4190
  high
4178
4191
  };
4179
4192
  return this;
4180
4193
  }
4181
4194
  addEqual(key, value) {
4182
- this.#query.equal[key] = value;
4195
+ __privateGet(this, _query).equal[key] = value;
4183
4196
  return this;
4184
4197
  }
4185
4198
  addNotEqual(key, value) {
4186
- this.#query.notEqual[key] = value;
4199
+ __privateGet(this, _query).notEqual[key] = value;
4187
4200
  return this;
4188
4201
  }
4189
4202
  addEmpty(key, value) {
4190
- this.#query.empty[key] = value;
4203
+ __privateGet(this, _query).empty[key] = value;
4191
4204
  return this;
4192
4205
  }
4193
4206
  addNotEmpty(key, value) {
4194
- this.#query.notEmpty[key] = value;
4207
+ __privateGet(this, _query).notEmpty[key] = value;
4195
4208
  return this;
4196
4209
  }
4197
4210
  addOneOf(key, value) {
4198
- this.#query.oneOf[key] = value;
4211
+ __privateGet(this, _query).oneOf[key] = value;
4199
4212
  return this;
4200
4213
  }
4201
4214
  addContains(key, value) {
4202
- this.#query.contains[key] = value;
4215
+ __privateGet(this, _query).contains[key] = value;
4203
4216
  return this;
4204
4217
  }
4205
4218
  addNotContains(key, value) {
4206
- this.#query.notContains[key] = value;
4219
+ __privateGet(this, _query).notContains[key] = value;
4207
4220
  return this;
4208
4221
  }
4209
4222
  addContainsAny(key, value) {
4210
- this.#query.containsAny[key] = value;
4223
+ __privateGet(this, _query).containsAny[key] = value;
4211
4224
  return this;
4212
4225
  }
4213
4226
  setAllOr() {
4214
- this.#query.allOr = true;
4215
- }
4216
- setOnEmptyFilter(value) {
4217
- this.#query.onEmptyFilter = value;
4227
+ __privateGet(this, _query).allOr = true;
4218
4228
  }
4219
4229
  handleSpaces(input) {
4220
- if (this.#noEscaping) {
4230
+ if (__privateGet(this, _noEscaping)) {
4221
4231
  return input;
4222
4232
  } else {
4223
4233
  return input.replace(/ /g, "_");
@@ -4231,12 +4241,12 @@ var init_lucene = __esm({
4231
4241
  * @returns {string|*}
4232
4242
  */
4233
4243
  preprocess(value, { escape, lowercase, wrap, type } = {}) {
4234
- const hasVersion = !!this.#version;
4244
+ const hasVersion = !!__privateGet(this, _version);
4235
4245
  const originalType = typeof value;
4236
4246
  if (value && lowercase) {
4237
4247
  value = value.toLowerCase ? value.toLowerCase() : value;
4238
4248
  }
4239
- if (!this.#noEscaping && escape && originalType === "string") {
4249
+ if (!__privateGet(this, _noEscaping) && escape && originalType === "string") {
4240
4250
  value = `${value}`.replace(/[ \/#+\-&|!(){}\]^"~*?:\\]/g, "\\$&");
4241
4251
  }
4242
4252
  if (originalType === "string" && !isNaN(value) && !type) {
@@ -4248,7 +4258,7 @@ var init_lucene = __esm({
4248
4258
  }
4249
4259
  isMultiCondition() {
4250
4260
  let count = 0;
4251
- for (let filters of Object.values(this.#query)) {
4261
+ for (let filters of Object.values(__privateGet(this, _query))) {
4252
4262
  if (typeof filters === "object") {
4253
4263
  count += Object.keys(filters).length;
4254
4264
  }
@@ -4274,14 +4284,13 @@ var init_lucene = __esm({
4274
4284
  }
4275
4285
  buildSearchQuery() {
4276
4286
  const builder = this;
4277
- let allOr = this.#query && this.#query.allOr;
4287
+ let allOr = __privateGet(this, _query) && __privateGet(this, _query).allOr;
4278
4288
  let query = allOr ? "" : "*:*";
4279
- let allFiltersEmpty = true;
4280
4289
  const allPreProcessingOpts = { escape: true, lowercase: true, wrap: true };
4281
- let tableId = "";
4282
- if (this.#query.equal.tableId) {
4283
- tableId = this.#query.equal.tableId;
4284
- delete this.#query.equal.tableId;
4290
+ let tableId;
4291
+ if (__privateGet(this, _query).equal.tableId) {
4292
+ tableId = __privateGet(this, _query).equal.tableId;
4293
+ delete __privateGet(this, _query).equal.tableId;
4285
4294
  }
4286
4295
  const equal = (key, value) => {
4287
4296
  if (!value && value !== 0) {
@@ -4290,7 +4299,7 @@ var init_lucene = __esm({
4290
4299
  return `${key}:${builder.preprocess(value, allPreProcessingOpts)}`;
4291
4300
  };
4292
4301
  const contains = (key, value, mode = "AND") => {
4293
- if (!value || Array.isArray(value) && value.length === 0) {
4302
+ if (Array.isArray(value) && value.length === 0) {
4294
4303
  return null;
4295
4304
  }
4296
4305
  if (!Array.isArray(value)) {
@@ -4355,22 +4364,19 @@ var init_lucene = __esm({
4355
4364
  continue;
4356
4365
  }
4357
4366
  if (built.length > 0 || query.length > 0) {
4358
- const mode = opts?.mode ? opts.mode : allOr ? "OR" : "AND";
4367
+ const mode = (opts == null ? void 0 : opts.mode) ? opts.mode : allOr ? "OR" : "AND";
4359
4368
  built += ` ${mode} `;
4360
4369
  }
4361
4370
  built += expression;
4362
- if (typeof value !== "string" && value != null || typeof value === "string" && value !== tableId && value !== "") {
4363
- allFiltersEmpty = false;
4364
- }
4365
4371
  }
4366
- if (opts?.returnBuilt) {
4372
+ if (opts == null ? void 0 : opts.returnBuilt) {
4367
4373
  return built;
4368
4374
  } else {
4369
4375
  query += built;
4370
4376
  }
4371
4377
  }
4372
- if (this.#query.string) {
4373
- build(this.#query.string, (key, value) => {
4378
+ if (__privateGet(this, _query).string) {
4379
+ build(__privateGet(this, _query).string, (key, value) => {
4374
4380
  if (!value) {
4375
4381
  return null;
4376
4382
  }
@@ -4382,8 +4388,8 @@ var init_lucene = __esm({
4382
4388
  return `${key}:${value}*`;
4383
4389
  });
4384
4390
  }
4385
- if (this.#query.range) {
4386
- build(this.#query.range, (key, value) => {
4391
+ if (__privateGet(this, _query).range) {
4392
+ build(__privateGet(this, _query).range, (key, value) => {
4387
4393
  if (!value) {
4388
4394
  return null;
4389
4395
  }
@@ -4398,14 +4404,14 @@ var init_lucene = __esm({
4398
4404
  return `${key}:[${low} TO ${high}]`;
4399
4405
  });
4400
4406
  }
4401
- if (this.#query.fuzzy) {
4402
- build(this.#query.fuzzy, fuzzy);
4407
+ if (__privateGet(this, _query).fuzzy) {
4408
+ build(__privateGet(this, _query).fuzzy, fuzzy);
4403
4409
  }
4404
- if (this.#query.equal) {
4405
- build(this.#query.equal, equal);
4410
+ if (__privateGet(this, _query).equal) {
4411
+ build(__privateGet(this, _query).equal, equal);
4406
4412
  }
4407
- if (this.#query.notEqual) {
4408
- build(this.#query.notEqual, (key, value) => {
4413
+ if (__privateGet(this, _query).notEqual) {
4414
+ build(__privateGet(this, _query).notEqual, (key, value) => {
4409
4415
  if (!value) {
4410
4416
  return null;
4411
4417
  }
@@ -4415,98 +4421,103 @@ var init_lucene = __esm({
4415
4421
  return `!${key}:${builder.preprocess(value, allPreProcessingOpts)}`;
4416
4422
  });
4417
4423
  }
4418
- if (this.#query.empty) {
4419
- build(this.#query.empty, (key) => `(*:* -${key}:["" TO *])`);
4424
+ if (__privateGet(this, _query).empty) {
4425
+ build(__privateGet(this, _query).empty, (key) => `(*:* -${key}:["" TO *])`);
4420
4426
  }
4421
- if (this.#query.notEmpty) {
4422
- build(this.#query.notEmpty, (key) => `${key}:["" TO *]`);
4427
+ if (__privateGet(this, _query).notEmpty) {
4428
+ build(__privateGet(this, _query).notEmpty, (key) => `${key}:["" TO *]`);
4423
4429
  }
4424
- if (this.#query.oneOf) {
4425
- build(this.#query.oneOf, oneOf);
4430
+ if (__privateGet(this, _query).oneOf) {
4431
+ build(__privateGet(this, _query).oneOf, oneOf);
4426
4432
  }
4427
- if (this.#query.contains) {
4428
- build(this.#query.contains, contains);
4433
+ if (__privateGet(this, _query).contains) {
4434
+ build(__privateGet(this, _query).contains, contains);
4429
4435
  }
4430
- if (this.#query.notContains) {
4431
- build(this.compressFilters(this.#query.notContains), notContains);
4436
+ if (__privateGet(this, _query).notContains) {
4437
+ build(this.compressFilters(__privateGet(this, _query).notContains), notContains);
4432
4438
  }
4433
- if (this.#query.containsAny) {
4434
- build(this.#query.containsAny, containsAny);
4439
+ if (__privateGet(this, _query).containsAny) {
4440
+ build(__privateGet(this, _query).containsAny, containsAny);
4435
4441
  }
4436
4442
  if (tableId) {
4437
4443
  query = this.isMultiCondition() ? `(${query})` : query;
4438
4444
  allOr = false;
4439
4445
  build({ tableId }, equal);
4440
4446
  }
4441
- if (allFiltersEmpty) {
4442
- if (this.#query.onEmptyFilter === "none" /* RETURN_NONE */) {
4443
- return "";
4444
- } else if (this.#query?.allOr) {
4445
- return query.replace("()", "(*:*)");
4446
- }
4447
- }
4448
4447
  return query;
4449
4448
  }
4450
4449
  buildSearchBody() {
4451
4450
  let body2 = {
4452
4451
  q: this.buildSearchQuery(),
4453
- limit: Math.min(this.#limit, _QueryBuilder.maxLimit),
4454
- include_docs: this.#includeDocs
4452
+ limit: Math.min(__privateGet(this, _limit), _QueryBuilder.maxLimit),
4453
+ include_docs: __privateGet(this, _includeDocs)
4455
4454
  };
4456
- if (this.#bookmark) {
4457
- body2.bookmark = this.#bookmark;
4455
+ if (__privateGet(this, _bookmark)) {
4456
+ body2.bookmark = __privateGet(this, _bookmark);
4458
4457
  }
4459
- if (this.#sort) {
4460
- const order = this.#sortOrder === "descending" ? "-" : "";
4461
- const type = `<${this.#sortType}>`;
4462
- body2.sort = `${order}${this.handleSpaces(this.#sort)}${type}`;
4458
+ if (__privateGet(this, _sort)) {
4459
+ const order = __privateGet(this, _sortOrder) === "descending" ? "-" : "";
4460
+ const type = `<${__privateGet(this, _sortType)}>`;
4461
+ body2.sort = `${order}${this.handleSpaces(__privateGet(this, _sort))}${type}`;
4463
4462
  }
4464
4463
  return body2;
4465
4464
  }
4466
4465
  async run() {
4467
- if (this.#skip) {
4468
- await this.#skipItems(this.#skip);
4466
+ if (__privateGet(this, _skip)) {
4467
+ await __privateMethod(this, _skipItems, skipItems_fn).call(this, __privateGet(this, _skip));
4469
4468
  }
4470
- return await this.#execute();
4469
+ return await __privateMethod(this, _execute, execute_fn).call(this);
4471
4470
  }
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 {
4471
+ };
4472
+ _dbName = new WeakMap();
4473
+ _index = new WeakMap();
4474
+ _query = new WeakMap();
4475
+ _limit = new WeakMap();
4476
+ _sort = new WeakMap();
4477
+ _bookmark = new WeakMap();
4478
+ _sortOrder = new WeakMap();
4479
+ _sortType = new WeakMap();
4480
+ _includeDocs = new WeakMap();
4481
+ _version = new WeakMap();
4482
+ _indexBuilder = new WeakMap();
4483
+ _noEscaping = new WeakMap();
4484
+ _skip = new WeakMap();
4485
+ _skipItems = new WeakSet();
4486
+ skipItems_fn = async function(skip) {
4487
+ const prevIncludeDocs = __privateGet(this, _includeDocs);
4488
+ const prevLimit = __privateGet(this, _limit);
4489
+ this.excludeDocs();
4490
+ let skipRemaining = skip;
4491
+ let iterationFetched = 0;
4492
+ do {
4493
+ const toSkip = Math.min(_QueryBuilder.maxLimit, skipRemaining);
4494
+ this.setLimit(toSkip);
4495
+ const { bookmark, rows } = await __privateMethod(this, _execute, execute_fn).call(this);
4496
+ this.setBookmark(bookmark);
4497
+ iterationFetched = rows.length;
4498
+ skipRemaining -= rows.length;
4499
+ } while (skipRemaining > 0 && iterationFetched > 0);
4500
+ __privateSet(this, _includeDocs, prevIncludeDocs);
4501
+ __privateSet(this, _limit, prevLimit);
4502
+ };
4503
+ _execute = new WeakSet();
4504
+ execute_fn = async function() {
4505
+ const { url, cookie } = getCouchInfo();
4506
+ const fullPath = `${url}/${__privateGet(this, _dbName)}/_design/database/_search/${__privateGet(this, _index)}`;
4507
+ const body2 = this.buildSearchBody();
4508
+ try {
4509
+ return await runQuery(fullPath, body2, cookie);
4510
+ } catch (err) {
4511
+ if (err.status === 404 && __privateGet(this, _indexBuilder)) {
4512
+ await __privateGet(this, _indexBuilder).call(this);
4499
4513
  return await runQuery(fullPath, body2, cookie);
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
- }
4514
+ } else {
4515
+ throw err;
4507
4516
  }
4508
4517
  }
4509
4518
  };
4519
+ _QueryBuilder.maxLimit = 200;
4520
+ QueryBuilder = _QueryBuilder;
4510
4521
  }
4511
4522
  });
4512
4523
 
@@ -4585,9 +4596,10 @@ var init_searchIndexes2 = __esm({
4585
4596
 
4586
4597
  // src/db/errors.ts
4587
4598
  function checkErrorCode(error, code) {
4599
+ var _a;
4588
4600
  const stringCode = code.toString();
4589
4601
  if (typeof error === "object") {
4590
- return error.status === code || error.message?.includes(stringCode);
4602
+ return error.status === code || ((_a = error.message) == null ? void 0 : _a.includes(stringCode));
4591
4603
  } else if (typeof error === "number") {
4592
4604
  return error === code;
4593
4605
  } else if (typeof error === "string") {
@@ -4838,12 +4850,12 @@ var init_objectStore = __esm({
4838
4850
  streamUpload = async (bucketName, filename, stream2, extra = {}) => {
4839
4851
  const objectStore = ObjectStore(bucketName);
4840
4852
  await makeSureBucketExists(objectStore, bucketName);
4841
- if (filename?.endsWith(".js")) {
4853
+ if (filename == null ? void 0 : filename.endsWith(".js")) {
4842
4854
  extra = {
4843
4855
  ...extra,
4844
4856
  ContentType: "application/javascript"
4845
4857
  };
4846
- } else if (filename?.endsWith(".svg")) {
4858
+ } else if (filename == null ? void 0 : filename.endsWith(".svg")) {
4847
4859
  extra = {
4848
4860
  ...extra,
4849
4861
  ContentType: "image"
@@ -4959,6 +4971,7 @@ var init_objectStore = __esm({
4959
4971
  return objectStore.deleteObjects(params2).promise();
4960
4972
  };
4961
4973
  deleteFolder = async (bucketName, folder) => {
4974
+ var _a, _b, _c;
4962
4975
  bucketName = sanitizeBucket(bucketName);
4963
4976
  folder = sanitizeKey(folder);
4964
4977
  const client = ObjectStore(bucketName);
@@ -4967,7 +4980,7 @@ var init_objectStore = __esm({
4967
4980
  Prefix: folder
4968
4981
  };
4969
4982
  const existingObjectsResponse = await client.listObjects(listParams).promise();
4970
- if (existingObjectsResponse.Contents?.length === 0) {
4983
+ if (((_a = existingObjectsResponse.Contents) == null ? void 0 : _a.length) === 0) {
4971
4984
  return;
4972
4985
  }
4973
4986
  const deleteParams = {
@@ -4976,11 +4989,11 @@ var init_objectStore = __esm({
4976
4989
  Objects: []
4977
4990
  }
4978
4991
  };
4979
- existingObjectsResponse.Contents?.forEach((content) => {
4992
+ (_b = existingObjectsResponse.Contents) == null ? void 0 : _b.forEach((content) => {
4980
4993
  deleteParams.Delete.Objects.push({ Key: content.Key });
4981
4994
  });
4982
4995
  const deleteResponse = await client.deleteObjects(deleteParams).promise();
4983
- if (deleteResponse.Deleted?.length === 1e3) {
4996
+ if (((_c = deleteResponse.Deleted) == null ? void 0 : _c.length) === 1e3) {
4984
4997
  return deleteFolder(bucketName, folder);
4985
4998
  }
4986
4999
  };
@@ -5257,7 +5270,7 @@ function getFullPath(fileName) {
5257
5270
  }
5258
5271
  function getSingleFileMaxSizeInfo(totalMaxSize) {
5259
5272
  const regex = /(\d+)([A-Za-z])/;
5260
- const match = totalMaxSize?.match(regex);
5273
+ const match = totalMaxSize == null ? void 0 : totalMaxSize.match(regex);
5261
5274
  if (!match) {
5262
5275
  console.warn(`totalMaxSize does not have a valid value`, {
5263
5276
  totalMaxSize
@@ -5289,9 +5302,9 @@ function localFileDestination() {
5289
5302
  const fileInfo = getSingleFileMaxSizeInfo(environment_default.ROLLING_LOG_MAX_SIZE);
5290
5303
  const outFile = rfs.createStream(logsFileName, {
5291
5304
  // As we have a rolling size, we want to half the max size
5292
- size: fileInfo?.size,
5305
+ size: fileInfo == null ? void 0 : fileInfo.size,
5293
5306
  path: logsPath,
5294
- maxFiles: fileInfo?.totalHistoryFiles || 1,
5307
+ maxFiles: (fileInfo == null ? void 0 : fileInfo.totalHistoryFiles) || 1,
5295
5308
  immutable: true,
5296
5309
  history: budibaseLogsHistoryFileName,
5297
5310
  initialRotation: false
@@ -5366,8 +5379,8 @@ var init_logger = __esm({
5366
5379
  tenantId: getTenantId2(),
5367
5380
  appId: getAppId2(),
5368
5381
  automationId: getAutomationId2(),
5369
- identityId: identity?._id,
5370
- identityType: identity?.type,
5382
+ identityId: identity == null ? void 0 : identity._id,
5383
+ identityType: identity == null ? void 0 : identity.type,
5371
5384
  correlationId: getId()
5372
5385
  };
5373
5386
  const mergingObject = {
@@ -5431,30 +5444,30 @@ var init_logger = __esm({
5431
5444
  pinoInstance = destinations.length ? (0, import_pino.default)(pinoOptions, import_pino.default.multistream(destinations)) : (0, import_pino.default)(pinoOptions);
5432
5445
  console.log = (...arg) => {
5433
5446
  const [obj, msg] = getLogParams2(arg);
5434
- pinoInstance?.info(obj, msg);
5447
+ pinoInstance == null ? void 0 : pinoInstance.info(obj, msg);
5435
5448
  };
5436
5449
  console.info = (...arg) => {
5437
5450
  const [obj, msg] = getLogParams2(arg);
5438
- pinoInstance?.info(obj, msg);
5451
+ pinoInstance == null ? void 0 : pinoInstance.info(obj, msg);
5439
5452
  };
5440
5453
  console.warn = (...arg) => {
5441
5454
  const [obj, msg] = getLogParams2(arg);
5442
- pinoInstance?.warn(obj, msg);
5455
+ pinoInstance == null ? void 0 : pinoInstance.warn(obj, msg);
5443
5456
  };
5444
5457
  console.error = (...arg) => {
5445
5458
  const [obj, msg] = getLogParams2(arg);
5446
- pinoInstance?.error(obj, msg);
5459
+ pinoInstance == null ? void 0 : pinoInstance.error(obj, msg);
5447
5460
  };
5448
5461
  console.trace = (...arg) => {
5449
5462
  const [obj, msg] = getLogParams2(arg);
5450
5463
  if (!obj.err) {
5451
5464
  obj.err = new Error();
5452
5465
  }
5453
- pinoInstance?.trace(obj, msg);
5466
+ pinoInstance == null ? void 0 : pinoInstance.trace(obj, msg);
5454
5467
  };
5455
5468
  console.debug = (...arg) => {
5456
5469
  const [obj, msg] = getLogParams2(arg);
5457
- pinoInstance?.debug(obj, msg);
5470
+ pinoInstance == null ? void 0 : pinoInstance.debug(obj, msg);
5458
5471
  };
5459
5472
  const getTenantId2 = () => {
5460
5473
  let tenantId;
@@ -5584,8 +5597,7 @@ __export(src_exports, {
5584
5597
  env: () => environment_default,
5585
5598
  errors: () => errors_exports,
5586
5599
  events: () => events_exports,
5587
- featureFlags: () => features_exports,
5588
- features: () => installation_exports2,
5600
+ featureFlags: () => featureFlags_exports,
5589
5601
  getPublicError: () => getPublicError,
5590
5602
  init: () => init8,
5591
5603
  installation: () => installation_exports,
@@ -5738,6 +5750,7 @@ var isUserInAppTenant = (appId, user) => {
5738
5750
  };
5739
5751
  var ALL_STRATEGIES = Object.values(TenantResolutionStrategy);
5740
5752
  var getTenantIDFromCtx = (ctx, opts) => {
5753
+ var _a;
5741
5754
  if (!isMultiTenant()) {
5742
5755
  return DEFAULT_TENANT_ID;
5743
5756
  }
@@ -5751,15 +5764,16 @@ var getTenantIDFromCtx = (ctx, opts) => {
5751
5764
  opts.excludeStrategies = [];
5752
5765
  }
5753
5766
  const isAllowed = (strategy) => {
5754
- if (opts.excludeStrategies?.includes(strategy)) {
5767
+ var _a2, _b;
5768
+ if ((_a2 = opts.excludeStrategies) == null ? void 0 : _a2.includes(strategy)) {
5755
5769
  return false;
5756
5770
  }
5757
- if (opts.includeStrategies?.includes(strategy)) {
5771
+ if ((_b = opts.includeStrategies) == null ? void 0 : _b.includes(strategy)) {
5758
5772
  return true;
5759
5773
  }
5760
5774
  };
5761
5775
  if (isAllowed("user" /* USER */)) {
5762
- const userTenantId = ctx.user?.tenantId;
5776
+ const userTenantId = (_a = ctx.user) == null ? void 0 : _a.tenantId;
5763
5777
  if (userTenantId) {
5764
5778
  return userTenantId;
5765
5779
  }
@@ -6327,7 +6341,7 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
6327
6341
  logWarn(`Ignoring redlock conflict in write-through cache`);
6328
6342
  }
6329
6343
  }
6330
- cacheItem = makeCacheItem(output, updateDb ? null : cacheItem?.lastWrite);
6344
+ cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
6331
6345
  if (output._id) {
6332
6346
  await cache.store(makeCacheKey(db, output._id), cacheItem);
6333
6347
  }
@@ -6419,6 +6433,7 @@ async function getSettingsConfig() {
6419
6433
  async function getPlatformUrl(opts = {
6420
6434
  tenantAware: true
6421
6435
  }) {
6436
+ var _a;
6422
6437
  let platformUrl = environment_default.PLATFORM_URL || "http://localhost:10000";
6423
6438
  if (!environment_default.SELF_HOSTED && environment_default.MULTI_TENANCY && opts.tenantAware) {
6424
6439
  const tenantId = getTenantId();
@@ -6426,11 +6441,11 @@ async function getPlatformUrl(opts = {
6426
6441
  platformUrl = platformUrl.replace("://", `://${tenantId}.`);
6427
6442
  }
6428
6443
  } else if (environment_default.SELF_HOSTED) {
6429
- const config = opts?.config ? opts.config : (
6444
+ const config = (opts == null ? void 0 : opts.config) ? opts.config : (
6430
6445
  // direct to db to prevent infinite loop
6431
- (await getConfig("settings" /* SETTINGS */))?.config
6446
+ (_a = await getConfig("settings" /* SETTINGS */)) == null ? void 0 : _a.config
6432
6447
  );
6433
- if (config?.platformUrl) {
6448
+ if (config == null ? void 0 : config.platformUrl) {
6434
6449
  platformUrl = config.platformUrl;
6435
6450
  }
6436
6451
  }
@@ -6444,13 +6459,14 @@ var analyticsEnabled = async (opts) => {
6444
6459
  "analyticsEnabled" /* ANALYTICS_ENABLED */,
6445
6460
  86400 /* ONE_DAY */,
6446
6461
  async () => {
6447
- const config = opts?.config ? opts.config : (
6462
+ var _a;
6463
+ const config = (opts == null ? void 0 : opts.config) ? opts.config : (
6448
6464
  // direct to db to prevent infinite loop
6449
- (await getConfig("settings" /* SETTINGS */))?.config
6465
+ (_a = await getConfig("settings" /* SETTINGS */)) == null ? void 0 : _a.config
6450
6466
  );
6451
- if (config?.analyticsEnabled === false) {
6467
+ if ((config == null ? void 0 : config.analyticsEnabled) === false) {
6452
6468
  return false;
6453
- } else if (config?.analyticsEnabled === true) {
6469
+ } else if ((config == null ? void 0 : config.analyticsEnabled) === true) {
6454
6470
  return true;
6455
6471
  }
6456
6472
  }
@@ -6470,7 +6486,7 @@ async function getGoogleConfigDoc() {
6470
6486
  }
6471
6487
  async function getGoogleConfig() {
6472
6488
  const config = await getGoogleConfigDoc();
6473
- return config?.config;
6489
+ return config == null ? void 0 : config.config;
6474
6490
  }
6475
6491
  async function getGoogleDatasourceConfig() {
6476
6492
  if (!environment_default.SELF_HOSTED) {
@@ -6498,11 +6514,13 @@ async function getOIDCConfigDoc() {
6498
6514
  return getConfig("oidc" /* OIDC */);
6499
6515
  }
6500
6516
  async function getOIDCConfig() {
6501
- const config = (await getOIDCConfigDoc())?.config;
6502
- return config?.configs && config.configs[0];
6517
+ var _a;
6518
+ const config = (_a = await getOIDCConfigDoc()) == null ? void 0 : _a.config;
6519
+ return (config == null ? void 0 : config.configs) && config.configs[0];
6503
6520
  }
6504
6521
  async function getOIDCConfigById(configId) {
6505
- const config = (await getConfig("oidc" /* OIDC */))?.config;
6522
+ var _a;
6523
+ const config = (_a = await getConfig("oidc" /* OIDC */)) == null ? void 0 : _a.config;
6506
6524
  return config && config.configs.filter((c) => c.uuid === configId)[0];
6507
6525
  }
6508
6526
  async function getSMTPConfigDoc() {
@@ -6529,7 +6547,7 @@ async function getSMTPConfig(isAutomation) {
6529
6547
  }
6530
6548
  async function getSCIMConfig() {
6531
6549
  const config = await getConfig("scim" /* SCIM */);
6532
- return config?.config;
6550
+ return config == null ? void 0 : config.config;
6533
6551
  }
6534
6552
 
6535
6553
  // src/events/index.ts
@@ -6944,7 +6962,7 @@ async function getAppIdFromCtx(ctx) {
6944
6962
  appId = confirmAppId(await resolveAppUrl(ctx));
6945
6963
  }
6946
6964
  const referer = ctx.request.headers.referer;
6947
- if (!appId && referer?.includes(BUILDER_APP_PREFIX)) {
6965
+ if (!appId && (referer == null ? void 0 : referer.includes(BUILDER_APP_PREFIX))) {
6948
6966
  const refererId = parseAppIdFromUrl(ctx.request.headers.referer);
6949
6967
  appId = confirmAppId(refererId);
6950
6968
  }
@@ -7163,6 +7181,7 @@ function handleStalled(queue, removeStalledCb) {
7163
7181
  });
7164
7182
  }
7165
7183
  function getLogParams(eventType, event, opts = {}, extra = {}) {
7184
+ var _a, _b, _c;
7166
7185
  const message = `[BULL] ${eventType}=${event}`;
7167
7186
  const err = opts.error;
7168
7187
  const bullLog = {
@@ -7170,11 +7189,11 @@ function getLogParams(eventType, event, opts = {}, extra = {}) {
7170
7189
  eventType,
7171
7190
  event,
7172
7191
  job: opts.job,
7173
- jobId: opts.jobId || opts.job?.id,
7192
+ jobId: opts.jobId || ((_a = opts.job) == null ? void 0 : _a.id),
7174
7193
  ...extra
7175
7194
  };
7176
7195
  let automationLog;
7177
- if (opts.job?.data?.automation) {
7196
+ if ((_c = (_b = opts.job) == null ? void 0 : _b.data) == null ? void 0 : _c.automation) {
7178
7197
  automationLog = {
7179
7198
  _logKey: "automation",
7180
7199
  trigger: opts.job ? opts.job.data.automation.definition.trigger.event : void 0
@@ -7189,9 +7208,11 @@ var EventTypeMap = {
7189
7208
  ["systemEventQueue" /* SYSTEM_EVENT_QUEUE */]: "system-event" /* SYSTEM_EVENT */
7190
7209
  };
7191
7210
  function logging(queue, jobQueue) {
7211
+ var _a;
7192
7212
  const eventType = EventTypeMap[jobQueue];
7193
7213
  function doInJobContext(job, task) {
7194
- const appId = job.data.event?.appId;
7214
+ var _a2;
7215
+ const appId = (_a2 = job.data.event) == null ? void 0 : _a2.appId;
7195
7216
  if (appId) {
7196
7217
  return doInContext(appId, task);
7197
7218
  } else {
@@ -7205,7 +7226,7 @@ function logging(queue, jobQueue) {
7205
7226
  }).on("error" /* ERROR */, (error) => {
7206
7227
  console.error(...getLogParams(eventType, "error" /* ERROR */, { error }));
7207
7228
  });
7208
- if (process.env.NODE_DEBUG?.includes("bull")) {
7229
+ if ((_a = process.env.NODE_DEBUG) == null ? void 0 : _a.includes("bull")) {
7209
7230
  queue.on("waiting" /* WAITING */, (jobId) => {
7210
7231
  console.info(...getLogParams(eventType, "waiting" /* WAITING */, { jobId }));
7211
7232
  }).on("active" /* ACTIVE */, async (job, jobPromise) => {
@@ -7275,7 +7296,7 @@ function createQueue(jobQueue, opts = {}) {
7275
7296
  } else {
7276
7297
  queue = new inMemoryQueue_default(jobQueue, queueConfig);
7277
7298
  }
7278
- addListeners(queue, jobQueue, opts?.removeStalledCb);
7299
+ addListeners(queue, jobQueue, opts == null ? void 0 : opts.removeStalledCb);
7279
7300
  QUEUES.push(queue);
7280
7301
  if (!cleanupInterval && !environment_default.isTest()) {
7281
7302
  cleanupInterval = set(cleanup2, CLEANUP_PERIOD_MS);
@@ -7300,10 +7321,7 @@ async function shutdown2() {
7300
7321
 
7301
7322
  // src/events/processors/AuditLogsProcessor.ts
7302
7323
  init_environment2();
7303
- var AuditLogsProcessor = class _AuditLogsProcessor {
7304
- static {
7305
- this.auditLogsEnabled = false;
7306
- }
7324
+ var _AuditLogsProcessor = class _AuditLogsProcessor {
7307
7325
  // can't use constructor as need to return promise
7308
7326
  static init(fn) {
7309
7327
  _AuditLogsProcessor.auditLogsEnabled = true;
@@ -7355,9 +7373,12 @@ var AuditLogsProcessor = class _AuditLogsProcessor {
7355
7373
  async identifyGroup(group, timestamp) {
7356
7374
  }
7357
7375
  shutdown() {
7358
- _AuditLogsProcessor.auditLogQueue?.close();
7376
+ var _a;
7377
+ (_a = _AuditLogsProcessor.auditLogQueue) == null ? void 0 : _a.close();
7359
7378
  }
7360
7379
  };
7380
+ _AuditLogsProcessor.auditLogsEnabled = false;
7381
+ var AuditLogsProcessor = _AuditLogsProcessor;
7361
7382
 
7362
7383
  // src/events/processors/Processors.ts
7363
7384
  var Processor = class {
@@ -7572,7 +7593,7 @@ var bulkGetGlobalUsersById = async (userIds, opts) => {
7572
7593
  keys: userIds,
7573
7594
  include_docs: true
7574
7595
  })).rows.map((row) => row.doc);
7575
- if (opts?.cleanup) {
7596
+ if (opts == null ? void 0 : opts.cleanup) {
7576
7597
  users = removeUserPassword(users);
7577
7598
  }
7578
7599
  return users;
@@ -7593,7 +7614,7 @@ var bulkUpdateGlobalUsers = async (users) => {
7593
7614
  async function getById(id, opts) {
7594
7615
  const db = getGlobalDB();
7595
7616
  let user = await db.get(id);
7596
- if (opts?.cleanup) {
7617
+ if (opts == null ? void 0 : opts.cleanup) {
7597
7618
  user = removeUserPassword(user);
7598
7619
  }
7599
7620
  return user;
@@ -7610,7 +7631,7 @@ var getGlobalUserByEmail = async (email, opts) => {
7610
7631
  throw new Error(`Multiple users found with email address: ${email}`);
7611
7632
  }
7612
7633
  let user = response;
7613
- if (opts?.cleanup) {
7634
+ if (opts == null ? void 0 : opts.cleanup) {
7614
7635
  user = removeUserPassword(user);
7615
7636
  }
7616
7637
  return user;
@@ -7628,7 +7649,7 @@ var searchGlobalUsersByApp = async (appId, opts, getOpts) => {
7628
7649
  response = [];
7629
7650
  }
7630
7651
  let users = Array.isArray(response) ? response : [response];
7631
- if (getOpts?.cleanup) {
7652
+ if (getOpts == null ? void 0 : getOpts.cleanup) {
7632
7653
  users = removeUserPassword(users);
7633
7654
  }
7634
7655
  return users;
@@ -7658,10 +7679,10 @@ var searchGlobalUsersByAppAccess = async (appId, opts) => {
7658
7679
  $regex: "^us_"
7659
7680
  }
7660
7681
  },
7661
- limit: opts?.limit || 50
7682
+ limit: (opts == null ? void 0 : opts.limit) || 50
7662
7683
  };
7663
7684
  const resp = await directCouchFind(getGlobalDBName(), searchOptions);
7664
- return resp?.rows;
7685
+ return resp == null ? void 0 : resp.rows;
7665
7686
  };
7666
7687
  var getGlobalUserByAppPage = (appId, user) => {
7667
7688
  if (!user) {
@@ -7684,7 +7705,7 @@ var searchGlobalUsersByEmail = async (email, opts, getOpts) => {
7684
7705
  response = [];
7685
7706
  }
7686
7707
  let users = Array.isArray(response) ? response : [response];
7687
- if (getOpts?.cleanup) {
7708
+ if (getOpts == null ? void 0 : getOpts.cleanup) {
7688
7709
  users = removeUserPassword(users);
7689
7710
  }
7690
7711
  return users;
@@ -8035,12 +8056,13 @@ __export(users_exports2, {
8035
8056
  isGlobalBuilder: () => isGlobalBuilder
8036
8057
  });
8037
8058
  function isBuilder(user, appId) {
8059
+ var _a, _b, _c;
8038
8060
  if (!user) {
8039
8061
  return false;
8040
8062
  }
8041
- if (user.builder?.global) {
8063
+ if ((_a = user.builder) == null ? void 0 : _a.global) {
8042
8064
  return true;
8043
- } else if (appId && user.builder?.apps?.includes(getProdAppID2(appId))) {
8065
+ } else if (appId && ((_c = (_b = user.builder) == null ? void 0 : _b.apps) == null ? void 0 : _c.includes(getProdAppID2(appId)))) {
8044
8066
  return true;
8045
8067
  }
8046
8068
  return false;
@@ -8058,24 +8080,27 @@ function isAdminOrBuilder(user, appId) {
8058
8080
  return isBuilder(user, appId) || isAdmin(user);
8059
8081
  }
8060
8082
  function hasAppBuilderPermissions(user) {
8083
+ var _a, _b, _c;
8061
8084
  if (!user) {
8062
8085
  return false;
8063
8086
  }
8064
- const appLength = user.builder?.apps?.length;
8065
- const isGlobalBuilder3 = !!user.builder?.global;
8087
+ const appLength = (_b = (_a = user.builder) == null ? void 0 : _a.apps) == null ? void 0 : _b.length;
8088
+ const isGlobalBuilder3 = !!((_c = user.builder) == null ? void 0 : _c.global);
8066
8089
  return !isGlobalBuilder3 && appLength != null && appLength > 0;
8067
8090
  }
8068
8091
  function hasBuilderPermissions(user) {
8092
+ var _a;
8069
8093
  if (!user) {
8070
8094
  return false;
8071
8095
  }
8072
- return user.builder?.global || hasAppBuilderPermissions(user);
8096
+ return ((_a = user.builder) == null ? void 0 : _a.global) || hasAppBuilderPermissions(user);
8073
8097
  }
8074
8098
  function hasAdminPermissions(user) {
8099
+ var _a;
8075
8100
  if (!user) {
8076
8101
  return false;
8077
8102
  }
8078
- return !!user.admin?.global;
8103
+ return !!((_a = user.admin) == null ? void 0 : _a.global);
8079
8104
  }
8080
8105
 
8081
8106
  // src/users/utils.ts
@@ -8148,7 +8173,7 @@ var unassignAppRoleEvents = async (user, roles, existingRoles) => {
8148
8173
  };
8149
8174
  var handleAppRoleEvents = async (user, existingUser) => {
8150
8175
  const roles = user.roles;
8151
- const existingRoles = existingUser?.roles;
8176
+ const existingRoles = existingUser == null ? void 0 : existingUser.roles;
8152
8177
  await assignAppRoleEvents(user, roles, existingRoles);
8153
8178
  await unassignAppRoleEvents(user, roles, existingRoles);
8154
8179
  };
@@ -8200,7 +8225,7 @@ var isRemovingAdmin = (user, existingUser) => {
8200
8225
  return isRemovingPermission(user, existingUser, hasAdminPermissions2);
8201
8226
  };
8202
8227
  var isOnboardingComplete = (user, existingUser) => {
8203
- return !existingUser?.onboardedAt && typeof user.onboardedAt === "string";
8228
+ return !(existingUser == null ? void 0 : existingUser.onboardedAt) && typeof user.onboardedAt === "string";
8204
8229
  };
8205
8230
  var isAddingPermission = (user, existingUser, hasPermission) => {
8206
8231
  if (!hasPermission(user)) {
@@ -8257,7 +8282,7 @@ async function getSessionsForUser(userId) {
8257
8282
  }
8258
8283
  async function invalidateSessions(userId, opts = {}) {
8259
8284
  try {
8260
- const reason = opts?.reason || "unknown";
8285
+ const reason = (opts == null ? void 0 : opts.reason) || "unknown";
8261
8286
  let sessionIds = opts.sessionIds || [];
8262
8287
  let sessionKeys;
8263
8288
  if (sessionIds.length === 0) {
@@ -8433,13 +8458,8 @@ var UserDB = class _UserDB {
8433
8458
  }
8434
8459
  return user;
8435
8460
  }
8436
- static async bulkGet(userIds) {
8437
- return await bulkGetGlobalUsersById(userIds);
8438
- }
8439
- static async bulkUpdate(users) {
8440
- return await bulkUpdateGlobalUsers(users);
8441
- }
8442
8461
  static async save(user, opts = {}) {
8462
+ var _a, _b;
8443
8463
  if (opts.hashPassword == null) {
8444
8464
  opts.hashPassword = true;
8445
8465
  }
@@ -8452,7 +8472,7 @@ var UserDB = class _UserDB {
8452
8472
  if (!email && !_id) {
8453
8473
  throw new Error("_id or email is required");
8454
8474
  }
8455
- if (user.builder?.apps?.length && !await _UserDB.features.isAppBuildersEnabled()) {
8475
+ if (((_b = (_a = user.builder) == null ? void 0 : _a.apps) == null ? void 0 : _b.length) && !await _UserDB.features.isAppBuildersEnabled()) {
8456
8476
  throw new Error("Unable to update app builders, please check license");
8457
8477
  }
8458
8478
  let dbUser;
@@ -8480,10 +8500,10 @@ var UserDB = class _UserDB {
8480
8500
  return _UserDB.quotas.addUsers(change, async () => {
8481
8501
  await validateUniqueUser(email, tenantId);
8482
8502
  let builtUser = await _UserDB.buildUser(user, opts, tenantId, dbUser);
8483
- if (opts.currentUserId && opts.currentUserId === dbUser?._id) {
8503
+ if (opts.currentUserId && opts.currentUserId === (dbUser == null ? void 0 : dbUser._id)) {
8484
8504
  builtUser = cleanseUserObject(builtUser, dbUser);
8485
8505
  }
8486
- if (!dbUser && roles?.length) {
8506
+ if (!dbUser && (roles == null ? void 0 : roles.length)) {
8487
8507
  builtUser.roles = { ...roles };
8488
8508
  }
8489
8509
  let groupPromises = [];
@@ -8762,8 +8782,8 @@ var identifyUser = async (user, account, timestamp) => {
8762
8782
  if (isSSOUser(user)) {
8763
8783
  providerType = user.providerType;
8764
8784
  }
8765
- const accountHolder = account?.budibaseUserId === user._id || false;
8766
- const verified2 = account && account?.budibaseUserId === user._id ? account.verified : false;
8785
+ const accountHolder = (account == null ? void 0 : account.budibaseUserId) === user._id || false;
8786
+ const verified2 = account && (account == null ? void 0 : account.budibaseUserId) === user._id ? account.verified : false;
8767
8787
  const installationId = await getInstallationId();
8768
8788
  const hosting = account ? account.hosting : getHostingFromEnv();
8769
8789
  const environment2 = getDeploymentEnvironment();
@@ -8922,7 +8942,7 @@ var clearEvents = async () => {
8922
8942
  };
8923
8943
  var isBackfillingEvent = async (event) => {
8924
8944
  const backfill = await getBackfillMetadata();
8925
- const events2 = backfill?.eventWhitelist;
8945
+ const events2 = backfill == null ? void 0 : backfill.eventWhitelist;
8926
8946
  if (events2 && events2.includes(event)) {
8927
8947
  return true;
8928
8948
  } else {
@@ -9266,11 +9286,12 @@ var auth_default = {
9266
9286
  // src/events/publishers/automation.ts
9267
9287
  init_src();
9268
9288
  async function created3(automation, timestamp) {
9289
+ var _a, _b, _c, _d;
9269
9290
  const properties = {
9270
9291
  appId: automation.appId,
9271
9292
  automationId: automation._id,
9272
- triggerId: automation.definition?.trigger?.id,
9273
- triggerType: automation.definition?.trigger?.stepId,
9293
+ triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9294
+ triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId,
9274
9295
  audited: {
9275
9296
  name: automation.name
9276
9297
  }
@@ -9278,20 +9299,22 @@ async function created3(automation, timestamp) {
9278
9299
  await publishEvent("automation:created" /* AUTOMATION_CREATED */, properties, timestamp);
9279
9300
  }
9280
9301
  async function triggerUpdated(automation) {
9302
+ var _a, _b, _c, _d;
9281
9303
  const properties = {
9282
9304
  appId: automation.appId,
9283
9305
  automationId: automation._id,
9284
- triggerId: automation.definition?.trigger?.id,
9285
- triggerType: automation.definition?.trigger?.stepId
9306
+ triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9307
+ triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId
9286
9308
  };
9287
9309
  await publishEvent("automation:trigger:updated" /* AUTOMATION_TRIGGER_UPDATED */, properties);
9288
9310
  }
9289
9311
  async function deleted3(automation) {
9312
+ var _a, _b, _c, _d;
9290
9313
  const properties = {
9291
9314
  appId: automation.appId,
9292
9315
  automationId: automation._id,
9293
- triggerId: automation.definition?.trigger?.id,
9294
- triggerType: automation.definition?.trigger?.stepId,
9316
+ triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9317
+ triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId,
9295
9318
  audited: {
9296
9319
  name: automation.name
9297
9320
  }
@@ -9299,11 +9322,12 @@ async function deleted3(automation) {
9299
9322
  await publishEvent("automation:deleted" /* AUTOMATION_DELETED */, properties);
9300
9323
  }
9301
9324
  async function tested(automation) {
9325
+ var _a, _b, _c, _d;
9302
9326
  const properties = {
9303
9327
  appId: automation.appId,
9304
9328
  automationId: automation._id,
9305
- triggerId: automation.definition?.trigger?.id,
9306
- triggerType: automation.definition?.trigger?.stepId
9329
+ triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9330
+ triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId
9307
9331
  };
9308
9332
  await publishEvent("automation:tested" /* AUTOMATION_TESTED */, properties);
9309
9333
  }
@@ -9314,11 +9338,12 @@ var run = async (count, timestamp) => {
9314
9338
  await publishEvent("automations:run" /* AUTOMATIONS_RUN */, properties, timestamp);
9315
9339
  };
9316
9340
  async function stepCreated(automation, step, timestamp) {
9341
+ var _a, _b, _c, _d;
9317
9342
  const properties = {
9318
9343
  appId: automation.appId,
9319
9344
  automationId: automation._id,
9320
- triggerId: automation.definition?.trigger?.id,
9321
- triggerType: automation.definition?.trigger?.stepId,
9345
+ triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9346
+ triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId,
9322
9347
  stepId: step.id,
9323
9348
  stepType: step.stepId,
9324
9349
  audited: {
@@ -9328,11 +9353,12 @@ async function stepCreated(automation, step, timestamp) {
9328
9353
  await publishEvent("automation:step:created" /* AUTOMATION_STEP_CREATED */, properties, timestamp);
9329
9354
  }
9330
9355
  async function stepDeleted(automation, step) {
9356
+ var _a, _b, _c, _d;
9331
9357
  const properties = {
9332
9358
  appId: automation.appId,
9333
9359
  automationId: automation._id,
9334
- triggerId: automation.definition?.trigger?.id,
9335
- triggerType: automation.definition?.trigger?.stepId,
9360
+ triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9361
+ triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId,
9336
9362
  stepId: step.id,
9337
9363
  stepType: step.stepId,
9338
9364
  audited: {
@@ -9619,23 +9645,25 @@ var role_default = {
9619
9645
  // src/events/publishers/screen.ts
9620
9646
  init_src();
9621
9647
  async function created8(screen, timestamp) {
9648
+ var _a;
9622
9649
  const properties = {
9623
9650
  layoutId: screen.layoutId,
9624
9651
  screenId: screen._id,
9625
9652
  roleId: screen.routing.roleId,
9626
9653
  audited: {
9627
- name: screen.routing?.route
9654
+ name: (_a = screen.routing) == null ? void 0 : _a.route
9628
9655
  }
9629
9656
  };
9630
9657
  await publishEvent("screen:created" /* SCREEN_CREATED */, properties, timestamp);
9631
9658
  }
9632
9659
  async function deleted8(screen) {
9660
+ var _a;
9633
9661
  const properties = {
9634
9662
  layoutId: screen.layoutId,
9635
9663
  screenId: screen._id,
9636
9664
  roleId: screen.routing.roleId,
9637
9665
  audited: {
9638
- name: screen.routing?.route
9666
+ name: (_a = screen.routing) == null ? void 0 : _a.route
9639
9667
  }
9640
9668
  };
9641
9669
  await publishEvent("screen:deleted" /* SCREEN_DELETED */, properties);
@@ -10571,7 +10599,8 @@ var BUILTIN_PERMISSIONS = {
10571
10599
  name: "Read only",
10572
10600
  permissions: [
10573
10601
  new Permission("query" /* QUERY */, "read" /* READ */),
10574
- new Permission("table" /* TABLE */, "read" /* READ */)
10602
+ new Permission("table" /* TABLE */, "read" /* READ */),
10603
+ new Permission("view" /* VIEW */, "read" /* READ */)
10575
10604
  ]
10576
10605
  },
10577
10606
  WRITE: {
@@ -10580,6 +10609,7 @@ var BUILTIN_PERMISSIONS = {
10580
10609
  permissions: [
10581
10610
  new Permission("query" /* QUERY */, "write" /* WRITE */),
10582
10611
  new Permission("table" /* TABLE */, "write" /* WRITE */),
10612
+ new Permission("view" /* VIEW */, "read" /* READ */),
10583
10613
  new Permission("automation" /* AUTOMATION */, "execute" /* EXECUTE */)
10584
10614
  ]
10585
10615
  },
@@ -10590,6 +10620,7 @@ var BUILTIN_PERMISSIONS = {
10590
10620
  new Permission("table" /* TABLE */, "write" /* WRITE */),
10591
10621
  new Permission("user" /* USER */, "read" /* READ */),
10592
10622
  new Permission("automation" /* AUTOMATION */, "execute" /* EXECUTE */),
10623
+ new Permission("view" /* VIEW */, "read" /* READ */),
10593
10624
  new Permission("webhook" /* WEBHOOK */, "read" /* READ */)
10594
10625
  ]
10595
10626
  },
@@ -10600,6 +10631,7 @@ var BUILTIN_PERMISSIONS = {
10600
10631
  new Permission("table" /* TABLE */, "admin" /* ADMIN */),
10601
10632
  new Permission("user" /* USER */, "admin" /* ADMIN */),
10602
10633
  new Permission("automation" /* AUTOMATION */, "admin" /* ADMIN */),
10634
+ new Permission("view" /* VIEW */, "admin" /* ADMIN */),
10603
10635
  new Permission("webhook" /* WEBHOOK */, "read" /* READ */),
10604
10636
  new Permission("query" /* QUERY */, "admin" /* ADMIN */)
10605
10637
  ]
@@ -10702,7 +10734,7 @@ var BUILTIN_ROLE_NAME_ARRAY = Object.values(BUILTIN_ROLES).map(
10702
10734
  (role) => role.name
10703
10735
  );
10704
10736
  function isBuiltin(role) {
10705
- return BUILTIN_ROLE_ID_ARRAY.some((builtin) => role?.includes(builtin));
10737
+ return BUILTIN_ROLE_ID_ARRAY.some((builtin) => role == null ? void 0 : role.includes(builtin));
10706
10738
  }
10707
10739
  function builtinRoleToNumber(id) {
10708
10740
  if (!id) {
@@ -10729,7 +10761,7 @@ async function roleToNumber(id) {
10729
10761
  }
10730
10762
  const hierarchy = await getUserRoleHierarchy(id);
10731
10763
  for (let role of hierarchy) {
10732
- if (isBuiltin(role?.inherits)) {
10764
+ if (isBuiltin(role == null ? void 0 : role.inherits)) {
10733
10765
  return builtinRoleToNumber(role.inherits) + 1;
10734
10766
  }
10735
10767
  }
@@ -10762,7 +10794,7 @@ async function getRole(roleId, opts) {
10762
10794
  role = Object.assign(role, dbRole);
10763
10795
  role._id = getExternalRoleID(role._id, role.version);
10764
10796
  } catch (err) {
10765
- if (!isBuiltin(roleId) && opts?.defaultPublic) {
10797
+ if (!isBuiltin(roleId) && (opts == null ? void 0 : opts.defaultPublic)) {
10766
10798
  return (0, import_cloneDeep2.default)(BUILTIN_ROLES.PUBLIC);
10767
10799
  }
10768
10800
  if (Object.keys(role).length === 0) {
@@ -10885,7 +10917,7 @@ var AccessController = class {
10885
10917
  });
10886
10918
  this.userHierarchies[userRoleId] = roleIds;
10887
10919
  }
10888
- return roleIds?.indexOf(tryingRoleId) !== -1;
10920
+ return (roleIds == null ? void 0 : roleIds.indexOf(tryingRoleId)) !== -1;
10889
10921
  }
10890
10922
  async checkScreensAccess(screens, userRoleId) {
10891
10923
  let accessibleScreens = [];
@@ -10906,7 +10938,7 @@ var AccessController = class {
10906
10938
  }
10907
10939
  };
10908
10940
  function getDBRoleID(roleName) {
10909
- if (roleName?.startsWith("role" /* ROLE */)) {
10941
+ if (roleName == null ? void 0 : roleName.startsWith("role" /* ROLE */)) {
10910
10942
  return roleName;
10911
10943
  }
10912
10944
  return prefixRoleID(roleName);
@@ -10918,39 +10950,16 @@ function getExternalRoleID(roleId, version) {
10918
10950
  return roleId;
10919
10951
  }
10920
10952
 
10921
- // src/features/index.ts
10922
- var features_exports = {};
10923
- __export(features_exports, {
10953
+ // src/featureFlags/index.ts
10954
+ var featureFlags_exports = {};
10955
+ __export(featureFlags_exports, {
10924
10956
  TenantFeatureFlag: () => TenantFeatureFlag,
10925
10957
  buildFeatureFlags: () => buildFeatureFlags,
10926
10958
  getTenantFeatureFlags: () => getTenantFeatureFlags,
10927
- isEnabled: () => isEnabled,
10928
- processFeatureEnvVar: () => processFeatureEnvVar
10959
+ isEnabled: () => isEnabled
10929
10960
  });
10930
10961
  init_environment2();
10931
10962
  init_context2();
10932
-
10933
- // src/features/installation.ts
10934
- var installation_exports2 = {};
10935
- __export(installation_exports2, {
10936
- processFeatureEnvVar: () => processFeatureEnvVar
10937
- });
10938
- function processFeatureEnvVar(fullList, featureList) {
10939
- let list;
10940
- if (!featureList) {
10941
- list = fullList;
10942
- } else {
10943
- list = featureList.split(",");
10944
- }
10945
- for (let feature of list) {
10946
- if (!fullList.includes(feature)) {
10947
- throw new Error(`Feature: ${feature} is not an allowed option`);
10948
- }
10949
- }
10950
- return list;
10951
- }
10952
-
10953
- // src/features/index.ts
10954
10963
  function buildFeatureFlags() {
10955
10964
  if (!environment_default.TENANT_FEATURE_FLAGS) {
10956
10965
  return;
@@ -11188,7 +11197,8 @@ async function authenticate2(details, requireLocalAccount = true, done, saveUser
11188
11197
  return done(null, ssoUser);
11189
11198
  }
11190
11199
  async function getProfilePictureUrl(user, details) {
11191
- const pictureUrl = details.profile?._json.picture;
11200
+ var _a;
11201
+ const pictureUrl = (_a = details.profile) == null ? void 0 : _a._json.picture;
11192
11202
  if (pictureUrl) {
11193
11203
  const response = await (0, import_node_fetch5.default)(pictureUrl);
11194
11204
  if (response.status === 200) {
@@ -11719,7 +11729,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
11719
11729
  user = await getUser(userId, session.tenantId);
11720
11730
  }
11721
11731
  user.csrfToken = session.csrfToken;
11722
- if (session?.lastAccessedAt < timeMinusOneMinute()) {
11732
+ if ((session == null ? void 0 : session.lastAccessedAt) < timeMinusOneMinute()) {
11723
11733
  await updateSessionTTL(session);
11724
11734
  }
11725
11735
  authenticated = true;
@@ -11761,9 +11771,9 @@ function authenticated_default(noAuthPatterns = [], opts = {
11761
11771
  } catch (err) {
11762
11772
  console.error(`Auth Error: ${err.message}`);
11763
11773
  console.error(err);
11764
- if (err?.name === "JsonWebTokenError") {
11774
+ if ((err == null ? void 0 : err.name) === "JsonWebTokenError") {
11765
11775
  clearCookie(ctx, "budibase:auth" /* Auth */);
11766
- } else if (err?.code === "invalid_api_key" /* INVALID_API_KEY */) {
11776
+ } else if ((err == null ? void 0 : err.code) === "invalid_api_key" /* INVALID_API_KEY */) {
11767
11777
  ctx.throw(403, err.message);
11768
11778
  }
11769
11779
  if (opts && opts.publicAllowed || publicEndpoint) {
@@ -11830,6 +11840,7 @@ var INCLUDED_CONTENT_TYPES = [
11830
11840
  function csrf_default(opts = { noCsrfPatterns: [] }) {
11831
11841
  const noCsrfOptions = buildMatcherRegex(opts.noCsrfPatterns);
11832
11842
  return async (ctx, next) => {
11843
+ var _a;
11833
11844
  const found = matches(ctx, noCsrfOptions);
11834
11845
  if (found) {
11835
11846
  return next();
@@ -11844,7 +11855,7 @@ function csrf_default(opts = { noCsrfPatterns: [] }) {
11844
11855
  if (ctx.internal) {
11845
11856
  return next();
11846
11857
  }
11847
- const userToken = ctx.user?.csrfToken;
11858
+ const userToken = (_a = ctx.user) == null ? void 0 : _a.csrfToken;
11848
11859
  if (!userToken) {
11849
11860
  return next();
11850
11861
  }
@@ -11904,7 +11915,10 @@ function pinoSettings() {
11904
11915
  logger,
11905
11916
  genReqId: correlator2.getId,
11906
11917
  autoLogging: {
11907
- ignore: (req) => !!req.url?.includes("/health")
11918
+ ignore: (req) => {
11919
+ var _a;
11920
+ return !!((_a = req.url) == null ? void 0 : _a.includes("/health"));
11921
+ }
11908
11922
  },
11909
11923
  serializers: {
11910
11924
  req: (req) => {
@@ -11975,7 +11989,8 @@ var errorHandling_default = errorHandling;
11975
11989
 
11976
11990
  // src/middleware/querystringToBody.ts
11977
11991
  function querystringToBody_default(ctx, next) {
11978
- const queryString = ctx.request.query?.query;
11992
+ var _a;
11993
+ const queryString = (_a = ctx.request.query) == null ? void 0 : _a.query;
11979
11994
  if (ctx.request.method.toLowerCase() !== "get") {
11980
11995
  ctx.throw(
11981
11996
  500,
@@ -12005,11 +12020,12 @@ __export(joi_validator_exports, {
12005
12020
  var import_joi = __toESM(require("joi"));
12006
12021
  function validate(schema, property) {
12007
12022
  return (ctx, next) => {
12023
+ var _a;
12008
12024
  if (!schema) {
12009
12025
  return next();
12010
12026
  }
12011
12027
  let params2 = null;
12012
- let reqProp = ctx.request?.[property];
12028
+ let reqProp = (_a = ctx.request) == null ? void 0 : _a[property];
12013
12029
  if (ctx[property] != null) {
12014
12030
  params2 = ctx[property];
12015
12031
  } else if (reqProp != null) {
@@ -12148,6 +12164,7 @@ async function updateUserOAuth(userId, oAuthConfig) {
12148
12164
  }
12149
12165
  }
12150
12166
  async function platformLogout(opts) {
12167
+ var _a;
12151
12168
  const ctx = opts.ctx;
12152
12169
  const userId = opts.userId;
12153
12170
  const keepActiveSession = opts.keepActiveSession;
@@ -12164,7 +12181,7 @@ async function platformLogout(opts) {
12164
12181
  }
12165
12182
  const sessionIds = sessions.map(({ sessionId }) => sessionId);
12166
12183
  await invalidateSessions(userId, { sessionIds, reason: "logout" });
12167
- await auth_default.logout(ctx.user?.email);
12184
+ await auth_default.logout((_a = ctx.user) == null ? void 0 : _a.email);
12168
12185
  await invalidateUser(userId);
12169
12186
  }
12170
12187
 
@@ -12280,7 +12297,7 @@ function validateAutomation(schema) {
12280
12297
  runJoi(validator, schema);
12281
12298
  }
12282
12299
  function validate2(schema) {
12283
- switch (schema?.type) {
12300
+ switch (schema == null ? void 0 : schema.type) {
12284
12301
  case "component" /* COMPONENT */:
12285
12302
  validateComponent(schema);
12286
12303
  break;
@@ -12344,7 +12361,7 @@ async function lookup(address) {
12344
12361
  }
12345
12362
  async function refreshBlacklist() {
12346
12363
  const blacklist = environment_default.BLACKLIST_IPS;
12347
- const list = blacklist?.split(",") || [];
12364
+ const list = (blacklist == null ? void 0 : blacklist.split(",")) || [];
12348
12365
  let final = [];
12349
12366
  for (let addr of list) {
12350
12367
  const trimmed = addr.trim();
@@ -12361,7 +12378,7 @@ async function isBlacklisted(address) {
12361
12378
  if (!blackListArray) {
12362
12379
  await refreshBlacklist();
12363
12380
  }
12364
- if (blackListArray?.length === 0) {
12381
+ if ((blackListArray == null ? void 0 : blackListArray.length) === 0) {
12365
12382
  return false;
12366
12383
  }
12367
12384
  let ips;
@@ -12370,7 +12387,7 @@ async function isBlacklisted(address) {
12370
12387
  } else {
12371
12388
  ips = [address];
12372
12389
  }
12373
- return !!blackListArray?.find((addr) => ips.includes(addr));
12390
+ return !!(blackListArray == null ? void 0 : blackListArray.find((addr) => ips.includes(addr)));
12374
12391
  }
12375
12392
 
12376
12393
  // src/docUpdates/index.ts
@@ -12516,7 +12533,6 @@ var init8 = (opts = {}) => {
12516
12533
  errors,
12517
12534
  events,
12518
12535
  featureFlags,
12519
- features,
12520
12536
  getPublicError,
12521
12537
  init,
12522
12538
  installation,