@runeditrun/rer 0.2.85 → 0.2.87

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.
Files changed (162) hide show
  1. package/README.md +138 -29
  2. package/cli/README.md +61 -1
  3. package/cli/agent-bindings.mjs +25 -0
  4. package/cli/agent-door.mjs +145 -0
  5. package/cli/agent-fixtures.mjs +16 -0
  6. package/cli/agent-journey-fixtures.mjs +17 -0
  7. package/cli/agent-mail.mjs +54 -0
  8. package/cli/agent-network.mjs +64 -0
  9. package/cli/agent-reviewers.mjs +110 -0
  10. package/cli/agent-rpc.mjs +23 -0
  11. package/cli/agent-secrets.mjs +23 -0
  12. package/cli/agent-sponsors.mjs +43 -0
  13. package/cli/agent-surface.mjs +34 -0
  14. package/cli/agent-verifier.mjs +31 -0
  15. package/cli/agent-webhooks.mjs +19 -0
  16. package/cli/authoring.mjs +2 -1
  17. package/cli/business/archive-task.mjs +32 -0
  18. package/cli/business/carry.mjs +3 -1
  19. package/cli/business/catchup-task.mjs +42 -0
  20. package/cli/business/choices.mjs +97 -0
  21. package/cli/business/command.mjs +23 -5
  22. package/cli/business/connect.mjs +19 -7
  23. package/cli/business/detector.mjs +4 -1
  24. package/cli/business/device.mjs +13 -0
  25. package/cli/business/export-inputs.mjs +69 -0
  26. package/cli/business/export-task.mjs +17 -0
  27. package/cli/business/invocation.mjs +8 -1
  28. package/cli/business/keychain.mjs +8 -1
  29. package/cli/business/lease.mjs +11 -1
  30. package/cli/business/local-commands.mjs +79 -31
  31. package/cli/business/outbound.mjs +9 -4
  32. package/cli/business/parsers-config.mjs +8 -7
  33. package/cli/business/parsers-syntax.mjs +7 -3
  34. package/cli/business/permissions.mjs +2 -0
  35. package/cli/business/questions.mjs +89 -9
  36. package/cli/business/setup-command.mjs +49 -0
  37. package/cli/business/setup-company.json +15 -0
  38. package/cli/business/setup-demo.mjs +95 -0
  39. package/cli/business/state.mjs +44 -10
  40. package/cli/business/supervisor.mjs +94 -35
  41. package/cli/business/vendor-door.mjs +230 -0
  42. package/cli/business/vendors/README.md +29 -3
  43. package/cli/business/vendors/common.mjs +8 -6
  44. package/cli/business/vendors/index.mjs +22 -11
  45. package/cli/business/vendors/sorry.mjs +106 -0
  46. package/cli/contract.mjs +2 -2
  47. package/cli/demo-deploy-error.mjs +14 -0
  48. package/cli/demo-native.mjs +4 -1
  49. package/cli/deploy-config.mjs +1 -1
  50. package/cli/deploy-owner-input.mjs +3 -1
  51. package/cli/deploy-variables.mjs +89 -0
  52. package/cli/door-clauses.mjs +157 -0
  53. package/cli/export.mjs +17 -4
  54. package/cli/hosted-output.mjs +31 -8
  55. package/cli/inspect.mjs +4 -0
  56. package/cli/jsonc.mjs +8 -4
  57. package/cli/lifecycle.mjs +3 -1
  58. package/cli/main.mjs +1 -0
  59. package/cli/managed-data-schema.mjs +14 -1
  60. package/cli/managed-data.mjs +8 -4
  61. package/cli/portability-empty.mjs +6 -0
  62. package/cli/portability-migrations.mjs +26 -4
  63. package/cli/portability-worker.mjs +2 -1
  64. package/cli/portability.mjs +1 -0
  65. package/cli/production-auth.mjs +2 -2
  66. package/cli/production-mail.mjs +19 -3
  67. package/cli/server-registry.mjs +2 -0
  68. package/edition-authoring/archive-source.mjs +65 -0
  69. package/edition-authoring/base-copies.mjs +108 -21
  70. package/edition-authoring/cli.mjs +1 -1
  71. package/edition-authoring/copy-namespaces.mjs +28 -0
  72. package/edition-authoring/edition-migrations.mjs +7 -3
  73. package/edition-authoring/files.mjs +2 -1
  74. package/edition-authoring/module-closure.mjs +58 -27
  75. package/edition-authoring/module-edges.mjs +13 -2
  76. package/edition-authoring/workflow-copies.mjs +1 -1
  77. package/edition-authoring/workflow-scripts.mjs +12 -3
  78. package/foundation/runtime/contract-docs.mjs +220 -32
  79. package/foundation/runtime/contract-prose-patterns.mjs +14 -0
  80. package/foundation/runtime/contract-prose.mjs +88 -0
  81. package/global/CHANGELOG.md +151 -0
  82. package/global/README.md +138 -29
  83. package/global/door/command.mjs +3 -1
  84. package/global/main.mjs +1 -1
  85. package/modules/agent-door/CLAUSES.md +215 -0
  86. package/modules/agent-door/conformance/audit-pages.mjs +11 -0
  87. package/modules/agent-door/conformance/audit-rows.mjs +20 -0
  88. package/modules/agent-door/conformance/audit.mjs +63 -0
  89. package/modules/agent-door/conformance/authority.d.mts +2 -0
  90. package/modules/agent-door/conformance/authority.mjs +17 -0
  91. package/modules/agent-door/conformance/crypto.mjs +36 -0
  92. package/modules/agent-door/conformance/discovery.mjs +61 -0
  93. package/modules/agent-door/conformance/fixtures.mjs +41 -0
  94. package/modules/agent-door/conformance/index.mjs +41 -0
  95. package/modules/agent-door/conformance/injection.mjs +24 -0
  96. package/modules/agent-door/conformance/invocation.mjs +33 -0
  97. package/modules/agent-door/conformance/journey.mjs +117 -0
  98. package/modules/agent-door/conformance/narrowing.d.mts +2 -0
  99. package/modules/agent-door/conformance/narrowing.mjs +29 -0
  100. package/modules/agent-door/conformance/negative.mjs +48 -0
  101. package/modules/agent-door/conformance/network-modules.mjs +86 -0
  102. package/modules/agent-door/conformance/network-runtime.mjs +46 -0
  103. package/modules/agent-door/conformance/policy-phases.mjs +83 -0
  104. package/modules/agent-door/conformance/protocol.mjs +153 -0
  105. package/modules/agent-door/conformance/replay.mjs +39 -0
  106. package/modules/agent-door/conformance/schema.mjs +71 -0
  107. package/modules/agent-door/conformance/security.mjs +34 -0
  108. package/modules/agent-door/conformance/sponsors.mjs +68 -0
  109. package/modules/agent-door/conformance/step-hooks.mjs +4 -0
  110. package/modules/agent-door/conformance/surface.mjs +92 -0
  111. package/modules/agent-door/conformance/target.mjs +19 -0
  112. package/modules/agent-door/conformance/tool-name.d.mts +1 -0
  113. package/modules/agent-door/conformance/tool-name.mjs +7 -0
  114. package/modules/agent-door/conformance/webhooks.mjs +31 -0
  115. package/modules/container/image-variables.mjs +8 -2
  116. package/modules/delivery-producer/mail.mjs +20 -0
  117. package/modules/demo-host/README.md +6 -0
  118. package/modules/demo-host/ownership.mjs +39 -0
  119. package/modules/demo-host/plan.mjs +2 -1
  120. package/modules/demo-host/remove.mjs +6 -1
  121. package/modules/import-kit/schema/importer-verification-receipt.schema.json +171 -0
  122. package/modules/import-kit/schema/importers.schema.json +107 -0
  123. package/modules/import-kit/src/door/ADOPTING.md +20 -0
  124. package/modules/import-kit/src/door/README.md +2 -1
  125. package/modules/import-kit/src/door/admission.ts +5 -3
  126. package/modules/import-kit/src/door/archive.ts +5 -2
  127. package/modules/import-kit/src/door/authority.ts +1 -0
  128. package/modules/import-kit/src/door/grants.ts +1 -1
  129. package/modules/import-kit/src/door/handler.ts +14 -8
  130. package/modules/import-kit/src/door/index.ts +1 -1
  131. package/modules/import-kit/src/door/jobs.ts +40 -0
  132. package/modules/import-kit/src/door/operator.ts +3 -3
  133. package/modules/import-kit/src/door/planning.ts +10 -6
  134. package/modules/import-kit/src/door/protocol.ts +2 -2
  135. package/modules/import-kit/src/door/raw.ts +25 -0
  136. package/modules/import-kit/src/door/refusals.ts +1 -0
  137. package/modules/import-kit/src/door/types.ts +26 -6
  138. package/modules/import-kit/src/receipt/encoding.ts +37 -0
  139. package/modules/import-kit/src/receipt/index.ts +69 -0
  140. package/modules/import-kit/src/receipt/policy.ts +24 -0
  141. package/modules/import-kit/src/receipt/types.ts +64 -0
  142. package/modules/import-kit/src/receipt/uri.ts +45 -0
  143. package/modules/import-kit/src/receipt/validation.ts +87 -0
  144. package/modules/import-kit/src/status/encoding.ts +13 -0
  145. package/modules/import-kit/src/status/evidence.ts +218 -0
  146. package/modules/import-kit/src/status/index.ts +56 -0
  147. package/modules/import-kit/src/status/schema.ts +208 -0
  148. package/modules/import-kit/src/status/types.ts +86 -0
  149. package/modules/operator-auth/accounts/delegated.mjs +48 -0
  150. package/modules/operator-auth/index.d.mts +7 -0
  151. package/modules/operator-auth/service.mjs +2 -0
  152. package/modules/portability/README.md +37 -13
  153. package/modules/portability/bridge.mjs +22 -2
  154. package/modules/portability/catalogue.mjs +12 -2
  155. package/modules/portability/copies.mjs +8 -1
  156. package/modules/portability/derived.mjs +33 -0
  157. package/modules/portability/http-errors.mjs +1 -1
  158. package/modules/portability/import.mjs +14 -7
  159. package/package.json +4 -2
  160. package/scripts/publish-check/copy_identities.py +3 -1
  161. package/scripts/publish-check/github_refs.py +32 -13
  162. package/cli/business/opt-ins.mjs +0 -37
