@runeditrun/rer 0.2.99 → 0.2.101

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/README.md +30 -102
  2. package/cli/README.md +38 -25
  3. package/cli/app-address.mjs +2 -0
  4. package/cli/business/api.mjs +2 -1
  5. package/cli/business/choices.mjs +1 -1
  6. package/cli/business/command.mjs +36 -25
  7. package/cli/business/connect.mjs +1 -1
  8. package/cli/business/lease.mjs +0 -9
  9. package/cli/business/local-commands.mjs +1 -18
  10. package/cli/business/outbound.mjs +2 -14
  11. package/cli/business/questions.mjs +85 -48
  12. package/cli/business/service.mjs +1 -24
  13. package/cli/business/setup-command.mjs +33 -26
  14. package/cli/business/state.mjs +2 -2
  15. package/cli/business/supervisor.mjs +26 -91
  16. package/cli/companion/command.mjs +2 -0
  17. package/cli/demo-native.mjs +1 -1
  18. package/cli/deploy-command.mjs +5 -4
  19. package/cli/deploy-inputs.mjs +1 -1
  20. package/cli/deploy.mjs +6 -4
  21. package/cli/parse.mjs +2 -1
  22. package/cli/production-auth.mjs +16 -3
  23. package/cli/production-mail.mjs +18 -1
  24. package/cli/site.mjs +1 -1
  25. package/global/CHANGELOG.md +45 -0
  26. package/global/README.md +30 -102
  27. package/global/main.mjs +2 -0
  28. package/modules/container/adapters/d1-limits.mjs +2 -10
  29. package/modules/d1-transport/limits.d.mts +10 -0
  30. package/modules/d1-transport/limits.mjs +10 -0
  31. package/modules/demo-host/native/prepare.mjs +2 -1
  32. package/modules/deploy-kit/README.md +10 -0
  33. package/modules/deploy-kit/provider.mjs +18 -2
  34. package/modules/import-kit/schema/importers.schema.json +104 -2
  35. package/modules/import-kit/src/d1/README.md +13 -0
  36. package/modules/import-kit/src/d1/apply-reads.ts +48 -0
  37. package/modules/import-kit/src/d1/apply.ts +21 -8
  38. package/modules/import-kit/src/d1/history.ts +2 -2
  39. package/modules/import-kit/src/d1/jobs.ts +3 -1
  40. package/modules/import-kit/src/d1/retirement-scope.ts +2 -2
  41. package/modules/import-kit/src/d1/retirement-tally.ts +1 -0
  42. package/modules/import-kit/src/d1/retirement.ts +15 -5
  43. package/modules/import-kit/src/d1/types.ts +14 -0
  44. package/modules/import-kit/src/d1/wave-boundary.ts +33 -0
  45. package/modules/import-kit/src/d1/wave-retirement.ts +47 -0
  46. package/modules/import-kit/src/provenance/credentials.ts +14 -5
  47. package/modules/import-kit/src/status/evidence.ts +3 -1
  48. package/modules/import-kit/src/status/index.ts +17 -2
  49. package/modules/import-kit/src/status/schema.ts +8 -0
  50. package/modules/import-kit/src/status/types.ts +25 -4
  51. package/onboarding/adapter.mjs +7 -1
  52. package/onboarding/operator-installer.mjs +3 -1
  53. package/package.json +1 -1
  54. package/scripts/publish-check/README.md +20 -0
  55. package/scripts/publish-check/diagnostics.mjs +73 -0
  56. package/scripts/publish-check/slots.py +37 -7
  57. package/scripts/publish-check.mjs +64 -37
  58. package/cli/business/archive-task.mjs +0 -32
  59. package/cli/business/catchup-task.mjs +0 -42
  60. package/cli/business/export-inputs.mjs +0 -69
  61. package/cli/business/export-task.mjs +0 -17
  62. package/cli/business/setup-demo.mjs +0 -95
  63. package/cli/business/vendor-door.mjs +0 -231
  64. package/cli/business/vendors/README.md +0 -176
  65. package/cli/business/vendors/calendly.mjs +0 -80
  66. package/cli/business/vendors/common.mjs +0 -199
  67. package/cli/business/vendors/credential-names.mjs +0 -124
  68. package/cli/business/vendors/index.mjs +0 -86
  69. package/cli/business/vendors/pagerduty.mjs +0 -61
  70. package/cli/business/vendors/sentry.mjs +0 -85
  71. package/cli/business/vendors/sorry.mjs +0 -106
  72. package/cli/business/vendors/uptimerobot.mjs +0 -21
