@monorise/core 1.0.2 → 1.0.4-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.
Files changed (69) hide show
  1. package/dist/mock/monorise/chapter.d.ts +1 -1
  2. package/dist/mock/monorise/course.d.ts +1 -1
  3. package/dist/mock/monorise/learning-journey-config.d.ts +1 -1
  4. package/dist/mock/monorise/module.d.ts +1 -1
  5. package/dist/mock/monorise/organization.d.ts +1 -1
  6. package/dist/services/entity.service.d.ts +2 -2
  7. package/dist/services/entity.service.d.ts.map +1 -1
  8. package/package.json +4 -1
  9. package/configs/service.config.ts +0 -14
  10. package/constants/table.ts +0 -3
  11. package/controllers/entity/create-entity.controller.ts +0 -51
  12. package/controllers/entity/delete-entity.controller.ts +0 -35
  13. package/controllers/entity/entity.http +0 -62
  14. package/controllers/entity/get-entity.controller.ts +0 -33
  15. package/controllers/entity/list-entities.controller.ts +0 -69
  16. package/controllers/entity/update-entity.controller.ts +0 -56
  17. package/controllers/entity/upsert-entity.controller.ts +0 -97
  18. package/controllers/mutual/create-mutual.controller.ts +0 -89
  19. package/controllers/mutual/delete-mutual.controller.ts +0 -40
  20. package/controllers/mutual/get-mutual.controller.ts +0 -38
  21. package/controllers/mutual/list-entities-by-entity.controller.ts +0 -76
  22. package/controllers/mutual/mutual.http +0 -88
  23. package/controllers/mutual/update-mutual.controller.ts +0 -50
  24. package/controllers/setupRoutes.ts +0 -73
  25. package/controllers/tag/list-tags.controller.ts +0 -57
  26. package/data/DbUtils.ts +0 -40
  27. package/data/Entity.ts +0 -499
  28. package/data/EventUtils.ts +0 -47
  29. package/data/FileObject.ts +0 -16
  30. package/data/Mutual.ts +0 -779
  31. package/data/ProjectionExpression.ts +0 -8
  32. package/data/Tag.ts +0 -470
  33. package/data/abstract/Item.base.ts +0 -19
  34. package/data/abstract/Repository.base.ts +0 -92
  35. package/errors/api-error.ts +0 -39
  36. package/errors/extendable-error.ts +0 -35
  37. package/errors/standard-error.ts +0 -29
  38. package/helpers/dependencies.ts +0 -10
  39. package/helpers/event.ts +0 -85
  40. package/helpers/fromLastKeyQuery.ts +0 -11
  41. package/helpers/sleep.ts +0 -1
  42. package/helpers/toLastKeyResponse.ts +0 -11
  43. package/index.ts +0 -23
  44. package/middlewares/entity-type-check.ts +0 -20
  45. package/middlewares/mutual-type-check.ts +0 -26
  46. package/mock/entity.ts +0 -12
  47. package/mock/monorise/admin.ts +0 -35
  48. package/mock/monorise/chapter.ts +0 -94
  49. package/mock/monorise/course.ts +0 -149
  50. package/mock/monorise/index.ts +0 -143
  51. package/mock/monorise/learner.ts +0 -66
  52. package/mock/monorise/learning-activity.ts +0 -62
  53. package/mock/monorise/learning-journey-config.ts +0 -34
  54. package/mock/monorise/module.ts +0 -108
  55. package/mock/monorise/organization.ts +0 -63
  56. package/mock/monorise/reference.ts +0 -28
  57. package/mock/monorise/video.ts +0 -36
  58. package/processors/create-entity-processor.ts +0 -55
  59. package/processors/mutual-processor.ts +0 -262
  60. package/processors/prejoin-processor.ts +0 -264
  61. package/processors/replication-processor.ts +0 -261
  62. package/processors/tag-processor.ts +0 -174
  63. package/services/DependencyContainer.ts +0 -208
  64. package/services/entity-service-lifecycle.ts +0 -41
  65. package/services/entity.service.ts +0 -201
  66. package/services/mutual.service.ts +0 -285
  67. package/tsconfig.json +0 -116
  68. package/types/entity.type.ts +0 -62
  69. package/types/event.ts +0 -84
