@unito/integration-sdk 0.1.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 (142) hide show
  1. package/.eslintrc.cjs +27 -0
  2. package/.nvmrc +1 -0
  3. package/.prettierignore +2 -0
  4. package/.prettierrc +7 -0
  5. package/LICENSE +3 -0
  6. package/README.md +16 -0
  7. package/dist/src/api/index.d.ts +2 -0
  8. package/dist/src/api/index.d.ts.map +1 -0
  9. package/dist/src/api/index.js +2 -0
  10. package/dist/src/api/index.js.map +1 -0
  11. package/dist/src/app/errors/HTTPError.d.ts +5 -0
  12. package/dist/src/app/errors/HTTPError.d.ts.map +1 -0
  13. package/dist/src/app/errors/HTTPError.js +8 -0
  14. package/dist/src/app/errors/HTTPError.js.map +1 -0
  15. package/dist/src/app/errors/HTTPNotFoundError.d.ts +5 -0
  16. package/dist/src/app/errors/HTTPNotFoundError.d.ts.map +1 -0
  17. package/dist/src/app/errors/HTTPNotFoundError.js +7 -0
  18. package/dist/src/app/errors/HTTPNotFoundError.js.map +1 -0
  19. package/dist/src/app/errors/HTTPUnprocessableEntityError.d.ts +5 -0
  20. package/dist/src/app/errors/HTTPUnprocessableEntityError.d.ts.map +1 -0
  21. package/dist/src/app/errors/HTTPUnprocessableEntityError.js +7 -0
  22. package/dist/src/app/errors/HTTPUnprocessableEntityError.js.map +1 -0
  23. package/dist/src/app/errors/index.d.ts +4 -0
  24. package/dist/src/app/errors/index.d.ts.map +1 -0
  25. package/dist/src/app/errors/index.js +4 -0
  26. package/dist/src/app/errors/index.js.map +1 -0
  27. package/dist/src/app/index.d.ts +6 -0
  28. package/dist/src/app/index.d.ts.map +1 -0
  29. package/dist/src/app/index.js +80 -0
  30. package/dist/src/app/index.js.map +1 -0
  31. package/dist/src/app/integration.d.ts +5 -0
  32. package/dist/src/app/integration.d.ts.map +1 -0
  33. package/dist/src/app/integration.js +86 -0
  34. package/dist/src/app/integration.js.map +1 -0
  35. package/dist/src/app/itemNode.d.ts +8 -0
  36. package/dist/src/app/itemNode.d.ts.map +1 -0
  37. package/dist/src/app/itemNode.js +13 -0
  38. package/dist/src/app/itemNode.js.map +1 -0
  39. package/dist/src/app/middlewares/withCorrelationId.d.ts +11 -0
  40. package/dist/src/app/middlewares/withCorrelationId.d.ts.map +1 -0
  41. package/dist/src/app/middlewares/withCorrelationId.js +8 -0
  42. package/dist/src/app/middlewares/withCorrelationId.js.map +1 -0
  43. package/dist/src/app/middlewares/withLogger.d.ts +12 -0
  44. package/dist/src/app/middlewares/withLogger.d.ts.map +1 -0
  45. package/dist/src/app/middlewares/withLogger.js +18 -0
  46. package/dist/src/app/middlewares/withLogger.js.map +1 -0
  47. package/dist/src/errors.d.ts +15 -0
  48. package/dist/src/errors.js +39 -0
  49. package/dist/src/handler.d.ts +67 -0
  50. package/dist/src/handler.js +224 -0
  51. package/dist/src/httpErrors.d.ts +22 -0
  52. package/dist/src/httpErrors.js +37 -0
  53. package/dist/src/index.d.ts +6 -0
  54. package/dist/src/index.d.ts.map +1 -0
  55. package/dist/src/index.js +6 -0
  56. package/dist/src/index.js.map +1 -0
  57. package/dist/src/integration.d.ts +9 -0
  58. package/dist/src/integration.js +108 -0
  59. package/dist/src/middlewares/correlationId.d.ts +10 -0
  60. package/dist/src/middlewares/correlationId.js +6 -0
  61. package/dist/src/middlewares/credentials.d.ts +11 -0
  62. package/dist/src/middlewares/credentials.js +17 -0
  63. package/dist/src/middlewares/errors.d.ts +3 -0
  64. package/dist/src/middlewares/errors.js +22 -0
  65. package/dist/src/middlewares/filters.d.ts +16 -0
  66. package/dist/src/middlewares/filters.js +25 -0
  67. package/dist/src/middlewares/finish.d.ts +11 -0
  68. package/dist/src/middlewares/finish.js +10 -0
  69. package/dist/src/middlewares/logger.d.ts +12 -0
  70. package/dist/src/middlewares/logger.js +18 -0
  71. package/dist/src/middlewares/notFound.d.ts +3 -0
  72. package/dist/src/middlewares/notFound.js +8 -0
  73. package/dist/src/middlewares/selects.d.ts +10 -0
  74. package/dist/src/middlewares/selects.js +11 -0
  75. package/dist/src/resources/cache.d.ts +4 -0
  76. package/dist/src/resources/cache.d.ts.map +1 -0
  77. package/dist/src/resources/cache.js +25 -0
  78. package/dist/src/resources/cache.js.map +1 -0
  79. package/dist/src/resources/context.d.ts +78 -0
  80. package/dist/src/resources/context.js +2 -0
  81. package/dist/src/resources/logger.d.ts +14 -0
  82. package/dist/src/resources/logger.d.ts.map +1 -0
  83. package/dist/src/resources/logger.js +46 -0
  84. package/dist/src/resources/logger.js.map +1 -0
  85. package/dist/src/resources/provider.d.ts +36 -0
  86. package/dist/src/resources/provider.js +76 -0
  87. package/dist/test/errors.test.d.ts +1 -0
  88. package/dist/test/errors.test.js +16 -0
  89. package/dist/test/handler.test.d.ts +1 -0
  90. package/dist/test/handler.test.js +146 -0
  91. package/dist/test/middlewares/correlationId.test.d.ts +1 -0
  92. package/dist/test/middlewares/correlationId.test.js +19 -0
  93. package/dist/test/middlewares/credentials.test.d.ts +1 -0
  94. package/dist/test/middlewares/credentials.test.js +37 -0
  95. package/dist/test/middlewares/errors.test.d.ts +1 -0
  96. package/dist/test/middlewares/errors.test.js +64 -0
  97. package/dist/test/middlewares/filters.test.d.ts +1 -0
  98. package/dist/test/middlewares/filters.test.js +26 -0
  99. package/dist/test/middlewares/finish.test.d.ts +1 -0
  100. package/dist/test/middlewares/finish.test.js +68 -0
  101. package/dist/test/middlewares/logger.test.d.ts +1 -0
  102. package/dist/test/middlewares/logger.test.js +41 -0
  103. package/dist/test/middlewares/notFound.test.d.ts +1 -0
  104. package/dist/test/middlewares/notFound.test.js +27 -0
  105. package/dist/test/middlewares/selects.test.d.ts +1 -0
  106. package/dist/test/middlewares/selects.test.js +21 -0
  107. package/dist/test/resources/cache.test.d.ts +1 -0
  108. package/dist/test/resources/cache.test.js +25 -0
  109. package/dist/test/resources/logger.test.d.ts +1 -0
  110. package/dist/test/resources/logger.test.js +67 -0
  111. package/dist/tsconfig.tsbuildinfo +1 -0
  112. package/package.json +59 -0
  113. package/src/errors.ts +34 -0
  114. package/src/handler.ts +404 -0
  115. package/src/httpErrors.ts +44 -0
  116. package/src/index.ts +10 -0
  117. package/src/integration.ts +129 -0
  118. package/src/middlewares/correlationId.ts +19 -0
  119. package/src/middlewares/credentials.ts +35 -0
  120. package/src/middlewares/errors.ts +30 -0
  121. package/src/middlewares/filters.ts +51 -0
  122. package/src/middlewares/finish.ts +24 -0
  123. package/src/middlewares/logger.ts +36 -0
  124. package/src/middlewares/notFound.ts +13 -0
  125. package/src/middlewares/selects.ts +31 -0
  126. package/src/resources/cache.ts +34 -0
  127. package/src/resources/context.ts +113 -0
  128. package/src/resources/logger.ts +57 -0
  129. package/src/resources/provider.ts +120 -0
  130. package/test/errors.test.ts +17 -0
  131. package/test/handler.test.ts +178 -0
  132. package/test/middlewares/correlationId.test.ts +26 -0
  133. package/test/middlewares/credentials.test.ts +52 -0
  134. package/test/middlewares/errors.test.ts +78 -0
  135. package/test/middlewares/filters.test.ts +39 -0
  136. package/test/middlewares/finish.test.ts +81 -0
  137. package/test/middlewares/logger.test.ts +57 -0
  138. package/test/middlewares/notFound.test.ts +32 -0
  139. package/test/middlewares/selects.test.ts +34 -0
  140. package/test/resources/cache.test.ts +31 -0
  141. package/test/resources/logger.test.ts +80 -0
  142. package/tsconfig.json +29 -0
