-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource-export-plugin.ts
More file actions
75 lines (69 loc) · 1.96 KB
/
Copy pathsource-export-plugin.ts
File metadata and controls
75 lines (69 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import {
captureSessionBundle,
writeCaptureStatus,
type SessionCaptureResult,
} from "./source-capture.js";
import type { SessionSnapshotSource } from "./importer.js";
export interface SourceExportPluginConfig {
sessionId: string;
outputPath: string;
statusPath: string;
nonce: string;
}
interface SourceExportContext {
sessionPersistence: SessionSnapshotSource & { name?: string };
}
/**
* One-shot, read-only overlay used by `dsh-teleport-import capture`.
*
* This function intentionally has no Cordis or DSH runtime import. Attaching
* `inject` directly to the default-exported function lets an old profile load
* the temporary overlay without installing this package's optional peers.
*/
export async function apply(
ctx: SourceExportContext,
config: SourceExportPluginConfig,
): Promise<void> {
const source = ctx.sessionPersistence;
const sourceBackend = source.name ?? "unknown";
let result: SessionCaptureResult;
try {
if (sourceBackend === "session-persistence-teleport") {
throw new Error("capture source is already the Teleport authority");
}
result = await captureSessionBundle(
source,
config.sessionId,
config.outputPath,
sourceBackend,
);
await writeCaptureStatus(config.statusPath, {
version: 1,
nonce: config.nonce,
ok: true,
result,
});
} catch (error: unknown) {
await writeCaptureStatus(config.statusPath, {
version: 1,
nonce: config.nonce,
ok: false,
error: safeErrorCode(error),
});
throw error;
}
}
apply.inject = ["sessionPersistence"];
export default apply;
function safeErrorCode(error: unknown): string {
if (
error !== null &&
typeof error === "object" &&
"code" in error &&
typeof error.code === "string" &&
/^[A-Z][A-Z0-9_]{1,63}$/.test(error.code)
) {
return `source Session capture failed (${error.code})`;
}
return "source Session capture failed; inspect the source profile locally";
}