@budibase/backend-core 2.9.21-alpha.1 → 2.9.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -29,6 +29,28 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
29
29
  mod
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+ var __accessCheck = (obj, member, msg) => {
33
+ if (!member.has(obj))
34
+ throw TypeError("Cannot " + msg);
35
+ };
36
+ var __privateGet = (obj, member, getter) => {
37
+ __accessCheck(obj, member, "read from private field");
38
+ return getter ? getter.call(obj) : member.get(obj);
39
+ };
40
+ var __privateAdd = (obj, member, value) => {
41
+ if (member.has(obj))
42
+ throw TypeError("Cannot add the same private member more than once");
43
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
44
+ };
45
+ var __privateSet = (obj, member, value, setter) => {
46
+ __accessCheck(obj, member, "write to private field");
47
+ setter ? setter.call(obj, value) : member.set(obj, value);
48
+ return value;
49
+ };
50
+ var __privateMethod = (obj, member, method) => {
51
+ __accessCheck(obj, member, "access private method");
52
+ return method;
53
+ };
32
54
 
33
55
  // ../types/src/sdk/automations/index.ts
34
56
  var init_automations = __esm({
@@ -690,13 +712,6 @@ var init_permissions = __esm({
690
712
  }
691
713
  });
692
714
 
693
- // ../types/src/sdk/row.ts
694
- var init_row = __esm({
695
- "../types/src/sdk/row.ts"() {
696
- "use strict";
697
- }
698
- });
699
-
700
715
  // ../types/src/sdk/index.ts
701
716
  var init_sdk = __esm({
702
717
  "../types/src/sdk/index.ts"() {
@@ -722,7 +737,6 @@ var init_sdk = __esm({
722
737
  init_cli();
723
738
  init_websocket();
724
739
  init_permissions();
725
- init_row();
726
740
  }
727
741
  });
728
742
 
@@ -952,7 +966,7 @@ var init_document = __esm({
952
966
  });
953
967
 
954
968
  // ../types/src/documents/app/row.ts
955
- var init_row2 = __esm({
969
+ var init_row = __esm({
956
970
  "../types/src/documents/app/row.ts"() {
957
971
  "use strict";
958
972
  }
@@ -1007,7 +1021,7 @@ var init_app3 = __esm({
1007
1021
  init_screen2();
1008
1022
  init_view2();
1009
1023
  init_document();
1010
- init_row2();
1024
+ init_row();
1011
1025
  init_user4();
1012
1026
  init_backup2();
1013
1027
  init_webhook();
@@ -1287,7 +1301,7 @@ var init_datasource3 = __esm({
1287
1301
  });
1288
1302
 
1289
1303
  // ../types/src/api/web/app/row.ts
1290
- var init_row3 = __esm({
1304
+ var init_row2 = __esm({
1291
1305
  "../types/src/api/web/app/row.ts"() {
1292
1306
  "use strict";
1293
1307
  }
@@ -1320,7 +1334,7 @@ var init_app4 = __esm({
1320
1334
  "use strict";
1321
1335
  init_backup3();
1322
1336
  init_datasource3();
1323
- init_row3();
1337
+ init_row2();
1324
1338
  init_view3();
1325
1339
  init_rows2();
1326
1340
  init_table4();
@@ -1413,13 +1427,6 @@ var init_pagination = __esm({
1413
1427
  }
1414
1428
  });
1415
1429
 
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
-
1423
1430
  // ../types/src/api/web/index.ts
1424
1431
  var init_web = __esm({
1425
1432
  "../types/src/api/web/index.ts"() {
@@ -1434,7 +1441,6 @@ var init_web = __esm({
1434
1441
  init_app4();
1435
1442
  init_global2();
1436
1443
  init_pagination();
1437
- init_searchFilter();
1438
1444
  }
1439
1445
  });
1440
1446
 
@@ -1866,15 +1872,12 @@ var init_environment2 = __esm({
1866
1872
  });
1867
1873
 
1868
1874
  // src/context/Context.ts
1869
- var import_async_hooks, Context;
1875
+ var import_async_hooks, _Context, Context;
1870
1876
  var init_Context = __esm({
1871
1877
  "src/context/Context.ts"() {
1872
1878
  "use strict";
1873
1879
  import_async_hooks = require("async_hooks");
1874
- Context = class _Context {
1875
- static {
1876
- this.storage = new import_async_hooks.AsyncLocalStorage();
1877
- }
1880
+ _Context = class _Context {
1878
1881
  static run(context, func) {
1879
1882
  return _Context.storage.run(context, () => func());
1880
1883
  }
@@ -1882,6 +1885,8 @@ var init_Context = __esm({
1882
1885
  return _Context.storage.getStore();
1883
1886
  }
1884
1887
  };
1888
+ _Context.storage = new import_async_hooks.AsyncLocalStorage();
1889
+ Context = _Context;
1885
1890
  }
1886
1891
  });
1887
1892
 
@@ -1923,7 +1928,7 @@ function getProdAppID(appId) {
1923
1928
  return `${APP_PREFIX}${rest}`;
1924
1929
  }
1925
1930
  function extractAppUUID(id) {
1926
- const split = id?.split("_") || [];
1931
+ const split = (id == null ? void 0 : id.split("_")) || [];
1927
1932
  return split.length ? split[split.length - 1] : null;
1928
1933
  }
1929
1934
  var NO_APP_ERROR, getDevAppID;
@@ -1943,17 +1948,18 @@ var init_connections = __esm({
1943
1948
  "use strict";
1944
1949
  init_environment2();
1945
1950
  getCouchInfo = (connection) => {
1951
+ var _a, _b;
1946
1952
  const urlInfo = getUrlInfo(connection);
1947
1953
  let username;
1948
1954
  let password;
1949
- if (urlInfo.auth?.username) {
1955
+ if ((_a = urlInfo.auth) == null ? void 0 : _a.username) {
1950
1956
  username = urlInfo.auth.username;
1951
1957
  } else if (environment_default.COUCH_DB_USERNAME) {
1952
1958
  username = environment_default.COUCH_DB_USERNAME;
1953
1959
  } else if (!environment_default.isTest()) {
1954
1960
  throw new Error("CouchDB username not set");
1955
1961
  }
1956
- if (urlInfo.auth?.password) {
1962
+ if ((_b = urlInfo.auth) == null ? void 0 : _b.password) {
1957
1963
  password = urlInfo.auth.password;
1958
1964
  } else if (environment_default.COUCH_DB_PASSWORD) {
1959
1965
  password = environment_default.COUCH_DB_PASSWORD;
@@ -2212,7 +2218,8 @@ var init_DatabaseImpl = __esm({
2212
2218
  return this.instanceNano || _DatabaseImpl.nano;
2213
2219
  }
2214
2220
  async checkSetup() {
2215
- let shouldCreate = !this.pouchOpts?.skip_setup;
2221
+ var _a;
2222
+ let shouldCreate = !((_a = this.pouchOpts) == null ? void 0 : _a.skip_setup);
2216
2223
  let exists2 = await this.exists();
2217
2224
  if (!shouldCreate && !exists2) {
2218
2225
  throw new Error("DB does not exist");
@@ -2245,6 +2252,18 @@ var init_DatabaseImpl = __esm({
2245
2252
  }
2246
2253
  return this.updateOutput(() => db.get(id));
2247
2254
  }
2255
+ async docExists(docId) {
2256
+ const db = await this.checkSetup();
2257
+ let _rev, exists2;
2258
+ try {
2259
+ const { etag } = await db.head(docId);
2260
+ _rev = etag;
2261
+ exists2 = true;
2262
+ } catch (err) {
2263
+ exists2 = false;
2264
+ }
2265
+ return { _rev, exists: exists2 };
2266
+ }
2248
2267
  async remove(idOrDoc, rev) {
2249
2268
  const db = await this.checkSetup();
2250
2269
  let _id;
@@ -2276,7 +2295,7 @@ var init_DatabaseImpl = __esm({
2276
2295
  document.createdAt = (/* @__PURE__ */ new Date()).toISOString();
2277
2296
  }
2278
2297
  document.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
2279
- if (opts?.force && document._id) {
2298
+ if ((opts == null ? void 0 : opts.force) && document._id) {
2280
2299
  try {
2281
2300
  const existing = await this.get(document._id);
2282
2301
  if (existing) {
@@ -2440,7 +2459,7 @@ function isMultiTenant() {
2440
2459
  }
2441
2460
  function isTenantIdSet() {
2442
2461
  const context = Context.get();
2443
- return !!context?.tenantId;
2462
+ return !!(context == null ? void 0 : context.tenantId);
2444
2463
  }
2445
2464
  function isTenancyEnabled() {
2446
2465
  return environment_default.MULTI_TENANCY;
@@ -2539,7 +2558,7 @@ async function doInIdentityContext(identity, task) {
2539
2558
  function getIdentity() {
2540
2559
  try {
2541
2560
  const context = Context.get();
2542
- return context?.identity;
2561
+ return context == null ? void 0 : context.identity;
2543
2562
  } catch (e) {
2544
2563
  }
2545
2564
  }
@@ -2548,7 +2567,7 @@ function getTenantId() {
2548
2567
  return DEFAULT_TENANT_ID;
2549
2568
  }
2550
2569
  const context = Context.get();
2551
- const tenantId = context?.tenantId;
2570
+ const tenantId = context == null ? void 0 : context.tenantId;
2552
2571
  if (!tenantId) {
2553
2572
  throw new Error("Tenant id not found");
2554
2573
  }
@@ -2556,11 +2575,11 @@ function getTenantId() {
2556
2575
  }
2557
2576
  function getAutomationId() {
2558
2577
  const context = Context.get();
2559
- return context?.automationId;
2578
+ return context == null ? void 0 : context.automationId;
2560
2579
  }
2561
2580
  function getAppId() {
2562
2581
  const context = Context.get();
2563
- const foundId = context?.appId;
2582
+ const foundId = context == null ? void 0 : context.appId;
2564
2583
  if (!foundId && environment_default.isTest() && TEST_APP_ID) {
2565
2584
  return TEST_APP_ID;
2566
2585
  } else {
@@ -2595,7 +2614,7 @@ function getGlobalDB() {
2595
2614
  if (!context || environment_default.MULTI_TENANCY && !context.tenantId) {
2596
2615
  throw new Error("Global DB not found");
2597
2616
  }
2598
- return getDB(baseGlobalDBName(context?.tenantId));
2617
+ return getDB(baseGlobalDBName(context == null ? void 0 : context.tenantId));
2599
2618
  }
2600
2619
  function getAuditLogsDB() {
2601
2620
  if (!getTenantId()) {
@@ -2623,7 +2642,7 @@ function getDevAppDB(opts) {
2623
2642
  }
2624
2643
  function isScim() {
2625
2644
  const context = Context.get();
2626
- const scimCall = context?.isScim;
2645
+ const scimCall = context == null ? void 0 : context.isScim;
2627
2646
  return !!scimCall;
2628
2647
  }
2629
2648
  var TEST_APP_ID, getProdAppId;
@@ -3474,7 +3493,7 @@ function getGlobalUserParams(globalId, otherProps = {}) {
3474
3493
  if (!globalId) {
3475
3494
  globalId = "";
3476
3495
  }
3477
- const startkey = otherProps?.startkey;
3496
+ const startkey = otherProps == null ? void 0 : otherProps.startkey;
3478
3497
  return {
3479
3498
  ...otherProps,
3480
3499
  // need to include this incase pagination
@@ -3607,7 +3626,10 @@ async function getAllApps({
3607
3626
  } else {
3608
3627
  const response = await Promise.allSettled(appPromises);
3609
3628
  const apps = response.filter(
3610
- (result) => result.status === "fulfilled" && result.value?.state !== "invalid" /* INVALID */
3629
+ (result) => {
3630
+ var _a;
3631
+ return result.status === "fulfilled" && ((_a = result.value) == null ? void 0 : _a.state) !== "invalid" /* INVALID */;
3632
+ }
3611
3633
  ).map(({ value }) => value);
3612
3634
  if (!all) {
3613
3635
  return apps.filter((app) => {
@@ -3669,7 +3691,7 @@ function pagination(data, pageSize, {
3669
3691
  const hasNextPage = data.length > pageSize;
3670
3692
  let nextPage = void 0;
3671
3693
  if (!getKey) {
3672
- getKey = (doc) => property ? doc?.[property] : doc?._id;
3694
+ getKey = (doc) => property ? doc == null ? void 0 : doc[property] : doc == null ? void 0 : doc._id;
3673
3695
  }
3674
3696
  if (hasNextPage) {
3675
3697
  nextPage = getKey(data[pageSize]);
@@ -3820,7 +3842,7 @@ var init_views = __esm({
3820
3842
  const docs = rows.map(
3821
3843
  (row) => params2.include_docs ? row.doc : row.value
3822
3844
  );
3823
- if (opts?.arrayResponse) {
3845
+ if (opts == null ? void 0 : opts.arrayResponse) {
3824
3846
  return docs;
3825
3847
  } else {
3826
3848
  return docs.length <= 1 ? docs[0] : docs;
@@ -4043,34 +4065,38 @@ async function fullSearch(dbName, index2, query, params2) {
4043
4065
  const rows = await recursiveSearch(dbName, index2, query, params2);
4044
4066
  return { rows };
4045
4067
  }
4046
- var import_node_fetch2, QUERY_START_REGEX, QueryBuilder;
4068
+ var import_node_fetch2, QUERY_START_REGEX, _dbName, _index, _query, _limit, _sort, _bookmark, _sortOrder, _sortType, _includeDocs, _version, _indexBuilder, _noEscaping, _skip, _skipItems, skipItems_fn, _execute, execute_fn, _QueryBuilder, QueryBuilder;
4047
4069
  var init_lucene = __esm({
4048
4070
  "src/db/lucene.ts"() {
4049
4071
  "use strict";
4050
4072
  import_node_fetch2 = __toESM(require("node-fetch"));
4051
4073
  init_couch();
4052
4074
  QUERY_START_REGEX = /\d[0-9]*:/g;
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
- }
4075
+ _QueryBuilder = class _QueryBuilder {
4070
4076
  constructor(dbName, index2, base) {
4071
- this.#dbName = dbName;
4072
- this.#index = index2;
4073
- this.#query = {
4077
+ /**
4078
+ * Lucene queries do not support pagination and use bookmarks instead.
4079
+ * For the given builder, walk through pages using bookmarks until the desired
4080
+ * page has been met.
4081
+ */
4082
+ __privateAdd(this, _skipItems);
4083
+ __privateAdd(this, _execute);
4084
+ __privateAdd(this, _dbName, void 0);
4085
+ __privateAdd(this, _index, void 0);
4086
+ __privateAdd(this, _query, void 0);
4087
+ __privateAdd(this, _limit, void 0);
4088
+ __privateAdd(this, _sort, void 0);
4089
+ __privateAdd(this, _bookmark, void 0);
4090
+ __privateAdd(this, _sortOrder, void 0);
4091
+ __privateAdd(this, _sortType, void 0);
4092
+ __privateAdd(this, _includeDocs, void 0);
4093
+ __privateAdd(this, _version, void 0);
4094
+ __privateAdd(this, _indexBuilder, void 0);
4095
+ __privateAdd(this, _noEscaping, false);
4096
+ __privateAdd(this, _skip, void 0);
4097
+ __privateSet(this, _dbName, dbName);
4098
+ __privateSet(this, _index, index2);
4099
+ __privateSet(this, _query, {
4074
4100
  allOr: false,
4075
4101
  string: {},
4076
4102
  fuzzy: {},
@@ -4084,124 +4110,124 @@ var init_lucene = __esm({
4084
4110
  notContains: {},
4085
4111
  containsAny: {},
4086
4112
  ...base
4087
- };
4088
- this.#limit = 50;
4089
- this.#sortOrder = "ascending";
4090
- this.#sortType = "string";
4091
- this.#includeDocs = true;
4113
+ });
4114
+ __privateSet(this, _limit, 50);
4115
+ __privateSet(this, _sortOrder, "ascending");
4116
+ __privateSet(this, _sortType, "string");
4117
+ __privateSet(this, _includeDocs, true);
4092
4118
  }
4093
4119
  disableEscaping() {
4094
- this.#noEscaping = true;
4120
+ __privateSet(this, _noEscaping, true);
4095
4121
  return this;
4096
4122
  }
4097
4123
  setIndexBuilder(builderFn) {
4098
- this.#indexBuilder = builderFn;
4124
+ __privateSet(this, _indexBuilder, builderFn);
4099
4125
  return this;
4100
4126
  }
4101
4127
  setVersion(version) {
4102
4128
  if (version != null) {
4103
- this.#version = version;
4129
+ __privateSet(this, _version, version);
4104
4130
  }
4105
4131
  return this;
4106
4132
  }
4107
4133
  setTable(tableId) {
4108
- this.#query.equal.tableId = tableId;
4134
+ __privateGet(this, _query).equal.tableId = tableId;
4109
4135
  return this;
4110
4136
  }
4111
4137
  setLimit(limit) {
4112
4138
  if (limit != null) {
4113
- this.#limit = limit;
4139
+ __privateSet(this, _limit, limit);
4114
4140
  }
4115
4141
  return this;
4116
4142
  }
4117
4143
  setSort(sort) {
4118
4144
  if (sort != null) {
4119
- this.#sort = sort;
4145
+ __privateSet(this, _sort, sort);
4120
4146
  }
4121
4147
  return this;
4122
4148
  }
4123
4149
  setSortOrder(sortOrder) {
4124
4150
  if (sortOrder != null) {
4125
- this.#sortOrder = sortOrder;
4151
+ __privateSet(this, _sortOrder, sortOrder);
4126
4152
  }
4127
4153
  return this;
4128
4154
  }
4129
4155
  setSortType(sortType) {
4130
4156
  if (sortType != null) {
4131
- this.#sortType = sortType;
4157
+ __privateSet(this, _sortType, sortType);
4132
4158
  }
4133
4159
  return this;
4134
4160
  }
4135
4161
  setBookmark(bookmark) {
4136
4162
  if (bookmark != null) {
4137
- this.#bookmark = bookmark;
4163
+ __privateSet(this, _bookmark, bookmark);
4138
4164
  }
4139
4165
  return this;
4140
4166
  }
4141
4167
  setSkip(skip) {
4142
- this.#skip = skip;
4168
+ __privateSet(this, _skip, skip);
4143
4169
  return this;
4144
4170
  }
4145
4171
  excludeDocs() {
4146
- this.#includeDocs = false;
4172
+ __privateSet(this, _includeDocs, false);
4147
4173
  return this;
4148
4174
  }
4149
4175
  includeDocs() {
4150
- this.#includeDocs = true;
4176
+ __privateSet(this, _includeDocs, true);
4151
4177
  return this;
4152
4178
  }
4153
4179
  addString(key, partial) {
4154
- this.#query.string[key] = partial;
4180
+ __privateGet(this, _query).string[key] = partial;
4155
4181
  return this;
4156
4182
  }
4157
4183
  addFuzzy(key, fuzzy) {
4158
- this.#query.fuzzy[key] = fuzzy;
4184
+ __privateGet(this, _query).fuzzy[key] = fuzzy;
4159
4185
  return this;
4160
4186
  }
4161
4187
  addRange(key, low, high) {
4162
- this.#query.range[key] = {
4188
+ __privateGet(this, _query).range[key] = {
4163
4189
  low,
4164
4190
  high
4165
4191
  };
4166
4192
  return this;
4167
4193
  }
4168
4194
  addEqual(key, value) {
4169
- this.#query.equal[key] = value;
4195
+ __privateGet(this, _query).equal[key] = value;
4170
4196
  return this;
4171
4197
  }
4172
4198
  addNotEqual(key, value) {
4173
- this.#query.notEqual[key] = value;
4199
+ __privateGet(this, _query).notEqual[key] = value;
4174
4200
  return this;
4175
4201
  }
4176
4202
  addEmpty(key, value) {
4177
- this.#query.empty[key] = value;
4203
+ __privateGet(this, _query).empty[key] = value;
4178
4204
  return this;
4179
4205
  }
4180
4206
  addNotEmpty(key, value) {
4181
- this.#query.notEmpty[key] = value;
4207
+ __privateGet(this, _query).notEmpty[key] = value;
4182
4208
  return this;
4183
4209
  }
4184
4210
  addOneOf(key, value) {
4185
- this.#query.oneOf[key] = value;
4211
+ __privateGet(this, _query).oneOf[key] = value;
4186
4212
  return this;
4187
4213
  }
4188
4214
  addContains(key, value) {
4189
- this.#query.contains[key] = value;
4215
+ __privateGet(this, _query).contains[key] = value;
4190
4216
  return this;
4191
4217
  }
4192
4218
  addNotContains(key, value) {
4193
- this.#query.notContains[key] = value;
4219
+ __privateGet(this, _query).notContains[key] = value;
4194
4220
  return this;
4195
4221
  }
4196
4222
  addContainsAny(key, value) {
4197
- this.#query.containsAny[key] = value;
4223
+ __privateGet(this, _query).containsAny[key] = value;
4198
4224
  return this;
4199
4225
  }
4200
4226
  setAllOr() {
4201
- this.#query.allOr = true;
4227
+ __privateGet(this, _query).allOr = true;
4202
4228
  }
4203
4229
  handleSpaces(input) {
4204
- if (this.#noEscaping) {
4230
+ if (__privateGet(this, _noEscaping)) {
4205
4231
  return input;
4206
4232
  } else {
4207
4233
  return input.replace(/ /g, "_");
@@ -4215,12 +4241,12 @@ var init_lucene = __esm({
4215
4241
  * @returns {string|*}
4216
4242
  */
4217
4243
  preprocess(value, { escape, lowercase, wrap, type } = {}) {
4218
- const hasVersion = !!this.#version;
4244
+ const hasVersion = !!__privateGet(this, _version);
4219
4245
  const originalType = typeof value;
4220
4246
  if (value && lowercase) {
4221
4247
  value = value.toLowerCase ? value.toLowerCase() : value;
4222
4248
  }
4223
- if (!this.#noEscaping && escape && originalType === "string") {
4249
+ if (!__privateGet(this, _noEscaping) && escape && originalType === "string") {
4224
4250
  value = `${value}`.replace(/[ \/#+\-&|!(){}\]^"~*?:\\]/g, "\\$&");
4225
4251
  }
4226
4252
  if (originalType === "string" && !isNaN(value) && !type) {
@@ -4232,7 +4258,7 @@ var init_lucene = __esm({
4232
4258
  }
4233
4259
  isMultiCondition() {
4234
4260
  let count = 0;
4235
- for (let filters of Object.values(this.#query)) {
4261
+ for (let filters of Object.values(__privateGet(this, _query))) {
4236
4262
  if (typeof filters === "object") {
4237
4263
  count += Object.keys(filters).length;
4238
4264
  }
@@ -4258,13 +4284,13 @@ var init_lucene = __esm({
4258
4284
  }
4259
4285
  buildSearchQuery() {
4260
4286
  const builder = this;
4261
- let allOr = this.#query && this.#query.allOr;
4287
+ let allOr = __privateGet(this, _query) && __privateGet(this, _query).allOr;
4262
4288
  let query = allOr ? "" : "*:*";
4263
4289
  const allPreProcessingOpts = { escape: true, lowercase: true, wrap: true };
4264
4290
  let tableId;
4265
- if (this.#query.equal.tableId) {
4266
- tableId = this.#query.equal.tableId;
4267
- delete this.#query.equal.tableId;
4291
+ if (__privateGet(this, _query).equal.tableId) {
4292
+ tableId = __privateGet(this, _query).equal.tableId;
4293
+ delete __privateGet(this, _query).equal.tableId;
4268
4294
  }
4269
4295
  const equal = (key, value) => {
4270
4296
  if (!value && value !== 0) {
@@ -4338,19 +4364,19 @@ var init_lucene = __esm({
4338
4364
  continue;
4339
4365
  }
4340
4366
  if (built.length > 0 || query.length > 0) {
4341
- const mode = opts?.mode ? opts.mode : allOr ? "OR" : "AND";
4367
+ const mode = (opts == null ? void 0 : opts.mode) ? opts.mode : allOr ? "OR" : "AND";
4342
4368
  built += ` ${mode} `;
4343
4369
  }
4344
4370
  built += expression;
4345
4371
  }
4346
- if (opts?.returnBuilt) {
4372
+ if (opts == null ? void 0 : opts.returnBuilt) {
4347
4373
  return built;
4348
4374
  } else {
4349
4375
  query += built;
4350
4376
  }
4351
4377
  }
4352
- if (this.#query.string) {
4353
- build(this.#query.string, (key, value) => {
4378
+ if (__privateGet(this, _query).string) {
4379
+ build(__privateGet(this, _query).string, (key, value) => {
4354
4380
  if (!value) {
4355
4381
  return null;
4356
4382
  }
@@ -4362,8 +4388,8 @@ var init_lucene = __esm({
4362
4388
  return `${key}:${value}*`;
4363
4389
  });
4364
4390
  }
4365
- if (this.#query.range) {
4366
- build(this.#query.range, (key, value) => {
4391
+ if (__privateGet(this, _query).range) {
4392
+ build(__privateGet(this, _query).range, (key, value) => {
4367
4393
  if (!value) {
4368
4394
  return null;
4369
4395
  }
@@ -4378,14 +4404,14 @@ var init_lucene = __esm({
4378
4404
  return `${key}:[${low} TO ${high}]`;
4379
4405
  });
4380
4406
  }
4381
- if (this.#query.fuzzy) {
4382
- build(this.#query.fuzzy, fuzzy);
4407
+ if (__privateGet(this, _query).fuzzy) {
4408
+ build(__privateGet(this, _query).fuzzy, fuzzy);
4383
4409
  }
4384
- if (this.#query.equal) {
4385
- build(this.#query.equal, equal);
4410
+ if (__privateGet(this, _query).equal) {
4411
+ build(__privateGet(this, _query).equal, equal);
4386
4412
  }
4387
- if (this.#query.notEqual) {
4388
- build(this.#query.notEqual, (key, value) => {
4413
+ if (__privateGet(this, _query).notEqual) {
4414
+ build(__privateGet(this, _query).notEqual, (key, value) => {
4389
4415
  if (!value) {
4390
4416
  return null;
4391
4417
  }
@@ -4395,23 +4421,23 @@ var init_lucene = __esm({
4395
4421
  return `!${key}:${builder.preprocess(value, allPreProcessingOpts)}`;
4396
4422
  });
4397
4423
  }
4398
- if (this.#query.empty) {
4399
- build(this.#query.empty, (key) => `(*:* -${key}:["" TO *])`);
4424
+ if (__privateGet(this, _query).empty) {
4425
+ build(__privateGet(this, _query).empty, (key) => `(*:* -${key}:["" TO *])`);
4400
4426
  }
4401
- if (this.#query.notEmpty) {
4402
- build(this.#query.notEmpty, (key) => `${key}:["" TO *]`);
4427
+ if (__privateGet(this, _query).notEmpty) {
4428
+ build(__privateGet(this, _query).notEmpty, (key) => `${key}:["" TO *]`);
4403
4429
  }
4404
- if (this.#query.oneOf) {
4405
- build(this.#query.oneOf, oneOf);
4430
+ if (__privateGet(this, _query).oneOf) {
4431
+ build(__privateGet(this, _query).oneOf, oneOf);
4406
4432
  }
4407
- if (this.#query.contains) {
4408
- build(this.#query.contains, contains);
4433
+ if (__privateGet(this, _query).contains) {
4434
+ build(__privateGet(this, _query).contains, contains);
4409
4435
  }
4410
- if (this.#query.notContains) {
4411
- build(this.compressFilters(this.#query.notContains), notContains);
4436
+ if (__privateGet(this, _query).notContains) {
4437
+ build(this.compressFilters(__privateGet(this, _query).notContains), notContains);
4412
4438
  }
4413
- if (this.#query.containsAny) {
4414
- build(this.#query.containsAny, containsAny);
4439
+ if (__privateGet(this, _query).containsAny) {
4440
+ build(__privateGet(this, _query).containsAny, containsAny);
4415
4441
  }
4416
4442
  if (tableId) {
4417
4443
  query = this.isMultiCondition() ? `(${query})` : query;
@@ -4423,63 +4449,75 @@ var init_lucene = __esm({
4423
4449
  buildSearchBody() {
4424
4450
  let body2 = {
4425
4451
  q: this.buildSearchQuery(),
4426
- limit: Math.min(this.#limit, _QueryBuilder.maxLimit),
4427
- include_docs: this.#includeDocs
4452
+ limit: Math.min(__privateGet(this, _limit), _QueryBuilder.maxLimit),
4453
+ include_docs: __privateGet(this, _includeDocs)
4428
4454
  };
4429
- if (this.#bookmark) {
4430
- body2.bookmark = this.#bookmark;
4455
+ if (__privateGet(this, _bookmark)) {
4456
+ body2.bookmark = __privateGet(this, _bookmark);
4431
4457
  }
4432
- if (this.#sort) {
4433
- const order = this.#sortOrder === "descending" ? "-" : "";
4434
- const type = `<${this.#sortType}>`;
4435
- body2.sort = `${order}${this.handleSpaces(this.#sort)}${type}`;
4458
+ if (__privateGet(this, _sort)) {
4459
+ const order = __privateGet(this, _sortOrder) === "descending" ? "-" : "";
4460
+ const type = `<${__privateGet(this, _sortType)}>`;
4461
+ body2.sort = `${order}${this.handleSpaces(__privateGet(this, _sort))}${type}`;
4436
4462
  }
4437
4463
  return body2;
4438
4464
  }
4439
4465
  async run() {
4440
- if (this.#skip) {
4441
- await this.#skipItems(this.#skip);
4466
+ if (__privateGet(this, _skip)) {
4467
+ await __privateMethod(this, _skipItems, skipItems_fn).call(this, __privateGet(this, _skip));
4442
4468
  }
4443
- return await this.#execute();
4469
+ return await __privateMethod(this, _execute, execute_fn).call(this);
4444
4470
  }
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 {
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);
4472
4513
  return await runQuery(fullPath, body2, cookie);
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
- }
4514
+ } else {
4515
+ throw err;
4480
4516
  }
4481
4517
  }
4482
4518
  };
4519
+ _QueryBuilder.maxLimit = 200;
4520
+ QueryBuilder = _QueryBuilder;
4483
4521
  }
4484
4522
  });
4485
4523
 
@@ -4558,9 +4596,10 @@ var init_searchIndexes2 = __esm({
4558
4596
 
4559
4597
  // src/db/errors.ts
4560
4598
  function checkErrorCode(error, code) {
4599
+ var _a;
4561
4600
  const stringCode = code.toString();
4562
4601
  if (typeof error === "object") {
4563
- return error.status === code || error.message?.includes(stringCode);
4602
+ return error.status === code || ((_a = error.message) == null ? void 0 : _a.includes(stringCode));
4564
4603
  } else if (typeof error === "number") {
4565
4604
  return error === code;
4566
4605
  } else if (typeof error === "string") {
@@ -4811,12 +4850,12 @@ var init_objectStore = __esm({
4811
4850
  streamUpload = async (bucketName, filename, stream2, extra = {}) => {
4812
4851
  const objectStore = ObjectStore(bucketName);
4813
4852
  await makeSureBucketExists(objectStore, bucketName);
4814
- if (filename?.endsWith(".js")) {
4853
+ if (filename == null ? void 0 : filename.endsWith(".js")) {
4815
4854
  extra = {
4816
4855
  ...extra,
4817
4856
  ContentType: "application/javascript"
4818
4857
  };
4819
- } else if (filename?.endsWith(".svg")) {
4858
+ } else if (filename == null ? void 0 : filename.endsWith(".svg")) {
4820
4859
  extra = {
4821
4860
  ...extra,
4822
4861
  ContentType: "image"
@@ -4932,6 +4971,7 @@ var init_objectStore = __esm({
4932
4971
  return objectStore.deleteObjects(params2).promise();
4933
4972
  };
4934
4973
  deleteFolder = async (bucketName, folder) => {
4974
+ var _a, _b, _c;
4935
4975
  bucketName = sanitizeBucket(bucketName);
4936
4976
  folder = sanitizeKey(folder);
4937
4977
  const client = ObjectStore(bucketName);
@@ -4940,7 +4980,7 @@ var init_objectStore = __esm({
4940
4980
  Prefix: folder
4941
4981
  };
4942
4982
  const existingObjectsResponse = await client.listObjects(listParams).promise();
4943
- if (existingObjectsResponse.Contents?.length === 0) {
4983
+ if (((_a = existingObjectsResponse.Contents) == null ? void 0 : _a.length) === 0) {
4944
4984
  return;
4945
4985
  }
4946
4986
  const deleteParams = {
@@ -4949,11 +4989,11 @@ var init_objectStore = __esm({
4949
4989
  Objects: []
4950
4990
  }
4951
4991
  };
4952
- existingObjectsResponse.Contents?.forEach((content) => {
4992
+ (_b = existingObjectsResponse.Contents) == null ? void 0 : _b.forEach((content) => {
4953
4993
  deleteParams.Delete.Objects.push({ Key: content.Key });
4954
4994
  });
4955
4995
  const deleteResponse = await client.deleteObjects(deleteParams).promise();
4956
- if (deleteResponse.Deleted?.length === 1e3) {
4996
+ if (((_c = deleteResponse.Deleted) == null ? void 0 : _c.length) === 1e3) {
4957
4997
  return deleteFolder(bucketName, folder);
4958
4998
  }
4959
4999
  };
@@ -5230,7 +5270,7 @@ function getFullPath(fileName) {
5230
5270
  }
5231
5271
  function getSingleFileMaxSizeInfo(totalMaxSize) {
5232
5272
  const regex = /(\d+)([A-Za-z])/;
5233
- const match = totalMaxSize?.match(regex);
5273
+ const match = totalMaxSize == null ? void 0 : totalMaxSize.match(regex);
5234
5274
  if (!match) {
5235
5275
  console.warn(`totalMaxSize does not have a valid value`, {
5236
5276
  totalMaxSize
@@ -5262,9 +5302,9 @@ function localFileDestination() {
5262
5302
  const fileInfo = getSingleFileMaxSizeInfo(environment_default.ROLLING_LOG_MAX_SIZE);
5263
5303
  const outFile = rfs.createStream(logsFileName, {
5264
5304
  // As we have a rolling size, we want to half the max size
5265
- size: fileInfo?.size,
5305
+ size: fileInfo == null ? void 0 : fileInfo.size,
5266
5306
  path: logsPath,
5267
- maxFiles: fileInfo?.totalHistoryFiles || 1,
5307
+ maxFiles: (fileInfo == null ? void 0 : fileInfo.totalHistoryFiles) || 1,
5268
5308
  immutable: true,
5269
5309
  history: budibaseLogsHistoryFileName,
5270
5310
  initialRotation: false
@@ -5339,8 +5379,8 @@ var init_logger = __esm({
5339
5379
  tenantId: getTenantId2(),
5340
5380
  appId: getAppId2(),
5341
5381
  automationId: getAutomationId2(),
5342
- identityId: identity?._id,
5343
- identityType: identity?.type,
5382
+ identityId: identity == null ? void 0 : identity._id,
5383
+ identityType: identity == null ? void 0 : identity.type,
5344
5384
  correlationId: getId()
5345
5385
  };
5346
5386
  const mergingObject = {
@@ -5404,30 +5444,30 @@ var init_logger = __esm({
5404
5444
  pinoInstance = destinations.length ? (0, import_pino.default)(pinoOptions, import_pino.default.multistream(destinations)) : (0, import_pino.default)(pinoOptions);
5405
5445
  console.log = (...arg) => {
5406
5446
  const [obj, msg] = getLogParams2(arg);
5407
- pinoInstance?.info(obj, msg);
5447
+ pinoInstance == null ? void 0 : pinoInstance.info(obj, msg);
5408
5448
  };
5409
5449
  console.info = (...arg) => {
5410
5450
  const [obj, msg] = getLogParams2(arg);
5411
- pinoInstance?.info(obj, msg);
5451
+ pinoInstance == null ? void 0 : pinoInstance.info(obj, msg);
5412
5452
  };
5413
5453
  console.warn = (...arg) => {
5414
5454
  const [obj, msg] = getLogParams2(arg);
5415
- pinoInstance?.warn(obj, msg);
5455
+ pinoInstance == null ? void 0 : pinoInstance.warn(obj, msg);
5416
5456
  };
5417
5457
  console.error = (...arg) => {
5418
5458
  const [obj, msg] = getLogParams2(arg);
5419
- pinoInstance?.error(obj, msg);
5459
+ pinoInstance == null ? void 0 : pinoInstance.error(obj, msg);
5420
5460
  };
5421
5461
  console.trace = (...arg) => {
5422
5462
  const [obj, msg] = getLogParams2(arg);
5423
5463
  if (!obj.err) {
5424
5464
  obj.err = new Error();
5425
5465
  }
5426
- pinoInstance?.trace(obj, msg);
5466
+ pinoInstance == null ? void 0 : pinoInstance.trace(obj, msg);
5427
5467
  };
5428
5468
  console.debug = (...arg) => {
5429
5469
  const [obj, msg] = getLogParams2(arg);
5430
- pinoInstance?.debug(obj, msg);
5470
+ pinoInstance == null ? void 0 : pinoInstance.debug(obj, msg);
5431
5471
  };
5432
5472
  const getTenantId2 = () => {
5433
5473
  let tenantId;
@@ -5710,6 +5750,7 @@ var isUserInAppTenant = (appId, user) => {
5710
5750
  };
5711
5751
  var ALL_STRATEGIES = Object.values(TenantResolutionStrategy);
5712
5752
  var getTenantIDFromCtx = (ctx, opts) => {
5753
+ var _a;
5713
5754
  if (!isMultiTenant()) {
5714
5755
  return DEFAULT_TENANT_ID;
5715
5756
  }
@@ -5723,15 +5764,16 @@ var getTenantIDFromCtx = (ctx, opts) => {
5723
5764
  opts.excludeStrategies = [];
5724
5765
  }
5725
5766
  const isAllowed = (strategy) => {
5726
- if (opts.excludeStrategies?.includes(strategy)) {
5767
+ var _a2, _b;
5768
+ if ((_a2 = opts.excludeStrategies) == null ? void 0 : _a2.includes(strategy)) {
5727
5769
  return false;
5728
5770
  }
5729
- if (opts.includeStrategies?.includes(strategy)) {
5771
+ if ((_b = opts.includeStrategies) == null ? void 0 : _b.includes(strategy)) {
5730
5772
  return true;
5731
5773
  }
5732
5774
  };
5733
5775
  if (isAllowed("user" /* USER */)) {
5734
- const userTenantId = ctx.user?.tenantId;
5776
+ const userTenantId = (_a = ctx.user) == null ? void 0 : _a.tenantId;
5735
5777
  if (userTenantId) {
5736
5778
  return userTenantId;
5737
5779
  }
@@ -6299,7 +6341,7 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
6299
6341
  logWarn(`Ignoring redlock conflict in write-through cache`);
6300
6342
  }
6301
6343
  }
6302
- cacheItem = makeCacheItem(output, updateDb ? null : cacheItem?.lastWrite);
6344
+ cacheItem = makeCacheItem(output, updateDb ? null : cacheItem == null ? void 0 : cacheItem.lastWrite);
6303
6345
  if (output._id) {
6304
6346
  await cache.store(makeCacheKey(db, output._id), cacheItem);
6305
6347
  }
@@ -6391,6 +6433,7 @@ async function getSettingsConfig() {
6391
6433
  async function getPlatformUrl(opts = {
6392
6434
  tenantAware: true
6393
6435
  }) {
6436
+ var _a;
6394
6437
  let platformUrl = environment_default.PLATFORM_URL || "http://localhost:10000";
6395
6438
  if (!environment_default.SELF_HOSTED && environment_default.MULTI_TENANCY && opts.tenantAware) {
6396
6439
  const tenantId = getTenantId();
@@ -6398,11 +6441,11 @@ async function getPlatformUrl(opts = {
6398
6441
  platformUrl = platformUrl.replace("://", `://${tenantId}.`);
6399
6442
  }
6400
6443
  } else if (environment_default.SELF_HOSTED) {
6401
- const config = opts?.config ? opts.config : (
6444
+ const config = (opts == null ? void 0 : opts.config) ? opts.config : (
6402
6445
  // direct to db to prevent infinite loop
6403
- (await getConfig("settings" /* SETTINGS */))?.config
6446
+ (_a = await getConfig("settings" /* SETTINGS */)) == null ? void 0 : _a.config
6404
6447
  );
6405
- if (config?.platformUrl) {
6448
+ if (config == null ? void 0 : config.platformUrl) {
6406
6449
  platformUrl = config.platformUrl;
6407
6450
  }
6408
6451
  }
@@ -6416,13 +6459,14 @@ var analyticsEnabled = async (opts) => {
6416
6459
  "analyticsEnabled" /* ANALYTICS_ENABLED */,
6417
6460
  86400 /* ONE_DAY */,
6418
6461
  async () => {
6419
- const config = opts?.config ? opts.config : (
6462
+ var _a;
6463
+ const config = (opts == null ? void 0 : opts.config) ? opts.config : (
6420
6464
  // direct to db to prevent infinite loop
6421
- (await getConfig("settings" /* SETTINGS */))?.config
6465
+ (_a = await getConfig("settings" /* SETTINGS */)) == null ? void 0 : _a.config
6422
6466
  );
6423
- if (config?.analyticsEnabled === false) {
6467
+ if ((config == null ? void 0 : config.analyticsEnabled) === false) {
6424
6468
  return false;
6425
- } else if (config?.analyticsEnabled === true) {
6469
+ } else if ((config == null ? void 0 : config.analyticsEnabled) === true) {
6426
6470
  return true;
6427
6471
  }
6428
6472
  }
@@ -6442,7 +6486,7 @@ async function getGoogleConfigDoc() {
6442
6486
  }
6443
6487
  async function getGoogleConfig() {
6444
6488
  const config = await getGoogleConfigDoc();
6445
- return config?.config;
6489
+ return config == null ? void 0 : config.config;
6446
6490
  }
6447
6491
  async function getGoogleDatasourceConfig() {
6448
6492
  if (!environment_default.SELF_HOSTED) {
@@ -6470,11 +6514,13 @@ async function getOIDCConfigDoc() {
6470
6514
  return getConfig("oidc" /* OIDC */);
6471
6515
  }
6472
6516
  async function getOIDCConfig() {
6473
- const config = (await getOIDCConfigDoc())?.config;
6474
- return config?.configs && config.configs[0];
6517
+ var _a;
6518
+ const config = (_a = await getOIDCConfigDoc()) == null ? void 0 : _a.config;
6519
+ return (config == null ? void 0 : config.configs) && config.configs[0];
6475
6520
  }
6476
6521
  async function getOIDCConfigById(configId) {
6477
- const config = (await getConfig("oidc" /* OIDC */))?.config;
6522
+ var _a;
6523
+ const config = (_a = await getConfig("oidc" /* OIDC */)) == null ? void 0 : _a.config;
6478
6524
  return config && config.configs.filter((c) => c.uuid === configId)[0];
6479
6525
  }
6480
6526
  async function getSMTPConfigDoc() {
@@ -6501,7 +6547,7 @@ async function getSMTPConfig(isAutomation) {
6501
6547
  }
6502
6548
  async function getSCIMConfig() {
6503
6549
  const config = await getConfig("scim" /* SCIM */);
6504
- return config?.config;
6550
+ return config == null ? void 0 : config.config;
6505
6551
  }
6506
6552
 
6507
6553
  // src/events/index.ts
@@ -6916,7 +6962,7 @@ async function getAppIdFromCtx(ctx) {
6916
6962
  appId = confirmAppId(await resolveAppUrl(ctx));
6917
6963
  }
6918
6964
  const referer = ctx.request.headers.referer;
6919
- if (!appId && referer?.includes(BUILDER_APP_PREFIX)) {
6965
+ if (!appId && (referer == null ? void 0 : referer.includes(BUILDER_APP_PREFIX))) {
6920
6966
  const refererId = parseAppIdFromUrl(ctx.request.headers.referer);
6921
6967
  appId = confirmAppId(refererId);
6922
6968
  }
@@ -7135,6 +7181,7 @@ function handleStalled(queue, removeStalledCb) {
7135
7181
  });
7136
7182
  }
7137
7183
  function getLogParams(eventType, event, opts = {}, extra = {}) {
7184
+ var _a, _b, _c;
7138
7185
  const message = `[BULL] ${eventType}=${event}`;
7139
7186
  const err = opts.error;
7140
7187
  const bullLog = {
@@ -7142,11 +7189,11 @@ function getLogParams(eventType, event, opts = {}, extra = {}) {
7142
7189
  eventType,
7143
7190
  event,
7144
7191
  job: opts.job,
7145
- jobId: opts.jobId || opts.job?.id,
7192
+ jobId: opts.jobId || ((_a = opts.job) == null ? void 0 : _a.id),
7146
7193
  ...extra
7147
7194
  };
7148
7195
  let automationLog;
7149
- if (opts.job?.data?.automation) {
7196
+ if ((_c = (_b = opts.job) == null ? void 0 : _b.data) == null ? void 0 : _c.automation) {
7150
7197
  automationLog = {
7151
7198
  _logKey: "automation",
7152
7199
  trigger: opts.job ? opts.job.data.automation.definition.trigger.event : void 0
@@ -7161,9 +7208,11 @@ var EventTypeMap = {
7161
7208
  ["systemEventQueue" /* SYSTEM_EVENT_QUEUE */]: "system-event" /* SYSTEM_EVENT */
7162
7209
  };
7163
7210
  function logging(queue, jobQueue) {
7211
+ var _a;
7164
7212
  const eventType = EventTypeMap[jobQueue];
7165
7213
  function doInJobContext(job, task) {
7166
- const appId = job.data.event?.appId;
7214
+ var _a2;
7215
+ const appId = (_a2 = job.data.event) == null ? void 0 : _a2.appId;
7167
7216
  if (appId) {
7168
7217
  return doInContext(appId, task);
7169
7218
  } else {
@@ -7177,7 +7226,7 @@ function logging(queue, jobQueue) {
7177
7226
  }).on("error" /* ERROR */, (error) => {
7178
7227
  console.error(...getLogParams(eventType, "error" /* ERROR */, { error }));
7179
7228
  });
7180
- if (process.env.NODE_DEBUG?.includes("bull")) {
7229
+ if ((_a = process.env.NODE_DEBUG) == null ? void 0 : _a.includes("bull")) {
7181
7230
  queue.on("waiting" /* WAITING */, (jobId) => {
7182
7231
  console.info(...getLogParams(eventType, "waiting" /* WAITING */, { jobId }));
7183
7232
  }).on("active" /* ACTIVE */, async (job, jobPromise) => {
@@ -7247,7 +7296,7 @@ function createQueue(jobQueue, opts = {}) {
7247
7296
  } else {
7248
7297
  queue = new inMemoryQueue_default(jobQueue, queueConfig);
7249
7298
  }
7250
- addListeners(queue, jobQueue, opts?.removeStalledCb);
7299
+ addListeners(queue, jobQueue, opts == null ? void 0 : opts.removeStalledCb);
7251
7300
  QUEUES.push(queue);
7252
7301
  if (!cleanupInterval && !environment_default.isTest()) {
7253
7302
  cleanupInterval = set(cleanup2, CLEANUP_PERIOD_MS);
@@ -7272,10 +7321,7 @@ async function shutdown2() {
7272
7321
 
7273
7322
  // src/events/processors/AuditLogsProcessor.ts
7274
7323
  init_environment2();
7275
- var AuditLogsProcessor = class _AuditLogsProcessor {
7276
- static {
7277
- this.auditLogsEnabled = false;
7278
- }
7324
+ var _AuditLogsProcessor = class _AuditLogsProcessor {
7279
7325
  // can't use constructor as need to return promise
7280
7326
  static init(fn) {
7281
7327
  _AuditLogsProcessor.auditLogsEnabled = true;
@@ -7327,9 +7373,12 @@ var AuditLogsProcessor = class _AuditLogsProcessor {
7327
7373
  async identifyGroup(group, timestamp) {
7328
7374
  }
7329
7375
  shutdown() {
7330
- _AuditLogsProcessor.auditLogQueue?.close();
7376
+ var _a;
7377
+ (_a = _AuditLogsProcessor.auditLogQueue) == null ? void 0 : _a.close();
7331
7378
  }
7332
7379
  };
7380
+ _AuditLogsProcessor.auditLogsEnabled = false;
7381
+ var AuditLogsProcessor = _AuditLogsProcessor;
7333
7382
 
7334
7383
  // src/events/processors/Processors.ts
7335
7384
  var Processor = class {
@@ -7544,7 +7593,7 @@ var bulkGetGlobalUsersById = async (userIds, opts) => {
7544
7593
  keys: userIds,
7545
7594
  include_docs: true
7546
7595
  })).rows.map((row) => row.doc);
7547
- if (opts?.cleanup) {
7596
+ if (opts == null ? void 0 : opts.cleanup) {
7548
7597
  users = removeUserPassword(users);
7549
7598
  }
7550
7599
  return users;
@@ -7565,7 +7614,7 @@ var bulkUpdateGlobalUsers = async (users) => {
7565
7614
  async function getById(id, opts) {
7566
7615
  const db = getGlobalDB();
7567
7616
  let user = await db.get(id);
7568
- if (opts?.cleanup) {
7617
+ if (opts == null ? void 0 : opts.cleanup) {
7569
7618
  user = removeUserPassword(user);
7570
7619
  }
7571
7620
  return user;
@@ -7582,7 +7631,7 @@ var getGlobalUserByEmail = async (email, opts) => {
7582
7631
  throw new Error(`Multiple users found with email address: ${email}`);
7583
7632
  }
7584
7633
  let user = response;
7585
- if (opts?.cleanup) {
7634
+ if (opts == null ? void 0 : opts.cleanup) {
7586
7635
  user = removeUserPassword(user);
7587
7636
  }
7588
7637
  return user;
@@ -7600,7 +7649,7 @@ var searchGlobalUsersByApp = async (appId, opts, getOpts) => {
7600
7649
  response = [];
7601
7650
  }
7602
7651
  let users = Array.isArray(response) ? response : [response];
7603
- if (getOpts?.cleanup) {
7652
+ if (getOpts == null ? void 0 : getOpts.cleanup) {
7604
7653
  users = removeUserPassword(users);
7605
7654
  }
7606
7655
  return users;
@@ -7630,10 +7679,10 @@ var searchGlobalUsersByAppAccess = async (appId, opts) => {
7630
7679
  $regex: "^us_"
7631
7680
  }
7632
7681
  },
7633
- limit: opts?.limit || 50
7682
+ limit: (opts == null ? void 0 : opts.limit) || 50
7634
7683
  };
7635
7684
  const resp = await directCouchFind(getGlobalDBName(), searchOptions);
7636
- return resp?.rows;
7685
+ return resp == null ? void 0 : resp.rows;
7637
7686
  };
7638
7687
  var getGlobalUserByAppPage = (appId, user) => {
7639
7688
  if (!user) {
@@ -7656,7 +7705,7 @@ var searchGlobalUsersByEmail = async (email, opts, getOpts) => {
7656
7705
  response = [];
7657
7706
  }
7658
7707
  let users = Array.isArray(response) ? response : [response];
7659
- if (getOpts?.cleanup) {
7708
+ if (getOpts == null ? void 0 : getOpts.cleanup) {
7660
7709
  users = removeUserPassword(users);
7661
7710
  }
7662
7711
  return users;
@@ -8007,12 +8056,13 @@ __export(users_exports2, {
8007
8056
  isGlobalBuilder: () => isGlobalBuilder
8008
8057
  });
8009
8058
  function isBuilder(user, appId) {
8059
+ var _a, _b, _c;
8010
8060
  if (!user) {
8011
8061
  return false;
8012
8062
  }
8013
- if (user.builder?.global) {
8063
+ if ((_a = user.builder) == null ? void 0 : _a.global) {
8014
8064
  return true;
8015
- } else if (appId && user.builder?.apps?.includes(getProdAppID2(appId))) {
8065
+ } else if (appId && ((_c = (_b = user.builder) == null ? void 0 : _b.apps) == null ? void 0 : _c.includes(getProdAppID2(appId)))) {
8016
8066
  return true;
8017
8067
  }
8018
8068
  return false;
@@ -8030,24 +8080,27 @@ function isAdminOrBuilder(user, appId) {
8030
8080
  return isBuilder(user, appId) || isAdmin(user);
8031
8081
  }
8032
8082
  function hasAppBuilderPermissions(user) {
8083
+ var _a, _b, _c;
8033
8084
  if (!user) {
8034
8085
  return false;
8035
8086
  }
8036
- const appLength = user.builder?.apps?.length;
8037
- const isGlobalBuilder3 = !!user.builder?.global;
8087
+ const appLength = (_b = (_a = user.builder) == null ? void 0 : _a.apps) == null ? void 0 : _b.length;
8088
+ const isGlobalBuilder3 = !!((_c = user.builder) == null ? void 0 : _c.global);
8038
8089
  return !isGlobalBuilder3 && appLength != null && appLength > 0;
8039
8090
  }
8040
8091
  function hasBuilderPermissions(user) {
8092
+ var _a;
8041
8093
  if (!user) {
8042
8094
  return false;
8043
8095
  }
8044
- return user.builder?.global || hasAppBuilderPermissions(user);
8096
+ return ((_a = user.builder) == null ? void 0 : _a.global) || hasAppBuilderPermissions(user);
8045
8097
  }
8046
8098
  function hasAdminPermissions(user) {
8099
+ var _a;
8047
8100
  if (!user) {
8048
8101
  return false;
8049
8102
  }
8050
- return !!user.admin?.global;
8103
+ return !!((_a = user.admin) == null ? void 0 : _a.global);
8051
8104
  }
8052
8105
 
8053
8106
  // src/users/utils.ts
@@ -8120,7 +8173,7 @@ var unassignAppRoleEvents = async (user, roles, existingRoles) => {
8120
8173
  };
8121
8174
  var handleAppRoleEvents = async (user, existingUser) => {
8122
8175
  const roles = user.roles;
8123
- const existingRoles = existingUser?.roles;
8176
+ const existingRoles = existingUser == null ? void 0 : existingUser.roles;
8124
8177
  await assignAppRoleEvents(user, roles, existingRoles);
8125
8178
  await unassignAppRoleEvents(user, roles, existingRoles);
8126
8179
  };
@@ -8172,7 +8225,7 @@ var isRemovingAdmin = (user, existingUser) => {
8172
8225
  return isRemovingPermission(user, existingUser, hasAdminPermissions2);
8173
8226
  };
8174
8227
  var isOnboardingComplete = (user, existingUser) => {
8175
- return !existingUser?.onboardedAt && typeof user.onboardedAt === "string";
8228
+ return !(existingUser == null ? void 0 : existingUser.onboardedAt) && typeof user.onboardedAt === "string";
8176
8229
  };
8177
8230
  var isAddingPermission = (user, existingUser, hasPermission) => {
8178
8231
  if (!hasPermission(user)) {
@@ -8229,7 +8282,7 @@ async function getSessionsForUser(userId) {
8229
8282
  }
8230
8283
  async function invalidateSessions(userId, opts = {}) {
8231
8284
  try {
8232
- const reason = opts?.reason || "unknown";
8285
+ const reason = (opts == null ? void 0 : opts.reason) || "unknown";
8233
8286
  let sessionIds = opts.sessionIds || [];
8234
8287
  let sessionKeys;
8235
8288
  if (sessionIds.length === 0) {
@@ -8406,6 +8459,7 @@ var UserDB = class _UserDB {
8406
8459
  return user;
8407
8460
  }
8408
8461
  static async save(user, opts = {}) {
8462
+ var _a, _b;
8409
8463
  if (opts.hashPassword == null) {
8410
8464
  opts.hashPassword = true;
8411
8465
  }
@@ -8418,7 +8472,7 @@ var UserDB = class _UserDB {
8418
8472
  if (!email && !_id) {
8419
8473
  throw new Error("_id or email is required");
8420
8474
  }
8421
- if (user.builder?.apps?.length && !await _UserDB.features.isAppBuildersEnabled()) {
8475
+ if (((_b = (_a = user.builder) == null ? void 0 : _a.apps) == null ? void 0 : _b.length) && !await _UserDB.features.isAppBuildersEnabled()) {
8422
8476
  throw new Error("Unable to update app builders, please check license");
8423
8477
  }
8424
8478
  let dbUser;
@@ -8446,10 +8500,10 @@ var UserDB = class _UserDB {
8446
8500
  return _UserDB.quotas.addUsers(change, async () => {
8447
8501
  await validateUniqueUser(email, tenantId);
8448
8502
  let builtUser = await _UserDB.buildUser(user, opts, tenantId, dbUser);
8449
- if (opts.currentUserId && opts.currentUserId === dbUser?._id) {
8503
+ if (opts.currentUserId && opts.currentUserId === (dbUser == null ? void 0 : dbUser._id)) {
8450
8504
  builtUser = cleanseUserObject(builtUser, dbUser);
8451
8505
  }
8452
- if (!dbUser && roles?.length) {
8506
+ if (!dbUser && (roles == null ? void 0 : roles.length)) {
8453
8507
  builtUser.roles = { ...roles };
8454
8508
  }
8455
8509
  let groupPromises = [];
@@ -8728,8 +8782,8 @@ var identifyUser = async (user, account, timestamp) => {
8728
8782
  if (isSSOUser(user)) {
8729
8783
  providerType = user.providerType;
8730
8784
  }
8731
- const accountHolder = account?.budibaseUserId === user._id || false;
8732
- const verified2 = account && account?.budibaseUserId === user._id ? account.verified : false;
8785
+ const accountHolder = (account == null ? void 0 : account.budibaseUserId) === user._id || false;
8786
+ const verified2 = account && (account == null ? void 0 : account.budibaseUserId) === user._id ? account.verified : false;
8733
8787
  const installationId = await getInstallationId();
8734
8788
  const hosting = account ? account.hosting : getHostingFromEnv();
8735
8789
  const environment2 = getDeploymentEnvironment();
@@ -8888,7 +8942,7 @@ var clearEvents = async () => {
8888
8942
  };
8889
8943
  var isBackfillingEvent = async (event) => {
8890
8944
  const backfill = await getBackfillMetadata();
8891
- const events2 = backfill?.eventWhitelist;
8945
+ const events2 = backfill == null ? void 0 : backfill.eventWhitelist;
8892
8946
  if (events2 && events2.includes(event)) {
8893
8947
  return true;
8894
8948
  } else {
@@ -9232,11 +9286,12 @@ var auth_default = {
9232
9286
  // src/events/publishers/automation.ts
9233
9287
  init_src();
9234
9288
  async function created3(automation, timestamp) {
9289
+ var _a, _b, _c, _d;
9235
9290
  const properties = {
9236
9291
  appId: automation.appId,
9237
9292
  automationId: automation._id,
9238
- triggerId: automation.definition?.trigger?.id,
9239
- triggerType: automation.definition?.trigger?.stepId,
9293
+ triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9294
+ triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId,
9240
9295
  audited: {
9241
9296
  name: automation.name
9242
9297
  }
@@ -9244,20 +9299,22 @@ async function created3(automation, timestamp) {
9244
9299
  await publishEvent("automation:created" /* AUTOMATION_CREATED */, properties, timestamp);
9245
9300
  }
9246
9301
  async function triggerUpdated(automation) {
9302
+ var _a, _b, _c, _d;
9247
9303
  const properties = {
9248
9304
  appId: automation.appId,
9249
9305
  automationId: automation._id,
9250
- triggerId: automation.definition?.trigger?.id,
9251
- triggerType: automation.definition?.trigger?.stepId
9306
+ triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9307
+ triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId
9252
9308
  };
9253
9309
  await publishEvent("automation:trigger:updated" /* AUTOMATION_TRIGGER_UPDATED */, properties);
9254
9310
  }
9255
9311
  async function deleted3(automation) {
9312
+ var _a, _b, _c, _d;
9256
9313
  const properties = {
9257
9314
  appId: automation.appId,
9258
9315
  automationId: automation._id,
9259
- triggerId: automation.definition?.trigger?.id,
9260
- triggerType: automation.definition?.trigger?.stepId,
9316
+ triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9317
+ triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId,
9261
9318
  audited: {
9262
9319
  name: automation.name
9263
9320
  }
@@ -9265,11 +9322,12 @@ async function deleted3(automation) {
9265
9322
  await publishEvent("automation:deleted" /* AUTOMATION_DELETED */, properties);
9266
9323
  }
9267
9324
  async function tested(automation) {
9325
+ var _a, _b, _c, _d;
9268
9326
  const properties = {
9269
9327
  appId: automation.appId,
9270
9328
  automationId: automation._id,
9271
- triggerId: automation.definition?.trigger?.id,
9272
- triggerType: automation.definition?.trigger?.stepId
9329
+ triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9330
+ triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId
9273
9331
  };
9274
9332
  await publishEvent("automation:tested" /* AUTOMATION_TESTED */, properties);
9275
9333
  }
@@ -9280,11 +9338,12 @@ var run = async (count, timestamp) => {
9280
9338
  await publishEvent("automations:run" /* AUTOMATIONS_RUN */, properties, timestamp);
9281
9339
  };
9282
9340
  async function stepCreated(automation, step, timestamp) {
9341
+ var _a, _b, _c, _d;
9283
9342
  const properties = {
9284
9343
  appId: automation.appId,
9285
9344
  automationId: automation._id,
9286
- triggerId: automation.definition?.trigger?.id,
9287
- triggerType: automation.definition?.trigger?.stepId,
9345
+ triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9346
+ triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId,
9288
9347
  stepId: step.id,
9289
9348
  stepType: step.stepId,
9290
9349
  audited: {
@@ -9294,11 +9353,12 @@ async function stepCreated(automation, step, timestamp) {
9294
9353
  await publishEvent("automation:step:created" /* AUTOMATION_STEP_CREATED */, properties, timestamp);
9295
9354
  }
9296
9355
  async function stepDeleted(automation, step) {
9356
+ var _a, _b, _c, _d;
9297
9357
  const properties = {
9298
9358
  appId: automation.appId,
9299
9359
  automationId: automation._id,
9300
- triggerId: automation.definition?.trigger?.id,
9301
- triggerType: automation.definition?.trigger?.stepId,
9360
+ triggerId: (_b = (_a = automation.definition) == null ? void 0 : _a.trigger) == null ? void 0 : _b.id,
9361
+ triggerType: (_d = (_c = automation.definition) == null ? void 0 : _c.trigger) == null ? void 0 : _d.stepId,
9302
9362
  stepId: step.id,
9303
9363
  stepType: step.stepId,
9304
9364
  audited: {
@@ -9585,23 +9645,25 @@ var role_default = {
9585
9645
  // src/events/publishers/screen.ts
9586
9646
  init_src();
9587
9647
  async function created8(screen, timestamp) {
9648
+ var _a;
9588
9649
  const properties = {
9589
9650
  layoutId: screen.layoutId,
9590
9651
  screenId: screen._id,
9591
9652
  roleId: screen.routing.roleId,
9592
9653
  audited: {
9593
- name: screen.routing?.route
9654
+ name: (_a = screen.routing) == null ? void 0 : _a.route
9594
9655
  }
9595
9656
  };
9596
9657
  await publishEvent("screen:created" /* SCREEN_CREATED */, properties, timestamp);
9597
9658
  }
9598
9659
  async function deleted8(screen) {
9660
+ var _a;
9599
9661
  const properties = {
9600
9662
  layoutId: screen.layoutId,
9601
9663
  screenId: screen._id,
9602
9664
  roleId: screen.routing.roleId,
9603
9665
  audited: {
9604
- name: screen.routing?.route
9666
+ name: (_a = screen.routing) == null ? void 0 : _a.route
9605
9667
  }
9606
9668
  };
9607
9669
  await publishEvent("screen:deleted" /* SCREEN_DELETED */, properties);
@@ -10672,7 +10734,7 @@ var BUILTIN_ROLE_NAME_ARRAY = Object.values(BUILTIN_ROLES).map(
10672
10734
  (role) => role.name
10673
10735
  );
10674
10736
  function isBuiltin(role) {
10675
- return BUILTIN_ROLE_ID_ARRAY.some((builtin) => role?.includes(builtin));
10737
+ return BUILTIN_ROLE_ID_ARRAY.some((builtin) => role == null ? void 0 : role.includes(builtin));
10676
10738
  }
10677
10739
  function builtinRoleToNumber(id) {
10678
10740
  if (!id) {
@@ -10699,7 +10761,7 @@ async function roleToNumber(id) {
10699
10761
  }
10700
10762
  const hierarchy = await getUserRoleHierarchy(id);
10701
10763
  for (let role of hierarchy) {
10702
- if (isBuiltin(role?.inherits)) {
10764
+ if (isBuiltin(role == null ? void 0 : role.inherits)) {
10703
10765
  return builtinRoleToNumber(role.inherits) + 1;
10704
10766
  }
10705
10767
  }
@@ -10732,7 +10794,7 @@ async function getRole(roleId, opts) {
10732
10794
  role = Object.assign(role, dbRole);
10733
10795
  role._id = getExternalRoleID(role._id, role.version);
10734
10796
  } catch (err) {
10735
- if (!isBuiltin(roleId) && opts?.defaultPublic) {
10797
+ if (!isBuiltin(roleId) && (opts == null ? void 0 : opts.defaultPublic)) {
10736
10798
  return (0, import_cloneDeep2.default)(BUILTIN_ROLES.PUBLIC);
10737
10799
  }
10738
10800
  if (Object.keys(role).length === 0) {
@@ -10855,7 +10917,7 @@ var AccessController = class {
10855
10917
  });
10856
10918
  this.userHierarchies[userRoleId] = roleIds;
10857
10919
  }
10858
- return roleIds?.indexOf(tryingRoleId) !== -1;
10920
+ return (roleIds == null ? void 0 : roleIds.indexOf(tryingRoleId)) !== -1;
10859
10921
  }
10860
10922
  async checkScreensAccess(screens, userRoleId) {
10861
10923
  let accessibleScreens = [];
@@ -10876,7 +10938,7 @@ var AccessController = class {
10876
10938
  }
10877
10939
  };
10878
10940
  function getDBRoleID(roleName) {
10879
- if (roleName?.startsWith("role" /* ROLE */)) {
10941
+ if (roleName == null ? void 0 : roleName.startsWith("role" /* ROLE */)) {
10880
10942
  return roleName;
10881
10943
  }
10882
10944
  return prefixRoleID(roleName);
@@ -11135,7 +11197,8 @@ async function authenticate2(details, requireLocalAccount = true, done, saveUser
11135
11197
  return done(null, ssoUser);
11136
11198
  }
11137
11199
  async function getProfilePictureUrl(user, details) {
11138
- const pictureUrl = details.profile?._json.picture;
11200
+ var _a;
11201
+ const pictureUrl = (_a = details.profile) == null ? void 0 : _a._json.picture;
11139
11202
  if (pictureUrl) {
11140
11203
  const response = await (0, import_node_fetch5.default)(pictureUrl);
11141
11204
  if (response.status === 200) {
@@ -11666,7 +11729,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
11666
11729
  user = await getUser(userId, session.tenantId);
11667
11730
  }
11668
11731
  user.csrfToken = session.csrfToken;
11669
- if (session?.lastAccessedAt < timeMinusOneMinute()) {
11732
+ if ((session == null ? void 0 : session.lastAccessedAt) < timeMinusOneMinute()) {
11670
11733
  await updateSessionTTL(session);
11671
11734
  }
11672
11735
  authenticated = true;
@@ -11708,9 +11771,9 @@ function authenticated_default(noAuthPatterns = [], opts = {
11708
11771
  } catch (err) {
11709
11772
  console.error(`Auth Error: ${err.message}`);
11710
11773
  console.error(err);
11711
- if (err?.name === "JsonWebTokenError") {
11774
+ if ((err == null ? void 0 : err.name) === "JsonWebTokenError") {
11712
11775
  clearCookie(ctx, "budibase:auth" /* Auth */);
11713
- } else if (err?.code === "invalid_api_key" /* INVALID_API_KEY */) {
11776
+ } else if ((err == null ? void 0 : err.code) === "invalid_api_key" /* INVALID_API_KEY */) {
11714
11777
  ctx.throw(403, err.message);
11715
11778
  }
11716
11779
  if (opts && opts.publicAllowed || publicEndpoint) {
@@ -11777,6 +11840,7 @@ var INCLUDED_CONTENT_TYPES = [
11777
11840
  function csrf_default(opts = { noCsrfPatterns: [] }) {
11778
11841
  const noCsrfOptions = buildMatcherRegex(opts.noCsrfPatterns);
11779
11842
  return async (ctx, next) => {
11843
+ var _a;
11780
11844
  const found = matches(ctx, noCsrfOptions);
11781
11845
  if (found) {
11782
11846
  return next();
@@ -11791,7 +11855,7 @@ function csrf_default(opts = { noCsrfPatterns: [] }) {
11791
11855
  if (ctx.internal) {
11792
11856
  return next();
11793
11857
  }
11794
- const userToken = ctx.user?.csrfToken;
11858
+ const userToken = (_a = ctx.user) == null ? void 0 : _a.csrfToken;
11795
11859
  if (!userToken) {
11796
11860
  return next();
11797
11861
  }
@@ -11851,7 +11915,10 @@ function pinoSettings() {
11851
11915
  logger,
11852
11916
  genReqId: correlator2.getId,
11853
11917
  autoLogging: {
11854
- ignore: (req) => !!req.url?.includes("/health")
11918
+ ignore: (req) => {
11919
+ var _a;
11920
+ return !!((_a = req.url) == null ? void 0 : _a.includes("/health"));
11921
+ }
11855
11922
  },
11856
11923
  serializers: {
11857
11924
  req: (req) => {
@@ -11922,7 +11989,8 @@ var errorHandling_default = errorHandling;
11922
11989
 
11923
11990
  // src/middleware/querystringToBody.ts
11924
11991
  function querystringToBody_default(ctx, next) {
11925
- const queryString = ctx.request.query?.query;
11992
+ var _a;
11993
+ const queryString = (_a = ctx.request.query) == null ? void 0 : _a.query;
11926
11994
  if (ctx.request.method.toLowerCase() !== "get") {
11927
11995
  ctx.throw(
11928
11996
  500,
@@ -11952,11 +12020,12 @@ __export(joi_validator_exports, {
11952
12020
  var import_joi = __toESM(require("joi"));
11953
12021
  function validate(schema, property) {
11954
12022
  return (ctx, next) => {
12023
+ var _a;
11955
12024
  if (!schema) {
11956
12025
  return next();
11957
12026
  }
11958
12027
  let params2 = null;
11959
- let reqProp = ctx.request?.[property];
12028
+ let reqProp = (_a = ctx.request) == null ? void 0 : _a[property];
11960
12029
  if (ctx[property] != null) {
11961
12030
  params2 = ctx[property];
11962
12031
  } else if (reqProp != null) {
@@ -12095,6 +12164,7 @@ async function updateUserOAuth(userId, oAuthConfig) {
12095
12164
  }
12096
12165
  }
12097
12166
  async function platformLogout(opts) {
12167
+ var _a;
12098
12168
  const ctx = opts.ctx;
12099
12169
  const userId = opts.userId;
12100
12170
  const keepActiveSession = opts.keepActiveSession;
@@ -12111,7 +12181,7 @@ async function platformLogout(opts) {
12111
12181
  }
12112
12182
  const sessionIds = sessions.map(({ sessionId }) => sessionId);
12113
12183
  await invalidateSessions(userId, { sessionIds, reason: "logout" });
12114
- await auth_default.logout(ctx.user?.email);
12184
+ await auth_default.logout((_a = ctx.user) == null ? void 0 : _a.email);
12115
12185
  await invalidateUser(userId);
12116
12186
  }
12117
12187
 
@@ -12227,7 +12297,7 @@ function validateAutomation(schema) {
12227
12297
  runJoi(validator, schema);
12228
12298
  }
12229
12299
  function validate2(schema) {
12230
- switch (schema?.type) {
12300
+ switch (schema == null ? void 0 : schema.type) {
12231
12301
  case "component" /* COMPONENT */:
12232
12302
  validateComponent(schema);
12233
12303
  break;
@@ -12291,7 +12361,7 @@ async function lookup(address) {
12291
12361
  }
12292
12362
  async function refreshBlacklist() {
12293
12363
  const blacklist = environment_default.BLACKLIST_IPS;
12294
- const list = blacklist?.split(",") || [];
12364
+ const list = (blacklist == null ? void 0 : blacklist.split(",")) || [];
12295
12365
  let final = [];
12296
12366
  for (let addr of list) {
12297
12367
  const trimmed = addr.trim();
@@ -12308,7 +12378,7 @@ async function isBlacklisted(address) {
12308
12378
  if (!blackListArray) {
12309
12379
  await refreshBlacklist();
12310
12380
  }
12311
- if (blackListArray?.length === 0) {
12381
+ if ((blackListArray == null ? void 0 : blackListArray.length) === 0) {
12312
12382
  return false;
12313
12383
  }
12314
12384
  let ips;
@@ -12317,7 +12387,7 @@ async function isBlacklisted(address) {
12317
12387
  } else {
12318
12388
  ips = [address];
12319
12389
  }
12320
- return !!blackListArray?.find((addr) => ips.includes(addr));
12390
+ return !!(blackListArray == null ? void 0 : blackListArray.find((addr) => ips.includes(addr)));
12321
12391
  }
12322
12392
 
12323
12393
  // src/docUpdates/index.ts