pinme 2.0.2-beta.13 → 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 +158 -58
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4724,6 +4724,66 @@ var init_axios2 = __esm({
4724
4724
  }
4725
4725
  });
4726
4726
 
4727
+ // bin/utils/config.ts
4728
+ function trimTrailingSlash(value) {
4729
+ return value.replace(/\/+$/, "");
4730
+ }
4731
+ function readNumberEnv(name, fallback) {
4732
+ const rawValue = process.env[name];
4733
+ if (!rawValue) {
4734
+ return fallback;
4735
+ }
4736
+ const parsed = Number.parseInt(rawValue, 10);
4737
+ return Number.isFinite(parsed) ? parsed : fallback;
4738
+ }
4739
+ function getPinmeApiUrl(pathname) {
4740
+ const normalizedPath = pathname.startsWith("/") ? pathname : `/${pathname}`;
4741
+ return `${APP_CONFIG.pinmeApiBase}${normalizedPath}`;
4742
+ }
4743
+ function includesAny(value, markers) {
4744
+ return markers.some((marker) => value.includes(marker));
4745
+ }
4746
+ function getWalletRechargeUrl() {
4747
+ const candidates = [APP_CONFIG.ipfsApiUrl].filter(Boolean);
4748
+ if (candidates.some(
4749
+ (candidate) => includesAny(candidate, ["test-pinme", "localhost:5173", "benny1996.win"])
4750
+ )) {
4751
+ return TEST_WALLET_RECHARGE_URL;
4752
+ }
4753
+ return PROD_WALLET_RECHARGE_URL;
4754
+ }
4755
+ var DEFAULT_PINME_WEB_URL, PROD_WALLET_RECHARGE_URL, TEST_WALLET_RECHARGE_URL, _a, APP_CONFIG;
4756
+ var init_config = __esm({
4757
+ "bin/utils/config.ts"() {
4758
+ DEFAULT_PINME_WEB_URL = "http://localhost:5173";
4759
+ PROD_WALLET_RECHARGE_URL = "https://pinme.eth.limo/#/profile?tab=wallet";
4760
+ TEST_WALLET_RECHARGE_URL = "https://test-pinme.pinit.eth.limo/#/profile?tab=wallet";
4761
+ APP_CONFIG = {
4762
+ pinmeApiBase: trimTrailingSlash("https://pinme.benny1996.win/api/v4"),
4763
+ ipfsApiUrl: trimTrailingSlash("https://pinme.benny1996.win/api/v3"),
4764
+ carApiBase: trimTrailingSlash(
4765
+ process.env.CAR_API_BASE || "https://pinme.benny1996.win/api/v3"
4766
+ ),
4767
+ pinmeWebUrl: trimTrailingSlash(
4768
+ process.env.PINME_WEB_URL || DEFAULT_PINME_WEB_URL
4769
+ ),
4770
+ pinmeCheckDomainPath: process.env.PINME_CHECK_DOMAIN_PATH || "/check_domain",
4771
+ ipfsPreviewUrl: "https://pinme.eth.limo/#/preview/",
4772
+ projectPeviewUrl: "https://test-pinme.pinit.eth.limo/#/console/projects/",
4773
+ secretKey: "pinme-secret-key",
4774
+ pinmeProjectName: (_a = process.env.PINME_PROJECT_NAME) == null ? void 0 : _a.trim(),
4775
+ upload: {
4776
+ maxRetries: readNumberEnv("MAX_RETRIES", 2),
4777
+ retryDelayMs: readNumberEnv("RETRY_DELAY_MS", 1e3),
4778
+ timeoutMs: readNumberEnv("TIMEOUT_MS", 6e5),
4779
+ maxPollTimeMs: readNumberEnv("MAX_POLL_TIME_MINUTES", 5) * 60 * 1e3,
4780
+ pollIntervalMs: readNumberEnv("POLL_INTERVAL_SECONDS", 2) * 1e3,
4781
+ pollTimeoutMs: readNumberEnv("POLL_TIMEOUT_SECONDS", 10) * 1e3
4782
+ }
4783
+ };
4784
+ }
4785
+ });
4786
+
4727
4787
  // bin/utils/cliError.ts
