@budibase/backend-core 2.10.15 → 2.10.16-alpha.0
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 +38 -0
- package/dist/index.js.map +2 -2
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +6 -14
- package/dist/plugins.js.meta.json +1 -1
- package/dist/src/cache/appMetadata.js +1 -1
- package/dist/src/cache/appMetadata.js.map +1 -1
- package/dist/src/cache/generic.js +2 -2
- package/dist/src/cache/generic.js.map +1 -1
- package/dist/src/cache/user.d.ts +13 -0
- package/dist/src/cache/user.js +51 -1
- package/dist/src/cache/user.js.map +1 -1
- package/dist/src/constants/db.js +3 -3
- package/dist/src/constants/db.js.map +1 -1
- package/dist/src/constants/misc.js +5 -5
- package/dist/src/constants/misc.js.map +1 -1
- package/dist/src/context/Context.js +1 -1
- package/dist/src/context/Context.js.map +1 -1
- package/dist/src/context/types.d.ts +1 -1
- package/dist/src/db/lucene.d.ts +1 -1
- package/dist/src/db/lucene.js +6 -6
- package/dist/src/db/lucene.js.map +1 -1
- package/dist/src/errors/errors.js +1 -1
- package/dist/src/errors/errors.js.map +1 -1
- package/dist/src/events/processors/AuditLogsProcessor.js +1 -1
- package/dist/src/events/processors/AuditLogsProcessor.js.map +1 -1
- package/dist/src/events/processors/async/DocumentUpdateProcessor.d.ts +2 -2
- package/dist/src/features/index.js +1 -1
- package/dist/src/features/index.js.map +1 -1
- package/dist/src/middleware/passport/datasource/google.d.ts +1 -1
- package/dist/src/objectStore/objectStore.d.ts +1 -1
- package/dist/src/queue/constants.js +1 -1
- package/dist/src/queue/constants.js.map +1 -1
- package/dist/src/queue/listeners.d.ts +1 -1
- package/dist/src/redis/redis.d.ts +1 -1
- package/dist/src/redis/redis.js.map +1 -1
- package/dist/src/redis/redlockImpl.d.ts +3 -3
- package/dist/src/redis/utils.js +2 -2
- package/dist/src/redis/utils.js.map +1 -1
- package/dist/src/security/encryption.js +1 -1
- package/dist/src/security/encryption.js.map +1 -1
- package/dist/src/security/permissions.d.ts +2 -2
- package/dist/src/security/permissions.js +1 -1
- package/dist/src/security/permissions.js.map +1 -1
- package/dist/src/users/db.d.ts +8 -8
- package/dist/src/users/users.d.ts +1 -1
- package/dist/tests/core/logging.js +1 -1
- package/dist/tests/core/logging.js.map +1 -1
- package/dist/tests/core/utilities/mocks/licenses.d.ts +1 -1
- package/dist/tests/core/utilities/mocks/licenses.js +4 -4
- package/dist/tests/core/utilities/mocks/licenses.js.map +1 -1
- package/dist/tests/core/utilities/structures/sso.js +3 -4
- package/dist/tests/core/utilities/structures/sso.js.map +1 -1
- package/dist/tests/core/utilities/structures/users.d.ts +4 -3
- package/dist/tests/core/utilities/structures/users.js +18 -10
- package/dist/tests/core/utilities/structures/users.js.map +1 -1
- package/dist/tests/extra/DBTestConfiguration.d.ts +1 -1
- package/dist/tests/extra/DBTestConfiguration.js.map +1 -1
- package/dist/tests/index.d.ts +1 -0
- package/dist/tests/index.js +1 -0
- package/dist/tests/index.js.map +1 -1
- package/package.json +6 -14
- package/src/cache/tests/user.spec.ts +145 -0
- package/src/cache/user.ts +60 -0
- package/src/middleware/passport/sso/tests/sso.spec.ts +1 -0
- package/src/redis/redis.ts +2 -2
- package/src/utils/utils.ts +1 -1
- package/tests/core/utilities/mocks/licenses.ts +2 -2
- package/tests/core/utilities/structures/sso.ts +3 -4
- package/tests/core/utilities/structures/users.ts +24 -3
- package/tests/extra/DBTestConfiguration.ts +1 -1
- package/tests/index.ts +1 -0
- package/dist/tests/core/utilities/structures/shared.d.ts +0 -3
- package/dist/tests/core/utilities/structures/shared.js +0 -14
- package/dist/tests/core/utilities/structures/shared.js.map +0 -1
- package/tests/core/utilities/structures/shared.ts +0 -19
|
@@ -17,7 +17,7 @@ export declare const useEnforceableSSO: () => License;
|
|
|
17
17
|
export declare const useGroups: () => License;
|
|
18
18
|
export declare const useEnvironmentVariables: () => License;
|
|
19
19
|
export declare const useAuditLogs: () => License;
|
|
20
|
-
export declare const
|
|
20
|
+
export declare const useExpandedPublicApi: () => License;
|
|
21
21
|
export declare const useScimIntegration: () => License;
|
|
22
22
|
export declare const useSyncAutomations: () => License;
|
|
23
23
|
export declare const useAppBuilders: () => License;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.setAutomationLogsQuota = exports.useViewPermissions = exports.useAppBuilders = exports.useSyncAutomations = exports.useScimIntegration = exports.
|
|
6
|
+
exports.setAutomationLogsQuota = exports.useViewPermissions = exports.useAppBuilders = exports.useSyncAutomations = exports.useScimIntegration = exports.useExpandedPublicApi = exports.useAuditLogs = exports.useEnvironmentVariables = exports.useGroups = exports.useEnforceableSSO = exports.useBackups = exports.useCloudFree = exports.useUnlimited = exports.useLicense = exports.initInternal = exports.init = void 0;
|
|
7
7
|
const types_1 = require("@budibase/types");
|
|
8
8
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
9
9
|
let CLOUD_FREE_LICENSE;
|
|
@@ -75,10 +75,10 @@ const useAuditLogs = () => {
|
|
|
75
75
|
return useFeature(types_1.Feature.AUDIT_LOGS);
|
|
76
76
|
};
|
|
77
77
|
exports.useAuditLogs = useAuditLogs;
|
|
78
|
-
const
|
|
79
|
-
return useFeature(types_1.Feature.
|
|
78
|
+
const useExpandedPublicApi = () => {
|
|
79
|
+
return useFeature(types_1.Feature.EXPANDED_PUBLIC_API);
|
|
80
80
|
};
|
|
81
|
-
exports.
|
|
81
|
+
exports.useExpandedPublicApi = useExpandedPublicApi;
|
|
82
82
|
const useScimIntegration = () => {
|
|
83
83
|
return useFeature(types_1.Feature.SCIM);
|
|
84
84
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"licenses.js","sourceRoot":"","sources":["../../../../../tests/core/utilities/mocks/licen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BAEhC;AAEM,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,OAAO,UAAU,CAAC,eAAO,CAAC,IAAI,CAAC,CAAA;AACjC,CAAC,CAAA;AAFY,QAAA,kBAAkB,sBAE9B;AAEM,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,OAAO,UAAU,CAAC,eAAO,CAAC,gBAAgB,CAAC,CAAA;AAC7C,CAAC,CAAA;AAFY,QAAA,kBAAkB,sBAE9B;AAEM,MAAM,cAAc,GAAG,GAAG,EAAE;IACjC,OAAO,UAAU,CAAC,eAAO,CAAC,YAAY,CAAC,CAAA;AACzC,CAAC,CAAA;AAFY,QAAA,cAAc,kBAE1B;AAEM,MAAM,kBAAkB,GAAG,GAAG,EAAE;IACrC,OAAO,UAAU,CAAC,eAAO,CAAC,gBAAgB,CAAC,CAAA;AAC7C,CAAC,CAAA;AAFY,QAAA,kBAAkB,sBAE9B;AAED,SAAS;AAEF,MAAM,sBAAsB,GAAG,CAAC,KAAa,EAAE,EAAE;IACtD,MAAM,OAAO,GAAG,IAAA,mBAAS,EAAC,iBAAiB,CAAC,CAAA;IAC5C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,0BAA0B,CAAC,KAAK,GAAG,KAAK,CAAA;IAChE,OAAO,IAAA,kBAAU,EAAC,OAAO,CAAC,CAAA;AAC5B,CAAC,CAAA;AAJY,QAAA,sBAAsB,0BAIlC"}
|
|
@@ -30,8 +30,7 @@ exports.googleConfigDoc = exports.googleConfig = exports.jwtClaims = exports.oid
|
|
|
30
30
|
const types_1 = require("@budibase/types");
|
|
31
31
|
const generator_1 = require("./generator");
|
|
32
32
|
const common_1 = require("./common");
|
|
33
|
-
const
|
|
34
|
-
const shared_1 = require("./shared");
|
|
33
|
+
const users = __importStar(require("./users"));
|
|
35
34
|
const sample_1 = __importDefault(require("lodash/sample"));
|
|
36
35
|
function OAuth() {
|
|
37
36
|
return {
|
|
@@ -42,7 +41,7 @@ function OAuth() {
|
|
|
42
41
|
exports.OAuth = OAuth;
|
|
43
42
|
function authDetails(userDoc) {
|
|
44
43
|
if (!userDoc) {
|
|
45
|
-
userDoc =
|
|
44
|
+
userDoc = users.user();
|
|
46
45
|
}
|
|
47
46
|
const userId = userDoc._id || (0, common_1.uuid)();
|
|
48
47
|
const provider = generator_1.generator.string();
|
|
@@ -65,7 +64,7 @@ function providerType() {
|
|
|
65
64
|
exports.providerType = providerType;
|
|
66
65
|
function ssoProfile(user) {
|
|
67
66
|
if (!user) {
|
|
68
|
-
user =
|
|
67
|
+
user = users.user();
|
|
69
68
|
}
|
|
70
69
|
return {
|
|
71
70
|
id: user._id,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sso.js","sourceRoot":"","sources":["../../../../../tests/core/utilities/structures/sso.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAYwB;AACxB,2CAAuC;AACvC,qCAAsC;AACtC
|
|
1
|
+
{"version":3,"file":"sso.js","sourceRoot":"","sources":["../../../../../tests/core/utilities/structures/sso.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAYwB;AACxB,2CAAuC;AACvC,qCAAsC;AACtC,+CAAgC;AAChC,2DAAkC;AAElC,SAAgB,KAAK;IACnB,OAAO;QACL,YAAY,EAAE,qBAAS,CAAC,MAAM,EAAE;QAChC,WAAW,EAAE,qBAAS,CAAC,MAAM,EAAE;KAChC,CAAA;AACH,CAAC;AALD,sBAKC;AAED,SAAgB,WAAW,CAAC,OAAc;IACxC,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAA;KACvB;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,IAAI,IAAA,aAAI,GAAE,CAAA;IACpC,MAAM,QAAQ,GAAG,qBAAS,CAAC,MAAM,EAAE,CAAA;IAEnC,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAA;IACn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MAAM,EAAE;QAC1B,sBAAsB,EAAE,qBAAS,CAAC,GAAG,EAAE;QACvC,cAAc,EAAE,qBAAS,CAAC,GAAG,EAAE;QAC/B,iBAAiB,EAAE,qBAAS,CAAC,GAAG,EAAE;KACnC,CAAA;AACH,CAAC;AAPD,kDAOC;AAED,SAAgB,SAAS;IACvB,OAAO;QACL,KAAK,EAAE,IAAA,cAAK,GAAE;QACd,kBAAkB,EAAE,IAAA,cAAK,GAAE;KAC5B,CAAA;AACH,CAAC;AALD,8BAKC;AAED,SAAS;AAET,SAAgB,YAAY;IAC1B,OAAO;QACL,SAAS,EAAE,IAAI;QACf,QAAQ,EAAE,qBAAS,CAAC,MAAM,EAAE;QAC5B,YAAY,EAAE,qBAAS,CAAC,MAAM,EAAE;KACjC,CAAA;AACH,CAAC;AAND,oCAMC;AAED,SAAgB,eAAe;IAC7B,OAAO;QACL,GAAG,EAAE,eAAe;QACpB,IAAI,EAAE,kBAAU,CAAC,MAAM;QACvB,MAAM,EAAE,YAAY,EAAE;KACvB,CAAA;AACH,CAAC;AAND,0CAMC"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { AdminUser, AdminOnlyUser, BuilderUser, SSOAuthDetails, SSOUser } from "@budibase/types";
|
|
2
|
-
export
|
|
1
|
+
import { AdminUser, AdminOnlyUser, BuilderUser, SSOAuthDetails, SSOUser, User } from "@budibase/types";
|
|
2
|
+
export declare const newEmail: () => string;
|
|
3
|
+
export declare const user: (userProps?: Partial<Omit<User, "userId">>) => User;
|
|
3
4
|
export declare const adminUser: (userProps?: any) => AdminUser;
|
|
4
5
|
export declare const adminOnlyUser: (userProps?: any) => AdminOnlyUser;
|
|
5
|
-
export declare const builderUser: (userProps?:
|
|
6
|
+
export declare const builderUser: (userProps?: Partial<User>) => BuilderUser;
|
|
6
7
|
export declare const appBuilderUser: (appId: string, userProps?: any) => BuilderUser;
|
|
7
8
|
export declare function ssoUser(opts?: {
|
|
8
9
|
user?: any;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ssoUser = exports.appBuilderUser = exports.builderUser = exports.adminOnlyUser = exports.adminUser = exports.
|
|
4
|
-
const shared_1 = require("./shared");
|
|
3
|
+
exports.ssoUser = exports.appBuilderUser = exports.builderUser = exports.adminOnlyUser = exports.adminUser = exports.user = exports.newEmail = void 0;
|
|
5
4
|
const sso_1 = require("./sso");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const common_1 = require("./common");
|
|
6
|
+
const generator_1 = require("./generator");
|
|
7
|
+
const _1 = require(".");
|
|
8
|
+
const newEmail = () => {
|
|
9
|
+
return `${(0, common_1.uuid)()}@test.com`;
|
|
10
|
+
};
|
|
11
|
+
exports.newEmail = newEmail;
|
|
12
|
+
const user = (userProps) => {
|
|
13
|
+
const userId = userProps === null || userProps === void 0 ? void 0 : userProps._id;
|
|
14
|
+
return Object.assign({ _id: userId, userId, email: (0, exports.newEmail)(), password: "test", roles: { app_test: "admin" }, firstName: generator_1.generator.first(), lastName: generator_1.generator.last(), pictureUrl: "http://test.com", tenantId: _1.tenant.id() }, userProps);
|
|
15
|
+
};
|
|
16
|
+
exports.user = user;
|
|
9
17
|
const adminUser = (userProps) => {
|
|
10
|
-
return Object.assign(Object.assign({}, (0,
|
|
18
|
+
return Object.assign(Object.assign({}, (0, exports.user)(userProps)), { admin: {
|
|
11
19
|
global: true,
|
|
12
20
|
}, builder: {
|
|
13
21
|
global: true,
|
|
@@ -15,26 +23,26 @@ const adminUser = (userProps) => {
|
|
|
15
23
|
};
|
|
16
24
|
exports.adminUser = adminUser;
|
|
17
25
|
const adminOnlyUser = (userProps) => {
|
|
18
|
-
return Object.assign(Object.assign({}, (0,
|
|
26
|
+
return Object.assign(Object.assign({}, (0, exports.user)(userProps)), { admin: {
|
|
19
27
|
global: true,
|
|
20
28
|
} });
|
|
21
29
|
};
|
|
22
30
|
exports.adminOnlyUser = adminOnlyUser;
|
|
23
31
|
const builderUser = (userProps) => {
|
|
24
|
-
return Object.assign(Object.assign({}, (0,
|
|
32
|
+
return Object.assign(Object.assign({}, (0, exports.user)(userProps)), { builder: {
|
|
25
33
|
global: true,
|
|
26
34
|
} });
|
|
27
35
|
};
|
|
28
36
|
exports.builderUser = builderUser;
|
|
29
37
|
const appBuilderUser = (appId, userProps) => {
|
|
30
|
-
return Object.assign(Object.assign({}, (0,
|
|
38
|
+
return Object.assign(Object.assign({}, (0, exports.user)(userProps)), { builder: {
|
|
31
39
|
apps: [appId],
|
|
32
40
|
} });
|
|
33
41
|
};
|
|
34
42
|
exports.appBuilderUser = appBuilderUser;
|
|
35
43
|
function ssoUser(opts = {}) {
|
|
36
44
|
var _a, _b, _c;
|
|
37
|
-
const base = (0,
|
|
45
|
+
const base = (0, exports.user)(opts.user);
|
|
38
46
|
delete base.password;
|
|
39
47
|
if (!opts.details) {
|
|
40
48
|
opts.details = (0, sso_1.authDetails)(base);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../../../../tests/core/utilities/structures/users.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"users.js","sourceRoot":"","sources":["../../../../../tests/core/utilities/structures/users.ts"],"names":[],"mappings":";;;AAQA,+BAAmC;AACnC,qCAA+B;AAC/B,2CAAuC;AACvC,wBAA0B;AAEnB,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,OAAO,GAAG,IAAA,aAAI,GAAE,WAAW,CAAA;AAC7B,CAAC,CAAA;AAFY,QAAA,QAAQ,YAEpB;AAEM,MAAM,IAAI,GAAG,CAAC,SAAyC,EAAQ,EAAE;IACtE,MAAM,MAAM,GAAG,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,GAAG,CAAA;IAC7B,uBACE,GAAG,EAAE,MAAM,EACX,MAAM,EACN,KAAK,EAAE,IAAA,gBAAQ,GAAE,EACjB,QAAQ,EAA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AA;IAEpB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;QACjB,IAAI,CAAC,OAAO,GAAG,IAAA,iBAAW,EAAC,IAAI,CAAC,CAAA;KACjC;IAED,uCACK,IAAI,KACP,kBAAkB,EAAE,KAAK,EACzB,MAAM,EAAE,MAAA,IAAI,CAAC,OAAO,0CAAE,MAAM,EAC5B,QAAQ,EAAE,MAAA,IAAI,CAAC,OAAO,0CAAE,QAAS,EACjC,YAAY,EAAE,MAAA,IAAI,CAAC,OAAO,0CAAE,YAAa,EACzC,iBAAiB,EAAE;YACjB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,OAAO,EAAE,IAAI,CAAC,UAAU;SACzB,IACF;AACH,CAAC;AArBD,0BAqBC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DBTestConfiguration.js","sourceRoot":"","sources":["../../../tests/extra/DBTestConfiguration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAgC;AAChC,yEAA0D;AAC1D,mDAAoC;AACpC,2DAA4C;AAE5C,MAAM,mBAAmB;IAGvB;QACE,wDAAwD;QACxD,OAAO,CAAC,WAAW,EAAE,CAAA;QACrB,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;IACxC,CAAC;IAED,SAAS;QACP,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;IACxC,CAAC;IAED,UAAU;IAEV,UAAU,
|
|
1
|
+
{"version":3,"file":"DBTestConfiguration.js","sourceRoot":"","sources":["../../../tests/extra/DBTestConfiguration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAgC;AAChC,yEAA0D;AAC1D,mDAAoC;AACpC,2DAA4C;AAE5C,MAAM,mBAAmB;IAGvB;QACE,wDAAwD;QACxD,OAAO,CAAC,WAAW,EAAE,CAAA;QACrB,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;IACxC,CAAC;IAED,SAAS;QACP,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;IACxC,CAAC;IAED,UAAU;IAEV,UAAU,CAAI,IAAsB;QAClC,OAAO,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE;YAC5C,OAAO,IAAI,EAAE,CAAA;QACf,CAAC,CAAC,CAAA;IACJ,CAAC;IAED,WAAW;QACT,IAAI;YACF,OAAO,OAAO,CAAC,WAAW,EAAE,CAAA;SAC7B;QAAC,OAAO,CAAC,EAAE;YACV,OAAO,IAAI,CAAC,QAAS,CAAA;SACtB;IACH,CAAC;CACF;AAED,kBAAe,mBAAmB,CAAA"}
|
package/dist/tests/index.d.ts
CHANGED
package/dist/tests/index.js
CHANGED
|
@@ -15,4 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./core/utilities"), exports);
|
|
18
|
+
__exportStar(require("./extra"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/dist/tests/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tests/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tests/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,mDAAgC;AAChC,0CAAuB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/backend-core",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.16-alpha.0",
|
|
4
4
|
"description": "Budibase backend core libraries used in server and worker",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@budibase/nano": "10.1.2",
|
|
25
25
|
"@budibase/pouchdb-replication-stream": "1.2.10",
|
|
26
|
-
"@budibase/shared-core": "2.10.
|
|
27
|
-
"@budibase/types": "2.10.
|
|
26
|
+
"@budibase/shared-core": "2.10.16-alpha.0",
|
|
27
|
+
"@budibase/types": "2.10.16-alpha.0",
|
|
28
28
|
"@techpass/passport-openidconnect": "0.3.2",
|
|
29
29
|
"aws-cloudfront-sign": "2.2.0",
|
|
30
30
|
"aws-sdk": "2.1030.0",
|
|
@@ -33,17 +33,14 @@
|
|
|
33
33
|
"bull": "4.10.1",
|
|
34
34
|
"correlation-id": "4.0.0",
|
|
35
35
|
"dotenv": "16.0.1",
|
|
36
|
-
"emitter-listener": "1.1.2",
|
|
37
36
|
"ioredis": "5.3.2",
|
|
38
37
|
"joi": "17.6.0",
|
|
39
38
|
"jsonwebtoken": "9.0.0",
|
|
40
39
|
"koa-passport": "4.1.4",
|
|
41
40
|
"koa-pino-logger": "4.0.0",
|
|
42
41
|
"lodash": "4.17.21",
|
|
43
|
-
"lodash.isarguments": "3.1.0",
|
|
44
42
|
"node-fetch": "2.6.7",
|
|
45
43
|
"passport-google-oauth": "2.0.0",
|
|
46
|
-
"passport-jwt": "4.0.0",
|
|
47
44
|
"passport-local": "1.0.0",
|
|
48
45
|
"passport-oauth2-refresh": "^2.1.0",
|
|
49
46
|
"pino": "8.11.0",
|
|
@@ -59,14 +56,13 @@
|
|
|
59
56
|
"uuid": "8.3.2"
|
|
60
57
|
},
|
|
61
58
|
"devDependencies": {
|
|
62
|
-
"@jest/test-sequencer": "29.6.2",
|
|
63
59
|
"@shopify/jest-koa-mocks": "5.1.1",
|
|
64
60
|
"@swc/core": "1.3.71",
|
|
65
61
|
"@swc/jest": "0.2.27",
|
|
66
62
|
"@trendyol/jest-testcontainers": "^2.1.1",
|
|
67
63
|
"@types/chance": "1.1.3",
|
|
64
|
+
"@types/cookies": "0.7.8",
|
|
68
65
|
"@types/jest": "29.5.3",
|
|
69
|
-
"@types/koa": "2.13.4",
|
|
70
66
|
"@types/lodash": "4.14.180",
|
|
71
67
|
"@types/node": "18.17.0",
|
|
72
68
|
"@types/node-fetch": "2.6.4",
|
|
@@ -80,14 +76,10 @@
|
|
|
80
76
|
"jest": "29.6.2",
|
|
81
77
|
"jest-environment-node": "29.6.2",
|
|
82
78
|
"jest-serial-runner": "1.2.1",
|
|
83
|
-
"koa": "2.13.4",
|
|
84
|
-
"nodemon": "2.0.16",
|
|
85
79
|
"pino-pretty": "10.0.0",
|
|
86
80
|
"pouchdb-adapter-memory": "7.2.2",
|
|
87
81
|
"timekeeper": "2.2.0",
|
|
88
|
-
"
|
|
89
|
-
"tsconfig-paths": "4.0.0",
|
|
90
|
-
"typescript": "4.7.3"
|
|
82
|
+
"typescript": "5.2.2"
|
|
91
83
|
},
|
|
92
84
|
"nx": {
|
|
93
85
|
"targets": {
|
|
@@ -104,5 +96,5 @@
|
|
|
104
96
|
}
|
|
105
97
|
}
|
|
106
98
|
},
|
|
107
|
-
"gitHead": "
|
|
99
|
+
"gitHead": "f373448384d66541cf3dfaf59bd1df32efd3661b"
|
|
108
100
|
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { User } from "@budibase/types"
|
|
2
|
+
import { generator, structures } from "../../../tests"
|
|
3
|
+
import { DBTestConfiguration } from "../../../tests/extra"
|
|
4
|
+
import { getUsers } from "../user"
|
|
5
|
+
import { getGlobalDB } from "../../context"
|
|
6
|
+
import _ from "lodash"
|
|
7
|
+
|
|
8
|
+
import * as redis from "../../redis/init"
|
|
9
|
+
import { UserDB } from "../../users"
|
|
10
|
+
|
|
11
|
+
const config = new DBTestConfiguration()
|
|
12
|
+
|
|
13
|
+
describe("user cache", () => {
|
|
14
|
+
describe("getUsers", () => {
|
|
15
|
+
const users: User[] = []
|
|
16
|
+
beforeAll(async () => {
|
|
17
|
+
const userCount = 10
|
|
18
|
+
const userIds = generator.arrayOf(() => generator.guid(), {
|
|
19
|
+
min: userCount,
|
|
20
|
+
max: userCount,
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
await config.doInTenant(async () => {
|
|
24
|
+
const db = getGlobalDB()
|
|
25
|
+
for (const userId of userIds) {
|
|
26
|
+
const user = structures.users.user({ _id: userId })
|
|
27
|
+
await db.put(user)
|
|
28
|
+
users.push(user)
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
beforeEach(async () => {
|
|
34
|
+
jest.clearAllMocks()
|
|
35
|
+
|
|
36
|
+
const redisClient = await redis.getUserClient()
|
|
37
|
+
await redisClient.clear()
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it("when no user is in cache, all of them are retrieved from db", async () => {
|
|
41
|
+
const usersToRequest = _.sampleSize(users, 5)
|
|
42
|
+
|
|
43
|
+
const userIdsToRequest = usersToRequest.map(x => x._id!)
|
|
44
|
+
|
|
45
|
+
jest.spyOn(UserDB, "bulkGet")
|
|
46
|
+
|
|
47
|
+
const results = await config.doInTenant(() => getUsers(userIdsToRequest))
|
|
48
|
+
|
|
49
|
+
expect(results.users).toHaveLength(5)
|
|
50
|
+
expect(results).toEqual({
|
|
51
|
+
users: usersToRequest.map(u => ({
|
|
52
|
+
...u,
|
|
53
|
+
budibaseAccess: true,
|
|
54
|
+
_rev: expect.any(String),
|
|
55
|
+
})),
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
expect(UserDB.bulkGet).toBeCalledTimes(1)
|
|
59
|
+
expect(UserDB.bulkGet).toBeCalledWith(userIdsToRequest)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it("on a second all, all of them are retrieved from cache", async () => {
|
|
63
|
+
const usersToRequest = _.sampleSize(users, 5)
|
|
64
|
+
|
|
65
|
+
const userIdsToRequest = usersToRequest.map(x => x._id!)
|
|
66
|
+
|
|
67
|
+
jest.spyOn(UserDB, "bulkGet")
|
|
68
|
+
|
|
69
|
+
await config.doInTenant(() => getUsers(userIdsToRequest))
|
|
70
|
+
const resultsFromCache = await config.doInTenant(() =>
|
|
71
|
+
getUsers(userIdsToRequest)
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
expect(resultsFromCache.users).toHaveLength(5)
|
|
75
|
+
expect(resultsFromCache).toEqual({
|
|
76
|
+
users: expect.arrayContaining(
|
|
77
|
+
usersToRequest.map(u => ({
|
|
78
|
+
...u,
|
|
79
|
+
budibaseAccess: true,
|
|
80
|
+
_rev: expect.any(String),
|
|
81
|
+
}))
|
|
82
|
+
),
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
expect(UserDB.bulkGet).toBeCalledTimes(1)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it("when some users are cached, only the missing ones are retrieved from db", async () => {
|
|
89
|
+
const usersToRequest = _.sampleSize(users, 5)
|
|
90
|
+
|
|
91
|
+
const userIdsToRequest = usersToRequest.map(x => x._id!)
|
|
92
|
+
|
|
93
|
+
jest.spyOn(UserDB, "bulkGet")
|
|
94
|
+
|
|
95
|
+
await config.doInTenant(() =>
|
|
96
|
+
getUsers([userIdsToRequest[0], userIdsToRequest[3]])
|
|
97
|
+
)
|
|
98
|
+
;(UserDB.bulkGet as jest.Mock).mockClear()
|
|
99
|
+
|
|
100
|
+
const results = await config.doInTenant(() => getUsers(userIdsToRequest))
|
|
101
|
+
|
|
102
|
+
expect(results.users).toHaveLength(5)
|
|
103
|
+
expect(results).toEqual({
|
|
104
|
+
users: expect.arrayContaining(
|
|
105
|
+
usersToRequest.map(u => ({
|
|
106
|
+
...u,
|
|
107
|
+
budibaseAccess: true,
|
|
108
|
+
_rev: expect.any(String),
|
|
109
|
+
}))
|
|
110
|
+
),
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
expect(UserDB.bulkGet).toBeCalledTimes(1)
|
|
114
|
+
expect(UserDB.bulkGet).toBeCalledWith([
|
|
115
|
+
userIdsToRequest[1],
|
|
116
|
+
userIdsToRequest[2],
|
|
117
|
+
userIdsToRequest[4],
|
|
118
|
+
])
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it("requesting existing and unexisting ids will return found ones", async () => {
|
|
122
|
+
const usersToRequest = _.sampleSize(users, 3)
|
|
123
|
+
const missingIds = [generator.guid(), generator.guid()]
|
|
124
|
+
|
|
125
|
+
const userIdsToRequest = _.shuffle([
|
|
126
|
+
...missingIds,
|
|
127
|
+
...usersToRequest.map(x => x._id!),
|
|
128
|
+
])
|
|
129
|
+
|
|
130
|
+
const results = await config.doInTenant(() => getUsers(userIdsToRequest))
|
|
131
|
+
|
|
132
|
+
expect(results.users).toHaveLength(3)
|
|
133
|
+
expect(results).toEqual({
|
|
134
|
+
users: expect.arrayContaining(
|
|
135
|
+
usersToRequest.map(u => ({
|
|
136
|
+
...u,
|
|
137
|
+
budibaseAccess: true,
|
|
138
|
+
_rev: expect.any(String),
|
|
139
|
+
}))
|
|
140
|
+
),
|
|
141
|
+
notFoundIds: expect.arrayContaining(missingIds),
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
})
|
|
145
|
+
})
|
package/src/cache/user.ts
CHANGED
|
@@ -6,6 +6,7 @@ import env from "../environment"
|
|
|
6
6
|
import * as accounts from "../accounts"
|
|
7
7
|
import { UserDB } from "../users"
|
|
8
8
|
import { sdk } from "@budibase/shared-core"
|
|
9
|
+
import { User } from "@budibase/types"
|
|
9
10
|
|
|
10
11
|
const EXPIRY_SECONDS = 3600
|
|
11
12
|
|
|
@@ -27,6 +28,35 @@ async function populateFromDB(userId: string, tenantId: string) {
|
|
|
27
28
|
return user
|
|
28
29
|
}
|
|
29
30
|
|
|
31
|
+
async function populateUsersFromDB(
|
|
32
|
+
userIds: string[]
|
|
33
|
+
): Promise<{ users: User[]; notFoundIds?: string[] }> {
|
|
34
|
+
const getUsersResponse = await UserDB.bulkGet(userIds)
|
|
35
|
+
|
|
36
|
+
// Handle missed user ids
|
|
37
|
+
const notFoundIds = userIds.filter((uid, i) => !getUsersResponse[i])
|
|
38
|
+
|
|
39
|
+
const users = getUsersResponse.filter(x => x)
|
|
40
|
+
|
|
41
|
+
await Promise.all(
|
|
42
|
+
users.map(async (user: any) => {
|
|
43
|
+
user.budibaseAccess = true
|
|
44
|
+
if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) {
|
|
45
|
+
const account = await accounts.getAccount(user.email)
|
|
46
|
+
if (account) {
|
|
47
|
+
user.account = account
|
|
48
|
+
user.accountPortalAccess = true
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
if (notFoundIds.length) {
|
|
55
|
+
return { users, notFoundIds }
|
|
56
|
+
}
|
|
57
|
+
return { users }
|
|
58
|
+
}
|
|
59
|
+
|
|
30
60
|
/**
|
|
31
61
|
* Get the requested user by id.
|
|
32
62
|
* Use redis cache to first read the user.
|
|
@@ -77,6 +107,36 @@ export async function getUser(
|
|
|
77
107
|
return user
|
|
78
108
|
}
|
|
79
109
|
|
|
110
|
+
/**
|
|
111
|
+
* Get the requested users by id.
|
|
112
|
+
* Use redis cache to first read the users.
|
|
113
|
+
* If not present fallback to loading the users directly and re-caching.
|
|
114
|
+
* @param {*} userIds the ids of the user to get
|
|
115
|
+
* @param {*} tenantId the tenant of the users to get
|
|
116
|
+
* @returns
|
|
117
|
+
*/
|
|
118
|
+
export async function getUsers(
|
|
119
|
+
userIds: string[]
|
|
120
|
+
): Promise<{ users: User[]; notFoundIds?: string[] }> {
|
|
121
|
+
const client = await redis.getUserClient()
|
|
122
|
+
// try cache
|
|
123
|
+
let usersFromCache = await client.bulkGet<User>(userIds)
|
|
124
|
+
const missingUsersFromCache = userIds.filter(uid => !usersFromCache[uid])
|
|
125
|
+
const users = Object.values(usersFromCache)
|
|
126
|
+
let notFoundIds
|
|
127
|
+
|
|
128
|
+
if (missingUsersFromCache.length) {
|
|
129
|
+
const usersFromDb = await populateUsersFromDB(missingUsersFromCache)
|
|
130
|
+
|
|
131
|
+
notFoundIds = usersFromDb.notFoundIds
|
|
132
|
+
for (const userToCache of usersFromDb.users) {
|
|
133
|
+
await client.store(userToCache._id!, userToCache, EXPIRY_SECONDS)
|
|
134
|
+
}
|
|
135
|
+
users.push(...usersFromDb.users)
|
|
136
|
+
}
|
|
137
|
+
return { users, notFoundIds: notFoundIds }
|
|
138
|
+
}
|
|
139
|
+
|
|
80
140
|
export async function invalidateUser(userId: string) {
|
|
81
141
|
const client = await redis.getUserClient()
|
|
82
142
|
await client.delete(userId)
|
package/src/redis/redis.ts
CHANGED
|
@@ -242,7 +242,7 @@ class RedisWrapper {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
async bulkGet(keys: string[]) {
|
|
245
|
+
async bulkGet<T>(keys: string[]) {
|
|
246
246
|
const db = this._db
|
|
247
247
|
if (keys.length === 0) {
|
|
248
248
|
return {}
|
|
@@ -250,7 +250,7 @@ class RedisWrapper {
|
|
|
250
250
|
const prefixedKeys = keys.map(key => addDbPrefix(db, key))
|
|
251
251
|
let response = await this.getClient().mget(prefixedKeys)
|
|
252
252
|
if (Array.isArray(response)) {
|
|
253
|
-
let final:
|
|
253
|
+
let final: Record<string, T> = {}
|
|
254
254
|
let count = 0
|
|
255
255
|
for (let result of response) {
|
|
256
256
|
if (result) {
|
package/src/utils/utils.ts
CHANGED
|
@@ -86,8 +86,8 @@ export const useAuditLogs = () => {
|
|
|
86
86
|
return useFeature(Feature.AUDIT_LOGS)
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
export const
|
|
90
|
-
return useFeature(Feature.
|
|
89
|
+
export const useExpandedPublicApi = () => {
|
|
90
|
+
return useFeature(Feature.EXPANDED_PUBLIC_API)
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
export const useScimIntegration = () => {
|
|
@@ -13,8 +13,7 @@ import {
|
|
|
13
13
|
} from "@budibase/types"
|
|
14
14
|
import { generator } from "./generator"
|
|
15
15
|
import { email, uuid } from "./common"
|
|
16
|
-
import * as
|
|
17
|
-
import { user } from "./shared"
|
|
16
|
+
import * as users from "./users"
|
|
18
17
|
import sample from "lodash/sample"
|
|
19
18
|
|
|
20
19
|
export function OAuth(): OAuth2 {
|
|
@@ -26,7 +25,7 @@ export function OAuth(): OAuth2 {
|
|
|
26
25
|
|
|
27
26
|
export function authDetails(userDoc?: User): SSOAuthDetails {
|
|
28
27
|
if (!userDoc) {
|
|
29
|
-
userDoc = user()
|
|
28
|
+
userDoc = users.user()
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
const userId = userDoc._id || uuid()
|
|
@@ -52,7 +51,7 @@ export function providerType(): SSOProviderType {
|
|
|
52
51
|
|
|
53
52
|
export function ssoProfile(user?: User): SSOProfile {
|
|
54
53
|
if (!user) {
|
|
55
|
-
user =
|
|
54
|
+
user = users.user()
|
|
56
55
|
}
|
|
57
56
|
return {
|
|
58
57
|
id: user._id!,
|
|
@@ -4,11 +4,32 @@ import {
|
|
|
4
4
|
BuilderUser,
|
|
5
5
|
SSOAuthDetails,
|
|
6
6
|
SSOUser,
|
|
7
|
+
User,
|
|
7
8
|
} from "@budibase/types"
|
|
8
|
-
import { user } from "./shared"
|
|
9
9
|
import { authDetails } from "./sso"
|
|
10
|
+
import { uuid } from "./common"
|
|
11
|
+
import { generator } from "./generator"
|
|
12
|
+
import { tenant } from "."
|
|
10
13
|
|
|
11
|
-
export
|
|
14
|
+
export const newEmail = () => {
|
|
15
|
+
return `${uuid()}@test.com`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const user = (userProps?: Partial<Omit<User, "userId">>): User => {
|
|
19
|
+
const userId = userProps?._id
|
|
20
|
+
return {
|
|
21
|
+
_id: userId,
|
|
22
|
+
userId,
|
|
23
|
+
email: newEmail(),
|
|
24
|
+
password: "test",
|
|
25
|
+
roles: { app_test: "admin" },
|
|
26
|
+
firstName: generator.first(),
|
|
27
|
+
lastName: generator.last(),
|
|
28
|
+
pictureUrl: "http://test.com",
|
|
29
|
+
tenantId: tenant.id(),
|
|
30
|
+
...userProps,
|
|
31
|
+
}
|
|
32
|
+
}
|
|
12
33
|
|
|
13
34
|
export const adminUser = (userProps?: any): AdminUser => {
|
|
14
35
|
return {
|
|
@@ -31,7 +52,7 @@ export const adminOnlyUser = (userProps?: any): AdminOnlyUser => {
|
|
|
31
52
|
}
|
|
32
53
|
}
|
|
33
54
|
|
|
34
|
-
export const builderUser = (userProps?:
|
|
55
|
+
export const builderUser = (userProps?: Partial<User>): BuilderUser => {
|
|
35
56
|
return {
|
|
36
57
|
...user(userProps),
|
|
37
58
|
builder: {
|
package/tests/index.ts
CHANGED