@miakapp/cli 4.0.0-alpha.3 → 4.0.0-alpha.4

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 (61) hide show
  1. package/dist/agent-pack.d.ts +86 -0
  2. package/dist/agent-pack.d.ts.map +1 -0
  3. package/dist/agent-pack.js +202 -0
  4. package/dist/agent-pack.js.map +1 -0
  5. package/dist/artifact.d.ts +32 -0
  6. package/dist/artifact.d.ts.map +1 -0
  7. package/dist/artifact.js +328 -0
  8. package/dist/artifact.js.map +1 -0
  9. package/dist/control-plane.d.ts +37 -0
  10. package/dist/control-plane.d.ts.map +1 -0
  11. package/dist/control-plane.js +127 -0
  12. package/dist/control-plane.js.map +1 -0
  13. package/dist/discovery.d.ts +95 -0
  14. package/dist/discovery.d.ts.map +1 -0
  15. package/dist/discovery.js +389 -0
  16. package/dist/discovery.js.map +1 -0
  17. package/dist/errors.d.ts +37 -0
  18. package/dist/errors.d.ts.map +1 -0
  19. package/dist/errors.js +56 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/internal/http.d.ts +35 -0
  22. package/dist/internal/http.d.ts.map +1 -0
  23. package/dist/internal/http.js +125 -0
  24. package/dist/internal/http.js.map +1 -0
  25. package/dist/internal/json.d.ts +15 -0
  26. package/dist/internal/json.d.ts.map +1 -0
  27. package/dist/internal/json.js +227 -0
  28. package/dist/internal/json.js.map +1 -0
  29. package/dist/internal/names.d.ts +45 -0
  30. package/dist/internal/names.d.ts.map +1 -0
  31. package/dist/internal/names.js +98 -0
  32. package/dist/internal/names.js.map +1 -0
  33. package/dist/internal/requirements.d.ts +10 -0
  34. package/dist/internal/requirements.d.ts.map +1 -0
  35. package/dist/internal/requirements.js +50 -0
  36. package/dist/internal/requirements.js.map +1 -0
  37. package/dist/internal/yaml.d.ts +26 -0
  38. package/dist/internal/yaml.d.ts.map +1 -0
  39. package/dist/internal/yaml.js +184 -0
  40. package/dist/internal/yaml.js.map +1 -0
  41. package/dist/main.d.ts +88 -0
  42. package/dist/main.d.ts.map +1 -0
  43. package/dist/main.js +698 -0
  44. package/dist/main.js.map +1 -0
  45. package/dist/mcp.d.ts +93 -0
  46. package/dist/mcp.d.ts.map +1 -0
  47. package/dist/mcp.js +539 -0
  48. package/dist/mcp.js.map +1 -0
  49. package/dist/project.d.ts +25 -0
  50. package/dist/project.d.ts.map +1 -0
  51. package/dist/project.js +90 -0
  52. package/dist/project.js.map +1 -0
  53. package/dist/publication.d.ts +95 -0
  54. package/dist/publication.d.ts.map +1 -0
  55. package/dist/publication.js +408 -0
  56. package/dist/publication.js.map +1 -0
  57. package/dist/version.d.ts +15 -0
  58. package/dist/version.d.ts.map +1 -0
  59. package/dist/version.js +15 -0
  60. package/dist/version.js.map +1 -0
  61. package/package.json +2 -1
