diff options
Diffstat (limited to 'vnext/server/http.js')
-rw-r--r-- | vnext/server/http.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/vnext/server/http.js b/vnext/server/http.js new file mode 100644 index 00000000..74c51b0a --- /dev/null +++ b/vnext/server/http.js @@ -0,0 +1,46 @@ +import axios from 'axios'; +var debug = require('debug')('http'); + + +/** + * @external Promise + * @see {@link http://api.jquery.com/Types/#Promise Promise} + */ +/** + * fetch message subscribers + * + * @param {URLSearchParams} params - request params + * @returns {Promise<import('../client').SecureUser[]>} subscribers list + */ +export function subscribers(params) { + return new Promise((resolve, reject) => { + client.get(`/notifications?${params.toString()}`) + .then(response => { + resolve(response.data); + }) + .catch(reason => { reject(reason); }); + }); +} + +/** + * delete invalid tokens + * + * @param {import('../client').Token[]} tokens tokens + */ +export const deleteSubscribers = async (tokens) => { + const response = await client.post('/notifications/delete', tokens); + return response.data; +}; + +const baseURL = process.env.JUICK_SERVICE_URL; +const user = process.env.JUICK_SERVICE_USER; +const password = process.env.JUICK_SERVICE_PASSWORD; + +/** @type { import('axios').AxiosInstance } */ +let client = axios.create({ + baseURL: baseURL, + headers: user ? { + 'Authorization': 'Basic ' + Buffer.from(user + ':' + password).toString('base64') + } : {} +}); +debug(`HTTP client initialized with base URL ${baseURL} ${ user? `and ${user} user` : ''}`); |