@userland.fun/cli 0.1.2 → 0.1.3

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 +65 -15
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -968,10 +968,72 @@ function errorMessage(body) {
968
968
  const typedError = error;
969
969
  const message = typeof typedError.message === "string" ? typedError.message : undefined;
970
970
  const code = typeof typedError.code === "string" ? typedError.code : undefined;
971
- if (code && message) {
972
- return `${code}: ${message}`;
971
+ const detail = entitlementDetailMessage(typedError.details);
972
+ const base = code && message ? `${code}: ${message}` : message ?? code;
973
+ return [base, detail].filter(Boolean).join("\n");
974
+ }
975
+ function entitlementDetailMessage(details) {
976
+ if (!isPlainObject(details)) {
977
+ return undefined;
978
+ }
979
+ const requiredPlan = stringValue(details.required_plan_key);
980
+ const violations = Array.isArray(details.violations) ? details.violations.map(formatEntitlementViolation).filter(Boolean) : [];
981
+ const limit = stringValue(details.limit_key);
982
+ const allowed = details.allowed;
983
+ const value = details.value;
984
+ const lines = [];
985
+ if (requiredPlan) {
986
+ lines.push(`Required plan: ${requiredPlan}`);
987
+ }
988
+ if (violations.length > 0) {
989
+ lines.push("Violations:");
990
+ lines.push(...violations.map((violation) => `- ${violation}`));
991
+ }
992
+ else if (limit) {
993
+ lines.push(`Limit: ${limit}${value !== undefined ? ` value=${String(value)}` : ""}${allowed !== undefined ? ` allowed=${formatAllowed(allowed)}` : ""}`);
973
994
  }
974
- return message ?? code;
995
+ return lines.length > 0 ? lines.join("\n") : undefined;
996
+ }
997
+ function formatEntitlementViolation(value) {
998
+ if (!isPlainObject(value)) {
999
+ return undefined;
1000
+ }
1001
+ const path = stringValue(value.manifest_path);
1002
+ const feature = stringValue(value.feature_key);
1003
+ const limit = stringValue(value.limit_key);
1004
+ const requiredPlan = stringValue(value.required_plan_key);
1005
+ const actualValue = value.value;
1006
+ const allowed = value.allowed;
1007
+ const parts = [
1008
+ path,
1009
+ feature ? `feature=${feature}` : undefined,
1010
+ limit ? `limit=${limit}` : undefined,
1011
+ actualValue !== undefined ? `value=${Array.isArray(actualValue) ? actualValue.join(",") : String(actualValue)}` : undefined,
1012
+ allowed !== undefined ? `allowed=${formatAllowed(allowed)}` : undefined,
1013
+ requiredPlan ? `requires=${requiredPlan}` : undefined
1014
+ ].filter(Boolean);
1015
+ return parts.length > 0 ? parts.join(" ") : undefined;
1016
+ }
1017
+ function formatAllowed(value) {
1018
+ return Array.isArray(value) ? value.join(",") : String(value);
1019
+ }
1020
+ function isPlainObject(value) {
1021
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1022
+ }
1023
+ function docsUrlForError(message) {
1024
+ if (message.includes("entitlement_required") || message.includes("plan_limit_exceeded")) {
1025
+ return "https://docs.userland.fun/reference/errors";
1026
+ }
1027
+ if (message.includes("USERLAND_API_KEY") || message.includes("credentials")) {
1028
+ return "https://docs.userland.fun/reference/cli";
1029
+ }
1030
+ if (message.includes("secrets") || message.includes("pending_secrets")) {
1031
+ return "https://docs.userland.fun/guides/secrets";
1032
+ }
1033
+ if (message.includes("rollback")) {
1034
+ return "https://docs.userland.fun/guides/rollback";
1035
+ }
1036
+ return "https://docs.userland.fun/guides/troubleshooting";
975
1037
  }
976
1038
  function isHelpCommand(command) {
977
1039
  return command === "--help" || command === "-h" || command === "help";
@@ -1020,15 +1082,3 @@ main().catch((error) => {
1020
1082
  console.error(`Docs: ${docsUrlForError(message)}`);
1021
1083
  process.exit(1);
1022
1084
  });
1023
- function docsUrlForError(message) {
1024
- if (message.includes("USERLAND_API_KEY") || message.includes("credentials")) {
1025
- return "https://docs.userland.fun/reference/cli";
1026
- }
1027
- if (message.includes("secrets") || message.includes("pending_secrets")) {
1028
- return "https://docs.userland.fun/guides/secrets";
1029
- }
1030
- if (message.includes("rollback")) {
1031
- return "https://docs.userland.fun/guides/rollback";
1032
- }
1033
- return "https://docs.userland.fun/guides/troubleshooting";
1034
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@userland.fun/cli",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Userland command-line tools for publishing and operating apps.",
5
5
  "license": "MIT",
6
6
  "type": "module",