@dignetwork/dig-sdk 0.0.1-alpha.54 → 0.0.1-alpha.56

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.
@@ -13,10 +13,10 @@ const ssl_1 = require("../utils/ssl");
13
13
  const credentialsUtils_1 = require("../utils/credentialsUtils");
14
14
  const https_1 = __importDefault(require("https"));
15
15
  const cli_progress_1 = __importDefault(require("cli-progress"));
16
- const chalk_1 = __importDefault(require("chalk")); // For colored output
17
- const ora_1 = __importDefault(require("ora")); // For spinners
16
+ const colorette_1 = require("colorette"); // For colored output
18
17
  const config_1 = require("../utils/config");
19
18
  const hashUtils_1 = require("../utils/hashUtils");
19
+ const nanospinner_1 = require("nanospinner");
20
20
  class PropagationServer {
21
21
  constructor(storeId, ipAddress) {
22
22
  this.storeId = storeId;
@@ -52,7 +52,7 @@ class PropagationServer {
52
52
  * @returns {Promise<{ storeExists: boolean, rootHashExists: boolean }>} - An object indicating if the store and root hash exist.
53
53
  */
54
54
  async checkStoreExists(rootHash) {
55
- const spinner = (0, ora_1.default)(`Checking if store ${this.storeId} exists...`).start();
55
+ const spinner = (0, nanospinner_1.createSpinner)(`Checking if store ${this.storeId} exists...`).start();
56
56
  try {
57
57
  const config = {
58
58
  httpsAgent: this.createHttpsAgent(),
@@ -66,24 +66,24 @@ class PropagationServer {
66
66
  const storeExists = response.headers["x-store-exists"] === "true";
67
67
  const rootHashExists = response.headers["x-has-root-hash"] === "true";
68
68
  if (storeExists) {
69
- spinner.succeed(chalk_1.default.green(`Store ${this.storeId} exists!`));
69
+ spinner.success({ text: (0, colorette_1.green)(`Store ${this.storeId} exists!`) });
70
70
  }
71
71
  else {
72
- spinner.fail(chalk_1.default.red(`Store ${this.storeId} does not exist.`));
72
+ spinner.error({ text: (0, colorette_1.red)(`Store ${this.storeId} does not exist.`) });
73
73
  }
74
74
  if (rootHash) {
75
75
  if (rootHashExists) {
76
- console.log(chalk_1.default.green(`Root hash ${rootHash} exists in the store.`));
76
+ console.log((0, colorette_1.green)(`Root hash ${rootHash} exists in the store.`));
77
77
  }
78
78
  else {
79
- console.log(chalk_1.default.red(`Root hash ${rootHash} does not exist in the store.`));
79
+ console.log((0, colorette_1.red)(`Root hash ${rootHash} does not exist in the store.`));
80
80
  }
81
81
  }
82
82
  return { storeExists, rootHashExists };
83
83
  }
84
84
  catch (error) {
85
- spinner.fail(chalk_1.default.red("Error checking if store exists:"));
86
- console.error(chalk_1.default.red(error));
85
+ spinner.error({ text: (0, colorette_1.red)("Error checking if store exists:") });
86
+ console.error((0, colorette_1.red)(error));
87
87
  throw error;
88
88
  }
89
89
  }
@@ -91,7 +91,7 @@ class PropagationServer {
91
91
  * Start an upload session by sending a POST request to the server.
92
92
  */
93
93
  async startUploadSession() {
94
- const spinner = (0, ora_1.default)(`Starting upload session for store ${this.storeId}...`).start();
94
+ const spinner = (0, nanospinner_1.createSpinner)(`Starting upload session for store ${this.storeId}...`).start();
95
95
  try {
96
96
  const config = {
97
97
  httpsAgent: this.createHttpsAgent(),
@@ -106,11 +106,13 @@ class PropagationServer {
106
106
  const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}`;
107
107
  const response = await axios_1.default.post(url, { publicKey: this.publicKey }, config);
108
108
  this.sessionId = response.data.sessionId;
109
- spinner.succeed(chalk_1.default.green(`Upload session started for DataStore ${this.storeId} with session ID ${this.sessionId}`));
109
+ spinner.success({
110
+ text: (0, colorette_1.green)(`Upload session started for DataStore ${this.storeId} with session ID ${this.sessionId}`),
111
+ });
110
112
  }
111
113
  catch (error) {
112
- spinner.fail(chalk_1.default.red("Error starting upload session:"));
113
- console.error(chalk_1.default.red(error));
114
+ spinner.error({ text: (0, colorette_1.red)("Error starting upload session:") });
115
+ console.error((0, colorette_1.red)(error));
114
116
  throw error;
115
117
  }
116
118
  }
@@ -125,11 +127,11 @@ class PropagationServer {
125
127
  const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${filename}`;
126
128
  const response = await axios_1.default.head(url, config);
127
129
  const nonce = response.headers["x-nonce"];
128
- console.log(chalk_1.default.blue(`Nonce received for file ${filename}: ${nonce}`));
130
+ console.log((0, colorette_1.blue)(`Nonce received for file ${filename}: ${nonce}`));
129
131
  return nonce;
130
132
  }
131
133
  catch (error) {
132
- console.error(chalk_1.default.red(`Error generating nonce for file ${filename}:`), error);
134
+ console.error((0, colorette_1.red)(`Error generating nonce for file ${filename}:`), error);
133
135
  throw error;
134
136
  }
135
137
  }
@@ -146,7 +148,7 @@ class PropagationServer {
146
148
  const fileSize = fs_1.default.statSync(filePath).size;
147
149
  // Create a new progress bar for each file
148
150
  const progressBar = PropagationServer.multiBar.create(fileSize, 0, {
149
- filename: chalk_1.default.yellow(filename),
151
+ filename: (0, colorette_1.yellow)(filename),
150
152
  percentage: 0,
151
153
  });
152
154
  let uploadedBytes = 0;
@@ -169,14 +171,14 @@ class PropagationServer {
169
171
  try {
170
172
  const url = `https://${this.ipAddress}:${PropagationServer.port}/upload/${this.storeId}/${this.sessionId}/${filename}`;
171
173
  const response = await axios_1.default.put(url, formData, config);
172
- console.log(chalk_1.default.green(`✔ File ${filename} uploaded successfully.`));
174
+ console.log((0, colorette_1.green)(`✔ File ${filename} uploaded successfully.`));
173
175
  // Complete the progress bar
174
176
  progressBar.update(fileSize, { percentage: 100 });
175
177
  progressBar.stop();
176
178
  return response.data;
177
179
  }
178
180
  catch (error) {
179
- console.error(chalk_1.default.red(`✖ Error uploading file ${filename}:`), error);
181
+ console.error((0, colorette_1.red)(`✖ Error uploading file ${filename}:`), error);
180
182
  progressBar.stop(); // Stop the progress bar in case of error
181
183
  throw error;
182
184
  }
@@ -196,7 +198,7 @@ class PropagationServer {
196
198
  const storeExists = await propagationServer.checkStoreExists();
197
199
  // If the store does not exist, prompt for credentials
198
200
  if (!storeExists) {
199
- console.log(chalk_1.default.red(`Store ${storeId} does not exist. Prompting for credentials...`));
201
+ console.log((0, colorette_1.red)(`Store ${storeId} does not exist. Prompting for credentials...`));
200
202
  const credentials = await (0, credentialsUtils_1.promptCredentials)(propagationServer.ipAddress);
201
203
  propagationServer.username = credentials.username;
202
204
  propagationServer.password = credentials.password;
@@ -211,7 +213,7 @@ class PropagationServer {
211
213
  }
212
214
  // Stop all progress bars after the files are uploaded
213
215
  PropagationServer.multiBar.stop();
214
- console.log(chalk_1.default.green(`✔ All files have been uploaded to DataStore ${storeId}.`));
216
+ console.log((0, colorette_1.green)(`✔ All files have been uploaded to DataStore ${storeId}.`));
215
217
  }
216
218
  /**
217
219
  * Fetch a file from the server by sending a GET request and return its content in memory.
@@ -228,10 +230,10 @@ class PropagationServer {
228
230
  try {
229
231
  const response = await axios_1.default.get(url, config);
230
232
  const totalLength = parseInt(response.headers["content-length"], 10);
231
- console.log(chalk_1.default.cyan(`Starting fetch for ${dataPath}...`));
233
+ console.log((0, colorette_1.cyan)(`Starting fetch for ${dataPath}...`));
232
234
  // Create a progress bar for the download
233
235
  const progressBar = PropagationServer.multiBar.create(totalLength, 0, {
234
- dataPath: chalk_1.default.yellow(dataPath),
236
+ dataPath: (0, colorette_1.yellow)(dataPath),
235
237
  percentage: 0,
236
238
  });
237
239
  let downloadedBytes = 0;
@@ -245,12 +247,12 @@ class PropagationServer {
245
247
  // Complete the progress bar once done
246
248
  progressBar.update(totalLength, { percentage: 100 });
247
249
  progressBar.stop();
248
- console.log(chalk_1.default.green(`✔ File ${dataPath} fetched successfully.`));
250
+ console.log((0, colorette_1.green)(`✔ File ${dataPath} fetched successfully.`));
249
251
  // Return the file contents as a Buffer
250
252
  return Buffer.from(response.data);
251
253
  }
252
254
  catch (error) {
253
- console.error(chalk_1.default.red(`✖ Error fetching file ${dataPath}:`), error);
255
+ console.error((0, colorette_1.red)(`✖ Error fetching file ${dataPath}:`), error);
254
256
  throw error;
255
257
  }
256
258
  }
@@ -272,10 +274,10 @@ class PropagationServer {
272
274
  try {
273
275
  const response = await axios_1.default.get(url, config);
274
276
  const totalLength = parseInt(response.headers["content-length"], 10);
275
- console.log(chalk_1.default.cyan(`Starting download for ${dataPath}...`));
277
+ console.log((0, colorette_1.cyan)(`Starting download for ${dataPath}...`));
276
278
  // Create a progress bar for the download
277
279
  const progressBar = PropagationServer.multiBar.create(totalLength, 0, {
278
- dataPath: chalk_1.default.yellow(dataPath),
280
+ dataPath: (0, colorette_1.yellow)(dataPath),
279
281
  percentage: 0,
280
282
  });
281
283
  let downloadedBytes = 0;
@@ -292,18 +294,18 @@ class PropagationServer {
292
294
  fileWriteStream.on("finish", () => {
293
295
  progressBar.update(totalLength, { percentage: 100 });
294
296
  progressBar.stop();
295
- console.log(chalk_1.default.green(`✔ File ${dataPath} downloaded successfully to ${downloadPath}.`));
297
+ console.log((0, colorette_1.green)(`✔ File ${dataPath} downloaded successfully to ${downloadPath}.`));
296
298
  resolve();
297
299
  });
298
300
  fileWriteStream.on("error", (error) => {
299
301
  progressBar.stop();
300
- console.error(chalk_1.default.red(`✖ Error downloading file ${dataPath}:`), error);
302
+ console.error((0, colorette_1.red)(`✖ Error downloading file ${dataPath}:`), error);
301
303
  reject(error);
302
304
  });
303
305
  });
304
306
  }
305
307
  catch (error) {
306
- console.error(chalk_1.default.red(`✖ Error downloading file ${dataPath}:`), error);
308
+ console.error((0, colorette_1.red)(`✖ Error downloading file ${dataPath}:`), error);
307
309
  throw error;
308
310
  }
309
311
  }
@@ -329,7 +331,7 @@ class PropagationServer {
329
331
  const dataPath = (0, hashUtils_1.getFilePathFromSha256)(root.files[fileKey].sha256, "data");
330
332
  await propagationServer.downloadFile(dataPath);
331
333
  }
332
- console.log(chalk_1.default.green(`✔ All files have been downloaded to ${storeId}.`));
334
+ console.log((0, colorette_1.green)(`✔ All files have been downloaded to ${storeId}.`));
333
335
  }
334
336
  }
335
337
  exports.PropagationServer = PropagationServer;
@@ -338,8 +340,8 @@ PropagationServer.port = 4159; // Static port used for all requests
338
340
  PropagationServer.multiBar = new cli_progress_1.default.MultiBar({
339
341
  clearOnComplete: false,
340
342
  hideCursor: true,
341
- format: chalk_1.default.green(" {bar} ") +
342
- chalk_1.default.cyan(" | {filename} | {percentage}% | {value}/{total} bytes"),
343
+ format: (0, colorette_1.green)(" {bar} ") +
344
+ (0, colorette_1.cyan)(" | {filename} | {percentage}% | {value}/{total} bytes"),
343
345
  barsize: 40,
344
346
  stopOnComplete: true,
345
347
  align: "center",
@@ -12,7 +12,7 @@ const FullNodePeer_1 = require("./FullNodePeer");
12
12
  const Wallet_1 = require("./Wallet");
13
13
  const config_1 = require("../utils/config");
14
14
  const coins_1 = require("./coins");
15
- const chalk_1 = __importDefault(require("chalk"));
15
+ const colorette_1 = require("colorette");
16
16
  const hashUtils_1 = require("../utils/hashUtils");
17
17
  const DataIntegrityTree_1 = require("../DataIntegrityTree");
18
18
  const prompts_1 = require("../prompts");
@@ -350,12 +350,12 @@ class DataStore {
350
350
  // Perform the integrity check before adding to the file set
351
351
  const integrityCheck = await DataIntegrityTree_1.DataIntegrityTree.validateKeyIntegrityWithForeignTree(fileKey, datFileContent.files[fileKey].sha256, datFileContent, rootHash, path_1.default.join(config_1.STORE_PATH, this.storeId, "data"));
352
352
  if (integrityCheck) {
353
- console.log(chalk_1.default.green(`File ${fileKey} has passed the integrity check.`));
353
+ console.log((0, colorette_1.green)(`File ${fileKey} has passed the integrity check.`));
354
354
  // Add the file to the file set only if the integrity check passes
355
355
  filesInvolved.push(filePath);
356
356
  }
357
357
  else {
358
- console.error(chalk_1.default.red(`File ${fileKey} failed the integrity check.`));
358
+ console.error((0, colorette_1.red)(`File ${fileKey} failed the integrity check.`));
359
359
  throw new Error(`Integrity check failed for file: ${fileKey}. Aborting.`);
360
360
  }
361
361
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dignetwork/dig-sdk",
3
- "version": "0.0.1-alpha.54",
3
+ "version": "0.0.1-alpha.56",
4
4
  "description": "",
5
5
  "type": "commonjs",
6
6
  "main": "./dist/index.js",
@@ -29,13 +29,13 @@
29
29
  "archiver": "^7.0.1",
30
30
  "axios": "^1.7.7",
31
31
  "bip39": "^3.1.0",
32
- "chalk": "^5.3.0",
33
32
  "chia-bls": "^1.0.2",
34
33
  "chia-config-loader": "^1.0.1",
35
34
  "chia-root-resolver": "^1.0.0",
36
35
  "chia-server-coin": "^0.0.5",
37
36
  "chia-wallet": "^1.0.18",
38
37
  "cli-progress": "^3.12.0",
38
+ "colorette": "^2.0.20",
39
39
  "crypto-js": "^4.2.0",
40
40
  "figures": "^6.1.0",
41
41
  "fs-extra": "^11.2.0",
@@ -46,7 +46,6 @@
46
46
  "nanospinner": "^1.1.0",
47
47
  "nconf": "^0.12.1",
48
48
  "node-cache": "^5.1.2",
49
- "ora": "^8.1.0",
50
49
  "p-limit": "^6.1.0",
51
50
  "superagent": "^10.0.0",
52
51
  "unzipper": "^0.12.3"