@twin.org/api-processors 0.0.2-next.8 → 0.0.3-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/dist/es/data/restRouteProcessor.js +115 -0
  2. package/dist/es/data/restRouteProcessor.js.map +1 -0
  3. package/dist/es/data/socketRouteProcessor.js +126 -0
  4. package/dist/es/data/socketRouteProcessor.js.map +1 -0
  5. package/dist/es/identity/contextIdProcessor.js +68 -0
  6. package/dist/es/identity/contextIdProcessor.js.map +1 -0
  7. package/dist/es/identity/staticContextIdProcessor.js +59 -0
  8. package/dist/es/identity/staticContextIdProcessor.js.map +1 -0
  9. package/dist/es/index.js +19 -0
  10. package/dist/es/index.js.map +1 -0
  11. package/dist/es/logging/loggingProcessor.js +177 -0
  12. package/dist/es/logging/loggingProcessor.js.map +1 -0
  13. package/dist/es/mimeType/jsonLdMimeTypeProcessor.js +38 -0
  14. package/dist/es/mimeType/jsonLdMimeTypeProcessor.js.map +1 -0
  15. package/dist/es/mimeType/jwtMimeTypeProcessor.js +34 -0
  16. package/dist/es/mimeType/jwtMimeTypeProcessor.js.map +1 -0
  17. package/dist/es/models/IContextIdProcessorConfig.js +4 -0
  18. package/dist/es/models/IContextIdProcessorConfig.js.map +1 -0
  19. package/dist/es/models/IContextIdProcessorConstructorOptions.js +2 -0
  20. package/dist/es/models/IContextIdProcessorConstructorOptions.js.map +1 -0
  21. package/dist/es/models/ILoggingProcessorConfig.js +4 -0
  22. package/dist/es/models/ILoggingProcessorConfig.js.map +1 -0
  23. package/dist/es/models/ILoggingProcessorConstructorOptions.js +2 -0
  24. package/dist/es/models/ILoggingProcessorConstructorOptions.js.map +1 -0
  25. package/dist/es/models/IRestRouteProcessorConstructorOptions.js +2 -0
  26. package/dist/es/models/IRestRouteProcessorConstructorOptions.js.map +1 -0
  27. package/dist/es/models/IRouteProcessorConfig.js +4 -0
  28. package/dist/es/models/IRouteProcessorConfig.js.map +1 -0
  29. package/dist/es/models/ISocketRouteProcessorConstructorOptions.js +2 -0
  30. package/dist/es/models/ISocketRouteProcessorConstructorOptions.js.map +1 -0
  31. package/dist/es/models/IStaticContextIdProcessorConfig.js +4 -0
  32. package/dist/es/models/IStaticContextIdProcessorConfig.js.map +1 -0
  33. package/dist/es/models/IStaticContextIdProcessorConstructorOptions.js +2 -0
  34. package/dist/es/models/IStaticContextIdProcessorConstructorOptions.js.map +1 -0
  35. package/dist/types/data/restRouteProcessor.d.ts +9 -5
  36. package/dist/types/data/socketRouteProcessor.d.ts +10 -6
  37. package/dist/types/identity/contextIdProcessor.d.ts +39 -0
  38. package/dist/types/identity/staticContextIdProcessor.d.ts +33 -0
  39. package/dist/types/index.d.ts +16 -14
  40. package/dist/types/logging/loggingProcessor.d.ts +13 -7
  41. package/dist/types/mimeType/jsonLdMimeTypeProcessor.d.ts +6 -1
  42. package/dist/types/mimeType/jwtMimeTypeProcessor.d.ts +6 -1
  43. package/dist/types/models/IContextIdProcessorConfig.d.ts +13 -0
  44. package/dist/types/models/IContextIdProcessorConstructorOptions.d.ts +10 -0
  45. package/dist/types/models/ILoggingProcessorConstructorOptions.d.ts +1 -1
  46. package/dist/types/models/IRestRouteProcessorConstructorOptions.d.ts +1 -1
  47. package/dist/types/models/ISocketRouteProcessorConstructorOptions.d.ts +1 -1
  48. package/dist/types/models/IStaticContextIdProcessorConfig.d.ts +17 -0
  49. package/dist/types/models/IStaticContextIdProcessorConstructorOptions.d.ts +10 -0
  50. package/docs/changelog.md +96 -0
  51. package/docs/reference/classes/{NodeIdentityProcessor.md → ContextIdProcessor.md} +37 -19
  52. package/docs/reference/classes/JsonLdMimeTypeProcessor.md +17 -3
  53. package/docs/reference/classes/JwtMimeTypeProcessor.md +17 -3
  54. package/docs/reference/classes/LoggingProcessor.md +27 -13
  55. package/docs/reference/classes/RestRouteProcessor.md +19 -11
  56. package/docs/reference/classes/SocketRouteProcessor.md +22 -14
  57. package/docs/reference/classes/StaticContextIdProcessor.md +99 -0
  58. package/docs/reference/index.md +6 -4
  59. package/docs/reference/interfaces/IContextIdProcessorConfig.md +19 -0
  60. package/docs/reference/interfaces/IContextIdProcessorConstructorOptions.md +11 -0
  61. package/docs/reference/interfaces/IStaticContextIdProcessorConfig.md +27 -0
  62. package/docs/reference/interfaces/IStaticContextIdProcessorConstructorOptions.md +11 -0
  63. package/locales/en.json +0 -5
  64. package/package.json +20 -9
  65. package/dist/cjs/index.cjs +0 -527
  66. package/dist/esm/index.mjs +0 -519
  67. package/dist/types/identity/nodeIdentityProcessor.d.ts +0 -28
  68. package/dist/types/identity/staticUserIdentityProcessor.d.ts +0 -27
  69. package/dist/types/models/IStaticUserIdentityProcessorConfig.d.ts +0 -9
  70. package/dist/types/models/IStaticUserIdentityProcessorConstructorOptions.d.ts +0 -10
  71. package/docs/reference/classes/StaticUserIdentityProcessor.md +0 -85
  72. package/docs/reference/interfaces/IStaticUserIdentityProcessorConfig.md +0 -11
  73. package/docs/reference/interfaces/IStaticUserIdentityProcessorConstructorOptions.md +0 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/api-processors",
