pinme 2.0.2-beta.14 → 2.0.2-beta.15

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.
Files changed (2) hide show
  1. package/dist/index.js +79 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4827,6 +4827,19 @@ function getBusinessMessage(data) {
4827
4827
  function dedupeSuggestions(suggestions) {
4828
4828
  return Array.from(new Set(suggestions.filter(Boolean)));
4829
4829
  }
4830
+ function getRechargeUrl(detail) {
4831
+ const prefix = "Recharge URL: ";
4832
+ if (!detail.startsWith(prefix)) {
4833
+ return null;
4834
+ }
4835
+ return detail.slice(prefix.length).trim() || null;
4836
+ }
4837
+ function printRechargeUrl(url2, useErrorStream = false) {
4838
+ const output = useErrorStream ? console.error : console.log;
4839
+ output("");
4840
+ output(import_chalk2.default.yellowBright.bold("Recharge URL:"));
4841
+ output(import_chalk2.default.blueBright.bold.underline(url2));
4842
+ }
4830
4843
  function isInsufficientBalanceError(businessCode, ...messages) {
4831
4844
  if (businessCode === "40001") {
4832
4845
  return true;
@@ -4947,6 +4960,11 @@ Error: ${cliError.message}`));
4947
4960
  console.error(import_chalk2.default.gray(`Stage: ${cliError.stage}`));
4948
4961
  }
4949
4962
  for (const detail of cliError.details) {
4963
+ const rechargeUrl = getRechargeUrl(detail);
4964
+ if (rechargeUrl) {
4965
+ printRechargeUrl(rechargeUrl, true);
4966
+ continue;
4967
+ }
4950
4968
  console.error(import_chalk2.default.gray(detail));
4951
4969
  }
4952
4970
  if (cliError.suggestions.length > 0) {
@@ -5901,7 +5919,7 @@ var import_chalk26 = __toESM(require("chalk"));
5901
5919
  var import_figlet5 = __toESM(require("figlet"));
5902
5920
 
5903
5921
  // package.json
5904
- var version = "2.0.2-beta.14";
5922
+ var version = "2.0.2-beta.15";
5905
5923
 
5906
5924
  // bin/upload.ts
5907
5925
  var import_path6 = __toESM(require("path"));
@@ -6045,6 +6063,9 @@ function formatSize(bytes) {
6045
6063
  else return (bytes / (1024 * 1024 * 1024)).toFixed(2) + " GB";
6046
6064
  }
6047
6065
 
6066
+ // bin/utils/uploadToIpfsSplit.ts
6067
+ init_cliError();
6068
+
6048
6069
  // bin/utils/history.ts
6049
6070
  var import_fs_extra3 = __toESM(require("fs-extra"));
6050
6071
  var import_path4 = __toESM(require("path"));
@@ -6211,13 +6232,27 @@ function extractAxiosErrorMessage(error) {
6211
6232
  return (error == null ? void 0 : error.message) || "Unknown network error";
6212
6233
  }
6213
6234
  function formatAxiosError(prefix, error) {
6214
- var _a2;
6215
- const status = (_a2 = error == null ? void 0 : error.response) == null ? void 0 : _a2.status;
6216
- const message = extractAxiosErrorMessage(error);
6217
- if (status) {
6218
- return new Error(`${prefix}: ${message} (status: ${status})`);
6219
- }
6220
- return new Error(`${prefix}: ${message}`);
6235
+ return createApiError(
6236
+ prefix,
6237
+ error,
6238
+ []
6239
+ );
6240
+ }
6241
+ function createUploadBusinessError(stage, endpoint, method, status, data) {
6242
+ return createApiError(
6243
+ stage,
6244
+ {
6245
+ response: {
6246
+ status,
6247
+ data
6248
+ },
6249
+ config: {
6250
+ url: endpoint,
6251
+ method
6252
+ }
6253
+ },
6254
+ [`Endpoint: ${endpoint}`]
6255
+ );
6221
6256
  }
6222
6257
  function logAxiosErrorDetails(prefix, error) {
6223
6258
  var _a2, _b;
@@ -6411,7 +6446,13 @@ async function initChunkSession(filePath, deviceId, options = {}, isDirectory =
6411
6446
  if (code === 200 && data) {
6412
6447
  return data;
6413
6448
  }
6414
- throw new Error(`Session initialization failed: ${msg} (code: ${code})`);
6449
+ throw createUploadBusinessError(
6450
+ "Session initialization failed",
6451
+ `${IPFS_API_URL}/chunk/init`,
6452
+ "POST",
6453
+ response.status,
6454
+ response.data
6455
+ );
6415
6456
  } catch (error) {
6416
6457
  if (axios_default.isAxiosError(error)) {
6417
6458
  logAxiosErrorDetails("chunk/init failed", error);
@@ -6449,7 +6490,13 @@ async function uploadChunkWithAbort(sessionId, chunkIndex, chunkData, deviceId,
6449
6490
  if (code === 200 && data) {
6450
6491
  return data;
6451
6492
  }
6452
- throw new Error(`Chunk upload failed: ${msg} (code: ${code})`);
6493
+ throw createUploadBusinessError(
6494
+ "Chunk upload failed",
6495
+ `${IPFS_API_URL}/chunk/upload`,
6496
+ "POST",
6497
+ response.status,
6498
+ response.data
6499
+ );
6453
6500
  } catch (error) {
6454
6501
  if (error.name === "CanceledError" || signal.aborted) {
6455
6502
  throw new Error("Request cancelled");
@@ -6580,7 +6627,13 @@ async function completeChunkUpload(sessionId, deviceId, options = {}) {
6580
6627
  if (code === 200 && data) {
6581
6628
  return data.trace_id;
6582
6629
  }
6583
- throw new Error(`Complete upload failed: ${msg} (code: ${code})`);
6630
+ throw createUploadBusinessError(
6631
+ "Complete upload failed",
6632
+ `${IPFS_API_URL}/chunk/complete`,
6633
+ "POST",
6634
+ response.status,
6635
+ response.data
6636
+ );
6584
6637
  } catch (error) {
6585
6638
  if (axios_default.isAxiosError(error)) {
6586
6639
  logAxiosErrorDetails("chunk/complete failed", error);
@@ -6615,7 +6668,13 @@ async function getChunkStatus(sessionId, deviceId, options = {}) {
6615
6668
  if (code === 200) {
6616
6669
  return data;
6617
6670
  }
6618
- throw new Error(`Server returned error: ${msg} (code: ${code})`);
6671
+ throw createUploadBusinessError(
6672
+ "Upload status check failed",
6673
+ `${IPFS_API_URL}/up_status`,
6674
+ "GET",
6675
+ response.status,
6676
+ response.data
6677
+ );
6619
6678
  } catch (error) {
6620
6679
  if (axios_default.isAxiosError(error)) {
6621
6680
  logAxiosErrorDetails("up_status failed", error);
@@ -7078,7 +7137,7 @@ var upload_default = async (options) => {
7078
7137
  "Insufficient wallet balance. Please recharge your wallet first."
7079
7138
  )
7080
7139
  );
7081
- console.log(import_chalk7.default.cyan(`Recharge URL: ${getWalletRechargeUrl()}`));
7140
+ printRechargeUrl(getWalletRechargeUrl());
7082
7141
  return;
7083
7142
  }
7084
7143
  } catch (e) {
@@ -7175,7 +7234,7 @@ var upload_default = async (options) => {
7175
7234
  "Insufficient wallet balance. Please recharge your wallet first."
7176
7235
  )
7177
7236
  );
7178
- console.log(import_chalk7.default.cyan(`Recharge URL: ${getWalletRechargeUrl()}`));
7237
+ printRechargeUrl(getWalletRechargeUrl());
7179
7238
  return;
7180
7239
  }
7181
7240
  } catch (e) {
@@ -7997,6 +8056,7 @@ async function myDomainsCmd() {
7997
8056
  // bin/wallet-balance.ts
7998
8057
  var import_chalk16 = __toESM(require("chalk"));
7999
8058
  init_cliError();
8059
+ init_config();
8000
8060
  init_pinmeApi();
8001
8061
  init_webLogin();
8002
8062
  async function walletBalanceCmd() {
@@ -8015,6 +8075,10 @@ async function walletBalanceCmd() {
8015
8075
  }
8016
8076
  console.log(import_chalk16.default.cyan("Wallet balance:"));
8017
8077
  console.log(import_chalk16.default.green(` USD: $${balance.toFixed(2)}`));
8078
+ if (balance <= 0) {
8079
+ console.log(import_chalk16.default.red("Insufficient wallet balance. Please recharge your wallet first."));
8080
+ printRechargeUrl(getWalletRechargeUrl());
8081
+ }
8018
8082
  } catch (e) {
8019
8083
  printCliError(e, "Failed to fetch wallet balance.");
8020
8084
  }
@@ -8103,7 +8167,7 @@ async function bindCmd() {
8103
8167
  const hasWalletBalance = await checkWalletBalanceStatus2(authConfig);
8104
8168
  if (!hasWalletBalance) {
8105
8169
  console.log(import_chalk17.default.red("Insufficient wallet balance. Please recharge your wallet first."));
8106
- console.log(import_chalk17.default.cyan(`Recharge URL: ${getWalletRechargeUrl()}`));
8170
+ printRechargeUrl(getWalletRechargeUrl());
8107
8171
  return;
8108
8172
  }
8109
8173
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinme",
3
- "version": "2.0.2-beta.14",
3
+ "version": "2.0.2-beta.15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },