@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loggingProcessor.js","sourceRoot":"","sources":["../../../src/logging/loggingProcessor.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG5E,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGvE;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC5B;;OAEG;IACI,MAAM,CAAU,UAAU,sBAAsC;IAEvE;;;OAGG;IACc,QAAQ,CAAqB;IAE9C;;;OAGG;IACc,YAAY,CAAU;IAEvC;;;OAGG;IACc,WAAW,CAAU;IAEtC;;;OAGG;IACc,oBAAoB,CAAW;IAEhD;;;OAGG;IACH,YAAY,OAA6C;QACxD,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,WAAW,CAAC,OAAO,EAAE,oB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AQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC;YAChF,CAAC,CAAC,KAAK,CAAC;IACV,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIBaseRoute,\n\tIBaseRouteProcessor,\n\tIHttpResponse,\n\tIHttpServerRequest\n} from \"@twin.org/api-models\";\nimport type { IContextIds } from \"@twin.org/context\";\nimport { Coerce, ComponentFactory, Is, ObjectHelper } from \"@twin.org/core\";\nimport type { ILoggingComponent } from \"@twin.org/logging-models\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@twin.org/web\";\nimport type { ILoggingProcessorConstructorOptions } from \"../models/ILoggingProcessorConstructorOptions.js\";\n\n/**\n * Process the REST request and log its information.\n */\nexport class LoggingProcessor implements IBaseRouteProcessor {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<LoggingProcessor>();\n\n\t/**\n\t * The component for logging the information.\n\t * @internal\n\t */\n\tprivate readonly _logging?: ILoggingComponent;\n\n\t/**\n\t * Include the body objects when logging the information.\n\t * @internal\n\t */\n\tprivate readonly _includeBody: boolean;\n\n\t/**\n\t * Show the full base64 content for data, default to abbreviate.\n\t * @internal\n\t */\n\tprivate readonly _fullBase64: boolean;\n\n\t/**\n\t * List of property names to obfuscate, defaults to \"password\".\n\t * @internal\n\t */\n\tprivate readonly _obfuscateProperties: string[];\n\n\t/**\n\t * Create a new instance of LoggingProcessor.\n\t * @param options Options for the processor.\n\t */\n\tconstructor(options?: ILoggingProcessorConstructorOptions) {\n\t\tthis._logging = ComponentFactory.getIfExists(options?.loggingComponentType ?? \"logging\");\n\t\tthis._includeBody = options?.config?.includeBody ?? false;\n\t\tthis._fullBase64 = options?.config?.fullBase64 ?? false;\n\t\tthis._obfuscateProperties = options?.config?.obfuscateProperties ?? [\"password\"];\n\t}\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn LoggingProcessor.CLASS_NAME;\n\t}\n\n\t/**\n\t * Pre process the REST request for the specified route.\n\t * @param request The incoming request.\n\t * @param response The outgoing response.\n\t * @param route The route to process.\n\t * @param contextIds The context IDs of the request.\n\t * @param processorState The state handed through the processors.\n\t */\n\tpublic async pre(\n\t\trequest: IHttpServerRequest,\n\t\tresponse: IHttpResponse,\n\t\troute: IBaseRoute | undefined,\n\t\tcontextIds: IContextIds,\n\t\tprocessorState: { [id: string]: unknown }\n\t): Promise<void> {\n\t\tconst now = process.hrtime.bigint();\n\t\tprocessorState.requestStart = now;\n\n\t\tconst contentType = request.headers?.[HeaderTypes.ContentType];\n\t\tconst isJson = this.isMimeJson(contentType);\n\n\t\tlet requestUrl = \"\";\n\t\tif (Is.stringValue(request.url)) {\n\t\t\t// Socket paths do not have a prefix so just use the whole url.\n\t\t\tif (request.url.startsWith(\"http\")) {\n\t\t\t\trequestUrl = new URL(request.url).pathname;\n\t\t\t} else {\n\t\t\t\trequestUrl = request.url;\n\t\t\t}\n\t\t}\n\n\t\tawait this._logging?.log({\n\t\t\tlevel: \"info\",\n\t\t\tsource: LoggingProcessor.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: `===> ${request.method} ${requestUrl}`,\n\t\t\tdata:\n\t\t\t\tthis._includeBody && isJson\n\t\t\t\t\t? (this.processJson(\"body\", ObjectHelper.clone(request?.body)) as {\n\t\t\t\t\t\t\t[key: string]: unknown;\n\t\t\t\t\t\t})\n\t\t\t\t\t: undefined\n\t\t});\n\t}\n\n\t/**\n\t * Post process the REST request for the specified route.\n\t * @param request The incoming request.\n\t * @param response The outgoing response.\n\t * @param route The route to process.\n\t * @param contextIds The context IDs of the request.\n\t * @param processorState The state handed through the processors.\n\t */\n\tpublic async post(\n\t\trequest: IHttpServerRequest,\n\t\tresponse: IHttpResponse,\n\t\troute: IBaseRoute | undefined,\n\t\tcontextIds: IContextIds,\n\t\tprocessorState: { [id: string]: unknown }\n\t): Promise<void> {\n\t\tlet data: { [id: string]: unknown } | undefined;\n\t\tif (this._includeBody) {\n\t\t\tconst contentType = response.headers?.[HeaderTypes.ContentType];\n\t\t\tconst isJson = this.isMimeJson(contentType);\n\t\t\tconst contentLength = response.headers?.[HeaderTypes.ContentLength];\n\t\t\tif (isJson) {\n\t\t\t\tdata = {\n\t\t\t\t\tbody: this.processJson(\"body\", ObjectHelper.clone(response.body))\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\tconst dataParts: { [id: string]: string } = {};\n\t\t\t\tif (Is.stringValue(contentType)) {\n\t\t\t\t\tdataParts[\"Content Type\"] = contentType;\n\t\t\t\t}\n\t\t\t\tif (Is.stringValue(contentLength)) {\n\t\t\t\t\tdataParts[\"Content Length\"] = contentLength;\n\t\t\t\t}\n\t\t\t\tif (Object.keys(dataParts).length > 0) {\n\t\t\t\t\tdata = {\n\t\t\t\t\t\theaders: dataParts\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tconst now = process.hrtime.bigint();\n\t\tconst start = Coerce.bigint(processorState.requestStart) ?? now;\n\t\tconst elapsed = now - start;\n\t\tconst elapsedMicroSeconds = Math.floor(Number(elapsed) / 1000);\n\n\t\tlet requestUrl = \"\";\n\t\tif (Is.stringValue(request.url)) {\n\t\t\t// Socket paths do not have a prefix so just use the whole url.\n\t\t\tif (request.url.startsWith(\"http\")) {\n\t\t\t\trequestUrl = new URL(request.url).pathname;\n\t\t\t} else {\n\t\t\t\trequestUrl = request.url;\n\t\t\t}\n\t\t}\n\n\t\tawait this._logging?.log({\n\t\t\tlevel:\n\t\t\t\tIs.number(response.statusCode) && response.statusCode >= HttpStatusCode.badRequest\n\t\t\t\t\t? \"error\"\n\t\t\t\t\t: \"info\",\n\t\t\tsource: LoggingProcessor.CLASS_NAME,\n\t\t\tts: Date.now(),\n\t\t\tmessage: `<=== ${response.statusCode ?? \"\"} ${request.method} ${requestUrl} duration: ${elapsedMicroSeconds}µs`,\n\t\t\tdata\n\t\t});\n\t}\n\n\t/**\n\t * Process the JSON.\n\t * @param propValue The property to process.\n\t * @returns The processed property.\n\t * @internal\n\t */\n\tprivate processJson(propName: string, propValue: unknown): unknown {\n\t\tif (Is.array(propValue)) {\n\t\t\tfor (let i = 0; i < propValue.length; i++) {\n\t\t\t\tpropValue[i] = this.processJson(`${i}`, propValue[i]);\n\t\t\t}\n\t\t} else if (Is.object(propValue)) {\n\t\t\tfor (const key of Object.keys(propValue)) {\n\t\t\t\tpropValue[key] = this.processJson(key, propValue[key]);\n\t\t\t}\n\t\t} else if (!this._fullBase64 && Is.stringBase64(propValue) && propValue.length > 256) {\n\t\t\tpropValue = \"<base64>\";\n\t\t} else if (\n\t\t\tIs.string(propValue) &&\n\t\t\tthis._obfuscateProperties.some(op => new RegExp(op).test(propName))\n\t\t) {\n\t\t\tpropValue = \"**************\";\n\t\t}\n\n\t\treturn propValue;\n\t}\n\n\t/**\n\t * Check if the content type is JSON.\n\t * @param contentType The content type to check.\n\t * @returns True if the content type is JSON, false otherwise.\n\t * @internal\n\t */\n\tprivate isMimeJson(contentType: string | string[] | undefined): boolean {\n\t\treturn Is.stringValue(contentType)\n\t\t\t? contentType.includes(MimeTypes.Json) || contentType.includes(MimeTypes.JsonLd)\n\t\t\t: false;\n\t}\n}\n"]}
@@ -0,0 +1,38 @@
1
+ import { GeneralError, Is, ObjectHelper } from "@twin.org/core";
2
+ import { MimeTypes } from "@twin.org/web";
3
+ /**
4
+ * Process the JSON-LD mime type.
5
+ */
6
+ export class JsonLdMimeTypeProcessor {
7
+ /**
8
+ * Runtime name for the class.
9
+ */
10
+ static CLASS_NAME = "JsonLdMimeTypeProcessor";
11
+ /**
12
+ * Returns the class name of the component.
13
+ * @returns The class name of the component.
14
+ */
15
+ className() {
16
+ return JsonLdMimeTypeProcessor.CLASS_NAME;
17
+ }
18
+ /**
19
+ * Get the MIME types that this handler can handle.
20
+ * @returns The MIME types that this handler can handle.
21
+ */
22
+ getTypes() {
23
+ return [MimeTypes.JsonLd];
24
+ }
25
+ /**
26
+ * Handle content.
27
+ * @param body The body to process.
28
+ * @returns The processed body.
29
+ */
30
+ async handle(body) {
31
+ const json = ObjectHelper.fromBytes(body);
32
+ if (Is.empty(json) || Is.empty(json["@context"])) {
33
+ throw new GeneralError(JsonLdMimeTypeProcessor.CLASS_NAME, "invalidJsonLd");
34
+ }
35
+ return json;
36
+ }
37
+ }
38
+ //# sourceMappingURL=jsonLdMimeTypeProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsonLdMimeTypeProcessor.js","sourceRoot":"","sources":["../../../src/mimeType/jsonLdMimeTypeProcessor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C;;GAEG;AACH,MAAM,OAAO,uBAAuB;IACnC;;OAEG;IACI,MAAM,CAAU,UAAU,6BAA6C;IAE9E;;;OAGG;IACI,SAAS;QACf,OAAO,uBAAuB,CAAC,UAAU,CAAC;IAC3C,CAAC;IAED;;;OAGG;IACI,QAAQ;QACd,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,MAAM,CAAC,IAAgB;QACnC,MAAM,IAAI,GAAG,YAAY,CAAC,SAAS,CAA0B,IAAI,CAAC,CAAC;QAEnE,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;YAClD,MAAM,IAAI,YAAY,CAAC,uBAAuB,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;QAC7E,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IMimeTypeProcessor } from \"@twin.org/api-models\";\nimport { GeneralError, Is, ObjectHelper } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { MimeTypes } from \"@twin.org/web\";\n\n/**\n * Process the JSON-LD mime type.\n */\nexport class JsonLdMimeTypeProcessor implements IMimeTypeProcessor {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<JsonLdMimeTypeProcessor>();\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn JsonLdMimeTypeProcessor.CLASS_NAME;\n\t}\n\n\t/**\n\t * Get the MIME types that this handler can handle.\n\t * @returns The MIME types that this handler can handle.\n\t */\n\tpublic getTypes(): string[] {\n\t\treturn [MimeTypes.JsonLd];\n\t}\n\n\t/**\n\t * Handle content.\n\t * @param body The body to process.\n\t * @returns The processed body.\n\t */\n\tpublic async handle(body: Uint8Array): Promise<unknown> {\n\t\tconst json = ObjectHelper.fromBytes<{ \"@context\"?: string }>(body);\n\n\t\tif (Is.empty(json) || Is.empty(json[\"@context\"])) {\n\t\t\tthrow new GeneralError(JsonLdMimeTypeProcessor.CLASS_NAME, \"invalidJsonLd\");\n\t\t}\n\n\t\treturn json;\n\t}\n}\n"]}
@@ -0,0 +1,34 @@
1
+ import { Converter } from "@twin.org/core";
2
+ import { MimeTypes } from "@twin.org/web";
3
+ /**
4
+ * Process the JWT mime type.
5
+ */
6
+ export class JwtMimeTypeProcessor {
7
+ /**
8
+ * Runtime name for the class.
9
+ */
10
+ static CLASS_NAME = "JwtMimeTypeProcessor";
11
+ /**
12
+ * Returns the class name of the component.
13
+ * @returns The class name of the component.
14
+ */
15
+ className() {
16
+ return JwtMimeTypeProcessor.CLASS_NAME;
17
+ }
18
+ /**
19
+ * Get the MIME types that this handler can handle.
20
+ * @returns The MIME types that this handler can handle.
21
+ */
22
+ getTypes() {
23
+ return [MimeTypes.Jwt];
24
+ }
25
+ /**
26
+ * Handle content.
27
+ * @param body The body to process.
28
+ * @returns The processed body.
29
+ */
30
+ async handle(body) {
31
+ return Converter.bytesToUtf8(body);
32
+ }
33
+ }
34
+ //# sourceMappingURL=jwtMimeTypeProcessor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwtMimeTypeProcessor.js","sourceRoot":"","sources":["../../../src/mimeType/jwtMimeTypeProcessor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE1C;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAChC;;OAEG;IACI,MAAM,CAAU,UAAU,0BAA0C;IAE3E;;;OAGG;IACI,SAAS;QACf,OAAO,oBAAoB,CAAC,UAAU,CAAC;IACxC,CAAC;IAED;;;OAGG;IACI,QAAQ;QACd,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,MAAM,CAAC,IAAgB;QACnC,OAAO,SAAS,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IMimeTypeProcessor } from \"@twin.org/api-models\";\nimport { Converter } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { MimeTypes } from \"@twin.org/web\";\n\n/**\n * Process the JWT mime type.\n */\nexport class JwtMimeTypeProcessor implements IMimeTypeProcessor {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<JwtMimeTypeProcessor>();\n\n\t/**\n\t * Returns the class name of the component.\n\t * @returns The class name of the component.\n\t */\n\tpublic className(): string {\n\t\treturn JwtMimeTypeProcessor.CLASS_NAME;\n\t}\n\n\t/**\n\t * Get the MIME types that this handler can handle.\n\t * @returns The MIME types that this handler can handle.\n\t */\n\tpublic getTypes(): string[] {\n\t\treturn [MimeTypes.Jwt];\n\t}\n\n\t/**\n\t * Handle content.\n\t * @param body The body to process.\n\t * @returns The processed body.\n\t */\n\tpublic async handle(body: Uint8Array): Promise<unknown> {\n\t\treturn Converter.bytesToUtf8(body);\n\t}\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IContextIdProcessorConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IContextIdProcessorConfig.js","sourceRoot":"","sources":["../../../src/models/IContextIdProcessorConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the context id processor.\n */\nexport interface IContextIdProcessorConfig {\n\t/**\n\t * The fixed identity key for request context.\n\t */\n\tkey: string;\n\n\t/**\n\t * Only add the identity if the request is authenticated.\n\t */\n\tauthOnly?: boolean;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IContextIdProcessorConstructorOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IContextIdProcessorConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IContextIdProcessorConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IContextIdProcessorConfig } from \"./IContextIdProcessorConfig.js\";\n\n/**\n * Options for the ContextIdProcessor constructor.\n */\nexport interface IContextIdProcessorConstructorOptions {\n\t/**\n\t * The configuration for the processor.\n\t */\n\tconfig: IContextIdProcessorConfig;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=ILoggingProcessorConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ILoggingProcessorConfig.js","sourceRoot":"","sources":["../../../src/models/ILoggingProcessorConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the request logging processor.\n */\nexport interface ILoggingProcessorConfig {\n\t/**\n\t * Include the body objects when logging the information.\n\t */\n\tincludeBody?: boolean;\n\n\t/**\n\t * Show the full base64 content for data, default to abbreviate.\n\t */\n\tfullBase64?: boolean;\n\n\t/**\n\t * List of property names to obfuscate, can be regex, defaults to \"password\".\n\t */\n\tobfuscateProperties?: string[];\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ILoggingProcessorConstructorOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ILoggingProcessorConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/ILoggingProcessorConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { ILoggingProcessorConfig } from \"./ILoggingProcessorConfig.js\";\n\n/**\n * Options for the LoggingProcessor constructor.\n */\nexport interface ILoggingProcessorConstructorOptions {\n\t/**\n\t * The type for the logging component.\n\t */\n\tloggingComponentType?: string;\n\n\t/**\n\t * The configuration for the logging processor.\n\t */\n\tconfig?: ILoggingProcessorConfig;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IRestRouteProcessorConstructorOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IRestRouteProcessorConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IRestRouteProcessorConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IRouteProcessorConfig } from \"../models/IRouteProcessorConfig.js\";\n\n/**\n * Options for the RestRouteProcessor constructor.\n */\nexport interface IRestRouteProcessorConstructorOptions {\n\t/**\n\t * The configuration for the processor.\n\t */\n\tconfig?: IRouteProcessorConfig;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IRouteProcessorConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IRouteProcessorConfig.js","sourceRoot":"","sources":["../../../src/models/IRouteProcessorConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the route processor.\n */\nexport interface IRouteProcessorConfig {\n\t/**\n\t * Include the stack with errors.\n\t */\n\tincludeErrorStack?: boolean;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ISocketRouteProcessorConstructorOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ISocketRouteProcessorConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/ISocketRouteProcessorConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IRouteProcessorConfig } from \"./IRouteProcessorConfig.js\";\n\n/**\n * Options for the SocketRouteProcessor constructor.\n */\nexport interface ISocketRouteProcessorConstructorOptions {\n\t/**\n\t * The configuration for the processor.\n\t */\n\tconfig?: IRouteProcessorConfig;\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright 2024 IOTA Stiftung.
2
+ // SPDX-License-Identifier: Apache-2.0.
3
+ export {};
4
+ //# sourceMappingURL=IStaticContextIdProcessorConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IStaticContextIdProcessorConfig.js","sourceRoot":"","sources":["../../../src/models/IStaticContextIdProcessorConfig.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\n\n/**\n * Configuration for the static id processor.\n */\nexport interface IStaticContextIdProcessorConfig {\n\t/**\n\t * The fixed identity key for request context.\n\t */\n\tkey: string;\n\n\t/**\n\t * The fixed identity value for request context.\n\t */\n\tvalue: string;\n\n\t/**\n\t * Only add the identity if the request is authenticated.\n\t */\n\tauthOnly?: boolean;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IStaticContextIdProcessorConstructorOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IStaticContextIdProcessorConstructorOptions.js","sourceRoot":"","sources":["../../../src/models/IStaticContextIdProcessorConstructorOptions.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IStaticContextIdProcessorConfig } from \"./IStaticContextIdProcessorConfig.js\";\n\n/**\n * Options for the StaticContextIdProcessor constructor.\n */\nexport interface IStaticContextIdProcessorConstructorOptions {\n\t/**\n\t * The configuration for the processor.\n\t */\n\tconfig: IStaticContextIdProcessorConfig;\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { type IHttpRequestIdentity, type IHttpResponse, type IRestRouteProcessor, type IHttpServerRequest, type IRestRoute } from "@twin.org/api-models";
2
- import type { IRestRouteProcessorConstructorOptions } from "../models/IRestRouteProcessorConstructorOptions";
1
+ import { type IHttpResponse, type IHttpServerRequest, type IRestRoute, type IRestRouteProcessor } from "@twin.org/api-models";
2
+ import type { IRestRouteProcessorConstructorOptions } from "../models/IRestRouteProcessorConstructorOptions.js";
3
3
  /**
4
4
  * Process the REST request and hands it on to the route handler.
5
5
  */
