Skip to content

Commit c0f3fd5

Browse files
committed
fix: use typed SDK responses instead of Record<string, unknown> casts
1 parent 8af1257 commit c0f3fd5

1 file changed

Lines changed: 17 additions & 38 deletions

File tree

src/cli/operations/identity/oauth2-credential-provider.ts

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,42 +28,20 @@ export interface OAuth2ProviderParams {
2828
clientSecret: string;
2929
}
3030

31-
/**
32-
* Extract credential provider ARN from API response, handling field name inconsistency.
33-
* The API may return the ARN as `credentialProviderArn` or `oAuth2CredentialProviderArn`.
34-
*/
35-
/**
36-
* Extract credential provider ARN from API response, handling field name inconsistency.
37-
* The API may return the ARN as `credentialProviderArn` or `oAuth2CredentialProviderArn`.
38-
*
39-
* Note: This casts to Record<string, unknown> to handle the inconsistency. The typed SDK
40-
* response only declares `credentialProviderArn`, but older API versions may return
41-
* `oAuth2CredentialProviderArn`. Remove the fallback once the API stabilizes.
42-
*/
43-
function extractArn(response: Record<string, unknown>): string | undefined {
44-
return (
45-
(response.credentialProviderArn as string | undefined) ??
46-
(response.oAuth2CredentialProviderArn as string | undefined)
47-
);
48-
}
49-
5031
/**
5132
* Extract result fields from an OAuth2 API response.
33+
* All Create/Get/Update responses share the same shape.
5234
*/
53-
function extractResult(response: Record<string, unknown>): OAuth2ProviderResult | undefined {
54-
const credentialProviderArn = extractArn(response);
55-
if (!credentialProviderArn) return undefined;
56-
57-
const clientSecretArnRaw = response.clientSecretArn;
58-
const clientSecretArn =
59-
clientSecretArnRaw && typeof clientSecretArnRaw === 'object' && 'secretArn' in clientSecretArnRaw
60-
? (clientSecretArnRaw as { secretArn?: string }).secretArn
61-
: undefined;
62-
35+
function extractResult(response: {
36+
credentialProviderArn?: string;
37+
clientSecretArn?: { secretArn?: string };
38+
callbackUrl?: string;
39+
}): OAuth2ProviderResult | undefined {
40+
if (!response.credentialProviderArn) return undefined;
6341
return {
64-
credentialProviderArn,
65-
clientSecretArn,
66-
callbackUrl: typeof response.callbackUrl === 'string' ? response.callbackUrl : undefined,
42+
credentialProviderArn: response.credentialProviderArn,
43+
clientSecretArn: response.clientSecretArn?.secretArn,
44+
callbackUrl: response.callbackUrl,
6745
};
6846
}
6947

@@ -87,9 +65,10 @@ export async function oAuth2ProviderExists(
8765

8866
/**
8967
* Build the OAuth2 provider config for Create/Update commands.
90-
* Always uses customOauth2ProviderConfig regardless of vendor — the vendor field
91-
* controls server-side behavior (token endpoints, scopes), but the config shape
92-
* is the same for all vendors in the current API.
68+
* Always uses customOauth2ProviderConfig — the vendor field controls server-side
69+
* behavior (token endpoints, scopes), but the config shape is the same for all
70+
* vendors in the current API. Vendor-specific config paths (e.g. googleOauth2ProviderConfig)
71+
* would be needed if we add vendor selection in a future phase.
9372
*/
9473
function buildOAuth2Config(params: OAuth2ProviderParams) {
9574
return {
@@ -117,7 +96,7 @@ export async function createOAuth2Provider(
11796
): Promise<{ success: boolean; result?: OAuth2ProviderResult; error?: string }> {
11897
try {
11998
const response = await client.send(new CreateOauth2CredentialProviderCommand(buildOAuth2Config(params)));
120-
const result = extractResult(response as unknown as Record<string, unknown>);
99+
const result = extractResult(response);
121100
if (!result) {
122101
return { success: false, error: 'No credential provider ARN in response' };
123102
}
@@ -147,7 +126,7 @@ export async function getOAuth2Provider(
147126
): Promise<{ success: boolean; result?: OAuth2ProviderResult; error?: string }> {
148127
try {
149128
const response = await client.send(new GetOauth2CredentialProviderCommand({ name }));
150-
const result = extractResult(response as unknown as Record<string, unknown>);
129+
const result = extractResult(response);
151130
if (!result) {
152131
return { success: false, error: 'No credential provider ARN in response' };
153132
}
@@ -169,7 +148,7 @@ export async function updateOAuth2Provider(
169148
): Promise<{ success: boolean; result?: OAuth2ProviderResult; error?: string }> {
170149
try {
171150
const response = await client.send(new UpdateOauth2CredentialProviderCommand(buildOAuth2Config(params)));
172-
const result = extractResult(response as unknown as Record<string, unknown>);
151+
const result = extractResult(response);
173152
if (!result) {
174153
return { success: false, error: 'No credential provider ARN in response' };
175154
}

0 commit comments

Comments
 (0)