4728
4788
  function stringifyValue(value) {
4729
4789
  if (value === void 0 || value === null) {
@@ -4767,6 +4827,26 @@ function getBusinessMessage(data) {
4767
4827
  function dedupeSuggestions(suggestions) {
4768
4828
  return Array.from(new Set(suggestions.filter(Boolean)));
4769
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
+ }
4843
+ function isInsufficientBalanceError(businessCode, ...messages) {
4844
+ if (businessCode === "40001") {
4845
+ return true;
4846
+ }
4847
+ const combined = messages.filter(Boolean).join(" ").toLowerCase();
4848
+ return combined.includes("insufficient balance") || combined.includes("insufficient wallet balance");
4849
+ }
4770
4850
  function createConfigError(summary, suggestions = []) {
4771
4851
  return new CliError({
4772
4852
  summary,
@@ -4805,6 +4885,13 @@ function createApiError(stage, error, context = [], suggestions = []) {
4805
4885
  const apiDetailMessage = getApiDetailMessage(responseData);
4806
4886
  const businessCode = getBusinessCode(responseData);
4807
4887
  const businessMessage = getBusinessMessage(responseData);
4888
+ const hasInsufficientBalanceError = isInsufficientBalanceError(
4889
+ businessCode,
4890
+ apiMessage,
4891
+ apiDetailMessage,
4892
+ businessMessage,
4893
+ rawMessage
4894
+ );
4808
4895
  const summary = apiMessage || businessMessage || apiDetailMessage || rawMessage || `${stage} failed.`;
4809
4896
  const detailLines = [...context];
4810
4897
  const hasBusinessError = Boolean(businessCode);
@@ -4823,6 +4910,9 @@ function createApiError(stage, error, context = [], suggestions = []) {
4823
4910
  if (apiMessage && apiMessage !== summary && apiMessage !== apiDetailMessage) {
4824
4911
  detailLines.push(`Error message: ${apiMessage}`);
4825
4912
  }
4913
+ if (hasInsufficientBalanceError) {
4914
+ detailLines.push(`Recharge URL: ${getWalletRechargeUrl()}`);
4915
+ }
4826
4916
  if (errorCode && errorCode !== "ERR_BAD_REQUEST" && !responseData) {
4827
4917
  detailLines.push(`Error code: ${errorCode}`);
4828
4918
  }
@@ -4870,6 +4960,11 @@ Error: ${cliError.message}`));
4870
4960
  console.error(import_chalk2.default.gray(`Stage: ${cliError.stage}`));
4871
4961
  }
4872
4962
  for (const detail of cliError.details) {
4963
+ const rechargeUrl = getRechargeUrl(detail);
4964
+ if (rechargeUrl) {
4965
+ printRechargeUrl(rechargeUrl, true);
4966
+ continue;
4967
+ }
4873
4968
  console.error(import_chalk2.default.gray(detail));
4874
4969
  }
4875
4970
  if (cliError.suggestions.length > 0) {
@@ -4883,6 +4978,7 @@ var import_chalk2, CliError;
4883
4978
  var init_cliError = __esm({
4884
4979
  "bin/utils/cliError.ts"() {
4885
4980
  import_chalk2 = __toESM(require("chalk"));
4981
+ init_config();
4886
4982
  CliError = class extends Error {
4887
4983
  stage;
4888
4984
  details;
@@ -4900,52 +4996,6 @@ var init_cliError = __esm({
4900
4996
  }
4901
4997
  });
4902
4998
 
4903
- // bin/utils/config.ts
4904
- function trimTrailingSlash(value) {
4905
- return value.replace(/\/+$/, "");
4906
- }
4907
- function readNumberEnv(name, fallback) {
4908
- const rawValue = process.env[name];
4909
- if (!rawValue) {
4910
- return fallback;
4911
- }
4912
- const parsed = Number.parseInt(rawValue, 10);
4913
- return Number.isFinite(parsed) ? parsed : fallback;
4914
- }
4915
- function getPinmeApiUrl(pathname) {
4916
- const normalizedPath = pathname.startsWith("/") ? pathname : `/${pathname}`;
4917
- return `${APP_CONFIG.pinmeApiBase}${normalizedPath}`;
4918
- }
4919
- var DEFAULT_PINME_WEB_URL, _a, APP_CONFIG;
4920
- var init_config = __esm({
4921
- "bin/utils/config.ts"() {
4922
- DEFAULT_PINME_WEB_URL = "http://localhost:5173";
4923
- APP_CONFIG = {
4924
- pinmeApiBase: trimTrailingSlash("https://pinme.benny1996.win/api/v4"),
4925
- ipfsApiUrl: trimTrailingSlash("https://pinme.benny1996.win/api/v3"),
4926
- carApiBase: trimTrailingSlash(
4927
- process.env.CAR_API_BASE || "https://pinme.benny1996.win/api/v3"
4928
- ),
4929
- pinmeWebUrl: trimTrailingSlash(
4930
- process.env.PINME_WEB_URL || DEFAULT_PINME_WEB_URL
4931
- ),
4932
- pinmeCheckDomainPath: process.env.PINME_CHECK_DOMAIN_PATH || "/check_domain",
4933
- ipfsPreviewUrl: "https://pinme.eth.limo/#/preview/",
4934
- projectPeviewUrl: "https://test-pinme.pinit.eth.limo/#/console/projects/",
4935
- secretKey: "pinme-secret-key",
4936
- pinmeProjectName: (_a = process.env.PINME_PROJECT_NAME) == null ? void 0 : _a.trim(),
4937
- upload: {
4938
- maxRetries: readNumberEnv("MAX_RETRIES", 2),
4939
- retryDelayMs: readNumberEnv("RETRY_DELAY_MS", 1e3),
4940
- timeoutMs: readNumberEnv("TIMEOUT_MS", 6e5),
4941
- maxPollTimeMs: readNumberEnv("MAX_POLL_TIME_MINUTES", 5) * 60 * 1e3,
4942
- pollIntervalMs: readNumberEnv("POLL_INTERVAL_SECONDS", 2) * 1e3,
4943
- pollTimeoutMs: readNumberEnv("POLL_TIMEOUT_SECONDS", 10) * 1e3
4944
- }
4945
- };
4946
- }
4947
- });
4948
-
4949
4999
  // bin/utils/webLogin.ts
4950
5000
  function openBrowser(url2) {
4951
5001
  const platform = process.platform;
@@ -5869,7 +5919,7 @@ var import_chalk26 = __toESM(require("chalk"));
5869
5919
  var import_figlet5 = __toESM(require("figlet"));
5870
5920
 
5871
5921
  // package.json
5872
- var version = "2.0.2-beta.13";
5922
+ var version = "2.0.2-beta.15";
5873
5923
 
5874
5924
  // bin/upload.ts
5875
5925
  var import_path6 = __toESM(require("path"));
@@ -6013,6 +6063,9 @@ function formatSize(bytes) {
6013
6063
  else return (bytes / (1024 * 1024 * 1024)).toFixed(2) + " GB";
6014
6064
  }
6015
6065
 
6066
+ // bin/utils/uploadToIpfsSplit.ts
6067
+ init_cliError();
6068
+
6016
6069
  // bin/utils/history.ts
6017
6070
  var import_fs_extra3 = __toESM(require("fs-extra"));
6018
6071
  var import_path4 = __toESM(require("path"));
@@ -6179,13 +6232,27 @@ function extractAxiosErrorMessage(error) {
6179
6232
  return (error == null ? void 0 : error.message) || "Unknown network error";
6180
6233
  }
6181
6234
  function formatAxiosError(prefix, error) {
6182
- var _a2;
6183
- const status = (_a2 = error == null ? void 0 : error.response) == null ? void 0 : _a2.status;
6184
- const message = extractAxiosErrorMessage(error);
6185
- if (status) {
6186
- return new Error(`${prefix}: ${message} (status: ${status})`);
6187
- }
6188
- 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
+ );
6189
6256
  }
6190
6257
  function logAxiosErrorDetails(prefix, error) {
6191
6258
  var _a2, _b;
@@ -6379,7 +6446,13 @@ async function initChunkSession(filePath, deviceId, options = {}, isDirectory =
6379
6446
  if (code === 200 && data) {
6380
6447
  return data;
6381
6448
  }
6382
- 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
+ );
6383
6456
  } catch (error) {
6384
6457
  if (axios_default.isAxiosError(error)) {
6385
6458
  logAxiosErrorDetails("chunk/init failed", error);
@@ -6417,7 +6490,13 @@ async function uploadChunkWithAbort(sessionId, chunkIndex, chunkData, deviceId,
6417
6490
  if (code === 200 && data) {
6418
6491
  return data;
6419
6492
  }
6420
- 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
+ );
6421
6500
  } catch (error) {
6422
6501
  if (error.name === "CanceledError" || signal.aborted) {
6423
6502
  throw new Error("Request cancelled");
@@ -6548,7 +6627,13 @@ async function completeChunkUpload(sessionId, deviceId, options = {}) {
6548
6627
  if (code === 200 && data) {
6549
6628
  return data.trace_id;
6550
6629
  }
6551
- 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
+ );
6552
6637
  } catch (error) {
6553
6638
  if (axios_default.isAxiosError(error)) {
6554
6639
  logAxiosErrorDetails("chunk/complete failed", error);
@@ -6583,7 +6668,13 @@ async function getChunkStatus(sessionId, deviceId, options = {}) {
6583
6668
  if (code === 200) {
6584
6669
  return data;
6585
6670
  }
6586
- 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
+ );
6587
6678
  } catch (error) {
6588
6679
  if (axios_default.isAxiosError(error)) {
6589
6680
  logAxiosErrorDetails("up_status failed", error);
@@ -7046,6 +7137,7 @@ var upload_default = async (options) => {
7046
7137
  "Insufficient wallet balance. Please recharge your wallet first."
7047
7138
  )
7048
7139
  );
7140
+ printRechargeUrl(getWalletRechargeUrl());
7049
7141
  return;
7050
7142
  }
7051
7143
  } catch (e) {
@@ -7142,6 +7234,7 @@ var upload_default = async (options) => {
7142
7234
  "Insufficient wallet balance. Please recharge your wallet first."
7143
7235
  )
7144
7236
  );
7237
+ printRechargeUrl(getWalletRechargeUrl());
7145
7238
  return;
7146
7239
  }
7147
7240
  } catch (e) {
@@ -7963,6 +8056,7 @@ async function myDomainsCmd() {
7963
8056
  // bin/wallet-balance.ts
7964
8057
  var import_chalk16 = __toESM(require("chalk"));
7965
8058
  init_cliError();
8059
+ init_config();
7966
8060
  init_pinmeApi();
7967
8061
  init_webLogin();
7968
8062
  async function walletBalanceCmd() {
@@ -7981,6 +8075,10 @@ async function walletBalanceCmd() {
7981
8075
  }
7982
8076
  console.log(import_chalk16.default.cyan("Wallet balance:"));
7983
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
+ }
7984
8082
  } catch (e) {
7985
8083
  printCliError(e, "Failed to fetch wallet balance.");
7986
8084
  }
@@ -7992,6 +8090,7 @@ var import_chalk17 = __toESM(require("chalk"));
7992
8090
  var import_inquirer7 = __toESM(require("inquirer"));
7993
8091
  init_pinmeApi();
7994
8092
  init_cliError();
8093
+ init_config();
7995
8094
  init_webLogin();
7996
8095
  function parseArgs() {
7997
8096
  const args = process.argv.slice(2);
@@ -8068,6 +8167,7 @@ async function bindCmd() {
8068
8167
  const hasWalletBalance = await checkWalletBalanceStatus2(authConfig);
8069
8168
  if (!hasWalletBalance) {
8070
8169
  console.log(import_chalk17.default.red("Insufficient wallet balance. Please recharge your wallet first."));
8170
+ printRechargeUrl(getWalletRechargeUrl());
8071
8171
  return;
8072
8172
  }
8073
8173
  } catch (e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinme",
3
- "version": "2.0.2-beta.13",
3
+ "version": "2.0.2-beta.15",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },