@userland.fun/cli 0.1.1 → 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 +80 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9,6 +9,9 @@ const KEYCHAIN_SERVICE = "fun.userland.cli";
9
9
  const KEYCHAIN_ACCOUNT = "default";
10
10
  async function main() {
11
11
  const [command, ...args] = process.argv.slice(2);
12
+ if (isHelpCommand(command)) {
13
+ usage(0);
14
+ }
12
15
  if (command === "apps") {
13
16
  await appsCommand(args);
14
17
  return;
@@ -965,13 +968,79 @@ function errorMessage(body) {
965
968
  const typedError = error;
966
969
  const message = typeof typedError.message === "string" ? typedError.message : undefined;
967
970
  const code = typeof typedError.code === "string" ? typedError.code : undefined;
968
- if (code && message) {
969
- 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}`));
970
991
  }
971
- return message ?? code;
992
+ else if (limit) {
993
+ lines.push(`Limit: ${limit}${value !== undefined ? ` value=${String(value)}` : ""}${allowed !== undefined ? ` allowed=${formatAllowed(allowed)}` : ""}`);
994
+ }
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";
1037
+ }
1038
+ function isHelpCommand(command) {
1039
+ return command === "--help" || command === "-h" || command === "help";
972
1040
  }
973
1041
  function usage(exitCode) {
974
- console.error(`Usage:
1042
+ const message = `Usage:
1043
+ userland [--help]
975
1044
  userland signup [--username <username>] [--password <password>] [--email <email>] [--no-save]
976
1045
  userland login [--username <username>] [--password <password>] [--no-save]
977
1046
  userland auth status
@@ -998,7 +1067,13 @@ Credentials:
998
1067
 
999
1068
  Docs:
1000
1069
  https://docs.userland.fun/reference/cli
1001
- https://docs.userland.fun/guides/troubleshooting`);
1070
+ https://docs.userland.fun/guides/troubleshooting`;
1071
+ if (exitCode === 0) {
1072
+ console.log(message);
1073
+ }
1074
+ else {
1075
+ console.error(message);
1076
+ }
1002
1077
  process.exit(exitCode);
1003
1078
  }
1004
1079
  main().catch((error) => {
@@ -1007,15 +1082,3 @@ main().catch((error) => {
1007
1082
  console.error(`Docs: ${docsUrlForError(message)}`);
1008
1083
  process.exit(1);
1009
1084
  });
1010
- function docsUrlForError(message) {
1011
- if (message.includes("USERLAND_API_KEY") || message.includes("credentials")) {
1012
- return "https://docs.userland.fun/reference/cli";
1013
- }
1014
- if (message.includes("secrets") || message.includes("pending_secrets")) {
1015
- return "https://docs.userland.fun/guides/secrets";
1016
- }
1017
- if (message.includes("rollback")) {
1018
- return "https://docs.userland.fun/guides/rollback";
1019
- }
1020
- return "https://docs.userland.fun/guides/troubleshooting";
1021
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@userland.fun/cli",
3
- "version": "0.1.1",
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",