@3sixty/api-processors 0.20.0-next.0 → 0.20.0-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.
@@ -1 +1 @@
1
- {"version":3,"file":"restRouteProcessor.js","sourceRoot":"","sources":["../../../src/data/restRouteProcessor.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,eAAe,EAOf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGrE;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC9B;;OAEG;IACI,MAAM,CAAU,UAAU,wBAAwC;IAEzE;;;OAGG;IACc,kBAAkB,CAAU;IAE7C;;;OAGG;IACH,YAAY,OAA+C;QAC1D,IAAI,CAAC,kBAAkB,GAAG,OAAO,EAAE,MAAM,EAAE,iBAAiB,IAAI,KAAK,CAAC;IACvE,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,kBAAkB,CAAC,UAAU,CAAC;IACtC,CAAC;IAED;;;;;;;;;OASG;IACI,KAAK,CAAC,OAAO,CACnB,OAA2B,EAC3B,QAAuB,EACvB,KAA6B,EAC7B,cAAyC,EACzC,cAEC;QAED,2EAA2E;QAC3E,0CAA0C;QAC1C,IAAI,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YACnC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrB,eAAe,CAAC,aAAa,CAC5B,QAAQ,EACR;oBACC,IAAI,EAAE,aAAa,CAAC,UAAU;oBAC9B,OAAO,EAAE,GAAG,kBAAkB,CAAC,UAAU,gBAAgB;oBACzD,UAAU,EAAE;wBACX,UAAU,EAAE,OAAO,CAAC,GAAG;qBACvB;iBACD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C;gBACzF,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tHttpErrorHelper,\n\ttype IHttpRequest,\n\ttype IHttpResponse,\n\ttype IHttpServerRequest,\n\ttype IRestRoute,\n\ttype IRestRouteProcessor,\n\ttype IRestRouteResponseOptions\n} from \"@3sixty/api-models\";\nimport { Is, NotFoundError } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@3sixty/web\";\nimport type { IRestRouteProcessorConstructorOptions } from \"../models/IRestRouteProcessorConstructorOptions.js\";\n\n/**\n * Process the REST request and hands it on to the route handler.\n */\nexport class RestRouteProcessor implements IRestRouteProcessor {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<RestRouteProcessor>();\n\n\t/**\n\t * Include the stack with errors.\n\t * @internal\n\t */\n\tprivate readonly _includeErrorStack: boolean;\n\n\t/**\n\t * Create a new instance of RouteProcessor.\n\t * @param options Options for the processor.\n\t */\n\tconstructor(options?: IRestRouteProcessorConstructorOptions) {\n\t\tthis._includeErrorStack = options?.config?.includeErrorStack ?? false;\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 RestRouteProcessor.CLASS_NAME;\n\t}\n\n\t/**\n\t * 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 processorState The state handed through the processors.\n\t * @param componentTypes The component types for the request.\n\t * @param componentTypes.loggingComponentType The logging component type.\n\t * @returns A promise that resolves when the request has been processed and the response populated.\n\t */\n\tpublic async process(\n\t\trequest: IHttpServerRequest,\n\t\tresponse: IHttpResponse,\n\t\troute: IRestRoute | undefined,\n\t\tprocessorState: { [id: string]: unknown },\n\t\tcomponentTypes?: {\n\t\t\tloggingComponentType?: string;\n\t\t}\n\t): Promise<void> {\n\t\t// Don't handle the route if another processor has already set the response\n\t\t// status code e.g. from an auth processor\n\t\tif (Is.empty(response.statusCode)) {\n\t\t\tif (Is.empty(route)) {\n\t\t\t\tHttpErrorHelper.buildResponse(\n\t\t\t\t\tresponse,\n\t\t\t\t\t{\n\t\t\t\t\t\tname: NotFoundError.CLASS_NAME,\n\t\t\t\t\t\tmessage: `${RestRouteProcessor.CLASS_NAME}.routeNotFound`,\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tnotFoundId: request.url\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tHttpStatusCode.notFound,\n\t\t\t\t\tthis._includeErrorStack\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tconst req: IHttpRequest = {\n\t\t\t\t\t\theaders: request.headers,\n\t\t\t\t\t\tpathParams: request.pathParams,\n\t\t\t\t\t\tquery: request.query,\n\t\t\t\t\t\tbody: request.body\n\t\t\t\t\t};\n\n\t\t\t\t\tconst restRouteResponse: IHttpResponse & IRestRouteResponseOptions = await route.handler(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tserverRequest: request,\n\t\t\t\t\t\t\tprocessorState,\n\t\t\t\t\t\t\tloggingComponentType: componentTypes?.loggingComponentType\n\t\t\t\t\t\t},\n\t\t\t\t\t\treq\n\t\t\t\t\t);\n\n\t\t\t\t\tlet statusCode: HttpStatusCode =\n\t\t\t\t\t\trestRouteResponse.statusCode ?? response.statusCode ?? HttpStatusCode.ok;\n\n\t\t\t\t\tconst headers = restRouteResponse?.headers ?? {};\n\n\t\t\t\t\tif (Is.empty(restRouteResponse?.body)) {\n\t\t\t\t\t\t// If there is no custom status code and the body is empty\n\t\t\t\t\t\t// use the no content response and set the length to 0\n\t\t\t\t\t\theaders[HeaderTypes.ContentLength] = \"0\";\n\t\t\t\t\t\t// Only change to no content if the status code is ok\n\t\t\t\t\t\t// This could be something like a created status code\n\t\t\t\t\t\t// which is successful but has no content\n\t\t\t\t\t\tif (statusCode === HttpStatusCode.ok) {\n\t\t\t\t\t\t\tstatusCode = HttpStatusCode.noContent;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Only set the content type if there is a body\n\t\t\t\t\t\t// If there are custom response types for the route then use them\n\t\t\t\t\t\t// instead of the default application/json\n\t\t\t\t\t\theaders[HeaderTypes.ContentType] =\n\t\t\t\t\t\t\trestRouteResponse?.attachment?.mimeType ??\n\t\t\t\t\t\t\trestRouteResponse.headers?.[HeaderTypes.ContentType] ??\n\t\t\t\t\t\t\t`${MimeTypes.Json}; charset=utf-8`;\n\n\t\t\t\t\t\t// If there are filename or inline options set then add the content disposition\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tIs.stringValue(restRouteResponse?.attachment?.filename) ||\n\t\t\t\t\t\t\tIs.boolean(restRouteResponse?.attachment?.inline)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tlet filename = \"\";\n\t\t\t\t\t\t\tif (Is.stringValue(restRouteResponse?.attachment?.filename)) {\n\t\t\t\t\t\t\t\tfilename = `; filename=\"${restRouteResponse?.attachment?.filename}\"`;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\theaders[HeaderTypes.ContentDisposition] =\n\t\t\t\t\t\t\t\t`${restRouteResponse?.attachment?.inline ? \"inline\" : \"attachment\"}${filename}`;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// If this is a binary response then set the content length\n\t\t\t\t\t\tif (Is.uint8Array(restRouteResponse?.body)) {\n\t\t\t\t\t\t\tconst contentLength = restRouteResponse.body.length;\n\t\t\t\t\t\t\theaders[HeaderTypes.ContentLength] = contentLength.toString();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tresponse.body = restRouteResponse?.body;\n\t\t\t\t\t}\n\n\t\t\t\t\tresponse.headers = headers;\n\t\t\t\t\tresponse.statusCode = statusCode;\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst { error, httpStatusCode } = HttpErrorHelper.processError(\n\t\t\t\t\t\terr,\n\t\t\t\t\t\tthis._includeErrorStack\n\t\t\t\t\t);\n\n\t\t\t\t\tHttpErrorHelper.buildResponse(response, error, httpStatusCode, this._includeErrorStack);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"restRouteProcessor.js","sources":["../../../src/data/restRouteProcessor.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,eAAe,EAOf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGrE;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC9B;;OAEG;IACI,MAAM,CAAU,UAAU,GAAW,oBAAoB,CAAC;IAEjE;;;OAGG;IACc,kBAAkB,CAAU;IAE7C;;;OAGG;IACH,YAAY,OAA+C;QAC1D,IAAI,CAAC,kBAAkB,GAAG,OAAO,EAAE,MAAM,EAAE,iBAAiB,IAAI,KAAK,CAAC;IACvE,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,kBAAkB,CAAC,UAAU,CAAC;IACtC,CAAC;IAED;;;;;;;;;OASG;IACI,KAAK,CAAC,OAAO,CACnB,OAA2B,EAC3B,QAAuB,EACvB,KAA6B,EAC7B,cAAyC,EACzC,cAEC;QAED,2EAA2E;QAC3E,0CAA0C;QAC1C,IAAI,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YACnC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;gBACrB,eAAe,CAAC,aAAa,CAC5B,QAAQ,EACR;oBACC,IAAI,EAAE,aAAa,CAAC,UAAU;oBAC9B,OAAO,EAAE,GAAG,kBAAkB,CAAC,UAAU,gBAAgB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,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;gBACzF,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tHttpErrorHelper,\n\ttype IHttpRequest,\n\ttype IHttpResponse,\n\ttype IHttpServerRequest,\n\ttype IRestRoute,\n\ttype IRestRouteProcessor,\n\ttype IRestRouteResponseOptions\n} from \"@3sixty/api-models\";\nimport { Is, NotFoundError } from \"@3sixty/core\";\n\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@3sixty/web\";\nimport type { IRestRouteProcessorConstructorOptions } from \"../models/IRestRouteProcessorConstructorOptions.js\";\n\n/**\n * Process the REST request and hands it on to the route handler.\n */\nexport class RestRouteProcessor implements IRestRouteProcessor {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = \"RestRouteProcessor\";\n\n\t/**\n\t * Include the stack with errors.\n\t * @internal\n\t */\n\tprivate readonly _includeErrorStack: boolean;\n\n\t/**\n\t * Create a new instance of RouteProcessor.\n\t * @param options Options for the processor.\n\t */\n\tconstructor(options?: IRestRouteProcessorConstructorOptions) {\n\t\tthis._includeErrorStack = options?.config?.includeErrorStack ?? false;\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 RestRouteProcessor.CLASS_NAME;\n\t}\n\n\t/**\n\t * 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 processorState The state handed through the processors.\n\t * @param componentTypes The component types for the request.\n\t * @param componentTypes.loggingComponentType The logging component type.\n\t * @returns A promise that resolves when the request has been processed and the response populated.\n\t */\n\tpublic async process(\n\t\trequest: IHttpServerRequest,\n\t\tresponse: IHttpResponse,\n\t\troute: IRestRoute | undefined,\n\t\tprocessorState: { [id: string]: unknown },\n\t\tcomponentTypes?: {\n\t\t\tloggingComponentType?: string;\n\t\t}\n\t): Promise<void> {\n\t\t// Don't handle the route if another processor has already set the response\n\t\t// status code e.g. from an auth processor\n\t\tif (Is.empty(response.statusCode)) {\n\t\t\tif (Is.empty(route)) {\n\t\t\t\tHttpErrorHelper.buildResponse(\n\t\t\t\t\tresponse,\n\t\t\t\t\t{\n\t\t\t\t\t\tname: NotFoundError.CLASS_NAME,\n\t\t\t\t\t\tmessage: `${RestRouteProcessor.CLASS_NAME}.routeNotFound`,\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tnotFoundId: request.url\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tHttpStatusCode.notFound,\n\t\t\t\t\tthis._includeErrorStack\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tconst req: IHttpRequest = {\n\t\t\t\t\t\theaders: request.headers,\n\t\t\t\t\t\tpathParams: request.pathParams,\n\t\t\t\t\t\tquery: request.query,\n\t\t\t\t\t\tbody: request.body\n\t\t\t\t\t};\n\n\t\t\t\t\tconst restRouteResponse: IHttpResponse & IRestRouteResponseOptions = await route.handler(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tserverRequest: request,\n\t\t\t\t\t\t\tprocessorState,\n\t\t\t\t\t\t\tloggingComponentType: componentTypes?.loggingComponentType\n\t\t\t\t\t\t},\n\t\t\t\t\t\treq\n\t\t\t\t\t);\n\n\t\t\t\t\tlet statusCode: HttpStatusCode =\n\t\t\t\t\t\trestRouteResponse.statusCode ?? response.statusCode ?? HttpStatusCode.ok;\n\n\t\t\t\t\tconst headers = restRouteResponse?.headers ?? {};\n\n\t\t\t\t\tif (Is.empty(restRouteResponse?.body)) {\n\t\t\t\t\t\t// If there is no custom status code and the body is empty\n\t\t\t\t\t\t// use the no content response and set the length to 0\n\t\t\t\t\t\theaders[HeaderTypes.ContentLength] = \"0\";\n\t\t\t\t\t\t// Only change to no content if the status code is ok\n\t\t\t\t\t\t// This could be something like a created status code\n\t\t\t\t\t\t// which is successful but has no content\n\t\t\t\t\t\tif (statusCode === HttpStatusCode.ok) {\n\t\t\t\t\t\t\tstatusCode = HttpStatusCode.noContent;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Only set the content type if there is a body\n\t\t\t\t\t\t// If there are custom response types for the route then use them\n\t\t\t\t\t\t// instead of the default application/json\n\t\t\t\t\t\theaders[HeaderTypes.ContentType] =\n\t\t\t\t\t\t\trestRouteResponse?.attachment?.mimeType ??\n\t\t\t\t\t\t\trestRouteResponse.headers?.[HeaderTypes.ContentType] ??\n\t\t\t\t\t\t\t`${MimeTypes.Json}; charset=utf-8`;\n\n\t\t\t\t\t\t// If there are filename or inline options set then add the content disposition\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tIs.stringValue(restRouteResponse?.attachment?.filename) ||\n\t\t\t\t\t\t\tIs.boolean(restRouteResponse?.attachment?.inline)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tlet filename = \"\";\n\t\t\t\t\t\t\tif (Is.stringValue(restRouteResponse?.attachment?.filename)) {\n\t\t\t\t\t\t\t\tfilename = `; filename=\"${restRouteResponse?.attachment?.filename}\"`;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\theaders[HeaderTypes.ContentDisposition] =\n\t\t\t\t\t\t\t\t`${restRouteResponse?.attachment?.inline ? \"inline\" : \"attachment\"}${filename}`;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// If this is a binary response then set the content length\n\t\t\t\t\t\tif (Is.uint8Array(restRouteResponse?.body)) {\n\t\t\t\t\t\t\tconst contentLength = restRouteResponse.body.length;\n\t\t\t\t\t\t\theaders[HeaderTypes.ContentLength] = contentLength.toString();\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tresponse.body = restRouteResponse?.body;\n\t\t\t\t\t}\n\n\t\t\t\t\tresponse.headers = headers;\n\t\t\t\t\tresponse.statusCode = statusCode;\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst { error, httpStatusCode } = HttpErrorHelper.processError(\n\t\t\t\t\t\terr,\n\t\t\t\t\t\tthis._includeErrorStack\n\t\t\t\t\t);\n\n\t\t\t\t\tHttpErrorHelper.buildResponse(response, error, httpStatusCode, this._includeErrorStack);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"socketRouteProcessor.js","sourceRoot":"","sources":["../../../src/data/socketRouteProcessor.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,eAAe,EAOf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAChC;;OAEG;IACI,MAAM,CAAU,UAAU,0BAA0C;IAE3E;;;OAGG;IACc,kBAAkB,CAAU;IAE7C;;;OAGG;IACH,YAAY,OAAiD;QAC5D,IAAI,CAAC,kBAAkB,GAAG,OAAO,EAAE,MAAM,EAAE,iBAAiB,IAAI,KAAK,CAAC;IACvE,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,oBAAoB,CAAC,UAAU,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,SAAS,CACrB,OAA6B,EAC7B,KAA+B,EAC/B,oBAA6B;QAE7B,IAAI,KAAK,EAAE,SAAS,EAAE,CAAC;YACtB,IAAI,CAAC;gBACJ,MAAM,oBAAoB,GAA0B;oBACnD,QAAQ,EAAE,OAAO,CAAC,QAAQ;oBAC1B,aAAa,EAAE,OAAO;oBACtB,cAAc,EAAE,EAAE;oBAClB,oBAAoB;iBACpB,CAAC;gBAEF,MAAM,KAAK,CAAC,SAAS,CAAC,oBAAoB,CAAC,CAAC;YAC7C,CAAC;YAAC,MA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BAClB,CAAC;oBAEF,MAAM,oBAAoB,GAA0B;wBACnD,QAAQ,EAAE,OAAO,CAAC,QAAQ;wBAC1B,aAAa,EAAE,OAAO;wBACtB,cAAc;wBACd,oBAAoB;qBACpB,CAAC;oBAEF,MAAM,KAAK,CAAC,OAAO,CAAC,oBAAoB,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,mBAAmB,EAAE,EAAE;wBACnF,QAAQ,CAAC,OAAO,GAAG,mBAAmB,EAAE,OAAO,CAAC;wBAChD,QAAQ,CAAC,IAAI,GAAG,mBAAmB,EAAE,IAAI,CAAC;wBAC1C,QAAQ,CAAC,UAAU;4BAClB,mBAAmB,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,IAAI,cAAc,CAAC,EAAE,CAAC;wBAC5E,MAAM,eAAe,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;oBACxC,CAAC,CAAC,CAAC;gBACJ,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACd,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,eAAe,CAAC,YAAY,CAC7D,GAAG,EACH,IAAI,CAAC,kBAAkB,CACvB,CAAC;oBAEF,eAAe,CAAC,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;gBACzF,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tHttpErrorHelper,\n\ttype IHttpRequest,\n\ttype IHttpResponse,\n\ttype ISocketRequestContext,\n\ttype ISocketRoute,\n\ttype ISocketRouteProcessor,\n\ttype ISocketServerRequest\n} from \"@3sixty/api-models\";\nimport { Is, NotFoundError } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport { HttpStatusCode } from \"@3sixty/web\";\nimport type { ISocketRouteProcessorConstructorOptions } from \"../models/ISocketRouteProcessorConstructorOptions.js\";\n\n/**\n * Process the socket request and hands it on to the route handler.\n */\nexport class SocketRouteProcessor implements ISocketRouteProcessor {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<SocketRouteProcessor>();\n\n\t/**\n\t * Include the stack with errors.\n\t * @internal\n\t */\n\tprivate readonly _includeErrorStack: boolean;\n\n\t/**\n\t * Create a new instance of SocketRouteProcessor.\n\t * @param options Options for the processor.\n\t */\n\tconstructor(options?: ISocketRouteProcessorConstructorOptions) {\n\t\tthis._includeErrorStack = options?.config?.includeErrorStack ?? false;\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 SocketRouteProcessor.CLASS_NAME;\n\t}\n\n\t/**\n\t * Process the connected event.\n\t * @param request The server request object containing the socket id and other parameters.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tpublic async connected(\n\t\trequest: ISocketServerRequest,\n\t\troute: ISocketRoute | undefined,\n\t\tloggingComponentType?: string\n\t): Promise<void> {\n\t\tif (route?.connected) {\n\t\t\ttry {\n\t\t\t\tconst socketRequestContext: ISocketRequestContext = {\n\t\t\t\t\tsocketId: request.socketId,\n\t\t\t\t\tserverRequest: request,\n\t\t\t\t\tprocessorState: {},\n\t\t\t\t\tloggingComponentType\n\t\t\t\t};\n\n\t\t\t\tawait route.connected(socketRequestContext);\n\t\t\t} catch {\n\t\t\t\t// There is no response to emit for a connected event, so the error is dropped\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Process the disconnected event.\n\t * @param request The server request object containing the socket id and other parameters.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tpublic async disconnected(\n\t\trequest: ISocketServerRequest,\n\t\troute: ISocketRoute | undefined,\n\t\tloggingComponentType?: string\n\t): Promise<void> {\n\t\tif (route?.disconnected) {\n\t\t\ttry {\n\t\t\t\tconst socketRequestContext: ISocketRequestContext = {\n\t\t\t\t\tsocketId: request.socketId,\n\t\t\t\t\tserverRequest: request,\n\t\t\t\t\tprocessorState: {},\n\t\t\t\t\tloggingComponentType\n\t\t\t\t};\n\n\t\t\t\tawait route.disconnected(socketRequestContext);\n\t\t\t} catch {\n\t\t\t\t// There is no response to emit for a disconnected event, so the error is dropped\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Process the socket 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 processorState The state handed through the processors.\n\t * @param responseEmitter The function to emit a response.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns A promise that resolves when the request has been processed and the response emitted.\n\t */\n\tpublic async process(\n\t\trequest: ISocketServerRequest,\n\t\tresponse: IHttpResponse,\n\t\troute: ISocketRoute | undefined,\n\t\tprocessorState: { [id: string]: unknown },\n\t\tresponseEmitter: (topic: string, response: IHttpResponse) => Promise<void>,\n\t\tloggingComponentType?: string\n\t): Promise<void> {\n\t\t// Don't handle the route if another processor has already set the response\n\t\t// status code e.g. from an auth processor\n\t\tif (Is.empty(response.statusCode)) {\n\t\t\tif (Is.empty(route)) {\n\t\t\t\tHttpErrorHelper.buildResponse(\n\t\t\t\t\tresponse,\n\t\t\t\t\t{\n\t\t\t\t\t\tname: NotFoundError.CLASS_NAME,\n\t\t\t\t\t\tmessage: `${SocketRouteProcessor.CLASS_NAME}.routeNotFound`,\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tnotFoundId: request.url\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tHttpStatusCode.notFound,\n\t\t\t\t\tthis._includeErrorStack\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tconst req: IHttpRequest = {\n\t\t\t\t\t\tpathParams: request.pathParams,\n\t\t\t\t\t\tquery: request.query,\n\t\t\t\t\t\tbody: request.body\n\t\t\t\t\t};\n\n\t\t\t\t\tconst socketRequestContext: ISocketRequestContext = {\n\t\t\t\t\t\tsocketId: request.socketId,\n\t\t\t\t\t\tserverRequest: request,\n\t\t\t\t\t\tprocessorState,\n\t\t\t\t\t\tloggingComponentType\n\t\t\t\t\t};\n\n\t\t\t\t\tawait route.handler(socketRequestContext, req, async (topic, socketRouteResponse) => {\n\t\t\t\t\t\tresponse.headers = socketRouteResponse?.headers;\n\t\t\t\t\t\tresponse.body = socketRouteResponse?.body;\n\t\t\t\t\t\tresponse.statusCode =\n\t\t\t\t\t\t\tsocketRouteResponse.statusCode ?? response.statusCode ?? HttpStatusCode.ok;\n\t\t\t\t\t\tawait responseEmitter(topic, response);\n\t\t\t\t\t});\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst { error, httpStatusCode } = HttpErrorHelper.processError(\n\t\t\t\t\t\terr,\n\t\t\t\t\t\tthis._includeErrorStack\n\t\t\t\t\t);\n\n\t\t\t\t\tHttpErrorHelper.buildResponse(response, error, httpStatusCode, this._includeErrorStack);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"socketRouteProcessor.js","sources":["../../../src/data/socketRouteProcessor.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,eAAe,EAOf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAChC;;OAEG;IACI,MAAM,CAAU,UAAU,GAAW,sBAAsB,CAAC;IAEnE;;;OAGG;IACc,kBAAkB,CAAU;IAE7C;;;OAGG;IACH,YAAY,OAAiD;QAC5D,IAAI,CAAC,kBAAkB,GAAG,OAAO,EAAE,MAAM,EAAE,iBAAiB,IAAI,KAAK,C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AAE,KAAK,EAAE,cAAc,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;gBACzF,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport {\n\tHttpErrorHelper,\n\ttype IHttpRequest,\n\ttype IHttpResponse,\n\ttype ISocketRequestContext,\n\ttype ISocketRoute,\n\ttype ISocketRouteProcessor,\n\ttype ISocketServerRequest\n} from \"@3sixty/api-models\";\nimport { Is, NotFoundError } from \"@3sixty/core\";\n\nimport { HttpStatusCode } from \"@3sixty/web\";\nimport type { ISocketRouteProcessorConstructorOptions } from \"../models/ISocketRouteProcessorConstructorOptions.js\";\n\n/**\n * Process the socket request and hands it on to the route handler.\n */\nexport class SocketRouteProcessor implements ISocketRouteProcessor {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = \"SocketRouteProcessor\";\n\n\t/**\n\t * Include the stack with errors.\n\t * @internal\n\t */\n\tprivate readonly _includeErrorStack: boolean;\n\n\t/**\n\t * Create a new instance of SocketRouteProcessor.\n\t * @param options Options for the processor.\n\t */\n\tconstructor(options?: ISocketRouteProcessorConstructorOptions) {\n\t\tthis._includeErrorStack = options?.config?.includeErrorStack ?? false;\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 SocketRouteProcessor.CLASS_NAME;\n\t}\n\n\t/**\n\t * Process the connected event.\n\t * @param request The server request object containing the socket id and other parameters.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tpublic async connected(\n\t\trequest: ISocketServerRequest,\n\t\troute: ISocketRoute | undefined,\n\t\tloggingComponentType?: string\n\t): Promise<void> {\n\t\tif (route?.connected) {\n\t\t\ttry {\n\t\t\t\tconst socketRequestContext: ISocketRequestContext = {\n\t\t\t\t\tsocketId: request.socketId,\n\t\t\t\t\tserverRequest: request,\n\t\t\t\t\tprocessorState: {},\n\t\t\t\t\tloggingComponentType\n\t\t\t\t};\n\n\t\t\t\tawait route.connected(socketRequestContext);\n\t\t\t} catch {\n\t\t\t\t// There is no response to emit for a connected event, so the error is dropped\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Process the disconnected event.\n\t * @param request The server request object containing the socket id and other parameters.\n\t * @param route The route being requested, if a matching one was found.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns Promise that resolves when the request is processed.\n\t */\n\tpublic async disconnected(\n\t\trequest: ISocketServerRequest,\n\t\troute: ISocketRoute | undefined,\n\t\tloggingComponentType?: string\n\t): Promise<void> {\n\t\tif (route?.disconnected) {\n\t\t\ttry {\n\t\t\t\tconst socketRequestContext: ISocketRequestContext = {\n\t\t\t\t\tsocketId: request.socketId,\n\t\t\t\t\tserverRequest: request,\n\t\t\t\t\tprocessorState: {},\n\t\t\t\t\tloggingComponentType\n\t\t\t\t};\n\n\t\t\t\tawait route.disconnected(socketRequestContext);\n\t\t\t} catch {\n\t\t\t\t// There is no response to emit for a disconnected event, so the error is dropped\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Process the socket 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 processorState The state handed through the processors.\n\t * @param responseEmitter The function to emit a response.\n\t * @param loggingComponentType The logging component type for the request.\n\t * @returns A promise that resolves when the request has been processed and the response emitted.\n\t */\n\tpublic async process(\n\t\trequest: ISocketServerRequest,\n\t\tresponse: IHttpResponse,\n\t\troute: ISocketRoute | undefined,\n\t\tprocessorState: { [id: string]: unknown },\n\t\tresponseEmitter: (topic: string, response: IHttpResponse) => Promise<void>,\n\t\tloggingComponentType?: string\n\t): Promise<void> {\n\t\t// Don't handle the route if another processor has already set the response\n\t\t// status code e.g. from an auth processor\n\t\tif (Is.empty(response.statusCode)) {\n\t\t\tif (Is.empty(route)) {\n\t\t\t\tHttpErrorHelper.buildResponse(\n\t\t\t\t\tresponse,\n\t\t\t\t\t{\n\t\t\t\t\t\tname: NotFoundError.CLASS_NAME,\n\t\t\t\t\t\tmessage: `${SocketRouteProcessor.CLASS_NAME}.routeNotFound`,\n\t\t\t\t\t\tproperties: {\n\t\t\t\t\t\t\tnotFoundId: request.url\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t\t\tHttpStatusCode.notFound,\n\t\t\t\t\tthis._includeErrorStack\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tconst req: IHttpRequest = {\n\t\t\t\t\t\tpathParams: request.pathParams,\n\t\t\t\t\t\tquery: request.query,\n\t\t\t\t\t\tbody: request.body\n\t\t\t\t\t};\n\n\t\t\t\t\tconst socketRequestContext: ISocketRequestContext = {\n\t\t\t\t\t\tsocketId: request.socketId,\n\t\t\t\t\t\tserverRequest: request,\n\t\t\t\t\t\tprocessorState,\n\t\t\t\t\t\tloggingComponentType\n\t\t\t\t\t};\n\n\t\t\t\t\tawait route.handler(socketRequestContext, req, async (topic, socketRouteResponse) => {\n\t\t\t\t\t\tresponse.headers = socketRouteResponse?.headers;\n\t\t\t\t\t\tresponse.body = socketRouteResponse?.body;\n\t\t\t\t\t\tresponse.statusCode =\n\t\t\t\t\t\t\tsocketRouteResponse.statusCode ?? response.statusCode ?? HttpStatusCode.ok;\n\t\t\t\t\t\tawait responseEmitter(topic, response);\n\t\t\t\t\t});\n\t\t\t\t} catch (err) {\n\t\t\t\t\tconst { error, httpStatusCode } = HttpErrorHelper.processError(\n\t\t\t\t\t\terr,\n\t\t\t\t\t\tthis._includeErrorStack\n\t\t\t\t\t);\n\n\t\t\t\t\tHttpErrorHelper.buildResponse(response, error, httpStatusCode, this._includeErrorStack);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"contextIdProcessor.js","sourceRoot":"","sources":["../../../src/identity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vB,cAAyC;QAEzC,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC;YACzE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACrC,CAAC;IACF,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 \"@3sixty/api-models\";\nimport { ContextIdStore, ContextIdHelper, type IContextIds } from \"@3sixty/context\";\nimport { Guards, Is } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport type { IContextIdProcessorConfig } from \"../models/IContextIdProcessorConfig.js\";\nimport type { IContextIdProcessorConstructorOptions } from \"../models/IContextIdProcessorConstructorOptions.js\";\n\n/**\n * Adds an id to the request context ids.\n */\nexport class ContextIdProcessor implements IBaseRouteProcessor {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<ContextIdProcessor>();\n\n\t/**\n\t * The fixed identity key for request context.\n\t * @internal\n\t */\n\tprivate readonly _key: string;\n\n\t/**\n\t * Only add the identity if the request is authenticated.\n\t * @internal\n\t */\n\tprivate readonly _authOnly: boolean;\n\n\t/**\n\t * The identity value for request context.\n\t * @internal\n\t */\n\tprivate _value?: string;\n\n\t/**\n\t * Create a new instance of ContextIdProcessor.\n\t * @param options Options for the processor.\n\t */\n\tconstructor(options: IContextIdProcessorConstructorOptions) {\n\t\tGuards.object(ContextIdProcessor.CLASS_NAME, nameof(options), options);\n\t\tGuards.object<IContextIdProcessorConfig>(\n\t\t\tContextIdProcessor.CLASS_NAME,\n\t\t\tnameof(options.config),\n\t\t\toptions.config\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tContextIdProcessor.CLASS_NAME,\n\t\t\tnameof(options.config.key),\n\t\t\toptions.config.key\n\t\t);\n\t\tthis._key = options.config.key;\n\t\tthis._authOnly = options.config.authOnly ?? false;\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 ContextIdProcessor.CLASS_NAME;\n\t}\n\n\t/**\n\t * The service needs to be started when the application is initialized.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns A promise that resolves when the context ID has been loaded from the store.\n\t */\n\tpublic async start(nodeLoggingComponentType?: string): Promise<void> {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tContextIdHelper.guard(contextIds, this._key);\n\t\tthis._value = contextIds[this._key];\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 * @returns A promise that resolves when the context ID has been injected into the request.\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\tif (!this._authOnly || (!Is.empty(route) && !(route.skipAuth ?? false))) {\n\t\t\tcontextIds[this._key] = this._value;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"contextIdProcessor.js","sources":["../../../src/identity/contextIdProcessor.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAoB,MAAM,iBAAiB,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAK1C;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC9B;;OAEG;IACI,MAAM,CAAU,UAAU,GAAW,oBAAoB,CAAC;IAEjE;;;OAGG;IACc,IAAI,CAAS;IAE9B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,CAAC;QACrC,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIBaseRoute,\n\tIBaseRouteProcessor,\n\tIHttpResponse,\n\tIHttpServerRequest\n} from \"@3sixty/api-models\";\nimport { ContextIdStore, ContextIdHelper, type IContextIds } from \"@3sixty/context\";\nimport { Guards, Is } from \"@3sixty/core\";\n\nimport type { IContextIdProcessorConfig } from \"../models/IContextIdProcessorConfig.js\";\nimport type { IContextIdProcessorConstructorOptions } from \"../models/IContextIdProcessorConstructorOptions.js\";\n\n/**\n * Adds an id to the request context ids.\n */\nexport class ContextIdProcessor implements IBaseRouteProcessor {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = \"ContextIdProcessor\";\n\n\t/**\n\t * The fixed identity key for request context.\n\t * @internal\n\t */\n\tprivate readonly _key: string;\n\n\t/**\n\t * Only add the identity if the request is authenticated.\n\t * @internal\n\t */\n\tprivate readonly _authOnly: boolean;\n\n\t/**\n\t * The identity value for request context.\n\t * @internal\n\t */\n\tprivate _value?: string;\n\n\t/**\n\t * Create a new instance of ContextIdProcessor.\n\t * @param options Options for the processor.\n\t */\n\tconstructor(options: IContextIdProcessorConstructorOptions) {\n\t\tGuards.object(ContextIdProcessor.CLASS_NAME, \"options\", options);\n\t\tGuards.object<IContextIdProcessorConfig>(\n\t\t\tContextIdProcessor.CLASS_NAME,\n\t\t\t\"options.config\",\n\t\t\toptions.config\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tContextIdProcessor.CLASS_NAME,\n\t\t\t\"options.config.key\",\n\t\t\toptions.config.key\n\t\t);\n\t\tthis._key = options.config.key;\n\t\tthis._authOnly = options.config.authOnly ?? false;\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 ContextIdProcessor.CLASS_NAME;\n\t}\n\n\t/**\n\t * The service needs to be started when the application is initialized.\n\t * @param nodeLoggingComponentType The node logging component type.\n\t * @returns A promise that resolves when the context ID has been loaded from the store.\n\t */\n\tpublic async start(nodeLoggingComponentType?: string): Promise<void> {\n\t\tconst contextIds = await ContextIdStore.getContextIds();\n\t\tContextIdHelper.guard(contextIds, this._key);\n\t\tthis._value = contextIds[this._key];\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 * @returns A promise that resolves when the context ID has been injected into the request.\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\tif (!this._authOnly || (!Is.empty(route) && !(route.skipAuth ?? false))) {\n\t\t\tcontextIds[this._key] = this._value;\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"staticContextIdProcessor.js","sourceRoot":"","sources":["../../../src/identity/staticContextIdProcessor.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAK1C;;GAEG;AACH,MAAM,OAAO,wBAAwB;IACpC;;OAEG;IACI,MAAM,CAAU,UAAU,8BAA8C;IAE/E;;;OAGG;IACc,IAAI,CAAS;IAE9B;;;OAGG;IACc,MAAM,CAAS;IAEhC;;;OAGG;IACc,SAAS,CAAU;IAEpC;;;OAGG;IACH,YAAY,OAAoD;QAC/D,MAAM,CAAC,MAAM,CAAC,wBAAwB,CAAC,UAAU,aAAmB,OAAO,CAAC,CAAC;QAC7E,MAAM,CAAC,MAAM,CACZ,wBAAwB,CAAC,UAAU,oBAEnC,OAAO,CAAC,MAAM,CACd,CAAC;QACF,MAAM,CAAC,WAAW,CACjB,wBAAwB,CAAC,UAAU,wBAEnC,OAAO,CAAC,MAAM,CAAC,GAAG,CAClB,CAAC;QACF,MAAM,CAAC,WAAW,CACjB,wBAAwB,CAAC,UAAU,0BAEnC,OAAO,CAAC,MAAM,CAAC,KAAK,CACpB,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC;IACnD,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,wBAAwB,CAAC,UAAU,CAAC;IAC5C,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,GAAG,CACf,OAA2B,EAC3B,QAAuB,EACvB,KAA6B,EAC7B,UAAuB,EACvB,cAAyC;QAEzC,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC;YACzE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACrC,CAAC;IACF,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 \"@3sixty/api-models\";\nimport type { IContextIds } from \"@3sixty/context\";\nimport { Guards, Is } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport type { IStaticContextIdProcessorConfig } from \"../models/IStaticContextIdProcessorConfig.js\";\nimport type { IStaticContextIdProcessorConstructorOptions } from \"../models/IStaticContextIdProcessorConstructorOptions.js\";\n\n/**\n * Adds a static context id to the request context.\n */\nexport class StaticContextIdProcessor implements IBaseRouteProcessor {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = nameof<StaticContextIdProcessor>();\n\n\t/**\n\t * The fixed identity key for request context.\n\t * @internal\n\t */\n\tprivate readonly _key: string;\n\n\t/**\n\t * The fixed identity value for request context.\n\t * @internal\n\t */\n\tprivate readonly _value: string;\n\n\t/**\n\t * Only add the identity if the request is authenticated.\n\t * @internal\n\t */\n\tprivate readonly _authOnly: boolean;\n\n\t/**\n\t * Create a new instance of StaticContextIdProcessor.\n\t * @param options Options for the processor.\n\t */\n\tconstructor(options: IStaticContextIdProcessorConstructorOptions) {\n\t\tGuards.object(StaticContextIdProcessor.CLASS_NAME, nameof(options), options);\n\t\tGuards.object<IStaticContextIdProcessorConfig>(\n\t\t\tStaticContextIdProcessor.CLASS_NAME,\n\t\t\tnameof(options.config),\n\t\t\toptions.config\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tStaticContextIdProcessor.CLASS_NAME,\n\t\t\tnameof(options.config.key),\n\t\t\toptions.config.key\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tStaticContextIdProcessor.CLASS_NAME,\n\t\t\tnameof(options.config.value),\n\t\t\toptions.config.value\n\t\t);\n\t\tthis._key = options.config.key;\n\t\tthis._value = options.config.value;\n\t\tthis._authOnly = options.config.authOnly ?? false;\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 StaticContextIdProcessor.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 * @returns A promise that resolves when the static context ID has been injected into the request.\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\tif (!this._authOnly || (!Is.empty(route) && !(route.skipAuth ?? false))) {\n\t\t\tcontextIds[this._key] = this._value;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"staticContextIdProcessor.js","sources":["../../../src/identity/staticContextIdProcessor.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC;AAK1C;;GAEG;AACH,MAAM,OAAO,wBAAwB;IACpC;;OAEG;IACI,MAAM,CAAU,UAAU,GAAW,0BAA0B,CAAC;IAEvE;;;OAGG;IACc,IAAI,CAAS;IAE9B;;;OAGG;IACc,MAAM,CAAS;IAEhC;;;OAGG;IACc,SAAS,CAAU;IAEpC;;;OAGG;IACH,YAAY,OAAoD;QAC/D,MAAM,CAAC,MAAM,CAAC,wBAAwB,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QACvE,MAAM,CAAC,MAAM,CACZ,wBAAwB,CAAC,UAAU,EACnC,gBAAgB,EAChB,OAAO,CAAC,MAAM,CACd,CAAC;QACF,MAAM,CAAC,WAAW,CACjB,wBAAwB,CAAC,UAAU,EACnC,oBAAoB,EACpB,OAAO,CAAC,MAAM,CAAC,GAAG,CAClB,CAAC;QACF,MAAM,CAAC,WAAW,CACjB,wBAAwB,CAAC,UAAU,EACnC,sBAAsB,EACtB,OAAO,CAAC,MAAM,CAAC,KAAK,CACpB,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,IAAI,KAAK,CAAC;IACnD,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,wBAAwB,CAAC,UAAU,CAAC;IAC5C,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,GAAG,CACf,OAA2B,EAC3B,QAAuB,EACvB,KAA6B,EAC7B,UAAuB,EACvB,cAAyC;QAEzC,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,QAAQ,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC;YACzE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;QACrC,CAAC;IACF,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIBaseRoute,\n\tIBaseRouteProcessor,\n\tIHttpResponse,\n\tIHttpServerRequest\n} from \"@3sixty/api-models\";\nimport type { IContextIds } from \"@3sixty/context\";\nimport { Guards, Is } from \"@3sixty/core\";\n\nimport type { IStaticContextIdProcessorConfig } from \"../models/IStaticContextIdProcessorConfig.js\";\nimport type { IStaticContextIdProcessorConstructorOptions } from \"../models/IStaticContextIdProcessorConstructorOptions.js\";\n\n/**\n * Adds a static context id to the request context.\n */\nexport class StaticContextIdProcessor implements IBaseRouteProcessor {\n\t/**\n\t * Runtime name for the class.\n\t */\n\tpublic static readonly CLASS_NAME: string = \"StaticContextIdProcessor\";\n\n\t/**\n\t * The fixed identity key for request context.\n\t * @internal\n\t */\n\tprivate readonly _key: string;\n\n\t/**\n\t * The fixed identity value for request context.\n\t * @internal\n\t */\n\tprivate readonly _value: string;\n\n\t/**\n\t * Only add the identity if the request is authenticated.\n\t * @internal\n\t */\n\tprivate readonly _authOnly: boolean;\n\n\t/**\n\t * Create a new instance of StaticContextIdProcessor.\n\t * @param options Options for the processor.\n\t */\n\tconstructor(options: IStaticContextIdProcessorConstructorOptions) {\n\t\tGuards.object(StaticContextIdProcessor.CLASS_NAME, \"options\", options);\n\t\tGuards.object<IStaticContextIdProcessorConfig>(\n\t\t\tStaticContextIdProcessor.CLASS_NAME,\n\t\t\t\"options.config\",\n\t\t\toptions.config\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tStaticContextIdProcessor.CLASS_NAME,\n\t\t\t\"options.config.key\",\n\t\t\toptions.config.key\n\t\t);\n\t\tGuards.stringValue(\n\t\t\tStaticContextIdProcessor.CLASS_NAME,\n\t\t\t\"options.config.value\",\n\t\t\toptions.config.value\n\t\t);\n\t\tthis._key = options.config.key;\n\t\tthis._value = options.config.value;\n\t\tthis._authOnly = options.config.authOnly ?? false;\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 StaticContextIdProcessor.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 * @returns A promise that resolves when the static context ID has been injected into the request.\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\tif (!this._authOnly || (!Is.empty(route) && !(route.skipAuth ?? false))) {\n\t\t\tcontextIds[this._key] = this._value;\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC;AACjD,cAAc,wCAAwC,CAAC;AACvD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uCAAuC,CAAC;AACtD,cAAc,oCAAoC,CAAC;AACnD,cAAc,uCAAuC,CAAC;AACtD,cAAc,mDAAmD,CAAC;AAClE,cAAc,qCAAqC,CAAC;AACpD,cAAc,iDAAiD,CAAC;AAChE,cAAc,mDAAmD,CAAC;AAClE,cAAc,mCAAmC,CAAC;AAClD,cAAc,qDAAqD,CAAC;AACpE,cAAc,6CAA6C,CAAC;AAC5D,cAAc,yDAAyD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./data/restRouteProcessor.js\";\nexport * from \"./data/socketRouteProcessor.js\";\nexport * from \"./identity/contextIdProcessor.js\";\nexport * from \"./identity/staticContextIdProcessor.js\";\nexport * from \"./logging/loggingProcessor.js\";\nexport * from \"./mimeType/jsonLdMimeTypeProcessor.js\";\nexport * from \"./mimeType/jwtMimeTypeProcessor.js\";\nexport * from \"./models/IContextIdProcessorConfig.js\";\nexport * from \"./models/IContextIdProcessorConstructorOptions.js\";\nexport * from \"./models/ILoggingProcessorConfig.js\";\nexport * from \"./models/ILoggingProcessorConstructorOptions.js\";\nexport * from \"./models/IRestRouteProcessorConstructorOptions.js\";\nexport * from \"./models/IRouteProcessorConfig.js\";\nexport * from \"./models/ISocketRouteProcessorConstructorOptions.js\";\nexport * from \"./models/IStaticContextIdProcessorConfig.js\";\nexport * from \"./models/IStaticContextIdProcessorConstructorOptions.js\";\n"]}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC;AACjD,cAAc,wCAAwC,CAAC;AACvD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uCAAuC,CAAC;AACtD,cAAc,oCAAoC,CAAC;AACnD,cAAc,uCAAuC,CAAC;AACtD,cAAc,mDAAmD,CAAC;AAClE,cAAc,qCAAqC,CAAC;AACpD,cAAc,iDAAiD,CAAC;AAChE,cAAc,mDAAmD,CAAC;AAClE,cAAc,mCAAmC,CAAC;AAClD,cAAc,qDAAqD,CAAC;AACpE,cAAc,6CAA6C,CAAC;AAC5D,cAAc,yDAAyD,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./data/restRouteProcessor.js\";\nexport * from \"./data/socketRouteProcessor.js\";\nexport * from \"./identity/contextIdProcessor.js\";\nexport * from \"./identity/staticContextIdProcessor.js\";\nexport * from \"./logging/loggingProcessor.js\";\nexport * from \"./mimeType/jsonLdMimeTypeProcessor.js\";\nexport * from \"./mimeType/jwtMimeTypeProcessor.js\";\nexport * from \"./models/IContextIdProcessorConfig.js\";\nexport * from \"./models/IContextIdProcessorConstructorOptions.js\";\nexport * from \"./models/ILoggingProcessorConfig.js\";\nexport * from \"./models/ILoggingProcessorConstructorOptions.js\";\nexport * from \"./models/IRestRouteProcessorConstructorOptions.js\";\nexport * from \"./models/IRouteProcessorConfig.js\";\nexport * from \"./models/ISocketRouteProcessorConstructorOptions.js\";\nexport * from \"./models/IStaticContextIdProcessorConfig.js\";\nexport * from \"./models/IStaticContextIdProcessorConstructorOptions.js\";\n"]}
@@ -1 +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,cAAc,CAAC;AAG1E,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGrE;;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;IACc,aAAa,CAAW;IAEzC;;;OAGG;IACH,YAAY,OAA6C;QACxD,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,W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CAAC,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;YACvD,CAAC;QACF,CAAC;aAAM,IAAI,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC;YACjC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC1C,SAAS,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACxD,CAAC;QACF,CAAC;aAAM,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;YACtF,SAAS,GAAG,UAAU,CAAC;QACxB,CAAC;aAAM,IACN,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC;YACpB,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAClE,CAAC;YACF,SAAS,GAAG,gBAAgB,CAAC;QAC9B,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACK,UAAU,CAAC,WAA0C;QAC5D,OAAO,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC;YACjC,CAAC,CAAC,WAAW,CAAC,QAAQ,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 \"@3sixty/api-models\";\nimport type { IContextIds } from \"@3sixty/context\";\nimport { Coerce, ComponentFactory, Is, ObjectHelper } from \"@3sixty/core\";\nimport type { ILoggingComponent } from \"@3sixty/logging-models\";\nimport { nameof } from \"@3sixty/nameof\";\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@3sixty/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 * Request URL path prefixes to skip logging, defaults to [\"/logging\"].\n\t * @internal\n\t */\n\tprivate readonly _excludePaths: 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);\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\tthis._excludePaths = options?.config?.excludePaths ?? [\"/logging\"];\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 * @returns A promise that resolves when the pre-processing log entry has been written.\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\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\tif (this._excludePaths.some(p => requestUrl.startsWith(p))) {\n\t\t\treturn;\n\t\t}\n\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\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: \"requestMessage\",\n\t\t\tdata: {\n\t\t\t\tmethod: request.method,\n\t\t\t\trequestUrl,\n\t\t\t\tbody:\n\t\t\t\t\tthis._includeBody && isJson\n\t\t\t\t\t\t? this.processJson(\"body\", ObjectHelper.clone(request?.body))\n\t\t\t\t\t\t: undefined\n\t\t\t}\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 * @returns A promise that resolves when the post-processing log entry has been written.\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 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\tif (this._excludePaths.some(p => requestUrl.startsWith(p))) {\n\t\t\treturn;\n\t\t}\n\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\tif (Is.number(response.statusCode) && response.statusCode >= HttpStatusCode.badRequest) {\n\t\t\tawait this._logging?.log({\n\t\t\t\tlevel: \"error\",\n\t\t\t\tsource: LoggingProcessor.CLASS_NAME,\n\t\t\t\tts: Date.now(),\n\t\t\t\tmessage: \"responseMessage\",\n\t\t\t\tdata: {\n\t\t\t\t\tstatusCode: response.statusCode,\n\t\t\t\t\tmethod: request.method,\n\t\t\t\t\trequestUrl: requestUrl ?? \"\",\n\t\t\t\t\telapsedMicroSeconds,\n\t\t\t\t\t...data\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tawait this._logging?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: LoggingProcessor.CLASS_NAME,\n\t\t\t\tts: Date.now(),\n\t\t\t\tmessage: \"responseMessage\",\n\t\t\t\tdata: {\n\t\t\t\t\tstatusCode: response.statusCode,\n\t\t\t\t\tmethod: request.method,\n\t\t\t\t\trequestUrl: requestUrl ?? \"\",\n\t\t\t\t\telapsedMicroSeconds,\n\t\t\t\t\t...data\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Process the JSON.\n\t * @param propName The property name to process.\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"]}
1
+ {"version":3,"file":"loggingProcessor.js","sources":["../../../src/logging/loggingProcessor.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAG1E,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGrE;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAC5B;;OAEG;IACI,MAAM,CAAU,UAAU,GAAW,kBAAkB,CAAC;IAE/D;;;OAGG;IACc,QAAQ,CAAqB;IAE9C;;;OAGG;IACc,YAAY,CAAU;IAEvC;;;OAGG;IACc,WAAW,CAAU;IAEtC;;;OAGG;IACc,oBAAoB,CAAW;IAEhD;;;OAGG;IACc,aAAa,CAAW;IAEzC;;;OAGG;IACH,YAAY,OAA6C;QACxD,IAAI,CAAC,QAAQ,GAAG,gBAAgB,CAAC,WAAW,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;QAC5E,IAAI,CAAC,YAAY,GAAG,OAAO,EAAE,MAAM,EAAE,WAAW,IAAI,KAAK,CAAC;QAC1D,IAAI,CAAC,WAAW,GAAG,OAAO,EAAE,MAAM,EAAE,UAAU,IAAI,KAAK,CAAC;QACxD,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,MAAM,EAAE,mBAAmB,IAAI,CAAC,UAAU,CAAC,CAAC;QACjF,IAAI,CAAC,aAAa,GAAG,OAAO,EAAE,MAAM,EAAE,YAAY,IAAI,CAAC,UAAU,CAAC,CAAC;IACpE,CAAC;IAED;;;OAGG;IACI,SAAS;QACf,OAAO,gBAAgB,CAAC,UAAU,CAAC;IACpC,CAAC;IAED;;;;;;;;OAQG;IACI,KAAK,CAAC,GAAG,CACf,OAA2B,EAC3B,QAAuB,EACvB,KAA6B,EAC7B,UAAuB,EACv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AI,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAClE,CAAC;YACF,SAAS,GAAG,gBAAgB,CAAC;QAC9B,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACK,UAAU,CAAC,WAA0C;QAC5D,OAAO,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC;YACjC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC;YAChF,CAAC,CAAC,KAAK,CAAC;IACV,CAAC;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type {\n\tIBaseRoute,\n\tIBaseRouteProcessor,\n\tIHttpResponse,\n\tIHttpServerRequest\n} from \"@3sixty/api-models\";\nimport type { IContextIds } from \"@3sixty/context\";\nimport { Coerce, ComponentFactory, Is, ObjectHelper } from \"@3sixty/core\";\nimport type { ILoggingComponent } from \"@3sixty/logging-models\";\n\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@3sixty/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 = \"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 * Request URL path prefixes to skip logging, defaults to [\"/logging\"].\n\t * @internal\n\t */\n\tprivate readonly _excludePaths: 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);\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\tthis._excludePaths = options?.config?.excludePaths ?? [\"/logging\"];\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 * @returns A promise that resolves when the pre-processing log entry has been written.\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\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\tif (this._excludePaths.some(p => requestUrl.startsWith(p))) {\n\t\t\treturn;\n\t\t}\n\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\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: \"requestMessage\",\n\t\t\tdata: {\n\t\t\t\tmethod: request.method,\n\t\t\t\trequestUrl,\n\t\t\t\tbody:\n\t\t\t\t\tthis._includeBody && isJson\n\t\t\t\t\t\t? this.processJson(\"body\", ObjectHelper.clone(request?.body))\n\t\t\t\t\t\t: undefined\n\t\t\t}\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 * @returns A promise that resolves when the post-processing log entry has been written.\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 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\tif (this._excludePaths.some(p => requestUrl.startsWith(p))) {\n\t\t\treturn;\n\t\t}\n\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\tif (Is.number(response.statusCode) && response.statusCode >= HttpStatusCode.badRequest) {\n\t\t\tawait this._logging?.log({\n\t\t\t\tlevel: \"error\",\n\t\t\t\tsource: LoggingProcessor.CLASS_NAME,\n\t\t\t\tts: Date.now(),\n\t\t\t\tmessage: \"responseMessage\",\n\t\t\t\tdata: {\n\t\t\t\t\tstatusCode: response.statusCode,\n\t\t\t\t\tmethod: request.method,\n\t\t\t\t\trequestUrl: requestUrl ?? \"\",\n\t\t\t\t\telapsedMicroSeconds,\n\t\t\t\t\t...data\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tawait this._logging?.log({\n\t\t\t\tlevel: \"info\",\n\t\t\t\tsource: LoggingProcessor.CLASS_NAME,\n\t\t\t\tts: Date.now(),\n\t\t\t\tmessage: \"responseMessage\",\n\t\t\t\tdata: {\n\t\t\t\t\tstatusCode: response.statusCode,\n\t\t\t\t\tmethod: request.method,\n\t\t\t\t\trequestUrl: requestUrl ?? \"\",\n\t\t\t\t\telapsedMicroSeconds,\n\t\t\t\t\t...data\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Process the JSON.\n\t * @param propName The property name to process.\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"]}
@@ -1 +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,cAAc,CAAC;AAE9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;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 \"@3sixty/api-models\";\nimport { GeneralError, Is, ObjectHelper } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport { MimeTypes } from \"@3sixty/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"]}
1
+ {"version":3,"file":"jsonLdMimeTypeProcessor.js","sources":["../../../src/mimeType/jsonLdMimeTypeProcessor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;GAEG;AACH,MAAM,OAAO,uBAAuB;IACnC;;OAEG;IACI,MAAM,CAAU,UAAU,GAAW,yBAAyB,CAAC;IAEtE;;;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;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IMimeTypeProcessor } from \"@3sixty/api-models\";\nimport { GeneralError, Is, ObjectHelper } from \"@3sixty/core\";\n\nimport { MimeTypes } from \"@3sixty/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 = \"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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"jwtMimeTypeProcessor.js","sourceRoot":"","sources":["../../../src/mimeType/jwtMimeTypeProcessor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;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 \"@3sixty/api-models\";\nimport { Converter } from \"@3sixty/core\";\nimport { nameof } from \"@3sixty/nameof\";\nimport { MimeTypes } from \"@3sixty/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"]}
1
+ {"version":3,"file":"jwtMimeTypeProcessor.js","sources":["../../../src/mimeType/jwtMimeTypeProcessor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAChC;;OAEG;IACI,MAAM,CAAU,UAAU,GAAW,sBAAsB,CAAC;IAEnE;;;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;CACD","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IMimeTypeProcessor } from \"@3sixty/api-models\";\nimport { Converter } from \"@3sixty/core\";\n\nimport { MimeTypes } from \"@3sixty/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 = \"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"]}
@@ -1 +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"]}
1
+ {"version":3,"file":"IContextIdProcessorConfig.js","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"]}
@@ -1 +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"]}
1
+ {"version":3,"file":"IContextIdProcessorConstructorOptions.js","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"]}
@@ -1 +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\t/**\n\t * Request URL path prefixes to exclude from logging, defaults to [\"/logging\"].\n\t * Use this to prevent the logging endpoint itself from appearing in its own output.\n\t */\n\texcludePaths?: string[];\n}\n"]}
1
+ {"version":3,"file":"ILoggingProcessorConfig.js","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\t/**\n\t * Request URL path prefixes to exclude from logging, defaults to [\"/logging\"].\n\t * Use this to prevent the logging endpoint itself from appearing in its own output.\n\t */\n\texcludePaths?: string[];\n}\n"]}
@@ -1 +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"]}
1
+ {"version":3,"file":"ILoggingProcessorConstructorOptions.js","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"]}
@@ -1 +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"]}
1
+ {"version":3,"file":"IRestRouteProcessorConstructorOptions.js","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"]}
@@ -1 +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"]}
1
+ {"version":3,"file":"IRouteProcessorConfig.js","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"]}
@@ -1 +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"]}
1
+ {"version":3,"file":"ISocketRouteProcessorConstructorOptions.js","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"]}
@@ -1 +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"]}
1
+ {"version":3,"file":"IStaticContextIdProcessorConfig.js","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"]}
@@ -1 +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
+ {"version":3,"file":"IStaticContextIdProcessorConstructorOptions.js","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"]}
package/docs/changelog.md CHANGED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ ## [0.20.0-next.1](https://github.com/3sixtyglobal/api/compare/api-processors-v0.20.0-next.0...api-processors-v0.20.0-next.1) (2026-10-23)
4
+
5
+
6
+ ### Features
7
+
8
+ * publish packages under the [@3sixty](https://github.com/3sixty) namespace ([91b1822](https://github.com/3sixtyglobal/api/commit/91b1822dba38f70692087ad4643572531d6634dc))
9
+ * updated ts compile ([d9a5c86](https://github.com/3sixtyglobal/api/commit/d9a5c86ec7dd1faf3045b5cd1e0d38a4b331313d))
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * The following workspace dependencies were updated
15
+ * dependencies
16
+ * @3sixty/api-models bumped from 0.20.0-next.0 to 0.20.0-next.1
@@ -114,6 +114,8 @@ The context IDs of the request.
114
114
 
115
115
  ##### processorState
116
116
 
117
+ \{\[`id`: `string`\]: `unknown`; \}
118
+
117
119
  The state handed through the processors.
118
120
 
119
121
  #### Returns
@@ -88,6 +88,8 @@ The context IDs of the request.
88
88
 
89
89
  ##### processorState
90
90
 
91
+ \{\[`id`: `string`\]: `unknown`; \}
92
+
91
93
  The state handed through the processors.
92
94
 
93
95
  #### Returns
@@ -136,6 +138,8 @@ The context IDs of the request.
136
138
 
137
139
  ##### processorState
138
140
 
141
+ \{\[`id`: `string`\]: `unknown`; \}
142
+
139
143
  The state handed through the processors.
140
144
 
141
145
  #### Returns
@@ -82,6 +82,8 @@ The route to process.
82
82
 
83
83
  ##### processorState
84
84
 
85
+ \{\[`id`: `string`\]: `unknown`; \}
86
+
85
87
  The state handed through the processors.
86
88
 
87
89
  ##### componentTypes?
@@ -158,6 +158,8 @@ The route to process.
158
158
 
159
159
  ##### processorState
160
160
 
161
+ \{\[`id`: `string`\]: `unknown`; \}
162
+
161
163
  The state handed through the processors.
162
164
 
163
165
  ##### responseEmitter
@@ -88,6 +88,8 @@ The context IDs of the request.
88
88
 
89
89
  ##### processorState
90
90
 
91
+ \{\[`id`: `string`\]: `unknown`; \}
92
+
91
93
  The state handed through the processors.
92
94
 
93
95
  #### Returns
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@3sixty/api-processors",
3
- "version": "0.20.0-next.0",
3
+ "version": "0.20.0-next.1",
4
4
  "description": "Reusable request and route processors for logging, context handling, and content negotiation.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "node": ">=24.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@3sixty/api-models": "0.20.0-next.0",
17
+ "@3sixty/api-models": "0.20.0-next.1",
18
18
  "@3sixty/context": "next",
19
19
  "@3sixty/core": "next",
20
20
  "@3sixty/logging-models": "next",