Skip to content

Commit

Permalink
fix: remove moment dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ernest-okot committed Mar 17, 2019
1 parent 1de61f4 commit 0403ccb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 28 deletions.
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,7 @@ collections
})
.then(accountBalance => console.log({ accountBalance }))
.catch(error => {
if (error.response) {
return console.log(error.response.data, error.response.config);
}

return console.log(error.message);
console.log(error);
});
```

Expand Down Expand Up @@ -211,10 +207,6 @@ disbursements
})
.then(accountBalance => console.log({ accountBalance }))
.catch(error => {
if (error.response) {
console.log(error.response.data, error.response.config);
}

console.log(error.message);
console.log(error);
});
```
6 changes: 1 addition & 5 deletions examples/disbursements.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,5 @@ disbursements
})
.then(accountBalance => console.log({ accountBalance }))
.catch(error => {
if (error.response) {
console.log(error.response.data, error.response.config);
}

console.log(error.message);
console.log(error);
});
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
"keywords": [
"MTN",
"Mobile Money",
"Mobile",
"Money",
"Momo",
"TypeScript",
"NodeJS"
Expand All @@ -37,7 +38,6 @@
"dependencies": {
"axios": "^0.18.0",
"commander": "^2.19.0",
"moment": "^2.22.2",
"uuid": "^3.3.2"
},
"devDependencies": {
Expand Down
10 changes: 4 additions & 6 deletions src/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { AxiosInstance } from "axios";
import moment from "moment";

import { createClient } from "./client";

Expand All @@ -14,7 +13,7 @@ export type Authorizer = (

interface OAuthCredentials {
accessToken: string;
expires: Date;
expires: number;
}

export function createTokenRefresher(
Expand All @@ -27,11 +26,10 @@ export function createTokenRefresher(
return authorize(config)
.then((accessToken: AccessToken) => {
const { access_token, expires_in }: AccessToken = accessToken;
const expires: number = Date.now() + expires_in * 1000 - 60000;
return {
accessToken: access_token,
expires: moment()
.add(expires_in, "seconds")
.toDate()
expires
};
})
.then(freshCredentials => {
Expand Down Expand Up @@ -83,5 +81,5 @@ function isExpired(credentials: OAuthCredentials): boolean {
return true;
}

return moment().isAfter(credentials.expires);
return Date.now() > credentials.expires;
}

0 comments on commit 0403ccb

Please sign in to comment.