@airmoney-degn/airmoney-cli 0.19.7 → 0.21.0
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/cli/dapp.js +4 -5
- package/dist/cli/upload.js +50 -6
- package/dist/config.json +1 -1
- package/dist/service/log/LogService.js +10 -0
- package/dist/util/env.js +6 -6
- package/dist/util/format.js +16 -0
- package/package.json +1 -1
package/dist/cli/dapp.js
CHANGED
|
@@ -8,16 +8,15 @@ const DappService_1 = require("../service/dapp/DappService");
|
|
|
8
8
|
const network_1 = require("../util/network");
|
|
9
9
|
async function dappStatusCommand() {
|
|
10
10
|
try {
|
|
11
|
-
const { userId, apiKey,
|
|
12
|
-
(0,
|
|
13
|
-
|
|
14
|
-
const dappService = new DappService_1.DappService(userId, apiKey, rpc);
|
|
11
|
+
const { userId, apiKey, network } = (0, env_1.validateCredential)();
|
|
12
|
+
(0, format_1.logUserAndNetwork)(userId, network);
|
|
13
|
+
const dappService = new DappService_1.DappService(userId, apiKey, network);
|
|
15
14
|
try {
|
|
16
15
|
await dappService.validateApiKey();
|
|
17
16
|
}
|
|
18
17
|
catch (err) {
|
|
19
18
|
(0, LogService_1.log)(`${err instanceof Error ? err.message : String(err)}`).red();
|
|
20
|
-
(0, LogService_1.log)(`Please setup your key at ${(0, network_1.networkToRpcUrl)(
|
|
19
|
+
(0, LogService_1.log)(`Please setup your key at ${(0, network_1.networkToRpcUrl)(network)}`).red();
|
|
21
20
|
return;
|
|
22
21
|
}
|
|
23
22
|
// Fetch dapp list
|
package/dist/cli/upload.js
CHANGED
|
@@ -41,11 +41,13 @@ const fs = __importStar(require("fs"));
|
|
|
41
41
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
42
42
|
const md5_1 = __importDefault(require("md5"));
|
|
43
43
|
const path_1 = __importDefault(require("path"));
|
|
44
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
44
45
|
const metadata_1 = require("../util/metadata");
|
|
45
46
|
const tarball_1 = require("../util/tarball");
|
|
46
47
|
const network_1 = require("../util/network");
|
|
47
48
|
const env_1 = require("../util/env");
|
|
48
49
|
const LogService_1 = require("../service/log/LogService");
|
|
50
|
+
const format_1 = require("../util/format");
|
|
49
51
|
/**
|
|
50
52
|
* Gets the project path based on location folder
|
|
51
53
|
*/
|
|
@@ -55,6 +57,23 @@ function getProjectPath(locationFolder) {
|
|
|
55
57
|
}
|
|
56
58
|
return path_1.default.join(process.cwd(), locationFolder);
|
|
57
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Prompts user for confirmation when uploading from current directory
|
|
62
|
+
*/
|
|
63
|
+
async function confirmUploadFromCurrentDirectory(projectPath) {
|
|
64
|
+
(0, LogService_1.log)('⚠️ WARNING: You are about to upload all files from the current directory!').red();
|
|
65
|
+
(0, LogService_1.log)(`Upload folder: ${path_1.default.resolve(projectPath)}`).white();
|
|
66
|
+
(0, LogService_1.log)('To upload a specific folder, use: airmoney-cli upload -f <folder-path>').white();
|
|
67
|
+
const answer = await inquirer_1.default.prompt([
|
|
68
|
+
{
|
|
69
|
+
type: 'confirm',
|
|
70
|
+
name: 'confirmed',
|
|
71
|
+
message: 'Do you want to continue with the upload?',
|
|
72
|
+
default: false,
|
|
73
|
+
},
|
|
74
|
+
]);
|
|
75
|
+
return answer.confirmed;
|
|
76
|
+
}
|
|
58
77
|
/**
|
|
59
78
|
* Loads and validates metadata
|
|
60
79
|
*/
|
|
@@ -66,6 +85,21 @@ async function loadAndValidateMetadata(locationFolder) {
|
|
|
66
85
|
}
|
|
67
86
|
return meta;
|
|
68
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Formats file size in human-readable format
|
|
90
|
+
*/
|
|
91
|
+
function formatFileSize(bytes) {
|
|
92
|
+
if (bytes < 1024) {
|
|
93
|
+
return `${bytes} B`;
|
|
94
|
+
}
|
|
95
|
+
if (bytes < 1024 * 1024) {
|
|
96
|
+
return `${(bytes / 1024).toFixed(2)} KB`;
|
|
97
|
+
}
|
|
98
|
+
if (bytes < 1024 * 1024 * 1024) {
|
|
99
|
+
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
|
|
100
|
+
}
|
|
101
|
+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
102
|
+
}
|
|
69
103
|
/**
|
|
70
104
|
* Prepares the package by packing and reading it
|
|
71
105
|
*/
|
|
@@ -79,7 +113,9 @@ async function preparePackage(meta, projectPath) {
|
|
|
79
113
|
}
|
|
80
114
|
const fileBuffer = fs.readFileSync(pkgPath);
|
|
81
115
|
const fileHash = (0, md5_1.default)(fileBuffer);
|
|
116
|
+
const fileSize = fileBuffer.length;
|
|
82
117
|
(0, LogService_1.log)(`Package Hash: ${fileHash}`).white();
|
|
118
|
+
(0, LogService_1.log)(`Package Size: ${formatFileSize(fileSize)}`).white();
|
|
83
119
|
return { fileBuffer, fileHash, pkgPath };
|
|
84
120
|
}
|
|
85
121
|
/**
|
|
@@ -146,19 +182,27 @@ function cleanupPackageFile(pkgPath) {
|
|
|
146
182
|
async function uploadCommand({ network, locationFolder, }) {
|
|
147
183
|
let packageData = null;
|
|
148
184
|
try {
|
|
149
|
-
(0, network_1.validateNetwork)(network);
|
|
150
|
-
const effectiveNetwork = (network || 'devnet');
|
|
151
|
-
(0, LogService_1.log)(`Using network: ${effectiveNetwork}`).white();
|
|
152
185
|
const credentials = (0, env_1.validateCredential)();
|
|
153
|
-
const { userId, apiKey } = credentials;
|
|
154
|
-
(0,
|
|
186
|
+
const { userId, apiKey, network } = credentials;
|
|
187
|
+
(0, format_1.logUserAndNetwork)(userId, network);
|
|
155
188
|
const projectPath = getProjectPath(locationFolder);
|
|
189
|
+
// Prompt for confirmation if uploading from current directory
|
|
190
|
+
if (!locationFolder) {
|
|
191
|
+
const confirmed = await confirmUploadFromCurrentDirectory(projectPath);
|
|
192
|
+
if (!confirmed) {
|
|
193
|
+
(0, LogService_1.log)('Upload cancelled by user').yellow();
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
(0, LogService_1.log)(`Upload folder: ${path_1.default.resolve(projectPath)}`).white();
|
|
199
|
+
}
|
|
156
200
|
const meta = await loadAndValidateMetadata(locationFolder);
|
|
157
201
|
packageData = await preparePackage(meta, projectPath);
|
|
158
202
|
(0, LogService_1.log)('Publishing package to DEGN Dapp Store...').white();
|
|
159
203
|
const encoded = Buffer.from(packageData.fileBuffer).toString('base64');
|
|
160
204
|
const body = createUploadRequestBody(userId, apiKey, meta, encoded);
|
|
161
|
-
await uploadPackageToServer(
|
|
205
|
+
await uploadPackageToServer(network || "devnet", body);
|
|
162
206
|
}
|
|
163
207
|
catch (err) {
|
|
164
208
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
package/dist/config.json
CHANGED
|
@@ -49,6 +49,13 @@ class LogBuilder {
|
|
|
49
49
|
this.color = 'white';
|
|
50
50
|
this.execute();
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Sets the color to yellow and logs
|
|
54
|
+
*/
|
|
55
|
+
yellow() {
|
|
56
|
+
this.color = 'yellow';
|
|
57
|
+
this.execute();
|
|
58
|
+
}
|
|
52
59
|
/**
|
|
53
60
|
* Executes the log with all formatting applied
|
|
54
61
|
*/
|
|
@@ -64,6 +71,9 @@ class LogBuilder {
|
|
|
64
71
|
else if (this.color === 'green') {
|
|
65
72
|
codes.push('32');
|
|
66
73
|
}
|
|
74
|
+
else if (this.color === 'yellow') {
|
|
75
|
+
codes.push('33');
|
|
76
|
+
}
|
|
67
77
|
else if (this.color === 'white') {
|
|
68
78
|
// White is default, no color code needed
|
|
69
79
|
}
|
package/dist/util/env.js
CHANGED
|
@@ -37,7 +37,7 @@ exports.configDir = configDir;
|
|
|
37
37
|
exports.loadEnvFromConfig = loadEnvFromConfig;
|
|
38
38
|
exports.getDeveloperAddress = getDeveloperAddress;
|
|
39
39
|
exports.getApiKey = getApiKey;
|
|
40
|
-
exports.
|
|
40
|
+
exports.getNetwork = getNetwork;
|
|
41
41
|
exports.validateCredential = validateCredential;
|
|
42
42
|
const fs = __importStar(require("fs"));
|
|
43
43
|
const path = __importStar(require("path"));
|
|
@@ -74,7 +74,7 @@ function getApiKey() {
|
|
|
74
74
|
/**
|
|
75
75
|
* Gets the RPC/network from environment variables
|
|
76
76
|
*/
|
|
77
|
-
function
|
|
77
|
+
function getNetwork() {
|
|
78
78
|
return process.env.RPC;
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
@@ -84,17 +84,17 @@ function getRpc() {
|
|
|
84
84
|
function validateCredential() {
|
|
85
85
|
const userId = getDeveloperAddress();
|
|
86
86
|
const apiKey = getApiKey();
|
|
87
|
-
const
|
|
87
|
+
const network = getNetwork();
|
|
88
88
|
if (!userId || !apiKey) {
|
|
89
89
|
throw new Error(`Missing credentials. Please setup your key at ${(0, network_1.networkToRpcUrl)('devnet')} for devnet or ${(0, network_1.networkToRpcUrl)('mainnet')} for mainnet`);
|
|
90
90
|
}
|
|
91
|
-
if ((0, network_1.validateNetwork)(
|
|
91
|
+
if ((0, network_1.validateNetwork)(network)) {
|
|
92
92
|
return {
|
|
93
93
|
userId,
|
|
94
94
|
apiKey,
|
|
95
|
-
|
|
95
|
+
network,
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
throw new Error('Invalid network. Must be "devnet" or "mainnet". Your current network is: ' +
|
|
99
|
-
|
|
99
|
+
network);
|
|
100
100
|
}
|
package/dist/util/format.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.padString = padString;
|
|
|
8
8
|
exports.printTableRow = printTableRow;
|
|
9
9
|
exports.printSeparator = printSeparator;
|
|
10
10
|
exports.shortenString = shortenString;
|
|
11
|
+
exports.logUserAndNetwork = logUserAndNetwork;
|
|
11
12
|
const LogService_1 = require("../service/log/LogService");
|
|
12
13
|
/**
|
|
13
14
|
* Strips ANSI color codes from a string
|
|
@@ -72,3 +73,18 @@ function shortenString(str, maxLength = 14, prefixLength = 6, suffixLength = 6)
|
|
|
72
73
|
}
|
|
73
74
|
return str.substring(0, prefixLength) + '…' + str.substring(str.length - suffixLength);
|
|
74
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Logs user and network information
|
|
78
|
+
* @param userId - The user ID to display (will be shortened)
|
|
79
|
+
* @param network - The network to display (optional, shows default message if undefined)
|
|
80
|
+
*/
|
|
81
|
+
function logUserAndNetwork(userId, network) {
|
|
82
|
+
const displayUserId = shortenString(userId);
|
|
83
|
+
(0, LogService_1.log)(`User: ${displayUserId}`).white();
|
|
84
|
+
if (network) {
|
|
85
|
+
(0, LogService_1.log)(`Network: ${network}`).white();
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
(0, LogService_1.log)(`Network: <empty> (default: devnet)`).white();
|
|
89
|
+
}
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airmoney-degn/airmoney-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "airmoney-cli is a command-line interface tool designed to facilitate the development and management of decentralized applications (DApps) for Airmoney.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|