heimdall-api-platform 1.0.4 → 1.0.6

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 (95) hide show
  1. package/dist/clients/http-client.js +1 -0
  2. package/dist/commons-cache.js +1 -0
  3. package/dist/commons-const.js +1 -0
  4. package/dist/commons-elasticsearch.js +1 -0
  5. package/dist/commons-errors.js +1 -0
  6. package/dist/commons-opensearch.js +1 -0
  7. package/dist/commons-splunk.js +1 -0
  8. package/dist/commons-util.js +1 -0
  9. package/dist/default-routes-docs.js +1 -0
  10. package/dist/default-routes-pos.js +1 -0
  11. package/dist/default-routes-pre.js +1 -0
  12. package/dist/environment.js +1 -0
  13. package/dist/factory/api-gateway.js +1 -0
  14. package/dist/factory/client-factory.js +1 -0
  15. package/dist/factory/function-factory.js +1 -0
  16. package/dist/factory/operation-flow-factory.js +1 -0
  17. package/dist/factory/server-factory.js +1 -0
  18. package/dist/factory/transformation-function-factory.js +1 -0
  19. package/dist/handle-route.js +1 -0
  20. package/dist/index.js +2 -0
  21. package/dist/jwt-util.js +1 -0
  22. package/dist/license/license-service.js +1 -0
  23. package/dist/models/base-context.js +1 -0
  24. package/dist/models/elastic-index-data.js +1 -0
  25. package/dist/models/flow-context.js +1 -0
  26. package/dist/models/flow-indexed.js +1 -0
  27. package/dist/models/operation-function-indexed.js +1 -0
  28. package/dist/models/operation-function-transformation-indexed.js +1 -0
  29. package/dist/models/operation-http-indexed.js +1 -0
  30. package/dist/models/operation-mock-indexed.js +1 -0
  31. package/dist/models/route-context.js +1 -0
  32. package/dist/models/security-route.js +1 -0
  33. package/dist/models/service-context.js +1 -0
  34. package/dist/models/service-group.js +1 -0
  35. package/dist/models/service-route.js +1 -0
  36. package/dist/models/splunk-data.js +1 -0
  37. package/dist/operations/abstract-operation.js +1 -0
  38. package/dist/operations/function.js +1 -0
  39. package/dist/operations/http.js +1 -0
  40. package/dist/operations/mock.js +1 -0
  41. package/dist/operations/monitor-check.js +1 -0
  42. package/dist/orchestration-flow.js +1 -0
  43. package/dist/router.js +1 -0
  44. package/dist/security-validation.js +1 -0
  45. package/dist/services/server.js +1 -0
  46. package/dist/services/template-monitorcheck-route.js +1 -0
  47. package/package.json +5 -5
  48. package/lib/clients/http-client.js +0 -296
  49. package/lib/commons-cache.js +0 -185
  50. package/lib/commons-const.js +0 -203
  51. package/lib/commons-elasticsearch.js +0 -49
  52. package/lib/commons-errors.js +0 -278
  53. package/lib/commons-opensearch.js +0 -37
  54. package/lib/commons-splunk.js +0 -105
  55. package/lib/commons-util.js +0 -669
  56. package/lib/default-routes-docs.js +0 -141
  57. package/lib/default-routes-pos.js +0 -111
  58. package/lib/default-routes-pre.js +0 -151
  59. package/lib/environment.js +0 -81
  60. package/lib/factory/api-gateway.js +0 -12
  61. package/lib/factory/client-factory.js +0 -41
  62. package/lib/factory/function-factory.js +0 -40
  63. package/lib/factory/operation-flow-factory.js +0 -64
  64. package/lib/factory/server-factory.js +0 -15
  65. package/lib/factory/transformation-function-factory.js +0 -47
  66. package/lib/handle-route.js +0 -472
  67. package/lib/index.js +0 -50
  68. package/lib/jwt-util.js +0 -38
  69. package/lib/license/license-service.js +0 -27
  70. package/lib/models/base-context.js +0 -77
  71. package/lib/models/elastic-index-data.js +0 -76
  72. package/lib/models/flow-context.js +0 -58
  73. package/lib/models/flow-indexed.js +0 -62
  74. package/lib/models/operation-function-indexed.js +0 -22
  75. package/lib/models/operation-function-transformation-indexed.js +0 -23
  76. package/lib/models/operation-http-indexed.js +0 -38
  77. package/lib/models/operation-mock-indexed.js +0 -22
  78. package/lib/models/route-context.js +0 -69
  79. package/lib/models/security-route.js +0 -41
  80. package/lib/models/service-context.js +0 -65
  81. package/lib/models/service-group.js +0 -15
  82. package/lib/models/service-route.js +0 -23
  83. package/lib/models/splunk-data.js +0 -70
  84. package/lib/operations/abstract-operation.js +0 -73
  85. package/lib/operations/function.js +0 -143
  86. package/lib/operations/http.js +0 -286
  87. package/lib/operations/mock.js +0 -34
  88. package/lib/operations/monitor-check.js +0 -151
  89. package/lib/orchestration-flow.js +0 -323
  90. package/lib/public/redoc.html +0 -152
  91. package/lib/public/swagger.html +0 -143
  92. package/lib/router.js +0 -29
  93. package/lib/security-validation.js +0 -46
  94. package/lib/services/server.js +0 -211
  95. package/lib/services/template-monitorcheck-route.js +0 -61
