@ikonintegration/ikapi 4.0.1 → 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.
Files changed (236) hide show
  1. package/.eslintignore +3 -0
  2. package/.eslintrc.cjs +81 -0
  3. package/.github/workflows/npmpublish.yml +8 -19
  4. package/.github/workflows/prs.yml +12 -0
  5. package/README.md +89 -99
  6. package/dist/index.d.ts +16 -0
  7. package/dist/index.js +27 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/package-lock.json +11881 -0
  10. package/dist/package.json +81 -0
  11. package/dist/src/API/Request.d.ts +125 -0
  12. package/dist/src/API/Request.js +185 -0
  13. package/dist/src/API/Request.js.map +1 -0
  14. package/dist/src/API/Response.d.ts +188 -0
  15. package/dist/src/API/Response.js +270 -0
  16. package/dist/src/API/Response.js.map +1 -0
  17. package/dist/src/BaseEvent/DynamoTransaction.d.ts +70 -0
  18. package/dist/src/BaseEvent/DynamoTransaction.js +104 -0
  19. package/dist/src/BaseEvent/DynamoTransaction.js.map +1 -0
  20. package/dist/src/BaseEvent/EventProcessor.d.ts +58 -0
  21. package/dist/src/BaseEvent/EventProcessor.js +101 -0
  22. package/dist/src/BaseEvent/EventProcessor.js.map +1 -0
  23. package/dist/src/BaseEvent/Process.d.ts +50 -0
  24. package/dist/src/BaseEvent/Process.js +64 -0
  25. package/dist/src/BaseEvent/Process.js.map +1 -0
  26. package/dist/src/BaseEvent/StepTransaction.d.ts +23 -0
  27. package/dist/src/BaseEvent/StepTransaction.js +27 -0
  28. package/dist/src/BaseEvent/StepTransaction.js.map +1 -0
  29. package/dist/src/BaseEvent/Transaction.d.ts +149 -0
  30. package/dist/src/BaseEvent/Transaction.js +224 -0
  31. package/dist/src/BaseEvent/Transaction.js.map +1 -0
  32. package/dist/src/Cache/Redis.d.ts +29 -0
  33. package/dist/src/Cache/Redis.js +80 -0
  34. package/dist/src/Cache/Redis.js.map +1 -0
  35. package/dist/src/Cache/types.d.ts +31 -0
  36. package/dist/src/Cache/types.js +2 -0
  37. package/dist/src/Cache/types.js.map +1 -0
  38. package/dist/src/Config/Configuration.d.ts +123 -0
  39. package/dist/src/Config/Configuration.js +109 -0
  40. package/dist/src/Config/Configuration.js.map +1 -0
  41. package/dist/src/Config/EnvironmentVar.d.ts +74 -0
  42. package/dist/src/Config/EnvironmentVar.js +138 -0
  43. package/dist/src/Config/EnvironmentVar.js.map +1 -0
  44. package/dist/src/Crypto/Crypto.d.ts +45 -0
  45. package/dist/src/Crypto/Crypto.js +72 -0
  46. package/dist/src/Crypto/Crypto.js.map +1 -0
  47. package/dist/src/Database/Database.d.ts +21 -0
  48. package/dist/src/Database/Database.js +15 -0
  49. package/dist/src/Database/Database.js.map +1 -0
  50. package/dist/src/Database/DatabaseManager.d.ts +47 -0
  51. package/dist/src/Database/DatabaseManager.js +60 -0
  52. package/dist/src/Database/DatabaseManager.js.map +1 -0
  53. package/dist/src/Database/DatabaseTransaction.d.ts +101 -0
  54. package/dist/src/Database/DatabaseTransaction.js +126 -0
  55. package/dist/src/Database/DatabaseTransaction.js.map +1 -0
  56. package/dist/src/Database/index.d.ts +10 -0
  57. package/dist/src/Database/index.js +15 -0
  58. package/dist/src/Database/index.js.map +1 -0
  59. package/dist/src/Database/integrations/dynamo/DynamoDatabase.d.ts +35 -0
  60. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js +59 -0
  61. package/dist/src/Database/integrations/dynamo/DynamoDatabase.js.map +1 -0
  62. package/dist/src/Database/integrations/kysely/KyselyDatabase.d.ts +66 -0
  63. package/dist/src/Database/integrations/kysely/KyselyDatabase.js +86 -0
  64. package/dist/src/Database/integrations/kysely/KyselyDatabase.js.map +1 -0
  65. package/dist/src/Database/integrations/kysely/KyselyTransaction.d.ts +70 -0
  66. package/dist/src/Database/integrations/kysely/KyselyTransaction.js +118 -0
  67. package/dist/src/Database/integrations/kysely/KyselyTransaction.js.map +1 -0
  68. package/dist/src/Database/integrations/pgsql/PostgresDatabase.d.ts +36 -0
  69. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js +54 -0
  70. package/dist/src/Database/integrations/pgsql/PostgresDatabase.js.map +1 -0
  71. package/dist/src/Database/integrations/pgsql/PostgresTransaction.d.ts +63 -0
  72. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js +61 -0
  73. package/dist/src/Database/integrations/pgsql/PostgresTransaction.js.map +1 -0
  74. package/dist/src/Database/types.d.ts +76 -0
  75. package/dist/src/Database/types.js +2 -0
  76. package/dist/src/Database/types.js.map +1 -0
  77. package/dist/src/Globals.d.ts +93 -0
  78. package/dist/src/Globals.js +99 -0
  79. package/dist/src/Globals.js.map +1 -0
  80. package/dist/src/Logger/Logger.d.ts +161 -0
  81. package/dist/src/Logger/Logger.js +299 -0
  82. package/dist/src/Logger/Logger.js.map +1 -0
  83. package/dist/src/Mailer/Mailer.d.ts +78 -0
  84. package/dist/src/Mailer/Mailer.js +182 -0
  85. package/dist/src/Mailer/Mailer.js.map +1 -0
  86. package/dist/src/Publisher/Publisher.d.ts +39 -0
  87. package/dist/src/Publisher/Publisher.js +77 -0
  88. package/dist/src/Publisher/Publisher.js.map +1 -0
  89. package/dist/src/Server/RouteResolver.d.ts +33 -0
  90. package/dist/src/Server/RouteResolver.js +100 -0
  91. package/dist/src/Server/RouteResolver.js.map +1 -0
  92. package/dist/src/Server/Router.d.ts +157 -0
  93. package/dist/src/Server/Router.js +32 -0
  94. package/dist/src/Server/Router.js.map +1 -0
  95. package/dist/src/Server/lib/ContainerServer.d.ts +42 -0
  96. package/dist/src/Server/lib/ContainerServer.js +66 -0
  97. package/dist/src/Server/lib/ContainerServer.js.map +1 -0
  98. package/dist/src/Server/lib/Server.d.ts +45 -0
  99. package/dist/src/Server/lib/Server.js +93 -0
  100. package/dist/src/Server/lib/Server.js.map +1 -0
  101. package/dist/src/Server/lib/container/GenericHandler.d.ts +9 -0
  102. package/dist/src/Server/lib/container/GenericHandler.js +82 -0
  103. package/dist/src/Server/lib/container/GenericHandler.js.map +1 -0
  104. package/dist/src/Server/lib/container/GenericHandlerEvent.d.ts +52 -0
  105. package/dist/src/Server/lib/container/GenericHandlerEvent.js +132 -0
  106. package/dist/src/Server/lib/container/GenericHandlerEvent.js.map +1 -0
  107. package/dist/src/Server/lib/container/HealthHandler.d.ts +9 -0
  108. package/dist/src/Server/lib/container/HealthHandler.js +19 -0
  109. package/dist/src/Server/lib/container/HealthHandler.js.map +1 -0
  110. package/dist/src/Server/lib/container/Proxy.d.ts +67 -0
  111. package/dist/src/Server/lib/container/Proxy.js +143 -0
  112. package/dist/src/Server/lib/container/Proxy.js.map +1 -0
  113. package/dist/src/Server/lib/container/Utils.d.ts +14 -0
  114. package/dist/src/Server/lib/container/Utils.js +37 -0
  115. package/dist/src/Server/lib/container/Utils.js.map +1 -0
  116. package/dist/src/Util/AsyncSingleton.d.ts +31 -0
  117. package/dist/src/Util/AsyncSingleton.js +83 -0
  118. package/dist/src/Util/AsyncSingleton.js.map +1 -0
  119. package/dist/src/Util/Utils.d.ts +61 -0
  120. package/dist/src/Util/Utils.js +147 -0
  121. package/dist/src/Util/Utils.js.map +1 -0
  122. package/dist/src/Validation/Validator.d.ts +17 -0
  123. package/dist/src/Validation/Validator.js +39 -0
  124. package/dist/src/Validation/Validator.js.map +1 -0
  125. package/dist/tsconfig.tsbuildinfo +1 -0
  126. package/index.ts +41 -0
  127. package/jest.config.ts +37 -0
  128. package/jest.smoke.config.ts +34 -0
  129. package/package.json +66 -22
  130. package/src/API/Request.ts +214 -0
  131. package/src/API/Response.ts +370 -0
  132. package/src/BaseEvent/DynamoTransaction.ts +175 -0
  133. package/src/BaseEvent/EventProcessor.ts +140 -0
  134. package/src/BaseEvent/Process.ts +78 -0
  135. package/src/BaseEvent/StepTransaction.ts +35 -0
  136. package/src/BaseEvent/Transaction.ts +323 -0
  137. package/src/Cache/Redis.ts +89 -0
  138. package/src/Cache/types.ts +33 -0
  139. package/src/Config/Configuration.ts +199 -0
  140. package/src/Config/EnvironmentVar.ts +142 -0
  141. package/src/Crypto/Crypto.ts +89 -0
  142. package/src/Database/Database.ts +22 -0
  143. package/src/Database/DatabaseManager.ts +67 -0
  144. package/src/Database/DatabaseTransaction.ts +170 -0
  145. package/src/Database/index.ts +27 -0
  146. package/src/Database/integrations/dynamo/DynamoDatabase.ts +58 -0
  147. package/src/Database/integrations/kysely/KyselyDatabase.ts +99 -0
  148. package/src/Database/integrations/kysely/KyselyTransaction.ts +172 -0
  149. package/src/Database/integrations/pgsql/PostgresDatabase.ts +56 -0
  150. package/src/Database/integrations/pgsql/PostgresTransaction.ts +87 -0
  151. package/src/Database/types.ts +85 -0
  152. package/src/Globals.ts +103 -0
  153. package/src/Logger/Logger.ts +363 -0
  154. package/src/Mailer/Mailer.ts +217 -0
  155. package/src/Publisher/Publisher.ts +96 -0
  156. package/src/Server/RouteResolver.ts +124 -0
  157. package/src/Server/Router.ts +200 -0
  158. package/src/Server/lib/ContainerServer.ts +65 -0
  159. package/src/Server/lib/Server.ts +109 -0
  160. package/src/Server/lib/container/GenericHandler.ts +76 -0
  161. package/src/Server/lib/container/GenericHandlerEvent.ts +154 -0
  162. package/src/Server/lib/container/HealthHandler.ts +11 -0
  163. package/src/Server/lib/container/Proxy.ts +172 -0
  164. package/src/Server/lib/container/Utils.ts +33 -0
  165. package/src/Util/AsyncSingleton.ts +86 -0
  166. package/src/Util/Utils.ts +131 -0
  167. package/src/Validation/Validator.ts +45 -0
  168. package/tests/API/Request.test.ts +273 -0
  169. package/tests/API/Response.test.ts +367 -0
  170. package/tests/BaseEvent/DynamoTransaction.test.ts +272 -0
  171. package/tests/BaseEvent/EventProcessor.test.ts +263 -0
  172. package/tests/BaseEvent/Process.test.ts +47 -0
  173. package/tests/BaseEvent/StepTransaction.test.ts +44 -0
  174. package/tests/BaseEvent/Transaction.test.ts +402 -0
  175. package/tests/Cache/Redis-client.test.ts +90 -0
  176. package/tests/Cache/Redis-cluster.test.ts +100 -0
  177. package/tests/Config/Config.test.ts +205 -0
  178. package/tests/Config/EnvironmentVar.test.ts +251 -0
  179. package/tests/Crypto/Crypto.test.ts +88 -0
  180. package/tests/Database/DatabaseManager.test.ts +79 -0
  181. package/tests/Database/integrations/dynamo/DynamoDatabase.test.ts +44 -0
  182. package/tests/Database/integrations/kysely/KyselyDatabase.test.ts +113 -0
  183. package/tests/Database/integrations/kysely/KyselyTransaction.test.ts +119 -0
  184. package/tests/Database/integrations/pg/PostgresDatabase.test.ts +76 -0
  185. package/tests/Database/integrations/pg/PostgresTransaction.test.ts +118 -0
  186. package/tests/Logger/Logger.test.ts +215 -0
  187. package/tests/Mailer/Mailer.test.ts +59 -0
  188. package/tests/Publisher/Publisher.test.ts +60 -0
  189. package/tests/Server/RouteResolver.test.ts +116 -0
  190. package/tests/Server/Router.test.ts +39 -0
  191. package/tests/Server/lib/ContainerServer.test.ts +531 -0
  192. package/tests/Server/lib/Server.test.ts +12 -0
  193. package/tests/Server/lib/container/GenericHandler.test.ts +131 -0
  194. package/tests/Server/lib/container/GenericHandlerEvent.test.ts +103 -0
  195. package/tests/Server/lib/container/HealthHandler.test.ts +30 -0
  196. package/tests/Server/lib/container/Proxy.test.ts +268 -0
  197. package/tests/Server/lib/container/Utils.test.ts +47 -0
  198. package/tests/Test.utils.ts +78 -0
  199. package/tests/Utils/Utils.test.ts +229 -0
  200. package/tests/Validation/Validator.test.ts +82 -0
  201. package/tsconfig.json +26 -0
  202. package/tsconfig.smoke.json +26 -0
  203. package/index.js +0 -88
  204. package/src/API/IKRequest.js +0 -52
  205. package/src/API/IKResponse.js +0 -119
  206. package/src/API/IKUtils.js +0 -51
  207. package/src/BaseEvent/IKProcess.js +0 -77
  208. package/src/BaseEvent/IKTransaction.js +0 -139
  209. package/src/Cache/Prototype/IKCache.js +0 -17
  210. package/src/Cache/Redis/IKRedis.js +0 -148
  211. package/src/Database/DDB/IKDB.js +0 -56
  212. package/src/Database/DDB/IKDBBaseExpression.js +0 -130
  213. package/src/Database/DDB/IKDBBaseQuery.js +0 -151
  214. package/src/Database/DDB/IKDBQueryBatchGet.js +0 -37
  215. package/src/Database/DDB/IKDBQueryBatchWrite.js +0 -64
  216. package/src/Database/DDB/IKDBQueryDelete.js +0 -34
  217. package/src/Database/DDB/IKDBQueryGet.js +0 -48
  218. package/src/Database/DDB/IKDBQueryPut.js +0 -87
  219. package/src/Database/DDB/IKDBQueryScan.js +0 -45
  220. package/src/Database/DDB/IKDBQueryTransactionalWrite.js +0 -69
  221. package/src/Database/DDB/IKDBQueryUpdate.js +0 -221
  222. package/src/Database/DDB/_IKDBQueryTransactionalRead.js +0 -46
  223. package/src/Database/PSQL/IKDB.js +0 -41
  224. package/src/Database/PSQL/IKDBBaseQuery.js +0 -26
  225. package/src/Database/Prototype/IKDB.js +0 -21
  226. package/src/Database/Prototype/IKDBBaseQuery.js +0 -14
  227. package/src/IKDynamoStream.js +0 -42
  228. package/src/IKEventProcessor.js +0 -42
  229. package/src/IKGlobals.js +0 -24
  230. package/src/IKRouter.js +0 -47
  231. package/src/IKStepTransaction.js +0 -14
  232. package/src/Logger/IKLogger.js +0 -136
  233. package/src/Mailer/IKMailer.js +0 -69
  234. package/src/Publisher/IKPublisher.js +0 -44
  235. package/src/Tracker/IKExecutionTracker.js +0 -79
  236. package/src/Validation/IKValidation.js +0 -76
