@runeditrun/rer 0.2.84 → 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 +156 -50
- package/cli/README.md +78 -2
- 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/bounded.mjs +1 -1
- package/cli/business/archive-task.mjs +32 -0
- package/cli/business/carry.mjs +151 -0
- package/cli/business/catchup-task.mjs +42 -0
- package/cli/business/choices.mjs +97 -0
- package/cli/business/command.mjs +29 -6
- package/cli/business/connect.mjs +20 -8
- 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 +80 -30
- 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 -6
- 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 +97 -32
- 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/container-transfer.mjs +2 -2
- package/cli/contract.mjs +7 -7
- package/cli/demo-deploy-error.mjs +14 -0
- package/cli/demo-native.mjs +6 -2
- package/cli/deploy-command.mjs +6 -4
- package/cli/deploy-config.mjs +1 -1
- package/cli/deploy-owner-input.mjs +3 -1
- package/cli/deploy-variables.mjs +58 -0
- package/cli/deploy.mjs +9 -7
- package/cli/door-clauses.mjs +157 -0
- package/cli/errors.mjs +1 -1
- package/cli/export.mjs +16 -4
- package/cli/hosted-output.mjs +17 -7
- package/cli/human-error.mjs +20 -0
- package/cli/inspect.mjs +4 -0
- package/cli/jsonc.mjs +8 -4
- package/cli/lifecycle.mjs +26 -6
- package/cli/main.mjs +2 -1
- package/cli/managed-data-schema.mjs +127 -0
- package/cli/managed-data-zip.mjs +116 -0
- package/cli/managed-data.mjs +110 -0
- package/cli/managed-server.mjs +25 -14
- package/cli/native-owner-entry.mjs +86 -0
- package/cli/output.mjs +3 -2
- package/cli/parse.mjs +2 -2
- package/cli/portability-empty.mjs +65 -0
- package/cli/portability-migrations.mjs +33 -9
- package/cli/portability-policy.mjs +5 -2
- package/cli/portability-worker.mjs +15 -6
- package/cli/portability.mjs +30 -8
- package/cli/production-auth.mjs +1 -1
- package/cli/production-mail.mjs +8 -2
- package/cli/ready-summary.mjs +9 -0
- package/cli/run-transfers.mjs +37 -0
- package/cli/runtime-front-door.mjs +4 -4
- package/cli/server-proxy.mjs +4 -3
- package/cli/server-registry.mjs +13 -8
- package/cli/site.mjs +6 -1
- package/cli/transfers.mjs +17 -4
- package/edition-authoring/archive-source.mjs +59 -0
- package/edition-authoring/base-copies.mjs +147 -25
- 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 +218 -34
- package/foundation/runtime/contract-prose-patterns.mjs +14 -0
- package/foundation/runtime/contract-prose.mjs +88 -0
- package/foundation/runtime/run-data.d.mts +1 -0
- package/foundation/runtime/run-data.mjs +2 -0
- package/global/CHANGELOG.md +126 -0
- package/global/README.md +156 -50
- package/global/cli/command.mjs +8 -2
- package/global/cli/install.mjs +4 -5
- package/global/cli/path-link.mjs +3 -2
- package/global/cli/repo-command.mjs +3 -7
- package/global/door/command.mjs +3 -1
- package/global/launch/dev.mjs +12 -2
- package/global/launch/facts.mjs +2 -2
- package/global/launch/render.mjs +16 -9
- package/global/launch/state.mjs +4 -4
- package/global/main.mjs +13 -8
- package/install.sh +17 -6
- 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/README.md +6 -1
- package/modules/container/adapters/d1-limits.mjs +286 -0
- package/modules/container/adapters/d1-sqlite.mjs +95 -0
- package/modules/container/adapters/d1-workerd-preload.mjs +19 -0
- package/modules/container/adapters/d1-workerd-setup.mjs +26 -0
- package/modules/container/adapters/d1-workerd.mjs +5 -0
- package/modules/container/adapters/sqlite-worker.mjs +5 -3
- package/modules/container/build.mjs +1 -0
- package/modules/container/image-variables.mjs +14 -3
- package/modules/container/transfer.mjs +14 -4
- package/modules/container/worker-engine.mjs +3 -3
- package/modules/demo-host/README.md +6 -0
- package/modules/demo-host/build.mjs +1 -0
- package/modules/demo-host/native/prepare.mjs +2 -1
- package/modules/demo-host/native/sql.mjs +7 -2
- 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/deploy-kit/README.md +22 -2
- package/modules/deploy-kit/d1-import-diagnostics.mjs +56 -0
- package/modules/deploy-kit/d1-import.mjs +17 -5
- package/modules/deploy-kit/diagnostics.mjs +29 -3
- package/modules/deploy-kit/owner-cli.mjs +20 -7
- package/modules/deploy-kit/provider-transport.mjs +19 -4
- package/modules/deploy-kit/provider.mjs +57 -22
- package/modules/deploy-kit/readiness-window.mjs +1 -1
- package/modules/deploy-kit/site.mjs +8 -3
- package/modules/deploy-kit/worker.mjs +4 -4
- 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/d1/README.md +23 -4
- package/modules/import-kit/src/d1/atomic-prefix.ts +2 -2
- package/modules/import-kit/src/d1/budget.ts +15 -7
- package/modules/import-kit/src/d1/column-layout.ts +5 -0
- package/modules/import-kit/src/d1/creation.ts +15 -8
- package/modules/import-kit/src/d1/database.ts +3 -3
- package/modules/import-kit/src/d1/erasure-pages.ts +2 -1
- package/modules/import-kit/src/d1/erasure.ts +2 -2
- package/modules/import-kit/src/d1/jobs.ts +10 -6
- package/modules/import-kit/src/d1/plans.ts +14 -8
- package/modules/import-kit/src/d1/retirement.ts +2 -2
- package/modules/import-kit/src/d1/sets.ts +1 -3
- package/modules/import-kit/src/d1/staged-creation.ts +3 -3
- 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/limits.ts +1 -1
- 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 +2 -1
- 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 +138 -9
- package/modules/portability/backfills.mjs +9 -8
- package/modules/portability/bridge.mjs +32 -5
- package/modules/portability/catalogue.mjs +12 -5
- package/modules/portability/copies.mjs +8 -1
- package/modules/portability/derived.mjs +33 -0
- package/modules/portability/files.mjs +4 -3
- package/modules/portability/http-errors.mjs +1 -1
- package/modules/portability/http.mjs +3 -3
- package/modules/portability/import.mjs +29 -13
- package/modules/portability/index.d.mts +4 -3
- package/modules/portability/index.mjs +1 -1
- package/modules/portability/ledgers.mjs +3 -2
- package/modules/portability/legacy-safety.mjs +11 -2
- package/modules/portability/migration-history.mjs +2 -2
- package/modules/portability/progress.mjs +1 -0
- package/modules/portability/restore-empty.mjs +12 -0
- package/modules/release/github-verify.mjs +11 -2
- package/onboarding/adapter.mjs +35 -6
- package/onboarding/app-fetch.mjs +6 -4
- package/onboarding/development-runtime.mjs +19 -0
- package/onboarding/local/operation.mjs +45 -27
- package/onboarding/loopback-fetch.mjs +16 -0
- package/onboarding/operator-installer.mjs +2 -4
- package/onboarding/process-diagnostics.mjs +6 -2
- package/onboarding/production-runtime.mjs +4 -2
- package/onboarding/readiness.mjs +1 -0
- package/package.json +4 -2
- package/scripts/publish-check/copy_identities.py +3 -1
- package/scripts/publish-check/github_refs.py +32 -13
- package/scripts/publish-check/public_hygiene.py +1 -1
- package/cli/business/opt-ins.mjs +0 -33
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { validateImporterEvidence } from './evidence.ts';
|
|
2
|
+
import { validateStatusDocumentSchema } from './schema.ts';
|
|
3
|
+
import type {
|
|
4
|
+
ImporterEvidencePort,
|
|
5
|
+
ImporterRecord,
|
|
6
|
+
ImporterValidationIssue,
|
|
7
|
+
ImporterValidationResult,
|
|
8
|
+
ImportersDocument,
|
|
9
|
+
} from './types.ts';
|
|
10
|
+
|
|
11
|
+
export type * from './types.ts';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Validate the published status document and resolve its evidence through the
|
|
15
|
+
* consumer's trust policy. A verified status also needs a trusted signed receipt.
|
|
16
|
+
*/
|
|
17
|
+
export async function validateImporters(
|
|
18
|
+
document: unknown,
|
|
19
|
+
evidence?: ImporterEvidencePort,
|
|
20
|
+
): Promise<ImporterValidationResult> {
|
|
21
|
+
const issues = validateStatusDocumentSchema(document);
|
|
22
|
+
const counters: ImporterValidationResult['evidence'] = { required: 0, resolved: 0, verifiedReceipts: 0 };
|
|
23
|
+
if (issues.length > 0) return result(issues, counters);
|
|
24
|
+
|
|
25
|
+
const records = (document as ImportersDocument).importers;
|
|
26
|
+
const seen = new Map<string, number>();
|
|
27
|
+
for (let index = 0; index < records.length; index += 1) {
|
|
28
|
+
const record = records[index]!;
|
|
29
|
+
const path = `$.importers[${index}]`;
|
|
30
|
+
const incumbent = normalizeLabel(record.incumbent);
|
|
31
|
+
const product = normalizeLabel(record.product);
|
|
32
|
+
if (record.incumbent.trim() !== record.incumbent || record.product.trim() !== record.product || !incumbent || !product) {
|
|
33
|
+
issues.push({ code: 'LABEL_NOT_NORMALIZED', path, message: 'Incumbent and product must be trimmed, non-empty labels.' });
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const key = JSON.stringify([incumbent, product]);
|
|
37
|
+
const previous = seen.get(key);
|
|
38
|
+
if (previous !== undefined) {
|
|
39
|
+
issues.push({ code: 'DUPLICATE_PAIR', path, message: `Importer pair duplicates $.importers[${previous}].` });
|
|
40
|
+
} else {
|
|
41
|
+
seen.set(key, index);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (issues.length > 0) return result(issues, counters);
|
|
45
|
+
|
|
46
|
+
const evidenceCounters = await validateImporterEvidence(records as ImporterRecord[], evidence, issues);
|
|
47
|
+
return result(issues, evidenceCounters);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function result(issues: ImporterValidationIssue[], evidence: ImporterValidationResult['evidence']): ImporterValidationResult {
|
|
51
|
+
return { valid: issues.length === 0, issues, evidence: { ...evidence } };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function normalizeLabel(value: string): string {
|
|
55
|
+
return value.normalize('NFKC').trim().toLowerCase();
|
|
56
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import importersSchemaJson from '../../schema/importers.schema.json' with { type: 'json' };
|
|
2
|
+
import receiptSchemaJson from '../../schema/importer-verification-receipt.schema.json' with { type: 'json' };
|
|
3
|
+
import { canonicalReceiptJson as canonicalJson } from '../receipt/encoding.ts';
|
|
4
|
+
import type { ImporterValidationIssue } from './types.ts';
|
|
5
|
+
|
|
6
|
+
interface JsonSchema {
|
|
7
|
+
$ref?: string;
|
|
8
|
+
type?: string;
|
|
9
|
+
const?: unknown;
|
|
10
|
+
enum?: unknown[];
|
|
11
|
+
minLength?: number;
|
|
12
|
+
maxLength?: number;
|
|
13
|
+
pattern?: string;
|
|
14
|
+
minimum?: number;
|
|
15
|
+
minItems?: number;
|
|
16
|
+
minProperties?: number;
|
|
17
|
+
required?: string[];
|
|
18
|
+
properties?: Record<string, JsonSchema>;
|
|
19
|
+
additionalProperties?: boolean | JsonSchema;
|
|
20
|
+
items?: JsonSchema;
|
|
21
|
+
oneOf?: JsonSchema[];
|
|
22
|
+
format?: string;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const importersSchema = importersSchemaJson as unknown as JsonSchema;
|
|
27
|
+
const receiptSchema = receiptSchemaJson as unknown as JsonSchema;
|
|
28
|
+
|
|
29
|
+
export function validateStatusDocumentSchema(document: unknown): ImporterValidationIssue[] {
|
|
30
|
+
if (!isJsonValue(document)) {
|
|
31
|
+
return [{ code: 'DOCUMENT_NOT_JSON', path: '$', message: 'Importer status must be JSON data.' }];
|
|
32
|
+
}
|
|
33
|
+
return schemaIssues(document, importersSchema, importersSchema, '$');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function validateReceiptDocumentSchema(document: unknown, path: string): ImporterValidationIssue[] {
|
|
37
|
+
if (!isJsonValue(document)) {
|
|
38
|
+
return [{ code: 'RECEIPT_NOT_JSON', path, message: 'Verification receipt must be JSON data.' }];
|
|
39
|
+
}
|
|
40
|
+
return schemaIssues(document, receiptSchema, receiptSchema, path);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function schemaIssues(value: unknown, schema: JsonSchema, root: JsonSchema, path: string): ImporterValidationIssue[] {
|
|
44
|
+
if (typeof schema.$ref === 'string') {
|
|
45
|
+
const target = resolveSchemaReference(root, schema.$ref);
|
|
46
|
+
if (!target) return [{ code: 'INVALID_SCHEMA_REFERENCE', path, message: `Schema reference ${schema.$ref} does not resolve.` }];
|
|
47
|
+
return schemaIssues(value, target, root, path);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (schema.oneOf) {
|
|
51
|
+
const matching = schema.oneOf.filter((branch) => schemaIssues(value, branch, root, path).length === 0).length;
|
|
52
|
+
return matching === 1
|
|
53
|
+
? []
|
|
54
|
+
: [{ code: 'SCHEMA_ONE_OF', path, message: matching === 0 ? 'Value does not match any allowed schema branch.' : 'Value matches more than one schema branch.' }];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const issues: ImporterValidationIssue[] = [];
|
|
58
|
+
if (schema.type && !matchesType(value, schema.type)) {
|
|
59
|
+
return [{ code: 'SCHEMA_TYPE', path, message: `Expected ${schema.type}.` }];
|
|
60
|
+
}
|
|
61
|
+
if (Object.hasOwn(schema, 'const') && !sameJsonValue(value, schema.const)) {
|
|
62
|
+
issues.push({ code: 'SCHEMA_CONST', path, message: `Expected the constant ${JSON.stringify(schema.const)}.` });
|
|
63
|
+
}
|
|
64
|
+
if (schema.enum && !schema.enum.some((allowed) => sameJsonValue(value, allowed))) {
|
|
65
|
+
issues.push({ code: 'SCHEMA_ENUM', path, message: 'Value is not one of the allowed values.' });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (typeof value === 'string') {
|
|
69
|
+
const length = codePointLength(value);
|
|
70
|
+
if (schema.minLength !== undefined && value.trim().length === 0) {
|
|
71
|
+
issues.push({ code: 'SCHEMA_BLANK_STRING', path, message: 'A non-empty string cannot contain only whitespace.' });
|
|
72
|
+
}
|
|
73
|
+
if (schema.minLength !== undefined && length < schema.minLength) {
|
|
74
|
+
issues.push({ code: 'SCHEMA_MIN_LENGTH', path, message: `String must contain at least ${schema.minLength} character(s).` });
|
|
75
|
+
}
|
|
76
|
+
if (schema.maxLength !== undefined && length > schema.maxLength) {
|
|
77
|
+
issues.push({ code: 'SCHEMA_MAX_LENGTH', path, message: `String must contain no more than ${schema.maxLength} character(s).` });
|
|
78
|
+
}
|
|
79
|
+
if (schema.pattern && !new RegExp(schema.pattern).test(value)) {
|
|
80
|
+
issues.push({ code: 'SCHEMA_PATTERN', path, message: 'String does not match the required pattern.' });
|
|
81
|
+
}
|
|
82
|
+
if (schema.format === 'date-time' && !isDateTime(value)) {
|
|
83
|
+
issues.push({ code: 'SCHEMA_FORMAT', path, message: 'Expected an ISO 8601 date-time with a timezone.' });
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (typeof value === 'number' && schema.minimum !== undefined && value < schema.minimum) {
|
|
87
|
+
issues.push({ code: 'SCHEMA_MINIMUM', path, message: `Number must be at least ${schema.minimum}.` });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (Array.isArray(value)) {
|
|
91
|
+
if (schema.minItems !== undefined && value.length < schema.minItems) {
|
|
92
|
+
issues.push({ code: 'SCHEMA_MIN_ITEMS', path, message: `Array must contain at least ${schema.minItems} item(s).` });
|
|
93
|
+
}
|
|
94
|
+
if (schema.items) {
|
|
95
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
96
|
+
issues.push(...schemaIssues(value[index], schema.items, root, `${path}[${index}]`));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (isPlainObject(value)) {
|
|
102
|
+
for (const required of schema.required ?? []) {
|
|
103
|
+
if (!Object.hasOwn(value, required)) {
|
|
104
|
+
issues.push({ code: 'SCHEMA_REQUIRED', path: `${path}.${required}`, message: 'Required property is missing.' });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (schema.minProperties !== undefined && Object.keys(value).length < schema.minProperties) {
|
|
108
|
+
issues.push({ code: 'SCHEMA_MIN_PROPERTIES', path, message: `Object must contain at least ${schema.minProperties} property/properties.` });
|
|
109
|
+
}
|
|
110
|
+
for (const [key, propertyValue] of Object.entries(value)) {
|
|
111
|
+
// Own members only: `constructor` or `__proto__` must not resolve to Object.prototype.
|
|
112
|
+
const propertySchema = schema.properties && Object.hasOwn(schema.properties, key) ? schema.properties[key] : undefined;
|
|
113
|
+
if (propertySchema) {
|
|
114
|
+
issues.push(...schemaIssues(propertyValue, propertySchema, root, `${path}.${key}`));
|
|
115
|
+
} else if (schema.additionalProperties === false) {
|
|
116
|
+
issues.push({ code: 'SCHEMA_ADDITIONAL_PROPERTY', path: `${path}.${key}`, message: 'Unknown property is not allowed.' });
|
|
117
|
+
} else if (schema.additionalProperties && typeof schema.additionalProperties === 'object') {
|
|
118
|
+
issues.push(...schemaIssues(propertyValue, schema.additionalProperties, root, `${path}.${key}`));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return issues;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Array.from(value).length without building the array: a surrogate pair counts once, a lone surrogate once. */
|
|
127
|
+
function codePointLength(value: string): number {
|
|
128
|
+
let length = value.length;
|
|
129
|
+
for (let index = 0; index + 1 < value.length; index += 1) {
|
|
130
|
+
const unit = value.charCodeAt(index);
|
|
131
|
+
if (unit >= 0xd800 && unit <= 0xdbff) {
|
|
132
|
+
const next = value.charCodeAt(index + 1);
|
|
133
|
+
if (next >= 0xdc00 && next <= 0xdfff) { length -= 1; index += 1; }
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return length;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function resolveSchemaReference(root: JsonSchema, reference: string): JsonSchema | undefined {
|
|
140
|
+
if (!reference.startsWith('#/')) return undefined;
|
|
141
|
+
let value: unknown = root;
|
|
142
|
+
for (const token of reference.slice(2).split('/').map((part) => part.replaceAll('~1', '/').replaceAll('~0', '~'))) {
|
|
143
|
+
if (!isPlainObject(value) || !Object.hasOwn(value, token)) return undefined;
|
|
144
|
+
value = value[token];
|
|
145
|
+
}
|
|
146
|
+
return isPlainObject(value) ? value as JsonSchema : undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function matchesType(value: unknown, type: string): boolean {
|
|
150
|
+
switch (type) {
|
|
151
|
+
case 'object': return isPlainObject(value);
|
|
152
|
+
case 'array': return Array.isArray(value);
|
|
153
|
+
case 'string': return typeof value === 'string';
|
|
154
|
+
case 'integer': return typeof value === 'number' && Number.isInteger(value);
|
|
155
|
+
case 'number': return typeof value === 'number' && Number.isFinite(value);
|
|
156
|
+
case 'boolean': return typeof value === 'boolean';
|
|
157
|
+
case 'null': return value === null;
|
|
158
|
+
default: return false;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function isJsonValue(value: unknown, active = new WeakSet<object>()): boolean {
|
|
163
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean') return true;
|
|
164
|
+
if (typeof value === 'number') return Number.isFinite(value);
|
|
165
|
+
if (Array.isArray(value)) {
|
|
166
|
+
if (active.has(value)) return false;
|
|
167
|
+
active.add(value);
|
|
168
|
+
const valid = value.every((item) => isJsonValue(item, active));
|
|
169
|
+
active.delete(value);
|
|
170
|
+
return valid;
|
|
171
|
+
}
|
|
172
|
+
if (isPlainObject(value)) {
|
|
173
|
+
if (active.has(value)) return false;
|
|
174
|
+
active.add(value);
|
|
175
|
+
const valid = Object.values(value).every((item) => isJsonValue(item, active));
|
|
176
|
+
active.delete(value);
|
|
177
|
+
return valid;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function isPlainObject(value: unknown): value is Record<string, any> {
|
|
183
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value)) return false;
|
|
184
|
+
const prototype = Object.getPrototypeOf(value);
|
|
185
|
+
return prototype === Object.prototype || prototype === null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function sameJsonValue(left: unknown, right: unknown): boolean {
|
|
189
|
+
return canonicalJson(left) === canonicalJson(right);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function isDateTime(value: string): boolean {
|
|
193
|
+
const match = value.match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?(Z|([+-])(\d{2}):(\d{2}))$/);
|
|
194
|
+
if (!match || !Number.isFinite(Date.parse(value))) return false;
|
|
195
|
+
const year = Number(match[1]);
|
|
196
|
+
const month = Number(match[2]);
|
|
197
|
+
const day = Number(match[3]);
|
|
198
|
+
const hour = Number(match[4]);
|
|
199
|
+
const minute = Number(match[5]);
|
|
200
|
+
const second = Number(match[6]);
|
|
201
|
+
const offsetHour = Number(match[9] ?? 0);
|
|
202
|
+
const offsetMinute = Number(match[10] ?? 0);
|
|
203
|
+
const leapYear = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
204
|
+
const daysInMonth = [31, leapYear ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
205
|
+
const offsetWithinRange = offsetHour < 14 || (offsetHour === 14 && offsetMinute === 0);
|
|
206
|
+
return month >= 1 && month <= 12 && day >= 1 && day <= daysInMonth[month - 1]!
|
|
207
|
+
&& hour <= 23 && minute <= 59 && second <= 59 && offsetMinute <= 59 && offsetWithinRange;
|
|
208
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { ImporterReceiptTrustPolicy } from '../receipt/types.ts';
|
|
2
|
+
|
|
3
|
+
export type ImporterStatus = 'verified' | 'documented format' | 'none';
|
|
4
|
+
|
|
5
|
+
export interface ImporterEvidenceArtifact {
|
|
6
|
+
link: string;
|
|
7
|
+
sha256: string;
|
|
8
|
+
size: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface DocumentedFormatEvidence extends ImporterEvidenceArtifact {
|
|
12
|
+
sourceRepository: string;
|
|
13
|
+
sourceRevision: string;
|
|
14
|
+
sourcePath: string;
|
|
15
|
+
sourceSha256: string;
|
|
16
|
+
validation: 'synthetic-only';
|
|
17
|
+
realExport: 'not-supplied';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface VerifiedEvidence extends ImporterEvidenceArtifact {
|
|
21
|
+
research: ImporterEvidenceArtifact;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface NoneEvidence extends ImporterEvidenceArtifact {
|
|
25
|
+
reason: string;
|
|
26
|
+
checkedAt: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface VerifiedImporter {
|
|
30
|
+
incumbent: string;
|
|
31
|
+
product: string;
|
|
32
|
+
status: 'verified';
|
|
33
|
+
evidence: VerifiedEvidence;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface DocumentedImporter {
|
|
37
|
+
incumbent: string;
|
|
38
|
+
product: string;
|
|
39
|
+
status: 'documented format';
|
|
40
|
+
evidence: DocumentedFormatEvidence;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface NoImporter {
|
|
44
|
+
incumbent: string;
|
|
45
|
+
product: string;
|
|
46
|
+
status: 'none';
|
|
47
|
+
evidence: NoneEvidence;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type ImporterRecord = VerifiedImporter | DocumentedImporter | NoImporter;
|
|
51
|
+
|
|
52
|
+
export interface ImportersDocument {
|
|
53
|
+
$schema: './schema/importers.schema.json';
|
|
54
|
+
schemaVersion: 1;
|
|
55
|
+
importers: ImporterRecord[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** A resolver must return the bytes it actually resolved and the final URL. */
|
|
59
|
+
export interface ResolvedEvidenceArtifact {
|
|
60
|
+
url: string;
|
|
61
|
+
bytes: Uint8Array;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Trust anchors belong to the consumer, never to the status document. */
|
|
65
|
+
export interface ImporterEvidencePort {
|
|
66
|
+
resolve: (link: string) => ResolvedEvidenceArtifact | undefined | Promise<ResolvedEvidenceArtifact | undefined>;
|
|
67
|
+
trustedHosts: readonly string[];
|
|
68
|
+
receiptPublicKeys?: Readonly<Record<string, string>>;
|
|
69
|
+
receiptTrustPolicy?: ImporterReceiptTrustPolicy;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface ImporterValidationIssue {
|
|
73
|
+
code: string;
|
|
74
|
+
path: string;
|
|
75
|
+
message: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface ImporterValidationResult {
|
|
79
|
+
valid: boolean;
|
|
80
|
+
issues: ImporterValidationIssue[];
|
|
81
|
+
evidence: {
|
|
82
|
+
required: number;
|
|
83
|
+
resolved: number;
|
|
84
|
+
verifiedReceipts: number;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Trusted server callers have already admitted a delegated principal. These
|
|
2
|
+
// commands reuse native administration, without minting or inventing a session.
|
|
3
|
+
import { administration } from './admin.mjs';
|
|
4
|
+
import { bindPolicyActor } from '../scheduled/fence.mjs';
|
|
5
|
+
import { emailAllowed } from './roles.mjs';
|
|
6
|
+
import { deny } from '../errors.mjs';
|
|
7
|
+
import { normalizeEmail } from '../policy.mjs';
|
|
8
|
+
|
|
9
|
+
export function delegatedAdministration(context, { personId, auditLabel, agentId }) {
|
|
10
|
+
const { store, config } = context;
|
|
11
|
+
if (typeof agentId !== 'string' || !agentId || typeof personId !== 'string' || !personId || typeof auditLabel !== 'string' || !auditLabel.trim()) deny('invalid_delegation', 400);
|
|
12
|
+
const request = new Request(new URL('/auth/delegated-administration', config.origin), {
|
|
13
|
+
method: 'POST', headers: { origin: config.origin, host: new URL(config.origin).host },
|
|
14
|
+
});
|
|
15
|
+
async function commands() {
|
|
16
|
+
const operator = await store.operator(personId);
|
|
17
|
+
if (!operator || operator.status !== 'active' || !emailAllowed(operator.email, config.allowList)) deny('unauthenticated', 401);
|
|
18
|
+
const actor = Object.freeze({ operator });
|
|
19
|
+
bindPolicyActor(actor, () => ({
|
|
20
|
+
sql: "EXISTS(SELECT 1 FROM oa_operators WHERE id=? AND version=? AND status='active' AND role=?)",
|
|
21
|
+
args: [operator.id, operator.version, operator.role],
|
|
22
|
+
}));
|
|
23
|
+
const audit = async event => {
|
|
24
|
+
const extra = context.audit ? await context.audit({ ...event, actorLabel: auditLabel, sponsorId: personId }) : [];
|
|
25
|
+
return [[`INSERT INTO oa_auth_audit(id,actor_id,action,value,created_at) VALUES(?,?,?,?,?)`,
|
|
26
|
+
[crypto.randomUUID(), `agent:${agentId}`, event.action, JSON.stringify({ operatorId: event.subjectId, detail: event.detail,
|
|
27
|
+
actor: auditLabel, for: personId }), event.now]], ...extra];
|
|
28
|
+
};
|
|
29
|
+
return administration({ ...context, authenticate: async () => actor, audit });
|
|
30
|
+
}
|
|
31
|
+
return Object.freeze({
|
|
32
|
+
async invite(input) {
|
|
33
|
+
if (input.role === 'owner') deny('delegated_owner_change', 403);
|
|
34
|
+
const admin = await commands();
|
|
35
|
+
const plan = await admin.prepareInvitation(request, input, { operator: await store.byEmail(normalizeEmail(input.email)) });
|
|
36
|
+
if (!await store.invite(plan.mutation, plan.actor, plan)) deny('invitation_conflict', 409);
|
|
37
|
+
await plan.afterCommit();
|
|
38
|
+
return { status: 'accepted' };
|
|
39
|
+
},
|
|
40
|
+
async setRole(operatorId, role) {
|
|
41
|
+
const target = await store.operator(operatorId);
|
|
42
|
+
// A delegation cannot widen its sponsor or transfer owner authority.
|
|
43
|
+
if (operatorId === personId || target?.role === 'owner' || role === 'owner') deny('delegated_owner_change', 403);
|
|
44
|
+
return (await commands()).setRole(request, operatorId, role);
|
|
45
|
+
},
|
|
46
|
+
async listOperators() { return (await commands()).listOperators(request); },
|
|
47
|
+
});
|
|
48
|
+
}
|
|
@@ -220,6 +220,13 @@ export interface OperatorAuth<R extends string = Role> {
|
|
|
220
220
|
cancelInvitation(request: Request, operatorId: string): Promise<Operator<R>>;
|
|
221
221
|
setOperatorStatus(request: Request, operatorId: string, status: 'active' | 'inactive'): Promise<Operator<R>>;
|
|
222
222
|
setRole(request: Request, operatorId: string, role: Role): Promise<Operator<R>>;
|
|
223
|
+
/** Trusted server only: caller admits the delegated principal; native policy
|
|
224
|
+
* and sponsor authority are checked again in each mutation transaction. */
|
|
225
|
+
delegatedAdministration(input: { personId: string; auditLabel: string; agentId: string }): {
|
|
226
|
+
invite(input: { email: string; displayName: string; role?: 'admin' | 'member'; returnTo?: string }): Promise<{ status: 'accepted' }>;
|
|
227
|
+
setRole(operatorId: string, role: 'admin' | 'member'): Promise<Operator<R>>;
|
|
228
|
+
listOperators(): Promise<Operator<R>[]>;
|
|
229
|
+
};
|
|
223
230
|
listSessions(request: Request, operatorId?: string): Promise<Array<{ id: string; kind: SessionKind; createdAt: number; expiresAt: number; active: boolean }>>;
|
|
224
231
|
revokeSession(request: Request, sessionId: string): Promise<void>;
|
|
225
232
|
issueReviewSession(request: Request, input?: { returnTo?: string }): Promise<CompletedSession<R>>;
|
|
@@ -25,6 +25,7 @@ import { displayNameChange } from './accounts/display-name.mjs';
|
|
|
25
25
|
import { isLocalCli } from './local-cli.mjs';
|
|
26
26
|
import { devAdmitted } from './dev-admission.mjs';
|
|
27
27
|
import { oneClickAccounts } from './accounts/one-click.mjs';
|
|
28
|
+
import { delegatedAdministration } from './accounts/delegated.mjs';
|
|
28
29
|
|
|
29
30
|
export { STEP_UP_ACTIONS, STEP_UP_SECONDS } from './identity/email-link/index.mjs';
|
|
30
31
|
export function createOperatorAuth(options) {
|
|
@@ -80,6 +81,7 @@ export function createOperatorAuth(options) {
|
|
|
80
81
|
const external = legacyAdmission({ admission, config });
|
|
81
82
|
return Object.freeze({
|
|
82
83
|
...admin,
|
|
84
|
+
delegatedAdministration: input => delegatedAdministration(adminContext, input),
|
|
83
85
|
businessTeam: businessTeam(adminContext),
|
|
84
86
|
...businessSettingsControls({ businessSettings: options.businessSettings, config, accounts, authenticate, requireFreshProof, store, clock }),
|
|
85
87
|
...(options.scheduledPolicies ? { scheduledPolicies: scheduledPolicies({ definitions: options.scheduledPolicies, store, config, clock, authenticate, requireFreshProof, rolePolicy }) } : {}),
|
|
@@ -102,7 +102,19 @@ The runner validates the module/export before applying data migrations. The
|
|
|
102
102
|
native transfer worker imports that same seed-owned entry point, preserving
|
|
103
103
|
functions and module-local closures. Modules should have no top-level effects:
|
|
104
104
|
preflight and transfer each load them in a separate process. Archive metadata
|
|
105
|
-
never selects executable policy.
|
|
105
|
+
never selects executable policy. A module may also export
|
|
106
|
+
`createPolicy({db, buckets})` to bind payload producers and consumers to the
|
|
107
|
+
current transfer's database and buckets. Its default policy is validated during
|
|
108
|
+
preflight; the factory's policy is validated when the bindings are available.
|
|
109
|
+
Managed intake supplies its disposable source bindings to the same factory, so
|
|
110
|
+
its payloads come from the ZIP's own staged data. Intake compares source schema
|
|
111
|
+
objects with a fresh replay of the destination migrations. Portable tables must
|
|
112
|
+
exist there; retired or replaced objects require a matching historical definition
|
|
113
|
+
and the migration that removes it. The receipt groups those objects by type and
|
|
114
|
+
migration, with counts and hashes of sorted names. Unknown objects refuse before
|
|
115
|
+
native restore; the destination retains its own schema. Native runners can use
|
|
116
|
+
`requireEmptyTables` before creating a restore job; finalization still enforces
|
|
117
|
+
the atomic empty-table guards. Invalid paths, missing/invalid default exports,
|
|
106
118
|
and declaring both `policy` and `policyModule` fail closed. Serializable object
|
|
107
119
|
`policy` declarations remain supported; inline functions (including nested
|
|
108
120
|
schema-upgrade and payload callbacks) are refused instead of being dropped by
|
|
@@ -225,11 +237,12 @@ provider operation.
|
|
|
225
237
|
| Compatible `d1_migrations`, every recorded name exactly equal to its checkout filename | `{nativeApply:true}`; Wrangler may apply its pending files. Plain Wrangler names remain supported; tracked history must also match hashes and applied states. |
|
|
226
238
|
| Native alias-only or hash-only relocation, or an unmapped native data-only row | `migration_ledger:incompatible`; restore the matching checkout or reconcile through the owning runner before native apply. |
|
|
227
239
|
| Sole, fully applied matching `rer_migrations` | `{nativeApply:false}`; preserve Platform's ledger and skip Wrangler. |
|
|
228
|
-
|
|
|
229
|
-
|
|
|
240
|
+
| Fully applied matching `_rer_deploy_migrations` plus plain Wrangler `d1_migrations` bookkeeping | `{nativeApply:false}`; preserve the deploy history and skip Wrangler. Bookkeeping names must belong to that history. A tracked D1 ledger must match the deploy history's names, hashes and order. |
|
|
241
|
+
| Any pending checkout file with Platform history or the legacy pair | `migration_ledger:unapplied`, naming the file (`error.migration`); apply it through the owning runner first. |
|
|
242
|
+
| Other multiple ledgers, or disagreeing tracked native histories | `migration_ledger:multiple`; reconcile history through its owning runner. |
|
|
230
243
|
| Legacy `_rer_deploy_migrations` alone | `migration_ledger:runner`; use its owning runner, which can adopt the history. |
|
|
231
244
|
| Invalid ledger shape, row or binding | `migration_ledger:incompatible` or `migration_ledger:binding`. |
|
|
232
|
-
| Partial Platform batch or non-applied tracked row | `migration_ledger:uncertain`; resolve the incomplete operation first. |
|
|
245
|
+
| Partial Platform batch or non-applied tracked or legacy row | `migration_ledger:uncertain`; resolve the incomplete operation first. |
|
|
233
246
|
| Unknown hash/name, ambiguous hash/alias or conflicting name/hash | `migration_ledger:unknown`, `:ambiguous` or `:conflict`; use the matching checkout and declaration. |
|
|
234
247
|
|
|
235
248
|
Refusals throw `PortabilityError` with status 409 and a constant `code`;
|
|
@@ -263,8 +276,10 @@ owner claim. Such a destination keeps that claim and recovers access through
|
|
|
263
276
|
ordinary native sign-in; setup does not grant another owner. Other tables are
|
|
264
277
|
discovered automatically. Exclusion rules follow SQLite's ASCII identifier case matching.
|
|
265
278
|
Unlisted virtual tables, hidden virtual-table columns and foreign keys into
|
|
266
|
-
excluded tables fail by name.
|
|
267
|
-
|
|
279
|
+
excluded tables fail by name. Restore rebuilds policy-declared external-content
|
|
280
|
+
FTS5 indexes from their content tables in the same transaction as the restored
|
|
281
|
+
rows. The product must explicitly regenerate other derived data. A schema
|
|
282
|
+
upgrade may change columns but cannot silently omit tables.
|
|
268
283
|
|
|
269
284
|
Provider link keys and transient provider sessions never travel. Export marks
|
|
270
285
|
retained dependency links as needing re-link and turns provider sign-in and
|
|
@@ -367,9 +382,13 @@ source identity, job ids and boundaries do not affect equivalence.
|
|
|
367
382
|
|
|
368
383
|
Schema identity covers table definitions (including constraints and generated
|
|
369
384
|
expressions), explicit indexes (including uniqueness and partial predicates),
|
|
370
|
-
views and triggers.
|
|
371
|
-
|
|
372
|
-
|
|
385
|
+
views and triggers. Row exclusions do not omit indexes and triggers attached
|
|
386
|
+
to excluded tables, including platform bookkeeping tables. Names with the literal
|
|
387
|
+
internal prefixes `sqlite_` and `_cf_` remain exempt. The complete additional
|
|
388
|
+
definitions travel in `schemaObjects`. Explicitly acknowledged v1 recovery uses
|
|
389
|
+
the historical exclusion projection only when placing its old backup within
|
|
390
|
+
native migration history; the live destination and ordinary v2 inventories
|
|
391
|
+
still use the complete catalogue. A single SQLite lexer reads the original
|
|
373
392
|
SQL before removing trivia. Identity records each token's class and canonical
|
|
374
393
|
value, plus a deterministic spelling: a single space separates neighbours
|
|
375
394
|
exactly when concatenating them would change their tokenization. The complete
|
|
@@ -417,6 +436,7 @@ Re-export from the original installation to carry the complete definitions.
|
|
|
417
436
|
A new archive explicitly records even an empty object inventory, so later
|
|
418
437
|
additive migrations can still be placed normally. The separate acknowledged
|
|
419
438
|
v1 recovery path remains an explicitly unverified recovery, as documented below.
|
|
439
|
+
Version 2 backups without that inventory use recorded migration replay when it proves the complete destination schema, or the acknowledged recovery below.
|
|
420
440
|
|
|
421
441
|
New exports use archive version 2. The closing `archiveHash` is SHA-256 of
|
|
422
442
|
canonical JSON `{manifest,parts}`, where `manifest` is the complete manifest
|
|
@@ -451,6 +471,60 @@ authenticate it. If the original installation is unavailable, use the explicit
|
|
|
451
471
|
[backup-only v1 recovery](#backup-only-v1-recovery) below. Normal import still
|
|
452
472
|
requires version 2 integrity.
|
|
453
473
|
|
|
474
|
+
## Older version 2 backups and acknowledged recovery
|
|
475
|
+
|
|
476
|
+
A fresh export from a current rer is preferred whenever the original installation
|
|
477
|
+
is available. Current archives carry the complete schema inventory and restore
|
|
478
|
+
without any acknowledgment. Version 2 backups written by rer 0.2.79 or earlier
|
|
479
|
+
can lack `schemaObjects`. Ordinary import verifies such a backup without an
|
|
480
|
+
acknowledgment when its nonempty recorded migration history, resolved against the
|
|
481
|
+
destination's own applied files in order, replays to the complete live destination
|
|
482
|
+
schema identity, including indexes, views and triggers. The same replay's tables
|
|
483
|
+
must match the archive's table definitions. The archive's ledger, when present,
|
|
484
|
+
must agree with its recorded names, and available hashes must match. Missing
|
|
485
|
+
history, failed replay, table drift or a different complete destination identity
|
|
486
|
+
still refuses `schema_mismatch:legacy_schema` before staging. Source SQL is never
|
|
487
|
+
installed. This verified path records no `schemaUnverified` receipt.
|
|
488
|
+
|
|
489
|
+
When that proof is unavailable, the owner can explicitly accept that its schema
|
|
490
|
+
objects are unverified:
|
|
491
|
+
|
|
492
|
+
```sh
|
|
493
|
+
rer import --input exports/retained.rer --yes --acknowledge-unverified-schema-objects
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
This accepts only the missing inventory and preserves the existing recovery path,
|
|
497
|
+
even when ordinary import could verify the backup. The acknowledgment never accepts
|
|
498
|
+
version 1 metadata; that separate recovery still needs both v1 flags below.
|
|
499
|
+
The destination must be empty under the existing product emptiness rule:
|
|
500
|
+
non-migration rows in product tables refuse `target_not_empty:<table>` before
|
|
501
|
+
staging, including before a local runner applies pending product migrations.
|
|
502
|
+
Finalization repeats the normal emptiness check and atomic guards.
|
|
503
|
+
The normal restore maintenance lock remains held throughout staging and restore.
|
|
504
|
+
|
|
505
|
+
The destination runner must replay its own applied migration files. Every
|
|
506
|
+
archived table, column, dependency and table definition must match a compatible
|
|
507
|
+
point in that history, with only the supported later additive changes. Recorded
|
|
508
|
+
migration names must form an ordered compatible subset of the destination's
|
|
509
|
+
history; unknown names, incompatible columns or definitions, uncertain migrations
|
|
510
|
+
and unsafe later data changes refuse before staging, naming the mismatch.
|
|
511
|
+
Older name-only migration ledger rows are accepted for this acknowledged path;
|
|
512
|
+
ledger hashes, when present, must still match. Platform ledger rows are verified
|
|
513
|
+
against the archive parts and skipped, never installed over destination history.
|
|
514
|
+
|
|
515
|
+
Indexes, views and triggers come only from the destination's migrations, never
|
|
516
|
+
from archive SQL. Recovery writes rows and assets through the normal integrity,
|
|
517
|
+
authentication, explicit confirmation, safety and final erasure-fencing checks.
|
|
518
|
+
Seed-owned authority checks, including private-key matching, remain the seed's
|
|
519
|
+
responsibility and are unchanged.
|
|
520
|
+
|
|
521
|
+
The completed restore job and returned receipt carry `schemaUnverified`, with
|
|
522
|
+
its reason (acknowledged recovery of a version 2 archive without schemaObjects),
|
|
523
|
+
source identity, export time, acknowledgment time and archive hash. The local
|
|
524
|
+
command prints this secret-free receipt. A current archive records no such
|
|
525
|
+
receipt, even when the flag was supplied. Preserve the original backup and the
|
|
526
|
+
receipt; export a new current archive after recovery.
|
|
527
|
+
|
|
454
528
|
## Archives across later additive migrations
|
|
455
529
|
|
|
456
530
|
An archive restores into an installation whose schema differs only by migrations
|
|
@@ -933,6 +1007,7 @@ modules/portability/sqlite-tokens.mjs
|
|
|
933
1007
|
modules/portability/bookkeeping.mjs
|
|
934
1008
|
modules/portability/storage.mjs
|
|
935
1009
|
modules/portability/copies.mjs
|
|
1010
|
+
modules/portability/derived.mjs
|
|
936
1011
|
modules/portability/dev-data.mjs
|
|
937
1012
|
modules/portability/provider-data.mjs
|
|
938
1013
|
modules/portability/policy-data.mjs
|
|
@@ -1009,3 +1084,57 @@ Base's default-seed and composed foundation CLI adapters adopt direct local D1
|
|
|
1009
1084
|
bindings with explicit identity/configuration exclusions. Their CLI journeys
|
|
1010
1085
|
exercise archive/reset/restore/archive equivalence. Remote transfer and deployed
|
|
1011
1086
|
product acceptance remain outside this local adoption.
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
### Optional Managed data intake
|
|
1090
|
+
|
|
1091
|
+
Platform's data download is a stored ZIP with kind `runeditrun-app-data` and
|
|
1092
|
+
schema 1. It is distinct from an installation archive. The reference adapter
|
|
1093
|
+
opts in with `localPortability({database, policy, buckets, managedData: true})`.
|
|
1094
|
+
Existing adapters retain their native archive and legacy JSON readers.
|
|
1095
|
+
|
|
1096
|
+
Adapters with their own native archive format can keep their existing `import`
|
|
1097
|
+
method and add `managedDataImport` from an opted-in `localPortability`
|
|
1098
|
+
declaration. The CLI selects that method only for ZIP input; all other inputs
|
|
1099
|
+
continue through the adapter's original reader. This requires the seed's real
|
|
1100
|
+
native Workers database name, binding and portability policy.
|
|
1101
|
+
|
|
1102
|
+
Adapters that already consume Base's native format can import `withManagedDataImport`
|
|
1103
|
+
from the package's portability entry point and call
|
|
1104
|
+
`withManagedDataImport(context, declaration, restoreNative)` before their native
|
|
1105
|
+
reader. The declaration supplies the real `binding`, `buckets`, `policy` or
|
|
1106
|
+
`policyModule`, and optional `platformMigrations`. The callback receives the
|
|
1107
|
+
context with a private native archive path for a Managed ZIP, or the original
|
|
1108
|
+
context for other inputs. Authentication, explicit confirmation, custody and
|
|
1109
|
+
empty-target checks remain the caller's responsibility. The callback must await
|
|
1110
|
+
its native restore before returning; staging is deleted on success or failure.
|
|
1111
|
+
This helper emits Base's native portability format; an adapter with a different
|
|
1112
|
+
format must provide a callback that adopts that native restore contract.
|
|
1113
|
+
|
|
1114
|
+
The intake checks the complete ZIP and manifest, required members, checksums,
|
|
1115
|
+
bindings and Platform ledger before native restore. Source SQL runs in a private
|
|
1116
|
+
workerd D1 sandbox. The existing exporter preserves its erasure journal, excludes
|
|
1117
|
+
identity and secret data, maps migration identities using the same hash matching
|
|
1118
|
+
as native Platform-ledger archives, and emits a verified native archive. Native
|
|
1119
|
+
restore still checks emptiness, migration compatibility, erasure and row safety.
|
|
1120
|
+
No source SQL runs against the destination. The intake accounts every non-internal
|
|
1121
|
+
source table, index, trigger and view against native schema or a named retirement
|
|
1122
|
+
in destination migrations, including objects attached to excluded tables. Internal
|
|
1123
|
+
prefixes are compared literally. A scratch native import preflight checks the
|
|
1124
|
+
projected archive before native restore can open the destination.
|
|
1125
|
+
|
|
1126
|
+
Policy-declared derived virtual tables omitted from a Managed dump are created
|
|
1127
|
+
in the sandbox from the destination's migrated definitions. Their triggers must
|
|
1128
|
+
still be present and compatible; omitting those triggers remains a schema
|
|
1129
|
+
refusal. The dump statement allowlist still refuses all `CREATE VIRTUAL TABLE`
|
|
1130
|
+
statements, including declared names. A native copy-normalization SQLite failure
|
|
1131
|
+
is reported as `copy_normalization_failed`, without SQL diagnostics or row values.
|
|
1132
|
+
|
|
1133
|
+
The current intake supports one database and declared buckets, local Workers
|
|
1134
|
+
transport, stored ZIP members, at most 10,000 entries and statements, a 128 MiB
|
|
1135
|
+
archive, 64 MiB members, 4 MiB metadata members and 16 MiB of SQL, with each SQL
|
|
1136
|
+
statement at most 100,000 bytes after binding string literals, with at most 100
|
|
1137
|
+
parameters of at most 2 MiB each. It refuses compressed or encrypted entries,
|
|
1138
|
+
unsafe paths, duplicate or unexpected members, missing ledgers, other versions,
|
|
1139
|
+
container transport, later-journal and legacy-recovery options. Refusals use
|
|
1140
|
+
constant `managed_data_*` reasons and do not print source values.
|