@twin.org/web 0.0.3-next.21 → 0.0.3-next.23

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # TWIN Web
2
2
 
3
- Contains classes for use with web operations.
3
+ This package is part of the framework workspace and provides classes for use with web operations to support consistent development workflows across the ecosystem.
4
4
 
5
5
  ## Installation
6
6
 
package/docs/changelog.md CHANGED
@@ -1,4 +1,44 @@
1
- # @twin.org/web - Changelog
1
+ # Changelog
2
+
3
+ ## [0.0.3-next.23](https://github.com/twinfoundation/framework/compare/web-v0.0.3-next.22...web-v0.0.3-next.23) (2026-03-17)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **web:** Synchronize repo versions
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/core bumped from 0.0.3-next.22 to 0.0.3-next.23
16
+ * @twin.org/crypto bumped from 0.0.3-next.22 to 0.0.3-next.23
17
+ * @twin.org/nameof bumped from 0.0.3-next.22 to 0.0.3-next.23
18
+ * devDependencies
19
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.22 to 0.0.3-next.23
20
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.22 to 0.0.3-next.23
21
+ * @twin.org/validate-locales bumped from 0.0.3-next.22 to 0.0.3-next.23
22
+
23
+ ## [0.0.3-next.22](https://github.com/twinfoundation/framework/compare/web-v0.0.3-next.21...web-v0.0.3-next.22) (2026-02-26)
24
+
25
+
26
+ ### Miscellaneous Chores
27
+
28
+ * **web:** Synchronize repo versions
29
+
30
+
31
+ ### Dependencies
32
+
33
+ * The following workspace dependencies were updated
34
+ * dependencies
35
+ * @twin.org/core bumped from 0.0.3-next.21 to 0.0.3-next.22
36
+ * @twin.org/crypto bumped from 0.0.3-next.21 to 0.0.3-next.22
37
+ * @twin.org/nameof bumped from 0.0.3-next.21 to 0.0.3-next.22
38
+ * devDependencies
39
+ * @twin.org/nameof-transformer bumped from 0.0.3-next.21 to 0.0.3-next.22
40
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.3-next.21 to 0.0.3-next.22
41
+ * @twin.org/validate-locales bumped from 0.0.3-next.21 to 0.0.3-next.22
2
42
 
3
43
  ## [0.0.3-next.21](https://github.com/twinfoundation/framework/compare/web-v0.0.3-next.20...web-v0.0.3-next.21) (2026-02-26)
4
44
 
