pinme 2.0.2-beta.12 → 2.0.2-beta.13
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 +462 -379
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4724,6 +4724,182 @@ var init_axios2 = __esm({
|
|
|
4724
4724
|
}
|
|
4725
4725
|
});
|
|
4726
4726
|
|
|
4727
|
+
// bin/utils/cliError.ts
|
|
4728
|
+
function stringifyValue(value) {
|
|
4729
|
+
if (value === void 0 || value === null) {
|
|
4730
|
+
return "";
|
|
4731
|
+
}
|
|
4732
|
+
if (typeof value === "string") {
|
|
4733
|
+
return value;
|
|
4734
|
+
}
|
|
4735
|
+
try {
|
|
4736
|
+
return JSON.stringify(value);
|
|
4737
|
+
} catch (error) {
|
|
4738
|
+
return String(value);
|
|
4739
|
+
}
|
|
4740
|
+
}
|
|
4741
|
+
function getApiMessage(data) {
|
|
4742
|
+
var _a2, _b, _c, _d, _e;
|
|
4743
|
+
if (typeof data === "string") {
|
|
4744
|
+
return data;
|
|
4745
|
+
}
|
|
4746
|
+
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);
|
|
4747
|
+
}
|
|
4748
|
+
function getApiDetailMessage(data) {
|
|
4749
|
+
var _a2, _b, _c, _d, _e;
|
|
4750
|
+
if (typeof data === "string") {
|
|
4751
|
+
return data;
|
|
4752
|
+
}
|
|
4753
|
+
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);
|
|
4754
|
+
}
|
|
4755
|
+
function getBusinessCode(data) {
|
|
4756
|
+
if ((data == null ? void 0 : data.code) === void 0 || (data == null ? void 0 : data.code) === null) {
|
|
4757
|
+
return void 0;
|
|
4758
|
+
}
|
|
4759
|
+
return String(data.code);
|
|
4760
|
+
}
|
|
4761
|
+
function getBusinessMessage(data) {
|
|
4762
|
+
if (!(data == null ? void 0 : data.msg)) {
|
|
4763
|
+
return void 0;
|
|
4764
|
+
}
|
|
4765
|
+
return String(data.msg);
|
|
4766
|
+
}
|
|
4767
|
+
function dedupeSuggestions(suggestions) {
|
|
4768
|
+
return Array.from(new Set(suggestions.filter(Boolean)));
|
|
4769
|
+
}
|
|
4770
|
+
function createConfigError(summary, suggestions = []) {
|
|
4771
|
+
return new CliError({
|
|
4772
|
+
summary,
|
|
4773
|
+
stage: "configuration",
|
|
4774
|
+
suggestions
|
|
4775
|
+
});
|
|
4776
|
+
}
|
|
4777
|
+
function createCommandError(stage, command, error, suggestions = []) {
|
|
4778
|
+
const exitCode = (error == null ? void 0 : error.status) ?? (error == null ? void 0 : error.code);
|
|
4779
|
+
const signal = error == null ? void 0 : error.signal;
|
|
4780
|
+
const detailLines = [`Command: ${command}`];
|
|
4781
|
+
if (exitCode !== void 0) {
|
|
4782
|
+
detailLines.push(`Exit code: ${exitCode}`);
|
|
4783
|
+
}
|
|
4784
|
+
if (signal) {
|
|
4785
|
+
detailLines.push(`Signal: ${signal}`);
|
|
4786
|
+
}
|
|
4787
|
+
if (error == null ? void 0 : error.message) {
|
|
4788
|
+
detailLines.push(`Reason: ${error.message}`);
|
|
4789
|
+
}
|
|
4790
|
+
return new CliError({
|
|
4791
|
+
summary: `${stage} failed.`,
|
|
4792
|
+
stage,
|
|
4793
|
+
details: detailLines,
|
|
4794
|
+
suggestions,
|
|
4795
|
+
cause: error
|
|
4796
|
+
});
|
|
4797
|
+
}
|
|
4798
|
+
function createApiError(stage, error, context = [], suggestions = []) {
|
|
4799
|
+
var _a2, _b;
|
|
4800
|
+
const status = (_a2 = error == null ? void 0 : error.response) == null ? void 0 : _a2.status;
|
|
4801
|
+
const responseData = (_b = error == null ? void 0 : error.response) == null ? void 0 : _b.data;
|
|
4802
|
+
const errorCode = error == null ? void 0 : error.code;
|
|
4803
|
+
const rawMessage = error == null ? void 0 : error.message;
|
|
4804
|
+
const apiMessage = getApiMessage(responseData);
|
|
4805
|
+
const apiDetailMessage = getApiDetailMessage(responseData);
|
|
4806
|
+
const businessCode = getBusinessCode(responseData);
|
|
4807
|
+
const businessMessage = getBusinessMessage(responseData);
|
|
4808
|
+
const summary = apiMessage || businessMessage || apiDetailMessage || rawMessage || `${stage} failed.`;
|
|
4809
|
+
const detailLines = [...context];
|
|
4810
|
+
const hasBusinessError = Boolean(businessCode);
|
|
4811
|
+
if (businessCode) {
|
|
4812
|
+
detailLines.push(`Business code: ${businessCode}`);
|
|
4813
|
+
}
|
|
4814
|
+
if (status && !hasBusinessError) {
|
|
4815
|
+
detailLines.push(`HTTP status: ${status}`);
|
|
4816
|
+
}
|
|
4817
|
+
if (businessMessage && businessMessage !== summary) {
|
|
4818
|
+
detailLines.push(`Business message: ${businessMessage}`);
|
|
4819
|
+
}
|
|
4820
|
+
if (apiDetailMessage && apiDetailMessage !== summary && apiDetailMessage !== businessMessage) {
|
|
4821
|
+
detailLines.push(`Error detail: ${apiDetailMessage}`);
|
|
4822
|
+
}
|
|
4823
|
+
if (apiMessage && apiMessage !== summary && apiMessage !== apiDetailMessage) {
|
|
4824
|
+
detailLines.push(`Error message: ${apiMessage}`);
|
|
4825
|
+
}
|
|
4826
|
+
if (errorCode && errorCode !== "ERR_BAD_REQUEST" && !responseData) {
|
|
4827
|
+
detailLines.push(`Error code: ${errorCode}`);
|
|
4828
|
+
}
|
|
4829
|
+
const isGenericAxiosStatusMessage = typeof rawMessage === "string" && /^Request failed with status code \d{3}$/.test(rawMessage);
|
|
4830
|
+
if (rawMessage && rawMessage !== summary && !(responseData && isGenericAxiosStatusMessage)) {
|
|
4831
|
+
detailLines.push(`Reason: ${rawMessage}`);
|
|
4832
|
+
}
|
|
4833
|
+
return new CliError({
|
|
4834
|
+
summary,
|
|
4835
|
+
stage,
|
|
4836
|
+
details: detailLines,
|
|
4837
|
+
suggestions: dedupeSuggestions(suggestions),
|
|
4838
|
+
cause: error
|
|
4839
|
+
});
|
|
4840
|
+
}
|
|
4841
|
+
function normalizeCliError(error, fallbackSummary, suggestions = []) {
|
|
4842
|
+
if (error instanceof CliError) {
|
|
4843
|
+
return error;
|
|
4844
|
+
}
|
|
4845
|
+
if (typeof error === "object" && error !== null) {
|
|
4846
|
+
const maybeApiError = error;
|
|
4847
|
+
if (maybeApiError.response || maybeApiError.config) {
|
|
4848
|
+
return createApiError("API request", maybeApiError, [], suggestions);
|
|
4849
|
+
}
|
|
4850
|
+
}
|
|
4851
|
+
if (error instanceof Error) {
|
|
4852
|
+
return new CliError({
|
|
4853
|
+
summary: error.message || fallbackSummary,
|
|
4854
|
+
suggestions: dedupeSuggestions(suggestions),
|
|
4855
|
+
cause: error
|
|
4856
|
+
});
|
|
4857
|
+
}
|
|
4858
|
+
return new CliError({
|
|
4859
|
+
summary: fallbackSummary,
|
|
4860
|
+
details: [`Raw error: ${stringifyValue(error)}`],
|
|
4861
|
+
suggestions: dedupeSuggestions(suggestions),
|
|
4862
|
+
cause: error
|
|
4863
|
+
});
|
|
4864
|
+
}
|
|
4865
|
+
function printCliError(error, fallbackSummary) {
|
|
4866
|
+
const cliError = normalizeCliError(error, fallbackSummary);
|
|
4867
|
+
console.error(import_chalk2.default.red(`
|
|
4868
|
+
Error: ${cliError.message}`));
|
|
4869
|
+
if (cliError.stage) {
|
|
4870
|
+
console.error(import_chalk2.default.gray(`Stage: ${cliError.stage}`));
|
|
4871
|
+
}
|
|
4872
|
+
for (const detail of cliError.details) {
|
|
4873
|
+
console.error(import_chalk2.default.gray(detail));
|
|
4874
|
+
}
|
|
4875
|
+
if (cliError.suggestions.length > 0) {
|
|
4876
|
+
console.error(import_chalk2.default.yellow("\nNext steps:"));
|
|
4877
|
+
for (const suggestion of cliError.suggestions) {
|
|
4878
|
+
console.error(import_chalk2.default.yellow(`- ${suggestion}`));
|
|
4879
|
+
}
|
|
4880
|
+
}
|
|
4881
|
+
}
|
|
4882
|
+
var import_chalk2, CliError;
|
|
4883
|
+
var init_cliError = __esm({
|
|
4884
|
+
"bin/utils/cliError.ts"() {
|
|
4885
|
+
import_chalk2 = __toESM(require("chalk"));
|
|
4886
|
+
CliError = class extends Error {
|
|
4887
|
+
stage;
|
|
4888
|
+
details;
|
|
4889
|
+
suggestions;
|
|
4890
|
+
cause;
|
|
4891
|
+
constructor(options) {
|
|
4892
|
+
super(options.summary);
|
|
4893
|
+
this.name = "CliError";
|
|
4894
|
+
this.stage = options.stage;
|
|
4895
|
+
this.details = options.details || [];
|
|
4896
|
+
this.suggestions = options.suggestions || [];
|
|
4897
|
+
this.cause = options.cause;
|
|
4898
|
+
}
|
|
4899
|
+
};
|
|
4900
|
+
}
|
|
4901
|
+
});
|
|
4902
|
+
|
|
4727
4903
|
// bin/utils/config.ts
|
|
4728
4904
|
function trimTrailingSlash(value) {
|
|
4729
4905
|
return value.replace(/\/+$/, "");
|
|
@@ -4783,7 +4959,7 @@ function openBrowser(url2) {
|
|
|
4783
4959
|
}
|
|
4784
4960
|
(0, import_child_process.exec)(command, (err) => {
|
|
4785
4961
|
if (err) {
|
|
4786
|
-
console.log(
|
|
4962
|
+
console.log(import_chalk3.default.yellow(`Unable to open browser automatically. Please visit manually: ${url2}`));
|
|
4787
4963
|
}
|
|
4788
4964
|
});
|
|
4789
4965
|
}
|
|
@@ -4831,13 +5007,13 @@ function getAuthHeaders() {
|
|
|
4831
5007
|
"authentication-tokens": conf.token
|
|
4832
5008
|
};
|
|
4833
5009
|
}
|
|
4834
|
-
var import_crypto, import_http3, import_url2,
|
|
5010
|
+
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
5011
|
var init_webLogin = __esm({
|
|
4836
5012
|
"bin/utils/webLogin.ts"() {
|
|
4837
5013
|
import_crypto = __toESM(require("crypto"));
|
|
4838
5014
|
import_http3 = __toESM(require("http"));
|
|
4839
5015
|
import_url2 = require("url");
|
|
4840
|
-
|
|
5016
|
+
import_chalk3 = __toESM(require("chalk"));
|
|
4841
5017
|
import_child_process = require("child_process");
|
|
4842
5018
|
import_fs_extra = __toESM(require("fs-extra"));
|
|
4843
5019
|
import_os = __toESM(require("os"));
|
|
@@ -4861,30 +5037,30 @@ var init_webLogin = __esm({
|
|
|
4861
5037
|
this.config = { ...DEFAULT_OPTIONS, ...options };
|
|
4862
5038
|
}
|
|
4863
5039
|
async login() {
|
|
4864
|
-
console.log(
|
|
5040
|
+
console.log(import_chalk3.default.blue("Starting login flow...\n"));
|
|
4865
5041
|
this.loginToken = this.generateLoginToken();
|
|
4866
|
-
console.log(
|
|
5042
|
+
console.log(import_chalk3.default.blue("Starting local callback server..."));
|
|
4867
5043
|
await this.startCallbackServer();
|
|
4868
5044
|
try {
|
|
4869
5045
|
const loginUrl = this.buildLoginUrl();
|
|
4870
|
-
console.log(
|
|
4871
|
-
console.log(
|
|
4872
|
-
console.log(
|
|
5046
|
+
console.log(import_chalk3.default.blue("Opening browser..."));
|
|
5047
|
+
console.log(import_chalk3.default.white("If browser does not open automatically, please visit manually:"));
|
|
5048
|
+
console.log(import_chalk3.default.cyan(` ${loginUrl}
|
|
4873
5049
|
`));
|
|
4874
5050
|
openBrowser(loginUrl);
|
|
4875
|
-
console.log(
|
|
4876
|
-
console.log(
|
|
5051
|
+
console.log(import_chalk3.default.yellow("Please complete login in browser..."));
|
|
5052
|
+
console.log(import_chalk3.default.gray("Browser will close automatically after successful login.\n"));
|
|
4877
5053
|
const authToken = await this.waitForCallback();
|
|
4878
5054
|
const authConfig = this.parseAuthToken(authToken);
|
|
4879
5055
|
this.saveAuthConfig(authConfig);
|
|
4880
|
-
console.log(
|
|
5056
|
+
console.log(import_chalk3.default.green("\nLogin successful!"));
|
|
4881
5057
|
if (authConfig.email) {
|
|
4882
|
-
console.log(
|
|
5058
|
+
console.log(import_chalk3.default.green(`Welcome, ${authConfig.email}`));
|
|
4883
5059
|
}
|
|
4884
|
-
console.log(
|
|
5060
|
+
console.log(import_chalk3.default.gray(`Address: ${authConfig.address}`));
|
|
4885
5061
|
return authConfig;
|
|
4886
5062
|
} catch (error) {
|
|
4887
|
-
console.error(
|
|
5063
|
+
console.error(import_chalk3.default.red(`
|
|
4888
5064
|
Login failed: ${error.message}`));
|
|
4889
5065
|
throw error;
|
|
4890
5066
|
} finally {
|
|
@@ -4946,7 +5122,7 @@ Login failed: ${error.message}`));
|
|
|
4946
5122
|
reject(err);
|
|
4947
5123
|
});
|
|
4948
5124
|
this.server.listen(this.config.callbackPort, "127.0.0.1", () => {
|
|
4949
|
-
console.log(
|
|
5125
|
+
console.log(import_chalk3.default.gray(`Local server: http://localhost:${this.config.callbackPort}`));
|
|
4950
5126
|
resolve();
|
|
4951
5127
|
});
|
|
4952
5128
|
setTimeout(() => {
|
|
@@ -5280,6 +5456,30 @@ function safeGetAuthHeaders() {
|
|
|
5280
5456
|
return {};
|
|
5281
5457
|
}
|
|
5282
5458
|
}
|
|
5459
|
+
function hasBusinessCode(data) {
|
|
5460
|
+
return Boolean(data) && typeof data === "object" && "code" in data;
|
|
5461
|
+
}
|
|
5462
|
+
function isSuccessfulBusinessCode(code) {
|
|
5463
|
+
return String(code) === "200";
|
|
5464
|
+
}
|
|
5465
|
+
function getRequestDescriptor(config) {
|
|
5466
|
+
if (!(config == null ? void 0 : config.url)) {
|
|
5467
|
+
return void 0;
|
|
5468
|
+
}
|
|
5469
|
+
const method = (config.method || "GET").toUpperCase();
|
|
5470
|
+
return `${method} ${config.url}`;
|
|
5471
|
+
}
|
|
5472
|
+
function buildErrorContext(config) {
|
|
5473
|
+
const descriptor = getRequestDescriptor(config);
|
|
5474
|
+
return descriptor ? [`Request: ${descriptor}`] : [];
|
|
5475
|
+
}
|
|
5476
|
+
function normalizeBusinessError(response) {
|
|
5477
|
+
throw createApiError(
|
|
5478
|
+
"API request",
|
|
5479
|
+
{ response, config: response.config },
|
|
5480
|
+
buildErrorContext(response.config)
|
|
5481
|
+
);
|
|
5482
|
+
}
|
|
5283
5483
|
function createApiClient(options = {}) {
|
|
5284
5484
|
const {
|
|
5285
5485
|
baseURL = APP_CONFIG.pinmeApiBase,
|
|
@@ -5300,8 +5500,19 @@ function createApiClient(options = {}) {
|
|
|
5300
5500
|
}
|
|
5301
5501
|
});
|
|
5302
5502
|
client.interceptors.response.use(
|
|
5303
|
-
(response) =>
|
|
5304
|
-
|
|
5503
|
+
(response) => {
|
|
5504
|
+
if (hasBusinessCode(response.data) && !isSuccessfulBusinessCode(response.data.code)) {
|
|
5505
|
+
normalizeBusinessError(response);
|
|
5506
|
+
}
|
|
5507
|
+
return response;
|
|
5508
|
+
},
|
|
5509
|
+
(error) => Promise.reject(
|
|
5510
|
+
createApiError(
|
|
5511
|
+
"API request",
|
|
5512
|
+
error,
|
|
5513
|
+
buildErrorContext(error == null ? void 0 : error.config)
|
|
5514
|
+
)
|
|
5515
|
+
)
|
|
5305
5516
|
);
|
|
5306
5517
|
return client;
|
|
5307
5518
|
}
|
|
@@ -5320,6 +5531,7 @@ function createCarApiClient(options = {}) {
|
|
|
5320
5531
|
var init_apiClient = __esm({
|
|
5321
5532
|
"bin/utils/apiClient.ts"() {
|
|
5322
5533
|
init_axios2();
|
|
5534
|
+
init_cliError();
|
|
5323
5535
|
init_webLogin();
|
|
5324
5536
|
init_config();
|
|
5325
5537
|
}
|
|
@@ -5356,8 +5568,8 @@ function isTokenExpired(error) {
|
|
|
5356
5568
|
);
|
|
5357
5569
|
}
|
|
5358
5570
|
function showTokenExpiredHint() {
|
|
5359
|
-
console.log(
|
|
5360
|
-
console.log(
|
|
5571
|
+
console.log(import_chalk4.default.red("\n\u26A0\uFE0F Token has expired or is invalid."));
|
|
5572
|
+
console.log(import_chalk4.default.yellow("Please re-run: pinme set-appkey <AppKey>\n"));
|
|
5361
5573
|
}
|
|
5362
5574
|
async function bindAnonymousDevice(anonymousUid) {
|
|
5363
5575
|
try {
|
|
@@ -5372,7 +5584,7 @@ async function bindAnonymousDevice(anonymousUid) {
|
|
|
5372
5584
|
return false;
|
|
5373
5585
|
}
|
|
5374
5586
|
console.log(
|
|
5375
|
-
|
|
5587
|
+
import_chalk4.default.yellow(`Failed to trigger anonymous binding: ${(e == null ? void 0 : e.message) || e}`)
|
|
5376
5588
|
);
|
|
5377
5589
|
return false;
|
|
5378
5590
|
}
|
|
@@ -5391,10 +5603,11 @@ async function getRootDomain(forceRefresh = false) {
|
|
|
5391
5603
|
throw new Error((data == null ? void 0 : data.msg) || "Failed to get root domain");
|
|
5392
5604
|
}
|
|
5393
5605
|
async function checkDomainAvailable(domainName) {
|
|
5394
|
-
var _a2;
|
|
5606
|
+
var _a2, _b;
|
|
5395
5607
|
const client = createPinmeApiClient();
|
|
5396
5608
|
const configured = APP_CONFIG.pinmeCheckDomainPath;
|
|
5397
5609
|
const fallbacks = [configured, "/check_domain_available"];
|
|
5610
|
+
let lastRecoverableError;
|
|
5398
5611
|
for (const p of fallbacks) {
|
|
5399
5612
|
try {
|
|
5400
5613
|
const { data } = await client.post(p, { domain_name: domainName });
|
|
@@ -5409,8 +5622,16 @@ async function checkDomainAvailable(domainName) {
|
|
|
5409
5622
|
showTokenExpiredHint();
|
|
5410
5623
|
throw new Error("Token expired");
|
|
5411
5624
|
}
|
|
5625
|
+
const status = (_b = e == null ? void 0 : e.response) == null ? void 0 : _b.status;
|
|
5626
|
+
if (status && ![404, 405].includes(status)) {
|
|
5627
|
+
throw e;
|
|
5628
|
+
}
|
|
5629
|
+
lastRecoverableError = e;
|
|
5412
5630
|
}
|
|
5413
5631
|
}
|
|
5632
|
+
if (lastRecoverableError) {
|
|
5633
|
+
throw lastRecoverableError;
|
|
5634
|
+
}
|
|
5414
5635
|
return { is_valid: true };
|
|
5415
5636
|
}
|
|
5416
5637
|
async function bindPinmeDomain(domainName, hash, projectName) {
|
|
@@ -5573,10 +5794,10 @@ async function checkCarExportStatus(taskId) {
|
|
|
5573
5794
|
throw new Error(`Failed to check export status: ${(e == null ? void 0 : e.message) || e}`);
|
|
5574
5795
|
}
|
|
5575
5796
|
}
|
|
5576
|
-
var
|
|
5797
|
+
var import_chalk4, TOKEN_EXPIRED_CODES, TOKEN_EXPIRED_MESSAGES, rootDomainCache;
|
|
5577
5798
|
var init_pinmeApi = __esm({
|
|
5578
5799
|
"bin/utils/pinmeApi.ts"() {
|
|
5579
|
-
|
|
5800
|
+
import_chalk4 = __toESM(require("chalk"));
|
|
5580
5801
|
init_apiClient();
|
|
5581
5802
|
init_config();
|
|
5582
5803
|
TOKEN_EXPIRED_CODES = [
|
|
@@ -5648,11 +5869,11 @@ var import_chalk26 = __toESM(require("chalk"));
|
|
|
5648
5869
|
var import_figlet5 = __toESM(require("figlet"));
|
|
5649
5870
|
|
|
5650
5871
|
// package.json
|
|
5651
|
-
var version = "2.0.2-beta.
|
|
5872
|
+
var version = "2.0.2-beta.13";
|
|
5652
5873
|
|
|
5653
5874
|
// bin/upload.ts
|
|
5654
5875
|
var import_path6 = __toESM(require("path"));
|
|
5655
|
-
var
|
|
5876
|
+
var import_chalk7 = __toESM(require("chalk"));
|
|
5656
5877
|
var import_inquirer = __toESM(require("inquirer"));
|
|
5657
5878
|
var import_figlet = __toESM(require("figlet"));
|
|
5658
5879
|
var import_fs2 = __toESM(require("fs"));
|
|
@@ -5709,6 +5930,9 @@ function validateDnsDomain(domain) {
|
|
|
5709
5930
|
return { valid: true };
|
|
5710
5931
|
}
|
|
5711
5932
|
|
|
5933
|
+
// bin/upload.ts
|
|
5934
|
+
init_cliError();
|
|
5935
|
+
|
|
5712
5936
|
// bin/services/uploadService.ts
|
|
5713
5937
|
var import_crypto_js = __toESM(require("crypto-js"));
|
|
5714
5938
|
|
|
@@ -5794,7 +6018,7 @@ var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
|
5794
6018
|
var import_path4 = __toESM(require("path"));
|
|
5795
6019
|
var import_os3 = __toESM(require("os"));
|
|
5796
6020
|
var import_dayjs = __toESM(require("dayjs"));
|
|
5797
|
-
var
|
|
6021
|
+
var import_chalk5 = __toESM(require("chalk"));
|
|
5798
6022
|
init_pinmeApi();
|
|
5799
6023
|
var HISTORY_DIR = import_path4.default.join(import_os3.default.homedir(), ".pinme");
|
|
5800
6024
|
var HISTORY_FILE = import_path4.default.join(HISTORY_DIR, "upload-history.json");
|
|
@@ -5828,7 +6052,7 @@ var saveUploadHistory = (uploadData) => {
|
|
|
5828
6052
|
import_fs_extra3.default.writeJsonSync(HISTORY_FILE, history, { spaces: 2 });
|
|
5829
6053
|
return true;
|
|
5830
6054
|
} catch (error) {
|
|
5831
|
-
console.error(
|
|
6055
|
+
console.error(import_chalk5.default.red(`Error saving upload history: ${error.message}`));
|
|
5832
6056
|
return false;
|
|
5833
6057
|
}
|
|
5834
6058
|
};
|
|
@@ -5838,7 +6062,7 @@ var getUploadHistory = (limit = 10) => {
|
|
|
5838
6062
|
const history = import_fs_extra3.default.readJsonSync(HISTORY_FILE);
|
|
5839
6063
|
return history.uploads.slice(0, limit);
|
|
5840
6064
|
} catch (error) {
|
|
5841
|
-
console.error(
|
|
6065
|
+
console.error(import_chalk5.default.red(`Error reading upload history: ${error.message}`));
|
|
5842
6066
|
return [];
|
|
5843
6067
|
}
|
|
5844
6068
|
};
|
|
@@ -5875,11 +6099,11 @@ async function formatHistoryUrl(value, options) {
|
|
|
5875
6099
|
var displayUploadHistory = async (limit = 10) => {
|
|
5876
6100
|
const history = getUploadHistory(limit);
|
|
5877
6101
|
if (history.length === 0) {
|
|
5878
|
-
console.log(
|
|
6102
|
+
console.log(import_chalk5.default.yellow("No upload history found."));
|
|
5879
6103
|
return;
|
|
5880
6104
|
}
|
|
5881
|
-
console.log(
|
|
5882
|
-
console.log(
|
|
6105
|
+
console.log(import_chalk5.default.cyan("Upload History:"));
|
|
6106
|
+
console.log(import_chalk5.default.cyan("-".repeat(80)));
|
|
5883
6107
|
let rootDomain = null;
|
|
5884
6108
|
try {
|
|
5885
6109
|
rootDomain = await getRootDomain();
|
|
@@ -5888,9 +6112,9 @@ var displayUploadHistory = async (limit = 10) => {
|
|
|
5888
6112
|
}
|
|
5889
6113
|
const recentHistory = history.slice(-limit);
|
|
5890
6114
|
for (const [index, item] of recentHistory.entries()) {
|
|
5891
|
-
console.log(
|
|
5892
|
-
console.log(
|
|
5893
|
-
console.log(
|
|
6115
|
+
console.log(import_chalk5.default.green(`${index + 1}. ${item.filename}`));
|
|
6116
|
+
console.log(import_chalk5.default.white(` Path: ${item.path}`));
|
|
6117
|
+
console.log(import_chalk5.default.white(` IPFS CID: ${item.contentHash}`));
|
|
5894
6118
|
const preferredUrl = await formatHistoryUrl(item.dnsUrl) || await formatHistoryUrl(item.pinmeUrl, {
|
|
5895
6119
|
appendRootDomain: true,
|
|
5896
6120
|
rootDomain
|
|
@@ -5899,30 +6123,30 @@ var displayUploadHistory = async (limit = 10) => {
|
|
|
5899
6123
|
rootDomain
|
|
5900
6124
|
});
|
|
5901
6125
|
if (preferredUrl) {
|
|
5902
|
-
console.log(
|
|
6126
|
+
console.log(import_chalk5.default.white(` URL: ${preferredUrl}`));
|
|
5903
6127
|
}
|
|
5904
|
-
console.log(
|
|
5905
|
-
console.log(
|
|
5906
|
-
console.log(
|
|
6128
|
+
console.log(import_chalk5.default.white(` Size: ${formatSize(item.size)}`));
|
|
6129
|
+
console.log(import_chalk5.default.white(` Files: ${item.fileCount}`));
|
|
6130
|
+
console.log(import_chalk5.default.white(` Type: ${item.type === "directory" ? "Directory" : "File"}`));
|
|
5907
6131
|
if (item.timestamp) {
|
|
5908
|
-
console.log(
|
|
6132
|
+
console.log(import_chalk5.default.white(` Date: ${new Date(item.timestamp).toLocaleString()}`));
|
|
5909
6133
|
}
|
|
5910
|
-
console.log(
|
|
6134
|
+
console.log(import_chalk5.default.cyan("-".repeat(80)));
|
|
5911
6135
|
}
|
|
5912
6136
|
const totalSize = history.reduce((sum, record) => sum + record.size, 0);
|
|
5913
6137
|
const totalFiles = history.reduce((sum, record) => sum + record.fileCount, 0);
|
|
5914
|
-
console.log(
|
|
5915
|
-
console.log(
|
|
5916
|
-
console.log(
|
|
6138
|
+
console.log(import_chalk5.default.bold(`Total Uploads: ${history.length}`));
|
|
6139
|
+
console.log(import_chalk5.default.bold(`Total Files: ${totalFiles}`));
|
|
6140
|
+
console.log(import_chalk5.default.bold(`Total Size: ${formatSize(totalSize)}`));
|
|
5917
6141
|
};
|
|
5918
6142
|
var clearUploadHistory = () => {
|
|
5919
6143
|
try {
|
|
5920
6144
|
ensureHistoryDir();
|
|
5921
6145
|
import_fs_extra3.default.writeJsonSync(HISTORY_FILE, { uploads: [] });
|
|
5922
|
-
console.log(
|
|
6146
|
+
console.log(import_chalk5.default.green("Upload history cleared successfully."));
|
|
5923
6147
|
return true;
|
|
5924
6148
|
} catch (error) {
|
|
5925
|
-
console.error(
|
|
6149
|
+
console.error(import_chalk5.default.red(`Error clearing upload history: ${error.message}`));
|
|
5926
6150
|
return false;
|
|
5927
6151
|
}
|
|
5928
6152
|
};
|
|
@@ -6669,12 +6893,12 @@ async function uploadPath(targetPath, options = {}) {
|
|
|
6669
6893
|
}
|
|
6670
6894
|
|
|
6671
6895
|
// bin/utils/urlDisplay.ts
|
|
6672
|
-
var
|
|
6896
|
+
var import_chalk6 = __toESM(require("chalk"));
|
|
6673
6897
|
function printHighlightedUrl(label, url2, tone = "primary") {
|
|
6674
6898
|
const safeLabel = label.trim() || "URL";
|
|
6675
6899
|
const safeUrl = url2.trim();
|
|
6676
|
-
const labelStyle =
|
|
6677
|
-
const urlStyle = tone === "management" ?
|
|
6900
|
+
const labelStyle = import_chalk6.default.black.bgWhiteBright.bold;
|
|
6901
|
+
const urlStyle = tone === "management" ? import_chalk6.default.blueBright.bold.underline : import_chalk6.default.cyanBright.bold;
|
|
6678
6902
|
console.log("");
|
|
6679
6903
|
console.log(labelStyle(` ${safeLabel} `));
|
|
6680
6904
|
console.log(urlStyle(safeUrl));
|
|
@@ -6691,7 +6915,7 @@ function checkPathSync(inputPath) {
|
|
|
6691
6915
|
}
|
|
6692
6916
|
return null;
|
|
6693
6917
|
} catch (error) {
|
|
6694
|
-
console.error(
|
|
6918
|
+
console.error(import_chalk7.default.red(`error checking path: ${error.message}`));
|
|
6695
6919
|
return null;
|
|
6696
6920
|
}
|
|
6697
6921
|
}
|
|
@@ -6723,7 +6947,7 @@ function getDnsFromArgs() {
|
|
|
6723
6947
|
}
|
|
6724
6948
|
async function checkWalletBalanceStatus(authConfig) {
|
|
6725
6949
|
var _a2;
|
|
6726
|
-
console.log(
|
|
6950
|
+
console.log(import_chalk7.default.blue("Checking wallet balance..."));
|
|
6727
6951
|
try {
|
|
6728
6952
|
const balanceResult = await getWalletBalance(
|
|
6729
6953
|
authConfig.address,
|
|
@@ -6734,21 +6958,21 @@ async function checkWalletBalanceStatus(authConfig) {
|
|
|
6734
6958
|
return false;
|
|
6735
6959
|
}
|
|
6736
6960
|
console.log(
|
|
6737
|
-
|
|
6961
|
+
import_chalk7.default.green(`Wallet balance available: $${balance.toFixed(2)}`)
|
|
6738
6962
|
);
|
|
6739
6963
|
return true;
|
|
6740
6964
|
} catch (e) {
|
|
6741
|
-
if (e.message === "Token expired") {
|
|
6965
|
+
if (e.message === "Token expired" || (e == null ? void 0 : e.name) === "CliError") {
|
|
6742
6966
|
throw e;
|
|
6743
6967
|
}
|
|
6744
|
-
console.log(
|
|
6968
|
+
console.log(import_chalk7.default.yellow("Failed to check wallet balance, continuing..."));
|
|
6745
6969
|
return true;
|
|
6746
6970
|
}
|
|
6747
6971
|
}
|
|
6748
6972
|
async function bindDomain(domain, contentHash, isDns, authConfig) {
|
|
6749
6973
|
const displayDomain = normalizeDomain(domain);
|
|
6750
6974
|
if (isDns) {
|
|
6751
|
-
console.log(
|
|
6975
|
+
console.log(import_chalk7.default.blue("Binding DNS domain..."));
|
|
6752
6976
|
const dnsResult = await bindDnsDomainV4(
|
|
6753
6977
|
displayDomain,
|
|
6754
6978
|
contentHash,
|
|
@@ -6756,26 +6980,26 @@ async function bindDomain(domain, contentHash, isDns, authConfig) {
|
|
|
6756
6980
|
authConfig.token
|
|
6757
6981
|
);
|
|
6758
6982
|
if (dnsResult.code !== 200) {
|
|
6759
|
-
console.log(
|
|
6983
|
+
console.log(import_chalk7.default.red(`DNS binding failed: ${dnsResult.msg}`));
|
|
6760
6984
|
return false;
|
|
6761
6985
|
}
|
|
6762
|
-
console.log(
|
|
6763
|
-
console.log(
|
|
6986
|
+
console.log(import_chalk7.default.green(`DNS bind success: ${displayDomain}`));
|
|
6987
|
+
console.log(import_chalk7.default.white(`Visit: https://${displayDomain}`));
|
|
6764
6988
|
console.log(
|
|
6765
|
-
|
|
6989
|
+
import_chalk7.default.cyan(
|
|
6766
6990
|
"\n\u{1F4DA} DNS Setup Guide: https://pinme.eth.limo/#/docs?id=custom-domain"
|
|
6767
6991
|
)
|
|
6768
6992
|
);
|
|
6769
6993
|
} else {
|
|
6770
|
-
console.log(
|
|
6994
|
+
console.log(import_chalk7.default.blue("Binding Pinme subdomain..."));
|
|
6771
6995
|
const ok = await bindPinmeDomain(displayDomain, contentHash);
|
|
6772
6996
|
if (!ok) {
|
|
6773
|
-
console.log(
|
|
6997
|
+
console.log(import_chalk7.default.red("Binding failed. Please try again later."));
|
|
6774
6998
|
return false;
|
|
6775
6999
|
}
|
|
6776
|
-
console.log(
|
|
7000
|
+
console.log(import_chalk7.default.green(`Bind success: ${displayDomain}`));
|
|
6777
7001
|
const rootDomain = await (await Promise.resolve().then(() => (init_pinmeApi(), pinmeApi_exports))).getRootDomain();
|
|
6778
|
-
console.log(
|
|
7002
|
+
console.log(import_chalk7.default.white(`Visit: https://${displayDomain}.${rootDomain}`));
|
|
6779
7003
|
}
|
|
6780
7004
|
return true;
|
|
6781
7005
|
}
|
|
@@ -6792,7 +7016,7 @@ var upload_default = async (options) => {
|
|
|
6792
7016
|
);
|
|
6793
7017
|
const authConfig = getAuthConfig();
|
|
6794
7018
|
if (!authConfig) {
|
|
6795
|
-
console.log(
|
|
7019
|
+
console.log(import_chalk7.default.red("Please login first. Run: pinme login"));
|
|
6796
7020
|
return;
|
|
6797
7021
|
}
|
|
6798
7022
|
const domainArg = getDomainFromArgs();
|
|
@@ -6801,7 +7025,7 @@ var upload_default = async (options) => {
|
|
|
6801
7025
|
if (argPath && !argPath.startsWith("-")) {
|
|
6802
7026
|
const absolutePath = checkPathSync(argPath);
|
|
6803
7027
|
if (!absolutePath) {
|
|
6804
|
-
console.log(
|
|
7028
|
+
console.log(import_chalk7.default.red(`path ${argPath} does not exist`));
|
|
6805
7029
|
return;
|
|
6806
7030
|
}
|
|
6807
7031
|
const isDns = dnsArg || (domainArg ? isDnsDomain(domainArg) : false);
|
|
@@ -6809,7 +7033,7 @@ var upload_default = async (options) => {
|
|
|
6809
7033
|
if (isDns && domainArg) {
|
|
6810
7034
|
const validation = validateDnsDomain(domainArg);
|
|
6811
7035
|
if (!validation.valid) {
|
|
6812
|
-
console.log(
|
|
7036
|
+
console.log(import_chalk7.default.red(validation.message));
|
|
6813
7037
|
return;
|
|
6814
7038
|
}
|
|
6815
7039
|
}
|
|
@@ -6818,7 +7042,7 @@ var upload_default = async (options) => {
|
|
|
6818
7042
|
const hasWalletBalance = await checkWalletBalanceStatus(authConfig);
|
|
6819
7043
|
if (!hasWalletBalance) {
|
|
6820
7044
|
console.log(
|
|
6821
|
-
|
|
7045
|
+
import_chalk7.default.red(
|
|
6822
7046
|
"Insufficient wallet balance. Please recharge your wallet first."
|
|
6823
7047
|
)
|
|
6824
7048
|
);
|
|
@@ -6836,13 +7060,13 @@ var upload_default = async (options) => {
|
|
|
6836
7060
|
const check = await checkDomainAvailable(displayDomain);
|
|
6837
7061
|
if (!check.is_valid) {
|
|
6838
7062
|
console.log(
|
|
6839
|
-
|
|
7063
|
+
import_chalk7.default.red(
|
|
6840
7064
|
`Domain not available: ${check.error || "unknown reason"}`
|
|
6841
7065
|
)
|
|
6842
7066
|
);
|
|
6843
7067
|
return;
|
|
6844
7068
|
}
|
|
6845
|
-
console.log(
|
|
7069
|
+
console.log(import_chalk7.default.green(`Domain available: ${displayDomain}`));
|
|
6846
7070
|
} catch (e) {
|
|
6847
7071
|
if (e.message === "Token expired") {
|
|
6848
7072
|
return;
|
|
@@ -6850,7 +7074,7 @@ var upload_default = async (options) => {
|
|
|
6850
7074
|
throw e;
|
|
6851
7075
|
}
|
|
6852
7076
|
}
|
|
6853
|
-
console.log(
|
|
7077
|
+
console.log(import_chalk7.default.blue(`uploading ${absolutePath} to ipfs...`));
|
|
6854
7078
|
let result;
|
|
6855
7079
|
try {
|
|
6856
7080
|
result = await uploadPath(absolutePath, {
|
|
@@ -6858,20 +7082,20 @@ var upload_default = async (options) => {
|
|
|
6858
7082
|
uid: authConfig == null ? void 0 : authConfig.address
|
|
6859
7083
|
});
|
|
6860
7084
|
} catch (error) {
|
|
6861
|
-
|
|
7085
|
+
printCliError(error, "Upload failed.");
|
|
6862
7086
|
process.exit(1);
|
|
6863
7087
|
}
|
|
6864
7088
|
if (!result) {
|
|
6865
|
-
console.error(
|
|
7089
|
+
console.error(import_chalk7.default.red("Upload failed: no result returned"));
|
|
6866
7090
|
process.exit(1);
|
|
6867
7091
|
}
|
|
6868
7092
|
console.log(
|
|
6869
|
-
|
|
7093
|
+
import_chalk7.default.cyan(import_figlet.default.textSync("Successful", { horizontalLayout: "full" }))
|
|
6870
7094
|
);
|
|
6871
7095
|
await printUploadUrls(result);
|
|
6872
7096
|
if (domainArg) {
|
|
6873
7097
|
console.log(
|
|
6874
|
-
|
|
7098
|
+
import_chalk7.default.blue(
|
|
6875
7099
|
`Binding domain: ${displayDomain} with CID: ${result.contentHash}`
|
|
6876
7100
|
)
|
|
6877
7101
|
);
|
|
@@ -6884,7 +7108,7 @@ var upload_default = async (options) => {
|
|
|
6884
7108
|
throw e;
|
|
6885
7109
|
}
|
|
6886
7110
|
}
|
|
6887
|
-
console.log(
|
|
7111
|
+
console.log(import_chalk7.default.green("\n\u{1F389} upload successful, program exit"));
|
|
6888
7112
|
process.exit(0);
|
|
6889
7113
|
}
|
|
6890
7114
|
const answer = await import_inquirer.default.prompt([
|
|
@@ -6897,7 +7121,7 @@ var upload_default = async (options) => {
|
|
|
6897
7121
|
if (answer.path) {
|
|
6898
7122
|
const absolutePath = checkPathSync(answer.path);
|
|
6899
7123
|
if (!absolutePath) {
|
|
6900
|
-
console.log(
|
|
7124
|
+
console.log(import_chalk7.default.red(`path ${answer.path} does not exist`));
|
|
6901
7125
|
return;
|
|
6902
7126
|
}
|
|
6903
7127
|
const isDns = dnsArg || (domainArg ? isDnsDomain(domainArg) : false);
|
|
@@ -6905,7 +7129,7 @@ var upload_default = async (options) => {
|
|
|
6905
7129
|
if (isDns && domainArg) {
|
|
6906
7130
|
const validation = validateDnsDomain(domainArg);
|
|
6907
7131
|
if (!validation.valid) {
|
|
6908
|
-
console.log(
|
|
7132
|
+
console.log(import_chalk7.default.red(validation.message));
|
|
6909
7133
|
return;
|
|
6910
7134
|
}
|
|
6911
7135
|
}
|
|
@@ -6914,7 +7138,7 @@ var upload_default = async (options) => {
|
|
|
6914
7138
|
const hasWalletBalance = await checkWalletBalanceStatus(authConfig);
|
|
6915
7139
|
if (!hasWalletBalance) {
|
|
6916
7140
|
console.log(
|
|
6917
|
-
|
|
7141
|
+
import_chalk7.default.red(
|
|
6918
7142
|
"Insufficient wallet balance. Please recharge your wallet first."
|
|
6919
7143
|
)
|
|
6920
7144
|
);
|
|
@@ -6932,13 +7156,13 @@ var upload_default = async (options) => {
|
|
|
6932
7156
|
const check = await checkDomainAvailable(displayDomain);
|
|
6933
7157
|
if (!check.is_valid) {
|
|
6934
7158
|
console.log(
|
|
6935
|
-
|
|
7159
|
+
import_chalk7.default.red(
|
|
6936
7160
|
`Domain not available: ${check.error || "unknown reason"}`
|
|
6937
7161
|
)
|
|
6938
7162
|
);
|
|
6939
7163
|
return;
|
|
6940
7164
|
}
|
|
6941
|
-
console.log(
|
|
7165
|
+
console.log(import_chalk7.default.green(`Domain available: ${displayDomain}`));
|
|
6942
7166
|
} catch (e) {
|
|
6943
7167
|
if (e.message === "Token expired") {
|
|
6944
7168
|
return;
|
|
@@ -6946,7 +7170,7 @@ var upload_default = async (options) => {
|
|
|
6946
7170
|
throw e;
|
|
6947
7171
|
}
|
|
6948
7172
|
}
|
|
6949
|
-
console.log(
|
|
7173
|
+
console.log(import_chalk7.default.blue(`uploading ${absolutePath} to ipfs...`));
|
|
6950
7174
|
let result;
|
|
6951
7175
|
try {
|
|
6952
7176
|
result = await uploadPath(absolutePath, {
|
|
@@ -6954,20 +7178,20 @@ var upload_default = async (options) => {
|
|
|
6954
7178
|
uid: authConfig == null ? void 0 : authConfig.address
|
|
6955
7179
|
});
|
|
6956
7180
|
} catch (error) {
|
|
6957
|
-
|
|
7181
|
+
printCliError(error, "Upload failed.");
|
|
6958
7182
|
process.exit(1);
|
|
6959
7183
|
}
|
|
6960
7184
|
if (!result) {
|
|
6961
|
-
console.error(
|
|
7185
|
+
console.error(import_chalk7.default.red("Upload failed: no result returned"));
|
|
6962
7186
|
process.exit(1);
|
|
6963
7187
|
}
|
|
6964
7188
|
console.log(
|
|
6965
|
-
|
|
7189
|
+
import_chalk7.default.cyan(import_figlet.default.textSync("Successful", { horizontalLayout: "full" }))
|
|
6966
7190
|
);
|
|
6967
7191
|
await printUploadUrls(result);
|
|
6968
7192
|
if (domainArg) {
|
|
6969
7193
|
console.log(
|
|
6970
|
-
|
|
7194
|
+
import_chalk7.default.blue(
|
|
6971
7195
|
`Binding domain: ${displayDomain} with CID: ${result.contentHash}`
|
|
6972
7196
|
)
|
|
6973
7197
|
);
|
|
@@ -6980,23 +7204,23 @@ var upload_default = async (options) => {
|
|
|
6980
7204
|
throw e;
|
|
6981
7205
|
}
|
|
6982
7206
|
}
|
|
6983
|
-
console.log(
|
|
7207
|
+
console.log(import_chalk7.default.green("\n\u{1F389} upload successful, program exit"));
|
|
6984
7208
|
process.exit(0);
|
|
6985
7209
|
}
|
|
6986
7210
|
} catch (error) {
|
|
6987
|
-
|
|
6988
|
-
console.error(error.stack);
|
|
7211
|
+
printCliError(error, "Upload failed.");
|
|
6989
7212
|
}
|
|
6990
7213
|
};
|
|
6991
7214
|
|
|
6992
7215
|
// bin/importCar.ts
|
|
6993
7216
|
var import_path7 = __toESM(require("path"));
|
|
6994
|
-
var
|
|
7217
|
+
var import_chalk8 = __toESM(require("chalk"));
|
|
6995
7218
|
var import_inquirer2 = __toESM(require("inquirer"));
|
|
6996
7219
|
var import_figlet2 = __toESM(require("figlet"));
|
|
6997
7220
|
var import_fs3 = __toESM(require("fs"));
|
|
6998
7221
|
var import_crypto_js2 = __toESM(require("crypto-js"));
|
|
6999
7222
|
init_pinmeApi();
|
|
7223
|
+
init_cliError();
|
|
7000
7224
|
init_webLogin();
|
|
7001
7225
|
init_config();
|
|
7002
7226
|
checkNodeVersion();
|
|
@@ -7022,7 +7246,7 @@ function checkPathSync2(inputPath) {
|
|
|
7022
7246
|
}
|
|
7023
7247
|
return null;
|
|
7024
7248
|
} catch (error) {
|
|
7025
|
-
console.error(
|
|
7249
|
+
console.error(import_chalk8.default.red(`error checking path: ${error.message}`));
|
|
7026
7250
|
return null;
|
|
7027
7251
|
}
|
|
7028
7252
|
}
|
|
@@ -7054,7 +7278,7 @@ var importCar_default = async (options) => {
|
|
|
7054
7278
|
);
|
|
7055
7279
|
const auth = getAuthConfig();
|
|
7056
7280
|
if (!auth) {
|
|
7057
|
-
console.log(
|
|
7281
|
+
console.log(import_chalk8.default.red("Please login first. Run: pinme login"));
|
|
7058
7282
|
return;
|
|
7059
7283
|
}
|
|
7060
7284
|
const argPath = process.argv[3];
|
|
@@ -7062,18 +7286,18 @@ var importCar_default = async (options) => {
|
|
|
7062
7286
|
if (argPath && !argPath.startsWith("-")) {
|
|
7063
7287
|
const absolutePath = checkPathSync2(argPath);
|
|
7064
7288
|
if (!absolutePath) {
|
|
7065
|
-
console.log(
|
|
7289
|
+
console.log(import_chalk8.default.red(`path ${argPath} does not exist`));
|
|
7066
7290
|
return;
|
|
7067
7291
|
}
|
|
7068
7292
|
if (domainArg) {
|
|
7069
7293
|
const check = await checkDomainAvailable(domainArg);
|
|
7070
7294
|
if (!check.is_valid) {
|
|
7071
|
-
console.log(
|
|
7295
|
+
console.log(import_chalk8.default.red(`Domain not available: ${check.error || "unknown reason"}`));
|
|
7072
7296
|
return;
|
|
7073
7297
|
}
|
|
7074
|
-
console.log(
|
|
7298
|
+
console.log(import_chalk8.default.green(`Domain available: ${domainArg}`));
|
|
7075
7299
|
}
|
|
7076
|
-
console.log(
|
|
7300
|
+
console.log(import_chalk8.default.blue(`importing ${absolutePath} to ipfs as CAR...`));
|
|
7077
7301
|
try {
|
|
7078
7302
|
const result = await uploadPath(absolutePath, {
|
|
7079
7303
|
importAsCar: true,
|
|
@@ -7083,7 +7307,7 @@ var importCar_default = async (options) => {
|
|
|
7083
7307
|
const uid = getUid2();
|
|
7084
7308
|
const encryptedCID = encryptHash2(result.contentHash, APP_CONFIG.secretKey, uid);
|
|
7085
7309
|
console.log(
|
|
7086
|
-
|
|
7310
|
+
import_chalk8.default.cyan(
|
|
7087
7311
|
import_figlet2.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7088
7312
|
)
|
|
7089
7313
|
);
|
|
@@ -7093,20 +7317,20 @@ var importCar_default = async (options) => {
|
|
|
7093
7317
|
"primary"
|
|
7094
7318
|
);
|
|
7095
7319
|
if (domainArg) {
|
|
7096
|
-
console.log(
|
|
7320
|
+
console.log(import_chalk8.default.blue(`Binding domain: ${domainArg} with CID: ${result.contentHash}`));
|
|
7097
7321
|
const ok = await bindPinmeDomain(domainArg, result.contentHash);
|
|
7098
7322
|
if (ok) {
|
|
7099
|
-
console.log(
|
|
7323
|
+
console.log(import_chalk8.default.green(`Bind success: ${domainArg}`));
|
|
7100
7324
|
const rootDomain = await getRootDomain();
|
|
7101
|
-
console.log(
|
|
7325
|
+
console.log(import_chalk8.default.white(`Visit (Pinme subdomain example): https://${domainArg}.${rootDomain}`));
|
|
7102
7326
|
} else {
|
|
7103
|
-
console.log(
|
|
7327
|
+
console.log(import_chalk8.default.red("Binding failed. Please try again later."));
|
|
7104
7328
|
}
|
|
7105
7329
|
}
|
|
7106
|
-
console.log(
|
|
7330
|
+
console.log(import_chalk8.default.green("\n\u{1F389} import successful, program exit"));
|
|
7107
7331
|
}
|
|
7108
7332
|
} catch (error) {
|
|
7109
|
-
|
|
7333
|
+
printCliError(error, "Import failed.");
|
|
7110
7334
|
}
|
|
7111
7335
|
process.exit(0);
|
|
7112
7336
|
}
|
|
@@ -7120,18 +7344,18 @@ var importCar_default = async (options) => {
|
|
|
7120
7344
|
if (answer.path) {
|
|
7121
7345
|
const absolutePath = checkPathSync2(answer.path);
|
|
7122
7346
|
if (!absolutePath) {
|
|
7123
|
-
console.log(
|
|
7347
|
+
console.log(import_chalk8.default.red(`path ${answer.path} does not exist`));
|
|
7124
7348
|
return;
|
|
7125
7349
|
}
|
|
7126
7350
|
if (domainArg) {
|
|
7127
7351
|
const check = await checkDomainAvailable(domainArg);
|
|
7128
7352
|
if (!check.is_valid) {
|
|
7129
|
-
console.log(
|
|
7353
|
+
console.log(import_chalk8.default.red(`Domain not available: ${check.error || "unknown reason"}`));
|
|
7130
7354
|
return;
|
|
7131
7355
|
}
|
|
7132
|
-
console.log(
|
|
7356
|
+
console.log(import_chalk8.default.green(`Domain available: ${domainArg}`));
|
|
7133
7357
|
}
|
|
7134
|
-
console.log(
|
|
7358
|
+
console.log(import_chalk8.default.blue(`importing ${absolutePath} to ipfs as CAR...`));
|
|
7135
7359
|
try {
|
|
7136
7360
|
const result = await uploadPath(absolutePath, {
|
|
7137
7361
|
importAsCar: true,
|
|
@@ -7141,7 +7365,7 @@ var importCar_default = async (options) => {
|
|
|
7141
7365
|
const uid = getUid2();
|
|
7142
7366
|
const encryptedCID = encryptHash2(result.contentHash, APP_CONFIG.secretKey, uid);
|
|
7143
7367
|
console.log(
|
|
7144
|
-
|
|
7368
|
+
import_chalk8.default.cyan(
|
|
7145
7369
|
import_figlet2.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7146
7370
|
)
|
|
7147
7371
|
);
|
|
@@ -7151,37 +7375,37 @@ var importCar_default = async (options) => {
|
|
|
7151
7375
|
"primary"
|
|
7152
7376
|
);
|
|
7153
7377
|
if (domainArg) {
|
|
7154
|
-
console.log(
|
|
7378
|
+
console.log(import_chalk8.default.blue(`Binding domain: ${domainArg} with CID: ${result.contentHash}`));
|
|
7155
7379
|
const ok = await bindPinmeDomain(domainArg, result.contentHash);
|
|
7156
7380
|
if (ok) {
|
|
7157
|
-
console.log(
|
|
7381
|
+
console.log(import_chalk8.default.green(`Bind success: ${domainArg}`));
|
|
7158
7382
|
const rootDomain = await getRootDomain();
|
|
7159
|
-
console.log(
|
|
7383
|
+
console.log(import_chalk8.default.white(`Visit (Pinme subdomain example): https://${domainArg}.${rootDomain}`));
|
|
7160
7384
|
} else {
|
|
7161
|
-
console.log(
|
|
7385
|
+
console.log(import_chalk8.default.red("Binding failed. Please try again later."));
|
|
7162
7386
|
}
|
|
7163
7387
|
}
|
|
7164
|
-
console.log(
|
|
7388
|
+
console.log(import_chalk8.default.green("\n\u{1F389} import successful, program exit"));
|
|
7165
7389
|
}
|
|
7166
7390
|
} catch (error) {
|
|
7167
|
-
|
|
7391
|
+
printCliError(error, "Import failed.");
|
|
7168
7392
|
}
|
|
7169
7393
|
process.exit(0);
|
|
7170
7394
|
}
|
|
7171
7395
|
} catch (error) {
|
|
7172
|
-
|
|
7173
|
-
console.error(error.stack);
|
|
7396
|
+
printCliError(error, "Import failed.");
|
|
7174
7397
|
}
|
|
7175
7398
|
};
|
|
7176
7399
|
|
|
7177
7400
|
// bin/exportCar.ts
|
|
7178
7401
|
var import_path8 = __toESM(require("path"));
|
|
7179
|
-
var
|
|
7402
|
+
var import_chalk9 = __toESM(require("chalk"));
|
|
7180
7403
|
var import_inquirer3 = __toESM(require("inquirer"));
|
|
7181
7404
|
var import_figlet3 = __toESM(require("figlet"));
|
|
7182
7405
|
var import_fs4 = __toESM(require("fs"));
|
|
7183
7406
|
init_axios2();
|
|
7184
7407
|
var import_ora2 = __toESM(require("ora"));
|
|
7408
|
+
init_cliError();
|
|
7185
7409
|
init_pinmeApi();
|
|
7186
7410
|
checkNodeVersion();
|
|
7187
7411
|
var POLL_INTERVAL2 = 5e3;
|
|
@@ -7203,7 +7427,7 @@ async function pollExportStatus(taskId, cid, spinner, startTime) {
|
|
|
7203
7427
|
spinner.text = `Exporting CAR file... (${minutes}m ${seconds}s)`;
|
|
7204
7428
|
}
|
|
7205
7429
|
} catch (error) {
|
|
7206
|
-
console.log(
|
|
7430
|
+
console.log(import_chalk9.default.yellow(`Polling error: ${error.message}`));
|
|
7207
7431
|
}
|
|
7208
7432
|
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL2));
|
|
7209
7433
|
}
|
|
@@ -7243,7 +7467,7 @@ async function downloadCarFile(downloadUrl, outputPath) {
|
|
|
7243
7467
|
});
|
|
7244
7468
|
});
|
|
7245
7469
|
} catch (error) {
|
|
7246
|
-
console.error(
|
|
7470
|
+
console.error(import_chalk9.default.red(`Download error: ${error.message}`));
|
|
7247
7471
|
return false;
|
|
7248
7472
|
}
|
|
7249
7473
|
}
|
|
@@ -7301,7 +7525,7 @@ var exportCar_default = async () => {
|
|
|
7301
7525
|
cid = answer.cid.trim();
|
|
7302
7526
|
}
|
|
7303
7527
|
if (!cid || !isValidCID(cid)) {
|
|
7304
|
-
console.log(
|
|
7528
|
+
console.log(import_chalk9.default.red("Invalid CID format. CID should start with Qm, bafy, bafk, or bafz"));
|
|
7305
7529
|
return;
|
|
7306
7530
|
}
|
|
7307
7531
|
let outputDir = getOutputPathFromArgs();
|
|
@@ -7321,7 +7545,7 @@ var exportCar_default = async () => {
|
|
|
7321
7545
|
if (!import_fs4.default.existsSync(outputDir)) {
|
|
7322
7546
|
import_fs4.default.mkdirSync(outputDir, { recursive: true });
|
|
7323
7547
|
} else if (!import_fs4.default.statSync(outputDir).isDirectory()) {
|
|
7324
|
-
console.log(
|
|
7548
|
+
console.log(import_chalk9.default.red(`Error: ${outputDir} exists but is not a directory.`));
|
|
7325
7549
|
return;
|
|
7326
7550
|
}
|
|
7327
7551
|
const finalOutputPath = import_path8.default.join(outputDir, `${cid}.car`);
|
|
@@ -7335,7 +7559,7 @@ var exportCar_default = async () => {
|
|
|
7335
7559
|
}
|
|
7336
7560
|
]);
|
|
7337
7561
|
if (!answer.overwrite) {
|
|
7338
|
-
console.log(
|
|
7562
|
+
console.log(import_chalk9.default.blue("Export cancelled."));
|
|
7339
7563
|
return;
|
|
7340
7564
|
}
|
|
7341
7565
|
}
|
|
@@ -7353,7 +7577,7 @@ var exportCar_default = async () => {
|
|
|
7353
7577
|
startTime
|
|
7354
7578
|
);
|
|
7355
7579
|
if (!downloadUrl) {
|
|
7356
|
-
console.log(
|
|
7580
|
+
console.log(import_chalk9.default.red("Export failed or timed out."));
|
|
7357
7581
|
return;
|
|
7358
7582
|
}
|
|
7359
7583
|
const success = await downloadCarFile(downloadUrl, finalOutputPath);
|
|
@@ -7361,42 +7585,41 @@ var exportCar_default = async () => {
|
|
|
7361
7585
|
const fileSize = import_fs4.default.statSync(finalOutputPath).size;
|
|
7362
7586
|
const fileSizeMB = (fileSize / (1024 * 1024)).toFixed(2);
|
|
7363
7587
|
console.log(
|
|
7364
|
-
|
|
7588
|
+
import_chalk9.default.cyan(
|
|
7365
7589
|
import_figlet3.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7366
7590
|
)
|
|
7367
7591
|
);
|
|
7368
|
-
console.log(
|
|
7592
|
+
console.log(import_chalk9.default.green(`
|
|
7369
7593
|
\u{1F389} Export successful!`));
|
|
7370
|
-
console.log(
|
|
7371
|
-
console.log(
|
|
7372
|
-
console.log(
|
|
7594
|
+
console.log(import_chalk9.default.cyan(`File: ${finalOutputPath}`));
|
|
7595
|
+
console.log(import_chalk9.default.cyan(`Size: ${fileSizeMB} MB`));
|
|
7596
|
+
console.log(import_chalk9.default.cyan(`CID: ${cid}`));
|
|
7373
7597
|
} else {
|
|
7374
|
-
console.log(
|
|
7598
|
+
console.log(import_chalk9.default.red("Download failed."));
|
|
7375
7599
|
}
|
|
7376
7600
|
} catch (error) {
|
|
7377
7601
|
spinner.fail(`Error: ${error.message}`);
|
|
7378
|
-
|
|
7602
|
+
printCliError(error, "Export failed.");
|
|
7379
7603
|
}
|
|
7380
7604
|
} catch (error) {
|
|
7381
|
-
|
|
7382
|
-
console.error(error.stack);
|
|
7605
|
+
printCliError(error, "Export failed.");
|
|
7383
7606
|
}
|
|
7384
7607
|
};
|
|
7385
7608
|
|
|
7386
7609
|
// bin/remove.ts
|
|
7387
|
-
var
|
|
7610
|
+
var import_chalk11 = __toESM(require("chalk"));
|
|
7388
7611
|
var import_inquirer4 = __toESM(require("inquirer"));
|
|
7389
7612
|
var import_figlet4 = __toESM(require("figlet"));
|
|
7390
7613
|
|
|
7391
7614
|
// bin/utils/removeFromIpfs.ts
|
|
7392
7615
|
init_axios2();
|
|
7393
|
-
var
|
|
7616
|
+
var import_chalk10 = __toESM(require("chalk"));
|
|
7394
7617
|
init_config();
|
|
7395
7618
|
var ipfsApiUrl = APP_CONFIG.ipfsApiUrl;
|
|
7396
7619
|
async function removeFromIpfs(value, type = "hash") {
|
|
7397
7620
|
try {
|
|
7398
7621
|
const uid = getUid();
|
|
7399
|
-
console.log(
|
|
7622
|
+
console.log(import_chalk10.default.blue(`Removing content from IPFS: ${value}...`));
|
|
7400
7623
|
const queryParams = new URLSearchParams({
|
|
7401
7624
|
uid
|
|
7402
7625
|
});
|
|
@@ -7414,49 +7637,49 @@ async function removeFromIpfs(value, type = "hash") {
|
|
|
7414
7637
|
);
|
|
7415
7638
|
const { code, msg, data } = response.data;
|
|
7416
7639
|
if (code === 200) {
|
|
7417
|
-
console.log(
|
|
7640
|
+
console.log(import_chalk10.default.green("\u2713 Removal successful!"));
|
|
7418
7641
|
console.log(
|
|
7419
|
-
|
|
7642
|
+
import_chalk10.default.cyan(
|
|
7420
7643
|
`Content ${type}: ${value} has been removed from IPFS network`
|
|
7421
7644
|
)
|
|
7422
7645
|
);
|
|
7423
7646
|
return true;
|
|
7424
7647
|
} else {
|
|
7425
|
-
console.log(
|
|
7426
|
-
console.log(
|
|
7648
|
+
console.log(import_chalk10.default.red("\u2717 Removal failed"));
|
|
7649
|
+
console.log(import_chalk10.default.red(`Error: ${msg || "Unknown error occurred"}`));
|
|
7427
7650
|
return false;
|
|
7428
7651
|
}
|
|
7429
7652
|
} catch (error) {
|
|
7430
|
-
console.log(
|
|
7653
|
+
console.log(import_chalk10.default.red("\u2717 Removal failed", error));
|
|
7431
7654
|
if (error.response) {
|
|
7432
7655
|
const { status, data } = error.response;
|
|
7433
7656
|
console.log(
|
|
7434
|
-
|
|
7657
|
+
import_chalk10.default.red(`HTTP Error ${status}: ${(data == null ? void 0 : data.msg) || "Server error"}`)
|
|
7435
7658
|
);
|
|
7436
7659
|
if (status === 404) {
|
|
7437
7660
|
console.log(
|
|
7438
|
-
|
|
7661
|
+
import_chalk10.default.yellow("Content not found on the network or already removed")
|
|
7439
7662
|
);
|
|
7440
7663
|
} else if (status === 403) {
|
|
7441
7664
|
console.log(
|
|
7442
|
-
|
|
7665
|
+
import_chalk10.default.yellow(
|
|
7443
7666
|
"Permission denied - you may not have access to remove this content"
|
|
7444
7667
|
)
|
|
7445
7668
|
);
|
|
7446
7669
|
} else if (status === 500) {
|
|
7447
7670
|
console.log(
|
|
7448
|
-
|
|
7671
|
+
import_chalk10.default.yellow("Server internal error - please try again later")
|
|
7449
7672
|
);
|
|
7450
7673
|
}
|
|
7451
7674
|
} else if (error.request) {
|
|
7452
7675
|
console.log(
|
|
7453
|
-
|
|
7676
|
+
import_chalk10.default.red("Network error: Unable to connect to IPFS service")
|
|
7454
7677
|
);
|
|
7455
7678
|
console.log(
|
|
7456
|
-
|
|
7679
|
+
import_chalk10.default.yellow("Please check your internet connection and try again")
|
|
7457
7680
|
);
|
|
7458
7681
|
} else {
|
|
7459
|
-
console.log(
|
|
7682
|
+
console.log(import_chalk10.default.red(`Error: ${error.message}`));
|
|
7460
7683
|
}
|
|
7461
7684
|
return false;
|
|
7462
7685
|
}
|
|
@@ -7516,29 +7739,29 @@ var remove_default = async (options) => {
|
|
|
7516
7739
|
if (argHash && !argHash.startsWith("-")) {
|
|
7517
7740
|
const parsedInput = parseInput(argHash);
|
|
7518
7741
|
if (!parsedInput) {
|
|
7519
|
-
console.log(
|
|
7520
|
-
console.log(
|
|
7521
|
-
console.log(
|
|
7522
|
-
console.log(
|
|
7523
|
-
console.log(
|
|
7742
|
+
console.log(import_chalk11.default.red(`Invalid input format: ${argHash}`));
|
|
7743
|
+
console.log(import_chalk11.default.yellow("Supported formats:"));
|
|
7744
|
+
console.log(import_chalk11.default.yellow(" - IPFS hash: bafybeig..."));
|
|
7745
|
+
console.log(import_chalk11.default.yellow(" - Subname: 3abt6ztu"));
|
|
7746
|
+
console.log(import_chalk11.default.yellow(" - Subname URL: https://3abt6ztu.<root-domain>"));
|
|
7524
7747
|
return;
|
|
7525
7748
|
}
|
|
7526
7749
|
try {
|
|
7527
7750
|
const success = await removeFromIpfs(parsedInput.value, parsedInput.type);
|
|
7528
7751
|
if (success) {
|
|
7529
7752
|
console.log(
|
|
7530
|
-
|
|
7753
|
+
import_chalk11.default.cyan(
|
|
7531
7754
|
import_figlet4.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7532
7755
|
)
|
|
7533
7756
|
);
|
|
7534
7757
|
}
|
|
7535
7758
|
} catch (error) {
|
|
7536
|
-
console.error(
|
|
7759
|
+
console.error(import_chalk11.default.red(`Error: ${error.message}`));
|
|
7537
7760
|
}
|
|
7538
7761
|
return;
|
|
7539
7762
|
}
|
|
7540
|
-
console.log(
|
|
7541
|
-
console.log(
|
|
7763
|
+
console.log(import_chalk11.default.yellow("\u26A0\uFE0F Warning: This action will permanently remove the content from IPFS network"));
|
|
7764
|
+
console.log(import_chalk11.default.yellow("\u26A0\uFE0F Make sure you have the correct IPFS hash"));
|
|
7542
7765
|
console.log("");
|
|
7543
7766
|
const confirmAnswer = await import_inquirer4.default.prompt([
|
|
7544
7767
|
{
|
|
@@ -7549,7 +7772,7 @@ var remove_default = async (options) => {
|
|
|
7549
7772
|
}
|
|
7550
7773
|
]);
|
|
7551
7774
|
if (!confirmAnswer.confirm) {
|
|
7552
|
-
console.log(
|
|
7775
|
+
console.log(import_chalk11.default.yellow("Operation cancelled"));
|
|
7553
7776
|
return;
|
|
7554
7777
|
}
|
|
7555
7778
|
const answer = await import_inquirer4.default.prompt([
|
|
@@ -7572,7 +7795,7 @@ var remove_default = async (options) => {
|
|
|
7572
7795
|
if (answer.input) {
|
|
7573
7796
|
const parsedInput = parseInput(answer.input.trim());
|
|
7574
7797
|
if (!parsedInput) {
|
|
7575
|
-
console.log(
|
|
7798
|
+
console.log(import_chalk11.default.red("Invalid input format"));
|
|
7576
7799
|
return;
|
|
7577
7800
|
}
|
|
7578
7801
|
const finalConfirm = await import_inquirer4.default.prompt([
|
|
@@ -7584,30 +7807,30 @@ var remove_default = async (options) => {
|
|
|
7584
7807
|
}
|
|
7585
7808
|
]);
|
|
7586
7809
|
if (!finalConfirm.confirm) {
|
|
7587
|
-
console.log(
|
|
7810
|
+
console.log(import_chalk11.default.yellow("Operation cancelled"));
|
|
7588
7811
|
return;
|
|
7589
7812
|
}
|
|
7590
7813
|
try {
|
|
7591
7814
|
const success = await removeFromIpfs(parsedInput.value, parsedInput.type);
|
|
7592
7815
|
if (success) {
|
|
7593
7816
|
console.log(
|
|
7594
|
-
|
|
7817
|
+
import_chalk11.default.cyan(
|
|
7595
7818
|
import_figlet4.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7596
7819
|
)
|
|
7597
7820
|
);
|
|
7598
7821
|
}
|
|
7599
7822
|
} catch (error) {
|
|
7600
|
-
console.error(
|
|
7823
|
+
console.error(import_chalk11.default.red(`Error: ${error.message}`));
|
|
7601
7824
|
}
|
|
7602
7825
|
}
|
|
7603
7826
|
} catch (error) {
|
|
7604
|
-
console.error(
|
|
7827
|
+
console.error(import_chalk11.default.red(`Error executing remove command: ${error.message}`));
|
|
7605
7828
|
console.error(error.stack);
|
|
7606
7829
|
}
|
|
7607
7830
|
};
|
|
7608
7831
|
|
|
7609
7832
|
// bin/set-appkey.ts
|
|
7610
|
-
var
|
|
7833
|
+
var import_chalk12 = __toESM(require("chalk"));
|
|
7611
7834
|
var import_inquirer5 = __toESM(require("inquirer"));
|
|
7612
7835
|
init_webLogin();
|
|
7613
7836
|
init_pinmeApi();
|
|
@@ -7626,32 +7849,32 @@ async function setAppKeyCmd() {
|
|
|
7626
7849
|
appKey = ans.appKey;
|
|
7627
7850
|
}
|
|
7628
7851
|
if (!appKey) {
|
|
7629
|
-
console.log(
|
|
7852
|
+
console.log(import_chalk12.default.red("AppKey not provided."));
|
|
7630
7853
|
return;
|
|
7631
7854
|
}
|
|
7632
7855
|
const saved = setAuthToken(appKey);
|
|
7633
|
-
console.log(
|
|
7856
|
+
console.log(import_chalk12.default.green(`Auth set for address: ${saved.address}`));
|
|
7634
7857
|
const deviceId = getDeviceId();
|
|
7635
7858
|
const ok = await bindAnonymousDevice(deviceId);
|
|
7636
7859
|
if (ok) {
|
|
7637
|
-
console.log(
|
|
7860
|
+
console.log(import_chalk12.default.green("Anonymous history merged to current account."));
|
|
7638
7861
|
} else {
|
|
7639
|
-
console.log(
|
|
7862
|
+
console.log(import_chalk12.default.yellow("Anonymous history merge not confirmed. You may retry later."));
|
|
7640
7863
|
}
|
|
7641
7864
|
} catch (e) {
|
|
7642
|
-
console.log(
|
|
7865
|
+
console.log(import_chalk12.default.red(`Failed to set AppKey: ${(e == null ? void 0 : e.message) || e}`));
|
|
7643
7866
|
}
|
|
7644
7867
|
}
|
|
7645
7868
|
|
|
7646
7869
|
// bin/logout.ts
|
|
7647
|
-
var
|
|
7870
|
+
var import_chalk13 = __toESM(require("chalk"));
|
|
7648
7871
|
var import_inquirer6 = __toESM(require("inquirer"));
|
|
7649
7872
|
init_webLogin();
|
|
7650
7873
|
async function logoutCmd() {
|
|
7651
7874
|
try {
|
|
7652
7875
|
const auth = getAuthConfig();
|
|
7653
7876
|
if (!auth) {
|
|
7654
|
-
console.log(
|
|
7877
|
+
console.log(import_chalk13.default.yellow("No active session found. You are already logged out."));
|
|
7655
7878
|
return;
|
|
7656
7879
|
}
|
|
7657
7880
|
const answer = await import_inquirer6.default.prompt([
|
|
@@ -7663,81 +7886,83 @@ async function logoutCmd() {
|
|
|
7663
7886
|
}
|
|
7664
7887
|
]);
|
|
7665
7888
|
if (!answer.confirm) {
|
|
7666
|
-
console.log(
|
|
7889
|
+
console.log(import_chalk13.default.blue("Logout cancelled."));
|
|
7667
7890
|
return;
|
|
7668
7891
|
}
|
|
7669
7892
|
clearAuthToken();
|
|
7670
|
-
console.log(
|
|
7671
|
-
console.log(
|
|
7893
|
+
console.log(import_chalk13.default.green("Successfully logged out."));
|
|
7894
|
+
console.log(import_chalk13.default.gray(`Address ${auth.address} has been removed from local storage.`));
|
|
7672
7895
|
} catch (e) {
|
|
7673
|
-
console.log(
|
|
7896
|
+
console.log(import_chalk13.default.red(`Failed to logout: ${(e == null ? void 0 : e.message) || e}`));
|
|
7674
7897
|
}
|
|
7675
7898
|
}
|
|
7676
7899
|
|
|
7677
7900
|
// bin/show-appkey.ts
|
|
7678
|
-
var
|
|
7901
|
+
var import_chalk14 = __toESM(require("chalk"));
|
|
7679
7902
|
init_webLogin();
|
|
7680
7903
|
function showAppKeyCmd() {
|
|
7681
7904
|
try {
|
|
7682
7905
|
const auth = getAuthConfig();
|
|
7683
7906
|
if (!auth) {
|
|
7684
|
-
console.log(
|
|
7685
|
-
console.log(
|
|
7907
|
+
console.log(import_chalk14.default.yellow("No AppKey found. Please set your AppKey first."));
|
|
7908
|
+
console.log(import_chalk14.default.gray("Run: pinme set-appkey <AppKey>"));
|
|
7686
7909
|
return;
|
|
7687
7910
|
}
|
|
7688
|
-
console.log(
|
|
7689
|
-
console.log(
|
|
7911
|
+
console.log(import_chalk14.default.green("Current AppKey Information:"));
|
|
7912
|
+
console.log(import_chalk14.default.cyan(` Address: ${auth.address}`));
|
|
7690
7913
|
const token = auth.token;
|
|
7691
7914
|
if (token.length > 12) {
|
|
7692
7915
|
const maskedToken = `${token.substring(0, 8)}${"*".repeat(token.length - 12)}${token.substring(token.length - 4)}`;
|
|
7693
|
-
console.log(
|
|
7916
|
+
console.log(import_chalk14.default.cyan(` Token: ${maskedToken}`));
|
|
7694
7917
|
} else {
|
|
7695
|
-
console.log(
|
|
7918
|
+
console.log(import_chalk14.default.cyan(` Token: ${"*".repeat(token.length)}`));
|
|
7696
7919
|
}
|
|
7697
7920
|
const combined = `${auth.address}-${auth.token}`;
|
|
7698
7921
|
if (combined.length > 20) {
|
|
7699
7922
|
const maskedAppKey = `${combined.substring(0, 12)}${"*".repeat(combined.length - 16)}${combined.substring(combined.length - 4)}`;
|
|
7700
|
-
console.log(
|
|
7923
|
+
console.log(import_chalk14.default.cyan(` AppKey: ${maskedAppKey}`));
|
|
7701
7924
|
} else {
|
|
7702
|
-
console.log(
|
|
7925
|
+
console.log(import_chalk14.default.cyan(` AppKey: ${"*".repeat(combined.length)}`));
|
|
7703
7926
|
}
|
|
7704
7927
|
} catch (e) {
|
|
7705
|
-
console.log(
|
|
7928
|
+
console.log(import_chalk14.default.red(`Failed to show AppKey: ${(e == null ? void 0 : e.message) || e}`));
|
|
7706
7929
|
}
|
|
7707
7930
|
}
|
|
7708
7931
|
|
|
7709
7932
|
// bin/my-domains.ts
|
|
7710
|
-
var
|
|
7933
|
+
var import_chalk15 = __toESM(require("chalk"));
|
|
7711
7934
|
var import_dayjs2 = __toESM(require("dayjs"));
|
|
7935
|
+
init_cliError();
|
|
7712
7936
|
init_pinmeApi();
|
|
7713
7937
|
async function myDomainsCmd() {
|
|
7714
7938
|
try {
|
|
7715
7939
|
const list = await getMyDomains();
|
|
7716
7940
|
if (!list.length) {
|
|
7717
|
-
console.log(
|
|
7941
|
+
console.log(import_chalk15.default.yellow("No bound domains found."));
|
|
7718
7942
|
return;
|
|
7719
7943
|
}
|
|
7720
|
-
console.log(
|
|
7721
|
-
console.log(
|
|
7944
|
+
console.log(import_chalk15.default.cyan("My domains:"));
|
|
7945
|
+
console.log(import_chalk15.default.cyan("-".repeat(80)));
|
|
7722
7946
|
list.forEach((item, i) => {
|
|
7723
|
-
console.log(
|
|
7724
|
-
console.log(
|
|
7947
|
+
console.log(import_chalk15.default.green(`${i + 1}. ${item.domain_name}`));
|
|
7948
|
+
console.log(import_chalk15.default.white(` Type: ${item.domain_type}`));
|
|
7725
7949
|
if (item.bind_time) {
|
|
7726
|
-
console.log(
|
|
7950
|
+
console.log(import_chalk15.default.white(` Bind time: ${(0, import_dayjs2.default)(item.bind_time * 1e3).format("YYYY-MM-DD HH:mm:ss")}`));
|
|
7727
7951
|
}
|
|
7728
7952
|
if (typeof item.expire_time === "number") {
|
|
7729
7953
|
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(
|
|
7954
|
+
console.log(import_chalk15.default.white(` Expire time: ${label}`));
|
|
7731
7955
|
}
|
|
7732
|
-
console.log(
|
|
7956
|
+
console.log(import_chalk15.default.cyan("-".repeat(80)));
|
|
7733
7957
|
});
|
|
7734
7958
|
} catch (e) {
|
|
7735
|
-
|
|
7959
|
+
printCliError(e, "Failed to fetch domains.");
|
|
7736
7960
|
}
|
|
7737
7961
|
}
|
|
7738
7962
|
|
|
7739
7963
|
// bin/wallet-balance.ts
|
|
7740
|
-
var
|
|
7964
|
+
var import_chalk16 = __toESM(require("chalk"));
|
|
7965
|
+
init_cliError();
|
|
7741
7966
|
init_pinmeApi();
|
|
7742
7967
|
init_webLogin();
|
|
7743
7968
|
async function walletBalanceCmd() {
|
|
@@ -7745,27 +7970,28 @@ async function walletBalanceCmd() {
|
|
|
7745
7970
|
try {
|
|
7746
7971
|
const auth = getAuthConfig();
|
|
7747
7972
|
if (!auth) {
|
|
7748
|
-
console.log(
|
|
7973
|
+
console.log(import_chalk16.default.yellow("Please login first. Run: pinme set-appkey <AppKey>"));
|
|
7749
7974
|
return;
|
|
7750
7975
|
}
|
|
7751
7976
|
const result = await getWalletBalance(auth.address, auth.token);
|
|
7752
7977
|
const balance = Number(((_a2 = result.data) == null ? void 0 : _a2.wallet_balance_usd) ?? 0);
|
|
7753
7978
|
if (!Number.isFinite(balance)) {
|
|
7754
|
-
console.log(
|
|
7979
|
+
console.log(import_chalk16.default.red("Failed to parse wallet balance."));
|
|
7755
7980
|
return;
|
|
7756
7981
|
}
|
|
7757
|
-
console.log(
|
|
7758
|
-
console.log(
|
|
7982
|
+
console.log(import_chalk16.default.cyan("Wallet balance:"));
|
|
7983
|
+
console.log(import_chalk16.default.green(` USD: $${balance.toFixed(2)}`));
|
|
7759
7984
|
} catch (e) {
|
|
7760
|
-
|
|
7985
|
+
printCliError(e, "Failed to fetch wallet balance.");
|
|
7761
7986
|
}
|
|
7762
7987
|
}
|
|
7763
7988
|
|
|
7764
7989
|
// bin/bind.ts
|
|
7765
7990
|
var import_path9 = __toESM(require("path"));
|
|
7766
|
-
var
|
|
7991
|
+
var import_chalk17 = __toESM(require("chalk"));
|
|
7767
7992
|
var import_inquirer7 = __toESM(require("inquirer"));
|
|
7768
7993
|
init_pinmeApi();
|
|
7994
|
+
init_cliError();
|
|
7769
7995
|
init_webLogin();
|
|
7770
7996
|
function parseArgs() {
|
|
7771
7997
|
const args = process.argv.slice(2);
|
|
@@ -7787,20 +8013,20 @@ function parseArgs() {
|
|
|
7787
8013
|
}
|
|
7788
8014
|
async function checkWalletBalanceStatus2(authConfig) {
|
|
7789
8015
|
var _a2;
|
|
7790
|
-
console.log(
|
|
8016
|
+
console.log(import_chalk17.default.blue("Checking wallet balance..."));
|
|
7791
8017
|
try {
|
|
7792
8018
|
const balanceResult = await getWalletBalance(authConfig.address, authConfig.token);
|
|
7793
8019
|
const balance = Number(((_a2 = balanceResult.data) == null ? void 0 : _a2.wallet_balance_usd) ?? 0);
|
|
7794
8020
|
if (!Number.isFinite(balance) || balance <= 0) {
|
|
7795
8021
|
return false;
|
|
7796
8022
|
}
|
|
7797
|
-
console.log(
|
|
8023
|
+
console.log(import_chalk17.default.green(`Wallet balance available: $${balance.toFixed(2)}`));
|
|
7798
8024
|
return true;
|
|
7799
8025
|
} catch (e) {
|
|
7800
|
-
if (e.message === "Token expired") {
|
|
8026
|
+
if (e.message === "Token expired" || (e == null ? void 0 : e.name) === "CliError") {
|
|
7801
8027
|
throw e;
|
|
7802
8028
|
}
|
|
7803
|
-
console.log(
|
|
8029
|
+
console.log(import_chalk17.default.yellow("Failed to check wallet balance, continuing..."));
|
|
7804
8030
|
return true;
|
|
7805
8031
|
}
|
|
7806
8032
|
}
|
|
@@ -7810,7 +8036,7 @@ async function bindCmd() {
|
|
|
7810
8036
|
let { domain, targetPath, dns } = parseArgs();
|
|
7811
8037
|
const authConfig = getAuthConfig();
|
|
7812
8038
|
if (!authConfig) {
|
|
7813
|
-
console.log(
|
|
8039
|
+
console.log(import_chalk17.default.red("Please login first. Run: pinme set-appkey <AppKey>"));
|
|
7814
8040
|
return;
|
|
7815
8041
|
}
|
|
7816
8042
|
if (!targetPath) {
|
|
@@ -7826,7 +8052,7 @@ async function bindCmd() {
|
|
|
7826
8052
|
domain = (_a2 = ans.domain) == null ? void 0 : _a2.trim();
|
|
7827
8053
|
}
|
|
7828
8054
|
if (!targetPath || !domain) {
|
|
7829
|
-
console.log(
|
|
8055
|
+
console.log(import_chalk17.default.red("Missing parameters. Path and domain are required."));
|
|
7830
8056
|
return;
|
|
7831
8057
|
}
|
|
7832
8058
|
const isDns = dns || isDnsDomain(domain);
|
|
@@ -7834,14 +8060,14 @@ async function bindCmd() {
|
|
|
7834
8060
|
if (isDns) {
|
|
7835
8061
|
const validation = validateDnsDomain(domain);
|
|
7836
8062
|
if (!validation.valid) {
|
|
7837
|
-
console.log(
|
|
8063
|
+
console.log(import_chalk17.default.red(validation.message));
|
|
7838
8064
|
return;
|
|
7839
8065
|
}
|
|
7840
8066
|
}
|
|
7841
8067
|
try {
|
|
7842
8068
|
const hasWalletBalance = await checkWalletBalanceStatus2(authConfig);
|
|
7843
8069
|
if (!hasWalletBalance) {
|
|
7844
|
-
console.log(
|
|
8070
|
+
console.log(import_chalk17.default.red("Insufficient wallet balance. Please recharge your wallet first."));
|
|
7845
8071
|
return;
|
|
7846
8072
|
}
|
|
7847
8073
|
} catch (e) {
|
|
@@ -7853,10 +8079,10 @@ async function bindCmd() {
|
|
|
7853
8079
|
try {
|
|
7854
8080
|
const check = await checkDomainAvailable(displayDomain);
|
|
7855
8081
|
if (!check.is_valid) {
|
|
7856
|
-
console.log(
|
|
8082
|
+
console.log(import_chalk17.default.red(`Domain not available: ${check.error || "unknown reason"}`));
|
|
7857
8083
|
return;
|
|
7858
8084
|
}
|
|
7859
|
-
console.log(
|
|
8085
|
+
console.log(import_chalk17.default.green(`Domain available: ${displayDomain}`));
|
|
7860
8086
|
} catch (e) {
|
|
7861
8087
|
if (e.message === "Token expired") {
|
|
7862
8088
|
return;
|
|
@@ -7864,34 +8090,34 @@ async function bindCmd() {
|
|
|
7864
8090
|
throw e;
|
|
7865
8091
|
}
|
|
7866
8092
|
const absolutePath = import_path9.default.resolve(targetPath);
|
|
7867
|
-
console.log(
|
|
8093
|
+
console.log(import_chalk17.default.blue(`Uploading: ${absolutePath}`));
|
|
7868
8094
|
const up = await uploadPath(absolutePath, { uid: authConfig.address });
|
|
7869
8095
|
if (!(up == null ? void 0 : up.contentHash)) {
|
|
7870
|
-
console.log(
|
|
8096
|
+
console.log(import_chalk17.default.red("Upload failed, binding aborted."));
|
|
7871
8097
|
return;
|
|
7872
8098
|
}
|
|
7873
|
-
console.log(
|
|
8099
|
+
console.log(import_chalk17.default.green(`Upload success, CID: ${up.contentHash}`));
|
|
7874
8100
|
try {
|
|
7875
8101
|
if (isDns) {
|
|
7876
|
-
console.log(
|
|
8102
|
+
console.log(import_chalk17.default.blue("Binding DNS domain..."));
|
|
7877
8103
|
const dnsResult = await bindDnsDomainV4(displayDomain, up.contentHash, authConfig.address, authConfig.token);
|
|
7878
8104
|
if (dnsResult.code !== 200) {
|
|
7879
|
-
console.log(
|
|
8105
|
+
console.log(import_chalk17.default.red(`DNS binding failed: ${dnsResult.msg}`));
|
|
7880
8106
|
return;
|
|
7881
8107
|
}
|
|
7882
|
-
console.log(
|
|
7883
|
-
console.log(
|
|
7884
|
-
console.log(
|
|
8108
|
+
console.log(import_chalk17.default.green(`DNS bind success: ${displayDomain}`));
|
|
8109
|
+
console.log(import_chalk17.default.white(`Visit: https://${displayDomain}`));
|
|
8110
|
+
console.log(import_chalk17.default.cyan("\n\u{1F4DA} DNS Setup Guide: https://pinme.eth.limo/#/docs?id=custom-domain"));
|
|
7885
8111
|
} else {
|
|
7886
|
-
console.log(
|
|
8112
|
+
console.log(import_chalk17.default.blue("Binding Pinme subdomain..."));
|
|
7887
8113
|
const ok = await bindPinmeDomain(displayDomain, up.contentHash);
|
|
7888
8114
|
if (!ok) {
|
|
7889
|
-
console.log(
|
|
8115
|
+
console.log(import_chalk17.default.red("Binding failed. Please try again later."));
|
|
7890
8116
|
return;
|
|
7891
8117
|
}
|
|
7892
|
-
console.log(
|
|
8118
|
+
console.log(import_chalk17.default.green(`Bind success: ${displayDomain}`));
|
|
7893
8119
|
const rootDomain = await getRootDomain();
|
|
7894
|
-
console.log(
|
|
8120
|
+
console.log(import_chalk17.default.white(`Visit: https://${displayDomain}.${rootDomain}`));
|
|
7895
8121
|
}
|
|
7896
8122
|
} catch (e) {
|
|
7897
8123
|
if (e.message === "Token expired") {
|
|
@@ -7900,12 +8126,12 @@ async function bindCmd() {
|
|
|
7900
8126
|
throw e;
|
|
7901
8127
|
}
|
|
7902
8128
|
} catch (e) {
|
|
7903
|
-
|
|
8129
|
+
printCliError(e, "Bind failed.");
|
|
7904
8130
|
}
|
|
7905
8131
|
}
|
|
7906
8132
|
|
|
7907
8133
|
// bin/login.ts
|
|
7908
|
-
var
|
|
8134
|
+
var import_chalk18 = __toESM(require("chalk"));
|
|
7909
8135
|
init_webLogin();
|
|
7910
8136
|
init_pinmeApi();
|
|
7911
8137
|
var ENV_URLS = {
|
|
@@ -7919,27 +8145,27 @@ async function loginCmd(options = {}) {
|
|
|
7919
8145
|
const env = (options.env || "prod").toLowerCase();
|
|
7920
8146
|
if (ENV_URLS[env]) {
|
|
7921
8147
|
webBaseUrl = ENV_URLS[env];
|
|
7922
|
-
console.log(
|
|
8148
|
+
console.log(import_chalk18.default.blue(`Using ${env} environment: ${webBaseUrl}`));
|
|
7923
8149
|
} else {
|
|
7924
8150
|
console.log(
|
|
7925
|
-
|
|
8151
|
+
import_chalk18.default.yellow(
|
|
7926
8152
|
`Unknown environment: ${options.env}. Using default prod.`
|
|
7927
8153
|
)
|
|
7928
8154
|
);
|
|
7929
8155
|
webBaseUrl = ENV_URLS.prod;
|
|
7930
|
-
console.log(
|
|
8156
|
+
console.log(import_chalk18.default.blue(`Using prod environment: ${webBaseUrl}`));
|
|
7931
8157
|
}
|
|
7932
8158
|
const manager = new WebLoginManager({ webBaseUrl });
|
|
7933
8159
|
await manager.login();
|
|
7934
|
-
console.log(
|
|
8160
|
+
console.log(import_chalk18.default.blue("\nMerging history..."));
|
|
7935
8161
|
const deviceId = getDeviceId();
|
|
7936
8162
|
const ok = await bindAnonymousDevice(deviceId);
|
|
7937
8163
|
if (ok) {
|
|
7938
|
-
console.log(
|
|
8164
|
+
console.log(import_chalk18.default.green("History merged to your account"));
|
|
7939
8165
|
}
|
|
7940
8166
|
process.exit(0);
|
|
7941
8167
|
} catch (e) {
|
|
7942
|
-
console.log(
|
|
8168
|
+
console.log(import_chalk18.default.red(`
|
|
7943
8169
|
Login failed: ${(e == null ? void 0 : e.message) || e}`));
|
|
7944
8170
|
process.exit(1);
|
|
7945
8171
|
}
|
|
@@ -7958,7 +8184,7 @@ init_webLogin();
|
|
|
7958
8184
|
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
7959
8185
|
var import_os4 = __toESM(require("os"));
|
|
7960
8186
|
var import_path10 = __toESM(require("path"));
|
|
7961
|
-
var
|
|
8187
|
+
var import_chalk19 = __toESM(require("chalk"));
|
|
7962
8188
|
var import_child_process2 = require("child_process");
|
|
7963
8189
|
function makeTempCacheDir() {
|
|
7964
8190
|
return import_fs_extra5.default.mkdtempSync(import_path10.default.join(import_os4.default.tmpdir(), "pinme-npm-cache-"));
|
|
@@ -7981,7 +8207,7 @@ function installProjectDependencies(cwd) {
|
|
|
7981
8207
|
const cacheDir = makeTempCacheDir();
|
|
7982
8208
|
try {
|
|
7983
8209
|
if (attempt > 1) {
|
|
7984
|
-
console.log(
|
|
8210
|
+
console.log(import_chalk19.default.yellow(" Retrying dependency install with a fresh npm cache..."));
|
|
7985
8211
|
}
|
|
7986
8212
|
runInstall(cwd, cacheDir);
|
|
7987
8213
|
return;
|
|
@@ -7994,155 +8220,8 @@ function installProjectDependencies(cwd) {
|
|
|
7994
8220
|
throw lastError;
|
|
7995
8221
|
}
|
|
7996
8222
|
|
|
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
8223
|
// bin/create.ts
|
|
8224
|
+
init_cliError();
|
|
8146
8225
|
init_config();
|
|
8147
8226
|
var PROJECT_DIR = process.cwd();
|
|
8148
8227
|
var TEMPLATE_BRANCH = "feat/auth";
|
|
@@ -8601,6 +8680,7 @@ init_axios2();
|
|
|
8601
8680
|
var import_child_process4 = require("child_process");
|
|
8602
8681
|
init_webLogin();
|
|
8603
8682
|
init_pinmeApi();
|
|
8683
|
+
init_cliError();
|
|
8604
8684
|
init_config();
|
|
8605
8685
|
var PROJECT_DIR2 = process.cwd();
|
|
8606
8686
|
function loadConfig() {
|
|
@@ -8931,6 +9011,7 @@ var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
|
8931
9011
|
var import_path13 = __toESM(require("path"));
|
|
8932
9012
|
init_axios2();
|
|
8933
9013
|
init_webLogin();
|
|
9014
|
+
init_cliError();
|
|
8934
9015
|
init_config();
|
|
8935
9016
|
var PROJECT_DIR3 = process.cwd();
|
|
8936
9017
|
function loadConfig2() {
|
|
@@ -9064,6 +9145,7 @@ var import_path14 = __toESM(require("path"));
|
|
|
9064
9145
|
init_axios2();
|
|
9065
9146
|
var import_child_process5 = require("child_process");
|
|
9066
9147
|
init_webLogin();
|
|
9148
|
+
init_cliError();
|
|
9067
9149
|
init_config();
|
|
9068
9150
|
var PROJECT_DIR4 = process.cwd();
|
|
9069
9151
|
function loadConfig3() {
|
|
@@ -9246,6 +9328,7 @@ var import_fs_extra10 = __toESM(require("fs-extra"));
|
|
|
9246
9328
|
var import_path15 = __toESM(require("path"));
|
|
9247
9329
|
var import_child_process6 = require("child_process");
|
|
9248
9330
|
init_webLogin();
|
|
9331
|
+
init_cliError();
|
|
9249
9332
|
init_config();
|
|
9250
9333
|
var PROJECT_DIR5 = process.cwd();
|
|
9251
9334
|
function loadConfig4() {
|