@@ -1,38 +0,0 @@
1
- import type { Entity } from '@monorise/base';
2
- import type { Request, Response } from 'express';
3
- import httpStatus from 'http-status';
4
- import type { MutualRepository } from '../../data/Mutual';
5
-
6
- export class GetMutualController {
7
- constructor(private associateRepository: MutualRepository) {}
8
-
9
- controller: (req: Request, res: Response) => void = async (req, res) => {
10
- const { byEntityType, byEntityId, entityType, entityId } =
11
- req.params as unknown as {
12
- byEntityType: Entity;
13
- byEntityId: string;
14
- entityType: Entity;
15
- entityId: string;
16
- };
17
-
18
- try {
19
- const associate = await this.associateRepository.getMutual(
20
- byEntityType,
21
- byEntityId,
22
- entityType,
23
- entityId,
24
- );
25
-
26
- return res.status(httpStatus.OK).json(associate);
27
- } catch (err) {
28
- if ((err as any).code === 'MUTUAL_IS_UNDEFINED') {
29
- return res.status(httpStatus.NOT_FOUND).json({
30
- code: 'MUTUAL_NOT_FOUND',
31
- message: 'Mutual not found',
32
- });
33
- }
34
-
35
- throw err;
36
- }
37
- };
38
- }
@@ -1,76 +0,0 @@
1
- import type { Entity } from '@monorise/base';
2
- import type { Request, Response } from 'express';
3
- import httpStatus from 'http-status';
4
- import { z } from 'zod';
5
- import type { Mutual, MutualRepository } from '../../data/Mutual';
6
-
7
- export class ListEntitiesByEntityController {
8
- constructor(private associateRepository: MutualRepository) {}
9
-
10
- controller: (req: Request, res: Response) => void = async (req, res) => {
11
- const { byEntityType, byEntityId, entityType } = req.params as unknown as {
12
- byEntityType: Entity;
13
- byEntityId: string;
14
- entityType: Entity;
15
- };
16
-
17
- /**
18
- * Chain query is a query that allows to query entities by a chain of mutual types.
19
- * if /core/mutual/learner/:learnerId/pathways?chainEntityQuery=type1,type2
20
- * then the query will look for list of type1 in learner based on learnerId,
21
- * then look for list of type2 in type1 by list of entityId of type1,
22
- * then finally look for list of pathways in type2 by list of entityId of type2.
23
- */
24
- const querySchema = z.object({
25
- chainEntityQuery: z.string().optional(),
26
- });
27
- const queryParam = querySchema.parse(req.query);
28
- if (queryParam?.chainEntityQuery) {
29
- try {
30
- const mutualTypes = queryParam.chainEntityQuery.split(
31
- ',',
32
- ) as unknown as Entity[];
33
-
34
- const chainMutualTypes = [byEntityType, ...mutualTypes, entityType];
35
- let byIds = [byEntityId];
36
- let items: Mutual<Entity, Entity, Record<string, unknown>>[] = [];
37
-
38
- for (let i = 1; i < chainMutualTypes.length; i++) {
39
- const byType = chainMutualTypes[i - 1];
40
- const type = chainMutualTypes[i];
41
- items = [];
42
-
43
- for (const byId of byIds) {
44
- const resp = await this.associateRepository.listEntitiesByEntity(
45
- byType,
46
- byId,
47
- type,
48
- );
49
- items = items.concat(resp.items);
50
- }
51
- byIds = items.map((item) => item.entityId);
52
- }
53
-
54
- return res.json({
55
- entities: items,
56
- });
57
- } catch (err) {
58
- return res.status(httpStatus.BAD_REQUEST).json({
59
- code: 'INVALID_CHAIN_QUERY',
60
- message:
61
- 'Chain query is invalid. Please double check the chainEntityQuery param',
62
- });
63
- }
64
- } else {
65
- const resp = await this.associateRepository.listEntitiesByEntity(
66
- byEntityType,
67
- byEntityId,
68
- entityType,
69
- );
70
-
71
- return res.json({
72
- entities: resp.items,
73
- });
74
- }
75
- };
76
- }
@@ -1,88 +0,0 @@
1
- ### Mutual
2
-
3
- @byEntityType=learner
4
- @byEntityId=01J5R3ZS09J1GHP3DKSRC6D601
5
- @entityType=course
6
- @entityId=01J5R4032JRV4ABQE42GVGW96C
7
-
8
- ### Create mutual: Associate entity x with entity y
9
-
10
- POST {{BASE_URL}}/core/mutual/{{byEntityType}}/{{byEntityId}}/{{entityType}}/{{entityId}}
11
- content-type: application/json
12
- x-api-key: {{X_API_KEY}}
13
-
14
- {
15
- "scope": ["member"]
16
- }
17
-
18
- ### Reverse associate, same as associate (should failed if already associated)
19
-
20
- POST {{BASE_URL}}/core/mutual/{{entityType}}/{{entityId}}/{{byEntityType}}/{{byEntityId}}
21
- content-type: application/json
22
- x-api-key: {{X_API_KEY}}
23
-
24
- {
25
- "scope": ["member"]
26
- }
27
-
28
- ### List associated accounts (flexible)
29
-
30
- GET {{BASE_URL}}/core/mutual/{{byEntityType}}/{{byEntityId}}/{{entityType}}
31
- content-type: application/json
32
- x-api-key: {{X_API_KEY}}
33
-
34
- ### List associated via chain query
35
-
36
- GET {{BASE_URL}}/core/mutual/{{byEntityType}}/{{byEntityId}}/{{entityType}}?chainEntityQuery=organization
37
- content-type: application/json
38
- x-api-key: {{X_API_KEY}}
39
-
40
- ### Reverse list associated accounts (list from the other perspective)
41
-
42
- GET {{BASE_URL}}/core/mutual/{{entityType}}/{{entityId}}/{{byEntityType}}
43
- content-type: application/json
44
- x-api-key: {{X_API_KEY}}
45
-
46
- ### Get account by entityId
47
-
48
- GET {{BASE_URL}}/core/mutual/{{byEntityType}}/{{byEntityId}}/{{entityType}}/{{entityId}}
49
- content-type: application/json
50
- x-api-key: {{X_API_KEY}}
51
-
52
- ### Reverse get account by entityId (should get the same thing but reversed ID)
53
-
54
- GET {{BASE_URL}}/core/mutual/{{entityType}}/{{entityId}}/{{byEntityType}}/{{byEntityId}}
55
- content-type: application/json
56
- x-api-key: {{X_API_KEY}}
57
-
58
- ### Update associate
59
-
60
- PATCH {{BASE_URL}}/core/mutual/{{byEntityType}}/{{byEntityId}}/{{entityType}}/{{entityId}}
61
- content-type: application/json
62
- x-api-key: {{X_API_KEY}}
63
-
64
- {
65
- "scope": ["superadmin"]
66
- }
67
-
68
- ### Reverse update associate
69
-
70
- PATCH {{BASE_URL}}/core/mutual/{{entityType}}/{{entityId}}/{{byEntityType}}/{{byEntityId}}
71
- content-type: application/json
72
- x-api-key: {{X_API_KEY}}
73
-
74
- {
75
- "scope": ["hello"]
76
- }
77
-
78
- ### Delete associate
79
-
80
- DELETE {{BASE_URL}}/core/mutual/{{byEntityType}}/{{byEntityId}}/{{entityType}}/{{entityId}}
81
- content-type: application/json
82
- x-api-key: {{X_API_KEY}}
83
-
84
- ### Reverse delete associate
85
-
86
- DELETE {{BASE_URL}}/core/mutual/{{entityType}}/{{entityId}}/{{byEntityType}}/{{byEntityId}}
87
- content-type: application/json
88
- x-api-key: {{X_API_KEY}}
@@ -1,50 +0,0 @@
1
- import type { Entity } from '@monorise/base';
2
- import type { Request, Response } from 'express';
3
- import httpStatus from 'http-status';
4
- import { ZodError } from 'zod';
5
- import { StandardError } from '../../errors/standard-error';
6
- import type { MutualService } from '../../services/mutual.service';
7
-
8
- export class UpdateMutualController {
9
- constructor(private mutualService: MutualService) {}
10
-
11
- controller: (req: Request, res: Response) => void = async (req, res) => {
12
- const accountId = req.headers['account-id'];
13
- const { byEntityType, byEntityId, entityType, entityId } =
14
- req.params as unknown as {
15
- byEntityType: Entity;
16
- byEntityId: string;
17
- entityType: Entity;
18
- entityId: string;
19
- };
20
-
21
- try {
22
- const mutual = await this.mutualService.updateMutual({
23
- byEntityType,
24
- byEntityId,
25
- entityType,
26
- entityId,
27
- mutualPayload: req.body,
28
- accountId,
29
- });
30
-
31
- return res.status(httpStatus.OK).json(mutual);
32
- } catch (err) {
33
- if (err instanceof ZodError) {
34
- return res.status(httpStatus.BAD_REQUEST).json({
35
- code: 'API_VALIDATION_ERROR',
36
- message: 'API validation failed',
37
- details: err.flatten(),
38
- });
39
- }
40
-
41
- if (err instanceof StandardError && err.code === 'MUTUAL_NOT_FOUND') {
42
- return res.status(httpStatus.BAD_REQUEST).json({
43
- ...err.toJSON(),
44
- });
45
- }
46
-
47
- throw err;
48
- }
49
- };
50
- }
@@ -1,73 +0,0 @@
1
- import type { Router } from 'express';
2
- import { entityTypeCheck } from '../middlewares/entity-type-check';
3
- import { mutualTypeCheck } from '../middlewares/mutual-type-check';
4
- import { DependencyContainer } from '../services/DependencyContainer';
5
-
6
- const setupCommonRoutes = (router: Router) => {
7
- /*
8
- * Mutual endpoint
9
- */
10
- const container = new DependencyContainer();
11
-
12
- router.use('/mutual/:byEntityType/:byEntityId/:entityType', mutualTypeCheck);
13
- router.get(
14
- '/mutual/:byEntityType/:byEntityId/:entityType',
15
- container.listEntitiesByEntityController.controller,
16
- );
17
- router.post(
18
- '/mutual/:byEntityType/:byEntityId/:entityType/:entityId',
19
- container.createMutualController.controller,
20
- );
21
- router.get(
22
- '/mutual/:byEntityType/:byEntityId/:entityType/:entityId',
23
- container.getMutualController.controller,
24
- );
25
- router.patch(
26
- '/mutual/:byEntityType/:byEntityId/:entityType/:entityId',
27
- container.updateMutualController.controller,
28
- );
29
- router.delete(
30
- '/mutual/:byEntityType/:byEntityId/:entityType/:entityId',
31
- container.deleteMutualController.controller,
32
- );
33
-
34
- /*
35
- * Entities endpoint
36
- */
37
-
38
- router.use('/entity/:entityType', entityTypeCheck);
39
- router.get(
40
- '/entity/:entityType',
41
- container.listEntitiesController.controller,
42
- );
43
- router.post(
44
- '/entity/:entityType',
45
- container.createEntityController.controller,
46
- );
47
- router.get(
48
- '/entity/:entityType/:entityId',
49
- container.getEntityController.controller,
50
- );
51
- router.put(
52
- '/entity/:entityType/:entityId',
53
- container.upsertEntityController.controller,
54
- );
55
- router.patch(
56
- '/entity/:entityType/:entityId',
57
- container.updateEntityController.controller,
58
- );
59
- router.delete(
60
- '/entity/:entityType/:entityId',
61
- container.deleteEntityController.controller,
62
- );
63
-
64
- /*
65
- * Tag endpoint
66
- */
67
- router.get(
68
- '/tag/:entityType/:tagName',
69
- container.listTagsController.controller,
70
- );
71
- };
72
-
73
- export { setupCommonRoutes };
@@ -1,57 +0,0 @@
1
- import type { Entity } from '@monorise/base';
2
- import type { Request, Response } from 'express';
3
- import { z } from 'zod';
4
- import type { TagRepository } from '../../data/Tag';
5
- import { fromLastKeyQuery } from '../../helpers/fromLastKeyQuery';
6
- import { toLastKeyResponse } from '../../helpers/toLastKeyResponse';
7
-
8
- const querySchema = z.object({
9
- group: z.string().optional(),
10
- query: z.string().optional(),
11
- start: z.string().optional(),
12
- end: z.string().optional(),
13
- limit: z.string().optional(),
14
- lastKey: z.string().optional(),
15
- });
16
-
17
- export class ListTagsController {
18
- constructor(private tagRepository: TagRepository) {}
19
-
20
- controller: (req: Request, res: Response) => void = async (req, res) => {
21
- const errorContext: Record<string, unknown> = {};
22
- try {
23
- errorContext.params = req.params;
24
- errorContext.query = req.query;
25
-
26
- const { entityType, tagName } = req.params as unknown as {
27
- entityType: Entity;
28
- tagName: string;
29
- };
30
-
31
- const { lastKey, query, limit, start, end, group } = querySchema.parse(
32
- req.query,
33
- );
34
-
35
- const results = await this.tagRepository.listTags({
36
- entityType,
37
- tagName,
38
- limit: Number(limit),
39
- options: {
40
- lastKey: fromLastKeyQuery(lastKey),
41
- },
42
- query,
43
- group,
44
- start,
45
- end,
46
- });
47
- return res.json({
48
- entities: results.items.map((item) => item.toJSON()),
49
- totalCount: results.totalCount,
50
- lastKey: toLastKeyResponse(results.lastKey),
51
- });
52
- } catch (error) {
53
- console.log({ error, errorContext });
54
- return res.status(500).json({ message: error });
55
- }
56
- };
57
- }
package/data/DbUtils.ts DELETED
@@ -1,40 +0,0 @@
1
- import {
2
- BatchStatementErrorCodeEnum,
3
- type DynamoDB,
4
- type TransactWriteItemsInput,
5
- TransactionCanceledException,
6
- } from '@aws-sdk/client-dynamodb';
7
- import { StandardError } from '../errors/standard-error';
8
-
9
- export class DbUtils {
10
- constructor(private ddbClient: DynamoDB) {}
11
-
12
- async executeTransactWrite(params: TransactWriteItemsInput) {
13
- try {
14
- await this.ddbClient.transactWriteItems(params);
15
- } catch (err) {
16
- if (err instanceof TransactionCanceledException) {
17
- const hasConditionalCheckFailed = err.CancellationReasons?.some(
18
- (reason) =>
19
- reason.Code === BatchStatementErrorCodeEnum.ConditionalCheckFailed,
20
- );
21
-
22
- if (hasConditionalCheckFailed) {
23
- throw new StandardError(
24
- 'CONDITIONAL_CHECK_FAILED',
25
- 'Failed to executeTransactWrite',
26
- err,
27
- { params },
28
- );
29
- }
30
- }
31
-
32
- throw new StandardError(
33
- 'TRANSACTION_FAILED',
34
- 'Failed to executeTransactWrite',
35
- err,
36
- { params },
37
- );
38
- }
39
- }
40
- }