@@ -1,211 +0,0 @@
1
- "use strict";
2
-
3
- const Util = require("../commons-util");
4
- const path = require("path");
5
- const express = require("express");
6
- const ServiceGroup = require("../models/service-group");
7
- const Router = require("../router");
8
- const ServiceRoute = require("../models/service-route");
9
- const HandleRoute = require("../handle-route");
10
- const OrchestrationFlow = require("../orchestration-flow");
11
- const commonsCache = require("../commons-cache");
12
- // const commonsElasticSearch = require("../commons-elasticsearch");
13
- const commonsOpenSearch = require("../commons-opensearch");
14
- const commonsSplunkInstance = require("../commons-splunk");
15
- const ServiceContext = require("../models/service-context");
16
- const templateMonitorCheckRoute = require("./template-monitorcheck-route");
17
- const _ = require("underscore");
18
- const licenseService = require("../license/license-service");
19
-
20
- class Server {
21
-
22
- constructor(environment) {
23
-
24
- this.environment = environment;
25
- this.initialTime = new Date();
26
- this.port = this.environment.application.serverPort || 8080;
27
-
28
- this.app = express();
29
-
30
- //Grupo de Servicos Expostos na API Gateway
31
- this.generateMonitorCheckRoutes(environment);
32
-
33
- this.listServiceGroup = createListServiceGroup(environment.mappingServices);
34
-
35
- this.redisClient = commonsCache.createClient(environment.application);
36
- // this.elasticSearch = commonsElasticSearch.createClient(environment.application);
37
- this.openSearch = commonsOpenSearch.createClient(environment.application);
38
- this.splunkInstance = commonsSplunkInstance.createClient(environment.application);
39
- this.express = express;
40
- this.validateFlowAndFunctions();
41
- }
42
-
43
- async licenseValidation() {
44
-
45
- try {
46
-
47
- const appKey = process.env.APP_KEY;
48
-
49
- if (!appKey) {
50
- throw new Error(
51
- "[Heimdall API Platform] APP_KEY não definida. " +
52
- "Configure a variável de ambiente APP_KEY com a chave da sua credencial. " +
53
- "Em caso de dúvidas, entre em contato com o suporte técnico da Heimdall API Platform (P4F)."
54
- );
55
- }
56
-
57
- const license = await licenseService.validate(appKey);
58
-
59
- if (!license || !license.active) {
60
- throw new Error(
61
- `[Heimdall API Platform] Licença inválida ou expirada para a APP_KEY '${appKey}'. ` +
62
- "A aplicação não pode ser iniciada. " +
63
- "Entre em contato com o suporte técnico da Heimdall API Platform da P4F para resolver esse problema."
64
- );
65
- }
66
-
67
- this.app.locals.license = license;
68
-
69
- console.error("stage=warn method=Server.start license validated", license);
70
-
71
- return true;
72
-
73
- } catch (error) {
74
- console.error("stage=error method=Server.start license validation failed", { message: error.message });
75
- process.exit(1);
76
- }
77
-
78
- }
79
-
80
- generateMonitorCheckRoutes(environment) {
81
- let serviceHealthCheck = {
82
- basePath: "/healthcheck/",
83
- description: "Health Clients",
84
- version: "V1",
85
- services: [],
86
- };
87
-
88
- let mappingClients = environment.mappingClients;
89
-
90
- Object.keys(mappingClients).map(function (clientName) {
91
- let currentClientConfig = mappingClients[clientName];
92
- serviceHealthCheck.services.push(new templateMonitorCheckRoute(clientName, currentClientConfig));
93
- });
94
-
95
- environment.mappingServices.push(serviceHealthCheck);
96
- }
97
-
98
- validateFlowAndFunctions() {
99
- Util.warning("Validate Flows and Services");
100
-
101
- try {
102
- let services = this.listServiceGroup.map((group) => {
103
- return group.services.map((service) => {
104
- return new ServiceContext(service, null);
105
- });
106
- });
107
- } catch (error) {
108
- Util.throwErrorIfItExists(error);
109
- }
110
- }
111
-
112
- async start() {
113
-
114
- let self = this;
115
-
116
- await this.licenseValidation();
117
-
118
- //SECURITY HEADERS, UUID, QUERYPARSER, BODYPARSER, MORGAN
119
- require("../default-routes-pre")(this);
120
-
121
- //DOCUMENTATION
122
- require("../default-routes-docs")(this);
123
-
124
- //CRIA AS ROTAS
125
- this.registerServiceRoutes();
126
-
127
- //Default API, VERSION, ROOT
128
- require("../default-routes-pos")(this);
129
-
130
- if (this.environment.startServer) {
131
- this.app.listen(this.port, function (error) {
132
- if (error) {
133
- Util.throwErrorIfItExists(error);
134
- } else {
135
- var listenMsg = "\n\n " + self.environment.application.appName.toUpperCase();
136
- listenMsg += "\n +++++++++++++++++++++++++++++++++++++++++++++++++++++";
137
- listenMsg += "\n\n Environment " + self.environment.environment.toUpperCase();
138
- listenMsg += "\n\n Listening on port " + self.port;
139
- listenMsg += "\n\n http://localhost:" + self.port + "/";
140
- listenMsg += "\n\n Groups Services: " + self.listServiceGroup.length;
141
- listenMsg +=
142
- "\n\n Services: " +
143
- self.listServiceGroup
144
- .map((group) => group.services.length)
145
- .reduce((a, b) => a + b, 0);
146
- listenMsg +=
147
- "\n\n Flows: " +
148
- self.listServiceGroup
149
- .map((group) => group.services
150
- .map((service) => service.flow.length)
151
- .reduce((a, b) => a + b, 0))
152
- .reduce((a, b) => a + b, 0);
153
- listenMsg += "\n\n Inicialization in " + (new Date() - self.initialTime) + " ms \n\n";
154
- listenMsg += "+++++++++++++++++++++++++++++++++++++++++++++++++++++ \n\n";
155
- Util.warning(listenMsg);
156
- }
157
- });
158
- }
159
- }
160
-
161
- registerServiceRoutes() {
162
- let self = this;
163
-
164
- let newRouter = new Router(self.app);
165
-
166
- self.listServiceGroup.forEach(function (currentServiceGroup) {
167
- Util.info("stage=init method=Server.registerServiceRoutes serviceGroup", {
168
- description: currentServiceGroup.description,
169
- basePath: currentServiceGroup.basePath,
170
- totalServices: currentServiceGroup.services.length,
171
- });
172
-
173
- currentServiceGroup.services.forEach(function (currentServiceOptions) {
174
- let route = new ServiceRoute({
175
- path: currentServiceGroup.validatePath
176
- ? path.join("/", currentServiceGroup.basePath, "/", currentServiceOptions.route || "")
177
- : currentServiceGroup.basePath + path.join("/", currentServiceOptions.route || ""),
178
- method: currentServiceOptions.method,
179
- enableUploader: currentServiceOptions.enableUploader,
180
- uploadFieldName: currentServiceOptions.uploadFieldName,
181
- security: currentServiceOptions.security,
182
- });
183
-
184
- Util.info(
185
- `stage=info method=Server.registerServiceRoutes route method=${currentServiceOptions.method.toUpperCase()} path=${route.getPath()} serviceName=${currentServiceOptions.name
186
- } totalFlows=${currentServiceOptions.flow.length}`
187
- );
188
-
189
- let newOrchestrationFlow = new OrchestrationFlow(self.redisClient);
190
-
191
- let newHandleRoute = new HandleRoute(
192
- newOrchestrationFlow,
193
- currentServiceOptions,
194
- self.splunkInstance,
195
- self.openSearch
196
- );
197
-
198
- newRouter.addRoute(route, newHandleRoute);
199
- });
200
- });
201
- }
202
- }
203
-
204
- function createListServiceGroup(mappingServices) {
205
- return mappingServices.map((serviceGroup) => {
206
- return new ServiceGroup(serviceGroup);
207
- });
208
- }
209
-
210
- // Hook into commonJS module systems
211
- module.exports = Server;
@@ -1,61 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path')
4
-
5
- class templateMonitorCheckRoute {
6
-
7
- constructor(clientName, options) {
8
-
9
- this.name = `${clientName}HealthCheck`;
10
- this.description = options.description;
11
- this.method = 'GET';
12
- this.route = `${clientName}`;
13
- this.flow = []
14
-
15
- if (options.hasOwnProperty('healthCheck')) {
16
- this.flow.push(this.addFlowHealth(clientName, options));
17
- };
18
-
19
- if (options.hasOwnProperty('infoCheck')) {
20
- this.flow.push(this.addFlowInfo(clientName, options));
21
- };
22
-
23
- };
24
-
25
- addFlowInfo(clientName, options) {
26
- return {
27
- resultVariable: 'info',
28
- operation: {
29
- clientName: clientName,
30
- path: options.infoCheck,
31
- type: 'monitor'
32
- }
33
- };
34
- };
35
-
36
- addFlowHealth(clientName, options) {
37
- return {
38
- resultVariable: 'health',
39
- operation: {
40
- clientName: clientName,
41
- path: options.healthCheck,
42
- type: 'monitor'
43
- }
44
- };
45
- };
46
-
47
- };
48
-
49
-
50
-
51
- // {
52
- // description: 'Login API',
53
- // clientName: 'loginSantander',
54
- // basePath: '',
55
- // host: 'https://santander2.continuousplatform.com',
56
- // poolSize: 50,
57
- // timeout: 60000,
58
- // healthCheck: 'monitor/health'
59
- // }
60
-
61
- module.exports = templateMonitorCheckRoute;