package/docs/examples.md CHANGED
@@ -1 +1,108 @@
1
- # @twin.org/web - Examples
1
+ # Web Examples
2
+
3
+ Use these snippets for token handling, fetch utilities and HTTP header helpers in browser and server runtimes.
4
+
5
+ ## Jwt
6
+
7
+ ```typescript
8
+ import { Jwt } from '@twin.org/web';
9
+
10
+ const payload = {
11
+ sub: 'user-01',
12
+ role: 'editor'
13
+ };
14
+
15
+ const token = Jwt.encode(payload, {
16
+ alg: 'HS256'
17
+ });
18
+
19
+ Jwt.decode(token).sub; // 'user-01'
20
+ ```
21
+
22
+ ```typescript
23
+ import { Jwt } from '@twin.org/web';
24
+
25
+ const token = Jwt.encode({ sub: 'u-2' }, { alg: 'HS256' });
26
+ Jwt.verify(token, {
27
+ key: 'local-signing-key'
28
+ }); // true
29
+ ```
30
+
31
+ ## FetchHelper
32
+
33
+ ```typescript
34
+ import { FetchHelper } from '@twin.org/web';
35
+
36
+ const response = await FetchHelper.fetchJson<{ status: string }>('https://api.example.org/status', {
37
+ method: 'GET',
38
+ cacheSeconds: 30
39
+ });
40
+
41
+ response.status; // 'ok'
42
+ ```
43
+
44
+ ## HeaderHelper
45
+
46
+ ```typescript
47
+ import { HeaderHelper } from '@twin.org/web';
48
+
49
+ const header = HeaderHelper.createBearer('token-123');
50
+
51
+ HeaderHelper.extractBearer(header); // 'token-123'
52
+ ```
53
+
54
+ ## Jwk and Jws
55
+
56
+ ```typescript
57
+ import { Jwk, Jws } from '@twin.org/web';
58
+
59
+ const jwk = Jwk.fromEd25519Public(new Uint8Array(32));
60
+ const compact = Jws.create(
61
+ {
62
+ typ: 'JWT',
63
+ alg: 'EdDSA'
64
+ },
65
+ {
66
+ iss: 'issuer-1'
67
+ },
68
+ async signingBytes => signingBytes
69
+ );
70
+
71
+ Jws.verify(compact, async () => true); // true
72
+ jwk.kty; // 'OKP'
73
+ ```
74
+
75
+ ## CookieHelper
76
+
77
+ ```typescript
78
+ import { CookieHelper } from '@twin.org/web';
79
+
80
+ CookieHelper.createCookie('sessionId', 'abc123', {
81
+ path: '/',
82
+ maxAge: 1800,
83
+ secure: true,
84
+ httpOnly: true
85
+ }); // 'sessionId=abc123; Max-Age=1800; Path=/; Secure; HttpOnly'
86
+ ```
87
+
88
+ ## MimeTypeHelper
89
+
90
+ ```typescript
91
+ import { MimeTypeHelper } from '@twin.org/web';
92
+
93
+ MimeTypeHelper.detect('avatar.png'); // 'image/png'
94
+ MimeTypeHelper.defaultExtension('application/json'); // 'json'
95
+ ```
96
+
97
+ ## FetchError
98
+
99
+ ```typescript
100
+ import { FetchError } from '@twin.org/web';
101
+
102
+ const error = new FetchError(this.CLASS_NAME, 'fetchFailed', {
103
+ statusCode: 503,
104
+ retryable: true
105
+ });
106
+
107
+ error.toJsonObject().statusCode; // 503
108
+ ```
@@ -14,7 +14,7 @@ Class to help with cookie operations.
14
14
 
15
15
  ## Properties
16
16
 
17
- ### CLASS\_NAME
17
+ ### CLASS\_NAME {#class_name}
18
18
 
19
19
  > `readonly` `static` **CLASS\_NAME**: `string`
20
20
 
@@ -22,7 +22,7 @@ Runtime name for the class.
22
22
 
23
23
  ## Methods
24
24
 
25
- ### createCookie()
25
+ ### createCookie() {#createcookie}
26
26
 
27
27
  > `static` **createCookie**(`cookieName`, `cookieValue`, `options?`): `string`
28
28
 
@@ -78,7 +78,7 @@ The created cookie string.
78
78
 
79
79
  ***
80
80
 
81
- ### deleteCookie()
81
+ ### deleteCookie() {#deletecookie}
82
82
 
83
83
  > `static` **deleteCookie**(`cookieName`, `options?`): `string`
84
84
 
@@ -128,7 +128,7 @@ The created cookie string.
128
128
 
129
129
  ***
130
130
 
131
- ### getCookieFromHeaders()
131
+ ### getCookieFromHeaders() {#getcookiefromheaders}
132
132
 
133
133
  > `static` **getCookieFromHeaders**(`headers`, `cookieName`): `string` \| `undefined`
134
134
 
@@ -54,8 +54,460 @@ The cause of the error if we have wrapped another error.
54
54
 
55
55
  ## Properties
56
56
 
57
- ### CLASS\_NAME
57
+ ### source? {#source}
58
+
59
+ > `optional` **source**: `string`
60
+
61
+ The source of the error.
62
+
63
+ #### Inherited from
64
+
65
+ `BaseError.source`
66
+
67
+ ***
68
+
69
+ ### properties? {#properties}
70
+
71
+ > `optional` **properties**: `object`
72
+
73
+ Any additional information for the error.
74
+
75
+ #### Index Signature
76
+
77
+ \[`id`: `string`\]: `unknown`
78
+
79
+ #### Inherited from
80
+
81
+ `BaseError.properties`
82
+
83
+ ***
84
+
85
+ ### cause? {#cause}
86
+
87
+ > `optional` **cause**: `IError`
88
+
89
+ The cause of the error.
90
+
91
+ #### Inherited from
92
+
93
+ `BaseError.cause`
94
+
95
+ ***
96
+
97
+ ### CLASS\_NAME {#class_name}
58
98
 
