@twin.org/api-server-fastify 0.0.1 → 0.0.2-next.2
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/dist/cjs/index.cjs +13 -3
- package/dist/esm/index.mjs +13 -3
- package/docs/changelog.md +34 -0
- package/locales/en.json +1 -1
- package/package.json +10 -9
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var FastifyCompress = require('@fastify/compress');
|
|
4
4
|
var FastifyCors = require('@fastify/cors');
|
|
5
5
|
var apiModels = require('@twin.org/api-models');
|
|
6
|
+
var apiProcessors = require('@twin.org/api-processors');
|
|
6
7
|
var core = require('@twin.org/core');
|
|
7
8
|
var loggingModels = require('@twin.org/logging-models');
|
|
8
9
|
var web = require('@twin.org/web');
|
|
@@ -99,6 +100,10 @@ class FastifyWebServer {
|
|
|
99
100
|
};
|
|
100
101
|
this._started = false;
|
|
101
102
|
this._mimeTypeProcessors = options?.mimeTypeProcessors ?? [];
|
|
103
|
+
const hasJsonLd = this._mimeTypeProcessors.find(processor => processor.CLASS_NAME === "json-ld");
|
|
104
|
+
if (!hasJsonLd) {
|
|
105
|
+
this._mimeTypeProcessors.push(new apiProcessors.JsonLdMimeTypeProcessor());
|
|
106
|
+
}
|
|
102
107
|
this._includeErrorStack = options?.config?.includeErrorStack ?? false;
|
|
103
108
|
}
|
|
104
109
|
/**
|
|
@@ -283,15 +288,20 @@ class FastifyWebServer {
|
|
|
283
288
|
for (const socketRoute of socketRoutes) {
|
|
284
289
|
const path = core.StringHelper.trimLeadingSlashes(core.StringHelper.trimTrailingSlashes(socketRoute.path));
|
|
285
290
|
const pathParts = path.split("/");
|
|
291
|
+
const namespace = `/${pathParts[0]}`;
|
|
292
|
+
const topic = pathParts.slice(1).join("/");
|
|
286
293
|
await this._loggingConnector?.log({
|
|
287
294
|
level: "info",
|
|
288
295
|
ts: Date.now(),
|
|
289
296
|
source: this.CLASS_NAME,
|
|
290
297
|
message: `${FastifyWebServer._CLASS_NAME_CAMEL_CASE}.socketRouteAdded`,
|
|
291
|
-
data: {
|
|
298
|
+
data: {
|
|
299
|
+
handshakePath: this._socketConfig.path,
|
|
300
|
+
namespace,
|
|
301
|
+
eventName: topic
|
|
302
|
+
}
|
|
292
303
|
});
|
|
293
|
-
const socketNamespace = io.of(
|
|
294
|
-
const topic = pathParts.slice(1).join("/");
|
|
304
|
+
const socketNamespace = io.of(namespace);
|
|
295
305
|
socketNamespace.on("connection", async (socket) => {
|
|
296
306
|
const httpServerRequest = {
|
|
297
307
|
method: web.HttpMethod.GET,
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import FastifyCompress from '@fastify/compress';
|
|
2
2
|
import FastifyCors from '@fastify/cors';
|
|
3
3
|
import { HttpErrorHelper } from '@twin.org/api-models';
|
|
4
|
+
import { JsonLdMimeTypeProcessor } from '@twin.org/api-processors';
|
|
4
5
|
import { StringHelper, Is, GeneralError, BaseError } from '@twin.org/core';
|
|
5
6
|
import { LoggingConnectorFactory } from '@twin.org/logging-models';
|
|
6
7
|
import { HttpStatusCode, HttpMethod, HeaderTypes } from '@twin.org/web';
|
|
@@ -97,6 +98,10 @@ class FastifyWebServer {
|
|
|
97
98
|
};
|
|
98
99
|
this._started = false;
|
|
99
100
|
this._mimeTypeProcessors = options?.mimeTypeProcessors ?? [];
|
|
101
|
+
const hasJsonLd = this._mimeTypeProcessors.find(processor => processor.CLASS_NAME === "json-ld");
|
|
102
|
+
if (!hasJsonLd) {
|
|
103
|
+
this._mimeTypeProcessors.push(new JsonLdMimeTypeProcessor());
|
|
104
|
+
}
|
|
100
105
|
this._includeErrorStack = options?.config?.includeErrorStack ?? false;
|
|
101
106
|
}
|
|
102
107
|
/**
|
|
@@ -281,15 +286,20 @@ class FastifyWebServer {
|
|
|
281
286
|
for (const socketRoute of socketRoutes) {
|
|
282
287
|
const path = StringHelper.trimLeadingSlashes(StringHelper.trimTrailingSlashes(socketRoute.path));
|
|
283
288
|
const pathParts = path.split("/");
|
|
289
|
+
const namespace = `/${pathParts[0]}`;
|
|
290
|
+
const topic = pathParts.slice(1).join("/");
|
|
284
291
|
await this._loggingConnector?.log({
|
|
285
292
|
level: "info",
|
|
286
293
|
ts: Date.now(),
|
|
287
294
|
source: this.CLASS_NAME,
|
|
288
295
|
message: `${FastifyWebServer._CLASS_NAME_CAMEL_CASE}.socketRouteAdded`,
|
|
289
|
-
data: {
|
|
296
|
+
data: {
|
|
297
|
+
handshakePath: this._socketConfig.path,
|
|
298
|
+
namespace,
|
|
299
|
+
eventName: topic
|
|
300
|
+
}
|
|
290
301
|
});
|
|
291
|
-
const socketNamespace = io.of(
|
|
292
|
-
const topic = pathParts.slice(1).join("/");
|
|
302
|
+
const socketNamespace = io.of(namespace);
|
|
293
303
|
socketNamespace.on("connection", async (socket) => {
|
|
294
304
|
const httpServerRequest = {
|
|
295
305
|
method: HttpMethod.GET,
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,39 @@
|
|
|
1
1
|
# @twin.org/api-server-fastify - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.2-next.2](https://github.com/twinfoundation/api/compare/api-server-fastify-v0.0.2-next.1...api-server-fastify-v0.0.2-next.2) (2025-07-17)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* improve socket route logging ([b8d9519](https://github.com/twinfoundation/api/commit/b8d95199f838ac6ba9f45c30ef7c4e613201ff53))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/api-core bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
16
|
+
* @twin.org/api-models bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
17
|
+
* @twin.org/api-processors bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
18
|
+
|
|
19
|
+
## [0.0.2-next.1](https://github.com/twinfoundation/api/compare/api-server-fastify-v0.0.2-next.0...api-server-fastify-v0.0.2-next.1) (2025-07-08)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* add json-ld mime type processor and auth admin component ([8861791](https://github.com/twinfoundation/api/commit/88617916e23bfbca023dbae1976fe421983a02ff))
|
|
25
|
+
* update dependencies ([1171dc4](https://github.com/twinfoundation/api/commit/1171dc416a9481737f6a640e3cf30145768f37e9))
|
|
26
|
+
* use shared store mechanism ([#19](https://github.com/twinfoundation/api/issues/19)) ([32116df](https://github.com/twinfoundation/api/commit/32116df3b4380a30137f5056f242a5c99afa2df9))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
### Dependencies
|
|
30
|
+
|
|
31
|
+
* The following workspace dependencies were updated
|
|
32
|
+
* dependencies
|
|
33
|
+
* @twin.org/api-core bumped from 0.0.2-next.0 to 0.0.2-next.1
|
|
34
|
+
* @twin.org/api-models bumped from 0.0.2-next.0 to 0.0.2-next.1
|
|
35
|
+
* @twin.org/api-processors bumped from 0.0.2-next.0 to 0.0.2-next.1
|
|
36
|
+
|
|
3
37
|
## 0.0.1 (2025-07-03)
|
|
4
38
|
|
|
5
39
|
|
package/locales/en.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"stopped": "The Web Server was stopped",
|
|
8
8
|
"badRequest": "The web server could not handle the request",
|
|
9
9
|
"restRouteAdded": "Added REST route \"{route}\" \"{method}\"",
|
|
10
|
-
"socketRouteAdded": "Added socket route \"{
|
|
10
|
+
"socketRouteAdded": "Added socket route: handshake path \"{handshakePath}\", namespace \"{namespace}\", event name \"{eventName}\"",
|
|
11
11
|
"noRestProcessors": "You must configure at least one REST processor",
|
|
12
12
|
"noSocketProcessors": "You must configure at least one socket processor",
|
|
13
13
|
"postProcessorError": "There was a failure after in a post processor for route \"{route}\""
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/api-server-fastify",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2-next.2",
|
|
4
4
|
"description": "Use Fastify as the core web server for APIs",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,15 +14,16 @@
|
|
|
14
14
|
"node": ">=20.0.0"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@fastify/compress": "8.0
|
|
17
|
+
"@fastify/compress": "8.1.0",
|
|
18
18
|
"@fastify/cors": "11.0.1",
|
|
19
|
-
"@twin.org/api-core": "
|
|
20
|
-
"@twin.org/api-models": "
|
|
21
|
-
"@twin.org/
|
|
22
|
-
"@twin.org/
|
|
23
|
-
"@twin.org/
|
|
24
|
-
"@twin.org/
|
|
25
|
-
"
|
|
19
|
+
"@twin.org/api-core": "0.0.2-next.2",
|
|
20
|
+
"@twin.org/api-models": "0.0.2-next.2",
|
|
21
|
+
"@twin.org/api-processors": "0.0.2-next.2",
|
|
22
|
+
"@twin.org/core": "next",
|
|
23
|
+
"@twin.org/logging-models": "next",
|
|
24
|
+
"@twin.org/nameof": "next",
|
|
25
|
+
"@twin.org/web": "next",
|
|
26
|
+
"fastify": "5.4.0",
|
|
26
27
|
"socket.io": "4.8.1"
|
|
27
28
|
},
|
|
28
29
|
"main": "./dist/cjs/index.cjs",
|