@sera4/essentia 1.1.66-rc.1 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (194) hide show
  1. package/README.md +352 -8
  2. package/dist/ts/index.d.ts +1 -2
  3. package/dist/ts/index.js +1 -3
  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
@@ -1,196 +0,0 @@
1
- import should from "should";
2
- import S4Pagination from "../paginator/s4-pagination.js";
3
- import http_mocks from "node-mocks-http";
4
- import events from "events";
5
-
6
- describe("Pagination", function () {
7
- var paginator = null;
8
- var request = null;
9
- var response = null;
10
- var next = null;
11
-
12
- before("Setup", function () {
13
- next = function () { };
14
- response = http_mocks.createResponse({ eventEmitter: events.EventEmitter });
15
- request = http_mocks.createRequest({
16
- method: "GET",
17
- url: "/"
18
- })
19
- paginator = S4Pagination.createPaginator(request, response, next);
20
- });
21
-
22
- describe("Parsing query parameters", function () {
23
- describe("Default values", function () {
24
- it("should have default page set to 1", function () {
25
- paginator.should.have.property("page", 1);
26
- });
27
-
28
- it("should have default page size set to 5", function () {
29
- paginator.should.have.property("page_size", 5);
30
- });
31
- });
32
-
33
- describe("Page value set to 0", function () {
34
- before("Setup", function () {
35
- request = http_mocks.createRequest({
36
- method: "GET",
37
- url: "/?page=0"
38
- })
39
- paginator = S4Pagination.createPaginator(request, response, next);
40
- });
41
-
42
- it("should set page to 1", function () {
43
- paginator.should.have.property("page", 1);
44
- });
45
- });
46
-
47
- describe("Page value set to negative", function () {
48
- before("Setup", function () {
49
- request = http_mocks.createRequest({
50
- method: "GET",
51
- url: "/?page=-1"
52
- })
53
- paginator = S4Pagination.createPaginator(request, response, next);
54
- });
55
-
56
- it("should set page to 1", function () {
57
- paginator.should.have.property("page", 1);
58
- });
59
- });
60
-
61
- describe("Page value set to 2", function () {
62
- before("Setup", function () {
63
- request = http_mocks.createRequest({
64
- method: "GET",
65
- url: "/?page=2"
66
- })
67
- paginator = S4Pagination.createPaginator(request, response, next);
68
- });
69
-
70
- it("should set page to 2", function () {
71
- paginator.should.have.property("page", 2);
72
- });
73
- });
74
-
75
- describe("Page value set to 10", function () {
76
- before("Setup", function () {
77
- request = http_mocks.createRequest({
78
- method: "GET",
79
- url: "/?page=10"
80
- })
81
- paginator = S4Pagination.createPaginator(request, response, next);
82
- });
83
-
84
- it("should set page to 10", function () {
85
- paginator.should.have.property("page", 10);
86
- });
87
- });
88
-
89
- describe("Page value set to 100", function () {
90
- before("Setup", function () {
91
- request = http_mocks.createRequest({
92
- method: "GET",
93
- url: "/?page=100"
94
- })
95
- paginator = S4Pagination.createPaginator(request, response, next);
96
- });
97
-
98
- it("should set page to 100", function () {
99
- paginator.should.have.property("page", 100);
100
- });
101
- });
102
-
103
- describe("Page Size value set to 0", function () {
104
- before("Setup", function () {
105
- request = http_mocks.createRequest({
106
- method: "GET",
107
- url: "/?page_size=0"
108
- })
109
- paginator = S4Pagination.createPaginator(request, response, next);
110
- });
111
-
112
- it("should set page size to 5", function () {
113
- paginator.should.have.property("page_size", 5);
114
- });
115
- });
116
-
117
- describe("Page Size value set to negative", function () {
118
- before("Setup", function () {
119
- request = http_mocks.createRequest({
120
- method: "GET",
121
- url: "/?page_size=-1"
122
- })
123
- paginator = S4Pagination.createPaginator(request, response, next);
124
- });
125
-
126
- it("should set page size to 5", function () {
127
- paginator.should.have.property("page_size", 5);
128
- });
129
- });
130
-
131
- describe("Page Size value set to 2", function () {
132
- before("Setup", function () {
133
- request = http_mocks.createRequest({
134
- method: "GET",
135
- url: "/?page_size=2"
136
- })
137
- paginator = S4Pagination.createPaginator(request, response, next);
138
- });
139
-
140
- it("should set page size to 5", function () {
141
- paginator.should.have.property("page_size", 5);
142
- });
143
- });
144
-
145
- describe("Page Size value set to 10", function () {
146
- before("Setup", function () {
147
- request = http_mocks.createRequest({
148
- method: "GET",
149
- url: "/?page_size=10"
150
- })
151
- paginator = S4Pagination.createPaginator(request, response, next);
152
- });
153
-
154
- it("should set page size to 10", function () {
155
- paginator.should.have.property("page_size", 10);
156
- });
157
- });
158
-
159
- describe("Page Size value set to 100", function () {
160
- before("Setup", function () {
161
- request = http_mocks.createRequest({
162
- method: "GET",
163
- url: "/?page_size=100"
164
- })
165
- paginator = S4Pagination.createPaginator(request, response, next);
166
- });
167
-
168
- it("should set page size to 100", function () {
169
- paginator.should.have.property("page_size", 100);
170
- });
171
- });
172
- });
173
-
174
- describe("Replying", function() {
175
- beforeEach("Clear request", function() {
176
- response = http_mocks.createResponse({ eventEmitter: events.EventEmitter });
177
- paginator = S4Pagination.createPaginator(request, response, next);
178
- });
179
-
180
- it ("should return 500 if data is null", function(){
181
- paginator.reply(null);
182
- response.statusCode.should.equal(500);
183
- });
184
-
185
- it ("should return pagination data", function(){
186
- const items = [1,2,3,4,5,6,7,8,9,10];
187
- const data = {
188
- docs : items,
189
- total : items.length,
190
- };
191
- paginator.reply(data);
192
- response.statusCode.should.equal(200);
193
- response._getHeaders().should.have.property("s4-pagination");
194
- });
195
- });
196
- });
@@ -1,34 +0,0 @@
1
- import { expect } from "chai";
2
- import serializer from "../serializer/index.js";
3
-
4
- describe("Serializer", () => {
5
-
6
- describe("Serialize", () => {
7
-
8
- it ("should not show Hidden/Removed fields", () => {
9
- const model = { prototype: {} }
10
- model.prototype.get = function() {
11
- return {
12
- name: "John",
13
- hidden_prefs: "should be hidden",
14
- password: "password",
15
- password_salt: "password_salt",
16
- mfa_totp_secret: "mfa_totp_secret",
17
- }
18
- }
19
- const options = { hide: ["hidden_prefs"], remove: ["password", "password_salt", "mfa_totp_secret"] }
20
-
21
- serializer.serialize(model, options);
22
-
23
- const serialized = model.prototype.toJSON();
24
-
25
- expect(serialized.name).to.eq("John");
26
-
27
- expect(serialized.hidden_prefs).to.be.undefined;
28
- expect(serialized.password).to.be.undefined;
29
- expect(serialized.password_salt).to.be.undefined;
30
- expect(serialized.mfa_totp_secret).to.be.undefined;
31
- });
32
-
33
- });
34
- });
@@ -1,145 +0,0 @@
1
- import { expect } from "chai";
2
-
3
- import { utils } from "../utils/index.js";
4
- import { TWS_ROUTE_TYPES } from "../constants/index.js";
5
-
6
- describe("Utils", () => {
7
-
8
- describe("UUID V4", () => {
9
-
10
- it ("should not validate ABCD", () => {
11
- expect(utils.isValidUuidV4("ABC")).to.be.false
12
- });
13
-
14
- it ("should not validate null", () => {
15
- expect(utils.isValidUuidV4(null)).to.be.false
16
- });
17
-
18
- it ("should not validate undefined", () => {
19
- expect(utils.isValidUuidV4()).to.be.false
20
- });
21
-
22
- it ("should not validate empty string", () => {
23
- expect(utils.isValidUuidV4("")).to.be.false
24
- });
25
-
26
- it ("should not validate 26d61a823587-4875-98a8e950e1bf2350", () => {
27
- expect(utils.isValidUuidV4("26d61a823587-4875-98a8-950e1bf2350")).to.be.false
28
- });
29
-
30
- it ("should not validate 26d61a82-3587-4875-98a8-e950e1bf235", () => {
31
- expect(utils.isValidUuidV4("26d61a82-3587-4875-98a8-e950e1bf235")).to.be.false
32
- });
33
-
34
- it ("should not validate 26d61a8-3587-4875-98a8-e950e1bf2350", () => {
35
- expect(utils.isValidUuidV4("26d61a8-3587-4875-98a8-e950e1bf2350")).to.be.false
36
- });
37
-
38
- it ("should not validate 26d61a82-3587-487-98a8-e950e1bf2350", () => {
39
- expect(utils.isValidUuidV4("26d61a82-3587-487-98a8-e950e1bf2350")).to.be.false
40
- });
41
-
42
- it ("should validate 26d61a82-3587-4875-98a8-e950e1bf2350", () => {
43
- expect(utils.isValidUuidV4("26d61a82-3587-4875-98a8-e950e1bf2350")).to.be.true
44
- });
45
-
46
- it ("should validate 26D61A82-3587-4875-98A8-E950E1BF2350", () => {
47
- expect(utils.isValidUuidV4("26D61A82-3587-4875-98A8-E950E1BF2350")).to.be.true
48
- });
49
-
50
- });
51
-
52
- describe("String -> Integer Array", () => {
53
- it ("Should return [] with a null/undefined input", () => {
54
- expect(utils.convertToIntegerArray()).to.be.an('array').that.is.empty;
55
- });
56
-
57
- it ("Should return a valid integer array for '1,2,3'", () => {
58
- expect(utils.convertToIntegerArray('1,2,3')).to.be.an('array').to.deep.equal([1, 2, 3])
59
- });
60
-
61
- it ("Should return a valid integer array for '[1,2,3]'", () => {
62
- expect(utils.convertToIntegerArray('[1,2,3]')).to.be.an('array').to.deep.equal([1, 2, 3])
63
- });
64
-
65
- it ("Should return a valid integer array for '[1,2],3'", () => {
66
- expect(utils.convertToIntegerArray('[1,2],3')).to.be.an('array').to.deep.equal([1, 2])
67
- });
68
-
69
- it ("Should return a valid integer array for '[1,2]],3'", () => {
70
- expect(utils.convertToIntegerArray('[1,2]],3')).to.be.an('array').to.deep.equal([1, 2])
71
- });
72
-
73
- it ("Should return a valid integer array for '[1,2,3'", () => {
74
- expect(utils.convertToIntegerArray('[1,2,3')).to.be.an('array').to.deep.equal([1, 2, 3])
75
- });
76
-
77
- it ("Should return a valid integer array for '1[1,2],3'", () => {
78
- expect(utils.convertToIntegerArray('1[1,2],3')).to.be.an('array').to.deep.equal([1, 2])
79
- });
80
-
81
- it ("Should return a valid integer array for 1", () => {
82
- expect(utils.convertToIntegerArray(1)).to.be.an('array').to.deep.equal([1])
83
- });
84
-
85
- it ("Should return a valid integer array for '1'", () => {
86
- expect(utils.convertToIntegerArray('1')).to.be.an('array').to.deep.equal([1])
87
- });
88
-
89
- it ("Should return a valid integer array for '1w'", () => {
90
- expect(utils.convertToIntegerArray('1w')).to.be.an('array').to.deep.equal([1])
91
- });
92
-
93
- it ("Should return a valid integer array for '[1,2e'", () => {
94
- expect(utils.convertToIntegerArray('[1,2e')).to.be.an('array').to.deep.equal([1,2])
95
- });
96
- });
97
-
98
- describe("Route testing", () => {
99
- it ("Return -1 for a blank domain", () => {
100
- expect(utils.getRouteType('')).to.eq(-1);
101
- });
102
- it ("Return a web route type for tws-web", () => {
103
- const route = utils.getRouteType('tws-web.sera4.com/v3/xxx');
104
- expect(route).to.eq(TWS_ROUTE_TYPES['web']);
105
- expect(utils.isWebRoute(route)).to.be.true
106
- });
107
- it ("Return a web route type for tws-web-staging", () => {
108
- const route = utils.getRouteType('tws-web-environmentX.sera4.com/v3/xxx');
109
- expect(route).to.eq(TWS_ROUTE_TYPES['web']);
110
- expect(utils.isWebRoute(route)).to.be.true
111
- });
112
- it ("Return a mobile route type for tws-mob", () => {
113
- const route = utils.getRouteType('tws-mob.sera4.com/v3/xxx');
114
- expect(route).to.eq(TWS_ROUTE_TYPES['mobile']);
115
- expect(utils.isMobileRoute(route)).to.be.true
116
- });
117
- it ("Return a mobile route type for tws-mob-staging", () => {
118
- const route = utils.getRouteType('tws-mob-environmentX.sera4.com/v3/xxx');
119
- expect(route).to.eq(TWS_ROUTE_TYPES['mobile']);
120
- expect(utils.isMobileRoute(route)).to.be.true
121
- });
122
- it ("Return an API route type for tws-api-xxxx", () => {
123
- const route = utils.getRouteType('tws-api-1234.sera4.com/v3/xxx');
124
- expect(route).to.eq(TWS_ROUTE_TYPES['api']);
125
- expect(utils.isApiRoute(route)).to.be.true
126
- });
127
- it ("Return isWebRoute TRUE for 1 or '1'", () => {
128
- expect(utils.isWebRoute(1)).to.eq(true);
129
- expect(utils.isWebRoute('1')).to.eq(true);
130
- });
131
- it ("Return isMobileRoute TRUE for 2 or '2'", () => {
132
- expect(utils.isMobileRoute(2)).to.eq(true);
133
- expect(utils.isMobileRoute('2')).to.eq(true);
134
- });
135
- it ("Return isApiRoute TRUE for 3 or '3'", () => {
136
- expect(utils.isApiRoute(3)).to.eq(true);
137
- expect(utils.isApiRoute('3')).to.eq(true);
138
- });
139
- it ("Return isApiRoute TRUE for many other values", () => {
140
- expect(utils.isOtherRoute(4)).to.eq(true);
141
- expect(utils.isOtherRoute('4')).to.eq(true);
142
- expect(utils.isOtherRoute('a')).to.eq(true);
143
- });
144
- });
145
- });
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
- }