@sera4/essentia 1.1.65 → 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.
Files changed (112) hide show
  1. package/README.md +352 -8
  2. package/dist/ts/cache/index.d.ts +33 -0
  3. package/dist/ts/cache/index.js +171 -0
  4. package/dist/ts/cache/index.js.map +1 -0
  5. package/dist/ts/configurations/server-config.d.ts +4 -0
  6. package/dist/ts/configurations/server-config.js +2 -0
  7. package/dist/ts/configurations/server-config.js.map +1 -0
  8. package/dist/ts/constants/index.d.ts +7 -0
  9. package/{constants → dist/ts/constants}/index.js +5 -6
  10. package/dist/ts/constants/index.js.map +1 -0
  11. package/dist/ts/cycle/index.d.ts +53 -0
  12. package/dist/ts/cycle/index.js +169 -0
  13. package/dist/ts/cycle/index.js.map +1 -0
  14. package/dist/ts/dns/DnsCache.d.ts +50 -0
  15. package/dist/ts/dns/DnsCache.js +137 -0
  16. package/dist/ts/dns/DnsCache.js.map +1 -0
  17. package/dist/ts/dns/index.d.ts +4 -0
  18. package/dist/ts/dns/index.js +4 -0
  19. package/dist/ts/dns/index.js.map +1 -0
  20. package/dist/ts/formatter/index.d.ts +44 -0
  21. package/dist/ts/formatter/index.js +76 -0
  22. package/dist/ts/formatter/index.js.map +1 -0
  23. package/dist/ts/hal/index.d.ts +26 -0
  24. package/dist/ts/hal/index.js +70 -0
  25. package/dist/ts/hal/index.js.map +1 -0
  26. package/dist/ts/health/index.d.ts +53 -0
  27. package/dist/ts/health/index.js +165 -0
  28. package/dist/ts/health/index.js.map +1 -0
  29. package/dist/ts/helpers/index.d.ts +1 -0
  30. package/dist/ts/helpers/index.js +2 -0
  31. package/dist/ts/helpers/index.js.map +1 -0
  32. package/dist/ts/helpers/test-server-wrapper.d.ts +56 -0
  33. package/dist/ts/helpers/test-server-wrapper.js +144 -0
  34. package/dist/ts/helpers/test-server-wrapper.js.map +1 -0
  35. package/dist/ts/index.d.ts +21 -0
  36. package/dist/ts/index.js +25 -0
  37. package/dist/ts/index.js.map +1 -0
  38. package/dist/ts/last-commit/index.d.ts +12 -0
  39. package/dist/ts/last-commit/index.js +82 -0
  40. package/dist/ts/last-commit/index.js.map +1 -0
  41. package/dist/ts/logger/index.d.ts +3 -0
  42. package/dist/ts/logger/index.js +4 -0
  43. package/dist/ts/logger/index.js.map +1 -0
  44. package/dist/ts/logger/s4-logger.d.ts +23 -0
  45. package/dist/ts/logger/s4-logger.js +103 -0
  46. package/dist/ts/logger/s4-logger.js.map +1 -0
  47. package/dist/ts/paginator/index.d.ts +2 -0
  48. package/dist/ts/paginator/index.js +3 -0
  49. package/dist/ts/paginator/index.js.map +1 -0
  50. package/dist/ts/paginator/s4-pagination.d.ts +26 -0
  51. package/dist/ts/paginator/s4-pagination.js +49 -0
  52. package/dist/ts/paginator/s4-pagination.js.map +1 -0
  53. package/dist/ts/paginator/sql-pagination.d.ts +52 -0
  54. package/dist/ts/paginator/sql-pagination.js +157 -0
  55. package/dist/ts/paginator/sql-pagination.js.map +1 -0
  56. package/dist/ts/paper-trail/helpers.d.ts +14 -0
  57. package/dist/ts/paper-trail/helpers.js +74 -0
  58. package/dist/ts/paper-trail/helpers.js.map +1 -0
  59. package/dist/ts/paper-trail/index.d.ts +54 -0
  60. package/dist/ts/paper-trail/index.js +236 -0
  61. package/dist/ts/paper-trail/index.js.map +1 -0
  62. package/dist/ts/prompts/index.d.ts +21 -0
  63. package/dist/ts/prompts/index.js +68 -0
  64. package/dist/ts/prompts/index.js.map +1 -0
  65. package/dist/ts/queue/index.d.ts +196 -0
  66. package/dist/ts/queue/index.js +371 -0
  67. package/dist/ts/queue/index.js.map +1 -0
  68. package/dist/ts/queue/publisher.d.ts +41 -0
  69. package/dist/ts/queue/publisher.js +84 -0
  70. package/dist/ts/queue/publisher.js.map +1 -0
  71. package/dist/ts/queue/queue-logger.d.ts +10 -0
  72. package/dist/ts/queue/queue-logger.js +35 -0
  73. package/dist/ts/queue/queue-logger.js.map +1 -0
  74. package/dist/ts/queue/subscriber.d.ts +55 -0
  75. package/dist/ts/queue/subscriber.js +98 -0
  76. package/dist/ts/queue/subscriber.js.map +1 -0
  77. package/dist/ts/safe-proxy/index.d.ts +35 -0
  78. package/dist/ts/safe-proxy/index.js +54 -0
  79. package/dist/ts/safe-proxy/index.js.map +1 -0
  80. package/dist/ts/serializer/index.d.ts +52 -0
  81. package/dist/ts/serializer/index.js +83 -0
  82. package/dist/ts/serializer/index.js.map +1 -0
  83. package/dist/ts/utils/index.d.ts +49 -0
  84. package/dist/ts/utils/index.js +157 -0
  85. package/dist/ts/utils/index.js.map +1 -0
  86. package/package.json +52 -11
  87. package/package.tar.gz +0 -0
  88. package/cache/index.js +0 -188
  89. package/formatter/index.js +0 -81
  90. package/hal/README.md +0 -54
  91. package/hal/index.js +0 -75
  92. package/health/health-logger.js +0 -40
  93. package/health/index.js +0 -188
  94. package/helpers/index.js +0 -1
  95. package/helpers/test-server-wrapper.js +0 -196
  96. package/last-commit.js +0 -12
  97. package/last_commit/index.js +0 -82
  98. package/logger/s4-logger.js +0 -128
  99. package/paginator/README.md +0 -183
  100. package/paginator/s4-pagination.js +0 -51
  101. package/paginator/sql-pagination.js +0 -178
  102. package/paper-trail/README.md +0 -68
  103. package/paper-trail/helpers.js +0 -99
  104. package/paper-trail/index.js +0 -842
  105. package/prompts/index.js +0 -78
  106. package/queue/index.js +0 -414
  107. package/queue/publisher.js +0 -96
  108. package/queue/queue-logger.js +0 -40
  109. package/queue/subscriber.js +0 -107
  110. package/safe_proxy/index.js +0 -61
  111. package/serializer/index.js +0 -90
  112. package/utils/index.js +0 -74
