@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.
Files changed (42) hide show
  1. package/LICENSE +201 -201
  2. package/dist/__tests__/common-test.utils.d.ts +2 -0
  3. package/dist/__tests__/common-test.utils.js +7 -1
  4. package/dist/__tests__/mongo-db.test-database.js +46 -12
  5. package/dist/__tests__/test-express-app.js +10 -6
  6. package/dist/controllers/api.controller.d.ts +1 -0
  7. package/dist/controllers/api.controller.js +12 -10
  8. package/dist/controllers/auth.controller.js +6 -2
  9. package/dist/controllers/features.controller.js +58 -6
  10. package/dist/controllers/organizations.controller.js +3 -4
  11. package/dist/controllers/query-api.controller.d.ts +1 -0
  12. package/dist/controllers/query-api.controller.js +7 -5
  13. package/dist/controllers/roles.controller.js +58 -6
  14. package/dist/controllers/user-roles.controller.js +58 -6
  15. package/dist/controllers/users.controller.d.ts +4 -1
  16. package/dist/controllers/users.controller.js +87 -11
  17. package/dist/services/authorization.service.js +0 -2
  18. package/dist/services/feature.service.d.ts +1 -2
  19. package/dist/services/feature.service.js +0 -5
  20. package/dist/services/role.service.d.ts +1 -2
  21. package/dist/services/role.service.js +0 -5
  22. package/dist/services/user-role.service.d.ts +1 -2
  23. package/dist/services/user-role.service.js +0 -5
  24. package/dist/services/user.service.d.ts +4 -7
  25. package/dist/services/user.service.js +15 -38
  26. package/dist/utils/auth/authorize-method.util.d.ts +1 -1
  27. package/dist/utils/auth/index.d.ts +0 -6
  28. package/dist/utils/auth/index.js +0 -6
  29. package/dist/utils/auth/reset-password.util.js +5 -3
  30. package/package.json +2 -2
  31. package/dist/utils/auth/assert-admin-or-feature.util.d.ts +0 -2
  32. package/dist/utils/auth/assert-admin-or-feature.util.js +0 -8
  33. package/dist/utils/auth/assert-admin.util.d.ts +0 -2
  34. package/dist/utils/auth/assert-admin.util.js +0 -7
  35. package/dist/utils/auth/assert-owner-or-admin.util.d.ts +0 -2
  36. package/dist/utils/auth/assert-owner-or-admin.util.js +0 -10
  37. package/dist/utils/auth/assert-user-has-feature.util.d.ts +0 -2
  38. package/dist/utils/auth/assert-user-has-feature.util.js +0 -18
  39. package/dist/utils/auth/assert-user-or-admin.util.d.ts +0 -3
  40. package/dist/utils/auth/assert-user-or-admin.util.js +0 -10
  41. package/dist/utils/auth/change-password.util.d.ts +0 -6
  42. 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.51",
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.87",
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,2 +0,0 @@
1
- import type { IUserContext } from '@loomcore/common/models';
2
- export declare function assertAdminOrFeature(userContext: IUserContext, features: string[], requireAll?: boolean): void;
@@ -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,2 +0,0 @@
1
- import type { IUserContext } from '@loomcore/common/models';
2
- export declare function assertAdmin(userContext: IUserContext): void;
@@ -1,7 +0,0 @@
1
- import { UnauthorizedError } from '../../errors/index.js';
2
- import { isAdmin } from './is-admin.util.js';
3
- export function assertAdmin(userContext) {
4
- if (!isAdmin(userContext)) {
5
- throw new UnauthorizedError();
6
- }
7
- }
@@ -1,2 +0,0 @@
1
- import type { IAuditable, IUserContext } from '@loomcore/common/models';
2
- export declare function assertOwnerOrAdmin(userContext: IUserContext, auditable: IAuditable): void;
@@ -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,2 +0,0 @@
1
- import { IUserContext } from '@loomcore/common/models';
2
- export declare function assertUserHasFeature(userContext: IUserContext, features: string[], requireAll?: boolean): void;
@@ -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,3 +0,0 @@
1
- import type { IUserContext } from '@loomcore/common/models';
2
- import type { AppIdType } from '@loomcore/common/types';
3
- export declare function assertUserOrAdmin(userContext: IUserContext, userId: AppIdType): void;
@@ -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
- }