@@ -0,0 +1,389 @@
1
+ /**
2
+ * Reading an installation that already exists.
3
+ *
4
+ * `docs/agent-guide.md` §3 tells an agent to characterize the house before
5
+ * designing anything. This module is the part of that work a program can do:
6
+ * it turns a Node-RED `flows.json` export into an inventory of brokers, flows,
7
+ * topics and the V3 MiakAPI surface, and it reports which V3 names are already
8
+ * legal V4 names.
9
+ *
10
+ * Three properties keep it honest:
11
+ *
12
+ * - **Offline and read-only.** It parses bytes handed to it. It opens no
13
+ * socket, contacts no broker and writes nothing back into the export.
14
+ * - **It never drops a node silently.** Every unrecognized `type` is counted
15
+ * and reported, because the value of an inventory is knowing what it missed.
16
+ * - **It never guesses semantics.** It reports what a node declares. Which
17
+ * actions are physically consequential is a judgement the reader makes from
18
+ * the listed surface; no keyword list decides it here.
19
+ *
20
+ * Field names come from the two schemas involved: Node-RED core `mqtt in`,
21
+ * `mqtt out` and `mqtt-broker` node definitions, and the `node-red-contrib-
22
+ * MiakAPI` v3 node definitions in `miakapi.html`.
23
+ */
24
+ import { projectError } from './errors.js';
25
+ import { isDottedName, utf8Bytes } from './internal/names.js';
26
+ /**
27
+ * A generous ceiling for a local export. The strict parser in `internal/json.ts`
28
+ * is bounded for untrusted control-plane responses at 2,048 values, which a real
29
+ * house blows through in the first tab; a flows export is an operator-supplied
30
+ * local file, so the bound here is on bytes rather than on structure.
31
+ */
32
+ export const MAXIMUM_FLOWS_BYTES = 33_554_432;
33
+ /** Keys that would poison a prototype if a record were ever spread. */
34
+ const FORBIDDEN_KEYS = new Set(['__proto__', 'prototype', 'constructor']);
35
+ const MIAKAPI_V3_TYPES = new Set([
36
+ 'initMiakapi',
37
+ 'getHomeUsers',
38
+ 'commitVariables',
39
+ 'onHomeReady',
40
+ 'onHomeUpdate',
41
+ 'onUserLogin',
42
+ 'onUserAction',
43
+ 'sendPushNotif',
44
+ 'reconnectMiakapi',
45
+ ]);
46
+ function field(node, key) {
47
+ return Object.hasOwn(node, key) ? node[key] : undefined;
48
+ }
49
+ function text(node, key) {
50
+ const value = field(node, key);
51
+ return typeof value === 'string' ? value : '';
52
+ }
53
+ function flag(node, key) {
54
+ return field(node, key) === true;
55
+ }
56
+ /** Node-RED writes `port` as either a number or a numeric string. */
57
+ function port(node) {
58
+ const value = field(node, 'port');
59
+ if (typeof value === 'number' && Number.isSafeInteger(value))
60
+ return value;
61
+ if (typeof value === 'string' && /^[0-9]{1,5}$/.test(value))
62
+ return Number(value);
63
+ return undefined;
64
+ }
65
+ function finding(kind, severity, detail, nodeId) {
66
+ return Object.freeze({ kind, severity, detail, nodeId });
67
+ }
68
+ /**
69
+ * Parses the export.
70
+ *
71
+ * A flows export is a flat array of node records; tabs, config nodes and wired
72
+ * nodes all sit at the same level and refer to each other by `id`.
73
+ */
74
+ function parseFlows(source) {
75
+ if (source.byteLength > MAXIMUM_FLOWS_BYTES) {
76
+ throw projectError(`The flows export is larger than ${MAXIMUM_FLOWS_BYTES} bytes`, 'Export one Node-RED instance at a time.');
77
+ }
78
+ let decoded;
79
+ try {
80
+ decoded = new TextDecoder('utf-8', { fatal: true }).decode(source);
81
+ }
82
+ catch {
83
+ throw projectError('The flows export is not readable as UTF-8 text');
84
+ }
85
+ let parsed;
86
+ try {
87
+ parsed = JSON.parse(decoded);
88
+ }
89
+ catch {
90
+ throw projectError('The flows export is not valid JSON', 'Use the file Node-RED writes, or the Export > All flows download, not a screenshot of it.');
91
+ }
92
+ if (!Array.isArray(parsed)) {
93
+ throw projectError('The flows export is not a JSON array of nodes', 'A Node-RED export is a flat array; an object here is usually a single copied node.');
94
+ }
95
+ const nodes = [];
96
+ for (const entry of parsed) {
97
+ if (entry === null || typeof entry !== 'object' || Array.isArray(entry))
98
+ continue;
99
+ // Values are only ever read through `Object.hasOwn`, never spread, so a
100
+ // poisoned key cannot reach a prototype; it is dropped here regardless.
101
+ if (Reflect.ownKeys(entry).some((key) => FORBIDDEN_KEYS.has(String(key))))
102
+ continue;
103
+ if (typeof entry['type'] !== 'string')
104
+ continue;
105
+ nodes.push(entry);
106
+ }
107
+ return nodes;
108
+ }
109
+ function collectTabs(nodes) {
110
+ const counts = new Map();
111
+ for (const node of nodes) {
112
+ const parent = text(node, 'z');
113
+ if (parent !== '')
114
+ counts.set(parent, (counts.get(parent) ?? 0) + 1);
115
+ }
116
+ return nodes
117
+ .filter((node) => node['type'] === 'tab')
118
+ .map((node) => {
119
+ const id = text(node, 'id');
120
+ return Object.freeze({
121
+ id,
122
+ label: text(node, 'label'),
123
+ disabled: flag(node, 'disabled'),
124
+ nodeCount: counts.get(id) ?? 0,
125
+ });
126
+ });
127
+ }
128
+ function collectBrokers(nodes, findings) {
129
+ const subscribes = new Map();
130
+ const publishes = new Map();
131
+ for (const node of nodes) {
132
+ const type = node['type'];
133
+ if (type !== 'mqtt in' && type !== 'mqtt out')
134
+ continue;
135
+ const broker = text(node, 'broker');
136
+ const topic = text(node, 'topic');
137
+ if (broker === '')
138
+ continue;
139
+ if (topic === '') {
140
+ // `mqtt in` with `topicType: dynamic` takes its topic from a message, so
141
+ // the export cannot say which devices it will reach.
142
+ findings.push(finding('unmodelled_node', 'attention', `${String(type)} node has no static topic; its subscription is set at runtime`, text(node, 'id')));
143
+ continue;
144
+ }
145
+ const into = type === 'mqtt in' ? subscribes : publishes;
146
+ const set = into.get(broker) ?? new Set();
147
+ set.add(topic);
148
+ into.set(broker, set);
149
+ if (type === 'mqtt in' && (topic.includes('#') || topic.includes('+'))) {
150
+ findings.push(finding('wildcard_subscription', 'note', `Subscription ${topic} is a pattern, not one device; enumerate what it actually matches`, text(node, 'id')));
151
+ }
152
+ }
153
+ return nodes
154
+ .filter((node) => node['type'] === 'mqtt-broker')
155
+ .map((node) => {
156
+ const id = text(node, 'id');
157
+ const host = text(node, 'broker');
158
+ const tls = flag(node, 'usetls');
159
+ if (!tls) {
160
+ findings.push(finding('broker_without_tls', 'attention', `Broker ${host === '' ? id : host} is configured without TLS`, id));
161
+ }
162
+ return Object.freeze({
163
+ id,
164
+ name: text(node, 'name'),
165
+ host,
166
+ port: port(node),
167
+ tls,
168
+ subscribes: [...subscribes.get(id) ?? []].sort(),
169
+ publishes: [...publishes.get(id) ?? []].sort(),
170
+ });
171
+ });
172
+ }
173
+ function collectHomes(nodes, findings) {
174
+ return nodes
175
+ .filter((node) => node['type'] === 'initMiakapi')
176
+ .map((node) => {
177
+ const nodeId = text(node, 'id');
178
+ // `coordSecret` is declared in the node's `defaults`, not in its
179
+ // `credentials`, so Node-RED stores it in `flows.json` itself rather than
180
+ // in the encrypted `flows_cred.json`.
181
+ const secretInExport = text(node, 'coordSecret') !== '';
182
+ if (secretInExport) {
183
+ findings.push(finding('secret_in_export', 'critical', 'A coordinator secret is stored in cleartext in this export; treat it as leaked, '
184
+ + 'rotate it, and keep the export out of Git', nodeId));
185
+ }
186
+ return Object.freeze({
187
+ nodeId,
188
+ homeId: text(node, 'home'),
189
+ coordinatorId: text(node, 'coordID'),
190
+ secretInExport,
191
+ });
192
+ });
193
+ }
194
+ /**
195
+ * Why a V3 name is not a legal V4 dotted name, in the words of the rule it
196
+ * breaks. `isDottedName` answers yes or no; a reader who has to rename a path
197
+ * needs to know which constraint bit them.
198
+ */
199
+ function illegalNameReason(value) {
200
+ if (value === '')
201
+ return 'it is empty';
202
+ if (value.includes('*'))
203
+ return 'it contains *, which V4 reserves for the trailing .* suffix';
204
+ if (/\p{Cc}/u.test(value))
205
+ return 'it contains a control character';
206
+ if (value.split('.').some((segment) => segment === '')) {
207
+ return 'it has an empty dotted segment';
208
+ }
209
+ return `it is ${utf8Bytes(value)} UTF-8 bytes, outside the 1..256 range`;
210
+ }
211
+ function variableSource(type) {
212
+ if (type === 'jsonata')
213
+ return 'jsonata';
214
+ if (type === 'env')
215
+ return 'env';
216
+ return 'literal';
217
+ }
218
+ function collectState(nodes, findings) {
219
+ const candidates = [];
220
+ for (const node of nodes) {
221
+ if (node['type'] !== 'commitVariables')
222
+ continue;
223
+ const values = field(node, 'values');
224
+ if (values === null || typeof values !== 'object' || Array.isArray(values))
225
+ continue;
226
+ const nodeId = text(node, 'id');
227
+ for (const path of Object.keys(values)) {
228
+ if (FORBIDDEN_KEYS.has(path))
229
+ continue;
230
+ const entry = values[path];
231
+ const type = entry !== null && typeof entry === 'object' && !Array.isArray(entry)
232
+ ? entry['type']
233
+ : undefined;
234
+ const legalV4Name = isDottedName(path);
235
+ if (!legalV4Name) {
236
+ findings.push(finding('name_needs_rename', 'attention', `Variable path ${path} is not a legal V4 state path: ${illegalNameReason(path)}; `
237
+ + 'rename it before the household depends on it', nodeId));
238
+ }
239
+ candidates.push(Object.freeze({
240
+ path,
241
+ source: variableSource(type),
242
+ nodeId,
243
+ legalV4Name,
244
+ }));
245
+ }
246
+ }
247
+ return candidates.sort((left, right) => (left.path < right.path ? -1 : 1));
248
+ }
249
+ function collectActions(nodes, findings) {
250
+ const candidates = [];
251
+ for (const node of nodes) {
252
+ if (node['type'] !== 'onUserAction')
253
+ continue;
254
+ const nodeId = text(node, 'id');
255
+ const inputId = text(node, 'inputID');
256
+ const raw = field(node, 'allowedGroups');
257
+ const allowedGroups = Array.isArray(raw)
258
+ ? raw.filter((group) => typeof group === 'string')
259
+ : [];
260
+ // The v3 handler allows the action outright when no group is listed, so an
261
+ // empty list is a grant to every signed-in user, not a deny.
262
+ if (allowedGroups.length === 0) {
263
+ findings.push(finding('unrestricted_action', 'critical', `Action ${inputId === '' ? nodeId : inputId} lists no group, so every signed-in user `
264
+ + 'may invoke it; V4 needs an explicit rule for it', nodeId));
265
+ }
266
+ const legalV4Name = isDottedName(inputId);
267
+ if (!legalV4Name) {
268
+ findings.push(finding('name_needs_rename', 'attention', `Action id ${inputId === '' ? '(empty)' : inputId} is not a legal V4 function name: `
269
+ + illegalNameReason(inputId), nodeId));
270
+ }
271
+ candidates.push(Object.freeze({ inputId, allowedGroups, nodeId, legalV4Name }));
272
+ }
273
+ return candidates.sort((left, right) => (left.inputId < right.inputId ? -1 : 1));
274
+ }
275
+ function collectNotifications(nodes) {
276
+ return nodes
277
+ .filter((node) => node['type'] === 'sendPushNotif')
278
+ .map((node) => Object.freeze({
279
+ nodeId: text(node, 'id'),
280
+ name: text(node, 'name'),
281
+ adminOnly: flag(node, 'adminOnly'),
282
+ group: text(node, 'group'),
283
+ }));
284
+ }
285
+ function collectUnmodelled(nodes, findings) {
286
+ const modelled = new Set(['tab', 'mqtt in', 'mqtt out', 'mqtt-broker', ...MIAKAPI_V3_TYPES]);
287
+ const counts = new Map();
288
+ for (const node of nodes) {
289
+ const type = node['type'];
290
+ if (modelled.has(type))
291
+ continue;
292
+ counts.set(type, (counts.get(type) ?? 0) + 1);
293
+ }
294
+ const unmodelled = [...counts]
295
+ .map(([type, count]) => Object.freeze({ type, count }))
296
+ .sort((left, right) => right.count - left.count || (left.type < right.type ? -1 : 1));
297
+ if (unmodelled.length > 0) {
298
+ findings.push(finding('unmodelled_node', 'note', `${unmodelled.length} node type(s) are not modelled by this inventory; `
299
+ + 'read them yourself before assuming the house is fully described'));
300
+ }
301
+ return unmodelled;
302
+ }
303
+ /**
304
+ * Builds the inventory for one Node-RED export.
305
+ *
306
+ * The result is a pure function of the bytes: the same export always produces
307
+ * the same report, which is what makes it usable as a migration baseline that
308
+ * can be diffed between two runs.
309
+ */
310
+ export function discoverFlows(source) {
311
+ const nodes = parseFlows(source);
312
+ const findings = [];
313
+ const flows = collectTabs(nodes);
314
+ const brokers = collectBrokers(nodes, findings);
315
+ const homes = collectHomes(nodes, findings);
316
+ const state = collectState(nodes, findings);
317
+ const actions = collectActions(nodes, findings);
318
+ const notifications = collectNotifications(nodes);
319
+ const unmodelled = collectUnmodelled(nodes, findings);
320
+ const order = { critical: 0, attention: 1, note: 2 };
321
+ return Object.freeze({
322
+ nodeCount: nodes.length,
323
+ flows,
324
+ brokers,
325
+ homes,
326
+ state,
327
+ actions,
328
+ notifications,
329
+ unmodelled,
330
+ findings: findings.sort((left, right) => order[left.severity] - order[right.severity]),
331
+ });
332
+ }
333
+ /** The JSON body of `miakapp discover --json`, with no secret value in it. */
334
+ export function inventoryJson(inventory) {
335
+ return {
336
+ node_count: inventory.nodeCount,
337
+ flows: inventory.flows.map((tab) => ({
338
+ id: tab.id,
339
+ label: tab.label,
340
+ disabled: tab.disabled,
341
+ node_count: tab.nodeCount,
342
+ })),
343
+ brokers: inventory.brokers.map((broker) => ({
344
+ id: broker.id,
345
+ name: broker.name,
346
+ host: broker.host,
347
+ ...(broker.port === undefined ? {} : { port: broker.port }),
348
+ tls: broker.tls,
349
+ subscribes: broker.subscribes,
350
+ publishes: broker.publishes,
351
+ })),
352
+ homes: inventory.homes.map((home) => ({
353
+ node_id: home.nodeId,
354
+ home_id: home.homeId,
355
+ coordinator_id: home.coordinatorId,
356
+ // The flag says a secret is present. The secret itself is never read out.
357
+ secret_in_export: home.secretInExport,
358
+ })),
359
+ state: inventory.state.map((candidate) => ({
360
+ path: candidate.path,
361
+ source: candidate.source,
362
+ node_id: candidate.nodeId,
363
+ legal_v4_name: candidate.legalV4Name,
364
+ })),
365
+ actions: inventory.actions.map((candidate) => ({
366
+ input_id: candidate.inputId,
367
+ allowed_groups: candidate.allowedGroups,
368
+ node_id: candidate.nodeId,
369
+ legal_v4_name: candidate.legalV4Name,
370
+ })),
371
+ notifications: inventory.notifications.map((candidate) => ({
372
+ node_id: candidate.nodeId,
373
+ name: candidate.name,
374
+ admin_only: candidate.adminOnly,
375
+ group: candidate.group,
376
+ })),
377
+ unmodelled: inventory.unmodelled.map((entry) => ({
378
+ type: entry.type,
379
+ count: entry.count,
380
+ })),
381
+ findings: inventory.findings.map((item) => ({
382
+ kind: item.kind,
383
+ severity: item.severity,
384
+ detail: item.detail,
385
+ ...(item.nodeId === undefined || item.nodeId === '' ? {} : { node_id: item.nodeId }),
386
+ })),
387
+ };
388
+ }
389
+ //# sourceMappingURL=discovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discovery.js","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAC;AAE9C,uEAAuE;AACvE,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC,CAAC;AAE1E,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC;IAC/B,aAAa;IACb,cAAc;IACd,iBAAiB;IACjB,aAAa;IACb,cAAc;IACd,aAAa;IACb,cAAc;IACd,eAAe;IACf,kBAAkB;CACnB,CAAC,CAAC;AAwFH,SAAS,KAAK,CAAC,IAAa,EAAE,GAAW;IACvC,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1D,CAAC;AAED,SAAS,IAAI,CAAC,IAAa,EAAE,GAAW;IACtC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,GAAG,CA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,IAAI,IAAI,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;SACrF,CAAC,CAAC;KACJ,CAAC;AACJ,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Deterministic CLI outcomes.
3
+ *
4
+ * An agent drives this tool without reading prose, so every failure maps to
5
+ * exactly one stable exit code and one stable machine-readable kind. New kinds
6
+ * may be added; existing codes never change meaning.
7
+ */
8
+ export declare const EXIT_CODE: {
9
+ readonly success: 0;
10
+ readonly usage: 1;
11
+ readonly project: 2;
12
+ readonly artifact: 3;
13
+ readonly authorization: 4;
14
+ readonly contract: 5;
15
+ readonly conflict: 6;
16
+ readonly unknown_outcome: 7;
17
+ };
18
+ export type CliFailureKind = Exclude<keyof typeof EXIT_CODE, 'success'>;
19
+ /**
20
+ * `unknown_outcome` is reserved for a request whose effect on the control plane
21
+ * is undetermined. The caller must reconcile with a read before acting again;
22
+ * it must never blindly retry with a new capability.
23
+ */
24
+ export declare class CliError extends Error {
25
+ readonly kind: CliFailureKind;
26
+ readonly exitCode: number;
27
+ readonly remedy: string | undefined;
28
+ constructor(kind: CliFailureKind, message: string, remedy?: string);
29
+ }
30
+ export declare function usageError(message: string, remedy?: string): CliError;
31
+ export declare function projectError(message: string, remedy?: string): CliError;
32
+ export declare function artifactError(message: string, remedy?: string): CliError;
33
+ export declare function authorizationError(message: string, remedy?: string): CliError;
34
+ export declare function contractError(message: string, remedy?: string): CliError;
35
+ export declare function conflictError(message: string, remedy?: string): CliError;
36
+ export declare function unknownOutcomeError(message: string, remedy: string): CliError;
37
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,SAAS;aACpB,OAAO,EAAE,CAAC;aACV,KAAK,EAAE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2
+ * Deterministic CLI outcomes.
3
+ *
4
+ * An agent drives this tool without reading prose, so every failure maps to
5
+ * exactly one stable exit code and one stable machine-readable kind. New kinds
6
+ * may be added; existing codes never change meaning.
7
+ */
8
+ export const EXIT_CODE = {
9
+ success: 0,
10
+ usage: 1,
11
+ project: 2,
12
+ artifact: 3,
13
+ authorization: 4,
14
+ contract: 5,
15
+ conflict: 6,
16
+ unknown_outcome: 7,
17
+ };
18
+ /**
19
+ * `unknown_outcome` is reserved for a request whose effect on the control plane
20
+ * is undetermined. The caller must reconcile with a read before acting again;
21
+ * it must never blindly retry with a new capability.
22
+ */
23
+ export class CliError extends Error {
24
+ kind;
25
+ exitCode;
26
+ remedy;
27
+ constructor(kind, message, remedy) {
28
+ super(message);
29
+ this.name = 'MiakappCliError';
30
+ this.kind = kind;
31
+ this.exitCode = EXIT_CODE[kind];
32
+ this.remedy = remedy;
33
+ }
34
+ }
35
+ export function usageError(message, remedy) {
36
+ return new CliError('usage', message, remedy);
37
+ }
38
+ export function projectError(message, remedy) {
39
+ return new CliError('project', message, remedy);
40
+ }
41
+ export function artifactError(message, remedy) {
42
+ return new CliError('artifact', message, remedy);
43
+ }
44
+ export function authorizationError(message, remedy) {
45
+ return new CliError('authorization', message, remedy);
46
+ }
47
+ export function contractError(message, remedy) {
48
+ return new CliError('contract', message, remedy);
49
+ }
50
+ export function conflictError(message, remedy) {
51
+ return new CliError('conflict', message, remedy);
52
+ }
53
+ export function unknownOutcomeError(message, remedy) {
54
+ return new CliError('unknown_outcome', message, remedy);
55
+ }
56
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IACV,QAAQ,EAAE,CAAC;IACX,aAAa,EAAE,CAA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AU,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,OAAe,EAAE,MAAc;IACjE,OAAO,IAAI,QAAQ,CAAC,iBAAiB,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAC1D,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { type JsonValue } from './json.js';
2
+ /** RFC 0004 §4.2: one response body is at most 64 KiB outside the stated exceptions. */
3
+ export declare const MAXIMUM_RESPONSE_BYTES = 65536;
4
+ /** RFC 0004 §4.2: one request body is at most 16 KiB. */
5
+ export declare const MAXIMUM_REQUEST_BYTES = 16384;
6
+ export type FetchLike = (input: string, init: RequestInit) => Promise<Response>;
7
+ export interface HttpsEndpoint {
8
+ readonly url: string;
9
+ readonly pathname: string;
10
+ }
11
+ /**
12
+ * Every control-plane URL is an exact absolute HTTPS identifier with no user
13
+ * information, query or fragment. A value that does not round-trip through
14
+ * `URL` is rejected rather than normalized.
15
+ *
16
+ * One deviation from byte-for-byte equality is required rather than convenient.
17
+ * RFC 0004 §3 states that `issuer` has no trailing slash, and its own example
18
+ * issuer is the bare origin `https://control.example.test`. `URL` serializes
19
+ * that back with a trailing slash, so demanding exact equality would reject
20
+ * every origin-only issuer the RFC describes and force an arbitrary path
21
+ * segment onto every deployment. An empty path is therefore accepted in either
22
+ * spelling; nothing else is relaxed, so a stray query, a default port or a
23
+ * non-normalized path is still refused.
24
+ */
25
+ export declare function canonicalHttpsUrl(value: unknown, label: string): string;
26
+ export declare function cancelBody(response: Response | undefined): void;
27
+ export declare function readBoundedBody(response: Response, maximumBytes: number): Promise<Uint8Array>;
28
+ export declare function readJsonBody(response: Response): Promise<JsonValue>;
29
+ export declare function requestBody(value: unknown): string;
30
+ /**
31
+ * A control-plane request never follows a redirect, never carries a cookie and
32
+ * never negotiates compression for an exact identifier.
33
+ */
34
+ export declare function jsonRequestInit(method: 'GET' | 'POST', token: string, body: string | undefined, signal: AbortSignal): RequestInit;
35
+ //# sourceMappingURL=http.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/internal/http.ts"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtD,wFAAwF;AACxF,eAAO,MAAM,sBAAsB,QAAS,CAAC;AAE7C,yDAAyD;AACzD,eAAO,MAAM,qBAAqB,QAAS,CAAC;AAE5C,MAAM,MAAM,SAAS,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEhF,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAsBvE;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,GAAG,IAAI,CAO/D;AAED,wBAAsB,eAAe,CACnC,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,UAAU,CAAC,CAmCrB;AAED,wBAAsB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,CAIzE;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAMlD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,KAAK,GAAG,MAAM,EACtB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,MAAM,EAAE,WAAW,GAClB,WAAW,CAab"}