@@ -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, ImportDoorRuntimeOptions, DoorRequest } from './types.ts';
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<ImportDoorRuntimeOptions> {
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, ownerPrincipalId: listed.ownerPrincipalId ?? options.ownerPrincipalId});
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 {source, liveCredentialsRemoved} = await readFileSourceRemovals({namespace: kitNamespace, name, bytes, format: intake ? 'ndjson' : options.format, parse: options.parse, credentials: 'remove'},
48
- {...options.limits, maxBytes: Math.min(options.limits?.maxBytes ?? access.maxBytes, access.maxBytes), maxRecords: Math.min(options.limits?.maxRecords ?? access.maxRecords, access.maxRecords)});
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, ImportDoorRuntimeOptions } from './types.ts';
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: Partial<ImportDoorRuntimeOptions>): boolean {
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 Partial<ImportDoorRuntimeOptions>>(options: T): T & ImportDoorRuntimeOptions {
41
- if (!options.mapping?.version || typeof options.parse!=='function' || !mountValid(options)) throw new DoorError('invalid_configuration',503);
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 & ImportDoorRuntimeOptions;
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);
@@ -1,3 +1,4 @@
1
+ import { readRawSource } from './raw.ts';
1
2
  import { randomUUID } from 'node:crypto';
2
3
  import { canonicalJson, sha256 } from '../provenance/identity.ts';
3
4
  import { readFileSource } from '../readers/file.ts';
@@ -13,9 +14,9 @@ import { bundleBytes, text, uploadRow, type UploadRow } from './uploads.ts';
13
14
  import { sourceRefusal } from './refusals.ts';
14
15
  import { intakeState } from './intake-policy.ts';
15
16
 
16
- export function preview(snapshot: DoorSnapshot) {
17
+ export function preview(snapshot: DoorSnapshot, created: boolean) {
17
18
  const {plan,differences} = snapshot;
18
- return {planId:snapshot.id,fingerprint:plan.fingerprint,bundleSha256:snapshot.bundleSha256,
19
+ return {planId:snapshot.id,fingerprint:plan.fingerprint,bundleSha256:snapshot.bundleSha256,created,
19
20
  summary:{sourceRecords:snapshot.sourceCount,created:differences.additions.length,updated:differences.replacements.length,unchanged:differences.unchanged.length,gone:differences.gone.length},
20
21
  counts:plan.counts,rejected:plan.entries.filter(e=>e.rejection).map(e=>({kind:e.source.kind,sourceId:e.source.sourceId,reason:e.rejection})),
21
22
  diagnostics:plan.diagnostics,differences};
@@ -67,7 +68,7 @@ async function planUpload(request: DoorRequest, input: Record<string, unknown>,
67
68
  if (snapshot.plan.mappingVersion !== request.options.mapping.version) throw new DoorError('snapshot_mapping_changed_use_new_namespace',409);
68
69
  if (request.access.catchup === 'bounded' && (!snapshot.standingApproval || snapshot.standingApproval.id !== request.access.approvalRecordId || snapshot.standingApproval.at !== request.access.approvedAt)) throw new DoorError('standing_approval_mismatch');
69
70
  await dropCredentialBytes(request,snapshot,upload);
70
- return preview(snapshot);
71
+ return preview(snapshot,false);
71
72
  }
72
73
  if (current.pending_id) throw new DoorError('namespace_has_pending_import',409);
73
74
  // An erasure withdrew the live import's snapshot, so nothing can be compared
@@ -138,7 +139,7 @@ async function planUpload(request: DoorRequest, input: Record<string, unknown>,
138
139
  if (retired) await retire(request,retired,snapshot.plan);
139
140
  await saveSnapshot(request,snapshot,upload,retainedFrom);
140
141
  await dropCredentialBytes(request,snapshot,upload);
141
- return preview(snapshot);
142
+ return preview(snapshot,true);
142
143
  }
143
144
  /** Retire an erasure-withdrawn live import as the namespace's baseline. The kit
144
145
  * never lets a new import write a record another live import holds, so while an
@@ -173,8 +174,11 @@ async function readUpload(request: DoorRequest, upload: UploadRow, planId: strin
173
174
  const retained = await retainedSource(request,upload);
174
175
  if (retained) return {kitNamespace,retainedFrom:retained.planId,source:{...retained.source,records:retained.source.records.map(record=>({...record,namespace:kitNamespace}))}};
175
176
  // Credential values are removed per record, never imported, and never refuse a record.
176
- const source = await readFileSource({namespace:kitNamespace,name:upload.name,bytes:await bundleBytes(request,upload),format:intake ? 'ndjson' : options.format,parse:options.parse,credentials:'remove'},
177
- {...options.limits,maxBytes:Math.min(options.limits?.maxBytes ?? request.access.maxBytes,request.access.maxBytes),maxRecords:Math.min(options.limits?.maxRecords ?? request.access.maxRecords,request.access.maxRecords)});
177
+ const bytes = await bundleBytes(request,upload);
178
+ const limits = {...options.limits,maxBytes:Math.min(options.limits?.maxBytes ?? request.access.maxBytes,request.access.maxBytes),maxRecords:Math.min(options.limits?.maxRecords ?? request.access.maxRecords,request.access.maxRecords)};
179
+ const source = options.format === 'raw'
180
+ ? await readRawSource(options,upload,bytes,kitNamespace,limits)
181
+ : await readFileSource({namespace:kitNamespace,name:upload.name,bytes,format:intake ? 'ndjson' : options.format,parse:options.parse,credentials:'remove'},limits);
178
182
  if (intake) source.intake = intake;
179
183
  return {kitNamespace,source,retainedFrom:undefined};
180
184
  }
@@ -1,6 +1,6 @@
1
- export type DoorAction = 'uploads' | 'plan' | 'apply' | 'status' | 'reconcile' | 'undo' | 'archive' | 'restore-check';
1
+ export type DoorAction = 'uploads' | 'plan' | 'apply' | 'status' | 'reconcile' | 'undo' | 'cancel' | 'archive' | 'restore-check';
2
2
  /** Grant-only actions: the owner-session mount answers them 404. */
3
- export const GRANT_ONLY_ACTIONS: readonly DoorAction[] = ['archive', 'restore-check'];
3
+ export const GRANT_ONLY_ACTIONS: readonly DoorAction[] = ['cancel', 'archive', 'restore-check'];
4
4
 
5
5
  export interface DoorGrant {
6
6
  v: 1;
@@ -0,0 +1,25 @@
1
+ import { Buffer } from 'node:buffer';
2
+ import type { ParsedRecord, ReaderLimits, SourceBundle } from '../types.ts';
3
+ import { limitsFor, RecordCollector, safeValue, textId } from '../readers/records.ts';
4
+ import { fail } from '../readers/errors.ts';
5
+ import type { ImportDoorRawRuntimeOptions } from './types.ts';
6
+ import type { UploadRow } from './uploads.ts';
7
+
8
+ /** Upload custody is already verified. Never decode it before the seed reads it. */
9
+ export async function readRawSource(options: ImportDoorRawRuntimeOptions, upload: Pick<UploadRow, 'name' | 'bundle_sha256' | 'total_bytes'>,
10
+ bytes: Uint8Array, namespace: string, limits: ReaderLimits): Promise<SourceBundle> {
11
+ const bounded = limitsFor(limits), location = {artifact: upload.name};
12
+ textId(upload.name); safeValue(upload.name);
13
+ if (bytes.byteLength > bounded.maxBytes) fail('SOURCE_BYTE_LIMIT',location);
14
+ // Snapshot custody before the callback, whose working buffer may be mutated.
15
+ const base64 = Buffer.from(bytes).toString('base64');
16
+ let records: ParsedRecord[];
17
+ try {
18
+ records = await options.readRaw({bytes:Uint8Array.from(bytes),name:upload.name,sha256:upload.bundle_sha256,size:upload.total_bytes},Object.freeze({...bounded}));
19
+ } catch { fail('SOURCE_RAW_READER_FAILED',location); }
20
+ const collector = new RecordCollector(namespace,bounded,[]);
21
+ collector.add(records,location,upload.bundle_sha256);
22
+ collector.bundle.artifacts.push({name:upload.name,sha256:upload.bundle_sha256,size:upload.total_bytes,
23
+ original:{status:'available',base64}});
24
+ return collector.bundle;
25
+ }
@@ -8,6 +8,7 @@ const reasons: Record<string, string> = {
8
8
  MALFORMED_JSON: 'The upload is not valid JSON in the declared format.',
9
9
  MALFORMED_UTF8: 'The upload is not valid UTF-8.',
10
10
  INVALID_OR_CREDENTIAL_SOURCE_DATA: 'A source value is not plain JSON data, holds a URL that cannot be parsed, or is encoded too deeply to inspect for credentials.',
11
+ SOURCE_RAW_READER_FAILED: "The seed's reader refused the raw upload. Check the archive format and contents.",
11
12
  SOURCE_PARSER_FAILED: "The seed's parser refused a source value.",
12
13
  SOURCE_OBJECT_DROPPED: "The seed's parser returned no record for a source value.",
13
14
  INVALID_PARSED_RECORDS: "The seed's parser returned an invalid record list.",