pax8-cta 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 (224) hide show
  1. package/LICENSE +200 -0
  2. package/README.md +659 -0
  3. package/demo-data/solutions/ProductQADemo_1_0_0_2_managed.zip +0 -0
  4. package/dist/commands/analyze.d.ts +28 -0
  5. package/dist/commands/analyze.d.ts.map +1 -0
  6. package/dist/commands/analyze.js +571 -0
  7. package/dist/commands/analyze.js.map +1 -0
  8. package/dist/commands/auth.d.ts +18 -0
  9. package/dist/commands/auth.d.ts.map +1 -0
  10. package/dist/commands/auth.js +171 -0
  11. package/dist/commands/auth.js.map +1 -0
  12. package/dist/commands/config.d.ts +34 -0
  13. package/dist/commands/config.d.ts.map +1 -0
  14. package/dist/commands/config.js +299 -0
  15. package/dist/commands/config.js.map +1 -0
  16. package/dist/commands/demo.d.ts +33 -0
  17. package/dist/commands/demo.d.ts.map +1 -0
  18. package/dist/commands/demo.js +362 -0
  19. package/dist/commands/demo.js.map +1 -0
  20. package/dist/commands/deploy.d.ts +18 -0
  21. package/dist/commands/deploy.d.ts.map +1 -0
  22. package/dist/commands/deploy.js +1186 -0
  23. package/dist/commands/deploy.js.map +1 -0
  24. package/dist/commands/deployments/helpers.d.ts +68 -0
  25. package/dist/commands/deployments/helpers.d.ts.map +1 -0
  26. package/dist/commands/deployments/helpers.js +414 -0
  27. package/dist/commands/deployments/helpers.js.map +1 -0
  28. package/dist/commands/deployments/index.d.ts +24 -0
  29. package/dist/commands/deployments/index.d.ts.map +1 -0
  30. package/dist/commands/deployments/index.js +47 -0
  31. package/dist/commands/deployments/index.js.map +1 -0
  32. package/dist/commands/deployments/list.d.ts +18 -0
  33. package/dist/commands/deployments/list.d.ts.map +1 -0
  34. package/dist/commands/deployments/list.js +97 -0
  35. package/dist/commands/deployments/list.js.map +1 -0
  36. package/dist/commands/deployments/show.d.ts +18 -0
  37. package/dist/commands/deployments/show.d.ts.map +1 -0
  38. package/dist/commands/deployments/show.js +81 -0
  39. package/dist/commands/deployments/show.js.map +1 -0
  40. package/dist/commands/deployments/undo.d.ts +18 -0
  41. package/dist/commands/deployments/undo.d.ts.map +1 -0
  42. package/dist/commands/deployments/undo.js +295 -0
  43. package/dist/commands/deployments/undo.js.map +1 -0
  44. package/dist/commands/export.d.ts +18 -0
  45. package/dist/commands/export.d.ts.map +1 -0
  46. package/dist/commands/export.js +133 -0
  47. package/dist/commands/export.js.map +1 -0
  48. package/dist/commands/import.d.ts +18 -0
  49. package/dist/commands/import.d.ts.map +1 -0
  50. package/dist/commands/import.js +129 -0
  51. package/dist/commands/import.js.map +1 -0
  52. package/dist/commands/init-config.d.ts +26 -0
  53. package/dist/commands/init-config.d.ts.map +1 -0
  54. package/dist/commands/init-config.js +123 -0
  55. package/dist/commands/init-config.js.map +1 -0
  56. package/dist/commands/init-validation.d.ts +47 -0
  57. package/dist/commands/init-validation.d.ts.map +1 -0
  58. package/dist/commands/init-validation.js +339 -0
  59. package/dist/commands/init-validation.js.map +1 -0
  60. package/dist/commands/init-wizard.d.ts +25 -0
  61. package/dist/commands/init-wizard.d.ts.map +1 -0
  62. package/dist/commands/init-wizard.js +433 -0
  63. package/dist/commands/init-wizard.js.map +1 -0
  64. package/dist/commands/init.d.ts +18 -0
  65. package/dist/commands/init.d.ts.map +1 -0
  66. package/dist/commands/init.js +46 -0
  67. package/dist/commands/init.js.map +1 -0
  68. package/dist/commands/resolve-url.d.ts +18 -0
  69. package/dist/commands/resolve-url.d.ts.map +1 -0
  70. package/dist/commands/resolve-url.js +126 -0
  71. package/dist/commands/resolve-url.js.map +1 -0
  72. package/dist/commands/setup.d.ts +18 -0
  73. package/dist/commands/setup.d.ts.map +1 -0
  74. package/dist/commands/setup.js +239 -0
  75. package/dist/commands/setup.js.map +1 -0
  76. package/dist/commands/solutions/drift-analysis.d.ts +73 -0
  77. package/dist/commands/solutions/drift-analysis.d.ts.map +1 -0
  78. package/dist/commands/solutions/drift-analysis.js +416 -0
  79. package/dist/commands/solutions/drift-analysis.js.map +1 -0
  80. package/dist/commands/solutions/drift.d.ts +32 -0
  81. package/dist/commands/solutions/drift.d.ts.map +1 -0
  82. package/dist/commands/solutions/drift.js +641 -0
  83. package/dist/commands/solutions/drift.js.map +1 -0
  84. package/dist/commands/solutions/fix-planner.d.ts +48 -0
  85. package/dist/commands/solutions/fix-planner.d.ts.map +1 -0
  86. package/dist/commands/solutions/fix-planner.js +43 -0
  87. package/dist/commands/solutions/fix-planner.js.map +1 -0
  88. package/dist/commands/solutions/helpers.d.ts +35 -0
  89. package/dist/commands/solutions/helpers.d.ts.map +1 -0
  90. package/dist/commands/solutions/helpers.js +54 -0
  91. package/dist/commands/solutions/helpers.js.map +1 -0
  92. package/dist/commands/solutions/index.d.ts +18 -0
  93. package/dist/commands/solutions/index.d.ts.map +1 -0
  94. package/dist/commands/solutions/index.js +30 -0
  95. package/dist/commands/solutions/index.js.map +1 -0
  96. package/dist/commands/solutions/list.d.ts +18 -0
  97. package/dist/commands/solutions/list.d.ts.map +1 -0
  98. package/dist/commands/solutions/list.js +174 -0
  99. package/dist/commands/solutions/list.js.map +1 -0
  100. package/dist/commands/solutions/remove.d.ts +18 -0
  101. package/dist/commands/solutions/remove.d.ts.map +1 -0
  102. package/dist/commands/solutions/remove.js +137 -0
  103. package/dist/commands/solutions/remove.js.map +1 -0
  104. package/dist/commands/solutions/risk-calculator.d.ts +33 -0
  105. package/dist/commands/solutions/risk-calculator.d.ts.map +1 -0
  106. package/dist/commands/solutions/risk-calculator.js +79 -0
  107. package/dist/commands/solutions/risk-calculator.js.map +1 -0
  108. package/dist/commands/solutions/show.d.ts +18 -0
  109. package/dist/commands/solutions/show.d.ts.map +1 -0
  110. package/dist/commands/solutions/show.js +165 -0
  111. package/dist/commands/solutions/show.js.map +1 -0
  112. package/dist/commands/status.d.ts +18 -0
  113. package/dist/commands/status.d.ts.map +1 -0
  114. package/dist/commands/status.js +573 -0
  115. package/dist/commands/status.js.map +1 -0
  116. package/dist/commands/telemetry.d.ts +18 -0
  117. package/dist/commands/telemetry.d.ts.map +1 -0
  118. package/dist/commands/telemetry.js +85 -0
  119. package/dist/commands/telemetry.js.map +1 -0
  120. package/dist/commands/tenants/health.d.ts +18 -0
  121. package/dist/commands/tenants/health.d.ts.map +1 -0
  122. package/dist/commands/tenants/health.js +172 -0
  123. package/dist/commands/tenants/health.js.map +1 -0
  124. package/dist/commands/tenants/helpers.d.ts +44 -0
  125. package/dist/commands/tenants/helpers.d.ts.map +1 -0
  126. package/dist/commands/tenants/helpers.js +72 -0
  127. package/dist/commands/tenants/helpers.js.map +1 -0
  128. package/dist/commands/tenants/index.d.ts +19 -0
  129. package/dist/commands/tenants/index.d.ts.map +1 -0
  130. package/dist/commands/tenants/index.js +39 -0
  131. package/dist/commands/tenants/index.js.map +1 -0
  132. package/dist/commands/tenants/inspect.d.ts +18 -0
  133. package/dist/commands/tenants/inspect.d.ts.map +1 -0
  134. package/dist/commands/tenants/inspect.js +176 -0
  135. package/dist/commands/tenants/inspect.js.map +1 -0
  136. package/dist/commands/tenants/list.d.ts +18 -0
  137. package/dist/commands/tenants/list.d.ts.map +1 -0
  138. package/dist/commands/tenants/list.js +144 -0
  139. package/dist/commands/tenants/list.js.map +1 -0
  140. package/dist/commands/tenants/manage.d.ts +20 -0
  141. package/dist/commands/tenants/manage.d.ts.map +1 -0
  142. package/dist/commands/tenants/manage.js +206 -0
  143. package/dist/commands/tenants/manage.js.map +1 -0
  144. package/dist/commands/tenants/show.d.ts +18 -0
  145. package/dist/commands/tenants/show.d.ts.map +1 -0
  146. package/dist/commands/tenants/show.js +191 -0
  147. package/dist/commands/tenants/show.js.map +1 -0
  148. package/dist/commands/validate.d.ts +18 -0
  149. package/dist/commands/validate.d.ts.map +1 -0
  150. package/dist/commands/validate.js +536 -0
  151. package/dist/commands/validate.js.map +1 -0
  152. package/dist/index.d.ts +19 -0
  153. package/dist/index.d.ts.map +1 -0
  154. package/dist/index.js +258 -0
  155. package/dist/index.js.map +1 -0
  156. package/dist/lib/auth.d.ts +51 -0
  157. package/dist/lib/auth.d.ts.map +1 -0
  158. package/dist/lib/auth.js +153 -0
  159. package/dist/lib/auth.js.map +1 -0
  160. package/dist/lib/banner.d.ts +19 -0
  161. package/dist/lib/banner.d.ts.map +1 -0
  162. package/dist/lib/banner.js +78 -0
  163. package/dist/lib/banner.js.map +1 -0
  164. package/dist/lib/command-wrapper.d.ts +56 -0
  165. package/dist/lib/command-wrapper.d.ts.map +1 -0
  166. package/dist/lib/command-wrapper.js +71 -0
  167. package/dist/lib/command-wrapper.js.map +1 -0
  168. package/dist/lib/credentials.d.ts +56 -0
  169. package/dist/lib/credentials.d.ts.map +1 -0
  170. package/dist/lib/credentials.js +146 -0
  171. package/dist/lib/credentials.js.map +1 -0
  172. package/dist/lib/demo-banner.d.ts +15 -0
  173. package/dist/lib/demo-banner.d.ts.map +1 -0
  174. package/dist/lib/demo-banner.js +33 -0
  175. package/dist/lib/demo-banner.js.map +1 -0
  176. package/dist/lib/error-handler.d.ts +51 -0
  177. package/dist/lib/error-handler.d.ts.map +1 -0
  178. package/dist/lib/error-handler.js +458 -0
  179. package/dist/lib/error-handler.js.map +1 -0
  180. package/dist/lib/errors.d.ts +61 -0
  181. package/dist/lib/errors.d.ts.map +1 -0
  182. package/dist/lib/errors.js +168 -0
  183. package/dist/lib/errors.js.map +1 -0
  184. package/dist/lib/formatters.d.ts +55 -0
  185. package/dist/lib/formatters.d.ts.map +1 -0
  186. package/dist/lib/formatters.js +163 -0
  187. package/dist/lib/formatters.js.map +1 -0
  188. package/dist/lib/graph-client.d.ts +74 -0
  189. package/dist/lib/graph-client.d.ts.map +1 -0
  190. package/dist/lib/graph-client.js +231 -0
  191. package/dist/lib/graph-client.js.map +1 -0
  192. package/dist/lib/input.d.ts +22 -0
  193. package/dist/lib/input.d.ts.map +1 -0
  194. package/dist/lib/input.js +120 -0
  195. package/dist/lib/input.js.map +1 -0
  196. package/dist/lib/interactive-wizard.d.ts +26 -0
  197. package/dist/lib/interactive-wizard.d.ts.map +1 -0
  198. package/dist/lib/interactive-wizard.js +550 -0
  199. package/dist/lib/interactive-wizard.js.map +1 -0
  200. package/dist/lib/oss-surface.d.ts +21 -0
  201. package/dist/lib/oss-surface.d.ts.map +1 -0
  202. package/dist/lib/oss-surface.js +29 -0
  203. package/dist/lib/oss-surface.js.map +1 -0
  204. package/dist/lib/output.d.ts +74 -0
  205. package/dist/lib/output.d.ts.map +1 -0
  206. package/dist/lib/output.js +156 -0
  207. package/dist/lib/output.js.map +1 -0
  208. package/dist/lib/picker.d.ts +75 -0
  209. package/dist/lib/picker.d.ts.map +1 -0
  210. package/dist/lib/picker.js +115 -0
  211. package/dist/lib/picker.js.map +1 -0
  212. package/dist/lib/repl.d.ts +19 -0
  213. package/dist/lib/repl.d.ts.map +1 -0
  214. package/dist/lib/repl.js +158 -0
  215. package/dist/lib/repl.js.map +1 -0
  216. package/dist/lib/spinner.d.ts +41 -0
  217. package/dist/lib/spinner.d.ts.map +1 -0
  218. package/dist/lib/spinner.js +126 -0
  219. package/dist/lib/spinner.js.map +1 -0
  220. package/dist/lib/telemetry.d.ts +96 -0
  221. package/dist/lib/telemetry.d.ts.map +1 -0
  222. package/dist/lib/telemetry.js +367 -0
  223. package/dist/lib/telemetry.js.map +1 -0
  224. package/package.json +68 -0
