@skillre/dsh-plugin-work-dashboard 0.0.0-stage → 0.9.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/LICENSE +21 -0
- package/README.en.md +259 -0
- package/README.md +371 -2
- package/UNINSTALL.md +7 -0
- package/compatibility.json +195 -0
- package/cordis.patch.yml +24 -0
- package/docs/DESIGN-0.3.md +122 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/PLAN-0.7-0.9.md +230 -0
- package/docs/preview.svg +254 -0
- package/docs/preview.zh.svg +254 -0
- package/icon.svg +17 -0
- package/lib/blockers.d.ts +45 -0
- package/lib/blockers.js +160 -0
- package/lib/client/api.d.ts +42 -0
- package/lib/client/api.js +45 -0
- package/lib/client/contracts.d.ts +94 -0
- package/lib/client/contracts.js +21 -0
- package/lib/client/css/base.d.ts +31 -0
- package/lib/client/css/base.js +461 -0
- package/lib/client/css/blockers.d.ts +18 -0
- package/lib/client/css/blockers.js +196 -0
- package/lib/client/css/charts.d.ts +14 -0
- package/lib/client/css/charts.js +191 -0
- package/lib/client/css/detail.d.ts +21 -0
- package/lib/client/css/detail.js +423 -0
- package/lib/client/css/insights.d.ts +27 -0
- package/lib/client/css/insights.js +660 -0
- package/lib/client/css/overview.d.ts +23 -0
- package/lib/client/css/overview.js +327 -0
- package/lib/client/css/summary.d.ts +13 -0
- package/lib/client/css/summary.js +187 -0
- package/lib/client/format.d.ts +57 -0
- package/lib/client/format.js +96 -0
- package/lib/client/preferences.d.ts +56 -0
- package/lib/client/preferences.js +118 -0
- package/lib/client/styles.d.ts +17 -0
- package/lib/client/styles.js +24 -0
- package/lib/client/text.d.ts +32 -0
- package/lib/client/text.js +1112 -0
- package/lib/client/view-contract.d.ts +118 -0
- package/lib/client/view-contract.js +28 -0
- package/lib/client.js +6599 -0
- package/lib/config.d.ts +61 -0
- package/lib/config.js +67 -0
- package/lib/form.d.ts +218 -0
- package/lib/form.js +1075 -0
- package/lib/gap.d.ts +60 -0
- package/lib/gap.js +227 -0
- package/lib/index.d.ts +40 -0
- package/lib/index.js +159 -0
- package/lib/repo.d.ts +124 -0
- package/lib/repo.js +407 -0
- package/lib/risks.d.ts +24 -0
- package/lib/risks.js +85 -0
- package/lib/skill.d.ts +94 -0
- package/lib/skill.js +220 -0
- package/lib/store.d.ts +63 -0
- package/lib/store.js +505 -0
- package/lib/timeline.d.ts +23 -0
- package/lib/timeline.js +93 -0
- package/lib/transport.d.ts +67 -0
- package/lib/transport.js +131 -0
- package/lib/types.d.ts +701 -0
- package/lib/types.js +78 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +117 -4
- package/skills/poc-export/SKILL.md +81 -0
- package/skills/poc-export/scripts/export-form.mjs +654 -0
- package/skills/poc-ledger/SKILL.md +171 -0
- package/skills/poc-submit/SKILL.md +186 -0
package/lib/transport.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host ↔ Client transport: one exact Fetch route inside Connection's fence.
|
|
3
|
+
*
|
|
4
|
+
* Connection owns the Host/Origin check, the browser-session authentication and
|
|
5
|
+
* the Peer scope; this module registers one exact `POST /api/<endpoint>` route
|
|
6
|
+
* and only validates its own envelope and payload. No physical server, no
|
|
7
|
+
* Express, and no second RPC channel is claimed.
|
|
8
|
+
*
|
|
9
|
+
* The wire envelope is the inspected Connection unary shape:
|
|
10
|
+
* `{ type: 'client-request', rpcId, method, payload }` in and
|
|
11
|
+
* `{ type: 'server-response', rpcId, result: { ok: true, value } | { ok: false, error } }`
|
|
12
|
+
* out. A non-owner Peer is rejected by Connection before this handler runs.
|
|
13
|
+
*/
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
import { RepoError } from './repo.js';
|
|
16
|
+
import { ENDPOINT } from './types.js';
|
|
17
|
+
/** Path of the exact route, under the shared `/api` channel. */
|
|
18
|
+
export const EXECUTE_PATH = `/api/${ENDPOINT}`;
|
|
19
|
+
const envelopeSchema = z.object({
|
|
20
|
+
type: z.literal('client-request'),
|
|
21
|
+
rpcId: z.string(),
|
|
22
|
+
method: z.string(),
|
|
23
|
+
payload: z.unknown(),
|
|
24
|
+
});
|
|
25
|
+
/** The ledger ids are `POC-YYYY-NNN`; accept that shape and nothing exotic. */
|
|
26
|
+
const pocIdSchema = z.string().min(1).max(128);
|
|
27
|
+
const requestSchema = z.discriminatedUnion('action', [
|
|
28
|
+
z.object({ action: z.literal('list') }).strict(),
|
|
29
|
+
z.object({ action: z.literal('refresh') }).strict(),
|
|
30
|
+
z.object({ action: z.literal('detail'), pocId: pocIdSchema }).strict(),
|
|
31
|
+
z.object({ action: z.literal('risks') }).strict(),
|
|
32
|
+
z.object({ action: z.literal('timeline') }).strict(),
|
|
33
|
+
z.object({
|
|
34
|
+
action: z.literal('export-form'),
|
|
35
|
+
mode: z.union([z.literal('fill'), z.literal('blank')]),
|
|
36
|
+
// Bounded: a form is meant for a batch a colleague will actually fill in,
|
|
37
|
+
// and an unbounded list would let one request build a thousands-project
|
|
38
|
+
// document on the Host.
|
|
39
|
+
pocIds: z.array(pocIdSchema).max(200),
|
|
40
|
+
}).strict(),
|
|
41
|
+
]);
|
|
42
|
+
/** A JSON response with no-store caching; the board is always live state. */
|
|
43
|
+
function json(body, status = 200) {
|
|
44
|
+
return Response.json(body, { status, headers: { 'cache-control': 'no-store' } });
|
|
45
|
+
}
|
|
46
|
+
/** One server-response success envelope. */
|
|
47
|
+
function success(rpcId, value) {
|
|
48
|
+
return json({ type: 'server-response', rpcId, result: { ok: true, value } });
|
|
49
|
+
}
|
|
50
|
+
/** One server-response failure envelope, using a stable plugin-owned code. */
|
|
51
|
+
function failure(rpcId, code, message, details = {}) {
|
|
52
|
+
return json({ type: 'server-response', rpcId, result: { ok: false, error: { code: `work-dashboard/${code}`, message, details } } });
|
|
53
|
+
}
|
|
54
|
+
/** Recover the correlation id from any body shape so failures stay correlatable. */
|
|
55
|
+
function correlation(body) {
|
|
56
|
+
return body !== null && typeof body === 'object' && 'rpcId' in body && typeof body.rpcId === 'string'
|
|
57
|
+
? body.rpcId
|
|
58
|
+
: 'invalid-request';
|
|
59
|
+
}
|
|
60
|
+
/** Dispatch one validated request onto the console actions. */
|
|
61
|
+
async function dispatch(actions, request, signal) {
|
|
62
|
+
switch (request.action) {
|
|
63
|
+
case 'list':
|
|
64
|
+
return actions.snapshot();
|
|
65
|
+
case 'refresh': {
|
|
66
|
+
const { snapshot, outcome } = await actions.refresh();
|
|
67
|
+
return { snapshot, outcome };
|
|
68
|
+
}
|
|
69
|
+
case 'detail': {
|
|
70
|
+
const detail = await actions.detail(request.pocId);
|
|
71
|
+
if (detail === null)
|
|
72
|
+
throw new RepoError('unknown-project', `No project with poc_id ${JSON.stringify(request.pocId)}.`, { pocId: request.pocId });
|
|
73
|
+
return detail;
|
|
74
|
+
}
|
|
75
|
+
case 'risks':
|
|
76
|
+
return actions.risks();
|
|
77
|
+
case 'timeline':
|
|
78
|
+
return actions.timeline();
|
|
79
|
+
case 'export-form':
|
|
80
|
+
return actions.exportForm(request.mode, request.pocIds);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function createExecuteRoute(ready, options = {}) {
|
|
84
|
+
return {
|
|
85
|
+
path: EXECUTE_PATH,
|
|
86
|
+
methods: ['POST'],
|
|
87
|
+
requestBody: 'buffered',
|
|
88
|
+
async fetch(request) {
|
|
89
|
+
if (request.method !== 'POST' || new URL(request.url).pathname !== EXECUTE_PATH)
|
|
90
|
+
return new Response('not found', { status: 404 });
|
|
91
|
+
const contentType = request.headers.get('content-type')?.split(';', 1)[0]?.trim().toLowerCase();
|
|
92
|
+
if (contentType !== 'application/json')
|
|
93
|
+
return new Response('content type must be application/json', { status: 415 });
|
|
94
|
+
let body;
|
|
95
|
+
try {
|
|
96
|
+
body = await request.json();
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return new Response('body is not JSON', { status: 400 });
|
|
100
|
+
}
|
|
101
|
+
if (request.signal.aborted)
|
|
102
|
+
return failure(correlation(body), 'cancelled', 'The request was cancelled before dispatch.');
|
|
103
|
+
const envelope = envelopeSchema.safeParse(body);
|
|
104
|
+
if (!envelope.success)
|
|
105
|
+
return failure(correlation(body), 'bad-request', 'Invalid client-request message.');
|
|
106
|
+
const message = envelope.data;
|
|
107
|
+
if (message.method !== ENDPOINT)
|
|
108
|
+
return failure(message.rpcId, 'bad-request', 'RPC method does not match the POC console endpoint.');
|
|
109
|
+
const parsed = requestSchema.safeParse(message.payload);
|
|
110
|
+
if (!parsed.success) {
|
|
111
|
+
const first = parsed.error.issues[0];
|
|
112
|
+
return failure(message.rpcId, 'bad-request', first?.message ?? 'Invalid POC console request.', { issues: parsed.error.issues.slice(0, 4) });
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
request.signal.throwIfAborted();
|
|
116
|
+
return success(message.rpcId, await dispatch(await ready(), parsed.data, request.signal));
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
// Both authored failure families keep their stable code; anything else
|
|
120
|
+
// stays a generic internal error with the detail only in the Host log.
|
|
121
|
+
if (error instanceof RepoError) {
|
|
122
|
+
return failure(correlation(body), error.code, error.message.slice(0, 2000), error.details);
|
|
123
|
+
}
|
|
124
|
+
if (request.signal.aborted)
|
|
125
|
+
return failure(correlation(body), 'cancelled', 'The request was cancelled.');
|
|
126
|
+
options.onInternalError?.(error);
|
|
127
|
+
return failure(correlation(body), 'internal', 'The POC console hit an internal error; check the Host log.');
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|