@stim-cli/server 0.0.0 → 1.10.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.
@@ -0,0 +1,187 @@
1
+ import { NdjsonRecord, StatusPayload } from "@stim-cli/core/state";
2
+ //#region src/protocol.d.ts
3
+ declare const PROTOCOL_VERSION = 1;
4
+ declare const PROTOCOL_SCHEMA_FILE = "protocol.schema.json";
5
+ declare const CAPABILITIES: readonly ["read"];
6
+ type Capability = (typeof CAPABILITIES)[number];
7
+ declare const METHODS: readonly ["hello", "status.subscribe", "logs.query", "logs.subscribe", "stats.get", "settings.get", "frames.subscribe", "unsubscribe"];
8
+ type Method = (typeof METHODS)[number];
9
+ /**
10
+ * `unauthorized`, `pairing-expired` and `protocol-unsupported` refuse the client until it pairs again or
11
+ * updates; clients retry the others.
12
+ */
13
+ declare const ERROR_CODES: readonly ["unauthorized", "pairing-expired", "protocol-unsupported", "identity-unavailable", "bad-request", "unknown-method", "already-authenticated", "unknown-subscription", "unknown-workspace", "limit-exceeded", "slow-client", "status-failed", "logs-failed", "stim-failed", "frames-failed"];
14
+ type ErrorCode = (typeof ERROR_CODES)[number];
15
+ type RequestId = number | string;
16
+ /** Spends a single-use pairing token; the result carries the new device token. */
17
+ interface PairingAuth {
18
+ pairingToken: string;
19
+ deviceName: string;
20
+ }
21
+ /** Presents the device token a previous pairing returned. */
22
+ interface DeviceAuth {
23
+ deviceToken: string;
24
+ }
25
+ interface HelloParams {
26
+ protocol: number;
27
+ client: {
28
+ name: string;
29
+ version: string;
30
+ };
31
+ auth: PairingAuth | DeviceAuth;
32
+ }
33
+ interface HelloResult {
34
+ protocol: number;
35
+ /** The Mac's name, this package's version, and the version of the `stim` it runs. */
36
+ server: {
37
+ name: string;
38
+ version: string;
39
+ stim: string;
40
+ };
41
+ capabilities: Capability[];
42
+ /** The paired device this connection authenticated as, as `stim-server devices` lists it. */
43
+ device: {
44
+ id: string;
45
+ name: string;
46
+ };
47
+ /** Present only when the hello spent a pairing token. The server keeps only its hash. */
48
+ deviceToken?: string;
49
+ }
50
+ interface SubscribeResult {
51
+ subscription: string;
52
+ }
53
+ interface UnsubscribeParams {
54
+ subscription: string;
55
+ }
56
+ declare const LOG_SOURCES: readonly ["metro", "client", "device", "build"];
57
+ type LogSource = (typeof LOG_SOURCES)[number];
58
+ declare const LOG_LEVELS: readonly ["debug", "info", "warn", "error", "fatal"];
59
+ type LogLevel = (typeof LOG_LEVELS)[number];
60
+ declare const MAX_LOG_TAIL = 5e3;
61
+ /**
62
+ * The Stim Desktop log viewer's filters, passed to `stim logs`. `workspace` is an environment `path` from a
63
+ * status payload. Without `sources`, `errors` keeps the CLI's default error scope. `tail` defaults to
64
+ * {@link MAX_LOG_TAIL}, which is also its maximum.
65
+ */
66
+ interface LogFilter {
67
+ workspace: string;
68
+ sources?: LogSource[];
69
+ level?: LogLevel;
70
+ slot?: string;
71
+ grep?: string;
72
+ errors?: boolean;
73
+ tail?: number;
74
+ }
75
+ /** One record as `stim logs --json` prints it. */
76
+ type LogRecord = NdjsonRecord;
77
+ interface LogsQueryResult {
78
+ records: LogRecord[];
79
+ }
80
+ /** Without `workspace`, stats and settings cover the machine only. */
81
+ interface WorkspaceParams {
82
+ workspace?: string;
83
+ }
84
+ /** `stim stats --json`. */
85
+ type StatsResult = Record<string, unknown>;
86
+ /** `stim settings --json`; the CLI masks sensitive values. */
87
+ type SettingsResult = Record<string, unknown>;
88
+ type Platform = "ios" | "android";
89
+ /**
90
+ * A device `stim status` lists as owned by `workspace`, in `slot` (`default` when absent). Frames come only
91
+ * from a booted simulator or a running emulator Stim created.
92
+ */
93
+ interface FrameTarget {
94
+ workspace: string;
95
+ platform: Platform;
96
+ slot?: string;
97
+ }
98
+ interface Methods {
99
+ hello: {
100
+ params: HelloParams;
101
+ result: HelloResult;
102
+ };
103
+ "status.subscribe": {
104
+ params?: Record<string, never>;
105
+ result: SubscribeResult;
106
+ };
107
+ "logs.query": {
108
+ params: LogFilter;
109
+ result: LogsQueryResult;
110
+ };
111
+ "logs.subscribe": {
112
+ params: LogFilter;
113
+ result: SubscribeResult;
114
+ };
115
+ "stats.get": {
116
+ params?: WorkspaceParams;
117
+ result: StatsResult;
118
+ };
119
+ "settings.get": {
120
+ params?: WorkspaceParams;
121
+ result: SettingsResult;
122
+ };
123
+ "frames.subscribe": {
124
+ params: FrameTarget;
125
+ result: SubscribeResult;
126
+ };
127
+ unsubscribe: {
128
+ params: UnsubscribeParams;
129
+ result: Record<string, never>;
130
+ };
131
+ }
132
+ type ClientRequest = { [M in Method]: {
133
+ id: RequestId;
134
+ method: M;
135
+ } & Pick<Methods[M], "params">; }[Method];
136
+ interface ProtocolError {
137
+ code: ErrorCode;
138
+ message: string;
139
+ }
140
+ type ServerResponse = {
141
+ id: RequestId;
142
+ result: Methods[Method]["result"];
143
+ } | {
144
+ id: RequestId | null;
145
+ error: ProtocolError;
146
+ };
147
+ /** A full status payload, as `stim status --watch --json` prints it. */
148
+ interface StatusEvent {
149
+ event: "status";
150
+ subscription: string;
151
+ payload: StatusPayload;
152
+ }
153
+ /**
154
+ * Records for a `logs.subscribe` subscription: first the last `tail` matching records, then new ones as
155
+ * they arrive.
156
+ */
157
+ interface LogsEvent {
158
+ event: "logs";
159
+ subscription: string;
160
+ records: LogRecord[];
161
+ }
162
+ /** A subscription ended because its source failed or the client fell behind; the client may resubscribe. */
163
+ interface ErrorEvent {
164
+ event: "error";
165
+ subscription: string;
166
+ error: ProtocolError;
167
+ }
168
+ /** A screenshot of the device, sent when the screen changed, at most 5 times a second. */
169
+ interface FrameEvent {
170
+ event: "frame";
171
+ subscription: string;
172
+ platform: Platform;
173
+ slot: string;
174
+ mime: "image/jpeg";
175
+ width: number;
176
+ height: number;
177
+ capturedAt: string;
178
+ /** Base64-encoded image bytes. */
179
+ data: string;
180
+ }
181
+ type ServerEvent = StatusEvent | LogsEvent | FrameEvent | ErrorEvent;
182
+ type ServerMessage = ServerResponse | ServerEvent;
183
+ type JsonSchema = Record<string, unknown>;
184
+ /** The JSON Schema of every message on the wire, written to `dist/protocol.schema.json` at build time. */
185
+ declare function protocolJsonSchema(): JsonSchema;
186
+ //#endregion
187
+ export { CAPABILITIES, Capability, ClientRequest, DeviceAuth, ERROR_CODES, ErrorCode, ErrorEvent, FrameEvent, FrameTarget, HelloParams, HelloResult, LOG_LEVELS, LOG_SOURCES, LogFilter, LogLevel, LogRecord, LogSource, LogsEvent, LogsQueryResult, MAX_LOG_TAIL, METHODS, Method, Methods, PROTOCOL_SCHEMA_FILE, PROTOCOL_VERSION, PairingAuth, Platform, ProtocolError, RequestId, ServerEvent, ServerMessage, ServerResponse, SettingsResult, StatsResult, StatusEvent, SubscribeResult, UnsubscribeParams, WorkspaceParams, protocolJsonSchema };
@@ -0,0 +1,2 @@
1
+ import { a as MAX_LOG_TAIL, c as PROTOCOL_VERSION, i as LOG_SOURCES, l as protocolJsonSchema, n as ERROR_CODES, o as METHODS, r as LOG_LEVELS, s as PROTOCOL_SCHEMA_FILE, t as CAPABILITIES } from "./protocol-dn2_TUeH.mjs";
2
+ export { CAPABILITIES, ERROR_CODES, LOG_LEVELS, LOG_SOURCES, MAX_LOG_TAIL, METHODS, PROTOCOL_SCHEMA_FILE, PROTOCOL_VERSION, protocolJsonSchema };