@budibase/backend-core 2.9.26-alpha.4 → 2.9.29

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;
@@ -5737,6 +5750,7 @@ var isUserInAppTenant = (appId, user) => {
5737
5750
  };
5738
5751
  var ALL_STRATEGIES = Object.values(TenantResolutionStrategy);
5739
5752
  var getTenantIDFromCtx = (ctx, opts) => {
5753
+ var _a;
5740
5754
  if (!isMultiTenant()) {
5741
5755
  return DEFAULT_TENANT_ID;
5742
5756
  }
@@ -5750,15 +5764,16 @@ var getTenantIDFromCtx = (ctx, opts) => {
5750
5764
  opts.excludeStrategies = [];
5751
5765
  }
5752
5766
  const isAllowed = (strategy) => {
5753
- if (opts.excludeStrategies?.includes(strategy)) {
5767
+ var _a2, _b;
5768
+ if ((_a2 = opts.excludeStrategies) == null ? void 0 : _a2.includes(strategy)) {
5754
5769
  return false;
5755
5770
  }
5756
- if (opts.includeStrategies?.includes(strategy)) {
5771
+ if ((_b = opts.includeStrategies) == null ? void 0 : _b.includes(strategy)) {
5757
5772
  return true;
5758
5773
  }
5759
5774
  };
5760
5775
  if (isAllowed("user" /* USER */)) {
5761
- const userTenantId = ctx.user?.tenantId;
5776
+ const userTenantId = (_a = ctx.user) == null ? void 0 : _a.tenantId;
5762
5777
  if (userTenantId) {
5763
5778
  return userTenantId;
5764
5779
  }
@@ -6326,7 +6341,7 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
6326
6341
  logWarn(`Ignoring redlock conflict in write-through cache`);
6327
6342
  }
6328
6343
  }
6329
- cacheItem = makeCacheItem(output, updateDb ? null : cacheItem?.lastWrite);
6344
+ cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
6330
6345
  if (output._id) {
6331
6346
  await cache.store(makeCacheKey(db, output._id), cacheItem);
6332
6347
  }
@@ -6418,6 +6433,7 @@ async function getSettingsConfig() {
6418
6433
  async function getPlatformUrl(opts = {
6419
6434
  tenantAware: true
6420
6435
  }) {
6436
+ var _a;
6421
6437
  let platformUrl = environment_default.PLATFORM_URL || "http://localhost:10000";
6422
6438
  if (!environment_default.SELF_HOSTED && environment_default.MULTI_TENANCY && opts.tenantAware) {
6423
6439
  const tenantId = getTenantId();
@@ -6425,11 +6441,11 @@ async function getPlatformUrl(opts = {
6425
6441
  platformUrl = platformUrl.replace("://", `://${tenantId}.`);
6426
6442
  }
6427
6443
  } else if (environment_default.SELF_HOSTED) {
6428
- const config = opts?.config ? opts.config : (
6444
+ const config = (opts == null ? void 0 : opts.config) ? opts.config : (
6429
6445
  // direct to db to prevent infinite loop
6430
- (await getConfig("settings" /* SETTINGS */))?.config
6446
+ (_a = await getConfig("settings" /* SETTINGS */)) == null ? void 0 : _a.config
6431
6447
  );
6432
- if (config?.platformUrl) {
6448
+ if (config == null ? void 0 : config.platformUrl) {
6433
6449
  platformUrl = config.platformUrl;
6434
6450
  }
6435
6451
  }
@@ -6443,13 +6459,14 @@ var analyticsEnabled = async (opts) => {
6443
6459
  "analyticsEnabled" /* ANALYTICS_ENABLED */,
6444
6460
  86400 /* ONE_DAY */,
6445
6461
  async () => {
6446
- const config = opts?.config ? opts.config : (
6462
+ var _a;
6463
+ const config = (opts == null ? void 0 : opts.config) ? opts.config : (
6447
6464
  // direct to db to prevent infinite loop
6448
- (await getConfig("settings" /* SETTINGS */))?.config
6465
+ (_a = await getConfig("settings" /* SETTINGS */)) == null ? void 0 : _a.config
6449
6466
  );
6450
- if (config?.analyticsEnabled === false) {
6467
+ if ((config == null ? void 0 : config.analyticsEnabled) === false) {
6451
6468
  return false;
6452
- } else if (config?.analyticsEnabled === true) {
6469
+ } else if ((config == null ? void 0 : config.analyticsEnabled) === true) {
6453
6470
  return true;
6454
6471
  }
6455
6472
  }
@@ -6469,7 +6486,7 @@ async function getGoogleConfigDoc() {
6469
6486
  }
6470
6487
  async function getGoogleConfig() {
6471
6488
  const config = await getGoogleConfigDoc();
6472
- return config?.config;
6489
+ return config == null ? void 0 : config.config;
6473
6490
  }
6474
6491
  async function getGoogleDatasourceConfig() {
6475
6492
  if (!environment_default.SELF_HOSTED) {
@@ -6497,11 +6514,13 @@ async function getOIDCConfigDoc() {
6497
6514
  return getConfig("oidc" /* OIDC */);
6498
6515
  }
6499
6516
  async function getOIDCConfig() {
6500
- const config = (await getOIDCConfigDoc())?.config;
6501
- 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];
6502
6520
  }
6503
6521
  async function getOIDCConfigById(configId) {
6504
- const config = (await getConfig("oidc" /* OIDC */))?.config;
6522
+ var _a;
6523
+ const config = (_a = await getConfig("oidc" /* OIDC */)) == null ? void 0 : _a.config;
6505
6524
  return config && config.configs.filter((c) => c.uuid === configId)[0];
6506
6525
  }
6507
6526
  async function getSMTPConfigDoc() {
@@ -6528,7 +6547,7 @@ async function getSMTPConfig(isAutomation) {
6528
6547
  }
6529
6548
  async function getSCIMConfig() {
6530
6549
  const config = await getConfig("scim" /* SCIM */);
6531
- return config?.config;
6550
+ return config == null ? void 0 : config.config;
6532
6551
  }
6533
6552
 
6534
6553
  // src/events/index.ts
@@ -6943,7 +6962,7 @@ async function getAppIdFromCtx(ctx) {
6943
6962
  appId = confirmAppId(await resolveAppUrl(ctx));
6944
6963
  }
6945
6964
  const referer = ctx.request.headers.referer;
6946
- if (!appId && referer?.includes(BUILDER_APP_PREFIX)) {
6965
+ if (!appId && (referer == null ? void 0 : referer.includes(BUILDER_APP_PREFIX))) {
6947
6966
  const refererId = parseAppIdFromUrl(ctx.request.headers.referer);
6948
6967
  appId = confirmAppId(refererId);
6949
6968
  }
@@ -7162,6 +7181,7 @@ function handleStalled(queue, removeStalledCb) {
7162
7181
  });
7163
7182
  }
7164
7183
  function getLogParams(eventType, event, opts = {}, extra = {}) {
7184
+ var _a, _b, _c;
7165
7185
  const message = `[BULL] ${eventType}=${event}`;
7166
7186
  const err = opts.error;
7167
7187
  const bullLog = {
@@ -7169,11 +7189,11 @@ function getLogParams(eventType, event, opts = {}, extra = {}) {
7169
7189
  eventType,
7170
7190
  event,
7171
7191
  job: opts.job,
7172
- jobId: opts.jobId || opts.job?.id,
7192
+ jobId: opts.jobId || ((_a = opts.job) == null ? void 0 : _a.id),
7173
7193
  ...extra
7174
7194
  };
7175
7195
  let automationLog;
7176
- if (opts.job?.data?.automation) {
7196
+ if ((_c = (_b = opts.job) == null ? void 0 : _b.data) == null ? void 0 : _c.automation) {
7177
7197
  automationLog = {
7178
7198
  _logKey: "automation",
7179
7199
  trigger: opts.job ? opts.job.data.automation.definition.trigger.event : void 0
@@ -7188,9 +7208,11 @@ var EventTypeMap = {
7188
7208
  ["systemEventQueue" /* SYSTEM_EVENT_QUEUE */]: "system-event" /* SYSTEM_EVENT */
7189
7209
  };
7190
7210
  function logging(queue, jobQueue) {
7211
+ var _a;
7191
7212
  const eventType = EventTypeMap[jobQueue];
7192
7213
  function doInJobContext(job, task) {
7193
- const appId = job.data.event?.appId;
7214
+ var _a2;
7215
+ const appId = (_a2 = job.data.event) == null ? void 0 : _a2.appId;
7194
7216
  if (appId) {
7195
7217
  return doInContext(appId, task);
7196
7218
  } else {
@@ -7204,7 +7226,7 @@ function logging(queue, jobQueue) {
7204
7226
  }).on("error" /* ERROR */, (error) => {
7205
7227
  console.error(...getLogParams(eventType, "error" /* ERROR */, { error }));
7206
7228
  });
7207
- if (process.env.NODE_DEBUG?.includes("bull")) {
7229
+ if ((_a = process.env.NODE_DEBUG) == null ? void 0 : _a.includes("bull")) {
7208
7230
  queue.on("waiting" /* WAITING */, (jobId) => {
7209
7231
  console.info(...getLogParams(eventType, "waiting" /* WAITING */, { jobId }));
7210
7232
  }).on("active" /* ACTIVE */, async (job, jobPromise) => {
@@ -7274,7 +7296,7 @@ function createQueue(jobQueue, opts = {}) {
7274
7296
  } else {
7275
7297
  queue = new inMemoryQueue_default(jobQueue, queueConfig);
7276
7298
  }
7277
- addListeners(queue, jobQueue, opts?.removeStalledCb);
7299
+ addListeners(queue, jobQueue, opts == null ? void 0 : opts.removeStalledCb);
7278
7300
  QUEUES.push(queue);
7279
7301
  if (!cleanupInterval && !environment_default.isTest()) {
7280
7302
  cleanupInterval = set(cleanup2, CLEANUP_PERIOD_MS);
@@ -7299,10 +7321,7 @@ async function shutdown2() {
7299
7321
 
7300
7322
  // src/events/processors/AuditLogsProcessor.ts
7301
7323
  init_environment2();
7302
- var AuditLogsProcessor = class _AuditLogsProcessor {
7303
- static {
7304
- this.auditLogsEnabled = false;
7305
- }
7324
+ var _AuditLogsProcessor = class _AuditLogsProcessor {
7306
7325
  // can't use constructor as need to return promise
7307
7326
  static init(fn) {
7308
7327
  _AuditLogsProcessor.auditLogsEnabled = true;
@@ -7354,9 +7373,12 @@ var AuditLogsProcessor = class _AuditLogsProcessor {
7354
7373
  async identifyGroup(group, timestamp) {
7355
7374
  }
7356
7375
  shutdown() {
7357
- _AuditLogsProcessor.auditLogQueue?.close();
7376
+ var _a;
7377
+ (_a = _AuditLogsProcessor.auditLogQueue) == null ? void 0 : _a.close();
7358
7378
  }
7359
7379
  };
7380
+ _AuditLogsProcessor.auditLogsEnabled = false;
7381
+ var AuditLogsProcessor = _AuditLogsProcessor;
7360
7382
 
7361
7383
  // src/events/processors/Processors.ts
7362
7384
  var Processor = class {
@@ -7571,7 +7593,7 @@ var bulkGetGlobalUsersById = async (userIds, opts) => {
7571
7593
  keys: userIds,
7572
7594
  include_docs: true
7573
7595
  })).rows.map((row) => row.doc);
7574
- if (opts?.cleanup) {
7596
+ if (opts == null ? void 0 : opts.cleanup) {
7575
7597
  users = removeUserPassword(users);
7576
7598
  }
7577
7599
  return users;
@@ -7592,7 +7614,7 @@ var bulkUpdateGlobalUsers = async (users) => {
7592
7614
  async function getById(id, opts) {
7593
7615
  const db = getGlobalDB();
7594
7616
  let user = await db.get(id);
7595
- if (opts?.cleanup) {
7617
+ if (opts == null ? void 0 : opts.cleanup) {
7596
7618
  user = removeUserPassword(user);
7597
7619
  }
7598
7620
  return user;
@@ -7609,7 +7631,7 @@ var getGlobalUserByEmail = async (email, opts) => {
7609
7631
  throw new Error(`Multiple users found with email address: ${email}`);
7610
7632
  }
7611
7633
  let user = response;
7612
- if (opts?.cleanup) {
7634
+ if (opts == null ? void 0 : opts.cleanup) {
7613
7635
  user = removeUserPassword(user);
7614
7636
  }
7615
7637
  return user;
@@ -7627,7 +7649,7 @@ var searchGlobalUsersByApp = async (appId, opts, getOpts) => {
7627
7649
  response = [];
7628
7650
  }
7629
7651
  let users = Array.isArray(response) ? response : [response];
7630
- if (getOpts?.cleanup) {
7652
+ if (getOpts == null ? void 0 : getOpts.cleanup) {
7631
7653
  users = removeUserPassword(users);
7632
7654
  }
7633
7655
  return users;
@@ -7657,10 +7679,10 @@ var searchGlobalUsersByAppAccess = async (appId, opts) => {
7657
7679
  $regex: "^us_"
7658
7680
  }
7659
7681
  },
7660
- limit: opts?.limit || 50
7682
+ limit: (opts == null ? void 0 : opts.limit) || 50
7661
7683
  };
7662
7684
  const resp = await directCouchFind(getGlobalDBName(), searchOptions);
7663
- return resp?.rows;
7685
+ return resp == null ? void 0 : resp.rows;
7664
7686
  };
7665
7687
  var getGlobalUserByAppPage = (appId, user) => {
7666
7688
  if (!user) {
@@ -7683,7 +7705,7 @@ var searchGlobalUsersByEmail = async (email, opts, getOpts) => {
7683
7705
  response = [];
7684
7706
  }
7685
7707
  let users = Array.isArray(response) ? response : [response];
7686
- if (getOpts?.cleanup) {
7708
+ if (getOpts == null ? void 0 : getOpts.cleanup) {
7687
7709
  users = removeUserPassword(users);
7688
7710
  }
7689
7711
  return users;
@@ -8034,12 +8056,13 @@ __export(users_exports2, {
8034
8056
  isGlobalBuilder: () => isGlobalBuilder
8035
8057
  });
8036
8058
  function isBuilder(user, appId) {
8059
+ var _a, _b, _c;
8037
8060
  if (!user) {
8038
8061
  return false;
8039
8062
  }
8040
- if (user.builder?.global) {
8063
+ if ((_a = user.builder) == null ? void 0 : _a.global) {
8041
8064
  return true;
8042
- } 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)))) {
8043
8066
  return true;
8044
8067
  }
8045
8068
  return false;
@@ -8057,24 +8080,27 @@ function isAdminOrBuilder(user, appId) {
8057
8080
  return isBuilder(user, appId) || isAdmin(user);
8058
8081
  }
8059
8082
  function hasAppBuilderPermissions(user) {
8083
+ var _a, _b, _c;
8060
8084
  if (!user) {
8061
8085
  return false;
8062
8086
  }
8063
- const appLength = user.builder?.apps?.length;
8064
- 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);
8065
8089
  return !isGlobalBuilder3 && appLength != null && appLength > 0;
8066
8090
  }
8067
8091
  function hasBuilderPermissions(user) {
8092
+ var _a;
8068
8093
  if (!user) {
8069
8094
  return false;
8070
8095
  }
8071
- return user.builder?.global || hasAppBuilderPermissions(user);
8096
+ return ((_a = user.builder) == null ? void 0 : _a.global) || hasAppBuilderPermissions(user);
8072
8097
  }
8073
8098
  function hasAdminPermissions(user) {
8099
+ var _a;
8074
8100
  if (!user) {
8075
8101
  return false;
8076
8102
  }
8077
- return !!user.admin?.global;
8103
+ return !!((_a = user.admin) == null ? void 0 : _a.global);
8078
8104
  }
8079
8105
 
8080
8106
  // src/users/utils.ts
@@ -8147,7 +8173,7 @@ var unassignAppRoleEvents = async (user, roles, existingRoles) => {
8147
8173
  };
8148
8174
  var handleAppRoleEvents = async (user, existingUser) => {
8149
8175
  const roles = user.roles;
8150
- const existingRoles = existingUser?.roles;
8176
+ const existingRoles = existingUser == null ? void 0 : existingUser.roles;
8151
8177
  await assignAppRoleEvents(user, roles, existingRoles);
8152
8178
  await unassignAppRoleEvents(user, roles, existingRoles);
8153
8179
  };
@@ -8199,7 +8225,7 @@ var isRemovingAdmin = (user, existingUser) => {
8199
8225
  return isRemovingPermission(user, existingUser, hasAdminPermissions2);
8200
8226
  };
8201
8227
  var isOnboardingComplete = (user, existingUser) => {
8202
- return !existingUser?.onboardedAt && typeof user.onboardedAt === "string";
8228
+ return !(existingUser == null ? void 0 : existingUser.onboardedAt) && typeof user.onboardedAt === "string";
8203
8229
  };
8204
8230
  var isAddingPermission = (user, existingUser, hasPermission) => {
8205
8231
  if (!hasPermission(user)) {
@@ -8256,7 +8282,7 @@ async function getSessionsForUser(userId) {
8256
8282
  }
8257
8283
  async function invalidateSessions(userId, opts = {}) {
8258
8284
  try {
8259
- const reason = opts?.reason || "unknown";
8285
+ const reason = (opts == null ? void 0 : opts.reason) || "unknown";
8260
8286
  let sessionIds = opts.sessionIds || [];
8261
8287
  let sessionKeys;
8262
8288
  if (sessionIds.length === 0) {
@@ -8433,6 +8459,7 @@ var UserDB = class _UserDB {
8433
8459
  return user;
8434
8460
  }
8435
8461
  static async save(user, opts = {}) {
8462
+ var _a, _b;
8436
8463
  if (opts.hashPassword == null) {
8437
8464
  opts.hashPassword = true;
8438
8465
  }
@@ -8445,7 +8472,7 @@ var UserDB = class _UserDB {
8445
8472
  if (!email && !_id) {
8446
8473
  throw new Error("_id or email is required");
8447
8474
  }
8448
- 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()) {
8449
8476
  throw new Error("Unable to update app builders, please check license");
8450
8477
  }
8451
8478
  let dbUser;
@@ -8473,10 +8500,10 @@ var UserDB = class _UserDB {
8473
8500
  return _UserDB.quotas.addUsers(change, async () => {
8474
8501
  await validateUniqueUser(email, tenantId);
8475
8502
  let builtUser = await _UserDB.buildUser(user, opts, tenantId, dbUser);
8476
- if (opts.currentUserId && opts.currentUserId === dbUser?._id) {
8503
+ if (opts.currentUserId && opts.currentUserId === (dbUser == null ? void 0 : dbUser._id)) {
8477
8504
  builtUser = cleanseUserObject(builtUser, dbUser);
8478
8505
  }
8479
- if (!dbUser && roles?.length) {
8506
+ if (!dbUser && (roles == null ? void 0 : roles.length)) {
8480
8507
  builtUser.roles = { ...roles };
8481
8508
  }
8482
8509
  let groupPromises = [];
@@ -8755,8 +8782,8 @@ var identifyUser = async (user, account, timestamp) => {
8755
8782
  if (isSSOUser(user)) {
8756
8783
  providerType = user.providerType;
8757
8784
  }
8758
- const accountHolder = account?.budibaseUserId === user._id || false;
8759
- 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;
8760
8787
  const installationId = await getInstallationId();
8761
8788
  const hosting = account ? account.hosting : getHostingFromEnv();
8762
8789
  const environment2 = getDeploymentEnvironment();
@@ -8915,7 +8942,7 @@ var clearEvents = async () => {
8915
8942
  };
8916
8943
  var isBackfillingEvent = async (event) => {
8917
8944
  const backfill = await getBackfillMetadata();
8918
- const events2 = backfill?.eventWhitelist;
8945
+ const events2 = backfill == null ? void 0 : backfill.eventWhitelist;
8919
8946
  if (events2 && events2.includes(event)) {
8920
8947
  return true;
8921
8948
  } else {
@@ -9259,11 +9286,12 @@ var auth_default = {
9259
9286
  // src/events/publishers/automation.ts
9260
9287
  init_src();
9261
9288
  async function created3(automation, timestamp) {
9289
+ var _a, _b, _c, _d;
9262
9290
  const properties = {
9263
9291
  appId: automation.appId,
9264
9292
  automationId: automation._id,
9265
- triggerId: automation.definition?.trigger?.id,
9266
- 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,
9267
9295
  audited: {
9268
9296
  name: automation.name
9269
9297
  }
@@ -9271,20 +9299,22 @@ async function created3(automation, timestamp) {
9271
9299
  await publishEvent("automation:created" /* AUTOMATION_CREATED */, properties, timestamp);
9272
9300
  }
9273
9301
  async function triggerUpdated(automation) {
9302
+ var _a, _b, _c, _d;
9274
9303
  const properties = {
9275
9304
  appId: automation.appId,
9276
9305
  automationId: automation._id,
9277
- triggerId: automation.definition?.trigger?.id,
9278
- 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
9279
9308
  };
9280
9309
  await publishEvent("automation:trigger:updated" /* AUTOMATION_TRIGGER_UPDATED */, properties);
9281
9310
  }
9282
9311
  async function deleted3(automation) {
9312
+ var _a, _b, _c, _d;
9283
9313
  const properties = {
9284
9314
  appId: automation.appId,
9285
9315
  automationId: automation._id,
9286
- triggerId: automation.definition?.trigger?.id,
9287
- 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,
9288
9318
  audited: {
9289
9319
  name: automation.name
9290
9320
  }
@@ -9292,11 +9322,12 @@ async function deleted3(automation) {
9292
9322
  await publishEvent("automation:deleted" /* AUTOMATION_DELETED */, properties);
9293
9323
  }
9294
9324
  async function tested(automation) {
9325
+ var _a, _b, _c, _d;
9295
9326
  const properties = {
9296
9327
  appId: automation.appId,
9297
9328
  automationId: automation._id,
9298
- triggerId: automation.definition?.trigger?.id,
9299
- 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
9300
9331
  };
9301
9332
  await publishEvent("automation:tested" /* AUTOMATION_TESTED */, properties);
9302
9333
  }
@@ -9307,11 +9338,12 @@ var run = async (count, timestamp) => {
9307
9338
  await publishEvent("automations:run" /* AUTOMATIONS_RUN */, properties, timestamp);
9308
9339
  };
9309
9340
  async function stepCreated(automation, step, timestamp) {
9341
+ var _a, _b, _c, _d;
9310
9342
  const properties = {
9311
9343
  appId: automation.appId,
9312
9344
  automationId: automation._id,
9313
- triggerId: automation.definition?.trigger?.id,
9314
- 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,
9315
9347
  stepId: step.id,
9316
9348
  stepType: step.stepId,
9317
9349
  audited: {
@@ -9321,11 +9353,12 @@ async function stepCreated(automation, step, timestamp) {
9321
9353
  await publishEvent("automation:step:created" /* AUTOMATION_STEP_CREATED */, properties, timestamp);
9322
9354
  }
9323
9355
  async function stepDeleted(automation, step) {
9356
+ var _a, _b, _c, _d;
9324
9357
  const properties = {
9325
9358
  appId: automation.appId,
9326
9359
  automationId: automation._id,
9327
- triggerId: automation.definition?.trigger?.id,
9328
- 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,
9329
9362
  stepId: step.id,
9330
9363
  stepType: step.stepId,
9331
9364
  audited: {
@@ -9612,23 +9645,25 @@ var role_default = {
9612
9645
  // src/events/publishers/screen.ts
9613
9646
  init_src();
9614
9647
  async function created8(screen, timestamp) {
9648
+ var _a;
9615
9649
  const properties = {
9616
9650
  layoutId: screen.layoutId,
9617
9651
  screenId: screen._id,
9618
9652
  roleId: screen.routing.roleId,
9619
9653
  audited: {
9620
- name: screen.routing?.route
9654
+ name: (_a = screen.routing) == null ? void 0 : _a.route
9621
9655
  }
9622
9656
  };
9623
9657
  await publishEvent("screen:created" /* SCREEN_CREATED */, properties, timestamp);
9624
9658
  }
9625
9659
  async function deleted8(screen) {
9660
+ var _a;
9626
9661
  const properties = {
9627
9662
  layoutId: screen.layoutId,
9628
9663
  screenId: screen._id,
9629
9664
  roleId: screen.routing.roleId,
9630
9665
  audited: {
9631
- name: screen.routing?.route
9666
+ name: (_a = screen.routing) == null ? void 0 : _a.route
9632
9667
  }
9633
9668
  };
9634
9669
  await publishEvent("screen:deleted" /* SCREEN_DELETED */, properties);
@@ -10564,7 +10599,8 @@ var BUILTIN_PERMISSIONS = {
10564
10599
  name: "Read only",
10565
10600
  permissions: [
10566
10601
  new Permission("query" /* QUERY */, "read" /* READ */),
10567
- new Permission("table" /* TABLE */, "read" /* READ */)
10602
+ new Permission("table" /* TABLE */, "read" /* READ */),
10603
+ new Permission("view" /* VIEW */, "read" /* READ */)
10568
10604
  ]
10569
10605
  },
10570
10606
  WRITE: {
@@ -10573,6 +10609,7 @@ var BUILTIN_PERMISSIONS = {
10573
10609
  permissions: [
10574
10610
  new Permission("query" /* QUERY */, "write" /* WRITE */),
10575
10611
  new Permission("table" /* TABLE */, "write" /* WRITE */),
10612
+ new Permission("view" /* VIEW */, "read" /* READ */),
10576
10613
  new Permission("automation" /* AUTOMATION */, "execute" /* EXECUTE */)
10577
10614
  ]
10578
10615
  },
@@ -10583,6 +10620,7 @@ var BUILTIN_PERMISSIONS = {
10583
10620
  new Permission("table" /* TABLE */, "write" /* WRITE */),
10584
10621
  new Permission("user" /* USER */, "read" /* READ */),
10585
10622
  new Permission("automation" /* AUTOMATION */, "execute" /* EXECUTE */),
10623
+ new Permission("view" /* VIEW */, "read" /* READ */),
10586
10624
  new Permission("webhook" /* WEBHOOK */, "read" /* READ */)
10587
10625
  ]
10588
10626
  },
@@ -10593,6 +10631,7 @@ var BUILTIN_PERMISSIONS = {
10593
10631
  new Permission("table" /* TABLE */, "admin" /* ADMIN */),
10594
10632
  new Permission("user" /* USER */, "admin" /* ADMIN */),
10595
10633
  new Permission("automation" /* AUTOMATION */, "admin" /* ADMIN */),
10634
+ new Permission("view" /* VIEW */, "admin" /* ADMIN */),
10596
10635
  new Permission("webhook" /* WEBHOOK */, "read" /* READ */),
10597
10636
  new Permission("query" /* QUERY */, "admin" /* ADMIN */)
10598
10637
  ]
@@ -10695,7 +10734,7 @@ var BUILTIN_ROLE_NAME_ARRAY = Object.values(BUILTIN_ROLES).map(
10695
10734
  (role) => role.name
10696
10735
  );
10697
10736
  function isBuiltin(role) {
10698
- 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));
10699
10738
  }
10700
10739
  function builtinRoleToNumber(id) {
10701
10740
  if (!id) {
@@ -10722,7 +10761,7 @@ async function roleToNumber(id) {
10722
10761
  }
10723
10762
  const hierarchy = await getUserRoleHierarchy(id);
10724
10763
  for (let role of hierarchy) {
10725
- if (isBuiltin(role?.inherits)) {
10764
+ if (isBuiltin(role == null ? void 0 : role.inherits)) {
10726
10765
  return builtinRoleToNumber(role.inherits) + 1;
10727
10766
  }
10728
10767
  }
@@ -10755,7 +10794,7 @@ async function getRole(roleId, opts) {
10755
10794
  role = Object.assign(role, dbRole);
10756
10795
  role._id = getExternalRoleID(role._id, role.version);
10757
10796
  } catch (err) {
10758
- if (!isBuiltin(roleId) && opts?.defaultPublic) {
10797
+ if (!isBuiltin(roleId) && (opts == null ? void 0 : opts.defaultPublic)) {
10759
10798
  return (0, import_cloneDeep2.default)(BUILTIN_ROLES.PUBLIC);
10760
10799
  }
10761
10800
  if (Object.keys(role).length === 0) {
@@ -10878,7 +10917,7 @@ var AccessController = class {
10878
10917
  });
10879
10918
  this.userHierarchies[userRoleId] = roleIds;
10880
10919
  }
10881
- return roleIds?.indexOf(tryingRoleId) !== -1;
10920
+ return (roleIds == null ? void 0 : roleIds.indexOf(tryingRoleId)) !== -1;
10882
10921
  }
10883
10922
  async checkScreensAccess(screens, userRoleId) {
10884
10923
  let accessibleScreens = [];
@@ -10899,7 +10938,7 @@ var AccessController = class {
10899
10938
  }
10900
10939
  };
10901
10940
  function getDBRoleID(roleName) {
10902
- if (roleName?.startsWith("role" /* ROLE */)) {
10941
+ if (roleName == null ? void 0 : roleName.startsWith("role" /* ROLE */)) {
10903
10942
  return roleName;
10904
10943
  }
10905
10944
  return prefixRoleID(roleName);
@@ -11158,7 +11197,8 @@ async function authenticate2(details, requireLocalAccount = true, done, saveUser
11158
11197
  return done(null, ssoUser);
11159
11198
  }
11160
11199
  async function getProfilePictureUrl(user, details) {
11161
- const pictureUrl = details.profile?._json.picture;
11200
+ var _a;
11201
+ const pictureUrl = (_a = details.profile) == null ? void 0 : _a._json.picture;
11162
11202
  if (pictureUrl) {
11163
11203
  const response = await (0, import_node_fetch5.default)(pictureUrl);
11164
11204
  if (response.status === 200) {
@@ -11689,7 +11729,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
11689
11729
  user = await getUser(userId, session.tenantId);
11690
11730
  }
11691
11731
  user.csrfToken = session.csrfToken;
11692
- if (session?.lastAccessedAt < timeMinusOneMinute()) {
11732
+ if ((session == null ? void 0 : session.lastAccessedAt) < timeMinusOneMinute()) {
11693
11733
  await updateSessionTTL(session);
11694
11734
  }
11695
11735
  authenticated = true;
@@ -11731,9 +11771,9 @@ function authenticated_default(noAuthPatterns = [], opts = {
11731
11771
  } catch (err) {
11732
11772
  console.error(`Auth Error: ${err.message}`);
11733
11773
  console.error(err);
11734
- if (err?.name === "JsonWebTokenError") {
11774
+ if ((err == null ? void 0 : err.name) === "JsonWebTokenError") {
11735
11775
  clearCookie(ctx, "budibase:auth" /* Auth */);
11736
- } 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 */) {
11737
11777
  ctx.throw(403, err.message);
11738
11778
  }
11739
11779
  if (opts && opts.publicAllowed || publicEndpoint) {
@@ -11800,6 +11840,7 @@ var INCLUDED_CONTENT_TYPES = [
11800
11840
  function csrf_default(opts = { noCsrfPatterns: [] }) {
11801
11841
  const noCsrfOptions = buildMatcherRegex(opts.noCsrfPatterns);
11802
11842
  return async (ctx, next) => {
11843
+ var _a;
11803
11844
  const found = matches(ctx, noCsrfOptions);
11804
11845
  if (found) {
11805
11846
  return next();
@@ -11814,7 +11855,7 @@ function csrf_default(opts = { noCsrfPatterns: [] }) {
11814
11855
  if (ctx.internal) {
11815
11856
  return next();
11816
11857
  }
11817
- const userToken = ctx.user?.csrfToken;
11858
+ const userToken = (_a = ctx.user) == null ? void 0 : _a.csrfToken;
11818
11859
  if (!userToken) {
11819
11860
  return next();
11820
11861
  }
@@ -11874,7 +11915,10 @@ function pinoSettings() {
11874
11915
  logger,
11875
11916
  genReqId: correlator2.getId,
11876
11917
  autoLogging: {
11877
- ignore: (req) => !!req.url?.includes("/health")
11918
+ ignore: (req) => {
11919
+ var _a;
11920
+ return !!((_a = req.url) == null ? void 0 : _a.includes("/health"));
11921
+ }
11878
11922
  },
11879
11923
  serializers: {
11880
11924
  req: (req) => {
@@ -11945,7 +11989,8 @@ var errorHandling_default = errorHandling;
11945
11989
 
11946
11990
  // src/middleware/querystringToBody.ts
11947
11991
  function querystringToBody_default(ctx, next) {
11948
- const queryString = ctx.request.query?.query;
11992
+ var _a;
11993
+ const queryString = (_a = ctx.request.query) == null ? void 0 : _a.query;
11949
11994
  if (ctx.request.method.toLowerCase() !== "get") {
11950
11995
  ctx.throw(
11951
11996
  500,
@@ -11975,11 +12020,12 @@ __export(joi_validator_exports, {
11975
12020
  var import_joi = __toESM(require("joi"));
11976
12021
  function validate(schema, property) {
11977
12022
  return (ctx, next) => {
12023
+ var _a;
11978
12024
  if (!schema) {
11979
12025
  return next();
11980
12026
  }
11981
12027
  let params2 = null;
11982
- let reqProp = ctx.request?.[property];
12028
+ let reqProp = (_a = ctx.request) == null ? void 0 : _a[property];
11983
12029
  if (ctx[property] != null) {
11984
12030
  params2 = ctx[property];
11985
12031
  } else if (reqProp != null) {
@@ -12118,6 +12164,7 @@ async function updateUserOAuth(userId, oAuthConfig) {
12118
12164
  }
12119
12165
  }
12120
12166
  async function platformLogout(opts) {
12167
+ var _a;
12121
12168
  const ctx = opts.ctx;
12122
12169
  const userId = opts.userId;
12123
12170
  const keepActiveSession = opts.keepActiveSession;
@@ -12134,7 +12181,7 @@ async function platformLogout(opts) {
12134
12181
  }
12135
12182
  const sessionIds = sessions.map(({ sessionId }) => sessionId);
12136
12183
  await invalidateSessions(userId, { sessionIds, reason: "logout" });
12137
- await auth_default.logout(ctx.user?.email);
12184
+ await auth_default.logout((_a = ctx.user) == null ? void 0 : _a.email);
12138
12185
  await invalidateUser(userId);
12139
12186
  }
12140
12187
 
@@ -12250,7 +12297,7 @@ function validateAutomation(schema) {
12250
12297
  runJoi(validator, schema);
12251
12298
  }
12252
12299
  function validate2(schema) {
12253
- switch (schema?.type) {
12300
+ switch (schema == null ? void 0 : schema.type) {
12254
12301
  case "component" /* COMPONENT */:
12255
12302
  validateComponent(schema);
12256
12303
  break;
@@ -12314,7 +12361,7 @@ async function lookup(address) {
12314
12361
  }
12315
12362
  async function refreshBlacklist() {
12316
12363
  const blacklist = environment_default.BLACKLIST_IPS;
12317
- const list = blacklist?.split(",") || [];
12364
+ const list = (blacklist == null ? void 0 : blacklist.split(",")) || [];
12318
12365
  let final = [];
12319
12366
  for (let addr of list) {
12320
12367
  const trimmed = addr.trim();
@@ -12331,7 +12378,7 @@ async function isBlacklisted(address) {
12331
12378
  if (!blackListArray) {
12332
12379
  await refreshBlacklist();
12333
12380
  }
12334
- if (blackListArray?.length === 0) {
12381
+ if ((blackListArray == null ? void 0 : blackListArray.length) === 0) {
12335
12382
  return false;
12336
12383
  }
12337
12384
  let ips;
@@ -12340,7 +12387,7 @@ async function isBlacklisted(address) {
12340
12387
  } else {
12341
12388
  ips = [address];
12342
12389
  }
12343
- return !!blackListArray?.find((addr) => ips.includes(addr));
12390
+ return !!(blackListArray == null ? void 0 : blackListArray.find((addr) => ips.includes(addr)));
12344
12391
  }
12345
12392
 
12346
12393
  // src/docUpdates/index.ts