@twin.org/api-auth-entity-storage-service 0.0.1-next.2

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 (34) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +21 -0
  3. package/dist/cjs/index.cjs +623 -0
  4. package/dist/esm/index.mjs +611 -0
  5. package/dist/types/entities/authenticationUser.d.ts +21 -0
  6. package/dist/types/index.d.ts +10 -0
  7. package/dist/types/models/IAuthHeaderProcessorConfig.d.ts +15 -0
  8. package/dist/types/models/IEntityStorageAuthenticationServiceConfig.d.ts +15 -0
  9. package/dist/types/processors/authHeaderProcessor.d.ts +50 -0
  10. package/dist/types/restEntryPoints.d.ts +2 -0
  11. package/dist/types/routes/entityStorageAuthenticationRoutes.d.ts +37 -0
  12. package/dist/types/schema.d.ts +4 -0
  13. package/dist/types/services/entityStorageAuthenticationService.d.ts +55 -0
  14. package/dist/types/utils/passwordHelper.d.ts +12 -0
  15. package/dist/types/utils/tokenHelper.d.ts +41 -0
  16. package/docs/changelog.md +5 -0
  17. package/docs/examples.md +1 -0
  18. package/docs/reference/classes/AuthHeaderProcessor.md +149 -0
  19. package/docs/reference/classes/AuthenticationUser.md +45 -0
  20. package/docs/reference/classes/EntityStorageAuthenticationService.md +169 -0
  21. package/docs/reference/classes/PasswordHelper.md +37 -0
  22. package/docs/reference/classes/TokenHelper.md +125 -0
  23. package/docs/reference/functions/authenticationLogin.md +25 -0
  24. package/docs/reference/functions/authenticationLogout.md +25 -0
  25. package/docs/reference/functions/authenticationRefreshToken.md +25 -0
  26. package/docs/reference/functions/generateRestRoutesAuthentication.md +21 -0
  27. package/docs/reference/functions/initSchema.md +9 -0
  28. package/docs/reference/index.md +27 -0
  29. package/docs/reference/interfaces/IAuthHeaderProcessorConfig.md +31 -0
  30. package/docs/reference/interfaces/IEntityStorageAuthenticationServiceConfig.md +31 -0
  31. package/docs/reference/variables/restEntryPoints.md +3 -0
  32. package/docs/reference/variables/tagsAuthentication.md +5 -0
  33. package/locales/en.json +18 -0
  34. package/package.json +73 -0
