@indigoai-us/hq-cli 5.345.214 → 5.345.215
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -0
- package/assets/scaffold/core/scripts/hq-delegate-verify.sh +5 -2
- package/dist/command-catalog.generated.d.ts +180 -13
- package/dist/command-catalog.generated.js +221 -13
- package/dist/commands/agents.d.ts +51 -1
- package/dist/commands/agents.js +154 -2
- package/dist/commands/bot-jobs.d.ts +2 -15
- package/dist/commands/bot-jobs.js +2 -94
- package/dist/commands/bot-runtime.d.ts +46 -5
- package/dist/commands/bot-runtime.js +228 -18
- package/dist/commands/bot.d.ts +16 -9
- package/dist/commands/bot.js +231 -55
- package/dist/commands/capacity.d.ts +4 -1
- package/dist/commands/capacity.js +46 -10
- package/dist/commands/cloud.d.ts +66 -13
- package/dist/commands/cloud.js +121 -40
- package/dist/commands/company-restore.d.ts +23 -0
- package/dist/commands/company-restore.js +128 -0
- package/dist/commands/company.js +2 -0
- package/dist/commands/core-delegate-w1b.js +15 -1
- package/dist/commands/core-policy.js +67 -8
- package/dist/commands/daemon.js +5 -0
- package/dist/commands/files-browse.d.ts +11 -4
- package/dist/commands/files-browse.js +21 -4
- package/dist/commands/files.d.ts +1 -1
- package/dist/commands/files.js +25 -11
- package/dist/commands/integrations-auth-rules.d.ts +27 -0
- package/dist/commands/integrations-auth-rules.js +79 -0
- package/dist/commands/integrations-connect.d.ts +10 -3
- package/dist/commands/integrations-connect.js +87 -13
- package/dist/commands/integrations-import.js +124 -12
- package/dist/commands/lanes.js +28 -11
- package/dist/commands/mesh.d.ts +2 -0
- package/dist/commands/mesh.js +60 -35
- package/dist/commands/sources.js +6 -0
- package/dist/commands/storage-offload.d.ts +12 -0
- package/dist/commands/storage-offload.js +41 -3
- package/dist/commands/sync-held.js +5 -2
- package/dist/commands/sync-mode.js +5 -0
- package/dist/commands/whoami.js +4 -0
- package/dist/lazy-commands.js +3 -5
- package/dist/lib/bot/config.d.ts +1 -0
- package/dist/lib/bot/config.js +10 -0
- package/dist/lib/bot/eventbridge-cron.d.ts +22 -0
- package/dist/lib/bot/eventbridge-cron.js +104 -0
- package/dist/lib/bot/fleet-cron.d.ts +8 -0
- package/dist/lib/bot/fleet-cron.js +35 -3
- package/dist/lib/bot/fleet-daemon.d.ts +46 -0
- package/dist/lib/bot/fleet-daemon.js +99 -1
- package/dist/lib/bot/fleet-local.d.ts +33 -1
- package/dist/lib/bot/fleet-local.js +215 -31
- package/dist/lib/bot/fleet-python.d.ts +3 -0
- package/dist/lib/bot/fleet-python.js +34 -4
- package/dist/lib/bot/fleet-runtime-sources.d.ts +15 -0
- package/dist/lib/bot/fleet-runtime-sources.js +30 -0
- package/dist/lib/bot/legacy-provider-login.d.ts +8 -0
- package/dist/lib/bot/legacy-provider-login.js +19 -2
- package/dist/lib/bot/probe.js +7 -1
- package/dist/lib/bot/prompt.js +1 -1
- package/dist/lib/bot/readiness.d.ts +8 -0
- package/dist/lib/bot/readiness.js +17 -3
- package/dist/lib/bot/run.js +20 -1
- package/dist/lib/bot/runtime/codex.js +1 -1
- package/dist/lib/bot/runtime/grok-acp.d.ts +5 -1
- package/dist/lib/bot/runtime/grok-acp.js +6 -3
- package/dist/lib/bot/runtime/index.js +19 -9
- package/dist/lib/bot/runtime/messages-stream.js +2 -2
- package/dist/lib/bot/runtime/types.d.ts +15 -0
- package/dist/lib/bot/runtime/types.js +9 -0
- package/dist/lib/bot/runtime-auth.d.ts +30 -0
- package/dist/lib/bot/runtime-auth.js +94 -3
- package/dist/lib/bot/runtime-failure.d.ts +23 -0
- package/dist/lib/bot/runtime-failure.js +43 -1
- package/dist/lib/bot/status.d.ts +2 -0
- package/dist/lib/capacity/accounts.d.ts +8 -0
- package/dist/lib/capacity/accounts.js +19 -0
- package/dist/lib/capacity/available.d.ts +154 -0
- package/dist/lib/capacity/available.js +905 -0
- package/dist/lib/capacity/codex-availability.d.ts +14 -1
- package/dist/lib/capacity/codex-availability.js +26 -1
- package/dist/lib/capacity/collectors/claude-oauth.d.ts +29 -2
- package/dist/lib/capacity/collectors/claude-oauth.js +104 -7
- package/dist/lib/capacity/collectors/codex.js +10 -7
- package/dist/lib/capacity/collectors/grok-refresh.d.ts +80 -0
- package/dist/lib/capacity/collectors/grok-refresh.js +189 -0
- package/dist/lib/capacity/collectors/grok.d.ts +5 -0
- package/dist/lib/capacity/collectors/grok.js +56 -5
- package/dist/lib/capacity/ledger.d.ts +37 -1
- package/dist/lib/capacity/ledger.js +207 -30
- package/dist/lib/capacity/project.d.ts +26 -0
- package/dist/lib/capacity/project.js +137 -8
- package/dist/lib/capacity/refusal-rows.d.ts +31 -0
- package/dist/lib/capacity/refusal-rows.js +61 -0
- package/dist/lib/capacity/refusal.d.ts +53 -2
- package/dist/lib/capacity/refusal.js +284 -65
- package/dist/lib/capacity/route.js +46 -11
- package/dist/lib/capacity/widget.d.ts +12 -1
- package/dist/lib/capacity/widget.js +91 -3
- package/dist/lib/daemon/catalog.js +11 -1
- package/dist/lib/daemon/resolver.d.ts +2 -0
- package/dist/lib/daemon/resolver.js +3 -0
- package/dist/lib/daemon/run.d.ts +9 -0
- package/dist/lib/daemon/run.js +54 -1
- package/dist/lib/daemon/server.d.ts +2 -0
- package/dist/lib/daemon/server.js +10 -1
- package/dist/lib/daemon/tcc-eperm.d.ts +153 -0
- package/dist/lib/daemon/tcc-eperm.js +310 -0
- package/dist/lib/db/sqlite-binding.d.ts +1 -0
- package/dist/lib/db/sqlite-binding.js +1 -1
- package/dist/lib/delivery/admission.d.ts +86 -0
- package/dist/lib/delivery/admission.js +148 -0
- package/dist/lib/delivery/artifacts.d.ts +105 -0
- package/dist/lib/delivery/artifacts.js +567 -0
- package/dist/lib/delivery/attempt-id.d.ts +13 -0
- package/dist/lib/delivery/attempt-id.js +16 -0
- package/dist/lib/delivery/backup.d.ts +78 -0
- package/dist/lib/delivery/backup.js +343 -0
- package/dist/lib/delivery/cache.d.ts +29 -0
- package/dist/lib/delivery/cache.js +33 -0
- package/dist/lib/delivery/contracts.d.ts +142 -0
- package/dist/lib/delivery/contracts.js +289 -0
- package/dist/lib/delivery/credentials.d.ts +54 -0
- package/dist/lib/delivery/credentials.js +119 -0
- package/dist/lib/delivery/disposable-target.d.ts +42 -0
- package/dist/lib/delivery/disposable-target.js +111 -0
- package/dist/lib/delivery/effects.d.ts +136 -0
- package/dist/lib/delivery/effects.js +541 -0
- package/dist/lib/delivery/enrollment.d.ts +146 -0
- package/dist/lib/delivery/enrollment.js +460 -0
- package/dist/lib/delivery/escalations.d.ts +51 -0
- package/dist/lib/delivery/escalations.js +60 -0
- package/dist/lib/delivery/identity.d.ts +25 -0
- package/dist/lib/delivery/identity.js +82 -0
- package/dist/lib/delivery/inbox.d.ts +116 -0
- package/dist/lib/delivery/inbox.js +260 -0
- package/dist/lib/delivery/lease.d.ts +80 -0
- package/dist/lib/delivery/lease.js +134 -0
- package/dist/lib/delivery/migrations.d.ts +255 -0
- package/dist/lib/delivery/migrations.js +823 -0
- package/dist/lib/delivery/mqtt-adapter.d.ts +50 -0
- package/dist/lib/delivery/mqtt-adapter.js +242 -0
- package/dist/lib/delivery/mqtt.d.ts +63 -0
- package/dist/lib/delivery/mqtt.js +119 -0
- package/dist/lib/delivery/outbox.d.ts +95 -0
- package/dist/lib/delivery/outbox.js +187 -0
- package/dist/lib/delivery/provenance.d.ts +129 -0
- package/dist/lib/delivery/provenance.js +93 -0
- package/dist/lib/delivery/reconciler.d.ts +215 -0
- package/dist/lib/delivery/reconciler.js +703 -0
- package/dist/lib/delivery/restore.d.ts +35 -0
- package/dist/lib/delivery/restore.js +134 -0
- package/dist/lib/delivery/rpc/client.d.ts +22 -0
- package/dist/lib/delivery/rpc/client.js +159 -0
- package/dist/lib/delivery/rpc/port.d.ts +40 -0
- package/dist/lib/delivery/rpc/port.js +16 -0
- package/dist/lib/delivery/rpc/server.d.ts +30 -0
- package/dist/lib/delivery/rpc/server.js +205 -0
- package/dist/lib/delivery/rpc/wire.d.ts +85 -0
- package/dist/lib/delivery/rpc/wire.js +143 -0
- package/dist/lib/delivery/store.d.ts +163 -0
- package/dist/lib/delivery/store.js +944 -0
- package/dist/lib/delivery/windows-service-install.d.ts +262 -0
- package/dist/lib/delivery/windows-service-install.js +892 -0
- package/dist/lib/delivery/workers/macos-job-helper.d.ts +103 -0
- package/dist/lib/delivery/workers/macos-job-helper.js +927 -0
- package/dist/lib/delivery/workers/macos.d.ts +191 -0
- package/dist/lib/delivery/workers/macos.js +943 -0
- package/dist/lib/delivery/workers/windows-job-helper.d.ts +35 -0
- package/dist/lib/delivery/workers/windows-job-helper.js +264 -0
- package/dist/lib/delivery/workers/windows-service-live.d.ts +121 -0
- package/dist/lib/delivery/workers/windows-service-live.js +711 -0
- package/dist/lib/delivery/workers/windows-service-runner.d.ts +33 -0
- package/dist/lib/delivery/workers/windows-service-runner.js +82 -0
- package/dist/lib/delivery/workers/windows-service.d.ts +140 -0
- package/dist/lib/delivery/workers/windows-service.js +584 -0
- package/dist/lib/delivery/workers/windows.d.ts +251 -0
- package/dist/lib/delivery/workers/windows.js +594 -0
- package/dist/lib/hot-channels/adapters/meetings.d.ts +15 -0
- package/dist/lib/hot-channels/adapters/meetings.js +36 -3
- package/dist/lib/hot-channels/signals-pass.d.ts +10 -0
- package/dist/lib/hot-channels/signals-pass.js +71 -2
- package/dist/lib/hot-channels/signals-redo.js +10 -2
- package/dist/lib/install/provider-wrappers.d.ts +2 -0
- package/dist/lib/install/provider-wrappers.js +68 -3
- package/dist/lib/lanes/watcher.js +35 -0
- package/dist/lib/signals/steps/extract.js +40 -4
- package/dist/schemas/hq-available-ai.v1.schema.json +76 -0
- package/dist/utils/catalog-runtime-paths.d.ts +34 -0
- package/dist/utils/catalog-runtime-paths.js +53 -0
- package/dist/utils/cognito-callback-port.d.ts +14 -0
- package/dist/utils/cognito-callback-port.js +24 -0
- package/dist/utils/cognito-session.js +3 -3
- package/dist/utils/deleted-company-notice.d.ts +59 -0
- package/dist/utils/deleted-company-notice.js +156 -0
- package/dist/utils/files-browse-acl.js +1 -1
- package/dist/utils/login-browser.d.ts +1 -1
- package/dist/utils/login-browser.js +7 -5
- package/dist/utils/resident-package-preload.js +30 -15
- package/dist/utils/vault-api.js +7 -0
- package/package.json +7 -7
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Portable delivery contracts (US-001).
|
|
3
|
+
*
|
|
4
|
+
* Provider-neutral, versioned records for HQ delivery. Nothing here names a
|
|
5
|
+
* cloud or forge provider; adapters translate these records at the edges.
|
|
6
|
+
*/
|
|
7
|
+
export const DELIVERY_SCHEMA_VERSIONS = {
|
|
8
|
+
tenant: "hq-delivery.tenant.v1",
|
|
9
|
+
run: "hq-delivery.run.v1",
|
|
10
|
+
job: "hq-delivery.job.v1",
|
|
11
|
+
attempt: "hq-delivery.attempt.v1",
|
|
12
|
+
lease: "hq-delivery.lease.v1",
|
|
13
|
+
recipe: "hq-delivery.recipe.v1",
|
|
14
|
+
policy: "hq-delivery.policy.v1",
|
|
15
|
+
artifact: "hq-delivery.artifact.v1",
|
|
16
|
+
};
|
|
17
|
+
function isObject(v) {
|
|
18
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
19
|
+
}
|
|
20
|
+
function nonEmpty(v) {
|
|
21
|
+
return typeof v === "string" && v.trim().length > 0;
|
|
22
|
+
}
|
|
23
|
+
const RUN_STATUSES = ["queued", "running", "succeeded", "failed", "cancelled"];
|
|
24
|
+
const ATTEMPT_OUTCOMES = ["pending", "passed", "failed"];
|
|
25
|
+
const ISO_TIMESTAMP = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(\.\d+)?(Z|[+-](\d{2}):(\d{2}))$/;
|
|
26
|
+
function isStringArray(v) {
|
|
27
|
+
return Array.isArray(v) && v.every((s) => typeof s === "string");
|
|
28
|
+
}
|
|
29
|
+
function isKnownKind(v) {
|
|
30
|
+
return typeof v === "string" && Object.prototype.hasOwnProperty.call(DELIVERY_SCHEMA_VERSIONS, v);
|
|
31
|
+
}
|
|
32
|
+
function describeValue(v) {
|
|
33
|
+
return typeof v === "string" ? JSON.stringify(v) : typeof v;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Strict ISO-8601 timestamp. The date must exist on the calendar (2026-02-30
|
|
37
|
+
* is rejected rather than rolled over to March), and hours, minutes, seconds
|
|
38
|
+
* and offsets must be in range.
|
|
39
|
+
*/
|
|
40
|
+
function isStrictTimestamp(v) {
|
|
41
|
+
if (typeof v !== "string")
|
|
42
|
+
return false;
|
|
43
|
+
const m = ISO_TIMESTAMP.exec(v);
|
|
44
|
+
if (!m)
|
|
45
|
+
return false;
|
|
46
|
+
const [year, month, day, hour, minute, second] = m.slice(1, 7).map(Number);
|
|
47
|
+
if (hour > 23 || minute > 59 || second > 59)
|
|
48
|
+
return false;
|
|
49
|
+
if (m[9] !== undefined && (Number(m[9]) > 23 || Number(m[10]) > 59))
|
|
50
|
+
return false;
|
|
51
|
+
const date = new Date(Date.UTC(year, month - 1, day));
|
|
52
|
+
return date.getUTCFullYear() === year && date.getUTCMonth() === month - 1 && date.getUTCDate() === day;
|
|
53
|
+
}
|
|
54
|
+
const REQUIRED_FIELDS = {
|
|
55
|
+
tenant: ["displayName"],
|
|
56
|
+
run: ["runId", "recipeId", "status"],
|
|
57
|
+
job: ["jobId", "runId", "name"],
|
|
58
|
+
attempt: ["attemptId", "jobId", "runId"],
|
|
59
|
+
lease: ["leaseId", "runId", "holder", "expiresAt"],
|
|
60
|
+
recipe: ["recipeId"],
|
|
61
|
+
policy: ["policyId"],
|
|
62
|
+
artifact: ["artifactId", "runId"],
|
|
63
|
+
};
|
|
64
|
+
/** Fields present on every record kind. */
|
|
65
|
+
const BASE_FIELDS = ["schemaVersion", "tenantId"];
|
|
66
|
+
/**
|
|
67
|
+
* Every field each kind declares in its contract, besides BASE_FIELDS.
|
|
68
|
+
*
|
|
69
|
+
* Unknown-field policy: reject. validateRecord returns an error for any field
|
|
70
|
+
* that is not declared here, on every record kind, and NESTED_FIELDS applies
|
|
71
|
+
* the same rule to nested objects such as sourcePin. A nested error names the
|
|
72
|
+
* full path ("artifact: unknown field sourcePin.<name>"). isSourcePin rejects
|
|
73
|
+
* undeclared pin fields the same way. The rule is generic: it does not look
|
|
74
|
+
* for particular names, so any undeclared field (provider-specific or not)
|
|
75
|
+
* fails validation instead of riding along in a portable record.
|
|
76
|
+
*/
|
|
77
|
+
const DECLARED_FIELDS = {
|
|
78
|
+
tenant: ["displayName"],
|
|
79
|
+
run: ["runId", "recipeId", "status"],
|
|
80
|
+
job: ["jobId", "runId", "name"],
|
|
81
|
+
attempt: ["attemptId", "jobId", "runId", "number", "outcome"],
|
|
82
|
+
lease: ["leaseId", "runId", "holder", "expiresAt"],
|
|
83
|
+
recipe: ["recipeId", "steps"],
|
|
84
|
+
policy: ["policyId", "rules"],
|
|
85
|
+
artifact: ["artifactId", "runId", "sourcePin", "deployedState"],
|
|
86
|
+
};
|
|
87
|
+
const SOURCE_PIN_FIELDS = ["repository", "commitSha", "verifiedOn"];
|
|
88
|
+
/** Timestamp fields per kind; each is checked with isStrictTimestamp. */
|
|
89
|
+
const TIMESTAMP_FIELDS = {
|
|
90
|
+
lease: ["expiresAt"],
|
|
91
|
+
};
|
|
92
|
+
const NESTED_FIELDS = {
|
|
93
|
+
artifact: { sourcePin: { fields: SOURCE_PIN_FIELDS } },
|
|
94
|
+
};
|
|
95
|
+
function undeclaredFields(input, declared) {
|
|
96
|
+
return Object.keys(input).filter((field) => !declared.includes(field));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Dotted paths of every undeclared field in `input`, at every nesting level
|
|
100
|
+
* described by `nested`. A top-level field is reported by name ("notes"); a
|
|
101
|
+
* nested one by its full path ("sourcePin.notes").
|
|
102
|
+
*/
|
|
103
|
+
function undeclaredFieldPaths(input, declared, nested = {}, prefix = "") {
|
|
104
|
+
const paths = undeclaredFields(input, declared).map((field) => prefix + field);
|
|
105
|
+
for (const [field, shape] of Object.entries(nested)) {
|
|
106
|
+
const child = input[field];
|
|
107
|
+
if (isObject(child)) {
|
|
108
|
+
paths.push(...undeclaredFieldPaths(child, shape.fields, shape.nested, `${prefix}${field}.`));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return paths;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Validate one record. Never throws: an unknown kind or a non-object record
|
|
115
|
+
* returns `{ ok: false, errors }`.
|
|
116
|
+
*/
|
|
117
|
+
export function validateRecord(kind, input) {
|
|
118
|
+
const errors = [];
|
|
119
|
+
if (!isKnownKind(kind)) {
|
|
120
|
+
return { ok: false, errors: [`unknown kind ${describeValue(kind)}`] };
|
|
121
|
+
}
|
|
122
|
+
if (!isObject(input)) {
|
|
123
|
+
return { ok: false, errors: [`${kind}: record must be an object`] };
|
|
124
|
+
}
|
|
125
|
+
const expected = DELIVERY_SCHEMA_VERSIONS[kind];
|
|
126
|
+
if (input.schemaVersion !== expected) {
|
|
127
|
+
errors.push(`${kind}: unsupported schemaVersion ${JSON.stringify(input.schemaVersion)} (expected ${expected})`);
|
|
128
|
+
}
|
|
129
|
+
if (!nonEmpty(input.tenantId)) {
|
|
130
|
+
errors.push(`${kind}: missing tenant identity`);
|
|
131
|
+
}
|
|
132
|
+
for (const field of REQUIRED_FIELDS[kind]) {
|
|
133
|
+
if (!nonEmpty(input[field]))
|
|
134
|
+
errors.push(`${kind}: missing ${field}`);
|
|
135
|
+
}
|
|
136
|
+
for (const path of undeclaredFieldPaths(input, [...BASE_FIELDS, ...DECLARED_FIELDS[kind]], NESTED_FIELDS[kind])) {
|
|
137
|
+
errors.push(`${kind}: unknown field ${path}`);
|
|
138
|
+
}
|
|
139
|
+
if (kind === "run" && !RUN_STATUSES.includes(input.status)) {
|
|
140
|
+
errors.push(`run: unsupported status ${JSON.stringify(input.status)}`);
|
|
141
|
+
}
|
|
142
|
+
if (kind === "attempt") {
|
|
143
|
+
if (!(Number.isInteger(input.number) && input.number >= 1)) {
|
|
144
|
+
errors.push("attempt: number must be a positive integer");
|
|
145
|
+
}
|
|
146
|
+
if (!ATTEMPT_OUTCOMES.includes(input.outcome)) {
|
|
147
|
+
errors.push(`attempt: unsupported outcome ${JSON.stringify(input.outcome)}`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (kind === "recipe" && !isStringArray(input.steps)) {
|
|
151
|
+
errors.push("recipe: steps must be an array of strings");
|
|
152
|
+
}
|
|
153
|
+
if (kind === "policy" && !isStringArray(input.rules)) {
|
|
154
|
+
errors.push("policy: rules must be an array of strings");
|
|
155
|
+
}
|
|
156
|
+
for (const field of TIMESTAMP_FIELDS[kind] ?? []) {
|
|
157
|
+
if (nonEmpty(input[field]) && !isStrictTimestamp(input[field])) {
|
|
158
|
+
errors.push(`${kind}: ${field} must be an ISO-8601 timestamp`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
if (kind === "artifact") {
|
|
162
|
+
// Only an absent deployedState defaults to unverified; null is not a declared value.
|
|
163
|
+
const ds = input.deployedState === undefined ? "unverified" : input.deployedState;
|
|
164
|
+
if (ds !== "unverified" && ds !== "verified") {
|
|
165
|
+
errors.push("artifact: deployedState must be unverified or verified");
|
|
166
|
+
}
|
|
167
|
+
if (input.sourcePin !== undefined && !isSourcePin(input.sourcePin)) {
|
|
168
|
+
errors.push("artifact: sourcePin is malformed");
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
if (errors.length > 0)
|
|
172
|
+
return { ok: false, errors };
|
|
173
|
+
const value = kind === "artifact" ? { ...input, deployedState: input.deployedState ?? "unverified" } : { ...input };
|
|
174
|
+
return { ok: true, value: value };
|
|
175
|
+
}
|
|
176
|
+
const BUNDLE_CHILD_KINDS = ["job", "attempt", "lease", "recipe", "policy", "artifact"];
|
|
177
|
+
/**
|
|
178
|
+
* Validate a run with its children. Every child must share the run's tenant
|
|
179
|
+
* and run, a recipe child must match the run's recipeId, and run or tenant
|
|
180
|
+
* records are not allowed as children. On success the returned bundle holds
|
|
181
|
+
* the normalized records from validateRecord. Never throws: malformed input
|
|
182
|
+
* returns `{ ok: false, errors }`.
|
|
183
|
+
*/
|
|
184
|
+
export function validateBundle(bundle) {
|
|
185
|
+
if (!isObject(bundle))
|
|
186
|
+
return { ok: false, errors: ["bundle: must be an object"] };
|
|
187
|
+
const errors = [];
|
|
188
|
+
const run = validateRecord("run", bundle.run);
|
|
189
|
+
if (!run.ok)
|
|
190
|
+
errors.push(...run.errors);
|
|
191
|
+
const rawChildren = bundle.children;
|
|
192
|
+
if (!Array.isArray(rawChildren)) {
|
|
193
|
+
errors.push("bundle: children must be an array");
|
|
194
|
+
return { ok: false, errors };
|
|
195
|
+
}
|
|
196
|
+
const children = [];
|
|
197
|
+
rawChildren.forEach((child, index) => {
|
|
198
|
+
if (!isObject(child)) {
|
|
199
|
+
errors.push(`bundle: child ${index} must be an object`);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const kind = child.kind;
|
|
203
|
+
if (!isKnownKind(kind)) {
|
|
204
|
+
errors.push(`bundle: child ${index} has unknown kind ${describeValue(kind)}`);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (!BUNDLE_CHILD_KINDS.includes(kind)) {
|
|
208
|
+
errors.push(`${kind}: not allowed as a bundle child`);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const res = validateRecord(kind, child.record);
|
|
212
|
+
if (!res.ok) {
|
|
213
|
+
errors.push(...res.errors);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (run.ok && res.value.tenantId !== run.value.tenantId) {
|
|
217
|
+
errors.push(`${kind}: tenantId ${res.value.tenantId} does not match run tenant ${run.value.tenantId}`);
|
|
218
|
+
}
|
|
219
|
+
const childRunId = res.value.runId;
|
|
220
|
+
if (run.ok && childRunId !== undefined && childRunId !== run.value.runId) {
|
|
221
|
+
errors.push(`${kind}: runId ${String(childRunId)} does not match run ${run.value.runId}`);
|
|
222
|
+
}
|
|
223
|
+
const childRecipeId = res.value.recipeId;
|
|
224
|
+
if (run.ok && kind === "recipe" && childRecipeId !== run.value.recipeId) {
|
|
225
|
+
errors.push(`recipe: recipeId ${String(childRecipeId)} does not match run recipeId ${run.value.recipeId}`);
|
|
226
|
+
}
|
|
227
|
+
children.push({ kind: kind, record: res.value });
|
|
228
|
+
});
|
|
229
|
+
if (!run.ok || errors.length > 0)
|
|
230
|
+
return { ok: false, errors };
|
|
231
|
+
return { ok: true, value: { run: run.value, children } };
|
|
232
|
+
}
|
|
233
|
+
const FULL_SHA = /^[0-9a-f]{40}$/;
|
|
234
|
+
const REMOTE_REF = /^refs\/(heads|tags)\/[A-Za-z0-9._/-]+$/;
|
|
235
|
+
/**
|
|
236
|
+
* Shape check for an attested remote ref: `refs/heads/<name>` or
|
|
237
|
+
* `refs/tags/<name>`, following git ref-name rules (no empty, dot-leading or
|
|
238
|
+
* `.lock` segments, no `..`, no trailing dot). Placeholders such as
|
|
239
|
+
* "local-only" or a bare branch name fail. This checks the string only; it
|
|
240
|
+
* does not confirm that the ref exists on any remote.
|
|
241
|
+
*/
|
|
242
|
+
function isRemoteRefShape(v) {
|
|
243
|
+
if (typeof v !== "string" || !REMOTE_REF.test(v) || v.includes("..") || v.endsWith("."))
|
|
244
|
+
return false;
|
|
245
|
+
return v
|
|
246
|
+
.split("/")
|
|
247
|
+
.slice(2)
|
|
248
|
+
.every((segment) => segment.length > 0 && !segment.startsWith(".") && !segment.endsWith(".lock"));
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Shape check for a source pin: non-empty repository, full 40-hex commit SHA,
|
|
252
|
+
* a remote-ref-shaped `verifiedOn`, and no undeclared fields. The pin is the
|
|
253
|
+
* writer's attestation; this check cannot prove provenance.
|
|
254
|
+
*/
|
|
255
|
+
export function isSourcePin(v) {
|
|
256
|
+
return (isObject(v) &&
|
|
257
|
+
undeclaredFields(v, SOURCE_PIN_FIELDS).length === 0 &&
|
|
258
|
+
nonEmpty(v.repository) &&
|
|
259
|
+
typeof v.commitSha === "string" &&
|
|
260
|
+
FULL_SHA.test(v.commitSha) &&
|
|
261
|
+
isRemoteRefShape(v.verifiedOn));
|
|
262
|
+
}
|
|
263
|
+
/** Next owner recorded for any blocked entry that does not name a non-empty one. */
|
|
264
|
+
export const UNRESOLVED_NEXT_OWNER = "unresolved; project lead/root to identify";
|
|
265
|
+
export function checkReadiness(entry) {
|
|
266
|
+
// Anything other than an explicit "verified" (absent, null, unknown) reads as unverified.
|
|
267
|
+
const deployedState = entry.deployedState === "verified" ? "verified" : "unverified";
|
|
268
|
+
if (entry.unresolved !== undefined) {
|
|
269
|
+
// An unresolved entry is always blocked; empty metadata is replaced, never passed through.
|
|
270
|
+
const unresolved = isObject(entry.unresolved) ? entry.unresolved : {};
|
|
271
|
+
return {
|
|
272
|
+
id: entry.id,
|
|
273
|
+
status: "blocked",
|
|
274
|
+
reason: nonEmpty(unresolved.reason) ? unresolved.reason : "unresolved entry has no recorded reason",
|
|
275
|
+
nextOwner: nonEmpty(unresolved.nextOwner) ? unresolved.nextOwner : UNRESOLVED_NEXT_OWNER,
|
|
276
|
+
deployedState,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
if (entry.sourcePin && isSourcePin(entry.sourcePin)) {
|
|
280
|
+
return { id: entry.id, status: "ready", sourcePin: entry.sourcePin, deployedState };
|
|
281
|
+
}
|
|
282
|
+
const why = entry.completionFlag
|
|
283
|
+
? "predecessor completion flag is not a source pin"
|
|
284
|
+
: entry.localCheckout
|
|
285
|
+
? "unpinned local checkout is not a source pin"
|
|
286
|
+
: "no verified source pin";
|
|
287
|
+
return { id: entry.id, status: "blocked", reason: why, nextOwner: UNRESOLVED_NEXT_OWNER, deployedState };
|
|
288
|
+
}
|
|
289
|
+
//# sourceMappingURL=contracts.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Job } from "./contracts.js";
|
|
2
|
+
import { type WorkerTrust } from "./migrations.js";
|
|
3
|
+
export interface CredentialSpec {
|
|
4
|
+
/** The only tenant whose jobs may receive this credential. */
|
|
5
|
+
tenantId: string;
|
|
6
|
+
ref: string;
|
|
7
|
+
/** release credentials go only to release jobs run by release workers. */
|
|
8
|
+
class: "standard" | "release";
|
|
9
|
+
}
|
|
10
|
+
export interface CredentialPolicy {
|
|
11
|
+
credentials: CredentialSpec[];
|
|
12
|
+
/** Job names that are release jobs. Every other job is untrusted. */
|
|
13
|
+
releaseJobNames: string[];
|
|
14
|
+
}
|
|
15
|
+
/** Looks up a credential value by ref. Called only for refs a plan allowed. */
|
|
16
|
+
export interface CredentialSource {
|
|
17
|
+
resolve(ref: string): string;
|
|
18
|
+
}
|
|
19
|
+
export type JobClass = "release" | "untrusted";
|
|
20
|
+
export interface CredentialPlan {
|
|
21
|
+
jobClass: JobClass;
|
|
22
|
+
refs: string[];
|
|
23
|
+
}
|
|
24
|
+
/** Injected credential values. Serializing or inspecting this shows refs only. */
|
|
25
|
+
export interface InjectedCredentials {
|
|
26
|
+
readonly refs: readonly string[];
|
|
27
|
+
has(ref: string): boolean;
|
|
28
|
+
get(ref: string): string;
|
|
29
|
+
}
|
|
30
|
+
/** A job is a release job only when the policy lists its name. */
|
|
31
|
+
export declare function classifyJob(policy: CredentialPolicy | undefined, job: Job): JobClass;
|
|
32
|
+
/**
|
|
33
|
+
* The one release-trust rule, shared by claim and dispatch: a release job may
|
|
34
|
+
* be taken only by a release-trust worker. Returns the job class, or throws
|
|
35
|
+
* PRIVILEGE_REJECTED.
|
|
36
|
+
*/
|
|
37
|
+
export declare function assertJobTrust(policy: CredentialPolicy | undefined, job: Job, workerTrust: WorkerTrust): JobClass;
|
|
38
|
+
/**
|
|
39
|
+
* Decide which credentials a dispatch may receive. Throws PRIVILEGE_REJECTED
|
|
40
|
+
* for a release job run by a standard worker, and for any requested ref that
|
|
41
|
+
* is malformed, repeated, undeclared, or beyond the job class or worker trust.
|
|
42
|
+
*/
|
|
43
|
+
export declare function planCredentials(policy: CredentialPolicy | undefined, input: {
|
|
44
|
+
job: Job;
|
|
45
|
+
workerTrust: WorkerTrust;
|
|
46
|
+
requested: unknown;
|
|
47
|
+
}): CredentialPlan;
|
|
48
|
+
/**
|
|
49
|
+
* Look up each planned ref once and return the values behind a redacting
|
|
50
|
+
* wrapper. A lookup failure or an empty value is CREDENTIAL_UNAVAILABLE naming
|
|
51
|
+
* the ref only; the source's own error is dropped so it cannot leak a value.
|
|
52
|
+
*/
|
|
53
|
+
export declare function injectCredentials(source: CredentialSource, refs: readonly string[]): InjectedCredentials;
|
|
54
|
+
//# sourceMappingURL=credentials.d.ts.map
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credential boundaries for dispatched jobs (US-004).
|
|
3
|
+
*
|
|
4
|
+
* A credential policy names each credential by tenant, ref and class, and
|
|
5
|
+
* lists the job names that are release jobs. Every other job is untrusted.
|
|
6
|
+
* A credential is granted only to jobs of its own tenant; a credential with
|
|
7
|
+
* no tenant is granted to none. Release job names apply in every tenant the
|
|
8
|
+
* access layer serves, which only adds the release-worker requirement. A dispatch
|
|
9
|
+
* first plans which refs it may receive and rejects, never downgrades, any
|
|
10
|
+
* request beyond the job class or the worker's trust. Only then are values
|
|
11
|
+
* looked up and injected. Values live in a closure and are redacted from
|
|
12
|
+
* JSON, inspect and string output; errors name refs, never values.
|
|
13
|
+
*/
|
|
14
|
+
import { inspect } from "node:util";
|
|
15
|
+
import { trustAllows } from "./identity.js";
|
|
16
|
+
import { DeliveryStoreError } from "./migrations.js";
|
|
17
|
+
const REDACTED = "[credentials redacted]";
|
|
18
|
+
function rejected(found, expected, action) {
|
|
19
|
+
return new DeliveryStoreError("PRIVILEGE_REJECTED", {
|
|
20
|
+
found,
|
|
21
|
+
expected,
|
|
22
|
+
action: `${action} No credential was looked up and nothing was written.`,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
function unavailable(ref, found) {
|
|
26
|
+
return new DeliveryStoreError("CREDENTIAL_UNAVAILABLE", {
|
|
27
|
+
found,
|
|
28
|
+
expected: `a non-empty value for credential ${ref}`,
|
|
29
|
+
action: `Check that credential ${ref} is configured in the credential source. Nothing was claimed.`,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** A job is a release job only when the policy lists its name. */
|
|
33
|
+
export function classifyJob(policy, job) {
|
|
34
|
+
return policy?.releaseJobNames.includes(job.name) ? "release" : "untrusted";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The one release-trust rule, shared by claim and dispatch: a release job may
|
|
38
|
+
* be taken only by a release-trust worker. Returns the job class, or throws
|
|
39
|
+
* PRIVILEGE_REJECTED.
|
|
40
|
+
*/
|
|
41
|
+
export function assertJobTrust(policy, job, workerTrust) {
|
|
42
|
+
const jobClass = classifyJob(policy, job);
|
|
43
|
+
if (jobClass === "release" && !trustAllows(workerTrust, "release")) {
|
|
44
|
+
throw rejected(`a ${workerTrust} worker asked to run release job ${job.jobId}`, "a release worker for a release job", "Give release jobs only to workers enrolled with release trust.");
|
|
45
|
+
}
|
|
46
|
+
return jobClass;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Decide which credentials a dispatch may receive. Throws PRIVILEGE_REJECTED
|
|
50
|
+
* for a release job run by a standard worker, and for any requested ref that
|
|
51
|
+
* is malformed, repeated, undeclared, or beyond the job class or worker trust.
|
|
52
|
+
*/
|
|
53
|
+
export function planCredentials(policy, input) {
|
|
54
|
+
const jobClass = assertJobTrust(policy, input.job, input.workerTrust);
|
|
55
|
+
const requested = input.requested;
|
|
56
|
+
if (!Array.isArray(requested) || !requested.every((r) => typeof r === "string" && r !== "")) {
|
|
57
|
+
throw rejected("a credential request that is not a list of refs", "a list of credential refs", "Pass credentials as a list of declared refs.");
|
|
58
|
+
}
|
|
59
|
+
const seen = new Set();
|
|
60
|
+
for (const ref of requested) {
|
|
61
|
+
if (seen.has(ref)) {
|
|
62
|
+
throw rejected(`credential ${ref} requested twice`, "each credential ref once", `Remove the repeated ${ref}.`);
|
|
63
|
+
}
|
|
64
|
+
seen.add(ref);
|
|
65
|
+
// Another tenant's ref is answered exactly like an undeclared one.
|
|
66
|
+
const spec = policy?.credentials.find((c) => c.ref === ref && typeof c.tenantId === "string" && c.tenantId !== "" && c.tenantId === input.job.tenantId);
|
|
67
|
+
if (!spec) {
|
|
68
|
+
throw rejected(`credential ${ref}, which ${policy ? `the credential policy does not declare for tenant ${input.job.tenantId}` : "cannot be granted because no credential policy is configured"}`, "a credential declared in the credential policy for the job's tenant", `Declare ${ref} in the credential policy, or stop requesting it.`);
|
|
69
|
+
}
|
|
70
|
+
if (spec.class === "release" && jobClass !== "release") {
|
|
71
|
+
throw rejected(`release credential ${ref} requested for untrusted job ${input.job.jobId}`, "release credentials only on release jobs", `Ordinary build and test jobs never receive ${ref}; remove it from the request.`);
|
|
72
|
+
}
|
|
73
|
+
if (spec.class === "release" && !trustAllows(input.workerTrust, "release")) {
|
|
74
|
+
throw rejected(`release credential ${ref} requested by a ${input.workerTrust} worker`, "a release worker", `Only workers enrolled with release trust may receive ${ref}.`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return { jobClass, refs: [...requested] };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Look up each planned ref once and return the values behind a redacting
|
|
81
|
+
* wrapper. A lookup failure or an empty value is CREDENTIAL_UNAVAILABLE naming
|
|
82
|
+
* the ref only; the source's own error is dropped so it cannot leak a value.
|
|
83
|
+
*/
|
|
84
|
+
export function injectCredentials(source, refs) {
|
|
85
|
+
const values = new Map();
|
|
86
|
+
for (const ref of refs) {
|
|
87
|
+
let value;
|
|
88
|
+
try {
|
|
89
|
+
value = source.resolve(ref);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
throw unavailable(ref, `the lookup of credential ${ref} failed`);
|
|
93
|
+
}
|
|
94
|
+
if (typeof value !== "string" || value === "")
|
|
95
|
+
throw unavailable(ref, `an empty or non-text value for credential ${ref}`);
|
|
96
|
+
values.set(ref, value);
|
|
97
|
+
}
|
|
98
|
+
const list = Object.freeze([...values.keys()]);
|
|
99
|
+
const describe = () => `${REDACTED}: ${list.join(", ")}`;
|
|
100
|
+
return Object.freeze({
|
|
101
|
+
refs: list,
|
|
102
|
+
has: (ref) => values.has(ref),
|
|
103
|
+
get: (ref) => {
|
|
104
|
+
const v = values.get(ref);
|
|
105
|
+
if (v === undefined) {
|
|
106
|
+
throw new DeliveryStoreError("CREDENTIAL_UNAVAILABLE", {
|
|
107
|
+
found: `credential ${ref}, which was not injected into this dispatch`,
|
|
108
|
+
expected: `one of: ${list.join(", ") || "no credentials"}`,
|
|
109
|
+
action: "Request the credential at dispatch, within the job's class and the worker's trust.",
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return v;
|
|
113
|
+
},
|
|
114
|
+
toJSON: () => ({ refs: [...list], values: REDACTED }),
|
|
115
|
+
toString: describe,
|
|
116
|
+
[inspect.custom]: describe,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=credentials.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface ApplyRequest {
|
|
2
|
+
deploymentId: string;
|
|
3
|
+
tenantId: string;
|
|
4
|
+
environment: string;
|
|
5
|
+
fence: number;
|
|
6
|
+
digest: string;
|
|
7
|
+
bytes: Buffer;
|
|
8
|
+
}
|
|
9
|
+
export type ApplyOutcome = {
|
|
10
|
+
kind: "applied";
|
|
11
|
+
fence: number;
|
|
12
|
+
digest: string;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "rejected";
|
|
15
|
+
detail: string;
|
|
16
|
+
} | {
|
|
17
|
+
kind: "unknown";
|
|
18
|
+
detail: string;
|
|
19
|
+
};
|
|
20
|
+
export type Observation = {
|
|
21
|
+
kind: "applied";
|
|
22
|
+
fence: number;
|
|
23
|
+
digest: string;
|
|
24
|
+
} | {
|
|
25
|
+
kind: "absent";
|
|
26
|
+
floor: number;
|
|
27
|
+
};
|
|
28
|
+
export interface DeploymentTarget {
|
|
29
|
+
readonly targetId: string;
|
|
30
|
+
apply(req: ApplyRequest, timeoutMs: number): Promise<ApplyOutcome>;
|
|
31
|
+
observe(req: {
|
|
32
|
+
deploymentId: string;
|
|
33
|
+
tenantId: string;
|
|
34
|
+
environment: string;
|
|
35
|
+
fence: number;
|
|
36
|
+
}, timeoutMs: number): Promise<Observation>;
|
|
37
|
+
}
|
|
38
|
+
export declare function disposableTarget(opts: {
|
|
39
|
+
targetId: string;
|
|
40
|
+
baseUrl: string;
|
|
41
|
+
}): DeploymentTarget;
|
|
42
|
+
//# sourceMappingURL=disposable-target.d.ts.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deployment target client (US-009).
|
|
3
|
+
*
|
|
4
|
+
* A DeploymentTarget applies one artifact to one tenant/environment under a
|
|
5
|
+
* fence, and answers what it actually applied. The target, not the deployer,
|
|
6
|
+
* is the last check on a stale effect: it refuses any fence at or below the
|
|
7
|
+
* highest it has seen for that environment.
|
|
8
|
+
*
|
|
9
|
+
* apply() returns one of three outcomes and never guesses:
|
|
10
|
+
* - applied: the target answered with the fence and digest it applied.
|
|
11
|
+
* - rejected: the target refused (stale fence, digest mismatch); nothing was applied.
|
|
12
|
+
* - unknown: no answer (timeout, dropped connection, crash). The effect may
|
|
13
|
+
* or may not have happened; the caller must reconcile before any retry.
|
|
14
|
+
*
|
|
15
|
+
* observe() is the reconcile query. It first raises the environment's fence
|
|
16
|
+
* floor to the given fence, so a request still in transit with that fence or
|
|
17
|
+
* lower cannot land after the answer, then reports whether the deployment was
|
|
18
|
+
* applied. If the target cannot be reached it throws TARGET_UNREACHABLE and
|
|
19
|
+
* the caller keeps the outcome unknown.
|
|
20
|
+
*
|
|
21
|
+
* disposableTarget() talks HTTP to the disposable app of the delivery
|
|
22
|
+
* harness and only to a loopback address: this story deploys to disposable
|
|
23
|
+
* local targets only.
|
|
24
|
+
*/
|
|
25
|
+
import { DeliveryStoreError } from "./migrations.js";
|
|
26
|
+
const LOOPBACK = new Set(["127.0.0.1", "[::1]", "localhost"]);
|
|
27
|
+
function describe(err) {
|
|
28
|
+
if (err instanceof Error) {
|
|
29
|
+
const cause = err.cause;
|
|
30
|
+
const c = cause instanceof Error ? `: ${cause.message}` : "";
|
|
31
|
+
return `${err.name}: ${err.message}${c}`;
|
|
32
|
+
}
|
|
33
|
+
return String(err);
|
|
34
|
+
}
|
|
35
|
+
export function disposableTarget(opts) {
|
|
36
|
+
const url = new URL(opts.baseUrl);
|
|
37
|
+
if (url.protocol !== "http:" || !LOOPBACK.has(url.hostname)) {
|
|
38
|
+
throw new DeliveryStoreError("INVALID_RECORD", {
|
|
39
|
+
found: `deployment target ${opts.baseUrl}`,
|
|
40
|
+
expected: "an http loopback address of a disposable target",
|
|
41
|
+
action: "Deploy only to a disposable local target. Nothing was sent.",
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const base = url.origin;
|
|
45
|
+
return {
|
|
46
|
+
targetId: opts.targetId,
|
|
47
|
+
async apply(req, timeoutMs) {
|
|
48
|
+
let res;
|
|
49
|
+
let body;
|
|
50
|
+
try {
|
|
51
|
+
res = await fetch(`${base}/deploy`, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers: { "content-type": "application/json" },
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
deploymentId: req.deploymentId,
|
|
56
|
+
tenantId: req.tenantId,
|
|
57
|
+
environment: req.environment,
|
|
58
|
+
fence: req.fence,
|
|
59
|
+
digest: req.digest,
|
|
60
|
+
bytes: req.bytes.toString("base64"),
|
|
61
|
+
}),
|
|
62
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
63
|
+
});
|
|
64
|
+
body = (await res.json());
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
return { kind: "unknown", detail: `no answer from ${opts.targetId} (${describe(err)})` };
|
|
68
|
+
}
|
|
69
|
+
if (res.status === 200 && body.applied === true) {
|
|
70
|
+
if (body.fence !== req.fence || body.digest !== req.digest || body.deploymentId !== req.deploymentId) {
|
|
71
|
+
return { kind: "unknown", detail: `target answered for another effect: ${JSON.stringify(body)}` };
|
|
72
|
+
}
|
|
73
|
+
return { kind: "applied", fence: req.fence, digest: req.digest };
|
|
74
|
+
}
|
|
75
|
+
if (res.status === 409 || res.status === 400)
|
|
76
|
+
return { kind: "rejected", detail: `target refused (${res.status}): ${JSON.stringify(body)}` };
|
|
77
|
+
return { kind: "unknown", detail: `unexpected target answer ${res.status}: ${JSON.stringify(body)}` };
|
|
78
|
+
},
|
|
79
|
+
async observe(req, timeoutMs) {
|
|
80
|
+
let res;
|
|
81
|
+
let body;
|
|
82
|
+
try {
|
|
83
|
+
res = await fetch(`${base}/deploy/reconcile`, {
|
|
84
|
+
method: "POST",
|
|
85
|
+
headers: { "content-type": "application/json" },
|
|
86
|
+
body: JSON.stringify(req),
|
|
87
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
88
|
+
});
|
|
89
|
+
body = (await res.json());
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
throw unreachable(opts.targetId, describe(err));
|
|
93
|
+
}
|
|
94
|
+
if (res.status === 200 && body.state === "applied" && typeof body.fence === "number" && typeof body.digest === "string") {
|
|
95
|
+
return { kind: "applied", fence: body.fence, digest: body.digest };
|
|
96
|
+
}
|
|
97
|
+
if (res.status === 200 && body.state === "absent" && typeof body.floor === "number" && body.floor >= req.fence) {
|
|
98
|
+
return { kind: "absent", floor: body.floor };
|
|
99
|
+
}
|
|
100
|
+
throw unreachable(opts.targetId, `unexpected answer ${res.status}: ${JSON.stringify(body)}`);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function unreachable(targetId, detail) {
|
|
105
|
+
return new DeliveryStoreError("TARGET_UNREACHABLE", {
|
|
106
|
+
found: `target ${targetId} could not be queried (${detail})`,
|
|
107
|
+
expected: "the target's answer on whether the deployment was applied",
|
|
108
|
+
action: "The outcome stays unknown and no retry is allowed. Bring the target back and reconcile again.",
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=disposable-target.js.map
|