@blazedpath/commons 0.0.4
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 +3 -0
- package/blz-base/health/index.js +215 -0
- package/blz-base/index.js +1466 -0
- package/blz-cache/LruCache.js +44 -0
- package/blz-cache/index.js +29 -0
- package/blz-config/index.js +434 -0
- package/blz-core/index.js +364 -0
- package/blz-cryptography/index.js +54 -0
- package/blz-datetimes/index.js +356 -0
- package/blz-file/example.dat +2545 -0
- package/blz-file/fileService.js +205 -0
- package/blz-file/index.js +94 -0
- package/blz-file/index.test.js +31 -0
- package/blz-file/lab.js +33 -0
- package/blz-hazelcast/index.js +189 -0
- package/blz-hazelcast/lib/credentials.js +25 -0
- package/blz-hazelcast/lib/credentialsFactory.js +12 -0
- package/blz-hazelcast/lib/hazelcastCache.js +234 -0
- package/blz-iterable/index.js +446 -0
- package/blz-json-schema/index.js +11 -0
- package/blz-jwt/index.js +121 -0
- package/blz-kafka/index.js +522 -0
- package/blz-math/index.js +131 -0
- package/blz-mongodb/index.js +326 -0
- package/blz-rds/__test__/scape.test.js +58 -0
- package/blz-rds/blz-rds-executor.js +578 -0
- package/blz-rds/blz-rds-helper.js +310 -0
- package/blz-rds/commands/core/add.js +13 -0
- package/blz-rds/commands/core/and.js +18 -0
- package/blz-rds/commands/core/asc.js +10 -0
- package/blz-rds/commands/core/avg.js +10 -0
- package/blz-rds/commands/core/column-ref.js +8 -0
- package/blz-rds/commands/core/count-distinct.js +10 -0
- package/blz-rds/commands/core/count.js +10 -0
- package/blz-rds/commands/core/decimal.js +8 -0
- package/blz-rds/commands/core/desc.js +10 -0
- package/blz-rds/commands/core/distinct.js +10 -0
- package/blz-rds/commands/core/divide.js +11 -0
- package/blz-rds/commands/core/embedded-exists.js +17 -0
- package/blz-rds/commands/core/embedded-select.js +17 -0
- package/blz-rds/commands/core/equals.js +9 -0
- package/blz-rds/commands/core/false.js +8 -0
- package/blz-rds/commands/core/greater-or-equal.js +9 -0
- package/blz-rds/commands/core/greater.js +9 -0
- package/blz-rds/commands/core/in.js +9 -0
- package/blz-rds/commands/core/integer.js +8 -0
- package/blz-rds/commands/core/is-not-null.js +11 -0
- package/blz-rds/commands/core/is-null-or-value.js +10 -0
- package/blz-rds/commands/core/is-null.js +11 -0
- package/blz-rds/commands/core/less-or-equal.js +9 -0
- package/blz-rds/commands/core/less-unary.js +12 -0
- package/blz-rds/commands/core/less.js +9 -0
- package/blz-rds/commands/core/like.js +12 -0
- package/blz-rds/commands/core/max.js +10 -0
- package/blz-rds/commands/core/min.js +10 -0
- package/blz-rds/commands/core/multiply.js +13 -0
- package/blz-rds/commands/core/not-equals.js +9 -0
- package/blz-rds/commands/core/not-in.js +9 -0
- package/blz-rds/commands/core/not.js +13 -0
- package/blz-rds/commands/core/null.js +8 -0
- package/blz-rds/commands/core/nvl.js +11 -0
- package/blz-rds/commands/core/or.js +13 -0
- package/blz-rds/commands/core/parameter.js +34 -0
- package/blz-rds/commands/core/remainder.js +16 -0
- package/blz-rds/commands/core/string.js +8 -0
- package/blz-rds/commands/core/subtract.js +13 -0
- package/blz-rds/commands/core/sum.js +10 -0
- package/blz-rds/commands/core/true.js +8 -0
- package/blz-rds/commands/core/tuple.js +13 -0
- package/blz-rds/commands/datetimes/add-days.js +11 -0
- package/blz-rds/commands/datetimes/add-hours.js +11 -0
- package/blz-rds/commands/datetimes/add-milliseconds.js +11 -0
- package/blz-rds/commands/datetimes/add-minutes.js +11 -0
- package/blz-rds/commands/datetimes/add-months.js +11 -0
- package/blz-rds/commands/datetimes/add-seconds.js +11 -0
- package/blz-rds/commands/datetimes/add-years.js +11 -0
- package/blz-rds/commands/datetimes/date-diff.js +11 -0
- package/blz-rds/commands/datetimes/date.js +12 -0
- package/blz-rds/commands/datetimes/datetime-diff.js +11 -0
- package/blz-rds/commands/datetimes/datetime.js +15 -0
- package/blz-rds/commands/datetimes/day.js +10 -0
- package/blz-rds/commands/datetimes/hour.js +10 -0
- package/blz-rds/commands/datetimes/millisecond.js +10 -0
- package/blz-rds/commands/datetimes/minute.js +10 -0
- package/blz-rds/commands/datetimes/month-text.js +10 -0
- package/blz-rds/commands/datetimes/month.js +10 -0
- package/blz-rds/commands/datetimes/now.js +9 -0
- package/blz-rds/commands/datetimes/second.js +10 -0
- package/blz-rds/commands/datetimes/subtract-days.js +11 -0
- package/blz-rds/commands/datetimes/subtract-hours.js +11 -0
- package/blz-rds/commands/datetimes/subtract-milliseconds.js +11 -0
- package/blz-rds/commands/datetimes/subtract-minutes.js +11 -0
- package/blz-rds/commands/datetimes/subtract-seconds.js +11 -0
- package/blz-rds/commands/datetimes/time-diff.js +11 -0
- package/blz-rds/commands/datetimes/time.js +13 -0
- package/blz-rds/commands/datetimes/today.js +9 -0
- package/blz-rds/commands/datetimes/week-day-text.js +10 -0
- package/blz-rds/commands/datetimes/week-day.js +10 -0
- package/blz-rds/commands/datetimes/week.js +10 -0
- package/blz-rds/commands/datetimes/year.js +10 -0
- package/blz-rds/commands/math/abs.js +10 -0
- package/blz-rds/commands/math/acos.js +10 -0
- package/blz-rds/commands/math/asin.js +10 -0
- package/blz-rds/commands/math/atan.js +10 -0
- package/blz-rds/commands/math/atan2.js +11 -0
- package/blz-rds/commands/math/ceil.js +10 -0
- package/blz-rds/commands/math/cos.js +10 -0
- package/blz-rds/commands/math/cosh.js +10 -0
- package/blz-rds/commands/math/exp.js +10 -0
- package/blz-rds/commands/math/floor.js +10 -0
- package/blz-rds/commands/math/log.js +18 -0
- package/blz-rds/commands/math/log10.js +10 -0
- package/blz-rds/commands/math/pow.js +11 -0
- package/blz-rds/commands/math/random.js +9 -0
- package/blz-rds/commands/math/round.js +18 -0
- package/blz-rds/commands/math/sign.js +10 -0
- package/blz-rds/commands/math/sin.js +10 -0
- package/blz-rds/commands/math/sinh.js +10 -0
- package/blz-rds/commands/math/sqrt.js +10 -0
- package/blz-rds/commands/math/tan.js +10 -0
- package/blz-rds/commands/math/tanh.js +10 -0
- package/blz-rds/commands/math/trunc.js +18 -0
- package/blz-rds/commands/strings/concat.js +20 -0
- package/blz-rds/commands/strings/contains.js +12 -0
- package/blz-rds/commands/strings/ends-with.js +12 -0
- package/blz-rds/commands/strings/index-of.js +11 -0
- package/blz-rds/commands/strings/is-null-or-empty.js +11 -0
- package/blz-rds/commands/strings/is-null-or-white-space.js +11 -0
- package/blz-rds/commands/strings/join.js +22 -0
- package/blz-rds/commands/strings/last-index-of.js +11 -0
- package/blz-rds/commands/strings/length.js +10 -0
- package/blz-rds/commands/strings/pad-left.js +20 -0
- package/blz-rds/commands/strings/pad-right.js +20 -0
- package/blz-rds/commands/strings/replace.js +12 -0
- package/blz-rds/commands/strings/starts-with.js +12 -0
- package/blz-rds/commands/strings/substring.js +12 -0
- package/blz-rds/commands/strings/to-lower.js +10 -0
- package/blz-rds/commands/strings/to-upper.js +10 -0
- package/blz-rds/commands/strings/trim-end.js +10 -0
- package/blz-rds/commands/strings/trim-start.js +10 -0
- package/blz-rds/commands/strings/trim.js +10 -0
- package/blz-rds/index.js +744 -0
- package/blz-rds-mysql/base.js +857 -0
- package/blz-rds-mysql/connection-manager.js +129 -0
- package/blz-rds-mysql/execute-bulk-insert.js +35 -0
- package/blz-rds-mysql/execute-bulk-merge.js +45 -0
- package/blz-rds-mysql/execute-non-query.js +34 -0
- package/blz-rds-mysql/execute-query.js +50 -0
- package/blz-rds-mysql/index.js +41 -0
- package/blz-rds-mysql/stored-procedure.js +207 -0
- package/blz-rds-mysql/syntaxis.json +114 -0
- package/blz-rds-mysqlx/base.js +846 -0
- package/blz-rds-mysqlx/connection-manager.js +141 -0
- package/blz-rds-mysqlx/execute-bulk-insert.js +35 -0
- package/blz-rds-mysqlx/execute-bulk-merge.js +45 -0
- package/blz-rds-mysqlx/execute-non-query.js +29 -0
- package/blz-rds-mysqlx/execute-query.js +39 -0
- package/blz-rds-mysqlx/index.js +41 -0
- package/blz-rds-mysqlx/stored-procedure.js +179 -0
- package/blz-rds-mysqlx/syntaxis.json +105 -0
- package/blz-rds-oracle/index.js +540 -0
- package/blz-rds-oracle/syntaxis.json +112 -0
- package/blz-rds-postgres/base.js +861 -0
- package/blz-rds-postgres/connection-manager.js +225 -0
- package/blz-rds-postgres/execute-bulk-insert.js +81 -0
- package/blz-rds-postgres/execute-bulk-merge.js +93 -0
- package/blz-rds-postgres/execute-non-query.js +23 -0
- package/blz-rds-postgres/execute-query.js +37 -0
- package/blz-rds-postgres/index.js +41 -0
- package/blz-rds-postgres/result-set.js +51 -0
- package/blz-rds-postgres/stored-procedure.js +116 -0
- package/blz-rds-postgres/syntaxis.json +114 -0
- package/blz-redis/index.js +217 -0
- package/blz-redis/lib/redisCache.js +265 -0
- package/blz-regex/index.js +25 -0
- package/blz-security/.eslintrc.js +15 -0
- package/blz-security/__test__/AuthorizationKpn.yaml +1043 -0
- package/blz-security/__test__/FinancingSetting.yaml +177 -0
- package/blz-security/__test__/KpnConfigPortal.yaml +330 -0
- package/blz-security/__test__/OrderManagement.yaml +5190 -0
- package/blz-security/__test__/Security.yaml +128 -0
- package/blz-security/__test__/autorization.test.js +105 -0
- package/blz-security/__test__/orderManagement.test.js +26 -0
- package/blz-security/__test__/secureUrl.test.js +79 -0
- package/blz-security/__test__/solveMergeRule.test.js +109 -0
- package/blz-security/__test__/sqlInjectionGuard.test.js +203 -0
- package/blz-security/__test__/xssGuard.test.js +204 -0
- package/blz-security/authorizationService.js +536 -0
- package/blz-security/config/global.js +8 -0
- package/blz-security/config/welcome +8 -0
- package/blz-security/doc/README.md +75 -0
- package/blz-security/filescanner/index.js +46 -0
- package/blz-security/helpers/consts.js +229 -0
- package/blz-security/helpers/utils.js +267 -0
- package/blz-security/implementations/cache.js +90 -0
- package/blz-security/implementations/oidc.js +404 -0
- package/blz-security/implementations/pkceCacheStore.js +23 -0
- package/blz-security/implementations/saml.js +10 -0
- package/blz-security/implementations/uma.js +63 -0
- package/blz-security/implementations/webAuthn.js +9 -0
- package/blz-security/implementations/wstg.js +72 -0
- package/blz-security/index.js +77 -0
- package/blz-security/lab/index.js +27 -0
- package/blz-security/middleware/HapiServerAzureAd.js +641 -0
- package/blz-security/middleware/HapiServerKeycloak.js +840 -0
- package/blz-security/middleware/HapiServerSimToken.js +247 -0
- package/blz-security/middleware/hapi.js +515 -0
- package/blz-security/middleware/hapiServer.js +974 -0
- package/blz-security/navigationMemoryRepository.js +15 -0
- package/blz-security/navigationMongoDbRepository.js +73 -0
- package/blz-security/secureUrlService.js +47 -0
- package/blz-security/securityService.js +409 -0
- package/blz-security/sqlInjectionGuard.js +162 -0
- package/blz-security/templates/forbidden.html +0 -0
- package/blz-security/templates/session-iframe-azure-ad.html +7 -0
- package/blz-security/templates/session-iframe.html +73 -0
- package/blz-security/templates/unauthorized.html +1 -0
- package/blz-security/xssGuard.js +87 -0
- package/blz-strings/index.js +167 -0
- package/blz-uuid/index.js +7 -0
- package/blz-yaml/index.js +19 -0
- package/index.js +84 -0
- package/package.json +97 -0
- package/process-managers/index.js +422 -0
package/README.md
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
const fetch = require('node-fetch');
|
|
2
|
+
const logger = require('pino')();
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const safeRequire = function(path) {
|
|
6
|
+
try {
|
|
7
|
+
require.resolve(path);
|
|
8
|
+
return require(path);
|
|
9
|
+
} catch (err) {
|
|
10
|
+
if (err.code === 'MODULE_NOT_FOUND') {
|
|
11
|
+
let newPath = path.replace(/^\.\.\//, '');
|
|
12
|
+
if (path !== newPath) {
|
|
13
|
+
return safeRequire(newPath);
|
|
14
|
+
}
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
throw err;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// Try to load this modules. IF they are not present, they will be set to undefined
|
|
23
|
+
const mongoDb = safeRequire ('../../../essentials/extensions/blz-mongodb/sources-backend-nodejs/index.js') ||
|
|
24
|
+
safeRequire ('../../blz-mongodb/backend/index.js');
|
|
25
|
+
const kafka = safeRequire('../../../essentials/extensions/blz-kafka/sources-backend-nodejs/index.js') ||
|
|
26
|
+
safeRequire ('../../blz-kafka/backend/index.js');
|
|
27
|
+
const rds = safeRequire('../../../essentials/extensions/blz-rds/sources-backend-nodejs/index.js') ||
|
|
28
|
+
safeRequire ('../../blz-rds/backend/index.js');
|
|
29
|
+
|
|
30
|
+
// This function checks health for blz microservices and blz-bpm nodes.
|
|
31
|
+
async function healthCheckMicroservice (connection) {
|
|
32
|
+
let healthResponse = {}
|
|
33
|
+
const fullUrl = (connection.healthCheckPath) ? new URL(healthCheckPath.healthCheckPath, connection.url).toString() :
|
|
34
|
+
new URL("/blz-health-status", connection.url).toString();
|
|
35
|
+
try {
|
|
36
|
+
const response = await fetch(fullUrl);
|
|
37
|
+
if (response.ok) {
|
|
38
|
+
const data = await response.json();
|
|
39
|
+
healthResponse = {
|
|
40
|
+
name: connection.name, type: connection.type,
|
|
41
|
+
status: response.status, statusCode: response.statusCode, error: "-", internal: data
|
|
42
|
+
};
|
|
43
|
+
} else {
|
|
44
|
+
healthResponse = { name: connection.name, type: connection.type,
|
|
45
|
+
status: "error",
|
|
46
|
+
error: `HTTP Error: ${response.statusText}`
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
} catch (error) {
|
|
50
|
+
healthResponse = {
|
|
51
|
+
name: connection.name, type: connection.type,
|
|
52
|
+
status: "error", error: error.message
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return healthResponse;
|
|
56
|
+
}
|
|
57
|
+
async function healthCheckAllPossibleUrl (connection) {
|
|
58
|
+
let possiblePaths = ["/blz-health-status", "/health", "/actuator/health", "/"];
|
|
59
|
+
if (connection.healthCheckPath) {
|
|
60
|
+
// leave the defined path first for evaluation if defined in the config
|
|
61
|
+
possiblePaths.unshift(connection.healthCheckPath);
|
|
62
|
+
}
|
|
63
|
+
for (const path of possiblePaths) {
|
|
64
|
+
const fullUrl = new URL(path, connection.url).toString();
|
|
65
|
+
try {
|
|
66
|
+
const response = await fetch(fullUrl);
|
|
67
|
+
if (response.ok && path === "/blz-health-status") {
|
|
68
|
+
const data = await response.json();
|
|
69
|
+
return { status: response.status, url: fullUrl, data };
|
|
70
|
+
} else if (response.ok && path === "/health") {
|
|
71
|
+
return { status: response.status, url: fullUrl, data: "Connected with /Health API. httpCode 200." };
|
|
72
|
+
} else if (response.ok) {
|
|
73
|
+
return { status: response.status, url: fullUrl, data: "Connected with standard Http code 200 protocol. Endpoint: " + path };
|
|
74
|
+
}
|
|
75
|
+
} catch (error) {
|
|
76
|
+
logger.info(error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return { status: "error", message: "No valid health check endpoint found" };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function getHealthStatus(_buildSystem, _connections) {
|
|
83
|
+
let selfName = _buildSystem.name;
|
|
84
|
+
let selfType = _buildSystem.type;
|
|
85
|
+
let healthResponse = {};
|
|
86
|
+
|
|
87
|
+
// Add self-health check
|
|
88
|
+
healthResponse[selfName] = { name: selfName, type: "Self", status: "ok", error: "-" };
|
|
89
|
+
|
|
90
|
+
// Prepare all health check promises
|
|
91
|
+
const healthPromises = [];
|
|
92
|
+
|
|
93
|
+
for (const key in _connections) {
|
|
94
|
+
if (Object.prototype.hasOwnProperty.call(_connections, key)) {
|
|
95
|
+
const connection = _connections[key];
|
|
96
|
+
if (connection.name !== selfName) {
|
|
97
|
+
const promise = (async () => {
|
|
98
|
+
switch (connection.type) {
|
|
99
|
+
case "Microservice":
|
|
100
|
+
case "ProcessEngine":
|
|
101
|
+
return {
|
|
102
|
+
name: connection.name,
|
|
103
|
+
result: await healthCheckMicroservice(connection)
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
case "RestApi":
|
|
107
|
+
return {
|
|
108
|
+
name: connection.name,
|
|
109
|
+
result: await healthCheckAllPossibleUrl(connection)
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
case "Mongodb": {
|
|
113
|
+
if (!mongoDb){
|
|
114
|
+
return {
|
|
115
|
+
name: connection.name,
|
|
116
|
+
type: connection.type,
|
|
117
|
+
result: {
|
|
118
|
+
name: connection.name,
|
|
119
|
+
type: connection.type,
|
|
120
|
+
error: 'mongoDb module not present'
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const mongoHealthResponse = await mongoDb.mongodbConnectionHealthCheck(connection);
|
|
125
|
+
return {
|
|
126
|
+
name: connection.name,
|
|
127
|
+
result: {
|
|
128
|
+
name: connection.name,
|
|
129
|
+
type: connection.type,
|
|
130
|
+
...mongoHealthResponse
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
case "Kafka": {
|
|
136
|
+
if (!kafka){
|
|
137
|
+
return { name: connection.name, type: connection.type, error: 'kafka module not present' }
|
|
138
|
+
}
|
|
139
|
+
const kafkaHealthResponse = await kafka.kafkaConnectionHealthCheck(connection);
|
|
140
|
+
return {
|
|
141
|
+
name: connection.name,
|
|
142
|
+
result: {
|
|
143
|
+
name: connection.name,
|
|
144
|
+
type: connection.type,
|
|
145
|
+
...kafkaHealthResponse
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
case "RelationalDatabase": {
|
|
151
|
+
if (!rds){
|
|
152
|
+
return { name: connection.name, type: connection.type, error: 'rds module not present' }
|
|
153
|
+
}
|
|
154
|
+
const callContext = {
|
|
155
|
+
callStack: [],
|
|
156
|
+
callVariables: {},
|
|
157
|
+
currentUrl: '',
|
|
158
|
+
description: 'GET /health',
|
|
159
|
+
systemName: selfName,
|
|
160
|
+
systemType: selfType
|
|
161
|
+
};
|
|
162
|
+
const rdsHealthResponse = await rds.rdsConnectionHealthCheck(connection, callContext);
|
|
163
|
+
return {
|
|
164
|
+
name: connection.name,
|
|
165
|
+
result: {
|
|
166
|
+
name: connection.name,
|
|
167
|
+
type: connection.type,
|
|
168
|
+
...rdsHealthResponse
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
default:
|
|
174
|
+
return {
|
|
175
|
+
name: connection.name,
|
|
176
|
+
result: {
|
|
177
|
+
name: connection.name,
|
|
178
|
+
type: connection.type,
|
|
179
|
+
status: "Not Implemented",
|
|
180
|
+
error: "Not Implemented"
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
})();
|
|
185
|
+
healthPromises.push(promise);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Await all in parallel
|
|
191
|
+
const results = await Promise.all(healthPromises);
|
|
192
|
+
for (const { name, result } of results) {
|
|
193
|
+
healthResponse[name] = result;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return healthResponse;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// not yet used, but will be necesary in the future when object requires to be standardized
|
|
200
|
+
function assembleHealthResponseObject(connection, state) {
|
|
201
|
+
let healthResponse = {
|
|
202
|
+
name: connection.name,
|
|
203
|
+
type: connection.type,
|
|
204
|
+
status: state.status,
|
|
205
|
+
statusCode: state.statusCode,
|
|
206
|
+
error: state.error,
|
|
207
|
+
internal: state.internal
|
|
208
|
+
};
|
|
209
|
+
return healthResponse
|
|
210
|
+
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
module.exports = {
|
|
214
|
+
getHealthStatus
|
|
215
|
+
};
|