59
99
  > `readonly` `static` **CLASS\_NAME**: `string`
60
100
 
61
101
  Runtime name for the class.
102
+
103
+ ## Methods
104
+
105
+ ### fromError() {#fromerror}
106
+
107
+ > `static` **fromError**(`err`): `BaseError`
108
+
109
+ Construct an error from an existing one.
110
+
111
+ #### Parameters
112
+
113
+ ##### err
114
+
115
+ `unknown`
116
+
117
+ The existing error.
118
+
119
+ #### Returns
120
+
121
+ `BaseError`
122
+
123
+ The new instance.
124
+
125
+ #### Inherited from
126
+
127
+ `BaseError.fromError`
128
+
129
+ ***
130
+
131
+ ### flatten() {#flatten}
132
+
133
+ > `static` **flatten**(`err`): `IError`[]
134
+
135
+ Flatten an error tree.
136
+
137
+ #### Parameters
138
+
139
+ ##### err
140
+
141
+ `unknown`
142
+
143
+ The starting error.
144
+
145
+ #### Returns
146
+
147
+ `IError`[]
148
+
149
+ The list of all internal errors.
150
+
151
+ #### Inherited from
152
+
153
+ `BaseError.flatten`
154
+
155
+ ***
156
+
157
+ ### expand() {#expand}
158
+
159
+ > `static` **expand**(`errors`): `IError` \| `undefined`
160
+
161
+ Expand an error tree.
162
+
163
+ #### Parameters
164
+
165
+ ##### errors
166
+
167
+ The list of errors to expand.
168
+
169
+ `IError`[] | `undefined`
170
+
171
+ #### Returns
172
+
173
+ `IError` \| `undefined`
174
+
175
+ The first level error.
176
+
177
+ #### Inherited from
178
+
179
+ `BaseError.expand`
180
+
181
+ ***
182
+
183
+ ### isErrorName() {#iserrorname}
184
+
185
+ > `static` **isErrorName**(`error`, `name`): `error is BaseError`
186
+
187
+ Test to see if the error has the specified error name.
188
+
189
+ #### Parameters
190
+
191
+ ##### error
192
+
193
+ `unknown`
194
+
195
+ The error to test.
196
+
197
+ ##### name
198
+
199
+ The name to check for.
200
+
201
+ `string` | `RegExp`
202
+
203
+ #### Returns
204
+
205
+ `error is BaseError`
206
+
207
+ True if the error has the name.
208
+
209
+ #### Inherited from
210
+
211
+ `BaseError.isErrorName`
212
+
213
+ ***
214
+
215
+ ### isErrorMessage() {#iserrormessage}
216
+
217
+ > `static` **isErrorMessage**(`error`, `message`): `error is BaseError`
218
+
219
+ Test to see if the error has the specified error message.
220
+
221
+ #### Parameters
222
+
223
+ ##### error
224
+
225
+ `unknown`
226
+
227
+ The error to test.
228
+
229
+ ##### message
230
+
231
+ The message to check for.
232
+
233
+ `string` | `RegExp`
234
+
235
+ #### Returns
236
+
237
+ `error is BaseError`
238
+
239
+ True if the error has the name.
240
+
241
+ #### Inherited from
242
+
243
+ `BaseError.isErrorMessage`
244
+
245
+ ***
246
+
247
+ ### isErrorCode() {#iserrorcode}
248
+
249
+ > `static` **isErrorCode**(`error`, `code`): `boolean`
250
+
251
+ Test to see if the error has the specified error code.
252
+
253
+ #### Parameters
254
+
255
+ ##### error
256
+
257
+ `unknown`
258
+
259
+ The error to test.
260
+
261
+ ##### code
262
+
263
+ The code to check for.
264
+
265
+ `string` | `RegExp`
266
+
267
+ #### Returns
268
+
269
+ `boolean`
270
+
271
+ True if the error has the code.
272
+
273
+ #### Inherited from
274
+
275
+ `BaseError.isErrorCode`
276
+
277
+ ***
278
+
279
+ ### someErrorName() {#someerrorname}
280
+
281
+ > `static` **someErrorName**(`error`, `name`): `error is BaseError`
282
+
283
+ Test to see if any of the errors or children have the given error name.
284
+
285
+ #### Parameters
286
+
287
+ ##### error
288
+
289
+ `unknown`
290
+
291
+ The error to test.
292
+
293
+ ##### name
294
+
295
+ The name to check for.
296
+
297
+ `string` | `RegExp`
298
+
299
+ #### Returns
300
+
301
+ `error is BaseError`
302
+
303
+ True if the error has the name.
304
+
305
+ #### Inherited from
306
+
307
+ `BaseError.someErrorName`
308
+
309
+ ***
310
+
311
+ ### someErrorMessage() {#someerrormessage}
312
+
313
+ > `static` **someErrorMessage**(`error`, `message`): `error is BaseError`
314
+
315
+ Test to see if any of the errors or children have the given error message.
316
+
317
+ #### Parameters
318
+
319
+ ##### error
320
+
321
+ `unknown`
322
+
323
+ The error to test.
324
+
325
+ ##### message
326
+
327
+ The message to check for.
328
+
329
+ `string` | `RegExp`
330
+
331
+ #### Returns
332
+
333
+ `error is BaseError`
334
+
335
+ True if the error has the name.
336
+
337
+ #### Inherited from
338
+
339
+ `BaseError.someErrorMessage`
340
+
341
+ ***
342
+
343
+ ### someErrorClass() {#someerrorclass}
344
+
345
+ > `static` **someErrorClass**(`error`, `cls`): `error is BaseError`
346
+
347
+ Test to see if any of the errors or children are from a specific class.
348
+
349
+ #### Parameters
350
+
351
+ ##### error
352
+
353
+ `unknown`
354
+
355
+ The error to test.
356
+
357
+ ##### cls
358
+
359
+ `string`
360
+
361
+ The class to check for.
362
+
363
+ #### Returns
364
+
365
+ `error is BaseError`
366
+
367
+ True if the error has the specific class.
368
+
369
+ #### Inherited from
370
+
371
+ `BaseError.someErrorClass`
372
+
373
+ ***
374
+
375
+ ### someErrorCode() {#someerrorcode}
376
+
377
+ > `static` **someErrorCode**(`error`, `code`): `error is BaseError`
378
+
379
+ Test to see if any of the errors or children have the given error code.
380
+
381
+ #### Parameters
382
+
383
+ ##### error
384
+
385
+ `unknown`
386
+
387
+ The error to test.
388
+
389
+ ##### code
390
+
391
+ The code to check for.
392
+
393
+ `string` | `RegExp`
394
+
395
+ #### Returns
396
+
397
+ `error is BaseError`
398
+
399
+ True if the error has the name.
400
+
401
+ #### Inherited from
402
+
403
+ `BaseError.someErrorCode`
404
+
405
+ ***
406
+
407
+ ### isEmpty() {#isempty}
408
+
409
+ > `static` **isEmpty**(`err`): `boolean`
410
+
411
+ Is the error empty, i.e. does it have no message, source, properties, or cause?
412
+
413
+ #### Parameters
414
+
415
+ ##### err
416
+
417
+ `IError`
418
+
419
+ The error to check for being empty.
420
+
421
+ #### Returns
422
+
423
+ `boolean`
424
+
425
+ True if the error is empty.
426
+
427
+ #### Inherited from
428
+
429
+ `BaseError.isEmpty`
430
+
431
+ ***
432
+
433
+ ### isAggregateError() {#isaggregateerror}
434
+
435
+ > `static` **isAggregateError**(`err`): `err is AggregateError`
436
+
437
+ Is the error an aggregate error.
438
+
439
+ #### Parameters
440
+
441
+ ##### err
442
+
443
+ `unknown`
444
+
445
+ The error to check for being an aggregate error.
446
+
447
+ #### Returns
448
+
449
+ `err is AggregateError`
450
+
451
+ True if the error is an aggregate error.
452
+
453
+ #### Inherited from
454
+
455
+ `BaseError.isAggregateError`
456
+
457
+ ***
458
+
459
+ ### fromAggregate() {#fromaggregate}
460
+
461
+ > `static` **fromAggregate**(`err`, `includeStackTrace?`): `IError`[]
462
+
463
+ Convert the aggregate error to an array of errors.
464
+
465
+ #### Parameters
466
+
467
+ ##### err
468
+
469
+ `unknown`
470
+
471
+ The error to convert.
472
+
473
+ ##### includeStackTrace?
474
+
475
+ `boolean`
476
+
477
+ Whether to include the error stack in the model, defaults to false.
478
+
479
+ #### Returns
480
+
481
+ `IError`[]
482
+
483
+ The array of errors.
484
+
485
+ #### Inherited from
486
+
487
+ `BaseError.fromAggregate`
488
+
489
+ ***
490
+
491
+ ### toJsonObject() {#tojsonobject}
492
+
493
+ > **toJsonObject**(`includeStackTrace?`): `IError`
494
+
495
+ Serialize the error to the error model.
496
+
497
+ #### Parameters
498
+
499
+ ##### includeStackTrace?
500
+
501
+ `boolean`
502
+
503
+ Whether to include the error stack in the model, defaults to false.
504
+
505
+ #### Returns
506
+
507
+ `IError`
508
+
509
+ The error model.
510
+
511
+ #### Inherited from
512
+
513
+ `BaseError.toJsonObject`
@@ -14,7 +14,7 @@ Class to helper with fetch operations.
14
14
 
