@runeditrun/rer 0.2.85 → 0.2.86
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 +138 -29
- package/cli/README.md +61 -1
- package/cli/agent-door.mjs +149 -0
- package/cli/agent-fixtures.mjs +16 -0
- package/cli/agent-mail.mjs +54 -0
- package/cli/agent-network.mjs +64 -0
- package/cli/agent-reviewers.mjs +110 -0
- package/cli/agent-secrets.mjs +23 -0
- package/cli/agent-sponsors.mjs +43 -0
- package/cli/agent-surface.mjs +34 -0
- package/cli/agent-webhooks.mjs +19 -0
- package/cli/authoring.mjs +2 -1
- package/cli/business/archive-task.mjs +32 -0
- package/cli/business/carry.mjs +3 -1
- package/cli/business/catchup-task.mjs +42 -0
- package/cli/business/choices.mjs +97 -0
- package/cli/business/command.mjs +23 -5
- package/cli/business/connect.mjs +19 -7
- package/cli/business/detector.mjs +4 -1
- package/cli/business/device.mjs +13 -0
- package/cli/business/export-inputs.mjs +69 -0
- package/cli/business/export-task.mjs +17 -0
- package/cli/business/invocation.mjs +8 -1
- package/cli/business/keychain.mjs +8 -1
- package/cli/business/lease.mjs +11 -1
- package/cli/business/local-commands.mjs +79 -31
- package/cli/business/outbound.mjs +9 -4
- package/cli/business/parsers-config.mjs +8 -7
- package/cli/business/parsers-syntax.mjs +7 -3
- package/cli/business/permissions.mjs +2 -0
- package/cli/business/questions.mjs +89 -9
- package/cli/business/setup-command.mjs +49 -0
- package/cli/business/setup-company.json +15 -0
- package/cli/business/setup-demo.mjs +95 -0
- package/cli/business/state.mjs +44 -10
- package/cli/business/supervisor.mjs +94 -35
- package/cli/business/vendor-door.mjs +230 -0
- package/cli/business/vendors/README.md +29 -3
- package/cli/business/vendors/common.mjs +8 -6
- package/cli/business/vendors/index.mjs +22 -11
- package/cli/business/vendors/sorry.mjs +106 -0
- package/cli/contract.mjs +2 -2
- package/cli/demo-deploy-error.mjs +14 -0
- package/cli/demo-native.mjs +4 -1
- package/cli/deploy-config.mjs +1 -1
- package/cli/deploy-owner-input.mjs +3 -1
- package/cli/deploy-variables.mjs +58 -0
- package/cli/door-clauses.mjs +157 -0
- package/cli/export.mjs +16 -4
- package/cli/hosted-output.mjs +17 -7
- package/cli/inspect.mjs +4 -0
- package/cli/jsonc.mjs +8 -4
- package/cli/lifecycle.mjs +3 -1
- package/cli/main.mjs +1 -0
- package/cli/managed-data-schema.mjs +14 -1
- package/cli/portability-empty.mjs +6 -0
- package/cli/portability-migrations.mjs +26 -4
- package/cli/production-auth.mjs +1 -1
- package/cli/production-mail.mjs +8 -2
- package/edition-authoring/archive-source.mjs +59 -0
- package/edition-authoring/base-copies.mjs +92 -18
- package/edition-authoring/cli.mjs +1 -1
- package/edition-authoring/edition-migrations.mjs +7 -3
- package/edition-authoring/module-closure.mjs +2 -16
- package/edition-authoring/workflow-copies.mjs +1 -1
- package/edition-authoring/workflow-scripts.mjs +12 -3
- package/foundation/runtime/contract-docs.mjs +215 -32
- package/foundation/runtime/contract-prose-patterns.mjs +14 -0
- package/foundation/runtime/contract-prose.mjs +88 -0
- package/global/CHANGELOG.md +93 -0
- package/global/README.md +138 -29
- package/global/door/command.mjs +3 -1
- package/global/main.mjs +1 -1
- package/modules/agent-door/CLAUSES.md +215 -0
- package/modules/agent-door/conformance/audit.mjs +66 -0
- package/modules/agent-door/conformance/authority.d.mts +2 -0
- package/modules/agent-door/conformance/authority.mjs +17 -0
- package/modules/agent-door/conformance/crypto.mjs +36 -0
- package/modules/agent-door/conformance/discovery.mjs +61 -0
- package/modules/agent-door/conformance/index.mjs +41 -0
- package/modules/agent-door/conformance/invocation.mjs +32 -0
- package/modules/agent-door/conformance/journey.mjs +112 -0
- package/modules/agent-door/conformance/narrowing.d.mts +1 -0
- package/modules/agent-door/conformance/narrowing.mjs +21 -0
- package/modules/agent-door/conformance/negative.mjs +47 -0
- package/modules/agent-door/conformance/network-modules.mjs +86 -0
- package/modules/agent-door/conformance/network-runtime.mjs +46 -0
- package/modules/agent-door/conformance/policy-phases.mjs +75 -0
- package/modules/agent-door/conformance/protocol.mjs +145 -0
- package/modules/agent-door/conformance/replay.mjs +38 -0
- package/modules/agent-door/conformance/schema.mjs +71 -0
- package/modules/agent-door/conformance/security.mjs +33 -0
- package/modules/agent-door/conformance/sponsors.mjs +68 -0
- package/modules/agent-door/conformance/surface.mjs +89 -0
- package/modules/agent-door/conformance/target.mjs +18 -0
- package/modules/agent-door/conformance/tool-name.d.mts +1 -0
- package/modules/agent-door/conformance/tool-name.mjs +7 -0
- package/modules/agent-door/conformance/webhooks.mjs +30 -0
- package/modules/container/image-variables.mjs +8 -2
- package/modules/demo-host/README.md +6 -0
- package/modules/demo-host/ownership.mjs +39 -0
- package/modules/demo-host/plan.mjs +2 -1
- package/modules/demo-host/remove.mjs +6 -1
- package/modules/import-kit/schema/importer-verification-receipt.schema.json +171 -0
- package/modules/import-kit/schema/importers.schema.json +107 -0
- package/modules/import-kit/src/door/ADOPTING.md +20 -0
- package/modules/import-kit/src/door/README.md +2 -1
- package/modules/import-kit/src/door/admission.ts +5 -3
- package/modules/import-kit/src/door/archive.ts +5 -2
- package/modules/import-kit/src/door/authority.ts +1 -0
- package/modules/import-kit/src/door/grants.ts +1 -1
- package/modules/import-kit/src/door/handler.ts +14 -8
- package/modules/import-kit/src/door/index.ts +1 -1
- package/modules/import-kit/src/door/jobs.ts +40 -0
- package/modules/import-kit/src/door/operator.ts +3 -3
- package/modules/import-kit/src/door/planning.ts +10 -6
- package/modules/import-kit/src/door/protocol.ts +2 -2
- package/modules/import-kit/src/door/raw.ts +25 -0
- package/modules/import-kit/src/door/refusals.ts +1 -0
- package/modules/import-kit/src/door/types.ts +26 -6
- package/modules/import-kit/src/receipt/encoding.ts +37 -0
- package/modules/import-kit/src/receipt/index.ts +69 -0
- package/modules/import-kit/src/receipt/policy.ts +24 -0
- package/modules/import-kit/src/receipt/types.ts +64 -0
- package/modules/import-kit/src/receipt/uri.ts +45 -0
- package/modules/import-kit/src/receipt/validation.ts +87 -0
- package/modules/import-kit/src/status/encoding.ts +13 -0
- package/modules/import-kit/src/status/evidence.ts +218 -0
- package/modules/import-kit/src/status/index.ts +56 -0
- package/modules/import-kit/src/status/schema.ts +208 -0
- package/modules/import-kit/src/status/types.ts +86 -0
- package/modules/operator-auth/accounts/delegated.mjs +48 -0
- package/modules/operator-auth/index.d.mts +7 -0
- package/modules/operator-auth/service.mjs +2 -0
- package/modules/portability/README.md +32 -11
- package/modules/portability/bridge.mjs +22 -2
- package/modules/portability/copies.mjs +8 -1
- package/modules/portability/derived.mjs +33 -0
- package/modules/portability/http-errors.mjs +1 -1
- package/modules/portability/import.mjs +14 -7
- package/package.json +4 -2
- package/scripts/publish-check/copy_identities.py +3 -1
- package/scripts/publish-check/github_refs.py +32 -13
- package/cli/business/opt-ins.mjs +0 -37
|
@@ -3,10 +3,16 @@ import {deliveryDeclarationSources} from '../../cli/delivery-declarations.mjs';
|
|
|
3
3
|
import {sourcePath} from '../delivery-producer/migrations.mjs';
|
|
4
4
|
import {usesManagedMail,validateMailSpec} from '../delivery-producer/mail.mjs';
|
|
5
5
|
|
|
6
|
+
/** Shared binding comparison for source checks and emitted image validation. */
|
|
7
|
+
export function imageVariableSecrets(vars, secrets) {
|
|
8
|
+
return secrets.filter(secret => Object.hasOwn(vars, secret.binding));
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
/** Drop empty runtime-secret placeholders; admit only managed-mail public legacy values. */
|
|
7
12
|
export async function checkImageVariables(root,vars,secrets) {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
13
|
+
const declared=imageVariableSecrets(vars,secrets);
|
|
14
|
+
const placeholders=declared.filter(secret=>vars[secret.binding] === '');
|
|
15
|
+
const overlaps=declared.filter(secret=>vars[secret.binding] !== '');
|
|
10
16
|
if (!overlaps.length) {
|
|
11
17
|
for (const {binding} of placeholders) delete vars[binding];
|
|
12
18
|
return;
|
|
@@ -36,6 +36,12 @@ host. See [adoption and deployment](https://github.com/runeditrun/base/blob/main
|
|
|
36
36
|
- `upgrade.mjs`: verifies ownership, removes the old Container application and
|
|
37
37
|
derives the class migration from deployed namespaces and migration tag.
|
|
38
38
|
- `remove.mjs`: exact-id teardown, ownership collision checks and absence reads.
|
|
39
|
+
- `ownership.mjs`: read-only recovery when secret PUT removed the version message.
|
|
40
|
+
The served version must be newest, with a contiguous secret-triggered history
|
|
41
|
+
back to this demo's rer record and identical script ETag, runtime and bindings
|
|
42
|
+
(including secret names and bound resource IDs). Only upload-tool provenance may
|
|
43
|
+
differ. Missing history, changed resources or a foreign message refuses before
|
|
44
|
+
writes. The next ordinary deploy writes the annotation again.
|
|
39
45
|
|
|
40
46
|
The historical resource-name hash remains stable so released container demos
|
|
41
47
|
can upgrade and be removed from a fresh checkout. Portable container hosting
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { hash, uuid, identifier } from '../deploy-kit/validation.mjs';
|
|
2
|
+
|
|
3
|
+
// Secret PUT drops the version message but retains code, runtime and bindings
|
|
4
|
+
// (secret values are not readable). Ignore only the upload tool's provenance;
|
|
5
|
+
// compare every other resource field, including assets and binding identities.
|
|
6
|
+
function identity(version) {
|
|
7
|
+
const resources = version?.resources, script = resources?.script, bindings = resources?.bindings;
|
|
8
|
+
if (typeof script?.etag !== 'string' || !script.etag || !resources.script_runtime?.compatibility_date
|
|
9
|
+
|| !Array.isArray(bindings) || !bindings.every(row => identifier(row?.name) && typeof row.type === 'string')
|
|
10
|
+
|| new Set(bindings.map(row => row.name)).size !== bindings.length) return null;
|
|
11
|
+
const content = { ...script };
|
|
12
|
+
// The provider changes this from wrangler to api on a secret PUT.
|
|
13
|
+
delete content.last_deployed_from;
|
|
14
|
+
return hash({ ...resources, script: content, bindings: [...bindings].sort((a, b) => a.name.localeCompare(b.name)) });
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Read-only proof under this account and Worker name. Never jump over a foreign
|
|
18
|
+
* version to find an older rer mark, or accept an undeployed/split successor. */
|
|
19
|
+
export async function secretRotationOwned(api, plan, served) {
|
|
20
|
+
if (!served.current || served.annotation !== undefined) return false;
|
|
21
|
+
const path = `/workers/scripts/${plan.worker}/versions`;
|
|
22
|
+
const items = (await api.request(path))?.items;
|
|
23
|
+
if (!Array.isArray(items) || items[0]?.id !== served.versionId || !items.every(row => uuid(row?.id))
|
|
24
|
+
|| new Set(items.map(row => row.id)).size !== items.length) return false;
|
|
25
|
+
let expected;
|
|
26
|
+
for (const { id } of items) {
|
|
27
|
+
let version;
|
|
28
|
+
try { version = await api.request(`${path}/${id}`); }
|
|
29
|
+
catch (error) { if (error.status === 404) return false; throw error; }
|
|
30
|
+
if (version?.id !== id) return false;
|
|
31
|
+
const fingerprint = identity(version);
|
|
32
|
+
if (!fingerprint || expected && fingerprint !== expected) return false;
|
|
33
|
+
expected ??= fingerprint;
|
|
34
|
+
const message = version.annotations?.['workers/message'];
|
|
35
|
+
if (message !== undefined) return message === plan.record;
|
|
36
|
+
if (version.annotations?.['workers/triggered_by'] !== 'secret') return false;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
@@ -57,6 +57,7 @@ export function demoPlan({ project, environment, compatibilityDate, originVar, h
|
|
|
57
57
|
|
|
58
58
|
/** The demo's record of what `rer deploy --demo` creates, kept on the provider so a
|
|
59
59
|
* fresh checkout (a CI runner) can remove it: the deploy writes it as the Worker
|
|
60
|
-
* version's message
|
|
60
|
+
* version's message. A secret-only successor can prove continuity against that
|
|
61
|
+
* retained version without changing the provider during inventory. */
|
|
61
62
|
export const demoRecord = ({ worker, hostname, hostnames = [hostname], container }) =>
|
|
62
63
|
`rer-demo:${hash({ worker, hostname, container, ...(hostnames.length > 1 ? { hostnames } : {}) })}`;
|
|
@@ -2,6 +2,7 @@ import { ownedBucket, removeBucket } from './native/deploy-r2.mjs';
|
|
|
2
2
|
import { assert } from '../deploy-kit/validation.mjs';
|
|
3
3
|
import { workerSettings } from '../deploy-kit/owner.mjs';
|
|
4
4
|
import { servedVersion } from '../deploy-kit/site.mjs';
|
|
5
|
+
import { secretRotationOwned } from './ownership.mjs';
|
|
5
6
|
import { deleteWorker } from '../deploy-kit/teardown.mjs';
|
|
6
7
|
|
|
7
8
|
// Exact-id teardown and ownership inventory, shared by native upgrades.
|
|
@@ -23,7 +24,11 @@ export async function demoInventory(api, plan) {
|
|
|
23
24
|
for (const row of named) if (row.service !== plan.worker) throw refuse('resource-name-collision', `domain:${row.hostname}`);
|
|
24
25
|
if (worker) {
|
|
25
26
|
const served = await servedVersion(api, plan.worker);
|
|
26
|
-
if (served.annotation !== plan.record
|
|
27
|
+
if (served.annotation !== plan.record && !await secretRotationOwned(api, plan, served)) {
|
|
28
|
+
const error = refuse('resource-name-collision', `worker:${plan.worker}`);
|
|
29
|
+
error.ownershipReason = served.annotation === undefined ? 'missing-annotation' : 'different-annotation';
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
27
32
|
if (!served.current) throw refuse('owned-resource-replaced', `worker:${plan.worker}`);
|
|
28
33
|
for (const row of attached) if (!plan.hostnames.includes(row.hostname)) throw refuse('resource-not-in-record', `domain:${row.hostname}`);
|
|
29
34
|
} else if (named.length || attached.length || apps.length) {
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://runeditrun.com/schemas/import-kit/importer-verification-receipt-v1.schema.json",
|
|
4
|
+
"title": "Signed real-export importer verification receipt",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["schemaVersion", "type", "keyId", "algorithm", "payload", "signature"],
|
|
7
|
+
"properties": {
|
|
8
|
+
"schemaVersion": { "const": 1 },
|
|
9
|
+
"type": { "const": "runeditrun.importer-verification-receipt" },
|
|
10
|
+
"keyId": { "type": "string", "minLength": 1 },
|
|
11
|
+
"algorithm": { "const": "Ed25519" },
|
|
12
|
+
"payload": { "$ref": "#/$defs/payload" },
|
|
13
|
+
"signature": {
|
|
14
|
+
"type": "string",
|
|
15
|
+
"description": "Base64 Ed25519 signature over UTF-8 canonical JSON of payload, with object keys sorted recursively.",
|
|
16
|
+
"pattern": "^[A-Za-z0-9+/]+={0,2}$"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"additionalProperties": false,
|
|
20
|
+
"$defs": {
|
|
21
|
+
"hash": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
|
22
|
+
"revision": { "type": "string", "pattern": "^[a-f0-9]{40,64}$" },
|
|
23
|
+
"timestamp": { "type": "string", "format": "date-time" },
|
|
24
|
+
"counts": {
|
|
25
|
+
"type": "object",
|
|
26
|
+
"required": ["input", "unique", "duplicates", "mapped", "unmapped", "rejected", "effects", "byKind"],
|
|
27
|
+
"properties": {
|
|
28
|
+
"input": { "type": "integer", "minimum": 0 },
|
|
29
|
+
"unique": { "type": "integer", "minimum": 0 },
|
|
30
|
+
"duplicates": { "type": "integer", "minimum": 0 },
|
|
31
|
+
"mapped": { "type": "integer", "minimum": 0 },
|
|
32
|
+
"unmapped": { "type": "integer", "minimum": 0 },
|
|
33
|
+
"rejected": { "type": "integer", "minimum": 0 },
|
|
34
|
+
"effects": { "type": "integer", "minimum": 0 },
|
|
35
|
+
"byKind": {
|
|
36
|
+
"type": "object",
|
|
37
|
+
"minProperties": 1,
|
|
38
|
+
"additionalProperties": { "type": "integer", "minimum": 0 }
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"additionalProperties": false
|
|
42
|
+
},
|
|
43
|
+
"manifestComparison": {
|
|
44
|
+
"type": "object",
|
|
45
|
+
"required": ["sourceCount", "targetCount", "sourceManifestSha256", "targetManifestSha256"],
|
|
46
|
+
"properties": {
|
|
47
|
+
"sourceCount": { "type": "integer", "minimum": 0 },
|
|
48
|
+
"targetCount": { "type": "integer", "minimum": 0 },
|
|
49
|
+
"sourceManifestSha256": { "$ref": "#/$defs/hash" },
|
|
50
|
+
"targetManifestSha256": { "$ref": "#/$defs/hash" }
|
|
51
|
+
},
|
|
52
|
+
"additionalProperties": false
|
|
53
|
+
},
|
|
54
|
+
"payload": {
|
|
55
|
+
"type": "object",
|
|
56
|
+
"required": [
|
|
57
|
+
"incumbent", "product", "synthetic", "source", "candidate", "adapter",
|
|
58
|
+
"mapping", "command", "runs", "reconciliation", "unmapped", "research", "review"
|
|
59
|
+
],
|
|
60
|
+
"properties": {
|
|
61
|
+
"incumbent": { "type": "string", "minLength": 1 },
|
|
62
|
+
"product": { "type": "string", "minLength": 1 },
|
|
63
|
+
"synthetic": { "const": false },
|
|
64
|
+
"source": {
|
|
65
|
+
"type": "object",
|
|
66
|
+
"required": ["classification", "origin", "exportedAt", "format", "version", "sha256", "size"],
|
|
67
|
+
"properties": {
|
|
68
|
+
"classification": { "const": "authorized-real-export" },
|
|
69
|
+
"origin": { "type": "string", "minLength": 1 },
|
|
70
|
+
"exportedAt": { "$ref": "#/$defs/timestamp" },
|
|
71
|
+
"format": { "type": "string", "minLength": 1 },
|
|
72
|
+
"version": { "type": "string", "minLength": 1 },
|
|
73
|
+
"sha256": { "$ref": "#/$defs/hash" },
|
|
74
|
+
"size": { "type": "integer", "minimum": 1 }
|
|
75
|
+
},
|
|
76
|
+
"additionalProperties": false
|
|
77
|
+
},
|
|
78
|
+
"candidate": {
|
|
79
|
+
"type": "object",
|
|
80
|
+
"required": ["repository", "revision"],
|
|
81
|
+
"properties": {
|
|
82
|
+
"repository": { "type": "string", "minLength": 1 },
|
|
83
|
+
"revision": { "$ref": "#/$defs/revision" }
|
|
84
|
+
},
|
|
85
|
+
"additionalProperties": false
|
|
86
|
+
},
|
|
87
|
+
"adapter": {
|
|
88
|
+
"type": "object",
|
|
89
|
+
"required": ["repository", "revision"],
|
|
90
|
+
"properties": {
|
|
91
|
+
"repository": { "type": "string", "minLength": 1 },
|
|
92
|
+
"revision": { "$ref": "#/$defs/revision" }
|
|
93
|
+
},
|
|
94
|
+
"additionalProperties": false
|
|
95
|
+
},
|
|
96
|
+
"mapping": {
|
|
97
|
+
"type": "object",
|
|
98
|
+
"required": ["version", "policy", "policySha256"],
|
|
99
|
+
"properties": {
|
|
100
|
+
"version": { "type": "string", "minLength": 1 },
|
|
101
|
+
"policy": { "type": "string", "minLength": 1 },
|
|
102
|
+
"policySha256": { "$ref": "#/$defs/hash" }
|
|
103
|
+
},
|
|
104
|
+
"additionalProperties": false
|
|
105
|
+
},
|
|
106
|
+
"command": { "type": "string", "minLength": 1 },
|
|
107
|
+
"runs": {
|
|
108
|
+
"type": "object",
|
|
109
|
+
"required": ["dryRun", "apply"],
|
|
110
|
+
"properties": {
|
|
111
|
+
"dryRun": { "$ref": "#/$defs/counts" },
|
|
112
|
+
"apply": { "$ref": "#/$defs/counts" }
|
|
113
|
+
},
|
|
114
|
+
"additionalProperties": false
|
|
115
|
+
},
|
|
116
|
+
"reconciliation": {
|
|
117
|
+
"type": "object",
|
|
118
|
+
"required": ["rows", "provenance", "attachments"],
|
|
119
|
+
"properties": {
|
|
120
|
+
"rows": { "$ref": "#/$defs/manifestComparison" },
|
|
121
|
+
"provenance": { "$ref": "#/$defs/manifestComparison" },
|
|
122
|
+
"attachments": { "$ref": "#/$defs/manifestComparison" }
|
|
123
|
+
},
|
|
124
|
+
"additionalProperties": false
|
|
125
|
+
},
|
|
126
|
+
"unmapped": {
|
|
127
|
+
"type": "object",
|
|
128
|
+
"required": ["count", "itemManifestSha256", "items"],
|
|
129
|
+
"properties": {
|
|
130
|
+
"count": { "type": "integer", "minimum": 0 },
|
|
131
|
+
"itemManifestSha256": { "$ref": "#/$defs/hash" },
|
|
132
|
+
"items": {
|
|
133
|
+
"type": "array",
|
|
134
|
+
"items": {
|
|
135
|
+
"type": "object",
|
|
136
|
+
"required": ["sourceIdentitySha256", "sourceKind", "fields"],
|
|
137
|
+
"properties": {
|
|
138
|
+
"sourceIdentitySha256": { "$ref": "#/$defs/hash" },
|
|
139
|
+
"sourceKind": { "type": "string", "minLength": 1 },
|
|
140
|
+
"fields": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } }
|
|
141
|
+
},
|
|
142
|
+
"additionalProperties": false
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
"additionalProperties": false
|
|
147
|
+
},
|
|
148
|
+
"research": {
|
|
149
|
+
"type": "object",
|
|
150
|
+
"required": ["state", "sha256"],
|
|
151
|
+
"properties": {
|
|
152
|
+
"state": { "const": "finished" },
|
|
153
|
+
"sha256": { "$ref": "#/$defs/hash" }
|
|
154
|
+
},
|
|
155
|
+
"additionalProperties": false
|
|
156
|
+
},
|
|
157
|
+
"review": {
|
|
158
|
+
"type": "object",
|
|
159
|
+
"required": ["reviewer", "reviewedAt", "result"],
|
|
160
|
+
"properties": {
|
|
161
|
+
"reviewer": { "type": "string", "minLength": 3, "maxLength": 128, "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]+$" },
|
|
162
|
+
"reviewedAt": { "$ref": "#/$defs/timestamp" },
|
|
163
|
+
"result": { "const": "passed" }
|
|
164
|
+
},
|
|
165
|
+
"additionalProperties": false
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
"additionalProperties": false
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://runeditrun.com/schemas/import-kit/importers-v1.schema.json",
|
|
4
|
+
"title": "Evidence-bound importer status catalogue",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["$schema", "schemaVersion", "importers"],
|
|
7
|
+
"properties": {
|
|
8
|
+
"$schema": { "const": "./schema/importers.schema.json" },
|
|
9
|
+
"schemaVersion": { "const": 1 },
|
|
10
|
+
"importers": {
|
|
11
|
+
"type": "array",
|
|
12
|
+
"minItems": 1,
|
|
13
|
+
"items": {
|
|
14
|
+
"oneOf": [
|
|
15
|
+
{ "$ref": "#/$defs/verifiedImporter" },
|
|
16
|
+
{ "$ref": "#/$defs/documentedImporter" },
|
|
17
|
+
{ "$ref": "#/$defs/noneImporter" }
|
|
18
|
+
]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"additionalProperties": false,
|
|
23
|
+
"$defs": {
|
|
24
|
+
"artifact": {
|
|
25
|
+
"type": "object",
|
|
26
|
+
"required": ["link", "sha256", "size"],
|
|
27
|
+
"properties": {
|
|
28
|
+
"link": { "type": "string", "minLength": 1 },
|
|
29
|
+
"sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
|
30
|
+
"size": { "type": "integer", "minimum": 1 }
|
|
31
|
+
},
|
|
32
|
+
"additionalProperties": false
|
|
33
|
+
},
|
|
34
|
+
"verifiedImporter": {
|
|
35
|
+
"type": "object",
|
|
36
|
+
"required": ["incumbent", "product", "status", "evidence"],
|
|
37
|
+
"properties": {
|
|
38
|
+
"incumbent": { "type": "string", "minLength": 1 },
|
|
39
|
+
"product": { "type": "string", "minLength": 1 },
|
|
40
|
+
"status": { "const": "verified" },
|
|
41
|
+
"evidence": {
|
|
42
|
+
"type": "object",
|
|
43
|
+
"required": ["link", "sha256", "size", "research"],
|
|
44
|
+
"properties": {
|
|
45
|
+
"link": { "type": "string", "minLength": 1 },
|
|
46
|
+
"sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
|
47
|
+
"size": { "type": "integer", "minimum": 1 },
|
|
48
|
+
"research": { "$ref": "#/$defs/artifact" }
|
|
49
|
+
},
|
|
50
|
+
"additionalProperties": false
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"additionalProperties": false
|
|
54
|
+
},
|
|
55
|
+
"documentedImporter": {
|
|
56
|
+
"type": "object",
|
|
57
|
+
"required": ["incumbent", "product", "status", "evidence"],
|
|
58
|
+
"properties": {
|
|
59
|
+
"incumbent": { "type": "string", "minLength": 1 },
|
|
60
|
+
"product": { "type": "string", "minLength": 1 },
|
|
61
|
+
"status": { "const": "documented format" },
|
|
62
|
+
"evidence": {
|
|
63
|
+
"type": "object",
|
|
64
|
+
"required": [
|
|
65
|
+
"link", "sha256", "size", "sourceRepository", "sourceRevision",
|
|
66
|
+
"sourcePath", "sourceSha256", "validation", "realExport"
|
|
67
|
+
],
|
|
68
|
+
"properties": {
|
|
69
|
+
"link": { "type": "string", "minLength": 1 },
|
|
70
|
+
"sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
|
71
|
+
"size": { "type": "integer", "minimum": 1 },
|
|
72
|
+
"sourceRepository": { "type": "string", "minLength": 1 },
|
|
73
|
+
"sourceRevision": { "type": "string", "pattern": "^[a-f0-9]{40,64}$" },
|
|
74
|
+
"sourcePath": { "type": "string", "minLength": 1 },
|
|
75
|
+
"sourceSha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
|
76
|
+
"validation": { "const": "synthetic-only" },
|
|
77
|
+
"realExport": { "const": "not-supplied" }
|
|
78
|
+
},
|
|
79
|
+
"additionalProperties": false
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"additionalProperties": false
|
|
83
|
+
},
|
|
84
|
+
"noneImporter": {
|
|
85
|
+
"type": "object",
|
|
86
|
+
"required": ["incumbent", "product", "status", "evidence"],
|
|
87
|
+
"properties": {
|
|
88
|
+
"incumbent": { "type": "string", "minLength": 1 },
|
|
89
|
+
"product": { "type": "string", "minLength": 1 },
|
|
90
|
+
"status": { "const": "none" },
|
|
91
|
+
"evidence": {
|
|
92
|
+
"type": "object",
|
|
93
|
+
"required": ["link", "sha256", "size", "reason", "checkedAt"],
|
|
94
|
+
"properties": {
|
|
95
|
+
"link": { "type": "string", "minLength": 1 },
|
|
96
|
+
"sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
|
97
|
+
"size": { "type": "integer", "minimum": 1 },
|
|
98
|
+
"reason": { "type": "string", "minLength": 1 },
|
|
99
|
+
"checkedAt": { "type": "string", "format": "date-time" }
|
|
100
|
+
},
|
|
101
|
+
"additionalProperties": false
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"additionalProperties": false
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -361,6 +361,26 @@ requires replacing that caller with the operator mount and deleting the old
|
|
|
361
361
|
HTTP importer in `src/domain/sentry-import/routes.ts`.
|
|
362
362
|
Do not copy its older vendored door instead of current Base.
|
|
363
363
|
|
|
364
|
+
## Raw source files
|
|
365
|
+
|
|
366
|
+
For ZIP or another binary export, declare `format: 'raw'` and
|
|
367
|
+
`readRaw(upload, limits)` instead of `parse`. The same source declaration serves
|
|
368
|
+
both mounts, including a grant allow-list entry. The reader receives the verified
|
|
369
|
+
`upload.bytes` (`Uint8Array`), `name`, `sha256` and `size`, before any text decoding,
|
|
370
|
+
and returns a `ParsedRecord[]` (or a promise of it). Bound archive expansion while
|
|
371
|
+
reading, inspect every member for credentials, and reject malformed or unsupported
|
|
372
|
+
archives; thrown errors become a non-secret 422 `source_raw_reader_failed`.
|
|
373
|
+
The door validates returned records, retains the exact original archive and binds
|
|
374
|
+
it to the reviewed fingerprint. Raw sources cannot declare `intake`, which changes
|
|
375
|
+
custody bytes. Chunk uploads have at most 1,024 chunks of 64 KiB: a 64 MiB
|
|
376
|
+
(67,108,864-byte) ceiling, also the default owner quota. Signed quotas can reduce
|
|
377
|
+
it. `limits.maxBytes` may lower it further and is checked before the
|
|
378
|
+
reader runs; excess upload declarations are refused, or planning answers 413
|
|
379
|
+
`source_byte_limit` (a previously retained upload above a lowered owner quota
|
|
380
|
+
answers 403 `upload_exceeds_grant_quota`). Record count and per-record byte limits still apply. Export
|
|
381
|
+
exclusion, erasure of complete or partial custody, archive restore-check, catch-up
|
|
382
|
+
and Undo use the existing lifecycle and require the same seed integration proof.
|
|
383
|
+
|
|
364
384
|
## Copyable public HTTP conformance
|
|
365
385
|
|
|
366
386
|
Copy the following into an existing seed test journey and call `checkDoor`.
|
|
@@ -225,11 +225,12 @@ are admission limits, not a hosted capacity promise.
|
|
|
225
225
|
| `uploads` (no intake declaration) | `{ uploadId?, name, bundleSha256, totalBytes, totalChunks, index, chunkSha256, base64 }`; decoded chunks are exactly 64 KiB except the final chunk. `totalChunks` must equal `ceil(totalBytes / 65536)`. Omit `uploadId` on the first chunk to receive a server-generated UUID. Reuse it and the same bundle metadata for subsequent chunks. Both chunk and complete bundle SHA-256 are checked before reporting completion. |
|
|
226
226
|
| `uploads` (declared intake) | Full raw stream with `Content-Type: application/octet-stream`, `X-Import-Format: csv\|ndjson\|json` and `X-Import-Name: <safe file name>`. Returns custody hashes and intake metadata; see below. |
|
|
227
227
|
| `uploads` | `{ uploadId }` returns received-chunk inventory/progress. Without intake, an identical duplicate chunk is idempotent with a fresh grant. |
|
|
228
|
-
| `plan` | `{ uploadId, catchup?: boolean }` returns `planId`, `fingerprint`, server-derived counts, summary, rejected rows with reasons, `diagnostics` and differences including gone source ids. Planning makes no native target writes. |
|
|
228
|
+
| `plan` | `{ uploadId, catchup?: boolean }` returns `planId`, `fingerprint`, `created` (true only when this request created the plan), server-derived counts, summary, rejected rows with reasons, `diagnostics` and differences including gone source ids. Planning makes no native target writes. |
|
|
229
229
|
| `apply` | `{ planId, reviewedFingerprint }` creates or resumes the real kit job in bounded batches. Repeat with a fresh valid grant to continue. A large source (a stored plan over 4 MiB, such as a multi-megabyte Notion export) is created in bounded staged steps within one request, and the answer may be the still `queued` job; an interrupted creation is never a job and the next `apply` resumes it from what was staged. |
|
|
230
230
|
| `status` | `{ planId }` reads current job progress. |
|
|
231
231
|
| `reconcile` | `{ planId }` derives source-id disposition/presence and native/provenance revision, value, attachment and count checks on the server. |
|
|
232
232
|
| `undo` | `{ planId }` reverses the newest snapshot's attributed effects in bounded kit work, preserving native edits. |
|
|
233
|
+
| `cancel` | `{ planId }` removes only an unapproved private plan with no `job_id`, failure or kit job under its operation key. Otherwise answers 409 `plan_cancel_refused`. Grant only; the owner-session mount uses `undo`. |
|
|
233
234
|
| `archive` | `{ uploadId, tool, takenAt }` keeps a fully uploaded bundle as the tool's archive; returns `archiveId`, `key`, `tool`, `takenAt`, `bundleSha256`, `bytes` and `counts`. Grant only. See "Archives". |
|
|
234
235
|
| `restore-check` | `{ archiveId }` parses the archive with the namespace's reader and mapping and writes nothing native; returns the archive's fields with `bundleSha256`, `bytes` and `counts` recomputed from its bytes, and `rejected`. Grant only. |
|
|
235
236
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ImportDoorOptions,
|
|
1
|
+
import type { ImportDoorOptions, ImportDoorRuntime, DoorRequest } from './types.ts';
|
|
2
2
|
import { runtimeOptions } from './handler.ts';
|
|
3
3
|
import { DoorError, verifyImportGrant, type DoorAction } from './grants.ts';
|
|
4
4
|
import { doorFence, erasures, sql, transact } from './store.ts';
|
|
@@ -17,11 +17,13 @@ export async function enabled(options: ImportDoorOptions): Promise<boolean> {
|
|
|
17
17
|
}
|
|
18
18
|
/** This grant's parser and mapping: the mount's own, or the seed's allow-list entry
|
|
19
19
|
* for the verified namespace. Unlisted namespaces are refused before any write. */
|
|
20
|
-
async function source(options: ImportDoorOptions, namespace: string): Promise<
|
|
20
|
+
async function source(options: ImportDoorOptions, namespace: string): Promise<ImportDoorRuntime> {
|
|
21
21
|
if (!options.source) return runtimeOptions(options);
|
|
22
22
|
const listed = await options.source(namespace);
|
|
23
23
|
if (!listed) throw new DoorError('unknown_import_source');
|
|
24
|
-
return runtimeOptions({...options, parse: listed.parse, mapping: listed.mapping, intake: listed.intake,
|
|
24
|
+
return runtimeOptions({...options, parse: listed.parse, mapping: listed.mapping, intake: listed.intake,
|
|
25
|
+
format: listed.format ?? options.format, readRaw: 'readRaw' in listed ? listed.readRaw : undefined,
|
|
26
|
+
ownerPrincipalId: listed.ownerPrincipalId ?? options.ownerPrincipalId});
|
|
25
27
|
}
|
|
26
28
|
export async function admit(options: ImportDoorOptions, request: Request, action: DoorAction): Promise<DoorRequest> {
|
|
27
29
|
const authorization = request.headers.get('Authorization');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readRawSource } from './raw.ts';
|
|
1
2
|
import { Buffer } from 'node:buffer';
|
|
2
3
|
import { randomUUID } from 'node:crypto';
|
|
3
4
|
import { canonicalJson, sha256 } from '../provenance/identity.ts';
|
|
@@ -44,8 +45,10 @@ async function readArchive(request: DoorRequest, name: string, bytes: Uint8Array
|
|
|
44
45
|
if (!!intake !== !!options.intake || (intake && intake.allowlistSha256 !== intakeIdentity(options.intake!))) throw new DoorError('archive_intake_changed',409);
|
|
45
46
|
const kitNamespace = 'door-archive:' + sha256(canonicalJson([access.namespace, bundleSha256, id]));
|
|
46
47
|
try {
|
|
47
|
-
const
|
|
48
|
-
|
|
48
|
+
const limits = {...options.limits, maxBytes: Math.min(options.limits?.maxBytes ?? access.maxBytes, access.maxBytes), maxRecords: Math.min(options.limits?.maxRecords ?? access.maxRecords, access.maxRecords)};
|
|
49
|
+
const {source, liveCredentialsRemoved} = options.format === 'raw'
|
|
50
|
+
? {source: await readRawSource(options,{name,bundle_sha256:bundleSha256,total_bytes:bytes.length},bytes,kitNamespace,limits),liveCredentialsRemoved:false}
|
|
51
|
+
: await readFileSourceRemovals({namespace: kitNamespace, name, bytes, format: intake ? 'ndjson' : options.format, parse: options.parse, credentials: 'remove'},limits);
|
|
49
52
|
if (liveCredentialsRemoved) throw new DoorError('archive_holds_credentials', 422,
|
|
50
53
|
{reason: 'The bundle holds credential values, and an archive keeps its exact bytes, so it is not kept. Export again with credential values removed (rer\'s vendor exports remove them) and archive that.'});
|
|
51
54
|
if (intake) source.intake = intake;
|
|
@@ -9,6 +9,7 @@ import { reserveReturn } from '../d1/budget.ts';
|
|
|
9
9
|
const actions: Record<DoorAction, ImportAction[]> = {
|
|
10
10
|
uploads: [], plan: ['plan', 'read'], apply: ['create', 'apply', 'read'],
|
|
11
11
|
status: ['read'], reconcile: ['read'], undo: ['read', 'undo', 'rollback'],
|
|
12
|
+
cancel: [],
|
|
12
13
|
// Parsing a bundle for its counts is a plan: no native write.
|
|
13
14
|
archive: ['plan'], 'restore-check': ['plan'],
|
|
14
15
|
};
|
|
@@ -10,7 +10,7 @@ function fail(): never { throw new DoorError('invalid_grant'); }
|
|
|
10
10
|
const object = (value: unknown): value is Record<string, unknown> => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
11
11
|
const requiredKeys = ['v', 'iss', 'aud', 'installationId', 'email', 'jti', 'iat', 'exp', 'action', 'namespace', 'maxBytes', 'maxChunks', 'maxRecords'];
|
|
12
12
|
const optionalKeys = ['fingerprint', 'approvalRecordId', 'approvedAt', 'catchup'];
|
|
13
|
-
const actions: readonly string[] = ['uploads', 'plan', 'apply', 'status', 'reconcile', 'undo', 'archive', 'restore-check'];
|
|
13
|
+
const actions: readonly string[] = ['uploads', 'plan', 'apply', 'status', 'reconcile', 'undo', 'cancel', 'archive', 'restore-check'];
|
|
14
14
|
|
|
15
15
|
function decode(segment: string): Uint8Array<ArrayBuffer> {
|
|
16
16
|
if (!/^[A-Za-z0-9_-]+$/.test(segment)) fail();
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { D1Database } from '../d1/types.ts';
|
|
2
|
-
import type { DoorRequest,
|
|
2
|
+
import type { DoorRequest, ImportDoorRuntime, ImportDoorRawSource } from './types.ts';
|
|
3
3
|
import { DoorError, GRANT_ONLY_ACTIONS, type DoorAction } from './protocol.ts';
|
|
4
4
|
import { authorized, erasedSince } from './store.ts';
|
|
5
5
|
import { sizeLimitError } from './limits.ts';
|
|
6
6
|
import { requestDatabase } from '../d1/budget.ts';
|
|
7
7
|
import { uploads } from './uploads.ts';
|
|
8
8
|
import { plan } from './planning.ts';
|
|
9
|
-
import { apply, status, reconcile, undo } from './jobs.ts';
|
|
9
|
+
import { apply, status, reconcile, undo, cancel } from './jobs.ts';
|
|
10
10
|
import { archive, restoreCheck } from './archive.ts';
|
|
11
11
|
import { streamUpload } from './intake-upload.ts';
|
|
12
12
|
import { intakeIdentity } from './intake-policy.ts';
|
|
13
13
|
|
|
14
|
-
const routes = {uploads,plan,apply,status,reconcile,undo,archive,'restore-check':restoreCheck};
|
|
14
|
+
const routes = {uploads,plan,apply,status,reconcile,undo,cancel,archive,'restore-check':restoreCheck};
|
|
15
15
|
const headers = {'Cache-Control':'no-store','Content-Type':'application/json','X-Content-Type-Options':'nosniff'};
|
|
16
16
|
async function readInput(request: Request): Promise<Record<string,unknown>> {
|
|
17
17
|
if (request.headers.get('Content-Type')?.split(';')[0] !== 'application/json' || !request.body) throw new DoorError('json_body_required',400);
|
|
@@ -31,16 +31,22 @@ async function readInput(request: Request): Promise<Record<string,unknown>> {
|
|
|
31
31
|
if (!value || typeof value!=='object' || Array.isArray(value)) throw new DoorError('invalid_input',400);
|
|
32
32
|
return value;
|
|
33
33
|
}
|
|
34
|
+
type RuntimeConfiguration = {[K in keyof ImportDoorRuntime]?: ImportDoorRuntime[K]} & {
|
|
35
|
+
readRaw?: ImportDoorRawSource['readRaw'];
|
|
36
|
+
};
|
|
37
|
+
|
|
34
38
|
/** The settings every mount needs whatever its source: a preserving undo policy needs the adapter's preserved undo. */
|
|
35
|
-
export function mountValid(options:
|
|
39
|
+
export function mountValid(options: RuntimeConfiguration): boolean {
|
|
36
40
|
return !!options.ownerPrincipalId?.trim() && !!options.destination?.trim() && [undefined,'strict','preserve-conflicts'].includes(options.reversalPolicy)
|
|
37
41
|
&& (options.reversalPolicy!=='preserve-conflicts' || typeof options.targets?.preparePreservedUndo==='function');
|
|
38
42
|
}
|
|
39
43
|
/** Refuses a mount, or a resolved source, missing what the pipeline needs. */
|
|
40
|
-
export function runtimeOptions<T extends
|
|
41
|
-
if (!options.mapping?.version ||
|
|
44
|
+
export function runtimeOptions<T extends RuntimeConfiguration>(options: T): T & ImportDoorRuntime {
|
|
45
|
+
if (!options.mapping?.version || !mountValid(options)
|
|
46
|
+
|| (options.format === 'raw' ? typeof options.readRaw !== 'function' || options.intake !== undefined
|
|
47
|
+
: typeof options.parse !== 'function')) throw new DoorError('invalid_configuration',503);
|
|
42
48
|
if (options.intake !== undefined) intakeIdentity(options.intake);
|
|
43
|
-
return options as T &
|
|
49
|
+
return options as T & ImportDoorRuntime;
|
|
44
50
|
}
|
|
45
51
|
/** Server-side mount only. A null response belongs to another dispatcher. Every
|
|
46
52
|
* statement of one request, the door's own, the adapter's and each kit call's,
|
|
@@ -71,7 +77,7 @@ export function createDoorHandler(prefix: string, database: D1Database,
|
|
|
71
77
|
}
|
|
72
78
|
const input = await readInput(request);
|
|
73
79
|
admitted = await review(admitted,input);
|
|
74
|
-
if (['status','reconcile','undo'].includes(action) && Object.keys(input).some(k=>k!=='planId')) throw new DoorError('invalid_input',400);
|
|
80
|
+
if (['status','reconcile','undo','cancel'].includes(action) && Object.keys(input).some(k=>k!=='planId')) throw new DoorError('invalid_input',400);
|
|
75
81
|
const result = await routes[action](admitted,input);
|
|
76
82
|
await authorized(admitted);
|
|
77
83
|
return Response.json(result,{headers});
|
|
@@ -13,7 +13,7 @@ export { createImportOperatorHandler } from './operator.ts';
|
|
|
13
13
|
export function createImportDoorHandler(options: ImportDoorOptions): (request: Request)=>Promise<Response|null> {
|
|
14
14
|
if (options.installationId !== undefined && (typeof options.installationId !== 'string' || !options.installationId.trim())) throw new DoorError('invalid_configuration',503);
|
|
15
15
|
if (options.source === undefined) runtimeOptions(options);
|
|
16
|
-
else if (typeof options.source !== 'function' || options.parse !== undefined || options.mapping !== undefined
|
|
16
|
+
else if (typeof options.source !== 'function' || options.parse !== undefined || options.mapping !== undefined || options.readRaw !== undefined
|
|
17
17
|
|| !mountValid(options)) throw new DoorError('invalid_configuration',503);
|
|
18
18
|
return createDoorHandler('/api/rer/import/', options.database, (request, action, database) => admit({...options, database}, request, action),
|
|
19
19
|
undefined, async database => !!options.claim?.publicKeys && Object.keys(options.claim.publicKeys).length > 0 && await enabled({...options, database}));
|
|
@@ -102,6 +102,46 @@ export async function reconcile(request: DoorRequest, input: Record<string,unkno
|
|
|
102
102
|
await authorized(request);
|
|
103
103
|
return {planId:row.id,fingerprint:row.fingerprint,bundleSha256:snapshot.bundleSha256,...report};
|
|
104
104
|
}
|
|
105
|
+
/** RER's cleanup for a plan created only while checking an executor's report.
|
|
106
|
+
* It can discard private plan custody, never a reviewed or published import. */
|
|
107
|
+
export async function cancel(request: DoorRequest, input: Record<string,unknown>) {
|
|
108
|
+
const id = text(input.planId,'plan_id'), db = request.options.database;
|
|
109
|
+
const row = await db.prepare(`SELECT p.job_id,
|
|
110
|
+
EXISTS(SELECT 1 FROM ik_jobs j WHERE j.destination=? AND j.principal_id=? AND j.operation_key='door:'||p.id) AS has_job,
|
|
111
|
+
EXISTS(SELECT 1 FROM ik_door_approvals a WHERE a.plan_id=p.id) AS has_approval,
|
|
112
|
+
EXISTS(SELECT 1 FROM ik_door_apply_failures f WHERE f.plan_id=p.id) AS has_failure
|
|
113
|
+
FROM ik_door_plans p WHERE p.id=? AND p.installation_id=? AND p.namespace=?`)
|
|
114
|
+
.bind(request.options.destination,request.options.ownerPrincipalId,id,request.access.installationId,request.access.namespace)
|
|
115
|
+
.first<{job_id:string|null;has_job:number;has_approval:number;has_failure:number}>();
|
|
116
|
+
if (!row) throw new DoorError('plan_not_found',404);
|
|
117
|
+
if (row.job_id || row.has_job || row.has_approval || row.has_failure) throw new DoorError('plan_cancel_refused',409);
|
|
118
|
+
const clear = sql(`EXISTS(SELECT 1 FROM ik_door_plans p WHERE p.id=? AND p.installation_id=? AND p.namespace=? AND p.job_id IS NULL
|
|
119
|
+
AND NOT EXISTS(SELECT 1 FROM ik_jobs j WHERE j.destination=? AND j.principal_id=? AND j.operation_key='door:'||p.id)
|
|
120
|
+
AND NOT EXISTS(SELECT 1 FROM ik_door_approvals a WHERE a.plan_id=p.id)
|
|
121
|
+
AND NOT EXISTS(SELECT 1 FROM ik_door_apply_failures f WHERE f.plan_id=p.id))`,
|
|
122
|
+
id,request.access.installationId,request.access.namespace,request.options.destination,request.options.ownerPrincipalId);
|
|
123
|
+
try {
|
|
124
|
+
await transact(db,request.authority,[
|
|
125
|
+
assertion(clear),
|
|
126
|
+
sql('UPDATE ik_door_namespaces SET pending_id=NULL WHERE installation_id=? AND namespace=? AND pending_id=?',request.access.installationId,request.access.namespace,id),
|
|
127
|
+
sql('DELETE FROM ik_d1_staging WHERE destination=? AND principal_id=? AND operation_key=?',request.options.destination,request.options.ownerPrincipalId,'door:'+id),
|
|
128
|
+
sql('DELETE FROM ik_door_plan_chunks WHERE plan_id=?',id),
|
|
129
|
+
sql(`DELETE FROM ik_door_plans WHERE id=? AND job_id IS NULL
|
|
130
|
+
AND NOT EXISTS(SELECT 1 FROM ik_jobs j WHERE j.destination=? AND j.principal_id=? AND j.operation_key='door:'||ik_door_plans.id)
|
|
131
|
+
AND NOT EXISTS(SELECT 1 FROM ik_door_approvals a WHERE a.plan_id=ik_door_plans.id)
|
|
132
|
+
AND NOT EXISTS(SELECT 1 FROM ik_door_apply_failures f WHERE f.plan_id=ik_door_plans.id)`,id,request.options.destination,request.options.ownerPrincipalId),
|
|
133
|
+
]);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (error instanceof DoorError) throw error;
|
|
136
|
+
const blocked = await db.prepare(`SELECT 1 FROM ik_door_plans p WHERE p.id=? AND (p.job_id IS NOT NULL
|
|
137
|
+
OR EXISTS(SELECT 1 FROM ik_jobs j WHERE j.destination=? AND j.principal_id=? AND j.operation_key='door:'||p.id)
|
|
138
|
+
OR EXISTS(SELECT 1 FROM ik_door_approvals a WHERE a.plan_id=p.id)
|
|
139
|
+
OR EXISTS(SELECT 1 FROM ik_door_apply_failures f WHERE f.plan_id=p.id))`).bind(id,request.options.destination,request.options.ownerPrincipalId).first();
|
|
140
|
+
if (blocked) throw new DoorError('plan_cancel_refused',409);
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
return {planId:id,state:'cancelled'};
|
|
144
|
+
}
|
|
105
145
|
export async function undo(request: DoorRequest, input: Record<string,unknown>) {
|
|
106
146
|
const id = text(input.planId,'plan_id');
|
|
107
147
|
const candidate = await request.options.database.prepare('SELECT * FROM ik_door_plans WHERE id=? AND installation_id=? AND namespace=?').bind(id,request.access.installationId,request.access.namespace).first<DoorPlanRow>();
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { DoorRequest, ImportOperatorOptions } from './types.ts';
|
|
1
|
+
import type { DoorRequest, ImportOperatorOptions, ImportRawOperatorOptions } from './types.ts';
|
|
2
2
|
import { DoorError } from './protocol.ts';
|
|
3
3
|
import { createDoorHandler, runtimeOptions } from './handler.ts';
|
|
4
4
|
import { authorized, doorFence, erasures, schemaCurrent, sql } from './store.ts';
|
|
5
5
|
export { importDoorSchema, importDoorApplyFailureMigration, importDoorScopesMigration, importDoorArchiveMigration, importDoorIntakeMigration } from './schema.ts';
|
|
6
6
|
export { writeImportDoorSettings, readImportDoorHistory } from './authority.ts';
|
|
7
|
-
export type { ImportOperatorOptions } from './types.ts';
|
|
7
|
+
export type { ImportOperatorOptions, ImportRawOperatorOptions } from './types.ts';
|
|
8
8
|
|
|
9
9
|
/** Owner-session entry point. No owner-claim module or grant key ring required. */
|
|
10
|
-
export function createImportOperatorHandler(options: ImportOperatorOptions) {
|
|
10
|
+
export function createImportOperatorHandler(options: ImportOperatorOptions | ImportRawOperatorOptions) {
|
|
11
11
|
if (!options.installationId?.trim() || !options.ownerEmail?.trim() || !options.namespace?.trim()
|
|
12
12
|
|| new URL(options.appOrigin).origin !== options.appOrigin || typeof options.authorize !== 'function') throw new DoorError('invalid_configuration',503);
|
|
13
13
|
runtimeOptions(options);
|