diff --git a/clients/js/.eslintignore b/clients/js/.eslintignore index 2483eec2..0a1aecd9 100644 --- a/clients/js/.eslintignore +++ b/clients/js/.eslintignore @@ -1,2 +1 @@ protos -examples diff --git a/clients/js/.npmignore b/clients/js/.npmignore new file mode 100644 index 00000000..f30eb650 --- /dev/null +++ b/clients/js/.npmignore @@ -0,0 +1,2 @@ +examples +test diff --git a/clients/js/.prettierignore b/clients/js/.prettierignore index 2483eec2..0a1aecd9 100644 --- a/clients/js/.prettierignore +++ b/clients/js/.prettierignore @@ -1,2 +1 @@ protos -examples diff --git a/clients/js/README.md b/clients/js/README.md index 7c098ef9..e9ed5e0a 100644 --- a/clients/js/README.md +++ b/clients/js/README.md @@ -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` @@ -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). diff --git a/clients/js/examples/json_messages.js b/clients/js/examples/json_messages.js index 008ac49d..e6bd9760 100644 --- a/clients/js/examples/json_messages.js +++ b/clients/js/examples/json_messages.js @@ -1,6 +1,9 @@ +// 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', @@ -8,11 +11,11 @@ const jsonEvents = [ }, { 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, @@ -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); }); diff --git a/clients/js/examples/protobuf_messages.js b/clients/js/examples/protobuf_messages.js index 51b42a54..30d94c80 100644 --- a/clients/js/examples/protobuf_messages.js +++ b/clients/js/examples/protobuf_messages.js @@ -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 = [ @@ -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, @@ -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); }); diff --git a/clients/js/lib/rest.js b/clients/js/lib/rest.js index f3672e48..9d092a9c 100644 --- a/clients/js/lib/rest.js +++ b/clients/js/lib/rest.js @@ -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 = {}) { @@ -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(); } diff --git a/clients/js/test/rest.test.js b/clients/js/test/rest.test.js index 688a7512..4e21a64a 100644 --- a/clients/js/test/rest.test.js +++ b/clients/js/test/rest.test.js @@ -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', () => { @@ -169,7 +169,7 @@ describe('RaccoonClient', () => { 'Content-Type': 'application/json', 'X-User-ID': 'test-user-1' }, - timeout: 5000, + timeout: 1000, responseType: 'json' } ); @@ -246,7 +246,7 @@ describe('RaccoonClient', () => { 'Content-Type': 'application/proto', 'X-User-ID': 'test-user-1' }, - timeout: 5000, + timeout: 1000, responseType: 'arraybuffer' } ); @@ -320,7 +320,7 @@ describe('RaccoonClient', () => { 'Content-Type': 'application/json', 'X-User-ID': 'test-user-1' }, - timeout: 5000, + timeout: 1000, responseType: 'json' } ); @@ -403,7 +403,7 @@ describe('RaccoonClient', () => { 'Content-Type': 'application/proto', 'X-User-ID': 'test-user-1' }, - timeout: 5000, + timeout: 1000, responseType: 'arraybuffer' } ); @@ -481,7 +481,7 @@ describe('RaccoonClient', () => { 'Content-Type': 'application/json', 'X-User-ID': 'test-user-1' }, - timeout: 5000, + timeout: 1000, responseType: 'json' } ); @@ -634,7 +634,7 @@ describe('RaccoonClient', () => { 'Content-Type': 'application/json', 'X-User-ID': 'test-user-1' }, - timeout: 5000, + timeout: 1000, responseType: 'json' } );