@twin.org/api-processors 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.
@@ -0,0 +1,95 @@
1
+ # Class: NodeIdentityProcessor
2
+
3
+ Adds a node identity to the request identity.
4
+
5
+ ## Implements
6
+
7
+ - `IHttpRestRouteProcessor`
8
+
9
+ ## Constructors
10
+
11
+ ### new NodeIdentityProcessor()
12
+
13
+ > **new NodeIdentityProcessor**(): [`NodeIdentityProcessor`](NodeIdentityProcessor.md)
14
+
15
+ #### Returns
16
+
17
+ [`NodeIdentityProcessor`](NodeIdentityProcessor.md)
18
+
19
+ ## Properties
20
+
21
+ ### CLASS\_NAME
22
+
23
+ > `readonly` **CLASS\_NAME**: `string`
24
+
25
+ Runtime name for the class.
26
+
27
+ #### Implementation of
28
+
29
+ `IHttpRestRouteProcessor.CLASS_NAME`
30
+
31
+ ## Methods
32
+
33
+ ### start()
34
+
35
+ > **start**(`nodeIdentity`, `nodeLoggingConnectorType`?): `Promise`\<`void`\>
36
+
37
+ The service needs to be started when the application is initialized.
38
+
39
+ #### Parameters
40
+
41
+ • **nodeIdentity**: `string`
42
+
43
+ The identity of the node.
44
+
45
+ • **nodeLoggingConnectorType?**: `string`
46
+
47
+ The node logging connector type, defaults to "node-logging".
48
+
49
+ #### Returns
50
+
51
+ `Promise`\<`void`\>
52
+
53
+ Nothing.
54
+
55
+ #### Implementation of
56
+
57
+ `IHttpRestRouteProcessor.start`
58
+
59
+ ***
60
+
61
+ ### pre()
62
+
63
+ > **pre**(`request`, `response`, `route`, `requestIdentity`, `processorState`): `Promise`\<`void`\>
64
+
65
+ Pre process the REST request for the specified route.
66
+
67
+ #### Parameters
68
+
69
+ • **request**: `IHttpServerRequest`\<`any`\>
70
+
71
+ The incoming request.
72
+
73
+ • **response**: `IHttpResponse`\<`any`\>
74
+
75
+ The outgoing response.
76
+
77
+ • **route**: `undefined` \| `IRestRoute`\<`any`, `any`\>
78
+
79
+ The route to process.
80
+
81
+ • **requestIdentity**: `IHttpRequestIdentity`
82
+
83
+ The identity context for the request.
84
+
85
+ • **processorState**
86
+
87
+ The state handed through the processors.
88
+
89
+ #### Returns
90
+
91
+ `Promise`\<`void`\>
92
+
93
+ #### Implementation of
94
+
95
+ `IHttpRestRouteProcessor.pre`
@@ -0,0 +1,81 @@
1
+ # Class: RouteProcessor
2
+
3
+ Process the REST request and hands it on to the route handler.
4
+
5
+ ## Implements
6
+
7
+ - `IHttpRestRouteProcessor`
8
+
9
+ ## Constructors
10
+
11
+ ### new RouteProcessor()
12
+
13
+ > **new RouteProcessor**(`options`?): [`RouteProcessor`](RouteProcessor.md)
14
+
15
+ Create a new instance of RouteProcessor.
16
+
17
+ #### Parameters
18
+
19
+ • **options?**
20
+
21
+ Options for the processor.
22
+
23
+ • **options.config?**: [`IRouteProcessorConfig`](../interfaces/IRouteProcessorConfig.md)
24
+
25
+ The configuration for the processor.
26
+
27
+ #### Returns
28
+
29
+ [`RouteProcessor`](RouteProcessor.md)
30
+
31
+ Promise that resolves when the processor is initialized.
32
+
33
+ ## Properties
34
+
35
+ ### CLASS\_NAME
36
+
37
+ > `readonly` **CLASS\_NAME**: `string`
38
+
39
+ Runtime name for the class.
40
+
41
+ #### Implementation of
42
+
43
+ `IHttpRestRouteProcessor.CLASS_NAME`
44
+
45
+ ## Methods
46
+
47
+ ### process()
48
+
49
+ > **process**(`request`, `response`, `route`, `requestIdentity`, `processorState`): `Promise`\<`void`\>
50
+
51
+ Process the REST request for the specified route.
52
+
53
+ #### Parameters
54
+
55
+ • **request**: `IHttpServerRequest`\<`any`\>
56
+
57
+ The incoming request.
58
+
59
+ • **response**: `IHttpResponse`\<`any`\>
60
+
61
+ The outgoing response.
62
+
63
+ • **route**: `undefined` \| `IRestRoute`\<`any`, `any`\>
64
+
65
+ The route to process.
66
+
67
+ • **requestIdentity**: `IHttpRequestIdentity`
68
+
69
+ The identity context for the request.
70
+
71
+ • **processorState**
72
+
73
+ The state handed through the processors.
74
+
75
+ #### Returns
76
+
77
+ `Promise`\<`void`\>
78
+
79
+ #### Implementation of
80
+
81
+ `IHttpRestRouteProcessor.process`
@@ -0,0 +1,81 @@
1
+ # Class: StaticUserIdentityProcessor
2
+
3
+ Adds a static user identity to the request context.
4
+
5
+ ## Implements
6
+
7
+ - `IHttpRestRouteProcessor`
8
+
9
+ ## Constructors
10
+
11
+ ### new StaticUserIdentityProcessor()
12
+
13
+ > **new StaticUserIdentityProcessor**(`options`): [`StaticUserIdentityProcessor`](StaticUserIdentityProcessor.md)
14
+
15
+ Create a new instance of StaticIdentityProcessor.
16
+
17
+ #### Parameters
18
+
19
+ • **options**
20
+
21
+ Options for the processor.
22
+
23
+ • **options.config**: [`IStaticUserIdentityProcessorConfig`](../interfaces/IStaticUserIdentityProcessorConfig.md)
24
+
25
+ The configuration for the processor.
26
+
27
+ #### Returns
28
+
29
+ [`StaticUserIdentityProcessor`](StaticUserIdentityProcessor.md)
30
+
31
+ Promise that resolves when the processor is initialized.
32
+
33
+ ## Properties
34
+
35
+ ### CLASS\_NAME
36
+
37
+ > `readonly` **CLASS\_NAME**: `string`
38
+
39
+ Runtime name for the class.
40
+
41
+ #### Implementation of
42
+
43
+ `IHttpRestRouteProcessor.CLASS_NAME`
44
+
45
+ ## Methods
46
+
47
+ ### pre()
48
+
49
+ > **pre**(`request`, `response`, `route`, `requestIdentity`, `processorState`): `Promise`\<`void`\>
50
+
51
+ Pre process the REST request for the specified route.
52
+
53
+ #### Parameters
54
+
55
+ • **request**: `IHttpServerRequest`\<`any`\>
56
+
57
+ The incoming request.
58
+
59
+ • **response**: `IHttpResponse`\<`any`\>
60
+
61
+ The outgoing response.
62
+
63
+ • **route**: `undefined` \| `IRestRoute`\<`any`, `any`\>
64
+
65
+ The route to process.
66
+
67
+ • **requestIdentity**: `IHttpRequestIdentity`
68
+
69
+ The identity context for the request.
70
+
71
+ • **processorState**
72
+
73
+ The state handed through the processors.
74
+
75
+ #### Returns
76
+
77
+ `Promise`\<`void`\>
78
+
79
+ #### Implementation of
80
+
81
+ `IHttpRestRouteProcessor.pre`
@@ -0,0 +1,15 @@
1
+ # @twin.org/api-processors
2
+
3
+ ## Classes
4
+
5
+ - [RouteProcessor](classes/RouteProcessor.md)
6
+ - [NodeIdentityProcessor](classes/NodeIdentityProcessor.md)
7
+ - [StaticUserIdentityProcessor](classes/StaticUserIdentityProcessor.md)
8
+ - [LoggingProcessor](classes/LoggingProcessor.md)
9
+
10
+ ## Interfaces
11
+
12
+ - [IRequestLoggingProcessorConfig](interfaces/IRequestLoggingProcessorConfig.md)
13
+ - [IResponseLoggingProcessorConfig](interfaces/IResponseLoggingProcessorConfig.md)
14
+ - [IRouteProcessorConfig](interfaces/IRouteProcessorConfig.md)
15
+ - [IStaticUserIdentityProcessorConfig](interfaces/IStaticUserIdentityProcessorConfig.md)
@@ -0,0 +1,11 @@
1
+ # Interface: IRequestLoggingProcessorConfig
2
+
3
+ Configuration for the request logging processor.
4
+
5
+ ## Properties
6
+
7
+ ### includeBody?
8
+
9
+ > `optional` **includeBody**: `boolean`
10
+
11
+ Include the body objects when logging the information.
@@ -0,0 +1,11 @@
1
+ # Interface: IResponseLoggingProcessorConfig
2
+
3
+ Configuration for the response logging processor.
4
+
5
+ ## Properties
6
+
7
+ ### includeBody?
8
+
9
+ > `optional` **includeBody**: `boolean`
10
+
11
+ Include the body objects when logging the information.
@@ -0,0 +1,11 @@
1
+ # Interface: IRouteProcessorConfig
2
+
3
+ Configuration for the route processor.
4
+
5
+ ## Properties
6
+
7
+ ### includeErrorStack?
8
+
9
+ > `optional` **includeErrorStack**: `boolean`
10
+
11
+ Include the stack with errors.
@@ -0,0 +1,11 @@
1
+ # Interface: IStaticUserIdentityProcessorConfig
2
+
3
+ Configuration for the static identity processor.
4
+
5
+ ## Properties
6
+
7
+ ### userIdentity
8
+
9
+ > **userIdentity**: `string`
10
+
11
+ The fixed user identity for request context.
@@ -0,0 +1,12 @@
1
+ {
2
+ "error": {
3
+ "routeProcessor": {
4
+ "routeNotFound": "The web server could not find the route \"{notFoundId}\""
5
+ },
6
+ "jwtIdentityProcessor": {
7
+ "jwtMissing": "The JSON Web token could not be found in the authorization header or a cookie",
8
+ "jwtSignatureInvalid": "The JSON Web token signature could not be validated",
9
+ "jwtExpired": "The JSON Web token has expired"
10
+ }
11
+ }
12
+ }
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@twin.org/api-processors",
3
+ "version": "0.0.1-next.2",
4
+ "description": "Route processors for use with API servers",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/twinfoundation/api.git",
8
+ "directory": "packages/api-processors"
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-models": "0.0.1-next.2",
31
+ "@twin.org/core": "next",
32
+ "@twin.org/entity": "next",
33
+ "@twin.org/entity-storage-models": "next",
34
+ "@twin.org/logging-models": "next",
35
+ "@twin.org/nameof": "next",
36
+ "@twin.org/web": "next"
37
+ },
38
+ "devDependencies": {
39
+ "@twin.org/nameof-transformer": "next",
40
+ "@vitest/coverage-v8": "2.1.1",
41
+ "@types/node": "22.5.5",
42
+ "copyfiles": "2.4.1",
43
+ "rimraf": "6.0.1",
44
+ "rollup": "4.21.3",
45
+ "rollup-plugin-typescript2": "0.36.0",
46
+ "ts-patch": "3.2.1",
47
+ "typedoc": "0.26.7",
48
+ "typedoc-plugin-markdown": "4.2.7",
49
+ "typescript": "5.6.2",
50
+ "vitest": "2.1.1"
51
+ },
52
+ "main": "./dist/cjs/index.cjs",
53
+ "module": "./dist/esm/index.mjs",
54
+ "types": "./dist/types/index.d.ts",
55
+ "exports": {
56
+ ".": {
57
+ "require": "./dist/cjs/index.cjs",
58
+ "import": "./dist/esm/index.mjs",
59
+ "types": "./dist/types/index.d.ts"
60
+ }
61
+ },
62
+ "files": [
63
+ "dist/cjs",
64
+ "dist/esm",
65
+ "dist/types",
66
+ "locales",
67
+ "docs"
68
+ ]
69
+ }