@budibase/backend-core 2.11.42 → 2.11.43
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 +264 -227
- package/dist/index.js.map +3 -3
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +4 -4
- package/dist/plugins.js.map +1 -1
- package/dist/plugins.js.meta.json +1 -1
- package/dist/src/environment.js +2 -2
- package/dist/src/environment.js.map +1 -1
- package/dist/src/users/users.d.ts +1 -0
- package/dist/src/users/users.js +20 -2
- package/dist/src/users/users.js.map +1 -1
- package/dist/src/users/utils.d.ts +1 -0
- package/dist/src/users/utils.js +2 -1
- package/dist/src/users/utils.js.map +1 -1
- package/dist/tests/core/utilities/structures/licenses.js +5 -0
- package/dist/tests/core/utilities/structures/licenses.js.map +1 -1
- package/dist/tests/core/utilities/structures/quotas.d.ts +1 -1
- package/dist/tests/core/utilities/structures/quotas.js +3 -2
- package/dist/tests/core/utilities/structures/quotas.js.map +1 -1
- package/package.json +4 -4
- package/src/environment.ts +2 -2
- package/src/users/users.ts +15 -1
- package/src/users/utils.ts +1 -0
- package/tests/core/utilities/structures/licenses.ts +5 -0
- package/tests/core/utilities/structures/quotas.ts +3 -2
package/dist/index.js
CHANGED
|
@@ -1753,11 +1753,11 @@ function getPackageJsonFields() {
|
|
|
1753
1753
|
const content = (0, import_fs.readFileSync)(packageJsonFile, "utf-8");
|
|
1754
1754
|
const parsedContent = JSON.parse(content);
|
|
1755
1755
|
return {
|
|
1756
|
-
VERSION: parsedContent.version,
|
|
1756
|
+
VERSION: process.env.BUDIBASE_VERSION || parsedContent.version,
|
|
1757
1757
|
SERVICE_NAME: parsedContent.name
|
|
1758
1758
|
};
|
|
1759
1759
|
} catch {
|
|
1760
|
-
return { VERSION: "", SERVICE_NAME: "" };
|
|
1760
|
+
return { VERSION: process.env.BUDIBASE_VERSION || "", SERVICE_NAME: "" };
|
|
1761
1761
|
}
|
|
1762
1762
|
}
|
|
1763
1763
|
function isWorker() {
|
|
@@ -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
|
|
2145
|
-
import_pouchdb.default.plugin(
|
|
2144
|
+
const find2 = require("pouchdb-find");
|
|
2145
|
+
import_pouchdb.default.plugin(find2);
|
|
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(
|
|
2585
|
-
if (!
|
|
2584
|
+
function doInEnvironmentContext(values2, task) {
|
|
2585
|
+
if (!values2) {
|
|
2586
2586
|
throw new Error("Must supply environment variables.");
|
|
2587
2587
|
}
|
|
2588
2588
|
const updates = {
|
|
2589
|
-
environmentVariables:
|
|
2589
|
+
environmentVariables: values2
|
|
2590
2590
|
};
|
|
2591
2591
|
return newContext(updates, task);
|
|
2592
2592
|
}
|
|
@@ -6254,6 +6254,7 @@ __export(users_exports3, {
|
|
|
6254
6254
|
getAccountHolderFromUserIds: () => getAccountHolderFromUserIds,
|
|
6255
6255
|
getAllUserIds: () => getAllUserIds,
|
|
6256
6256
|
getById: () => getById,
|
|
6257
|
+
getCreatorCount: () => getCreatorCount,
|
|
6257
6258
|
getExistingAccounts: () => getExistingAccounts,
|
|
6258
6259
|
getExistingPlatformUsers: () => getExistingPlatformUsers,
|
|
6259
6260
|
getExistingTenantUsers: () => getExistingTenantUsers,
|
|
@@ -6267,6 +6268,7 @@ __export(users_exports3, {
|
|
|
6267
6268
|
isAdmin: () => isAdmin2,
|
|
6268
6269
|
isAdminOrBuilder: () => isAdminOrBuilder2,
|
|
6269
6270
|
isBuilder: () => isBuilder2,
|
|
6271
|
+
isCreator: () => isCreator2,
|
|
6270
6272
|
isGlobalBuilder: () => isGlobalBuilder2,
|
|
6271
6273
|
isSupportedUserSearch: () => isSupportedUserSearch,
|
|
6272
6274
|
paginatedUsers: () => paginatedUsers,
|
|
@@ -6283,224 +6285,6 @@ init_db4();
|
|
|
6283
6285
|
init_src();
|
|
6284
6286
|
init_context2();
|
|
6285
6287
|
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
|
-
}
|
|
6504
6288
|
|
|
6505
6289
|
// src/users/utils.ts
|
|
6506
6290
|
init_environment2();
|
|
@@ -6787,14 +6571,17 @@ __export(users_exports2, {
|
|
|
6787
6571
|
getGlobalUserID: () => getGlobalUserID,
|
|
6788
6572
|
hasAdminPermissions: () => hasAdminPermissions,
|
|
6789
6573
|
hasAppBuilderPermissions: () => hasAppBuilderPermissions,
|
|
6574
|
+
hasAppCreatorPermissions: () => hasAppCreatorPermissions,
|
|
6790
6575
|
hasBuilderPermissions: () => hasBuilderPermissions,
|
|
6791
6576
|
isAdmin: () => isAdmin,
|
|
6792
6577
|
isAdminOrBuilder: () => isAdminOrBuilder,
|
|
6793
6578
|
isAdminOrGlobalBuilder: () => isAdminOrGlobalBuilder,
|
|
6794
6579
|
isBuilder: () => isBuilder,
|
|
6580
|
+
isCreator: () => isCreator,
|
|
6795
6581
|
isGlobalBuilder: () => isGlobalBuilder
|
|
6796
6582
|
});
|
|
6797
6583
|
init_src();
|
|
6584
|
+
var _ = __toESM(require("lodash/fp"));
|
|
6798
6585
|
function isBuilder(user, appId) {
|
|
6799
6586
|
if (!user) {
|
|
6800
6587
|
return false;
|
|
@@ -6829,6 +6616,17 @@ function hasAppBuilderPermissions(user) {
|
|
|
6829
6616
|
const isGlobalBuilder3 = !!user.builder?.global;
|
|
6830
6617
|
return !isGlobalBuilder3 && appLength != null && appLength > 0;
|
|
6831
6618
|
}
|
|
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
|
+
}
|
|
6832
6630
|
function hasBuilderPermissions(user) {
|
|
6833
6631
|
if (!user) {
|
|
6834
6632
|
return false;
|
|
@@ -6841,6 +6639,12 @@ function hasAdminPermissions(user) {
|
|
|
6841
6639
|
}
|
|
6842
6640
|
return !!user.admin?.global;
|
|
6843
6641
|
}
|
|
6642
|
+
function isCreator(user) {
|
|
6643
|
+
if (!user) {
|
|
6644
|
+
return false;
|
|
6645
|
+
}
|
|
6646
|
+
return isGlobalBuilder(user) || hasAdminPermissions(user) || hasAppBuilderPermissions(user) || hasAppCreatorPermissions(user);
|
|
6647
|
+
}
|
|
6844
6648
|
function getGlobalUserID(userId) {
|
|
6845
6649
|
if (typeof userId !== "string") {
|
|
6846
6650
|
return userId;
|
|
@@ -6900,6 +6704,7 @@ var allowSortColumnByType = {
|
|
|
6900
6704
|
// src/users/utils.ts
|
|
6901
6705
|
var isBuilder2 = sdk_exports.users.isBuilder;
|
|
6902
6706
|
var isAdmin2 = sdk_exports.users.isAdmin;
|
|
6707
|
+
var isCreator2 = sdk_exports.users.isCreator;
|
|
6903
6708
|
var isGlobalBuilder2 = sdk_exports.users.isGlobalBuilder;
|
|
6904
6709
|
var isAdminOrBuilder2 = sdk_exports.users.isAdminOrBuilder;
|
|
6905
6710
|
var hasAdminPermissions2 = sdk_exports.users.hasAdminPermissions;
|
|
@@ -6933,6 +6738,238 @@ async function getAccountHolderFromUserIds(userIds) {
|
|
|
6933
6738
|
}
|
|
6934
6739
|
}
|
|
6935
6740
|
|
|
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
|
+
|
|
6936
6973
|
// src/users/db.ts
|
|
6937
6974
|
init_environment2();
|
|
6938
6975
|
|
|
@@ -10267,7 +10304,7 @@ async function put(db, doc, writeRateMs = DEFAULT_WRITE_RATE_MS) {
|
|
|
10267
10304
|
}
|
|
10268
10305
|
return { ok: true, id: output._id, rev: output._rev };
|
|
10269
10306
|
}
|
|
10270
|
-
async function
|
|
10307
|
+
async function get3(db, id) {
|
|
10271
10308
|
const cache = await getCache();
|
|
10272
10309
|
const cacheKey = makeCacheKey(db, id);
|
|
10273
10310
|
let cacheItem = await cache.get(cacheKey);
|
|
@@ -10300,7 +10337,7 @@ var Writethrough = class {
|
|
|
10300
10337
|
return put(this.db, doc, this.writeRateMs);
|
|
10301
10338
|
}
|
|
10302
10339
|
async get(id) {
|
|
10303
|
-
return
|
|
10340
|
+
return get3(this.db, id);
|
|
10304
10341
|
}
|
|
10305
10342
|
async remove(docOrId, rev) {
|
|
10306
10343
|
return remove(this.db, docOrId, rev);
|