@twin.org/web 0.0.1-next.4 → 0.0.1-next.40
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/cjs/index.cjs +151 -96
- package/dist/esm/index.mjs +153 -98
- package/dist/types/index.d.ts +2 -1
- package/dist/types/models/IJwk.d.ts +2 -58
- package/dist/types/models/IJwtHeader.d.ts +2 -18
- package/dist/types/models/IJwtPayload.d.ts +2 -33
- package/dist/types/models/headerTypes.d.ts +8 -8
- package/dist/types/models/jwkCryptoKey.d.ts +4 -0
- package/dist/types/models/mimeTypes.d.ts +4 -0
- package/dist/types/utils/jwk.d.ts +13 -0
- package/dist/types/utils/jwt.d.ts +67 -29
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/FetchError.md +13 -5
- package/docs/reference/classes/FetchHelper.md +51 -17
- package/docs/reference/classes/Jwk.md +35 -0
- package/docs/reference/classes/Jwt.md +222 -102
- package/docs/reference/classes/MimeTypeHelper.md +6 -2
- package/docs/reference/index.md +2 -2
- package/docs/reference/interfaces/IHttpHeaders.md +1 -1
- package/docs/reference/interfaces/IJwk.md +2 -106
- package/docs/reference/interfaces/IJwtHeader.md +4 -24
- package/docs/reference/interfaces/IJwtPayload.md +4 -56
- package/docs/reference/type-aliases/JwkCryptoKey.md +5 -0
- package/docs/reference/variables/HeaderTypes.md +8 -8
- package/docs/reference/variables/MimeTypes.md +6 -0
- package/locales/en.json +7 -1
- package/package.json +7 -6
- package/dist/types/models/jwtAlgorithms.d.ts +0 -17
- package/docs/reference/type-aliases/JwtAlgorithms.md +0 -5
- package/docs/reference/variables/JwtAlgorithms.md +0 -19
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { IJwtHeader } from "../models/IJwtHeader";
|
|
2
2
|
import type { IJwtPayload } from "../models/IJwtPayload";
|
|
3
|
-
import {
|
|
3
|
+
import type { JwkCryptoKey } from "../models/jwkCryptoKey";
|
|
4
4
|
/**
|
|
5
|
-
* Class to
|
|
5
|
+
* Class to handle JSON Web Tokens.
|
|
6
6
|
*/
|
|
7
7
|
export declare class Jwt {
|
|
8
8
|
/**
|
|
@@ -12,7 +12,7 @@ export declare class Jwt {
|
|
|
12
12
|
* @param key The key for signing the token, can be omitted if a signer is provided.
|
|
13
13
|
* @returns The encoded token.
|
|
14
14
|
*/
|
|
15
|
-
static encode<
|
|
15
|
+
static encode<T extends IJwtHeader, U extends IJwtPayload>(header: T, payload: U, key: JwkCryptoKey): Promise<string>;
|
|
16
16
|
/**
|
|
17
17
|
* Encode a token.
|
|
18
18
|
* @param header The header to encode.
|
|
@@ -20,15 +20,15 @@ export declare class Jwt {
|
|
|
20
20
|
* @param signer Custom signer method.
|
|
21
21
|
* @returns The encoded token.
|
|
22
22
|
*/
|
|
23
|
-
static encodeWithSigner<
|
|
23
|
+
static encodeWithSigner<T extends IJwtHeader, U extends IJwtPayload>(header: T, payload: U, signer: (header: IJwtHeader, payload: IJwtPayload, key: JwkCryptoKey | undefined) => Promise<string>): Promise<string>;
|
|
24
24
|
/**
|
|
25
25
|
* Decode a token.
|
|
26
26
|
* @param token The token to decode.
|
|
27
27
|
* @returns The decoded payload.
|
|
28
28
|
*/
|
|
29
|
-
static decode<
|
|
30
|
-
header?:
|
|
31
|
-
payload?:
|
|
29
|
+
static decode<T extends IJwtHeader, U extends IJwtPayload>(token: string): Promise<{
|
|
30
|
+
header?: T;
|
|
31
|
+
payload?: U;
|
|
32
32
|
signature?: Uint8Array;
|
|
33
33
|
}>;
|
|
34
34
|
/**
|
|
@@ -37,11 +37,9 @@ export declare class Jwt {
|
|
|
37
37
|
* @param key The key for verifying the token
|
|
38
38
|
* @returns The decoded payload.
|
|
39
39
|
*/
|
|
40
|
-
static verify<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
payload?: T;
|
|
44
|
-
signature?: Uint8Array;
|
|
40
|
+
static verify<T extends IJwtHeader, U extends IJwtPayload>(token: string, key: JwkCryptoKey): Promise<{
|
|
41
|
+
header: T;
|
|
42
|
+
payload: U;
|
|
45
43
|
}>;
|
|
46
44
|
/**
|
|
47
45
|
* Verify a token.
|
|
@@ -49,37 +47,77 @@ export declare class Jwt {
|
|
|
49
47
|
* @param verifier Custom verification method.
|
|
50
48
|
* @returns The decoded payload.
|
|
51
49
|
*/
|
|
52
|
-
static verifyWithVerifier<
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
static verifyWithVerifier<T extends IJwtHeader, U extends IJwtPayload>(token: string, verifier: (token: string, key: JwkCryptoKey | undefined) => Promise<{
|
|
51
|
+
header: T;
|
|
52
|
+
payload: U;
|
|
53
|
+
}>): Promise<{
|
|
54
|
+
header: T;
|
|
55
|
+
payload: U;
|
|
57
56
|
}>;
|
|
58
57
|
/**
|
|
59
58
|
* Verify a token by parts.
|
|
60
|
-
* @param
|
|
61
|
-
* @param payload The payload to verify.
|
|
62
|
-
* @param signature The signature to verify.
|
|
59
|
+
* @param token The token to verify.
|
|
63
60
|
* @param key The key for verifying the token, if not provided no verification occurs.
|
|
64
61
|
* @param verifier Custom verification method.
|
|
65
62
|
* @returns True if the parts are verified.
|
|
66
63
|
*/
|
|
67
|
-
static verifySignature<
|
|
64
|
+
static verifySignature<T extends IJwtHeader, U extends IJwtPayload>(token: string, key?: JwkCryptoKey, verifier?: (token: string, key: JwkCryptoKey | undefined) => Promise<{
|
|
65
|
+
header: T;
|
|
66
|
+
payload: U;
|
|
67
|
+
}>): Promise<{
|
|
68
|
+
header: T;
|
|
69
|
+
payload: U;
|
|
70
|
+
}>;
|
|
68
71
|
/**
|
|
69
72
|
* The default signer for the JWT.
|
|
70
|
-
* @param
|
|
71
|
-
* @param key The key to sign with.
|
|
73
|
+
* @param header The header to sign.
|
|
72
74
|
* @param payload The payload to sign.
|
|
75
|
+
* @param key The optional key to sign with.
|
|
73
76
|
* @returns The signature.
|
|
74
77
|
*/
|
|
75
|
-
static defaultSigner(
|
|
78
|
+
static defaultSigner(header: IJwtHeader, payload: IJwtPayload, key: JwkCryptoKey | undefined): Promise<string>;
|
|
76
79
|
/**
|
|
77
80
|
* The default verifier for the JWT.
|
|
78
|
-
* @param
|
|
81
|
+
* @param token The token to verify.
|
|
79
82
|
* @param key The key to verify with.
|
|
80
|
-
* @
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
* @returns The header and payload if verification successful.
|
|
84
|
+
*/
|
|
85
|
+
static defaultVerifier<T extends IJwtHeader, U extends IJwtPayload>(token: string, key: JwkCryptoKey | undefined): Promise<{
|
|
86
|
+
header: T;
|
|
87
|
+
payload: U;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Create bytes for signing from header and payload.
|
|
91
|
+
* @param header The header.
|
|
92
|
+
* @param payload The payload.
|
|
93
|
+
* @returns The bytes to sign.
|
|
94
|
+
*/
|
|
95
|
+
static toSigningBytes<T extends IJwtHeader, U extends IJwtPayload>(header: T, payload: U): Uint8Array;
|
|
96
|
+
/**
|
|
97
|
+
* Create header and payload from signing bytes.
|
|
98
|
+
* @param signingBytes The signing bytes from a token.
|
|
99
|
+
* @returns The header and payload.
|
|
100
|
+
* @throws If the signing bytes are invalid
|
|
101
|
+
*/
|
|
102
|
+
static fromSigningBytes<T extends IJwtHeader, U extends IJwtPayload>(signingBytes: Uint8Array): {
|
|
103
|
+
header: T;
|
|
104
|
+
payload: U;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Convert signed bytes and signature bytes to token.
|
|
108
|
+
* @param signingBytes The signed bytes.
|
|
109
|
+
* @param signature The signature.
|
|
110
|
+
* @returns The token.
|
|
111
|
+
*/
|
|
112
|
+
static tokenFromBytes(signingBytes: Uint8Array, signature: Uint8Array): string;
|
|
113
|
+
/**
|
|
114
|
+
* Convert the token to signing bytes and signature bytes.
|
|
115
|
+
* @param token The token to convert to bytes.
|
|
116
|
+
* @returns The decoded bytes.
|
|
117
|
+
* @throws If the token is invalid.
|
|
83
118
|
*/
|
|
84
|
-
static
|
|
119
|
+
static tokenToBytes(token: string): {
|
|
120
|
+
signingBytes: Uint8Array;
|
|
121
|
+
signature: Uint8Array;
|
|
122
|
+
};
|
|
85
123
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -16,23 +16,31 @@ Create a new instance of FetchError.
|
|
|
16
16
|
|
|
17
17
|
#### Parameters
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
##### source
|
|
20
|
+
|
|
21
|
+
`string`
|
|
20
22
|
|
|
21
23
|
The source of the error.
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
##### message
|
|
26
|
+
|
|
27
|
+
`string`
|
|
24
28
|
|
|
25
29
|
The message as a code.
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
##### httpStatus
|
|
32
|
+
|
|
33
|
+
[`HttpStatusCode`](../type-aliases/HttpStatusCode.md)
|
|
28
34
|
|
|
29
35
|
The http status code.
|
|
30
36
|
|
|
31
|
-
|
|
37
|
+
##### properties?
|
|
32
38
|
|
|
33
39
|
Any additional information for the error.
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
##### inner?
|
|
42
|
+
|
|
43
|
+
`unknown`
|
|
36
44
|
|
|
37
45
|
The inner error if we have wrapped another error.
|
|
38
46
|
|
|
@@ -22,23 +22,33 @@ Perform a fetch request.
|
|
|
22
22
|
|
|
23
23
|
#### Parameters
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
##### source
|
|
26
|
+
|
|
27
|
+
`string`
|
|
26
28
|
|
|
27
29
|
The source for the request.
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
##### url
|
|
32
|
+
|
|
33
|
+
`string`
|
|
30
34
|
|
|
31
35
|
The url for the request.
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
##### method
|
|
38
|
+
|
|
39
|
+
[`HttpMethod`](../type-aliases/HttpMethod.md)
|
|
34
40
|
|
|
35
41
|
The http method.
|
|
36
42
|
|
|
37
|
-
|
|
43
|
+
##### body?
|
|
38
44
|
|
|
39
45
|
Request to send to the endpoint.
|
|
40
46
|
|
|
41
|
-
|
|
47
|
+
`string` | `Uint8Array`
|
|
48
|
+
|
|
49
|
+
##### options?
|
|
50
|
+
|
|
51
|
+
`Omit`\<[`IFetchOptions`](../interfaces/IFetchOptions.md), `"cacheTtlSeconds"`\>
|
|
42
52
|
|
|
43
53
|
Options for sending the requests.
|
|
44
54
|
|
|
@@ -64,23 +74,33 @@ Perform a request in json format.
|
|
|
64
74
|
|
|
65
75
|
#### Parameters
|
|
66
76
|
|
|
67
|
-
|
|
77
|
+
##### source
|
|
78
|
+
|
|
79
|
+
`string`
|
|
68
80
|
|
|
69
81
|
The source for the request.
|
|
70
82
|
|
|
71
|
-
|
|
83
|
+
##### url
|
|
84
|
+
|
|
85
|
+
`string`
|
|
72
86
|
|
|
73
87
|
The url for the request.
|
|
74
88
|
|
|
75
|
-
|
|
89
|
+
##### method
|
|
90
|
+
|
|
91
|
+
[`HttpMethod`](../type-aliases/HttpMethod.md)
|
|
76
92
|
|
|
77
93
|
The http method.
|
|
78
94
|
|
|
79
|
-
|
|
95
|
+
##### requestData?
|
|
96
|
+
|
|
97
|
+
`T`
|
|
80
98
|
|
|
81
99
|
Request to send to the endpoint.
|
|
82
100
|
|
|
83
|
-
|
|
101
|
+
##### options?
|
|
102
|
+
|
|
103
|
+
[`IFetchOptions`](../interfaces/IFetchOptions.md)
|
|
84
104
|
|
|
85
105
|
Options for sending the requests.
|
|
86
106
|
|
|
@@ -104,23 +124,33 @@ Perform a request for binary data.
|
|
|
104
124
|
|
|
105
125
|
#### Parameters
|
|
106
126
|
|
|
107
|
-
|
|
127
|
+
##### source
|
|
128
|
+
|
|
129
|
+
`string`
|
|
108
130
|
|
|
109
131
|
The source for the request.
|
|
110
132
|
|
|
111
|
-
|
|
133
|
+
##### url
|
|
134
|
+
|
|
135
|
+
`string`
|
|
112
136
|
|
|
113
137
|
The url for the request.
|
|
114
138
|
|
|
115
|
-
|
|
139
|
+
##### method
|
|
116
140
|
|
|
117
141
|
The http method.
|
|
118
142
|
|
|
119
|
-
|
|
143
|
+
`"GET"` | `"POST"`
|
|
144
|
+
|
|
145
|
+
##### requestData?
|
|
146
|
+
|
|
147
|
+
`Uint8Array`
|
|
120
148
|
|
|
121
149
|
Request to send to the endpoint.
|
|
122
150
|
|
|
123
|
-
|
|
151
|
+
##### options?
|
|
152
|
+
|
|
153
|
+
[`IFetchOptions`](../interfaces/IFetchOptions.md)
|
|
124
154
|
|
|
125
155
|
Options for sending the requests.
|
|
126
156
|
|
|
@@ -156,7 +186,9 @@ Get a cache entry.
|
|
|
156
186
|
|
|
157
187
|
#### Parameters
|
|
158
188
|
|
|
159
|
-
|
|
189
|
+
##### url
|
|
190
|
+
|
|
191
|
+
`string`
|
|
160
192
|
|
|
161
193
|
The url for the request.
|
|
162
194
|
|
|
@@ -176,7 +208,9 @@ Remove a cache entry.
|
|
|
176
208
|
|
|
177
209
|
#### Parameters
|
|
178
210
|
|
|
179
|
-
|
|
211
|
+
##### url
|
|
212
|
+
|
|
213
|
+
`string`
|
|
180
214
|
|
|
181
215
|
The url for the request.
|
|
182
216
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Class: Jwk
|
|
2
|
+
|
|
3
|
+
Class to handle JSON Web Keys.
|
|
4
|
+
|
|
5
|
+
## Constructors
|
|
6
|
+
|
|
7
|
+
### new Jwk()
|
|
8
|
+
|
|
9
|
+
> **new Jwk**(): [`Jwk`](Jwk.md)
|
|
10
|
+
|
|
11
|
+
#### Returns
|
|
12
|
+
|
|
13
|
+
[`Jwk`](Jwk.md)
|
|
14
|
+
|
|
15
|
+
## Methods
|
|
16
|
+
|
|
17
|
+
### toCryptoKey()
|
|
18
|
+
|
|
19
|
+
> `static` **toCryptoKey**(`jwk`): `Promise`\<[`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)\>
|
|
20
|
+
|
|
21
|
+
Convert the JWK to a crypto key.
|
|
22
|
+
|
|
23
|
+
#### Parameters
|
|
24
|
+
|
|
25
|
+
##### jwk
|
|
26
|
+
|
|
27
|
+
[`IJwk`](../interfaces/IJwk.md)
|
|
28
|
+
|
|
29
|
+
The JWK to convert.
|
|
30
|
+
|
|
31
|
+
#### Returns
|
|
32
|
+
|
|
33
|
+
`Promise`\<[`JwkCryptoKey`](../type-aliases/JwkCryptoKey.md)\>
|
|
34
|
+
|
|
35
|
+
The crypto key.
|