@budibase/backend-core 2.11.41 → 2.11.42

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
@@ -2141,8 +2141,8 @@ var init_pouchDB = __esm({
2141
2141
  import_pouchdb.default.adapter("writableStream", replicationStream.adapters.writableStream);
2142
2142
  }
2143
2143
  if (opts.find) {
2144
- const find2 = require("pouchdb-find");
2145
- import_pouchdb.default.plugin(find2);
2144
+ const find = require("pouchdb-find");
2145
+ import_pouchdb.default.plugin(find);
2146
2146
  }
2147
2147
  return import_pouchdb.default.defaults(POUCH_DB_DEFAULTS);
2148
2148
  };
@@ -2581,12 +2581,12 @@ function getAppId() {
2581
2581
  return foundId;
2582
2582
  }
2583
2583
  }
2584
- function doInEnvironmentContext(values2, task) {
2585
- if (!values2) {
2584
+ function doInEnvironmentContext(values, task) {
2585
+ if (!values) {
2586
2586
  throw new Error("Must supply environment variables.");
2587
2587
  }
2588
2588
  const updates = {
2589
- environmentVariables: values2
2589
+ environmentVariables: values
2590
2590
  };
2591
2591
  return newContext(updates, task);
2592
2592
  }
@@ -6254,7 +6254,6 @@ __export(users_exports3, {
6254
6254
  getAccountHolderFromUserIds: () => getAccountHolderFromUserIds,
6255
6255
  getAllUserIds: () => getAllUserIds,
6256
6256
  getById: () => getById,
6257
- getCreatorCount: () => getCreatorCount,
6258
6257
  getExistingAccounts: () => getExistingAccounts,
6259
6258
  getExistingPlatformUsers: () => getExistingPlatformUsers,
6260
6259
  getExistingTenantUsers: () => getExistingTenantUsers,
@@ -6268,7 +6267,6 @@ __export(users_exports3, {
6268
6267
  isAdmin: () => isAdmin2,
6269
6268
  isAdminOrBuilder: () => isAdminOrBuilder2,
6270
6269
  isBuilder: () => isBuilder2,
6271
- isCreator: () => isCreator2,
6272
6270
  isGlobalBuilder: () => isGlobalBuilder2,
6273
6271
  isSupportedUserSearch: () => isSupportedUserSearch,
6274
6272
  paginatedUsers: () => paginatedUsers,
@@ -6285,6 +6283,224 @@ init_db4();
6285
6283
  init_src();
6286
6284
  init_context2();
6287
6285
  init_context2();
6286
+ function removeUserPassword(users) {
6287
+ if (Array.isArray(users)) {
6288
+ return users.map((user) => {
6289
+ if (user) {
6290
+ delete user.password;
6291
+ return user;
6292
+ }
6293
+ });
6294
+ } else if (users) {
6295
+ delete users.password;
6296
+ return users;
6297
+ }
6298
+ return users;
6299
+ }
6300
+ var isSupportedUserSearch = (query) => {
6301
+ const allowed = [
6302
+ { op: "string" /* STRING */, key: "email" },
6303
+ { op: "equal" /* EQUAL */, key: "_id" }
6304
+ ];
6305
+ for (let [key, operation] of Object.entries(query)) {
6306
+ if (typeof operation !== "object") {
6307
+ return false;
6308
+ }
6309
+ const fields = Object.keys(operation || {});
6310
+ if (fields.length === 0) {
6311
+ continue;
6312
+ }
6313
+ const allowedOperation = allowed.find(
6314
+ (allow) => allow.op === key && fields.length === 1 && fields[0] === allow.key
6315
+ );
6316
+ if (!allowedOperation) {
6317
+ return false;
6318
+ }
6319
+ }
6320
+ return true;
6321
+ };
6322
+ var bulkGetGlobalUsersById = async (userIds, opts) => {
6323
+ const db = getGlobalDB();
6324
+ let users = (await db.allDocs({
6325
+ keys: userIds,
6326
+ include_docs: true
6327
+ })).rows.map((row) => row.doc);
6328
+ if (opts?.cleanup) {
6329
+ users = removeUserPassword(users);
6330
+ }
6331
+ return users;
6332
+ };
6333
+ var getAllUserIds = async () => {
6334
+ const db = getGlobalDB();
6335
+ const startKey = `${"us" /* USER */}${SEPARATOR}`;
6336
+ const response = await db.allDocs({
6337
+ startkey: startKey,
6338
+ endkey: `${startKey}${UNICODE_MAX}`
6339
+ });
6340
+ return response.rows.map((row) => row.id);
6341
+ };
6342
+ var bulkUpdateGlobalUsers = async (users) => {
6343
+ const db = getGlobalDB();
6344
+ return await db.bulkDocs(users);
6345
+ };
6346
+ async function getById(id, opts) {
6347
+ const db = getGlobalDB();
6348
+ let user = await db.get(id);
6349
+ if (opts?.cleanup) {
6350
+ user = removeUserPassword(user);
6351
+ }
6352
+ return user;
6353
+ }
6354
+ var getGlobalUserByEmail = async (email, opts) => {
6355
+ if (email == null) {
6356
+ throw "Must supply an email address to view";
6357
+ }
6358
+ const response = await queryGlobalView("by_email2" /* USER_BY_EMAIL */, {
6359
+ key: email.toLowerCase(),
6360
+ include_docs: true
6361
+ });
6362
+ if (Array.isArray(response)) {
6363
+ throw new Error(`Multiple users found with email address: ${email}`);
6364
+ }
6365
+ let user = response;
6366
+ if (opts?.cleanup) {
6367
+ user = removeUserPassword(user);
6368
+ }
6369
+ return user;
6370
+ };
6371
+ var searchGlobalUsersByApp = async (appId, opts, getOpts) => {
6372
+ if (typeof appId !== "string") {
6373
+ throw new Error("Must provide a string based app ID");
6374
+ }
6375
+ const params2 = getUsersByAppParams(appId, {
6376
+ include_docs: true
6377
+ });
6378
+ params2.startkey = opts && opts.startkey ? opts.startkey : params2.startkey;
6379
+ let response = await queryGlobalView("by_app" /* USER_BY_APP */, params2);
6380
+ if (!response) {
6381
+ response = [];
6382
+ }
6383
+ let users = Array.isArray(response) ? response : [response];
6384
+ if (getOpts?.cleanup) {
6385
+ users = removeUserPassword(users);
6386
+ }
6387
+ return users;
6388
+ };
6389
+ var searchGlobalUsersByAppAccess = async (appId, opts) => {
6390
+ const roleSelector = `roles.${appId}`;
6391
+ let orQuery = [
6392
+ {
6393
+ "builder.global": true
6394
+ },
6395
+ {
6396
+ "admin.global": true
6397
+ }
6398
+ ];
6399
+ if (appId) {
6400
+ const roleCheck = {
6401
+ [roleSelector]: {
6402
+ $exists: true
6403
+ }
6404
+ };
6405
+ orQuery.push(roleCheck);
6406
+ }
6407
+ let searchOptions = {
6408
+ selector: {
6409
+ $or: orQuery,
6410
+ _id: {
6411
+ $regex: "^us_"
6412
+ }
6413
+ },
6414
+ limit: opts?.limit || 50
6415
+ };
6416
+ const resp = await directCouchFind(getGlobalDBName(), searchOptions);
6417
+ return resp?.rows;
6418
+ };
6419
+ var getGlobalUserByAppPage = (appId, user) => {
6420
+ if (!user) {
6421
+ return;
6422
+ }
6423
+ return generateAppUserID(getProdAppID(appId), user._id);
6424
+ };
6425
+ var searchGlobalUsersByEmail = async (email, opts, getOpts) => {
6426
+ if (typeof email !== "string") {
6427
+ throw new Error("Must provide a string to search by");
6428
+ }
6429
+ const lcEmail = email.toLowerCase();
6430
+ const startkey = opts && opts.startkey ? opts.startkey : lcEmail;
6431
+ let response = await queryGlobalView("by_email2" /* USER_BY_EMAIL */, {
6432
+ ...opts,
6433
+ startkey,
6434
+ endkey: `${lcEmail}${UNICODE_MAX}`
6435
+ });
6436
+ if (!response) {
6437
+ response = [];
6438
+ }
6439
+ let users = Array.isArray(response) ? response : [response];
6440
+ if (getOpts?.cleanup) {
6441
+ users = removeUserPassword(users);
6442
+ }
6443
+ return users;
6444
+ };
6445
+ var PAGE_LIMIT = 8;
6446
+ var paginatedUsers = async ({
6447
+ bookmark,
6448
+ query,
6449
+ appId,
6450
+ limit
6451
+ } = {}) => {
6452
+ const db = getGlobalDB();
6453
+ const pageLimit = limit ? limit + 1 : PAGE_LIMIT + 1;
6454
+ const opts = {
6455
+ include_docs: true,
6456
+ limit: pageLimit
6457
+ };
6458
+ if (bookmark) {
6459
+ opts.startkey = bookmark;
6460
+ }
6461
+ let userList, property = "_id", getKey;
6462
+ if (query?.equal?._id) {
6463
+ userList = [await getById(query.equal._id)];
6464
+ } else if (appId) {
6465
+ userList = await searchGlobalUsersByApp(appId, opts);
6466
+ getKey = (doc) => getGlobalUserByAppPage(appId, doc);
6467
+ } else if (query?.string?.email) {
6468
+ userList = await searchGlobalUsersByEmail(query?.string?.email, opts);
6469
+ property = "email";
6470
+ } else {
6471
+ const response = await db.allDocs(getGlobalUserParams(null, opts));
6472
+ userList = response.rows.map((row) => row.doc);
6473
+ }
6474
+ return pagination(userList, pageLimit, {
6475
+ paginate: true,
6476
+ property,
6477
+ getKey
6478
+ });
6479
+ };
6480
+ async function getUserCount() {
6481
+ const response = await queryGlobalViewRaw("by_email2" /* USER_BY_EMAIL */, {
6482
+ limit: 0,
6483
+ // to be as fast as possible - we just want the total rows count
6484
+ include_docs: false
6485
+ });
6486
+ return response.total_rows;
6487
+ }
6488
+ function removePortalUserPermissions(user) {
6489
+ delete user.admin;
6490
+ delete user.builder;
6491
+ return user;
6492
+ }
6493
+ function cleanseUserObject(user, base) {
6494
+ delete user.admin;
6495
+ delete user.builder;
6496
+ delete user.roles;
6497
+ if (base) {
6498
+ user.admin = base.admin;
6499
+ user.builder = base.builder;
6500
+ user.roles = base.roles;
6501
+ }
6502
+ return user;
6503
+ }
6288
6504
 
6289
6505
  // src/users/utils.ts
6290
6506
  init_environment2();
@@ -6571,17 +6787,14 @@ __export(users_exports2, {
6571
6787
  getGlobalUserID: () => getGlobalUserID,
6572
6788
  hasAdminPermissions: () => hasAdminPermissions,
6573
6789
  hasAppBuilderPermissions: () => hasAppBuilderPermissions,
6574
- hasAppCreatorPermissions: () => hasAppCreatorPermissions,
6575
6790
  hasBuilderPermissions: () => hasBuilderPermissions,
6576
6791
  isAdmin: () => isAdmin,
6577
6792
  isAdminOrBuilder: () => isAdminOrBuilder,
6578
6793
  isAdminOrGlobalBuilder: () => isAdminOrGlobalBuilder,
6579
6794
  isBuilder: () => isBuilder,
6580
- isCreator: () => isCreator,
6581
6795
  isGlobalBuilder: () => isGlobalBuilder
6582
6796
  });
6583
6797
  init_src();
6584
- var _ = __toESM(require("lodash/fp"));
6585
6798
  function isBuilder(user, appId) {
6586
6799
  if (!user) {
6587
6800
  return false;
@@ -6616,17 +6829,6 @@ function hasAppBuilderPermissions(user) {
6616
6829
  const isGlobalBuilder3 = !!user.builder?.global;
6617
6830
  return !isGlobalBuilder3 && appLength != null && appLength > 0;
6618
6831
  }
6619
- function hasAppCreatorPermissions(user) {
6620
- if (!user) {
6621
- return false;
6622
- }
6623
- return _.flow(
6624
- _.get("roles"),
6625
- _.values,
6626
- _.find((x) => ["CREATOR", "ADMIN"].includes(x)),
6627
- (x) => !!x
6628
- )(user);
6629
- }
6630
6832
  function hasBuilderPermissions(user) {
6631
6833
  if (!user) {
6632
6834
  return false;
@@ -6639,12 +6841,6 @@ function hasAdminPermissions(user) {
6639
6841
  }
6640
6842
  return !!user.admin?.global;
6641
6843
  }
6642
- function isCreator(user) {
6643
- if (!user) {
6644
- return false;
6645
- }
6646
- return isGlobalBuilder(user) || hasAdminPermissions(user) || hasAppBuilderPermissions(user) || hasAppCreatorPermissions(user);
6647
- }
6648
6844
  function getGlobalUserID(userId) {
6649
6845
  if (typeof userId !== "string") {
6650
6846
  return userId;
@@ -6704,7 +6900,6 @@ var allowSortColumnByType = {
6704
6900
  // src/users/utils.ts
6705
6901
  var isBuilder2 = sdk_exports.users.isBuilder;
6706
6902
  var isAdmin2 = sdk_exports.users.isAdmin;
6707
- var isCreator2 = sdk_exports.users.isCreator;
6708
6903
  var isGlobalBuilder2 = sdk_exports.users.isGlobalBuilder;
6709
6904
  var isAdminOrBuilder2 = sdk_exports.users.isAdminOrBuilder;
6710
6905
  var hasAdminPermissions2 = sdk_exports.users.hasAdminPermissions;
@@ -6738,238 +6933,6 @@ async function getAccountHolderFromUserIds(userIds) {
6738
6933
  }
6739
6934
  }
6740
6935
 
6741
- // src/users/users.ts
6742
- function removeUserPassword(users) {
6743
- if (Array.isArray(users)) {
6744
- return users.map((user) => {
6745
- if (user) {
6746
- delete user.password;
6747
- return user;
6748
- }
6749
- });
6750
- } else if (users) {
6751
- delete users.password;
6752
- return users;
6753
- }
6754
- return users;
6755
- }
6756
- var isSupportedUserSearch = (query) => {
6757
- const allowed = [
6758
- { op: "string" /* STRING */, key: "email" },
6759
- { op: "equal" /* EQUAL */, key: "_id" }
6760
- ];
6761
- for (let [key, operation] of Object.entries(query)) {
6762
- if (typeof operation !== "object") {
6763
- return false;
6764
- }
6765
- const fields = Object.keys(operation || {});
6766
- if (fields.length === 0) {
6767
- continue;
6768
- }
6769
- const allowedOperation = allowed.find(
6770
- (allow) => allow.op === key && fields.length === 1 && fields[0] === allow.key
6771
- );
6772
- if (!allowedOperation) {
6773
- return false;
6774
- }
6775
- }
6776
- return true;
6777
- };
6778
- var bulkGetGlobalUsersById = async (userIds, opts) => {
6779
- const db = getGlobalDB();
6780
- let users = (await db.allDocs({
6781
- keys: userIds,
6782
- include_docs: true
6783
- })).rows.map((row) => row.doc);
6784
- if (opts?.cleanup) {
6785
- users = removeUserPassword(users);
6786
- }
6787
- return users;
6788
- };
6789
- var getAllUserIds = async () => {
6790
- const db = getGlobalDB();
6791
- const startKey = `${"us" /* USER */}${SEPARATOR}`;
6792
- const response = await db.allDocs({
6793
- startkey: startKey,
6794
- endkey: `${startKey}${UNICODE_MAX}`
6795
- });
6796
- return response.rows.map((row) => row.id);
6797
- };
6798
- var bulkUpdateGlobalUsers = async (users) => {
6799
- const db = getGlobalDB();
6800
- return await db.bulkDocs(users);
6801
- };
6802
- async function getById(id, opts) {
6803
- const db = getGlobalDB();
6804
- let user = await db.get(id);
6805
- if (opts?.cleanup) {
6806
- user = removeUserPassword(user);
6807
- }
6808
- return user;
6809
- }
6810
- var getGlobalUserByEmail = async (email, opts) => {
6811
- if (email == null) {
6812
- throw "Must supply an email address to view";
6813
- }
6814
- const response = await queryGlobalView("by_email2" /* USER_BY_EMAIL */, {
6815
- key: email.toLowerCase(),
6816
- include_docs: true
6817
- });
6818
- if (Array.isArray(response)) {
6819
- throw new Error(`Multiple users found with email address: ${email}`);
6820
- }
6821
- let user = response;
6822
- if (opts?.cleanup) {
6823
- user = removeUserPassword(user);
6824
- }
6825
- return user;
6826
- };
6827
- var searchGlobalUsersByApp = async (appId, opts, getOpts) => {
6828
- if (typeof appId !== "string") {
6829
- throw new Error("Must provide a string based app ID");
6830
- }
6831
- const params2 = getUsersByAppParams(appId, {
6832
- include_docs: true
6833
- });
6834
- params2.startkey = opts && opts.startkey ? opts.startkey : params2.startkey;
6835
- let response = await queryGlobalView("by_app" /* USER_BY_APP */, params2);
6836
- if (!response) {
6837
- response = [];
6838
- }
6839
- let users = Array.isArray(response) ? response : [response];
6840
- if (getOpts?.cleanup) {
6841
- users = removeUserPassword(users);
6842
- }
6843
- return users;
6844
- };
6845
- var searchGlobalUsersByAppAccess = async (appId, opts) => {
6846
- const roleSelector = `roles.${appId}`;
6847
- let orQuery = [
6848
- {
6849
- "builder.global": true
6850
- },
6851
- {
6852
- "admin.global": true
6853
- }
6854
- ];
6855
- if (appId) {
6856
- const roleCheck = {
6857
- [roleSelector]: {
6858
- $exists: true
6859
- }
6860
- };
6861
- orQuery.push(roleCheck);
6862
- }
6863
- let searchOptions = {
6864
- selector: {
6865
- $or: orQuery,
6866
- _id: {
6867
- $regex: "^us_"
6868
- }
6869
- },
6870
- limit: opts?.limit || 50
6871
- };
6872
- const resp = await directCouchFind(getGlobalDBName(), searchOptions);
6873
- return resp?.rows;
6874
- };
6875
- var getGlobalUserByAppPage = (appId, user) => {
6876
- if (!user) {
6877
- return;
6878
- }
6879
- return generateAppUserID(getProdAppID(appId), user._id);
6880
- };
6881
- var searchGlobalUsersByEmail = async (email, opts, getOpts) => {
6882
- if (typeof email !== "string") {
6883
- throw new Error("Must provide a string to search by");
6884
- }
6885
- const lcEmail = email.toLowerCase();
6886
- const startkey = opts && opts.startkey ? opts.startkey : lcEmail;
6887
- let response = await queryGlobalView("by_email2" /* USER_BY_EMAIL */, {
6888
- ...opts,
6889
- startkey,
6890
- endkey: `${lcEmail}${UNICODE_MAX}`
6891
- });
6892
- if (!response) {
6893
- response = [];
6894
- }
6895
- let users = Array.isArray(response) ? response : [response];
6896
- if (getOpts?.cleanup) {
6897
- users = removeUserPassword(users);
6898
- }
6899
- return users;
6900
- };
6901
- var PAGE_LIMIT = 8;
6902
- var paginatedUsers = async ({
6903
- bookmark,
6904
- query,
6905
- appId,
6906
- limit
6907
- } = {}) => {
6908
- const db = getGlobalDB();
6909
- const pageLimit = limit ? limit + 1 : PAGE_LIMIT + 1;
6910
- const opts = {
6911
- include_docs: true,
6912
- limit: pageLimit
6913
- };
6914
- if (bookmark) {
6915
- opts.startkey = bookmark;
6916
- }
6917
- let userList, property = "_id", getKey;
6918
- if (query?.equal?._id) {
6919
- userList = [await getById(query.equal._id)];
6920
- } else if (appId) {
6921
- userList = await searchGlobalUsersByApp(appId, opts);
6922
- getKey = (doc) => getGlobalUserByAppPage(appId, doc);
6923
- } else if (query?.string?.email) {
6924
- userList = await searchGlobalUsersByEmail(query?.string?.email, opts);
6925
- property = "email";
6926
- } else {
6927
- const response = await db.allDocs(getGlobalUserParams(null, opts));
6928
- userList = response.rows.map((row) => row.doc);
6929
- }
6930
- return pagination(userList, pageLimit, {
6931
- paginate: true,
6932
- property,
6933
- getKey
6934
- });
6935
- };
6936
- async function getUserCount() {
6937
- const response = await queryGlobalViewRaw("by_email2" /* USER_BY_EMAIL */, {
6938
- limit: 0,
6939
- // to be as fast as possible - we just want the total rows count
6940
- include_docs: false
6941
- });
6942
- return response.total_rows;
6943
- }
6944
- async function getCreatorCount() {
6945
- let creators = 0;
6946
- async function iterate(startPage) {
6947
- const page = await paginatedUsers({ bookmark: startPage });
6948
- creators += page.data.filter(isCreator2).length;
6949
- if (page.hasNextPage) {
6950
- await iterate(page.nextPage);
6951
- }
6952
- }
6953
- await iterate();
6954
- return creators;
6955
- }
6956
- function removePortalUserPermissions(user) {
6957
- delete user.admin;
6958
- delete user.builder;
6959
- return user;
6960
- }
6961
- function cleanseUserObject(user, base) {
6962
- delete user.admin;
6963
- delete user.builder;
6964
- delete user.roles;
6965
- if (base) {
6966
- user.admin = base.admin;
6967
- user.builder = base.builder;
6968
- user.roles = base.roles;
6969
- }
6970
- return user;
6971
- }
6972
-
6973
6936
  // src/users/db.ts
6974
6937
  init_environment2();
6975
6938
 
@@ -9955,8 +9918,7 @@ var UserDB = class _UserDB {
9955
9918
  }
9956
9919
  }
9957
9920
  const change = dbUser ? 0 : 1;
9958
- const creatorsChange = isCreator2(dbUser) !== isCreator2(user) ? 1 : 0;
9959
- return _UserDB.quotas.addUsers(change, creatorsChange, async () => {
9921
+ return _UserDB.quotas.addUsers(change, async () => {
9960
9922
  await validateUniqueUser(email, tenantId);
9961
9923
  let builtUser = await _UserDB.buildUser(user, opts, tenantId, dbUser);
9962
9924
  if (opts.currentUserId && opts.currentUserId === dbUser?._id) {
@@ -10000,7 +9962,6 @@ var UserDB = class _UserDB {
10000
9962
  const tenantId = getTenantId();
10001
9963
  let usersToSave = [];
10002
9964
  let newUsers = [];
10003
- let newCreators = [];
10004
9965
  const emails = newUsersRequested.map((user) => user.email);
10005
9966
  const existingEmails = await searchExistingEmails(emails);
10006
9967
  const unsuccessful = [];
@@ -10016,56 +9977,49 @@ var UserDB = class _UserDB {
10016
9977
  }
10017
9978
  newUser.userGroups = groups;
10018
9979
  newUsers.push(newUser);
10019
- if (isCreator2(newUser)) {
10020
- newCreators.push(newUser);
10021
- }
10022
9980
  }
10023
9981
  const account = await getAccountByTenantId(tenantId);
10024
- return _UserDB.quotas.addUsers(
10025
- newUsers.length,
10026
- newCreators.length,
10027
- async () => {
10028
- newUsers.forEach((user) => {
10029
- usersToSave.push(
10030
- _UserDB.buildUser(
10031
- user,
10032
- {
10033
- hashPassword: true,
10034
- requirePassword: user.requirePassword
10035
- },
10036
- tenantId,
10037
- void 0,
10038
- // no dbUser
10039
- account
10040
- )
10041
- );
10042
- });
10043
- const usersToBulkSave = await Promise.all(usersToSave);
10044
- await bulkUpdateGlobalUsers(usersToBulkSave);
10045
- for (const user of usersToBulkSave) {
10046
- await users_exports.addUser(tenantId, user._id, user.email);
10047
- await handleSaveEvents(user, void 0);
10048
- }
10049
- const saved = usersToBulkSave.map((user) => {
10050
- return {
10051
- _id: user._id,
10052
- email: user.email
10053
- };
10054
- });
10055
- if (Array.isArray(saved) && groups) {
10056
- const groupPromises = [];
10057
- const createdUserIds = saved.map((user) => user._id);
10058
- for (let groupId of groups) {
10059
- groupPromises.push(_UserDB.groups.addUsers(groupId, createdUserIds));
10060
- }
10061
- await Promise.all(groupPromises);
10062
- }
9982
+ return _UserDB.quotas.addUsers(newUsers.length, async () => {
9983
+ newUsers.forEach((user) => {
9984
+ usersToSave.push(
9985
+ _UserDB.buildUser(
9986
+ user,
9987
+ {
9988
+ hashPassword: true,
9989
+ requirePassword: user.requirePassword
9990
+ },
9991
+ tenantId,
9992
+ void 0,
9993
+ // no dbUser
9994
+ account
9995
+ )
9996
+ );
9997
+ });
9998
+ const usersToBulkSave = await Promise.all(usersToSave);
9999
+ await bulkUpdateGlobalUsers(usersToBulkSave);
10000
+ for (const user of usersToBulkSave) {
10001
+ await users_exports.addUser(tenantId, user._id, user.email);
10002
+ await handleSaveEvents(user, void 0);
10003
+ }
10004
+ const saved = usersToBulkSave.map((user) => {
10063
10005
  return {
10064
- successful: saved,
10065
- unsuccessful
10006
+ _id: user._id,
10007
+ email: user.email
10066
10008
  };
10009
+ });
10010
+ if (Array.isArray(saved) && groups) {
10011
+ const groupPromises = [];
10012
+ const createdUserIds = saved.map((user) => user._id);
10013
+ for (let groupId of groups) {
10014
+ groupPromises.push(_UserDB.groups.addUsers(groupId, createdUserIds));
10015
+ }
10016
+ await Promise.all(groupPromises);
10067
10017
  }
10068
- );
10018
+ return {
10019
+ successful: saved,
10020
+ unsuccessful
10021
+ };
10022
+ });
10069
10023
  }
10070
10024
  static async bulkDelete(userIds) {
10071
10025
  const db = getGlobalDB();
@@ -10096,11 +10050,10 @@ var UserDB = class _UserDB {
10096
10050
  _deleted: true
10097
10051
  }));
10098
10052
  const dbResponse = await bulkUpdateGlobalUsers(toDelete);
10099
- const creatorsToDelete = usersToDelete.filter(isCreator2);
10053
+ await _UserDB.quotas.removeUsers(toDelete.length);
10100
10054
  for (let user of usersToDelete) {
10101
10055
  await bulkDeleteProcessing(user);
10102
10056
  }
10103
- await _UserDB.quotas.removeUsers(toDelete.length, creatorsToDelete.length);
10104
10057
  const userIndex = {};
10105
10058
  usersToDelete.reduce((prev, current) => {
10106
10059
  prev[current._id] = current;
@@ -10137,8 +10090,7 @@ var UserDB = class _UserDB {
10137
10090
  }
10138
10091
  await users_exports.removeUser(dbUser);
10139
10092
  await db.remove(userId, dbUser._rev);
10140
- const creatorsToDelete = isCreator2(dbUser) ? 1 : 0;
10141
- await _UserDB.quotas.removeUsers(1, creatorsToDelete);
10093
+ await _UserDB.quotas.removeUsers(1);
10142
10094
  await handleDeleteEvents(dbUser);
10143
10095
  await user_exports.invalidateUser(userId);
10144
10096
  await invalidateSessions(userId, { reason: "deletion" });
@@ -10315,7 +10267,7 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
10315
10267
  }
10316
10268
  return { ok: true, id: output._id, rev: output._rev };
10317
10269
  }
10318
- async function get3(db, id) {
10270
+ async function get2(db, id) {
10319
10271
  const cache = await getCache();
10320
10272
  const cacheKey = makeCacheKey(db, id);
10321
10273
  let cacheItem = await cache.get(cacheKey);
@@ -10344,11 +10296,11 @@ var Writethrough = class {
10344
10296
  this.db = db;
10345
10297
  this.writeRateMs = writeRateMs;
10346
10298
  }
10347
- async put(doc, writeRateMs = this.writeRateMs) {
10348
- return put(this.db, doc, writeRateMs);
10299
+ async put(doc) {
10300
+ return put(this.db, doc, this.writeRateMs);
10349
10301
  }
10350
10302
  async get(id) {
10351
- return get3(this.db, id);
10303
+ return get2(this.db, id);
10352
10304
  }
10353
10305
  async remove(docOrId, rev) {
10354
10306
  return remove(this.db, docOrId, rev);