From 20f10b5288386c491f7191f12a59e300f42f2d17 Mon Sep 17 00:00:00 2001 From: Dan Jones <dan.jones@noc.ac.uk> Date: Thu, 12 Jan 2023 10:55:06 +0000 Subject: [PATCH] fix: correct use of this in wrong context --- dist/adapter.esm.js | 18 +++++++++++------- dist/adapter.js | 18 +++++++++++------- src/adapter/index.js | 18 +++++++++++------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/dist/adapter.esm.js b/dist/adapter.esm.js index c8c1dac..da7f498 100644 --- a/dist/adapter.esm.js +++ b/dist/adapter.esm.js @@ -6,8 +6,8 @@ import axios from 'axios'; */ class Adapter { constructor(protocol, config) { - this.config = config; this.protocol = protocol; + this.config = config; this.axios = axios; this.validator = new Validator(protocol.schema); this.auth(); @@ -68,11 +68,12 @@ class Adapter { * @returns {object} */ auth() { + let config = this.config; return this.axios - .get(`${this.config.api}/token`, { + .get(`${config.api}/token`, { params: { - client_id: this.config.client_id, - secret: this.config.secret, + client_id: config.client_id, + secret: config.secret, }, }) .then((response) => { @@ -88,9 +89,10 @@ class Adapter { * @returns {object} */ poll() { + let config = this.config; return this.getAuthorizationHeader() .then((headers) => { - return this.axios.get(`${this.config.api}/receive`, { + return this.axios.get(`${config.api}/receive`, { headers, }); }) @@ -116,10 +118,11 @@ class Adapter { * @returns */ publish(topic, body) { + let config = this.config; return this.getAuthorizationHeader() .then((headers) => { return this.axios.post( - `${this.config.api}/send`, + `${config.api}/send`, { topic, body, @@ -146,10 +149,11 @@ class Adapter { * @returns */ broadcast(body) { + let config = this.config; return this.getAuthorizationHeader() .then((headers) => { return this.axios.post( - `${this.config.api}/notify`, + `${config.api}/notify`, { body, }, diff --git a/dist/adapter.js b/dist/adapter.js index 51b0ce2..3f49e26 100644 --- a/dist/adapter.js +++ b/dist/adapter.js @@ -8,8 +8,8 @@ var axios = require('axios'); */ class Adapter { constructor(protocol, config) { - this.config = config; this.protocol = protocol; + this.config = config; this.axios = axios; this.validator = new Validator(protocol.schema); this.auth(); @@ -70,11 +70,12 @@ class Adapter { * @returns {object} */ auth() { + let config = this.config; return this.axios - .get(`${this.config.api}/token`, { + .get(`${config.api}/token`, { params: { - client_id: this.config.client_id, - secret: this.config.secret, + client_id: config.client_id, + secret: config.secret, }, }) .then((response) => { @@ -90,9 +91,10 @@ class Adapter { * @returns {object} */ poll() { + let config = this.config; return this.getAuthorizationHeader() .then((headers) => { - return this.axios.get(`${this.config.api}/receive`, { + return this.axios.get(`${config.api}/receive`, { headers, }); }) @@ -118,10 +120,11 @@ class Adapter { * @returns */ publish(topic, body) { + let config = this.config; return this.getAuthorizationHeader() .then((headers) => { return this.axios.post( - `${this.config.api}/send`, + `${config.api}/send`, { topic, body, @@ -148,10 +151,11 @@ class Adapter { * @returns */ broadcast(body) { + let config = this.config; return this.getAuthorizationHeader() .then((headers) => { return this.axios.post( - `${this.config.api}/notify`, + `${config.api}/notify`, { body, }, diff --git a/src/adapter/index.js b/src/adapter/index.js index 9c1a21a..91320eb 100644 --- a/src/adapter/index.js +++ b/src/adapter/index.js @@ -6,8 +6,8 @@ import axios from 'axios'; */ export class Adapter { constructor(protocol, config) { - this.config = config; this.protocol = protocol; + this.config = config; this.axios = axios; this.validator = new Validator(protocol.schema); this.auth(); @@ -68,11 +68,12 @@ export class Adapter { * @returns {object} */ auth() { + let config = this.config; return this.axios - .get(`${this.config.api}/token`, { + .get(`${config.api}/token`, { params: { - client_id: this.config.client_id, - secret: this.config.secret, + client_id: config.client_id, + secret: config.secret, }, }) .then((response) => { @@ -88,9 +89,10 @@ export class Adapter { * @returns {object} */ poll() { + let config = this.config; return this.getAuthorizationHeader() .then((headers) => { - return this.axios.get(`${this.config.api}/receive`, { + return this.axios.get(`${config.api}/receive`, { headers, }); }) @@ -116,10 +118,11 @@ export class Adapter { * @returns */ publish(topic, body) { + let config = this.config; return this.getAuthorizationHeader() .then((headers) => { return this.axios.post( - `${this.config.api}/send`, + `${config.api}/send`, { topic, body, @@ -146,10 +149,11 @@ export class Adapter { * @returns */ broadcast(body) { + let config = this.config; return this.getAuthorizationHeader() .then((headers) => { return this.axios.post( - `${this.config.api}/notify`, + `${config.api}/notify`, { body, }, -- GitLab