@twin.org/web 0.0.2-next.12 → 0.0.2-next.14

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.
@@ -723,6 +723,39 @@ class FetchHelper {
723
723
  }
724
724
  }
725
725
 
726
+ // Copyright 2024 IOTA Stiftung.
727
+ // SPDX-License-Identifier: Apache-2.0.
728
+ /**
729
+ * Class to helper with header operations.
730
+ */
731
+ class HeaderHelper {
732
+ /**
733
+ * Create a bearer token header.
734
+ * @param token The token to create the header for.
735
+ * @returns The bearer token header.
736
+ */
737
+ static createBearer(token) {
738
+ if (core.Is.stringValue(token)) {
739
+ if (token.startsWith("Bearer ")) {
740
+ return token;
741
+ }
742
+ return `Bearer ${token.trim()}`;
743
+ }
744
+ return undefined;
745
+ }
746
+ /**
747
+ * Extract the bearer token from a header.
748
+ * @param header The header value to extract the token from.
749
+ * @returns The extracted token if it exists.
750
+ */
751
+ static extractBearerToken(header) {
752
+ if (core.Is.stringValue(header) && header.startsWith("Bearer ")) {
753
+ return header.slice(7, header.length).trim();
754
+ }
755
+ return undefined;
756
+ }
757
+ }
758
+
726
759
  // Copyright 2024 IOTA Stiftung.
727
760
  // SPDX-License-Identifier: Apache-2.0.
728
761
  /**
@@ -1261,6 +1294,7 @@ class MimeTypeHelper {
1261
1294
 
1262
1295
  exports.FetchError = FetchError;
1263
1296
  exports.FetchHelper = FetchHelper;
1297
+ exports.HeaderHelper = HeaderHelper;
1264
1298
  exports.HeaderTypes = HeaderTypes;
1265
1299
  exports.HttpMethod = HttpMethod;
1266
1300
  exports.HttpStatusCode = HttpStatusCode;
@@ -721,6 +721,39 @@ class FetchHelper {
721
721
  }
722
722
  }
723
723
 
724
+ // Copyright 2024 IOTA Stiftung.
725
+ // SPDX-License-Identifier: Apache-2.0.
726
+ /**
727
+ * Class to helper with header operations.
728
+ */
729
+ class HeaderHelper {
730
+ /**
731
+ * Create a bearer token header.
732
+ * @param token The token to create the header for.
733
+ * @returns The bearer token header.
734
+ */
735
+ static createBearer(token) {
736
+ if (Is.stringValue(token)) {
737
+ if (token.startsWith("Bearer ")) {
738
+ return token;
739
+ }
740
+ return `Bearer ${token.trim()}`;
741
+ }
742
+ return undefined;
743
+ }
744
+ /**
745
+ * Extract the bearer token from a header.
746
+ * @param header The header value to extract the token from.
747
+ * @returns The extracted token if it exists.
748
+ */
749
+ static extractBearerToken(header) {
750
+ if (Is.stringValue(header) && header.startsWith("Bearer ")) {
751
+ return header.slice(7, header.length).trim();
752
+ }
753
+ return undefined;
754
+ }
755
+ }
756
+
724
757
  // Copyright 2024 IOTA Stiftung.
725
758
  // SPDX-License-Identifier: Apache-2.0.
726
759
  /**
@@ -1257,4 +1290,4 @@ class MimeTypeHelper {
1257
1290
  }
1258
1291
  }
1259
1292
 
1260
- export { FetchError, FetchHelper, HeaderTypes, HttpMethod, HttpStatusCode, Jwk, Jws, Jwt, MimeTypeHelper, MimeTypes };
1293
+ export { FetchError, FetchHelper, HeaderHelper, HeaderTypes, HttpMethod, HttpStatusCode, Jwk, Jws, Jwt, MimeTypeHelper, MimeTypes };
@@ -10,6 +10,7 @@ export * from "./models/IJwtPayload";
10
10
  export * from "./models/jwkCryptoKey";
11
11
  export * from "./models/mimeTypes";
12
12
  export * from "./utils/fetchHelper";
13
+ export * from "./utils/headerHelper";
13
14
  export * from "./utils/jwk";
14
15
  export * from "./utils/jws";
15
16
  export * from "./utils/jwt";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Class to helper with header operations.
3
+ */
4
+ export declare class HeaderHelper {
5
+ /**
6
+ * Create a bearer token header.
7
+ * @param token The token to create the header for.
8
+ * @returns The bearer token header.
9
+ */
10
+ static createBearer(token: string): string | undefined;
11
+ /**
12
+ * Extract the bearer token from a header.
13
+ * @param header The header value to extract the token from.
14
+ * @returns The extracted token if it exists.
15
+ */
16
+ static extractBearerToken(header: unknown): string | undefined;
17
+ }
package/docs/changelog.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # @twin.org/web - Changelog
2
2
 