package/.eslintignore ADDED
@@ -0,0 +1,3 @@
1
+ node_modules
2
+ dist
3
+ smoke-tests
package/.eslintrc.cjs ADDED
@@ -0,0 +1,81 @@
1
+ /* eslint-env node */
2
+ module.exports = {
3
+ extends: [
4
+ 'eslint:recommended',
5
+ 'plugin:@typescript-eslint/recommended',
6
+ 'plugin:prettier/recommended',
7
+ 'plugin:import/recommended',
8
+ 'plugin:import/typescript',
9
+ 'plugin:require-extensions/recommended',
10
+ ],
11
+ parser: '@typescript-eslint/parser',
12
+ plugins: ['@typescript-eslint', 'prettier', 'require-extensions'],
13
+ root: true,
14
+ rules: {
15
+ 'import/extensions': ['error', 'always'],
16
+ 'prettier/prettier': [
17
+ 'error',
18
+ {
19
+ tabWidth: 2,
20
+ useTabs: false,
21
+ bracketSameLine: false,
22
+ semi: false,
23
+ arrowParens: 'avoid',
24
+ jsxSingleQuote: true,
25
+ printWidth: 100,
26
+ singleQuote: true,
27
+ quoteProps: 'as-needed',
28
+ htmlWhitespaceSensitivity: 'css',
29
+ proseWrap: 'preserve',
30
+ bracketSpacing: true,
31
+ embeddedLanguageFormatting: 'auto',
32
+ endOfLine: 'lf',
33
+ trailingComma: 'es5',
34
+ },
35
+ ],
36
+ '@typescript-eslint/ban-ts-comment': 0,
37
+ '@typescript-eslint/no-explicit-any': 0,
38
+ '@typescript-eslint/explicit-member-accessibility': [
39
+ 'error',
40
+ {
41
+ accessibility: 'explicit',
42
+ overrides: {
43
+ accessors: 'explicit',
44
+ constructors: 'no-public',
45
+ methods: 'explicit',
46
+ properties: 'explicit',
47
+ parameterProperties: 'explicit',
48
+ },
49
+ },
50
+ ],
51
+ 'lines-between-class-members': [
52
+ 'error',
53
+ {
54
+ enforce: [{ blankLine: 'always', prev: 'method', next: 'method' }],
55
+ },
56
+ ],
57
+ // turn on errors for missing imports
58
+ 'import/no-unresolved': ['error', { ignore: ['\\.js$'] }],
59
+ // 'import/no-named-as-default-member': 'off',
60
+ 'import/order': [
61
+ 'error',
62
+ {
63
+ groups: [
64
+ 'builtin', // Built-in imports (come from NodeJS native) go first
65
+ 'external', // <- External imports
66
+ 'internal', // <- Absolute imports
67
+ ['sibling', 'parent'], // <- Relative imports, the sibling and parent types they can be mingled together
68
+ 'index', // <- index imports
69
+ 'unknown', // <- unknown
70
+ ],
71
+ 'newlines-between': 'always',
72
+ alphabetize: {
73
+ /* sort in ascending order. Options: ["ignore", "asc", "desc"] */
74
+ order: 'asc',
75
+ /* ignore case. Options: [true, false] */
76
+ caseInsensitive: true,
77
+ },
78
+ },
79
+ ],
80
+ },
81
+ }
@@ -1,22 +1,11 @@
1
- # This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
2
- # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
3
-
4
- name: Node.js Package
5
-
1
+ name: NPM Publish
6
2
  on:
