pinme 1.2.6 → 2.0.0-beta.2

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 CHANGED
@@ -96,10 +96,10 @@ var require_package = __commonJS({
96
96
  // node_modules/.pnpm/dotenv@16.5.0/node_modules/dotenv/lib/main.js
97
97
  var require_main = __commonJS({
98
98
  "node_modules/.pnpm/dotenv@16.5.0/node_modules/dotenv/lib/main.js"(exports2, module2) {
99
- var fs9 = require("fs");
100
- var path10 = require("path");
101
- var os4 = require("os");
102
- var crypto2 = require("crypto");
99
+ var fs15 = require("fs");
100
+ var path16 = require("path");
101
+ var os5 = require("os");
102
+ var crypto3 = require("crypto");
103
103
  var packageJson = require_package();
104
104
  var version2 = packageJson.version;
105
105
  var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
@@ -200,7 +200,7 @@ var require_main = __commonJS({
200
200
  if (options && options.path && options.path.length > 0) {
201
201
  if (Array.isArray(options.path)) {
202
202
  for (const filepath of options.path) {
203
- if (fs9.existsSync(filepath)) {
203
+ if (fs15.existsSync(filepath)) {
204
204
  possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
205
205
  }
206
206
  }
@@ -208,15 +208,15 @@ var require_main = __commonJS({
208
208
  possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
209
209
  }
210
210
  } else {
211
- possibleVaultPath = path10.resolve(process.cwd(), ".env.vault");
211
+ possibleVaultPath = path16.resolve(process.cwd(), ".env.vault");
212
212
  }
213
- if (fs9.existsSync(possibleVaultPath)) {
213
+ if (fs15.existsSync(possibleVaultPath)) {
214
214
  return possibleVaultPath;
215
215
  }
216
216
  return null;
217
217
  }
218
218
  function _resolveHome(envPath) {
219
- return envPath[0] === "~" ? path10.join(os4.homedir(), envPath.slice(1)) : envPath;
219
+ return envPath[0] === "~" ? path16.join(os5.homedir(), envPath.slice(1)) : envPath;
220
220
  }
221
221
  function _configVault(options) {
222
222
  const debug = Boolean(options && options.debug);
@@ -232,7 +232,7 @@ var require_main = __commonJS({
232
232
  return { parsed };
233
233
  }
234
234
  function configDotenv(options) {
235
- const dotenvPath = path10.resolve(process.cwd(), ".env");
235
+ const dotenvPath = path16.resolve(process.cwd(), ".env");
236
236
  let encoding = "utf8";
237
237
  const debug = Boolean(options && options.debug);
238
238
  if (options && options.encoding) {
@@ -255,13 +255,13 @@ var require_main = __commonJS({
255
255
  }
256
256
  let lastError;
257
257
  const parsedAll = {};
258
- for (const path11 of optionPaths) {
258
+ for (const path17 of optionPaths) {
259
259
  try {
260
- const parsed = DotenvModule.parse(fs9.readFileSync(path11, { encoding }));
260
+ const parsed = DotenvModule.parse(fs15.readFileSync(path17, { encoding }));
261
261
  DotenvModule.populate(parsedAll, parsed, options);
262
262
  } catch (e) {
263
263
  if (debug) {
264
- _debug(`Failed to load ${path11} ${e.message}`);
264
+ _debug(`Failed to load ${path17} ${e.message}`);
265
265
  }
266
266
  lastError = e;
267
267
  }
@@ -295,7 +295,7 @@ var require_main = __commonJS({
295
295
  const authTag = ciphertext.subarray(-16);
296
296
  ciphertext = ciphertext.subarray(12, -16);
297
297
  try {
298
- const aesgcm = crypto2.createDecipheriv("aes-256-gcm", key, nonce);
298
+ const aesgcm = crypto3.createDecipheriv("aes-256-gcm", key, nonce);
299
299
  aesgcm.setAuthTag(authTag);
300
300
  return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
301
301
  } catch (error) {
@@ -810,7 +810,7 @@ var require_has_flag = __commonJS({
810
810
  var require_supports_color = __commonJS({
811
811
  "node_modules/.pnpm/supports-color@5.5.0/node_modules/supports-color/index.js"(exports2, module2) {
812
812
  "use strict";
813
- var os4 = require("os");
813
+ var os5 = require("os");
814
814
  var hasFlag = require_has_flag();
815
815
  var env = process.env;
816
816
  var forceColor;
@@ -848,7 +848,7 @@ var require_supports_color = __commonJS({
848
848
  }
849
849
  const min = forceColor ? 1 : 0;
850
850
  if (process.platform === "win32") {
851
- const osRelease = os4.release().split(".");
851
+ const osRelease = os5.release().split(".");
852
852
  if (Number(process.versions.node.split(".")[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
853
853
  return Number(osRelease[2]) >= 14931 ? 3 : 2;
854
854
  }
@@ -1033,8 +1033,8 @@ var require_debug = __commonJS({
1033
1033
  var require_follow_redirects = __commonJS({
1034
1034
  "node_modules/.pnpm/follow-redirects@1.15.2/node_modules/follow-redirects/index.js"(exports2, module2) {
1035
1035
  var url2 = require("url");
1036
- var URL4 = url2.URL;
1037
- var http2 = require("http");
1036
+ var URL5 = url2.URL;
1037
+ var http3 = require("http");
1038
1038
  var https2 = require("https");
1039
1039
  var Writable = require("stream").Writable;
1040
1040
  var assert = require("assert");
@@ -1367,7 +1367,7 @@ var require_follow_redirects = __commonJS({
1367
1367
  if (isString2(input)) {
1368
1368
  var parsed;
1369
1369
  try {
1370
- parsed = urlToOptions(new URL4(input));
1370
+ parsed = urlToOptions(new URL5(input));
1371
1371
  } catch (err) {
1372
1372
  parsed = url2.parse(input);
1373
1373
  }
@@ -1375,7 +1375,7 @@ var require_follow_redirects = __commonJS({
1375
1375
  throw new InvalidUrlError({ input });
1376
1376
  }
1377
1377
  input = parsed;
1378
- } else if (URL4 && input instanceof URL4) {
1378
+ } else if (URL5 && input instanceof URL5) {
1379
1379
  input = urlToOptions(input);
1380
1380
  } else {
1381
1381
  callback = options;
@@ -1473,7 +1473,7 @@ var require_follow_redirects = __commonJS({
1473
1473
  function isBuffer2(value) {
1474
1474
  return typeof value === "object" && "length" in value;
1475
1475
  }
1476
- module2.exports = wrap({ http: http2, https: https2 });
1476
+ module2.exports = wrap({ http: http3, https: https2 });
1477
1477
  module2.exports.wrap = wrap;
1478
1478
  }
1479
1479
  });
@@ -1519,15 +1519,15 @@ function checkNodeVersion() {
1519
1519
 
1520
1520
  // bin/index.ts
1521
1521
  var import_commander = require("commander");
1522
- var import_chalk14 = __toESM(require("chalk"));
1522
+ var import_chalk21 = __toESM(require("chalk"));
1523
1523
  var import_figlet5 = __toESM(require("figlet"));
1524
1524
 
1525
1525
  // package.json
1526
- var version = "1.2.6";
1526
+ var version = "2.0.0-beta.2";
1527
1527
 
1528
1528
  // bin/upload.ts
1529
- var import_path6 = __toESM(require("path"));
1530
- var import_chalk4 = __toESM(require("chalk"));
1529
+ var import_path7 = __toESM(require("path"));
1530
+ var import_chalk5 = __toESM(require("chalk"));
1531
1531
  var import_inquirer = __toESM(require("inquirer"));
1532
1532
  var import_figlet = __toESM(require("figlet"));
1533
1533
 
@@ -1968,9 +1968,9 @@ function isVisitable(thing) {
1968
1968
  function removeBrackets(key) {
1969
1969
  return utils_default.endsWith(key, "[]") ? key.slice(0, -2) : key;
1970
1970
  }
1971
- function renderKey(path10, key, dots) {
1972
- if (!path10) return key;
1973
- return path10.concat(key).map(function each(token, i) {
1971
+ function renderKey(path16, key, dots) {
1972
+ if (!path16) return key;
1973
+ return path16.concat(key).map(function each(token, i) {
1974
1974
  token = removeBrackets(token);
1975
1975
  return !dots && i ? "[" + token + "]" : token;
1976
1976
  }).join(dots ? "." : "");
@@ -2015,9 +2015,9 @@ function toFormData(obj, formData, options) {
2015
2015
  }
2016
2016
  return value;
2017
2017
  }
2018
- function defaultVisitor(value, key, path10) {
2018
+ function defaultVisitor(value, key, path16) {
2019
2019
  let arr = value;
2020
- if (value && !path10 && typeof value === "object") {
2020
+ if (value && !path16 && typeof value === "object") {
2021
2021
  if (utils_default.endsWith(key, "{}")) {
2022
2022
  key = metaTokens ? key : key.slice(0, -2);
2023
2023
  value = JSON.stringify(value);
@@ -2036,7 +2036,7 @@ function toFormData(obj, formData, options) {
2036
2036
  if (isVisitable(value)) {
2037
2037
  return true;
2038
2038
  }
2039
- formData.append(renderKey(path10, key, dots), convertValue(value));
2039
+ formData.append(renderKey(path16, key, dots), convertValue(value));
2040
2040
  return false;
2041
2041
  }
2042
2042
  const stack = [];
@@ -2045,10 +2045,10 @@ function toFormData(obj, formData, options) {
2045
2045
  convertValue,
2046
2046
  isVisitable
2047
2047
  });
2048
- function build(value, path10) {
2048
+ function build(value, path16) {
2049
2049
  if (utils_default.isUndefined(value)) return;
2050
2050
  if (stack.indexOf(value) !== -1) {
2051
- throw Error("Circular reference detected in " + path10.join("."));
2051
+ throw Error("Circular reference detected in " + path16.join("."));
2052
2052
  }
2053
2053
  stack.push(value);
2054
2054
  utils_default.forEach(value, function each(el, key) {
@@ -2056,11 +2056,11 @@ function toFormData(obj, formData, options) {
2056
2056
  formData,
2057
2057
  el,
2058
2058
  utils_default.isString(key) ? key.trim() : key,
2059
- path10,
2059
+ path16,
2060
2060
  exposedHelpers
2061
2061
  );
2062
2062
  if (result === true) {
2063
- build(el, path10 ? path10.concat(key) : [key]);
2063
+ build(el, path16 ? path16.concat(key) : [key]);
2064
2064
  }
2065
2065
  });
2066
2066
  stack.pop();
@@ -2221,7 +2221,7 @@ var node_default = {
2221
2221
  // node_modules/.pnpm/axios@1.3.2/node_modules/axios/lib/helpers/toURLEncodedForm.js
2222
2222
  function toURLEncodedForm(data, options) {
2223
2223
  return toFormData_default(data, new node_default.classes.URLSearchParams(), Object.assign({
2224
- visitor: function(value, key, path10, helpers) {
2224
+ visitor: function(value, key, path16, helpers) {
2225
2225
  if (node_default.isNode && utils_default.isBuffer(value)) {
2226
2226
  this.append(key, value.toString("base64"));
2227
2227
  return false;
@@ -2250,10 +2250,10 @@ function arrayToObject(arr) {
2250
2250
  return obj;
2251
2251
  }
2252
2252
  function formDataToJSON(formData) {
2253
- function buildPath(path10, value, target, index) {
2254
- let name = path10[index++];
2253
+ function buildPath(path16, value, target, index) {
2254
+ let name = path16[index++];
2255
2255
  const isNumericKey = Number.isFinite(+name);
2256
- const isLast = index >= path10.length;
2256
+ const isLast = index >= path16.length;
2257
2257
  name = !name && utils_default.isArray(target) ? target.length : name;
2258
2258
  if (isLast) {
2259
2259
  if (utils_default.hasOwnProp(target, name)) {
@@ -2266,7 +2266,7 @@ function formDataToJSON(formData) {
2266
2266
  if (!target[name] || !utils_default.isObject(target[name])) {
2267
2267
  target[name] = [];
2268
2268
  }
2269
- const result = buildPath(path10, value, target[name], index);
2269
+ const result = buildPath(path16, value, target[name], index);
2270
2270
  if (result && utils_default.isArray(target[name])) {
2271
2271
  target[name] = arrayToObject(target[name]);
2272
2272
  }
@@ -3328,9 +3328,9 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
3328
3328
  auth = urlUsername + ":" + urlPassword;
3329
3329
  }
3330
3330
  auth && headers.delete("authorization");
3331
- let path10;
3331
+ let path16;
3332
3332
  try {
3333
- path10 = buildURL(
3333
+ path16 = buildURL(
3334
3334
  parsed.pathname + parsed.search,
3335
3335
  config.params,
3336
3336
  config.paramsSerializer
@@ -3348,7 +3348,7 @@ var http_default = isHttpAdapterSupported && function httpAdapter(config) {
3348
3348
  false
3349
3349
  );
3350
3350
  const options = {
3351
- path: path10,
3351
+ path: path16,
3352
3352
  method,
3353
3353
  headers: headers.toJSON(),
3354
3354
  agents: { http: config.httpAgent, https: config.httpsAgent },
@@ -3567,14 +3567,14 @@ var cookies_default = node_default.isStandardBrowserEnv ? (
3567
3567
  // Standard browser envs support document.cookie
3568
3568
  /* @__PURE__ */ function standardBrowserEnv() {
3569
3569
  return {
3570
- write: function write(name, value, expires, path10, domain, secure) {
3570
+ write: function write(name, value, expires, path16, domain, secure) {
3571
3571
  const cookie = [];
3572
3572
  cookie.push(name + "=" + encodeURIComponent(value));
3573
3573
  if (utils_default.isNumber(expires)) {
3574
3574
  cookie.push("expires=" + new Date(expires).toGMTString());
3575
3575
  }
3576
- if (utils_default.isString(path10)) {
3577
- cookie.push("path=" + path10);
3576
+ if (utils_default.isString(path16)) {
3577
+ cookie.push("path=" + path16);
3578
3578
  }
3579
3579
  if (utils_default.isString(domain)) {
3580
3580
  cookie.push("domain=" + domain);
@@ -4551,38 +4551,6 @@ var import_os2 = __toESM(require("os"));
4551
4551
  var import_path3 = __toESM(require("path"));
4552
4552
  var CONFIG_DIR = import_path3.default.join(import_os2.default.homedir(), ".pinme");
4553
4553
  var AUTH_FILE = import_path3.default.join(CONFIG_DIR, "auth.json");
4554
- function ensureConfigDir() {
4555
- if (!import_fs_extra2.default.existsSync(CONFIG_DIR)) {
4556
- import_fs_extra2.default.mkdirSync(CONFIG_DIR, { recursive: true });
4557
- }
4558
- }
4559
- function parseCombinedToken(combined) {
4560
- const firstDash = combined.indexOf("-");
4561
- if (firstDash <= 0 || firstDash === combined.length - 1) {
4562
- throw new Error('Invalid token format. Expected "<address>-<jwt>".');
4563
- }
4564
- const address = combined.slice(0, firstDash).trim();
4565
- const token = combined.slice(firstDash + 1).trim();
4566
- if (!address || !token) {
4567
- throw new Error("Invalid token content. Address or token is empty.");
4568
- }
4569
- return { address, token };
4570
- }
4571
- function setAuthToken(combined) {
4572
- ensureConfigDir();
4573
- const auth = parseCombinedToken(combined);
4574
- import_fs_extra2.default.writeJsonSync(AUTH_FILE, auth, { spaces: 2 });
4575
- return auth;
4576
- }
4577
- function clearAuthToken() {
4578
- try {
4579
- if (import_fs_extra2.default.existsSync(AUTH_FILE)) {
4580
- import_fs_extra2.default.removeSync(AUTH_FILE);
4581
- }
4582
- } catch (error) {
4583
- console.error(`Failed to clear auth token: ${error}`);
4584
- }
4585
- }
4586
4554
  function getAuthConfig() {
4587
4555
  try {
4588
4556
  if (!import_fs_extra2.default.existsSync(AUTH_FILE)) return null;
@@ -4593,16 +4561,6 @@ function getAuthConfig() {
4593
4561
  return null;
4594
4562
  }
4595
4563
  }
4596
- function getAuthHeaders() {
4597
- const conf = getAuthConfig();
4598
- if (!conf) {
4599
- throw new Error("Auth not set. Run: pinme set-appkey <AppKey>");
4600
- }
4601
- return {
4602
- "token-address": conf.address,
4603
- "authentication-tokens": conf.token
4604
- };
4605
- }
4606
4564
 
4607
4565
  // bin/utils/getDeviceId.ts
4608
4566
  function getDeviceId() {
@@ -5147,7 +5105,329 @@ var import_fs2 = __toESM(require("fs"));
5147
5105
  var import_crypto_js = __toESM(require("crypto-js"));
5148
5106
 
5149
5107
  // bin/utils/pinmeApi.ts
5108
+ var import_chalk4 = __toESM(require("chalk"));
5109
+
5110
+ // bin/utils/webLogin.ts
5111
+ var import_crypto = __toESM(require("crypto"));
5112
+ var import_http3 = __toESM(require("http"));
5113
+ var import_url2 = require("url");
5150
5114
  var import_chalk3 = __toESM(require("chalk"));
5115
+ var import_child_process = require("child_process");
5116
+ var import_fs_extra5 = __toESM(require("fs-extra"));
5117
+ var import_os4 = __toESM(require("os"));
5118
+ var import_path6 = __toESM(require("path"));
5119
+ function openBrowser(url2) {
5120
+ const platform = process.platform;
5121
+ let command;
5122
+ if (platform === "darwin") {
5123
+ command = `open "${url2}"`;
5124
+ } else if (platform === "win32") {
5125
+ command = `start "" "${url2}"`;
5126
+ } else {
5127
+ command = `xdg-open "${url2}"`;
5128
+ }
5129
+ (0, import_child_process.exec)(command, (err) => {
5130
+ if (err) {
5131
+ console.log(import_chalk3.default.yellow(`Unable to open browser automatically. Please visit manually: ${url2}`));
5132
+ }
5133
+ });
5134
+ }
5135
+ var CONFIG_DIR2 = import_path6.default.join(import_os4.default.homedir(), ".pinme");
5136
+ var AUTH_FILE2 = import_path6.default.join(CONFIG_DIR2, "auth.json");
5137
+ var DEFAULT_OPTIONS = {
5138
+ apiBaseUrl: "https://pinme.dev/api/v4",
5139
+ webBaseUrl: process.env.PINME_WEB_URL || "http://localhost:5173",
5140
+ callbackPort: 3e3,
5141
+ callbackPath: "/cli/callback"
5142
+ };
5143
+ var WebLoginManager = class {
5144
+ config;
5145
+ server = null;
5146
+ resolvePromise = null;
5147
+ rejectPromise = null;
5148
+ loginToken = "";
5149
+ constructor(options = {}) {
5150
+ this.config = { ...DEFAULT_OPTIONS, ...options };
5151
+ }
5152
+ async login() {
5153
+ console.log(import_chalk3.default.blue("Starting login flow...\n"));
5154
+ this.loginToken = this.generateLoginToken();
5155
+ console.log(import_chalk3.default.blue("Starting local callback server..."));
5156
+ await this.startCallbackServer();
5157
+ try {
5158
+ const loginUrl = this.buildLoginUrl();
5159
+ console.log(import_chalk3.default.blue("Opening browser..."));
5160
+ console.log(import_chalk3.default.white("If browser does not open automatically, please visit manually:"));
5161
+ console.log(import_chalk3.default.cyan(` ${loginUrl}
5162
+ `));
5163
+ openBrowser(loginUrl);
5164
+ console.log(import_chalk3.default.yellow("Please complete login in browser..."));
5165
+ console.log(import_chalk3.default.gray("Browser will close automatically after successful login.\n"));
5166
+ const authToken = await this.waitForCallback();
5167
+ const authConfig = this.parseAuthToken(authToken);
5168
+ this.saveAuthConfig(authConfig);
5169
+ console.log(import_chalk3.default.green("\nLogin successful!"));
5170
+ if (authConfig.email) {
5171
+ console.log(import_chalk3.default.green(`Welcome, ${authConfig.email}`));
5172
+ }
5173
+ console.log(import_chalk3.default.gray(`Address: ${authConfig.address}`));
5174
+ return authConfig;
5175
+ } catch (error) {
5176
+ console.error(import_chalk3.default.red(`
5177
+ Login failed: ${error.message}`));
5178
+ throw error;
5179
+ } finally {
5180
+ this.closeServer();
5181
+ }
5182
+ }
5183
+ generateLoginToken() {
5184
+ return import_crypto.default.randomBytes(32).toString("hex");
5185
+ }
5186
+ async startCallbackServer() {
5187
+ return new Promise((resolve, reject) => {
5188
+ this.server = import_http3.default.createServer(async (req, res) => {
5189
+ try {
5190
+ const url2 = new import_url2.URL(req.url || "", `http://localhost:${this.config.callbackPort}`);
5191
+ if (url2.pathname === this.config.callbackPath) {
5192
+ const authToken = url2.searchParams.get("token");
5193
+ const error = url2.searchParams.get("error");
5194
+ const loginToken = url2.searchParams.get("login_token");
5195
+ if (error) {
5196
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
5197
+ res.end(this.getErrorHtml(error));
5198
+ if (this.rejectPromise) {
5199
+ this.rejectPromise(new Error(error));
5200
+ }
5201
+ return;
5202
+ }
5203
+ if (!authToken) {
5204
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
5205
+ res.end(this.getErrorHtml("Auth token not received"));
5206
+ if (this.rejectPromise) {
5207
+ this.rejectPromise(new Error("Auth token not received"));
5208
+ }
5209
+ return;
5210
+ }
5211
+ if (loginToken !== this.loginToken) {
5212
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
5213
+ res.end(this.getErrorHtml("Login token invalid or expired"));
5214
+ if (this.rejectPromise) {
5215
+ this.rejectPromise(new Error("Login token invalid or expired"));
5216
+ }
5217
+ return;
5218
+ }
5219
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
5220
+ res.end(this.getSuccessHtml());
5221
+ if (this.resolvePromise) {
5222
+ this.resolvePromise(authToken);
5223
+ }
5224
+ } else {
5225
+ res.writeHead(404, { "Content-Type": "text/plain" });
5226
+ res.end("Not Found");
5227
+ }
5228
+ } catch (err) {
5229
+ console.error("Callback error:", err);
5230
+ res.writeHead(500, { "Content-Type": "text/plain" });
5231
+ res.end("Internal Server Error");
5232
+ }
5233
+ });
5234
+ this.server.on("error", (err) => {
5235
+ reject(err);
5236
+ });
5237
+ this.server.listen(this.config.callbackPort, "127.0.0.1", () => {
5238
+ console.log(import_chalk3.default.gray(`Local server: http://localhost:${this.config.callbackPort}`));
5239
+ resolve();
5240
+ });
5241
+ setTimeout(() => {
5242
+ if (this.rejectPromise) {
5243
+ this.rejectPromise(new Error("Login timeout, please try again"));
5244
+ }
5245
+ this.closeServer();
5246
+ }, 10 * 60 * 1e3);
5247
+ });
5248
+ }
5249
+ buildLoginUrl() {
5250
+ const callbackUrl = `http://localhost:${this.config.callbackPort}${this.config.callbackPath}`;
5251
+ const url2 = `${this.config.webBaseUrl}/#/cli-login?login_token=${this.loginToken}&callback_url=${encodeURIComponent(callbackUrl)}`;
5252
+ return url2;
5253
+ }
5254
+ waitForCallback() {
5255
+ return new Promise((resolve, reject) => {
5256
+ this.resolvePromise = resolve;
5257
+ this.rejectPromise = reject;
5258
+ });
5259
+ }
5260
+ parseAuthToken(authToken) {
5261
+ const firstDash = authToken.indexOf("-");
5262
+ if (firstDash <= 0 || firstDash === authToken.length - 1) {
5263
+ throw new Error("Invalid token format");
5264
+ }
5265
+ const address = authToken.slice(0, firstDash).trim();
5266
+ const token = authToken.slice(firstDash + 1).trim();
5267
+ if (!address || !token) {
5268
+ throw new Error("Token parsing failed: address or token is empty");
5269
+ }
5270
+ return { address, token };
5271
+ }
5272
+ saveAuthConfig(config) {
5273
+ import_fs_extra5.default.ensureDirSync(CONFIG_DIR2);
5274
+ import_fs_extra5.default.writeJsonSync(AUTH_FILE2, config, { spaces: 2 });
5275
+ import_fs_extra5.default.chmodSync(AUTH_FILE2, 384);
5276
+ }
5277
+ closeServer() {
5278
+ if (this.server) {
5279
+ this.server.close();
5280
+ this.server = null;
5281
+ }
5282
+ }
5283
+ // HTML templates
5284
+ getSuccessHtml() {
5285
+ return `
5286
+ <!DOCTYPE html>
5287
+ <html>
5288
+ <head>
5289
+ <title>Login Success - PinMe</title>
5290
+ <style>
5291
+ body {
5292
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
5293
+ display: flex;
5294
+ justify-content: center;
5295
+ align-items: center;
5296
+ height: 100vh;
5297
+ margin: 0;
5298
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
5299
+ }
5300
+ .container {
5301
+ background: white;
5302
+ padding: 3rem;
5303
+ border-radius: 12px;
5304
+ box-shadow: 0 20px 60px rgba(0,0,0,0.3);
5305
+ text-align: center;
5306
+ max-width: 400px;
5307
+ }
5308
+ .success-icon {
5309
+ font-size: 4rem;
5310
+ margin-bottom: 1rem;
5311
+ }
5312
+ h1 {
5313
+ color: #1f2937;
5314
+ margin: 0 0 1rem 0;
5315
+ }
5316
+ p {
5317
+ color: #6b7280;
5318
+ margin: 0 0 2rem 0;
5319
+ }
5320
+ .close-btn {
5321
+ background: #3b82f6;
5322
+ color: white;
5323
+ border: none;
5324
+ padding: 0.75rem 2rem;
5325
+ border-radius: 6px;
5326
+ font-size: 1rem;
5327
+ cursor: pointer;
5328
+ transition: background 0.2s;
5329
+ }
5330
+ .close-btn:hover {
5331
+ background: #2563eb;
5332
+ }
5333
+ </style>
5334
+ </head>
5335
+ <body>
5336
+ <div class="container">
5337
+ <div class="success-icon">\u2705</div>
5338
+ <h1>Login Successful!</h1>
5339
+ <p>You have successfully logged in to PinMe CLI.</p>
5340
+ <p>You can close this window and return to the command line.</p>
5341
+ <button id="closeBtn" class="close-btn">Close Window</button>
5342
+ <p id="message" style="color: #6b7280; margin-top: 1rem;"></p>
5343
+ </div>
5344
+ <script>
5345
+ // For redirected pages, show message instead of auto-close
5346
+ document.addEventListener('DOMContentLoaded', function() {
5347
+ document.getElementById('closeBtn').addEventListener('click', function() {
5348
+ // Try to close, fallback to showing message
5349
+ try {
5350
+ window.close();
5351
+ } catch (e) {
5352
+ document.getElementById('message').textContent = 'You can close this window manually.';
5353
+ }
5354
+ });
5355
+ });
5356
+ </script>
5357
+ </body>
5358
+ </html>`;
5359
+ }
5360
+ getErrorHtml(error) {
5361
+ const encodedError = encodeURIComponent(error);
5362
+ return `
5363
+ <!DOCTYPE html>
5364
+ <html>
5365
+ <head>
5366
+ <title>Login Failed - PinMe</title>
5367
+ <style>
5368
+ body { font-family: sans-serif; padding: 2rem; text-align: center; background: #f3f4f6; }
5369
+ .container { background: white; padding: 2rem; border-radius: 12px; max-width: 400px; margin: 0 auto; }
5370
+ .error { color: #dc2626; font-size: 1.25rem; margin: 1rem 0; }
5371
+ button { padding: 0.5rem 1rem; cursor: pointer; background: #3b82f6; color: white; border: none; border-radius: 6px; }
5372
+ </style>
5373
+ </head>
5374
+ <body>
5375
+ <div class="container">
5376
+ <h2>Login Failed</h2>
5377
+ <div class="error">${error}</div>
5378
+ <button onclick="window.close()">Close</button>
5379
+ </div>
5380
+ </body>
5381
+ </html>`;
5382
+ }
5383
+ };
5384
+ var webLoginManager = new WebLoginManager();
5385
+ function setAuthToken(combined) {
5386
+ const firstDash = combined.indexOf("-");
5387
+ if (firstDash <= 0 || firstDash === combined.length - 1) {
5388
+ throw new Error('Invalid token format. Expected "<address>-<jwt>".');
5389
+ }
5390
+ const address = combined.slice(0, firstDash).trim();
5391
+ const token = combined.slice(firstDash + 1).trim();
5392
+ if (!address || !token) {
5393
+ throw new Error("Invalid token content. Address or token is empty.");
5394
+ }
5395
+ const config = { address, token };
5396
+ import_fs_extra5.default.ensureDirSync(CONFIG_DIR2);
5397
+ import_fs_extra5.default.writeJsonSync(AUTH_FILE2, config, { spaces: 2 });
5398
+ return config;
5399
+ }
5400
+ function getAuthConfig2() {
5401
+ try {
5402
+ if (!import_fs_extra5.default.existsSync(AUTH_FILE2)) return null;
5403
+ const data = import_fs_extra5.default.readJsonSync(AUTH_FILE2);
5404
+ if (!(data == null ? void 0 : data.address) || !(data == null ? void 0 : data.token)) return null;
5405
+ return data;
5406
+ } catch {
5407
+ return null;
5408
+ }
5409
+ }
5410
+ function clearAuthToken() {
5411
+ try {
5412
+ if (import_fs_extra5.default.existsSync(AUTH_FILE2)) {
5413
+ import_fs_extra5.default.removeSync(AUTH_FILE2);
5414
+ }
5415
+ } catch (error) {
5416
+ console.error(`Failed to clear auth token: ${error}`);
5417
+ }
5418
+ }
5419
+ function getAuthHeaders() {
5420
+ const conf = getAuthConfig2();
5421
+ if (!conf) {
5422
+ throw new Error("Auth not set. Run: pinme login");
5423
+ }
5424
+ return {
5425
+ "token-address": conf.address,
5426
+ "authentication-tokens": conf.token
5427
+ };
5428
+ }
5429
+
5430
+ // bin/utils/pinmeApi.ts
5151
5431
  var DEFAULT_BASE = "https://pinme.dev/api/v4";
5152
5432
  var TOKEN_EXPIRED_CODES = [
5153
5433
  401,
@@ -5186,8 +5466,8 @@ function isTokenExpired(error) {
5186
5466
  );
5187
5467
  }
5188
5468
  function showTokenExpiredHint() {
5189
- console.log(import_chalk3.default.red("\n\u26A0\uFE0F Token has expired or is invalid."));
5190
- console.log(import_chalk3.default.yellow("Please re-run: pinme set-appkey <AppKey>\n"));
5469
+ console.log(import_chalk4.default.red("\n\u26A0\uFE0F Token has expired or is invalid."));
5470
+ console.log(import_chalk4.default.yellow("Please re-run: pinme set-appkey <AppKey>\n"));
5191
5471
  }
5192
5472
  function createClient() {
5193
5473
  const headers = getAuthHeaders();
@@ -5216,7 +5496,7 @@ async function bindAnonymousDevice(anonymousUid) {
5216
5496
  return false;
5217
5497
  }
5218
5498
  console.log(
5219
- import_chalk3.default.yellow(`Failed to trigger anonymous binding: ${(e == null ? void 0 : e.message) || e}`)
5499
+ import_chalk4.default.yellow(`Failed to trigger anonymous binding: ${(e == null ? void 0 : e.message) || e}`)
5220
5500
  );
5221
5501
  return false;
5222
5502
  }
@@ -5402,7 +5682,7 @@ async function checkCarExportStatus(taskId) {
5402
5682
  }
5403
5683
 
5404
5684
  // bin/upload.ts
5405
- var URL2 = "https://pinme.eth.limo/#/preview/";
5685
+ var URL3 = "https://pinme.eth.limo/#/preview/";
5406
5686
  var secretKey = "pinme-secret-key";
5407
5687
  checkNodeVersion();
5408
5688
  function isDnsDomain(domain) {
@@ -5450,13 +5730,13 @@ function encryptHash(contentHash, key, uid) {
5450
5730
  }
5451
5731
  function checkPathSync(inputPath) {
5452
5732
  try {
5453
- const absolutePath = import_path6.default.resolve(inputPath);
5733
+ const absolutePath = import_path7.default.resolve(inputPath);
5454
5734
  if (import_fs2.default.existsSync(absolutePath)) {
5455
5735
  return absolutePath;
5456
5736
  }
5457
5737
  return null;
5458
5738
  } catch (error) {
5459
- console.error(import_chalk4.default.red(`error checking path: ${error.message}`));
5739
+ console.error(import_chalk5.default.red(`error checking path: ${error.message}`));
5460
5740
  return null;
5461
5741
  }
5462
5742
  }
@@ -5474,43 +5754,43 @@ function getDnsFromArgs() {
5474
5754
  }
5475
5755
  async function checkVipStatus(authConfig) {
5476
5756
  var _a;
5477
- console.log(import_chalk4.default.blue("Checking VIP status..."));
5757
+ console.log(import_chalk5.default.blue("Checking VIP status..."));
5478
5758
  try {
5479
5759
  const vipResult = await isVip(authConfig.address, authConfig.token);
5480
5760
  if (!((_a = vipResult.data) == null ? void 0 : _a.is_vip)) {
5481
5761
  return false;
5482
5762
  }
5483
- console.log(import_chalk4.default.green("VIP verified."));
5763
+ console.log(import_chalk5.default.green("VIP verified."));
5484
5764
  return true;
5485
5765
  } catch (e) {
5486
5766
  if (e.message === "Token expired") {
5487
5767
  throw e;
5488
5768
  }
5489
- console.log(import_chalk4.default.yellow("Failed to check VIP status, continuing..."));
5769
+ console.log(import_chalk5.default.yellow("Failed to check VIP status, continuing..."));
5490
5770
  return true;
5491
5771
  }
5492
5772
  }
5493
5773
  async function bindDomain(domain, contentHash, isDns, authConfig) {
5494
5774
  const displayDomain = domain.replace(/^https?:\/\//, "").replace(/\/$/, "");
5495
5775
  if (isDns) {
5496
- console.log(import_chalk4.default.blue("Binding DNS domain..."));
5776
+ console.log(import_chalk5.default.blue("Binding DNS domain..."));
5497
5777
  const dnsResult = await bindDnsDomainV4(displayDomain, contentHash, authConfig.address, authConfig.token);
5498
5778
  if (dnsResult.code !== 200) {
5499
- console.log(import_chalk4.default.red(`DNS binding failed: ${dnsResult.msg}`));
5779
+ console.log(import_chalk5.default.red(`DNS binding failed: ${dnsResult.msg}`));
5500
5780
  return false;
5501
5781
  }
5502
- console.log(import_chalk4.default.green(`DNS bind success: ${displayDomain}`));
5503
- console.log(import_chalk4.default.white(`Visit: https://${displayDomain}`));
5504
- console.log(import_chalk4.default.cyan("\n\u{1F4DA} DNS Setup Guide: https://pinme.eth.limo/#/docs?id=custom-domain"));
5782
+ console.log(import_chalk5.default.green(`DNS bind success: ${displayDomain}`));
5783
+ console.log(import_chalk5.default.white(`Visit: https://${displayDomain}`));
5784
+ console.log(import_chalk5.default.cyan("\n\u{1F4DA} DNS Setup Guide: https://pinme.eth.limo/#/docs?id=custom-domain"));
5505
5785
  } else {
5506
- console.log(import_chalk4.default.blue("Binding Pinme subdomain..."));
5786
+ console.log(import_chalk5.default.blue("Binding Pinme subdomain..."));
5507
5787
  const ok = await bindPinmeDomain(displayDomain, contentHash);
5508
5788
  if (!ok) {
5509
- console.log(import_chalk4.default.red("Binding failed. Please try again later."));
5789
+ console.log(import_chalk5.default.red("Binding failed. Please try again later."));
5510
5790
  return false;
5511
5791
  }
5512
- console.log(import_chalk4.default.green(`Bind success: ${displayDomain}`));
5513
- console.log(import_chalk4.default.white(`Visit: https://${displayDomain}.pinit.eth.limo`));
5792
+ console.log(import_chalk5.default.green(`Bind success: ${displayDomain}`));
5793
+ console.log(import_chalk5.default.white(`Visit: https://${displayDomain}.pinit.eth.limo`));
5514
5794
  }
5515
5795
  return true;
5516
5796
  }
@@ -5530,9 +5810,9 @@ var upload_default = async (options) => {
5530
5810
  const needsAuth = !!domainArg || dnsArg;
5531
5811
  let authConfig = null;
5532
5812
  if (needsAuth) {
5533
- authConfig = getAuthConfig();
5813
+ authConfig = getAuthConfig2();
5534
5814
  if (!authConfig) {
5535
- console.log(import_chalk4.default.red("Please login first. Run: pinme set-appkey <AppKey>"));
5815
+ console.log(import_chalk5.default.red("Please login first. Run: pinme set-appkey <AppKey>"));
5536
5816
  return;
5537
5817
  }
5538
5818
  }
@@ -5540,7 +5820,7 @@ var upload_default = async (options) => {
5540
5820
  if (argPath && !argPath.startsWith("-")) {
5541
5821
  const absolutePath = checkPathSync(argPath);
5542
5822
  if (!absolutePath) {
5543
- console.log(import_chalk4.default.red(`path ${argPath} does not exist`));
5823
+ console.log(import_chalk5.default.red(`path ${argPath} does not exist`));
5544
5824
  return;
5545
5825
  }
5546
5826
  const isDns = dnsArg || (domainArg ? isDnsDomain(domainArg) : false);
@@ -5548,7 +5828,7 @@ var upload_default = async (options) => {
5548
5828
  if (isDns && domainArg) {
5549
5829
  const validation = validateDnsDomain(domainArg);
5550
5830
  if (!validation.valid) {
5551
- console.log(import_chalk4.default.red(validation.message));
5831
+ console.log(import_chalk5.default.red(validation.message));
5552
5832
  return;
5553
5833
  }
5554
5834
  }
@@ -5556,7 +5836,7 @@ var upload_default = async (options) => {
5556
5836
  try {
5557
5837
  const isVipUser = await checkVipStatus(authConfig);
5558
5838
  if (!isVipUser) {
5559
- console.log(import_chalk4.default.red("Domain binding requires VIP. Please upgrade to VIP first."));
5839
+ console.log(import_chalk5.default.red("Domain binding requires VIP. Please upgrade to VIP first."));
5560
5840
  return;
5561
5841
  }
5562
5842
  } catch (e) {
@@ -5571,13 +5851,13 @@ var upload_default = async (options) => {
5571
5851
  const check = await checkDomainAvailable(displayDomain);
5572
5852
  if (!check.is_valid) {
5573
5853
  console.log(
5574
- import_chalk4.default.red(
5854
+ import_chalk5.default.red(
5575
5855
  `Domain not available: ${check.error || "unknown reason"}`
5576
5856
  )
5577
5857
  );
5578
5858
  return;
5579
5859
  }
5580
- console.log(import_chalk4.default.green(`Domain available: ${displayDomain}`));
5860
+ console.log(import_chalk5.default.green(`Domain available: ${displayDomain}`));
5581
5861
  } catch (e) {
5582
5862
  if (e.message === "Token expired") {
5583
5863
  return;
@@ -5585,22 +5865,22 @@ var upload_default = async (options) => {
5585
5865
  throw e;
5586
5866
  }
5587
5867
  }
5588
- console.log(import_chalk4.default.blue(`uploading ${absolutePath} to ipfs...`));
5868
+ console.log(import_chalk5.default.blue(`uploading ${absolutePath} to ipfs...`));
5589
5869
  try {
5590
5870
  const result = await uploadToIpfsSplit_default(absolutePath);
5591
5871
  if (result) {
5592
5872
  const uid = getUid();
5593
5873
  const encryptedCID = encryptHash(result.contentHash, secretKey, uid);
5594
5874
  console.log(
5595
- import_chalk4.default.cyan(
5875
+ import_chalk5.default.cyan(
5596
5876
  import_figlet.default.textSync("Successful", { horizontalLayout: "full" })
5597
5877
  )
5598
5878
  );
5599
- console.log(import_chalk4.default.cyan(`URL:`));
5600
- console.log(import_chalk4.default.cyan(`${URL2}${encryptedCID}`));
5879
+ console.log(import_chalk5.default.cyan(`URL:`));
5880
+ console.log(import_chalk5.default.cyan(`${URL3}${encryptedCID}`));
5601
5881
  if (domainArg) {
5602
5882
  console.log(
5603
- import_chalk4.default.blue(
5883
+ import_chalk5.default.blue(
5604
5884
  `Binding domain: ${displayDomain} with CID: ${result.contentHash}`
5605
5885
  )
5606
5886
  );
@@ -5608,15 +5888,16 @@ var upload_default = async (options) => {
5608
5888
  await bindDomain(domainArg, result.contentHash, isDns, authConfig);
5609
5889
  } catch (e) {
5610
5890
  if (e.message === "Token expired") {
5611
- return;
5891
+ process.exit(1);
5612
5892
  }
5613
5893
  throw e;
5614
5894
  }
5615
5895
  }
5616
- console.log(import_chalk4.default.green("\n\u{1F389} upload successful, program exit"));
5896
+ console.log(import_chalk5.default.green("\n\u{1F389} upload successful, program exit"));
5617
5897
  }
5618
5898
  } catch (error) {
5619
- console.error(import_chalk4.default.red(`Error: ${error.message}`));
5899
+ console.error(import_chalk5.default.red(`Error: ${error.message}`));
5900
+ process.exit(1);
5620
5901
  }
5621
5902
  process.exit(0);
5622
5903
  }
@@ -5630,7 +5911,7 @@ var upload_default = async (options) => {
5630
5911
  if (answer.path) {
5631
5912
  const absolutePath = checkPathSync(answer.path);
5632
5913
  if (!absolutePath) {
5633
- console.log(import_chalk4.default.red(`path ${answer.path} does not exist`));
5914
+ console.log(import_chalk5.default.red(`path ${answer.path} does not exist`));
5634
5915
  return;
5635
5916
  }
5636
5917
  const isDns = dnsArg || (domainArg ? isDnsDomain(domainArg) : false);
@@ -5638,7 +5919,7 @@ var upload_default = async (options) => {
5638
5919
  if (isDns && domainArg) {
5639
5920
  const validation = validateDnsDomain(domainArg);
5640
5921
  if (!validation.valid) {
5641
- console.log(import_chalk4.default.red(validation.message));
5922
+ console.log(import_chalk5.default.red(validation.message));
5642
5923
  return;
5643
5924
  }
5644
5925
  }
@@ -5646,7 +5927,7 @@ var upload_default = async (options) => {
5646
5927
  try {
5647
5928
  const isVipUser = await checkVipStatus(authConfig);
5648
5929
  if (!isVipUser) {
5649
- console.log(import_chalk4.default.red("Domain binding requires VIP. Please upgrade to VIP first."));
5930
+ console.log(import_chalk5.default.red("Domain binding requires VIP. Please upgrade to VIP first."));
5650
5931
  return;
5651
5932
  }
5652
5933
  } catch (e) {
@@ -5661,13 +5942,13 @@ var upload_default = async (options) => {
5661
5942
  const check = await checkDomainAvailable(displayDomain);
5662
5943
  if (!check.is_valid) {
5663
5944
  console.log(
5664
- import_chalk4.default.red(
5945
+ import_chalk5.default.red(
5665
5946
  `Domain not available: ${check.error || "unknown reason"}`
5666
5947
  )
5667
5948
  );
5668
5949
  return;
5669
5950
  }
5670
- console.log(import_chalk4.default.green(`Domain available: ${displayDomain}`));
5951
+ console.log(import_chalk5.default.green(`Domain available: ${displayDomain}`));
5671
5952
  } catch (e) {
5672
5953
  if (e.message === "Token expired") {
5673
5954
  return;
@@ -5675,22 +5956,22 @@ var upload_default = async (options) => {
5675
5956
  throw e;
5676
5957
  }
5677
5958
  }
5678
- console.log(import_chalk4.default.blue(`uploading ${absolutePath} to ipfs...`));
5959
+ console.log(import_chalk5.default.blue(`uploading ${absolutePath} to ipfs...`));
5679
5960
  try {
5680
5961
  const result = await uploadToIpfsSplit_default(absolutePath);
5681
5962
  if (result) {
5682
5963
  const uid = getUid();
5683
5964
  const encryptedCID = encryptHash(result.contentHash, secretKey, uid);
5684
5965
  console.log(
5685
- import_chalk4.default.cyan(
5966
+ import_chalk5.default.cyan(
5686
5967
  import_figlet.default.textSync("Successful", { horizontalLayout: "full" })
5687
5968
  )
5688
5969
  );
5689
- console.log(import_chalk4.default.cyan(`URL:`));
5690
- console.log(import_chalk4.default.cyan(`${URL2}${encryptedCID}`));
5970
+ console.log(import_chalk5.default.cyan(`URL:`));
5971
+ console.log(import_chalk5.default.cyan(`${URL3}${encryptedCID}`));
5691
5972
  if (domainArg) {
5692
5973
  console.log(
5693
- import_chalk4.default.blue(
5974
+ import_chalk5.default.blue(
5694
5975
  `Binding domain: ${displayDomain} with CID: ${result.contentHash}`
5695
5976
  )
5696
5977
  );
@@ -5698,32 +5979,33 @@ var upload_default = async (options) => {
5698
5979
  await bindDomain(domainArg, result.contentHash, isDns, authConfig);
5699
5980
  } catch (e) {
5700
5981
  if (e.message === "Token expired") {
5701
- return;
5982
+ process.exit(1);
5702
5983
  }
5703
5984
  throw e;
5704
5985
  }
5705
5986
  }
5706
- console.log(import_chalk4.default.green("\n\u{1F389} upload successful, program exit"));
5987
+ console.log(import_chalk5.default.green("\n\u{1F389} upload successful, program exit"));
5707
5988
  }
5708
5989
  } catch (error) {
5709
- console.error(import_chalk4.default.red(`Error: ${error.message}`));
5990
+ console.error(import_chalk5.default.red(`Error: ${error.message}`));
5991
+ process.exit(1);
5710
5992
  }
5711
5993
  process.exit(0);
5712
5994
  }
5713
5995
  } catch (error) {
5714
- console.error(import_chalk4.default.red(`error executing: ${error.message}`));
5996
+ console.error(import_chalk5.default.red(`error executing: ${error.message}`));
5715
5997
  console.error(error.stack);
5716
5998
  }
5717
5999
  };
5718
6000
 
5719
6001
  // bin/importCar.ts
5720
- var import_path7 = __toESM(require("path"));
5721
- var import_chalk5 = __toESM(require("chalk"));
6002
+ var import_path8 = __toESM(require("path"));
6003
+ var import_chalk6 = __toESM(require("chalk"));
5722
6004
  var import_inquirer2 = __toESM(require("inquirer"));
5723
6005
  var import_figlet2 = __toESM(require("figlet"));
5724
6006
  var import_fs3 = __toESM(require("fs"));
5725
6007
  var import_crypto_js2 = __toESM(require("crypto-js"));
5726
- var URL3 = "https://pinme.eth.limo/#/preview/";
6008
+ var URL4 = "https://pinme.eth.limo/#/preview/";
5727
6009
  var secretKey2 = "pinme-secret-key";
5728
6010
  checkNodeVersion();
5729
6011
  function encryptHash2(contentHash, key, uid) {
@@ -5742,13 +6024,13 @@ function encryptHash2(contentHash, key, uid) {
5742
6024
  }
5743
6025
  function checkPathSync2(inputPath) {
5744
6026
  try {
5745
- const absolutePath = import_path7.default.resolve(inputPath);
6027
+ const absolutePath = import_path8.default.resolve(inputPath);
5746
6028
  if (import_fs3.default.existsSync(absolutePath)) {
5747
6029
  return absolutePath;
5748
6030
  }
5749
6031
  return null;
5750
6032
  } catch (error) {
5751
- console.error(import_chalk5.default.red(`error checking path: ${error.message}`));
6033
+ console.error(import_chalk6.default.red(`error checking path: ${error.message}`));
5752
6034
  return null;
5753
6035
  }
5754
6036
  }
@@ -5761,7 +6043,7 @@ function getDomainFromArgs2() {
5761
6043
  return null;
5762
6044
  }
5763
6045
  function getUid2() {
5764
- const auth = getAuthConfig();
6046
+ const auth = getAuthConfig2();
5765
6047
  if (auth == null ? void 0 : auth.address) {
5766
6048
  return auth.address;
5767
6049
  }
@@ -5783,44 +6065,44 @@ var importCar_default = async (options) => {
5783
6065
  if (argPath && !argPath.startsWith("-")) {
5784
6066
  const absolutePath = checkPathSync2(argPath);
5785
6067
  if (!absolutePath) {
5786
- console.log(import_chalk5.default.red(`path ${argPath} does not exist`));
6068
+ console.log(import_chalk6.default.red(`path ${argPath} does not exist`));
5787
6069
  return;
5788
6070
  }
5789
6071
  if (domainArg) {
5790
6072
  const check = await checkDomainAvailable(domainArg);
5791
6073
  if (!check.is_valid) {
5792
- console.log(import_chalk5.default.red(`Domain not available: ${check.error || "unknown reason"}`));
6074
+ console.log(import_chalk6.default.red(`Domain not available: ${check.error || "unknown reason"}`));
5793
6075
  return;
5794
6076
  }
5795
- console.log(import_chalk5.default.green(`Domain available: ${domainArg}`));
6077
+ console.log(import_chalk6.default.green(`Domain available: ${domainArg}`));
5796
6078
  }
5797
- console.log(import_chalk5.default.blue(`importing ${absolutePath} to ipfs as CAR...`));
6079
+ console.log(import_chalk6.default.blue(`importing ${absolutePath} to ipfs as CAR...`));
5798
6080
  try {
5799
6081
  const result = await uploadToIpfsSplit_default(absolutePath, true);
5800
6082
  if (result) {
5801
6083
  const uid = getUid2();
5802
6084
  const encryptedCID = encryptHash2(result.contentHash, secretKey2, uid);
5803
6085
  console.log(
5804
- import_chalk5.default.cyan(
6086
+ import_chalk6.default.cyan(
5805
6087
  import_figlet2.default.textSync("Successful", { horizontalLayout: "full" })
5806
6088
  )
5807
6089
  );
5808
- console.log(import_chalk5.default.cyan(`URL:`));
5809
- console.log(import_chalk5.default.cyan(`${URL3}${encryptedCID}`));
6090
+ console.log(import_chalk6.default.cyan(`URL:`));
6091
+ console.log(import_chalk6.default.cyan(`${URL4}${encryptedCID}`));
5810
6092
  if (domainArg) {
5811
- console.log(import_chalk5.default.blue(`Binding domain: ${domainArg} with CID: ${result.contentHash}`));
6093
+ console.log(import_chalk6.default.blue(`Binding domain: ${domainArg} with CID: ${result.contentHash}`));
5812
6094
  const ok = await bindPinmeDomain(domainArg, result.contentHash);
5813
6095
  if (ok) {
5814
- console.log(import_chalk5.default.green(`Bind success: ${domainArg}`));
5815
- console.log(import_chalk5.default.white(`Visit (Pinme subdomain example): https://${domainArg}.pinit.eth.limo`));
6096
+ console.log(import_chalk6.default.green(`Bind success: ${domainArg}`));
6097
+ console.log(import_chalk6.default.white(`Visit (Pinme subdomain example): https://${domainArg}.pinit.eth.limo`));
5816
6098
  } else {
5817
- console.log(import_chalk5.default.red("Binding failed. Please try again later."));
6099
+ console.log(import_chalk6.default.red("Binding failed. Please try again later."));
5818
6100
  }
5819
6101
  }
5820
- console.log(import_chalk5.default.green("\n\u{1F389} import successful, program exit"));
6102
+ console.log(import_chalk6.default.green("\n\u{1F389} import successful, program exit"));
5821
6103
  }
5822
6104
  } catch (error) {
5823
- console.error(import_chalk5.default.red(`Error: ${error.message}`));
6105
+ console.error(import_chalk6.default.red(`Error: ${error.message}`));
5824
6106
  }
5825
6107
  process.exit(0);
5826
6108
  }
@@ -5834,56 +6116,56 @@ var importCar_default = async (options) => {
5834
6116
  if (answer.path) {
5835
6117
  const absolutePath = checkPathSync2(answer.path);
5836
6118
  if (!absolutePath) {
5837
- console.log(import_chalk5.default.red(`path ${answer.path} does not exist`));
6119
+ console.log(import_chalk6.default.red(`path ${answer.path} does not exist`));
5838
6120
  return;
5839
6121
  }
5840
6122
  if (domainArg) {
5841
6123
  const check = await checkDomainAvailable(domainArg);
5842
6124
  if (!check.is_valid) {
5843
- console.log(import_chalk5.default.red(`Domain not available: ${check.error || "unknown reason"}`));
6125
+ console.log(import_chalk6.default.red(`Domain not available: ${check.error || "unknown reason"}`));
5844
6126
  return;
5845
6127
  }
5846
- console.log(import_chalk5.default.green(`Domain available: ${domainArg}`));
6128
+ console.log(import_chalk6.default.green(`Domain available: ${domainArg}`));
5847
6129
  }
5848
- console.log(import_chalk5.default.blue(`importing ${absolutePath} to ipfs as CAR...`));
6130
+ console.log(import_chalk6.default.blue(`importing ${absolutePath} to ipfs as CAR...`));
5849
6131
  try {
5850
6132
  const result = await uploadToIpfsSplit_default(absolutePath, true);
5851
6133
  if (result) {
5852
6134
  const uid = getUid2();
5853
6135
  const encryptedCID = encryptHash2(result.contentHash, secretKey2, uid);
5854
6136
  console.log(
5855
- import_chalk5.default.cyan(
6137
+ import_chalk6.default.cyan(
5856
6138
  import_figlet2.default.textSync("Successful", { horizontalLayout: "full" })
5857
6139
  )
5858
6140
  );
5859
- console.log(import_chalk5.default.cyan(`URL:`));
5860
- console.log(import_chalk5.default.cyan(`${URL3}${encryptedCID}`));
6141
+ console.log(import_chalk6.default.cyan(`URL:`));
6142
+ console.log(import_chalk6.default.cyan(`${URL4}${encryptedCID}`));
5861
6143
  if (domainArg) {
5862
- console.log(import_chalk5.default.blue(`Binding domain: ${domainArg} with CID: ${result.contentHash}`));
6144
+ console.log(import_chalk6.default.blue(`Binding domain: ${domainArg} with CID: ${result.contentHash}`));
5863
6145
  const ok = await bindPinmeDomain(domainArg, result.contentHash);
5864
6146
  if (ok) {
5865
- console.log(import_chalk5.default.green(`Bind success: ${domainArg}`));
5866
- console.log(import_chalk5.default.white(`Visit (Pinme subdomain example): https://${domainArg}.pinit.eth.limo`));
6147
+ console.log(import_chalk6.default.green(`Bind success: ${domainArg}`));
6148
+ console.log(import_chalk6.default.white(`Visit (Pinme subdomain example): https://${domainArg}.pinit.eth.limo`));
5867
6149
  } else {
5868
- console.log(import_chalk5.default.red("Binding failed. Please try again later."));
6150
+ console.log(import_chalk6.default.red("Binding failed. Please try again later."));
5869
6151
  }
5870
6152
  }
5871
- console.log(import_chalk5.default.green("\n\u{1F389} import successful, program exit"));
6153
+ console.log(import_chalk6.default.green("\n\u{1F389} import successful, program exit"));
5872
6154
  }
5873
6155
  } catch (error) {
5874
- console.error(import_chalk5.default.red(`Error: ${error.message}`));
6156
+ console.error(import_chalk6.default.red(`Error: ${error.message}`));
5875
6157
  }
5876
6158
  process.exit(0);
5877
6159
  }
5878
6160
  } catch (error) {
5879
- console.error(import_chalk5.default.red(`error executing: ${error.message}`));
6161
+ console.error(import_chalk6.default.red(`error executing: ${error.message}`));
5880
6162
  console.error(error.stack);
5881
6163
  }
5882
6164
  };
5883
6165
 
5884
6166
  // bin/exportCar.ts
5885
- var import_path8 = __toESM(require("path"));
5886
- var import_chalk6 = __toESM(require("chalk"));
6167
+ var import_path9 = __toESM(require("path"));
6168
+ var import_chalk7 = __toESM(require("chalk"));
5887
6169
  var import_inquirer3 = __toESM(require("inquirer"));
5888
6170
  var import_figlet3 = __toESM(require("figlet"));
5889
6171
  var import_fs4 = __toESM(require("fs"));
@@ -5908,7 +6190,7 @@ async function pollExportStatus(taskId, cid, spinner, startTime) {
5908
6190
  spinner.text = `Exporting CAR file... (${minutes}m ${seconds}s)`;
5909
6191
  }
5910
6192
  } catch (error) {
5911
- console.log(import_chalk6.default.yellow(`Polling error: ${error.message}`));
6193
+ console.log(import_chalk7.default.yellow(`Polling error: ${error.message}`));
5912
6194
  }
5913
6195
  await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL2));
5914
6196
  }
@@ -5948,7 +6230,7 @@ async function downloadCarFile(downloadUrl, outputPath) {
5948
6230
  });
5949
6231
  });
5950
6232
  } catch (error) {
5951
- console.error(import_chalk6.default.red(`Download error: ${error.message}`));
6233
+ console.error(import_chalk7.default.red(`Download error: ${error.message}`));
5952
6234
  return false;
5953
6235
  }
5954
6236
  }
@@ -6006,7 +6288,7 @@ var exportCar_default = async () => {
6006
6288
  cid = answer.cid.trim();
6007
6289
  }
6008
6290
  if (!cid || !isValidCID(cid)) {
6009
- console.log(import_chalk6.default.red("Invalid CID format. CID should start with Qm, bafy, bafk, or bafz"));
6291
+ console.log(import_chalk7.default.red("Invalid CID format. CID should start with Qm, bafy, bafk, or bafz"));
6010
6292
  return;
6011
6293
  }
6012
6294
  let outputDir = getOutputPathFromArgs();
@@ -6022,14 +6304,14 @@ var exportCar_default = async () => {
6022
6304
  ]);
6023
6305
  outputDir = answer.output.trim() || currentDir;
6024
6306
  }
6025
- outputDir = import_path8.default.resolve(outputDir);
6307
+ outputDir = import_path9.default.resolve(outputDir);
6026
6308
  if (!import_fs4.default.existsSync(outputDir)) {
6027
6309
  import_fs4.default.mkdirSync(outputDir, { recursive: true });
6028
6310
  } else if (!import_fs4.default.statSync(outputDir).isDirectory()) {
6029
- console.log(import_chalk6.default.red(`Error: ${outputDir} exists but is not a directory.`));
6311
+ console.log(import_chalk7.default.red(`Error: ${outputDir} exists but is not a directory.`));
6030
6312
  return;
6031
6313
  }
6032
- const finalOutputPath = import_path8.default.join(outputDir, `${cid}.car`);
6314
+ const finalOutputPath = import_path9.default.join(outputDir, `${cid}.car`);
6033
6315
  if (import_fs4.default.existsSync(finalOutputPath)) {
6034
6316
  const answer = await import_inquirer3.default.prompt([
6035
6317
  {
@@ -6040,7 +6322,7 @@ var exportCar_default = async () => {
6040
6322
  }
6041
6323
  ]);
6042
6324
  if (!answer.overwrite) {
6043
- console.log(import_chalk6.default.blue("Export cancelled."));
6325
+ console.log(import_chalk7.default.blue("Export cancelled."));
6044
6326
  return;
6045
6327
  }
6046
6328
  }
@@ -6058,7 +6340,7 @@ var exportCar_default = async () => {
6058
6340
  startTime
6059
6341
  );
6060
6342
  if (!downloadUrl) {
6061
- console.log(import_chalk6.default.red("Export failed or timed out."));
6343
+ console.log(import_chalk7.default.red("Export failed or timed out."));
6062
6344
  return;
6063
6345
  }
6064
6346
  const success = await downloadCarFile(downloadUrl, finalOutputPath);
@@ -6066,40 +6348,40 @@ var exportCar_default = async () => {
6066
6348
  const fileSize = import_fs4.default.statSync(finalOutputPath).size;
6067
6349
  const fileSizeMB = (fileSize / (1024 * 1024)).toFixed(2);
6068
6350
  console.log(
6069
- import_chalk6.default.cyan(
6351
+ import_chalk7.default.cyan(
6070
6352
  import_figlet3.default.textSync("Successful", { horizontalLayout: "full" })
6071
6353
  )
6072
6354
  );
6073
- console.log(import_chalk6.default.green(`
6355
+ console.log(import_chalk7.default.green(`
6074
6356
  \u{1F389} Export successful!`));
6075
- console.log(import_chalk6.default.cyan(`File: ${finalOutputPath}`));
6076
- console.log(import_chalk6.default.cyan(`Size: ${fileSizeMB} MB`));
6077
- console.log(import_chalk6.default.cyan(`CID: ${cid}`));
6357
+ console.log(import_chalk7.default.cyan(`File: ${finalOutputPath}`));
6358
+ console.log(import_chalk7.default.cyan(`Size: ${fileSizeMB} MB`));
6359
+ console.log(import_chalk7.default.cyan(`CID: ${cid}`));
6078
6360
  } else {
6079
- console.log(import_chalk6.default.red("Download failed."));
6361
+ console.log(import_chalk7.default.red("Download failed."));
6080
6362
  }
6081
6363
  } catch (error) {
6082
6364
  spinner.fail(`Error: ${error.message}`);
6083
- console.error(import_chalk6.default.red(`Export error: ${error.message}`));
6365
+ console.error(import_chalk7.default.red(`Export error: ${error.message}`));
6084
6366
  }
6085
6367
  } catch (error) {
6086
- console.error(import_chalk6.default.red(`error executing: ${error.message}`));
6368
+ console.error(import_chalk7.default.red(`error executing: ${error.message}`));
6087
6369
  console.error(error.stack);
6088
6370
  }
6089
6371
  };
6090
6372
 
6091
6373
  // bin/remove.ts
6092
- var import_chalk8 = __toESM(require("chalk"));
6374
+ var import_chalk9 = __toESM(require("chalk"));
6093
6375
  var import_inquirer4 = __toESM(require("inquirer"));
6094
6376
  var import_figlet4 = __toESM(require("figlet"));
6095
6377
 
6096
6378
  // bin/utils/removeFromIpfs.ts
6097
- var import_chalk7 = __toESM(require("chalk"));
6379
+ var import_chalk8 = __toESM(require("chalk"));
6098
6380
  var ipfsApiUrl = "https://pinme.dev/api/v3";
6099
6381
  async function removeFromIpfs(value, type = "hash") {
6100
6382
  try {
6101
6383
  const uid = getUid();
6102
- console.log(import_chalk7.default.blue(`Removing content from IPFS: ${value}...`));
6384
+ console.log(import_chalk8.default.blue(`Removing content from IPFS: ${value}...`));
6103
6385
  const queryParams = new URLSearchParams({
6104
6386
  uid
6105
6387
  });
@@ -6117,49 +6399,49 @@ async function removeFromIpfs(value, type = "hash") {
6117
6399
  );
6118
6400
  const { code, msg, data } = response.data;
6119
6401
  if (code === 200) {
6120
- console.log(import_chalk7.default.green("\u2713 Removal successful!"));
6402
+ console.log(import_chalk8.default.green("\u2713 Removal successful!"));
6121
6403
  console.log(
6122
- import_chalk7.default.cyan(
6404
+ import_chalk8.default.cyan(
6123
6405
  `Content ${type}: ${value} has been removed from IPFS network`
6124
6406
  )
6125
6407
  );
6126
6408
  return true;
6127
6409
  } else {
6128
- console.log(import_chalk7.default.red("\u2717 Removal failed"));
6129
- console.log(import_chalk7.default.red(`Error: ${msg || "Unknown error occurred"}`));
6410
+ console.log(import_chalk8.default.red("\u2717 Removal failed"));
6411
+ console.log(import_chalk8.default.red(`Error: ${msg || "Unknown error occurred"}`));
6130
6412
  return false;
6131
6413
  }
6132
6414
  } catch (error) {
6133
- console.log(import_chalk7.default.red("\u2717 Removal failed", error));
6415
+ console.log(import_chalk8.default.red("\u2717 Removal failed", error));
6134
6416
  if (error.response) {
6135
6417
  const { status, data } = error.response;
6136
6418
  console.log(
6137
- import_chalk7.default.red(`HTTP Error ${status}: ${(data == null ? void 0 : data.msg) || "Server error"}`)
6419
+ import_chalk8.default.red(`HTTP Error ${status}: ${(data == null ? void 0 : data.msg) || "Server error"}`)
6138
6420
  );
6139
6421
  if (status === 404) {
6140
6422
  console.log(
6141
- import_chalk7.default.yellow("Content not found on the network or already removed")
6423
+ import_chalk8.default.yellow("Content not found on the network or already removed")
6142
6424
  );
6143
6425
  } else if (status === 403) {
6144
6426
  console.log(
6145
- import_chalk7.default.yellow(
6427
+ import_chalk8.default.yellow(
6146
6428
  "Permission denied - you may not have access to remove this content"
6147
6429
  )
6148
6430
  );
6149
6431
  } else if (status === 500) {
6150
6432
  console.log(
6151
- import_chalk7.default.yellow("Server internal error - please try again later")
6433
+ import_chalk8.default.yellow("Server internal error - please try again later")
6152
6434
  );
6153
6435
  }
6154
6436
  } else if (error.request) {
6155
6437
  console.log(
6156
- import_chalk7.default.red("Network error: Unable to connect to IPFS service")
6438
+ import_chalk8.default.red("Network error: Unable to connect to IPFS service")
6157
6439
  );
6158
6440
  console.log(
6159
- import_chalk7.default.yellow("Please check your internet connection and try again")
6441
+ import_chalk8.default.yellow("Please check your internet connection and try again")
6160
6442
  );
6161
6443
  } else {
6162
- console.log(import_chalk7.default.red(`Error: ${error.message}`));
6444
+ console.log(import_chalk8.default.red(`Error: ${error.message}`));
6163
6445
  }
6164
6446
  return false;
6165
6447
  }
@@ -6219,29 +6501,29 @@ var remove_default = async (options) => {
6219
6501
  if (argHash && !argHash.startsWith("-")) {
6220
6502
  const parsedInput = parseInput(argHash);
6221
6503
  if (!parsedInput) {
6222
- console.log(import_chalk8.default.red(`Invalid input format: ${argHash}`));
6223
- console.log(import_chalk8.default.yellow("Supported formats:"));
6224
- console.log(import_chalk8.default.yellow(" - IPFS hash: bafybeig..."));
6225
- console.log(import_chalk8.default.yellow(" - Subname: 3abt6ztu"));
6226
- console.log(import_chalk8.default.yellow(" - Subname URL: https://3abt6ztu.pinit.eth.limo"));
6504
+ console.log(import_chalk9.default.red(`Invalid input format: ${argHash}`));
6505
+ console.log(import_chalk9.default.yellow("Supported formats:"));
6506
+ console.log(import_chalk9.default.yellow(" - IPFS hash: bafybeig..."));
6507
+ console.log(import_chalk9.default.yellow(" - Subname: 3abt6ztu"));
6508
+ console.log(import_chalk9.default.yellow(" - Subname URL: https://3abt6ztu.pinit.eth.limo"));
6227
6509
  return;
6228
6510
  }
6229
6511
  try {
6230
6512
  const success = await removeFromIpfs(parsedInput.value, parsedInput.type);
6231
6513
  if (success) {
6232
6514
  console.log(
6233
- import_chalk8.default.cyan(
6515
+ import_chalk9.default.cyan(
6234
6516
  import_figlet4.default.textSync("Successful", { horizontalLayout: "full" })
6235
6517
  )
6236
6518
  );
6237
6519
  }
6238
6520
  } catch (error) {
6239
- console.error(import_chalk8.default.red(`Error: ${error.message}`));
6521
+ console.error(import_chalk9.default.red(`Error: ${error.message}`));
6240
6522
  }
6241
6523
  return;
6242
6524
  }
6243
- console.log(import_chalk8.default.yellow("\u26A0\uFE0F Warning: This action will permanently remove the content from IPFS network"));
6244
- console.log(import_chalk8.default.yellow("\u26A0\uFE0F Make sure you have the correct IPFS hash"));
6525
+ console.log(import_chalk9.default.yellow("\u26A0\uFE0F Warning: This action will permanently remove the content from IPFS network"));
6526
+ console.log(import_chalk9.default.yellow("\u26A0\uFE0F Make sure you have the correct IPFS hash"));
6245
6527
  console.log("");
6246
6528
  const confirmAnswer = await import_inquirer4.default.prompt([
6247
6529
  {
@@ -6252,7 +6534,7 @@ var remove_default = async (options) => {
6252
6534
  }
6253
6535
  ]);
6254
6536
  if (!confirmAnswer.confirm) {
6255
- console.log(import_chalk8.default.yellow("Operation cancelled"));
6537
+ console.log(import_chalk9.default.yellow("Operation cancelled"));
6256
6538
  return;
6257
6539
  }
6258
6540
  const answer = await import_inquirer4.default.prompt([
@@ -6275,7 +6557,7 @@ var remove_default = async (options) => {
6275
6557
  if (answer.input) {
6276
6558
  const parsedInput = parseInput(answer.input.trim());
6277
6559
  if (!parsedInput) {
6278
- console.log(import_chalk8.default.red("Invalid input format"));
6560
+ console.log(import_chalk9.default.red("Invalid input format"));
6279
6561
  return;
6280
6562
  }
6281
6563
  const finalConfirm = await import_inquirer4.default.prompt([
@@ -6287,30 +6569,30 @@ var remove_default = async (options) => {
6287
6569
  }
6288
6570
  ]);
6289
6571
  if (!finalConfirm.confirm) {
6290
- console.log(import_chalk8.default.yellow("Operation cancelled"));
6572
+ console.log(import_chalk9.default.yellow("Operation cancelled"));
6291
6573
  return;
6292
6574
  }
6293
6575
  try {
6294
6576
  const success = await removeFromIpfs(parsedInput.value, parsedInput.type);
6295
6577
  if (success) {
6296
6578
  console.log(
6297
- import_chalk8.default.cyan(
6579
+ import_chalk9.default.cyan(
6298
6580
  import_figlet4.default.textSync("Successful", { horizontalLayout: "full" })
6299
6581
  )
6300
6582
  );
6301
6583
  }
6302
6584
  } catch (error) {
6303
- console.error(import_chalk8.default.red(`Error: ${error.message}`));
6585
+ console.error(import_chalk9.default.red(`Error: ${error.message}`));
6304
6586
  }
6305
6587
  }
6306
6588
  } catch (error) {
6307
- console.error(import_chalk8.default.red(`Error executing remove command: ${error.message}`));
6589
+ console.error(import_chalk9.default.red(`Error executing remove command: ${error.message}`));
6308
6590
  console.error(error.stack);
6309
6591
  }
6310
6592
  };
6311
6593
 
6312
6594
  // bin/set-appkey.ts
6313
- var import_chalk9 = __toESM(require("chalk"));
6595
+ var import_chalk10 = __toESM(require("chalk"));
6314
6596
  var import_inquirer5 = __toESM(require("inquirer"));
6315
6597
  async function setAppKeyCmd() {
6316
6598
  try {
@@ -6327,31 +6609,31 @@ async function setAppKeyCmd() {
6327
6609
  appKey = ans.appKey;
6328
6610
  }
6329
6611
  if (!appKey) {
6330
- console.log(import_chalk9.default.red("AppKey not provided."));
6612
+ console.log(import_chalk10.default.red("AppKey not provided."));
6331
6613
  return;
6332
6614
  }
6333
6615
  const saved = setAuthToken(appKey);
6334
- console.log(import_chalk9.default.green(`Auth set for address: ${saved.address}`));
6616
+ console.log(import_chalk10.default.green(`Auth set for address: ${saved.address}`));
6335
6617
  const deviceId = getDeviceId();
6336
6618
  const ok = await bindAnonymousDevice(deviceId);
6337
6619
  if (ok) {
6338
- console.log(import_chalk9.default.green("Anonymous history merged to current account."));
6620
+ console.log(import_chalk10.default.green("Anonymous history merged to current account."));
6339
6621
  } else {
6340
- console.log(import_chalk9.default.yellow("Anonymous history merge not confirmed. You may retry later."));
6622
+ console.log(import_chalk10.default.yellow("Anonymous history merge not confirmed. You may retry later."));
6341
6623
  }
6342
6624
  } catch (e) {
6343
- console.log(import_chalk9.default.red(`Failed to set AppKey: ${(e == null ? void 0 : e.message) || e}`));
6625
+ console.log(import_chalk10.default.red(`Failed to set AppKey: ${(e == null ? void 0 : e.message) || e}`));
6344
6626
  }
6345
6627
  }
6346
6628
 
6347
6629
  // bin/logout.ts
6348
- var import_chalk10 = __toESM(require("chalk"));
6630
+ var import_chalk11 = __toESM(require("chalk"));
6349
6631
  var import_inquirer6 = __toESM(require("inquirer"));
6350
6632
  async function logoutCmd() {
6351
6633
  try {
6352
- const auth = getAuthConfig();
6634
+ const auth = getAuthConfig2();
6353
6635
  if (!auth) {
6354
- console.log(import_chalk10.default.yellow("No active session found. You are already logged out."));
6636
+ console.log(import_chalk11.default.yellow("No active session found. You are already logged out."));
6355
6637
  return;
6356
6638
  }
6357
6639
  const answer = await import_inquirer6.default.prompt([
@@ -6363,80 +6645,80 @@ async function logoutCmd() {
6363
6645
  }
6364
6646
  ]);
6365
6647
  if (!answer.confirm) {
6366
- console.log(import_chalk10.default.blue("Logout cancelled."));
6648
+ console.log(import_chalk11.default.blue("Logout cancelled."));
6367
6649
  return;
6368
6650
  }
6369
6651
  clearAuthToken();
6370
- console.log(import_chalk10.default.green("Successfully logged out."));
6371
- console.log(import_chalk10.default.gray(`Address ${auth.address} has been removed from local storage.`));
6652
+ console.log(import_chalk11.default.green("Successfully logged out."));
6653
+ console.log(import_chalk11.default.gray(`Address ${auth.address} has been removed from local storage.`));
6372
6654
  } catch (e) {
6373
- console.log(import_chalk10.default.red(`Failed to logout: ${(e == null ? void 0 : e.message) || e}`));
6655
+ console.log(import_chalk11.default.red(`Failed to logout: ${(e == null ? void 0 : e.message) || e}`));
6374
6656
  }
6375
6657
  }
6376
6658
 
6377
6659
  // bin/show-appkey.ts
6378
- var import_chalk11 = __toESM(require("chalk"));
6660
+ var import_chalk12 = __toESM(require("chalk"));
6379
6661
  function showAppKeyCmd() {
6380
6662
  try {
6381
- const auth = getAuthConfig();
6663
+ const auth = getAuthConfig2();
6382
6664
  if (!auth) {
6383
- console.log(import_chalk11.default.yellow("No AppKey found. Please set your AppKey first."));
6384
- console.log(import_chalk11.default.gray("Run: pinme set-appkey <AppKey>"));
6665
+ console.log(import_chalk12.default.yellow("No AppKey found. Please set your AppKey first."));
6666
+ console.log(import_chalk12.default.gray("Run: pinme set-appkey <AppKey>"));
6385
6667
  return;
6386
6668
  }
6387
- console.log(import_chalk11.default.green("Current AppKey Information:"));
6388
- console.log(import_chalk11.default.cyan(` Address: ${auth.address}`));
6669
+ console.log(import_chalk12.default.green("Current AppKey Information:"));
6670
+ console.log(import_chalk12.default.cyan(` Address: ${auth.address}`));
6389
6671
  const token = auth.token;
6390
6672
  if (token.length > 12) {
6391
6673
  const maskedToken = `${token.substring(0, 8)}${"*".repeat(token.length - 12)}${token.substring(token.length - 4)}`;
6392
- console.log(import_chalk11.default.cyan(` Token: ${maskedToken}`));
6674
+ console.log(import_chalk12.default.cyan(` Token: ${maskedToken}`));
6393
6675
  } else {
6394
- console.log(import_chalk11.default.cyan(` Token: ${"*".repeat(token.length)}`));
6676
+ console.log(import_chalk12.default.cyan(` Token: ${"*".repeat(token.length)}`));
6395
6677
  }
6396
6678
  const combined = `${auth.address}-${auth.token}`;
6397
6679
  if (combined.length > 20) {
6398
6680
  const maskedAppKey = `${combined.substring(0, 12)}${"*".repeat(combined.length - 16)}${combined.substring(combined.length - 4)}`;
6399
- console.log(import_chalk11.default.cyan(` AppKey: ${maskedAppKey}`));
6681
+ console.log(import_chalk12.default.cyan(` AppKey: ${maskedAppKey}`));
6400
6682
  } else {
6401
- console.log(import_chalk11.default.cyan(` AppKey: ${"*".repeat(combined.length)}`));
6683
+ console.log(import_chalk12.default.cyan(` AppKey: ${"*".repeat(combined.length)}`));
6402
6684
  }
6403
6685
  } catch (e) {
6404
- console.log(import_chalk11.default.red(`Failed to show AppKey: ${(e == null ? void 0 : e.message) || e}`));
6686
+ console.log(import_chalk12.default.red(`Failed to show AppKey: ${(e == null ? void 0 : e.message) || e}`));
6405
6687
  }
6406
6688
  }
6407
6689
 
6408
6690
  // bin/my-domains.ts
6409
- var import_chalk12 = __toESM(require("chalk"));
6691
+ var import_chalk13 = __toESM(require("chalk"));
6410
6692
  var import_dayjs2 = __toESM(require("dayjs"));
6411
6693
  async function myDomainsCmd() {
6412
6694
  try {
6413
6695
  const list = await getMyDomains();
6414
6696
  if (!list.length) {
6415
- console.log(import_chalk12.default.yellow("No bound domains found."));
6697
+ console.log(import_chalk13.default.yellow("No bound domains found."));
6416
6698
  return;
6417
6699
  }
6418
- console.log(import_chalk12.default.cyan("My domains:"));
6419
- console.log(import_chalk12.default.cyan("-".repeat(80)));
6700
+ console.log(import_chalk13.default.cyan("My domains:"));
6701
+ console.log(import_chalk13.default.cyan("-".repeat(80)));
6420
6702
  list.forEach((item, i) => {
6421
- console.log(import_chalk12.default.green(`${i + 1}. ${item.domain_name}`));
6422
- console.log(import_chalk12.default.white(` Type: ${item.domain_type}`));
6703
+ console.log(import_chalk13.default.green(`${i + 1}. ${item.domain_name}`));
6704
+ console.log(import_chalk13.default.white(` Type: ${item.domain_type}`));
6423
6705
  if (item.bind_time) {
6424
- console.log(import_chalk12.default.white(` Bind time: ${(0, import_dayjs2.default)(item.bind_time * 1e3).format("YYYY-MM-DD HH:mm:ss")}`));
6706
+ console.log(import_chalk13.default.white(` Bind time: ${(0, import_dayjs2.default)(item.bind_time * 1e3).format("YYYY-MM-DD HH:mm:ss")}`));
6425
6707
  }
6426
6708
  if (typeof item.expire_time === "number") {
6427
6709
  const label = item.expire_time === 0 ? "Never" : (0, import_dayjs2.default)(item.expire_time * 1e3).format("YYYY-MM-DD HH:mm:ss");
6428
- console.log(import_chalk12.default.white(` Expire time: ${label}`));
6710
+ console.log(import_chalk13.default.white(` Expire time: ${label}`));
6429
6711
  }
6430
- console.log(import_chalk12.default.cyan("-".repeat(80)));
6712
+ console.log(import_chalk13.default.cyan("-".repeat(80)));
6431
6713
  });
6432
6714
  } catch (e) {
6433
- console.log(import_chalk12.default.red(`Failed to fetch domains: ${(e == null ? void 0 : e.message) || e}`));
6715
+ console.log(import_chalk13.default.red(`Failed to fetch domains: ${(e == null ? void 0 : e.message) || e}`));
6434
6716
  }
6435
6717
  }
6436
6718
 
6437
6719
  // bin/bind.ts
6438
- var import_path9 = __toESM(require("path"));
6439
- var import_chalk13 = __toESM(require("chalk"));
6720
+ var import_path10 = __toESM(require("path"));
6721
+ var import_chalk14 = __toESM(require("chalk"));
6440
6722
  var import_inquirer7 = __toESM(require("inquirer"));
6441
6723
  function isDnsDomain2(domain) {
6442
6724
  return domain.includes(".");
@@ -6487,19 +6769,19 @@ function parseArgs() {
6487
6769
  }
6488
6770
  async function checkVipStatus2(authConfig) {
6489
6771
  var _a;
6490
- console.log(import_chalk13.default.blue("Checking VIP status..."));
6772
+ console.log(import_chalk14.default.blue("Checking VIP status..."));
6491
6773
  try {
6492
6774
  const vipResult = await isVip(authConfig.address, authConfig.token);
6493
6775
  if (!((_a = vipResult.data) == null ? void 0 : _a.is_vip)) {
6494
6776
  return false;
6495
6777
  }
6496
- console.log(import_chalk13.default.green("VIP verified."));
6778
+ console.log(import_chalk14.default.green("VIP verified."));
6497
6779
  return true;
6498
6780
  } catch (e) {
6499
6781
  if (e.message === "Token expired") {
6500
6782
  throw e;
6501
6783
  }
6502
- console.log(import_chalk13.default.yellow("Failed to check VIP status, continuing..."));
6784
+ console.log(import_chalk14.default.yellow("Failed to check VIP status, continuing..."));
6503
6785
  return true;
6504
6786
  }
6505
6787
  }
@@ -6507,9 +6789,9 @@ async function bindCmd() {
6507
6789
  var _a;
6508
6790
  try {
6509
6791
  let { domain, targetPath, dns } = parseArgs();
6510
- const authConfig = getAuthConfig();
6792
+ const authConfig = getAuthConfig2();
6511
6793
  if (!authConfig) {
6512
- console.log(import_chalk13.default.red("Please login first. Run: pinme set-appkey <AppKey>"));
6794
+ console.log(import_chalk14.default.red("Please login first. Run: pinme set-appkey <AppKey>"));
6513
6795
  return;
6514
6796
  }
6515
6797
  if (!targetPath) {
@@ -6525,7 +6807,7 @@ async function bindCmd() {
6525
6807
  domain = (_a = ans.domain) == null ? void 0 : _a.trim();
6526
6808
  }
6527
6809
  if (!targetPath || !domain) {
6528
- console.log(import_chalk13.default.red("Missing parameters. Path and domain are required."));
6810
+ console.log(import_chalk14.default.red("Missing parameters. Path and domain are required."));
6529
6811
  return;
6530
6812
  }
6531
6813
  const isDns = dns || isDnsDomain2(domain);
@@ -6534,14 +6816,14 @@ async function bindCmd() {
6534
6816
  if (isDns) {
6535
6817
  const validation = validateDnsDomain2(domain);
6536
6818
  if (!validation.valid) {
6537
- console.log(import_chalk13.default.red(validation.message));
6819
+ console.log(import_chalk14.default.red(validation.message));
6538
6820
  return;
6539
6821
  }
6540
6822
  }
6541
6823
  try {
6542
6824
  const isVipUser = await checkVipStatus2(authConfig);
6543
6825
  if (!isVipUser) {
6544
- console.log(import_chalk13.default.red("Domain binding requires VIP. Please upgrade to VIP first."));
6826
+ console.log(import_chalk14.default.red("Domain binding requires VIP. Please upgrade to VIP first."));
6545
6827
  return;
6546
6828
  }
6547
6829
  } catch (e) {
@@ -6553,44 +6835,44 @@ async function bindCmd() {
6553
6835
  try {
6554
6836
  const check = await checkDomainAvailable(displayDomain);
6555
6837
  if (!check.is_valid) {
6556
- console.log(import_chalk13.default.red(`Domain not available: ${check.error || "unknown reason"}`));
6838
+ console.log(import_chalk14.default.red(`Domain not available: ${check.error || "unknown reason"}`));
6557
6839
  return;
6558
6840
  }
6559
- console.log(import_chalk13.default.green(`Domain available: ${displayDomain}`));
6841
+ console.log(import_chalk14.default.green(`Domain available: ${displayDomain}`));
6560
6842
  } catch (e) {
6561
6843
  if (e.message === "Token expired") {
6562
6844
  return;
6563
6845
  }
6564
6846
  throw e;
6565
6847
  }
6566
- const absolutePath = import_path9.default.resolve(targetPath);
6567
- console.log(import_chalk13.default.blue(`Uploading: ${absolutePath}`));
6848
+ const absolutePath = import_path10.default.resolve(targetPath);
6849
+ console.log(import_chalk14.default.blue(`Uploading: ${absolutePath}`));
6568
6850
  const up = await uploadToIpfsSplit_default(absolutePath);
6569
6851
  if (!(up == null ? void 0 : up.contentHash)) {
6570
- console.log(import_chalk13.default.red("Upload failed, binding aborted."));
6852
+ console.log(import_chalk14.default.red("Upload failed, binding aborted."));
6571
6853
  return;
6572
6854
  }
6573
- console.log(import_chalk13.default.green(`Upload success, CID: ${up.contentHash}`));
6855
+ console.log(import_chalk14.default.green(`Upload success, CID: ${up.contentHash}`));
6574
6856
  try {
6575
6857
  if (isDns) {
6576
- console.log(import_chalk13.default.blue("Binding DNS domain..."));
6858
+ console.log(import_chalk14.default.blue("Binding DNS domain..."));
6577
6859
  const dnsResult = await bindDnsDomainV4(displayDomain, up.contentHash, authConfig.address, authConfig.token);
6578
6860
  if (dnsResult.code !== 200) {
6579
- console.log(import_chalk13.default.red(`DNS binding failed: ${dnsResult.msg}`));
6861
+ console.log(import_chalk14.default.red(`DNS binding failed: ${dnsResult.msg}`));
6580
6862
  return;
6581
6863
  }
6582
- console.log(import_chalk13.default.green(`DNS bind success: ${displayDomain}`));
6583
- console.log(import_chalk13.default.white(`Visit: https://${displayDomain}`));
6584
- console.log(import_chalk13.default.cyan("\n\u{1F4DA} DNS Setup Guide: https://pinme.eth.limo/#/docs?id=custom-domain"));
6864
+ console.log(import_chalk14.default.green(`DNS bind success: ${displayDomain}`));
6865
+ console.log(import_chalk14.default.white(`Visit: https://${displayDomain}`));
6866
+ console.log(import_chalk14.default.cyan("\n\u{1F4DA} DNS Setup Guide: https://pinme.eth.limo/#/docs?id=custom-domain"));
6585
6867
  } else {
6586
- console.log(import_chalk13.default.blue("Binding Pinme subdomain..."));
6868
+ console.log(import_chalk14.default.blue("Binding Pinme subdomain..."));
6587
6869
  const ok = await bindPinmeDomain(displayDomain, up.contentHash);
6588
6870
  if (!ok) {
6589
- console.log(import_chalk13.default.red("Binding failed. Please try again later."));
6871
+ console.log(import_chalk14.default.red("Binding failed. Please try again later."));
6590
6872
  return;
6591
6873
  }
6592
- console.log(import_chalk13.default.green(`Bind success: ${displayDomain}`));
6593
- console.log(import_chalk13.default.white(`Visit: https://${displayDomain}.pinit.eth.limo`));
6874
+ console.log(import_chalk14.default.green(`Bind success: ${displayDomain}`));
6875
+ console.log(import_chalk14.default.white(`Visit: https://${displayDomain}.pinit.eth.limo`));
6594
6876
  }
6595
6877
  } catch (e) {
6596
6878
  if (e.message === "Token expired") {
@@ -6599,7 +6881,781 @@ async function bindCmd() {
6599
6881
  throw e;
6600
6882
  }
6601
6883
  } catch (e) {
6602
- console.log(import_chalk13.default.red(`Execution failed: ${(e == null ? void 0 : e.message) || e}`));
6884
+ console.log(import_chalk14.default.red(`Execution failed: ${(e == null ? void 0 : e.message) || e}`));
6885
+ }
6886
+ }
6887
+
6888
+ // bin/login.ts
6889
+ var import_chalk15 = __toESM(require("chalk"));
6890
+ var ENV_URLS = {
6891
+ dev: "http://localhost:5173",
6892
+ test: "http://test-pinme.pinit.eth.limo",
6893
+ prod: "https://pinme.eth.limo"
6894
+ };
6895
+ async function loginCmd(options = {}) {
6896
+ try {
6897
+ const existingAuth = getAuthConfig2();
6898
+ if (existingAuth) {
6899
+ console.log(import_chalk15.default.yellow("Already logged in"));
6900
+ console.log(import_chalk15.default.gray(` Address: ${existingAuth.address}`));
6901
+ console.log(import_chalk15.default.gray(" To re-login, please run: pinme logout\n"));
6902
+ process.exit(0);
6903
+ return;
6904
+ }
6905
+ let webBaseUrl;
6906
+ const env = (options.env || "prod").toLowerCase();
6907
+ if (ENV_URLS[env]) {
6908
+ webBaseUrl = ENV_URLS[env];
6909
+ console.log(import_chalk15.default.blue(`Using ${env} environment: ${webBaseUrl}`));
6910
+ } else {
6911
+ console.log(import_chalk15.default.yellow(`Unknown environment: ${options.env}. Using default prod.`));
6912
+ webBaseUrl = ENV_URLS.prod;
6913
+ console.log(import_chalk15.default.blue(`Using prod environment: ${webBaseUrl}`));
6914
+ }
6915
+ const manager = new WebLoginManager({ webBaseUrl });
6916
+ await manager.login();
6917
+ console.log(import_chalk15.default.blue("\nMerging history..."));
6918
+ const deviceId = getDeviceId();
6919
+ const ok = await bindAnonymousDevice(deviceId);
6920
+ if (ok) {
6921
+ console.log(import_chalk15.default.green("History merged to your account"));
6922
+ }
6923
+ process.exit(0);
6924
+ } catch (e) {
6925
+ console.log(import_chalk15.default.red(`
6926
+ Login failed: ${(e == null ? void 0 : e.message) || e}`));
6927
+ process.exit(1);
6928
+ }
6929
+ }
6930
+
6931
+ // bin/create.ts
6932
+ var import_chalk16 = __toESM(require("chalk"));
6933
+ var import_fs_extra6 = __toESM(require("fs-extra"));
6934
+ var import_path11 = __toESM(require("path"));
6935
+ var import_inquirer8 = __toESM(require("inquirer"));
6936
+ var TEMPLATE_DIR = import_path11.default.join(__dirname, "../template");
6937
+ var PROJECT_DIR = process.cwd();
6938
+ var API_BASE = "https://pinme.benny1996.win/api/v4";
6939
+ async function createCmd(options) {
6940
+ var _a, _b, _c, _d, _e, _f;
6941
+ try {
6942
+ const headers = getAuthHeaders();
6943
+ if (!headers["authentication-tokens"] || !headers["token-address"]) {
6944
+ console.log(import_chalk16.default.yellow("\n\u26A0\uFE0F You are not logged in."));
6945
+ console.log(import_chalk16.default.gray("Please run: pinme login"));
6946
+ process.exit(1);
6947
+ }
6948
+ console.log(import_chalk16.default.blue("Creating new project from template...\n"));
6949
+ let projectName = options.name;
6950
+ if (!projectName) {
6951
+ const answers = await import_inquirer8.default.prompt([
6952
+ {
6953
+ type: "input",
6954
+ name: "projectName",
6955
+ message: "Enter project name:",
6956
+ validate: (input) => {
6957
+ if (!input.trim()) return "Project name is required";
6958
+ if (!/^[a-zA-Z0-9-_]+$/.test(input)) {
6959
+ return "Project name can only contain letters, numbers, hyphens and underscores";
6960
+ }
6961
+ return true;
6962
+ }
6963
+ }
6964
+ ]);
6965
+ projectName = answers.projectName;
6966
+ }
6967
+ const targetDir = import_path11.default.join(PROJECT_DIR, projectName);
6968
+ if (import_fs_extra6.default.existsSync(targetDir) && !options.force) {
6969
+ console.log(import_chalk16.default.yellow(`
6970
+ Directory "${projectName}" already exists.`));
6971
+ const answers = await import_inquirer8.default.prompt([
6972
+ {
6973
+ type: "confirm",
6974
+ name: "overwrite",
6975
+ message: "Do you want to overwrite it?",
6976
+ default: false
6977
+ }
6978
+ ]);
6979
+ if (!answers.overwrite) {
6980
+ console.log(import_chalk16.default.gray("Cancelled."));
6981
+ process.exit(0);
6982
+ }
6983
+ import_fs_extra6.default.removeSync(targetDir);
6984
+ }
6985
+ console.log(import_chalk16.default.blue("\n1. Creating worker and database..."));
6986
+ const apiUrl = `${API_BASE}/create_worker`;
6987
+ console.log(import_chalk16.default.gray(`API URL: ${apiUrl}`));
6988
+ const normalizedProjectName = projectName.toLowerCase();
6989
+ console.log(import_chalk16.default.gray(`Project name: ${normalizedProjectName}`));
6990
+ let workerData;
6991
+ try {
6992
+ const response = await axios_default.post(apiUrl, {
6993
+ project_name: normalizedProjectName
6994
+ }, {
6995
+ headers: {
6996
+ ...headers,
6997
+ "Content-Type": "application/json"
6998
+ }
6999
+ });
7000
+ const data = response.data;
7001
+ if (data.code !== 200) {
7002
+ const errorMsg = ((_a = data == null ? void 0 : data.data) == null ? void 0 : _a.error) || (data == null ? void 0 : data.msg) || "Failed to create worker";
7003
+ throw new Error(errorMsg);
7004
+ }
7005
+ workerData = data.data;
7006
+ console.log(import_chalk16.default.gray(` API Response: ${JSON.stringify(workerData)}`));
7007
+ console.log(import_chalk16.default.green(` API Domain: ${workerData.api_domain}`));
7008
+ console.log(import_chalk16.default.green(` Project Name: ${workerData.project_name}`));
7009
+ console.log(import_chalk16.default.green(` D1 UUID: ${workerData.uuid}`));
7010
+ } catch (error) {
7011
+ const errorMsg = ((_d = (_c = (_b = error.response) == null ? void 0 : _b.data) == null ? void 0 : _c.data) == null ? void 0 : _d.error) || ((_f = (_e = error.response) == null ? void 0 : _e.data) == null ? void 0 : _f.msg) || error.message || "Failed to create worker";
7012
+ throw new Error(errorMsg);
7013
+ }
7014
+ console.log(import_chalk16.default.blue("\n2. Copying template files..."));
7015
+ import_fs_extra6.default.copySync(TEMPLATE_DIR, targetDir);
7016
+ console.log(import_chalk16.default.green(` Template copied to: ${targetDir}`));
7017
+ console.log(import_chalk16.default.blue("\n3. Updating configuration..."));
7018
+ const configPath = import_path11.default.join(targetDir, "pinme.toml");
7019
+ const config = import_fs_extra6.default.readFileSync(configPath, "utf-8");
7020
+ let updatedConfig = config.replace(
7021
+ /project_name = ".*"/,
7022
+ `project_name = "${workerData.project_name}"`
7023
+ );
7024
+ updatedConfig = updatedConfig.replace(
7025
+ /^VITE_WORKER_URL = ".*"$/m,
7026
+ `VITE_WORKER_URL = "${workerData.api_domain}"`
7027
+ );
7028
+ updatedConfig = updatedConfig.replace(
7029
+ /# database_id = ".*"/,
7030
+ `database_id = "${workerData.uuid}"`
7031
+ );
7032
+ import_fs_extra6.default.writeFileSync(configPath, updatedConfig);
7033
+ console.log(import_chalk16.default.green(` Updated pinme.toml`));
7034
+ console.log(import_chalk16.default.gray(` metadata: ${workerData.metadata}`));
7035
+ console.log(import_chalk16.default.gray(` VITE_API_URL: ${workerData.api_domain}`));
7036
+ const backendDir = import_path11.default.join(targetDir, "backend");
7037
+ if (import_fs_extra6.default.existsSync(backendDir) && workerData.metadata) {
7038
+ const metadataContent = typeof workerData.metadata === "string" ? workerData.metadata : JSON.stringify(workerData.metadata, null, 2);
7039
+ import_fs_extra6.default.writeFileSync(
7040
+ import_path11.default.join(backendDir, "metadata.json"),
7041
+ metadataContent
7042
+ );
7043
+ console.log(import_chalk16.default.green(` Saved metadata.json`));
7044
+ }
7045
+ const envExamplePath = import_path11.default.join(targetDir, "frontend", ".env.example");
7046
+ const envPath = import_path11.default.join(targetDir, "frontend", ".env");
7047
+ if (import_fs_extra6.default.existsSync(envExamplePath)) {
7048
+ let envContent = import_fs_extra6.default.readFileSync(envExamplePath, "utf-8");
7049
+ envContent = envContent.replace(/your-project/g, workerData.project_name);
7050
+ envContent = envContent.replace(
7051
+ /^VITE_WORKER_URL=.*$/m,
7052
+ `VITE_WORKER_URL=${workerData.api_domain}`
7053
+ );
7054
+ envContent = envContent.replace(
7055
+ /^VITE_API_URL=.*$/m,
7056
+ `VITE_API_URL=${workerData.api_domain}`
7057
+ );
7058
+ import_fs_extra6.default.writeFileSync(envPath, envContent);
7059
+ console.log(import_chalk16.default.green(` Created frontend/.env file`));
7060
+ }
7061
+ console.log(import_chalk16.default.green("\n\u2705 Project created successfully!"));
7062
+ console.log(import_chalk16.default.gray(`
7063
+ Project Details:`));
7064
+ console.log(import_chalk16.default.gray(` API Domain: ${workerData.api_domain}`));
7065
+ console.log(import_chalk16.default.gray(` Project Name: ${workerData.project_name}`));
7066
+ console.log(import_chalk16.default.gray(`
7067
+ Next steps:`));
7068
+ console.log(import_chalk16.default.gray(` cd ${projectName}`));
7069
+ console.log(import_chalk16.default.gray(` npm install`));
7070
+ process.exit(0);
7071
+ } catch (error) {
7072
+ console.error(import_chalk16.default.red(`
7073
+ Error: ${error.message || error}`));
7074
+ process.exit(1);
7075
+ }
7076
+ }
7077
+
7078
+ // bin/save.ts
7079
+ var import_chalk17 = __toESM(require("chalk"));
7080
+ var import_fs_extra7 = __toESM(require("fs-extra"));
7081
+ var import_path12 = __toESM(require("path"));
7082
+ var import_child_process2 = require("child_process");
7083
+ var PROJECT_DIR2 = process.cwd();
7084
+ var API_BASE2 = "https://pinme.benny1996.win/api/v4";
7085
+ function loadConfig() {
7086
+ const configPath = import_path12.default.join(PROJECT_DIR2, "pinme.toml");
7087
+ if (!import_fs_extra7.default.existsSync(configPath)) {
7088
+ throw new Error("pinme.toml not found");
7089
+ }
7090
+ const configContent = import_fs_extra7.default.readFileSync(configPath, "utf-8");
7091
+ const projectNameMatch = configContent.match(/project_name\s*=\s*"([^"]+)"/);
7092
+ return {
7093
+ project_name: (projectNameMatch == null ? void 0 : projectNameMatch[1]) || ""
7094
+ };
7095
+ }
7096
+ function getMetadata() {
7097
+ const metadataPath = import_path12.default.join(PROJECT_DIR2, "backend", "metadata.json");
7098
+ if (!import_fs_extra7.default.existsSync(metadataPath)) {
7099
+ console.log(import_chalk17.default.yellow(" Warning: metadata.json not found, using empty metadata"));
7100
+ return {};
7101
+ }
7102
+ return import_fs_extra7.default.readJsonSync(metadataPath);
7103
+ }
7104
+ function buildWorker() {
7105
+ console.log(import_chalk17.default.blue("Building worker..."));
7106
+ try {
7107
+ (0, import_child_process2.execSync)("npm run build:worker", {
7108
+ cwd: PROJECT_DIR2,
7109
+ stdio: "inherit"
7110
+ });
7111
+ console.log(import_chalk17.default.green("Worker built"));
7112
+ } catch (error) {
7113
+ throw new Error(`Worker build failed: ${error.message}`);
7114
+ }
7115
+ }
7116
+ function installDependencies() {
7117
+ console.log(import_chalk17.default.blue("Installing dependencies..."));
7118
+ try {
7119
+ (0, import_child_process2.execSync)("npm install", {
7120
+ cwd: PROJECT_DIR2,
7121
+ stdio: "inherit"
7122
+ });
7123
+ console.log(import_chalk17.default.green("Root dependencies installed"));
7124
+ } catch (error) {
7125
+ throw new Error(`Root dependencies install failed: ${error.message}`);
7126
+ }
7127
+ const backendDir = import_path12.default.join(PROJECT_DIR2, "backend");
7128
+ if (import_fs_extra7.default.existsSync(import_path12.default.join(backendDir, "package.json"))) {
7129
+ try {
7130
+ (0, import_child_process2.execSync)("npm install", {
7131
+ cwd: backendDir,
7132
+ stdio: "inherit"
7133
+ });
7134
+ console.log(import_chalk17.default.green("Backend dependencies installed"));
7135
+ } catch (error) {
7136
+ throw new Error(`Backend dependencies install failed: ${error.message}`);
7137
+ }
7138
+ }
7139
+ const frontendDir = import_path12.default.join(PROJECT_DIR2, "frontend");
7140
+ if (import_fs_extra7.default.existsSync(import_path12.default.join(frontendDir, "package.json"))) {
7141
+ try {
7142
+ (0, import_child_process2.execSync)("npm install", {
7143
+ cwd: frontendDir,
7144
+ stdio: "inherit"
7145
+ });
7146
+ console.log(import_chalk17.default.green("Frontend dependencies installed"));
7147
+ } catch (error) {
7148
+ throw new Error(`Frontend dependencies install failed: ${error.message}`);
7149
+ }
7150
+ }
7151
+ }
7152
+ function getBuiltWorker() {
7153
+ const distWorkerDir = import_path12.default.join(PROJECT_DIR2, "dist-worker");
7154
+ if (!import_fs_extra7.default.existsSync(distWorkerDir)) {
7155
+ throw new Error('Dist worker not found. Run "npm run build:worker" first.');
7156
+ }
7157
+ const workerJsPath = import_path12.default.join(distWorkerDir, "worker.js");
7158
+ if (!import_fs_extra7.default.existsSync(workerJsPath)) {
7159
+ throw new Error("worker.js not found in dist-worker");
7160
+ }
7161
+ const modulePaths = [];
7162
+ const files = import_fs_extra7.default.readdirSync(distWorkerDir);
7163
+ for (const file of files) {
7164
+ if (file.endsWith(".js") && file !== "worker.js") {
7165
+ modulePaths.push(import_path12.default.join(distWorkerDir, file));
7166
+ }
7167
+ }
7168
+ return { workerJsPath, modulePaths };
7169
+ }
7170
+ function getSqlFiles() {
7171
+ const sqlDir = import_path12.default.join(PROJECT_DIR2, "backend", "schema");
7172
+ if (!import_fs_extra7.default.existsSync(sqlDir)) {
7173
+ return [];
7174
+ }
7175
+ const files = import_fs_extra7.default.readdirSync(sqlDir).filter((f) => f.endsWith(".sql")).sort();
7176
+ return files.map((f) => import_path12.default.join(sqlDir, f));
7177
+ }
7178
+ async function saveWorker(workerJsPath, modulePaths, sqlFiles, metadata, projectName) {
7179
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
7180
+ console.log(import_chalk17.default.blue("Saving worker to platform..."));
7181
+ console.log(import_chalk17.default.gray(`Project: ${projectName}`));
7182
+ console.log(import_chalk17.default.gray(`workerJsPath: ${workerJsPath}`));
7183
+ console.log(import_chalk17.default.gray(`modulePaths: ${modulePaths}`));
7184
+ console.log(import_chalk17.default.gray(`sqlFiles: ${sqlFiles}`));
7185
+ console.log(import_chalk17.default.gray(`metadata: ${metadata}`));
7186
+ const apiUrl = `${API_BASE2}/save_worker?project_name=${encodeURIComponent(projectName)}`;
7187
+ const headers = getAuthHeaders();
7188
+ console.log(import_chalk17.default.gray(`API URL: ${apiUrl}`));
7189
+ try {
7190
+ const FormData4 = (await import("formdata-node")).FormData;
7191
+ const Blob2 = (await import("formdata-node")).Blob;
7192
+ const formData = new FormData4();
7193
+ formData.append("metadata", new Blob2([JSON.stringify(metadata)], {
7194
+ type: "application/json"
7195
+ }), "metadata.json");
7196
+ const workerCode = import_fs_extra7.default.readFileSync(workerJsPath, "utf-8");
7197
+ formData.append("worker.js", new Blob2([workerCode], {
7198
+ type: "application/javascript+module"
7199
+ }), "worker.js");
7200
+ for (const modulePath of modulePaths) {
7201
+ const filename = import_path12.default.basename(modulePath);
7202
+ const content = import_fs_extra7.default.readFileSync(modulePath, "utf-8");
7203
+ formData.append(filename, new Blob2([content], {
7204
+ type: "application/javascript+module"
7205
+ }), filename);
7206
+ }
7207
+ for (const sqlFile of sqlFiles) {
7208
+ const filename = import_path12.default.basename(sqlFile);
7209
+ const content = import_fs_extra7.default.readFileSync(sqlFile, "utf-8");
7210
+ formData.append("sql_file", new Blob2([content], {
7211
+ type: "application/sql"
7212
+ }), filename);
7213
+ console.log(import_chalk17.default.gray(` Including SQL: ${filename}`));
7214
+ }
7215
+ const response = await axios_default.put(apiUrl, formData, {
7216
+ headers: { ...headers },
7217
+ timeout: 12e4
7218
+ });
7219
+ console.log(import_chalk17.default.gray(` Response: ${JSON.stringify(response.data)}`));
7220
+ if (response.data) {
7221
+ console.log(import_chalk17.default.green("Worker saved"));
7222
+ if ((_b = (_a = response.data) == null ? void 0 : _a.data) == null ? void 0 : _b.sql_results) {
7223
+ for (const result of response.data.data.sql_results) {
7224
+ console.log(import_chalk17.default.gray(` SQL ${result.filename}: ${result.status}`));
7225
+ }
7226
+ }
7227
+ } else {
7228
+ throw new Error(((_e = (_d = (_c = response.data) == null ? void 0 : _c.errors) == null ? void 0 : _d[0]) == null ? void 0 : _e.message) || "Failed to save worker");
7229
+ }
7230
+ } catch (error) {
7231
+ console.log(import_chalk17.default.red(` Response status: ${(_f = error.response) == null ? void 0 : _f.status}`));
7232
+ console.log(import_chalk17.default.red(` Response data: ${JSON.stringify((_g = error.response) == null ? void 0 : _g.data)}`));
7233
+ const errorMsg = ((_k = (_j = (_i = (_h = error.response) == null ? void 0 : _h.data) == null ? void 0 : _i.errors) == null ? void 0 : _j[0]) == null ? void 0 : _k.message) || ((_m = (_l = error.response) == null ? void 0 : _l.data) == null ? void 0 : _m.error) || error.message || "Failed to save worker";
7234
+ throw new Error(errorMsg);
7235
+ }
7236
+ }
7237
+ function buildFrontend() {
7238
+ console.log(import_chalk17.default.blue("Building frontend..."));
7239
+ try {
7240
+ (0, import_child_process2.execSync)("npm run build:frontend", {
7241
+ cwd: PROJECT_DIR2,
7242
+ stdio: "inherit"
7243
+ });
7244
+ console.log(import_chalk17.default.green("Frontend built"));
7245
+ } catch (error) {
7246
+ throw new Error(`Frontend build failed: ${error.message}`);
7247
+ }
7248
+ }
7249
+ function deployFrontend() {
7250
+ console.log(import_chalk17.default.blue("Deploying frontend to IPFS..."));
7251
+ try {
7252
+ (0, import_child_process2.execSync)("pinme upload ./frontend/dist", {
7253
+ cwd: PROJECT_DIR2,
7254
+ stdio: "inherit"
7255
+ });
7256
+ console.log(import_chalk17.default.green("Frontend deployed to IPFS"));
7257
+ } catch (error) {
7258
+ throw new Error(`Frontend deploy failed: ${error.message}`);
7259
+ }
7260
+ }
7261
+ async function saveCmd(options) {
7262
+ try {
7263
+ const headers = getAuthHeaders();
7264
+ if (!headers["authentication-tokens"] || !headers["token-address"]) {
7265
+ console.log(import_chalk17.default.yellow("\n\u26A0\uFE0F You are not logged in."));
7266
+ console.log(import_chalk17.default.gray("Please run: pinme login"));
7267
+ process.exit(1);
7268
+ }
7269
+ const projectDir = options.projectName || options.name ? import_path12.default.join(PROJECT_DIR2, options.projectName || options.name) : PROJECT_DIR2;
7270
+ const tokenFileSrc = import_path12.default.join(PROJECT_DIR2, ".token.json");
7271
+ const tokenFileDst = import_path12.default.join(projectDir, ".token.json");
7272
+ if (import_fs_extra7.default.existsSync(tokenFileSrc) && !import_fs_extra7.default.existsSync(tokenFileDst)) {
7273
+ import_fs_extra7.default.copySync(tokenFileSrc, tokenFileDst);
7274
+ }
7275
+ console.log(import_chalk17.default.blue("\u{1F680} Deploying to platform...\n"));
7276
+ console.log(import_chalk17.default.gray(`Project dir: ${PROJECT_DIR2}`));
7277
+ const config = loadConfig();
7278
+ const projectName = config.project_name;
7279
+ if (!projectName) {
7280
+ throw new Error("project_name not found in pinme.toml");
7281
+ }
7282
+ console.log(import_chalk17.default.gray(`Project: ${projectName}`));
7283
+ const apiUrl = `${API_BASE2}/save_worker?project_name=${encodeURIComponent(projectName)}`;
7284
+ console.log(import_chalk17.default.gray(`API URL: ${apiUrl}`));
7285
+ console.log(import_chalk17.default.blue("\n--- Backend ---"));
7286
+ installDependencies();
7287
+ buildWorker();
7288
+ const metadata = getMetadata();
7289
+ const { workerJsPath, modulePaths } = getBuiltWorker();
7290
+ console.log(import_chalk17.default.gray(`Worker JS: ${workerJsPath}`));
7291
+ console.log(import_chalk17.default.gray(`Module paths: ${JSON.stringify(modulePaths)}`));
7292
+ const sqlFiles = getSqlFiles();
7293
+ console.log(import_chalk17.default.gray(`SQL files: ${JSON.stringify(sqlFiles)}`));
7294
+ await saveWorker(workerJsPath, modulePaths, sqlFiles, metadata, projectName);
7295
+ console.log(import_chalk17.default.blue("\n--- Frontend ---"));
7296
+ buildFrontend();
7297
+ deployFrontend();
7298
+ console.log(import_chalk17.default.green("\n\u2705 Deployment complete!"));
7299
+ process.exit(0);
7300
+ } catch (error) {
7301
+ console.error(import_chalk17.default.red(`
7302
+ \u274C Error: ${error.message}`));
7303
+ process.exit(1);
7304
+ }
7305
+ }
7306
+
7307
+ // bin/updateDb.ts
7308
+ var import_chalk18 = __toESM(require("chalk"));
7309
+ var import_fs_extra8 = __toESM(require("fs-extra"));
7310
+ var import_path13 = __toESM(require("path"));
7311
+ var PROJECT_DIR3 = process.cwd();
7312
+ var API_BASE3 = "https://pinme.benny1996.win/api/v4";
7313
+ function loadConfig2() {
7314
+ const configPath = import_path13.default.join(PROJECT_DIR3, "pinme.toml");
7315
+ if (!import_fs_extra8.default.existsSync(configPath)) {
7316
+ throw new Error("pinme.toml not found");
7317
+ }
7318
+ const configContent = import_fs_extra8.default.readFileSync(configPath, "utf-8");
7319
+ const projectNameMatch = configContent.match(/project_name\s*=\s*"([^"]+)"/);
7320
+ return {
7321
+ project_name: (projectNameMatch == null ? void 0 : projectNameMatch[1]) || ""
7322
+ };
7323
+ }
7324
+ function getSqlFiles2() {
7325
+ const sqlDir = import_path13.default.join(PROJECT_DIR3, "backend", "schema");
7326
+ if (!import_fs_extra8.default.existsSync(sqlDir)) {
7327
+ throw new Error("SQL directory not found: backend/schema");
7328
+ }
7329
+ const files = import_fs_extra8.default.readdirSync(sqlDir).filter((f) => f.endsWith(".sql")).sort();
7330
+ if (files.length === 0) {
7331
+ throw new Error("No SQL files found in backend/schema");
7332
+ }
7333
+ return files.map((f) => import_path13.default.join(sqlDir, f));
7334
+ }
7335
+ async function updateDb(sqlFiles, projectName) {
7336
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
7337
+ console.log(import_chalk18.default.blue("Importing SQL files to database..."));
7338
+ console.log(import_chalk18.default.gray(`Project: ${projectName}`));
7339
+ console.log(import_chalk18.default.gray(`SQL files: ${sqlFiles.length}`));
7340
+ const apiUrl = `${API_BASE3}/update_db?project_name=${encodeURIComponent(projectName)}`;
7341
+ const headers = getAuthHeaders();
7342
+ console.log(import_chalk18.default.gray(`API URL: ${apiUrl}`));
7343
+ try {
7344
+ const FormData4 = (await import("formdata-node")).FormData;
7345
+ const Blob2 = (await import("formdata-node")).Blob;
7346
+ const formData = new FormData4();
7347
+ let totalSize = 0;
7348
+ for (const sqlFile of sqlFiles) {
7349
+ const filename = import_path13.default.basename(sqlFile);
7350
+ const content = import_fs_extra8.default.readFileSync(sqlFile);
7351
+ totalSize += content.length;
7352
+ if (totalSize > 10 * 1024 * 1024) {
7353
+ throw new Error("Total SQL files size exceeds 10MB limit");
7354
+ }
7355
+ formData.append("file", new Blob2([content], {
7356
+ type: "application/sql"
7357
+ }), filename);
7358
+ console.log(import_chalk18.default.gray(` Including: ${filename} (${content.length} bytes)`));
7359
+ }
7360
+ const response = await axios_default.post(apiUrl, formData, {
7361
+ headers: { ...headers },
7362
+ timeout: 12e4
7363
+ });
7364
+ console.log(import_chalk18.default.gray(` Response: ${JSON.stringify(response.data)}`));
7365
+ if (response.data.code === 200) {
7366
+ console.log(import_chalk18.default.green("SQL files imported successfully!"));
7367
+ const results = response.data.data.results;
7368
+ for (const result of results) {
7369
+ if (result.status === "complete") {
7370
+ console.log(import_chalk18.default.green(` \u2713 ${result.filename}: ${result.num_queries} queries, ${result.duration}ms`));
7371
+ if (result.changes !== void 0) {
7372
+ console.log(import_chalk18.default.gray(` Changes: ${result.changes}, Read: ${result.rows_read}, Written: ${result.rows_written}`));
7373
+ }
7374
+ } else if (result.status === "error") {
7375
+ console.log(import_chalk18.default.red(` \u2717 ${result.filename}: ${result.error}`));
7376
+ }
7377
+ }
7378
+ } else {
7379
+ const errorMsg = response.data.msg || response.data.error || "Failed to import SQL files";
7380
+ throw new Error(errorMsg);
7381
+ }
7382
+ } catch (error) {
7383
+ console.log(import_chalk18.default.red(` Response status: ${(_a = error.response) == null ? void 0 : _a.status}`));
7384
+ console.log(import_chalk18.default.red(` Response data: ${JSON.stringify((_b = error.response) == null ? void 0 : _b.data)}`));
7385
+ const errorMsg = ((_f = (_e = (_d = (_c = error.response) == null ? void 0 : _c.data) == null ? void 0 : _d.errors) == null ? void 0 : _e[0]) == null ? void 0 : _f.message) || ((_h = (_g = error.response) == null ? void 0 : _g.data) == null ? void 0 : _h.error) || ((_j = (_i = error.response) == null ? void 0 : _i.data) == null ? void 0 : _j.msg) || error.message || "Failed to import SQL files";
7386
+ throw new Error(errorMsg);
7387
+ }
7388
+ }
7389
+ async function updateDbCmd(options) {
7390
+ try {
7391
+ const headers = getAuthHeaders();
7392
+ if (!headers["authentication-tokens"] || !headers["token-address"]) {
7393
+ console.log(import_chalk18.default.yellow("\n\u26A0\uFE0F You are not logged in."));
7394
+ console.log(import_chalk18.default.gray("Please run: pinme login"));
7395
+ process.exit(1);
7396
+ }
7397
+ const projectDir = (options == null ? void 0 : options.projectName) || (options == null ? void 0 : options.name) ? import_path13.default.join(PROJECT_DIR3, options.projectName || options.name) : PROJECT_DIR3;
7398
+ const tokenFileSrc = import_path13.default.join(PROJECT_DIR3, ".token.json");
7399
+ const tokenFileDst = import_path13.default.join(projectDir, ".token.json");
7400
+ if (import_fs_extra8.default.existsSync(tokenFileSrc) && !import_fs_extra8.default.existsSync(tokenFileDst)) {
7401
+ import_fs_extra8.default.copySync(tokenFileSrc, tokenFileDst);
7402
+ }
7403
+ console.log(import_chalk18.default.blue("\u{1F680} Importing SQL to database...\n"));
7404
+ console.log(import_chalk18.default.gray(`Project dir: ${PROJECT_DIR3}`));
7405
+ const config = loadConfig2();
7406
+ const projectName = config.project_name;
7407
+ if (!projectName) {
7408
+ throw new Error("project_name not found in pinme.toml");
7409
+ }
7410
+ console.log(import_chalk18.default.gray(`Project: ${projectName}`));
7411
+ const sqlFiles = getSqlFiles2();
7412
+ console.log(import_chalk18.default.gray(`Found ${sqlFiles.length} SQL file(s) in backend/schema`));
7413
+ await updateDb(sqlFiles, projectName);
7414
+ console.log(import_chalk18.default.green("\n\u2705 Database update complete!"));
7415
+ process.exit(0);
7416
+ } catch (error) {
7417
+ console.error(import_chalk18.default.red(`
7418
+ \u274C Error: ${error.message}`));
7419
+ process.exit(1);
7420
+ }
7421
+ }
7422
+
7423
+ // bin/updateWorker.ts
7424
+ var import_chalk19 = __toESM(require("chalk"));
7425
+ var import_fs_extra9 = __toESM(require("fs-extra"));
7426
+ var import_path14 = __toESM(require("path"));
7427
+ var import_child_process3 = require("child_process");
7428
+ var PROJECT_DIR4 = process.cwd();
7429
+ var API_BASE4 = "https://pinme.benny1996.win/api/v4";
7430
+ function loadConfig3() {
7431
+ const configPath = import_path14.default.join(PROJECT_DIR4, "pinme.toml");
7432
+ if (!import_fs_extra9.default.existsSync(configPath)) {
7433
+ throw new Error("pinme.toml not found");
7434
+ }
7435
+ const configContent = import_fs_extra9.default.readFileSync(configPath, "utf-8");
7436
+ const projectNameMatch = configContent.match(/project_name\s*=\s*"([^"]+)"/);
7437
+ return {
7438
+ project_name: (projectNameMatch == null ? void 0 : projectNameMatch[1]) || ""
7439
+ };
7440
+ }
7441
+ function getMetadata2() {
7442
+ const metadataPath = import_path14.default.join(PROJECT_DIR4, "backend", "metadata.json");
7443
+ if (!import_fs_extra9.default.existsSync(metadataPath)) {
7444
+ throw new Error("metadata.json not found in backend directory");
7445
+ }
7446
+ return import_fs_extra9.default.readJsonSync(metadataPath);
7447
+ }
7448
+ function buildWorker2() {
7449
+ console.log(import_chalk19.default.blue("Building worker..."));
7450
+ try {
7451
+ (0, import_child_process3.execSync)("npm run build:worker", {
7452
+ cwd: PROJECT_DIR4,
7453
+ stdio: "inherit"
7454
+ });
7455
+ console.log(import_chalk19.default.green("Worker built"));
7456
+ } catch (error) {
7457
+ throw new Error(`Worker build failed: ${error.message}`);
7458
+ }
7459
+ }
7460
+ function getBuiltWorker2() {
7461
+ const distWorkerDir = import_path14.default.join(PROJECT_DIR4, "dist-worker");
7462
+ if (!import_fs_extra9.default.existsSync(distWorkerDir)) {
7463
+ throw new Error('Dist worker not found. Run "npm run build:worker" first.');
7464
+ }
7465
+ const workerJsPath = import_path14.default.join(distWorkerDir, "worker.js");
7466
+ if (!import_fs_extra9.default.existsSync(workerJsPath)) {
7467
+ throw new Error("worker.js not found in dist-worker");
7468
+ }
7469
+ const modulePaths = [];
7470
+ const files = import_fs_extra9.default.readdirSync(distWorkerDir);
7471
+ for (const file of files) {
7472
+ if (file.endsWith(".js") && file !== "worker.js") {
7473
+ modulePaths.push(import_path14.default.join(distWorkerDir, file));
7474
+ }
7475
+ }
7476
+ return { workerJsPath, modulePaths };
7477
+ }
7478
+ async function updateWorker(workerJsPath, modulePaths, metadata, projectName) {
7479
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
7480
+ console.log(import_chalk19.default.blue("Updating worker on platform..."));
7481
+ console.log(import_chalk19.default.gray(`Project: ${projectName}`));
7482
+ console.log(import_chalk19.default.gray(`workerJsPath: ${workerJsPath}`));
7483
+ console.log(import_chalk19.default.gray(`modulePaths: ${modulePaths}`));
7484
+ console.log(import_chalk19.default.gray(`metadata: ${metadata}`));
7485
+ const apiUrl = `${API_BASE4}/update_worker?project_name=${encodeURIComponent(projectName)}`;
7486
+ const headers = getAuthHeaders();
7487
+ console.log(import_chalk19.default.gray(`API URL: ${apiUrl}`));
7488
+ try {
7489
+ const FormData4 = (await import("formdata-node")).FormData;
7490
+ const Blob2 = (await import("formdata-node")).Blob;
7491
+ const formData = new FormData4();
7492
+ formData.append("metadata", new Blob2([JSON.stringify(metadata)], {
7493
+ type: "application/json"
7494
+ }), "metadata.json");
7495
+ const workerCode = import_fs_extra9.default.readFileSync(workerJsPath, "utf-8");
7496
+ formData.append("worker.js", new Blob2([workerCode], {
7497
+ type: "application/javascript+module"
7498
+ }), "worker.js");
7499
+ for (const modulePath of modulePaths) {
7500
+ const filename = import_path14.default.basename(modulePath);
7501
+ const content = import_fs_extra9.default.readFileSync(modulePath, "utf-8");
7502
+ formData.append(filename, new Blob2([content], {
7503
+ type: "application/javascript+module"
7504
+ }), filename);
7505
+ }
7506
+ const response = await axios_default.put(apiUrl, formData, {
7507
+ headers: { ...headers },
7508
+ timeout: 12e4
7509
+ });
7510
+ console.log(import_chalk19.default.gray(` Response: ${JSON.stringify(response.data)}`));
7511
+ if (response.data) {
7512
+ console.log(import_chalk19.default.green("Worker updated"));
7513
+ const data = response.data.data;
7514
+ if (data.worker_id) {
7515
+ console.log(import_chalk19.default.gray(` Worker ID: ${data.worker_id}`));
7516
+ }
7517
+ if (data.deployment_id) {
7518
+ console.log(import_chalk19.default.gray(` Deployment ID: ${data.deployment_id}`));
7519
+ }
7520
+ if (data.entry_point) {
7521
+ console.log(import_chalk19.default.gray(` Entry Point: ${data.entry_point}`));
7522
+ }
7523
+ if (data.created_on) {
7524
+ console.log(import_chalk19.default.gray(` Created: ${data.created_on}`));
7525
+ }
7526
+ if (data.modified_on) {
7527
+ console.log(import_chalk19.default.gray(` Modified: ${data.modified_on}`));
7528
+ }
7529
+ if (data.startup_time_ms !== void 0) {
7530
+ console.log(import_chalk19.default.gray(` Startup Time: ${data.startup_time_ms}ms`));
7531
+ }
7532
+ if (data.has_modules !== void 0) {
7533
+ console.log(import_chalk19.default.gray(` Has Modules: ${data.has_modules}`));
7534
+ }
7535
+ if (data.domain) {
7536
+ console.log(import_chalk19.default.gray(` Domain: ${data.domain}`));
7537
+ }
7538
+ } else {
7539
+ throw new Error(((_c = (_b = (_a = response.data) == null ? void 0 : _a.errors) == null ? void 0 : _b[0]) == null ? void 0 : _c.message) || "Failed to update worker");
7540
+ }
7541
+ } catch (error) {
7542
+ console.log(import_chalk19.default.red(` Response status: ${(_d = error.response) == null ? void 0 : _d.status}`));
7543
+ console.log(import_chalk19.default.red(` Response data: ${JSON.stringify((_e = error.response) == null ? void 0 : _e.data)}`));
7544
+ const errorMsg = ((_i = (_h = (_g = (_f = error.response) == null ? void 0 : _f.data) == null ? void 0 : _g.errors) == null ? void 0 : _h[0]) == null ? void 0 : _i.message) || ((_k = (_j = error.response) == null ? void 0 : _j.data) == null ? void 0 : _k.error) || error.message || "Failed to update worker";
7545
+ throw new Error(errorMsg);
7546
+ }
7547
+ }
7548
+ async function updateWorkerCmd(options) {
7549
+ try {
7550
+ const headers = getAuthHeaders();
7551
+ if (!headers["authentication-tokens"] || !headers["token-address"]) {
7552
+ console.log(import_chalk19.default.yellow("\n\u26A0\uFE0F You are not logged in."));
7553
+ console.log(import_chalk19.default.gray("Please run: pinme login"));
7554
+ process.exit(1);
7555
+ }
7556
+ const projectDir = (options == null ? void 0 : options.projectName) || (options == null ? void 0 : options.name) ? import_path14.default.join(PROJECT_DIR4, options.projectName || options.name) : PROJECT_DIR4;
7557
+ const tokenFileSrc = import_path14.default.join(PROJECT_DIR4, ".token.json");
7558
+ const tokenFileDst = import_path14.default.join(projectDir, ".token.json");
7559
+ if (import_fs_extra9.default.existsSync(tokenFileSrc) && !import_fs_extra9.default.existsSync(tokenFileDst)) {
7560
+ import_fs_extra9.default.copySync(tokenFileSrc, tokenFileDst);
7561
+ }
7562
+ console.log(import_chalk19.default.blue("\u{1F680} Updating worker...\n"));
7563
+ console.log(import_chalk19.default.gray(`Project dir: ${PROJECT_DIR4}`));
7564
+ const config = loadConfig3();
7565
+ const projectName = config.project_name;
7566
+ if (!projectName) {
7567
+ throw new Error("project_name not found in pinme.toml");
7568
+ }
7569
+ console.log(import_chalk19.default.gray(`Project: ${projectName}`));
7570
+ console.log(import_chalk19.default.blue("\n--- Worker Update ---"));
7571
+ buildWorker2();
7572
+ const metadata = getMetadata2();
7573
+ const { workerJsPath, modulePaths } = getBuiltWorker2();
7574
+ console.log(import_chalk19.default.gray(`Worker JS: ${workerJsPath}`));
7575
+ console.log(import_chalk19.default.gray(`Module paths: ${JSON.stringify(modulePaths)}`));
7576
+ console.log(import_chalk19.default.gray(`SQL files: ignored (not processed for update_worker)`));
7577
+ await updateWorker(workerJsPath, modulePaths, metadata, projectName);
7578
+ console.log(import_chalk19.default.green("\n\u2705 Worker update complete!"));
7579
+ process.exit(0);
7580
+ } catch (error) {
7581
+ console.error(import_chalk19.default.red(`
7582
+ \u274C Error: ${error.message}`));
7583
+ process.exit(1);
7584
+ }
7585
+ }
7586
+
7587
+ // bin/updateWeb.ts
7588
+ var import_chalk20 = __toESM(require("chalk"));
7589
+ var import_fs_extra10 = __toESM(require("fs-extra"));
7590
+ var import_path15 = __toESM(require("path"));
7591
+ var import_child_process4 = require("child_process");
7592
+ var PROJECT_DIR5 = process.cwd();
7593
+ function loadConfig4() {
7594
+ const configPath = import_path15.default.join(PROJECT_DIR5, "pinme.toml");
7595
+ if (!import_fs_extra10.default.existsSync(configPath)) {
7596
+ throw new Error("pinme.toml not found");
7597
+ }
7598
+ const configContent = import_fs_extra10.default.readFileSync(configPath, "utf-8");
7599
+ const projectNameMatch = configContent.match(/project_name\s*=\s*"([^"]+)"/);
7600
+ return {
7601
+ project_name: (projectNameMatch == null ? void 0 : projectNameMatch[1]) || ""
7602
+ };
7603
+ }
7604
+ function buildFrontend2() {
7605
+ console.log(import_chalk20.default.blue("Building frontend..."));
7606
+ try {
7607
+ (0, import_child_process4.execSync)("npm run build:frontend", {
7608
+ cwd: PROJECT_DIR5,
7609
+ stdio: "inherit"
7610
+ });
7611
+ console.log(import_chalk20.default.green("Frontend built"));
7612
+ } catch (error) {
7613
+ throw new Error(`Frontend build failed: ${error.message}`);
7614
+ }
7615
+ }
7616
+ function deployFrontend2() {
7617
+ console.log(import_chalk20.default.blue("Deploying frontend to IPFS..."));
7618
+ try {
7619
+ (0, import_child_process4.execSync)("pinme upload ./frontend/dist", {
7620
+ cwd: PROJECT_DIR5,
7621
+ stdio: "inherit"
7622
+ });
7623
+ console.log(import_chalk20.default.green("Frontend deployed to IPFS"));
7624
+ } catch (error) {
7625
+ throw new Error(`Frontend deploy failed: ${error.message}`);
7626
+ }
7627
+ }
7628
+ async function updateWebCmd(options) {
7629
+ try {
7630
+ const headers = getAuthHeaders();
7631
+ if (!headers["authentication-tokens"] || !headers["token-address"]) {
7632
+ console.log(import_chalk20.default.yellow("\n\u26A0\uFE0F You are not logged in."));
7633
+ console.log(import_chalk20.default.gray("Please run: pinme login"));
7634
+ process.exit(1);
7635
+ }
7636
+ const projectDir = (options == null ? void 0 : options.projectName) || (options == null ? void 0 : options.name) ? import_path15.default.join(PROJECT_DIR5, options.projectName || options.name) : PROJECT_DIR5;
7637
+ const tokenFileSrc = import_path15.default.join(PROJECT_DIR5, ".token.json");
7638
+ const tokenFileDst = import_path15.default.join(projectDir, ".token.json");
7639
+ if (import_fs_extra10.default.existsSync(tokenFileSrc) && !import_fs_extra10.default.existsSync(tokenFileDst)) {
7640
+ import_fs_extra10.default.copySync(tokenFileSrc, tokenFileDst);
7641
+ }
7642
+ console.log(import_chalk20.default.blue("\u{1F680} Updating web (frontend)...\n"));
7643
+ console.log(import_chalk20.default.gray(`Project dir: ${PROJECT_DIR5}`));
7644
+ const config = loadConfig4();
7645
+ const projectName = config.project_name;
7646
+ if (!projectName) {
7647
+ throw new Error("project_name not found in pinme.toml");
7648
+ }
7649
+ console.log(import_chalk20.default.gray(`Project: ${projectName}`));
7650
+ console.log(import_chalk20.default.blue("\n--- Frontend Update ---"));
7651
+ buildFrontend2();
7652
+ deployFrontend2();
7653
+ console.log(import_chalk20.default.green("\n\u2705 Web update complete!"));
7654
+ process.exit(0);
7655
+ } catch (error) {
7656
+ console.error(import_chalk20.default.red(`
7657
+ \u274C Error: ${error.message}`));
7658
+ process.exit(1);
6603
7659
  }
6604
7660
  }
6605
7661
 
@@ -6608,9 +7664,9 @@ import_dotenv.default.config();
6608
7664
  checkNodeVersion();
6609
7665
  function showBanner() {
6610
7666
  console.log(
6611
- import_chalk14.default.cyan(import_figlet5.default.textSync("Pinme", { horizontalLayout: "full" }))
7667
+ import_chalk21.default.cyan(import_figlet5.default.textSync("Pinme", { horizontalLayout: "full" }))
6612
7668
  );
6613
- console.log(import_chalk14.default.cyan("A command-line tool for uploading files to IPFS\n"));
7669
+ console.log(import_chalk21.default.cyan("A command-line tool for uploading files to IPFS\n"));
6614
7670
  }
6615
7671
  var program = new import_commander.Command();
6616
7672
  program.name("pinme").version(version).option("-v, --version", "output the current version");
@@ -6620,13 +7676,19 @@ program.command("upload").description(
6620
7676
  program.command("import").description("import a CAR file to IPFS. Supports --domain to bind after import").option("-d, --domain <name>", "Pinme subdomain").action(() => importCar_default());
6621
7677
  program.command("export").description("export IPFS content as CAR file").option("-o, --output <path>", "output file path for CAR file").action(() => exportCar_default());
6622
7678
  program.command("rm").description("remove a file from IPFS network").action(() => remove_default());
7679
+ program.command("login").description("Login via browser (opens web login page)").option("-e, --env <env>", "Environment: test, prod").action((options) => loginCmd(options));
6623
7680
  program.command("set-appkey").description(
6624
- "Set AppKey for authentication, and auto-merge anonymous history"
7681
+ "Set AppKey for authentication (alternative to login command)"
6625
7682
  ).action(() => setAppKeyCmd());
6626
7683
  program.command("logout").description("log out and clear authentication").action(() => logoutCmd());
6627
7684
  program.command("show-appkey").alias("appkey").description("show current AppKey information (masked)").action(() => showAppKeyCmd());
6628
7685
  program.command("my-domains").alias("domain").description("List domains owned by current account").action(() => myDomainsCmd());
6629
7686
  program.command("bind").description("Upload and bind to a domain (requires VIP)").option("-d, --domain <name>", "Domain name to bind").option("--dns", "Force DNS domain mode").action(() => bindCmd());
7687
+ program.command("create").description("Create a new project from template").argument("[name]", "Project name").option("-f, --force", "Overwrite if exists").action((name, options) => createCmd({ name, force: options == null ? void 0 : options.force }));
7688
+ program.command("save").description("Deploy the project (frontend + backend)").action((options) => saveCmd(options));
7689
+ program.command("update-db").description("Execute database migration").action(() => updateDbCmd());
7690
+ program.command("update-worker").description("Execute worker migration").action(() => updateWorkerCmd());
7691
+ program.command("update-web").description("Deploy frontend to IPFS").action((options) => updateWebCmd(options));
6630
7692
  program.command("domain").description("Alias for 'my-domains' command").action(() => myDomainsCmd());
6631
7693
  program.command("list").description("show upload history").option(
6632
7694
  "-l, --limit <number>",
@@ -6663,6 +7725,7 @@ program.on("--help", () => {
6663
7725
  console.log(" $ pinme import <path> --domain <name>");
6664
7726
  console.log(" $ pinme export <cid> --output <path>");
6665
7727
  console.log(" $ pinme rm <hash>");
7728
+ console.log(" $ pinme login");
6666
7729
  console.log(" $ pinme set-appkey <AppKey>");
6667
7730
  console.log(" $ pinme show-appkey");
6668
7731
  console.log(" $ pinme logout");