@sellable/install
Version:
One-command installer for Sellable MCP in Claude Code, Codex, and Hermes
82 lines (77 loc) • 1.95 kB
JavaScript
const ADMIN_RUNTIME_PHASES = new Set([
"runtime_secrets",
"snapshot_restore",
"profile_settings_delivery",
"profile_stage",
"profile_live_merge_promote",
"profile_crons",
"product_mcp_readiness",
"default_profile_bundle",
"memory_snapshot",
"slack_serving_proof",
"native_gateway",
"serving_observation",
"operation_completion",
]);
function phaseFailureCode(error) {
const code = error instanceof Error ? error.message : "";
return /^[A-Za-z0-9_:-]{1,160}$/.test(code)
? code
: "admin_runtime_phase_failed";
}
export function createAdminRuntimePhaseTelemetry({
bootSessionId,
operationId,
now = () => Date.now(),
write = (entry) => process.stderr.write(`${JSON.stringify(entry)}\n`),
}) {
if (
typeof bootSessionId !== "string" ||
bootSessionId.length < 1 ||
typeof operationId !== "string" ||
operationId.length < 1
) {
throw new Error("admin_runtime_phase_identity_rejected");
}
const run = async (phase, work) => {
if (!ADMIN_RUNTIME_PHASES.has(phase) || typeof work !== "function") {
throw new Error("admin_runtime_phase_rejected");
}
const startedAt = now();
write({
ok: true,
code: "admin_runtime_phase",
phase,
status: "started",
elapsedMs: 0,
bootSessionId,
operationId,
});
try {
const result = await work();
write({
ok: true,
code: "admin_runtime_phase",
phase,
status: "completed",
elapsedMs: Math.max(0, now() - startedAt),
bootSessionId,
operationId,
});
return result;
} catch (error) {
write({
ok: false,
code: "admin_runtime_phase",
phase,
status: "failed",
elapsedMs: Math.max(0, now() - startedAt),
bootSessionId,
operationId,
errorCode: phaseFailureCode(error),
});
throw error;
}
};
return { run };
}