pinme 2.0.2 → 2.0.4-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +148 -72
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5587,6 +5587,59 @@ var init_apiClient = __esm({
5587
5587
  }
5588
5588
  });
5589
5589
 
5590
+ // bin/utils/domainValidator.ts
5591
+ function normalizeDomain(domain) {
5592
+ return domain.replace(/^https?:\/\//, "").replace(/\/$/, "");
5593
+ }
5594
+ function isDnsDomain(domain) {
5595
+ return normalizeDomain(domain).includes(".");
5596
+ }
5597
+ function validateDnsDomain(domain) {
5598
+ const cleanDomain = normalizeDomain(domain);
5599
+ const domainRegex = /^[a-zA-Z0-9][a-zA-Z0-9-]*(\.[a-zA-Z0-9][a-zA-Z0-9-]*)*\.[a-zA-Z]{2,}$/;
5600
+ const parts = cleanDomain.split(".");
5601
+ if (parts.length < 2) {
5602
+ return {
5603
+ valid: false,
5604
+ message: "Invalid domain format. Please enter a complete domain (e.g., example.com)"
5605
+ };
5606
+ }
5607
+ for (const part of parts) {
5608
+ if (part.length === 0) {
5609
+ return {
5610
+ valid: false,
5611
+ message: "Invalid domain format. Consecutive dots are not allowed"
5612
+ };
5613
+ }
5614
+ if (part.length > 63) {
5615
+ return {
5616
+ valid: false,
5617
+ message: "Invalid domain format. Each label must be 63 characters or less"
5618
+ };
5619
+ }
5620
+ if (!/^[a-zA-Z0-9-]+$/.test(part)) {
5621
+ return {
5622
+ valid: false,
5623
+ message: "Invalid domain format. Domains can only contain letters, numbers, and hyphens"
5624
+ };
5625
+ }
5626
+ if (/^-|-$/.test(part)) {
5627
+ return {
5628
+ valid: false,
5629
+ message: "Invalid domain format. Labels cannot start or end with hyphens"
5630
+ };
5631
+ }
5632
+ }
5633
+ if (!domainRegex.test(cleanDomain)) {
5634
+ return { valid: false, message: "Invalid domain format" };
5635
+ }
5636
+ return { valid: true };
5637
+ }
5638
+ var init_domainValidator = __esm({
5639
+ "bin/utils/domainValidator.ts"() {
5640
+ }
5641
+ });
5642
+
5590
5643
  // bin/utils/pinmeApi.ts
5591
5644
  var pinmeApi_exports = {};
5592
5645
  __export(pinmeApi_exports, {
@@ -5654,9 +5707,13 @@ async function getRootDomain(forceRefresh = false) {
5654
5707
  }
5655
5708
  async function checkDomainAvailable(domainName) {
5656
5709
  var _a2, _b;
5710
+ if (isDnsDomain(domainName))
5711
+ return await {
5712
+ is_valid: true
5713
+ };
5657
5714
  const client = createPinmeApiClient();
5658
5715
  const configured = APP_CONFIG.pinmeCheckDomainPath;
5659
- const fallbacks = [configured, "/check_domain_available"];
5716
+ const fallbacks = [configured];
5660
5717
  let lastRecoverableError;
5661
5718
  for (const p of fallbacks) {
5662
5719
  try {
@@ -5850,6 +5907,7 @@ var init_pinmeApi = __esm({
5850
5907
  import_chalk4 = __toESM(require("chalk"));
5851
5908
  init_apiClient();
5852
5909
  init_config();
5910
+ init_domainValidator();
5853
5911
  TOKEN_EXPIRED_CODES = [
5854
5912
  401,
5855
5913
  403,
@@ -5919,7 +5977,7 @@ var import_chalk26 = __toESM(require("chalk"));
5919
5977
  var import_figlet5 = __toESM(require("figlet"));
5920
5978
 
5921
5979
  // package.json
5922
- var version = "2.0.2";
5980
+ var version = "2.0.4-beta.1";
5923
5981
 
5924
5982
  // bin/upload.ts
5925
5983
  var import_path6 = __toESM(require("path"));
@@ -5930,57 +5988,7 @@ var import_fs2 = __toESM(require("fs"));
5930
5988
  init_pinmeApi();
5931
5989
  init_webLogin();
5932
5990
  init_config();
5933
-
5934
- // bin/utils/domainValidator.ts
5935
- function normalizeDomain(domain) {
5936
- return domain.replace(/^https?:\/\//, "").replace(/\/$/, "");
5937
- }
5938
- function isDnsDomain(domain) {
5939
- return normalizeDomain(domain).includes(".");
5940
- }
5941
- function validateDnsDomain(domain) {
5942
- const cleanDomain = normalizeDomain(domain);
5943
- const domainRegex = /^[a-zA-Z0-9][a-zA-Z0-9-]*(\.[a-zA-Z0-9][a-zA-Z0-9-]*)*\.[a-zA-Z]{2,}$/;
5944
- const parts = cleanDomain.split(".");
5945
- if (parts.length < 2) {
5946
- return {
5947
- valid: false,
5948
- message: "Invalid domain format. Please enter a complete domain (e.g., example.com)"
5949
- };
5950
- }
5951
- for (const part of parts) {
5952
- if (part.length === 0) {
5953
- return {
5954
- valid: false,
5955
- message: "Invalid domain format. Consecutive dots are not allowed"
5956
- };
5957
- }
5958
- if (part.length > 63) {
5959
- return {
5960
- valid: false,
5961
- message: "Invalid domain format. Each label must be 63 characters or less"
5962
- };
5963
- }
5964
- if (!/^[a-zA-Z0-9-]+$/.test(part)) {
5965
- return {
5966
- valid: false,
5967
- message: "Invalid domain format. Domains can only contain letters, numbers, and hyphens"
5968
- };
5969
- }
5970
- if (/^-|-$/.test(part)) {
5971
- return {
5972
- valid: false,
5973
- message: "Invalid domain format. Labels cannot start or end with hyphens"
5974
- };
5975
- }
5976
- }
5977
- if (!domainRegex.test(cleanDomain)) {
5978
- return { valid: false, message: "Invalid domain format" };
5979
- }
5980
- return { valid: true };
5981
- }
5982
-
5983
- // bin/upload.ts
5991
+ init_domainValidator();
5984
5992
  init_cliError();
5985
5993
 
5986
5994
  // bin/services/uploadService.ts
@@ -7385,7 +7393,11 @@ var importCar_default = async (options) => {
7385
7393
  if (domainArg) {
7386
7394
  const check = await checkDomainAvailable(domainArg);
7387
7395
  if (!check.is_valid) {
7388
- console.log(import_chalk8.default.red(`Domain not available: ${check.error || "unknown reason"}`));
7396
+ console.log(
7397
+ import_chalk8.default.red(
7398
+ `Domain not available: ${check.error || "unknown reason"}`
7399
+ )
7400
+ );
7389
7401
  return;
7390
7402
  }
7391
7403
  console.log(import_chalk8.default.green(`Domain available: ${domainArg}`));
@@ -7398,7 +7410,11 @@ var importCar_default = async (options) => {
7398
7410
  });
7399
7411
  if (result) {
7400
7412
  const uid = getUid2();
7401
- const encryptedCID = encryptHash2(result.contentHash, APP_CONFIG.secretKey, uid);
7413
+ const encryptedCID = encryptHash2(
7414
+ result.contentHash,
7415
+ APP_CONFIG.secretKey,
7416
+ uid
7417
+ );
7402
7418
  console.log(
7403
7419
  import_chalk8.default.cyan(
7404
7420
  import_figlet2.default.textSync("Successful", { horizontalLayout: "full" })
@@ -7410,12 +7426,20 @@ var importCar_default = async (options) => {
7410
7426
  "primary"
7411
7427
  );
7412
7428
  if (domainArg) {
7413
- console.log(import_chalk8.default.blue(`Binding domain: ${domainArg} with CID: ${result.contentHash}`));
7429
+ console.log(
7430
+ import_chalk8.default.blue(
7431
+ `Binding domain: ${domainArg} with CID: ${result.contentHash}`
7432
+ )
7433
+ );
7414
7434
  const ok = await bindPinmeDomain(domainArg, result.contentHash);
7415
7435
  if (ok) {
7416
7436
  console.log(import_chalk8.default.green(`Bind success: ${domainArg}`));
7417
7437
  const rootDomain = await getRootDomain();
7418
- console.log(import_chalk8.default.white(`Visit (Pinme subdomain example): https://${domainArg}.${rootDomain}`));
7438
+ console.log(
7439
+ import_chalk8.default.white(
7440
+ `Visit (Pinme subdomain example): https://${domainArg}.${rootDomain}`
7441
+ )
7442
+ );
7419
7443
  } else {
7420
7444
  console.log(import_chalk8.default.red("Binding failed. Please try again later."));
7421
7445
  }
@@ -7443,7 +7467,11 @@ var importCar_default = async (options) => {
7443
7467
  if (domainArg) {
7444
7468
  const check = await checkDomainAvailable(domainArg);
7445
7469
  if (!check.is_valid) {
7446
- console.log(import_chalk8.default.red(`Domain not available: ${check.error || "unknown reason"}`));
7470
+ console.log(
7471
+ import_chalk8.default.red(
7472
+ `Domain not available: ${check.error || "unknown reason"}`
7473
+ )
7474
+ );
7447
7475
  return;
7448
7476
  }
7449
7477
  console.log(import_chalk8.default.green(`Domain available: ${domainArg}`));
@@ -7456,7 +7484,11 @@ var importCar_default = async (options) => {
7456
7484
  });
7457
7485
  if (result) {
7458
7486
  const uid = getUid2();
7459
- const encryptedCID = encryptHash2(result.contentHash, APP_CONFIG.secretKey, uid);
7487
+ const encryptedCID = encryptHash2(
7488
+ result.contentHash,
7489
+ APP_CONFIG.secretKey,
7490
+ uid
7491
+ );
7460
7492
  console.log(
7461
7493
  import_chalk8.default.cyan(
7462
7494
  import_figlet2.default.textSync("Successful", { horizontalLayout: "full" })
@@ -7468,12 +7500,20 @@ var importCar_default = async (options) => {
7468
7500
  "primary"
7469
7501
  );
7470
7502
  if (domainArg) {
7471
- console.log(import_chalk8.default.blue(`Binding domain: ${domainArg} with CID: ${result.contentHash}`));
7503
+ console.log(
7504
+ import_chalk8.default.blue(
7505
+ `Binding domain: ${domainArg} with CID: ${result.contentHash}`
7506
+ )
7507
+ );
7472
7508
  const ok = await bindPinmeDomain(domainArg, result.contentHash);
7473
7509
  if (ok) {
7474
7510
  console.log(import_chalk8.default.green(`Bind success: ${domainArg}`));
7475
7511
  const rootDomain = await getRootDomain();
7476
- console.log(import_chalk8.default.white(`Visit (Pinme subdomain example): https://${domainArg}.${rootDomain}`));
7512
+ console.log(
7513
+ import_chalk8.default.white(
7514
+ `Visit (Pinme subdomain example): https://${domainArg}.${rootDomain}`
7515
+ )
7516
+ );
7477
7517
  } else {
7478
7518
  console.log(import_chalk8.default.red("Binding failed. Please try again later."));
7479
7519
  }
@@ -8092,6 +8132,7 @@ init_pinmeApi();
8092
8132
  init_cliError();
8093
8133
  init_config();
8094
8134
  init_webLogin();
8135
+ init_domainValidator();
8095
8136
  function parseArgs() {
8096
8137
  const args = process.argv.slice(2);
8097
8138
  const res = {};
@@ -8114,12 +8155,17 @@ async function checkWalletBalanceStatus2(authConfig) {
8114
8155
  var _a2;
8115
8156
  console.log(import_chalk17.default.blue("Checking wallet balance..."));
8116
8157
  try {
8117
- const balanceResult = await getWalletBalance(authConfig.address, authConfig.token);
8158
+ const balanceResult = await getWalletBalance(
8159
+ authConfig.address,
8160
+ authConfig.token
8161
+ );
8118
8162
  const balance = Number(((_a2 = balanceResult.data) == null ? void 0 : _a2.wallet_balance_usd) ?? 0);
8119
8163
  if (!Number.isFinite(balance) || balance <= 0) {
8120
8164
  return false;
8121
8165
  }
8122
- console.log(import_chalk17.default.green(`Wallet balance available: $${balance.toFixed(2)}`));
8166
+ console.log(
8167
+ import_chalk17.default.green(`Wallet balance available: $${balance.toFixed(2)}`)
8168
+ );
8123
8169
  return true;
8124
8170
  } catch (e) {
8125
8171
  if (e.message === "Token expired" || (e == null ? void 0 : e.name) === "CliError") {
@@ -8135,23 +8181,35 @@ async function bindCmd() {
8135
8181
  let { domain, targetPath, dns } = parseArgs();
8136
8182
  const authConfig = getAuthConfig();
8137
8183
  if (!authConfig) {
8138
- console.log(import_chalk17.default.red("Please login first. Run: pinme set-appkey <AppKey>"));
8184
+ console.log(
8185
+ import_chalk17.default.red("Please login first. Run: pinme set-appkey <AppKey>")
8186
+ );
8139
8187
  return;
8140
8188
  }
8141
8189
  if (!targetPath) {
8142
8190
  const ans = await import_inquirer7.default.prompt([
8143
- { type: "input", name: "path", message: "Enter the path to upload and bind: " }
8191
+ {
8192
+ type: "input",
8193
+ name: "path",
8194
+ message: "Enter the path to upload and bind: "
8195
+ }
8144
8196
  ]);
8145
8197
  targetPath = ans.path;
8146
8198
  }
8147
8199
  if (!domain) {
8148
8200
  const ans = await import_inquirer7.default.prompt([
8149
- { type: "input", name: "domain", message: "Enter the domain to bind (e.g., my-site or example.com): " }
8201
+ {
8202
+ type: "input",
8203
+ name: "domain",
8204
+ message: "Enter the domain to bind (e.g., my-site or example.com): "
8205
+ }
8150
8206
  ]);
8151
8207
  domain = (_a2 = ans.domain) == null ? void 0 : _a2.trim();
8152
8208
  }
8153
8209
  if (!targetPath || !domain) {
8154
- console.log(import_chalk17.default.red("Missing parameters. Path and domain are required."));
8210
+ console.log(
8211
+ import_chalk17.default.red("Missing parameters. Path and domain are required.")
8212
+ );
8155
8213
  return;
8156
8214
  }
8157
8215
  const isDns = dns || isDnsDomain(domain);
@@ -8166,7 +8224,11 @@ async function bindCmd() {
8166
8224
  try {
8167
8225
  const hasWalletBalance = await checkWalletBalanceStatus2(authConfig);
8168
8226
  if (!hasWalletBalance) {
8169
- console.log(import_chalk17.default.red("Insufficient wallet balance. Please recharge your wallet first."));
8227
+ console.log(
8228
+ import_chalk17.default.red(
8229
+ "Insufficient wallet balance. Please recharge your wallet first."
8230
+ )
8231
+ );
8170
8232
  printRechargeUrl(getWalletRechargeUrl());
8171
8233
  return;
8172
8234
  }
@@ -8179,7 +8241,9 @@ async function bindCmd() {
8179
8241
  try {
8180
8242
  const check = await checkDomainAvailable(displayDomain);
8181
8243
  if (!check.is_valid) {
8182
- console.log(import_chalk17.default.red(`Domain not available: ${check.error || "unknown reason"}`));
8244
+ console.log(
8245
+ import_chalk17.default.red(`Domain not available: ${check.error || "unknown reason"}`)
8246
+ );
8183
8247
  return;
8184
8248
  }
8185
8249
  console.log(import_chalk17.default.green(`Domain available: ${displayDomain}`));
@@ -8200,14 +8264,23 @@ async function bindCmd() {
8200
8264
  try {
8201
8265
  if (isDns) {
8202
8266
  console.log(import_chalk17.default.blue("Binding DNS domain..."));
8203
- const dnsResult = await bindDnsDomainV4(displayDomain, up.contentHash, authConfig.address, authConfig.token);
8267
+ const dnsResult = await bindDnsDomainV4(
8268
+ displayDomain,
8269
+ up.contentHash,
8270
+ authConfig.address,
8271
+ authConfig.token
8272
+ );
8204
8273
  if (dnsResult.code !== 200) {
8205
8274
  console.log(import_chalk17.default.red(`DNS binding failed: ${dnsResult.msg}`));
8206
8275
  return;
8207
8276
  }
8208
8277
  console.log(import_chalk17.default.green(`DNS bind success: ${displayDomain}`));
8209
8278
  console.log(import_chalk17.default.white(`Visit: https://${displayDomain}`));
8210
- console.log(import_chalk17.default.cyan("\n\u{1F4DA} DNS Setup Guide: https://pinme.eth.limo/#/docs?id=custom-domain"));
8279
+ console.log(
8280
+ import_chalk17.default.cyan(
8281
+ "\n\u{1F4DA} DNS Setup Guide: https://pinme.eth.limo/#/docs?id=custom-domain"
8282
+ )
8283
+ );
8211
8284
  } else {
8212
8285
  console.log(import_chalk17.default.blue("Binding Pinme subdomain..."));
8213
8286
  const ok = await bindPinmeDomain(displayDomain, up.contentHash);
@@ -8217,7 +8290,9 @@ async function bindCmd() {
8217
8290
  }
8218
8291
  console.log(import_chalk17.default.green(`Bind success: ${displayDomain}`));
8219
8292
  const rootDomain = await getRootDomain();
8220
- console.log(import_chalk17.default.white(`Visit: https://${displayDomain}.${rootDomain}`));
8293
+ console.log(
8294
+ import_chalk17.default.white(`Visit: https://${displayDomain}.${rootDomain}`)
8295
+ );
8221
8296
  }
8222
8297
  } catch (e) {
8223
8298
  if (e.message === "Token expired") {
@@ -8780,6 +8855,7 @@ init_axios2();
8780
8855
  var import_child_process4 = require("child_process");
8781
8856
  init_webLogin();
8782
8857
  init_pinmeApi();
8858
+ init_domainValidator();
8783
8859
  init_cliError();
8784
8860
  init_config();
8785
8861
  var PROJECT_DIR2 = process.cwd();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinme",
3
- "version": "2.0.2",
3
+ "version": "2.0.4-beta.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },