@aeriajs/core 0.0.284 → 0.0.285
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/dist/token.d.ts +19 -3
- package/dist/token.js +15 -2
- package/package.json +3 -3
package/dist/token.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
import type { SignOptions } from 'jsonwebtoken';
|
|
2
|
-
export declare const signToken: ({ iat, exp, ...payload }: Record<string, unknown>, secret?: string | null, options?: SignOptions) => Promise<
|
|
3
|
-
|
|
1
|
+
import type { SignOptions, VerifyErrors } from 'jsonwebtoken';
|
|
2
|
+
export declare const signToken: ({ iat, exp, ...payload }: Record<string, unknown>, secret?: string | null, options?: SignOptions) => Promise<{
|
|
3
|
+
readonly _tag: "Result";
|
|
4
|
+
readonly error: undefined;
|
|
5
|
+
readonly result: string;
|
|
6
|
+
} | {
|
|
7
|
+
readonly _tag: "Error";
|
|
8
|
+
readonly error: VerifyErrors;
|
|
9
|
+
readonly result: undefined;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const decodeToken: <TToken>(token: string, secret?: string) => Promise<{
|
|
12
|
+
readonly _tag: "Error";
|
|
13
|
+
readonly error: VerifyErrors;
|
|
14
|
+
readonly result: undefined;
|
|
15
|
+
} | {
|
|
16
|
+
readonly _tag: "Result";
|
|
17
|
+
readonly error: undefined;
|
|
18
|
+
readonly result: TToken;
|
|
19
|
+
}>;
|
package/dist/token.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getConfig } from '@aeriajs/entrypoint';
|
|
2
|
+
import { Result } from '@aeriajs/types';
|
|
2
3
|
import jwt from 'jsonwebtoken';
|
|
3
4
|
const getTokenConfig = async () => {
|
|
4
5
|
const config = await getConfig();
|
|
@@ -22,9 +23,21 @@ export const signToken = async ({ iat, exp, ...payload }, secret, options) => {
|
|
|
22
23
|
tokenOptions.expiresIn = tokenConfig.tokenExpiration;
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
try {
|
|
27
|
+
const result = jwt.sign(payload, secret || tokenConfig.secret, tokenOptions);
|
|
28
|
+
return Result.result(result);
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
return Result.error(err);
|
|
32
|
+
}
|
|
26
33
|
};
|
|
27
34
|
export const decodeToken = async (token, secret) => {
|
|
28
35
|
const tokenConfig = await getTokenConfig();
|
|
29
|
-
|
|
36
|
+
try {
|
|
37
|
+
const result = jwt.verify(token, secret || tokenConfig.secret);
|
|
38
|
+
return Result.result(result);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
return Result.error(err);
|
|
42
|
+
}
|
|
30
43
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.285",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"aeriaMain": "tests/fixtures/aeriaMain.js",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"mongodb-memory-server": "^10.2.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@aeriajs/builtins": "^0.0.
|
|
43
|
+
"@aeriajs/builtins": "^0.0.285",
|
|
44
44
|
"@aeriajs/common": "^0.0.161",
|
|
45
45
|
"@aeriajs/entrypoint": "^0.0.169",
|
|
46
46
|
"@aeriajs/http": "^0.0.200",
|
|
47
|
-
"@aeriajs/security": "^0.0.
|
|
47
|
+
"@aeriajs/security": "^0.0.285",
|
|
48
48
|
"@aeriajs/types": "^0.0.137",
|
|
49
49
|
"@aeriajs/validation": "^0.0.185"
|
|
50
50
|
},
|