@@ -0,0 +1,458 @@
1
+ /**
2
+ * Copyright 2024 Pax8, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import chalk from "chalk";
17
+ import { AuthError, GdapError, SolutionError, AgentResolutionError, ConfigValidationError, NetworkError, ErrorCode, isCtaError, } from "@pax8-cta/core";
18
+ const LEGACY_QUEUE_ERROR_MESSAGE = "Legacy deployment queue support is unavailable in the open-source CLI";
19
+ const LEGACY_QUEUE_ERROR_CAUSES = [
20
+ "A Redis-backed worker was referenced by older tooling or configuration",
21
+ "The CLI now deploys directly and does not use a queue",
22
+ "An outdated command or environment variable is still pointing at Redis",
23
+ ];
24
+ const LEGACY_QUEUE_ERROR_RECOVERY = [
25
+ "Remove any legacy queue-related flags or configuration",
26
+ "Use the direct deployment flow instead:",
27
+ " deploy --direct --all --solution ./agent.zip",
28
+ "If this is coming from older automation, update it to call the direct CLI",
29
+ ];
30
+ /**
31
+ * Structured CLI error with recovery guidance.
32
+ *
33
+ * This wraps any error (typed or untyped) into a presentation-friendly
34
+ * format with causes, recovery steps, and context for the CLI output.
35
+ */
36
+ export class CtaError extends Error {
37
+ code;
38
+ causes;
39
+ recovery;
40
+ context;
41
+ constructor(code, message, causes, recovery, context) {
42
+ super(message);
43
+ this.code = code;
44
+ this.causes = causes;
45
+ this.recovery = recovery;
46
+ this.context = context;
47
+ this.name = "CtaError";
48
+ }
49
+ }
50
+ // ---------------------------------------------------------------------------
51
+ // Code-based mapping: structured errors from @pax8-cta/core
52
+ // ---------------------------------------------------------------------------
53
+ function formatByErrorCode(error) {
54
+ const ctx = {
55
+ environmentUrl: error.context?.environmentUrl,
56
+ tenantName: error.context?.tenantName,
57
+ solutionName: error.context?.solutionName,
58
+ clientId: error.context?.clientId,
59
+ };
60
+ // --- GDAP / App-user errors ---
61
+ if (error instanceof GdapError ||
62
+ error.code === ErrorCode.GDAP_MISSING ||
63
+ error.code === ErrorCode.GDAP_APP_USER_NOT_REGISTERED ||
64
+ error.code === ErrorCode.GDAP_SETUP_FAILED ||
65
+ error.code === ErrorCode.GDAP_ENVIRONMENT_ID_MISSING) {
66
+ return new CtaError("ERROR_GDAP_MISSING", "Application user not registered in Power Platform environment", [
67
+ "The application is not configured as a user in the target environment",
68
+ "The app registration may not have been added to the environment yet",
69
+ "GDAP (Granular Delegated Admin Privileges) relationship may not be established",
70
+ ], [
71
+ "Go to https://admin.powerplatform.microsoft.com",
72
+ "Select the target environment \u2192 Settings \u2192 Users + permissions \u2192 Application users",
73
+ 'Click "+ New app user" and add your application',
74
+ ctx.clientId
75
+ ? `Use Client ID: ${ctx.clientId}`
76
+ : "Use the Client ID from your partner configuration",
77
+ 'Assign the "System Administrator" security role',
78
+ "Save and retry the command",
79
+ ], ctx);
80
+ }
81
+ // --- Permission / privilege errors ---
82
+ if (error.code === ErrorCode.PERMISSION_DENIED ||
83
+ error.code === ErrorCode.PERMISSION_PRIVILEGE_MISSING ||
84
+ error.code === ErrorCode.DATAVERSE_FORBIDDEN) {
85
+ return new CtaError("ERROR_INSUFFICIENT_PERMISSIONS", "Application user lacks required permissions in Power Platform environment", [
86
+ "The application user exists but doesn't have necessary security roles",
87
+ "The System Administrator role may not be assigned",
88
+ "Solution-specific permissions (prvReadSolution, prvWriteSolution, etc.) are missing",
89
+ ], [
90
+ "Go to https://admin.powerplatform.microsoft.com",
91
+ "Select the target environment \u2192 Settings \u2192 Users + permissions \u2192 Application users",
92
+ ctx.clientId
93
+ ? `Find your application user (Client ID: ${ctx.clientId})`
94
+ : "Find your application user",
95
+ 'Click "Manage security roles" or "Edit"',
96
+ 'Ensure "System Administrator" role is assigned',
97
+ "Verify the role includes solution deployment privileges (prvReadSolution, prvWriteSolution, prvCreateSolution)",
98
+ "Save and retry the command",
99
+ ], ctx);
100
+ }
101
+ // --- Authentication errors ---
102
+ if (error instanceof AuthError ||
103
+ error.code === ErrorCode.DATAVERSE_UNAUTHORIZED ||
104
+ error.code === ErrorCode.AUTH_FAILED ||
105
+ error.code === ErrorCode.AUTH_TOKEN_EXPIRED ||
106
+ error.code === ErrorCode.AUTH_APP_NOT_FOUND ||
107
+ error.code === ErrorCode.AUTH_INVALID_SECRET ||
108
+ error.code === ErrorCode.AUTH_ACCOUNT_NOT_FOUND ||
109
+ error.code === ErrorCode.AUTH_INVALID_CLIENT) {
110
+ return new CtaError("ERROR_AUTH_FAILED", "Authentication failed - unable to acquire or validate access token", [
111
+ "The client secret may have expired",
112
+ "API permissions may not be configured correctly in Azure AD",
113
+ "Admin consent may not have been granted for the required permissions",
114
+ ], [
115
+ "Verify the app registration in Azure Portal:",
116
+ " - Go to https://portal.azure.com \u2192 Azure Active Directory \u2192 App registrations",
117
+ ctx.clientId
118
+ ? ` - Find your app (Client ID: ${ctx.clientId})`
119
+ : " - Locate your application registration",
120
+ "Check API permissions:",
121
+ ' - Ensure "Dynamics CRM" or "Common Data Service" API permission is added',
122
+ ' - Permission should be "user_impersonation" (delegated) or ".default" (application)',
123
+ ' - Click "Grant admin consent" if not already done',
124
+ "Verify client secret:",
125
+ " - Check if the secret has expired in the app registration",
126
+ " - Generate a new secret if needed and update your environment variable (PARTNER_CLIENT_SECRET)",
127
+ "Retry the command",
128
+ ], ctx);
129
+ }
130
+ // --- Solution not found ---
131
+ if (error instanceof SolutionError ||
132
+ error.code === ErrorCode.SOLUTION_NOT_FOUND ||
133
+ error.code === ErrorCode.SOLUTION_IMPORT_FAILED ||
134
+ error.code === ErrorCode.SOLUTION_EXPORT_FAILED) {
135
+ return new CtaError("ERROR_SOLUTION_NOT_FOUND", ctx.solutionName
136
+ ? `Solution '${ctx.solutionName}' not found in environment`
137
+ : "Solution not found in environment", [
138
+ "The solution may not exist in the source environment",
139
+ "The solution name may be misspelled (names are case-sensitive)",
140
+ "The solution may have been deleted or renamed",
141
+ ], [
142
+ ctx.solutionName
143
+ ? `Verify the solution name '${ctx.solutionName}' is correct`
144
+ : "Verify the solution name is correct and matches exactly (case-sensitive)",
145
+ "List available solutions in the source environment:",
146
+ " agents list",
147
+ "Check that you're connected to the correct source environment",
148
+ "Ensure the solution is published and visible in the source environment",
149
+ "Retry with the correct solution name",
150
+ ], ctx);
151
+ }
152
+ // --- Agent resolution errors ---
153
+ if (error instanceof AgentResolutionError) {
154
+ return new CtaError("ERROR_SOLUTION_NOT_FOUND", "Could not resolve agent URL to a solution", [
155
+ "The agent URL may be invalid or the agent no longer exists",
156
+ "The titleId in the URL may not match any bot in the environment",
157
+ "The M365 Graph API may be needed to resolve this URL format",
158
+ ], [
159
+ "Verify the agent URL is correct and the agent is published",
160
+ "List available agents in the source environment:",
161
+ " agents list",
162
+ "Try using the solution name directly instead of the agent URL",
163
+ ], ctx);
164
+ }
165
+ // --- Network errors ---
166
+ if (error instanceof NetworkError ||
167
+ error.code === ErrorCode.NETWORK_CONNECTION_REFUSED ||
168
+ error.code === ErrorCode.NETWORK_TIMEOUT ||
169
+ error.code === ErrorCode.NETWORK_DNS_FAILED ||
170
+ error.code === ErrorCode.NETWORK_ERROR) {
171
+ return new CtaError("ERROR_NETWORK", "Network connection failed", [
172
+ "The target environment URL may be incorrect or unreachable",
173
+ "Network connectivity issues (firewall, proxy, DNS)",
174
+ "The Power Platform environment may be temporarily unavailable",
175
+ ], [
176
+ "Verify the environment URL is correct:",
177
+ ctx.environmentUrl
178
+ ? ` Current: ${ctx.environmentUrl}`
179
+ : " Check your configuration file for the correct URL",
180
+ "Test network connectivity:",
181
+ ctx.environmentUrl
182
+ ? ` curl -I ${ctx.environmentUrl}`
183
+ : " Use curl or ping to test the environment URL",
184
+ "Check firewall/proxy settings that may block Power Platform endpoints",
185
+ "Verify DNS resolution for the environment hostname",
186
+ "If using a VPN, ensure it's connected and configured properly",
187
+ "Check Power Platform service status: https://admin.powerplatform.microsoft.com/service-health",
188
+ "Retry the command after resolving connectivity issues",
189
+ ], ctx);
190
+ }
191
+ // --- Config errors ---
192
+ if (error instanceof ConfigValidationError ||
193
+ error.code === ErrorCode.CONFIG_NOT_FOUND ||
194
+ error.code === ErrorCode.CONFIG_INVALID ||
195
+ error.code === ErrorCode.CONFIG_READ_FAILED ||
196
+ error.code === ErrorCode.CONFIG_PARSE_FAILED ||
197
+ error.code === ErrorCode.CONFIG_SECRET_MISSING) {
198
+ return new CtaError("ERROR_CONFIG_NOT_FOUND", "Configuration file or required resource not found", [
199
+ "The configuration file may not exist at the specified path",
200
+ "The working directory may be incorrect",
201
+ "Required files may have been deleted or moved",
202
+ ], [
203
+ "Verify you're in the correct directory (should contain config/ folder)",
204
+ "Check if the configuration file exists:",
205
+ " ls -la ./config/tenants.yaml",
206
+ "If the config file doesn't exist, initialize a new configuration:",
207
+ " init",
208
+ "Specify a custom config path with --config flag if needed:",
209
+ " deploy --config /path/to/config.yaml ...",
210
+ ], ctx);
211
+ }
212
+ // --- Queue / Redis errors ---
213
+ if (error.code === ErrorCode.QUEUE_CONNECTION_FAILED) {
214
+ return new CtaError("ERROR_QUEUE_CONNECTION", LEGACY_QUEUE_ERROR_MESSAGE, LEGACY_QUEUE_ERROR_CAUSES, LEGACY_QUEUE_ERROR_RECOVERY, ctx);
215
+ }
216
+ // Unknown code from core - fall through to regex
217
+ return null;
218
+ }
219
+ // ---------------------------------------------------------------------------
220
+ // Regex-based fallback for untyped errors
221
+ // ---------------------------------------------------------------------------
222
+ function formatByRegex(error) {
223
+ const errorMessage = error instanceof Error ? error.message : String(error);
224
+ const errorString = errorMessage.toLowerCase();
225
+ // Extract context from error message
226
+ const environmentUrlMatch = errorMessage.match(/environment:?\s+(https?:\/\/[^\s]+)/i);
227
+ const clientIdMatch = errorMessage.match(/client\s+id:?\s+([a-f0-9-]+)/i);
228
+ const context = {};
229
+ if (environmentUrlMatch) {
230
+ context.environmentUrl = environmentUrlMatch[1];
231
+ }
232
+ if (clientIdMatch) {
233
+ context.clientId = clientIdMatch[1];
234
+ }
235
+ // GDAP/App user missing
236
+ if (errorString.includes("not a member of the organization") ||
237
+ errorString.includes("not a member of") ||
238
+ errorString.includes("application is not registered")) {
239
+ return new CtaError("ERROR_GDAP_MISSING", "Application user not registered in Power Platform environment", [
240
+ "The application is not configured as a user in the target environment",
241
+ "The app registration may not have been added to the environment yet",
242
+ "GDAP (Granular Delegated Admin Privileges) relationship may not be established",
243
+ ], [
244
+ "Go to https://admin.powerplatform.microsoft.com",
245
+ "Select the target environment \u2192 Settings \u2192 Users + permissions \u2192 Application users",
246
+ 'Click "+ New app user" and add your application',
247
+ context.clientId
248
+ ? `Use Client ID: ${context.clientId}`
249
+ : "Use the Client ID from your partner configuration",
250
+ 'Assign the "System Administrator" security role',
251
+ "Save and retry the command",
252
+ ], context);
253
+ }
254
+ // Permission/privilege errors
255
+ if (errorString.includes("prvread") ||
256
+ errorString.includes("prvwrite") ||
257
+ errorString.includes("prvcreate") ||
258
+ errorString.includes("prvdelete") ||
259
+ errorString.includes("privilege") ||
260
+ errorString.includes("insufficient") ||
261
+ errorString.includes("access") ||
262
+ errorString.includes("403")) {
263
+ return new CtaError("ERROR_INSUFFICIENT_PERMISSIONS", "Application user lacks required permissions in Power Platform environment", [
264
+ "The application user exists but doesn't have necessary security roles",
265
+ "The System Administrator role may not be assigned",
266
+ "Solution-specific permissions (prvReadSolution, prvWriteSolution, etc.) are missing",
267
+ ], [
268
+ "Go to https://admin.powerplatform.microsoft.com",
269
+ "Select the target environment \u2192 Settings \u2192 Users + permissions \u2192 Application users",
270
+ context.clientId
271
+ ? `Find your application user (Client ID: ${context.clientId})`
272
+ : "Find your application user",
273
+ 'Click "Manage security roles" or "Edit"',
274
+ 'Ensure "System Administrator" role is assigned',
275
+ "Verify the role includes solution deployment privileges (prvReadSolution, prvWriteSolution, prvCreateSolution)",
276
+ "Save and retry the command",
277
+ ], context);
278
+ }
279
+ // Authentication/token errors
280
+ if (errorString.includes("401") ||
281
+ errorString.includes("unauthorized") ||
282
+ errorString.includes("authentication failed") ||
283
+ errorString.includes("token")) {
284
+ return new CtaError("ERROR_AUTH_FAILED", "Authentication failed - unable to acquire or validate access token", [
285
+ "The client secret may have expired",
286
+ "API permissions may not be configured correctly in Azure AD",
287
+ "Admin consent may not have been granted for the required permissions",
288
+ ], [
289
+ "Verify the app registration in Azure Portal:",
290
+ " - Go to https://portal.azure.com \u2192 Azure Active Directory \u2192 App registrations",
291
+ context.clientId
292
+ ? ` - Find your app (Client ID: ${context.clientId})`
293
+ : " - Locate your application registration",
294
+ "Check API permissions:",
295
+ ' - Ensure "Dynamics CRM" or "Common Data Service" API permission is added',
296
+ ' - Permission should be "user_impersonation" (delegated) or ".default" (application)',
297
+ ' - Click "Grant admin consent" if not already done',
298
+ "Verify client secret:",
299
+ " - Check if the secret has expired in the app registration",
300
+ " - Generate a new secret if needed and update your environment variable (PARTNER_CLIENT_SECRET)",
301
+ "Retry the command",
302
+ ], context);
303
+ }
304
+ // Solution not found
305
+ if ((errorString.includes("not found") || errorString.includes("404")) &&
306
+ (errorString.includes("solution") || errorString.includes("agent"))) {
307
+ // Try to extract solution name from message
308
+ const solutionMatch = errorMessage.match(/solution\s+'([^']+)'|solution\s+"([^"]+)"/i);
309
+ if (solutionMatch) {
310
+ context.solutionName = solutionMatch[1] || solutionMatch[2];
311
+ }
312
+ return new CtaError("ERROR_SOLUTION_NOT_FOUND", context.solutionName
313
+ ? `Solution '${context.solutionName}' not found in environment`
314
+ : "Solution not found in environment", [
315
+ "The solution may not exist in the source environment",
316
+ "The solution name may be misspelled (names are case-sensitive)",
317
+ "The solution may have been deleted or renamed",
318
+ ], [
319
+ context.solutionName
320
+ ? `Verify the solution name '${context.solutionName}' is correct`
321
+ : "Verify the solution name is correct and matches exactly (case-sensitive)",
322
+ "List available solutions in the source environment:",
323
+ " solutions list",
324
+ "Check that you're connected to the correct source environment",
325
+ "Ensure the solution is published and visible in the source environment",
326
+ "Retry with the correct solution name",
327
+ ], context);
328
+ }
329
+ // Network errors
330
+ if (errorString.includes("econnrefused") ||
331
+ errorString.includes("etimedout") ||
332
+ errorString.includes("enotfound") ||
333
+ errorString.includes("network") ||
334
+ errorString.includes("fetch failed")) {
335
+ return new CtaError("ERROR_NETWORK", "Network connection failed", [
336
+ "The target environment URL may be incorrect or unreachable",
337
+ "Network connectivity issues (firewall, proxy, DNS)",
338
+ "The Power Platform environment may be temporarily unavailable",
339
+ ], [
340
+ "Verify the environment URL is correct:",
341
+ context.environmentUrl
342
+ ? ` Current: ${context.environmentUrl}`
343
+ : " Check your configuration file for the correct URL",
344
+ "Test network connectivity:",
345
+ context.environmentUrl
346
+ ? ` curl -I ${context.environmentUrl}`
347
+ : " Use curl or ping to test the environment URL",
348
+ "Check firewall/proxy settings that may block Power Platform endpoints",
349
+ "Verify DNS resolution for the environment hostname",
350
+ "If using a VPN, ensure it's connected and configured properly",
351
+ "Check Power Platform service status: https://admin.powerplatform.microsoft.com/service-health",
352
+ "Retry the command after resolving connectivity issues",
353
+ ], context);
354
+ }
355
+ // Config/file not found
356
+ if (errorString.includes("not found") &&
357
+ (errorString.includes("config") ||
358
+ errorString.includes("file") ||
359
+ errorString.includes("enoent"))) {
360
+ return new CtaError("ERROR_CONFIG_NOT_FOUND", "Configuration file or required resource not found", [
361
+ "The configuration file may not exist at the specified path",
362
+ "The working directory may be incorrect",
363
+ "Required files may have been deleted or moved",
364
+ ], [
365
+ "Verify you're in the correct directory (should contain config/ folder)",
366
+ "Check if the configuration file exists:",
367
+ " ls -la ./config/tenants.yaml",
368
+ "If the config file doesn't exist, initialize a new configuration:",
369
+ " init",
370
+ "Specify a custom config path with --config flag if needed:",
371
+ " deploy --config /path/to/config.yaml ...",
372
+ ], context);
373
+ }
374
+ // Redis/queue connection errors
375
+ if (errorString.includes("redis") ||
376
+ errorString.includes("queue") ||
377
+ (errorString.includes("connection") && errorString.includes("refused"))) {
378
+ return new CtaError("ERROR_QUEUE_CONNECTION", LEGACY_QUEUE_ERROR_MESSAGE, LEGACY_QUEUE_ERROR_CAUSES, LEGACY_QUEUE_ERROR_RECOVERY, context);
379
+ }
380
+ // Generic fallback
381
+ return new CtaError("ERROR_UNKNOWN", errorMessage, [
382
+ "An unexpected error occurred",
383
+ "The error details are shown above",
384
+ "This may be a temporary issue or a bug in Pax8 CTA",
385
+ ], [
386
+ "Review the error message above for specific details",
387
+ "Check the Pax8 CTA documentation for common issues",
388
+ "Verify your configuration and environment setup",
389
+ "Try the command again with --verbose flag for more details (if available)",
390
+ "If the issue persists, please report it on GitHub with the error details",
391
+ " https://github.com/pax8labs/pax8-cta/issues",
392
+ ], context);
393
+ }
394
+ // ---------------------------------------------------------------------------
395
+ // Public API
396
+ // ---------------------------------------------------------------------------
397
+ /**
398
+ * Maps any error to a structured CtaError with recovery guidance.
399
+ *
400
+ * 1. If the error is a typed CtaError from @pax8-cta/core, the
401
+ * error code is used to select the appropriate guidance (no regex).
402
+ * 2. Otherwise, falls back to regex matching on the error message.
403
+ */
404
+ export function formatError(error) {
405
+ // Fast path: structured error from core with a known code
406
+ if (isCtaError(error)) {
407
+ const result = formatByErrorCode(error);
408
+ if (result) {
409
+ return result;
410
+ }
411
+ }
412
+ // Slow path: regex fallback for plain Error / string / unknown
413
+ return formatByRegex(error);
414
+ }
415
+ /**
416
+ * Prints a formatted error message with recovery guidance
417
+ */
418
+ export function printError(error) {
419
+ console.error();
420
+ console.error(chalk.red.bold(`Error: ${error.message}`), chalk.gray(`(${error.code})`));
421
+ console.error();
422
+ // Possible causes
423
+ console.error(chalk.yellow.bold("Possible causes:"));
424
+ error.causes.forEach((cause) => {
425
+ console.error(chalk.yellow(` \u2022 ${cause}`));
426
+ });
427
+ console.error();
428
+ // Recovery steps
429
+ console.error(chalk.cyan.bold("To fix:"));
430
+ error.recovery.forEach((step, index) => {
431
+ // Check if this is a sub-step (starts with spaces/dash)
432
+ if (step.startsWith(" ")) {
433
+ console.error(chalk.cyan(` ${step.trim()}`));
434
+ }
435
+ else {
436
+ console.error(chalk.cyan(` ${index + 1}. ${step}`));
437
+ }
438
+ });
439
+ console.error();
440
+ // Context information
441
+ if (error.context && Object.keys(error.context).length > 0) {
442
+ console.error(chalk.gray.bold("Context:"));
443
+ if (error.context.environmentUrl) {
444
+ console.error(chalk.gray(` Environment: ${error.context.environmentUrl}`));
445
+ }
446
+ if (error.context.tenantName) {
447
+ console.error(chalk.gray(` Tenant: ${error.context.tenantName}`));
448
+ }
449
+ if (error.context.solutionName) {
450
+ console.error(chalk.gray(` Solution: ${error.context.solutionName}`));
451
+ }
452
+ if (error.context.clientId) {
453
+ console.error(chalk.gray(` Client ID: ${error.context.clientId}`));
454
+ }
455
+ console.error();
456
+ }
457
+ }
458
+ //# sourceMappingURL=error-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../src/lib/error-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAEL,SAAS,EACT,SAAS,EACT,aAAa,EACb,oBAAoB,EACpB,qBAAqB,EACrB,YAAY,EACZ,SAAS,EACT,UAAU,GACX,MAAM,gBAAgB,CAAC;AAExB,MAAM,0BAA0B,GAC9B,uEAAuE,CAAC;AAC1E,MAAM,yBAAyB,GAAG;IAChC,wEAAwE;IACxE,uDAAuD;IACvD,wEAAwE;CACzE,CAAC;AACF,MAAM,2BAA2B,GAAG;IAClC,wDAAwD;IACxD,yCAAyC;IACzC,gDAAgD;IAChD,2EAA2E;CAC5E,CAAC;AAEF;;;;;GAKG;AACH,MAAM,OAAO,QAAS,SAAQ,KAAK;IAEf;IAEA;IACA;IACA;IALlB,YACkB,IAAY,EAC5B,OAAe,EACC,MAAgB,EAChB,QAAkB,EAClB,OAKf;QAED,KAAK,CAAC,OAAO,CAAC,CAAC;QAXC,SAAI,GAAJ,IAAI,CAAQ;QAEZ,WAAM,GAAN,MAAM,CAAU;QAChB,aAAQ,GAAR,QAAQ,CAAU;QAClB,YAAO,GAAP,OAAO,CAKtB;QAGD,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IACzB,CAAC;CACF;AAED,8EAA8E;AAC9E,4DAA4D;AAC5D,8EAA8E;AAE9E,SAAS,iBAAiB,CAAC,KAAgB;IACzC,MAAM,GAAG,GAAwB;QAC/B,cAAc,EAAE,KAAK,CAAC,OAAO,EAAE,cAAoC;QACnE,UAAU,EAAE,KAAK,CAAC,O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liance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ /**
17
+ * Base CLI error with exit code.
18
+ * Exit code 1 = runtime error (config not found, network failure, etc.)
19
+ */
20
+ export declare class CliError extends Error {
21
+ exitCode: number;
22
+ constructor(message: string, exitCode?: number);
23
+ }
24
+ /**
25
+ * Usage error — invalid options, missing required args, etc.
26
+ * Exit code 2.
27
+ */
28
+ export declare class UsageError extends CliError {
29
+ constructor(message: string);
30
+ }
31
+ /**
32
+ * Spinner-like interface for cleanup. Matches the ora spinner API subset we use.
33
+ */
34
+ interface SpinnerLike {
35
+ fail: (text?: string) => void;
36
+ isSpinning?: boolean;
37
+ }
38
+ /**
39
+ * Detect whether JSON output mode is active.
40
+ *
41
+ * Two signals (OR'd):
42
+ * 1. `--json` is present anywhere in process.argv (simple substring check).
43
+ * 2. stdout is not a TTY (piped/redirected).
44
+ *
45
+ * Exported so that issue #345 (proper Commander-driven --json flag) can replace
46
+ * this with a single authoritative source of truth once that flag lands.
47
+ */
48
+ export declare function isJsonOutputMode(): boolean;
49
+ /**
50
+ * Standard error handler for CLI commands.
51
+ *
52
+ * - Stops the spinner with a fail message
53
+ * - When JSON mode is active (--json flag or piped stdout), emits a single JSON
54
+ * object to stderr with structured `code`, `message`, `causes`, and `recovery`
55
+ * fields — suitable for LLM-agent consumption.
56
+ * - Otherwise, uses the human-formatted handler (formatError/printError).
57
+ * - Exits with the appropriate code (1=runtime, 2=usage).
58
+ */
59
+ export declare function handleCommandError(error: unknown, spinner?: SpinnerLike | null, failMessage?: string): never;
60
+ export {};
61
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/lib/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH;;;GAGG;AACH,qBAAa,QAAS,SAAQ,KAAK;IAGxB,QAAQ,EAAE,MAAM;gBADvB,OAAO,EAAE,MAAM,EACR,QAAQ,GAAE,MAAU;CAK9B;AAED;;;GAGG;AACH,qBAAa,UAAW,SAAQ,QAAQ;gBAC1B,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,UAAU,WAAW;IACnB,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAsFD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,OAAO,EACd,OAAO,CAAC,EAAE,WAAW,GAAG,IAAI,EAC5B,WAAW,CAAC,EAAE,MAAM,GACnB,KAAK,CA8BP"}