@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 CHANGED
@@ -1,6 +1,7 @@
1
1
  # IKApi ![Node.js Package](https://github.com/ikon-integration/IKApi/workflows/Node.js%20Package/badge.svg)
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 * as Config from './routes/tenant/config.js';
17
+ ```
18
+ import { Router } from '@ikonintegration/ikapi';
19
+ import HealthCheck from './routes/health/get';
18
20
 
19
21
  const routes = [
20
- { route: '/tenant/config', method: 'GET', handler: Config.get },
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
- const mailer = new IKAPI.IKMailer(LMCoreGlobals.SESSender, LMCoreGlobals.SESRegion);
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
- - Process
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
- - Event Process (Queue/SQS)
40
+ - Route
87
41
 
88
42
  ```
89
- //Main handler
90
- export const handler = async (event, context) => {
91
- //Start event processor, if any event failed, execution will stop!
92
- await (new IKAPI.IKEventProcessor(event, context, Docket.Globals.API_Config)).processEvent( async (transaction, recordContent) => {
93
- //init authorization
94
- return await (new Docket.Core(transaction, Docket.Globals.AccessLevel.ANY)).authenticate(async (core) => {
95
- core.queue.publishOnTopic(event, Docket.Globals.SNSTopic_ExtractorNotification);
96
- return IKAPI.IKSuccessResponse();
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
- //Start event processor, if any event failed, execution will stop!
108
- await (new IKAPI.IKTransaction(event, context, Docket.Globals.API_Config)).execute( async (transaction) => {
109
- //init authorization
110
- return await (new Docket.Core(transaction, Docket.Globals.AccessLevel.ANY)).authenticate(async (core) => {
111
- const queue = event.queue;
112
- //Get from specified queue
113
- if (!queue) throw new Error(`Empty queue URL! - ${queue}`);
114
- //Success :)
115
- return IKAPI.IKSuccessResponse();
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
- - Dynamo Streams
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
- //Start event processor, if any event failed, execution will stop!
127
- await (new IKAPI.IKDynamoStream(event, context, Docket.Globals.API_Config)).processEvent( async (transaction, recordContent) => {
128
- //Check if is deletion
129
- if (!_isDynamoDeletion(recordContent)) return (new IKAPI.IKSuccessNoContentResponse());
130
- //init authorization
131
- return await (new Docket.Core(transaction, Docket.Globals.AccessLevel.ANY)).authenticate(async (core) => {
132
- return IKAPI.IKSuccessResponse();
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
  ```