Skip to content

Commit bd11bba

Browse files
authored
feat(notification): init task entity and notify factory infra (#111)
* feat(notification): add notice all * feat(notification): add create batch tests * feat(notification): update notice tests * feat(notification): add send notice to all users tests * feat(notification): add create notice batch permissions * feat(notification): init notify task entity and factory * feat(notification): add task template relations * feat(notification): add task crud * feat(notification): remove create batch * feat(notification): clean up * feat(notification): clean up * feat(notification): rename notify tasks to task handlers * feat(notification): add task handlers workflow and notice all service (#112) * feat(notification): add task http requests examples * feat(notification): update task crud * feat(notification): clean up * feat(notification): add task migration * feat(notification): add task attach nested notice and message logic * feat(notification): update task factory process * feat(notification): add task handlers process and retry workflow * feat(notification): update task error target naming * feat(notification): add task and job permissions * feat(notification): update cron tasks * feat(notification): update tasks handlers tasks select * feat(notification): update templates build * feat(notification): update task relations * feat(notification): update task entity * feat(notification): clean up * feat(notification): update task error logging * feat(notification): update task last error target type * feat(notification): update notice all workflow * feat(notification): update jsdocs * feat(notification): update jsdocs * feat(notification): clean up * feat(notification): clean up * feat(notification): clean up * feat(notification): update job tasks output (#113) * feat(notification): update job tasks output * feat(notification): update cron config * feat(notification): clean up * feat(notification): add task email all and update message validation (#114) * feat(notification): update json schema descriptions * feat(notification): add email all workflow * feat(notification): update message and notice validations * feat(notification): update message entity validators * feat(notification): update nodemailer email send * feat(notification): clean up * feat(notification): update send all email workflow * feat(notification): update message relation with task * feat(notification): clean up * feat(notification): update email all rollback send workflow * feat(notification): clean up * feat(notification): add notification task tests (#115) * feat(notification): update send email tests * feat(notification): add crud task tests * feat(notification): add factory tests * feat(notification): clean up * feat(notification): update abstract tests * feat(notification): update mocks * feat(notification): add task modes and update task factory tests (#116) * feat(notification): update jsdocs * feat(notification): clean up * feat(notification): add task modes and tests * feat(notification): update jsdocs * feat(notification): add task http example with the full check up mode * feat(notification): update jsdocs * feat(notification): update jsdocs * feat(notification): update check for failed tasks for the duplicated notifications * feat(notification): clean up * feat(notification): update jsdocs * feat(notification): add email group workflow (#117) * feat(notification): add email group workflow * feat(notification): update tests * feat(notification): update jsdocs * feat(notification): update message recipient relation * feat(notification): clean up * feat(notification): update deps * feat(notification): rebuild * feat: add checkout step for pr title check action * feat(notification): update tests * feat(notification): update permissions * feat(notification): clean up * feat(notification): clean up
1 parent 28de629 commit bd11bba

File tree

47 files changed

+2675
-50
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2675
-50
lines changed

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MS_INIT_CONFIGS='[{"microservice":"*","type":"db","params":{"host":"db","port":5432,"username":"postgres","password":"example"}},{"microservice":"authentication","type":"config","params":{"jwtOptions":{"secretKey":"DemoSecretKey"}}},{"microservice":"authorization","type":"config","params":{}},{"microservice":"content","type":"config","params":{}},{"microservice":"gateway","type":"config","params":{"corsOptions":{},"webhookUrl":"/webhook/"}},{"microservice":"users","type":"config","params":{"removedAccountRestoreTime":0}},{"microservice":"notification","type":"config","params":{"defaultEmailFrom":"[email protected]","transportOptions":{"host":"smtp.ethereal.email","port":587,"secure":false,"auth":{"user":"generated ethereal user","pass":"generated ethereal password"}}}},{"microservice":"files","type":"config","params":{"imageProcessingConfig":{"thumbnails":[{"name":"thumbnail","options":{"width":75}},{"name":"small","options":{"width":150}},{"name":"medium","options":{"width":300}},{"name":"large","options":{"width":600}},{"name":"extra-large","options":{"width":1200}}],"outputOptions":{"jpeg":{"quality":80,"mozjpeg":true},"png":{"quality":80},"webp":{"quality":80}},"isWebp":true}}},{"microservice":"payment-stripe","type":"config","params":{"paymentMethods":["bancontact","card"],"apiKey":"your test key from stripe or other service","config":{"apiVersion":"2022-11-15"},"payoutCoeff":0.3,"webhookKeys":{"connect":"your test webhook key from stripe or other service for connect account"},"fees":{"stableUnit":30,"paymentPercent":2.9},"duplicatedCardsUsage":"reject"}}]'
22
MS_INIT_MIDDLEWARES='[{"target":"gateway","targetMethod":"*","sender":"authentication","senderMethod":"token.identify","type":"request","order":10,"description":"Validate JWT token and add payload with token info.","params":{"type":"request","isRequired":true,"maxValueSize":100,"exclude":["users.user.sign-in","users.identity-provider.sign-in","authentication.cookies.remove","authentication.token.renew"],"strategy":"transform","convertResult":{"payload.authentication.tokenId":"$middleware.tokenId","payload.authentication.userId":"$middleware.userId","payload.authentication.isAuth":"$middleware.isAuth","payload.authentication.provider":"$middleware.provider"}}},{"target":"gateway","targetMethod":"*","sender":"authorization","senderMethod":"endpoint.enforce","type":"request","order":20,"description":"Whether the user is allowed to call the method. Filter method input params.","params":{"type":"request","isRequired":true,"isCleanResult":true,"strategy":"transform","reqParams":{"isInternal":true},"convertParams":{"userId":"$task.params.payload.authentication.userId","method":"$task.method","filterInput":"$task.params"},"convertResult":{".":"$middleware.filteredInput","payload":"$task.params.payload","payload.authorization.isAllow":"$middleware.isAllow","payload.authorization.roles":"$middleware.roles","payload.authorization.filter":"$middleware.filters"}}},{"target":"gateway","targetMethod":"*","sender":"authorization","senderMethod":"endpoint.filter","type":"response","order":20,"description":"Filter microservice response fields.","params":{"type":"response","isRequired":true,"isCleanResult":true,"strategy":"transform","reqParams":{"isInternal":true},"convertParams":{"type":"out","userId":"$task.params.payload.authentication.userId","method":"$task.method","filterInput":"$result"},"convertResult":{".":"$middleware.filtered"}}},{"target":"users","targetMethod":"identity-provider.sign-in","sender":"authentication","senderMethod":"token.create","type":"response","order":10,"description":"Create JWT auth tokens and attach to response after successful sign in.","params":{"type":"response","isRequired":true,"strategy":"transform","extraRequests":[{"key":"rolesResp","method":"authorization.user-role.view","params":{"userId":"<%= result.user.id %>"}}],"convertParams":{"type":"jwt","userId":"$result.user.id","params":"$task.params.payload.headers.user-info","jwtPayload.roles":"$rolesResp.roles","returnType":"<%= _.get(task, \"params.payload.headers.user-info.authType\", \"cookies\") %>"},"convertResult":{"payload.cookies":"$middleware.payload.cookies","tokens.access":"$middleware.access","tokens.refresh":"$middleware.refresh"}}},{"target":"users","targetMethod":"user.sign-in","sender":"authentication","senderMethod":"token.create","type":"response","order":10,"description":"Create JWT auth tokens and attach to response after successful sign in.","params":{"type":"response","isRequired":true,"strategy":"transform","extraRequests":[{"key":"rolesResp","method":"authorization.user-role.view","params":{"userId":"<%= result.user.id %>"}}],"convertParams":{"type":"jwt","userId":"$result.user.id","params":"$task.params.payload.headers.user-info","jwtPayload.roles":"$rolesResp.roles","returnType":"<%= _.get(task, \"params.payload.headers.user-info.authType\", \"cookies\") %>"},"convertResult":{"payload.cookies":"$middleware.payload.cookies","tokens.access":"$middleware.access","tokens.refresh":"$middleware.refresh"}}},{"target":"users","targetMethod":"user.sign-up","sender":"authentication","senderMethod":"token.create","type":"response","order":10,"description":"Create JWT auth tokens and attach to response after successful sign up.","params":{"type":"response","isRequired":true,"strategy":"transform","extraRequests":[{"key":"rolesResp","method":"authorization.user-role.view","params":{"userId":"<%= result.user.id %>"}}],"convertParams":{"type":"jwt","userId":"$result.user.id","params":"$task.params.payload.headers.user-info","jwtPayload.roles":"$rolesResp.roles","returnType":"<%= _.get(task, \"params.payload.headers.user-info.authType\", \"cookies\") %>"},"convertResult":{"payload.cookies":"$middleware.payload.cookies","tokens.access":"$middleware.access","tokens.refresh":"$middleware.refresh"}}},{"target":"users","targetMethod":"user.sign-out","sender":"authentication","senderMethod":"token.remove","type":"response","order":10,"description":"Remove JWT auth token after successful sign out.","params":{"type":"response","isRequired":true,"strategy":"transform","extraRequests":[{"key":"rolesResp","method":"authentication.cookies.remove","condition":"<%= _.get(task, \"params.payload.headers.authType\", \"cookies\") === \"cookies\" %>"}],"convertParams":{"query.where.id":"$task.params.payload.authentication.tokenId"},"convertResult":{"payload.cookies":"$rolesResp.payload.cookies"}}},{"target":"users","targetMethod":"user.remove","sender":"authentication","senderMethod":"token.remove","type":"response","order":10,"description":"Remove JWT auth tokens after successful sign out.","params":{"type":"response","isRequired":true,"strategy":"transform","extraRequests":[{"key":"rolesResp","method":"authentication.cookies.remove","condition":"<%= _.get(task, \"params.payload.headers.authType\", \"cookies\") === \"cookies\" %>"}],"convertParams":{"query.where.userId":"$task.params.payload.authentication.userId"},"convertResult":{"payload.cookies":"$rolesResp.payload.cookies"}}}]'
3-
MS_INIT_TASKS='[{"rule":"0 1 * * *","method":"users.confirm-code.remove","description":"Cleanup old confirmation codes","payload":{"params":{"query":{"where":{"expirationAt":{"<":"<%= Math.floor(Date.now() / 1000) %>"}}},"payload":{"authorization":{"filter":{"methodOptions":{"isAllowMultiple":true}}}}},"allowErrorCodes":[-33485],"responseTemplate":"<%= `deleted: ${deleted.length}` %>"}},{"rule":"0 1 * * *","method":"authentication.token.remove","description":"Cleanup old auth tokens","payload":{"params":{"query":{"where":{"expirationAt":{"<":"<%= Math.floor(Date.now() / 1000) %>"}}},"payload":{"authorization":{"filter":{"methodOptions":{"isAllowMultiple":true}}}}},"allowErrorCodes":[-33485],"responseTemplate":"<%= `deleted: ${deleted.length}` %>"}}]'
3+
MS_INIT_TASKS='[{"rule":"0 1 * * *","method":"users.confirm-code.remove","description":"Cleanup old confirmation codes","payload":{"params":{"query":{"where":{"expirationAt":{"<":"<%= Math.floor(Date.now() / 1000) %>"}}},"payload":{"authorization":{"filter":{"methodOptions":{"isAllowMultiple":true}}}}},"allowErrorCodes":[-33485],"responseTemplate":"<%= `deleted: ${deleted.length}` %>"}},{"rule":"0 1 * * *","method":"authentication.token.remove","description":"Cleanup old auth tokens","payload":{"params":{"query":{"where":{"expirationAt":{"<":"<%= Math.floor(Date.now() / 1000) %>"}}},"payload":{"authorization":{"filter":{"methodOptions":{"isAllowMultiple":true}}}}},"allowErrorCodes":[-33485],"responseTemplate":"<%= `deleted: ${deleted.length}` %>"}},{"rule":"* * * * *","method":"notification.job.task.process","description":"Process tasks","payload":{"responseTemplate":"<%= `Process tasks counts: total is ${total}, completed is ${completed} and failed is ${failed}` %>"}}]'
44
MS_IMPORT_PERMISSION=2
55
MS_CONNECTION=http://ijson:8001
66
GATEWAY_PORT=3000

.github/workflows/pr-check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
runs-on: ubuntu-latest
3636

3737
steps:
38+
- uses: actions/checkout@v3
39+
3840
- name: Commit lint
3941
run: |
4042
npm install commitlint@latest @commitlint/config-conventional@latest

configs/cron.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,13 @@
5252
"allowErrorCodes": [-33485],
5353
"responseTemplate": "<%= `deleted: ${deleted.length}` %>"
5454
}
55+
},
56+
{
57+
"rule": "* * * * *",
58+
"method": "notification.job.task.process",
59+
"description": "Process tasks",
60+
"payload": {
61+
"responseTemplate": "<%= `Process tasks counts: total is ${total}, completed is ${completed} and failed is ${failed}` %>"
62+
}
5563
}
5664
]
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
### Create email all task with full check up mode
2+
POST http://127.0.0.1:8001/ms/notification
3+
Accept: application/json
4+
Content-Type: application/json
5+
6+
{
7+
"id": "1",
8+
"method": "notice.create",
9+
"params": {
10+
"fields": [
11+
{
12+
"userId": "6e6ed89f-637f-4fd6-86c2-95ef706cacf3",
13+
"title": "1 task notice all",
14+
"description": "1 task notice all description",
15+
"type": "announce",
16+
"params": {
17+
"status": "warning",
18+
"isTemplate": true
19+
}
20+
},
21+
{
22+
"userId": "5b86356f-bea2-469b-8a82-7566f369a1e0",
23+
"title": "2 task notice all",
24+
"description": "2 task notice all description",
25+
"type": "announce",
26+
"params": {
27+
"status": "warning",
28+
"isTemplate": true
29+
}
30+
},
31+
{
32+
"userId": "6e6ed89f-637f-4fd6-86c2-95ef706cacf3",
33+
"title": "3 task notice all",
34+
"description": "3 task notice all description",
35+
"type": "announce",
36+
"params": {
37+
"status": "warning",
38+
"isTemplate": true
39+
}
40+
}
41+
]
42+
}
43+
}
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
### Step 1.1 Create notice all task
2+
POST http://127.0.0.1:8001/ms/notification
3+
Accept: application/json
4+
Content-Type: application/json
5+
6+
{
7+
"id": "1",
8+
"method": "task.create",
9+
"params": {
10+
"fields": {
11+
"type": "noticeAll",
12+
"notices": [
13+
{
14+
"title": "1 task notice all",
15+
"description": "1 task notice all description",
16+
"type": "announce",
17+
"params": {
18+
"status": "warning",
19+
"isTemplate": true
20+
}
21+
}
22+
]
23+
}
24+
}
25+
}
26+
27+
### Step 1.2. Create email all task
28+
POST http://127.0.0.1:8001/ms/notification
29+
Accept: application/json
30+
Content-Type: application/json
31+
32+
{
33+
"id": "1",
34+
"method": "task.create",
35+
"params": {
36+
"fields": {
37+
"type": "emailAll",
38+
"messages": [
39+
{
40+
"html": "<p>1 task email all</p>",
41+
"subject": "1 task email all subject",
42+
"text": "1 task email all text",
43+
"type": "email",
44+
"params": {
45+
"isTemplate": true
46+
}
47+
}
48+
]
49+
}
50+
}
51+
}
52+
53+
### Step 1.3. Create email all task with full check up mode
54+
POST http://127.0.0.1:8001/ms/notification
55+
Accept: application/json
56+
Content-Type: application/json
57+
58+
{
59+
"id": "1",
60+
"method": "task.create",
61+
"params": {
62+
"fields": {
63+
"type": "emailAll",
64+
"mode": "fullCheckUp",
65+
"messages": [
66+
{
67+
"html": "<p>1 task email all</p>",
68+
"subject": "1 task email all subject",
69+
"text": "1 task email all text",
70+
"type": "email",
71+
"params": {
72+
"isTemplate": true
73+
}
74+
}
75+
]
76+
}
77+
}
78+
}
79+
80+
### Step 1.4. Create email group task
81+
POST http://127.0.0.1:8001/ms/notification
82+
Accept: application/json
83+
Content-Type: application/json
84+
85+
{
86+
"id": "1",
87+
"method": "task.create",
88+
"params": {
89+
"fields": {
90+
"type": "emailGroup",
91+
"messages": [
92+
{
93+
"html": "<p>1 task email all</p>",
94+
"subject": "1 task email all subject",
95+
"text": "1 task email all text",
96+
"type": "email",
97+
"params": {
98+
"isTemplate": true
99+
}
100+
}
101+
],
102+
"recipients": [
103+
{
104+
"userId": "7bf97098-c84e-4b41-a8d8-0c628b957ff3"
105+
},
106+
{
107+
"userId": "5b86356f-bea2-469b-8a82-7566f369a1e0"
108+
},
109+
{
110+
"userId": "6e6ed89f-637f-4fd6-86c2-95ef706cacf3"
111+
}
112+
]
113+
}
114+
}
115+
}
116+
117+
### Step 2. Execute cron task - task process
118+
POST http://127.0.0.1:8001/ms/notification
119+
Accept: application/json
120+
Content-Type: application/json
121+
122+
{
123+
"id": "1",
124+
"method": "job.task.process",
125+
"params": {
126+
}
127+
}

