Skip to content

Commit

Permalink
release(required): Amplify JS release (#12796)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimblanc authored Jan 4, 2024
2 parents 3587513 + 46038f7 commit 629fbac
Show file tree
Hide file tree
Showing 75 changed files with 1,928 additions and 831 deletions.
23 changes: 23 additions & 0 deletions .github/ISSUE_TEMPLATE/1.bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ body:
- Not applicable
validations:
required: true
- type: dropdown
attributes:
label: Amplify Version
description: |
Which major version of `aws-amplify` are you using?
multiple: false
options:
- v6
- v5
- Older than v5
validations:
required: true
- type: dropdown
attributes:
label: Amplify Categories
Expand All @@ -107,6 +119,17 @@ body:
- interactions
- predictions
- Not applicable
- type: dropdown
attributes:
label: Backend
description: |
How have you deployed the backend resources?
multiple: false
options:
- Amplify CLI
- Amplify Gen 2 (Preview)
- CDK
- Other
- type: textarea
attributes:
label: Environment information
Expand Down
1 change: 1 addition & 0 deletions .github/dependency-review/dependecy-review-config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
allow-licenses:
- 'Apache-2.0'
- '0BSD'
- 'BSL-1.0'
- 'BSD-1-Clause'
- 'BSD-2-Clause-FreeBSD'
Expand Down
18 changes: 18 additions & 0 deletions .github/integ-config/integ-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,15 @@ tests:
browser: [chrome]
timeout_minutes: 45
retry_count: 10
- test_name: integ_next_sign_in_with_oauth
desc: 'Sign-in with the OAuth flow'
framework: next
category: auth
sample_name: [sign-in-with-oauth]
spec: sign-in-with-oauth
browser: [chrome]
timeout_minutes: 45
retry_count: 10

# DISABLED Angular/Vue tests:
# TODO: delete tests or add custom ui logic to support them.
Expand Down Expand Up @@ -734,6 +743,15 @@ tests:
spec: multi-part-copy
browser: *minimal_browser_list

# INAPPMESSAGING
- test_name: integ_in_app_messaging
desc: 'React InApp Messaging'
framework: react
category: in-app-messaging
sample_name: [in-app-messaging-app]
spec: in-app-messaging
browser: *minimal_browser_list

# - test_name: integ_duplicate_packages
# desc: 'Duplicate Package Errors'
# framework: react
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { EventBuffer, groupBy, IAnalyticsClient } from '../../../utils';
import {
AWSCredentials,
haveCredentialsChanged
} from '@aws-amplify/core/internals/utils';
import {
FirehoseClient,
PutRecordBatchCommand,
} from '@aws-sdk/client-firehose';
import {
EventBuffer,
groupBy,
IAnalyticsClient
} from '../../../utils';
import {
KinesisFirehoseBufferEvent,
KinesisFirehoseEventBufferConfig,
Expand All @@ -23,7 +31,7 @@ const eventBufferMap: Record<
string,
EventBuffer<KinesisFirehoseBufferEvent>
> = {};
const cachedClients: Record<string, FirehoseClient> = {};
const cachedClients: Record<string, [FirehoseClient, AWSCredentials]> = {};

const createPutRecordsBatchCommand = (
streamName: string,
Expand Down Expand Up @@ -76,18 +84,29 @@ export const getEventBuffer = ({
userAgentValue,
}: KinesisFirehoseEventBufferConfig): EventBuffer<KinesisFirehoseBufferEvent> => {
const sessionIdentityKey = [region, identityId].filter(id => !!id).join('-');
const [ cachedClient, cachedCredentials ] = cachedClients[sessionIdentityKey] ?? [];
let credentialsHaveChanged = false;

if (!eventBufferMap[sessionIdentityKey]) {
// Check if credentials have changed for the cached client
if (cachedClient) {
credentialsHaveChanged = haveCredentialsChanged(cachedCredentials, credentials);
}

if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
const getClient = (): IAnalyticsClient<KinesisFirehoseBufferEvent> => {
if (!cachedClients[sessionIdentityKey]) {
cachedClients[sessionIdentityKey] = new FirehoseClient({
region,
credentials,
customUserAgent: userAgentValue,
});
if (!cachedClient || credentialsHaveChanged) {
cachedClients[sessionIdentityKey] = [
new FirehoseClient({
region,
credentials,
customUserAgent: userAgentValue,
}),
credentials
];
}

const firehoseClient = cachedClients[sessionIdentityKey];
const [ firehoseClient ] = cachedClients[sessionIdentityKey];

return events => submitEvents(events, firehoseClient, resendLimit);
};

Expand Down
42 changes: 31 additions & 11 deletions packages/analytics/src/providers/kinesis/utils/getEventBuffer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { KinesisBufferEvent, KinesisEventBufferConfig } from '../types';
import { EventBuffer, groupBy, IAnalyticsClient } from '../../../utils';
import {
AWSCredentials,
haveCredentialsChanged
} from '@aws-amplify/core/internals/utils';
import { KinesisClient, PutRecordsCommand } from '@aws-sdk/client-kinesis';
import { KinesisBufferEvent, KinesisEventBufferConfig } from '../types';
import {
EventBuffer,
groupBy,
IAnalyticsClient
} from '../../../utils';

/**
* These Records hold cached event buffers and AWS clients.
Expand All @@ -14,7 +22,7 @@ import { KinesisClient, PutRecordsCommand } from '@aws-sdk/client-kinesis';
* When a new session is initiated, the previous ones should be released.
* */
const eventBufferMap: Record<string, EventBuffer<KinesisBufferEvent>> = {};
const cachedClients: Record<string, KinesisClient> = {};
const cachedClients: Record<string, [KinesisClient, AWSCredentials]> = {};

const createKinesisPutRecordsCommand = (
streamName: string,
Expand Down Expand Up @@ -67,19 +75,31 @@ export const getEventBuffer = ({
userAgentValue,
}: KinesisEventBufferConfig): EventBuffer<KinesisBufferEvent> => {
const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
const [ cachedClient, cachedCredentials ] = cachedClients[sessionIdentityKey] ?? [];
let credentialsHaveChanged = false;

if (!eventBufferMap[sessionIdentityKey]) {
// Check if credentials have changed for the cached client
if (cachedClient) {
credentialsHaveChanged = haveCredentialsChanged(cachedCredentials, credentials);
}

if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
const getKinesisClient = (): IAnalyticsClient<KinesisBufferEvent> => {
if (!cachedClients[sessionIdentityKey]) {
cachedClients[sessionIdentityKey] = new KinesisClient({
credentials,
region,
customUserAgent: userAgentValue,
});
if (!cachedClient || credentialsHaveChanged) {
cachedClients[sessionIdentityKey] = [
new KinesisClient({
credentials,
region,
customUserAgent: userAgentValue,
}),
credentials
];
}

const [ kinesisClient ] = cachedClients[sessionIdentityKey];

return events =>
submitEvents(events, cachedClients[sessionIdentityKey], resendLimit);
submitEvents(events, kinesisClient, resendLimit);
};

// create new session
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { EventBuffer, groupBy, IAnalyticsClient } from '../../../utils';
import { PersonalizeBufferConfig, PersonalizeBufferEvent } from '../types';
import {
AWSCredentials,
haveCredentialsChanged
} from '@aws-amplify/core/internals/utils';
import {
PersonalizeEventsClient,
PutEventsCommand,
} from '@aws-sdk/client-personalize-events';
import {
EventBuffer,
groupBy,
IAnalyticsClient
} from '../../../utils';
import { PersonalizeBufferConfig, PersonalizeBufferEvent } from '../types';

/**
* These Records hold cached event buffers and AWS clients.
Expand All @@ -17,7 +25,7 @@ import {
* When a new session is initiated, the previous ones should be released.
* */
const eventBufferMap: Record<string, EventBuffer<PersonalizeBufferEvent>> = {};
const cachedClients: Record<string, PersonalizeEventsClient> = {};
const cachedClients: Record<string, [PersonalizeEventsClient, AWSCredentials]> = {};

const DELIMITER = '#';

Expand Down Expand Up @@ -71,17 +79,30 @@ export const getEventBuffer = ({
userAgentValue,
}: PersonalizeBufferConfig): EventBuffer<PersonalizeBufferEvent> => {
const sessionIdentityKey = [region, identityId].filter(x => !!x).join('-');
const [ cachedClient, cachedCredentials ] = cachedClients[sessionIdentityKey] ?? [];
let credentialsHaveChanged = false;

// Check if credentials have changed for the cached client
if (cachedClient) {
credentialsHaveChanged = haveCredentialsChanged(cachedCredentials, credentials);
}

if (!eventBufferMap[sessionIdentityKey]) {
if (!eventBufferMap[sessionIdentityKey] || credentialsHaveChanged) {
const getClient = (): IAnalyticsClient<PersonalizeBufferEvent> => {
if (!cachedClients[sessionIdentityKey]) {
cachedClients[sessionIdentityKey] = new PersonalizeEventsClient({
region,
credentials,
customUserAgent: userAgentValue,
});
if (!cachedClient || credentialsHaveChanged) {
cachedClients[sessionIdentityKey] = [
new PersonalizeEventsClient({
region,
credentials,
customUserAgent: userAgentValue,
}),
credentials
];
}
return events => submitEvents(events, cachedClients[sessionIdentityKey]);

const [ personalizeClient ] = cachedClients[sessionIdentityKey];

return events => submitEvents(events, personalizeClient);
};

eventBufferMap[sessionIdentityKey] =
Expand Down
2 changes: 1 addition & 1 deletion packages/analytics/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"strict": true,
"noImplicitAny": true
},
"include": ["./src"]
"include": ["./src", "../core/src/utils/haveCredentialsChanged.ts"]
}
19 changes: 19 additions & 0 deletions packages/api-rest/__tests__/apis/common/internalPost.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,25 @@ describe('internal post', () => {
expect(mockAuthenticatedHandler).not.toHaveBeenCalled();
});

it('should call unauthenticatedHandler if credential is not set', async () => {
mockFetchAuthSession.mockClear();
mockFetchAuthSession.mockRejectedValue(
new Error('Mock error as credentials not configured')
);
await post(mockAmplifyInstance, {
url: apiGatewayUrl,
});
expect(mockUnauthenticatedHandler).toHaveBeenCalledWith(
{
url: apiGatewayUrl,
method: 'POST',
headers: {},
},
expect.anything()
);
expect(mockAuthenticatedHandler).not.toHaveBeenCalled();
});

it('should abort request when cancel is called', async () => {
expect.assertions(4);
let underLyingHandlerReject;
Expand Down
Loading

0 comments on commit 629fbac

Please sign in to comment.