@runeditrun/rer 0.2.19 → 0.2.20
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 +7 -7
- package/cli/README.md +22 -21
- package/cli/adapter.mjs +5 -0
- package/cli/container.mjs +7 -2
- package/cli/contract.mjs +3 -4
- package/cli/delivery-declarations.mjs +36 -0
- package/cli/demo-host.mjs +2 -2
- package/cli/demo.mjs +16 -5
- package/cli/deploy-command.mjs +3 -0
- package/cli/deploy.mjs +4 -1
- package/cli/detached-server.mjs +2 -2
- package/cli/dev-identity.mjs +1 -1
- package/cli/export.mjs +1 -1
- package/cli/inspect.mjs +13 -13
- package/cli/lifecycle.mjs +16 -49
- package/cli/listen.mjs +31 -0
- package/cli/local.mjs +12 -18
- package/cli/main.mjs +5 -0
- package/cli/managed-server.mjs +26 -44
- package/cli/output.mjs +1 -1
- package/cli/parse.mjs +3 -3
- package/cli/port.mjs +20 -20
- package/cli/production-auth.mjs +38 -0
- package/cli/server-proxy.mjs +2 -6
- package/cli/server-registry.mjs +7 -2
- package/cli/setup-input.mjs +3 -0
- package/global/CHANGELOG.md +9 -0
- package/global/README.md +7 -7
- package/global/cli/install.mjs +4 -28
- package/global/cli/path-link.mjs +25 -21
- package/global/launch/dev.mjs +1 -1
- package/global/launch/facts.mjs +11 -14
- package/global/launch/failure.mjs +20 -0
- package/global/launch/render.mjs +2 -6
- package/global/launch/worker.mjs +3 -3
- package/global/main.mjs +1 -1
- package/modules/container/build.mjs +2 -2
- package/modules/container/demo-egress.mjs +35 -0
- package/modules/container/worker-engine.mjs +3 -3
- package/modules/d1-transport/index.d.mts +9 -0
- package/modules/d1-transport/index.mjs +124 -0
- package/modules/delivery-producer/bindings.mjs +140 -0
- package/modules/delivery-producer/declarations.mjs +49 -0
- package/modules/demo/README.md +34 -0
- package/modules/demo/effects.mjs +73 -0
- package/modules/demo/index.d.mts +15 -0
- package/modules/demo/index.mjs +63 -0
- package/modules/demo/label.d.mts +2 -0
- package/modules/demo/label.mjs +24 -0
- package/modules/demo/responses.mjs +26 -0
- package/modules/demo/sockets.mjs +13 -0
- package/modules/demo/vite.d.mts +2 -0
- package/modules/demo/vite.mjs +19 -0
- package/modules/demo-host/README.md +5 -1
- package/modules/demo-host/container.mjs +4 -4
- package/modules/demo-host/pages.mjs +1 -1
- package/modules/demo-host/worker.mjs +1 -1
- package/modules/deploy-kit/owner.mjs +2 -2
- package/modules/deploy-kit/r2-objects.mjs +8 -5
- package/modules/job-queue/storage.mjs +4 -1
- package/modules/mail/README.md +19 -86
- package/modules/mail/src/core/validation.mjs +0 -1
- package/modules/mail/src/development/index.d.mts +1 -6
- package/modules/mail/src/development/index.mjs +3 -16
- package/modules/operator-auth/README.md +10 -9
- package/modules/operator-auth/csp.mjs +1 -2
- package/modules/operator-auth/dev/cli-session.mjs +32 -0
- package/modules/operator-auth/dev/index.mjs +18 -11
- package/modules/operator-auth/identity/email-link/index.mjs +3 -0
- package/modules/operator-auth/page.mjs +1 -1
- package/modules/operator-auth/signin/index.d.mts +1 -1
- package/modules/portability/README.md +6 -0
- package/modules/portability/catalogue.mjs +1 -1
- package/modules/portability/copies.mjs +17 -2
- package/modules/portability/index.mjs +2 -0
- package/modules/portability/storage.mjs +5 -1
- package/onboarding/README.md +8 -11
- package/onboarding/adapter-auth.mjs +6 -38
- package/onboarding/adapter-labels.mjs +1 -1
- package/onboarding/adapter.mjs +8 -11
- package/onboarding/app-fetch.mjs +1 -1
- package/onboarding/dependency-approval.mjs +5 -15
- package/onboarding/dev-identity.mjs +1 -1
- package/onboarding/operator-install.mjs +6 -7
- package/onboarding/operator-installer.mjs +5 -5
- package/onboarding/operator-prerequisites.mjs +4 -5
- package/onboarding/port-probe.mjs +38 -0
- package/onboarding/process-diagnostics.mjs +36 -20
- package/onboarding/server.mjs +1 -1
- package/onboarding/ui/app.js +1 -1
- package/operations/README.md +3 -0
- package/package.json +4 -2
- package/scripts/publish-check/public_hygiene.py +31 -10
- package/modules/mail/src/development/viewer-html.mjs +0 -42
- package/modules/mail/src/development/viewer.mjs +0 -72
- package/modules/operator-auth/dev/badge.mjs +0 -44
package/modules/mail/README.md
CHANGED
|
@@ -19,11 +19,11 @@ const result = await sender.send({
|
|
|
19
19
|
|
|
20
20
|
## Adopting
|
|
21
21
|
|
|
22
|
-
A seed copies this module's runtime files byte for byte, to the same paths under its root, and records them in its source lock. Every seed copies the same one module:
|
|
22
|
+
A seed copies this module's runtime files byte for byte, to the same paths under its root, and records them in its source lock. Every seed copies the same one module: the remote transports and an explicit development suppression path. The same facade also supports optional signed Messaging links.
|
|
23
23
|
|
|
24
24
|
### Mail
|
|
25
25
|
|
|
26
|
-
Every seed copies these files. `index.mjs` loads all of them, including the
|
|
26
|
+
Every seed copies these files. `index.mjs` loads all of them, including the development path below, so none can be left out.
|
|
27
27
|
|
|
28
28
|
```text
|
|
29
29
|
modules/mail/LICENSE
|
|
@@ -71,9 +71,9 @@ modules/mail/src/doctor/receive.mjs
|
|
|
71
71
|
modules/mail/src/doctor/records.mjs
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
###
|
|
74
|
+
### Development delivery
|
|
75
75
|
|
|
76
|
-
|
|
76
|
+
Copy the development entry with the facade. Its sender validates messages and silently suppresses them. Preserve the schema and storage reader when an installation has historical development mail.
|
|
77
77
|
|
|
78
78
|
```text
|
|
79
79
|
modules/mail/src/development/
|
|
@@ -95,11 +95,10 @@ Sign-in mail is the seed's own wiring around the two things above, not a copy of
|
|
|
95
95
|
|
|
96
96
|
```text
|
|
97
97
|
default-seed/src/core/platform/auth/mail.server.mjs
|
|
98
|
-
default-seed/src/core/platform/auth/outbox.server.mjs
|
|
99
98
|
default-seed/migrations/core/0004_development_outbox.sql
|
|
100
99
|
```
|
|
101
100
|
|
|
102
|
-
`mail.server.mjs` builds the production sender from `MAIL_PROVIDER` (`resend`, `sendgrid` or `cloudflare`)
|
|
101
|
+
`mail.server.mjs` builds the production sender from `MAIL_PROVIDER` (`resend`, `sendgrid` or `cloudflare`). Explicit development and demo configuration suppress mail before selecting any configured remote sender. The migration preserves historical local messages.
|
|
103
102
|
|
|
104
103
|
### Former sendgrid-email API
|
|
105
104
|
|
|
@@ -121,7 +120,7 @@ These are for developing the module itself or documentation. A seed may keep any
|
|
|
121
120
|
The provider is explicit: `sendgrid`, `resend`, `cloudflare`, `rer`, `messaging`, or `development`.
|
|
122
121
|
`mode` is required (`production`, `development`, or `test`). Remote providers require `apiKey`; Cloudflare additionally requires a 32-hex `accountId`. A remote provider in test/development mode still makes a real provider request unless the caller explicitly supplies a test fetch. Missing credentials, validation errors, or provider failure never select another provider. Config and messages reject unknown fields so requested features cannot silently disappear.
|
|
123
122
|
|
|
124
|
-
`createMailSender(config, dependencies?)` returns `{send(message)}`. Dependencies are optional standard `fetch`,
|
|
123
|
+
`createMailSender(config, dependencies?)` returns `{send(message)}`. Dependencies are optional standard `fetch`, `clock: () => epochMilliseconds`, and `timeoutMilliseconds` (a positive safe integer bounding each remote attempt; the default is 15,000). Production normally uses global fetch. Direct provider endpoints are fixed; `rer` uses its assigned relay URL. No retry or automatic replay exists. The sender snapshots configuration at construction and the message at submission.
|
|
125
124
|
|
|
126
125
|
### Managed mail through RER
|
|
127
126
|
|
|
@@ -175,7 +174,7 @@ Resend checks a conservative 40,000,000-byte total email budget before Base64 or
|
|
|
175
174
|
JSON encoding, including UTF-8 bodies, all recipients/headers, aggregate Base64
|
|
176
175
|
attachments and MIME overhead. Its final JSON request is capped at 39,000,000
|
|
177
176
|
UTF-8 bytes. Oversize input throws `MailValidationError` with fixed code
|
|
178
|
-
`resend_message_too_large` before
|
|
177
|
+
`resend_message_too_large` before dispatch. See the precise
|
|
179
178
|
[Resend size budget](src/adapters/resend/README.md#outbound-size-budget); it is a
|
|
180
179
|
local guard and may reject input below the provider's maximum.
|
|
181
180
|
|
|
@@ -191,58 +190,14 @@ Network loss, redirects, HTTP 408 and 5xx are conservatively `uncertain`; 429 is
|
|
|
191
190
|
|
|
192
191
|
## Development and unsubscribe
|
|
193
192
|
|
|
194
|
-
Development requires
|
|
193
|
+
Development requires `provider:'development'` and `mode:'development'`.
|
|
194
|
+
It validates the prepared message and silently suppresses delivery, returning
|
|
195
|
+
`development` without contacting a provider or storing the message. Production
|
|
196
|
+
must never select development mode after missing credentials or a send failure.
|
|
195
197
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
`createD1DevelopmentOutbox({db,maxMessages?,maxAgeMs?,clock?})` and
|
|
200
|
-
`createDevelopmentOutboxHandler({local,origin,outbox,path?,theme?})`. The root facade's
|
|
201
|
-
exports remain stable. `theme` is the seed's served theme stylesheet, a
|
|
202
|
-
root-relative `.css` path such as `'/rer-theme.css'` (the same grammar as
|
|
203
|
-
operator-auth `branding.theme`; any other value throws when the handler is
|
|
204
|
-
created). With it the page links that file, reads its `--rer-*` tokens with
|
|
205
|
-
readable fallbacks and a visible 3px focus ring, and its policy allows
|
|
206
|
-
same-origin styles, fonts and images (still no script). Without it the page is
|
|
207
|
-
unchanged. Apply the additive [schema](src/development/schema.sql)
|
|
208
|
-
to your local D1 database during local setup, for example:
|
|
209
|
-
|
|
210
|
-
```sh
|
|
211
|
-
pnpm exec wrangler d1 execute DB --local --file=../modules/mail/src/development/schema.sql
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
Use the actual database binding and source path for your host. The table and
|
|
215
|
-
index are namespaced `rer_mail_development_outbox`; the schema is repeatable and
|
|
216
|
-
does not replace application tables. Keep the local D1 persistence directory
|
|
217
|
-
between restarts. No provider credentials are needed for local capture.
|
|
218
|
-
|
|
219
|
-
```js
|
|
220
|
-
import { createMailSender } from './modules/mail/index.mjs';
|
|
221
|
-
import {
|
|
222
|
-
createD1DevelopmentOutbox, createDevelopmentOutboxHandler,
|
|
223
|
-
} from './modules/mail/src/development/index.mjs';
|
|
224
|
-
|
|
225
|
-
// These values come from trusted, explicit local host configuration.
|
|
226
|
-
const outbox = createD1DevelopmentOutbox({ db: env.DB });
|
|
227
|
-
const sender = createMailSender(
|
|
228
|
-
{ provider: 'development', mode: 'development' }, { outbox },
|
|
229
|
-
);
|
|
230
|
-
const viewOutbox = createDevelopmentOutboxHandler({
|
|
231
|
-
local: localConfiguration.enabled === true,
|
|
232
|
-
origin: localConfiguration.origin, // e.g. 'http://localhost:8787'
|
|
233
|
-
outbox,
|
|
234
|
-
});
|
|
235
|
-
// In the host's request handler, before the application catch-all:
|
|
236
|
-
const response = await viewOutbox(request);
|
|
237
|
-
if (response) return response;
|
|
238
|
-
// Continue normal application routing otherwise.
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
Wire the application's real sign-in mail call to `sender.send`; the regular
|
|
242
|
-
message composition and unsubscribe assembly still run. Make this selection
|
|
243
|
-
only in the explicit local configuration. Production keeps its configured
|
|
244
|
-
remote sender, and does not mount the development viewer. Missing provider
|
|
245
|
-
credentials or a delivery failure must never select development mode.
|
|
198
|
+
`createD1DevelopmentOutbox({db,maxMessages?,maxAgeMs?,clock?})` remains available
|
|
199
|
+
for reading and erasing mail retained by older local installations. There is no
|
|
200
|
+
outbox viewer or development sign-in mail flow. Keep applied migrations.
|
|
246
201
|
|
|
247
202
|
`put(preparedMessage)` resolves without a receipt; `list()` returns captures
|
|
248
203
|
newest first, and `get(id)` returns a capture or `null`. A capture is
|
|
@@ -255,31 +210,9 @@ D1 batch as the operation; a message expires exactly at `createdAt + maxAgeMs`.
|
|
|
255
210
|
Equal timestamps retain the most recently inserted captures first. A failing
|
|
256
211
|
batch fails the operation without a process-memory fallback.
|
|
257
212
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
its scheme and authority. `localhost`, canonical `127.x.x.x`, and `[::1]` are
|
|
262
|
-
supported. Trailing slashes, credentials, paths, queries, fragments, whitespace
|
|
263
|
-
and alternate URL spellings in the configured origin are refused. Host must
|
|
264
|
-
include the configured non-default port. Forwarded headers never grant access;
|
|
265
|
-
a different Origin or a cross-site fetch is also refused before any D1 read.
|
|
266
|
-
The host must bind its development listener to loopback; these request checks
|
|
267
|
-
do not replace that listener configuration.
|
|
268
|
-
|
|
269
|
-
The listing shows subject, recipient and received time. A message detail shows
|
|
270
|
-
escaped text (escaped source for HTML-only messages) and a large **Open this
|
|
271
|
-
link** action for the first valid HTTP(S) link. It never renders live email
|
|
272
|
-
HTML or attachment content. All viewer responses, including errors, carry
|
|
273
|
-
no-store, noindex, nosniff and a strict CSP with an exact static-style hash and
|
|
274
|
-
scripts disabled. The layout wraps long content on a 390px viewport.
|
|
275
|
-
|
|
276
|
-
First-party seeds route local setup through `rer setup` and
|
|
277
|
-
declare their actual mail, auth, database and migration behavior in the RER
|
|
278
|
-
adapter. Base's default seed is the reference for loopback development mail and
|
|
279
|
-
the private local outbox. Follow the runnable checkout's root
|
|
280
|
-
`RUN-LOCALLY.md` for current command and state requirements; the outbox module does not
|
|
281
|
-
replace a seed's owner setup, database bindings, migration directory or sign-in
|
|
282
|
-
policy.
|
|
213
|
+
First-party seeds route local setup through `rer setup` and declare their actual
|
|
214
|
+
mail, auth, database and migration behavior in the RER adapter. Follow the
|
|
215
|
+
runnable checkout's root `RUN-LOCALLY.md` for its command and state requirements.
|
|
283
216
|
|
|
284
217
|
`unsubscribe: {url, mailto?, oneClick?}` supplies an HTTPS unsubscribe URL and optional mailbox. One-click generates `List-Unsubscribe-Post: List-Unsubscribe=One-Click`. Insecure URLs, injection and contradictory custom unsubscribe headers fail before dispatch. `applyUnsubscribeHeaders(message)` returns a new prepared message with the `unsubscribe` request removed. Passing an already prepared message to the facade is safe. Direct adapters reject unconsumed requests before any effect; the facade performs assembly once before dispatch. Applications own unsubscribe authorization and processing. Confirm delivered headers and DKIM coverage with a real delivered message; local serialization is not one-click acceptance.
|
|
285
218
|
|
|
@@ -319,7 +252,7 @@ For a D1 application, copy `src/events/d1-schema.sql` into a **new** migration a
|
|
|
319
252
|
use [the D1 event constructor](src/events/README.md). No migration, linking,
|
|
320
253
|
provider switch or credential removal happens automatically. Self-hosted installs
|
|
321
254
|
stay unlinked until the owner configures them; local development still uses the
|
|
322
|
-
|
|
255
|
+
explicit development suppression without a Messaging service.
|
|
323
256
|
|
|
324
257
|
## The former sendgrid-email API
|
|
325
258
|
|
|
@@ -373,6 +306,6 @@ pnpm --dir modules/mail test:workerd
|
|
|
373
306
|
|
|
374
307
|
The root install is also required for the bundle regression, which uses the reference app's actual Vite dependency. The facade formerly re-exported the doctor while the doctor dynamically imported the facade, causing Vite's `INEFFECTIVE_DYNAMIC_IMPORT` warning. Both now import a private sender module; the existing facade exports and send behavior remain unchanged. `tests/development/bundle.test.mjs` builds the facade and doctor with Vite and fails on that warning.
|
|
375
308
|
|
|
376
|
-
The module-local lock pins the Miniflare/workerd test runtime; production source has no npm dependencies. Unit suites cover core validation, adapters, events, inbound parsing, development, unsubscribe and doctor behaviour. The Messaging HTTP/service-binding smoke and real D1 intake race/rollback/restart suite join the existing area smokes. They check core portability, remote adapters, inbound hydration, durable event intake,
|
|
309
|
+
The module-local lock pins the Miniflare/workerd test runtime; production source has no npm dependencies. Unit suites cover core validation, adapters, events, inbound parsing, development, unsubscribe and doctor behaviour. The Messaging HTTP/service-binding smoke and real D1 intake race/rollback/restart suite join the existing area smokes. They check core portability, remote adapters, inbound hydration, durable event intake, historical development storage and doctor/facade assembly. The storage smokes retain real transaction rollback, namespace isolation, restart and suppression coverage. `tests/all.test.ts` runs the nested suites serially through `pnpm verify:modules`; each worker is disposed after its run. Former SendGrid API tests remain while seed source still imports the deprecated module.
|
|
377
310
|
|
|
378
311
|
Local conformance does not establish provider configuration, DNS propagation, deployed webhook reachability, DKIM coverage or mailbox delivery. Live acceptance remains **PENDING** until an exact-SHA hosted run sends and receives on the owner's approved test domain with independently correlated mailbox evidence. Resend is the default test sender; SendGrid is selected where Inbound Parse is required. No live request is authorized by running local tests.
|
|
@@ -36,7 +36,6 @@ export function validateConfig(config, dependencies = {}) {
|
|
|
36
36
|
if (config.provider === 'development') {
|
|
37
37
|
if (config.mode !== 'development') fail('development_mode_required');
|
|
38
38
|
if (config.apiKey !== undefined || config.accountId !== undefined) fail('unsupported_development_config');
|
|
39
|
-
if (!dependencies.outbox || typeof dependencies.outbox.put !== 'function') fail('development_outbox_required');
|
|
40
39
|
} else {
|
|
41
40
|
if (typeof config.apiKey !== 'string' || !config.apiKey.trim()) fail('api_key_required');
|
|
42
41
|
bounded(config.apiKey, 4096, 'invalid_api_key');
|
|
@@ -34,10 +34,5 @@ export class DevelopmentOutboxError extends Error {
|
|
|
34
34
|
readonly retryable: true;
|
|
35
35
|
}
|
|
36
36
|
export function createD1DevelopmentOutbox(options: { db: DevelopmentD1Database; maxMessages?: number; maxAgeMs?: number; clock?: () => number }): DevelopmentOutbox;
|
|
37
|
-
export function createDevelopmentOutboxHandler(options: {
|
|
38
|
-
local: boolean; origin: string; outbox: Pick<DevelopmentOutbox, 'list' | 'get'>; path?: string;
|
|
39
|
-
/** The seed's served theme stylesheet, a root-relative `.css` path such as '/rer-theme.css'; other values throw. */
|
|
40
|
-
theme?: string;
|
|
41
|
-
}): (request: Request) => Promise<Response | null>;
|
|
42
37
|
export function sendDevelopment(config: { provider: 'development'; mode: 'development' }, message: DevelopmentMessage,
|
|
43
|
-
dependencies
|
|
38
|
+
dependencies?: { clock?: () => number }): Promise<{ provider: 'development'; status: 'development'; providerMessageId: null }>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { MailValidationError,
|
|
1
|
+
import { MailValidationError, fail } from '../core/errors.mjs';
|
|
2
2
|
import { validateConfig, validateMessage } from '../core/validation.mjs';
|
|
3
3
|
import { sendResult } from '../core/transport.mjs';
|
|
4
4
|
|
|
5
|
+
// Retained for reading and erasing messages saved by older local installations.
|
|
5
6
|
export { createD1DevelopmentOutbox } from './outbox.mjs';
|
|
6
|
-
export { createDevelopmentOutboxHandler } from './viewer.mjs';
|
|
7
7
|
export { DevelopmentOutboxError } from '../core/errors.mjs';
|
|
8
8
|
|
|
9
9
|
function validate(operation, errorCode) {
|
|
@@ -15,24 +15,11 @@ function validate(operation, errorCode) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
/**
|
|
18
|
+
/** Explicit development delivery validates the message and silently suppresses it. */
|
|
19
19
|
export async function sendDevelopment(config, message, dependencies = {}) {
|
|
20
20
|
validate(() => validateConfig(config, dependencies), 'invalid_config');
|
|
21
21
|
if (validate(() => config.provider, 'invalid_config') !== 'development') fail('development_provider_required');
|
|
22
|
-
|
|
23
22
|
validate(() => validateMessage(message, 'development'), 'invalid_message');
|
|
24
23
|
if (validate(() => message.unsubscribe, 'invalid_message') !== undefined) fail('unsubscribe_not_assembled');
|
|
25
|
-
|
|
26
|
-
const snapshot = validate(() => structuredClone(message), 'invalid_message');
|
|
27
|
-
validate(() => validateMessage(snapshot, 'development'), 'invalid_message');
|
|
28
|
-
|
|
29
|
-
try {
|
|
30
|
-
await dependencies.outbox.put(snapshot);
|
|
31
|
-
} catch (error) {
|
|
32
|
-
// Input the outbox itself refuses stays permanent; a storage failure is worth a retry.
|
|
33
|
-
if (error instanceof MailValidationError) throw error;
|
|
34
|
-
throw new DevelopmentOutboxError();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
24
|
return sendResult('development', 'development', null);
|
|
38
25
|
}
|
|
@@ -63,7 +63,7 @@ Base's operator auth is the only staff sign-in, in three layers:
|
|
|
63
63
|
| --- | --- | --- |
|
|
64
64
|
| `identity/` | Proving who a person is: the email link (`identity/email-link/`), identity providers over OpenID Connect (`identity/oidc/`, see [its README](identity/oidc/README.md)), and the admission that turns a verified principal into a session (`identity/admission.mjs`). | Outputs a **verified principal** `{issuer, subject, provider?, email?, emailVerified?, emailVerifiedAt?, amr?}`; `identity/index.mjs`. |
|
|
65
65
|
| `accounts/` | Who a person is in this app and what they may do: operators, roles, invitations, sessions, domain rules and step-up proofs in the `oa_` store (`accounts/store.mjs`, `accounts/schema/`). | The **accounts adapter interface** (`accounts/adapter.mjs`); Base's implementation over `oa_` is `accounts/oa.mjs`. |
|
|
66
|
-
| `dev/` | Local-only dev sessions, personas and
|
|
66
|
+
| `dev/` | Local-only dev sessions, personas and mode labels, loaded only from a local-only Worker entry. | `dev/index.mjs`; see "Local dev identity" below. |
|
|
67
67
|
|
|
68
68
|
The files at the root are shared by all three: HTTP and input checks, crypto,
|
|
69
69
|
configuration and branding, the shared page frame (`page.mjs`), the key gate
|
|
@@ -380,7 +380,7 @@ for other requests). It is server-rendered plain HTML with no script, so it work
|
|
|
380
380
|
before hydration and without JavaScript, in the same hashed-style frame as the
|
|
381
381
|
confirmation page (light and dark, the seed's `rer-theme.css` when declared).
|
|
382
382
|
It shows "Continue with…" for each linked, reachable provider, then the email
|
|
383
|
-
link, then optional seed links
|
|
383
|
+
link, then optional seed links and, while the first owner is
|
|
384
384
|
unclaimed, the setup form. A provider that has failed discovery or JWKS for 5
|
|
385
385
|
minutes, or answered 404 or a DNS failure, is hidden, and a browser that still
|
|
386
386
|
posts to it comes back to this page with a notice and the email link instead of
|
|
@@ -477,8 +477,7 @@ local mode. `admits(request)` accepts the `rer_dev_gate_<port>` cookie (an HMAC
|
|
|
477
477
|
key, so a reset key refuses old cookies) or the key in `x-rer-dev-key` (the rer
|
|
478
478
|
CLI and test harnesses). `exchange(request)` serves `GET /__dev/key` and trades
|
|
479
479
|
the key from the URL fragment, through a same-origin POST, for a host-only
|
|
480
|
-
`HttpOnly; SameSite=Strict; Path=/` cookie.
|
|
481
|
-
with it.
|
|
480
|
+
`HttpOnly; SameSite=Strict; Path=/` cookie.
|
|
482
481
|
|
|
483
482
|
`dev/` is the dev layer: **server-only and local-only**. Import it only from a
|
|
484
483
|
local-only Worker entry (a Vite-serve or local `wrangler dev` entry), never
|
|
@@ -489,19 +488,21 @@ the seed's Worker and serves, behind the gate only:
|
|
|
489
488
|
| Path | Result |
|
|
490
489
|
| --- | --- |
|
|
491
490
|
| `/auth/dev/enter?as=owner\|signed-out\|PERSONA&returnTo=` | Creates or reuses a real `oa_sessions` row of kind `dev` for the configured owner or persona and 303s to `returnTo` (default `/app`); `signed-out` revokes the current session. |
|
|
491
|
+
| `POST /auth/local/cli-session` | Owner-side tooling proves possession of the session secret with `x-rer-local-cli`; exact loopback and origin checks precede issuing a native owner session and fresh local proof. This route exists only in the dev entry. |
|
|
492
492
|
| `/__dev/personas` | `[{as,email,role?}]`, used by `rer dev` for `RER_SIGNED_IN`. |
|
|
493
493
|
|
|
494
494
|
`personas()` returns the seed's `devPersonas()`: `[{as, role, displayName?}]`,
|
|
495
495
|
real operators at `<as>@dev.localhost` created only by dev sign-in. Dev
|
|
496
496
|
sessions pass the same version fences, revocation, deactivation and allow-list
|
|
497
|
-
as every other session.
|
|
497
|
+
as every other session. An admitted local dev session also confirms sensitive
|
|
498
|
+
actions directly, so dev never waits for an email step-up link. The core admits a `dev` session, and any credential
|
|
498
499
|
minted while using one (`oa_dev_credentials`, today an invitation link, whose
|
|
499
500
|
confirmation then yields a `dev` session), only when the dev layer's
|
|
500
501
|
registered check passes for that request; a production Worker never registers
|
|
501
|
-
one. HTML documents gain
|
|
502
|
-
document
|
|
503
|
-
document
|
|
504
|
-
dev sign-in and personas
|
|
502
|
+
one. HTML documents gain the Dev suffix on product labels marked with
|
|
503
|
+
`data-rer-name` and document titles; a demo receives Demo instead. The dedicated
|
|
504
|
+
`/__dev/key` document exchanges the RER_OPEN fragment without placing the key in
|
|
505
|
+
request URLs. `RER_DEV_IDENTITY=off` disables dev sign-in and personas. The
|
|
505
506
|
layer answers 503 to every request when `RER_INSTALLATION_ID` is set beside a
|
|
506
507
|
non-loopback `RER_MANAGEMENT_ORIGIN`.
|
|
507
508
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// Inline
|
|
2
|
-
// the demo bar each add one hashed style without loosening anything else.
|
|
1
|
+
// Inline product labels add exact CSP hashes without broadening other sources.
|
|
3
2
|
|
|
4
3
|
/** The CSP source token for an exact inline text. */
|
|
5
4
|
export async function sha256(text) {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { isLocalCli } from '../local-cli.mjs';
|
|
2
|
+
import { requireLoopback, requirePost, sessionCookie } from '../http.mjs';
|
|
3
|
+
import { opaqueToken } from '../crypto.mjs';
|
|
4
|
+
import { safeReturnTo } from '../policy.mjs';
|
|
5
|
+
import { isActiveOperator } from '../accounts/roles.mjs';
|
|
6
|
+
import { AuthError } from '../errors.mjs';
|
|
7
|
+
import { devNotFound } from '../dev-gate.mjs';
|
|
8
|
+
import { readInput } from '../input.mjs';
|
|
9
|
+
|
|
10
|
+
// Owner-side local tooling proves possession of this installation's session
|
|
11
|
+
// secret. This endpoint exists only in the local dev entry, never production.
|
|
12
|
+
export async function cliSession(request, { config, store, hash, everyone }, headers) {
|
|
13
|
+
requireLoopback(request);
|
|
14
|
+
requirePost(request, config);
|
|
15
|
+
if (!await isLocalCli(request, config)) return devNotFound();
|
|
16
|
+
const input = await readInput(request);
|
|
17
|
+
const ownerEmail = (await everyone()).find(persona => persona.as === 'owner')?.email;
|
|
18
|
+
const operator = ownerEmail ? await store.byEmail(ownerEmail) : null;
|
|
19
|
+
if (operator?.role !== 'owner' || !isActiveOperator(operator, config.allowList)) throw new AuthError('owner_required', 403);
|
|
20
|
+
const now = Date.now(), token = opaqueToken();
|
|
21
|
+
const session = { id: crypto.randomUUID(), hash: await hash(token), expiresAt: now + config.sessionSeconds * 1000 };
|
|
22
|
+
const record = await store.issue({ operatorId: operator.id, expectedVersion: operator.version, session, now, kind: 'native' });
|
|
23
|
+
if (!record || record.operator.role !== 'owner') throw new AuthError('authority_changed', 409);
|
|
24
|
+
// A local owner proof uses the existing durable, version-fenced proof ledger.
|
|
25
|
+
// It can authorize setup linking without manufacturing an email credential.
|
|
26
|
+
const inserted = await store.run(`INSERT INTO oa_step_up_challenges(id,token_hash,session_id,operator_id,operator_version,action,return_to,created_at,expires_at,consumed_at)
|
|
27
|
+
SELECT ?,?,?,?,?,?,?,?,?,? WHERE EXISTS(SELECT 1 FROM oa_sessions s JOIN oa_operators o ON o.id=s.operator_id
|
|
28
|
+
WHERE s.id=? AND s.revoked_at IS NULL AND o.role='owner' AND o.status='active' AND o.version=?)`,
|
|
29
|
+
[crypto.randomUUID(), await hash(opaqueToken()), record.id, operator.id, operator.version, 'local-cli', '/', now, session.expiresAt, now, record.id, operator.version]);
|
|
30
|
+
if (inserted.meta.changes !== 1) throw new AuthError('authority_changed', 409);
|
|
31
|
+
return new Response(null, { status: 303, headers: { ...headers, location: safeReturnTo(input.returnTo), 'set-cookie': sessionCookie(token, config) } });
|
|
32
|
+
}
|
|
@@ -7,13 +7,15 @@ import { AuthStore } from '../accounts/store.mjs';
|
|
|
7
7
|
import { createOperatorAuth } from '../service.mjs';
|
|
8
8
|
import { AuthError } from '../errors.mjs';
|
|
9
9
|
import { hashToken, opaqueToken } from '../crypto.mjs';
|
|
10
|
-
import { readCookie, sessionCookie, isLoopbackHost } from '../http.mjs';
|
|
10
|
+
import { readCookie, sessionCookie, isLoopbackHost, escapeHtml } from '../http.mjs';
|
|
11
11
|
import { safeReturnTo } from '../policy.mjs';
|
|
12
12
|
import { isActiveOperator, defaultRolePolicy } from '../accounts/roles.mjs';
|
|
13
13
|
import { devGate, devNotFound } from '../dev-gate.mjs';
|
|
14
14
|
import { registerDevAdmission } from '../dev-admission.mjs';
|
|
15
15
|
import { definePersonas } from './personas.mjs';
|
|
16
|
-
import {
|
|
16
|
+
import { cliSession } from './cli-session.mjs';
|
|
17
|
+
import { decorateLabel } from '../../demo/label.mjs';
|
|
18
|
+
import { pageResponse } from '../page.mjs';
|
|
17
19
|
|
|
18
20
|
export const DEV_LAYER_MARKER = 'rer-dev-layer:local-only-never-deploy';
|
|
19
21
|
const headers = { 'cache-control': 'no-store', 'referrer-policy': 'no-referrer', 'x-content-type-options': 'nosniff', 'x-robots-tag': 'noindex, nofollow', 'x-rer-dev-layer': DEV_LAYER_MARKER };
|
|
@@ -28,7 +30,7 @@ export function managedInstallation(env) {
|
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* Wraps a seed's Worker with dev sign-in (`/auth/dev/enter?as=…`), the persona
|
|
31
|
-
* list (`/__dev/personas`)
|
|
33
|
+
* list (`/__dev/personas`). Every identity surface needs the key
|
|
32
34
|
* gate and answers 404 without it. `config(env)` is the seed's own AuthConfig
|
|
33
35
|
* and `personas()` its devPersonas() declaration.
|
|
34
36
|
*/
|
|
@@ -42,16 +44,24 @@ export function withDevIdentity(worker, { bindings = env => env, config: authCon
|
|
|
42
44
|
// Never admit a dev credential here; with dev identity on, serve nothing.
|
|
43
45
|
registerDevAdmission(null);
|
|
44
46
|
if (env.RER_DEV_IDENTITY !== 'off') return rejectedResponse(request, text(503, 'Dev identity refuses to run beside RER_INSTALLATION_ID with a non-loopback RER_MANAGEMENT_ORIGIN. Remove those bindings from local settings or use rer dev --login.'));
|
|
45
|
-
return new URL(request.url).pathname === '/auth/dev/enter' || new URL(request.url).pathname === '/__dev/personas' ? rejectedResponse(request, devNotFound()) : worker.fetch(request, original, execution);
|
|
47
|
+
return new URL(request.url).pathname === '/auth/dev/enter' || new URL(request.url).pathname === '/__dev/personas' || new URL(request.url).pathname === '/auth/local/cli-session' ? rejectedResponse(request, devNotFound()) : worker.fetch(request, original, execution);
|
|
46
48
|
}
|
|
47
49
|
const gate = devGate({ key: env.RER_DEV_KEY, origin: env.AUTH_ORIGIN, local: env.AUTH_LOCAL === 'true' });
|
|
48
50
|
registerDevAdmission(gate ? r => gate.admits(r) : null);
|
|
49
51
|
const path = new URL(request.url).pathname;
|
|
50
|
-
if (path === '/
|
|
51
|
-
|
|
52
|
+
if (path === '/__dev/key') return gate ? gate.exchange(request) : devNotFound();
|
|
53
|
+
if (path === '/signin' && gate && env.RER_DEV_IDENTITY !== 'off' && request.method === 'GET') {
|
|
54
|
+
if (!await gate.admits(request)) return new Response(null, { status: 303, headers: { ...headers, location: '/__dev/key' } });
|
|
55
|
+
const { config } = identity(env, authConfig, declared);
|
|
56
|
+
const returnTo = safeReturnTo(new URL(request.url).searchParams.get('returnTo'));
|
|
57
|
+
const href = `/auth/dev/enter?as=owner&returnTo=${encodeURIComponent(returnTo)}`;
|
|
58
|
+
return decorateLabel(await pageResponse({ branding: config.branding, heading: 'Open your local app', content: `<a class="action" href="${escapeHtml(href)}">Continue as owner</a>` }), env.RER_DEMO === '1' ? 'Demo' : 'Dev');
|
|
59
|
+
}
|
|
60
|
+
if (path === '/auth/dev/enter' || path === '/__dev/personas' || path === '/auth/local/cli-session') {
|
|
61
|
+
if (!gate || env.RER_DEV_IDENTITY === 'off' || (path !== '/auth/local/cli-session' && !await gate.admits(request))) return rejectedResponse(request, devNotFound());
|
|
52
62
|
const context = identity(env, authConfig, declared);
|
|
53
63
|
try {
|
|
54
|
-
const response = path === '/__dev/personas' ? Response.json(await context.list(), { headers }) : await enter(request, gate, context);
|
|
64
|
+
const response = path === '/auth/local/cli-session' ? await cliSession(request, context, headers) : path === '/__dev/personas' ? Response.json(await context.list(), { headers }) : await enter(request, gate, context);
|
|
55
65
|
return rejectedResponse(request, response);
|
|
56
66
|
} catch (error) {
|
|
57
67
|
if (error instanceof AuthError) return rejectedResponse(request, Response.json({ error: error.code }, { status: error.status, headers }));
|
|
@@ -60,9 +70,7 @@ export function withDevIdentity(worker, { bindings = env => env, config: authCon
|
|
|
60
70
|
}
|
|
61
71
|
const response = await worker.fetch(request, original, execution);
|
|
62
72
|
if (!gate || request.method !== 'GET' || path.startsWith('/__dev/')) return response;
|
|
63
|
-
|
|
64
|
-
const badge = admitted && env.RER_DEV_IDENTITY !== 'off' ? await identity(env, authConfig, declared).badge(request) : null;
|
|
65
|
-
return decorate(response, { exchange: path === '/', badge });
|
|
73
|
+
return decorateLabel(response, env.RER_DEMO === '1' ? 'Demo' : 'Dev');
|
|
66
74
|
},
|
|
67
75
|
};
|
|
68
76
|
}
|
|
@@ -97,7 +105,6 @@ function identity(env, authConfig, declared) {
|
|
|
97
105
|
return { ...actor, hash: await hash(readCookie(request, config)) };
|
|
98
106
|
},
|
|
99
107
|
list: async () => [...(await everyone()).map(({ as, email, role }) => ({ as, email, ...(role ? { role } : {}) })), { as: 'signed-out' }],
|
|
100
|
-
async badge(request) { return { session: await current(request), choices: (await everyone()).filter(persona => persona.email) }; },
|
|
101
108
|
};
|
|
102
109
|
}
|
|
103
110
|
|
|
@@ -55,6 +55,9 @@ export function createEmailLinkLifecycle({ config: input, clock = Date.now, mail
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
async function requireFreshProof(actor) {
|
|
58
|
+
// Authentication already required the local key gate for this session.
|
|
59
|
+
// Dev confirms actions directly rather than sending an unusable mail link.
|
|
60
|
+
if (config.local && actor.kind === 'dev') return;
|
|
58
61
|
if (!await store.steppedUp(actor, clock() - STEP_UP_SECONDS * 1000, clock())) deny('step_up_required', 403);
|
|
59
62
|
}
|
|
60
63
|
const authenticate = request => store.authenticate(request);
|
|
@@ -23,7 +23,7 @@ export async function pageResponse({ branding, title, heading, content, status =
|
|
|
23
23
|
const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(css)));
|
|
24
24
|
const hash = btoa(String.fromCharCode(...digest));
|
|
25
25
|
const product = escapeHtml(branding.productName);
|
|
26
|
-
const html = `<!doctype html><html lang="en"${branding.theme ? ' class="rer-themed"' : ''}><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${title ?? heading}</title>${branding.theme ? `<link rel="stylesheet" href="${escapeHtml(branding.theme)}">` : ''}<style>${css}</style></head><body><main><p class="brand"><span class="mark" aria-hidden="true"></span>${product}</p><h1>${heading}</h1>${content}</main></body></html>`;
|
|
26
|
+
const html = `<!doctype html><html lang="en"${branding.theme ? ' class="rer-themed"' : ''}><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${title ?? heading}</title>${branding.theme ? `<link rel="stylesheet" href="${escapeHtml(branding.theme)}">` : ''}<style>${css}</style></head><body><main><p class="brand"><span class="mark" aria-hidden="true"></span><span data-rer-name>${product}</span></p><h1>${heading}</h1>${content}</main></body></html>`;
|
|
27
27
|
const headers = { ...securityHeaders(), 'Content-Type': 'text/html; charset=utf-8' };
|
|
28
28
|
// A form may post to this origin only, plus any origin its own redirect must reach (a provider's authorization endpoint).
|
|
29
29
|
if (formTargets.length) headers['Content-Security-Policy'] = headers['Content-Security-Policy'].replace("form-action 'self'", `form-action 'self' ${formTargets.join(' ')}`);
|
|
@@ -3,7 +3,7 @@ import type { OperatorAuth } from '../index.mjs';
|
|
|
3
3
|
export interface SignInPageOptions {
|
|
4
4
|
/** While the first owner is unclaimed: the setup form and its instructions. */
|
|
5
5
|
setup?: (request: Request) => null | false | undefined | { instructions?: string } | Promise<null | false | undefined | { instructions?: string }>;
|
|
6
|
-
/** Extra same-origin links under the form
|
|
6
|
+
/** Extra same-origin links under the form. */
|
|
7
7
|
links?: (request: Request) => Array<{ href: string; label: string }> | Promise<Array<{ href: string; label: string }>>;
|
|
8
8
|
defaultReturnTo?: string;
|
|
9
9
|
}
|
|
@@ -292,6 +292,10 @@ by table name. Product-only staging keeps restore queries small even with long
|
|
|
292
292
|
column names.
|
|
293
293
|
Advance normalizes the durable snapshot, sorts archived keys and checks attachment
|
|
294
294
|
references again before completing the archive.
|
|
295
|
+
The shared D1 transport preserves mixed-script text through SQLite decoding and
|
|
296
|
+
accounts for workerd's whole-call string width. Snapshot and archive-segment
|
|
297
|
+
reads are bounded before crossing the provider boundary; staging and restore
|
|
298
|
+
transactions remain atomic.
|
|
295
299
|
`exports.advance(id,{expectedPart,maxParts})` commits durable bounded parts;
|
|
296
300
|
`expectedPart` makes a lost-acknowledgement retry a no-op. Status reports progress;
|
|
297
301
|
download streams completed jobs. Abort removes snapshots and stored parts.
|
|
@@ -417,6 +421,8 @@ executes the copied Worker and CLI. Tests and development fixtures are not copie
|
|
|
417
421
|
|
|
418
422
|
```text
|
|
419
423
|
modules/portability/index.mjs
|
|
424
|
+
modules/d1-transport/index.mjs
|
|
425
|
+
modules/d1-transport/index.d.mts
|
|
420
426
|
modules/portability/index.d.mts
|
|
421
427
|
modules/portability/lines.mjs
|
|
422
428
|
modules/portability/hash.mjs
|
|
@@ -52,7 +52,7 @@ export async function catalogue(db,config) {
|
|
|
52
52
|
columns.forEach(c=>{if(c.hidden)c.generated=c.hidden===2?'virtual':'stored';delete c.hidden;});
|
|
53
53
|
// Both archived base cells and visible staging reads must fit D1's SQL
|
|
54
54
|
// limit, with room for copy names and joins.
|
|
55
|
-
insist([false,true].every(encoded=>utf8(projectedColumns({columns},encoded)).length+1024<=100000),'transfer_sql_limit:'+entry.name);
|
|
55
|
+
insist([false,true].every(encoded=>utf8(projectedColumns({columns},encoded)).length+1024+columns.length*64<=100000),'transfer_sql_limit:'+entry.name);
|
|
56
56
|
const dependencies=[...new Set((await all(db,`PRAGMA foreign_key_list(${quote(entry.name)})`)).map(ref=>objects.find(x=>x.type==='table' && identifier(x.name)===identifier(ref.table))?.name??ref.table))].sort();
|
|
57
57
|
for(const parent of dependencies) insist(!excluded.some(x=>x.name===parent),'excluded_foreign_key:'+entry.name+':'+parent);
|
|
58
58
|
const rowidAlias=columns.some(c=>c.pk)?null:['rowid','_rowid_','oid'].find(alias=>!columns.some(c=>c.name.toLowerCase()===alias));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { all,statement,quote,insist } from './storage.mjs';
|
|
2
2
|
import { projectedColumns,encodedRow,mapRow,bindCell,writableColumns } from './catalogue.mjs';
|
|
3
|
-
import { canonicalJson } from './hash.mjs';
|
|
3
|
+
import { canonicalJson, utf8 } from './hash.mjs';
|
|
4
4
|
import { generatedCopySQL } from './generated.mjs';
|
|
5
5
|
|
|
6
6
|
export const sidecar=copy=>copy+'_meta';
|
|
@@ -10,6 +10,7 @@ export function copyRowid(table) {
|
|
|
10
10
|
}
|
|
11
11
|
const keys=table=>table.columns.filter(c=>c.pk).sort((a,b)=>a.pk-b.pk);
|
|
12
12
|
const order=table=>keys(table).length?keys(table).map(c=>quote(c.name)).join(','):quote(table.rowidAlias);
|
|
13
|
+
const sum=terms=>terms.length<2?(terms[0]??'0'):`(${sum(terms.slice(0,terms.length>>1))}+${sum(terms.slice(terms.length>>1))})`;
|
|
13
14
|
export function createCopy(db,table,copy,snapshot=false) {
|
|
14
15
|
const ordering=order(table),meta=quote(sidecar(copy));
|
|
15
16
|
const columns=writableColumns(table).map(c=>quote(c.name)).join(',');
|
|
@@ -22,7 +23,21 @@ export function createCopy(db,table,copy,snapshot=false) {
|
|
|
22
23
|
}
|
|
23
24
|
export async function readCopy(db,table,copy,offset,limit,encoded=false) {
|
|
24
25
|
const columns=projectedColumns(table,encoded);
|
|
25
|
-
const
|
|
26
|
+
const selected=encoded?writableColumns(table):table.columns;
|
|
27
|
+
const from=`FROM ${quote(copy)} s JOIN ${quote(sidecar(copy))} m ON s.${copyRowid(table)}=m.rer_portability_copy_rowid ORDER BY m.rer_portability_row_order LIMIT ? OFFSET ?`;
|
|
28
|
+
// Read sizes first, never discover a large row by overflowing the RPC result.
|
|
29
|
+
// 12x covers JSON control escapes (6x), binary arrays (4x), and whole-string
|
|
30
|
+
// two-byte workerd serialization. Names and scalar framing count separately.
|
|
31
|
+
const overhead=selected.reduce((n,c)=>n+utf8(c.name).length*12+128,256);
|
|
32
|
+
const weight=sum(selected.map(c=>`COALESCE(length(CAST(s.${quote(c.name)} AS BLOB)),0)`));
|
|
33
|
+
const sizes=await all(db,`SELECT (${weight})*12+${overhead} AS bytes ${from}`,limit,offset);
|
|
34
|
+
const raw=[];
|
|
35
|
+
for(let start=0;start<sizes.length;) {
|
|
36
|
+
let end=start,bytes=0;
|
|
37
|
+
while(end<sizes.length && bytes+sizes[end].bytes<30*1024*1024){bytes+=sizes[end].bytes;end++;}
|
|
38
|
+
insist(end>start,'row_part_too_large:'+table.name);
|
|
39
|
+
raw.push(...await all(db,`SELECT ${columns} ${from}`,end-start,offset+start));start=end;
|
|
40
|
+
}
|
|
26
41
|
const meta=await all(db,`SELECT * FROM ${quote(sidecar(copy))} ORDER BY rer_portability_row_order LIMIT ? OFFSET ?`,limit,offset);
|
|
27
42
|
insist(raw.length===meta.length,'copy_inventory:'+table.name);
|
|
28
43
|
return raw.map((row,i)=>({row,meta:meta[i]}));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { policy, catalogue } from './catalogue.mjs';
|
|
2
|
+
import { wireDatabase } from '../d1-transport/index.mjs';
|
|
2
3
|
import { insist, job } from './storage.mjs';
|
|
3
4
|
import { createExport, advanceExport, exportStatus, downloadExport, abortExport } from './export.mjs';
|
|
4
5
|
import { createImport, uploadPart, finalizeImport, importStatus, abortImport } from './import.mjs';
|
|
@@ -10,6 +11,7 @@ export { canonicalJson, sha256 } from './hash.mjs';
|
|
|
10
11
|
export { PortabilityError } from './storage.mjs';
|
|
11
12
|
export { createPortabilityHandler } from './http.mjs';
|
|
12
13
|
export async function createPortability({db,buckets={},policy:input,migrations}) {
|
|
14
|
+
db=wireDatabase(db);
|
|
13
15
|
const config=policy(input);await catalogue(db,config);
|
|
14
16
|
for(const name of Object.keys(config.buckets))insist(buckets[name] && typeof buckets[name].get==='function','missing_bucket:'+name);
|
|
15
17
|
const context={db,buckets,config,migrations};
|
|
@@ -36,7 +36,11 @@ export function partStatements(db,id,part) {
|
|
|
36
36
|
return result;
|
|
37
37
|
}
|
|
38
38
|
export async function readPart(db,id,index) {
|
|
39
|
-
const rows=
|
|
39
|
+
const rows=[];
|
|
40
|
+
for(let offset=0;;offset+=64) {
|
|
41
|
+
const page=await all(db,'SELECT data FROM rer_portability_segments WHERE job=? AND part=? ORDER BY segment LIMIT 64 OFFSET ?',id,index,offset);
|
|
42
|
+
rows.push(...page);if(page.length<64)break;
|
|
43
|
+
}
|
|
40
44
|
insist(rows.length,'part_missing');
|
|
41
45
|
return JSON.parse(rows.map(x=>x.data).join(''));
|
|
42
46
|
}
|
package/onboarding/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
First-party seeds expose public operations through the RER dispatcher. From a
|
|
4
4
|
runnable seed checkout, the supported local sequence begins with
|
|
5
5
|
`rer install`, `rer setup` and
|
|
6
|
-
`rer dev`; owner sign-in uses the
|
|
6
|
+
`rer dev`; owner sign-in uses the one-click `RER_OPEN` link. The
|
|
7
7
|
command contract and flags are documented in the runnable checkout's root
|
|
8
8
|
`RUN-LOCALLY.md`.
|
|
9
9
|
|
|
@@ -48,9 +48,8 @@ A seed that declares `devIdentity` on its command adapter gets the key-gated way
|
|
|
48
48
|
in from the installer without declaring anything more: before setup the installer
|
|
49
49
|
creates the checkout's dev key (as `rer setup` does) and passes it to the hooks as
|
|
50
50
|
`context.devKey`. The `start` hook must give it to the temporary app (an
|
|
51
|
-
`RER_DEV_KEY` binding),
|
|
52
|
-
|
|
53
|
-
key exchange (`RER_OPEN`); the key never enters saved state or logs. A seed
|
|
51
|
+
`RER_DEV_KEY` binding). When setup completes, the installer page offers the app
|
|
52
|
+
through the key exchange and dev owner entry (`RER_OPEN`); the key never enters saved state or logs. A seed
|
|
54
53
|
without `devIdentity` gets no key and its installer is unchanged.
|
|
55
54
|
|
|
56
55
|
`rer-setup.json` is the only setup schema. Its fields, groups, defaults,
|
|
@@ -104,8 +103,7 @@ Declare the theme in two places that name the same file:
|
|
|
104
103
|
and `firstRunResponse(request, bindings, auth, { theme: { href:
|
|
105
104
|
'/rer-theme.css', productName, accentColor? } })` from `src/base/setup` for
|
|
106
105
|
`/setup`; the foundation sign-in uses `themeFrame` from
|
|
107
|
-
`src/base/theme-frame` the same way
|
|
108
|
-
`createDevelopmentOutboxHandler({ ..., theme: '/rer-theme.css' })`.
|
|
106
|
+
`src/base/theme-frame` the same way.
|
|
109
107
|
`accentColor` colours buttons when the theme declares no accent. A seed's own
|
|
110
108
|
pages may read the same tokens by linking the file.
|
|
111
109
|
|
|
@@ -116,12 +114,11 @@ and the foundation template's `public/rer-theme.css` are worked examples.
|
|
|
116
114
|
|
|
117
115
|
Setup validates answers before effects, then uses the declared lifecycle to
|
|
118
116
|
prepare local state, private settings, build and migrations, start the real
|
|
119
|
-
application briefly
|
|
120
|
-
the loopback development outbox. It stops the temporary app before returning.
|
|
117
|
+
application briefly and prepare the first owner. It stops the temporary app before returning.
|
|
121
118
|
Reruns preserve an existing owner, data and exact settings bytes; setup does
|
|
122
119
|
not create a second owner or rotate secrets. Dev and preview use the saved
|
|
123
|
-
owner and canonical durable state.
|
|
124
|
-
|
|
120
|
+
owner and canonical durable state. Dev opens through the local identity entry;
|
|
121
|
+
application mail is silently suppressed in development and demo.
|
|
125
122
|
|
|
126
123
|
Adapters use the shared captured command store for child work. It redacts
|
|
127
124
|
registered credential values from terminal output and private logs, records
|
|
@@ -145,7 +142,7 @@ exports and deployment receipts.
|
|
|
145
142
|
Each first-party adapter declares which resources local export/import supports.
|
|
146
143
|
Every first-party seed verifies a complete local export/import/export round
|
|
147
144
|
trip across those resources. Archives are private and integrity-checked;
|
|
148
|
-
owner/auth,
|
|
145
|
+
owner/auth, historical development mail, private settings and transient runtime state remain
|
|
149
146
|
excluded. Import validates and restores atomically into an empty destination.
|
|
150
147
|
Remote transfer is supported only when every required resource has a complete
|
|
151
148
|
adapter implementation; unsupported targets fail visibly.
|