@twin.org/api-processors 0.0.1-next.10 → 0.0.1-next.12
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/dist/cjs/index.cjs +53 -31
- package/dist/esm/index.mjs +54 -33
- package/dist/types/index.d.ts +2 -1
- package/dist/types/mimeType/jwtMimeTypeProcessor.d.ts +17 -0
- package/docs/changelog.md +1 -1
- package/docs/reference/classes/JwtMimeTypeProcessor.md +59 -0
- package/docs/reference/index.md +1 -0
- package/package.json +2 -2
package/dist/cjs/index.cjs
CHANGED
|
@@ -113,29 +113,27 @@ class RouteProcessor {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
|
-
* Adds a
|
|
116
|
+
* Adds a node identity to the request identity.
|
|
117
117
|
*/
|
|
118
|
-
class
|
|
118
|
+
class NodeIdentityProcessor {
|
|
119
119
|
/**
|
|
120
120
|
* Runtime name for the class.
|
|
121
121
|
*/
|
|
122
|
-
CLASS_NAME = "
|
|
122
|
+
CLASS_NAME = "NodeIdentityProcessor";
|
|
123
123
|
/**
|
|
124
|
-
* The
|
|
124
|
+
* The node identity for request context.
|
|
125
125
|
* @internal
|
|
126
126
|
*/
|
|
127
|
-
|
|
127
|
+
_nodeIdentity;
|
|
128
128
|
/**
|
|
129
|
-
*
|
|
130
|
-
* @param
|
|
131
|
-
* @param
|
|
132
|
-
* @returns
|
|
129
|
+
* The service needs to be started when the application is initialized.
|
|
130
|
+
* @param nodeIdentity The identity of the node.
|
|
131
|
+
* @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
|
|
132
|
+
* @returns Nothing.
|
|
133
133
|
*/
|
|
134
|
-
|
|
135
|
-
core.Guards.
|
|
136
|
-
|
|
137
|
-
core.Guards.stringValue(this.CLASS_NAME, "options.config.userIdentity", options.config.userIdentity);
|
|
138
|
-
this._userIdentity = options.config.userIdentity;
|
|
134
|
+
async start(nodeIdentity, nodeLoggingConnectorType) {
|
|
135
|
+
core.Guards.string(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
|
|
136
|
+
this._nodeIdentity = nodeIdentity;
|
|
139
137
|
}
|
|
140
138
|
/**
|
|
141
139
|
* Pre process the REST request for the specified route.
|
|
@@ -146,34 +144,34 @@ class StaticUserIdentityProcessor {
|
|
|
146
144
|
* @param processorState The state handed through the processors.
|
|
147
145
|
*/
|
|
148
146
|
async pre(request, response, route, requestIdentity, processorState) {
|
|
149
|
-
|
|
150
|
-
requestIdentity.userIdentity = this._userIdentity;
|
|
151
|
-
}
|
|
147
|
+
requestIdentity.nodeIdentity = this._nodeIdentity;
|
|
152
148
|
}
|
|
153
149
|
}
|
|
154
150
|
|
|
155
151
|
/**
|
|
156
|
-
* Adds a
|
|
152
|
+
* Adds a static user identity to the request context.
|
|
157
153
|
*/
|
|
158
|
-
class
|
|
154
|
+
class StaticUserIdentityProcessor {
|
|
159
155
|
/**
|
|
160
156
|
* Runtime name for the class.
|
|
161
157
|
*/
|
|
162
|
-
CLASS_NAME = "
|
|
158
|
+
CLASS_NAME = "StaticUserIdentityProcessor";
|
|
163
159
|
/**
|
|
164
|
-
* The
|
|
160
|
+
* The fixed identity for request context.
|
|
165
161
|
* @internal
|
|
166
162
|
*/
|
|
167
|
-
|
|
163
|
+
_userIdentity;
|
|
168
164
|
/**
|
|
169
|
-
*
|
|
170
|
-
* @param
|
|
171
|
-
* @param
|
|
172
|
-
* @returns
|
|
165
|
+
* Create a new instance of StaticIdentityProcessor.
|
|
166
|
+
* @param options Options for the processor.
|
|
167
|
+
* @param options.config The configuration for the processor.
|
|
168
|
+
* @returns Promise that resolves when the processor is initialized.
|
|
173
169
|
*/
|
|
174
|
-
|
|
175
|
-
core.Guards.
|
|
176
|
-
this.
|
|
170
|
+
constructor(options) {
|
|
171
|
+
core.Guards.object(this.CLASS_NAME, "options", options);
|
|
172
|
+
core.Guards.object(this.CLASS_NAME, "options.config", options.config);
|
|
173
|
+
core.Guards.stringValue(this.CLASS_NAME, "options.config.userIdentity", options.config.userIdentity);
|
|
174
|
+
this._userIdentity = options.config.userIdentity;
|
|
177
175
|
}
|
|
178
176
|
/**
|
|
179
177
|
* Pre process the REST request for the specified route.
|
|
@@ -184,7 +182,9 @@ class NodeIdentityProcessor {
|
|
|
184
182
|
* @param processorState The state handed through the processors.
|
|
185
183
|
*/
|
|
186
184
|
async pre(request, response, route, requestIdentity, processorState) {
|
|
187
|
-
|
|
185
|
+
if (!core.Is.empty(route) && !(route.skipAuth ?? false)) {
|
|
186
|
+
requestIdentity.userIdentity = this._userIdentity;
|
|
187
|
+
}
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
|
|
@@ -321,7 +321,7 @@ class LoggingProcessor {
|
|
|
321
321
|
propValue[key] = this.processJson(key, propValue[key]);
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
|
-
else if (core.Is.stringBase64(propValue) &&
|
|
324
|
+
else if (!this._fullBase64 && core.Is.stringBase64(propValue) && propValue.length > 256) {
|
|
325
325
|
propValue = "<base64>";
|
|
326
326
|
}
|
|
327
327
|
else if (core.Is.string(propValue) &&
|
|
@@ -332,6 +332,28 @@ class LoggingProcessor {
|
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Process the REST request and log its information.
|
|
337
|
+
*/
|
|
338
|
+
class JwtMimeTypeProcessor {
|
|
339
|
+
/**
|
|
340
|
+
* Get the MIME types that this handler can handle.
|
|
341
|
+
* @returns The MIME types that this handler can handle.
|
|
342
|
+
*/
|
|
343
|
+
getTypes() {
|
|
344
|
+
return [web.MimeTypes.Jwt];
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Handle content.
|
|
348
|
+
* @param body The body to process.
|
|
349
|
+
* @returns The processed body.
|
|
350
|
+
*/
|
|
351
|
+
async handle(body) {
|
|
352
|
+
return core.Converter.bytesToUtf8(body);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
exports.JwtMimeTypeProcessor = JwtMimeTypeProcessor;
|
|
335
357
|
exports.LoggingProcessor = LoggingProcessor;
|
|
336
358
|
exports.NodeIdentityProcessor = NodeIdentityProcessor;
|
|
337
359
|
exports.RouteProcessor = RouteProcessor;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HttpErrorHelper } from '@twin.org/api-models';
|
|
2
|
-
import { Is, NotFoundError, Guards, ObjectHelper, Coerce } from '@twin.org/core';
|
|
2
|
+
import { Is, NotFoundError, Guards, ObjectHelper, Coerce, Converter } from '@twin.org/core';
|
|
3
3
|
import { HttpStatusCode, HeaderTypes, MimeTypes } from '@twin.org/web';
|
|
4
4
|
import { LoggingConnectorFactory } from '@twin.org/logging-models';
|
|
5
5
|
|
|
@@ -111,29 +111,27 @@ class RouteProcessor {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/**
|
|
114
|
-
* Adds a
|
|
114
|
+
* Adds a node identity to the request identity.
|
|
115
115
|
*/
|
|
116
|
-
class
|
|
116
|
+
class NodeIdentityProcessor {
|
|
117
117
|
/**
|
|
118
118
|
* Runtime name for the class.
|
|
119
119
|
*/
|
|
120
|
-
CLASS_NAME = "
|
|
120
|
+
CLASS_NAME = "NodeIdentityProcessor";
|
|
121
121
|
/**
|
|
122
|
-
* The
|
|
122
|
+
* The node identity for request context.
|
|
123
123
|
* @internal
|
|
124
124
|
*/
|
|
125
|
-
|
|
125
|
+
_nodeIdentity;
|
|
126
126
|
/**
|
|
127
|
-
*
|
|
128
|
-
* @param
|
|
129
|
-
* @param
|
|
130
|
-
* @returns
|
|
127
|
+
* The service needs to be started when the application is initialized.
|
|
128
|
+
* @param nodeIdentity The identity of the node.
|
|
129
|
+
* @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
|
|
130
|
+
* @returns Nothing.
|
|
131
131
|
*/
|
|
132
|
-
|
|
133
|
-
Guards.
|
|
134
|
-
|
|
135
|
-
Guards.stringValue(this.CLASS_NAME, "options.config.userIdentity", options.config.userIdentity);
|
|
136
|
-
this._userIdentity = options.config.userIdentity;
|
|
132
|
+
async start(nodeIdentity, nodeLoggingConnectorType) {
|
|
133
|
+
Guards.string(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
|
|
134
|
+
this._nodeIdentity = nodeIdentity;
|
|
137
135
|
}
|
|
138
136
|
/**
|
|
139
137
|
* Pre process the REST request for the specified route.
|
|
@@ -144,34 +142,34 @@ class StaticUserIdentityProcessor {
|
|
|
144
142
|
* @param processorState The state handed through the processors.
|
|
145
143
|
*/
|
|
146
144
|
async pre(request, response, route, requestIdentity, processorState) {
|
|
147
|
-
|
|
148
|
-
requestIdentity.userIdentity = this._userIdentity;
|
|
149
|
-
}
|
|
145
|
+
requestIdentity.nodeIdentity = this._nodeIdentity;
|
|
150
146
|
}
|
|
151
147
|
}
|
|
152
148
|
|
|
153
149
|
/**
|
|
154
|
-
* Adds a
|
|
150
|
+
* Adds a static user identity to the request context.
|
|
155
151
|
*/
|
|
156
|
-
class
|
|
152
|
+
class StaticUserIdentityProcessor {
|
|
157
153
|
/**
|
|
158
154
|
* Runtime name for the class.
|
|
159
155
|
*/
|
|
160
|
-
CLASS_NAME = "
|
|
156
|
+
CLASS_NAME = "StaticUserIdentityProcessor";
|
|
161
157
|
/**
|
|
162
|
-
* The
|
|
158
|
+
* The fixed identity for request context.
|
|
163
159
|
* @internal
|
|
164
160
|
*/
|
|
165
|
-
|
|
161
|
+
_userIdentity;
|
|
166
162
|
/**
|
|
167
|
-
*
|
|
168
|
-
* @param
|
|
169
|
-
* @param
|
|
170
|
-
* @returns
|
|
163
|
+
* Create a new instance of StaticIdentityProcessor.
|
|
164
|
+
* @param options Options for the processor.
|
|
165
|
+
* @param options.config The configuration for the processor.
|
|
166
|
+
* @returns Promise that resolves when the processor is initialized.
|
|
171
167
|
*/
|
|
172
|
-
|
|
173
|
-
Guards.
|
|
174
|
-
this.
|
|
168
|
+
constructor(options) {
|
|
169
|
+
Guards.object(this.CLASS_NAME, "options", options);
|
|
170
|
+
Guards.object(this.CLASS_NAME, "options.config", options.config);
|
|
171
|
+
Guards.stringValue(this.CLASS_NAME, "options.config.userIdentity", options.config.userIdentity);
|
|
172
|
+
this._userIdentity = options.config.userIdentity;
|
|
175
173
|
}
|
|
176
174
|
/**
|
|
177
175
|
* Pre process the REST request for the specified route.
|
|
@@ -182,7 +180,9 @@ class NodeIdentityProcessor {
|
|
|
182
180
|
* @param processorState The state handed through the processors.
|
|
183
181
|
*/
|
|
184
182
|
async pre(request, response, route, requestIdentity, processorState) {
|
|
185
|
-
|
|
183
|
+
if (!Is.empty(route) && !(route.skipAuth ?? false)) {
|
|
184
|
+
requestIdentity.userIdentity = this._userIdentity;
|
|
185
|
+
}
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
|
|
@@ -319,7 +319,7 @@ class LoggingProcessor {
|
|
|
319
319
|
propValue[key] = this.processJson(key, propValue[key]);
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
|
-
else if (Is.stringBase64(propValue) &&
|
|
322
|
+
else if (!this._fullBase64 && Is.stringBase64(propValue) && propValue.length > 256) {
|
|
323
323
|
propValue = "<base64>";
|
|
324
324
|
}
|
|
325
325
|
else if (Is.string(propValue) &&
|
|
@@ -330,4 +330,25 @@ class LoggingProcessor {
|
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
|
|
333
|
-
|
|
333
|
+
/**
|
|
334
|
+
* Process the REST request and log its information.
|
|
335
|
+
*/
|
|
336
|
+
class JwtMimeTypeProcessor {
|
|
337
|
+
/**
|
|
338
|
+
* Get the MIME types that this handler can handle.
|
|
339
|
+
* @returns The MIME types that this handler can handle.
|
|
340
|
+
*/
|
|
341
|
+
getTypes() {
|
|
342
|
+
return [MimeTypes.Jwt];
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Handle content.
|
|
346
|
+
* @param body The body to process.
|
|
347
|
+
* @returns The processed body.
|
|
348
|
+
*/
|
|
349
|
+
async handle(body) {
|
|
350
|
+
return Converter.bytesToUtf8(body);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export { JwtMimeTypeProcessor, LoggingProcessor, NodeIdentityProcessor, RouteProcessor, StaticUserIdentityProcessor };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from "./data/routeProcessor";
|
|
2
|
-
export * from "./identity/staticUserIdentityProcessor";
|
|
3
2
|
export * from "./identity/nodeIdentityProcessor";
|
|
3
|
+
export * from "./identity/staticUserIdentityProcessor";
|
|
4
4
|
export * from "./logging/loggingProcessor";
|
|
5
|
+
export * from "./mimeType/jwtMimeTypeProcessor";
|
|
5
6
|
export * from "./models/IRequestLoggingProcessorConfig";
|
|
6
7
|
export * from "./models/IResponseLoggingProcessorConfig";
|
|
7
8
|
export * from "./models/IRouteProcessorConfig";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { IMimeTypeProcessor } from "@twin.org/api-models";
|
|
2
|
+
/**
|
|
3
|
+
* Process the REST request and log its information.
|
|
4
|
+
*/
|
|
5
|
+
export declare class JwtMimeTypeProcessor implements IMimeTypeProcessor {
|
|
6
|
+
/**
|
|
7
|
+
* Get the MIME types that this handler can handle.
|
|
8
|
+
* @returns The MIME types that this handler can handle.
|
|
9
|
+
*/
|
|
10
|
+
getTypes(): string[];
|
|
11
|
+
/**
|
|
12
|
+
* Handle content.
|
|
13
|
+
* @param body The body to process.
|
|
14
|
+
* @returns The processed body.
|
|
15
|
+
*/
|
|
16
|
+
handle(body: Uint8Array): Promise<unknown>;
|
|
17
|
+
}
|
package/docs/changelog.md
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Class: JwtMimeTypeProcessor
|
|
2
|
+
|
|
3
|
+
Process the REST request and log its information.
|
|
4
|
+
|
|
5
|
+
## Implements
|
|
6
|
+
|
|
7
|
+
- `IMimeTypeProcessor`
|
|
8
|
+
|
|
9
|
+
## Constructors
|
|
10
|
+
|
|
11
|
+
### new JwtMimeTypeProcessor()
|
|
12
|
+
|
|
13
|
+
> **new JwtMimeTypeProcessor**(): [`JwtMimeTypeProcessor`](JwtMimeTypeProcessor.md)
|
|
14
|
+
|
|
15
|
+
#### Returns
|
|
16
|
+
|
|
17
|
+
[`JwtMimeTypeProcessor`](JwtMimeTypeProcessor.md)
|
|
18
|
+
|
|
19
|
+
## Methods
|
|
20
|
+
|
|
21
|
+
### getTypes()
|
|
22
|
+
|
|
23
|
+
> **getTypes**(): `string`[]
|
|
24
|
+
|
|
25
|
+
Get the MIME types that this handler can handle.
|
|
26
|
+
|
|
27
|
+
#### Returns
|
|
28
|
+
|
|
29
|
+
`string`[]
|
|
30
|
+
|
|
31
|
+
The MIME types that this handler can handle.
|
|
32
|
+
|
|
33
|
+
#### Implementation of
|
|
34
|
+
|
|
35
|
+
`IMimeTypeProcessor.getTypes`
|
|
36
|
+
|
|
37
|
+
***
|
|
38
|
+
|
|
39
|
+
### handle()
|
|
40
|
+
|
|
41
|
+
> **handle**(`body`): `Promise`\<`unknown`\>
|
|
42
|
+
|
|
43
|
+
Handle content.
|
|
44
|
+
|
|
45
|
+
#### Parameters
|
|
46
|
+
|
|
47
|
+
• **body**: `Uint8Array`
|
|
48
|
+
|
|
49
|
+
The body to process.
|
|
50
|
+
|
|
51
|
+
#### Returns
|
|
52
|
+
|
|
53
|
+
`Promise`\<`unknown`\>
|
|
54
|
+
|
|
55
|
+
The processed body.
|
|
56
|
+
|
|
57
|
+
#### Implementation of
|
|
58
|
+
|
|
59
|
+
`IMimeTypeProcessor.handle`
|
package/docs/reference/index.md
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
- [NodeIdentityProcessor](classes/NodeIdentityProcessor.md)
|
|
7
7
|
- [StaticUserIdentityProcessor](classes/StaticUserIdentityProcessor.md)
|
|
8
8
|
- [LoggingProcessor](classes/LoggingProcessor.md)
|
|
9
|
+
- [JwtMimeTypeProcessor](classes/JwtMimeTypeProcessor.md)
|
|
9
10
|
|
|
10
11
|
## Interfaces
|
|
11
12
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/api-processors",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.12",
|
|
4
4
|
"description": "Route processors for use with API servers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/api-models": "0.0.1-next.
|
|
17
|
+
"@twin.org/api-models": "0.0.1-next.12",
|
|
18
18
|
"@twin.org/core": "next",
|
|
19
19
|
"@twin.org/entity": "next",
|
|
20
20
|
"@twin.org/entity-storage-models": "next",
|