@benchme/site-kit 0.10.0 → 0.11.0

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 (61) hide show
  1. package/dist/auth-service.d.ts +9 -1
  2. package/dist/auth-service.js +14 -3
  3. package/dist/auth-service.js.map +1 -1
  4. package/dist/domain-error.d.ts +6 -0
  5. package/dist/domain-error.js +12 -0
  6. package/dist/domain-error.js.map +1 -0
  7. package/dist/doors/caller.d.ts +25 -0
  8. package/dist/doors/caller.js +22 -0
  9. package/dist/doors/caller.js.map +1 -0
  10. package/dist/doors/door.d.ts +23 -0
  11. package/dist/doors/door.js +30 -0
  12. package/dist/doors/door.js.map +1 -0
  13. package/dist/doors/register-doors.d.ts +44 -0
  14. package/dist/doors/register-doors.js +92 -0
  15. package/dist/doors/register-doors.js.map +1 -0
  16. package/dist/doors/session-carrier.d.ts +42 -0
  17. package/dist/doors/session-carrier.js +44 -0
  18. package/dist/doors/session-carrier.js.map +1 -0
  19. package/dist/doors/sign-in-tools.d.ts +23 -0
  20. package/dist/doors/sign-in-tools.js +69 -0
  21. package/dist/doors/sign-in-tools.js.map +1 -0
  22. package/dist/doors/sign-in.d.ts +20 -0
  23. package/dist/doors/sign-in.js +31 -0
  24. package/dist/doors/sign-in.js.map +1 -0
  25. package/dist/index.d.ts +16 -2
  26. package/dist/index.js +16 -2
  27. package/dist/index.js.map +1 -1
  28. package/dist/ledger/auth-rules.d.ts +11 -0
  29. package/dist/ledger/auth-rules.js +21 -0
  30. package/dist/ledger/auth-rules.js.map +1 -0
  31. package/dist/ledger/entry.d.ts +219 -0
  32. package/dist/ledger/entry.js +40 -0
  33. package/dist/ledger/entry.js.map +1 -0
  34. package/dist/ledger/ledger-route.d.ts +15 -0
  35. package/dist/ledger/ledger-route.js +25 -0
  36. package/dist/ledger/ledger-route.js.map +1 -0
  37. package/dist/ledger/ledger.d.ts +38 -0
  38. package/dist/ledger/ledger.js +55 -0
  39. package/dist/ledger/ledger.js.map +1 -0
  40. package/dist/ledger/ledgered.d.ts +36 -0
  41. package/dist/ledger/ledgered.js +108 -0
  42. package/dist/ledger/ledgered.js.map +1 -0
  43. package/dist/ledger/rules.d.ts +45 -0
  44. package/dist/ledger/rules.js +22 -0
  45. package/dist/ledger/rules.js.map +1 -0
  46. package/dist/ledger/schema.d.ts +23 -0
  47. package/dist/ledger/schema.js +56 -0
  48. package/dist/ledger/schema.js.map +1 -0
  49. package/dist/mcp-server.d.ts +11 -6
  50. package/dist/mcp-server.js +24 -15
  51. package/dist/mcp-server.js.map +1 -1
  52. package/dist/refusal.d.ts +8 -0
  53. package/dist/refusal.js +8 -0
  54. package/dist/refusal.js.map +1 -0
  55. package/dist/users-repo.d.ts +32 -0
  56. package/dist/users-repo.js +69 -0
  57. package/dist/users-repo.js.map +1 -1
  58. package/dist/webmcp.d.ts +2 -1
  59. package/dist/webmcp.js +4 -2
  60. package/dist/webmcp.js.map +1 -1
  61. package/package.json +2 -2
package/dist/index.d.ts CHANGED
@@ -1,10 +1,24 @@
1
1
  export { registerWorkspaceScope, header } from "./workspace-scope.js";
2
- export { PgUsersRepo, type UserRow, type UsersRepo } from "./users-repo.js";
2
+ export { MemoryUsersRepo, PgUsersRepo, seedAccounts, type SeedAccount, type UserRow, type UsersRepo } from "./users-repo.js";
3
3
  export { AuthError, AuthService, type AuthDeps, type Mailer, type VerificationCopy } from "./auth-service.js";
4
4
  export { HttpMailer } from "./http-mailer.js";
5
5
  export { ToolRegistry, type ToolDef } from "./tool-registry.js";
6
6
  export { toolInputJsonSchema, type JsonSchemaObject } from "./tool-schema.js";
