@termix-ssh/plugin-sdk 1.0.20 → 1.0.21

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 (36) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/PLUGIN-GUIDE.md +5 -2
  3. package/dist/host/{PluginsTab-ZSMTJ5C5.js → PluginsTab-HQGSDSHS.js} +7 -5
  4. package/dist/host/{chunk-J3ZQPBDK.js → chunk-A5CULDWV.js} +10 -5
  5. package/dist/host/{chunk-2MU6WNSX.js → chunk-FGX27MAA.js} +1 -1
  6. package/dist/host/{chunk-EYONBBRJ.js → chunk-GTHINW3L.js} +1 -1
  7. package/dist/host/{chunk-7LEJ3HYF.js → chunk-JFQGI4OD.js} +5 -3
  8. package/dist/host/{chunk-CITUENSU.js → chunk-WWFRBU2E.js} +3 -2
  9. package/dist/host/{linked-server-OUF3POT7.js → linked-server-UDSFY3N7.js} +1 -1
  10. package/dist/host/{rbac-api-LZVENREG.js → rbac-api-AAAPMF52.js} +1 -1
  11. package/dist/host/testing-host.js +4 -4
  12. package/dist/host/types/src/ui/api/look-api.d.ts +2 -0
  13. package/dist/host/types/src/ui/api/plugins-api.d.ts +1 -1
  14. package/dist/host/types/src/ui/lib/app-return.d.ts +13 -0
  15. package/dist/host/types/src/ui/plugins/plugin-model.d.ts +1 -1
  16. package/dist/host/ui.js +67 -24
  17. package/dist/host/{use-permissions-BYCDS5PD.js → use-permissions-VAND5GEG.js} +1 -1
  18. package/dist/host-commands.d.ts +2 -6
  19. package/dist/host-commands.js +3 -6
  20. package/dist/host-scripts/docker.d.ts +137 -0
  21. package/dist/host-scripts/docker.js +345 -0
  22. package/dist/host-scripts/index.d.ts +15 -0
  23. package/dist/host-scripts/index.js +15 -0
  24. package/dist/host-scripts/journal.d.ts +45 -0
  25. package/dist/host-scripts/journal.js +194 -0
  26. package/dist/host-scripts/metrics.d.ts +134 -0
  27. package/dist/host-scripts/metrics.js +320 -0
  28. package/dist/host-scripts/openrc.d.ts +6 -0
  29. package/dist/host-scripts/openrc.js +90 -0
  30. package/dist/host-scripts/shell.d.ts +43 -0
  31. package/dist/host-scripts/shell.js +95 -0
  32. package/dist/host-scripts/systemd.d.ts +73 -0
  33. package/dist/host-scripts/systemd.js +320 -0
  34. package/dist/host-scripts/text.d.ts +23 -0
  35. package/dist/host-scripts/text.js +111 -0
  36. package/package.json +5 -1
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Quoting, encoding and the error type the host scripts share.
3
+ *
4
+ * No Node APIs here: this entry also runs in the mobile app.
5
+ */
6
+ /** A bad input to a host script builder. `status` is the HTTP status to answer with. */
7
+ export class HostScriptError extends Error {
8
+ status;
9
+ extra;
10
+ constructor(message, status = 400, extra = {}) {
11
+ super(message);
12
+ this.status = status;
13
+ this.extra = extra;
14
+ this.name = "HostScriptError";
15
+ }
16
+ }
17
+ /** Wraps a value in single quotes for a POSIX shell. */
18
+ export function shellQuote(value) {
19
+ return `'${value.replace(/'/g, `'\\''`)}'`;
20
+ }
21
+ // Written by hand because some JS engines (Hermes) have no TextDecoder.
22
+ /** UTF-8 bytes of a string. */
23
+ export function utf8Encode(text) {
24
+ const out = [];
25
+ for (const char of text) {
26
+ const cp = char.codePointAt(0) ?? 0xfffd;
27
+ if (cp < 0x80)
28
+ out.push(cp);
29
+ else if (cp < 0x800)
30
+ out.push(0xc0 | (cp >> 6), 0x80 | (cp & 63));
31
+ else if (cp < 0x10000) {
32
+ out.push(0xe0 | (cp >> 12), 0x80 | ((cp >> 6) & 63), 0x80 | (cp & 63));
33
+ }
34
+ else {
35
+ out.push(0xf0 | (cp >> 18), 0x80 | ((cp >> 12) & 63), 0x80 | ((cp >> 6) & 63), 0x80 | (cp & 63));
36
+ }
37
+ }
38
+ return Uint8Array.from(out);
39
+ }
40
+ /** A string from UTF-8 bytes. Bad sequences become U+FFFD. */
41
+ export function utf8Decode(bytes) {
42
+ let out = "";
43
+ let i = 0;
44
+ while (i < bytes.length) {
45
+ const b = bytes[i];
46
+ let need = 0;
47
+ let cp = 0;
48
+ if (b < 0x80)
49
+ cp = b;
50
+ else if (b >= 0xc2 && b < 0xe0)
51
+ [need, cp] = [1, b & 31];
52
+ else if (b >= 0xe0 && b < 0xf0)
53
+ [need, cp] = [2, b & 15];
54
+ else if (b >= 0xf0 && b < 0xf5)
55
+ [need, cp] = [3, b & 7];
56
+ else {
57
+ out += "\ufffd";
58
+ i++;
59
+ continue;
60
+ }
61
+ let j = 1;
62
+ for (; j <= need; j++) {
63
+ const next = bytes[i + j];
64
+ if (next === undefined || (next & 0xc0) !== 0x80)
65
+ break;
66
+ cp = (cp << 6) | (next & 63);
67
+ }
68
+ const tooSmall = [0, 0x80, 0x800, 0x10000][need];
69
+ if (j <= need ||
70
+ cp < tooSmall ||
71
+ cp > 0x10ffff ||
72
+ (cp >= 0xd800 && cp < 0xe000)) {
73
+ out += "\ufffd";
74
+ i += Math.max(1, j);
75
+ continue;
76
+ }
77
+ out += String.fromCodePoint(cp);
78
+ i += need + 1;
79
+ }
80
+ return out;
81
+ }
82
+ const B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
83
+ /** Base64 of the UTF-8 bytes of a string, for `base64 -d` on the host. */
84
+ export function toBase64(text) {
85
+ const bytes = utf8Encode(text);
86
+ let out = "";
87
+ for (let i = 0; i < bytes.length; i += 3) {
88
+ const a = bytes[i];
89
+ const b = i + 1 < bytes.length ? bytes[i + 1] : 0;
90
+ const c = i + 2 < bytes.length ? bytes[i + 2] : 0;
91
+ const n = (a << 16) | (b << 8) | c;
92
+ out += B64[(n >> 18) & 63] + B64[(n >> 12) & 63];
93
+ out += i + 1 < bytes.length ? B64[(n >> 6) & 63] : "=";
94
+ out += i + 2 < bytes.length ? B64[n & 63] : "=";
95
+ }
96
+ return out;
97
+ }
98
+ /** Reads key=value lines. Only the first = splits a line. */
99
+ export function parseKeys(output) {
100
+ const out = {};
101
+ for (const line of output.split("\n")) {
102
+ const eq = line.indexOf("=");
103
+ if (eq > 0)
104
+ out[line.slice(0, eq).trim()] = line.slice(eq + 1).trim();
105
+ }
106
+ return out;
107
+ }
108
+ /** Trims output and keeps it short enough to show. */
109
+ export function scrub(text, max = 600) {
110
+ return text.trim().slice(0, max);
111
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@termix-ssh/plugin-sdk",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
4
4
  "description": "The contract between Termix core and a plugin: types, the capability catalog and the manifest schema.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -81,6 +81,10 @@
81
81
  "types": "./dist/host-commands.d.ts",
82
82
  "default": "./dist/host-commands.js"
83
83
  },
84
+ "./host-scripts": {
85
+ "types": "./dist/host-scripts/index.d.ts",
86
+ "default": "./dist/host-scripts/index.js"
87
+ },
84
88
  "./ssh-certs": {
85
89
  "types": "./dist/ssh-certs.d.ts",
86
90
  "default": "./dist/ssh-certs.js"