pinme 2.0.2-beta.12 → 2.0.2-beta.14
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/index.js +499 -380
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4740,10 +4740,24 @@ function getPinmeApiUrl(pathname) {
|
|
|
4740
4740
|
const normalizedPath = pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
4741
4741
|
return `${APP_CONFIG.pinmeApiBase}${normalizedPath}`;
|
|
4742
4742
|
}
|
|
4743
|
-
|
|
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;
|
|
4744
4756
|
var init_config = __esm({
|
|
4745
4757
|
"bin/utils/config.ts"() {
|
|
4746
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";
|
|
4747
4761
|
APP_CONFIG = {
|
|
4748
4762
|
pinmeApiBase: trimTrailingSlash("https://pinme.benny1996.win/api/v4"),
|
|
4749
4763
|
ipfsApiUrl: trimTrailingSlash("https://pinme.benny1996.win/api/v3"),
|
|
@@ -4770,6 +4784,200 @@ var init_config = __esm({
|
|
|
4770
4784
|
}
|
|
4771
4785
|
});
|
|
4772
4786
|
|
|
4787
|
+
// bin/utils/cliError.ts
|
|
4788
|
+
function stringifyValue(value) {
|
|
4789
|
+
if (value === void 0 || value === null) {
|
|
4790
|
+
return "";
|
|
4791
|
+
}
|
|
4792
|
+
if (typeof value === "string") {
|
|
4793
|
+
return value;
|
|
4794
|
+
}
|
|
4795
|
+
try {
|
|
4796
|
+
return JSON.stringify(value);
|
|
4797
|
+
} catch (error) {
|
|
4798
|
+
return String(value);
|
|
4799
|
+
}
|
|
4800
|
+
}
|
|
4801
|
+
function getApiMessage(data) {
|
|
4802
|
+
var _a2, _b, _c, _d, _e;
|
|
4803
|
+
if (typeof data === "string") {
|
|
4804
|
+
return data;
|
|
4805
|
+
}
|
|
4806
|
+
return (data == null ? void 0 : data.msg) || (data == null ? void 0 : data.message) || ((_a2 = data == null ? void 0 : data.data) == null ? void 0 : _a2.msg) || ((_b = data == null ? void 0 : data.data) == null ? void 0 : _b.message) || ((_c = data == null ? void 0 : data.data) == null ? void 0 : _c.error) || ((_e = (_d = data == null ? void 0 : data.errors) == null ? void 0 : _d[0]) == null ? void 0 : _e.message) || (data == null ? void 0 : data.error);
|
|
4807
|
+
}
|
|
4808
|
+
function getApiDetailMessage(data) {
|
|
4809
|
+
var _a2, _b, _c, _d, _e;
|
|
4810
|
+
if (typeof data === "string") {
|
|
4811
|
+
return data;
|
|
4812
|
+
}
|
|
4813
|
+
return ((_a2 = data == null ? void 0 : data.data) == null ? void 0 : _a2.error) || ((_b = data == null ? void 0 : data.data) == null ? void 0 : _b.msg) || ((_c = data == null ? void 0 : data.data) == null ? void 0 : _c.message) || ((_e = (_d = data == null ? void 0 : data.errors) == null ? void 0 : _d[0]) == null ? void 0 : _e.message) || (data == null ? void 0 : data.error);
|
|
4814
|
+
}
|
|
4815
|
+
function getBusinessCode(data) {
|
|
4816
|
+
if ((data == null ? void 0 : data.code) === void 0 || (data == null ? void 0 : data.code) === null) {
|
|
4817
|
+
return void 0;
|
|
4818
|
+
}
|
|
4819
|
+
return String(data.code);
|
|
4820
|
+
}
|
|
4821
|
+
function getBusinessMessage(data) {
|
|
4822
|
+
if (!(data == null ? void 0 : data.msg)) {
|
|
4823
|
+
return void 0;
|
|
4824
|
+
}
|
|
4825
|
+
return String(data.msg);
|
|
4826
|
+
}
|
|
4827
|
+
function dedupeSuggestions(suggestions) {
|
|
4828
|
+
return Array.from(new Set(suggestions.filter(Boolean)));
|
|
4829
|
+
}
|
|
4830
|
+
function isInsufficientBalanceError(businessCode, ...messages) {
|
|
4831
|
+
if (businessCode === "40001") {
|
|
4832
|
+
return true;
|
|
4833
|
+
}
|
|
4834
|
+
const combined = messages.filter(Boolean).join(" ").toLowerCase();
|
|
4835
|
+
return combined.includes("insufficient balance") || combined.includes("insufficient wallet balance");
|
|
4836
|
+
}
|
|
4837
|
+
function createConfigError(summary, suggestions = []) {
|
|
4838
|
+
return new CliError({
|
|
4839
|
+
summary,
|
|
4840
|
+
stage: "configuration",
|
|
4841
|
+
suggestions
|
|
4842
|
+
});
|
|
4843
|
+
}
|
|
4844
|
+
function createCommandError(stage, command, error, suggestions = []) {
|
|
4845
|
+
const exitCode = (error == null ? void 0 : error.status) ?? (error == null ? void 0 : error.code);
|
|
4846
|
+
const signal = error == null ? void 0 : error.signal;
|
|
4847
|
+
const detailLines = [`Command: ${command}`];
|
|
4848
|
+
if (exitCode !== void 0) {
|
|
4849
|
+
detailLines.push(`Exit code: ${exitCode}`);
|
|
4850
|
+
}
|
|
4851
|
+
if (signal) {
|
|
4852
|
+
detailLines.push(`Signal: ${signal}`);
|
|
4853
|
+
}
|
|
4854
|
+
if (error == null ? void 0 : error.message) {
|
|
4855
|
+
detailLines.push(`Reason: ${error.message}`);
|
|
4856
|
+
}
|
|
4857
|
+
return new CliError({
|
|
4858
|
+
summary: `${stage} failed.`,
|
|
4859
|
+
stage,
|
|
4860
|
+
details: detailLines,
|
|
4861
|
+
suggestions,
|
|
4862
|
+
cause: error
|
|
4863
|
+
});
|
|
4864
|
+
}
|
|
4865
|
+
function createApiError(stage, error, context = [], suggestions = []) {
|
|
4866
|
+
var _a2, _b;
|
|
4867
|
+
const status = (_a2 = error == null ? void 0 : error.response) == null ? void 0 : _a2.status;
|
|
4868
|
+
const responseData = (_b = error == null ? void 0 : error.response) == null ? void 0 : _b.data;
|
|
4869
|
+
const errorCode = error == null ? void 0 : error.code;
|
|
4870
|
+
const rawMessage = error == null ? void 0 : error.message;
|
|
4871
|
+
const apiMessage = getApiMessage(responseData);
|
|
4872
|
+
const apiDetailMessage = getApiDetailMessage(responseData);
|
|
4873
|
+
const businessCode = getBusinessCode(responseData);
|
|
4874
|
+
const businessMessage = getBusinessMessage(responseData);
|
|
4875
|
+
const hasInsufficientBalanceError = isInsufficientBalanceError(
|
|
4876
|
+
businessCode,
|
|
4877
|
+
apiMessage,
|
|
4878
|
+
apiDetailMessage,
|
|
4879
|
+
businessMessage,
|
|
4880
|
+
rawMessage
|
|
4881
|
+
);
|
|
4882
|
+
const summary = apiMessage || businessMessage || apiDetailMessage || rawMessage || `${stage} failed.`;
|
|
4883
|
+
const detailLines = [...context];
|
|
4884
|
+
const hasBusinessError = Boolean(businessCode);
|
|
4885
|
+
if (businessCode) {
|
|
4886
|
+
detailLines.push(`Business code: ${businessCode}`);
|
|
4887
|
+
}
|
|
4888
|
+
if (status && !hasBusinessError) {
|
|
4889
|
+
detailLines.push(`HTTP status: ${status}`);
|
|
4890
|
+
}
|
|
4891
|
+
if (businessMessage && businessMessage !== summary) {
|
|
4892
|
+
detailLines.push(`Business message: ${businessMessage}`);
|
|
4893
|
+
}
|
|
4894
|
+
if (apiDetailMessage && apiDetailMessage !== summary && apiDetailMessage !== businessMessage) {
|
|
4895
|
+
detailLines.push(`Error detail: ${apiDetailMessage}`);
|
|
4896
|
+
}
|
|
4897
|
+
if (apiMessage && apiMessage !== summary && apiMessage !== apiDetailMessage) {
|
|
4898
|
+
detailLines.push(`Error message: ${apiMessage}`);
|
|
4899
|
+
}
|
|
4900
|
+
if (hasInsufficientBalanceError) {
|
|
4901
|
+
detailLines.push(`Recharge URL: ${getWalletRechargeUrl()}`);
|
|
4902
|
+
}
|
|
4903
|
+
if (errorCode && errorCode !== "ERR_BAD_REQUEST" && !responseData) {
|
|
4904
|
+
detailLines.push(`Error code: ${errorCode}`);
|
|
4905
|
+
}
|
|
4906
|
+
const isGenericAxiosStatusMessage = typeof rawMessage === "string" && /^Request failed with status code \d{3}$/.test(rawMessage);
|
|
4907
|
+
if (rawMessage && rawMessage !== summary && !(responseData && isGenericAxiosStatusMessage)) {
|
|
4908
|
+
detailLines.push(`Reason: ${rawMessage}`);
|
|
4909
|
+
}
|
|
4910
|
+
return new CliError({
|
|
4911
|
+
summary,
|
|
4912
|
+
stage,
|
|
4913
|
+
details: detailLines,
|
|
4914
|
+
suggestions: dedupeSuggestions(suggestions),
|
|
4915
|
+
cause: error
|
|
4916
|
+
});
|
|
4917
|
+
}
|
|
4918
|
+
function normalizeCliError(error, fallbackSummary, suggestions = []) {
|
|
4919
|
+
if (error instanceof CliError) {
|
|
4920
|
+
return error;
|
|
4921
|
+
}
|
|
4922
|
+
if (typeof error === "object" && error !== null) {
|
|
4923
|
+
const maybeApiError = error;
|
|
4924
|
+
if (maybeApiError.response || maybeApiError.config) {
|
|
4925
|
+
return createApiError("API request", maybeApiError, [], suggestions);
|
|
4926
|
+
}
|
|
4927
|
+
}
|
|
4928
|
+
if (error instanceof Error) {
|
|
4929
|
+
return new CliError({
|
|
4930
|
+
summary: error.message || fallbackSummary,
|
|
4931
|
+
suggestions: dedupeSuggestions(suggestions),
|
|
4932
|
+
cause: error
|
|
4933
|
+
});
|
|
4934
|
+
}
|
|
4935
|
+
return new CliError({
|
|
4936
|
+
summary: fallbackSummary,
|
|
4937
|
+
details: [`Raw error: ${stringifyValue(error)}`],
|
|
4938
|
+
suggestions: dedupeSuggestions(suggestions),
|
|
4939
|
+
cause: error
|
|
4940
|
+
});
|
|
4941
|
+
}
|
|
4942
|
+
function printCliError(error, fallbackSummary) {
|
|
4943
|
+
const cliError = normalizeCliError(error, fallbackSummary);
|
|
4944
|
+
console.error(import_chalk2.default.red(`
|
|
4945
|
+
Error: ${cliError.message}`));
|
|
4946
|
+
if (cliError.stage) {
|
|
4947
|
+
console.error(import_chalk2.default.gray(`Stage: ${cliError.stage}`));
|
|
4948
|
+
}
|
|
4949
|
+
for (const detail of cliError.details) {
|
|
4950
|
+
console.error(import_chalk2.default.gray(detail));
|
|
4951
|
+
}
|
|
4952
|
+
if (cliError.suggestions.length > 0) {
|
|
4953
|
+
console.error(import_chalk2.default.yellow("\nNext steps:"));
|
|
4954
|
+
for (const suggestion of cliError.suggestions) {
|
|
4955
|
+
console.error(import_chalk2.default.yellow(`- ${suggestion}`));
|
|
4956
|
+
}
|
|
4957
|
+
}
|
|
4958
|
+
}
|
|
4959
|
+
var import_chalk2, CliError;
|
|
4960
|
+
var init_cliError = __esm({
|
|
4961
|
+
"bin/utils/cliError.ts"() {
|
|
4962
|
+
import_chalk2 = __toESM(require("chalk"));
|
|
4963
|
+
init_config();
|
|
4964
|
+
CliError = class extends Error {
|
|
4965
|
+
stage;
|
|
4966
|
+
details;
|
|
4967
|
+
suggestions;
|
|
4968
|
+
cause;
|
|
4969
|
+
constructor(options) {
|
|
4970
|
+
super(options.summary);
|
|
4971
|
+
this.name = "CliError";
|
|
4972
|
+
this.stage = options.stage;
|
|
4973
|
+
this.details = options.details || [];
|
|
4974
|
+
this.suggestions = options.suggestions || [];
|
|
4975
|
+
this.cause = options.cause;
|
|
4976
|
+
}
|
|
4977
|
+
};
|
|
4978
|
+
}
|
|
4979
|
+
});
|
|
4980
|
+
|
|
4773
4981
|
// bin/utils/webLogin.ts
|
|
4774
4982
|
function openBrowser(url2) {
|
|
4775
4983
|
const platform = process.platform;
|
|
@@ -4783,7 +4991,7 @@ function openBrowser(url2) {
|
|
|
4783
4991
|
}
|
|
4784
4992
|
(0, import_child_process.exec)(command, (err) => {
|
|
4785
4993
|
if (err) {
|
|
4786
|
-
console.log(
|
|
4994
|
+
console.log(import_chalk3.default.yellow(`Unable to open browser automatically. Please visit manually: ${url2}`));
|
|
4787
4995
|
}
|
|
4788
4996
|
});
|
|
4789
4997
|
}
|
|
@@ -4831,13 +5039,13 @@ function getAuthHeaders() {
|
|
|
4831
5039
|
"authentication-tokens": conf.token
|
|
4832
5040
|
};
|
|
4833
5041
|
}
|
|
4834
|
-
var import_crypto, import_http3, import_url2,
|
|
5042
|
+
var import_crypto, import_http3, import_url2, import_chalk3, import_child_process, import_fs_extra, import_os, import_path, CONFIG_DIR, AUTH_FILE, DEFAULT_OPTIONS, WebLoginManager, webLoginManager;
|
|
4835
5043
|
var init_webLogin = __esm({
|
|
4836
5044
|
"bin/utils/webLogin.ts"() {
|
|
4837
5045
|
import_crypto = __toESM(require("crypto"));
|
|
4838
5046
|
import_http3 = __toESM(require("http"));
|
|
4839
5047
|
import_url2 = require("url");
|
|
4840
|
-
|
|
5048
|
+
import_chalk3 = __toESM(require("chalk"));
|
|
4841
5049
|
import_child_process = require("child_process");
|
|
4842
5050
|
import_fs_extra = __toESM(require("fs-extra"));
|
|
4843
5051
|
import_os = __toESM(require("os"));
|
|
@@ -4861,30 +5069,30 @@ var init_webLogin = __esm({
|
|
|
4861
5069
|
this.config = { ...DEFAULT_OPTIONS, ...options };
|
|
4862
5070
|
}
|
|
4863
5071
|
async login() {
|
|
4864
|
-
console.log(
|
|
5072
|
+
console.log(import_chalk3.default.blue("Starting login flow...\n"));
|
|
4865
5073
|
this.loginToken = this.generateLoginToken();
|
|
4866
|
-
console.log(
|
|
5074
|
+
console.log(import_chalk3.default.blue("Starting local callback server..."));
|
|
4867
5075
|
await this.startCallbackServer();
|
|
4868
5076
|
try {
|
|
4869
5077
|
const loginUrl = this.buildLoginUrl();
|
|
4870
|
-
console.log(
|
|
4871
|
-
console.log(
|
|
4872
|
-
console.log(
|
|
5078
|
+
console.log(import_chalk3.default.blue("Opening browser..."));
|
|
5079
|
+
console.log(import_chalk3.default.white("If browser does not open automatically, please visit manually:"));
|
|
5080
|
+
console.log(import_chalk3.default.cyan(` ${loginUrl}
|
|
4873
5081
|
`));
|
|
4874
5082
|
openBrowser(loginUrl);
|
|
4875
|
-
console.log(
|
|
4876
|
-
console.log(
|
|
5083
|
+
console.log(import_chalk3.default.yellow("Please complete login in browser..."));
|
|
5084
|
+
console.log(import_chalk3.default.gray("Browser will close automatically after successful login.\n"));
|
|
4877
5085
|
const authToken = await this.waitForCallback();
|
|
4878
5086
|
const authConfig = this.parseAuthToken(authToken);
|
|
4879
5087
|
this.saveAuthConfig(authConfig);
|
|
4880
|
-
console.log(
|
|
5088
|
+
console.log(import_chalk3.default.green("\nLogin successful!"));
|
|
4881
5089
|
if (authConfig.email) {
|
|
4882
|
-
console.log(
|
|
5090
|
+
console.log(import_chalk3.default.green(`Welcome, ${authConfig.email}`));
|
|
4883
5091
|
}
|
|
4884
|
-
console.log(
|
|
5092
|
+
console.log(import_chalk3.default.gray(`Address: ${authConfig.address}`));
|
|
4885
5093
|
return authConfig;
|
|
4886
5094
|
} catch (error) {
|
|
4887
|
-
console.error(
|
|
5095
|
+
console.error(import_chalk3.default.red(`
|
|
4888
5096
|
Login failed: ${error.message}`));
|
|
4889
5097
|
throw error;
|
|
4890
5098
|
} finally {
|
|
@@ -4946,7 +5154,7 @@ Login failed: ${error.message}`));
|
|
|
4946
5154
|
reject(err);
|
|
4947
5155
|
});
|
|
4948
5156
|
this.server.listen(this.config.callbackPort, "127.0.0.1", () => {
|
|
4949
|
-
console.log(
|
|
5157
|
+
console.log(import_chalk3.default.gray(`Local server: http://localhost:${this.config.callbackPort}`));
|
|
4950
5158
|
resolve();
|
|
4951
5159
|
});
|
|
4952
5160
|
setTimeout(() => {
|
|
@@ -5280,6 +5488,30 @@ function safeGetAuthHeaders() {
|
|
|
5280
5488
|
return {};
|
|
5281
5489
|
}
|
|
5282
5490
|
}
|
|
5491
|
+
function hasBusinessCode(data) {
|
|
5492
|
+
return Boolean(data) && typeof data === "object" && "code" in data;
|
|
5493
|
+
}
|
|
5494
|
+
function isSuccessfulBusinessCode(code) {
|
|
5495
|
+
return String(code) === "200";
|
|
5496
|
+
}
|
|
5497
|
+
function getRequestDescriptor(config) {
|
|
5498
|
+
if (!(config == null ? void 0 : config.url)) {
|
|
5499
|
+
return void 0;
|
|
5500
|
+
}
|
|
5501
|
+
const method = (config.method || "GET").toUpperCase();
|
|
5502
|
+
return `${method} ${config.url}`;
|
|
5503
|
+
}
|
|
5504
|
+
function buildErrorContext(config) {
|
|
5505
|
+
const descriptor = getRequestDescriptor(config);
|
|
5506
|
+
return descriptor ? [`Request: ${descriptor}`] : [];
|
|
5507
|
+
}
|
|
5508
|
+
function normalizeBusinessError(response) {
|
|
5509
|
+
throw createApiError(
|
|
5510
|
+
"API request",
|
|
5511
|
+
{ response, config: response.config },
|
|
5512
|
+
buildErrorContext(response.config)
|
|
5513
|
+
);
|
|
5514
|
+
}
|
|
5283
5515
|
function createApiClient(options = {}) {
|
|
5284
5516
|
const {
|
|
5285
5517
|
baseURL = APP_CONFIG.pinmeApiBase,
|
|
@@ -5300,8 +5532,19 @@ function createApiClient(options = {}) {
|
|
|
5300
5532
|
}
|
|
5301
5533
|
});
|
|
5302
5534
|
client.interceptors.response.use(
|
|
5303
|
-
(response) =>
|
|
5304
|
-
|
|
5535
|
+
(response) => {
|
|
5536
|
+
if (hasBusinessCode(response.data) && !isSuccessfulBusinessCode(response.data.code)) {
|
|
5537
|
+
normalizeBusinessError(response);
|
|
5538
|
+
}
|
|
5539
|
+
return response;
|
|
5540
|
+
},
|
|
5541
|
+
(error) => Promise.reject(
|
|
5542
|
+
createApiError(
|
|
5543
|
+
"API request",
|
|
5544
|
+
error,
|
|
5545
|
+
buildErrorContext(error == null ? void 0 : error.config)
|
|
5546
|
+
)
|
|
5547
|
+
)
|
|
5305
5548
|
);
|
|
5306
5549
|
return client;
|
|
5307
5550
|
}
|
|
@@ -5320,6 +5563,7 @@ function createCarApiClient(options = {}) {
|
|
|
5320
5563
|
var init_apiClient = __esm({
|
|
5321
5564
|
"bin/utils/apiClient.ts"() {
|
|
5322
5565
|
init_axios2();
|
|
5566
|
+
init_cliError();
|
|
5323
5567
|
init_webLogin();
|
|
5324
5568
|
init_config();
|
|
5325
5569
|
}
|
|
@@ -5356,8 +5600,8 @@ function isTokenExpired(error) {
|
|
|
5356
5600
|
);
|
|
5357
5601
|
}
|
|
5358
5602
|
function showTokenExpiredHint() {
|
|
5359
|
-
console.log(
|
|
5360
|
-
console.log(
|
|
5603
|
+
console.log(import_chalk4.default.red("\n\u26A0\uFE0F Token has expired or is invalid."));
|
|
5604
|
+
console.log(import_chalk4.default.yellow("Please re-run: pinme set-appkey <AppKey>\n"));
|
|
5361
5605
|
}
|
|
5362
5606
|
async function bindAnonymousDevice(anonymousUid) {
|
|
5363
5607
|
try {
|
|
@@ -5372,7 +5616,7 @@ async function bindAnonymousDevice(anonymousUid) {
|
|
|
5372
5616
|
return false;
|
|
5373
5617
|
}
|
|
5374
5618
|
console.log(
|
|
5375
|
-
|
|
5619
|
+
import_chalk4.default.yellow(`Failed to trigger anonymous binding: ${(e == null ? void 0 : e.message) || e}`)
|
|
5376
5620
|
);
|
|
5377
5621
|
return false;
|
|
5378
5622
|
}
|
|
@@ -5391,10 +5635,11 @@ async function getRootDomain(forceRefresh = false) {
|
|
|
5391
5635
|
throw new Error((data == null ? void 0 : data.msg) || "Failed to get root domain");
|
|
5392
5636
|
}
|
|
5393
5637
|
async function checkDomainAvailable(domainName) {
|
|
5394
|
-
var _a2;
|
|
5638
|
+
var _a2, _b;
|
|
5395
5639
|
const client = createPinmeApiClient();
|
|
5396
5640
|
const configured = APP_CONFIG.pinmeCheckDomainPath;
|
|
5397
5641
|
const fallbacks = [configured, "/check_domain_available"];
|
|
5642
|
+
let lastRecoverableError;
|
|
5398
5643
|
for (const p of fallbacks) {
|
|
5399
5644
|
try {
|
|
5400
5645
|
const { data } = await client.post(p, { domain_name: domainName });
|
|
@@ -5409,8 +5654,16 @@ async function checkDomainAvailable(domainName) {
|
|
|
5409
5654
|
showTokenExpiredHint();
|
|
5410
5655
|
throw new Error("Token expired");
|
|
5411
5656
|
}
|
|
5657
|
+
const status = (_b = e == null ? void 0 : e.response) == null ? void 0 : _b.status;
|
|
5658
|
+
if (status && ![404, 405].includes(status)) {
|
|
5659
|
+
throw e;
|
|
5660
|
+
}
|
|
5661
|
+
lastRecoverableError = e;
|
|
5412
5662
|
}
|
|
5413
5663
|
}
|
|
5664
|
+
if (lastRecoverableError) {
|
|
5665
|
+
throw lastRecoverableError;
|
|
5666
|
+
}
|
|
5414
5667
|
return { is_valid: true };
|
|
5415
5668
|
}
|
|
5416
5669
|
async function bindPinmeDomain(domainName, hash, projectName) {
|
|
@@ -5573,10 +5826,10 @@ async function checkCarExportStatus(taskId) {
|
|
|
5573
5826
|
throw new Error(`Failed to check export status: ${(e == null ? void 0 : e.message) || e}`);
|
|
5574
5827
|
}
|
|
5575
5828
|
}
|
|
5576
|
-
var
|
|
5829
|
+
var import_chalk4, TOKEN_EXPIRED_CODES, TOKEN_EXPIRED_MESSAGES, rootDomainCache;
|
|
5577
5830
|
var init_pinmeApi = __esm({
|
|
5578
5831
|
"bin/utils/pinmeApi.ts"() {
|
|
5579
|
-
|
|
5832
|
+
import_chalk4 = __toESM(require("chalk"));
|
|
5580
5833
|
init_apiClient();
|
|
5581
5834
|
init_config();
|
|
5582
5835
|
TOKEN_EXPIRED_CODES = [
|
|
@@ -5648,11 +5901,11 @@ var import_chalk26 = __toESM(require("chalk"));
|
|
|
5648
5901
|
var import_figlet5 = __toESM(require("figlet"));
|
|
5649
5902
|
|
|
5650
5903
|
// package.json
|
|
5651
|
-
var version = "2.0.2-beta.
|
|
5904
|
+
var version = "2.0.2-beta.14";
|
|
5652
5905
|
|
|
5653
5906
|
// bin/upload.ts
|
|
5654
5907
|
var import_path6 = __toESM(require("path"));
|
|
5655
|
-
var
|
|
5908
|
+
var import_chalk7 = __toESM(require("chalk"));
|
|
5656
5909
|
var import_inquirer = __toESM(require("inquirer"));
|
|
5657
5910
|
var import_figlet = __toESM(require("figlet"));
|
|
5658
5911
|
var import_fs2 = __toESM(require("fs"));
|
|
@@ -5709,6 +5962,9 @@ function validateDnsDomain(domain) {
|
|
|
5709
5962
|
return { valid: true };
|
|
5710
5963
|
}
|
|
5711
5964
|
|
|
5965
|
+
// bin/upload.ts
|
|
5966
|
+
init_cliError();
|
|
5967
|
+
|
|
5712
5968
|
// bin/services/uploadService.ts
|
|
5713
5969
|
var import_crypto_js = __toESM(require("crypto-js"));
|
|
5714
5970
|
|
|
@@ -5794,7 +6050,7 @@ var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
|
5794
6050
|
var import_path4 = __toESM(require("path"));
|
|
5795
6051
|
var import_os3 = __toESM(require("os"));
|
|
5796
6052
|
var import_dayjs = __toESM(require("dayjs"));
|
|
5797
|
-
var
|
|
6053
|
+
var import_chalk5 = __toESM(require("chalk"));
|
|
5798
6054
|
init_pinmeApi();
|
|
5799
6055
|
var HISTORY_DIR = import_path4.default.join(import_os3.default.homedir(), ".pinme");
|
|
5800
6056
|
var HISTORY_FILE = import_path4.default.join(HISTORY_DIR, "upload-history.json");
|
|
@@ -5828,7 +6084,7 @@ var saveUploadHistory = (uploadData) => {
|
|
|
5828
6084
|
import_fs_extra3.default.writeJsonSync(HISTORY_FILE, history, { spaces: 2 });
|
|
5829
6085
|
return true;
|
|
5830
6086
|
} catch (error) {
|
|
5831
|
-
console.error(
|
|
6087
|
+
console.error(import_chalk5.default.red(`Error saving upload history: ${error.message}`));
|
|
5832
6088
|
return false;
|
|
5833
6089
|
}
|
|
5834
6090
|
};
|
|
@@ -5838,7 +6094,7 @@ var getUploadHistory = (limit = 10) => {
|
|
|
5838
6094
|
const history = import_fs_extra3.default.readJsonSync(HISTORY_FILE);
|
|
5839
6095
|
return history.uploads.slice(0, limit);
|
|
5840
6096
|
} catch (error) {
|
|
5841
|
-
console.error(
|
|
6097
|
+
console.error(import_chalk5.default.red(`Error reading upload history: ${error.message}`));
|
|
5842
6098
|
return [];
|
|
5843
6099
|
}
|
|
5844
6100
|
};
|
|
@@ -5875,11 +6131,11 @@ async function formatHistoryUrl(value, options) {
|
|
|
5875
6131
|
var displayUploadHistory = async (limit = 10) => {
|
|
5876
6132
|
const history = getUploadHistory(limit);
|
|
5877
6133
|
if (history.length === 0) {
|
|
5878
|
-
console.log(
|
|
6134
|
+
console.log(import_chalk5.default.yellow("No upload history found."));
|
|
5879
6135
|
return;
|
|
5880
6136
|
}
|
|
5881
|
-
console.log(
|
|
5882
|
-
console.log(
|
|
6137
|
+
console.log(import_chalk5.default.cyan("Upload History:"));
|
|
6138
|
+
console.log(import_chalk5.default.cyan("-".repeat(80)));
|
|
5883
6139
|
let rootDomain = null;
|
|
5884
6140
|
try {
|
|
5885
6141
|
rootDomain = await getRootDomain();
|
|
@@ -5888,9 +6144,9 @@ var displayUploadHistory = async (limit = 10) => {
|
|
|
5888
6144
|
}
|
|
5889
6145
|
const recentHistory = history.slice(-limit);
|
|
5890
6146
|
for (const [index, item] of recentHistory.entries()) {
|
|
5891
|
-
console.log(
|
|
5892
|
-
console.log(
|
|
5893
|
-
console.log(
|
|
6147
|
+
console.log(import_chalk5.default.green(`${index + 1}. ${item.filename}`));
|
|
6148
|
+
console.log(import_chalk5.default.white(` Path: ${item.path}`));
|
|
6149
|
+
console.log(import_chalk5.default.white(` IPFS CID: ${item.contentHash}`));
|
|
5894
6150
|
const preferredUrl = await formatHistoryUrl(item.dnsUrl) || await formatHistoryUrl(item.pinmeUrl, {
|
|
5895
6151
|
appendRootDomain: true,
|
|
5896
6152
|
rootDomain
|
|
@@ -5899,30 +6155,30 @@ var displayUploadHistory = async (limit = 10) => {
|
|
|
5899
6155
|
rootDomain
|
|
5900
6156
|
});
|
|
5901
6157
|
if (preferredUrl) {
|
|
5902
|
-
console.log(
|
|
6158
|
+
console.log(import_chalk5.default.white(` URL: ${preferredUrl}`));
|
|
5903
6159
|
}
|
|
5904
|
-
console.log(
|
|
5905
|
-
console.log(
|
|
5906
|
-
console.log(
|
|
6160
|
+
console.log(import_chalk5.default.white(` Size: ${formatSize(item.size)}`));
|
|
6161
|
+
console.log(import_chalk5.default.white(` Files: ${item.fileCount}`));
|
|
6162
|
+
console.log(import_chalk5.default.white(` Type: ${item.type === "directory" ? "Directory" : "File"}`));
|
|
5907
6163
|
if (item.timestamp) {
|
|
5908
|
-
console.log(
|
|
6164
|
+
console.log(import_chalk5.default.white(` Date: ${new Date(item.timestamp).toLocaleString()}`));
|
|
5909
6165
|
}
|
|
5910
|
-
console.log(
|
|
6166
|
+
console.log(import_chalk5.default.cyan("-".repeat(80)));
|
|
5911
6167
|
}
|
|
5912
6168
|
const totalSize = history.reduce((sum, record) => sum + record.size, 0);
|
|
5913
6169
|
const totalFiles = history.reduce((sum, record) => sum + record.fileCount, 0);
|
|
5914
|
-
console.log(
|
|
5915
|
-
console.log(
|
|
5916
|
-
console.log(
|
|
6170
|
+
console.log(import_chalk5.default.bold(`Total Uploads: ${history.length}`));
|
|
6171
|
+
console.log(import_chalk5.default.bold(`Total Files: ${totalFiles}`));
|
|
6172
|
+
console.log(import_chalk5.default.bold(`Total Size: ${formatSize(totalSize)}`));
|
|
5917
6173
|
};
|
|
5918
6174
|
var clearUploadHistory = () => {
|
|
5919
6175
|
try {
|
|
5920
6176
|
ensureHistoryDir();
|
|
5921
6177
|
import_fs_extra3.default.writeJsonSync(HISTORY_FILE, { uploads: [] });
|
|
5922
|
-
console.log(
|
|
6178
|
+
console.log(import_chalk5.default.green("Upload history cleared successfully."));
|
|
5923
6179
|
return true;
|
|
5924
6180
|
} catch (error) {
|
|
5925
|
-
console.error(
|
|
6181
|
+
console.error(import_chalk5.default.red(`Error clearing upload history: ${error.message}`));
|
|
5926
6182
|
return false;
|
|
5927
6183
|
}
|
|
5928
6184
|
};
|
|
@@ -6669,12 +6925,12 @@ async function uploadPath(targetPath, options = {}) {
|
|
|
6669
6925
|
}
|
|
6670
6926
|
|
|
6671
6927
|
// bin/utils/urlDisplay.ts
|
|
6672
|
-
var
|
|
6928
|
+
var import_chalk6 = __toESM(require("chalk"));
|
|
6673
6929
|
function printHighlightedUrl(label, url2, tone = "primary") {
|
|
6674
6930
|
const safeLabel = label.trim() || "URL";
|
|
6675
6931
|
const safeUrl = url2.trim();
|
|
6676
|
-
const labelStyle =
|
|
6677
|
-
const urlStyle = tone === "management" ?
|
|
6932
|
+
const labelStyle = import_chalk6.default.black.bgWhiteBright.bold;
|
|
6933
|
+
const urlStyle = tone === "management" ? import_chalk6.default.blueBright.bold.underline : import_chalk6.default.cyanBright.bold;
|
|
6678
6934
|
console.log("");
|
|
6679
6935
|
console.log(labelStyle(` ${safeLabel} `));
|
|
6680
6936
|
console.log(urlStyle(safeUrl));
|
|
@@ -6691,7 +6947,7 @@ function checkPathSync(inputPath) {
|
|
|
6691
6947
|
}
|
|
6692
6948
|
return null;
|
|
6693
6949
|
} catch (error) {
|
|
6694
|
-
console.error(
|
|
6950
|
+
console.error(import_chalk7.default.red(`error checking path: ${error.message}`));
|
|
6695
6951
|
return null;
|
|
6696
6952
|
}
|
|
6697
6953
|
}
|
|
@@ -6723,7 +6979,7 @@ function getDnsFromArgs() {
|
|
|
6723
6979
|
}
|
|
6724
6980
|
async function checkWalletBalanceStatus(authConfig) {
|
|
6725
6981
|
var _a2;
|
|
6726
|
-
console.log(
|
|
6982
|
+
console.log(import_chalk7.default.blue("Checking wallet balance..."));
|
|
6727
6983
|
try {
|
|
6728
6984
|
const balanceResult = await getWalletBalance(
|
|
6729
6985
|
authConfig.address,
|
|
@@ -6734,21 +6990,21 @@ async function checkWalletBalanceStatus(authConfig) {
|
|
|
6734
6990
|
return false;
|
|
6735
6991
|
}
|
|
6736
6992
|
console.log(
|
|
6737
|
-
|
|
6993
|
+
import_chalk7.default.green(`Wallet balance available: $${balance.toFixed(2)}`)
|
|
6738
6994
|
);
|
|
6739
6995
|
return true;
|
|
6740
6996
|
} catch (e) {
|
|
6741
|
-
if (e.message === "Token expired") {
|
|
6997
|
+
if (e.message === "Token expired" || (e == null ? void 0 : e.name) === "CliError") {
|
|
6742
6998
|
throw e;
|
|
6743
6999
|
}
|
|
6744
|
-
console.log(
|
|
7000
|
+
console.log(import_chalk7.default.yellow("Failed to check wallet balance, continuing..."));
|
|
6745
7001
|
return true;
|
|
6746
7002
|
}
|
|
6747
7003
|
}
|
|
6748
7004
|
async function bindDomain(domain, contentHash, isDns, authConfig) {
|
|
6749
7005
|
const displayDomain = normalizeDomain(domain);
|
|
6750
7006
|
if (isDns) {
|
|
6751
|
-
console.log(
|
|
7007
|
+
console.log(import_chalk7.default.blue("Binding DNS domain..."));
|
|
6752
7008
|
const dnsResult = await bindDnsDomainV4(
|
|
6753
7009
|
displayDomain,
|
|
6754
7010
|
contentHash,
|
|
@@ -6756,26 +7012,26 @@ async function bindDomain(domain, contentHash, isDns, authConfig) {
|
|
|
6756
7012
|
authConfig.token
|
|
6757
7013
|
);
|
|
6758
7014
|
if (dnsResult.code !== 200) {
|
|
6759
|
-
console.log(
|
|
7015
|
+
console.log(import_chalk7.default.red(`DNS binding failed: ${dnsResult.msg}`));
|
|
6760
7016
|
return false;
|
|
6761
7017
|
}
|
|
6762
|
-
console.log(
|
|
6763
|
-
console.log(
|
|
7018
|
+
console.log(import_chalk7.default.green(`DNS bind success: ${displayDomain}`));
|
|
7019
|
+
console.log(import_chalk7.default.white(`Visit: https://${displayDomain}`));
|
|
6764
7020
|
console.log(
|
|
6765
|
-
|
|
7021
|
+
import_chalk7.default.cyan(
|
|
6766
7022
|
"\n\u{1F4DA} DNS Setup Guide: https://pinme.eth.limo/#/docs?id=custom-domain"
|
|
6767
7023
|
)
|
|
6768
7024
|
);
|
|
6769
7025
|
} else {
|
|
6770
|
-
console.log(
|
|
7026
|
+
console.log(import_chalk7.default.blue("Binding Pinme subdomain..."));
|
|
6771
7027
|
const ok = await bindPinmeDomain(displayDomain, contentHash);
|
|
6772
7028
|
if (!ok) {
|
|
6773
|
-
console.log(
|
|
7029
|
+
console.log(import_chalk7.default.red("Binding failed. Please try again later."));
|
|
6774
7030
|
return false;
|
|
6775
7031
|
}
|
|
6776
|
-
console.log(
|
|
7032
|
+
console.log(import_chalk7.default.green(`Bind success: ${displayDomain}`));
|
|
6777
7033
|
const rootDomain = await (await Promise.resolve().then(() => (init_pinmeApi(), pinmeApi_exports))).getRootDomain();
|
|
6778
|
-
console.log(
|
|
7034
|
+
console.log(import_chalk7.default.white(`Visit: https://${displayDomain}.${rootDomain}`));
|
|
6779
7035
|
}
|
|
6780
7036
|
return true;
|
|
6781
7037
|
}
|
|
@@ -6792,7 +7048,7 @@ var upload_default = async (options) => {
|
|
|
6792
7048
|
);
|
|
6793
7049
|
const authConfig = getAuthConfig();
|
|
6794
7050
|
if (!authConfig) {
|
|
6795
|
-
console.log(
|
|
7051
|
+
console.log(import_chalk7.default.red("Please login first. Run: pinme login"));
|
|
6796
7052
|
return;
|
|
6797
7053
|
}
|
|
6798
7054
|
const domainArg = getDomainFromArgs();
|
|
@@ -6801,7 +7057,7 @@ var upload_default = async (options) => {
|
|
|
6801
7057
|
if (argPath && !argPath.startsWith("-")) {
|
|
6802
7058
|
const absolutePath = checkPathSync(argPath);
|
|
6803
7059
|
if (!absolutePath) {
|
|
6804
|
-
console.log(
|
|
7060
|
+
console.log(import_chalk7.default.red(`path ${argPath} does not exist`));
|
|
6805
7061
|
return;
|
|
6806
7062
|
}
|
|
6807
7063
|
const isDns = dnsArg || (domainArg ? isDnsDomain(domainArg) : false);
|
|
@@ -6809,7 +7065,7 @@ var upload_default = async (options) => {
|
|
|
6809
7065
|
if (isDns && domainArg) {
|
|
6810
7066
|
const validation = validateDnsDomain(domainArg);
|
|
6811
7067
|
if (!validation.valid) {
|
|
6812
|
-
console.log(
|
|
7068
|
+
console.log(import_chalk7.default.red(validation.message));
|
|
6813
7069
|
return;
|
|
6814
7070
|
}
|
|
6815
7071
|
}
|
|
@@ -6818,10 +7074,11 @@ var upload_default = async (options) => {
|
|
|
6818
7074
|
const hasWalletBalance = await checkWalletBalanceStatus(authConfig);
|
|
6819
7075
|
if (!hasWalletBalance) {
|
|
6820
7076
|
console.log(
|
|
6821
|
-
|
|
7077
|
+
import_chalk7.default.red(
|
|
6822
7078
|
"Insufficient wallet balance. Please recharge your wallet first."
|
|
6823
7079
|
)
|
|
6824
7080
|
);
|
|
7081
|
+
console.log(import_chalk7.default.cyan(`Recharge URL: ${getWalletRechargeUrl()}`));
|
|
6825
7082
|
return;
|
|
6826
7083
|
}
|
|
6827
7084
|
} catch (e) {
|
|
@@ -6836,13 +7093,13 @@ var upload_default = async (options) => {
|
|
|
6836
7093
|
const check = await checkDomainAvailable(displayDomain);
|
|
6837
7094
|
if (!check.is_valid) {
|
|
6838
7095
|
console.log(
|
|
6839
|
-
|
|
7096
|
+
import_chalk7.default.red(
|
|
6840
7097
|
`Domain not available: ${check.error || "unknown reason"}`
|
|
6841
7098
|
)
|
|
6842
7099
|
);
|
|
6843
7100
|
return;
|
|
6844
7101
|
}
|
|
6845
|
-
console.log(
|
|
7102
|
+
console.log(import_chalk7.default.green(`Domain available: ${displayDomain}`));
|
|
6846
7103
|
} catch (e) {
|
|
6847
7104
|
if (e.message === "Token expired") {
|
|
6848
7105
|
return;
|
|
@@ -6850,7 +7107,7 @@ var upload_default = async (options) => {
|
|
|
6850
7107
|
throw e;
|
|
6851
7108
|
}
|
|
6852
7109
|
}
|
|
6853
|
-
console.log(
|
|
7110
|
+
console.log(import_chalk7.default.blue(`uploading ${absolutePath} to ipfs...`));
|
|
6854
7111
|
let result;
|
|
6855
7112
|
try {
|
|
6856
7113
|
result = await uploadPath(absolutePath, {
|
|
@@ -6858,20 +7115,20 @@ var upload_default = async (options) => {
|
|
|
6858
7115
|
uid: authConfig == null ? void 0 : authConfig.address
|
|
6859
7116
|
});
|
|
6860
7117
|
} catch (error) {
|
|
6861
|
-
|
|
7118
|
+
printCliError(error, "Upload failed.");
|
|
6862
7119
|
process.exit(1);
|
|
6863
7120
|
}
|
|
6864
7121
|
if (!result) {
|
|
6865
|
-
console.error(
|
|
7122
|
+
console.error(import_chalk7.default.red("Upload failed: no result returned"));
|
|
6866
7123
|
process.exit(1);
|
|
6867
7124
|
}
|
|
6868
7125
|
console.log(
|
|
6869
|
-
|
|
7126
|
+
import_chalk7.default.cyan(import_figlet.default.textSync("Successful", { horizontalLayout: "full" }))
|
|
6870
7127
|
);
|
|
6871
7128
|
await printUploadUrls(result);
|
|
6872
7129
|
if (domainArg) {
|
|
6873
7130
|
console.log(
|
|
6874
|
-
|
|
7131
|
+
import_chalk7.default.blue(
|
|
6875
7132
|
`Binding domain: ${displayDomain} with CID: ${result.contentHash}`
|
|
6876
7133
|
)
|
|
6877
7134
|
);
|
|
@@ -6884,7 +7141,7 @@ var upload_default = async (options) => {
|
|
|
6884
7141
|
throw e;
|
|
6885
7142
|
}
|
|
6886
7143
|
}
|
|
6887
|
-
console.log(
|
|
7144
|
+
console.log(import_chalk7.default.green("\n\u{1F389} upload successful, program exit"));
|
|
6888
7145
|
process.exit(0);
|
|
6889
7146
|
}
|
|
6890
7147
|
const answer = await import_inquirer.default.prompt([
|
|
@@ -6897,7 +7154,7 @@ var upload_default = async (options) => {
|
|
|
6897
7154
|
if (answer.path) {
|
|
6898
7155
|
const absolutePath = checkPathSync(answer.path);
|
|
6899
7156
|
if (!absolutePath) {
|
|
6900
|
-
console.log(
|
|
7157
|
+
console.log(import_chalk7.default.red(`path ${answer.path} does not exist`));
|
|
6901
7158
|
return;
|
|
6902
7159
|
}
|
|
6903
7160
|
const isDns = dnsArg || (domainArg ? isDnsDomain(domainArg) : false);
|
|
@@ -6905,7 +7162,7 @@ var upload_default = async (options) => {
|
|
|
6905
7162
|
if (isDns && domainArg) {
|
|
6906
7163
|
const validation = validateDnsDomain(domainArg);
|
|
6907
7164
|
if (!validation.valid) {
|
|
6908
|
-
console.log(
|
|
7165
|
+
console.log(import_chalk7.default.red(validation.message));
|
|
6909
7166
|
return;
|
|
6910
7167
|
}
|
|
6911
7168
|
}
|
|
@@ -6914,10 +7171,11 @@ var upload_default = async (options) => {
|
|
|
6914
7171
|
const hasWalletBalance = await checkWalletBalanceStatus(authConfig);
|
|
6915
7172
|
if (!hasWalletBalance) {
|
|
6916
7173
|
console.log(
|
|
6917
|
-
|
|
7174
|
+
import_chalk7.default.red(
|
|
6918
7175
|
"Insufficient wallet balance. Please recharge your wallet first."
|
|
6919
7176
|
)
|
|
6920
7177
|
);
|
|
7178
|
+
console.log(import_chalk7.default.cyan(`Recharge URL: ${getWalletRechargeUrl()}`));
|
|
6921
7179
|
return;
|
|
6922
7180
|
}
|
|
6923
7181
|
} catch (e) {
|
|
@@ -6932,13 +7190,13 @@ var upload_default = async (options) => {
|
|
|
6932
7190
|
const check = await checkDomainAvailable(displayDomain);
|
|
6933
7191
|
if (!check.is_valid) {
|
|
6934
7192
|
console.log(
|
|
6935
|
-
|
|
7193
|
+
import_chalk7.default.red(
|
|
6936
7194
|
`Domain not available: ${check.error || "unknown reason"}`
|
|
6937
7195
|
)
|
|
6938
7196
|
);
|
|
6939
7197
|
return;
|
|
6940
7198
|
}
|
|
6941
|
-
console.log(
|
|
7199
|
+
console.log(import_chalk7.default.green(`Domain available: ${displayDomain}`));
|
|
6942
7200
|
} catch (e) {
|
|
6943
7201
|
if (e.message === "Token expired") {
|
|
6944
7202
|
return;
|
|
@@ -6946,7 +7204,7 @@ var upload_default = async (options) => {
|
|
|
6946
7204
|
throw e;
|
|
6947
7205
|
}
|
|
6948
7206
|
}
|
|
6949
|
-
console.log(
|
|
7207
|
+
console.log(import_chalk7.default.blue(`uploading ${absolutePath} to ipfs...`));
|
|
6950
7208
|
let result;
|
|
6951
7209
|
try {
|
|
6952
7210
|
result = await uploadPath(absolutePath, {
|
|
@@ -6954,20 +7212,20 @@ var upload_default = async (options) => {
|
|
|
6954
7212
|
uid: authConfig == null ? void 0 : authConfig.address
|
|
6955
7213
|
});
|
|
6956
7214
|
} catch (error) {
|
|
6957
|
-
|
|
7215
|
+
printCliError(error, "Upload failed.");
|
|
6958
7216
|
process.exit(1);
|
|
6959
7217
|
}
|
|
6960
7218
|
if (!result) {
|
|
6961
|
-
console.error(
|
|
7219
|
+
console.error(import_chalk7.default.red("Upload failed: no result returned"));
|
|
6962
7220
|
process.exit(1);
|
|
6963
7221
|
}
|
|
6964
7222
|
console.log(
|
|
6965
|
-
|
|
7223
|
+
import_chalk7.default.cyan(import_figlet.default.textSync("Successful", { horizontalLayout: "full" }))
|
|
6966
7224
|
);
|
|
6967
7225
|
await printUploadUrls(result);
|
|
6968
7226
|
if (domainArg) {
|
|
6969
7227
|
console.log(
|
|
6970
|
-
|
|
7228
|
+
import_chalk7.default.blue(
|
|
6971
7229
|
`Binding domain: ${displayDomain} with CID: ${result.contentHash}`
|
|
6972
7230
|
)
|
|
6973
7231
|
);
|
|
@@ -6980,23 +7238,23 @@ var upload_default = async (options) => {
|
|
|
6980
7238
|
throw e;
|
|
6981
7239
|
}
|
|
6982
7240
|
}
|
|
6983
|
-
console.log(
|
|
7241
|
+
console.log(import_chalk7.default.green("\n\u{1F389} upload successful, program exit"));
|
|
6984
7242
|
process.exit(0);
|
|
6985
7243
|
}
|
|
6986
7244
|
} catch (error) {
|
|
6987
|
-
|
|
6988
|
-
console.error(error.stack);
|
|
7245
|
+
printCliError(error, "Upload failed.");
|
|
6989
7246
|
}
|
|
6990
7247
|
};
|
|
6991
7248
|
|
|
6992
7249
|
// bin/importCar.ts
|
|
6993
7250
|
var import_path7 = __toESM(require("path"));
|
|
6994
|
-
var
|
|
7251
|
+
var import_chalk8 = __toESM(require("chalk"));
|
|
6995
7252
|
var import_inquirer2 = __toESM(require("inquirer"));
|
|
6996
7253
|
var import_figlet2 = __toESM(require("figlet"));
|
|
6997
7254
|
var import_fs3 = __toESM(require("fs"));
|
|
6998
7255
|
var import_crypto_js2 = __toESM(require("crypto-js"));
|
|
6999
7256
|
init_pinmeApi();
|
|
7257
|
+
init_cliError();
|
|
7000
7258
|
init_webLogin();
|
|
7001
7259
|
init_config();
|
|
7002
7260
|
checkNodeVersion();
|
|
@@ -7022,7 +7280,7 @@ function checkPathSync2(inputPath) {
|
|
|
7022
7280
|
}
|
|
7023
7281
|
return null;
|
|
7024
7282
|
} catch (error) {
|
|
7025
|
-
console.error(
|
|
7283
|
+
console.error(import_chalk8.default.red(`error checking path: ${error.message}`));
|
|
7026
7284
|
return null;
|
|
7027
7285
|
}
|
|
7028
7286
|
}
|
|
@@ -7054,7 +7312,7 @@ var importCar_default = async (options) => {
|
|
|
7054
7312
|
);
|
|
7055
7313
|
const auth = getAuthConfig();
|
|
7056
7314
|
if (!auth) {
|
|
7057
|
-
console.log(
|
|
7315
|
+
console.log(import_chalk8.default.red("Please login first. Run: pinme login"));
|
|
7058
7316
|
return;
|
|
7059
7317
|
}
|
|
7060
7318
|
const argPath = process.argv[3];
|
|
@@ -7062,18 +7320,18 @@ var importCar_default = async (options) => {
|
|
|
7062
7320
|
if (argPath && !argPath.startsWith("-")) {
|
|
7063
7321
|
const absolutePath = checkPathSync2(argPath);
|
|
7064
7322
|
if (!absolutePath) {
|
|
7065
|
-
console.log(
|
|
7323
|
+
console.log(import_chalk8.default.red(`path ${argPath} does not exist`));
|
|
7066
7324
|
return;
|
|
7067
7325
|
}
|
|
7068
7326
|
if (domainArg) {
|
|
7069
7327
|
const check = await checkDomainAvailable(domainArg);
|
|
7070
7328
|
if (!check.is_valid) {
|
|
7071
|
-
console.log(
|
|
7329
|
+
console.log(import_chalk8.default.red(`Domain not available: ${check.error || "unknown reason"}`));
|
|
7072
7330
|
return;
|
|
7073
7331
|
}
|
|
7074
|
-
console.log(
|
|
7332
|
+
console.log(import_chalk8.default.green(`Domain available: ${domainArg}`));
|
|
7075
7333
|
}
|
|
7076
|
-
console.log(
|
|
7334
|
+
console.log(import_chalk8.default.blue(`importing ${absolutePath} to ipfs as CAR...`));
|
|
7077
7335
|
try {
|
|
7078
7336
|
const result = await uploadPath(absolutePath, {
|
|
7079
7337
|
importAsCar: true,
|
|
@@ -7083,7 +7341,7 @@ var importCar_default = async (options) => {
|
|
|
7083
7341
|
const uid = getUid2();
|
|
7084
7342
|
const encryptedCID = encryptHash2(result.contentHash, APP_CONFIG.secretKey, uid);
|
|
7085
7343
|
console.log(
|
|
7086
|
-
|
|
7344
|
+
import_chalk8.default.cyan(
|
|
7087
7345
|
import_figlet2.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7088
7346
|
)
|
|
7089
7347
|
);
|
|
@@ -7093,20 +7351,20 @@ var importCar_default = async (options) => {
|
|
|
7093
7351
|
"primary"
|
|
7094
7352
|
);
|
|
7095
7353
|
if (domainArg) {
|
|
7096
|
-
console.log(
|
|
7354
|
+
console.log(import_chalk8.default.blue(`Binding domain: ${domainArg} with CID: ${result.contentHash}`));
|
|
7097
7355
|
const ok = await bindPinmeDomain(domainArg, result.contentHash);
|
|
7098
7356
|
if (ok) {
|
|
7099
|
-
console.log(
|
|
7357
|
+
console.log(import_chalk8.default.green(`Bind success: ${domainArg}`));
|
|
7100
7358
|
const rootDomain = await getRootDomain();
|
|
7101
|
-
console.log(
|
|
7359
|
+
console.log(import_chalk8.default.white(`Visit (Pinme subdomain example): https://${domainArg}.${rootDomain}`));
|
|
7102
7360
|
} else {
|
|
7103
|
-
console.log(
|
|
7361
|
+
console.log(import_chalk8.default.red("Binding failed. Please try again later."));
|
|
7104
7362
|
}
|
|
7105
7363
|
}
|
|
7106
|
-
console.log(
|
|
7364
|
+
console.log(import_chalk8.default.green("\n\u{1F389} import successful, program exit"));
|
|
7107
7365
|
}
|
|
7108
7366
|
} catch (error) {
|
|
7109
|
-
|
|
7367
|
+
printCliError(error, "Import failed.");
|
|
7110
7368
|
}
|
|
7111
7369
|
process.exit(0);
|
|
7112
7370
|
}
|
|
@@ -7120,18 +7378,18 @@ var importCar_default = async (options) => {
|
|
|
7120
7378
|
if (answer.path) {
|
|
7121
7379
|
const absolutePath = checkPathSync2(answer.path);
|
|
7122
7380
|
if (!absolutePath) {
|
|
7123
|
-
console.log(
|
|
7381
|
+
console.log(import_chalk8.default.red(`path ${answer.path} does not exist`));
|
|
7124
7382
|
return;
|
|
7125
7383
|
}
|
|
7126
7384
|
if (domainArg) {
|
|
7127
7385
|
const check = await checkDomainAvailable(domainArg);
|
|
7128
7386
|
if (!check.is_valid) {
|
|
7129
|
-
console.log(
|
|
7387
|
+
console.log(import_chalk8.default.red(`Domain not available: ${check.error || "unknown reason"}`));
|
|
7130
7388
|
return;
|
|
7131
7389
|
}
|
|
7132
|
-
console.log(
|
|
7390
|
+
console.log(import_chalk8.default.green(`Domain available: ${domainArg}`));
|
|
7133
7391
|
}
|
|
7134
|
-
console.log(
|
|
7392
|
+
console.log(import_chalk8.default.blue(`importing ${absolutePath} to ipfs as CAR...`));
|
|
7135
7393
|
try {
|
|
7136
7394
|
const result = await uploadPath(absolutePath, {
|
|
7137
7395
|
importAsCar: true,
|
|
@@ -7141,7 +7399,7 @@ var importCar_default = async (options) => {
|
|
|
7141
7399
|
const uid = getUid2();
|
|
7142
7400
|
const encryptedCID = encryptHash2(result.contentHash, APP_CONFIG.secretKey, uid);
|
|
7143
7401
|
console.log(
|
|
7144
|
-
|
|
7402
|
+
import_chalk8.default.cyan(
|
|
7145
7403
|
import_figlet2.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7146
7404
|
)
|
|
7147
7405
|
);
|
|
@@ -7151,37 +7409,37 @@ var importCar_default = async (options) => {
|
|
|
7151
7409
|
"primary"
|
|
7152
7410
|
);
|
|
7153
7411
|
if (domainArg) {
|
|
7154
|
-
console.log(
|
|
7412
|
+
console.log(import_chalk8.default.blue(`Binding domain: ${domainArg} with CID: ${result.contentHash}`));
|
|
7155
7413
|
const ok = await bindPinmeDomain(domainArg, result.contentHash);
|
|
7156
7414
|
if (ok) {
|
|
7157
|
-
console.log(
|
|
7415
|
+
console.log(import_chalk8.default.green(`Bind success: ${domainArg}`));
|
|
7158
7416
|
const rootDomain = await getRootDomain();
|
|
7159
|
-
console.log(
|
|
7417
|
+
console.log(import_chalk8.default.white(`Visit (Pinme subdomain example): https://${domainArg}.${rootDomain}`));
|
|
7160
7418
|
} else {
|
|
7161
|
-
console.log(
|
|
7419
|
+
console.log(import_chalk8.default.red("Binding failed. Please try again later."));
|
|
7162
7420
|
}
|
|
7163
7421
|
}
|
|
7164
|
-
console.log(
|
|
7422
|
+
console.log(import_chalk8.default.green("\n\u{1F389} import successful, program exit"));
|
|
7165
7423
|
}
|
|
7166
7424
|
} catch (error) {
|
|
7167
|
-
|
|
7425
|
+
printCliError(error, "Import failed.");
|
|
7168
7426
|
}
|
|
7169
7427
|
process.exit(0);
|
|
7170
7428
|
}
|
|
7171
7429
|
} catch (error) {
|
|
7172
|
-
|
|
7173
|
-
console.error(error.stack);
|
|
7430
|
+
printCliError(error, "Import failed.");
|
|
7174
7431
|
}
|
|
7175
7432
|
};
|
|
7176
7433
|
|
|
7177
7434
|
// bin/exportCar.ts
|
|
7178
7435
|
var import_path8 = __toESM(require("path"));
|
|
7179
|
-
var
|
|
7436
|
+
var import_chalk9 = __toESM(require("chalk"));
|
|
7180
7437
|
var import_inquirer3 = __toESM(require("inquirer"));
|
|
7181
7438
|
var import_figlet3 = __toESM(require("figlet"));
|
|
7182
7439
|
var import_fs4 = __toESM(require("fs"));
|
|
7183
7440
|
init_axios2();
|
|
7184
7441
|
var import_ora2 = __toESM(require("ora"));
|
|
7442
|
+
init_cliError();
|
|
7185
7443
|
init_pinmeApi();
|
|
7186
7444
|
checkNodeVersion();
|
|
7187
7445
|
var POLL_INTERVAL2 = 5e3;
|
|
@@ -7203,7 +7461,7 @@ async function pollExportStatus(taskId, cid, spinner, startTime) {
|
|
|
7203
7461
|
spinner.text = `Exporting CAR file... (${minutes}m ${seconds}s)`;
|
|
7204
7462
|
}
|
|
7205
7463
|
} catch (error) {
|
|
7206
|
-
console.log(
|
|
7464
|
+
console.log(import_chalk9.default.yellow(`Polling error: ${error.message}`));
|
|
7207
7465
|
}
|
|
7208
7466
|
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL2));
|
|
7209
7467
|
}
|
|
@@ -7243,7 +7501,7 @@ async function downloadCarFile(downloadUrl, outputPath) {
|
|
|
7243
7501
|
});
|
|
7244
7502
|
});
|
|
7245
7503
|
} catch (error) {
|
|
7246
|
-
console.error(
|
|
7504
|
+
console.error(import_chalk9.default.red(`Download error: ${error.message}`));
|
|
7247
7505
|
return false;
|
|
7248
7506
|
}
|
|
7249
7507
|
}
|
|
@@ -7301,7 +7559,7 @@ var exportCar_default = async () => {
|
|
|
7301
7559
|
cid = answer.cid.trim();
|
|
7302
7560
|
}
|
|
7303
7561
|
if (!cid || !isValidCID(cid)) {
|
|
7304
|
-
console.log(
|
|
7562
|
+
console.log(import_chalk9.default.red("Invalid CID format. CID should start with Qm, bafy, bafk, or bafz"));
|
|
7305
7563
|
return;
|
|
7306
7564
|
}
|
|
7307
7565
|
let outputDir = getOutputPathFromArgs();
|
|
@@ -7321,7 +7579,7 @@ var exportCar_default = async () => {
|
|
|
7321
7579
|
if (!import_fs4.default.existsSync(outputDir)) {
|
|
7322
7580
|
import_fs4.default.mkdirSync(outputDir, { recursive: true });
|
|
7323
7581
|
} else if (!import_fs4.default.statSync(outputDir).isDirectory()) {
|
|
7324
|
-
console.log(
|
|
7582
|
+
console.log(import_chalk9.default.red(`Error: ${outputDir} exists but is not a directory.`));
|
|
7325
7583
|
return;
|
|
7326
7584
|
}
|
|
7327
7585
|
const finalOutputPath = import_path8.default.join(outputDir, `${cid}.car`);
|
|
@@ -7335,7 +7593,7 @@ var exportCar_default = async () => {
|
|
|
7335
7593
|
}
|
|
7336
7594
|
]);
|
|
7337
7595
|
if (!answer.overwrite) {
|
|
7338
|
-
console.log(
|
|
7596
|
+
console.log(import_chalk9.default.blue("Export cancelled."));
|
|
7339
7597
|
return;
|
|
7340
7598
|
}
|
|
7341
7599
|
}
|
|
@@ -7353,7 +7611,7 @@ var exportCar_default = async () => {
|
|
|
7353
7611
|
startTime
|
|
7354
7612
|
);
|
|
7355
7613
|
if (!downloadUrl) {
|
|
7356
|
-
console.log(
|
|
7614
|
+
console.log(import_chalk9.default.red("Export failed or timed out."));
|
|
7357
7615
|
return;
|
|
7358
7616
|
}
|
|
7359
7617
|
const success = await downloadCarFile(downloadUrl, finalOutputPath);
|
|
@@ -7361,42 +7619,41 @@ var exportCar_default = async () => {
|
|
|
7361
7619
|
const fileSize = import_fs4.default.statSync(finalOutputPath).size;
|
|
7362
7620
|
const fileSizeMB = (fileSize / (1024 * 1024)).toFixed(2);
|
|
7363
7621
|
console.log(
|
|
7364
|
-
|
|
7622
|
+
import_chalk9.default.cyan(
|
|
7365
7623
|
import_figlet3.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7366
7624
|
)
|
|
7367
7625
|
);
|
|
7368
|
-
console.log(
|
|
7626
|
+
console.log(import_chalk9.default.green(`
|
|
7369
7627
|
\u{1F389} Export successful!`));
|
|
7370
|
-
console.log(
|
|
7371
|
-
console.log(
|
|
7372
|
-
console.log(
|
|
7628
|
+
console.log(import_chalk9.default.cyan(`File: ${finalOutputPath}`));
|
|
7629
|
+
console.log(import_chalk9.default.cyan(`Size: ${fileSizeMB} MB`));
|
|
7630
|
+
console.log(import_chalk9.default.cyan(`CID: ${cid}`));
|
|
7373
7631
|
} else {
|
|
7374
|
-
console.log(
|
|
7632
|
+
console.log(import_chalk9.default.red("Download failed."));
|
|
7375
7633
|
}
|
|
7376
7634
|
} catch (error) {
|
|
7377
7635
|
spinner.fail(`Error: ${error.message}`);
|
|
7378
|
-
|
|
7636
|
+
printCliError(error, "Export failed.");
|
|
7379
7637
|
}
|
|
7380
7638
|
} catch (error) {
|
|
7381
|
-
|
|
7382
|
-
console.error(error.stack);
|
|
7639
|
+
printCliError(error, "Export failed.");
|
|
7383
7640
|
}
|
|
7384
7641
|
};
|
|
7385
7642
|
|
|
7386
7643
|
// bin/remove.ts
|
|
7387
|
-
var
|
|
7644
|
+
var import_chalk11 = __toESM(require("chalk"));
|
|
7388
7645
|
var import_inquirer4 = __toESM(require("inquirer"));
|
|
7389
7646
|
var import_figlet4 = __toESM(require("figlet"));
|
|
7390
7647
|
|
|
7391
7648
|
// bin/utils/removeFromIpfs.ts
|
|
7392
7649
|
init_axios2();
|
|
7393
|
-
var
|
|
7650
|
+
var import_chalk10 = __toESM(require("chalk"));
|
|
7394
7651
|
init_config();
|
|
7395
7652
|
var ipfsApiUrl = APP_CONFIG.ipfsApiUrl;
|
|
7396
7653
|
async function removeFromIpfs(value, type = "hash") {
|
|
7397
7654
|
try {
|
|
7398
7655
|
const uid = getUid();
|
|
7399
|
-
console.log(
|
|
7656
|
+
console.log(import_chalk10.default.blue(`Removing content from IPFS: ${value}...`));
|
|
7400
7657
|
const queryParams = new URLSearchParams({
|
|
7401
7658
|
uid
|
|
7402
7659
|
});
|
|
@@ -7414,49 +7671,49 @@ async function removeFromIpfs(value, type = "hash") {
|
|
|
7414
7671
|
);
|
|
7415
7672
|
const { code, msg, data } = response.data;
|
|
7416
7673
|
if (code === 200) {
|
|
7417
|
-
console.log(
|
|
7674
|
+
console.log(import_chalk10.default.green("\u2713 Removal successful!"));
|
|
7418
7675
|
console.log(
|
|
7419
|
-
|
|
7676
|
+
import_chalk10.default.cyan(
|
|
7420
7677
|
`Content ${type}: ${value} has been removed from IPFS network`
|
|
7421
7678
|
)
|
|
7422
7679
|
);
|
|
7423
7680
|
return true;
|
|
7424
7681
|
} else {
|
|
7425
|
-
console.log(
|
|
7426
|
-
console.log(
|
|
7682
|
+
console.log(import_chalk10.default.red("\u2717 Removal failed"));
|
|
7683
|
+
console.log(import_chalk10.default.red(`Error: ${msg || "Unknown error occurred"}`));
|
|
7427
7684
|
return false;
|
|
7428
7685
|
}
|
|
7429
7686
|
} catch (error) {
|
|
7430
|
-
console.log(
|
|
7687
|
+
console.log(import_chalk10.default.red("\u2717 Removal failed", error));
|
|
7431
7688
|
if (error.response) {
|
|
7432
7689
|
const { status, data } = error.response;
|
|
7433
7690
|
console.log(
|
|
7434
|
-
|
|
7691
|
+
import_chalk10.default.red(`HTTP Error ${status}: ${(data == null ? void 0 : data.msg) || "Server error"}`)
|
|
7435
7692
|
);
|
|
7436
7693
|
if (status === 404) {
|
|
7437
7694
|
console.log(
|
|
7438
|
-
|
|
7695
|
+
import_chalk10.default.yellow("Content not found on the network or already removed")
|
|
7439
7696
|
);
|
|
7440
7697
|
} else if (status === 403) {
|
|
7441
7698
|
console.log(
|
|
7442
|
-
|
|
7699
|
+
import_chalk10.default.yellow(
|
|
7443
7700
|
"Permission denied - you may not have access to remove this content"
|
|
7444
7701
|
)
|
|
7445
7702
|
);
|
|
7446
7703
|
} else if (status === 500) {
|
|
7447
7704
|
console.log(
|
|
7448
|
-
|
|
7705
|
+
import_chalk10.default.yellow("Server internal error - please try again later")
|
|
7449
7706
|
);
|
|
7450
7707
|
}
|
|
7451
7708
|
} else if (error.request) {
|
|
7452
7709
|
console.log(
|
|
7453
|
-
|
|
7710
|
+
import_chalk10.default.red("Network error: Unable to connect to IPFS service")
|
|
7454
7711
|
);
|
|
7455
7712
|
console.log(
|
|
7456
|
-
|
|
7713
|
+
import_chalk10.default.yellow("Please check your internet connection and try again")
|
|
7457
7714
|
);
|
|
7458
7715
|
} else {
|
|
7459
|
-
console.log(
|
|
7716
|
+
console.log(import_chalk10.default.red(`Error: ${error.message}`));
|
|
7460
7717
|
}
|
|
7461
7718
|
return false;
|
|
7462
7719
|
}
|
|
@@ -7516,29 +7773,29 @@ var remove_default = async (options) => {
|
|
|
7516
7773
|
if (argHash && !argHash.startsWith("-")) {
|
|
7517
7774
|
const parsedInput = parseInput(argHash);
|
|
7518
7775
|
if (!parsedInput) {
|
|
7519
|
-
console.log(
|
|
7520
|
-
console.log(
|
|
7521
|
-
console.log(
|
|
7522
|
-
console.log(
|
|
7523
|
-
console.log(
|
|
7776
|
+
console.log(import_chalk11.default.red(`Invalid input format: ${argHash}`));
|
|
7777
|
+
console.log(import_chalk11.default.yellow("Supported formats:"));
|
|
7778
|
+
console.log(import_chalk11.default.yellow(" - IPFS hash: bafybeig..."));
|
|
7779
|
+
console.log(import_chalk11.default.yellow(" - Subname: 3abt6ztu"));
|
|
7780
|
+
console.log(import_chalk11.default.yellow(" - Subname URL: https://3abt6ztu.<root-domain>"));
|
|
7524
7781
|
return;
|
|
7525
7782
|
}
|
|
7526
7783
|
try {
|
|
7527
7784
|
const success = await removeFromIpfs(parsedInput.value, parsedInput.type);
|
|
7528
7785
|
if (success) {
|
|
7529
7786
|
console.log(
|
|
7530
|
-
|
|
7787
|
+
import_chalk11.default.cyan(
|
|
7531
7788
|
import_figlet4.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7532
7789
|
)
|
|
7533
7790
|
);
|
|
7534
7791
|
}
|
|
7535
7792
|
} catch (error) {
|
|
7536
|
-
console.error(
|
|
7793
|
+
console.error(import_chalk11.default.red(`Error: ${error.message}`));
|
|
7537
7794
|
}
|
|
7538
7795
|
return;
|
|
7539
7796
|
}
|
|
7540
|
-
console.log(
|
|
7541
|
-
console.log(
|
|
7797
|
+
console.log(import_chalk11.default.yellow("\u26A0\uFE0F Warning: This action will permanently remove the content from IPFS network"));
|
|
7798
|
+
console.log(import_chalk11.default.yellow("\u26A0\uFE0F Make sure you have the correct IPFS hash"));
|
|
7542
7799
|
console.log("");
|
|
7543
7800
|
const confirmAnswer = await import_inquirer4.default.prompt([
|
|
7544
7801
|
{
|
|
@@ -7549,7 +7806,7 @@ var remove_default = async (options) => {
|
|
|
7549
7806
|
}
|
|
7550
7807
|
]);
|
|
7551
7808
|
if (!confirmAnswer.confirm) {
|
|
7552
|
-
console.log(
|
|
7809
|
+
console.log(import_chalk11.default.yellow("Operation cancelled"));
|
|
7553
7810
|
return;
|
|
7554
7811
|
}
|
|
7555
7812
|
const answer = await import_inquirer4.default.prompt([
|
|
@@ -7572,7 +7829,7 @@ var remove_default = async (options) => {
|
|
|
7572
7829
|
if (answer.input) {
|
|
7573
7830
|
const parsedInput = parseInput(answer.input.trim());
|
|
7574
7831
|
if (!parsedInput) {
|
|
7575
|
-
console.log(
|
|
7832
|
+
console.log(import_chalk11.default.red("Invalid input format"));
|
|
7576
7833
|
return;
|
|
7577
7834
|
}
|
|
7578
7835
|
const finalConfirm = await import_inquirer4.default.prompt([
|
|
@@ -7584,30 +7841,30 @@ var remove_default = async (options) => {
|
|
|
7584
7841
|
}
|
|
7585
7842
|
]);
|
|
7586
7843
|
if (!finalConfirm.confirm) {
|
|
7587
|
-
console.log(
|
|
7844
|
+
console.log(import_chalk11.default.yellow("Operation cancelled"));
|
|
7588
7845
|
return;
|
|
7589
7846
|
}
|
|
7590
7847
|
try {
|
|
7591
7848
|
const success = await removeFromIpfs(parsedInput.value, parsedInput.type);
|
|
7592
7849
|
if (success) {
|
|
7593
7850
|
console.log(
|
|
7594
|
-
|
|
7851
|
+
import_chalk11.default.cyan(
|
|
7595
7852
|
import_figlet4.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7596
7853
|
)
|
|
7597
7854
|
);
|
|
7598
7855
|
}
|
|
7599
7856
|
} catch (error) {
|
|
7600
|
-
console.error(
|
|
7857
|
+
console.error(import_chalk11.default.red(`Error: ${error.message}`));
|
|
7601
7858
|
}
|
|
7602
7859
|
}
|
|
7603
7860
|
} catch (error) {
|
|
7604
|
-
console.error(
|
|
7861
|
+
console.error(import_chalk11.default.red(`Error executing remove command: ${error.message}`));
|
|
7605
7862
|
console.error(error.stack);
|
|
7606
7863
|
}
|
|
7607
7864
|
};
|
|
7608
7865
|
|
|
7609
7866
|
// bin/set-appkey.ts
|
|
7610
|
-
var
|
|
7867
|
+
var import_chalk12 = __toESM(require("chalk"));
|
|
7611
7868
|
var import_inquirer5 = __toESM(require("inquirer"));
|
|
7612
7869
|
init_webLogin();
|
|
7613
7870
|
init_pinmeApi();
|
|
@@ -7626,32 +7883,32 @@ async function setAppKeyCmd() {
|
|
|
7626
7883
|
appKey = ans.appKey;
|
|
7627
7884
|
}
|
|
7628
7885
|
if (!appKey) {
|
|
7629
|
-
console.log(
|
|
7886
|
+
console.log(import_chalk12.default.red("AppKey not provided."));
|
|
7630
7887
|
return;
|
|
7631
7888
|
}
|
|
7632
7889
|
const saved = setAuthToken(appKey);
|
|
7633
|
-
console.log(
|
|
7890
|
+
console.log(import_chalk12.default.green(`Auth set for address: ${saved.address}`));
|
|
7634
7891
|
const deviceId = getDeviceId();
|
|
7635
7892
|
const ok = await bindAnonymousDevice(deviceId);
|
|
7636
7893
|
if (ok) {
|
|
7637
|
-
console.log(
|
|
7894
|
+
console.log(import_chalk12.default.green("Anonymous history merged to current account."));
|
|
7638
7895
|
} else {
|
|
7639
|
-
console.log(
|
|
7896
|
+
console.log(import_chalk12.default.yellow("Anonymous history merge not confirmed. You may retry later."));
|
|
7640
7897
|
}
|
|
7641
7898
|
} catch (e) {
|
|
7642
|
-
console.log(
|
|
7899
|
+
console.log(import_chalk12.default.red(`Failed to set AppKey: ${(e == null ? void 0 : e.message) || e}`));
|
|
7643
7900
|
}
|
|
7644
7901
|
}
|
|
7645
7902
|
|
|
7646
7903
|
// bin/logout.ts
|
|
7647
|
-
var
|
|
7904
|
+
var import_chalk13 = __toESM(require("chalk"));
|
|
7648
7905
|
var import_inquirer6 = __toESM(require("inquirer"));
|
|
7649
7906
|
init_webLogin();
|
|
7650
7907
|
async function logoutCmd() {
|
|
7651
7908
|
try {
|
|
7652
7909
|
const auth = getAuthConfig();
|
|
7653
7910
|
if (!auth) {
|
|
7654
|
-
console.log(
|
|
7911
|
+
console.log(import_chalk13.default.yellow("No active session found. You are already logged out."));
|
|
7655
7912
|
return;
|
|
7656
7913
|
}
|
|
7657
7914
|
const answer = await import_inquirer6.default.prompt([
|
|
@@ -7663,81 +7920,83 @@ async function logoutCmd() {
|
|
|
7663
7920
|
}
|
|
7664
7921
|
]);
|
|
7665
7922
|
if (!answer.confirm) {
|
|
7666
|
-
console.log(
|
|
7923
|
+
console.log(import_chalk13.default.blue("Logout cancelled."));
|
|
7667
7924
|
return;
|
|
7668
7925
|
}
|
|
7669
7926
|
clearAuthToken();
|
|
7670
|
-
console.log(
|
|
7671
|
-
console.log(
|
|
7927
|
+
console.log(import_chalk13.default.green("Successfully logged out."));
|
|
7928
|
+
console.log(import_chalk13.default.gray(`Address ${auth.address} has been removed from local storage.`));
|
|
7672
7929
|
} catch (e) {
|
|
7673
|
-
console.log(
|
|
7930
|
+
console.log(import_chalk13.default.red(`Failed to logout: ${(e == null ? void 0 : e.message) || e}`));
|
|
7674
7931
|
}
|
|
7675
7932
|
}
|
|
7676
7933
|
|
|
7677
7934
|
// bin/show-appkey.ts
|
|
7678
|
-
var
|
|
7935
|
+
var import_chalk14 = __toESM(require("chalk"));
|
|
7679
7936
|
init_webLogin();
|
|
7680
7937
|
function showAppKeyCmd() {
|
|
7681
7938
|
try {
|
|
7682
7939
|
const auth = getAuthConfig();
|
|
7683
7940
|
if (!auth) {
|
|
7684
|
-
console.log(
|
|
7685
|
-
console.log(
|
|
7941
|
+
console.log(import_chalk14.default.yellow("No AppKey found. Please set your AppKey first."));
|
|
7942
|
+
console.log(import_chalk14.default.gray("Run: pinme set-appkey <AppKey>"));
|
|
7686
7943
|
return;
|
|
7687
7944
|
}
|
|
7688
|
-
console.log(
|
|
7689
|
-
console.log(
|
|
7945
|
+
console.log(import_chalk14.default.green("Current AppKey Information:"));
|
|
7946
|
+
console.log(import_chalk14.default.cyan(` Address: ${auth.address}`));
|
|
7690
7947
|
const token = auth.token;
|
|
7691
7948
|
if (token.length > 12) {
|
|
7692
7949
|
const maskedToken = `${token.substring(0, 8)}${"*".repeat(token.length - 12)}${token.substring(token.length - 4)}`;
|
|
7693
|
-
console.log(
|
|
7950
|
+
console.log(import_chalk14.default.cyan(` Token: ${maskedToken}`));
|
|
7694
7951
|
} else {
|
|
7695
|
-
console.log(
|
|
7952
|
+
console.log(import_chalk14.default.cyan(` Token: ${"*".repeat(token.length)}`));
|
|
7696
7953
|
}
|
|
7697
7954
|
const combined = `${auth.address}-${auth.token}`;
|
|
7698
7955
|
if (combined.length > 20) {
|
|
7699
7956
|
const maskedAppKey = `${combined.substring(0, 12)}${"*".repeat(combined.length - 16)}${combined.substring(combined.length - 4)}`;
|
|
7700
|
-
console.log(
|
|
7957
|
+
console.log(import_chalk14.default.cyan(` AppKey: ${maskedAppKey}`));
|
|
7701
7958
|
} else {
|
|
7702
|
-
console.log(
|
|
7959
|
+
console.log(import_chalk14.default.cyan(` AppKey: ${"*".repeat(combined.length)}`));
|
|
7703
7960
|
}
|
|
7704
7961
|
} catch (e) {
|
|
7705
|
-
console.log(
|
|
7962
|
+
console.log(import_chalk14.default.red(`Failed to show AppKey: ${(e == null ? void 0 : e.message) || e}`));
|
|
7706
7963
|
}
|
|
7707
7964
|
}
|
|
7708
7965
|
|
|
7709
7966
|
// bin/my-domains.ts
|
|
7710
|
-
var
|
|
7967
|
+
var import_chalk15 = __toESM(require("chalk"));
|
|
7711
7968
|
var import_dayjs2 = __toESM(require("dayjs"));
|
|
7969
|
+
init_cliError();
|
|
7712
7970
|
init_pinmeApi();
|
|
7713
7971
|
async function myDomainsCmd() {
|
|
7714
7972
|
try {
|
|
7715
7973
|
const list = await getMyDomains();
|
|
7716
7974
|
if (!list.length) {
|
|
7717
|
-
console.log(
|
|
7975
|
+
console.log(import_chalk15.default.yellow("No bound domains found."));
|
|
7718
7976
|
return;
|
|
7719
7977
|
}
|
|
7720
|
-
console.log(
|
|
7721
|
-
console.log(
|
|
7978
|
+
console.log(import_chalk15.default.cyan("My domains:"));
|
|
7979
|
+
console.log(import_chalk15.default.cyan("-".repeat(80)));
|
|
7722
7980
|
list.forEach((item, i) => {
|
|
7723
|
-
console.log(
|
|
7724
|
-
console.log(
|
|
7981
|
+
console.log(import_chalk15.default.green(`${i + 1}. ${item.domain_name}`));
|
|
7982
|
+
console.log(import_chalk15.default.white(` Type: ${item.domain_type}`));
|
|
7725
7983
|
if (item.bind_time) {
|
|
7726
|
-
console.log(
|
|
7984
|
+
console.log(import_chalk15.default.white(` Bind time: ${(0, import_dayjs2.default)(item.bind_time * 1e3).format("YYYY-MM-DD HH:mm:ss")}`));
|
|
7727
7985
|
}
|
|
7728
7986
|
if (typeof item.expire_time === "number") {
|
|
7729
7987
|
const label = item.expire_time === 0 ? "Never" : (0, import_dayjs2.default)(item.expire_time * 1e3).format("YYYY-MM-DD HH:mm:ss");
|
|
7730
|
-
console.log(
|
|
7988
|
+
console.log(import_chalk15.default.white(` Expire time: ${label}`));
|
|
7731
7989
|
}
|
|
7732
|
-
console.log(
|
|
7990
|
+
console.log(import_chalk15.default.cyan("-".repeat(80)));
|
|
7733
7991
|
});
|
|
7734
7992
|
} catch (e) {
|
|
7735
|
-
|
|
7993
|
+
printCliError(e, "Failed to fetch domains.");
|
|
7736
7994
|
}
|
|
7737
7995
|
}
|
|
7738
7996
|
|
|
7739
7997
|
// bin/wallet-balance.ts
|
|
7740
|
-
var
|
|
7998
|
+
var import_chalk16 = __toESM(require("chalk"));
|
|
7999
|
+
init_cliError();
|
|
7741
8000
|
init_pinmeApi();
|
|
7742
8001
|
init_webLogin();
|
|
7743
8002
|
async function walletBalanceCmd() {
|
|
@@ -7745,27 +8004,29 @@ async function walletBalanceCmd() {
|
|
|
7745
8004
|
try {
|
|
7746
8005
|
const auth = getAuthConfig();
|
|
7747
8006
|
if (!auth) {
|
|
7748
|
-
console.log(
|
|
8007
|
+
console.log(import_chalk16.default.yellow("Please login first. Run: pinme set-appkey <AppKey>"));
|
|
7749
8008
|
return;
|
|
7750
8009
|
}
|
|
7751
8010
|
const result = await getWalletBalance(auth.address, auth.token);
|
|
7752
8011
|
const balance = Number(((_a2 = result.data) == null ? void 0 : _a2.wallet_balance_usd) ?? 0);
|
|
7753
8012
|
if (!Number.isFinite(balance)) {
|
|
7754
|
-
console.log(
|
|
8013
|
+
console.log(import_chalk16.default.red("Failed to parse wallet balance."));
|
|
7755
8014
|
return;
|
|
7756
8015
|
}
|
|
7757
|
-
console.log(
|
|
7758
|
-
console.log(
|
|
8016
|
+
console.log(import_chalk16.default.cyan("Wallet balance:"));
|
|
8017
|
+
console.log(import_chalk16.default.green(` USD: $${balance.toFixed(2)}`));
|
|
7759
8018
|
} catch (e) {
|
|
7760
|
-
|
|
8019
|
+
printCliError(e, "Failed to fetch wallet balance.");
|
|
7761
8020
|
}
|
|
7762
8021
|
}
|
|
7763
8022
|
|
|
7764
8023
|
// bin/bind.ts
|
|
7765
8024
|
var import_path9 = __toESM(require("path"));
|
|
7766
|
-
var
|
|
8025
|
+
var import_chalk17 = __toESM(require("chalk"));
|
|
7767
8026
|
var import_inquirer7 = __toESM(require("inquirer"));
|
|
7768
8027
|
init_pinmeApi();
|
|
8028
|
+
init_cliError();
|
|
8029
|
+
init_config();
|
|
7769
8030
|
init_webLogin();
|
|
7770
8031
|
function parseArgs() {
|
|
7771
8032
|
const args = process.argv.slice(2);
|
|
@@ -7787,20 +8048,20 @@ function parseArgs() {
|
|
|
7787
8048
|
}
|
|
7788
8049
|
async function checkWalletBalanceStatus2(authConfig) {
|
|
7789
8050
|
var _a2;
|
|
7790
|
-
console.log(
|
|
8051
|
+
console.log(import_chalk17.default.blue("Checking wallet balance..."));
|
|
7791
8052
|
try {
|
|
7792
8053
|
const balanceResult = await getWalletBalance(authConfig.address, authConfig.token);
|
|
7793
8054
|
const balance = Number(((_a2 = balanceResult.data) == null ? void 0 : _a2.wallet_balance_usd) ?? 0);
|
|
7794
8055
|
if (!Number.isFinite(balance) || balance <= 0) {
|
|
7795
8056
|
return false;
|
|
7796
8057
|
}
|
|
7797
|
-
console.log(
|
|
8058
|
+
console.log(import_chalk17.default.green(`Wallet balance available: $${balance.toFixed(2)}`));
|
|
7798
8059
|
return true;
|
|
7799
8060
|
} catch (e) {
|
|
7800
|
-
if (e.message === "Token expired") {
|
|
8061
|
+
if (e.message === "Token expired" || (e == null ? void 0 : e.name) === "CliError") {
|
|
7801
8062
|
throw e;
|
|
7802
8063
|
}
|
|
7803
|
-
console.log(
|
|
8064
|
+
console.log(import_chalk17.default.yellow("Failed to check wallet balance, continuing..."));
|
|
7804
8065
|
return true;
|
|
7805
8066
|
}
|
|
7806
8067
|
}
|
|
@@ -7810,7 +8071,7 @@ async function bindCmd() {
|
|
|
7810
8071
|
let { domain, targetPath, dns } = parseArgs();
|
|
7811
8072
|
const authConfig = getAuthConfig();
|
|
7812
8073
|
if (!authConfig) {
|
|
7813
|
-
console.log(
|
|
8074
|
+
console.log(import_chalk17.default.red("Please login first. Run: pinme set-appkey <AppKey>"));
|
|
7814
8075
|
return;
|
|
7815
8076
|
}
|
|
7816
8077
|
if (!targetPath) {
|
|
@@ -7826,7 +8087,7 @@ async function bindCmd() {
|
|
|
7826
8087
|
domain = (_a2 = ans.domain) == null ? void 0 : _a2.trim();
|
|
7827
8088
|
}
|
|
7828
8089
|
if (!targetPath || !domain) {
|
|
7829
|
-
console.log(
|
|
8090
|
+
console.log(import_chalk17.default.red("Missing parameters. Path and domain are required."));
|
|
7830
8091
|
return;
|
|
7831
8092
|
}
|
|
7832
8093
|
const isDns = dns || isDnsDomain(domain);
|
|
@@ -7834,14 +8095,15 @@ async function bindCmd() {
|
|
|
7834
8095
|
if (isDns) {
|
|
7835
8096
|
const validation = validateDnsDomain(domain);
|
|
7836
8097
|
if (!validation.valid) {
|
|
7837
|
-
console.log(
|
|
8098
|
+
console.log(import_chalk17.default.red(validation.message));
|
|
7838
8099
|
return;
|
|
7839
8100
|
}
|
|
7840
8101
|
}
|
|
7841
8102
|
try {
|
|
7842
8103
|
const hasWalletBalance = await checkWalletBalanceStatus2(authConfig);
|
|
7843
8104
|
if (!hasWalletBalance) {
|
|
7844
|
-
console.log(
|
|
8105
|
+
console.log(import_chalk17.default.red("Insufficient wallet balance. Please recharge your wallet first."));
|
|
8106
|
+
console.log(import_chalk17.default.cyan(`Recharge URL: ${getWalletRechargeUrl()}`));
|
|
7845
8107
|
return;
|
|
7846
8108
|
}
|
|
7847
8109
|
} catch (e) {
|
|
@@ -7853,10 +8115,10 @@ async function bindCmd() {
|
|
|
7853
8115
|
try {
|
|
7854
8116
|
const check = await checkDomainAvailable(displayDomain);
|
|
7855
8117
|
if (!check.is_valid) {
|
|
7856
|
-
console.log(
|
|
8118
|
+
console.log(import_chalk17.default.red(`Domain not available: ${check.error || "unknown reason"}`));
|
|
7857
8119
|
return;
|
|
7858
8120
|
}
|
|
7859
|
-
console.log(
|
|
8121
|
+
console.log(import_chalk17.default.green(`Domain available: ${displayDomain}`));
|
|
7860
8122
|
} catch (e) {
|
|
7861
8123
|
if (e.message === "Token expired") {
|
|
7862
8124
|
return;
|
|
@@ -7864,34 +8126,34 @@ async function bindCmd() {
|
|
|
7864
8126
|
throw e;
|
|
7865
8127
|
}
|
|
7866
8128
|
const absolutePath = import_path9.default.resolve(targetPath);
|
|
7867
|
-
console.log(
|
|
8129
|
+
console.log(import_chalk17.default.blue(`Uploading: ${absolutePath}`));
|
|
7868
8130
|
const up = await uploadPath(absolutePath, { uid: authConfig.address });
|
|
7869
8131
|
if (!(up == null ? void 0 : up.contentHash)) {
|
|
7870
|
-
console.log(
|
|
8132
|
+
console.log(import_chalk17.default.red("Upload failed, binding aborted."));
|
|
7871
8133
|
return;
|
|
7872
8134
|
}
|
|
7873
|
-
console.log(
|
|
8135
|
+
console.log(import_chalk17.default.green(`Upload success, CID: ${up.contentHash}`));
|
|
7874
8136
|
try {
|
|
7875
8137
|
if (isDns) {
|
|
7876
|
-
console.log(
|
|
8138
|
+
console.log(import_chalk17.default.blue("Binding DNS domain..."));
|
|
7877
8139
|
const dnsResult = await bindDnsDomainV4(displayDomain, up.contentHash, authConfig.address, authConfig.token);
|
|
7878
8140
|
if (dnsResult.code !== 200) {
|
|
7879
|
-
console.log(
|
|
8141
|
+
console.log(import_chalk17.default.red(`DNS binding failed: ${dnsResult.msg}`));
|
|
7880
8142
|
return;
|
|
7881
8143
|
}
|
|
7882
|
-
console.log(
|
|
7883
|
-
console.log(
|
|
7884
|
-
console.log(
|
|
8144
|
+
console.log(import_chalk17.default.green(`DNS bind success: ${displayDomain}`));
|
|
8145
|
+
console.log(import_chalk17.default.white(`Visit: https://${displayDomain}`));
|
|
8146
|
+
console.log(import_chalk17.default.cyan("\n\u{1F4DA} DNS Setup Guide: https://pinme.eth.limo/#/docs?id=custom-domain"));
|
|
7885
8147
|
} else {
|
|
7886
|
-
console.log(
|
|
8148
|
+
console.log(import_chalk17.default.blue("Binding Pinme subdomain..."));
|
|
7887
8149
|
const ok = await bindPinmeDomain(displayDomain, up.contentHash);
|
|
7888
8150
|
if (!ok) {
|
|
7889
|
-
console.log(
|
|
8151
|
+
console.log(import_chalk17.default.red("Binding failed. Please try again later."));
|
|
7890
8152
|
return;
|
|
7891
8153
|
}
|
|
7892
|
-
console.log(
|
|
8154
|
+
console.log(import_chalk17.default.green(`Bind success: ${displayDomain}`));
|
|
7893
8155
|
const rootDomain = await getRootDomain();
|
|
7894
|
-
console.log(
|
|
8156
|
+
console.log(import_chalk17.default.white(`Visit: https://${displayDomain}.${rootDomain}`));
|
|
7895
8157
|
}
|
|
7896
8158
|
} catch (e) {
|
|
7897
8159
|
if (e.message === "Token expired") {
|
|
@@ -7900,12 +8162,12 @@ async function bindCmd() {
|
|
|
7900
8162
|
throw e;
|
|
7901
8163
|
}
|
|
7902
8164
|
} catch (e) {
|
|
7903
|
-
|
|
8165
|
+
printCliError(e, "Bind failed.");
|
|
7904
8166
|
}
|
|
7905
8167
|
}
|
|
7906
8168
|
|
|
7907
8169
|
// bin/login.ts
|
|
7908
|
-
var
|
|
8170
|
+
var import_chalk18 = __toESM(require("chalk"));
|
|
7909
8171
|
init_webLogin();
|
|
7910
8172
|
init_pinmeApi();
|
|
7911
8173
|
var ENV_URLS = {
|
|
@@ -7919,27 +8181,27 @@ async function loginCmd(options = {}) {
|
|
|
7919
8181
|
const env = (options.env || "prod").toLowerCase();
|
|
7920
8182
|
if (ENV_URLS[env]) {
|
|
7921
8183
|
webBaseUrl = ENV_URLS[env];
|
|
7922
|
-
console.log(
|
|
8184
|
+
console.log(import_chalk18.default.blue(`Using ${env} environment: ${webBaseUrl}`));
|
|
7923
8185
|
} else {
|
|
7924
8186
|
console.log(
|
|
7925
|
-
|
|
8187
|
+
import_chalk18.default.yellow(
|
|
7926
8188
|
`Unknown environment: ${options.env}. Using default prod.`
|
|
7927
8189
|
)
|
|
7928
8190
|
);
|
|
7929
8191
|
webBaseUrl = ENV_URLS.prod;
|
|
7930
|
-
console.log(
|
|
8192
|
+
console.log(import_chalk18.default.blue(`Using prod environment: ${webBaseUrl}`));
|
|
7931
8193
|
}
|
|
7932
8194
|
const manager = new WebLoginManager({ webBaseUrl });
|
|
7933
8195
|
await manager.login();
|
|
7934
|
-
console.log(
|
|
8196
|
+
console.log(import_chalk18.default.blue("\nMerging history..."));
|
|
7935
8197
|
const deviceId = getDeviceId();
|
|
7936
8198
|
const ok = await bindAnonymousDevice(deviceId);
|
|
7937
8199
|
if (ok) {
|
|
7938
|
-
console.log(
|
|
8200
|
+
console.log(import_chalk18.default.green("History merged to your account"));
|
|
7939
8201
|
}
|
|
7940
8202
|
process.exit(0);
|
|
7941
8203
|
} catch (e) {
|
|
7942
|
-
console.log(
|
|
8204
|
+
console.log(import_chalk18.default.red(`
|
|
7943
8205
|
Login failed: ${(e == null ? void 0 : e.message) || e}`));
|
|
7944
8206
|
process.exit(1);
|
|
7945
8207
|
}
|
|
@@ -7958,7 +8220,7 @@ init_webLogin();
|
|
|
7958
8220
|
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
7959
8221
|
var import_os4 = __toESM(require("os"));
|
|
7960
8222
|
var import_path10 = __toESM(require("path"));
|
|
7961
|
-
var
|
|
8223
|
+
var import_chalk19 = __toESM(require("chalk"));
|
|
7962
8224
|
var import_child_process2 = require("child_process");
|
|
7963
8225
|
function makeTempCacheDir() {
|
|
7964
8226
|
return import_fs_extra5.default.mkdtempSync(import_path10.default.join(import_os4.default.tmpdir(), "pinme-npm-cache-"));
|
|
@@ -7981,7 +8243,7 @@ function installProjectDependencies(cwd) {
|
|
|
7981
8243
|
const cacheDir = makeTempCacheDir();
|
|
7982
8244
|
try {
|
|
7983
8245
|
if (attempt > 1) {
|
|
7984
|
-
console.log(
|
|
8246
|
+
console.log(import_chalk19.default.yellow(" Retrying dependency install with a fresh npm cache..."));
|
|
7985
8247
|
}
|
|
7986
8248
|
runInstall(cwd, cacheDir);
|
|
7987
8249
|
return;
|
|
@@ -7994,155 +8256,8 @@ function installProjectDependencies(cwd) {
|
|
|
7994
8256
|
throw lastError;
|
|
7995
8257
|
}
|
|
7996
8258
|
|
|
7997
|
-
// bin/utils/cliError.ts
|
|
7998
|
-
var import_chalk19 = __toESM(require("chalk"));
|
|
7999
|
-
var CliError = class extends Error {
|
|
8000
|
-
stage;
|
|
8001
|
-
details;
|
|
8002
|
-
suggestions;
|
|
8003
|
-
cause;
|
|
8004
|
-
constructor(options) {
|
|
8005
|
-
super(options.summary);
|
|
8006
|
-
this.name = "CliError";
|
|
8007
|
-
this.stage = options.stage;
|
|
8008
|
-
this.details = options.details || [];
|
|
8009
|
-
this.suggestions = options.suggestions || [];
|
|
8010
|
-
this.cause = options.cause;
|
|
8011
|
-
}
|
|
8012
|
-
};
|
|
8013
|
-
function stringifyValue(value) {
|
|
8014
|
-
if (value === void 0 || value === null) {
|
|
8015
|
-
return "";
|
|
8016
|
-
}
|
|
8017
|
-
if (typeof value === "string") {
|
|
8018
|
-
return value;
|
|
8019
|
-
}
|
|
8020
|
-
try {
|
|
8021
|
-
return JSON.stringify(value);
|
|
8022
|
-
} catch (error) {
|
|
8023
|
-
return String(value);
|
|
8024
|
-
}
|
|
8025
|
-
}
|
|
8026
|
-
function getApiMessage(data) {
|
|
8027
|
-
var _a2, _b, _c;
|
|
8028
|
-
return ((_a2 = data == null ? void 0 : data.data) == null ? void 0 : _a2.error) || ((_c = (_b = data == null ? void 0 : data.errors) == null ? void 0 : _b[0]) == null ? void 0 : _c.message) || (data == null ? void 0 : data.message) || (data == null ? void 0 : data.msg) || (data == null ? void 0 : data.error);
|
|
8029
|
-
}
|
|
8030
|
-
function getBusinessCode(data) {
|
|
8031
|
-
if ((data == null ? void 0 : data.code) === void 0 || (data == null ? void 0 : data.code) === null) {
|
|
8032
|
-
return void 0;
|
|
8033
|
-
}
|
|
8034
|
-
return String(data.code);
|
|
8035
|
-
}
|
|
8036
|
-
function getBusinessMessage(data) {
|
|
8037
|
-
if (!(data == null ? void 0 : data.msg)) {
|
|
8038
|
-
return void 0;
|
|
8039
|
-
}
|
|
8040
|
-
return String(data.msg);
|
|
8041
|
-
}
|
|
8042
|
-
function dedupeSuggestions(suggestions) {
|
|
8043
|
-
return Array.from(new Set(suggestions.filter(Boolean)));
|
|
8044
|
-
}
|
|
8045
|
-
function createConfigError(summary, suggestions = []) {
|
|
8046
|
-
return new CliError({
|
|
8047
|
-
summary,
|
|
8048
|
-
stage: "configuration",
|
|
8049
|
-
suggestions
|
|
8050
|
-
});
|
|
8051
|
-
}
|
|
8052
|
-
function createCommandError(stage, command, error, suggestions = []) {
|
|
8053
|
-
const exitCode = (error == null ? void 0 : error.status) ?? (error == null ? void 0 : error.code);
|
|
8054
|
-
const signal = error == null ? void 0 : error.signal;
|
|
8055
|
-
const detailLines = [`Command: ${command}`];
|
|
8056
|
-
if (exitCode !== void 0) {
|
|
8057
|
-
detailLines.push(`Exit code: ${exitCode}`);
|
|
8058
|
-
}
|
|
8059
|
-
if (signal) {
|
|
8060
|
-
detailLines.push(`Signal: ${signal}`);
|
|
8061
|
-
}
|
|
8062
|
-
if (error == null ? void 0 : error.message) {
|
|
8063
|
-
detailLines.push(`Reason: ${error.message}`);
|
|
8064
|
-
}
|
|
8065
|
-
return new CliError({
|
|
8066
|
-
summary: `${stage} failed.`,
|
|
8067
|
-
stage,
|
|
8068
|
-
details: detailLines,
|
|
8069
|
-
suggestions,
|
|
8070
|
-
cause: error
|
|
8071
|
-
});
|
|
8072
|
-
}
|
|
8073
|
-
function createApiError(stage, error, context = [], suggestions = []) {
|
|
8074
|
-
var _a2, _b;
|
|
8075
|
-
const status = (_a2 = error == null ? void 0 : error.response) == null ? void 0 : _a2.status;
|
|
8076
|
-
const responseData = (_b = error == null ? void 0 : error.response) == null ? void 0 : _b.data;
|
|
8077
|
-
const errorCode = error == null ? void 0 : error.code;
|
|
8078
|
-
const apiMessage = getApiMessage(responseData);
|
|
8079
|
-
const businessCode = getBusinessCode(responseData);
|
|
8080
|
-
const businessMessage = getBusinessMessage(responseData);
|
|
8081
|
-
const summary = apiMessage || (error == null ? void 0 : error.message) || `${stage} failed.`;
|
|
8082
|
-
const detailLines = [...context];
|
|
8083
|
-
if (status) {
|
|
8084
|
-
detailLines.push(`HTTP status: ${status}`);
|
|
8085
|
-
}
|
|
8086
|
-
if (businessCode) {
|
|
8087
|
-
detailLines.push(`Business code: ${businessCode}`);
|
|
8088
|
-
}
|
|
8089
|
-
if (businessMessage && businessMessage !== apiMessage) {
|
|
8090
|
-
detailLines.push(`Business message: ${businessMessage}`);
|
|
8091
|
-
}
|
|
8092
|
-
if (apiMessage && apiMessage !== summary) {
|
|
8093
|
-
detailLines.push(`Error message: ${apiMessage}`);
|
|
8094
|
-
}
|
|
8095
|
-
if (errorCode && errorCode !== "ERR_BAD_REQUEST" && !responseData) {
|
|
8096
|
-
detailLines.push(`Error code: ${errorCode}`);
|
|
8097
|
-
}
|
|
8098
|
-
if (!responseData && (error == null ? void 0 : error.message) && error.message !== apiMessage) {
|
|
8099
|
-
detailLines.push(`Reason: ${error.message}`);
|
|
8100
|
-
}
|
|
8101
|
-
return new CliError({
|
|
8102
|
-
summary,
|
|
8103
|
-
stage,
|
|
8104
|
-
details: detailLines,
|
|
8105
|
-
suggestions: dedupeSuggestions(suggestions),
|
|
8106
|
-
cause: error
|
|
8107
|
-
});
|
|
8108
|
-
}
|
|
8109
|
-
function normalizeCliError(error, fallbackSummary, suggestions = []) {
|
|
8110
|
-
if (error instanceof CliError) {
|
|
8111
|
-
return error;
|
|
8112
|
-
}
|
|
8113
|
-
if (error instanceof Error) {
|
|
8114
|
-
return new CliError({
|
|
8115
|
-
summary: error.message || fallbackSummary,
|
|
8116
|
-
suggestions: dedupeSuggestions(suggestions),
|
|
8117
|
-
cause: error
|
|
8118
|
-
});
|
|
8119
|
-
}
|
|
8120
|
-
return new CliError({
|
|
8121
|
-
summary: fallbackSummary,
|
|
8122
|
-
details: [`Raw error: ${stringifyValue(error)}`],
|
|
8123
|
-
suggestions: dedupeSuggestions(suggestions),
|
|
8124
|
-
cause: error
|
|
8125
|
-
});
|
|
8126
|
-
}
|
|
8127
|
-
function printCliError(error, fallbackSummary) {
|
|
8128
|
-
const cliError = normalizeCliError(error, fallbackSummary);
|
|
8129
|
-
console.error(import_chalk19.default.red(`
|
|
8130
|
-
Error: ${cliError.message}`));
|
|
8131
|
-
if (cliError.stage) {
|
|
8132
|
-
console.error(import_chalk19.default.gray(`Stage: ${cliError.stage}`));
|
|
8133
|
-
}
|
|
8134
|
-
for (const detail of cliError.details) {
|
|
8135
|
-
console.error(import_chalk19.default.gray(detail));
|
|
8136
|
-
}
|
|
8137
|
-
if (cliError.suggestions.length > 0) {
|
|
8138
|
-
console.error(import_chalk19.default.yellow("\nNext steps:"));
|
|
8139
|
-
for (const suggestion of cliError.suggestions) {
|
|
8140
|
-
console.error(import_chalk19.default.yellow(`- ${suggestion}`));
|
|
8141
|
-
}
|
|
8142
|
-
}
|
|
8143
|
-
}
|
|
8144
|
-
|
|
8145
8259
|
// bin/create.ts
|
|
8260
|
+
init_cliError();
|
|
8146
8261
|
init_config();
|
|
8147
8262
|
var PROJECT_DIR = process.cwd();
|
|
8148
8263
|
var TEMPLATE_BRANCH = "feat/auth";
|
|
@@ -8601,6 +8716,7 @@ init_axios2();
|
|
|
8601
8716
|
var import_child_process4 = require("child_process");
|
|
8602
8717
|
init_webLogin();
|
|
8603
8718
|
init_pinmeApi();
|
|
8719
|
+
init_cliError();
|
|
8604
8720
|
init_config();
|
|
8605
8721
|
var PROJECT_DIR2 = process.cwd();
|
|
8606
8722
|
function loadConfig() {
|
|
@@ -8931,6 +9047,7 @@ var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
|
8931
9047
|
var import_path13 = __toESM(require("path"));
|
|
8932
9048
|
init_axios2();
|
|
8933
9049
|
init_webLogin();
|
|
9050
|
+
init_cliError();
|
|
8934
9051
|
init_config();
|
|
8935
9052
|
var PROJECT_DIR3 = process.cwd();
|
|
8936
9053
|
function loadConfig2() {
|
|
@@ -9064,6 +9181,7 @@ var import_path14 = __toESM(require("path"));
|
|
|
9064
9181
|
init_axios2();
|
|
9065
9182
|
var import_child_process5 = require("child_process");
|
|
9066
9183
|
init_webLogin();
|
|
9184
|
+
init_cliError();
|
|
9067
9185
|
init_config();
|
|
9068
9186
|
var PROJECT_DIR4 = process.cwd();
|
|
9069
9187
|
function loadConfig3() {
|
|
@@ -9246,6 +9364,7 @@ var import_fs_extra10 = __toESM(require("fs-extra"));
|
|
|
9246
9364
|
var import_path15 = __toESM(require("path"));
|
|
9247
9365
|
var import_child_process6 = require("child_process");
|
|
9248
9366
|
init_webLogin();
|
|
9367
|
+
init_cliError();
|
|
9249
9368
|
init_config();
|
|
9250
9369
|
var PROJECT_DIR5 = process.cwd();
|
|
9251
9370
|
function loadConfig4() {
|