Skip to content

Commit

Permalink
docs: fix linting in examples, change default timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
prakharmathur82 committed Aug 28, 2023
1 parent a9e6bab commit d7ce2fd
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 35 deletions.
1 change: 0 additions & 1 deletion clients/js/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
protos
examples
2 changes: 2 additions & 0 deletions clients/js/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
examples
test
1 change: 0 additions & 1 deletion clients/js/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
protos
examples
4 changes: 2 additions & 2 deletions clients/js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Custom headers to be included in the HTTP requests.
The request timeout in milliseconds.

- Type: `Optional`
- Default value: `5000`
- Default value: `1000`

#### `retryMax`

Expand Down Expand Up @@ -178,4 +178,4 @@ Logger object for logging.

## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags](https://github.com/raystack/raccoon/tags).
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags](https://www.npmjs.com/package/@raystack/raccoon?activeTab=versions).
22 changes: 13 additions & 9 deletions clients/js/examples/json_messages.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
// eslint-disable-next-line import/no-unresolved
import { RaccoonClient, SerializationType, WireType } from '@raystack/raccoon';

//create json messages
const logger = console;

// create json messages
const jsonEvents = [
{
type: 'test-topic1',
data: { key1: 'value1', key2: ['a', 'b'] }
},
{
type: 'test-topic2',
data: { key1: 'value2' , key2: {key3: 'value3', key4: 'value4'}}
data: { key1: 'value2', key2: { key3: 'value3', key4: 'value4' } }
}
];

//initialise the raccoon client with required configs
// initialise the raccoon client with required configs
const raccoonClient = new RaccoonClient({
serializationType: SerializationType.JSON,
wireType: WireType.JSON,
Expand All @@ -23,11 +26,12 @@ const raccoonClient = new RaccoonClient({
}
});

//send the request
raccoonClient.send(jsonEvents)
.then(result => {
console.log('Result:', result);
// send the request
raccoonClient
.send(jsonEvents)
.then((result) => {
logger.log('Result:', result);
})
.catch(error => {
console.error('Error:', error);
.catch((error) => {
logger.error('Error:', error);
});
30 changes: 17 additions & 13 deletions clients/js/examples/protobuf_messages.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
// eslint-disable-next-line import/no-unresolved
import { RaccoonClient, SerializationType, WireType } from '@raystack/raccoon';
//import the compiled js file generated via protobufjs
// import the compiled js file generated via protobufjs
import { google, clickevents } from './protos/compiled.js';

const logger = console;

const currentTime = new Date();
const timestamp = google.protobuf.Timestamp.create({
seconds: Math.floor(currentTime / 1000),
nanos: (currentTime % 1000) * 1e6
});

//create the protobufjs messages and set the field values
// create the protobufjs messages and set the field values
const pageEvent = new clickevents.PageEvent();
pageEvent.eventGuid = "123";
pageEvent.eventName = "page open";
pageEvent.eventGuid = '123';
pageEvent.eventName = 'page open';
pageEvent.sentTime = timestamp;

const clickEvent = new clickevents.ClickEvent();
clickEvent.eventGuid = "123";
clickEvent.eventGuid = '123';
clickEvent.componentIndex = 12;
clickEvent.componentName = "images";
clickEvent.componentName = 'images';
clickEvent.sentTime = timestamp;

const protobufEvents = [
Expand All @@ -31,7 +34,7 @@ const protobufEvents = [
}
];

//initialise the raccoon client with required configs
// initialise the raccoon client with required configs
const raccoonClient = new RaccoonClient({
serializationType: SerializationType.PROTOBUF,
wireType: WireType.JSON,
Expand All @@ -42,11 +45,12 @@ const raccoonClient = new RaccoonClient({
}
});

//send the request
raccoonClient.send(protobufEvents)
.then(result => {
console.log('Result:', result);
// send the request
raccoonClient
.send(protobufEvents)
.then((result) => {
logger.log('Result:', result);
})
.catch(error => {
console.error('Error:', error);
.catch((error) => {
logger.error('Error:', error);
});
4 changes: 2 additions & 2 deletions clients/js/lib/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RaccoonClient {
* @param {number} [options.retryWait=1000] - The time in milliseconds to wait between retry attempts.
* @param {string} [options.url=''] - The base URL for the API requests.
* @param {string} [options.logger=''] - Logger object for logging.
* @param {number} [options.timeout=5000] - The timeout in milliseconds.
* @param {number} [options.timeout=1000] - The timeout in milliseconds.
* @returns {RaccoonClient} A new instance of the RaccoonClient.
*/
constructor(options = {}) {
Expand All @@ -48,7 +48,7 @@ class RaccoonClient {
this.retryWait = options.retryWait || 5000;
this.url = options.url || '';
this.logger = options.logger || console;
this.timeout = options.timeout || 5000;
this.timeout = options.timeout || 1000;
this.uuidGenerator = () => uuidv4();
this.httpClient = axios.create();
}
Expand Down
14 changes: 7 additions & 7 deletions clients/js/test/rest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe('RaccoonClient', () => {
expect(raccoonClient.retryMax).toBe(3);
expect(raccoonClient.retryWait).toBe(5000);
expect(raccoonClient.logger).toBe(console);
expect(raccoonClient.timeout).toBe(5000);
expect(raccoonClient.timeout).toBe(1000);
});

it('should throw error for invalid serializationType', () => {
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('RaccoonClient', () => {
'Content-Type': 'application/json',
'X-User-ID': 'test-user-1'
},
timeout: 5000,
timeout: 1000,
responseType: 'json'
}
);
Expand Down Expand Up @@ -246,7 +246,7 @@ describe('RaccoonClient', () => {
'Content-Type': 'application/proto',
'X-User-ID': 'test-user-1'
},
timeout: 5000,
timeout: 1000,
responseType: 'arraybuffer'
}
);
Expand Down Expand Up @@ -320,7 +320,7 @@ describe('RaccoonClient', () => {
'Content-Type': 'application/json',
'X-User-ID': 'test-user-1'
},
timeout: 5000,
timeout: 1000,
responseType: 'json'
}
);
Expand Down Expand Up @@ -403,7 +403,7 @@ describe('RaccoonClient', () => {
'Content-Type': 'application/proto',
'X-User-ID': 'test-user-1'
},
timeout: 5000,
timeout: 1000,
responseType: 'arraybuffer'
}
);
Expand Down Expand Up @@ -481,7 +481,7 @@ describe('RaccoonClient', () => {
'Content-Type': 'application/json',
'X-User-ID': 'test-user-1'
},
timeout: 5000,
timeout: 1000,
responseType: 'json'
}
);
Expand Down Expand Up @@ -634,7 +634,7 @@ describe('RaccoonClient', () => {
'Content-Type': 'application/json',
'X-User-ID': 'test-user-1'
},
timeout: 5000,
timeout: 1000,
responseType: 'json'
}
);
Expand Down

0 comments on commit d7ce2fd

Please sign in to comment.