@airmoney-degn/airmoney-cli 0.20.0 → 0.22.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 +52 -41
- 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
|
*/
|
|
@@ -102,51 +121,37 @@ async function preparePackage(meta, projectPath) {
|
|
|
102
121
|
/**
|
|
103
122
|
* Creates the JSON-RPC request body for upload
|
|
104
123
|
*/
|
|
105
|
-
|
|
106
|
-
const metaJson = JSON.stringify(meta);
|
|
107
|
-
return JSON.stringify({
|
|
108
|
-
jsonrpc: '2.0',
|
|
109
|
-
id: 1,
|
|
110
|
-
method: 'uploadPackage',
|
|
111
|
-
params: [userId, apiKey, metaJson, encodedFile],
|
|
112
|
-
});
|
|
113
|
-
}
|
|
124
|
+
// no longer needed: JSON-RPC upload replaced by streaming HTTP upload
|
|
114
125
|
/**
|
|
115
126
|
* Handles the upload response
|
|
116
127
|
*/
|
|
117
|
-
|
|
118
|
-
if (json.result === true) {
|
|
119
|
-
(0, LogService_1.log)('Package uploaded successfully').green();
|
|
120
|
-
(0, LogService_1.log)('Open : https://dash-devnet.degn.com/').white();
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
(0, LogService_1.log)('Error uploding package').red();
|
|
124
|
-
if (json.error?.code === -32602) {
|
|
125
|
-
(0, LogService_1.log)('invalid api key, please visit https://dash-devnet.degn.com/ and setup env with the new key').red();
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
(0, LogService_1.log)('unknow error, please contact support').red();
|
|
129
|
-
(0, LogService_1.log)(JSON.stringify(json.error)).red();
|
|
130
|
-
}
|
|
128
|
+
// handled inline with plain-text response from /upload
|
|
131
129
|
/**
|
|
132
130
|
* Uploads the package to the server
|
|
133
131
|
*/
|
|
134
|
-
async function uploadPackageToServer(network,
|
|
135
|
-
const
|
|
136
|
-
const
|
|
132
|
+
async function uploadPackageToServer(network, userId, apiKey, meta, fileBuffer) {
|
|
133
|
+
const origin = (0, network_1.networkToRpcUrl)(network).replace(/\/+$/, '');
|
|
134
|
+
const metaParam = encodeURIComponent(JSON.stringify(meta));
|
|
135
|
+
const url = `${origin}/upload?user=${userId}&apiKey=${apiKey}&meta=${metaParam}`;
|
|
136
|
+
const res = await (0, node_fetch_1.default)(url, {
|
|
137
137
|
method: 'POST',
|
|
138
|
-
|
|
138
|
+
// raw bytes, no base64 overhead
|
|
139
|
+
body: fileBuffer,
|
|
139
140
|
headers: {
|
|
140
|
-
'Content-Type': 'application/
|
|
141
|
+
'Content-Type': 'application/octet-stream',
|
|
141
142
|
},
|
|
142
143
|
});
|
|
144
|
+
const text = await res.text();
|
|
143
145
|
if (!res.ok) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
throw new Error(`Upload failed: ${errorText}`);
|
|
146
|
+
(0, LogService_1.log)(`Error uploading package: ${text}`).red();
|
|
147
|
+
throw new Error(`Upload failed: ${text}`);
|
|
147
148
|
}
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
if (text.trim() === 'ok') {
|
|
150
|
+
(0, LogService_1.log)('Package uploaded successfully').green();
|
|
151
|
+
(0, LogService_1.log)('Open : https://dash-devnet.degn.com/').white();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
(0, LogService_1.log)(`Unexpected response: ${text}`);
|
|
150
155
|
}
|
|
151
156
|
/**
|
|
152
157
|
* Cleans up the package file
|
|
@@ -163,19 +168,25 @@ function cleanupPackageFile(pkgPath) {
|
|
|
163
168
|
async function uploadCommand({ network, locationFolder, }) {
|
|
164
169
|
let packageData = null;
|
|
165
170
|
try {
|
|
166
|
-
(0, network_1.validateNetwork)(network);
|
|
167
|
-
const effectiveNetwork = (network || 'devnet');
|
|
168
|
-
(0, LogService_1.log)(`Using network: ${effectiveNetwork}`).white();
|
|
169
171
|
const credentials = (0, env_1.validateCredential)();
|
|
170
|
-
const { userId, apiKey } = credentials;
|
|
171
|
-
(0,
|
|
172
|
+
const { userId, apiKey, network } = credentials;
|
|
173
|
+
(0, format_1.logUserAndNetwork)(userId, network);
|
|
172
174
|
const projectPath = getProjectPath(locationFolder);
|
|
175
|
+
// Prompt for confirmation if uploading from current directory
|
|
176
|
+
if (!locationFolder) {
|
|
177
|
+
const confirmed = await confirmUploadFromCurrentDirectory(projectPath);
|
|
178
|
+
if (!confirmed) {
|
|
179
|
+
(0, LogService_1.log)('Upload cancelled by user').yellow();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
(0, LogService_1.log)(`Upload folder: ${path_1.default.resolve(projectPath)}`).white();
|
|
185
|
+
}
|
|
173
186
|
const meta = await loadAndValidateMetadata(locationFolder);
|
|
174
187
|
packageData = await preparePackage(meta, projectPath);
|
|
175
188
|
(0, LogService_1.log)('Publishing package to DEGN Dapp Store...').white();
|
|
176
|
-
|
|
177
|
-
const body = createUploadRequestBody(userId, apiKey, meta, encoded);
|
|
178
|
-
await uploadPackageToServer(effectiveNetwork, body);
|
|
189
|
+
await uploadPackageToServer(network || "devnet", userId, apiKey, meta, packageData.fileBuffer);
|
|
179
190
|
}
|
|
180
191
|
catch (err) {
|
|
181
192
|
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.22.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"
|