create-cs-object 0.1.0 → 0.1.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/README.md +6 -2
- package/dist/cli.js +29 -2
- package/package.json +5 -2
- package/template/AGENTS.md +6 -0
- package/template/README.md +16 -0
- package/template/authoring.md +179 -18
- package/template/components.json +25 -0
- package/template/gitignore +1 -0
- package/template/index.html +12 -0
- package/template/reports.json +8 -0
- package/template/requirements.txt +1 -1
- package/template/scripts/dev.ts +104 -33
- package/template/scripts/reports.ts +24 -0
- package/template/src/App.tsx +681 -0
- package/template/src/components/theme-provider.tsx +230 -0
- package/template/src/components/ui/badge.tsx +51 -0
- package/template/src/components/ui/button.tsx +55 -0
- package/template/src/components/ui/card.tsx +102 -0
- package/template/src/components/ui/dropdown-menu.tsx +274 -0
- package/template/src/components/ui/input.tsx +19 -0
- package/template/src/components/ui/label.tsx +17 -0
- package/template/src/components/ui/separator.tsx +22 -0
- package/template/src/components/ui/sheet.tsx +137 -0
- package/template/src/hooks/use-mobile.ts +19 -0
- package/template/src/index.css +131 -0
- package/template/src/lib/utils.ts +1 -0
- package/template/src/main.tsx +9 -0
- package/template/tsconfig.app.json +29 -0
- package/template/tsconfig.json +12 -0
- package/template/tsconfig.node.json +24 -0
- package/template/vite.config.ts +144 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
4
|
+
"target": "es2023",
|
|
5
|
+
"lib": ["ES2023"],
|
|
6
|
+
"module": "esnext",
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
|
|
10
|
+
/* Bundler mode */
|
|
11
|
+
"moduleResolution": "bundler",
|
|
12
|
+
"allowImportingTsExtensions": true,
|
|
13
|
+
"verbatimModuleSyntax": true,
|
|
14
|
+
"moduleDetection": "force",
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
|
|
17
|
+
/* Linting */
|
|
18
|
+
"noUnusedLocals": true,
|
|
19
|
+
"noUnusedParameters": true,
|
|
20
|
+
"erasableSyntaxOnly": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true
|
|
22
|
+
},
|
|
23
|
+
"include": ["vite.config.ts"]
|
|
24
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
|
+
import tailwindcss from '@tailwindcss/vite';
|
|
4
|
+
import react from '@vitejs/plugin-react';
|
|
5
|
+
import { defineConfig } from 'vite';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
|
+
const backends = z
|
|
9
|
+
.array(
|
|
10
|
+
z.object({
|
|
11
|
+
id: z.string().regex(/^[a-z][a-z0-9-]*$/),
|
|
12
|
+
title: z.string(),
|
|
13
|
+
origin: z.url(),
|
|
14
|
+
}),
|
|
15
|
+
)
|
|
16
|
+
.parse(JSON.parse(process.env.CSO_REPORT_BACKENDS ?? '[]'));
|
|
17
|
+
const LinkedRunSchema = z.looseObject({
|
|
18
|
+
html: z.string().startsWith('/api/runs/'),
|
|
19
|
+
pdf: z.string().startsWith('/api/runs/'),
|
|
20
|
+
evidence: z.string().startsWith('/api/runs/'),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
async function forwardRun(
|
|
24
|
+
request: IncomingMessage,
|
|
25
|
+
response: ServerResponse,
|
|
26
|
+
origin: string,
|
|
27
|
+
reportId: string,
|
|
28
|
+
runId?: string,
|
|
29
|
+
) {
|
|
30
|
+
try {
|
|
31
|
+
const chunks: Buffer[] = [];
|
|
32
|
+
let size = 0;
|
|
33
|
+
if (request.method === 'POST') {
|
|
34
|
+
for await (const chunk of request) {
|
|
35
|
+
const bytes = Buffer.from(chunk);
|
|
36
|
+
size += bytes.length;
|
|
37
|
+
if (size > 64 * 1024) {
|
|
38
|
+
request.resume();
|
|
39
|
+
response.statusCode = 413;
|
|
40
|
+
response.end(
|
|
41
|
+
JSON.stringify({ error: 'Request body exceeds 64 KiB' }),
|
|
42
|
+
);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
chunks.push(bytes);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const upstream = await fetch(
|
|
49
|
+
new URL(`/api/runs${runId ? `/${runId}` : ''}`, origin),
|
|
50
|
+
{
|
|
51
|
+
method: request.method,
|
|
52
|
+
headers: {
|
|
53
|
+
Origin: origin,
|
|
54
|
+
...(request.method === 'POST'
|
|
55
|
+
? { 'Content-Type': request.headers['content-type'] ?? '' }
|
|
56
|
+
: {}),
|
|
57
|
+
},
|
|
58
|
+
...(request.method === 'POST' ? { body: Buffer.concat(chunks) } : {}),
|
|
59
|
+
},
|
|
60
|
+
);
|
|
61
|
+
const bodyText = await upstream.text();
|
|
62
|
+
const body: unknown = JSON.parse(bodyText);
|
|
63
|
+
const linked = upstream.ok ? LinkedRunSchema.safeParse(body) : undefined;
|
|
64
|
+
if (upstream.ok && !linked?.success)
|
|
65
|
+
throw new Error('Invalid calculation run links');
|
|
66
|
+
let result = bodyText;
|
|
67
|
+
if (linked?.success) {
|
|
68
|
+
for (const key of ['html', 'pdf', 'evidence'] as const) {
|
|
69
|
+
const before = `${JSON.stringify(key)}:${JSON.stringify(linked.data[key])}`;
|
|
70
|
+
const after = `${JSON.stringify(key)}:${JSON.stringify(`/api/reports/${reportId}${linked.data[key].slice(4)}`)}`;
|
|
71
|
+
if (!result.includes(before))
|
|
72
|
+
throw new Error('Missing calculation run link');
|
|
73
|
+
result = result.replace(before, after);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
response.statusCode = upstream.status;
|
|
77
|
+
response.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
78
|
+
response.end(result);
|
|
79
|
+
} catch {
|
|
80
|
+
response.statusCode = 502;
|
|
81
|
+
response.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
82
|
+
response.end(JSON.stringify({ error: 'Calculation server unavailable' }));
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default defineConfig({
|
|
87
|
+
plugins: [
|
|
88
|
+
react(),
|
|
89
|
+
tailwindcss(),
|
|
90
|
+
{
|
|
91
|
+
name: 'cso-report-catalog',
|
|
92
|
+
configureServer(server) {
|
|
93
|
+
server.middlewares.use('/api/reports', (request, response, next) => {
|
|
94
|
+
if (request.url === '/' && request.method === 'GET') {
|
|
95
|
+
response.setHeader(
|
|
96
|
+
'Content-Type',
|
|
97
|
+
'application/json; charset=utf-8',
|
|
98
|
+
);
|
|
99
|
+
response.end(
|
|
100
|
+
JSON.stringify(backends.map(({ id, title }) => ({ id, title }))),
|
|
101
|
+
);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const match = /^\/([a-z][a-z0-9-]*)\/runs(?:\/([\da-f-]{36}))?$/.exec(
|
|
105
|
+
request.url ?? '',
|
|
106
|
+
);
|
|
107
|
+
const report = backends.find(({ id }) => id === match?.[1]);
|
|
108
|
+
if (
|
|
109
|
+
!report ||
|
|
110
|
+
!match ||
|
|
111
|
+
(match[2] ? request.method !== 'GET' : request.method !== 'POST')
|
|
112
|
+
)
|
|
113
|
+
return next();
|
|
114
|
+
void forwardRun(
|
|
115
|
+
request,
|
|
116
|
+
response,
|
|
117
|
+
report.origin,
|
|
118
|
+
report.id,
|
|
119
|
+
match[2],
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
|
|
126
|
+
server: {
|
|
127
|
+
host: '127.0.0.1',
|
|
128
|
+
proxy: Object.fromEntries(
|
|
129
|
+
backends.map(({ id, origin }) => [
|
|
130
|
+
`^/api/reports/${id}/`,
|
|
131
|
+
{
|
|
132
|
+
target: origin,
|
|
133
|
+
changeOrigin: true,
|
|
134
|
+
rewrite: (url: string) => url.replace(`/api/reports/${id}/`, '/api/'),
|
|
135
|
+
configure(proxy) {
|
|
136
|
+
proxy.on('proxyReq', (request) =>
|
|
137
|
+
request.setHeader('Origin', origin),
|
|
138
|
+
);
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
]),
|
|
142
|
+
),
|
|
143
|
+
},
|
|
144
|
+
});
|