@@ -7,22 +7,26 @@ export declare class RestRouteProcessor implements IRestRouteProcessor {
7
7
  /**
8
8
  * Runtime name for the class.
9
9
  */
10
- readonly CLASS_NAME: string;
10
+ static readonly CLASS_NAME: string;
11
11
  /**
12
12
  * Create a new instance of RouteProcessor.
13
13
  * @param options Options for the processor.
14
14
  */
15
15
  constructor(options?: IRestRouteProcessorConstructorOptions);
16
+ /**
17
+ * Returns the class name of the component.
18
+ * @returns The class name of the component.
19
+ */
20
+ className(): string;
16
21
  /**
17
22
  * Process the REST request for the specified route.
18
23
  * @param request The incoming request.
19
24
  * @param response The outgoing response.
20
25
  * @param route The route to process.
21
- * @param requestIdentity The identity context for the request.
22
26
  * @param processorState The state handed through the processors.
23
27
  * @param loggingComponentType The logging component type for the request.
24
28
  */
25
- process(request: IHttpServerRequest, response: IHttpResponse, route: IRestRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
29
+ process(request: IHttpServerRequest, response: IHttpResponse, route: IRestRoute | undefined, processorState: {
26
30
  [id: string]: unknown;
27
31
  }, loggingComponentType?: string): Promise<void>;
28
32
  }
@@ -1,5 +1,5 @@
1
- import { type IHttpRequestIdentity, type IHttpResponse, type ISocketRoute, type ISocketRouteProcessor, type ISocketServerRequest } from "@twin.org/api-models";
2
- import type { ISocketRouteProcessorConstructorOptions } from "../models/ISocketRouteProcessorConstructorOptions";
1
+ import { type IHttpResponse, type ISocketRoute, type ISocketRouteProcessor, type ISocketServerRequest } from "@twin.org/api-models";
2
+ import type { ISocketRouteProcessorConstructorOptions } from "../models/ISocketRouteProcessorConstructorOptions.js";
3
3
  /**
4
4
  * Process the socket request and hands it on to the route handler.
5
5
  */
@@ -7,12 +7,17 @@ export declare class SocketRouteProcessor implements ISocketRouteProcessor {
7
7
  /**
8
8
  * Runtime name for the class.
9
9
  */
10
- readonly CLASS_NAME: string;
10
+ static readonly CLASS_NAME: string;
11
11
  /**
12
12
  * Create a new instance of SocketRouteProcessor.
13
13
  * @param options Options for the processor.
14
14
  */
15
15
  constructor(options?: ISocketRouteProcessorConstructorOptions);
16
+ /**
17
+ * Returns the class name of the component.
18
+ * @returns The class name of the component.
19
+ */
20
+ className(): string;
16
21
  /**
17
22
  * Process the connected event.
18
23
  * @param request The server request object containing the socket id and other parameters.
@@ -30,16 +35,15 @@ export declare class SocketRouteProcessor implements ISocketRouteProcessor {
30
35
  */
31
36
  disconnected(request: ISocketServerRequest, route: ISocketRoute | undefined, loggingComponentType?: string): Promise<void>;
32
37
  /**
33
- * Process the REST request for the specified route.
38
+ * Process the socket request for the specified route.
34
39
  * @param request The incoming request.
35
40
  * @param response The outgoing response.
36
41
  * @param route The route to process.
37
- * @param requestIdentity The identity context for the request.
38
42
  * @param processorState The state handed through the processors.
39
43
  * @param responseEmitter The function to emit a response.
40
44
  * @param loggingComponentType The logging component type for the request.
41
45
  */
42
- process(request: ISocketServerRequest, response: IHttpResponse, route: ISocketRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
46
+ process(request: ISocketServerRequest, response: IHttpResponse, route: ISocketRoute | undefined, processorState: {
43
47
  [id: string]: unknown;
44
48
  }, responseEmitter: (topic: string, response: IHttpResponse) => Promise<void>, loggingComponentType?: string): Promise<void>;
45
49
  }
@@ -0,0 +1,39 @@
1
+ import type { IBaseRoute, IBaseRouteProcessor, IHttpResponse, IHttpServerRequest } from "@twin.org/api-models";
2
+ import { type IContextIds } from "@twin.org/context";
3
+ import type { IContextIdProcessorConstructorOptions } from "../models/IContextIdProcessorConstructorOptions.js";
4
+ /**
5
+ * Adds an id to the request context ids.
6
+ */
7
+ export declare class ContextIdProcessor implements IBaseRouteProcessor {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ static readonly CLASS_NAME: string;
12
+ /**
13
+ * Create a new instance of ContextIdProcessor.
14
+ * @param options Options for the processor.
15
+ */
16
+ constructor(options: IContextIdProcessorConstructorOptions);
17
+ /**
18
+ * Returns the class name of the component.
19
+ * @returns The class name of the component.
20
+ */
21
+ className(): string;
22
+ /**
23
+ * The service needs to be started when the application is initialized.
24
+ * @param nodeLoggingComponentType The node logging component type.
25
+ * @returns Nothing.
26
+ */
27
+ start(nodeLoggingComponentType?: string): Promise<void>;
28
+ /**
29
+ * Pre process the REST request for the specified route.
30
+ * @param request The incoming request.
31
+ * @param response The outgoing response.
32
+ * @param route The route to process.
33
+ * @param contextIds The context IDs of the request.
34
+ * @param processorState The state handed through the processors.
35
+ */
36
+ pre(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, contextIds: IContextIds, processorState: {
37
+ [id: string]: unknown;
38
+ }): Promise<void>;
39
+ }
@@ -0,0 +1,33 @@
1
+ import type { IBaseRoute, IBaseRouteProcessor, IHttpResponse, IHttpServerRequest } from "@twin.org/api-models";
2
+ import type { IContextIds } from "@twin.org/context";
3
+ import type { IStaticContextIdProcessorConstructorOptions } from "../models/IStaticContextIdProcessorConstructorOptions.js";
4
+ /**
5
+ * Adds a static context id to the request context.
6
+ */
7
+ export declare class StaticContextIdProcessor implements IBaseRouteProcessor {
8
+ /**
9
+ * Runtime name for the class.
10
+ */
11
+ static readonly CLASS_NAME: string;
12
+ /**
13
+ * Create a new instance of StaticContextIdProcessor.
14
+ * @param options Options for the processor.
15
+ */
16
+ constructor(options: IStaticContextIdProcessorConstructorOptions);
17
+ /**
18
+ * Returns the class name of the component.
19
+ * @returns The class name of the component.
20
+ */
21
+ className(): string;
22
+ /**
23
+ * Pre process the REST request for the specified route.
24
+ * @param request The incoming request.
25
+ * @param response The outgoing response.
26
+ * @param route The route to process.
27
+ * @param contextIds The context IDs of the request.
28
+ * @param processorState The state handed through the processors.
29
+ */
30
+ pre(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, contextIds: IContextIds, processorState: {
31
+ [id: string]: unknown;
32
+ }): Promise<void>;
33
+ }
@@ -1,14 +1,16 @@
1
- export * from "./data/restRouteProcessor";
2
- export * from "./data/socketRouteProcessor";
3
- export * from "./identity/nodeIdentityProcessor";
4
- export * from "./identity/staticUserIdentityProcessor";
5
- export * from "./logging/loggingProcessor";
6
- export * from "./mimeType/jsonLdMimeTypeProcessor";
7
- export * from "./mimeType/jwtMimeTypeProcessor";
8
- export * from "./models/ILoggingProcessorConfig";
9
- export * from "./models/ILoggingProcessorConstructorOptions";
10
- export * from "./models/IRestRouteProcessorConstructorOptions";
11
- export * from "./models/IRouteProcessorConfig";
12
- export * from "./models/ISocketRouteProcessorConstructorOptions";
13
- export * from "./models/IStaticUserIdentityProcessorConfig";
14
- export * from "./models/IStaticUserIdentityProcessorConstructorOptions";
1
+ export * from "./data/restRouteProcessor.js";
2
+ export * from "./data/socketRouteProcessor.js";
3
+ export * from "./identity/contextIdProcessor.js";
4
+ export * from "./identity/staticContextIdProcessor.js";
5
+ export * from "./logging/loggingProcessor.js";
6
+ export * from "./mimeType/jsonLdMimeTypeProcessor.js";
7
+ export * from "./mimeType/jwtMimeTypeProcessor.js";
8
+ export * from "./models/IContextIdProcessorConfig.js";
9
+ export * from "./models/IContextIdProcessorConstructorOptions.js";
10
+ export * from "./models/ILoggingProcessorConfig.js";
11
+ export * from "./models/ILoggingProcessorConstructorOptions.js";
12
+ export * from "./models/IRestRouteProcessorConstructorOptions.js";
13
+ export * from "./models/IRouteProcessorConfig.js";
14
+ export * from "./models/ISocketRouteProcessorConstructorOptions.js";
15
+ export * from "./models/IStaticContextIdProcessorConfig.js";
16
+ export * from "./models/IStaticContextIdProcessorConstructorOptions.js";
@@ -1,5 +1,6 @@
1
- import type { IBaseRoute, IBaseRouteProcessor, IHttpRequestIdentity, IHttpResponse, IHttpServerRequest } from "@twin.org/api-models";
2
- import type { ILoggingProcessorConstructorOptions } from "../models/ILoggingProcessorConstructorOptions";
1
+ import type { IBaseRoute, IBaseRouteProcessor, IHttpResponse, IHttpServerRequest } from "@twin.org/api-models";
2
+ import type { IContextIds } from "@twin.org/context";
3
+ import type { ILoggingProcessorConstructorOptions } from "../models/ILoggingProcessorConstructorOptions.js";
3
4
  /**
4
5
  * Process the REST request and log its information.
5
6
  */
@@ -7,21 +8,26 @@ export declare class LoggingProcessor implements IBaseRouteProcessor {
7
8
  /**
8
9
  * Runtime name for the class.
9
10
  */
10
- readonly CLASS_NAME: string;
11
+ static readonly CLASS_NAME: string;
11
12
  /**
12
13
  * Create a new instance of LoggingProcessor.
13
14
  * @param options Options for the processor.
14
15
  */
15
16
  constructor(options?: ILoggingProcessorConstructorOptions);
17
+ /**
18
+ * Returns the class name of the component.
19
+ * @returns The class name of the component.
20
+ */
21
+ className(): string;
16
22
  /**
17
23
  * Pre process the REST request for the specified route.
18
24
  * @param request The incoming request.
19
25
  * @param response The outgoing response.
20
26
  * @param route The route to process.
21
- * @param requestIdentity The identity context for the request.
27
+ * @param contextIds The context IDs of the request.
22
28
  * @param processorState The state handed through the processors.
23
29
  */
24
- pre(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
30
+ pre(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, contextIds: IContextIds, processorState: {
25
31
  [id: string]: unknown;
26
32
  }): Promise<void>;
27
33
  /**
@@ -29,10 +35,10 @@ export declare class LoggingProcessor implements IBaseRouteProcessor {
29
35
  * @param request The incoming request.
30
36
  * @param response The outgoing response.
31
37
  * @param route The route to process.
32
- * @param requestIdentity The identity context for the request.
38
+ * @param contextIds The context IDs of the request.
33
39
  * @param processorState The state handed through the processors.
34
40
  */
35
- post(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
41
+ post(request: IHttpServerRequest, response: IHttpResponse, route: IBaseRoute | undefined, contextIds: IContextIds, processorState: {
36
42
  [id: string]: unknown;
37
43
  }): Promise<void>;
38
44
  }
@@ -6,7 +6,12 @@ export declare class JsonLdMimeTypeProcessor implements IMimeTypeProcessor {
6
6
  /**
7
7
  * Runtime name for the class.
8
8
  */
9
- readonly CLASS_NAME: string;
9
+ static readonly CLASS_NAME: string;
10
+ /**
11
+ * Returns the class name of the component.
12
+ * @returns The class name of the component.
13
+ */
14
+ className(): string;
10
15
  /**
11
16
  * Get the MIME types that this handler can handle.
12
17
  * @returns The MIME types that this handler can handle.
@@ -6,7 +6,12 @@ export declare class JwtMimeTypeProcessor implements IMimeTypeProcessor {
6
6
  /**
7
7
  * Runtime name for the class.
8
8
  */
9
- readonly CLASS_NAME: string;
9
+ static readonly CLASS_NAME: string;
10
+ /**
11
+ * Returns the class name of the component.
12
+ * @returns The class name of the component.
13
+ */
14
+ className(): string;
10
15
  /**
11
16
  * Get the MIME types that this handler can handle.
12
17
  * @returns The MIME types that this handler can handle.
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Configuration for the context id processor.
3
+ */
4
+ export interface IContextIdProcessorConfig {
5
+ /**
6
+ * The fixed identity key for request context.
7
+ */
8
+ key: string;
9
+ /**
10
+ * Only add the identity if the request is authenticated.
11
+ */
12
+ authOnly?: boolean;
13
+ }
@@ -0,0 +1,10 @@
1
+ import type { IContextIdProcessorConfig } from "./IContextIdProcessorConfig.js";
2
+ /**
3
+ * Options for the ContextIdProcessor constructor.
4
+ */
5
+ export interface IContextIdProcessorConstructorOptions {
6
+ /**
7
+ * The configuration for the processor.
8
+ */
9
+ config: IContextIdProcessorConfig;
10
+ }
@@ -1,4 +1,4 @@
1
- import type { ILoggingProcessorConfig } from "./ILoggingProcessorConfig";
1
+ import type { ILoggingProcessorConfig } from "./ILoggingProcessorConfig.js";
2
2
  /**
3
3
  * Options for the LoggingProcessor constructor.
4
4
  */
@@ -1,4 +1,4 @@
1
- import type { IRouteProcessorConfig } from "../models/IRouteProcessorConfig";
1
+ import type { IRouteProcessorConfig } from "../models/IRouteProcessorConfig.js";
2
2
  /**
3
3
  * Options for the RestRouteProcessor constructor.
4
4
  */
@@ -1,4 +1,4 @@
1
- import type { IRouteProcessorConfig } from "./IRouteProcessorConfig";
1
+ import type { IRouteProcessorConfig } from "./IRouteProcessorConfig.js";
2
2
  /**
3
3
  * Options for the SocketRouteProcessor constructor.
4
4
  */
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Configuration for the static id processor.
3
+ */
4
+ export interface IStaticContextIdProcessorConfig {
5
+ /**
6
+ * The fixed identity key for request context.
7
+ */
8
+ key: string;
9
+ /**
10
+ * The fixed identity value for request context.
11
+ */
12
+ value: string;
13
+ /**
14
+ * Only add the identity if the request is authenticated.
15
+ */
16
+ authOnly?: boolean;
17
+ }
@@ -0,0 +1,10 @@
1
+ import type { IStaticContextIdProcessorConfig } from "./IStaticContextIdProcessorConfig.js";
2
+ /**
3
+ * Options for the StaticContextIdProcessor constructor.
4
+ */
5
+ export interface IStaticContextIdProcessorConstructorOptions {
6
+ /**
7
+ * The configuration for the processor.
8
+ */
9
+ config: IStaticContextIdProcessorConfig;
10
+ }