spl2dql 0.0.0-stage → 0.1.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.
Files changed (44) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +18 -0
  3. package/README.md +82 -2
  4. package/bin/spl2dql.js +20 -0
  5. package/dist/inputs.d.ts +21 -0
  6. package/dist/inputs.js +130 -0
  7. package/dist/main.d.ts +41 -0
  8. package/dist/main.js +650 -0
  9. package/dist/mapping.d.ts +18 -0
  10. package/dist/mapping.js +60 -0
  11. package/dist/report.d.ts +95 -0
  12. package/dist/report.js +285 -0
  13. package/dist/safe-fs.d.ts +7 -0
  14. package/dist/safe-fs.js +81 -0
  15. package/dist/serve/server.d.ts +47 -0
  16. package/dist/serve/server.js +195 -0
  17. package/package.json +64 -3
  18. package/web/404.html +27 -0
  19. package/web/THIRD-PARTY-NOTICES.txt +774 -0
  20. package/web/_headers +26 -0
  21. package/web/assets/BatchView-CJw9TDhQ.js +1 -0
  22. package/web/assets/DashboardsView-gW0FEoq7.js +1 -0
  23. package/web/assets/DropZone-CIbk77sc.js +492 -0
  24. package/web/assets/MappingView-Co21Vkp_.js +14 -0
  25. package/web/assets/ReferenceView-S1R-kCt6.js +2 -0
  26. package/web/assets/atkinson-hyperlegible-mono-latin-ext-wght-normal-CXgNM06D.woff2 +0 -0
  27. package/web/assets/atkinson-hyperlegible-mono-latin-wght-normal-CoA7y8X5.woff2 +0 -0
  28. package/web/assets/atkinson-hyperlegible-next-latin-ext-wght-normal-C6vrW8VD.woff2 +0 -0
  29. package/web/assets/atkinson-hyperlegible-next-latin-wght-normal-BcXVPD7q.woff2 +0 -0
  30. package/web/assets/dict-9ToLi8Te.js +1 -0
  31. package/web/assets/index-BO3AM1fZ.js +46 -0
  32. package/web/assets/index-DPywAY6M.css +2 -0
  33. package/web/assets/jsx-runtime-Wy9s6hX0.js +1 -0
  34. package/web/assets/mapping-text-B64_Oh2A.js +106 -0
  35. package/web/assets/translate.worker-C2M3Sf23.js +656 -0
  36. package/web/icon-180.png +0 -0
  37. package/web/icon-192.png +0 -0
  38. package/web/icon-512.png +0 -0
  39. package/web/icon.svg +1 -0
  40. package/web/index.html +63 -0
  41. package/web/manifest.webmanifest +15 -0
  42. package/web/robots.txt +2 -0
  43. package/web/social.png +0 -0
  44. package/web/sw.js +24 -0
