@microsoft/managed-apps-cli 0.6.1 → 0.8.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 (207) hide show
  1. package/README.md +56 -10
  2. package/dist/ArgumentProvider.d.ts +21 -2
  3. package/dist/ArgumentProvider.d.ts.map +1 -1
  4. package/dist/ArgumentProvider.js +47 -3
  5. package/dist/ArgumentProvider.js.map +1 -1
  6. package/dist/Authentication/ActiveAccountStore.d.ts +24 -0
  7. package/dist/Authentication/ActiveAccountStore.d.ts.map +1 -0
  8. package/dist/Authentication/ActiveAccountStore.js +54 -0
  9. package/dist/Authentication/ActiveAccountStore.js.map +1 -0
  10. package/dist/Authentication/NodeMsalAuthenticationProvider.d.ts +57 -3
  11. package/dist/Authentication/NodeMsalAuthenticationProvider.d.ts.map +1 -1
  12. package/dist/Authentication/NodeMsalAuthenticationProvider.js +187 -27
  13. package/dist/Authentication/NodeMsalAuthenticationProvider.js.map +1 -1
  14. package/dist/Cli.d.ts.map +1 -1
  15. package/dist/Cli.js +8 -2
  16. package/dist/Cli.js.map +1 -1
  17. package/dist/CliSettings.d.ts.map +1 -1
  18. package/dist/CliSettings.js +1 -2
  19. package/dist/CliSettings.js.map +1 -1
  20. package/dist/CliUtils.d.ts +2 -1
  21. package/dist/CliUtils.d.ts.map +1 -1
  22. package/dist/CliUtils.js +4 -0
  23. package/dist/CliUtils.js.map +1 -1
  24. package/dist/Constants/CommandRegistry.d.ts.map +1 -1
  25. package/dist/Constants/CommandRegistry.js +44 -6
  26. package/dist/Constants/CommandRegistry.js.map +1 -1
  27. package/dist/Constants/HelpStrings.d.ts +75 -3
  28. package/dist/Constants/HelpStrings.d.ts.map +1 -1
  29. package/dist/Constants/HelpStrings.js +143 -41
  30. package/dist/Constants/HelpStrings.js.map +1 -1
  31. package/dist/Errors/GitHubErrorMap.d.ts +3 -3
  32. package/dist/Errors/GitHubErrorMap.d.ts.map +1 -1
  33. package/dist/Errors/GitHubErrorMap.js +12 -7
  34. package/dist/Errors/GitHubErrorMap.js.map +1 -1
  35. package/dist/FS/CliFs.d.ts.map +1 -1
  36. package/dist/FS/CliFs.js.map +1 -1
  37. package/dist/HttpClient/CliHttpClient.d.ts +17 -0
  38. package/dist/HttpClient/CliHttpClient.d.ts.map +1 -1
  39. package/dist/HttpClient/CliHttpClient.js +112 -1
  40. package/dist/HttpClient/CliHttpClient.js.map +1 -1
  41. package/dist/Logger/CliLogger.d.ts.map +1 -1
  42. package/dist/Logger/CliLogger.js +1 -1
  43. package/dist/Logger/CliLogger.js.map +1 -1
  44. package/dist/Logger/ConsoleWriter.d.ts.map +1 -1
  45. package/dist/Logger/ConsoleWriter.js +7 -7
  46. package/dist/Logger/ConsoleWriter.js.map +1 -1
  47. package/dist/Middletier/FunctionsBundler.d.ts +17 -0
  48. package/dist/Middletier/FunctionsBundler.d.ts.map +1 -0
  49. package/dist/Middletier/FunctionsBundler.js +165 -0
  50. package/dist/Middletier/FunctionsBundler.js.map +1 -0
  51. package/dist/Middletier/PackFunctions.d.ts +52 -0
  52. package/dist/Middletier/PackFunctions.d.ts.map +1 -0
  53. package/dist/Middletier/PackFunctions.js +122 -0
  54. package/dist/Middletier/PackFunctions.js.map +1 -0
  55. package/dist/Types/Cli.types.d.ts +42 -1
  56. package/dist/Types/Cli.types.d.ts.map +1 -1
  57. package/dist/Types/Command.types.d.ts +14 -3
  58. package/dist/Types/Command.types.d.ts.map +1 -1
  59. package/dist/Types/Command.types.js +4 -0
  60. package/dist/Types/Command.types.js.map +1 -1
  61. package/dist/Utils/BuildPolling.d.ts +18 -0
  62. package/dist/Utils/BuildPolling.d.ts.map +1 -0
  63. package/dist/Utils/BuildPolling.js +63 -0
  64. package/dist/Utils/BuildPolling.js.map +1 -0
  65. package/dist/Utils/BuildVerbDescriptionTable.d.ts +11 -1
  66. package/dist/Utils/BuildVerbDescriptionTable.d.ts.map +1 -1
  67. package/dist/Utils/BuildVerbDescriptionTable.js +73 -17
  68. package/dist/Utils/BuildVerbDescriptionTable.js.map +1 -1
  69. package/dist/Utils/ConsoleOutput.d.ts.map +1 -1
  70. package/dist/Utils/ConsoleOutput.js +15 -12
  71. package/dist/Utils/ConsoleOutput.js.map +1 -1
  72. package/dist/Utils/DcfRecovery.d.ts +84 -0
  73. package/dist/Utils/DcfRecovery.d.ts.map +1 -0
  74. package/dist/Utils/DcfRecovery.js +258 -0
  75. package/dist/Utils/DcfRecovery.js.map +1 -0
  76. package/dist/Utils/EnhanceNetworkError.d.ts.map +1 -1
  77. package/dist/Utils/EnhanceNetworkError.js +2 -0
  78. package/dist/Utils/EnhanceNetworkError.js.map +1 -1
  79. package/dist/Utils/EnvVars.d.ts +1 -1
  80. package/dist/Utils/EnvVars.d.ts.map +1 -1
  81. package/dist/Utils/EnvVars.js.map +1 -1
  82. package/dist/Utils/EnvironmentRoutingUtils.d.ts +8 -0
  83. package/dist/Utils/EnvironmentRoutingUtils.d.ts.map +1 -0
  84. package/dist/Utils/EnvironmentRoutingUtils.js +45 -0
  85. package/dist/Utils/EnvironmentRoutingUtils.js.map +1 -0
  86. package/dist/Utils/GitHubDcfFlow.d.ts +4 -5
  87. package/dist/Utils/GitHubDcfFlow.d.ts.map +1 -1
  88. package/dist/Utils/GitHubDcfFlow.js +4 -5
  89. package/dist/Utils/GitHubDcfFlow.js.map +1 -1
  90. package/dist/Utils/GitUtils.d.ts +5 -0
  91. package/dist/Utils/GitUtils.d.ts.map +1 -1
  92. package/dist/Utils/GitUtils.js +15 -0
  93. package/dist/Utils/GitUtils.js.map +1 -1
  94. package/dist/Utils/Paging.d.ts.map +1 -1
  95. package/dist/Utils/Paging.js +4 -4
  96. package/dist/Utils/Paging.js.map +1 -1
  97. package/dist/Utils/ResolveCommand.d.ts +7 -1
  98. package/dist/Utils/ResolveCommand.d.ts.map +1 -1
  99. package/dist/Utils/ResolveCommand.js +38 -20
  100. package/dist/Utils/ResolveCommand.js.map +1 -1
  101. package/dist/Utils/Spinner.d.ts +9 -1
  102. package/dist/Utils/Spinner.d.ts.map +1 -1
  103. package/dist/Utils/Spinner.js +25 -5
  104. package/dist/Utils/Spinner.js.map +1 -1
  105. package/dist/Verbs/AddAction.d.ts.map +1 -1
  106. package/dist/Verbs/AddAction.js +12 -41
  107. package/dist/Verbs/AddAction.js.map +1 -1
  108. package/dist/Verbs/AddConnector.d.ts +24 -0
  109. package/dist/Verbs/AddConnector.d.ts.map +1 -0
  110. package/dist/Verbs/AddConnector.js +156 -0
  111. package/dist/Verbs/AddConnector.js.map +1 -0
  112. package/dist/Verbs/AddConnectorFlows.d.ts +72 -0
  113. package/dist/Verbs/AddConnectorFlows.d.ts.map +1 -0
  114. package/dist/Verbs/AddConnectorFlows.js +198 -0
  115. package/dist/Verbs/AddConnectorFlows.js.map +1 -0
  116. package/dist/Verbs/AddDataSource.js +1 -1
  117. package/dist/Verbs/AddDataSource.js.map +1 -1
  118. package/dist/Verbs/AddTable.d.ts.map +1 -1
  119. package/dist/Verbs/AddTable.js +15 -100
  120. package/dist/Verbs/AddTable.js.map +1 -1
  121. package/dist/Verbs/AuthStatus.d.ts.map +1 -1
  122. package/dist/Verbs/AuthStatus.js +34 -6
  123. package/dist/Verbs/AuthStatus.js.map +1 -1
  124. package/dist/Verbs/AuthSwitch.d.ts +6 -0
  125. package/dist/Verbs/AuthSwitch.d.ts.map +1 -0
  126. package/dist/Verbs/AuthSwitch.js +67 -0
  127. package/dist/Verbs/AuthSwitch.js.map +1 -0
  128. package/dist/Verbs/BuildMaafApp.d.ts.map +1 -1
  129. package/dist/Verbs/BuildMaafApp.js +98 -22
  130. package/dist/Verbs/BuildMaafApp.js.map +1 -1
  131. package/dist/Verbs/ConnectorHelpers.d.ts +54 -1
  132. package/dist/Verbs/ConnectorHelpers.d.ts.map +1 -1
  133. package/dist/Verbs/ConnectorHelpers.js +217 -16
  134. package/dist/Verbs/ConnectorHelpers.js.map +1 -1
  135. package/dist/Verbs/CreateMaafApp.d.ts +75 -0
  136. package/dist/Verbs/CreateMaafApp.d.ts.map +1 -1
  137. package/dist/Verbs/CreateMaafApp.js +273 -75
  138. package/dist/Verbs/CreateMaafApp.js.map +1 -1
  139. package/dist/Verbs/DeployMaafApp.d.ts.map +1 -1
  140. package/dist/Verbs/DeployMaafApp.js +52 -20
  141. package/dist/Verbs/DeployMaafApp.js.map +1 -1
  142. package/dist/Verbs/Dev.js +5 -5
  143. package/dist/Verbs/Dev.js.map +1 -1
  144. package/dist/Verbs/GetMaafBuildStatus.d.ts.map +1 -1
  145. package/dist/Verbs/GetMaafBuildStatus.js +66 -17
  146. package/dist/Verbs/GetMaafBuildStatus.js.map +1 -1
  147. package/dist/Verbs/Init.d.ts.map +1 -1
  148. package/dist/Verbs/Init.js +170 -60
  149. package/dist/Verbs/Init.js.map +1 -1
  150. package/dist/Verbs/ListConnectors.d.ts.map +1 -1
  151. package/dist/Verbs/ListConnectors.js +4 -2
  152. package/dist/Verbs/ListConnectors.js.map +1 -1
  153. package/dist/Verbs/ListDatasets.d.ts.map +1 -1
  154. package/dist/Verbs/ListDatasets.js +5 -0
  155. package/dist/Verbs/ListDatasets.js.map +1 -1
  156. package/dist/Verbs/ListFlows.d.ts.map +1 -1
  157. package/dist/Verbs/ListFlows.js +1 -2
  158. package/dist/Verbs/ListFlows.js.map +1 -1
  159. package/dist/Verbs/ListSqlStoredProcedures.d.ts.map +1 -1
  160. package/dist/Verbs/ListSqlStoredProcedures.js +5 -0
  161. package/dist/Verbs/ListSqlStoredProcedures.js.map +1 -1
  162. package/dist/Verbs/ListTables.d.ts.map +1 -1
  163. package/dist/Verbs/ListTables.js +5 -0
  164. package/dist/Verbs/ListTables.js.map +1 -1
  165. package/dist/Verbs/Login.d.ts.map +1 -1
  166. package/dist/Verbs/Login.js +16 -13
  167. package/dist/Verbs/Login.js.map +1 -1
  168. package/dist/Verbs/Logout.d.ts.map +1 -1
  169. package/dist/Verbs/Logout.js +19 -13
  170. package/dist/Verbs/Logout.js.map +1 -1
  171. package/dist/Verbs/MaafAppPermissions.d.ts.map +1 -1
  172. package/dist/Verbs/MaafAppPermissions.js +4 -0
  173. package/dist/Verbs/MaafAppPermissions.js.map +1 -1
  174. package/dist/Verbs/Pack.d.ts +6 -6
  175. package/dist/Verbs/Pack.d.ts.map +1 -1
  176. package/dist/Verbs/Pack.js +80 -12
  177. package/dist/Verbs/Pack.js.map +1 -1
  178. package/dist/Verbs/PlayMaafApp.d.ts +22 -0
  179. package/dist/Verbs/PlayMaafApp.d.ts.map +1 -0
  180. package/dist/Verbs/PlayMaafApp.js +147 -0
  181. package/dist/Verbs/PlayMaafApp.js.map +1 -0
  182. package/dist/Verbs/RefreshDataSource.d.ts.map +1 -1
  183. package/dist/Verbs/RefreshDataSource.js.map +1 -1
  184. package/dist/Verbs/RefreshGitAuth.d.ts.map +1 -1
  185. package/dist/Verbs/RefreshGitAuth.js +1 -1
  186. package/dist/Verbs/RefreshGitAuth.js.map +1 -1
  187. package/dist/Verbs/ShareLinkCreate.d.ts +23 -0
  188. package/dist/Verbs/ShareLinkCreate.d.ts.map +1 -0
  189. package/dist/Verbs/ShareLinkCreate.js +73 -0
  190. package/dist/Verbs/ShareLinkCreate.js.map +1 -0
  191. package/dist/Verbs/ShareLinkList.d.ts +16 -0
  192. package/dist/Verbs/ShareLinkList.d.ts.map +1 -0
  193. package/dist/Verbs/ShareLinkList.js +84 -0
  194. package/dist/Verbs/ShareLinkList.js.map +1 -0
  195. package/dist/Verbs/ShareLinkRevoke.d.ts +22 -0
  196. package/dist/Verbs/ShareLinkRevoke.d.ts.map +1 -0
  197. package/dist/Verbs/ShareLinkRevoke.js +137 -0
  198. package/dist/Verbs/ShareLinkRevoke.js.map +1 -0
  199. package/dist/Verbs/VerbConstants.d.ts +151 -21
  200. package/dist/Verbs/VerbConstants.d.ts.map +1 -1
  201. package/dist/Verbs/VerbConstants.js +127 -21
  202. package/dist/Verbs/VerbConstants.js.map +1 -1
  203. package/dist/Verbs/index.d.ts +6 -0
  204. package/dist/Verbs/index.d.ts.map +1 -1
  205. package/dist/Verbs/index.js +6 -0
  206. package/dist/Verbs/index.js.map +1 -1
  207. package/package.json +8 -8
