@budibase/server 2.7.15 → 2.7.17

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.
@@ -11,8 +11,8 @@ var __commonJS = (cb, mod) => function __require() {
11
11
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
12
  };
13
13
  var __export = (target, all) => {
14
- for (var name in all)
15
- __defProp(target, name, { get: all[name], enumerable: true });
14
+ for (var name2 in all)
15
+ __defProp(target, name2, { get: all[name2], enumerable: true });
16
16
  };
17
17
  var __copyProps = (to, from, except, desc) => {
18
18
  if (from && typeof from === "object" || typeof from === "function") {
@@ -671,13 +671,13 @@ var init_plan = __esm({
671
671
  var isStaticQuota, isMonthlyQuota, isConstantQuota;
672
672
  var init_quota = __esm({
673
673
  "../types/src/sdk/licensing/quota.ts"() {
674
- isStaticQuota = (quotaType, usageType, name) => {
674
+ isStaticQuota = (quotaType, usageType, name2) => {
675
675
  return quotaType === "usage" /* USAGE */ && usageType === "static" /* STATIC */;
676
676
  };
677
- isMonthlyQuota = (quotaType, usageType, name) => {
677
+ isMonthlyQuota = (quotaType, usageType, name2) => {
678
678
  return quotaType === "usage" /* USAGE */ && usageType === "monthly" /* MONTHLY */;
679
679
  };
680
- isConstantQuota = (quotaType, name) => {
680
+ isConstantQuota = (quotaType, name2) => {
681
681
  return quotaType === "constant" /* CONSTANT */;
682
682
  };
683
683
  }
@@ -787,8 +787,8 @@ var init_locks = __esm({
787
787
  var isDocument;
788
788
  var init_db = __esm({
789
789
  "../types/src/sdk/db.ts"() {
790
- isDocument = (doc) => {
791
- return typeof doc === "object" && doc._id && doc._rev;
790
+ isDocument = (doc2) => {
791
+ return typeof doc2 === "object" && doc2._id && doc2._rev;
792
792
  };
793
793
  }
794
794
  });
@@ -2064,12 +2064,12 @@ function getPouchDB(dbName, opts) {
2064
2064
  checkInitialised();
2065
2065
  const db2 = new Pouch(dbName, opts);
2066
2066
  const dbPut = db2.put;
2067
- db2.put = async (doc, options2 = {}) => {
2068
- if (!doc.createdAt) {
2069
- doc.createdAt = (/* @__PURE__ */ new Date()).toISOString();
2067
+ db2.put = async (doc2, options2 = {}) => {
2068
+ if (!doc2.createdAt) {
2069
+ doc2.createdAt = (/* @__PURE__ */ new Date()).toISOString();
2070
2070
  }
2071
- doc.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
2072
- return dbPut(doc, options2);
2071
+ doc2.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
2072
+ return dbPut(doc2, options2);
2073
2073
  };
2074
2074
  db2.exists = async () => {
2075
2075
  const info = await db2.info();
@@ -2239,7 +2239,7 @@ var init_DatabaseImpl = __esm({
2239
2239
  }
2240
2240
  return this.updateOutput(() => db2.get(id));
2241
2241
  }
2242
- async remove(idOrDoc, rev) {
2242
+ async remove(idOrDoc, rev2) {
2243
2243
  const db2 = await this.checkSetup();
2244
2244
  let _id;
2245
2245
  let _rev;
@@ -2248,7 +2248,7 @@ var init_DatabaseImpl = __esm({
2248
2248
  _rev = idOrDoc._rev;
2249
2249
  } else {
2250
2250
  _id = idOrDoc;
2251
- _rev = rev;
2251
+ _rev = rev2;
2252
2252
  }
2253
2253
  if (!_id || !_rev) {
2254
2254
  throw new Error("Unable to remove doc without a valid _id and _rev.");
@@ -3512,18 +3512,18 @@ async function newRedlock(opts = {}) {
3512
3512
  }
3513
3513
  function getLockName(opts) {
3514
3514
  const prefix = opts.systemLock ? "system" : getTenantId();
3515
- let name = `lock:${prefix}_${opts.name}`;
3515
+ let name2 = `lock:${prefix}_${opts.name}`;
3516
3516
  if (opts.resource) {
3517
- name = name + `_${opts.resource}`;
3517
+ name2 = name2 + `_${opts.resource}`;
3518
3518
  }
3519
- return name;
3519
+ return name2;
3520
3520
  }
3521
3521
  async function doWithLock(opts, task) {
3522
3522
  const redlock = await getClient(opts.type, opts.customOptions);
3523
3523
  let lock;
3524
3524
  try {
3525
- const name = getLockName(opts);
3526
- lock = await redlock.lock(name, opts.ttl);
3525
+ const name2 = getLockName(opts);
3526
+ lock = await redlock.lock(name2, opts.ttl);
3527
3527
  const result = await task();
3528
3528
  return { executed: true, result };
3529
3529
  } catch (e) {
@@ -4037,8 +4037,8 @@ var init_ids = __esm({
4037
4037
  generateDevInfoID = (userId) => {
4038
4038
  return `${"devinfo" /* DEV_INFO */}${SEPARATOR}${userId}`;
4039
4039
  };
4040
- generatePluginID = (name) => {
4041
- return `${"plg" /* PLUGIN */}${SEPARATOR}${name}`;
4040
+ generatePluginID = (name2) => {
4041
+ return `${"plg" /* PLUGIN */}${SEPARATOR}${name2}`;
4042
4042
  };
4043
4043
  }
4044
4044
  });
@@ -4128,8 +4128,8 @@ var init_params = __esm({
4128
4128
  isDatasourceId = (id) => {
4129
4129
  return id && id.startsWith(`${"datasource" /* DATASOURCE */}${SEPARATOR}`);
4130
4130
  };
4131
- getPluginParams = (pluginId, otherProps = {}) => {
4132
- return getDocParams("plg" /* PLUGIN */, pluginId, otherProps);
4131
+ getPluginParams = (pluginId2, otherProps = {}) => {
4132
+ return getDocParams("plg" /* PLUGIN */, pluginId2, otherProps);
4133
4133
  };
4134
4134
  }
4135
4135
  });
@@ -4266,7 +4266,7 @@ function pagination(data2, pageSize, {
4266
4266
  const hasNextPage = data2.length > pageSize;
4267
4267
  let nextPage = void 0;
4268
4268
  if (!getKey) {
4269
- getKey = (doc) => property ? doc == null ? void 0 : doc[property] : doc == null ? void 0 : doc._id;
4269
+ getKey = (doc2) => property ? doc2 == null ? void 0 : doc2[property] : doc2 == null ? void 0 : doc2._id;
4270
4270
  }
4271
4271
  if (hasNextPage) {
4272
4272
  nextPage = getKey(data2[pageSize]);
@@ -4484,8 +4484,8 @@ var init_Replication = __esm({
4484
4484
  * @param {String} source - the DB you want to replicate or rollback to
4485
4485
  * @param {String} target - the DB you want to replicate to, or rollback from
4486
4486
  */
4487
- constructor({ source, target }) {
4488
- this.source = getPouchDB(source);
4487
+ constructor({ source: source2, target }) {
4488
+ this.source = getPouchDB(source2);
4489
4489
  this.target = getPouchDB(target);
4490
4490
  }
4491
4491
  close() {
@@ -4520,8 +4520,8 @@ var init_Replication = __esm({
4520
4520
  }
4521
4521
  appReplicateOpts() {
4522
4522
  return {
4523
- filter: (doc) => {
4524
- return doc._id !== "app_metadata" /* APP_METADATA */;
4523
+ filter: (doc2) => {
4524
+ return doc2._id !== "app_metadata" /* APP_METADATA */;
4525
4525
  }
4526
4526
  };
4527
4527
  }
@@ -4702,9 +4702,9 @@ var init_lucene = __esm({
4702
4702
  __privateSet(this, _indexBuilder, builderFn);
4703
4703
  return this;
4704
4704
  }
4705
- setVersion(version) {
4706
- if (version != null) {
4707
- __privateSet(this, _version, version);
4705
+ setVersion(version2) {
4706
+ if (version2 != null) {
4707
+ __privateSet(this, _version, version2);
4708
4708
  }
4709
4709
  return this;
4710
4710
  }
@@ -5288,36 +5288,36 @@ async function populateFromDB2(appId) {
5288
5288
  { skip_setup: true }
5289
5289
  );
5290
5290
  }
5291
- function isInvalid(metadata) {
5292
- return !metadata || metadata.state === AppState.INVALID;
5291
+ function isInvalid(metadata2) {
5292
+ return !metadata2 || metadata2.state === AppState.INVALID;
5293
5293
  }
5294
5294
  async function getAppMetadata(appId) {
5295
5295
  const client3 = await getAppClient();
5296
- let metadata = await client3.get(appId);
5297
- if (!metadata) {
5296
+ let metadata2 = await client3.get(appId);
5297
+ if (!metadata2) {
5298
5298
  let expiry = EXPIRY_SECONDS2;
5299
5299
  try {
5300
- metadata = await populateFromDB2(appId);
5300
+ metadata2 = await populateFromDB2(appId);
5301
5301
  } catch (err) {
5302
5302
  if (err && err.status === 404) {
5303
- metadata = { state: AppState.INVALID };
5303
+ metadata2 = { state: AppState.INVALID };
5304
5304
  expiry = void 0;
5305
5305
  } else {
5306
5306
  throw err;
5307
5307
  }
5308
5308
  }
5309
- if (isInvalid(metadata)) {
5309
+ if (isInvalid(metadata2)) {
5310
5310
  const temp = await client3.get(appId);
5311
5311
  if (temp) {
5312
- metadata = temp;
5312
+ metadata2 = temp;
5313
5313
  }
5314
5314
  }
5315
- await client3.store(appId, metadata, expiry);
5315
+ await client3.store(appId, metadata2, expiry);
5316
5316
  }
5317
- if (isInvalid(metadata)) {
5317
+ if (isInvalid(metadata2)) {
5318
5318
  throw { status: 404, message: "No app metadata found" };
5319
5319
  }
5320
- return metadata;
5320
+ return metadata2;
5321
5321
  }
5322
5322
  async function invalidateAppMetadata(appId, newMetadata) {
5323
5323
  if (!appId) {
@@ -5356,18 +5356,18 @@ async function getCache() {
5356
5356
  function makeCacheKey(db2, key) {
5357
5357
  return db2.name + key;
5358
5358
  }
5359
- function makeCacheItem(doc, lastWrite = null) {
5360
- return { doc, lastWrite: lastWrite || Date.now() };
5359
+ function makeCacheItem(doc2, lastWrite = null) {
5360
+ return { doc: doc2, lastWrite: lastWrite || Date.now() };
5361
5361
  }
5362
- async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5362
+ async function put(db2, doc2, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5363
5363
  const cache2 = await getCache();
5364
- const key = doc._id;
5364
+ const key = doc2._id;
5365
5365
  let cacheItem;
5366
5366
  if (key) {
5367
5367
  cacheItem = await cache2.get(makeCacheKey(db2, key));
5368
5368
  }
5369
5369
  const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs;
5370
- let output = doc;
5370
+ let output = doc2;
5371
5371
  if (updateDb) {
5372
5372
  const lockResponse = await doWithLock(
5373
5373
  {
@@ -5380,13 +5380,13 @@ async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5380
5380
  const writeDb = async (toWrite) => {
5381
5381
  const response2 = await db2.put(toWrite, { force: true });
5382
5382
  output = {
5383
- ...doc,
5383
+ ...doc2,
5384
5384
  _id: response2.id,
5385
5385
  _rev: response2.rev
5386
5386
  };
5387
5387
  };
5388
5388
  try {
5389
- await writeDb(doc);
5389
+ await writeDb(doc2);
5390
5390
  } catch (err) {
5391
5391
  if (err.status !== 409) {
5392
5392
  throw err;
@@ -5411,23 +5411,23 @@ async function get2(db2, id) {
5411
5411
  const cacheKey = makeCacheKey(db2, id);
5412
5412
  let cacheItem = await cache2.get(cacheKey);
5413
5413
  if (!cacheItem) {
5414
- const doc = await db2.get(id);
5415
- cacheItem = makeCacheItem(doc);
5414
+ const doc2 = await db2.get(id);
5415
+ cacheItem = makeCacheItem(doc2);
5416
5416
  await cache2.store(cacheKey, cacheItem);
5417
5417
  }
5418
5418
  return cacheItem.doc;
5419
5419
  }
5420
- async function remove(db2, docOrId, rev) {
5420
+ async function remove(db2, docOrId, rev2) {
5421
5421
  const cache2 = await getCache();
5422
5422
  if (!docOrId) {
5423
5423
  throw new Error("No ID/Rev provided.");
5424
5424
  }
5425
5425
  const id = typeof docOrId === "string" ? docOrId : docOrId._id;
5426
- rev = typeof docOrId === "string" ? rev : docOrId._rev;
5426
+ rev2 = typeof docOrId === "string" ? rev2 : docOrId._rev;
5427
5427
  try {
5428
5428
  await cache2.delete(makeCacheKey(db2, id));
5429
5429
  } finally {
5430
- await db2.remove(id, rev);
5430
+ await db2.remove(id, rev2);
5431
5431
  }
5432
5432
  }
5433
5433
  var DEFAULT_WRITE_RATE_MS, CACHE, Writethrough;
@@ -5445,14 +5445,14 @@ var init_writethrough = __esm({
5445
5445
  this.db = db2;
5446
5446
  this.writeRateMs = writeRateMs;
5447
5447
  }
5448
- async put(doc) {
5449
- return put(this.db, doc, this.writeRateMs);
5448
+ async put(doc2) {
5449
+ return put(this.db, doc2, this.writeRateMs);
5450
5450
  }
5451
5451
  async get(id) {
5452
5452
  return get2(this.db, id);
5453
5453
  }
5454
- async remove(docOrId, rev) {
5455
- return remove(this.db, docOrId, rev);
5454
+ async remove(docOrId, rev2) {
5455
+ return remove(this.db, docOrId, rev2);
5456
5456
  }
5457
5457
  };
5458
5458
  }
@@ -5951,7 +5951,7 @@ var init_LoggingProcessor = __esm({
5951
5951
  });
5952
5952
 
5953
5953
  // ../backend-core/src/utils/hashing.ts
5954
- async function hash(data2) {
5954
+ async function hash2(data2) {
5955
5955
  const salt = await bcrypt.genSalt(SALT_ROUNDS);
5956
5956
  return bcrypt.hash(data2, salt);
5957
5957
  }
@@ -6065,14 +6065,14 @@ function isValidInternalAPIKey(apiKey) {
6065
6065
  }
6066
6066
  return false;
6067
6067
  }
6068
- function getCookie(ctx, name) {
6069
- const cookie = ctx.cookies.get(name);
6068
+ function getCookie(ctx, name2) {
6069
+ const cookie = ctx.cookies.get(name2);
6070
6070
  if (!cookie) {
6071
6071
  return cookie;
6072
6072
  }
6073
6073
  return openJwt(cookie);
6074
6074
  }
6075
- function setCookie(ctx, value, name = "builder", opts = { sign: true }) {
6075
+ function setCookie(ctx, value, name2 = "builder", opts = { sign: true }) {
6076
6076
  if (value && opts && opts.sign) {
6077
6077
  value = jwt.sign(value, environment_default2.JWT_SECRET);
6078
6078
  }
@@ -6085,10 +6085,10 @@ function setCookie(ctx, value, name = "builder", opts = { sign: true }) {
6085
6085
  if (environment_default2.COOKIE_DOMAIN) {
6086
6086
  config.domain = environment_default2.COOKIE_DOMAIN;
6087
6087
  }
6088
- ctx.cookies.set(name, value, config);
6088
+ ctx.cookies.set(name2, value, config);
6089
6089
  }
6090
- function clearCookie(ctx, name) {
6091
- setCookie(ctx, null, name);
6090
+ function clearCookie(ctx, name2) {
6091
+ setCookie(ctx, null, name2);
6092
6092
  }
6093
6093
  function isClient(ctx) {
6094
6094
  return ctx.headers["x-budibase-type" /* TYPE */] === "client";
@@ -6136,7 +6136,7 @@ __export(utils_exports2, {
6136
6136
  compare: () => compare,
6137
6137
  getAppIdFromCtx: () => getAppIdFromCtx,
6138
6138
  getCookie: () => getCookie,
6139
- hash: () => hash,
6139
+ hash: () => hash2,
6140
6140
  isAudited: () => isAudited,
6141
6141
  isClient: () => isClient,
6142
6142
  isPublicApiRequest: () => isPublicApiRequest,
@@ -6179,8 +6179,8 @@ var init_inMemoryQueue = __esm({
6179
6179
  * @param {object|null} opts This is not used by the in memory queue as there is no real use
6180
6180
  * case when in memory, but is the same API as Bull
6181
6181
  */
6182
- constructor(name, opts = null) {
6183
- this._name = name;
6182
+ constructor(name2, opts = null) {
6183
+ this._name = name2;
6184
6184
  this._opts = opts;
6185
6185
  this._messages = [];
6186
6186
  this._emitter = new import_events2.default.EventEmitter();
@@ -6677,13 +6677,13 @@ var init_installation = __esm({
6677
6677
  }
6678
6678
  );
6679
6679
  };
6680
- updateVersion = async (version) => {
6680
+ updateVersion = async (version2) => {
6681
6681
  try {
6682
6682
  await doWithDB(
6683
6683
  StaticDatabases.PLATFORM_INFO.name,
6684
6684
  async (platformDb) => {
6685
6685
  const install = await getInstall();
6686
- install.version = version;
6686
+ install.version = version2;
6687
6687
  await platformDb.put(install);
6688
6688
  await bustCache("installation" /* INSTALLATION */);
6689
6689
  }
@@ -6799,13 +6799,13 @@ var init_identification2 = __esm({
6799
6799
  const id = installId;
6800
6800
  const type = "installation" /* INSTALLATION */;
6801
6801
  const hosting = getHostingFromEnv();
6802
- const version = environment_default2.VERSION;
6802
+ const version2 = environment_default2.VERSION;
6803
6803
  const environment3 = getDeploymentEnvironment();
6804
6804
  const group2 = {
6805
6805
  id,
6806
6806
  type,
6807
6807
  hosting,
6808
- version,
6808
+ version: version2,
6809
6809
  environment: environment3
6810
6810
  };
6811
6811
  await identifyGroup(group2, timestamp);
@@ -6985,10 +6985,10 @@ var init_backfill2 = __esm({
6985
6985
  init_generic();
6986
6986
  init_generic();
6987
6987
  start = async (events2) => {
6988
- const metadata = {
6988
+ const metadata2 = {
6989
6989
  eventWhitelist: events2
6990
6990
  };
6991
- return saveBackfillMetadata(metadata);
6991
+ return saveBackfillMetadata(metadata2);
6992
6992
  };
6993
6993
  recordEvent2 = async (event, properties) => {
6994
6994
  const eventKey2 = getEventKey(event, properties);
@@ -7338,11 +7338,11 @@ var init_app5 = __esm({
7338
7338
  });
7339
7339
 
7340
7340
  // ../backend-core/src/events/publishers/auth.ts
7341
- async function login(source, email) {
7341
+ async function login(source2, email) {
7342
7342
  const identity = await identification_default.getCurrentIdentity();
7343
7343
  const properties = {
7344
7344
  userId: identity.id,
7345
- source,
7345
+ source: source2,
7346
7346
  audited: {
7347
7347
  email
7348
7348
  }
@@ -8222,9 +8222,9 @@ var init_view3 = __esm({
8222
8222
  });
8223
8223
 
8224
8224
  // ../backend-core/src/events/publishers/installation.ts
8225
- async function versionChecked(version) {
8225
+ async function versionChecked(version2) {
8226
8226
  const properties = {
8227
- currentVersion: version
8227
+ currentVersion: version2
8228
8228
  };
8229
8229
  await publishEvent("installation:version:checked" /* INSTALLATION_VERSION_CHECKED */, properties);
8230
8230
  }
@@ -8467,13 +8467,13 @@ async function appBackupRestored(backup) {
8467
8467
  };
8468
8468
  await publishEvent("app:backup:restored" /* APP_BACKUP_RESTORED */, properties);
8469
8469
  }
8470
- async function appBackupTriggered(appId, backupId, type, trigger, name) {
8470
+ async function appBackupTriggered(appId, backupId, type, trigger, name2) {
8471
8471
  const properties = {
8472
8472
  appId,
8473
8473
  backupId,
8474
8474
  type,
8475
8475
  trigger,
8476
- name
8476
+ name: name2
8477
8477
  };
8478
8478
  await publishEvent("app:backup:triggered" /* APP_BACKUP_TRIGGERED */, properties);
8479
8479
  }
@@ -8490,16 +8490,16 @@ var init_backup4 = __esm({
8490
8490
  });
8491
8491
 
8492
8492
  // ../backend-core/src/events/publishers/environmentVariable.ts
8493
- async function created14(name, environments) {
8493
+ async function created14(name2, environments) {
8494
8494
  const properties = {
8495
- name,
8495
+ name: name2,
8496
8496
  environments
8497
8497
  };
8498
8498
  await publishEvent("environment_variable:created" /* ENVIRONMENT_VARIABLE_CREATED */, properties);
8499
8499
  }
8500
- async function deleted14(name) {
8500
+ async function deleted14(name2) {
8501
8501
  const properties = {
8502
- name
8502
+ name: name2
8503
8503
  };
8504
8504
  await publishEvent("environment_variable:deleted" /* ENVIRONMENT_VARIABLE_DELETED */, properties);
8505
8505
  }
@@ -8878,7 +8878,7 @@ var init_users4 = __esm({
8878
8878
  let userList, property = "_id", getKey;
8879
8879
  if (appId) {
8880
8880
  userList = await searchGlobalUsersByApp(appId, opts);
8881
- getKey = (doc) => getGlobalUserByAppPage(appId, doc);
8881
+ getKey = (doc2) => getGlobalUserByAppPage(appId, doc2);
8882
8882
  } else if (email) {
8883
8883
  userList = await searchGlobalUsersByEmail(email, opts);
8884
8884
  property = "email";
@@ -9183,10 +9183,10 @@ var init_roles = __esm({
9183
9183
  BUILTIN_IDS.PUBLIC
9184
9184
  ];
9185
9185
  Role2 = class {
9186
- constructor(id, name, permissionId) {
9186
+ constructor(id, name2, permissionId) {
9187
9187
  this.permissions = {};
9188
9188
  this._id = id;
9189
- this.name = name;
9189
+ this.name = name2;
9190
9190
  this.permissionId = permissionId;
9191
9191
  }
9192
9192
  addInheritance(inherits) {
@@ -9552,12 +9552,12 @@ async function syncUser(user, details) {
9552
9552
  if (details.profile) {
9553
9553
  const profile = details.profile;
9554
9554
  if (profile.name) {
9555
- const name = profile.name;
9556
- if (name.givenName) {
9557
- firstName = name.givenName;
9555
+ const name2 = profile.name;
9556
+ if (name2.givenName) {
9557
+ firstName = name2.givenName;
9558
9558
  }
9559
- if (name.familyName) {
9560
- lastName = name.familyName;
9559
+ if (name2.familyName) {
9560
+ lastName = name2.familyName;
9561
9561
  }
9562
9562
  }
9563
9563
  pictureUrl = await getProfilePictureUrl(user, details);
@@ -10073,7 +10073,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
10073
10073
  const noAuthOptions = noAuthPatterns ? buildMatcherRegex(noAuthPatterns) : [];
10074
10074
  return async (ctx, next) => {
10075
10075
  let publicEndpoint = false;
10076
- const version = ctx.request.headers["x-budibase-api-version" /* API_VER */];
10076
+ const version2 = ctx.request.headers["x-budibase-api-version" /* API_VER */];
10077
10077
  const found = matches(ctx, noAuthOptions);
10078
10078
  if (found) {
10079
10079
  publicEndpoint = true;
@@ -10136,7 +10136,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
10136
10136
  if (!authenticated) {
10137
10137
  authenticated = false;
10138
10138
  }
10139
- finalise(ctx, { authenticated, user, internal, version, publicEndpoint });
10139
+ finalise(ctx, { authenticated, user, internal, version: version2, publicEndpoint });
10140
10140
  if (user && user.email) {
10141
10141
  return doInUserContext(user, ctx, next);
10142
10142
  } else {
@@ -10151,7 +10151,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
10151
10151
  ctx.throw(403, err.message);
10152
10152
  }
10153
10153
  if (opts && opts.publicAllowed || publicEndpoint) {
10154
- finalise(ctx, { authenticated: false, version, publicEndpoint });
10154
+ finalise(ctx, { authenticated: false, version: version2, publicEndpoint });
10155
10155
  return next();
10156
10156
  } else {
10157
10157
  ctx.throw(err.status || 403, err);
@@ -10965,7 +10965,7 @@ var init_objectStore = __esm({
10965
10965
  filename,
10966
10966
  path: path2,
10967
10967
  type,
10968
- metadata
10968
+ metadata: metadata2
10969
10969
  }) => {
10970
10970
  const extension = filename.split(".").pop();
10971
10971
  const fileBytes = import_fs3.default.readFileSync(path2);
@@ -10981,13 +10981,13 @@ var init_objectStore = __esm({
10981
10981
  Body: fileBytes,
10982
10982
  ContentType: contentType
10983
10983
  };
10984
- if (metadata && typeof metadata === "object") {
10985
- for (let key of Object.keys(metadata)) {
10986
- if (!metadata[key] || typeof metadata[key] !== "string") {
10987
- delete metadata[key];
10984
+ if (metadata2 && typeof metadata2 === "object") {
10985
+ for (let key of Object.keys(metadata2)) {
10986
+ if (!metadata2[key] || typeof metadata2[key] !== "string") {
10987
+ delete metadata2[key];
10988
10988
  }
10989
10989
  }
10990
- config.Metadata = metadata;
10990
+ config.Metadata = metadata2;
10991
10991
  }
10992
10992
  return objectStore.upload(config).promise();
10993
10993
  };
@@ -11141,12 +11141,12 @@ var init_objectStore = __esm({
11141
11141
  return deleteFolder(bucketName, folder);
11142
11142
  }
11143
11143
  };
11144
- uploadDirectory = async (bucketName, localPath, bucketPath) => {
11144
+ uploadDirectory = async (bucketName, localPath, bucketPath2) => {
11145
11145
  bucketName = sanitizeBucket(bucketName);
11146
11146
  let uploads = [];
11147
- const files = import_fs3.default.readdirSync(localPath, { withFileTypes: true });
11148
- for (let file of files) {
11149
- const path2 = sanitizeKey((0, import_path3.join)(bucketPath, file.name));
11147
+ const files2 = import_fs3.default.readdirSync(localPath, { withFileTypes: true });
11148
+ for (let file of files2) {
11149
+ const path2 = sanitizeKey((0, import_path3.join)(bucketPath2, file.name));
11150
11150
  const local = (0, import_path3.join)(localPath, file.name);
11151
11151
  if (file.isDirectory()) {
11152
11152
  uploads.push(uploadDirectory(bucketName, local, path2));
@@ -11155,7 +11155,7 @@ var init_objectStore = __esm({
11155
11155
  }
11156
11156
  }
11157
11157
  await Promise.all(uploads);
11158
- return files;
11158
+ return files2;
11159
11159
  };
11160
11160
  downloadTarballDirect = async (url, path2, headers = {}) => {
11161
11161
  path2 = sanitizeKey(path2);
@@ -11229,12 +11229,12 @@ var init_app6 = __esm({
11229
11229
  init_environment3();
11230
11230
  init_objectStore();
11231
11231
  init_cloudfront();
11232
- clientLibraryUrl = (appId, version) => {
11232
+ clientLibraryUrl = (appId, version2) => {
11233
11233
  if (environment_default2.isProd()) {
11234
11234
  let file = `${sanitizeKey(appId)}/budibase-client.js`;
11235
11235
  if (environment_default2.CLOUDFRONT_CDN) {
11236
- if (version) {
11237
- file += `?v=${version}`;
11236
+ if (version2) {
11237
+ file += `?v=${version2}`;
11238
11238
  }
11239
11239
  return getUrl(file);
11240
11240
  } else {
@@ -11262,8 +11262,8 @@ var init_global3 = __esm({
11262
11262
  init_context2();
11263
11263
  init_objectStore();
11264
11264
  init_cloudfront();
11265
- getGlobalFileUrl = (type, name, etag) => {
11266
- let file = getGlobalFileS3Key(type, name);
11265
+ getGlobalFileUrl = (type, name2, etag) => {
11266
+ let file = getGlobalFileS3Key(type, name2);
11267
11267
  if (environment_default2.CLOUDFRONT_CDN) {
11268
11268
  if (etag) {
11269
11269
  file = `${file}?etag=${etag}`;
@@ -11273,8 +11273,8 @@ var init_global3 = __esm({
11273
11273
  return getPresignedUrl(environment_default2.GLOBAL_BUCKET_NAME, file);
11274
11274
  }
11275
11275
  };
11276
- getGlobalFileS3Key = (type, name) => {
11277
- let file = `${type}/${name}`;
11276
+ getGlobalFileS3Key = (type, name2) => {
11277
+ let file = `${type}/${name2}`;
11278
11278
  if (environment_default2.MULTI_TENANCY) {
11279
11279
  const tenantId = getTenantId();
11280
11280
  file = `${tenantId}/${file}`;
@@ -11324,11 +11324,11 @@ var init_plugins = __esm({
11324
11324
  return getPluginS3Key(plugin, "plugin.min.js");
11325
11325
  };
11326
11326
  getPluginIconKey = (plugin) => {
11327
- const iconFileName = plugin.iconUrl ? "icon.svg" : plugin.iconFileName;
11328
- if (!iconFileName) {
11327
+ const iconFileName2 = plugin.iconUrl ? "icon.svg" : plugin.iconFileName;
11328
+ if (!iconFileName2) {
11329
11329
  return;
11330
11330
  }
11331
- return getPluginS3Key(plugin, iconFileName);
11331
+ return getPluginS3Key(plugin, iconFileName2);
11332
11332
  };
11333
11333
  getPluginS3Key = (plugin, fileName) => {
11334
11334
  const s3Key = getPluginS3Dir(plugin.name);
@@ -11759,11 +11759,11 @@ var init_utils9 = __esm({
11759
11759
  }
11760
11760
  usage.monthly.current = usage.monthly[currentMonth];
11761
11761
  };
11762
- getBreakdownName = (name, id) => {
11763
- if (!id || !name) {
11762
+ getBreakdownName = (name2, id) => {
11763
+ if (!id || !name2) {
11764
11764
  return;
11765
11765
  }
11766
- switch (name) {
11766
+ switch (name2) {
11767
11767
  case "automations" /* AUTOMATIONS */:
11768
11768
  return "automations" /* AUTOMATIONS */;
11769
11769
  case "queries" /* QUERIES */:
@@ -11825,17 +11825,17 @@ var init_quotas2 = __esm({
11825
11825
  delete usage.usageQuota.developers;
11826
11826
  return usage;
11827
11827
  };
11828
- setUsage = async (value, name, type) => {
11829
- return setAllUsage(name, type, { total: value });
11828
+ setUsage = async (value, name2, type) => {
11829
+ return setAllUsage(name2, type, { total: value });
11830
11830
  };
11831
- setUsagePerApp = async (appValues, name, type) => {
11831
+ setUsagePerApp = async (appValues, name2, type) => {
11832
11832
  const db2 = getDB2();
11833
11833
  let quotaUsage = await getQuotaUsage();
11834
11834
  const total = Object.values(appValues).reduce((sum, num) => sum + num, 0);
11835
11835
  for (let [appId, value] of Object.entries(appValues)) {
11836
11836
  quotaUsage = coreUsageUpdate(
11837
11837
  quotaUsage,
11838
- name,
11838
+ name2,
11839
11839
  type,
11840
11840
  {
11841
11841
  total,
@@ -11850,8 +11850,8 @@ var init_quotas2 = __esm({
11850
11850
  quotaUsage._rev = response2.rev;
11851
11851
  return quotaUsage;
11852
11852
  };
11853
- setBreakdown = (monthUsage, name, id, values) => {
11854
- const breakdownName = getBreakdownName(name, id);
11853
+ setBreakdown = (monthUsage, name2, id, values) => {
11854
+ const breakdownName = getBreakdownName(name2, id);
11855
11855
  if (!breakdownName || !(values == null ? void 0 : values.breakdown)) {
11856
11856
  return monthUsage;
11857
11857
  }
@@ -11860,7 +11860,7 @@ var init_quotas2 = __esm({
11860
11860
  }
11861
11861
  if (!monthUsage.breakdown[breakdownName]) {
11862
11862
  monthUsage.breakdown[breakdownName] = {
11863
- parent: name,
11863
+ parent: name2,
11864
11864
  values: {}
11865
11865
  };
11866
11866
  }
@@ -11868,14 +11868,14 @@ var init_quotas2 = __esm({
11868
11868
  breakdown.values[id] = values.breakdown;
11869
11869
  return monthUsage;
11870
11870
  };
11871
- setAppUsageValue = (quotaUsage, name, type, opts = {}, values) => {
11871
+ setAppUsageValue = (quotaUsage, name2, type, opts = {}, values) => {
11872
11872
  var _a;
11873
11873
  let appId;
11874
11874
  try {
11875
11875
  appId = db_exports.getProdAppID((opts == null ? void 0 : opts.appId) || context_exports.getAppId());
11876
11876
  } catch (err) {
11877
11877
  }
11878
- if (!appId || !values.app || !APP_QUOTA_NAMES.includes(name)) {
11878
+ if (!appId || !values.app || !APP_QUOTA_NAMES.includes(name2)) {
11879
11879
  return quotaUsage;
11880
11880
  }
11881
11881
  if (!((_a = quotaUsage.apps) == null ? void 0 : _a[appId])) {
@@ -11887,11 +11887,11 @@ var init_quotas2 = __esm({
11887
11887
  const appUsage = quotaUsage.apps[appId];
11888
11888
  switch (type) {
11889
11889
  case "static" /* STATIC */:
11890
- appUsage.usageQuota[name] = values.app;
11890
+ appUsage.usageQuota[name2] = values.app;
11891
11891
  break;
11892
11892
  case "monthly" /* MONTHLY */:
11893
11893
  const currentMonth = getCurrentMonthString();
11894
- const monthlyName = name;
11894
+ const monthlyName = name2;
11895
11895
  let monthUsage = appUsage.monthly[currentMonth];
11896
11896
  if (!monthUsage) {
11897
11897
  appUsage.monthly[currentMonth] = generateNewMonthlyQuotas();
@@ -11905,9 +11905,9 @@ var init_quotas2 = __esm({
11905
11905
  }
11906
11906
  return quotaUsage;
11907
11907
  };
11908
- getAppUsageValue = (quotaUsage, type, name, id) => {
11908
+ getAppUsageValue = (quotaUsage, type, name2, id) => {
11909
11909
  var _a, _b, _c, _d, _e;
11910
- if (!APP_QUOTA_NAMES.includes(name)) {
11910
+ if (!APP_QUOTA_NAMES.includes(name2)) {
11911
11911
  return {};
11912
11912
  }
11913
11913
  let appId;
@@ -11921,13 +11921,13 @@ var init_quotas2 = __esm({
11921
11921
  const appUsage = quotaUsage.apps[appId];
11922
11922
  switch (type) {
11923
11923
  case "static" /* STATIC */:
11924
- if ((_a = appUsage.usageQuota) == null ? void 0 : _a[name]) {
11925
- return { app: appUsage.usageQuota[name] };
11924
+ if ((_a = appUsage.usageQuota) == null ? void 0 : _a[name2]) {
11925
+ return { app: appUsage.usageQuota[name2] };
11926
11926
  }
11927
11927
  break;
11928
11928
  case "monthly" /* MONTHLY */:
11929
11929
  const currentMonth = getCurrentMonthString();
11930
- const monthlyName = name;
11930
+ const monthlyName = name2;
11931
11931
  if (!((_c = (_b = appUsage.monthly) == null ? void 0 : _b[currentMonth]) == null ? void 0 : _c[monthlyName])) {
11932
11932
  break;
11933
11933
  }
@@ -11942,68 +11942,68 @@ var init_quotas2 = __esm({
11942
11942
  }
11943
11943
  return { app: 0 };
11944
11944
  };
11945
- setStaticTriggers = (name, quotaUsage, triggers) => {
11945
+ setStaticTriggers = (name2, quotaUsage, triggers) => {
11946
11946
  if (!quotaUsage.usageQuota.triggers) {
11947
11947
  quotaUsage.usageQuota.triggers = {};
11948
11948
  }
11949
11949
  if (triggers) {
11950
- quotaUsage.usageQuota.triggers[name] = triggers;
11950
+ quotaUsage.usageQuota.triggers[name2] = triggers;
11951
11951
  }
11952
11952
  };
11953
- setMonthlyTriggers = (name, currentMonth, quotaUsage, triggers) => {
11953
+ setMonthlyTriggers = (name2, currentMonth, quotaUsage, triggers) => {
11954
11954
  if (!quotaUsage.monthly[currentMonth].triggers) {
11955
11955
  quotaUsage.monthly[currentMonth].triggers = {};
11956
11956
  }
11957
11957
  if (triggers) {
11958
- quotaUsage.monthly[currentMonth].triggers[name] = triggers;
11958
+ quotaUsage.monthly[currentMonth].triggers[name2] = triggers;
11959
11959
  }
11960
11960
  };
11961
- coreUsageUpdate = (quotaUsage, name, type, values, opts = {}) => {
11961
+ coreUsageUpdate = (quotaUsage, name2, type, values, opts = {}) => {
11962
11962
  if (type === "static" /* STATIC */) {
11963
- name = name;
11964
- quotaUsage.usageQuota[name] = values.total;
11965
- setStaticTriggers(name, quotaUsage, values.triggers);
11963
+ name2 = name2;
11964
+ quotaUsage.usageQuota[name2] = values.total;
11965
+ setStaticTriggers(name2, quotaUsage, values.triggers);
11966
11966
  } else if (type === "monthly" /* MONTHLY */) {
11967
- name = name;
11967
+ name2 = name2;
11968
11968
  const currentMonth = getCurrentMonthString();
11969
- quotaUsage.monthly[currentMonth][name] = values.total;
11970
- setMonthlyTriggers(name, currentMonth, quotaUsage, values.triggers);
11969
+ quotaUsage.monthly[currentMonth][name2] = values.total;
11970
+ setMonthlyTriggers(name2, currentMonth, quotaUsage, values.triggers);
11971
11971
  } else {
11972
11972
  throw new Error(`Invalid usage type: ${type}`);
11973
11973
  }
11974
- return setAppUsageValue(quotaUsage, name, type, opts, values);
11974
+ return setAppUsageValue(quotaUsage, name2, type, opts, values);
11975
11975
  };
11976
- setAllUsage = async (name, type, values, opts = {}) => {
11976
+ setAllUsage = async (name2, type, values, opts = {}) => {
11977
11977
  const db2 = getDB2();
11978
11978
  let quotaUsage = await getQuotaUsage();
11979
- quotaUsage = coreUsageUpdate(quotaUsage, name, type, values, opts);
11979
+ quotaUsage = coreUsageUpdate(quotaUsage, name2, type, values, opts);
11980
11980
  const response2 = await db2.put(quotaUsage);
11981
11981
  quotaUsage._rev = response2.rev;
11982
11982
  return quotaUsage;
11983
11983
  };
11984
- getCurrentUsageValues = async (type, name, id) => {
11984
+ getCurrentUsageValues = async (type, name2, id) => {
11985
11985
  const quotaUsage = await getQuotaUsage();
11986
11986
  let total = 0, appValues = {};
11987
11987
  switch (type) {
11988
11988
  case "static" /* STATIC */:
11989
- if (quotaUsage.usageQuota[name]) {
11990
- const staticName = name;
11989
+ if (quotaUsage.usageQuota[name2]) {
11990
+ const staticName = name2;
11991
11991
  total = quotaUsage.usageQuota[staticName];
11992
- appValues = getAppUsageValue(quotaUsage, type, name, id);
11992
+ appValues = getAppUsageValue(quotaUsage, type, name2, id);
11993
11993
  }
11994
11994
  break;
11995
11995
  case "monthly" /* MONTHLY */:
11996
11996
  const currentMonth = getCurrentMonthString();
11997
- const monthlyName = name;
11997
+ const monthlyName = name2;
11998
11998
  if (quotaUsage.monthly[currentMonth][monthlyName]) {
11999
11999
  total = quotaUsage.monthly[currentMonth][monthlyName];
12000
- appValues = getAppUsageValue(quotaUsage, type, name, id);
12000
+ appValues = getAppUsageValue(quotaUsage, type, name2, id);
12001
12001
  }
12002
12002
  break;
12003
12003
  default:
12004
12004
  throw new Error(`Invalid usage type: ${type}`);
12005
12005
  }
12006
- if (APP_QUOTA_NAMES.includes(name) && !(appValues.app || appValues.breakdown)) {
12006
+ if (APP_QUOTA_NAMES.includes(name2) && !(appValues.app || appValues.breakdown)) {
12007
12007
  appValues.app = appValues.app || 0;
12008
12008
  appValues.breakdown = appValues.breakdown || 0;
12009
12009
  }
@@ -12225,9 +12225,9 @@ async function getGroupUsers(groupId, params2) {
12225
12225
  createGroupUserLookupView,
12226
12226
  { arrayResponse: true }
12227
12227
  );
12228
- const users2 = userDocs.map((doc) => ({
12229
- _id: doc.userId,
12230
- email: doc.email
12228
+ const users2 = userDocs.map((doc2) => ({
12229
+ _id: doc2.userId,
12230
+ email: doc2.email
12231
12231
  })) || [];
12232
12232
  return users2;
12233
12233
  }
@@ -12316,12 +12316,12 @@ async function destroy3(groupId, revision) {
12316
12316
  await cleanupUsers(group2);
12317
12317
  return resp;
12318
12318
  }
12319
- async function getByName(name) {
12319
+ async function getByName(name2) {
12320
12320
  try {
12321
12321
  const groups = await db_exports.directCouchFind(tenancy.getGlobalDBName(), {
12322
12322
  selector: {
12323
12323
  name: {
12324
- $regex: `^(?i)${name}$`
12324
+ $regex: `^(?i)${name2}$`
12325
12325
  }
12326
12326
  },
12327
12327
  limit: 1
@@ -12648,11 +12648,11 @@ var init_version2 = __esm({
12648
12648
  }
12649
12649
  };
12650
12650
  getProVersion = () => {
12651
- const version = environment_default2.VERSION;
12652
- if (!version) {
12651
+ const version2 = environment_default2.VERSION;
12652
+ if (!version2) {
12653
12653
  throw new Error("No budibase pro version was specified");
12654
12654
  }
12655
- return version;
12655
+ return version2;
12656
12656
  };
12657
12657
  }
12658
12658
  });
@@ -12796,15 +12796,15 @@ async function fetchAppBackups(appId, opts = {}) {
12796
12796
  }
12797
12797
  return pageData;
12798
12798
  }
12799
- async function storeAppBackupMetadata(metadata, opts = {}) {
12799
+ async function storeAppBackupMetadata(metadata2, opts = {}) {
12800
12800
  const db2 = tenancy.getGlobalDB();
12801
- const prodAppId = db_exports.getProdAppID(metadata.appId);
12802
- let _id = generateAppBackupID(prodAppId, metadata.timestamp);
12801
+ const prodAppId = db_exports.getProdAppID(metadata2.appId);
12802
+ let _id = generateAppBackupID(prodAppId, metadata2.timestamp);
12803
12803
  const appBackupDoc = {
12804
- ...metadata,
12804
+ ...metadata2,
12805
12805
  _id,
12806
12806
  appId: prodAppId,
12807
- name: metadata.name
12807
+ name: metadata2.name
12808
12808
  };
12809
12809
  if (opts.filename) {
12810
12810
  appBackupDoc.filename = opts.filename;
@@ -12813,18 +12813,18 @@ async function storeAppBackupMetadata(metadata, opts = {}) {
12813
12813
  appBackupDoc._id = opts.docId;
12814
12814
  appBackupDoc._rev = opts.docRev;
12815
12815
  }
12816
- if (metadata.createdBy) {
12816
+ if (metadata2.createdBy) {
12817
12817
  appBackupDoc.createdBy = db_exports.getGlobalIDFromUserMetadataID(
12818
- metadata.createdBy
12818
+ metadata2.createdBy
12819
12819
  );
12820
12820
  }
12821
12821
  return await db2.put(appBackupDoc);
12822
12822
  }
12823
- async function updateAppBackupMetadata(backupId, name) {
12823
+ async function updateAppBackupMetadata(backupId, name2) {
12824
12824
  const db2 = tenancy.getGlobalDB();
12825
- const metadata = await db2.get(backupId);
12826
- metadata.name = name;
12827
- return await db2.put(metadata);
12825
+ const metadata2 = await db2.get(backupId);
12826
+ metadata2.name = name2;
12827
+ return await db2.put(metadata2);
12828
12828
  }
12829
12829
  async function deleteAppBackupMetadata(backupId) {
12830
12830
  const db2 = tenancy.getGlobalDB();
@@ -12859,9 +12859,9 @@ __export(environmentVariables_exports, {
12859
12859
  function getEnvVarID() {
12860
12860
  return StaticDatabases.GLOBAL.docs.environmentVariables;
12861
12861
  }
12862
- function getCacheEnvVarID(rev) {
12862
+ function getCacheEnvVarID(rev2) {
12863
12863
  const tenantId = tenancy.getTenantId();
12864
- return `${tenantId}/${getEnvVarID()}/${rev || ""}`;
12864
+ return `${tenantId}/${getEnvVarID()}/${rev2 || ""}`;
12865
12865
  }
12866
12866
  async function get5() {
12867
12867
  const id = getEnvVarID();
@@ -12901,14 +12901,14 @@ async function get5() {
12901
12901
  cache.set(cacheKey, finalDoc);
12902
12902
  return finalDoc;
12903
12903
  }
12904
- async function update(doc) {
12904
+ async function update(doc2) {
12905
12905
  const id = getEnvVarID();
12906
12906
  const db2 = tenancy.getGlobalDB();
12907
12907
  return await db2.put({
12908
- _id: doc._id || id,
12909
- _rev: doc._rev || void 0,
12908
+ _id: doc2._id || id,
12909
+ _rev: doc2._rev || void 0,
12910
12910
  variables: encryption_exports.encrypt(
12911
- JSON.stringify(doc.variables),
12911
+ JSON.stringify(doc2.variables),
12912
12912
  encryption_exports.SecretOption.ENCRYPTION
12913
12913
  )
12914
12914
  });
@@ -13391,14 +13391,14 @@ var init_quotas5 = __esm({
13391
13391
  init_db6();
13392
13392
  init_src2();
13393
13393
  init_quotas3();
13394
- increment = (name, type, opts) => {
13395
- return tryIncrement(1, name, type, opts);
13394
+ increment = (name2, type, opts) => {
13395
+ return tryIncrement(1, name2, type, opts);
13396
13396
  };
13397
- incrementMany = (change, name, type, opts) => {
13398
- return tryIncrement(change, name, type, opts);
13397
+ incrementMany = (change, name2, type, opts) => {
13398
+ return tryIncrement(change, name2, type, opts);
13399
13399
  };
13400
- tryIncrement = async (change, name, type, opts = {}) => {
13401
- await updateUsage(change, name, type, {
13400
+ tryIncrement = async (change, name2, type, opts = {}) => {
13401
+ await updateUsage(change, name2, type, {
13402
13402
  dryRun: true,
13403
13403
  suppressErrorLog: opts.suppressErrorLog,
13404
13404
  id: opts.id
@@ -13407,7 +13407,7 @@ var init_quotas5 = __esm({
13407
13407
  if (opts.fn) {
13408
13408
  result = await opts.fn();
13409
13409
  }
13410
- await updateUsage(change, name, type, {
13410
+ await updateUsage(change, name2, type, {
13411
13411
  dryRun: false,
13412
13412
  valueFn: opts.valueFn,
13413
13413
  suppressErrorLog: opts.suppressErrorLog,
@@ -13415,32 +13415,32 @@ var init_quotas5 = __esm({
13415
13415
  });
13416
13416
  return result;
13417
13417
  };
13418
- decrement = (name, type, opts = {}) => {
13419
- return updateUsage(-1, name, type, opts);
13418
+ decrement = (name2, type, opts = {}) => {
13419
+ return updateUsage(-1, name2, type, opts);
13420
13420
  };
13421
- decrementMany = (change, name, type, opts = {}) => {
13422
- return updateUsage(-change, name, type, opts);
13421
+ decrementMany = (change, name2, type, opts = {}) => {
13422
+ return updateUsage(-change, name2, type, opts);
13423
13423
  };
13424
- set2 = async (name, type, value) => {
13425
- return quotas_exports.setUsage(value, name, type);
13424
+ set2 = async (name2, type, value) => {
13425
+ return quotas_exports.setUsage(value, name2, type);
13426
13426
  };
13427
- getExistingTriggers = (type, name, quotaUsage) => {
13427
+ getExistingTriggers = (type, name2, quotaUsage) => {
13428
13428
  if (type == "static" /* STATIC */) {
13429
13429
  const triggers = quotaUsage.usageQuota.triggers;
13430
- return triggers ? triggers[name] || {} : {};
13430
+ return triggers ? triggers[name2] || {} : {};
13431
13431
  } else {
13432
13432
  const currentMonthString = quotas_exports.utils.getCurrentMonthString();
13433
13433
  const triggers = quotaUsage.monthly[currentMonthString].triggers;
13434
- return triggers ? triggers[name] || {} : {};
13434
+ return triggers ? triggers[name2] || {} : {};
13435
13435
  }
13436
13436
  };
13437
- triggerQuota2 = async (name, quota, percentage, resetDate) => {
13437
+ triggerQuota2 = async (name2, quota, percentage, resetDate) => {
13438
13438
  try {
13439
13439
  await redlockImpl_exports.doWithLock(
13440
13440
  {
13441
13441
  type: "try_once" /* TRY_ONCE */,
13442
13442
  name: "trigger_quota" /* TRIGGER_QUOTA */,
13443
- resource: name,
13443
+ resource: name2,
13444
13444
  // use the quota name for extra uniqueness on the lock
13445
13445
  ttl: 1e4
13446
13446
  // auto expire after 10 seconds
@@ -13460,10 +13460,10 @@ var init_quotas5 = __esm({
13460
13460
  logging_exports.logAlert("Error triggering quota", e);
13461
13461
  }
13462
13462
  };
13463
- checkTriggers = async (type, name, totalValue, quota) => {
13463
+ checkTriggers = async (type, name2, totalValue, quota) => {
13464
13464
  const usage = await getQuotaUsage();
13465
13465
  const resetDate = type === "monthly" /* MONTHLY */ ? usage.quotaReset : void 0;
13466
- const triggers = await getExistingTriggers(type, name, usage);
13466
+ const triggers = await getExistingTriggers(type, name2, usage);
13467
13467
  const quotaTriggers = quota.triggers;
13468
13468
  let percentage = totalValue / quota.value * 100;
13469
13469
  if (percentage > 100) {
@@ -13479,7 +13479,7 @@ var init_quotas5 = __esm({
13479
13479
  const isAtTrigger = percentage === triggerPercentage;
13480
13480
  const sendNotification = !nextIsTriggered || isAtTrigger;
13481
13481
  if (sendNotification) {
13482
- await triggerQuota2(name, quota, percentage, resetDate);
13482
+ await triggerQuota2(name2, quota, percentage, resetDate);
13483
13483
  }
13484
13484
  }
13485
13485
  } else {
@@ -13488,23 +13488,23 @@ var init_quotas5 = __esm({
13488
13488
  }
13489
13489
  return triggers;
13490
13490
  };
13491
- updateUsage = async (usageChange, name, type, opts = {}) => {
13491
+ updateUsage = async (usageChange, name2, type, opts = {}) => {
13492
13492
  let appId = null;
13493
13493
  try {
13494
13494
  appId = context_exports.getAppId();
13495
13495
  } catch (err) {
13496
13496
  }
13497
- const isAppQuota = APP_QUOTA_NAMES.includes(name);
13497
+ const isAppQuota = APP_QUOTA_NAMES.includes(name2);
13498
13498
  if (isAppQuota && !appId) {
13499
13499
  throw new Error("App context required for quota update");
13500
13500
  }
13501
13501
  try {
13502
- const licensedQuota = await getLicensedQuota("usage" /* USAGE */, name, type);
13502
+ const licensedQuota = await getLicensedQuota("usage" /* USAGE */, name2, type);
13503
13503
  let {
13504
13504
  total: totalValue,
13505
13505
  app: appValue,
13506
13506
  breakdown: breakdownValue
13507
- } = await quotas_exports.getCurrentUsageValues(type, name, opts.id);
13507
+ } = await quotas_exports.getCurrentUsageValues(type, name2, opts.id);
13508
13508
  totalValue += usageChange;
13509
13509
  if (appValue != null) {
13510
13510
  appValue += usageChange;
@@ -13514,7 +13514,7 @@ var init_quotas5 = __esm({
13514
13514
  }
13515
13515
  let triggers = {};
13516
13516
  if (!opts.dryRun) {
13517
- triggers = await checkTriggers(type, name, totalValue, licensedQuota);
13517
+ triggers = await checkTriggers(type, name2, totalValue, licensedQuota);
13518
13518
  }
13519
13519
  if (licensedQuota.value !== quotas_exports2.UNLIMITED && totalValue > licensedQuota.value && usageChange > 0) {
13520
13520
  throw new UsageLimitError(
@@ -13537,7 +13537,7 @@ var init_quotas5 = __esm({
13537
13537
  appValue = totalValue;
13538
13538
  }
13539
13539
  await quotas_exports.setAllUsage(
13540
- name,
13540
+ name2,
13541
13541
  type,
13542
13542
  {
13543
13543
  total: totalValue,
@@ -13549,30 +13549,30 @@ var init_quotas5 = __esm({
13549
13549
  );
13550
13550
  } catch (err) {
13551
13551
  if (!opts.suppressErrorLog) {
13552
- console.error(`Error updating usage quotas for ${name}`, err);
13552
+ console.error(`Error updating usage quotas for ${name2}`, err);
13553
13553
  }
13554
13554
  throw err;
13555
13555
  }
13556
13556
  };
13557
- getLicensedQuota = async (quotaType, name, usageType) => {
13557
+ getLicensedQuota = async (quotaType, name2, usageType) => {
13558
13558
  const license = await cache_exports2.getCachedLicense();
13559
13559
  if (!license) {
13560
13560
  const tenantId = tenancy.getTenantId();
13561
13561
  throw new Error("License not found for tenant id " + tenantId);
13562
13562
  }
13563
- if (usageType && isStaticQuota(quotaType, usageType, name)) {
13564
- return license.quotas[quotaType][usageType][name];
13565
- } else if (usageType && isMonthlyQuota(quotaType, usageType, name)) {
13566
- return license.quotas[quotaType][usageType][name];
13567
- } else if (isConstantQuota(quotaType, name)) {
13568
- return license.quotas[quotaType][name];
13563
+ if (usageType && isStaticQuota(quotaType, usageType, name2)) {
13564
+ return license.quotas[quotaType][usageType][name2];
13565
+ } else if (usageType && isMonthlyQuota(quotaType, usageType, name2)) {
13566
+ return license.quotas[quotaType][usageType][name2];
13567
+ } else if (isConstantQuota(quotaType, name2)) {
13568
+ return license.quotas[quotaType][name2];
13569
13569
  } else {
13570
13570
  throw new Error("Invalid quota type");
13571
13571
  }
13572
13572
  };
13573
- usageLimitIsExceeded = async (name, type) => {
13573
+ usageLimitIsExceeded = async (name2, type) => {
13574
13574
  try {
13575
- await updateUsage(1, name, type, { dryRun: true });
13575
+ await updateUsage(1, name2, type, { dryRun: true });
13576
13576
  return false;
13577
13577
  } catch (e) {
13578
13578
  if (e.code === "usage_limit_exceeded" /* USAGE_LIMIT_EXCEEDED */) {
@@ -14111,7 +14111,7 @@ async function getLogsByView(startDate, endDate, viewParams = {}) {
14111
14111
  async function writeLog(automation, results) {
14112
14112
  const db2 = context_exports.getProdAppDB();
14113
14113
  const automationId = automation._id;
14114
- const name = automation.name;
14114
+ const name2 = automation.name;
14115
14115
  const status2 = getStatus(results);
14116
14116
  const isoDate = (/* @__PURE__ */ new Date()).toISOString();
14117
14117
  const id = generateAutomationLogID(isoDate, status2, automationId);
@@ -14120,7 +14120,7 @@ async function writeLog(automation, results) {
14120
14120
  ...results,
14121
14121
  automationId,
14122
14122
  status: status2,
14123
- automationName: name,
14123
+ automationName: name2,
14124
14124
  createdAt: isoDate,
14125
14125
  _id: id
14126
14126
  };
@@ -14130,13 +14130,13 @@ async function writeLog(automation, results) {
14130
14130
  async function updateAppMetadataWithErrors(logIds, { clearing } = { clearing: false }) {
14131
14131
  const db2 = context_exports.getProdAppDB();
14132
14132
  await backOff(async () => {
14133
- const metadata = await db2.get(db_exports.DocumentType.APP_METADATA);
14133
+ const metadata2 = await db2.get(db_exports.DocumentType.APP_METADATA);
14134
14134
  for (let logId of logIds) {
14135
14135
  const parts = logId.split(db_exports.SEPARATOR);
14136
14136
  const autoId = `${parts[parts.length - 3]}${db_exports.SEPARATOR}${parts[parts.length - 2]}`;
14137
14137
  let errors = {};
14138
- if (metadata.automationErrors) {
14139
- errors = metadata.automationErrors;
14138
+ if (metadata2.automationErrors) {
14139
+ errors = metadata2.automationErrors;
14140
14140
  }
14141
14141
  if (!Array.isArray(errors[autoId])) {
14142
14142
  errors[autoId] = [];
@@ -14150,10 +14150,10 @@ async function updateAppMetadataWithErrors(logIds, { clearing } = { clearing: fa
14150
14150
  if (errors[autoId].length === 0) {
14151
14151
  delete errors[autoId];
14152
14152
  }
14153
- metadata.automationErrors = errors;
14153
+ metadata2.automationErrors = errors;
14154
14154
  }
14155
- await db2.put(metadata);
14156
- await cache_exports.app.invalidateAppMetadata(metadata.appId, metadata);
14155
+ await db2.put(metadata2);
14156
+ await cache_exports.app.invalidateAppMetadata(metadata2.appId, metadata2);
14157
14157
  }, "Failed to update app metadata with automation log error");
14158
14158
  }
14159
14159
  async function getExpiredLogs() {
@@ -14175,16 +14175,16 @@ async function clearOldHistory() {
14175
14175
  if (!expired.data || expired.data.length === 0) {
14176
14176
  return;
14177
14177
  }
14178
- const toDelete = expired.data.map((doc) => ({
14179
- _id: doc.id,
14180
- _rev: doc.value.rev,
14178
+ const toDelete = expired.data.map((doc2) => ({
14179
+ _id: doc2.id,
14180
+ _rev: doc2.value.rev,
14181
14181
  _deleted: true
14182
14182
  }));
14183
- const errorLogIds = expired.data.filter((doc) => {
14184
- const parts = doc.id.split(db_exports.SEPARATOR);
14183
+ const errorLogIds = expired.data.filter((doc2) => {
14184
+ const parts = doc2.id.split(db_exports.SEPARATOR);
14185
14185
  const status2 = parts[parts.length - 1];
14186
14186
  return status2 === "error" /* ERROR */;
14187
- }).map((doc) => doc.id);
14187
+ }).map((doc2) => doc2.id);
14188
14188
  await db2.bulkDocs(toDelete);
14189
14189
  if (errorLogIds.length) {
14190
14190
  await updateAppMetadataWithErrors(errorLogIds, { clearing: true });
@@ -14404,10 +14404,10 @@ async function get6(id) {
14404
14404
  async function getBulk2(ids, opts = { enriched: true }) {
14405
14405
  return await groups_exports.getBulk(ids, opts);
14406
14406
  }
14407
- async function guardNameAvailility(name) {
14408
- const existingGroup = await groups_exports.getByName(name);
14407
+ async function guardNameAvailility(name2) {
14408
+ const existingGroup = await groups_exports.getByName(name2);
14409
14409
  if (existingGroup) {
14410
- throw new GroupNameUnavailableError(name);
14410
+ throw new GroupNameUnavailableError(name2);
14411
14411
  }
14412
14412
  }
14413
14413
  async function save4(group2) {
@@ -14566,8 +14566,8 @@ var init_groups6 = __esm({
14566
14566
  });
14567
14567
 
14568
14568
  // ../pro/packages/pro/src/utilities/fileSystem.ts
14569
- function loadJSFile(directory, name) {
14570
- return import_fs6.default.readFileSync((0, import_path6.join)(directory, name), "utf8");
14569
+ function loadJSFile(directory2, name2) {
14570
+ return import_fs6.default.readFileSync((0, import_path6.join)(directory2, name2), "utf8");
14571
14571
  }
14572
14572
  var import_fs6, import_path6;
14573
14573
  var init_fileSystem = __esm({
@@ -14585,8 +14585,8 @@ __export(plugins_exports, {
14585
14585
  storePlugin: () => storePlugin
14586
14586
  });
14587
14587
  async function storePlugin(metadata, directory, source) {
14588
- const db2 = tenancy.getGlobalDB();
14589
- const version = metadata.package.version, name = metadata.package.name, description = metadata.package.description, hash2 = metadata.schema.hash;
14588
+ const db = tenancy.getGlobalDB();
14589
+ const version = metadata.package.version, name = metadata.package.name, description = metadata.package.description, hash = metadata.schema.hash;
14590
14590
  const bucketPath = objectStore_exports2.getPluginS3Dir(name);
14591
14591
  const files = await objectStore_exports2.uploadDirectory(
14592
14592
  objectStore_exports2.ObjectStoreBuckets.PLUGINS,
@@ -14601,8 +14601,7 @@ async function storePlugin(metadata, directory, source) {
14601
14601
  if (metadata.schema.type === "datasource" /* DATASOURCE */) {
14602
14602
  const js = loadJSFile(directory, jsFile.name);
14603
14603
  try {
14604
- ;
14605
- (0, eval)(js);
14604
+ eval(js);
14606
14605
  } catch (err) {
14607
14606
  const message = (err == null ? void 0 : err.message) ? err.message : JSON.stringify(err);
14608
14607
  throw new Error(`JS invalid: ${message}`);
@@ -14612,7 +14611,7 @@ async function storePlugin(metadata, directory, source) {
14612
14611
  const pluginId = db_exports.generatePluginID(name);
14613
14612
  let rev;
14614
14613
  try {
14615
- const existing = await db2.get(pluginId);
14614
+ const existing = await db.get(pluginId);
14616
14615
  rev = existing._rev;
14617
14616
  } catch (err) {
14618
14617
  rev = void 0;
@@ -14623,7 +14622,7 @@ async function storePlugin(metadata, directory, source) {
14623
14622
  ...metadata,
14624
14623
  name,
14625
14624
  version,
14626
- hash: hash2,
14625
+ hash,
14627
14626
  description
14628
14627
  };
14629
14628
  if (iconFileName) {
@@ -14635,8 +14634,8 @@ async function storePlugin(metadata, directory, source) {
14635
14634
  source
14636
14635
  };
14637
14636
  }
14638
- const write2 = async () => {
14639
- const response2 = await db2.put(doc);
14637
+ const write = async () => {
14638
+ const response2 = await db.put(doc);
14640
14639
  await events_exports.plugin.imported(doc);
14641
14640
  return {
14642
14641
  ...doc,
@@ -14644,21 +14643,21 @@ async function storePlugin(metadata, directory, source) {
14644
14643
  };
14645
14644
  };
14646
14645
  if (!rev) {
14647
- return await addPlugin(write2);
14646
+ return await addPlugin(write);
14648
14647
  } else {
14649
- return await write2();
14648
+ return await write();
14650
14649
  }
14651
14650
  }
14652
- async function deletePlugin(pluginId) {
14651
+ async function deletePlugin(pluginId2) {
14653
14652
  const db2 = tenancy.getGlobalDB();
14654
14653
  try {
14655
- const plugin = await db2.get(pluginId);
14656
- const bucketPath = objectStore_exports2.getPluginS3Dir(plugin.name);
14654
+ const plugin = await db2.get(pluginId2);
14655
+ const bucketPath2 = objectStore_exports2.getPluginS3Dir(plugin.name);
14657
14656
  await objectStore_exports2.deleteFolder(
14658
14657
  objectStore_exports2.ObjectStoreBuckets.PLUGINS,
14659
- bucketPath
14658
+ bucketPath2
14660
14659
  );
14661
- await db2.remove(pluginId, plugin._rev);
14660
+ await db2.remove(pluginId2, plugin._rev);
14662
14661
  await events_exports.plugin.deleted(plugin);
14663
14662
  await removePlugin();
14664
14663
  } catch (err) {
@@ -14692,12 +14691,12 @@ function isEncryptionKeyAvailable() {
14692
14691
  return !!environment_default2.ENCRYPTION_KEY;
14693
14692
  }
14694
14693
  async function fetch10() {
14695
- const doc = await environmentVariables_exports.get();
14696
- return Object.keys(doc.variables);
14694
+ const doc2 = await environmentVariables_exports.get();
14695
+ return Object.keys(doc2.variables);
14697
14696
  }
14698
14697
  async function fetchValues(environment3) {
14699
- const doc = await environmentVariables_exports.get();
14700
- const decrypted = doc.variables;
14698
+ const doc2 = await environmentVariables_exports.get();
14699
+ const decrypted = doc2.variables;
14701
14700
  const output = {};
14702
14701
  for (let [key, value] of Object.entries(decrypted)) {
14703
14702
  switch (environment3) {
@@ -14719,9 +14718,9 @@ async function changeValues(cb) {
14719
14718
  "User does not have access to environment variables feature."
14720
14719
  );
14721
14720
  }
14722
- const doc = await environmentVariables_exports.get();
14723
- doc.variables = cb(doc.variables);
14724
- await environmentVariables_exports.update(doc);
14721
+ const doc2 = await environmentVariables_exports.get();
14722
+ doc2.variables = cb(doc2.variables);
14723
+ await environmentVariables_exports.update(doc2);
14725
14724
  }
14726
14725
  async function update2(varName, value) {
14727
14726
  const checkName = isValid(varName);
@@ -14772,15 +14771,15 @@ var init_environmentVariables6 = __esm({
14772
14771
  function generateAuditLogID(timestamp) {
14773
14772
  return `${"al" /* AUDIT_LOG */}${SEPARATOR}${timestamp}${SEPARATOR}${utils_exports2.newid()}`;
14774
14773
  }
14775
- async function save5(doc) {
14776
- if (!doc._id) {
14777
- doc._id = generateAuditLogID(doc.timestamp);
14774
+ async function save5(doc2) {
14775
+ if (!doc2._id) {
14776
+ doc2._id = generateAuditLogID(doc2.timestamp);
14778
14777
  }
14779
14778
  try {
14780
14779
  const db2 = context_exports.getAuditLogsDB();
14781
- const response2 = await db2.put(doc);
14780
+ const response2 = await db2.put(doc2);
14782
14781
  return {
14783
- ...doc,
14782
+ ...doc2,
14784
14783
  _rev: response2.rev
14785
14784
  };
14786
14785
  } catch (err) {
@@ -14808,9 +14807,9 @@ function dump(params2) {
14808
14807
  const db2 = context_exports.getAuditLogsDB();
14809
14808
  const stream3 = new MemoryStream();
14810
14809
  const promise = db2.dump(stream3, {
14811
- filter: (doc) => {
14810
+ filter: (doc2) => {
14812
14811
  var _a;
14813
- const auditLog = doc;
14812
+ const auditLog = doc2;
14814
14813
  if (!((_a = auditLog._id) == null ? void 0 : _a.startsWith("al" /* AUDIT_LOG */))) {
14815
14814
  return false;
14816
14815
  }
@@ -14828,7 +14827,7 @@ function dump(params2) {
14828
14827
  allMatched = allMatched && auditLog.timestamp >= params2.startDate && auditLog.timestamp <= params2.endDate;
14829
14828
  }
14830
14829
  if (params2.fullSearch) {
14831
- const json2 = JSON.stringify(doc);
14830
+ const json2 = JSON.stringify(doc2);
14832
14831
  allMatched = allMatched && json2.includes(params2.fullSearch);
14833
14832
  }
14834
14833
  return allMatched;
@@ -14839,8 +14838,8 @@ function dump(params2) {
14839
14838
  const json2 = JSON.parse(Buffer.from(data2).toString());
14840
14839
  if (Array.isArray(json2.docs)) {
14841
14840
  let str = "";
14842
- for (let doc of json2.docs) {
14843
- str += JSON.stringify(doc) + "\n";
14841
+ for (let doc2 of json2.docs) {
14842
+ str += JSON.stringify(doc2) + "\n";
14844
14843
  }
14845
14844
  returnStream.write(str);
14846
14845
  }
@@ -14865,8 +14864,8 @@ var init_auditLogs4 = __esm({
14865
14864
  var require_Helper = __commonJS({
14866
14865
  "../string-templates/src/helpers/Helper.js"(exports2, module2) {
14867
14866
  var Helper = class {
14868
- constructor(name, fn2, useValueFallback = true) {
14869
- this.name = name;
14867
+ constructor(name2, fn2, useValueFallback = true) {
14868
+ this.name = name2;
14870
14869
  this.fn = fn2;
14871
14870
  this.useValueFallback = useValueFallback;
14872
14871
  }
@@ -15035,18 +15034,18 @@ var require_external = __commonJS({
15035
15034
  exports2.externalCollections = EXTERNAL_FUNCTION_COLLECTIONS;
15036
15035
  exports2.addedHelpers = ADDED_HELPERS;
15037
15036
  exports2.registerAll = (handlebars) => {
15038
- for (let [name, helper] of Object.entries(ADDED_HELPERS)) {
15039
- handlebars.registerHelper(name, helper);
15037
+ for (let [name2, helper] of Object.entries(ADDED_HELPERS)) {
15038
+ handlebars.registerHelper(name2, helper);
15040
15039
  }
15041
15040
  let externalNames = [];
15042
15041
  for (let collection of EXTERNAL_FUNCTION_COLLECTIONS) {
15043
15042
  let hbsHelperInfo = helpers[collection]();
15044
15043
  for (let entry of Object.entries(hbsHelperInfo)) {
15045
- const name = entry[0];
15046
- if (HelperFunctionBuiltin.indexOf(name) !== -1 || externalNames.indexOf(name) !== -1) {
15044
+ const name2 = entry[0];
15045
+ if (HelperFunctionBuiltin.indexOf(name2) !== -1 || externalNames.indexOf(name2) !== -1) {
15047
15046
  continue;
15048
15047
  }
15049
- externalNames.push(name);
15048
+ externalNames.push(name2);
15050
15049
  }
15051
15050
  helpers[collection]({
15052
15051
  handlebars
@@ -15055,11 +15054,11 @@ var require_external = __commonJS({
15055
15054
  exports2.externalHelperNames = externalNames.concat(Object.keys(ADDED_HELPERS));
15056
15055
  };
15057
15056
  exports2.unregisterAll = (handlebars) => {
15058
- for (let name of Object.keys(ADDED_HELPERS)) {
15059
- handlebars.unregisterHelper(name);
15057
+ for (let name2 of Object.keys(ADDED_HELPERS)) {
15058
+ handlebars.unregisterHelper(name2);
15060
15059
  }
15061
- for (let name of module2.exports.externalHelperNames) {
15062
- handlebars.unregisterHelper(name);
15060
+ for (let name2 of module2.exports.externalHelperNames) {
15061
+ handlebars.unregisterHelper(name2);
15063
15062
  }
15064
15063
  exports2.externalHelperNames = [];
15065
15064
  };
@@ -15173,12 +15172,12 @@ var require_javascript = __commonJS({
15173
15172
  throw new Error("JS disabled in environment.");
15174
15173
  }
15175
15174
  try {
15176
- const js = `function run(){${atob(handlebars)}};run();`;
15175
+ const js2 = `function run(){${atob(handlebars)}};run();`;
15177
15176
  const sandboxContext = {
15178
15177
  $: (path2) => getContextValue(path2, cloneDeep16(context)),
15179
15178
  helpers: getHelperList()
15180
15179
  };
15181
- const res = { data: runJS(js, sandboxContext) };
15180
+ const res = { data: runJS(js2, sandboxContext) };
15182
15181
  return `{{${LITERAL_MARKER} js_result-${JSON.stringify(res)}}}`;
15183
15182
  } catch (error) {
15184
15183
  return "Error while executing JS";
@@ -15291,8 +15290,8 @@ var require_preprocessor = __commonJS({
15291
15290
  FINALISE: "finalise"
15292
15291
  };
15293
15292
  var Preprocessor = class {
15294
- constructor(name, fn2) {
15295
- this.name = name;
15293
+ constructor(name2, fn2) {
15294
+ this.name = name2;
15296
15295
  this.fn = fn2;
15297
15296
  }
15298
15297
  process(fullString, statement, opts) {
@@ -15356,8 +15355,8 @@ var require_postprocessor = __commonJS({
15356
15355
  CONVERT_LITERALS: "convert-literals"
15357
15356
  };
15358
15357
  var Postprocessor = class {
15359
- constructor(name, fn2) {
15360
- this.name = name;
15358
+ constructor(name2, fn2) {
15359
+ this.name = name2;
15361
15360
  this.fn = fn2;
15362
15361
  }
15363
15362
  process(statement) {
@@ -16999,10 +16998,10 @@ var require_src = __commonJS({
16999
16998
  };
17000
16999
  module2.exports.convertToJS = (hbs) => {
17001
17000
  const blocks = exports2.findHBSBlocks(hbs);
17002
- let js = "return `", prevBlock = null;
17001
+ let js2 = "return `", prevBlock = null;
17003
17002
  const variables = {};
17004
17003
  if (blocks.length === 0) {
17005
- js += hbs;
17004
+ js2 += hbs;
17006
17005
  }
17007
17006
  let count = 1;
17008
17007
  for (let block of blocks) {
@@ -17014,15 +17013,15 @@ var require_src = __commonJS({
17014
17013
  prevBlock = block;
17015
17014
  const { variable, value } = convertHBSBlock(block, count++);
17016
17015
  variables[variable] = value;
17017
- js += `${stringPart.split()}\${${variable}}`;
17016
+ js2 += `${stringPart.split()}\${${variable}}`;
17018
17017
  }
17019
17018
  let varBlock = "";
17020
17019
  for (let [variable, value] of Object.entries(variables)) {
17021
17020
  varBlock += `const ${variable} = ${value};
17022
17021
  `;
17023
17022
  }
17024
- js += "`;";
17025
- return `${varBlock}${js}`;
17023
+ js2 += "`;";
17024
+ return `${varBlock}${js2}`;
17026
17025
  };
17027
17026
  }
17028
17027
  });
@@ -17049,12 +17048,12 @@ var require_src2 = __commonJS({
17049
17048
  if (!process.env.NO_JS) {
17050
17049
  const { VM: VM2 } = require("vm2");
17051
17050
  const { setJSRunner } = require_javascript();
17052
- setJSRunner((js, context) => {
17051
+ setJSRunner((js2, context) => {
17053
17052
  const vm = new VM2({
17054
17053
  sandbox: context,
17055
17054
  timeout: 1e3
17056
17055
  });
17057
- return vm.run(js);
17056
+ return vm.run(js2);
17058
17057
  });
17059
17058
  }
17060
17059
  }
@@ -17148,12 +17147,12 @@ async function auditLogsEnabled() {
17148
17147
  const license = await licensing_exports.cache.getCachedLicense();
17149
17148
  return license.features.includes("auditLogs" /* AUDIT_LOGS */);
17150
17149
  }
17151
- function getEventFriendlyName(event, metadata) {
17150
+ function getEventFriendlyName(event, metadata2) {
17152
17151
  const friendly = AuditedEventFriendlyName[event];
17153
17152
  if (!friendly) {
17154
17153
  throw new Error("No friendly name found.");
17155
17154
  }
17156
- let processed = processStringSync(friendly, metadata);
17155
+ let processed = processStringSync(friendly, metadata2);
17157
17156
  if (processed.includes(`""`)) {
17158
17157
  processed = removeTemplateStrings(friendly);
17159
17158
  }
@@ -17175,29 +17174,29 @@ var init_utils10 = __esm({
17175
17174
  });
17176
17175
 
17177
17176
  // ../pro/packages/pro/src/sdk/auditLogs/auditLogs.ts
17178
- async function write(event, metadata, opts) {
17177
+ async function write2(event, metadata2, opts) {
17179
17178
  if (!await auditLogsEnabled() || !utils_exports2.isAudited(event)) {
17180
17179
  return;
17181
17180
  }
17182
- const friendly = getEventFriendlyName(event, metadata);
17181
+ const friendly = getEventFriendlyName(event, metadata2);
17183
17182
  let date = /* @__PURE__ */ new Date();
17184
17183
  if (opts == null ? void 0 : opts.timestamp) {
17185
17184
  date = new Date(opts.timestamp);
17186
17185
  }
17187
- const doc = {
17186
+ const doc2 = {
17188
17187
  timestamp: date.toISOString(),
17189
17188
  event,
17190
17189
  name: friendly,
17191
17190
  userId: (opts == null ? void 0 : opts.userId) || AuditLogSystemUser,
17192
17191
  metadata: {
17193
- ...metadata,
17192
+ ...metadata2,
17194
17193
  ...opts == null ? void 0 : opts.hostInfo
17195
17194
  }
17196
17195
  };
17197
17196
  const fallback = {};
17198
17197
  try {
17199
17198
  if (opts == null ? void 0 : opts.appId) {
17200
- doc.appId = db_exports.getProdAppID(opts.appId);
17199
+ doc2.appId = db_exports.getProdAppID(opts.appId);
17201
17200
  const appMetadata = await cache_exports.app.getAppMetadata(opts.appId);
17202
17201
  fallback.appName = appMetadata.name;
17203
17202
  }
@@ -17211,8 +17210,8 @@ async function write(event, metadata, opts) {
17211
17210
  err
17212
17211
  );
17213
17212
  }
17214
- doc.fallback = fallback;
17215
- return await save5(doc);
17213
+ doc2.fallback = fallback;
17214
+ return await save5(doc2);
17216
17215
  }
17217
17216
  async function enrich(logs) {
17218
17217
  const allUserIds = logs.map((log) => log.userId);
@@ -17284,7 +17283,7 @@ __export(auditLogs_exports2, {
17284
17283
  definitions: () => definitions2,
17285
17284
  download: () => download,
17286
17285
  fetch: () => fetch11,
17287
- write: () => write
17286
+ write: () => write2
17288
17287
  });
17289
17288
  var init_auditLogs6 = __esm({
17290
17289
  "../pro/packages/pro/src/sdk/auditLogs/index.ts"() {
@@ -17307,8 +17306,8 @@ var init_queue4 = __esm({
17307
17306
  });
17308
17307
 
17309
17308
  // ../pro/packages/pro/src/sdk/backups/backup.ts
17310
- async function storeAppBackupMetadata2(metadata, opts = {}) {
17311
- return backups_exports.storeAppBackupMetadata(metadata, opts);
17309
+ async function storeAppBackupMetadata2(metadata2, opts = {}) {
17310
+ return backups_exports.storeAppBackupMetadata(metadata2, opts);
17312
17311
  }
17313
17312
  function getTimestamps(status2) {
17314
17313
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
@@ -17322,7 +17321,7 @@ function getTimestamps(status2) {
17322
17321
  return { timestamp, createdAt: timestamp };
17323
17322
  }
17324
17323
  }
17325
- async function updateBackupStatus(id, rev, status2, contents, filename) {
17324
+ async function updateBackupStatus(id, rev2, status2, contents, filename) {
17326
17325
  const backup = await getAppBackup(id);
17327
17326
  return await backups_exports.storeAppBackupMetadata(
17328
17327
  {
@@ -17332,10 +17331,10 @@ async function updateBackupStatus(id, rev, status2, contents, filename) {
17332
17331
  status: status2,
17333
17332
  type: "backup" /* BACKUP */
17334
17333
  },
17335
- { filename, docId: id, docRev: rev }
17334
+ { filename, docId: id, docRev: rev2 }
17336
17335
  );
17337
17336
  }
17338
- async function updateRestoreStatus(id, rev, status2) {
17337
+ async function updateRestoreStatus(id, rev2, status2) {
17339
17338
  const restore = await getAppBackup(id);
17340
17339
  return await backups_exports.storeAppBackupMetadata(
17341
17340
  {
@@ -17345,7 +17344,7 @@ async function updateRestoreStatus(id, rev, status2) {
17345
17344
  type: "restore" /* RESTORE */,
17346
17345
  trigger: "manual" /* MANUAL */
17347
17346
  },
17348
- { docId: id, docRev: rev }
17347
+ { docId: id, docRev: rev2 }
17349
17348
  );
17350
17349
  }
17351
17350
  async function getAppBackup(backupId) {
@@ -17355,11 +17354,11 @@ async function updateAppBackup(backupId, backupName) {
17355
17354
  return backups_exports.updateAppBackupMetadata(backupId, backupName);
17356
17355
  }
17357
17356
  async function deleteAppBackup(backupId) {
17358
- const metadata = await backups_exports.getAppBackupMetadata(backupId);
17359
- if (metadata.filename) {
17357
+ const metadata2 = await backups_exports.getAppBackupMetadata(backupId);
17358
+ if (metadata2.filename) {
17360
17359
  await objectStore_exports2.deleteFile(
17361
17360
  objectStore_exports2.ObjectStoreBuckets.BACKUPS,
17362
- metadata.filename
17361
+ metadata2.filename
17363
17362
  );
17364
17363
  }
17365
17364
  return backups_exports.deleteAppBackupMetadata(backupId);
@@ -17368,15 +17367,15 @@ async function fetchAppBackups2(appId, opts) {
17368
17367
  return backups_exports.fetchAppBackups(appId, opts);
17369
17368
  }
17370
17369
  async function downloadAppBackup(backupId) {
17371
- const metadata = await backups_exports.getAppBackupMetadata(backupId);
17372
- if (!metadata.filename) {
17370
+ const metadata2 = await backups_exports.getAppBackupMetadata(backupId);
17371
+ if (!metadata2.filename) {
17373
17372
  throw new Error("Backup incomplete - cannot download.");
17374
17373
  }
17375
17374
  const path2 = await objectStore_exports2.retrieveToTmp(
17376
17375
  objectStore_exports2.ObjectStoreBuckets.BACKUPS,
17377
- metadata.filename
17376
+ metadata2.filename
17378
17377
  );
17379
- return { metadata, path: path2 };
17378
+ return { metadata: metadata2, path: path2 };
17380
17379
  }
17381
17380
  async function triggerAppBackup(appId, trigger, opts = {}) {
17382
17381
  let backup;
@@ -17415,7 +17414,7 @@ async function triggerAppBackup(appId, trigger, opts = {}) {
17415
17414
  return backup.id;
17416
17415
  }
17417
17416
  async function triggerAppRestore(appId, backupId, nameForBackup, createdBy) {
17418
- const metadata = await getAppBackup(backupId);
17417
+ const metadata2 = await getAppBackup(backupId);
17419
17418
  let restore;
17420
17419
  try {
17421
17420
  restore = await storeAppBackupMetadata2({
@@ -17442,7 +17441,7 @@ async function triggerAppRestore(appId, backupId, nameForBackup, createdBy) {
17442
17441
  createdBy
17443
17442
  }
17444
17443
  });
17445
- return { restoreId: restore.id, metadata };
17444
+ return { restoreId: restore.id, metadata: metadata2 };
17446
17445
  }
17447
17446
  var pkg, backup_default2;
17448
17447
  var init_backup5 = __esm({
@@ -17555,7 +17554,7 @@ async function importProcessor(job, opts) {
17555
17554
  const tenantId = tenancy.getTenantIDFromAppID(appId);
17556
17555
  return tenancy.doInTenant(tenantId, async () => {
17557
17556
  const devAppId = db_exports.getDevAppID(appId);
17558
- const { rev } = await backup_default2.updateRestoreStatus(
17557
+ const { rev: rev2 } = await backup_default2.updateRestoreStatus(
17559
17558
  data2.docId,
17560
17559
  data2.docRev,
17561
17560
  "started" /* STARTED */
@@ -17580,23 +17579,23 @@ async function importProcessor(job, opts) {
17580
17579
  logging_exports.logAlert("App restore error", err);
17581
17580
  status2 = "failed" /* FAILED */;
17582
17581
  }
17583
- await backup_default2.updateRestoreStatus(data2.docId, rev, status2);
17582
+ await backup_default2.updateRestoreStatus(data2.docId, rev2, status2);
17584
17583
  });
17585
17584
  }
17586
17585
  async function exportProcessor(job, opts) {
17587
17586
  const data2 = job.data;
17588
- const appId = data2.appId, trigger = data2.export.trigger, name = data2.export.name;
17587
+ const appId = data2.appId, trigger = data2.export.trigger, name2 = data2.export.name;
17589
17588
  const tenantId = tenancy.getTenantIDFromAppID(appId);
17590
17589
  await tenancy.doInTenant(tenantId, async () => {
17591
- const { rev } = await backup_default2.updateBackupStatus(
17590
+ const { rev: rev2 } = await backup_default2.updateBackupStatus(
17592
17591
  data2.docId,
17593
17592
  data2.docRev,
17594
17593
  "started" /* STARTED */
17595
17594
  );
17596
17595
  return runBackup(trigger, tenantId, appId, {
17597
17596
  processing: opts,
17598
- doc: { id: data2.docId, rev },
17599
- name
17597
+ doc: { id: data2.docId, rev: rev2 },
17598
+ name: name2
17600
17599
  });
17601
17600
  });
17602
17601
  }
@@ -17905,9 +17904,9 @@ var init_groups7 = __esm({
17905
17904
  ctx.body = { data: await fetch9() };
17906
17905
  };
17907
17906
  destroy4 = async (ctx) => {
17908
- const { id, rev } = ctx.params;
17907
+ const { id, rev: rev2 } = ctx.params;
17909
17908
  try {
17910
- await remove2(id, rev);
17909
+ await remove2(id, rev2);
17911
17910
  ctx.body = { message: "Group deleted successfully" };
17912
17911
  } catch (err) {
17913
17912
  ctx.throw(err.status, err);
@@ -17953,13 +17952,13 @@ async function fetch13(ctx) {
17953
17952
  };
17954
17953
  }
17955
17954
  async function create3(ctx) {
17956
- const { name, production, development } = ctx.request.body;
17957
- await environmentVariables_exports2.update(name, { production, development });
17955
+ const { name: name2, production, development } = ctx.request.body;
17956
+ await environmentVariables_exports2.update(name2, { production, development });
17958
17957
  const environments = ["production" /* PRODUCTION */];
17959
17958
  if (production !== development) {
17960
17959
  environments.push("development" /* DEVELOPMENT */);
17961
17960
  }
17962
- await events_exports.environmentVariable.created(name, environments);
17961
+ await events_exports.environmentVariable.created(name2, environments);
17963
17962
  ctx.status = 200;
17964
17963
  }
17965
17964
  async function update4(ctx) {
@@ -18246,8 +18245,8 @@ async function downloadBackup(ctx) {
18246
18245
  const appId = ctx.params.appId;
18247
18246
  await checkAppID(ctx, appId);
18248
18247
  const backupId = ctx.params.backupId;
18249
- const { metadata, path: path2 } = await backups_default.downloadAppBackup(backupId);
18250
- ctx.attachment(`backup-${metadata.timestamp}.tar.gz`);
18248
+ const { metadata: metadata2, path: path2 } = await backups_default.downloadAppBackup(backupId);
18249
+ ctx.attachment(`backup-${metadata2.timestamp}.tar.gz`);
18251
18250
  ctx.body = import_fs8.default.createReadStream(path2);
18252
18251
  }
18253
18252
  var import_fs8;
@@ -18387,8 +18386,8 @@ var init_schedules2 = __esm({
18387
18386
  });
18388
18387
 
18389
18388
  // ../pro/packages/pro/src/api/controllers/global/scim/users.ts
18390
- function tryGetQueryAsNumber(ctx, name) {
18391
- const value = ctx.request.query[name];
18389
+ function tryGetQueryAsNumber(ctx, name2) {
18390
+ const value = ctx.request.query[name2];
18392
18391
  if (value === void 0) {
18393
18392
  return void 0;
18394
18393
  }
@@ -18779,11 +18778,11 @@ var init_filters = __esm({
18779
18778
  return docs;
18780
18779
  }
18781
18780
  query = cleanupQuery(query);
18782
- const match = (type, failFn) => (doc) => {
18781
+ const match = (type, failFn) => (doc2) => {
18783
18782
  const filters = Object.entries(query[type] || {});
18784
18783
  for (let i = 0; i < filters.length; i++) {
18785
18784
  const [key, testValue] = filters[i];
18786
- const docValue = deepGet(doc, removeKeyNumbering2(key));
18785
+ const docValue = deepGet(doc2, removeKeyNumbering2(key));
18787
18786
  if (failFn(docValue, testValue)) {
18788
18787
  return false;
18789
18788
  }
@@ -18844,8 +18843,8 @@ var init_filters = __esm({
18844
18843
  return testValue == null ? void 0 : testValue.every((item) => docValue == null ? void 0 : docValue.includes(item));
18845
18844
  }
18846
18845
  );
18847
- const docMatch = (doc) => {
18848
- return stringMatch(doc) && fuzzyMatch(doc) && rangeMatch(doc) && equalMatch(doc) && notEqualMatch(doc) && emptyMatch(doc) && notEmptyMatch(doc) && oneOf(doc) && contains(doc) && containsAny(doc) && notContains(doc);
18846
+ const docMatch = (doc2) => {
18847
+ return stringMatch(doc2) && fuzzyMatch(doc2) && rangeMatch(doc2) && equalMatch(doc2) && notEqualMatch(doc2) && emptyMatch(doc2) && notEmptyMatch(doc2) && oneOf(doc2) && contains(doc2) && containsAny(doc2) && notContains(doc2);
18849
18848
  };
18850
18849
  return docs.filter(docMatch);
18851
18850
  };
@@ -19589,7 +19588,7 @@ var init_app7 = __esm({
19589
19588
  // src/utilities/fileSystem/plugin.ts
19590
19589
  async function getPluginImpl(path2, plugin) {
19591
19590
  var _a;
19592
- const hash2 = (_a = plugin.schema) == null ? void 0 : _a.hash;
19591
+ const hash3 = (_a = plugin.schema) == null ? void 0 : _a.hash;
19593
19592
  if (!import_fs10.default.existsSync(path2)) {
19594
19593
  import_fs10.default.mkdirSync(path2);
19595
19594
  }
@@ -19597,7 +19596,7 @@ async function getPluginImpl(path2, plugin) {
19597
19596
  const metadataName = `${filename}.bbmetadata`;
19598
19597
  if (import_fs10.default.existsSync(filename)) {
19599
19598
  const currentHash = import_fs10.default.readFileSync(metadataName, "utf8");
19600
- if (currentHash === hash2) {
19599
+ if (currentHash === hash3) {
19601
19600
  return require(filename);
19602
19601
  } else {
19603
19602
  console.log(`Updating plugin: ${plugin.name}`);
@@ -19611,7 +19610,7 @@ async function getPluginImpl(path2, plugin) {
19611
19610
  pluginKey
19612
19611
  );
19613
19612
  import_fs10.default.writeFileSync(filename, pluginJs);
19614
- import_fs10.default.writeFileSync(metadataName, hash2);
19613
+ import_fs10.default.writeFileSync(metadataName, hash3);
19615
19614
  return require(filename);
19616
19615
  }
19617
19616
  var import_fs10, import_path9, DATASOURCE_PATH, AUTOMATION_PATH, getPluginMetadata, getDatasourcePlugin, getAutomationPlugin;
@@ -19624,13 +19623,13 @@ var init_plugin5 = __esm({
19624
19623
  DATASOURCE_PATH = (0, import_path9.join)(budibaseTempDir2(), "datasource");
19625
19624
  AUTOMATION_PATH = (0, import_path9.join)(budibaseTempDir2(), "automation");
19626
19625
  getPluginMetadata = async (path2) => {
19627
- let metadata = {};
19626
+ let metadata2 = {};
19628
19627
  try {
19629
19628
  const pkg2 = import_fs10.default.readFileSync((0, import_path9.join)(path2, "package.json"), "utf8");
19630
19629
  const schema = import_fs10.default.readFileSync((0, import_path9.join)(path2, "schema.json"), "utf8");
19631
- metadata.schema = JSON.parse(schema);
19632
- metadata.package = JSON.parse(pkg2);
19633
- if (!metadata.package.name || !metadata.package.version || !metadata.package.description) {
19630
+ metadata2.schema = JSON.parse(schema);
19631
+ metadata2.package = JSON.parse(pkg2);
19632
+ if (!metadata2.package.name || !metadata2.package.version || !metadata2.package.description) {
19634
19633
  throw new Error(
19635
19634
  "package.json is missing one of 'name', 'version' or 'description'."
19636
19635
  );
@@ -19640,7 +19639,7 @@ var init_plugin5 = __esm({
19640
19639
  `Unable to process schema.json/package.json in plugin. ${err.message}`
19641
19640
  );
19642
19641
  }
19643
- return { metadata, directory: path2 };
19642
+ return { metadata: metadata2, directory: path2 };
19644
19643
  };
19645
19644
  getDatasourcePlugin = async (plugin) => {
19646
19645
  return getPluginImpl(DATASOURCE_PATH, plugin);
@@ -19657,9 +19656,9 @@ var init_template = __esm({
19657
19656
  "src/utilities/fileSystem/template.ts"() {
19658
19657
  init_constants6();
19659
19658
  init_src2();
19660
- downloadTemplate = async (type, name) => {
19659
+ downloadTemplate = async (type, name2) => {
19661
19660
  const DEFAULT_TEMPLATES_BUCKET = "prod-budi-templates.s3-eu-west-1.amazonaws.com";
19662
- const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${name}.tar.gz`;
19661
+ const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${name2}.tar.gz`;
19663
19662
  return objectStore_exports2.downloadTarball(
19664
19663
  templateUrl,
19665
19664
  ObjectStoreBuckets2.TEMPLATES,
@@ -19697,7 +19696,7 @@ __export(exports_exports, {
19697
19696
  exportDB: () => exportDB,
19698
19697
  streamExportApp: () => streamExportApp
19699
19698
  });
19700
- function tarFilesToTmp(tmpDir, files) {
19699
+ function tarFilesToTmp(tmpDir, files2) {
19701
19700
  const exportFile = (0, import_path10.join)(budibaseTempDir2(), `${uuid3()}.tar.gz`);
19702
19701
  tar3.create(
19703
19702
  {
@@ -19707,7 +19706,7 @@ function tarFilesToTmp(tmpDir, files) {
19707
19706
  recursive: true,
19708
19707
  cwd: tmpDir
19709
19708
  },
19710
- files
19709
+ files2
19711
19710
  );
19712
19711
  return exportFile;
19713
19712
  }
@@ -19743,7 +19742,7 @@ function defineFilter(excludeRows, excludeLogs) {
19743
19742
  if (excludeLogs) {
19744
19743
  ids.push(AUTOMATION_LOG_PREFIX);
19745
19744
  }
19746
- return (doc) => !ids.map((key) => doc._id.includes(key)).reduce((prev, curr) => prev || curr);
19745
+ return (doc2) => !ids.map((key) => doc2._id.includes(key)).reduce((prev, curr) => prev || curr);
19747
19746
  }
19748
19747
  async function exportApp(appId, config) {
19749
19748
  const prodAppId = db_exports.getProdAppID(appId);
@@ -19887,9 +19886,9 @@ async function getTemplateStream(template) {
19887
19886
  if (template.file) {
19888
19887
  return import_fs12.default.createReadStream(template.file.path);
19889
19888
  } else if (template.key) {
19890
- const [type, name] = template.key.split("/");
19891
- const tmpPath = await downloadTemplate(type, name);
19892
- return import_fs12.default.createReadStream((0, import_path11.join)(tmpPath, name, "db", "dump.txt"));
19889
+ const [type, name2] = template.key.split("/");
19890
+ const tmpPath = await downloadTemplate(type, name2);
19891
+ return import_fs12.default.createReadStream((0, import_path11.join)(tmpPath, name2, "db", "dump.txt"));
19893
19892
  }
19894
19893
  }
19895
19894
  function untarFile(file) {
@@ -20202,22 +20201,34 @@ function finaliseExternalTables(tables, entities) {
20202
20201
  let finalTables = {};
20203
20202
  const errors = {};
20204
20203
  const tableIds = Object.values(tables).map((table) => table._id);
20205
- for (let [name, table] of Object.entries(tables)) {
20204
+ for (let [name2, table] of Object.entries(tables)) {
20206
20205
  const schemaFields = Object.keys(table.schema);
20207
20206
  if (table.primary == null || table.primary.length === 0) {
20208
- errors[name] = "no_key" /* NO_KEY */;
20207
+ errors[name2] = "no_key" /* NO_KEY */;
20209
20208
  continue;
20210
20209
  } else if (schemaFields.find(
20211
20210
  (field) => invalidColumns.includes(field)
20212
20211
  )) {
20213
- errors[name] = "invalid_column" /* INVALID_COLUMN */;
20212
+ errors[name2] = "invalid_column" /* INVALID_COLUMN */;
20214
20213
  continue;
20215
20214
  }
20216
- finalTables[name] = copyExistingPropsOver(name, table, entities, tableIds);
20215
+ finalTables[name2] = copyExistingPropsOver(name2, table, entities, tableIds);
20217
20216
  }
20218
20217
  finalTables = Object.entries(finalTables).sort(([a], [b]) => a.localeCompare(b)).reduce((r, [k, v]) => ({ ...r, [k]: v }), {});
20219
20218
  return { tables: finalTables, errors };
20220
20219
  }
20220
+ function getPrimaryDisplay(testValue) {
20221
+ if (testValue instanceof Date) {
20222
+ return testValue.toISOString();
20223
+ }
20224
+ if (Array.isArray(testValue) && testValue[0] && typeof testValue[0] !== "object") {
20225
+ return testValue.join(", ");
20226
+ }
20227
+ if (typeof testValue === "object") {
20228
+ return void 0;
20229
+ }
20230
+ return testValue;
20231
+ }
20221
20232
  var DOUBLE_SEPARATOR, ROW_ID_REGEX, ENCODED_SPACE, SQL_NUMBER_TYPE_MAP, SQL_DATE_TYPE_MAP, SQL_DATE_ONLY_TYPES, SQL_TIME_ONLY_TYPES, SQL_STRING_TYPE_MAP, SQL_BOOLEAN_TYPE_MAP, SQL_MISC_TYPE_MAP, SQL_TYPE_MAP;
20222
20233
  var init_utils14 = __esm({
20223
20234
  "src/integrations/utils.ts"() {
@@ -22108,21 +22119,21 @@ var init_mongodb = __esm({
22108
22119
  const collection = db2.collection(query.extra.collection);
22109
22120
  let response2 = [];
22110
22121
  if (((_a = query.extra) == null ? void 0 : _a.actionType) === "pipeline") {
22111
- for await (const doc of collection.aggregate(
22122
+ for await (const doc2 of collection.aggregate(
22112
22123
  query.steps.map(({ key, value }) => {
22113
22124
  let temp = {};
22114
22125
  temp[key] = JSON.parse(value.value);
22115
22126
  return this.createObjectIds(temp);
22116
22127
  })
22117
22128
  )) {
22118
- response2.push(doc);
22129
+ response2.push(doc2);
22119
22130
  }
22120
22131
  } else {
22121
22132
  const stages = query.json;
22122
- for await (const doc of collection.aggregate(
22133
+ for await (const doc2 of collection.aggregate(
22123
22134
  stages ? this.createObjectIds(stages) : []
22124
22135
  )) {
22125
- response2.push(doc);
22136
+ response2.push(doc2);
22126
22137
  }
22127
22138
  }
22128
22139
  return response2;
@@ -22433,9 +22444,9 @@ var init_couchdb = __esm({
22433
22444
  });
22434
22445
  }
22435
22446
  async delete(query) {
22436
- const doc = await this.query("get", "Cannot find doc to be deleted", query);
22447
+ const doc2 = await this.query("get", "Cannot find doc to be deleted", query);
22437
22448
  return this.query("remove", "Error deleting couchDB document", {
22438
- json: doc
22449
+ json: doc2
22439
22450
  });
22440
22451
  }
22441
22452
  };
@@ -22621,7 +22632,7 @@ var init_microsoftSqlServer = __esm({
22621
22632
  throw "Unable to get list of tables in database";
22622
22633
  }
22623
22634
  const schema = this.config.schema || DEFAULT_SCHEMA;
22624
- const tableNames = tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name) => this.MASTER_TABLES.indexOf(name) === -1);
22635
+ const tableNames = tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name2) => this.MASTER_TABLES.indexOf(name2) === -1);
22625
22636
  const tables = {};
22626
22637
  for (let tableName of tableNames) {
22627
22638
  const definition26 = await this.runSQL(this.getDefinitionSQL(tableName));
@@ -22636,16 +22647,16 @@ var init_microsoftSqlServer = __esm({
22636
22647
  const requiredColumns = columns.filter((col) => col.IS_NULLABLE === "NO").map((col) => col.COLUMN_NAME);
22637
22648
  let schema2 = {};
22638
22649
  for (let def of definition26) {
22639
- const name = def.COLUMN_NAME;
22640
- if (typeof name !== "string") {
22650
+ const name2 = def.COLUMN_NAME;
22651
+ if (typeof name2 !== "string") {
22641
22652
  continue;
22642
22653
  }
22643
22654
  const hasDefault = def.COLUMN_DEFAULT;
22644
- const isAuto = !!autoColumns.find((col) => col === name);
22645
- const required = !!requiredColumns.find((col) => col === name);
22646
- schema2[name] = {
22655
+ const isAuto = !!autoColumns.find((col) => col === name2);
22656
+ const required = !!requiredColumns.find((col) => col === name2);
22657
+ schema2[name2] = {
22647
22658
  autocolumn: isAuto,
22648
- name,
22659
+ name: name2,
22649
22660
  constraints: {
22650
22661
  presence: required && !isAuto && !hasDefault
22651
22662
  },
@@ -22667,7 +22678,7 @@ var init_microsoftSqlServer = __esm({
22667
22678
  async queryTableNames() {
22668
22679
  let tableInfo = await this.runSQL(this.TABLES_SQL);
22669
22680
  const schema = this.config.schema || DEFAULT_SCHEMA;
22670
- return tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name) => this.MASTER_TABLES.indexOf(name) === -1);
22681
+ return tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name2) => this.MASTER_TABLES.indexOf(name2) === -1);
22671
22682
  }
22672
22683
  async getTableNames() {
22673
22684
  await this.connect();
@@ -23101,7 +23112,12 @@ function bindingTypeCoerce(bindings) {
23101
23112
  if (matches2 && matches2[0] !== "" && !isNaN(Number(matches2[0]))) {
23102
23113
  bindings[i] = parseFloat(binding);
23103
23114
  } else if (/^\d/.test(binding) && (0, import_dayjs.default)(binding).isValid() && !binding.includes(",")) {
23104
- bindings[i] = (0, import_dayjs.default)(binding).toDate();
23115
+ let value;
23116
+ value = new Date(binding);
23117
+ if (isNaN(value)) {
23118
+ value = binding;
23119
+ }
23120
+ bindings[i] = value;
23105
23121
  }
23106
23122
  }
23107
23123
  return bindings;
@@ -24084,13 +24100,13 @@ var init_googlesheets = __esm({
24084
24100
  }
24085
24101
  return rowObject;
24086
24102
  }
24087
- async createTable(name) {
24088
- if (!name) {
24103
+ async createTable(name2) {
24104
+ if (!name2) {
24089
24105
  throw new Error("Must provide name for new sheet.");
24090
24106
  }
24091
24107
  try {
24092
24108
  await this.connect();
24093
- return await this.client.addSheet({ title: name, headerValues: [name] });
24109
+ return await this.client.addSheet({ title: name2, headerValues: [name2] });
24094
24110
  } catch (err) {
24095
24111
  console.error("Error creating new table in google sheets", err);
24096
24112
  throw err;
@@ -24416,7 +24432,7 @@ var init_firebase = __esm({
24416
24432
  snapshot = await collectionRef.get();
24417
24433
  }
24418
24434
  const result = [];
24419
- snapshot.forEach((doc) => result.push(doc.data()));
24435
+ snapshot.forEach((doc2) => result.push(doc2.data()));
24420
24436
  return result;
24421
24437
  } catch (err) {
24422
24438
  console.error("Error querying Firestore", err);
@@ -25078,13 +25094,13 @@ var init_oracle = __esm({
25078
25094
  });
25079
25095
 
25080
25096
  // src/integrations/index.ts
25081
- async function getDefinition(source) {
25082
- const definition26 = DEFINITIONS2[source];
25097
+ async function getDefinition(source2) {
25098
+ const definition26 = DEFINITIONS2[source2];
25083
25099
  if (definition26) {
25084
25100
  return definition26;
25085
25101
  }
25086
25102
  const allDefinitions = await getDefinitions();
25087
- return allDefinitions[source];
25103
+ return allDefinitions[source2];
25088
25104
  }
25089
25105
  async function getDefinitions() {
25090
25106
  const pluginSchemas = {};
@@ -25420,10 +25436,10 @@ __export(webhook_exports2, {
25420
25436
  function isWebhookID(id) {
25421
25437
  return id.startsWith(db_exports.DocumentType.WEBHOOK);
25422
25438
  }
25423
- function newDoc(name, type, target) {
25439
+ function newDoc(name2, type, target) {
25424
25440
  return {
25425
25441
  live: true,
25426
- name,
25442
+ name: name2,
25427
25443
  action: {
25428
25444
  type,
25429
25445
  target
@@ -25441,12 +25457,12 @@ async function save7(webhook) {
25441
25457
  webhook._rev = response2.rev;
25442
25458
  return webhook;
25443
25459
  }
25444
- async function destroy6(id, rev) {
25460
+ async function destroy6(id, rev2) {
25445
25461
  const db2 = context_exports.getAppDB();
25446
25462
  if (!id || !isWebhookID(id)) {
25447
25463
  throw new Error("Provided webhook ID is not valid.");
25448
25464
  }
25449
- return await db2.remove(id, rev);
25465
+ return await db2.remove(id, rev2);
25450
25466
  }
25451
25467
  var init_webhook2 = __esm({
25452
25468
  "src/sdk/app/automations/webhook.ts"() {
@@ -25623,9 +25639,9 @@ async function syncUsersToApp(appId, users2, groups) {
25623
25639
  if (roleId === roles_exports.BUILTIN_ROLE_IDS.PUBLIC) {
25624
25640
  roleId = void 0;
25625
25641
  }
25626
- let metadata;
25642
+ let metadata2;
25627
25643
  try {
25628
- metadata = await db2.get(metadataId);
25644
+ metadata2 = await db2.get(metadataId);
25629
25645
  } catch (err) {
25630
25646
  if (err.status !== 404) {
25631
25647
  throw err;
@@ -25633,19 +25649,19 @@ async function syncUsersToApp(appId, users2, groups) {
25633
25649
  if (!roleId) {
25634
25650
  continue;
25635
25651
  } else if (!deletedUser) {
25636
- metadata = {
25652
+ metadata2 = {
25637
25653
  tableId: InternalTables.USER_METADATA
25638
25654
  };
25639
25655
  }
25640
25656
  }
25641
25657
  if (deletedUser || !roleId) {
25642
- await db2.remove(metadata);
25658
+ await db2.remove(metadata2);
25643
25659
  continue;
25644
25660
  }
25645
25661
  if (roleId) {
25646
- metadata.roleId = roleId;
25662
+ metadata2.roleId = roleId;
25647
25663
  }
25648
- let combined = sdk_default.users.combineMetadataAndUser(ctxUser, metadata);
25664
+ let combined = sdk_default.users.combineMetadataAndUser(ctxUser, metadata2);
25649
25665
  if (combined) {
25650
25666
  await db2.put(combined);
25651
25667
  }
@@ -25702,7 +25718,7 @@ async function syncApp(appId, opts) {
25702
25718
  try {
25703
25719
  const replOpts = replication.appReplicateOpts();
25704
25720
  if (opts == null ? void 0 : opts.automationOnly) {
25705
- replOpts.filter = (doc) => doc._id.startsWith(db_exports.DocumentType.AUTOMATION);
25721
+ replOpts.filter = (doc2) => doc2._id.startsWith(db_exports.DocumentType.AUTOMATION);
25706
25722
  }
25707
25723
  await replication.replicate(replOpts);
25708
25724
  } catch (err) {
@@ -25929,9 +25945,9 @@ __export(utils_exports8, {
25929
25945
  rawUserMetadata: () => rawUserMetadata,
25930
25946
  syncGlobalUsers: () => syncGlobalUsers
25931
25947
  });
25932
- function combineMetadataAndUser(user, metadata) {
25948
+ function combineMetadataAndUser(user, metadata2) {
25933
25949
  const metadataId = generateUserMetadataID2(user._id);
25934
- const found = Array.isArray(metadata) ? metadata.find((doc) => doc._id === metadataId) : metadata;
25950
+ const found = Array.isArray(metadata2) ? metadata2.find((doc2) => doc2._id === metadataId) : metadata2;
25935
25951
  if (user.roleId == null || user.roleId === roles_exports.BUILTIN_ROLE_IDS.PUBLIC) {
25936
25952
  if (found == null ? void 0 : found._id) {
25937
25953
  return { ...found, _deleted: true };
@@ -25976,16 +25992,16 @@ async function syncGlobalUsers() {
25976
25992
  }
25977
25993
  const resp = await Promise.all([getGlobalUsers(), rawUserMetadata(db2)]);
25978
25994
  const users2 = resp[0];
25979
- const metadata = resp[1];
25995
+ const metadata2 = resp[1];
25980
25996
  const toWrite = [];
25981
25997
  for (let user of users2) {
25982
- const combined = combineMetadataAndUser(user, metadata);
25998
+ const combined = combineMetadataAndUser(user, metadata2);
25983
25999
  if (combined) {
25984
26000
  toWrite.push(combined);
25985
26001
  }
25986
26002
  }
25987
26003
  let foundEmails = [];
25988
- for (let data2 of metadata) {
26004
+ for (let data2 of metadata2) {
25989
26005
  if (!data2._id) {
25990
26006
  continue;
25991
26007
  }
@@ -26114,17 +26130,17 @@ var init_client2 = __esm({
26114
26130
  // src/utilities/users.ts
26115
26131
  async function getFullUser(ctx, userId) {
26116
26132
  const global = await getGlobalUser(userId);
26117
- let metadata = {};
26133
+ let metadata2 = {};
26118
26134
  delete global._id;
26119
26135
  delete global._rev;
26120
26136
  try {
26121
26137
  const db2 = context_exports.getAppDB();
26122
- metadata = await db2.get(userId);
26138
+ metadata2 = await db2.get(userId);
26123
26139
  } catch (err) {
26124
26140
  }
26125
- delete metadata.csrfToken;
26141
+ delete metadata2.csrfToken;
26126
26142
  return {
26127
- ...metadata,
26143
+ ...metadata2,
26128
26144
  ...global,
26129
26145
  roleId: global.roleId || roles_exports.BUILTIN_ROLE_IDS.PUBLIC,
26130
26146
  tableId: InternalTables.USER_METADATA,
@@ -26143,10 +26159,10 @@ var init_users12 = __esm({
26143
26159
  // src/api/controllers/user.ts
26144
26160
  async function fetchMetadata(ctx) {
26145
26161
  const global = await getGlobalUsers();
26146
- const metadata = await sdk_default.users.rawUserMetadata();
26162
+ const metadata2 = await sdk_default.users.rawUserMetadata();
26147
26163
  const users2 = [];
26148
26164
  for (let user of global) {
26149
- const info = metadata.find((meta) => meta._id.includes(user._id));
26165
+ const info = metadata2.find((meta) => meta._id.includes(user._id));
26150
26166
  users2.push({
26151
26167
  ...user,
26152
26168
  ...info,
@@ -26161,11 +26177,11 @@ async function updateMetadata(ctx) {
26161
26177
  const db2 = context_exports.getAppDB();
26162
26178
  const user = ctx.request.body;
26163
26179
  delete user.roles;
26164
- const metadata = {
26180
+ const metadata2 = {
26165
26181
  tableId: InternalTables.USER_METADATA,
26166
26182
  ...user
26167
26183
  };
26168
- ctx.body = await db2.put(metadata);
26184
+ ctx.body = await db2.put(metadata2);
26169
26185
  }
26170
26186
  async function destroyMetadata(ctx) {
26171
26187
  const db2 = context_exports.getAppDB();
@@ -26463,16 +26479,16 @@ async function fetch16(type) {
26463
26479
  return plugins2;
26464
26480
  }
26465
26481
  }
26466
- async function processUploaded(plugin, source) {
26482
+ async function processUploaded(plugin, source2) {
26467
26483
  var _a, _b;
26468
- const { metadata, directory } = await fileUpload(plugin);
26469
- plugin_exports.validate(metadata == null ? void 0 : metadata.schema);
26470
- if (!environment_default.SELF_HOSTED && ((_a = metadata == null ? void 0 : metadata.schema) == null ? void 0 : _a.type) !== "component" /* COMPONENT */) {
26484
+ const { metadata: metadata2, directory: directory2 } = await fileUpload(plugin);
26485
+ plugin_exports.validate(metadata2 == null ? void 0 : metadata2.schema);
26486
+ if (!environment_default.SELF_HOSTED && ((_a = metadata2 == null ? void 0 : metadata2.schema) == null ? void 0 : _a.type) !== "component" /* COMPONENT */) {
26471
26487
  throw new Error("Only component plugins are supported outside of self-host");
26472
26488
  }
26473
- const doc = await sdk_exports.plugins.storePlugin(metadata, directory, source);
26474
- (_b = clientAppSocket) == null ? void 0 : _b.emit("plugin-update", { name: doc.name, hash: doc.hash });
26475
- return doc;
26489
+ const doc2 = await sdk_exports.plugins.storePlugin(metadata2, directory2, source2);
26490
+ (_b = clientAppSocket) == null ? void 0 : _b.emit("plugin-update", { name: doc2.name, hash: doc2.hash });
26491
+ return doc2;
26476
26492
  }
26477
26493
  var init_plugins4 = __esm({
26478
26494
  "src/sdk/plugins/plugins.ts"() {
@@ -27514,20 +27530,20 @@ async function createLinkView() {
27514
27530
  const db2 = context_exports.getAppDB();
27515
27531
  const designDoc = await db2.get("_design/database");
27516
27532
  const view2 = {
27517
- map: function(doc) {
27518
- if (doc.type === "link") {
27519
- let doc1 = doc.doc1;
27520
- let doc2 = doc.doc2;
27533
+ map: function(doc2) {
27534
+ if (doc2.type === "link") {
27535
+ let doc1 = doc2.doc1;
27536
+ let doc22 = doc2.doc2;
27521
27537
  emit([doc1.tableId, doc1.rowId], {
27522
- id: doc2.rowId,
27538
+ id: doc22.rowId,
27523
27539
  thisId: doc1.rowId,
27524
27540
  fieldName: doc1.fieldName
27525
27541
  });
27526
- if (doc1.tableId !== doc2.tableId) {
27527
- emit([doc2.tableId, doc2.rowId], {
27542
+ if (doc1.tableId !== doc22.tableId) {
27543
+ emit([doc22.tableId, doc22.rowId], {
27528
27544
  id: doc1.rowId,
27529
- thisId: doc2.rowId,
27530
- fieldName: doc2.fieldName
27545
+ thisId: doc22.rowId,
27546
+ fieldName: doc22.fieldName
27531
27547
  });
27532
27548
  }
27533
27549
  }
@@ -27829,11 +27845,11 @@ var LinkController = class {
27829
27845
  );
27830
27846
  }
27831
27847
  }
27832
- let toDeleteDocs = thisFieldLinkDocs.filter((doc) => {
27833
- let correctDoc = doc.doc1.fieldName === fieldName ? doc.doc2 : doc.doc1;
27848
+ let toDeleteDocs = thisFieldLinkDocs.filter((doc2) => {
27849
+ let correctDoc = doc2.doc1.fieldName === fieldName ? doc2.doc2 : doc2.doc1;
27834
27850
  return rowField.indexOf(correctDoc.rowId) === -1;
27835
- }).map((doc) => {
27836
- return { ...doc, _deleted: true };
27851
+ }).map((doc2) => {
27852
+ return { ...doc2, _deleted: true };
27837
27853
  });
27838
27854
  operations.push(...toDeleteDocs);
27839
27855
  delete row[fieldName];
@@ -27854,9 +27870,9 @@ var LinkController = class {
27854
27870
  if (linkDocs.length === 0) {
27855
27871
  return null;
27856
27872
  }
27857
- const toDelete = linkDocs.map((doc) => {
27873
+ const toDelete = linkDocs.map((doc2) => {
27858
27874
  return {
27859
- ...doc,
27875
+ ...doc2,
27860
27876
  _deleted: true
27861
27877
  };
27862
27878
  });
@@ -27877,9 +27893,9 @@ var LinkController = class {
27877
27893
  return correctFieldName === fieldName;
27878
27894
  });
27879
27895
  await this._db.bulkDocs(
27880
- toDelete.map((doc) => {
27896
+ toDelete.map((doc2) => {
27881
27897
  return {
27882
- ...doc,
27898
+ ...doc2,
27883
27899
  _deleted: true
27884
27900
  };
27885
27901
  })
@@ -27977,9 +27993,9 @@ var LinkController = class {
27977
27993
  if (linkDocs.length === 0) {
27978
27994
  return null;
27979
27995
  }
27980
- const toDelete = linkDocs.map((doc) => {
27996
+ const toDelete = linkDocs.map((doc2) => {
27981
27997
  return {
27982
- ...doc,
27998
+ ...doc2,
27983
27999
  _deleted: true
27984
28000
  };
27985
28001
  });
@@ -28318,10 +28334,10 @@ async function cleanupAttachments(table, {
28318
28334
  return;
28319
28335
  }
28320
28336
  }
28321
- let files = [];
28337
+ let files2 = [];
28322
28338
  function addFiles(row2, key) {
28323
28339
  if (row2[key]) {
28324
- files = files.concat(row2[key].map((attachment) => attachment.key));
28340
+ files2 = files2.concat(row2[key].map((attachment) => attachment.key));
28325
28341
  }
28326
28342
  }
28327
28343
  const schemaToUse = oldTable ? oldTable.schema : table.schema;
@@ -28332,15 +28348,15 @@ async function cleanupAttachments(table, {
28332
28348
  if (rows2 && oldTable && !table.schema[key]) {
28333
28349
  rows2.forEach((row2) => addFiles(row2, key));
28334
28350
  } else if (oldRow && row) {
28335
- files = files.concat(getRemovedAttachmentKeys(oldRow, row, key));
28351
+ files2 = files2.concat(getRemovedAttachmentKeys(oldRow, row, key));
28336
28352
  } else if (row) {
28337
28353
  addFiles(row, key);
28338
28354
  } else if (rows2) {
28339
28355
  rows2.forEach((row2) => addFiles(row2, key));
28340
28356
  }
28341
28357
  }
28342
- if (files.length > 0) {
28343
- await objectStore_exports2.deleteFiles(ObjectStoreBuckets2.APPS, files);
28358
+ if (files2.length > 0) {
28359
+ await objectStore_exports2.deleteFiles(ObjectStoreBuckets2.APPS, files2);
28344
28360
  }
28345
28361
  }
28346
28362
 
@@ -28515,7 +28531,7 @@ async function runView(view, calculation, group, data) {
28515
28531
  _rev: void 0
28516
28532
  }))
28517
28533
  );
28518
- let fn = (doc, emit2) => emit2(doc._id);
28534
+ let fn = (doc2, emit2) => emit2(doc2._id);
28519
28535
  eval("fn = " + ((_a = view == null ? void 0 : view.map) == null ? void 0 : _a.replace("function (doc)", "function (doc, emit)")));
28520
28536
  const queryFns = {
28521
28537
  meta: view.meta,
@@ -29281,7 +29297,7 @@ function cleanupConfig(config, table) {
29281
29297
  const fieldNames = Object.entries(table.schema).filter((schema) => primaryOptions.find((val) => val === schema[1].type)).map(([fieldName]) => fieldName);
29282
29298
  const iterateObject = (obj) => {
29283
29299
  for (let [field, value] of Object.entries(obj)) {
29284
- if (fieldNames.find((name) => name === field) && isRowId(value)) {
29300
+ if (fieldNames.find((name2) => name2 === field) && isRowId(value)) {
29285
29301
  obj[field] = convertRowId(value);
29286
29302
  }
29287
29303
  }
@@ -29480,7 +29496,10 @@ var ExternalRequest = class {
29480
29496
  }
29481
29497
  }
29482
29498
  relatedRow = processFormulas(linkedTable, relatedRow);
29483
- const relatedDisplay = display ? relatedRow[display] : void 0;
29499
+ let relatedDisplay;
29500
+ if (display) {
29501
+ relatedDisplay = getPrimaryDisplay(relatedRow[display]);
29502
+ }
29484
29503
  row[relationship.column][key] = {
29485
29504
  primaryDisplay: relatedDisplay || "Invalid display column",
29486
29505
  _id: relatedRow._id
@@ -31987,7 +32006,7 @@ function rowEmission({
31987
32006
  appId,
31988
32007
  row,
31989
32008
  table,
31990
- metadata
32009
+ metadata: metadata2
31991
32010
  }) {
31992
32011
  let event = {
31993
32012
  row,
@@ -32001,8 +32020,8 @@ function rowEmission({
32001
32020
  if (row == null ? void 0 : row._rev) {
32002
32021
  event.revision = row._rev;
32003
32022
  }
32004
- if (metadata) {
32005
- event.metadata = metadata;
32023
+ if (metadata2) {
32024
+ event.metadata = metadata2;
32006
32025
  }
32007
32026
  emitter2.emit(eventName, event);
32008
32027
  }
@@ -32011,7 +32030,7 @@ function tableEmission({
32011
32030
  eventName,
32012
32031
  appId,
32013
32032
  table,
32014
- metadata
32033
+ metadata: metadata2
32015
32034
  }) {
32016
32035
  const tableId = table == null ? void 0 : table._id;
32017
32036
  const inputTable = table;
@@ -32027,8 +32046,8 @@ function tableEmission({
32027
32046
  if (table == null ? void 0 : table._rev) {
32028
32047
  event.revision = table._rev;
32029
32048
  }
32030
- if (metadata) {
32031
- event.metadata = metadata;
32049
+ if (metadata2) {
32050
+ event.metadata = metadata2;
32032
32051
  }
32033
32052
  emitter2.emit(eventName, event);
32034
32053
  }
@@ -32170,8 +32189,8 @@ var Orchestrator = class {
32170
32189
  constructor(job) {
32171
32190
  let automation = job.data.automation;
32172
32191
  let triggerOutput = job.data.event;
32173
- const metadata = triggerOutput.metadata;
32174
- this._chainCount = metadata ? metadata.automationChainCount : 0;
32192
+ const metadata2 = triggerOutput.metadata;
32193
+ this._chainCount = metadata2 ? metadata2.automationChainCount : 0;
32175
32194
  this._appId = triggerOutput.appId;
32176
32195
  this._job = job;
32177
32196
  const triggerStepId = automation.definition.trigger.stepId;
@@ -32201,16 +32220,16 @@ var Orchestrator = class {
32201
32220
  async getMetadata() {
32202
32221
  const metadataId = generateAutomationMetadataID(this._automation._id);
32203
32222
  const db2 = context_exports.getAppDB();
32204
- let metadata;
32223
+ let metadata2;
32205
32224
  try {
32206
- metadata = await db2.get(metadataId);
32225
+ metadata2 = await db2.get(metadataId);
32207
32226
  } catch (err) {
32208
- metadata = {
32227
+ metadata2 = {
32209
32228
  _id: metadataId,
32210
32229
  errorCount: 0
32211
32230
  };
32212
32231
  }
32213
- return metadata;
32232
+ return metadata2;
32214
32233
  }
32215
32234
  async stopCron(reason) {
32216
32235
  if (!this._job.opts.repeat) {
@@ -32233,34 +32252,34 @@ var Orchestrator = class {
32233
32252
  );
32234
32253
  await storeLog2(automation, this.executionOutput);
32235
32254
  }
32236
- async checkIfShouldStop(metadata) {
32237
- if (!metadata.errorCount || !this._job.opts.repeat) {
32255
+ async checkIfShouldStop(metadata2) {
32256
+ if (!metadata2.errorCount || !this._job.opts.repeat) {
32238
32257
  return false;
32239
32258
  }
32240
- if (metadata.errorCount >= MAX_AUTOMATION_RECURRING_ERRORS) {
32259
+ if (metadata2.errorCount >= MAX_AUTOMATION_RECURRING_ERRORS) {
32241
32260
  await this.stopCron("errors");
32242
32261
  return true;
32243
32262
  }
32244
32263
  return false;
32245
32264
  }
32246
- async updateMetadata(metadata) {
32265
+ async updateMetadata(metadata2) {
32247
32266
  const output = this.executionOutput, automation = this._automation;
32248
32267
  if (!output || !isRecurring(automation)) {
32249
32268
  return;
32250
32269
  }
32251
- const count = metadata.errorCount;
32270
+ const count = metadata2.errorCount;
32252
32271
  const isError = isErrorInOutput(output);
32253
32272
  if (!count && !isError) {
32254
32273
  return;
32255
32274
  }
32256
32275
  if (isError) {
32257
- metadata.errorCount = count ? count + 1 : 1;
32276
+ metadata2.errorCount = count ? count + 1 : 1;
32258
32277
  } else {
32259
- metadata.errorCount = 0;
32278
+ metadata2.errorCount = 0;
32260
32279
  }
32261
32280
  const db2 = context_exports.getAppDB();
32262
32281
  try {
32263
- await db2.put(metadata);
32282
+ await db2.put(metadata2);
32264
32283
  } catch (err) {
32265
32284
  logging_exports.logAlertWithInfo(
32266
32285
  "Failed to write automation metadata",
@@ -32311,13 +32330,13 @@ var Orchestrator = class {
32311
32330
  let stepCount = 0;
32312
32331
  let loopStepNumber = void 0;
32313
32332
  let loopSteps = [];
32314
- let metadata;
32333
+ let metadata2;
32315
32334
  let timeoutFlag = false;
32316
32335
  let wasLoopStep = false;
32317
32336
  let timeout2 = this._job.data.event.timeout;
32318
32337
  if (isProdAppID2(this._appId) && isRecurring(automation)) {
32319
- metadata = await this.getMetadata();
32320
- const shouldStop = await this.checkIfShouldStop(metadata);
32338
+ metadata2 = await this.getMetadata();
32339
+ const shouldStop = await this.checkIfShouldStop(metadata2);
32321
32340
  if (shouldStop) {
32322
32341
  return;
32323
32342
  }
@@ -32521,8 +32540,8 @@ var Orchestrator = class {
32521
32540
  }
32522
32541
  logging_exports.logAlert("Error writing automation log", e);
32523
32542
  }
32524
- if (isProdAppID2(this._appId) && isRecurring(automation) && metadata) {
32525
- await this.updateMetadata(metadata);
32543
+ if (isProdAppID2(this._appId) && isRecurring(automation) && metadata2) {
32544
+ await this.updateMetadata(metadata2);
32526
32545
  }
32527
32546
  return this.executionOutput;
32528
32547
  }