@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.
- package/README.md +138 -29
- package/cli/README.md +61 -1
- package/cli/agent-bindings.mjs +25 -0
- package/cli/agent-door.mjs +145 -0
- package/cli/agent-fixtures.mjs +16 -0
- package/cli/agent-journey-fixtures.mjs +17 -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-rpc.mjs +23 -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-verifier.mjs +31 -0
- package/cli/agent-webhooks.mjs +19 -0
- package/cli/authoring.mjs +2 -1
- package/cli/business/archive-task.mjs +32 -0
- package/cli/business/carry.mjs +3 -1
- package/cli/business/catchup-task.mjs +42 -0
- package/cli/business/choices.mjs +97 -0
- package/cli/business/command.mjs +23 -5
- package/cli/business/connect.mjs +19 -7
- package/cli/business/detector.mjs +4 -1
- package/cli/business/device.mjs +13 -0
- package/cli/business/export-inputs.mjs +69 -0
- package/cli/business/export-task.mjs +17 -0
- package/cli/business/invocation.mjs +8 -1
- package/cli/business/keychain.mjs +8 -1
- package/cli/business/lease.mjs +11 -1
- package/cli/business/local-commands.mjs +79 -31
- package/cli/business/outbound.mjs +9 -4
- package/cli/business/parsers-config.mjs +8 -7
- package/cli/business/parsers-syntax.mjs +7 -3
- package/cli/business/permissions.mjs +2 -0
- package/cli/business/questions.mjs +89 -9
- package/cli/business/setup-command.mjs +49 -0
- package/cli/business/setup-company.json +15 -0
- package/cli/business/setup-demo.mjs +95 -0
- package/cli/business/state.mjs +44 -10
- package/cli/business/supervisor.mjs +94 -35
- package/cli/business/vendor-door.mjs +230 -0
- package/cli/business/vendors/README.md +29 -3
- package/cli/business/vendors/common.mjs +8 -6
- package/cli/business/vendors/index.mjs +22 -11
- package/cli/business/vendors/sorry.mjs +106 -0
- package/cli/contract.mjs +2 -2
- package/cli/demo-deploy-error.mjs +14 -0
- package/cli/demo-native.mjs +4 -1
- package/cli/deploy-config.mjs +1 -1
- package/cli/deploy-owner-input.mjs +3 -1
- package/cli/deploy-variables.mjs +89 -0
- package/cli/door-clauses.mjs +157 -0
- package/cli/export.mjs +17 -4
- package/cli/hosted-output.mjs +31 -8
- package/cli/inspect.mjs +4 -0
- package/cli/jsonc.mjs +8 -4
- package/cli/lifecycle.mjs +3 -1
- package/cli/main.mjs +1 -0
- package/cli/managed-data-schema.mjs +14 -1
- package/cli/managed-data.mjs +8 -4
- package/cli/portability-empty.mjs +6 -0
- package/cli/portability-migrations.mjs +26 -4
- package/cli/portability-worker.mjs +2 -1
- package/cli/portability.mjs +1 -0
- package/cli/production-auth.mjs +2 -2
- package/cli/production-mail.mjs +19 -3
- package/cli/server-registry.mjs +2 -0
- package/edition-authoring/archive-source.mjs +65 -0
- package/edition-authoring/base-copies.mjs +108 -21
- package/edition-authoring/cli.mjs +1 -1
- package/edition-authoring/copy-namespaces.mjs +28 -0
- package/edition-authoring/edition-migrations.mjs +7 -3
- package/edition-authoring/files.mjs +2 -1
- package/edition-authoring/module-closure.mjs +58 -27
- package/edition-authoring/module-edges.mjs +13 -2
- package/edition-authoring/workflow-copies.mjs +1 -1
- package/edition-authoring/workflow-scripts.mjs +12 -3
- package/foundation/runtime/contract-docs.mjs +220 -32
- package/foundation/runtime/contract-prose-patterns.mjs +14 -0
- package/foundation/runtime/contract-prose.mjs +88 -0
- package/global/CHANGELOG.md +151 -0
- package/global/README.md +138 -29
- package/global/door/command.mjs +3 -1
- package/global/main.mjs +1 -1
- package/modules/agent-door/CLAUSES.md +215 -0
- package/modules/agent-door/conformance/audit-pages.mjs +11 -0
- package/modules/agent-door/conformance/audit-rows.mjs +20 -0
- package/modules/agent-door/conformance/audit.mjs +63 -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/fixtures.mjs +41 -0
- package/modules/agent-door/conformance/index.mjs +41 -0
- package/modules/agent-door/conformance/injection.mjs +24 -0
- package/modules/agent-door/conformance/invocation.mjs +33 -0
- package/modules/agent-door/conformance/journey.mjs +117 -0
- package/modules/agent-door/conformance/narrowing.d.mts +2 -0
- package/modules/agent-door/conformance/narrowing.mjs +29 -0
- package/modules/agent-door/conformance/negative.mjs +48 -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 +83 -0
- package/modules/agent-door/conformance/protocol.mjs +153 -0
- package/modules/agent-door/conformance/replay.mjs +39 -0
- package/modules/agent-door/conformance/schema.mjs +71 -0
- package/modules/agent-door/conformance/security.mjs +34 -0
- package/modules/agent-door/conformance/sponsors.mjs +68 -0
- package/modules/agent-door/conformance/step-hooks.mjs +4 -0
- package/modules/agent-door/conformance/surface.mjs +92 -0
- package/modules/agent-door/conformance/target.mjs +19 -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 +31 -0
- package/modules/container/image-variables.mjs +8 -2
- package/modules/delivery-producer/mail.mjs +20 -0
- package/modules/demo-host/README.md +6 -0
- package/modules/demo-host/ownership.mjs +39 -0
- package/modules/demo-host/plan.mjs +2 -1
- package/modules/demo-host/remove.mjs +6 -1
- package/modules/import-kit/schema/importer-verification-receipt.schema.json +171 -0
- package/modules/import-kit/schema/importers.schema.json +107 -0
- package/modules/import-kit/src/door/ADOPTING.md +20 -0
- package/modules/import-kit/src/door/README.md +2 -1
- package/modules/import-kit/src/door/admission.ts +5 -3
- package/modules/import-kit/src/door/archive.ts +5 -2
- package/modules/import-kit/src/door/authority.ts +1 -0
- package/modules/import-kit/src/door/grants.ts +1 -1
- package/modules/import-kit/src/door/handler.ts +14 -8
- package/modules/import-kit/src/door/index.ts +1 -1
- package/modules/import-kit/src/door/jobs.ts +40 -0
- package/modules/import-kit/src/door/operator.ts +3 -3
- package/modules/import-kit/src/door/planning.ts +10 -6
- package/modules/import-kit/src/door/protocol.ts +2 -2
- package/modules/import-kit/src/door/raw.ts +25 -0
- package/modules/import-kit/src/door/refusals.ts +1 -0
- package/modules/import-kit/src/door/types.ts +26 -6
- package/modules/import-kit/src/receipt/encoding.ts +37 -0
- package/modules/import-kit/src/receipt/index.ts +69 -0
- package/modules/import-kit/src/receipt/policy.ts +24 -0
- package/modules/import-kit/src/receipt/types.ts +64 -0
- package/modules/import-kit/src/receipt/uri.ts +45 -0
- package/modules/import-kit/src/receipt/validation.ts +87 -0
- package/modules/import-kit/src/status/encoding.ts +13 -0
- package/modules/import-kit/src/status/evidence.ts +218 -0
- package/modules/import-kit/src/status/index.ts +56 -0
- package/modules/import-kit/src/status/schema.ts +208 -0
- package/modules/import-kit/src/status/types.ts +86 -0
- package/modules/operator-auth/accounts/delegated.mjs +48 -0
- package/modules/operator-auth/index.d.mts +7 -0
- package/modules/operator-auth/service.mjs +2 -0
- package/modules/portability/README.md +37 -13
- package/modules/portability/bridge.mjs +22 -2
- package/modules/portability/catalogue.mjs +12 -2
- package/modules/portability/copies.mjs +8 -1
- package/modules/portability/derived.mjs +33 -0
- package/modules/portability/http-errors.mjs +1 -1
- package/modules/portability/import.mjs +14 -7
- package/package.json +4 -2
- package/scripts/publish-check/copy_identities.py +3 -1
- package/scripts/publish-check/github_refs.py +32 -13
- package/cli/business/opt-ins.mjs +0 -37
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { constants } from 'node:fs';
|
|
3
|
+
import { open, unlink } from 'node:fs/promises';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { taskPath } from './api.mjs';
|
|
6
|
+
import { assertChunk } from './outbound.mjs';
|
|
7
|
+
import { createCredentialStore } from './keychain.mjs';
|
|
8
|
+
import { exportVendor, VENDORS, KEYED_VENDORS, VENDOR_CAPABILITIES, VendorExportError } from './vendors/index.mjs';
|
|
9
|
+
import { exportInputs, inputNeeds } from './export-inputs.mjs';
|
|
10
|
+
import { businessCommand } from './invocation.mjs';
|
|
11
|
+
|
|
12
|
+
// What every vendor task that writes into an app's import door shares
|
|
13
|
+
// (modules/import-kit/src/door): the claimed grant's door, one RER-signed grant
|
|
14
|
+
// per door request, the owner's read-only key from OS credential storage, the
|
|
15
|
+
// shipped adapter into a private 0600 bundle, and 64 KiB chunks.
|
|
16
|
+
|
|
17
|
+
// The door's upload unit ("Requests"): every chunk is exactly 64 KiB except the last.
|
|
18
|
+
const CHUNK_BYTES = 65_536;
|
|
19
|
+
const DOOR_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
20
|
+
// The catalogue names the platform builds vendor task titles from.
|
|
21
|
+
export const vendorNames = Object.freeze({ sentry: 'Sentry', uptimerobot: 'UptimeRobot', pagerduty: 'PagerDuty', calendly: 'Calendly', sorry: 'Sorry' });
|
|
22
|
+
/** Whether a vendor's export needs the owner's read-only key (Sorry's public page does not). */
|
|
23
|
+
export const keyed = vendor => KEYED_VENDORS.includes(vendor);
|
|
24
|
+
export const vendorHandle = vendor => `vendor:${vendor}:read`;
|
|
25
|
+
export const hash = bytes => createHash('sha256').update(bytes).digest('hex');
|
|
26
|
+
const loopback = hostname => ['localhost', '127.0.0.1', '[::1]'].includes(hostname);
|
|
27
|
+
// The door identifiers Business accepts in a task's outputs (platform business/imports.ts).
|
|
28
|
+
export const DOOR_ID = /^[0-9A-Za-z][0-9A-Za-z_-]{0,127}$/;
|
|
29
|
+
export const count = value => Number.isSafeInteger(value) && value >= 0 ? value : null;
|
|
30
|
+
export const plural = (value, word) => `${value} ${word}${value === 1 ? '' : 's'}`;
|
|
31
|
+
|
|
32
|
+
/** A vendor task that cannot go on until someone else acts. The supervisor tells
|
|
33
|
+
* Business with `question`, hands the lease back as paused and says `message`. */
|
|
34
|
+
export class ExportWaiting extends Error {
|
|
35
|
+
constructor(message, question, { keyMissing = null } = {}) { super(message); this.question = question; this.keyMissing = keyMissing; }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// The platform's task titles (business/task-titles.ts) for the kinds that name a vendor.
|
|
39
|
+
const titles = {
|
|
40
|
+
'export.vendor': name => `Export ${name} history`,
|
|
41
|
+
'catchup.vendor': name => `Bring over recent ${name} changes`,
|
|
42
|
+
'switchoff.archive': name => `Archive ${name} before switching it off`,
|
|
43
|
+
'freeze.vendor': name => `Freeze ${name} before the switch`,
|
|
44
|
+
'switchoff.cancel': name => `Cancel ${name}`,
|
|
45
|
+
};
|
|
46
|
+
/** The shipped vendor a task names, read from its catalogue title
|
|
47
|
+
* (`Export UptimeRobot history`), or null. Run trusts only the grant's namespace. */
|
|
48
|
+
export function titledVendor(kind, title) {
|
|
49
|
+
if (!Object.hasOwn(titles, kind)) return null;
|
|
50
|
+
return VENDORS.find(vendor => title === titles[kind](vendorNames[vendor])) ?? null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const keyCommand = vendor => businessCommand(`vendor-key add ${vendor ?? '<vendor>'}`);
|
|
54
|
+
/** The owner-typed step that keeps a vendor's read-only key on this computer. */
|
|
55
|
+
export function keyStep(vendor) {
|
|
56
|
+
return `ask the owner to type this in their own terminal, outside any agent sandbox (it asks for the key with hidden input; never put a key in chat, a command or a file):\n ${keyCommand(vendor)}`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const unavailableWords = {
|
|
60
|
+
'vendor-not-in-catalogue': 'this tool has no shipped export',
|
|
61
|
+
'no-linked-installation': 'Business has not set up the app this tool moves into',
|
|
62
|
+
'ambiguous-target-installation': 'more than one app could receive this export',
|
|
63
|
+
'installation-import-origin-unavailable': "the app's address is not known yet",
|
|
64
|
+
'owner-claim-keys-unconfigured': 'Business cannot sign import grants yet',
|
|
65
|
+
'import-door-off': "the app's import door is off",
|
|
66
|
+
'installation-owner-claim-unconfigured': "the app's import door does not trust Business yet",
|
|
67
|
+
'door-trust-keys-stale': "the app's import door holds old Business keys",
|
|
68
|
+
'owner-not-claimed': 'the owner has not claimed the app yet',
|
|
69
|
+
'connected-seed-import-required': "the app's import door is not ready",
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** The claimed grant's door: its origin and byte quota. */
|
|
73
|
+
function destination(task, grant) {
|
|
74
|
+
if (grant.available === false || typeof grant.destination === 'string' && grant.destination.startsWith('unavailable:')) {
|
|
75
|
+
const reason = Object.hasOwn(unavailableWords, grant.reason) && grant.destination === `unavailable:${grant.reason}` ? grant.reason : 'connected-seed-import-required';
|
|
76
|
+
throw new ExportWaiting(`Business vendor export unavailable: ${reason} (${unavailableWords[reason]}). Task released as paused.`, 'connected_runner_required');
|
|
77
|
+
}
|
|
78
|
+
let url;
|
|
79
|
+
try { url = new URL(grant.destination); } catch { throw Error('Business returned an invalid import destination.'); }
|
|
80
|
+
if (!(url.protocol === 'https:' || url.protocol === 'http:' && loopback(url.hostname)) || url.username || url.password || url.search || url.hash
|
|
81
|
+
|| url.pathname !== '/api/rer/import/uploads' || grant.import_grants !== taskPath(task.id, 'import-grants')
|
|
82
|
+
|| !Number.isSafeInteger(grant.quota_bytes) || grant.quota_bytes < 1 || grant.quota_bytes > 300_000_000) throw Error('Business returned an invalid import destination.');
|
|
83
|
+
return { origin: url.origin, quota: grant.quota_bytes };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Inputs the shipped adapter needs beyond the key: the leased task's own
|
|
87
|
+
* non-secret `export_inputs`. A task that does not carry them yet waits for
|
|
88
|
+
* Business (which asks the owner when its evidence is missing). */
|
|
89
|
+
function adapterInputs(vendor, task) {
|
|
90
|
+
const inputs = exportInputs(vendor, task);
|
|
91
|
+
if (inputs) return inputs;
|
|
92
|
+
const needs = vendor === 'calendly' ? 'an import door that takes its folder of files' : `${inputNeeds[vendor]}, which this task does not carry yet`;
|
|
93
|
+
throw new ExportWaiting(`Business vendor export for ${vendorNames[vendor]} needs ${needs}. Task released as paused.`, 'configuration_required');
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** One RER-signed import grant for one door request. `review` asks for a
|
|
97
|
+
* catch-up plan grant without the owner's standing approval; a plan grant
|
|
98
|
+
* Business minted under that approval says so with `catchup: 'bounded'`. */
|
|
99
|
+
async function doorGrant(lease, action, origin, vendor, { review = false } = {}) {
|
|
100
|
+
const grant = await lease.importGrant(action, review ? { review: true } : {});
|
|
101
|
+
if (!grant || grant.action !== action || grant.destination !== new URL(`/api/rer/import/${action}`, origin).href
|
|
102
|
+
|| typeof grant.authorization !== 'string' || grant.authorization.length > 8192 || !/^Bearer [A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(grant.authorization)
|
|
103
|
+
|| !VENDORS.includes(grant.namespace) || vendor && grant.namespace !== vendor || !(Date.parse(grant.expires_at) > Date.now())
|
|
104
|
+
|| Object.hasOwn(grant, 'catchup') && (grant.catchup !== 'bounded' || action !== 'plan' || review)) throw Error('Business returned an invalid import grant.');
|
|
105
|
+
return grant;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** POST one request to the app's door. Only the door's error code is ever
|
|
109
|
+
* shown: its bodies can hold vendor records. */
|
|
110
|
+
export async function door(grant, body, signal) {
|
|
111
|
+
const action = grant.action;
|
|
112
|
+
let response;
|
|
113
|
+
try {
|
|
114
|
+
response = await fetch(grant.destination, { method: 'POST', redirect: 'error', body: JSON.stringify(body),
|
|
115
|
+
headers: { authorization: grant.authorization, 'content-type': 'application/json' }, signal: AbortSignal.any([signal, AbortSignal.timeout(30_000)]) });
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (signal.aborted) throw signal.reason;
|
|
118
|
+
const code = error?.cause?.code ?? error?.code;
|
|
119
|
+
throw Error(`Could not reach the app's import door at ${new URL(grant.destination).origin} (${error?.name === 'TimeoutError' ? 'no answer within 30 seconds' : typeof code === 'string' && /^[A-Z_]{2,40}$/.test(code) ? code : 'the request failed'}).`);
|
|
120
|
+
}
|
|
121
|
+
const chunks = []; let size = 0;
|
|
122
|
+
for await (const chunk of response.body ?? []) {
|
|
123
|
+
size += chunk.byteLength;
|
|
124
|
+
if (size > DOOR_RESPONSE_BYTES) { await response.body.cancel().catch(() => {}); throw Error(`The app's import door answered the ${action} request with more than the CLI reads.`); }
|
|
125
|
+
chunks.push(chunk);
|
|
126
|
+
}
|
|
127
|
+
let result = null;
|
|
128
|
+
try { result = JSON.parse(Buffer.concat(chunks).toString('utf8')); } catch { /* Judged below. */ }
|
|
129
|
+
if (!response.ok) {
|
|
130
|
+
// A door code is snake_case, sometimes with one named reason (`catchup_requires_proposal:source_records_gone`).
|
|
131
|
+
const doorCode = typeof result?.error === 'string' && /^[a-z][a-z0-9_]{0,79}(?::[a-z][a-z0-9_]{0,79})?$/.test(result.error) ? result.error : null;
|
|
132
|
+
throw Object.assign(Error(`The app's import door refused the ${action} request (HTTP ${response.status}${doorCode ? `: ${doorCode}` : ''}).`), { doorStatus: response.status, doorCode });
|
|
133
|
+
}
|
|
134
|
+
if (!result || typeof result !== 'object' || Array.isArray(result)) throw Error(`The app's import door returned an invalid ${action} answer.`);
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Run the shipped adapter into a private 0600 bundle file, checking every
|
|
139
|
+
* item with the outbound detector before it is written. */
|
|
140
|
+
async function exportBundle({ vendor, key = null, inputs, path, quota, signal }) {
|
|
141
|
+
await unlink(path).catch(error => { if (error.code !== 'ENOENT') throw error; });
|
|
142
|
+
const file = await open(path, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
|
|
143
|
+
const digest = createHash('sha256'); let size = 0;
|
|
144
|
+
try {
|
|
145
|
+
for await (const item of exportVendor(vendor, { key, inputs, signal })) {
|
|
146
|
+
assertChunk(item.bytes, key ? [key] : []);
|
|
147
|
+
size += item.bytes.length;
|
|
148
|
+
if (size > quota) throw Error(`Business vendor export is larger than the app's import door accepts (${quota} bytes). Nothing was uploaded.`);
|
|
149
|
+
digest.update(item.bytes);
|
|
150
|
+
await file.write(item.bytes);
|
|
151
|
+
}
|
|
152
|
+
await file.sync();
|
|
153
|
+
} catch (error) {
|
|
154
|
+
if (!(error instanceof VendorExportError)) throw error;
|
|
155
|
+
if (error.code === 'HTTP_REFUSED' && [401, 403].includes(error.status) && key) {
|
|
156
|
+
throw new ExportWaiting(`${vendorNames[vendor]} refused the stored read-only key (HTTP ${error.status}). To replace it, ${keyStep(vendor)}`, 'owner_required');
|
|
157
|
+
}
|
|
158
|
+
throw Error(`${vendorNames[vendor]} export stopped (${error.code}${error.status ? `, HTTP ${error.status}` : ''}). Nothing was uploaded.`);
|
|
159
|
+
} finally { await file.close(); }
|
|
160
|
+
if (!size) throw Error(`${vendorNames[vendor]} export produced nothing to upload.`);
|
|
161
|
+
return { size, sha256: digest.digest('hex') };
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function readChunk(path, index, size) {
|
|
165
|
+
const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
|
|
166
|
+
try {
|
|
167
|
+
const length = Math.min(CHUNK_BYTES, size - index * CHUNK_BYTES), bytes = Buffer.alloc(length);
|
|
168
|
+
const { bytesRead } = await file.read(bytes, 0, length, index * CHUNK_BYTES);
|
|
169
|
+
if (bytesRead !== length) throw Error('Business vendor export bundle changed while uploading.');
|
|
170
|
+
return bytes;
|
|
171
|
+
} finally { await file.close(); }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** A door plan's preview of exactly this bundle: its ids and the door's counts. */
|
|
175
|
+
export function checkedPreview(preview, bundle) {
|
|
176
|
+
const summary = preview.summary ?? {}, [records, created, updated, unchanged, gone] = ['sourceRecords', 'created', 'updated', 'unchanged', 'gone'].map(name => count(summary[name]));
|
|
177
|
+
const rejected = count(preview.counts?.rejected);
|
|
178
|
+
if (typeof preview.planId !== 'string' || !DOOR_ID.test(preview.planId) || !/^[a-f0-9]{64}$/.test(preview.fingerprint ?? '')
|
|
179
|
+
|| preview.bundleSha256 !== bundle.sha256 || [records, created, updated, unchanged, gone, rejected].includes(null)) throw Error("The app's import door returned an invalid preview.");
|
|
180
|
+
return { records, created, updated, unchanged, gone, rejected };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* The shared start of a claimed vendor door task: the claimed grant's door, the
|
|
185
|
+
* vendor its first grant names, the owner's key from the OS store, the shipped
|
|
186
|
+
* adapter into a private 0600 bundle, then the bundle in 64 KiB chunks, each with
|
|
187
|
+
* a fresh grant. A vendor that needs no key (a public status page) reads none.
|
|
188
|
+
* `finish` gets the uploaded bundle and returns `{outputs, said}`:
|
|
189
|
+
* the task then completes with those outputs (identifiers only, which Business
|
|
190
|
+
* checks against the door itself) and `said` is the line to say. The bundle file
|
|
191
|
+
* is removed on every exit. `doing(name, origin, keyed)` is said first.
|
|
192
|
+
*/
|
|
193
|
+
export async function withUploadedBundle({ lease, task, grant: claimedGrant, directory, say, doing }, finish) {
|
|
194
|
+
const signal = lease.signal, { origin, quota } = destination(task, claimedGrant);
|
|
195
|
+
// The first grant names the vendor (its namespace); it then carries chunk 0.
|
|
196
|
+
let spare = await doorGrant(lease, 'uploads', origin, null);
|
|
197
|
+
const vendor = spare.namespace, name = vendorNames[vendor], capability = VENDOR_CAPABILITIES[vendor];
|
|
198
|
+
const fresh = async (action, options) => {
|
|
199
|
+
if (action === 'uploads' && spare && Date.parse(spare.expires_at) - Date.now() > 60_000) { const grant = spare; spare = null; return grant; }
|
|
200
|
+
spare = null;
|
|
201
|
+
return doorGrant(lease, action, origin, vendor, options);
|
|
202
|
+
};
|
|
203
|
+
const inputs = adapterInputs(vendor, task);
|
|
204
|
+
let key = keyed(vendor) ? await createCredentialStore().get(vendorHandle(vendor)) : null;
|
|
205
|
+
if (keyed(vendor) && !key) throw new ExportWaiting(`Business vendor export needs the owner's read-only ${name} key on this computer: ${keyStep(vendor)}\nThen run ${businessCommand('run')} again.`, 'owner_required', { keyMissing: vendor });
|
|
206
|
+
const path = join(directory, `export-${hash(task.id).slice(0, 32)}.bundle`);
|
|
207
|
+
try {
|
|
208
|
+
say(doing(name, origin, keyed(vendor)));
|
|
209
|
+
let bundle;
|
|
210
|
+
try { bundle = await exportBundle({ vendor, key, inputs, path, quota, signal }); } finally { key = undefined; }
|
|
211
|
+
const total = Math.ceil(bundle.size / CHUNK_BYTES);
|
|
212
|
+
let uploadId;
|
|
213
|
+
for (let index = 0; index < total; index++) {
|
|
214
|
+
signal.throwIfAborted();
|
|
215
|
+
const bytes = await readChunk(path, index, bundle.size);
|
|
216
|
+
const result = await door(await fresh('uploads'), { ...(uploadId ? { uploadId } : {}), name: capability.output, bundleSha256: bundle.sha256,
|
|
217
|
+
totalBytes: bundle.size, totalChunks: total, index, chunkSha256: hash(bytes), base64: bytes.toString('base64') }, signal);
|
|
218
|
+
if (typeof result.uploadId !== 'string' || !DOOR_ID.test(result.uploadId) || uploadId && result.uploadId !== uploadId
|
|
219
|
+
|| result.bundleSha256 !== bundle.sha256 || index === total - 1 && result.complete !== true) throw Error("The app's import door returned an invalid upload answer.");
|
|
220
|
+
uploadId = result.uploadId;
|
|
221
|
+
await lease.checkpointSaved({ page: index + 1, total, bytes_done: Math.min((index + 1) * CHUNK_BYTES, bundle.size), progress: Math.floor((index + 1) / total * 90) });
|
|
222
|
+
}
|
|
223
|
+
const { outputs, said } = await finish({ vendor, name, origin, uploadId, bundle, fresh });
|
|
224
|
+
await lease.checkpointSaved({ page: total, total, bytes_done: bundle.size, progress: 100 });
|
|
225
|
+
await lease.complete(outputs);
|
|
226
|
+
return said;
|
|
227
|
+
} finally {
|
|
228
|
+
await unlink(path).catch(error => { if (error.code !== 'ENOENT') throw error; });
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -15,12 +15,15 @@ with their own supported readers and native adapters.
|
|
|
15
15
|
|
|
16
16
|
`exportVendor(vendor, {key, inputs, checkpoint, signal})` is an async generator.
|
|
17
17
|
It yields `{name, bytes: Buffer, checkpoint}`. Keys remain in memory and are
|
|
18
|
-
attached only to GET requests on the adapter's fixed HTTPS origin.
|
|
18
|
+
attached only to GET requests on the adapter's fixed HTTPS origin. Sorry reads a
|
|
19
|
+
public status page and takes no key (`key` must be absent); `KEYED_VENDORS` lists
|
|
20
|
+
the vendors that need one. Redirects,
|
|
19
21
|
caller origins, arbitrary paths and credential-bearing pagination are refused.
|
|
20
22
|
No export runs merely by importing these modules. No account export was run
|
|
21
23
|
during implementation.
|
|
22
24
|
|
|
23
|
-
`VENDORS` is the closed vendor enum
|
|
25
|
+
`VENDORS` is the closed vendor enum (`sentry`, `uptimerobot`, `pagerduty`,
|
|
26
|
+
`calendly`, `sorry`). `VENDOR_CAPABILITIES` describes the adapter,
|
|
24
27
|
required vendor-key capability, native importer format, layout and read scopes.
|
|
25
28
|
These adapters cannot verify that a supplied key itself has read-only scope;
|
|
26
29
|
the owner must create the documented read-only key where the vendor offers one.
|
|
@@ -51,12 +54,19 @@ import. Never treat a partial stream as a completed bundle.
|
|
|
51
54
|
Every item is at most 1 MiB. Exports are bounded to 1,000 requests, one request
|
|
52
55
|
per second, 30 seconds per request, 2 MiB/499 API records for Sentry,
|
|
53
56
|
512 KiB/500 records for PagerDuty, and 8 MiB/2,500 records for UptimeRobot and
|
|
54
|
-
Calendly.
|
|
57
|
+
Calendly. Sorry follows Lamp's reader: at most 200 requests (one saved file
|
|
58
|
+
each), one every 125 ms, 8 MiB of responses, 5,000 records and a 16 MiB bundle. The output bound includes JSON framing and Calendly's manifest.
|
|
55
59
|
Limits stop rather than truncate. AbortSignal stops waits, HTTP reads and
|
|
56
60
|
emission. HTTP errors contain only a fixed code and numeric status; network,
|
|
57
61
|
parsing and unexpected errors never expose response text, URLs or key values.
|
|
58
62
|
429 stops with `RATE_LIMITED`; there is no hidden retry loop.
|
|
59
63
|
|
|
64
|
+
The Business CLI supervisor currently captures a complete private bundle before
|
|
65
|
+
uploading it. After a lease handover, its next run captures and uploads the export
|
|
66
|
+
again under a fresh lease; it does not resume a partially uploaded bundle in
|
|
67
|
+
place. Only a completed upload and the door's matching plan are reported as a
|
|
68
|
+
preview. Calendly's folder layout remains outside this single-bundle path.
|
|
69
|
+
|
|
60
70
|
## Credentials in responses
|
|
61
71
|
|
|
62
72
|
Every adapter strips credential values from a parsed response before it emits
|
|
@@ -110,9 +120,23 @@ pagination link is still refused.
|
|
|
110
120
|
* `pagerduty`: `start`/`end` (or `since`/`until`). Exports users, schedule details
|
|
111
121
|
with layers/final coverage, overrides for the window and escalation policies.
|
|
112
122
|
Schedule listing only discovers IDs and is not duplicated in the bundle.
|
|
123
|
+
Oncall compares a schedule's final timeline over at most 31 days, so the
|
|
124
|
+
Business CLI passes a window of at most 31 whole UTC days ending two weeks
|
|
125
|
+
ahead.
|
|
113
126
|
Overrides retain full boundaries with `overflow=true` and add `schedule_id`,
|
|
114
127
|
as Oncall's documented bundle requires. Incident history and paging
|
|
115
128
|
configuration are not fetched.
|
|
129
|
+
* `sorry`: `page: {host}`, the public status page's host name (a public DNS
|
|
130
|
+
name; no scheme, port, path, IP address or local name). Reads, anonymously,
|
|
131
|
+
`/api/v1/status`, every `components` and `notices` page (`meta.next_page`) and
|
|
132
|
+
each notice's detail with its components and full update history, like Lamp's
|
|
133
|
+
public Move in. The bundle is Lamp's door `sorry` source: `{source: 'sorry',
|
|
134
|
+
publicUrl, publicAccessAcknowledged: true, files: [{name, text}]}`, each file
|
|
135
|
+
the original response text under the name Lamp's reader requires
|
|
136
|
+
(`sorry-status.json`, `sorry-components[-N].json`, `sorry-notices[-N].json`,
|
|
137
|
+
`sorry-notice-<id>.json`). Every response came from the page's own public API,
|
|
138
|
+
so it is public by construction; Lamp still refuses private or
|
|
139
|
+
audience-scoped records, and public responses carry no subscribers.
|
|
116
140
|
* `calendly`: optional `asOf` timestamp (recommended for a repeatable catch-up).
|
|
117
141
|
An omitted timestamp is captured at first invocation and retained on resume.
|
|
118
142
|
Downloads the current user, event types, availability schedules, per-type
|
|
@@ -129,6 +153,8 @@ their file-writing command wrappers.
|
|
|
129
153
|
|
|
130
154
|
* [Dial downloader at 6014c99875dd002545e194ab23a7852d30e94e01](https://github.com/just-every/run-dial/blob/6014c99875dd002545e194ab23a7852d30e94e01/scripts/move-in/download.mjs).
|
|
131
155
|
* [Uptime guide at 157686b52ecc652d64250a30ec224f1a47355a6c](https://github.com/just-every/run-uptime/blob/157686b52ecc652d64250a30ec224f1a47355a6c/docs/moving-from-uptimerobot.md).
|
|
156
|
+
* [Lamp's Sorry public reader at a0179bfe](https://github.com/just-every/run-lamp/blob/a0179bfe/src/core/features/statuspage-import/sorry/fetch.ts)
|
|
157
|
+
and its door source (`door-plan.ts` `doorExport`).
|
|
132
158
|
* [Oncall guide at 4f928effc3ce735f3d246bb8a3c4bbb8436cae6b](https://github.com/just-every/run-oncall/blob/4f928effc3ce735f3d246bb8a3c4bbb8436cae6b/docs/move-in.md).
|
|
133
159
|
* Spool's proposal-cited `app/docs/SENTRY-SWITCHING.md` and
|
|
134
160
|
`app/src/domain/sentry-import/source.ts`, local source commit
|
|
@@ -162,8 +162,9 @@ export function client({ origin, headers, route, signal, limits, counters, key }
|
|
|
162
162
|
const url = new URL(path, origin);
|
|
163
163
|
if (url.origin !== origin || url.username || url.password || url.hash || !route(url)) fail('INVALID_REFERENCE');
|
|
164
164
|
if (++counters.requests > limits.requests) fail('REQUEST_LIMIT');
|
|
165
|
-
// At most one request per second
|
|
166
|
-
|
|
165
|
+
// At most one request per `spacing` (a second unless the adapter's limits say
|
|
166
|
+
// otherwise); no automatic retry or rate-limit hammering.
|
|
167
|
+
const pause = (limits.spacing ?? 1000) - (Date.now() - lastRequest);
|
|
167
168
|
if (pause > 0) await delay(pause, undefined, { signal });
|
|
168
169
|
lastRequest = Date.now();
|
|
169
170
|
const timeout = AbortSignal.timeout(30_000);
|
|
@@ -189,9 +190,10 @@ export function client({ origin, headers, route, signal, limits, counters, key }
|
|
|
189
190
|
}
|
|
190
191
|
const bytes = Buffer.concat(chunks);
|
|
191
192
|
// A reflected authentication key must never become a vendor artifact.
|
|
192
|
-
if (bytes.includes(Buffer.from(key))) fail('CREDENTIAL_IN_RESPONSE');
|
|
193
|
-
let body;
|
|
194
|
-
try { body = JSON.parse(
|
|
195
|
-
|
|
193
|
+
if (key && bytes.includes(Buffer.from(key))) fail('CREDENTIAL_IN_RESPONSE');
|
|
194
|
+
let text, body;
|
|
195
|
+
try { text = new TextDecoder('utf-8', { fatal: true }).decode(bytes); body = JSON.parse(text); } catch { fail('INVALID_JSON'); }
|
|
196
|
+
// `text` is the response exactly as received, for adapters whose bundle keeps original bytes.
|
|
197
|
+
return { body, text, headers: response.headers };
|
|
196
198
|
};
|
|
197
199
|
}
|
|
@@ -3,22 +3,31 @@ import * as sentry from './sentry.mjs';
|
|
|
3
3
|
import * as uptimerobot from './uptimerobot.mjs';
|
|
4
4
|
import * as pagerduty from './pagerduty.mjs';
|
|
5
5
|
import * as calendly from './calendly.mjs';
|
|
6
|
+
import * as sorry from './sorry.mjs';
|
|
6
7
|
|
|
7
8
|
export { VendorExportError } from './common.mjs';
|
|
8
|
-
export const VENDORS = Object.freeze(['sentry','uptimerobot','pagerduty','calendly']);
|
|
9
|
-
const adapters = { sentry, uptimerobot, pagerduty, calendly };
|
|
9
|
+
export const VENDORS = Object.freeze(['sentry','uptimerobot','pagerduty','calendly','sorry']);
|
|
10
|
+
const adapters = { sentry, uptimerobot, pagerduty, calendly, sorry };
|
|
10
11
|
export const VENDOR_CAPABILITIES = Object.freeze({
|
|
11
12
|
sentry: Object.freeze({ vendor: 'sentry', adapter: 'rer:sentry', capability: 'vendor_key:sentry', format: 'spool-sentry-org-export-v1', layout: 'concatenate', output: 'sentry-export.json', readOnly: true, resume: true, scopes: ['org:read','project:read','event:read'], origins: Object.values(sentry.origins) }),
|
|
12
13
|
uptimerobot: Object.freeze({ vendor: 'uptimerobot', adapter: 'rer:uptimerobot', capability: 'vendor_key:uptimerobot', format: 'uptimerobot-v3-monitors', layout: 'concatenate', output: 'uptimerobot-monitors.json', readOnly: true, resume: true, scopes: ['read-only API key'], origins: [uptimerobot.origin] }),
|
|
13
14
|
pagerduty: Object.freeze({ vendor: 'pagerduty', adapter: 'rer:pagerduty', capability: 'vendor_key:pagerduty', format: 'pagerduty-saved-responses', layout: 'concatenate', output: 'pagerduty-export.json', readOnly: true, resume: true, scopes: ['read-only REST API key'], origins: [pagerduty.origin] }),
|
|
14
15
|
calendly: Object.freeze({ vendor: 'calendly', adapter: 'rer:calendly', capability: 'vendor_key:calendly', format: 'dial-calendly-api-folder-v1', layout: 'files', output: 'manifest.json', readOnly: true, resume: true, scopes: ['personal access token with read access'], origins: [calendly.origin] }),
|
|
16
|
+
// A public status page: read anonymously from the page's own address, so it takes no key.
|
|
17
|
+
sorry: Object.freeze({ vendor: 'sorry', adapter: 'rer:sorry', capability: null, format: 'lamp-sorry-public-responses', layout: 'concatenate', output: 'sorry-export.json', readOnly: true, resume: true, scopes: [], origins: ['https://<page host>'] }),
|
|
15
18
|
});
|
|
19
|
+
/** The vendors whose export needs the owner's read-only key. */
|
|
20
|
+
export const KEYED_VENDORS = Object.freeze(VENDORS.filter(vendor => VENDOR_CAPABILITIES[vendor].capability !== null));
|
|
16
21
|
const LIMITS = Object.freeze({
|
|
17
22
|
// Spool's 500-record bound also counts its synthesized manifest record.
|
|
18
23
|
sentry: { bytes: 2 * 1024 * 1024, records: 499 },
|
|
19
24
|
uptimerobot: { bytes: 8 * 1024 * 1024, records: 2500 },
|
|
20
25
|
pagerduty: { bytes: 512 * 1024, records: 500 },
|
|
21
26
|
calendly: { bytes: 8 * 1024 * 1024, records: 2500 },
|
|
27
|
+
// Lamp's Sorry reader: 8 MiB of responses in at most 200 files and 5,000
|
|
28
|
+
// records; its door takes twice that, as the bundle carries each response as
|
|
29
|
+
// JSON text. Lamp reads a public page at most every 125 ms.
|
|
30
|
+
sorry: { bytes: 8 * 1024 * 1024, emitted: 16 * 1024 * 1024, records: 5000, requests: 200, spacing: 125 },
|
|
22
31
|
});
|
|
23
32
|
|
|
24
33
|
/** Persist each checkpoint only after the corresponding bytes have been acknowledged.
|
|
@@ -27,27 +36,29 @@ const LIMITS = Object.freeze({
|
|
|
27
36
|
export async function* exportVendor(vendor, { key, inputs = {}, checkpoint, signal } = {}) {
|
|
28
37
|
try {
|
|
29
38
|
if (!VENDORS.includes(vendor)) fail('UNSUPPORTED_VENDOR');
|
|
30
|
-
|
|
39
|
+
const keyed = KEYED_VENDORS.includes(vendor);
|
|
40
|
+
if (keyed ? typeof key !== 'string' || !key || key.length > 8192 || /[\u0000-\u0020\u007f]/u.test(key) : key != null) fail('INVALID_KEY');
|
|
31
41
|
object(inputs);
|
|
32
42
|
const fingerprint = hash(JSON.stringify(stable({ vendor, inputs })));
|
|
33
|
-
const limits = { ...LIMITS[vendor],
|
|
43
|
+
const limits = { requests: 1000, ...LIMITS[vendor], pageBytes: 1024 * 1024 - 16 * 1024 };
|
|
34
44
|
let state, sequence = 0;
|
|
35
45
|
let counters = { requests: 0, received: 0, emitted: 0, records: 0 };
|
|
36
46
|
if (checkpoint != null) {
|
|
37
47
|
const encoded = JSON.stringify(checkpoint);
|
|
38
|
-
if (Buffer.byteLength(encoded) >= 128 * 1024 || encoded.includes(key)) fail('INVALID_CHECKPOINT');
|
|
48
|
+
if (Buffer.byteLength(encoded) >= 128 * 1024 || key && encoded.includes(key)) fail('INVALID_CHECKPOINT');
|
|
39
49
|
const cp = JSON.parse(encoded);
|
|
40
50
|
shape(cp, ['version','vendor','fingerprint','sequence','counters','state']);
|
|
41
51
|
if (cp.version !== 1 || cp.vendor !== vendor || cp.fingerprint !== fingerprint) fail('INVALID_CHECKPOINT');
|
|
42
52
|
sequence = assertCount(cp.sequence, 2000);
|
|
43
53
|
shape(cp.counters, ['requests','received','emitted','records']); object(cp.state);
|
|
44
|
-
counters = Object.fromEntries(Object.keys(counters).map(name => [name, assertCount(cp.counters[name], name === 'requests' ? limits.requests : name === 'records' ? limits.records : limits.bytes)]));
|
|
54
|
+
counters = Object.fromEntries(Object.keys(counters).map(name => [name, assertCount(cp.counters[name], name === 'requests' ? limits.requests : name === 'records' ? limits.records : name === 'emitted' ? limits.emitted ?? limits.bytes : limits.bytes)]));
|
|
45
55
|
state = cp.state;
|
|
46
56
|
}
|
|
47
57
|
const adapter = adapters[vendor];
|
|
48
|
-
const origin = vendor === 'sentry' ? adapter.origins[inputs.organization?.region] : adapter.origin;
|
|
58
|
+
const origin = vendor === 'sentry' ? adapter.origins[inputs.organization?.region] : vendor === 'sorry' ? adapter.originOf(inputs) : adapter.origin;
|
|
49
59
|
if (!origin) fail('INVALID_INPUT');
|
|
50
|
-
const headers = { Accept: vendor === 'pagerduty' ? 'application/vnd.pagerduty+json;version=2' : 'application/json',
|
|
60
|
+
const headers = { Accept: vendor === 'pagerduty' ? 'application/vnd.pagerduty+json;version=2' : 'application/json',
|
|
61
|
+
...(keyed ? { Authorization: vendor === 'pagerduty' ? `Token token=${key}` : `Bearer ${key}` } : {}) };
|
|
51
62
|
const ctx = {
|
|
52
63
|
inputs, state,
|
|
53
64
|
get: client({ origin, headers, route: adapter.route, signal, limits, counters, key }),
|
|
@@ -58,12 +69,12 @@ export async function* exportVendor(vendor, { key, inputs = {}, checkpoint, sign
|
|
|
58
69
|
item(value, nextState, name) {
|
|
59
70
|
signal?.throwIfAborted();
|
|
60
71
|
const bytes = Buffer.isBuffer(value) ? value : Buffer.from(value);
|
|
61
|
-
if (bytes.length > 1024 * 1024 || (counters.emitted += bytes.length) > limits.bytes) fail('BYTE_LIMIT');
|
|
62
|
-
if (bytes.includes(Buffer.from(key))) fail('CREDENTIAL_IN_RESPONSE');
|
|
72
|
+
if (bytes.length > 1024 * 1024 || (counters.emitted += bytes.length) > (limits.emitted ?? limits.bytes)) fail('BYTE_LIMIT');
|
|
73
|
+
if (key && bytes.includes(Buffer.from(key))) fail('CREDENTIAL_IN_RESPONSE');
|
|
63
74
|
if (++sequence > 2000) fail('ITEM_LIMIT');
|
|
64
75
|
const cp = { version: 1, vendor, fingerprint, sequence, counters: { ...counters }, state: nextState };
|
|
65
76
|
const encoded = JSON.stringify(cp);
|
|
66
|
-
if (Buffer.byteLength(encoded) >= 128 * 1024 || encoded.includes(key)) fail('CHECKPOINT_LIMIT');
|
|
77
|
+
if (Buffer.byteLength(encoded) >= 128 * 1024 || key && encoded.includes(key)) fail('CHECKPOINT_LIMIT');
|
|
67
78
|
return { name: name ?? `${String(sequence).padStart(6,'0')}.part`, bytes, checkpoint: JSON.parse(encoded) };
|
|
68
79
|
},
|
|
69
80
|
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { object, list, assertCount, shape, fail } from './common.mjs';
|
|
2
|
+
|
|
3
|
+
// Sorry's public status page API, read anonymously from the page's own HTTPS
|
|
4
|
+
// address, as Lamp's Move in reads it (statuspage-import/sorry/fetch.ts,
|
|
5
|
+
// fetchSorryPublicResponses): /api/v1/status, the components and notices lists
|
|
6
|
+
// (25 a page, `meta.next_page`), then every notice's detail with its components
|
|
7
|
+
// and full update history. No key is sent or accepted.
|
|
8
|
+
|
|
9
|
+
const label = /^(?!-)[a-z0-9-]{1,63}(?<!-)$/u;
|
|
10
|
+
/** The page's public HTTPS origin from its host name alone: no scheme, port,
|
|
11
|
+
* path, credentials, IP address or local name can come from the inputs. */
|
|
12
|
+
export function originOf(inputs) {
|
|
13
|
+
const page = object(inputs.page);
|
|
14
|
+
if (Object.keys(page).some(key => key !== 'host')) fail('INVALID_INPUT');
|
|
15
|
+
const host = page.host;
|
|
16
|
+
if (typeof host !== 'string' || host.length > 253) fail('INVALID_INPUT');
|
|
17
|
+
const labels = host.split('.');
|
|
18
|
+
if (labels.length < 2 || !labels.every(part => label.test(part)) || /^[0-9]+$/u.test(labels.at(-1))
|
|
19
|
+
|| ['localhost', 'local', 'internal', 'invalid', 'test'].includes(labels.at(-1))) fail('INVALID_INPUT');
|
|
20
|
+
return `https://${host}`;
|
|
21
|
+
}
|
|
22
|
+
export const route = url => /^\/api\/v1\/(?:status|components|notices(?:\/(?:0|[1-9][0-9]{0,127}))?)$/u.test(url.pathname)
|
|
23
|
+
&& [...url.searchParams.keys()].every(key => key === 'page');
|
|
24
|
+
|
|
25
|
+
const resources = ['components', 'notices'];
|
|
26
|
+
/** The documented next page of one public list: the same collection, page n+1, or null. */
|
|
27
|
+
function nextPage(value, path, current) {
|
|
28
|
+
if (value == null) return null;
|
|
29
|
+
if (typeof value !== 'string' || value.length > 2048) fail('INVALID_PAGINATION');
|
|
30
|
+
let next;
|
|
31
|
+
try { next = new URL(value, 'https://sorry.invalid'); } catch { fail('INVALID_PAGINATION'); }
|
|
32
|
+
const params = [...next.searchParams];
|
|
33
|
+
if (next.username || next.password || next.hash || ![path, path.replace('/api/v1/', '/v1/')].includes(next.pathname)
|
|
34
|
+
|| params.length !== 1 || params[0][0] !== 'page' || params[0][1] !== String(current + 1)) fail('INVALID_PAGINATION');
|
|
35
|
+
return `${path}?page=${current + 1}`;
|
|
36
|
+
}
|
|
37
|
+
/** Notice ids exactly as Sorry wrote them (large integers never pass through Number). */
|
|
38
|
+
function noticeIds(text) {
|
|
39
|
+
const ids = [];
|
|
40
|
+
JSON.parse(text, function (key, value, context) {
|
|
41
|
+
// A notice is the object with a subject; its components and updates have none.
|
|
42
|
+
if (key === 'id' && this && !Array.isArray(this) && Object.hasOwn(this, 'subject')) {
|
|
43
|
+
const lexeme = typeof value === 'string' ? value : context?.source;
|
|
44
|
+
if (typeof lexeme !== 'string' || !/^(?:0|[1-9][0-9]{0,127})$/u.test(lexeme)) fail('INVALID_RESPONSE');
|
|
45
|
+
ids.push(lexeme);
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
});
|
|
49
|
+
return ids;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The bundle Lamp's import door reads for its `sorry` source (door-plan.ts
|
|
53
|
+
* `doorExport`): the public page address, the saved responses under the file
|
|
54
|
+
* names Lamp's Sorry reader requires, each with its original text, and the
|
|
55
|
+
* acknowledgement that they are public. Every response here came from the
|
|
56
|
+
* page's own unauthenticated API, so it is public by construction; Lamp still
|
|
57
|
+
* refuses any private, unpublished or audience-scoped record, and the owner
|
|
58
|
+
* reviews the plan before anything is imported. */
|
|
59
|
+
export async function* run(ctx) {
|
|
60
|
+
const origin = originOf(ctx.inputs);
|
|
61
|
+
const s = ctx.state ?? { phase: 0, page: 1, total: null, rows: 0, notices: [], index: 0 };
|
|
62
|
+
shape(s, ['phase', 'page', 'total', 'rows', 'notices', 'index']);
|
|
63
|
+
assertCount(s.phase, 4); assertCount(s.page, 50); assertCount(s.rows, 5000); assertCount(s.index, 5000);
|
|
64
|
+
if (s.total !== null) assertCount(s.total, 5000);
|
|
65
|
+
if (!Array.isArray(s.notices) || s.notices.length > 1250 || s.notices.some(id => typeof id !== 'string' || !/^(?:0|[1-9][0-9]{0,127})$/u.test(id))) fail('INVALID_CHECKPOINT');
|
|
66
|
+
const file = (name, text, first = false) => (first ? '' : ',') + JSON.stringify({ name, text });
|
|
67
|
+
while (s.phase < 4) {
|
|
68
|
+
let bytes;
|
|
69
|
+
if (s.phase === 0) {
|
|
70
|
+
const { body, text } = await ctx.get('/api/v1/status');
|
|
71
|
+
const page = object(object(body).page);
|
|
72
|
+
if (typeof page.name !== 'string' || typeof page.url !== 'string') fail();
|
|
73
|
+
ctx.records(1);
|
|
74
|
+
s.phase = 1;
|
|
75
|
+
bytes = JSON.stringify({ source: 'sorry', publicUrl: origin, publicAccessAcknowledged: true }).slice(0, -1) + ',"files":[' + file('sorry-status.json', text, true);
|
|
76
|
+
} else if (s.phase <= 2) {
|
|
77
|
+
const resource = resources[s.phase - 1], path = `/api/v1/${resource}`;
|
|
78
|
+
const { body, text } = await ctx.get(s.page === 1 ? path : `${path}?page=${s.page}`);
|
|
79
|
+
object(body); const rows = list(body[resource], 25), meta = object(body.meta);
|
|
80
|
+
if (meta.count !== rows.length || !Number.isSafeInteger(meta.total_count) || s.total !== null && meta.total_count !== s.total) fail('INVALID_PAGINATION');
|
|
81
|
+
ctx.records(rows.length);
|
|
82
|
+
if (resource === 'notices') {
|
|
83
|
+
const ids = noticeIds(text);
|
|
84
|
+
if (ids.length !== rows.length || ids.some(id => s.notices.includes(id))) fail('DUPLICATE_ID');
|
|
85
|
+
s.notices.push(...ids);
|
|
86
|
+
}
|
|
87
|
+
s.rows += rows.length; s.total = meta.total_count;
|
|
88
|
+
const next = nextPage(meta.next_page, path, s.page);
|
|
89
|
+
if (s.rows > s.total || Boolean(next) !== s.rows < s.total || next && !rows.length) fail('INVALID_PAGINATION');
|
|
90
|
+
bytes = file(`sorry-${resource}${s.page === 1 ? '' : `-${s.page}`}.json`, text);
|
|
91
|
+
if (next) { if (++s.page > 50) fail('PAGE_LIMIT'); }
|
|
92
|
+
else { s.phase++; s.page = 1; s.total = null; s.rows = 0; }
|
|
93
|
+
} else {
|
|
94
|
+
if (s.index === s.notices.length) { s.phase = 4; yield ctx.item(']}\n', s); break; }
|
|
95
|
+
const id = s.notices[s.index];
|
|
96
|
+
const { body, text } = await ctx.get(`/api/v1/notices/${id}`);
|
|
97
|
+
const notice = object(object(body).notice);
|
|
98
|
+
const ids = noticeIds(text);
|
|
99
|
+
if (ids.length !== 1 || ids[0] !== id || !Array.isArray(notice.components) || !Array.isArray(notice.updates)) fail('INVALID_RESPONSE');
|
|
100
|
+
ctx.records(1 + notice.updates.length);
|
|
101
|
+
bytes = file(`sorry-notice-${id}.json`, text);
|
|
102
|
+
s.index++;
|
|
103
|
+
}
|
|
104
|
+
yield ctx.item(bytes, s);
|
|
105
|
+
}
|
|
106
|
+
}
|
package/cli/contract.mjs
CHANGED
|
@@ -11,7 +11,7 @@ const definitions = {
|
|
|
11
11
|
build: [['--site'], 'Production build with private local settings excluded and restored. --site instead writes the static run site (homepage, /run, docs) to its declared folder and prints that folder.'],
|
|
12
12
|
verify: [[], 'Run the complete internal verification target.'],
|
|
13
13
|
reset: [['--yes'], 'Confirmed removal of the declared local inventory only.'],
|
|
14
|
-
deploy: [['--owner-name', '--environment', '--dry-run', '--site', '--demo', '--host', '--env-file', '--image', '--bind-address', '--http-port', '--https-port', '--remove', '--yes', '--set-secret', '--unset-secret', '--rotate-secret', '--reopen-installation-key'], 'Owner-account deployment and health; dry run builds and validates the local deployment plan, printing target names, bindings and migration names. No Cloudflare credentials or requests are needed and nothing changes remotely. Target secrets, permissions and remote readiness are checked only by a real deploy. Builds and deploy hooks run with the checkout\'s local settings files moved aside, and a build output holding one (.dev.vars, .env) is refused. Declared secrets come from the environment or --env-file (an owned 0600 KEY=VALUE file); a new Worker gets the local setup owner and fresh generated secrets when they are not given. rer keeps the secrets it generates in .rer/deploy/ENVIRONMENT.secrets.env (0600) and reuses them on every redeploy; it refuses to generate a replacement for one a live Worker holds, and --rotate-secret NAME[,NAME] replaces them on purpose. After a healthy deploy rer claims the setup owner on the hosted app with the saved setup owner name and the one-time setup token, then removes the token. If the installer declares an owner-name field and no name is saved, deploy asks once and saves it; --non-interactive requires --owner-name NAME before any upload. --set-secret NAME[,NAME] (each value from the environment or --env-file; repeat the flag or join names with commas) and --unset-secret NAME[,NAME] change those secrets of the deployed Worker without a build, all of them in one new Worker version or none, and record that version; a missing value refuses before any change. --reopen-installation-key KID temporarily binds a retired installation key from private custody, reseals restored dependency keys under the current key, verifies them and removes the previous binding. --remove --yes deletes what this environment\'s deploy record says rer created (Worker, D1, R2, KV, queues), reads back that each is gone, and touches nothing else. --site deploys the run site instead: an assets-only Worker on its custom domain with www redirected; with --dry-run it builds the site and prints the plan with no provider request. --demo deploys the hosted demo instead (deploy-demo.json): a front Worker on demo.<domain> giving each visitor their own signed-in, throwaway native Worker isolate of this seed with real public reads/checks and simulated external writes; --dry-run writes it to .rer/demo-host with no provider request; --demo --remove --yes deletes that demo (its Worker, demo.<domain> Custom Domain, each only while the record its deploy left proves it the demo\'s), reads back that each is gone, and is a no-op once it is.'],
|
|
14
|
+
deploy: [['--owner-name', '--environment', '--dry-run', '--site', '--demo', '--host', '--env-file', '--image', '--bind-address', '--http-port', '--https-port', '--remove', '--yes', '--set-secret', '--unset-secret', '--rotate-secret', '--reopen-installation-key'], 'Owner-account deployment and health; dry run builds and validates the local deployment plan, printing target names, bindings and migration names. No Cloudflare credentials or requests are needed and nothing changes remotely. Valid fixture senders on .test, .example, .invalid, .localhost and example.com, example.net or example.org (including subdomains) are accepted only in a dry run; real deploys refuse placeholder senders. Dry run never prompts for or requires a missing owner name, saves no name and bypasses custom deploy hooks and their owner-email preflight. Target secrets, permissions and remote readiness are checked only by a real deploy. Builds and deploy hooks run with the checkout\'s local settings files moved aside, and a build output holding one (.dev.vars, .env) is refused. Declared secrets come from the environment or --env-file (an owned 0600 KEY=VALUE file); a new Worker gets the local setup owner and fresh generated secrets when they are not given. rer keeps the secrets it generates in .rer/deploy/ENVIRONMENT.secrets.env (0600) and reuses them on every redeploy; it refuses to generate a replacement for one a live Worker holds, and --rotate-secret NAME[,NAME] replaces them on purpose. After a healthy deploy rer claims the setup owner on the hosted app with the saved setup owner name and the one-time setup token, then removes the token. For a real deploy, the managed adapter checks its hosted owner email before rer resolves the owner name, so its placeholder-email refusal comes first. If the installer declares an owner-name field and no name is saved, deploy asks once and saves it; --non-interactive requires --owner-name NAME before any upload. --set-secret NAME[,NAME] (each value from the environment or --env-file; repeat the flag or join names with commas) and --unset-secret NAME[,NAME] change those secrets of the deployed Worker without a build, all of them in one new Worker version or none, and record that version; a missing value refuses before any change. --reopen-installation-key KID temporarily binds a retired installation key from private custody, reseals restored dependency keys under the current key, verifies them and removes the previous binding. --remove --yes deletes what this environment\'s deploy record says rer created (Worker, D1, R2, KV, queues), reads back that each is gone, and touches nothing else. --site deploys the run site instead: an assets-only Worker on its custom domain with www redirected; with --dry-run it builds the site and prints the plan with no provider request. --demo deploys the hosted demo instead (deploy-demo.json): a front Worker on demo.<domain> giving each visitor their own signed-in, throwaway native Worker isolate of this seed with real public reads/checks and simulated external writes; --dry-run writes it to .rer/demo-host with no provider request; --demo --remove --yes deletes that demo (its Worker, demo.<domain> Custom Domain, each only while the record its deploy left proves it the demo\'s), reads back that each is gone, and is a no-op once it is.'],
|
|
15
15
|
export: [['--target', '--output', '--origin', '--session-file'], 'For owner move-in, run rer dev and open /app/import: export people there, then upload through the destination door. Developer-only installation backup: complete supported archive of the local copy on this computer, with integrity and exclusions, written to --output. The hosted install cannot be exported yet: --origin or --target remote refuses (exit 2) before any effect and names the command that saves the hosted database.'],
|
|
16
16
|
import: [['--target', '--input', '--journal', '--origin', '--session-file', '--yes', '--legacy-v1', '--acknowledge-unverified-metadata', '--acknowledge-unverified-schema-objects', '--output'], 'For owner move-in, run rer dev and open /app/import: upload, review and apply through the door. Developer-only installation recovery: confirmed atomic restore into an empty destination; --journal LATER_ARCHIVE also fences rows that installation erased since. Backup-only local v1 recovery requires --legacy-v1 --acknowledge-unverified-metadata and a new --output v2 archive; --journal requires normal v2 import. A v2 archive without schemaObjects requires --acknowledge-unverified-schema-objects, an empty destination and compatible destination migration history; its receipt records schemaUnverified. A fresh export from current rer is preferred; current archives need no acknowledgment.'],
|
|
17
17
|
doctor: [[], 'Read-only installed tool, configuration and state diagnostics.', 'never'],
|
|
@@ -29,7 +29,7 @@ export const signinVerb = Object.freeze({ bootstrap: 'before', flags: [...common
|
|
|
29
29
|
// Their project-package bootstrap uses the same contract as every checkout verb.
|
|
30
30
|
export const authoringVerbs = Object.freeze({
|
|
31
31
|
'adopt-edition': {bootstrap: 'before', flags: [...commonFlags], effects: 'Add edition.json and sources.lock.json for the existing tracked local source, preserving declared project identity and existing copy/composition records. Create an empty base-copies.json only when none exists. Review and stage the new authoring inputs; no source regeneration, install setup or commit.'},
|
|
32
|
-
'refresh-base': {bootstrap: 'before', flags: [...commonFlags, '--ref', '--base', '--record', '--offline', '--edition-migration'], effects: 'Consent to each declared edition edit with repeatable --edition-migration ID; refresh leaves the edit owed. Refresh recorded Base copies to --ref FULL_COMMIT, preserving acknowledged adaptations and applied migrations; announce removed singleton retirement. Deliver invoked workflow helpers atomically; adopt tracked known historical Verify templates and preserve divergent workflows with adoption notices. Acquire committed source from the declared Base repository (default https://github.com/runeditrun/base.git), or use --base CHECKOUT. --offline requires --base and never acquires remote source. Refuse incomplete Git checkouts without changing their records. Review the diff and run edition tests before committing.'},
|
|
32
|
+
'refresh-base': {bootstrap: 'before', flags: [...commonFlags, '--ref', '--base', '--base-archive', '--record', '--offline', '--edition-migration'], effects: 'Consent to each declared edition edit with repeatable --edition-migration ID; refresh leaves the edit owed. Refresh recorded Base copies to --ref FULL_COMMIT, preserving acknowledged adaptations and applied migrations; announce removed singleton retirement. Deliver invoked workflow helpers atomically; adopt tracked known historical Verify templates and preserve divergent workflows with adoption notices. Acquire committed source from the declared Base repository (default https://github.com/runeditrun/base.git), or use --base CHECKOUT or --base-archive DIRECTORY with --ref FULL_COMMIT for an exported source tree. --offline requires --base and never acquires remote source. Refuse incomplete Git checkouts without changing their records. Review the diff and run edition tests before committing.'},
|
|
33
33
|
});
|
|
34
34
|
export const aliases = Object.fromEntries([...Object.keys(verbs).filter(v => v !== 'install'), 'release', 'deps', 'rer'].map(name => [name, name === 'deps' ? 'install' : name === 'rer' ? null : name]));
|
|
35
35
|
export const releaseFlags = ['--repo', '--project', '--repository', '--output', '--ref', '--public-base', '--dry-run', '--local-verify', '--verify-workflow', '--scan-timeout-seconds', '--tag', '--clean-history', '--onto', '--env-file', '--allow-placeholder-mark', '--no-queue'];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RerError } from './errors.mjs';
|
|
2
|
+
|
|
3
|
+
// Approve only known ownership failures; arbitrary provider error text stays
|
|
4
|
+
// behind the usual redacted capture boundary.
|
|
5
|
+
export function demoDeployFailure(error, store) {
|
|
6
|
+
const codes = ['resource-name-collision', 'owned-resource-replaced', 'resource-not-in-record', 'uncertain-resource-create'];
|
|
7
|
+
if (!codes.includes(error.message)) return error;
|
|
8
|
+
const resource = typeof error.resource === 'string' && /^[a-z-]+:[a-z0-9.-]+$/.test(error.resource) ? ` ${error.resource}` : '';
|
|
9
|
+
const reason = error.ownershipReason === 'missing-annotation'
|
|
10
|
+
? ': served version has no workers/message ownership annotation; unchanged secret-only history matching the previous rer deployment record could not be verified'
|
|
11
|
+
: error.ownershipReason === 'different-annotation' ? ': served version workers/message ownership annotation does not match this demo' : '';
|
|
12
|
+
const recovery = 'Nothing was changed. For your own demo, restore the verified previous rer deployment and its workers/message ownership annotation, then rerun the same command. For a foreign resource, choose another --environment name or remove it yourself.';
|
|
13
|
+
return new RerError('deploy_refused', store.redact(`Demo deploy refused: ${error.message}${resource}${reason}. ${recovery}`), 1);
|
|
14
|
+
}
|
package/cli/demo-native.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { cloudflare } from '../modules/deploy-kit/provider.mjs';
|
|
|
10
10
|
import { RUNTIME_FILES } from '../modules/demo-host/native/config.mjs';
|
|
11
11
|
import { prepareNative } from '../modules/demo-host/native/prepare.mjs';
|
|
12
12
|
import { TESTING_SECRET } from '../modules/demo-host/measurement.mjs';
|
|
13
|
+
import { demoDeployFailure } from './demo-deploy-error.mjs';
|
|
13
14
|
import { awaitCertificates } from '../modules/demo-host/certificate.mjs';
|
|
14
15
|
|
|
15
16
|
export async function nativeDemoCommand(project, options, store, signal, out, operation, app, plan) {
|
|
@@ -52,7 +53,9 @@ export async function nativeDemoCommand(project, options, store, signal, out, op
|
|
|
52
53
|
const required = ['CLOUDFLARE_ACCOUNT_ID', 'CLOUDFLARE_API_TOKEN', 'TURNSTILE_SITE_KEY', 'TURNSTILE_SECRET_KEY'];
|
|
53
54
|
if (required.some(name => !process.env[name]?.trim())) throw missing(`${required.join(', ')} are required`);
|
|
54
55
|
const api = cloudflare({ accountId: process.env.CLOUDFLARE_ACCOUNT_ID, token: process.env.CLOUDFLARE_API_TOKEN });
|
|
55
|
-
|
|
56
|
+
await store.step(`Checking ownership of the demo Worker ${plan.worker}`);
|
|
57
|
+
try { config.migrations = await upgradeDemo({ api, plan, report: line => store.report(line) }); }
|
|
58
|
+
catch (error) { throw demoDeployFailure(error, store); }
|
|
56
59
|
await writeFile(join(folder, 'wrangler.json'), JSON.stringify(config, null, 2) + '\n');
|
|
57
60
|
const testing = TESTING_SECRET.test(process.env.TURNSTILE_SECRET_KEY);
|
|
58
61
|
const measurement = testing ? process.env.RER_DEMO_MEASUREMENT_TOKEN || randomBytes(32).toString('base64url') : undefined;
|
package/cli/deploy-config.mjs
CHANGED
|
@@ -28,7 +28,7 @@ export function tomlMain(source) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export function jsoncMain(source) {
|
|
31
|
-
try { return
|
|
31
|
+
try { return parseJsonc(source).main; } catch { return undefined; }
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// The deployed Worker entry (`main`) from the first of those files that exists.
|