@@ -1,17 +0,0 @@
1
- import { withUploadedBundle, door, checkedPreview, plural } from './vendor-door.mjs';
2
-
3
- /** Perform a claimed export.vendor: the shipped adapter's bundle uploaded into
4
- * the app's import door, then the door's plan (a zero-write preview), then
5
- * completion with the door's upload_id and plan_id and the bundle's SHA-256.
6
- * Returns the line to say. */
7
- export function runExport({ lease, task, grant, directory, say, ownerPage }) {
8
- return withUploadedBundle({ lease, task, grant, directory, say,
9
- doing: (name, origin, keyed) => `Exporting ${name} through the shipped read-only adapter. ${keyed ? 'The key stays on this computer; records' : 'Records'} go only to the app's import door at ${origin}.` },
10
- async ({ origin, uploadId, bundle, fresh }) => {
11
- const preview = await door(await fresh('plan'), { uploadId }, lease.signal), { records, created, updated, unchanged, rejected } = checkedPreview(preview, bundle);
12
- // Identifiers only: Business reads that plan from the door with its own grants
13
- // and completes the task only if it is the plan of exactly this bundle.
14
- return { outputs: { upload_id: uploadId, plan_id: preview.planId, bundle_sha256: bundle.sha256 },
15
- said: `Import preview ready in ${origin}: ${plural(records, 'source record')}; ${created} to create, ${updated} to update, ${unchanged} unchanged, ${rejected} rejected. Nothing was imported: the owner reviews and approves this move in the browser: ${ownerPage}` };
16
- });
17
- }
@@ -1,95 +0,0 @@
1
- // Mirrored from runeditrun/platform 0261033177e8e05284c037369ee9c3a85922a8aa, scripts/business/demo.mjs.
2
- import { readFile } from 'node:fs/promises';
3
- const company = JSON.parse(await readFile(new URL('./setup-company.json', import.meta.url), 'utf8'));
4
- export const demoPolicy={schema:'rer-agent-policy/1',catalogue:'rer-agent-classes/1',rules:[
5
- {id:'internal',class:'standard',do:'autonomous'},
6
- {id:'context',class:'sensitive',do:'autonomous'},
7
- {id:'owner',class:'*',do:'approval',approver:['role:owner'],wait:'P1D'},
8
- ],spend:{none:true}};
9
-
10
- /** The only injectable boundary is HTTP. Tokens, cookies, policy envelopes and peer bodies never enter the receipt. */
11
- export async function setupDemo({origin,cookie,hosting='managed',waitSeconds=240,fetch:request=globalThis.fetch,now=Date.now,wait=ms=>new Promise(resolve=>setTimeout(resolve,ms))}) {
12
- const api=async(path,method='GET',body,token)=>{
13
- let response;
14
- try{response=await request(new URL(path,origin),{method,redirect:'manual',signal:AbortSignal.timeout(60000),headers:{Origin:origin,Cookie:cookie,'Content-Type':'application/json',...(token?{'X-RER-Demo-Seed-Token':token}:{})},...(body===undefined?{}:{body:JSON.stringify(body)})});}
15
- catch{throw Error('platform_transport_unavailable');}
16
- let answer;try{answer=await response.json();}catch{throw Error(`platform_http_${response.status}`);}
17
- if(!response.ok){const code=answer?.code;throw Error(typeof code==='string'&&/^[a-z0-9_]{1,100}$/.test(code)?code:`platform_http_${response.status}`);}
18
- return answer;
19
- };
20
- const businesses=(await api('/api/business')).businesses;
21
- let business=businesses.find(row=>row.name===company.name);
22
- if(!business){
23
- business=(await api('/api/business','POST',{name:company.name,default_hosting:hosting,executor_preference:hosting==='self_host'?'local':'managed'})).business;
24
- await api('/api/business/'+encodeURIComponent(business.id)+'/profile','PUT',company.profile);
25
- }
26
- if(business.default_hosting!==hosting)throw Error('existing_demo_hosting_differs');
27
- const root='/api/business/'+encodeURIComponent(business.id),initial=await api(root+'/demo');
28
- // Return exactly the same projection after the first successful run and on every repeat.
29
- if(initial.complete)return initial;
30
- const pending=initial.seeds.filter(seed=>seed.adopted&&!seed.complete);
31
- if(!pending.length)return initial;
32
- let policy=await api(root+'/agents/policy');
33
- if(policy.paused)throw Error('demo_is_paused_resume_as_owner');
34
- const errors=new Map(),credentials=new Map(),ready=pending.filter(seed=>seed.provisioned);
35
- let waiting=pending.filter(seed=>!seed.provisioned);
36
- if(waiting.length){
37
- const plan=await api(root+'/demo/plan','POST',{confirmed:true});
38
- if(plan.plan_id&&!plan.approved)await api(root+'/plans/'+encodeURIComponent(plan.plan_id)+'/approve','POST',{});
39
- const deadline=now()+waitSeconds*1000;
40
- do{
41
- await api(root+'/demo/advance','POST',{});
42
- const status=await api(root+'/demo'),apps=(await api(root+'/apps')).apps,next=[];
43
- for(const seed of waiting){
44
- const current=status.seeds.find(row=>row.app===seed.app),installed=apps.find(row=>row.app===seed.app);
45
- if(current?.provisioned)ready.push(current);
46
- else if(installed?.failure||installed?.stage==='failed')errors.set(seed.app,'M4 provisioning failed');
47
- else if(installed?.waits?.length||installed?.answers_needed?.length)errors.set(seed.app,'M4 setup needs hosting, payment, domain or app answers');
48
- else next.push(seed);
49
- }
50
- waiting=next;
51
- if(waiting.length&&now()<deadline)await wait(Math.min(3000,Math.max(0,deadline-now())));
52
- }while(waiting.length&&now()<deadline);
53
- for(const seed of waiting)errors.set(seed.app,'Run the same command to resume provisioning');
54
- }
55
- const eligible=[];
56
- for(const seed of ready){
57
- try{
58
- // This is the shared Business sender, not a demo-specific settings signer or transport.
59
- const settings=await api(root+'/settings/deliver','POST',{});
60
- const delivery=settings.deliveries.find(row=>row.installation_id===seed.installation_id);
61
- if(!delivery||delivery.state!=='delivered')throw Error(delivery?.code??'settings_not_delivered');
62
- if(policy.revision&&!seed.no_policy_refused)throw Error('no_policy_probe_requires_fresh_demo');
63
- const issued=await api(root+'/agents/seed-token','POST',{seed:seed.app,installation_id:seed.installation_id,
64
- agent:{id:'demo:'+business.id,name:'Synthetic demo setup'},scopes:seed.scopes});
65
- credentials.set(seed.app,issued.access_token);
66
- if(!policy.revision&&!seed.no_policy_refused)await api(root+'/demo/apps/'+encodeURIComponent(seed.app)+'/door','POST',{phase:'unset'},issued.access_token);
67
- eligible.push(seed);
68
- }catch(error){errors.set(seed.app,error.message);}
69
- }
70
- if(eligible.length&&!policy.revision){
71
- let draft=policy.draft;
72
- if(draft&&JSON.stringify(draft.document)!==JSON.stringify(demoPolicy))throw Error('existing_policy_draft_requires_owner_review');
73
- if(!draft)draft=(await api(root+'/agents/policy/revisions','POST',{document:demoPolicy})).revision;
74
- await api(root+'/agents/policy/revisions/'+draft.revision+'/confirm','POST',{digest:draft.document_sha256});
75
- policy=await api(root+'/agents/policy');
76
- }
77
- const seeded=[];
78
- for(const seed of eligible){
79
- try{await api(root+'/demo/apps/'+encodeURIComponent(seed.app)+'/door','POST',{phase:'seed'},credentials.get(seed.app));seeded.push(seed);}
80
- catch(error){errors.set(seed.app,error.message);}
81
- }
82
- if(seeded.length){
83
- await api(root+'/pause','POST',{paused:true});
84
- let allPaused=true;
85
- for(const seed of seeded){
86
- try{await api(root+'/demo/apps/'+encodeURIComponent(seed.app)+'/door','POST',{phase:'paused'},credentials.get(seed.app));}
87
- catch(error){allPaused=false;errors.set(seed.app,error.message);}
88
- }
89
- if(allPaused)await api(root+'/pause','POST',{paused:false});
90
- }
91
- credentials.clear();
92
- const receipt=await api(root+'/demo');
93
- for(const seed of receipt.seeds)if(!seed.complete&&errors.has(seed.app))seed.cause=errors.get(seed.app);
94
- return receipt;
95
- }
@@ -1,231 +0,0 @@
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 message = vendor === 'calendly' ? 'Waiting for the owner: this tool needs its folder of files shared with Business.'
93
- : `Waiting for the owner to confirm ${inputNeeds[vendor]} in Business.`;
94
- throw new ExportWaiting(message, 'configuration_required');
95
- }
96
-
97
- /** One RER-signed import grant for one door request. `review` asks for a
98
- * catch-up plan grant without the owner's standing approval; a plan grant
99
- * Business minted under that approval says so with `catchup: 'bounded'`. */
100
- async function doorGrant(lease, action, origin, vendor, { review = false } = {}) {
101
- const grant = await lease.importGrant(action, review ? { review: true } : {});
102
- if (!grant || grant.action !== action || grant.destination !== new URL(`/api/rer/import/${action}`, origin).href
103
- || typeof grant.authorization !== 'string' || grant.authorization.length > 8192 || !/^Bearer [A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/.test(grant.authorization)
104
- || !VENDORS.includes(grant.namespace) || vendor && grant.namespace !== vendor || !(Date.parse(grant.expires_at) > Date.now())
105
- || Object.hasOwn(grant, 'catchup') && (grant.catchup !== 'bounded' || action !== 'plan' || review)) throw Error('Business returned an invalid import grant.');
106
- return grant;
107
- }
108
-
109
- /** POST one request to the app's door. Only the door's error code is ever
110
- * shown: its bodies can hold vendor records. */
111
- export async function door(grant, body, signal) {
112
- const action = grant.action;
113
- let response;
114
- try {
115
- response = await fetch(grant.destination, { method: 'POST', redirect: 'error', body: JSON.stringify(body),
116
- headers: { authorization: grant.authorization, 'content-type': 'application/json' }, signal: AbortSignal.any([signal, AbortSignal.timeout(30_000)]) });
117
- } catch (error) {
118
- if (signal.aborted) throw signal.reason;
119
- const code = error?.cause?.code ?? error?.code;
120
- 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'}).`);
121
- }
122
- const chunks = []; let size = 0;
123
- for await (const chunk of response.body ?? []) {
124
- size += chunk.byteLength;
125
- 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.`); }
126
- chunks.push(chunk);
127
- }
128
- let result = null;
129
- try { result = JSON.parse(Buffer.concat(chunks).toString('utf8')); } catch { /* Judged below. */ }
130
- if (!response.ok) {
131
- // A door code is snake_case, sometimes with one named reason (`catchup_requires_proposal:source_records_gone`).
132
- 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;
133
- throw Object.assign(Error(`The app's import door refused the ${action} request (HTTP ${response.status}${doorCode ? `: ${doorCode}` : ''}).`), { doorStatus: response.status, doorCode });
134
- }
135
- if (!result || typeof result !== 'object' || Array.isArray(result)) throw Error(`The app's import door returned an invalid ${action} answer.`);
136
- return result;
137
- }
138
-
139
- /** Run the shipped adapter into a private 0600 bundle file, checking every
140
- * item with the outbound detector before it is written. */
141
- async function exportBundle({ vendor, key = null, inputs, path, quota, signal }) {
142
- await unlink(path).catch(error => { if (error.code !== 'ENOENT') throw error; });
143
- const file = await open(path, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
144
- const digest = createHash('sha256'); let size = 0;
145
- try {
146
- for await (const item of exportVendor(vendor, { key, inputs, signal })) {
147
- assertChunk(item.bytes, key ? [key] : []);
148
- size += item.bytes.length;
149
- if (size > quota) throw Error(`Business vendor export is larger than the app's import door accepts (${quota} bytes). Nothing was uploaded.`);
150
- digest.update(item.bytes);
151
- await file.write(item.bytes);
152
- }
153
- await file.sync();
154
- } catch (error) {
155
- if (!(error instanceof VendorExportError)) throw error;
156
- if (error.code === 'HTTP_REFUSED' && [401, 403].includes(error.status) && key) {
157
- throw new ExportWaiting(`${vendorNames[vendor]} refused the stored read-only key (HTTP ${error.status}). To replace it, ${keyStep(vendor)}`, 'owner_required');
158
- }
159
- throw Error(`${vendorNames[vendor]} export stopped (${error.code}${error.status ? `, HTTP ${error.status}` : ''}). Nothing was uploaded.`);
160
- } finally { await file.close(); }
161
- if (!size) throw Error(`${vendorNames[vendor]} export produced nothing to upload.`);
162
- return { size, sha256: digest.digest('hex') };
163
- }
164
-
165
- async function readChunk(path, index, size) {
166
- const file = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW);
167
- try {
168
- const length = Math.min(CHUNK_BYTES, size - index * CHUNK_BYTES), bytes = Buffer.alloc(length);
169
- const { bytesRead } = await file.read(bytes, 0, length, index * CHUNK_BYTES);
170
- if (bytesRead !== length) throw Error('Business vendor export bundle changed while uploading.');
171
- return bytes;
172
- } finally { await file.close(); }
173
- }
174
-
175
- /** A door plan's preview of exactly this bundle: its ids and the door's counts. */
176
- export function checkedPreview(preview, bundle) {
177
- const summary = preview.summary ?? {}, [records, created, updated, unchanged, gone] = ['sourceRecords', 'created', 'updated', 'unchanged', 'gone'].map(name => count(summary[name]));
178
- const rejected = count(preview.counts?.rejected);
179
- if (typeof preview.planId !== 'string' || !DOOR_ID.test(preview.planId) || !/^[a-f0-9]{64}$/.test(preview.fingerprint ?? '')
180
- || preview.bundleSha256 !== bundle.sha256 || [records, created, updated, unchanged, gone, rejected].includes(null)) throw Error("The app's import door returned an invalid preview.");
181
- return { records, created, updated, unchanged, gone, rejected };
182
- }
183
-
184
- /**
185
- * The shared start of a claimed vendor door task: the claimed grant's door, the
186
- * vendor its first grant names, the owner's key from the OS store, the shipped
187
- * adapter into a private 0600 bundle, then the bundle in 64 KiB chunks, each with
188
- * a fresh grant. A vendor that needs no key (a public status page) reads none.
189
- * `finish` gets the uploaded bundle and returns `{outputs, said}`:
190
- * the task then completes with those outputs (identifiers only, which Business
191
- * checks against the door itself) and `said` is the line to say. The bundle file
192
- * is removed on every exit. `doing(name, origin, keyed)` is said first.
193
- */
194
- export async function withUploadedBundle({ lease, task, grant: claimedGrant, directory, say, doing }, finish) {
195
- const signal = lease.signal, { origin, quota } = destination(task, claimedGrant);
196
- // The first grant names the vendor (its namespace); it then carries chunk 0.
197
- let spare = await doorGrant(lease, 'uploads', origin, null);
198
- const vendor = spare.namespace, name = vendorNames[vendor], capability = VENDOR_CAPABILITIES[vendor];
199
- const fresh = async (action, options) => {
200
- if (action === 'uploads' && spare && Date.parse(spare.expires_at) - Date.now() > 60_000) { const grant = spare; spare = null; return grant; }
201
- spare = null;
202
- return doorGrant(lease, action, origin, vendor, options);
203
- };
204
- const inputs = adapterInputs(vendor, task);
205
- let key = keyed(vendor) ? await createCredentialStore().get(vendorHandle(vendor)) : null;
206
- 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 });
207
- const path = join(directory, `export-${hash(task.id).slice(0, 32)}.bundle`);
208
- try {
209
- say(doing(name, origin, keyed(vendor)));
210
- let bundle;
211
- try { bundle = await exportBundle({ vendor, key, inputs, path, quota, signal }); } finally { key = undefined; }
212
- const total = Math.ceil(bundle.size / CHUNK_BYTES);
213
- let uploadId;
214
- for (let index = 0; index < total; index++) {
215
- signal.throwIfAborted();
216
- const bytes = await readChunk(path, index, bundle.size);
217
- const result = await door(await fresh('uploads'), { ...(uploadId ? { uploadId } : {}), name: capability.output, bundleSha256: bundle.sha256,
218
- totalBytes: bundle.size, totalChunks: total, index, chunkSha256: hash(bytes), base64: bytes.toString('base64') }, signal);
219
- if (typeof result.uploadId !== 'string' || !DOOR_ID.test(result.uploadId) || uploadId && result.uploadId !== uploadId
220
- || result.bundleSha256 !== bundle.sha256 || index === total - 1 && result.complete !== true) throw Error("The app's import door returned an invalid upload answer.");
221
- uploadId = result.uploadId;
222
- await lease.checkpointSaved({ page: index + 1, total, bytes_done: Math.min((index + 1) * CHUNK_BYTES, bundle.size), progress: Math.floor((index + 1) / total * 90) });
223
- }
224
- const { outputs, said } = await finish({ vendor, name, origin, uploadId, bundle, fresh });
225
- await lease.checkpointSaved({ page: total, total, bytes_done: bundle.size, progress: 100 });
226
- await lease.complete(outputs);
227
- return said;
228
- } finally {
229
- await unlink(path).catch(error => { if (error.code !== 'ENOENT') throw error; });
230
- }
231
- }
@@ -1,176 +0,0 @@
1
- # Shipped vendor exports
2
-
3
- To bring existing data into a seed, sign in as the owner and use its import
4
- screen. First step: open this path on the destination app:
5
-
6
- ```text
7
- /app/import
8
- ```
9
-
10
- Upload a supported source export, review the plan and its differences, then
11
- approve that exact plan to apply it. Reconcile the result against native data;
12
- use Undo from the same history when needed. Base's reference accepts people JSON
13
- here, not installation `.rer` archives. Editions adopt this same door
14
- with their own supported readers and native adapters.
15
-
16
- `exportVendor(vendor, {key, inputs, checkpoint, signal})` is an async generator.
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. 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,
21
- caller origins, arbitrary paths and credential-bearing pagination are refused.
22
- No export runs merely by importing these modules. No account export was run
23
- during implementation.
24
-
25
- `VENDORS` is the closed vendor enum (`sentry`, `uptimerobot`, `pagerduty`,
26
- `calendly`, `sorry`). `VENDOR_CAPABILITIES` describes the adapter,
27
- required vendor-key capability, native importer format, layout and read scopes.
28
- These adapters cannot verify that a supplied key itself has read-only scope;
29
- the owner must create the documented read-only key where the vendor offers one.
30
-
31
- ## Transport and resume
32
-
33
- Upload bytes only to the task grant's seed destination. They contain private,
34
- untrusted vendor data and must never appear in CLI output, events or model
35
- context. The caller applies its outbound secret detector and computes SHA-256,
36
- enforces the grant quota, and atomically acknowledges the item before persisting
37
- its checkpoint. Checkpoints contain progress, source IDs, cursor strings, file
38
- metadata and hashes, never response records. They are less than 128 KiB.
39
-
40
- An interrupted upload is retried under the same task/fence, deterministic name
41
- and SHA-256. Resume with exactly the acknowledged checkpoint and original
42
- inputs; object key ordering does not affect input identity. An unacknowledged
43
- page may be fetched again, so source edits during interruption can change it:
44
- the seed must reject a conflicting hash under the same name, and the owner must
45
- restart that export. This is an API export, not a vendor snapshot transaction.
46
-
47
- For `layout: 'concatenate'`, concatenate the numbered `000001.part` items in
48
- sequence to the metadata's `output` filename. Some PagerDuty items have empty
49
- bytes: they checkpoint schedule discovery and must still be acknowledged.
50
- Fragments are deliberately not standalone JSON. For `layout: 'files'`, retain
51
- the given filenames; Calendly ends with `manifest.json`, matching Dial's folder
52
- import. Never treat a partial stream as a completed bundle.
53
-
54
- Every item is at most 1 MiB. Exports are bounded to 1,000 requests, one request
55
- per second, 30 seconds per request, 2 MiB/499 API records for Sentry,
56
- 512 KiB/500 records for PagerDuty, and 8 MiB/2,500 records for UptimeRobot and
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.
59
- Limits stop rather than truncate. AbortSignal stops waits, HTTP reads and
60
- emission. HTTP errors contain only a fixed code and numeric status; network,
61
- parsing and unexpected errors never expose response text, URLs or key values.
62
- 429 stops with `RATE_LIMITED`; there is no hidden retry loop.
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
-
70
- ## Credentials in responses
71
-
72
- Every adapter strips credential values from a parsed response before it emits
73
- bytes for upload, keeping the record, by the same rules as the seed's import
74
- door. A field whose name's parts are a credential word or phrase (`apiKey`,
75
- `httpPassword`, `http_password`, `client_secret`, `X-Api-Key`, `integration_key`,
76
- `webhook_url`, `secret_key`, `x-functions-key`, `Ocp-Apim-Subscription-Key`,
77
- `pwd`, `X-Auth` and the like), the `value` of a `{name|key, value}` pair
78
- naming one (`{name: 'Authorization', value}`), or the value of such a
79
- `[name, value]` pair in a list of them (Sentry's header tuples), becomes
80
- `"[removed]"`. A plural name (`apiKeys`, `tokens`) counts only when it holds
81
- text, so a count such as `tokens: 1500` stays. A URL of any scheme keeps a
82
- marker where each credential was: its user name and password become `removed@`,
83
- and the value of each credential query or fragment parameter (`api_key`,
84
- `access_token`, `sig` and the like) becomes `removed`
85
- (`?api_key=removed&region=eu`, `#access_token=removed`), except the adapter's
86
- own validated pagination keys (`page_token`). The door drops each marker and
87
- reports it per record as `CREDENTIAL_REMOVED`, so the owner sees which record
88
- lost a credential. Null, booleans, empty strings and masks such as `****` are
89
- not credentials and stay as they are. Names are matched by whole parts
90
- (camelCase, `_`, `-`, digits), so names that merely contain such letters
91
- (`keyword`, `monkey`, `author`, `signal`, `design`, `primaryKey`) are not
92
- credential names and a `?keyword=up` URL stays intact. `Signature` and
93
- `Session-Id` count only as header names (a key under `headers`, a tuple, a
94
- `{name|key, value}` pair in a header list), so an agent's `signature` field and
95
- Help Scout's `customFields: [{name: 'Session ID', value}]` stay;
96
- `auth` and `credentials` count only when they hold text naming no scheme or mode,
97
- and an object under them loses only its own credential fields
98
- (`auth: {type: 'oauth2', token: "[removed]"}`) and a `value`, `pass`, `pw` or
99
- `secret…` member (Keycloak's `credentials: [{type: 'password', value: "[removed]"}]`).
100
- `passphrase`, `jwt`, `JSESSIONID` and `PHPSESSID` count everywhere. Query and fragment keys also
101
- count documented API key names such as `token_auth`, `application_key`,
102
- `user_key` and `hapikey`.
103
- Pagination is read from the response as received, so a credential-bearing
104
- pagination link is still refused.
105
-
106
- ## Inputs and native coverage
107
-
108
- * `sentry`: `organization: {id, slug, region: 'us'|'de'}`, `start`, `end`, and
109
- optional `events: [{project, eventId}]`. Self-hosted origins are unsupported.
110
- Projects, releases and all-status issues are paginated; issues use the current
111
- organization issues API filtered by project and window. Event details are
112
- fetched only for the explicitly selected IDs, must fall in the window and
113
- form a complete local cursor chain. A fixed omissions list declares that all
114
- other event history and unsupported Sentry features remain outside the export.
115
- Projects/releases are not time-filtered. Spool counts one manifest record in
116
- addition to the API records. At most 49 projects fit its 100-collection bound.
117
- * `uptimerobot`: no additional inputs. Exports v3 monitor response pages,
118
- including their original `data` and `nextLink` envelopes. History, contacts
119
- and status pages are not fetched.
120
- * `pagerduty`: `start`/`end` (or `since`/`until`). Exports users, schedule details
121
- with layers/final coverage, overrides for the window and escalation policies.
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.
126
- Overrides retain full boundaries with `overflow=true` and add `schedule_id`,
127
- as Oncall's documented bundle requires. Incident history and paging
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.
140
- * `calendly`: optional `asOf` timestamp (recommended for a repeatable catch-up).
141
- An omitted timestamp is captured at first invocation and retained on resume.
142
- Downloads the current user, event types, availability schedules, per-type
143
- availability, future scheduled events including cancellations, and invitees.
144
- Like Dial's downloader, this is the current user's scope, at most 100 event
145
- types and 500 scheduled events. Every original page receives a manifest hash.
146
- No past booking history or arbitrary referenced resource is fetched.
147
-
148
- ## Primary-source provenance
149
-
150
- Implementation preserves the response formats and flow in these seed sources;
151
- it adds streaming, bounded resume and fixed-origin transport rather than running
152
- their file-writing command wrappers.
153
-
154
- * [Dial downloader at 6014c99875dd002545e194ab23a7852d30e94e01](https://github.com/just-every/run-dial/blob/6014c99875dd002545e194ab23a7852d30e94e01/scripts/move-in/download.mjs).
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`).
158
- * [Oncall guide at 4f928effc3ce735f3d246bb8a3c4bbb8436cae6b](https://github.com/just-every/run-oncall/blob/4f928effc3ce735f3d246bb8a3c4bbb8436cae6b/docs/move-in.md).
159
- * Spool's proposal-cited `app/docs/SENTRY-SWITCHING.md` and
160
- `app/src/domain/sentry-import/source.ts`, local source commit
161
- `39cbaf67de3bc8174bf941a6922bb92ff31110de`. Spool supplied a bundle contract,
162
- not an existing downloader. This adapter implements that contract against
163
- the official APIs below.
164
- * Sentry: [projects](https://docs.sentry.io/api/organizations/list-an-organizations-projects/),
165
- [releases](https://docs.sentry.io/api/releases/list-an-organizations-releases/),
166
- [organization issues](https://docs.sentry.io/api/events/list-an-organizations-issues/),
167
- [event details](https://docs.sentry.io/api/events/retrieve-an-event-for-a-project/),
168
- [pagination](https://docs.sentry.io/api/pagination/),
169
- [regional domains](https://docs.sentry.io/api/).
170
- * [PagerDuty overrides](https://docs.pagerduty.com/developer/api/reference/rest/schedules/list-schedule-overrides)
171
- is a window-bounded response, not an offset-paginated list.
172
-
173
- Seed documentation and official APIs were inspected on 16 October 2026.
174
- These sources document shapes; no real-account parity or migration success is
175
- claimed. Parent integration must provide seed assembly and transport under the
176
- actual import grant protocol, plus network-edge acceptance coverage.
@@ -1,80 +0,0 @@
1
- import { object, list, id, timestamp, reference, cursor, assertCount, hash, shape, fail, withoutCredentials } from './common.mjs';
2
-
3
- export const origin = 'https://api.calendly.com';
4
- const queries = ['user','count','event_type','min_start_time','page_token'];
5
- export const route = url => /^\/(?:users\/me|event_types|user_availability_schedules|event_type_availability_schedules|scheduled_events(?:\/[a-zA-Z0-9_-]+\/invitees)?)$/u.test(url.pathname) && [...url.searchParams.keys()].every(x => queries.includes(x));
6
- function identity(uri, kind) {
7
- const url = reference(uri, origin, new RegExp(`^/${kind}/[a-zA-Z0-9_-]+$`, 'u'));
8
- return id(url.pathname.split('/').at(-1));
9
- }
10
- function nextToken(body, path, previous) {
11
- object(body.pagination);
12
- const next = body.pagination.next_page;
13
- if (next == null) {
14
- if (body.pagination.next_page_token != null) return cursor(body.pagination.next_page_token);
15
- return null;
16
- }
17
- const url = reference(next, origin, new RegExp(`^${path}$`, 'u'), queries);
18
- const token = cursor(url.searchParams.get('page_token'));
19
- if (!token || token === previous) fail('INVALID_PAGINATION');
20
- return token;
21
- }
22
- export async function* run(ctx) {
23
- const s = ctx.state ?? { phase: 0, user: null, types: [], events: [], index: 0, token: null, seen: [], files: [], asOf: timestamp(ctx.inputs.asOf ?? new Date().toISOString()) };
24
- shape(s, ['phase','user','types','events','index','token','seen','files','asOf']);
25
- assertCount(s.phase, 7); assertCount(s.index, 500); timestamp(s.asOf); cursor(s.token);
26
- if (!Array.isArray(s.types) || s.types.length > 100 || !Array.isArray(s.events) || s.events.length > 500 || !Array.isArray(s.files) || s.files.length > 600 || !Array.isArray(s.seen) || s.seen.length > 600) fail('INVALID_CHECKPOINT');
27
- s.types.forEach(id); s.events.forEach(id); if (s.user !== null) id(s.user);
28
- s.seen.forEach(cursor);
29
- for (const file of s.files) {
30
- shape(file, ['name','resource','page','size','sha256','capturedAt']);
31
- if (typeof file.name !== 'string' || !/^(?:user|event_types|schedules|event_availability|scheduled_events|invitees)-\d{6}\.json$/u.test(file.name) || !['user','event_types','schedules','event_availability','scheduled_events','invitees'].includes(file.resource) || !/^[a-f0-9]{64}$/u.test(file.sha256) || file.capturedAt !== s.asOf) fail('INVALID_CHECKPOINT');
32
- assertCount(file.page, 600); assertCount(file.size, 1024 * 1024);
33
- }
34
- while (s.phase < 7) {
35
- if (s.phase === 3 && s.index >= s.types.length) { s.phase = 4; s.index = 0; }
36
- if (s.phase === 5 && s.index >= s.events.length) s.phase = 6;
37
- if (s.phase === 6) {
38
- s.phase = 7;
39
- yield ctx.item(JSON.stringify({ version: 1, capturedAt: s.asOf, files: s.files }) + '\n', s, 'manifest.json');
40
- break;
41
- }
42
- const resource = ['user','event_types','schedules','event_availability','scheduled_events','invitees'][s.phase];
43
- const path = ['/users/me','/event_types','/user_availability_schedules','/event_type_availability_schedules','/scheduled_events',`/scheduled_events/${s.events[s.index]}/invitees`][s.phase];
44
- const query = new URLSearchParams();
45
- if (s.phase !== 0) query.set('count', '100');
46
- if ([1,2,4].includes(s.phase)) query.set('user', `${origin}/users/${id(s.user)}`);
47
- if (s.phase === 3) query.set('event_type', `${origin}/event_types/${id(s.types[s.index])}`);
48
- if (s.phase === 4) query.set('min_start_time', s.asOf);
49
- if (s.token !== null) query.set('page_token', s.token);
50
- const { body } = await ctx.get(path + (query.size ? `?${query}` : ''));
51
- object(body);
52
- const rows = s.phase === 0 ? [object(body.resource)] : list(body.collection);
53
- if (rows.some(row => Buffer.byteLength(JSON.stringify(row)) > 512 * 1024)) fail('RECORD_BYTE_LIMIT');
54
- ctx.records(rows.length);
55
- if (s.phase === 0) s.user = identity(rows[0].uri, 'users');
56
- if (s.phase === 1 || s.phase === 4) {
57
- const values = s.phase === 1 ? s.types : s.events;
58
- const kind = s.phase === 1 ? 'event_types' : 'scheduled_events';
59
- for (const row of rows) {
60
- const value = identity(row.uri, kind);
61
- if (values.includes(value)) fail('DUPLICATE_ID');
62
- values.push(value);
63
- }
64
- if (values.length > (s.phase === 1 ? 100 : 500)) fail('RECORD_LIMIT');
65
- }
66
- const next = s.phase === 0 ? null : nextToken(body, path, s.token);
67
- if (next !== null && (next === s.token || s.seen.includes(next))) fail('PAGINATION_CYCLE');
68
- const name = `${resource}-${String(s.files.length + 1).padStart(6,'0')}.json`;
69
- const bytes = Buffer.from(JSON.stringify(withoutCredentials(body, queries)) + '\n');
70
- if (s.files.length >= 600) fail('FILE_LIMIT');
71
- s.files.push({ name, resource, page: s.seen.length + 1, size: bytes.length, sha256: hash(bytes), capturedAt: s.asOf });
72
- s.token = next;
73
- if (next === null) {
74
- s.seen = [];
75
- if (s.phase === 3 || s.phase === 5) s.index++;
76
- else { s.phase++; s.index = 0; }
77
- } else s.seen.push(next);
78
- yield ctx.item(bytes, s, name);
79
- }
80
- }