-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@aws-amplify/ui-components): User agent tracking for UI componen…
…t packages (#4804) * Update Cognito user agent inside of amplify-authenticator * Move user agent set to configure, change append logic check * UserAgent unit tests for cognito sdk
- Loading branch information
1 parent
6d1019f
commit 15a0a2f
Showing
12 changed files
with
139 additions
and
19 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
packages/amazon-cognito-identity-js/__tests__/UserAgent-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import UserAgent, { appendToCognitoUserAgent } from '../src/UserAgent'; | ||
|
||
const DEFAULT_USER_AGENT = 'amazon-cognito-identity-js'; | ||
|
||
describe('UserAgent test', () => { | ||
beforeEach(() => { | ||
UserAgent.prototype.userAgent = DEFAULT_USER_AGENT; | ||
}); | ||
test('userAgent is set by default', () => { | ||
expect(UserAgent.prototype.userAgent).toBe(DEFAULT_USER_AGENT); | ||
}); | ||
|
||
test('appendToCognitoUserAgent does nothing to the userAgent if nothing is passed into it', () => { | ||
appendToCognitoUserAgent(); | ||
expect(UserAgent.prototype.userAgent).toBe(DEFAULT_USER_AGENT); | ||
}); | ||
|
||
test('appendToCognitoUserAgent appends content to userAgent', () => { | ||
appendToCognitoUserAgent('test'); | ||
expect(UserAgent.prototype.userAgent).toBe(`${DEFAULT_USER_AGENT} test`); | ||
}); | ||
|
||
test('appendToCognitoUserAgent does not append duplicate content', () => { | ||
appendToCognitoUserAgent('test'); | ||
appendToCognitoUserAgent('test'); | ||
expect(UserAgent.prototype.userAgent).not.toBe( | ||
`${DEFAULT_USER_AGENT} test test` | ||
); | ||
|
||
expect(UserAgent.prototype.userAgent).toBe(`${DEFAULT_USER_AGENT} test`); | ||
}); | ||
|
||
test('appendToCognitoUserAgent sets userAgent if userAgent has no content', () => { | ||
UserAgent.prototype.userAgent = ''; | ||
appendToCognitoUserAgent('test'); | ||
expect(UserAgent.prototype.userAgent).toBe('test'); | ||
|
||
UserAgent.prototype.userAgent = undefined; | ||
appendToCognitoUserAgent('test'); | ||
expect(UserAgent.prototype.userAgent).toBe('test'); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,26 @@ | ||
// class for defining the amzn user-agent | ||
export default UserAgent; | ||
const DEFAULT_USER_AGENT = 'amazon-cognito-identity-js'; | ||
// constructor | ||
function UserAgent() {} | ||
// public | ||
UserAgent.prototype.userAgent = 'aws-amplify/0.1.x js'; | ||
UserAgent.prototype.userAgent = DEFAULT_USER_AGENT; | ||
|
||
export const appendToCognitoUserAgent = content => { | ||
if (!content) { | ||
return; | ||
} | ||
if ( | ||
UserAgent.prototype.userAgent && | ||
!UserAgent.prototype.userAgent.includes(content) | ||
) { | ||
UserAgent.prototype.userAgent = UserAgent.prototype.userAgent.concat( | ||
' ', | ||
content | ||
); | ||
} | ||
if (!UserAgent.prototype.userAgent || UserAgent.prototype.userAgent === '') { | ||
UserAgent.prototype.userAgent = content; | ||
} | ||
}; | ||
|
||
// class for defining the amzn user-agent | ||
export default UserAgent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export * from './components'; | ||
export * from './components'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Due to this addition, I believe that the @aws-amplify/auth dependency version in amplify-ui-components should be bumped to 3.x so that this method can be found. If. @aws-amplify/ui-components is paired with @aws-amplify/auth 2 an error is hit at runtime