@ovineko/spa-guard-fastify 0.0.1-alpha-18 → 0.0.1-alpha-19
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/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/index.ts
|
|
2
2
|
import fp from "fastify-plugin";
|
|
3
3
|
import { BeaconError } from "@ovineko/spa-guard";
|
|
4
4
|
import { logMessage } from "@ovineko/spa-guard/_internal";
|
|
@@ -7,7 +7,7 @@ import { parseBeacon } from "@ovineko/spa-guard/schema/parse";
|
|
|
7
7
|
// package.json
|
|
8
8
|
var name = "@ovineko/spa-guard-fastify";
|
|
9
9
|
|
|
10
|
-
// src/
|
|
10
|
+
// src/index.ts
|
|
11
11
|
var parseStringBody = (body) => {
|
|
12
12
|
try {
|
|
13
13
|
return JSON.parse(body);
|
|
@@ -51,11 +51,24 @@ var fastifySPAGuardPlugin = async (fastify, options) => {
|
|
|
51
51
|
const { onBeacon, onUnknownBeacon, path } = options;
|
|
52
52
|
fastify.post(path, async (request, reply) => {
|
|
53
53
|
if (typeof request.body !== "string") {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
if (onUnknownBeacon) {
|
|
55
|
+
const result = await onUnknownBeacon(request.body, request, reply);
|
|
56
|
+
if (!result?.skipDefaultLog) {
|
|
57
|
+
request.log.warn(
|
|
58
|
+
{ bodyType: typeof request.body },
|
|
59
|
+
logMessage("Invalid beacon body type, expected string")
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
request.log.warn(
|
|
64
|
+
{ bodyType: typeof request.body },
|
|
65
|
+
logMessage("Invalid beacon body type, expected string")
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
if (!reply.sent) {
|
|
69
|
+
return reply.status(400).send({ error: "Invalid body type" });
|
|
70
|
+
}
|
|
71
|
+
return reply;
|
|
59
72
|
}
|
|
60
73
|
const body = parseStringBody(request.body);
|
|
61
74
|
await handleBeaconRequest({ body, options: { onBeacon, onUnknownBeacon }, reply, request });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ovineko/spa-guard-fastify",
|
|
3
|
-
"version": "0.0.1-alpha-
|
|
3
|
+
"version": "0.0.1-alpha-19",
|
|
4
4
|
"description": "Fastify plugin for spa-guard beacon endpoint",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"spa",
|
|
@@ -23,16 +23,15 @@
|
|
|
23
23
|
"type": "module",
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
|
-
"types": "./dist/
|
|
27
|
-
"default": "./dist/
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"default": "./dist/index.js"
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"files": [
|
|
31
|
-
"dist"
|
|
32
|
-
"README.md"
|
|
31
|
+
"dist"
|
|
33
32
|
],
|
|
34
33
|
"dependencies": {
|
|
35
|
-
"@ovineko/spa-guard": "0.0.1-alpha-
|
|
34
|
+
"@ovineko/spa-guard": "0.0.1-alpha-19"
|
|
36
35
|
},
|
|
37
36
|
"peerDependencies": {
|
|
38
37
|
"fastify": "^5 || ^4",
|
|
File without changes
|