@budibase/backend-core 2.29.24 → 2.29.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -42652,9 +42652,9 @@ var require_schema_obj = __commonJS({
42652
42652
  }
42653
42653
  });
42654
42654
 
42655
- // ../../node_modules/json-schema-traverse/index.js
42655
+ // ../../node_modules/ajv/node_modules/json-schema-traverse/index.js
42656
42656
  var require_json_schema_traverse = __commonJS({
42657
- "../../node_modules/json-schema-traverse/index.js"(exports, module2) {
42657
+ "../../node_modules/ajv/node_modules/json-schema-traverse/index.js"(exports, module2) {
42658
42658
  "use strict";
42659
42659
  var traverse = module2.exports = function(schema, opts, cb) {
42660
42660
  if (typeof opts == "function") {
@@ -54561,6 +54561,7 @@ var AutomationTriggerStepId = /* @__PURE__ */ ((AutomationTriggerStepId2) => {
54561
54561
  AutomationTriggerStepId2["WEBHOOK"] = "WEBHOOK";
54562
54562
  AutomationTriggerStepId2["APP"] = "APP";
54563
54563
  AutomationTriggerStepId2["CRON"] = "CRON";
54564
+ AutomationTriggerStepId2["ROW_ACTION"] = "ROW_ACTION";
54564
54565
  return AutomationTriggerStepId2;
54565
54566
  })(AutomationTriggerStepId || {});
54566
54567
  var AutomationActionStepId = /* @__PURE__ */ ((AutomationActionStepId2) => {
@@ -55378,7 +55379,7 @@ var runQuery = (docs, query) => {
55378
55379
  if (Array.isArray(docValue)) {
55379
55380
  return docValue.length === 0;
55380
55381
  }
55381
- if (typeof docValue === "object") {
55382
+ if (docValue && typeof docValue === "object") {
55382
55383
  return Object.keys(docValue).length === 0;
55383
55384
  }
55384
55385
  return docValue == null;
@@ -55564,6 +55565,7 @@ function hasSchema(test) {
55564
55565
  var sdk_exports = {};
55565
55566
  __export(sdk_exports, {
55566
55567
  applications: () => applications_exports,
55568
+ automations: () => automations_exports,
55567
55569
  users: () => users_exports
55568
55570
  });
55569
55571
 
@@ -55600,6 +55602,21 @@ function getProdAppID(appId) {
55600
55602
  return `${APP_PREFIX}${rest}`;
55601
55603
  }
55602
55604
 
55605
+ // ../shared-core/src/sdk/documents/automations.ts
55606
+ var automations_exports = {};
55607
+ __export(automations_exports, {
55608
+ isAppAction: () => isAppAction,
55609
+ isRowAction: () => isRowAction
55610
+ });
55611
+ function isRowAction(automation) {
55612
+ const result = automation.definition.trigger?.stepId === "ROW_ACTION" /* ROW_ACTION */;
55613
+ return result;
55614
+ }
55615
+ function isAppAction(automation) {
55616
+ const result = automation.definition.trigger?.stepId === "APP" /* APP */;
55617
+ return result;
55618
+ }
55619
+
55603
55620
  // ../shared-core/src/sdk/documents/users.ts
55604
55621
  var users_exports = {};
55605
55622
  __export(users_exports, {
@@ -56464,6 +56481,12 @@ var DDInstrumentedDatabase = class {
56464
56481
  return this.db.remove(id, rev);
56465
56482
  });
56466
56483
  }
56484
+ bulkRemove(documents, opts) {
56485
+ return import_dd_trace.default.trace("db.bulkRemove", (span) => {
56486
+ span?.addTags({ db_name: this.name, num_docs: documents.length });
56487
+ return this.db.bulkRemove(documents, opts);
56488
+ });
56489
+ }
56467
56490
  put(document, opts) {
56468
56491
  return import_dd_trace.default.trace("db.put", (span) => {
56469
56492
  span?.addTags({ db_name: this.name, doc_id: document._id });
@@ -58716,14 +58739,16 @@ var createPlatformUserView = async () => {
58716
58739
  }`;
58717
58740
  await createPlatformView(viewJs, "platform_users_lowercase_2" /* PLATFORM_USERS_LOWERCASE */);
58718
58741
  };
58719
- var queryPlatformView = async (viewName, params2, opts) => {
58742
+ var queryPlatformView = async (viewName, params2) => {
58720
58743
  const CreateFuncByName2 = {
58721
58744
  ["account_by_email" /* ACCOUNT_BY_EMAIL */]: createPlatformAccountEmailView,
58722
58745
  ["platform_users_lowercase_2" /* PLATFORM_USERS_LOWERCASE */]: createPlatformUserView
58723
58746
  };
58724
58747
  return doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db) => {
58725
58748
  const createFn = CreateFuncByName2[viewName];
58726
- return queryView(viewName, params2, db, createFn, opts);
58749
+ return queryView(viewName, params2, db, createFn, {
58750
+ arrayResponse: true
58751
+ });
58727
58752
  });
58728
58753
  };
58729
58754
  var CreateFuncByName = {
@@ -59578,11 +59603,11 @@ var CouchDBError = class extends Error {
59578
59603
  const statusCode = info.status || info.statusCode || 500;
59579
59604
  this.status = statusCode;
59580
59605
  this.statusCode = statusCode;
59581
- this.reason = info.reason;
59606
+ this.reason = info.reason || "Unknown";
59582
59607
  this.name = info.name;
59583
- this.errid = info.errid;
59584
- this.description = info.description;
59585
- this.error = info.error;
59608
+ this.errid = info.errid || "Unknown";
59609
+ this.description = info.description || "Unknown";
59610
+ this.error = info.error || "Not found";
59586
59611
  }
59587
59612
  };
59588
59613
  function DatabaseWithConnection(dbName, connection, opts) {
@@ -59716,6 +59741,33 @@ var DatabaseImpl = class _DatabaseImpl {
59716
59741
  return () => db.destroy(_id, _rev);
59717
59742
  });
59718
59743
  }
59744
+ async bulkRemove(documents, opts) {
59745
+ const response = await this.performCall((db) => {
59746
+ return () => db.bulk({
59747
+ docs: documents.map((doc) => ({
59748
+ ...doc,
59749
+ _deleted: true
59750
+ }))
59751
+ });
59752
+ });
59753
+ if (opts?.silenceErrors) {
59754
+ return;
59755
+ }
59756
+ let errorFound = false;
59757
+ let errorMessage = "Unable to bulk remove documents: ";
59758
+ for (let res of response) {
59759
+ if (res.error) {
59760
+ errorFound = true;
59761
+ errorMessage += res.error;
59762
+ }
59763
+ }
59764
+ if (errorFound) {
59765
+ throw new CouchDBError(errorMessage, {
59766
+ name: this.name,
59767
+ status: 400
59768
+ });
59769
+ }
59770
+ }
59719
59771
  async post(document, opts) {
59720
59772
  if (!document._id) {
59721
59773
  document._id = newid();
@@ -60446,7 +60498,8 @@ __export(users_exports2, {
60446
60498
  addUser: () => addUser,
60447
60499
  getUserDoc: () => getUserDoc,
60448
60500
  lookupTenantId: () => lookupTenantId,
60449
- removeUser: () => removeUser
60501
+ removeUser: () => removeUser,
60502
+ updateUserDoc: () => updateUserDoc
60450
60503
  });
60451
60504
 
60452
60505
  // src/platform/platformDb.ts
@@ -60466,6 +60519,10 @@ async function getUserDoc(emailOrId) {
60466
60519
  const db = getPlatformDB();
60467
60520
  return db.get(emailOrId);
60468
60521
  }
60522
+ async function updateUserDoc(platformUser) {
60523
+ const db = getPlatformDB();
60524
+ await db.put(platformUser);
60525
+ }
60469
60526
  function newUserIdDoc(id, tenantId) {
60470
60527
  return {
60471
60528
  _id: id,
@@ -60524,13 +60581,10 @@ async function removeUser(user) {
60524
60581
  keys: keys2,
60525
60582
  include_docs: true
60526
60583
  });
60527
- const toDelete = userDocs.rows.map((row) => {
60528
- return {
60529
- ...row.doc,
60530
- _deleted: true
60531
- };
60532
- });
60533
- await db.bulkDocs(toDelete);
60584
+ await db.bulkRemove(
60585
+ userDocs.rows.map((row) => row.doc),
60586
+ { silenceErrors: true }
60587
+ );
60534
60588
  }
60535
60589
 
60536
60590
  // src/platform/tenants.ts
@@ -61103,9 +61157,10 @@ __export(users_exports3, {
61103
61157
  getExistingAccounts: () => getExistingAccounts,
61104
61158
  getExistingPlatformUsers: () => getExistingPlatformUsers,
61105
61159
  getExistingTenantUsers: () => getExistingTenantUsers,
61160
+ getFirstPlatformUser: () => getFirstPlatformUser,
61106
61161
  getGlobalUserByAppPage: () => getGlobalUserByAppPage,
61107
61162
  getGlobalUserByEmail: () => getGlobalUserByEmail,
61108
- getPlatformUser: () => getPlatformUser,
61163
+ getPlatformUsers: () => getPlatformUsers,
61109
61164
  getUserCount: () => getUserCount,
61110
61165
  hasAdminPermissions: () => hasAdminPermissions2,
61111
61166
  hasAppBuilderPermissions: () => hasAppBuilderPermissions2,
@@ -61208,12 +61263,16 @@ async function searchExistingEmails(emails) {
61208
61263
  matchedEmails.push(...invitedEmails.map((invite) => invite.email));
61209
61264
  return [...new Set(matchedEmails.map((email) => email.toLowerCase()))];
61210
61265
  }
61211
- async function getPlatformUser(identifier) {
61266
+ async function getPlatformUsers(identifier) {
61212
61267
  return await queryPlatformView("platform_users_lowercase_2" /* PLATFORM_USERS_LOWERCASE */, {
61213
61268
  keys: [identifier.toLowerCase()],
61214
61269
  include_docs: true
61215
61270
  });
61216
61271
  }
61272
+ async function getFirstPlatformUser(identifier) {
61273
+ const platformUserDocs = await getPlatformUsers(identifier);
61274
+ return platformUserDocs[0] ?? null;
61275
+ }
61217
61276
  async function getExistingTenantUsers(emails) {
61218
61277
  const lcEmails = emails.map((email) => email.toLowerCase());
61219
61278
  const params2 = {
@@ -61236,13 +61295,9 @@ async function getExistingPlatformUsers(emails) {
61236
61295
  keys: lcEmails,
61237
61296
  include_docs: true
61238
61297
  };
61239
- const opts = {
61240
- arrayResponse: true
61241
- };
61242
61298
  return await queryPlatformView(
61243
61299
  "platform_users_lowercase_2" /* PLATFORM_USERS_LOWERCASE */,
61244
- params2,
61245
- opts
61300
+ params2
61246
61301
  );
61247
61302
  }
61248
61303
  async function getExistingAccounts(emails) {
@@ -61251,14 +61306,7 @@ async function getExistingAccounts(emails) {
61251
61306
  keys: lcEmails,
61252
61307
  include_docs: true
61253
61308
  };
61254
- const opts = {
61255
- arrayResponse: true
61256
- };
61257
- return await queryPlatformView(
61258
- "account_by_email" /* ACCOUNT_BY_EMAIL */,
61259
- params2,
61260
- opts
61261
- );
61309
+ return await queryPlatformView("account_by_email" /* ACCOUNT_BY_EMAIL */, params2);
61262
61310
  }
61263
61311
 
61264
61312
  // src/errors/index.ts
@@ -61832,7 +61880,7 @@ async function isCreatorByGroupMembership(user) {
61832
61880
  }
61833
61881
  async function validateUniqueUser(email, tenantId) {
61834
61882
  if (environment_default.MULTI_TENANCY) {
61835
- const tenantUser = await getPlatformUser(email);
61883
+ const tenantUser = await getFirstPlatformUser(email);
61836
61884
  if (tenantUser != null && tenantUser.tenantId !== tenantId) {
61837
61885
  throw new EmailUnavailableError(email);
61838
61886
  }
@@ -64833,9 +64881,26 @@ var UserDB = class _UserDB {
64833
64881
  const creatorsToDeleteCount = creatorsEval.filter(
64834
64882
  (creator) => !!creator
64835
64883
  ).length;
64884
+ const ssoUsersToDelete = [];
64836
64885
  for (let user of usersToDelete) {
64886
+ const platformUser = await getFirstPlatformUser(
64887
+ user._id
64888
+ );
64889
+ const ssoId = platformUser.ssoId;
64890
+ if (ssoId) {
64891
+ const ssoUsers = await getPlatformUsers(
64892
+ ssoId
64893
+ );
64894
+ ssoUsers.filter((user2) => user2.ssoId == null).forEach((user2) => {
64895
+ ssoUsersToDelete.push({
64896
+ ...user2,
64897
+ _deleted: true
64898
+ });
64899
+ });
64900
+ }
64837
64901
  await bulkDeleteProcessing(user);
64838
64902
  }
64903
+ await getPlatformDB().bulkDocs(ssoUsersToDelete);
64839
64904
  await _UserDB.quotas.removeUsers(toDelete.length, creatorsToDeleteCount);
64840
64905
  const userIndex = {};
64841
64906
  usersToDelete.reduce((prev, current) => {