@budibase/backend-core 2.9.24 → 2.9.26-alpha.0

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,28 +29,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  mod
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
- var __accessCheck = (obj, member, msg) => {
33
- if (!member.has(obj))
34
- throw TypeError("Cannot " + msg);
35
- };
36
- var __privateGet = (obj, member, getter) => {
37
- __accessCheck(obj, member, "read from private field");
38
- return getter ? getter.call(obj) : member.get(obj);
39
- };
40
- var __privateAdd = (obj, member, value) => {
41
- if (member.has(obj))
42
- throw TypeError("Cannot add the same private member more than once");
43
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
44
- };
45
- var __privateSet = (obj, member, value, setter) => {
46
- __accessCheck(obj, member, "write to private field");
47
- setter ? setter.call(obj, value) : member.set(obj, value);
48
- return value;
49
- };
50
- var __privateMethod = (obj, member, method) => {
51
- __accessCheck(obj, member, "access private method");
52
- return method;
53
- };
54
32
 
55
33
  // ../types/src/sdk/automations/index.ts
56
34
  var init_automations = __esm({
@@ -705,13 +683,19 @@ var init_permissions = __esm({
705
683
  PermissionType2["WEBHOOK"] = "webhook";
706
684
  PermissionType2["BUILDER"] = "builder";
707
685
  PermissionType2["GLOBAL_BUILDER"] = "globalBuilder";
708
- PermissionType2["VIEW"] = "view";
709
686
  PermissionType2["QUERY"] = "query";
710
687
  return PermissionType2;
711
688
  })(PermissionType || {});
712
689
  }
713
690
  });
714
691
 
692
+ // ../types/src/sdk/row.ts
693
+ var init_row = __esm({
694
+ "../types/src/sdk/row.ts"() {
695
+ "use strict";
696
+ }
697
+ });
698
+
715
699
  // ../types/src/sdk/index.ts
