@ikonintegration/ikapi 5.0.0-alpha1 → 5.0.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.
- package/README.md +89 -99
- package/dist/package-lock.json +818 -823
- package/dist/package.json +20 -20
- package/dist/src/BaseEvent/DynamoTransaction.d.ts +50 -0
- package/dist/src/BaseEvent/DynamoTransaction.js +23 -0
- package/dist/src/BaseEvent/DynamoTransaction.js.map +1 -1
- package/dist/src/Config/EnvironmentVar.js.map +1 -1
- package/dist/src/Logger/Logger.js +4 -2
- package/dist/src/Logger/Logger.js.map +1 -1
- package/dist/src/Server/lib/Server.js +1 -1
- package/dist/src/Server/lib/Server.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +20 -20
- package/src/BaseEvent/DynamoTransaction.ts +50 -0
- package/src/Config/EnvironmentVar.ts +1 -6
- package/src/Logger/Logger.ts +5 -2
- package/src/Server/lib/Server.ts +1 -1
- package/tests/Utils/Utils.test.ts +2 -3
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# IKApi 
|
|
2
2
|
Ikon nodejs API foundation
|
|
3
3
|
|
|
4
|
+
[Docs](https://ikon-integration.github.io/ikapi/)
|
|
4
5
|
|
|
5
6
|
### Overall
|
|
6
7
|
|
|
@@ -13,124 +14,113 @@ Ikon nodejs API foundation
|
|
|
13
14
|
|
|
14
15
|
- Router
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
import
|
|
17
|
+
```
|
|
18
|
+
import { Router } from '@ikonintegration/ikapi';
|
|
19
|
+
import HealthCheck from './routes/health/get';
|
|
18
20
|
|
|
19
21
|
const routes = [
|
|
20
|
-
{ route: '/
|
|
22
|
+
{ route: '/health', method: 'GET', handler: HealthCheck.handler },
|
|
23
|
+
// Additional routes can be added here
|
|
21
24
|
];
|
|
22
|
-
//Main handler
|
|
23
|
-
export const handler = async (event, context) => {
|
|
24
|
-
(await (new IKAPI.IKRouter(routes, {
|
|
25
|
-
database: {
|
|
26
|
-
type: 'DDB | SQL', -- fallback to DDB if not set
|
|
27
|
-
//DDB Specific
|
|
28
|
-
region: IBEWCoreGlobals.DatabaseRegion,
|
|
29
|
-
tableName: IBEWCoreGlobals.DatabaseTableName,
|
|
30
|
-
//SQL Specific
|
|
31
|
-
host: '127.0.0.1', database: 'DB',
|
|
32
|
-
port: 3307, user: 'root', password: 'IDK'
|
|
33
|
-
},
|
|
34
|
-
//Cache
|
|
35
|
-
cache: {
|
|
36
|
-
type: 'REDIS',
|
|
37
|
-
host: '127.0.0.1',
|
|
38
|
-
password: '22P',
|
|
39
|
-
user: '22U',
|
|
40
|
-
enableTLS: true,
|
|
41
|
-
},
|
|
42
|
-
//IKValidator
|
|
43
|
-
validation: {
|
|
44
|
-
additionalTypes: { TYPE: (val) => { return validate(val); } }
|
|
45
|
-
},
|
|
46
|
-
//Logger
|
|
47
|
-
logger: {
|
|
48
|
-
//takes precende over process.env.LOG_LEVEL
|
|
49
|
-
level: 'DEBUG' | 'INFO' | 'WARN' | 'ERROR',
|
|
50
|
-
enableSensitiveFiltering: false, //defaults to false
|
|
51
|
-
sensitiveFilteringKeywords: [], //replaced default blacklist set
|
|
52
|
-
},
|
|
53
|
-
//Queue
|
|
54
|
-
publisher: { region: 'SNS-REGION' },
|
|
55
|
-
//Resources tracker
|
|
56
|
-
resourcesTracker: { //by default, it will auto track (lambda, ecs, ddb)
|
|
57
|
-
busName: 'busName',
|
|
58
|
-
region: 'region',
|
|
59
|
-
appName: 'appName',
|
|
60
|
-
}
|
|
61
|
-
};)).handleEvent(event, context));
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
- Mailer
|
|
66
25
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
26
|
+
export const router = new Router({
|
|
27
|
+
routes,
|
|
28
|
+
healthCheckRoute: '/otherHealth',
|
|
29
|
+
logger: {
|
|
30
|
+
logLevel: 'DEBUG', // or process.env.LOG_LEVEL
|
|
31
|
+
sensitiveFilteringKeywords: ['password', 'secret'],
|
|
32
|
+
},
|
|
33
|
+
});
|
|
70
34
|
|
|
71
|
-
|
|
35
|
+
// Handler export
|
|
36
|
+
export const handler = router.getExport();
|
|
72
37
|
|
|
73
|
-
```
|
|
74
|
-
export const main = async () => {
|
|
75
|
-
const interval = (Docket.Globals.ExtractorPollerInterval * 1000);
|
|
76
|
-
console.debug('Using interval of', interval);
|
|
77
|
-
//init authorization
|
|
78
|
-
await (new Docket.Core({}, Docket.Globals.AccessLevel.ANY)).authenticate(async (core) => {
|
|
79
|
-
await (new IKAPI.IKProcess(Docket.Globals.API_Config, interval)).execute( async (process) => {
|
|
80
|
-
await pull(core);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
38
|
```
|
|
85
39
|
|
|
86
|
-
-
|
|
40
|
+
- Route
|
|
87
41
|
|
|
88
42
|
```
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
43
|
+
import { Response, Route, HttpMethod } from '@ikonintegration/ikapi';
|
|
44
|
+
|
|
45
|
+
interface GetHealthRoute extends Route<null, { message: string }> {}
|
|
46
|
+
|
|
47
|
+
export default class HealthCheck implements GetHealthRoute {
|
|
48
|
+
public path: string = '/health';
|
|
49
|
+
public method: HttpMethod = HttpMethod.GET;
|
|
50
|
+
public openApi = {
|
|
51
|
+
summary: 'System health check',
|
|
52
|
+
description: 'Returns if the system is healthy or not',
|
|
53
|
+
tags: ['Health'],
|
|
54
|
+
security: [],
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
public handler: GetHealthRoute['handler'] = async () => {
|
|
58
|
+
return new Response({ message: 'System is healthy' });
|
|
59
|
+
};
|
|
60
|
+
}
|
|
100
61
|
```
|
|
101
62
|
|
|
63
|
+
|
|
102
64
|
- Transaction
|
|
103
65
|
|
|
104
66
|
```
|
|
67
|
+
import { Response, ResponseErrorType, Transaction } from '@ikonintegration/ikapi'
|
|
68
|
+
import type { Context, SQSEvent } from 'aws-lambda'
|
|
69
|
+
|
|
70
|
+
import Core from '../core/Core.js'
|
|
71
|
+
import Globals, { AccessLevel } from '../core/Globals.js'
|
|
72
|
+
|
|
73
|
+
export type SuccessResponseType = { message: string }
|
|
74
|
+
|
|
105
75
|
//Main handler
|
|
106
|
-
export const handler = async (event, context) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
76
|
+
export const handler = async (event: SQSEvent, context: Context): Promise<void> => {
|
|
77
|
+
await new Transaction<null, SuccessResponseType | ResponseErrorType>(
|
|
78
|
+
event,
|
|
79
|
+
context,
|
|
80
|
+
Globals.API_Config
|
|
81
|
+
).execute(async transaction => {
|
|
82
|
+
const type = event['eventType']
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
84
|
+
return await new Core(transaction, AccessLevel.PUBLIC).authenticate(async core => {
|
|
85
|
+
// Schedule
|
|
86
|
+
if (type == 'SCHEDULE_1') {
|
|
87
|
+
/* Schedule more message to SQS?*/
|
|
88
|
+
return Response.SuccessResponse({ message: '213' })
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return Response.BadRequestResponse('No handler for the specified event type!')
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
119
96
|
```
|
|
120
97
|
|
|
121
|
-
-
|
|
98
|
+
- Event Processor (SQS)
|
|
122
99
|
|
|
123
100
|
```
|
|
101
|
+
import { EventProcessor, Response } from '@ikonintegration/ikapi'
|
|
102
|
+
import type { Context, SQSEvent } from 'aws-lambda'
|
|
103
|
+
|
|
104
|
+
import Core from '../core/Core.js'
|
|
105
|
+
import Globals, { AccessLevel } from '../core/Globals.js'
|
|
106
|
+
|
|
107
|
+
export type SuccessResponseType = { message: string }
|
|
108
|
+
|
|
124
109
|
//Main handler
|
|
125
|
-
export const handler = async (event, context) => {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
110
|
+
export const handler = async (event: SQSEvent, context: Context): Promise<void> => {
|
|
111
|
+
await new EventProcessor<SuccessResponseType | null>(
|
|
112
|
+
event,
|
|
113
|
+
context,
|
|
114
|
+
Globals.API_Config
|
|
115
|
+
).processEvent(async (transaction, recordContent) => {
|
|
116
|
+
const type = event['eventType'] || recordContent?.['eventType']
|
|
117
|
+
return await new Core(transaction, AccessLevel.PUBLIC).authenticate(async core => {
|
|
118
|
+
// Schedule
|
|
119
|
+
if (type == Globals.EmailEventType.TEMPLATE_EMAIL)
|
|
120
|
+
return await templateEmailNotification(recordContent, core)
|
|
121
|
+
|
|
122
|
+
return Response.BadRequestResponse('No handler for the specified event type!')
|
|
123
|
+
})
|
|
124
|
+
})
|
|
125
|
+
}
|
|
136
126
|
```
|