pinme 2.0.2-beta.6 → 2.0.2-beta.8

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 +112 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1523,7 +1523,7 @@ var import_chalk25 = __toESM(require("chalk"));
1523
1523
  var import_figlet5 = __toESM(require("figlet"));
1524
1524
 
1525
1525
  // package.json
1526
- var version = "2.0.2-beta.6";
1526
+ var version = "2.0.2-beta.8";
1527
1527
 
1528
1528
  // bin/upload.ts
1529
1529
  var import_path6 = __toESM(require("path"));
@@ -5069,12 +5069,13 @@ async function checkDomainAvailable(domainName) {
5069
5069
  }
5070
5070
  return { is_valid: true };
5071
5071
  }
5072
- async function bindPinmeDomain(domainName, hash) {
5072
+ async function bindPinmeDomain(domainName, hash, projectName) {
5073
5073
  try {
5074
5074
  const client = createPinmeApiClient();
5075
5075
  const { data } = await client.post("/bind_pinme_domain", {
5076
5076
  domain_name: domainName,
5077
- hash
5077
+ hash,
5078
+ ...projectName ? { project_name: projectName } : {}
5078
5079
  });
5079
5080
  return (data == null ? void 0 : data.code) === 200;
5080
5081
  } catch (e) {
@@ -5111,14 +5112,15 @@ async function getMyDomains() {
5111
5112
  throw e;
5112
5113
  }
5113
5114
  }
5114
- async function bindDnsDomainV4(domainName, hash, tokenAddress, authToken) {
5115
+ async function bindDnsDomainV4(domainName, hash, tokenAddress, authToken, projectName) {
5115
5116
  try {
5116
5117
  const client = createPinmeApiClient();
5117
5118
  const { data } = await client.post(
5118
5119
  "/bind_dns",
5119
5120
  {
5120
5121
  domain_name: domainName,
5121
- hash
5122
+ hash,
5123
+ ...projectName ? { project_name: projectName } : {}
5122
5124
  },
5123
5125
  {
5124
5126
  headers: {
@@ -5439,6 +5441,47 @@ var POLL_INTERVAL = APP_CONFIG.upload.pollIntervalMs;
5439
5441
  var PROGRESS_UPDATE_INTERVAL = 200;
5440
5442
  var EXPECTED_UPLOAD_TIME = 6e4;
5441
5443
  var MAX_PROGRESS = 0.9;
5444
+ function extractAxiosErrorMessage(error) {
5445
+ var _a2, _b, _c, _d;
5446
+ const responseData = (_a2 = error == null ? void 0 : error.response) == null ? void 0 : _a2.data;
5447
+ if (typeof responseData === "string" && responseData.trim()) {
5448
+ return responseData.trim();
5449
+ }
5450
+ const message = (responseData == null ? void 0 : responseData.msg) || (responseData == null ? void 0 : responseData.message) || (responseData == null ? void 0 : responseData.error) || ((_b = responseData == null ? void 0 : responseData.data) == null ? void 0 : _b.msg) || ((_c = responseData == null ? void 0 : responseData.data) == null ? void 0 : _c.message) || ((_d = responseData == null ? void 0 : responseData.data) == null ? void 0 : _d.error);
5451
+ if (typeof message === "string" && message.trim()) {
5452
+ return message.trim();
5453
+ }
5454
+ return (error == null ? void 0 : error.message) || "Unknown network error";
5455
+ }
5456
+ function formatAxiosError(prefix, error) {
5457
+ var _a2;
5458
+ const status = (_a2 = error == null ? void 0 : error.response) == null ? void 0 : _a2.status;
5459
+ const message = extractAxiosErrorMessage(error);
5460
+ if (status) {
5461
+ return new Error(`${prefix}: ${message} (status: ${status})`);
5462
+ }
5463
+ return new Error(`${prefix}: ${message}`);
5464
+ }
5465
+ function logAxiosErrorDetails(prefix, error) {
5466
+ var _a2, _b;
5467
+ const status = (_a2 = error == null ? void 0 : error.response) == null ? void 0 : _a2.status;
5468
+ const responseData = (_b = error == null ? void 0 : error.response) == null ? void 0 : _b.data;
5469
+ console.error(`[pinme upload] ${prefix}`);
5470
+ console.error(`[pinme upload] status: ${status ?? "unknown"}`);
5471
+ if (responseData === void 0) {
5472
+ console.error("[pinme upload] response: <empty>");
5473
+ return;
5474
+ }
5475
+ try {
5476
+ console.error(`[pinme upload] response: ${JSON.stringify(responseData)}`);
5477
+ } catch {
5478
+ console.error(`[pinme upload] response: ${String(responseData)}`);
5479
+ }
5480
+ }
5481
+ function isStorageLimitError(error) {
5482
+ const message = extractAxiosErrorMessage(error).toLowerCase();
5483
+ return message.includes("storage space limit") || message.includes("space limit reached") || message.includes("storage limit reached") || message.includes("quota exceeded") || message.includes("insufficient storage");
5484
+ }
5442
5485
  var StepProgressBar = class {
5443
5486
  spinner;
5444
5487
  fileName;
@@ -5615,7 +5658,8 @@ async function initChunkSession(filePath, deviceId, options = {}, isDirectory =
5615
5658
  throw new Error(`Session initialization failed: ${msg} (code: ${code})`);
5616
5659
  } catch (error) {
5617
5660
  if (axios_default.isAxiosError(error)) {
5618
- throw new Error(`Network error: ${error.message}`);
5661
+ logAxiosErrorDetails("chunk/init failed", error);
5662
+ throw formatAxiosError("Session initialization failed", error);
5619
5663
  }
5620
5664
  throw error;
5621
5665
  }
@@ -5651,6 +5695,10 @@ async function uploadChunkWithAbort(sessionId, chunkIndex, chunkData, deviceId,
5651
5695
  if (error.name === "CanceledError" || signal.aborted) {
5652
5696
  throw new Error("Request cancelled");
5653
5697
  }
5698
+ if (axios_default.isAxiosError(error) && isStorageLimitError(error)) {
5699
+ logAxiosErrorDetails("chunk/upload failed", error);
5700
+ throw formatAxiosError("Chunk upload failed", error);
5701
+ }
5654
5702
  if (retryCount < MAX_RETRIES) {
5655
5703
  await delayWithAbortCheck(RETRY_DELAY, signal);
5656
5704
  return uploadChunkWithAbort(
@@ -5662,6 +5710,10 @@ async function uploadChunkWithAbort(sessionId, chunkIndex, chunkData, deviceId,
5662
5710
  retryCount + 1
5663
5711
  );
5664
5712
  }
5713
+ if (axios_default.isAxiosError(error)) {
5714
+ logAxiosErrorDetails("chunk/upload failed", error);
5715
+ throw formatAxiosError("Chunk upload failed", error);
5716
+ }
5665
5717
  throw new Error(
5666
5718
  `Chunk ${chunkIndex + 1} upload failed after ${MAX_RETRIES} retries: ${error.message}`
5667
5719
  );
@@ -5773,7 +5825,8 @@ async function completeChunkUpload(sessionId, deviceId, options = {}) {
5773
5825
  throw new Error(`Complete upload failed: ${msg} (code: ${code})`);
5774
5826
  } catch (error) {
5775
5827
  if (axios_default.isAxiosError(error)) {
5776
- throw new Error(`Network error: ${error.message}`);
5828
+ logAxiosErrorDetails("chunk/complete failed", error);
5829
+ throw formatAxiosError("Complete upload failed", error);
5777
5830
  }
5778
5831
  throw error;
5779
5832
  }
@@ -5803,7 +5856,8 @@ async function getChunkStatus(sessionId, deviceId, options = {}) {
5803
5856
  throw new Error(`Server returned error: ${msg} (code: ${code})`);
5804
5857
  } catch (error) {
5805
5858
  if (axios_default.isAxiosError(error)) {
5806
- throw new Error(`Network error: ${error.message}`);
5859
+ logAxiosErrorDetails("up_status failed", error);
5860
+ throw formatAxiosError("Upload status check failed", error);
5807
5861
  }
5808
5862
  throw error;
5809
5863
  }
@@ -8108,12 +8162,51 @@ async function deployFrontend(projectName) {
8108
8162
  console.log(import_chalk20.default.green(`Frontend deployed to IPFS: ${uploadResult.publicUrl}`));
8109
8163
  updateFrontendUrlInConfig2(import_path12.default.join(PROJECT_DIR2, "pinme.toml"), uploadResult.publicUrl);
8110
8164
  console.log(import_chalk20.default.green("Updated pinme.toml with frontend URL"));
8165
+ return {
8166
+ contentHash: uploadResult.contentHash,
8167
+ publicUrl: uploadResult.publicUrl
8168
+ };
8111
8169
  } catch (error) {
8112
8170
  throw createCommandError("frontend deploy", "upload frontend/dist", error, [
8113
8171
  "Make sure `frontend/dist` exists and the upload API is reachable."
8114
8172
  ]);
8115
8173
  }
8116
8174
  }
8175
+ async function bindFrontendDomain(domain, contentHash, projectName, headers) {
8176
+ const displayDomain = normalizeDomain(domain);
8177
+ const isDns = isDnsDomain(displayDomain);
8178
+ if (isDns) {
8179
+ const validation = validateDnsDomain(displayDomain);
8180
+ if (!validation.valid) {
8181
+ throw createConfigError(validation.message || "Invalid domain format.", [
8182
+ "Use a complete domain like `example.com` for DNS binding."
8183
+ ]);
8184
+ }
8185
+ }
8186
+ if (isDns) {
8187
+ console.log(import_chalk20.default.blue(`Binding DNS domain: ${displayDomain}`));
8188
+ const dnsResult = await bindDnsDomainV4(
8189
+ displayDomain,
8190
+ contentHash,
8191
+ headers["token-address"],
8192
+ headers["authentication-tokens"],
8193
+ projectName
8194
+ );
8195
+ if (dnsResult.code !== 200) {
8196
+ throw new Error(dnsResult.msg || "DNS binding failed");
8197
+ }
8198
+ console.log(import_chalk20.default.green(`DNS bind success: ${displayDomain}`));
8199
+ console.log(import_chalk20.default.white(`Visit: https://${displayDomain}`));
8200
+ return;
8201
+ }
8202
+ console.log(import_chalk20.default.blue(`Binding Pinme subdomain: ${displayDomain}`));
8203
+ const ok = await bindPinmeDomain(displayDomain, contentHash, projectName);
8204
+ if (!ok) {
8205
+ throw new Error("Pinme subdomain binding failed");
8206
+ }
8207
+ console.log(import_chalk20.default.green(`Bind success: ${displayDomain}`));
8208
+ console.log(import_chalk20.default.white(`Visit: https://${displayDomain}.pinit.eth.limo`));
8209
+ }
8117
8210
  async function saveCmd(options) {
8118
8211
  try {
8119
8212
  const headers = getAuthHeaders();
@@ -8152,7 +8245,16 @@ async function saveCmd(options) {
8152
8245
  await saveWorker(workerJsPath, modulePaths, sqlFiles, metadata, projectName);
8153
8246
  console.log(import_chalk20.default.blue("\n--- Frontend ---"));
8154
8247
  buildFrontend();
8155
- await deployFrontend(projectName);
8248
+ const frontendResult = await deployFrontend(projectName);
8249
+ if (options.domain) {
8250
+ console.log(import_chalk20.default.blue("\n--- Domain Binding ---"));
8251
+ await bindFrontendDomain(
8252
+ options.domain,
8253
+ frontendResult.contentHash,
8254
+ projectName,
8255
+ headers
8256
+ );
8257
+ }
8156
8258
  console.log(import_chalk20.default.green("\nDeployment complete."));
8157
8259
  process.exit(0);
8158
8260
  } catch (error) {
@@ -8674,7 +8776,7 @@ program.command("my-domains").alias("domain").description("List domains owned by
8674
8776
  program.command("wallet").alias("wallet-balance").alias("balance").description("Show current wallet balance").action(() => walletBalanceCmd());
8675
8777
  program.command("bind").description("Upload and bind to a domain (requires wallet balance)").option("-d, --domain <name>", "Domain name to bind").option("--dns", "Force DNS domain mode").action(() => bindCmd());
8676
8778
  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 }));
8677
- program.command("save").description("Deploy the project (frontend + backend)").action((options) => saveCmd(options));
8779
+ program.command("save").description("Deploy the project (frontend + backend)").option("-d, --domain <name>", "Bind a domain after frontend deploy").action((options) => saveCmd(options));
8678
8780
  program.command("update-db").description("Execute database migration").action(() => updateDbCmd());
8679
8781
  program.command("update-worker").description("Execute worker migration").action(() => updateWorkerCmd());
8680
8782
  program.command("update-web").description("Deploy frontend to IPFS").action((options) => updateWebCmd(options));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinme",
3
- "version": "2.0.2-beta.6",
3
+ "version": "2.0.2-beta.8",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },