@sera4/essentia 3.0.12 → 3.0.13
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/package.json +9 -3
- package/package.tar.gz +0 -0
- package/scripts/publish.sh +46 -0
- package/dist/ts/cache/index.d.ts +0 -33
- package/dist/ts/cache/index.js +0 -171
- package/dist/ts/cache/index.js.map +0 -1
- package/dist/ts/configurations/server-config.d.ts +0 -4
- package/dist/ts/configurations/server-config.js +0 -2
- package/dist/ts/configurations/server-config.js.map +0 -1
- package/dist/ts/constants/index.d.ts +0 -7
- package/dist/ts/constants/index.js +0 -8
- package/dist/ts/constants/index.js.map +0 -1
- package/dist/ts/cycle/index.d.ts +0 -53
- package/dist/ts/cycle/index.js +0 -169
- package/dist/ts/cycle/index.js.map +0 -1
- package/dist/ts/dns/DnsCache.d.ts +0 -50
- package/dist/ts/dns/DnsCache.js +0 -137
- package/dist/ts/dns/DnsCache.js.map +0 -1
- package/dist/ts/dns/index.d.ts +0 -4
- package/dist/ts/dns/index.js +0 -4
- package/dist/ts/dns/index.js.map +0 -1
- package/dist/ts/formatter/index.d.ts +0 -44
- package/dist/ts/formatter/index.js +0 -76
- package/dist/ts/formatter/index.js.map +0 -1
- package/dist/ts/hal/index.d.ts +0 -26
- package/dist/ts/hal/index.js +0 -70
- package/dist/ts/hal/index.js.map +0 -1
- package/dist/ts/health/index.d.ts +0 -53
- package/dist/ts/health/index.js +0 -165
- package/dist/ts/health/index.js.map +0 -1
- package/dist/ts/helpers/index.d.ts +0 -1
- package/dist/ts/helpers/index.js +0 -2
- package/dist/ts/helpers/index.js.map +0 -1
- package/dist/ts/helpers/test-server-wrapper.d.ts +0 -56
- package/dist/ts/helpers/test-server-wrapper.js +0 -144
- package/dist/ts/helpers/test-server-wrapper.js.map +0 -1
- package/dist/ts/index.d.ts +0 -22
- package/dist/ts/index.js +0 -27
- package/dist/ts/index.js.map +0 -1
- package/dist/ts/last-commit/index.d.ts +0 -12
- package/dist/ts/last-commit/index.js +0 -82
- package/dist/ts/last-commit/index.js.map +0 -1
- package/dist/ts/logger/index.d.ts +0 -3
- package/dist/ts/logger/index.js +0 -4
- package/dist/ts/logger/index.js.map +0 -1
- package/dist/ts/logger/s4-logger.d.ts +0 -23
- package/dist/ts/logger/s4-logger.js +0 -105
- package/dist/ts/logger/s4-logger.js.map +0 -1
- package/dist/ts/paginator/index.d.ts +0 -2
- package/dist/ts/paginator/index.js +0 -3
- package/dist/ts/paginator/index.js.map +0 -1
- package/dist/ts/paginator/s4-pagination.d.ts +0 -26
- package/dist/ts/paginator/s4-pagination.js +0 -49
- package/dist/ts/paginator/s4-pagination.js.map +0 -1
- package/dist/ts/paginator/sql-pagination.d.ts +0 -52
- package/dist/ts/paginator/sql-pagination.js +0 -157
- package/dist/ts/paginator/sql-pagination.js.map +0 -1
- package/dist/ts/paper-trail/helpers.d.ts +0 -14
- package/dist/ts/paper-trail/helpers.js +0 -74
- package/dist/ts/paper-trail/helpers.js.map +0 -1
- package/dist/ts/paper-trail/index.d.ts +0 -54
- package/dist/ts/paper-trail/index.js +0 -236
- package/dist/ts/paper-trail/index.js.map +0 -1
- package/dist/ts/prompts/index.d.ts +0 -21
- package/dist/ts/prompts/index.js +0 -68
- package/dist/ts/prompts/index.js.map +0 -1
- package/dist/ts/queue/index.d.ts +0 -232
- package/dist/ts/queue/index.js +0 -451
- package/dist/ts/queue/index.js.map +0 -1
- package/dist/ts/queue/publisher.d.ts +0 -41
- package/dist/ts/queue/publisher.js +0 -84
- package/dist/ts/queue/publisher.js.map +0 -1
- package/dist/ts/queue/queue-logger.d.ts +0 -10
- package/dist/ts/queue/queue-logger.js +0 -35
- package/dist/ts/queue/queue-logger.js.map +0 -1
- package/dist/ts/queue/subscriber.d.ts +0 -55
- package/dist/ts/queue/subscriber.js +0 -98
- package/dist/ts/queue/subscriber.js.map +0 -1
- package/dist/ts/safe-proxy/index.d.ts +0 -35
- package/dist/ts/safe-proxy/index.js +0 -54
- package/dist/ts/safe-proxy/index.js.map +0 -1
- package/dist/ts/serializer/index.d.ts +0 -52
- package/dist/ts/serializer/index.js +0 -83
- package/dist/ts/serializer/index.js.map +0 -1
- package/dist/ts/utils/index.d.ts +0 -49
- package/dist/ts/utils/index.js +0 -157
- package/dist/ts/utils/index.js.map +0 -1
package/dist/ts/dns/DnsCache.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { S4Logger } from '../logger/index.js';
|
|
2
|
-
import dns from 'node:dns';
|
|
3
|
-
export class DnsCache {
|
|
4
|
-
constructor(config = {}) {
|
|
5
|
-
this.cache = new Map();
|
|
6
|
-
this.ongoingLookups = new Map();
|
|
7
|
-
this.cacheTtlMs = config.cacheTtlMs ?? 5000; // 5 seconds default
|
|
8
|
-
this.purgeIntervalMs = config.purgeIntervalMs ?? 60 * 2 * 1000; // 2 minutes default
|
|
9
|
-
this.debug = config.debug ?? false;
|
|
10
|
-
this.forceTestMode = config.forceTestMode ?? false;
|
|
11
|
-
this.logger = new S4Logger();
|
|
12
|
-
this.logger.configure({ service: 'dns-cache' });
|
|
13
|
-
}
|
|
14
|
-
static getInstance(config = {}) {
|
|
15
|
-
DnsCache.instance ?? (DnsCache.instance = new DnsCache(config));
|
|
16
|
-
return DnsCache.instance;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Resolves a target URL or hostname to its IP address
|
|
20
|
-
* @param urlOrHostname - The URL or hostname to resolve
|
|
21
|
-
* @param keepPath - Whether to keep the path in the returned URL
|
|
22
|
-
* @returns The resolved URL with IP address
|
|
23
|
-
*/
|
|
24
|
-
async resolveTarget(urlOrHostname, keepPath = false) {
|
|
25
|
-
const parsed = new URL(urlOrHostname);
|
|
26
|
-
try {
|
|
27
|
-
// Only return localhost if explicitly in test mode
|
|
28
|
-
if (this.forceTestMode) {
|
|
29
|
-
return `${parsed.protocol}//localhost:${parsed.port || 80}${keepPath ? parsed.pathname : ''}`;
|
|
30
|
-
}
|
|
31
|
-
const ip = await this.lookupWithCache(parsed.hostname);
|
|
32
|
-
let hostPart = ip.includes(':') ? `[${ip}]` : ip; // wrap IPv6
|
|
33
|
-
return `${parsed.protocol}//${hostPart}:${parsed.port || 80}${keepPath ? parsed.pathname : ''}`;
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
if (this.forceTestMode) {
|
|
37
|
-
return urlOrHostname;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
throw e;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Purges expired entries from the DNS cache
|
|
46
|
-
*/
|
|
47
|
-
purgeExpiredCache() {
|
|
48
|
-
const now = Date.now();
|
|
49
|
-
const purgedInstances = new Map();
|
|
50
|
-
for (const [hostname, entry] of this.cache.entries()) {
|
|
51
|
-
if (now - entry.timestamp >= this.cacheTtlMs) {
|
|
52
|
-
purgedInstances.set(hostname, entry);
|
|
53
|
-
this.cache.delete(hostname);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
if (this.debug && purgedInstances.size > 0) {
|
|
57
|
-
console.log("Purged", purgedInstances.size, "expired DNS cache entries", purgedInstances.keys());
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Forces a cache purge for a specific hostname or all entries
|
|
62
|
-
* @param hostname - Optional hostname to purge, if not provided purges all entries
|
|
63
|
-
*/
|
|
64
|
-
forceCachePurge(hostname) {
|
|
65
|
-
if (!hostname) {
|
|
66
|
-
this.cache.clear();
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
// if hostname is specified then purge all entries that match
|
|
70
|
-
for (const [key] of this.cache.entries()) {
|
|
71
|
-
if (key.includes(hostname)) {
|
|
72
|
-
this.cache.delete(key);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Performs a DNS lookup with caching
|
|
79
|
-
* @param target - The target hostname or URL to lookup
|
|
80
|
-
* @returns The resolved IP address
|
|
81
|
-
*/
|
|
82
|
-
async lookupWithCache(target) {
|
|
83
|
-
const now = Date.now();
|
|
84
|
-
const cached = this.cache.get(target);
|
|
85
|
-
// Check for valid cache entry first
|
|
86
|
-
if (cached && (now - cached.timestamp < this.cacheTtlMs)) {
|
|
87
|
-
this.logger.debug(`DNS cache hit for ${target}`);
|
|
88
|
-
return cached.address;
|
|
89
|
-
}
|
|
90
|
-
// If cache TTL is 0, always do a new lookup
|
|
91
|
-
if (this.cacheTtlMs === 0) {
|
|
92
|
-
this.logger.debug(`DNS cache miss for ${target} (TTL=0)`);
|
|
93
|
-
const { address } = await dns.promises.lookup(target);
|
|
94
|
-
this.cache.set(target, { address, timestamp: now });
|
|
95
|
-
this.logger.debug(`Cached ${target}: ${address}`);
|
|
96
|
-
return address;
|
|
97
|
-
}
|
|
98
|
-
// Check if there's already a lookup in progress for this hostname
|
|
99
|
-
if (this.ongoingLookups.has(target)) {
|
|
100
|
-
this.logger.debug(`Waiting for ongoing DNS lookup for ${target}`);
|
|
101
|
-
return this.ongoingLookups.get(target);
|
|
102
|
-
}
|
|
103
|
-
// Create a new lookup promise
|
|
104
|
-
const lookupPromise = (async () => {
|
|
105
|
-
try {
|
|
106
|
-
this.logger.debug(`DNS cache miss for ${target}`);
|
|
107
|
-
const { address } = await dns.promises.lookup(target);
|
|
108
|
-
this.cache.set(target, { address, timestamp: now });
|
|
109
|
-
this.logger.debug(`Cached ${target}: ${address}`);
|
|
110
|
-
return address;
|
|
111
|
-
}
|
|
112
|
-
finally {
|
|
113
|
-
// Clean up the ongoing lookup
|
|
114
|
-
this.ongoingLookups.delete(target);
|
|
115
|
-
}
|
|
116
|
-
})();
|
|
117
|
-
// Store the promise in the ongoing lookups map
|
|
118
|
-
this.ongoingLookups.set(target, lookupPromise);
|
|
119
|
-
return lookupPromise;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Gets the current cache size
|
|
123
|
-
*/
|
|
124
|
-
getCacheSize() {
|
|
125
|
-
return this.cache.size;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Gets the current number of ongoing lookups
|
|
129
|
-
*/
|
|
130
|
-
getOngoingLookupsCount() {
|
|
131
|
-
return this.ongoingLookups.size;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
DnsCache.instance = null;
|
|
135
|
-
// Export a default instance with default configuration
|
|
136
|
-
export default DnsCache.getInstance();
|
|
137
|
-
//# sourceMappingURL=DnsCache.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DnsCache.js","sourceRoot":"","sources":["../../../ts/dns/DnsCache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,GAAG,MAAM,UAAU,CAAC;AAc3B,MAAM,OAAO,QAAQ;IAUnB,YAAoB,SAAyB,EAAE;QAC7C,IAAI,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;QAChC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,IAAI,IAAI,CAAC,CAAC,oBAAoB;QACjE,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,IAAI,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,oBAAoB;QACpF,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC;QACnC,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,IAAI,KAAK,CAAC;QACnD,IAAI,CAAC,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;IAClD,CAAC;IAEM,MAAM,CAAC,WAAW,CAAC,SAAyB,EAAE;QACnD,QAAQ,CAAC,QAAQ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ACpD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,MAAM,KAAK,OAAO,EAAE,CAAC,CAAC;gBAClD,OAAO,OAAO,CAAC;YACjB,CAAC;oBAAS,CAAC;gBACT,8BAA8B;gBAC9B,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACrC,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;QAEL,+CAA+C;QAC/C,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;QAE/C,OAAO,aAAa,CAAC;IACvB,CAAC;IAED;;OAEG;IACI,YAAY;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;IAED;;OAEG;IACI,sBAAsB;QAC3B,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;IAClC,CAAC;;AAvJc,iBAAQ,GAAoB,IAAI,CAAC;AA0JlD,uDAAuD;AACvD,eAAe,QAAQ,CAAC,WAAW,EAAE,CAAC"}
|
package/dist/ts/dns/index.d.ts
DELETED
package/dist/ts/dns/index.js
DELETED
package/dist/ts/dns/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/dns/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpB,eAAe,QAAQ,CAAC,WAAW,EAAE,CAAC"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
interface ErrorResponse {
|
|
2
|
-
status: number;
|
|
3
|
-
errors: Record<string, any>;
|
|
4
|
-
}
|
|
5
|
-
interface FormattedError {
|
|
6
|
-
error: ErrorResponse;
|
|
7
|
-
error_id?: string;
|
|
8
|
-
}
|
|
9
|
-
interface ErrorInput {
|
|
10
|
-
status?: number | string;
|
|
11
|
-
error?: string;
|
|
12
|
-
errors?: string[] | Record<string, any>;
|
|
13
|
-
}
|
|
14
|
-
declare class FormatError extends Error {
|
|
15
|
-
constructor(message: string);
|
|
16
|
-
}
|
|
17
|
-
declare class S4Formatter {
|
|
18
|
-
private defaults;
|
|
19
|
-
constructor();
|
|
20
|
-
private _isArray;
|
|
21
|
-
private _fromHash;
|
|
22
|
-
/**
|
|
23
|
-
* Desired Response format
|
|
24
|
-
*{
|
|
25
|
-
* "error": {
|
|
26
|
-
* "status": 422,
|
|
27
|
-
* "errors": {
|
|
28
|
-
* "password": {
|
|
29
|
-
* "location": "body",
|
|
30
|
-
* "param": "password",
|
|
31
|
-
* "value": "mypassword",
|
|
32
|
-
* "msg": "weak"
|
|
33
|
-
* }
|
|
34
|
-
* }
|
|
35
|
-
* },
|
|
36
|
-
* "error_id": "a2ddf895-2aaf-4189-88a2-8e11f6843f91"
|
|
37
|
-
*}
|
|
38
|
-
*/
|
|
39
|
-
formatError(error: ErrorInput | null): ErrorResponse;
|
|
40
|
-
}
|
|
41
|
-
declare const formatter: S4Formatter;
|
|
42
|
-
export default formatter;
|
|
43
|
-
export type { ErrorResponse, FormattedError, ErrorInput };
|
|
44
|
-
export { FormatError };
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
class FormatError extends Error {
|
|
2
|
-
constructor(message) {
|
|
3
|
-
super(message);
|
|
4
|
-
this.name = "FormatError";
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
// helps to clean up response formats for services responding to rest requests
|
|
8
|
-
class S4Formatter {
|
|
9
|
-
constructor() {
|
|
10
|
-
this.defaults = {
|
|
11
|
-
status: 422,
|
|
12
|
-
errors: {}
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
_isArray(value) {
|
|
16
|
-
return value && typeof value === 'object' && value.constructor === Array;
|
|
17
|
-
}
|
|
18
|
-
_fromHash(error) {
|
|
19
|
-
const response = Object.assign({}, this.defaults);
|
|
20
|
-
if (error.status) {
|
|
21
|
-
const errorStatus = parseInt(error.status.toString());
|
|
22
|
-
if ((errorStatus >= 200) && (errorStatus < 522)) {
|
|
23
|
-
response.status = errorStatus;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (error.error && (typeof (error.error) === "string")) {
|
|
27
|
-
response.errors["generic"] = { msg: error.error };
|
|
28
|
-
}
|
|
29
|
-
else if (error.errors) {
|
|
30
|
-
if (this._isArray(error.errors)) {
|
|
31
|
-
// many legacy responses which are errors: ["error_name"]
|
|
32
|
-
error.errors.forEach((el, index) => {
|
|
33
|
-
response.errors[`generic_${index}`] = { msg: el };
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
else if (typeof (error.errors) === "object") {
|
|
37
|
-
response.errors = error.errors;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return response;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Desired Response format
|
|
44
|
-
*{
|
|
45
|
-
* "error": {
|
|
46
|
-
* "status": 422,
|
|
47
|
-
* "errors": {
|
|
48
|
-
* "password": {
|
|
49
|
-
* "location": "body",
|
|
50
|
-
* "param": "password",
|
|
51
|
-
* "value": "mypassword",
|
|
52
|
-
* "msg": "weak"
|
|
53
|
-
* }
|
|
54
|
-
* }
|
|
55
|
-
* },
|
|
56
|
-
* "error_id": "a2ddf895-2aaf-4189-88a2-8e11f6843f91"
|
|
57
|
-
*}
|
|
58
|
-
*/
|
|
59
|
-
formatError(error) {
|
|
60
|
-
let response;
|
|
61
|
-
if (error === null) {
|
|
62
|
-
response = this.defaults;
|
|
63
|
-
}
|
|
64
|
-
else if (typeof (error) === "object") {
|
|
65
|
-
response = this._fromHash(error);
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
throw new FormatError("invalid_error_format");
|
|
69
|
-
}
|
|
70
|
-
return response;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const formatter = new S4Formatter();
|
|
74
|
-
export default formatter;
|
|
75
|
-
export { FormatError };
|
|
76
|
-
//# sourceMappingURL=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,CAAC,MAAM,CAAC,EAAE,CAAC;gBAChC,yDAAyD;gBACzD,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EAAO,EAAE,KAAa,EAAE,EAAE;oBAC9C,QAAQ,CAAC,MAAM,CAAC,WAAW,KAAK,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC;gBACpD,CAAC,CAAC,CAAC;YACL,CAAC;iBAAM,IAAI,OAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,QAAQ,EAAE,CAAC;gBAC7C,QAAQ,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;YACjC,CAAC;QACH,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;;;;;;;;;;;;;;;MAgBE;IACF,WAAW,CAAC,KAAwB;QAClC,IAAI,QAAuB,CAAC;QAE5B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACnB,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC3B,CAAC;aAAM,IAAI,OAAM,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAG,CAAC;YACvC,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,WAAW,CAAC,sBAAsB,CAAC,CAAC;QAChD,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAED,MAAM,SAAS,GAAG,IAAI,WAAW,EAAE,CAAC;AACpC,eAAe,SAAS,CAAC;AAEzB,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
package/dist/ts/hal/index.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
interface HalOptions {
|
|
2
|
-
resource?: string;
|
|
3
|
-
exclude?: string[];
|
|
4
|
-
links?: Record<string, Record<string, string>>;
|
|
5
|
-
linksTag?: string;
|
|
6
|
-
resourceTag?: string;
|
|
7
|
-
}
|
|
8
|
-
interface ModelInstance {
|
|
9
|
-
instance?: any;
|
|
10
|
-
prototype: {
|
|
11
|
-
toJSON: () => any;
|
|
12
|
-
get: () => Record<string, any>;
|
|
13
|
-
};
|
|
14
|
-
get: () => Record<string, any>;
|
|
15
|
-
}
|
|
16
|
-
interface LinkData {
|
|
17
|
-
[key: string]: {
|
|
18
|
-
[method: string]: string;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
declare class HalDecorator {
|
|
22
|
-
decorate(Model: ModelInstance, options?: HalOptions): void;
|
|
23
|
-
}
|
|
24
|
-
declare const halDecorator: HalDecorator;
|
|
25
|
-
export default halDecorator;
|
|
26
|
-
export type { HalOptions, ModelInstance, LinkData };
|
package/dist/ts/hal/index.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
function lastElement(arr) {
|
|
2
|
-
if (arr && arr.length) {
|
|
3
|
-
return arr[arr.length - 1];
|
|
4
|
-
}
|
|
5
|
-
else {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
class HalDecorator {
|
|
10
|
-
decorate(Model, options = {}) {
|
|
11
|
-
const model = Model.instance || Model;
|
|
12
|
-
const resource = options.resource || "";
|
|
13
|
-
const exclude = options.exclude || [];
|
|
14
|
-
const links = options.links || {};
|
|
15
|
-
const linksTag = options.linksTag || "_links";
|
|
16
|
-
const resourceTag = options.resourceTag || "_resource";
|
|
17
|
-
const link = (name, method, l) => {
|
|
18
|
-
if (name && method && l) {
|
|
19
|
-
const aLink = {};
|
|
20
|
-
aLink[method] = l; // Fixed typo: was "alink"
|
|
21
|
-
links[name] = aLink;
|
|
22
|
-
}
|
|
23
|
-
return model;
|
|
24
|
-
};
|
|
25
|
-
const getLinkData = (values) => {
|
|
26
|
-
const linkData = {};
|
|
27
|
-
if (links) {
|
|
28
|
-
for (const key in links) {
|
|
29
|
-
if (links.hasOwnProperty(key)) {
|
|
30
|
-
const link = links[key];
|
|
31
|
-
const method = lastElement(Object.keys(link));
|
|
32
|
-
if (method) {
|
|
33
|
-
let url = link[method];
|
|
34
|
-
const paramPattern = /\:([a-zA-z_0-9]*)/;
|
|
35
|
-
const arr = paramPattern.exec(url);
|
|
36
|
-
if (arr) {
|
|
37
|
-
// Replace parameters
|
|
38
|
-
url = `/${resource}/${url.split(arr[0]).join(values[arr[1]])}`;
|
|
39
|
-
// Remove extra slashes that may have been added
|
|
40
|
-
url = url.replace(/\/\/*/g, "/");
|
|
41
|
-
linkData[key] = {};
|
|
42
|
-
linkData[key][method] = url;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return Object.keys(linkData).length > 0 ? linkData : null;
|
|
49
|
-
};
|
|
50
|
-
model.link = link;
|
|
51
|
-
Model.prototype.toJSON = function () {
|
|
52
|
-
const values = Object.assign({}, this.get());
|
|
53
|
-
if (exclude) {
|
|
54
|
-
exclude.forEach(element => {
|
|
55
|
-
delete values[element];
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
const links = getLinkData(values);
|
|
59
|
-
const result = {};
|
|
60
|
-
if (links) {
|
|
61
|
-
result[linksTag] = links;
|
|
62
|
-
}
|
|
63
|
-
result[resourceTag] = values;
|
|
64
|
-
return result;
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
const halDecorator = new HalDecorator();
|
|
69
|
-
export default halDecorator;
|
|
70
|
-
//# sourceMappingURL=index.js.map
|
package/dist/ts/hal/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/hal/index.ts"],"names":[],"mappings":"AAuBA,SAAS,WAAW,CAAI,GAAQ;IAC9B,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;QACtB,OAAO,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7B,CAAC;SAAM,CAAC;QACN,OAAO,IAAI,CAAC;I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QAAQ,CAAC,GAAG,KAAK,CAAC;YAC3B,CAAC;YACD,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,CAAC;YAC7B,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;IACJ,CAAC;CACF;AAED,MAAM,YAAY,GAAG,IAAI,YAAY,EAAE,CAAC;AACxC,eAAe,YAAY,CAAC"}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Request, Response } from 'express';
|
|
2
|
-
interface HealthCheckResult {
|
|
3
|
-
name: string;
|
|
4
|
-
result: 'success' | 'fail';
|
|
5
|
-
critical?: boolean;
|
|
6
|
-
status?: number;
|
|
7
|
-
}
|
|
8
|
-
interface HealthCheckConfig {
|
|
9
|
-
name: string;
|
|
10
|
-
checkResult?: boolean;
|
|
11
|
-
critical: boolean;
|
|
12
|
-
healthFunction: () => Promise<boolean | HealthCheckResult>;
|
|
13
|
-
}
|
|
14
|
-
interface ExpressRequest extends Request {
|
|
15
|
-
baseUrl: string;
|
|
16
|
-
path: string;
|
|
17
|
-
}
|
|
18
|
-
interface ExpressResponse extends Response {
|
|
19
|
-
status: (code: number) => this;
|
|
20
|
-
json: (data: any) => this;
|
|
21
|
-
send: (data: any) => this;
|
|
22
|
-
setHeader: (name: string, value: string | number) => this;
|
|
23
|
-
}
|
|
24
|
-
interface ExpressRouter {
|
|
25
|
-
get: (path: string, handler: (req: ExpressRequest, res: ExpressResponse) => void) => void;
|
|
26
|
-
}
|
|
27
|
-
interface ExpressApp {
|
|
28
|
-
use: (middleware: any) => void;
|
|
29
|
-
}
|
|
30
|
-
export declare class HealthCheckError extends Error {
|
|
31
|
-
constructor(message: string);
|
|
32
|
-
}
|
|
33
|
-
export declare class HealthCheck {
|
|
34
|
-
private readonly logger;
|
|
35
|
-
private readonly defaultResponse;
|
|
36
|
-
private readonly defaultPathRoute;
|
|
37
|
-
private suppressLogs;
|
|
38
|
-
private lastCallId;
|
|
39
|
-
private pathPrefix;
|
|
40
|
-
private healthChecks;
|
|
41
|
-
constructor(appendData?: Record<string, unknown>, enableLogging?: boolean);
|
|
42
|
-
/**
|
|
43
|
-
* @deprecated Use setupCheck instead
|
|
44
|
-
*/
|
|
45
|
-
addCheck(fcn: () => Promise<HealthCheckResult>): void;
|
|
46
|
-
setPrefix(prefix: string): void;
|
|
47
|
-
defaultPath(prefix?: string): string;
|
|
48
|
-
routes(router: ExpressRouter): ExpressRouter;
|
|
49
|
-
suppressHealthCheckLog(app: ExpressApp): void;
|
|
50
|
-
setupCheck(config: HealthCheckConfig): void;
|
|
51
|
-
private checkHealth;
|
|
52
|
-
}
|
|
53
|
-
export default HealthCheck;
|
package/dist/ts/health/index.js
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import morgan from 'morgan';
|
|
3
|
-
import { S4Logger } from '../logger/index.js';
|
|
4
|
-
export class HealthCheckError extends Error {
|
|
5
|
-
constructor(message) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.name = 'HealthCheckError';
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export class HealthCheck {
|
|
11
|
-
constructor(appendData = {}, enableLogging = true) {
|
|
12
|
-
this.logger = new S4Logger();
|
|
13
|
-
this.logger.configure({ level: enableLogging ? 'debug' : 'error' });
|
|
14
|
-
this.defaultResponse = {
|
|
15
|
-
appendData,
|
|
16
|
-
status: 200,
|
|
17
|
-
errors: {}
|
|
18
|
-
};
|
|
19
|
-
this.defaultPathRoute = 'health_check(.*)?';
|
|
20
|
-
this.suppressLogs = false;
|
|
21
|
-
this.lastCallId = 0;
|
|
22
|
-
this.pathPrefix = '';
|
|
23
|
-
this.healthChecks = [];
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated Use setupCheck instead
|
|
27
|
-
*/
|
|
28
|
-
addCheck(fcn) {
|
|
29
|
-
this.healthChecks.push(fcn);
|
|
30
|
-
}
|
|
31
|
-
setPrefix(prefix) {
|
|
32
|
-
this.pathPrefix = prefix;
|
|
33
|
-
}
|
|
34
|
-
defaultPath(prefix = '') {
|
|
35
|
-
if (prefix === '') {
|
|
36
|
-
prefix = this.pathPrefix;
|
|
37
|
-
}
|
|
38
|
-
return `${prefix}/${this.defaultPathRoute}`;
|
|
39
|
-
}
|
|
40
|
-
routes(router) {
|
|
41
|
-
if (!router) {
|
|
42
|
-
throw new HealthCheckError('missing_express_router');
|
|
43
|
-
}
|
|
44
|
-
router.get('/', (req, res) => {
|
|
45
|
-
this.checkHealth(req, res);
|
|
46
|
-
});
|
|
47
|
-
return router;
|
|
48
|
-
}
|
|
49
|
-
suppressHealthCheckLog(app) {
|
|
50
|
-
app.use(morgan('combined', {
|
|
51
|
-
skip: (req) => {
|
|
52
|
-
const expressReq = req;
|
|
53
|
-
return expressReq.path === this.defaultPath();
|
|
54
|
-
}
|
|
55
|
-
}));
|
|
56
|
-
}
|
|
57
|
-
setupCheck(config) {
|
|
58
|
-
this.healthChecks.push(config);
|
|
59
|
-
}
|
|
60
|
-
async checkHealth(req, res) {
|
|
61
|
-
const checkFormat = path.extname(req.baseUrl);
|
|
62
|
-
const result = await Promise.all(this.healthChecks.map(async (hc) => {
|
|
63
|
-
if (typeof hc === 'function') {
|
|
64
|
-
try {
|
|
65
|
-
return await hc();
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
return { name: 'unknown', result: 'fail', status: e.status };
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
const res = {
|
|
73
|
-
name: hc.name,
|
|
74
|
-
critical: hc.critical
|
|
75
|
-
};
|
|
76
|
-
try {
|
|
77
|
-
const result = await hc.healthFunction();
|
|
78
|
-
if (typeof result === 'boolean') {
|
|
79
|
-
res.result = result ? 'success' : 'fail';
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
res.result = 'success';
|
|
83
|
-
}
|
|
84
|
-
return res;
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
const appendStatus = e.status ? ` (${e.status})` : '';
|
|
88
|
-
this.logger.warn(`${hc.name} service failed${appendStatus}`);
|
|
89
|
-
return {
|
|
90
|
-
...res,
|
|
91
|
-
result: 'fail',
|
|
92
|
-
status: e.status
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}));
|
|
97
|
-
try {
|
|
98
|
-
let callId = ++this.lastCallId;
|
|
99
|
-
if ((callId % (1 << 30)) === 0) {
|
|
100
|
-
callId = this.lastCallId = 1;
|
|
101
|
-
}
|
|
102
|
-
let status = this.defaultResponse.status;
|
|
103
|
-
let nonCriticalFail = false;
|
|
104
|
-
let criticalFail = false;
|
|
105
|
-
result.some((e) => {
|
|
106
|
-
if (e.result.match(/fail/)) {
|
|
107
|
-
if ('critical' in e && e.critical === false) {
|
|
108
|
-
nonCriticalFail = true;
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
criticalFail = true;
|
|
112
|
-
status = 500;
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return false;
|
|
117
|
-
});
|
|
118
|
-
res.setHeader('check', callId);
|
|
119
|
-
if (checkFormat === '.json') {
|
|
120
|
-
const payload = {
|
|
121
|
-
check: callId,
|
|
122
|
-
healthy: true,
|
|
123
|
-
message: 'success'
|
|
124
|
-
};
|
|
125
|
-
if (criticalFail) {
|
|
126
|
-
res.status(status).json({
|
|
127
|
-
...payload,
|
|
128
|
-
healthy: false,
|
|
129
|
-
message: 'fail',
|
|
130
|
-
services: result
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
else if (nonCriticalFail) {
|
|
134
|
-
res.status(status).json({
|
|
135
|
-
...payload,
|
|
136
|
-
message: 'fail',
|
|
137
|
-
services: result
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
else if (status === 200) {
|
|
141
|
-
res.status(status).json(payload);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
let statusMessage;
|
|
146
|
-
if (criticalFail) {
|
|
147
|
-
statusMessage = 'fail';
|
|
148
|
-
}
|
|
149
|
-
else if ((status === 200) || nonCriticalFail) {
|
|
150
|
-
statusMessage = 'success';
|
|
151
|
-
}
|
|
152
|
-
else {
|
|
153
|
-
statusMessage = 'unknown';
|
|
154
|
-
}
|
|
155
|
-
res.status(status).send(statusMessage);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
this.logger.error('Health check error:', error);
|
|
160
|
-
res.status(500).send('Internal Server Error');
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
export default HealthCheck;
|
|
165
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/health/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AA2C9C,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED,MAAM,OAAO,WAAW;IAatB,YAAY,aAAsC,EAAE,EAAE,aAAa,GAAG,IAAI;QACxE,IAAI,CAAC,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QAEpE,IAAI,CAAC,eAAe,GAAG;YACrB,UAAU;YACV,MAAM,EAAE,GAAG;YACX,MAAM,EAAE,EAAE;SACX,CAAC;QAEF,IAAI,CAAC,gBAAgB,GAAG,mBAAmB,CAAC;QAC5C,IA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-server-wrapper.js";
|
package/dist/ts/helpers/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
|