@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
package/helpers/event.ts DELETED
@@ -1,85 +0,0 @@
1
- import {
2
- EventBridgeClient,
3
- PutEventsCommand,
4
- } from '@aws-sdk/client-eventbridge';
5
- import { CORE_EVENT_BUS } from '../configs/service.config';
6
- import { EVENT, type EventDetail } from '../types/event';
7
-
8
- const eventBridge = new EventBridgeClient();
9
-
10
- type PublishEventProps<T> = {
11
- payload: T;
12
- event: EventDetail;
13
- };
14
-
15
- type ParsedSQSBusEvent<T = Record<string, any>> = {
16
- event: EventDetail;
17
- detail: T;
18
- };
19
-
20
- export function parseSQSBusEvent<T>(
21
- evRecordBody: string,
22
- ): ParsedSQSBusEvent<T> {
23
- const body = JSON.parse(evRecordBody);
24
- return {
25
- ...body,
26
- detail: body.detail,
27
- event: {
28
- Source: body.source,
29
- DetailType: body['detail-type'],
30
- },
31
- };
32
- }
33
-
34
- export async function publishEvent<T extends Record<string, any>>({
35
- payload,
36
- event,
37
- }: PublishEventProps<T>): Promise<void> {
38
- const params = {
39
- Entries: [
40
- {
41
- ...event,
42
- Detail: JSON.stringify(payload),
43
- EventBusName: CORE_EVENT_BUS,
44
- },
45
- ],
46
- };
47
-
48
- await eventBridge.send(new PutEventsCommand(params));
49
- }
50
-
51
- type PublishErrorEventPayload = {
52
- id: string;
53
- serviceName: string;
54
- method: string;
55
- path: string;
56
- body?: Record<string, any>;
57
- error: Error;
58
- };
59
-
60
- export async function publishErrorEvent({
61
- id,
62
- serviceName,
63
- method,
64
- path,
65
- body,
66
- error,
67
- }: PublishErrorEventPayload) {
68
- await publishEvent({
69
- event: EVENT.GENERAL.ENDPOINT_ERROR,
70
- payload: {
71
- id,
72
- serviceName,
73
- method,
74
- path,
75
- ...(body ? { requestBody: body } : {}),
76
- error: {
77
- name: error.name,
78
- message: error.message,
79
- // @ts-ignore
80
- cause: error.cause,
81
- stack: error.stack,
82
- },
83
- },
84
- });
85
- }
@@ -1,11 +0,0 @@
1
- import type { NativeAttributeValue } from '@aws-sdk/util-dynamodb';
2
-
3
- export function fromLastKeyQuery(
4
- lastKeyQuery?: string,
5
- ): Record<string, NativeAttributeValue> | undefined {
6
- if (!lastKeyQuery) {
7
- return;
8
- }
9
-
10
- return JSON.parse(Buffer.from(lastKeyQuery, 'base64').toString('utf-8'));
11
- }
package/helpers/sleep.ts DELETED
@@ -1 +0,0 @@
1
- export const sleep = (ms: number) => new Promise((res) => setTimeout(res, ms));
@@ -1,11 +0,0 @@
1
- import type { NativeAttributeValue } from '@aws-sdk/util-dynamodb';
2
-
3
- export function toLastKeyResponse(
4
- lastKey?: Record<string, NativeAttributeValue>,
5
- ): string | undefined {
6
- if (!lastKey) {
7
- return;
8
- }
9
-
10
- return Buffer.from(JSON.stringify(lastKey)).toString('base64');
11
- }
package/index.ts DELETED
@@ -1,23 +0,0 @@
1
- import { setupCommonRoutes } from './controllers/setupRoutes';
2
- import { Entity } from './data/Entity';
3
- import { Mutual } from './data/Mutual';
4
- import { PROJECTION_EXPRESSION } from './data/ProjectionExpression';
5
- import { handler as createEntityProcessor } from './processors/create-entity-processor';
6
- import { handler as mutualProcessor } from './processors/mutual-processor';
7
- import { handler as prejoinProcessor } from './processors/prejoin-processor';
8
- import { handler as replicationProcessor } from './processors/replication-processor';
9
- import { handler as tagProcessor } from './processors/tag-processor';
10
- import { DependencyContainer } from './services/DependencyContainer';
11
-
12
- export {
13
- setupCommonRoutes,
14
- Entity,
15
- Mutual,
16
- PROJECTION_EXPRESSION,
17
- createEntityProcessor,
18
- mutualProcessor,
19
- prejoinProcessor,
20
- replicationProcessor,
21
- tagProcessor,
22
- DependencyContainer,
23
- };
@@ -1,20 +0,0 @@
1
- import type { Entity } from '@monorise/base';
2
- import type { NextFunction, Request, Response } from 'express';
3
- import httpStatus from 'http-status';
4
- import { AllowedEntityTypes } from '#/lambda-layer/monorise';
5
-
6
- export const entityTypeCheck: (
7
- req: Request,
8
- res: Response,
9
- next: NextFunction,
10
- ) => void = (req, res, next) => {
11
- const { entityType } = req.params as unknown as { entityType: Entity };
12
-
13
- if (!AllowedEntityTypes.includes(entityType)) {
14
- return res.status(httpStatus.NOT_FOUND).json({
15
- code: 'NOT_FOUND',
16
- });
17
- }
18
-
19
- next();
20
- };
@@ -1,26 +0,0 @@
1
- import type { Entity } from '@monorise/base';
2
- import type { NextFunction, Request, Response } from 'express';
3
- import httpStatus from 'http-status';
4
- import { AllowedEntityTypes } from '#/lambda-layer/monorise';
5
-
6
- export const mutualTypeCheck: (
7
- req: Request,
8
- res: Response,
9
- next: NextFunction,
10
- ) => void = (req, res, next) => {
11
- const { entityType, byEntityType } = req.params as unknown as {
12
- entityType: Entity;
13
- byEntityType: Entity;
14
- };
15
-
16
- if (
17
- !AllowedEntityTypes.includes(entityType) ||
18
- !AllowedEntityTypes.includes(byEntityType)
19
- ) {
20
- return res.status(httpStatus.NOT_FOUND).json({
21
- code: 'NOT_FOUND',
22
- });
23
- }
24
-
25
- next();
26
- };
package/mock/entity.ts DELETED
@@ -1,12 +0,0 @@
1
- export enum Entity {
2
- ADMIN = 'admin',
3
- CHAPTER = 'chapter',
4
- COURSE = 'course',
5
- LEARNER = 'learner',
6
- LEARNING_ACTIVITY = 'learning-activity',
7
- LEARNING_JOURNEY_CONFIG = 'learning-journey-config',
8
- MODULE = 'module',
9
- ORGANIZATION = 'organization',
10
- REFERENCE = 'reference',
11
- VIDEO = 'video',
12
- }
@@ -1,35 +0,0 @@
1
- import { createEntityConfig } from '@monorise/cli';
2
- import { z } from 'zod';
3
-
4
- const baseSchema = z
5
- .object({
6
- email: z.string().toLowerCase(),
7
- displayName: z.string(),
8
- })
9
- .partial();
10
-
11
- const createSchema = baseSchema.extend({
12
- email: z
13
- .string()
14
- .toLowerCase()
15
- .regex(
16
- /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/,
17
- "Doesn't seems like an email",
18
- ),
19
- displayName: z.string().min(1, 'Please provide a name for this user account'),
20
- });
21
-
22
- const config = createEntityConfig({
23
- name: 'admin',
24
- displayName: 'Admin',
25
- authMethod: {
26
- email: {
27
- tokenExpiresIn: 1000 * 60 * 60 * 24 * 14, // 14 days
28
- },
29
- },
30
- baseSchema,
31
- createSchema,
32
- searchableFields: ['email', 'displayName'],
33
- });
34
-
35
- export default config;
@@ -1,94 +0,0 @@
1
- import { createEntityConfig } from '@monorise/cli';
2
- import type { Mutual } from '@monorise/react';
3
- import { z } from 'zod';
4
- import { Entity } from '../entity';
5
-
6
- export enum CHAPTER_TYPE {
7
- CHAPTER = 'CHAPTER',
8
- CUSTOM = 'CUSTOM',
9
- TOUCHPOINT = 'TOUCHPOINT',
10
- CHECKPOINT = 'CHECKPOINT',
11
- }
12
-
13
- const baseSchema = z
14
- .object({
15
- description: z.string(),
16
- discussionLink: z.string(),
17
- remark: z.string(),
18
- type: z.nativeEnum(CHAPTER_TYPE),
19
- title: z.string(),
20
- learningActivityDescription: z.string(),
21
- body: z
22
- .object({
23
- type: z.string(),
24
- id: z.string(),
25
- content: z.any(),
26
- })
27
- .array()
28
- .optional(),
29
- progress: z.coerce.number().int(),
30
- })
31
- .partial();
32
-
33
- const createSchema = baseSchema.extend({
34
- remark: z.string(),
35
- type: z.nativeEnum(CHAPTER_TYPE),
36
- });
37
-
38
- const mutualSchema = z
39
- .object({
40
- learningActivityOrders: z.string().array(),
41
- referenceOrders: z.string().array(),
42
- videos: z.string().array().max(1),
43
- })
44
- .partial();
45
-
46
- const config = createEntityConfig({
47
- name: 'chapter',
48
- displayName: 'Chapter',
49
- baseSchema,
50
- createSchema,
51
- searchableFields: ['remark', 'title'],
52
- mutual: {
53
- mutualSchema,
54
- mutualFields: {
55
- learningActivityOrders: {
56
- entityType: Entity.LEARNING_ACTIVITY,
57
- mutualDataProcessor: (
58
- ids: string[],
59
- context: Mutual<Entity.CHAPTER, Entity.LEARNING_ACTIVITY>,
60
- ) => {
61
- return { index: ids.indexOf(context.entityId) };
62
- },
63
- },
64
- referenceOrders: {
65
- entityType: Entity.REFERENCE,
66
- mutualDataProcessor: (
67
- ids: string[],
68
- context: Mutual<Entity.CHAPTER, Entity.REFERENCE>,
69
- ) => {
70
- return { index: ids.indexOf(context.entityId) };
71
- },
72
- },
73
- videos: {
74
- entityType: Entity.VIDEO,
75
- },
76
- },
77
- },
78
- effect: (schema) => {
79
- return schema.superRefine((value, ctx) => {
80
- if (
81
- value.type === CHAPTER_TYPE.CHAPTER &&
82
- 'videos' in value &&
83
- !value.videos?.length
84
- )
85
- ctx.addIssue({
86
- code: z.ZodIssueCode.custom,
87
- message: 'Video is required',
88
- path: ['videos'],
89
- });
90
- });
91
- },
92
- });
93
-
94
- export default config;
@@ -1,149 +0,0 @@
1
- import { createEntityConfig } from '@monorise/cli';
2
- import type { Mutual } from '@monorise/react';
3
- import { z } from 'zod';
4
- import { Entity } from '../entity';
5
-
6
- const baseSchema = z
7
- .object({
8
- title: z.string(),
9
- categories: z.string().array(),
10
- duration: z.number(),
11
- description: z.string(),
12
- learningOutcomes: z.string().array(),
13
- infographics: z.string().array(),
14
- tags: z.string().array(),
15
- })
16
- .partial();
17
-
18
- const createSchema = baseSchema.extend({
19
- title: z.string().min(4, {
20
- message: 'Title must be at least 4 characters.',
21
- }),
22
- });
23
-
24
- const mutualSchema = z
25
- .object({
26
- moduleOrders: z.string().array(),
27
- videos: z.string().array(),
28
- chapters: z.string().array(),
29
- learningActivities: z.string().array(),
30
- })
31
- .partial();
32
-
33
- const config = createEntityConfig({
34
- name: 'course',
35
- displayName: 'Course',
36
- baseSchema: baseSchema,
37
- createSchema,
38
- searchableFields: ['title'],
39
- mutual: {
40
- subscribes: [{ entityType: Entity.MODULE }],
41
- mutualSchema,
42
- mutualFields: {
43
- moduleOrders: {
44
- entityType: Entity.MODULE,
45
- mutualDataProcessor: (
46
- ids: string[],
47
- context: Mutual<Entity.COURSE, Entity.MODULE>,
48
- ) => {
49
- return { index: ids.indexOf(context.entityId) };
50
- },
51
- },
52
- videos: {
53
- entityType: Entity.VIDEO,
54
- mutualDataProcessor: (
55
- ids: string[],
56
- context: Mutual<Entity.COURSE, Entity.VIDEO>,
57
- prejoinContext?: Record<string, any>,
58
- ) => {
59
- return {
60
- index: ids.indexOf(context.entityId),
61
- moduleId: prejoinContext?.[context.entityId],
62
- };
63
- },
64
- },
65
- chapters: {
66
- entityType: Entity.CHAPTER,
67
- mutualDataProcessor: (
68
- ids: string[],
69
- context: Mutual<Entity.COURSE, Entity.CHAPTER>,
70
- prejoinContext?: Record<string, any>,
71
- ) => ({
72
- index: ids.indexOf(context.entityId),
73
- moduleId: prejoinContext?.[context.entityId],
74
- }),
75
- },
76
- learningActivities: {
77
- entityType: Entity.LEARNING_ACTIVITY,
78
- mutualDataProcessor: (
79
- ids: string[],
80
- context: Mutual<Entity.COURSE, Entity.LEARNING_ACTIVITY>,
81
- prejoinContext?: Record<string, any>,
82
- ) => {
83
- return {
84
- index: ids.indexOf(context.entityId),
85
- moduleId: prejoinContext?.[context.entityId],
86
- };
87
- },
88
- },
89
- },
90
-
91
- prejoins: [
92
- {
93
- mutualField: 'chapters',
94
- targetEntityType: Entity.CHAPTER,
95
- entityPaths: [
96
- {
97
- entityType: Entity.COURSE,
98
- },
99
- {
100
- entityType: Entity.MODULE,
101
- },
102
- {
103
- entityType: Entity.CHAPTER,
104
- },
105
- ],
106
- },
107
- {
108
- mutualField: 'videos',
109
- targetEntityType: Entity.VIDEO,
110
- entityPaths: [
111
- {
112
- entityType: Entity.COURSE,
113
- },
114
- {
115
- entityType: Entity.MODULE,
116
- },
117
- {
118
- skipCache: true,
119
- entityType: Entity.CHAPTER,
120
- },
121
- {
122
- entityType: Entity.VIDEO,
123
- },
124
- ],
125
- },
126
- {
127
- mutualField: 'learningActivities',
128
- targetEntityType: Entity.LEARNING_ACTIVITY,
129
- entityPaths: [
130
- {
131
- entityType: Entity.COURSE,
132
- },
133
- {
134
- entityType: Entity.MODULE,
135
- },
136
- {
137
- skipCache: true,
138
- entityType: Entity.CHAPTER,
139
- },
140
- {
141
- entityType: Entity.LEARNING_ACTIVITY,
142
- },
143
- ],
144
- },
145
- ],
146
- },
147
- });
148
-
149
- export default config;
@@ -1,143 +0,0 @@
1
- import type { z } from 'zod';
2
- import admin from './admin';
3
- import chapter from './chapter';
4
- import course from './course';
5
- import learner from './learner';
6
- import learningActivity from './learning-activity';
7
- import learningJourneyConfig from './learning-journey-config';
8
- import module from './module';
9
- import organization from './organization';
10
- import reference from './reference';
11
- import video from './video';
12
-
13
- export enum Entity {
14
- ADMIN = 'admin',
15
- CHAPTER = 'chapter',
16
- COURSE = 'course',
17
- LEARNER = 'learner',
18
- LEARNING_ACTIVITY = 'learning-activity',
19
- LEARNING_JOURNEY_CONFIG = 'learning-journey-config',
20
- MODULE = 'module',
21
- ORGANIZATION = 'organization',
22
- REFERENCE = 'reference',
23
- VIDEO = 'video',
24
- }
25
-
26
- export type AdminType = z.infer<(typeof admin)['finalSchema']>;
27
- export type ChapterType = z.infer<(typeof chapter)['finalSchema']>;
28
- export type CourseType = z.infer<(typeof course)['finalSchema']>;
29
- export type LearnerType = z.infer<(typeof learner)['finalSchema']>;
30
- export type LearningActivityType = z.infer<
31
- (typeof learningActivity)['finalSchema']
32
- >;
33
- export type LearningJourneyConfigType = z.infer<
34
- (typeof learningJourneyConfig)['finalSchema']
35
- >;
36
- export type ModuleType = z.infer<(typeof module)['finalSchema']>;
37
- export type OrganizationType = z.infer<(typeof organization)['finalSchema']>;
38
- export type ReferenceType = z.infer<(typeof reference)['finalSchema']>;
39
- export type VideoType = z.infer<(typeof video)['finalSchema']>;
40
-
41
- export interface EntitySchemaMap {
42
- admin: AdminType;
43
- chapter: ChapterType;
44
- course: CourseType;
45
- learner: LearnerType;
46
- learningActivity: LearningActivityType;
47
- learningJourneyConfig: LearningJourneyConfigType;
48
- module: ModuleType;
49
- organization: OrganizationType;
50
- reference: ReferenceType;
51
- video: VideoType;
52
- }
53
-
54
- const EntityConfig = {
55
- [Entity.ADMIN]: admin,
56
- [Entity.CHAPTER]: chapter,
57
- [Entity.COURSE]: course,
58
- [Entity.LEARNER]: learner,
59
- [Entity.LEARNING_ACTIVITY]: learningActivity,
60
- [Entity.LEARNING_JOURNEY_CONFIG]: learningJourneyConfig,
61
- [Entity.MODULE]: module,
62
- [Entity.ORGANIZATION]: organization,
63
- [Entity.REFERENCE]: reference,
64
- [Entity.VIDEO]: video,
65
- };
66
-
67
- const FormSchema = {
68
- [Entity.ADMIN]: admin.finalSchema,
69
- [Entity.CHAPTER]: chapter.finalSchema,
70
- [Entity.COURSE]: course.finalSchema,
71
- [Entity.LEARNER]: learner.finalSchema,
72
- [Entity.LEARNING_ACTIVITY]: learningActivity.finalSchema,
73
- [Entity.LEARNING_JOURNEY_CONFIG]: learningJourneyConfig.finalSchema,
74
- [Entity.MODULE]: module.finalSchema,
75
- [Entity.ORGANIZATION]: organization.finalSchema,
76
- [Entity.REFERENCE]: reference.finalSchema,
77
- [Entity.VIDEO]: video.finalSchema,
78
- };
79
-
80
- const AllowedEntityTypes = [
81
- Entity.ADMIN,
82
- Entity.CHAPTER,
83
- Entity.COURSE,
84
- Entity.LEARNER,
85
- Entity.LEARNING_ACTIVITY,
86
- Entity.LEARNING_JOURNEY_CONFIG,
87
- Entity.MODULE,
88
- Entity.ORGANIZATION,
89
- Entity.REFERENCE,
90
- Entity.VIDEO,
91
- ];
92
-
93
- const EmailAuthEnabledEntities = [Entity.ADMIN, Entity.LEARNER];
94
-
95
- export {
96
- EntityConfig,
97
- FormSchema,
98
- AllowedEntityTypes,
99
- EmailAuthEnabledEntities,
100
- };
101
-
102
- declare module '@monorise/base' {
103
- export enum Entity {
104
- ADMIN = 'admin',
105
- CHAPTER = 'chapter',
106
- COURSE = 'course',
107
- LEARNER = 'learner',
108
- LEARNING_ACTIVITY = 'learning-activity',
109
- LEARNING_JOURNEY_CONFIG = 'learning-journey-config',
110
- MODULE = 'module',
111
- ORGANIZATION = 'organization',
112
- REFERENCE = 'reference',
113
- VIDEO = 'video',
114
- }
115
-
116
- export type AdminType = z.infer<(typeof admin)['finalSchema']>;
117
- export type ChapterType = z.infer<(typeof chapter)['finalSchema']>;
118
- export type CourseType = z.infer<(typeof course)['finalSchema']>;
119
- export type LearnerType = z.infer<(typeof learner)['finalSchema']>;
120
- export type LearningActivityType = z.infer<
121
- (typeof learningActivity)['finalSchema']
122
- >;
123
- export type LearningJourneyConfigType = z.infer<
124
- (typeof learningJourneyConfig)['finalSchema']
125
- >;
126
- export type ModuleType = z.infer<(typeof module)['finalSchema']>;
127
- export type OrganizationType = z.infer<(typeof organization)['finalSchema']>;
128
- export type ReferenceType = z.infer<(typeof reference)['finalSchema']>;
129
- export type VideoType = z.infer<(typeof video)['finalSchema']>;
130
-
131
- export interface EntitySchemaMap {
132
- admin: AdminType;
133
- chapter: ChapterType;
134
- course: CourseType;
135
- learner: LearnerType;
136
- learningActivity: LearningActivityType;
137
- learningJourneyConfig: LearningJourneyConfigType;
138
- module: ModuleType;
139
- organization: OrganizationType;
140
- reference: ReferenceType;
141
- video: VideoType;
142
- }
143
- }
@@ -1,66 +0,0 @@
1
- import { createEntityConfig } from '@monorise/cli';
2
- import { z } from 'zod';
3
- import { Entity } from '../entity';
4
- import { EXPIRY_TYPE } from './organization';
5
-
6
- const baseSchema = z
7
- .object({
8
- email: z
9
- .string()
10
- .toLowerCase()
11
- .regex(
12
- /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/,
13
- "Doesn't seems like an email",
14
- ),
15
- displayName: z
16
- .string()
17
- .min(1, 'Please provide a name for this user account'),
18
- firstName: z.string().min(1, 'Please provide first name'),
19
- lastName: z.string().min(1, 'Please provide last name'),
20
- jobTitle: z.string(),
21
- locatedCountry: z.string(),
22
- educationLevel: z.string(),
23
- school: z.string(),
24
- major: z.string(),
25
- expiryType: z.nativeEnum(EXPIRY_TYPE).nullable(),
26
- expiryDate: z.string().datetime().nullable(),
27
- subOrganizationId: z.string(),
28
- acceptedDisclaimer: z.boolean(),
29
- })
30
- .partial();
31
-
32
- const createSchema = baseSchema.extend({
33
- email: z.string().toLowerCase(),
34
- displayName: z.string().min(1, 'Please provide a name for this user account'),
35
- firstName: z.string().min(1, 'Please provide first name'),
36
- lastName: z.string().min(1, 'Please provide last name'),
37
- });
38
-
39
- const mutualSchema = z
40
- .object({
41
- organizations: z.string().array(),
42
- })
43
- .partial();
44
-
45
- const config = createEntityConfig({
46
- name: 'learner',
47
- displayName: 'Learner',
48
- authMethod: {
49
- email: {
50
- tokenExpiresIn: 1000 * 60 * 60 * 24 * 14, // 14 days
51
- },
52
- },
53
- baseSchema,
54
- createSchema,
55
- searchableFields: ['email', 'displayName', 'firstName', 'lastName'],
56
- mutual: {
57
- mutualSchema,
58
- mutualFields: {
59
- organizations: {
60
- entityType: Entity.ORGANIZATION,
61
- },
62
- },
63
- },
64
- });
65
-
66
- export default config;