Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amplify JS release #10813

Merged
merged 11 commits into from
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/1.bug_report.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Bug report
description: Create a report to help us improve Amplify JS
labels: pending-triage

body:
- type: markdown
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/2.feature_request.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Feature request
description: Suggest an idea for Amplify JS
labels: feature-request
labels: pending-triage

body:
- type: markdown
Expand Down
5 changes: 3 additions & 2 deletions .github/ISSUE_TEMPLATE/3.usage-question.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ Temporarily removed/hidden from GitHub's New Issue Chooser while we pilot Discus
-->

---

name: Usage Question
about: Ask a question about AWS Amplify usage
title: ''
labels: question
labels: question,pending-triage
assignees: ''

---

** Which Category is your question related to? **
Expand All @@ -19,4 +21,3 @@ E.g. Auth, Predictions, Storage, etc.
E.g. Cognito, AWS AppSync, etc.
** Provide additional details e.g. code snippets **
E.g. Sample code, versions of Amplify you are using

4 changes: 2 additions & 2 deletions docs/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ GEM
jekyll-seo-tag (~> 2.1)
minitest (5.15.0)
multipart-post (2.1.1)
nokogiri (1.13.9)
nokogiri (1.13.10)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
octokit (4.22.0)
Expand All @@ -241,7 +241,7 @@ GEM
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (4.0.7)
racc (1.6.0)
racc (1.6.1)
rb-fsevent (0.11.1)
rb-inotify (0.10.1)
ffi (~> 1.0)
Expand Down
2 changes: 1 addition & 1 deletion packages/amazon-cognito-identity-js/src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ export default class Client {
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': `AWSCognitoIdentityProviderService.${operation}`,
'X-Amz-User-Agent': UserAgent.prototype.userAgent,
'Cache-Control': 'no-store',
};

const options = Object.assign({}, this.fetchOptions, {
headers,
method: 'POST',
mode: 'cors',
cache: 'no-cache',
body: JSON.stringify(params),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,44 @@ describe('kinesis firehose provider test', () => {
spyon.mockRestore();
});

test('record with immediate transmission', async () => {
const kinesisProvider = new KinesisFirehoseProvider();
const putRecordBatchCommandSpy = jest.spyOn(
PutRecordBatchCommand.prototype,
'constructor'
);

jest.spyOn(Credentials, 'get').mockImplementationOnce(() => {
return Promise.resolve(credentials);
});

await expect(
kinesisProvider.record({
event: {
data: {
d: 1,
},
streamName: 'testStream',
immediate: true,
},
config: {},
})
).resolves.toBe(true);

// Ensure PutRecord was constructed as expected
expect(putRecordBatchCommandSpy).toHaveBeenCalledTimes(1);
expect(putRecordBatchCommandSpy).toHaveBeenCalledWith({
DeliveryStreamName: 'testStream',
Records: [
{
Data: new Uint8Array([123, 34, 100, 34, 58, 49, 125]), // Encoded data payload
},
],
});

expect(FirehoseClient.prototype.send).toHaveBeenCalledTimes(1);
});

test('record happy case', async () => {
const analytics = new KinesisFirehoseProvider();
analytics.configure({ region: 'region1' });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,45 @@ describe('kinesis provider test', () => {
expect(await analytics.record('params')).toBe(false);
});

test('record with immediate transmission', async () => {
const kinesisProvider = new KinesisProvider();
const putRecordCommandSpy = jest.spyOn(
PutRecordsCommand.prototype,
'constructor'
);

jest.spyOn(Credentials, 'get').mockImplementationOnce(() => {
return Promise.resolve(credentials);
});

await expect(
kinesisProvider.record({
event: {
data: {
d: 1,
},
streamName: 'testStream',
immediate: true,
},
config: {},
})
).resolves.toBe(true);

// Ensure PutRecord was constructed as expected
expect(putRecordCommandSpy).toHaveBeenCalledTimes(1);
expect(putRecordCommandSpy).toHaveBeenCalledWith({
Records: [
{
Data: new Uint8Array([123, 34, 100, 34, 58, 49, 125]), // Encoded data payload
PartitionKey: 'partition-identityId',
},
],
StreamName: 'testStream',
});

expect(KinesisClient.prototype.send).toHaveBeenCalledTimes(1);
});

test('record happy case', async () => {
const analytics = new KinesisProvider();

Expand All @@ -90,6 +129,7 @@ describe('kinesis provider test', () => {
});

jest.advanceTimersByTime(6000);
});
});

describe('passing parameters to KinesisClient', () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/analytics/src/Providers/AWSKinesisProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ export class AWSKinesisProvider implements AnalyticsProvider {

Object.assign(params, { config: this._config, credentials });

return this._putToBuffer(params);
if (params.event?.immediate) {
this._sendEvents([params]);

return Promise.resolve(true);
} else {
return this._putToBuffer(params);
}
}

public updateEndpoint() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface KinesisAnalyticsEvent {
data: object | string;
partitionKey: string;
streamName: string;
immediate?: boolean;
}