@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.
@@ -113,29 +113,27 @@ class RouteProcessor {
113
113
  }
114
114
 
115
115
  /**
116
- * Adds a static user identity to the request context.
116
+ * Adds a node identity to the request identity.
117
117
  */
118
- class StaticUserIdentityProcessor {
118
+ class NodeIdentityProcessor {
119
119
  /**
120
120
  * Runtime name for the class.
121
121
  */
122
- CLASS_NAME = "StaticUserIdentityProcessor";
122
+ CLASS_NAME = "NodeIdentityProcessor";
123
123
  /**
124
- * The fixed identity for request context.
124
+ * The node identity for request context.
125
125
  * @internal
126
126
  */
127
- _userIdentity;
127
+ _nodeIdentity;
128
128
  /**
129
- * Create a new instance of StaticIdentityProcessor.
130
- * @param options Options for the processor.
131
- * @param options.config The configuration for the processor.
132
- * @returns Promise that resolves when the processor is initialized.
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
- constructor(options) {
135
- core.Guards.object(this.CLASS_NAME, "options", options);
136
- core.Guards.object(this.CLASS_NAME, "options.config", options.config);
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
- if (!core.Is.empty(route) && !(route.skipAuth ?? false)) {
150
- requestIdentity.userIdentity = this._userIdentity;
151
- }
147
+ requestIdentity.nodeIdentity = this._nodeIdentity;
152
148
  }
153
149
  }
154
150
 
155
151
  /**
156
- * Adds a node identity to the request identity.
152
+ * Adds a static user identity to the request context.
157
153
  */
158
- class NodeIdentityProcessor {
154
+ class StaticUserIdentityProcessor {
159
155
  /**
160
156
  * Runtime name for the class.
161
157
  */
162
- CLASS_NAME = "NodeIdentityProcessor";
158
+ CLASS_NAME = "StaticUserIdentityProcessor";
163
159
  /**
164
- * The node identity for request context.
160
+ * The fixed identity for request context.
165
161
  * @internal
166
162
  */
167
- _nodeIdentity;
163
+ _userIdentity;
168
164
  /**
169
- * The service needs to be started when the application is initialized.
170
- * @param nodeIdentity The identity of the node.
171
- * @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
172
- * @returns Nothing.
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
- async start(nodeIdentity, nodeLoggingConnectorType) {
175
- core.Guards.string(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
176
- this._nodeIdentity = nodeIdentity;
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
- requestIdentity.nodeIdentity = this._nodeIdentity;
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) && !this._fullBase64) {
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;
@@ -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 static user identity to the request context.
114
+ * Adds a node identity to the request identity.
115
115
  */
116
- class StaticUserIdentityProcessor {
116
+ class NodeIdentityProcessor {
117
117
  /**
118
118
  * Runtime name for the class.
119
119
  */
120
- CLASS_NAME = "StaticUserIdentityProcessor";
120
+ CLASS_NAME = "NodeIdentityProcessor";
121
121
  /**
122
- * The fixed identity for request context.
122
+ * The node identity for request context.
123
123
  * @internal
124
124
  */
125
- _userIdentity;
125
+ _nodeIdentity;
126
126
  /**
127
- * Create a new instance of StaticIdentityProcessor.
128
- * @param options Options for the processor.
129
- * @param options.config The configuration for the processor.
130
- * @returns Promise that resolves when the processor is initialized.
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
- constructor(options) {
133
- Guards.object(this.CLASS_NAME, "options", options);
134
- Guards.object(this.CLASS_NAME, "options.config", options.config);
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
- if (!Is.empty(route) && !(route.skipAuth ?? false)) {
148
- requestIdentity.userIdentity = this._userIdentity;
149
- }
145
+ requestIdentity.nodeIdentity = this._nodeIdentity;
150
146
  }
151
147
  }
152
148
 
153
149
  /**
154
- * Adds a node identity to the request identity.
150
+ * Adds a static user identity to the request context.
155
151
  */
156
- class NodeIdentityProcessor {
152
+ class StaticUserIdentityProcessor {
157
153
  /**
158
154
  * Runtime name for the class.
159
155
  */
160
- CLASS_NAME = "NodeIdentityProcessor";
156
+ CLASS_NAME = "StaticUserIdentityProcessor";
161
157
  /**
162
- * The node identity for request context.
158
+ * The fixed identity for request context.
163
159
  * @internal
164
160
  */
165
- _nodeIdentity;
161
+ _userIdentity;
166
162
  /**
167
- * The service needs to be started when the application is initialized.
168
- * @param nodeIdentity The identity of the node.
169
- * @param nodeLoggingConnectorType The node logging connector type, defaults to "node-logging".
170
- * @returns Nothing.
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
- async start(nodeIdentity, nodeLoggingConnectorType) {
173
- Guards.string(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
174
- this._nodeIdentity = nodeIdentity;
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
- requestIdentity.nodeIdentity = this._nodeIdentity;
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) && !this._fullBase64) {
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
- export { LoggingProcessor, NodeIdentityProcessor, RouteProcessor, StaticUserIdentityProcessor };
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 };
@@ -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
@@ -1,5 +1,5 @@
1
1
  # @twin.org/api-processors - Changelog
2
2
 
3
- ## v0.0.1-next.10
3
+ ## v0.0.1-next.12
4
4
 
5
5
  - Initial Release
@@ -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`
@@ -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.10",
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.10",
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",