15
15
  ## Properties
16
16
 
17
- ### CLASS\_NAME
17
+ ### CLASS\_NAME {#class_name}
18
18
 
19
19
  > `readonly` `static` **CLASS\_NAME**: `string`
20
20
 
@@ -22,7 +22,7 @@ Runtime name for the class.
22
22
 
23
23
  ## Methods
24
24
 
25
- ### fetch()
25
+ ### fetch() {#fetch}
26
26
 
27
27
  > `static` **fetch**(`source`, `url`, `method`, `body?`, `options?`): `Promise`\<`Response`\>
28
28
 
@@ -68,7 +68,7 @@ The response.
68
68
 
69
69
  ***
70
70
 
71
- ### fetchJson()
71
+ ### fetchJson() {#fetchjson}
72
72
 
73
73
  > `static` **fetchJson**\<`T`, `U`\>(`source`, `url`, `method`, `requestData?`, `options?`): `Promise`\<`U`\>
74
74
 
@@ -124,7 +124,7 @@ The response.
124
124
 
125
125
  ***
126
126
 
127
- ### fetchBinary()
127
+ ### fetchBinary() {#fetchbinary}
128
128
 
129
129
  > `static` **fetchBinary**\<`T`\>(`source`, `url`, `method`, `requestData?`, `options?`): `Promise`\<`Uint8Array`\<`ArrayBufferLike`\> \| `T`\>
