@budibase/backend-core 2.9.17 → 2.9.19-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({
@@ -712,6 +690,13 @@ var init_permissions = __esm({
712
690
  }
713
691
  });
714
692
 
693
+ // ../types/src/sdk/row.ts
694
+ var init_row = __esm({
695
+ "../types/src/sdk/row.ts"() {
696
+ "use strict";
697
+ }
698
+ });
699
+
715
700
  // ../types/src/sdk/index.ts
716
701
  var init_sdk = __esm({
717
702
  "../types/src/sdk/index.ts"() {
@@ -737,6 +722,7 @@ var init_sdk = __esm({
737
722
  init_cli();
738
723
  init_websocket();
739
724
  init_permissions();
725
+ init_row();
740
726
  }
741
727
  });
742
728
 
@@ -966,7 +952,7 @@ var init_document = __esm({
966
952
  });
967
953
 
968
954
  // ../types/src/documents/app/row.ts
969
- var init_row = __esm({
955
+ var init_row2 = __esm({
970
956
  "../types/src/documents/app/row.ts"() {
971
957
  "use strict";
972
958
  }
@@ -1021,7 +1007,7 @@ var init_app3 = __esm({
1021
1007
  init_screen2();
1022
1008
  init_view2();
1023
1009
  init_document();
1024
- init_row();
1010
+ init_row2();
1025
1011
  init_user4();
1026
1012
  init_backup2();
1027
1013
  init_webhook();
@@ -1301,7 +1287,7 @@ var init_datasource3 = __esm({
1301
1287
  });
1302
1288
 
1303
1289
  // ../types/src/api/web/app/row.ts
1304
- var init_row2 = __esm({
1290
+ var init_row3 = __esm({
1305
1291
  "../types/src/api/web/app/row.ts"() {
1306
1292
  "use strict";
1307
1293
  }
@@ -1334,7 +1320,7 @@ var init_app4 = __esm({
1334
1320
  "use strict";
1335
1321
  init_backup3();
1336
1322
  init_datasource3();
1337
- init_row2();
1323
+ init_row3();
1338
1324
  init_view3();
1339
1325
  init_rows2();
1340
1326
  init_table4();
@@ -1427,6 +1413,13 @@ var init_pagination = __esm({
1427
1413
  }
1428
1414
  });
1429
1415
 
1416
+ // ../types/src/api/web/searchFilter.ts
1417
+ var init_searchFilter = __esm({
1418
+ "../types/src/api/web/searchFilter.ts"() {
1419
+ "use strict";
1420
+ }
1421
+ });
1422
+
1430
1423
  // ../types/src/api/web/index.ts
1431
1424
  var init_web = __esm({
1432
1425
  "../types/src/api/web/index.ts"() {
@@ -1441,6 +1434,7 @@ var init_web = __esm({
1441
1434
  init_app4();
1442
1435
  init_global2();
1443
1436
  init_pagination();
1437
+ init_searchFilter();
1444
1438
  }
1445
1439
  });
1446
1440
 
@@ -1872,12 +1866,15 @@ var init_environment2 = __esm({
1872
1866
  });
1873
1867
 
1874
1868
  // src/context/Context.ts
1875
- var import_async_hooks, _Context, Context;
1869
+ var import_async_hooks, Context;
1876
1870
  var init_Context = __esm({
1877
1871
  "src/context/Context.ts"() {
1878
1872
  "use strict";
1879
1873
  import_async_hooks = require("async_hooks");
1880
- _Context = class _Context {
1874
+ Context = class _Context {
1875
+ static {
1876
+ this.storage = new import_async_hooks.AsyncLocalStorage();
1877
+ }
1881
1878
  static run(context, func) {
1882
1879
  return _Context.storage.run(context, () => func());
1883
1880
  }
@@ -1885,8 +1882,6 @@ var init_Context = __esm({
1885
1882
  return _Context.storage.getStore();
1886
1883
  }
1887
1884
  };
1888
- _Context.storage = new import_async_hooks.AsyncLocalStorage();
1889
- Context = _Context;
1890
1885
  }
1891
1886
  });
1892
1887
 
@@ -1928,7 +1923,7 @@ function getProdAppID(appId) {
1928
1923
  return `${APP_PREFIX}${rest}`;
1929
1924
  }
1930
1925
  function extractAppUUID(id) {
1931
- const split = (id == null ? void 0 : id.split("_")) || [];
1926
+ const split = id?.split("_") || [];
1932
1927
  return split.length ? split[split.length - 1] : null;
1933
1928
  }
1934
1929
  var NO_APP_ERROR, getDevAppID;
@@ -1948,18 +1943,17 @@ var init_connections = __esm({
1948
1943
  "use strict";
1949
1944
  init_environment2();
1950
1945
  getCouchInfo = (connection) => {
1951
- var _a, _b;
1952
1946
  const urlInfo = getUrlInfo(connection);
1953
1947
  let username;
1954
1948
  let password;
1955
- if ((_a = urlInfo.auth) == null ? void 0 : _a.username) {
1949
+ if (urlInfo.auth?.username) {
1956
1950
  username = urlInfo.auth.username;
1957
1951
  } else if (environment_default.COUCH_DB_USERNAME) {
1958
1952
  username = environment_default.COUCH_DB_USERNAME;
1959
1953
  } else if (!environment_default.isTest()) {
1960
1954
  throw new Error("CouchDB username not set");
1961
1955
  }
1962
- if ((_b = urlInfo.auth) == null ? void 0 : _b.password) {
1956
+ if (urlInfo.auth?.password) {
1963
1957
  password = urlInfo.auth.password;
1964
1958
  } else if (environment_default.COUCH_DB_PASSWORD) {
1965
1959
  password = environment_default.COUCH_DB_PASSWORD;
@@ -2218,8 +2212,7 @@ var init_DatabaseImpl = __esm({
2218
2212
  return this.instanceNano || _DatabaseImpl.nano;
2219
2213
  }
2220
2214
  async checkSetup() {
2221
- var _a;
2222
- let shouldCreate = !((_a = this.pouchOpts) == null ? void 0 : _a.skip_setup);
2215
+ let shouldCreate = !this.pouchOpts?.skip_setup;
2223
2216
  let exists2 = await this.exists();
2224
2217
  if (!shouldCreate && !exists2) {
2225
2218
  throw new Error("DB does not exist");
@@ -2283,7 +2276,7 @@ var init_DatabaseImpl = __esm({
2283
2276
  document.createdAt = (/* @__PURE__ */ new Date()).toISOString();
2284
2277
  }
2285
2278
  document.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
2286
- if ((opts == null ? void 0 : opts.force) && document._id) {
2279
+ if (opts?.force && document._id) {
2287
2280
  try {
2288
2281
  const existing = await this.get(document._id);
2289
2282
  if (existing) {
@@ -2447,7 +2440,7 @@ function isMultiTenant() {
2447
2440
  }
2448
2441
  function isTenantIdSet() {
2449
2442
  const context = Context.get();
2450
- return !!(context == null ? void 0 : context.tenantId);
2443
+ return !!context?.tenantId;
2451
2444
  }
2452
2445
  function isTenancyEnabled() {
2453
2446
  return environment_default.MULTI_TENANCY;
@@ -2546,7 +2539,7 @@ async function doInIdentityContext(identity, task) {
2546
2539
  function getIdentity() {
2547
2540
  try {
2548
2541
  const context = Context.get();
2549
- return context == null ? void 0 : context.identity;
2542
+ return context?.identity;
2550
2543
  } catch (e) {
2551
2544
  }
2552
2545
  }
@@ -2555,7 +2548,7 @@ function getTenantId() {
2555
2548
  return DEFAULT_TENANT_ID;
2556
2549
  }
2557
2550
  const context = Context.get();
2558
- const tenantId = context == null ? void 0 : context.tenantId;
2551
+ const tenantId = context?.tenantId;
2559
2552
  if (!tenantId) {
2560
2553
  throw new Error("Tenant id not found");
2561
2554
  }
@@ -2563,11 +2556,11 @@ function getTenantId() {
2563
2556
  }
2564
2557
  function getAutomationId() {
2565
2558
  const context = Context.get();
2566
- return context == null ? void 0 : context.automationId;
2559
+ return context?.automationId;
2567
2560
  }
2568
2561
  function getAppId() {
2569
2562
  const context = Context.get();
2570
- const foundId = context == null ? void 0 : context.appId;
2563
+ const foundId = context?.appId;
2571
2564
  if (!foundId && environment_default.isTest() && TEST_APP_ID) {
2572
2565
  return TEST_APP_ID;
2573
2566
  } else {
@@ -2602,7 +2595,7 @@ function getGlobalDB() {
2602
2595
  if (!context || environment_default.MULTI_TENANCY && !context.tenantId) {
2603
2596
  throw new Error("Global DB not found");
2604
2597
  }
2605
- return getDB(baseGlobalDBName(context == null ? void 0 : context.tenantId));
2598
+ return getDB(baseGlobalDBName(context?.tenantId));
2606
2599
  }
2607
2600
  function getAuditLogsDB() {
2608
2601
  if (!getTenantId()) {
@@ -2630,7 +2623,7 @@ function getDevAppDB(opts) {
2630
2623
  }
2631
2624
  function isScim() {
2632
2625
  const context = Context.get();
2633
- const scimCall = context == null ? void 0 : context.isScim;
2626
+ const scimCall = context?.isScim;
2634
2627
  return !!scimCall;
2635
2628
  }
2636
2629
  var TEST_APP_ID, getProdAppId;
@@ -3481,7 +3474,7 @@ function getGlobalUserParams(globalId, otherProps = {}) {
3481
3474
  if (!globalId) {
3482
3475
  globalId = "";
3483
3476
  }
3484
- const startkey = otherProps == null ? void 0 : otherProps.startkey;
3477
+ const startkey = otherProps?.startkey;
3485
3478
  return {
3486
3479
  ...otherProps,
3487
3480
  // need to include this incase pagination
@@ -3614,10 +3607,7 @@ async function getAllApps({
3614
3607
  } else {
3615
3608
  const response = await Promise.allSettled(appPromises);
3616
3609
  const apps = response.filter(
3617
- (result) => {
3618
- var _a;
3619
- return result.status === "fulfilled" && ((_a = result.value) == null ? void 0 : _a.state) !== "invalid" /* INVALID */;
3620
- }
3610
+ (result) => result.status === "fulfilled" && result.value?.state !== "invalid" /* INVALID */
3621
3611
  ).map(({ value }) => value);
3622
3612
  if (!all) {
3623
3613
  return apps.filter((app) => {
@@ -3679,7 +3669,7 @@ function pagination(data, pageSize, {
3679
3669
  const hasNextPage = data.length > pageSize;
3680
3670
  let nextPage = void 0;
3681
3671
  if (!getKey) {
3682
- getKey = (doc) => property ? doc == null ? void 0 : doc[property] : doc == null ? void 0 : doc._id;
3672
+ getKey = (doc) => property ? doc?.[property] : doc?._id;
3683
3673
  }
3684
3674
  if (hasNextPage) {
3685
3675
  nextPage = getKey(data[pageSize]);
@@ -3830,7 +3820,7 @@ var init_views = __esm({
3830
3820
  const docs = rows.map(
3831
3821
  (row) => params2.include_docs ? row.doc : row.value
3832
3822
  );
3833
- if (opts == null ? void 0 : opts.arrayResponse) {
3823
+ if (opts?.arrayResponse) {
3834
3824
  return docs;
3835
3825
  } else {
3836
3826
  return docs.length <= 1 ? docs[0] : docs;
@@ -4053,38 +4043,34 @@ async function fullSearch(dbName, index2, query, params2) {
4053
4043
  const rows = await recursiveSearch(dbName, index2, query, params2);
4054
4044
  return { rows };
4055
4045
  }
4056
- 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;
4046
+ var import_node_fetch2, QUERY_START_REGEX, QueryBuilder;
4057
4047
  var init_lucene = __esm({
4058
4048
  "src/db/lucene.ts"() {
4059
4049
  "use strict";
4060
4050
  import_node_fetch2 = __toESM(require("node-fetch"));
4061
4051
  init_couch();
4062
4052
  QUERY_START_REGEX = /\d[0-9]*:/g;
4063
- _QueryBuilder = class _QueryBuilder {
4053
+ QueryBuilder = class _QueryBuilder {
4054
+ #dbName;
4055
+ #index;
4056
+ #query;
4057
+ #limit;
4058
+ #sort;
4059
+ #bookmark;
4060
+ #sortOrder;
4061
+ #sortType;
4062
+ #includeDocs;
4063
+ #version;
4064
+ #indexBuilder;
4065
+ #noEscaping = false;
4066
+ #skip;
4067
+ static {
4068
+ this.maxLimit = 200;
4069
+ }
4064
4070
  constructor(dbName, index2, base) {
4065
- /**
4066
- * Lucene queries do not support pagination and use bookmarks instead.
4067
- * For the given builder, walk through pages using bookmarks until the desired
4068
- * page has been met.
4069
- */
4070
- __privateAdd(this, _skipItems);
4071
- __privateAdd(this, _execute);
4072
- __privateAdd(this, _dbName, void 0);
4073
- __privateAdd(this, _index, void 0);
4074
- __privateAdd(this, _query, void 0);
4075
- __privateAdd(this, _limit, void 0);
4076
- __privateAdd(this, _sort, void 0);
4077
- __privateAdd(this, _bookmark, void 0);
4078
- __privateAdd(this, _sortOrder, void 0);
4079
- __privateAdd(this, _sortType, void 0);
4080
- __privateAdd(this, _includeDocs, void 0);
4081
- __privateAdd(this, _version, void 0);
4082
- __privateAdd(this, _indexBuilder, void 0);
4083
- __privateAdd(this, _noEscaping, false);
4084
- __privateAdd(this, _skip, void 0);
4085
- __privateSet(this, _dbName, dbName);
4086
- __privateSet(this, _index, index2);
4087
- __privateSet(this, _query, {
4071
+ this.#dbName = dbName;
4072
+ this.#index = index2;
4073
+ this.#query = {
4088
4074
  allOr: false,
4089
4075
  string: {},
4090
4076
  fuzzy: {},
@@ -4098,124 +4084,124 @@ var init_lucene = __esm({
4098
4084
  notContains: {},
4099
4085
  containsAny: {},
4100
4086
  ...base
4101
- });
4102
- __privateSet(this, _limit, 50);
4103
- __privateSet(this, _sortOrder, "ascending");
4104
- __privateSet(this, _sortType, "string");
4105
- __privateSet(this, _includeDocs, true);
4087
+ };
4088
+ this.#limit = 50;
4089
+ this.#sortOrder = "ascending";
4090
+ this.#sortType = "string";
4091
+ this.#includeDocs = true;
4106
4092
  }
4107
4093
  disableEscaping() {
4108
- __privateSet(this, _noEscaping, true);
4094
+ this.#noEscaping = true;
4109
4095
  return this;
4110
4096
  }
4111
4097
  setIndexBuilder(builderFn) {
4112
- __privateSet(this, _indexBuilder, builderFn);
4098
+ this.#indexBuilder = builderFn;
4113
4099
  return this;
4114
4100
  }
4115
4101
  setVersion(version) {
4116
4102
  if (version != null) {
4117
- __privateSet(this, _version, version);
4103
+ this.#version = version;
4118
4104
  }
4119
4105
  return this;
4120
4106
  }
4121
4107
  setTable(tableId) {
4122
- __privateGet(this, _query).equal.tableId = tableId;
4108
+ this.#query.equal.tableId = tableId;
4123
4109
  return this;
4124
4110
  }
4125
4111
  setLimit(limit) {
4126
4112
  if (limit != null) {
4127
- __privateSet(this, _limit, limit);
4113
+ this.#limit = limit;
4128
4114
  }
4129
4115
  return this;
4130
4116
  }
4131
4117
  setSort(sort) {
4132
4118
  if (sort != null) {
4133
- __privateSet(this, _sort, sort);
4119
+ this.#sort = sort;
4134
4120
  }
4135
4121
  return this;
4136
4122
  }
4137
4123
  setSortOrder(sortOrder) {
4138
4124
  if (sortOrder != null) {
4139
- __privateSet(this, _sortOrder, sortOrder);
4125
+ this.#sortOrder = sortOrder;
4140
4126
  }
4141
4127
  return this;
4142
4128
  }
4143
4129
  setSortType(sortType) {
4144
4130
  if (sortType != null) {
4145
- __privateSet(this, _sortType, sortType);
4131
+ this.#sortType = sortType;
4146
4132
  }
4147
4133
  return this;
4148
4134
  }
4149
4135
  setBookmark(bookmark) {
4150
4136
  if (bookmark != null) {
4151
- __privateSet(this, _bookmark, bookmark);
4137
+ this.#bookmark = bookmark;
4152
4138
  }
4153
4139
  return this;
4154
4140
  }
4155
4141
  setSkip(skip) {
4156
- __privateSet(this, _skip, skip);
4142
+ this.#skip = skip;
4157
4143
  return this;
4158
4144
  }
4159
4145
  excludeDocs() {
4160
- __privateSet(this, _includeDocs, false);
4146
+ this.#includeDocs = false;
4161
4147
  return this;
4162
4148
  }
4163
4149
  includeDocs() {
4164
- __privateSet(this, _includeDocs, true);
4150
+ this.#includeDocs = true;
4165
4151
  return this;
4166
4152
  }
4167
4153
  addString(key, partial) {
4168
- __privateGet(this, _query).string[key] = partial;
4154
+ this.#query.string[key] = partial;
4169
4155
  return this;
4170
4156
  }
4171
4157
  addFuzzy(key, fuzzy) {
4172
- __privateGet(this, _query).fuzzy[key] = fuzzy;
4158
+ this.#query.fuzzy[key] = fuzzy;
4173
4159
  return this;
4174
4160
  }
4175
4161
  addRange(key, low, high) {
4176
- __privateGet(this, _query).range[key] = {
4162
+ this.#query.range[key] = {
4177
4163
  low,
4178
4164
  high
4179
4165
  };
4180
4166
  return this;
4181
4167
  }
4182
4168
  addEqual(key, value) {
4183
- __privateGet(this, _query).equal[key] = value;
4169
+ this.#query.equal[key] = value;
4184
4170
  return this;
4185
4171
  }
4186
4172
  addNotEqual(key, value) {
4187
- __privateGet(this, _query).notEqual[key] = value;
4173
+ this.#query.notEqual[key] = value;
4188
4174
  return this;
4189
4175
  }
4190
4176
  addEmpty(key, value) {
4191
- __privateGet(this, _query).empty[key] = value;
4177
+ this.#query.empty[key] = value;
4192
4178
  return this;
4193
4179
  }
4194
4180
  addNotEmpty(key, value) {
4195
- __privateGet(this, _query).notEmpty[key] = value;
4181
+ this.#query.notEmpty[key] = value;
4196
4182
  return this;
4197
4183
  }
4198
4184
  addOneOf(key, value) {
4199
- __privateGet(this, _query).oneOf[key] = value;
4185
+ this.#query.oneOf[key] = value;
4200
4186
  return this;
4201
4187
  }
4202
4188
  addContains(key, value) {
4203
- __privateGet(this, _query).contains[key] = value;
4189
+ this.#query.contains[key] = value;
4204
4190
  return this;
4205
4191
  }
4206
4192
  addNotContains(key, value) {
4207
- __privateGet(this, _query).notContains[key] = value;
4193
+ this.#query.notContains[key] = value;
4208
4194
  return this;
4209
4195
  }
4210
4196
  addContainsAny(key, value) {
4211
- __privateGet(this, _query).containsAny[key] = value;
4197
+ this.#query.containsAny[key] = value;
4212
4198
  return this;
4213
4199
  }
4214
4200
  setAllOr() {
4215
- __privateGet(this, _query).allOr = true;
4201
+ this.#query.allOr = true;
4216
4202
  }
4217
4203
  handleSpaces(input) {
4218
- if (__privateGet(this, _noEscaping)) {
4204
+ if (this.#noEscaping) {
4219
4205
  return input;
4220
4206
  } else {
4221
4207
  return input.replace(/ /g, "_");
@@ -4229,12 +4215,12 @@ var init_lucene = __esm({
4229
4215
  * @returns {string|*}
4230
4216
  */
4231
4217
  preprocess(value, { escape, lowercase, wrap, type } = {}) {
4232
- const hasVersion = !!__privateGet(this, _version);
4218
+ const hasVersion = !!this.#version;
4233
4219
  const originalType = typeof value;
4234
4220
  if (value && lowercase) {
4235
4221
  value = value.toLowerCase ? value.toLowerCase() : value;
4236
4222
  }
4237
- if (!__privateGet(this, _noEscaping) && escape && originalType === "string") {
4223
+ if (!this.#noEscaping && escape && originalType === "string") {
4238
4224
  value = `${value}`.replace(/[ \/#+\-&|!(){}\]^"~*?:\\]/g, "\\$&");
4239
4225
  }
4240
4226
  if (originalType === "string" && !isNaN(value) && !type) {
@@ -4246,7 +4232,7 @@ var init_lucene = __esm({
4246
4232
  }
4247
4233
  isMultiCondition() {
4248
4234
  let count = 0;
4249
- for (let filters of Object.values(__privateGet(this, _query))) {
4235
+ for (let filters of Object.values(this.#query)) {
4250
4236
  if (typeof filters === "object") {
4251
4237
  count += Object.keys(filters).length;
4252
4238
  }
@@ -4272,13 +4258,13 @@ var init_lucene = __esm({
4272
4258
  }
4273
4259
  buildSearchQuery() {
4274
4260
  const builder = this;
4275
- let allOr = __privateGet(this, _query) && __privateGet(this, _query).allOr;
4261
+ let allOr = this.#query && this.#query.allOr;
4276
4262
  let query = allOr ? "" : "*:*";
4277
4263
  const allPreProcessingOpts = { escape: true, lowercase: true, wrap: true };
4278
4264
  let tableId;
4279
- if (__privateGet(this, _query).equal.tableId) {
4280
- tableId = __privateGet(this, _query).equal.tableId;
4281
- delete __privateGet(this, _query).equal.tableId;
4265
+ if (this.#query.equal.tableId) {
4266
+ tableId = this.#query.equal.tableId;
4267
+ delete this.#query.equal.tableId;
4282
4268
  }
4283
4269
  const equal = (key, value) => {
4284
4270
  if (!value && value !== 0) {
@@ -4352,19 +4338,19 @@ var init_lucene = __esm({
4352
4338
  continue;
4353
4339
  }
4354
4340
  if (built.length > 0 || query.length > 0) {
4355
- const mode = (opts == null ? void 0 : opts.mode) ? opts.mode : allOr ? "OR" : "AND";
4341
+ const mode = opts?.mode ? opts.mode : allOr ? "OR" : "AND";
4356
4342
  built += ` ${mode} `;
4357
4343
  }
4358
4344
  built += expression;
4359
4345
  }
4360
- if (opts == null ? void 0 : opts.returnBuilt) {
4346
+ if (opts?.returnBuilt) {
4361
4347
  return built;
4362
4348
  } else {
4363
4349
  query += built;
4364
4350
  }
4365
4351
  }
4366
- if (__privateGet(this, _query).string) {
4367
- build(__privateGet(this, _query).string, (key, value) => {
4352
+ if (this.#query.string) {
4353
+ build(this.#query.string, (key, value) => {
4368
4354
  if (!value) {
4369
4355
  return null;
4370
4356
  }
@@ -4376,8 +4362,8 @@ var init_lucene = __esm({
4376
4362
  return `${key}:${value}*`;
4377
4363
  });
4378
4364
  }
4379
- if (__privateGet(this, _query).range) {
4380
- build(__privateGet(this, _query).range, (key, value) => {
4365
+ if (this.#query.range) {
4366
+ build(this.#query.range, (key, value) => {
4381
4367
  if (!value) {
4382
4368
  return null;
4383
4369
  }
@@ -4392,14 +4378,14 @@ var init_lucene = __esm({
4392
4378
  return `${key}:[${low} TO ${high}]`;
4393
4379
  });
4394
4380
  }
4395
- if (__privateGet(this, _query).fuzzy) {
4396
- build(__privateGet(this, _query).fuzzy, fuzzy);
4381
+ if (this.#query.fuzzy) {
4382
+ build(this.#query.fuzzy, fuzzy);
4397
4383
  }
4398
- if (__privateGet(this, _query).equal) {
4399
- build(__privateGet(this, _query).equal, equal);
4384
+ if (this.#query.equal) {
4385
+ build(this.#query.equal, equal);
4400
4386
  }
4401
- if (__privateGet(this, _query).notEqual) {
4402
- build(__privateGet(this, _query).notEqual, (key, value) => {
4387
+ if (this.#query.notEqual) {
4388
+ build(this.#query.notEqual, (key, value) => {
4403
4389
  if (!value) {
4404
4390
  return null;
4405
4391
  }
@@ -4409,23 +4395,23 @@ var init_lucene = __esm({
4409
4395
  return `!${key}:${builder.preprocess(value, allPreProcessingOpts)}`;
4410
4396
  });
4411
4397
  }
4412
- if (__privateGet(this, _query).empty) {
4413
- build(__privateGet(this, _query).empty, (key) => `(*:* -${key}:["" TO *])`);
4398
+ if (this.#query.empty) {
4399
+ build(this.#query.empty, (key) => `(*:* -${key}:["" TO *])`);
4414
4400
  }
4415
- if (__privateGet(this, _query).notEmpty) {
4416
- build(__privateGet(this, _query).notEmpty, (key) => `${key}:["" TO *]`);
4401
+ if (this.#query.notEmpty) {
4402
+ build(this.#query.notEmpty, (key) => `${key}:["" TO *]`);
4417
4403
  }
4418
- if (__privateGet(this, _query).oneOf) {
4419
- build(__privateGet(this, _query).oneOf, oneOf);
4404
+ if (this.#query.oneOf) {
4405
+ build(this.#query.oneOf, oneOf);
4420
4406
  }
4421
- if (__privateGet(this, _query).contains) {
4422
- build(__privateGet(this, _query).contains, contains);
4407
+ if (this.#query.contains) {
4408
+ build(this.#query.contains, contains);
4423
4409
  }
4424
- if (__privateGet(this, _query).notContains) {
4425
- build(this.compressFilters(__privateGet(this, _query).notContains), notContains);
4410
+ if (this.#query.notContains) {
4411
+ build(this.compressFilters(this.#query.notContains), notContains);
4426
4412
  }
4427
- if (__privateGet(this, _query).containsAny) {
4428
- build(__privateGet(this, _query).containsAny, containsAny);
4413
+ if (this.#query.containsAny) {
4414
+ build(this.#query.containsAny, containsAny);
4429
4415
  }
4430
4416
  if (tableId) {
4431
4417
  query = this.isMultiCondition() ? `(${query})` : query;
@@ -4437,75 +4423,63 @@ var init_lucene = __esm({
4437
4423
  buildSearchBody() {
4438
4424
  let body2 = {
4439
4425
  q: this.buildSearchQuery(),
4440
- limit: Math.min(__privateGet(this, _limit), _QueryBuilder.maxLimit),
4441
- include_docs: __privateGet(this, _includeDocs)
4426
+ limit: Math.min(this.#limit, _QueryBuilder.maxLimit),
4427
+ include_docs: this.#includeDocs
4442
4428
  };
4443
- if (__privateGet(this, _bookmark)) {
4444
- body2.bookmark = __privateGet(this, _bookmark);
4429
+ if (this.#bookmark) {
4430
+ body2.bookmark = this.#bookmark;
4445
4431
  }
4446
- if (__privateGet(this, _sort)) {
4447
- const order = __privateGet(this, _sortOrder) === "descending" ? "-" : "";
4448
- const type = `<${__privateGet(this, _sortType)}>`;
4449
- body2.sort = `${order}${this.handleSpaces(__privateGet(this, _sort))}${type}`;
4432
+ if (this.#sort) {
4433
+ const order = this.#sortOrder === "descending" ? "-" : "";
4434
+ const type = `<${this.#sortType}>`;
4435
+ body2.sort = `${order}${this.handleSpaces(this.#sort)}${type}`;
4450
4436
  }
4451
4437
  return body2;
4452
4438
  }
4453
4439
  async run() {
4454
- if (__privateGet(this, _skip)) {
4455
- await __privateMethod(this, _skipItems, skipItems_fn).call(this, __privateGet(this, _skip));
4440
+ if (this.#skip) {
4441
+ await this.#skipItems(this.#skip);
4456
4442
  }
4457
- return await __privateMethod(this, _execute, execute_fn).call(this);
4443
+ return await this.#execute();
4458
4444
  }
4459
- };
4460
- _dbName = new WeakMap();
4461
- _index = new WeakMap();
4462
- _query = new WeakMap();
4463
- _limit = new WeakMap();
4464
- _sort = new WeakMap();
4465
- _bookmark = new WeakMap();
4466
- _sortOrder = new WeakMap();
4467
- _sortType = new WeakMap();
4468
- _includeDocs = new WeakMap();
4469
- _version = new WeakMap();
4470
- _indexBuilder = new WeakMap();
4471
- _noEscaping = new WeakMap();
4472
- _skip = new WeakMap();
4473
- _skipItems = new WeakSet();
4474
- skipItems_fn = async function(skip) {
4475
- const prevIncludeDocs = __privateGet(this, _includeDocs);
4476
- const prevLimit = __privateGet(this, _limit);
4477
- this.excludeDocs();
4478
- let skipRemaining = skip;
4479
- let iterationFetched = 0;
4480
- do {
4481
- const toSkip = Math.min(_QueryBuilder.maxLimit, skipRemaining);
4482
- this.setLimit(toSkip);
4483
- const { bookmark, rows } = await __privateMethod(this, _execute, execute_fn).call(this);
4484
- this.setBookmark(bookmark);
4485
- iterationFetched = rows.length;
4486
- skipRemaining -= rows.length;
4487
- } while (skipRemaining > 0 && iterationFetched > 0);
4488
- __privateSet(this, _includeDocs, prevIncludeDocs);
4489
- __privateSet(this, _limit, prevLimit);
4490
- };
4491
- _execute = new WeakSet();
4492
- execute_fn = async function() {
4493
- const { url, cookie } = getCouchInfo();
4494
- const fullPath = `${url}/${__privateGet(this, _dbName)}/_design/database/_search/${__privateGet(this, _index)}`;
4495
- const body2 = this.buildSearchBody();
4496
- try {
4497
- return await runQuery(fullPath, body2, cookie);
4498
- } catch (err) {
4499
- if (err.status === 404 && __privateGet(this, _indexBuilder)) {
4500
- await __privateGet(this, _indexBuilder).call(this);
4445
+ /**
4446
+ * Lucene queries do not support pagination and use bookmarks instead.
4447
+ * For the given builder, walk through pages using bookmarks until the desired
4448
+ * page has been met.
4449
+ */
4450
+ async #skipItems(skip) {
4451
+ const prevIncludeDocs = this.#includeDocs;
4452
+ const prevLimit = this.#limit;
4453
+ this.excludeDocs();
4454
+ let skipRemaining = skip;
4455
+ let iterationFetched = 0;
4456
+ do {
4457
+ const toSkip = Math.min(_QueryBuilder.maxLimit, skipRemaining);
4458
+ this.setLimit(toSkip);
4459
+ const { bookmark, rows } = await this.#execute();
4460
+ this.setBookmark(bookmark);
4461
+ iterationFetched = rows.length;
4462
+ skipRemaining -= rows.length;
4463
+ } while (skipRemaining > 0 && iterationFetched > 0);
4464
+ this.#includeDocs = prevIncludeDocs;
4465
+ this.#limit = prevLimit;
4466
+ }
4467
+ async #execute() {
4468
+ const { url, cookie } = getCouchInfo();
4469
+ const fullPath = `${url}/${this.#dbName}/_design/database/_search/${this.#index}`;
4470
+ const body2 = this.buildSearchBody();
4471
+ try {
4501
4472
  return await runQuery(fullPath, body2, cookie);
4502
- } else {
4503
- throw err;
4473
+ } catch (err) {
4474
+ if (err.status === 404 && this.#indexBuilder) {
4475
+ await this.#indexBuilder();
4476
+ return await runQuery(fullPath, body2, cookie);
4477
+ } else {
4478
+ throw err;
4479
+ }
4504
4480
  }
4505
4481
  }
4506
4482
  };
4507
- _QueryBuilder.maxLimit = 200;
4508
- QueryBuilder = _QueryBuilder;
4509
4483
  }
4510
4484
  });
4511
4485
 
@@ -4584,10 +4558,9 @@ var init_searchIndexes2 = __esm({
4584
4558
 
4585
4559
  // src/db/errors.ts
4586
4560
  function checkErrorCode(error, code) {
4587
- var _a;
4588
4561
  const stringCode = code.toString();
4589
4562
  if (typeof error === "object") {
4590
- return error.status === code || ((_a = error.message) == null ? void 0 : _a.includes(stringCode));
4563
+ return error.status === code || error.message?.includes(stringCode);
4591
4564
  } else if (typeof error === "number") {
4592
4565
  return error === code;
4593
4566
  } else if (typeof error === "string") {
@@ -4838,12 +4811,12 @@ var init_objectStore = __esm({
4838
4811
  streamUpload = async (bucketName, filename, stream2, extra = {}) => {
4839
4812
  const objectStore = ObjectStore(bucketName);
4840
4813
  await makeSureBucketExists(objectStore, bucketName);
4841
- if (filename == null ? void 0 : filename.endsWith(".js")) {
4814
+ if (filename?.endsWith(".js")) {
4842
4815
  extra = {
4843
4816
  ...extra,
4844
4817
  ContentType: "application/javascript"
4845
4818
  };
4846
- } else if (filename == null ? void 0 : filename.endsWith(".svg")) {
4819
+ } else if (filename?.endsWith(".svg")) {
4847
4820
  extra = {
4848
4821
  ...extra,
4849
4822
  ContentType: "image"
@@ -4959,7 +4932,6 @@ var init_objectStore = __esm({
4959
4932
  return objectStore.deleteObjects(params2).promise();
4960
4933
  };
4961
4934
  deleteFolder = async (bucketName, folder) => {
4962
- var _a, _b, _c;
4963
4935
  bucketName = sanitizeBucket(bucketName);
4964
4936
  folder = sanitizeKey(folder);
4965
4937
  const client = ObjectStore(bucketName);
@@ -4968,7 +4940,7 @@ var init_objectStore = __esm({
4968
4940
  Prefix: folder
4969
4941
  };
4970
4942
  const existingObjectsResponse = await client.listObjects(listParams).promise();
4971
- if (((_a = existingObjectsResponse.Contents) == null ? void 0 : _a.length) === 0) {
4943
+ if (existingObjectsResponse.Contents?.length === 0) {
4972
4944
  return;
4973
4945
  }
4974
4946
  const deleteParams = {
@@ -4977,11 +4949,11 @@ var init_objectStore = __esm({
4977
4949
  Objects: []
4978
4950
  }
4979
4951
  };
4980
- (_b = existingObjectsResponse.Contents) == null ? void 0 : _b.forEach((content) => {
4952
+ existingObjectsResponse.Contents?.forEach((content) => {
4981
4953
  deleteParams.Delete.Objects.push({ Key: content.Key });
4982
4954
  });
4983
4955
  const deleteResponse = await client.deleteObjects(deleteParams).promise();
4984
- if (((_c = deleteResponse.Deleted) == null ? void 0 : _c.length) === 1e3) {
4956
+ if (deleteResponse.Deleted?.length === 1e3) {
4985
4957
  return deleteFolder(bucketName, folder);
4986
4958
  }
4987
4959
  };
@@ -5258,7 +5230,7 @@ function getFullPath(fileName) {
5258
5230
  }
5259
5231
  function getSingleFileMaxSizeInfo(totalMaxSize) {
5260
5232
  const regex = /(\d+)([A-Za-z])/;
5261
- const match = totalMaxSize == null ? void 0 : totalMaxSize.match(regex);
5233
+ const match = totalMaxSize?.match(regex);
5262
5234
  if (!match) {
5263
5235
  console.warn(`totalMaxSize does not have a valid value`, {
5264
5236
  totalMaxSize
@@ -5290,9 +5262,9 @@ function localFileDestination() {
5290
5262
  const fileInfo = getSingleFileMaxSizeInfo(environment_default.ROLLING_LOG_MAX_SIZE);
5291
5263
  const outFile = rfs.createStream(logsFileName, {
5292
5264
  // As we have a rolling size, we want to half the max size
5293
- size: fileInfo == null ? void 0 : fileInfo.size,
5265
+ size: fileInfo?.size,
5294
5266
  path: logsPath,
5295
- maxFiles: (fileInfo == null ? void 0 : fileInfo.totalHistoryFiles) || 1,
5267
+ maxFiles: fileInfo?.totalHistoryFiles || 1,
5296
5268
  immutable: true,
5297
5269
  history: budibaseLogsHistoryFileName,
5298
5270
  initialRotation: false
@@ -5367,8 +5339,8 @@ var init_logger = __esm({
5367
5339
  tenantId: getTenantId2(),
5368
5340
  appId: getAppId2(),
5369
5341
  automationId: getAutomationId2(),
5370
- identityId: identity == null ? void 0 : identity._id,
5371
- identityType: identity == null ? void 0 : identity.type,
5342
+ identityId: identity?._id,
5343
+ identityType: identity?.type,
5372
5344
  correlationId: getId()
5373
5345
  };
5374
5346
  const mergingObject = {
@@ -5432,30 +5404,30 @@ var init_logger = __esm({
5432
5404
  pinoInstance = destinations.length ? (0, import_pino.default)(pinoOptions, import_pino.default.multistream(destinations)) : (0, import_pino.default)(pinoOptions);
5433
5405
  console.log = (...arg) => {
5434
5406
  const [obj, msg] = getLogParams2(arg);
5435
- pinoInstance == null ? void 0 : pinoInstance.info(obj, msg);
5407
+ pinoInstance?.info(obj, msg);
5436
5408
  };
5437
5409
  console.info = (...arg) => {
5438
5410
  const [obj, msg] = getLogParams2(arg);
5439
- pinoInstance == null ? void 0 : pinoInstance.info(obj, msg);
5411
+ pinoInstance?.info(obj, msg);
5440
5412
  };
5441
5413
  console.warn = (...arg) => {
5442
5414
  const [obj, msg] = getLogParams2(arg);
5443
- pinoInstance == null ? void 0 : pinoInstance.warn(obj, msg);
5415
+ pinoInstance?.warn(obj, msg);
5444
5416
  };
5445
5417
  console.error = (...arg) => {
5446
5418
  const [obj, msg] = getLogParams2(arg);
5447
- pinoInstance == null ? void 0 : pinoInstance.error(obj, msg);
5419
+ pinoInstance?.error(obj, msg);
5448
5420
  };
5449
5421
  console.trace = (...arg) => {
5450
5422
  const [obj, msg] = getLogParams2(arg);
5451
5423
  if (!obj.err) {
5452
5424
  obj.err = new Error();
5453
5425
  }
5454
- pinoInstance == null ? void 0 : pinoInstance.trace(obj, msg);
5426
+ pinoInstance?.trace(obj, msg);
5455
5427
  };
5456
5428
  console.debug = (...arg) => {
5457
5429
  const [obj, msg] = getLogParams2(arg);
5458
- pinoInstance == null ? void 0 : pinoInstance.debug(obj, msg);
5430
+ pinoInstance?.debug(obj, msg);
5459
5431
  };
5460
5432
  const getTenantId2 = () => {
5461
5433
  let tenantId;
@@ -5738,7 +5710,6 @@ var isUserInAppTenant = (appId, user) => {
5738
5710
  };
5739
5711
  var ALL_STRATEGIES = Object.values(TenantResolutionStrategy);
5740
5712
  var getTenantIDFromCtx = (ctx, opts) => {
5741
- var _a;
5742
5713
  if (!isMultiTenant()) {
5743
5714
  return DEFAULT_TENANT_ID;
5744
5715
  }
@@ -5752,16 +5723,15 @@ var getTenantIDFromCtx = (ctx, opts) => {
5752
5723
  opts.excludeStrategies = [];
5753
5724
  }
5754
5725
  const isAllowed = (strategy) => {
5755
- var _a2, _b;
5756
- if ((_a2 = opts.excludeStrategies) == null ? void 0 : _a2.includes(strategy)) {
5726
+ if (opts.excludeStrategies?.includes(strategy)) {
5757
5727
  return false;
5758
5728
  }
5759
- if ((_b = opts.includeStrategies) == null ? void 0 : _b.includes(strategy)) {
5729
+ if (opts.includeStrategies?.includes(strategy)) {
5760
5730
  return true;
5761
5731
  }
5762
5732
  };
5763
5733
  if (isAllowed("user" /* USER */)) {
5764
- const userTenantId = (_a = ctx.user) == null ? void 0 : _a.tenantId;
5734
+ const userTenantId = ctx.user?.tenantId;
5765
5735
  if (userTenantId) {
5766
5736
  return userTenantId;
5767
5737
  }
@@ -6329,7 +6299,7 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
6329
6299
  logWarn(`Ignoring redlock conflict in write-through cache`);
6330
6300
  }
6331
6301
  }
6332
- cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
6302
+ cacheItem = makeCacheItem(output, updateDb ? null : cacheItem?.lastWrite);
6333
6303
  if (output._id) {
6334
6304
  await cache.store(makeCacheKey(db, output._id), cacheItem);
6335
6305
  }
@@ -6421,7 +6391,6 @@ async function getSettingsConfig() {
6421
6391
  async function getPlatformUrl(opts = {
6422
6392
  tenantAware: true
6423
6393
  }) {
6424
- var _a;
6425
6394
  let platformUrl = environment_default.PLATFORM_URL || "http://localhost:10000";
6426
6395
  if (!environment_default.SELF_HOSTED && environment_default.MULTI_TENANCY && opts.tenantAware) {
6427
6396
  const tenantId = getTenantId();
@@ -6429,11 +6398,11 @@ async function getPlatformUrl(opts = {
6429
6398
  platformUrl = platformUrl.replace("://", `://${tenantId}.`);
6430
6399
  }
6431
6400
  } else if (environment_default.SELF_HOSTED) {
6432
- const config = (opts == null ? void 0 : opts.config) ? opts.config : (
6401
+ const config = opts?.config ? opts.config : (
6433
6402
  // direct to db to prevent infinite loop
6434
- (_a = await getConfig("settings" /* SETTINGS */)) == null ? void 0 : _a.config
6403
+ (await getConfig("settings" /* SETTINGS */))?.config
6435
6404
  );
6436
- if (config == null ? void 0 : config.platformUrl) {
6405
+ if (config?.platformUrl) {
6437
6406
  platformUrl = config.platformUrl;
6438
6407
  }
6439
6408
  }
@@ -6447,14 +6416,13 @@ var analyticsEnabled = async (opts) => {
6447
6416
  "analyticsEnabled" /* ANALYTICS_ENABLED */,
6448
6417
  86400 /* ONE_DAY */,
6449
6418
  async () => {
6450
- var _a;
6451
- const config = (opts == null ? void 0 : opts.config) ? opts.config : (
6419
+ const config = opts?.config ? opts.config : (
6452
6420
  // direct to db to prevent infinite loop
6453
- (_a = await getConfig("settings" /* SETTINGS */)) == null ? void 0 : _a.config
6421
+ (await getConfig("settings" /* SETTINGS */))?.config
6454
6422
  );
6455
- if ((config == null ? void 0 : config.analyticsEnabled) === false) {
6423
+ if (config?.analyticsEnabled === false) {
6456
6424
  return false;
6457
- } else if ((config == null ? void 0 : config.analyticsEnabled) === true) {
6425
+ } else if (config?.analyticsEnabled === true) {
6458
6426
  return true;
6459
6427
  }
6460
6428
  }
@@ -6474,7 +6442,7 @@ async function getGoogleConfigDoc() {
6474
6442
  }
6475
6443
  async function getGoogleConfig() {
6476
6444
  const config = await getGoogleConfigDoc();
6477
- return config == null ? void 0 : config.config;
6445
+ return config?.config;
6478
6446
  }
6479
6447
  async function getGoogleDatasourceConfig() {
6480
6448
  if (!environment_default.SELF_HOSTED) {
@@ -6502,13 +6470,11 @@ async function getOIDCConfigDoc() {
6502
6470
  return getConfig("oidc" /* OIDC */);
6503
6471
  }
6504
6472
  async function getOIDCConfig() {
6505
- var _a;
6506
- const config = (_a = await getOIDCConfigDoc()) == null ? void 0 : _a.config;
6507
- return (config == null ? void 0 : config.configs) && config.configs[0];
6473
+ const config = (await getOIDCConfigDoc())?.config;
6474
+ return config?.configs && config.configs[0];
6508
6475
  }
6509
6476
  async function getOIDCConfigById(configId) {
6510
- var _a;
6511
- const config = (_a = await getConfig("oidc" /* OIDC */)) == null ? void 0 : _a.config;
6477
+ const config = (await getConfig("oidc" /* OIDC */))?.config;
6512
6478
  return config && config.configs.filter((c) => c.uuid === configId)[0];
6513
6479
  }
6514
6480
  async function getSMTPConfigDoc() {
@@ -6535,7 +6501,7 @@ async function getSMTPConfig(isAutomation) {
6535
6501
  }
6536
6502
  async function getSCIMConfig() {
6537
6503
  const config = await getConfig("scim" /* SCIM */);
6538
- return config == null ? void 0 : config.config;
6504
+ return config?.config;
6539
6505
  }
6540
6506
 
6541
6507
  // src/events/index.ts
@@ -6950,7 +6916,7 @@ async function getAppIdFromCtx(ctx) {
6950
6916
  appId = confirmAppId(await resolveAppUrl(ctx));
6951
6917
  }
6952
6918
  const referer = ctx.request.headers.referer;
6953
- if (!appId && (referer == null ? void 0 : referer.includes(BUILDER_APP_PREFIX))) {
6919
+ if (!appId && referer?.includes(BUILDER_APP_PREFIX)) {
6954
6920
  const refererId = parseAppIdFromUrl(ctx.request.headers.referer);
6955
6921
  appId = confirmAppId(refererId);
6956
6922
  }
@@ -7169,7 +7135,6 @@ function handleStalled(queue, removeStalledCb) {
7169
7135
  });
7170
7136
  }
7171
7137
  function getLogParams(eventType, event, opts = {}, extra = {}) {
7172
- var _a, _b, _c;
7173
7138
  const message = `[BULL] ${eventType}=${event}`;
7174
7139
  const err = opts.error;
7175
7140
  const bullLog = {
@@ -7177,11 +7142,11 @@ function getLogParams(eventType, event, opts = {}, extra = {}) {
7177
7142
  eventType,
7178
7143
  event,
7179
7144
  job: opts.job,
7180
- jobId: opts.jobId || ((_a = opts.job) == null ? void 0 : _a.id),
7145
+ jobId: opts.jobId || opts.job?.id,
7181
7146
  ...extra
7182
7147
  };
7183
7148
  let automationLog;
7184
- if ((_c = (_b = opts.job) == null ? void 0 : _b.data) == null ? void 0 : _c.automation) {
7149
+ if (opts.job?.data?.automation) {
7185
7150
  automationLog = {
7186
7151
  _logKey: "automation",
7187
7152
  trigger: opts.job ? opts.job.data.automation.definition.trigger.event : void 0
@@ -7196,11 +7161,9 @@ var EventTypeMap = {
7196
7161
  ["systemEventQueue" /* SYSTEM_EVENT_QUEUE */]: "system-event" /* SYSTEM_EVENT */
7197
7162
  };
7198
7163
  function logging(queue, jobQueue) {
7199
- var _a;
7200
7164
  const eventType = EventTypeMap[jobQueue];
7201
7165
  function doInJobContext(job, task) {
7202
- var _a2;
7203
- const appId = (_a2 = job.data.event) == null ? void 0 : _a2.appId;
7166
+ const appId = job.data.event?.appId;
7204
7167
  if (appId) {
7205
7168
  return doInContext(appId, task);
7206
7169
  } else {
@@ -7214,7 +7177,7 @@ function logging(queue, jobQueue) {
7214
7177
  }).on("error" /* ERROR */, (error) => {
7215
7178
  console.error(...getLogParams(eventType, "error" /* ERROR */, { error }));
7216
7179
  });
7217
- if ((_a = process.env.NODE_DEBUG) == null ? void 0 : _a.includes("bull")) {
7180
+ if (process.env.NODE_DEBUG?.includes("bull")) {
7218
7181
  queue.on("waiting" /* WAITING */, (jobId) => {
7219
7182
  console.info(...getLogParams(eventType, "waiting" /* WAITING */, { jobId }));
7220
7183
  }).on("active" /* ACTIVE */, async (job, jobPromise) => {
@@ -7284,7 +7247,7 @@ function createQueue(jobQueue, opts = {}) {
7284
7247
  } else {
7285
7248
  queue = new inMemoryQueue_default(jobQueue, queueConfig);
7286
7249
  }
7287
- addListeners(queue, jobQueue, opts == null ? void 0 : opts.removeStalledCb);
7250
+ addListeners(queue, jobQueue, opts?.removeStalledCb);
7288
7251
  QUEUES.push(queue);
7289
7252
  if (!cleanupInterval && !environment_default.isTest()) {
7290
7253
  cleanupInterval = set(cleanup2, CLEANUP_PERIOD_MS);
@@ -7309,7 +7272,10 @@ async function shutdown2() {
7309
7272
 
7310
7273
  // src/events/processors/AuditLogsProcessor.ts
7311
7274
  init_environment2();
7312
- var _AuditLogsProcessor = class _AuditLogsProcessor {
7275
+ var AuditLogsProcessor = class _AuditLogsProcessor {
7276
+ static {
7277
+ this.auditLogsEnabled = false;
7278
+ }
7313
7279
  // can't use constructor as need to return promise
7314
7280
  static init(fn) {
7315
7281
  _AuditLogsProcessor.auditLogsEnabled = true;
@@ -7361,12 +7327,9 @@ var _AuditLogsProcessor = class _AuditLogsProcessor {
7361
7327
  async identifyGroup(group, timestamp) {
7362
7328
  }
7363
7329
  shutdown() {
7364
- var _a;
7365
- (_a = _AuditLogsProcessor.auditLogQueue) == null ? void 0 : _a.close();
7330
+ _AuditLogsProcessor.auditLogQueue?.close();
7366
7331
  }
7367
7332
  };
7368
- _AuditLogsProcessor.auditLogsEnabled = false;
7369
- var AuditLogsProcessor = _AuditLogsProcessor;
7370
7333
 
7371
7334
  // src/events/processors/Processors.ts
7372
7335
  var Processor = class {
@@ -7581,7 +7544,7 @@ var bulkGetGlobalUsersById = async (userIds, opts) => {
7581
7544
  keys: userIds,
7582
7545
  include_docs: true
7583
7546
  })).rows.map((row) => row.doc);
7584
- if (opts == null ? void 0 : opts.cleanup) {
7547
+ if (opts?.cleanup) {
7585
7548
  users = removeUserPassword(users);
7586
7549
  }
7587
7550
  return users;
@@ -7602,7 +7565,7 @@ var bulkUpdateGlobalUsers = async (users) => {
7602
7565
  async function getById(id, opts) {
7603
7566
  const db = getGlobalDB();
7604
7567
  let user = await db.get(id);
7605
- if (opts == null ? void 0 : opts.cleanup) {
7568
+ if (opts?.cleanup) {
7606
7569
  user = removeUserPassword(user);
7607
7570
  }
7608
7571
  return user;
@@ -7619,7 +7582,7 @@ var getGlobalUserByEmail = async (email, opts) => {
7619
7582
  throw new Error(`Multiple users found with email address: ${email}`);
7620
7583
  }
7621
7584
  let user = response;
7622
- if (opts == null ? void 0 : opts.cleanup) {
7585
+ if (opts?.cleanup) {
7623
7586
  user = removeUserPassword(user);
7624
7587
  }
7625
7588
  return user;
@@ -7637,7 +7600,7 @@ var searchGlobalUsersByApp = async (appId, opts, getOpts) => {
7637
7600
  response = [];
7638
7601
  }
7639
7602
  let users = Array.isArray(response) ? response : [response];
7640
- if (getOpts == null ? void 0 : getOpts.cleanup) {
7603
+ if (getOpts?.cleanup) {
7641
7604
  users = removeUserPassword(users);
7642
7605
  }
7643
7606
  return users;
@@ -7667,10 +7630,10 @@ var searchGlobalUsersByAppAccess = async (appId, opts) => {
7667
7630
  $regex: "^us_"
7668
7631
  }
7669
7632
  },
7670
- limit: (opts == null ? void 0 : opts.limit) || 50
7633
+ limit: opts?.limit || 50
7671
7634
  };
7672
7635
  const resp = await directCouchFind(getGlobalDBName(), searchOptions);
7673
- return resp == null ? void 0 : resp.rows;
7636
+ return resp?.rows;
7674
7637
  };
7675
7638
  var getGlobalUserByAppPage = (appId, user) => {
7676
7639
  if (!user) {
@@ -7693,7 +7656,7 @@ var searchGlobalUsersByEmail = async (email, opts, getOpts) => {
7693
7656
  response = [];
7694
7657
  }
7695
7658
  let users = Array.isArray(response) ? response : [response];
7696
- if (getOpts == null ? void 0 : getOpts.cleanup) {
7659
+ if (getOpts?.cleanup) {
7697
7660
  users = removeUserPassword(users);
7698
7661
  }
7699
7662
  return users;
@@ -8044,13 +8007,12 @@ __export(users_exports2, {
8044
8007
  isGlobalBuilder: () => isGlobalBuilder
8045
8008
  });
8046
8009
  function isBuilder(user, appId) {
8047
- var _a, _b, _c;
8048
8010
  if (!user) {
8049
8011
  return false;
8050
8012
  }
8051
- if ((_a = user.builder) == null ? void 0 : _a.global) {
8013
+ if (user.builder?.global) {
8052
8014
  return true;
8053
- } else if (appId && ((_c = (_b = user.builder) == null ? void 0 : _b.apps) == null ? void 0 : _c.includes(getProdAppID2(appId)))) {
8015
+ } else if (appId && user.builder?.apps?.includes(getProdAppID2(appId))) {
8054
8016
  return true;
8055
8017
  }
8056
8018
  return false;
@@ -8068,27 +8030,24 @@ function isAdminOrBuilder(user, appId) {
8068
8030
  return isBuilder(user, appId) || isAdmin(user);
8069
8031
  }
8070
8032
  function hasAppBuilderPermissions(user) {
8071
- var _a, _b, _c;
8072
8033
  if (!user) {
8073
8034
  return false;
8074
8035
  }
8075
- const appLength = (_b = (_a = user.builder) == null ? void 0 : _a.apps) == null ? void 0 : _b.length;
8076
- const isGlobalBuilder3 = !!((_c = user.builder) == null ? void 0 : _c.global);
8036
+ const appLength = user.builder?.apps?.length;
8037
+ const isGlobalBuilder3 = !!user.builder?.global;
8077
8038
  return !isGlobalBuilder3 && appLength != null && appLength > 0;
8078
8039
  }
8079
8040
  function hasBuilderPermissions(user) {
8080
- var _a;
8081
8041
  if (!user) {
8082
8042
  return false;
8083
8043
  }
8084
- return ((_a = user.builder) == null ? void 0 : _a.global) || hasAppBuilderPermissions(user);
8044
+ return user.builder?.global || hasAppBuilderPermissions(user);
8085
8045
  }
8086
8046
  function hasAdminPermissions(user) {
8087
- var _a;
8088
8047
  if (!user) {
8089
8048
  return false;
8090
8049
  }
8091
- return !!((_a = user.admin) == null ? void 0 : _a.global);
8050
+ return !!user.admin?.global;
8092
8051
  }
8093
8052
 
8094
8053
  // src/users/utils.ts
@@ -8161,7 +8120,7 @@ var unassignAppRoleEvents = async (user, roles, existingRoles) => {
8161
8120
  };
8162
8121
  var handleAppRoleEvents = async (user, existingUser) => {
8163
8122
  const roles = user.roles;
8164
- const existingRoles = existingUser == null ? void 0 : existingUser.roles;
8123
+ const existingRoles = existingUser?.roles;
8165
8124
  await assignAppRoleEvents(user, roles, existingRoles);
8166
8125
  await unassignAppRoleEvents(user, roles, existingRoles);
8167
8126
  };
@@ -8213,7 +8172,7 @@ var isRemovingAdmin = (user, existingUser) => {
8213
8172
  return isRemovingPermission(user, existingUser, hasAdminPermissions2);
8214
8173
  };
8215
8174
  var isOnboardingComplete = (user, existingUser) => {
8216
- return !(existingUser == null ? void 0 : existingUser.onboardedAt) && typeof user.onboardedAt === "string";
8175
+ return !existingUser?.onboardedAt && typeof user.onboardedAt === "string";
8217
8176
  };
8218
8177
  var isAddingPermission = (user, existingUser, hasPermission) => {
8219
8178
  if (!hasPermission(user)) {
@@ -8270,7 +8229,7 @@ async function getSessionsForUser(userId) {
8270
8229
  }
8271
8230
  async function invalidateSessions(userId, opts = {}) {
8272
8231
  try {
8273
- const reason = (opts == null ? void 0 : opts.reason) || "unknown";
8232
+ const reason = opts?.reason || "unknown";
8274
8233
  let sessionIds = opts.sessionIds || [];
8275
8234
  let sessionKeys;
8276
8235
  if (sessionIds.length === 0) {
@@ -8447,7 +8406,6 @@ var UserDB = class _UserDB {
8447
8406
  return user;
8448
8407
  }
8449
8408
  static async save(user, opts = {}) {
8450
- var _a, _b;
8451
8409
  if (opts.hashPassword == null) {
8452
8410
  opts.hashPassword = true;
8453
8411
  }
@@ -8460,7 +8418,7 @@ var UserDB = class _UserDB {
8460
8418
  if (!email && !_id) {
8461
8419
  throw new Error("_id or email is required");
8462
8420
  }
8463
- if (((_b = (_a = user.builder) == null ? void 0 : _a.apps) == null ? void 0 : _b.length) && !await _UserDB.features.isAppBuildersEnabled()) {
8421
+ if (user.builder?.apps?.length && !await _UserDB.features.isAppBuildersEnabled()) {
8464
8422
  throw new Error("Unable to update app builders, please check license");
8465
8423
  }
8466
8424
  let dbUser;
@@ -8488,10 +8446,10 @@ var UserDB = class _UserDB {
8488
8446
  return _UserDB.quotas.addUsers(change, async () => {
8489
8447
  await validateUniqueUser(email, tenantId);
8490
8448
  let builtUser = await _UserDB.buildUser(user, opts, tenantId, dbUser);
8491
- if (opts.currentUserId && opts.currentUserId === (dbUser == null ? void 0 : dbUser._id)) {
8449
+ if (opts.currentUserId && opts.currentUserId === dbUser?._id) {
8492
8450
  builtUser = cleanseUserObject(builtUser, dbUser);
8493
8451
  }
8494
- if (!dbUser && (roles == null ? void 0 : roles.length)) {
8452
+ if (!dbUser && roles?.length) {
8495
8453
  builtUser.roles = { ...roles };
8496
8454
  }
8497
8455
  let groupPromises = [];
@@ -8770,8 +8728,8 @@ var identifyUser = async (user, account, timestamp) => {
8770
8728
  if (isSSOUser(user)) {
8771
8729
  providerType = user.providerType;
8772
8730
  }
8773
- const accountHolder = (account == null ? void 0 : account.budibaseUserId) === user._id || false;
8774
- const verified2 = account && (account == null ? void 0 : account.budibaseUserId) === user._id ? account.verified : false;
8731
+ const accountHolder = account?.budibaseUserId === user._id || false;
8732
+ const verified2 = account && account?.budibaseUserId === user._id ? account.verified : false;
8775
8733
  const installationId = await getInstallationId();
8776
8734
  const hosting = account ? account.hosting : getHostingFromEnv();
8777
8735
  const environment2 = getDeploymentEnvironment();
@@ -8930,7 +8888,7 @@ var clearEvents = async () => {
8930
8888
  };
8931
8889
  var isBackfillingEvent = async (event) => {
8932
8890
  const backfill = await getBackfillMetadata();
8933
- const events2 = backfill == null ? void 0 : backfill.eventWhitelist;
8891
+ const events2 = backfill?.eventWhitelist;
8934
8892
  if (events2 && events2.includes(event)) {
8935
8893
  return true;
8936
8894
  } else {
@@ -9274,12 +9232,11 @@ var auth_default = {
9274
9232
  // src/events/publishers/automation.ts
9275
9233
  init_src();
9276
9234
  async function created3(automation, timestamp) {
9277
- var _a, _b, _c, _d;
9278
9235
  const properties = {
9279
9236
  appId: automation.appId,
9280
9237
  automationId: automation._id,
9281
- triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9282
- triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId,
9238
+ triggerId: automation.definition?.trigger?.id,
9239
+ triggerType: automation.definition?.trigger?.stepId,
9283
9240
  audited: {
9284
9241
  name: automation.name
9285
9242
  }
@@ -9287,22 +9244,20 @@ async function created3(automation, timestamp) {
9287
9244
  await publishEvent("automation:created" /* AUTOMATION_CREATED */, properties, timestamp);
9288
9245
  }
9289
9246
  async function triggerUpdated(automation) {
9290
- var _a, _b, _c, _d;
9291
9247
  const properties = {
9292
9248
  appId: automation.appId,
9293
9249
  automationId: automation._id,
9294
- triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9295
- triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId
9250
+ triggerId: automation.definition?.trigger?.id,
9251
+ triggerType: automation.definition?.trigger?.stepId
9296
9252
  };
9297
9253
  await publishEvent("automation:trigger:updated" /* AUTOMATION_TRIGGER_UPDATED */, properties);
9298
9254
  }
9299
9255
  async function deleted3(automation) {
9300
- var _a, _b, _c, _d;
9301
9256
  const properties = {
9302
9257
  appId: automation.appId,
9303
9258
  automationId: automation._id,
9304
- triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9305
- triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId,
9259
+ triggerId: automation.definition?.trigger?.id,
9260
+ triggerType: automation.definition?.trigger?.stepId,
9306
9261
  audited: {
9307
9262
  name: automation.name
9308
9263
  }
@@ -9310,12 +9265,11 @@ async function deleted3(automation) {
9310
9265
  await publishEvent("automation:deleted" /* AUTOMATION_DELETED */, properties);
9311
9266
  }
9312
9267
  async function tested(automation) {
9313
- var _a, _b, _c, _d;
9314
9268
  const properties = {
9315
9269
  appId: automation.appId,
9316
9270
  automationId: automation._id,
9317
- triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9318
- triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId
9271
+ triggerId: automation.definition?.trigger?.id,
9272
+ triggerType: automation.definition?.trigger?.stepId
9319
9273
  };
9320
9274
  await publishEvent("automation:tested" /* AUTOMATION_TESTED */, properties);
9321
9275
  }
@@ -9326,12 +9280,11 @@ var run = async (count, timestamp) => {
9326
9280
  await publishEvent("automations:run" /* AUTOMATIONS_RUN */, properties, timestamp);
9327
9281
  };
9328
9282
  async function stepCreated(automation, step, timestamp) {
9329
- var _a, _b, _c, _d;
9330
9283
  const properties = {
9331
9284
  appId: automation.appId,
9332
9285
  automationId: automation._id,
9333
- triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9334
- triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId,
9286
+ triggerId: automation.definition?.trigger?.id,
9287
+ triggerType: automation.definition?.trigger?.stepId,
9335
9288
  stepId: step.id,
9336
9289
  stepType: step.stepId,
9337
9290
  audited: {
@@ -9341,12 +9294,11 @@ async function stepCreated(automation, step, timestamp) {
9341
9294
  await publishEvent("automation:step:created" /* AUTOMATION_STEP_CREATED */, properties, timestamp);
9342
9295
  }
9343
9296
  async function stepDeleted(automation, step) {
9344
- var _a, _b, _c, _d;
9345
9297
  const properties = {
9346
9298
  appId: automation.appId,
9347
9299
  automationId: automation._id,
9348
- triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9349
- triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId,
9300
+ triggerId: automation.definition?.trigger?.id,
9301
+ triggerType: automation.definition?.trigger?.stepId,
9350
9302
  stepId: step.id,
9351
9303
  stepType: step.stepId,
9352
9304
  audited: {
@@ -9633,25 +9585,23 @@ var role_default = {
9633
9585
  // src/events/publishers/screen.ts
9634
9586
  init_src();
9635
9587
  async function created8(screen, timestamp) {
9636
- var _a;
9637
9588
  const properties = {
9638
9589
  layoutId: screen.layoutId,
9639
9590
  screenId: screen._id,
9640
9591
  roleId: screen.routing.roleId,
9641
9592
  audited: {
9642
- name: (_a = screen.routing) == null ? void 0 : _a.route
9593
+ name: screen.routing?.route
9643
9594
  }
9644
9595
  };
9645
9596
  await publishEvent("screen:created" /* SCREEN_CREATED */, properties, timestamp);
9646
9597
  }
9647
9598
  async function deleted8(screen) {
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:deleted" /* SCREEN_DELETED */, properties);
@@ -10722,7 +10672,7 @@ var BUILTIN_ROLE_NAME_ARRAY = Object.values(BUILTIN_ROLES).map(
10722
10672
  (role) => role.name
10723
10673
  );
10724
10674
  function isBuiltin(role) {
10725
- return BUILTIN_ROLE_ID_ARRAY.some((builtin) => role == null ? void 0 : role.includes(builtin));
10675
+ return BUILTIN_ROLE_ID_ARRAY.some((builtin) => role?.includes(builtin));
10726
10676
  }
10727
10677
  function builtinRoleToNumber(id) {
10728
10678
  if (!id) {
@@ -10749,7 +10699,7 @@ async function roleToNumber(id) {
10749
10699
  }
10750
10700
  const hierarchy = await getUserRoleHierarchy(id);
10751
10701
  for (let role of hierarchy) {
10752
- if (isBuiltin(role == null ? void 0 : role.inherits)) {
10702
+ if (isBuiltin(role?.inherits)) {
10753
10703
  return builtinRoleToNumber(role.inherits) + 1;
10754
10704
  }
10755
10705
  }
@@ -10782,7 +10732,7 @@ async function getRole(roleId, opts) {
10782
10732
  role = Object.assign(role, dbRole);
10783
10733
  role._id = getExternalRoleID(role._id, role.version);
10784
10734
  } catch (err) {
10785
- if (!isBuiltin(roleId) && (opts == null ? void 0 : opts.defaultPublic)) {
10735
+ if (!isBuiltin(roleId) && opts?.defaultPublic) {
10786
10736
  return (0, import_cloneDeep2.default)(BUILTIN_ROLES.PUBLIC);
10787
10737
  }
10788
10738
  if (Object.keys(role).length === 0) {
@@ -10905,7 +10855,7 @@ var AccessController = class {
10905
10855
  });
10906
10856
  this.userHierarchies[userRoleId] = roleIds;
10907
10857
  }
10908
- return (roleIds == null ? void 0 : roleIds.indexOf(tryingRoleId)) !== -1;
10858
+ return roleIds?.indexOf(tryingRoleId) !== -1;
10909
10859
  }
10910
10860
  async checkScreensAccess(screens, userRoleId) {
10911
10861
  let accessibleScreens = [];
@@ -10926,7 +10876,7 @@ var AccessController = class {
10926
10876
  }
10927
10877
  };
10928
10878
  function getDBRoleID(roleName) {
10929
- if (roleName == null ? void 0 : roleName.startsWith("role" /* ROLE */)) {
10879
+ if (roleName?.startsWith("role" /* ROLE */)) {
10930
10880
  return roleName;
10931
10881
  }
10932
10882
  return prefixRoleID(roleName);
@@ -11185,8 +11135,7 @@ async function authenticate2(details, requireLocalAccount = true, done, saveUser
11185
11135
  return done(null, ssoUser);
11186
11136
  }
11187
11137
  async function getProfilePictureUrl(user, details) {
11188
- var _a;
11189
- const pictureUrl = (_a = details.profile) == null ? void 0 : _a._json.picture;
11138
+ const pictureUrl = details.profile?._json.picture;
11190
11139
  if (pictureUrl) {
11191
11140
  const response = await (0, import_node_fetch5.default)(pictureUrl);
11192
11141
  if (response.status === 200) {
@@ -11717,7 +11666,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
11717
11666
  user = await getUser(userId, session.tenantId);
11718
11667
  }
11719
11668
  user.csrfToken = session.csrfToken;
11720
- if ((session == null ? void 0 : session.lastAccessedAt) < timeMinusOneMinute()) {
11669
+ if (session?.lastAccessedAt < timeMinusOneMinute()) {
11721
11670
  await updateSessionTTL(session);
11722
11671
  }
11723
11672
  authenticated = true;
@@ -11759,9 +11708,9 @@ function authenticated_default(noAuthPatterns = [], opts = {
11759
11708
  } catch (err) {
11760
11709
  console.error(`Auth Error: ${err.message}`);
11761
11710
  console.error(err);
11762
- if ((err == null ? void 0 : err.name) === "JsonWebTokenError") {
11711
+ if (err?.name === "JsonWebTokenError") {
11763
11712
  clearCookie(ctx, "budibase:auth" /* Auth */);
11764
- } else if ((err == null ? void 0 : err.code) === "invalid_api_key" /* INVALID_API_KEY */) {
11713
+ } else if (err?.code === "invalid_api_key" /* INVALID_API_KEY */) {
11765
11714
  ctx.throw(403, err.message);
11766
11715
  }
11767
11716
  if (opts && opts.publicAllowed || publicEndpoint) {
@@ -11828,7 +11777,6 @@ var INCLUDED_CONTENT_TYPES = [
11828
11777
  function csrf_default(opts = { noCsrfPatterns: [] }) {
11829
11778
  const noCsrfOptions = buildMatcherRegex(opts.noCsrfPatterns);
11830
11779
  return async (ctx, next) => {
11831
- var _a;
11832
11780
  const found = matches(ctx, noCsrfOptions);
11833
11781
  if (found) {
11834
11782
  return next();
@@ -11843,7 +11791,7 @@ function csrf_default(opts = { noCsrfPatterns: [] }) {
11843
11791
  if (ctx.internal) {
11844
11792
  return next();
11845
11793
  }
11846
- const userToken = (_a = ctx.user) == null ? void 0 : _a.csrfToken;
11794
+ const userToken = ctx.user?.csrfToken;
11847
11795
  if (!userToken) {
11848
11796
  return next();
11849
11797
  }
@@ -11903,10 +11851,7 @@ function pinoSettings() {
11903
11851
  logger,
11904
11852
  genReqId: correlator2.getId,
11905
11853
  autoLogging: {
11906
- ignore: (req) => {
11907
- var _a;
11908
- return !!((_a = req.url) == null ? void 0 : _a.includes("/health"));
11909
- }
11854
+ ignore: (req) => !!req.url?.includes("/health")
11910
11855
  },
11911
11856
  serializers: {
11912
11857
  req: (req) => {
@@ -11977,8 +11922,7 @@ var errorHandling_default = errorHandling;
11977
11922
 
11978
11923
  // src/middleware/querystringToBody.ts
11979
11924
  function querystringToBody_default(ctx, next) {
11980
- var _a;
11981
- const queryString = (_a = ctx.request.query) == null ? void 0 : _a.query;
11925
+ const queryString = ctx.request.query?.query;
11982
11926
  if (ctx.request.method.toLowerCase() !== "get") {
11983
11927
  ctx.throw(
11984
11928
  500,
@@ -12008,12 +11952,11 @@ __export(joi_validator_exports, {
12008
11952
  var import_joi = __toESM(require("joi"));
12009
11953
  function validate(schema, property) {
12010
11954
  return (ctx, next) => {
12011
- var _a;
12012
11955
  if (!schema) {
12013
11956
  return next();
12014
11957
  }
12015
11958
  let params2 = null;
12016
- let reqProp = (_a = ctx.request) == null ? void 0 : _a[property];
11959
+ let reqProp = ctx.request?.[property];
12017
11960
  if (ctx[property] != null) {
12018
11961
  params2 = ctx[property];
12019
11962
  } else if (reqProp != null) {
@@ -12152,7 +12095,6 @@ async function updateUserOAuth(userId, oAuthConfig) {
12152
12095
  }
12153
12096
  }
12154
12097
  async function platformLogout(opts) {
12155
- var _a;
12156
12098
  const ctx = opts.ctx;
12157
12099
  const userId = opts.userId;
12158
12100
  const keepActiveSession = opts.keepActiveSession;
@@ -12169,7 +12111,7 @@ async function platformLogout(opts) {
12169
12111
  }
12170
12112
  const sessionIds = sessions.map(({ sessionId }) => sessionId);
12171
12113
  await invalidateSessions(userId, { sessionIds, reason: "logout" });
12172
- await auth_default.logout((_a = ctx.user) == null ? void 0 : _a.email);
12114
+ await auth_default.logout(ctx.user?.email);
12173
12115
  await invalidateUser(userId);
12174
12116
  }
12175
12117
 
@@ -12285,7 +12227,7 @@ function validateAutomation(schema) {
12285
12227
  runJoi(validator, schema);
12286
12228
  }
12287
12229
  function validate2(schema) {
12288
- switch (schema == null ? void 0 : schema.type) {
12230
+ switch (schema?.type) {
12289
12231
  case "component" /* COMPONENT */:
12290
12232
  validateComponent(schema);
12291
12233
  break;
@@ -12349,7 +12291,7 @@ async function lookup(address) {
12349
12291
  }
12350
12292
  async function refreshBlacklist() {
12351
12293
  const blacklist = environment_default.BLACKLIST_IPS;
12352
- const list = (blacklist == null ? void 0 : blacklist.split(",")) || [];
12294
+ const list = blacklist?.split(",") || [];
12353
12295
  let final = [];
12354
12296
  for (let addr of list) {
12355
12297
  const trimmed = addr.trim();
@@ -12366,7 +12308,7 @@ async function isBlacklisted(address) {
12366
12308
  if (!blackListArray) {
12367
12309
  await refreshBlacklist();
12368
12310
  }
12369
- if ((blackListArray == null ? void 0 : blackListArray.length) === 0) {
12311
+ if (blackListArray?.length === 0) {
12370
12312
  return false;
12371
12313
  }
12372
12314
  let ips;
@@ -12375,7 +12317,7 @@ async function isBlacklisted(address) {
12375
12317
  } else {
12376
12318
  ips = [address];
12377
12319
  }
12378
- return !!(blackListArray == null ? void 0 : blackListArray.find((addr) => ips.includes(addr)));
12320
+ return !!blackListArray?.find((addr) => ips.includes(addr));
12379
12321
  }
12380
12322
 
12381
12323
  // src/docUpdates/index.ts