@budibase/server 2.7.16-alpha.0 → 2.7.16-alpha.2

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
  });
@@ -2065,12 +2065,12 @@ function getPouchDB(dbName, opts) {
2065
2065
  checkInitialised();
2066
2066
  const db2 = new Pouch(dbName, opts);
2067
2067
  const dbPut = db2.put;
2068
- db2.put = async (doc, options2 = {}) => {
2069
- if (!doc.createdAt) {
2070
- doc.createdAt = (/* @__PURE__ */ new Date()).toISOString();
2068
+ db2.put = async (doc2, options2 = {}) => {
2069
+ if (!doc2.createdAt) {
2070
+ doc2.createdAt = (/* @__PURE__ */ new Date()).toISOString();
2071
2071
  }
2072
- doc.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
2073
- return dbPut(doc, options2);
2072
+ doc2.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
2073
+ return dbPut(doc2, options2);
2074
2074
  };
2075
2075
  db2.exists = async () => {
2076
2076
  const info = await db2.info();
@@ -2240,7 +2240,7 @@ var init_DatabaseImpl = __esm({
2240
2240
  }
2241
2241
  return this.updateOutput(() => db2.get(id));
2242
2242
  }
2243
- async remove(idOrDoc, rev) {
2243
+ async remove(idOrDoc, rev2) {
2244
2244
  const db2 = await this.checkSetup();
2245
2245
  let _id;
2246
2246
  let _rev;
@@ -2249,7 +2249,7 @@ var init_DatabaseImpl = __esm({
2249
2249
  _rev = idOrDoc._rev;
2250
2250
  } else {
2251
2251
  _id = idOrDoc;
2252
- _rev = rev;
2252
+ _rev = rev2;
2253
2253
  }
2254
2254
  if (!_id || !_rev) {
2255
2255
  throw new Error("Unable to remove doc without a valid _id and _rev.");
@@ -3513,18 +3513,18 @@ async function newRedlock(opts = {}) {
3513
3513
  }
3514
3514
  function getLockName(opts) {
3515
3515
  const prefix = opts.systemLock ? "system" : getTenantId();
3516
- let name = `lock:${prefix}_${opts.name}`;
3516
+ let name2 = `lock:${prefix}_${opts.name}`;
3517
3517
  if (opts.resource) {
3518
- name = name + `_${opts.resource}`;
3518
+ name2 = name2 + `_${opts.resource}`;
3519
3519
  }
3520
- return name;
3520
+ return name2;
3521
3521
  }
3522
3522
  async function doWithLock(opts, task) {
3523
3523
  const redlock = await getClient(opts.type, opts.customOptions);
3524
3524
  let lock;
3525
3525
  try {
3526
- const name = getLockName(opts);
3527
- lock = await redlock.lock(name, opts.ttl);
3526
+ const name2 = getLockName(opts);
3527
+ lock = await redlock.lock(name2, opts.ttl);
3528
3528
  const result = await task();
3529
3529
  return { executed: true, result };
3530
3530
  } catch (e) {
@@ -4038,8 +4038,8 @@ var init_ids = __esm({
4038
4038
  generateDevInfoID = (userId) => {
4039
4039
  return `${"devinfo" /* DEV_INFO */}${SEPARATOR}${userId}`;
4040
4040
  };
4041
- generatePluginID = (name) => {
4042
- return `${"plg" /* PLUGIN */}${SEPARATOR}${name}`;
4041
+ generatePluginID = (name2) => {
4042
+ return `${"plg" /* PLUGIN */}${SEPARATOR}${name2}`;
4043
4043
  };
4044
4044
  }
4045
4045
  });
@@ -4129,8 +4129,8 @@ var init_params = __esm({
4129
4129
  isDatasourceId = (id) => {
4130
4130
  return id && id.startsWith(`${"datasource" /* DATASOURCE */}${SEPARATOR}`);
4131
4131
  };
4132
- getPluginParams = (pluginId, otherProps = {}) => {
4133
- return getDocParams("plg" /* PLUGIN */, pluginId, otherProps);
4132
+ getPluginParams = (pluginId2, otherProps = {}) => {
4133
+ return getDocParams("plg" /* PLUGIN */, pluginId2, otherProps);
4134
4134
  };
4135
4135
  }
4136
4136
  });
@@ -4267,7 +4267,7 @@ function pagination(data2, pageSize, {
4267
4267
  const hasNextPage = data2.length > pageSize;
4268
4268
  let nextPage = void 0;
4269
4269
  if (!getKey) {
4270
- getKey = (doc) => property ? doc == null ? void 0 : doc[property] : doc == null ? void 0 : doc._id;
4270
+ getKey = (doc2) => property ? doc2 == null ? void 0 : doc2[property] : doc2 == null ? void 0 : doc2._id;
4271
4271
  }
4272
4272
  if (hasNextPage) {
4273
4273
  nextPage = getKey(data2[pageSize]);
@@ -4485,8 +4485,8 @@ var init_Replication = __esm({
4485
4485
  * @param {String} source - the DB you want to replicate or rollback to
4486
4486
  * @param {String} target - the DB you want to replicate to, or rollback from
4487
4487
  */
4488
- constructor({ source, target }) {
4489
- this.source = getPouchDB(source);
4488
+ constructor({ source: source2, target }) {
4489
+ this.source = getPouchDB(source2);
4490
4490
  this.target = getPouchDB(target);
4491
4491
  }
4492
4492
  close() {
@@ -4521,8 +4521,8 @@ var init_Replication = __esm({
4521
4521
  }
4522
4522
  appReplicateOpts() {
4523
4523
  return {
4524
- filter: (doc) => {
4525
- return doc._id !== "app_metadata" /* APP_METADATA */;
4524
+ filter: (doc2) => {
4525
+ return doc2._id !== "app_metadata" /* APP_METADATA */;
4526
4526
  }
4527
4527
  };
4528
4528
  }
@@ -4703,9 +4703,9 @@ var init_lucene = __esm({
4703
4703
  __privateSet(this, _indexBuilder, builderFn);
4704
4704
  return this;
4705
4705
  }
4706
- setVersion(version) {
4707
- if (version != null) {
4708
- __privateSet(this, _version, version);
4706
+ setVersion(version2) {
4707
+ if (version2 != null) {
4708
+ __privateSet(this, _version, version2);
4709
4709
  }
4710
4710
  return this;
4711
4711
  }
@@ -5289,36 +5289,36 @@ async function populateFromDB2(appId) {
5289
5289
  { skip_setup: true }
5290
5290
  );
5291
5291
  }
5292
- function isInvalid(metadata) {
5293
- return !metadata || metadata.state === AppState.INVALID;
5292
+ function isInvalid(metadata2) {
5293
+ return !metadata2 || metadata2.state === AppState.INVALID;
5294
5294
  }
5295
5295
  async function getAppMetadata(appId) {
5296
5296
  const client3 = await getAppClient();
5297
- let metadata = await client3.get(appId);
5298
- if (!metadata) {
5297
+ let metadata2 = await client3.get(appId);
5298
+ if (!metadata2) {
5299
5299
  let expiry = EXPIRY_SECONDS2;
5300
5300
  try {
5301
- metadata = await populateFromDB2(appId);
5301
+ metadata2 = await populateFromDB2(appId);
5302
5302
  } catch (err) {
5303
5303
  if (err && err.status === 404) {
5304
- metadata = { state: AppState.INVALID };
5304
+ metadata2 = { state: AppState.INVALID };
5305
5305
  expiry = void 0;
5306
5306
  } else {
5307
5307
  throw err;
5308
5308
  }
5309
5309
  }
5310
- if (isInvalid(metadata)) {
5310
+ if (isInvalid(metadata2)) {
5311
5311
  const temp = await client3.get(appId);
5312
5312
  if (temp) {
5313
- metadata = temp;
5313
+ metadata2 = temp;
5314
5314
  }
5315
5315
  }
5316
- await client3.store(appId, metadata, expiry);
5316
+ await client3.store(appId, metadata2, expiry);
5317
5317
  }
5318
- if (isInvalid(metadata)) {
5318
+ if (isInvalid(metadata2)) {
5319
5319
  throw { status: 404, message: "No app metadata found" };
5320
5320
  }
5321
- return metadata;
5321
+ return metadata2;
5322
5322
  }
5323
5323
  async function invalidateAppMetadata(appId, newMetadata) {
5324
5324
  if (!appId) {
@@ -5357,18 +5357,18 @@ async function getCache() {
5357
5357
  function makeCacheKey(db2, key) {
5358
5358
  return db2.name + key;
5359
5359
  }
5360
- function makeCacheItem(doc, lastWrite = null) {
5361
- return { doc, lastWrite: lastWrite || Date.now() };
5360
+ function makeCacheItem(doc2, lastWrite = null) {
5361
+ return { doc: doc2, lastWrite: lastWrite || Date.now() };
5362
5362
  }
5363
- async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5363
+ async function put(db2, doc2, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5364
5364
  const cache3 = await getCache();
5365
- const key = doc._id;
5365
+ const key = doc2._id;
5366
5366
  let cacheItem;
5367
5367
  if (key) {
5368
5368
  cacheItem = await cache3.get(makeCacheKey(db2, key));
5369
5369
  }
5370
5370
  const updateDb = !cacheItem || cacheItem.lastWrite < Date.now() - writeRateMs;
5371
- let output = doc;
5371
+ let output = doc2;
5372
5372
  if (updateDb) {
5373
5373
  const lockResponse = await doWithLock(
5374
5374
  {
@@ -5381,13 +5381,13 @@ async function put(db2, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
5381
5381
  const writeDb = async (toWrite) => {
5382
5382
  const response2 = await db2.put(toWrite, { force: true });
5383
5383
  output = {
5384
- ...doc,
5384
+ ...doc2,
5385
5385
  _id: response2.id,
5386
5386
  _rev: response2.rev
5387
5387
  };
5388
5388
  };
5389
5389
  try {
5390
- await writeDb(doc);
5390
+ await writeDb(doc2);
5391
5391
  } catch (err) {
5392
5392
  if (err.status !== 409) {
5393
5393
  throw err;
@@ -5412,23 +5412,23 @@ async function get2(db2, id) {
5412
5412
  const cacheKey = makeCacheKey(db2, id);
5413
5413
  let cacheItem = await cache3.get(cacheKey);
5414
5414
  if (!cacheItem) {
5415
- const doc = await db2.get(id);
5416
- cacheItem = makeCacheItem(doc);
5415
+ const doc2 = await db2.get(id);
5416
+ cacheItem = makeCacheItem(doc2);
5417
5417
  await cache3.store(cacheKey, cacheItem);
5418
5418
  }
5419
5419
  return cacheItem.doc;
5420
5420
  }
5421
- async function remove(db2, docOrId, rev) {
5421
+ async function remove(db2, docOrId, rev2) {
5422
5422
  const cache3 = await getCache();
5423
5423
  if (!docOrId) {
5424
5424
  throw new Error("No ID/Rev provided.");
5425
5425
  }
5426
5426
  const id = typeof docOrId === "string" ? docOrId : docOrId._id;
5427
- rev = typeof docOrId === "string" ? rev : docOrId._rev;
5427
+ rev2 = typeof docOrId === "string" ? rev2 : docOrId._rev;
5428
5428
  try {
5429
5429
  await cache3.delete(makeCacheKey(db2, id));
5430
5430
  } finally {
5431
- await db2.remove(id, rev);
5431
+ await db2.remove(id, rev2);
5432
5432
  }
5433
5433
  }
5434
5434
  var DEFAULT_WRITE_RATE_MS, CACHE, Writethrough;
@@ -5446,14 +5446,14 @@ var init_writethrough = __esm({
5446
5446
  this.db = db2;
5447
5447
  this.writeRateMs = writeRateMs;
5448
5448
  }
5449
- async put(doc) {
5450
- return put(this.db, doc, this.writeRateMs);
5449
+ async put(doc2) {
5450
+ return put(this.db, doc2, this.writeRateMs);
5451
5451
  }
5452
5452
  async get(id) {
5453
5453
  return get2(this.db, id);
5454
5454
  }
5455
- async remove(docOrId, rev) {
5456
- return remove(this.db, docOrId, rev);
5455
+ async remove(docOrId, rev2) {
5456
+ return remove(this.db, docOrId, rev2);
5457
5457
  }
5458
5458
  };
5459
5459
  }
@@ -5952,7 +5952,7 @@ var init_LoggingProcessor = __esm({
5952
5952
  });
5953
5953
 
5954
5954
  // ../backend-core/src/utils/hashing.ts
5955
- async function hash(data2) {
5955
+ async function hash2(data2) {
5956
5956
  const salt = await bcrypt.genSalt(SALT_ROUNDS);
5957
5957
  return bcrypt.hash(data2, salt);
5958
5958
  }
@@ -6066,14 +6066,14 @@ function isValidInternalAPIKey(apiKey) {
6066
6066
  }
6067
6067
  return false;
6068
6068
  }
6069
- function getCookie(ctx, name) {
6070
- const cookie = ctx.cookies.get(name);
6069
+ function getCookie(ctx, name2) {
6070
+ const cookie = ctx.cookies.get(name2);
6071
6071
  if (!cookie) {
6072
6072
  return cookie;
6073
6073
  }
6074
6074
  return openJwt(cookie);
6075
6075
  }
6076
- function setCookie(ctx, value, name = "builder", opts = { sign: true }) {
6076
+ function setCookie(ctx, value, name2 = "builder", opts = { sign: true }) {
6077
6077
  if (value && opts && opts.sign) {
6078
6078
  value = jwt.sign(value, environment_default2.JWT_SECRET);
6079
6079
  }
@@ -6086,10 +6086,10 @@ function setCookie(ctx, value, name = "builder", opts = { sign: true }) {
6086
6086
  if (environment_default2.COOKIE_DOMAIN) {
6087
6087
  config.domain = environment_default2.COOKIE_DOMAIN;
6088
6088
  }
6089
- ctx.cookies.set(name, value, config);
6089
+ ctx.cookies.set(name2, value, config);
6090
6090
  }
6091
- function clearCookie(ctx, name) {
6092
- setCookie(ctx, null, name);
6091
+ function clearCookie(ctx, name2) {
6092
+ setCookie(ctx, null, name2);
6093
6093
  }
6094
6094
  function isClient(ctx) {
6095
6095
  return ctx.headers["x-budibase-type" /* TYPE */] === "client";
@@ -6137,7 +6137,7 @@ __export(utils_exports2, {
6137
6137
  compare: () => compare,
6138
6138
  getAppIdFromCtx: () => getAppIdFromCtx,
6139
6139
  getCookie: () => getCookie,
6140
- hash: () => hash,
6140
+ hash: () => hash2,
6141
6141
  isAudited: () => isAudited,
6142
6142
  isClient: () => isClient,
6143
6143
  isPublicApiRequest: () => isPublicApiRequest,
@@ -6180,8 +6180,8 @@ var init_inMemoryQueue = __esm({
6180
6180
  * @param {object|null} opts This is not used by the in memory queue as there is no real use
6181
6181
  * case when in memory, but is the same API as Bull
6182
6182
  */
6183
- constructor(name, opts = null) {
6184
- this._name = name;
6183
+ constructor(name2, opts = null) {
6184
+ this._name = name2;
6185
6185
  this._opts = opts;
6186
6186
  this._messages = [];
6187
6187
  this._emitter = new import_events2.default.EventEmitter();
@@ -6678,13 +6678,13 @@ var init_installation = __esm({
6678
6678
  }
6679
6679
  );
6680
6680
  };
6681
- updateVersion = async (version) => {
6681
+ updateVersion = async (version2) => {
6682
6682
  try {
6683
6683
  await doWithDB(
6684
6684
  StaticDatabases.PLATFORM_INFO.name,
6685
6685
  async (platformDb) => {
6686
6686
  const install = await getInstall();
6687
- install.version = version;
6687
+ install.version = version2;
6688
6688
  await platformDb.put(install);
6689
6689
  await bustCache("installation" /* INSTALLATION */);
6690
6690
  }
@@ -6800,13 +6800,13 @@ var init_identification2 = __esm({
6800
6800
  const id = installId;
6801
6801
  const type = "installation" /* INSTALLATION */;
6802
6802
  const hosting = getHostingFromEnv();
6803
- const version = environment_default2.VERSION;
6803
+ const version2 = environment_default2.VERSION;
6804
6804
  const environment3 = getDeploymentEnvironment();
6805
6805
  const group2 = {
6806
6806
  id,
6807
6807
  type,
6808
6808
  hosting,
6809
- version,
6809
+ version: version2,
6810
6810
  environment: environment3
6811
6811
  };
6812
6812
  await identifyGroup(group2, timestamp);
@@ -6986,10 +6986,10 @@ var init_backfill2 = __esm({
6986
6986
  init_generic();
6987
6987
  init_generic();
6988
6988
  start = async (events2) => {
6989
- const metadata = {
6989
+ const metadata2 = {
6990
6990
  eventWhitelist: events2
6991
6991
  };
6992
- return saveBackfillMetadata(metadata);
6992
+ return saveBackfillMetadata(metadata2);
6993
6993
  };
6994
6994
  recordEvent2 = async (event, properties) => {
6995
6995
  const eventKey2 = getEventKey(event, properties);
@@ -7339,11 +7339,11 @@ var init_app5 = __esm({
7339
7339
  });
7340
7340
 
7341
7341
  // ../backend-core/src/events/publishers/auth.ts
7342
- async function login(source, email) {
7342
+ async function login(source2, email) {
7343
7343
  const identity = await identification_default.getCurrentIdentity();
7344
7344
  const properties = {
7345
7345
  userId: identity.id,
7346
- source,
7346
+ source: source2,
7347
7347
  audited: {
7348
7348
  email
7349
7349
  }
@@ -8223,9 +8223,9 @@ var init_view3 = __esm({
8223
8223
  });
8224
8224
 
8225
8225
  // ../backend-core/src/events/publishers/installation.ts
8226
- async function versionChecked(version) {
8226
+ async function versionChecked(version2) {
8227
8227
  const properties = {
8228
- currentVersion: version
8228
+ currentVersion: version2
8229
8229
  };
8230
8230
  await publishEvent("installation:version:checked" /* INSTALLATION_VERSION_CHECKED */, properties);
8231
8231
  }
@@ -8468,13 +8468,13 @@ async function appBackupRestored(backup) {
8468
8468
  };
8469
8469
  await publishEvent("app:backup:restored" /* APP_BACKUP_RESTORED */, properties);
8470
8470
  }
8471
- async function appBackupTriggered(appId, backupId, type, trigger, name) {
8471
+ async function appBackupTriggered(appId, backupId, type, trigger, name2) {
8472
8472
  const properties = {
8473
8473
  appId,
8474
8474
  backupId,
8475
8475
  type,
8476
8476
  trigger,
8477
- name
8477
+ name: name2
8478
8478
  };
8479
8479
  await publishEvent("app:backup:triggered" /* APP_BACKUP_TRIGGERED */, properties);
8480
8480
  }
@@ -8491,16 +8491,16 @@ var init_backup4 = __esm({
8491
8491
  });
8492
8492
 
8493
8493
  // ../backend-core/src/events/publishers/environmentVariable.ts
8494
- async function created14(name, environments) {
8494
+ async function created14(name2, environments) {
8495
8495
  const properties = {
8496
- name,
8496
+ name: name2,
8497
8497
  environments
8498
8498
  };
8499
8499
  await publishEvent("environment_variable:created" /* ENVIRONMENT_VARIABLE_CREATED */, properties);
8500
8500
  }
8501
- async function deleted14(name) {
8501
+ async function deleted14(name2) {
8502
8502
  const properties = {
8503
- name
8503
+ name: name2
8504
8504
  };
8505
8505
  await publishEvent("environment_variable:deleted" /* ENVIRONMENT_VARIABLE_DELETED */, properties);
8506
8506
  }
@@ -8879,7 +8879,7 @@ var init_users4 = __esm({
8879
8879
  let userList, property = "_id", getKey;
8880
8880
  if (appId) {
8881
8881
  userList = await searchGlobalUsersByApp(appId, opts);
8882
- getKey = (doc) => getGlobalUserByAppPage(appId, doc);
8882
+ getKey = (doc2) => getGlobalUserByAppPage(appId, doc2);
8883
8883
  } else if (email) {
8884
8884
  userList = await searchGlobalUsersByEmail(email, opts);
8885
8885
  property = "email";
@@ -9187,10 +9187,10 @@ var init_roles = __esm({
9187
9187
  BUILTIN_IDS.PUBLIC
9188
9188
  ];
9189
9189
  Role2 = class {
9190
- constructor(id, name, permissionId) {
9190
+ constructor(id, name2, permissionId) {
9191
9191
  this.permissions = {};
9192
9192
  this._id = id;
9193
- this.name = name;
9193
+ this.name = name2;
9194
9194
  this.permissionId = permissionId;
9195
9195
  }
9196
9196
  addInheritance(inherits) {
@@ -9556,12 +9556,12 @@ async function syncUser(user, details) {
9556
9556
  if (details.profile) {
9557
9557
  const profile = details.profile;
9558
9558
  if (profile.name) {
9559
- const name = profile.name;
9560
- if (name.givenName) {
9561
- firstName = name.givenName;
9559
+ const name2 = profile.name;
9560
+ if (name2.givenName) {
9561
+ firstName = name2.givenName;
9562
9562
  }
9563
- if (name.familyName) {
9564
- lastName = name.familyName;
9563
+ if (name2.familyName) {
9564
+ lastName = name2.familyName;
9565
9565
  }
9566
9566
  }
9567
9567
  pictureUrl = await getProfilePictureUrl(user, details);
@@ -10156,7 +10156,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
10156
10156
  const noAuthOptions = noAuthPatterns ? buildMatcherRegex(noAuthPatterns) : [];
10157
10157
  return async (ctx, next) => {
10158
10158
  let publicEndpoint = false;
10159
- const version = ctx.request.headers["x-budibase-api-version" /* API_VER */];
10159
+ const version2 = ctx.request.headers["x-budibase-api-version" /* API_VER */];
10160
10160
  const found = matches(ctx, noAuthOptions);
10161
10161
  if (found) {
10162
10162
  publicEndpoint = true;
@@ -10219,7 +10219,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
10219
10219
  if (!authenticated) {
10220
10220
  authenticated = false;
10221
10221
  }
10222
- finalise(ctx, { authenticated, user, internal, version, publicEndpoint });
10222
+ finalise(ctx, { authenticated, user, internal, version: version2, publicEndpoint });
10223
10223
  if (user && user.email) {
10224
10224
  return doInUserContext(user, ctx, next);
10225
10225
  } else {
@@ -10234,7 +10234,7 @@ function authenticated_default(noAuthPatterns = [], opts = {
10234
10234
  ctx.throw(403, err.message);
10235
10235
  }
10236
10236
  if (opts && opts.publicAllowed || publicEndpoint) {
10237
- finalise(ctx, { authenticated: false, version, publicEndpoint });
10237
+ finalise(ctx, { authenticated: false, version: version2, publicEndpoint });
10238
10238
  return next();
10239
10239
  } else {
10240
10240
  ctx.throw(err.status || 403, err);
@@ -11048,7 +11048,7 @@ var init_objectStore = __esm({
11048
11048
  filename,
11049
11049
  path: path2,
11050
11050
  type,
11051
- metadata
11051
+ metadata: metadata2
11052
11052
  }) => {
11053
11053
  const extension = filename.split(".").pop();
11054
11054
  const fileBytes = import_fs4.default.readFileSync(path2);
@@ -11064,13 +11064,13 @@ var init_objectStore = __esm({
11064
11064
  Body: fileBytes,
11065
11065
  ContentType: contentType
11066
11066
  };
11067
- if (metadata && typeof metadata === "object") {
11068
- for (let key of Object.keys(metadata)) {
11069
- if (!metadata[key] || typeof metadata[key] !== "string") {
11070
- delete metadata[key];
11067
+ if (metadata2 && typeof metadata2 === "object") {
11068
+ for (let key of Object.keys(metadata2)) {
11069
+ if (!metadata2[key] || typeof metadata2[key] !== "string") {
11070
+ delete metadata2[key];
11071
11071
  }
11072
11072
  }
11073
- config.Metadata = metadata;
11073
+ config.Metadata = metadata2;
11074
11074
  }
11075
11075
  return objectStore.upload(config).promise();
11076
11076
  };
@@ -11224,12 +11224,12 @@ var init_objectStore = __esm({
11224
11224
  return deleteFolder(bucketName, folder);
11225
11225
  }
11226
11226
  };
11227
- uploadDirectory = async (bucketName, localPath, bucketPath) => {
11227
+ uploadDirectory = async (bucketName, localPath, bucketPath2) => {
11228
11228
  bucketName = sanitizeBucket(bucketName);
11229
11229
  let uploads = [];
11230
- const files = import_fs4.default.readdirSync(localPath, { withFileTypes: true });
11231
- for (let file of files) {
11232
- const path2 = sanitizeKey((0, import_path4.join)(bucketPath, file.name));
11230
+ const files2 = import_fs4.default.readdirSync(localPath, { withFileTypes: true });
11231
+ for (let file of files2) {
11232
+ const path2 = sanitizeKey((0, import_path4.join)(bucketPath2, file.name));
11233
11233
  const local = (0, import_path4.join)(localPath, file.name);
11234
11234
  if (file.isDirectory()) {
11235
11235
  uploads.push(uploadDirectory(bucketName, local, path2));
@@ -11238,7 +11238,7 @@ var init_objectStore = __esm({
11238
11238
  }
11239
11239
  }
11240
11240
  await Promise.all(uploads);
11241
- return files;
11241
+ return files2;
11242
11242
  };
11243
11243
  downloadTarballDirect = async (url, path2, headers = {}) => {
11244
11244
  path2 = sanitizeKey(path2);
@@ -11312,12 +11312,12 @@ var init_app6 = __esm({
11312
11312
  init_environment3();
11313
11313
  init_objectStore();
11314
11314
  init_cloudfront();
11315
- clientLibraryUrl = (appId, version) => {
11315
+ clientLibraryUrl = (appId, version2) => {
11316
11316
  if (environment_default2.isProd()) {
11317
11317
  let file = `${sanitizeKey(appId)}/budibase-client.js`;
11318
11318
  if (environment_default2.CLOUDFRONT_CDN) {
11319
- if (version) {
11320
- file += `?v=${version}`;
11319
+ if (version2) {
11320
+ file += `?v=${version2}`;
11321
11321
  }
11322
11322
  return getUrl(file);
11323
11323
  } else {
@@ -11345,8 +11345,8 @@ var init_global3 = __esm({
11345
11345
  init_context2();
11346
11346
  init_objectStore();
11347
11347
  init_cloudfront();
11348
- getGlobalFileUrl = (type, name, etag) => {
11349
- let file = getGlobalFileS3Key(type, name);
11348
+ getGlobalFileUrl = (type, name2, etag) => {
11349
+ let file = getGlobalFileS3Key(type, name2);
11350
11350
  if (environment_default2.CLOUDFRONT_CDN) {
11351
11351
  if (etag) {
11352
11352
  file = `${file}?etag=${etag}`;
@@ -11356,8 +11356,8 @@ var init_global3 = __esm({
11356
11356
  return getPresignedUrl(environment_default2.GLOBAL_BUCKET_NAME, file);
11357
11357
  }
11358
11358
  };
11359
- getGlobalFileS3Key = (type, name) => {
11360
- let file = `${type}/${name}`;
11359
+ getGlobalFileS3Key = (type, name2) => {
11360
+ let file = `${type}/${name2}`;
11361
11361
  if (environment_default2.MULTI_TENANCY) {
11362
11362
  const tenantId = getTenantId();
11363
11363
  file = `${tenantId}/${file}`;
@@ -11407,11 +11407,11 @@ var init_plugins = __esm({
11407
11407
  return getPluginS3Key(plugin, "plugin.min.js");
11408
11408
  };
11409
11409
  getPluginIconKey = (plugin) => {
11410
- const iconFileName = plugin.iconUrl ? "icon.svg" : plugin.iconFileName;
11411
- if (!iconFileName) {
11410
+ const iconFileName2 = plugin.iconUrl ? "icon.svg" : plugin.iconFileName;
11411
+ if (!iconFileName2) {
11412
11412
  return;
11413
11413
  }
11414
- return getPluginS3Key(plugin, iconFileName);
11414
+ return getPluginS3Key(plugin, iconFileName2);
11415
11415
  };
11416
11416
  getPluginS3Key = (plugin, fileName) => {
11417
11417
  const s3Key = getPluginS3Dir(plugin.name);
@@ -11842,11 +11842,11 @@ var init_utils9 = __esm({
11842
11842
  }
11843
11843
  usage.monthly.current = usage.monthly[currentMonth];
11844
11844
  };
11845
- getBreakdownName = (name, id) => {
11846
- if (!id || !name) {
11845
+ getBreakdownName = (name2, id) => {
11846
+ if (!id || !name2) {
11847
11847
  return;
11848
11848
  }
11849
- switch (name) {
11849
+ switch (name2) {
11850
11850
  case "automations" /* AUTOMATIONS */:
11851
11851
  return "automations" /* AUTOMATIONS */;
11852
11852
  case "queries" /* QUERIES */:
@@ -11908,17 +11908,17 @@ var init_quotas2 = __esm({
11908
11908
  delete usage.usageQuota.developers;
11909
11909
  return usage;
11910
11910
  };
11911
- setUsage = async (value, name, type) => {
11912
- return setAllUsage(name, type, { total: value });
11911
+ setUsage = async (value, name2, type) => {
11912
+ return setAllUsage(name2, type, { total: value });
11913
11913
  };
11914
- setUsagePerApp = async (appValues, name, type) => {
11914
+ setUsagePerApp = async (appValues, name2, type) => {
11915
11915
  const db2 = getDB2();
11916
11916
  let quotaUsage = await getQuotaUsage();
11917
11917
  const total = Object.values(appValues).reduce((sum, num) => sum + num, 0);
11918
11918
  for (let [appId, value] of Object.entries(appValues)) {
11919
11919
  quotaUsage = coreUsageUpdate(
11920
11920
  quotaUsage,
11921
- name,
11921
+ name2,
11922
11922
  type,
11923
11923
  {
11924
11924
  total,
@@ -11933,8 +11933,8 @@ var init_quotas2 = __esm({
11933
11933
  quotaUsage._rev = response2.rev;
11934
11934
  return quotaUsage;
11935
11935
  };
11936
- setBreakdown = (monthUsage, name, id, values) => {
11937
- const breakdownName = getBreakdownName(name, id);
11936
+ setBreakdown = (monthUsage, name2, id, values) => {
11937
+ const breakdownName = getBreakdownName(name2, id);
11938
11938
  if (!breakdownName || !(values == null ? void 0 : values.breakdown)) {
11939
11939
  return monthUsage;
11940
11940
  }
@@ -11943,7 +11943,7 @@ var init_quotas2 = __esm({
11943
11943
  }
11944
11944
  if (!monthUsage.breakdown[breakdownName]) {
11945
11945
  monthUsage.breakdown[breakdownName] = {
11946
- parent: name,
11946
+ parent: name2,
11947
11947
  values: {}
11948
11948
  };
11949
11949
  }
@@ -11951,14 +11951,14 @@ var init_quotas2 = __esm({
11951
11951
  breakdown.values[id] = values.breakdown;
11952
11952
  return monthUsage;
11953
11953
  };
11954
- setAppUsageValue = (quotaUsage, name, type, opts = {}, values) => {
11954
+ setAppUsageValue = (quotaUsage, name2, type, opts = {}, values) => {
11955
11955
  var _a;
11956
11956
  let appId;
11957
11957
  try {
11958
11958
  appId = db_exports.getProdAppID((opts == null ? void 0 : opts.appId) || context_exports.getAppId());
11959
11959
  } catch (err) {
11960
11960
  }
11961
- if (!appId || !values.app || !APP_QUOTA_NAMES.includes(name)) {
11961
+ if (!appId || !values.app || !APP_QUOTA_NAMES.includes(name2)) {
11962
11962
  return quotaUsage;
11963
11963
  }
11964
11964
  if (!((_a = quotaUsage.apps) == null ? void 0 : _a[appId])) {
@@ -11970,11 +11970,11 @@ var init_quotas2 = __esm({
11970
11970
  const appUsage = quotaUsage.apps[appId];
11971
11971
  switch (type) {
11972
11972
  case "static" /* STATIC */:
11973
- appUsage.usageQuota[name] = values.app;
11973
+ appUsage.usageQuota[name2] = values.app;
11974
11974
  break;
11975
11975
  case "monthly" /* MONTHLY */:
11976
11976
  const currentMonth = getCurrentMonthString();
11977
- const monthlyName = name;
11977
+ const monthlyName = name2;
11978
11978
  let monthUsage = appUsage.monthly[currentMonth];
11979
11979
  if (!monthUsage) {
11980
11980
  appUsage.monthly[currentMonth] = generateNewMonthlyQuotas();
@@ -11988,9 +11988,9 @@ var init_quotas2 = __esm({
11988
11988
  }
11989
11989
  return quotaUsage;
11990
11990
  };
11991
- getAppUsageValue = (quotaUsage, type, name, id) => {
11991
+ getAppUsageValue = (quotaUsage, type, name2, id) => {
11992
11992
  var _a, _b, _c, _d, _e;
11993
- if (!APP_QUOTA_NAMES.includes(name)) {
11993
+ if (!APP_QUOTA_NAMES.includes(name2)) {
11994
11994
  return {};
11995
11995
  }
11996
11996
  let appId;
@@ -12004,13 +12004,13 @@ var init_quotas2 = __esm({
12004
12004
  const appUsage = quotaUsage.apps[appId];
12005
12005
  switch (type) {
12006
12006
  case "static" /* STATIC */:
12007
- if ((_a = appUsage.usageQuota) == null ? void 0 : _a[name]) {
12008
- return { app: appUsage.usageQuota[name] };
12007
+ if ((_a = appUsage.usageQuota) == null ? void 0 : _a[name2]) {
12008
+ return { app: appUsage.usageQuota[name2] };
12009
12009
  }
12010
12010
  break;
12011
12011
  case "monthly" /* MONTHLY */:
12012
12012
  const currentMonth = getCurrentMonthString();
12013
- const monthlyName = name;
12013
+ const monthlyName = name2;
12014
12014
  if (!((_c = (_b = appUsage.monthly) == null ? void 0 : _b[currentMonth]) == null ? void 0 : _c[monthlyName])) {
12015
12015
  break;
12016
12016
  }
@@ -12025,68 +12025,68 @@ var init_quotas2 = __esm({
12025
12025
  }
12026
12026
  return { app: 0 };
12027
12027
  };
12028
- setStaticTriggers = (name, quotaUsage, triggers) => {
12028
+ setStaticTriggers = (name2, quotaUsage, triggers) => {
12029
12029
  if (!quotaUsage.usageQuota.triggers) {
12030
12030
  quotaUsage.usageQuota.triggers = {};
12031
12031
  }
12032
12032
  if (triggers) {
12033
- quotaUsage.usageQuota.triggers[name] = triggers;
12033
+ quotaUsage.usageQuota.triggers[name2] = triggers;
12034
12034
  }
12035
12035
  };
12036
- setMonthlyTriggers = (name, currentMonth, quotaUsage, triggers) => {
12036
+ setMonthlyTriggers = (name2, currentMonth, quotaUsage, triggers) => {
12037
12037
  if (!quotaUsage.monthly[currentMonth].triggers) {
12038
12038
  quotaUsage.monthly[currentMonth].triggers = {};
12039
12039
  }
12040
12040
  if (triggers) {
12041
- quotaUsage.monthly[currentMonth].triggers[name] = triggers;
12041
+ quotaUsage.monthly[currentMonth].triggers[name2] = triggers;
12042
12042
  }
12043
12043
  };
12044
- coreUsageUpdate = (quotaUsage, name, type, values, opts = {}) => {
12044
+ coreUsageUpdate = (quotaUsage, name2, type, values, opts = {}) => {
12045
12045
  if (type === "static" /* STATIC */) {
12046
- name = name;
12047
- quotaUsage.usageQuota[name] = values.total;
12048
- setStaticTriggers(name, quotaUsage, values.triggers);
12046
+ name2 = name2;
12047
+ quotaUsage.usageQuota[name2] = values.total;
12048
+ setStaticTriggers(name2, quotaUsage, values.triggers);
12049
12049
  } else if (type === "monthly" /* MONTHLY */) {
12050
- name = name;
12050
+ name2 = name2;
12051
12051
  const currentMonth = getCurrentMonthString();
12052
- quotaUsage.monthly[currentMonth][name] = values.total;
12053
- setMonthlyTriggers(name, currentMonth, quotaUsage, values.triggers);
12052
+ quotaUsage.monthly[currentMonth][name2] = values.total;
12053
+ setMonthlyTriggers(name2, currentMonth, quotaUsage, values.triggers);
12054
12054
  } else {
12055
12055
  throw new Error(`Invalid usage type: ${type}`);
12056
12056
  }
12057
- return setAppUsageValue(quotaUsage, name, type, opts, values);
12057
+ return setAppUsageValue(quotaUsage, name2, type, opts, values);
12058
12058
  };
12059
- setAllUsage = async (name, type, values, opts = {}) => {
12059
+ setAllUsage = async (name2, type, values, opts = {}) => {
12060
12060
  const db2 = getDB2();
12061
12061
  let quotaUsage = await getQuotaUsage();
12062
- quotaUsage = coreUsageUpdate(quotaUsage, name, type, values, opts);
12062
+ quotaUsage = coreUsageUpdate(quotaUsage, name2, type, values, opts);
12063
12063
  const response2 = await db2.put(quotaUsage);
12064
12064
  quotaUsage._rev = response2.rev;
12065
12065
  return quotaUsage;
12066
12066
  };
12067
- getCurrentUsageValues = async (type, name, id) => {
12067
+ getCurrentUsageValues = async (type, name2, id) => {
12068
12068
  const quotaUsage = await getQuotaUsage();
12069
12069
  let total = 0, appValues = {};
12070
12070
  switch (type) {
12071
12071
  case "static" /* STATIC */:
12072
- if (quotaUsage.usageQuota[name]) {
12073
- const staticName = name;
12072
+ if (quotaUsage.usageQuota[name2]) {
12073
+ const staticName = name2;
12074
12074
  total = quotaUsage.usageQuota[staticName];
12075
- appValues = getAppUsageValue(quotaUsage, type, name, id);
12075
+ appValues = getAppUsageValue(quotaUsage, type, name2, id);
12076
12076
  }
12077
12077
  break;
12078
12078
  case "monthly" /* MONTHLY */:
12079
12079
  const currentMonth = getCurrentMonthString();
12080
- const monthlyName = name;
12080
+ const monthlyName = name2;
12081
12081
  if (quotaUsage.monthly[currentMonth][monthlyName]) {
12082
12082
  total = quotaUsage.monthly[currentMonth][monthlyName];
12083
- appValues = getAppUsageValue(quotaUsage, type, name, id);
12083
+ appValues = getAppUsageValue(quotaUsage, type, name2, id);
12084
12084
  }
12085
12085
  break;
12086
12086
  default:
12087
12087
  throw new Error(`Invalid usage type: ${type}`);
12088
12088
  }
12089
- if (APP_QUOTA_NAMES.includes(name) && !(appValues.app || appValues.breakdown)) {
12089
+ if (APP_QUOTA_NAMES.includes(name2) && !(appValues.app || appValues.breakdown)) {
12090
12090
  appValues.app = appValues.app || 0;
12091
12091
  appValues.breakdown = appValues.breakdown || 0;
12092
12092
  }
@@ -12308,9 +12308,9 @@ async function getGroupUsers(groupId, params2) {
12308
12308
  createGroupUserLookupView,
12309
12309
  { arrayResponse: true }
12310
12310
  );
12311
- const users2 = userDocs.map((doc) => ({
12312
- _id: doc.userId,
12313
- email: doc.email
12311
+ const users2 = userDocs.map((doc2) => ({
12312
+ _id: doc2.userId,
12313
+ email: doc2.email
12314
12314
  })) || [];
12315
12315
  return users2;
12316
12316
  }
@@ -12399,12 +12399,12 @@ async function destroy3(groupId, revision) {
12399
12399
  await cleanupUsers(group2);
12400
12400
  return resp;
12401
12401
  }
12402
- async function getByName(name) {
12402
+ async function getByName(name2) {
12403
12403
  try {
12404
12404
  const groups = await db_exports.directCouchFind(tenancy.getGlobalDBName(), {
12405
12405
  selector: {
12406
12406
  name: {
12407
- $regex: `^(?i)${name}$`
12407
+ $regex: `^(?i)${name2}$`
12408
12408
  }
12409
12409
  },
12410
12410
  limit: 1
@@ -12731,11 +12731,11 @@ var init_version2 = __esm({
12731
12731
  }
12732
12732
  };
12733
12733
  getProVersion = () => {
12734
- const version = environment_default2.VERSION;
12735
- if (!version) {
12734
+ const version2 = environment_default2.VERSION;
12735
+ if (!version2) {
12736
12736
  throw new Error("No budibase pro version was specified");
12737
12737
  }
12738
- return version;
12738
+ return version2;
12739
12739
  };
12740
12740
  }
12741
12741
  });
@@ -12879,15 +12879,15 @@ async function fetchAppBackups(appId, opts = {}) {
12879
12879
  }
12880
12880
  return pageData;
12881
12881
  }
12882
- async function storeAppBackupMetadata(metadata, opts = {}) {
12882
+ async function storeAppBackupMetadata(metadata2, opts = {}) {
12883
12883
  const db2 = tenancy.getGlobalDB();
12884
- const prodAppId = db_exports.getProdAppID(metadata.appId);
12885
- let _id = generateAppBackupID(prodAppId, metadata.timestamp);
12884
+ const prodAppId = db_exports.getProdAppID(metadata2.appId);
12885
+ let _id = generateAppBackupID(prodAppId, metadata2.timestamp);
12886
12886
  const appBackupDoc = {
12887
- ...metadata,
12887
+ ...metadata2,
12888
12888
  _id,
12889
12889
  appId: prodAppId,
12890
- name: metadata.name
12890
+ name: metadata2.name
12891
12891
  };
12892
12892
  if (opts.filename) {
12893
12893
  appBackupDoc.filename = opts.filename;
@@ -12896,18 +12896,18 @@ async function storeAppBackupMetadata(metadata, opts = {}) {
12896
12896
  appBackupDoc._id = opts.docId;
12897
12897
  appBackupDoc._rev = opts.docRev;
12898
12898
  }
12899
- if (metadata.createdBy) {
12899
+ if (metadata2.createdBy) {
12900
12900
  appBackupDoc.createdBy = db_exports.getGlobalIDFromUserMetadataID(
12901
- metadata.createdBy
12901
+ metadata2.createdBy
12902
12902
  );
12903
12903
  }
12904
12904
  return await db2.put(appBackupDoc);
12905
12905
  }
12906
- async function updateAppBackupMetadata(backupId, name) {
12906
+ async function updateAppBackupMetadata(backupId, name2) {
12907
12907
  const db2 = tenancy.getGlobalDB();
12908
- const metadata = await db2.get(backupId);
12909
- metadata.name = name;
12910
- return await db2.put(metadata);
12908
+ const metadata2 = await db2.get(backupId);
12909
+ metadata2.name = name2;
12910
+ return await db2.put(metadata2);
12911
12911
  }
12912
12912
  async function deleteAppBackupMetadata(backupId) {
12913
12913
  const db2 = tenancy.getGlobalDB();
@@ -12942,9 +12942,9 @@ __export(environmentVariables_exports, {
12942
12942
  function getEnvVarID() {
12943
12943
  return StaticDatabases.GLOBAL.docs.environmentVariables;
12944
12944
  }
12945
- function getCacheEnvVarID(rev) {
12945
+ function getCacheEnvVarID(rev2) {
12946
12946
  const tenantId = tenancy.getTenantId();
12947
- return `${tenantId}/${getEnvVarID()}/${rev || ""}`;
12947
+ return `${tenantId}/${getEnvVarID()}/${rev2 || ""}`;
12948
12948
  }
12949
12949
  async function get5() {
12950
12950
  const id = getEnvVarID();
@@ -12984,14 +12984,14 @@ async function get5() {
12984
12984
  cache.set(cacheKey, finalDoc);
12985
12985
  return finalDoc;
12986
12986
  }
12987
- async function update(doc) {
12987
+ async function update(doc2) {
12988
12988
  const id = getEnvVarID();
12989
12989
  const db2 = tenancy.getGlobalDB();
12990
12990
  return await db2.put({
12991
- _id: doc._id || id,
12992
- _rev: doc._rev || void 0,
12991
+ _id: doc2._id || id,
12992
+ _rev: doc2._rev || void 0,
12993
12993
  variables: encryption_exports.encrypt(
12994
- JSON.stringify(doc.variables),
12994
+ JSON.stringify(doc2.variables),
12995
12995
  encryption_exports.SecretOption.ENCRYPTION
12996
12996
  )
12997
12997
  });
@@ -13474,14 +13474,14 @@ var init_quotas5 = __esm({
13474
13474
  init_db6();
13475
13475
  init_src2();
13476
13476
  init_quotas3();
13477
- increment = (name, type, opts) => {
13478
- return tryIncrement(1, name, type, opts);
13477
+ increment = (name2, type, opts) => {
13478
+ return tryIncrement(1, name2, type, opts);
13479
13479
  };
13480
- incrementMany = (change, name, type, opts) => {
13481
- return tryIncrement(change, name, type, opts);
13480
+ incrementMany = (change, name2, type, opts) => {
13481
+ return tryIncrement(change, name2, type, opts);
13482
13482
  };
13483
- tryIncrement = async (change, name, type, opts = {}) => {
13484
- await updateUsage(change, name, type, {
13483
+ tryIncrement = async (change, name2, type, opts = {}) => {
13484
+ await updateUsage(change, name2, type, {
13485
13485
  dryRun: true,
13486
13486
  suppressErrorLog: opts.suppressErrorLog,
13487
13487
  id: opts.id
@@ -13490,7 +13490,7 @@ var init_quotas5 = __esm({
13490
13490
  if (opts.fn) {
13491
13491
  result = await opts.fn();
13492
13492
  }
13493
- await updateUsage(change, name, type, {
13493
+ await updateUsage(change, name2, type, {
13494
13494
  dryRun: false,
13495
13495
  valueFn: opts.valueFn,
13496
13496
  suppressErrorLog: opts.suppressErrorLog,
@@ -13498,32 +13498,32 @@ var init_quotas5 = __esm({
13498
13498
  });
13499
13499
  return result;
13500
13500
  };
13501
- decrement = (name, type, opts = {}) => {
13502
- return updateUsage(-1, name, type, opts);
13501
+ decrement = (name2, type, opts = {}) => {
13502
+ return updateUsage(-1, name2, type, opts);
13503
13503
  };
13504
- decrementMany = (change, name, type, opts = {}) => {
13505
- return updateUsage(-change, name, type, opts);
13504
+ decrementMany = (change, name2, type, opts = {}) => {
13505
+ return updateUsage(-change, name2, type, opts);
13506
13506
  };
13507
- set2 = async (name, type, value) => {
13508
- return quotas_exports.setUsage(value, name, type);
13507
+ set2 = async (name2, type, value) => {
13508
+ return quotas_exports.setUsage(value, name2, type);
13509
13509
  };
13510
- getExistingTriggers = (type, name, quotaUsage) => {
13510
+ getExistingTriggers = (type, name2, quotaUsage) => {
13511
13511
  if (type == "static" /* STATIC */) {
13512
13512
  const triggers = quotaUsage.usageQuota.triggers;
13513
- return triggers ? triggers[name] || {} : {};
13513
+ return triggers ? triggers[name2] || {} : {};
13514
13514
  } else {
13515
13515
  const currentMonthString = quotas_exports.utils.getCurrentMonthString();
13516
13516
  const triggers = quotaUsage.monthly[currentMonthString].triggers;
13517
- return triggers ? triggers[name] || {} : {};
13517
+ return triggers ? triggers[name2] || {} : {};
13518
13518
  }
13519
13519
  };
13520
- triggerQuota2 = async (name, quota, percentage, resetDate) => {
13520
+ triggerQuota2 = async (name2, quota, percentage, resetDate) => {
13521
13521
  try {
13522
13522
  await redlockImpl_exports.doWithLock(
13523
13523
  {
13524
13524
  type: "try_once" /* TRY_ONCE */,
13525
13525
  name: "trigger_quota" /* TRIGGER_QUOTA */,
13526
- resource: name,
13526
+ resource: name2,
13527
13527
  // use the quota name for extra uniqueness on the lock
13528
13528
  ttl: 1e4
13529
13529
  // auto expire after 10 seconds
@@ -13543,10 +13543,10 @@ var init_quotas5 = __esm({
13543
13543
  logging_exports.logAlert("Error triggering quota", e);
13544
13544
  }
13545
13545
  };
13546
- checkTriggers = async (type, name, totalValue, quota) => {
13546
+ checkTriggers = async (type, name2, totalValue, quota) => {
13547
13547
  const usage = await getQuotaUsage();
13548
13548
  const resetDate = type === "monthly" /* MONTHLY */ ? usage.quotaReset : void 0;
13549
- const triggers = await getExistingTriggers(type, name, usage);
13549
+ const triggers = await getExistingTriggers(type, name2, usage);
13550
13550
  const quotaTriggers = quota.triggers;
13551
13551
  let percentage = totalValue / quota.value * 100;
13552
13552
  if (percentage > 100) {
@@ -13562,7 +13562,7 @@ var init_quotas5 = __esm({
13562
13562
  const isAtTrigger = percentage === triggerPercentage;
13563
13563
  const sendNotification = !nextIsTriggered || isAtTrigger;
13564
13564
  if (sendNotification) {
13565
- await triggerQuota2(name, quota, percentage, resetDate);
13565
+ await triggerQuota2(name2, quota, percentage, resetDate);
13566
13566
  }
13567
13567
  }
13568
13568
  } else {
@@ -13571,23 +13571,23 @@ var init_quotas5 = __esm({
13571
13571
  }
13572
13572
  return triggers;
13573
13573
  };
13574
- updateUsage = async (usageChange, name, type, opts = {}) => {
13574
+ updateUsage = async (usageChange, name2, type, opts = {}) => {
13575
13575
  let appId = null;
13576
13576
  try {
13577
13577
  appId = context_exports.getAppId();
13578
13578
  } catch (err) {
13579
13579
  }
13580
- const isAppQuota = APP_QUOTA_NAMES.includes(name);
13580
+ const isAppQuota = APP_QUOTA_NAMES.includes(name2);
13581
13581
  if (isAppQuota && !appId) {
13582
13582
  throw new Error("App context required for quota update");
13583
13583
  }
13584
13584
  try {
13585
- const licensedQuota = await getLicensedQuota("usage" /* USAGE */, name, type);
13585
+ const licensedQuota = await getLicensedQuota("usage" /* USAGE */, name2, type);
13586
13586
  let {
13587
13587
  total: totalValue,
13588
13588
  app: appValue,
13589
13589
  breakdown: breakdownValue
13590
- } = await quotas_exports.getCurrentUsageValues(type, name, opts.id);
13590
+ } = await quotas_exports.getCurrentUsageValues(type, name2, opts.id);
13591
13591
  totalValue += usageChange;
13592
13592
  if (appValue != null) {
13593
13593
  appValue += usageChange;
@@ -13597,7 +13597,7 @@ var init_quotas5 = __esm({
13597
13597
  }
13598
13598
  let triggers = {};
13599
13599
  if (!opts.dryRun) {
13600
- triggers = await checkTriggers(type, name, totalValue, licensedQuota);
13600
+ triggers = await checkTriggers(type, name2, totalValue, licensedQuota);
13601
13601
  }
13602
13602
  if (licensedQuota.value !== quotas_exports2.UNLIMITED && totalValue > licensedQuota.value && usageChange > 0) {
13603
13603
  throw new UsageLimitError(
@@ -13620,7 +13620,7 @@ var init_quotas5 = __esm({
13620
13620
  appValue = totalValue;
13621
13621
  }
13622
13622
  await quotas_exports.setAllUsage(
13623
- name,
13623
+ name2,
13624
13624
  type,
13625
13625
  {
13626
13626
  total: totalValue,
@@ -13632,30 +13632,30 @@ var init_quotas5 = __esm({
13632
13632
  );
13633
13633
  } catch (err) {
13634
13634
  if (!opts.suppressErrorLog) {
13635
- console.error(`Error updating usage quotas for ${name}`, err);
13635
+ console.error(`Error updating usage quotas for ${name2}`, err);
13636
13636
  }
13637
13637
  throw err;
13638
13638
  }
13639
13639
  };
13640
- getLicensedQuota = async (quotaType, name, usageType) => {
13640
+ getLicensedQuota = async (quotaType, name2, usageType) => {
13641
13641
  const license = await cache_exports2.getCachedLicense();
13642
13642
  if (!license) {
13643
13643
  const tenantId = tenancy.getTenantId();
13644
13644
  throw new Error("License not found for tenant id " + tenantId);
13645
13645
  }
13646
- if (usageType && isStaticQuota(quotaType, usageType, name)) {
13647
- return license.quotas[quotaType][usageType][name];
13648
- } else if (usageType && isMonthlyQuota(quotaType, usageType, name)) {
13649
- return license.quotas[quotaType][usageType][name];
13650
- } else if (isConstantQuota(quotaType, name)) {
13651
- return license.quotas[quotaType][name];
13646
+ if (usageType && isStaticQuota(quotaType, usageType, name2)) {
13647
+ return license.quotas[quotaType][usageType][name2];
13648
+ } else if (usageType && isMonthlyQuota(quotaType, usageType, name2)) {
13649
+ return license.quotas[quotaType][usageType][name2];
13650
+ } else if (isConstantQuota(quotaType, name2)) {
13651
+ return license.quotas[quotaType][name2];
13652
13652
  } else {
13653
13653
  throw new Error("Invalid quota type");
13654
13654
  }
13655
13655
  };
13656
- usageLimitIsExceeded = async (name, type) => {
13656
+ usageLimitIsExceeded = async (name2, type) => {
13657
13657
  try {
13658
- await updateUsage(1, name, type, { dryRun: true });
13658
+ await updateUsage(1, name2, type, { dryRun: true });
13659
13659
  return false;
13660
13660
  } catch (e) {
13661
13661
  if (e.code === "usage_limit_exceeded" /* USAGE_LIMIT_EXCEEDED */) {
@@ -14194,7 +14194,7 @@ async function getLogsByView(startDate, endDate, viewParams = {}) {
14194
14194
  async function writeLog(automation, results) {
14195
14195
  const db2 = context_exports.getProdAppDB();
14196
14196
  const automationId = automation._id;
14197
- const name = automation.name;
14197
+ const name2 = automation.name;
14198
14198
  const status2 = getStatus(results);
14199
14199
  const isoDate = (/* @__PURE__ */ new Date()).toISOString();
14200
14200
  const id = generateAutomationLogID(isoDate, status2, automationId);
@@ -14203,7 +14203,7 @@ async function writeLog(automation, results) {
14203
14203
  ...results,
14204
14204
  automationId,
14205
14205
  status: status2,
14206
- automationName: name,
14206
+ automationName: name2,
14207
14207
  createdAt: isoDate,
14208
14208
  _id: id
14209
14209
  };
@@ -14213,13 +14213,13 @@ async function writeLog(automation, results) {
14213
14213
  async function updateAppMetadataWithErrors(logIds, { clearing } = { clearing: false }) {
14214
14214
  const db2 = context_exports.getProdAppDB();
14215
14215
  await backOff(async () => {
14216
- const metadata = await db2.get(db_exports.DocumentType.APP_METADATA);
14216
+ const metadata2 = await db2.get(db_exports.DocumentType.APP_METADATA);
14217
14217
  for (let logId of logIds) {
14218
14218
  const parts = logId.split(db_exports.SEPARATOR);
14219
14219
  const autoId = `${parts[parts.length - 3]}${db_exports.SEPARATOR}${parts[parts.length - 2]}`;
14220
14220
  let errors = {};
14221
- if (metadata.automationErrors) {
14222
- errors = metadata.automationErrors;
14221
+ if (metadata2.automationErrors) {
14222
+ errors = metadata2.automationErrors;
14223
14223
  }
14224
14224
  if (!Array.isArray(errors[autoId])) {
14225
14225
  errors[autoId] = [];
@@ -14233,10 +14233,10 @@ async function updateAppMetadataWithErrors(logIds, { clearing } = { clearing: fa
14233
14233
  if (errors[autoId].length === 0) {
14234
14234
  delete errors[autoId];
14235
14235
  }
14236
- metadata.automationErrors = errors;
14236
+ metadata2.automationErrors = errors;
14237
14237
  }
14238
- await db2.put(metadata);
14239
- await cache_exports.app.invalidateAppMetadata(metadata.appId, metadata);
14238
+ await db2.put(metadata2);
14239
+ await cache_exports.app.invalidateAppMetadata(metadata2.appId, metadata2);
14240
14240
  }, "Failed to update app metadata with automation log error");
14241
14241
  }
14242
14242
  async function getExpiredLogs() {
@@ -14258,16 +14258,16 @@ async function clearOldHistory() {
14258
14258
  if (!expired.data || expired.data.length === 0) {
14259
14259
  return;
14260
14260
  }
14261
- const toDelete = expired.data.map((doc) => ({
14262
- _id: doc.id,
14263
- _rev: doc.value.rev,
14261
+ const toDelete = expired.data.map((doc2) => ({
14262
+ _id: doc2.id,
14263
+ _rev: doc2.value.rev,
14264
14264
  _deleted: true
14265
14265
  }));
14266
- const errorLogIds = expired.data.filter((doc) => {
14267
- const parts = doc.id.split(db_exports.SEPARATOR);
14266
+ const errorLogIds = expired.data.filter((doc2) => {
14267
+ const parts = doc2.id.split(db_exports.SEPARATOR);
14268
14268
  const status2 = parts[parts.length - 1];
14269
14269
  return status2 === "error" /* ERROR */;
14270
- }).map((doc) => doc.id);
14270
+ }).map((doc2) => doc2.id);
14271
14271
  await db2.bulkDocs(toDelete);
14272
14272
  if (errorLogIds.length) {
14273
14273
  await updateAppMetadataWithErrors(errorLogIds, { clearing: true });
@@ -14487,10 +14487,10 @@ async function get6(id) {
14487
14487
  async function getBulk2(ids, opts = { enriched: true }) {
14488
14488
  return await groups_exports.getBulk(ids, opts);
14489
14489
  }
14490
- async function guardNameAvailility(name) {
14491
- const existingGroup = await groups_exports.getByName(name);
14490
+ async function guardNameAvailility(name2) {
14491
+ const existingGroup = await groups_exports.getByName(name2);
14492
14492
  if (existingGroup) {
14493
- throw new GroupNameUnavailableError(name);
14493
+ throw new GroupNameUnavailableError(name2);
14494
14494
  }
14495
14495
  }
14496
14496
  async function save4(group2) {
@@ -14649,8 +14649,8 @@ var init_groups6 = __esm({
14649
14649
  });
14650
14650
 
14651
14651
  // ../pro/packages/pro/src/utilities/fileSystem.ts
14652
- function loadJSFile(directory, name) {
14653
- return import_fs7.default.readFileSync((0, import_path7.join)(directory, name), "utf8");
14652
+ function loadJSFile(directory2, name2) {
14653
+ return import_fs7.default.readFileSync((0, import_path7.join)(directory2, name2), "utf8");
14654
14654
  }
14655
14655
  var import_fs7, import_path7;
14656
14656
  var init_fileSystem = __esm({
@@ -14668,8 +14668,8 @@ __export(plugins_exports, {
14668
14668
  storePlugin: () => storePlugin
14669
14669
  });
14670
14670
  async function storePlugin(metadata, directory, source) {
14671
- const db2 = tenancy.getGlobalDB();
14672
- const version = metadata.package.version, name = metadata.package.name, description = metadata.package.description, hash2 = metadata.schema.hash;
14671
+ const db = tenancy.getGlobalDB();
14672
+ const version = metadata.package.version, name = metadata.package.name, description = metadata.package.description, hash = metadata.schema.hash;
14673
14673
  const bucketPath = objectStore_exports2.getPluginS3Dir(name);
14674
14674
  const files = await objectStore_exports2.uploadDirectory(
14675
14675
  objectStore_exports2.ObjectStoreBuckets.PLUGINS,
@@ -14684,8 +14684,7 @@ async function storePlugin(metadata, directory, source) {
14684
14684
  if (metadata.schema.type === "datasource" /* DATASOURCE */) {
14685
14685
  const js = loadJSFile(directory, jsFile.name);
14686
14686
  try {
14687
- ;
14688
- (0, eval)(js);
14687
+ eval(js);
14689
14688
  } catch (err) {
14690
14689
  const message = (err == null ? void 0 : err.message) ? err.message : JSON.stringify(err);
14691
14690
  throw new Error(`JS invalid: ${message}`);
@@ -14695,7 +14694,7 @@ async function storePlugin(metadata, directory, source) {
14695
14694
  const pluginId = db_exports.generatePluginID(name);
14696
14695
  let rev;
14697
14696
  try {
14698
- const existing = await db2.get(pluginId);
14697
+ const existing = await db.get(pluginId);
14699
14698
  rev = existing._rev;
14700
14699
  } catch (err) {
14701
14700
  rev = void 0;
@@ -14706,7 +14705,7 @@ async function storePlugin(metadata, directory, source) {
14706
14705
  ...metadata,
14707
14706
  name,
14708
14707
  version,
14709
- hash: hash2,
14708
+ hash,
14710
14709
  description
14711
14710
  };
14712
14711
  if (iconFileName) {
@@ -14718,8 +14717,8 @@ async function storePlugin(metadata, directory, source) {
14718
14717
  source
14719
14718
  };
14720
14719
  }
14721
- const write2 = async () => {
14722
- const response2 = await db2.put(doc);
14720
+ const write = async () => {
14721
+ const response2 = await db.put(doc);
14723
14722
  await events_exports.plugin.imported(doc);
14724
14723
  return {
14725
14724
  ...doc,
@@ -14727,21 +14726,21 @@ async function storePlugin(metadata, directory, source) {
14727
14726
  };
14728
14727
  };
14729
14728
  if (!rev) {
14730
- return await addPlugin(write2);
14729
+ return await addPlugin(write);
14731
14730
  } else {
14732
- return await write2();
14731
+ return await write();
14733
14732
  }
14734
14733
  }
14735
- async function deletePlugin(pluginId) {
14734
+ async function deletePlugin(pluginId2) {
14736
14735
  const db2 = tenancy.getGlobalDB();
14737
14736
  try {
14738
- const plugin = await db2.get(pluginId);
14739
- const bucketPath = objectStore_exports2.getPluginS3Dir(plugin.name);
14737
+ const plugin = await db2.get(pluginId2);
14738
+ const bucketPath2 = objectStore_exports2.getPluginS3Dir(plugin.name);
14740
14739
  await objectStore_exports2.deleteFolder(
14741
14740
  objectStore_exports2.ObjectStoreBuckets.PLUGINS,
14742
- bucketPath
14741
+ bucketPath2
14743
14742
  );
14744
- await db2.remove(pluginId, plugin._rev);
14743
+ await db2.remove(pluginId2, plugin._rev);
14745
14744
  await events_exports.plugin.deleted(plugin);
14746
14745
  await removePlugin();
14747
14746
  } catch (err) {
@@ -14775,12 +14774,12 @@ function isEncryptionKeyAvailable() {
14775
14774
  return !!environment_default2.ENCRYPTION_KEY;
14776
14775
  }
14777
14776
  async function fetch10() {
14778
- const doc = await environmentVariables_exports.get();
14779
- return Object.keys(doc.variables);
14777
+ const doc2 = await environmentVariables_exports.get();
14778
+ return Object.keys(doc2.variables);
14780
14779
  }
14781
14780
  async function fetchValues(environment3) {
14782
- const doc = await environmentVariables_exports.get();
14783
- const decrypted = doc.variables;
14781
+ const doc2 = await environmentVariables_exports.get();
14782
+ const decrypted = doc2.variables;
14784
14783
  const output = {};
14785
14784
  for (let [key, value] of Object.entries(decrypted)) {
14786
14785
  switch (environment3) {
@@ -14802,9 +14801,9 @@ async function changeValues(cb) {
14802
14801
  "User does not have access to environment variables feature."
14803
14802
  );
14804
14803
  }
14805
- const doc = await environmentVariables_exports.get();
14806
- doc.variables = cb(doc.variables);
14807
- await environmentVariables_exports.update(doc);
14804
+ const doc2 = await environmentVariables_exports.get();
14805
+ doc2.variables = cb(doc2.variables);
14806
+ await environmentVariables_exports.update(doc2);
14808
14807
  }
14809
14808
  async function update2(varName, value) {
14810
14809
  const checkName = isValid(varName);
@@ -14855,15 +14854,15 @@ var init_environmentVariables6 = __esm({
14855
14854
  function generateAuditLogID(timestamp) {
14856
14855
  return `${"al" /* AUDIT_LOG */}${SEPARATOR}${timestamp}${SEPARATOR}${utils_exports2.newid()}`;
14857
14856
  }
14858
- async function save5(doc) {
14859
- if (!doc._id) {
14860
- doc._id = generateAuditLogID(doc.timestamp);
14857
+ async function save5(doc2) {
14858
+ if (!doc2._id) {
14859
+ doc2._id = generateAuditLogID(doc2.timestamp);
14861
14860
  }
14862
14861
  try {
14863
14862
  const db2 = context_exports.getAuditLogsDB();
14864
- const response2 = await db2.put(doc);
14863
+ const response2 = await db2.put(doc2);
14865
14864
  return {
14866
- ...doc,
14865
+ ...doc2,
14867
14866
  _rev: response2.rev
14868
14867
  };
14869
14868
  } catch (err) {
@@ -14891,9 +14890,9 @@ function dump(params2) {
14891
14890
  const db2 = context_exports.getAuditLogsDB();
14892
14891
  const stream3 = new MemoryStream();
14893
14892
  const promise = db2.dump(stream3, {
14894
- filter: (doc) => {
14893
+ filter: (doc2) => {
14895
14894
  var _a;
14896
- const auditLog = doc;
14895
+ const auditLog = doc2;
14897
14896
  if (!((_a = auditLog._id) == null ? void 0 : _a.startsWith("al" /* AUDIT_LOG */))) {
14898
14897
  return false;
14899
14898
  }
@@ -14911,7 +14910,7 @@ function dump(params2) {
14911
14910
  allMatched = allMatched && auditLog.timestamp >= params2.startDate && auditLog.timestamp <= params2.endDate;
14912
14911
  }
14913
14912
  if (params2.fullSearch) {
14914
- const json2 = JSON.stringify(doc);
14913
+ const json2 = JSON.stringify(doc2);
14915
14914
  allMatched = allMatched && json2.includes(params2.fullSearch);
14916
14915
  }
14917
14916
  return allMatched;
@@ -14922,8 +14921,8 @@ function dump(params2) {
14922
14921
  const json2 = JSON.parse(Buffer.from(data2).toString());
14923
14922
  if (Array.isArray(json2.docs)) {
14924
14923
  let str = "";
14925
- for (let doc of json2.docs) {
14926
- str += JSON.stringify(doc) + "\n";
14924
+ for (let doc2 of json2.docs) {
14925
+ str += JSON.stringify(doc2) + "\n";
14927
14926
  }
14928
14927
  returnStream.write(str);
14929
14928
  }
@@ -14948,8 +14947,8 @@ var init_auditLogs4 = __esm({
14948
14947
  var require_Helper = __commonJS({
14949
14948
  "../string-templates/src/helpers/Helper.js"(exports2, module2) {
14950
14949
  var Helper = class {
14951
- constructor(name, fn2, useValueFallback = true) {
14952
- this.name = name;
14950
+ constructor(name2, fn2, useValueFallback = true) {
14951
+ this.name = name2;
14953
14952
  this.fn = fn2;
14954
14953
  this.useValueFallback = useValueFallback;
14955
14954
  }
@@ -15118,18 +15117,18 @@ var require_external = __commonJS({
15118
15117
  exports2.externalCollections = EXTERNAL_FUNCTION_COLLECTIONS;
15119
15118
  exports2.addedHelpers = ADDED_HELPERS;
15120
15119
  exports2.registerAll = (handlebars) => {
15121
- for (let [name, helper] of Object.entries(ADDED_HELPERS)) {
15122
- handlebars.registerHelper(name, helper);
15120
+ for (let [name2, helper] of Object.entries(ADDED_HELPERS)) {
15121
+ handlebars.registerHelper(name2, helper);
15123
15122
  }
15124
15123
  let externalNames = [];
15125
15124
  for (let collection of EXTERNAL_FUNCTION_COLLECTIONS) {
15126
15125
  let hbsHelperInfo = helpers[collection]();
15127
15126
  for (let entry of Object.entries(hbsHelperInfo)) {
15128
- const name = entry[0];
15129
- if (HelperFunctionBuiltin.indexOf(name) !== -1 || externalNames.indexOf(name) !== -1) {
15127
+ const name2 = entry[0];
15128
+ if (HelperFunctionBuiltin.indexOf(name2) !== -1 || externalNames.indexOf(name2) !== -1) {
15130
15129
  continue;
15131
15130
  }
15132
- externalNames.push(name);
15131
+ externalNames.push(name2);
15133
15132
  }
15134
15133
  helpers[collection]({
15135
15134
  handlebars
@@ -15138,11 +15137,11 @@ var require_external = __commonJS({
15138
15137
  exports2.externalHelperNames = externalNames.concat(Object.keys(ADDED_HELPERS));
15139
15138
  };
15140
15139
  exports2.unregisterAll = (handlebars) => {
15141
- for (let name of Object.keys(ADDED_HELPERS)) {
15142
- handlebars.unregisterHelper(name);
15140
+ for (let name2 of Object.keys(ADDED_HELPERS)) {
15141
+ handlebars.unregisterHelper(name2);
15143
15142
  }
15144
- for (let name of module2.exports.externalHelperNames) {
15145
- handlebars.unregisterHelper(name);
15143
+ for (let name2 of module2.exports.externalHelperNames) {
15144
+ handlebars.unregisterHelper(name2);
15146
15145
  }
15147
15146
  exports2.externalHelperNames = [];
15148
15147
  };
@@ -15256,12 +15255,12 @@ var require_javascript = __commonJS({
15256
15255
  throw new Error("JS disabled in environment.");
15257
15256
  }
15258
15257
  try {
15259
- const js = `function run(){${atob(handlebars)}};run();`;
15258
+ const js2 = `function run(){${atob(handlebars)}};run();`;
15260
15259
  const sandboxContext = {
15261
15260
  $: (path2) => getContextValue(path2, cloneDeep16(context)),
15262
15261
  helpers: getHelperList()
15263
15262
  };
15264
- const res = { data: runJS(js, sandboxContext) };
15263
+ const res = { data: runJS(js2, sandboxContext) };
15265
15264
  return `{{${LITERAL_MARKER} js_result-${JSON.stringify(res)}}}`;
15266
15265
  } catch (error) {
15267
15266
  return "Error while executing JS";
@@ -15374,8 +15373,8 @@ var require_preprocessor = __commonJS({
15374
15373
  FINALISE: "finalise"
15375
15374
  };
15376
15375
  var Preprocessor = class {
15377
- constructor(name, fn2) {
15378
- this.name = name;
15376
+ constructor(name2, fn2) {
15377
+ this.name = name2;
15379
15378
  this.fn = fn2;
15380
15379
  }
15381
15380
  process(fullString, statement, opts) {
@@ -15439,8 +15438,8 @@ var require_postprocessor = __commonJS({
15439
15438
  CONVERT_LITERALS: "convert-literals"
15440
15439
  };
15441
15440
  var Postprocessor = class {
15442
- constructor(name, fn2) {
15443
- this.name = name;
15441
+ constructor(name2, fn2) {
15442
+ this.name = name2;
15444
15443
  this.fn = fn2;
15445
15444
  }
15446
15445
  process(statement) {
@@ -17082,10 +17081,10 @@ var require_src = __commonJS({
17082
17081
  };
17083
17082
  module2.exports.convertToJS = (hbs) => {
17084
17083
  const blocks = exports2.findHBSBlocks(hbs);
17085
- let js = "return `", prevBlock = null;
17084
+ let js2 = "return `", prevBlock = null;
17086
17085
  const variables = {};
17087
17086
  if (blocks.length === 0) {
17088
- js += hbs;
17087
+ js2 += hbs;
17089
17088
  }
17090
17089
  let count = 1;
17091
17090
  for (let block of blocks) {
@@ -17097,15 +17096,15 @@ var require_src = __commonJS({
17097
17096
  prevBlock = block;
17098
17097
  const { variable, value } = convertHBSBlock(block, count++);
17099
17098
  variables[variable] = value;
17100
- js += `${stringPart.split()}\${${variable}}`;
17099
+ js2 += `${stringPart.split()}\${${variable}}`;
17101
17100
  }
17102
17101
  let varBlock = "";
17103
17102
  for (let [variable, value] of Object.entries(variables)) {
17104
17103
  varBlock += `const ${variable} = ${value};
17105
17104
  `;
17106
17105
  }
17107
- js += "`;";
17108
- return `${varBlock}${js}`;
17106
+ js2 += "`;";
17107
+ return `${varBlock}${js2}`;
17109
17108
  };
17110
17109
  }
17111
17110
  });
@@ -17132,12 +17131,12 @@ var require_src2 = __commonJS({
17132
17131
  if (!process.env.NO_JS) {
17133
17132
  const { VM: VM2 } = require("vm2");
17134
17133
  const { setJSRunner } = require_javascript();
17135
- setJSRunner((js, context) => {
17134
+ setJSRunner((js2, context) => {
17136
17135
  const vm = new VM2({
17137
17136
  sandbox: context,
17138
17137
  timeout: 1e3
17139
17138
  });
17140
- return vm.run(js);
17139
+ return vm.run(js2);
17141
17140
  });
17142
17141
  }
17143
17142
  }
@@ -17231,12 +17230,12 @@ async function auditLogsEnabled() {
17231
17230
  const license = await licensing_exports.cache.getCachedLicense();
17232
17231
  return license.features.includes("auditLogs" /* AUDIT_LOGS */);
17233
17232
  }
17234
- function getEventFriendlyName(event, metadata) {
17233
+ function getEventFriendlyName(event, metadata2) {
17235
17234
  const friendly = AuditedEventFriendlyName[event];
17236
17235
  if (!friendly) {
17237
17236
  throw new Error("No friendly name found.");
17238
17237
  }
17239
- let processed = processStringSync(friendly, metadata);
17238
+ let processed = processStringSync(friendly, metadata2);
17240
17239
  if (processed.includes(`""`)) {
17241
17240
  processed = removeTemplateStrings(friendly);
17242
17241
  }
@@ -17258,29 +17257,29 @@ var init_utils10 = __esm({
17258
17257
  });
17259
17258
 
17260
17259
  // ../pro/packages/pro/src/sdk/auditLogs/auditLogs.ts
17261
- async function write(event, metadata, opts) {
17260
+ async function write2(event, metadata2, opts) {
17262
17261
  if (!await auditLogsEnabled() || !utils_exports2.isAudited(event)) {
17263
17262
  return;
17264
17263
  }
17265
- const friendly = getEventFriendlyName(event, metadata);
17264
+ const friendly = getEventFriendlyName(event, metadata2);
17266
17265
  let date = /* @__PURE__ */ new Date();
17267
17266
  if (opts == null ? void 0 : opts.timestamp) {
17268
17267
  date = new Date(opts.timestamp);
17269
17268
  }
17270
- const doc = {
17269
+ const doc2 = {
17271
17270
  timestamp: date.toISOString(),
17272
17271
  event,
17273
17272
  name: friendly,
17274
17273
  userId: (opts == null ? void 0 : opts.userId) || AuditLogSystemUser,
17275
17274
  metadata: {
17276
- ...metadata,
17275
+ ...metadata2,
17277
17276
  ...opts == null ? void 0 : opts.hostInfo
17278
17277
  }
17279
17278
  };
17280
17279
  const fallback = {};
17281
17280
  try {
17282
17281
  if (opts == null ? void 0 : opts.appId) {
17283
- doc.appId = db_exports.getProdAppID(opts.appId);
17282
+ doc2.appId = db_exports.getProdAppID(opts.appId);
17284
17283
  const appMetadata = await cache_exports.app.getAppMetadata(opts.appId);
17285
17284
  fallback.appName = appMetadata.name;
17286
17285
  }
@@ -17294,8 +17293,8 @@ async function write(event, metadata, opts) {
17294
17293
  err
17295
17294
  );
17296
17295
  }
17297
- doc.fallback = fallback;
17298
- return await save5(doc);
17296
+ doc2.fallback = fallback;
17297
+ return await save5(doc2);
17299
17298
  }
17300
17299
  async function enrich(logs) {
17301
17300
  const allUserIds = logs.map((log) => log.userId);
@@ -17367,7 +17366,7 @@ __export(auditLogs_exports2, {
17367
17366
  definitions: () => definitions2,
17368
17367
  download: () => download,
17369
17368
  fetch: () => fetch11,
17370
- write: () => write
17369
+ write: () => write2
17371
17370
  });
17372
17371
  var init_auditLogs6 = __esm({
17373
17372
  "../pro/packages/pro/src/sdk/auditLogs/index.ts"() {
@@ -17390,8 +17389,8 @@ var init_queue4 = __esm({
17390
17389
  });
17391
17390
 
17392
17391
  // ../pro/packages/pro/src/sdk/backups/backup.ts
17393
- async function storeAppBackupMetadata2(metadata, opts = {}) {
17394
- return backups_exports.storeAppBackupMetadata(metadata, opts);
17392
+ async function storeAppBackupMetadata2(metadata2, opts = {}) {
17393
+ return backups_exports.storeAppBackupMetadata(metadata2, opts);
17395
17394
  }
17396
17395
  function getTimestamps(status2) {
17397
17396
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
@@ -17405,7 +17404,7 @@ function getTimestamps(status2) {
17405
17404
  return { timestamp, createdAt: timestamp };
17406
17405
  }
17407
17406
  }
17408
- async function updateBackupStatus(id, rev, status2, contents, filename) {
17407
+ async function updateBackupStatus(id, rev2, status2, contents, filename) {
17409
17408
  const backup = await getAppBackup(id);
17410
17409
  return await backups_exports.storeAppBackupMetadata(
17411
17410
  {
@@ -17415,10 +17414,10 @@ async function updateBackupStatus(id, rev, status2, contents, filename) {
17415
17414
  status: status2,
17416
17415
  type: "backup" /* BACKUP */
17417
17416
  },
17418
- { filename, docId: id, docRev: rev }
17417
+ { filename, docId: id, docRev: rev2 }
17419
17418
  );
17420
17419
  }
17421
- async function updateRestoreStatus(id, rev, status2) {
17420
+ async function updateRestoreStatus(id, rev2, status2) {
17422
17421
  const restore = await getAppBackup(id);
17423
17422
  return await backups_exports.storeAppBackupMetadata(
17424
17423
  {
@@ -17428,7 +17427,7 @@ async function updateRestoreStatus(id, rev, status2) {
17428
17427
  type: "restore" /* RESTORE */,
17429
17428
  trigger: "manual" /* MANUAL */
17430
17429
  },
17431
- { docId: id, docRev: rev }
17430
+ { docId: id, docRev: rev2 }
17432
17431
  );
17433
17432
  }
17434
17433
  async function getAppBackup(backupId) {
@@ -17438,11 +17437,11 @@ async function updateAppBackup(backupId, backupName) {
17438
17437
  return backups_exports.updateAppBackupMetadata(backupId, backupName);
17439
17438
  }
17440
17439
  async function deleteAppBackup(backupId) {
17441
- const metadata = await backups_exports.getAppBackupMetadata(backupId);
17442
- if (metadata.filename) {
17440
+ const metadata2 = await backups_exports.getAppBackupMetadata(backupId);
17441
+ if (metadata2.filename) {
17443
17442
  await objectStore_exports2.deleteFile(
17444
17443
  objectStore_exports2.ObjectStoreBuckets.BACKUPS,
17445
- metadata.filename
17444
+ metadata2.filename
17446
17445
  );
17447
17446
  }
17448
17447
  return backups_exports.deleteAppBackupMetadata(backupId);
@@ -17451,15 +17450,15 @@ async function fetchAppBackups2(appId, opts) {
17451
17450
  return backups_exports.fetchAppBackups(appId, opts);
17452
17451
  }
17453
17452
  async function downloadAppBackup(backupId) {
17454
- const metadata = await backups_exports.getAppBackupMetadata(backupId);
17455
- if (!metadata.filename) {
17453
+ const metadata2 = await backups_exports.getAppBackupMetadata(backupId);
17454
+ if (!metadata2.filename) {
17456
17455
  throw new Error("Backup incomplete - cannot download.");
17457
17456
  }
17458
17457
  const path2 = await objectStore_exports2.retrieveToTmp(
17459
17458
  objectStore_exports2.ObjectStoreBuckets.BACKUPS,
17460
- metadata.filename
17459
+ metadata2.filename
17461
17460
  );
17462
- return { metadata, path: path2 };
17461
+ return { metadata: metadata2, path: path2 };
17463
17462
  }
17464
17463
  async function triggerAppBackup(appId, trigger, opts = {}) {
17465
17464
  let backup;
@@ -17498,7 +17497,7 @@ async function triggerAppBackup(appId, trigger, opts = {}) {
17498
17497
  return backup.id;
17499
17498
  }
17500
17499
  async function triggerAppRestore(appId, backupId, nameForBackup, createdBy) {
17501
- const metadata = await getAppBackup(backupId);
17500
+ const metadata2 = await getAppBackup(backupId);
17502
17501
  let restore;
17503
17502
  try {
17504
17503
  restore = await storeAppBackupMetadata2({
@@ -17525,7 +17524,7 @@ async function triggerAppRestore(appId, backupId, nameForBackup, createdBy) {
17525
17524
  createdBy
17526
17525
  }
17527
17526
  });
17528
- return { restoreId: restore.id, metadata };
17527
+ return { restoreId: restore.id, metadata: metadata2 };
17529
17528
  }
17530
17529
  var pkg, backup_default2;
17531
17530
  var init_backup5 = __esm({
@@ -17638,7 +17637,7 @@ async function importProcessor(job, opts) {
17638
17637
  const tenantId = tenancy.getTenantIDFromAppID(appId);
17639
17638
  return tenancy.doInTenant(tenantId, async () => {
17640
17639
  const devAppId = db_exports.getDevAppID(appId);
17641
- const { rev } = await backup_default2.updateRestoreStatus(
17640
+ const { rev: rev2 } = await backup_default2.updateRestoreStatus(
17642
17641
  data2.docId,
17643
17642
  data2.docRev,
17644
17643
  "started" /* STARTED */
@@ -17663,23 +17662,23 @@ async function importProcessor(job, opts) {
17663
17662
  logging_exports.logAlert("App restore error", err);
17664
17663
  status2 = "failed" /* FAILED */;
17665
17664
  }
17666
- await backup_default2.updateRestoreStatus(data2.docId, rev, status2);
17665
+ await backup_default2.updateRestoreStatus(data2.docId, rev2, status2);
17667
17666
  });
17668
17667
  }
17669
17668
  async function exportProcessor(job, opts) {
17670
17669
  const data2 = job.data;
17671
- const appId = data2.appId, trigger = data2.export.trigger, name = data2.export.name;
17670
+ const appId = data2.appId, trigger = data2.export.trigger, name2 = data2.export.name;
17672
17671
  const tenantId = tenancy.getTenantIDFromAppID(appId);
17673
17672
  await tenancy.doInTenant(tenantId, async () => {
17674
- const { rev } = await backup_default2.updateBackupStatus(
17673
+ const { rev: rev2 } = await backup_default2.updateBackupStatus(
17675
17674
  data2.docId,
17676
17675
  data2.docRev,
17677
17676
  "started" /* STARTED */
17678
17677
  );
17679
17678
  return runBackup(trigger, tenantId, appId, {
17680
17679
  processing: opts,
17681
- doc: { id: data2.docId, rev },
17682
- name
17680
+ doc: { id: data2.docId, rev: rev2 },
17681
+ name: name2
17683
17682
  });
17684
17683
  });
17685
17684
  }
@@ -17988,9 +17987,9 @@ var init_groups7 = __esm({
17988
17987
  ctx.body = { data: await fetch9() };
17989
17988
  };
17990
17989
  destroy4 = async (ctx) => {
17991
- const { id, rev } = ctx.params;
17990
+ const { id, rev: rev2 } = ctx.params;
17992
17991
  try {
17993
- await remove2(id, rev);
17992
+ await remove2(id, rev2);
17994
17993
  ctx.body = { message: "Group deleted successfully" };
17995
17994
  } catch (err) {
17996
17995
  ctx.throw(err.status, err);
@@ -18036,13 +18035,13 @@ async function fetch13(ctx) {
18036
18035
  };
18037
18036
  }
18038
18037
  async function create3(ctx) {
18039
- const { name, production, development } = ctx.request.body;
18040
- await environmentVariables_exports2.update(name, { production, development });
18038
+ const { name: name2, production, development } = ctx.request.body;
18039
+ await environmentVariables_exports2.update(name2, { production, development });
18041
18040
  const environments = ["production" /* PRODUCTION */];
18042
18041
  if (production !== development) {
18043
18042
  environments.push("development" /* DEVELOPMENT */);
18044
18043
  }
18045
- await events_exports.environmentVariable.created(name, environments);
18044
+ await events_exports.environmentVariable.created(name2, environments);
18046
18045
  ctx.status = 200;
18047
18046
  }
18048
18047
  async function update4(ctx) {
@@ -18329,8 +18328,8 @@ async function downloadBackup(ctx) {
18329
18328
  const appId = ctx.params.appId;
18330
18329
  await checkAppID(ctx, appId);
18331
18330
  const backupId = ctx.params.backupId;
18332
- const { metadata, path: path2 } = await backups_default.downloadAppBackup(backupId);
18333
- ctx.attachment(`backup-${metadata.timestamp}.tar.gz`);
18331
+ const { metadata: metadata2, path: path2 } = await backups_default.downloadAppBackup(backupId);
18332
+ ctx.attachment(`backup-${metadata2.timestamp}.tar.gz`);
18334
18333
  ctx.body = import_fs9.default.createReadStream(path2);
18335
18334
  }
18336
18335
  var import_fs9;
@@ -18470,8 +18469,8 @@ var init_schedules2 = __esm({
18470
18469
  });
18471
18470
 
18472
18471
  // ../pro/packages/pro/src/api/controllers/global/scim/users.ts
18473
- function tryGetQueryAsNumber(ctx, name) {
18474
- const value = ctx.request.query[name];
18472
+ function tryGetQueryAsNumber(ctx, name2) {
18473
+ const value = ctx.request.query[name2];
18475
18474
  if (value === void 0) {
18476
18475
  return void 0;
18477
18476
  }
@@ -18862,11 +18861,11 @@ var init_filters = __esm({
18862
18861
  return docs;
18863
18862
  }
18864
18863
  query = cleanupQuery(query);
18865
- const match = (type, failFn) => (doc) => {
18864
+ const match = (type, failFn) => (doc2) => {
18866
18865
  const filters = Object.entries(query[type] || {});
18867
18866
  for (let i = 0; i < filters.length; i++) {
18868
18867
  const [key, testValue] = filters[i];
18869
- const docValue = deepGet(doc, removeKeyNumbering2(key));
18868
+ const docValue = deepGet(doc2, removeKeyNumbering2(key));
18870
18869
  if (failFn(docValue, testValue)) {
18871
18870
  return false;
18872
18871
  }
@@ -18927,8 +18926,8 @@ var init_filters = __esm({
18927
18926
  return testValue == null ? void 0 : testValue.every((item) => docValue == null ? void 0 : docValue.includes(item));
18928
18927
  }
18929
18928
  );
18930
- const docMatch = (doc) => {
18931
- return stringMatch(doc) && fuzzyMatch(doc) && rangeMatch(doc) && equalMatch(doc) && notEqualMatch(doc) && emptyMatch(doc) && notEmptyMatch(doc) && oneOf(doc) && contains(doc) && containsAny(doc) && notContains(doc);
18929
+ const docMatch = (doc2) => {
18930
+ return stringMatch(doc2) && fuzzyMatch(doc2) && rangeMatch(doc2) && equalMatch(doc2) && notEqualMatch(doc2) && emptyMatch(doc2) && notEmptyMatch(doc2) && oneOf(doc2) && contains(doc2) && containsAny(doc2) && notContains(doc2);
18932
18931
  };
18933
18932
  return docs.filter(docMatch);
18934
18933
  };
@@ -19700,7 +19699,7 @@ var init_app7 = __esm({
19700
19699
  // src/utilities/fileSystem/plugin.ts
19701
19700
  async function getPluginImpl(path2, plugin) {
19702
19701
  var _a;
19703
- const hash2 = (_a = plugin.schema) == null ? void 0 : _a.hash;
19702
+ const hash3 = (_a = plugin.schema) == null ? void 0 : _a.hash;
19704
19703
  if (!import_fs11.default.existsSync(path2)) {
19705
19704
  import_fs11.default.mkdirSync(path2);
19706
19705
  }
@@ -19708,7 +19707,7 @@ async function getPluginImpl(path2, plugin) {
19708
19707
  const metadataName = `${filename}.bbmetadata`;
19709
19708
  if (import_fs11.default.existsSync(filename)) {
19710
19709
  const currentHash = import_fs11.default.readFileSync(metadataName, "utf8");
19711
- if (currentHash === hash2) {
19710
+ if (currentHash === hash3) {
19712
19711
  return require(filename);
19713
19712
  } else {
19714
19713
  console.log(`Updating plugin: ${plugin.name}`);
@@ -19722,7 +19721,7 @@ async function getPluginImpl(path2, plugin) {
19722
19721
  pluginKey
19723
19722
  );
19724
19723
  import_fs11.default.writeFileSync(filename, pluginJs);
19725
- import_fs11.default.writeFileSync(metadataName, hash2);
19724
+ import_fs11.default.writeFileSync(metadataName, hash3);
19726
19725
  return require(filename);
19727
19726
  }
19728
19727
  var import_fs11, import_path10, DATASOURCE_PATH, AUTOMATION_PATH, getPluginMetadata, getDatasourcePlugin, getAutomationPlugin;
@@ -19735,13 +19734,13 @@ var init_plugin5 = __esm({
19735
19734
  DATASOURCE_PATH = (0, import_path10.join)(budibaseTempDir2(), "datasource");
19736
19735
  AUTOMATION_PATH = (0, import_path10.join)(budibaseTempDir2(), "automation");
19737
19736
  getPluginMetadata = async (path2) => {
19738
- let metadata = {};
19737
+ let metadata2 = {};
19739
19738
  try {
19740
19739
  const pkg2 = import_fs11.default.readFileSync((0, import_path10.join)(path2, "package.json"), "utf8");
19741
19740
  const schema = import_fs11.default.readFileSync((0, import_path10.join)(path2, "schema.json"), "utf8");
19742
- metadata.schema = JSON.parse(schema);
19743
- metadata.package = JSON.parse(pkg2);
19744
- if (!metadata.package.name || !metadata.package.version || !metadata.package.description) {
19741
+ metadata2.schema = JSON.parse(schema);
19742
+ metadata2.package = JSON.parse(pkg2);
19743
+ if (!metadata2.package.name || !metadata2.package.version || !metadata2.package.description) {
19745
19744
  throw new Error(
19746
19745
  "package.json is missing one of 'name', 'version' or 'description'."
19747
19746
  );
@@ -19751,7 +19750,7 @@ var init_plugin5 = __esm({
19751
19750
  `Unable to process schema.json/package.json in plugin. ${err.message}`
19752
19751
  );
19753
19752
  }
19754
- return { metadata, directory: path2 };
19753
+ return { metadata: metadata2, directory: path2 };
19755
19754
  };
19756
19755
  getDatasourcePlugin = async (plugin) => {
19757
19756
  return getPluginImpl(DATASOURCE_PATH, plugin);
@@ -19768,9 +19767,9 @@ var init_template = __esm({
19768
19767
  "src/utilities/fileSystem/template.ts"() {
19769
19768
  init_constants6();
19770
19769
  init_src2();
19771
- downloadTemplate = async (type, name) => {
19770
+ downloadTemplate = async (type, name2) => {
19772
19771
  const DEFAULT_TEMPLATES_BUCKET = "prod-budi-templates.s3-eu-west-1.amazonaws.com";
19773
- const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${name}.tar.gz`;
19772
+ const templateUrl = `https://${DEFAULT_TEMPLATES_BUCKET}/templates/${type}/${name2}.tar.gz`;
19774
19773
  return objectStore_exports2.downloadTarball(
19775
19774
  templateUrl,
19776
19775
  ObjectStoreBuckets2.TEMPLATES,
@@ -19808,7 +19807,7 @@ __export(exports_exports, {
19808
19807
  exportDB: () => exportDB,
19809
19808
  streamExportApp: () => streamExportApp
19810
19809
  });
19811
- function tarFilesToTmp(tmpDir, files) {
19810
+ function tarFilesToTmp(tmpDir, files2) {
19812
19811
  const fileName = `${uuid3()}.tar.gz`;
19813
19812
  const exportFile = (0, import_path11.join)(budibaseTempDir2(), fileName);
19814
19813
  import_tar2.default.create(
@@ -19819,7 +19818,7 @@ function tarFilesToTmp(tmpDir, files) {
19819
19818
  noDirRecurse: false,
19820
19819
  cwd: tmpDir
19821
19820
  },
19822
- files
19821
+ files2
19823
19822
  );
19824
19823
  return exportFile;
19825
19824
  }
@@ -19855,7 +19854,7 @@ function defineFilter(excludeRows, excludeLogs) {
19855
19854
  if (excludeLogs) {
19856
19855
  ids.push(AUTOMATION_LOG_PREFIX);
19857
19856
  }
19858
- return (doc) => !ids.map((key) => doc._id.includes(key)).reduce((prev, curr) => prev || curr);
19857
+ return (doc2) => !ids.map((key) => doc2._id.includes(key)).reduce((prev, curr) => prev || curr);
19859
19858
  }
19860
19859
  async function exportApp(appId, config) {
19861
19860
  const prodAppId = db_exports.getProdAppID(appId);
@@ -20014,9 +20013,9 @@ async function getTemplateStream(template) {
20014
20013
  if (template.file) {
20015
20014
  return import_fs13.default.createReadStream(template.file.path);
20016
20015
  } else if (template.key) {
20017
- const [type, name] = template.key.split("/");
20018
- const tmpPath = await downloadTemplate(type, name);
20019
- return import_fs13.default.createReadStream((0, import_path12.join)(tmpPath, name, "db", "dump.txt"));
20016
+ const [type, name2] = template.key.split("/");
20017
+ const tmpPath = await downloadTemplate(type, name2);
20018
+ return import_fs13.default.createReadStream((0, import_path12.join)(tmpPath, name2, "db", "dump.txt"));
20020
20019
  }
20021
20020
  }
20022
20021
  function untarFile(file) {
@@ -20347,18 +20346,18 @@ function finaliseExternalTables(tables, entities) {
20347
20346
  let finalTables = {};
20348
20347
  const errors = {};
20349
20348
  const tableIds = Object.values(tables).map((table) => table._id);
20350
- for (let [name, table] of Object.entries(tables)) {
20349
+ for (let [name2, table] of Object.entries(tables)) {
20351
20350
  const schemaFields = Object.keys(table.schema);
20352
20351
  if (table.primary == null || table.primary.length === 0) {
20353
- errors[name] = "no_key" /* NO_KEY */;
20352
+ errors[name2] = "no_key" /* NO_KEY */;
20354
20353
  continue;
20355
20354
  } else if (schemaFields.find(
20356
20355
  (field) => invalidColumns.includes(field)
20357
20356
  )) {
20358
- errors[name] = "invalid_column" /* INVALID_COLUMN */;
20357
+ errors[name2] = "invalid_column" /* INVALID_COLUMN */;
20359
20358
  continue;
20360
20359
  }
20361
- finalTables[name] = copyExistingPropsOver(name, table, entities, tableIds);
20360
+ finalTables[name2] = copyExistingPropsOver(name2, table, entities, tableIds);
20362
20361
  }
20363
20362
  finalTables = Object.entries(finalTables).sort(([a], [b]) => a.localeCompare(b)).reduce((r, [k, v]) => ({ ...r, [k]: v }), {});
20364
20363
  return { tables: finalTables, errors };
@@ -22256,21 +22255,21 @@ var init_mongodb = __esm({
22256
22255
  const collection = db2.collection(query.extra.collection);
22257
22256
  let response2 = [];
22258
22257
  if (((_a = query.extra) == null ? void 0 : _a.actionType) === "pipeline") {
22259
- for await (const doc of collection.aggregate(
22258
+ for await (const doc2 of collection.aggregate(
22260
22259
  query.steps.map(({ key, value }) => {
22261
22260
  let temp = {};
22262
22261
  temp[key] = JSON.parse(value.value);
22263
22262
  return this.createObjectIds(temp);
22264
22263
  })
22265
22264
  )) {
22266
- response2.push(doc);
22265
+ response2.push(doc2);
22267
22266
  }
22268
22267
  } else {
22269
22268
  const stages = query.json;
22270
- for await (const doc of collection.aggregate(
22269
+ for await (const doc2 of collection.aggregate(
22271
22270
  stages ? this.createObjectIds(stages) : []
22272
22271
  )) {
22273
- response2.push(doc);
22272
+ response2.push(doc2);
22274
22273
  }
22275
22274
  }
22276
22275
  return response2;
@@ -22581,9 +22580,9 @@ var init_couchdb = __esm({
22581
22580
  });
22582
22581
  }
22583
22582
  async delete(query) {
22584
- const doc = await this.query("get", "Cannot find doc to be deleted", query);
22583
+ const doc2 = await this.query("get", "Cannot find doc to be deleted", query);
22585
22584
  return this.query("remove", "Error deleting couchDB document", {
22586
- json: doc
22585
+ json: doc2
22587
22586
  });
22588
22587
  }
22589
22588
  };
@@ -22769,7 +22768,7 @@ var init_microsoftSqlServer = __esm({
22769
22768
  throw "Unable to get list of tables in database";
22770
22769
  }
22771
22770
  const schema = this.config.schema || DEFAULT_SCHEMA;
22772
- const tableNames = tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name) => this.MASTER_TABLES.indexOf(name) === -1);
22771
+ const tableNames = tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name2) => this.MASTER_TABLES.indexOf(name2) === -1);
22773
22772
  const tables = {};
22774
22773
  for (let tableName of tableNames) {
22775
22774
  const definition26 = await this.runSQL(this.getDefinitionSQL(tableName));
@@ -22784,16 +22783,16 @@ var init_microsoftSqlServer = __esm({
22784
22783
  const requiredColumns = columns.filter((col) => col.IS_NULLABLE === "NO").map((col) => col.COLUMN_NAME);
22785
22784
  let schema2 = {};
22786
22785
  for (let def of definition26) {
22787
- const name = def.COLUMN_NAME;
22788
- if (typeof name !== "string") {
22786
+ const name2 = def.COLUMN_NAME;
22787
+ if (typeof name2 !== "string") {
22789
22788
  continue;
22790
22789
  }
22791
22790
  const hasDefault = def.COLUMN_DEFAULT;
22792
- const isAuto = !!autoColumns.find((col) => col === name);
22793
- const required = !!requiredColumns.find((col) => col === name);
22794
- schema2[name] = {
22791
+ const isAuto = !!autoColumns.find((col) => col === name2);
22792
+ const required = !!requiredColumns.find((col) => col === name2);
22793
+ schema2[name2] = {
22795
22794
  autocolumn: isAuto,
22796
- name,
22795
+ name: name2,
22797
22796
  constraints: {
22798
22797
  presence: required && !isAuto && !hasDefault
22799
22798
  },
@@ -22815,7 +22814,7 @@ var init_microsoftSqlServer = __esm({
22815
22814
  async queryTableNames() {
22816
22815
  let tableInfo = await this.runSQL(this.TABLES_SQL);
22817
22816
  const schema = this.config.schema || DEFAULT_SCHEMA;
22818
- return tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name) => this.MASTER_TABLES.indexOf(name) === -1);
22817
+ return tableInfo.filter((record) => record.TABLE_SCHEMA === schema).map((record) => record.TABLE_NAME).filter((name2) => this.MASTER_TABLES.indexOf(name2) === -1);
22819
22818
  }
22820
22819
  async getTableNames() {
22821
22820
  await this.connect();
@@ -24244,13 +24243,13 @@ var init_googlesheets = __esm({
24244
24243
  }
24245
24244
  return rowObject;
24246
24245
  }
24247
- async createTable(name) {
24248
- if (!name) {
24246
+ async createTable(name2) {
24247
+ if (!name2) {
24249
24248
  throw new Error("Must provide name for new sheet.");
24250
24249
  }
24251
24250
  try {
24252
24251
  await this.connect();
24253
- return await this.client.addSheet({ title: name, headerValues: [name] });
24252
+ return await this.client.addSheet({ title: name2, headerValues: [name2] });
24254
24253
  } catch (err) {
24255
24254
  console.error("Error creating new table in google sheets", err);
24256
24255
  throw err;
@@ -24576,7 +24575,7 @@ var init_firebase = __esm({
24576
24575
  snapshot = await collectionRef.get();
24577
24576
  }
24578
24577
  const result = [];
24579
- snapshot.forEach((doc) => result.push(doc.data()));
24578
+ snapshot.forEach((doc2) => result.push(doc2.data()));
24580
24579
  return result;
24581
24580
  } catch (err) {
24582
24581
  console.error("Error querying Firestore", err);
@@ -25238,13 +25237,13 @@ var init_oracle = __esm({
25238
25237
  });
25239
25238
 
25240
25239
  // src/integrations/index.ts
25241
- async function getDefinition(source) {
25242
- const definition26 = DEFINITIONS2[source];
25240
+ async function getDefinition(source2) {
25241
+ const definition26 = DEFINITIONS2[source2];
25243
25242
  if (definition26) {
25244
25243
  return definition26;
25245
25244
  }
25246
25245
  const allDefinitions = await getDefinitions();
25247
- return allDefinitions[source];
25246
+ return allDefinitions[source2];
25248
25247
  }
25249
25248
  async function getDefinitions() {
25250
25249
  const pluginSchemas = {};
@@ -25580,10 +25579,10 @@ __export(webhook_exports2, {
25580
25579
  function isWebhookID(id) {
25581
25580
  return id.startsWith(db_exports.DocumentType.WEBHOOK);
25582
25581
  }
25583
- function newDoc(name, type, target) {
25582
+ function newDoc(name2, type, target) {
25584
25583
  return {
25585
25584
  live: true,
25586
- name,
25585
+ name: name2,
25587
25586
  action: {
25588
25587
  type,
25589
25588
  target
@@ -25601,12 +25600,12 @@ async function save7(webhook) {
25601
25600
  webhook._rev = response2.rev;
25602
25601
  return webhook;
25603
25602
  }
25604
- async function destroy6(id, rev) {
25603
+ async function destroy6(id, rev2) {
25605
25604
  const db2 = context_exports.getAppDB();
25606
25605
  if (!id || !isWebhookID(id)) {
25607
25606
  throw new Error("Provided webhook ID is not valid.");
25608
25607
  }
25609
- return await db2.remove(id, rev);
25608
+ return await db2.remove(id, rev2);
25610
25609
  }
25611
25610
  var init_webhook2 = __esm({
25612
25611
  "src/sdk/app/automations/webhook.ts"() {
@@ -25783,9 +25782,9 @@ async function syncUsersToApp(appId, users2, groups) {
25783
25782
  if (roleId === roles_exports.BUILTIN_ROLE_IDS.PUBLIC) {
25784
25783
  roleId = void 0;
25785
25784
  }
25786
- let metadata;
25785
+ let metadata2;
25787
25786
  try {
25788
- metadata = await db2.get(metadataId);
25787
+ metadata2 = await db2.get(metadataId);
25789
25788
  } catch (err) {
25790
25789
  if (err.status !== 404) {
25791
25790
  throw err;
@@ -25793,19 +25792,19 @@ async function syncUsersToApp(appId, users2, groups) {
25793
25792
  if (!roleId) {
25794
25793
  continue;
25795
25794
  } else if (!deletedUser) {
25796
- metadata = {
25795
+ metadata2 = {
25797
25796
  tableId: InternalTables.USER_METADATA
25798
25797
  };
25799
25798
  }
25800
25799
  }
25801
25800
  if (deletedUser || !roleId) {
25802
- await db2.remove(metadata);
25801
+ await db2.remove(metadata2);
25803
25802
  continue;
25804
25803
  }
25805
25804
  if (roleId) {
25806
- metadata.roleId = roleId;
25805
+ metadata2.roleId = roleId;
25807
25806
  }
25808
- let combined = sdk_default.users.combineMetadataAndUser(ctxUser, metadata);
25807
+ let combined = sdk_default.users.combineMetadataAndUser(ctxUser, metadata2);
25809
25808
  if (combined) {
25810
25809
  await db2.put(combined);
25811
25810
  }
@@ -25862,7 +25861,7 @@ async function syncApp(appId, opts) {
25862
25861
  try {
25863
25862
  const replOpts = replication.appReplicateOpts();
25864
25863
  if (opts == null ? void 0 : opts.automationOnly) {
25865
- replOpts.filter = (doc) => doc._id.startsWith(db_exports.DocumentType.AUTOMATION);
25864
+ replOpts.filter = (doc2) => doc2._id.startsWith(db_exports.DocumentType.AUTOMATION);
25866
25865
  }
25867
25866
  await replication.replicate(replOpts);
25868
25867
  } catch (err) {
@@ -26089,9 +26088,9 @@ __export(utils_exports8, {
26089
26088
  rawUserMetadata: () => rawUserMetadata,
26090
26089
  syncGlobalUsers: () => syncGlobalUsers
26091
26090
  });
26092
- function combineMetadataAndUser(user, metadata) {
26091
+ function combineMetadataAndUser(user, metadata2) {
26093
26092
  const metadataId = generateUserMetadataID2(user._id);
26094
- const found = Array.isArray(metadata) ? metadata.find((doc) => doc._id === metadataId) : metadata;
26093
+ const found = Array.isArray(metadata2) ? metadata2.find((doc2) => doc2._id === metadataId) : metadata2;
26095
26094
  if (user.roleId == null || user.roleId === roles_exports.BUILTIN_ROLE_IDS.PUBLIC) {
26096
26095
  if (found == null ? void 0 : found._id) {
26097
26096
  return { ...found, _deleted: true };
@@ -26136,16 +26135,16 @@ async function syncGlobalUsers() {
26136
26135
  }
26137
26136
  const resp = await Promise.all([getGlobalUsers(), rawUserMetadata(db2)]);
26138
26137
  const users2 = resp[0];
26139
- const metadata = resp[1];
26138
+ const metadata2 = resp[1];
26140
26139
  const toWrite = [];
26141
26140
  for (let user of users2) {
26142
- const combined = combineMetadataAndUser(user, metadata);
26141
+ const combined = combineMetadataAndUser(user, metadata2);
26143
26142
  if (combined) {
26144
26143
  toWrite.push(combined);
26145
26144
  }
26146
26145
  }
26147
26146
  let foundEmails = [];
26148
- for (let data2 of metadata) {
26147
+ for (let data2 of metadata2) {
26149
26148
  if (!data2._id) {
26150
26149
  continue;
26151
26150
  }
@@ -26274,17 +26273,17 @@ var init_client2 = __esm({
26274
26273
  // src/utilities/users.ts
26275
26274
  async function getFullUser(ctx, userId) {
26276
26275
  const global = await getGlobalUser(userId);
26277
- let metadata = {};
26276
+ let metadata2 = {};
26278
26277
  delete global._id;
26279
26278
  delete global._rev;
26280
26279
  try {
26281
26280
  const db2 = context_exports.getAppDB();
26282
- metadata = await db2.get(userId);
26281
+ metadata2 = await db2.get(userId);
26283
26282
  } catch (err) {
26284
26283
  }
26285
- delete metadata.csrfToken;
26284
+ delete metadata2.csrfToken;
26286
26285
  return {
26287
- ...metadata,
26286
+ ...metadata2,
26288
26287
  ...global,
26289
26288
  roleId: global.roleId || roles_exports.BUILTIN_ROLE_IDS.PUBLIC,
26290
26289
  tableId: InternalTables.USER_METADATA,
@@ -26303,10 +26302,10 @@ var init_users12 = __esm({
26303
26302
  // src/api/controllers/user.ts
26304
26303
  async function fetchMetadata(ctx) {
26305
26304
  const global = await getGlobalUsers();
26306
- const metadata = await sdk_default.users.rawUserMetadata();
26305
+ const metadata2 = await sdk_default.users.rawUserMetadata();
26307
26306
  const users2 = [];
26308
26307
  for (let user of global) {
26309
- const info = metadata.find((meta) => meta._id.includes(user._id));
26308
+ const info = metadata2.find((meta) => meta._id.includes(user._id));
26310
26309
  users2.push({
26311
26310
  ...user,
26312
26311
  ...info,
@@ -26321,11 +26320,11 @@ async function updateMetadata(ctx) {
26321
26320
  const db2 = context_exports.getAppDB();
26322
26321
  const user = ctx.request.body;
26323
26322
  delete user.roles;
26324
- const metadata = {
26323
+ const metadata2 = {
26325
26324
  tableId: InternalTables.USER_METADATA,
26326
26325
  ...user
26327
26326
  };
26328
- ctx.body = await db2.put(metadata);
26327
+ ctx.body = await db2.put(metadata2);
26329
26328
  }
26330
26329
  async function destroyMetadata(ctx) {
26331
26330
  const db2 = context_exports.getAppDB();
@@ -26623,16 +26622,16 @@ async function fetch16(type) {
26623
26622
  return plugins2;
26624
26623
  }
26625
26624
  }
26626
- async function processUploaded(plugin, source) {
26625
+ async function processUploaded(plugin, source2) {
26627
26626
  var _a, _b;
26628
- const { metadata, directory } = await fileUpload(plugin);
26629
- plugin_exports.validate(metadata == null ? void 0 : metadata.schema);
26630
- if (!environment_default.SELF_HOSTED && ((_a = metadata == null ? void 0 : metadata.schema) == null ? void 0 : _a.type) !== "component" /* COMPONENT */) {
26627
+ const { metadata: metadata2, directory: directory2 } = await fileUpload(plugin);
26628
+ plugin_exports.validate(metadata2 == null ? void 0 : metadata2.schema);
26629
+ if (!environment_default.SELF_HOSTED && ((_a = metadata2 == null ? void 0 : metadata2.schema) == null ? void 0 : _a.type) !== "component" /* COMPONENT */) {
26631
26630
  throw new Error("Only component plugins are supported outside of self-host");
26632
26631
  }
26633
- const doc = await sdk_exports.plugins.storePlugin(metadata, directory, source);
26634
- (_b = clientAppSocket) == null ? void 0 : _b.emit("plugin-update", { name: doc.name, hash: doc.hash });
26635
- return doc;
26632
+ const doc2 = await sdk_exports.plugins.storePlugin(metadata2, directory2, source2);
26633
+ (_b = clientAppSocket) == null ? void 0 : _b.emit("plugin-update", { name: doc2.name, hash: doc2.hash });
26634
+ return doc2;
26636
26635
  }
26637
26636
  var init_plugins4 = __esm({
26638
26637
  "src/sdk/plugins/plugins.ts"() {
@@ -27733,20 +27732,20 @@ async function createLinkView() {
27733
27732
  const db2 = context_exports.getAppDB();
27734
27733
  const designDoc = await db2.get("_design/database");
27735
27734
  const view2 = {
27736
- map: function(doc) {
27737
- if (doc.type === "link") {
27738
- let doc1 = doc.doc1;
27739
- let doc2 = doc.doc2;
27735
+ map: function(doc2) {
27736
+ if (doc2.type === "link") {
27737
+ let doc1 = doc2.doc1;
27738
+ let doc22 = doc2.doc2;
27740
27739
  emit([doc1.tableId, doc1.rowId], {
27741
- id: doc2.rowId,
27740
+ id: doc22.rowId,
27742
27741
  thisId: doc1.rowId,
27743
27742
  fieldName: doc1.fieldName
27744
27743
  });
27745
- if (doc1.tableId !== doc2.tableId) {
27746
- emit([doc2.tableId, doc2.rowId], {
27744
+ if (doc1.tableId !== doc22.tableId) {
27745
+ emit([doc22.tableId, doc22.rowId], {
27747
27746
  id: doc1.rowId,
27748
- thisId: doc2.rowId,
27749
- fieldName: doc2.fieldName
27747
+ thisId: doc22.rowId,
27748
+ fieldName: doc22.fieldName
27750
27749
  });
27751
27750
  }
27752
27751
  }
@@ -28048,11 +28047,11 @@ var LinkController = class {
28048
28047
  );
28049
28048
  }
28050
28049
  }
28051
- let toDeleteDocs = thisFieldLinkDocs.filter((doc) => {
28052
- let correctDoc = doc.doc1.fieldName === fieldName ? doc.doc2 : doc.doc1;
28050
+ let toDeleteDocs = thisFieldLinkDocs.filter((doc2) => {
28051
+ let correctDoc = doc2.doc1.fieldName === fieldName ? doc2.doc2 : doc2.doc1;
28053
28052
  return rowField.indexOf(correctDoc.rowId) === -1;
28054
- }).map((doc) => {
28055
- return { ...doc, _deleted: true };
28053
+ }).map((doc2) => {
28054
+ return { ...doc2, _deleted: true };
28056
28055
  });
28057
28056
  operations.push(...toDeleteDocs);
28058
28057
  delete row[fieldName];
@@ -28073,9 +28072,9 @@ var LinkController = class {
28073
28072
  if (linkDocs.length === 0) {
28074
28073
  return null;
28075
28074
  }
28076
- const toDelete = linkDocs.map((doc) => {
28075
+ const toDelete = linkDocs.map((doc2) => {
28077
28076
  return {
28078
- ...doc,
28077
+ ...doc2,
28079
28078
  _deleted: true
28080
28079
  };
28081
28080
  });
@@ -28096,9 +28095,9 @@ var LinkController = class {
28096
28095
  return correctFieldName === fieldName;
28097
28096
  });
28098
28097
  await this._db.bulkDocs(
28099
- toDelete.map((doc) => {
28098
+ toDelete.map((doc2) => {
28100
28099
  return {
28101
- ...doc,
28100
+ ...doc2,
28102
28101
  _deleted: true
28103
28102
  };
28104
28103
  })
@@ -28196,9 +28195,9 @@ var LinkController = class {
28196
28195
  if (linkDocs.length === 0) {
28197
28196
  return null;
28198
28197
  }
28199
- const toDelete = linkDocs.map((doc) => {
28198
+ const toDelete = linkDocs.map((doc2) => {
28200
28199
  return {
28201
- ...doc,
28200
+ ...doc2,
28202
28201
  _deleted: true
28203
28202
  };
28204
28203
  });
@@ -28537,10 +28536,10 @@ async function cleanupAttachments(table, {
28537
28536
  return;
28538
28537
  }
28539
28538
  }
28540
- let files = [];
28539
+ let files2 = [];
28541
28540
  function addFiles(row2, key) {
28542
28541
  if (row2[key]) {
28543
- files = files.concat(row2[key].map((attachment) => attachment.key));
28542
+ files2 = files2.concat(row2[key].map((attachment) => attachment.key));
28544
28543
  }
28545
28544
  }
28546
28545
  const schemaToUse = oldTable ? oldTable.schema : table.schema;
@@ -28551,15 +28550,15 @@ async function cleanupAttachments(table, {
28551
28550
  if (rows2 && oldTable && !table.schema[key]) {
28552
28551
  rows2.forEach((row2) => addFiles(row2, key));
28553
28552
  } else if (oldRow && row) {
28554
- files = files.concat(getRemovedAttachmentKeys(oldRow, row, key));
28553
+ files2 = files2.concat(getRemovedAttachmentKeys(oldRow, row, key));
28555
28554
  } else if (row) {
28556
28555
  addFiles(row, key);
28557
28556
  } else if (rows2) {
28558
28557
  rows2.forEach((row2) => addFiles(row2, key));
28559
28558
  }
28560
28559
  }
28561
- if (files.length > 0) {
28562
- await objectStore_exports2.deleteFiles(ObjectStoreBuckets2.APPS, files);
28560
+ if (files2.length > 0) {
28561
+ await objectStore_exports2.deleteFiles(ObjectStoreBuckets2.APPS, files2);
28563
28562
  }
28564
28563
  }
28565
28564
 
@@ -28734,7 +28733,7 @@ async function runView(view, calculation, group, data) {
28734
28733
  _rev: void 0
28735
28734
  }))
28736
28735
  );
28737
- let fn = (doc, emit2) => emit2(doc._id);
28736
+ let fn = (doc2, emit2) => emit2(doc2._id);
28738
28737
  eval("fn = " + ((_a = view == null ? void 0 : view.map) == null ? void 0 : _a.replace("function (doc)", "function (doc, emit)")));
28739
28738
  const queryFns = {
28740
28739
  meta: view.meta,
@@ -29500,7 +29499,7 @@ function cleanupConfig(config, table) {
29500
29499
  const fieldNames = Object.entries(table.schema).filter((schema) => primaryOptions.find((val) => val === schema[1].type)).map(([fieldName]) => fieldName);
29501
29500
  const iterateObject = (obj) => {
29502
29501
  for (let [field, value] of Object.entries(obj)) {
29503
- if (fieldNames.find((name) => name === field) && isRowId(value)) {
29502
+ if (fieldNames.find((name2) => name2 === field) && isRowId(value)) {
29504
29503
  obj[field] = convertRowId(value);
29505
29504
  }
29506
29505
  }
@@ -32213,7 +32212,7 @@ function rowEmission({
32213
32212
  appId,
32214
32213
  row,
32215
32214
  table,
32216
- metadata
32215
+ metadata: metadata2
32217
32216
  }) {
32218
32217
  let event = {
32219
32218
  row,
@@ -32227,8 +32226,8 @@ function rowEmission({
32227
32226
  if (row == null ? void 0 : row._rev) {
32228
32227
  event.revision = row._rev;
32229
32228
  }
32230
- if (metadata) {
32231
- event.metadata = metadata;
32229
+ if (metadata2) {
32230
+ event.metadata = metadata2;
32232
32231
  }
32233
32232
  emitter2.emit(eventName, event);
32234
32233
  }
@@ -32237,7 +32236,7 @@ function tableEmission({
32237
32236
  eventName,
32238
32237
  appId,
32239
32238
  table,
32240
- metadata
32239
+ metadata: metadata2
32241
32240
  }) {
32242
32241
  const tableId = table == null ? void 0 : table._id;
32243
32242
  const inputTable = table;
@@ -32253,8 +32252,8 @@ function tableEmission({
32253
32252
  if (table == null ? void 0 : table._rev) {
32254
32253
  event.revision = table._rev;
32255
32254
  }
32256
- if (metadata) {
32257
- event.metadata = metadata;
32255
+ if (metadata2) {
32256
+ event.metadata = metadata2;
32258
32257
  }
32259
32258
  emitter2.emit(eventName, event);
32260
32259
  }
@@ -32396,8 +32395,8 @@ var Orchestrator = class {
32396
32395
  constructor(job) {
32397
32396
  let automation = job.data.automation;
32398
32397
  let triggerOutput = job.data.event;
32399
- const metadata = triggerOutput.metadata;
32400
- this._chainCount = metadata ? metadata.automationChainCount : 0;
32398
+ const metadata2 = triggerOutput.metadata;
32399
+ this._chainCount = metadata2 ? metadata2.automationChainCount : 0;
32401
32400
  this._appId = triggerOutput.appId;
32402
32401
  this._job = job;
32403
32402
  const triggerStepId = automation.definition.trigger.stepId;
@@ -32427,16 +32426,16 @@ var Orchestrator = class {
32427
32426
  async getMetadata() {
32428
32427
  const metadataId = generateAutomationMetadataID(this._automation._id);
32429
32428
  const db2 = context_exports.getAppDB();
32430
- let metadata;
32429
+ let metadata2;
32431
32430
  try {
32432
- metadata = await db2.get(metadataId);
32431
+ metadata2 = await db2.get(metadataId);
32433
32432
  } catch (err) {
32434
- metadata = {
32433
+ metadata2 = {
32435
32434
  _id: metadataId,
32436
32435
  errorCount: 0
32437
32436
  };
32438
32437
  }
32439
- return metadata;
32438
+ return metadata2;
32440
32439
  }
32441
32440
  async stopCron(reason) {
32442
32441
  if (!this._job.opts.repeat) {
@@ -32459,34 +32458,34 @@ var Orchestrator = class {
32459
32458
  );
32460
32459
  await storeLog2(automation, this.executionOutput);
32461
32460
  }
32462
- async checkIfShouldStop(metadata) {
32463
- if (!metadata.errorCount || !this._job.opts.repeat) {
32461
+ async checkIfShouldStop(metadata2) {
32462
+ if (!metadata2.errorCount || !this._job.opts.repeat) {
32464
32463
  return false;
32465
32464
  }
32466
- if (metadata.errorCount >= MAX_AUTOMATION_RECURRING_ERRORS) {
32465
+ if (metadata2.errorCount >= MAX_AUTOMATION_RECURRING_ERRORS) {
32467
32466
  await this.stopCron("errors");
32468
32467
  return true;
32469
32468
  }
32470
32469
  return false;
32471
32470
  }
32472
- async updateMetadata(metadata) {
32471
+ async updateMetadata(metadata2) {
32473
32472
  const output = this.executionOutput, automation = this._automation;
32474
32473
  if (!output || !isRecurring(automation)) {
32475
32474
  return;
32476
32475
  }
32477
- const count = metadata.errorCount;
32476
+ const count = metadata2.errorCount;
32478
32477
  const isError = isErrorInOutput(output);
32479
32478
  if (!count && !isError) {
32480
32479
  return;
32481
32480
  }
32482
32481
  if (isError) {
32483
- metadata.errorCount = count ? count + 1 : 1;
32482
+ metadata2.errorCount = count ? count + 1 : 1;
32484
32483
  } else {
32485
- metadata.errorCount = 0;
32484
+ metadata2.errorCount = 0;
32486
32485
  }
32487
32486
  const db2 = context_exports.getAppDB();
32488
32487
  try {
32489
- await db2.put(metadata);
32488
+ await db2.put(metadata2);
32490
32489
  } catch (err) {
32491
32490
  logging_exports.logAlertWithInfo(
32492
32491
  "Failed to write automation metadata",
@@ -32537,13 +32536,13 @@ var Orchestrator = class {
32537
32536
  let stepCount = 0;
32538
32537
  let loopStepNumber = void 0;
32539
32538
  let loopSteps = [];
32540
- let metadata;
32539
+ let metadata2;
32541
32540
  let timeoutFlag = false;
32542
32541
  let wasLoopStep = false;
32543
32542
  let timeout2 = this._job.data.event.timeout;
32544
32543
  if (isProdAppID2(this._appId) && isRecurring(automation)) {
32545
- metadata = await this.getMetadata();
32546
- const shouldStop = await this.checkIfShouldStop(metadata);
32544
+ metadata2 = await this.getMetadata();
32545
+ const shouldStop = await this.checkIfShouldStop(metadata2);
32547
32546
  if (shouldStop) {
32548
32547
  return;
32549
32548
  }
@@ -32747,8 +32746,8 @@ var Orchestrator = class {
32747
32746
  }
32748
32747
  logging_exports.logAlert("Error writing automation log", e);
32749
32748
  }
32750
- if (isProdAppID2(this._appId) && isRecurring(automation) && metadata) {
32751
- await this.updateMetadata(metadata);
32749
+ if (isProdAppID2(this._appId) && isRecurring(automation) && metadata2) {
32750
+ await this.updateMetadata(metadata2);
32752
32751
  }
32753
32752
  return this.executionOutput;
32754
32753
  }