@@ -0,0 +1,195 @@
1
+ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
2
+ import { createServer } from 'node:http';
3
+ import { extname, join, relative, sep } from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+ export class ServeError extends Error {
6
+ }
7
+ const LOOPBACK = new Set(['127.0.0.1', '::1', 'localhost']);
8
+ const MIME = {
9
+ '.html': 'text/html; charset=utf-8',
10
+ '.js': 'text/javascript; charset=utf-8',
11
+ '.mjs': 'text/javascript; charset=utf-8',
12
+ '.css': 'text/css; charset=utf-8',
13
+ '.json': 'application/json; charset=utf-8',
14
+ '.webmanifest': 'application/manifest+json; charset=utf-8',
15
+ '.svg': 'image/svg+xml',
16
+ '.png': 'image/png',
17
+ '.ico': 'image/x-icon',
18
+ '.woff2': 'font/woff2',
19
+ '.woff': 'font/woff',
20
+ '.txt': 'text/plain; charset=utf-8',
21
+ };
22
+ /**
23
+ * The policy when the web folder has no `_headers` file (an unbuilt checkout): the same rules the
24
+ * build writes (apps/web/vite.config.ts), so the local server never sends less than the hosted page.
25
+ */
26
+ export const DEFAULT_HEADERS = `/*
27
+ Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'none'; worker-src 'self'; manifest-src 'self'; object-src 'none'; base-uri 'none'; form-action 'none'; require-trusted-types-for 'script'; trusted-types spl2dql; frame-ancestors 'none'
28
+ X-Content-Type-Options: nosniff
29
+ X-Frame-Options: DENY
30
+ Referrer-Policy: no-referrer
31
+ Cross-Origin-Opener-Policy: same-origin
32
+ Cross-Origin-Resource-Policy: same-origin
33
+ Permissions-Policy: camera=(), microphone=(), geolocation=(), payment=(), usb=()
34
+ /sw.js
35
+ ! Content-Security-Policy
36
+ Content-Security-Policy: default-src 'none'; connect-src 'self'; frame-ancestors 'none'
37
+ /social.png
38
+ ! Cross-Origin-Resource-Policy
39
+ Cross-Origin-Resource-Policy: cross-origin
40
+ `;
41
+ /**
42
+ * Reads the subset of the `_headers` format the build writes: a path (`/sw.js`) or a folder
43
+ * pattern (`/assets/*`, `/*`) at the start of a line, then indented `Name: value` lines and
44
+ * `! Name` lines that remove a header an earlier rule set. Comments and blank lines are skipped.
45
+ */
46
+ export function parseHeadersFile(text) {
47
+ const rules = [];
48
+ for (const raw of text.split(/\r?\n/)) {
49
+ if (raw.trim() === '' || raw.trimStart().startsWith('#'))
50
+ continue;
51
+ if (!/^\s/.test(raw)) {
52
+ rules.push({ pattern: raw.trim(), lines: [] });
53
+ continue;
54
+ }
55
+ const rule = rules[rules.length - 1];
56
+ if (!rule)
57
+ continue;
58
+ const line = raw.trim();
59
+ if (line.startsWith('!')) {
60
+ rule.lines.push({ remove: line.slice(1).trim().toLowerCase() });
61
+ continue;
62
+ }
63
+ const colon = line.indexOf(':');
64
+ if (colon <= 0)
65
+ continue;
66
+ rule.lines.push({ set: line.slice(0, colon).trim(), value: line.slice(colon + 1).trim() });
67
+ }
68
+ return rules;
69
+ }
70
+ function matches(pattern, path) {
71
+ if (pattern.endsWith('/*'))
72
+ return path.startsWith(pattern.slice(0, -1));
73
+ return pattern === path;
74
+ }
75
+ /**
76
+ * The headers a path gets: every matching rule in order. The hosted page's caching rules are not
77
+ * applied: a loopback server sends `Cache-Control: no-store` for everything (docs/spec/cli.md).
78
+ */
79
+ export function headersFor(rules, path) {
80
+ const out = new Map();
81
+ for (const rule of rules) {
82
+ if (!matches(rule.pattern, path))
83
+ continue;
84
+ for (const line of rule.lines) {
85
+ if ('remove' in line)
86
+ out.delete(line.remove);
87
+ else
88
+ out.set(line.set.toLowerCase(), [line.set, line.value]);
89
+ }
90
+ }
91
+ out.set('cache-control', ['Cache-Control', 'no-store']);
92
+ return Object.fromEntries([...out.values()]);
93
+ }
94
+ /** Starts the local web app server. Loopback only; GET and HEAD only; own Host names only. */
95
+ export async function startServer(options) {
96
+ if (!LOOPBACK.has(options.host))
97
+ throw new ServeError('spl2dql serve only listens on 127.0.0.1, ::1 or localhost.');
98
+ if (!Number.isInteger(options.port) || options.port < 0 || options.port > 65535)
99
+ throw new ServeError('Invalid port.');
100
+ const webDir = options.webDir ?? fileURLToPath(new URL('../../web', import.meta.url));
101
+ const files = loadStatic(webDir);
102
+ // The same policy the hosted page gets: the built `_headers`, read once (ADR-029).
103
+ const headersPath = join(webDir, '_headers');
104
+ const rules = parseHeadersFile(existsSync(headersPath) ? readFileSync(headersPath, 'utf8') : DEFAULT_HEADERS);
105
+ let port = options.port;
106
+ const allowedHosts = () => new Set([`127.0.0.1:${port}`, `localhost:${port}`, `[::1]:${port}`]);
107
+ const send = (res, status, type, body, head, path = '/') => {
108
+ res.writeHead(status, { ...headersFor(rules, path), 'Content-Type': type, 'Content-Length': Buffer.byteLength(body) });
109
+ res.end(head ? undefined : body);
110
+ };
111
+ const server = createServer((req, res) => {
112
+ // DNS-rebinding defence: only our own Host names.
113
+ if (!allowedHosts().has(req.headers.host ?? ''))
114
+ return send(res, 403, 'text/plain; charset=utf-8', 'Forbidden host', false);
115
+ const head = req.method === 'HEAD';
116
+ if (req.method !== 'GET' && !head) {
117
+ res.setHeader('Allow', 'GET, HEAD');
118
+ return send(res, 405, 'text/plain; charset=utf-8', 'Method not allowed', false);
119
+ }
120
+ // The request body is never read; drop anything sent.
121
+ req.resume();
122
+ let path;
123
+ try {
124
+ path = new URL(req.url ?? '/', 'http://localhost').pathname;
125
+ }
126
+ catch {
127
+ return send(res, 400, 'text/plain; charset=utf-8', 'Bad request', head);
128
+ }
129
+ const asked = path;
130
+ if (path === '/')
131
+ path = '/index.html';
132
+ // The header rules are not a file to serve.
133
+ if (path === '/_headers')
134
+ return send(res, 404, 'text/plain; charset=utf-8', 'Not found', head, asked);
135
+ // Static files come from an allow-list built at start-up; no filesystem access per request.
136
+ // Paths without an extension are app views (/batch, /mapping …) and get the app page.
137
+ const file = files.get(path) ?? (extname(path) === '' ? files.get('/index.html') : undefined);
138
+ if (!file)
139
+ return send(res, 404, 'text/plain; charset=utf-8', 'Not found', head, asked);
140
+ return send(res, 200, file.type, file.body, head, asked);
141
+ });
142
+ server.headersTimeout = 10_000;
143
+ server.requestTimeout = 30_000;
144
+ await new Promise((resolve, reject) => {
145
+ server.once('error', reject);
146
+ server.listen(options.port, options.host, () => {
147
+ server.off('error', reject);
148
+ resolve();
149
+ });
150
+ });
151
+ port = server.address().port;
152
+ const hostForUrl = options.host === '::1' ? '[::1]' : options.host;
153
+ let resolveClosed = () => undefined;
154
+ const closed = new Promise((r) => {
155
+ resolveClosed = r;
156
+ });
157
+ server.on('close', () => resolveClosed());
158
+ return {
159
+ url: `http://${hostForUrl}:${port}`,
160
+ closed,
161
+ close: () => new Promise((r) => {
162
+ server.closeAllConnections();
163
+ server.close(() => r());
164
+ }),
165
+ };
166
+ }
167
+ const FALLBACK_PAGE = `<!doctype html><html lang="en"><head><meta charset="utf-8"><title>spl2dql</title></head><body><p>The web app is not built. Run <code>pnpm build</code> in the repository.</p></body></html>`;
168
+ /** Reads the built web app once. Symbolic links, unknown file types and files over 20 MB are skipped. */
169
+ function loadStatic(dir) {
170
+ const out = new Map();
171
+ if (!existsSync(dir)) {
172
+ out.set('/index.html', { body: Buffer.from(FALLBACK_PAGE), type: MIME['.html'] });
173
+ return out;
174
+ }
175
+ const walk = (d) => {
176
+ for (const entry of readdirSync(d, { withFileTypes: true })) {
177
+ const full = join(d, entry.name);
178
+ if (entry.isSymbolicLink())
179
+ continue;
180
+ if (entry.isDirectory())
181
+ walk(full);
182
+ else if (entry.isFile() && statSync(full).size < 20_000_000) {
183
+ const type = MIME[extname(entry.name).toLowerCase()];
184
+ if (!type)
185
+ continue;
186
+ out.set(`/${relative(dir, full).split(sep).join('/')}`, { body: readFileSync(full), type });
187
+ }
188
+ }
189
+ };
190
+ walk(dir);
191
+ if (!out.has('/index.html'))
192
+ out.set('/index.html', { body: Buffer.from(FALLBACK_PAGE), type: MIME['.html'] });
193
+ return out;
194
+ }
195
+ //# sourceMappingURL=server.js.map
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "spl2dql",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Move a Splunk app to Dynatrace: SPL searches to DQL queries, dashboards to Dynatrace dashboards — offline, from the terminal.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "gokul-babu",
8
+ "url": "https://github.com/gokul-babu"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/gokul-babu/spl2dql.git",
13
+ "directory": "packages/cli"
14
+ },
15
+ "homepage": "https://spl2dql.pages.dev",
16
+ "bugs": {
17
+ "url": "https://github.com/gokul-babu/spl2dql/issues"
18
+ },
19
+ "keywords": [
20
+ "splunk",
21
+ "spl",
22
+ "dynatrace",
23
+ "dql",
24
+ "grail",
25
+ "migration",
26
+ "translator",
27
+ "dashboard",
28
+ "savedsearches",
29
+ "cli"
30
+ ],
31
+ "type": "module",
32
+ "bin": {
33
+ "spl2dql": "./bin/spl2dql.js"
34
+ },
35
+ "exports": {
36
+ ".": {
37
+ "default": "./dist/main.js"
38
+ }
39
+ },
40
+ "files": [
41
+ "bin",
42
+ "dist",
43
+ "web",
44
+ "LICENSE",
45
+ "NOTICE",
46
+ "!dist/**/*.map"
47
+ ],
48
+ "engines": {
49
+ "node": ">=24"
50
+ },
51
+ "dependencies": {
52
+ "@spl2dql/core": "0.1.0",
53
+ "commander": "^15.0.0",
54
+ "yaml": "^2.9.0"
55
+ },
56
+ "devDependencies": {
57
+ "@spl2dql/web": "0.1.0"
58
+ },
59
+ "publishConfig": {
60
+ "access": "public"
61
+ },
62
+ "scripts": {
63
+ "typecheck": "tsc --noEmit -p .",
64
+ "build": "tsc -p tsconfig.build.json && node ../../scripts/copy-web.ts",
65
+ "dev": "node --conditions=source src/main.ts"
66
+ }
6
67
  }