package/.eslintrc.cjs ADDED
@@ -0,0 +1,27 @@
1
+ module.exports = {
2
+ env: {
3
+ node: true
4
+ },
5
+ plugins: [
6
+ '@typescript-eslint',
7
+ ],
8
+ extends: [
9
+ 'eslint:recommended',
10
+ 'plugin:@typescript-eslint/recommended',
11
+ ],
12
+ overrides: [
13
+ {
14
+ 'files': ['src/**/*.ts'],
15
+ 'rules': {
16
+ 'no-console': 'off',
17
+ '@typescript-eslint/no-explicit-any': 'off'
18
+ }
19
+ },
20
+ {
21
+ 'files': ['test/**/*.test.ts'],
22
+ 'rules': {
23
+ '@typescript-eslint/no-floating-promises': 'off'
24
+ }
25
+ }
26
+ ],
27
+ };
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ lts/iron
@@ -0,0 +1,2 @@
1
+ src/configurationTypes.ts
2
+ *.md
package/.prettierrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": true,
3
+ "trailingComma": "all",
4
+ "singleQuote": true,
5
+ "printWidth": 120,
6
+ "arrowParens": "avoid"
7
+ }
package/LICENSE ADDED
@@ -0,0 +1,3 @@
1
+ Copyright (c) Unito, Inc.
2
+
3
+ This repository is a component of the Unito Software Development Kit (SDK). By downloading, installing, accessing, or using any part of the Unito SDK, including this repository, you signify your acceptance of and agree to be bound by the terms of the Unito Software Development Kit Agreement found at https://unito.io/sdk-agreement/. If you do not agree to the terms of the Unito Software Development Kit Agreement, you are not authorized to download, install, access, or use any part of the Unito SDK, including this repository.
package/README.md ADDED
@@ -0,0 +1,16 @@
1
+ # Integration SDK
2
+
3
+ **Notice**: This package is currently in a development phase. It may be subject to significant changes.
4
+ This SDK can be used to produce integrations that are compliant with the Integration API Specification.
5
+
6
+ ## Getting started
7
+
8
+ ```sh
9
+ npm install --save @unitoio/integration-sdk
10
+ ```
11
+
12
+ ## Terms and Conditions
13
+
14
+ By using the Integration SDK, you agree to be bound by our terms and conditions.
15
+ Please ensure you have read and understood the Unito Software Development Kit Agreement before using the API.
16
+ The full agreement can be found at [Unito SDK Agreement](https://unito.io/sdk-agreement/).
@@ -0,0 +1,2 @@
1
+ export * from '@unito/integration-api';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from '@unito/integration-api';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/api/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare class HTTPError extends Error {
2
+ readonly status: number;
3
+ constructor(message: string, status: number);
4
+ }
5
+ //# sourceMappingURL=HTTPError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HTTPError.d.ts","sourceRoot":"","sources":["../../../../src/app/errors/HTTPError.ts"],"names":[],"mappings":"AAAA,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAO;gBAElB,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;CAI5C"}
@@ -0,0 +1,8 @@
1
+ export class HTTPError extends Error {
2
+ status = 500;
3
+ constructor(message, status) {
4
+ super(message);
5
+ this.status = status;
6
+ }
7
+ }
8
+ //# sourceMappingURL=HTTPError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HTTPError.js","sourceRoot":"","sources":["../../../../src/app/errors/HTTPError.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,SAAU,SAAQ,KAAK;IACzB,MAAM,GAAW,GAAG,CAAC;IAE9B,YAAY,OAAe,EAAE,MAAc;QACzC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import { HTTPError } from './HTTPError.js';
2
+ export declare class HTTPNotFoundError extends HTTPError {
3
+ constructor(message?: string);
4
+ }
5
+ //# sourceMappingURL=HTTPNotFoundError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HTTPNotFoundError.d.ts","sourceRoot":"","sources":["../../../../src/app/errors/HTTPNotFoundError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,qBAAa,iBAAkB,SAAQ,SAAS;gBAClC,OAAO,CAAC,EAAE,MAAM;CAG7B"}
@@ -0,0 +1,7 @@
1
+ import { HTTPError } from './HTTPError.js';
2
+ export class HTTPNotFoundError extends HTTPError {
3
+ constructor(message) {
4
+ super(message || 'Not found', 404);
5
+ }
6
+ }
7
+ //# sourceMappingURL=HTTPNotFoundError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HTTPNotFoundError.js","sourceRoot":"","sources":["../../../../src/app/errors/HTTPNotFoundError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC9C,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,IAAI,WAAW,EAAE,GAAG,CAAC,CAAC;IACrC,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import { HTTPError } from './HTTPError.js';
2
+ export declare class HTTPUnprocessableEntityError extends HTTPError {
3
+ constructor(message?: string);
4
+ }
5
+ //# sourceMappingURL=HTTPUnprocessableEntityError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HTTPUnprocessableEntityError.d.ts","sourceRoot":"","sources":["../../../../src/app/errors/HTTPUnprocessableEntityError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,qBAAa,4BAA6B,SAAQ,SAAS;gBAC7C,OAAO,CAAC,EAAE,MAAM;CAG7B"}
@@ -0,0 +1,7 @@
1
+ import { HTTPError } from './HTTPError.js';
2
+ export class HTTPUnprocessableEntityError extends HTTPError {
3
+ constructor(message) {
4
+ super(message || 'Unprocessable Entity', 422);
5
+ }
6
+ }
7
+ //# sourceMappingURL=HTTPUnprocessableEntityError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HTTPUnprocessableEntityError.js","sourceRoot":"","sources":["../../../../src/app/errors/HTTPUnprocessableEntityError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,OAAO,4BAA6B,SAAQ,SAAS;IACzD,YAAY,OAAgB;QAC1B,KAAK,CAAC,OAAO,IAAI,sBAAsB,EAAE,GAAG,CAAC,CAAC;IAChD,CAAC;CACF"}
@@ -0,0 +1,4 @@
1
+ export { HTTPError } from './HTTPError.js';
2
+ export { HTTPNotFoundError } from './HTTPNotFoundError.js';
3
+ export { HTTPUnprocessableEntityError } from './HTTPUnprocessableEntityError.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/app/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { HTTPError } from './HTTPError.js';
2
+ export { HTTPNotFoundError } from './HTTPNotFoundError.js';
3
+ export { HTTPUnprocessableEntityError } from './HTTPUnprocessableEntityError.js';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/app/errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import express from 'express';
2
+ export declare const createApp: (options: {
3
+ router: express.Router;
4
+ middlewares?: express.RequestHandler[];
5
+ }) => void;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/app/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAO9B,eAAO,MAAM,SAAS,YAAa;IAAE,MAAM,EAAE,QAAQ,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,QAAQ,cAAc,EAAE,CAAA;CAAE,SA6FpG,CAAC"}
@@ -0,0 +1,80 @@
1
+ import express from 'express';
2
+ import withCorrelationId from './middlewares/withCorrelationId.js';
3
+ import withLogger from './middlewares/withLogger.js';
4
+ import { HTTPError } from './errors/index.js';
5
+ export const createApp = (options) => {
6
+ // Express Server initialization
7
+ const app = express();
8
+ // Parse query strings with https://github.com/ljharb/qs.
9
+ app.set('query parser', 'extended');
10
+ app.use(express.json());
11
+ // Extract the correlation id.
12
+ app.use(withCorrelationId);
13
+ app.use(withLogger);
14
+ // Must be one of the first handlers (to catch all the errors).
15
+ app.use((req, res, next) => {
16
+ if (req.originalUrl !== '/health') {
17
+ res.on('finish', function () {
18
+ const loggerLevel = res.statusCode >= 500 ? 'error' : 'info';
19
+ // eslint-disable-next-line
20
+ res.locals.logger[loggerLevel](`${req.method} ${req.originalUrl} ${res.statusCode}`);
21
+ });
22
+ }
23
+ next();
24
+ });
25
+ // Load the middlewares.
26
+ options.middlewares?.forEach(middleware => app.use(middleware));
27
+ // Load the routes.
28
+ app.use(options.router);
29
+ // Must be the (last - 1) handler.
30
+ app.use((err, _req, res, next) => {
31
+ if (res.headersSent) {
32
+ return next(err);
33
+ }
34
+ if (process.env.NODE_ENV !== 'production') {
35
+ // eslint-disable-next-line
36
+ res.locals.logger.error(err);
37
+ }
38
+ if (err instanceof HTTPError) {
39
+ return res.status(err.status).json(err.message);
40
+ }
41
+ const originalError = {
42
+ code: err.name,
43
+ message: err.message,
44
+ };
45
+ res.status(500).json({
46
+ code: '500',
47
+ message: 'Oops! Something went wrong',
48
+ originalError: originalError,
49
+ });
50
+ });
51
+ // Must be the last handler.
52
+ app.use((req, res, _next) => {
53
+ const error = {
54
+ code: '404',
55
+ message: `Path ${req.path} not found.`,
56
+ };
57
+ res.status(404).json(error);
58
+ });
59
+ const instance = app.listen(process.env.PORT || 9200, () =>
60
+ // eslint-disable-next-line
61
+ console.info(`Server started on port ${process.env.PORT || 9200}.`));
62
+ // Trap exit signals.
63
+ ['SIGTERM', 'SIGINT', 'SIGUSR2'].forEach(signalType => {
64
+ process.once(signalType, async () => {
65
+ // eslint-disable-next-line
66
+ console.info(`Received termination signal ${signalType}. Exiting.`);
67
+ try {
68
+ if (instance) {
69
+ instance.close();
70
+ }
71
+ }
72
+ catch (e) {
73
+ // eslint-disable-next-line
74
+ console.error('Failed to gracefully exit', e);
75
+ }
76
+ process.exit();
77
+ });
78
+ });
79
+ };
80
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/app/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,OAAO,iBAAiB,MAAM,oCAAoC,CAAC;AACnE,OAAO,UAAU,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAA2E,EAAE,EAAE;IACvG,gCAAgC;IAChC,MAAM,GAAG,GAAwB,OAAO,EAAE,CAAC;IAE3C,yDAAyD;IACzD,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;IAEpC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAExB,8BAA8B;IAC9B,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAE3B,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IAEpB,+DAA+D;IAC/D,GAAG,CAAC,GAAG,CAAC,CAAC,GAAoB,EAAE,GAAqB,EAAE,IAA0B,EAAE,EAAE;QAClF,IAAI,GAAG,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YAClC,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE;gBACf,MAAM,WAAW,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAA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 }
5
+ //# sourceMappingURL=integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.d.ts","sourceRoot":"","sources":["../../../src/app/integration.ts"],"names":[],"mappings":"AAQA,qBAAa,WAAW;IACtB,OAAO,CAAC,WAAW,CAAgC;IAK5C,KAAK;CA8Fb"}
@@ -0,0 +1,86 @@
1
+ import express from 'express';
2
+ import withCorrelationId from './middlewares/withCorrelationId.js';
3
+ import withLogger from './middlewares/withLogger.js';
4
+ import { HTTPError } from './errors/index.js';
5
+ // import { ItemNode } from './itemNode.js';
6
+ export class Integration {
7
+ middlewares = [];
8
+ // private router: express.Router = express.Router();
9
+ // private graph: ItemNode = new ItemNode(''); // Take root node from .unito.json
10
+ start() {
11
+ // Express Server initialization
12
+ const app = express();
13
+ // Parse query strings with https://github.com/ljharb/qs.
14
+ app.set('query parser', 'extended');
15
+ app.use(express.json());
16
+ // Extract the correlation id.
17
+ app.use(withCorrelationId);
18
+ app.use(withLogger);
19
+ // Must be one of the first handlers (to catch all the errors).
20
+ app.use((req, res, next) => {
21
+ if (req.originalUrl !== '/health') {
22
+ res.on('finish', function () {
23
+ const loggerLevel = res.statusCode >= 500 ? 'error' : 'info';
24
+ // eslint-disable-next-line
25
+ res.locals.logger[loggerLevel](`${req.method} ${req.originalUrl} ${res.statusCode}`);
26
+ });
27
+ }
28
+ next();
29
+ });
30
+ // Load the middlewares.
31
+ this.middlewares?.forEach(middleware => app.use(middleware));
32
+ // Load the routes.
33
+ app.use(this.router);
34
+ // Must be the (last - 1) handler.
35
+ app.use((err, _req, res, next) => {
36
+ if (res.headersSent) {
37
+ return next(err);
38
+ }
39
+ if (process.env.NODE_ENV !== 'production') {
40
+ // eslint-disable-next-line
41
+ res.locals.logger.error(err);
42
+ }
43
+ if (err instanceof HTTPError) {
44
+ return res.status(err.status).json(err.message);
45
+ }
46
+ const originalError = {
47
+ code: err.name,
48
+ message: err.message,
49
+ };
50
+ res.status(500).json({
51
+ code: '500',
52
+ message: 'Oops! Something went wrong',
53
+ originalError: originalError,
54
+ });
55
+ });
56
+ // Must be the last handler.
57
+ app.use((req, res, _next) => {
58
+ const error = {
59
+ code: '404',
60
+ message: `Path ${req.path} not found.`,
61
+ };
62
+ res.status(404).json(error);
63
+ });
64
+ const instance = app.listen(process.env.PORT || 9200, () =>
65
+ // eslint-disable-next-line
66
+ console.info(`Server started on port ${process.env.PORT || 9200}.`));
67
+ // Trap exit signals.
68
+ ['SIGTERM', 'SIGINT', 'SIGUSR2'].forEach(signalType => {
69
+ process.once(signalType, async () => {
70
+ // eslint-disable-next-line
71
+ console.info(`Received termination signal ${signalType}. Exiting.`);
72
+ try {
73
+ if (instance) {
74
+ instance.close();
75
+ }
76
+ }
77
+ catch (e) {
78
+ // eslint-disable-next-line
79
+ console.error('Failed to gracefully exit', e);
80
+ }
81
+ process.exit();
82
+ });
83
+ });
84
+ }
85
+ }
86
+ //# sourceMappingURL=integration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.js","sourceRoot":"","sources":["../../../src/app/integration.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAG9B,OAAO,iBAAiB,MAAM,oCAAoC,CAAC;AACnE,OAAO,UAAU,MAAM,6BAA6B,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,4CAA4C;AAE5C,MAAM,OAAO,WAAW;IACd,WAAW,GAA6B,EAAE,CAAC;IACnD,qDAAqD;IAErD,iFAAiF;IAE1E,KAAK;QACV,gCAAgC;QAChC,MAAM,GAAG,GAAwB,OAAO,EAAE,CAAC;QAE3C,yDAAyD;QACzD,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC;QAEpC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAExB,8BAA8B;QAC9B,GAAG,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QAE3B,GAAG,CAAC,GA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,CAAC,KAAK,EAAE,CAAC;oBACnB,CAAC;gBACH,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,2BAA2B;oBAC3B,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,CAAC,CAAC,CAAC;gBAChD,CAAC;gBAED,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ export declare class ItemNode {
2
+ private path;
3
+ private router;
4
+ private relations;
5
+ constructor(path: string);
6
+ getRelations(): ItemNode[];
7
+ }
8
+ //# sourceMappingURL=itemNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"itemNode.d.ts","sourceRoot":"","sources":["../../../src/app/itemNode.ts"],"names":[],"mappings":"AAEA,qBAAa,QAAQ;IACnB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,MAAM,CAAoC;IAClD,OAAO,CAAC,SAAS,CAAkB;gBAEvB,IAAI,EAAE,MAAM;IAIxB,YAAY;CAKb"}
@@ -0,0 +1,13 @@
1
+ import express from 'express';
2
+ export class ItemNode {
3
+ path;
4
+ router = express.Router();
5
+ relations = [];
6
+ constructor(path) {
7
+ this.path = path;
8
+ }
9
+ getRelations() {
10
+ return this.relations;
11
+ }
12
+ }
13
+ //# sourceMappingURL=itemNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"itemNode.js","sourceRoot":"","sources":["../../../src/app/itemNode.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,MAAM,OAAO,QAAQ;IACX,IAAI,CAAS;IACb,MAAM,GAAmB,OAAO,CAAC,MAAM,EAAE,CAAC;IAC1C,SAAS,GAAe,EAAE,CAAC;IAEnC,YAAY,IAAY;QACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CAGF"}
@@ -0,0 +1,11 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ declare global {
3
+ namespace Express {
4
+ interface Locals {
5
+ correlationId: string;
6
+ }
7
+ }
8
+ }
9
+ declare const withCorrelationId: (req: Request, res: Response, next: NextFunction) => void;
10
+ export default withCorrelationId;
11
+ //# sourceMappingURL=withCorrelationId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withCorrelationId.d.ts","sourceRoot":"","sources":["../../../../src/app/middlewares/withCorrelationId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG1D,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAO,CAAC;QAChB,UAAU,MAAM;YACd,aAAa,EAAE,MAAM,CAAC;SACvB;KACF;CACF;AAED,QAAA,MAAM,iBAAiB,QAAS,OAAO,OAAO,QAAQ,QAAQ,YAAY,SAMzE,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import * as uuid from 'uuid';
2
+ const withCorrelationId = (req, res, next) => {
3
+ const correlationIdHeader = req.header('X-Unito-Correlation-Id');
4
+ res.locals.correlationId = correlationIdHeader ?? uuid.v4();
5
+ next();
6
+ };
7
+ export default withCorrelationId;
8
+ //# sourceMappingURL=withCorrelationId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withCorrelationId.js","sourceRoot":"","sources":["../../../../src/app/middlewares/withCorrelationId.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAW7B,MAAM,iBAAiB,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IAC5E,MAAM,mBAAmB,GAAG,GAAG,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;IAEjE,GAAG,CAAC,MAAM,CAAC,aAAa,GAAG,mBAAmB,IAAI,IAAI,CAAC,EAAE,EAAE,CAAC;IAE5D,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { Request, Response, NextFunction } from 'express';
2
+ import Logger from '../../resources/logger.js';
3
+ declare global {
4
+ namespace Express {
5
+ interface Locals {
6
+ logger: Logger;
7
+ }
8
+ }
9
+ }
10
+ declare const withLogger: (req: Request, res: Response, next: NextFunction) => void;
11
+ export default withLogger;
12
+ //# sourceMappingURL=withLogger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withLogger.d.ts","sourceRoot":"","sources":["../../../../src/app/middlewares/withLogger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAE/C,OAAO,CAAC,MAAM,CAAC;IAEb,UAAU,OAAO,CAAC;QAChB,UAAU,MAAM;YACd,MAAM,EAAE,MAAM,CAAC;SAChB;KACF;CACF;AAED,QAAA,MAAM,UAAU,QAAS,OAAO,OAAO,QAAQ,QAAQ,YAAY,SAiBlE,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,18 @@
1
+ import Logger from '../../resources/logger.js';
2
+ const withLogger = (req, res, next) => {
3
+ const logger = new Logger({ correlation_id: res.locals.correlationId });
4
+ res.locals.logger = logger;
5
+ const additionalLoggingContextHeader = req.header('X-Unito-Additional-Logging-Context');
6
+ if (typeof additionalLoggingContextHeader === 'string') {
7
+ try {
8
+ const additionalLoggingContext = JSON.parse(additionalLoggingContextHeader);
9
+ logger.decorate(additionalLoggingContext);
10
+ }
11
+ catch (error) {
12
+ logger.warn(`Failed parsing header X-Unito-Additional-Logging-Context: ${additionalLoggingContextHeader}`);
13
+ }
14
+ }
15
+ next();
16
+ };
17
+ export default withLogger;
18
+ //# sourceMappingURL=withLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withLogger.js","sourceRoot":"","sources":["../../../../src/app/middlewares/withLogger.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,2BAA2B,CAAC;AAW/C,MAAM,UAAU,GAAG,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;IACrE,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;IAExE,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IAE3B,MAAM,8BAA8B,GAAG,GAAG,CAAC,MAAM,CAAC,oCAAoC,CAAC,CAAC;IAExF,IAAI,OAAO,8BAA8B,KAAK,QAAQ,EAAE,CAAC;QACvD,IAAI,CAAC;YACH,MAAM,wBAAwB,GAAG,IAAI,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;YAC5E,MAAM,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,6DAA6D,8BAA8B,EAAE,CAAC,CAAC;QAC7G,CAAC;IACH,CAAC;IAED,IAAI,EAAE,CAAC;AACT,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,15 @@
1
+ export declare class NoIntegrationFoundError extends Error {
2
+ }
3
+ export declare class NoConfigurationFileError extends Error {
4
+ }
5
+ export declare class ConfigurationMalformed extends Error {
6
+ }
7
+ export declare class InvalidHandler extends Error {
8
+ }
9
+ /**
10
+ * Processes provider response codes and throw corresponding errors to be translated further in our responses
11
+ *
12
+ * @param responseStatus the reponseStatus of the request. Any HTTP response code passed here will result in an error!
13
+ * @param message The message returned by the provider
14
+ */
15
+ export declare function handleErrorResponse(responseStatus: number, message: string): void;
@@ -0,0 +1,39 @@
1
+ import * as HttpErrors from './httpErrors.js';
2
+ export class NoIntegrationFoundError extends Error {
3
+ }
4
+ export class NoConfigurationFileError extends Error {
5
+ }
6
+ export class ConfigurationMalformed extends Error {
7
+ }
8
+ export class InvalidHandler extends Error {
9
+ }
10
+ /**
11
+ * Processes provider response codes and throw corresponding errors to be translated further in our responses
12
+ *
13
+ * @param responseStatus the reponseStatus of the request. Any HTTP response code passed here will result in an error!
14
+ * @param message The message returned by the provider
15
+ */
16
+ // Keep in errors.ts instead of httpErrors.ts because we do not need to export it outside of the sdk
17
+ export function handleErrorResponse(responseStatus, message) {
18
+ if (responseStatus === 400) {
19
+ throw new HttpErrors.BadRequestError(message);
20
+ }
21
+ else if (responseStatus === 401 || responseStatus === 403) {
22
+ throw new HttpErrors.UnauthorizedError(message);
23
+ }
24
+ else if (responseStatus === 404) {
25
+ throw new HttpErrors.NotFoundError(message);
26
+ }
27
+ else if (responseStatus === 408) {
28
+ throw new HttpErrors.TimeoutError(message);
29
+ }
30
+ else if (responseStatus === 422) {
31
+ throw new HttpErrors.UnprocessableEntityError(message);
32
+ }
33
+ else if (responseStatus === 429) {
34
+ throw new HttpErrors.RateLimitExceededError(message);
35
+ }
36
+ else {
37
+ throw new HttpErrors.HttpError(message, responseStatus);
38
+ }
39
+ }
@@ -0,0 +1,67 @@
1
+ import { Router } from 'express';
2
+ import * as API from '@unito/integration-api';
3
+ import { GetItemContext, GetCollectionContext, CreateItemContext, UpdateItemContext, DeleteItemContext, GetCredentialAccountContext, ParseWebhooksContext, UpdateWebhookSubscriptionsContext, AckknowledgeWebhooksContext } from './resources/context.js';
4
+ /**
5
+ * Handler called to get an individual item.
6
+ */
7
+ export type GetItemHandler = (context: GetItemContext<any, any>) => Promise<API.Item>;
8
+ /**
9
+ * Handler called to retrieve a collection of items.
10
+ */
11
+ export type GetCollectionHandler = (context: GetCollectionContext<any, any>) => Promise<API.Collection>;
12
+ /**
13
+ * Handler called to create an item.
14
+ */
15
+ export type CreateItemHandler = (context: CreateItemContext<any, any, any>) => Promise<API.ItemSummary>;
16
+ /**
17
+ * Handler called to update an item.
18
+ */
19
+ export type UpdateItemHandler = (context: UpdateItemContext<any, any, any>) => Promise<API.Item>;
20
+ /**
21
+ * Handler called to delete an item.
22
+ */
23
+ export type DeleteItemHandler = (context: DeleteItemContext<any, any>) => Promise<void>;
24
+ /**
25
+ * Handler called to retrieve the account details associated with the credentials.
26
+ */
27
+ export type GetCredentialAccountHandler = (context: GetCredentialAccountContext<any, any>) => Promise<API.CredentialAccount>;
28
+ /**
29
+ * Handler called to parse the content of an incoming webhook.
30
+ */
31
+ export type ParseWebhooksHandler = (context: ParseWebhooksContext<any, any, any>) => Promise<API.WebhookParseResponsePayload>;
32
+ /**
33
+ * Handler called to subscribe or unsubscribe to a particular webhook.
34
+ */
35
+ export type UpdateWebhookSubscriptionsHandler = (context: UpdateWebhookSubscriptionsContext<any, any, any>) => Promise<void>;
36
+ /**
37
+ * Handler called to acknowledge the reception of a webhook.
38
+ */
39
+ export type AckknowledgeWebhooksHandler = (context: AckknowledgeWebhooksContext<any, any, any>) => Promise<API.WebhookAcknowledgeResponsePayload>;
40
+ type ItemHandlers = {
41
+ getItem?: GetItemHandler;
42
+ getCollection?: GetCollectionHandler;
43
+ createItem?: CreateItemHandler;
44
+ updateItem?: UpdateItemHandler;
45
+ deleteItem?: DeleteItemHandler;
46
+ };
47
+ type CredentialAccountHandlers = {
48
+ getCredentialAccount: GetCredentialAccountHandler;
49
+ };
50
+ type ParseWebhookHandlers = {
51
+ parseWebhooks: ParseWebhooksHandler;
52
+ };
53
+ type WebhookSubscriptionHandlers = {
54
+ updateWebhookSubscriptions: UpdateWebhookSubscriptionsHandler;
55
+ };
56
+ type AcknowledgeWebhookHandlers = {
57
+ acknowledgeWebhooks?: AckknowledgeWebhooksHandler;
58
+ };
59
+ export type HandlersInput = ItemHandlers | CredentialAccountHandlers | ParseWebhookHandlers | WebhookSubscriptionHandlers | AcknowledgeWebhookHandlers;
60
+ export declare class Handler {
61
+ private path;
62
+ private pathWithIdentifier;
63
+ private handlers;
64
+ constructor(inputPath: string, handlers: HandlersInput);
65
+ generate(): Router;
66
+ }
67
+ export {};