zsyp 1.4.1 → 2.0.0
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/index.js +4 -9
- package/lib/app.js +8 -8
- package/lib/converter.js +1 -3
- package/lib/env.js +5 -0
- package/lib/event.js +5 -9
- package/lib/filter.js +1 -5
- package/lib/from.js +2 -4
- package/lib/logger.js +3 -3
- package/lib/ping.js +24 -0
- package/lib/router.js +5 -7
- package/lib/source-map.js +6 -11
- package/package.json +7 -3
package/index.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
} catch {
|
|
4
|
-
console.error('Failed to load config file.');
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
const makeApp = require('./lib/app');
|
|
1
|
+
import './lib/env.js';
|
|
2
|
+
import makeApp from './lib/app.js';
|
|
8
3
|
|
|
9
4
|
const { ZSYP_PORT: PORT = 3090 } = process.env;
|
|
10
5
|
|
|
11
6
|
const app = makeApp();
|
|
12
7
|
|
|
13
|
-
|
|
8
|
+
export default app;
|
|
14
9
|
|
|
15
|
-
if (
|
|
10
|
+
if (import.meta.main) {
|
|
16
11
|
app.listen(PORT);
|
|
17
12
|
console.log('Listening on port', PORT);
|
|
18
13
|
}
|
package/lib/app.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
module.exports = makeApp;
|
|
1
|
+
import { json } from 'node:stream/consumers';
|
|
2
|
+
import connect from '@pirxpilot/connect';
|
|
3
|
+
import mniam from 'mniam';
|
|
4
|
+
import * as event from './event.js';
|
|
5
|
+
import ping from './ping.js';
|
|
6
|
+
import router from './router.js';
|
|
8
7
|
|
|
9
8
|
const { ZSYP_DOMAINS: domains, ZSYP_DB: database = 'mongodb://localhost/zsyp' } = process.env;
|
|
10
9
|
|
|
11
|
-
function makeApp(opts = {}) {
|
|
10
|
+
export default function makeApp(opts = {}) {
|
|
12
11
|
const app = connect();
|
|
13
12
|
|
|
14
13
|
opts.db = mniam.db(database);
|
|
@@ -18,6 +17,7 @@ function makeApp(opts = {}) {
|
|
|
18
17
|
|
|
19
18
|
app.use('/csp', router({ ...opts, name: 'csp', domains }));
|
|
20
19
|
app.use('/event', router({ ...opts, converter: event.converter }));
|
|
20
|
+
app.use('/_/ping', ping(opts));
|
|
21
21
|
|
|
22
22
|
return app;
|
|
23
23
|
}
|
package/lib/converter.js
CHANGED
package/lib/env.js
ADDED
package/lib/event.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import stackParser from 'error-stack-parser';
|
|
3
|
+
import { ObjectId } from 'mongodb';
|
|
4
|
+
import { resolve } from './source-map.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
converter
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
async function converter(event) {
|
|
6
|
+
export async function converter(event) {
|
|
11
7
|
const { type = 'event' } = event;
|
|
12
8
|
let item;
|
|
13
9
|
let name;
|
package/lib/filter.js
CHANGED
package/lib/from.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { parse } from 'useragent';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function from(req, _res, next) {
|
|
3
|
+
export default function from(req, _res, next) {
|
|
6
4
|
const { headers, body } = req;
|
|
7
5
|
const ua = body?.from?.ua ?? headers['user-agent'];
|
|
8
6
|
const { family, major, os, device } = parse(ua);
|
package/lib/logger.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import Debug from 'debug';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const debug = Debug('zsyp:logger');
|
|
4
4
|
|
|
5
|
-
function makeLogger({ db, name }) {
|
|
5
|
+
export default function makeLogger({ db, name }) {
|
|
6
6
|
const cache = Object.create(null);
|
|
7
7
|
|
|
8
8
|
const getCollection = name ? () => collectionFromCache(name) : ({ name }) => collectionFromCache(name);
|
package/lib/ping.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export default function makePing({ db }) {
|
|
2
|
+
const pingsCollection = db.collection({ name: 'ping' });
|
|
3
|
+
|
|
4
|
+
return ping;
|
|
5
|
+
|
|
6
|
+
async function ping(req, res) {
|
|
7
|
+
if (req.method !== 'GET' && req.path !== '/') {
|
|
8
|
+
res.statusCode = 404;
|
|
9
|
+
res.end();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
await pingsCollection.insertOne({
|
|
14
|
+
timestamp: new Date()
|
|
15
|
+
});
|
|
16
|
+
res.statusCode = 204; // empty
|
|
17
|
+
res.end();
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error(error);
|
|
20
|
+
res.statusCode = 500;
|
|
21
|
+
res.end();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/lib/router.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import makeConverter from './converter.js';
|
|
2
|
+
import makeFilter from './filter.js';
|
|
3
|
+
import from from './from.js';
|
|
4
|
+
import makeLogger from './logger.js';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function router(opts) {
|
|
6
|
+
export default function router(opts) {
|
|
9
7
|
const stack = [respond, from, makeFilter(opts), makeConverter(opts), makeLogger(opts), opts.finalMiddleware].filter(
|
|
10
8
|
Boolean
|
|
11
9
|
);
|
package/lib/source-map.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
module.exports = {
|
|
7
|
-
resolve,
|
|
8
|
-
clear
|
|
9
|
-
};
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { LRUCache as LRU } from 'lru-cache';
|
|
4
|
+
import { SourceMapConsumer } from 'source-map';
|
|
10
5
|
|
|
11
6
|
const { ZSYP_SOURCE_MAP_DIR = '/var/lib/zsyp', ZSYP_SOURCE_MAP_CACHE_SIZE = 30 } = process.env;
|
|
12
7
|
|
|
@@ -16,7 +11,7 @@ const cache = new LRU({
|
|
|
16
11
|
dispose: smc => smc?.destroy()
|
|
17
12
|
});
|
|
18
13
|
|
|
19
|
-
async function resolve({ an, av }, frame) {
|
|
14
|
+
export async function resolve({ an, av }, frame) {
|
|
20
15
|
const [source, line, column] = frame;
|
|
21
16
|
const smc = await loadSourceMap(an, av, source);
|
|
22
17
|
if (!smc) {
|
|
@@ -33,7 +28,7 @@ async function resolve({ an, av }, frame) {
|
|
|
33
28
|
return resolved;
|
|
34
29
|
}
|
|
35
30
|
|
|
36
|
-
function clear() {
|
|
31
|
+
export function clear() {
|
|
37
32
|
cache.clear();
|
|
38
33
|
}
|
|
39
34
|
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zsyp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "CSP violation reports logger.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Damian Krzeminski",
|
|
7
7
|
"email": "pirxpilot@furkot.com",
|
|
8
8
|
"url": "https://pirxpilot.me"
|
|
9
9
|
},
|
|
10
|
-
"
|
|
10
|
+
"type": "module",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/pirxpilot/zsyp.git"
|
|
14
|
+
},
|
|
11
15
|
"license": "MIT",
|
|
12
16
|
"keywords": [
|
|
13
17
|
"zsyp",
|
|
@@ -26,7 +30,7 @@
|
|
|
26
30
|
"useragent": "^2.3.0"
|
|
27
31
|
},
|
|
28
32
|
"devDependencies": {
|
|
29
|
-
"@biomejs/biome": "2.
|
|
33
|
+
"@biomejs/biome": "2.2.7",
|
|
30
34
|
"supertest-fetch": "~2"
|
|
31
35
|
},
|
|
32
36
|
"scripts": {
|