Skip to content

Commit

Permalink
feat: add option to exclude from request block (#225)
Browse files Browse the repository at this point in the history
* feat: add option to exclude from request block
* chore: bump package version
  • Loading branch information
yashim-deriv authored Feb 13, 2024
1 parent 9859ffe commit fc931a6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deriv/deriv-api",
"version": "1.0.14",
"version": "1.0.15",
"description": "Websocket API for Deriv applications",
"main": "dist/DerivAPI.js",
"unpkg": "dist/DerivAPI.js",
Expand Down
29 changes: 17 additions & 12 deletions src/deriv_api/DerivAPIBasic.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
* @param {String} options.lang - Language of the API communication
* @param {String} options.brand - Brand name
* @param {Object} options.middleware - A middleware to call on certain API actions
* @param {Array} options.excluded_request_block - An array of api types which is excluded from request blocking
*
* @property {Observable} events
* @property {Cache} cache - Temporary cache default to @link{InMemory}
Expand All @@ -46,6 +47,7 @@ export default class DerivAPIBasic extends DerivAPICalls {
lang = 'EN',
brand = '',
middleware = {},
excluded_request_block = ['website_status', 'authorize'],
} = {}) {
super();

Expand All @@ -66,17 +68,18 @@ export default class DerivAPIBasic extends DerivAPICalls {
this.connect();
}

this.lang = lang;
this.reqId = 0;
this.connected = new CustomPromise();
this.sanityErrors = new Subject();
this.middleware = middleware;
this.pendingRequests = {};
this.expect_response_types = {};
this.subscription_manager = new SubscriptionManager(this);
this.reconnect_timeout = false;
this.keep_alive_interval = false;
this.is_request_blocked = false;
this.lang = lang;
this.reqId = 0;
this.connected = new CustomPromise();
this.sanityErrors = new Subject();
this.middleware = middleware;
this.pendingRequests = {};
this.expect_response_types = {};
this.subscription_manager = new SubscriptionManager(this);
this.reconnect_timeout = false;
this.keep_alive_interval = false;
this.is_request_blocked = false;
this.excluded_request_block = excluded_request_block;

if (storage) {
this.storage = new Cache(this, storage);
Expand Down Expand Up @@ -151,7 +154,9 @@ export default class DerivAPIBasic extends DerivAPICalls {

async send(...args) {
const api_type = Object.keys(args[0])[0];
if (this.is_request_blocked && api_type !== 'website_status') return new Promise((resolve) => { resolve(true); });
if (this.is_request_blocked && !this.excluded_request_block.includes(api_type)) {
return new Promise();
}

const send_will_be_called = this.callMiddleware('sendWillBeCalled', { args });
if (send_will_be_called) return send_will_be_called;
Expand Down

0 comments on commit fc931a6

Please sign in to comment.