sentinelayer-cli 0.6.2 → 0.8.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/README.md +1009 -996
- package/bin/create-sentinelayer.js +5 -5
- package/bin/sentinelayer-cli.js +4 -4
- package/bin/sl.js +5 -5
- package/package.json +64 -63
- package/src/agents/ai-governance/index.js +12 -0
- package/src/agents/ai-governance/tools/base.js +171 -0
- package/src/agents/ai-governance/tools/eval-regression.js +47 -0
- package/src/agents/ai-governance/tools/hitl-audit.js +81 -0
- package/src/agents/ai-governance/tools/index.js +52 -0
- package/src/agents/ai-governance/tools/prompt-drift.js +42 -0
- package/src/agents/ai-governance/tools/provenance-check.js +69 -0
- package/src/agents/backend/index.js +12 -0
- package/src/agents/backend/tools/base.js +189 -0
- package/src/agents/backend/tools/circuit-breaker-check.js +123 -0
- package/src/agents/backend/tools/idempotency-audit.js +105 -0
- package/src/agents/backend/tools/index.js +87 -0
- package/src/agents/backend/tools/retry-audit.js +132 -0
- package/src/agents/backend/tools/timeout-audit.js +144 -0
- package/src/agents/code-quality/index.js +12 -0
- package/src/agents/code-quality/tools/base.js +159 -0
- package/src/agents/code-quality/tools/complexity-measure.js +197 -0
- package/src/agents/code-quality/tools/coupling-analysis.js +81 -0
- package/src/agents/code-quality/tools/cycle-detect.js +49 -0
- package/src/agents/code-quality/tools/dep-graph.js +196 -0
- package/src/agents/code-quality/tools/index.js +89 -0
- package/src/agents/data-layer/index.js +12 -0
- package/src/agents/data-layer/tools/base.js +181 -0
- package/src/agents/data-layer/tools/index-audit.js +165 -0
- package/src/agents/data-layer/tools/index.js +83 -0
- package/src/agents/data-layer/tools/migration-scan.js +135 -0
- package/src/agents/data-layer/tools/query-explain.js +120 -0
- package/src/agents/data-layer/tools/tenancy-scan.js +166 -0
- package/src/agents/documentation/index.js +12 -0
- package/src/agents/documentation/tools/api-diff.js +91 -0
- package/src/agents/documentation/tools/base.js +151 -0
- package/src/agents/documentation/tools/dead-link-check.js +58 -0
- package/src/agents/documentation/tools/docstring-coverage.js +78 -0
- package/src/agents/documentation/tools/index.js +52 -0
- package/src/agents/documentation/tools/readme-freshness.js +61 -0
- package/src/agents/envelope/fix-cycle.js +45 -0
- package/src/agents/envelope/index.js +31 -0
- package/src/agents/envelope/loop.js +150 -0
- package/src/agents/envelope/pulse.js +18 -0
- package/src/agents/envelope/stream.js +40 -0
- package/src/agents/infrastructure/index.js +12 -0
- package/src/agents/infrastructure/tools/base.js +171 -0
- package/src/agents/infrastructure/tools/checkov-run.js +32 -0
- package/src/agents/infrastructure/tools/drift-detect.js +59 -0
- package/src/agents/infrastructure/tools/iam-least-priv-check.js +78 -0
- package/src/agents/infrastructure/tools/index.js +52 -0
- package/src/agents/infrastructure/tools/tflint-run.js +31 -0
- package/src/agents/jules/config/definition.js +160 -160
- package/src/agents/jules/config/system-prompt.js +182 -182
- package/src/agents/jules/error-intake.js +51 -51
- package/src/agents/jules/fix-cycle.js +17 -17
- package/src/agents/jules/loop.js +460 -450
- package/src/agents/jules/pulse.js +10 -10
- package/src/agents/jules/stream.js +187 -186
- package/src/agents/jules/swarm/file-scanner.js +74 -74
- package/src/agents/jules/swarm/index.js +11 -11
- package/src/agents/jules/swarm/orchestrator.js +362 -362
- package/src/agents/jules/swarm/pattern-hunter.js +123 -123
- package/src/agents/jules/swarm/sub-agent.js +315 -309
- package/src/agents/jules/tools/aidenid-email.js +189 -189
- package/src/agents/jules/tools/auth-audit.js +1708 -1691
- package/src/agents/jules/tools/dispatch.js +340 -335
- package/src/agents/jules/tools/file-edit.js +2 -2
- package/src/agents/jules/tools/file-read.js +2 -2
- package/src/agents/jules/tools/frontend-analyze.js +570 -570
- package/src/agents/jules/tools/glob.js +2 -2
- package/src/agents/jules/tools/grep.js +2 -2
- package/src/agents/jules/tools/index.js +29 -29
- package/src/agents/jules/tools/path-guards.js +2 -2
- package/src/agents/jules/tools/runtime-audit.js +507 -507
- package/src/agents/jules/tools/shell.js +2 -2
- package/src/agents/jules/tools/url-policy.js +100 -100
- package/src/agents/mode.js +113 -0
- package/src/agents/observability/index.js +12 -0
- package/src/agents/observability/tools/alert-audit.js +39 -0
- package/src/agents/observability/tools/base.js +181 -0
- package/src/agents/observability/tools/dashboard-gap.js +42 -0
- package/src/agents/observability/tools/index.js +54 -0
- package/src/agents/observability/tools/log-schema-check.js +74 -0
- package/src/agents/observability/tools/span-coverage.js +74 -0
- package/src/agents/persona-visuals.js +102 -61
- package/src/agents/release/index.js +12 -0
- package/src/agents/release/tools/base.js +181 -0
- package/src/agents/release/tools/changelog-diff.js +86 -0
- package/src/agents/release/tools/feature-flag-audit.js +126 -0
- package/src/agents/release/tools/index.js +61 -0
- package/src/agents/release/tools/rollback-verify.js +129 -0
- package/src/agents/release/tools/semver-check.js +109 -0
- package/src/agents/reliability/index.js +12 -0
- package/src/agents/reliability/tools/backpressure-check.js +129 -0
- package/src/agents/reliability/tools/base.js +181 -0
- package/src/agents/reliability/tools/chaos-probe.js +109 -0
- package/src/agents/reliability/tools/graceful-degradation-check.js +114 -0
- package/src/agents/reliability/tools/health-check-audit.js +111 -0
- package/src/agents/reliability/tools/index.js +87 -0
- package/src/agents/run-persona.js +109 -0
- package/src/agents/security/index.js +12 -0
- package/src/agents/security/tools/authz-audit.js +134 -0
- package/src/agents/security/tools/base.js +190 -0
- package/src/agents/security/tools/crypto-review.js +175 -0
- package/src/agents/security/tools/index.js +97 -0
- package/src/agents/security/tools/sast-scan.js +175 -0
- package/src/agents/security/tools/secrets-scan.js +216 -0
- package/src/agents/shared-tools/dispatch-core.js +320 -315
- package/src/agents/shared-tools/file-edit.js +180 -180
- package/src/agents/shared-tools/file-read.js +100 -100
- package/src/agents/shared-tools/glob.js +168 -168
- package/src/agents/shared-tools/grep.js +228 -228
- package/src/agents/shared-tools/index.js +46 -46
- package/src/agents/shared-tools/path-guards.js +161 -161
- package/src/agents/shared-tools/shell.js +383 -383
- package/src/agents/supply-chain/index.js +12 -0
- package/src/agents/supply-chain/tools/attestation-check.js +42 -0
- package/src/agents/supply-chain/tools/base.js +151 -0
- package/src/agents/supply-chain/tools/index.js +52 -0
- package/src/agents/supply-chain/tools/lockfile-integrity.js +73 -0
- package/src/agents/supply-chain/tools/package-verify.js +56 -0
- package/src/agents/supply-chain/tools/sbom-diff.js +34 -0
- package/src/agents/testing/index.js +12 -0
- package/src/agents/testing/tools/base.js +202 -0
- package/src/agents/testing/tools/coverage-gap.js +144 -0
- package/src/agents/testing/tools/flake-detect.js +125 -0
- package/src/agents/testing/tools/index.js +85 -0
- package/src/agents/testing/tools/mutation-test.js +143 -0
- package/src/agents/testing/tools/snapshot-diff.js +103 -0
- package/src/ai/aidenid.js +1021 -1009
- package/src/ai/client.js +553 -553
- package/src/ai/domain-target-store.js +268 -268
- package/src/ai/identity-store.js +270 -270
- package/src/ai/proxy.js +137 -137
- package/src/ai/site-store.js +145 -145
- package/src/audit/agents/architecture.js +180 -180
- package/src/audit/agents/compliance.js +179 -179
- package/src/audit/agents/documentation.js +165 -165
- package/src/audit/agents/performance.js +145 -145
- package/src/audit/agents/security.js +215 -215
- package/src/audit/agents/testing.js +172 -172
- package/src/audit/orchestrator.js +557 -557
- package/src/audit/package.js +204 -204
- package/src/audit/registry.js +284 -284
- package/src/audit/replay.js +103 -103
- package/src/auth/gate.js +428 -371
- package/src/auth/http.js +681 -611
- package/src/auth/service.js +1106 -1106
- package/src/auth/session-store.js +813 -813
- package/src/cli.js +257 -252
- package/src/commands/ai/identity-lifecycle.js +1338 -1338
- package/src/commands/ai/provision-governance.js +1272 -1272
- package/src/commands/ai/shared.js +147 -147
- package/src/commands/ai.js +11 -11
- package/src/commands/apply.js +12 -12
- package/src/commands/audit.js +1171 -1166
- package/src/commands/auth.js +419 -419
- package/src/commands/chat.js +184 -191
- package/src/commands/config.js +184 -184
- package/src/commands/cost.js +311 -311
- package/src/commands/daemon/core.js +850 -850
- package/src/commands/daemon/extended.js +1048 -1048
- package/src/commands/daemon/shared.js +213 -213
- package/src/commands/daemon.js +11 -11
- package/src/commands/guide.js +174 -174
- package/src/commands/ingest.js +58 -58
- package/src/commands/init.js +55 -55
- package/src/commands/legacy-args.js +20 -10
- package/src/commands/mcp.js +461 -461
- package/src/commands/omargate.js +63 -29
- package/src/commands/persona.js +65 -20
- package/src/commands/plugin.js +260 -260
- package/src/commands/policy.js +132 -132
- package/src/commands/prompt.js +238 -238
- package/src/commands/review.js +704 -704
- package/src/commands/scan.js +865 -872
- package/src/commands/session.js +1238 -0
- package/src/commands/spec.js +771 -716
- package/src/commands/swarm.js +651 -651
- package/src/commands/telemetry.js +202 -202
- package/src/commands/watch.js +511 -511
- package/src/config/agent-dictionary.js +182 -182
- package/src/config/io.js +56 -56
- package/src/config/paths.js +18 -18
- package/src/config/schema.js +55 -55
- package/src/config/service.js +184 -184
- package/src/coord/events-log.js +141 -0
- package/src/coord/handshake.js +719 -0
- package/src/coord/index.js +35 -0
- package/src/coord/paths.js +84 -0
- package/src/coord/priority.js +62 -0
- package/src/coord/tarjan.js +157 -0
- package/src/cost/budget.js +235 -235
- package/src/cost/history.js +188 -188
- package/src/cost/tokenizer.js +160 -0
- package/src/cost/tracker.js +232 -171
- package/src/daemon/artifact-lineage.js +896 -534
- package/src/daemon/assignment-ledger.js +1083 -770
- package/src/daemon/ast-drift.js +496 -0
- package/src/daemon/ast-parser-layer.js +258 -258
- package/src/daemon/budget-governor.js +633 -633
- package/src/daemon/callgraph-overlay.js +646 -646
- package/src/daemon/error-worker.js +1209 -626
- package/src/daemon/fix-cycle.js +384 -377
- package/src/daemon/hybrid-mapper.js +929 -929
- package/src/daemon/ingest-refresh.js +79 -11
- package/src/daemon/jira-lifecycle.js +767 -632
- package/src/daemon/operator-control.js +657 -657
- package/src/daemon/pulse.js +327 -327
- package/src/daemon/reliability-lane.js +471 -471
- package/src/daemon/scope-engine.js +1068 -0
- package/src/daemon/watchdog.js +971 -971
- package/src/events/schema.js +190 -0
- package/src/guide/generator.js +316 -316
- package/src/ingest/engine.js +933 -918
- package/src/ingest/ownership.js +380 -0
- package/src/interactive/index.js +97 -97
- package/src/legacy-cli.js +3228 -2994
- package/src/mcp/registry.js +695 -695
- package/src/memory/blackboard.js +301 -301
- package/src/memory/retrieval.js +581 -581
- package/src/orchestrator/kai-chen.js +126 -0
- package/src/plugin/manifest.js +553 -553
- package/src/policy/packs.js +144 -144
- package/src/prompt/generator.js +136 -118
- package/src/review/ai-review.js +672 -679
- package/src/review/compliance-pack.js +389 -0
- package/src/review/investor-dd-config.js +54 -0
- package/src/review/investor-dd-file-loop.js +303 -0
- package/src/review/investor-dd-file-router.js +406 -0
- package/src/review/investor-dd-html-report.js +233 -0
- package/src/review/investor-dd-notification.js +120 -0
- package/src/review/investor-dd-orchestrator.js +405 -0
- package/src/review/investor-dd-persona-runner.js +275 -0
- package/src/review/live-validator.js +253 -0
- package/src/review/local-review.js +1351 -1305
- package/src/review/omargate-interactive.js +68 -68
- package/src/review/omargate-orchestrator.js +492 -300
- package/src/review/persona-prompts.js +484 -296
- package/src/review/reconciliation-rules.js +329 -0
- package/src/review/replay.js +235 -235
- package/src/review/report.js +664 -664
- package/src/review/reproducibility-chain.js +136 -0
- package/src/review/scan-modes.js +147 -42
- package/src/review/spec-binding.js +487 -487
- package/src/scaffold/generator.js +67 -67
- package/src/scaffold/templates.js +150 -150
- package/src/scan/generator.js +418 -418
- package/src/scan/gh-secrets.js +107 -107
- package/src/session/agent-registry.js +359 -0
- package/src/session/analytics.js +479 -0
- package/src/session/daemon.js +1396 -0
- package/src/session/file-locks.js +666 -0
- package/src/session/paths.js +37 -0
- package/src/session/recap.js +567 -0
- package/src/session/redact.js +82 -0
- package/src/session/runtime-bridge.js +762 -0
- package/src/session/scoring.js +406 -0
- package/src/session/setup-guides.js +304 -0
- package/src/session/store.js +704 -0
- package/src/session/stream.js +333 -0
- package/src/session/sync.js +753 -0
- package/src/session/tasks.js +1054 -0
- package/src/session/templates.js +188 -0
- package/src/spec/generator.js +619 -519
- package/src/spec/regenerate.js +237 -237
- package/src/spec/templates.js +91 -91
- package/src/swarm/dashboard.js +247 -247
- package/src/swarm/factory.js +363 -363
- package/src/swarm/pentest.js +934 -934
- package/src/swarm/registry.js +419 -419
- package/src/swarm/report.js +158 -158
- package/src/swarm/runtime.js +569 -576
- package/src/swarm/scenario-dsl.js +272 -272
- package/src/telemetry/ledger.js +302 -302
- package/src/telemetry/session-tracker.js +234 -234
- package/src/telemetry/sync.js +203 -203
- package/src/ui/command-hints.js +13 -13
- package/src/ui/markdown.js +220 -220
|
@@ -1,1272 +1,1272 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import process from "node:process";
|
|
3
|
-
|
|
4
|
-
import pc from "picocolors";
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
buildProvisionEmailPayload,
|
|
8
|
-
createDomain,
|
|
9
|
-
createTemporarySite,
|
|
10
|
-
createTarget,
|
|
11
|
-
freezeDomain,
|
|
12
|
-
getTarget,
|
|
13
|
-
normalizeAidenIdApiUrl,
|
|
14
|
-
provisionEmailIdentity,
|
|
15
|
-
resolveAidenIdCredentials,
|
|
16
|
-
verifyDomain,
|
|
17
|
-
verifyTarget,
|
|
18
|
-
} from "../../ai/aidenid.js";
|
|
19
|
-
import {
|
|
20
|
-
getDomainById,
|
|
21
|
-
getTargetById as getTrackedTargetById,
|
|
22
|
-
recordDomainProofResponse,
|
|
23
|
-
recordTargetProofResponse,
|
|
24
|
-
} from "../../ai/domain-target-store.js";
|
|
25
|
-
import { listSites, recordTemporarySite } from "../../ai/site-store.js";
|
|
26
|
-
import { getIdentityById, recordProvisionedIdentity } from "../../ai/identity-store.js";
|
|
27
|
-
import { resolveOutputRoot } from "../../config/service.js";
|
|
28
|
-
import { readStoredSession } from "../../auth/session-store.js";
|
|
29
|
-
import { fetchAidenIdCredentials } from "../../auth/service.js";
|
|
30
|
-
import {
|
|
31
|
-
buildCurlPreview,
|
|
32
|
-
normalizeIdempotencyKey,
|
|
33
|
-
parseCsvTokens,
|
|
34
|
-
parseJsonObject,
|
|
35
|
-
parsePositiveInteger,
|
|
36
|
-
shouldEmitJson,
|
|
37
|
-
stableTimestampForFile,
|
|
38
|
-
writeArtifact,
|
|
39
|
-
} from "./shared.js";
|
|
40
|
-
|
|
41
|
-
function addProvisionEmailOptions(cmd) {
|
|
42
|
-
return cmd
|
|
43
|
-
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
44
|
-
.option("--output-dir <path>", "Optional artifact output root override")
|
|
45
|
-
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
46
|
-
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
47
|
-
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
48
|
-
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
49
|
-
.option("--alias-template <value>", "Optional alias template")
|
|
50
|
-
.option("--ttl-hours <hours>", "Identity TTL in hours", "24")
|
|
51
|
-
.option("--tags <csv>", "Comma-separated tags")
|
|
52
|
-
.option("--domain-pool-id <id>", "Optional domain pool id")
|
|
53
|
-
.option("--receive-mode <mode>", "Identity receive mode", "EDGE_ACCEPT")
|
|
54
|
-
.option("--extraction-types <csv>", "Comma-separated extraction types", "otp,link")
|
|
55
|
-
.option("--allow-webhooks", "Allow webhook delivery", true)
|
|
56
|
-
.option("--no-allow-webhooks", "Disable webhook delivery")
|
|
57
|
-
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
58
|
-
.option("--execute", "Execute live API call (default is dry-run artifact generation)")
|
|
59
|
-
.option("--json", "Emit machine-readable output");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async function provisionEmailAction(options, command) {
|
|
63
|
-
const emitJson = shouldEmitJson(options, command);
|
|
64
|
-
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
65
|
-
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
66
|
-
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
67
|
-
const ttlHours = parsePositiveInteger(options.ttlHours, "ttlHours", 24);
|
|
68
|
-
|
|
69
|
-
const payload = buildProvisionEmailPayload({
|
|
70
|
-
aliasTemplate: options.aliasTemplate,
|
|
71
|
-
ttlHours,
|
|
72
|
-
tags: options.tags,
|
|
73
|
-
domainPoolId: options.domainPoolId,
|
|
74
|
-
receiveMode: options.receiveMode,
|
|
75
|
-
allowWebhooks: Boolean(options.allowWebhooks),
|
|
76
|
-
extractionTypes: options.extractionTypes,
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const outputRoot = await resolveOutputRoot({
|
|
80
|
-
cwd: targetPath,
|
|
81
|
-
outputDirOverride: options.outputDir,
|
|
82
|
-
env: process.env,
|
|
83
|
-
});
|
|
84
|
-
const artifactsDir = path.join(outputRoot, "aidenid", "provision-email");
|
|
85
|
-
const stamp = stableTimestampForFile();
|
|
86
|
-
const requestPath = path.join(artifactsDir, `request-${stamp}.json`);
|
|
87
|
-
|
|
88
|
-
await writeArtifact(requestPath, {
|
|
89
|
-
generatedAt: new Date().toISOString(),
|
|
90
|
-
apiUrl,
|
|
91
|
-
idempotencyKey,
|
|
92
|
-
payload,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
let session = null;
|
|
96
|
-
try { session = await readStoredSession(); } catch { /* no session */ }
|
|
97
|
-
|
|
98
|
-
const makeFetcher = () => {
|
|
99
|
-
if (!session || !session.token) return null;
|
|
100
|
-
return () => fetchAidenIdCredentials({ apiUrl: session.apiUrl, token: session.token });
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
104
|
-
apiKey: options.apiKey,
|
|
105
|
-
orgId: options.orgId,
|
|
106
|
-
projectId: options.projectId,
|
|
107
|
-
env: process.env,
|
|
108
|
-
requireAll: false,
|
|
109
|
-
session,
|
|
110
|
-
fetchCredentials: makeFetcher(),
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
if (!options.execute) {
|
|
114
|
-
const result = {
|
|
115
|
-
command: "ai provision-email",
|
|
116
|
-
execute: false,
|
|
117
|
-
apiUrl,
|
|
118
|
-
idempotencyKey,
|
|
119
|
-
requestPath,
|
|
120
|
-
credentialsMissing: resolvedCredentials.missing,
|
|
121
|
-
curlPreview: buildCurlPreview({
|
|
122
|
-
apiUrl,
|
|
123
|
-
idempotencyKey,
|
|
124
|
-
requestPath,
|
|
125
|
-
}),
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
if (emitJson) {
|
|
129
|
-
console.log(JSON.stringify(result, null, 2));
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
console.log(pc.bold("AIdenID provision request artifact created (dry-run)"));
|
|
134
|
-
console.log(pc.gray(`Request: ${requestPath}`));
|
|
135
|
-
console.log(pc.gray(`API: ${apiUrl}`));
|
|
136
|
-
console.log(pc.gray(`Idempotency-Key: ${idempotencyKey}`));
|
|
137
|
-
if (resolvedCredentials.missing.length > 0) {
|
|
138
|
-
console.log(
|
|
139
|
-
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
console.log(pc.gray("Execute preview:"));
|
|
143
|
-
console.log(result.curlPreview);
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const requiredCredentials = await resolveAidenIdCredentials({
|
|
148
|
-
apiKey: options.apiKey,
|
|
149
|
-
orgId: options.orgId,
|
|
150
|
-
projectId: options.projectId,
|
|
151
|
-
env: process.env,
|
|
152
|
-
requireAll: true,
|
|
153
|
-
session,
|
|
154
|
-
fetchCredentials: makeFetcher(),
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
const execution = await provisionEmailIdentity({
|
|
158
|
-
apiUrl,
|
|
159
|
-
apiKey: requiredCredentials.apiKey,
|
|
160
|
-
orgId: requiredCredentials.orgId,
|
|
161
|
-
projectId: requiredCredentials.projectId,
|
|
162
|
-
idempotencyKey,
|
|
163
|
-
payload,
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const responsePath = path.join(artifactsDir, `response-${stamp}.json`);
|
|
167
|
-
await writeArtifact(responsePath, {
|
|
168
|
-
receivedAt: new Date().toISOString(),
|
|
169
|
-
apiUrl,
|
|
170
|
-
idempotencyKey,
|
|
171
|
-
response: execution.response,
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
const responseIdentity = execution.response || {};
|
|
175
|
-
const registryUpdate = await recordProvisionedIdentity({
|
|
176
|
-
outputRoot,
|
|
177
|
-
response: execution.response || {},
|
|
178
|
-
context: {
|
|
179
|
-
apiUrl,
|
|
180
|
-
orgId: requiredCredentials.orgId,
|
|
181
|
-
projectId: requiredCredentials.projectId,
|
|
182
|
-
idempotencyKey,
|
|
183
|
-
tags: payload.tags,
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
const result = {
|
|
187
|
-
command: "ai provision-email",
|
|
188
|
-
execute: true,
|
|
189
|
-
apiUrl,
|
|
190
|
-
idempotencyKey,
|
|
191
|
-
requestPath,
|
|
192
|
-
responsePath,
|
|
193
|
-
identity: {
|
|
194
|
-
id: String(responseIdentity.id || "").trim() || null,
|
|
195
|
-
emailAddress: String(responseIdentity.emailAddress || "").trim() || null,
|
|
196
|
-
status: String(responseIdentity.status || "").trim() || null,
|
|
197
|
-
expiresAt: responseIdentity.expiresAt || null,
|
|
198
|
-
projectId: responseIdentity.projectId || null,
|
|
199
|
-
},
|
|
200
|
-
response: execution.response,
|
|
201
|
-
identityRegistryPath: registryUpdate.registryPath,
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
if (emitJson) {
|
|
205
|
-
console.log(JSON.stringify(result, null, 2));
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
console.log(pc.bold("AIdenID identity provisioned"));
|
|
210
|
-
console.log(pc.gray(`Request: ${requestPath}`));
|
|
211
|
-
console.log(pc.gray(`Response: ${responsePath}`));
|
|
212
|
-
if (result.identity.id || result.identity.emailAddress) {
|
|
213
|
-
console.log(
|
|
214
|
-
pc.green(
|
|
215
|
-
`${result.identity.id || "unknown-id"} | ${result.identity.emailAddress || "unknown-email"} | ${
|
|
216
|
-
result.identity.status || "unknown-status"
|
|
217
|
-
}`
|
|
218
|
-
)
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
export function registerAiProvisionAndGovernanceCommands(ai) {
|
|
224
|
-
addProvisionEmailOptions(
|
|
225
|
-
ai.command("provision-email")
|
|
226
|
-
.alias("provision")
|
|
227
|
-
.description("Provision an AIdenID identity payload (dry-run by default, optional live execute)")
|
|
228
|
-
).action(provisionEmailAction);
|
|
229
|
-
|
|
230
|
-
const identity = ai.command("identity").description("AIdenID identity lifecycle commands");
|
|
231
|
-
|
|
232
|
-
addProvisionEmailOptions(
|
|
233
|
-
identity.command("provision")
|
|
234
|
-
.description("Provision an AIdenID identity (alias for 'sl ai provision-email')")
|
|
235
|
-
).action(provisionEmailAction);
|
|
236
|
-
const domain = identity.command("domain").description("AIdenID domain governance commands");
|
|
237
|
-
const target = identity.command("target").description("AIdenID target governance commands");
|
|
238
|
-
const site = identity.command("site").description("AIdenID temporary callback domain commands");
|
|
239
|
-
const legalHold = identity.command("legal-hold").description("Identity legal-hold controls");
|
|
240
|
-
|
|
241
|
-
domain
|
|
242
|
-
.command("create")
|
|
243
|
-
.description("Create a domain registration and proof challenge (dry-run by default)")
|
|
244
|
-
.argument("<domainName>", "Domain hostname")
|
|
245
|
-
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
246
|
-
.option("--output-dir <path>", "Optional artifact output root override")
|
|
247
|
-
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
248
|
-
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
249
|
-
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
250
|
-
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
251
|
-
.option("--trust-class <value>", "Domain trust class", "BYOD")
|
|
252
|
-
.option("--verification-method <value>", "Domain verification method", "DNS_TXT")
|
|
253
|
-
.option("--challenge-value <value>", "Explicit challenge value override")
|
|
254
|
-
.option("--proof-ttl-hours <hours>", "Proof TTL hours", "24")
|
|
255
|
-
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
256
|
-
.option("--execute", "Execute live API call")
|
|
257
|
-
.option("--json", "Emit machine-readable output")
|
|
258
|
-
.action(async (domainName, options, command) => {
|
|
259
|
-
const emitJson = shouldEmitJson(options, command);
|
|
260
|
-
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
261
|
-
const outputRoot = await resolveOutputRoot({
|
|
262
|
-
cwd: targetPath,
|
|
263
|
-
outputDirOverride: options.outputDir,
|
|
264
|
-
env: process.env,
|
|
265
|
-
});
|
|
266
|
-
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
267
|
-
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
268
|
-
const proofTtlHours = parsePositiveInteger(options.proofTtlHours, "proofTtlHours", 24);
|
|
269
|
-
const payload = {
|
|
270
|
-
domainName: String(domainName || "").trim(),
|
|
271
|
-
trustClass: String(options.trustClass || "BYOD").trim() || "BYOD",
|
|
272
|
-
verificationMethod:
|
|
273
|
-
String(options.verificationMethod || "DNS_TXT").trim() || "DNS_TXT",
|
|
274
|
-
challengeValue: String(options.challengeValue || "").trim() || null,
|
|
275
|
-
proofTtlHours,
|
|
276
|
-
};
|
|
277
|
-
if (!payload.domainName) {
|
|
278
|
-
throw new Error("domainName is required.");
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const artifactsDir = path.join(outputRoot, "aidenid", "domain-create");
|
|
282
|
-
const stamp = stableTimestampForFile();
|
|
283
|
-
const requestPath = path.join(artifactsDir, `request-${encodeURIComponent(payload.domainName)}-${stamp}.json`);
|
|
284
|
-
await writeArtifact(requestPath, {
|
|
285
|
-
generatedAt: new Date().toISOString(),
|
|
286
|
-
apiUrl,
|
|
287
|
-
idempotencyKey,
|
|
288
|
-
payload,
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
292
|
-
apiKey: options.apiKey,
|
|
293
|
-
orgId: options.orgId,
|
|
294
|
-
projectId: options.projectId,
|
|
295
|
-
env: process.env,
|
|
296
|
-
requireAll: false,
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
if (!options.execute) {
|
|
300
|
-
const result = {
|
|
301
|
-
command: "ai identity domain create",
|
|
302
|
-
execute: false,
|
|
303
|
-
apiUrl,
|
|
304
|
-
idempotencyKey,
|
|
305
|
-
requestPath,
|
|
306
|
-
payload,
|
|
307
|
-
credentialsMissing: resolvedCredentials.missing,
|
|
308
|
-
curlPreview: [
|
|
309
|
-
`curl -X POST ${apiUrl}/v1/domains \\`,
|
|
310
|
-
` -H \"Authorization: Bearer $AIDENID_API_KEY\" \\`,
|
|
311
|
-
` -H \"X-Org-Id: $AIDENID_ORG_ID\" \\`,
|
|
312
|
-
` -H \"X-Project-Id: $AIDENID_PROJECT_ID\" \\`,
|
|
313
|
-
` -H \"Idempotency-Key: ${idempotencyKey}\" \\`,
|
|
314
|
-
` -H \"Content-Type: application/json\" \\`,
|
|
315
|
-
` --data @${String(requestPath || "").replace(/\\/g, "/")}`,
|
|
316
|
-
].join("\n"),
|
|
317
|
-
};
|
|
318
|
-
if (emitJson) {
|
|
319
|
-
console.log(JSON.stringify(result, null, 2));
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
console.log(pc.bold("AIdenID domain create artifact generated (dry-run)"));
|
|
323
|
-
console.log(pc.gray(`Request: ${requestPath}`));
|
|
324
|
-
if (resolvedCredentials.missing.length > 0) {
|
|
325
|
-
console.log(
|
|
326
|
-
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
327
|
-
);
|
|
328
|
-
}
|
|
329
|
-
console.log(result.curlPreview);
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
const requiredCredentials = await resolveAidenIdCredentials({
|
|
334
|
-
apiKey: options.apiKey,
|
|
335
|
-
orgId: options.orgId,
|
|
336
|
-
projectId: options.projectId,
|
|
337
|
-
env: process.env,
|
|
338
|
-
requireAll: true,
|
|
339
|
-
});
|
|
340
|
-
const execution = await createDomain({
|
|
341
|
-
apiUrl,
|
|
342
|
-
apiKey: requiredCredentials.apiKey,
|
|
343
|
-
orgId: requiredCredentials.orgId,
|
|
344
|
-
projectId: requiredCredentials.projectId,
|
|
345
|
-
idempotencyKey,
|
|
346
|
-
payload,
|
|
347
|
-
});
|
|
348
|
-
const responsePath = path.join(
|
|
349
|
-
artifactsDir,
|
|
350
|
-
`response-${encodeURIComponent(payload.domainName)}-${stamp}.json`
|
|
351
|
-
);
|
|
352
|
-
await writeArtifact(responsePath, {
|
|
353
|
-
receivedAt: new Date().toISOString(),
|
|
354
|
-
apiUrl,
|
|
355
|
-
idempotencyKey,
|
|
356
|
-
response: execution.response,
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
const proofResponse = execution.response || {};
|
|
360
|
-
const registryUpdate = await recordDomainProofResponse({
|
|
361
|
-
outputRoot,
|
|
362
|
-
domain: proofResponse.domain || {},
|
|
363
|
-
proof: proofResponse,
|
|
364
|
-
context: {
|
|
365
|
-
source: "domain-create",
|
|
366
|
-
idempotencyKey,
|
|
367
|
-
projectId: requiredCredentials.projectId,
|
|
368
|
-
},
|
|
369
|
-
});
|
|
370
|
-
const result = {
|
|
371
|
-
command: "ai identity domain create",
|
|
372
|
-
execute: true,
|
|
373
|
-
apiUrl,
|
|
374
|
-
idempotencyKey,
|
|
375
|
-
requestPath,
|
|
376
|
-
responsePath,
|
|
377
|
-
domain: proofResponse.domain || null,
|
|
378
|
-
proof: {
|
|
379
|
-
proofId: proofResponse.proofId || null,
|
|
380
|
-
challengeValue: proofResponse.challengeValue || null,
|
|
381
|
-
proofStatus: proofResponse.proofStatus || null,
|
|
382
|
-
proofExpiresAt: proofResponse.proofExpiresAt || null,
|
|
383
|
-
},
|
|
384
|
-
registryPath: registryUpdate.registryPath,
|
|
385
|
-
};
|
|
386
|
-
if (emitJson) {
|
|
387
|
-
console.log(JSON.stringify(result, null, 2));
|
|
388
|
-
return;
|
|
389
|
-
}
|
|
390
|
-
console.log(pc.bold("AIdenID domain created"));
|
|
391
|
-
console.log(pc.gray(`Response: ${responsePath}`));
|
|
392
|
-
console.log(
|
|
393
|
-
`${String(result.domain?.id || "unknown-domain")} | ${String(result.domain?.domainName || payload.domainName)}`
|
|
394
|
-
);
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
domain
|
|
398
|
-
.command("verify")
|
|
399
|
-
.description("Verify domain proof challenge (dry-run by default)")
|
|
400
|
-
.argument("<domainId>", "Domain id")
|
|
401
|
-
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
402
|
-
.option("--output-dir <path>", "Optional artifact output root override")
|
|
403
|
-
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
404
|
-
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
405
|
-
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
406
|
-
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
407
|
-
.option("--method <value>", "Verification method", "DNS_TXT")
|
|
408
|
-
.option("--challenge-value <value>", "Challenge value override (fallback: local registry)")
|
|
409
|
-
.option("--proof-value <value>", "Proof value", "txt-verification-record")
|
|
410
|
-
.option("--verification-source <value>", "Verification source", "sentinelayer-cli")
|
|
411
|
-
.option("--expires-hours <hours>", "Proof expiration in hours", "24")
|
|
412
|
-
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
413
|
-
.option("--execute", "Execute live API call")
|
|
414
|
-
.option("--json", "Emit machine-readable output")
|
|
415
|
-
.action(async (domainId, options, command) => {
|
|
416
|
-
const emitJson = shouldEmitJson(options, command);
|
|
417
|
-
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
418
|
-
const outputRoot = await resolveOutputRoot({
|
|
419
|
-
cwd: targetPath,
|
|
420
|
-
outputDirOverride: options.outputDir,
|
|
421
|
-
env: process.env,
|
|
422
|
-
});
|
|
423
|
-
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
424
|
-
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
425
|
-
const tracked = await getDomainById({ outputRoot, domainId });
|
|
426
|
-
const challengeValue =
|
|
427
|
-
String(options.challengeValue || "").trim() ||
|
|
428
|
-
String(tracked.domain?.challengeValue || "").trim() ||
|
|
429
|
-
null;
|
|
430
|
-
if (!challengeValue) {
|
|
431
|
-
throw new Error(
|
|
432
|
-
`challengeValue is required. Provide --challenge-value or run domain create first for '${domainId}'.`
|
|
433
|
-
);
|
|
434
|
-
}
|
|
435
|
-
const payload = {
|
|
436
|
-
method: String(options.method || "DNS_TXT").trim() || "DNS_TXT",
|
|
437
|
-
challengeValue,
|
|
438
|
-
proofValue: String(options.proofValue || "txt-verification-record").trim() || null,
|
|
439
|
-
verificationSource:
|
|
440
|
-
String(options.verificationSource || "sentinelayer-cli").trim() || null,
|
|
441
|
-
expiresHours: parsePositiveInteger(options.expiresHours, "expiresHours", 24),
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
const artifactsDir = path.join(outputRoot, "aidenid", "domain-verify");
|
|
445
|
-
const stamp = stableTimestampForFile();
|
|
446
|
-
const requestPath = path.join(artifactsDir, `request-${encodeURIComponent(domainId)}-${stamp}.json`);
|
|
447
|
-
await writeArtifact(requestPath, {
|
|
448
|
-
generatedAt: new Date().toISOString(),
|
|
449
|
-
apiUrl,
|
|
450
|
-
idempotencyKey,
|
|
451
|
-
domainId,
|
|
452
|
-
payload,
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
456
|
-
apiKey: options.apiKey,
|
|
457
|
-
orgId: options.orgId,
|
|
458
|
-
projectId: options.projectId || tracked.domain?.projectId,
|
|
459
|
-
env: process.env,
|
|
460
|
-
requireAll: false,
|
|
461
|
-
});
|
|
462
|
-
if (!options.execute) {
|
|
463
|
-
const result = {
|
|
464
|
-
command: "ai identity domain verify",
|
|
465
|
-
execute: false,
|
|
466
|
-
domainId,
|
|
467
|
-
apiUrl,
|
|
468
|
-
idempotencyKey,
|
|
469
|
-
requestPath,
|
|
470
|
-
payload,
|
|
471
|
-
credentialsMissing: resolvedCredentials.missing,
|
|
472
|
-
};
|
|
473
|
-
if (emitJson) {
|
|
474
|
-
console.log(JSON.stringify(result, null, 2));
|
|
475
|
-
return;
|
|
476
|
-
}
|
|
477
|
-
console.log(pc.bold("AIdenID domain verify artifact generated (dry-run)"));
|
|
478
|
-
console.log(pc.gray(`Request: ${requestPath}`));
|
|
479
|
-
if (resolvedCredentials.missing.length > 0) {
|
|
480
|
-
console.log(
|
|
481
|
-
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
482
|
-
);
|
|
483
|
-
}
|
|
484
|
-
return;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
const requiredCredentials = await resolveAidenIdCredentials({
|
|
488
|
-
apiKey: options.apiKey,
|
|
489
|
-
orgId: options.orgId,
|
|
490
|
-
projectId: options.projectId || tracked.domain?.projectId,
|
|
491
|
-
env: process.env,
|
|
492
|
-
requireAll: true,
|
|
493
|
-
});
|
|
494
|
-
const execution = await verifyDomain({
|
|
495
|
-
apiUrl,
|
|
496
|
-
apiKey: requiredCredentials.apiKey,
|
|
497
|
-
orgId: requiredCredentials.orgId,
|
|
498
|
-
projectId: requiredCredentials.projectId,
|
|
499
|
-
domainId,
|
|
500
|
-
idempotencyKey,
|
|
501
|
-
payload,
|
|
502
|
-
});
|
|
503
|
-
const responsePath = path.join(
|
|
504
|
-
artifactsDir,
|
|
505
|
-
`response-${encodeURIComponent(domainId)}-${stamp}.json`
|
|
506
|
-
);
|
|
507
|
-
await writeArtifact(responsePath, {
|
|
508
|
-
receivedAt: new Date().toISOString(),
|
|
509
|
-
apiUrl,
|
|
510
|
-
idempotencyKey,
|
|
511
|
-
domainId,
|
|
512
|
-
response: execution.response,
|
|
513
|
-
});
|
|
514
|
-
|
|
515
|
-
const proofResponse = execution.response || {};
|
|
516
|
-
const registryUpdate = await recordDomainProofResponse({
|
|
517
|
-
outputRoot,
|
|
518
|
-
domain: proofResponse.domain || {},
|
|
519
|
-
proof: proofResponse,
|
|
520
|
-
context: {
|
|
521
|
-
source: "domain-verify",
|
|
522
|
-
idempotencyKey,
|
|
523
|
-
projectId: requiredCredentials.projectId,
|
|
524
|
-
},
|
|
525
|
-
});
|
|
526
|
-
const result = {
|
|
527
|
-
command: "ai identity domain verify",
|
|
528
|
-
execute: true,
|
|
529
|
-
domainId,
|
|
530
|
-
apiUrl,
|
|
531
|
-
idempotencyKey,
|
|
532
|
-
requestPath,
|
|
533
|
-
responsePath,
|
|
534
|
-
domain: proofResponse.domain || null,
|
|
535
|
-
proof: {
|
|
536
|
-
proofId: proofResponse.proofId || null,
|
|
537
|
-
challengeValue: proofResponse.challengeValue || null,
|
|
538
|
-
proofStatus: proofResponse.proofStatus || null,
|
|
539
|
-
proofExpiresAt: proofResponse.proofExpiresAt || null,
|
|
540
|
-
},
|
|
541
|
-
registryPath: registryUpdate.registryPath,
|
|
542
|
-
};
|
|
543
|
-
if (emitJson) {
|
|
544
|
-
console.log(JSON.stringify(result, null, 2));
|
|
545
|
-
return;
|
|
546
|
-
}
|
|
547
|
-
console.log(pc.bold("AIdenID domain verified"));
|
|
548
|
-
console.log(pc.gray(`Response: ${responsePath}`));
|
|
549
|
-
console.log(
|
|
550
|
-
`${String(result.domain?.id || domainId)} | verification=${String(result.domain?.verificationStatus || "UNKNOWN")}`
|
|
551
|
-
);
|
|
552
|
-
});
|
|
553
|
-
|
|
554
|
-
domain
|
|
555
|
-
.command("freeze")
|
|
556
|
-
.description("Freeze a domain for containment (dry-run by default)")
|
|
557
|
-
.argument("<domainId>", "Domain id")
|
|
558
|
-
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
559
|
-
.option("--output-dir <path>", "Optional artifact output root override")
|
|
560
|
-
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
561
|
-
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
562
|
-
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
563
|
-
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
564
|
-
.option("--reason <text>", "Freeze reason", "incident containment")
|
|
565
|
-
.option("--pool-isolated", "Isolate the domain pool", true)
|
|
566
|
-
.option("--no-pool-isolated", "Do not isolate the domain pool")
|
|
567
|
-
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
568
|
-
.option("--execute", "Execute live API call")
|
|
569
|
-
.option("--json", "Emit machine-readable output")
|
|
570
|
-
.action(async (domainId, options, command) => {
|
|
571
|
-
const emitJson = shouldEmitJson(options, command);
|
|
572
|
-
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
573
|
-
const outputRoot = await resolveOutputRoot({
|
|
574
|
-
cwd: targetPath,
|
|
575
|
-
outputDirOverride: options.outputDir,
|
|
576
|
-
env: process.env,
|
|
577
|
-
});
|
|
578
|
-
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
579
|
-
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
580
|
-
const tracked = await getDomainById({ outputRoot, domainId });
|
|
581
|
-
const payload = {
|
|
582
|
-
reason: String(options.reason || "").trim() || "incident containment",
|
|
583
|
-
poolIsolated: Boolean(options.poolIsolated),
|
|
584
|
-
};
|
|
585
|
-
|
|
586
|
-
const artifactsDir = path.join(outputRoot, "aidenid", "domain-freeze");
|
|
587
|
-
const stamp = stableTimestampForFile();
|
|
588
|
-
const requestPath = path.join(artifactsDir, `request-${encodeURIComponent(domainId)}-${stamp}.json`);
|
|
589
|
-
await writeArtifact(requestPath, {
|
|
590
|
-
generatedAt: new Date().toISOString(),
|
|
591
|
-
apiUrl,
|
|
592
|
-
idempotencyKey,
|
|
593
|
-
domainId,
|
|
594
|
-
payload,
|
|
595
|
-
});
|
|
596
|
-
|
|
597
|
-
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
598
|
-
apiKey: options.apiKey,
|
|
599
|
-
orgId: options.orgId,
|
|
600
|
-
projectId: options.projectId || tracked.domain?.projectId,
|
|
601
|
-
env: process.env,
|
|
602
|
-
requireAll: false,
|
|
603
|
-
});
|
|
604
|
-
if (!options.execute) {
|
|
605
|
-
const result = {
|
|
606
|
-
command: "ai identity domain freeze",
|
|
607
|
-
execute: false,
|
|
608
|
-
domainId,
|
|
609
|
-
apiUrl,
|
|
610
|
-
idempotencyKey,
|
|
611
|
-
requestPath,
|
|
612
|
-
payload,
|
|
613
|
-
credentialsMissing: resolvedCredentials.missing,
|
|
614
|
-
};
|
|
615
|
-
if (emitJson) {
|
|
616
|
-
console.log(JSON.stringify(result, null, 2));
|
|
617
|
-
return;
|
|
618
|
-
}
|
|
619
|
-
console.log(pc.bold("AIdenID domain freeze artifact generated (dry-run)"));
|
|
620
|
-
console.log(pc.gray(`Request: ${requestPath}`));
|
|
621
|
-
if (resolvedCredentials.missing.length > 0) {
|
|
622
|
-
console.log(
|
|
623
|
-
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
624
|
-
);
|
|
625
|
-
}
|
|
626
|
-
return;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
const requiredCredentials = await resolveAidenIdCredentials({
|
|
630
|
-
apiKey: options.apiKey,
|
|
631
|
-
orgId: options.orgId,
|
|
632
|
-
projectId: options.projectId || tracked.domain?.projectId,
|
|
633
|
-
env: process.env,
|
|
634
|
-
requireAll: true,
|
|
635
|
-
});
|
|
636
|
-
const execution = await freezeDomain({
|
|
637
|
-
apiUrl,
|
|
638
|
-
apiKey: requiredCredentials.apiKey,
|
|
639
|
-
orgId: requiredCredentials.orgId,
|
|
640
|
-
projectId: requiredCredentials.projectId,
|
|
641
|
-
domainId,
|
|
642
|
-
idempotencyKey,
|
|
643
|
-
payload,
|
|
644
|
-
});
|
|
645
|
-
const responsePath = path.join(
|
|
646
|
-
artifactsDir,
|
|
647
|
-
`response-${encodeURIComponent(domainId)}-${stamp}.json`
|
|
648
|
-
);
|
|
649
|
-
await writeArtifact(responsePath, {
|
|
650
|
-
receivedAt: new Date().toISOString(),
|
|
651
|
-
apiUrl,
|
|
652
|
-
idempotencyKey,
|
|
653
|
-
domainId,
|
|
654
|
-
response: execution.response,
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
const registryUpdate = await recordDomainProofResponse({
|
|
658
|
-
outputRoot,
|
|
659
|
-
domain: execution.response || {},
|
|
660
|
-
proof: {},
|
|
661
|
-
context: {
|
|
662
|
-
source: "domain-freeze",
|
|
663
|
-
idempotencyKey,
|
|
664
|
-
projectId: requiredCredentials.projectId,
|
|
665
|
-
},
|
|
666
|
-
});
|
|
667
|
-
const result = {
|
|
668
|
-
command: "ai identity domain freeze",
|
|
669
|
-
execute: true,
|
|
670
|
-
domainId,
|
|
671
|
-
apiUrl,
|
|
672
|
-
idempotencyKey,
|
|
673
|
-
requestPath,
|
|
674
|
-
responsePath,
|
|
675
|
-
domain: execution.response || null,
|
|
676
|
-
registryPath: registryUpdate.registryPath,
|
|
677
|
-
};
|
|
678
|
-
if (emitJson) {
|
|
679
|
-
console.log(JSON.stringify(result, null, 2));
|
|
680
|
-
return;
|
|
681
|
-
}
|
|
682
|
-
console.log(pc.bold("AIdenID domain frozen"));
|
|
683
|
-
console.log(pc.gray(`Response: ${responsePath}`));
|
|
684
|
-
console.log(
|
|
685
|
-
`${String(result.domain?.id || domainId)} | freeze=${String(result.domain?.freezeStatus || "UNKNOWN")}`
|
|
686
|
-
);
|
|
687
|
-
});
|
|
688
|
-
|
|
689
|
-
target
|
|
690
|
-
.command("create")
|
|
691
|
-
.description("Create a managed target and proof challenge (dry-run by default)")
|
|
692
|
-
.argument("<host>", "Target host")
|
|
693
|
-
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
694
|
-
.option("--output-dir <path>", "Optional artifact output root override")
|
|
695
|
-
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
696
|
-
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
697
|
-
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
698
|
-
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
699
|
-
.option("--domain-id <id>", "Optional domain id")
|
|
700
|
-
.option("--allowed-paths <csv>", "Allowed paths", "/")
|
|
701
|
-
.option("--allowed-methods <csv>", "Allowed methods", "GET")
|
|
702
|
-
.option("--allowed-scenarios <csv>", "Allowed scenarios", "form_boundary_fuzz")
|
|
703
|
-
.option("--max-rps <count>", "Maximum requests per second", "5")
|
|
704
|
-
.option("--max-concurrency <count>", "Maximum concurrency", "5")
|
|
705
|
-
.option("--stop-conditions-json <json>", "JSON object for stop conditions", "{}")
|
|
706
|
-
.option("--maintenance-window-json <json>", "JSON object for maintenance window", "{}")
|
|
707
|
-
.option("--contact-json <json>", "JSON object for contact metadata", "{}")
|
|
708
|
-
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
709
|
-
.option("--execute", "Execute live API call")
|
|
710
|
-
.option("--json", "Emit machine-readable output")
|
|
711
|
-
.action(async (host, options, command) => {
|
|
712
|
-
const emitJson = shouldEmitJson(options, command);
|
|
713
|
-
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
714
|
-
const outputRoot = await resolveOutputRoot({
|
|
715
|
-
cwd: targetPath,
|
|
716
|
-
outputDirOverride: options.outputDir,
|
|
717
|
-
env: process.env,
|
|
718
|
-
});
|
|
719
|
-
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
720
|
-
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
721
|
-
const payload = {
|
|
722
|
-
host: String(host || "").trim(),
|
|
723
|
-
domainId: String(options.domainId || "").trim() || null,
|
|
724
|
-
maintenanceWindow: parseJsonObject(options.maintenanceWindowJson, "maintenanceWindowJson"),
|
|
725
|
-
contact: parseJsonObject(options.contactJson, "contactJson"),
|
|
726
|
-
policy: {
|
|
727
|
-
allowedPaths: parseCsvTokens(options.allowedPaths, ["/"]),
|
|
728
|
-
allowedMethods: parseCsvTokens(options.allowedMethods, ["GET"]),
|
|
729
|
-
allowedScenarios: parseCsvTokens(options.allowedScenarios, ["form_boundary_fuzz"]),
|
|
730
|
-
maxRps: parsePositiveInteger(options.maxRps, "maxRps", 5),
|
|
731
|
-
maxConcurrency: parsePositiveInteger(options.maxConcurrency, "maxConcurrency", 5),
|
|
732
|
-
stopConditions: parseJsonObject(options.stopConditionsJson, "stopConditionsJson"),
|
|
733
|
-
},
|
|
734
|
-
};
|
|
735
|
-
if (!payload.host) {
|
|
736
|
-
throw new Error("host is required.");
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
const artifactsDir = path.join(outputRoot, "aidenid", "target-create");
|
|
740
|
-
const stamp = stableTimestampForFile();
|
|
741
|
-
const requestPath = path.join(artifactsDir, `request-${encodeURIComponent(payload.host)}-${stamp}.json`);
|
|
742
|
-
await writeArtifact(requestPath, {
|
|
743
|
-
generatedAt: new Date().toISOString(),
|
|
744
|
-
apiUrl,
|
|
745
|
-
idempotencyKey,
|
|
746
|
-
payload,
|
|
747
|
-
});
|
|
748
|
-
|
|
749
|
-
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
750
|
-
apiKey: options.apiKey,
|
|
751
|
-
orgId: options.orgId,
|
|
752
|
-
projectId: options.projectId,
|
|
753
|
-
env: process.env,
|
|
754
|
-
requireAll: false,
|
|
755
|
-
});
|
|
756
|
-
if (!options.execute) {
|
|
757
|
-
const result = {
|
|
758
|
-
command: "ai identity target create",
|
|
759
|
-
execute: false,
|
|
760
|
-
apiUrl,
|
|
761
|
-
idempotencyKey,
|
|
762
|
-
requestPath,
|
|
763
|
-
payload,
|
|
764
|
-
credentialsMissing: resolvedCredentials.missing,
|
|
765
|
-
};
|
|
766
|
-
if (emitJson) {
|
|
767
|
-
console.log(JSON.stringify(result, null, 2));
|
|
768
|
-
return;
|
|
769
|
-
}
|
|
770
|
-
console.log(pc.bold("AIdenID target create artifact generated (dry-run)"));
|
|
771
|
-
console.log(pc.gray(`Request: ${requestPath}`));
|
|
772
|
-
if (resolvedCredentials.missing.length > 0) {
|
|
773
|
-
console.log(
|
|
774
|
-
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
775
|
-
);
|
|
776
|
-
}
|
|
777
|
-
return;
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
const requiredCredentials = await resolveAidenIdCredentials({
|
|
781
|
-
apiKey: options.apiKey,
|
|
782
|
-
orgId: options.orgId,
|
|
783
|
-
projectId: options.projectId,
|
|
784
|
-
env: process.env,
|
|
785
|
-
requireAll: true,
|
|
786
|
-
});
|
|
787
|
-
const execution = await createTarget({
|
|
788
|
-
apiUrl,
|
|
789
|
-
apiKey: requiredCredentials.apiKey,
|
|
790
|
-
orgId: requiredCredentials.orgId,
|
|
791
|
-
projectId: requiredCredentials.projectId,
|
|
792
|
-
idempotencyKey,
|
|
793
|
-
payload,
|
|
794
|
-
});
|
|
795
|
-
const responsePath = path.join(
|
|
796
|
-
artifactsDir,
|
|
797
|
-
`response-${encodeURIComponent(payload.host)}-${stamp}.json`
|
|
798
|
-
);
|
|
799
|
-
await writeArtifact(responsePath, {
|
|
800
|
-
receivedAt: new Date().toISOString(),
|
|
801
|
-
apiUrl,
|
|
802
|
-
idempotencyKey,
|
|
803
|
-
response: execution.response,
|
|
804
|
-
});
|
|
805
|
-
|
|
806
|
-
const proofResponse = execution.response || {};
|
|
807
|
-
const registryUpdate = await recordTargetProofResponse({
|
|
808
|
-
outputRoot,
|
|
809
|
-
target: proofResponse.target || {},
|
|
810
|
-
proof: proofResponse,
|
|
811
|
-
context: {
|
|
812
|
-
source: "target-create",
|
|
813
|
-
idempotencyKey,
|
|
814
|
-
projectId: requiredCredentials.projectId,
|
|
815
|
-
domainId: payload.domainId,
|
|
816
|
-
},
|
|
817
|
-
});
|
|
818
|
-
const result = {
|
|
819
|
-
command: "ai identity target create",
|
|
820
|
-
execute: true,
|
|
821
|
-
apiUrl,
|
|
822
|
-
idempotencyKey,
|
|
823
|
-
requestPath,
|
|
824
|
-
responsePath,
|
|
825
|
-
target: proofResponse.target || null,
|
|
826
|
-
proof: {
|
|
827
|
-
proofId: proofResponse.proofId || null,
|
|
828
|
-
challengeValue: proofResponse.challengeValue || null,
|
|
829
|
-
proofStatus: proofResponse.proofStatus || null,
|
|
830
|
-
proofExpiresAt: proofResponse.proofExpiresAt || null,
|
|
831
|
-
},
|
|
832
|
-
registryPath: registryUpdate.registryPath,
|
|
833
|
-
};
|
|
834
|
-
if (emitJson) {
|
|
835
|
-
console.log(JSON.stringify(result, null, 2));
|
|
836
|
-
return;
|
|
837
|
-
}
|
|
838
|
-
console.log(pc.bold("AIdenID target created"));
|
|
839
|
-
console.log(pc.gray(`Response: ${responsePath}`));
|
|
840
|
-
console.log(`${String(result.target?.id || "unknown-target")} | ${String(result.target?.host || payload.host)}`);
|
|
841
|
-
});
|
|
842
|
-
|
|
843
|
-
target
|
|
844
|
-
.command("verify")
|
|
845
|
-
.description("Verify target proof challenge (dry-run by default)")
|
|
846
|
-
.argument("<targetId>", "Target id")
|
|
847
|
-
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
848
|
-
.option("--output-dir <path>", "Optional artifact output root override")
|
|
849
|
-
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
850
|
-
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
851
|
-
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
852
|
-
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
853
|
-
.option("--method <value>", "Verification method", "DNS_TXT")
|
|
854
|
-
.option("--challenge-value <value>", "Challenge value override (fallback: local registry)")
|
|
855
|
-
.option("--proof-value <value>", "Proof value", "target-txt-proof")
|
|
856
|
-
.option("--verification-source <value>", "Verification source", "sentinelayer-cli")
|
|
857
|
-
.option("--expires-hours <hours>", "Proof expiration in hours", "24")
|
|
858
|
-
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
859
|
-
.option("--execute", "Execute live API call")
|
|
860
|
-
.option("--json", "Emit machine-readable output")
|
|
861
|
-
.action(async (targetId, options, command) => {
|
|
862
|
-
const emitJson = shouldEmitJson(options, command);
|
|
863
|
-
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
864
|
-
const outputRoot = await resolveOutputRoot({
|
|
865
|
-
cwd: targetPath,
|
|
866
|
-
outputDirOverride: options.outputDir,
|
|
867
|
-
env: process.env,
|
|
868
|
-
});
|
|
869
|
-
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
870
|
-
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
871
|
-
const tracked = await getTrackedTargetById({ outputRoot, targetId });
|
|
872
|
-
const challengeValue =
|
|
873
|
-
String(options.challengeValue || "").trim() ||
|
|
874
|
-
String(tracked.target?.challengeValue || "").trim() ||
|
|
875
|
-
null;
|
|
876
|
-
if (!challengeValue) {
|
|
877
|
-
throw new Error(
|
|
878
|
-
`challengeValue is required. Provide --challenge-value or run target create first for '${targetId}'.`
|
|
879
|
-
);
|
|
880
|
-
}
|
|
881
|
-
const payload = {
|
|
882
|
-
method: String(options.method || "DNS_TXT").trim() || "DNS_TXT",
|
|
883
|
-
challengeValue,
|
|
884
|
-
proofValue: String(options.proofValue || "target-txt-proof").trim() || null,
|
|
885
|
-
verificationSource:
|
|
886
|
-
String(options.verificationSource || "sentinelayer-cli").trim() || null,
|
|
887
|
-
expiresHours: parsePositiveInteger(options.expiresHours, "expiresHours", 24),
|
|
888
|
-
};
|
|
889
|
-
|
|
890
|
-
const artifactsDir = path.join(outputRoot, "aidenid", "target-verify");
|
|
891
|
-
const stamp = stableTimestampForFile();
|
|
892
|
-
const requestPath = path.join(artifactsDir, `request-${encodeURIComponent(targetId)}-${stamp}.json`);
|
|
893
|
-
await writeArtifact(requestPath, {
|
|
894
|
-
generatedAt: new Date().toISOString(),
|
|
895
|
-
apiUrl,
|
|
896
|
-
idempotencyKey,
|
|
897
|
-
targetId,
|
|
898
|
-
payload,
|
|
899
|
-
});
|
|
900
|
-
|
|
901
|
-
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
902
|
-
apiKey: options.apiKey,
|
|
903
|
-
orgId: options.orgId,
|
|
904
|
-
projectId: options.projectId || tracked.target?.projectId,
|
|
905
|
-
env: process.env,
|
|
906
|
-
requireAll: false,
|
|
907
|
-
});
|
|
908
|
-
if (!options.execute) {
|
|
909
|
-
const result = {
|
|
910
|
-
command: "ai identity target verify",
|
|
911
|
-
execute: false,
|
|
912
|
-
targetId,
|
|
913
|
-
apiUrl,
|
|
914
|
-
idempotencyKey,
|
|
915
|
-
requestPath,
|
|
916
|
-
payload,
|
|
917
|
-
credentialsMissing: resolvedCredentials.missing,
|
|
918
|
-
};
|
|
919
|
-
if (emitJson) {
|
|
920
|
-
console.log(JSON.stringify(result, null, 2));
|
|
921
|
-
return;
|
|
922
|
-
}
|
|
923
|
-
console.log(pc.bold("AIdenID target verify artifact generated (dry-run)"));
|
|
924
|
-
console.log(pc.gray(`Request: ${requestPath}`));
|
|
925
|
-
if (resolvedCredentials.missing.length > 0) {
|
|
926
|
-
console.log(
|
|
927
|
-
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
928
|
-
);
|
|
929
|
-
}
|
|
930
|
-
return;
|
|
931
|
-
}
|
|
932
|
-
|
|
933
|
-
const requiredCredentials = await resolveAidenIdCredentials({
|
|
934
|
-
apiKey: options.apiKey,
|
|
935
|
-
orgId: options.orgId,
|
|
936
|
-
projectId: options.projectId || tracked.target?.projectId,
|
|
937
|
-
env: process.env,
|
|
938
|
-
requireAll: true,
|
|
939
|
-
});
|
|
940
|
-
const execution = await verifyTarget({
|
|
941
|
-
apiUrl,
|
|
942
|
-
apiKey: requiredCredentials.apiKey,
|
|
943
|
-
orgId: requiredCredentials.orgId,
|
|
944
|
-
projectId: requiredCredentials.projectId,
|
|
945
|
-
targetId,
|
|
946
|
-
idempotencyKey,
|
|
947
|
-
payload,
|
|
948
|
-
});
|
|
949
|
-
const responsePath = path.join(
|
|
950
|
-
artifactsDir,
|
|
951
|
-
`response-${encodeURIComponent(targetId)}-${stamp}.json`
|
|
952
|
-
);
|
|
953
|
-
await writeArtifact(responsePath, {
|
|
954
|
-
receivedAt: new Date().toISOString(),
|
|
955
|
-
apiUrl,
|
|
956
|
-
idempotencyKey,
|
|
957
|
-
targetId,
|
|
958
|
-
response: execution.response,
|
|
959
|
-
});
|
|
960
|
-
|
|
961
|
-
const proofResponse = execution.response || {};
|
|
962
|
-
const registryUpdate = await recordTargetProofResponse({
|
|
963
|
-
outputRoot,
|
|
964
|
-
target: proofResponse.target || {},
|
|
965
|
-
proof: proofResponse,
|
|
966
|
-
context: {
|
|
967
|
-
source: "target-verify",
|
|
968
|
-
idempotencyKey,
|
|
969
|
-
projectId: requiredCredentials.projectId,
|
|
970
|
-
},
|
|
971
|
-
});
|
|
972
|
-
const result = {
|
|
973
|
-
command: "ai identity target verify",
|
|
974
|
-
execute: true,
|
|
975
|
-
targetId,
|
|
976
|
-
apiUrl,
|
|
977
|
-
idempotencyKey,
|
|
978
|
-
requestPath,
|
|
979
|
-
responsePath,
|
|
980
|
-
target: proofResponse.target || null,
|
|
981
|
-
proof: {
|
|
982
|
-
proofId: proofResponse.proofId || null,
|
|
983
|
-
challengeValue: proofResponse.challengeValue || null,
|
|
984
|
-
proofStatus: proofResponse.proofStatus || null,
|
|
985
|
-
proofExpiresAt: proofResponse.proofExpiresAt || null,
|
|
986
|
-
},
|
|
987
|
-
registryPath: registryUpdate.registryPath,
|
|
988
|
-
};
|
|
989
|
-
if (emitJson) {
|
|
990
|
-
console.log(JSON.stringify(result, null, 2));
|
|
991
|
-
return;
|
|
992
|
-
}
|
|
993
|
-
console.log(pc.bold("AIdenID target verified"));
|
|
994
|
-
console.log(pc.gray(`Response: ${responsePath}`));
|
|
995
|
-
console.log(
|
|
996
|
-
`${String(result.target?.id || targetId)} | verification=${String(result.target?.verificationStatus || "UNKNOWN")}`
|
|
997
|
-
);
|
|
998
|
-
});
|
|
999
|
-
|
|
1000
|
-
target
|
|
1001
|
-
.command("show")
|
|
1002
|
-
.description("Show managed target details")
|
|
1003
|
-
.argument("<targetId>", "Target id")
|
|
1004
|
-
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
1005
|
-
.option("--output-dir <path>", "Optional artifact output root override")
|
|
1006
|
-
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
1007
|
-
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
1008
|
-
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
1009
|
-
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
1010
|
-
.option("--json", "Emit machine-readable output")
|
|
1011
|
-
.action(async (targetId, options, command) => {
|
|
1012
|
-
const emitJson = shouldEmitJson(options, command);
|
|
1013
|
-
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
1014
|
-
const outputRoot = await resolveOutputRoot({
|
|
1015
|
-
cwd: targetPath,
|
|
1016
|
-
outputDirOverride: options.outputDir,
|
|
1017
|
-
env: process.env,
|
|
1018
|
-
});
|
|
1019
|
-
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
1020
|
-
const tracked = await getTrackedTargetById({ outputRoot, targetId });
|
|
1021
|
-
const credentials = await resolveAidenIdCredentials({
|
|
1022
|
-
apiKey: options.apiKey,
|
|
1023
|
-
orgId: options.orgId,
|
|
1024
|
-
projectId: options.projectId || tracked.target?.projectId,
|
|
1025
|
-
env: process.env,
|
|
1026
|
-
requireAll: true,
|
|
1027
|
-
});
|
|
1028
|
-
|
|
1029
|
-
const execution = await getTarget({
|
|
1030
|
-
apiUrl,
|
|
1031
|
-
apiKey: credentials.apiKey,
|
|
1032
|
-
orgId: credentials.orgId,
|
|
1033
|
-
projectId: credentials.projectId,
|
|
1034
|
-
targetId,
|
|
1035
|
-
});
|
|
1036
|
-
const stamp = stableTimestampForFile();
|
|
1037
|
-
const artifactsDir = path.join(outputRoot, "aidenid", "target-show");
|
|
1038
|
-
const outputPath = path.join(artifactsDir, `target-${encodeURIComponent(targetId)}-${stamp}.json`);
|
|
1039
|
-
await writeArtifact(outputPath, {
|
|
1040
|
-
generatedAt: new Date().toISOString(),
|
|
1041
|
-
targetId,
|
|
1042
|
-
response: execution.response,
|
|
1043
|
-
});
|
|
1044
|
-
|
|
1045
|
-
const registryUpdate = await recordTargetProofResponse({
|
|
1046
|
-
outputRoot,
|
|
1047
|
-
target: execution.response || {},
|
|
1048
|
-
proof: {},
|
|
1049
|
-
context: {
|
|
1050
|
-
source: "target-show",
|
|
1051
|
-
projectId: credentials.projectId,
|
|
1052
|
-
},
|
|
1053
|
-
});
|
|
1054
|
-
const payload = {
|
|
1055
|
-
command: "ai identity target show",
|
|
1056
|
-
targetId,
|
|
1057
|
-
outputPath,
|
|
1058
|
-
target: execution.response,
|
|
1059
|
-
registryPath: registryUpdate.registryPath,
|
|
1060
|
-
};
|
|
1061
|
-
if (emitJson) {
|
|
1062
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
1063
|
-
return;
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
console.log(pc.bold("AIdenID target"));
|
|
1067
|
-
console.log(pc.gray(`Artifact: ${outputPath}`));
|
|
1068
|
-
console.log(
|
|
1069
|
-
`${String(execution.response?.id || targetId)} | host=${String(execution.response?.host || "unknown")}`
|
|
1070
|
-
);
|
|
1071
|
-
console.log(
|
|
1072
|
-
`status=${String(execution.response?.status || "UNKNOWN")} verification=${String(
|
|
1073
|
-
execution.response?.verificationStatus || "UNKNOWN"
|
|
1074
|
-
)}`
|
|
1075
|
-
);
|
|
1076
|
-
});
|
|
1077
|
-
|
|
1078
|
-
site
|
|
1079
|
-
.command("create")
|
|
1080
|
-
.description("Create an ephemeral callback site linked to an identity (dry-run by default)")
|
|
1081
|
-
.argument("<identityId>", "Identity id")
|
|
1082
|
-
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
1083
|
-
.option("--output-dir <path>", "Optional artifact output root override")
|
|
1084
|
-
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
1085
|
-
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
1086
|
-
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
1087
|
-
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
1088
|
-
.option("--domain-id <id>", "Domain id used for callback host")
|
|
1089
|
-
.option("--subdomain-prefix <value>", "Subdomain prefix", "cb")
|
|
1090
|
-
.option("--callback-path <value>", "Callback path", "/callback")
|
|
1091
|
-
.option("--ttl-hours <hours>", "Site TTL in hours", "24")
|
|
1092
|
-
.option("--dns-cleanup-contract-json <json>", "JSON cleanup contract", "{}")
|
|
1093
|
-
.option("--metadata-json <json>", "JSON metadata", "{}")
|
|
1094
|
-
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
1095
|
-
.option("--execute", "Execute live API call")
|
|
1096
|
-
.option("--json", "Emit machine-readable output")
|
|
1097
|
-
.action(async (identityId, options, command) => {
|
|
1098
|
-
const emitJson = shouldEmitJson(options, command);
|
|
1099
|
-
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
1100
|
-
const outputRoot = await resolveOutputRoot({
|
|
1101
|
-
cwd: targetPath,
|
|
1102
|
-
outputDirOverride: options.outputDir,
|
|
1103
|
-
env: process.env,
|
|
1104
|
-
});
|
|
1105
|
-
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
1106
|
-
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
1107
|
-
const ttlHours = parsePositiveInteger(options.ttlHours, "ttlHours", 24);
|
|
1108
|
-
const domainId = String(options.domainId || "").trim();
|
|
1109
|
-
if (!domainId) {
|
|
1110
|
-
throw new Error("domainId is required. Use --domain-id <id>.");
|
|
1111
|
-
}
|
|
1112
|
-
const trackedIdentity = await getIdentityById({
|
|
1113
|
-
outputRoot,
|
|
1114
|
-
identityId,
|
|
1115
|
-
});
|
|
1116
|
-
const payload = {
|
|
1117
|
-
identityId,
|
|
1118
|
-
domainId,
|
|
1119
|
-
subdomainPrefix: String(options.subdomainPrefix || "cb").trim() || "cb",
|
|
1120
|
-
callbackPath: String(options.callbackPath || "/callback").trim() || "/callback",
|
|
1121
|
-
ttlHours,
|
|
1122
|
-
dnsCleanupContract: parseJsonObject(options.dnsCleanupContractJson, "dnsCleanupContractJson"),
|
|
1123
|
-
metadata: parseJsonObject(options.metadataJson, "metadataJson"),
|
|
1124
|
-
};
|
|
1125
|
-
|
|
1126
|
-
const artifactsDir = path.join(outputRoot, "aidenid", "site-create");
|
|
1127
|
-
const stamp = stableTimestampForFile();
|
|
1128
|
-
const requestPath = path.join(artifactsDir, `request-${encodeURIComponent(identityId)}-${stamp}.json`);
|
|
1129
|
-
await writeArtifact(requestPath, {
|
|
1130
|
-
generatedAt: new Date().toISOString(),
|
|
1131
|
-
apiUrl,
|
|
1132
|
-
idempotencyKey,
|
|
1133
|
-
payload,
|
|
1134
|
-
});
|
|
1135
|
-
|
|
1136
|
-
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
1137
|
-
apiKey: options.apiKey,
|
|
1138
|
-
orgId: options.orgId || trackedIdentity.identity?.orgId,
|
|
1139
|
-
projectId: options.projectId || trackedIdentity.identity?.projectId,
|
|
1140
|
-
env: process.env,
|
|
1141
|
-
requireAll: false,
|
|
1142
|
-
});
|
|
1143
|
-
if (!options.execute) {
|
|
1144
|
-
const result = {
|
|
1145
|
-
command: "ai identity site create",
|
|
1146
|
-
execute: false,
|
|
1147
|
-
identityId,
|
|
1148
|
-
apiUrl,
|
|
1149
|
-
idempotencyKey,
|
|
1150
|
-
requestPath,
|
|
1151
|
-
payload,
|
|
1152
|
-
credentialsMissing: resolvedCredentials.missing,
|
|
1153
|
-
};
|
|
1154
|
-
if (emitJson) {
|
|
1155
|
-
console.log(JSON.stringify(result, null, 2));
|
|
1156
|
-
return;
|
|
1157
|
-
}
|
|
1158
|
-
console.log(pc.bold("AIdenID site create artifact generated (dry-run)"));
|
|
1159
|
-
console.log(pc.gray(`Request: ${requestPath}`));
|
|
1160
|
-
if (resolvedCredentials.missing.length > 0) {
|
|
1161
|
-
console.log(
|
|
1162
|
-
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
1163
|
-
);
|
|
1164
|
-
}
|
|
1165
|
-
return;
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
const requiredCredentials = await resolveAidenIdCredentials({
|
|
1169
|
-
apiKey: options.apiKey,
|
|
1170
|
-
orgId: options.orgId || trackedIdentity.identity?.orgId,
|
|
1171
|
-
projectId: options.projectId || trackedIdentity.identity?.projectId,
|
|
1172
|
-
env: process.env,
|
|
1173
|
-
requireAll: true,
|
|
1174
|
-
});
|
|
1175
|
-
const execution = await createTemporarySite({
|
|
1176
|
-
apiUrl,
|
|
1177
|
-
apiKey: requiredCredentials.apiKey,
|
|
1178
|
-
orgId: requiredCredentials.orgId,
|
|
1179
|
-
projectId: requiredCredentials.projectId,
|
|
1180
|
-
idempotencyKey,
|
|
1181
|
-
payload,
|
|
1182
|
-
});
|
|
1183
|
-
const responsePath = path.join(
|
|
1184
|
-
artifactsDir,
|
|
1185
|
-
`response-${encodeURIComponent(identityId)}-${stamp}.json`
|
|
1186
|
-
);
|
|
1187
|
-
await writeArtifact(responsePath, {
|
|
1188
|
-
receivedAt: new Date().toISOString(),
|
|
1189
|
-
apiUrl,
|
|
1190
|
-
idempotencyKey,
|
|
1191
|
-
response: execution.response,
|
|
1192
|
-
});
|
|
1193
|
-
|
|
1194
|
-
const registryUpdate = await recordTemporarySite({
|
|
1195
|
-
outputRoot,
|
|
1196
|
-
site: execution.response || {},
|
|
1197
|
-
context: {
|
|
1198
|
-
source: "site-create",
|
|
1199
|
-
idempotencyKey,
|
|
1200
|
-
identityId,
|
|
1201
|
-
domainId,
|
|
1202
|
-
projectId: requiredCredentials.projectId,
|
|
1203
|
-
},
|
|
1204
|
-
});
|
|
1205
|
-
const result = {
|
|
1206
|
-
command: "ai identity site create",
|
|
1207
|
-
execute: true,
|
|
1208
|
-
identityId,
|
|
1209
|
-
apiUrl,
|
|
1210
|
-
idempotencyKey,
|
|
1211
|
-
requestPath,
|
|
1212
|
-
responsePath,
|
|
1213
|
-
site: execution.response || null,
|
|
1214
|
-
registryPath: registryUpdate.registryPath,
|
|
1215
|
-
};
|
|
1216
|
-
if (emitJson) {
|
|
1217
|
-
console.log(JSON.stringify(result, null, 2));
|
|
1218
|
-
return;
|
|
1219
|
-
}
|
|
1220
|
-
console.log(pc.bold("AIdenID temporary site created"));
|
|
1221
|
-
console.log(pc.gray(`Response: ${responsePath}`));
|
|
1222
|
-
console.log(
|
|
1223
|
-
`${String(result.site?.id || "unknown-site")} | ${String(result.site?.callbackUrl || result.site?.host || "unknown-host")}`
|
|
1224
|
-
);
|
|
1225
|
-
});
|
|
1226
|
-
|
|
1227
|
-
site
|
|
1228
|
-
.command("list")
|
|
1229
|
-
.description("List locally tracked temporary callback sites")
|
|
1230
|
-
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
1231
|
-
.option("--output-dir <path>", "Optional artifact output root override")
|
|
1232
|
-
.option("--identity-id <id>", "Optional identity filter")
|
|
1233
|
-
.option("--json", "Emit machine-readable output")
|
|
1234
|
-
.action(async (options, command) => {
|
|
1235
|
-
const emitJson = shouldEmitJson(options, command);
|
|
1236
|
-
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
1237
|
-
const outputRoot = await resolveOutputRoot({
|
|
1238
|
-
cwd: targetPath,
|
|
1239
|
-
outputDirOverride: options.outputDir,
|
|
1240
|
-
env: process.env,
|
|
1241
|
-
});
|
|
1242
|
-
const listing = await listSites({
|
|
1243
|
-
outputRoot,
|
|
1244
|
-
identityId: options.identityId,
|
|
1245
|
-
});
|
|
1246
|
-
const payload = {
|
|
1247
|
-
command: "ai identity site list",
|
|
1248
|
-
registryPath: listing.registryPath,
|
|
1249
|
-
count: listing.sites.length,
|
|
1250
|
-
sites: listing.sites,
|
|
1251
|
-
};
|
|
1252
|
-
if (emitJson) {
|
|
1253
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
1254
|
-
return;
|
|
1255
|
-
}
|
|
1256
|
-
|
|
1257
|
-
console.log(pc.bold("AIdenID temporary sites"));
|
|
1258
|
-
console.log(pc.gray(`Registry: ${listing.registryPath}`));
|
|
1259
|
-
if (listing.sites.length === 0) {
|
|
1260
|
-
console.log(pc.gray("No tracked temporary sites."));
|
|
1261
|
-
return;
|
|
1262
|
-
}
|
|
1263
|
-
for (const item of listing.sites) {
|
|
1264
|
-
console.log(
|
|
1265
|
-
`- ${item.siteId} | ${item.identityId || "unknown-identity"} | ${item.status} | ${item.callbackUrl || item.host || "unknown-host"}`
|
|
1266
|
-
);
|
|
1267
|
-
}
|
|
1268
|
-
});
|
|
1269
|
-
|
|
1270
|
-
return { identity, legalHold };
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
|
|
4
|
+
import pc from "picocolors";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
buildProvisionEmailPayload,
|
|
8
|
+
createDomain,
|
|
9
|
+
createTemporarySite,
|
|
10
|
+
createTarget,
|
|
11
|
+
freezeDomain,
|
|
12
|
+
getTarget,
|
|
13
|
+
normalizeAidenIdApiUrl,
|
|
14
|
+
provisionEmailIdentity,
|
|
15
|
+
resolveAidenIdCredentials,
|
|
16
|
+
verifyDomain,
|
|
17
|
+
verifyTarget,
|
|
18
|
+
} from "../../ai/aidenid.js";
|
|
19
|
+
import {
|
|
20
|
+
getDomainById,
|
|
21
|
+
getTargetById as getTrackedTargetById,
|
|
22
|
+
recordDomainProofResponse,
|
|
23
|
+
recordTargetProofResponse,
|
|
24
|
+
} from "../../ai/domain-target-store.js";
|
|
25
|
+
import { listSites, recordTemporarySite } from "../../ai/site-store.js";
|
|
26
|
+
import { getIdentityById, recordProvisionedIdentity } from "../../ai/identity-store.js";
|
|
27
|
+
import { resolveOutputRoot } from "../../config/service.js";
|
|
28
|
+
import { readStoredSession } from "../../auth/session-store.js";
|
|
29
|
+
import { fetchAidenIdCredentials } from "../../auth/service.js";
|
|
30
|
+
import {
|
|
31
|
+
buildCurlPreview,
|
|
32
|
+
normalizeIdempotencyKey,
|
|
33
|
+
parseCsvTokens,
|
|
34
|
+
parseJsonObject,
|
|
35
|
+
parsePositiveInteger,
|
|
36
|
+
shouldEmitJson,
|
|
37
|
+
stableTimestampForFile,
|
|
38
|
+
writeArtifact,
|
|
39
|
+
} from "./shared.js";
|
|
40
|
+
|
|
41
|
+
function addProvisionEmailOptions(cmd) {
|
|
42
|
+
return cmd
|
|
43
|
+
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
44
|
+
.option("--output-dir <path>", "Optional artifact output root override")
|
|
45
|
+
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
46
|
+
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
47
|
+
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
48
|
+
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
49
|
+
.option("--alias-template <value>", "Optional alias template")
|
|
50
|
+
.option("--ttl-hours <hours>", "Identity TTL in hours", "24")
|
|
51
|
+
.option("--tags <csv>", "Comma-separated tags")
|
|
52
|
+
.option("--domain-pool-id <id>", "Optional domain pool id")
|
|
53
|
+
.option("--receive-mode <mode>", "Identity receive mode", "EDGE_ACCEPT")
|
|
54
|
+
.option("--extraction-types <csv>", "Comma-separated extraction types", "otp,link")
|
|
55
|
+
.option("--allow-webhooks", "Allow webhook delivery", true)
|
|
56
|
+
.option("--no-allow-webhooks", "Disable webhook delivery")
|
|
57
|
+
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
58
|
+
.option("--execute", "Execute live API call (default is dry-run artifact generation)")
|
|
59
|
+
.option("--json", "Emit machine-readable output");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async function provisionEmailAction(options, command) {
|
|
63
|
+
const emitJson = shouldEmitJson(options, command);
|
|
64
|
+
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
65
|
+
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
66
|
+
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
67
|
+
const ttlHours = parsePositiveInteger(options.ttlHours, "ttlHours", 24);
|
|
68
|
+
|
|
69
|
+
const payload = buildProvisionEmailPayload({
|
|
70
|
+
aliasTemplate: options.aliasTemplate,
|
|
71
|
+
ttlHours,
|
|
72
|
+
tags: options.tags,
|
|
73
|
+
domainPoolId: options.domainPoolId,
|
|
74
|
+
receiveMode: options.receiveMode,
|
|
75
|
+
allowWebhooks: Boolean(options.allowWebhooks),
|
|
76
|
+
extractionTypes: options.extractionTypes,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const outputRoot = await resolveOutputRoot({
|
|
80
|
+
cwd: targetPath,
|
|
81
|
+
outputDirOverride: options.outputDir,
|
|
82
|
+
env: process.env,
|
|
83
|
+
});
|
|
84
|
+
const artifactsDir = path.join(outputRoot, "aidenid", "provision-email");
|
|
85
|
+
const stamp = stableTimestampForFile();
|
|
86
|
+
const requestPath = path.join(artifactsDir, `request-${stamp}.json`);
|
|
87
|
+
|
|
88
|
+
await writeArtifact(requestPath, {
|
|
89
|
+
generatedAt: new Date().toISOString(),
|
|
90
|
+
apiUrl,
|
|
91
|
+
idempotencyKey,
|
|
92
|
+
payload,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
let session = null;
|
|
96
|
+
try { session = await readStoredSession(); } catch { /* no session */ }
|
|
97
|
+
|
|
98
|
+
const makeFetcher = () => {
|
|
99
|
+
if (!session || !session.token) return null;
|
|
100
|
+
return () => fetchAidenIdCredentials({ apiUrl: session.apiUrl, token: session.token });
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
104
|
+
apiKey: options.apiKey,
|
|
105
|
+
orgId: options.orgId,
|
|
106
|
+
projectId: options.projectId,
|
|
107
|
+
env: process.env,
|
|
108
|
+
requireAll: false,
|
|
109
|
+
session,
|
|
110
|
+
fetchCredentials: makeFetcher(),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
if (!options.execute) {
|
|
114
|
+
const result = {
|
|
115
|
+
command: "ai provision-email",
|
|
116
|
+
execute: false,
|
|
117
|
+
apiUrl,
|
|
118
|
+
idempotencyKey,
|
|
119
|
+
requestPath,
|
|
120
|
+
credentialsMissing: resolvedCredentials.missing,
|
|
121
|
+
curlPreview: buildCurlPreview({
|
|
122
|
+
apiUrl,
|
|
123
|
+
idempotencyKey,
|
|
124
|
+
requestPath,
|
|
125
|
+
}),
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
if (emitJson) {
|
|
129
|
+
console.log(JSON.stringify(result, null, 2));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
console.log(pc.bold("AIdenID provision request artifact created (dry-run)"));
|
|
134
|
+
console.log(pc.gray(`Request: ${requestPath}`));
|
|
135
|
+
console.log(pc.gray(`API: ${apiUrl}`));
|
|
136
|
+
console.log(pc.gray(`Idempotency-Key: ${idempotencyKey}`));
|
|
137
|
+
if (resolvedCredentials.missing.length > 0) {
|
|
138
|
+
console.log(
|
|
139
|
+
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
console.log(pc.gray("Execute preview:"));
|
|
143
|
+
console.log(result.curlPreview);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const requiredCredentials = await resolveAidenIdCredentials({
|
|
148
|
+
apiKey: options.apiKey,
|
|
149
|
+
orgId: options.orgId,
|
|
150
|
+
projectId: options.projectId,
|
|
151
|
+
env: process.env,
|
|
152
|
+
requireAll: true,
|
|
153
|
+
session,
|
|
154
|
+
fetchCredentials: makeFetcher(),
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const execution = await provisionEmailIdentity({
|
|
158
|
+
apiUrl,
|
|
159
|
+
apiKey: requiredCredentials.apiKey,
|
|
160
|
+
orgId: requiredCredentials.orgId,
|
|
161
|
+
projectId: requiredCredentials.projectId,
|
|
162
|
+
idempotencyKey,
|
|
163
|
+
payload,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
const responsePath = path.join(artifactsDir, `response-${stamp}.json`);
|
|
167
|
+
await writeArtifact(responsePath, {
|
|
168
|
+
receivedAt: new Date().toISOString(),
|
|
169
|
+
apiUrl,
|
|
170
|
+
idempotencyKey,
|
|
171
|
+
response: execution.response,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
const responseIdentity = execution.response || {};
|
|
175
|
+
const registryUpdate = await recordProvisionedIdentity({
|
|
176
|
+
outputRoot,
|
|
177
|
+
response: execution.response || {},
|
|
178
|
+
context: {
|
|
179
|
+
apiUrl,
|
|
180
|
+
orgId: requiredCredentials.orgId,
|
|
181
|
+
projectId: requiredCredentials.projectId,
|
|
182
|
+
idempotencyKey,
|
|
183
|
+
tags: payload.tags,
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
const result = {
|
|
187
|
+
command: "ai provision-email",
|
|
188
|
+
execute: true,
|
|
189
|
+
apiUrl,
|
|
190
|
+
idempotencyKey,
|
|
191
|
+
requestPath,
|
|
192
|
+
responsePath,
|
|
193
|
+
identity: {
|
|
194
|
+
id: String(responseIdentity.id || "").trim() || null,
|
|
195
|
+
emailAddress: String(responseIdentity.emailAddress || "").trim() || null,
|
|
196
|
+
status: String(responseIdentity.status || "").trim() || null,
|
|
197
|
+
expiresAt: responseIdentity.expiresAt || null,
|
|
198
|
+
projectId: responseIdentity.projectId || null,
|
|
199
|
+
},
|
|
200
|
+
response: execution.response,
|
|
201
|
+
identityRegistryPath: registryUpdate.registryPath,
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
if (emitJson) {
|
|
205
|
+
console.log(JSON.stringify(result, null, 2));
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
console.log(pc.bold("AIdenID identity provisioned"));
|
|
210
|
+
console.log(pc.gray(`Request: ${requestPath}`));
|
|
211
|
+
console.log(pc.gray(`Response: ${responsePath}`));
|
|
212
|
+
if (result.identity.id || result.identity.emailAddress) {
|
|
213
|
+
console.log(
|
|
214
|
+
pc.green(
|
|
215
|
+
`${result.identity.id || "unknown-id"} | ${result.identity.emailAddress || "unknown-email"} | ${
|
|
216
|
+
result.identity.status || "unknown-status"
|
|
217
|
+
}`
|
|
218
|
+
)
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export function registerAiProvisionAndGovernanceCommands(ai) {
|
|
224
|
+
addProvisionEmailOptions(
|
|
225
|
+
ai.command("provision-email")
|
|
226
|
+
.alias("provision")
|
|
227
|
+
.description("Provision an AIdenID identity payload (dry-run by default, optional live execute)")
|
|
228
|
+
).action(provisionEmailAction);
|
|
229
|
+
|
|
230
|
+
const identity = ai.command("identity").description("AIdenID identity lifecycle commands");
|
|
231
|
+
|
|
232
|
+
addProvisionEmailOptions(
|
|
233
|
+
identity.command("provision")
|
|
234
|
+
.description("Provision an AIdenID identity (alias for 'sl ai provision-email')")
|
|
235
|
+
).action(provisionEmailAction);
|
|
236
|
+
const domain = identity.command("domain").description("AIdenID domain governance commands");
|
|
237
|
+
const target = identity.command("target").description("AIdenID target governance commands");
|
|
238
|
+
const site = identity.command("site").description("AIdenID temporary callback domain commands");
|
|
239
|
+
const legalHold = identity.command("legal-hold").description("Identity legal-hold controls");
|
|
240
|
+
|
|
241
|
+
domain
|
|
242
|
+
.command("create")
|
|
243
|
+
.description("Create a domain registration and proof challenge (dry-run by default)")
|
|
244
|
+
.argument("<domainName>", "Domain hostname")
|
|
245
|
+
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
246
|
+
.option("--output-dir <path>", "Optional artifact output root override")
|
|
247
|
+
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
248
|
+
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
249
|
+
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
250
|
+
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
251
|
+
.option("--trust-class <value>", "Domain trust class", "BYOD")
|
|
252
|
+
.option("--verification-method <value>", "Domain verification method", "DNS_TXT")
|
|
253
|
+
.option("--challenge-value <value>", "Explicit challenge value override")
|
|
254
|
+
.option("--proof-ttl-hours <hours>", "Proof TTL hours", "24")
|
|
255
|
+
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
256
|
+
.option("--execute", "Execute live API call")
|
|
257
|
+
.option("--json", "Emit machine-readable output")
|
|
258
|
+
.action(async (domainName, options, command) => {
|
|
259
|
+
const emitJson = shouldEmitJson(options, command);
|
|
260
|
+
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
261
|
+
const outputRoot = await resolveOutputRoot({
|
|
262
|
+
cwd: targetPath,
|
|
263
|
+
outputDirOverride: options.outputDir,
|
|
264
|
+
env: process.env,
|
|
265
|
+
});
|
|
266
|
+
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
267
|
+
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
268
|
+
const proofTtlHours = parsePositiveInteger(options.proofTtlHours, "proofTtlHours", 24);
|
|
269
|
+
const payload = {
|
|
270
|
+
domainName: String(domainName || "").trim(),
|
|
271
|
+
trustClass: String(options.trustClass || "BYOD").trim() || "BYOD",
|
|
272
|
+
verificationMethod:
|
|
273
|
+
String(options.verificationMethod || "DNS_TXT").trim() || "DNS_TXT",
|
|
274
|
+
challengeValue: String(options.challengeValue || "").trim() || null,
|
|
275
|
+
proofTtlHours,
|
|
276
|
+
};
|
|
277
|
+
if (!payload.domainName) {
|
|
278
|
+
throw new Error("domainName is required.");
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const artifactsDir = path.join(outputRoot, "aidenid", "domain-create");
|
|
282
|
+
const stamp = stableTimestampForFile();
|
|
283
|
+
const requestPath = path.join(artifactsDir, `request-${encodeURIComponent(payload.domainName)}-${stamp}.json`);
|
|
284
|
+
await writeArtifact(requestPath, {
|
|
285
|
+
generatedAt: new Date().toISOString(),
|
|
286
|
+
apiUrl,
|
|
287
|
+
idempotencyKey,
|
|
288
|
+
payload,
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
292
|
+
apiKey: options.apiKey,
|
|
293
|
+
orgId: options.orgId,
|
|
294
|
+
projectId: options.projectId,
|
|
295
|
+
env: process.env,
|
|
296
|
+
requireAll: false,
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
if (!options.execute) {
|
|
300
|
+
const result = {
|
|
301
|
+
command: "ai identity domain create",
|
|
302
|
+
execute: false,
|
|
303
|
+
apiUrl,
|
|
304
|
+
idempotencyKey,
|
|
305
|
+
requestPath,
|
|
306
|
+
payload,
|
|
307
|
+
credentialsMissing: resolvedCredentials.missing,
|
|
308
|
+
curlPreview: [
|
|
309
|
+
`curl -X POST ${apiUrl}/v1/domains \\`,
|
|
310
|
+
` -H \"Authorization: Bearer $AIDENID_API_KEY\" \\`,
|
|
311
|
+
` -H \"X-Org-Id: $AIDENID_ORG_ID\" \\`,
|
|
312
|
+
` -H \"X-Project-Id: $AIDENID_PROJECT_ID\" \\`,
|
|
313
|
+
` -H \"Idempotency-Key: ${idempotencyKey}\" \\`,
|
|
314
|
+
` -H \"Content-Type: application/json\" \\`,
|
|
315
|
+
` --data @${String(requestPath || "").replace(/\\/g, "/")}`,
|
|
316
|
+
].join("\n"),
|
|
317
|
+
};
|
|
318
|
+
if (emitJson) {
|
|
319
|
+
console.log(JSON.stringify(result, null, 2));
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
console.log(pc.bold("AIdenID domain create artifact generated (dry-run)"));
|
|
323
|
+
console.log(pc.gray(`Request: ${requestPath}`));
|
|
324
|
+
if (resolvedCredentials.missing.length > 0) {
|
|
325
|
+
console.log(
|
|
326
|
+
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
console.log(result.curlPreview);
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const requiredCredentials = await resolveAidenIdCredentials({
|
|
334
|
+
apiKey: options.apiKey,
|
|
335
|
+
orgId: options.orgId,
|
|
336
|
+
projectId: options.projectId,
|
|
337
|
+
env: process.env,
|
|
338
|
+
requireAll: true,
|
|
339
|
+
});
|
|
340
|
+
const execution = await createDomain({
|
|
341
|
+
apiUrl,
|
|
342
|
+
apiKey: requiredCredentials.apiKey,
|
|
343
|
+
orgId: requiredCredentials.orgId,
|
|
344
|
+
projectId: requiredCredentials.projectId,
|
|
345
|
+
idempotencyKey,
|
|
346
|
+
payload,
|
|
347
|
+
});
|
|
348
|
+
const responsePath = path.join(
|
|
349
|
+
artifactsDir,
|
|
350
|
+
`response-${encodeURIComponent(payload.domainName)}-${stamp}.json`
|
|
351
|
+
);
|
|
352
|
+
await writeArtifact(responsePath, {
|
|
353
|
+
receivedAt: new Date().toISOString(),
|
|
354
|
+
apiUrl,
|
|
355
|
+
idempotencyKey,
|
|
356
|
+
response: execution.response,
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
const proofResponse = execution.response || {};
|
|
360
|
+
const registryUpdate = await recordDomainProofResponse({
|
|
361
|
+
outputRoot,
|
|
362
|
+
domain: proofResponse.domain || {},
|
|
363
|
+
proof: proofResponse,
|
|
364
|
+
context: {
|
|
365
|
+
source: "domain-create",
|
|
366
|
+
idempotencyKey,
|
|
367
|
+
projectId: requiredCredentials.projectId,
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
const result = {
|
|
371
|
+
command: "ai identity domain create",
|
|
372
|
+
execute: true,
|
|
373
|
+
apiUrl,
|
|
374
|
+
idempotencyKey,
|
|
375
|
+
requestPath,
|
|
376
|
+
responsePath,
|
|
377
|
+
domain: proofResponse.domain || null,
|
|
378
|
+
proof: {
|
|
379
|
+
proofId: proofResponse.proofId || null,
|
|
380
|
+
challengeValue: proofResponse.challengeValue || null,
|
|
381
|
+
proofStatus: proofResponse.proofStatus || null,
|
|
382
|
+
proofExpiresAt: proofResponse.proofExpiresAt || null,
|
|
383
|
+
},
|
|
384
|
+
registryPath: registryUpdate.registryPath,
|
|
385
|
+
};
|
|
386
|
+
if (emitJson) {
|
|
387
|
+
console.log(JSON.stringify(result, null, 2));
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
console.log(pc.bold("AIdenID domain created"));
|
|
391
|
+
console.log(pc.gray(`Response: ${responsePath}`));
|
|
392
|
+
console.log(
|
|
393
|
+
`${String(result.domain?.id || "unknown-domain")} | ${String(result.domain?.domainName || payload.domainName)}`
|
|
394
|
+
);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
domain
|
|
398
|
+
.command("verify")
|
|
399
|
+
.description("Verify domain proof challenge (dry-run by default)")
|
|
400
|
+
.argument("<domainId>", "Domain id")
|
|
401
|
+
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
402
|
+
.option("--output-dir <path>", "Optional artifact output root override")
|
|
403
|
+
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
404
|
+
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
405
|
+
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
406
|
+
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
407
|
+
.option("--method <value>", "Verification method", "DNS_TXT")
|
|
408
|
+
.option("--challenge-value <value>", "Challenge value override (fallback: local registry)")
|
|
409
|
+
.option("--proof-value <value>", "Proof value", "txt-verification-record")
|
|
410
|
+
.option("--verification-source <value>", "Verification source", "sentinelayer-cli")
|
|
411
|
+
.option("--expires-hours <hours>", "Proof expiration in hours", "24")
|
|
412
|
+
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
413
|
+
.option("--execute", "Execute live API call")
|
|
414
|
+
.option("--json", "Emit machine-readable output")
|
|
415
|
+
.action(async (domainId, options, command) => {
|
|
416
|
+
const emitJson = shouldEmitJson(options, command);
|
|
417
|
+
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
418
|
+
const outputRoot = await resolveOutputRoot({
|
|
419
|
+
cwd: targetPath,
|
|
420
|
+
outputDirOverride: options.outputDir,
|
|
421
|
+
env: process.env,
|
|
422
|
+
});
|
|
423
|
+
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
424
|
+
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
425
|
+
const tracked = await getDomainById({ outputRoot, domainId });
|
|
426
|
+
const challengeValue =
|
|
427
|
+
String(options.challengeValue || "").trim() ||
|
|
428
|
+
String(tracked.domain?.challengeValue || "").trim() ||
|
|
429
|
+
null;
|
|
430
|
+
if (!challengeValue) {
|
|
431
|
+
throw new Error(
|
|
432
|
+
`challengeValue is required. Provide --challenge-value or run domain create first for '${domainId}'.`
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
const payload = {
|
|
436
|
+
method: String(options.method || "DNS_TXT").trim() || "DNS_TXT",
|
|
437
|
+
challengeValue,
|
|
438
|
+
proofValue: String(options.proofValue || "txt-verification-record").trim() || null,
|
|
439
|
+
verificationSource:
|
|
440
|
+
String(options.verificationSource || "sentinelayer-cli").trim() || null,
|
|
441
|
+
expiresHours: parsePositiveInteger(options.expiresHours, "expiresHours", 24),
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
const artifactsDir = path.join(outputRoot, "aidenid", "domain-verify");
|
|
445
|
+
const stamp = stableTimestampForFile();
|
|
446
|
+
const requestPath = path.join(artifactsDir, `request-${encodeURIComponent(domainId)}-${stamp}.json`);
|
|
447
|
+
await writeArtifact(requestPath, {
|
|
448
|
+
generatedAt: new Date().toISOString(),
|
|
449
|
+
apiUrl,
|
|
450
|
+
idempotencyKey,
|
|
451
|
+
domainId,
|
|
452
|
+
payload,
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
456
|
+
apiKey: options.apiKey,
|
|
457
|
+
orgId: options.orgId,
|
|
458
|
+
projectId: options.projectId || tracked.domain?.projectId,
|
|
459
|
+
env: process.env,
|
|
460
|
+
requireAll: false,
|
|
461
|
+
});
|
|
462
|
+
if (!options.execute) {
|
|
463
|
+
const result = {
|
|
464
|
+
command: "ai identity domain verify",
|
|
465
|
+
execute: false,
|
|
466
|
+
domainId,
|
|
467
|
+
apiUrl,
|
|
468
|
+
idempotencyKey,
|
|
469
|
+
requestPath,
|
|
470
|
+
payload,
|
|
471
|
+
credentialsMissing: resolvedCredentials.missing,
|
|
472
|
+
};
|
|
473
|
+
if (emitJson) {
|
|
474
|
+
console.log(JSON.stringify(result, null, 2));
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
console.log(pc.bold("AIdenID domain verify artifact generated (dry-run)"));
|
|
478
|
+
console.log(pc.gray(`Request: ${requestPath}`));
|
|
479
|
+
if (resolvedCredentials.missing.length > 0) {
|
|
480
|
+
console.log(
|
|
481
|
+
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const requiredCredentials = await resolveAidenIdCredentials({
|
|
488
|
+
apiKey: options.apiKey,
|
|
489
|
+
orgId: options.orgId,
|
|
490
|
+
projectId: options.projectId || tracked.domain?.projectId,
|
|
491
|
+
env: process.env,
|
|
492
|
+
requireAll: true,
|
|
493
|
+
});
|
|
494
|
+
const execution = await verifyDomain({
|
|
495
|
+
apiUrl,
|
|
496
|
+
apiKey: requiredCredentials.apiKey,
|
|
497
|
+
orgId: requiredCredentials.orgId,
|
|
498
|
+
projectId: requiredCredentials.projectId,
|
|
499
|
+
domainId,
|
|
500
|
+
idempotencyKey,
|
|
501
|
+
payload,
|
|
502
|
+
});
|
|
503
|
+
const responsePath = path.join(
|
|
504
|
+
artifactsDir,
|
|
505
|
+
`response-${encodeURIComponent(domainId)}-${stamp}.json`
|
|
506
|
+
);
|
|
507
|
+
await writeArtifact(responsePath, {
|
|
508
|
+
receivedAt: new Date().toISOString(),
|
|
509
|
+
apiUrl,
|
|
510
|
+
idempotencyKey,
|
|
511
|
+
domainId,
|
|
512
|
+
response: execution.response,
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
const proofResponse = execution.response || {};
|
|
516
|
+
const registryUpdate = await recordDomainProofResponse({
|
|
517
|
+
outputRoot,
|
|
518
|
+
domain: proofResponse.domain || {},
|
|
519
|
+
proof: proofResponse,
|
|
520
|
+
context: {
|
|
521
|
+
source: "domain-verify",
|
|
522
|
+
idempotencyKey,
|
|
523
|
+
projectId: requiredCredentials.projectId,
|
|
524
|
+
},
|
|
525
|
+
});
|
|
526
|
+
const result = {
|
|
527
|
+
command: "ai identity domain verify",
|
|
528
|
+
execute: true,
|
|
529
|
+
domainId,
|
|
530
|
+
apiUrl,
|
|
531
|
+
idempotencyKey,
|
|
532
|
+
requestPath,
|
|
533
|
+
responsePath,
|
|
534
|
+
domain: proofResponse.domain || null,
|
|
535
|
+
proof: {
|
|
536
|
+
proofId: proofResponse.proofId || null,
|
|
537
|
+
challengeValue: proofResponse.challengeValue || null,
|
|
538
|
+
proofStatus: proofResponse.proofStatus || null,
|
|
539
|
+
proofExpiresAt: proofResponse.proofExpiresAt || null,
|
|
540
|
+
},
|
|
541
|
+
registryPath: registryUpdate.registryPath,
|
|
542
|
+
};
|
|
543
|
+
if (emitJson) {
|
|
544
|
+
console.log(JSON.stringify(result, null, 2));
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
console.log(pc.bold("AIdenID domain verified"));
|
|
548
|
+
console.log(pc.gray(`Response: ${responsePath}`));
|
|
549
|
+
console.log(
|
|
550
|
+
`${String(result.domain?.id || domainId)} | verification=${String(result.domain?.verificationStatus || "UNKNOWN")}`
|
|
551
|
+
);
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
domain
|
|
555
|
+
.command("freeze")
|
|
556
|
+
.description("Freeze a domain for containment (dry-run by default)")
|
|
557
|
+
.argument("<domainId>", "Domain id")
|
|
558
|
+
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
559
|
+
.option("--output-dir <path>", "Optional artifact output root override")
|
|
560
|
+
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
561
|
+
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
562
|
+
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
563
|
+
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
564
|
+
.option("--reason <text>", "Freeze reason", "incident containment")
|
|
565
|
+
.option("--pool-isolated", "Isolate the domain pool", true)
|
|
566
|
+
.option("--no-pool-isolated", "Do not isolate the domain pool")
|
|
567
|
+
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
568
|
+
.option("--execute", "Execute live API call")
|
|
569
|
+
.option("--json", "Emit machine-readable output")
|
|
570
|
+
.action(async (domainId, options, command) => {
|
|
571
|
+
const emitJson = shouldEmitJson(options, command);
|
|
572
|
+
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
573
|
+
const outputRoot = await resolveOutputRoot({
|
|
574
|
+
cwd: targetPath,
|
|
575
|
+
outputDirOverride: options.outputDir,
|
|
576
|
+
env: process.env,
|
|
577
|
+
});
|
|
578
|
+
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
579
|
+
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
580
|
+
const tracked = await getDomainById({ outputRoot, domainId });
|
|
581
|
+
const payload = {
|
|
582
|
+
reason: String(options.reason || "").trim() || "incident containment",
|
|
583
|
+
poolIsolated: Boolean(options.poolIsolated),
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
const artifactsDir = path.join(outputRoot, "aidenid", "domain-freeze");
|
|
587
|
+
const stamp = stableTimestampForFile();
|
|
588
|
+
const requestPath = path.join(artifactsDir, `request-${encodeURIComponent(domainId)}-${stamp}.json`);
|
|
589
|
+
await writeArtifact(requestPath, {
|
|
590
|
+
generatedAt: new Date().toISOString(),
|
|
591
|
+
apiUrl,
|
|
592
|
+
idempotencyKey,
|
|
593
|
+
domainId,
|
|
594
|
+
payload,
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
598
|
+
apiKey: options.apiKey,
|
|
599
|
+
orgId: options.orgId,
|
|
600
|
+
projectId: options.projectId || tracked.domain?.projectId,
|
|
601
|
+
env: process.env,
|
|
602
|
+
requireAll: false,
|
|
603
|
+
});
|
|
604
|
+
if (!options.execute) {
|
|
605
|
+
const result = {
|
|
606
|
+
command: "ai identity domain freeze",
|
|
607
|
+
execute: false,
|
|
608
|
+
domainId,
|
|
609
|
+
apiUrl,
|
|
610
|
+
idempotencyKey,
|
|
611
|
+
requestPath,
|
|
612
|
+
payload,
|
|
613
|
+
credentialsMissing: resolvedCredentials.missing,
|
|
614
|
+
};
|
|
615
|
+
if (emitJson) {
|
|
616
|
+
console.log(JSON.stringify(result, null, 2));
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
console.log(pc.bold("AIdenID domain freeze artifact generated (dry-run)"));
|
|
620
|
+
console.log(pc.gray(`Request: ${requestPath}`));
|
|
621
|
+
if (resolvedCredentials.missing.length > 0) {
|
|
622
|
+
console.log(
|
|
623
|
+
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
624
|
+
);
|
|
625
|
+
}
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
const requiredCredentials = await resolveAidenIdCredentials({
|
|
630
|
+
apiKey: options.apiKey,
|
|
631
|
+
orgId: options.orgId,
|
|
632
|
+
projectId: options.projectId || tracked.domain?.projectId,
|
|
633
|
+
env: process.env,
|
|
634
|
+
requireAll: true,
|
|
635
|
+
});
|
|
636
|
+
const execution = await freezeDomain({
|
|
637
|
+
apiUrl,
|
|
638
|
+
apiKey: requiredCredentials.apiKey,
|
|
639
|
+
orgId: requiredCredentials.orgId,
|
|
640
|
+
projectId: requiredCredentials.projectId,
|
|
641
|
+
domainId,
|
|
642
|
+
idempotencyKey,
|
|
643
|
+
payload,
|
|
644
|
+
});
|
|
645
|
+
const responsePath = path.join(
|
|
646
|
+
artifactsDir,
|
|
647
|
+
`response-${encodeURIComponent(domainId)}-${stamp}.json`
|
|
648
|
+
);
|
|
649
|
+
await writeArtifact(responsePath, {
|
|
650
|
+
receivedAt: new Date().toISOString(),
|
|
651
|
+
apiUrl,
|
|
652
|
+
idempotencyKey,
|
|
653
|
+
domainId,
|
|
654
|
+
response: execution.response,
|
|
655
|
+
});
|
|
656
|
+
|
|
657
|
+
const registryUpdate = await recordDomainProofResponse({
|
|
658
|
+
outputRoot,
|
|
659
|
+
domain: execution.response || {},
|
|
660
|
+
proof: {},
|
|
661
|
+
context: {
|
|
662
|
+
source: "domain-freeze",
|
|
663
|
+
idempotencyKey,
|
|
664
|
+
projectId: requiredCredentials.projectId,
|
|
665
|
+
},
|
|
666
|
+
});
|
|
667
|
+
const result = {
|
|
668
|
+
command: "ai identity domain freeze",
|
|
669
|
+
execute: true,
|
|
670
|
+
domainId,
|
|
671
|
+
apiUrl,
|
|
672
|
+
idempotencyKey,
|
|
673
|
+
requestPath,
|
|
674
|
+
responsePath,
|
|
675
|
+
domain: execution.response || null,
|
|
676
|
+
registryPath: registryUpdate.registryPath,
|
|
677
|
+
};
|
|
678
|
+
if (emitJson) {
|
|
679
|
+
console.log(JSON.stringify(result, null, 2));
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
console.log(pc.bold("AIdenID domain frozen"));
|
|
683
|
+
console.log(pc.gray(`Response: ${responsePath}`));
|
|
684
|
+
console.log(
|
|
685
|
+
`${String(result.domain?.id || domainId)} | freeze=${String(result.domain?.freezeStatus || "UNKNOWN")}`
|
|
686
|
+
);
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
target
|
|
690
|
+
.command("create")
|
|
691
|
+
.description("Create a managed target and proof challenge (dry-run by default)")
|
|
692
|
+
.argument("<host>", "Target host")
|
|
693
|
+
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
694
|
+
.option("--output-dir <path>", "Optional artifact output root override")
|
|
695
|
+
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
696
|
+
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
697
|
+
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
698
|
+
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
699
|
+
.option("--domain-id <id>", "Optional domain id")
|
|
700
|
+
.option("--allowed-paths <csv>", "Allowed paths", "/")
|
|
701
|
+
.option("--allowed-methods <csv>", "Allowed methods", "GET")
|
|
702
|
+
.option("--allowed-scenarios <csv>", "Allowed scenarios", "form_boundary_fuzz")
|
|
703
|
+
.option("--max-rps <count>", "Maximum requests per second", "5")
|
|
704
|
+
.option("--max-concurrency <count>", "Maximum concurrency", "5")
|
|
705
|
+
.option("--stop-conditions-json <json>", "JSON object for stop conditions", "{}")
|
|
706
|
+
.option("--maintenance-window-json <json>", "JSON object for maintenance window", "{}")
|
|
707
|
+
.option("--contact-json <json>", "JSON object for contact metadata", "{}")
|
|
708
|
+
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
709
|
+
.option("--execute", "Execute live API call")
|
|
710
|
+
.option("--json", "Emit machine-readable output")
|
|
711
|
+
.action(async (host, options, command) => {
|
|
712
|
+
const emitJson = shouldEmitJson(options, command);
|
|
713
|
+
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
714
|
+
const outputRoot = await resolveOutputRoot({
|
|
715
|
+
cwd: targetPath,
|
|
716
|
+
outputDirOverride: options.outputDir,
|
|
717
|
+
env: process.env,
|
|
718
|
+
});
|
|
719
|
+
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
720
|
+
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
721
|
+
const payload = {
|
|
722
|
+
host: String(host || "").trim(),
|
|
723
|
+
domainId: String(options.domainId || "").trim() || null,
|
|
724
|
+
maintenanceWindow: parseJsonObject(options.maintenanceWindowJson, "maintenanceWindowJson"),
|
|
725
|
+
contact: parseJsonObject(options.contactJson, "contactJson"),
|
|
726
|
+
policy: {
|
|
727
|
+
allowedPaths: parseCsvTokens(options.allowedPaths, ["/"]),
|
|
728
|
+
allowedMethods: parseCsvTokens(options.allowedMethods, ["GET"]),
|
|
729
|
+
allowedScenarios: parseCsvTokens(options.allowedScenarios, ["form_boundary_fuzz"]),
|
|
730
|
+
maxRps: parsePositiveInteger(options.maxRps, "maxRps", 5),
|
|
731
|
+
maxConcurrency: parsePositiveInteger(options.maxConcurrency, "maxConcurrency", 5),
|
|
732
|
+
stopConditions: parseJsonObject(options.stopConditionsJson, "stopConditionsJson"),
|
|
733
|
+
},
|
|
734
|
+
};
|
|
735
|
+
if (!payload.host) {
|
|
736
|
+
throw new Error("host is required.");
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
const artifactsDir = path.join(outputRoot, "aidenid", "target-create");
|
|
740
|
+
const stamp = stableTimestampForFile();
|
|
741
|
+
const requestPath = path.join(artifactsDir, `request-${encodeURIComponent(payload.host)}-${stamp}.json`);
|
|
742
|
+
await writeArtifact(requestPath, {
|
|
743
|
+
generatedAt: new Date().toISOString(),
|
|
744
|
+
apiUrl,
|
|
745
|
+
idempotencyKey,
|
|
746
|
+
payload,
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
750
|
+
apiKey: options.apiKey,
|
|
751
|
+
orgId: options.orgId,
|
|
752
|
+
projectId: options.projectId,
|
|
753
|
+
env: process.env,
|
|
754
|
+
requireAll: false,
|
|
755
|
+
});
|
|
756
|
+
if (!options.execute) {
|
|
757
|
+
const result = {
|
|
758
|
+
command: "ai identity target create",
|
|
759
|
+
execute: false,
|
|
760
|
+
apiUrl,
|
|
761
|
+
idempotencyKey,
|
|
762
|
+
requestPath,
|
|
763
|
+
payload,
|
|
764
|
+
credentialsMissing: resolvedCredentials.missing,
|
|
765
|
+
};
|
|
766
|
+
if (emitJson) {
|
|
767
|
+
console.log(JSON.stringify(result, null, 2));
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
console.log(pc.bold("AIdenID target create artifact generated (dry-run)"));
|
|
771
|
+
console.log(pc.gray(`Request: ${requestPath}`));
|
|
772
|
+
if (resolvedCredentials.missing.length > 0) {
|
|
773
|
+
console.log(
|
|
774
|
+
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
const requiredCredentials = await resolveAidenIdCredentials({
|
|
781
|
+
apiKey: options.apiKey,
|
|
782
|
+
orgId: options.orgId,
|
|
783
|
+
projectId: options.projectId,
|
|
784
|
+
env: process.env,
|
|
785
|
+
requireAll: true,
|
|
786
|
+
});
|
|
787
|
+
const execution = await createTarget({
|
|
788
|
+
apiUrl,
|
|
789
|
+
apiKey: requiredCredentials.apiKey,
|
|
790
|
+
orgId: requiredCredentials.orgId,
|
|
791
|
+
projectId: requiredCredentials.projectId,
|
|
792
|
+
idempotencyKey,
|
|
793
|
+
payload,
|
|
794
|
+
});
|
|
795
|
+
const responsePath = path.join(
|
|
796
|
+
artifactsDir,
|
|
797
|
+
`response-${encodeURIComponent(payload.host)}-${stamp}.json`
|
|
798
|
+
);
|
|
799
|
+
await writeArtifact(responsePath, {
|
|
800
|
+
receivedAt: new Date().toISOString(),
|
|
801
|
+
apiUrl,
|
|
802
|
+
idempotencyKey,
|
|
803
|
+
response: execution.response,
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
const proofResponse = execution.response || {};
|
|
807
|
+
const registryUpdate = await recordTargetProofResponse({
|
|
808
|
+
outputRoot,
|
|
809
|
+
target: proofResponse.target || {},
|
|
810
|
+
proof: proofResponse,
|
|
811
|
+
context: {
|
|
812
|
+
source: "target-create",
|
|
813
|
+
idempotencyKey,
|
|
814
|
+
projectId: requiredCredentials.projectId,
|
|
815
|
+
domainId: payload.domainId,
|
|
816
|
+
},
|
|
817
|
+
});
|
|
818
|
+
const result = {
|
|
819
|
+
command: "ai identity target create",
|
|
820
|
+
execute: true,
|
|
821
|
+
apiUrl,
|
|
822
|
+
idempotencyKey,
|
|
823
|
+
requestPath,
|
|
824
|
+
responsePath,
|
|
825
|
+
target: proofResponse.target || null,
|
|
826
|
+
proof: {
|
|
827
|
+
proofId: proofResponse.proofId || null,
|
|
828
|
+
challengeValue: proofResponse.challengeValue || null,
|
|
829
|
+
proofStatus: proofResponse.proofStatus || null,
|
|
830
|
+
proofExpiresAt: proofResponse.proofExpiresAt || null,
|
|
831
|
+
},
|
|
832
|
+
registryPath: registryUpdate.registryPath,
|
|
833
|
+
};
|
|
834
|
+
if (emitJson) {
|
|
835
|
+
console.log(JSON.stringify(result, null, 2));
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
console.log(pc.bold("AIdenID target created"));
|
|
839
|
+
console.log(pc.gray(`Response: ${responsePath}`));
|
|
840
|
+
console.log(`${String(result.target?.id || "unknown-target")} | ${String(result.target?.host || payload.host)}`);
|
|
841
|
+
});
|
|
842
|
+
|
|
843
|
+
target
|
|
844
|
+
.command("verify")
|
|
845
|
+
.description("Verify target proof challenge (dry-run by default)")
|
|
846
|
+
.argument("<targetId>", "Target id")
|
|
847
|
+
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
848
|
+
.option("--output-dir <path>", "Optional artifact output root override")
|
|
849
|
+
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
850
|
+
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
851
|
+
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
852
|
+
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
853
|
+
.option("--method <value>", "Verification method", "DNS_TXT")
|
|
854
|
+
.option("--challenge-value <value>", "Challenge value override (fallback: local registry)")
|
|
855
|
+
.option("--proof-value <value>", "Proof value", "target-txt-proof")
|
|
856
|
+
.option("--verification-source <value>", "Verification source", "sentinelayer-cli")
|
|
857
|
+
.option("--expires-hours <hours>", "Proof expiration in hours", "24")
|
|
858
|
+
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
859
|
+
.option("--execute", "Execute live API call")
|
|
860
|
+
.option("--json", "Emit machine-readable output")
|
|
861
|
+
.action(async (targetId, options, command) => {
|
|
862
|
+
const emitJson = shouldEmitJson(options, command);
|
|
863
|
+
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
864
|
+
const outputRoot = await resolveOutputRoot({
|
|
865
|
+
cwd: targetPath,
|
|
866
|
+
outputDirOverride: options.outputDir,
|
|
867
|
+
env: process.env,
|
|
868
|
+
});
|
|
869
|
+
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
870
|
+
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
871
|
+
const tracked = await getTrackedTargetById({ outputRoot, targetId });
|
|
872
|
+
const challengeValue =
|
|
873
|
+
String(options.challengeValue || "").trim() ||
|
|
874
|
+
String(tracked.target?.challengeValue || "").trim() ||
|
|
875
|
+
null;
|
|
876
|
+
if (!challengeValue) {
|
|
877
|
+
throw new Error(
|
|
878
|
+
`challengeValue is required. Provide --challenge-value or run target create first for '${targetId}'.`
|
|
879
|
+
);
|
|
880
|
+
}
|
|
881
|
+
const payload = {
|
|
882
|
+
method: String(options.method || "DNS_TXT").trim() || "DNS_TXT",
|
|
883
|
+
challengeValue,
|
|
884
|
+
proofValue: String(options.proofValue || "target-txt-proof").trim() || null,
|
|
885
|
+
verificationSource:
|
|
886
|
+
String(options.verificationSource || "sentinelayer-cli").trim() || null,
|
|
887
|
+
expiresHours: parsePositiveInteger(options.expiresHours, "expiresHours", 24),
|
|
888
|
+
};
|
|
889
|
+
|
|
890
|
+
const artifactsDir = path.join(outputRoot, "aidenid", "target-verify");
|
|
891
|
+
const stamp = stableTimestampForFile();
|
|
892
|
+
const requestPath = path.join(artifactsDir, `request-${encodeURIComponent(targetId)}-${stamp}.json`);
|
|
893
|
+
await writeArtifact(requestPath, {
|
|
894
|
+
generatedAt: new Date().toISOString(),
|
|
895
|
+
apiUrl,
|
|
896
|
+
idempotencyKey,
|
|
897
|
+
targetId,
|
|
898
|
+
payload,
|
|
899
|
+
});
|
|
900
|
+
|
|
901
|
+
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
902
|
+
apiKey: options.apiKey,
|
|
903
|
+
orgId: options.orgId,
|
|
904
|
+
projectId: options.projectId || tracked.target?.projectId,
|
|
905
|
+
env: process.env,
|
|
906
|
+
requireAll: false,
|
|
907
|
+
});
|
|
908
|
+
if (!options.execute) {
|
|
909
|
+
const result = {
|
|
910
|
+
command: "ai identity target verify",
|
|
911
|
+
execute: false,
|
|
912
|
+
targetId,
|
|
913
|
+
apiUrl,
|
|
914
|
+
idempotencyKey,
|
|
915
|
+
requestPath,
|
|
916
|
+
payload,
|
|
917
|
+
credentialsMissing: resolvedCredentials.missing,
|
|
918
|
+
};
|
|
919
|
+
if (emitJson) {
|
|
920
|
+
console.log(JSON.stringify(result, null, 2));
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
console.log(pc.bold("AIdenID target verify artifact generated (dry-run)"));
|
|
924
|
+
console.log(pc.gray(`Request: ${requestPath}`));
|
|
925
|
+
if (resolvedCredentials.missing.length > 0) {
|
|
926
|
+
console.log(
|
|
927
|
+
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
const requiredCredentials = await resolveAidenIdCredentials({
|
|
934
|
+
apiKey: options.apiKey,
|
|
935
|
+
orgId: options.orgId,
|
|
936
|
+
projectId: options.projectId || tracked.target?.projectId,
|
|
937
|
+
env: process.env,
|
|
938
|
+
requireAll: true,
|
|
939
|
+
});
|
|
940
|
+
const execution = await verifyTarget({
|
|
941
|
+
apiUrl,
|
|
942
|
+
apiKey: requiredCredentials.apiKey,
|
|
943
|
+
orgId: requiredCredentials.orgId,
|
|
944
|
+
projectId: requiredCredentials.projectId,
|
|
945
|
+
targetId,
|
|
946
|
+
idempotencyKey,
|
|
947
|
+
payload,
|
|
948
|
+
});
|
|
949
|
+
const responsePath = path.join(
|
|
950
|
+
artifactsDir,
|
|
951
|
+
`response-${encodeURIComponent(targetId)}-${stamp}.json`
|
|
952
|
+
);
|
|
953
|
+
await writeArtifact(responsePath, {
|
|
954
|
+
receivedAt: new Date().toISOString(),
|
|
955
|
+
apiUrl,
|
|
956
|
+
idempotencyKey,
|
|
957
|
+
targetId,
|
|
958
|
+
response: execution.response,
|
|
959
|
+
});
|
|
960
|
+
|
|
961
|
+
const proofResponse = execution.response || {};
|
|
962
|
+
const registryUpdate = await recordTargetProofResponse({
|
|
963
|
+
outputRoot,
|
|
964
|
+
target: proofResponse.target || {},
|
|
965
|
+
proof: proofResponse,
|
|
966
|
+
context: {
|
|
967
|
+
source: "target-verify",
|
|
968
|
+
idempotencyKey,
|
|
969
|
+
projectId: requiredCredentials.projectId,
|
|
970
|
+
},
|
|
971
|
+
});
|
|
972
|
+
const result = {
|
|
973
|
+
command: "ai identity target verify",
|
|
974
|
+
execute: true,
|
|
975
|
+
targetId,
|
|
976
|
+
apiUrl,
|
|
977
|
+
idempotencyKey,
|
|
978
|
+
requestPath,
|
|
979
|
+
responsePath,
|
|
980
|
+
target: proofResponse.target || null,
|
|
981
|
+
proof: {
|
|
982
|
+
proofId: proofResponse.proofId || null,
|
|
983
|
+
challengeValue: proofResponse.challengeValue || null,
|
|
984
|
+
proofStatus: proofResponse.proofStatus || null,
|
|
985
|
+
proofExpiresAt: proofResponse.proofExpiresAt || null,
|
|
986
|
+
},
|
|
987
|
+
registryPath: registryUpdate.registryPath,
|
|
988
|
+
};
|
|
989
|
+
if (emitJson) {
|
|
990
|
+
console.log(JSON.stringify(result, null, 2));
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
console.log(pc.bold("AIdenID target verified"));
|
|
994
|
+
console.log(pc.gray(`Response: ${responsePath}`));
|
|
995
|
+
console.log(
|
|
996
|
+
`${String(result.target?.id || targetId)} | verification=${String(result.target?.verificationStatus || "UNKNOWN")}`
|
|
997
|
+
);
|
|
998
|
+
});
|
|
999
|
+
|
|
1000
|
+
target
|
|
1001
|
+
.command("show")
|
|
1002
|
+
.description("Show managed target details")
|
|
1003
|
+
.argument("<targetId>", "Target id")
|
|
1004
|
+
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
1005
|
+
.option("--output-dir <path>", "Optional artifact output root override")
|
|
1006
|
+
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
1007
|
+
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
1008
|
+
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
1009
|
+
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
1010
|
+
.option("--json", "Emit machine-readable output")
|
|
1011
|
+
.action(async (targetId, options, command) => {
|
|
1012
|
+
const emitJson = shouldEmitJson(options, command);
|
|
1013
|
+
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
1014
|
+
const outputRoot = await resolveOutputRoot({
|
|
1015
|
+
cwd: targetPath,
|
|
1016
|
+
outputDirOverride: options.outputDir,
|
|
1017
|
+
env: process.env,
|
|
1018
|
+
});
|
|
1019
|
+
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
1020
|
+
const tracked = await getTrackedTargetById({ outputRoot, targetId });
|
|
1021
|
+
const credentials = await resolveAidenIdCredentials({
|
|
1022
|
+
apiKey: options.apiKey,
|
|
1023
|
+
orgId: options.orgId,
|
|
1024
|
+
projectId: options.projectId || tracked.target?.projectId,
|
|
1025
|
+
env: process.env,
|
|
1026
|
+
requireAll: true,
|
|
1027
|
+
});
|
|
1028
|
+
|
|
1029
|
+
const execution = await getTarget({
|
|
1030
|
+
apiUrl,
|
|
1031
|
+
apiKey: credentials.apiKey,
|
|
1032
|
+
orgId: credentials.orgId,
|
|
1033
|
+
projectId: credentials.projectId,
|
|
1034
|
+
targetId,
|
|
1035
|
+
});
|
|
1036
|
+
const stamp = stableTimestampForFile();
|
|
1037
|
+
const artifactsDir = path.join(outputRoot, "aidenid", "target-show");
|
|
1038
|
+
const outputPath = path.join(artifactsDir, `target-${encodeURIComponent(targetId)}-${stamp}.json`);
|
|
1039
|
+
await writeArtifact(outputPath, {
|
|
1040
|
+
generatedAt: new Date().toISOString(),
|
|
1041
|
+
targetId,
|
|
1042
|
+
response: execution.response,
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1045
|
+
const registryUpdate = await recordTargetProofResponse({
|
|
1046
|
+
outputRoot,
|
|
1047
|
+
target: execution.response || {},
|
|
1048
|
+
proof: {},
|
|
1049
|
+
context: {
|
|
1050
|
+
source: "target-show",
|
|
1051
|
+
projectId: credentials.projectId,
|
|
1052
|
+
},
|
|
1053
|
+
});
|
|
1054
|
+
const payload = {
|
|
1055
|
+
command: "ai identity target show",
|
|
1056
|
+
targetId,
|
|
1057
|
+
outputPath,
|
|
1058
|
+
target: execution.response,
|
|
1059
|
+
registryPath: registryUpdate.registryPath,
|
|
1060
|
+
};
|
|
1061
|
+
if (emitJson) {
|
|
1062
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
console.log(pc.bold("AIdenID target"));
|
|
1067
|
+
console.log(pc.gray(`Artifact: ${outputPath}`));
|
|
1068
|
+
console.log(
|
|
1069
|
+
`${String(execution.response?.id || targetId)} | host=${String(execution.response?.host || "unknown")}`
|
|
1070
|
+
);
|
|
1071
|
+
console.log(
|
|
1072
|
+
`status=${String(execution.response?.status || "UNKNOWN")} verification=${String(
|
|
1073
|
+
execution.response?.verificationStatus || "UNKNOWN"
|
|
1074
|
+
)}`
|
|
1075
|
+
);
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
site
|
|
1079
|
+
.command("create")
|
|
1080
|
+
.description("Create an ephemeral callback site linked to an identity (dry-run by default)")
|
|
1081
|
+
.argument("<identityId>", "Identity id")
|
|
1082
|
+
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
1083
|
+
.option("--output-dir <path>", "Optional artifact output root override")
|
|
1084
|
+
.option("--api-url <url>", "AIdenID API base URL", "https://api.aidenid.com")
|
|
1085
|
+
.option("--api-key <key>", "AIdenID API key (or use AIDENID_API_KEY env)")
|
|
1086
|
+
.option("--org-id <id>", "AIdenID org id (or use AIDENID_ORG_ID env)")
|
|
1087
|
+
.option("--project-id <id>", "AIdenID project id (or use AIDENID_PROJECT_ID env)")
|
|
1088
|
+
.option("--domain-id <id>", "Domain id used for callback host")
|
|
1089
|
+
.option("--subdomain-prefix <value>", "Subdomain prefix", "cb")
|
|
1090
|
+
.option("--callback-path <value>", "Callback path", "/callback")
|
|
1091
|
+
.option("--ttl-hours <hours>", "Site TTL in hours", "24")
|
|
1092
|
+
.option("--dns-cleanup-contract-json <json>", "JSON cleanup contract", "{}")
|
|
1093
|
+
.option("--metadata-json <json>", "JSON metadata", "{}")
|
|
1094
|
+
.option("--idempotency-key <key>", "Explicit idempotency key override")
|
|
1095
|
+
.option("--execute", "Execute live API call")
|
|
1096
|
+
.option("--json", "Emit machine-readable output")
|
|
1097
|
+
.action(async (identityId, options, command) => {
|
|
1098
|
+
const emitJson = shouldEmitJson(options, command);
|
|
1099
|
+
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
1100
|
+
const outputRoot = await resolveOutputRoot({
|
|
1101
|
+
cwd: targetPath,
|
|
1102
|
+
outputDirOverride: options.outputDir,
|
|
1103
|
+
env: process.env,
|
|
1104
|
+
});
|
|
1105
|
+
const apiUrl = normalizeAidenIdApiUrl(options.apiUrl);
|
|
1106
|
+
const idempotencyKey = normalizeIdempotencyKey(options.idempotencyKey);
|
|
1107
|
+
const ttlHours = parsePositiveInteger(options.ttlHours, "ttlHours", 24);
|
|
1108
|
+
const domainId = String(options.domainId || "").trim();
|
|
1109
|
+
if (!domainId) {
|
|
1110
|
+
throw new Error("domainId is required. Use --domain-id <id>.");
|
|
1111
|
+
}
|
|
1112
|
+
const trackedIdentity = await getIdentityById({
|
|
1113
|
+
outputRoot,
|
|
1114
|
+
identityId,
|
|
1115
|
+
});
|
|
1116
|
+
const payload = {
|
|
1117
|
+
identityId,
|
|
1118
|
+
domainId,
|
|
1119
|
+
subdomainPrefix: String(options.subdomainPrefix || "cb").trim() || "cb",
|
|
1120
|
+
callbackPath: String(options.callbackPath || "/callback").trim() || "/callback",
|
|
1121
|
+
ttlHours,
|
|
1122
|
+
dnsCleanupContract: parseJsonObject(options.dnsCleanupContractJson, "dnsCleanupContractJson"),
|
|
1123
|
+
metadata: parseJsonObject(options.metadataJson, "metadataJson"),
|
|
1124
|
+
};
|
|
1125
|
+
|
|
1126
|
+
const artifactsDir = path.join(outputRoot, "aidenid", "site-create");
|
|
1127
|
+
const stamp = stableTimestampForFile();
|
|
1128
|
+
const requestPath = path.join(artifactsDir, `request-${encodeURIComponent(identityId)}-${stamp}.json`);
|
|
1129
|
+
await writeArtifact(requestPath, {
|
|
1130
|
+
generatedAt: new Date().toISOString(),
|
|
1131
|
+
apiUrl,
|
|
1132
|
+
idempotencyKey,
|
|
1133
|
+
payload,
|
|
1134
|
+
});
|
|
1135
|
+
|
|
1136
|
+
const resolvedCredentials = await resolveAidenIdCredentials({
|
|
1137
|
+
apiKey: options.apiKey,
|
|
1138
|
+
orgId: options.orgId || trackedIdentity.identity?.orgId,
|
|
1139
|
+
projectId: options.projectId || trackedIdentity.identity?.projectId,
|
|
1140
|
+
env: process.env,
|
|
1141
|
+
requireAll: false,
|
|
1142
|
+
});
|
|
1143
|
+
if (!options.execute) {
|
|
1144
|
+
const result = {
|
|
1145
|
+
command: "ai identity site create",
|
|
1146
|
+
execute: false,
|
|
1147
|
+
identityId,
|
|
1148
|
+
apiUrl,
|
|
1149
|
+
idempotencyKey,
|
|
1150
|
+
requestPath,
|
|
1151
|
+
payload,
|
|
1152
|
+
credentialsMissing: resolvedCredentials.missing,
|
|
1153
|
+
};
|
|
1154
|
+
if (emitJson) {
|
|
1155
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1156
|
+
return;
|
|
1157
|
+
}
|
|
1158
|
+
console.log(pc.bold("AIdenID site create artifact generated (dry-run)"));
|
|
1159
|
+
console.log(pc.gray(`Request: ${requestPath}`));
|
|
1160
|
+
if (resolvedCredentials.missing.length > 0) {
|
|
1161
|
+
console.log(
|
|
1162
|
+
pc.yellow(`Missing credentials for live execute: ${resolvedCredentials.missing.join(", ")}`)
|
|
1163
|
+
);
|
|
1164
|
+
}
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
const requiredCredentials = await resolveAidenIdCredentials({
|
|
1169
|
+
apiKey: options.apiKey,
|
|
1170
|
+
orgId: options.orgId || trackedIdentity.identity?.orgId,
|
|
1171
|
+
projectId: options.projectId || trackedIdentity.identity?.projectId,
|
|
1172
|
+
env: process.env,
|
|
1173
|
+
requireAll: true,
|
|
1174
|
+
});
|
|
1175
|
+
const execution = await createTemporarySite({
|
|
1176
|
+
apiUrl,
|
|
1177
|
+
apiKey: requiredCredentials.apiKey,
|
|
1178
|
+
orgId: requiredCredentials.orgId,
|
|
1179
|
+
projectId: requiredCredentials.projectId,
|
|
1180
|
+
idempotencyKey,
|
|
1181
|
+
payload,
|
|
1182
|
+
});
|
|
1183
|
+
const responsePath = path.join(
|
|
1184
|
+
artifactsDir,
|
|
1185
|
+
`response-${encodeURIComponent(identityId)}-${stamp}.json`
|
|
1186
|
+
);
|
|
1187
|
+
await writeArtifact(responsePath, {
|
|
1188
|
+
receivedAt: new Date().toISOString(),
|
|
1189
|
+
apiUrl,
|
|
1190
|
+
idempotencyKey,
|
|
1191
|
+
response: execution.response,
|
|
1192
|
+
});
|
|
1193
|
+
|
|
1194
|
+
const registryUpdate = await recordTemporarySite({
|
|
1195
|
+
outputRoot,
|
|
1196
|
+
site: execution.response || {},
|
|
1197
|
+
context: {
|
|
1198
|
+
source: "site-create",
|
|
1199
|
+
idempotencyKey,
|
|
1200
|
+
identityId,
|
|
1201
|
+
domainId,
|
|
1202
|
+
projectId: requiredCredentials.projectId,
|
|
1203
|
+
},
|
|
1204
|
+
});
|
|
1205
|
+
const result = {
|
|
1206
|
+
command: "ai identity site create",
|
|
1207
|
+
execute: true,
|
|
1208
|
+
identityId,
|
|
1209
|
+
apiUrl,
|
|
1210
|
+
idempotencyKey,
|
|
1211
|
+
requestPath,
|
|
1212
|
+
responsePath,
|
|
1213
|
+
site: execution.response || null,
|
|
1214
|
+
registryPath: registryUpdate.registryPath,
|
|
1215
|
+
};
|
|
1216
|
+
if (emitJson) {
|
|
1217
|
+
console.log(JSON.stringify(result, null, 2));
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
console.log(pc.bold("AIdenID temporary site created"));
|
|
1221
|
+
console.log(pc.gray(`Response: ${responsePath}`));
|
|
1222
|
+
console.log(
|
|
1223
|
+
`${String(result.site?.id || "unknown-site")} | ${String(result.site?.callbackUrl || result.site?.host || "unknown-host")}`
|
|
1224
|
+
);
|
|
1225
|
+
});
|
|
1226
|
+
|
|
1227
|
+
site
|
|
1228
|
+
.command("list")
|
|
1229
|
+
.description("List locally tracked temporary callback sites")
|
|
1230
|
+
.option("--path <path>", "Workspace path for artifact/config resolution", ".")
|
|
1231
|
+
.option("--output-dir <path>", "Optional artifact output root override")
|
|
1232
|
+
.option("--identity-id <id>", "Optional identity filter")
|
|
1233
|
+
.option("--json", "Emit machine-readable output")
|
|
1234
|
+
.action(async (options, command) => {
|
|
1235
|
+
const emitJson = shouldEmitJson(options, command);
|
|
1236
|
+
const targetPath = path.resolve(process.cwd(), String(options.path || "."));
|
|
1237
|
+
const outputRoot = await resolveOutputRoot({
|
|
1238
|
+
cwd: targetPath,
|
|
1239
|
+
outputDirOverride: options.outputDir,
|
|
1240
|
+
env: process.env,
|
|
1241
|
+
});
|
|
1242
|
+
const listing = await listSites({
|
|
1243
|
+
outputRoot,
|
|
1244
|
+
identityId: options.identityId,
|
|
1245
|
+
});
|
|
1246
|
+
const payload = {
|
|
1247
|
+
command: "ai identity site list",
|
|
1248
|
+
registryPath: listing.registryPath,
|
|
1249
|
+
count: listing.sites.length,
|
|
1250
|
+
sites: listing.sites,
|
|
1251
|
+
};
|
|
1252
|
+
if (emitJson) {
|
|
1253
|
+
console.log(JSON.stringify(payload, null, 2));
|
|
1254
|
+
return;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
console.log(pc.bold("AIdenID temporary sites"));
|
|
1258
|
+
console.log(pc.gray(`Registry: ${listing.registryPath}`));
|
|
1259
|
+
if (listing.sites.length === 0) {
|
|
1260
|
+
console.log(pc.gray("No tracked temporary sites."));
|
|
1261
|
+
return;
|
|
1262
|
+
}
|
|
1263
|
+
for (const item of listing.sites) {
|
|
1264
|
+
console.log(
|
|
1265
|
+
`- ${item.siteId} | ${item.identityId || "unknown-identity"} | ${item.status} | ${item.callbackUrl || item.host || "unknown-host"}`
|
|
1266
|
+
);
|
|
1267
|
+
}
|
|
1268
|
+
});
|
|
1269
|
+
|
|
1270
|
+
return { identity, legalHold };
|
|
1271
|
+
}
|
|
1272
|
+
|