@mixd-id/web-scaffold 0.1.240411108 → 0.1.240411110
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/middleware/http/trim-string.js +1 -9
- package/src/utils/helpers.cjs +17 -1
- package/src/utils/helpers.js +17 -1
- package/src/utils/helpers.mjs +16 -0
- package/src/utils/importer.js +2 -2
- package/src/utils/wss.js +10 -5
- package/src/utils/wss.mjs +6 -1
package/package.json
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
for (const key in obj) {
|
|
3
|
-
if (typeof obj[key] === 'string') {
|
|
4
|
-
obj[key] = obj[key].trim();
|
|
5
|
-
} else if (typeof obj[key] === 'object') {
|
|
6
|
-
trimStrings(obj[key]);
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
const { trimStrings } = require('../../utils/helpers')
|
|
10
2
|
|
|
11
3
|
module.exports = async function(req, res, next){
|
|
12
4
|
|
package/src/utils/helpers.cjs
CHANGED
|
@@ -598,6 +598,21 @@ const groupBy = (arr, key) => {
|
|
|
598
598
|
}, {});
|
|
599
599
|
}
|
|
600
600
|
|
|
601
|
+
// Trims string values of an object/array in place (recursive), skips Buffers/typed arrays
|
|
602
|
+
const trimStrings = (obj) => {
|
|
603
|
+
if(!obj || typeof obj !== 'object' || ArrayBuffer.isView(obj)) return obj
|
|
604
|
+
|
|
605
|
+
for(const key in obj){
|
|
606
|
+
const value = obj[key]
|
|
607
|
+
if(typeof value === 'string')
|
|
608
|
+
obj[key] = value.trim()
|
|
609
|
+
else if(value && typeof value === 'object')
|
|
610
|
+
trimStrings(value)
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return obj
|
|
614
|
+
}
|
|
615
|
+
|
|
601
616
|
module.exports = {
|
|
602
617
|
capitalize,
|
|
603
618
|
ceil,
|
|
@@ -631,5 +646,6 @@ module.exports = {
|
|
|
631
646
|
hashMake,
|
|
632
647
|
hashCheck,
|
|
633
648
|
transactionWithRetry,
|
|
634
|
-
groupBy
|
|
649
|
+
groupBy,
|
|
650
|
+
trimStrings
|
|
635
651
|
}
|
package/src/utils/helpers.js
CHANGED
|
@@ -598,6 +598,21 @@ const groupBy = (arr, key) => {
|
|
|
598
598
|
}, {});
|
|
599
599
|
}
|
|
600
600
|
|
|
601
|
+
// Trims string values of an object/array in place (recursive), skips Buffers/typed arrays
|
|
602
|
+
const trimStrings = (obj) => {
|
|
603
|
+
if(!obj || typeof obj !== 'object' || ArrayBuffer.isView(obj)) return obj
|
|
604
|
+
|
|
605
|
+
for(const key in obj){
|
|
606
|
+
const value = obj[key]
|
|
607
|
+
if(typeof value === 'string')
|
|
608
|
+
obj[key] = value.trim()
|
|
609
|
+
else if(value && typeof value === 'object')
|
|
610
|
+
trimStrings(value)
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return obj
|
|
614
|
+
}
|
|
615
|
+
|
|
601
616
|
module.exports = {
|
|
602
617
|
capitalize,
|
|
603
618
|
ceil,
|
|
@@ -631,5 +646,6 @@ module.exports = {
|
|
|
631
646
|
hashMake,
|
|
632
647
|
hashCheck,
|
|
633
648
|
transactionWithRetry,
|
|
634
|
-
groupBy
|
|
649
|
+
groupBy,
|
|
650
|
+
trimStrings
|
|
635
651
|
}
|
package/src/utils/helpers.mjs
CHANGED
|
@@ -510,6 +510,21 @@ const groupBy = (arr, key) => {
|
|
|
510
510
|
}, {});
|
|
511
511
|
}
|
|
512
512
|
|
|
513
|
+
// Trims string values of an object/array in place (recursive), skips Buffers/typed arrays
|
|
514
|
+
const trimStrings = (obj) => {
|
|
515
|
+
if(!obj || typeof obj !== 'object' || ArrayBuffer.isView(obj)) return obj
|
|
516
|
+
|
|
517
|
+
for(const key in obj){
|
|
518
|
+
const value = obj[key]
|
|
519
|
+
if(typeof value === 'string')
|
|
520
|
+
obj[key] = value.trim()
|
|
521
|
+
else if(value && typeof value === 'object')
|
|
522
|
+
trimStrings(value)
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
return obj
|
|
526
|
+
}
|
|
527
|
+
|
|
513
528
|
const arrayPush = (arr, items, opt = { update:true }) => {
|
|
514
529
|
if(!Array.isArray(arr)) return
|
|
515
530
|
if(!Array.isArray(items)) items = [ items ]
|
|
@@ -653,6 +668,7 @@ export {
|
|
|
653
668
|
queueForLaterWithKey,
|
|
654
669
|
transactionWithRetry,
|
|
655
670
|
groupBy,
|
|
671
|
+
trimStrings,
|
|
656
672
|
arrayPush,
|
|
657
673
|
arrayRemove,
|
|
658
674
|
arrayUnshift,
|
package/src/utils/importer.js
CHANGED
|
@@ -3,7 +3,7 @@ const fs = require("fs");
|
|
|
3
3
|
const AdmZip = require("adm-zip");
|
|
4
4
|
const glob = require("glob");
|
|
5
5
|
const Exceljs = require("exceljs")
|
|
6
|
-
const { saveBuffer, unflatten } = require('./helpers.js')
|
|
6
|
+
const { saveBuffer, unflatten, trimStrings } = require('./helpers.js')
|
|
7
7
|
|
|
8
8
|
const getCellText = (cell, image) => {
|
|
9
9
|
if(!cell) return image?.buffer ?? ''
|
|
@@ -259,7 +259,7 @@ const importRequest = async(req) => {
|
|
|
259
259
|
//Object.assign(obj, row)
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
rows.push(unflatten(obj))
|
|
262
|
+
rows.push(trimStrings(unflatten(obj)))
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
Object.assign(doc, {
|
package/src/utils/wss.js
CHANGED
|
@@ -68,6 +68,8 @@ const revertDataUrlObj = (obj) => {
|
|
|
68
68
|
const isClosedError = (e) =>
|
|
69
69
|
e && (e.message === 'Disconnects client' || e.message === 'The client is closed')
|
|
70
70
|
|
|
71
|
+
const REJECT_CLOSE_CODE = 4001
|
|
72
|
+
|
|
71
73
|
const reportError = (e) => {
|
|
72
74
|
if(isClosedError(e)) return
|
|
73
75
|
'$report' in process ? process.$report(e) : console.error(e)
|
|
@@ -134,7 +136,11 @@ class WSS extends EventEmitter2{
|
|
|
134
136
|
|
|
135
137
|
// Protocol errors (e.g. invalid close codes) emit 'error'; without a
|
|
136
138
|
// listener they crash the process. ws closes the socket afterwards.
|
|
137
|
-
|
|
139
|
+
// WS_ERR_* are malformed frames from the client — not worth reporting.
|
|
140
|
+
socket.on('error', (e) => {
|
|
141
|
+
if(`${e?.code ?? ''}`.startsWith('WS_ERR_')) return
|
|
142
|
+
reportError(e)
|
|
143
|
+
})
|
|
138
144
|
|
|
139
145
|
let closed = false
|
|
140
146
|
|
|
@@ -215,8 +221,6 @@ class WSS extends EventEmitter2{
|
|
|
215
221
|
subscriber = client
|
|
216
222
|
await client.connect()
|
|
217
223
|
|
|
218
|
-
// Socket closed while authenticating/connecting: the close handler may
|
|
219
|
-
// have run before the client was open, so release it here.
|
|
220
224
|
if(closed){
|
|
221
225
|
disconnectQuietly(client)
|
|
222
226
|
return
|
|
@@ -228,7 +232,7 @@ class WSS extends EventEmitter2{
|
|
|
228
232
|
catch(e){
|
|
229
233
|
disconnectQuietly(subscriber)
|
|
230
234
|
if(closed) return
|
|
231
|
-
return socket.close(
|
|
235
|
+
return socket.close(REJECT_CLOSE_CODE, (e.message ?? '').substring(0, 123));
|
|
232
236
|
}
|
|
233
237
|
|
|
234
238
|
if(this._opt.ping !== false && !closed){
|
|
@@ -285,7 +289,7 @@ class WSS extends EventEmitter2{
|
|
|
285
289
|
if(typeof obj !== 'object' || obj === null) throw new Error('Invalid message')
|
|
286
290
|
}
|
|
287
291
|
catch(e){
|
|
288
|
-
return socket.close(
|
|
292
|
+
return socket.close(REJECT_CLOSE_CODE, (e.message ?? '').substring(0, 123));
|
|
289
293
|
}
|
|
290
294
|
|
|
291
295
|
const { _requestId, path, params, ping, pong } = obj
|
|
@@ -439,6 +443,7 @@ class WSS extends EventEmitter2{
|
|
|
439
443
|
|
|
440
444
|
module.exports = {
|
|
441
445
|
WSS,
|
|
446
|
+
REJECT_CLOSE_CODE,
|
|
442
447
|
convertDataUrlObj,
|
|
443
448
|
revertDataUrlObj
|
|
444
449
|
}
|
package/src/utils/wss.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import CryptoJS from "crypto-js";
|
|
2
2
|
import EventEmitter2 from "eventemitter2";
|
|
3
3
|
|
|
4
|
+
// Must match REJECT_CLOSE_CODE in wss.js
|
|
5
|
+
const REJECT_CLOSE_CODE = 4001
|
|
6
|
+
|
|
4
7
|
const fileToDataURL = (file) => {
|
|
5
8
|
return new Promise((resolve, reject) => {
|
|
6
9
|
const reader = new FileReader();
|
|
@@ -157,7 +160,8 @@ class WSS extends EventEmitter2{
|
|
|
157
160
|
this._instance.onclose = (e) => {
|
|
158
161
|
switch(e.code){
|
|
159
162
|
|
|
160
|
-
|
|
163
|
+
// Rejected by server (auth failure etc.), retrying won't help
|
|
164
|
+
case REJECT_CLOSE_CODE:
|
|
161
165
|
this.emit('connect_error', e, [])
|
|
162
166
|
break
|
|
163
167
|
|
|
@@ -280,6 +284,7 @@ class WSS extends EventEmitter2{
|
|
|
280
284
|
|
|
281
285
|
export {
|
|
282
286
|
WSS,
|
|
287
|
+
REJECT_CLOSE_CODE,
|
|
283
288
|
fileToDataURL,
|
|
284
289
|
convertDataUrlObj
|
|
285
290
|
}
|