Skip to content

Commit 20335d1

Browse files
authored
release(required): Amplify JS release (#14431)
2 parents 52d5552 + 2b4282a commit 20335d1

File tree

6 files changed

+41
-7
lines changed

6 files changed

+41
-7
lines changed

packages/aws-amplify/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
"name": "[Analytics] record (Pinpoint)",
308308
"path": "./dist/esm/analytics/index.mjs",
309309
"import": "{ record }",
310-
"limit": "17.90 kB"
310+
"limit": "17.92 kB"
311311
},
312312
{
313313
"name": "[Analytics] record (Kinesis)",

packages/core/__tests__/providers/pinpoint/utils/EventBuffer.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,15 @@ describe('EventBuffer', () => {
5555
buffer.push(EVENT_OBJECT);
5656
buffer.push(EVENT_OBJECT);
5757
});
58+
59+
test('haveCredentialsChanged returns true if credentials have changed', () => {
60+
const config = { ...DEFAULT_CONFIG, bufferSize: 1 };
61+
const buffer = new PinpointEventBuffer(config);
62+
expect(
63+
buffer.haveCredentialsChanged({
64+
accessKeyId: 'different-access-key-id',
65+
secretAccessKey: 'different-secret-access-key',
66+
}),
67+
).toBeTruthy();
68+
});
5869
});

packages/core/__tests__/providers/pinpoint/utils/getEventBuffer.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const mockConfig = {
2222
describe('Pinpoint Provider Util: bufferManager', () => {
2323
const mockPinpointEventBuffer = PinpointEventBuffer as jest.Mock;
2424
const mockIdentityHasChanged = jest.fn();
25+
const mockHaveCredentialsChanged = jest.fn();
2526
const mockFlush = jest.fn();
2627

2728
beforeEach(() => {
@@ -30,6 +31,7 @@ describe('Pinpoint Provider Util: bufferManager', () => {
3031
mockPinpointEventBuffer.mockReset();
3132
mockPinpointEventBuffer.mockImplementation(() => ({
3233
identityHasChanged: mockIdentityHasChanged,
34+
haveCredentialsChanged: mockHaveCredentialsChanged,
3335
flush: mockFlush,
3436
}));
3537
});
@@ -58,4 +60,16 @@ describe('Pinpoint Provider Util: bufferManager', () => {
5860
expect(mockFlush).toHaveBeenCalledTimes(1);
5961
expect(testBuffer).not.toBe(testBuffer2);
6062
});
63+
64+
it('flushes & creates a new buffer when the credentials changes', () => {
65+
const testBuffer = getEventBuffer(mockConfig);
66+
67+
mockIdentityHasChanged.mockReturnValue(false);
68+
mockHaveCredentialsChanged.mockReturnValue(true);
69+
70+
const testBuffer2 = getEventBuffer(mockConfig);
71+
72+
expect(mockFlush).toHaveBeenCalledTimes(1);
73+
expect(testBuffer).not.toBe(testBuffer2);
74+
});
6175
});

packages/core/src/providers/pinpoint/utils/PinpointEventBuffer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
EventBuffer,
1515
PinpointEventBufferConfig,
1616
} from '../types/buffer';
17-
import { AuthSession } from '../../../singleton/Auth/types';
17+
import { AWSCredentials, AuthSession } from '../../../singleton/Auth/types';
18+
import { haveCredentialsChanged } from '../../../utils/haveCredentialsChanged';
1819

1920
import { isAppInForeground } from './isAppInForeground';
2021

@@ -66,6 +67,10 @@ export class PinpointEventBuffer {
6667
return this._config.identityId !== identityId;
6768
}
6869

70+
public haveCredentialsChanged(credentials: AWSCredentials) {
71+
return haveCredentialsChanged(this._config.credentials, credentials);
72+
}
73+
6974
public flushAll() {
7075
this._putEvents(this._buffer.splice(0, this._buffer.length));
7176
}

packages/core/src/providers/pinpoint/utils/getEventBuffer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,14 @@ export const getEventBuffer = ({
3737
const buffer = eventBufferMap[region][appId];
3838

3939
/*
40-
If the identity has changed flush out the buffer and create a new instance. The old instance will be garbage
40+
If the identity or credentials has changed flush out the buffer and create a new instance. The old instance will be garbage
4141
collected.
4242
*/
43-
if (buffer.identityHasChanged(identityId)) {
43+
const shouldFlushBuffer =
44+
buffer.identityHasChanged(identityId) ||
45+
buffer.haveCredentialsChanged(credentials);
46+
47+
if (shouldFlushBuffer) {
4448
buffer.flush();
4549
} else {
4650
return buffer;

yarn.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)