@twin.org/api-models 0.0.3-next.20 → 0.0.3-next.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ISocketRouteProcessor.js","sourceRoot":"","sources":["../../../../src/models/server/ISocketRouteProcessor.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IBaseRouteProcessor } from \"./IBaseRouteProcessor.js\";\nimport type { IHttpResponse } from \"../protocol/IHttpResponse.js\";\nimport type { ISocketServerRequest } from \"../protocol/ISocketServerRequest.js\";\nimport type { ISocketRoute } from \"../routes/ISocketRoute.js\";\n\n/**\n * The definition for a processor for handling socket routes.\n */\nexport interface ISocketRouteProcessor\n\
|
|
1
|
+
{"version":3,"file":"ISocketRouteProcessor.js","sourceRoot":"","sources":["../../../../src/models/server/ISocketRouteProcessor.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IBaseRouteProcessor } from \"./IBaseRouteProcessor.js\";\nimport type { IHttpResponse } from \"../protocol/IHttpResponse.js\";\nimport type { ISocketServerRequest } from \"../protocol/ISocketServerRequest.js\";\nimport type { ISocketRoute } from \"../routes/ISocketRoute.js\";\n\n/**\n * The definition for a processor for handling socket routes.\n */\nexport interface ISocketRouteProcessor extends IBaseRouteProcessor<\n\tISocketRoute,\n\tISocketServerRequest\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\tconnected?(\n\t\trequest: ISocketServerRequest,\n\t\troute: ISocketRoute | undefined,\n\t\tloggingComponentType?: string\n\t): Promise<void>;\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\tdisconnected?(\n\t\trequest: ISocketServerRequest,\n\t\troute: ISocketRoute | undefined,\n\t\tloggingComponentType?: string\n\t): Promise<void>;\n\n\t/**\n\t * Process the REST request for the specified route.\n\t * @param request The server request object containing the socket id and other parameters.\n\t * @param response The response data to send if any.\n\t * @param route The route being requested, if a matching one was found.\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 Promise that resolves when the request is processed.\n\t */\n\tprocess?(\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}\n"]}
|
package/docs/changelog.md
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.0.3-next.21](https://github.com/twinfoundation/api/compare/api-models-v0.0.3-next.20...api-models-v0.0.3-next.21) (2026-03-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **api-models:** Synchronize repo versions
|
|
2
9
|
|
|
3
10
|
## [0.0.3-next.20](https://github.com/twinfoundation/api/compare/api-models-v0.0.3-next.19...api-models-v0.0.3-next.20) (2026-02-09)
|
|
4
11
|
|
package/docs/examples.md
CHANGED
|
@@ -1 +1,63 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Models Examples
|
|
2
|
+
|
|
3
|
+
These snippets show practical helpers for URL manipulation, request parameter conversion, and consistent error responses.
|
|
4
|
+
|
|
5
|
+
## HttpUrlHelper
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { HttpUrlHelper } from '@twin.org/api-models';
|
|
9
|
+
|
|
10
|
+
const fullUrl = 'https://tenant.example.org/orders?page=2';
|
|
11
|
+
|
|
12
|
+
console.log(HttpUrlHelper.extractOrigin(fullUrl)); // https://tenant.example.org
|
|
13
|
+
console.log(HttpUrlHelper.extractPath(fullUrl)); // /orders
|
|
14
|
+
console.log(HttpUrlHelper.extractSearch(fullUrl)); // ?page=2
|
|
15
|
+
console.log(HttpUrlHelper.extractPathAndSearch(fullUrl)); // /orders?page=2
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { HttpUrlHelper } from '@twin.org/api-models';
|
|
20
|
+
|
|
21
|
+
const combined = HttpUrlHelper.combineParts('https://tenant.example.org/', '/api/v1/orders');
|
|
22
|
+
const replaced = HttpUrlHelper.replaceOrigin(combined ?? '', 'https://edge.example.org');
|
|
23
|
+
|
|
24
|
+
console.log(combined); // https://tenant.example.org/api/v1/orders
|
|
25
|
+
console.log(replaced); // https://edge.example.org/api/v1/orders
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## HttpParameterHelper
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { HttpParameterHelper } from '@twin.org/api-models';
|
|
32
|
+
|
|
33
|
+
const ids = HttpParameterHelper.arrayFromString('id-1,id-2,id-3');
|
|
34
|
+
const idsAsString = HttpParameterHelper.arrayToString(ids);
|
|
35
|
+
|
|
36
|
+
const filterObject = HttpParameterHelper.objectFromString('{"status":"active"}');
|
|
37
|
+
const filterString = HttpParameterHelper.objectToString(filterObject);
|
|
38
|
+
|
|
39
|
+
console.log(ids.length); // 3
|
|
40
|
+
console.log(idsAsString); // id-1,id-2,id-3
|
|
41
|
+
console.log(filterString); // {"status":"active"}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## HttpErrorHelper
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { HttpErrorHelper } from '@twin.org/api-models';
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
throw new Error('Invalid request');
|
|
51
|
+
} catch (err) {
|
|
52
|
+
const mapped = HttpErrorHelper.processError(err, false);
|
|
53
|
+
const response: {
|
|
54
|
+
body?: unknown;
|
|
55
|
+
statusCode?: number;
|
|
56
|
+
headers?: { [id: string]: string };
|
|
57
|
+
} = {};
|
|
58
|
+
HttpErrorHelper.buildResponse(response, mapped.error, mapped.httpStatusCode);
|
|
59
|
+
|
|
60
|
+
console.log(response.statusCode); // 500
|
|
61
|
+
console.log(mapped.error.message); // Error: Invalid request
|
|
62
|
+
}
|
|
63
|
+
```
|
|
@@ -10,12 +10,6 @@ Options for the web server.
|
|
|
10
10
|
|
|
11
11
|
The port to bind the web server to.
|
|
12
12
|
|
|
13
|
-
#### Default
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
3000
|
|
17
|
-
```
|
|
18
|
-
|
|
19
13
|
***
|
|
20
14
|
|
|
21
15
|
### host?
|
|
@@ -24,12 +18,6 @@ The port to bind the web server to.
|
|
|
24
18
|
|
|
25
19
|
The address to bind the web server to.
|
|
26
20
|
|
|
27
|
-
#### Default
|
|
28
|
-
|
|
29
|
-
```ts
|
|
30
|
-
localhost
|
|
31
|
-
```
|
|
32
|
-
|
|
33
21
|
***
|
|
34
22
|
|
|
35
23
|
### methods?
|
|
@@ -38,12 +26,6 @@ localhost
|
|
|
38
26
|
|
|
39
27
|
The methods that the server accepts.
|
|
40
28
|
|
|
41
|
-
#### Default
|
|
42
|
-
|
|
43
|
-
```ts
|
|
44
|
-
["GET", "PUT", "POST", "DELETE", "OPTIONS"]
|
|
45
|
-
```
|
|
46
|
-
|
|
47
29
|
***
|
|
48
30
|
|
|
49
31
|
### allowedHeaders?
|
|
@@ -67,9 +49,3 @@ And additional exposed headers.
|
|
|
67
49
|
> `optional` **corsOrigins**: `string` \| `string`[]
|
|
68
50
|
|
|
69
51
|
The allowed CORS domains.
|
|
70
|
-
|
|
71
|
-
#### Default
|
|
72
|
-
|
|
73
|
-
```ts
|
|
74
|
-
["*"]
|
|
75
|
-
```
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/api-models",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.21",
|
|
4
|
+
"description": "Shared API contracts, route types, and response models used across services and clients.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/twinfoundation/api.git",
|