microservices/authorization/migrations/permissions/list/methods/notification.json

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,95 @@
231231
"createdAt": "2023-09-20T22:49:48.824Z",
232232
"modelOut": "notification.HideAllOutput",
233233
"methodFilters": []
234+
},
235+
{
236+
"microservice": "notification",
237+
"method": "task.count",
238+
"description": "Returns count of Task by given condition",
239+
"allowGroup": [
240+
"admin"
241+
],
242+
"denyGroup": [],
243+
"createdAt": "2023-11-28T08:24:13.755Z",
244+
"modelIn": "CountRequestParams",
245+
"modelOut": "CountOutputParams",
246+
"methodFilters": []
247+
},
248+
{
249+
"microservice": "notification",
250+
"method": "task.list",
251+
"description": "Returns list of Task by given condition",
252+
"allowGroup": [
253+
"admin"
254+
],
255+
"denyGroup": [],
256+
"createdAt": "2023-11-28T08:24:13.755Z",
257+
"modelIn": "ListRequestParams",
258+
"modelOut": "notification.ListOutputParams.bbbcb6cef990d65df49a90e21dec6e66",
259+
"methodFilters": []
260+
},
261+
{
262+
"microservice": "notification",
263+
"method": "task.view",
264+
"description": "Returns Task by given condition",
265+
"allowGroup": [
266+
"admin"
267+
],
268+
"denyGroup": [],
269+
"createdAt": "2023-11-28T08:24:13.755Z",
270+
"modelIn": "ViewRequestParams",
271+
"modelOut": "notification.ViewOutputParams.6cc49e5e15754ec8fd6013ccc05489d9",
272+
"methodFilters": []
273+
},
274+
{
275+
"microservice": "notification",
276+
"method": "task.create",
277+
"description": "Create a new Task",
278+
"allowGroup": [
279+
"admin"
280+
],
281+
"denyGroup": [],
282+
"createdAt": "2023-11-28T08:24:13.755Z",
283+
"modelIn": "notification.CreateRequestParams.540b18ddac00a8a1654f4d3704c482bc",
284+
"modelOut": "notification.CreateOutputParams.6cc49e5e15754ec8fd6013ccc05489d9",
285+
"methodFilters": []
286+
},
287+
{
288+
"microservice": "notification",
289+
"method": "task.update",
290+
"description": "Update Task by given condition",
291+
"allowGroup": [
292+
"admin"
293+
],
294+
"denyGroup": [],
295+
"createdAt": "2023-11-28T08:24:13.755Z",
296+
"modelIn": "notification.UpdateRequestParams.540b18ddac00a8a1654f4d3704c482bc",
297+
"modelOut": "notification.UpdateOutputParams.6cc49e5e15754ec8fd6013ccc05489d9",
298+
"methodFilters": []
299+
},
300+
{
301+
"microservice": "notification",
302+
"method": "task.remove",
303+
"description": "Remove Task by given condition",
304+
"allowGroup": [
305+
"admin"
306+
],
307+
"denyGroup": [],
308+
"createdAt": "2023-11-28T08:24:13.755Z",
309+
"modelIn": "RemoveRequestParams",
310+
"modelOut": "notification.RemoveOutputParams.76da26644ee5b1db84b77f612d3aed27",
311+
"methodFilters": []
312+
},
313+
{
314+
"microservice": "notification",
315+
"method": "job.task.process",
316+
"description": "Process tasks",
317+
"allowGroup": [
318+
"admin"
319+
],
320+
"denyGroup": [],
321+
"createdAt": "2023-11-28T08:24:13.755Z",
322+
"modelOut": "notification.ProcessOutput",
323+
"methodFilters": []
234324
}
235325
]

0 commit comments

Comments
 (0)