3
+ ## [0.0.2-next.14](https://github.com/twinfoundation/framework/compare/web-v0.0.2-next.13...web-v0.0.2-next.14) (2025-09-22)
4
+
5
+
6
+ ### Features
7
+
8
+ * add header helper for common bearer support ([0c940b2](https://github.com/twinfoundation/framework/commit/0c940b29cccf0c3bb5b4aa8a01f1998010e44d51))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/core bumped from 0.0.2-next.13 to 0.0.2-next.14
16
+ * @twin.org/crypto bumped from 0.0.2-next.13 to 0.0.2-next.14
17
+ * @twin.org/nameof bumped from 0.0.2-next.13 to 0.0.2-next.14
18
+ * devDependencies
19
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.13 to 0.0.2-next.14
20
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.13 to 0.0.2-next.14
21
+
22
+ ## [0.0.2-next.13](https://github.com/twinfoundation/framework/compare/web-v0.0.2-next.12...web-v0.0.2-next.13) (2025-09-22)
23
+
24
+
25
+ ### Miscellaneous Chores
26
+
27
+ * **web:** Synchronize repo versions
28
+
29
+
30
+ ### Dependencies
31
+
32
+ * The following workspace dependencies were updated
33
+ * dependencies
34
+ * @twin.org/core bumped from 0.0.2-next.12 to 0.0.2-next.13
35
+ * @twin.org/crypto bumped from 0.0.2-next.12 to 0.0.2-next.13
36
+ * @twin.org/nameof bumped from 0.0.2-next.12 to 0.0.2-next.13
37
+ * devDependencies
38
+ * @twin.org/nameof-transformer bumped from 0.0.2-next.12 to 0.0.2-next.13
39
+ * @twin.org/nameof-vitest-plugin bumped from 0.0.2-next.12 to 0.0.2-next.13
40
+
3
41
  ## [0.0.2-next.12](https://github.com/twinfoundation/framework/compare/web-v0.0.2-next.11...web-v0.0.2-next.12) (2025-09-15)
4
42
 
5
43
 
@@ -0,0 +1,57 @@
1
+ # Class: HeaderHelper
2
+
3
+ Class to helper with header operations.
4
+
5
+ ## Constructors
6
+
7
+ ### Constructor
8
+
9
+ > **new HeaderHelper**(): `HeaderHelper`
10
+
11
+ #### Returns
12
+
13
+ `HeaderHelper`
14
+
15
+ ## Methods
16
+
17
+ ### createBearer()
18
+
19
+ > `static` **createBearer**(`token`): `undefined` \| `string`
20
+
21
+ Create a bearer token header.
22
+
23
+ #### Parameters
24
+
25
+ ##### token
26
+
27
+ `string`
28
+
29
+ The token to create the header for.
30
+
31
+ #### Returns
32
+
33
+ `undefined` \| `string`
34
+
35
+ The bearer token header.
36
+
37
+ ***
38
+
39
+ ### extractBearerToken()
40
+
41
+ > `static` **extractBearerToken**(`header`): `undefined` \| `string`
42
+
43
+ Extract the bearer token from a header.
44
+
45
+ #### Parameters
46
+
47
+ ##### header
48
+
49
+ `unknown`
50
+
51
+ The header value to extract the token from.
52
+
53
+ #### Returns
54
+
55
+ `undefined` \| `string`
56
+
57
+ The extracted token if it exists.
@@ -4,6 +4,7 @@
4
4
 
5
5
  - [FetchError](classes/FetchError.md)
6
6
  - [FetchHelper](classes/FetchHelper.md)
7
+ - [HeaderHelper](classes/HeaderHelper.md)
7
8
  - [Jwk](classes/Jwk.md)
8
9
  - [Jws](classes/Jws.md)
9
10
  - [Jwt](classes/Jwt.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/web",
3
- "version": "0.0.2-next.12",
3
+ "version": "0.0.2-next.14",
4
4
  "description": "Contains classes for use with web operations",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,9 +14,9 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/core": "0.0.2-next.12",
18
- "@twin.org/crypto": "0.0.2-next.12",
19
- "@twin.org/nameof": "0.0.2-next.12",
17
+ "@twin.org/core": "0.0.2-next.14",
18
+ "@twin.org/crypto": "0.0.2-next.14",
19
+ "@twin.org/nameof": "0.0.2-next.14",
20
20
  "jose": "6.1.0"
21
21
  },
22
22
  "main": "./dist/cjs/index.cjs",