@twin.org/api-processors 0.0.2-next.2 → 0.0.2-next.3

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.
@@ -11,10 +11,6 @@ var loggingModels = require('@twin.org/logging-models');
11
11
  * Process the REST request and hands it on to the route handler.
12
12
  */
13
13
  class RestRouteProcessor {
14
- /**
15
- * The namespace supported by the processor.
16
- */
17
- static NAMESPACE = "rest-route";
18
14
  /**
19
15
  * Runtime name for the class.
20
16
  */
@@ -120,10 +116,6 @@ class RestRouteProcessor {
120
116
  * Process the socket request and hands it on to the route handler.
121
117
  */
122
118
  class SocketRouteProcessor {
123
- /**
124
- * The namespace supported by the processor.
125
- */
126
- static NAMESPACE = "socket-route";
127
119
  /**
128
120
  * Runtime name for the class.
129
121
  */
@@ -140,6 +132,54 @@ class SocketRouteProcessor {
140
132
  constructor(options) {
141
133
  this._includeErrorStack = options?.config?.includeErrorStack ?? false;
142
134
  }
135
+ /**
136
+ * Process the connected event.
137
+ * @param request The server request object containing the socket id and other parameters.
138
+ * @param route The route being requested, if a matching one was found.
139
+ * @returns Promise that resolves when the request is processed.
140
+ */
141
+ async connected(request, route) {
142
+ if (route?.connected) {
143
+ try {
144
+ const req = {
145
+ pathParams: request.pathParams,
146
+ query: request.query,
147
+ body: request.body
148
+ };
149
+ const socketRequestContext = {
150
+ socketId: request.socketId,
151
+ serverRequest: req,
152
+ processorState: {}
153
+ };
154
+ await route.connected(socketRequestContext);
155
+ }
156
+ catch { }
157
+ }
158
+ }
159
+ /**
160
+ * Process the disconnected event.
161
+ * @param request The server request object containing the socket id and other parameters.
162
+ * @param route The route being requested, if a matching one was found.
163
+ * @returns Promise that resolves when the request is processed.
164
+ */
165
+ async disconnected(request, route) {
166
+ if (route?.disconnected) {
167
+ try {
168
+ const req = {
169
+ pathParams: request.pathParams,
170
+ query: request.query,
171
+ body: request.body
172
+ };
173
+ const socketRequestContext = {
174
+ socketId: request.socketId,
175
+ serverRequest: req,
176
+ processorState: {}
177
+ };
178
+ await route.disconnected(socketRequestContext);
179
+ }
180
+ catch { }
181
+ }
182
+ }
143
183
  /**
144
184
  * Process the REST request for the specified route.
145
185
  * @param request The incoming request.
@@ -169,11 +209,13 @@ class SocketRouteProcessor {
169
209
  query: request.query,
170
210
  body: request.body
171
211
  };
172
- await route.handler({
212
+ const socketRequestContext = {
173
213
  ...requestIdentity,
214
+ socketId: request.socketId,
174
215
  serverRequest: request,
175
216
  processorState
176
- }, req, async (topic, restRouteResponse) => {
217
+ };
218
+ await route.handler(socketRequestContext, req, async (topic, restRouteResponse) => {
177
219
  response.headers = restRouteResponse?.headers;
178
220
  response.body = restRouteResponse?.body;
179
221
  response.statusCode =
@@ -194,10 +236,6 @@ class SocketRouteProcessor {
194
236
  * Adds a node identity to the request identity.
195
237
  */
196
238
  class NodeIdentityProcessor {
197
- /**
198
- * The namespace supported by the processor.
199
- */
200
- static NAMESPACE = "node-identity";
201
239
  /**
202
240
  * Runtime name for the class.
203
241
  */
@@ -234,10 +272,6 @@ class NodeIdentityProcessor {
234
272
  * Adds a static user identity to the request context.
235
273
  */
236
274
  class StaticUserIdentityProcessor {
237
- /**
238
- * The namespace supported by the processor.
239
- */
240
- static NAMESPACE = "static-user-identity";
241
275
  /**
242
276
  * Runtime name for the class.
243
277
  */
@@ -276,10 +310,6 @@ class StaticUserIdentityProcessor {
276
310
  * Process the REST request and log its information.
277
311
  */
278
312
  class LoggingProcessor {
279
- /**
280
- * The namespace supported by the processor.
281
- */
282
- static NAMESPACE = "logging";
283
313
  /**
284
314
  * Runtime name for the class.
285
315
  */
@@ -441,10 +471,6 @@ class LoggingProcessor {
441
471
  * Process the JSON-LD mime type.
442
472
  */
443
473
  class JsonLdMimeTypeProcessor {
444
- /**
445
- * The namespace supported by the processor.
446
- */
447
- static NAMESPACE = "json-ld";
448
474
  /**
449
475
  * Runtime name for the class.
450
476
  */
@@ -474,10 +500,6 @@ class JsonLdMimeTypeProcessor {
474
500
  * Process the JWT mime type.
475
501
  */
476
502
  class JwtMimeTypeProcessor {
477
- /**
478
- * The namespace supported by the processor.
479
- */
480
- static NAMESPACE = "jwt";
481
503
  /**
482
504
  * Runtime name for the class.
483
505
  */
@@ -9,10 +9,6 @@ import { LoggingConnectorFactory } from '@twin.org/logging-models';
9
9
  * Process the REST request and hands it on to the route handler.
10
10
  */
11
11
  class RestRouteProcessor {
12
- /**
13
- * The namespace supported by the processor.
14
- */
15
- static NAMESPACE = "rest-route";
16
12
  /**
17
13
  * Runtime name for the class.
18
14
  */
@@ -118,10 +114,6 @@ class RestRouteProcessor {
118
114
  * Process the socket request and hands it on to the route handler.
119
115
  */
120
116
  class SocketRouteProcessor {
121
- /**
122
- * The namespace supported by the processor.
123
- */
124
- static NAMESPACE = "socket-route";
125
117
  /**
126
118
  * Runtime name for the class.
127
119
  */
@@ -138,6 +130,54 @@ class SocketRouteProcessor {
138
130
  constructor(options) {
139
131
  this._includeErrorStack = options?.config?.includeErrorStack ?? false;
140
132
  }
133
+ /**
134
+ * Process the connected event.
135
+ * @param request The server request object containing the socket id and other parameters.
136
+ * @param route The route being requested, if a matching one was found.
137
+ * @returns Promise that resolves when the request is processed.
138
+ */
139
+ async connected(request, route) {
140
+ if (route?.connected) {
141
+ try {
142
+ const req = {
143
+ pathParams: request.pathParams,
144
+ query: request.query,
145
+ body: request.body
146
+ };
147
+ const socketRequestContext = {
148
+ socketId: request.socketId,
149
+ serverRequest: req,
150
+ processorState: {}
151
+ };
152
+ await route.connected(socketRequestContext);
153
+ }
154
+ catch { }
155
+ }
156
+ }
157
+ /**
158
+ * Process the disconnected event.
159
+ * @param request The server request object containing the socket id and other parameters.
160
+ * @param route The route being requested, if a matching one was found.
161
+ * @returns Promise that resolves when the request is processed.
162
+ */
163
+ async disconnected(request, route) {
164
+ if (route?.disconnected) {
165
+ try {
166
+ const req = {
167
+ pathParams: request.pathParams,
168
+ query: request.query,
169
+ body: request.body
170
+ };
171
+ const socketRequestContext = {
172
+ socketId: request.socketId,
173
+ serverRequest: req,
174
+ processorState: {}
175
+ };
176
+ await route.disconnected(socketRequestContext);
177
+ }
178
+ catch { }
179
+ }
180
+ }
141
181
  /**
142
182
  * Process the REST request for the specified route.
143
183
  * @param request The incoming request.
@@ -167,11 +207,13 @@ class SocketRouteProcessor {
167
207
  query: request.query,
168
208
  body: request.body
169
209
  };
170
- await route.handler({
210
+ const socketRequestContext = {
171
211
  ...requestIdentity,
212
+ socketId: request.socketId,
172
213
  serverRequest: request,
173
214
  processorState
174
- }, req, async (topic, restRouteResponse) => {
215
+ };
216
+ await route.handler(socketRequestContext, req, async (topic, restRouteResponse) => {
175
217
  response.headers = restRouteResponse?.headers;
176
218
  response.body = restRouteResponse?.body;
177
219
  response.statusCode =
@@ -192,10 +234,6 @@ class SocketRouteProcessor {
192
234
  * Adds a node identity to the request identity.
193
235
  */
194
236
  class NodeIdentityProcessor {
195
- /**
196
- * The namespace supported by the processor.
197
- */
198
- static NAMESPACE = "node-identity";
199
237
  /**
200
238
  * Runtime name for the class.
201
239
  */
@@ -232,10 +270,6 @@ class NodeIdentityProcessor {
232
270
  * Adds a static user identity to the request context.
233
271
  */
234
272
  class StaticUserIdentityProcessor {
235
- /**
236
- * The namespace supported by the processor.
237
- */
238
- static NAMESPACE = "static-user-identity";
239
273
  /**
240
274
  * Runtime name for the class.
241
275
  */
@@ -274,10 +308,6 @@ class StaticUserIdentityProcessor {
274
308
  * Process the REST request and log its information.
275
309
  */
276
310
  class LoggingProcessor {
277
- /**
278
- * The namespace supported by the processor.
279
- */
280
- static NAMESPACE = "logging";
281
311
  /**
282
312
  * Runtime name for the class.
283
313
  */
@@ -439,10 +469,6 @@ class LoggingProcessor {
439
469
  * Process the JSON-LD mime type.
440
470
  */
441
471
  class JsonLdMimeTypeProcessor {
442
- /**
443
- * The namespace supported by the processor.
444
- */
445
- static NAMESPACE = "json-ld";
446
472
  /**
447
473
  * Runtime name for the class.
448
474
  */
@@ -472,10 +498,6 @@ class JsonLdMimeTypeProcessor {
472
498
  * Process the JWT mime type.
473
499
  */
474
500
  class JwtMimeTypeProcessor {
475
- /**
476
- * The namespace supported by the processor.
477
- */
478
- static NAMESPACE = "jwt";
479
501
  /**
480
502
  * Runtime name for the class.
481
503
  */
@@ -4,10 +4,6 @@ import type { IRestRouteProcessorConstructorOptions } from "../models/IRestRoute
4
4
  * Process the REST request and hands it on to the route handler.
5
5
  */
6
6
  export declare class RestRouteProcessor implements IRestRouteProcessor {
7
- /**
8
- * The namespace supported by the processor.
9
- */
10
- static readonly NAMESPACE: string;
11
7
  /**
12
8
  * Runtime name for the class.
13
9
  */
@@ -1,13 +1,9 @@
1
- import { type IHttpRequestIdentity, type IHttpResponse, type IHttpServerRequest, type ISocketRoute, type ISocketRouteProcessor } from "@twin.org/api-models";
1
+ import { type IHttpRequestIdentity, type IHttpResponse, type ISocketRoute, type ISocketRouteProcessor, type ISocketServerRequest } from "@twin.org/api-models";
2
2
  import type { ISocketRouteProcessorConstructorOptions } from "../models/ISocketRouteProcessorConstructorOptions";
3
3
  /**
4
4
  * Process the socket request and hands it on to the route handler.
5
5
  */
6
6
  export declare class SocketRouteProcessor implements ISocketRouteProcessor {
7
- /**
8
- * The namespace supported by the processor.
9
- */
10
- static readonly NAMESPACE: string;
11
7
  /**
12
8
  * Runtime name for the class.
13
9
  */
@@ -17,6 +13,20 @@ export declare class SocketRouteProcessor implements ISocketRouteProcessor {
17
13
  * @param options Options for the processor.
18
14
  */
19
15
  constructor(options?: ISocketRouteProcessorConstructorOptions);
16
+ /**
17
+ * Process the connected event.
18
+ * @param request The server request object containing the socket id and other parameters.
19
+ * @param route The route being requested, if a matching one was found.
20
+ * @returns Promise that resolves when the request is processed.
21
+ */
22
+ connected(request: ISocketServerRequest, route: ISocketRoute | undefined): Promise<void>;
23
+ /**
24
+ * Process the disconnected event.
25
+ * @param request The server request object containing the socket id and other parameters.
26
+ * @param route The route being requested, if a matching one was found.
27
+ * @returns Promise that resolves when the request is processed.
28
+ */
29
+ disconnected(request: ISocketServerRequest, route: ISocketRoute | undefined): Promise<void>;
20
30
  /**
21
31
  * Process the REST request for the specified route.
22
32
  * @param request The incoming request.
@@ -26,7 +36,7 @@ export declare class SocketRouteProcessor implements ISocketRouteProcessor {
26
36
  * @param processorState The state handed through the processors.
27
37
  * @param responseEmitter The function to emit a response.
28
38
  */
29
- process(request: IHttpServerRequest, response: IHttpResponse, route: ISocketRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
39
+ process(request: ISocketServerRequest, response: IHttpResponse, route: ISocketRoute | undefined, requestIdentity: IHttpRequestIdentity, processorState: {
30
40
  [id: string]: unknown;
31
41
  }, responseEmitter: (topic: string, response: IHttpResponse) => Promise<void>): Promise<void>;
32
42
  }
@@ -3,10 +3,6 @@ import type { IBaseRoute, IBaseRouteProcessor, IHttpRequestIdentity, IHttpRespon
3
3
  * Adds a node identity to the request identity.
4
4
  */
5
5
  export declare class NodeIdentityProcessor implements IBaseRouteProcessor {
6
- /**
7
- * The namespace supported by the processor.
8
- */
9
- static readonly NAMESPACE: string;
10
6
  /**
11
7
  * Runtime name for the class.
12
8
  */
@@ -4,10 +4,6 @@ import type { IStaticUserIdentityProcessorConstructorOptions } from "../models/I
4
4
  * Adds a static user identity to the request context.
5
5
  */
6
6
  export declare class StaticUserIdentityProcessor implements IBaseRouteProcessor {
7
- /**
8
- * The namespace supported by the processor.
9
- */
10
- static readonly NAMESPACE: string;
11
7
  /**
12
8
  * Runtime name for the class.
13
9
  */
@@ -4,10 +4,6 @@ import type { ILoggingProcessorConstructorOptions } from "../models/ILoggingProc
4
4
  * Process the REST request and log its information.
5
5
  */
6
6
  export declare class LoggingProcessor implements IBaseRouteProcessor {
7
- /**
8
- * The namespace supported by the processor.
9
- */
10
- static readonly NAMESPACE: string;
11
7
  /**
12
8
  * Runtime name for the class.
13
9
  */
@@ -3,10 +3,6 @@ import type { IMimeTypeProcessor } from "@twin.org/api-models";
3
3
  * Process the JSON-LD mime type.
4
4
  */
5
5
  export declare class JsonLdMimeTypeProcessor implements IMimeTypeProcessor {
6
- /**
7
- * The namespace supported by the processor.
8
- */
9
- static readonly NAMESPACE: string;
10
6
  /**
11
7
  * Runtime name for the class.
12
8
  */
@@ -3,10 +3,6 @@ import type { IMimeTypeProcessor } from "@twin.org/api-models";
3
3
  * Process the JWT mime type.
4
4
  */
5
5
  export declare class JwtMimeTypeProcessor implements IMimeTypeProcessor {
6
- /**
7
- * The namespace supported by the processor.
8
- */
9
- static readonly NAMESPACE: string;
10
6
  /**
11
7
  * Runtime name for the class.
12
8
  */
package/docs/changelog.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @twin.org/api-processors - Changelog
2
2
 
3
+ ## [0.0.2-next.3](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.2...api-processors-v0.0.2-next.3) (2025-07-24)
4
+
5
+
6
+ ### Features
7
+
8
+ * add socket id, connect and disconnect ([20b0d0e](https://github.com/twinfoundation/api/commit/20b0d0ec279cab46141fee09de2c4a7087cdce16))
9
+ * remove unused namespace ([08478f2](https://github.com/twinfoundation/api/commit/08478f27efda9beb0271fdb22f6972e918361965))
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * The following workspace dependencies were updated
15
+ * dependencies
16
+ * @twin.org/api-models bumped from 0.0.2-next.2 to 0.0.2-next.3
17
+
3
18
  ## [0.0.2-next.2](https://github.com/twinfoundation/api/compare/api-processors-v0.0.2-next.1...api-processors-v0.0.2-next.2) (2025-07-17)
4
19
 
5
20
 
@@ -18,14 +18,6 @@ Process the JSON-LD mime type.
18
18
 
19
19
  ## Properties
20
20
 
21
- ### NAMESPACE
22
-
23
- > `readonly` `static` **NAMESPACE**: `string` = `"json-ld"`
24
-
25
- The namespace supported by the processor.
26
-
27
- ***
28
-
29
21
  ### CLASS\_NAME
30
22
 
31
23
  > `readonly` **CLASS\_NAME**: `string`
@@ -18,14 +18,6 @@ Process the JWT mime type.
18
18
 
19
19
  ## Properties
20
20
 
21
- ### NAMESPACE
22
-
23
- > `readonly` `static` **NAMESPACE**: `string` = `"jwt"`
24
-
25
- The namespace supported by the processor.
26
-
27
- ***
28
-
29
21
  ### CLASS\_NAME
30
22
 
31
23
  > `readonly` **CLASS\_NAME**: `string`
@@ -28,14 +28,6 @@ Options for the processor.
28
28
 
29
29
  ## Properties
30
30
 
31
- ### NAMESPACE
32
-
33
- > `readonly` `static` **NAMESPACE**: `string` = `"logging"`
34
-
35
- The namespace supported by the processor.
36
-
37
- ***
38
-
39
31
  ### CLASS\_NAME
40
32
 
41
33
  > `readonly` **CLASS\_NAME**: `string`
@@ -18,14 +18,6 @@ Adds a node identity to the request identity.
18
18
 
19
19
  ## Properties
20
20
 
21
- ### NAMESPACE
22
-
23
- > `readonly` `static` **NAMESPACE**: `string` = `"node-identity"`
24
-
25
- The namespace supported by the processor.
26
-
27
- ***
28
-
29
21
  ### CLASS\_NAME
30
22
 
31
23
  > `readonly` **CLASS\_NAME**: `string`
@@ -28,14 +28,6 @@ Options for the processor.
28
28
 
29
29
  ## Properties
30
30
 
31
- ### NAMESPACE
32
-
33
- > `readonly` `static` **NAMESPACE**: `string` = `"rest-route"`
34
-
35
- The namespace supported by the processor.
36
-
37
- ***
38
-
39
31
  ### CLASS\_NAME
40
32
 
41
33
  > `readonly` **CLASS\_NAME**: `string`
@@ -28,14 +28,6 @@ Options for the processor.
28
28
 
29
29
  ## Properties
30
30
 
31
- ### NAMESPACE
32
-
33
- > `readonly` `static` **NAMESPACE**: `string` = `"socket-route"`
34
-
35
- The namespace supported by the processor.
36
-
37
- ***
38
-
39
31
  ### CLASS\_NAME
40
32
 
41
33
  > `readonly` **CLASS\_NAME**: `string`
@@ -48,6 +40,70 @@ Runtime name for the class.
48
40
 
49
41
  ## Methods
50
42
 
43
+ ### connected()
44
+
45
+ > **connected**(`request`, `route`): `Promise`\<`void`\>
46
+
47
+ Process the connected event.
48
+
49
+ #### Parameters
50
+
51
+ ##### request
52
+
53
+ `ISocketServerRequest`
54
+
55
+ The server request object containing the socket id and other parameters.
56
+
57
+ ##### route
58
+
59
+ The route being requested, if a matching one was found.
60
+
61
+ `undefined` | `ISocketRoute`\<`any`, `any`\>
62
+
63
+ #### Returns
64
+
65
+ `Promise`\<`void`\>
66
+
67
+ Promise that resolves when the request is processed.
68
+
69
+ #### Implementation of
70
+
71
+ `ISocketRouteProcessor.connected`
72
+
73
+ ***
74
+
75
+ ### disconnected()
76
+
77
+ > **disconnected**(`request`, `route`): `Promise`\<`void`\>
78
+
79
+ Process the disconnected event.
80
+
81
+ #### Parameters
82
+
83
+ ##### request
84
+
85
+ `ISocketServerRequest`
86
+
87
+ The server request object containing the socket id and other parameters.
88
+
89
+ ##### route
90
+
91
+ The route being requested, if a matching one was found.
92
+
93
+ `undefined` | `ISocketRoute`\<`any`, `any`\>
94
+
95
+ #### Returns
96
+
97
+ `Promise`\<`void`\>
98
+
99
+ Promise that resolves when the request is processed.
100
+
101
+ #### Implementation of
102
+
103
+ `ISocketRouteProcessor.disconnected`
104
+
105
+ ***
106
+
51
107
  ### process()
52
108
 
53
109
  > **process**(`request`, `response`, `route`, `requestIdentity`, `processorState`, `responseEmitter`): `Promise`\<`void`\>
@@ -58,7 +114,7 @@ Process the REST request for the specified route.
58
114
 
59
115
  ##### request
60
116
 
61
- `IHttpServerRequest`
117
+ `ISocketServerRequest`
62
118
 
63
119
  The incoming request.
64
120
 
@@ -28,14 +28,6 @@ Options for the processor.
28
28
 
29
29
  ## Properties
30
30
 
31
- ### NAMESPACE
32
-
33
- > `readonly` `static` **NAMESPACE**: `string` = `"static-user-identity"`
34
-
35
- The namespace supported by the processor.
36
-
37
- ***
38
-
39
31
  ### CLASS\_NAME
40
32
 
41
33
  > `readonly` **CLASS\_NAME**: `string`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/api-processors",
3
- "version": "0.0.2-next.2",
3
+ "version": "0.0.2-next.3",
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.2-next.2",
17
+ "@twin.org/api-models": "0.0.2-next.3",
18
18
  "@twin.org/core": "next",
19
19
  "@twin.org/logging-models": "next",
20
20
  "@twin.org/nameof": "next",