@twin.org/api-processors 0.0.3-next.15 → 0.0.3-next.16

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.
@@ -36,9 +36,11 @@ export class RestRouteProcessor {
36
36
  * @param response The outgoing response.
37
37
  * @param route The route to process.
38
38
  * @param processorState The state handed through the processors.
39
- * @param loggingComponentType The logging component type for the request.
39
+ * @param componentTypes The component types for the request.
40
+ * @param componentTypes.loggingComponentType The logging component type.
41
+ * @param componentTypes.hostingComponentType The hosting component type.
40
42
  */
41
- async process(request, response, route, processorState, loggingComponentType) {
43
+ async process(request, response, route, processorState, componentTypes) {
42
44
  // Don't handle the route if another processor has already set the response
43
45
  // status code e.g. from an auth processor
44
46
  if (Is.empty(response.statusCode)) {
@@ -62,7 +64,8 @@ export class RestRouteProcessor {
62
64
  const restRouteResponse = await route.handler({
63
65
  serverRequest: request,
64
66
  processorState,
65
- loggingComponentType
67
+ loggingComponentType: componentTypes?.loggingComponentType,
68
+ hostingComponentType: componentTypes?.hostingComponentType
66
69
  }, req);
67
70
  let statusCode = restRouteResponse.statusCode ?? response.statusCode ?? HttpStatusCode.ok;
68
71
  const headers = restRouteResponse?.headers ?? {};
@@ -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,sBAAsB,CAAC;AAC9B,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGvE;;GAEG;AACH,MAAM,OAAO,kBAAkB;IAC9B;;OAEG;IACI,MAAM,CAAU,UAAU,wBAAwC;IAEzE;;;OAGG;IACc,kBAAkB,CAAU;IAE7C;;;OAGG;IACH,YAAY,OAA+C;QAC1D,IA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CAAC;4BAC5C,MAAM,aAAa,GAAG,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC;4BACpD,OAAO,CAAC,WAAW,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC,QAAQ,EAAE,CAAC;wBAC/D,CAAC;wBAED,QAAQ,CAAC,IAAI,GAAG,iBAAiB,EAAE,IAAI,CAAC;oBACzC,CAAC;oBAED,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;oBAC3B,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;gBAClC,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,CAAC,CAAC;gBAChE,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 \"@twin.org/api-models\";\nimport { Is, NotFoundError } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@twin.org/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 loggingComponentType The logging component type for the request.\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\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: `${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);\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\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);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"restRouteProcessor.js","sourceRoot":"","sources":["../../../src/data/restRouteProcessor.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EACN,eAAe,EAOf,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAGvE;;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,CA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,WAAW,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC,QAAQ,EAAE,CAAC;wBAC/D,CAAC;wBAED,QAAQ,CAAC,IAAI,GAAG,iBAAiB,EAAE,IAAI,CAAC;oBACzC,CAAC;oBAED,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;oBAC3B,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;gBAClC,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,CAAC,CAAC;gBAChE,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 \"@twin.org/api-models\";\nimport { Is, NotFoundError } from \"@twin.org/core\";\nimport { nameof } from \"@twin.org/nameof\";\nimport { HeaderTypes, HttpStatusCode, MimeTypes } from \"@twin.org/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 * @param componentTypes.hostingComponentType The hosting component type.\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\thostingComponentType?: 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);\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\thostingComponentType: componentTypes?.hostingComponentType\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);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -24,9 +24,14 @@ export declare class RestRouteProcessor implements IRestRouteProcessor {
24
24
  * @param response The outgoing response.
25
25
  * @param route The route to process.
26
26
  * @param processorState The state handed through the processors.
27
- * @param loggingComponentType The logging component type for the request.
27
+ * @param componentTypes The component types for the request.
28
+ * @param componentTypes.loggingComponentType The logging component type.
29
+ * @param componentTypes.hostingComponentType The hosting component type.
28
30
  */
29
31
  process(request: IHttpServerRequest, response: IHttpResponse, route: IRestRoute | undefined, processorState: {
30
32
  [id: string]: unknown;
31
- }, loggingComponentType?: string): Promise<void>;
33
+ }, componentTypes?: {
34
+ loggingComponentType?: string;
35
+ hostingComponentType?: string;
36
+ }): Promise<void>;
32
37
  }
package/docs/changelog.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @twin.org/api-processors - Changelog
2
2
 
3
+ ## [0.0.3-next.16](https://github.com/twinfoundation/api/compare/api-processors-v0.0.3-next.15...api-processors-v0.0.3-next.16) (2026-01-26)
4
+
5
+
6
+ ### Features
7
+
8
+ * public base url ([#70](https://github.com/twinfoundation/api/issues/70)) ([5b958cd](https://github.com/twinfoundation/api/commit/5b958cd91e8a38cdae2835ff5f2356c7e48d37c3))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * dependencies
15
+ * @twin.org/api-models bumped from 0.0.3-next.15 to 0.0.3-next.16
16
+
3
17
  ## [0.0.3-next.15](https://github.com/twinfoundation/api/compare/api-processors-v0.0.3-next.14...api-processors-v0.0.3-next.15) (2026-01-22)
4
18
 
5
19
 
@@ -56,7 +56,7 @@ The class name of the component.
56
56
 
57
57
  ### process()
58
58
 
59
- > **process**(`request`, `response`, `route`, `processorState`, `loggingComponentType?`): `Promise`\<`void`\>
59
+ > **process**(`request`, `response`, `route`, `processorState`, `componentTypes?`): `Promise`\<`void`\>
60
60
 
61
61
  Process the REST request for the specified route.
62
62
 
@@ -84,11 +84,21 @@ The route to process.
84
84
 
85
85
  The state handed through the processors.
86
86
 
87
- ##### loggingComponentType?
87
+ ##### componentTypes?
88
+
89
+ The component types for the request.
90
+
91
+ ###### loggingComponentType?
92
+
93
+ `string`
94
+
95
+ The logging component type.
96
+
97
+ ###### hostingComponentType?
88
98
 
89
99
  `string`
90
100
 
91
- The logging component type for the request.
101
+ The hosting component type.
92
102
 
93
103
  #### Returns
94
104
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/api-processors",
3
- "version": "0.0.3-next.15",
3
+ "version": "0.0.3-next.16",
4
4
  "description": "Route processors for use with API servers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,7 +14,7 @@
14
14
  "node": ">=20.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@twin.org/api-models": "0.0.3-next.15",
17
+ "@twin.org/api-models": "0.0.3-next.16",
18
18
  "@twin.org/context": "next",
19
19
  "@twin.org/core": "next",
20
20
  "@twin.org/logging-models": "next",