@twin.org/web 0.0.1-next.1

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.
Files changed (43) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +21 -0
  3. package/dist/cjs/index.cjs +1056 -0
  4. package/dist/esm/index.mjs +1046 -0
  5. package/dist/types/errors/fetchError.d.ts +22 -0
  6. package/dist/types/index.d.ts +14 -0
  7. package/dist/types/models/IFetchOptions.d.ts +30 -0
  8. package/dist/types/models/IHttpHeaders.d.ts +6 -0
  9. package/dist/types/models/IJwk.d.ts +62 -0
  10. package/dist/types/models/IJwtHeader.d.ts +22 -0
  11. package/dist/types/models/IJwtPayload.d.ts +37 -0
  12. package/dist/types/models/headerTypes.d.ts +41 -0
  13. package/dist/types/models/httpMethod.d.ts +18 -0
  14. package/dist/types/models/httpStatusCode.d.ts +257 -0
  15. package/dist/types/models/jwtAlgorithms.d.ts +17 -0
  16. package/dist/types/models/mimeTypes.d.ts +93 -0
  17. package/dist/types/utils/fetchHelper.d.ts +52 -0
  18. package/dist/types/utils/jwt.d.ts +85 -0
  19. package/dist/types/utils/mimeTypeHelper.d.ts +17 -0
  20. package/docs/changelog.md +5 -0
  21. package/docs/examples.md +1 -0
  22. package/docs/reference/classes/FetchError.md +379 -0
  23. package/docs/reference/classes/FetchHelper.md +185 -0
  24. package/docs/reference/classes/Jwt.md +313 -0
  25. package/docs/reference/classes/MimeTypeHelper.md +53 -0
  26. package/docs/reference/index.md +32 -0
  27. package/docs/reference/interfaces/IFetchOptions.md +53 -0
  28. package/docs/reference/interfaces/IHttpHeaders.md +7 -0
  29. package/docs/reference/interfaces/IJwk.md +111 -0
  30. package/docs/reference/interfaces/IJwtHeader.md +31 -0
  31. package/docs/reference/interfaces/IJwtPayload.md +63 -0
  32. package/docs/reference/type-aliases/HeaderTypes.md +5 -0
  33. package/docs/reference/type-aliases/HttpMethod.md +5 -0
  34. package/docs/reference/type-aliases/HttpStatusCode.md +5 -0
  35. package/docs/reference/type-aliases/JwtAlgorithms.md +5 -0
  36. package/docs/reference/type-aliases/MimeTypes.md +5 -0
  37. package/docs/reference/variables/HeaderTypes.md +55 -0
  38. package/docs/reference/variables/HttpMethod.md +43 -0
  39. package/docs/reference/variables/HttpStatusCode.md +379 -0
  40. package/docs/reference/variables/JwtAlgorithms.md +19 -0
  41. package/docs/reference/variables/MimeTypes.md +133 -0
  42. package/locales/en.json +18 -0
  43. package/package.json +65 -0
