@rexezuge/identity 1.0.1 → 1.0.2

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 (2) hide show
  1. package/README.md +61 -0
  2. package/package.json +5 -4
package/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # @rexezuge/identity
2
+
3
+ Account layer with address resolution, user DAOs, and canonical identity migrations.
4
+
5
+ Depends on `@rexezuge/d1` (persistence + statement splitter), `@rexezuge/errors`, and `@rexezuge/shared` (email normalization).
6
+
7
+ ```bash
8
+ pnpm add @rexezuge/identity
9
+ ```
10
+
11
+ ---
12
+
13
+ ## 1. The invariant: the address is not the account
14
+
15
+ A login address can move between accounts, so resolution goes through the verified `user_emails` registry — never the mutable address string — and a revoked row resolves to nothing. The only safe fall-through is a database whose identity migration has not run yet (`isMissingSchemaError`); every other D1 failure rethrows, because a transient error answered with the wrong account is a full cross-account read.
16
+
17
+ ```ts
18
+ import { resolveAccount, type AccountLookupDeps } from '@rexezuge/identity';
19
+
20
+ const account = await resolveAccount(deps, 'user@example.com'); // ResolvedAccount | null
21
+ ```
22
+
23
+ `UserIdentityService` is the stateful service over the same rules (register, verify, resolve); the free functions exist so account bootstrap and the service share one implementation.
24
+
25
+ ## 2. DAOs
26
+
27
+ | Export | Role |
28
+ | --- | --- |
29
+ | `UserDAO` | `users` table: frozen anchor id, lookup by id/anchor/email |
30
+ | `UserEmailDAO` | `user_emails` registry: claims, verification, revocation |
31
+ | `newAccountId` / `newAnchor` | ID generation for new accounts |
32
+ | `summarize` / `AccountSummary` | safe-to-log account projection |
33
+
34
+ ```ts
35
+ import { UserDAO, UserEmailDAO } from '@rexezuge/identity';
36
+
37
+ const users = new UserDAO(env.DB);
38
+ const emails = new UserEmailDAO(env.DB);
39
+ await users.getById(account.id);
40
+ ```
41
+
42
+ ## 3. Migrations
43
+
44
+ ```ts
45
+ import { applyIdentityMigrations } from '@rexezuge/identity';
46
+
47
+ await applyIdentityMigrations(env.DB); // fresh install: users.sql
48
+ await applyIdentityMigrations(env.DB, { upgrade: true }); // legacy DB: + upgrade-user-identity.sql (rerunnable)
49
+ ```
50
+
51
+ Executed through `@rexezuge/d1`'s splitter — one `batch()` per file, matching D1's own per-file apply, so a failure names its file. `IDENTITY_MIGRATIONS` / `IDENTITY_MIGRATION_SQL` carry the same pair as data for repos that apply migrations through their own runner. The upgrade backfills a verified registry row for every anchor, which is what lets pre-identity databases resolve addresses the old way until they migrate.
52
+
53
+ ---
54
+
55
+ ## Verifying this package
56
+
57
+ ```bash
58
+ pnpm --filter @rexezuge/identity exec tsc -p tsconfig.json
59
+ pnpm --filter @rexezuge/identity typecheck
60
+ pnpm --filter @rexezuge/identity test
61
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rexezuge/identity",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -25,15 +25,16 @@
25
25
  "dist"
26
26
  ],
27
27
  "dependencies": {
28
- "@rexezuge/d1": "1.0.1",
29
- "@rexezuge/errors": "1.0.1",
30
- "@rexezuge/shared": "1.0.1"
28
+ "@rexezuge/d1": "1.0.2",
29
+ "@rexezuge/errors": "1.0.2",
30
+ "@rexezuge/shared": "1.0.2"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "26.6.4",
34
34
  "typescript": "6.0.3",
35
35
  "vitest": "4.1.11"
36
36
  },
37
+ "description": "Account layer with address resolution, user DAOs, and canonical identity migrations.",
37
38
  "scripts": {
38
39
  "build": "tsc -p tsconfig.json",
39
40
  "typecheck": "tsc -p tsconfig.test.json --noEmit",