@portaidentity/cli 0.1.0

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 (157) hide show
  1. package/dist/auth/browser-flow.d.ts +42 -0
  2. package/dist/auth/browser-flow.d.ts.map +1 -0
  3. package/dist/auth/browser-flow.js +193 -0
  4. package/dist/auth/browser-flow.js.map +1 -0
  5. package/dist/auth/callback-server.d.ts +81 -0
  6. package/dist/auth/callback-server.d.ts.map +1 -0
  7. package/dist/auth/callback-server.js +193 -0
  8. package/dist/auth/callback-server.js.map +1 -0
  9. package/dist/auth/metadata.d.ts +43 -0
  10. package/dist/auth/metadata.d.ts.map +1 -0
  11. package/dist/auth/metadata.js +66 -0
  12. package/dist/auth/metadata.js.map +1 -0
  13. package/dist/auth/pkce.d.ts +42 -0
  14. package/dist/auth/pkce.d.ts.map +1 -0
  15. package/dist/auth/pkce.js +52 -0
  16. package/dist/auth/pkce.js.map +1 -0
  17. package/dist/auth/types.d.ts +72 -0
  18. package/dist/auth/types.d.ts.map +1 -0
  19. package/dist/auth/types.js +11 -0
  20. package/dist/auth/types.js.map +1 -0
  21. package/dist/client-factory.d.ts +29 -0
  22. package/dist/client-factory.d.ts.map +1 -0
  23. package/dist/client-factory.js +43 -0
  24. package/dist/client-factory.js.map +1 -0
  25. package/dist/commands/app-claim.d.ts +9 -0
  26. package/dist/commands/app-claim.d.ts.map +1 -0
  27. package/dist/commands/app-claim.js +128 -0
  28. package/dist/commands/app-claim.js.map +1 -0
  29. package/dist/commands/app-module.d.ts +9 -0
  30. package/dist/commands/app-module.d.ts.map +1 -0
  31. package/dist/commands/app-module.js +104 -0
  32. package/dist/commands/app-module.js.map +1 -0
  33. package/dist/commands/app-permission.d.ts +9 -0
  34. package/dist/commands/app-permission.d.ts.map +1 -0
  35. package/dist/commands/app-permission.js +118 -0
  36. package/dist/commands/app-permission.js.map +1 -0
  37. package/dist/commands/app-role.d.ts +9 -0
  38. package/dist/commands/app-role.d.ts.map +1 -0
  39. package/dist/commands/app-role.js +166 -0
  40. package/dist/commands/app-role.js.map +1 -0
  41. package/dist/commands/app.d.ts +12 -0
  42. package/dist/commands/app.d.ts.map +1 -0
  43. package/dist/commands/app.js +255 -0
  44. package/dist/commands/app.js.map +1 -0
  45. package/dist/commands/audit.d.ts +12 -0
  46. package/dist/commands/audit.d.ts.map +1 -0
  47. package/dist/commands/audit.js +96 -0
  48. package/dist/commands/audit.js.map +1 -0
  49. package/dist/commands/bulk.d.ts +12 -0
  50. package/dist/commands/bulk.d.ts.map +1 -0
  51. package/dist/commands/bulk.js +77 -0
  52. package/dist/commands/bulk.js.map +1 -0
  53. package/dist/commands/client-secret.d.ts +18 -0
  54. package/dist/commands/client-secret.d.ts.map +1 -0
  55. package/dist/commands/client-secret.js +126 -0
  56. package/dist/commands/client-secret.js.map +1 -0
  57. package/dist/commands/client.d.ts +27 -0
  58. package/dist/commands/client.d.ts.map +1 -0
  59. package/dist/commands/client.js +385 -0
  60. package/dist/commands/client.js.map +1 -0
  61. package/dist/commands/completion.d.ts +27 -0
  62. package/dist/commands/completion.d.ts.map +1 -0
  63. package/dist/commands/completion.js +42 -0
  64. package/dist/commands/completion.js.map +1 -0
  65. package/dist/commands/config.d.ts +14 -0
  66. package/dist/commands/config.d.ts.map +1 -0
  67. package/dist/commands/config.js +85 -0
  68. package/dist/commands/config.js.map +1 -0
  69. package/dist/commands/doctor.d.ts +25 -0
  70. package/dist/commands/doctor.d.ts.map +1 -0
  71. package/dist/commands/doctor.js +198 -0
  72. package/dist/commands/doctor.js.map +1 -0
  73. package/dist/commands/exports.d.ts +12 -0
  74. package/dist/commands/exports.d.ts.map +1 -0
  75. package/dist/commands/exports.js +80 -0
  76. package/dist/commands/exports.js.map +1 -0
  77. package/dist/commands/health.d.ts +12 -0
  78. package/dist/commands/health.d.ts.map +1 -0
  79. package/dist/commands/health.js +53 -0
  80. package/dist/commands/health.js.map +1 -0
  81. package/dist/commands/keys.d.ts +14 -0
  82. package/dist/commands/keys.d.ts.map +1 -0
  83. package/dist/commands/keys.js +91 -0
  84. package/dist/commands/keys.js.map +1 -0
  85. package/dist/commands/login.d.ts +36 -0
  86. package/dist/commands/login.d.ts.map +1 -0
  87. package/dist/commands/login.js +78 -0
  88. package/dist/commands/login.js.map +1 -0
  89. package/dist/commands/logout.d.ts +25 -0
  90. package/dist/commands/logout.d.ts.map +1 -0
  91. package/dist/commands/logout.js +43 -0
  92. package/dist/commands/logout.js.map +1 -0
  93. package/dist/commands/org.d.ts +26 -0
  94. package/dist/commands/org.d.ts.map +1 -0
  95. package/dist/commands/org.js +396 -0
  96. package/dist/commands/org.js.map +1 -0
  97. package/dist/commands/provision.d.ts +47 -0
  98. package/dist/commands/provision.d.ts.map +1 -0
  99. package/dist/commands/provision.js +400 -0
  100. package/dist/commands/provision.js.map +1 -0
  101. package/dist/commands/sessions.d.ts +14 -0
  102. package/dist/commands/sessions.d.ts.map +1 -0
  103. package/dist/commands/sessions.js +122 -0
  104. package/dist/commands/sessions.js.map +1 -0
  105. package/dist/commands/stats.d.ts +12 -0
  106. package/dist/commands/stats.d.ts.map +1 -0
  107. package/dist/commands/stats.js +46 -0
  108. package/dist/commands/stats.js.map +1 -0
  109. package/dist/commands/user-claim.d.ts +17 -0
  110. package/dist/commands/user-claim.d.ts.map +1 -0
  111. package/dist/commands/user-claim.js +123 -0
  112. package/dist/commands/user-claim.js.map +1 -0
  113. package/dist/commands/user-role.d.ts +17 -0
  114. package/dist/commands/user-role.d.ts.map +1 -0
  115. package/dist/commands/user-role.js +118 -0
  116. package/dist/commands/user-role.js.map +1 -0
  117. package/dist/commands/user.d.ts +26 -0
  118. package/dist/commands/user.d.ts.map +1 -0
  119. package/dist/commands/user.js +352 -0
  120. package/dist/commands/user.js.map +1 -0
  121. package/dist/commands/version.d.ts +25 -0
  122. package/dist/commands/version.d.ts.map +1 -0
  123. package/dist/commands/version.js +83 -0
  124. package/dist/commands/version.js.map +1 -0
  125. package/dist/commands/whoami.d.ts +26 -0
  126. package/dist/commands/whoami.d.ts.map +1 -0
  127. package/dist/commands/whoami.js +66 -0
  128. package/dist/commands/whoami.js.map +1 -0
  129. package/dist/credential-store.d.ts +101 -0
  130. package/dist/credential-store.d.ts.map +1 -0
  131. package/dist/credential-store.js +121 -0
  132. package/dist/credential-store.js.map +1 -0
  133. package/dist/error-handler.d.ts +47 -0
  134. package/dist/error-handler.d.ts.map +1 -0
  135. package/dist/error-handler.js +166 -0
  136. package/dist/error-handler.js.map +1 -0
  137. package/dist/global-options.d.ts +50 -0
  138. package/dist/global-options.d.ts.map +1 -0
  139. package/dist/global-options.js +62 -0
  140. package/dist/global-options.js.map +1 -0
  141. package/dist/index.d.ts +29 -0
  142. package/dist/index.d.ts.map +1 -0
  143. package/dist/index.js +122 -0
  144. package/dist/index.js.map +1 -0
  145. package/dist/output.d.ts +75 -0
  146. package/dist/output.d.ts.map +1 -0
  147. package/dist/output.js +100 -0
  148. package/dist/output.js.map +1 -0
  149. package/dist/parsers.d.ts +74 -0
  150. package/dist/parsers.d.ts.map +1 -0
  151. package/dist/parsers.js +125 -0
  152. package/dist/parsers.js.map +1 -0
  153. package/dist/prompt.d.ts +50 -0
  154. package/dist/prompt.d.ts.map +1 -0
  155. package/dist/prompt.js +98 -0
  156. package/dist/prompt.js.map +1 -0
  157. package/package.json +46 -0
