@budibase/backend-core 2.10.13 → 2.10.14

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
@@ -1519,7 +1519,7 @@ var init_db2 = __esm({
1519
1519
  ViewName3["ROUTING"] = "screen_routes";
1520
1520
  ViewName3["AUTOMATION_LOGS"] = "automation_logs";
1521
1521
  ViewName3["ACCOUNT_BY_EMAIL"] = "account_by_email";
1522
- ViewName3["PLATFORM_USERS_LOWERCASE"] = "platform_users_lowercase";
1522
+ ViewName3["PLATFORM_USERS_LOWERCASE"] = "platform_users_lowercase_2";
1523
1523
  ViewName3["USER_BY_GROUP"] = "user_by_group";
1524
1524
  ViewName3["APP_BACKUP_BY_TRIGGER"] = "by_trigger";
1525
1525
  return ViewName3;
@@ -3847,13 +3847,17 @@ var init_views = __esm({
3847
3847
  if (doc.tenantId) {
3848
3848
  emit(doc._id.toLowerCase(), doc._id)
3849
3849
  }
3850
+
3851
+ if (doc.ssoId) {
3852
+ emit(doc.ssoId, doc._id)
3853
+ }
3850
3854
  }`;
3851
- await createPlatformView(viewJs, "platform_users_lowercase" /* PLATFORM_USERS_LOWERCASE */);
3855
+ await createPlatformView(viewJs, "platform_users_lowercase_2" /* PLATFORM_USERS_LOWERCASE */);
3852
3856
  };
3853
3857
  queryPlatformView = async (viewName, params2, opts) => {
3854
3858
  const CreateFuncByName2 = {
3855
3859
  ["account_by_email" /* ACCOUNT_BY_EMAIL */]: createPlatformAccountEmailView,
3856
- ["platform_users_lowercase" /* PLATFORM_USERS_LOWERCASE */]: createPlatformUserView
3860
+ ["platform_users_lowercase_2" /* PLATFORM_USERS_LOWERCASE */]: createPlatformUserView
3857
3861
  };
3858
3862
  return doWithDB(StaticDatabases.PLATFORM_INFO.name, async (db) => {
3859
3863
  const createFn = CreateFuncByName2[viewName];
@@ -5863,6 +5867,14 @@ function newUserEmailDoc(userId, email, tenantId) {
5863
5867
  tenantId
5864
5868
  };
5865
5869
  }
5870
+ function newUserSsoIdDoc(ssoId, email, userId, tenantId) {
5871
+ return {
5872
+ _id: ssoId,
5873
+ userId,
5874
+ email,
5875
+ tenantId
5876
+ };
5877
+ }
5866
5878
  async function addUserDoc(emailOrId, newDocFn) {
5867
5879
  const db = getPlatformDB();
5868
5880
  let user;
@@ -5877,11 +5889,17 @@ async function addUserDoc(emailOrId, newDocFn) {
5877
5889
  }
5878
5890
  }
5879
5891
  }
5880
- async function addUser(tenantId, userId, email) {
5881
- await Promise.all([
5892
+ async function addUser(tenantId, userId, email, ssoId) {
5893
+ const promises = [
5882
5894
  addUserDoc(userId, () => newUserIdDoc(userId, tenantId)),
5883
5895
  addUserDoc(email, () => newUserEmailDoc(userId, email, tenantId))
5884
- ]);
5896
+ ];
5897
+ if (ssoId) {
5898
+ promises.push(
5899
+ addUserDoc(ssoId, () => newUserSsoIdDoc(ssoId, email, userId, tenantId))
5900
+ );
5901
+ }
5902
+ await Promise.all(promises);
5885
5903
  }
5886
5904
  async function removeUser(user) {
5887
5905
  const db = getPlatformDB();
@@ -6461,7 +6479,7 @@ async function searchExistingEmails(emails) {
6461
6479
  return [...new Set(matchedEmails.map((email) => email.toLowerCase()))];
6462
6480
  }
6463
6481
  async function getPlatformUser(identifier) {
6464
- return await queryPlatformView("platform_users_lowercase" /* PLATFORM_USERS_LOWERCASE */, {
6482
+ return await queryPlatformView("platform_users_lowercase_2" /* PLATFORM_USERS_LOWERCASE */, {
6465
6483
  keys: [identifier.toLowerCase()],
6466
6484
  include_docs: true
6467
6485
  });
@@ -6492,7 +6510,7 @@ async function getExistingPlatformUsers(emails) {
6492
6510
  arrayResponse: true
6493
6511
  };
6494
6512
  return await queryPlatformView(
6495
- "platform_users_lowercase" /* PLATFORM_USERS_LOWERCASE */,
6513
+ "platform_users_lowercase_2" /* PLATFORM_USERS_LOWERCASE */,
6496
6514
  params2,
6497
6515
  opts
6498
6516
  );
@@ -9824,7 +9842,12 @@ var UserDB = class _UserDB {
9824
9842
  let response = await db.put(builtUser);
9825
9843
  builtUser._rev = response.rev;
9826
9844
  await handleSaveEvents(builtUser, dbUser);
9827
- await users_exports.addUser(tenantId, builtUser._id, builtUser.email);
9845
+ await users_exports.addUser(
9846
+ tenantId,
9847
+ builtUser._id,
9848
+ builtUser.email,
9849
+ builtUser.ssoId
9850
+ );
9828
9851
  await user_exports.invalidateUser(response.id);
9829
9852
  await Promise.all(groupPromises);
9830
9853
  return db.get(builtUser._id);