@brianbuie/node-kit 0.6.0 → 0.8.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 +519 -66
- package/dist/Cache.d.ts +14 -19
- package/dist/Cache.js +16 -13
- package/dist/Dir.d.ts +1 -1
- package/dist/Dir.js +2 -2
- package/dist/Fetcher.d.ts +6 -6
- package/dist/Fetcher.js +6 -6
- package/dist/File.d.ts +13 -13
- package/dist/File.js +17 -15
- package/{src/_index.ts → dist/index.d.ts} +1 -2
- package/dist/{_index.js → index.js} +1 -2
- package/package.json +7 -6
- package/src/Cache.ts +16 -13
- package/src/Dir.ts +2 -2
- package/src/Fetcher.ts +6 -6
- package/src/File.test.ts +15 -2
- package/src/File.ts +21 -19
- package/{dist/_index.d.ts → src/index.ts} +1 -2
- package/dist/Jwt.d.ts +0 -15
- package/dist/Jwt.js +0 -29
- package/src/Jwt.test.ts +0 -22
- package/src/Jwt.ts +0 -47
package/src/Jwt.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { default as jsonwebtoken, type JwtPayload, type SignOptions } from 'jsonwebtoken';
|
|
2
|
-
import { merge } from 'lodash-es';
|
|
3
|
-
|
|
4
|
-
type JwtConfig = {
|
|
5
|
-
payload: JwtPayload;
|
|
6
|
-
options: SignOptions;
|
|
7
|
-
seconds: number;
|
|
8
|
-
key: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export class Jwt {
|
|
12
|
-
config;
|
|
13
|
-
#saved?: {
|
|
14
|
-
exp: number;
|
|
15
|
-
token: string;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
constructor(config: JwtConfig) {
|
|
19
|
-
this.config = config;
|
|
20
|
-
this.#createToken();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
get now() {
|
|
24
|
-
return Math.floor(Date.now() / 1000);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
#createToken() {
|
|
28
|
-
const exp = this.now + this.config.seconds;
|
|
29
|
-
const payload: JwtPayload = merge(
|
|
30
|
-
{
|
|
31
|
-
iat: this.now,
|
|
32
|
-
exp,
|
|
33
|
-
},
|
|
34
|
-
this.config.payload
|
|
35
|
-
);
|
|
36
|
-
const token = jsonwebtoken.sign(payload, this.config.key, this.config.options);
|
|
37
|
-
this.#saved = { token, exp };
|
|
38
|
-
return token;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
get token() {
|
|
42
|
-
if (this.#saved && this.#saved.exp > this.now) {
|
|
43
|
-
return this.#saved.token;
|
|
44
|
-
}
|
|
45
|
-
return this.#createToken();
|
|
46
|
-
}
|
|
47
|
-
}
|