package/web/404.html ADDED
@@ -0,0 +1,27 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'none'; worker-src 'self'; manifest-src 'self'; object-src 'none'; base-uri 'none'; form-action 'none'; require-trusted-types-for 'script'; trusted-types spl2dql">
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <meta name="referrer" content="no-referrer">
8
+ <meta name="color-scheme" content="light dark">
9
+ <meta name="robots" content="noindex">
10
+ <title>Page not found – spl2dql</title>
11
+ <link rel="icon" href="/icon.svg" type="image/svg+xml">
12
+ <link rel="stylesheet" href="/assets/index-DPywAY6M.css">
13
+ </head>
14
+ <body>
15
+ <div class="flex h-full flex-col">
16
+ <header class="app-header">
17
+ <p class="app-name">spl2dql</p>
18
+ <p class="app-line">Translates Splunk searches to Dynatrace DQL, dashboards included.</p>
19
+ </header>
20
+ <main class="min-h-0 flex-1 px-4 py-6">
21
+ <h1 class="text-lg font-semibold">Page not found</h1>
22
+ <p class="mt-1 text-sm">There is nothing at this address.</p>
23
+ <p class="mt-4"><a class="control primary" href="/">Open the translator</a></p>
24
+ </main>
25
+ </div>
26
+ </body>
27
+ </html>