@sera4/essentia 3.0.13-rc.1 → 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.
Files changed (154) hide show
  1. package/package.json +1 -1
  2. package/package.tar.gz +0 -0
  3. package/dist/cache/index.d.ts +0 -22
  4. package/dist/cache/index.js +0 -166
  5. package/dist/cache/index.js.map +0 -1
  6. package/dist/constants/index.d.ts +0 -6
  7. package/dist/constants/index.js +0 -9
  8. package/dist/constants/index.js.map +0 -1
  9. package/dist/formatter/index.d.ts +0 -37
  10. package/dist/formatter/index.js +0 -75
  11. package/dist/formatter/index.js.map +0 -1
  12. package/dist/hal/index.d.ts +0 -5
  13. package/dist/hal/index.js +0 -69
  14. package/dist/hal/index.js.map +0 -1
  15. package/dist/health/health-logger.d.ts +0 -9
  16. package/dist/health/health-logger.js +0 -34
  17. package/dist/health/health-logger.js.map +0 -1
  18. package/dist/health/index.d.ts +0 -19
  19. package/dist/health/index.js +0 -175
  20. package/dist/health/index.js.map +0 -1
  21. package/dist/helpers/index.d.ts +0 -1
  22. package/dist/helpers/index.js +0 -2
  23. package/dist/helpers/index.js.map +0 -1
  24. package/dist/helpers/test-server-wrapper.d.ts +0 -120
  25. package/dist/helpers/test-server-wrapper.js +0 -165
  26. package/dist/helpers/test-server-wrapper.js.map +0 -1
  27. package/dist/index.d.ts +0 -1
  28. package/dist/index.js +0 -17
  29. package/dist/index.js.map +0 -1
  30. package/dist/last-commit.d.ts +0 -1
  31. package/dist/last-commit.js.map +0 -1
  32. package/dist/last_commit/index.d.ts +0 -7
  33. package/dist/last_commit/index.js +0 -83
  34. package/dist/last_commit/index.js.map +0 -1
  35. package/dist/paginator/s4-pagination.d.ts +0 -9
  36. package/dist/paginator/s4-pagination.js +0 -49
  37. package/dist/paginator/s4-pagination.js.map +0 -1
  38. package/dist/paginator/sql-pagination.d.ts +0 -27
  39. package/dist/paginator/sql-pagination.js +0 -166
  40. package/dist/paginator/sql-pagination.js.map +0 -1
  41. package/dist/paper-trail/helpers.d.ts +0 -11
  42. package/dist/paper-trail/helpers.js +0 -74
  43. package/dist/paper-trail/helpers.js.map +0 -1
  44. package/dist/paper-trail/index.d.ts +0 -13
  45. package/dist/paper-trail/index.js +0 -662
  46. package/dist/paper-trail/index.js.map +0 -1
  47. package/dist/prompts/index.d.ts +0 -14
  48. package/dist/prompts/index.js +0 -63
  49. package/dist/prompts/index.js.map +0 -1
  50. package/dist/queue/index.d.ts +0 -166
  51. package/dist/queue/index.js +0 -371
  52. package/dist/queue/index.js.map +0 -1
  53. package/dist/queue/publisher.d.ts +0 -31
  54. package/dist/queue/publisher.js +0 -84
  55. package/dist/queue/publisher.js.map +0 -1
  56. package/dist/queue/queue-logger.d.ts +0 -9
  57. package/dist/queue/queue-logger.js +0 -35
  58. package/dist/queue/queue-logger.js.map +0 -1
  59. package/dist/queue/subscriber.d.ts +0 -39
  60. package/dist/queue/subscriber.js +0 -97
  61. package/dist/queue/subscriber.js.map +0 -1
  62. package/dist/safe_proxy/index.d.ts +0 -13
  63. package/dist/safe_proxy/index.js +0 -54
  64. package/dist/safe_proxy/index.js.map +0 -1
  65. package/dist/serializer/index.d.ts +0 -5
  66. package/dist/serializer/index.js +0 -83
  67. package/dist/serializer/index.js.map +0 -1
  68. package/dist/ts/cache/index.d.ts +0 -33
  69. package/dist/ts/cache/index.js +0 -171
  70. package/dist/ts/cache/index.js.map +0 -1
  71. package/dist/ts/configurations/server-config.d.ts +0 -4
  72. package/dist/ts/configurations/server-config.js +0 -2
  73. package/dist/ts/configurations/server-config.js.map +0 -1
  74. package/dist/ts/constants/index.d.ts +0 -7
  75. package/dist/ts/constants/index.js +0 -8
  76. package/dist/ts/constants/index.js.map +0 -1
  77. package/dist/ts/cycle/index.d.ts +0 -53
  78. package/dist/ts/cycle/index.js +0 -169
  79. package/dist/ts/cycle/index.js.map +0 -1
  80. package/dist/ts/dns/DnsCache.d.ts +0 -50
  81. package/dist/ts/dns/DnsCache.js +0 -137
  82. package/dist/ts/dns/DnsCache.js.map +0 -1
  83. package/dist/ts/dns/index.d.ts +0 -4
  84. package/dist/ts/dns/index.js +0 -4
  85. package/dist/ts/dns/index.js.map +0 -1
  86. package/dist/ts/formatter/index.d.ts +0 -44
  87. package/dist/ts/formatter/index.js +0 -76
  88. package/dist/ts/formatter/index.js.map +0 -1
  89. package/dist/ts/hal/index.d.ts +0 -26
  90. package/dist/ts/hal/index.js +0 -70
  91. package/dist/ts/hal/index.js.map +0 -1
  92. package/dist/ts/health/index.d.ts +0 -53
  93. package/dist/ts/health/index.js +0 -165
  94. package/dist/ts/health/index.js.map +0 -1
  95. package/dist/ts/helpers/index.d.ts +0 -1
  96. package/dist/ts/helpers/index.js +0 -2
  97. package/dist/ts/helpers/index.js.map +0 -1
  98. package/dist/ts/helpers/test-server-wrapper.d.ts +0 -56
  99. package/dist/ts/helpers/test-server-wrapper.js +0 -144
  100. package/dist/ts/helpers/test-server-wrapper.js.map +0 -1
  101. package/dist/ts/index.d.ts +0 -22
  102. package/dist/ts/index.js +0 -27
  103. package/dist/ts/index.js.map +0 -1
  104. package/dist/ts/last-commit/index.d.ts +0 -12
  105. package/dist/ts/last-commit/index.js +0 -82
  106. package/dist/ts/last-commit/index.js.map +0 -1
  107. package/dist/ts/logger/index.d.ts +0 -3
  108. package/dist/ts/logger/index.js +0 -4
  109. package/dist/ts/logger/index.js.map +0 -1
  110. package/dist/ts/logger/s4-logger.d.ts +0 -23
  111. package/dist/ts/logger/s4-logger.js +0 -105
  112. package/dist/ts/logger/s4-logger.js.map +0 -1
  113. package/dist/ts/paginator/index.d.ts +0 -2
  114. package/dist/ts/paginator/index.js +0 -3
  115. package/dist/ts/paginator/index.js.map +0 -1
  116. package/dist/ts/paginator/s4-pagination.d.ts +0 -26
  117. package/dist/ts/paginator/s4-pagination.js +0 -49
  118. package/dist/ts/paginator/s4-pagination.js.map +0 -1
  119. package/dist/ts/paginator/sql-pagination.d.ts +0 -52
  120. package/dist/ts/paginator/sql-pagination.js +0 -157
  121. package/dist/ts/paginator/sql-pagination.js.map +0 -1
  122. package/dist/ts/paper-trail/helpers.d.ts +0 -14
  123. package/dist/ts/paper-trail/helpers.js +0 -74
  124. package/dist/ts/paper-trail/helpers.js.map +0 -1
  125. package/dist/ts/paper-trail/index.d.ts +0 -54
  126. package/dist/ts/paper-trail/index.js +0 -236
  127. package/dist/ts/paper-trail/index.js.map +0 -1
  128. package/dist/ts/prompts/index.d.ts +0 -21
  129. package/dist/ts/prompts/index.js +0 -68
  130. package/dist/ts/prompts/index.js.map +0 -1
  131. package/dist/ts/queue/index.d.ts +0 -232
  132. package/dist/ts/queue/index.js +0 -440
  133. package/dist/ts/queue/index.js.map +0 -1
  134. package/dist/ts/queue/publisher.d.ts +0 -41
  135. package/dist/ts/queue/publisher.js +0 -84
  136. package/dist/ts/queue/publisher.js.map +0 -1
  137. package/dist/ts/queue/queue-logger.d.ts +0 -10
  138. package/dist/ts/queue/queue-logger.js +0 -35
  139. package/dist/ts/queue/queue-logger.js.map +0 -1
  140. package/dist/ts/queue/subscriber.d.ts +0 -55
  141. package/dist/ts/queue/subscriber.js +0 -98
  142. package/dist/ts/queue/subscriber.js.map +0 -1
  143. package/dist/ts/safe-proxy/index.d.ts +0 -35
  144. package/dist/ts/safe-proxy/index.js +0 -54
  145. package/dist/ts/safe-proxy/index.js.map +0 -1
  146. package/dist/ts/serializer/index.d.ts +0 -52
  147. package/dist/ts/serializer/index.js +0 -83
  148. package/dist/ts/serializer/index.js.map +0 -1
  149. package/dist/ts/task-scheduler/index.d.ts +0 -130
  150. package/dist/ts/task-scheduler/index.js +0 -259
  151. package/dist/ts/task-scheduler/index.js.map +0 -1
  152. package/dist/ts/utils/index.d.ts +0 -49
  153. package/dist/ts/utils/index.js +0 -157
  154. package/dist/ts/utils/index.js.map +0 -1
