@duct-sdk/sdk 0.5.4 → 0.5.10
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/CHANGELOG.md +42 -0
- package/README.md +10 -10
- package/dist/adapters/react/shell.d.ts +2 -2
- package/dist/adapters/react/shell.js +1 -2
- package/dist/cli/generators/config.test.js +3 -0
- package/dist/cli/index.js +216 -36
- package/dist/cli/prompts/review.js +14 -0
- package/dist/core/config-roundtrip.test.d.ts +1 -0
- package/dist/core/config-roundtrip.test.js +180 -0
- package/dist/core/config.d.ts +281 -25
- package/dist/core/config.js +51 -67
- package/dist/core/endpoint-guard.d.ts +27 -0
- package/dist/core/endpoint-guard.js +71 -0
- package/dist/core/endpoint-guard.test.d.ts +1 -0
- package/dist/core/endpoint-guard.test.js +57 -0
- package/dist/core/env-diagnostics.d.ts +13 -0
- package/dist/core/env-diagnostics.js +63 -0
- package/dist/core/env-diagnostics.test.d.ts +1 -0
- package/dist/core/env-diagnostics.test.js +31 -0
- package/dist/core/evidence-bundle.conformance.test.d.ts +1 -0
- package/dist/core/evidence-bundle.conformance.test.js +110 -0
- package/dist/core/evidence-bundle.d.ts +59 -0
- package/dist/core/evidence-bundle.js +68 -0
- package/dist/core/evidence-bundle.test.d.ts +1 -0
- package/dist/core/evidence-bundle.test.js +58 -0
- package/dist/core/profile.d.ts +44 -0
- package/dist/core/profile.js +128 -0
- package/dist/core/profile.test.d.ts +1 -0
- package/dist/core/profile.test.js +95 -0
- package/dist/core/readiness-checks.d.ts +131 -0
- package/dist/core/readiness-checks.js +162 -0
- package/dist/core/readiness-checks.test.d.ts +1 -0
- package/dist/core/readiness-checks.test.js +106 -0
- package/dist/core/receipt.d.ts +5 -1
- package/dist/core/types.d.ts +23 -0
- package/dist/core/types.js +3 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -1
- package/dist/server.d.ts +3 -2
- package/dist/server.js +2 -1
- package/package.json +94 -93
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Offline verification for duct:audit-evidence:v1 bundles.
|
|
3
|
+
*/
|
|
4
|
+
import { verifyReceipt } from "./receipt.js";
|
|
5
|
+
export function verifyEvidenceBundle(bundle, options = {}) {
|
|
6
|
+
const warnings = [];
|
|
7
|
+
const failedReceipts = [];
|
|
8
|
+
let verifiedReceipts = 0;
|
|
9
|
+
const jwks = bundle.manifest.verification_keys ?? options.jwks;
|
|
10
|
+
const verifyOpts = { ...options, jwks: jwks ?? options.jwks };
|
|
11
|
+
for (const raw of bundle.receipts) {
|
|
12
|
+
const result = verifyReceipt(raw, verifyOpts);
|
|
13
|
+
if (result.valid) {
|
|
14
|
+
verifiedReceipts += 1;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
failedReceipts.push({
|
|
18
|
+
receipt_id: raw.receipt_id,
|
|
19
|
+
reason: result.reason,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const stages = new Set(bundle.evidence_events.map((e) => e.stage).filter(Boolean));
|
|
24
|
+
const required = [
|
|
25
|
+
"request_observed",
|
|
26
|
+
"policy_decided",
|
|
27
|
+
"upstream_dispatched",
|
|
28
|
+
"upstream_completed",
|
|
29
|
+
"response_delivered",
|
|
30
|
+
];
|
|
31
|
+
const missingStages = required.filter((s) => !stages.has(s));
|
|
32
|
+
const redactedFields = [];
|
|
33
|
+
for (const ev of bundle.evidence_events) {
|
|
34
|
+
const fields = ev.disclosed_fields;
|
|
35
|
+
if (!fields)
|
|
36
|
+
continue;
|
|
37
|
+
for (const f of fields) {
|
|
38
|
+
if (f.mode === "redacted" || f.mode === "masked") {
|
|
39
|
+
redactedFields.push(f.key);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (bundle.manifest.completeness === "partial") {
|
|
44
|
+
warnings.push("Bundle completeness is partial — some evidence stages may be missing");
|
|
45
|
+
}
|
|
46
|
+
if (bundle.integrity && !bundle.integrity.valid) {
|
|
47
|
+
warnings.push("Hash chain integrity check failed for included window");
|
|
48
|
+
}
|
|
49
|
+
if (!bundle.manifest.complete) {
|
|
50
|
+
warnings.push("Bundle is paginated — additional pages may be required");
|
|
51
|
+
}
|
|
52
|
+
const integrityValid = bundle.integrity?.valid !== false;
|
|
53
|
+
const valid = failedReceipts.length === 0 &&
|
|
54
|
+
integrityValid &&
|
|
55
|
+
bundle.manifest.schema === "duct:audit-evidence:v1";
|
|
56
|
+
return {
|
|
57
|
+
valid,
|
|
58
|
+
schema: bundle.manifest.schema,
|
|
59
|
+
completeness: bundle.manifest.completeness,
|
|
60
|
+
verified_receipts: verifiedReceipts,
|
|
61
|
+
failed_receipts: failedReceipts,
|
|
62
|
+
integrity_valid: integrityValid,
|
|
63
|
+
missing_stages: missingStages,
|
|
64
|
+
redacted_fields: [...new Set(redactedFields)],
|
|
65
|
+
non_claims: bundle.manifest.non_claims ?? [],
|
|
66
|
+
warnings,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, it } from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import { createHmac } from 'crypto';
|
|
4
|
+
import { verifyEvidenceBundle } from './evidence-bundle.js';
|
|
5
|
+
import { computeReceiptId } from './receipt.js';
|
|
6
|
+
import { canonicalizeJson } from './jcs.js';
|
|
7
|
+
const HMAC_SECRET = 'x'.repeat(32);
|
|
8
|
+
function minimalReceipt() {
|
|
9
|
+
const body = {
|
|
10
|
+
claim_type: 'duct:action:v1',
|
|
11
|
+
issued_at: new Date().toISOString(),
|
|
12
|
+
shell_id: 'shell_test',
|
|
13
|
+
action_id: 'get_items',
|
|
14
|
+
caller_type: 'human',
|
|
15
|
+
decision: 'permit',
|
|
16
|
+
reason: 'Passes all permission checks',
|
|
17
|
+
permission_source: 'default',
|
|
18
|
+
capture_mode: 'gateway_observed',
|
|
19
|
+
scope_of_claim: {
|
|
20
|
+
asserts: ['test'],
|
|
21
|
+
does_not_assert: ['test'],
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
const receipt_id = computeReceiptId(body);
|
|
25
|
+
const canonical = canonicalizeJson(body);
|
|
26
|
+
const signature = createHmac('sha256', HMAC_SECRET).update(canonical).digest('hex');
|
|
27
|
+
return { ...body, receipt_id, signature, kid: 'duct-gateway-hs256-v1' };
|
|
28
|
+
}
|
|
29
|
+
describe('verifyEvidenceBundle', () => {
|
|
30
|
+
it('validates a minimal complete bundle', () => {
|
|
31
|
+
const receipt = minimalReceipt();
|
|
32
|
+
const result = verifyEvidenceBundle({
|
|
33
|
+
manifest: {
|
|
34
|
+
schema: 'duct:audit-evidence:v1',
|
|
35
|
+
bundle_id: 'b1',
|
|
36
|
+
exported_at: new Date().toISOString(),
|
|
37
|
+
shell_id: 'shell_test',
|
|
38
|
+
company_id: 'co_1',
|
|
39
|
+
profile: 'standard',
|
|
40
|
+
completeness: 'complete',
|
|
41
|
+
complete: true,
|
|
42
|
+
},
|
|
43
|
+
conversation: [],
|
|
44
|
+
evidence_events: [
|
|
45
|
+
{ stage: 'request_observed' },
|
|
46
|
+
{ stage: 'policy_decided' },
|
|
47
|
+
{ stage: 'upstream_dispatched' },
|
|
48
|
+
{ stage: 'upstream_completed' },
|
|
49
|
+
{ stage: 'response_delivered' },
|
|
50
|
+
],
|
|
51
|
+
receipts: [receipt],
|
|
52
|
+
redaction_ledger: [],
|
|
53
|
+
integrity: { valid: true, window_size: 1 },
|
|
54
|
+
}, { hmacSecret: HMAC_SECRET });
|
|
55
|
+
assert.equal(result.valid, true);
|
|
56
|
+
assert.equal(result.verified_receipts, 1);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type DuctProfileName = string;
|
|
2
|
+
export interface ServiceProfileUrls {
|
|
3
|
+
ductUrl?: string;
|
|
4
|
+
authUrl?: string;
|
|
5
|
+
apiUrl?: string;
|
|
6
|
+
shellUrl?: string;
|
|
7
|
+
registryUrl?: string;
|
|
8
|
+
dashboardUrl?: string;
|
|
9
|
+
docsUrl?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface DuctProfileFile {
|
|
12
|
+
active?: string;
|
|
13
|
+
profiles?: Record<string, ServiceProfileUrls>;
|
|
14
|
+
}
|
|
15
|
+
export declare const DEFAULT_PROFILE_NAME = "hosted";
|
|
16
|
+
/** Built-in URL presets — hosted leaves URLs empty so DUCT_URL derivation applies. */
|
|
17
|
+
export declare const BUILTIN_PROFILE_URLS: Record<string, ServiceProfileUrls>;
|
|
18
|
+
export declare function getDuctProfileFilePath(customPath?: string): string;
|
|
19
|
+
export declare function readProfileFileSync(profilePath?: string): DuctProfileFile | null;
|
|
20
|
+
export declare function writeProfileFileSync(file: DuctProfileFile, profilePath?: string): void;
|
|
21
|
+
export declare function listProfileNames(file?: DuctProfileFile | null): string[];
|
|
22
|
+
export declare function resolveActiveProfileName(file?: DuctProfileFile | null, env?: NodeJS.ProcessEnv): DuctProfileName;
|
|
23
|
+
export declare function resolveProfileUrls(profileName: string, file?: DuctProfileFile | null): ServiceProfileUrls;
|
|
24
|
+
export declare function applyProfileUrlsToEnv(profileName: string, options?: {
|
|
25
|
+
file?: DuctProfileFile | null;
|
|
26
|
+
env?: NodeJS.ProcessEnv;
|
|
27
|
+
/** Keys present in the shell environment before .env / profile loads — never overwritten. */
|
|
28
|
+
protectedKeys?: ReadonlySet<string>;
|
|
29
|
+
}): void;
|
|
30
|
+
/**
|
|
31
|
+
* Load ~/.duct/profile.json and apply the active profile's URLs to process.env.
|
|
32
|
+
* Returns the resolved active profile name.
|
|
33
|
+
*/
|
|
34
|
+
export declare function applyActiveProfileEnvSync(options?: {
|
|
35
|
+
profilePath?: string;
|
|
36
|
+
protectedKeys?: ReadonlySet<string>;
|
|
37
|
+
env?: NodeJS.ProcessEnv;
|
|
38
|
+
}): DuctProfileName;
|
|
39
|
+
export declare function setActiveProfileSync(profileName: string, options?: {
|
|
40
|
+
profilePath?: string;
|
|
41
|
+
}): DuctProfileFile;
|
|
42
|
+
export declare function ensureProfileExists(profileName: string, urls?: ServiceProfileUrls, options?: {
|
|
43
|
+
profilePath?: string;
|
|
44
|
+
}): DuctProfileFile;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// @duct/sdk — Platform profile discovery (SDK-01)
|
|
3
|
+
//
|
|
4
|
+
// Named profiles map service URLs for local vs hosted stacks.
|
|
5
|
+
// Resolution order for the active profile name:
|
|
6
|
+
// 1. DUCT_PROFILE env (shell wins over files)
|
|
7
|
+
// 2. ~/.duct/profile.json "active"
|
|
8
|
+
// 3. "hosted" (default)
|
|
9
|
+
//
|
|
10
|
+
// URL resolution per key (DUCT_URL, DUCT_API_URL, …):
|
|
11
|
+
// 1. Existing process.env (shell or project .env)
|
|
12
|
+
// 2. Active named profile in ~/.duct/profile.json
|
|
13
|
+
// 3. Built-in preset for local / hosted
|
|
14
|
+
// ============================================================
|
|
15
|
+
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import os from "node:os";
|
|
18
|
+
export const DEFAULT_PROFILE_NAME = "hosted";
|
|
19
|
+
/** Built-in URL presets — hosted leaves URLs empty so DUCT_URL derivation applies. */
|
|
20
|
+
export const BUILTIN_PROFILE_URLS = {
|
|
21
|
+
local: {
|
|
22
|
+
authUrl: "http://localhost:3001",
|
|
23
|
+
apiUrl: "http://localhost:3002",
|
|
24
|
+
shellUrl: "http://localhost:3000",
|
|
25
|
+
registryUrl: "http://localhost:3003",
|
|
26
|
+
dashboardUrl: "http://localhost:3004",
|
|
27
|
+
docsUrl: "http://localhost:3005/docs",
|
|
28
|
+
},
|
|
29
|
+
hosted: {},
|
|
30
|
+
};
|
|
31
|
+
const PROFILE_ENV_MAP = [
|
|
32
|
+
{ profileKey: "ductUrl", envKey: "DUCT_URL" },
|
|
33
|
+
{ profileKey: "authUrl", envKey: "DUCT_AUTH_URL" },
|
|
34
|
+
{ profileKey: "apiUrl", envKey: "DUCT_API_URL" },
|
|
35
|
+
{ profileKey: "shellUrl", envKey: "DUCT_SHELL_URL" },
|
|
36
|
+
{ profileKey: "registryUrl", envKey: "DUCT_REGISTRY_URL" },
|
|
37
|
+
{ profileKey: "dashboardUrl", envKey: "DUCT_DASHBOARD_URL" },
|
|
38
|
+
{ profileKey: "docsUrl", envKey: "DUCT_DOCS_URL" },
|
|
39
|
+
];
|
|
40
|
+
export function getDuctProfileFilePath(customPath) {
|
|
41
|
+
return customPath ?? path.join(os.homedir(), ".duct", "profile.json");
|
|
42
|
+
}
|
|
43
|
+
export function readProfileFileSync(profilePath) {
|
|
44
|
+
const filePath = getDuctProfileFilePath(profilePath);
|
|
45
|
+
try {
|
|
46
|
+
return JSON.parse(readFileSync(filePath, "utf8"));
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export function writeProfileFileSync(file, profilePath) {
|
|
53
|
+
const filePath = getDuctProfileFilePath(profilePath);
|
|
54
|
+
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
55
|
+
writeFileSync(filePath, `${JSON.stringify(file, null, 2)}\n`, "utf8");
|
|
56
|
+
}
|
|
57
|
+
export function listProfileNames(file) {
|
|
58
|
+
const names = new Set(Object.keys(BUILTIN_PROFILE_URLS));
|
|
59
|
+
if (file?.profiles) {
|
|
60
|
+
for (const name of Object.keys(file.profiles)) {
|
|
61
|
+
names.add(name);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return [...names].sort();
|
|
65
|
+
}
|
|
66
|
+
export function resolveActiveProfileName(file, env = process.env) {
|
|
67
|
+
const fromEnv = (env["DUCT_PROFILE"] ?? "").trim();
|
|
68
|
+
if (fromEnv)
|
|
69
|
+
return fromEnv;
|
|
70
|
+
const fromFile = (file?.active ?? "").trim();
|
|
71
|
+
if (fromFile)
|
|
72
|
+
return fromFile;
|
|
73
|
+
return DEFAULT_PROFILE_NAME;
|
|
74
|
+
}
|
|
75
|
+
export function resolveProfileUrls(profileName, file) {
|
|
76
|
+
const builtin = BUILTIN_PROFILE_URLS[profileName] ?? {};
|
|
77
|
+
const fromFile = file?.profiles?.[profileName] ?? {};
|
|
78
|
+
return { ...builtin, ...fromFile };
|
|
79
|
+
}
|
|
80
|
+
export function applyProfileUrlsToEnv(profileName, options) {
|
|
81
|
+
const env = options?.env ?? process.env;
|
|
82
|
+
const protectedKeys = options?.protectedKeys;
|
|
83
|
+
const urls = resolveProfileUrls(profileName, options?.file);
|
|
84
|
+
for (const { profileKey, envKey } of PROFILE_ENV_MAP) {
|
|
85
|
+
if (protectedKeys?.has(envKey))
|
|
86
|
+
continue;
|
|
87
|
+
if ((env[envKey] ?? "").trim())
|
|
88
|
+
continue;
|
|
89
|
+
const value = urls[profileKey];
|
|
90
|
+
if (value)
|
|
91
|
+
env[envKey] = value;
|
|
92
|
+
}
|
|
93
|
+
if (!protectedKeys?.has("DUCT_PROFILE") && !(env["DUCT_PROFILE"] ?? "").trim()) {
|
|
94
|
+
env["DUCT_PROFILE"] = profileName;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Load ~/.duct/profile.json and apply the active profile's URLs to process.env.
|
|
99
|
+
* Returns the resolved active profile name.
|
|
100
|
+
*/
|
|
101
|
+
export function applyActiveProfileEnvSync(options) {
|
|
102
|
+
const file = readProfileFileSync(options?.profilePath);
|
|
103
|
+
const profileName = resolveActiveProfileName(file, options?.env);
|
|
104
|
+
applyProfileUrlsToEnv(profileName, {
|
|
105
|
+
file,
|
|
106
|
+
env: options?.env,
|
|
107
|
+
protectedKeys: options?.protectedKeys,
|
|
108
|
+
});
|
|
109
|
+
return profileName;
|
|
110
|
+
}
|
|
111
|
+
export function setActiveProfileSync(profileName, options) {
|
|
112
|
+
const filePath = getDuctProfileFilePath(options?.profilePath);
|
|
113
|
+
const file = readProfileFileSync(filePath) ?? { profiles: {} };
|
|
114
|
+
file.active = profileName;
|
|
115
|
+
if (!file.profiles)
|
|
116
|
+
file.profiles = {};
|
|
117
|
+
writeProfileFileSync(file, filePath);
|
|
118
|
+
return file;
|
|
119
|
+
}
|
|
120
|
+
export function ensureProfileExists(profileName, urls = {}, options) {
|
|
121
|
+
const filePath = getDuctProfileFilePath(options?.profilePath);
|
|
122
|
+
const file = readProfileFileSync(filePath) ?? { profiles: {} };
|
|
123
|
+
if (!file.profiles)
|
|
124
|
+
file.profiles = {};
|
|
125
|
+
file.profiles[profileName] = { ...(file.profiles[profileName] ?? {}), ...urls };
|
|
126
|
+
writeProfileFileSync(file, filePath);
|
|
127
|
+
return file;
|
|
128
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, it, beforeEach, afterEach } from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { applyActiveProfileEnvSync, applyProfileUrlsToEnv, listProfileNames, readProfileFileSync, resolveActiveProfileName, resolveProfileUrls, setActiveProfileSync, writeProfileFileSync, } from "./profile.js";
|
|
7
|
+
const ORIGINAL_ENV = { ...process.env };
|
|
8
|
+
function restoreEnv() {
|
|
9
|
+
for (const key of Object.keys(process.env)) {
|
|
10
|
+
if (!(key in ORIGINAL_ENV))
|
|
11
|
+
delete process.env[key];
|
|
12
|
+
}
|
|
13
|
+
for (const [key, value] of Object.entries(ORIGINAL_ENV)) {
|
|
14
|
+
if (value === undefined)
|
|
15
|
+
delete process.env[key];
|
|
16
|
+
else
|
|
17
|
+
process.env[key] = value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
describe("profile discovery", () => {
|
|
21
|
+
let tempDir;
|
|
22
|
+
let profilePath;
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
tempDir = mkdtempSync(path.join(tmpdir(), "duct-profile-"));
|
|
25
|
+
profilePath = path.join(tempDir, "profile.json");
|
|
26
|
+
delete process.env.DUCT_PROFILE;
|
|
27
|
+
delete process.env.DUCT_URL;
|
|
28
|
+
delete process.env.DUCT_API_URL;
|
|
29
|
+
delete process.env.DUCT_AUTH_URL;
|
|
30
|
+
delete process.env.DUCT_SHELL_URL;
|
|
31
|
+
delete process.env.DUCT_DASHBOARD_URL;
|
|
32
|
+
delete process.env.DUCT_REGISTRY_URL;
|
|
33
|
+
delete process.env.DUCT_DOCS_URL;
|
|
34
|
+
});
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
restoreEnv();
|
|
37
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
38
|
+
});
|
|
39
|
+
it("defaults to hosted when no file or env", () => {
|
|
40
|
+
assert.equal(resolveActiveProfileName(null), "hosted");
|
|
41
|
+
});
|
|
42
|
+
it("reads active profile from file", () => {
|
|
43
|
+
writeProfileFileSync({ active: "local" }, profilePath);
|
|
44
|
+
const file = readProfileFileSync(profilePath);
|
|
45
|
+
assert.equal(resolveActiveProfileName(file), "local");
|
|
46
|
+
});
|
|
47
|
+
it("prefers DUCT_PROFILE env over file", () => {
|
|
48
|
+
process.env.DUCT_PROFILE = "staging";
|
|
49
|
+
writeProfileFileSync({ active: "local" }, profilePath);
|
|
50
|
+
const file = readProfileFileSync(profilePath);
|
|
51
|
+
assert.equal(resolveActiveProfileName(file), "staging");
|
|
52
|
+
});
|
|
53
|
+
it("applies local builtin URLs when profile is local", () => {
|
|
54
|
+
applyProfileUrlsToEnv("local");
|
|
55
|
+
assert.equal(process.env.DUCT_API_URL, "http://localhost:3002");
|
|
56
|
+
assert.equal(process.env.DUCT_AUTH_URL, "http://localhost:3001");
|
|
57
|
+
assert.equal(process.env.DUCT_PROFILE, "local");
|
|
58
|
+
});
|
|
59
|
+
it("merges custom profile URLs from file", () => {
|
|
60
|
+
writeProfileFileSync({
|
|
61
|
+
active: "staging",
|
|
62
|
+
profiles: {
|
|
63
|
+
staging: { ductUrl: "https://staging.acme.dev" },
|
|
64
|
+
},
|
|
65
|
+
}, profilePath);
|
|
66
|
+
const file = readProfileFileSync(profilePath);
|
|
67
|
+
const urls = resolveProfileUrls("staging", file);
|
|
68
|
+
assert.equal(urls.ductUrl, "https://staging.acme.dev");
|
|
69
|
+
});
|
|
70
|
+
it("does not override shell-protected env keys", () => {
|
|
71
|
+
process.env.DUCT_API_URL = "https://api.custom.test";
|
|
72
|
+
const protectedKeys = new Set(["DUCT_API_URL"]);
|
|
73
|
+
applyProfileUrlsToEnv("local", { protectedKeys });
|
|
74
|
+
assert.equal(process.env.DUCT_API_URL, "https://api.custom.test");
|
|
75
|
+
assert.equal(process.env.DUCT_AUTH_URL, "http://localhost:3001");
|
|
76
|
+
});
|
|
77
|
+
it("applyActiveProfileEnvSync loads file and applies URLs", () => {
|
|
78
|
+
writeProfileFileSync({ active: "local" }, profilePath);
|
|
79
|
+
const name = applyActiveProfileEnvSync({ profilePath });
|
|
80
|
+
assert.equal(name, "local");
|
|
81
|
+
assert.equal(process.env.DUCT_SHELL_URL, "http://localhost:3000");
|
|
82
|
+
});
|
|
83
|
+
it("lists builtin and custom profile names", () => {
|
|
84
|
+
writeProfileFileSync({ active: "local", profiles: { staging: { ductUrl: "https://x.test" } } }, profilePath);
|
|
85
|
+
const names = listProfileNames(readProfileFileSync(profilePath));
|
|
86
|
+
assert.ok(names.includes("local"));
|
|
87
|
+
assert.ok(names.includes("hosted"));
|
|
88
|
+
assert.ok(names.includes("staging"));
|
|
89
|
+
});
|
|
90
|
+
it("setActiveProfileSync updates active field", () => {
|
|
91
|
+
setActiveProfileSync("local", { profilePath });
|
|
92
|
+
const file = readProfileFileSync(profilePath);
|
|
93
|
+
assert.equal(file?.active, "local");
|
|
94
|
+
});
|
|
95
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const ReadinessCheckStatusSchema: z.ZodEnum<["pass", "fail", "warn", "skip"]>;
|
|
3
|
+
export declare const ReadinessCheckSchema: z.ZodObject<{
|
|
4
|
+
id: z.ZodString;
|
|
5
|
+
label: z.ZodString;
|
|
6
|
+
status: z.ZodEnum<["pass", "fail", "warn", "skip"]>;
|
|
7
|
+
message: z.ZodOptional<z.ZodString>;
|
|
8
|
+
url: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
status: "fail" | "pass" | "warn" | "skip";
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
message?: string | undefined;
|
|
14
|
+
url?: string | undefined;
|
|
15
|
+
}, {
|
|
16
|
+
status: "fail" | "pass" | "warn" | "skip";
|
|
17
|
+
id: string;
|
|
18
|
+
label: string;
|
|
19
|
+
message?: string | undefined;
|
|
20
|
+
url?: string | undefined;
|
|
21
|
+
}>;
|
|
22
|
+
export declare const ReadinessReportSchema: z.ZodObject<{
|
|
23
|
+
ok: z.ZodBoolean;
|
|
24
|
+
generatedAt: z.ZodString;
|
|
25
|
+
docsUrl: z.ZodOptional<z.ZodString>;
|
|
26
|
+
/** Marketing site status page — used by dashboard shell readiness. */
|
|
27
|
+
statusUrl: z.ZodOptional<z.ZodString>;
|
|
28
|
+
checks: z.ZodArray<z.ZodObject<{
|
|
29
|
+
id: z.ZodString;
|
|
30
|
+
label: z.ZodString;
|
|
31
|
+
status: z.ZodEnum<["pass", "fail", "warn", "skip"]>;
|
|
32
|
+
message: z.ZodOptional<z.ZodString>;
|
|
33
|
+
url: z.ZodOptional<z.ZodString>;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
status: "fail" | "pass" | "warn" | "skip";
|
|
36
|
+
id: string;
|
|
37
|
+
label: string;
|
|
38
|
+
message?: string | undefined;
|
|
39
|
+
url?: string | undefined;
|
|
40
|
+
}, {
|
|
41
|
+
status: "fail" | "pass" | "warn" | "skip";
|
|
42
|
+
id: string;
|
|
43
|
+
label: string;
|
|
44
|
+
message?: string | undefined;
|
|
45
|
+
url?: string | undefined;
|
|
46
|
+
}>, "many">;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
|
+
ok: boolean;
|
|
49
|
+
generatedAt: string;
|
|
50
|
+
checks: {
|
|
51
|
+
status: "fail" | "pass" | "warn" | "skip";
|
|
52
|
+
id: string;
|
|
53
|
+
label: string;
|
|
54
|
+
message?: string | undefined;
|
|
55
|
+
url?: string | undefined;
|
|
56
|
+
}[];
|
|
57
|
+
docsUrl?: string | undefined;
|
|
58
|
+
statusUrl?: string | undefined;
|
|
59
|
+
}, {
|
|
60
|
+
ok: boolean;
|
|
61
|
+
generatedAt: string;
|
|
62
|
+
checks: {
|
|
63
|
+
status: "fail" | "pass" | "warn" | "skip";
|
|
64
|
+
id: string;
|
|
65
|
+
label: string;
|
|
66
|
+
message?: string | undefined;
|
|
67
|
+
url?: string | undefined;
|
|
68
|
+
}[];
|
|
69
|
+
docsUrl?: string | undefined;
|
|
70
|
+
statusUrl?: string | undefined;
|
|
71
|
+
}>;
|
|
72
|
+
export type ReadinessCheckStatus = z.infer<typeof ReadinessCheckStatusSchema>;
|
|
73
|
+
export type ReadinessCheck = z.infer<typeof ReadinessCheckSchema>;
|
|
74
|
+
export type ReadinessReport = z.infer<typeof ReadinessReportSchema>;
|
|
75
|
+
export declare function readinessReportOk(checks: ReadinessCheck[]): boolean;
|
|
76
|
+
export interface HealthProbeResult {
|
|
77
|
+
ok: boolean;
|
|
78
|
+
status?: number;
|
|
79
|
+
error?: string;
|
|
80
|
+
}
|
|
81
|
+
export declare function probeHealth(url: string, timeoutMs?: number, fetchFn?: typeof fetch): Promise<HealthProbeResult>;
|
|
82
|
+
export declare function makeCheck(id: string, label: string, status: ReadinessCheckStatus, extras?: Pick<ReadinessCheck, 'message' | 'url'>): ReadinessCheck;
|
|
83
|
+
export interface CliReadinessEnv {
|
|
84
|
+
ductUrl?: string;
|
|
85
|
+
shellId?: string;
|
|
86
|
+
secretKey?: string;
|
|
87
|
+
authEmail?: string;
|
|
88
|
+
authSlug?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface CliReadinessEndpoints {
|
|
91
|
+
authHealthUrl: string;
|
|
92
|
+
apiHealthUrl: string;
|
|
93
|
+
shellHealthUrl: string;
|
|
94
|
+
dashboardHealthUrl: string;
|
|
95
|
+
docsUrl: string;
|
|
96
|
+
}
|
|
97
|
+
export interface CliReadinessOptions {
|
|
98
|
+
env: CliReadinessEnv;
|
|
99
|
+
endpoints: CliReadinessEndpoints;
|
|
100
|
+
probe?: (url: string) => Promise<HealthProbeResult>;
|
|
101
|
+
}
|
|
102
|
+
export declare function buildCliReadinessReport(options: CliReadinessOptions): Promise<ReadinessReport>;
|
|
103
|
+
export interface ReachabilityProbeResult {
|
|
104
|
+
/** True when any HTTP response was received (including 4xx/5xx). */
|
|
105
|
+
reachable: boolean;
|
|
106
|
+
status?: number;
|
|
107
|
+
error?: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Probe whether a URL accepts connections. Any HTTP response counts as reachable;
|
|
111
|
+
* only network errors / timeouts do not.
|
|
112
|
+
*/
|
|
113
|
+
export declare function probeReachable(url: string, timeoutMs?: number, fetchFn?: typeof fetch): Promise<ReachabilityProbeResult>;
|
|
114
|
+
/** Rewrite loopback hosts so a Dockerized probe can reach the operator's machine. */
|
|
115
|
+
export declare function rewriteLoopbackForDocker(url: string): string | null;
|
|
116
|
+
/**
|
|
117
|
+
* Probe a product base URL, retrying once via host.docker.internal when the
|
|
118
|
+
* configured host is loopback.
|
|
119
|
+
*/
|
|
120
|
+
export declare function probeProductBaseUrl(url: string, fetchFn?: typeof fetch): Promise<ReachabilityProbeResult>;
|
|
121
|
+
export interface ShellReadinessInput {
|
|
122
|
+
shellId: string;
|
|
123
|
+
manifestPushed: boolean;
|
|
124
|
+
productBaseUrl?: string;
|
|
125
|
+
actionCount: number;
|
|
126
|
+
recentMessages: number;
|
|
127
|
+
recentInvokeTurns: number;
|
|
128
|
+
statusUrl?: string;
|
|
129
|
+
probeProduct?: (url: string) => Promise<ReachabilityProbeResult>;
|
|
130
|
+
}
|
|
131
|
+
export declare function buildShellReadinessReport(input: ShellReadinessInput): Promise<ReadinessReport>;
|