Skip to content

Commit 0403ccb

Browse files
committed
fix: remove moment dependency
1 parent 1de61f4 commit 0403ccb

File tree

5 files changed

+9
-28
lines changed

5 files changed

+9
-28
lines changed

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,7 @@ collections
128128
})
129129
.then(accountBalance => console.log({ accountBalance }))
130130
.catch(error => {
131-
if (error.response) {
132-
return console.log(error.response.data, error.response.config);
133-
}
134-
135-
return console.log(error.message);
131+
console.log(error);
136132
});
137133
```
138134

@@ -211,10 +207,6 @@ disbursements
211207
})
212208
.then(accountBalance => console.log({ accountBalance }))
213209
.catch(error => {
214-
if (error.response) {
215-
console.log(error.response.data, error.response.config);
216-
}
217-
218-
console.log(error.message);
210+
console.log(error);
219211
});
220212
```

examples/disbursements.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,5 @@ disbursements
3737
})
3838
.then(accountBalance => console.log({ accountBalance }))
3939
.catch(error => {
40-
if (error.response) {
41-
console.log(error.response.data, error.response.config);
42-
}
43-
44-
console.log(error.message);
40+
console.log(error);
4541
});

package-lock.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
},
2626
"keywords": [
2727
"MTN",
28-
"Mobile Money",
28+
"Mobile",
29+
"Money",
2930
"Momo",
3031
"TypeScript",
3132
"NodeJS"
@@ -37,7 +38,6 @@
3738
"dependencies": {
3839
"axios": "^0.18.0",
3940
"commander": "^2.19.0",
40-
"moment": "^2.22.2",
4141
"uuid": "^3.3.2"
4242
},
4343
"devDependencies": {

src/auth.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AxiosInstance } from "axios";
2-
import moment from "moment";
32

43
import { createClient } from "./client";
54

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

1514
interface OAuthCredentials {
1615
accessToken: string;
17-
expires: Date;
16+
expires: number;
1817
}
1918

2019
export function createTokenRefresher(
@@ -27,11 +26,10 @@ export function createTokenRefresher(
2726
return authorize(config)
2827
.then((accessToken: AccessToken) => {
2928
const { access_token, expires_in }: AccessToken = accessToken;
29+
const expires: number = Date.now() + expires_in * 1000 - 60000;
3030
return {
3131
accessToken: access_token,
32-
expires: moment()
33-
.add(expires_in, "seconds")
34-
.toDate()
32+
expires
3533
};
3634
})
3735
.then(freshCredentials => {
@@ -83,5 +81,5 @@ function isExpired(credentials: OAuthCredentials): boolean {
8381
return true;
8482
}
8583

86-
return moment().isAfter(credentials.expires);
84+
return Date.now() > credentials.expires;
8785
}

0 commit comments

Comments
 (0)