@@ -1,17 +1,23 @@
1
1
  /*!
2
2
  * Copyright (C) Microsoft Corporation. All rights reserved.
3
3
  */
4
- import { createConnectionAsync, getConnectorAsync, getEffectiveConnectorDataPolicyAsync, getPlayerServiceConfig, listConnectionsForConnectorAsync, } from '@microsoft/managed-apps-actions';
4
+ import { createConnectionAsync, getConnectorAsync, getEffectiveConnectorDataPolicyAsync, getPlayerServiceConfig, isSsoOnlyConnector, listConnectionsForConnectorAsync, requestConnectionUserConsentAsync, } from '@microsoft/managed-apps-actions';
5
+ import { createMaafConnectionUrl, HttpClientError } from '@microsoft/managed-apps-common/services';
6
+ import * as http from 'http';
7
+ import open from 'open';
5
8
  import { getCliLogger, getSettings } from '../CliSettings.js';
6
9
  import { promptSelect } from '../CliUtils.js';
7
10
  import { CLI_BINARY_NAME } from '../Constants/CliConstants.js';
8
- import { NotFoundError, UsageError } from '../Errors/CliError.js';
9
- import { printTable, printWarning } from '../Utils/ConsoleOutput.js';
11
+ import { AppError, NotFoundError, UsageError } from '../Errors/CliError.js';
12
+ import { printInfo, printSuccess, printTable, printWarning } from '../Utils/ConsoleOutput.js';
13
+ import { getCliEnvVarBool } from '../Utils/EnvVars.js';
10
14
  const ALLOW_ALL_POLICY = {
11
15
  defaultBehavior: 'Allow',
12
16
  allowedConnectors: [],
13
17
  };