130
130
 
@@ -176,7 +176,7 @@ The response.
176
176
 
177
177
  ***
178
178
 
179
- ### clearCache()
179
+ ### clearCache() {#clearcache}
180
180
 
181
181
  > `static` **clearCache**(): `void`
182
182
 
@@ -188,7 +188,7 @@ Clears the cache.
188
188
 
189
189
  ***
190
190
 
191
- ### getCacheEntry()
191
+ ### getCacheEntry() {#getcacheentry}
192
192
 
193
193
  > `static` **getCacheEntry**\<`T`\>(`url`): `Promise`\<`T` \| `undefined`\>
194
194
 
@@ -216,7 +216,7 @@ The cache entry if it exists.
216
216
 
217
217
  ***
218
218
 
219
- ### setCacheEntry()
219
+ ### setCacheEntry() {#setcacheentry}
220
220
 
221
221
  > `static` **setCacheEntry**\<`T`\>(`url`, `value`): `Promise`\<`void`\>
222
222
 
@@ -250,7 +250,7 @@ The cache entry if it exists.
250
250
 
251
251
  ***
252
252
 
253
- ### removeCacheEntry()
253
+ ### removeCacheEntry() {#removecacheentry}
254
254
 
255
255
  > `static` **removeCacheEntry**(`url`): `void`
256
256