@@ -13,28 +13,24 @@ import { selectCodeCatalystResource } from './wizards/selectResource'
13
13
import { openCodeCatalystUrl } from './utils'
14
14
import { CodeCatalystAuthenticationProvider } from './auth'
15
15
import { Commands } from '../shared/vscode/commands2'
16
- import {
17
- CodeCatalystClient ,
18
- ConnectedCodeCatalystClient ,
19
- CodeCatalystResource ,
20
- } from '../shared/clients/codecatalystClient'
21
- import { createClientFactory , DevEnvironmentId , getConnectedDevEnv , openDevEnv } from './model'
16
+ import { CodeCatalystClient , CodeCatalystResource , createClient } from '../shared/clients/codecatalystClient'
17
+ import { DevEnvironmentId , getConnectedDevEnv , openDevEnv } from './model'
22
18
import { showConfigureDevEnv } from './vue/configure/backend'
23
19
import { showCreateDevEnv } from './vue/create/backend'
24
20
import { CancellationError } from '../shared/utilities/timeoutUtils'
25
21
import { ToolkitError } from '../shared/errors'
26
22
import { telemetry } from '../shared/telemetry/telemetry'
27
23
import { showConfirmationMessage } from '../shared/utilities/messages'
28
24
import { AccountStatus } from '../shared/telemetry/telemetryClient'
29
- import { CreateDevEnvironmentRequest } from '../../types/clientcodecatalyst '
25
+ import { CreateDevEnvironmentRequest } from 'aws-sdk/clients/codecatalyst '
30
26
31
27
/** "List CodeCatalyst Commands" command. */
32
28
export async function listCommands ( ) : Promise < void > {
33
29
vscode . commands . executeCommand ( 'workbench.action.quickOpen' , '> CodeCatalyst' )
34
30
}
35
31
36
32
/** "Clone CodeCatalyst Repository" command. */
37
- export async function cloneCodeCatalystRepo ( client : ConnectedCodeCatalystClient , url ?: vscode . Uri ) : Promise < void > {
33
+ export async function cloneCodeCatalystRepo ( client : CodeCatalystClient , url ?: vscode . Uri ) : Promise < void > {
38
34
let resource : { name : string ; project : string ; org : string }
39
35
if ( ! url ) {
40
36
const r = await selectCodeCatalystResource ( client , 'repo' )
@@ -65,7 +61,7 @@ export async function cloneCodeCatalystRepo(client: ConnectedCodeCatalystClient,
65
61
* - "Open CodeCatalyst Repository"
66
62
*/
67
63
export async function openCodeCatalystResource (
68
- client : ConnectedCodeCatalystClient ,
64
+ client : CodeCatalystClient ,
69
65
kind : CodeCatalystResource [ 'type' ]
70
66
) : Promise < void > {
71
67
const resource = await selectCodeCatalystResource ( client , kind )
@@ -78,7 +74,7 @@ export async function openCodeCatalystResource(
78
74
}
79
75
80
76
export async function stopDevEnv (
81
- client : ConnectedCodeCatalystClient ,
77
+ client : CodeCatalystClient ,
82
78
devenv : DevEnvironmentId ,
83
79
opts ?: { readonly showPrompt ?: boolean }
84
80
) : Promise < void > {
@@ -102,7 +98,7 @@ export async function stopDevEnv(
102
98
} )
103
99
}
104
100
105
- export async function deleteDevEnv ( client : ConnectedCodeCatalystClient , devenv : DevEnvironmentId ) : Promise < void > {
101
+ export async function deleteDevEnv ( client : CodeCatalystClient , devenv : DevEnvironmentId ) : Promise < void > {
106
102
await client . deleteDevEnvironment ( {
107
103
id : devenv . id ,
108
104
projectName : devenv . project . name ,
@@ -116,7 +112,7 @@ export type DevEnvironmentSettings = Pick<
116
112
>
117
113
118
114
export async function updateDevEnv (
119
- client : ConnectedCodeCatalystClient ,
115
+ client : CodeCatalystClient ,
120
116
devenv : DevEnvironmentId ,
121
117
settings : DevEnvironmentSettings
122
118
) {
@@ -128,27 +124,16 @@ export async function updateDevEnv(
128
124
} )
129
125
}
130
126
131
- function createClientInjector (
132
- authProvider : CodeCatalystAuthenticationProvider ,
133
- clientFactory : ( ) => Promise < CodeCatalystClient >
134
- ) : ClientInjector {
127
+ function createClientInjector ( authProvider : CodeCatalystAuthenticationProvider ) : ClientInjector {
135
128
return async ( command , ...args ) => {
136
- let client = await clientFactory ( )
129
+ telemetry . record ( { userId : AccountStatus . NotSet } )
137
130
138
- try {
139
- if ( ! client . connected ) {
140
- const conn = await authProvider . promptNotConnected ( )
141
- client = await client . setCredentials ( async ( ) => ( await conn . getToken ( ) ) . accessToken )
142
- }
131
+ await authProvider . restore ( )
132
+ const conn = authProvider . activeConnection ?? ( await authProvider . promptNotConnected ( ) )
133
+ const client = await createClient ( conn )
134
+ telemetry . record ( { userId : client . identity . id } )
143
135
144
- return await command ( client , ...args )
145
- } finally {
146
- const userId = client . connected ? client . identity . id : AccountStatus . NotApplicable
147
-
148
- // TODO(sijaden): should this mark only instantiated spans or future spans as well?
149
- // right now it won't mark spans if they're created and emitted prior to the command finishing
150
- telemetry . record ( { userId } )
151
- }
136
+ return command ( client , ...args )
152
137
}
153
138
}
154
139
@@ -159,7 +144,7 @@ function createCommandDecorator(commands: CodeCatalystCommands): CommandDecorato
159
144
}
160
145
161
146
interface CodeCatalystCommand < T extends any [ ] , U > {
162
- ( client : ConnectedCodeCatalystClient , ...args : T ) : U | Promise < U >
147
+ ( client : CodeCatalystClient , ...args : T ) : U | Promise < U >
163
148
}
164
149
165
150
interface ClientInjector {
@@ -176,17 +161,14 @@ type Inject<T, U> = T extends (...args: infer P) => infer R
176
161
: never
177
162
: never
178
163
179
- type WithClient < T > = Parameters < Inject < T , ConnectedCodeCatalystClient > >
164
+ type WithClient < T > = Parameters < Inject < T , CodeCatalystClient > >
180
165
181
166
export class CodeCatalystCommands {
182
167
public readonly withClient : ClientInjector
183
168
public readonly bindClient = createCommandDecorator ( this )
184
169
185
- public constructor (
186
- authProvider : CodeCatalystAuthenticationProvider ,
187
- clientFactory = createClientFactory ( authProvider )
188
- ) {
189
- this . withClient = createClientInjector ( authProvider , clientFactory )
170
+ public constructor ( authProvider : CodeCatalystAuthenticationProvider ) {
171
+ this . withClient = createClientInjector ( authProvider )
190
172
}
191
173
192
174
public listCommands ( ) {
@@ -282,9 +264,8 @@ export class CodeCatalystCommands {
282
264
283
265
public static fromContext ( ctx : Pick < vscode . ExtensionContext , 'secrets' | 'globalState' > ) {
284
266
const auth = CodeCatalystAuthenticationProvider . fromContext ( ctx )
285
- const factory = createClientFactory ( auth )
286
267
287
- return new this ( auth , factory )
268
+ return new this ( auth )
288
269
}
289
270
290
271
public static readonly declared = {
0 commit comments