@@ -0,0 +1,125 @@
1
+ # Class: TokenHelper
2
+
3
+ Helper class for token operations.
4
+
5
+ ## Constructors
6
+
7
+ ### new TokenHelper()
8
+
9
+ > **new TokenHelper**(): [`TokenHelper`](TokenHelper.md)
10
+
11
+ #### Returns
12
+
13
+ [`TokenHelper`](TokenHelper.md)
14
+
15
+ ## Methods
16
+
17
+ ### createToken()
18
+
19
+ > `static` **createToken**(`vaultConnector`, `signingKeyName`, `subject`, `ttlMinutes`): `Promise`\<`object`\>
20
+
21
+ Create a new token.
22
+
23
+ #### Parameters
24
+
25
+ • **vaultConnector**: `IVaultConnector`
26
+
27
+ The vault connector.
28
+
29
+ • **signingKeyName**: `string`
30
+
31
+ The signing key name.
32
+
33
+ • **subject**: `string`
34
+
35
+ The subject for the token.
36
+
37
+ • **ttlMinutes**: `number`
38
+
39
+ The time to live for the token in minutes.
40
+
41
+ #### Returns
42
+
43
+ `Promise`\<`object`\>
44
+
45
+ The new token and its expiry date.
46
+
47
+ ##### token
48
+
49
+ > **token**: `string`
50
+
51
+ ##### expiry
52
+
53
+ > **expiry**: `number`
54
+
55
+ ***
56
+
57
+ ### verify()
58
+
59
+ > `static` **verify**(`vaultConnector`, `signingKeyName`, `token`): `Promise`\<`object`\>
60
+
61
+ Verify the token.
62
+
63
+ #### Parameters
64
+
65
+ • **vaultConnector**: `IVaultConnector`
66
+
67
+ The vault connector.
68
+
69
+ • **signingKeyName**: `string`
70
+
71
+ The signing key name.
72
+
73
+ • **token**: `undefined` \| `string`
74
+
75
+ The token to verify.
76
+
77
+ #### Returns
78
+
79
+ `Promise`\<`object`\>
80
+
81
+ The verified details.
82
+
83
+ ##### header
84
+
85
+ > **header**: `IJwtHeader`
86
+
87
+ ##### payload
88
+
89
+ > **payload**: `IJwtPayload`
90
+
91
+ #### Throws
92
+
93
+ UnauthorizedError if the token is missing, invalid or expired.
94
+
95
+ ***
96
+
97
+ ### extractTokenFromHeaders()
98
+
99
+ > `static` **extractTokenFromHeaders**(`headers`?, `cookieName`?): `object`
100
+
101
+ Extract the auth token from the headers, either from the authorization header or the cookie header.
102
+
103
+ #### Parameters
104
+
105
+ • **headers?**: `IHttpHeaders`
106
+
107
+ The headers to extract the token from.
108
+
109
+ • **cookieName?**: `string`
110
+
111
+ The name of the cookie to extract the token from.
112
+
113
+ #### Returns
114
+
115
+ `object`
116
+
117
+ The token if found.
118
+
119
+ ##### token
120
+
121
+ > **token**: `undefined` \| `string`
122
+
123
+ ##### location
124
+
125
+ > **location**: `undefined` \| `"authorization"` \| `"cookie"`
@@ -0,0 +1,25 @@
1
+ # Function: authenticationLogin()
2
+
3
+ > **authenticationLogin**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`ILoginResponse` & `IRestRouteResponseOptions`\>
4
+
5
+ Login to the server.
6
+
7
+ ## Parameters
8
+
9
+ • **httpRequestContext**: `IHttpRequestContext`
10
+
11
+ The request context for the API.
12
+
13
+ • **componentName**: `string`
14
+
15
+ The name of the component to use in the routes.
16
+
17
+ • **request**: `ILoginRequest`
18
+
19
+ The request.
20
+
21
+ ## Returns
22
+
23
+ `Promise`\<`ILoginResponse` & `IRestRouteResponseOptions`\>
24
+
25
+ The response object with additional http response properties.
@@ -0,0 +1,25 @@
1
+ # Function: authenticationLogout()
2
+
3
+ > **authenticationLogout**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`INoContentResponse` & `IRestRouteResponseOptions`\>
4
+
5
+ Logout from the server.
6
+
7
+ ## Parameters
8
+
9
+ • **httpRequestContext**: `IHttpRequestContext`
10
+
11
+ The request context for the API.
12
+
13
+ • **componentName**: `string`
14
+
15
+ The name of the component to use in the routes.
16
+
17
+ • **request**: `ILogoutRequest`
18
+
19
+ The request.
20
+
21
+ ## Returns
22
+
23
+ `Promise`\<`INoContentResponse` & `IRestRouteResponseOptions`\>
24
+
25
+ The response object with additional http response properties.
@@ -0,0 +1,25 @@
1
+ # Function: authenticationRefreshToken()
2
+
3
+ > **authenticationRefreshToken**(`httpRequestContext`, `componentName`, `request`): `Promise`\<`IRefreshTokenResponse` & `IRestRouteResponseOptions`\>
4
+
5
+ Refresh the login token.
6
+
7
+ ## Parameters
8
+
9
+ • **httpRequestContext**: `IHttpRequestContext`
10
+
11
+ The request context for the API.
12
+
13
+ • **componentName**: `string`
14
+
15
+ The name of the component to use in the routes.
16
+
17
+ • **request**: `IRefreshTokenRequest`
18
+
19
+ The request.
20
+
21
+ ## Returns
22
+
23
+ `Promise`\<`IRefreshTokenResponse` & `IRestRouteResponseOptions`\>
24
+
25
+ The response object with additional http response properties.
@@ -0,0 +1,21 @@
1
+ # Function: generateRestRoutesAuthentication()
2
+
3
+ > **generateRestRoutesAuthentication**(`baseRouteName`, `componentName`): `IRestRoute`[]
4
+
5
+ The REST routes for authentication.
6
+
7
+ ## Parameters
8
+
9
+ • **baseRouteName**: `string`
10
+
11
+ Prefix to prepend to the paths.
12
+
13
+ • **componentName**: `string`
14
+
15
+ The name of the component to use in the routes stored in the ComponentFactory.
16
+
17
+ ## Returns
18
+
19
+ `IRestRoute`[]
20
+
21
+ The generated routes.
@@ -0,0 +1,9 @@
1
+ # Function: initSchema()
2
+
3
+ > **initSchema**(): `void`
4
+
5
+ Initialize the schema for the authentication service.
6
+
7
+ ## Returns
8
+
9
+ `void`
@@ -0,0 +1,27 @@
1
+ # @twin.org/api-auth-entity-storage-service
2
+
3
+ ## Classes
4
+
5
+ - [AuthenticationUser](classes/AuthenticationUser.md)
6
+ - [AuthHeaderProcessor](classes/AuthHeaderProcessor.md)
7
+ - [EntityStorageAuthenticationService](classes/EntityStorageAuthenticationService.md)
8
+ - [PasswordHelper](classes/PasswordHelper.md)
9
+ - [TokenHelper](classes/TokenHelper.md)
10
+
11
+ ## Interfaces
12
+
13
+ - [IAuthHeaderProcessorConfig](interfaces/IAuthHeaderProcessorConfig.md)
14
+ - [IEntityStorageAuthenticationServiceConfig](interfaces/IEntityStorageAuthenticationServiceConfig.md)
15
+
16
+ ## Variables
17
+
18
+ - [restEntryPoints](variables/restEntryPoints.md)
19
+ - [tagsAuthentication](variables/tagsAuthentication.md)
20
+
21
+ ## Functions
22
+
23
+ - [generateRestRoutesAuthentication](functions/generateRestRoutesAuthentication.md)
24
+ - [authenticationLogin](functions/authenticationLogin.md)
25
+ - [authenticationLogout](functions/authenticationLogout.md)
26
+ - [authenticationRefreshToken](functions/authenticationRefreshToken.md)
27
+ - [initSchema](functions/initSchema.md)
@@ -0,0 +1,31 @@
1
+ # Interface: IAuthHeaderProcessorConfig
2
+
3
+ Configuration for the authentication header processor
4
+
5
+ ## Properties
6
+
7
+ ### signingKeyName?
8
+
9
+ > `optional` **signingKeyName**: `string`
10
+
11
+ The name of the key to retrieve from the vault for signing JWT.
12
+
13
+ #### Default
14
+
15
+ ```ts
16
+ auth-signing
17
+ ```
18
+
19
+ ***
20
+
21
+ ### cookieName?
22
+
23
+ > `optional` **cookieName**: `string`
24
+
25
+ The name of the cookie to use for the token.
26
+
27
+ #### Default
28
+
29
+ ```ts
30
+ access_token
31
+ ```
@@ -0,0 +1,31 @@
1
+ # Interface: IEntityStorageAuthenticationServiceConfig
2
+
3
+ Configuration for the entity storage authentication service.
4
+
5
+ ## Properties
6
+
7
+ ### signingKeyName?
8
+
9
+ > `optional` **signingKeyName**: `string`
10
+
11
+ The name of the key to retrieve from the vault for signing JWT.
12
+
13
+ #### Default
14
+
15
+ ```ts
16
+ auth-signing
17
+ ```
18
+
19
+ ***
20
+
21
+ ### defaultTtlMinutes?
22
+
23
+ > `optional` **defaultTtlMinutes**: `number`
24
+
25
+ The default time to live for the JWT.
26
+
27
+ #### Default
28
+
29
+ ```ts
30
+ 1440
31
+ ```
@@ -0,0 +1,3 @@
1
+ # Variable: restEntryPoints
2
+
3
+ > `const` **restEntryPoints**: `IRestRouteEntryPoint`[]
@@ -0,0 +1,5 @@
1
+ # Variable: tagsAuthentication
2
+
3
+ > `const` **tagsAuthentication**: `ITag`[]
4
+
5
+ The tag to associate with the routes.
@@ -0,0 +1,18 @@
1
+ {
2
+ "error": {
3
+ "entityStorageAuthenticationService": {
4
+ "loginFailed": "Login failed",
5
+ "refreshFailed": "Refresh failed",
6
+ "userNotFound": "The user with the specified e-mail could not be found",
7
+ "passwordMismatch": "The password does not match the user's password"
8
+ },
9
+ "entityStorageAuthenticationProcessor": {
10
+ "initializeFailed": "The JSON Web token authentication processor could not be initialized"
11
+ },
12
+ "tokenHelper": {
13
+ "missing": "The JSON Web token could not be found in the authorization header",
14
+ "invalid": "The JSON Web token signature could not be validated",
15
+ "expired": "The JSON Web token has expired"
16
+ }
17
+ }
18
+ }
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@twin.org/api-auth-entity-storage-service",
3
+ "version": "0.0.1-next.2",
4
+ "description": "Auth Entity Storage contract implementation and REST endpoint definitions",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/twinfoundation/api.git",
8
+ "directory": "packages/api-auth-entity-storage-service"
9
+ },
10
+ "author": "martyn.janes@iota.org",
11
+ "license": "Apache-2.0",
12
+ "type": "module",
13
+ "engines": {
14
+ "node": ">=20.0.0"
15
+ },
16
+ "scripts": {
17
+ "clean": "rimraf dist coverage",
18
+ "build": "tspc",
19
+ "test": "vitest --run --config ./vitest.config.ts --no-cache",
20
+ "coverage": "vitest --run --coverage --config ./vitest.config.ts --no-cache",
21
+ "bundle:esm": "rollup --config rollup.config.mjs --environment MODULE:esm",
22
+ "bundle:cjs": "rollup --config rollup.config.mjs --environment MODULE:cjs",
23
+ "bundle": "npm run bundle:esm && npm run bundle:cjs",
24
+ "docs:clean": "rimraf docs/reference",
25
+ "docs:generate": "typedoc",
26
+ "docs": "npm run docs:clean && npm run docs:generate",
27
+ "dist": "npm run clean && npm run build && npm run test && npm run bundle && npm run docs"
28
+ },
29
+ "dependencies": {
30
+ "@twin.org/api-auth-entity-storage-models": "0.0.1-next.2",
31
+ "@twin.org/api-core": "0.0.1-next.2",
32
+ "@twin.org/api-models": "0.0.1-next.2",
33
+ "@twin.org/core": "next",
34
+ "@twin.org/crypto": "next",
35
+ "@twin.org/entity": "next",
36
+ "@twin.org/entity-storage-models": "next",
37
+ "@twin.org/logging-models": "next",
38
+ "@twin.org/nameof": "next",
39
+ "@twin.org/vault-models": "next",
40
+ "@twin.org/web": "next"
41
+ },
42
+ "devDependencies": {
43
+ "@twin.org/nameof-transformer": "next",
44
+ "@vitest/coverage-v8": "2.1.1",
45
+ "@types/node": "22.5.5",
46
+ "copyfiles": "2.4.1",
47
+ "rimraf": "6.0.1",
48
+ "rollup": "4.21.3",
49
+ "rollup-plugin-typescript2": "0.36.0",
50
+ "ts-patch": "3.2.1",
51
+ "typedoc": "0.26.7",
52
+ "typedoc-plugin-markdown": "4.2.7",
53
+ "typescript": "5.6.2",
54
+ "vitest": "2.1.1"
55
+ },
56
+ "main": "./dist/cjs/index.cjs",
57
+ "module": "./dist/esm/index.mjs",
58
+ "types": "./dist/types/index.d.ts",
59
+ "exports": {
60
+ ".": {
61
+ "require": "./dist/cjs/index.cjs",
62
+ "import": "./dist/esm/index.mjs",
63
+ "types": "./dist/types/index.d.ts"
64
+ }
65
+ },
66
+ "files": [
67
+ "dist/cjs",
68
+ "dist/esm",
69
+ "dist/types",
70
+ "locales",
71
+ "docs"
72
+ ]
73
+ }