@@ -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=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/formatter/index.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAY,SAAQ,KAAK;IAC7B,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,8EAA8E;AAC9E,MAAM,WAAW;IAGf;QACE,IAAI,CAAC,QAAQ,GAAG;YACd,MAAM,EAAE,GAAG;YACX,MAAM,EAAE,EAAE;SACX,CAAC;IACJ,CAAC;IAEO,QAAQ,CAAC,KAAU;QACzB,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,WAAW,KAAK,KAAK,CAAC;IAC3E,CAAC;IAEO,SAAS,CAAC,KAAiB;QACjC,MAAM,QAAQ,GAAkB,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEjE,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YACjB,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;YAEtD,IAAI,CAAC,WAAW,IAAI,GAAG,CAAC,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC,EAAE,CAAC;gBAChD,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B,CAAC;CACF;AAED,MAAM,SAAS,GAAG,IAAI,WAAW,EAAE,CAAC;AACpC,eAAe,SAAS,CAAC;AAEzB,OAAO,EAAE,WAAW,EAAE,CAAC"}
@@ -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 };
@@ -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
@@ -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;IACd,CAAC;AACH,CAAC;AAED,MAAM,YAAY;IAChB,QAAQ,CAAC,KAAoB,EAAE,UAAsB,EAAE;QACrD,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC;QACtC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;QACxC,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC;QAClC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,QAAQ,CAAC;QAC9C,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,WAAW,CAAC;QAEvD,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,MAAc,EAAE,CAAS,EAAO,EAAE;YAC5D,IAAI,IAAI,IAAI,MAA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AAC;wBACH,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;YACD,OAAO,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;QAC5D,CAAC,CAAC;QAEF,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC;QAClB,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG;YACvB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;YAC7C,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;oBACxB,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;gBACzB,CAAC,CAAC,CAAC;YACL,CAAC;YACD,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;YAClC,MAAM,MAAM,GAAwB,EAAE,CAAC;YACvC,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,CAAC,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;
@@ -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,mB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* from "./test-server-wrapper.js";
@@ -1,2 +0,0 @@
1
- export * from "./test-server-wrapper.js";
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../ts/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC"}
@@ -1,56 +0,0 @@
1
- interface RequestOptions {
2
- headers?: Record<string, string>;
3
- body?: any;
4
- }
5
- interface V1API {
6
- get: (url: string) => any;
7
- post: (url: string) => any;
8
- put: (url: string) => any;
9
- delete: (url: string) => any;
10
- }
11
- /**
12
- * A small wrapper around an express js server
13
- * meant to be used in unit tests
14
- */
15
- export declare class TestServerWrapper {
16
- private server;
17
- private defaultHeaders;
18
- private apiPrefix;
19
- private routePrinter;
20
- private chai;
21
- private mobileDomain;
22
- private webDomain;
23
- private factory;
24
- v1: V1API;
25
- constructor(apiPrefix: string, expressServer: any, defaultHeaders: Record<string, string>, oldAuthToken: string, routePrinter: any, chai: any, factory: any);
26
- /**
27
- * Adds a leading slash to the url if missing
28
- * @param {String} url the url to sanitize
29
- * @returns sanitized url
30
- */
31
- sanitizeUrl(url: string): string;
32
- /**
33
- * Apply given headers to the request object
34
- * @param {Object} request
35
- * @param {Object} headers
36
- */
37
- applyHeaders(request: any, headers: Record<string, string>): void;
38
- get(url: string, options?: RequestOptions): any;
39
- getWithPrefix(prefix: string, url: string, options?: RequestOptions): any;
40
- post(url: string, options?: RequestOptions): any;
41
- postWithPrefix(prefix: string, url: string, options?: RequestOptions): any;
42
- put(url: string, options?: RequestOptions): any;
43
- putWithPrefix(prefix: string, url: string, options?: RequestOptions): any;
44
- delete(url: string, options?: RequestOptions): any;
45
- deleteWithPrefix(prefix: string, url: string, options?: RequestOptions): any;
46
- upload(url: string, fields: any, file: any, options?: RequestOptions): any;
47
- uploadWithPrefix(prefix: string, url: string, fields: any, file: any, options?: RequestOptions): any;
48
- stop(): void;
49
- allRoutes(): any;
50
- withHeaders(headers: Record<string, string>): TestServerWrapper;
51
- setMembership(membership: any, addlHeaders?: Record<string, string>): Promise<TestServerWrapper>;
52
- withMembership(m: any): Promise<TestServerWrapper>;
53
- withS4(): TestServerWrapper;
54
- withTap(): TestServerWrapper;
55
- }
56
- export {};
@@ -1,144 +0,0 @@
1
- const s4Domain = "sera4.com";
2
- const mobileDomain = "tws-mob." + s4Domain;
3
- const webDomain = "tws-web." + s4Domain;
4
- /**
5
- * A small wrapper around an express js server
6
- * meant to be used in unit tests
7
- */
8
- export class TestServerWrapper {
9
- constructor(apiPrefix, expressServer, defaultHeaders, oldAuthToken, routePrinter, chai, factory) {
10
- this.server = expressServer;
11
- this.defaultHeaders = defaultHeaders;
12
- this.apiPrefix = apiPrefix;
13
- this.routePrinter = routePrinter;
14
- this.chai = chai;
15
- this.mobileDomain = mobileDomain;
16
- this.webDomain = webDomain;
17
- this.factory = factory;
18
- // Support for older/deprecated apis
19
- const oldAuthHeaders = { headers: { "Authorization": `Token organization_token=${oldAuthToken}` } };
20
- this.v1 = {
21
- get: (url) => this.getWithPrefix("/v1", url, oldAuthHeaders),
22
- post: (url) => this.postWithPrefix("/v1", url, oldAuthHeaders),
23
- put: (url) => this.putWithPrefix("/v1", url, oldAuthHeaders),
24
- delete: (url) => this.deleteWithPrefix("/v1", url, oldAuthHeaders)
25
- };
26
- }
27
- /**
28
- * Adds a leading slash to the url if missing
29
- * @param {String} url the url to sanitize
30
- * @returns sanitized url
31
- */
32
- sanitizeUrl(url) {
33
- // add leading slash if missing
34
- if (!url.startsWith("/")) {
35
- return "/" + url;
36
- }
37
- else {
38
- return url;
39
- }
40
- }
41
- /**
42
- * Apply given headers to the request object
43
- * @param {Object} request
44
- * @param {Object} headers
45
- */
46
- applyHeaders(request, headers) {
47
- Object.keys(headers).map(k => {
48
- request.set(k, headers[k]);
49
- });
50
- }
51
- get(url, options) {
52
- return this.getWithPrefix(this.apiPrefix, url, options);
53
- }
54
- getWithPrefix(prefix, url, options) {
55
- const sanitizedUrl = this.sanitizeUrl(url);
56
- const request = this.chai.request(this.server).get(`${prefix}${sanitizedUrl}`);
57
- this.applyHeaders(request, this.defaultHeaders);
58
- if (options?.headers) {
59
- this.applyHeaders(request, options.headers);
60
- }
61
- if (options?.body) {
62
- request.send(options.body);
63
- }
64
- return request;
65
- }
66
- post(url, options) {
67
- return this.postWithPrefix(this.apiPrefix, url, options);
68
- }
69
- postWithPrefix(prefix, url, options) {
70
- const sanitizedUrl = this.sanitizeUrl(url);
71
- const request = this.chai.request(this.server).post(`${prefix}${sanitizedUrl}`);
72
- this.applyHeaders(request, this.defaultHeaders);
73
- if (options?.headers) {
74
- this.applyHeaders(request, options.headers);
75
- }
76
- return request;
77
- }
78
- put(url, options) {
79
- return this.putWithPrefix(this.apiPrefix, url, options);
80
- }
81
- putWithPrefix(prefix, url, options) {
82
- const sanitizedUrl = this.sanitizeUrl(url);
83
- const request = this.chai.request(this.server).put(`${prefix}${sanitizedUrl}`);
84
- this.applyHeaders(request, this.defaultHeaders);
85
- if (options?.headers) {
86
- this.applyHeaders(request, options.headers);
87
- }
88
- return request;
89
- }
90
- delete(url, options) {
91
- return this.deleteWithPrefix(this.apiPrefix, url, options);
92
- }
93
- deleteWithPrefix(prefix, url, options) {
94
- const sanitizedUrl = this.sanitizeUrl(url);
95
- const request = this.chai.request(this.server).delete(`${prefix}${sanitizedUrl}`);
96
- this.applyHeaders(request, this.defaultHeaders);
97
- if (options?.headers) {
98
- this.applyHeaders(request, options.headers);
99
- }
100
- return request;
101
- }
102
- upload(url, fields, file, options) {
103
- return this.uploadWithPrefix(this.apiPrefix, url, fields, file, options);
104
- }
105
- uploadWithPrefix(prefix, url, fields, file, options) {
106
- const sanitizedUrl = this.sanitizeUrl(url);
107
- const request = this.chai.request(this.server).post(`${prefix}${sanitizedUrl}`);
108
- this.applyHeaders(request, this.defaultHeaders);
109
- if (options?.headers) {
110
- this.applyHeaders(request, options.headers);
111
- }
112
- request.field(fields);
113
- request.attach('file', file);
114
- return request;
115
- }
116
- stop() {
117
- this.server.close();
118
- }
119
- allRoutes() {
120
- return this.routePrinter(this.server);
121
- }
122
- withHeaders(headers) {
123
- return new TestServerWrapper(this.apiPrefix, this.server, { ...this.defaultHeaders, ...headers }, "", // oldAuthToken
124
- this.routePrinter, this.chai, this.factory);
125
- }
126
- async setMembership(membership, addlHeaders = {}) {
127
- const headers = {
128
- "X-Membership": membership,
129
- ...addlHeaders
130
- };
131
- return new TestServerWrapper(this.apiPrefix, this.server, { ...this.defaultHeaders, ...headers }, "", // oldAuthToken
132
- this.routePrinter, this.chai, this.factory);
133
- }
134
- withMembership(m) {
135
- return this.setMembership(m);
136
- }
137
- withS4() {
138
- return this.withHeaders({ "X-S4": "true" });
139
- }
140
- withTap() {
141
- return this.withHeaders({ "X-Tap": "true" });
142
- }
143
- }
144
- //# sourceMappingURL=test-server-wrapper.js.map