@sera4/essentia 1.1.66-rc.1 → 3.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.
- package/README.md +352 -8
- package/dist/ts/index.d.ts +1 -2
- package/dist/ts/index.js +1 -3
- package/dist/ts/index.js.map +1 -1
- package/dist/ts/logger/s4-logger.js +0 -2
- package/dist/ts/logger/s4-logger.js.map +1 -1
- package/dist/ts/queue/index.d.ts +2 -38
- package/dist/ts/queue/index.js +67 -136
- package/dist/ts/queue/index.js.map +1 -1
- package/package.json +51 -12
- package/package.tar.gz +0 -0
- package/cache/index.js +0 -188
- package/constants/index.js +0 -9
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/configurations/index.html +0 -116
- package/coverage/configurations/server-config.ts.html +0 -94
- package/coverage/dns/DnsCache.ts.html +0 -598
- package/coverage/dns/index.html +0 -131
- package/coverage/dns/index.ts.html +0 -94
- package/coverage/favicon.png +0 -0
- package/coverage/health/index.html +0 -116
- package/coverage/health/index.ts.html +0 -778
- package/coverage/index.html +0 -161
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/configurations/index.html +0 -116
- package/coverage/lcov-report/configurations/server-config.ts.html +0 -94
- package/coverage/lcov-report/dns/DnsCache.ts.html +0 -598
- package/coverage/lcov-report/dns/index.html +0 -131
- package/coverage/lcov-report/dns/index.ts.html +0 -94
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/health/index.html +0 -116
- package/coverage/lcov-report/health/index.ts.html +0 -778
- package/coverage/lcov-report/index.html +0 -161
- package/coverage/lcov-report/logger/index.html +0 -131
- package/coverage/lcov-report/logger/index.ts.html +0 -94
- package/coverage/lcov-report/logger/s4-logger.ts.html +0 -514
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov.info +0 -747
- package/coverage/logger/index.html +0 -131
- package/coverage/logger/index.ts.html +0 -94
- package/coverage/logger/s4-logger.ts.html +0 -514
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -196
- package/coverage/tmp/coverage-24302-1746472691313-0.json +0 -1
- package/coverage/tmp/coverage-24302-1746472691366-1.json +0 -1
- package/dist/cache/index.d.ts +0 -22
- package/dist/cache/index.js +0 -166
- package/dist/cache/index.js.map +0 -1
- package/dist/constants/index.d.ts +0 -6
- package/dist/constants/index.js +0 -9
- package/dist/constants/index.js.map +0 -1
- package/dist/coverage/block-navigation.d.ts +0 -1
- package/dist/coverage/block-navigation.js +0 -70
- package/dist/coverage/block-navigation.js.map +0 -1
- package/dist/coverage/lcov-report/block-navigation.d.ts +0 -1
- package/dist/coverage/lcov-report/block-navigation.js +0 -70
- package/dist/coverage/lcov-report/block-navigation.js.map +0 -1
- package/dist/coverage/lcov-report/prettify.d.ts +0 -0
- package/dist/coverage/lcov-report/prettify.js +0 -477
- package/dist/coverage/lcov-report/prettify.js.map +0 -1
- package/dist/coverage/lcov-report/sorter.d.ts +0 -1
- package/dist/coverage/lcov-report/sorter.js +0 -163
- package/dist/coverage/lcov-report/sorter.js.map +0 -1
- package/dist/coverage/prettify.d.ts +0 -0
- package/dist/coverage/prettify.js +0 -477
- package/dist/coverage/prettify.js.map +0 -1
- package/dist/coverage/sorter.d.ts +0 -1
- package/dist/coverage/sorter.js +0 -163
- package/dist/coverage/sorter.js.map +0 -1
- package/dist/formatter/index.d.ts +0 -37
- package/dist/formatter/index.js +0 -75
- package/dist/formatter/index.js.map +0 -1
- package/dist/hal/index.d.ts +0 -5
- package/dist/hal/index.js +0 -69
- package/dist/hal/index.js.map +0 -1
- package/dist/health/health-logger.d.ts +0 -9
- package/dist/health/health-logger.js +0 -34
- package/dist/health/health-logger.js.map +0 -1
- package/dist/health/index.d.ts +0 -19
- package/dist/health/index.js +0 -175
- package/dist/health/index.js.map +0 -1
- package/dist/helpers/index.d.ts +0 -1
- package/dist/helpers/index.js +0 -2
- package/dist/helpers/index.js.map +0 -1
- package/dist/helpers/test-server-wrapper.d.ts +0 -120
- package/dist/helpers/test-server-wrapper.js +0 -165
- package/dist/helpers/test-server-wrapper.js.map +0 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -17
- package/dist/index.js.map +0 -1
- package/dist/last-commit.d.ts +0 -1
- package/dist/last-commit.js +0 -12
- package/dist/last-commit.js.map +0 -1
- package/dist/last_commit/index.d.ts +0 -7
- package/dist/last_commit/index.js +0 -83
- package/dist/last_commit/index.js.map +0 -1
- package/dist/paginator/s4-pagination.d.ts +0 -9
- package/dist/paginator/s4-pagination.js +0 -49
- package/dist/paginator/s4-pagination.js.map +0 -1
- package/dist/paginator/sql-pagination.d.ts +0 -27
- package/dist/paginator/sql-pagination.js +0 -166
- package/dist/paginator/sql-pagination.js.map +0 -1
- package/dist/paper-trail/helpers.d.ts +0 -11
- package/dist/paper-trail/helpers.js +0 -74
- package/dist/paper-trail/helpers.js.map +0 -1
- package/dist/paper-trail/index.d.ts +0 -13
- package/dist/paper-trail/index.js +0 -662
- package/dist/paper-trail/index.js.map +0 -1
- package/dist/prompts/index.d.ts +0 -14
- package/dist/prompts/index.js +0 -63
- package/dist/prompts/index.js.map +0 -1
- package/dist/queue/index.d.ts +0 -166
- package/dist/queue/index.js +0 -371
- package/dist/queue/index.js.map +0 -1
- package/dist/queue/publisher.d.ts +0 -31
- package/dist/queue/publisher.js +0 -84
- package/dist/queue/publisher.js.map +0 -1
- package/dist/queue/queue-logger.d.ts +0 -9
- package/dist/queue/queue-logger.js +0 -35
- package/dist/queue/queue-logger.js.map +0 -1
- package/dist/queue/subscriber.d.ts +0 -39
- package/dist/queue/subscriber.js +0 -97
- package/dist/queue/subscriber.js.map +0 -1
- package/dist/safe_proxy/index.d.ts +0 -13
- package/dist/safe_proxy/index.js +0 -54
- package/dist/safe_proxy/index.js.map +0 -1
- package/dist/serializer/index.d.ts +0 -5
- package/dist/serializer/index.js +0 -83
- package/dist/serializer/index.js.map +0 -1
- package/dist/test/debug-array.d.ts +0 -0
- package/dist/test/debug-array.js +0 -1
- package/dist/test/debug-array.js.map +0 -1
- package/dist/test/debug-setJSONB.d.ts +0 -0
- package/dist/test/debug-setJSONB.js +0 -1
- package/dist/test/debug-setJSONB.js.map +0 -1
- package/dist/test/prompt.test.d.ts +0 -1
- package/dist/test/prompt.test.js +0 -74
- package/dist/test/prompt.test.js.map +0 -1
- package/dist/test/s4-formatter.spec.d.ts +0 -1
- package/dist/test/s4-formatter.spec.js +0 -67
- package/dist/test/s4-formatter.spec.js.map +0 -1
- package/dist/test/s4-pagination.spec.d.ts +0 -1
- package/dist/test/s4-pagination.spec.js +0 -170
- package/dist/test/s4-pagination.spec.js.map +0 -1
- package/dist/test/safe-proxy.spec.d.ts +0 -1
- package/dist/test/safe-proxy.spec.js +0 -252
- package/dist/test/safe-proxy.spec.js.map +0 -1
- package/dist/test/serializer.spec.d.ts +0 -1
- package/dist/test/serializer.spec.js +0 -27
- package/dist/test/serializer.spec.js.map +0 -1
- package/dist/test/utils.spec.d.ts +0 -1
- package/dist/test/utils.spec.js +0 -446
- package/dist/test/utils.spec.js.map +0 -1
- package/dist/ts/task-scheduler/index.d.ts +0 -130
- package/dist/ts/task-scheduler/index.js +0 -259
- package/dist/ts/task-scheduler/index.js.map +0 -1
- package/formatter/index.js +0 -81
- package/hal/README.md +0 -54
- package/hal/index.js +0 -75
- package/health/health-logger.js +0 -40
- package/health/index.js +0 -188
- package/helpers/index.js +0 -1
- package/helpers/test-server-wrapper.js +0 -196
- package/last-commit.js +0 -12
- package/last_commit/index.js +0 -82
- package/logger/s4-logger.js +0 -128
- package/paginator/README.md +0 -183
- package/paginator/s4-pagination.js +0 -51
- package/paginator/sql-pagination.js +0 -178
- package/paper-trail/README.md +0 -68
- package/paper-trail/helpers.js +0 -99
- package/paper-trail/index.js +0 -843
- package/prompts/index.js +0 -78
- package/queue/index.js +0 -402
- package/queue/publisher.js +0 -96
- package/queue/queue-logger.js +0 -40
- package/queue/subscriber.js +0 -107
- package/safe_proxy/index.js +0 -61
- package/scripts/publish.sh +0 -46
- package/serializer/index.js +0 -90
- package/test/health.spec.js +0 -213
- package/test/prompt.test.js +0 -91
- package/test/s4-formatter.spec.js +0 -80
- package/test/s4-pagination.spec.js +0 -196
- package/test/serializer.spec.js +0 -34
- package/test/utils.spec.js +0 -145
- package/utils/index.js +0 -74
package/health/index.js
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"use strict"
|
|
2
|
-
|
|
3
|
-
import pathHelper from "path";
|
|
4
|
-
import logger from "./health-logger.js";
|
|
5
|
-
import morgan from "morgan";
|
|
6
|
-
|
|
7
|
-
class HealthCheckError extends Error {}
|
|
8
|
-
|
|
9
|
-
/* Health Checking router + controller for use in all of our modules
|
|
10
|
-
* Example use: Place the following code in your routes file
|
|
11
|
-
*
|
|
12
|
-
* import { healthCheck } from "@sera4/essentia";
|
|
13
|
-
* const router = require('express').Router();
|
|
14
|
-
*
|
|
15
|
-
* ....
|
|
16
|
-
*
|
|
17
|
-
* const checkRedis = async () => { await cache.ping(); }
|
|
18
|
-
* hc.setupCheck({ name: "redis", checkResult: false, critical: true, healthFunction: checkRedis });
|
|
19
|
-
* app.use(hc.defaultPath(serverConfigs.api_prefix), hc.routes(router));
|
|
20
|
-
*
|
|
21
|
-
*/
|
|
22
|
-
class HealthCheck {
|
|
23
|
-
constructor(appendData = {}, enableLogging = true) {
|
|
24
|
-
logger.setEnabled(enableLogging);
|
|
25
|
-
|
|
26
|
-
this.defaultResponse = {
|
|
27
|
-
...
|
|
28
|
-
appendData,
|
|
29
|
-
status: 200,
|
|
30
|
-
errors: {}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
this.defaultPathRoute = `health_check\(.*\)?`
|
|
34
|
-
this.suppressLogs = false;
|
|
35
|
-
this.lastCallId = 0; // default start point/integer
|
|
36
|
-
this.pathPrefix = "";
|
|
37
|
-
this.healthChecks = [];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/* Deprecated and replaced by setupCheck
|
|
41
|
-
* call this with an async function, must support wait capability
|
|
42
|
-
*
|
|
43
|
-
* const dbCheck = async () => {
|
|
44
|
-
* return { name: "db", "result": "success", critical: false };
|
|
45
|
-
* }
|
|
46
|
-
*/
|
|
47
|
-
addCheck(fcn) {
|
|
48
|
-
this.healthChecks.push(fcn);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
setPrefix(prefix) {
|
|
52
|
-
this.pathPrefix = prefix;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
defaultPath(prefix = "") {
|
|
56
|
-
if (prefix === "") {
|
|
57
|
-
prefix = this.pathPrefix; // maybe setup manually
|
|
58
|
-
}
|
|
59
|
-
return `${prefix}/${this.defaultPathRoute}`
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
routes(router) {
|
|
63
|
-
if (!router) {
|
|
64
|
-
throw new HealthCheckError("missing_express_router");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/* definition of all routes, rooted at defaultPath */
|
|
68
|
-
router.get('/', (req, res) => {
|
|
69
|
-
this.checkHealth(req, res)
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
return router
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
suppressHealthCheckLog(app) {
|
|
76
|
-
// Custom morgan skip function to ignore health check logging
|
|
77
|
-
console.log("skip: ", this.defaultPath())
|
|
78
|
-
app.use(morgan('combined', {
|
|
79
|
-
skip: (req) => req.path === defaultPath()
|
|
80
|
-
}));
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// v2 version of health check, replaced addCheck
|
|
84
|
-
// example:
|
|
85
|
-
// const checkRedisFcn = async () => { await cache.ping().then(() => true) }
|
|
86
|
-
// setupCheck({ name: "redis", checkResult: false, critical: false, healthFunction: checkRedisFcn });
|
|
87
|
-
setupCheck(config) {
|
|
88
|
-
this.healthChecks.push(config);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/* performs health checks and returns 200 if true and 500 if not */
|
|
92
|
-
async checkHealth(req, res) {
|
|
93
|
-
const checkFormat = pathHelper.extname(req.baseUrl);
|
|
94
|
-
|
|
95
|
-
const result = await Promise.all(this.healthChecks.map(async hc => {
|
|
96
|
-
if (typeof(hc) === "function") {
|
|
97
|
-
try {
|
|
98
|
-
return await hc();
|
|
99
|
-
} catch(e) {
|
|
100
|
-
return { name: "unknown", result: 'fail', status: e.status }
|
|
101
|
-
}
|
|
102
|
-
} else {
|
|
103
|
-
let res = { name: hc.name, critical: hc.critical }
|
|
104
|
-
try {
|
|
105
|
-
const result = await hc.healthFunction();
|
|
106
|
-
if (typeof(result) === "boolean") {
|
|
107
|
-
if (result === false) {
|
|
108
|
-
res = {"result": "fail", ...res }
|
|
109
|
-
} else {
|
|
110
|
-
res = {"result": "success", ...res }
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
res = {"result": "success", ...res }
|
|
114
|
-
}
|
|
115
|
-
return res;
|
|
116
|
-
} catch(e) {
|
|
117
|
-
const appendStatus = e.status ? ` (${e.status})` : ""
|
|
118
|
-
logger.warn(`${hc.name} service failed${appendStatus}` )
|
|
119
|
-
return { ...res, "result": "fail", status: e.status }
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}));
|
|
123
|
-
|
|
124
|
-
try {
|
|
125
|
-
let callId = ++this.lastCallId;
|
|
126
|
-
|
|
127
|
-
// start the counter over
|
|
128
|
-
if ((callId % (1 << 30)) === 0) {
|
|
129
|
-
callId = this.lastCallId = 1;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
let status = this.defaultResponse.status;
|
|
133
|
-
|
|
134
|
-
let nonCriticalFail = false;
|
|
135
|
-
let criticalFail = false;
|
|
136
|
-
|
|
137
|
-
result.some(e => {
|
|
138
|
-
if (e.result.match(/fail/)) {
|
|
139
|
-
if (e.critical === false) {
|
|
140
|
-
nonCriticalFail = true;
|
|
141
|
-
} else {
|
|
142
|
-
criticalFail = true;
|
|
143
|
-
status = 500;
|
|
144
|
-
return true; // break
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
// set this in the header no matter what
|
|
150
|
-
res.setHeader('check', callId)
|
|
151
|
-
|
|
152
|
-
if (checkFormat === ".json") {
|
|
153
|
-
const payload = { "check": callId, healthy: "true", message: "success" }
|
|
154
|
-
|
|
155
|
-
if (criticalFail) {
|
|
156
|
-
res.status(status).json({
|
|
157
|
-
... payload,
|
|
158
|
-
"healthy": false,
|
|
159
|
-
"message": "fail",
|
|
160
|
-
"services": result
|
|
161
|
-
});
|
|
162
|
-
} else if (nonCriticalFail) {
|
|
163
|
-
res.status(status).json({
|
|
164
|
-
... payload,
|
|
165
|
-
"message": "fail",
|
|
166
|
-
"services": result
|
|
167
|
-
});
|
|
168
|
-
} else if (status === 200) {
|
|
169
|
-
res.status(status).json(payload);
|
|
170
|
-
}
|
|
171
|
-
} else {
|
|
172
|
-
let status_message;
|
|
173
|
-
if (criticalFail) {
|
|
174
|
-
status_message = "fail"
|
|
175
|
-
} else if ((status === 200) || nonCriticalFail) {
|
|
176
|
-
status_message = "success"
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
res.status(status).send(status_message);
|
|
180
|
-
}
|
|
181
|
-
} catch(error) {
|
|
182
|
-
console.warn("error: ", error)
|
|
183
|
-
res.status(500).send();
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
export { HealthCheck };
|
package/helpers/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./test-server-wrapper.js";
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
|
|
4
|
-
const s4Domain = "sera4.com";
|
|
5
|
-
const mobileDomain = "tws-mob." + s4Domain;
|
|
6
|
-
const webDomain = "tws-web." + s4Domain;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A small wrapper around an express js server
|
|
10
|
-
* meant to be used in unit tests
|
|
11
|
-
*/
|
|
12
|
-
export class TestServerWrapper {
|
|
13
|
-
|
|
14
|
-
constructor(apiPrefix, expressServer, defaultHeaders, oldAuthToken, routePrinter, chai, factory) {
|
|
15
|
-
this.server = expressServer;
|
|
16
|
-
this.defaultHeaders = defaultHeaders;
|
|
17
|
-
this.apiPrefix = apiPrefix;
|
|
18
|
-
this.routePrinter = routePrinter;
|
|
19
|
-
this.chai = chai;
|
|
20
|
-
this.mobileDomain = mobileDomain;
|
|
21
|
-
this.webDomain = webDomain;
|
|
22
|
-
this.factory = factory;
|
|
23
|
-
|
|
24
|
-
// Support for older/deprecated apis
|
|
25
|
-
const oldAuthHeaders = {headers: {"Authorization" : `Token organization_token=${oldAuthToken}`}};
|
|
26
|
-
this.v1 = {
|
|
27
|
-
get: (url) => this.getWithPrefix("/v1", url, oldAuthHeaders),
|
|
28
|
-
post: (url) => this.postWithPrefix("/v1", url, oldAuthHeaders),
|
|
29
|
-
put: (url) => this.putWithPrefix("/v1", url, oldAuthHeaders),
|
|
30
|
-
delete: (url) => this.deleteWithPrefix("/v1", url, oldAuthHeaders)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Adds a leading slash to the url if missing
|
|
36
|
-
* @param {String} url the url to sanitize
|
|
37
|
-
* @returns sanitized url
|
|
38
|
-
*/
|
|
39
|
-
sanitizeUrl (url) {
|
|
40
|
-
// add leading slash if missing
|
|
41
|
-
if (!url.startsWith("/")) {
|
|
42
|
-
return "/" + url;
|
|
43
|
-
} else {
|
|
44
|
-
return url;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Apply given headers to the request object
|
|
50
|
-
* @param {Object} request
|
|
51
|
-
* @param {Object} headers
|
|
52
|
-
*/
|
|
53
|
-
applyHeaders (request, headers) {
|
|
54
|
-
Object.keys(headers).map(k => {
|
|
55
|
-
request.set(k, headers[k]);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get (url, options) {
|
|
60
|
-
return this.getWithPrefix(this.apiPrefix, url, options);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
getWithPrefix (prefix, url, options) {
|
|
64
|
-
const sanitizedUrl = this.sanitizeUrl(url);
|
|
65
|
-
const request = this.chai.request(this.server).get(`${prefix}${sanitizedUrl}`);
|
|
66
|
-
this.applyHeaders(request, this.defaultHeaders);
|
|
67
|
-
|
|
68
|
-
if (options?.headers) {
|
|
69
|
-
this.applyHeaders(request, options.headers);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (options?.body) {
|
|
73
|
-
request.send(options.body);
|
|
74
|
-
}
|
|
75
|
-
return request;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
post (url, options) {
|
|
79
|
-
return this.postWithPrefix(this.apiPrefix, url, options);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
postWithPrefix (prefix, url, options) {
|
|
83
|
-
const sanitizedUrl = this.sanitizeUrl(url);
|
|
84
|
-
const request = this.chai.request(this.server).post(`${prefix}${sanitizedUrl}`);
|
|
85
|
-
this.applyHeaders(request, this.defaultHeaders);
|
|
86
|
-
|
|
87
|
-
if (options?.headers) {
|
|
88
|
-
this.applyHeaders(request, options.headers);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return request;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
put (url, options) {
|
|
95
|
-
return this.putWithPrefix(this.apiPrefix, url, options);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
putWithPrefix (prefix, url, options) {
|
|
99
|
-
const sanitizedUrl = this.sanitizeUrl(url);
|
|
100
|
-
const request = this.chai.request(this.server).put(`${prefix}${sanitizedUrl}`);
|
|
101
|
-
this.applyHeaders(request, this.defaultHeaders);
|
|
102
|
-
|
|
103
|
-
if (options?.headers) {
|
|
104
|
-
this.applyHeaders(request, options.headers);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return request;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
delete (url, options) {
|
|
111
|
-
return this.deleteWithPrefix(this.apiPrefix, url, options);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
deleteWithPrefix (prefix, url, options) {
|
|
115
|
-
const sanitizedUrl = this.sanitizeUrl(url);
|
|
116
|
-
const request = this.chai.request(this.server).delete(`${prefix}${sanitizedUrl}`);
|
|
117
|
-
this.applyHeaders(request, this.defaultHeaders);
|
|
118
|
-
|
|
119
|
-
if (options?.headers) {
|
|
120
|
-
this.applyHeaders(request, options.headers);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return request;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
upload ( url, fields, file, options) {
|
|
127
|
-
return this.uploadWithPrefix(this.apiPrefix, url, fields, file, options);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
uploadWithPrefix (prefix, url, fields, file, options) {
|
|
131
|
-
const sanitizedUrl = this.sanitizeUrl(url);
|
|
132
|
-
const request = this.chai.request(this.server).post(`${prefix}${sanitizedUrl}`);
|
|
133
|
-
this.applyHeaders(request, this.defaultHeaders);
|
|
134
|
-
|
|
135
|
-
if (options?.headers) {
|
|
136
|
-
this.applyHeaders(request, options.headers);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
request.attach("data", fs.readFileSync(file), {filename: "data"});
|
|
140
|
-
const keys = Object.keys(fields);
|
|
141
|
-
keys.forEach(k => {
|
|
142
|
-
request.field(k, fields[k]);
|
|
143
|
-
});
|
|
144
|
-
return request;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
stop () {
|
|
148
|
-
this.server.close();
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
allRoutes () {
|
|
152
|
-
return this.routePrinter.getAll();
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
withHeaders (headers) {
|
|
156
|
-
return {
|
|
157
|
-
get: (url, options) => this.get(url, {headers, ...options}),
|
|
158
|
-
post: (url, options) => this.post(url, {headers, ...options}),
|
|
159
|
-
put: (url, options) => this.put(url, {headers, ...options}),
|
|
160
|
-
delete: (url, options) => this.delete(url, {headers, ...options}),
|
|
161
|
-
upload: (url, fields, file, options) => this.upload(url, fields, file, {headers, ...options}),
|
|
162
|
-
stop: this.stop,
|
|
163
|
-
allRoutes: this.allRoutes,
|
|
164
|
-
v1: this.v1
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// setup
|
|
169
|
-
async setMembership (membership, addlHeaders) {
|
|
170
|
-
let headers;
|
|
171
|
-
|
|
172
|
-
if (membership) {
|
|
173
|
-
headers = { "tws-account-id" : membership.account_id, "tws-membership-id": membership.id, "tws-tenant-id" : membership.tenant_id };
|
|
174
|
-
} else {
|
|
175
|
-
// auto create an s4 user
|
|
176
|
-
const m = await this.factory.create("membership", { s4Admin: true })
|
|
177
|
-
headers = { "tws-account-id" : m.account_id, "tws-membership-id": m.id, "tws-tenant-id" : m.tenant_id };
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
headers = { ...headers, "tws-request-host": this.webDomain, ...addlHeaders }
|
|
181
|
-
return this.withHeaders(headers);
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
withMembership (m) {
|
|
185
|
-
const h = { "tws-membership" : JSON.stringify(m) }
|
|
186
|
-
return this.withHeaders(h);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
withS4 () {
|
|
190
|
-
return this.withMembership({s4_role: 1, id: uuidv4(), account_id: uuidv4(), tenant_id: uuidv4()});
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
withTap() {
|
|
194
|
-
return this.withMembership({s4_role: 2, id: uuidv4(), account_id: uuidv4(), tenant_id: uuidv4()});
|
|
195
|
-
}
|
|
196
|
-
}
|
package/last-commit.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import lastCommit from "./last_commit/index.js"
|
|
3
|
-
|
|
4
|
-
lastCommit.writeLastCommit()
|
|
5
|
-
.then(c => {
|
|
6
|
-
console.debug("Last commit written");
|
|
7
|
-
console.debug(c);
|
|
8
|
-
})
|
|
9
|
-
.catch(e => {
|
|
10
|
-
console.error("Failed to write last commit");
|
|
11
|
-
console.error(e);
|
|
12
|
-
})
|
package/last_commit/index.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import git from "git-rev";
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import async from "async";
|
|
6
|
-
import { dirname } from 'path';
|
|
7
|
-
import { fileURLToPath } from 'url';
|
|
8
|
-
|
|
9
|
-
const appDir = dirname(fileURLToPath(import.meta.url));
|
|
10
|
-
const commitFile = `${appDir}/last-commit.json`;
|
|
11
|
-
|
|
12
|
-
const lastCommit = {
|
|
13
|
-
parseLastCommit() {
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
async.waterfall([
|
|
16
|
-
(next) => {
|
|
17
|
-
var commit = {};
|
|
18
|
-
git.branch((str) => {
|
|
19
|
-
commit["branch"] = str;
|
|
20
|
-
next(null, commit);
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
(commit, next) => {
|
|
24
|
-
git.long((str) => {
|
|
25
|
-
commit["commmit"] = str;
|
|
26
|
-
next(null, commit);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
], (err, commit) => {
|
|
30
|
-
if (err) {
|
|
31
|
-
reject(err);
|
|
32
|
-
} else {
|
|
33
|
-
resolve(commit);
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
})
|
|
37
|
-
},
|
|
38
|
-
getLastCommit() {
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
fs.readFile(commitFile, 'utf8', (err, data) => {
|
|
41
|
-
if (err) {
|
|
42
|
-
reject(err);
|
|
43
|
-
} else {
|
|
44
|
-
try {
|
|
45
|
-
var commit = JSON.parse(data);
|
|
46
|
-
resolve(commit);
|
|
47
|
-
} catch (e) {
|
|
48
|
-
reject(e);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
},
|
|
54
|
-
getLastCommitSync() {
|
|
55
|
-
var data = fs.readFileSync(commitFile, 'utf8');
|
|
56
|
-
return JSON.parse(data);
|
|
57
|
-
},
|
|
58
|
-
writeLastCommit() {
|
|
59
|
-
return new Promise((resolve, reject) => {
|
|
60
|
-
async.waterfall([
|
|
61
|
-
(next) => {
|
|
62
|
-
this.parseLastCommit()
|
|
63
|
-
.then((commit) => next(null, commit))
|
|
64
|
-
.catch(e => next(e));
|
|
65
|
-
},
|
|
66
|
-
(commit, next) => {
|
|
67
|
-
fs.writeFile(commitFile, JSON.stringify(commit, null, 2), 'utf8', (err) => {
|
|
68
|
-
next(err, commit);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
],(err, commit) => {
|
|
72
|
-
if (err) {
|
|
73
|
-
reject(err);
|
|
74
|
-
} else {
|
|
75
|
-
resolve(commit);
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export default lastCommit;
|
package/logger/s4-logger.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import winston from "winston";
|
|
2
|
-
import util from "util";
|
|
3
|
-
import jsonStringify from "fast-safe-stringify";
|
|
4
|
-
const colorizer = winston.format.colorize();
|
|
5
|
-
import "winston-logstash";
|
|
6
|
-
|
|
7
|
-
// IETF RFC5424:
|
|
8
|
-
// Severity of all levels is assumed to be numerically ascending from most important to least important.
|
|
9
|
-
const levels = {
|
|
10
|
-
error: 0,
|
|
11
|
-
warn: 1,
|
|
12
|
-
info: 2,
|
|
13
|
-
debug: 3,
|
|
14
|
-
trace: 4,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// These colors are not used, however if colors are not defined for custom levels
|
|
18
|
-
// then winston will throw an exception.
|
|
19
|
-
winston.addColors({
|
|
20
|
-
trace: 'white'
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const defaultLevel = process.env.NODE_ENV === 'production' ? 'info' : 'debug';
|
|
24
|
-
|
|
25
|
-
// These colors are not used, however if colors are not defined for custom levels
|
|
26
|
-
// then winston will throw an exception.
|
|
27
|
-
winston.addColors({
|
|
28
|
-
trace: 'white'
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const devFormat = {
|
|
32
|
-
transform(info) {
|
|
33
|
-
const { message } = info;
|
|
34
|
-
const level = info[Symbol.for('level')];
|
|
35
|
-
const args = info[Symbol.for('splat')];
|
|
36
|
-
const strArgs = args ? args.map(jsonStringify).join(' ') : "";
|
|
37
|
-
info[Symbol.for('message')] = colorizer.colorize(level, `${level}:\t`) + `${message} ${strArgs}`;
|
|
38
|
-
return info;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const defaultTransport = new winston.transports.Console({
|
|
43
|
-
format: devFormat,
|
|
44
|
-
level: 'trace'
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const logger = winston.createLogger({
|
|
48
|
-
levels: levels,
|
|
49
|
-
level: defaultLevel,
|
|
50
|
-
defaultMeta: { },
|
|
51
|
-
transports: [defaultTransport]
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
class S4Logger {
|
|
55
|
-
configure(options) {
|
|
56
|
-
if (!options) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.setLevel(options.level);
|
|
61
|
-
|
|
62
|
-
logger.defaultMeta.service = options.service;
|
|
63
|
-
switch(options.format.toLowerCase()) {
|
|
64
|
-
case "logstash":
|
|
65
|
-
defaultTransport.format = winston.format.logstash();
|
|
66
|
-
break;
|
|
67
|
-
case "json":
|
|
68
|
-
defaultTransport.format = winston.format.json();
|
|
69
|
-
break;
|
|
70
|
-
default:
|
|
71
|
-
defaultTransport.format = devFormat;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
setLevel(level) {
|
|
77
|
-
if (level && ["trace", "debug", "info", "error", "warn"].indexOf(level.toLowerCase())) {
|
|
78
|
-
logger.level = level;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
mute() {
|
|
83
|
-
logger.transports.forEach(t => {
|
|
84
|
-
t.silent = true;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
unmute() {
|
|
89
|
-
logger.transports.forEach(t => {
|
|
90
|
-
t.silent = false;
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
trace(...args) {
|
|
95
|
-
logger.trace(util.format(...args));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
debug(...args) {
|
|
99
|
-
logger.debug(util.format(...args));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
log(...args) {
|
|
103
|
-
logger.debug(util.format(...args));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
warn(...args) {
|
|
107
|
-
logger.warn(util.format(...args));
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
info(...args) {
|
|
111
|
-
logger.info(util.format(...args));
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
error(...args) {
|
|
115
|
-
logger.error(util.format(...args));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
getStream() {
|
|
119
|
-
return {
|
|
120
|
-
write: function(message, encoding){
|
|
121
|
-
logger.info(message);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const s4logger = new S4Logger();
|
|
128
|
-
export default s4logger;
|