pinme 2.0.2-beta.11 → 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 +703 -561
- 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(/\/+$/, "");
|
|
@@ -4755,6 +4931,7 @@ var init_config = __esm({
|
|
|
4755
4931
|
),
|
|
4756
4932
|
pinmeCheckDomainPath: process.env.PINME_CHECK_DOMAIN_PATH || "/check_domain",
|
|
4757
4933
|
ipfsPreviewUrl: "https://pinme.eth.limo/#/preview/",
|
|
4934
|
+
projectPeviewUrl: "https://test-pinme.pinit.eth.limo/#/console/projects/",
|
|
4758
4935
|
secretKey: "pinme-secret-key",
|
|
4759
4936
|
pinmeProjectName: (_a = process.env.PINME_PROJECT_NAME) == null ? void 0 : _a.trim(),
|
|
4760
4937
|
upload: {
|
|
@@ -4782,7 +4959,7 @@ function openBrowser(url2) {
|
|
|
4782
4959
|
}
|
|
4783
4960
|
(0, import_child_process.exec)(command, (err) => {
|
|
4784
4961
|
if (err) {
|
|
4785
|
-
console.log(
|
|
4962
|
+
console.log(import_chalk3.default.yellow(`Unable to open browser automatically. Please visit manually: ${url2}`));
|
|
4786
4963
|
}
|
|
4787
4964
|
});
|
|
4788
4965
|
}
|
|
@@ -4830,13 +5007,13 @@ function getAuthHeaders() {
|
|
|
4830
5007
|
"authentication-tokens": conf.token
|
|
4831
5008
|
};
|
|
4832
5009
|
}
|
|
4833
|
-
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;
|
|
4834
5011
|
var init_webLogin = __esm({
|
|
4835
5012
|
"bin/utils/webLogin.ts"() {
|
|
4836
5013
|
import_crypto = __toESM(require("crypto"));
|
|
4837
5014
|
import_http3 = __toESM(require("http"));
|
|
4838
5015
|
import_url2 = require("url");
|
|
4839
|
-
|
|
5016
|
+
import_chalk3 = __toESM(require("chalk"));
|
|
4840
5017
|
import_child_process = require("child_process");
|
|
4841
5018
|
import_fs_extra = __toESM(require("fs-extra"));
|
|
4842
5019
|
import_os = __toESM(require("os"));
|
|
@@ -4860,30 +5037,30 @@ var init_webLogin = __esm({
|
|
|
4860
5037
|
this.config = { ...DEFAULT_OPTIONS, ...options };
|
|
4861
5038
|
}
|
|
4862
5039
|
async login() {
|
|
4863
|
-
console.log(
|
|
5040
|
+
console.log(import_chalk3.default.blue("Starting login flow...\n"));
|
|
4864
5041
|
this.loginToken = this.generateLoginToken();
|
|
4865
|
-
console.log(
|
|
5042
|
+
console.log(import_chalk3.default.blue("Starting local callback server..."));
|
|
4866
5043
|
await this.startCallbackServer();
|
|
4867
5044
|
try {
|
|
4868
5045
|
const loginUrl = this.buildLoginUrl();
|
|
4869
|
-
console.log(
|
|
4870
|
-
console.log(
|
|
4871
|
-
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}
|
|
4872
5049
|
`));
|
|
4873
5050
|
openBrowser(loginUrl);
|
|
4874
|
-
console.log(
|
|
4875
|
-
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"));
|
|
4876
5053
|
const authToken = await this.waitForCallback();
|
|
4877
5054
|
const authConfig = this.parseAuthToken(authToken);
|
|
4878
5055
|
this.saveAuthConfig(authConfig);
|
|
4879
|
-
console.log(
|
|
5056
|
+
console.log(import_chalk3.default.green("\nLogin successful!"));
|
|
4880
5057
|
if (authConfig.email) {
|
|
4881
|
-
console.log(
|
|
5058
|
+
console.log(import_chalk3.default.green(`Welcome, ${authConfig.email}`));
|
|
4882
5059
|
}
|
|
4883
|
-
console.log(
|
|
5060
|
+
console.log(import_chalk3.default.gray(`Address: ${authConfig.address}`));
|
|
4884
5061
|
return authConfig;
|
|
4885
5062
|
} catch (error) {
|
|
4886
|
-
console.error(
|
|
5063
|
+
console.error(import_chalk3.default.red(`
|
|
4887
5064
|
Login failed: ${error.message}`));
|
|
4888
5065
|
throw error;
|
|
4889
5066
|
} finally {
|
|
@@ -4945,7 +5122,7 @@ Login failed: ${error.message}`));
|
|
|
4945
5122
|
reject(err);
|
|
4946
5123
|
});
|
|
4947
5124
|
this.server.listen(this.config.callbackPort, "127.0.0.1", () => {
|
|
4948
|
-
console.log(
|
|
5125
|
+
console.log(import_chalk3.default.gray(`Local server: http://localhost:${this.config.callbackPort}`));
|
|
4949
5126
|
resolve();
|
|
4950
5127
|
});
|
|
4951
5128
|
setTimeout(() => {
|
|
@@ -5279,6 +5456,30 @@ function safeGetAuthHeaders() {
|
|
|
5279
5456
|
return {};
|
|
5280
5457
|
}
|
|
5281
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
|
+
}
|
|
5282
5483
|
function createApiClient(options = {}) {
|
|
5283
5484
|
const {
|
|
5284
5485
|
baseURL = APP_CONFIG.pinmeApiBase,
|
|
@@ -5299,8 +5500,19 @@ function createApiClient(options = {}) {
|
|
|
5299
5500
|
}
|
|
5300
5501
|
});
|
|
5301
5502
|
client.interceptors.response.use(
|
|
5302
|
-
(response) =>
|
|
5303
|
-
|
|
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
|
+
)
|
|
5304
5516
|
);
|
|
5305
5517
|
return client;
|
|
5306
5518
|
}
|
|
@@ -5319,6 +5531,7 @@ function createCarApiClient(options = {}) {
|
|
|
5319
5531
|
var init_apiClient = __esm({
|
|
5320
5532
|
"bin/utils/apiClient.ts"() {
|
|
5321
5533
|
init_axios2();
|
|
5534
|
+
init_cliError();
|
|
5322
5535
|
init_webLogin();
|
|
5323
5536
|
init_config();
|
|
5324
5537
|
}
|
|
@@ -5355,8 +5568,8 @@ function isTokenExpired(error) {
|
|
|
5355
5568
|
);
|
|
5356
5569
|
}
|
|
5357
5570
|
function showTokenExpiredHint() {
|
|
5358
|
-
console.log(
|
|
5359
|
-
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"));
|
|
5360
5573
|
}
|
|
5361
5574
|
async function bindAnonymousDevice(anonymousUid) {
|
|
5362
5575
|
try {
|
|
@@ -5371,7 +5584,7 @@ async function bindAnonymousDevice(anonymousUid) {
|
|
|
5371
5584
|
return false;
|
|
5372
5585
|
}
|
|
5373
5586
|
console.log(
|
|
5374
|
-
|
|
5587
|
+
import_chalk4.default.yellow(`Failed to trigger anonymous binding: ${(e == null ? void 0 : e.message) || e}`)
|
|
5375
5588
|
);
|
|
5376
5589
|
return false;
|
|
5377
5590
|
}
|
|
@@ -5390,10 +5603,11 @@ async function getRootDomain(forceRefresh = false) {
|
|
|
5390
5603
|
throw new Error((data == null ? void 0 : data.msg) || "Failed to get root domain");
|
|
5391
5604
|
}
|
|
5392
5605
|
async function checkDomainAvailable(domainName) {
|
|
5393
|
-
var _a2;
|
|
5606
|
+
var _a2, _b;
|
|
5394
5607
|
const client = createPinmeApiClient();
|
|
5395
5608
|
const configured = APP_CONFIG.pinmeCheckDomainPath;
|
|
5396
5609
|
const fallbacks = [configured, "/check_domain_available"];
|
|
5610
|
+
let lastRecoverableError;
|
|
5397
5611
|
for (const p of fallbacks) {
|
|
5398
5612
|
try {
|
|
5399
5613
|
const { data } = await client.post(p, { domain_name: domainName });
|
|
@@ -5408,8 +5622,16 @@ async function checkDomainAvailable(domainName) {
|
|
|
5408
5622
|
showTokenExpiredHint();
|
|
5409
5623
|
throw new Error("Token expired");
|
|
5410
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;
|
|
5411
5630
|
}
|
|
5412
5631
|
}
|
|
5632
|
+
if (lastRecoverableError) {
|
|
5633
|
+
throw lastRecoverableError;
|
|
5634
|
+
}
|
|
5413
5635
|
return { is_valid: true };
|
|
5414
5636
|
}
|
|
5415
5637
|
async function bindPinmeDomain(domainName, hash, projectName) {
|
|
@@ -5572,10 +5794,10 @@ async function checkCarExportStatus(taskId) {
|
|
|
5572
5794
|
throw new Error(`Failed to check export status: ${(e == null ? void 0 : e.message) || e}`);
|
|
5573
5795
|
}
|
|
5574
5796
|
}
|
|
5575
|
-
var
|
|
5797
|
+
var import_chalk4, TOKEN_EXPIRED_CODES, TOKEN_EXPIRED_MESSAGES, rootDomainCache;
|
|
5576
5798
|
var init_pinmeApi = __esm({
|
|
5577
5799
|
"bin/utils/pinmeApi.ts"() {
|
|
5578
|
-
|
|
5800
|
+
import_chalk4 = __toESM(require("chalk"));
|
|
5579
5801
|
init_apiClient();
|
|
5580
5802
|
init_config();
|
|
5581
5803
|
TOKEN_EXPIRED_CODES = [
|
|
@@ -5643,15 +5865,15 @@ function checkNodeVersion() {
|
|
|
5643
5865
|
|
|
5644
5866
|
// bin/index.ts
|
|
5645
5867
|
var import_commander = require("commander");
|
|
5646
|
-
var
|
|
5868
|
+
var import_chalk26 = __toESM(require("chalk"));
|
|
5647
5869
|
var import_figlet5 = __toESM(require("figlet"));
|
|
5648
5870
|
|
|
5649
5871
|
// package.json
|
|
5650
|
-
var version = "2.0.2-beta.
|
|
5872
|
+
var version = "2.0.2-beta.13";
|
|
5651
5873
|
|
|
5652
5874
|
// bin/upload.ts
|
|
5653
5875
|
var import_path6 = __toESM(require("path"));
|
|
5654
|
-
var
|
|
5876
|
+
var import_chalk7 = __toESM(require("chalk"));
|
|
5655
5877
|
var import_inquirer = __toESM(require("inquirer"));
|
|
5656
5878
|
var import_figlet = __toESM(require("figlet"));
|
|
5657
5879
|
var import_fs2 = __toESM(require("fs"));
|
|
@@ -5708,6 +5930,9 @@ function validateDnsDomain(domain) {
|
|
|
5708
5930
|
return { valid: true };
|
|
5709
5931
|
}
|
|
5710
5932
|
|
|
5933
|
+
// bin/upload.ts
|
|
5934
|
+
init_cliError();
|
|
5935
|
+
|
|
5711
5936
|
// bin/services/uploadService.ts
|
|
5712
5937
|
var import_crypto_js = __toESM(require("crypto-js"));
|
|
5713
5938
|
|
|
@@ -5793,7 +6018,7 @@ var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
|
5793
6018
|
var import_path4 = __toESM(require("path"));
|
|
5794
6019
|
var import_os3 = __toESM(require("os"));
|
|
5795
6020
|
var import_dayjs = __toESM(require("dayjs"));
|
|
5796
|
-
var
|
|
6021
|
+
var import_chalk5 = __toESM(require("chalk"));
|
|
5797
6022
|
init_pinmeApi();
|
|
5798
6023
|
var HISTORY_DIR = import_path4.default.join(import_os3.default.homedir(), ".pinme");
|
|
5799
6024
|
var HISTORY_FILE = import_path4.default.join(HISTORY_DIR, "upload-history.json");
|
|
@@ -5827,7 +6052,7 @@ var saveUploadHistory = (uploadData) => {
|
|
|
5827
6052
|
import_fs_extra3.default.writeJsonSync(HISTORY_FILE, history, { spaces: 2 });
|
|
5828
6053
|
return true;
|
|
5829
6054
|
} catch (error) {
|
|
5830
|
-
console.error(
|
|
6055
|
+
console.error(import_chalk5.default.red(`Error saving upload history: ${error.message}`));
|
|
5831
6056
|
return false;
|
|
5832
6057
|
}
|
|
5833
6058
|
};
|
|
@@ -5837,7 +6062,7 @@ var getUploadHistory = (limit = 10) => {
|
|
|
5837
6062
|
const history = import_fs_extra3.default.readJsonSync(HISTORY_FILE);
|
|
5838
6063
|
return history.uploads.slice(0, limit);
|
|
5839
6064
|
} catch (error) {
|
|
5840
|
-
console.error(
|
|
6065
|
+
console.error(import_chalk5.default.red(`Error reading upload history: ${error.message}`));
|
|
5841
6066
|
return [];
|
|
5842
6067
|
}
|
|
5843
6068
|
};
|
|
@@ -5874,11 +6099,11 @@ async function formatHistoryUrl(value, options) {
|
|
|
5874
6099
|
var displayUploadHistory = async (limit = 10) => {
|
|
5875
6100
|
const history = getUploadHistory(limit);
|
|
5876
6101
|
if (history.length === 0) {
|
|
5877
|
-
console.log(
|
|
6102
|
+
console.log(import_chalk5.default.yellow("No upload history found."));
|
|
5878
6103
|
return;
|
|
5879
6104
|
}
|
|
5880
|
-
console.log(
|
|
5881
|
-
console.log(
|
|
6105
|
+
console.log(import_chalk5.default.cyan("Upload History:"));
|
|
6106
|
+
console.log(import_chalk5.default.cyan("-".repeat(80)));
|
|
5882
6107
|
let rootDomain = null;
|
|
5883
6108
|
try {
|
|
5884
6109
|
rootDomain = await getRootDomain();
|
|
@@ -5887,9 +6112,9 @@ var displayUploadHistory = async (limit = 10) => {
|
|
|
5887
6112
|
}
|
|
5888
6113
|
const recentHistory = history.slice(-limit);
|
|
5889
6114
|
for (const [index, item] of recentHistory.entries()) {
|
|
5890
|
-
console.log(
|
|
5891
|
-
console.log(
|
|
5892
|
-
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}`));
|
|
5893
6118
|
const preferredUrl = await formatHistoryUrl(item.dnsUrl) || await formatHistoryUrl(item.pinmeUrl, {
|
|
5894
6119
|
appendRootDomain: true,
|
|
5895
6120
|
rootDomain
|
|
@@ -5898,30 +6123,30 @@ var displayUploadHistory = async (limit = 10) => {
|
|
|
5898
6123
|
rootDomain
|
|
5899
6124
|
});
|
|
5900
6125
|
if (preferredUrl) {
|
|
5901
|
-
console.log(
|
|
6126
|
+
console.log(import_chalk5.default.white(` URL: ${preferredUrl}`));
|
|
5902
6127
|
}
|
|
5903
|
-
console.log(
|
|
5904
|
-
console.log(
|
|
5905
|
-
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"}`));
|
|
5906
6131
|
if (item.timestamp) {
|
|
5907
|
-
console.log(
|
|
6132
|
+
console.log(import_chalk5.default.white(` Date: ${new Date(item.timestamp).toLocaleString()}`));
|
|
5908
6133
|
}
|
|
5909
|
-
console.log(
|
|
6134
|
+
console.log(import_chalk5.default.cyan("-".repeat(80)));
|
|
5910
6135
|
}
|
|
5911
6136
|
const totalSize = history.reduce((sum, record) => sum + record.size, 0);
|
|
5912
6137
|
const totalFiles = history.reduce((sum, record) => sum + record.fileCount, 0);
|
|
5913
|
-
console.log(
|
|
5914
|
-
console.log(
|
|
5915
|
-
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)}`));
|
|
5916
6141
|
};
|
|
5917
6142
|
var clearUploadHistory = () => {
|
|
5918
6143
|
try {
|
|
5919
6144
|
ensureHistoryDir();
|
|
5920
6145
|
import_fs_extra3.default.writeJsonSync(HISTORY_FILE, { uploads: [] });
|
|
5921
|
-
console.log(
|
|
6146
|
+
console.log(import_chalk5.default.green("Upload history cleared successfully."));
|
|
5922
6147
|
return true;
|
|
5923
6148
|
} catch (error) {
|
|
5924
|
-
console.error(
|
|
6149
|
+
console.error(import_chalk5.default.red(`Error clearing upload history: ${error.message}`));
|
|
5925
6150
|
return false;
|
|
5926
6151
|
}
|
|
5927
6152
|
};
|
|
@@ -6623,10 +6848,11 @@ async function formatPreferredUrl(value, options) {
|
|
|
6623
6848
|
return withProtocol.replace(/\/$/, "");
|
|
6624
6849
|
}
|
|
6625
6850
|
}
|
|
6626
|
-
async function resolveUploadUrls(contentHash, urls, uid) {
|
|
6851
|
+
async function resolveUploadUrls(contentHash, urls, projectName, uid) {
|
|
6627
6852
|
const resolvedUid = (uid == null ? void 0 : uid.trim()) || getUid();
|
|
6628
6853
|
const encryptedCID = encryptHash(contentHash, APP_CONFIG.secretKey, resolvedUid);
|
|
6629
|
-
const
|
|
6854
|
+
const normalizedProjectName = projectName == null ? void 0 : projectName.trim();
|
|
6855
|
+
const managementUrl = normalizedProjectName ? `${APP_CONFIG.projectPeviewUrl}${normalizedProjectName}` : `${APP_CONFIG.ipfsPreviewUrl}${encryptedCID}`;
|
|
6630
6856
|
const publicUrl = await formatPreferredUrl(urls == null ? void 0 : urls.dnsUrl) || await formatPreferredUrl(urls == null ? void 0 : urls.pinmeUrl, { appendRootDomain: true }) || await formatShortUrl(urls == null ? void 0 : urls.shortUrl) || managementUrl;
|
|
6631
6857
|
return {
|
|
6632
6858
|
publicUrl,
|
|
@@ -6653,6 +6879,7 @@ async function uploadPath(targetPath, options = {}) {
|
|
|
6653
6879
|
pinmeUrl: result.pinmeUrl,
|
|
6654
6880
|
shortUrl: result.shortUrl
|
|
6655
6881
|
},
|
|
6882
|
+
options.projectName,
|
|
6656
6883
|
options.uid
|
|
6657
6884
|
);
|
|
6658
6885
|
return {
|
|
@@ -6665,6 +6892,19 @@ async function uploadPath(targetPath, options = {}) {
|
|
|
6665
6892
|
};
|
|
6666
6893
|
}
|
|
6667
6894
|
|
|
6895
|
+
// bin/utils/urlDisplay.ts
|
|
6896
|
+
var import_chalk6 = __toESM(require("chalk"));
|
|
6897
|
+
function printHighlightedUrl(label, url2, tone = "primary") {
|
|
6898
|
+
const safeLabel = label.trim() || "URL";
|
|
6899
|
+
const safeUrl = url2.trim();
|
|
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;
|
|
6902
|
+
console.log("");
|
|
6903
|
+
console.log(labelStyle(` ${safeLabel} `));
|
|
6904
|
+
console.log(urlStyle(safeUrl));
|
|
6905
|
+
console.log("");
|
|
6906
|
+
}
|
|
6907
|
+
|
|
6668
6908
|
// bin/upload.ts
|
|
6669
6909
|
checkNodeVersion();
|
|
6670
6910
|
function checkPathSync(inputPath) {
|
|
@@ -6675,7 +6915,7 @@ function checkPathSync(inputPath) {
|
|
|
6675
6915
|
}
|
|
6676
6916
|
return null;
|
|
6677
6917
|
} catch (error) {
|
|
6678
|
-
console.error(
|
|
6918
|
+
console.error(import_chalk7.default.red(`error checking path: ${error.message}`));
|
|
6679
6919
|
return null;
|
|
6680
6920
|
}
|
|
6681
6921
|
}
|
|
@@ -6687,17 +6927,11 @@ async function printUploadUrls(result) {
|
|
|
6687
6927
|
dnsUrl: result.dnsUrl,
|
|
6688
6928
|
pinmeUrl: result.pinmeUrl,
|
|
6689
6929
|
shortUrl: result.shortUrl
|
|
6690
|
-
}
|
|
6930
|
+
},
|
|
6931
|
+
projectName
|
|
6691
6932
|
);
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
console.log(import_chalk5.default.cyan(publicUrl));
|
|
6695
|
-
console.log(import_chalk5.default.cyan(`Management page:`));
|
|
6696
|
-
console.log(import_chalk5.default.cyan(managementUrl));
|
|
6697
|
-
return;
|
|
6698
|
-
}
|
|
6699
|
-
console.log(import_chalk5.default.cyan(`URL:`));
|
|
6700
|
-
console.log(import_chalk5.default.cyan(publicUrl));
|
|
6933
|
+
printHighlightedUrl("URL", publicUrl, "primary");
|
|
6934
|
+
printHighlightedUrl("Management URL", managementUrl, "management");
|
|
6701
6935
|
}
|
|
6702
6936
|
function getDomainFromArgs() {
|
|
6703
6937
|
const args = process.argv.slice(2);
|
|
@@ -6713,45 +6947,59 @@ function getDnsFromArgs() {
|
|
|
6713
6947
|
}
|
|
6714
6948
|
async function checkWalletBalanceStatus(authConfig) {
|
|
6715
6949
|
var _a2;
|
|
6716
|
-
console.log(
|
|
6950
|
+
console.log(import_chalk7.default.blue("Checking wallet balance..."));
|
|
6717
6951
|
try {
|
|
6718
|
-
const balanceResult = await getWalletBalance(
|
|
6952
|
+
const balanceResult = await getWalletBalance(
|
|
6953
|
+
authConfig.address,
|
|
6954
|
+
authConfig.token
|
|
6955
|
+
);
|
|
6719
6956
|
const balance = Number(((_a2 = balanceResult.data) == null ? void 0 : _a2.wallet_balance_usd) ?? 0);
|
|
6720
6957
|
if (!Number.isFinite(balance) || balance <= 0) {
|
|
6721
6958
|
return false;
|
|
6722
6959
|
}
|
|
6723
|
-
console.log(
|
|
6960
|
+
console.log(
|
|
6961
|
+
import_chalk7.default.green(`Wallet balance available: $${balance.toFixed(2)}`)
|
|
6962
|
+
);
|
|
6724
6963
|
return true;
|
|
6725
6964
|
} catch (e) {
|
|
6726
|
-
if (e.message === "Token expired") {
|
|
6965
|
+
if (e.message === "Token expired" || (e == null ? void 0 : e.name) === "CliError") {
|
|
6727
6966
|
throw e;
|
|
6728
6967
|
}
|
|
6729
|
-
console.log(
|
|
6968
|
+
console.log(import_chalk7.default.yellow("Failed to check wallet balance, continuing..."));
|
|
6730
6969
|
return true;
|
|
6731
6970
|
}
|
|
6732
6971
|
}
|
|
6733
6972
|
async function bindDomain(domain, contentHash, isDns, authConfig) {
|
|
6734
6973
|
const displayDomain = normalizeDomain(domain);
|
|
6735
6974
|
if (isDns) {
|
|
6736
|
-
console.log(
|
|
6737
|
-
const dnsResult = await bindDnsDomainV4(
|
|
6975
|
+
console.log(import_chalk7.default.blue("Binding DNS domain..."));
|
|
6976
|
+
const dnsResult = await bindDnsDomainV4(
|
|
6977
|
+
displayDomain,
|
|
6978
|
+
contentHash,
|
|
6979
|
+
authConfig.address,
|
|
6980
|
+
authConfig.token
|
|
6981
|
+
);
|
|
6738
6982
|
if (dnsResult.code !== 200) {
|
|
6739
|
-
console.log(
|
|
6983
|
+
console.log(import_chalk7.default.red(`DNS binding failed: ${dnsResult.msg}`));
|
|
6740
6984
|
return false;
|
|
6741
6985
|
}
|
|
6742
|
-
console.log(
|
|
6743
|
-
console.log(
|
|
6744
|
-
console.log(
|
|
6986
|
+
console.log(import_chalk7.default.green(`DNS bind success: ${displayDomain}`));
|
|
6987
|
+
console.log(import_chalk7.default.white(`Visit: https://${displayDomain}`));
|
|
6988
|
+
console.log(
|
|
6989
|
+
import_chalk7.default.cyan(
|
|
6990
|
+
"\n\u{1F4DA} DNS Setup Guide: https://pinme.eth.limo/#/docs?id=custom-domain"
|
|
6991
|
+
)
|
|
6992
|
+
);
|
|
6745
6993
|
} else {
|
|
6746
|
-
console.log(
|
|
6994
|
+
console.log(import_chalk7.default.blue("Binding Pinme subdomain..."));
|
|
6747
6995
|
const ok = await bindPinmeDomain(displayDomain, contentHash);
|
|
6748
6996
|
if (!ok) {
|
|
6749
|
-
console.log(
|
|
6997
|
+
console.log(import_chalk7.default.red("Binding failed. Please try again later."));
|
|
6750
6998
|
return false;
|
|
6751
6999
|
}
|
|
6752
|
-
console.log(
|
|
7000
|
+
console.log(import_chalk7.default.green(`Bind success: ${displayDomain}`));
|
|
6753
7001
|
const rootDomain = await (await Promise.resolve().then(() => (init_pinmeApi(), pinmeApi_exports))).getRootDomain();
|
|
6754
|
-
console.log(
|
|
7002
|
+
console.log(import_chalk7.default.white(`Visit: https://${displayDomain}.${rootDomain}`));
|
|
6755
7003
|
}
|
|
6756
7004
|
return true;
|
|
6757
7005
|
}
|
|
@@ -6768,7 +7016,7 @@ var upload_default = async (options) => {
|
|
|
6768
7016
|
);
|
|
6769
7017
|
const authConfig = getAuthConfig();
|
|
6770
7018
|
if (!authConfig) {
|
|
6771
|
-
console.log(
|
|
7019
|
+
console.log(import_chalk7.default.red("Please login first. Run: pinme login"));
|
|
6772
7020
|
return;
|
|
6773
7021
|
}
|
|
6774
7022
|
const domainArg = getDomainFromArgs();
|
|
@@ -6777,7 +7025,7 @@ var upload_default = async (options) => {
|
|
|
6777
7025
|
if (argPath && !argPath.startsWith("-")) {
|
|
6778
7026
|
const absolutePath = checkPathSync(argPath);
|
|
6779
7027
|
if (!absolutePath) {
|
|
6780
|
-
console.log(
|
|
7028
|
+
console.log(import_chalk7.default.red(`path ${argPath} does not exist`));
|
|
6781
7029
|
return;
|
|
6782
7030
|
}
|
|
6783
7031
|
const isDns = dnsArg || (domainArg ? isDnsDomain(domainArg) : false);
|
|
@@ -6785,7 +7033,7 @@ var upload_default = async (options) => {
|
|
|
6785
7033
|
if (isDns && domainArg) {
|
|
6786
7034
|
const validation = validateDnsDomain(domainArg);
|
|
6787
7035
|
if (!validation.valid) {
|
|
6788
|
-
console.log(
|
|
7036
|
+
console.log(import_chalk7.default.red(validation.message));
|
|
6789
7037
|
return;
|
|
6790
7038
|
}
|
|
6791
7039
|
}
|
|
@@ -6793,7 +7041,11 @@ var upload_default = async (options) => {
|
|
|
6793
7041
|
try {
|
|
6794
7042
|
const hasWalletBalance = await checkWalletBalanceStatus(authConfig);
|
|
6795
7043
|
if (!hasWalletBalance) {
|
|
6796
|
-
console.log(
|
|
7044
|
+
console.log(
|
|
7045
|
+
import_chalk7.default.red(
|
|
7046
|
+
"Insufficient wallet balance. Please recharge your wallet first."
|
|
7047
|
+
)
|
|
7048
|
+
);
|
|
6797
7049
|
return;
|
|
6798
7050
|
}
|
|
6799
7051
|
} catch (e) {
|
|
@@ -6808,13 +7060,13 @@ var upload_default = async (options) => {
|
|
|
6808
7060
|
const check = await checkDomainAvailable(displayDomain);
|
|
6809
7061
|
if (!check.is_valid) {
|
|
6810
7062
|
console.log(
|
|
6811
|
-
|
|
7063
|
+
import_chalk7.default.red(
|
|
6812
7064
|
`Domain not available: ${check.error || "unknown reason"}`
|
|
6813
7065
|
)
|
|
6814
7066
|
);
|
|
6815
7067
|
return;
|
|
6816
7068
|
}
|
|
6817
|
-
console.log(
|
|
7069
|
+
console.log(import_chalk7.default.green(`Domain available: ${displayDomain}`));
|
|
6818
7070
|
} catch (e) {
|
|
6819
7071
|
if (e.message === "Token expired") {
|
|
6820
7072
|
return;
|
|
@@ -6822,7 +7074,7 @@ var upload_default = async (options) => {
|
|
|
6822
7074
|
throw e;
|
|
6823
7075
|
}
|
|
6824
7076
|
}
|
|
6825
|
-
console.log(
|
|
7077
|
+
console.log(import_chalk7.default.blue(`uploading ${absolutePath} to ipfs...`));
|
|
6826
7078
|
let result;
|
|
6827
7079
|
try {
|
|
6828
7080
|
result = await uploadPath(absolutePath, {
|
|
@@ -6830,22 +7082,20 @@ var upload_default = async (options) => {
|
|
|
6830
7082
|
uid: authConfig == null ? void 0 : authConfig.address
|
|
6831
7083
|
});
|
|
6832
7084
|
} catch (error) {
|
|
6833
|
-
|
|
7085
|
+
printCliError(error, "Upload failed.");
|
|
6834
7086
|
process.exit(1);
|
|
6835
7087
|
}
|
|
6836
7088
|
if (!result) {
|
|
6837
|
-
console.error(
|
|
7089
|
+
console.error(import_chalk7.default.red("Upload failed: no result returned"));
|
|
6838
7090
|
process.exit(1);
|
|
6839
7091
|
}
|
|
6840
7092
|
console.log(
|
|
6841
|
-
|
|
6842
|
-
import_figlet.default.textSync("Successful", { horizontalLayout: "full" })
|
|
6843
|
-
)
|
|
7093
|
+
import_chalk7.default.cyan(import_figlet.default.textSync("Successful", { horizontalLayout: "full" }))
|
|
6844
7094
|
);
|
|
6845
7095
|
await printUploadUrls(result);
|
|
6846
7096
|
if (domainArg) {
|
|
6847
7097
|
console.log(
|
|
6848
|
-
|
|
7098
|
+
import_chalk7.default.blue(
|
|
6849
7099
|
`Binding domain: ${displayDomain} with CID: ${result.contentHash}`
|
|
6850
7100
|
)
|
|
6851
7101
|
);
|
|
@@ -6858,7 +7108,7 @@ var upload_default = async (options) => {
|
|
|
6858
7108
|
throw e;
|
|
6859
7109
|
}
|
|
6860
7110
|
}
|
|
6861
|
-
console.log(
|
|
7111
|
+
console.log(import_chalk7.default.green("\n\u{1F389} upload successful, program exit"));
|
|
6862
7112
|
process.exit(0);
|
|
6863
7113
|
}
|
|
6864
7114
|
const answer = await import_inquirer.default.prompt([
|
|
@@ -6871,7 +7121,7 @@ var upload_default = async (options) => {
|
|
|
6871
7121
|
if (answer.path) {
|
|
6872
7122
|
const absolutePath = checkPathSync(answer.path);
|
|
6873
7123
|
if (!absolutePath) {
|
|
6874
|
-
console.log(
|
|
7124
|
+
console.log(import_chalk7.default.red(`path ${answer.path} does not exist`));
|
|
6875
7125
|
return;
|
|
6876
7126
|
}
|
|
6877
7127
|
const isDns = dnsArg || (domainArg ? isDnsDomain(domainArg) : false);
|
|
@@ -6879,7 +7129,7 @@ var upload_default = async (options) => {
|
|
|
6879
7129
|
if (isDns && domainArg) {
|
|
6880
7130
|
const validation = validateDnsDomain(domainArg);
|
|
6881
7131
|
if (!validation.valid) {
|
|
6882
|
-
console.log(
|
|
7132
|
+
console.log(import_chalk7.default.red(validation.message));
|
|
6883
7133
|
return;
|
|
6884
7134
|
}
|
|
6885
7135
|
}
|
|
@@ -6887,7 +7137,11 @@ var upload_default = async (options) => {
|
|
|
6887
7137
|
try {
|
|
6888
7138
|
const hasWalletBalance = await checkWalletBalanceStatus(authConfig);
|
|
6889
7139
|
if (!hasWalletBalance) {
|
|
6890
|
-
console.log(
|
|
7140
|
+
console.log(
|
|
7141
|
+
import_chalk7.default.red(
|
|
7142
|
+
"Insufficient wallet balance. Please recharge your wallet first."
|
|
7143
|
+
)
|
|
7144
|
+
);
|
|
6891
7145
|
return;
|
|
6892
7146
|
}
|
|
6893
7147
|
} catch (e) {
|
|
@@ -6902,13 +7156,13 @@ var upload_default = async (options) => {
|
|
|
6902
7156
|
const check = await checkDomainAvailable(displayDomain);
|
|
6903
7157
|
if (!check.is_valid) {
|
|
6904
7158
|
console.log(
|
|
6905
|
-
|
|
7159
|
+
import_chalk7.default.red(
|
|
6906
7160
|
`Domain not available: ${check.error || "unknown reason"}`
|
|
6907
7161
|
)
|
|
6908
7162
|
);
|
|
6909
7163
|
return;
|
|
6910
7164
|
}
|
|
6911
|
-
console.log(
|
|
7165
|
+
console.log(import_chalk7.default.green(`Domain available: ${displayDomain}`));
|
|
6912
7166
|
} catch (e) {
|
|
6913
7167
|
if (e.message === "Token expired") {
|
|
6914
7168
|
return;
|
|
@@ -6916,7 +7170,7 @@ var upload_default = async (options) => {
|
|
|
6916
7170
|
throw e;
|
|
6917
7171
|
}
|
|
6918
7172
|
}
|
|
6919
|
-
console.log(
|
|
7173
|
+
console.log(import_chalk7.default.blue(`uploading ${absolutePath} to ipfs...`));
|
|
6920
7174
|
let result;
|
|
6921
7175
|
try {
|
|
6922
7176
|
result = await uploadPath(absolutePath, {
|
|
@@ -6924,22 +7178,20 @@ var upload_default = async (options) => {
|
|
|
6924
7178
|
uid: authConfig == null ? void 0 : authConfig.address
|
|
6925
7179
|
});
|
|
6926
7180
|
} catch (error) {
|
|
6927
|
-
|
|
7181
|
+
printCliError(error, "Upload failed.");
|
|
6928
7182
|
process.exit(1);
|
|
6929
7183
|
}
|
|
6930
7184
|
if (!result) {
|
|
6931
|
-
console.error(
|
|
7185
|
+
console.error(import_chalk7.default.red("Upload failed: no result returned"));
|
|
6932
7186
|
process.exit(1);
|
|
6933
7187
|
}
|
|
6934
7188
|
console.log(
|
|
6935
|
-
|
|
6936
|
-
import_figlet.default.textSync("Successful", { horizontalLayout: "full" })
|
|
6937
|
-
)
|
|
7189
|
+
import_chalk7.default.cyan(import_figlet.default.textSync("Successful", { horizontalLayout: "full" }))
|
|
6938
7190
|
);
|
|
6939
7191
|
await printUploadUrls(result);
|
|
6940
7192
|
if (domainArg) {
|
|
6941
7193
|
console.log(
|
|
6942
|
-
|
|
7194
|
+
import_chalk7.default.blue(
|
|
6943
7195
|
`Binding domain: ${displayDomain} with CID: ${result.contentHash}`
|
|
6944
7196
|
)
|
|
6945
7197
|
);
|
|
@@ -6952,23 +7204,23 @@ var upload_default = async (options) => {
|
|
|
6952
7204
|
throw e;
|
|
6953
7205
|
}
|
|
6954
7206
|
}
|
|
6955
|
-
console.log(
|
|
7207
|
+
console.log(import_chalk7.default.green("\n\u{1F389} upload successful, program exit"));
|
|
6956
7208
|
process.exit(0);
|
|
6957
7209
|
}
|
|
6958
7210
|
} catch (error) {
|
|
6959
|
-
|
|
6960
|
-
console.error(error.stack);
|
|
7211
|
+
printCliError(error, "Upload failed.");
|
|
6961
7212
|
}
|
|
6962
7213
|
};
|
|
6963
7214
|
|
|
6964
7215
|
// bin/importCar.ts
|
|
6965
7216
|
var import_path7 = __toESM(require("path"));
|
|
6966
|
-
var
|
|
7217
|
+
var import_chalk8 = __toESM(require("chalk"));
|
|
6967
7218
|
var import_inquirer2 = __toESM(require("inquirer"));
|
|
6968
7219
|
var import_figlet2 = __toESM(require("figlet"));
|
|
6969
7220
|
var import_fs3 = __toESM(require("fs"));
|
|
6970
7221
|
var import_crypto_js2 = __toESM(require("crypto-js"));
|
|
6971
7222
|
init_pinmeApi();
|
|
7223
|
+
init_cliError();
|
|
6972
7224
|
init_webLogin();
|
|
6973
7225
|
init_config();
|
|
6974
7226
|
checkNodeVersion();
|
|
@@ -6994,7 +7246,7 @@ function checkPathSync2(inputPath) {
|
|
|
6994
7246
|
}
|
|
6995
7247
|
return null;
|
|
6996
7248
|
} catch (error) {
|
|
6997
|
-
console.error(
|
|
7249
|
+
console.error(import_chalk8.default.red(`error checking path: ${error.message}`));
|
|
6998
7250
|
return null;
|
|
6999
7251
|
}
|
|
7000
7252
|
}
|
|
@@ -7026,7 +7278,7 @@ var importCar_default = async (options) => {
|
|
|
7026
7278
|
);
|
|
7027
7279
|
const auth = getAuthConfig();
|
|
7028
7280
|
if (!auth) {
|
|
7029
|
-
console.log(
|
|
7281
|
+
console.log(import_chalk8.default.red("Please login first. Run: pinme login"));
|
|
7030
7282
|
return;
|
|
7031
7283
|
}
|
|
7032
7284
|
const argPath = process.argv[3];
|
|
@@ -7034,18 +7286,18 @@ var importCar_default = async (options) => {
|
|
|
7034
7286
|
if (argPath && !argPath.startsWith("-")) {
|
|
7035
7287
|
const absolutePath = checkPathSync2(argPath);
|
|
7036
7288
|
if (!absolutePath) {
|
|
7037
|
-
console.log(
|
|
7289
|
+
console.log(import_chalk8.default.red(`path ${argPath} does not exist`));
|
|
7038
7290
|
return;
|
|
7039
7291
|
}
|
|
7040
7292
|
if (domainArg) {
|
|
7041
7293
|
const check = await checkDomainAvailable(domainArg);
|
|
7042
7294
|
if (!check.is_valid) {
|
|
7043
|
-
console.log(
|
|
7295
|
+
console.log(import_chalk8.default.red(`Domain not available: ${check.error || "unknown reason"}`));
|
|
7044
7296
|
return;
|
|
7045
7297
|
}
|
|
7046
|
-
console.log(
|
|
7298
|
+
console.log(import_chalk8.default.green(`Domain available: ${domainArg}`));
|
|
7047
7299
|
}
|
|
7048
|
-
console.log(
|
|
7300
|
+
console.log(import_chalk8.default.blue(`importing ${absolutePath} to ipfs as CAR...`));
|
|
7049
7301
|
try {
|
|
7050
7302
|
const result = await uploadPath(absolutePath, {
|
|
7051
7303
|
importAsCar: true,
|
|
@@ -7055,27 +7307,30 @@ var importCar_default = async (options) => {
|
|
|
7055
7307
|
const uid = getUid2();
|
|
7056
7308
|
const encryptedCID = encryptHash2(result.contentHash, APP_CONFIG.secretKey, uid);
|
|
7057
7309
|
console.log(
|
|
7058
|
-
|
|
7310
|
+
import_chalk8.default.cyan(
|
|
7059
7311
|
import_figlet2.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7060
7312
|
)
|
|
7061
7313
|
);
|
|
7062
|
-
|
|
7063
|
-
|
|
7314
|
+
printHighlightedUrl(
|
|
7315
|
+
"URL",
|
|
7316
|
+
`${APP_CONFIG.ipfsPreviewUrl}${encryptedCID}`,
|
|
7317
|
+
"primary"
|
|
7318
|
+
);
|
|
7064
7319
|
if (domainArg) {
|
|
7065
|
-
console.log(
|
|
7320
|
+
console.log(import_chalk8.default.blue(`Binding domain: ${domainArg} with CID: ${result.contentHash}`));
|
|
7066
7321
|
const ok = await bindPinmeDomain(domainArg, result.contentHash);
|
|
7067
7322
|
if (ok) {
|
|
7068
|
-
console.log(
|
|
7323
|
+
console.log(import_chalk8.default.green(`Bind success: ${domainArg}`));
|
|
7069
7324
|
const rootDomain = await getRootDomain();
|
|
7070
|
-
console.log(
|
|
7325
|
+
console.log(import_chalk8.default.white(`Visit (Pinme subdomain example): https://${domainArg}.${rootDomain}`));
|
|
7071
7326
|
} else {
|
|
7072
|
-
console.log(
|
|
7327
|
+
console.log(import_chalk8.default.red("Binding failed. Please try again later."));
|
|
7073
7328
|
}
|
|
7074
7329
|
}
|
|
7075
|
-
console.log(
|
|
7330
|
+
console.log(import_chalk8.default.green("\n\u{1F389} import successful, program exit"));
|
|
7076
7331
|
}
|
|
7077
7332
|
} catch (error) {
|
|
7078
|
-
|
|
7333
|
+
printCliError(error, "Import failed.");
|
|
7079
7334
|
}
|
|
7080
7335
|
process.exit(0);
|
|
7081
7336
|
}
|
|
@@ -7089,18 +7344,18 @@ var importCar_default = async (options) => {
|
|
|
7089
7344
|
if (answer.path) {
|
|
7090
7345
|
const absolutePath = checkPathSync2(answer.path);
|
|
7091
7346
|
if (!absolutePath) {
|
|
7092
|
-
console.log(
|
|
7347
|
+
console.log(import_chalk8.default.red(`path ${answer.path} does not exist`));
|
|
7093
7348
|
return;
|
|
7094
7349
|
}
|
|
7095
7350
|
if (domainArg) {
|
|
7096
7351
|
const check = await checkDomainAvailable(domainArg);
|
|
7097
7352
|
if (!check.is_valid) {
|
|
7098
|
-
console.log(
|
|
7353
|
+
console.log(import_chalk8.default.red(`Domain not available: ${check.error || "unknown reason"}`));
|
|
7099
7354
|
return;
|
|
7100
7355
|
}
|
|
7101
|
-
console.log(
|
|
7356
|
+
console.log(import_chalk8.default.green(`Domain available: ${domainArg}`));
|
|
7102
7357
|
}
|
|
7103
|
-
console.log(
|
|
7358
|
+
console.log(import_chalk8.default.blue(`importing ${absolutePath} to ipfs as CAR...`));
|
|
7104
7359
|
try {
|
|
7105
7360
|
const result = await uploadPath(absolutePath, {
|
|
7106
7361
|
importAsCar: true,
|
|
@@ -7110,44 +7365,47 @@ var importCar_default = async (options) => {
|
|
|
7110
7365
|
const uid = getUid2();
|
|
7111
7366
|
const encryptedCID = encryptHash2(result.contentHash, APP_CONFIG.secretKey, uid);
|
|
7112
7367
|
console.log(
|
|
7113
|
-
|
|
7368
|
+
import_chalk8.default.cyan(
|
|
7114
7369
|
import_figlet2.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7115
7370
|
)
|
|
7116
7371
|
);
|
|
7117
|
-
|
|
7118
|
-
|
|
7372
|
+
printHighlightedUrl(
|
|
7373
|
+
"URL",
|
|
7374
|
+
`${APP_CONFIG.ipfsPreviewUrl}${encryptedCID}`,
|
|
7375
|
+
"primary"
|
|
7376
|
+
);
|
|
7119
7377
|
if (domainArg) {
|
|
7120
|
-
console.log(
|
|
7378
|
+
console.log(import_chalk8.default.blue(`Binding domain: ${domainArg} with CID: ${result.contentHash}`));
|
|
7121
7379
|
const ok = await bindPinmeDomain(domainArg, result.contentHash);
|
|
7122
7380
|
if (ok) {
|
|
7123
|
-
console.log(
|
|
7381
|
+
console.log(import_chalk8.default.green(`Bind success: ${domainArg}`));
|
|
7124
7382
|
const rootDomain = await getRootDomain();
|
|
7125
|
-
console.log(
|
|
7383
|
+
console.log(import_chalk8.default.white(`Visit (Pinme subdomain example): https://${domainArg}.${rootDomain}`));
|
|
7126
7384
|
} else {
|
|
7127
|
-
console.log(
|
|
7385
|
+
console.log(import_chalk8.default.red("Binding failed. Please try again later."));
|
|
7128
7386
|
}
|
|
7129
7387
|
}
|
|
7130
|
-
console.log(
|
|
7388
|
+
console.log(import_chalk8.default.green("\n\u{1F389} import successful, program exit"));
|
|
7131
7389
|
}
|
|
7132
7390
|
} catch (error) {
|
|
7133
|
-
|
|
7391
|
+
printCliError(error, "Import failed.");
|
|
7134
7392
|
}
|
|
7135
7393
|
process.exit(0);
|
|
7136
7394
|
}
|
|
7137
7395
|
} catch (error) {
|
|
7138
|
-
|
|
7139
|
-
console.error(error.stack);
|
|
7396
|
+
printCliError(error, "Import failed.");
|
|
7140
7397
|
}
|
|
7141
7398
|
};
|
|
7142
7399
|
|
|
7143
7400
|
// bin/exportCar.ts
|
|
7144
7401
|
var import_path8 = __toESM(require("path"));
|
|
7145
|
-
var
|
|
7402
|
+
var import_chalk9 = __toESM(require("chalk"));
|
|
7146
7403
|
var import_inquirer3 = __toESM(require("inquirer"));
|
|
7147
7404
|
var import_figlet3 = __toESM(require("figlet"));
|
|
7148
7405
|
var import_fs4 = __toESM(require("fs"));
|
|
7149
7406
|
init_axios2();
|
|
7150
7407
|
var import_ora2 = __toESM(require("ora"));
|
|
7408
|
+
init_cliError();
|
|
7151
7409
|
init_pinmeApi();
|
|
7152
7410
|
checkNodeVersion();
|
|
7153
7411
|
var POLL_INTERVAL2 = 5e3;
|
|
@@ -7169,7 +7427,7 @@ async function pollExportStatus(taskId, cid, spinner, startTime) {
|
|
|
7169
7427
|
spinner.text = `Exporting CAR file... (${minutes}m ${seconds}s)`;
|
|
7170
7428
|
}
|
|
7171
7429
|
} catch (error) {
|
|
7172
|
-
console.log(
|
|
7430
|
+
console.log(import_chalk9.default.yellow(`Polling error: ${error.message}`));
|
|
7173
7431
|
}
|
|
7174
7432
|
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL2));
|
|
7175
7433
|
}
|
|
@@ -7209,7 +7467,7 @@ async function downloadCarFile(downloadUrl, outputPath) {
|
|
|
7209
7467
|
});
|
|
7210
7468
|
});
|
|
7211
7469
|
} catch (error) {
|
|
7212
|
-
console.error(
|
|
7470
|
+
console.error(import_chalk9.default.red(`Download error: ${error.message}`));
|
|
7213
7471
|
return false;
|
|
7214
7472
|
}
|
|
7215
7473
|
}
|
|
@@ -7267,7 +7525,7 @@ var exportCar_default = async () => {
|
|
|
7267
7525
|
cid = answer.cid.trim();
|
|
7268
7526
|
}
|
|
7269
7527
|
if (!cid || !isValidCID(cid)) {
|
|
7270
|
-
console.log(
|
|
7528
|
+
console.log(import_chalk9.default.red("Invalid CID format. CID should start with Qm, bafy, bafk, or bafz"));
|
|
7271
7529
|
return;
|
|
7272
7530
|
}
|
|
7273
7531
|
let outputDir = getOutputPathFromArgs();
|
|
@@ -7287,7 +7545,7 @@ var exportCar_default = async () => {
|
|
|
7287
7545
|
if (!import_fs4.default.existsSync(outputDir)) {
|
|
7288
7546
|
import_fs4.default.mkdirSync(outputDir, { recursive: true });
|
|
7289
7547
|
} else if (!import_fs4.default.statSync(outputDir).isDirectory()) {
|
|
7290
|
-
console.log(
|
|
7548
|
+
console.log(import_chalk9.default.red(`Error: ${outputDir} exists but is not a directory.`));
|
|
7291
7549
|
return;
|
|
7292
7550
|
}
|
|
7293
7551
|
const finalOutputPath = import_path8.default.join(outputDir, `${cid}.car`);
|
|
@@ -7301,7 +7559,7 @@ var exportCar_default = async () => {
|
|
|
7301
7559
|
}
|
|
7302
7560
|
]);
|
|
7303
7561
|
if (!answer.overwrite) {
|
|
7304
|
-
console.log(
|
|
7562
|
+
console.log(import_chalk9.default.blue("Export cancelled."));
|
|
7305
7563
|
return;
|
|
7306
7564
|
}
|
|
7307
7565
|
}
|
|
@@ -7319,7 +7577,7 @@ var exportCar_default = async () => {
|
|
|
7319
7577
|
startTime
|
|
7320
7578
|
);
|
|
7321
7579
|
if (!downloadUrl) {
|
|
7322
|
-
console.log(
|
|
7580
|
+
console.log(import_chalk9.default.red("Export failed or timed out."));
|
|
7323
7581
|
return;
|
|
7324
7582
|
}
|
|
7325
7583
|
const success = await downloadCarFile(downloadUrl, finalOutputPath);
|
|
@@ -7327,42 +7585,41 @@ var exportCar_default = async () => {
|
|
|
7327
7585
|
const fileSize = import_fs4.default.statSync(finalOutputPath).size;
|
|
7328
7586
|
const fileSizeMB = (fileSize / (1024 * 1024)).toFixed(2);
|
|
7329
7587
|
console.log(
|
|
7330
|
-
|
|
7588
|
+
import_chalk9.default.cyan(
|
|
7331
7589
|
import_figlet3.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7332
7590
|
)
|
|
7333
7591
|
);
|
|
7334
|
-
console.log(
|
|
7592
|
+
console.log(import_chalk9.default.green(`
|
|
7335
7593
|
\u{1F389} Export successful!`));
|
|
7336
|
-
console.log(
|
|
7337
|
-
console.log(
|
|
7338
|
-
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}`));
|
|
7339
7597
|
} else {
|
|
7340
|
-
console.log(
|
|
7598
|
+
console.log(import_chalk9.default.red("Download failed."));
|
|
7341
7599
|
}
|
|
7342
7600
|
} catch (error) {
|
|
7343
7601
|
spinner.fail(`Error: ${error.message}`);
|
|
7344
|
-
|
|
7602
|
+
printCliError(error, "Export failed.");
|
|
7345
7603
|
}
|
|
7346
7604
|
} catch (error) {
|
|
7347
|
-
|
|
7348
|
-
console.error(error.stack);
|
|
7605
|
+
printCliError(error, "Export failed.");
|
|
7349
7606
|
}
|
|
7350
7607
|
};
|
|
7351
7608
|
|
|
7352
7609
|
// bin/remove.ts
|
|
7353
|
-
var
|
|
7610
|
+
var import_chalk11 = __toESM(require("chalk"));
|
|
7354
7611
|
var import_inquirer4 = __toESM(require("inquirer"));
|
|
7355
7612
|
var import_figlet4 = __toESM(require("figlet"));
|
|
7356
7613
|
|
|
7357
7614
|
// bin/utils/removeFromIpfs.ts
|
|
7358
7615
|
init_axios2();
|
|
7359
|
-
var
|
|
7616
|
+
var import_chalk10 = __toESM(require("chalk"));
|
|
7360
7617
|
init_config();
|
|
7361
7618
|
var ipfsApiUrl = APP_CONFIG.ipfsApiUrl;
|
|
7362
7619
|
async function removeFromIpfs(value, type = "hash") {
|
|
7363
7620
|
try {
|
|
7364
7621
|
const uid = getUid();
|
|
7365
|
-
console.log(
|
|
7622
|
+
console.log(import_chalk10.default.blue(`Removing content from IPFS: ${value}...`));
|
|
7366
7623
|
const queryParams = new URLSearchParams({
|
|
7367
7624
|
uid
|
|
7368
7625
|
});
|
|
@@ -7380,49 +7637,49 @@ async function removeFromIpfs(value, type = "hash") {
|
|
|
7380
7637
|
);
|
|
7381
7638
|
const { code, msg, data } = response.data;
|
|
7382
7639
|
if (code === 200) {
|
|
7383
|
-
console.log(
|
|
7640
|
+
console.log(import_chalk10.default.green("\u2713 Removal successful!"));
|
|
7384
7641
|
console.log(
|
|
7385
|
-
|
|
7642
|
+
import_chalk10.default.cyan(
|
|
7386
7643
|
`Content ${type}: ${value} has been removed from IPFS network`
|
|
7387
7644
|
)
|
|
7388
7645
|
);
|
|
7389
7646
|
return true;
|
|
7390
7647
|
} else {
|
|
7391
|
-
console.log(
|
|
7392
|
-
console.log(
|
|
7648
|
+
console.log(import_chalk10.default.red("\u2717 Removal failed"));
|
|
7649
|
+
console.log(import_chalk10.default.red(`Error: ${msg || "Unknown error occurred"}`));
|
|
7393
7650
|
return false;
|
|
7394
7651
|
}
|
|
7395
7652
|
} catch (error) {
|
|
7396
|
-
console.log(
|
|
7653
|
+
console.log(import_chalk10.default.red("\u2717 Removal failed", error));
|
|
7397
7654
|
if (error.response) {
|
|
7398
7655
|
const { status, data } = error.response;
|
|
7399
7656
|
console.log(
|
|
7400
|
-
|
|
7657
|
+
import_chalk10.default.red(`HTTP Error ${status}: ${(data == null ? void 0 : data.msg) || "Server error"}`)
|
|
7401
7658
|
);
|
|
7402
7659
|
if (status === 404) {
|
|
7403
7660
|
console.log(
|
|
7404
|
-
|
|
7661
|
+
import_chalk10.default.yellow("Content not found on the network or already removed")
|
|
7405
7662
|
);
|
|
7406
7663
|
} else if (status === 403) {
|
|
7407
7664
|
console.log(
|
|
7408
|
-
|
|
7665
|
+
import_chalk10.default.yellow(
|
|
7409
7666
|
"Permission denied - you may not have access to remove this content"
|
|
7410
7667
|
)
|
|
7411
7668
|
);
|
|
7412
7669
|
} else if (status === 500) {
|
|
7413
7670
|
console.log(
|
|
7414
|
-
|
|
7671
|
+
import_chalk10.default.yellow("Server internal error - please try again later")
|
|
7415
7672
|
);
|
|
7416
7673
|
}
|
|
7417
7674
|
} else if (error.request) {
|
|
7418
7675
|
console.log(
|
|
7419
|
-
|
|
7676
|
+
import_chalk10.default.red("Network error: Unable to connect to IPFS service")
|
|
7420
7677
|
);
|
|
7421
7678
|
console.log(
|
|
7422
|
-
|
|
7679
|
+
import_chalk10.default.yellow("Please check your internet connection and try again")
|
|
7423
7680
|
);
|
|
7424
7681
|
} else {
|
|
7425
|
-
console.log(
|
|
7682
|
+
console.log(import_chalk10.default.red(`Error: ${error.message}`));
|
|
7426
7683
|
}
|
|
7427
7684
|
return false;
|
|
7428
7685
|
}
|
|
@@ -7482,29 +7739,29 @@ var remove_default = async (options) => {
|
|
|
7482
7739
|
if (argHash && !argHash.startsWith("-")) {
|
|
7483
7740
|
const parsedInput = parseInput(argHash);
|
|
7484
7741
|
if (!parsedInput) {
|
|
7485
|
-
console.log(
|
|
7486
|
-
console.log(
|
|
7487
|
-
console.log(
|
|
7488
|
-
console.log(
|
|
7489
|
-
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>"));
|
|
7490
7747
|
return;
|
|
7491
7748
|
}
|
|
7492
7749
|
try {
|
|
7493
7750
|
const success = await removeFromIpfs(parsedInput.value, parsedInput.type);
|
|
7494
7751
|
if (success) {
|
|
7495
7752
|
console.log(
|
|
7496
|
-
|
|
7753
|
+
import_chalk11.default.cyan(
|
|
7497
7754
|
import_figlet4.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7498
7755
|
)
|
|
7499
7756
|
);
|
|
7500
7757
|
}
|
|
7501
7758
|
} catch (error) {
|
|
7502
|
-
console.error(
|
|
7759
|
+
console.error(import_chalk11.default.red(`Error: ${error.message}`));
|
|
7503
7760
|
}
|
|
7504
7761
|
return;
|
|
7505
7762
|
}
|
|
7506
|
-
console.log(
|
|
7507
|
-
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"));
|
|
7508
7765
|
console.log("");
|
|
7509
7766
|
const confirmAnswer = await import_inquirer4.default.prompt([
|
|
7510
7767
|
{
|
|
@@ -7515,7 +7772,7 @@ var remove_default = async (options) => {
|
|
|
7515
7772
|
}
|
|
7516
7773
|
]);
|
|
7517
7774
|
if (!confirmAnswer.confirm) {
|
|
7518
|
-
console.log(
|
|
7775
|
+
console.log(import_chalk11.default.yellow("Operation cancelled"));
|
|
7519
7776
|
return;
|
|
7520
7777
|
}
|
|
7521
7778
|
const answer = await import_inquirer4.default.prompt([
|
|
@@ -7538,7 +7795,7 @@ var remove_default = async (options) => {
|
|
|
7538
7795
|
if (answer.input) {
|
|
7539
7796
|
const parsedInput = parseInput(answer.input.trim());
|
|
7540
7797
|
if (!parsedInput) {
|
|
7541
|
-
console.log(
|
|
7798
|
+
console.log(import_chalk11.default.red("Invalid input format"));
|
|
7542
7799
|
return;
|
|
7543
7800
|
}
|
|
7544
7801
|
const finalConfirm = await import_inquirer4.default.prompt([
|
|
@@ -7550,30 +7807,30 @@ var remove_default = async (options) => {
|
|
|
7550
7807
|
}
|
|
7551
7808
|
]);
|
|
7552
7809
|
if (!finalConfirm.confirm) {
|
|
7553
|
-
console.log(
|
|
7810
|
+
console.log(import_chalk11.default.yellow("Operation cancelled"));
|
|
7554
7811
|
return;
|
|
7555
7812
|
}
|
|
7556
7813
|
try {
|
|
7557
7814
|
const success = await removeFromIpfs(parsedInput.value, parsedInput.type);
|
|
7558
7815
|
if (success) {
|
|
7559
7816
|
console.log(
|
|
7560
|
-
|
|
7817
|
+
import_chalk11.default.cyan(
|
|
7561
7818
|
import_figlet4.default.textSync("Successful", { horizontalLayout: "full" })
|
|
7562
7819
|
)
|
|
7563
7820
|
);
|
|
7564
7821
|
}
|
|
7565
7822
|
} catch (error) {
|
|
7566
|
-
console.error(
|
|
7823
|
+
console.error(import_chalk11.default.red(`Error: ${error.message}`));
|
|
7567
7824
|
}
|
|
7568
7825
|
}
|
|
7569
7826
|
} catch (error) {
|
|
7570
|
-
console.error(
|
|
7827
|
+
console.error(import_chalk11.default.red(`Error executing remove command: ${error.message}`));
|
|
7571
7828
|
console.error(error.stack);
|
|
7572
7829
|
}
|
|
7573
7830
|
};
|
|
7574
7831
|
|
|
7575
7832
|
// bin/set-appkey.ts
|
|
7576
|
-
var
|
|
7833
|
+
var import_chalk12 = __toESM(require("chalk"));
|
|
7577
7834
|
var import_inquirer5 = __toESM(require("inquirer"));
|
|
7578
7835
|
init_webLogin();
|
|
7579
7836
|
init_pinmeApi();
|
|
@@ -7592,32 +7849,32 @@ async function setAppKeyCmd() {
|
|
|
7592
7849
|
appKey = ans.appKey;
|
|
7593
7850
|
}
|
|
7594
7851
|
if (!appKey) {
|
|
7595
|
-
console.log(
|
|
7852
|
+
console.log(import_chalk12.default.red("AppKey not provided."));
|
|
7596
7853
|
return;
|
|
7597
7854
|
}
|
|
7598
7855
|
const saved = setAuthToken(appKey);
|
|
7599
|
-
console.log(
|
|
7856
|
+
console.log(import_chalk12.default.green(`Auth set for address: ${saved.address}`));
|
|
7600
7857
|
const deviceId = getDeviceId();
|
|
7601
7858
|
const ok = await bindAnonymousDevice(deviceId);
|
|
7602
7859
|
if (ok) {
|
|
7603
|
-
console.log(
|
|
7860
|
+
console.log(import_chalk12.default.green("Anonymous history merged to current account."));
|
|
7604
7861
|
} else {
|
|
7605
|
-
console.log(
|
|
7862
|
+
console.log(import_chalk12.default.yellow("Anonymous history merge not confirmed. You may retry later."));
|
|
7606
7863
|
}
|
|
7607
7864
|
} catch (e) {
|
|
7608
|
-
console.log(
|
|
7865
|
+
console.log(import_chalk12.default.red(`Failed to set AppKey: ${(e == null ? void 0 : e.message) || e}`));
|
|
7609
7866
|
}
|
|
7610
7867
|
}
|
|
7611
7868
|
|
|
7612
7869
|
// bin/logout.ts
|
|
7613
|
-
var
|
|
7870
|
+
var import_chalk13 = __toESM(require("chalk"));
|
|
7614
7871
|
var import_inquirer6 = __toESM(require("inquirer"));
|
|
7615
7872
|
init_webLogin();
|
|
7616
7873
|
async function logoutCmd() {
|
|
7617
7874
|
try {
|
|
7618
7875
|
const auth = getAuthConfig();
|
|
7619
7876
|
if (!auth) {
|
|
7620
|
-
console.log(
|
|
7877
|
+
console.log(import_chalk13.default.yellow("No active session found. You are already logged out."));
|
|
7621
7878
|
return;
|
|
7622
7879
|
}
|
|
7623
7880
|
const answer = await import_inquirer6.default.prompt([
|
|
@@ -7629,81 +7886,83 @@ async function logoutCmd() {
|
|
|
7629
7886
|
}
|
|
7630
7887
|
]);
|
|
7631
7888
|
if (!answer.confirm) {
|
|
7632
|
-
console.log(
|
|
7889
|
+
console.log(import_chalk13.default.blue("Logout cancelled."));
|
|
7633
7890
|
return;
|
|
7634
7891
|
}
|
|
7635
7892
|
clearAuthToken();
|
|
7636
|
-
console.log(
|
|
7637
|
-
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.`));
|
|
7638
7895
|
} catch (e) {
|
|
7639
|
-
console.log(
|
|
7896
|
+
console.log(import_chalk13.default.red(`Failed to logout: ${(e == null ? void 0 : e.message) || e}`));
|
|
7640
7897
|
}
|
|
7641
7898
|
}
|
|
7642
7899
|
|
|
7643
7900
|
// bin/show-appkey.ts
|
|
7644
|
-
var
|
|
7901
|
+
var import_chalk14 = __toESM(require("chalk"));
|
|
7645
7902
|
init_webLogin();
|
|
7646
7903
|
function showAppKeyCmd() {
|
|
7647
7904
|
try {
|
|
7648
7905
|
const auth = getAuthConfig();
|
|
7649
7906
|
if (!auth) {
|
|
7650
|
-
console.log(
|
|
7651
|
-
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>"));
|
|
7652
7909
|
return;
|
|
7653
7910
|
}
|
|
7654
|
-
console.log(
|
|
7655
|
-
console.log(
|
|
7911
|
+
console.log(import_chalk14.default.green("Current AppKey Information:"));
|
|
7912
|
+
console.log(import_chalk14.default.cyan(` Address: ${auth.address}`));
|
|
7656
7913
|
const token = auth.token;
|
|
7657
7914
|
if (token.length > 12) {
|
|
7658
7915
|
const maskedToken = `${token.substring(0, 8)}${"*".repeat(token.length - 12)}${token.substring(token.length - 4)}`;
|
|
7659
|
-
console.log(
|
|
7916
|
+
console.log(import_chalk14.default.cyan(` Token: ${maskedToken}`));
|
|
7660
7917
|
} else {
|
|
7661
|
-
console.log(
|
|
7918
|
+
console.log(import_chalk14.default.cyan(` Token: ${"*".repeat(token.length)}`));
|
|
7662
7919
|
}
|
|
7663
7920
|
const combined = `${auth.address}-${auth.token}`;
|
|
7664
7921
|
if (combined.length > 20) {
|
|
7665
7922
|
const maskedAppKey = `${combined.substring(0, 12)}${"*".repeat(combined.length - 16)}${combined.substring(combined.length - 4)}`;
|
|
7666
|
-
console.log(
|
|
7923
|
+
console.log(import_chalk14.default.cyan(` AppKey: ${maskedAppKey}`));
|
|
7667
7924
|
} else {
|
|
7668
|
-
console.log(
|
|
7925
|
+
console.log(import_chalk14.default.cyan(` AppKey: ${"*".repeat(combined.length)}`));
|
|
7669
7926
|
}
|
|
7670
7927
|
} catch (e) {
|
|
7671
|
-
console.log(
|
|
7928
|
+
console.log(import_chalk14.default.red(`Failed to show AppKey: ${(e == null ? void 0 : e.message) || e}`));
|
|
7672
7929
|
}
|
|
7673
7930
|
}
|
|
7674
7931
|
|
|
7675
7932
|
// bin/my-domains.ts
|
|
7676
|
-
var
|
|
7933
|
+
var import_chalk15 = __toESM(require("chalk"));
|
|
7677
7934
|
var import_dayjs2 = __toESM(require("dayjs"));
|
|
7935
|
+
init_cliError();
|
|
7678
7936
|
init_pinmeApi();
|
|
7679
7937
|
async function myDomainsCmd() {
|
|
7680
7938
|
try {
|
|
7681
7939
|
const list = await getMyDomains();
|
|
7682
7940
|
if (!list.length) {
|
|
7683
|
-
console.log(
|
|
7941
|
+
console.log(import_chalk15.default.yellow("No bound domains found."));
|
|
7684
7942
|
return;
|
|
7685
7943
|
}
|
|
7686
|
-
console.log(
|
|
7687
|
-
console.log(
|
|
7944
|
+
console.log(import_chalk15.default.cyan("My domains:"));
|
|
7945
|
+
console.log(import_chalk15.default.cyan("-".repeat(80)));
|
|
7688
7946
|
list.forEach((item, i) => {
|
|
7689
|
-
console.log(
|
|
7690
|
-
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}`));
|
|
7691
7949
|
if (item.bind_time) {
|
|
7692
|
-
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")}`));
|
|
7693
7951
|
}
|
|
7694
7952
|
if (typeof item.expire_time === "number") {
|
|
7695
7953
|
const label = item.expire_time === 0 ? "Never" : (0, import_dayjs2.default)(item.expire_time * 1e3).format("YYYY-MM-DD HH:mm:ss");
|
|
7696
|
-
console.log(
|
|
7954
|
+
console.log(import_chalk15.default.white(` Expire time: ${label}`));
|
|
7697
7955
|
}
|
|
7698
|
-
console.log(
|
|
7956
|
+
console.log(import_chalk15.default.cyan("-".repeat(80)));
|
|
7699
7957
|
});
|
|
7700
7958
|
} catch (e) {
|
|
7701
|
-
|
|
7959
|
+
printCliError(e, "Failed to fetch domains.");
|
|
7702
7960
|
}
|
|
7703
7961
|
}
|
|
7704
7962
|
|
|
7705
7963
|
// bin/wallet-balance.ts
|
|
7706
|
-
var
|
|
7964
|
+
var import_chalk16 = __toESM(require("chalk"));
|
|
7965
|
+
init_cliError();
|
|
7707
7966
|
init_pinmeApi();
|
|
7708
7967
|
init_webLogin();
|
|
7709
7968
|
async function walletBalanceCmd() {
|
|
@@ -7711,27 +7970,28 @@ async function walletBalanceCmd() {
|
|
|
7711
7970
|
try {
|
|
7712
7971
|
const auth = getAuthConfig();
|
|
7713
7972
|
if (!auth) {
|
|
7714
|
-
console.log(
|
|
7973
|
+
console.log(import_chalk16.default.yellow("Please login first. Run: pinme set-appkey <AppKey>"));
|
|
7715
7974
|
return;
|
|
7716
7975
|
}
|
|
7717
7976
|
const result = await getWalletBalance(auth.address, auth.token);
|
|
7718
7977
|
const balance = Number(((_a2 = result.data) == null ? void 0 : _a2.wallet_balance_usd) ?? 0);
|
|
7719
7978
|
if (!Number.isFinite(balance)) {
|
|
7720
|
-
console.log(
|
|
7979
|
+
console.log(import_chalk16.default.red("Failed to parse wallet balance."));
|
|
7721
7980
|
return;
|
|
7722
7981
|
}
|
|
7723
|
-
console.log(
|
|
7724
|
-
console.log(
|
|
7982
|
+
console.log(import_chalk16.default.cyan("Wallet balance:"));
|
|
7983
|
+
console.log(import_chalk16.default.green(` USD: $${balance.toFixed(2)}`));
|
|
7725
7984
|
} catch (e) {
|
|
7726
|
-
|
|
7985
|
+
printCliError(e, "Failed to fetch wallet balance.");
|
|
7727
7986
|
}
|
|
7728
7987
|
}
|
|
7729
7988
|
|
|
7730
7989
|
// bin/bind.ts
|
|
7731
7990
|
var import_path9 = __toESM(require("path"));
|
|
7732
|
-
var
|
|
7991
|
+
var import_chalk17 = __toESM(require("chalk"));
|
|
7733
7992
|
var import_inquirer7 = __toESM(require("inquirer"));
|
|
7734
7993
|
init_pinmeApi();
|
|
7994
|
+
init_cliError();
|
|
7735
7995
|
init_webLogin();
|
|
7736
7996
|
function parseArgs() {
|
|
7737
7997
|
const args = process.argv.slice(2);
|
|
@@ -7753,20 +8013,20 @@ function parseArgs() {
|
|
|
7753
8013
|
}
|
|
7754
8014
|
async function checkWalletBalanceStatus2(authConfig) {
|
|
7755
8015
|
var _a2;
|
|
7756
|
-
console.log(
|
|
8016
|
+
console.log(import_chalk17.default.blue("Checking wallet balance..."));
|
|
7757
8017
|
try {
|
|
7758
8018
|
const balanceResult = await getWalletBalance(authConfig.address, authConfig.token);
|
|
7759
8019
|
const balance = Number(((_a2 = balanceResult.data) == null ? void 0 : _a2.wallet_balance_usd) ?? 0);
|
|
7760
8020
|
if (!Number.isFinite(balance) || balance <= 0) {
|
|
7761
8021
|
return false;
|
|
7762
8022
|
}
|
|
7763
|
-
console.log(
|
|
8023
|
+
console.log(import_chalk17.default.green(`Wallet balance available: $${balance.toFixed(2)}`));
|
|
7764
8024
|
return true;
|
|
7765
8025
|
} catch (e) {
|
|
7766
|
-
if (e.message === "Token expired") {
|
|
8026
|
+
if (e.message === "Token expired" || (e == null ? void 0 : e.name) === "CliError") {
|
|
7767
8027
|
throw e;
|
|
7768
8028
|
}
|
|
7769
|
-
console.log(
|
|
8029
|
+
console.log(import_chalk17.default.yellow("Failed to check wallet balance, continuing..."));
|
|
7770
8030
|
return true;
|
|
7771
8031
|
}
|
|
7772
8032
|
}
|
|
@@ -7776,7 +8036,7 @@ async function bindCmd() {
|
|
|
7776
8036
|
let { domain, targetPath, dns } = parseArgs();
|
|
7777
8037
|
const authConfig = getAuthConfig();
|
|
7778
8038
|
if (!authConfig) {
|
|
7779
|
-
console.log(
|
|
8039
|
+
console.log(import_chalk17.default.red("Please login first. Run: pinme set-appkey <AppKey>"));
|
|
7780
8040
|
return;
|
|
7781
8041
|
}
|
|
7782
8042
|
if (!targetPath) {
|
|
@@ -7792,7 +8052,7 @@ async function bindCmd() {
|
|
|
7792
8052
|
domain = (_a2 = ans.domain) == null ? void 0 : _a2.trim();
|
|
7793
8053
|
}
|
|
7794
8054
|
if (!targetPath || !domain) {
|
|
7795
|
-
console.log(
|
|
8055
|
+
console.log(import_chalk17.default.red("Missing parameters. Path and domain are required."));
|
|
7796
8056
|
return;
|
|
7797
8057
|
}
|
|
7798
8058
|
const isDns = dns || isDnsDomain(domain);
|
|
@@ -7800,14 +8060,14 @@ async function bindCmd() {
|
|
|
7800
8060
|
if (isDns) {
|
|
7801
8061
|
const validation = validateDnsDomain(domain);
|
|
7802
8062
|
if (!validation.valid) {
|
|
7803
|
-
console.log(
|
|
8063
|
+
console.log(import_chalk17.default.red(validation.message));
|
|
7804
8064
|
return;
|
|
7805
8065
|
}
|
|
7806
8066
|
}
|
|
7807
8067
|
try {
|
|
7808
8068
|
const hasWalletBalance = await checkWalletBalanceStatus2(authConfig);
|
|
7809
8069
|
if (!hasWalletBalance) {
|
|
7810
|
-
console.log(
|
|
8070
|
+
console.log(import_chalk17.default.red("Insufficient wallet balance. Please recharge your wallet first."));
|
|
7811
8071
|
return;
|
|
7812
8072
|
}
|
|
7813
8073
|
} catch (e) {
|
|
@@ -7819,10 +8079,10 @@ async function bindCmd() {
|
|
|
7819
8079
|
try {
|
|
7820
8080
|
const check = await checkDomainAvailable(displayDomain);
|
|
7821
8081
|
if (!check.is_valid) {
|
|
7822
|
-
console.log(
|
|
8082
|
+
console.log(import_chalk17.default.red(`Domain not available: ${check.error || "unknown reason"}`));
|
|
7823
8083
|
return;
|
|
7824
8084
|
}
|
|
7825
|
-
console.log(
|
|
8085
|
+
console.log(import_chalk17.default.green(`Domain available: ${displayDomain}`));
|
|
7826
8086
|
} catch (e) {
|
|
7827
8087
|
if (e.message === "Token expired") {
|
|
7828
8088
|
return;
|
|
@@ -7830,34 +8090,34 @@ async function bindCmd() {
|
|
|
7830
8090
|
throw e;
|
|
7831
8091
|
}
|
|
7832
8092
|
const absolutePath = import_path9.default.resolve(targetPath);
|
|
7833
|
-
console.log(
|
|
8093
|
+
console.log(import_chalk17.default.blue(`Uploading: ${absolutePath}`));
|
|
7834
8094
|
const up = await uploadPath(absolutePath, { uid: authConfig.address });
|
|
7835
8095
|
if (!(up == null ? void 0 : up.contentHash)) {
|
|
7836
|
-
console.log(
|
|
8096
|
+
console.log(import_chalk17.default.red("Upload failed, binding aborted."));
|
|
7837
8097
|
return;
|
|
7838
8098
|
}
|
|
7839
|
-
console.log(
|
|
8099
|
+
console.log(import_chalk17.default.green(`Upload success, CID: ${up.contentHash}`));
|
|
7840
8100
|
try {
|
|
7841
8101
|
if (isDns) {
|
|
7842
|
-
console.log(
|
|
8102
|
+
console.log(import_chalk17.default.blue("Binding DNS domain..."));
|
|
7843
8103
|
const dnsResult = await bindDnsDomainV4(displayDomain, up.contentHash, authConfig.address, authConfig.token);
|
|
7844
8104
|
if (dnsResult.code !== 200) {
|
|
7845
|
-
console.log(
|
|
8105
|
+
console.log(import_chalk17.default.red(`DNS binding failed: ${dnsResult.msg}`));
|
|
7846
8106
|
return;
|
|
7847
8107
|
}
|
|
7848
|
-
console.log(
|
|
7849
|
-
console.log(
|
|
7850
|
-
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"));
|
|
7851
8111
|
} else {
|
|
7852
|
-
console.log(
|
|
8112
|
+
console.log(import_chalk17.default.blue("Binding Pinme subdomain..."));
|
|
7853
8113
|
const ok = await bindPinmeDomain(displayDomain, up.contentHash);
|
|
7854
8114
|
if (!ok) {
|
|
7855
|
-
console.log(
|
|
8115
|
+
console.log(import_chalk17.default.red("Binding failed. Please try again later."));
|
|
7856
8116
|
return;
|
|
7857
8117
|
}
|
|
7858
|
-
console.log(
|
|
8118
|
+
console.log(import_chalk17.default.green(`Bind success: ${displayDomain}`));
|
|
7859
8119
|
const rootDomain = await getRootDomain();
|
|
7860
|
-
console.log(
|
|
8120
|
+
console.log(import_chalk17.default.white(`Visit: https://${displayDomain}.${rootDomain}`));
|
|
7861
8121
|
}
|
|
7862
8122
|
} catch (e) {
|
|
7863
8123
|
if (e.message === "Token expired") {
|
|
@@ -7866,12 +8126,12 @@ async function bindCmd() {
|
|
|
7866
8126
|
throw e;
|
|
7867
8127
|
}
|
|
7868
8128
|
} catch (e) {
|
|
7869
|
-
|
|
8129
|
+
printCliError(e, "Bind failed.");
|
|
7870
8130
|
}
|
|
7871
8131
|
}
|
|
7872
8132
|
|
|
7873
8133
|
// bin/login.ts
|
|
7874
|
-
var
|
|
8134
|
+
var import_chalk18 = __toESM(require("chalk"));
|
|
7875
8135
|
init_webLogin();
|
|
7876
8136
|
init_pinmeApi();
|
|
7877
8137
|
var ENV_URLS = {
|
|
@@ -7885,34 +8145,34 @@ async function loginCmd(options = {}) {
|
|
|
7885
8145
|
const env = (options.env || "prod").toLowerCase();
|
|
7886
8146
|
if (ENV_URLS[env]) {
|
|
7887
8147
|
webBaseUrl = ENV_URLS[env];
|
|
7888
|
-
console.log(
|
|
8148
|
+
console.log(import_chalk18.default.blue(`Using ${env} environment: ${webBaseUrl}`));
|
|
7889
8149
|
} else {
|
|
7890
8150
|
console.log(
|
|
7891
|
-
|
|
8151
|
+
import_chalk18.default.yellow(
|
|
7892
8152
|
`Unknown environment: ${options.env}. Using default prod.`
|
|
7893
8153
|
)
|
|
7894
8154
|
);
|
|
7895
8155
|
webBaseUrl = ENV_URLS.prod;
|
|
7896
|
-
console.log(
|
|
8156
|
+
console.log(import_chalk18.default.blue(`Using prod environment: ${webBaseUrl}`));
|
|
7897
8157
|
}
|
|
7898
8158
|
const manager = new WebLoginManager({ webBaseUrl });
|
|
7899
8159
|
await manager.login();
|
|
7900
|
-
console.log(
|
|
8160
|
+
console.log(import_chalk18.default.blue("\nMerging history..."));
|
|
7901
8161
|
const deviceId = getDeviceId();
|
|
7902
8162
|
const ok = await bindAnonymousDevice(deviceId);
|
|
7903
8163
|
if (ok) {
|
|
7904
|
-
console.log(
|
|
8164
|
+
console.log(import_chalk18.default.green("History merged to your account"));
|
|
7905
8165
|
}
|
|
7906
8166
|
process.exit(0);
|
|
7907
8167
|
} catch (e) {
|
|
7908
|
-
console.log(
|
|
8168
|
+
console.log(import_chalk18.default.red(`
|
|
7909
8169
|
Login failed: ${(e == null ? void 0 : e.message) || e}`));
|
|
7910
8170
|
process.exit(1);
|
|
7911
8171
|
}
|
|
7912
8172
|
}
|
|
7913
8173
|
|
|
7914
8174
|
// bin/create.ts
|
|
7915
|
-
var
|
|
8175
|
+
var import_chalk20 = __toESM(require("chalk"));
|
|
7916
8176
|
var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
7917
8177
|
var import_path11 = __toESM(require("path"));
|
|
7918
8178
|
var import_inquirer8 = __toESM(require("inquirer"));
|
|
@@ -7924,7 +8184,7 @@ init_webLogin();
|
|
|
7924
8184
|
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
7925
8185
|
var import_os4 = __toESM(require("os"));
|
|
7926
8186
|
var import_path10 = __toESM(require("path"));
|
|
7927
|
-
var
|
|
8187
|
+
var import_chalk19 = __toESM(require("chalk"));
|
|
7928
8188
|
var import_child_process2 = require("child_process");
|
|
7929
8189
|
function makeTempCacheDir() {
|
|
7930
8190
|
return import_fs_extra5.default.mkdtempSync(import_path10.default.join(import_os4.default.tmpdir(), "pinme-npm-cache-"));
|
|
@@ -7947,7 +8207,7 @@ function installProjectDependencies(cwd) {
|
|
|
7947
8207
|
const cacheDir = makeTempCacheDir();
|
|
7948
8208
|
try {
|
|
7949
8209
|
if (attempt > 1) {
|
|
7950
|
-
console.log(
|
|
8210
|
+
console.log(import_chalk19.default.yellow(" Retrying dependency install with a fresh npm cache..."));
|
|
7951
8211
|
}
|
|
7952
8212
|
runInstall(cwd, cacheDir);
|
|
7953
8213
|
return;
|
|
@@ -7960,155 +8220,8 @@ function installProjectDependencies(cwd) {
|
|
|
7960
8220
|
throw lastError;
|
|
7961
8221
|
}
|
|
7962
8222
|
|
|
7963
|
-
// bin/utils/cliError.ts
|
|
7964
|
-
var import_chalk18 = __toESM(require("chalk"));
|
|
7965
|
-
var CliError = class extends Error {
|
|
7966
|
-
stage;
|
|
7967
|
-
details;
|
|
7968
|
-
suggestions;
|
|
7969
|
-
cause;
|
|
7970
|
-
constructor(options) {
|
|
7971
|
-
super(options.summary);
|
|
7972
|
-
this.name = "CliError";
|
|
7973
|
-
this.stage = options.stage;
|
|
7974
|
-
this.details = options.details || [];
|
|
7975
|
-
this.suggestions = options.suggestions || [];
|
|
7976
|
-
this.cause = options.cause;
|
|
7977
|
-
}
|
|
7978
|
-
};
|
|
7979
|
-
function stringifyValue(value) {
|
|
7980
|
-
if (value === void 0 || value === null) {
|
|
7981
|
-
return "";
|
|
7982
|
-
}
|
|
7983
|
-
if (typeof value === "string") {
|
|
7984
|
-
return value;
|
|
7985
|
-
}
|
|
7986
|
-
try {
|
|
7987
|
-
return JSON.stringify(value);
|
|
7988
|
-
} catch (error) {
|
|
7989
|
-
return String(value);
|
|
7990
|
-
}
|
|
7991
|
-
}
|
|
7992
|
-
function getApiMessage(data) {
|
|
7993
|
-
var _a2, _b, _c;
|
|
7994
|
-
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);
|
|
7995
|
-
}
|
|
7996
|
-
function getBusinessCode(data) {
|
|
7997
|
-
if ((data == null ? void 0 : data.code) === void 0 || (data == null ? void 0 : data.code) === null) {
|
|
7998
|
-
return void 0;
|
|
7999
|
-
}
|
|
8000
|
-
return String(data.code);
|
|
8001
|
-
}
|
|
8002
|
-
function getBusinessMessage(data) {
|
|
8003
|
-
if (!(data == null ? void 0 : data.msg)) {
|
|
8004
|
-
return void 0;
|
|
8005
|
-
}
|
|
8006
|
-
return String(data.msg);
|
|
8007
|
-
}
|
|
8008
|
-
function dedupeSuggestions(suggestions) {
|
|
8009
|
-
return Array.from(new Set(suggestions.filter(Boolean)));
|
|
8010
|
-
}
|
|
8011
|
-
function createConfigError(summary, suggestions = []) {
|
|
8012
|
-
return new CliError({
|
|
8013
|
-
summary,
|
|
8014
|
-
stage: "configuration",
|
|
8015
|
-
suggestions
|
|
8016
|
-
});
|
|
8017
|
-
}
|
|
8018
|
-
function createCommandError(stage, command, error, suggestions = []) {
|
|
8019
|
-
const exitCode = (error == null ? void 0 : error.status) ?? (error == null ? void 0 : error.code);
|
|
8020
|
-
const signal = error == null ? void 0 : error.signal;
|
|
8021
|
-
const detailLines = [`Command: ${command}`];
|
|
8022
|
-
if (exitCode !== void 0) {
|
|
8023
|
-
detailLines.push(`Exit code: ${exitCode}`);
|
|
8024
|
-
}
|
|
8025
|
-
if (signal) {
|
|
8026
|
-
detailLines.push(`Signal: ${signal}`);
|
|
8027
|
-
}
|
|
8028
|
-
if (error == null ? void 0 : error.message) {
|
|
8029
|
-
detailLines.push(`Reason: ${error.message}`);
|
|
8030
|
-
}
|
|
8031
|
-
return new CliError({
|
|
8032
|
-
summary: `${stage} failed.`,
|
|
8033
|
-
stage,
|
|
8034
|
-
details: detailLines,
|
|
8035
|
-
suggestions,
|
|
8036
|
-
cause: error
|
|
8037
|
-
});
|
|
8038
|
-
}
|
|
8039
|
-
function createApiError(stage, error, context = [], suggestions = []) {
|
|
8040
|
-
var _a2, _b;
|
|
8041
|
-
const status = (_a2 = error == null ? void 0 : error.response) == null ? void 0 : _a2.status;
|
|
8042
|
-
const responseData = (_b = error == null ? void 0 : error.response) == null ? void 0 : _b.data;
|
|
8043
|
-
const errorCode = error == null ? void 0 : error.code;
|
|
8044
|
-
const apiMessage = getApiMessage(responseData);
|
|
8045
|
-
const businessCode = getBusinessCode(responseData);
|
|
8046
|
-
const businessMessage = getBusinessMessage(responseData);
|
|
8047
|
-
const summary = apiMessage || (error == null ? void 0 : error.message) || `${stage} failed.`;
|
|
8048
|
-
const detailLines = [...context];
|
|
8049
|
-
if (status) {
|
|
8050
|
-
detailLines.push(`HTTP status: ${status}`);
|
|
8051
|
-
}
|
|
8052
|
-
if (businessCode) {
|
|
8053
|
-
detailLines.push(`Business code: ${businessCode}`);
|
|
8054
|
-
}
|
|
8055
|
-
if (businessMessage && businessMessage !== apiMessage) {
|
|
8056
|
-
detailLines.push(`Business message: ${businessMessage}`);
|
|
8057
|
-
}
|
|
8058
|
-
if (apiMessage && apiMessage !== summary) {
|
|
8059
|
-
detailLines.push(`Error message: ${apiMessage}`);
|
|
8060
|
-
}
|
|
8061
|
-
if (errorCode && errorCode !== "ERR_BAD_REQUEST" && !responseData) {
|
|
8062
|
-
detailLines.push(`Error code: ${errorCode}`);
|
|
8063
|
-
}
|
|
8064
|
-
if (!responseData && (error == null ? void 0 : error.message) && error.message !== apiMessage) {
|
|
8065
|
-
detailLines.push(`Reason: ${error.message}`);
|
|
8066
|
-
}
|
|
8067
|
-
return new CliError({
|
|
8068
|
-
summary,
|
|
8069
|
-
stage,
|
|
8070
|
-
details: detailLines,
|
|
8071
|
-
suggestions: dedupeSuggestions(suggestions),
|
|
8072
|
-
cause: error
|
|
8073
|
-
});
|
|
8074
|
-
}
|
|
8075
|
-
function normalizeCliError(error, fallbackSummary, suggestions = []) {
|
|
8076
|
-
if (error instanceof CliError) {
|
|
8077
|
-
return error;
|
|
8078
|
-
}
|
|
8079
|
-
if (error instanceof Error) {
|
|
8080
|
-
return new CliError({
|
|
8081
|
-
summary: error.message || fallbackSummary,
|
|
8082
|
-
suggestions: dedupeSuggestions(suggestions),
|
|
8083
|
-
cause: error
|
|
8084
|
-
});
|
|
8085
|
-
}
|
|
8086
|
-
return new CliError({
|
|
8087
|
-
summary: fallbackSummary,
|
|
8088
|
-
details: [`Raw error: ${stringifyValue(error)}`],
|
|
8089
|
-
suggestions: dedupeSuggestions(suggestions),
|
|
8090
|
-
cause: error
|
|
8091
|
-
});
|
|
8092
|
-
}
|
|
8093
|
-
function printCliError(error, fallbackSummary) {
|
|
8094
|
-
const cliError = normalizeCliError(error, fallbackSummary);
|
|
8095
|
-
console.error(import_chalk18.default.red(`
|
|
8096
|
-
Error: ${cliError.message}`));
|
|
8097
|
-
if (cliError.stage) {
|
|
8098
|
-
console.error(import_chalk18.default.gray(`Stage: ${cliError.stage}`));
|
|
8099
|
-
}
|
|
8100
|
-
for (const detail of cliError.details) {
|
|
8101
|
-
console.error(import_chalk18.default.gray(detail));
|
|
8102
|
-
}
|
|
8103
|
-
if (cliError.suggestions.length > 0) {
|
|
8104
|
-
console.error(import_chalk18.default.yellow("\nNext steps:"));
|
|
8105
|
-
for (const suggestion of cliError.suggestions) {
|
|
8106
|
-
console.error(import_chalk18.default.yellow(`- ${suggestion}`));
|
|
8107
|
-
}
|
|
8108
|
-
}
|
|
8109
|
-
}
|
|
8110
|
-
|
|
8111
8223
|
// bin/create.ts
|
|
8224
|
+
init_cliError();
|
|
8112
8225
|
init_config();
|
|
8113
8226
|
var PROJECT_DIR = process.cwd();
|
|
8114
8227
|
var TEMPLATE_BRANCH = "feat/auth";
|
|
@@ -8164,6 +8277,9 @@ function updateFrontendUrlInConfig(configPath, frontendUrl) {
|
|
|
8164
8277
|
}
|
|
8165
8278
|
import_fs_extra6.default.writeFileSync(configPath, config);
|
|
8166
8279
|
}
|
|
8280
|
+
function getProjectManagementUrl(projectName) {
|
|
8281
|
+
return `${APP_CONFIG.projectPeviewUrl}${projectName}`;
|
|
8282
|
+
}
|
|
8167
8283
|
async function createCmd(options) {
|
|
8168
8284
|
var _a2, _b;
|
|
8169
8285
|
try {
|
|
@@ -8173,7 +8289,7 @@ async function createCmd(options) {
|
|
|
8173
8289
|
"Run `pinme login` and retry."
|
|
8174
8290
|
]);
|
|
8175
8291
|
}
|
|
8176
|
-
console.log(
|
|
8292
|
+
console.log(import_chalk20.default.blue("Creating new project from template...\n"));
|
|
8177
8293
|
let projectName = options.name;
|
|
8178
8294
|
if (!projectName) {
|
|
8179
8295
|
const answers = await import_inquirer8.default.prompt([
|
|
@@ -8194,7 +8310,7 @@ async function createCmd(options) {
|
|
|
8194
8310
|
}
|
|
8195
8311
|
const targetDir = import_path11.default.join(PROJECT_DIR, projectName);
|
|
8196
8312
|
if (import_fs_extra6.default.existsSync(targetDir) && !options.force) {
|
|
8197
|
-
console.log(
|
|
8313
|
+
console.log(import_chalk20.default.yellow(`
|
|
8198
8314
|
Directory "${projectName}" already exists.`));
|
|
8199
8315
|
const answers = await import_inquirer8.default.prompt([
|
|
8200
8316
|
{
|
|
@@ -8205,16 +8321,16 @@ Directory "${projectName}" already exists.`));
|
|
|
8205
8321
|
}
|
|
8206
8322
|
]);
|
|
8207
8323
|
if (!answers.overwrite) {
|
|
8208
|
-
console.log(
|
|
8324
|
+
console.log(import_chalk20.default.gray("Cancelled."));
|
|
8209
8325
|
process.exit(0);
|
|
8210
8326
|
}
|
|
8211
8327
|
import_fs_extra6.default.removeSync(targetDir);
|
|
8212
8328
|
}
|
|
8213
|
-
console.log(
|
|
8329
|
+
console.log(import_chalk20.default.blue("\n1. Creating worker and database..."));
|
|
8214
8330
|
const apiUrl = getPinmeApiUrl("/create_worker");
|
|
8215
|
-
console.log(
|
|
8331
|
+
console.log(import_chalk20.default.gray(`API URL: ${apiUrl}`));
|
|
8216
8332
|
const normalizedProjectName = projectName.toLowerCase();
|
|
8217
|
-
console.log(
|
|
8333
|
+
console.log(import_chalk20.default.gray(`Project name: ${normalizedProjectName}`));
|
|
8218
8334
|
let workerData;
|
|
8219
8335
|
try {
|
|
8220
8336
|
const response = await axios_default.post(apiUrl, {
|
|
@@ -8233,24 +8349,24 @@ Directory "${projectName}" already exists.`));
|
|
|
8233
8349
|
]);
|
|
8234
8350
|
}
|
|
8235
8351
|
workerData = data.data;
|
|
8236
|
-
console.log(
|
|
8237
|
-
console.log(
|
|
8238
|
-
console.log(
|
|
8352
|
+
console.log(import_chalk20.default.gray(` API Response: ${JSON.stringify(workerData)}`));
|
|
8353
|
+
console.log(import_chalk20.default.green(` API Domain: ${workerData.api_domain}`));
|
|
8354
|
+
console.log(import_chalk20.default.green(` Project Name: ${workerData.project_name}`));
|
|
8239
8355
|
} catch (error) {
|
|
8240
8356
|
throw createApiError("project creation", error, [
|
|
8241
8357
|
`Project name: ${normalizedProjectName}`,
|
|
8242
8358
|
`Endpoint: ${apiUrl}`
|
|
8243
8359
|
]);
|
|
8244
8360
|
}
|
|
8245
|
-
console.log(
|
|
8361
|
+
console.log(import_chalk20.default.blue("\n2. Downloading template from repository..."));
|
|
8246
8362
|
const zipPath = import_path11.default.join(PROJECT_DIR, "template.zip");
|
|
8247
8363
|
const extractDir = import_path11.default.join(PROJECT_DIR, `.pinme-template-${Date.now()}`);
|
|
8248
8364
|
const templateZipUrl = getTemplateZipUrl(TEMPLATE_BRANCH);
|
|
8249
8365
|
let downloadSuccess = false;
|
|
8250
|
-
console.log(
|
|
8366
|
+
console.log(import_chalk20.default.gray(` Template branch: ${TEMPLATE_BRANCH}`));
|
|
8251
8367
|
for (let attempt = 1; attempt <= 3 && !downloadSuccess; attempt++) {
|
|
8252
8368
|
try {
|
|
8253
|
-
console.log(
|
|
8369
|
+
console.log(import_chalk20.default.gray(` Download attempt ${attempt}/3...`));
|
|
8254
8370
|
(0, import_child_process3.execSync)(`curl -L --retry 3 --retry-delay 2 -o "${zipPath}" "${templateZipUrl}"`, {
|
|
8255
8371
|
stdio: "inherit"
|
|
8256
8372
|
});
|
|
@@ -8259,7 +8375,7 @@ Directory "${projectName}" already exists.`));
|
|
|
8259
8375
|
}
|
|
8260
8376
|
downloadSuccess = true;
|
|
8261
8377
|
} catch (downloadError) {
|
|
8262
|
-
console.log(
|
|
8378
|
+
console.log(import_chalk20.default.yellow(` Attempt ${attempt} failed: ${downloadError.message}`));
|
|
8263
8379
|
if (import_fs_extra6.default.existsSync(zipPath)) {
|
|
8264
8380
|
import_fs_extra6.default.removeSync(zipPath);
|
|
8265
8381
|
}
|
|
@@ -8280,11 +8396,11 @@ Directory "${projectName}" already exists.`));
|
|
|
8280
8396
|
const nodeModulesPath = import_path11.default.join(targetDir, "node_modules");
|
|
8281
8397
|
const packageLockPath = import_path11.default.join(targetDir, "package-lock.json");
|
|
8282
8398
|
if (import_fs_extra6.default.existsSync(nodeModulesPath)) {
|
|
8283
|
-
console.log(
|
|
8399
|
+
console.log(import_chalk20.default.gray(" Removing existing node_modules..."));
|
|
8284
8400
|
import_fs_extra6.default.removeSync(nodeModulesPath);
|
|
8285
8401
|
}
|
|
8286
8402
|
if (import_fs_extra6.default.existsSync(packageLockPath)) {
|
|
8287
|
-
console.log(
|
|
8403
|
+
console.log(import_chalk20.default.gray(" Removing existing package-lock.json..."));
|
|
8288
8404
|
import_fs_extra6.default.removeSync(packageLockPath);
|
|
8289
8405
|
}
|
|
8290
8406
|
const frontendNodeModules = import_path11.default.join(targetDir, "frontend", "node_modules");
|
|
@@ -8295,13 +8411,13 @@ Directory "${projectName}" already exists.`));
|
|
|
8295
8411
|
if (import_fs_extra6.default.existsSync(backendNodeModules)) import_fs_extra6.default.removeSync(backendNodeModules);
|
|
8296
8412
|
if (import_fs_extra6.default.existsSync(frontendPackageLock)) import_fs_extra6.default.removeSync(frontendPackageLock);
|
|
8297
8413
|
if (import_fs_extra6.default.existsSync(backendPackageLock)) import_fs_extra6.default.removeSync(backendPackageLock);
|
|
8298
|
-
console.log(
|
|
8414
|
+
console.log(import_chalk20.default.green(` Template downloaded to: ${targetDir}`));
|
|
8299
8415
|
} catch (error) {
|
|
8300
8416
|
throw createCommandError("template extraction", `unzip -o "${zipPath}" -d "${PROJECT_DIR}"`, error, [
|
|
8301
8417
|
"Check whether `unzip` is available and the downloaded template archive is valid."
|
|
8302
8418
|
]);
|
|
8303
8419
|
}
|
|
8304
|
-
console.log(
|
|
8420
|
+
console.log(import_chalk20.default.blue("\n3. Updating configuration..."));
|
|
8305
8421
|
const configPath = import_path11.default.join(targetDir, "pinme.toml");
|
|
8306
8422
|
const config = import_fs_extra6.default.readFileSync(configPath, "utf-8");
|
|
8307
8423
|
let updatedConfig = config.replace(
|
|
@@ -8309,8 +8425,8 @@ Directory "${projectName}" already exists.`));
|
|
|
8309
8425
|
`project_name = "${workerData.project_name}"`
|
|
8310
8426
|
);
|
|
8311
8427
|
import_fs_extra6.default.writeFileSync(configPath, updatedConfig);
|
|
8312
|
-
console.log(
|
|
8313
|
-
console.log(
|
|
8428
|
+
console.log(import_chalk20.default.green(` Updated pinme.toml`));
|
|
8429
|
+
console.log(import_chalk20.default.gray(` metadata: ${workerData.metadata}`));
|
|
8314
8430
|
const backendDir = import_path11.default.join(targetDir, "backend");
|
|
8315
8431
|
if (import_fs_extra6.default.existsSync(backendDir) && workerData.metadata) {
|
|
8316
8432
|
const metadataContent = typeof workerData.metadata === "string" ? workerData.metadata : JSON.stringify(workerData.metadata, null, 2);
|
|
@@ -8318,7 +8434,7 @@ Directory "${projectName}" already exists.`));
|
|
|
8318
8434
|
import_path11.default.join(backendDir, "metadata.json"),
|
|
8319
8435
|
metadataContent
|
|
8320
8436
|
);
|
|
8321
|
-
console.log(
|
|
8437
|
+
console.log(import_chalk20.default.green(` Saved metadata.json`));
|
|
8322
8438
|
}
|
|
8323
8439
|
const wranglerPath = import_path11.default.join(backendDir, "wrangler.toml");
|
|
8324
8440
|
if (import_fs_extra6.default.existsSync(wranglerPath) && workerData.api_key) {
|
|
@@ -8328,7 +8444,7 @@ Directory "${projectName}" already exists.`));
|
|
|
8328
8444
|
`name = "${workerData.project_name}"`
|
|
8329
8445
|
);
|
|
8330
8446
|
import_fs_extra6.default.writeFileSync(wranglerPath, wranglerContent);
|
|
8331
|
-
console.log(
|
|
8447
|
+
console.log(import_chalk20.default.green(` Updated backend/wrangler.toml API_KEY`));
|
|
8332
8448
|
}
|
|
8333
8449
|
const frontendConfigPath = import_path11.default.join(targetDir, "frontend", "src", "utils", "config.ts");
|
|
8334
8450
|
if (workerData.public_client_config) {
|
|
@@ -8338,7 +8454,7 @@ Directory "${projectName}" already exists.`));
|
|
|
8338
8454
|
frontendConfigPath,
|
|
8339
8455
|
injectPublicClientConfigIntoFile(frontendConfigContent, workerData.public_client_config)
|
|
8340
8456
|
);
|
|
8341
|
-
console.log(
|
|
8457
|
+
console.log(import_chalk20.default.green(` Updated frontend/src/utils/config.ts public_client_config`));
|
|
8342
8458
|
}
|
|
8343
8459
|
const envExamplePath = import_path11.default.join(targetDir, "frontend", ".env.example");
|
|
8344
8460
|
const envPath = import_path11.default.join(targetDir, "frontend", ".env");
|
|
@@ -8350,8 +8466,8 @@ Directory "${projectName}" already exists.`));
|
|
|
8350
8466
|
`VITE_API_URL=${workerData.api_domain}`
|
|
8351
8467
|
);
|
|
8352
8468
|
import_fs_extra6.default.writeFileSync(envPath, envContent);
|
|
8353
|
-
console.log(
|
|
8354
|
-
console.log(
|
|
8469
|
+
console.log(import_chalk20.default.green(` Created frontend/.env file`));
|
|
8470
|
+
console.log(import_chalk20.default.gray(` VITE_API_URL: ${workerData.api_domain}`));
|
|
8355
8471
|
}
|
|
8356
8472
|
let pinmeConfig = import_fs_extra6.default.readFileSync(configPath, "utf-8");
|
|
8357
8473
|
if (pinmeConfig.includes("api_url")) {
|
|
@@ -8371,11 +8487,11 @@ Directory "${projectName}" already exists.`));
|
|
|
8371
8487
|
pinmeConfig = newLines.join("\n");
|
|
8372
8488
|
}
|
|
8373
8489
|
import_fs_extra6.default.writeFileSync(configPath, pinmeConfig);
|
|
8374
|
-
console.log(
|
|
8375
|
-
console.log(
|
|
8490
|
+
console.log(import_chalk20.default.green(` Updated pinme.toml with api_url`));
|
|
8491
|
+
console.log(import_chalk20.default.blue("\n4. Installing dependencies..."));
|
|
8376
8492
|
try {
|
|
8377
8493
|
installProjectDependencies(targetDir);
|
|
8378
|
-
console.log(
|
|
8494
|
+
console.log(import_chalk20.default.green(" Project dependencies installed"));
|
|
8379
8495
|
} catch (error) {
|
|
8380
8496
|
const errorMsg = error.message || "";
|
|
8381
8497
|
if (errorMsg.includes("EACCES") || errorMsg.includes("EPERM") || errorMsg.includes("permission denied")) {
|
|
@@ -8414,13 +8530,13 @@ Directory "${projectName}" already exists.`));
|
|
|
8414
8530
|
" sudo chown -R $(whoami) " + targetDir + "/node_modules"
|
|
8415
8531
|
]);
|
|
8416
8532
|
}
|
|
8417
|
-
console.log(
|
|
8533
|
+
console.log(import_chalk20.default.blue("\n5. Building backend worker..."));
|
|
8418
8534
|
try {
|
|
8419
8535
|
(0, import_child_process3.execSync)("npm run build:worker", {
|
|
8420
8536
|
cwd: targetDir,
|
|
8421
8537
|
stdio: "inherit"
|
|
8422
8538
|
});
|
|
8423
|
-
console.log(
|
|
8539
|
+
console.log(import_chalk20.default.green(" Worker built"));
|
|
8424
8540
|
} catch (error) {
|
|
8425
8541
|
throw createCommandError("worker build", "npm run build:worker", error, [
|
|
8426
8542
|
"Fix the build error shown above, then rerun `pinme create`."
|
|
@@ -8446,12 +8562,12 @@ Directory "${projectName}" already exists.`));
|
|
|
8446
8562
|
const sqlFileNames = import_fs_extra6.default.readdirSync(sqlDir).filter((f) => f.endsWith(".sql")).sort();
|
|
8447
8563
|
for (const filename of sqlFileNames) {
|
|
8448
8564
|
sqlFiles.push(import_path11.default.join(sqlDir, filename));
|
|
8449
|
-
console.log(
|
|
8565
|
+
console.log(import_chalk20.default.gray(` Including SQL: ${filename}`));
|
|
8450
8566
|
}
|
|
8451
8567
|
}
|
|
8452
|
-
console.log(
|
|
8568
|
+
console.log(import_chalk20.default.blue("\n6. Deploying backend worker..."));
|
|
8453
8569
|
const saveApiUrl = `${getPinmeApiUrl("/save_worker")}?project_name=${encodeURIComponent(workerData.project_name)}`;
|
|
8454
|
-
console.log(
|
|
8570
|
+
console.log(import_chalk20.default.gray(` API URL: ${saveApiUrl}`));
|
|
8455
8571
|
try {
|
|
8456
8572
|
const FormData4 = (await import("formdata-node")).FormData;
|
|
8457
8573
|
const Blob2 = (await import("formdata-node")).Blob;
|
|
@@ -8483,10 +8599,10 @@ Directory "${projectName}" already exists.`));
|
|
|
8483
8599
|
timeout: 12e4
|
|
8484
8600
|
});
|
|
8485
8601
|
if (response.data) {
|
|
8486
|
-
console.log(
|
|
8602
|
+
console.log(import_chalk20.default.green(" Worker deployed"));
|
|
8487
8603
|
if ((_b = (_a2 = response.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.sql_results) {
|
|
8488
8604
|
for (const result of response.data.data.sql_results) {
|
|
8489
|
-
console.log(
|
|
8605
|
+
console.log(import_chalk20.default.gray(` SQL ${result.filename}: ${result.status}`));
|
|
8490
8606
|
}
|
|
8491
8607
|
}
|
|
8492
8608
|
} else {
|
|
@@ -8505,7 +8621,7 @@ Directory "${projectName}" already exists.`));
|
|
|
8505
8621
|
"Check whether backend metadata, SQL files, or worker bundle contains invalid content."
|
|
8506
8622
|
]);
|
|
8507
8623
|
}
|
|
8508
|
-
console.log(
|
|
8624
|
+
console.log(import_chalk20.default.blue("\n7. Building frontend..."));
|
|
8509
8625
|
const frontendDir = import_path11.default.join(targetDir, "frontend");
|
|
8510
8626
|
if (import_fs_extra6.default.existsSync(frontendDir)) {
|
|
8511
8627
|
try {
|
|
@@ -8513,37 +8629,42 @@ Directory "${projectName}" already exists.`));
|
|
|
8513
8629
|
cwd: targetDir,
|
|
8514
8630
|
stdio: "inherit"
|
|
8515
8631
|
});
|
|
8516
|
-
console.log(
|
|
8632
|
+
console.log(import_chalk20.default.green(" Frontend built"));
|
|
8517
8633
|
} catch (error) {
|
|
8518
8634
|
throw createCommandError("frontend build", "npm run build:frontend", error, [
|
|
8519
8635
|
"Fix the frontend build error shown above, then rerun `pinme create`."
|
|
8520
8636
|
]);
|
|
8521
8637
|
}
|
|
8522
|
-
console.log(
|
|
8638
|
+
console.log(import_chalk20.default.blue(" Uploading to IPFS..."));
|
|
8523
8639
|
try {
|
|
8524
8640
|
const uploadResult = await uploadPath(import_path11.default.join(frontendDir, "dist"), {
|
|
8525
8641
|
projectName: workerData.project_name,
|
|
8526
8642
|
uid: headers["token-address"]
|
|
8527
8643
|
});
|
|
8528
|
-
|
|
8644
|
+
printHighlightedUrl("Frontend URL", uploadResult.publicUrl, "primary");
|
|
8529
8645
|
updateFrontendUrlInConfig(
|
|
8530
8646
|
import_path11.default.join(targetDir, "pinme.toml"),
|
|
8531
8647
|
uploadResult.publicUrl
|
|
8532
8648
|
);
|
|
8533
|
-
console.log(
|
|
8649
|
+
console.log(import_chalk20.default.green(" Updated pinme.toml with frontend URL"));
|
|
8534
8650
|
} catch (error) {
|
|
8535
|
-
console.log(
|
|
8651
|
+
console.log(import_chalk20.default.yellow(" Warning: IPFS upload failed, you can upload manually later"));
|
|
8536
8652
|
}
|
|
8537
8653
|
}
|
|
8538
|
-
console.log(
|
|
8539
|
-
console.log(
|
|
8654
|
+
console.log(import_chalk20.default.green("\nProject created successfully."));
|
|
8655
|
+
console.log(import_chalk20.default.gray(`
|
|
8540
8656
|
Project Details:`));
|
|
8541
|
-
console.log(
|
|
8542
|
-
console.log(
|
|
8543
|
-
|
|
8657
|
+
console.log(import_chalk20.default.gray(` API Domain: ${workerData.api_domain}`));
|
|
8658
|
+
console.log(import_chalk20.default.gray(` Project Name: ${workerData.project_name}`));
|
|
8659
|
+
printHighlightedUrl(
|
|
8660
|
+
"Project Management URL",
|
|
8661
|
+
getProjectManagementUrl(workerData.project_name),
|
|
8662
|
+
"management"
|
|
8663
|
+
);
|
|
8664
|
+
console.log(import_chalk20.default.gray(`
|
|
8544
8665
|
Next steps:`));
|
|
8545
|
-
console.log(
|
|
8546
|
-
console.log(
|
|
8666
|
+
console.log(import_chalk20.default.gray(` cd ${projectName}`));
|
|
8667
|
+
console.log(import_chalk20.default.gray(` pinme save`));
|
|
8547
8668
|
process.exit(0);
|
|
8548
8669
|
} catch (error) {
|
|
8549
8670
|
printCliError(error, "Project creation failed.");
|
|
@@ -8552,13 +8673,14 @@ Next steps:`));
|
|
|
8552
8673
|
}
|
|
8553
8674
|
|
|
8554
8675
|
// bin/save.ts
|
|
8555
|
-
var
|
|
8676
|
+
var import_chalk21 = __toESM(require("chalk"));
|
|
8556
8677
|
var import_fs_extra7 = __toESM(require("fs-extra"));
|
|
8557
8678
|
var import_path12 = __toESM(require("path"));
|
|
8558
8679
|
init_axios2();
|
|
8559
8680
|
var import_child_process4 = require("child_process");
|
|
8560
8681
|
init_webLogin();
|
|
8561
8682
|
init_pinmeApi();
|
|
8683
|
+
init_cliError();
|
|
8562
8684
|
init_config();
|
|
8563
8685
|
var PROJECT_DIR2 = process.cwd();
|
|
8564
8686
|
function loadConfig() {
|
|
@@ -8575,22 +8697,25 @@ function loadConfig() {
|
|
|
8575
8697
|
project_name: (projectNameMatch == null ? void 0 : projectNameMatch[1]) || ""
|
|
8576
8698
|
};
|
|
8577
8699
|
}
|
|
8700
|
+
function getProjectManagementUrl2(projectName) {
|
|
8701
|
+
return `${APP_CONFIG.projectPeviewUrl}${projectName}`;
|
|
8702
|
+
}
|
|
8578
8703
|
function getMetadata() {
|
|
8579
8704
|
const metadataPath = import_path12.default.join(PROJECT_DIR2, "backend", "metadata.json");
|
|
8580
8705
|
if (!import_fs_extra7.default.existsSync(metadataPath)) {
|
|
8581
|
-
console.log(
|
|
8706
|
+
console.log(import_chalk21.default.yellow(" Warning: metadata.json not found, using empty metadata"));
|
|
8582
8707
|
return {};
|
|
8583
8708
|
}
|
|
8584
8709
|
return import_fs_extra7.default.readJsonSync(metadataPath);
|
|
8585
8710
|
}
|
|
8586
8711
|
function buildWorker() {
|
|
8587
|
-
console.log(
|
|
8712
|
+
console.log(import_chalk21.default.blue("Building worker..."));
|
|
8588
8713
|
try {
|
|
8589
8714
|
(0, import_child_process4.execSync)("npm run build:worker", {
|
|
8590
8715
|
cwd: PROJECT_DIR2,
|
|
8591
8716
|
stdio: "inherit"
|
|
8592
8717
|
});
|
|
8593
|
-
console.log(
|
|
8718
|
+
console.log(import_chalk21.default.green("Worker built"));
|
|
8594
8719
|
} catch (error) {
|
|
8595
8720
|
throw createCommandError("worker build", "npm run build:worker", error, [
|
|
8596
8721
|
"Fix the build error shown above, then rerun `pinme save`."
|
|
@@ -8598,10 +8723,10 @@ function buildWorker() {
|
|
|
8598
8723
|
}
|
|
8599
8724
|
}
|
|
8600
8725
|
function installDependencies() {
|
|
8601
|
-
console.log(
|
|
8726
|
+
console.log(import_chalk21.default.blue("Installing dependencies..."));
|
|
8602
8727
|
try {
|
|
8603
8728
|
installProjectDependencies(PROJECT_DIR2);
|
|
8604
|
-
console.log(
|
|
8729
|
+
console.log(import_chalk21.default.green("Project dependencies installed"));
|
|
8605
8730
|
} catch (error) {
|
|
8606
8731
|
const errorMsg = error.message || "";
|
|
8607
8732
|
if (errorMsg.includes("EACCES") || errorMsg.includes("EPERM") || errorMsg.includes("permission denied")) {
|
|
@@ -8673,15 +8798,15 @@ function getSqlFiles() {
|
|
|
8673
8798
|
}
|
|
8674
8799
|
async function saveWorker(workerJsPath, modulePaths, sqlFiles, metadata, projectName) {
|
|
8675
8800
|
var _a2, _b;
|
|
8676
|
-
console.log(
|
|
8677
|
-
console.log(
|
|
8678
|
-
console.log(
|
|
8679
|
-
console.log(
|
|
8680
|
-
console.log(
|
|
8681
|
-
console.log(
|
|
8801
|
+
console.log(import_chalk21.default.blue("Saving worker to platform..."));
|
|
8802
|
+
console.log(import_chalk21.default.gray(`Project: ${projectName}`));
|
|
8803
|
+
console.log(import_chalk21.default.gray(`workerJsPath: ${workerJsPath}`));
|
|
8804
|
+
console.log(import_chalk21.default.gray(`modulePaths: ${modulePaths}`));
|
|
8805
|
+
console.log(import_chalk21.default.gray(`sqlFiles: ${sqlFiles}`));
|
|
8806
|
+
console.log(import_chalk21.default.gray(`metadata: ${metadata}`));
|
|
8682
8807
|
const apiUrl = `${getPinmeApiUrl("/save_worker")}?project_name=${encodeURIComponent(projectName)}`;
|
|
8683
8808
|
const headers = getAuthHeaders();
|
|
8684
|
-
console.log(
|
|
8809
|
+
console.log(import_chalk21.default.gray(`API URL: ${apiUrl}`));
|
|
8685
8810
|
try {
|
|
8686
8811
|
const FormData4 = (await import("formdata-node")).FormData;
|
|
8687
8812
|
const Blob2 = (await import("formdata-node")).Blob;
|
|
@@ -8706,18 +8831,18 @@ async function saveWorker(workerJsPath, modulePaths, sqlFiles, metadata, project
|
|
|
8706
8831
|
formData.append("sql_file", new Blob2([content], {
|
|
8707
8832
|
type: "application/sql"
|
|
8708
8833
|
}), filename);
|
|
8709
|
-
console.log(
|
|
8834
|
+
console.log(import_chalk21.default.gray(` Including SQL: ${filename}`));
|
|
8710
8835
|
}
|
|
8711
8836
|
const response = await axios_default.put(apiUrl, formData, {
|
|
8712
8837
|
headers: { ...headers },
|
|
8713
8838
|
timeout: 12e4
|
|
8714
8839
|
});
|
|
8715
|
-
console.log(
|
|
8840
|
+
console.log(import_chalk21.default.gray(` Response: ${JSON.stringify(response.data)}`));
|
|
8716
8841
|
if (response.data) {
|
|
8717
|
-
console.log(
|
|
8842
|
+
console.log(import_chalk21.default.green("Worker saved"));
|
|
8718
8843
|
if ((_b = (_a2 = response.data) == null ? void 0 : _a2.data) == null ? void 0 : _b.sql_results) {
|
|
8719
8844
|
for (const result of response.data.data.sql_results) {
|
|
8720
|
-
console.log(
|
|
8845
|
+
console.log(import_chalk21.default.gray(` SQL ${result.filename}: ${result.status}`));
|
|
8721
8846
|
}
|
|
8722
8847
|
}
|
|
8723
8848
|
} else {
|
|
@@ -8738,13 +8863,13 @@ async function saveWorker(workerJsPath, modulePaths, sqlFiles, metadata, project
|
|
|
8738
8863
|
}
|
|
8739
8864
|
}
|
|
8740
8865
|
function buildFrontend() {
|
|
8741
|
-
console.log(
|
|
8866
|
+
console.log(import_chalk21.default.blue("Building frontend..."));
|
|
8742
8867
|
try {
|
|
8743
8868
|
(0, import_child_process4.execSync)("npm run build:frontend", {
|
|
8744
8869
|
cwd: PROJECT_DIR2,
|
|
8745
8870
|
stdio: "inherit"
|
|
8746
8871
|
});
|
|
8747
|
-
console.log(
|
|
8872
|
+
console.log(import_chalk21.default.green("Frontend built"));
|
|
8748
8873
|
} catch (error) {
|
|
8749
8874
|
throw createCommandError("frontend build", "npm run build:frontend", error, [
|
|
8750
8875
|
"Fix the frontend build error shown above, then rerun `pinme save`."
|
|
@@ -8768,7 +8893,7 @@ function updateFrontendUrlInConfig2(configPath, frontendUrl) {
|
|
|
8768
8893
|
import_fs_extra7.default.writeFileSync(configPath, config);
|
|
8769
8894
|
}
|
|
8770
8895
|
async function deployFrontend(projectName) {
|
|
8771
|
-
console.log(
|
|
8896
|
+
console.log(import_chalk21.default.blue("Deploying frontend to IPFS..."));
|
|
8772
8897
|
try {
|
|
8773
8898
|
const headers = getAuthHeaders();
|
|
8774
8899
|
const uploadResult = await uploadPath(import_path12.default.join(PROJECT_DIR2, "frontend", "dist"), {
|
|
@@ -8831,8 +8956,8 @@ async function saveCmd(options) {
|
|
|
8831
8956
|
if (import_fs_extra7.default.existsSync(tokenFileSrc) && !import_fs_extra7.default.existsSync(tokenFileDst)) {
|
|
8832
8957
|
import_fs_extra7.default.copySync(tokenFileSrc, tokenFileDst);
|
|
8833
8958
|
}
|
|
8834
|
-
console.log(
|
|
8835
|
-
console.log(
|
|
8959
|
+
console.log(import_chalk21.default.blue("Deploying to platform...\n"));
|
|
8960
|
+
console.log(import_chalk21.default.gray(`Project dir: ${PROJECT_DIR2}`));
|
|
8836
8961
|
const config = loadConfig();
|
|
8837
8962
|
const projectName = config.project_name;
|
|
8838
8963
|
if (!projectName) {
|
|
@@ -8840,20 +8965,20 @@ async function saveCmd(options) {
|
|
|
8840
8965
|
'Set `project_name = "your-project-name"` in `pinme.toml`.'
|
|
8841
8966
|
]);
|
|
8842
8967
|
}
|
|
8843
|
-
console.log(
|
|
8968
|
+
console.log(import_chalk21.default.gray(`Project: ${projectName}`));
|
|
8844
8969
|
const apiUrl = `${getPinmeApiUrl("/save_worker")}?project_name=${encodeURIComponent(projectName)}`;
|
|
8845
|
-
console.log(
|
|
8846
|
-
console.log(
|
|
8970
|
+
console.log(import_chalk21.default.gray(`API URL: ${apiUrl}`));
|
|
8971
|
+
console.log(import_chalk21.default.blue("\n--- Backend ---"));
|
|
8847
8972
|
installDependencies();
|
|
8848
8973
|
buildWorker();
|
|
8849
8974
|
const metadata = getMetadata();
|
|
8850
8975
|
const { workerJsPath, modulePaths } = getBuiltWorker();
|
|
8851
|
-
console.log(
|
|
8852
|
-
console.log(
|
|
8976
|
+
console.log(import_chalk21.default.gray(`Worker JS: ${workerJsPath}`));
|
|
8977
|
+
console.log(import_chalk21.default.gray(`Module paths: ${JSON.stringify(modulePaths)}`));
|
|
8853
8978
|
const sqlFiles = getSqlFiles();
|
|
8854
|
-
console.log(
|
|
8979
|
+
console.log(import_chalk21.default.gray(`SQL files: ${JSON.stringify(sqlFiles)}`));
|
|
8855
8980
|
await saveWorker(workerJsPath, modulePaths, sqlFiles, metadata, projectName);
|
|
8856
|
-
console.log(
|
|
8981
|
+
console.log(import_chalk21.default.blue("\n--- Frontend ---"));
|
|
8857
8982
|
buildFrontend();
|
|
8858
8983
|
const frontendResult = await deployFrontend(projectName);
|
|
8859
8984
|
let finalFrontendUrl = frontendResult.publicUrl;
|
|
@@ -8865,9 +8990,14 @@ async function saveCmd(options) {
|
|
|
8865
8990
|
headers
|
|
8866
8991
|
);
|
|
8867
8992
|
}
|
|
8868
|
-
console.log(
|
|
8869
|
-
|
|
8870
|
-
|
|
8993
|
+
console.log(import_chalk21.default.blue("\n--- Access ---"));
|
|
8994
|
+
printHighlightedUrl("Frontend URL", finalFrontendUrl, "primary");
|
|
8995
|
+
printHighlightedUrl(
|
|
8996
|
+
"Project Management URL",
|
|
8997
|
+
getProjectManagementUrl2(projectName),
|
|
8998
|
+
"management"
|
|
8999
|
+
);
|
|
9000
|
+
console.log(import_chalk21.default.green("\nDeployment complete."));
|
|
8871
9001
|
process.exit(0);
|
|
8872
9002
|
} catch (error) {
|
|
8873
9003
|
printCliError(error, "Save failed.");
|
|
@@ -8876,11 +9006,12 @@ async function saveCmd(options) {
|
|
|
8876
9006
|
}
|
|
8877
9007
|
|
|
8878
9008
|
// bin/updateDb.ts
|
|
8879
|
-
var
|
|
9009
|
+
var import_chalk22 = __toESM(require("chalk"));
|
|
8880
9010
|
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
8881
9011
|
var import_path13 = __toESM(require("path"));
|
|
8882
9012
|
init_axios2();
|
|
8883
9013
|
init_webLogin();
|
|
9014
|
+
init_cliError();
|
|
8884
9015
|
init_config();
|
|
8885
9016
|
var PROJECT_DIR3 = process.cwd();
|
|
8886
9017
|
function loadConfig2() {
|
|
@@ -8912,12 +9043,12 @@ function getSqlFiles2() {
|
|
|
8912
9043
|
return files.map((f) => import_path13.default.join(sqlDir, f));
|
|
8913
9044
|
}
|
|
8914
9045
|
async function updateDb(sqlFiles, projectName) {
|
|
8915
|
-
console.log(
|
|
8916
|
-
console.log(
|
|
8917
|
-
console.log(
|
|
9046
|
+
console.log(import_chalk22.default.blue("Importing SQL files to database..."));
|
|
9047
|
+
console.log(import_chalk22.default.gray(`Project: ${projectName}`));
|
|
9048
|
+
console.log(import_chalk22.default.gray(`SQL files: ${sqlFiles.length}`));
|
|
8918
9049
|
const apiUrl = `${getPinmeApiUrl("/update_db")}?project_name=${encodeURIComponent(projectName)}`;
|
|
8919
9050
|
const headers = getAuthHeaders();
|
|
8920
|
-
console.log(
|
|
9051
|
+
console.log(import_chalk22.default.gray(`API URL: ${apiUrl}`));
|
|
8921
9052
|
try {
|
|
8922
9053
|
const FormData4 = (await import("formdata-node")).FormData;
|
|
8923
9054
|
const Blob2 = (await import("formdata-node")).Blob;
|
|
@@ -8935,24 +9066,24 @@ async function updateDb(sqlFiles, projectName) {
|
|
|
8935
9066
|
formData.append("file", new Blob2([content], {
|
|
8936
9067
|
type: "application/sql"
|
|
8937
9068
|
}), filename);
|
|
8938
|
-
console.log(
|
|
9069
|
+
console.log(import_chalk22.default.gray(` Including: ${filename} (${content.length} bytes)`));
|
|
8939
9070
|
}
|
|
8940
9071
|
const response = await axios_default.post(apiUrl, formData, {
|
|
8941
9072
|
headers: { ...headers },
|
|
8942
9073
|
timeout: 12e4
|
|
8943
9074
|
});
|
|
8944
|
-
console.log(
|
|
9075
|
+
console.log(import_chalk22.default.gray(` Response: ${JSON.stringify(response.data)}`));
|
|
8945
9076
|
if (response.data.code === 200) {
|
|
8946
|
-
console.log(
|
|
9077
|
+
console.log(import_chalk22.default.green("SQL files imported successfully!"));
|
|
8947
9078
|
const results = response.data.data.results;
|
|
8948
9079
|
for (const result of results) {
|
|
8949
9080
|
if (result.status === "complete") {
|
|
8950
|
-
console.log(
|
|
9081
|
+
console.log(import_chalk22.default.green(` COMPLETE ${result.filename}: ${result.num_queries} queries, ${result.duration}ms`));
|
|
8951
9082
|
if (result.changes !== void 0) {
|
|
8952
|
-
console.log(
|
|
9083
|
+
console.log(import_chalk22.default.gray(` Changes: ${result.changes}, Read: ${result.rows_read}, Written: ${result.rows_written}`));
|
|
8953
9084
|
}
|
|
8954
9085
|
} else if (result.status === "error") {
|
|
8955
|
-
console.log(
|
|
9086
|
+
console.log(import_chalk22.default.red(` ERROR ${result.filename}: ${result.error}`));
|
|
8956
9087
|
}
|
|
8957
9088
|
}
|
|
8958
9089
|
} else {
|
|
@@ -8986,8 +9117,8 @@ async function updateDbCmd(options) {
|
|
|
8986
9117
|
if (import_fs_extra8.default.existsSync(tokenFileSrc) && !import_fs_extra8.default.existsSync(tokenFileDst)) {
|
|
8987
9118
|
import_fs_extra8.default.copySync(tokenFileSrc, tokenFileDst);
|
|
8988
9119
|
}
|
|
8989
|
-
console.log(
|
|
8990
|
-
console.log(
|
|
9120
|
+
console.log(import_chalk22.default.blue("Importing SQL to database...\n"));
|
|
9121
|
+
console.log(import_chalk22.default.gray(`Project dir: ${PROJECT_DIR3}`));
|
|
8991
9122
|
const config = loadConfig2();
|
|
8992
9123
|
const projectName = config.project_name;
|
|
8993
9124
|
if (!projectName) {
|
|
@@ -8995,11 +9126,11 @@ async function updateDbCmd(options) {
|
|
|
8995
9126
|
'Set `project_name = "your-project-name"` in `pinme.toml`.'
|
|
8996
9127
|
]);
|
|
8997
9128
|
}
|
|
8998
|
-
console.log(
|
|
9129
|
+
console.log(import_chalk22.default.gray(`Project: ${projectName}`));
|
|
8999
9130
|
const sqlFiles = getSqlFiles2();
|
|
9000
|
-
console.log(
|
|
9131
|
+
console.log(import_chalk22.default.gray(`Found ${sqlFiles.length} SQL file(s) in db`));
|
|
9001
9132
|
await updateDb(sqlFiles, projectName);
|
|
9002
|
-
console.log(
|
|
9133
|
+
console.log(import_chalk22.default.green("\nDatabase update complete."));
|
|
9003
9134
|
process.exit(0);
|
|
9004
9135
|
} catch (error) {
|
|
9005
9136
|
printCliError(error, "Database update failed.");
|
|
@@ -9008,12 +9139,13 @@ async function updateDbCmd(options) {
|
|
|
9008
9139
|
}
|
|
9009
9140
|
|
|
9010
9141
|
// bin/updateWorker.ts
|
|
9011
|
-
var
|
|
9142
|
+
var import_chalk23 = __toESM(require("chalk"));
|
|
9012
9143
|
var import_fs_extra9 = __toESM(require("fs-extra"));
|
|
9013
9144
|
var import_path14 = __toESM(require("path"));
|
|
9014
9145
|
init_axios2();
|
|
9015
9146
|
var import_child_process5 = require("child_process");
|
|
9016
9147
|
init_webLogin();
|
|
9148
|
+
init_cliError();
|
|
9017
9149
|
init_config();
|
|
9018
9150
|
var PROJECT_DIR4 = process.cwd();
|
|
9019
9151
|
function loadConfig3() {
|
|
@@ -9039,13 +9171,13 @@ function getMetadata2() {
|
|
|
9039
9171
|
return import_fs_extra9.default.readJsonSync(metadataPath);
|
|
9040
9172
|
}
|
|
9041
9173
|
function buildWorker2() {
|
|
9042
|
-
console.log(
|
|
9174
|
+
console.log(import_chalk23.default.blue("Building worker..."));
|
|
9043
9175
|
try {
|
|
9044
9176
|
(0, import_child_process5.execSync)("npm run build:worker", {
|
|
9045
9177
|
cwd: PROJECT_DIR4,
|
|
9046
9178
|
stdio: "inherit"
|
|
9047
9179
|
});
|
|
9048
|
-
console.log(
|
|
9180
|
+
console.log(import_chalk23.default.green("Worker built"));
|
|
9049
9181
|
} catch (error) {
|
|
9050
9182
|
throw createCommandError("worker build", "npm run build:worker", error, [
|
|
9051
9183
|
"Fix the build error shown above, then rerun `pinme update-worker`."
|
|
@@ -9075,14 +9207,14 @@ function getBuiltWorker2() {
|
|
|
9075
9207
|
return { workerJsPath, modulePaths };
|
|
9076
9208
|
}
|
|
9077
9209
|
async function updateWorker(workerJsPath, modulePaths, metadata, projectName) {
|
|
9078
|
-
console.log(
|
|
9079
|
-
console.log(
|
|
9080
|
-
console.log(
|
|
9081
|
-
console.log(
|
|
9082
|
-
console.log(
|
|
9210
|
+
console.log(import_chalk23.default.blue("Updating worker on platform..."));
|
|
9211
|
+
console.log(import_chalk23.default.gray(`Project: ${projectName}`));
|
|
9212
|
+
console.log(import_chalk23.default.gray(`workerJsPath: ${workerJsPath}`));
|
|
9213
|
+
console.log(import_chalk23.default.gray(`modulePaths: ${modulePaths}`));
|
|
9214
|
+
console.log(import_chalk23.default.gray(`metadata: ${metadata}`));
|
|
9083
9215
|
const apiUrl = `${getPinmeApiUrl("/update_worker")}?project_name=${encodeURIComponent(projectName)}`;
|
|
9084
9216
|
const headers = getAuthHeaders();
|
|
9085
|
-
console.log(
|
|
9217
|
+
console.log(import_chalk23.default.gray(`API URL: ${apiUrl}`));
|
|
9086
9218
|
try {
|
|
9087
9219
|
const FormData4 = (await import("formdata-node")).FormData;
|
|
9088
9220
|
const Blob2 = (await import("formdata-node")).Blob;
|
|
@@ -9105,33 +9237,33 @@ async function updateWorker(workerJsPath, modulePaths, metadata, projectName) {
|
|
|
9105
9237
|
headers: { ...headers },
|
|
9106
9238
|
timeout: 12e4
|
|
9107
9239
|
});
|
|
9108
|
-
console.log(
|
|
9240
|
+
console.log(import_chalk23.default.gray(` Response: ${JSON.stringify(response.data)}`));
|
|
9109
9241
|
if (response.data) {
|
|
9110
|
-
console.log(
|
|
9242
|
+
console.log(import_chalk23.default.green("Worker updated"));
|
|
9111
9243
|
const data = response.data.data;
|
|
9112
9244
|
if (data.worker_id) {
|
|
9113
|
-
console.log(
|
|
9245
|
+
console.log(import_chalk23.default.gray(` Worker ID: ${data.worker_id}`));
|
|
9114
9246
|
}
|
|
9115
9247
|
if (data.deployment_id) {
|
|
9116
|
-
console.log(
|
|
9248
|
+
console.log(import_chalk23.default.gray(` Deployment ID: ${data.deployment_id}`));
|
|
9117
9249
|
}
|
|
9118
9250
|
if (data.entry_point) {
|
|
9119
|
-
console.log(
|
|
9251
|
+
console.log(import_chalk23.default.gray(` Entry Point: ${data.entry_point}`));
|
|
9120
9252
|
}
|
|
9121
9253
|
if (data.created_on) {
|
|
9122
|
-
console.log(
|
|
9254
|
+
console.log(import_chalk23.default.gray(` Created: ${data.created_on}`));
|
|
9123
9255
|
}
|
|
9124
9256
|
if (data.modified_on) {
|
|
9125
|
-
console.log(
|
|
9257
|
+
console.log(import_chalk23.default.gray(` Modified: ${data.modified_on}`));
|
|
9126
9258
|
}
|
|
9127
9259
|
if (data.startup_time_ms !== void 0) {
|
|
9128
|
-
console.log(
|
|
9260
|
+
console.log(import_chalk23.default.gray(` Startup Time: ${data.startup_time_ms}ms`));
|
|
9129
9261
|
}
|
|
9130
9262
|
if (data.has_modules !== void 0) {
|
|
9131
|
-
console.log(
|
|
9263
|
+
console.log(import_chalk23.default.gray(` Has Modules: ${data.has_modules}`));
|
|
9132
9264
|
}
|
|
9133
9265
|
if (data.domain) {
|
|
9134
|
-
console.log(
|
|
9266
|
+
console.log(import_chalk23.default.gray(` Domain: ${data.domain}`));
|
|
9135
9267
|
}
|
|
9136
9268
|
} else {
|
|
9137
9269
|
throw createApiError("worker update", { response: { data: response.data } }, [
|
|
@@ -9164,8 +9296,8 @@ async function updateWorkerCmd(options) {
|
|
|
9164
9296
|
if (import_fs_extra9.default.existsSync(tokenFileSrc) && !import_fs_extra9.default.existsSync(tokenFileDst)) {
|
|
9165
9297
|
import_fs_extra9.default.copySync(tokenFileSrc, tokenFileDst);
|
|
9166
9298
|
}
|
|
9167
|
-
console.log(
|
|
9168
|
-
console.log(
|
|
9299
|
+
console.log(import_chalk23.default.blue("Updating worker...\n"));
|
|
9300
|
+
console.log(import_chalk23.default.gray(`Project dir: ${PROJECT_DIR4}`));
|
|
9169
9301
|
const config = loadConfig3();
|
|
9170
9302
|
const projectName = config.project_name;
|
|
9171
9303
|
if (!projectName) {
|
|
@@ -9173,16 +9305,16 @@ async function updateWorkerCmd(options) {
|
|
|
9173
9305
|
'Set `project_name = "your-project-name"` in `pinme.toml`.'
|
|
9174
9306
|
]);
|
|
9175
9307
|
}
|
|
9176
|
-
console.log(
|
|
9177
|
-
console.log(
|
|
9308
|
+
console.log(import_chalk23.default.gray(`Project: ${projectName}`));
|
|
9309
|
+
console.log(import_chalk23.default.blue("\n--- Worker Update ---"));
|
|
9178
9310
|
buildWorker2();
|
|
9179
9311
|
const metadata = getMetadata2();
|
|
9180
9312
|
const { workerJsPath, modulePaths } = getBuiltWorker2();
|
|
9181
|
-
console.log(
|
|
9182
|
-
console.log(
|
|
9183
|
-
console.log(
|
|
9313
|
+
console.log(import_chalk23.default.gray(`Worker JS: ${workerJsPath}`));
|
|
9314
|
+
console.log(import_chalk23.default.gray(`Module paths: ${JSON.stringify(modulePaths)}`));
|
|
9315
|
+
console.log(import_chalk23.default.gray(`SQL files: ignored (not processed for update_worker)`));
|
|
9184
9316
|
await updateWorker(workerJsPath, modulePaths, metadata, projectName);
|
|
9185
|
-
console.log(
|
|
9317
|
+
console.log(import_chalk23.default.green("\nWorker update complete."));
|
|
9186
9318
|
process.exit(0);
|
|
9187
9319
|
} catch (error) {
|
|
9188
9320
|
printCliError(error, "Worker update failed.");
|
|
@@ -9191,11 +9323,13 @@ async function updateWorkerCmd(options) {
|
|
|
9191
9323
|
}
|
|
9192
9324
|
|
|
9193
9325
|
// bin/updateWeb.ts
|
|
9194
|
-
var
|
|
9326
|
+
var import_chalk24 = __toESM(require("chalk"));
|
|
9195
9327
|
var import_fs_extra10 = __toESM(require("fs-extra"));
|
|
9196
9328
|
var import_path15 = __toESM(require("path"));
|
|
9197
9329
|
var import_child_process6 = require("child_process");
|
|
9198
9330
|
init_webLogin();
|
|
9331
|
+
init_cliError();
|
|
9332
|
+
init_config();
|
|
9199
9333
|
var PROJECT_DIR5 = process.cwd();
|
|
9200
9334
|
function loadConfig4() {
|
|
9201
9335
|
const configPath = import_path15.default.join(PROJECT_DIR5, "pinme.toml");
|
|
@@ -9210,14 +9344,17 @@ function loadConfig4() {
|
|
|
9210
9344
|
project_name: (projectNameMatch == null ? void 0 : projectNameMatch[1]) || ""
|
|
9211
9345
|
};
|
|
9212
9346
|
}
|
|
9347
|
+
function getProjectManagementUrl3(projectName) {
|
|
9348
|
+
return `${APP_CONFIG.projectPeviewUrl}${projectName}`;
|
|
9349
|
+
}
|
|
9213
9350
|
function buildFrontend2() {
|
|
9214
|
-
console.log(
|
|
9351
|
+
console.log(import_chalk24.default.blue("Building frontend..."));
|
|
9215
9352
|
try {
|
|
9216
9353
|
(0, import_child_process6.execSync)("npm run build:frontend", {
|
|
9217
9354
|
cwd: PROJECT_DIR5,
|
|
9218
9355
|
stdio: "inherit"
|
|
9219
9356
|
});
|
|
9220
|
-
console.log(
|
|
9357
|
+
console.log(import_chalk24.default.green("Frontend built"));
|
|
9221
9358
|
} catch (error) {
|
|
9222
9359
|
throw createCommandError("frontend build", "npm run build:frontend", error, [
|
|
9223
9360
|
"Fix the frontend build error shown above, then rerun `pinme update-web`."
|
|
@@ -9225,14 +9362,19 @@ function buildFrontend2() {
|
|
|
9225
9362
|
}
|
|
9226
9363
|
}
|
|
9227
9364
|
async function deployFrontend2(projectName) {
|
|
9228
|
-
console.log(
|
|
9365
|
+
console.log(import_chalk24.default.blue("Deploying frontend to IPFS..."));
|
|
9229
9366
|
try {
|
|
9230
9367
|
const headers = getAuthHeaders();
|
|
9231
9368
|
const uploadResult = await uploadPath(import_path15.default.join(PROJECT_DIR5, "frontend", "dist"), {
|
|
9232
9369
|
projectName,
|
|
9233
9370
|
uid: headers["token-address"]
|
|
9234
9371
|
});
|
|
9235
|
-
|
|
9372
|
+
printHighlightedUrl("Frontend URL", uploadResult.publicUrl, "primary");
|
|
9373
|
+
printHighlightedUrl(
|
|
9374
|
+
"Project Management URL",
|
|
9375
|
+
getProjectManagementUrl3(projectName),
|
|
9376
|
+
"management"
|
|
9377
|
+
);
|
|
9236
9378
|
} catch (error) {
|
|
9237
9379
|
throw createCommandError("frontend deploy", "upload frontend/dist", error, [
|
|
9238
9380
|
"Make sure `frontend/dist` exists and the upload API is reachable."
|
|
@@ -9253,8 +9395,8 @@ async function updateWebCmd(options) {
|
|
|
9253
9395
|
if (import_fs_extra10.default.existsSync(tokenFileSrc) && !import_fs_extra10.default.existsSync(tokenFileDst)) {
|
|
9254
9396
|
import_fs_extra10.default.copySync(tokenFileSrc, tokenFileDst);
|
|
9255
9397
|
}
|
|
9256
|
-
console.log(
|
|
9257
|
-
console.log(
|
|
9398
|
+
console.log(import_chalk24.default.blue("Updating web (frontend)...\n"));
|
|
9399
|
+
console.log(import_chalk24.default.gray(`Project dir: ${PROJECT_DIR5}`));
|
|
9258
9400
|
const config = loadConfig4();
|
|
9259
9401
|
const projectName = config.project_name;
|
|
9260
9402
|
if (!projectName) {
|
|
@@ -9262,11 +9404,11 @@ async function updateWebCmd(options) {
|
|
|
9262
9404
|
'Set `project_name = "your-project-name"` in `pinme.toml`.'
|
|
9263
9405
|
]);
|
|
9264
9406
|
}
|
|
9265
|
-
console.log(
|
|
9266
|
-
console.log(
|
|
9407
|
+
console.log(import_chalk24.default.gray(`Project: ${projectName}`));
|
|
9408
|
+
console.log(import_chalk24.default.blue("\n--- Frontend Update ---"));
|
|
9267
9409
|
buildFrontend2();
|
|
9268
9410
|
await deployFrontend2(projectName);
|
|
9269
|
-
console.log(
|
|
9411
|
+
console.log(import_chalk24.default.green("\nWeb update complete."));
|
|
9270
9412
|
process.exit(0);
|
|
9271
9413
|
} catch (error) {
|
|
9272
9414
|
printCliError(error, "Web update failed.");
|
|
@@ -9275,7 +9417,7 @@ async function updateWebCmd(options) {
|
|
|
9275
9417
|
}
|
|
9276
9418
|
|
|
9277
9419
|
// bin/delete.ts
|
|
9278
|
-
var
|
|
9420
|
+
var import_chalk25 = __toESM(require("chalk"));
|
|
9279
9421
|
var import_inquirer9 = __toESM(require("inquirer"));
|
|
9280
9422
|
init_axios2();
|
|
9281
9423
|
var import_fs_extra11 = __toESM(require("fs-extra"));
|
|
@@ -9296,23 +9438,23 @@ async function deleteCmd(options) {
|
|
|
9296
9438
|
try {
|
|
9297
9439
|
const headers = getAuthHeaders();
|
|
9298
9440
|
if (!headers["authentication-tokens"] || !headers["token-address"]) {
|
|
9299
|
-
console.log(
|
|
9300
|
-
console.log(
|
|
9441
|
+
console.log(import_chalk25.default.yellow("\n\u26A0\uFE0F You are not logged in."));
|
|
9442
|
+
console.log(import_chalk25.default.gray("Please run: pinme login"));
|
|
9301
9443
|
process.exit(1);
|
|
9302
9444
|
}
|
|
9303
|
-
console.log(
|
|
9445
|
+
console.log(import_chalk25.default.blue("Deleting project...\n"));
|
|
9304
9446
|
let projectName = options.name || getProjectName();
|
|
9305
9447
|
if (!projectName) {
|
|
9306
|
-
console.log(
|
|
9307
|
-
console.log(
|
|
9308
|
-
console.log(
|
|
9309
|
-
console.log(
|
|
9310
|
-
console.log(
|
|
9311
|
-
console.log(
|
|
9448
|
+
console.log(import_chalk25.default.red("\n\u274C Error: Cannot find project name."));
|
|
9449
|
+
console.log(import_chalk25.default.yellow(" Please make sure you are in the project directory."));
|
|
9450
|
+
console.log(import_chalk25.default.gray(" The project directory should contain a pinme.toml file."));
|
|
9451
|
+
console.log(import_chalk25.default.gray("\n Or specify the project name:"));
|
|
9452
|
+
console.log(import_chalk25.default.gray(" cd /path/to/your-project"));
|
|
9453
|
+
console.log(import_chalk25.default.gray(" pinme delete"));
|
|
9312
9454
|
process.exit(1);
|
|
9313
9455
|
}
|
|
9314
|
-
console.log(
|
|
9315
|
-
console.log(
|
|
9456
|
+
console.log(import_chalk25.default.gray(`Project: ${projectName}`));
|
|
9457
|
+
console.log(import_chalk25.default.gray(`Directory: ${process.cwd()}`));
|
|
9316
9458
|
if (!options.force) {
|
|
9317
9459
|
const answers = await import_inquirer9.default.prompt([
|
|
9318
9460
|
{
|
|
@@ -9323,14 +9465,14 @@ async function deleteCmd(options) {
|
|
|
9323
9465
|
}
|
|
9324
9466
|
]);
|
|
9325
9467
|
if (!answers.confirm) {
|
|
9326
|
-
console.log(
|
|
9468
|
+
console.log(import_chalk25.default.gray("Cancelled."));
|
|
9327
9469
|
process.exit(0);
|
|
9328
9470
|
}
|
|
9329
9471
|
}
|
|
9330
|
-
console.log(
|
|
9472
|
+
console.log(import_chalk25.default.blue("Deleting project on platform..."));
|
|
9331
9473
|
const apiUrl = getPinmeApiUrl("/delete_project");
|
|
9332
|
-
console.log(
|
|
9333
|
-
console.log(
|
|
9474
|
+
console.log(import_chalk25.default.gray(`API URL: ${apiUrl}`));
|
|
9475
|
+
console.log(import_chalk25.default.gray(`Project name: ${projectName}`));
|
|
9334
9476
|
const response = await axios_default.post(apiUrl, {
|
|
9335
9477
|
project_name: projectName
|
|
9336
9478
|
}, {
|
|
@@ -9341,31 +9483,31 @@ async function deleteCmd(options) {
|
|
|
9341
9483
|
}).catch((error) => {
|
|
9342
9484
|
var _a3, _b2;
|
|
9343
9485
|
if (error.response) {
|
|
9344
|
-
console.log(
|
|
9345
|
-
console.log(
|
|
9486
|
+
console.log(import_chalk25.default.red(` Response status: ${(_a3 = error.response) == null ? void 0 : _a3.status}`));
|
|
9487
|
+
console.log(import_chalk25.default.red(` Response data: ${JSON.stringify((_b2 = error.response) == null ? void 0 : _b2.data)}`));
|
|
9346
9488
|
} else {
|
|
9347
|
-
console.log(
|
|
9489
|
+
console.log(import_chalk25.default.red("No Response"));
|
|
9348
9490
|
}
|
|
9349
9491
|
throw error;
|
|
9350
9492
|
});
|
|
9351
9493
|
const data = response.data;
|
|
9352
9494
|
if (data.code === 200) {
|
|
9353
|
-
console.log(
|
|
9354
|
-
console.log(
|
|
9495
|
+
console.log(import_chalk25.default.green("\n\u2705 Project deleted successfully!"));
|
|
9496
|
+
console.log(import_chalk25.default.gray(`
|
|
9355
9497
|
Project: ${data.data.project_name}`));
|
|
9356
|
-
console.log(
|
|
9357
|
-
console.log(
|
|
9358
|
-
console.log(
|
|
9359
|
-
console.log(
|
|
9498
|
+
console.log(import_chalk25.default.gray(` Domain deleted: ${data.data.domain_deleted ? "\u2705" : "\u274C"}`));
|
|
9499
|
+
console.log(import_chalk25.default.gray(` Worker deleted: ${data.data.worker_deleted ? "\u2705" : "\u274C"}`));
|
|
9500
|
+
console.log(import_chalk25.default.gray(` Database deleted: ${data.data.database_deleted ? "\u2705" : "\u274C"}`));
|
|
9501
|
+
console.log(import_chalk25.default.gray("\nLocal files are kept unchanged."));
|
|
9360
9502
|
} else {
|
|
9361
9503
|
const errorMsg = (data == null ? void 0 : data.msg) || "Failed to delete project";
|
|
9362
9504
|
throw new Error(errorMsg);
|
|
9363
9505
|
}
|
|
9364
9506
|
process.exit(0);
|
|
9365
9507
|
} catch (error) {
|
|
9366
|
-
console.log(
|
|
9508
|
+
console.log(import_chalk25.default.red(error));
|
|
9367
9509
|
const errorMsg = ((_b = (_a2 = error.response) == null ? void 0 : _a2.data) == null ? void 0 : _b.msg) || error.message || "Failed to delete project";
|
|
9368
|
-
console.error(
|
|
9510
|
+
console.error(import_chalk25.default.red(`
|
|
9369
9511
|
\u274C Error: ${errorMsg}`));
|
|
9370
9512
|
process.exit(1);
|
|
9371
9513
|
}
|
|
@@ -9376,9 +9518,9 @@ import_dotenv.default.config();
|
|
|
9376
9518
|
checkNodeVersion();
|
|
9377
9519
|
function showBanner() {
|
|
9378
9520
|
console.log(
|
|
9379
|
-
|
|
9521
|
+
import_chalk26.default.cyan(import_figlet5.default.textSync("Pinme", { horizontalLayout: "full" }))
|
|
9380
9522
|
);
|
|
9381
|
-
console.log(
|
|
9523
|
+
console.log(import_chalk26.default.cyan("A command-line tool for uploading files to IPFS\n"));
|
|
9382
9524
|
}
|
|
9383
9525
|
var program = new import_commander.Command();
|
|
9384
9526
|
program.name("pinme").version(version).option("-v, --version", "output the current version");
|