core-services-sdk 1.3.27 → 1.3.29
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
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
-
import * as amqp from 'amqplib'
|
|
3
2
|
import { ulid } from 'ulid'
|
|
3
|
+
import * as amqp from 'amqplib'
|
|
4
|
+
|
|
5
|
+
import { mask } from '../util/mask-sensitive.js'
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* @typedef {Object} Log
|
|
@@ -19,7 +21,7 @@ const generateMsgId = () => `rbt_${ulid()}`
|
|
|
19
21
|
*/
|
|
20
22
|
export const connectQueueService = async ({ host, log }) => {
|
|
21
23
|
const t0 = Date.now()
|
|
22
|
-
const logger = log.child({ op: 'connectQueueService', host })
|
|
24
|
+
const logger = log.child({ op: 'connectQueueService', host: mask(host) })
|
|
23
25
|
|
|
24
26
|
try {
|
|
25
27
|
logger.debug('start')
|
|
@@ -48,7 +50,7 @@ export const connectQueueService = async ({ host, log }) => {
|
|
|
48
50
|
*/
|
|
49
51
|
export const createChannel = async ({ host, log }) => {
|
|
50
52
|
const t0 = Date.now()
|
|
51
|
-
const logger = log.child({ op: 'createChannel', host })
|
|
53
|
+
const logger = log.child({ op: 'createChannel', host: mask(host) })
|
|
52
54
|
|
|
53
55
|
try {
|
|
54
56
|
logger.debug('start')
|
|
@@ -168,7 +170,7 @@ export const subscribeToQueue = async ({
|
|
|
168
170
|
*/
|
|
169
171
|
export const initializeQueue = async ({ host, log }) => {
|
|
170
172
|
const channel = await createChannel({ host, log })
|
|
171
|
-
const logger = log.child({ op: 'initializeQueue' })
|
|
173
|
+
const logger = log.child({ op: 'initializeQueue', host: mask(host) })
|
|
172
174
|
|
|
173
175
|
/**
|
|
174
176
|
* Publishes a message to a queue with a generated `rbt_<ulid>` ID.
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Mask middle of a primitive value while keeping left/right edges.
|
|
3
3
|
* @param {string|number|boolean|null|undefined} value
|
|
4
|
-
* @param {string} [fill='
|
|
5
|
-
* @param {number} [maskLen=
|
|
4
|
+
* @param {string} [fill='.']
|
|
5
|
+
* @param {number} [maskLen=2]
|
|
6
6
|
* @param {number} [left=4]
|
|
7
7
|
* @param {number} [right=4]
|
|
8
8
|
* @returns {string}
|
|
9
9
|
*/
|
|
10
10
|
export const maskSingle = (
|
|
11
11
|
value,
|
|
12
|
-
fill = '
|
|
13
|
-
maskLen =
|
|
14
|
-
left =
|
|
15
|
-
right =
|
|
12
|
+
fill = '.',
|
|
13
|
+
maskLen = null,
|
|
14
|
+
left = 2,
|
|
15
|
+
right = 2,
|
|
16
16
|
) => {
|
|
17
17
|
if (value == null) {
|
|
18
18
|
return ''
|
|
@@ -21,14 +21,19 @@ export const maskSingle = (
|
|
|
21
21
|
if (str.length === 0) {
|
|
22
22
|
return ''
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
if (typeof value === 'boolean') {
|
|
26
|
+
return str
|
|
27
|
+
}
|
|
28
|
+
const m =
|
|
29
|
+
null === maskLen ? Math.max(1, str.length - (right + left)) : maskLen
|
|
25
30
|
|
|
26
31
|
if (str.length <= left + right) {
|
|
27
32
|
if (str.length === 1) {
|
|
28
33
|
return fill
|
|
29
34
|
}
|
|
30
35
|
if (str.length === 2) {
|
|
31
|
-
return str[0] + fill.repeat(
|
|
36
|
+
return str[0] + fill.repeat(1) // "ab" -> "a.."
|
|
32
37
|
}
|
|
33
38
|
return str.slice(0, 1) + fill.repeat(m) + str.slice(-1)
|
|
34
39
|
}
|
|
@@ -39,13 +44,19 @@ export const maskSingle = (
|
|
|
39
44
|
/**
|
|
40
45
|
* Recursively mask values in strings, numbers, booleans, arrays, and objects.
|
|
41
46
|
* @param {string|number|boolean|Array|Object|null|undefined} value
|
|
42
|
-
* @param {string} [fill='
|
|
43
|
-
* @param {number} [maskLen=
|
|
47
|
+
* @param {string} [fill='.']
|
|
48
|
+
* @param {number} [maskLen=2]
|
|
44
49
|
* @param {number} [left=4]
|
|
45
50
|
* @param {number} [right=4]
|
|
46
51
|
* @returns {string|Array|Object}
|
|
47
52
|
*/
|
|
48
|
-
export const mask = (
|
|
53
|
+
export const mask = (
|
|
54
|
+
value,
|
|
55
|
+
fill = '.',
|
|
56
|
+
maskLen = null,
|
|
57
|
+
left = 2,
|
|
58
|
+
right = 2,
|
|
59
|
+
) => {
|
|
49
60
|
const type = typeof value
|
|
50
61
|
|
|
51
62
|
if (value instanceof Date) {
|
|
@@ -4,30 +4,37 @@ import { mask, maskSingle } from '../../src/util/index.js'
|
|
|
4
4
|
|
|
5
5
|
describe('maskSingle', () => {
|
|
6
6
|
it('masks middle of a regular string (length == left+right)', () => {
|
|
7
|
-
|
|
7
|
+
const value = maskSingle('abcdefgh')
|
|
8
|
+
expect(value).toBe('ab....gh')
|
|
8
9
|
})
|
|
9
10
|
|
|
10
11
|
it('masks numbers with default settings', () => {
|
|
11
|
-
expect(maskSingle(12345678)).toBe('
|
|
12
|
+
expect(maskSingle(12345678)).toBe('12....78')
|
|
12
13
|
})
|
|
13
14
|
|
|
14
15
|
it('masks booleans', () => {
|
|
15
|
-
|
|
16
|
-
expect(
|
|
16
|
+
const trueValue = maskSingle(true)
|
|
17
|
+
expect(trueValue).toBe('true')
|
|
18
|
+
const falseValue = maskSingle(false)
|
|
19
|
+
expect(falseValue).toBe('false')
|
|
17
20
|
})
|
|
18
21
|
|
|
19
22
|
it('masks very short strings correctly', () => {
|
|
20
|
-
|
|
21
|
-
expect(
|
|
23
|
+
const value1 = maskSingle('ab')
|
|
24
|
+
expect(value1).toBe('a.') // will produce 'a.'
|
|
25
|
+
const value2 = maskSingle('a')
|
|
26
|
+
expect(value2).toBe('.')
|
|
22
27
|
expect(maskSingle('')).toBe('')
|
|
23
28
|
})
|
|
24
29
|
|
|
25
30
|
it('respects custom fill and mask length', () => {
|
|
26
|
-
|
|
31
|
+
const value = maskSingle('abcdefgh', '*', 5)
|
|
32
|
+
expect(value).toBe('ab*****gh')
|
|
27
33
|
})
|
|
28
34
|
|
|
29
35
|
it('ensures maskLen is at least 1', () => {
|
|
30
|
-
|
|
36
|
+
const value = maskSingle('abcdefgh', '*', 1, 1, 1)
|
|
37
|
+
expect(value).toBe('a*h')
|
|
31
38
|
})
|
|
32
39
|
|
|
33
40
|
it('returns empty string for null/undefined', () => {
|
|
@@ -38,9 +45,10 @@ describe('maskSingle', () => {
|
|
|
38
45
|
|
|
39
46
|
describe('mask', () => {
|
|
40
47
|
it('masks primitives (string, number, boolean)', () => {
|
|
41
|
-
expect(mask('abcdefgh')).toBe('
|
|
42
|
-
expect(mask(12345678)).toBe('
|
|
43
|
-
|
|
48
|
+
expect(mask('abcdefgh')).toBe('ab....gh')
|
|
49
|
+
expect(mask(12345678)).toBe('12....78')
|
|
50
|
+
const trueValue = mask(true)
|
|
51
|
+
expect(trueValue).toBe('true')
|
|
44
52
|
expect(mask(false)).toBe('false')
|
|
45
53
|
})
|
|
46
54
|
|
|
@@ -50,20 +58,22 @@ describe('mask', () => {
|
|
|
50
58
|
})
|
|
51
59
|
|
|
52
60
|
it('masks arrays recursively', () => {
|
|
53
|
-
|
|
61
|
+
const value = mask(['abcdefgh', 12345678])
|
|
62
|
+
expect(value).toEqual(['ab....gh', '12....78'])
|
|
54
63
|
})
|
|
55
64
|
|
|
56
65
|
it('masks objects recursively', () => {
|
|
57
66
|
expect(mask({ a: 'abcdefgh', b: 12345678 })).toEqual({
|
|
58
|
-
a: '
|
|
59
|
-
b: '
|
|
67
|
+
a: 'ab....gh',
|
|
68
|
+
b: '12....78',
|
|
60
69
|
})
|
|
61
70
|
})
|
|
62
71
|
|
|
63
72
|
it('masks nested objects/arrays recursively', () => {
|
|
64
73
|
const input = { arr: ['abcdefgh', { num: 12345678 }] }
|
|
65
|
-
const expected = { arr: ['
|
|
66
|
-
|
|
74
|
+
const expected = { arr: ['ab....gh', { num: '12....78' }] }
|
|
75
|
+
const value = mask(input)
|
|
76
|
+
expect(value).toEqual(expected)
|
|
67
77
|
})
|
|
68
78
|
|
|
69
79
|
it('handles Date instances by returning full ISO string', () => {
|
|
@@ -73,7 +83,8 @@ describe('mask', () => {
|
|
|
73
83
|
|
|
74
84
|
it('respects custom fill and mask length in recursive calls', () => {
|
|
75
85
|
const input = { val: 'abcdefgh' }
|
|
76
|
-
const expected = { val: '
|
|
77
|
-
|
|
86
|
+
const expected = { val: 'ab*****gh' }
|
|
87
|
+
const value = mask(input, '*', 5)
|
|
88
|
+
expect(value).toEqual(expected)
|
|
78
89
|
})
|
|
79
90
|
})
|