@impz/client 7.4.0 → 7.5.1
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/identity.js +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.js +108 -108
- package/package.json +1 -1
package/dist/identity.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
-
// ../api/src/schemas/identity-schema.ts
|
|
2
|
+
// ../api/src/schemas/identity-trust-document-schema.ts
|
|
3
3
|
const IdentityIssuerSchema = z.string().regex(/^[A-Za-z0-9._-]{1,128}$/u, "must be 1 to 128 letters, digits, \".\", \"_\" or \"-\"");
|
|
4
4
|
const Base64UrlSchema = z.string().regex(/^[A-Za-z0-9_-]+$/u);
|
|
5
5
|
const IdentityJwkSchema = z.object({
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ interface ServerCheck {
|
|
|
13
13
|
interface CheckServerOptions {
|
|
14
14
|
readonly signal?: Readonly<AbortSignal>;
|
|
15
15
|
}
|
|
16
|
+
type StartTimer = (fire: () => void, durationMs: number) => () => void;
|
|
16
17
|
type ReadonlyFields<T> = { readonly [Key in keyof T]: ToReadonly<T[Key]>; };
|
|
17
18
|
type ToReadonly<T> = T extends readonly (infer Item)[] ? readonly Item[] : T extends object ? Readonly<T> : T;
|
|
18
19
|
type ExecStart = ReadonlyFields<Omit<z.input<typeof ExecStartMessageSchema>, 'type' | 'tool' | 'outer'>>;
|
|
@@ -119,14 +120,6 @@ interface RunResult extends ExecExit {
|
|
|
119
120
|
interface RunOptions extends Omit<ExecOptions, 'tty' | 'cols' | 'rows'> {
|
|
120
121
|
readonly stdin?: string | Uint8Array;
|
|
121
122
|
}
|
|
122
|
-
interface RequireAwakeOptions {
|
|
123
|
-
readonly restartError?: boolean;
|
|
124
|
-
readonly retryUnavailable?: {
|
|
125
|
-
readonly attempts: number;
|
|
126
|
-
readonly delayMs: number;
|
|
127
|
-
};
|
|
128
|
-
readonly signal?: Readonly<AbortSignal>;
|
|
129
|
-
}
|
|
130
123
|
type BuildContext = Blob | Uint8Array<ArrayBuffer> | ReadableStream<Uint8Array>;
|
|
131
124
|
interface BuildImageOptions {
|
|
132
125
|
readonly dockerfile?: string;
|
|
@@ -135,7 +128,14 @@ interface BuildImageOptions {
|
|
|
135
128
|
readonly onProgress?: (progress: ImageBuildProgress) => void;
|
|
136
129
|
readonly onLog?: (line: string) => void;
|
|
137
130
|
}
|
|
138
|
-
|
|
131
|
+
interface RequireAwakeOptions {
|
|
132
|
+
readonly restartError?: boolean;
|
|
133
|
+
readonly retryUnavailable?: {
|
|
134
|
+
readonly attempts: number;
|
|
135
|
+
readonly delayMs: number;
|
|
136
|
+
};
|
|
137
|
+
readonly signal?: Readonly<AbortSignal>;
|
|
138
|
+
}
|
|
139
139
|
type RpcClient = ContractRouterClient<ImpContract>;
|
|
140
140
|
interface ImpClientOptions {
|
|
141
141
|
readonly url: string;
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@ import { RPCLink } from "@orpc/client/fetch";
|
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
import { P, match } from "ts-pattern";
|
|
5
5
|
import pRetry, { AbortError } from "p-retry";
|
|
6
|
-
// src/check-server.ts
|
|
7
|
-
const CLIENT_VERSION = "7.
|
|
6
|
+
// src/features/check-server.ts
|
|
7
|
+
const CLIENT_VERSION = "7.5.1";
|
|
8
8
|
async function checkServer(rpc, options = {}) {
|
|
9
9
|
const signal = options.signal;
|
|
10
10
|
const callOptions = signal === void 0 ? {} : { signal };
|
|
@@ -29,6 +29,64 @@ function parseVersion(version) {
|
|
|
29
29
|
minor: Number(groups["minor"])
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
// src/connection/resolve-impd-url.ts
|
|
33
|
+
function resolveImpdUrl(base, path) {
|
|
34
|
+
const url = new URL(base);
|
|
35
|
+
url.pathname = `${url.pathname.replace(/\/+$/u, "")}${path}`;
|
|
36
|
+
return url;
|
|
37
|
+
}
|
|
38
|
+
// src/connection/send-long-call.ts
|
|
39
|
+
const HOUR_MS = 36e5;
|
|
40
|
+
const LONG_CALL_DEADLINES_MS = /* @__PURE__ */ new Map([
|
|
41
|
+
["backups.run", 24 * HOUR_MS],
|
|
42
|
+
["backups.restore", 24 * HOUR_MS],
|
|
43
|
+
["backups.check", 24 * HOUR_MS],
|
|
44
|
+
["images.add", 6 * HOUR_MS],
|
|
45
|
+
["images.build", 6 * HOUR_MS],
|
|
46
|
+
["system.gc", HOUR_MS],
|
|
47
|
+
["moves.abort", HOUR_MS],
|
|
48
|
+
["moves.resume", HOUR_MS]
|
|
49
|
+
]);
|
|
50
|
+
async function sendLongCall(request, init, call) {
|
|
51
|
+
const limit = new AbortController();
|
|
52
|
+
const expired = Promise.withResolvers();
|
|
53
|
+
const onCallerAbort = () => {
|
|
54
|
+
limit.abort(request.signal.reason);
|
|
55
|
+
};
|
|
56
|
+
request.signal.addEventListener("abort", onCallerAbort, { once: true });
|
|
57
|
+
if (request.signal.aborted) onCallerAbort();
|
|
58
|
+
const cancel = call.startTimer(() => {
|
|
59
|
+
const error = new DOMException(`impd sent no answer to ${call.procedure} in ${formatHours(call.deadlineMs)}`, "TimeoutError");
|
|
60
|
+
limit.abort(error);
|
|
61
|
+
expired.reject(error);
|
|
62
|
+
}, call.deadlineMs);
|
|
63
|
+
const signal = limit.signal;
|
|
64
|
+
try {
|
|
65
|
+
const limited = new Request(request, { signal });
|
|
66
|
+
const sent = call.send === null ? fetch(limited, {
|
|
67
|
+
...init,
|
|
68
|
+
signal,
|
|
69
|
+
timeout: false
|
|
70
|
+
}) : call.send(limited);
|
|
71
|
+
return await Promise.race([sent, expired.promise]);
|
|
72
|
+
} finally {
|
|
73
|
+
cancel();
|
|
74
|
+
request.signal.removeEventListener("abort", onCallerAbort);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function formatHours(durationMs) {
|
|
78
|
+
const hours = durationMs / HOUR_MS;
|
|
79
|
+
return hours === 1 ? "an hour" : `${String(hours)} hours`;
|
|
80
|
+
}
|
|
81
|
+
// src/connection/unknown-procedure-error.ts
|
|
82
|
+
var UnknownProcedureError = class extends Error {
|
|
83
|
+
procedure;
|
|
84
|
+
constructor(procedure) {
|
|
85
|
+
super(`impd has no procedure ${procedure}`);
|
|
86
|
+
this.name = "UnknownProcedureError";
|
|
87
|
+
this.procedure = procedure;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
32
90
|
// ../api/src/schemas/name-schema.ts
|
|
33
91
|
const NameSchema = z.string().regex(/^[a-z][a-z0-9-]{0,30}$/u, "must be a lowercase letter followed by up to 30 lowercase letters, digits or hyphens");
|
|
34
92
|
z.string().regex(/^[\w.:-]{1,64}$/u, "must be 1–64 letters, digits, dots, underscores, colons or hyphens");
|
|
@@ -47,7 +105,7 @@ const LeaseSummarySchema = z.object({
|
|
|
47
105
|
leases: z.array(LeaseSchema).readonly(),
|
|
48
106
|
otherCount: z.int().nonnegative()
|
|
49
107
|
});
|
|
50
|
-
// ../api/src/protocols/build-context-
|
|
108
|
+
// ../api/src/protocols/build-context-query-schema.ts
|
|
51
109
|
const BUILD_CONTEXT_PATH = "/images/build-context";
|
|
52
110
|
const DockerfilePathSchema = z.string().min(1).refine((path) => !path.startsWith("/") && !path.split(/[/\\]/u).includes(".."), { message: "the Dockerfile path must be relative and stay inside the build context" });
|
|
53
111
|
z.object({
|
|
@@ -147,7 +205,7 @@ z.object({
|
|
|
147
205
|
endObservedAt: z.date().optional(),
|
|
148
206
|
log: z.boolean().optional()
|
|
149
207
|
});
|
|
150
|
-
// ../api/src/protocols/exec-
|
|
208
|
+
// ../api/src/protocols/exec-client-message-schema.ts
|
|
151
209
|
const EXEC_PATH = "/exec";
|
|
152
210
|
const EXEC_TICKET_PARAM = "ticket";
|
|
153
211
|
const EXEC_CHANNELS = {
|
|
@@ -303,7 +361,7 @@ z.object({
|
|
|
303
361
|
credential: z.string().nullable(),
|
|
304
362
|
warning: z.string().optional()
|
|
305
363
|
});
|
|
306
|
-
// ../api/src/schemas/move-schema.ts
|
|
364
|
+
// ../api/src/schemas/move-status-schema.ts
|
|
307
365
|
const MoveStateSchema = z.enum([
|
|
308
366
|
"sending",
|
|
309
367
|
"moved",
|
|
@@ -601,7 +659,7 @@ ImpSchema.extend({
|
|
|
601
659
|
grantsNotCopied: z.array(GrantNotCopiedSchema).readonly().optional(),
|
|
602
660
|
grantsError: z.string().optional()
|
|
603
661
|
});
|
|
604
|
-
// ../api/src/protocols/tunnel-
|
|
662
|
+
// ../api/src/protocols/tunnel-client-message-schema.ts
|
|
605
663
|
const TUNNEL_PATH = "/tunnel";
|
|
606
664
|
const TUNNEL_CLOSE_NORMAL = 1e3;
|
|
607
665
|
const TUNNEL_CLOSE_PROTOCOL = 1002;
|
|
@@ -772,7 +830,7 @@ const IMP_ERRORS = defineErrors({
|
|
|
772
830
|
data: z.object({ retryAfterS: z.int().positive() })
|
|
773
831
|
}
|
|
774
832
|
});
|
|
775
|
-
// ../api/src/protocols/
|
|
833
|
+
// ../api/src/protocols/console-shell.ts
|
|
776
834
|
const CONSOLE_SHELL = buildConsoleShell("/etc/passwd", ["/bin/bash", "/bin/sh"]);
|
|
777
835
|
function buildConsoleShell(passwdPath, fallbacks) {
|
|
778
836
|
return [
|
|
@@ -797,13 +855,7 @@ var ExecError = class extends Error {
|
|
|
797
855
|
this.data = options.data;
|
|
798
856
|
}
|
|
799
857
|
};
|
|
800
|
-
// src/
|
|
801
|
-
function resolveImpdUrl(base, path) {
|
|
802
|
-
const url = new URL(base);
|
|
803
|
-
url.pathname = `${url.pathname.replace(/\/+$/u, "")}${path}`;
|
|
804
|
-
return url;
|
|
805
|
-
}
|
|
806
|
-
// src/create-rpc-client.ts
|
|
858
|
+
// src/connection/create-rpc-client.ts
|
|
807
859
|
function createRpcClient(options) {
|
|
808
860
|
const customFetch = options.fetch;
|
|
809
861
|
const sendRequest = async (request, init) => {
|
|
@@ -824,22 +876,13 @@ function createRpcClient(options) {
|
|
|
824
876
|
function isJson(contentType) {
|
|
825
877
|
return (contentType ?? "").startsWith("application/json");
|
|
826
878
|
}
|
|
827
|
-
// src/resolve-impd-web-socket-url.ts
|
|
879
|
+
// src/connection/resolve-impd-web-socket-url.ts
|
|
828
880
|
function resolveImpdWebSocketUrl(base, path) {
|
|
829
881
|
const url = resolveImpdUrl(base, path);
|
|
830
882
|
url.protocol = url.protocol === "https:" ? "wss:" : "ws:";
|
|
831
883
|
return url;
|
|
832
884
|
}
|
|
833
|
-
// src/
|
|
834
|
-
var UnknownProcedureError = class extends Error {
|
|
835
|
-
procedure;
|
|
836
|
-
constructor(procedure) {
|
|
837
|
-
super(`impd has no procedure ${procedure}`);
|
|
838
|
-
this.name = "UnknownProcedureError";
|
|
839
|
-
this.procedure = procedure;
|
|
840
|
-
}
|
|
841
|
-
};
|
|
842
|
-
// src/require-features.ts
|
|
885
|
+
// src/features/require-features.ts
|
|
843
886
|
const FEATURE_GAPS = {
|
|
844
887
|
sessionOffsets: "has no session offsets",
|
|
845
888
|
leases: "has no leases",
|
|
@@ -1471,51 +1514,7 @@ async function readAll(stream) {
|
|
|
1471
1514
|
const buffer = await new Response(stream).arrayBuffer();
|
|
1472
1515
|
return new Uint8Array(buffer);
|
|
1473
1516
|
}
|
|
1474
|
-
// src/
|
|
1475
|
-
async function requireAwake(rpc, name, options = {}) {
|
|
1476
|
-
const signal = options.signal;
|
|
1477
|
-
const callOptions = signal === void 0 ? {} : { signal };
|
|
1478
|
-
const retry = options.retryUnavailable ?? {
|
|
1479
|
-
attempts: 0,
|
|
1480
|
-
delayMs: 0
|
|
1481
|
-
};
|
|
1482
|
-
const input = {
|
|
1483
|
-
name,
|
|
1484
|
-
restartError: options.restartError === true
|
|
1485
|
-
};
|
|
1486
|
-
const wake = async () => {
|
|
1487
|
-
try {
|
|
1488
|
-
return await rpc.imps.wake(input, callOptions);
|
|
1489
|
-
} catch (error) {
|
|
1490
|
-
throw new WakeFailureError(error);
|
|
1491
|
-
}
|
|
1492
|
-
};
|
|
1493
|
-
try {
|
|
1494
|
-
return await pRetry(wake, {
|
|
1495
|
-
retries: retry.attempts,
|
|
1496
|
-
minTimeout: retry.delayMs,
|
|
1497
|
-
factor: 1,
|
|
1498
|
-
...signal !== void 0 && { signal },
|
|
1499
|
-
shouldRetry: (context) => context.error instanceof WakeFailureError && isUnavailable(context.error.failure)
|
|
1500
|
-
});
|
|
1501
|
-
} catch (error) {
|
|
1502
|
-
throw error instanceof WakeFailureError ? error.failure : error;
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
var WakeFailureError = class extends Error {
|
|
1506
|
-
name = "WakeFailureError";
|
|
1507
|
-
failure;
|
|
1508
|
-
constructor(failure) {
|
|
1509
|
-
const message = failure instanceof Error ? failure.message : String(failure);
|
|
1510
|
-
super(message);
|
|
1511
|
-
this.failure = failure;
|
|
1512
|
-
}
|
|
1513
|
-
};
|
|
1514
|
-
function isUnavailable(error) {
|
|
1515
|
-
if (error instanceof ORPCError$1) return error.code === "SERVICE_UNAVAILABLE";
|
|
1516
|
-
return error instanceof TypeError;
|
|
1517
|
-
}
|
|
1518
|
-
// src/run-image-build.ts
|
|
1517
|
+
// src/images/run-image-build.ts
|
|
1519
1518
|
async function runImageBuild(deps, name, context, options = {}) {
|
|
1520
1519
|
const call = { ...options.signal !== void 0 && { signal: options.signal } };
|
|
1521
1520
|
await requireFeatures(deps.rpc, { buildContextUpload: "answer the upload with not found" }, call);
|
|
@@ -1559,48 +1558,49 @@ async function writeBuildContext(deps, name, context, options) {
|
|
|
1559
1558
|
message: `impd answered ${String(response.status)} to the build context upload`
|
|
1560
1559
|
});
|
|
1561
1560
|
}
|
|
1562
|
-
// src/
|
|
1563
|
-
|
|
1564
|
-
const
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1561
|
+
// src/require-awake.ts
|
|
1562
|
+
async function requireAwake(rpc, name, options = {}) {
|
|
1563
|
+
const signal = options.signal;
|
|
1564
|
+
const callOptions = signal === void 0 ? {} : { signal };
|
|
1565
|
+
const retry = options.retryUnavailable ?? {
|
|
1566
|
+
attempts: 0,
|
|
1567
|
+
delayMs: 0
|
|
1568
|
+
};
|
|
1569
|
+
const input = {
|
|
1570
|
+
name,
|
|
1571
|
+
restartError: options.restartError === true
|
|
1572
|
+
};
|
|
1573
|
+
const wake = async () => {
|
|
1574
|
+
try {
|
|
1575
|
+
return await rpc.imps.wake(input, callOptions);
|
|
1576
|
+
} catch (error) {
|
|
1577
|
+
throw new WakeFailureError(error);
|
|
1578
|
+
}
|
|
1579
1579
|
};
|
|
1580
|
-
request.signal.addEventListener("abort", onCallerAbort, { once: true });
|
|
1581
|
-
if (request.signal.aborted) onCallerAbort();
|
|
1582
|
-
const cancel = call.startTimer(() => {
|
|
1583
|
-
const error = new DOMException(`impd sent no answer to ${call.procedure} in ${formatHours(call.deadlineMs)}`, "TimeoutError");
|
|
1584
|
-
limit.abort(error);
|
|
1585
|
-
expired.reject(error);
|
|
1586
|
-
}, call.deadlineMs);
|
|
1587
|
-
const signal = limit.signal;
|
|
1588
1580
|
try {
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
}
|
|
1597
|
-
|
|
1598
|
-
request.signal.removeEventListener("abort", onCallerAbort);
|
|
1581
|
+
return await pRetry(wake, {
|
|
1582
|
+
retries: retry.attempts,
|
|
1583
|
+
minTimeout: retry.delayMs,
|
|
1584
|
+
factor: 1,
|
|
1585
|
+
...signal !== void 0 && { signal },
|
|
1586
|
+
shouldRetry: (context) => context.error instanceof WakeFailureError && isUnavailable(context.error.failure)
|
|
1587
|
+
});
|
|
1588
|
+
} catch (error) {
|
|
1589
|
+
throw error instanceof WakeFailureError ? error.failure : error;
|
|
1599
1590
|
}
|
|
1600
1591
|
}
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1592
|
+
var WakeFailureError = class extends Error {
|
|
1593
|
+
name = "WakeFailureError";
|
|
1594
|
+
failure;
|
|
1595
|
+
constructor(failure) {
|
|
1596
|
+
const message = failure instanceof Error ? failure.message : String(failure);
|
|
1597
|
+
super(message);
|
|
1598
|
+
this.failure = failure;
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1601
|
+
function isUnavailable(error) {
|
|
1602
|
+
if (error instanceof ORPCError$1) return error.code === "SERVICE_UNAVAILABLE";
|
|
1603
|
+
return error instanceof TypeError;
|
|
1604
1604
|
}
|
|
1605
1605
|
// src/create-imp-client.ts
|
|
1606
1606
|
function createImpClient(options) {
|