7
- release:
8
- types: [created]
3
+ push:
4
+ branches: [ "master" ]
9
5
 
10
6
  jobs:
11
- publish-npm:
12
- runs-on: ubuntu-latest
13
- steps:
14
- - uses: actions/checkout@v3
15
- - uses: actions/setup-node@v3
16
- with:
17
- node-version: 18
18
- registry-url: https://registry.npmjs.org/
19
- - run: npm ci
20
- - run: npm publish --access='public'
21
- env:
22
- NODE_AUTH_TOKEN: ${{secrets.npm_token}}
7
+ Publish:
8
+ uses: ikon-integration/tools-github-workflows/.github/workflows/npm-publish.yml@master
9
+ secrets: inherit
10
+ with:
11
+ NODE_VERSION: "20.x"
@@ -0,0 +1,12 @@
1
+ name: PR Checks
2
+ on:
3
+ pull_request:
4
+ branches:
5
+ - master
6
+
7
+ jobs:
8
+ Checks:
9
+ uses: ikon-integration/tools-github-workflows/.github/workflows/prs-check.yml@master
10
+ secrets: inherit
11
+ with:
12
+ NODE_VERSION: "20.x"
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
  ```
@@ -0,0 +1,16 @@
1
+ import { HttpMethod } from './src/API/Request.js';
2
+ import Response, { ResponseErrorType } from './src/API/Response.js';
3
+ import DynamoTransaction from './src/BaseEvent/DynamoTransaction.js';
4
+ import EventProcessor from './src/BaseEvent/EventProcessor.js';
5
+ import Process from './src/BaseEvent/Process.js';
6
+ import StepTransaction from './src/BaseEvent/StepTransaction.js';
7
+ import Transaction, { TransactionConfig } from './src/BaseEvent/Transaction.js';
8
+ import Redis from './src/Cache/Redis.js';
9
+ import Configuration from './src/Config/Configuration.js';
10
+ import Crypto from './src/Crypto/Crypto.js';
11
+ import * as Database from './src/Database/index.js';
12
+ import Mailer from './src/Mailer/Mailer.js';
13
+ import Router, { Route } from './src/Server/Router.js';
14
+ import AsyncSingleton from './src/Util/AsyncSingleton.js';
15
+ import Utils from './src/Util/Utils.js';
16
+ export { Transaction, Process, EventProcessor, DynamoTransaction, StepTransaction, Router, Route, HttpMethod, Mailer, Crypto, Configuration, Redis, Database, Response, ResponseErrorType, Utils, AsyncSingleton, TransactionConfig, };
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ import { HttpMethod } from './src/API/Request.js';
2
+ import Response from './src/API/Response.js';
3
+ import DynamoTransaction from './src/BaseEvent/DynamoTransaction.js';
4
+ import EventProcessor from './src/BaseEvent/EventProcessor.js';
5
+ import Process from './src/BaseEvent/Process.js';
6
+ import StepTransaction from './src/BaseEvent/StepTransaction.js';
7
+ import Transaction from './src/BaseEvent/Transaction.js';
8
+ import Redis from './src/Cache/Redis.js';
9
+ import Configuration from './src/Config/Configuration.js';
10
+ import Crypto from './src/Crypto/Crypto.js';
11
+ import * as Database from './src/Database/index.js';
12
+ import Mailer from './src/Mailer/Mailer.js';
13
+ import Router from './src/Server/Router.js';
14
+ import AsyncSingleton from './src/Util/AsyncSingleton.js';
15
+ import Utils from './src/Util/Utils.js';
16
+ export {
17
+ // Base Events
18
+ Transaction, Process, EventProcessor, DynamoTransaction, StepTransaction,
19
+ // Http
20
+ Router, HttpMethod,
21
+ // Modules
22
+ Mailer, Crypto, Configuration, Redis, Database,
23
+ // API
24
+ Response,
25
+ // Helpers
26
+ Utils, AsyncSingleton, };
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,OAAO,QAA+B,MAAM,uBAAuB,CAAA;AACnE,OAAO,iBAAiB,MAAM,sCAAsC,CAAA;AACpE,OAAO,cAAc,MAAM,mCAAmC,CAAA;AAC9D,OAAO,OAAO,MAAM,4BAA4B,CAAA;AAChD,OAAO,eAAe,MAAM,oCAAoC,CAAA;AAChE,OAAO,WAAkC,MAAM,gCAAgC,CAAA;AAC/E,OAAO,KAAK,MAAM,sBAAsB,CAAA;AACxC,OAAO,aAAa,MAAM,+BAA+B,CAAA;AACzD,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAC3C,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAA;AACnD,OAAO,MAAM,MAAM,wBAAwB,CAAA;AAC3C,OAAO,MAAiB,MAAM,wBAAwB,CAAA;AACtD,OAAO,cAAc,MAAM,8BAA8B,CAAA;AACzD,OAAO,KAAK,MAAM,qBAAqB,CAAA;AAEvC,OAAO;AACL,cAAc;AACd,WAAW,EACX,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,eAAe;AACf,OAAO;AACP,MAAM,EAEN,UAAU;AACV,UAAU;AACV,MAAM,EACN,MAAM,EACN,aAAa,EACb,KAAK,EACL,QAAQ;AACR,MAAM;AACN,QAAQ;AAER,UAAU;AACV,KAAK,EACL,cAAc,GAEf,CAAA"}