@swipt/cli 0.1.0-nightly.78 → 0.1.0-nightly.80
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/availability.d.ts +5 -0
- package/dist/availability.js +349 -0
- package/dist/availability.js.map +1 -0
- package/dist/client.d.ts +25 -0
- package/dist/client.js +248 -0
- package/dist/client.js.map +1 -0
- package/dist/connection.d.ts +24 -0
- package/dist/connection.js +293 -0
- package/dist/connection.js.map +1 -0
- package/dist/coredevice.d.ts +22 -0
- package/dist/coredevice.js +329 -0
- package/dist/coredevice.js.map +1 -0
- package/dist/device.d.ts +130 -0
- package/dist/device.js +539 -0
- package/dist/device.js.map +1 -0
- package/dist/i18n.d.ts +2 -0
- package/dist/i18n.js +57 -0
- package/dist/i18n.js.map +1 -0
- package/dist/ignore.d.ts +8 -0
- package/dist/ignore.js +112 -0
- package/dist/ignore.js.map +1 -0
- package/dist/metro.d.ts +10 -0
- package/dist/metro.js +349 -0
- package/dist/metro.js.map +1 -0
- package/dist/output.d.ts +20 -0
- package/dist/output.js +116 -0
- package/dist/output.js.map +1 -0
- package/dist/project.d.ts +18 -0
- package/dist/project.js +696 -0
- package/dist/project.js.map +1 -0
- package/dist/proto/common_pb.js +14 -0
- package/dist/proto/common_pb.js.map +1 -0
- package/dist/proto/logs_pb.js +15 -0
- package/dist/proto/logs_pb.js.map +1 -0
- package/dist/proto/repl_pb.js +15 -0
- package/dist/proto/repl_pb.js.map +1 -0
- package/dist/proto/swiplets_pb.js +20 -0
- package/dist/proto/swiplets_pb.js.map +1 -0
- package/dist/proto/system_pb.js +15 -0
- package/dist/proto/system_pb.js.map +1 -0
- package/dist/sideload.d.ts +17 -0
- package/dist/sideload.js +1098 -0
- package/dist/sideload.js.map +1 -0
- package/dist/swipt.d.ts +1 -0
- package/dist/swipt.js +631 -0
- package/dist/swipt.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +15 -0
- package/dist/version.js.map +1 -0
- package/package.json +21 -7
- package/availability.mjs +0 -642
- package/client.mjs +0 -375
- package/connection.mjs +0 -450
- package/coredevice.mjs +0 -464
- package/device.mjs +0 -837
- package/i18n.mjs +0 -71
- package/ignore.mjs +0 -149
- package/metro.mjs +0 -432
- package/output.mjs +0 -177
- package/project.mjs +0 -1013
- package/proto/common_pb.js +0 -98
- package/proto/logs_pb.js +0 -34
- package/proto/repl_pb.js +0 -55
- package/proto/swiplets_pb.js +0 -179
- package/proto/system_pb.js +0 -27
- package/sideload.mjs +0 -1696
- package/swipt.mjs +0 -726
- package/version.mjs +0 -16
package/dist/client.js
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { LogService } from "./proto/logs_pb.js";
|
|
2
|
+
import { REPLService } from "./proto/repl_pb.js";
|
|
3
|
+
import { SwipletService } from "./proto/swiplets_pb.js";
|
|
4
|
+
import { SystemService } from "./proto/system_pb.js";
|
|
5
|
+
import dns from "node:dns";
|
|
6
|
+
import { create, fromBinary, toBinary } from "@bufbuild/protobuf";
|
|
7
|
+
// src/client.ts
|
|
8
|
+
const largestMessage = 128 << 20;
|
|
9
|
+
const contentType = "application/grpc-web+proto";
|
|
10
|
+
const webSocketSubprotocol = "grpc-websockets";
|
|
11
|
+
dns.setDefaultResultOrder("ipv4first");
|
|
12
|
+
const Code = {
|
|
13
|
+
Canceled: 1,
|
|
14
|
+
Unknown: 2,
|
|
15
|
+
DeadlineExceeded: 4,
|
|
16
|
+
NotFound: 5,
|
|
17
|
+
Unimplemented: 12,
|
|
18
|
+
Internal: 13,
|
|
19
|
+
Unavailable: 14,
|
|
20
|
+
Unauthenticated: 16
|
|
21
|
+
};
|
|
22
|
+
var UsageError = class extends Error {};
|
|
23
|
+
var RpcError = class extends Error {
|
|
24
|
+
constructor(code, message) {
|
|
25
|
+
super(message);
|
|
26
|
+
this.code = code;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const httpStatusCodes = {
|
|
30
|
+
400: Code.Internal,
|
|
31
|
+
401: Code.Unauthenticated,
|
|
32
|
+
403: Code.Unauthenticated,
|
|
33
|
+
404: Code.Unimplemented,
|
|
34
|
+
429: Code.Unavailable,
|
|
35
|
+
502: Code.Unavailable,
|
|
36
|
+
503: Code.Unavailable,
|
|
37
|
+
504: Code.Unavailable
|
|
38
|
+
};
|
|
39
|
+
function statusMessage(text) {
|
|
40
|
+
if (text === void 0 || text === null) return "";
|
|
41
|
+
try {
|
|
42
|
+
return decodeURIComponent(text);
|
|
43
|
+
} catch {
|
|
44
|
+
return text;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const causeText = (cause) => cause?.errors?.length > 0 ? cause.errors.map(causeText).join("; ") : cause?.message || cause?.code;
|
|
48
|
+
const transportError = (error) => {
|
|
49
|
+
if (error instanceof RpcError) return error;
|
|
50
|
+
if (error?.name === "AbortError") return new RpcError(Code.Canceled, "the call was canceled");
|
|
51
|
+
return new RpcError(Code.Unavailable, causeText(error?.cause) || error?.message || String(error));
|
|
52
|
+
};
|
|
53
|
+
function frame(schema, init) {
|
|
54
|
+
const body = toBinary(schema, create(schema, init));
|
|
55
|
+
const out = Buffer.allocUnsafe(5 + body.length);
|
|
56
|
+
out[0] = 0;
|
|
57
|
+
out.writeUInt32BE(body.length, 1);
|
|
58
|
+
out.set(body, 5);
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
function parseMetadata(body) {
|
|
62
|
+
const headers = {};
|
|
63
|
+
for (const line of Buffer.from(body).toString().split("\r\n")) {
|
|
64
|
+
const separator = line.indexOf(":");
|
|
65
|
+
if (separator > 0) headers[line.slice(0, separator).trim().toLowerCase()] = line.slice(separator + 1).trim();
|
|
66
|
+
}
|
|
67
|
+
return headers;
|
|
68
|
+
}
|
|
69
|
+
var FrameReader = class {
|
|
70
|
+
pending = Buffer.alloc(0);
|
|
71
|
+
constructor(schema) {
|
|
72
|
+
this.schema = schema;
|
|
73
|
+
}
|
|
74
|
+
push(chunk) {
|
|
75
|
+
this.pending = this.pending.length === 0 ? Buffer.from(chunk) : Buffer.concat([this.pending, Buffer.from(chunk)]);
|
|
76
|
+
const frames = [];
|
|
77
|
+
while (this.pending.length >= 5) {
|
|
78
|
+
const length = this.pending.readUInt32BE(1);
|
|
79
|
+
if (length > largestMessage) throw new RpcError(Code.Internal, `the server sent a message of ${length} bytes`);
|
|
80
|
+
if (this.pending.length < 5 + length) break;
|
|
81
|
+
const body = this.pending.subarray(5, 5 + length);
|
|
82
|
+
frames.push((this.pending[0] & 128) !== 0 ? { trailers: parseMetadata(body) } : { message: fromBinary(this.schema, body) });
|
|
83
|
+
this.pending = this.pending.subarray(5 + length);
|
|
84
|
+
}
|
|
85
|
+
return frames;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
function checkStatus(headers) {
|
|
89
|
+
const status = headers["grpc-status"];
|
|
90
|
+
if (status === void 0 || status === null) return false;
|
|
91
|
+
const code = Number(status);
|
|
92
|
+
if (code !== 0) throw new RpcError(code, statusMessage(headers["grpc-message"]));
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
function requestHeaders(connection) {
|
|
96
|
+
const headers = {
|
|
97
|
+
"content-type": contentType,
|
|
98
|
+
"x-grpc-web": "1"
|
|
99
|
+
};
|
|
100
|
+
if (connection.token !== "") headers.authorization = `Bearer ${connection.token}`;
|
|
101
|
+
return headers;
|
|
102
|
+
}
|
|
103
|
+
async function* invokeHTTP(connection, method, input, { signal }) {
|
|
104
|
+
let response;
|
|
105
|
+
try {
|
|
106
|
+
response = await fetch(`${connection.base}/${method.parent.typeName}/${method.name}`, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
headers: requestHeaders(connection),
|
|
109
|
+
body: frame(method.input, input),
|
|
110
|
+
signal
|
|
111
|
+
});
|
|
112
|
+
} catch (error) {
|
|
113
|
+
throw transportError(error);
|
|
114
|
+
}
|
|
115
|
+
const headers = Object.fromEntries(response.headers);
|
|
116
|
+
if (response.status !== 200) {
|
|
117
|
+
await response.body?.cancel();
|
|
118
|
+
throw new RpcError(httpStatusCodes[response.status] ?? Code.Unknown, `HTTP ${response.status}`);
|
|
119
|
+
}
|
|
120
|
+
if (checkStatus(headers)) {
|
|
121
|
+
await response.body?.cancel();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const reader = new FrameReader(method.output);
|
|
125
|
+
let ended = false;
|
|
126
|
+
try {
|
|
127
|
+
for await (const chunk of response.body) for (const found of reader.push(chunk)) if (found.trailers) {
|
|
128
|
+
checkStatus(found.trailers);
|
|
129
|
+
ended = true;
|
|
130
|
+
} else if (!ended) yield found.message;
|
|
131
|
+
} catch (error) {
|
|
132
|
+
throw transportError(error);
|
|
133
|
+
}
|
|
134
|
+
if (!ended) throw new RpcError(Code.Unavailable, "the response ended without a status");
|
|
135
|
+
}
|
|
136
|
+
async function* invokeWebSocket(connection, method, input, { signal }) {
|
|
137
|
+
const socket = new WebSocket(`${connection.webSocketBase}/${method.parent.typeName}/${method.name}`, [webSocketSubprotocol]);
|
|
138
|
+
socket.binaryType = "arraybuffer";
|
|
139
|
+
const reader = new FrameReader(method.output);
|
|
140
|
+
const messages = [];
|
|
141
|
+
let failure;
|
|
142
|
+
let closed = false;
|
|
143
|
+
let headersSeen = false;
|
|
144
|
+
let wake = () => {};
|
|
145
|
+
const notify = () => {
|
|
146
|
+
const current = wake;
|
|
147
|
+
wake = () => {};
|
|
148
|
+
current();
|
|
149
|
+
};
|
|
150
|
+
const fail = (error) => {
|
|
151
|
+
failure ??= error;
|
|
152
|
+
socket.close();
|
|
153
|
+
notify();
|
|
154
|
+
};
|
|
155
|
+
const abort = () => fail(new RpcError(Code.Canceled, "the call was canceled"));
|
|
156
|
+
const opened = new Promise((resolve, reject) => {
|
|
157
|
+
socket.addEventListener("open", resolve, { once: true });
|
|
158
|
+
socket.addEventListener("error", () => reject(new RpcError(Code.Unavailable, `cannot connect to ${connection.webSocketBase}`)), { once: true });
|
|
159
|
+
});
|
|
160
|
+
socket.addEventListener("message", (event) => {
|
|
161
|
+
try {
|
|
162
|
+
for (const found of reader.push(new Uint8Array(event.data))) if (found.message) messages.push(found.message);
|
|
163
|
+
else if (headersSeen || "grpc-status" in found.trailers) {
|
|
164
|
+
checkStatus(found.trailers);
|
|
165
|
+
closed = true;
|
|
166
|
+
socket.close();
|
|
167
|
+
} else headersSeen = true;
|
|
168
|
+
} catch (error) {
|
|
169
|
+
fail(error);
|
|
170
|
+
}
|
|
171
|
+
notify();
|
|
172
|
+
});
|
|
173
|
+
socket.addEventListener("close", (event) => {
|
|
174
|
+
if (!closed) failure ??= new RpcError(Code.Unavailable, event.reason || "the connection closed before the response");
|
|
175
|
+
closed = true;
|
|
176
|
+
notify();
|
|
177
|
+
});
|
|
178
|
+
socket.addEventListener("error", () => {
|
|
179
|
+
failure ??= new RpcError(Code.Unavailable, `cannot connect to ${connection.webSocketBase}`);
|
|
180
|
+
});
|
|
181
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
182
|
+
try {
|
|
183
|
+
await opened;
|
|
184
|
+
const headers = requestHeaders(connection);
|
|
185
|
+
socket.send(Buffer.from(`${Object.entries(headers).map(([key, value]) => `${key}: ${value}\r\n`).join("")}`));
|
|
186
|
+
const sender = (async () => {
|
|
187
|
+
try {
|
|
188
|
+
const body = method.methodKind === "client_streaming" ? input : [input];
|
|
189
|
+
for await (const message of body) {
|
|
190
|
+
if (closed) return;
|
|
191
|
+
socket.send(Buffer.concat([Buffer.from([0]), frame(method.input, message)]));
|
|
192
|
+
}
|
|
193
|
+
if (!closed) socket.send(Buffer.from([1]));
|
|
194
|
+
} catch (error) {
|
|
195
|
+
fail(transportError(error));
|
|
196
|
+
}
|
|
197
|
+
})();
|
|
198
|
+
while (true) {
|
|
199
|
+
if (messages.length > 0) {
|
|
200
|
+
yield messages.shift();
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
if (closed) break;
|
|
204
|
+
await new Promise((resolve) => {
|
|
205
|
+
wake = resolve;
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
await sender;
|
|
209
|
+
if (failure) throw failure;
|
|
210
|
+
} finally {
|
|
211
|
+
signal?.removeEventListener("abort", abort);
|
|
212
|
+
if (socket.readyState !== WebSocket.CLOSED) socket.close();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
async function single(iterable) {
|
|
216
|
+
let found;
|
|
217
|
+
for await (const message of iterable) found ??= message;
|
|
218
|
+
if (found === void 0) throw new RpcError(Code.Internal, "the server sent no response");
|
|
219
|
+
return found;
|
|
220
|
+
}
|
|
221
|
+
function bind(service, connection) {
|
|
222
|
+
const client = {};
|
|
223
|
+
for (const method of service.methods) {
|
|
224
|
+
const streamsInput = method.methodKind === "client_streaming" || method.methodKind === "bidi_streaming";
|
|
225
|
+
client[method.localName] = (input, options = {}) => {
|
|
226
|
+
const call = (streamsInput ? invokeWebSocket : invokeHTTP)(connection, method, input, { signal: options.signal });
|
|
227
|
+
return method.methodKind === "unary" || method.methodKind === "client_streaming" ? single(call) : call;
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
return client;
|
|
231
|
+
}
|
|
232
|
+
function open({ url, token }) {
|
|
233
|
+
const connection = {
|
|
234
|
+
token,
|
|
235
|
+
base: url,
|
|
236
|
+
webSocketBase: url.replace(/^http/, "ws")
|
|
237
|
+
};
|
|
238
|
+
return {
|
|
239
|
+
system: bind(SystemService, connection),
|
|
240
|
+
logs: bind(LogService, connection),
|
|
241
|
+
swiplets: bind(SwipletService, connection),
|
|
242
|
+
repl: bind(REPLService, connection)
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
const unauthenticated = (error) => error instanceof RpcError && error.code === Code.Unauthenticated;
|
|
246
|
+
export { Code, RpcError, UsageError, open, unauthenticated };
|
|
247
|
+
|
|
248
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../src/client.ts"],"sourcesContent":["import dns from \"node:dns\";\n\nimport { create, fromBinary, toBinary } from \"@bufbuild/protobuf\";\n\nimport { LogService } from \"./proto/logs_pb\";\nimport { REPLService } from \"./proto/repl_pb\";\nimport { SwipletService } from \"./proto/swiplets_pb\";\nimport { SystemService } from \"./proto/system_pb\";\n\nconst largestMessage = 128 << 20;\nconst contentType = \"application/grpc-web+proto\";\nconst webSocketSubprotocol = \"grpc-websockets\";\n\ndns.setDefaultResultOrder(\"ipv4first\");\n\nexport const Code = {\n Canceled: 1,\n Unknown: 2,\n DeadlineExceeded: 4,\n NotFound: 5,\n Unimplemented: 12,\n Internal: 13,\n Unavailable: 14,\n Unauthenticated: 16,\n};\n\nexport class UsageError extends Error {}\n\nexport class RpcError extends Error {\n declare code: number;\n\n constructor(code: number, message?: string) {\n super(message);\n this.code = code;\n }\n}\n\nconst httpStatusCodes = {\n 400: Code.Internal,\n 401: Code.Unauthenticated,\n 403: Code.Unauthenticated,\n 404: Code.Unimplemented,\n 429: Code.Unavailable,\n 502: Code.Unavailable,\n 503: Code.Unavailable,\n 504: Code.Unavailable,\n};\n\nfunction statusMessage(text) {\n if (text === undefined || text === null) {\n return \"\";\n }\n try {\n return decodeURIComponent(text);\n } catch {\n return text;\n }\n}\n\nconst causeText = (cause) =>\n cause?.errors?.length > 0\n ? cause.errors.map(causeText).join(\"; \")\n : cause?.message || cause?.code;\n\nconst transportError = (error) => {\n if (error instanceof RpcError) {\n return error;\n }\n if (error?.name === \"AbortError\") {\n return new RpcError(Code.Canceled, \"the call was canceled\");\n }\n return new RpcError(\n Code.Unavailable,\n causeText(error?.cause) || error?.message || String(error),\n );\n};\n\nfunction frame(schema, init) {\n const body = toBinary(schema, create(schema, init));\n const out = Buffer.allocUnsafe(5 + body.length);\n out[0] = 0;\n out.writeUInt32BE(body.length, 1);\n out.set(body, 5);\n return out;\n}\n\nfunction parseMetadata(body) {\n const headers = {};\n for (const line of Buffer.from(body).toString().split(\"\\r\\n\")) {\n const separator = line.indexOf(\":\");\n if (separator > 0) {\n headers[line.slice(0, separator).trim().toLowerCase()] = line\n .slice(separator + 1)\n .trim();\n }\n }\n return headers;\n}\n\nclass FrameReader {\n declare schema: any;\n pending = Buffer.alloc(0);\n\n constructor(schema) {\n this.schema = schema;\n }\n\n push(chunk) {\n this.pending =\n this.pending.length === 0\n ? Buffer.from(chunk)\n : Buffer.concat([this.pending, Buffer.from(chunk)]);\n const frames = [];\n while (this.pending.length >= 5) {\n const length = this.pending.readUInt32BE(1);\n if (length > largestMessage) {\n throw new RpcError(\n Code.Internal,\n `the server sent a message of ${length} bytes`,\n );\n }\n if (this.pending.length < 5 + length) {\n break;\n }\n const body = this.pending.subarray(5, 5 + length);\n frames.push(\n (this.pending[0] & 0x80) !== 0\n ? { trailers: parseMetadata(body) }\n : { message: fromBinary(this.schema, body) },\n );\n this.pending = this.pending.subarray(5 + length);\n }\n return frames;\n }\n}\n\nfunction checkStatus(headers) {\n const status = headers[\"grpc-status\"];\n if (status === undefined || status === null) {\n return false;\n }\n const code = Number(status);\n if (code !== 0) {\n throw new RpcError(code, statusMessage(headers[\"grpc-message\"]));\n }\n return true;\n}\n\nfunction requestHeaders(connection) {\n const headers: Record<string, string> = {\n \"content-type\": contentType,\n \"x-grpc-web\": \"1\",\n };\n if (connection.token !== \"\") {\n headers.authorization = `Bearer ${connection.token}`;\n }\n return headers;\n}\n\nasync function* invokeHTTP(connection, method, input, { signal }) {\n let response;\n try {\n response = await fetch(\n `${connection.base}/${method.parent.typeName}/${method.name}`,\n {\n method: \"POST\",\n headers: requestHeaders(connection),\n body: frame(method.input, input),\n signal,\n },\n );\n } catch (error) {\n throw transportError(error);\n }\n const headers = Object.fromEntries(response.headers);\n if (response.status !== 200) {\n await response.body?.cancel();\n throw new RpcError(\n httpStatusCodes[response.status] ?? Code.Unknown,\n `HTTP ${response.status}`,\n );\n }\n if (checkStatus(headers)) {\n await response.body?.cancel();\n return;\n }\n const reader = new FrameReader(method.output);\n let ended = false;\n try {\n for await (const chunk of response.body) {\n for (const found of reader.push(chunk)) {\n if (found.trailers) {\n checkStatus(found.trailers);\n ended = true;\n } else if (!ended) {\n yield found.message;\n }\n }\n }\n } catch (error) {\n throw transportError(error);\n }\n if (!ended) {\n throw new RpcError(Code.Unavailable, \"the response ended without a status\");\n }\n}\n\nasync function* invokeWebSocket(connection, method, input, { signal }) {\n const socket = new WebSocket(\n `${connection.webSocketBase}/${method.parent.typeName}/${method.name}`,\n [webSocketSubprotocol],\n );\n socket.binaryType = \"arraybuffer\";\n const reader = new FrameReader(method.output);\n const messages = [];\n let failure;\n let closed = false;\n let headersSeen = false;\n let wake: (value?: unknown) => void = () => {};\n const notify = () => {\n const current = wake;\n wake = () => {};\n current();\n };\n const fail = (error) => {\n failure ??= error;\n socket.close();\n notify();\n };\n const abort = () =>\n fail(new RpcError(Code.Canceled, \"the call was canceled\"));\n const opened = new Promise((resolve, reject) => {\n socket.addEventListener(\"open\", resolve, { once: true });\n socket.addEventListener(\n \"error\",\n () =>\n reject(\n new RpcError(\n Code.Unavailable,\n `cannot connect to ${connection.webSocketBase}`,\n ),\n ),\n { once: true },\n );\n });\n socket.addEventListener(\"message\", (event) => {\n try {\n for (const found of reader.push(new Uint8Array(event.data))) {\n if (found.message) {\n messages.push(found.message);\n } else if (headersSeen || \"grpc-status\" in found.trailers) {\n checkStatus(found.trailers);\n closed = true;\n socket.close();\n } else {\n headersSeen = true;\n }\n }\n } catch (error) {\n fail(error);\n }\n notify();\n });\n socket.addEventListener(\"close\", (event) => {\n if (!closed) {\n failure ??= new RpcError(\n Code.Unavailable,\n event.reason || \"the connection closed before the response\",\n );\n }\n closed = true;\n notify();\n });\n socket.addEventListener(\"error\", () => {\n failure ??= new RpcError(\n Code.Unavailable,\n `cannot connect to ${connection.webSocketBase}`,\n );\n });\n signal?.addEventListener(\"abort\", abort, { once: true });\n try {\n await opened;\n const headers = requestHeaders(connection);\n socket.send(\n Buffer.from(\n `${Object.entries(headers)\n .map(([key, value]) => `${key}: ${value}\\r\\n`)\n .join(\"\")}`,\n ),\n );\n const sender = (async () => {\n try {\n const body = method.methodKind === \"client_streaming\" ? input : [input];\n for await (const message of body) {\n if (closed) {\n return;\n }\n socket.send(\n Buffer.concat([Buffer.from([0]), frame(method.input, message)]),\n );\n }\n if (!closed) {\n socket.send(Buffer.from([1]));\n }\n } catch (error) {\n fail(transportError(error));\n }\n })();\n while (true) {\n if (messages.length > 0) {\n yield messages.shift();\n continue;\n }\n if (closed) {\n break;\n }\n await new Promise((resolve) => {\n wake = resolve;\n });\n }\n await sender;\n if (failure) {\n throw failure;\n }\n } finally {\n signal?.removeEventListener(\"abort\", abort);\n if (socket.readyState !== WebSocket.CLOSED) {\n socket.close();\n }\n }\n}\n\nasync function single(iterable) {\n let found;\n for await (const message of iterable) {\n found ??= message;\n }\n if (found === undefined) {\n throw new RpcError(Code.Internal, \"the server sent no response\");\n }\n return found;\n}\n\nfunction bind(service, connection): Record<string, any> {\n const client: Record<string, any> = {};\n for (const method of service.methods) {\n const streamsInput =\n method.methodKind === \"client_streaming\" ||\n method.methodKind === \"bidi_streaming\";\n client[method.localName] = (\n input,\n options: { signal?: AbortSignal } = {},\n ) => {\n const call = (streamsInput ? invokeWebSocket : invokeHTTP)(\n connection,\n method,\n input,\n { signal: options.signal },\n );\n return method.methodKind === \"unary\" ||\n method.methodKind === \"client_streaming\"\n ? single(call)\n : call;\n };\n }\n return client;\n}\n\nexport function open({ url, token }) {\n const connection = {\n token,\n base: url,\n webSocketBase: url.replace(/^http/, \"ws\"),\n };\n return {\n system: bind(SystemService, connection),\n logs: bind(LogService, connection),\n swiplets: bind(SwipletService, connection),\n repl: bind(REPLService, connection),\n };\n}\n\nexport const unauthenticated = (error) =>\n error instanceof RpcError && error.code === Code.Unauthenticated;\n"],"mappings":";;;;;;;AASA,MAAM,iBAAiB,OAAO;AAC9B,MAAM,cAAc;AACpB,MAAM,uBAAuB;AAE7B,IAAI,sBAAsB,WAAW;AAErC,MAAa,OAAO;CAClB,UAAU;CACV,SAAS;CACT,kBAAkB;CAClB,UAAU;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AC3B,OAAO,eAAe,qBACpB,OAAO,IAAI,IACX;EACN;CACF;CACA,OAAO;AACT;AAEA,SAAgB,KAAK,EAAE,KAAK,SAAS;CACnC,MAAM,aAAa;EACjB;EACA,MAAM;EACN,eAAe,IAAI,QAAQ,SAAS,IAAI;CAC1C;CACA,OAAO;EACL,QAAQ,KAAK,eAAe,UAAU;EACtC,MAAM,KAAK,YAAY,UAAU;EACjC,UAAU,KAAK,gBAAgB,UAAU;EACzC,MAAM,KAAK,aAAa,UAAU;CACpC;AACF;AAEA,MAAa,mBAAmB,UAC9B,iBAAiB,YAAY,MAAM,SAAS,KAAK"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare function label(name: any): any;
|
|
2
|
+
export declare const sameName: (a: any, b: any) => boolean;
|
|
3
|
+
export declare const withToken: (url: any) => any;
|
|
4
|
+
export declare function findPublished(name: any, signal: any): Promise<any>;
|
|
5
|
+
export declare function runningSwipt(name: any, signal: any): Promise<{
|
|
6
|
+
system: Record<string, any>;
|
|
7
|
+
logs: Record<string, any>;
|
|
8
|
+
swiplets: Record<string, any>;
|
|
9
|
+
repl: Record<string, any>;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function tryUnlock(client: any, signal: any): Promise<any>;
|
|
12
|
+
export declare function attach(context: any): Promise<{
|
|
13
|
+
system: Record<string, any>;
|
|
14
|
+
logs: Record<string, any>;
|
|
15
|
+
swiplets: Record<string, any>;
|
|
16
|
+
repl: Record<string, any>;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function list({ signal }: {
|
|
19
|
+
signal: any;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
export declare function add(context: any): Promise<void>;
|
|
22
|
+
export declare function remove({ args }: {
|
|
23
|
+
args: any;
|
|
24
|
+
}): void;
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { Code, RpcError, UsageError, open } from "./client.js";
|
|
2
|
+
import { tr } from "./i18n.js";
|
|
3
|
+
import { columns } from "./output.js";
|
|
4
|
+
import "./proto/common_pb.js";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import dgram from "node:dgram";
|
|
8
|
+
import { on } from "node:events";
|
|
9
|
+
import os from "node:os";
|
|
10
|
+
import { setTimeout } from "node:timers/promises";
|
|
11
|
+
import Bonjour from "bonjour-service";
|
|
12
|
+
import multicastDNS from "multicast-dns";
|
|
13
|
+
// src/connection.ts
|
|
14
|
+
const browseLimit = 1500;
|
|
15
|
+
const browseRequery = 300;
|
|
16
|
+
const publishLimit = 1e4;
|
|
17
|
+
const answerLimit = 5e3;
|
|
18
|
+
const storeFile = path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config"), "swipt", "devices.json");
|
|
19
|
+
function load() {
|
|
20
|
+
let text;
|
|
21
|
+
try {
|
|
22
|
+
text = fs.readFileSync(storeFile, "utf8");
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if (error.code === "ENOENT") return {};
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
return JSON.parse(text);
|
|
28
|
+
}
|
|
29
|
+
function save(devices) {
|
|
30
|
+
fs.mkdirSync(path.dirname(storeFile), {
|
|
31
|
+
recursive: true,
|
|
32
|
+
mode: 448
|
|
33
|
+
});
|
|
34
|
+
fs.writeFileSync(storeFile, `${JSON.stringify(devices, null, 2)}\n`, { mode: 384 });
|
|
35
|
+
}
|
|
36
|
+
function label(name) {
|
|
37
|
+
const slug = [...name.replaceAll(/['’]/g, "")].map((character) => /[A-Za-z0-9]/.test(character) ? character : "-").join("").split("-").filter((part) => part !== "").join("-");
|
|
38
|
+
return slug === "" ? name : slug;
|
|
39
|
+
}
|
|
40
|
+
const sameName = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
41
|
+
const storedName = (stored, name) => Object.keys(stored).find((it) => sameName(it, name));
|
|
42
|
+
function parseURL(text) {
|
|
43
|
+
let parsed;
|
|
44
|
+
try {
|
|
45
|
+
parsed = new URL(text.includes("://") ? text : `http://${text}`);
|
|
46
|
+
} catch {
|
|
47
|
+
throw new UsageError(tr("{text} is not a URL", { text }));
|
|
48
|
+
}
|
|
49
|
+
if (parsed.hostname === "" || parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new UsageError(tr("{text} is not an http or https URL", { text }));
|
|
50
|
+
let token;
|
|
51
|
+
try {
|
|
52
|
+
token = decodeURIComponent(parsed.username);
|
|
53
|
+
} catch {
|
|
54
|
+
token = parsed.username;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
url: `${parsed.protocol}//${parsed.host}${parsed.pathname.replace(/\/+$/, "")}`,
|
|
58
|
+
token
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
const withToken = (url) => url.replace("://", "://TOKEN@");
|
|
62
|
+
async function browse(signal, until, limit = browseLimit) {
|
|
63
|
+
const bonjour = new Bonjour({
|
|
64
|
+
socket: dgram.createSocket("udp4"),
|
|
65
|
+
bind: false
|
|
66
|
+
});
|
|
67
|
+
const found = /* @__PURE__ */ new Map();
|
|
68
|
+
const enough = new AbortController();
|
|
69
|
+
try {
|
|
70
|
+
const browser = bonjour.find({ type: "swipt" }, (service) => {
|
|
71
|
+
if (!service.host || found.has(service.name)) return;
|
|
72
|
+
const host = service.host.replace(/\.$/, "").toLowerCase();
|
|
73
|
+
found.set(service.name, {
|
|
74
|
+
name: label(service.name),
|
|
75
|
+
url: `http://${host.includes(":") ? `[${host}]` : host}:${service.port}`,
|
|
76
|
+
authenticates: service.txt?.auth === "1"
|
|
77
|
+
});
|
|
78
|
+
if (until?.([...found.values()])) enough.abort();
|
|
79
|
+
});
|
|
80
|
+
const requery = setInterval(() => browser.update(), browseRequery);
|
|
81
|
+
try {
|
|
82
|
+
await setTimeout(limit, void 0, { signal: AbortSignal.any([signal, enough.signal]) });
|
|
83
|
+
} catch (error) {
|
|
84
|
+
if (signal.aborted) throw error;
|
|
85
|
+
} finally {
|
|
86
|
+
clearInterval(requery);
|
|
87
|
+
}
|
|
88
|
+
browser.stop();
|
|
89
|
+
} finally {
|
|
90
|
+
bonjour.destroy();
|
|
91
|
+
}
|
|
92
|
+
return [...found.values()];
|
|
93
|
+
}
|
|
94
|
+
async function findPublished(name, signal) {
|
|
95
|
+
const wanted = label(name);
|
|
96
|
+
const matches = (service) => sameName(service.name, wanted);
|
|
97
|
+
return (await browse(signal, (services) => services.some(matches), publishLimit)).find(matches);
|
|
98
|
+
}
|
|
99
|
+
async function runningSwipt(name, signal) {
|
|
100
|
+
const wanted = label(name);
|
|
101
|
+
const stored = load();
|
|
102
|
+
await discover(signal, stored, (services) => services.some((it) => sameName(it.name, wanted)));
|
|
103
|
+
const known = storedName(stored, wanted);
|
|
104
|
+
if (known === void 0) return;
|
|
105
|
+
const client = open(parseURL(stored[known]));
|
|
106
|
+
try {
|
|
107
|
+
await client.system.getInfo({}, { signal: AbortSignal.any([signal, AbortSignal.timeout(answerLimit)]) });
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (signal.aborted || !(error instanceof RpcError)) throw error;
|
|
110
|
+
if (error.code === Code.Unauthenticated) console.error(tr("error: {message}", { message: error.message }));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
return client;
|
|
114
|
+
}
|
|
115
|
+
async function tryUnlock(client, signal) {
|
|
116
|
+
try {
|
|
117
|
+
for await (const response of client.repl.execute({
|
|
118
|
+
code: "await device.unlock()",
|
|
119
|
+
args: [],
|
|
120
|
+
program: false
|
|
121
|
+
}, { signal })) if (response.part.case === "error") return response.part.value.message;
|
|
122
|
+
} catch (error) {
|
|
123
|
+
if (signal.aborted || !(error instanceof RpcError)) throw error;
|
|
124
|
+
return error.message;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
async function discover(signal, stored, until) {
|
|
128
|
+
const found = await browse(signal, until);
|
|
129
|
+
let changed = false;
|
|
130
|
+
for (const it of found) {
|
|
131
|
+
if (it.authenticates) continue;
|
|
132
|
+
const name = storedName(stored, it.name);
|
|
133
|
+
if (name === void 0) {
|
|
134
|
+
stored[it.name] = it.url;
|
|
135
|
+
changed = true;
|
|
136
|
+
} else {
|
|
137
|
+
const current = parseURL(stored[name]);
|
|
138
|
+
if (current.token === "" && current.url !== it.url) {
|
|
139
|
+
stored[name] = it.url;
|
|
140
|
+
changed = true;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (changed) save(stored);
|
|
145
|
+
return found;
|
|
146
|
+
}
|
|
147
|
+
const requiresToken = (found) => tr("{device} requires a token: swipt device add {url}", {
|
|
148
|
+
device: found.name,
|
|
149
|
+
url: withToken(found.url)
|
|
150
|
+
});
|
|
151
|
+
async function attach(context) {
|
|
152
|
+
const given = context.options.device;
|
|
153
|
+
const stored = load();
|
|
154
|
+
let device;
|
|
155
|
+
if (given && /[:/]/.test(given)) device = parseURL(given);
|
|
156
|
+
else if (given) {
|
|
157
|
+
const name = label(given);
|
|
158
|
+
let known = storedName(stored, name);
|
|
159
|
+
if (known === void 0) {
|
|
160
|
+
const found = (await discover(context.signal, stored, (services) => services.some((it) => sameName(it.name, name)))).find((it) => sameName(it.name, name));
|
|
161
|
+
if (!found) throw new Error(tr("there is no device {device}; \"swipt device list\" lists them", { device: name }));
|
|
162
|
+
if (found.authenticates) throw new Error(requiresToken(found));
|
|
163
|
+
known = found.name;
|
|
164
|
+
}
|
|
165
|
+
device = parseURL(stored[known]);
|
|
166
|
+
} else {
|
|
167
|
+
let found = [];
|
|
168
|
+
if (Object.keys(stored).length === 0) found = await discover(context.signal, stored);
|
|
169
|
+
const names = Object.keys(stored);
|
|
170
|
+
if (names.length === 0) {
|
|
171
|
+
const locked = found.filter((it) => it.authenticates);
|
|
172
|
+
if (locked.length > 0) throw new Error(locked.map(requiresToken).join("\n"));
|
|
173
|
+
throw new Error(tr("there is no device; turn on Swipt › Developer › Local Network, or connect one with \"swipt device add URL\""));
|
|
174
|
+
}
|
|
175
|
+
if (names.length > 1) throw new Error(tr("there is more than one device: {devices}; choose one with -d", { devices: names.join(", ") }));
|
|
176
|
+
device = parseURL(stored[names[0]]);
|
|
177
|
+
}
|
|
178
|
+
context.target.url = device.url;
|
|
179
|
+
return open(device);
|
|
180
|
+
}
|
|
181
|
+
const connectionStates = {
|
|
182
|
+
[0]: tr("unspecified"),
|
|
183
|
+
[1]: tr("stopped"),
|
|
184
|
+
[2]: tr("connecting"),
|
|
185
|
+
[3]: tr("preparing"),
|
|
186
|
+
[4]: tr("running"),
|
|
187
|
+
[5]: tr("failed")
|
|
188
|
+
};
|
|
189
|
+
const connectionProblems = {
|
|
190
|
+
[1]: tr("unreachable"),
|
|
191
|
+
[2]: tr("pairing rejected"),
|
|
192
|
+
[3]: tr("developer mode off"),
|
|
193
|
+
[4]: tr("disk image missing"),
|
|
194
|
+
[5]: tr("disk image mount failed"),
|
|
195
|
+
[6]: tr("device unsupported"),
|
|
196
|
+
[7]: tr("screen in use"),
|
|
197
|
+
[8]: tr("VPN peer address missing"),
|
|
198
|
+
[9]: tr("other")
|
|
199
|
+
};
|
|
200
|
+
function connectionText(connection) {
|
|
201
|
+
let text = connectionStates[connection?.state ?? 0];
|
|
202
|
+
if (connection && connection.problem !== 0) text += `, ${connectionProblems[connection.problem]}`;
|
|
203
|
+
if (connection?.message) text += `: ${connection.message}`;
|
|
204
|
+
return text;
|
|
205
|
+
}
|
|
206
|
+
async function onLocalNetwork(host, signal) {
|
|
207
|
+
const mdns = multicastDNS({
|
|
208
|
+
socket: dgram.createSocket("udp4"),
|
|
209
|
+
bind: false
|
|
210
|
+
});
|
|
211
|
+
const query = () => mdns.query([{
|
|
212
|
+
name: host,
|
|
213
|
+
type: "A"
|
|
214
|
+
}, {
|
|
215
|
+
name: host,
|
|
216
|
+
type: "AAAA"
|
|
217
|
+
}]);
|
|
218
|
+
const requery = setInterval(query, browseRequery);
|
|
219
|
+
query();
|
|
220
|
+
try {
|
|
221
|
+
for await (const [response] of on(mdns, "response", { signal })) if (response.answers.some((it) => sameName(it.name, host))) return true;
|
|
222
|
+
} catch (error) {
|
|
223
|
+
if (!signal.aborted) throw error;
|
|
224
|
+
} finally {
|
|
225
|
+
clearInterval(requery);
|
|
226
|
+
mdns.destroy();
|
|
227
|
+
}
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
async function probe(url, signal) {
|
|
231
|
+
try {
|
|
232
|
+
const device = parseURL(url);
|
|
233
|
+
const { hostname } = new URL(device.url);
|
|
234
|
+
if (hostname.endsWith(".local") && !await onLocalNetwork(hostname, signal)) return { cells: [tr("offline")] };
|
|
235
|
+
const info = await open(device).system.getInfo({}, { signal });
|
|
236
|
+
return { cells: [`${info.appVersion} (${info.appBuild})`, connectionText(info.deviceConnection)] };
|
|
237
|
+
} catch (error) {
|
|
238
|
+
if (error instanceof RpcError && error.code === Code.Unauthenticated) return { cells: [tr("requires a token")] };
|
|
239
|
+
return {
|
|
240
|
+
cells: [tr("offline")],
|
|
241
|
+
failure: signal.aborted ? void 0 : error.message
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
async function list({ signal }) {
|
|
246
|
+
const stored = load();
|
|
247
|
+
const deadline = AbortSignal.any([signal, AbortSignal.timeout(browseLimit)]);
|
|
248
|
+
const probes = new Map(Object.values(stored).map((url) => [url, probe(url, deadline)]));
|
|
249
|
+
const locked = (await discover(signal, stored)).filter((it) => it.authenticates && storedName(stored, it.name) === void 0);
|
|
250
|
+
const names = Object.keys(stored).sort((a, b) => a.localeCompare(b));
|
|
251
|
+
if (names.length === 0 && locked.length === 0) {
|
|
252
|
+
console.error(tr("no device publishes Swipt on the local network; turn on Swipt › Developer › Local Network, or connect one with \"swipt device add URL\""));
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const late = AbortSignal.any([signal, AbortSignal.timeout(browseLimit)]);
|
|
256
|
+
const probed = await Promise.all(names.map(async (name) => ({
|
|
257
|
+
name,
|
|
258
|
+
...await (probes.get(stored[name]) ?? probe(stored[name], late))
|
|
259
|
+
})));
|
|
260
|
+
console.log(columns([...probed.map(({ name, cells }) => [
|
|
261
|
+
name,
|
|
262
|
+
parseURL(stored[name]).url,
|
|
263
|
+
...cells
|
|
264
|
+
]), ...locked.map((it) => [
|
|
265
|
+
it.name,
|
|
266
|
+
it.url,
|
|
267
|
+
tr("requires a token")
|
|
268
|
+
])].sort((a, b) => a[0].localeCompare(b[0]))));
|
|
269
|
+
for (const { name, failure } of probed) if (failure !== void 0) console.error(`${name}: ${failure}`);
|
|
270
|
+
for (const it of locked) console.error(requiresToken(it));
|
|
271
|
+
}
|
|
272
|
+
async function add(context) {
|
|
273
|
+
const device = parseURL(context.args[0]);
|
|
274
|
+
context.target.url = device.url;
|
|
275
|
+
const name = label((await open(device).system.getInfo({}, { signal: context.signal })).deviceName) || new URL(device.url).hostname;
|
|
276
|
+
const stored = load();
|
|
277
|
+
const previous = storedName(stored, name);
|
|
278
|
+
if (previous !== void 0) delete stored[previous];
|
|
279
|
+
stored[name] = context.args[0];
|
|
280
|
+
save(stored);
|
|
281
|
+
console.log(tr("added {device}", { device: name }));
|
|
282
|
+
}
|
|
283
|
+
function remove({ args }) {
|
|
284
|
+
const stored = load();
|
|
285
|
+
const name = storedName(stored, label(args[0]));
|
|
286
|
+
if (name === void 0) throw new Error(tr("there is no device {device}", { device: args[0] }));
|
|
287
|
+
delete stored[name];
|
|
288
|
+
save(stored);
|
|
289
|
+
console.log(tr("removed {name}", { name }));
|
|
290
|
+
}
|
|
291
|
+
export { add, attach, findPublished, label, list, remove, runningSwipt, sameName, tryUnlock, withToken };
|
|
292
|
+
|
|
293
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","names":["sleep"],"sources":["../src/connection.ts"],"sourcesContent":["import dgram from \"node:dgram\";\nimport { on } from \"node:events\";\nimport fs from \"node:fs\";\nimport os from \"node:os\";\nimport path from \"node:path\";\nimport { setTimeout as sleep } from \"node:timers/promises\";\n\nimport Bonjour from \"bonjour-service\";\nimport multicastDNS from \"multicast-dns\";\n\nimport { Code, RpcError, UsageError, open } from \"./client\";\nimport { tr } from \"./i18n\";\nimport { columns } from \"./output\";\nimport {\n DeviceConnectionProblem,\n DeviceConnectionState,\n} from \"./proto/common_pb\";\n\nconst browseLimit = 1500;\nconst browseRequery = 300;\nconst publishLimit = 10_000;\nconst answerLimit = 5000;\n\nconst storeFile = path.join(\n process.env.XDG_CONFIG_HOME || path.join(os.homedir(), \".config\"),\n \"swipt\",\n \"devices.json\",\n);\n\nfunction load() {\n let text;\n try {\n text = fs.readFileSync(storeFile, \"utf8\");\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"ENOENT\") {\n return {};\n }\n throw error;\n }\n return JSON.parse(text);\n}\n\nfunction save(devices) {\n fs.mkdirSync(path.dirname(storeFile), { recursive: true, mode: 0o700 });\n fs.writeFileSync(storeFile, `${JSON.stringify(devices, null, 2)}\\n`, {\n mode: 0o600,\n });\n}\n\nexport function label(name) {\n const slug = [...name.replaceAll(/['’]/g, \"\")]\n .map((character) => (/[A-Za-z0-9]/.test(character) ? character : \"-\"))\n .join(\"\")\n .split(\"-\")\n .filter((part) => part !== \"\")\n .join(\"-\");\n return slug === \"\" ? name : slug;\n}\n\nexport const sameName = (a, b) => a.toLowerCase() === b.toLowerCase();\n\nconst storedName = (stored, name) =>\n Object.keys(stored).find((it) => sameName(it, name));\n\nfunction parseURL(text) {\n let parsed;\n try {\n parsed = new URL(text.includes(\"://\") ? text : `http://${text}`);\n } catch {\n throw new UsageError(tr(\"{text} is not a URL\", { text }));\n }\n if (\n parsed.hostname === \"\" ||\n (parsed.protocol !== \"http:\" && parsed.protocol !== \"https:\")\n ) {\n throw new UsageError(tr(\"{text} is not an http or https URL\", { text }));\n }\n let token;\n try {\n token = decodeURIComponent(parsed.username);\n } catch {\n token = parsed.username;\n }\n return {\n url: `${parsed.protocol}//${parsed.host}${parsed.pathname.replace(/\\/+$/, \"\")}`,\n token,\n };\n}\n\nexport const withToken = (url) => url.replace(\"://\", \"://TOKEN@\");\n\nasync function browse(signal, until, limit = browseLimit) {\n const bonjour = new Bonjour({\n socket: dgram.createSocket(\"udp4\"),\n bind: false,\n } as any);\n const found = new Map();\n const enough = new AbortController();\n try {\n const browser = bonjour.find({ type: \"swipt\" }, (service) => {\n if (!service.host || found.has(service.name)) {\n return;\n }\n const host = service.host.replace(/\\.$/, \"\").toLowerCase();\n found.set(service.name, {\n name: label(service.name),\n url: `http://${host.includes(\":\") ? `[${host}]` : host}:${service.port}`,\n authenticates: service.txt?.auth === \"1\",\n });\n if (until?.([...found.values()])) {\n enough.abort();\n }\n });\n const requery = setInterval(() => browser.update(), browseRequery);\n try {\n await sleep(limit, undefined, {\n signal: AbortSignal.any([signal, enough.signal]),\n });\n } catch (error) {\n if (signal.aborted) {\n throw error;\n }\n } finally {\n clearInterval(requery);\n }\n browser.stop();\n } finally {\n bonjour.destroy();\n }\n return [...found.values()];\n}\n\nexport async function findPublished(name, signal) {\n const wanted = label(name);\n const matches = (service) => sameName(service.name, wanted);\n const found = await browse(\n signal,\n (services) => services.some(matches),\n publishLimit,\n );\n return found.find(matches);\n}\n\nexport async function runningSwipt(name, signal) {\n const wanted = label(name);\n const stored = load();\n await discover(signal, stored, (services) =>\n services.some((it) => sameName(it.name, wanted)),\n );\n const known = storedName(stored, wanted);\n if (known === undefined) {\n return undefined;\n }\n const client = open(parseURL(stored[known]));\n try {\n await client.system.getInfo(\n {},\n { signal: AbortSignal.any([signal, AbortSignal.timeout(answerLimit)]) },\n );\n } catch (error) {\n if (signal.aborted || !(error instanceof RpcError)) {\n throw error;\n }\n if (error.code === Code.Unauthenticated) {\n console.error(tr(\"error: {message}\", { message: error.message }));\n }\n return undefined;\n }\n return client;\n}\n\nexport async function tryUnlock(client, signal) {\n try {\n for await (const response of client.repl.execute(\n { code: \"await device.unlock()\", args: [], program: false },\n { signal },\n )) {\n if (response.part.case === \"error\") {\n return response.part.value.message;\n }\n }\n } catch (error) {\n if (signal.aborted || !(error instanceof RpcError)) {\n throw error;\n }\n return error.message;\n }\n return undefined;\n}\n\nasync function discover(signal, stored, until?) {\n const found = await browse(signal, until);\n let changed = false;\n for (const it of found) {\n if (it.authenticates) {\n continue;\n }\n const name = storedName(stored, it.name);\n if (name === undefined) {\n stored[it.name] = it.url;\n changed = true;\n } else {\n const current = parseURL(stored[name]);\n if (current.token === \"\" && current.url !== it.url) {\n stored[name] = it.url;\n changed = true;\n }\n }\n }\n if (changed) {\n save(stored);\n }\n return found;\n}\n\nconst requiresToken = (found) =>\n tr(\"{device} requires a token: swipt device add {url}\", {\n device: found.name,\n url: withToken(found.url),\n });\n\nexport async function attach(context) {\n const given = context.options.device;\n const stored = load();\n let device;\n if (given && /[:/]/.test(given)) {\n device = parseURL(given);\n } else if (given) {\n const name = label(given);\n let known = storedName(stored, name);\n if (known === undefined) {\n const found = (\n await discover(context.signal, stored, (services) =>\n services.some((it) => sameName(it.name, name)),\n )\n ).find((it) => sameName(it.name, name));\n if (!found) {\n throw new Error(\n tr('there is no device {device}; \"swipt device list\" lists them', {\n device: name,\n }),\n );\n }\n if (found.authenticates) {\n throw new Error(requiresToken(found));\n }\n known = found.name;\n }\n device = parseURL(stored[known]);\n } else {\n let found = [];\n if (Object.keys(stored).length === 0) {\n found = await discover(context.signal, stored);\n }\n const names = Object.keys(stored);\n if (names.length === 0) {\n const locked = found.filter((it) => it.authenticates);\n if (locked.length > 0) {\n throw new Error(locked.map(requiresToken).join(\"\\n\"));\n }\n throw new Error(\n tr(\n 'there is no device; turn on Swipt › Developer › Local Network, or connect one with \"swipt device add URL\"',\n ),\n );\n }\n if (names.length > 1) {\n throw new Error(\n tr(\"there is more than one device: {devices}; choose one with -d\", {\n devices: names.join(\", \"),\n }),\n );\n }\n device = parseURL(stored[names[0]]);\n }\n context.target.url = device.url;\n return open(device);\n}\n\nconst connectionStates = {\n [DeviceConnectionState.UNSPECIFIED]: tr(\"unspecified\"),\n [DeviceConnectionState.STOPPED]: tr(\"stopped\"),\n [DeviceConnectionState.CONNECTING]: tr(\"connecting\"),\n [DeviceConnectionState.PREPARING]: tr(\"preparing\"),\n [DeviceConnectionState.RUNNING]: tr(\"running\"),\n [DeviceConnectionState.FAILED]: tr(\"failed\"),\n};\n\nconst connectionProblems = {\n [DeviceConnectionProblem.UNREACHABLE]: tr(\"unreachable\"),\n [DeviceConnectionProblem.PAIRING_REJECTED]: tr(\"pairing rejected\"),\n [DeviceConnectionProblem.DEVELOPER_MODE_OFF]: tr(\"developer mode off\"),\n [DeviceConnectionProblem.DISK_IMAGE_MISSING]: tr(\"disk image missing\"),\n [DeviceConnectionProblem.DISK_IMAGE_MOUNT_FAILED]: tr(\n \"disk image mount failed\",\n ),\n [DeviceConnectionProblem.DEVICE_UNSUPPORTED]: tr(\"device unsupported\"),\n [DeviceConnectionProblem.SCREEN_IN_USE]: tr(\"screen in use\"),\n [DeviceConnectionProblem.VPN_PEER_ADDRESS_MISSING]: tr(\n \"VPN peer address missing\",\n ),\n [DeviceConnectionProblem.OTHER]: tr(\"other\"),\n};\n\nfunction connectionText(connection) {\n let text = connectionStates[connection?.state ?? 0];\n if (\n connection &&\n connection.problem !== DeviceConnectionProblem.UNSPECIFIED\n ) {\n text += `, ${connectionProblems[connection.problem]}`;\n }\n if (connection?.message) {\n text += `: ${connection.message}`;\n }\n return text;\n}\n\nasync function onLocalNetwork(host, signal) {\n const mdns = multicastDNS({\n socket: dgram.createSocket(\"udp4\"),\n bind: false,\n });\n const query = () =>\n mdns.query([\n { name: host, type: \"A\" },\n { name: host, type: \"AAAA\" },\n ]);\n const requery = setInterval(query, browseRequery);\n query();\n try {\n for await (const [response] of on(mdns, \"response\", { signal })) {\n if (response.answers.some((it) => sameName(it.name, host))) {\n return true;\n }\n }\n } catch (error) {\n if (!signal.aborted) {\n throw error;\n }\n } finally {\n clearInterval(requery);\n mdns.destroy();\n }\n return false;\n}\n\nasync function probe(url, signal) {\n try {\n const device = parseURL(url);\n const { hostname } = new URL(device.url);\n if (\n hostname.endsWith(\".local\") &&\n !(await onLocalNetwork(hostname, signal))\n ) {\n return { cells: [tr(\"offline\")] };\n }\n const info = await open(device).system.getInfo({}, { signal });\n return {\n cells: [\n `${info.appVersion} (${info.appBuild})`,\n connectionText(info.deviceConnection),\n ],\n };\n } catch (error) {\n if (error instanceof RpcError && error.code === Code.Unauthenticated) {\n return { cells: [tr(\"requires a token\")] };\n }\n return {\n cells: [tr(\"offline\")],\n failure: signal.aborted ? undefined : error.message,\n };\n }\n}\n\nexport async function list({ signal }) {\n const stored = load();\n const deadline = AbortSignal.any([signal, AbortSignal.timeout(browseLimit)]);\n const probes = new Map(\n Object.values(stored).map((url) => [url, probe(url, deadline)]),\n );\n const locked = (await discover(signal, stored)).filter(\n (it) => it.authenticates && storedName(stored, it.name) === undefined,\n );\n const names = Object.keys(stored).sort((a, b) => a.localeCompare(b));\n if (names.length === 0 && locked.length === 0) {\n console.error(\n tr(\n 'no device publishes Swipt on the local network; turn on Swipt › Developer › Local Network, or connect one with \"swipt device add URL\"',\n ),\n );\n return;\n }\n const late = AbortSignal.any([signal, AbortSignal.timeout(browseLimit)]);\n const probed = await Promise.all(\n names.map(async (name) => ({\n name,\n ...(await (probes.get(stored[name]) ?? probe(stored[name], late))),\n })),\n );\n console.log(\n columns(\n [\n ...probed.map(({ name, cells }) => [\n name,\n parseURL(stored[name]).url,\n ...cells,\n ]),\n ...locked.map((it) => [it.name, it.url, tr(\"requires a token\")]),\n ].sort((a, b) => a[0].localeCompare(b[0])),\n ),\n );\n for (const { name, failure } of probed) {\n if (failure !== undefined) {\n console.error(`${name}: ${failure}`);\n }\n }\n for (const it of locked) {\n console.error(requiresToken(it));\n }\n}\n\nexport async function add(context) {\n const device = parseURL(context.args[0]);\n context.target.url = device.url;\n const info = await open(device).system.getInfo(\n {},\n { signal: context.signal },\n );\n const name = label(info.deviceName) || new URL(device.url).hostname;\n const stored = load();\n const previous = storedName(stored, name);\n if (previous !== undefined) {\n delete stored[previous];\n }\n stored[name] = context.args[0];\n save(stored);\n console.log(tr(\"added {device}\", { device: name }));\n}\n\nexport function remove({ args }) {\n const stored = load();\n const name = storedName(stored, label(args[0]));\n if (name === undefined) {\n throw new Error(tr(\"there is no device {device}\", { device: args[0] }));\n }\n delete stored[name];\n save(stored);\n console.log(tr(\"removed {name}\", { name }));\n}\n"],"mappings":";;;;;;;;;;;;;AAkBA,MAAM,cAAc;AACpB,MAAM,gBAAgB;AACtB,MAAM,eAAe;AACrB,MAAM,cAAc;AAEpB,MAAM,YAAY,KAAK,KACrB,QAAQ,IAAI,mBAAmB,KAAK,KAAK,GAAG,QAAQ,GAAG,SAAS,GAChE,SACA,cACF;AAEA,SAAS,OAAO;CACd,IAAI;CACJ,IAAI;EACF,OAAO,GAAG,aAAa,WAAW,MAAM;CAC1C,SAAS,OAAO;EACd,IAAK,MAAgC,SAAS,UAC5C,OAAO,CAAC;EAEV,MAAM;CACR;CACA,OAAO,KAAK,MAAM,IAAI;AACxB;AAEA,SAAS,KAAK,SAAS;CACrB,GAAG,UAAU,KAAK,QAAQ,SAAS,GAAG;EAAE,WAAW;EAAM,MAAM;CAAM,CAAC;CACtE,GAAG,cAAc,WAAW,GAAG,KAAK,UAAU,SAAS,MAAM,CAAC,EAAE,KAAK,EACnE,MAAM,IACR,CAAC;AACH;AAEA,SAAgB,MAAM,MAAM;CAC1B,MAAM,OAAO,CAAC,GAAG,KAAK,WAAW,SAAS,EAAE,CAAC,CAAC,CAC3C,KAAK,cAAe,cAAc,KAAK,SAAS,IAAI,YAAY,GAAI,CAAC,CACrE,KAAK,EAAE,CAAC,CACR,MAAM,GAAG,CAAC,CACV,QAAQ,SAAS,SAAS,EAAE,CAAC,CAC7B,KAAK,GAAG;CACX,OAAO,SAAS,KAAK,OAAO;AAC9B;AAEA,MAAa,YAAY,GAAG,MAAM,EAAE,YAAY,MAAM,EAAE,YAAY;AAEpE,MAAM,cAAc,QAAQ,SAC1B,OAAO,KAAK,MAAM,CAAC,CAAC,MAAM,OAAO,SAAS,IAAI,IAAI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,CAAC,CAAC,MAAM,GAAG,MAAM,EAAE,EAAE,CAAC,cAAc,EAAE,EAAE,CAAC,CAC3C,CACF;CACA,KAAK,MAAM,EAAE,MAAM,aAAa,QAC9B,IAAI,YAAY,KAAA,GACd,QAAQ,MAAM,GAAG,KAAK,IAAI,SAAS;CAGvC,KAAK,MAAM,MAAM,QACf,QAAQ,MAAM,cAAc,EAAE,CAAC;AAEnC;AAEA,eAAsB,IAAI,SAAS;CACjC,MAAM,SAAS,SAAS,QAAQ,KAAK,EAAE;CACvC,QAAQ,OAAO,MAAM,OAAO;CAK5B,MAAM,OAAO,OAAM,MAJA,KAAK,MAAM,CAAC,CAAC,OAAO,QACrC,CAAC,GACD,EAAE,QAAQ,QAAQ,OAAO,CAC3B,EAAA,CACwB,UAAU,KAAK,IAAI,IAAI,OAAO,GAAG,CAAC,CAAC;CAC3D,MAAM,SAAS,KAAK;CACpB,MAAM,WAAW,WAAW,QAAQ,IAAI;CACxC,IAAI,aAAa,KAAA,GACf,OAAO,OAAO;CAEhB,OAAO,QAAQ,QAAQ,KAAK;CAC5B,KAAK,MAAM;CACX,QAAQ,IAAI,GAAG,kBAAkB,EAAE,QAAQ,KAAK,CAAC,CAAC;AACpD;AAEA,SAAgB,OAAO,EAAE,QAAQ;CAC/B,MAAM,SAAS,KAAK;CACpB,MAAM,OAAO,WAAW,QAAQ,MAAM,KAAK,EAAE,CAAC;CAC9C,IAAI,SAAS,KAAA,GACX,MAAM,IAAI,MAAM,GAAG,+BAA+B,EAAE,QAAQ,KAAK,GAAG,CAAC,CAAC;CAExE,OAAO,OAAO;CACd,KAAK,MAAM;CACX,QAAQ,IAAI,GAAG,kBAAkB,EAAE,KAAK,CAAC,CAAC;AAC5C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare function devicectl(args: any, { parse }?: {
|
|
2
|
+
parse?: boolean;
|
|
3
|
+
}): Promise<any>;
|
|
4
|
+
export declare const serverHint: any;
|
|
5
|
+
export declare function serverPath(): any;
|
|
6
|
+
interface DeviceQuery {
|
|
7
|
+
required?: boolean;
|
|
8
|
+
filter?: (devices: any[]) => Promise<any[]> | any[];
|
|
9
|
+
}
|
|
10
|
+
export declare const apps: (device: any) => Promise<any>;
|
|
11
|
+
export declare const lockedError: RegExp;
|
|
12
|
+
export declare const installApp: (device: any, app: any, id: any) => Promise<any>;
|
|
13
|
+
export declare const uninstallApp: (device: any, id: any) => Promise<any>;
|
|
14
|
+
export declare const launchApp: (device: any, id: any, args?: any[]) => Promise<any>;
|
|
15
|
+
export declare function terminateApp(device: any, id: any): Promise<void>;
|
|
16
|
+
export declare const configureGuest: (device: any, id: any, name: any) => Promise<void>;
|
|
17
|
+
export declare function coreDevice(context: any, options?: DeviceQuery): Promise<any>;
|
|
18
|
+
export declare function containerHasFile(device: any, id: any, file: any): Promise<any>;
|
|
19
|
+
export declare function pullFromContainer(device: any, id: any, source: any, destination: any): Promise<void>;
|
|
20
|
+
export declare function pushToContainer(device: any, id: any, source: any, destination: any): Promise<void>;
|
|
21
|
+
export declare const provisioningProfiles: (udid: any) => Promise<any>;
|
|
22
|
+
export {};
|