@sera4/essentia 1.1.66-rc.1 → 3.0.8

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 (194) hide show
  1. package/README.md +352 -8
  2. package/dist/ts/index.d.ts +1 -1
  3. package/dist/ts/index.js +1 -1
  4. package/dist/ts/index.js.map +1 -1
  5. package/dist/ts/logger/s4-logger.js +0 -2
  6. package/dist/ts/logger/s4-logger.js.map +1 -1
  7. package/dist/ts/queue/index.d.ts +2 -38
  8. package/dist/ts/queue/index.js +67 -136
  9. package/dist/ts/queue/index.js.map +1 -1
  10. package/package.json +51 -12
  11. package/package.tar.gz +0 -0
  12. package/cache/index.js +0 -188
  13. package/constants/index.js +0 -9
  14. package/coverage/base.css +0 -224
  15. package/coverage/block-navigation.js +0 -87
  16. package/coverage/configurations/index.html +0 -116
  17. package/coverage/configurations/server-config.ts.html +0 -94
  18. package/coverage/dns/DnsCache.ts.html +0 -598
  19. package/coverage/dns/index.html +0 -131
  20. package/coverage/dns/index.ts.html +0 -94
  21. package/coverage/favicon.png +0 -0
  22. package/coverage/health/index.html +0 -116
  23. package/coverage/health/index.ts.html +0 -778
  24. package/coverage/index.html +0 -161
  25. package/coverage/lcov-report/base.css +0 -224
  26. package/coverage/lcov-report/block-navigation.js +0 -87
  27. package/coverage/lcov-report/configurations/index.html +0 -116
  28. package/coverage/lcov-report/configurations/server-config.ts.html +0 -94
  29. package/coverage/lcov-report/dns/DnsCache.ts.html +0 -598
  30. package/coverage/lcov-report/dns/index.html +0 -131
  31. package/coverage/lcov-report/dns/index.ts.html +0 -94
  32. package/coverage/lcov-report/favicon.png +0 -0
  33. package/coverage/lcov-report/health/index.html +0 -116
  34. package/coverage/lcov-report/health/index.ts.html +0 -778
  35. package/coverage/lcov-report/index.html +0 -161
  36. package/coverage/lcov-report/logger/index.html +0 -131
  37. package/coverage/lcov-report/logger/index.ts.html +0 -94
  38. package/coverage/lcov-report/logger/s4-logger.ts.html +0 -514
  39. package/coverage/lcov-report/prettify.css +0 -1
  40. package/coverage/lcov-report/prettify.js +0 -2
  41. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  42. package/coverage/lcov-report/sorter.js +0 -196
  43. package/coverage/lcov.info +0 -747
  44. package/coverage/logger/index.html +0 -131
  45. package/coverage/logger/index.ts.html +0 -94
  46. package/coverage/logger/s4-logger.ts.html +0 -514
  47. package/coverage/prettify.css +0 -1
  48. package/coverage/prettify.js +0 -2
  49. package/coverage/sort-arrow-sprite.png +0 -0
  50. package/coverage/sorter.js +0 -196
  51. package/coverage/tmp/coverage-24302-1746472691313-0.json +0 -1
  52. package/coverage/tmp/coverage-24302-1746472691366-1.json +0 -1
  53. package/dist/cache/index.d.ts +0 -22
  54. package/dist/cache/index.js +0 -166
  55. package/dist/cache/index.js.map +0 -1
  56. package/dist/constants/index.d.ts +0 -6
  57. package/dist/constants/index.js +0 -9
  58. package/dist/constants/index.js.map +0 -1
  59. package/dist/coverage/block-navigation.d.ts +0 -1
  60. package/dist/coverage/block-navigation.js +0 -70
  61. package/dist/coverage/block-navigation.js.map +0 -1
  62. package/dist/coverage/lcov-report/block-navigation.d.ts +0 -1
  63. package/dist/coverage/lcov-report/block-navigation.js +0 -70
  64. package/dist/coverage/lcov-report/block-navigation.js.map +0 -1
  65. package/dist/coverage/lcov-report/prettify.d.ts +0 -0
  66. package/dist/coverage/lcov-report/prettify.js +0 -477
  67. package/dist/coverage/lcov-report/prettify.js.map +0 -1
  68. package/dist/coverage/lcov-report/sorter.d.ts +0 -1
  69. package/dist/coverage/lcov-report/sorter.js +0 -163
  70. package/dist/coverage/lcov-report/sorter.js.map +0 -1
  71. package/dist/coverage/prettify.d.ts +0 -0
  72. package/dist/coverage/prettify.js +0 -477
  73. package/dist/coverage/prettify.js.map +0 -1
  74. package/dist/coverage/sorter.d.ts +0 -1
  75. package/dist/coverage/sorter.js +0 -163
  76. package/dist/coverage/sorter.js.map +0 -1
  77. package/dist/formatter/index.d.ts +0 -37
  78. package/dist/formatter/index.js +0 -75
  79. package/dist/formatter/index.js.map +0 -1
  80. package/dist/hal/index.d.ts +0 -5
  81. package/dist/hal/index.js +0 -69
  82. package/dist/hal/index.js.map +0 -1
  83. package/dist/health/health-logger.d.ts +0 -9
  84. package/dist/health/health-logger.js +0 -34
  85. package/dist/health/health-logger.js.map +0 -1
  86. package/dist/health/index.d.ts +0 -19
  87. package/dist/health/index.js +0 -175
  88. package/dist/health/index.js.map +0 -1
  89. package/dist/helpers/index.d.ts +0 -1
  90. package/dist/helpers/index.js +0 -2
  91. package/dist/helpers/index.js.map +0 -1
  92. package/dist/helpers/test-server-wrapper.d.ts +0 -120
  93. package/dist/helpers/test-server-wrapper.js +0 -165
  94. package/dist/helpers/test-server-wrapper.js.map +0 -1
  95. package/dist/index.d.ts +0 -1
  96. package/dist/index.js +0 -17
  97. package/dist/index.js.map +0 -1
  98. package/dist/last-commit.d.ts +0 -1
  99. package/dist/last-commit.js +0 -12
  100. package/dist/last-commit.js.map +0 -1
  101. package/dist/last_commit/index.d.ts +0 -7
  102. package/dist/last_commit/index.js +0 -83
  103. package/dist/last_commit/index.js.map +0 -1
  104. package/dist/paginator/s4-pagination.d.ts +0 -9
  105. package/dist/paginator/s4-pagination.js +0 -49
  106. package/dist/paginator/s4-pagination.js.map +0 -1
  107. package/dist/paginator/sql-pagination.d.ts +0 -27
  108. package/dist/paginator/sql-pagination.js +0 -166
  109. package/dist/paginator/sql-pagination.js.map +0 -1
  110. package/dist/paper-trail/helpers.d.ts +0 -11
  111. package/dist/paper-trail/helpers.js +0 -74
  112. package/dist/paper-trail/helpers.js.map +0 -1
  113. package/dist/paper-trail/index.d.ts +0 -13
  114. package/dist/paper-trail/index.js +0 -662
  115. package/dist/paper-trail/index.js.map +0 -1
  116. package/dist/prompts/index.d.ts +0 -14
  117. package/dist/prompts/index.js +0 -63
  118. package/dist/prompts/index.js.map +0 -1
  119. package/dist/queue/index.d.ts +0 -166
  120. package/dist/queue/index.js +0 -371
  121. package/dist/queue/index.js.map +0 -1
  122. package/dist/queue/publisher.d.ts +0 -31
  123. package/dist/queue/publisher.js +0 -84
  124. package/dist/queue/publisher.js.map +0 -1
  125. package/dist/queue/queue-logger.d.ts +0 -9
  126. package/dist/queue/queue-logger.js +0 -35
  127. package/dist/queue/queue-logger.js.map +0 -1
  128. package/dist/queue/subscriber.d.ts +0 -39
  129. package/dist/queue/subscriber.js +0 -97
  130. package/dist/queue/subscriber.js.map +0 -1
  131. package/dist/safe_proxy/index.d.ts +0 -13
  132. package/dist/safe_proxy/index.js +0 -54
  133. package/dist/safe_proxy/index.js.map +0 -1
  134. package/dist/serializer/index.d.ts +0 -5
  135. package/dist/serializer/index.js +0 -83
  136. package/dist/serializer/index.js.map +0 -1
  137. package/dist/test/debug-array.d.ts +0 -0
  138. package/dist/test/debug-array.js +0 -1
  139. package/dist/test/debug-array.js.map +0 -1
  140. package/dist/test/debug-setJSONB.d.ts +0 -0
  141. package/dist/test/debug-setJSONB.js +0 -1
  142. package/dist/test/debug-setJSONB.js.map +0 -1
  143. package/dist/test/prompt.test.d.ts +0 -1
  144. package/dist/test/prompt.test.js +0 -74
  145. package/dist/test/prompt.test.js.map +0 -1
  146. package/dist/test/s4-formatter.spec.d.ts +0 -1
  147. package/dist/test/s4-formatter.spec.js +0 -67
  148. package/dist/test/s4-formatter.spec.js.map +0 -1
  149. package/dist/test/s4-pagination.spec.d.ts +0 -1
  150. package/dist/test/s4-pagination.spec.js +0 -170
  151. package/dist/test/s4-pagination.spec.js.map +0 -1
  152. package/dist/test/safe-proxy.spec.d.ts +0 -1
  153. package/dist/test/safe-proxy.spec.js +0 -252
  154. package/dist/test/safe-proxy.spec.js.map +0 -1
  155. package/dist/test/serializer.spec.d.ts +0 -1
  156. package/dist/test/serializer.spec.js +0 -27
  157. package/dist/test/serializer.spec.js.map +0 -1
  158. package/dist/test/utils.spec.d.ts +0 -1
  159. package/dist/test/utils.spec.js +0 -446
  160. package/dist/test/utils.spec.js.map +0 -1
  161. package/dist/ts/task-scheduler/index.d.ts +0 -130
  162. package/dist/ts/task-scheduler/index.js +0 -259
  163. package/dist/ts/task-scheduler/index.js.map +0 -1
  164. package/formatter/index.js +0 -81
  165. package/hal/README.md +0 -54
  166. package/hal/index.js +0 -75
  167. package/health/health-logger.js +0 -40
  168. package/health/index.js +0 -188
  169. package/helpers/index.js +0 -1
  170. package/helpers/test-server-wrapper.js +0 -196
  171. package/last-commit.js +0 -12
  172. package/last_commit/index.js +0 -82
  173. package/logger/s4-logger.js +0 -128
  174. package/paginator/README.md +0 -183
  175. package/paginator/s4-pagination.js +0 -51
  176. package/paginator/sql-pagination.js +0 -178
  177. package/paper-trail/README.md +0 -68
  178. package/paper-trail/helpers.js +0 -99
  179. package/paper-trail/index.js +0 -843
  180. package/prompts/index.js +0 -78
  181. package/queue/index.js +0 -402
  182. package/queue/publisher.js +0 -96
  183. package/queue/queue-logger.js +0 -40
  184. package/queue/subscriber.js +0 -107
  185. package/safe_proxy/index.js +0 -61
  186. package/scripts/publish.sh +0 -46
  187. package/serializer/index.js +0 -90
  188. package/test/health.spec.js +0 -213
  189. package/test/prompt.test.js +0 -91
  190. package/test/s4-formatter.spec.js +0 -80
  191. package/test/s4-pagination.spec.js +0 -196
  192. package/test/serializer.spec.js +0 -34
  193. package/test/utils.spec.js +0 -145
  194. 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
- })
@@ -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;
@@ -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;