716
700
  var init_sdk = __esm({
717
701
  "../types/src/sdk/index.ts"() {
@@ -737,6 +721,7 @@ var init_sdk = __esm({
737
721
  init_cli();
738
722
  init_websocket();
739
723
  init_permissions();
724
+ init_row();
740
725
  }
741
726
  });
742
727
 
@@ -966,7 +951,7 @@ var init_document = __esm({
966
951
  });
967
952
 
968
953
  // ../types/src/documents/app/row.ts
969
- var init_row = __esm({
954
+ var init_row2 = __esm({
970
955
  "../types/src/documents/app/row.ts"() {
971
956
  "use strict";
972
957
  }
@@ -1021,7 +1006,7 @@ var init_app3 = __esm({
1021
1006
  init_screen2();
1022
1007
  init_view2();
1023
1008
  init_document();
1024
- init_row();
1009
+ init_row2();
1025
1010
  init_user4();
1026
1011
  init_backup2();
1027
1012
  init_webhook();
@@ -1301,7 +1286,7 @@ var init_datasource3 = __esm({
1301
1286
  });
1302
1287
 
1303
1288
  // ../types/src/api/web/app/row.ts
1304
- var init_row2 = __esm({
1289
+ var init_row3 = __esm({
1305
1290
  "../types/src/api/web/app/row.ts"() {
1306
1291
  "use strict";
1307
1292
  }
@@ -1334,7 +1319,7 @@ var init_app4 = __esm({
1334
1319
  "use strict";
1335
1320
  init_backup3();
1336
1321
  init_datasource3();
1337
- init_row2();
1322
+ init_row3();
1338
1323
  init_view3();
1339
1324
  init_rows2();
1340
1325
  init_table4();
@@ -1427,6 +1412,13 @@ var init_pagination = __esm({
1427
1412
  }
1428
1413
  });
1429
1414
 
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
+
1430
1422
  // ../types/src/api/web/index.ts
1431
1423
  var init_web = __esm({
1432
1424
  "../types/src/api/web/index.ts"() {
@@ -1441,6 +1433,7 @@ var init_web = __esm({
1441
1433
  init_app4();
1442
1434
  init_global2();
1443
1435
  init_pagination();
1436
+ init_searchFilter();
1444
1437
  }
1445
1438
  });
1446
1439
 
@@ -1872,12 +1865,15 @@ var init_environment2 = __esm({
1872
1865
  });
1873
1866
 
1874
1867
  // src/context/Context.ts
1875
- var import_async_hooks, _Context, Context;
1868
+ var import_async_hooks, Context;
1876
1869
  var init_Context = __esm({
1877
1870
  "src/context/Context.ts"() {
1878
1871
  "use strict";
1879
1872
  import_async_hooks = require("async_hooks");
1880
- _Context = class _Context {
1873
+ Context = class _Context {
1874
+ static {
1875
+ this.storage = new import_async_hooks.AsyncLocalStorage();
1876
+ }
1881
1877
  static run(context, func) {
1882
1878
  return _Context.storage.run(context, () => func());
1883
1879
  }
@@ -1885,8 +1881,6 @@ var init_Context = __esm({
1885
1881
  return _Context.storage.getStore();
1886
1882
  }
1887
1883
  };
1888
- _Context.storage = new import_async_hooks.AsyncLocalStorage();
1889
- Context = _Context;
1890
1884
  }
1891
1885
  });
1892
1886
 
@@ -1928,7 +1922,7 @@ function getProdAppID(appId) {
1928
1922
  return `${APP_PREFIX}${rest}`;
1929
1923
  }
1930
1924
  function extractAppUUID(id) {
1931
- const split = (id == null ? void 0 : id.split("_")) || [];
1925
+ const split = id?.split("_") || [];
1932
1926
  return split.length ? split[split.length - 1] : null;
1933
1927
  }
1934
1928
  var NO_APP_ERROR, getDevAppID;
@@ -1948,18 +1942,17 @@ var init_connections = __esm({
1948
1942
  "use strict";
1949
1943
  init_environment2();
1950
1944
  getCouchInfo = (connection) => {
1951
- var _a, _b;
1952
1945
  const urlInfo = getUrlInfo(connection);
1953
1946
  let username;
1954
1947
  let password;
1955
- if ((_a = urlInfo.auth) == null ? void 0 : _a.username) {
1948
+ if (urlInfo.auth?.username) {
1956
1949
  username = urlInfo.auth.username;
1957
1950
  } else if (environment_default.COUCH_DB_USERNAME) {
1958
1951
  username = environment_default.COUCH_DB_USERNAME;
1959
1952
  } else if (!environment_default.isTest()) {
1960
1953
  throw new Error("CouchDB username not set");
1961
1954
  }
1962
- if ((_b = urlInfo.auth) == null ? void 0 : _b.password) {
1955
+ if (urlInfo.auth?.password) {
1963
1956
  password = urlInfo.auth.password;
1964
1957
  } else if (environment_default.COUCH_DB_PASSWORD) {
1965
1958
  password = environment_default.COUCH_DB_PASSWORD;
@@ -2218,8 +2211,7 @@ var init_DatabaseImpl = __esm({
2218
2211
  return this.instanceNano || _DatabaseImpl.nano;
2219
2212
  }
2220
2213
  async checkSetup() {
2221
- var _a;
2222
- let shouldCreate = !((_a = this.pouchOpts) == null ? void 0 : _a.skip_setup);
2214
+ let shouldCreate = !this.pouchOpts?.skip_setup;
2223
2215
  let exists2 = await this.exists();
2224
2216
  if (!shouldCreate && !exists2) {
2225
2217
  throw new Error("DB does not exist");
@@ -2295,7 +2287,7 @@ var init_DatabaseImpl = __esm({
2295
2287
  document.createdAt = (/* @__PURE__ */ new Date()).toISOString();
2296
2288
  }
2297
2289
  document.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
2298
- if ((opts == null ? void 0 : opts.force) && document._id) {
2290
+ if (opts?.force && document._id) {
2299
2291
  try {
2300
2292
  const existing = await this.get(document._id);
2301
2293
  if (existing) {
@@ -2459,7 +2451,7 @@ function isMultiTenant() {
2459
2451
  }
2460
2452
  function isTenantIdSet() {
2461
2453
  const context = Context.get();
2462
- return !!(context == null ? void 0 : context.tenantId);
2454
+ return !!context?.tenantId;
2463
2455
  }
2464
2456
  function isTenancyEnabled() {
2465
2457
  return environment_default.MULTI_TENANCY;
@@ -2558,7 +2550,7 @@ async function doInIdentityContext(identity, task) {
2558
2550
  function getIdentity() {
2559
2551
  try {
2560
2552
  const context = Context.get();
2561
- return context == null ? void 0 : context.identity;
2553
+ return context?.identity;
2562
2554
  } catch (e) {
2563
2555
  }
2564
2556
  }
@@ -2567,7 +2559,7 @@ function getTenantId() {
2567
2559
  return DEFAULT_TENANT_ID;
2568
2560
  }
2569
2561
  const context = Context.get();
2570
- const tenantId = context == null ? void 0 : context.tenantId;
2562
+ const tenantId = context?.tenantId;
2571
2563
  if (!tenantId) {
2572
2564
  throw new Error("Tenant id not found");
2573
2565
  }
@@ -2575,11 +2567,11 @@ function getTenantId() {
2575
2567
  }
2576
2568
  function getAutomationId() {
2577
2569
  const context = Context.get();
2578
- return context == null ? void 0 : context.automationId;
2570
+ return context?.automationId;
2579
2571
  }
2580
2572
  function getAppId() {
2581
2573
  const context = Context.get();
2582
- const foundId = context == null ? void 0 : context.appId;
2574
+ const foundId = context?.appId;
2583
2575
  if (!foundId && environment_default.isTest() && TEST_APP_ID) {
2584
2576
  return TEST_APP_ID;
2585
2577
  } else {
@@ -2614,7 +2606,7 @@ function getGlobalDB() {
2614
2606
  if (!context || environment_default.MULTI_TENANCY && !context.tenantId) {
2615
2607
  throw new Error("Global DB not found");
2616
2608
  }
2617
- return getDB(baseGlobalDBName(context == null ? void 0 : context.tenantId));
2609
+ return getDB(baseGlobalDBName(context?.tenantId));
2618
2610
  }
2619
2611
  function getAuditLogsDB() {
2620
2612
  if (!getTenantId()) {
@@ -2642,7 +2634,7 @@ function getDevAppDB(opts) {
2642
2634
  }
2643
2635
  function isScim() {
2644
2636
  const context = Context.get();
2645
- const scimCall = context == null ? void 0 : context.isScim;
2637
+ const scimCall = context?.isScim;
2646
2638
  return !!scimCall;
2647
2639
  }
2648
2640
  var TEST_APP_ID, getProdAppId;
@@ -3493,7 +3485,7 @@ function getGlobalUserParams(globalId, otherProps = {}) {
3493
3485
  if (!globalId) {
3494
3486
  globalId = "";
3495
3487
  }
3496
- const startkey = otherProps == null ? void 0 : otherProps.startkey;
3488
+ const startkey = otherProps?.startkey;
3497
3489
  return {
3498
3490
  ...otherProps,
3499
3491
  // need to include this incase pagination
@@ -3626,10 +3618,7 @@ async function getAllApps({
3626
3618
  } else {
3627
3619
  const response = await Promise.allSettled(appPromises);
3628
3620
  const apps = response.filter(
3629
- (result) => {
3630
- var _a;
3631
- return result.status === "fulfilled" && ((_a = result.value) == null ? void 0 : _a.state) !== "invalid" /* INVALID */;
3632
- }
3621
+ (result) => result.status === "fulfilled" && result.value?.state !== "invalid" /* INVALID */
3633
3622
  ).map(({ value }) => value);
3634
3623
  if (!all) {
3635
3624
  return apps.filter((app) => {
@@ -3691,7 +3680,7 @@ function pagination(data, pageSize, {
3691
3680
  const hasNextPage = data.length > pageSize;
3692
3681
  let nextPage = void 0;
3693
3682
  if (!getKey) {
3694
- getKey = (doc) => property ? doc == null ? void 0 : doc[property] : doc == null ? void 0 : doc._id;
3683
+ getKey = (doc) => property ? doc?.[property] : doc?._id;
3695
3684
  }
3696
3685
  if (hasNextPage) {
3697
3686
  nextPage = getKey(data[pageSize]);
@@ -3842,7 +3831,7 @@ var init_views = __esm({
3842
3831
  const docs = rows.map(
3843
3832
  (row) => params2.include_docs ? row.doc : row.value
3844
3833
  );
3845
- if (opts == null ? void 0 : opts.arrayResponse) {
3834
+ if (opts?.arrayResponse) {
3846
3835
  return docs;
3847
3836
  } else {
3848
3837
  return docs.length <= 1 ? docs[0] : docs;
@@ -4065,38 +4054,34 @@ async function fullSearch(dbName, index2, query, params2) {
4065
4054
  const rows = await recursiveSearch(dbName, index2, query, params2);
4066
4055
  return { rows };
4067
4056
  }
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;
4057
+ var import_node_fetch2, QUERY_START_REGEX, QueryBuilder;
4069
4058
  var init_lucene = __esm({
4070
4059
  "src/db/lucene.ts"() {
4071
4060
  "use strict";
4072
4061
  import_node_fetch2 = __toESM(require("node-fetch"));
4073
4062
  init_couch();
4074
4063
  QUERY_START_REGEX = /\d[0-9]*:/g;
4075
- _QueryBuilder = class _QueryBuilder {
4064
+ QueryBuilder = class _QueryBuilder {
4065
+ #dbName;
4066
+ #index;
4067
+ #query;
4068
+ #limit;
4069
+ #sort;
4070
+ #bookmark;
4071
+ #sortOrder;
4072
+ #sortType;
4073
+ #includeDocs;
4074
+ #version;
4075
+ #indexBuilder;
4076
+ #noEscaping = false;
4077
+ #skip;
4078
+ static {
4079
+ this.maxLimit = 200;
4080
+ }
4076
4081
  constructor(dbName, index2, base) {
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, {
4082
+ this.#dbName = dbName;
4083
+ this.#index = index2;
4084
+ this.#query = {
4100
4085
  allOr: false,
4101
4086
  string: {},
4102
4087
  fuzzy: {},
@@ -4110,124 +4095,124 @@ var init_lucene = __esm({
4110
4095
  notContains: {},
4111
4096
  containsAny: {},
4112
4097
  ...base
4113
- });
4114
- __privateSet(this, _limit, 50);
4115
- __privateSet(this, _sortOrder, "ascending");
4116
- __privateSet(this, _sortType, "string");
4117
- __privateSet(this, _includeDocs, true);
4098
+ };
4099
+ this.#limit = 50;
4100
+ this.#sortOrder = "ascending";
4101
+ this.#sortType = "string";
4102
+ this.#includeDocs = true;
4118
4103
  }
4119
4104
  disableEscaping() {
4120
- __privateSet(this, _noEscaping, true);
4105
+ this.#noEscaping = true;
4121
4106
  return this;
4122
4107
  }
4123
4108
  setIndexBuilder(builderFn) {
4124
- __privateSet(this, _indexBuilder, builderFn);
4109
+ this.#indexBuilder = builderFn;
4125
4110
  return this;
4126
4111
  }
4127
4112
  setVersion(version) {
4128
4113
  if (version != null) {
4129
- __privateSet(this, _version, version);
4114
+ this.#version = version;
4130
4115
  }
4131
4116
  return this;
4132
4117
  }
4133
4118
  setTable(tableId) {
4134
- __privateGet(this, _query).equal.tableId = tableId;
4119
+ this.#query.equal.tableId = tableId;
4135
4120
  return this;
4136
4121
  }
4137
4122
  setLimit(limit) {
4138
4123
  if (limit != null) {
4139
- __privateSet(this, _limit, limit);
4124
+ this.#limit = limit;
4140
4125
  }
4141
4126
  return this;
4142
4127
  }
4143
4128
  setSort(sort) {
4144
4129
  if (sort != null) {
4145
- __privateSet(this, _sort, sort);
4130
+ this.#sort = sort;
4146
4131
  }
4147
4132
  return this;
4148
4133
  }
4149
4134
  setSortOrder(sortOrder) {
4150
4135
  if (sortOrder != null) {
4151
- __privateSet(this, _sortOrder, sortOrder);
4136
+ this.#sortOrder = sortOrder;
4152
4137
  }
4153
4138
  return this;
4154
4139
  }
4155
4140
  setSortType(sortType) {
4156
4141
  if (sortType != null) {
4157
- __privateSet(this, _sortType, sortType);
4142
+ this.#sortType = sortType;
4158
4143
  }
4159
4144
  return this;
4160
4145
  }
4161
4146
  setBookmark(bookmark) {
4162
4147
  if (bookmark != null) {
4163
- __privateSet(this, _bookmark, bookmark);
4148
+ this.#bookmark = bookmark;
4164
4149
  }
4165
4150
  return this;
4166
4151
  }
4167
4152
  setSkip(skip) {
4168
- __privateSet(this, _skip, skip);
4153
+ this.#skip = skip;
4169
4154
  return this;
4170
4155
  }
4171
4156
  excludeDocs() {
4172
- __privateSet(this, _includeDocs, false);
4157
+ this.#includeDocs = false;
4173
4158
  return this;
4174
4159
  }
4175
4160
  includeDocs() {
4176
- __privateSet(this, _includeDocs, true);
4161
+ this.#includeDocs = true;
4177
4162
  return this;
4178
4163
  }
4179
4164
  addString(key, partial) {
4180
- __privateGet(this, _query).string[key] = partial;
4165
+ this.#query.string[key] = partial;
4181
4166
  return this;
4182
4167
  }
4183
4168
  addFuzzy(key, fuzzy) {
4184
- __privateGet(this, _query).fuzzy[key] = fuzzy;
4169
+ this.#query.fuzzy[key] = fuzzy;
4185
4170
  return this;
4186
4171
  }
4187
4172
  addRange(key, low, high) {
4188
- __privateGet(this, _query).range[key] = {
4173
+ this.#query.range[key] = {
4189
4174
  low,
4190
4175
  high
4191
4176
  };
4192
4177
  return this;
4193
4178
  }
4194
4179
  addEqual(key, value) {
4195
- __privateGet(this, _query).equal[key] = value;
4180
+ this.#query.equal[key] = value;
4196
4181
  return this;
4197
4182
  }
4198
4183
  addNotEqual(key, value) {
4199
- __privateGet(this, _query).notEqual[key] = value;
4184
+ this.#query.notEqual[key] = value;
4200
4185
  return this;
4201
4186
  }
4202
4187
  addEmpty(key, value) {
4203
- __privateGet(this, _query).empty[key] = value;
4188
+ this.#query.empty[key] = value;
4204
4189
  return this;
4205
4190
  }
4206
4191
  addNotEmpty(key, value) {
4207
- __privateGet(this, _query).notEmpty[key] = value;
4192
+ this.#query.notEmpty[key] = value;
4208
4193
  return this;
4209
4194
  }
4210
4195
  addOneOf(key, value) {
4211
- __privateGet(this, _query).oneOf[key] = value;
4196
+ this.#query.oneOf[key] = value;
4212
4197
  return this;
4213
4198
  }
4214
4199
  addContains(key, value) {
4215
- __privateGet(this, _query).contains[key] = value;
4200
+ this.#query.contains[key] = value;
4216
4201
  return this;
4217
4202
  }
4218
4203
  addNotContains(key, value) {
4219
- __privateGet(this, _query).notContains[key] = value;
4204
+ this.#query.notContains[key] = value;
4220
4205
  return this;
4221
4206
  }
4222
4207
  addContainsAny(key, value) {
4223
- __privateGet(this, _query).containsAny[key] = value;
4208
+ this.#query.containsAny[key] = value;
4224
4209
  return this;
4225
4210
  }
4226
4211
  setAllOr() {
4227
- __privateGet(this, _query).allOr = true;
4212
+ this.#query.allOr = true;
4228
4213
  }
4229
4214
  handleSpaces(input) {
4230
- if (__privateGet(this, _noEscaping)) {
4215
+ if (this.#noEscaping) {
4231
4216
  return input;
4232
4217
  } else {
4233
4218
  return input.replace(/ /g, "_");
@@ -4241,12 +4226,12 @@ var init_lucene = __esm({
4241
4226
  * @returns {string|*}
4242
4227
  */
4243
4228
  preprocess(value, { escape, lowercase, wrap, type } = {}) {
4244
- const hasVersion = !!__privateGet(this, _version);
4229
+ const hasVersion = !!this.#version;
4245
4230
  const originalType = typeof value;
4246
4231
  if (value && lowercase) {
4247
4232
  value = value.toLowerCase ? value.toLowerCase() : value;
4248
4233
  }
4249
- if (!__privateGet(this, _noEscaping) && escape && originalType === "string") {
4234
+ if (!this.#noEscaping && escape && originalType === "string") {
4250
4235
  value = `${value}`.replace(/[ \/#+\-&|!(){}\]^"~*?:\\]/g, "\\$&");
4251
4236
  }
4252
4237
  if (originalType === "string" && !isNaN(value) && !type) {
@@ -4258,7 +4243,7 @@ var init_lucene = __esm({
4258
4243
  }
4259
4244
  isMultiCondition() {
4260
4245
  let count = 0;
4261
- for (let filters of Object.values(__privateGet(this, _query))) {
4246
+ for (let filters of Object.values(this.#query)) {
4262
4247
  if (typeof filters === "object") {
4263
4248
  count += Object.keys(filters).length;
4264
4249
  }
@@ -4284,13 +4269,13 @@ var init_lucene = __esm({
4284
4269
  }
4285
4270
  buildSearchQuery() {
4286
4271
  const builder = this;
4287
- let allOr = __privateGet(this, _query) && __privateGet(this, _query).allOr;
4272
+ let allOr = this.#query && this.#query.allOr;
4288
4273
  let query = allOr ? "" : "*:*";
4289
4274
  const allPreProcessingOpts = { escape: true, lowercase: true, wrap: true };
4290
4275
  let tableId;
4291
- if (__privateGet(this, _query).equal.tableId) {
4292
- tableId = __privateGet(this, _query).equal.tableId;
4293
- delete __privateGet(this, _query).equal.tableId;
4276
+ if (this.#query.equal.tableId) {
4277
+ tableId = this.#query.equal.tableId;
4278
+ delete this.#query.equal.tableId;
4294
4279
  }
4295
4280
  const equal = (key, value) => {
4296
4281
  if (!value && value !== 0) {
@@ -4364,19 +4349,19 @@ var init_lucene = __esm({
4364
4349
  continue;
4365
4350
  }
4366
4351
  if (built.length > 0 || query.length > 0) {
4367
- const mode = (opts == null ? void 0 : opts.mode) ? opts.mode : allOr ? "OR" : "AND";
4352
+ const mode = opts?.mode ? opts.mode : allOr ? "OR" : "AND";
4368
4353
  built += ` ${mode} `;
4369
4354
  }
4370
4355
  built += expression;
4371
4356
  }
4372
- if (opts == null ? void 0 : opts.returnBuilt) {
4357
+ if (opts?.returnBuilt) {
4373
4358
  return built;
4374
4359
  } else {
4375
4360
  query += built;
4376
4361
  }
4377
4362
  }
4378
- if (__privateGet(this, _query).string) {
4379
- build(__privateGet(this, _query).string, (key, value) => {
4363
+ if (this.#query.string) {
4364
+ build(this.#query.string, (key, value) => {
4380
4365
  if (!value) {
4381
4366
  return null;
4382
4367
  }
@@ -4388,8 +4373,8 @@ var init_lucene = __esm({
4388
4373
  return `${key}:${value}*`;
4389
4374
  });
4390
4375
  }
4391
- if (__privateGet(this, _query).range) {
4392
- build(__privateGet(this, _query).range, (key, value) => {
4376
+ if (this.#query.range) {
4377
+ build(this.#query.range, (key, value) => {
4393
4378
  if (!value) {
4394
4379
  return null;
4395
4380
  }
@@ -4404,14 +4389,14 @@ var init_lucene = __esm({
4404
4389
  return `${key}:[${low} TO ${high}]`;
4405
4390
  });
4406
4391
  }
4407
- if (__privateGet(this, _query).fuzzy) {
4408
- build(__privateGet(this, _query).fuzzy, fuzzy);
4392
+ if (this.#query.fuzzy) {
4393
+ build(this.#query.fuzzy, fuzzy);
4409
4394
  }
4410
- if (__privateGet(this, _query).equal) {
4411
- build(__privateGet(this, _query).equal, equal);
4395
+ if (this.#query.equal) {
4396
+ build(this.#query.equal, equal);
4412
4397
  }
4413
- if (__privateGet(this, _query).notEqual) {
4414
- build(__privateGet(this, _query).notEqual, (key, value) => {
4398
+ if (this.#query.notEqual) {
4399
+ build(this.#query.notEqual, (key, value) => {
4415
4400
  if (!value) {
4416
4401
  return null;
4417
4402
  }
@@ -4421,23 +4406,23 @@ var init_lucene = __esm({
4421
4406
  return `!${key}:${builder.preprocess(value, allPreProcessingOpts)}`;
4422
4407
  });
4423
4408
  }
4424
- if (__privateGet(this, _query).empty) {
4425
- build(__privateGet(this, _query).empty, (key) => `(*:* -${key}:["" TO *])`);
4409
+ if (this.#query.empty) {
4410
+ build(this.#query.empty, (key) => `(*:* -${key}:["" TO *])`);
4426
4411
  }
4427
- if (__privateGet(this, _query).notEmpty) {
4428
- build(__privateGet(this, _query).notEmpty, (key) => `${key}:["" TO *]`);
4412
+ if (this.#query.notEmpty) {
4413
+ build(this.#query.notEmpty, (key) => `${key}:["" TO *]`);
4429
4414
  }
4430
- if (__privateGet(this, _query).oneOf) {
4431
- build(__privateGet(this, _query).oneOf, oneOf);
4415
+ if (this.#query.oneOf) {
4416
+ build(this.#query.oneOf, oneOf);
4432
4417
  }
4433
- if (__privateGet(this, _query).contains) {
4434
- build(__privateGet(this, _query).contains, contains);
4418
+ if (this.#query.contains) {
4419
+ build(this.#query.contains, contains);
4435
4420
  }
4436
- if (__privateGet(this, _query).notContains) {
4437
- build(this.compressFilters(__privateGet(this, _query).notContains), notContains);
4421
+ if (this.#query.notContains) {
4422
+ build(this.compressFilters(this.#query.notContains), notContains);
4438
4423
  }
4439
- if (__privateGet(this, _query).containsAny) {
4440
- build(__privateGet(this, _query).containsAny, containsAny);
4424
+ if (this.#query.containsAny) {
4425
+ build(this.#query.containsAny, containsAny);
4441
4426
  }
4442
4427
  if (tableId) {
4443
4428
  query = this.isMultiCondition() ? `(${query})` : query;
@@ -4449,75 +4434,63 @@ var init_lucene = __esm({
4449
4434
  buildSearchBody() {
4450
4435
  let body2 = {
4451
4436
  q: this.buildSearchQuery(),
4452
- limit: Math.min(__privateGet(this, _limit), _QueryBuilder.maxLimit),
4453
- include_docs: __privateGet(this, _includeDocs)
4437
+ limit: Math.min(this.#limit, _QueryBuilder.maxLimit),
4438
+ include_docs: this.#includeDocs
4454
4439
  };
4455
- if (__privateGet(this, _bookmark)) {
4456
- body2.bookmark = __privateGet(this, _bookmark);
4440
+ if (this.#bookmark) {
4441
+ body2.bookmark = this.#bookmark;
4457
4442
  }
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}`;
4443
+ if (this.#sort) {
4444
+ const order = this.#sortOrder === "descending" ? "-" : "";
4445
+ const type = `<${this.#sortType}>`;
4446
+ body2.sort = `${order}${this.handleSpaces(this.#sort)}${type}`;
4462
4447
  }
4463
4448
  return body2;
4464
4449
  }
4465
4450
  async run() {
4466
- if (__privateGet(this, _skip)) {
4467
- await __privateMethod(this, _skipItems, skipItems_fn).call(this, __privateGet(this, _skip));
4451
+ if (this.#skip) {
4452
+ await this.#skipItems(this.#skip);
4468
4453
  }
4469
- return await __privateMethod(this, _execute, execute_fn).call(this);
4454
+ return await this.#execute();
4470
4455
  }
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);
4456
+ /**
4457
+ * Lucene queries do not support pagination and use bookmarks instead.
4458
+ * For the given builder, walk through pages using bookmarks until the desired
4459
+ * page has been met.
4460
+ */
4461
+ async #skipItems(skip) {
4462
+ const prevIncludeDocs = this.#includeDocs;
4463
+ const prevLimit = this.#limit;
4464
+ this.excludeDocs();
4465
+ let skipRemaining = skip;
4466
+ let iterationFetched = 0;
4467
+ do {
4468
+ const toSkip = Math.min(_QueryBuilder.maxLimit, skipRemaining);
4469
+ this.setLimit(toSkip);
4470
+ const { bookmark, rows } = await this.#execute();
4471
+ this.setBookmark(bookmark);
4472
+ iterationFetched = rows.length;
4473
+ skipRemaining -= rows.length;
4474
+ } while (skipRemaining > 0 && iterationFetched > 0);
4475
+ this.#includeDocs = prevIncludeDocs;
4476
+ this.#limit = prevLimit;
4477
+ }
4478
+ async #execute() {
4479
+ const { url, cookie } = getCouchInfo();
4480
+ const fullPath = `${url}/${this.#dbName}/_design/database/_search/${this.#index}`;
4481
+ const body2 = this.buildSearchBody();
4482
+ try {
4513
4483
  return await runQuery(fullPath, body2, cookie);
4514
- } else {
4515
- throw err;
4484
+ } catch (err) {
4485
+ if (err.status === 404 && this.#indexBuilder) {
4486
+ await this.#indexBuilder();
4487
+ return await runQuery(fullPath, body2, cookie);
4488
+ } else {
4489
+ throw err;
4490
+ }
4516
4491
  }
4517
4492
  }
4518
4493
  };
4519
- _QueryBuilder.maxLimit = 200;
4520
- QueryBuilder = _QueryBuilder;
4521
4494
  }
4522
4495
  });
4523
4496
 
@@ -4596,10 +4569,9 @@ var init_searchIndexes2 = __esm({
4596
4569
 
4597
4570
  // src/db/errors.ts
4598
4571
  function checkErrorCode(error, code) {
4599
- var _a;
4600
4572
  const stringCode = code.toString();
4601
4573
  if (typeof error === "object") {
4602
- return error.status === code || ((_a = error.message) == null ? void 0 : _a.includes(stringCode));
4574
+ return error.status === code || error.message?.includes(stringCode);
4603
4575
  } else if (typeof error === "number") {
4604
4576
  return error === code;
4605
4577
  } else if (typeof error === "string") {
@@ -4850,12 +4822,12 @@ var init_objectStore = __esm({
4850
4822
  streamUpload = async (bucketName, filename, stream2, extra = {}) => {
4851
4823
  const objectStore = ObjectStore(bucketName);
4852
4824
  await makeSureBucketExists(objectStore, bucketName);
4853
- if (filename == null ? void 0 : filename.endsWith(".js")) {
4825
+ if (filename?.endsWith(".js")) {
4854
4826
  extra = {
4855
4827
  ...extra,
4856
4828
  ContentType: "application/javascript"
4857
4829
  };
4858
- } else if (filename == null ? void 0 : filename.endsWith(".svg")) {
4830
+ } else if (filename?.endsWith(".svg")) {
4859
4831
  extra = {
4860
4832
  ...extra,
4861
4833
  ContentType: "image"
@@ -4971,7 +4943,6 @@ var init_objectStore = __esm({
4971
4943
  return objectStore.deleteObjects(params2).promise();
4972
4944
  };
4973
4945
  deleteFolder = async (bucketName, folder) => {
4974
- var _a, _b, _c;
4975
4946
  bucketName = sanitizeBucket(bucketName);
4976
4947
  folder = sanitizeKey(folder);
4977
4948
  const client = ObjectStore(bucketName);
@@ -4980,7 +4951,7 @@ var init_objectStore = __esm({
4980
4951
  Prefix: folder
4981
4952
  };
4982
4953
  const existingObjectsResponse = await client.listObjects(listParams).promise();
4983
- if (((_a = existingObjectsResponse.Contents) == null ? void 0 : _a.length) === 0) {
4954
+ if (existingObjectsResponse.Contents?.length === 0) {
4984
4955
  return;
4985
4956
  }
4986
4957
  const deleteParams = {
@@ -4989,11 +4960,11 @@ var init_objectStore = __esm({
4989
4960
  Objects: []
4990
4961
  }
4991
4962
  };
4992
- (_b = existingObjectsResponse.Contents) == null ? void 0 : _b.forEach((content) => {
4963
+ existingObjectsResponse.Contents?.forEach((content) => {
4993
4964
  deleteParams.Delete.Objects.push({ Key: content.Key });
4994
4965
  });
4995
4966
  const deleteResponse = await client.deleteObjects(deleteParams).promise();
4996
- if (((_c = deleteResponse.Deleted) == null ? void 0 : _c.length) === 1e3) {
4967
+ if (deleteResponse.Deleted?.length === 1e3) {
4997
4968
  return deleteFolder(bucketName, folder);
4998
4969
  }
4999
4970
  };
@@ -5270,7 +5241,7 @@ function getFullPath(fileName) {
5270
5241
  }
5271
5242
  function getSingleFileMaxSizeInfo(totalMaxSize) {
5272
5243
  const regex = /(\d+)([A-Za-z])/;
5273
- const match = totalMaxSize == null ? void 0 : totalMaxSize.match(regex);
5244
+ const match = totalMaxSize?.match(regex);
5274
5245
  if (!match) {
5275
5246
  console.warn(`totalMaxSize does not have a valid value`, {
5276
5247
  totalMaxSize
@@ -5302,9 +5273,9 @@ function localFileDestination() {
5302
5273
  const fileInfo = getSingleFileMaxSizeInfo(environment_default.ROLLING_LOG_MAX_SIZE);
5303
5274
  const outFile = rfs.createStream(logsFileName, {
5304
5275
  // As we have a rolling size, we want to half the max size
5305
- size: fileInfo == null ? void 0 : fileInfo.size,
5276
+ size: fileInfo?.size,
5306
5277
  path: logsPath,
5307
- maxFiles: (fileInfo == null ? void 0 : fileInfo.totalHistoryFiles) || 1,
5278
+ maxFiles: fileInfo?.totalHistoryFiles || 1,
5308
5279
  immutable: true,
5309
5280
  history: budibaseLogsHistoryFileName,
5310
5281
  initialRotation: false
@@ -5379,8 +5350,8 @@ var init_logger = __esm({
5379
5350
  tenantId: getTenantId2(),
5380
5351
  appId: getAppId2(),
5381
5352
  automationId: getAutomationId2(),
5382
- identityId: identity == null ? void 0 : identity._id,
5383
- identityType: identity == null ? void 0 : identity.type,
5353
+ identityId: identity?._id,
5354
+ identityType: identity?.type,
5384
5355
  correlationId: getId()
5385
5356
  };
5386
5357
  const mergingObject = {
@@ -5444,30 +5415,30 @@ var init_logger = __esm({
5444
5415
  pinoInstance = destinations.length ? (0, import_pino.default)(pinoOptions, import_pino.default.multistream(destinations)) : (0, import_pino.default)(pinoOptions);
5445
5416
  console.log = (...arg) => {
5446
5417
  const [obj, msg] = getLogParams2(arg);
5447
- pinoInstance == null ? void 0 : pinoInstance.info(obj, msg);
5418
+ pinoInstance?.info(obj, msg);
5448
5419
  };
5449
5420
  console.info = (...arg) => {
5450
5421
  const [obj, msg] = getLogParams2(arg);
5451
- pinoInstance == null ? void 0 : pinoInstance.info(obj, msg);
5422
+ pinoInstance?.info(obj, msg);
5452
5423
  };
5453
5424
  console.warn = (...arg) => {
5454
5425
  const [obj, msg] = getLogParams2(arg);
5455
- pinoInstance == null ? void 0 : pinoInstance.warn(obj, msg);
5426
+ pinoInstance?.warn(obj, msg);
5456
5427
  };
5457
5428
  console.error = (...arg) => {
5458
5429
  const [obj, msg] = getLogParams2(arg);
5459
- pinoInstance == null ? void 0 : pinoInstance.error(obj, msg);
5430
+ pinoInstance?.error(obj, msg);
5460
5431
  };
5461
5432
  console.trace = (...arg) => {
5462
5433
  const [obj, msg] = getLogParams2(arg);
5463
5434
  if (!obj.err) {
5464
5435
  obj.err = new Error();
5465
5436
  }
5466
- pinoInstance == null ? void 0 : pinoInstance.trace(obj, msg);
5437
+ pinoInstance?.trace(obj, msg);
5467
5438
  };
5468
5439
  console.debug = (...arg) => {
5469
5440
  const [obj, msg] = getLogParams2(arg);
5470
- pinoInstance == null ? void 0 : pinoInstance.debug(obj, msg);
5441
+ pinoInstance?.debug(obj, msg);
5471
5442
  };
5472
5443
  const getTenantId2 = () => {
5473
5444
  let tenantId;
@@ -5750,7 +5721,6 @@ var isUserInAppTenant = (appId, user) => {
5750
5721
  };
5751
5722
  var ALL_STRATEGIES = Object.values(TenantResolutionStrategy);
5752
5723
  var getTenantIDFromCtx = (ctx, opts) => {
5753
- var _a;
5754
5724
  if (!isMultiTenant()) {
5755
5725
  return DEFAULT_TENANT_ID;
5756
5726
  }
@@ -5764,16 +5734,15 @@ var getTenantIDFromCtx = (ctx, opts) => {
5764
5734
  opts.excludeStrategies = [];
5765
5735
  }
5766
5736
  const isAllowed = (strategy) => {
5767
- var _a2, _b;
5768
- if ((_a2 = opts.excludeStrategies) == null ? void 0 : _a2.includes(strategy)) {
5737
+ if (opts.excludeStrategies?.includes(strategy)) {
5769
5738
  return false;
5770
5739
  }
5771
- if ((_b = opts.includeStrategies) == null ? void 0 : _b.includes(strategy)) {
5740
+ if (opts.includeStrategies?.includes(strategy)) {
5772
5741
  return true;
5773
5742
  }
5774
5743
  };
5775
5744
  if (isAllowed("user" /* USER */)) {
5776
- const userTenantId = (_a = ctx.user) == null ? void 0 : _a.tenantId;
5745
+ const userTenantId = ctx.user?.tenantId;
5777
5746
  if (userTenantId) {
5778
5747
  return userTenantId;
5779
5748
  }
@@ -6341,7 +6310,7 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
6341
6310
  logWarn(`Ignoring redlock conflict in write-through cache`);
6342
6311
  }
6343
6312
  }
6344
- cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
6313
+ cacheItem = makeCacheItem(output, updateDb ? null : cacheItem?.lastWrite);
6345
6314
  if (output._id) {
6346
6315
  await cache.store(makeCacheKey(db, output._id), cacheItem);
6347
6316
  }
@@ -6433,7 +6402,6 @@ async function getSettingsConfig() {
6433
6402
  async function getPlatformUrl(opts = {
6434
6403
  tenantAware: true
6435
6404
  }) {
6436
- var _a;
6437
6405
  let platformUrl = environment_default.PLATFORM_URL || "http://localhost:10000";
6438
6406
  if (!environment_default.SELF_HOSTED && environment_default.MULTI_TENANCY && opts.tenantAware) {
6439
6407
  const tenantId = getTenantId();
@@ -6441,11 +6409,11 @@ async function getPlatformUrl(opts = {
6441
6409
  platformUrl = platformUrl.replace("://", `://${tenantId}.`);
6442
6410
  }
6443
6411
  } else if (environment_default.SELF_HOSTED) {
6444
- const config = (opts == null ? void 0 : opts.config) ? opts.config : (
6412
+ const config = opts?.config ? opts.config : (
6445
6413
  // direct to db to prevent infinite loop
6446
- (_a = await getConfig("settings" /* SETTINGS */)) == null ? void 0 : _a.config
6414
+ (await getConfig("settings" /* SETTINGS */))?.config
6447
6415
  );
6448
- if (config == null ? void 0 : config.platformUrl) {
6416
+ if (config?.platformUrl) {
6449
6417
  platformUrl = config.platformUrl;
6450
6418
  }
6451
6419
  }
@@ -6459,14 +6427,13 @@ var analyticsEnabled = async (opts) => {
6459
6427
  "analyticsEnabled" /* ANALYTICS_ENABLED */,
6460
6428
  86400 /* ONE_DAY */,
6461
6429
  async () => {
6462
- var _a;
6463
- const config = (opts == null ? void 0 : opts.config) ? opts.config : (
6430
+ const config = opts?.config ? opts.config : (
6464
6431
  // direct to db to prevent infinite loop
6465
- (_a = await getConfig("settings" /* SETTINGS */)) == null ? void 0 : _a.config
6432
+ (await getConfig("settings" /* SETTINGS */))?.config
6466
6433
  );
6467
- if ((config == null ? void 0 : config.analyticsEnabled) === false) {
6434
+ if (config?.analyticsEnabled === false) {
6468
6435
  return false;
6469
- } else if ((config == null ? void 0 : config.analyticsEnabled) === true) {
6436
+ } else if (config?.analyticsEnabled === true) {
6470
6437
  return true;
6471
6438
  }
6472
6439
  }
@@ -6486,7 +6453,7 @@ async function getGoogleConfigDoc() {
6486
6453
  }
6487
6454
  async function getGoogleConfig() {
6488
6455
  const config = await getGoogleConfigDoc();
6489
- return config == null ? void 0 : config.config;
6456
+ return config?.config;
6490
6457
  }
6491
6458
  async function getGoogleDatasourceConfig() {
6492
6459
  if (!environment_default.SELF_HOSTED) {
@@ -6514,13 +6481,11 @@ async function getOIDCConfigDoc() {
6514
6481
  return getConfig("oidc" /* OIDC */);
6515
6482
  }
6516
6483
  async function getOIDCConfig() {
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];
6484
+ const config = (await getOIDCConfigDoc())?.config;
6485
+ return config?.configs && config.configs[0];
6520
6486
  }
6521
6487
  async function getOIDCConfigById(configId) {
6522
- var _a;
6523
- const config = (_a = await getConfig("oidc" /* OIDC */)) == null ? void 0 : _a.config;
6488
+ const config = (await getConfig("oidc" /* OIDC */))?.config;
6524
6489
  return config && config.configs.filter((c) => c.uuid === configId)[0];
6525
6490
  }
6526
6491
  async function getSMTPConfigDoc() {
@@ -6547,7 +6512,7 @@ async function getSMTPConfig(isAutomation) {
6547
6512
  }
6548
6513
  async function getSCIMConfig() {
6549
6514
  const config = await getConfig("scim" /* SCIM */);
6550
- return config == null ? void 0 : config.config;
6515
+ return config?.config;
6551
6516
  }
6552
6517
 
6553
6518
  // src/events/index.ts
@@ -6962,7 +6927,7 @@ async function getAppIdFromCtx(ctx) {
6962
6927
  appId = confirmAppId(await resolveAppUrl(ctx));
6963
6928
  }
6964
6929
  const referer = ctx.request.headers.referer;
6965
- if (!appId && (referer == null ? void 0 : referer.includes(BUILDER_APP_PREFIX))) {
6930
+ if (!appId && referer?.includes(BUILDER_APP_PREFIX)) {
6966
6931
  const refererId = parseAppIdFromUrl(ctx.request.headers.referer);
6967
6932
  appId = confirmAppId(refererId);
6968
6933
  }
@@ -7181,7 +7146,6 @@ function handleStalled(queue, removeStalledCb) {
7181
7146
  });
7182
7147
  }
7183
7148
  function getLogParams(eventType, event, opts = {}, extra = {}) {
7184
- var _a, _b, _c;
7185
7149
  const message = `[BULL] ${eventType}=${event}`;
7186
7150
  const err = opts.error;
7187
7151
  const bullLog = {
@@ -7189,11 +7153,11 @@ function getLogParams(eventType, event, opts = {}, extra = {}) {
7189
7153
  eventType,
7190
7154
  event,
7191
7155
  job: opts.job,
7192
- jobId: opts.jobId || ((_a = opts.job) == null ? void 0 : _a.id),
7156
+ jobId: opts.jobId || opts.job?.id,
7193
7157
  ...extra
7194
7158
  };
7195
7159
  let automationLog;
7196
- if ((_c = (_b = opts.job) == null ? void 0 : _b.data) == null ? void 0 : _c.automation) {
7160
+ if (opts.job?.data?.automation) {
7197
7161
  automationLog = {
7198
7162
  _logKey: "automation",
7199
7163
  trigger: opts.job ? opts.job.data.automation.definition.trigger.event : void 0
@@ -7208,11 +7172,9 @@ var EventTypeMap = {
7208
7172
  ["systemEventQueue" /* SYSTEM_EVENT_QUEUE */]: "system-event" /* SYSTEM_EVENT */
7209
7173
  };
7210
7174
  function logging(queue, jobQueue) {
7211
- var _a;
7212
7175
  const eventType = EventTypeMap[jobQueue];
7213
7176
  function doInJobContext(job, task) {
7214
- var _a2;
7215
- const appId = (_a2 = job.data.event) == null ? void 0 : _a2.appId;
7177
+ const appId = job.data.event?.appId;
7216
7178
  if (appId) {
7217
7179
  return doInContext(appId, task);
7218
7180
  } else {
@@ -7226,7 +7188,7 @@ function logging(queue, jobQueue) {
7226
7188
  }).on("error" /* ERROR */, (error) => {
7227
7189
  console.error(...getLogParams(eventType, "error" /* ERROR */, { error }));
7228
7190
  });
7229
- if ((_a = process.env.NODE_DEBUG) == null ? void 0 : _a.includes("bull")) {
7191
+ if (process.env.NODE_DEBUG?.includes("bull")) {
7230
7192
  queue.on("waiting" /* WAITING */, (jobId) => {
7231
7193
  console.info(...getLogParams(eventType, "waiting" /* WAITING */, { jobId }));
7232
7194
  }).on("active" /* ACTIVE */, async (job, jobPromise) => {
@@ -7296,7 +7258,7 @@ function createQueue(jobQueue, opts = {}) {
7296
7258
  } else {
7297
7259
  queue = new inMemoryQueue_default(jobQueue, queueConfig);
7298
7260
  }
7299
- addListeners(queue, jobQueue, opts == null ? void 0 : opts.removeStalledCb);
7261
+ addListeners(queue, jobQueue, opts?.removeStalledCb);
7300
7262
  QUEUES.push(queue);
7301
7263
  if (!cleanupInterval && !environment_default.isTest()) {
7302
7264
  cleanupInterval = set(cleanup2, CLEANUP_PERIOD_MS);
@@ -7321,7 +7283,10 @@ async function shutdown2() {
7321
7283
 
7322
7284
  // src/events/processors/AuditLogsProcessor.ts
7323
7285
  init_environment2();
7324
- var _AuditLogsProcessor = class _AuditLogsProcessor {
7286
+ var AuditLogsProcessor = class _AuditLogsProcessor {
7287
+ static {
7288
+ this.auditLogsEnabled = false;
7289
+ }
7325
7290
  // can't use constructor as need to return promise
7326
7291
  static init(fn) {
7327
7292
  _AuditLogsProcessor.auditLogsEnabled = true;
@@ -7373,12 +7338,9 @@ var _AuditLogsProcessor = class _AuditLogsProcessor {
7373
7338
  async identifyGroup(group, timestamp) {
7374
7339
  }
7375
7340
  shutdown() {
7376
- var _a;
7377
- (_a = _AuditLogsProcessor.auditLogQueue) == null ? void 0 : _a.close();
7341
+ _AuditLogsProcessor.auditLogQueue?.close();
7378
7342
  }
7379
7343
  };
7380
- _AuditLogsProcessor.auditLogsEnabled = false;
7381
- var AuditLogsProcessor = _AuditLogsProcessor;
7382
7344
 
7383
7345
  // src/events/processors/Processors.ts
7384
7346
  var Processor = class {
@@ -7593,7 +7555,7 @@ var bulkGetGlobalUsersById = async (userIds, opts) => {
7593
7555
  keys: userIds,
7594
7556
  include_docs: true
7595
7557
  })).rows.map((row) => row.doc);
7596
- if (opts == null ? void 0 : opts.cleanup) {
7558
+ if (opts?.cleanup) {
7597
7559
  users = removeUserPassword(users);
7598
7560
  }
7599
7561
  return users;
@@ -7614,7 +7576,7 @@ var bulkUpdateGlobalUsers = async (users) => {
7614
7576
  async function getById(id, opts) {
7615
7577
  const db = getGlobalDB();
7616
7578
  let user = await db.get(id);
7617
- if (opts == null ? void 0 : opts.cleanup) {
7579
+ if (opts?.cleanup) {
7618
7580
  user = removeUserPassword(user);
7619
7581
  }
7620
7582
  return user;
@@ -7631,7 +7593,7 @@ var getGlobalUserByEmail = async (email, opts) => {
7631
7593
  throw new Error(`Multiple users found with email address: ${email}`);
7632
7594
  }
7633
7595
  let user = response;
7634
- if (opts == null ? void 0 : opts.cleanup) {
7596
+ if (opts?.cleanup) {
7635
7597
  user = removeUserPassword(user);
7636
7598
  }
7637
7599
  return user;
@@ -7649,7 +7611,7 @@ var searchGlobalUsersByApp = async (appId, opts, getOpts) => {
7649
7611
  response = [];
7650
7612
  }
7651
7613
  let users = Array.isArray(response) ? response : [response];
7652
- if (getOpts == null ? void 0 : getOpts.cleanup) {
7614
+ if (getOpts?.cleanup) {
7653
7615
  users = removeUserPassword(users);
7654
7616
  }
7655
7617
  return users;
@@ -7679,10 +7641,10 @@ var searchGlobalUsersByAppAccess = async (appId, opts) => {
7679
7641
  $regex: "^us_"
7680
7642
  }
7681
7643
  },
7682
- limit: (opts == null ? void 0 : opts.limit) || 50
7644
+ limit: opts?.limit || 50
7683
7645
  };
7684
7646
  const resp = await directCouchFind(getGlobalDBName(), searchOptions);
7685
- return resp == null ? void 0 : resp.rows;
7647
+ return resp?.rows;
7686
7648
  };
7687
7649
  var getGlobalUserByAppPage = (appId, user) => {
7688
7650
  if (!user) {
@@ -7705,7 +7667,7 @@ var searchGlobalUsersByEmail = async (email, opts, getOpts) => {
7705
7667
  response = [];
7706
7668
  }
7707
7669
  let users = Array.isArray(response) ? response : [response];
7708
- if (getOpts == null ? void 0 : getOpts.cleanup) {
7670
+ if (getOpts?.cleanup) {
7709
7671
  users = removeUserPassword(users);
7710
7672
  }
7711
7673
  return users;
@@ -8056,13 +8018,12 @@ __export(users_exports2, {
8056
8018
  isGlobalBuilder: () => isGlobalBuilder
8057
8019
  });
8058
8020
  function isBuilder(user, appId) {
8059
- var _a, _b, _c;
8060
8021
  if (!user) {
8061
8022
  return false;
8062
8023
  }
8063
- if ((_a = user.builder) == null ? void 0 : _a.global) {
8024
+ if (user.builder?.global) {
8064
8025
  return true;
8065
- } else if (appId && ((_c = (_b = user.builder) == null ? void 0 : _b.apps) == null ? void 0 : _c.includes(getProdAppID2(appId)))) {
8026
+ } else if (appId && user.builder?.apps?.includes(getProdAppID2(appId))) {
8066
8027
  return true;
8067
8028
  }
8068
8029
  return false;
@@ -8080,27 +8041,24 @@ function isAdminOrBuilder(user, appId) {
8080
8041
  return isBuilder(user, appId) || isAdmin(user);
8081
8042
  }
8082
8043
  function hasAppBuilderPermissions(user) {
8083
- var _a, _b, _c;
8084
8044
  if (!user) {
8085
8045
  return false;
8086
8046
  }
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);
8047
+ const appLength = user.builder?.apps?.length;
8048
+ const isGlobalBuilder3 = !!user.builder?.global;
8089
8049
  return !isGlobalBuilder3 && appLength != null && appLength > 0;
8090
8050
  }
8091
8051
  function hasBuilderPermissions(user) {
8092
- var _a;
8093
8052
  if (!user) {
8094
8053
  return false;
8095
8054
  }
8096
- return ((_a = user.builder) == null ? void 0 : _a.global) || hasAppBuilderPermissions(user);
8055
+ return user.builder?.global || hasAppBuilderPermissions(user);
8097
8056
  }
8098
8057
  function hasAdminPermissions(user) {
8099
- var _a;
8100
8058
  if (!user) {
8101
8059
  return false;
8102
8060
  }
8103
- return !!((_a = user.admin) == null ? void 0 : _a.global);
8061
+ return !!user.admin?.global;
8104
8062
  }
8105
8063
 
8106
8064
  // src/users/utils.ts
@@ -8173,7 +8131,7 @@ var unassignAppRoleEvents = async (user, roles, existingRoles) => {
8173
8131
  };
8174
8132
  var handleAppRoleEvents = async (user, existingUser) => {
8175
8133
  const roles = user.roles;
8176
- const existingRoles = existingUser == null ? void 0 : existingUser.roles;
8134
+ const existingRoles = existingUser?.roles;
8177
8135
  await assignAppRoleEvents(user, roles, existingRoles);
8178
8136
  await unassignAppRoleEvents(user, roles, existingRoles);
8179
8137
  };
@@ -8225,7 +8183,7 @@ var isRemovingAdmin = (user, existingUser) => {
8225
8183
  return isRemovingPermission(user, existingUser, hasAdminPermissions2);
8226
8184
  };
8227
8185
  var isOnboardingComplete = (user, existingUser) => {
8228
- return !(existingUser == null ? void 0 : existingUser.onboardedAt) && typeof user.onboardedAt === "string";
8186
+ return !existingUser?.onboardedAt && typeof user.onboardedAt === "string";
8229
8187
  };
8230
8188
  var isAddingPermission = (user, existingUser, hasPermission) => {
8231
8189
  if (!hasPermission(user)) {
@@ -8282,7 +8240,7 @@ async function getSessionsForUser(userId) {
8282
8240
  }
8283
8241
  async function invalidateSessions(userId, opts = {}) {
8284
8242
  try {
8285
- const reason = (opts == null ? void 0 : opts.reason) || "unknown";
8243
+ const reason = opts?.reason || "unknown";
8286
8244
  let sessionIds = opts.sessionIds || [];
8287
8245
  let sessionKeys;
8288
8246
  if (sessionIds.length === 0) {
@@ -8459,7 +8417,6 @@ var UserDB = class _UserDB {
8459
8417
  return user;
8460
8418
  }
8461
8419
  static async save(user, opts = {}) {
8462
- var _a, _b;
8463
8420
  if (opts.hashPassword == null) {
8464
8421
  opts.hashPassword = true;
8465
8422
  }
@@ -8472,7 +8429,7 @@ var UserDB = class _UserDB {
8472
8429
  if (!email && !_id) {
8473
8430
  throw new Error("_id or email is required");
8474
8431
  }
8475
- if (((_b = (_a = user.builder) == null ? void 0 : _a.apps) == null ? void 0 : _b.length) && !await _UserDB.features.isAppBuildersEnabled()) {
8432
+ if (user.builder?.apps?.length && !await _UserDB.features.isAppBuildersEnabled()) {
8476
8433
  throw new Error("Unable to update app builders, please check license");
8477
8434
  }
8478
8435
  let dbUser;
@@ -8500,10 +8457,10 @@ var UserDB = class _UserDB {
8500
8457
  return _UserDB.quotas.addUsers(change, async () => {
8501
8458
  await validateUniqueUser(email, tenantId);
8502
8459
  let builtUser = await _UserDB.buildUser(user, opts, tenantId, dbUser);
8503
- if (opts.currentUserId && opts.currentUserId === (dbUser == null ? void 0 : dbUser._id)) {
8460
+ if (opts.currentUserId && opts.currentUserId === dbUser?._id) {
8504
8461
  builtUser = cleanseUserObject(builtUser, dbUser);
8505
8462
  }
8506
- if (!dbUser && (roles == null ? void 0 : roles.length)) {
8463
+ if (!dbUser && roles?.length) {
8507
8464
  builtUser.roles = { ...roles };
8508
8465
  }
8509
8466
  let groupPromises = [];
@@ -8782,8 +8739,8 @@ var identifyUser = async (user, account, timestamp) => {
8782
8739
  if (isSSOUser(user)) {
8783
8740
  providerType = user.providerType;
8784
8741
  }
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;
8742
+ const accountHolder = account?.budibaseUserId === user._id || false;
8743
+ const verified2 = account && account?.budibaseUserId === user._id ? account.verified : false;
8787
8744
  const installationId = await getInstallationId();
8788
8745
  const hosting = account ? account.hosting : getHostingFromEnv();
8789
8746
  const environment2 = getDeploymentEnvironment();
@@ -8942,7 +8899,7 @@ var clearEvents = async () => {
8942
8899
  };
8943
8900
  var isBackfillingEvent = async (event) => {
8944
8901
  const backfill = await getBackfillMetadata();
8945
- const events2 = backfill == null ? void 0 : backfill.eventWhitelist;
8902
+ const events2 = backfill?.eventWhitelist;
8946
8903
  if (events2 && events2.includes(event)) {
8947
8904
  return true;
8948
8905
  } else {
@@ -9286,12 +9243,11 @@ var auth_default = {
9286
9243
  // src/events/publishers/automation.ts
9287
9244
  init_src();
9288
9245
  async function created3(automation, timestamp) {
9289
- var _a, _b, _c, _d;
9290
9246
  const properties = {
9291
9247
  appId: automation.appId,
9292
9248
  automationId: automation._id,
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,
9249
+ triggerId: automation.definition?.trigger?.id,
9250
+ triggerType: automation.definition?.trigger?.stepId,
9295
9251
  audited: {
9296
9252
  name: automation.name
9297
9253
  }
@@ -9299,22 +9255,20 @@ async function created3(automation, timestamp) {
9299
9255
  await publishEvent("automation:created" /* AUTOMATION_CREATED */, properties, timestamp);
9300
9256
  }
9301
9257
  async function triggerUpdated(automation) {
9302
- var _a, _b, _c, _d;
9303
9258
  const properties = {
9304
9259
  appId: automation.appId,
9305
9260
  automationId: automation._id,
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
9261
+ triggerId: automation.definition?.trigger?.id,
9262
+ triggerType: automation.definition?.trigger?.stepId
9308
9263
  };
9309
9264
  await publishEvent("automation:trigger:updated" /* AUTOMATION_TRIGGER_UPDATED */, properties);
9310
9265
  }
9311
9266
  async function deleted3(automation) {
9312
- var _a, _b, _c, _d;
9313
9267
  const properties = {
9314
9268
  appId: automation.appId,
9315
9269
  automationId: automation._id,
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,
9270
+ triggerId: automation.definition?.trigger?.id,
9271
+ triggerType: automation.definition?.trigger?.stepId,
9318
9272
  audited: {
9319
9273
  name: automation.name
9320
9274
  }
@@ -9322,12 +9276,11 @@ async function deleted3(automation) {
9322
9276
  await publishEvent("automation:deleted" /* AUTOMATION_DELETED */, properties);
9323
9277
  }
9324
9278
  async function tested(automation) {
9325
- var _a, _b, _c, _d;
9326
9279
  const properties = {
9327
9280
  appId: automation.appId,
9328
9281
  automationId: automation._id,
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
9282
+ triggerId: automation.definition?.trigger?.id,
9283
+ triggerType: automation.definition?.trigger?.stepId
9331
9284
  };
9332
9285
  await publishEvent("automation:tested" /* AUTOMATION_TESTED */, properties);
9333
9286
  }
@@ -9338,12 +9291,11 @@ var run = async (count, timestamp) => {
9338
9291
  await publishEvent("automations:run" /* AUTOMATIONS_RUN */, properties, timestamp);
9339
9292
  };
9340
9293
  async function stepCreated(automation, step, timestamp) {
9341
- var _a, _b, _c, _d;
9342
9294
  const properties = {
9343
9295
  appId: automation.appId,
9344
9296
  automationId: automation._id,
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,
9297
+ triggerId: automation.definition?.trigger?.id,
9298
+ triggerType: automation.definition?.trigger?.stepId,
9347
9299
  stepId: step.id,
9348
9300
  stepType: step.stepId,
9349
9301
  audited: {
@@ -9353,12 +9305,11 @@ async function stepCreated(automation, step, timestamp) {
9353
9305
  await publishEvent("automation:step:created" /* AUTOMATION_STEP_CREATED */, properties, timestamp);
9354
9306
  }
9355
9307
  async function stepDeleted(automation, step) {
9356
- var _a, _b, _c, _d;
9357
9308
  const properties = {
9358
9309
  appId: automation.appId,
9359
9310
  automationId: automation._id,
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,
9311
+ triggerId: automation.definition?.trigger?.id,
9312
+ triggerType: automation.definition?.trigger?.stepId,
9362
9313
  stepId: step.id,
9363
9314
  stepType: step.stepId,
9364
9315
  audited: {
@@ -9645,25 +9596,23 @@ var role_default = {
9645
9596
  // src/events/publishers/screen.ts
9646
9597
  init_src();
9647
9598
  async function created8(screen, timestamp) {
9648
- var _a;
9649
9599
  const properties = {
9650
9600
  layoutId: screen.layoutId,
9651
9601
  screenId: screen._id,
9652
9602
  roleId: screen.routing.roleId,
9653
9603
  audited: {
9654
- name: (_a = screen.routing) == null ? void 0 : _a.route
9604
+ name: screen.routing?.route
9655
9605
  }
9656
9606
  };
9657
9607
  await publishEvent("screen:created" /* SCREEN_CREATED */, properties, timestamp);
9658
9608
  }
9659
9609
  async function deleted8(screen) {
9660
- var _a;
9661
9610
  const properties = {
9662
9611
  layoutId: screen.layoutId,
9663
9612
  screenId: screen._id,
9664
9613
  roleId: screen.routing.roleId,
9665
9614
  audited: {
9666
- name: (_a = screen.routing) == null ? void 0 : _a.route
9615
+ name: screen.routing?.route
9667
9616
  }
9668
9617
  };
9669
9618
  await publishEvent("screen:deleted" /* SCREEN_DELETED */, properties);
@@ -10599,8 +10548,7 @@ var BUILTIN_PERMISSIONS = {
10599
10548
  name: "Read only",
10600
10549
  permissions: [
10601
10550
  new Permission("query" /* QUERY */, "read" /* READ */),
10602
- new Permission("table" /* TABLE */, "read" /* READ */),
10603
- new Permission("view" /* VIEW */, "read" /* READ */)
10551
+ new Permission("table" /* TABLE */, "read" /* READ */)
10604
10552
  ]
10605
10553
  },
10606
10554
  WRITE: {
@@ -10609,7 +10557,6 @@ var BUILTIN_PERMISSIONS = {
10609
10557
  permissions: [
10610
10558
  new Permission("query" /* QUERY */, "write" /* WRITE */),
10611
10559
  new Permission("table" /* TABLE */, "write" /* WRITE */),
10612
- new Permission("view" /* VIEW */, "read" /* READ */),
10613
10560
  new Permission("automation" /* AUTOMATION */, "execute" /* EXECUTE */)
10614
10561
  ]
10615
10562
  },
@@ -10620,7 +10567,6 @@ var BUILTIN_PERMISSIONS = {
10620
10567
  new Permission("table" /* TABLE */, "write" /* WRITE */),
10621
10568
  new Permission("user" /* USER */, "read" /* READ */),
10622
10569
  new Permission("automation" /* AUTOMATION */, "execute" /* EXECUTE */),
10623
- new Permission("view" /* VIEW */, "read" /* READ */),
10624
10570
  new Permission("webhook" /* WEBHOOK */, "read" /* READ */)
10625
10571
  ]
10626
10572
  },
@@ -10631,7 +10577,6 @@ var BUILTIN_PERMISSIONS = {
10631
10577
  new Permission("table" /* TABLE */, "admin" /* ADMIN */),
10632
10578
  new Permission("user" /* USER */, "admin" /* ADMIN */),
10633
10579
  new Permission("automation" /* AUTOMATION */, "admin" /* ADMIN */),
10634
- new Permission("view" /* VIEW */, "admin" /* ADMIN */),
10635
10580
  new Permission("webhook" /* WEBHOOK */, "read" /* READ */),
10636
10581
  new Permission("query" /* QUERY */, "admin" /* ADMIN */)
10637
10582
  ]
@@ -10734,7 +10679,7 @@ var BUILTIN_ROLE_NAME_ARRAY = Object.values(BUILTIN_ROLES).map(
10734
10679
  (role) => role.name
10735
10680
  );
10736
10681
  function isBuiltin(role) {
10737
- return BUILTIN_ROLE_ID_ARRAY.some((builtin) => role == null ? void 0 : role.includes(builtin));
10682
+ return BUILTIN_ROLE_ID_ARRAY.some((builtin) => role?.includes(builtin));
10738
10683
  }
10739
10684
  function builtinRoleToNumber(id) {
10740
10685
  if (!id) {
@@ -10761,7 +10706,7 @@ async function roleToNumber(id) {
10761
10706
  }
10762
10707
  const hierarchy = await getUserRoleHierarchy(id);
10763
10708
  for (let role of hierarchy) {
10764
- if (isBuiltin(role == null ? void 0 : role.inherits)) {
10709
+ if (isBuiltin(role?.inherits)) {
10765
10710
  return builtinRoleToNumber(role.inherits) + 1;
10766
10711
  }
10767
10712
  }
@@ -10794,7 +10739,7 @@ async function getRole(roleId, opts) {
10794
10739
  role = Object.assign(role, dbRole);
10795
10740
  role._id = getExternalRoleID(role._id, role.version);
10796
10741
  } catch (err) {
10797
- if (!isBuiltin(roleId) && (opts == null ? void 0 : opts.defaultPublic)) {
10742
+ if (!isBuiltin(roleId) && opts?.defaultPublic) {
10798
10743
  return (0, import_cloneDeep2.default)(BUILTIN_ROLES.PUBLIC);
10799
10744
  }
10800
10745
  if (Object.keys(role).length === 0) {
@@ -10917,7 +10862,7 @@ var AccessController = class {
10917
10862
  });
10918
10863
  this.userHierarchies[userRoleId] = roleIds;
10919
10864
  }
10920
- return (roleIds == null ? void 0 : roleIds.indexOf(tryingRoleId)) !== -1;
10865
+ return roleIds?.indexOf(tryingRoleId) !== -1;
10921
10866
  }
10922
10867
  async checkScreensAccess(screens, userRoleId) {
10923
10868
  let accessibleScreens = [];
@@ -10938,7 +10883,7 @@ var AccessController = class {
10938
10883
  }
10939
10884
  };
10940
10885
  function getDBRoleID(roleName) {
10941
- if (roleName == null ? void 0 : roleName.startsWith("role" /* ROLE */)) {
10886
+ if (roleName?.startsWith("role" /* ROLE */)) {
10942
10887
  return roleName;
10943
10888
  }
10944
10889
  return prefixRoleID(roleName);
@@ -11197,8 +11142,7 @@ async function authenticate2(details, requireLocalAccount = true, done, saveUser
11197
11142
  return done(null, ssoUser);
11198
11143
  }
11199
11144
  async function getProfilePictureUrl(user, details) {
11200
- var _a;
11201
- const pictureUrl = (_a = details.profile) == null ? void 0 : _a._json.picture;
11145
+ const pictureUrl = details.profile?._json.picture;
11202
11146
  if (pictureUrl) {
11203
11147
  const response = await (0, import_node_fetch5.default)(pictureUrl);
11204
11148
  if (response.status === 200) {
@@ -11729,7 +11673,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
11729
11673
  user = await getUser(userId, session.tenantId);
11730
11674
  }
11731
11675
  user.csrfToken = session.csrfToken;
11732
- if ((session == null ? void 0 : session.lastAccessedAt) < timeMinusOneMinute()) {
11676
+ if (session?.lastAccessedAt < timeMinusOneMinute()) {
11733
11677
  await updateSessionTTL(session);
11734
11678
  }
11735
11679
  authenticated = true;
@@ -11771,9 +11715,9 @@ function authenticated_default(noAuthPatterns = [], opts = {
11771
11715
  } catch (err) {
11772
11716
  console.error(`Auth Error: ${err.message}`);
11773
11717
  console.error(err);
11774
- if ((err == null ? void 0 : err.name) === "JsonWebTokenError") {
11718
+ if (err?.name === "JsonWebTokenError") {
11775
11719
  clearCookie(ctx, "budibase:auth" /* Auth */);
11776
- } else if ((err == null ? void 0 : err.code) === "invalid_api_key" /* INVALID_API_KEY */) {
11720
+ } else if (err?.code === "invalid_api_key" /* INVALID_API_KEY */) {
11777
11721
  ctx.throw(403, err.message);
11778
11722
  }
11779
11723
  if (opts && opts.publicAllowed || publicEndpoint) {
@@ -11840,7 +11784,6 @@ var INCLUDED_CONTENT_TYPES = [
11840
11784
  function csrf_default(opts = { noCsrfPatterns: [] }) {
11841
11785
  const noCsrfOptions = buildMatcherRegex(opts.noCsrfPatterns);
11842
11786
  return async (ctx, next) => {
11843
- var _a;
11844
11787
  const found = matches(ctx, noCsrfOptions);
11845
11788
  if (found) {
11846
11789
  return next();
@@ -11855,7 +11798,7 @@ function csrf_default(opts = { noCsrfPatterns: [] }) {
11855
11798
  if (ctx.internal) {
11856
11799
  return next();
11857
11800
  }
11858
- const userToken = (_a = ctx.user) == null ? void 0 : _a.csrfToken;
11801
+ const userToken = ctx.user?.csrfToken;
11859
11802
  if (!userToken) {
11860
11803
  return next();
11861
11804
  }
@@ -11915,10 +11858,7 @@ function pinoSettings() {
11915
11858
  logger,
11916
11859
  genReqId: correlator2.getId,
11917
11860
  autoLogging: {
11918
- ignore: (req) => {
11919
- var _a;
11920
- return !!((_a = req.url) == null ? void 0 : _a.includes("/health"));
11921
- }
11861
+ ignore: (req) => !!req.url?.includes("/health")
11922
11862
  },
11923
11863
  serializers: {
11924
11864
  req: (req) => {
@@ -11989,8 +11929,7 @@ var errorHandling_default = errorHandling;
11989
11929
 
11990
11930
  // src/middleware/querystringToBody.ts
11991
11931
  function querystringToBody_default(ctx, next) {
11992
- var _a;
11993
- const queryString = (_a = ctx.request.query) == null ? void 0 : _a.query;
11932
+ const queryString = ctx.request.query?.query;
11994
11933
  if (ctx.request.method.toLowerCase() !== "get") {
11995
11934
  ctx.throw(
11996
11935
  500,
@@ -12020,12 +11959,11 @@ __export(joi_validator_exports, {
12020
11959
  var import_joi = __toESM(require("joi"));
12021
11960
  function validate(schema, property) {
12022
11961
  return (ctx, next) => {
12023
- var _a;
12024
11962
  if (!schema) {
12025
11963
  return next();
12026
11964
  }
12027
11965
  let params2 = null;
12028
- let reqProp = (_a = ctx.request) == null ? void 0 : _a[property];
11966
+ let reqProp = ctx.request?.[property];
12029
11967
  if (ctx[property] != null) {
12030
11968
  params2 = ctx[property];
12031
11969
  } else if (reqProp != null) {
@@ -12164,7 +12102,6 @@ async function updateUserOAuth(userId, oAuthConfig) {
12164
12102
  }
12165
12103
  }
12166
12104
  async function platformLogout(opts) {
12167
- var _a;
12168
12105
  const ctx = opts.ctx;
12169
12106
  const userId = opts.userId;
12170
12107
  const keepActiveSession = opts.keepActiveSession;
@@ -12181,7 +12118,7 @@ async function platformLogout(opts) {
12181
12118
  }
12182
12119
  const sessionIds = sessions.map(({ sessionId }) => sessionId);
12183
12120
  await invalidateSessions(userId, { sessionIds, reason: "logout" });
12184
- await auth_default.logout((_a = ctx.user) == null ? void 0 : _a.email);
12121
+ await auth_default.logout(ctx.user?.email);
12185
12122
  await invalidateUser(userId);
12186
12123
  }
12187
12124
 
@@ -12297,7 +12234,7 @@ function validateAutomation(schema) {
12297
12234
  runJoi(validator, schema);
12298
12235
  }
12299
12236
  function validate2(schema) {
12300
- switch (schema == null ? void 0 : schema.type) {
12237
+ switch (schema?.type) {
12301
12238
  case "component" /* COMPONENT */:
12302
12239
  validateComponent(schema);
12303
12240
  break;
@@ -12361,7 +12298,7 @@ async function lookup(address) {
12361
12298
  }
12362
12299
  async function refreshBlacklist() {
12363
12300
  const blacklist = environment_default.BLACKLIST_IPS;
12364
- const list = (blacklist == null ? void 0 : blacklist.split(",")) || [];
12301
+ const list = blacklist?.split(",") || [];
12365
12302
  let final = [];
12366
12303
  for (let addr of list) {
12367
12304
  const trimmed = addr.trim();
@@ -12378,7 +12315,7 @@ async function isBlacklisted(address) {
12378
12315
  if (!blackListArray) {
12379
12316
  await refreshBlacklist();
12380
12317
  }
12381
- if ((blackListArray == null ? void 0 : blackListArray.length) === 0) {
12318
+ if (blackListArray?.length === 0) {
12382
12319
  return false;
12383
12320
  }
12384
12321
  let ips;
@@ -12387,7 +12324,7 @@ async function isBlacklisted(address) {
12387
12324
  } else {
12388
12325
  ips = [address];
12389
12326
  }
12390
- return !!(blackListArray == null ? void 0 : blackListArray.find((addr) => ips.includes(addr)));
12327
+ return !!blackListArray?.find((addr) => ips.includes(addr));
12391
12328
  }
12392
12329
 
12393
12330
  // src/docUpdates/index.ts