Skip to content

Commit

Permalink
chore: upgrade project
Browse files Browse the repository at this point in the history
BREAKING CHANGE: remove support for older node versions, only >= v8 is supported
  • Loading branch information
satazor committed Aug 7, 2018
1 parent 495cd15 commit 07ccbc7
Show file tree
Hide file tree
Showing 13 changed files with 9,027 additions and 462 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
[{*.md,*.snap}]
trim_trailing_whitespace = false

[package.json]
Expand Down
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage/
6 changes: 3 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"root": true,
"extends": [
"@satazor/eslint-config/es6",
"@satazor/eslint-config/addons/node",
"@satazor/eslint-config/addons/node-v4-es6"
"eslint-config-moxy/es9",
"eslint-config-moxy/addons/node",
"eslint-config-moxy/addons/jest"
]
}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules
node_modules/
npm-debug.*
test/coverage
coverage/
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
language: node_js
node_js:
- "4"
- "5"
script: "npm run test-travis"
- "node"
- "lts/*"
# Report coverage
after_success:
- "npm i codecov"
- "node_modules/.bin/codecov"
12 changes: 7 additions & 5 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
Copyright (c) 2016 IndigoUnited
The MIT License (MIT)

Copyright (c) 2018 Made With MOXY Lda <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# token-dealer

[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] [![Greenkeeper badge][greenkeeper-image]][greenkeeper-url]
[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][codecov-image]][codecov-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] [![Greenkeeper badge][greenkeeper-image]][greenkeeper-url]

[npm-url]:https://npmjs.org/package/token-dealer
[downloads-image]:http://img.shields.io/npm/dm/token-dealer.svg
[npm-image]:http://img.shields.io/npm/v/token-dealer.svg
[travis-url]:https://travis-ci.org/IndigoUnited/node-token-dealer
[travis-image]:http://img.shields.io/travis/IndigoUnited/node-token-dealer/master.svg
[coveralls-url]:https://coveralls.io/r/IndigoUnited/node-token-dealer
[coveralls-image]:https://img.shields.io/coveralls/IndigoUnited/node-token-dealer/master.svg
[david-dm-url]:https://david-dm.org/IndigoUnited/node-token-dealer
[david-dm-image]:https://img.shields.io/david/IndigoUnited/node-token-dealer.svg
[david-dm-dev-url]:https://david-dm.org/IndigoUnited/node-token-dealer?type=dev
[david-dm-dev-image]:https://img.shields.io/david/dev/IndigoUnited/node-token-dealer.svg
[greenkeeper-image]:https://badges.greenkeeper.io/IndigoUnited/node-token-dealer.svg
[greenkeeper-url]:https://greenkeeper.io/
[downloads-image]:http://img.shields.io/npm/dm/token-dealer.svg
[travis-url]:https://travis-ci.org/moxystudio/node-token-dealer
[travis-image]:http://img.shields.io/travis/moxystudio/node-token-dealer/master.svg
[codecov-url]:https://codecov.io/gh/moxystudio/node-token-dealer
[codecov-image]:https://img.shields.io/codecov/c/github/moxystudio/node-token-dealer/master.svg
[david-dm-url]:https://david-dm.org/moxystudio/node-token-dealer
[david-dm-image]:https://img.shields.io/david/moxystudio/node-token-dealer.svg
[david-dm-dev-url]:https://david-dm.org/moxystudio/node-token-dealer?type=dev
[david-dm-dev-image]:https://img.shields.io/david/dev/moxystudio/node-token-dealer.svg
[greenkeeper-image]:https://badges.greenkeeper.io/moxystudio/node-token-dealer.svg
[greenkeeper-url]:https://greenkeeper.io

Circumvent API rate limits by having several API tokens and let the dealer manage and give them to you.

Expand Down Expand Up @@ -55,7 +55,7 @@ tokenDealer(tokens, (token, exhaust) => {
}
};

return got('https://api.github.com/repos/IndigoUnited/node-cross-spawn', {
return got('https://api.github.com/repos/moxystudio/node-cross-spawn', {
json: true,
headers: { Authorization: `token ${token}` },
})
Expand Down Expand Up @@ -116,7 +116,7 @@ const usage = tokenDealer.getTokensUsage(tokens);
## Tests

`$ npm test`
`$ npm test-cov` to get coverage report
`$ npm test -- --watch` during development


## License
Expand Down
33 changes: 17 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,19 @@ function dealToken(tokens, fn, options) {
chosen.usage.inflight += 1;

return Promise.resolve()
.then(() => {
return fn(chosen.token, (reset, retry) => {
chosen.usage.exhausted = true;
chosen.usage.reset = reset;

options.onExhausted && options.onExhausted(chosen.token, reset);

if (retry) {
throw Object.assign(new Error('Token is exhausted, retrying..'), { code: 'ETOKENEXHAUSTED' });
}
});
})
.then(() => fn(chosen.token, (reset, retry) => {
chosen.usage.exhausted = true;
chosen.usage.reset = reset;

options.onExhausted && options.onExhausted(chosen.token, reset);

if (retry) {
throw Object.assign(new Error('Token is exhausted, retrying..'), { code: 'ETOKENEXHAUSTED' });
}
}))
.then((val) => {
chosen.usage.inflight -= 1;

return val;
}, (err) => {
chosen.usage.inflight -= 1;
Expand All @@ -105,12 +104,13 @@ function tokenDealer(tokens, fn, options) {
tokens = [''];
}

options = Object.assign({
options = {
group: 'default',
wait: false,
lru: defaultLru,
onExhausted: null,
}, options);
...options,
};

return dealToken(tokens, fn, options);
}
Expand All @@ -120,10 +120,11 @@ function getTokensUsage(tokens, options) {
tokens = [''];
}

options = Object.assign({
options = {
group: 'default',
lru: defaultLru,
}, options);
...options,
};

const tokensUsage = {};

Expand Down
Loading

0 comments on commit 07ccbc7

Please sign in to comment.