@autofleet/node-common 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
File without changes
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ network: require('./network'),
3
+ }
@@ -0,0 +1,38 @@
1
+ const axios = require('axios');
2
+ require('dotenv').config();
3
+
4
+ const HTTPMethods = [
5
+ 'get',
6
+ 'post',
7
+ 'delete',
8
+ 'head',
9
+ 'put',
10
+ 'patch',
11
+ 'options'
12
+ ]
13
+
14
+ module.exports = class Network {
15
+ static defaultSettings = {
16
+ timeout: 2500,
17
+ headers: { 'X-AF-AUTH': 'ANYONE' }
18
+ }
19
+
20
+ constructor(settings = {}) {
21
+ this.settings = Object.assign(Network.defaultSettings, settings);
22
+
23
+ if(settings.serviceUrl) {
24
+ this.baseURL = settings.serviceUrl;
25
+ } else if (settings.serviceName) {
26
+ this.baseURL = process.env[`SERVICE_URL_${settings.serviceUrl}`];
27
+ }
28
+
29
+ if (!this.baseURL){
30
+ throw new Error('Missing serviceUrl or serviceName')
31
+ }
32
+
33
+ this.axios = axios.create(settings);
34
+
35
+ // Temp
36
+ HTTPMethods.map((method) => this[method] = (...args) => this.axios[method](...args));
37
+ }
38
+ }
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@autofleet/node-common",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+ssh://git@gitlab.com/AutoFleet/node-common.git"
12
+ },
13
+ "author": "",
14
+ "license": "ISC",
15
+ "bugs": {
16
+ "url": "https://gitlab.com/AutoFleet/node-common/issues"
17
+ },
18
+ "homepage": "https://gitlab.com/AutoFleet/node-common#README",
19
+ "dependencies": {
20
+ "axios": "^0.18.0"
21
+ }
22
+ }