@@ -0,0 +1,313 @@
1
+ # Class: Jwt
2
+
3
+ Class to encode and decode JSON Web Tokens.
4
+
5
+ ## Constructors
6
+
7
+ ### new Jwt()
8
+
9
+ > **new Jwt**(): [`Jwt`](Jwt.md)
10
+
11
+ #### Returns
12
+
13
+ [`Jwt`](Jwt.md)
14
+
15
+ ## Methods
16
+
17
+ ### encode()
18
+
19
+ > `static` **encode**\<`U`, `T`\>(`header`, `payload`, `key`): `Promise`\<`string`\>
20
+
21
+ Encode a token.
22
+
23
+ #### Type Parameters
24
+
25
+ • **U** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
26
+
27
+ • **T** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
28
+
29
+ #### Parameters
30
+
31
+ • **header**: `U`
32
+
33
+ The header to encode.
34
+
35
+ • **payload**: `T`
36
+
37
+ The payload to encode.
38
+
39
+ • **key**: `Uint8Array`
40
+
41
+ The key for signing the token, can be omitted if a signer is provided.
42
+
43
+ #### Returns
44
+
45
+ `Promise`\<`string`\>
46
+
47
+ The encoded token.
48
+
49
+ ***
50
+
51
+ ### encodeWithSigner()
52
+
53
+ > `static` **encodeWithSigner**\<`U`, `T`\>(`header`, `payload`, `signer`): `Promise`\<`string`\>
54
+
55
+ Encode a token.
56
+
57
+ #### Type Parameters
58
+
59
+ • **U** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
60
+
61
+ • **T** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
62
+
63
+ #### Parameters
64
+
65
+ • **header**: `U`
66
+
67
+ The header to encode.
68
+
69
+ • **payload**: `T`
70
+
71
+ The payload to encode.
72
+
73
+ • **signer**
74
+
75
+ Custom signer method.
76
+
77
+ #### Returns
78
+
79
+ `Promise`\<`string`\>
80
+
81
+ The encoded token.
82
+
83
+ ***
84
+
85
+ ### decode()
86
+
87
+ > `static` **decode**\<`U`, `T`\>(`token`): `Promise`\<`object`\>
88
+
89
+ Decode a token.
90
+
91
+ #### Type Parameters
92
+
93
+ • **U** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
94
+
95
+ • **T** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
96
+
97
+ #### Parameters
98
+
99
+ • **token**: `string`
100
+
101
+ The token to decode.
102
+
103
+ #### Returns
104
+
105
+ `Promise`\<`object`\>
106
+
107
+ The decoded payload.
108
+
109
+ ##### header?
110
+
111
+ > `optional` **header**: `U`
112
+
113
+ ##### payload?
114
+
115
+ > `optional` **payload**: `T`
116
+
117
+ ##### signature?
118
+
119
+ > `optional` **signature**: `Uint8Array`
120
+
121
+ ***
122
+
123
+ ### verify()
124
+
125
+ > `static` **verify**\<`U`, `T`\>(`token`, `key`): `Promise`\<`object`\>
126
+
127
+ Verify a token.
128
+
129
+ #### Type Parameters
130
+
131
+ • **U** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
132
+
133
+ • **T** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
134
+
135
+ #### Parameters
136
+
137
+ • **token**: `string`
138
+
139
+ The token to verify.
140
+
141
+ • **key**: `Uint8Array`
142
+
143
+ The key for verifying the token
144
+
145
+ #### Returns
146
+
147
+ `Promise`\<`object`\>
148
+
149
+ The decoded payload.
150
+
151
+ ##### verified
152
+
153
+ > **verified**: `boolean`
154
+
155
+ ##### header?
156
+
157
+ > `optional` **header**: `U`
158
+
159
+ ##### payload?
160
+
161
+ > `optional` **payload**: `T`
162
+
163
+ ##### signature?
164
+
165
+ > `optional` **signature**: `Uint8Array`
166
+
167
+ ***
168
+
169
+ ### verifyWithVerifier()
170
+
171
+ > `static` **verifyWithVerifier**\<`U`, `T`\>(`token`, `verifier`): `Promise`\<`object`\>
172
+
173
+ Verify a token.
174
+
175
+ #### Type Parameters
176
+
177
+ • **U** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
178
+
179
+ • **T** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
180
+
181
+ #### Parameters
182
+
183
+ • **token**: `string`
184
+
185
+ The token to verify.
186
+
187
+ • **verifier**
188
+
189
+ Custom verification method.
190
+
191
+ #### Returns
192
+
193
+ `Promise`\<`object`\>
194
+
195
+ The decoded payload.
196
+
197
+ ##### verified
198
+
199
+ > **verified**: `boolean`
200
+
201
+ ##### header?
202
+
203
+ > `optional` **header**: `U`
204
+
205
+ ##### payload?
206
+
207
+ > `optional` **payload**: `T`
208
+
209
+ ##### signature?
210
+
211
+ > `optional` **signature**: `Uint8Array`
212
+
213
+ ***
214
+
215
+ ### verifySignature()
216
+
217
+ > `static` **verifySignature**\<`U`, `T`\>(`header`?, `payload`?, `signature`?, `key`?, `verifier`?): `Promise`\<`boolean`\>
218
+
219
+ Verify a token by parts.
220
+
221
+ #### Type Parameters
222
+
223
+ • **U** *extends* [`IJwtHeader`](../interfaces/IJwtHeader.md)
224
+
225
+ • **T** *extends* [`IJwtPayload`](../interfaces/IJwtPayload.md)
226
+
227
+ #### Parameters
228
+
229
+ • **header?**: `U`
230
+
231
+ The header to verify.
232
+
233
+ • **payload?**: `T`
234
+
235
+ The payload to verify.
236
+
237
+ • **signature?**: `Uint8Array`
238
+
239
+ The signature to verify.
240
+
241
+ • **key?**: `Uint8Array`
242
+
243
+ The key for verifying the token, if not provided no verification occurs.
244
+
245
+ • **verifier?**
246
+
247
+ Custom verification method.
248
+
249
+ #### Returns
250
+
251
+ `Promise`\<`boolean`\>
252
+
253
+ True if the parts are verified.
254
+
255
+ ***
256
+
257
+ ### defaultSigner()
258
+
259
+ > `static` **defaultSigner**(`alg`, `key`, `payload`): `Promise`\<`Uint8Array`\>
260
+
261
+ The default signer for the JWT.
262
+
263
+ #### Parameters
264
+
265
+ • **alg**: [`JwtAlgorithms`](../type-aliases/JwtAlgorithms.md)
266
+
267
+ The algorithm to use.
268
+
269
+ • **key**: `undefined` \| `Uint8Array`
270
+
271
+ The key to sign with.
272
+
273
+ • **payload**: `Uint8Array`
274
+
275
+ The payload to sign.
276
+
277
+ #### Returns
278
+
279
+ `Promise`\<`Uint8Array`\>
280
+
281
+ The signature.
282
+
283
+ ***
284
+
285
+ ### defaultVerifier()
286
+
287
+ > `static` **defaultVerifier**(`alg`, `key`, `payload`, `signature`): `Promise`\<`boolean`\>
288
+
289
+ The default verifier for the JWT.
290
+
291
+ #### Parameters
292
+
293
+ • **alg**: [`JwtAlgorithms`](../type-aliases/JwtAlgorithms.md)
294
+
295
+ The algorithm to use.
296
+
297
+ • **key**: `undefined` \| `Uint8Array`
298
+
299
+ The key to verify with.
300
+
301
+ • **payload**: `Uint8Array`
302
+
303
+ The payload to verify.
304
+
305
+ • **signature**: `Uint8Array`
306
+
307
+ The signature to verify.
308
+
309
+ #### Returns
310
+
311
+ `Promise`\<`boolean`\>
312
+
313
+ True if the signature was verified.
@@ -0,0 +1,53 @@
1
+ # Class: MimeTypeHelper
2
+
3
+ Class to help with mime types.
4
+
5
+ ## Constructors
6
+
7
+ ### new MimeTypeHelper()
8
+
9
+ > **new MimeTypeHelper**(): [`MimeTypeHelper`](MimeTypeHelper.md)
10
+
11
+ #### Returns
12
+
13
+ [`MimeTypeHelper`](MimeTypeHelper.md)
14
+
15
+ ## Methods
16
+
17
+ ### detect()
18
+
19
+ > `static` **detect**(`data`): `Promise`\<`undefined` \| `string`\>
20
+
21
+ Detect the mime type from a byte array.
22
+
23
+ #### Parameters
24
+
25
+ • **data**: `Uint8Array`
26
+
27
+ The data to test.
28
+
29
+ #### Returns
30
+
31
+ `Promise`\<`undefined` \| `string`\>
32
+
33
+ The mime type if detected.
34
+
35
+ ***
36
+
37
+ ### defaultExtension()
38
+
39
+ > `static` **defaultExtension**(`mimeType`): `undefined` \| `string`
40
+
41
+ Return the default extension for a mime type.
42
+
43
+ #### Parameters
44
+
45
+ • **mimeType**: `undefined` \| `string`
46
+
47
+ The mimetype to get the extension for.
48
+
49
+ #### Returns
50
+
51
+ `undefined` \| `string`
52
+
53
+ The extension for the mime type.
@@ -0,0 +1,32 @@
1
+ # @twin.org/web
2
+
3
+ ## Classes
4
+
5
+ - [FetchError](classes/FetchError.md)
6
+ - [FetchHelper](classes/FetchHelper.md)
7
+ - [Jwt](classes/Jwt.md)
8
+ - [MimeTypeHelper](classes/MimeTypeHelper.md)
9
+
10
+ ## Interfaces
11
+
12
+ - [IFetchOptions](interfaces/IFetchOptions.md)
13
+ - [IHttpHeaders](interfaces/IHttpHeaders.md)
14
+ - [IJwk](interfaces/IJwk.md)
15
+ - [IJwtHeader](interfaces/IJwtHeader.md)
16
+ - [IJwtPayload](interfaces/IJwtPayload.md)
17
+
18
+ ## Type Aliases
19
+
20
+ - [HeaderTypes](type-aliases/HeaderTypes.md)
21
+ - [HttpMethod](type-aliases/HttpMethod.md)
22
+ - [HttpStatusCode](type-aliases/HttpStatusCode.md)
23
+ - [JwtAlgorithms](type-aliases/JwtAlgorithms.md)
24
+ - [MimeTypes](type-aliases/MimeTypes.md)
25
+
26
+ ## Variables
27
+
28
+ - [HeaderTypes](variables/HeaderTypes.md)
29
+ - [HttpMethod](variables/HttpMethod.md)
30
+ - [HttpStatusCode](variables/HttpStatusCode.md)
31
+ - [JwtAlgorithms](variables/JwtAlgorithms.md)
32
+ - [MimeTypes](variables/MimeTypes.md)
@@ -0,0 +1,53 @@
1
+ # Interface: IFetchOptions
2
+
3
+ Options for call to the fetch helper.
4
+
5
+ ## Properties
6
+
7
+ ### headers?
8
+
9
+ > `optional` **headers**: [`IHttpHeaders`](IHttpHeaders.md)
10
+
11
+ #### Param
12
+
13
+ The headers for the request.
14
+
15
+ ***
16
+
17
+ ### timeoutMs?
18
+
19
+ > `optional` **timeoutMs**: `number`
20
+
21
+ Timeout for requests in milliseconds.
22
+
23
+ ***
24
+
25
+ ### includeCredentials?
26
+
27
+ > `optional` **includeCredentials**: `boolean`
28
+
29
+ Include credentials in the requests.
30
+
31
+ ***
32
+
33
+ ### retryCount?
34
+
35
+ > `optional` **retryCount**: `number`
36
+
37
+ The number of times to retry fetching defaults to no retries.
38
+
39
+ ***
40
+
41
+ ### retryDelayMs?
42
+
43
+ > `optional` **retryDelayMs**: `number`
44
+
45
+ The number of milliseconds we should delay before any retry.
46
+
47
+ ***
48
+
49
+ ### cacheTtlMs?
50
+
51
+ > `optional` **cacheTtlMs**: `number`
52
+
53
+ The number of milliseconds to cache the response for, leave undefined for no cache, 0 means infinite.
@@ -0,0 +1,7 @@
1
+ # Interface: IHttpHeaders
2
+
3
+ Model used for Http headers parameter.
4
+
5
+ ## Indexable
6
+
7
+ \[`key`: `string`\]: `string` \| `string`[]
@@ -0,0 +1,111 @@
1
+ # Interface: IJwk
2
+
3
+ The fields in a JSON Web Key.
4
+
5
+ ## Indexable
6
+
7
+ \[`key`: `string`\]: `unknown`
8
+
9
+ ## Properties
10
+
11
+ ### alg?
12
+
13
+ > `optional` **alg**: [`JwtAlgorithms`](../type-aliases/JwtAlgorithms.md)
14
+
15
+ The cryptographic algorithm for the key.
16
+
17
+ ***
18
+
19
+ ### use?
20
+
21
+ > `optional` **use**: `string`
22
+
23
+ The intended use for the key.
24
+
25
+ ***
26
+
27
+ ### key\_ops?
28
+
29
+ > `optional` **key\_ops**: `string`[]
30
+
31
+ The operation(s) that the key is intended to be used for.
32
+
33
+ ***
34
+
35
+ ### kty
36
+
37
+ > **kty**: `string`
38
+
39
+ The key type parameter.
40
+
41
+ ***
42
+
43
+ ### n?
44
+
45
+ > `optional` **n**: `string`
46
+
47
+ The public key parameters.
48
+
49
+ ***
50
+
51
+ ### e?
52
+
53
+ > `optional` **e**: `string`
54
+
55
+ Exponent parameter.
56
+
57
+ ***
58
+
59
+ ### d?
60
+
61
+ > `optional` **d**: `string`
62
+
63
+ The private key parameters.
64
+
65
+ ***
66
+
67
+ ### p?
68
+
69
+ > `optional` **p**: `string`
70
+
71
+ The private key parameters.
72
+
73
+ ***
74
+
75
+ ### q?
76
+
77
+ > `optional` **q**: `string`
78
+
79
+ The private key parameters.
80
+
81
+ ***
82
+
83
+ ### dp?
84
+
85
+ > `optional` **dp**: `string`
86
+
87
+ The private key parameters.
88
+
89
+ ***
90
+
91
+ ### dq?
92
+
93
+ > `optional` **dq**: `string`
94
+
95
+ The private key parameters.
96
+
97
+ ***
98
+
99
+ ### qi?
100
+
101
+ > `optional` **qi**: `string`
102
+
103
+ The private key parameters.
104
+
105
+ ***
106
+
107
+ ### kid?
108
+
109
+ > `optional` **kid**: `string`
110
+
111
+ The key ID.
@@ -0,0 +1,31 @@
1
+ # Interface: IJwtHeader
2
+
3
+ The fields in a JSON Web Token header.
4
+
5
+ ## Indexable
6
+
7
+ \[`key`: `string`\]: `unknown`
8
+
9
+ ## Properties
10
+
11
+ ### typ?
12
+
13
+ > `optional` **typ**: `string`
14
+
15
+ The type of the token.
16
+
17
+ ***
18
+
19
+ ### alg
20
+
21
+ > **alg**: [`JwtAlgorithms`](../type-aliases/JwtAlgorithms.md)
22
+
23
+ The algorithm used to sign the token.
24
+
25
+ ***
26
+
27
+ ### kid?
28
+
29
+ > `optional` **kid**: `string`
30
+
31
+ The key ID.
@@ -0,0 +1,63 @@
1
+ # Interface: IJwtPayload
2
+
3
+ The fields in a JSON Web Token payload.
4
+
5
+ ## Indexable
6
+
7
+ \[`key`: `string`\]: `unknown`
8
+
9
+ ## Properties
10
+
11
+ ### iss?
12
+
13
+ > `optional` **iss**: `string`
14
+
15
+ The issuer of the token.
16
+
17
+ ***
18
+
19
+ ### sub?
20
+
21
+ > `optional` **sub**: `string`
22
+
23
+ The subject of the token.
24
+
25
+ ***
26
+
27
+ ### aud?
28
+
29
+ > `optional` **aud**: `string`
30
+
31
+ The audience of the token.
32
+
33
+ ***
34
+
35
+ ### exp?
36
+
37
+ > `optional` **exp**: `number`
38
+
39
+ The expiration time of the token.
40
+
41
+ ***
42
+
43
+ ### nbf?
44
+
45
+ > `optional` **nbf**: `number`
46
+
47
+ The not before time of the token.
48
+
49
+ ***
50
+
51
+ ### iat?
52
+
53
+ > `optional` **iat**: `number`
54
+
55
+ The issued at time of the token.
56
+
57
+ ***
58
+
59
+ ### jti?
60
+
61
+ > `optional` **jti**: `string`
62
+
63
+ The JWT ID.
@@ -0,0 +1,5 @@
1
+ # Type Alias: HeaderTypes
2
+
3
+ > **HeaderTypes**: *typeof* [`HeaderTypes`](../variables/HeaderTypes.md)\[keyof *typeof* [`HeaderTypes`](../variables/HeaderTypes.md)\]
4
+
5
+ Common http header types.
@@ -0,0 +1,5 @@
1
+ # Type Alias: HttpMethod
2
+
3
+ > **HttpMethod**: *typeof* [`HttpMethod`](../variables/HttpMethod.md)\[keyof *typeof* [`HttpMethod`](../variables/HttpMethod.md)\]
4
+
5
+ The HTTP Methods.
@@ -0,0 +1,5 @@
1
+ # Type Alias: HttpStatusCode
2
+
3
+ > **HttpStatusCode**: *typeof* [`HttpStatusCode`](../variables/HttpStatusCode.md)\[keyof *typeof* [`HttpStatusCode`](../variables/HttpStatusCode.md)\]
4
+
5
+ Standard HTTP status codes.
@@ -0,0 +1,5 @@
1
+ # Type Alias: JwtAlgorithms
2
+
3
+ > **JwtAlgorithms**: *typeof* [`JwtAlgorithms`](../variables/JwtAlgorithms.md)\[keyof *typeof* [`JwtAlgorithms`](../variables/JwtAlgorithms.md)\]
4
+
5
+ The cryptographic algorithms supported for JSON Web Tokens and JSON Web Keys.
@@ -0,0 +1,5 @@
1
+ # Type Alias: MimeTypes
2
+
3
+ > **MimeTypes**: *typeof* [`MimeTypes`](../variables/MimeTypes.md)\[keyof *typeof* [`MimeTypes`](../variables/MimeTypes.md)\]
4
+
5
+ Common mime types.