From fc931a65a3cad15a18aff1c225cb41112161822a Mon Sep 17 00:00:00 2001 From: yashim-deriv Date: Tue, 13 Feb 2024 16:32:48 +0800 Subject: [PATCH] feat: add option to exclude from request block (#225) * feat: add option to exclude from request block * chore: bump package version --- package-lock.json | 4 ++-- package.json | 2 +- src/deriv_api/DerivAPIBasic.js | 29 +++++++++++++++++------------ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9eb3cf3..6699d96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@deriv/deriv-api", - "version": "1.0.14", + "version": "1.0.15", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@deriv/deriv-api", - "version": "1.0.14", + "version": "1.0.15", "license": "MIT", "dependencies": { "dayjs": "^1.11.10", diff --git a/package.json b/package.json index 6efe3d2..dc7d279 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/deriv_api/DerivAPIBasic.js b/src/deriv_api/DerivAPIBasic.js index 0de1804..23f561b 100644 --- a/src/deriv_api/DerivAPIBasic.js +++ b/src/deriv_api/DerivAPIBasic.js @@ -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} @@ -46,6 +47,7 @@ export default class DerivAPIBasic extends DerivAPICalls { lang = 'EN', brand = '', middleware = {}, + excluded_request_block = ['website_status', 'authorize'], } = {}) { super(); @@ -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); @@ -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;