@budibase/backend-core 2.29.25 → 2.29.27

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) => {
@@ -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, {
@@ -58722,14 +58739,16 @@ var createPlatformUserView = async () => {
58722
58739
  }`;
58723
58740
  await createPlatformView(viewJs, "platform_users_lowercase_2" /* PLATFORM_USERS_LOWERCASE */);
58724
58741
  };
58725
- var queryPlatformView = async (viewName, params2, opts) => {
58742
+ var queryPlatformView = async (viewName, params2) => {
58726
58743
  const CreateFuncByName2 = {
58727
58744
  ["account_by_email" /* ACCOUNT_BY_EMAIL */]: createPlatformAccountEmailView,
58728
58745
  ["platform_users_lowercase_2" /* PLATFORM_USERS_LOWERCASE */]: createPlatformUserView
58729
58746
  };
58730
58747
  return doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db) => {
58731
58748
  const createFn = CreateFuncByName2[viewName];
58732
- return queryView(viewName, params2, db, createFn, opts);
58749
+ return queryView(viewName, params2, db, createFn, {
58750
+ arrayResponse: true
58751
+ });
58733
58752
  });
58734
58753
  };
58735
58754
  var CreateFuncByName = {
@@ -59780,8 +59799,11 @@ var DatabaseImpl = class _DatabaseImpl {
59780
59799
  });
59781
59800
  }
59782
59801
  async bulkDocs(documents) {
59802
+ const now = (/* @__PURE__ */ new Date()).toISOString();
59783
59803
  return this.performCall((db) => {
59784
- return () => db.bulk({ docs: documents });
59804
+ return () => db.bulk({
59805
+ docs: documents.map((d) => ({ createdAt: now, ...d, updatedAt: now }))
59806
+ });
59785
59807
  });
59786
59808
  }
59787
59809
  async allDocs(params2) {
@@ -60479,7 +60501,8 @@ __export(users_exports2, {
60479
60501
  addUser: () => addUser,
60480
60502
  getUserDoc: () => getUserDoc,
60481
60503
  lookupTenantId: () => lookupTenantId,
60482
- removeUser: () => removeUser
60504
+ removeUser: () => removeUser,
60505
+ updateUserDoc: () => updateUserDoc
60483
60506
  });
60484
60507
 
60485
60508
  // src/platform/platformDb.ts
@@ -60499,6 +60522,10 @@ async function getUserDoc(emailOrId) {
60499
60522
  const db = getPlatformDB();
60500
60523
  return db.get(emailOrId);
60501
60524
  }
60525
+ async function updateUserDoc(platformUser) {
60526
+ const db = getPlatformDB();
60527
+ await db.put(platformUser);
60528
+ }
60502
60529
  function newUserIdDoc(id, tenantId) {
60503
60530
  return {
60504
60531
  _id: id,
@@ -61133,9 +61160,10 @@ __export(users_exports3, {
61133
61160
  getExistingAccounts: () => getExistingAccounts,
61134
61161
  getExistingPlatformUsers: () => getExistingPlatformUsers,
61135
61162
  getExistingTenantUsers: () => getExistingTenantUsers,
61163
+ getFirstPlatformUser: () => getFirstPlatformUser,
61136
61164
  getGlobalUserByAppPage: () => getGlobalUserByAppPage,
61137
61165
  getGlobalUserByEmail: () => getGlobalUserByEmail,
61138
- getPlatformUser: () => getPlatformUser,
61166
+ getPlatformUsers: () => getPlatformUsers,
61139
61167
  getUserCount: () => getUserCount,
61140
61168
  hasAdminPermissions: () => hasAdminPermissions2,
61141
61169
  hasAppBuilderPermissions: () => hasAppBuilderPermissions2,
@@ -61238,12 +61266,16 @@ async function searchExistingEmails(emails) {
61238
61266
  matchedEmails.push(...invitedEmails.map((invite) => invite.email));
61239
61267
  return [...new Set(matchedEmails.map((email) => email.toLowerCase()))];
61240
61268
  }
61241
- async function getPlatformUser(identifier) {
61269
+ async function getPlatformUsers(identifier) {
61242
61270
  return await queryPlatformView("platform_users_lowercase_2" /* PLATFORM_USERS_LOWERCASE */, {
61243
61271
  keys: [identifier.toLowerCase()],
61244
61272
  include_docs: true
61245
61273
  });
61246
61274
  }
61275
+ async function getFirstPlatformUser(identifier) {
61276
+ const platformUserDocs = await getPlatformUsers(identifier);
61277
+ return platformUserDocs[0] ?? null;
61278
+ }
61247
61279
  async function getExistingTenantUsers(emails) {
61248
61280
  const lcEmails = emails.map((email) => email.toLowerCase());
61249
61281
  const params2 = {
@@ -61266,13 +61298,9 @@ async function getExistingPlatformUsers(emails) {
61266
61298
  keys: lcEmails,
61267
61299
  include_docs: true
61268
61300
  };
61269
- const opts = {
61270
- arrayResponse: true
61271
- };
61272
61301
  return await queryPlatformView(
61273
61302
  "platform_users_lowercase_2" /* PLATFORM_USERS_LOWERCASE */,
61274
- params2,
61275
- opts
61303
+ params2
61276
61304
  );
61277
61305
  }
61278
61306
  async function getExistingAccounts(emails) {
@@ -61281,14 +61309,7 @@ async function getExistingAccounts(emails) {
61281
61309
  keys: lcEmails,
61282
61310
  include_docs: true
61283
61311
  };
61284
- const opts = {
61285
- arrayResponse: true
61286
- };
61287
- return await queryPlatformView(
61288
- "account_by_email" /* ACCOUNT_BY_EMAIL */,
61289
- params2,
61290
- opts
61291
- );
61312
+ return await queryPlatformView("account_by_email" /* ACCOUNT_BY_EMAIL */, params2);
61292
61313
  }
61293
61314
 
61294
61315
  // src/errors/index.ts
@@ -61862,7 +61883,7 @@ async function isCreatorByGroupMembership(user) {
61862
61883
  }
61863
61884
  async function validateUniqueUser(email, tenantId) {
61864
61885
  if (environment_default.MULTI_TENANCY) {
61865
- const tenantUser = await getPlatformUser(email);
61886
+ const tenantUser = await getFirstPlatformUser(email);
61866
61887
  if (tenantUser != null && tenantUser.tenantId !== tenantId) {
61867
61888
  throw new EmailUnavailableError(email);
61868
61889
  }
@@ -64863,9 +64884,26 @@ var UserDB = class _UserDB {
64863
64884
  const creatorsToDeleteCount = creatorsEval.filter(
64864
64885
  (creator) => !!creator
64865
64886
  ).length;
64887
+ const ssoUsersToDelete = [];
64866
64888
  for (let user of usersToDelete) {
64889
+ const platformUser = await getFirstPlatformUser(
64890
+ user._id
64891
+ );
64892
+ const ssoId = platformUser.ssoId;
64893
+ if (ssoId) {
64894
+ const ssoUsers = await getPlatformUsers(
64895
+ ssoId
64896
+ );
64897
+ ssoUsers.filter((user2) => user2.ssoId == null).forEach((user2) => {
64898
+ ssoUsersToDelete.push({
64899
+ ...user2,
64900
+ _deleted: true
64901
+ });
64902
+ });
64903
+ }
64867
64904
  await bulkDeleteProcessing(user);
64868
64905
  }
64906
+ await getPlatformDB().bulkDocs(ssoUsersToDelete);
64869
64907
  await _UserDB.quotas.removeUsers(toDelete.length, creatorsToDeleteCount);
64870
64908
  const userIndex = {};
64871
64909
  usersToDelete.reduce((prev, current) => {