@@ -0,0 +1,166 @@
1
+ /**
2
+ * CLI error handler — maps SDK errors to user-friendly output.
3
+ *
4
+ * Wraps command handlers with a try/catch that translates the SDK
5
+ * error hierarchy into appropriate CLI output and exit codes:
6
+ *
7
+ * | Exit Code | Meaning | SDK Error Class |
8
+ * |-----------|---------------------|--------------------------|
9
+ * | 0 | Success | — |
10
+ * | 1 | General error | PortaError, unknown |
11
+ * | 2 | Authentication error| PortaAuthenticationError |
12
+ * | 3 | Validation error | PortaValidationError |
13
+ *
14
+ * In verbose mode (`--verbose`), the full error stack trace and
15
+ * response body are printed. In normal mode, only the user-friendly
16
+ * message is shown.
17
+ *
18
+ * @module error-handler
19
+ */
20
+ import { PortaError, PortaHttpError, PortaAuthenticationError, PortaValidationError, PortaForbiddenError, PortaNotFoundError, PortaConflictError, PortaRateLimitError, PortaServerError, } from '@portaidentity/sdk';
21
+ import { error as printError } from './output.js';
22
+ // ---------------------------------------------------------------------------
23
+ // Exit Codes
24
+ // ---------------------------------------------------------------------------
25
+ /** CLI exit codes per AR #99 */
26
+ export const EXIT_SUCCESS = 0;
27
+ export const EXIT_GENERAL_ERROR = 1;
28
+ export const EXIT_AUTH_ERROR = 2;
29
+ export const EXIT_VALIDATION_ERROR = 3;
30
+ // ---------------------------------------------------------------------------
31
+ // Error Handler
32
+ // ---------------------------------------------------------------------------
33
+ /**
34
+ * Wraps a command handler function with error handling.
35
+ *
36
+ * Catches SDK errors and translates them to user-friendly output
37
+ * with appropriate exit codes. This is the primary error boundary
38
+ * for all CLI commands.
39
+ *
40
+ * @param fn - The async command handler to wrap
41
+ * @param verbose - Whether to show detailed error output
42
+ * @returns A wrapped function that handles errors gracefully
43
+ */
44
+ export function withErrorHandling(fn, verbose = false) {
45
+ return async (...args) => {
46
+ try {
47
+ await fn(...args);
48
+ }
49
+ catch (err) {
50
+ handleError(err, verbose);
51
+ }
52
+ };
53
+ }
54
+ /**
55
+ * Handles an error by printing a user-friendly message and exiting.
56
+ *
57
+ * Maps SDK error types to specific messages and exit codes.
58
+ * In verbose mode, includes the full stack trace and response body.
59
+ *
60
+ * @param err - The caught error
61
+ * @param verbose - Whether to show detailed output
62
+ */
63
+ export function handleError(err, verbose = false) {
64
+ // --- SDK Validation Error (400) ---
65
+ if (err instanceof PortaValidationError) {
66
+ printError(`Validation failed: ${err.message}`);
67
+ if (err.details.length > 0) {
68
+ for (const detail of err.details) {
69
+ printError(` ${detail.path}: ${detail.message}`);
70
+ }
71
+ }
72
+ if (verbose)
73
+ printVerboseDetails(err);
74
+ process.exit(EXIT_VALIDATION_ERROR);
75
+ }
76
+ // --- SDK Authentication Error (401) ---
77
+ if (err instanceof PortaAuthenticationError) {
78
+ printError(`Authentication failed: ${err.message}`);
79
+ printError('Run "porta login" to authenticate.');
80
+ if (verbose)
81
+ printVerboseDetails(err);
82
+ process.exit(EXIT_AUTH_ERROR);
83
+ }
84
+ // --- SDK Forbidden Error (403) ---
85
+ if (err instanceof PortaForbiddenError) {
86
+ printError(`Access denied: ${err.message}`);
87
+ printError('You do not have the required permissions for this operation.');
88
+ if (verbose)
89
+ printVerboseDetails(err);
90
+ process.exit(EXIT_AUTH_ERROR);
91
+ }
92
+ // --- SDK Not Found Error (404) ---
93
+ if (err instanceof PortaNotFoundError) {
94
+ printError(`Not found: ${err.message}`);
95
+ if (verbose)
96
+ printVerboseDetails(err);
97
+ process.exit(EXIT_GENERAL_ERROR);
98
+ }
99
+ // --- SDK Conflict Error (409) ---
100
+ if (err instanceof PortaConflictError) {
101
+ printError(`Conflict: ${err.message}`);
102
+ if (verbose)
103
+ printVerboseDetails(err);
104
+ process.exit(EXIT_GENERAL_ERROR);
105
+ }
106
+ // --- SDK Rate Limit Error (429) ---
107
+ if (err instanceof PortaRateLimitError) {
108
+ const retryMsg = err.retryAfter ? ` Retry after ${err.retryAfter}s.` : '';
109
+ printError(`Rate limit exceeded: ${err.message}${retryMsg}`);
110
+ if (verbose)
111
+ printVerboseDetails(err);
112
+ process.exit(EXIT_GENERAL_ERROR);
113
+ }
114
+ // --- SDK Server Error (5xx) ---
115
+ if (err instanceof PortaServerError) {
116
+ printError(`Server error (${err.status}): ${err.message}`);
117
+ if (verbose)
118
+ printVerboseDetails(err);
119
+ process.exit(EXIT_GENERAL_ERROR);
120
+ }
121
+ // --- Generic SDK HTTP Error ---
122
+ if (err instanceof PortaHttpError) {
123
+ printError(`HTTP ${err.status}: ${err.message}`);
124
+ if (verbose)
125
+ printVerboseDetails(err);
126
+ process.exit(EXIT_GENERAL_ERROR);
127
+ }
128
+ // --- Generic SDK Error ---
129
+ if (err instanceof PortaError) {
130
+ printError(err.message);
131
+ if (verbose && err.stack) {
132
+ console.error('\n' + err.stack);
133
+ }
134
+ process.exit(EXIT_GENERAL_ERROR);
135
+ }
136
+ // --- Standard Error ---
137
+ if (err instanceof Error) {
138
+ printError(err.message);
139
+ if (verbose && err.stack) {
140
+ console.error('\n' + err.stack);
141
+ }
142
+ process.exit(EXIT_GENERAL_ERROR);
143
+ }
144
+ // --- Unknown error ---
145
+ printError(`An unexpected error occurred: ${String(err)}`);
146
+ process.exit(EXIT_GENERAL_ERROR);
147
+ }
148
+ // ---------------------------------------------------------------------------
149
+ // Internal Helpers
150
+ // ---------------------------------------------------------------------------
151
+ /**
152
+ * Prints verbose error details (stack trace and response body).
153
+ *
154
+ * @param err - The HTTP error with additional details
155
+ */
156
+ function printVerboseDetails(err) {
157
+ if (err.stack) {
158
+ console.error('\nStack trace:');
159
+ console.error(err.stack);
160
+ }
161
+ if (err.body) {
162
+ console.error('\nResponse body:');
163
+ console.error(JSON.stringify(err.body, null, 2));
164
+ }
165
+ }
166
+ //# sourceMappingURL=error-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../src/error-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,UAAU,EACV,cAAc,EACd,wBAAwB,EACxB,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AAElD,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E,gCAAgC;AAChC,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAC9B,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAC;AACpC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAC;AACjC,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEvC,8EAA8E;A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AC9C,IAAI,GAAG,CAAC,KAAK,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;QAChC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IACD,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;QAClC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IACnD,CAAC;AACH,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Global CLI options and server URL resolution.
3
+ *
4
+ * Defines the `GlobalOptions` interface shared across all commands,
5
+ * and the `resolveServerUrl()` function that determines the Porta
6
+ * server URL using a priority chain:
7
+ *
8
+ * 1. `--server` flag (highest priority)
9
+ * 2. `PORTA_SERVER` environment variable
10
+ * 3. Server URL from stored credentials file
11
+ * 4. Error — no server configured
12
+ *
13
+ * This resolution chain lets users configure once via `porta login`
14
+ * and override per-command via flag or env var.
15
+ *
16
+ * @module global-options
17
+ */
18
+ /**
19
+ * Global options available to all CLI commands.
20
+ *
21
+ * These are parsed by yargs from the command line and passed
22
+ * through to command handlers.
23
+ */
24
+ export interface GlobalOptions {
25
+ /** Porta server URL override (e.g., https://porta.example.com) */
26
+ server?: string;
27
+ /** Output in JSON format instead of table */
28
+ json: boolean;
29
+ /** Show verbose output including stack traces on error */
30
+ verbose: boolean;
31
+ /** Skip TLS certificate verification (for self-signed certs) */
32
+ insecure: boolean;
33
+ /** Skip confirmation prompts for destructive operations */
34
+ force: boolean;
35
+ }
36
+ /**
37
+ * Resolves the Porta server URL using the priority chain.
38
+ *
39
+ * Resolution order:
40
+ * 1. `--server` CLI flag
41
+ * 2. `PORTA_SERVER` environment variable
42
+ * 3. Server URL from stored credentials (`~/.porta/credentials.json`)
43
+ * 4. Throws an error if no server URL is found
44
+ *
45
+ * @param options - Global CLI options (may contain `server` flag)
46
+ * @returns The resolved server URL
47
+ * @throws Error if no server URL can be determined
48
+ */
49
+ export declare function resolveServerUrl(options: GlobalOptions): string;
50
+ //# sourceMappingURL=global-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-options.d.ts","sourceRoot":"","sources":["../src/global-options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAQH;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,IAAI,EAAE,OAAO,CAAC;IACd,0DAA0D;IAC1D,OAAO,EAAE,OAAO,CAAC;IACjB,gEAAgE;IAChE,QAAQ,EAAE,OAAO,CAAC;IAClB,2DAA2D;IAC3D,KAAK,EAAE,OAAO,CAAC;CAChB;AAMD;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAsB/D"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Global CLI options and server URL resolution.
3
+ *
4
+ * Defines the `GlobalOptions` interface shared across all commands,
5
+ * and the `resolveServerUrl()` function that determines the Porta
6
+ * server URL using a priority chain:
7
+ *
8
+ * 1. `--server` flag (highest priority)
9
+ * 2. `PORTA_SERVER` environment variable
10
+ * 3. Server URL from stored credentials file
11
+ * 4. Error — no server configured
12
+ *
13
+ * This resolution chain lets users configure once via `porta login`
14
+ * and override per-command via flag or env var.
15
+ *
16
+ * @module global-options
17
+ */
18
+ import { loadCredentials } from './credential-store.js';
19
+ // ---------------------------------------------------------------------------
20
+ // Server URL Resolution
21
+ // ---------------------------------------------------------------------------
22
+ /**
23
+ * Resolves the Porta server URL using the priority chain.
24
+ *
25
+ * Resolution order:
26
+ * 1. `--server` CLI flag
27
+ * 2. `PORTA_SERVER` environment variable
28
+ * 3. Server URL from stored credentials (`~/.porta/credentials.json`)
29
+ * 4. Throws an error if no server URL is found
30
+ *
31
+ * @param options - Global CLI options (may contain `server` flag)
32
+ * @returns The resolved server URL
33
+ * @throws Error if no server URL can be determined
34
+ */
35
+ export function resolveServerUrl(options) {
36
+ // Priority 1: --server flag
37
+ if (options.server) {
38
+ return normalizeUrl(options.server);
39
+ }
40
+ // Priority 2: PORTA_SERVER environment variable
41
+ const envUrl = process.env.PORTA_SERVER;
42
+ if (envUrl) {
43
+ return normalizeUrl(envUrl);
44
+ }
45
+ // Priority 3: Credentials file
46
+ const credentials = loadCredentials();
47
+ if (credentials?.server) {
48
+ return normalizeUrl(credentials.server);
49
+ }
50
+ // Priority 4: No server configured
51
+ throw new Error('No Porta server configured. Use --server, set PORTA_SERVER, or run "porta login" first.');
52
+ }
53
+ /**
54
+ * Normalizes a URL by removing trailing slashes.
55
+ *
56
+ * @param url - The URL to normalize
57
+ * @returns URL without trailing slash
58
+ */
59
+ function normalizeUrl(url) {
60
+ return url.replace(/\/+$/, '');
61
+ }
62
+ //# sourceMappingURL=global-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-options.js","sourceRoot":"","sources":["../src/global-options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAyBxD,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAsB;IACrD,4BAA4B;IAC5B,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,YAAY,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED,gDAAgD;IAChD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;IACxC,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;IAED,+BAA+B;IAC/B,MAAM,WAAW,GAAG,eAAe,EAAE,CAAC;IACtC,IAAI,WAAW,EAAE,MAAM,EAAE,CAAC;QACxB,OAAO,YAAY,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED,mCAAmC;IACnC,MAAM,IAAI,KAAK,CACb,yFAAyF,CAC1F,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Porta CLI entry point.
4
+ *
5
+ * Sets up yargs with global options and registers all command modules.
6
+ * This is the standalone CLI package — commands use the SDK for all
7
+ * API communication rather than direct HTTP or database access.
8
+ *
9
+ * Usage: porta <command> <subcommand> [options]
10
+ *
11
+ * Global options:
12
+ * --server Porta server URL (overrides PORTA_SERVER env and credentials)
13
+ * --json Output in JSON format (default: table)
14
+ * --verbose Show detailed output including stack traces on error
15
+ * --insecure Skip TLS certificate verification (self-signed certs)
16
+ * --force Skip confirmation prompts for destructive operations
17
+ *
18
+ * Bootstrap commands (no auth required):
19
+ * login Authenticate with a Porta server via OIDC browser flow
20
+ * logout Clear stored authentication tokens
21
+ * whoami Show current authenticated identity
22
+ * version Show CLI, SDK, and server version information
23
+ * doctor Run diagnostic checks on CLI configuration
24
+ * completion Generate shell completion script
25
+ *
26
+ * @module index
27
+ */
28
+ export {};
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG"}
package/dist/index.js ADDED
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Porta CLI entry point.
4
+ *
5
+ * Sets up yargs with global options and registers all command modules.
6
+ * This is the standalone CLI package — commands use the SDK for all
7
+ * API communication rather than direct HTTP or database access.
8
+ *
9
+ * Usage: porta <command> <subcommand> [options]
10
+ *
11
+ * Global options:
12
+ * --server Porta server URL (overrides PORTA_SERVER env and credentials)
13
+ * --json Output in JSON format (default: table)
14
+ * --verbose Show detailed output including stack traces on error
15
+ * --insecure Skip TLS certificate verification (self-signed certs)
16
+ * --force Skip confirmation prompts for destructive operations
17
+ *
18
+ * Bootstrap commands (no auth required):
19
+ * login Authenticate with a Porta server via OIDC browser flow
20
+ * logout Clear stored authentication tokens
21
+ * whoami Show current authenticated identity
22
+ * version Show CLI, SDK, and server version information
23
+ * doctor Run diagnostic checks on CLI configuration
24
+ * completion Generate shell completion script
25
+ *
26
+ * @module index
27
+ */
28
+ import yargs from 'yargs';
29
+ import { hideBin } from 'yargs/helpers';
30
+ import { loginCommand } from './commands/login.js';
31
+ import { logoutCommand } from './commands/logout.js';
32
+ import { whoamiCommand } from './commands/whoami.js';
33
+ import { versionCommand } from './commands/version.js';
34
+ import { doctorCommand } from './commands/doctor.js';
35
+ import { completionCommand } from './commands/completion.js';
36
+ import { orgCommand } from './commands/org.js';
37
+ import { appCommand } from './commands/app.js';
38
+ import { clientCommand } from './commands/client.js';
39
+ import { userCommand } from './commands/user.js';
40
+ import { keysCommand } from './commands/keys.js';
41
+ import { configCommand } from './commands/config.js';
42
+ import { auditCommand } from './commands/audit.js';
43
+ import { provisionCommand } from './commands/provision.js';
44
+ import { healthCommand } from './commands/health.js';
45
+ import { sessionsCommand } from './commands/sessions.js';
46
+ import { bulkCommand } from './commands/bulk.js';
47
+ import { statsCommand } from './commands/stats.js';
48
+ import { exportsCommand } from './commands/exports.js';
49
+ /**
50
+ * Builds and runs the CLI.
51
+ *
52
+ * Configures yargs with global options, registers all command modules,
53
+ * and parses the command line arguments.
54
+ */
55
+ async function main() {
56
+ await yargs(hideBin(process.argv))
57
+ .scriptName('porta')
58
+ .usage('$0 <command> [options]')
59
+ .option('server', {
60
+ type: 'string',
61
+ describe: 'Porta server URL',
62
+ global: true,
63
+ })
64
+ .option('json', {
65
+ type: 'boolean',
66
+ default: false,
67
+ describe: 'Output in JSON format',
68
+ global: true,
69
+ })
70
+ .option('verbose', {
71
+ type: 'boolean',
72
+ default: false,
73
+ describe: 'Show detailed output',
74
+ global: true,
75
+ })
76
+ .option('insecure', {
77
+ type: 'boolean',
78
+ default: false,
79
+ describe: 'Skip TLS certificate verification',
80
+ global: true,
81
+ })
82
+ .option('force', {
83
+ type: 'boolean',
84
+ default: false,
85
+ describe: 'Skip confirmation prompts',
86
+ global: true,
87
+ })
88
+ // Bootstrap commands (no auth required)
89
+ .command(loginCommand)
90
+ .command(logoutCommand)
91
+ .command(whoamiCommand)
92
+ .command(versionCommand)
93
+ .command(doctorCommand)
94
+ .command(completionCommand)
95
+ // Domain commands (auth required)
96
+ .command(orgCommand)
97
+ .command(appCommand)
98
+ .command(clientCommand)
99
+ .command(userCommand)
100
+ // Infrastructure commands (auth required)
101
+ .command(keysCommand)
102
+ .command(configCommand)
103
+ .command(auditCommand)
104
+ .command(sessionsCommand)
105
+ .command(statsCommand)
106
+ .command(bulkCommand)
107
+ .command(exportsCommand)
108
+ .command(provisionCommand)
109
+ // Unauthenticated commands
110
+ .command(healthCommand)
111
+ .demandCommand(1, 'Please specify a command')
112
+ .strict()
113
+ .help()
114
+ .version(false) // Disable default --version; we use a custom version command
115
+ .completion('completion', false) // Enable yargs completion but hide from help (we have our own command)
116
+ .parse();
117
+ }
118
+ main().catch((err) => {
119
+ console.error(err);
120
+ process.exit(1);
121
+ });
122
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC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I,EAAE;SACN,OAAO,CAAC,KAAK,CAAC,CAAC,6DAA6D;SAC5E,UAAU,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC,uEAAuE;SACvG,KAAK,EAAE,CAAC;AACb,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,75 @@
1
+ /**
2
+ * CLI output helpers.
3
+ *
4
+ * Provides table and JSON formatters, color helpers, and common display
5
+ * utilities. All commands use these helpers for consistent output across
6
+ * the CLI.
7
+ *
8
+ * Table output uses cli-table3 with bold headers.
9
+ * JSON output uses formatted (2-space indent) JSON to stdout.
10
+ * Color helpers use chalk for success/warning/error messages.
11
+ *
12
+ * @module output
13
+ */
14
+ /**
15
+ * Formats data as a table and prints to stdout.
16
+ *
17
+ * Creates a cli-table3 instance with bold headers and prints each row.
18
+ * Used by list and show commands for human-readable output.
19
+ *
20
+ * @param headers - Column header labels (will be bold)
21
+ * @param rows - Array of row data (each row is an array of cell strings)
22
+ */
23
+ export declare function printTable(headers: string[], rows: string[][]): void;
24
+ /**
25
+ * Prints data as formatted JSON to stdout.
26
+ *
27
+ * Outputs a 2-space-indented JSON string. Used when `--json` flag is set,
28
+ * enabling machine-readable output for scripting and piping.
29
+ *
30
+ * @param data - Any JSON-serializable value
31
+ */
32
+ export declare function printJson(data: unknown): void;
33
+ /**
34
+ * Prints a success message in green.
35
+ *
36
+ * @param message - The success message
37
+ */
38
+ export declare function success(message: string): void;
39
+ /**
40
+ * Prints a warning message in yellow to stderr.
41
+ *
42
+ * @param message - The warning message
43
+ */
44
+ export declare function warn(message: string): void;
45
+ /**
46
+ * Prints an error message in red to stderr.
47
+ *
48
+ * @param message - The error message
49
+ */
50
+ export declare function error(message: string): void;
51
+ /**
52
+ * Prints an info message in blue.
53
+ *
54
+ * @param message - The info message
55
+ */
56
+ export declare function info(message: string): void;
57
+ /**
58
+ * Formats a date string or Date object for display.
59
+ *
60
+ * Returns 'N/A' for null/undefined values.
61
+ * Uses ISO 8601 format with local timezone.
62
+ *
63
+ * @param date - Date string, Date object, or null/undefined
64
+ * @returns Formatted date string or 'N/A'
65
+ */
66
+ export declare function formatDate(date: string | Date | null | undefined): string;
67
+ /**
68
+ * Truncates a string to a maximum length with ellipsis.
69
+ *
70
+ * @param str - The string to truncate
71
+ * @param maxLen - Maximum length (default: 40)
72
+ * @returns Truncated string with '...' if needed
73
+ */
74
+ export declare function truncate(str: string, maxLen?: number): string;
75
+ //# sourceMappingURL=output.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,IAAI,CAIpE;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE7C;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE1C;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAIzE;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,SAAK,GAAG,MAAM,CAGzD"}
package/dist/output.js ADDED
@@ -0,0 +1,100 @@
1
+ /**
2
+ * CLI output helpers.
3
+ *
4
+ * Provides table and JSON formatters, color helpers, and common display
5
+ * utilities. All commands use these helpers for consistent output across
6
+ * the CLI.
7
+ *
8
+ * Table output uses cli-table3 with bold headers.
9
+ * JSON output uses formatted (2-space indent) JSON to stdout.
10
+ * Color helpers use chalk for success/warning/error messages.
11
+ *
12
+ * @module output
13
+ */
14
+ import Table from 'cli-table3';
15
+ import chalk from 'chalk';
16
+ /**
17
+ * Formats data as a table and prints to stdout.
18
+ *
19
+ * Creates a cli-table3 instance with bold headers and prints each row.
20
+ * Used by list and show commands for human-readable output.
21
+ *
22
+ * @param headers - Column header labels (will be bold)
23
+ * @param rows - Array of row data (each row is an array of cell strings)
24
+ */
25
+ export function printTable(headers, rows) {
26
+ const table = new Table({ head: headers.map((h) => chalk.bold(h)) });
27
+ rows.forEach((row) => table.push(row));
28
+ console.log(table.toString());
29
+ }
30
+ /**
31
+ * Prints data as formatted JSON to stdout.
32
+ *
33
+ * Outputs a 2-space-indented JSON string. Used when `--json` flag is set,
34
+ * enabling machine-readable output for scripting and piping.
35
+ *
36
+ * @param data - Any JSON-serializable value
37
+ */
38
+ export function printJson(data) {
39
+ console.log(JSON.stringify(data, null, 2));
40
+ }
41
+ /**
42
+ * Prints a success message in green.
43
+ *
44
+ * @param message - The success message
45
+ */
46
+ export function success(message) {
47
+ console.log(chalk.green(`✓ ${message}`));
48
+ }
49
+ /**
50
+ * Prints a warning message in yellow to stderr.
51
+ *
52
+ * @param message - The warning message
53
+ */
54
+ export function warn(message) {
55
+ console.error(chalk.yellow(`⚠ ${message}`));
56
+ }
57
+ /**
58
+ * Prints an error message in red to stderr.
59
+ *
60
+ * @param message - The error message
61
+ */
62
+ export function error(message) {
63
+ console.error(chalk.red(`✗ ${message}`));
64
+ }
65
+ /**
66
+ * Prints an info message in blue.
67
+ *
68
+ * @param message - The info message
69
+ */
70
+ export function info(message) {
71
+ console.log(chalk.blue(`ℹ ${message}`));
72
+ }
73
+ /**
74
+ * Formats a date string or Date object for display.
75
+ *
76
+ * Returns 'N/A' for null/undefined values.
77
+ * Uses ISO 8601 format with local timezone.
78
+ *
79
+ * @param date - Date string, Date object, or null/undefined
80
+ * @returns Formatted date string or 'N/A'
81
+ */
82
+ export function formatDate(date) {
83
+ if (!date)
84
+ return 'N/A';
85
+ const d = typeof date === 'string' ? new Date(date) : date;
86
+ return d.toLocaleString();
87
+ }
88
+ /**
89
+ * Truncates a string to a maximum length with ellipsis.
90
+ *
91
+ * @param str - The string to truncate
92
+ * @param maxLen - Maximum length (default: 40)
93
+ * @returns Truncated string with '...' if needed
94
+ */
95
+ export function truncate(str, maxLen = 40) {
96
+ if (str.length <= maxLen)
97
+ return str;
98
+ return str.slice(0, maxLen - 3) + '...';
99
+ }
100
+ //# sourceMappingURL=output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"output.js","sourceRoot":"","sources":["../src/output.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,MAAM,YAAY,CAAC;AAC/B,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,OAAiB,EAAE,IAAgB;IAC5D,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACrE,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACvC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,S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