pinme 2.0.0-beta.16 → 2.0.0-beta.17

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 +25 -64
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1775,7 +1775,7 @@ var import_chalk23 = __toESM(require("chalk"));
1775
1775
  var import_figlet5 = __toESM(require("figlet"));
1776
1776
 
1777
1777
  // package.json
1778
- var version = "2.0.0-beta.16";
1778
+ var version = "2.0.0-beta.17";
1779
1779
 
1780
1780
  // bin/upload.ts
1781
1781
  var import_path7 = __toESM(require("path"));
@@ -8340,62 +8340,20 @@ function getApiMessage(data) {
8340
8340
  var _a, _b, _c;
8341
8341
  return ((_a = data == null ? void 0 : data.data) == null ? void 0 : _a.error) || ((_c = (_b = data == null ? void 0 : data.errors) == null ? void 0 : _b[0]) == null ? void 0 : _c.message) || (data == null ? void 0 : data.message) || (data == null ? void 0 : data.msg) || (data == null ? void 0 : data.error);
8342
8342
  }
8343
- function dedupeSuggestions(suggestions) {
8344
- return Array.from(new Set(suggestions.filter(Boolean)));
8345
- }
8346
- function inferApiSummary(stage, status, errorCode, apiMessage, rawResponse) {
8347
- const text = `${apiMessage || ""} ${rawResponse}`.toLowerCase();
8348
- if (status === 401 || status === 403) {
8349
- return "Authentication expired or permission denied.";
8350
- }
8351
- if (status === 404) {
8352
- return "Project or API endpoint was not found.";
8353
- }
8354
- if (errorCode === "ECONNABORTED" || text.includes("timeout")) {
8355
- return "Request timed out while talking to the platform.";
8356
- }
8357
- if (errorCode === "ENOTFOUND" || errorCode === "ECONNREFUSED" || errorCode === "ECONNRESET") {
8358
- return "Unable to connect to the platform API.";
8343
+ function getBusinessCode(data) {
8344
+ if ((data == null ? void 0 : data.code) === void 0 || (data == null ? void 0 : data.code) === null) {
8345
+ return void 0;
8359
8346
  }
8360
- if (text.includes("sql") || text.includes("sqlite") || text.includes("migration")) {
8361
- return "Database migration failed.";
8362
- }
8363
- if (text.includes("not found") && text.includes("project")) {
8364
- return "Project was not found on the platform.";
8365
- }
8366
- if (text.includes("already exists") || text.includes("duplicate")) {
8367
- return "The platform rejected the request because of conflicting existing data.";
8368
- }
8369
- if (status && status >= 500) {
8370
- return "The platform returned a server-side error.";
8371
- }
8372
- return apiMessage || `${stage} failed.`;
8347
+ return String(data.code);
8373
8348
  }
8374
- function inferApiSuggestions(status, errorCode, apiMessage, rawResponse) {
8375
- const text = `${apiMessage || ""} ${rawResponse}`.toLowerCase();
8376
- const suggestions = [];
8377
- if (status === 401 || status === 403) {
8378
- suggestions.push("Run `pinme login` again to refresh local auth.");
8379
- }
8380
- if (status === 404 || text.includes("project") && text.includes("not found")) {
8381
- suggestions.push("Confirm `project_name` in `pinme.toml` matches an existing project.");
8382
- }
8383
- if (errorCode === "ECONNABORTED" || text.includes("timeout")) {
8384
- suggestions.push("Retry once. If it keeps timing out, check network quality and platform responsiveness.");
8349
+ function getBusinessMessage(data) {
8350
+ if (!(data == null ? void 0 : data.msg)) {
8351
+ return void 0;
8385
8352
  }
8386
- if (errorCode === "ENOTFOUND" || errorCode === "ECONNREFUSED" || errorCode === "ECONNRESET") {
8387
- suggestions.push("Check `PINME_API_BASE`, local network connectivity, and whether the API service is reachable.");
8388
- }
8389
- if (text.includes("sql") || text.includes("sqlite") || text.includes("migration")) {
8390
- suggestions.push("Review the SQL file mentioned in the response and verify it is safe to run on the current schema.");
8391
- }
8392
- if (text.includes("already exists") || text.includes("duplicate")) {
8393
- suggestions.push("Check whether this resource or schema change was already created in a previous deployment.");
8394
- }
8395
- if (status && status >= 500) {
8396
- suggestions.push("The platform returned a server-side error. Retry once and check the backend logs if it persists.");
8397
- }
8398
- return suggestions;
8353
+ return String(data.msg);
8354
+ }
8355
+ function dedupeSuggestions(suggestions) {
8356
+ return Array.from(new Set(suggestions.filter(Boolean)));
8399
8357
  }
8400
8358
  function createConfigError(summary, suggestions = []) {
8401
8359
  return new CliError({
@@ -8431,30 +8389,33 @@ function createApiError(stage, error, context = [], suggestions = []) {
8431
8389
  const responseData = (_b = error == null ? void 0 : error.response) == null ? void 0 : _b.data;
8432
8390
  const errorCode = error == null ? void 0 : error.code;
8433
8391
  const apiMessage = getApiMessage(responseData);
8434
- const summary = apiMessage || inferApiSummary(stage, status, errorCode, apiMessage, stringifyValue(responseData)) || (error == null ? void 0 : error.message) || `${stage} failed.`;
8392
+ const businessCode = getBusinessCode(responseData);
8393
+ const businessMessage = getBusinessMessage(responseData);
8394
+ const summary = apiMessage || (error == null ? void 0 : error.message) || `${stage} failed.`;
8435
8395
  const detailLines = [...context];
8436
8396
  if (status) {
8437
8397
  detailLines.push(`HTTP status: ${status}`);
8438
8398
  }
8439
- if (apiMessage && apiMessage !== summary) {
8440
- detailLines.push(`API message: ${apiMessage}`);
8399
+ if (businessCode) {
8400
+ detailLines.push(`Business code: ${businessCode}`);
8441
8401
  }
8442
- const rawResponse = stringifyValue(responseData);
8443
- if (rawResponse) {
8444
- detailLines.push(`API response: ${rawResponse}`);
8402
+ if (businessMessage && businessMessage !== apiMessage) {
8403
+ detailLines.push(`Business message: ${businessMessage}`);
8445
8404
  }
8446
- if (errorCode && errorCode !== "ERR_BAD_REQUEST") {
8405
+ if (apiMessage && apiMessage !== summary) {
8406
+ detailLines.push(`Error message: ${apiMessage}`);
8407
+ }
8408
+ if (errorCode && errorCode !== "ERR_BAD_REQUEST" && !responseData) {
8447
8409
  detailLines.push(`Error code: ${errorCode}`);
8448
8410
  }
8449
- if (!rawResponse && (error == null ? void 0 : error.message) && error.message !== apiMessage) {
8411
+ if (!responseData && (error == null ? void 0 : error.message) && error.message !== apiMessage) {
8450
8412
  detailLines.push(`Reason: ${error.message}`);
8451
8413
  }
8452
- const inferredSuggestions = inferApiSuggestions(status, errorCode, apiMessage, rawResponse);
8453
8414
  return new CliError({
8454
8415
  summary,
8455
8416
  stage,
8456
8417
  details: detailLines,
8457
- suggestions: dedupeSuggestions([...inferredSuggestions, ...suggestions]),
8418
+ suggestions: dedupeSuggestions(suggestions),
8458
8419
  cause: error
8459
8420
  });
8460
8421
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinme",
3
- "version": "2.0.0-beta.16",
3
+ "version": "2.0.0-beta.17",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },