puter-cli 1.5.0 → 1.5.2
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/CHANGELOG.md +14 -0
- package/README.md +1 -0
- package/package.json +1 -1
- package/src/commands/apps.js +2 -2
- package/src/commands/files.js +2 -2
- package/src/commands/sites.js +2 -1
- package/src/crypto.js +1 -168
package/CHANGELOG.md
CHANGED
|
@@ -4,8 +4,22 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
+
#### [v1.5.2](https://github.com/HeyPuter/puter-cli/compare/v1.5.1...v1.5.2)
|
|
8
|
+
|
|
9
|
+
- chore: clean unused [`e5c7fcc`](https://github.com/HeyPuter/puter-cli/commit/e5c7fcca3096b4b2c0659d84d8de63dce039a765)
|
|
10
|
+
- chore: more details [`0a25a2f`](https://github.com/HeyPuter/puter-cli/commit/0a25a2fb7efa9a67033b4e483305da44a68f2c9a)
|
|
11
|
+
- docs: badge version [`503bc66`](https://github.com/HeyPuter/puter-cli/commit/503bc6667666b14f85245887a3bf2071711dc4e1)
|
|
12
|
+
|
|
13
|
+
#### [v1.5.1](https://github.com/HeyPuter/puter-cli/compare/v1.5.0...v1.5.1)
|
|
14
|
+
|
|
15
|
+
> 5 February 2025
|
|
16
|
+
|
|
17
|
+
- imporve listing uid [`e2573f8`](https://github.com/HeyPuter/puter-cli/commit/e2573f83df6b47d8ab32ffc66ab19a9c984dd250)
|
|
18
|
+
|
|
7
19
|
#### [v1.5.0](https://github.com/HeyPuter/puter-cli/compare/v1.4.4...v1.5.0)
|
|
8
20
|
|
|
21
|
+
> 5 February 2025
|
|
22
|
+
|
|
9
23
|
- fix: improve version check [`f3ea79e`](https://github.com/HeyPuter/puter-cli/commit/f3ea79e3156632f892558489dfd34b1119948a48)
|
|
10
24
|
- update README [`79b381c`](https://github.com/HeyPuter/puter-cli/commit/79b381c57935cae5ffb9edf5ad11aca395ae8f8d)
|
|
11
25
|
|
package/README.md
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
<a href="https://opensource.org/licenses/MIT" >
|
|
10
10
|
<img alt="License" src="https://img.shields.io/badge/License-MIT-yellow.svg">
|
|
11
11
|
</a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/puter-cli"><img src="https://img.shields.io/npm/v/puter-cli?color=729B1B&label="></a>
|
|
12
13
|
</p>
|
|
13
14
|
|
|
14
15
|
|
package/package.json
CHANGED
package/src/commands/apps.js
CHANGED
|
@@ -22,7 +22,7 @@ import crypto from '../crypto.js';
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
export async function listApps({ statsPeriod = 'all', iconSize = 64 } = {}) {
|
|
25
|
-
console.log(chalk.green(`Listing of apps during period "${chalk.
|
|
25
|
+
console.log(chalk.green(`Listing of apps during period "${chalk.cyan(statsPeriod)}" (try also: today, yesterday, 7d, 30d, this_month, last_month):\n`));
|
|
26
26
|
try {
|
|
27
27
|
const response = await fetch(`${API_BASE}/drivers/call`, {
|
|
28
28
|
method: 'POST',
|
|
@@ -72,7 +72,7 @@ export async function listApps({ statsPeriod = 'all', iconSize = 64 } = {}) {
|
|
|
72
72
|
|
|
73
73
|
// Display the table
|
|
74
74
|
console.log(table.toString());
|
|
75
|
-
console.log(chalk.green(`You have in total: ${chalk.
|
|
75
|
+
console.log(chalk.green(`You have in total: ${chalk.cyan(data['result'].length)} application(s).`));
|
|
76
76
|
} else {
|
|
77
77
|
console.error(chalk.red('Unable to list your apps. Please check your credentials.'));
|
|
78
78
|
}
|
package/src/commands/files.js
CHANGED
|
@@ -56,8 +56,8 @@ export async function listFiles(args = []) {
|
|
|
56
56
|
const name = file.name.padEnd(20);
|
|
57
57
|
const size = file.is_dir ? '0' : formatSize(file.size);
|
|
58
58
|
const modified = formatDateTime(file.modified);
|
|
59
|
-
const uid = file.uid;
|
|
60
|
-
console.log(`${type}${write} ${name} ${size.padEnd(8)} ${modified} ${uid}`);
|
|
59
|
+
const uid = file.uid?.split('-');
|
|
60
|
+
console.log(`${type}${write} ${name} ${size.padEnd(8)} ${modified} ${uid[0]}-...-${uid.slice(-1)}`);
|
|
61
61
|
});
|
|
62
62
|
console.log(chalk.green(`There are ${files.length} object(s).`));
|
|
63
63
|
} else {
|
package/src/commands/sites.js
CHANGED
|
@@ -35,6 +35,7 @@ export async function listSites(args = {}) {
|
|
|
35
35
|
// Format and add data to table
|
|
36
36
|
let i = 0;
|
|
37
37
|
data.result.forEach(domain => {
|
|
38
|
+
let appDir = domain?.root_dir?.path.split('/').pop().split('-');
|
|
38
39
|
table.push([
|
|
39
40
|
i++,
|
|
40
41
|
domain.uid,
|
|
@@ -42,7 +43,7 @@ export async function listSites(args = {}) {
|
|
|
42
43
|
formatDate(domain.created_at).split(',')[0],
|
|
43
44
|
domain.protected ? chalk.red('Yes') : chalk.green('No'),
|
|
44
45
|
// domain.owner['username'],
|
|
45
|
-
|
|
46
|
+
appDir.length == 6?`${appDir[0]}-...-${appDir.slice(-1)}`:appDir.join('-')
|
|
46
47
|
]);
|
|
47
48
|
});
|
|
48
49
|
|
package/src/crypto.js
CHANGED
|
@@ -1,176 +1,9 @@
|
|
|
1
1
|
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
-
import { TextEncoder } from 'util';
|
|
3
|
-
|
|
4
|
-
class Hash {
|
|
5
|
-
constructor(algorithm) {
|
|
6
|
-
this.algorithm = algorithm;
|
|
7
|
-
this.data = [];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
update(data) {
|
|
11
|
-
if (typeof data === 'string') {
|
|
12
|
-
const encoder = new TextEncoder();
|
|
13
|
-
data = encoder.encode(data);
|
|
14
|
-
}
|
|
15
|
-
this.data.push(Buffer.from(data));
|
|
16
|
-
return this;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async digest(encoding = 'hex') {
|
|
20
|
-
const concatenatedData = Buffer.concat(this.data);
|
|
21
|
-
const hashBuffer = await crypto.subtle.digest(
|
|
22
|
-
this.algorithm.toUpperCase(),
|
|
23
|
-
concatenatedData
|
|
24
|
-
);
|
|
25
|
-
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
26
|
-
|
|
27
|
-
if (encoding === 'buffer') {
|
|
28
|
-
return Buffer.from(hashArray);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const hashHex = hashArray
|
|
32
|
-
.map(byte => byte.toString(16).padStart(2, '0'))
|
|
33
|
-
.join('');
|
|
34
|
-
|
|
35
|
-
if (encoding === 'hex') return hashHex;
|
|
36
|
-
if (encoding === 'base64') return Buffer.from(hashHex, 'hex').toString('base64');
|
|
37
|
-
|
|
38
|
-
throw new Error(`Unsupported encoding: ${encoding}`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
class Hmac {
|
|
43
|
-
constructor(algorithm, key) {
|
|
44
|
-
this.algorithm = algorithm;
|
|
45
|
-
this.key = typeof key === 'string' ? Buffer.from(key) : key;
|
|
46
|
-
this.data = [];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
update(data) {
|
|
50
|
-
if (typeof data === 'string') {
|
|
51
|
-
const encoder = new TextEncoder();
|
|
52
|
-
data = encoder.encode(data);
|
|
53
|
-
}
|
|
54
|
-
this.data.push(Buffer.from(data));
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async digest(encoding = 'hex') {
|
|
59
|
-
const concatenatedData = Buffer.concat(this.data);
|
|
60
|
-
const key = await crypto.subtle.importKey(
|
|
61
|
-
'raw',
|
|
62
|
-
this.key,
|
|
63
|
-
{ name: 'HMAC', hash: { name: this.algorithm.toUpperCase() } },
|
|
64
|
-
false,
|
|
65
|
-
['sign']
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
const signature = await crypto.subtle.sign(
|
|
69
|
-
'HMAC',
|
|
70
|
-
key,
|
|
71
|
-
concatenatedData
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const hashArray = Array.from(new Uint8Array(signature));
|
|
75
|
-
|
|
76
|
-
if (encoding === 'buffer') {
|
|
77
|
-
return Buffer.from(hashArray);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const hashHex = hashArray
|
|
81
|
-
.map(byte => byte.toString(16).padStart(2, '0'))
|
|
82
|
-
.join('');
|
|
83
|
-
|
|
84
|
-
if (encoding === 'hex') return hashHex;
|
|
85
|
-
if (encoding === 'base64') return Buffer.from(hashHex, 'hex').toString('base64');
|
|
86
|
-
|
|
87
|
-
throw new Error(`Unsupported encoding: ${encoding}`);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const randomBytes = (size) => {
|
|
92
|
-
const array = new Uint8Array(size);
|
|
93
|
-
crypto.getRandomValues(array);
|
|
94
|
-
return Buffer.from(array);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const createHash = (algorithm) => {
|
|
98
|
-
return new Hash(algorithm);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
const createHmac = (algorithm, key) => {
|
|
102
|
-
return new Hmac(algorithm, key);
|
|
103
|
-
};
|
|
104
2
|
|
|
105
3
|
const randomUUID = () => {
|
|
106
4
|
return uuidv4();
|
|
107
5
|
};
|
|
108
6
|
|
|
109
|
-
const scrypt = async (password, salt, keylen, options = {}) => {
|
|
110
|
-
const encoder = new TextEncoder();
|
|
111
|
-
const passwordBuffer = encoder.encode(password);
|
|
112
|
-
const saltBuffer = encoder.encode(salt);
|
|
113
|
-
|
|
114
|
-
const N = options.N || 16384;
|
|
115
|
-
const r = options.r || 8;
|
|
116
|
-
const p = options.p || 1;
|
|
117
|
-
|
|
118
|
-
const key = await crypto.subtle.importKey(
|
|
119
|
-
'raw',
|
|
120
|
-
passwordBuffer,
|
|
121
|
-
'PBKDF2',
|
|
122
|
-
false,
|
|
123
|
-
['deriveBits']
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
const derivedKey = await crypto.subtle.deriveBits(
|
|
127
|
-
{
|
|
128
|
-
name: 'PBKDF2',
|
|
129
|
-
salt: saltBuffer,
|
|
130
|
-
iterations: N * r * p,
|
|
131
|
-
hash: 'SHA-256'
|
|
132
|
-
},
|
|
133
|
-
key,
|
|
134
|
-
keylen * 8
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
return Buffer.from(derivedKey);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const pbkdf2 = async (password, salt, iterations, keylen, digest) => {
|
|
141
|
-
const encoder = new TextEncoder();
|
|
142
|
-
const passwordBuffer = encoder.encode(password);
|
|
143
|
-
const saltBuffer = encoder.encode(salt);
|
|
144
|
-
|
|
145
|
-
const key = await crypto.subtle.importKey(
|
|
146
|
-
'raw',
|
|
147
|
-
passwordBuffer,
|
|
148
|
-
'PBKDF2',
|
|
149
|
-
false,
|
|
150
|
-
['deriveBits']
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
const derivedKey = await crypto.subtle.deriveBits(
|
|
154
|
-
{
|
|
155
|
-
name: 'PBKDF2',
|
|
156
|
-
salt: saltBuffer,
|
|
157
|
-
iterations,
|
|
158
|
-
hash: digest.toUpperCase()
|
|
159
|
-
},
|
|
160
|
-
key,
|
|
161
|
-
keylen * 8
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
return Buffer.from(derivedKey);
|
|
165
|
-
};
|
|
166
|
-
|
|
167
7
|
export default {
|
|
168
|
-
|
|
169
|
-
createHmac,
|
|
170
|
-
randomBytes,
|
|
171
|
-
randomUUID,
|
|
172
|
-
scrypt,
|
|
173
|
-
pbkdf2,
|
|
174
|
-
Hash,
|
|
175
|
-
Hmac
|
|
8
|
+
randomUUID
|
|
176
9
|
};
|