3
- "version": "0.0.2-next.8",
3
+ "version": "0.0.3-next.1",
4
4
  "description": "Route processors for use with API servers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,27 +14,38 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/api-models": "0.0.2-next.8",
17
+ "@twin.org/api-models": "0.0.3-next.1",
18
+ "@twin.org/context": "next",
18
19
  "@twin.org/core": "next",
19
20
  "@twin.org/logging-models": "next",
20
21
  "@twin.org/nameof": "next",
21
22
  "@twin.org/web": "next"
22
23
  },
23
- "main": "./dist/cjs/index.cjs",
24
- "module": "./dist/esm/index.mjs",
24
+ "main": "./dist/es/index.js",
25
25
  "types": "./dist/types/index.d.ts",
26
26
  "exports": {
27
27
  ".": {
28
28
  "types": "./dist/types/index.d.ts",
29
- "require": "./dist/cjs/index.cjs",
30
- "import": "./dist/esm/index.mjs"
29
+ "import": "./dist/es/index.js",
30
+ "default": "./dist/es/index.js"
31
31
  }
32
32
  },
33
33
  "files": [
34
- "dist/cjs",
35
- "dist/esm",
34
+ "dist/es",
36
35
  "dist/types",
37
36
  "locales",
38
37
  "docs"
39
- ]
38
+ ],
39
+ "keywords": [
40
+ "twin",
41
+ "trade",
42
+ "iota",
43
+ "framework",
44
+ "blockchain",
45
+ "api"
46
+ ],
47
+ "bugs": {
48
+ "url": "git+https://github.com/twinfoundation/api/issues"
49
+ },
50
+ "homepage": "https://twindev.org"
40
51
  }