14
18
  const CREATE_NEW_CONNECTION = '__create__';
19
+ const CONNECTION_CREATION_TIMEOUT_MS = 10 * 60 * 1000; // 10 minutes
20
+ const PROTOCOL_VERSION = '1';
15
21
  /**
16
22
  * Preflight step shared by `app add action` and `app add table`. Fetches the
17
23
  * connector and effective DLP policy in parallel, then enforces the policy.
@@ -57,7 +63,7 @@ export async function runConnectorDlpPreflightAsync(argumentProvider, apiId) {
57
63
  if (isBlocked) {
58
64
  throw new UsageError(`Connector '${connector.properties.displayName ?? apiId}' is blocked by your organization's DLP policy.`);
59
65
  }
60
- return { connector, tenantId };
66
+ return { connector, tenantId, policy };
61
67
  }
62
68
  /**
63
69
  * Resolves a connection for a connector. In interactive mode, lists the
@@ -96,21 +102,216 @@ export async function resolveConnectionInteractivelyAsync(options) {
96
102
  options: choices,
97
103
  });
98
104
  if (selected === CREATE_NEW_CONNECTION) {
99
- const newConnection = await createConnectionAsync({
100
- vfs: cliFs,
101
- authProvider,
105
+ // Only attempt SSO when the connector has a single auth type that is SSO-eligible.
106
+ // Connectors with multiple auth types need the browser flow so the user can choose.
107
+ if (isSsoOnlyConnector(connector)) {
108
+ try {
109
+ const newConnection = await createConnectionAsync({
110
+ vfs: cliFs,
111
+ authProvider,
112
+ region: playerServiceConfig.region,
113
+ environmentName: playerServiceConfig.environmentName,
114
+ actionsParams: { connectorId: apiId },
115
+ localFilePaths: {
116
+ appConfigPath: fileConfig.appConfigPath,
117
+ schemaPath: fileConfig.schemaPath,
118
+ codeGenPath: fileConfig.codeGenPath,
119
+ },
120
+ logger,
121
+ });
122
+ return newConnection.name;
123
+ }
124
+ catch (ssoError) {
125
+ printWarning(`Silent connection creation failed: ${ssoError instanceof Error ? ssoError.message : String(ssoError)}`);
126
+ printInfo('Falling back to browser-based connection creation...\n');
127
+ }
128
+ }
129
+ else {
130
+ printInfo('This connector requires manual interaction. Opening browser for connection creation...\n');
131
+ }
132
+ // Browser-based fallback: open the maaf-player connection dialog
133
+ const connectorName = apiId.startsWith('shared_') ? apiId : `shared_${apiId}`;
134
+ const result = await startConnectionServerAsync({
135
+ connectorName,
136
+ environmentId: playerServiceConfig.environmentName,
102
137
  region: playerServiceConfig.region,
103
- environmentName: playerServiceConfig.environmentName,
104
- actionsParams: { connectorId: apiId },
105
- localFilePaths: {
106
- appConfigPath: fileConfig.appConfigPath,
107
- schemaPath: fileConfig.schemaPath,
108
- codeGenPath: fileConfig.codeGenPath,
109
- },
110
- logger,
111
138
  });
112
- return newConnection.name;
139
+ if (result.status === 'created' && result.connectionName) {
140
+ printSuccess('Connection created successfully!');
141
+ if (result.displayName) {
142
+ printInfo(` Display Name: ${result.displayName}`);
143
+ }
144
+ printInfo(` Connection ID: ${result.connectionName}`);
145
+ return result.connectionName;
146
+ }
147
+ else if (result.status === 'error') {
148
+ throw new AppError(result.errorMessage ?? 'Connection creation failed in the browser.');
149
+ }
150
+ else {
151
+ throw new UsageError('Connection creation was cancelled.');
152
+ }
113
153
  }
114
154
  return selected;
115
155
  }
156
+ /**
157
+ * Best-effort request that the calling application be added to a connection's
158
+ * API Hubs ACL via the Power Platform user-consent endpoint. The server reads
159
+ * the calling app's `appid` from the bearer token, and the gateway resolves
160
+ * tenant + environment from the auth context and its routing config — so the
161
+ * CLI only needs to supply connector + connection identifiers, no body.
162
+ *
163
+ * Gating: requires the opt-in feature flag
164
+ * `MS_CLI_ENABLE_CONNECTOR_USER_CONSENT=true` (off by default while the
165
+ * consent endpoint is rolling out). When the flag is unset, the call is
166
+ * silently skipped — no warning, no telemetry, no HTTP traffic.
167
+ *
168
+ * Failure modes:
169
+ * - HTTP 403: emits a permission-specific warning explaining that the tenant
170
+ * admin must grant the calling app the
171
+ * `Connectivity.Connections.UserConsent` delegated permission, then returns.
172
+ * - Any other HTTP / network error: surfaces a generic warning and returns.
173
+ * The underlying `ConnectivityService` already records its own
174
+ * `scenario.failure` telemetry, so this helper doesn't re-emit a duplicate
175
+ * error event.
176
+ *
177
+ * Silent on success: a 200 OK does not guarantee the ACL was modified (the
178
+ * server has feature-gated silent-skip paths), so the success path emits no
179
+ * user-facing message.
180
+ *
181
+ * Never throws.
182
+ */
183
+ export async function requestCliUserConsentAsync(opts) {
184
+ if (!getCliEnvVarBool('ENABLE_CONNECTOR_USER_CONSENT')) {
185
+ return;
186
+ }
187
+ const { apiId, connectionId } = opts;
188
+ const logger = getCliLogger();
189
+ const scenario = logger.trackScenario('ConnectorUserConsent', { apiId, connectionId });
190
+ try {
191
+ await requestConnectionUserConsentAsync(apiId, connectionId, logger);
192
+ scenario.complete();
193
+ }
194
+ catch (error) {
195
+ if (error instanceof HttpClientError && error.status === 403) {
196
+ scenario.failure(error);
197
+ printWarning(`Could not request user consent on connection '${connectionId}' (HTTP 403). ` +
198
+ `The data source was added, but later calls against this connection may fail until ` +
199
+ `your tenant admin grants the calling application the ` +
200
+ `'Connectivity.Connections.UserConsent' delegated permission.`);
201
+ return;
202
+ }
203
+ scenario.failure(error);
204
+ const message = error instanceof Error ? error.message : String(error);
205
+ printWarning(`Could not request user consent on connection '${connectionId}': ${message}. ` +
206
+ `The data source was added, but later calls against this connection may fail.`);
207
+ }
208
+ }
209
+ /**
210
+ * Starts a local HTTP server, opens the maaf-player connection page in the
211
+ * browser, and waits for a callback with the result. Uses the same pattern
212
+ * as an OAuth authorization code flow: nonce for CSRF, protocol version for
213
+ * drift detection, and a timeout for cleanup.
214
+ */
215
+ export async function startConnectionServerAsync(config) {
216
+ const { connectorName, environmentId, region } = config;
217
+ const nonce = crypto.randomUUID();
218
+ return new Promise((resolve, reject) => {
219
+ const server = http.createServer((req, res) => {
220
+ const url = new URL(req.url ?? '/', `http://localhost`);
221
+ if (url.pathname === '/callback' && req.method === 'GET') {
222
+ const queryNonce = url.searchParams.get('nonce');
223
+ if (queryNonce !== nonce) {
224
+ res.writeHead(403, { 'Content-Type': 'text/html; charset=utf-8' });
225
+ res.end('<html><body><h2>Connection request verification failed. Please run the CLI command again.</h2></body></html>');
226
+ cleanup();
227
+ resolve({ status: 'cancelled' });
228
+ return;
229
+ }
230
+ const callbackVersion = url.searchParams.get('v');
231
+ if (callbackVersion !== PROTOCOL_VERSION) {
232
+ printWarning(`Warning: callback protocol version mismatch (expected ${PROTOCOL_VERSION}, got ${callbackVersion ?? 'none'}). Update the CLI to the latest version.`);
233
+ }
234
+ const status = url.searchParams.get('status');
235
+ const errorMessage = url.searchParams.get('message') ?? undefined;
236
+ res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
237
+ let tabHtml;
238
+ if (status === 'created') {
239
+ tabHtml =
240
+ '<html><body><h2>Connection created! You can close this tab.</h2></body></html>';
241
+ }
242
+ else if (status === 'error') {
243
+ const safeMessage = errorMessage
244
+ ? errorMessage.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`)
245
+ : '';
246
+ tabHtml = safeMessage
247
+ ? `<html><body><h2>Connection creation failed. You can close this tab.</h2><p>${safeMessage}</p></body></html>`
248
+ : '<html><body><h2>Connection creation failed. You can close this tab.</h2></body></html>';
249
+ }
250
+ else {
251
+ tabHtml =
252
+ '<html><body><h2>Connection creation cancelled. You can close this tab.</h2></body></html>';
253
+ }
254
+ res.end(tabHtml);
255
+ cleanup();
256
+ if (status === 'created') {
257
+ resolve({
258
+ status: 'created',
259
+ connectionId: url.searchParams.get('connectionId') ?? undefined,
260
+ connectionName: url.searchParams.get('connectionName') ?? undefined,
261
+ displayName: url.searchParams.get('displayName') ?? undefined,
262
+ });
263
+ }
264
+ else if (status === 'error') {
265
+ resolve({ status: 'error', errorMessage });
266
+ }
267
+ else {
268
+ resolve({ status: 'cancelled' });
269
+ }
270
+ return;
271
+ }
272
+ res.writeHead(404);
273
+ res.end('Not found');
274
+ });
275
+ // Listen on port 0 to let the OS assign an available port
276
+ server.listen(0, 'localhost', async () => {
277
+ const address = server.address();
278
+ const port = typeof address === 'object' && address ? address.port : 0;
279
+ const callbackUrl = `http://localhost:${port}/callback`;
280
+ const playerUrl = createMaafConnectionUrl(region, environmentId, {
281
+ connector: connectorName,
282
+ callbackUrl,
283
+ nonce,
284
+ protocolVersion: PROTOCOL_VERSION,
285
+ });
286
+ printInfo(`Opening browser at ${playerUrl}`);
287
+ try {
288
+ await open(playerUrl, { wait: false });
289
+ }
290
+ catch {
291
+ printInfo(`Could not open browser automatically. Please navigate to:\n ${playerUrl}`);
292
+ }
293
+ printInfo('Waiting for connection creation... (press Ctrl+C to cancel)\n');
294
+ });
295
+ server.on('error', (error) => {
296
+ cleanup();
297
+ reject(error);
298
+ });
299
+ const timeoutId = setTimeout(() => {
300
+ printInfo('\nConnection creation timed out after 10 minutes.');
301
+ cleanup();
302
+ resolve({ status: 'cancelled' });
303
+ }, CONNECTION_CREATION_TIMEOUT_MS);
304
+ const sigintHandler = () => {
305
+ printInfo('\nCancelling...');
306
+ cleanup();
307
+ resolve({ status: 'cancelled' });
308
+ };
309
+ function cleanup() {
310
+ clearTimeout(timeoutId);
311
+ process.off('SIGINT', sigintHandler);
312
+ server.close();
313
+ }
314
+ process.on('SIGINT', sigintHandler);
315
+ });
316
+ }
116
317
  //# sourceMappingURL=ConnectorHelpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ConnectorHelpers.js","sourceRoot":"","sources":["../../src/Verbs/ConnectorHelpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,oCAAoC,EACpC,sBAAsB,EACtB,gCAAgC,GACjC,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAElE,MAAM,gBAAgB,GAAiC;IACrD,eAAe,EAAE,OAAO;IACxB,iBAAiB,EAAE,EAAE;CACtB,CAAC;AAEF,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAE3C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,gBAAkC,EAClC,KAAa;IAEb,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;IAC9B,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,gBAAgB,EAAE,CAAC;IAE3D,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,C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AO,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -3,19 +3,74 @@
3
3
  */
4
4
  import { type RepoType } from '@microsoft/managed-apps-common/config';
5
5
  import type { ArgumentProvider } from '../ArgumentProvider.js';
6
+ /**
7
+ * Result of parsing the `--repo` flag value.
8
+ *
9
+ * - `native` (default): MAAF auto-provisions a platform-managed git repo, no remote URL.
10
+ * - `none`: source-control-free; no platform-managed repo, no remote URL.
11
+ * - `github`: bound to an external GitHub Enterprise repo at `remoteUrl`.
12
+ *
13
+ * `remoteUrl` is populated only when `repoType === 'github'`. This is a flat
14
+ * interface (not a discriminated union), so `if (repoType === 'github')` does NOT
15
+ * auto-narrow `remoteUrl` to `string`; github-branch use sites assert `remoteUrl!`.
16
+ */
6
17
  interface RepoSelection {
7
18
  repoType: RepoType;
8
19
  remoteUrl: string | undefined;
9
20
  }
21
+ /**
22
+ * Result of `commitAndPushScaffoldAsync`. Carried into the `--json` success
23
+ * envelope (as the `push` field) so automation can distinguish three states:
24
+ * push succeeded, push failed (with retry command), or no push attempted
25
+ * (field absent — e.g. `--repo none` where there is no remote).
26
+ */
27
+ interface PushOutcome {
28
+ success: boolean;
29
+ error?: Record<string, unknown>;
30
+ retryCommand?: string;
31
+ }
10
32
  /**
11
33
  * Maps the raw `--repo` flag value to a `(repoType, remoteUrl)` pair.
12
34
  * - omitted / empty → `native` (default GRS-backed flow)
13
35
  * - `none` (case-insensitive) → `none` (no GRS, no local setup)
14
36
  * - any other non-empty value → `github` (external GHE binding, value flows through as
15
37
  * `remoteUrl` to the action and the eventual git clone)
38
+ *
39
+ * Runtime invariant: `remoteUrl` is set iff `repoType === 'github'`. Consumers
40
+ * branch on `repoType` and assert `remoteUrl!` at github use sites — see
41
+ * `RepoSelection` for why narrowing is not automatic.
16
42
  */
17
43
  export declare function parseRepoOption(rawRepoValue: string | undefined): RepoSelection;
44
+ /**
45
+ * Creates a new MAAF app and (where applicable) sets up local source control.
46
+ *
47
+ * Three repo flows, selected by `--repo`:
48
+ * - `native` (default): server auto-provisions a GRS repo; local clone happens via GCM.
49
+ * - `github`: external GHE Cloud binding. Clones the user's repo locally. On the first
50
+ * `createAsync` call, a missing/expired server-side GitHub identity mapping is
51
+ * recoverable in-band: a single inline DCF run + exactly one `createAsync` retry.
52
+ * Any other error — or a second mapping failure after DCF — is a hard fail.
53
+ * - `none`: no git binding at all (just the server record + template + ms.config.json).
54
+ */
18
55
  export declare function createMaafAppAsync(argumentProvider: ArgumentProvider): Promise<void>;
56
+ /**
57
+ * Commits the scaffolded files and pushes to the remote. Called by both `native`
58
+ * and `github` flows after writeRepoConfig.
59
+ *
60
+ * Failure is non-fatal: prints a warning with the retry command and returns
61
+ * `{ success: false, ... }`. The server-side app and local scaffold are unchanged.
62
+ *
63
+ * `stdio: ['ignore', 'ignore', 'inherit']`:
64
+ * - stdin ignored: child can't prompt for input (would block forever).
65
+ * - stdout ignored: discards git's progress prose so pretty output stays clean.
66
+ * - stderr inherited: git's actual error messages reach the user's terminal
67
+ * so they see git's own context alongside our warning.
68
+ *
69
+ * Commit identity (user.name / user.email) is read by git itself from
70
+ * local-then-global config — we pass nothing. Missing identity surfaces as
71
+ * git's own descriptive commit error through the inherited stderr.
72
+ */
73
+ export declare function commitAndPushScaffoldAsync(appDir: string, jsonMode: boolean): Promise<PushOutcome>;
19
74
  interface CloneRepoOptions {
20
75
  directory: string;
21
76
  repoUrl: string;
@@ -52,6 +107,26 @@ export declare function ensureGitInstalled(): void;
52
107
  export declare function ensureTemplateSourceValid(source: string): void;
53
108
  export declare function ensureTargetDirectoryEmpty(appDir: string): void;
54
109
  export declare function ensureRepoTargetDirectoryEmpty(appDir: string): void;
110
+ /**
111
+ * Cheap pre-network probe to detect a non-empty remote BEFORE createAsync runs.
112
+ *
113
+ * Implementation: partial clone (`--depth=1 --filter=blob:none --no-checkout`)
114
+ * into an OS temp dir, then `git ls-tree -r HEAD`. The clone pulls refs + the
115
+ * tip commit + its tree objects only — no blob bytes, no working tree — so the
116
+ * bandwidth on the rejection path is tens of KB even for a multi-GB repo. The
117
+ * temp dir is removed in `finally`.
118
+ *
119
+ * Failure semantics — fail-OPEN:
120
+ * - Non-empty tree at HEAD → throws `UsageError` with the "is not empty" /
121
+ * "ms app init" actionable lead, BEFORE createAsync. No orphan, no leak.
122
+ * - Empty tree (incl. the cleaned-up-repo edge case: commit1 add, commit2
123
+ * delete all) → ls-tree returns no lines → returns without throwing.
124
+ * - Any error from git itself (auth, network blip, server doesn't support
125
+ * --filter, repo doesn't exist, etc.) → swallow and return. The subsequent
126
+ * cloneRepo will surface a friendlier message for the user-facing failure;
127
+ * we don't want this probe to become a parallel error-message surface.
128
+ */
129
+ export declare function ensureExternalRepoIsEmpty(repoUrl: string): void;
55
130
  export declare function ensureTargetDirectoryWritable(appDir: string): void;
56
131
  export {};
57
132
  //# sourceMappingURL=CreateMaafApp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CreateMaafApp.d.ts","sourceRoot":"","sources":["../../src/Verbs/CreateMaafApp.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AAezF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAsB5D,UAAU,aAAa;IACrB,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa,CAQ/E;AAED,wBAAsB,kBAAkB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CA0S1F;AAsDD,UAAU,gBAAgB;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;;;GAYG;AACH,wBAA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