Events 3.0: auto-connect, demo people in Accounts, e2e; import.finish checks the subs
- contracts 1.8.0 / Accounts 1.1.0: import.finish lists the subs the product relies on; Accounts checks each is held, not deleted and known to it (the count+hash failed a second move after Undo once someone had joined through Accounts). - Events: connects to the church's Accounts once the Hub lists it; moveNewPeople (demo data, people added after the move); set-demo moves demo people; e2e/sign-in-accounts.spec.ts with Accounts in memory and an e2e-only /api rewrite. test:accounts 14/14; Jest auto-connect tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -97,14 +97,18 @@ export const importBatchSchema = base.extend({
|
||||
people: z.array(importPersonSchema).min(1).max(IMPORT_BATCH_MAX),
|
||||
});
|
||||
|
||||
/** At most this many subs in an `import.finish`. */
|
||||
export const IMPORT_FINISH_MAX = 50_000;
|
||||
|
||||
/**
|
||||
* Ends a move: Accounts compares the count and the hash (`importIdsHash`) of the **subs** it gave
|
||||
* back (`created`, `updated` and `linked`) with the people it holds as moved from this product.
|
||||
* Ends a move: every account the product now relies on (each of its users' `sub`). Accounts checks
|
||||
* each is an account it holds, not deleted, and known to this product (moved in, added, or signed
|
||||
* in through it), and only then ends the move. So people who signed up through Accounts since an
|
||||
* earlier move, or a move run again after a failure, check out too.
|
||||
*/
|
||||
export const importFinishSchema = base.extend({
|
||||
type: z.literal("import.finish"),
|
||||
count: z.int().nonnegative(),
|
||||
idsHash: z.string().regex(/^[0-9a-f]{64}$/),
|
||||
subs: z.array(idSchema).max(IMPORT_FINISH_MAX),
|
||||
});
|
||||
|
||||
export const importAbortSchema = base.extend({ type: z.literal("import.abort") });
|
||||
@@ -172,8 +176,12 @@ export const importBatchReplySchema = z.object({
|
||||
|
||||
export const importFinishReplySchema = z.object({
|
||||
schema: z.literal(IDENTITY_REQUEST_SCHEMA),
|
||||
/** Every sub checked out; the move has ended. */
|
||||
matched: z.boolean(),
|
||||
/** How many of the subs Accounts holds for this product. */
|
||||
count: z.int().nonnegative(),
|
||||
/** Some of the subs that didn't check out (at most 100). */
|
||||
missing: z.array(idSchema).max(100),
|
||||
});
|
||||
|
||||
export const peopleEnsureReplySchema = z.object({
|
||||
@@ -188,11 +196,3 @@ export const okReplySchema = z.object({ schema: z.literal(IDENTITY_REQUEST_SCHEM
|
||||
export const IDENTITY_REQUEST_ERROR_CODES = [
|
||||
"NOT_LINKED", "BAD_SIGNATURE", "STALE_REQUEST", "INVALID_REQUEST", "NOT_MOVING", "WRONG_PRODUCT", "UNKNOWN_PERSON", "EMAIL_TAKEN", "NOT_ALLOWED",
|
||||
] as const;
|
||||
|
||||
/**
|
||||
* The hash `import.finish` carries: SHA-256 (hex) of the sorted ids joined by "\n". Pure JS so it
|
||||
* works in the browser build too; products compute it over the ids they sent (not `refused`).
|
||||
*/
|
||||
export function importIdsInput(ids: Iterable<string>): string {
|
||||
return [...ids].sort().join("\n");
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
createCipheriv,
|
||||
createDecipheriv,
|
||||
createHash,
|
||||
createHmac,
|
||||
createPrivateKey,
|
||||
createPublicKey,
|
||||
@@ -16,7 +15,6 @@ import {
|
||||
} from "node:crypto";
|
||||
import { AGENT_HEADERS, type Sealed } from "./agent";
|
||||
import { canonicalJson } from "./canonical";
|
||||
import { importIdsInput } from "./identity-request";
|
||||
|
||||
export { canonicalJson } from "./canonical";
|
||||
|
||||
@@ -324,8 +322,3 @@ export function openLinkValue(linkSecret: string, sealed: string): string {
|
||||
decipher.setAuthTag(raw.subarray(raw.length - 16));
|
||||
return Buffer.concat([decipher.update(raw.subarray(12, raw.length - 16)), decipher.final()]).toString("utf8");
|
||||
}
|
||||
|
||||
/** The `idsHash` of `import.finish`: SHA-256 (hex) of the sorted ids joined by "\n". */
|
||||
export function importIdsHash(ids: Iterable<string>): string {
|
||||
return createHash("sha256").update(importIdsInput(ids)).digest("hex");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user