@@ -1,527 +0,0 @@
1
- 'use strict';
2
-
3
- var apiModels = require('@twin.org/api-models');
4
- var core = require('@twin.org/core');
5
- var web = require('@twin.org/web');
6
-
7
- // Copyright 2024 IOTA Stiftung.
8
- // SPDX-License-Identifier: Apache-2.0.
9
- /**
10
- * Process the REST request and hands it on to the route handler.
11
- */
12
- class RestRouteProcessor {
13
- /**
14
- * Runtime name for the class.
15
- */
16
- CLASS_NAME = "RestRouteProcessor";
17
- /**
18
- * Include the stack with errors.
19
- * @internal
20
- */
21
- _includeErrorStack;
22
- /**
23
- * Create a new instance of RouteProcessor.
24
- * @param options Options for the processor.
25
- */
26
- constructor(options) {
27
- this._includeErrorStack = options?.config?.includeErrorStack ?? false;
28
- }
29
- /**
30
- * Process the REST request for the specified route.
31
- * @param request The incoming request.
32
- * @param response The outgoing response.
33
- * @param route The route to process.
34
- * @param requestIdentity The identity context for the request.
35
- * @param processorState The state handed through the processors.
36
- * @param loggingComponentType The logging component type for the request.
37
- */
38
- async process(request, response, route, requestIdentity, processorState, loggingComponentType) {
39
- // Don't handle the route if another processor has already set the response
40
- // status code e.g. from an auth processor
41
- if (core.Is.empty(response.statusCode)) {
42
- if (core.Is.empty(route)) {
43
- apiModels.HttpErrorHelper.buildResponse(response, {
44
- name: core.NotFoundError.CLASS_NAME,
45
- message: `${this.CLASS_NAME}.routeNotFound`,
46
- properties: {
47
- notFoundId: request.url
48
- }
49
- }, web.HttpStatusCode.notFound);
50
- }
51
- else {
52
- try {
53
- const req = {
54
- pathParams: request.pathParams,
55
- query: request.query,
56
- body: request.body
57
- };
58
- const restRouteResponse = await route.handler({
59
- ...requestIdentity,
60
- serverRequest: request,
61
- processorState,
62
- loggingComponentType
63
- }, req);
64
- let statusCode = restRouteResponse.statusCode ?? response.statusCode ?? web.HttpStatusCode.ok;
65
- const headers = restRouteResponse?.headers ?? {};
66
- if (core.Is.empty(restRouteResponse?.body)) {
67
- // If there is no custom status code and the body is empty
68
- // use the no content response and set the length to 0
69
- headers[web.HeaderTypes.ContentLength] = "0";
70
- // Only change to no content if the status code is ok
71
- // This could be something like a created status code
72
- // which is successful but has no content
73
- if (statusCode === web.HttpStatusCode.ok) {
74
- statusCode = web.HttpStatusCode.noContent;
75
- }
76
- }
77
- else {
78
- // Only set the content type if there is a body
79
- // If there are custom response types for the route then use them
80
- // instead of the default application/json
81
- headers[web.HeaderTypes.ContentType] =
82
- restRouteResponse?.attachment?.mimeType ??
83
- restRouteResponse.headers?.[web.HeaderTypes.ContentType] ??
84
- `${web.MimeTypes.Json}; charset=utf-8`;
85
- // If there are filename or inline options set then add the content disposition
86
- if (core.Is.stringValue(restRouteResponse?.attachment?.filename) ||
87
- core.Is.boolean(restRouteResponse?.attachment?.inline)) {
88
- let filename = "";
89
- if (core.Is.stringValue(restRouteResponse?.attachment?.filename)) {
90
- filename = `; filename="${restRouteResponse?.attachment?.filename}"`;
91
- }
92
- headers[web.HeaderTypes.ContentDisposition] =
93
- `${restRouteResponse?.attachment?.inline ? "inline" : "attachment"}${filename}`;
94
- }
95
- // If this is a binary response then set the content length
96
- if (core.Is.uint8Array(restRouteResponse?.body)) {
97
- const contentLength = restRouteResponse.body.length;
98
- headers[web.HeaderTypes.ContentLength] = contentLength.toString();
99
- }
100
- response.body = restRouteResponse?.body;
101
- }
102
- response.headers = headers;
103
- response.statusCode = statusCode;
104
- }
105
- catch (err) {
106
- const { error, httpStatusCode } = apiModels.HttpErrorHelper.processError(err, this._includeErrorStack);
107
- apiModels.HttpErrorHelper.buildResponse(response, error, httpStatusCode);
108
- }
109
- }
110
- }
111
- }
112
- }
113
-
114
- // Copyright 2024 IOTA Stiftung.
115
- // SPDX-License-Identifier: Apache-2.0.
116
- /**
117
- * Process the socket request and hands it on to the route handler.
118
- */
119
- class SocketRouteProcessor {
120
- /**
121
- * Runtime name for the class.
122
- */
123
- CLASS_NAME = "SocketRouteProcessor";
124
- /**
125
- * Include the stack with errors.
126
- * @internal
127
- */
128
- _includeErrorStack;
129
- /**
130
- * Create a new instance of SocketRouteProcessor.
131
- * @param options Options for the processor.
132
- */
133
- constructor(options) {
134
- this._includeErrorStack = options?.config?.includeErrorStack ?? false;
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
- }
178
- /**
179
- * Process the REST request for the specified route.
180
- * @param request The incoming request.
181
- * @param response The outgoing response.
182
- * @param route The route to process.
183
- * @param requestIdentity The identity context for the request.
184
- * @param processorState The state handed through the processors.
185
- * @param responseEmitter The function to emit a response.
186
- * @param loggingComponentType The logging component type for the request.
187
- */
188
- async process(request, response, route, requestIdentity, processorState, responseEmitter, loggingComponentType) {
189
- // Don't handle the route if another processor has already set the response
190
- // status code e.g. from an auth processor
191
- if (core.Is.empty(response.statusCode)) {
192
- if (core.Is.empty(route)) {
193
- apiModels.HttpErrorHelper.buildResponse(response, {
194
- name: core.NotFoundError.CLASS_NAME,
195
- message: `${this.CLASS_NAME}.routeNotFound`,
196
- properties: {
197
- notFoundId: request.url
198
- }
199
- }, web.HttpStatusCode.notFound);
200
- }
201
- else {
202
- try {
203
- const req = {
204
- pathParams: request.pathParams,
205
- query: request.query,
206
- body: request.body
207
- };
208
- const socketRequestContext = {
209
- ...requestIdentity,
210
- socketId: request.socketId,
211
- serverRequest: request,
212
- processorState,
213
- loggingComponentType
214
- };
215
- await route.handler(socketRequestContext, req, async (topic, restRouteResponse) => {
216
- response.headers = restRouteResponse?.headers;
217
- response.body = restRouteResponse?.body;
218
- response.statusCode =
219
- restRouteResponse.statusCode ?? response.statusCode ?? web.HttpStatusCode.ok;
220
- await responseEmitter(topic, response);
221
- });
222
- }
223
- catch (err) {
224
- const { error, httpStatusCode } = apiModels.HttpErrorHelper.processError(err, this._includeErrorStack);
225
- apiModels.HttpErrorHelper.buildResponse(response, error, httpStatusCode);
226
- }
227
- }
228
- }
229
- }
230
- }
231
-
232
- /**
233
- * Adds a node identity to the request identity.
234
- */
235
- class NodeIdentityProcessor {
236
- /**
237
- * Runtime name for the class.
238
- */
239
- CLASS_NAME = "NodeIdentityProcessor";
240
- /**
241
- * The node identity for request context.
242
- * @internal
243
- */
244
- _nodeIdentity;
245
- /**
246
- * The service needs to be started when the application is initialized.
247
- * @param nodeIdentity The identity of the node.
248
- * @param nodeLoggingComponentType The node logging component type.
249
- * @returns Nothing.
250
- */
251
- async start(nodeIdentity, nodeLoggingComponentType) {
252
- core.Guards.string(this.CLASS_NAME, "nodeIdentity", nodeIdentity);
253
- this._nodeIdentity = nodeIdentity;
254
- }
255
- /**
256
- * Pre process the REST request for the specified route.
257
- * @param request The incoming request.
258
- * @param response The outgoing response.
259
- * @param route The route to process.
260
- * @param requestIdentity The identity context for the request.
261
- * @param processorState The state handed through the processors.
262
- */
263
- async pre(request, response, route, requestIdentity, processorState) {
264
- requestIdentity.nodeIdentity = this._nodeIdentity;
265
- }
266
- }
267
-
268
- /**
269
- * Adds a static user identity to the request context.
270
- */
271
- class StaticUserIdentityProcessor {
272
- /**
273
- * Runtime name for the class.
274
- */
275
- CLASS_NAME = "StaticUserIdentityProcessor";
276
- /**
277
- * The fixed identity for request context.
278
- * @internal
279
- */
280
- _userIdentity;
281
- /**
282
- * Create a new instance of StaticIdentityProcessor.
283
- * @param options Options for the processor.
284
- */
285
- constructor(options) {
286
- core.Guards.object(this.CLASS_NAME, "options", options);
287
- core.Guards.object(this.CLASS_NAME, "options.config", options.config);
288
- core.Guards.stringValue(this.CLASS_NAME, "options.config.userIdentity", options.config.userIdentity);
289
- this._userIdentity = options.config.userIdentity;
290
- }
291
- /**
292
- * Pre process the REST request for the specified route.
293
- * @param request The incoming request.
294
- * @param response The outgoing response.
295
- * @param route The route to process.
296
- * @param requestIdentity The identity context for the request.
297
- * @param processorState The state handed through the processors.
298
- */
299
- async pre(request, response, route, requestIdentity, processorState) {
300
- if (!core.Is.empty(route) && !(route.skipAuth ?? false)) {
301
- requestIdentity.userIdentity = this._userIdentity;
302
- }
303
- }
304
- }
305
-
306
- /**
307
- * Process the REST request and log its information.
308
- */
309
- class LoggingProcessor {
310
- /**
311
- * Runtime name for the class.
312
- */
313
- CLASS_NAME = "LoggingProcessor";
314
- /**
315
- * The component for logging the information.
316
- * @internal
317
- */
318
- _logging;
319
- /**
320
- * Include the body objects when logging the information.
321
- * @internal
322
- */
323
- _includeBody;
324
- /**
325
- * Show the full base64 content for data, default to abbreviate.
326
- * @internal
327
- */
328
- _fullBase64;
329
- /**
330
- * List of property names to obfuscate, defaults to "password".
331
- * @internal
332
- */
333
- _obfuscateProperties;
334
- /**
335
- * Create a new instance of LoggingProcessor.
336
- * @param options Options for the processor.
337
- */
338
- constructor(options) {
339
- this._logging = core.ComponentFactory.getIfExists(options?.loggingComponentType ?? "logging");
340
- this._includeBody = options?.config?.includeBody ?? false;
341
- this._fullBase64 = options?.config?.fullBase64 ?? false;
342
- this._obfuscateProperties = options?.config?.obfuscateProperties ?? ["password"];
343
- }
344
- /**
345
- * Pre process the REST request for the specified route.
346
- * @param request The incoming request.
347
- * @param response The outgoing response.
348
- * @param route The route to process.
349
- * @param requestIdentity The identity context for the request.
350
- * @param processorState The state handed through the processors.
351
- */
352
- async pre(request, response, route, requestIdentity, processorState) {
353
- const now = process.hrtime.bigint();
354
- processorState.requestStart = now;
355
- const contentType = request.headers?.[web.HeaderTypes.ContentType];
356
- const isJson = core.Is.stringValue(contentType)
357
- ? contentType.includes(web.MimeTypes.Json) || contentType.includes(web.MimeTypes.JsonLd)
358
- : false;
359
- let requestUrl = "";
360
- if (core.Is.stringValue(request.url)) {
361
- // Socket paths do not have a prefix so just use the whole url.
362
- if (request.url.startsWith("http")) {
363
- requestUrl = new URL(request.url).pathname;
364
- }
365
- else {
366
- requestUrl = request.url;
367
- }
368
- }
369
- await this._logging?.log({
370
- level: "info",
371
- source: this.CLASS_NAME,
372
- ts: Date.now(),
373
- message: `===> ${request.method} ${requestUrl}`,
374
- data: this._includeBody && isJson
375
- ? this.processJson("body", core.ObjectHelper.clone(request?.body))
376
- : undefined
377
- });
378
- }
379
- /**
380
- * Post process the REST request for the specified route.
381
- * @param request The incoming request.
382
- * @param response The outgoing response.
383
- * @param route The route to process.
384
- * @param requestIdentity The identity context for the request.
385
- * @param processorState The state handed through the processors.
386
- */
387
- async post(request, response, route, requestIdentity, processorState) {
388
- let data;
389
- if (this._includeBody) {
390
- const contentType = response.headers?.[web.HeaderTypes.ContentType];
391
- const isJson = core.Is.stringValue(contentType)
392
- ? contentType.includes(web.MimeTypes.Json) || contentType.includes(web.MimeTypes.JsonLd)
393
- : false;
394
- const contentLength = response.headers?.[web.HeaderTypes.ContentLength];
395
- if (isJson) {
396
- data = {
397
- body: this.processJson("body", core.ObjectHelper.clone(response.body))
398
- };
399
- }
400
- else {
401
- const dataParts = {};
402
- if (core.Is.stringValue(contentType)) {
403
- dataParts["Content Type"] = contentType;
404
- }
405
- if (core.Is.stringValue(contentLength)) {
406
- dataParts["Content Length"] = contentLength;
407
- }
408
- if (Object.keys(dataParts).length > 0) {
409
- data = {
410
- headers: dataParts
411
- };
412
- }
413
- }
414
- }
415
- const now = process.hrtime.bigint();
416
- const start = core.Coerce.bigint(processorState.requestStart) ?? now;
417
- const elapsed = now - start;
418
- const elapsedMicroSeconds = Math.floor(Number(elapsed) / 1000);
419
- let requestUrl = "";
420
- if (core.Is.stringValue(request.url)) {
421
- // Socket paths do not have a prefix so just use the whole url.
422
- if (request.url.startsWith("http")) {
423
- requestUrl = new URL(request.url).pathname;
424
- }
425
- else {
426
- requestUrl = request.url;
427
- }
428
- }
429
- await this._logging?.log({
430
- level: core.Is.number(response.statusCode) && response.statusCode >= web.HttpStatusCode.badRequest
431
- ? "error"
432
- : "info",
433
- source: this.CLASS_NAME,
434
- ts: Date.now(),
435
- message: `<=== ${response.statusCode ?? ""} ${request.method} ${requestUrl} duration: ${elapsedMicroSeconds}µs`,
436
- data
437
- });
438
- }
439
- /**
440
- * Process the JSON.
441
- * @param propValue The property to process.
442
- * @returns The processed property.
443
- * @internal
444
- */
445
- processJson(propName, propValue) {
446
- if (core.Is.array(propValue)) {
447
- for (let i = 0; i < propValue.length; i++) {
448
- propValue[i] = this.processJson(`${i}`, propValue[i]);
449
- }
450
- }
451
- else if (core.Is.object(propValue)) {
452
- for (const key of Object.keys(propValue)) {
453
- propValue[key] = this.processJson(key, propValue[key]);
454
- }
455
- }
456
- else if (!this._fullBase64 && core.Is.stringBase64(propValue) && propValue.length > 256) {
457
- propValue = "<base64>";
458
- }
459
- else if (core.Is.string(propValue) &&
460
- this._obfuscateProperties.some(op => new RegExp(op).test(propName))) {
461
- propValue = "**************";
462
- }
463
- return propValue;
464
- }
465
- }
466
-
467
- /**
468
- * Process the JSON-LD mime type.
469
- */
470
- class JsonLdMimeTypeProcessor {
471
- /**
472
- * Runtime name for the class.
473
- */
474
- CLASS_NAME = "JsonLdMimeTypeProcessor";
475
- /**
476
- * Get the MIME types that this handler can handle.
477
- * @returns The MIME types that this handler can handle.
478
- */
479
- getTypes() {
480
- return [web.MimeTypes.JsonLd];
481
- }
482
- /**
483
- * Handle content.
484
- * @param body The body to process.
485
- * @returns The processed body.
486
- */
487
- async handle(body) {
488
- const json = core.ObjectHelper.fromBytes(body);
489
- if (core.Is.empty(json) || core.Is.empty(json["@context"])) {
490
- throw new core.GeneralError(this.CLASS_NAME, "invalidJsonLd");
491
- }
492
- return json;
493
- }
494
- }
495
-
496
- /**
497
- * Process the JWT mime type.
498
- */
499
- class JwtMimeTypeProcessor {
500
- /**
501
- * Runtime name for the class.
502
- */
503
- CLASS_NAME = "JwtMimeTypeProcessor";
504
- /**
505
- * Get the MIME types that this handler can handle.
506
- * @returns The MIME types that this handler can handle.
507
- */
508
- getTypes() {
509
- return [web.MimeTypes.Jwt];
510
- }
511
- /**
512
- * Handle content.
513
- * @param body The body to process.
514
- * @returns The processed body.
515
- */
516
- async handle(body) {
517
- return core.Converter.bytesToUtf8(body);
518
- }
519
- }
520
-
521
- exports.JsonLdMimeTypeProcessor = JsonLdMimeTypeProcessor;
522
- exports.JwtMimeTypeProcessor = JwtMimeTypeProcessor;
523
- exports.LoggingProcessor = LoggingProcessor;
524
- exports.NodeIdentityProcessor = NodeIdentityProcessor;
525
- exports.RestRouteProcessor = RestRouteProcessor;
526
- exports.SocketRouteProcessor = SocketRouteProcessor;
527
- exports.StaticUserIdentityProcessor = StaticUserIdentityProcessor;