@tsplc/agent 0.5.9 → 0.5.12
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/cli.js +2660 -525
- package/dist/cli.js.map +32 -18
- package/dist/client.js +262 -37
- package/dist/client.js.map +4 -4
- package/dist/index.js +2325 -415
- package/dist/index.js.map +27 -14
- package/package.json +6 -5
- package/src/access.ts +276 -0
- package/src/agent.ts +130 -29
- package/src/audit.ts +64 -0
- package/src/cli.ts +81 -5
- package/src/client.ts +204 -36
- package/src/controller.ts +60 -0
- package/src/dashboard/index.ts +118 -0
- package/src/dashboard/ui/access.ts +192 -0
- package/src/dashboard/ui/actions.ts +192 -0
- package/src/dashboard/ui/api.ts +158 -0
- package/src/dashboard/ui/app.ts +41 -0
- package/src/dashboard/ui/approval.ts +132 -0
- package/src/dashboard/ui/audit.ts +115 -0
- package/src/dashboard/ui/contract.ts +19 -0
- package/src/dashboard/ui/dashboard.css +1332 -0
- package/src/dashboard/ui/deployment.ts +432 -0
- package/src/dashboard/ui/deployments.ts +317 -0
- package/src/dashboard/ui/details.ts +240 -0
- package/src/dashboard/ui/dom.ts +91 -0
- package/src/dashboard/ui/environment.ts +326 -0
- package/src/dashboard/ui/format.ts +118 -0
- package/src/dashboard/ui/logs.ts +127 -0
- package/src/dashboard/ui/main.ts +86 -0
- package/src/dashboard/ui/overlay.ts +146 -0
- package/src/dashboard/ui/shell.ts +192 -0
- package/src/dashboard/ui/source.ts +144 -0
- package/src/deploy.ts +174 -144
- package/src/deployments/health.ts +80 -0
- package/src/deployments/retention.ts +45 -0
- package/src/deployments/routes.ts +273 -0
- package/src/deployments/runner.ts +877 -0
- package/src/deployments/store.ts +233 -0
- package/src/environment.ts +284 -0
- package/src/index.ts +4 -0
- package/src/login.ts +17 -0
- package/src/operations.ts +6 -1
- package/src/protocol.ts +259 -2
- package/src/releases.ts +73 -1
- package/src/routes.ts +52 -0
- package/src/secrets.ts +74 -4
- package/src/server-process.ts +33 -16
- package/src/sessions.ts +58 -0
- package/src/state.ts +2 -0
- package/src/tailscale.ts +112 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { DeploymentRecord } from "../../protocol";
|
|
2
|
+
import { cancel } from "./actions";
|
|
3
|
+
import { api } from "./api";
|
|
4
|
+
import { type App, attempt } from "./app";
|
|
5
|
+
import { h } from "./dom";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* What a deployment waiting in `awaitingApproval` asks of a deployer. A full download stops the
|
|
9
|
+
* line, so approving one takes an explicit acknowledgement first.
|
|
10
|
+
*/
|
|
11
|
+
export const approvalBanner = (
|
|
12
|
+
app: App,
|
|
13
|
+
record: DeploymentRecord,
|
|
14
|
+
onChanged: () => void,
|
|
15
|
+
) => {
|
|
16
|
+
const { approval } = record;
|
|
17
|
+
if (record.state !== "awaitingApproval" || !approval) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const deployer = app.can("deployer");
|
|
21
|
+
const cancelButton = h(
|
|
22
|
+
"button",
|
|
23
|
+
{
|
|
24
|
+
class: "button",
|
|
25
|
+
onclick: () => void cancel(record).then(onChanged),
|
|
26
|
+
},
|
|
27
|
+
"Cancel deployment",
|
|
28
|
+
);
|
|
29
|
+
if (approval.reason === "review") {
|
|
30
|
+
return h(
|
|
31
|
+
"section",
|
|
32
|
+
{ class: "banner t-waiting" },
|
|
33
|
+
h(
|
|
34
|
+
"div",
|
|
35
|
+
{ class: "banner-text" },
|
|
36
|
+
h("h3", {}, "Waiting for review"),
|
|
37
|
+
h("p", {}, approval.message),
|
|
38
|
+
h(
|
|
39
|
+
"p",
|
|
40
|
+
{ class: "muted" },
|
|
41
|
+
record.findings.length
|
|
42
|
+
? `The online-change check found ${record.findings.length} ${record.findings.length === 1 ? "thing" : "things"} to look at: see Changes.`
|
|
43
|
+
: "The online-change check found nothing to report.",
|
|
44
|
+
),
|
|
45
|
+
),
|
|
46
|
+
deployer
|
|
47
|
+
? h(
|
|
48
|
+
"div",
|
|
49
|
+
{ class: "banner-actions" },
|
|
50
|
+
cancelButton,
|
|
51
|
+
h(
|
|
52
|
+
"button",
|
|
53
|
+
{
|
|
54
|
+
class: "button primary",
|
|
55
|
+
onclick: () =>
|
|
56
|
+
void attempt(
|
|
57
|
+
() => api.approve(record.id, false),
|
|
58
|
+
"Approved: the deployment applies now",
|
|
59
|
+
).then(onChanged),
|
|
60
|
+
},
|
|
61
|
+
"Approve and apply",
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
: h("p", { class: "muted" }, "A deployer must approve it."),
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
const refusals = record.findings.filter((finding) => finding.refuses);
|
|
68
|
+
const acknowledge = h("input", { type: "checkbox" });
|
|
69
|
+
const approve = h(
|
|
70
|
+
"button",
|
|
71
|
+
{
|
|
72
|
+
class: "button danger",
|
|
73
|
+
disabled: true,
|
|
74
|
+
onclick: () =>
|
|
75
|
+
void attempt(
|
|
76
|
+
() => api.approve(record.id, true),
|
|
77
|
+
"Approved: the full download starts now",
|
|
78
|
+
).then(onChanged),
|
|
79
|
+
},
|
|
80
|
+
"Approve full download",
|
|
81
|
+
);
|
|
82
|
+
acknowledge.addEventListener("change", () => {
|
|
83
|
+
approve.disabled = !acknowledge.checked;
|
|
84
|
+
});
|
|
85
|
+
return h(
|
|
86
|
+
"section",
|
|
87
|
+
{ class: "banner t-error" },
|
|
88
|
+
h(
|
|
89
|
+
"div",
|
|
90
|
+
{ class: "banner-text" },
|
|
91
|
+
h("h3", {}, "A full download stops the line"),
|
|
92
|
+
h("p", {}, approval.message),
|
|
93
|
+
h(
|
|
94
|
+
"p",
|
|
95
|
+
{},
|
|
96
|
+
"An online change can't apply this release. A full download stops the PLC application, and the line with it, until the download has finished and the application runs again.",
|
|
97
|
+
),
|
|
98
|
+
refusals.length
|
|
99
|
+
? h(
|
|
100
|
+
"ul",
|
|
101
|
+
{ class: "refusals" },
|
|
102
|
+
...refusals.map((finding) =>
|
|
103
|
+
h(
|
|
104
|
+
"li",
|
|
105
|
+
{},
|
|
106
|
+
h(
|
|
107
|
+
"span",
|
|
108
|
+
{ class: "mono" },
|
|
109
|
+
finding.variable
|
|
110
|
+
? `${finding.object}.${finding.variable}`
|
|
111
|
+
: finding.object,
|
|
112
|
+
),
|
|
113
|
+
": ",
|
|
114
|
+
finding.advice,
|
|
115
|
+
),
|
|
116
|
+
),
|
|
117
|
+
)
|
|
118
|
+
: null,
|
|
119
|
+
deployer
|
|
120
|
+
? h(
|
|
121
|
+
"label",
|
|
122
|
+
{ class: "check acknowledge" },
|
|
123
|
+
acknowledge,
|
|
124
|
+
"I understand that approving stops the line while the controller downloads.",
|
|
125
|
+
)
|
|
126
|
+
: null,
|
|
127
|
+
),
|
|
128
|
+
deployer
|
|
129
|
+
? h("div", { class: "banner-actions" }, cancelButton, approve)
|
|
130
|
+
: h("p", { class: "muted" }, "A deployer must approve it."),
|
|
131
|
+
);
|
|
132
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { errorMessage } from "../../errors";
|
|
2
|
+
import type { Audit } from "../../protocol";
|
|
3
|
+
import { api } from "./api";
|
|
4
|
+
import type { App } from "./app";
|
|
5
|
+
import { empty, fill, h, pageHeader, type View } from "./dom";
|
|
6
|
+
import { formatAgo, formatTimestamp } from "./format";
|
|
7
|
+
|
|
8
|
+
const limits = [100, 500, 2000];
|
|
9
|
+
|
|
10
|
+
const values = (entries: Record<string, string>) => {
|
|
11
|
+
const pairs = Object.entries(entries);
|
|
12
|
+
if (!pairs.length) {
|
|
13
|
+
return h("span", { class: "muted" }, "—");
|
|
14
|
+
}
|
|
15
|
+
return h(
|
|
16
|
+
"div",
|
|
17
|
+
{ class: "values" },
|
|
18
|
+
...pairs.map(([expression, value]) =>
|
|
19
|
+
h(
|
|
20
|
+
"div",
|
|
21
|
+
{ class: "mono" },
|
|
22
|
+
expression,
|
|
23
|
+
value ? h("span", { class: "muted" }, ` = ${value}`) : null,
|
|
24
|
+
),
|
|
25
|
+
),
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const row = (entry: Audit, now: number) =>
|
|
30
|
+
h(
|
|
31
|
+
"tr",
|
|
32
|
+
{ class: entry.error ? "failed" : "" },
|
|
33
|
+
h(
|
|
34
|
+
"td",
|
|
35
|
+
{ class: "nowrap", title: formatTimestamp(entry.at) },
|
|
36
|
+
formatAgo(entry.at, now),
|
|
37
|
+
),
|
|
38
|
+
h("td", { class: "mono nowrap" }, entry.command),
|
|
39
|
+
h("td", {}, values(entry.values)),
|
|
40
|
+
h(
|
|
41
|
+
"td",
|
|
42
|
+
{},
|
|
43
|
+
entry.previous
|
|
44
|
+
? values(entry.previous)
|
|
45
|
+
: h("span", { class: "muted" }, "—"),
|
|
46
|
+
),
|
|
47
|
+
h(
|
|
48
|
+
"td",
|
|
49
|
+
{ class: "nowrap" },
|
|
50
|
+
[entry.user, entry.host].filter(Boolean).join("@") || "—",
|
|
51
|
+
),
|
|
52
|
+
h("td", { class: "mono nowrap" }, entry.release?.slice(0, 12) ?? "—"),
|
|
53
|
+
h("td", { class: "error-text" }, entry.error ?? ""),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
/** What was changed on the controller through the agent's login, newest first. */
|
|
57
|
+
export const auditView = (_app: App): View => {
|
|
58
|
+
const limit = h(
|
|
59
|
+
"select",
|
|
60
|
+
{ class: "input", "aria-label": "Entries" },
|
|
61
|
+
...limits.map((value) => h("option", { value }, `Last ${value}`)),
|
|
62
|
+
);
|
|
63
|
+
const holder = h("div", {}, empty("Loading the audit log…"));
|
|
64
|
+
|
|
65
|
+
const load = async () => {
|
|
66
|
+
try {
|
|
67
|
+
const entries = await api.audit(Number(limit.value));
|
|
68
|
+
const now = Date.now();
|
|
69
|
+
fill(
|
|
70
|
+
holder,
|
|
71
|
+
entries.length
|
|
72
|
+
? h(
|
|
73
|
+
"table",
|
|
74
|
+
{ class: "table" },
|
|
75
|
+
h(
|
|
76
|
+
"thead",
|
|
77
|
+
{},
|
|
78
|
+
h(
|
|
79
|
+
"tr",
|
|
80
|
+
{},
|
|
81
|
+
...[
|
|
82
|
+
"When",
|
|
83
|
+
"Command",
|
|
84
|
+
"Values",
|
|
85
|
+
"Before",
|
|
86
|
+
"By",
|
|
87
|
+
"Release",
|
|
88
|
+
"Error",
|
|
89
|
+
].map((label) => h("th", {}, label)),
|
|
90
|
+
),
|
|
91
|
+
),
|
|
92
|
+
h("tbody", {}, ...entries.map((entry) => row(entry, now))),
|
|
93
|
+
)
|
|
94
|
+
: empty("Nothing has been written or forced through the agent yet."),
|
|
95
|
+
);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
fill(holder, h("p", { class: "error-text" }, errorMessage(error)));
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
limit.addEventListener("change", () => void load());
|
|
101
|
+
void load();
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
element: h(
|
|
105
|
+
"div",
|
|
106
|
+
{ class: "page" },
|
|
107
|
+
pageHeader(
|
|
108
|
+
"Audit",
|
|
109
|
+
"Writes, forces and resets through the agent's login, newest first.",
|
|
110
|
+
limit,
|
|
111
|
+
),
|
|
112
|
+
holder,
|
|
113
|
+
),
|
|
114
|
+
};
|
|
115
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { controllerRestartPath as restartPath } from "@tsplc/server/plant-agent";
|
|
2
|
+
import type { Role, roles } from "../../protocol";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Put into the bundle by `createDashboard`, from protocol.ts and `@tsplc/server/plant-agent`: the bundle can't import protocol.ts,
|
|
6
|
+
* whose other schemas load the agent's Node-only packages.
|
|
7
|
+
*/
|
|
8
|
+
declare const TSPLC_CONTRACT: {
|
|
9
|
+
roles: typeof roles;
|
|
10
|
+
controllerRestartPath: typeof restartPath;
|
|
11
|
+
permissions: Readonly<Record<Role, Readonly<Record<Role, boolean>>>>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const roleNames = TSPLC_CONTRACT.roles;
|
|
15
|
+
export const controllerRestartPath = TSPLC_CONTRACT.controllerRestartPath;
|
|
16
|
+
|
|
17
|
+
/** Whether `role` includes `required`, as protocol.ts's `allows` answered it. */
|
|
18
|
+
export const allows = (role: Role, required: Role) =>
|
|
19
|
+
TSPLC_CONTRACT.permissions[role][required];
|