@twin.org/api-processors 0.0.1 → 0.0.2-next.10
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 +105 -45
- package/dist/esm/index.mjs +106 -47
- package/dist/types/data/restRouteProcessor.d.ts +2 -5
- package/dist/types/data/socketRouteProcessor.d.ts +20 -7
- package/dist/types/identity/nodeIdentityProcessor.d.ts +2 -6
- package/dist/types/identity/staticUserIdentityProcessor.d.ts +0 -4
- package/dist/types/index.d.ts +1 -0
- package/dist/types/logging/loggingProcessor.d.ts +0 -4
- package/dist/types/mimeType/jsonLdMimeTypeProcessor.d.ts +21 -0
- package/dist/types/mimeType/jwtMimeTypeProcessor.d.ts +0 -4
- package/dist/types/models/ILoggingProcessorConstructorOptions.d.ts +3 -4
- package/docs/changelog.md +148 -0
- package/docs/reference/classes/JsonLdMimeTypeProcessor.md +73 -0
- package/docs/reference/classes/JwtMimeTypeProcessor.md +0 -8
- package/docs/reference/classes/LoggingProcessor.md +0 -8
- package/docs/reference/classes/NodeIdentityProcessor.md +3 -11
- package/docs/reference/classes/RestRouteProcessor.md +7 -9
- package/docs/reference/classes/SocketRouteProcessor.md +84 -10
- package/docs/reference/classes/StaticUserIdentityProcessor.md +0 -8
- package/docs/reference/index.md +1 -0
- package/docs/reference/interfaces/ILoggingProcessorConstructorOptions.md +5 -9
- package/locales/en.json +3 -0
- package/package.json +6 -8
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
var apiModels = require('@twin.org/api-models');
|
|
4
4
|
var core = require('@twin.org/core');
|
|
5
5
|
var web = require('@twin.org/web');
|
|
6
|
-
var loggingModels = require('@twin.org/logging-models');
|
|
7
6
|
|
|
8
7
|
// Copyright 2024 IOTA Stiftung.
|
|
9
8
|
// SPDX-License-Identifier: Apache-2.0.
|
|
@@ -11,10 +10,6 @@ var loggingModels = require('@twin.org/logging-models');
|
|
|
11
10
|
* Process the REST request and hands it on to the route handler.
|
|
12
11
|
*/
|
|
13
12
|
class RestRouteProcessor {
|
|
14
|
-
/**
|
|
15
|
-
* The namespace supported by the processor.
|
|
16
|
-
*/
|
|
17
|
-
static NAMESPACE = "rest-route";
|
|
18
13
|
/**
|
|
19
14
|
* Runtime name for the class.
|
|
20
15
|
*/
|
|
@@ -38,8 +33,9 @@ class RestRouteProcessor {
|
|
|
38
33
|
* @param route The route to process.
|
|
39
34
|
* @param requestIdentity The identity context for the request.
|
|
40
35
|
* @param processorState The state handed through the processors.
|
|
36
|
+
* @param loggingComponentType The logging component type for the request.
|
|
41
37
|
*/
|
|
42
|
-
async process(request, response, route, requestIdentity, processorState) {
|
|
38
|
+
async process(request, response, route, requestIdentity, processorState, loggingComponentType) {
|
|
43
39
|
// Don't handle the route if another processor has already set the response
|
|
44
40
|
// status code e.g. from an auth processor
|
|
45
41
|
if (core.Is.empty(response.statusCode)) {
|
|
@@ -62,7 +58,8 @@ class RestRouteProcessor {
|
|
|
62
58
|
const restRouteResponse = await route.handler({
|
|
63
59
|
...requestIdentity,
|
|
64
60
|
serverRequest: request,
|
|
65
|
-
processorState
|
|
61
|
+
processorState,
|
|
62
|
+
loggingComponentType
|
|
66
63
|
}, req);
|
|
67
64
|
let statusCode = restRouteResponse.statusCode ?? response.statusCode ?? web.HttpStatusCode.ok;
|
|
68
65
|
const headers = restRouteResponse?.headers ?? {};
|
|
@@ -83,7 +80,7 @@ class RestRouteProcessor {
|
|
|
83
80
|
// instead of the default application/json
|
|
84
81
|
headers[web.HeaderTypes.ContentType] =
|
|
85
82
|
restRouteResponse?.attachment?.mimeType ??
|
|
86
|
-
|
|
83
|
+
restRouteResponse.headers?.[web.HeaderTypes.ContentType] ??
|
|
87
84
|
`${web.MimeTypes.Json}; charset=utf-8`;
|
|
88
85
|
// If there are filename or inline options set then add the content disposition
|
|
89
86
|
if (core.Is.stringValue(restRouteResponse?.attachment?.filename) ||
|
|
@@ -120,10 +117,6 @@ class RestRouteProcessor {
|
|
|
120
117
|
* Process the socket request and hands it on to the route handler.
|
|
121
118
|
*/
|
|
122
119
|
class SocketRouteProcessor {
|
|
123
|
-
/**
|
|
124
|
-
* The namespace supported by the processor.
|
|
125
|
-
*/
|
|
126
|
-
static NAMESPACE = "socket-route";
|
|
127
120
|
/**
|
|
128
121
|
* Runtime name for the class.
|
|
129
122
|
*/
|
|
@@ -140,6 +133,48 @@ class SocketRouteProcessor {
|
|
|
140
133
|
constructor(options) {
|
|
141
134
|
this._includeErrorStack = options?.config?.includeErrorStack ?? false;
|
|
142
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Process the connected event.
|
|
138
|
+
* @param request The server request object containing the socket id and other parameters.
|
|
139
|
+
* @param route The route being requested, if a matching one was found.
|
|
140
|
+
* @param loggingComponentType The logging component type for the request.
|
|
141
|
+
* @returns Promise that resolves when the request is processed.
|
|
142
|
+
*/
|
|
143
|
+
async connected(request, route, loggingComponentType) {
|
|
144
|
+
if (route?.connected) {
|
|
145
|
+
try {
|
|
146
|
+
const socketRequestContext = {
|
|
147
|
+
socketId: request.socketId,
|
|
148
|
+
serverRequest: request,
|
|
149
|
+
processorState: {},
|
|
150
|
+
loggingComponentType
|
|
151
|
+
};
|
|
152
|
+
await route.connected(socketRequestContext);
|
|
153
|
+
}
|
|
154
|
+
catch { }
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Process the disconnected event.
|
|
159
|
+
* @param request The server request object containing the socket id and other parameters.
|
|
160
|
+
* @param route The route being requested, if a matching one was found.
|
|
161
|
+
* @param loggingComponentType The logging component type for the request.
|
|
162
|
+
* @returns Promise that resolves when the request is processed.
|
|
163
|
+
*/
|
|
164
|
+
async disconnected(request, route, loggingComponentType) {
|
|
165
|
+
if (route?.disconnected) {
|
|
166
|
+
try {
|
|
167
|
+
const socketRequestContext = {
|
|
168
|
+
socketId: request.socketId,
|
|
169
|
+
serverRequest: request,
|
|
170
|
+
processorState: {},
|
|
171
|
+
loggingComponentType
|
|
172
|
+
};
|
|
173
|
+
await route.disconnected(socketRequestContext);
|
|
174
|
+
}
|
|
175
|
+
catch { }
|
|
176
|
+
}
|
|
177
|
+
}
|
|
143
178
|
/**
|
|
144
179
|
* Process the REST request for the specified route.
|
|
145
180
|
* @param request The incoming request.
|
|
@@ -148,8 +183,9 @@ class SocketRouteProcessor {
|
|
|
148
183
|
* @param requestIdentity The identity context for the request.
|
|
149
184
|
* @param processorState The state handed through the processors.
|
|
150
185
|
* @param responseEmitter The function to emit a response.
|
|
186
|
+
* @param loggingComponentType The logging component type for the request.
|
|
151
187
|
*/
|
|
152
|
-
async process(request, response, route, requestIdentity, processorState, responseEmitter) {
|
|
188
|
+
async process(request, response, route, requestIdentity, processorState, responseEmitter, loggingComponentType) {
|
|
153
189
|
// Don't handle the route if another processor has already set the response
|
|
154
190
|
// status code e.g. from an auth processor
|
|
155
191
|
if (core.Is.empty(response.statusCode)) {
|
|
@@ -169,11 +205,14 @@ class SocketRouteProcessor {
|
|
|
169
205
|
query: request.query,
|
|
170
206
|
body: request.body
|
|
171
207
|
};
|
|
172
|
-
|
|
208
|
+
const socketRequestContext = {
|
|
173
209
|
...requestIdentity,
|
|
210
|
+
socketId: request.socketId,
|
|
174
211
|
serverRequest: request,
|
|
175
|
-
processorState
|
|
176
|
-
|
|
212
|
+
processorState,
|
|
213
|
+
loggingComponentType
|
|
214
|
+
};
|
|
215
|
+
await route.handler(socketRequestContext, req, async (topic, restRouteResponse) => {
|
|
177
216
|
response.headers = restRouteResponse?.headers;
|
|
178
217
|
response.body = restRouteResponse?.body;
|
|
179
218
|
response.statusCode =
|
|
@@ -194,10 +233,6 @@ class SocketRouteProcessor {
|
|
|
194
233
|
* Adds a node identity to the request identity.
|
|
195
234
|
*/
|
|
196
235
|
class NodeIdentityProcessor {
|
|
197
|
-
/**
|
|
198
|
-
* The namespace supported by the processor.
|
|
199
|
-
*/
|
|
200
|
-
static NAMESPACE = "node-identity";
|
|
201
236
|
/**
|
|
202
237
|
* Runtime name for the class.
|
|
203
238
|
*/
|
|
@@ -210,10 +245,10 @@ class NodeIdentityProcessor {
|
|
|
210
245
|
/**
|
|
211
246
|
* The service needs to be started when the application is initialized.
|
|
212
247
|
* @param nodeIdentity The identity of the node.
|
|
213
|
-
* @param
|
|
248
|
+
* @param nodeLoggingComponentType The node logging component type.
|
|
214
249
|
* @returns Nothing.
|
|
215
250
|
*/
|
|
216
|
-
async start(nodeIdentity,
|
|
251
|
+
async start(nodeIdentity, nodeLoggingComponentType) {
|
|
217
252
|
core.Guards.string(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
|
|
218
253
|
this._nodeIdentity = nodeIdentity;
|
|
219
254
|
}
|
|
@@ -234,10 +269,6 @@ class NodeIdentityProcessor {
|
|
|
234
269
|
* Adds a static user identity to the request context.
|
|
235
270
|
*/
|
|
236
271
|
class StaticUserIdentityProcessor {
|
|
237
|
-
/**
|
|
238
|
-
* The namespace supported by the processor.
|
|
239
|
-
*/
|
|
240
|
-
static NAMESPACE = "static-user-identity";
|
|
241
272
|
/**
|
|
242
273
|
* Runtime name for the class.
|
|
243
274
|
*/
|
|
@@ -276,19 +307,15 @@ class StaticUserIdentityProcessor {
|
|
|
276
307
|
* Process the REST request and log its information.
|
|
277
308
|
*/
|
|
278
309
|
class LoggingProcessor {
|
|
279
|
-
/**
|
|
280
|
-
* The namespace supported by the processor.
|
|
281
|
-
*/
|
|
282
|
-
static NAMESPACE = "logging";
|
|
283
310
|
/**
|
|
284
311
|
* Runtime name for the class.
|
|
285
312
|
*/
|
|
286
313
|
CLASS_NAME = "LoggingProcessor";
|
|
287
314
|
/**
|
|
288
|
-
* The
|
|
315
|
+
* The component for logging the information.
|
|
289
316
|
* @internal
|
|
290
317
|
*/
|
|
291
|
-
|
|
318
|
+
_logging;
|
|
292
319
|
/**
|
|
293
320
|
* Include the body objects when logging the information.
|
|
294
321
|
* @internal
|
|
@@ -309,7 +336,7 @@ class LoggingProcessor {
|
|
|
309
336
|
* @param options Options for the processor.
|
|
310
337
|
*/
|
|
311
338
|
constructor(options) {
|
|
312
|
-
this.
|
|
339
|
+
this._logging = core.ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
|
|
313
340
|
this._includeBody = options?.config?.includeBody ?? false;
|
|
314
341
|
this._fullBase64 = options?.config?.fullBase64 ?? false;
|
|
315
342
|
this._obfuscateProperties = options?.config?.obfuscateProperties ?? ["password"];
|
|
@@ -326,9 +353,7 @@ class LoggingProcessor {
|
|
|
326
353
|
const now = process.hrtime.bigint();
|
|
327
354
|
processorState.requestStart = now;
|
|
328
355
|
const contentType = request.headers?.[web.HeaderTypes.ContentType];
|
|
329
|
-
const isJson =
|
|
330
|
-
? contentType.includes(web.MimeTypes.Json) || contentType.includes(web.MimeTypes.JsonLd)
|
|
331
|
-
: false;
|
|
356
|
+
const isJson = this.isMimeJson(contentType);
|
|
332
357
|
let requestUrl = "";
|
|
333
358
|
if (core.Is.stringValue(request.url)) {
|
|
334
359
|
// Socket paths do not have a prefix so just use the whole url.
|
|
@@ -339,7 +364,7 @@ class LoggingProcessor {
|
|
|
339
364
|
requestUrl = request.url;
|
|
340
365
|
}
|
|
341
366
|
}
|
|
342
|
-
await this.
|
|
367
|
+
await this._logging?.log({
|
|
343
368
|
level: "info",
|
|
344
369
|
source: this.CLASS_NAME,
|
|
345
370
|
ts: Date.now(),
|
|
@@ -361,9 +386,7 @@ class LoggingProcessor {
|
|
|
361
386
|
let data;
|
|
362
387
|
if (this._includeBody) {
|
|
363
388
|
const contentType = response.headers?.[web.HeaderTypes.ContentType];
|
|
364
|
-
const isJson =
|
|
365
|
-
? contentType.includes(web.MimeTypes.Json) || contentType.includes(web.MimeTypes.JsonLd)
|
|
366
|
-
: false;
|
|
389
|
+
const isJson = this.isMimeJson(contentType);
|
|
367
390
|
const contentLength = response.headers?.[web.HeaderTypes.ContentLength];
|
|
368
391
|
if (isJson) {
|
|
369
392
|
data = {
|
|
@@ -399,7 +422,7 @@ class LoggingProcessor {
|
|
|
399
422
|
requestUrl = request.url;
|
|
400
423
|
}
|
|
401
424
|
}
|
|
402
|
-
await this.
|
|
425
|
+
await this._logging?.log({
|
|
403
426
|
level: core.Is.number(response.statusCode) && response.statusCode >= web.HttpStatusCode.badRequest
|
|
404
427
|
? "error"
|
|
405
428
|
: "info",
|
|
@@ -435,16 +458,52 @@ class LoggingProcessor {
|
|
|
435
458
|
}
|
|
436
459
|
return propValue;
|
|
437
460
|
}
|
|
461
|
+
/**
|
|
462
|
+
* Check if the content type is JSON.
|
|
463
|
+
* @param contentType The content type to check.
|
|
464
|
+
* @returns True if the content type is JSON, false otherwise.
|
|
465
|
+
* @internal
|
|
466
|
+
*/
|
|
467
|
+
isMimeJson(contentType) {
|
|
468
|
+
return core.Is.stringValue(contentType)
|
|
469
|
+
? contentType.includes(web.MimeTypes.Json) || contentType.includes(web.MimeTypes.JsonLd)
|
|
470
|
+
: false;
|
|
471
|
+
}
|
|
438
472
|
}
|
|
439
473
|
|
|
440
474
|
/**
|
|
441
|
-
* Process the
|
|
475
|
+
* Process the JSON-LD mime type.
|
|
442
476
|
*/
|
|
443
|
-
class
|
|
477
|
+
class JsonLdMimeTypeProcessor {
|
|
478
|
+
/**
|
|
479
|
+
* Runtime name for the class.
|
|
480
|
+
*/
|
|
481
|
+
CLASS_NAME = "JsonLdMimeTypeProcessor";
|
|
482
|
+
/**
|
|
483
|
+
* Get the MIME types that this handler can handle.
|
|
484
|
+
* @returns The MIME types that this handler can handle.
|
|
485
|
+
*/
|
|
486
|
+
getTypes() {
|
|
487
|
+
return [web.MimeTypes.JsonLd];
|
|
488
|
+
}
|
|
444
489
|
/**
|
|
445
|
-
*
|
|
490
|
+
* Handle content.
|
|
491
|
+
* @param body The body to process.
|
|
492
|
+
* @returns The processed body.
|
|
446
493
|
*/
|
|
447
|
-
|
|
494
|
+
async handle(body) {
|
|
495
|
+
const json = core.ObjectHelper.fromBytes(body);
|
|
496
|
+
if (core.Is.empty(json) || core.Is.empty(json["@context"])) {
|
|
497
|
+
throw new core.GeneralError(this.CLASS_NAME, "invalidJsonLd");
|
|
498
|
+
}
|
|
499
|
+
return json;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Process the JWT mime type.
|
|
505
|
+
*/
|
|
506
|
+
class JwtMimeTypeProcessor {
|
|
448
507
|
/**
|
|
449
508
|
* Runtime name for the class.
|
|
450
509
|
*/
|
|
@@ -466,6 +525,7 @@ class JwtMimeTypeProcessor {
|
|
|
466
525
|
}
|
|
467
526
|
}
|
|
468
527
|
|
|
528
|
+
exports.JsonLdMimeTypeProcessor = JsonLdMimeTypeProcessor;
|
|
469
529
|
exports.JwtMimeTypeProcessor = JwtMimeTypeProcessor;
|
|
470
530
|
exports.LoggingProcessor = LoggingProcessor;
|
|
471
531
|
exports.NodeIdentityProcessor = NodeIdentityProcessor;
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { HttpErrorHelper } from '@twin.org/api-models';
|
|
2
|
-
import { Is, NotFoundError, Guards, ObjectHelper, Coerce, Converter } from '@twin.org/core';
|
|
2
|
+
import { Is, NotFoundError, Guards, ComponentFactory, ObjectHelper, Coerce, GeneralError, Converter } from '@twin.org/core';
|
|
3
3
|
import { HttpStatusCode, HeaderTypes, MimeTypes } from '@twin.org/web';
|
|
4
|
-
import { LoggingConnectorFactory } from '@twin.org/logging-models';
|
|
5
4
|
|
|
6
5
|
// Copyright 2024 IOTA Stiftung.
|
|
7
6
|
// SPDX-License-Identifier: Apache-2.0.
|
|
@@ -9,10 +8,6 @@ import { LoggingConnectorFactory } from '@twin.org/logging-models';
|
|
|
9
8
|
* Process the REST request and hands it on to the route handler.
|
|
10
9
|
*/
|
|
11
10
|
class RestRouteProcessor {
|
|
12
|
-
/**
|
|
13
|
-
* The namespace supported by the processor.
|
|
14
|
-
*/
|
|
15
|
-
static NAMESPACE = "rest-route";
|
|
16
11
|
/**
|
|
17
12
|
* Runtime name for the class.
|
|
18
13
|
*/
|
|
@@ -36,8 +31,9 @@ class RestRouteProcessor {
|
|
|
36
31
|
* @param route The route to process.
|
|
37
32
|
* @param requestIdentity The identity context for the request.
|
|
38
33
|
* @param processorState The state handed through the processors.
|
|
34
|
+
* @param loggingComponentType The logging component type for the request.
|
|
39
35
|
*/
|
|
40
|
-
async process(request, response, route, requestIdentity, processorState) {
|
|
36
|
+
async process(request, response, route, requestIdentity, processorState, loggingComponentType) {
|
|
41
37
|
// Don't handle the route if another processor has already set the response
|
|
42
38
|
// status code e.g. from an auth processor
|
|
43
39
|
if (Is.empty(response.statusCode)) {
|
|
@@ -60,7 +56,8 @@ class RestRouteProcessor {
|
|
|
60
56
|
const restRouteResponse = await route.handler({
|
|
61
57
|
...requestIdentity,
|
|
62
58
|
serverRequest: request,
|
|
63
|
-
processorState
|
|
59
|
+
processorState,
|
|
60
|
+
loggingComponentType
|
|
64
61
|
}, req);
|
|
65
62
|
let statusCode = restRouteResponse.statusCode ?? response.statusCode ?? HttpStatusCode.ok;
|
|
66
63
|
const headers = restRouteResponse?.headers ?? {};
|
|
@@ -81,7 +78,7 @@ class RestRouteProcessor {
|
|
|
81
78
|
// instead of the default application/json
|
|
82
79
|
headers[HeaderTypes.ContentType] =
|
|
83
80
|
restRouteResponse?.attachment?.mimeType ??
|
|
84
|
-
|
|
81
|
+
restRouteResponse.headers?.[HeaderTypes.ContentType] ??
|
|
85
82
|
`${MimeTypes.Json}; charset=utf-8`;
|
|
86
83
|
// If there are filename or inline options set then add the content disposition
|
|
87
84
|
if (Is.stringValue(restRouteResponse?.attachment?.filename) ||
|
|
@@ -118,10 +115,6 @@ class RestRouteProcessor {
|
|
|
118
115
|
* Process the socket request and hands it on to the route handler.
|
|
119
116
|
*/
|
|
120
117
|
class SocketRouteProcessor {
|
|
121
|
-
/**
|
|
122
|
-
* The namespace supported by the processor.
|
|
123
|
-
*/
|
|
124
|
-
static NAMESPACE = "socket-route";
|
|
125
118
|
/**
|
|
126
119
|
* Runtime name for the class.
|
|
127
120
|
*/
|
|
@@ -138,6 +131,48 @@ class SocketRouteProcessor {
|
|
|
138
131
|
constructor(options) {
|
|
139
132
|
this._includeErrorStack = options?.config?.includeErrorStack ?? false;
|
|
140
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Process the connected event.
|
|
136
|
+
* @param request The server request object containing the socket id and other parameters.
|
|
137
|
+
* @param route The route being requested, if a matching one was found.
|
|
138
|
+
* @param loggingComponentType The logging component type for the request.
|
|
139
|
+
* @returns Promise that resolves when the request is processed.
|
|
140
|
+
*/
|
|
141
|
+
async connected(request, route, loggingComponentType) {
|
|
142
|
+
if (route?.connected) {
|
|
143
|
+
try {
|
|
144
|
+
const socketRequestContext = {
|
|
145
|
+
socketId: request.socketId,
|
|
146
|
+
serverRequest: request,
|
|
147
|
+
processorState: {},
|
|
148
|
+
loggingComponentType
|
|
149
|
+
};
|
|
150
|
+
await route.connected(socketRequestContext);
|
|
151
|
+
}
|
|
152
|
+
catch { }
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Process the disconnected event.
|
|
157
|
+
* @param request The server request object containing the socket id and other parameters.
|
|
158
|
+
* @param route The route being requested, if a matching one was found.
|
|
159
|
+
* @param loggingComponentType The logging component type for the request.
|
|
160
|
+
* @returns Promise that resolves when the request is processed.
|
|
161
|
+
*/
|
|
162
|
+
async disconnected(request, route, loggingComponentType) {
|
|
163
|
+
if (route?.disconnected) {
|
|
164
|
+
try {
|
|
165
|
+
const socketRequestContext = {
|
|
166
|
+
socketId: request.socketId,
|
|
167
|
+
serverRequest: request,
|
|
168
|
+
processorState: {},
|
|
169
|
+
loggingComponentType
|
|
170
|
+
};
|
|
171
|
+
await route.disconnected(socketRequestContext);
|
|
172
|
+
}
|
|
173
|
+
catch { }
|
|
174
|
+
}
|
|
175
|
+
}
|
|
141
176
|
/**
|
|
142
177
|
* Process the REST request for the specified route.
|
|
143
178
|
* @param request The incoming request.
|
|
@@ -146,8 +181,9 @@ class SocketRouteProcessor {
|
|
|
146
181
|
* @param requestIdentity The identity context for the request.
|
|
147
182
|
* @param processorState The state handed through the processors.
|
|
148
183
|
* @param responseEmitter The function to emit a response.
|
|
184
|
+
* @param loggingComponentType The logging component type for the request.
|
|
149
185
|
*/
|
|
150
|
-
async process(request, response, route, requestIdentity, processorState, responseEmitter) {
|
|
186
|
+
async process(request, response, route, requestIdentity, processorState, responseEmitter, loggingComponentType) {
|
|
151
187
|
// Don't handle the route if another processor has already set the response
|
|
152
188
|
// status code e.g. from an auth processor
|
|
153
189
|
if (Is.empty(response.statusCode)) {
|
|
@@ -167,11 +203,14 @@ class SocketRouteProcessor {
|
|
|
167
203
|
query: request.query,
|
|
168
204
|
body: request.body
|
|
169
205
|
};
|
|
170
|
-
|
|
206
|
+
const socketRequestContext = {
|
|
171
207
|
...requestIdentity,
|
|
208
|
+
socketId: request.socketId,
|
|
172
209
|
serverRequest: request,
|
|
173
|
-
processorState
|
|
174
|
-
|
|
210
|
+
processorState,
|
|
211
|
+
loggingComponentType
|
|
212
|
+
};
|
|
213
|
+
await route.handler(socketRequestContext, req, async (topic, restRouteResponse) => {
|
|
175
214
|
response.headers = restRouteResponse?.headers;
|
|
176
215
|
response.body = restRouteResponse?.body;
|
|
177
216
|
response.statusCode =
|
|
@@ -192,10 +231,6 @@ class SocketRouteProcessor {
|
|
|
192
231
|
* Adds a node identity to the request identity.
|
|
193
232
|
*/
|
|
194
233
|
class NodeIdentityProcessor {
|
|
195
|
-
/**
|
|
196
|
-
* The namespace supported by the processor.
|
|
197
|
-
*/
|
|
198
|
-
static NAMESPACE = "node-identity";
|
|
199
234
|
/**
|
|
200
235
|
* Runtime name for the class.
|
|
201
236
|
*/
|
|
@@ -208,10 +243,10 @@ class NodeIdentityProcessor {
|
|
|
208
243
|
/**
|
|
209
244
|
* The service needs to be started when the application is initialized.
|
|
210
245
|
* @param nodeIdentity The identity of the node.
|
|
211
|
-
* @param
|
|
246
|
+
* @param nodeLoggingComponentType The node logging component type.
|
|
212
247
|
* @returns Nothing.
|
|
213
248
|
*/
|
|
214
|
-
async start(nodeIdentity,
|
|
249
|
+
async start(nodeIdentity, nodeLoggingComponentType) {
|
|
215
250
|
Guards.string(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
|
|
216
251
|
this._nodeIdentity = nodeIdentity;
|
|
217
252
|
}
|
|
@@ -232,10 +267,6 @@ class NodeIdentityProcessor {
|
|
|
232
267
|
* Adds a static user identity to the request context.
|
|
233
268
|
*/
|
|
234
269
|
class StaticUserIdentityProcessor {
|
|
235
|
-
/**
|
|
236
|
-
* The namespace supported by the processor.
|
|
237
|
-
*/
|
|
238
|
-
static NAMESPACE = "static-user-identity";
|
|
239
270
|
/**
|
|
240
271
|
* Runtime name for the class.
|
|
241
272
|
*/
|
|
@@ -274,19 +305,15 @@ class StaticUserIdentityProcessor {
|
|
|
274
305
|
* Process the REST request and log its information.
|
|
275
306
|
*/
|
|
276
307
|
class LoggingProcessor {
|
|
277
|
-
/**
|
|
278
|
-
* The namespace supported by the processor.
|
|
279
|
-
*/
|
|
280
|
-
static NAMESPACE = "logging";
|
|
281
308
|
/**
|
|
282
309
|
* Runtime name for the class.
|
|
283
310
|
*/
|
|
284
311
|
CLASS_NAME = "LoggingProcessor";
|
|
285
312
|
/**
|
|
286
|
-
* The
|
|
313
|
+
* The component for logging the information.
|
|
287
314
|
* @internal
|
|
288
315
|
*/
|
|
289
|
-
|
|
316
|
+
_logging;
|
|
290
317
|
/**
|
|
291
318
|
* Include the body objects when logging the information.
|
|
292
319
|
* @internal
|
|
@@ -307,7 +334,7 @@ class LoggingProcessor {
|
|
|
307
334
|
* @param options Options for the processor.
|
|
308
335
|
*/
|
|
309
336
|
constructor(options) {
|
|
310
|
-
this.
|
|
337
|
+
this._logging = ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
|
|
311
338
|
this._includeBody = options?.config?.includeBody ?? false;
|
|
312
339
|
this._fullBase64 = options?.config?.fullBase64 ?? false;
|
|
313
340
|
this._obfuscateProperties = options?.config?.obfuscateProperties ?? ["password"];
|
|
@@ -324,9 +351,7 @@ class LoggingProcessor {
|
|
|
324
351
|
const now = process.hrtime.bigint();
|
|
325
352
|
processorState.requestStart = now;
|
|
326
353
|
const contentType = request.headers?.[HeaderTypes.ContentType];
|
|
327
|
-
const isJson =
|
|
328
|
-
? contentType.includes(MimeTypes.Json) || contentType.includes(MimeTypes.JsonLd)
|
|
329
|
-
: false;
|
|
354
|
+
const isJson = this.isMimeJson(contentType);
|
|
330
355
|
let requestUrl = "";
|
|
331
356
|
if (Is.stringValue(request.url)) {
|
|
332
357
|
// Socket paths do not have a prefix so just use the whole url.
|
|
@@ -337,7 +362,7 @@ class LoggingProcessor {
|
|
|
337
362
|
requestUrl = request.url;
|
|
338
363
|
}
|
|
339
364
|
}
|
|
340
|
-
await this.
|
|
365
|
+
await this._logging?.log({
|
|
341
366
|
level: "info",
|
|
342
367
|
source: this.CLASS_NAME,
|
|
343
368
|
ts: Date.now(),
|
|
@@ -359,9 +384,7 @@ class LoggingProcessor {
|
|
|
359
384
|
let data;
|
|
360
385
|
if (this._includeBody) {
|
|
361
386
|
const contentType = response.headers?.[HeaderTypes.ContentType];
|
|
362
|
-
const isJson =
|
|
363
|
-
? contentType.includes(MimeTypes.Json) || contentType.includes(MimeTypes.JsonLd)
|
|
364
|
-
: false;
|
|
387
|
+
const isJson = this.isMimeJson(contentType);
|
|
365
388
|
const contentLength = response.headers?.[HeaderTypes.ContentLength];
|
|
366
389
|
if (isJson) {
|
|
367
390
|
data = {
|
|
@@ -397,7 +420,7 @@ class LoggingProcessor {
|
|
|
397
420
|
requestUrl = request.url;
|
|
398
421
|
}
|
|
399
422
|
}
|
|
400
|
-
await this.
|
|
423
|
+
await this._logging?.log({
|
|
401
424
|
level: Is.number(response.statusCode) && response.statusCode >= HttpStatusCode.badRequest
|
|
402
425
|
? "error"
|
|
403
426
|
: "info",
|
|
@@ -433,16 +456,52 @@ class LoggingProcessor {
|
|
|
433
456
|
}
|
|
434
457
|
return propValue;
|
|
435
458
|
}
|
|
459
|
+
/**
|
|
460
|
+
* Check if the content type is JSON.
|
|
461
|
+
* @param contentType The content type to check.
|
|
462
|
+
* @returns True if the content type is JSON, false otherwise.
|
|
463
|
+
* @internal
|
|
464
|
+
*/
|
|
465
|
+
isMimeJson(contentType) {
|
|
466
|
+
return Is.stringValue(contentType)
|
|
467
|
+
? contentType.includes(MimeTypes.Json) || contentType.includes(MimeTypes.JsonLd)
|
|
468
|
+
: false;
|
|
469
|
+
}
|
|
436
470
|
}
|
|
437
471
|
|
|
438
472
|
/**
|
|
439
|
-
* Process the
|
|
473
|
+
* Process the JSON-LD mime type.
|
|
440
474
|
*/
|
|
441
|
-
class
|
|
475
|
+
class JsonLdMimeTypeProcessor {
|
|
476
|
+
/**
|
|
477
|
+
* Runtime name for the class.
|
|
478
|
+
*/
|
|
479
|
+
CLASS_NAME = "JsonLdMimeTypeProcessor";
|
|
480
|
+
/**
|
|
481
|
+
* Get the MIME types that this handler can handle.
|
|
482
|
+
* @returns The MIME types that this handler can handle.
|
|
483
|
+
*/
|
|
484
|
+
getTypes() {
|
|
485
|
+
return [MimeTypes.JsonLd];
|
|
486
|
+
}
|
|
442
487
|
/**
|
|
443
|
-
*
|
|
488
|
+
* Handle content.
|
|
489
|
+
* @param body The body to process.
|
|
490
|
+
* @returns The processed body.
|
|
444
491
|
*/
|
|
445
|
-
|
|
492
|
+
async handle(body) {
|
|
493
|
+
const json = ObjectHelper.fromBytes(body);
|
|
494
|
+
if (Is.empty(json) || Is.empty(json["@context"])) {
|
|
495
|
+
throw new GeneralError(this.CLASS_NAME, "invalidJsonLd");
|
|
496
|
+
}
|
|
497
|
+
return json;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Process the JWT mime type.
|
|
503
|
+
*/
|
|
504
|
+
class JwtMimeTypeProcessor {
|
|
446
505
|
/**
|
|
447
506
|
* Runtime name for the class.
|
|
448
507
|
*/
|
|
@@ -464,4 +523,4 @@ class JwtMimeTypeProcessor {
|
|
|
464
523
|
}
|
|
465
524
|
}
|
|
466
525
|
|
|
467
|
-
export { JwtMimeTypeProcessor, LoggingProcessor, NodeIdentityProcessor, RestRouteProcessor, SocketRouteProcessor, StaticUserIdentityProcessor };
|
|
526
|
+
export { JsonLdMimeTypeProcessor, JwtMimeTypeProcessor, LoggingProcessor, NodeIdentityProcessor, RestRouteProcessor, SocketRouteProcessor, StaticUserIdentityProcessor };
|
|
@@ -4,10 +4,6 @@ import type { IRestRouteProcessorConstructorOptions } from "../models/IRestRoute
|
|
|
4
4
|
* Process the REST request and hands it on to the route handler.
|
|
5
5
|
*/
|
|
6
6
|
export declare class RestRouteProcessor implements IRestRouteProcessor {
|
|
7
|
-
/**
|
|
8
|
-
* The namespace supported by the processor.
|
|
9
|
-
*/
|
|
10
|
-
static readonly NAMESPACE: string;
|
|
11
7
|
/**
|
|
12
8
|
* Runtime name for the class.
|
|
13
9
|
*/
|
|
@@ -24,8 +20,9 @@ export declare class RestRouteProcessor implements IRestRouteProcessor {
|
|
|
24
20
|
* @param route The route to process.
|
|
25
21
|
* @param requestIdentity The identity context for the request.
|
|
26
22
|
* @param processorState The state handed through the processors.
|
|
23
|
+
* @param loggingComponentType The logging component type for the request.
|
|
27
24
|
*/
|
|
28
25
|
process(request: IHttpServerRequest, response: IHttpResponse, route: IRestRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
|
|
29
26
|
[id: string]: unknown;
|
|
30
|
-
}): Promise<void>;
|
|
27
|
+
}, loggingComponentType?: string): Promise<void>;
|
|
31
28
|
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { type IHttpRequestIdentity, type IHttpResponse, type
|
|
1
|
+
import { type IHttpRequestIdentity, type IHttpResponse, type ISocketRoute, type ISocketRouteProcessor, type ISocketServerRequest } from "@twin.org/api-models";
|
|
2
2
|
import type { ISocketRouteProcessorConstructorOptions } from "../models/ISocketRouteProcessorConstructorOptions";
|
|
3
3
|
/**
|
|
4
4
|
* Process the socket request and hands it on to the route handler.
|
|
5
5
|
*/
|
|
6
6
|
export declare class SocketRouteProcessor implements ISocketRouteProcessor {
|
|
7
|
-
/**
|
|
8
|
-
* The namespace supported by the processor.
|
|
9
|
-
*/
|
|
10
|
-
static readonly NAMESPACE: string;
|
|
11
7
|
/**
|
|
12
8
|
* Runtime name for the class.
|
|
13
9
|
*/
|
|
@@ -17,6 +13,22 @@ export declare class SocketRouteProcessor implements ISocketRouteProcessor {
|
|
|
17
13
|
* @param options Options for the processor.
|
|
18
14
|
*/
|
|
19
15
|
constructor(options?: ISocketRouteProcessorConstructorOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Process the connected event.
|
|
18
|
+
* @param request The server request object containing the socket id and other parameters.
|
|
19
|
+
* @param route The route being requested, if a matching one was found.
|
|
20
|
+
* @param loggingComponentType The logging component type for the request.
|
|
21
|
+
* @returns Promise that resolves when the request is processed.
|
|
22
|
+
*/
|
|
23
|
+
connected(request: ISocketServerRequest, route: ISocketRoute | undefined, loggingComponentType?: string): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Process the disconnected event.
|
|
26
|
+
* @param request The server request object containing the socket id and other parameters.
|
|
27
|
+
* @param route The route being requested, if a matching one was found.
|
|
28
|
+
* @param loggingComponentType The logging component type for the request.
|
|
29
|
+
* @returns Promise that resolves when the request is processed.
|
|
30
|
+
*/
|
|
31
|
+
disconnected(request: ISocketServerRequest, route: ISocketRoute | undefined, loggingComponentType?: string): Promise<void>;
|
|
20
32
|
/**
|
|
21
33
|
* Process the REST request for the specified route.
|
|
22
34
|
* @param request The incoming request.
|
|
@@ -25,8 +37,9 @@ export declare class SocketRouteProcessor implements ISocketRouteProcessor {
|
|
|
25
37
|
* @param requestIdentity The identity context for the request.
|
|
26
38
|
* @param processorState The state handed through the processors.
|
|
27
39
|
* @param responseEmitter The function to emit a response.
|
|
40
|
+
* @param loggingComponentType The logging component type for the request.
|
|
28
41
|
*/
|
|
29
|
-
process(request:
|
|
42
|
+
process(request: ISocketServerRequest, response: IHttpResponse, route: ISocketRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
|
|
30
43
|
[id: string]: unknown;
|
|
31
|
-
}, responseEmitter: (topic: string, response: IHttpResponse) => Promise<void
|
|
44
|
+
}, responseEmitter: (topic: string, response: IHttpResponse) => Promise<void>, loggingComponentType?: string): Promise<void>;
|
|
32
45
|
}
|
|
@@ -3,10 +3,6 @@ import type { IBaseRoute, IBaseRouteProcessor, IHttpRequestIdentity, IHttpRespon
|
|
|
3
3
|
* Adds a node identity to the request identity.
|
|
4
4
|
*/
|
|
5
5
|
export declare class NodeIdentityProcessor implements IBaseRouteProcessor {
|
|
6
|
-
/**
|
|
7
|
-
* The namespace supported by the processor.
|
|
8
|
-
*/
|
|
9
|
-
static readonly NAMESPACE: string;
|
|
10
6
|
/**
|
|
11
7
|
* Runtime name for the class.
|
|
12
8
|
*/
|
|
@@ -14,10 +10,10 @@ export declare class NodeIdentityProcessor implements IBaseRouteProcessor {
|
|
|
14
10
|
/**
|
|
15
11
|
* The service needs to be started when the application is initialized.
|
|
16
12
|
* @param nodeIdentity The identity of the node.
|
|
17
|
-
* @param
|
|
13
|
+
* @param nodeLoggingComponentType The node logging component type.
|
|
18
14
|
* @returns Nothing.
|
|
19
15
|
*/
|
|
20
|
-
start(nodeIdentity: string,
|
|
16
|
+
start(nodeIdentity: string, nodeLoggingComponentType?: string): Promise<void>;
|
|
21
17
|
/**
|
|
22
18
|
* Pre process the REST request for the specified route.
|
|
23
19
|
* @param request The incoming request.
|
|
@@ -4,10 +4,6 @@ import type { IStaticUserIdentityProcessorConstructorOptions } from "../models/I
|
|
|
4
4
|
* Adds a static user identity to the request context.
|
|
5
5
|
*/
|
|
6
6
|
export declare class StaticUserIdentityProcessor implements IBaseRouteProcessor {
|
|
7
|
-
/**
|
|
8
|
-
* The namespace supported by the processor.
|
|
9
|
-
*/
|
|
10
|
-
static readonly NAMESPACE: string;
|
|
11
7
|
/**
|
|
12
8
|
* Runtime name for the class.
|
|
13
9
|
*/
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./data/socketRouteProcessor";
|
|
|
3
3
|
export * from "./identity/nodeIdentityProcessor";
|
|
4
4
|
export * from "./identity/staticUserIdentityProcessor";
|
|
5
5
|
export * from "./logging/loggingProcessor";
|
|
6
|
+
export * from "./mimeType/jsonLdMimeTypeProcessor";
|
|
6
7
|
export * from "./mimeType/jwtMimeTypeProcessor";
|
|
7
8
|
export * from "./models/ILoggingProcessorConfig";
|
|
8
9
|
export * from "./models/ILoggingProcessorConstructorOptions";
|
|
@@ -4,10 +4,6 @@ import type { ILoggingProcessorConstructorOptions } from "../models/ILoggingProc
|
|
|
4
4
|
* Process the REST request and log its information.
|
|
5
5
|
*/
|
|
6
6
|
export declare class LoggingProcessor implements IBaseRouteProcessor {
|
|
7
|
-
/**
|
|
8
|
-
* The namespace supported by the processor.
|
|
9
|
-
*/
|
|
10
|
-
static readonly NAMESPACE: string;
|
|
11
7
|
/**
|
|
12
8
|
* Runtime name for the class.
|
|
13
9
|
*/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { IMimeTypeProcessor } from "@twin.org/api-models";
|
|
2
|
+
/**
|
|
3
|
+
* Process the JSON-LD mime type.
|
|
4
|
+
*/
|
|
5
|
+
export declare class JsonLdMimeTypeProcessor implements IMimeTypeProcessor {
|
|
6
|
+
/**
|
|
7
|
+
* Runtime name for the class.
|
|
8
|
+
*/
|
|
9
|
+
readonly CLASS_NAME: string;
|
|
10
|
+
/**
|
|
11
|
+
* Get the MIME types that this handler can handle.
|
|
12
|
+
* @returns The MIME types that this handler can handle.
|
|
13
|
+
*/
|
|
14
|
+
getTypes(): string[];
|
|
15
|
+
/**
|
|
16
|
+
* Handle content.
|
|
17
|
+
* @param body The body to process.
|
|
18
|
+
* @returns The processed body.
|
|
19
|
+
*/
|
|
20
|
+
handle(body: Uint8Array): Promise<unknown>;
|
|
21
|
+
}
|
|
@@ -3,10 +3,6 @@ import type { IMimeTypeProcessor } from "@twin.org/api-models";
|
|
|
3
3
|
* Process the JWT mime type.
|
|
4
4
|
*/
|
|
5
5
|
export declare class JwtMimeTypeProcessor implements IMimeTypeProcessor {
|
|
6
|
-
/**
|
|
7
|
-
* The namespace supported by the processor.
|
|
8
|
-
*/
|
|
9
|
-
static readonly NAMESPACE: string;
|
|
10
6
|
/**
|
|
11
7
|
* Runtime name for the class.
|
|
12
8
|
*/
|
|
@@ -4,12 +4,11 @@ import type { ILoggingProcessorConfig } from "./ILoggingProcessorConfig";
|
|
|
4
4
|
*/
|
|
5
5
|
export interface ILoggingProcessorConstructorOptions {
|
|
6
6
|
/**
|
|
7
|
-
* The type for the logging
|
|
8
|
-
* @default logging
|
|
7
|
+
* The type for the logging component.
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
loggingComponentType?: string;
|
|
11
10
|
/**
|
|
12
|
-
*
|
|
11
|
+
* The configuration for the logging processor.
|
|
13
12
|
*/
|
|
14
13
|
config?: ILoggingProcessorConfig;
|
|
15
14
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,153 @@
|
|
|
1
1
|
# @twin.org/api-processors - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.2-next.10](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.9...api-processors-v0.0.2-next.10) (2025-09-23)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **api-processors:** Synchronize repo versions
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/api-models bumped from 0.0.2-next.9 to 0.0.2-next.10
|
|
16
|
+
|
|
17
|
+
## [0.0.2-next.9](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.8...api-processors-v0.0.2-next.9) (2025-08-29)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* eslint migration to flat config ([0dd5820](https://github.com/twinfoundation/api/commit/0dd5820e3af97350fd08b8d226f4a6c1a9246805))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* dependencies
|
|
29
|
+
* @twin.org/api-models bumped from 0.0.2-next.8 to 0.0.2-next.9
|
|
30
|
+
|
|
31
|
+
## [0.0.2-next.8](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.7...api-processors-v0.0.2-next.8) (2025-08-21)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
* add root, favicon routes ([71da1c3](https://github.com/twinfoundation/api/commit/71da1c3a93c349588aff7084d1d8d6a29a277da8))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Dependencies
|
|
40
|
+
|
|
41
|
+
* The following workspace dependencies were updated
|
|
42
|
+
* dependencies
|
|
43
|
+
* @twin.org/api-models bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
44
|
+
|
|
45
|
+
## [0.0.2-next.7](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.6...api-processors-v0.0.2-next.7) (2025-08-20)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Features
|
|
49
|
+
|
|
50
|
+
* logging naming consistency ([a4a6ef2](https://github.com/twinfoundation/api/commit/a4a6ef2de5049045589eb78b177ff62e744bde9d))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Dependencies
|
|
54
|
+
|
|
55
|
+
* The following workspace dependencies were updated
|
|
56
|
+
* dependencies
|
|
57
|
+
* @twin.org/api-models bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
58
|
+
|
|
59
|
+
## [0.0.2-next.6](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.5...api-processors-v0.0.2-next.6) (2025-08-19)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Features
|
|
63
|
+
|
|
64
|
+
* update framework core ([d8eebf2](https://github.com/twinfoundation/api/commit/d8eebf267fa2a0abaa84e58590496e9d20490cfa))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### Dependencies
|
|
68
|
+
|
|
69
|
+
* The following workspace dependencies were updated
|
|
70
|
+
* dependencies
|
|
71
|
+
* @twin.org/api-models bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
72
|
+
|
|
73
|
+
## [0.0.2-next.5](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.4...api-processors-v0.0.2-next.5) (2025-07-25)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
### Features
|
|
77
|
+
|
|
78
|
+
* add json-ld mime type processor and auth admin component ([8861791](https://github.com/twinfoundation/api/commit/88617916e23bfbca023dbae1976fe421983a02ff))
|
|
79
|
+
* add logging component type to request contexts ([210de1b](https://github.com/twinfoundation/api/commit/210de1b9e1c91079b59a2b90ddd57569668d647d))
|
|
80
|
+
* add socket id, connect and disconnect ([20b0d0e](https://github.com/twinfoundation/api/commit/20b0d0ec279cab46141fee09de2c4a7087cdce16))
|
|
81
|
+
* remove unused namespace ([08478f2](https://github.com/twinfoundation/api/commit/08478f27efda9beb0271fdb22f6972e918361965))
|
|
82
|
+
* update dependencies ([1171dc4](https://github.com/twinfoundation/api/commit/1171dc416a9481737f6a640e3cf30145768f37e9))
|
|
83
|
+
* use shared store mechanism ([#19](https://github.com/twinfoundation/api/issues/19)) ([32116df](https://github.com/twinfoundation/api/commit/32116df3b4380a30137f5056f242a5c99afa2df9))
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
### Dependencies
|
|
87
|
+
|
|
88
|
+
* The following workspace dependencies were updated
|
|
89
|
+
* dependencies
|
|
90
|
+
* @twin.org/api-models bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
91
|
+
|
|
92
|
+
## [0.0.2-next.4](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.3...api-processors-v0.0.2-next.4) (2025-07-25)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
### Features
|
|
96
|
+
|
|
97
|
+
* add logging component type to request contexts ([210de1b](https://github.com/twinfoundation/api/commit/210de1b9e1c91079b59a2b90ddd57569668d647d))
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
### Dependencies
|
|
101
|
+
|
|
102
|
+
* The following workspace dependencies were updated
|
|
103
|
+
* dependencies
|
|
104
|
+
* @twin.org/api-models bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
105
|
+
|
|
106
|
+
## [0.0.2-next.3](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.2...api-processors-v0.0.2-next.3) (2025-07-24)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
### Features
|
|
110
|
+
|
|
111
|
+
* add socket id, connect and disconnect ([20b0d0e](https://github.com/twinfoundation/api/commit/20b0d0ec279cab46141fee09de2c4a7087cdce16))
|
|
112
|
+
* remove unused namespace ([08478f2](https://github.com/twinfoundation/api/commit/08478f27efda9beb0271fdb22f6972e918361965))
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
### Dependencies
|
|
116
|
+
|
|
117
|
+
* The following workspace dependencies were updated
|
|
118
|
+
* dependencies
|
|
119
|
+
* @twin.org/api-models bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
120
|
+
|
|
121
|
+
## [0.0.2-next.2](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.1...api-processors-v0.0.2-next.2) (2025-07-17)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
### Miscellaneous Chores
|
|
125
|
+
|
|
126
|
+
* **api-processors:** Synchronize repo versions
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
### Dependencies
|
|
130
|
+
|
|
131
|
+
* The following workspace dependencies were updated
|
|
132
|
+
* dependencies
|
|
133
|
+
* @twin.org/api-models bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
134
|
+
|
|
135
|
+
## [0.0.2-next.1](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.0...api-processors-v0.0.2-next.1) (2025-07-08)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
### Features
|
|
139
|
+
|
|
140
|
+
* add json-ld mime type processor and auth admin component ([8861791](https://github.com/twinfoundation/api/commit/88617916e23bfbca023dbae1976fe421983a02ff))
|
|
141
|
+
* update dependencies ([1171dc4](https://github.com/twinfoundation/api/commit/1171dc416a9481737f6a640e3cf30145768f37e9))
|
|
142
|
+
* use shared store mechanism ([#19](https://github.com/twinfoundation/api/issues/19)) ([32116df](https://github.com/twinfoundation/api/commit/32116df3b4380a30137f5056f242a5c99afa2df9))
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
### Dependencies
|
|
146
|
+
|
|
147
|
+
* The following workspace dependencies were updated
|
|
148
|
+
* dependencies
|
|
149
|
+
* @twin.org/api-models bumped from 0.0.2-next.0 to 0.0.2-next.1
|
|
150
|
+
|
|
3
151
|
## 0.0.1 (2025-07-03)
|
|
4
152
|
|
|
5
153
|
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# Class: JsonLdMimeTypeProcessor
|
|
2
|
+
|
|
3
|
+
Process the JSON-LD mime type.
|
|
4
|
+
|
|
5
|
+
## Implements
|
|
6
|
+
|
|
7
|
+
- `IMimeTypeProcessor`
|
|
8
|
+
|
|
9
|
+
## Constructors
|
|
10
|
+
|
|
11
|
+
### Constructor
|
|
12
|
+
|
|
13
|
+
> **new JsonLdMimeTypeProcessor**(): `JsonLdMimeTypeProcessor`
|
|
14
|
+
|
|
15
|
+
#### Returns
|
|
16
|
+
|
|
17
|
+
`JsonLdMimeTypeProcessor`
|
|
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
|
+
`IMimeTypeProcessor.CLASS_NAME`
|
|
30
|
+
|
|
31
|
+
## Methods
|
|
32
|
+
|
|
33
|
+
### getTypes()
|
|
34
|
+
|
|
35
|
+
> **getTypes**(): `string`[]
|
|
36
|
+
|
|
37
|
+
Get the MIME types that this handler can handle.
|
|
38
|
+
|
|
39
|
+
#### Returns
|
|
40
|
+
|
|
41
|
+
`string`[]
|
|
42
|
+
|
|
43
|
+
The MIME types that this handler can handle.
|
|
44
|
+
|
|
45
|
+
#### Implementation of
|
|
46
|
+
|
|
47
|
+
`IMimeTypeProcessor.getTypes`
|
|
48
|
+
|
|
49
|
+
***
|
|
50
|
+
|
|
51
|
+
### handle()
|
|
52
|
+
|
|
53
|
+
> **handle**(`body`): `Promise`\<`unknown`\>
|
|
54
|
+
|
|
55
|
+
Handle content.
|
|
56
|
+
|
|
57
|
+
#### Parameters
|
|
58
|
+
|
|
59
|
+
##### body
|
|
60
|
+
|
|
61
|
+
`Uint8Array`
|
|
62
|
+
|
|
63
|
+
The body to process.
|
|
64
|
+
|
|
65
|
+
#### Returns
|
|
66
|
+
|
|
67
|
+
`Promise`\<`unknown`\>
|
|
68
|
+
|
|
69
|
+
The processed body.
|
|
70
|
+
|
|
71
|
+
#### Implementation of
|
|
72
|
+
|
|
73
|
+
`IMimeTypeProcessor.handle`
|
|
@@ -18,14 +18,6 @@ Process the JWT mime type.
|
|
|
18
18
|
|
|
19
19
|
## Properties
|
|
20
20
|
|
|
21
|
-
### NAMESPACE
|
|
22
|
-
|
|
23
|
-
> `readonly` `static` **NAMESPACE**: `string` = `"jwt"`
|
|
24
|
-
|
|
25
|
-
The namespace supported by the processor.
|
|
26
|
-
|
|
27
|
-
***
|
|
28
|
-
|
|
29
21
|
### CLASS\_NAME
|
|
30
22
|
|
|
31
23
|
> `readonly` **CLASS\_NAME**: `string`
|
|
@@ -28,14 +28,6 @@ Options for the processor.
|
|
|
28
28
|
|
|
29
29
|
## Properties
|
|
30
30
|
|
|
31
|
-
### NAMESPACE
|
|
32
|
-
|
|
33
|
-
> `readonly` `static` **NAMESPACE**: `string` = `"logging"`
|
|
34
|
-
|
|
35
|
-
The namespace supported by the processor.
|
|
36
|
-
|
|
37
|
-
***
|
|
38
|
-
|
|
39
31
|
### CLASS\_NAME
|
|
40
32
|
|
|
41
33
|
> `readonly` **CLASS\_NAME**: `string`
|
|
@@ -18,14 +18,6 @@ Adds a node identity to the request identity.
|
|
|
18
18
|
|
|
19
19
|
## Properties
|
|
20
20
|
|
|
21
|
-
### NAMESPACE
|
|
22
|
-
|
|
23
|
-
> `readonly` `static` **NAMESPACE**: `string` = `"node-identity"`
|
|
24
|
-
|
|
25
|
-
The namespace supported by the processor.
|
|
26
|
-
|
|
27
|
-
***
|
|
28
|
-
|
|
29
21
|
### CLASS\_NAME
|
|
30
22
|
|
|
31
23
|
> `readonly` **CLASS\_NAME**: `string`
|
|
@@ -40,7 +32,7 @@ Runtime name for the class.
|
|
|
40
32
|
|
|
41
33
|
### start()
|
|
42
34
|
|
|
43
|
-
> **start**(`nodeIdentity`, `
|
|
35
|
+
> **start**(`nodeIdentity`, `nodeLoggingComponentType?`): `Promise`\<`void`\>
|
|
44
36
|
|
|
45
37
|
The service needs to be started when the application is initialized.
|
|
46
38
|
|
|
@@ -52,11 +44,11 @@ The service needs to be started when the application is initialized.
|
|
|
52
44
|
|
|
53
45
|
The identity of the node.
|
|
54
46
|
|
|
55
|
-
#####
|
|
47
|
+
##### nodeLoggingComponentType?
|
|
56
48
|
|
|
57
49
|
`string`
|
|
58
50
|
|
|
59
|
-
The node logging
|
|
51
|
+
The node logging component type.
|
|
60
52
|
|
|
61
53
|
#### Returns
|
|
62
54
|
|
|
@@ -28,14 +28,6 @@ Options for the processor.
|
|
|
28
28
|
|
|
29
29
|
## Properties
|
|
30
30
|
|
|
31
|
-
### NAMESPACE
|
|
32
|
-
|
|
33
|
-
> `readonly` `static` **NAMESPACE**: `string` = `"rest-route"`
|
|
34
|
-
|
|
35
|
-
The namespace supported by the processor.
|
|
36
|
-
|
|
37
|
-
***
|
|
38
|
-
|
|
39
31
|
### CLASS\_NAME
|
|
40
32
|
|
|
41
33
|
> `readonly` **CLASS\_NAME**: `string`
|
|
@@ -50,7 +42,7 @@ Runtime name for the class.
|
|
|
50
42
|
|
|
51
43
|
### process()
|
|
52
44
|
|
|
53
|
-
> **process**(`request`, `response`, `route`, `requestIdentity`, `processorState`): `Promise`\<`void`\>
|
|
45
|
+
> **process**(`request`, `response`, `route`, `requestIdentity`, `processorState`, `loggingComponentType?`): `Promise`\<`void`\>
|
|
54
46
|
|
|
55
47
|
Process the REST request for the specified route.
|
|
56
48
|
|
|
@@ -84,6 +76,12 @@ The identity context for the request.
|
|
|
84
76
|
|
|
85
77
|
The state handed through the processors.
|
|
86
78
|
|
|
79
|
+
##### loggingComponentType?
|
|
80
|
+
|
|
81
|
+
`string`
|
|
82
|
+
|
|
83
|
+
The logging component type for the request.
|
|
84
|
+
|
|
87
85
|
#### Returns
|
|
88
86
|
|
|
89
87
|
`Promise`\<`void`\>
|
|
@@ -28,14 +28,6 @@ Options for the processor.
|
|
|
28
28
|
|
|
29
29
|
## Properties
|
|
30
30
|
|
|
31
|
-
### NAMESPACE
|
|
32
|
-
|
|
33
|
-
> `readonly` `static` **NAMESPACE**: `string` = `"socket-route"`
|
|
34
|
-
|
|
35
|
-
The namespace supported by the processor.
|
|
36
|
-
|
|
37
|
-
***
|
|
38
|
-
|
|
39
31
|
### CLASS\_NAME
|
|
40
32
|
|
|
41
33
|
> `readonly` **CLASS\_NAME**: `string`
|
|
@@ -48,9 +40,85 @@ Runtime name for the class.
|
|
|
48
40
|
|
|
49
41
|
## Methods
|
|
50
42
|
|
|
43
|
+
### connected()
|
|
44
|
+
|
|
45
|
+
> **connected**(`request`, `route`, `loggingComponentType?`): `Promise`\<`void`\>
|
|
46
|
+
|
|
47
|
+
Process the connected event.
|
|
48
|
+
|
|
49
|
+
#### Parameters
|
|
50
|
+
|
|
51
|
+
##### request
|
|
52
|
+
|
|
53
|
+
`ISocketServerRequest`
|
|
54
|
+
|
|
55
|
+
The server request object containing the socket id and other parameters.
|
|
56
|
+
|
|
57
|
+
##### route
|
|
58
|
+
|
|
59
|
+
The route being requested, if a matching one was found.
|
|
60
|
+
|
|
61
|
+
`undefined` | `ISocketRoute`\<`any`, `any`\>
|
|
62
|
+
|
|
63
|
+
##### loggingComponentType?
|
|
64
|
+
|
|
65
|
+
`string`
|
|
66
|
+
|
|
67
|
+
The logging component type for the request.
|
|
68
|
+
|
|
69
|
+
#### Returns
|
|
70
|
+
|
|
71
|
+
`Promise`\<`void`\>
|
|
72
|
+
|
|
73
|
+
Promise that resolves when the request is processed.
|
|
74
|
+
|
|
75
|
+
#### Implementation of
|
|
76
|
+
|
|
77
|
+
`ISocketRouteProcessor.connected`
|
|
78
|
+
|
|
79
|
+
***
|
|
80
|
+
|
|
81
|
+
### disconnected()
|
|
82
|
+
|
|
83
|
+
> **disconnected**(`request`, `route`, `loggingComponentType?`): `Promise`\<`void`\>
|
|
84
|
+
|
|
85
|
+
Process the disconnected event.
|
|
86
|
+
|
|
87
|
+
#### Parameters
|
|
88
|
+
|
|
89
|
+
##### request
|
|
90
|
+
|
|
91
|
+
`ISocketServerRequest`
|
|
92
|
+
|
|
93
|
+
The server request object containing the socket id and other parameters.
|
|
94
|
+
|
|
95
|
+
##### route
|
|
96
|
+
|
|
97
|
+
The route being requested, if a matching one was found.
|
|
98
|
+
|
|
99
|
+
`undefined` | `ISocketRoute`\<`any`, `any`\>
|
|
100
|
+
|
|
101
|
+
##### loggingComponentType?
|
|
102
|
+
|
|
103
|
+
`string`
|
|
104
|
+
|
|
105
|
+
The logging component type for the request.
|
|
106
|
+
|
|
107
|
+
#### Returns
|
|
108
|
+
|
|
109
|
+
`Promise`\<`void`\>
|
|
110
|
+
|
|
111
|
+
Promise that resolves when the request is processed.
|
|
112
|
+
|
|
113
|
+
#### Implementation of
|
|
114
|
+
|
|
115
|
+
`ISocketRouteProcessor.disconnected`
|
|
116
|
+
|
|
117
|
+
***
|
|
118
|
+
|
|
51
119
|
### process()
|
|
52
120
|
|
|
53
|
-
> **process**(`request`, `response`, `route`, `requestIdentity`, `processorState`, `responseEmitter`): `Promise`\<`void`\>
|
|
121
|
+
> **process**(`request`, `response`, `route`, `requestIdentity`, `processorState`, `responseEmitter`, `loggingComponentType?`): `Promise`\<`void`\>
|
|
54
122
|
|
|
55
123
|
Process the REST request for the specified route.
|
|
56
124
|
|
|
@@ -58,7 +126,7 @@ Process the REST request for the specified route.
|
|
|
58
126
|
|
|
59
127
|
##### request
|
|
60
128
|
|
|
61
|
-
`
|
|
129
|
+
`ISocketServerRequest`
|
|
62
130
|
|
|
63
131
|
The incoming request.
|
|
64
132
|
|
|
@@ -90,6 +158,12 @@ The state handed through the processors.
|
|
|
90
158
|
|
|
91
159
|
The function to emit a response.
|
|
92
160
|
|
|
161
|
+
##### loggingComponentType?
|
|
162
|
+
|
|
163
|
+
`string`
|
|
164
|
+
|
|
165
|
+
The logging component type for the request.
|
|
166
|
+
|
|
93
167
|
#### Returns
|
|
94
168
|
|
|
95
169
|
`Promise`\<`void`\>
|
|
@@ -28,14 +28,6 @@ Options for the processor.
|
|
|
28
28
|
|
|
29
29
|
## Properties
|
|
30
30
|
|
|
31
|
-
### NAMESPACE
|
|
32
|
-
|
|
33
|
-
> `readonly` `static` **NAMESPACE**: `string` = `"static-user-identity"`
|
|
34
|
-
|
|
35
|
-
The namespace supported by the processor.
|
|
36
|
-
|
|
37
|
-
***
|
|
38
|
-
|
|
39
31
|
### CLASS\_NAME
|
|
40
32
|
|
|
41
33
|
> `readonly` **CLASS\_NAME**: `string`
|
package/docs/reference/index.md
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
- [NodeIdentityProcessor](classes/NodeIdentityProcessor.md)
|
|
8
8
|
- [StaticUserIdentityProcessor](classes/StaticUserIdentityProcessor.md)
|
|
9
9
|
- [LoggingProcessor](classes/LoggingProcessor.md)
|
|
10
|
+
- [JsonLdMimeTypeProcessor](classes/JsonLdMimeTypeProcessor.md)
|
|
10
11
|
- [JwtMimeTypeProcessor](classes/JwtMimeTypeProcessor.md)
|
|
11
12
|
|
|
12
13
|
## Interfaces
|
|
@@ -4,20 +4,16 @@ Options for the LoggingProcessor constructor.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
###
|
|
7
|
+
### loggingComponentType?
|
|
8
8
|
|
|
9
|
-
> `optional` **
|
|
9
|
+
> `optional` **loggingComponentType**: `string`
|
|
10
10
|
|
|
11
|
-
The type for the logging
|
|
12
|
-
|
|
13
|
-
#### Default
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
logging
|
|
17
|
-
```
|
|
11
|
+
The type for the logging component.
|
|
18
12
|
|
|
19
13
|
***
|
|
20
14
|
|
|
21
15
|
### config?
|
|
22
16
|
|
|
23
17
|
> `optional` **config**: [`ILoggingProcessorConfig`](ILoggingProcessorConfig.md)
|
|
18
|
+
|
|
19
|
+
The configuration for the logging processor.
|
package/locales/en.json
CHANGED
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
"jwtMissing": "The JSON Web token could not be found in the authorization header or a cookie",
|
|
11
11
|
"jwtSignatureInvalid": "The JSON Web token signature could not be validated",
|
|
12
12
|
"jwtExpired": "The JSON Web token has expired"
|
|
13
|
+
},
|
|
14
|
+
"jsonLdMimeTypeProcessor": {
|
|
15
|
+
"invalidJsonLd": "The JSON-LD content is invalid or missing '@context'."
|
|
13
16
|
}
|
|
14
17
|
}
|
|
15
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/api-processors",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-next.10",
|
|
4
4
|
"description": "Route processors for use with API servers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,13 +14,11 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@twin.org/api-models": "
|
|
18
|
-
"@twin.org/core": "
|
|
19
|
-
"@twin.org/
|
|
20
|
-
"@twin.org/
|
|
21
|
-
"@twin.org/
|
|
22
|
-
"@twin.org/nameof": "^0.0.1",
|
|
23
|
-
"@twin.org/web": "^0.0.1"
|
|
17
|
+
"@twin.org/api-models": "0.0.2-next.10",
|
|
18
|
+
"@twin.org/core": "next",
|
|
19
|
+
"@twin.org/logging-models": "next",
|
|
20
|
+
"@twin.org/nameof": "next",
|
|
21
|
+
"@twin.org/web": "next"
|
|
24
22
|
},
|
|
25
23
|
"main": "./dist/cjs/index.cjs",
|
|
26
24
|
"module": "./dist/esm/index.mjs",
|