7
- export { DomainError, buildMcpServer, registerMcp, type McpDeps } from "./mcp-server.js";
7
+ export { DomainError, buildMcpServer, newMcpSessionId, registerMcp, type McpDeps } from "./mcp-server.js";
8
+ export { refusalOf, type Refusal } from "./refusal.js";
9
+ export { DOORS, DOOR_HEADER, WEBMCP_DOOR_VALUE, doorOf, type Door } from "./doors/door.js";
10
+ export { CallerScope, once, type Caller } from "./doors/caller.js";
11
+ export { MCP_SESSION_HEADER, registerDoors, type Doors, type DoorsDeps } from "./doors/register-doors.js";
12
+ export { SIGN_IN_REQUIRED_CODE, SignInRequired } from "./doors/sign-in.js";
13
+ export { SIGN_IN_TOOLS, registerSignInTools, type SignInToolsDeps } from "./doors/sign-in-tools.js";
14
+ export { CookieCarrier, McpSessionCarrier, NoCarrier, isMcpSessionId, type Session, type SessionCarrier } from "./doors/session-carrier.js";
15
+ export { AUTH_LEDGER } from "./ledger/auth-rules.js";
16
+ export { LEDGER_KINDS, LEDGER_OUTCOMES, NOT_FOUND_CODE, READ_ACTION, ledgerEntrySchema, ledgerPageSchema, type LedgerEntry, type LedgerKind, type LedgerOutcome, type LedgerPage, type NewLedgerEntry } from "./ledger/entry.js";
17
+ export { MemoryLedger, PgLedger, type Ledger } from "./ledger/ledger.js";
18
+ export { ledgerPath, registerLedgerRoute } from "./ledger/ledger-route.js";
19
+ export { ledgered, untransacted, type LedgeredDeps } from "./ledger/ledgered.js";
20
+ export { about, authStep, read, unrecorded, write, type LedgerRule, type LedgerRules, type Recorded, type Subject, type Unrecorded } from "./ledger/rules.js";
21
+ export { LEDGER_MIGRATIONS, ledgerSql, ledgerSubjectSql, ledgerTableSql } from "./ledger/schema.js";
8
22
  export { esc, money, shell, authPages, type NavLink, type ShellCtx } from "./html.js";
9
23
  export { webmcpScript, WEBMCP_SCRIPT_MARKER, WEBMCP_REGISTER_GLOBAL } from "./webmcp.js";
10
24
  export { registerAuthRoutes, requireSession, sessionUser, apiUser, type AuthRoutesDeps, type SessionUser } from "./auth-routes.js";
package/dist/index.js CHANGED
@@ -1,10 +1,24 @@
1
1
  export { registerWorkspaceScope, header } from "./workspace-scope.js";
2
- export { PgUsersRepo } from "./users-repo.js";
2
+ export { MemoryUsersRepo, PgUsersRepo, seedAccounts } from "./users-repo.js";
3
3
  export { AuthError, AuthService } from "./auth-service.js";
4
4
  export { HttpMailer } from "./http-mailer.js";
5
5
  export { ToolRegistry } from "./tool-registry.js";
6
6
  export { toolInputJsonSchema } from "./tool-schema.js";
7
- export { DomainError, buildMcpServer, registerMcp } from "./mcp-server.js";
7
+ export { DomainError, buildMcpServer, newMcpSessionId, registerMcp } from "./mcp-server.js";
8
+ export { refusalOf } from "./refusal.js";
9
+ export { DOORS, DOOR_HEADER, WEBMCP_DOOR_VALUE, doorOf } from "./doors/door.js";
10
+ export { CallerScope, once } from "./doors/caller.js";
11
+ export { MCP_SESSION_HEADER, registerDoors } from "./doors/register-doors.js";
12
+ export { SIGN_IN_REQUIRED_CODE, SignInRequired } from "./doors/sign-in.js";
13
+ export { SIGN_IN_TOOLS, registerSignInTools } from "./doors/sign-in-tools.js";
14
+ export { CookieCarrier, McpSessionCarrier, NoCarrier, isMcpSessionId } from "./doors/session-carrier.js";
15
+ export { AUTH_LEDGER } from "./ledger/auth-rules.js";
16
+ export { LEDGER_KINDS, LEDGER_OUTCOMES, NOT_FOUND_CODE, READ_ACTION, ledgerEntrySchema, ledgerPageSchema } from "./ledger/entry.js";
17
+ export { MemoryLedger, PgLedger } from "./ledger/ledger.js";
18
+ export { ledgerPath, registerLedgerRoute } from "./ledger/ledger-route.js";
19
+ export { ledgered, untransacted } from "./ledger/ledgered.js";
20
+ export { about, authStep, read, unrecorded, write } from "./ledger/rules.js";
21
+ export { LEDGER_MIGRATIONS, ledgerSql, ledgerSubjectSql, ledgerTableSql } from "./ledger/schema.js";
8
22
  export { esc, money, shell, authPages } from "./html.js";