@@ -1,107 +0,0 @@
1
- import logger from "./queue-logger.js";
2
-
3
- /**
4
- * A subscriber for AMQP service
5
- */
6
- export class Subscriber {
7
-
8
- /**
9
- * Builds a subscriber
10
- * @param {String} exchange name of the AMQP exchange.
11
- * @param {String} queue name of the AMQP service.
12
- * @param {String} type direct|fanout or other supported connection types.
13
- * @param {String} key routing key. This will be used to bind the queue to the exchange.
14
- * @param {String} name a usefull name to be printed in the logs.
15
- * @param {Object} options connection options
16
- */
17
- constructor(exchange, queue, key, name) {
18
- this.exchange = exchange;
19
- this.queue = queue;
20
- this.key = key;
21
- this.name = name;
22
- this.channel = null;
23
- this.callbacks = [];
24
- }
25
-
26
- /**
27
- * Initializes the subscriber on the given connection.
28
- * During this call, the exchange and the queues are asserted
29
- * and bound via the key provided in the constructor.
30
- * @param {Object} conn aqmp connection object
31
- */
32
- async init (conn) {
33
- logger.debug(`Initializing SUB channel for ${this.name}`);
34
-
35
- if(this.channel) {
36
- logger.warn(`SUB channel for ${this.name} already initialized`);
37
- return;
38
- }
39
-
40
- this.channel = await conn.createChannel();
41
- if (!this.channel) {
42
- throw(new Error(`Cannot create SUB channel for ${this.name}`));
43
- }
44
-
45
- this.channel.on("error", (err) => {
46
- logger.debug(`Connection error for ${this.name}`, err);
47
- this.channel = null;
48
- });
49
-
50
- this.channel.on("close", () => {
51
- logger.debug(`Connection closed for ${this.name}`);
52
- this.channel = null;
53
- });
54
-
55
- logger.debug(`Initialized SUB channel for ${this.name}`);
56
- const { name: exchangeName, options: exchangeOptions, type } = this.exchange;
57
- const { name: queueName, options: queueOptions } = this.queue;
58
-
59
- await this.channel.assertExchange(exchangeName, type, exchangeOptions);
60
- await this.channel.assertQueue(queueName, queueOptions);
61
-
62
- logger.debug(`Binding queue ${queueName} on ${exchangeName} exchange for ${this.key} key`);
63
- await this.channel.bindQueue(queueName, exchangeName, this.key);
64
-
65
- this.channel.consume(queueName, (msg) => {
66
- const { fields, content } = msg;
67
- let payload = null;
68
- let error = null;
69
- try {
70
- payload = JSON.parse(content.toString());
71
- } catch (e) {
72
- logger.error("Failed to parse incomming message:", e);
73
- error = e;
74
- payload = { error, original_content: content.toString() };
75
- }
76
- payload.metadata = fields;
77
- logger.debug(`Got message from exchange '${fields.exchange}' with key '${fields.routingKey}'`);
78
- logger.debug("Content", payload);
79
- this.callbacks.forEach(cb => {
80
- cb(payload, error);
81
- });
82
- this.channel.ack(msg);
83
- }, { noAck: false });
84
- }
85
-
86
- /**
87
- * Closes the channel
88
- * @returns promise
89
- */
90
- async closeChannel() {
91
- if (this.channel) {
92
- logger.debug("Closing subscriber channel", this.name);
93
- return this.channel.close();
94
- } else {
95
- logger.error("Can't close a null subscriber channel");
96
- }
97
- }
98
-
99
- /**
100
- * Register a new callback to recive message through this
101
- * subscriber object
102
- * @param {function} cb A callback to be called when a message arrives
103
- */
104
- registerCallback(cb) {
105
- this.callbacks.push(cb);
106
- }
107
- }
@@ -1,61 +0,0 @@
1
- "use strict";
2
-
3
- import axios from "axios";
4
- import lodash from 'lodash';
5
- const { omitBy, isNil } = lodash;
6
-
7
- /* A class which safely wraps an axios connection in order to pass the current user through to
8
- * the next service. Useful when one of our microservices requires auth as either an admin (sera4tal)
9
- * or as the end user (example: DELETE /auth/sessions/:id
10
- *
11
- * Similar to proxy however this isn't a proxy, it's a full out new call that we can manage
12
- * each method requires a res.locals from a pre-authd session
13
- */
14
- class SafeProxy {
15
- constructor() {
16
- }
17
-
18
- // a safe post request
19
- // locals = res.locals - your authentication details
20
- post(locals, url, options = { headers: {}, data: {}}) {
21
- let { account, tenant, membership } = locals;
22
- return this._proxyRequest({ account, tenant, membership }, url, "post", options);
23
- }
24
- delete(locals, url, options = { headers: {}, data: {}}) {
25
- let { account, tenant, membership } = locals;
26
- return this._proxyRequest({ account, tenant, membership }, url, "delete", options);
27
- }
28
-
29
- /* private methods */
30
- // supports get, delete, post
31
- // options includes { headers, data } for post / delete payloads
32
- async _proxyRequest(locals, url, method = "get", options) {
33
- let request;
34
- let membership = locals.membership ? JSON.stringify(locals.membership) : null;
35
- let headers = omitBy({ ...options.headers,
36
- "tws-account-id": locals.account?.id,
37
- "tws-tenant-id": locals.tenant?.id,
38
- "tws-membership-id": locals.membership?.id,
39
- "tws-membership": membership
40
- }, isNil);
41
-
42
- switch(method) {
43
- case "post":
44
- request = axios.post(url, { ...options.data }, { headers })
45
- break;
46
- case "delete":
47
- request = axios.delete(url, { ...options.data, headers } )
48
- break;
49
- case "get":
50
- request = axios.get(url, { headers, data } )
51
- break;
52
- default:
53
- throw new Error("uknown type called in proxyRequest");
54
- }
55
-
56
- return request;
57
- }
58
-
59
- }
60
-
61
- export const safeProxy = new SafeProxy();
@@ -1,90 +0,0 @@
1
- import _ from "lodash";
2
-
3
- const customSerializers = {};
4
-
5
- export default {
6
- /**
7
- * Seralizes a Sequelize Model.
8
- * @param {Object} Model the squelize model to add this plugin to
9
- * @param {Object} options various options for serialization. These can be:
10
- * • hide - an array of fields to be omitted
11
- * • remove - an array of fields ot be REMOVED so they cannot be unhidden
12
- * • decorators - an array of special decorators to run during serialization
13
- * • handler - a handler for transforming data using only the values
14
- * • advhandler - an advanced handler for transforming data using the value, object or options
15
- * • includeAllFields - show fields that are normally hidden
16
- * • includeFields[..] - show specific fields that are normally hidden
17
- */
18
- serialize : (Model, options) => {
19
- Model.prototype.toJSON = function(eachOptions={}) {
20
- const hide = options && options.hide ? options.hide : [];
21
- const remove = options && options.remove ? options.remove : [];
22
- // ignore hide principles; but still do NOT show null
23
- const includeAllFields = eachOptions["includeAllFields"];
24
-
25
- // optionally force a normally hidden fields to be seen (by name)
26
- const includeFields = eachOptions["includeFields"] || []
27
- const handlerOptions = eachOptions["handlerOptions"] || {}
28
-
29
- const values = this.get();
30
-
31
- if (options?.decorators) {
32
- options.decorators.forEach(dec => {
33
- const k = dec.name;
34
- const v = values[k];
35
- // the advanced handler takes more parameters
36
- if (dec.advHandler) {
37
- values[k] = dec.advHandler(v, this, handlerOptions);
38
- } else {
39
- values[k] = dec.handler(v);
40
- }
41
- });
42
- }
43
-
44
- // for security reasons, some fields may need to be removed, such as
45
- // password salts and mfa tokens
46
- remove.forEach((field) => {
47
- delete values[field];
48
- });
49
-
50
- // hidden fields CAN be resurrected if NOT null, and forced to be
51
- // included
52
- let serialized = _.omitBy(values, (v, k) => {
53
- if (v === null) return true;
54
-
55
- let omitted = (includeAllFields ? false : hide.includes(k));
56
- if (omitted && includeFields[k]) omitted = true ;
57
- return omitted;
58
- });
59
-
60
- const s = eachOptions["serializer"];
61
- if (s && customSerializers[s]) {
62
- serialized = customSerializers[s](serialized);
63
- }
64
-
65
- if (Array.isArray(eachOptions.includes)) {
66
- // Attach any included options that are
67
- // not null or undefined
68
- eachOptions.includes.forEach(include => {
69
- if (include) {
70
- const key = Object.keys(include);
71
- const value = include[key];
72
- if (value) {
73
- serialized[key] = value;
74
- }
75
- }
76
- });
77
- }
78
- return serialized;
79
- }
80
- },
81
-
82
- /**
83
- * Registers a custom serializer.
84
- * @param {String} name the name of the custom serializer
85
- * @param {Function} serializer a custom serializer function associated with the name
86
- */
87
- register : (name, serializer) => {
88
- customSerializers[name] = serializer;
89
- }
90
- }
package/utils/index.js DELETED
@@ -1,74 +0,0 @@
1
- "use strict";
2
-
3
- import { TWS_ROUTE_TYPES } from "../constants/index.js";
4
-
5
- export const utils = {
6
- isValidUuidV4 : (input) => {
7
- if (!input) {
8
- return false
9
- } else {
10
- return /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/.test(input);
11
- }
12
- },
13
- // convert a regular string or Array to array (ie, "[1,2,3, 0xA]", "1,2,3,10")
14
- // useful for controller inputs
15
- // - also accepts hex
16
- convertToIntegerArray(input) {
17
- return this.convertToArray(input)
18
- .filter((el) => /^[0-9]+/.test(el))
19
- .map((el) => parseInt(el))
20
- .filter((el) => Number.isInteger(el));
21
- },
22
- convertToArray: (input) => {
23
- if (Array.isArray(input)){
24
- return input
25
- } else {
26
- if (!!input) {
27
- if (typeof input === "number") {
28
- return [ input ]
29
- }
30
- let matches;
31
- if (matches = input.match(/\[(.*?)\]/)) {
32
- input = matches[1]
33
- }
34
- input = input.replace(/[\[\]]/, '')
35
-
36
- return input.replace(/\s+/, '').split(',').filter((el) => /^[0-9A-Za-z-.]+/.test(el));
37
- } else {
38
- return []
39
- }
40
- }
41
- },
42
- isBlank: (str) => {
43
- return ((str === null) || (str === undefined) || /^\s*$/.test(str));
44
- },
45
- getRouteType: (domain) => {
46
- if (!domain)
47
- return -1;
48
-
49
- let routeType;
50
-
51
- switch (true) {
52
- case /^(tws-web|local-gateway)/i.test(domain):
53
- routeType = TWS_ROUTE_TYPES['web'];
54
- break;
55
- case /^tws-mob/i.test(domain):
56
- routeType = TWS_ROUTE_TYPES['mobile'];
57
- break;
58
- case /^(tws-api-)/i.test(domain):
59
- routeType = TWS_ROUTE_TYPES['api'];
60
- break;
61
- default:
62
- routeType = TWS_ROUTE_TYPES['other'];
63
- }
64
-
65
- return routeType;
66
- },
67
- isWebRoute: (sessionType) => (parseInt(sessionType) === TWS_ROUTE_TYPES['web']),
68
- isApiRoute: (sessionType) => (parseInt(sessionType) === TWS_ROUTE_TYPES['api']),
69
- isMobileRoute: (sessionType) => (parseInt(sessionType) === TWS_ROUTE_TYPES['mobile']),
70
- isOtherRoute: (sessionType) => {
71
- const value = parseInt(sessionType);
72
- return ((value === TWS_ROUTE_TYPES['other']) || isNaN(value)) ? true : false;
73
- }
74
- }