@loomcore/api 0.2.51 → 0.2.53
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/LICENSE +201 -201
- package/dist/__tests__/common-test.utils.d.ts +2 -0
- package/dist/__tests__/common-test.utils.js +7 -1
- package/dist/__tests__/mongo-db.test-database.js +46 -12
- package/dist/__tests__/test-express-app.js +10 -6
- package/dist/controllers/api.controller.d.ts +1 -0
- package/dist/controllers/api.controller.js +12 -10
- package/dist/controllers/auth.controller.js +6 -2
- package/dist/controllers/features.controller.js +58 -6
- package/dist/controllers/organizations.controller.js +3 -4
- package/dist/controllers/query-api.controller.d.ts +1 -0
- package/dist/controllers/query-api.controller.js +7 -5
- package/dist/controllers/roles.controller.js +58 -6
- package/dist/controllers/user-roles.controller.js +58 -6
- package/dist/controllers/users.controller.d.ts +4 -1
- package/dist/controllers/users.controller.js +87 -11
- package/dist/services/authorization.service.js +0 -2
- package/dist/services/feature.service.d.ts +1 -2
- package/dist/services/feature.service.js +0 -5
- package/dist/services/role.service.d.ts +1 -2
- package/dist/services/role.service.js +0 -5
- package/dist/services/user-role.service.d.ts +1 -2
- package/dist/services/user-role.service.js +0 -5
- package/dist/services/user.service.d.ts +4 -7
- package/dist/services/user.service.js +15 -38
- package/dist/utils/auth/authorize-method.util.d.ts +1 -1
- package/dist/utils/auth/index.d.ts +0 -6
- package/dist/utils/auth/index.js +0 -6
- package/dist/utils/auth/reset-password.util.js +5 -3
- package/package.json +2 -2
- package/dist/utils/auth/assert-admin-or-feature.util.d.ts +0 -2
- package/dist/utils/auth/assert-admin-or-feature.util.js +0 -8
- package/dist/utils/auth/assert-admin.util.d.ts +0 -2
- package/dist/utils/auth/assert-admin.util.js +0 -7
- package/dist/utils/auth/assert-owner-or-admin.util.d.ts +0 -2
- package/dist/utils/auth/assert-owner-or-admin.util.js +0 -10
- package/dist/utils/auth/assert-user-has-feature.util.d.ts +0 -2
- package/dist/utils/auth/assert-user-has-feature.util.js +0 -18
- package/dist/utils/auth/assert-user-or-admin.util.d.ts +0 -3
- package/dist/utils/auth/assert-user-or-admin.util.js +0 -10
- package/dist/utils/auth/change-password.util.d.ts +0 -6
- package/dist/utils/auth/change-password.util.js +0 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loomcore/api",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.53",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb or PostgreSQL",
|
|
6
6
|
"scripts": {
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"reflect-metadata": "^0.2.2"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@loomcore/common": "^0.0.
|
|
63
|
+
"@loomcore/common": "^0.0.89",
|
|
64
64
|
"@sinclair/typebox": "0.34.33",
|
|
65
65
|
"cookie-parser": "^1.4.6",
|
|
66
66
|
"cors": "^2.8.5",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { isAdmin } from './is-admin.util.js';
|
|
2
|
-
import { assertUserHasFeature } from './assert-user-has-feature.util.js';
|
|
3
|
-
export function assertAdminOrFeature(userContext, features, requireAll = false) {
|
|
4
|
-
if (isAdmin(userContext)) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
assertUserHasFeature(userContext, features, requireAll);
|
|
8
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { UnauthorizedError } from '../../errors/index.js';
|
|
2
|
-
import { isAdmin } from './is-admin.util.js';
|
|
3
|
-
export function assertOwnerOrAdmin(userContext, auditable) {
|
|
4
|
-
if (isAdmin(userContext)) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
if (userContext.user._id !== auditable._createdBy) {
|
|
8
|
-
throw new UnauthorizedError();
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { UnauthorizedError } from '../../errors/index.js';
|
|
2
|
-
export function assertUserHasFeature(userContext, features, requireAll = false) {
|
|
3
|
-
if (features.length === 0) {
|
|
4
|
-
return;
|
|
5
|
-
}
|
|
6
|
-
const missingFeatures = features.filter(feature => !userContext.features.includes(feature));
|
|
7
|
-
if (requireAll) {
|
|
8
|
-
if (missingFeatures.length > 0) {
|
|
9
|
-
throw new UnauthorizedError(missingFeatures);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
if (missingFeatures.length === features.length) {
|
|
14
|
-
throw new UnauthorizedError(missingFeatures);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { UnauthorizedError } from '../../errors/index.js';
|
|
2
|
-
import { isAdmin } from './is-admin.util.js';
|
|
3
|
-
export function assertUserOrAdmin(userContext, userId) {
|
|
4
|
-
if (isAdmin(userContext)) {
|
|
5
|
-
return;
|
|
6
|
-
}
|
|
7
|
-
if (userContext.user._id !== userId) {
|
|
8
|
-
throw new UnauthorizedError();
|
|
9
|
-
}
|
|
10
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type IUserContext } from '@loomcore/common/models';
|
|
2
|
-
import type { IDatabase } from '../../databases/models/index.js';
|
|
3
|
-
import type { UpdateResult } from '../../databases/models/update-result.js';
|
|
4
|
-
import { UserService } from '../../services/user.service.js';
|
|
5
|
-
import { AppIdType } from '@loomcore/common/types';
|
|
6
|
-
export declare function changePassword(database: IDatabase, userContext: IUserContext, userId: AppIdType, password: string, userService?: UserService): Promise<UpdateResult>;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { UserService } from '../../services/user.service.js';
|
|
2
|
-
export async function changePassword(database, userContext, userId, password, userService = new UserService(database)) {
|
|
3
|
-
const updates = {
|
|
4
|
-
password: password,
|
|
5
|
-
};
|
|
6
|
-
await userService.partialUpdateById(userContext, userId, updates, true);
|
|
7
|
-
return {
|
|
8
|
-
success: true,
|
|
9
|
-
count: 1,
|
|
10
|
-
};
|
|
11
|
-
}
|