9
23
  export { webmcpScript, WEBMCP_SCRIPT_MARKER, WEBMCP_REGISTER_GLOBAL } from "./webmcp.js";
10
24
  export { registerAuthRoutes, requireSession, sessionUser, apiUser } from "./auth-routes.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,WAAW,EA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AAM,aAAa,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAyC,MAAM,kBAAkB,CAAC;AACnI,OAAO,EACL,cAAc,EACd,OAAO,EACP,eAAe,EACf,KAAK,EACL,YAAY,EACZ,MAAM,EACN,KAAK,EACL,OAAO,EACP,QAAQ,EACR,OAAO,GAER,MAAM,aAAa,CAAC;AACrB,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { AuthService } from "../auth-service.js";
2
+ import { type LedgerRules } from "./rules.js";
3
+ /**
4
+ * What a site's ledger keeps of signing up and in, whichever door it was done
5
+ * through (the pages' forms and the sign-in tools both call the one
6
+ * AuthService): each step with the account's email, and a refused one with its
7
+ * reason (`EXISTS`, `BAD_CODE`, `BAD_CREDENTIALS`, `UNVERIFIED`). They are
8
+ * `auth` entries: an account is not a change to what the site sells. Looking a
9
+ * session up, which every request does, is not recorded.
10
+ */
11
+ export declare const AUTH_LEDGER: LedgerRules<AuthService>;
@@ -0,0 +1,21 @@
1
+ import { authStep, unrecorded } from "./rules.js";
2
+ const email = (address) => address.trim().toLowerCase();
3
+ /**
4
+ * What a site's ledger keeps of signing up and in, whichever door it was done
5
+ * through (the pages' forms and the sign-in tools both call the one
6
+ * AuthService): each step with the account's email, and a refused one with its
7
+ * reason (`EXISTS`, `BAD_CODE`, `BAD_CREDENTIALS`, `UNVERIFIED`). They are
8
+ * `auth` entries: an account is not a change to what the site sells. Looking a
9
+ * session up, which every request does, is not recorded.
10
+ */
11
+ export const AUTH_LEDGER = {
12
+ signup: authStep("sign_up", ([address]) => email(address)),
13
+ verify: authStep("verify", ([address]) => email(address)),
14
+ login: authStep("sign_in", ([address]) => email(address)),
15
+ logout: authStep("sign_out", () => null),
16
+ issueApiToken: authStep("issue_token", ([address]) => email(address)),
17
+ sendVerification: unrecorded,
18
+ userForSession: unrecorded,
19
+ userForApiToken: unrecorded,
20
+ };
21
+ //# sourceMappingURL=auth-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-rules.js","sourceRoot":"","sources":["../../src/ledger/auth-rules.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAoB,MAAM,YAAY,CAAC;AAEpE,MAAM,KAAK,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;AAEhE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAA6B;IACnD,MAAM,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1D,MAAM,EAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACzD,KAAK,EAAE,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACzD,MAAM,EAAE,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC;IACxC,aAAa,EAAE,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACrE,gBAAgB,EAAE,UAAU;IAC5B,cAAc,EAAE,UAAU;IAC1B,eAAe,EAAE,UAAU;CAC5B,CAAC"}
@@ -0,0 +1,219 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * What an entry records: a `read` of one entity, a `write` (a change to the
4
+ * site's rows, made or refused), or an `auth` step (an account signed up,
5
+ * verified, signed in). Only a `write` is a change to what the site sells.
6
+ */
7
+ export declare const LEDGER_KINDS: readonly ["read", "write", "auth"];
8
+ export type LedgerKind = (typeof LEDGER_KINDS)[number];
9
+ export declare const LEDGER_OUTCOMES: readonly ["ok", "refused"];
10
+ export type LedgerOutcome = (typeof LEDGER_OUTCOMES)[number];
11
+ /** The action of every `read` entry. A write's action is the site's own verb (create, cancel, change …). */
12
+ export declare const READ_ACTION = "read";
13
+ /** The code of a read that found nothing. */
14
+ export declare const NOT_FOUND_CODE = "NOT_FOUND";
15
+ /** One line of a site's change ledger, as the verifier reads it. */
16
+ export declare const ledgerEntrySchema: z.ZodObject<{
17
+ /** Order within one app's ledger. */
18
+ seq: z.ZodNumber;
19
+ /** When it happened, by the database's clock (ISO 8601, UTC). */
20
+ at: z.ZodString;
21
+ app: z.ZodString;
22
+ kind: z.ZodEnum<["read", "write", "auth"]>;
23
+ /** `id` is null when there is no entity yet: a create the rules refused. */
24
+ entity: z.ZodObject<{
25
+ type: z.ZodString;
26
+ id: z.ZodNullable<z.ZodString>;
27
+ }, "strip", z.ZodTypeAny, {
28
+ id: string | null;
29
+ type: string;
30
+ }, {
31
+ id: string | null;
32
+ type: string;
33
+ }>;
34
+ /**
35
+ * What the request was about, when it names something other than the entity it makes or changes: the order a
36
+ * return is for, the showtime a booking is for, the event a registration is for. A refused create has no entity
37
+ * id, so this is what says which one it was. Null when the request names nothing else.
38
+ */
39
+ subject: z.ZodNullable<z.ZodObject<{
40
+ type: z.ZodString;
41
+ id: z.ZodString;
42
+ }, "strip", z.ZodTypeAny, {
43
+ id: string;
44
+ type: string;
45
+ }, {
46
+ id: string;
47
+ type: string;
48
+ }>>;
49
+ action: z.ZodString;
50
+ door: z.ZodEnum<["page", "rest", "mcp", "webmcp"]>;
51
+ /** The email signed in on the request, or null for nobody. */
52
+ actor: z.ZodNullable<z.ZodString>;
53
+ outcome: z.ZodEnum<["ok", "refused"]>;
54
+ /** The site's reason code when refused, else null. */
55
+ code: z.ZodNullable<z.ZodString>;
56
+ }, "strip", z.ZodTypeAny, {
57
+ code: string | null;
58
+ at: string;
59
+ seq: number;
60
+ app: string;
61
+ kind: "read" | "write" | "auth";
62
+ entity: {
63
+ id: string | null;
64
+ type: string;
65
+ };
66
+ subject: {
67
+ id: string;
68
+ type: string;
69
+ } | null;
70
+ action: string;
71
+ door: "rest" | "page" | "mcp" | "webmcp";
72
+ actor: string | null;
73
+ outcome: "ok" | "refused";
74
+ }, {
75
+ code: string | null;
76
+ at: string;
77
+ seq: number;
78
+ app: string;
79
+ kind: "read" | "write" | "auth";
80
+ entity: {
81
+ id: string | null;
82
+ type: string;
83
+ };
84
+ subject: {
85
+ id: string;
86
+ type: string;
87
+ } | null;
88
+ action: string;
89
+ door: "rest" | "page" | "mcp" | "webmcp";
90
+ actor: string | null;
91
+ outcome: "ok" | "refused";
92
+ }>;
93
+ export type LedgerEntry = z.infer<typeof ledgerEntrySchema>;
94
+ /** What a site hands the ledger; the ledger adds the order, the time and the app. */
95
+ export type NewLedgerEntry = Omit<LedgerEntry, "seq" | "at" | "app">;
96
+ /** A page of entries, in the envelope the sites' list routes use. */
97
+ export declare const ledgerPageSchema: z.ZodObject<{
98
+ items: z.ZodArray<z.ZodObject<{
99
+ /** Order within one app's ledger. */
100
+ seq: z.ZodNumber;
101
+ /** When it happened, by the database's clock (ISO 8601, UTC). */
102
+ at: z.ZodString;
103
+ app: z.ZodString;
104
+ kind: z.ZodEnum<["read", "write", "auth"]>;
105
+ /** `id` is null when there is no entity yet: a create the rules refused. */
106
+ entity: z.ZodObject<{
107
+ type: z.ZodString;
108
+ id: z.ZodNullable<z.ZodString>;
109
+ }, "strip", z.ZodTypeAny, {
110
+ id: string | null;
111
+ type: string;
112
+ }, {
113
+ id: string | null;
114
+ type: string;
115
+ }>;
116
+ /**
117
+ * What the request was about, when it names something other than the entity it makes or changes: the order a
118
+ * return is for, the showtime a booking is for, the event a registration is for. A refused create has no entity
119
+ * id, so this is what says which one it was. Null when the request names nothing else.
120
+ */
121
+ subject: z.ZodNullable<z.ZodObject<{
122
+ type: z.ZodString;
123
+ id: z.ZodString;
124
+ }, "strip", z.ZodTypeAny, {
125
+ id: string;
126
+ type: string;
127
+ }, {
128
+ id: string;
129
+ type: string;
130
+ }>>;
131
+ action: z.ZodString;
132
+ door: z.ZodEnum<["page", "rest", "mcp", "webmcp"]>;
133
+ /** The email signed in on the request, or null for nobody. */
134
+ actor: z.ZodNullable<z.ZodString>;
135
+ outcome: z.ZodEnum<["ok", "refused"]>;
136
+ /** The site's reason code when refused, else null. */
137
+ code: z.ZodNullable<z.ZodString>;
138
+ }, "strip", z.ZodTypeAny, {
139
+ code: string | null;
140
+ at: string;
141
+ seq: number;
142
+ app: string;
143
+ kind: "read" | "write" | "auth";
144
+ entity: {
145
+ id: string | null;
146
+ type: string;
147
+ };
148
+ subject: {
149
+ id: string;
150
+ type: string;
151
+ } | null;
152
+ action: string;
153
+ door: "rest" | "page" | "mcp" | "webmcp";
154
+ actor: string | null;
155
+ outcome: "ok" | "refused";
156
+ }, {
157
+ code: string | null;
158
+ at: string;
159
+ seq: number;
160
+ app: string;
161
+ kind: "read" | "write" | "auth";
162
+ entity: {
163
+ id: string | null;
164
+ type: string;
165
+ };
166
+ subject: {
167
+ id: string;
168
+ type: string;
169
+ } | null;
170
+ action: string;
171
+ door: "rest" | "page" | "mcp" | "webmcp";
172
+ actor: string | null;
173
+ outcome: "ok" | "refused";
174
+ }>, "many">;
175
+ nextCursor: z.ZodNullable<z.ZodString>;
176
+ }, "strip", z.ZodTypeAny, {
177
+ items: {
178
+ code: string | null;
179
+ at: string;
180
+ seq: number;
181
+ app: string;
182
+ kind: "read" | "write" | "auth";
183
+ entity: {
184
+ id: string | null;
185
+ type: string;
186
+ };
187
+ subject: {
188
+ id: string;
189
+ type: string;
190
+ } | null;
191
+ action: string;
192
+ door: "rest" | "page" | "mcp" | "webmcp";
193
+ actor: string | null;
194
+ outcome: "ok" | "refused";
195
+ }[];
196
+ nextCursor: string | null;
197
+ }, {
198
+ items: {
199
+ code: string | null;
200
+ at: string;
201
+ seq: number;
202
+ app: string;
203
+ kind: "read" | "write" | "auth";
204
+ entity: {
205
+ id: string | null;
206
+ type: string;
207
+ };
208
+ subject: {
209
+ id: string;
210
+ type: string;
211
+ } | null;
212
+ action: string;
213
+ door: "rest" | "page" | "mcp" | "webmcp";
214
+ actor: string | null;
215
+ outcome: "ok" | "refused";
216
+ }[];
217
+ nextCursor: string | null;
218
+ }>;
219
+ export type LedgerPage = z.infer<typeof ledgerPageSchema>;
@@ -0,0 +1,40 @@
1
+ import { z } from "zod";
2
+ import { DOORS } from "../doors/door.js";
3
+ /**
4
+ * What an entry records: a `read` of one entity, a `write` (a change to the
5
+ * site's rows, made or refused), or an `auth` step (an account signed up,
6
+ * verified, signed in). Only a `write` is a change to what the site sells.
7
+ */
8
+ export const LEDGER_KINDS = ["read", "write", "auth"];
9
+ export const LEDGER_OUTCOMES = ["ok", "refused"];
10
+ /** The action of every `read` entry. A write's action is the site's own verb (create, cancel, change …). */
11
+ export const READ_ACTION = "read";
12
+ /** The code of a read that found nothing. */
13
+ export const NOT_FOUND_CODE = "NOT_FOUND";
14
+ /** One line of a site's change ledger, as the verifier reads it. */
15
+ export const ledgerEntrySchema = z.object({
16
+ /** Order within one app's ledger. */
17
+ seq: z.number().int().positive(),
18
+ /** When it happened, by the database's clock (ISO 8601, UTC). */
19
+ at: z.string().datetime(),
20
+ app: z.string().min(1),
21
+ kind: z.enum(LEDGER_KINDS),
22
+ /** `id` is null when there is no entity yet: a create the rules refused. */
23
+ entity: z.object({ type: z.string().min(1), id: z.string().nullable() }),
24
+ /**
25
+ * What the request was about, when it names something other than the entity it makes or changes: the order a
26
+ * return is for, the showtime a booking is for, the event a registration is for. A refused create has no entity
27
+ * id, so this is what says which one it was. Null when the request names nothing else.
28
+ */
29
+ subject: z.object({ type: z.string().min(1), id: z.string().min(1) }).nullable(),
30
+ action: z.string().min(1),
31
+ door: z.enum(DOORS),
32
+ /** The email signed in on the request, or null for nobody. */
33
+ actor: z.string().nullable(),
34
+ outcome: z.enum(LEDGER_OUTCOMES),
35
+ /** The site's reason code when refused, else null. */
36
+ code: z.string().nullable(),
37
+ });
38
+ /** A page of entries, in the envelope the sites' list routes use. */
39
+ export const ledgerPageSchema = z.object({ items: z.array(ledgerEntrySchema), nextCursor: z.string().nullable() });
40
+ //# sourceMappingURL=entry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.js","sourceRoot":"","sources":["../../src/ledger/entry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAU,CAAC;AAG/D,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,SAAS,CAAU,CAAC;AAG1D,4GAA4G;AAC5G,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC;AAClC,6CAA6C;AAC7C,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC;AAE1C,oEAAoE;AACpE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,qCAAqC;IACrC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAChC,iEAAiE;IACjE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACzB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC;IAC1B,4EAA4E;IAC5E,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC;IACxE;;;;OAIG;IACH,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;IAChF,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACzB,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;IACnB,8DAA8D;IAC9D,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC;IAChC,sDAAsD;IACtD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC5B,CAAC,CAAC;AAMH,qEAAqE;AACrE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { FastifyInstance } from "fastify";
2
+ import type { Ledger } from "./ledger.js";
3
+ /** Where the verifier reads a workspace's ledger, on the app's own address. */
4
+ export declare const ledgerPath: (workspaceId: string) => string;
5
+ /**
6
+ * The ledger's only reader is the verifier, behind two locks. The route sits
7
+ * under /internal/workspaces/, which the gateway never proxies, so no address
8
+ * an agent can open leads here. And it answers only a request that carries the
9
+ * verifier's signature, made with the gateway secret no client holds: a
10
+ * request without one is told there is no such page.
11
+ */
12
+ export declare function registerLedgerRoute(app: FastifyInstance, d: {
13
+ ledger: Ledger;
14
+ gatewaySecret: string;
15
+ }): void;
@@ -0,0 +1,25 @@
1
+ import { VERIFIER_SIG_HEADER, verifyVerifierHeader } from "@benchme/core";
2
+ import { z } from "zod";
3
+ import { header } from "../workspace-scope.js";
4
+ /** Where the verifier reads a workspace's ledger, on the app's own address. */
5
+ export const ledgerPath = (workspaceId) => `/internal/workspaces/${workspaceId}/ledger`;
6
+ const query = z.object({ cursor: z.coerce.number().int().min(0).default(0), limit: z.coerce.number().int().min(1).max(1000).default(500) });
7
+ /**
8
+ * The ledger's only reader is the verifier, behind two locks. The route sits
9
+ * under /internal/workspaces/, which the gateway never proxies, so no address
10
+ * an agent can open leads here. And it answers only a request that carries the
11
+ * verifier's signature, made with the gateway secret no client holds: a
12
+ * request without one is told there is no such page.
13
+ */
14
+ export function registerLedgerRoute(app, d) {
15
+ app.get("/internal/workspaces/:id/ledger", async (req, reply) => {
16
+ const fromVerifier = verifyVerifierHeader(d.gatewaySecret, req.workspaceId, header(req, VERIFIER_SIG_HEADER) ?? "");
17
+ if (!fromVerifier || req.params.id !== req.workspaceId)
18
+ return reply.code(404).send({ error: "NOT_FOUND" });
19
+ const q = query.parse(req.query);
20
+ const rows = await d.ledger.list(req.workspaceId, q.cursor, q.limit + 1);
21
+ const items = rows.slice(0, q.limit);
22
+ return { items, nextCursor: rows.length > q.limit ? String(items[items.length - 1]?.seq ?? q.cursor) : null };
23
+ });
24
+ }
25
+ //# sourceMappingURL=ledger-route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledger-route.js","sourceRoot":"","sources":["../../src/ledger/ledger-route.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE1E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAI/C,+EAA+E;AAC/E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,WAAmB,EAAU,EAAE,CAAC,wBAAwB,WAAW,SAAS,CAAC;AAExG,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,C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AAK,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAChH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { Transactions } from "@benchme/core";
2
+ import type { LedgerEntry, NewLedgerEntry } from "./entry.js";
3
+ /** A site's change ledger: appended to by the site's rules, read by the verifier alone. */
4
+ export interface Ledger {
5
+ record(ws: string, entry: NewLedgerEntry): Promise<void>;
6
+ /** Entries after `afterSeq`, oldest first, at most `limit`. */
7
+ list(ws: string, afterSeq: number, limit: number): Promise<LedgerEntry[]>;
8
+ }
9
+ /**
10
+ * The same `ledger` table under any app schema (each site's own migration
11
+ * creates it), so every site keeps its own and none share rows. The time is
12
+ * the database's own clock at the insert, one clock for every site.
13
+ *
14
+ * It takes the site's `transactions`, not a pool, so an entry is always
15
+ * written on the connection of the write it records: handed the raw pool, a
16
+ * ledger would commit an entry on its own while its write could still fail.
17
+ */
18
+ export declare class PgLedger implements Ledger {
19
+ private readonly schema;
20
+ /** The app's name on every entry; a site's schema carries its name. */
21
+ private readonly app;
22
+ private readonly pool;
23
+ constructor(db: Pick<Transactions, "pool">, schema: string,
24
+ /** The app's name on every entry; a site's schema carries its name. */
25
+ app?: string);
26
+ record(ws: string, e: NewLedgerEntry): Promise<void>;
27
+ list(ws: string, afterSeq: number, limit: number): Promise<LedgerEntry[]>;
28
+ }
29
+ /** A ledger in memory, for tests of what records into one. `now` is the clock its entries are stamped with. */
30
+ export declare class MemoryLedger implements Ledger {
31
+ private readonly app;
32
+ private readonly now;
33
+ private readonly byWorkspace;
34
+ private seq;
35
+ constructor(app: string, now?: () => Date);
36
+ record(ws: string, e: NewLedgerEntry): Promise<void>;
37
+ list(ws: string, afterSeq?: number, limit?: number): Promise<LedgerEntry[]>;
38
+ }
@@ -0,0 +1,55 @@
1
+ const SCHEMA = /^[a-z_][a-z0-9_]*$/;
2
+ /**
3
+ * The same `ledger` table under any app schema (each site's own migration
4
+ * creates it), so every site keeps its own and none share rows. The time is
5
+ * the database's own clock at the insert, one clock for every site.
6
+ *
7
+ * It takes the site's `transactions`, not a pool, so an entry is always
8
+ * written on the connection of the write it records: handed the raw pool, a
9
+ * ledger would commit an entry on its own while its write could still fail.
10
+ */
11
+ export class PgLedger {
12
+ schema;
13
+ app;
14
+ pool;
15
+ constructor(db, schema,
16
+ /** The app's name on every entry; a site's schema carries its name. */
17
+ app = schema) {
18
+ this.schema = schema;
19
+ this.app = app;
20
+ if (!SCHEMA.test(schema))
21
+ throw new Error(`invalid schema name: ${schema}`);
22
+ this.pool = db.pool;
23
+ }
24
+ async record(ws, e) {
25
+ await this.pool.query(`INSERT INTO ${this.schema}.ledger (workspace_id, kind, entity_type, entity_id, subject_type, subject_id, action, door, actor, outcome, code) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)`, [ws, e.kind, e.entity.type, e.entity.id, e.subject?.type ?? null, e.subject?.id ?? null, e.action, e.door, e.actor, e.outcome, e.code]);
26
+ }
27
+ async list(ws, afterSeq, limit) {
28
+ const r = await this.pool.query(`SELECT seq, at, kind, entity_type, entity_id, subject_type, subject_id, action, door, actor, outcome, code FROM ${this.schema}.ledger WHERE workspace_id = $1 AND seq > $2 ORDER BY seq LIMIT $3`, [ws, afterSeq, limit]);
29
+ return r.rows.map((x) => ({
30
+ seq: Number(x.seq), at: x.at.toISOString(), app: this.app, kind: x.kind, entity: { type: x.entity_type, id: x.entity_id },
31
+ subject: x.subject_type && x.subject_id ? { type: x.subject_type, id: x.subject_id } : null,
32
+ action: x.action, door: x.door, actor: x.actor, outcome: x.outcome, code: x.code,
33
+ }));
34
+ }
35
+ }
36
+ /** A ledger in memory, for tests of what records into one. `now` is the clock its entries are stamped with. */
37
+ export class MemoryLedger {
38
+ app;
39
+ now;
40
+ byWorkspace = new Map();
41
+ seq = 0;
42
+ constructor(app, now = () => new Date()) {
43
+ this.app = app;
44
+ this.now = now;
45
+ }
46
+ async record(ws, e) {
47
+ const entries = this.byWorkspace.get(ws) ?? [];
48
+ entries.push({ ...e, entity: { ...e.entity }, subject: e.subject ? { ...e.subject } : null, seq: ++this.seq, at: this.now().toISOString(), app: this.app });
49
+ this.byWorkspace.set(ws, entries);
50
+ }
51
+ async list(ws, afterSeq = 0, limit = Number.MAX_SAFE_INTEGER) {
52
+ return (this.byWorkspace.get(ws) ?? []).filter((e) => e.seq > afterSeq).slice(0, limit);
53
+ }
54
+ }
55
+ //# sourceMappingURL=ledger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../src/ledger/ledger.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,GAAG,oBAAoB,CAAC;AAEpC;;;;;;;;GAQG;AACH,MAAM,OAAO,QAAQ;IAIA;IAEA;IALF,IAAI,CAAuB;IAC5C,YACE,EAA8B,EACb,MAAc;IAC/B,uEAAuE;IACtD,MAAc,MAAM;QAFpB,WAAM,GAAN,MAAM,CAAQ;QAEd,QAAG,GAAH,GAAG,CAAiB;QAErC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,wBAAwB,MAAM,EAAE,CAAC,CAAC;QAC5E,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,CAAiB;QACxC,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CACnB,eAAe,IAAI,CAAC,MAAM,0KAA0K,EACpM,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CA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,YACmB,GAAW,EACX,MAAkB,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE;QADlC,QAAG,GAAH,GAAG,CAAQ;QACX,QAAG,GAAH,GAAG,CAA+B;IAClD,CAAC;IAEJ,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,CAAiB;QACxC,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;QAC/C,OAAO,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;QAC5J,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAU,EAAE,QAAQ,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,gBAAgB;QAClE,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC1F,CAAC;CACF"}
@@ -0,0 +1,36 @@
1
+ import type { Transactions } from "@benchme/core";
2
+ import type { CallerScope } from "../doors/caller.js";
3
+ import type { Ledger } from "./ledger.js";
4
+ import type { LedgerRules } from "./rules.js";
5
+ export type LedgeredDeps = {
6
+ ledger: Ledger;
7
+ callers: CallerScope;
8
+ /** Where a write and its entry are made one transaction: the site's `transactions(pool)`, whose pool its repositories use. */
9
+ transactions: Pick<Transactions, "run">;
10
+ };
11
+ /** For a site whose rows are not in Postgres (tests): each write runs as it comes, with nothing to make atomic. */
12
+ export declare const untransacted: Pick<Transactions, "run">;
13
+ /**
14
+ * A site's rules with the ledger kept. Pages, REST and the MCP tools (and,
15
+ * through the bridge, the WebMCP tools) all reach a site's rows through one
16
+ * repository, so recording there records every door, and no route or tool can
17
+ * leave it out. The wrapped object is the repository's own type: every caller
18
+ * keeps calling what it called.
19
+ *
20
+ * Each recorded method notes who called (the door and whoever is signed in,
21
+ * from the request's caller scope), then what came of it: `ok`, or `refused`
22
+ * with the rule's reason code. A read that found nothing is refused with
23
+ * NOT_FOUND. The verifier's own reads pass through unrecorded. A call with no
24
+ * caller in scope is a door that never said which one it is, and it throws.
25
+ *
26
+ * It is also where a write asks for a sign-in, for the same reason: asked
27
+ * here, every door asks the same, and a new door cannot forget to. A write by
28
+ * nobody is recorded as refused with the one sign-in code and never reaches
29
+ * the repository; the door it came through says so in its own way.
30
+ *
31
+ * A write (or a step of signing up or in) and its entry are one transaction:
32
+ * both are kept, or neither is, so the ledger never shows a change that did
33
+ * not happen, nor misses one that did. A refused write changed nothing: its
34
+ * transaction is rolled back and the refusal is kept on its own.
35
+ */
36
+ export declare function ledgered<R extends object>(repo: R, rules: LedgerRules<R>, d: LedgeredDeps): R;