Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions .eslintrc

This file was deleted.

9 changes: 4 additions & 5 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ jobs:

strategy:
matrix:
node-version: [8.x, 10.x, 12.x, 14.x]
node-version: [20.x, 22.x, 24.x]

steps:
- name: Check out Git repository
uses: actions/checkout@v2
uses: actions/checkout@v5

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -25,7 +25,6 @@ jobs:
run: npm install

- name: Run linters
uses: samuelmeuli/lint-action@v1
uses: wearerequired/lint-action@v2
with:
github_token: ${{ secrets.github_token }}
eslint: true
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:

strategy:
matrix:
node-version: [8.x, 10.x, 12.x, 14.x]
node-version: [20.x, 22.x, 24.x]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v5
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
Expand Down
4 changes: 4 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# always save installed packages without version range
save-exact=true
# always amends --ignore-scripts on npm installs
ignore-scripts=true
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.17.0
20
36 changes: 36 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const js = require('@eslint/js');

module.exports = [
js.configs.recommended,
{
languageOptions: {
ecmaVersion: 6,
sourceType: 'script',
globals: {
// Node.js globals
console: 'readonly',
process: 'readonly',
Buffer: 'readonly',
__dirname: 'readonly',
__filename: 'readonly',
module: 'readonly',
require: 'readonly',
exports: 'readonly',
global: 'readonly',
// Mocha globals
describe: 'readonly',
it: 'readonly',
before: 'readonly',
after: 'readonly',
beforeEach: 'readonly',
afterEach: 'readonly'
}
},
rules: {
'no-console': 'off',
'semi': ['warn', 'always']
}
}
];
57 changes: 33 additions & 24 deletions lib/mite-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var splice = [].splice;
var url = require('url');
var request = require('request');
var axios = require('axios');

module.exports = function(options) {
var api, defaults, handleResponse, makeRequest;
Expand All @@ -14,7 +14,7 @@ module.exports = function(options) {
apiUrl: 'mite.de',
apiExtension: '.json',
query: false,
request: request,
request: axios,
urls: {
account: 'account',
myself: 'myself',
Expand All @@ -38,29 +38,28 @@ module.exports = function(options) {
};
options = Object.assign({}, defaults, options);
api = {};
handleResponse = function(err, response, body, done) {
handleResponse = function(err, response, done) {
if (err) {
return done(err, null);
}
try {
// always try to parse body as JSON
body = JSON.parse(body);
} catch (error) {
err = error;
}
switch (response.req.method) {

var body = response.data;
var statusCode = response.status;
var method = (response.config && response.config.method || 'GET').toUpperCase();

switch (method) {
case 'GET':
case 'PUT':
case 'DELETE':
if (response.statusCode === 200) {
if (statusCode === 200) {
err = null;
} else {
err = new Error(body.error || body);
err.response = response;
}
break;
case 'POST':
if (response.statusCode === 201) {
if (statusCode === 201) {
err = null;
} else {
err = new Error(body.error || body);
Expand All @@ -79,19 +78,29 @@ module.exports = function(options) {
ref = args, [...args] = ref, [done] = splice.call(args, -1);
requestOptions = Object.assign({
url: args[0],
method: 'GET',
headers: {
'User-Agent': options.applicationName
}
}, args[1]);
if (['POST', 'PUT', 'DELETE'].indexOf(requestOptions.method !== -1)) {
if (['POST', 'PUT', 'DELETE'].indexOf(requestOptions.method) !== -1) {
requestOptions.headers['Content-Type'] = 'application/json';
}
if (options.query === false) {
requestOptions.headers['X-MiteApiKey'] = options.apiKey;
}
return options.request(requestOptions, function(err, response, body) {
return handleResponse(err, response, body, done);
});

return options.request(requestOptions)
.then(function(response) {
handleResponse(null, response, done);
})
.catch(function(error) {
if (error.response) {
handleResponse(null, error.response, done);
} else {
handleResponse(error, null, done);
}
});
};
api.getOption = function(name) {
if (options[name] != null) {
Expand Down Expand Up @@ -151,7 +160,7 @@ module.exports = function(options) {
}
return makeRequest(apiUrl, {
method: 'POST',
body: JSON.stringify(entry)
data: entry
}, done);
};
api.updateTimeEntry = function(id, entry, done) {
Expand All @@ -166,7 +175,7 @@ module.exports = function(options) {
}
return makeRequest(apiUrl, {
method: 'PUT',
body: JSON.stringify(entry)
data: entry
}, done);
};
api.deleteTimeEntry = function(id, done) {
Expand Down Expand Up @@ -228,7 +237,7 @@ module.exports = function(options) {
}
return makeRequest(apiUrl, {
method: 'POST',
body: JSON.stringify(project)
data: project
}, done);
};
api.updateProject = function(id, project, done) {
Expand All @@ -243,7 +252,7 @@ module.exports = function(options) {
}
return makeRequest(apiUrl, {
method: 'PUT',
body: JSON.stringify(project)
data: project
}, done);
};
api.deleteProject = function(id, done) {
Expand Down Expand Up @@ -285,7 +294,7 @@ module.exports = function(options) {
}
return makeRequest(apiUrl, {
method: 'POST',
body: JSON.stringify(customer)
data: customer
}, done);
};
api.updateCustomer = function(id, customer, done) {
Expand All @@ -300,7 +309,7 @@ module.exports = function(options) {
}
return makeRequest(apiUrl, {
method: 'PUT',
body: JSON.stringify(customer)
data: customer
}, done);
};
api.deleteCustomer = function(id, done) {
Expand Down Expand Up @@ -342,7 +351,7 @@ module.exports = function(options) {
}
return makeRequest(apiUrl, {
method: 'POST',
body: JSON.stringify(service)
data: service
}, done);
};
api.updateService = function(id, service, done) {
Expand All @@ -357,7 +366,7 @@ module.exports = function(options) {
}
return makeRequest(apiUrl, {
method: 'PUT',
body: JSON.stringify(service)
data: service
}, done);
};
api.deleteService = function(id, done) {
Expand Down
Loading