Skip to content

Commit

Permalink
Fixes callback typing in credentials refresh (#3172)
Browse files Browse the repository at this point in the history
* Fix for no error object in typings if refresh succeeds for credentials

Fixes [#3140](#3140)

* Adds changelog for fix for #3140

Co-authored-by: Anmol Dalmia <anmold@amazon.com>
  • Loading branch information
anmoldalmia and Anmol Dalmia committed May 20, 2020
1 parent da4a9db commit 61d2e7e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-Typings-2e38bbb7.json
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "Typings",
"description": "When implementing `Credentials` interface's `refresh()` method, the callback needs a defined `AWSError` as arg but it may not exist in case of successful refresh. Hence, modifed the method typing to include the fact that the callback can be called with no error on success as described in the docs."
}
4 changes: 2 additions & 2 deletions lib/credentials/cognito_identity_credentials.d.ts
Expand Up @@ -16,7 +16,7 @@ export class CognitoIdentityCredentials extends Credentials {
/**
* Refreshes credentials using AWS.CognitoIdentity.getCredentialsForIdentity(), or AWS.STS.assumeRoleWithWebIdentity().
*/
refresh(callback: (err: AWSError) => void): void;
refresh(callback: (err?: AWSError) => void): void;
/**
* Clears the cached Cognito ID associated with the currently configured identity pool ID.
*/
Expand All @@ -40,4 +40,4 @@ declare namespace CognitoIdentityCredentials {
export type CognitoIdentityCredentialsInputs = CognitoIdentity.GetIdInput|CognitoIdentity.GetCredentialsForIdentityInput|CognitoIdentity.GetOpenIdTokenInput|STS.AssumeRoleWithWebIdentityRequest;
export type CognitoIdentityOptions = CognitoIdentityCredentialsInputs & {LoginId?: string};
export type ClientConfiguration = ConfigurationOptions;
}
}
4 changes: 2 additions & 2 deletions lib/credentials/temporary_credentials.d.ts
Expand Up @@ -17,7 +17,7 @@ export class TemporaryCredentials extends Credentials {
/**
* Refreshes credentials using AWS.STS.assumeRole() or AWS.STS.getSessionToken(), depending on whether an IAM role ARN was passed to the credentials constructor().
*/
refresh(callback: (err: AWSError) => void): void;
refresh(callback: (err?: AWSError) => void): void;

/**
* The master (non-temporary) credentials used to get and refresh temporary credentials from AWS STS.
Expand All @@ -28,4 +28,4 @@ export class TemporaryCredentials extends Credentials {
// Needed to expose interfaces on the class
declare namespace TemporaryCredentials {
export type TemporaryCredentialsOptions = STS.Types.AssumeRoleRequest|STS.Types.GetSessionTokenRequest;
}
}
4 changes: 2 additions & 2 deletions lib/credentials/token_file_web_identity_credentials.d.ts
Expand Up @@ -10,5 +10,5 @@ export class TokenFileWebIdentityCredentials extends Credentials {
/**
* Refreshes credentials using AWS.STS.assumeRoleWithWebIdentity().
*/
refresh(callback: (err: AWSError) => void): void;
}
refresh(callback: (err?: AWSError) => void): void;
}
4 changes: 2 additions & 2 deletions lib/credentials/web_identity_credentials.d.ts
Expand Up @@ -17,7 +17,7 @@ export class WebIdentityCredentials extends Credentials {
/**
* Refreshes credentials using AWS.STS.assumeRoleWithWebIdentity().
*/
refresh(callback: (err: AWSError) => void): void;
refresh(callback: (err?: AWSError) => void): void;

data: STS.Types.AssumeRoleWithWebIdentityResponse;
params: STS.Types.AssumeRoleWithWebIdentityRequest
Expand All @@ -27,4 +27,4 @@ export class WebIdentityCredentials extends Credentials {
declare namespace WebIdentityCredentials {
export type ClientConfiguration = ConfigurationOptions;
export type WebIdentityCredentialsOptions = STS.AssumeRoleWithWebIdentityRequest;
}
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -146,4 +146,4 @@
"helper-test": "mocha scripts/lib/test-helper.spec.js",
"csm-functional-test": "mocha test/publisher/functional_test"
}
}
}
2 changes: 1 addition & 1 deletion ts/credentials.ts
Expand Up @@ -15,7 +15,7 @@ creds.getPromise().then(
);

if (creds.needsRefresh()) {
creds.refresh(err => {
creds.refresh((err = undefined) => {

});

Expand Down

0 comments on commit 61d2e7e

Please sign in to comment.