@matterbridge/utils 3.6.2-dev-20260314-f95be8a → 3.6.2-dev-20260316-0b03ae0
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/dist/copyDirectory.js +2 -1
- package/dist/error.d.ts +1 -0
- package/dist/error.js +3 -0
- package/dist/export.d.ts +0 -1
- package/dist/export.js +0 -1
- package/dist/githubVersion.js +3 -2
- package/dist/hex.d.ts +1 -1
- package/dist/hex.js +5 -4
- package/dist/inspector.js +7 -6
- package/dist/npmVersion.js +3 -2
- package/package.json +3 -3
- package/dist/createZip.d.ts +0 -1
- package/dist/createZip.js +0 -69
package/dist/copyDirectory.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getErrorMessage } from './error.js';
|
|
1
2
|
export async function copyDirectory(srcDir, destDir, log) {
|
|
2
3
|
if (srcDir === '') {
|
|
3
4
|
throw new Error('Source directory must be specified.');
|
|
@@ -33,7 +34,7 @@ export async function copyDirectory(srcDir, destDir, log) {
|
|
|
33
34
|
return true;
|
|
34
35
|
}
|
|
35
36
|
catch (error) {
|
|
36
|
-
log?.error(`copyDirectory error copying from ${srcDir} to ${destDir}: ${error
|
|
37
|
+
log?.error(`copyDirectory error copying from ${srcDir} to ${destDir}: ${getErrorMessage(error)}`);
|
|
37
38
|
return false;
|
|
38
39
|
}
|
|
39
40
|
}
|
package/dist/error.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { type AnsiLogger } from 'node-ansi-logger';
|
|
2
|
+
export declare function getErrorMessage(error: unknown): string;
|
|
2
3
|
export declare function logError(log: AnsiLogger, message: string, error: unknown): void;
|
|
3
4
|
export declare function inspectError(log: AnsiLogger, message: string, error: unknown): string;
|
package/dist/error.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { inspect } from 'node:util';
|
|
2
2
|
import { RESET } from 'node-ansi-logger';
|
|
3
|
+
export function getErrorMessage(error) {
|
|
4
|
+
return error instanceof Error ? error.message : String(error);
|
|
5
|
+
}
|
|
3
6
|
export function logError(log, message, error) {
|
|
4
7
|
log.error(`${message}: ${error instanceof Error ? error.message + ' \nStack: \n' + error.stack : error}`);
|
|
5
8
|
}
|
package/dist/export.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ export * from './colorUtils.js';
|
|
|
2
2
|
export * from './commandLine.js';
|
|
3
3
|
export * from './copyDirectory.js';
|
|
4
4
|
export * from './createDirectory.js';
|
|
5
|
-
export * from './createZip.js';
|
|
6
5
|
export * from './deepCopy.js';
|
|
7
6
|
export * from './deepEqual.js';
|
|
8
7
|
export * from './error.js';
|
package/dist/export.js
CHANGED
|
@@ -2,7 +2,6 @@ export * from './colorUtils.js';
|
|
|
2
2
|
export * from './commandLine.js';
|
|
3
3
|
export * from './copyDirectory.js';
|
|
4
4
|
export * from './createDirectory.js';
|
|
5
|
-
export * from './createZip.js';
|
|
6
5
|
export * from './deepCopy.js';
|
|
7
6
|
export * from './deepEqual.js';
|
|
8
7
|
export * from './error.js';
|
package/dist/githubVersion.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getErrorMessage } from './error.js';
|
|
1
2
|
export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
2
3
|
const https = await import('node:https');
|
|
3
4
|
return new Promise((resolve, reject) => {
|
|
@@ -25,13 +26,13 @@ export async function getGitHubUpdate(branch, file, timeout = 10000) {
|
|
|
25
26
|
resolve(jsonData);
|
|
26
27
|
}
|
|
27
28
|
catch (error) {
|
|
28
|
-
reject(new Error(`Failed to parse response JSON: ${error
|
|
29
|
+
reject(new Error(`Failed to parse response JSON: ${getErrorMessage(error)}`));
|
|
29
30
|
}
|
|
30
31
|
});
|
|
31
32
|
});
|
|
32
33
|
req.on('error', (error) => {
|
|
33
34
|
clearTimeout(timeoutId);
|
|
34
|
-
reject(new Error(`Request failed: ${error
|
|
35
|
+
reject(new Error(`Request failed: ${getErrorMessage(error)}`));
|
|
35
36
|
});
|
|
36
37
|
});
|
|
37
38
|
}
|
package/dist/hex.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function bufferToHex(buffer: ArrayBufferLike): string;
|
|
1
|
+
export declare function bufferToHex(buffer: ArrayBufferLike | ArrayBufferView): string;
|
|
2
2
|
export declare function hexToBuffer(hex: string): Uint8Array;
|
|
3
3
|
export declare function pemToBuffer(pem: string, validate?: boolean): Uint8Array;
|
|
4
4
|
export declare function extractPrivateKeyRaw(pemPrivateKey: string): Uint8Array;
|
package/dist/hex.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createPrivateKey, createPublicKey, X509Certificate } from 'node:crypto';
|
|
2
|
+
import { getErrorMessage } from './error.js';
|
|
2
3
|
export function bufferToHex(buffer) {
|
|
3
4
|
if (!(buffer instanceof ArrayBuffer || ArrayBuffer.isView(buffer))) {
|
|
4
5
|
throw new TypeError('Expected input to be an ArrayBuffer or ArrayBufferView');
|
|
5
6
|
}
|
|
6
|
-
const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
7
|
+
const bytes = buffer instanceof Uint8Array ? buffer : ArrayBuffer.isView(buffer) ? new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength) : new Uint8Array(buffer);
|
|
7
8
|
return Array.from(bytes)
|
|
8
9
|
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
9
10
|
.join('');
|
|
@@ -86,13 +87,13 @@ export function pemToBuffer(pem, validate = false) {
|
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
catch (validationError) {
|
|
89
|
-
throw new Error(`PEM validation failed: ${
|
|
90
|
+
throw new Error(`PEM validation failed: ${getErrorMessage(validationError)}`, { cause: validationError });
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
return result;
|
|
93
94
|
}
|
|
94
95
|
catch (error) {
|
|
95
|
-
throw new Error(`Failed to decode base64 content: ${
|
|
96
|
+
throw new Error(`Failed to decode base64 content: ${getErrorMessage(error)}`, { cause: error });
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
export function extractPrivateKeyRaw(pemPrivateKey) {
|
|
@@ -113,6 +114,6 @@ export function extractPrivateKeyRaw(pemPrivateKey) {
|
|
|
113
114
|
return new Uint8Array(rawPrivateKey);
|
|
114
115
|
}
|
|
115
116
|
catch (error) {
|
|
116
|
-
throw new Error(`Failed to extract private key: ${
|
|
117
|
+
throw new Error(`Failed to extract private key: ${getErrorMessage(error)}`, { cause: error });
|
|
117
118
|
}
|
|
118
119
|
}
|
package/dist/inspector.js
CHANGED
|
@@ -2,6 +2,7 @@ if (process.argv.includes('--loader') || process.argv.includes('-loader'))
|
|
|
2
2
|
console.log('\u001B[32mInspector loaded.\u001B[40;0m');
|
|
3
3
|
import EventEmitter from 'node:events';
|
|
4
4
|
import { AnsiLogger, BRIGHT, CYAN, db, RESET, YELLOW } from 'node-ansi-logger';
|
|
5
|
+
import { getErrorMessage } from './error.js';
|
|
5
6
|
export class Inspector extends EventEmitter {
|
|
6
7
|
name;
|
|
7
8
|
debug;
|
|
@@ -69,13 +70,13 @@ export class Inspector extends EventEmitter {
|
|
|
69
70
|
await this.takeHeapSnapshot();
|
|
70
71
|
}
|
|
71
72
|
catch (err) {
|
|
72
|
-
this.log.error(`Error during scheduled heap snapshot: ${err
|
|
73
|
+
this.log.error(`Error during scheduled heap snapshot: ${getErrorMessage(err)}`);
|
|
73
74
|
}
|
|
74
75
|
}, interval).unref();
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
catch (err) {
|
|
78
|
-
this.log.error(`Failed to start heap sampling: ${err
|
|
79
|
+
this.log.error(`Failed to start heap sampling: ${getErrorMessage(err)}`);
|
|
79
80
|
this.session?.disconnect();
|
|
80
81
|
this.session = undefined;
|
|
81
82
|
return;
|
|
@@ -105,7 +106,7 @@ export class Inspector extends EventEmitter {
|
|
|
105
106
|
this.log.debug(`Heap sampling profile saved to ${CYAN}${filename}${db}`);
|
|
106
107
|
}
|
|
107
108
|
catch (err) {
|
|
108
|
-
this.log.error(`Failed to stop heap sampling: ${err
|
|
109
|
+
this.log.error(`Failed to stop heap sampling: ${getErrorMessage(err)}`);
|
|
109
110
|
}
|
|
110
111
|
finally {
|
|
111
112
|
this.session.disconnect();
|
|
@@ -136,7 +137,7 @@ export class Inspector extends EventEmitter {
|
|
|
136
137
|
let streamErrored = false;
|
|
137
138
|
const onStreamError = (err) => {
|
|
138
139
|
streamErrored = true;
|
|
139
|
-
this.log.error(`Heap snapshot stream error: ${err
|
|
140
|
+
this.log.error(`Heap snapshot stream error: ${getErrorMessage(err)}`);
|
|
140
141
|
};
|
|
141
142
|
stream.once('error', onStreamError);
|
|
142
143
|
const chunksListener = (notification) => {
|
|
@@ -157,7 +158,7 @@ export class Inspector extends EventEmitter {
|
|
|
157
158
|
this.emit('snapshot_done');
|
|
158
159
|
}
|
|
159
160
|
else if (err) {
|
|
160
|
-
this.log.error(`Failed to take heap snapshot: ${err
|
|
161
|
+
this.log.error(`Failed to take heap snapshot: ${getErrorMessage(err)}`);
|
|
161
162
|
this.runGarbageCollector('minor', 'async');
|
|
162
163
|
this.runGarbageCollector('major', 'async');
|
|
163
164
|
}
|
|
@@ -167,7 +168,7 @@ export class Inspector extends EventEmitter {
|
|
|
167
168
|
stream.end(() => finalize());
|
|
168
169
|
}
|
|
169
170
|
catch (e) {
|
|
170
|
-
this.log.error(`Error finalizing heap snapshot stream: ${e
|
|
171
|
+
this.log.error(`Error finalizing heap snapshot stream: ${getErrorMessage(e)}`);
|
|
171
172
|
finalize();
|
|
172
173
|
}
|
|
173
174
|
});
|
package/dist/npmVersion.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getErrorMessage } from './error.js';
|
|
1
2
|
export async function getNpmPackageVersion(packageName, tag = 'latest', timeout = 10000) {
|
|
2
3
|
const https = await import('node:https');
|
|
3
4
|
return new Promise((resolve, reject) => {
|
|
@@ -31,13 +32,13 @@ export async function getNpmPackageVersion(packageName, tag = 'latest', timeout
|
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
catch (error) {
|
|
34
|
-
reject(new Error(`Failed to parse response JSON: ${error
|
|
35
|
+
reject(new Error(`Failed to parse response JSON: ${getErrorMessage(error)}`));
|
|
35
36
|
}
|
|
36
37
|
});
|
|
37
38
|
});
|
|
38
39
|
req.on('error', (error) => {
|
|
39
40
|
clearTimeout(timeoutId);
|
|
40
|
-
reject(new Error(`Request failed: ${error
|
|
41
|
+
reject(new Error(`Request failed: ${getErrorMessage(error)}`));
|
|
41
42
|
});
|
|
42
43
|
});
|
|
43
44
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@matterbridge/utils",
|
|
3
|
-
"version": "3.6.2-dev-
|
|
3
|
+
"version": "3.6.2-dev-20260316-0b03ae0",
|
|
4
4
|
"description": "Matterbridge utils library",
|
|
5
5
|
"author": "https://github.com/Luligu",
|
|
6
6
|
"homepage": "https://matterbridge.io/",
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
}
|
|
125
125
|
},
|
|
126
126
|
"engines": {
|
|
127
|
-
"node": ">=20.
|
|
127
|
+
"node": ">=20.19.0 <21.0.0 || >=22.13.0 <23.0.0 || >=24.0.0 <25.0.0"
|
|
128
128
|
},
|
|
129
129
|
"files": [
|
|
130
130
|
"bin",
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
"CHANGELOG.md"
|
|
134
134
|
],
|
|
135
135
|
"dependencies": {
|
|
136
|
-
"@matterbridge/jest-utils": "3.6.2-dev-
|
|
136
|
+
"@matterbridge/jest-utils": "3.6.2-dev-20260316-0b03ae0",
|
|
137
137
|
"node-ansi-logger": "3.2.0"
|
|
138
138
|
}
|
|
139
139
|
}
|
package/dist/createZip.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function createZip(outputPath: string, ...sourcePaths: string[]): Promise<number>;
|
package/dist/createZip.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { AnsiLogger } from 'node-ansi-logger';
|
|
2
|
-
export async function createZip(outputPath, ...sourcePaths) {
|
|
3
|
-
const log = new AnsiLogger({ logName: 'Archive', logTimestampFormat: 4, logLevel: "info" });
|
|
4
|
-
const { default: archiver } = await import('archiver');
|
|
5
|
-
const { glob } = await import('glob');
|
|
6
|
-
const { createWriteStream, statSync } = await import('node:fs');
|
|
7
|
-
const path = await import('node:path');
|
|
8
|
-
log.debug(`creating archive ${outputPath} from ${sourcePaths.join(', ')} ...`);
|
|
9
|
-
return new Promise((resolve, reject) => {
|
|
10
|
-
const output = createWriteStream(outputPath);
|
|
11
|
-
const archive = archiver('zip', {
|
|
12
|
-
zlib: { level: 9 },
|
|
13
|
-
});
|
|
14
|
-
output.on('close', () => {
|
|
15
|
-
log.debug(`archive ${outputPath} closed with ${archive.pointer()} total bytes`);
|
|
16
|
-
resolve(archive.pointer());
|
|
17
|
-
});
|
|
18
|
-
output.on('end', () => {
|
|
19
|
-
log.debug(`archive ${outputPath} data has been drained ${archive.pointer()} total bytes`);
|
|
20
|
-
});
|
|
21
|
-
archive.on('error', (error) => {
|
|
22
|
-
log.error(`archive error: ${error.message}`);
|
|
23
|
-
reject(error);
|
|
24
|
-
});
|
|
25
|
-
archive.on('warning', (error) => {
|
|
26
|
-
if (error.code === 'ENOENT') {
|
|
27
|
-
log.warn(`archive warning: ${error.message}`);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
log.error(`archive warning: ${error.message}`);
|
|
31
|
-
reject(error);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
archive.on('entry', (entry) => {
|
|
35
|
-
log.debug(`- archive entry: ${entry.name}`);
|
|
36
|
-
});
|
|
37
|
-
archive.pipe(output);
|
|
38
|
-
for (const sourcePath of sourcePaths) {
|
|
39
|
-
let stats;
|
|
40
|
-
try {
|
|
41
|
-
stats = statSync(sourcePath);
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
if (sourcePath.includes('*')) {
|
|
45
|
-
const files = glob.sync(sourcePath.replace(/\\/g, '/'));
|
|
46
|
-
log.debug(`adding files matching glob pattern: ${sourcePath}`);
|
|
47
|
-
for (const file of files) {
|
|
48
|
-
log.debug(`- glob file: ${file}`);
|
|
49
|
-
archive.file(file, { name: file });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
log.error(`no files or directory found for pattern ${sourcePath}: ${error}`);
|
|
54
|
-
}
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
if (stats.isFile()) {
|
|
58
|
-
log.debug(`adding file: ${sourcePath}`);
|
|
59
|
-
archive.file(sourcePath, { name: path.basename(sourcePath) });
|
|
60
|
-
}
|
|
61
|
-
else if (stats.isDirectory()) {
|
|
62
|
-
log.debug(`adding directory: ${sourcePath}`);
|
|
63
|
-
archive.directory(sourcePath, path.basename(sourcePath));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
log.debug(`finalizing archive ${outputPath}...`);
|
|
67
|
-
archive.finalize().catch(reject);
|
|
68
|
-
});
|
|
69
|
-
}
|