@yielded/auth-persistence 0.1.0-beta.23 → 0.1.0-beta.25

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 (182) hide show
  1. package/README.md +11 -0
  2. package/dist/Adapter.d.mts +12 -6
  3. package/dist/Adapter.mjs +8 -3
  4. package/dist/OAuthPersistence.d.mts +87 -0
  5. package/dist/OAuthPersistence.mjs +125 -0
  6. package/dist/OAuthPersistence.mjs.map +1 -0
  7. package/dist/_virtual/_rolldown/runtime.mjs +13 -0
  8. package/dist/index.d.mts +3 -1
  9. package/dist/index.mjs +3 -1
  10. package/dist/internal/configuration.d.mts +1 -1
  11. package/dist/internal/configuration.mjs.map +1 -1
  12. package/dist/internal/email-kernel.d.mts +1 -1
  13. package/dist/internal/email-kernel.mjs +1 -1
  14. package/dist/internal/email-kernel.mjs.map +1 -1
  15. package/dist/internal/models/oauth-connected-model.d.mts +294 -0
  16. package/dist/internal/models/oauth-connected-model.mjs +22 -0
  17. package/dist/internal/models/oauth-connected-model.mjs.map +1 -0
  18. package/dist/internal/models/oauth-model.d.mts +467 -0
  19. package/dist/internal/models/oauth-model.mjs +49 -0
  20. package/dist/internal/models/oauth-model.mjs.map +1 -0
  21. package/dist/internal/models/password-model.d.mts +6 -48
  22. package/dist/internal/models/password-model.mjs +0 -1
  23. package/dist/internal/models/password-model.mjs.map +1 -1
  24. package/dist/internal/native-sql-table.d.mts +4 -0
  25. package/dist/internal/native-sql-table.mjs +7 -0
  26. package/dist/internal/native-sql-table.mjs.map +1 -1
  27. package/dist/internal/oauth/accounts.d.mts +8 -0
  28. package/dist/internal/oauth/accounts.mjs +379 -0
  29. package/dist/internal/oauth/accounts.mjs.map +1 -0
  30. package/dist/internal/oauth/connected-access.d.mts +9 -0
  31. package/dist/internal/oauth/connected-access.mjs +229 -0
  32. package/dist/internal/oauth/connected-access.mjs.map +1 -0
  33. package/dist/internal/oauth/connected-collection.d.mts +7 -0
  34. package/dist/internal/oauth/connected-collection.mjs +214 -0
  35. package/dist/internal/oauth/connected-collection.mjs.map +1 -0
  36. package/dist/internal/oauth/connected-custody.d.mts +6 -0
  37. package/dist/internal/oauth/connected-custody.mjs +165 -0
  38. package/dist/internal/oauth/connected-custody.mjs.map +1 -0
  39. package/dist/internal/oauth/connected-flow.d.mts +7 -0
  40. package/dist/internal/oauth/connected-flow.mjs +324 -0
  41. package/dist/internal/oauth/connected-flow.mjs.map +1 -0
  42. package/dist/internal/oauth/connected-input.mjs +122 -0
  43. package/dist/internal/oauth/connected-input.mjs.map +1 -0
  44. package/dist/internal/oauth/connected-keys.d.mts +2 -0
  45. package/dist/internal/oauth/connected-keys.mjs +22 -0
  46. package/dist/internal/oauth/connected-keys.mjs.map +1 -0
  47. package/dist/internal/oauth/connected-maintenance.d.mts +9 -0
  48. package/dist/internal/oauth/connected-maintenance.mjs +226 -0
  49. package/dist/internal/oauth/connected-maintenance.mjs.map +1 -0
  50. package/dist/internal/oauth/connected-management.d.mts +9 -0
  51. package/dist/internal/oauth/connected-management.mjs +243 -0
  52. package/dist/internal/oauth/connected-management.mjs.map +1 -0
  53. package/dist/internal/oauth/connected-reference.mjs +63 -0
  54. package/dist/internal/oauth/connected-reference.mjs.map +1 -0
  55. package/dist/internal/oauth/connected-settlement.d.mts +8 -0
  56. package/dist/internal/oauth/connected-settlement.mjs +141 -0
  57. package/dist/internal/oauth/connected-settlement.mjs.map +1 -0
  58. package/dist/internal/oauth/connected-sign-in.d.mts +10 -0
  59. package/dist/internal/oauth/connected-sign-in.mjs +281 -0
  60. package/dist/internal/oauth/connected-sign-in.mjs.map +1 -0
  61. package/dist/internal/oauth/connected-state.d.mts +14 -0
  62. package/dist/internal/oauth/connected-state.mjs +469 -0
  63. package/dist/internal/oauth/connected-state.mjs.map +1 -0
  64. package/dist/internal/oauth/connected-target.d.mts +21 -0
  65. package/dist/internal/oauth/connected-target.mjs +117 -0
  66. package/dist/internal/oauth/connected-target.mjs.map +1 -0
  67. package/dist/internal/oauth/flow.d.mts +5 -0
  68. package/dist/internal/oauth/flow.mjs +279 -0
  69. package/dist/internal/oauth/flow.mjs.map +1 -0
  70. package/dist/internal/oauth/input.mjs +127 -0
  71. package/dist/internal/oauth/input.mjs.map +1 -0
  72. package/dist/internal/oauth/owner.d.mts +10 -0
  73. package/dist/internal/oauth/owner.mjs +10 -0
  74. package/dist/internal/oauth/owner.mjs.map +1 -0
  75. package/dist/internal/oauth/query-compiler.d.mts +7 -0
  76. package/dist/internal/oauth/query-compiler.mjs +9 -0
  77. package/dist/internal/oauth/query-compiler.mjs.map +1 -0
  78. package/dist/internal/oauth/registration.d.mts +7 -0
  79. package/dist/internal/oauth/registration.mjs +393 -0
  80. package/dist/internal/oauth/registration.mjs.map +1 -0
  81. package/dist/internal/oauth/state.mjs +107 -0
  82. package/dist/internal/oauth/state.mjs.map +1 -0
  83. package/dist/internal/oauth/target.d.mts +31 -0
  84. package/dist/internal/oauth/target.mjs +273 -0
  85. package/dist/internal/oauth/target.mjs.map +1 -0
  86. package/dist/internal/oauth-kernel.d.mts +1423 -0
  87. package/dist/internal/oauth-kernel.mjs +187 -0
  88. package/dist/internal/oauth-kernel.mjs.map +1 -0
  89. package/dist/internal/oauth-proxy.d.mts +31 -0
  90. package/dist/internal/oauth-proxy.mjs +129 -0
  91. package/dist/internal/oauth-proxy.mjs.map +1 -0
  92. package/dist/internal/passkey/write-state.mjs +9 -1
  93. package/dist/internal/passkey/write-state.mjs.map +1 -1
  94. package/dist/internal/passkey-kernel.d.mts +9 -9
  95. package/dist/internal/{password-attempts.d.mts → password-credentials.d.mts} +3 -4
  96. package/dist/internal/password-credentials.mjs +121 -0
  97. package/dist/internal/password-credentials.mjs.map +1 -0
  98. package/dist/internal/password-kernel.d.mts +8 -24
  99. package/dist/internal/password-kernel.mjs +5 -43
  100. package/dist/internal/password-kernel.mjs.map +1 -1
  101. package/dist/internal/persistence.d.mts +1 -1
  102. package/dist/internal/persistence.mjs +2 -2
  103. package/dist/internal/persistence.mjs.map +1 -1
  104. package/dist/internal/query-operations.d.mts +2 -0
  105. package/dist/internal/session-kernel.d.mts +2 -2
  106. package/dist/internal/session-kernel.mjs +74 -18
  107. package/dist/internal/session-kernel.mjs.map +1 -1
  108. package/dist/internal/sql-oauth-connected-model.d.mts +29 -0
  109. package/dist/internal/sql-oauth-connected-model.mjs +7 -0
  110. package/dist/internal/sql-oauth-connected-model.mjs.map +1 -0
  111. package/dist/internal/sql-oauth-model.d.mts +60 -0
  112. package/dist/internal/sql-oauth-model.mjs +10 -0
  113. package/dist/internal/sql-oauth-model.mjs.map +1 -0
  114. package/dist/internal/sql-query.d.mts +12 -0
  115. package/dist/internal/sql-query.mjs +15 -18
  116. package/dist/internal/sql-query.mjs.map +1 -1
  117. package/dist/internal/sql-storage-validation.mjs +54 -0
  118. package/dist/internal/sql-storage-validation.mjs.map +1 -0
  119. package/dist/internal/storage-mapping.mjs +1 -37
  120. package/dist/internal/storage-mapping.mjs.map +1 -1
  121. package/dist/internal/storage-plans.d.mts +7 -0
  122. package/dist/internal/storage-plans.mjs +189 -0
  123. package/dist/internal/storage-plans.mjs.map +1 -0
  124. package/dist/internal/storage-tables.d.mts +0 -56
  125. package/dist/internal/storage-tables.mjs +0 -17
  126. package/dist/internal/storage-tables.mjs.map +1 -1
  127. package/dist/internal/storage-validation.d.mts +6 -1
  128. package/dist/internal/storage-validation.mjs +42 -1
  129. package/dist/internal/storage-validation.mjs.map +1 -1
  130. package/dist/internal/transaction-kernel.mjs +3 -2
  131. package/dist/internal/transaction-kernel.mjs.map +1 -1
  132. package/package.json +1 -1
  133. package/src/Adapter.ts +89 -5
  134. package/src/OAuthPersistence.ts +427 -0
  135. package/src/index.ts +3 -0
  136. package/src/internal/configuration.ts +1 -3
  137. package/src/internal/email-kernel.ts +2 -1
  138. package/src/internal/models/oauth-connected-model.ts +396 -0
  139. package/src/internal/models/oauth-model.ts +708 -0
  140. package/src/internal/models/password-model.ts +2 -57
  141. package/src/internal/native-sql-table.ts +14 -0
  142. package/src/internal/oauth/accounts.ts +839 -0
  143. package/src/internal/oauth/connected-access.ts +388 -0
  144. package/src/internal/oauth/connected-collection.ts +345 -0
  145. package/src/internal/oauth/connected-custody.ts +308 -0
  146. package/src/internal/oauth/connected-flow.ts +562 -0
  147. package/src/internal/oauth/connected-input.ts +147 -0
  148. package/src/internal/oauth/connected-keys.ts +31 -0
  149. package/src/internal/oauth/connected-maintenance.ts +379 -0
  150. package/src/internal/oauth/connected-management.ts +391 -0
  151. package/src/internal/oauth/connected-reference.ts +135 -0
  152. package/src/internal/oauth/connected-settlement.ts +278 -0
  153. package/src/internal/oauth/connected-sign-in.ts +472 -0
  154. package/src/internal/oauth/connected-state.ts +924 -0
  155. package/src/internal/oauth/connected-target.ts +307 -0
  156. package/src/internal/oauth/flow.ts +505 -0
  157. package/src/internal/oauth/input.ts +201 -0
  158. package/src/internal/oauth/owner.ts +22 -0
  159. package/src/internal/oauth/query-compiler.ts +15 -0
  160. package/src/internal/oauth/registration.ts +676 -0
  161. package/src/internal/oauth/state.ts +218 -0
  162. package/src/internal/oauth/target.ts +803 -0
  163. package/src/internal/oauth-kernel.ts +294 -0
  164. package/src/internal/oauth-proxy.ts +176 -0
  165. package/src/internal/passkey/write-state.ts +18 -4
  166. package/src/internal/password-credentials.ts +245 -0
  167. package/src/internal/password-kernel.ts +7 -99
  168. package/src/internal/persistence.ts +1 -1
  169. package/src/internal/query-operations.ts +2 -0
  170. package/src/internal/session-kernel.ts +143 -55
  171. package/src/internal/sql-oauth-connected-model.ts +145 -0
  172. package/src/internal/sql-oauth-model.ts +263 -0
  173. package/src/internal/sql-query.ts +16 -13
  174. package/src/internal/sql-storage-validation.ts +64 -0
  175. package/src/internal/storage-mapping.ts +0 -37
  176. package/src/internal/storage-plans.ts +218 -0
  177. package/src/internal/storage-tables.ts +0 -20
  178. package/src/internal/storage-validation.ts +58 -0
  179. package/src/internal/transaction-kernel.ts +6 -2
  180. package/dist/internal/password-attempts.mjs +0 -197
  181. package/dist/internal/password-attempts.mjs.map +0 -1
  182. package/src/internal/password-attempts.ts +0 -466
@@ -0,0 +1,467 @@
1
+ import { PersistenceMappingError } from "../mapping-error.mjs";
2
+ import { SqlExpression, TableModel } from "../query-operations.mjs";
3
+ import { SubjectIdCodec } from "./common.mjs";
4
+ import { Crypto, Effect, PlatformError } from "effect";
5
+ import { TokenDigest } from "@yielded/auth/Schema";
6
+ import { PreparedCommit } from "@yielded/auth/Hooks";
7
+ import { AuthenticationRequirement, SecurityRevision } from "@yielded/auth/Sessions";
8
+ import { OAuthAccountRevision, OAuthActionAuthorization, OAuthCleanupInput, OAuthCommandId, OAuthCredentialSnapshot, OAuthExternalIdentity, OAuthRegistrationAccess, OAuthRegistrationDecision, OAuthRegistrationInspection, OAuthRegistrationIntent, OAuthUnavailable, PrepareOAuthCommit } from "@yielded/auth/OAuth";
9
+ import { AuthenticationFactor } from "@yielded/auth/Operations";
10
+ declare namespace oauth_model_d_exports {
11
+ export { OAuthAccountsMapping, OAuthAction, OAuthAuthorityReadTable, OAuthAuthorityTable, OAuthCleanupDescriptor, OAuthCleanupTable, OAuthClock, OAuthCredentialReadTable, OAuthCredentialTable, OAuthD1Mapping, OAuthEligibilityDescriptor, OAuthEligibilityFact, OAuthEligibilityTable, OAuthFlowState, OAuthFlowTable, OAuthMetadataPolicy, OAuthOwnershipMutation, OAuthOwnershipReadTable, OAuthOwnershipTable, OAuthReferenceGuardDescriptor, OAuthReferenceGuardTable, OAuthRegistrationAuthority, OAuthRegistrationBase, OAuthRegistrationCommandTable, OAuthRegistrationEligibility, OAuthRegistrationGuardDescriptor, OAuthRegistrationGuardTable, OAuthRegistrationIntentMapping, OAuthRegistrationIntentTable, OAuthRegistrationMapping, OAuthRegistrationState, OAuthSignInMapping, OAuthSubjectReadTable, OAuthSubjectTable, OAuthTupleAuthorityTable, OAuthTupleState, OAuthUnlinkCommandTable, oauthCleanupTable, oauthEligibilityTable, oauthReferenceGuardTable, oauthRegistrationGuardTable, requiredOAuthAccountsConstraints, requiredOAuthRegistrationConstraints, requiredOAuthSignInConstraints, requiredOAuthTupleConstraints };
12
+ }
13
+ type Column<T extends TableModel> = T["column"];
14
+ export type OAuthFlowState = "Pending" | "Claimed" | "Verified" | "RegistrationIssued" | "Linked" | "Cancelled" | "Rejected" | "Ambiguous" | "Conflict";
15
+ export type OAuthTupleState = "Unowned" | "Reserved" | "Owned";
16
+ export type OAuthRegistrationState = "Unbound" | "Registered" | "ProvisioningPending" | "Rejected";
17
+ export type OAuthAction = OAuthActionAuthorization["challenge"]["action"];
18
+ /** The engine writes every critical column explicitly after applying the pure
19
+ * consumer encoder. Native instant values must roundtrip without precision loss. */
20
+ export interface OAuthClock<Expression extends SqlExpression = SqlExpression> {
21
+ readonly encodeInstant: (millis: number) => unknown;
22
+ readonly decodeInstant: (value: unknown) => number;
23
+ /** Actual engine wall clock sampled after locks, not transaction-start time.
24
+ * PostgreSQL uses clock_timestamp(), never now()/CURRENT_TIMESTAMP. D1 repeats
25
+ * its primary-engine sample bounds in final guards. Return integer milliseconds. */
26
+ readonly engineNowMillis: Expression;
27
+ }
28
+ export interface OAuthSubjectReadTable<S extends TableModel, Expression extends SqlExpression = SqlExpression> {
29
+ readonly table: S["table"];
30
+ readonly id: Column<S>;
31
+ readonly status: Column<S>;
32
+ readonly securityRevision: Column<S>;
33
+ readonly isActiveStatus: (value: unknown) => boolean;
34
+ readonly activeCondition: Expression;
35
+ }
36
+ export interface OAuthSubjectTable<S extends TableModel, Expression extends SqlExpression = SqlExpression> extends OAuthSubjectReadTable<S, Expression> {
37
+ readonly decodeActionRequirement: (row: S["select"], action: OAuthAction) => AuthenticationRequirement;
38
+ readonly decodeAuthenticationRequirement: (row: S["select"]) => AuthenticationRequirement;
39
+ readonly nextSecurityRevision: (current: SecurityRevision) => SecurityRevision;
40
+ }
41
+ export interface OAuthOwnershipReadTable<O extends TableModel, N, Expression extends SqlExpression = SqlExpression> {
42
+ readonly table: O["table"];
43
+ readonly identityKey: Column<O>;
44
+ readonly provider: Column<O>;
45
+ readonly issuer: Column<O>;
46
+ readonly externalSubject: Column<O>;
47
+ readonly subjectId: Column<O>;
48
+ /** Includes Owned state when authority and ownership share a physical table. */
49
+ readonly ownedCondition: Expression;
50
+ readonly decodeSubjectId: (row: O["select"]) => N;
51
+ }
52
+ export interface OAuthOwnershipTable<O extends TableModel, N, Expression extends SqlExpression = SqlExpression> extends OAuthOwnershipReadTable<O, N, Expression> {
53
+ readonly encodeInsert: (input: {
54
+ readonly identity: typeof OAuthExternalIdentity.Type;
55
+ readonly identityKey: string;
56
+ readonly subjectId: N;
57
+ }) => O["insert"];
58
+ }
59
+ export interface OAuthCredentialReadTable<C extends TableModel, Expression extends SqlExpression = SqlExpression> {
60
+ readonly table: C["table"];
61
+ readonly moduleId: Column<C>;
62
+ readonly credentialId: Column<C>;
63
+ readonly subjectId: Column<C>;
64
+ readonly identityKey: Column<C>;
65
+ readonly credentialRevision: Column<C>;
66
+ readonly status: Column<C>;
67
+ readonly isActiveStatus: (value: unknown) => boolean;
68
+ readonly activeCondition: Expression;
69
+ }
70
+ export interface OAuthCredentialTable<C extends TableModel, N, Expression extends SqlExpression = SqlExpression> extends OAuthCredentialReadTable<C, Expression> {
71
+ readonly encodeInsert: (input: {
72
+ readonly moduleId: string;
73
+ readonly subjectId: N;
74
+ readonly identityKey: string;
75
+ readonly credentialId: string;
76
+ readonly credentialRevision: SecurityRevision;
77
+ }) => C["insert"];
78
+ /** This slice removes login rows. Historical records belong in separate audit storage. */
79
+ readonly removal: "delete";
80
+ }
81
+ export interface OAuthAuthorityReadTable<C extends TableModel, Expression extends SqlExpression = SqlExpression> {
82
+ readonly table: C["table"];
83
+ readonly subjectId: Column<C>;
84
+ readonly credentialId: Column<C>;
85
+ readonly revision: Column<C>;
86
+ readonly status: Column<C>;
87
+ readonly isActiveStatus: (value: unknown) => boolean;
88
+ readonly activeCondition: Expression;
89
+ }
90
+ export interface OAuthAuthorityTable<C extends TableModel, N, Expression extends SqlExpression = SqlExpression> extends OAuthAuthorityReadTable<C, Expression> {
91
+ readonly encodeInsert: (input: {
92
+ readonly subjectId: N;
93
+ readonly credentialId: string;
94
+ readonly revision: SecurityRevision;
95
+ }) => C["insert"];
96
+ }
97
+ /** Both purposes may use the same physical table. Shared tables share module/flow
98
+ * and module/command uniqueness. The snapshot has the exact purpose-specific core
99
+ * codec; terminal writes erase it, while identity, claim and retention columns remain. */
100
+ export interface OAuthFlowTable<F extends TableModel> {
101
+ readonly table: F["table"];
102
+ readonly moduleId: Column<F>;
103
+ readonly flowId: Column<F>;
104
+ readonly commandId: Column<F>;
105
+ readonly purpose: Column<F>;
106
+ readonly generation: Column<F>;
107
+ readonly state: Column<F>;
108
+ readonly version: Column<F>;
109
+ readonly stateDigest: Column<F>;
110
+ readonly binderVerifier: Column<F>;
111
+ readonly binderExpiresAt: Column<F>;
112
+ readonly snapshot: Column<F>;
113
+ readonly issuedAt: Column<F>;
114
+ readonly expiresAt: Column<F>;
115
+ readonly claimId: Column<F>;
116
+ readonly claimedAt: Column<F>;
117
+ readonly claimExpiresAt: Column<F>;
118
+ readonly retentionUntil: Column<F>;
119
+ readonly encodeInsert: (input: {
120
+ readonly moduleId: string;
121
+ readonly flowId: string;
122
+ readonly purpose: "sign-in" | "link";
123
+ }) => F["insert"];
124
+ }
125
+ export interface OAuthTupleAuthorityTable<T extends TableModel, N> {
126
+ readonly table: T["table"];
127
+ readonly identityKey: Column<T>;
128
+ readonly provider: Column<T>;
129
+ readonly issuer: Column<T>;
130
+ readonly externalSubject: Column<T>;
131
+ readonly state: Column<T>;
132
+ readonly version: Column<T>;
133
+ readonly subjectId: Column<T>;
134
+ /** Exact reservation identity; no application payload or bearer. */
135
+ readonly reservation: Column<T>;
136
+ readonly encodeInsert: (input: {
137
+ readonly identityKey: string;
138
+ readonly identity: typeof OAuthExternalIdentity.Type;
139
+ readonly subjectId?: N;
140
+ }) => T["insert"];
141
+ }
142
+ export interface OAuthRegistrationIntentTable<I extends TableModel> {
143
+ readonly table: I["table"];
144
+ readonly moduleId: Column<I>;
145
+ readonly reference: Column<I>;
146
+ readonly flowId: Column<I>;
147
+ readonly claimId: Column<I>;
148
+ readonly identityKey: Column<I>;
149
+ readonly version: Column<I>;
150
+ readonly state: Column<I>;
151
+ readonly snapshot: Column<I>;
152
+ readonly commandId: Column<I>;
153
+ readonly fingerprint: Column<I>;
154
+ readonly pendingReference: Column<I>;
155
+ readonly expiresAt: Column<I>;
156
+ readonly retentionUntil: Column<I>;
157
+ readonly encodeInsert: (intent: OAuthRegistrationIntent) => I["insert"];
158
+ }
159
+ export interface OAuthRegistrationCommandTable<R extends TableModel, Registration> {
160
+ readonly table: R["table"];
161
+ readonly moduleId: Column<R>;
162
+ readonly commandId: Column<R>;
163
+ readonly reference: Column<R>;
164
+ readonly identityKey: Column<R>;
165
+ readonly fingerprint: Column<R>;
166
+ readonly intentSnapshot: Column<R>;
167
+ readonly applicationSnapshot: Column<R>;
168
+ readonly provisioningIdentity: Column<R>;
169
+ readonly decision: Column<R>;
170
+ readonly retentionUntil: Column<R>;
171
+ /** Persists exact detached Type before protected pending work can start. */
172
+ readonly encodeInsert: (input: {
173
+ readonly intent: OAuthRegistrationIntent;
174
+ readonly commandId: string;
175
+ readonly fingerprint: string;
176
+ readonly registration: Registration;
177
+ readonly provisioningIdentity: string;
178
+ }) => R["insert"];
179
+ }
180
+ export interface OAuthUnlinkCommandTable<U extends TableModel> {
181
+ readonly table: U["table"];
182
+ readonly moduleId: Column<U>;
183
+ readonly commandId: Column<U>;
184
+ readonly subjectId: Column<U>;
185
+ readonly credentialId: Column<U>;
186
+ readonly intentSnapshot: Column<U>;
187
+ readonly decision: Column<U>;
188
+ readonly retentionUntil: Column<U>;
189
+ readonly encodeInsert: (input: {
190
+ readonly moduleId: string;
191
+ readonly commandId: string;
192
+ readonly credential: OAuthCredentialSnapshot;
193
+ }) => U["insert"];
194
+ }
195
+ export interface OAuthEligibilityFact {
196
+ readonly credentialId: string;
197
+ readonly revision: SecurityRevision;
198
+ readonly usablePrimary: boolean;
199
+ readonly factors: ReadonlyArray<AuthenticationFactor>;
200
+ readonly userVerified: boolean;
201
+ readonly phishingResistant: boolean;
202
+ }
203
+ /** Each descriptor reads only its own subject-scoped method rows. The native row
204
+ * projector and SQL condition must express the same installed method eligibility.
205
+ * All source/identifier/policy mutations advance subject securityRevision. D1 also
206
+ * guards exact selected IDs/versions and absence/count assumptions, never just a
207
+ * stale boolean. An over-limit graph fails closed rather than truncating. */
208
+ export interface OAuthEligibilityTable<T extends TableModel, N, Expression extends SqlExpression = SqlExpression> {
209
+ readonly table: T["table"];
210
+ readonly subjectId: Column<T>;
211
+ readonly credentialId: Column<T>;
212
+ readonly revision: Column<T>;
213
+ readonly scope: string;
214
+ readonly condition: (subjectId: N) => Expression;
215
+ readonly decode: (row: T["select"]) => OAuthEligibilityFact | undefined;
216
+ }
217
+ /** Authenticated command replay uses current subject status and this additional
218
+ * nonconsuming SQL policy. It never consumes a fresh action factor. */
219
+ export interface OAuthMetadataPolicy<N, Expression extends SqlExpression = SqlExpression> {
220
+ readonly condition: (subjectId: N) => Expression;
221
+ }
222
+ export interface OAuthCleanupTable<T extends TableModel, N, Expression extends SqlExpression = SqlExpression> {
223
+ readonly table: T["table"];
224
+ readonly subjectId: Column<T>;
225
+ /** Bound to this subject's old revision; no opaque independently committing service. */
226
+ readonly condition: (input: {
227
+ readonly subjectId: N;
228
+ readonly revision: OAuthAccountRevision;
229
+ readonly removedCredentialId?: string;
230
+ }) => Expression;
231
+ readonly disposition: "delete";
232
+ }
233
+ export interface OAuthRegistrationEligibility<N, Expression extends SqlExpression = SqlExpression> {
234
+ /** Pure SQL guards for mutable app policy; evaluated again after app writes. */
235
+ readonly condition: (input: {
236
+ readonly intent: OAuthRegistrationIntent;
237
+ readonly nativeSubjectId?: N;
238
+ }) => Expression;
239
+ }
240
+ export interface OAuthD1Mapping {
241
+ readonly d1: {
242
+ readonly primary: true;
243
+ };
244
+ }
245
+ export declare const requiredOAuthSignInConstraints: {
246
+ readonly flow: "unique(flow.moduleId,flow.flowId)";
247
+ readonly command: "unique(flow.moduleId,flow.commandId)";
248
+ readonly stateDigest: "unique(flow.stateDigest)";
249
+ readonly ownership: "unique(ownership.identityKey)";
250
+ readonly credentialId: "unique(credential.credentialId)";
251
+ readonly credentialIdentity: "unique(credential.identityKey)";
252
+ readonly authorityCredential: "unique(authority.subjectId,authority.credentialId)";
253
+ };
254
+ export declare const requiredOAuthTupleConstraints: {
255
+ readonly identityKey: "unique(tuple.identityKey)";
256
+ };
257
+ export declare const requiredOAuthRegistrationConstraints: {
258
+ readonly intentReference: "unique(intent.moduleId,intent.reference)";
259
+ readonly intentFlow: "unique(intent.moduleId,intent.flowId)";
260
+ readonly command: "unique(registrationCommand.moduleId,registrationCommand.commandId)";
261
+ };
262
+ export declare const requiredOAuthAccountsConstraints: {
263
+ readonly unlinkCommand: "unique(unlinkCommand.moduleId,unlinkCommand.commandId)";
264
+ };
265
+ export interface OAuthSignInMapping<S extends TableModel, O extends TableModel, C extends TableModel, AC extends TableModel, F extends TableModel, N, Expression extends SqlExpression = SqlExpression> {
266
+ readonly subject: OAuthSubjectReadTable<S, Expression>;
267
+ readonly ownership: OAuthOwnershipReadTable<O, N, Expression>;
268
+ readonly credential: OAuthCredentialReadTable<C, Expression>;
269
+ readonly authority: OAuthAuthorityReadTable<AC, Expression>;
270
+ readonly flow: OAuthFlowTable<F>;
271
+ readonly subjectId: SubjectIdCodec<N>;
272
+ readonly clock: OAuthClock<Expression>;
273
+ readonly constraints: typeof requiredOAuthSignInConstraints;
274
+ }
275
+ export type OAuthOwnershipMutation<T extends TableModel, O extends TableModel, N, Expression extends SqlExpression = SqlExpression> = {
276
+ readonly mode: "integrated";
277
+ readonly tuple: OAuthTupleAuthorityTable<T, N>;
278
+ } | {
279
+ readonly mode: "separate";
280
+ readonly tuple: OAuthTupleAuthorityTable<T, N>;
281
+ readonly external: OAuthOwnershipTable<O, N, Expression>;
282
+ };
283
+ export interface OAuthRegistrationIntentMapping<S extends TableModel, O extends TableModel, C extends TableModel, AC extends TableModel, F extends TableModel, T extends TableModel, I extends TableModel, N, Expression extends SqlExpression = SqlExpression> {
284
+ readonly signIn: OAuthSignInMapping<S, O, C, AC, F, N, Expression>;
285
+ readonly ownership: OAuthOwnershipMutation<T, O, N, Expression>;
286
+ readonly intent: OAuthRegistrationIntentTable<I>;
287
+ readonly tupleConstraints: typeof requiredOAuthTupleConstraints;
288
+ readonly registrationConstraints: Pick<typeof requiredOAuthRegistrationConstraints, "intentReference" | "intentFlow">;
289
+ readonly eligibility: OAuthRegistrationEligibility<N, Expression>;
290
+ }
291
+ export interface OAuthRegistrationBase<Registration, T extends TableModel, O extends TableModel, I extends TableModel, R extends TableModel, N, Expression extends SqlExpression = SqlExpression, Descriptor extends object = object> {
292
+ readonly ownership: OAuthOwnershipMutation<T, O, N, Expression>;
293
+ readonly intent: OAuthRegistrationIntentTable<I>;
294
+ readonly command: OAuthRegistrationCommandTable<R, Registration>;
295
+ readonly clock: OAuthClock<Expression>;
296
+ readonly tupleConstraints: typeof requiredOAuthTupleConstraints;
297
+ readonly constraints: typeof requiredOAuthRegistrationConstraints;
298
+ readonly inspect: (input: {
299
+ readonly intent: OAuthRegistrationIntent;
300
+ readonly registration: Registration;
301
+ }) => Effect.Effect<{
302
+ readonly fingerprint: string;
303
+ readonly eligible: boolean;
304
+ }, PersistenceMappingError>;
305
+ /** Required for an explicitly bound native/DO command: no asynchronous callback
306
+ * is evaluated inside the physical owner. Standalone inspection is pre-owner. */
307
+ readonly inspectSync?: (input: {
308
+ readonly intent: OAuthRegistrationIntent;
309
+ readonly registration: Registration;
310
+ }) => {
311
+ readonly fingerprint: string;
312
+ readonly eligible: boolean;
313
+ };
314
+ /** Type projection, never the original wire transformation. */
315
+ readonly snapshot: (registration: Registration) => Effect.Effect<Registration, PersistenceMappingError>;
316
+ readonly snapshotSync?: (registration: Registration) => Registration;
317
+ /** Canonical bounded storage of Registration.Type. These are Type codecs, not
318
+ * the original wire decoder/encoder; decode(encode(value)) must encode identically.
319
+ * The engine writes and roundtrip-checks this exact string (maximum 1 MiB). */
320
+ readonly application: {
321
+ readonly encode: (registration: Registration) => string;
322
+ readonly decode: (stored: string) => Registration;
323
+ };
324
+ readonly eligibility: {
325
+ /** Stable application authority anchors, in one configured global order.
326
+ * Omit only for immutable/tuple-local policy or an equivalent explicit outer
327
+ * owner lock. Each scope must match 1..64 rows, never an absent quota row.
328
+ * Locks precede tuple/intent/command locks; postcondition owns changed state. */
329
+ readonly guards?: ReadonlyArray<OAuthRegistrationGuardDescriptor<Registration, N, Expression, Descriptor>>;
330
+ readonly admission: (input: {
331
+ readonly intent: OAuthRegistrationIntent;
332
+ readonly registration: Registration;
333
+ readonly nativeSubjectId?: N;
334
+ }) => Expression;
335
+ /** Evaluated after subject/application writes, including appended coordinator
336
+ * writes. May assert consumption of the admission invitation/quota. */
337
+ readonly postcondition: (input: {
338
+ readonly intent: OAuthRegistrationIntent;
339
+ readonly registration: Registration;
340
+ readonly nativeSubjectId?: N;
341
+ }) => Expression;
342
+ };
343
+ readonly allocateProvisioningIdentity: Effect.Effect<string, PersistenceMappingError>;
344
+ readonly retentionMillis: number;
345
+ }
346
+ export interface OAuthRegistrationGuardTable<T extends TableModel, Registration, N, Expression extends SqlExpression = SqlExpression> {
347
+ readonly table: T["table"];
348
+ readonly orderBy: Column<T>;
349
+ readonly condition: (input: {
350
+ readonly intent: OAuthRegistrationIntent;
351
+ readonly registration: Registration;
352
+ readonly nativeSubjectId?: N;
353
+ }) => Expression;
354
+ }
355
+ export interface OAuthRegistrationGuardDescriptor<Registration, N, Expression extends SqlExpression = SqlExpression, Descriptor extends object = object> {
356
+ readonly table: Descriptor;
357
+ readonly orderBy: string;
358
+ readonly condition: OAuthRegistrationGuardTable<TableModel, Registration, N, Expression>["condition"];
359
+ }
360
+ export declare const oauthRegistrationGuardTable: <T extends TableModel, Registration, N, Expression extends SqlExpression = SqlExpression>(input: OAuthRegistrationGuardTable<T, Registration, N, Expression>) => OAuthRegistrationGuardDescriptor<Registration, N, Expression, T["table"]>;
361
+ export type OAuthRegistrationMapping<Registration, S extends TableModel, O extends TableModel, C extends TableModel, AC extends TableModel, T extends TableModel, I extends TableModel, R extends TableModel, N, Expression extends SqlExpression = SqlExpression, Descriptor extends object = object> = OAuthRegistrationBase<Registration, T, O, I, R, N, Expression, Descriptor> & ({
362
+ readonly mode: "pending";
363
+ readonly allocatePendingReference: Effect.Effect<string, PersistenceMappingError>;
364
+ } | {
365
+ readonly mode: "atomic";
366
+ readonly subjectId: SubjectIdCodec<N>;
367
+ readonly subject: OAuthSubjectReadTable<S, Expression>;
368
+ readonly credential: OAuthCredentialTable<C, N, Expression>;
369
+ readonly authority: OAuthAuthorityTable<AC, N, Expression>;
370
+ readonly allocateSubjectId: Effect.Effect<N, PersistenceMappingError>;
371
+ readonly allocateCredentialId: Effect.Effect<string, PersistenceMappingError>;
372
+ readonly allocateRevision: Effect.Effect<SecurityRevision, PersistenceMappingError>;
373
+ readonly encodeSubjectInsert: (input: {
374
+ readonly intent: OAuthRegistrationIntent;
375
+ readonly registration: Registration;
376
+ }, ids: {
377
+ readonly subjectId: N;
378
+ readonly securityRevision: SecurityRevision;
379
+ }) => S["insert"];
380
+ });
381
+ /** Heterogeneous descriptors are made by typed factories and projected privately. */
382
+ export interface OAuthEligibilityDescriptor<N, Expression extends SqlExpression = SqlExpression, Descriptor extends object = object> {
383
+ readonly _tag: "OAuthEligibilityDescriptor";
384
+ readonly scope: string;
385
+ readonly table: Descriptor;
386
+ readonly subjectId: string;
387
+ readonly credentialId: string;
388
+ readonly revision: string;
389
+ readonly condition: (subjectId: N) => Expression;
390
+ readonly decode: (row: unknown) => OAuthEligibilityFact | undefined;
391
+ }
392
+ export declare const oauthEligibilityTable: <T extends TableModel, N, Expression extends SqlExpression = SqlExpression>(input: OAuthEligibilityTable<T, N, Expression>) => OAuthEligibilityDescriptor<N, Expression, T["table"]>;
393
+ export interface OAuthCleanupDescriptor<N, Expression extends SqlExpression = SqlExpression, Descriptor extends object = object> {
394
+ readonly table: Descriptor;
395
+ readonly subjectId: string;
396
+ readonly condition: OAuthCleanupTable<TableModel, N, Expression>["condition"];
397
+ }
398
+ export declare const oauthCleanupTable: <T extends TableModel, N, Expression extends SqlExpression = SqlExpression>(input: OAuthCleanupTable<T, N, Expression>) => OAuthCleanupDescriptor<N, Expression, T["table"]>;
399
+ /** A stable application/reference lock acquired before an ownership target.
400
+ * Missing rows retain ownership. Conditions use detached native IDs; every
401
+ * writer of the guarded reference follows the same order. */
402
+ export interface OAuthReferenceGuardTable<T extends TableModel, N, Expression extends SqlExpression = SqlExpression> {
403
+ readonly table: T["table"];
404
+ readonly orderBy: Column<T>;
405
+ readonly condition: (input: {
406
+ readonly identity: typeof OAuthExternalIdentity.Type;
407
+ readonly identityKey: string;
408
+ readonly subjectId: N;
409
+ }) => Expression | Effect.Effect<Expression, PlatformError.PlatformError, Crypto.Crypto>;
410
+ }
411
+ export interface OAuthReferenceGuardDescriptor<N, Expression extends SqlExpression = SqlExpression, Descriptor extends object = object> {
412
+ readonly table: Descriptor;
413
+ readonly orderBy: string;
414
+ readonly condition: OAuthReferenceGuardTable<TableModel, N, Expression>["condition"];
415
+ }
416
+ export declare const oauthReferenceGuardTable: <T extends TableModel, N, Expression extends SqlExpression = SqlExpression>(input: OAuthReferenceGuardTable<T, N, Expression>) => OAuthReferenceGuardDescriptor<N, Expression, T["table"]>;
417
+ export interface OAuthAccountsMapping<S extends TableModel, O extends TableModel, C extends TableModel, AC extends TableModel, F extends TableModel, T extends TableModel, U extends TableModel, N, Expression extends SqlExpression = SqlExpression, Descriptor extends object = object> {
418
+ readonly subject: OAuthSubjectTable<S, Expression>;
419
+ readonly ownership: OAuthOwnershipMutation<T, O, N, Expression>;
420
+ readonly credential: OAuthCredentialTable<C, N, Expression>;
421
+ readonly authority: OAuthAuthorityTable<AC, N, Expression>;
422
+ readonly flow: OAuthFlowTable<F>;
423
+ readonly command: OAuthUnlinkCommandTable<U>;
424
+ readonly subjectId: SubjectIdCodec<N>;
425
+ readonly clock: OAuthClock<Expression>;
426
+ readonly constraints: typeof requiredOAuthSignInConstraints & typeof requiredOAuthAccountsConstraints;
427
+ readonly tupleConstraints: typeof requiredOAuthTupleConstraints;
428
+ readonly eligibility: ReadonlyArray<OAuthEligibilityDescriptor<N, Expression, Descriptor>>;
429
+ readonly cleanup: ReadonlyArray<OAuthCleanupDescriptor<N, Expression, Descriptor>>;
430
+ readonly metadata: OAuthMetadataPolicy<N, Expression>;
431
+ readonly sessionInvalidation: "same-authority-immediate" | "original-absolute-expiry";
432
+ /** Omit only when connected access is absent. A predicate alone conservatively
433
+ * retains ownership; release also needs all configured guard rows below. */
434
+ readonly connectedReference?: (input: {
435
+ readonly identityKey: string;
436
+ readonly subjectId: N;
437
+ }) => Expression;
438
+ /** At most 32 descriptors, each locking 1..64 stable rows in supplied order.
439
+ * Missing/empty guards retain Owned, even when the reference predicate is false. */
440
+ readonly connectedReferenceGuards?: ReadonlyArray<OAuthReferenceGuardDescriptor<N, Expression, Descriptor>>;
441
+ readonly allocateCredentialId: Effect.Effect<string, PersistenceMappingError>;
442
+ readonly allocateRevision: Effect.Effect<SecurityRevision, PersistenceMappingError>;
443
+ }
444
+ export interface OAuthRegistrationAuthority<Registration> {
445
+ readonly read: (access: OAuthRegistrationAccess) => Effect.Effect<OAuthRegistrationInspection | undefined, OAuthUnavailable>;
446
+ readonly inspect: (input: {
447
+ readonly intent: OAuthRegistrationIntent;
448
+ readonly registration: Registration;
449
+ }) => Effect.Effect<{
450
+ readonly fingerprint: TokenDigest;
451
+ readonly eligible: boolean;
452
+ }, OAuthUnavailable>;
453
+ readonly register: <A>(input: {
454
+ readonly access: OAuthRegistrationAccess;
455
+ readonly intent: OAuthRegistrationIntent;
456
+ readonly commandId: typeof OAuthCommandId.Type;
457
+ readonly registration: Registration;
458
+ readonly fingerprint: TokenDigest;
459
+ }, prepare: PrepareOAuthCommit<OAuthRegistrationDecision, A>) => Effect.Effect<PreparedCommit<A>, OAuthUnavailable>;
460
+ readonly cleanup: <A>(input: OAuthCleanupInput, prepare: PrepareOAuthCommit<{
461
+ readonly removed: number;
462
+ readonly hasMore: boolean;
463
+ }, A>) => Effect.Effect<PreparedCommit<A>, OAuthUnavailable>;
464
+ }
465
+ //#endregion
466
+ export { oauth_model_d_exports };
467
+ //# sourceMappingURL=oauth-model.d.mts.map
@@ -0,0 +1,49 @@
1
+ //#region src/internal/models/oauth-model.ts
2
+ const requiredOAuthSignInConstraints = {
3
+ flow: "unique(flow.moduleId,flow.flowId)",
4
+ command: "unique(flow.moduleId,flow.commandId)",
5
+ stateDigest: "unique(flow.stateDigest)",
6
+ ownership: "unique(ownership.identityKey)",
7
+ credentialId: "unique(credential.credentialId)",
8
+ credentialIdentity: "unique(credential.identityKey)",
9
+ authorityCredential: "unique(authority.subjectId,authority.credentialId)"
10
+ };
11
+ const requiredOAuthTupleConstraints = { identityKey: "unique(tuple.identityKey)" };
12
+ const requiredOAuthRegistrationConstraints = {
13
+ intentReference: "unique(intent.moduleId,intent.reference)",
14
+ intentFlow: "unique(intent.moduleId,intent.flowId)",
15
+ command: "unique(registrationCommand.moduleId,registrationCommand.commandId)"
16
+ };
17
+ const requiredOAuthAccountsConstraints = { unlinkCommand: "unique(unlinkCommand.moduleId,unlinkCommand.commandId)" };
18
+ const oauthRegistrationGuardTable = (input) => Object.freeze({
19
+ table: input.table,
20
+ orderBy: input.orderBy,
21
+ condition: input.condition
22
+ });
23
+ const oauthEligibilityTable = (input) => {
24
+ const { table, subjectId, credentialId, revision, scope, condition, decode } = input;
25
+ return Object.freeze({
26
+ _tag: "OAuthEligibilityDescriptor",
27
+ table,
28
+ subjectId,
29
+ credentialId,
30
+ revision,
31
+ scope,
32
+ condition,
33
+ decode: (row) => decode(row)
34
+ });
35
+ };
36
+ const oauthCleanupTable = (input) => Object.freeze({
37
+ table: input.table,
38
+ subjectId: input.subjectId,
39
+ condition: input.condition
40
+ });
41
+ const oauthReferenceGuardTable = (input) => Object.freeze({
42
+ table: input.table,
43
+ orderBy: input.orderBy,
44
+ condition: input.condition
45
+ });
46
+ //#endregion
47
+ export { oauthCleanupTable, oauthEligibilityTable, oauthReferenceGuardTable, oauthRegistrationGuardTable, requiredOAuthAccountsConstraints, requiredOAuthRegistrationConstraints, requiredOAuthSignInConstraints, requiredOAuthTupleConstraints };
48
+
49
+ //# sourceMappingURL=oauth-model.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-model.mjs","names":[],"sources":["../../../src/internal/models/oauth-model.ts"],"sourcesContent":["import type { PreparedCommit } from \"@yielded/auth/Hooks\";\nimport type {\n OAuthActionAuthorization,\n OAuthAccountRevision,\n OAuthRegistrationIntent,\n OAuthCredentialSnapshot,\n OAuthExternalIdentity,\n OAuthRegistrationAccess,\n OAuthRegistrationInspection,\n OAuthUnavailable,\n OAuthCommandId,\n PrepareOAuthCommit,\n OAuthRegistrationDecision,\n OAuthCleanupInput,\n} from \"@yielded/auth/OAuth\";\nimport type { AuthenticationFactor } from \"@yielded/auth/Operations\";\nimport type { TokenDigest } from \"@yielded/auth/Schema\";\nimport type { AuthenticationRequirement, SecurityRevision } from \"@yielded/auth/Sessions\";\nimport type { Crypto, Effect, PlatformError } from \"effect\";\n\nimport type { TableModel as Table, SqlExpression } from \"../query-operations\";\nimport type { PersistenceMappingError, SubjectIdCodec } from \"./common\";\n\ntype Column<T extends Table> = T[\"column\"];\n\nexport type OAuthFlowState =\n | \"Pending\"\n | \"Claimed\"\n | \"Verified\"\n | \"RegistrationIssued\"\n | \"Linked\"\n | \"Cancelled\"\n | \"Rejected\"\n | \"Ambiguous\"\n | \"Conflict\";\n\nexport type OAuthTupleState = \"Unowned\" | \"Reserved\" | \"Owned\";\nexport type OAuthRegistrationState = \"Unbound\" | \"Registered\" | \"ProvisioningPending\" | \"Rejected\";\nexport type OAuthAction = OAuthActionAuthorization[\"challenge\"][\"action\"];\n\n/** The engine writes every critical column explicitly after applying the pure\n * consumer encoder. Native instant values must roundtrip without precision loss. */\nexport interface OAuthClock<Expression extends SqlExpression = SqlExpression> {\n readonly encodeInstant: (millis: number) => unknown;\n readonly decodeInstant: (value: unknown) => number;\n /** Actual engine wall clock sampled after locks, not transaction-start time.\n * PostgreSQL uses clock_timestamp(), never now()/CURRENT_TIMESTAMP. D1 repeats\n * its primary-engine sample bounds in final guards. Return integer milliseconds. */\n readonly engineNowMillis: Expression;\n}\n\nexport interface OAuthSubjectReadTable<\n S extends Table,\n Expression extends SqlExpression = SqlExpression,\n> {\n readonly table: S[\"table\"];\n readonly id: Column<S>;\n readonly status: Column<S>;\n readonly securityRevision: Column<S>;\n readonly isActiveStatus: (value: unknown) => boolean;\n readonly activeCondition: Expression;\n}\n\nexport interface OAuthSubjectTable<\n S extends Table,\n Expression extends SqlExpression = SqlExpression,\n> extends OAuthSubjectReadTable<S, Expression> {\n readonly decodeActionRequirement: (\n row: S[\"select\"],\n action: OAuthAction,\n ) => AuthenticationRequirement;\n readonly decodeAuthenticationRequirement: (row: S[\"select\"]) => AuthenticationRequirement;\n readonly nextSecurityRevision: (current: SecurityRevision) => SecurityRevision;\n}\n\nexport interface OAuthOwnershipReadTable<\n O extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n> {\n readonly table: O[\"table\"];\n readonly identityKey: Column<O>;\n readonly provider: Column<O>;\n readonly issuer: Column<O>;\n readonly externalSubject: Column<O>;\n readonly subjectId: Column<O>;\n /** Includes Owned state when authority and ownership share a physical table. */\n readonly ownedCondition: Expression;\n readonly decodeSubjectId: (row: O[\"select\"]) => N;\n}\n\nexport interface OAuthOwnershipTable<\n O extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n> extends OAuthOwnershipReadTable<O, N, Expression> {\n readonly encodeInsert: (input: {\n readonly identity: typeof OAuthExternalIdentity.Type;\n readonly identityKey: string;\n readonly subjectId: N;\n }) => O[\"insert\"];\n}\n\nexport interface OAuthCredentialReadTable<\n C extends Table,\n Expression extends SqlExpression = SqlExpression,\n> {\n readonly table: C[\"table\"];\n readonly moduleId: Column<C>;\n readonly credentialId: Column<C>;\n readonly subjectId: Column<C>;\n readonly identityKey: Column<C>;\n readonly credentialRevision: Column<C>;\n readonly status: Column<C>;\n readonly isActiveStatus: (value: unknown) => boolean;\n readonly activeCondition: Expression;\n}\n\nexport interface OAuthCredentialTable<\n C extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n> extends OAuthCredentialReadTable<C, Expression> {\n readonly encodeInsert: (input: {\n readonly moduleId: string;\n readonly subjectId: N;\n readonly identityKey: string;\n readonly credentialId: string;\n readonly credentialRevision: SecurityRevision;\n }) => C[\"insert\"];\n /** This slice removes login rows. Historical records belong in separate audit storage. */\n readonly removal: \"delete\";\n}\n\nexport interface OAuthAuthorityReadTable<\n C extends Table,\n Expression extends SqlExpression = SqlExpression,\n> {\n readonly table: C[\"table\"];\n readonly subjectId: Column<C>;\n readonly credentialId: Column<C>;\n readonly revision: Column<C>;\n readonly status: Column<C>;\n readonly isActiveStatus: (value: unknown) => boolean;\n readonly activeCondition: Expression;\n}\n\nexport interface OAuthAuthorityTable<\n C extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n> extends OAuthAuthorityReadTable<C, Expression> {\n readonly encodeInsert: (input: {\n readonly subjectId: N;\n readonly credentialId: string;\n readonly revision: SecurityRevision;\n }) => C[\"insert\"];\n}\n\n/** Both purposes may use the same physical table. Shared tables share module/flow\n * and module/command uniqueness. The snapshot has the exact purpose-specific core\n * codec; terminal writes erase it, while identity, claim and retention columns remain. */\nexport interface OAuthFlowTable<F extends Table> {\n readonly table: F[\"table\"];\n readonly moduleId: Column<F>;\n readonly flowId: Column<F>;\n readonly commandId: Column<F>;\n readonly purpose: Column<F>;\n readonly generation: Column<F>;\n readonly state: Column<F>;\n readonly version: Column<F>;\n readonly stateDigest: Column<F>;\n readonly binderVerifier: Column<F>;\n readonly binderExpiresAt: Column<F>;\n readonly snapshot: Column<F>;\n readonly issuedAt: Column<F>;\n readonly expiresAt: Column<F>;\n readonly claimId: Column<F>;\n readonly claimedAt: Column<F>;\n readonly claimExpiresAt: Column<F>;\n readonly retentionUntil: Column<F>;\n readonly encodeInsert: (input: {\n readonly moduleId: string;\n readonly flowId: string;\n readonly purpose: \"sign-in\" | \"link\";\n }) => F[\"insert\"];\n}\n\nexport interface OAuthTupleAuthorityTable<T extends Table, N> {\n readonly table: T[\"table\"];\n readonly identityKey: Column<T>;\n readonly provider: Column<T>;\n readonly issuer: Column<T>;\n readonly externalSubject: Column<T>;\n readonly state: Column<T>;\n readonly version: Column<T>;\n readonly subjectId: Column<T>;\n /** Exact reservation identity; no application payload or bearer. */\n readonly reservation: Column<T>;\n readonly encodeInsert: (input: {\n readonly identityKey: string;\n readonly identity: typeof OAuthExternalIdentity.Type;\n readonly subjectId?: N;\n }) => T[\"insert\"];\n}\n\nexport interface OAuthRegistrationIntentTable<I extends Table> {\n readonly table: I[\"table\"];\n readonly moduleId: Column<I>;\n readonly reference: Column<I>;\n readonly flowId: Column<I>;\n readonly claimId: Column<I>;\n readonly identityKey: Column<I>;\n readonly version: Column<I>;\n readonly state: Column<I>;\n readonly snapshot: Column<I>;\n readonly commandId: Column<I>;\n readonly fingerprint: Column<I>;\n readonly pendingReference: Column<I>;\n readonly expiresAt: Column<I>;\n readonly retentionUntil: Column<I>;\n readonly encodeInsert: (intent: OAuthRegistrationIntent) => I[\"insert\"];\n}\n\nexport interface OAuthRegistrationCommandTable<R extends Table, Registration> {\n readonly table: R[\"table\"];\n readonly moduleId: Column<R>;\n readonly commandId: Column<R>;\n readonly reference: Column<R>;\n readonly identityKey: Column<R>;\n readonly fingerprint: Column<R>;\n readonly intentSnapshot: Column<R>;\n readonly applicationSnapshot: Column<R>;\n readonly provisioningIdentity: Column<R>;\n readonly decision: Column<R>;\n readonly retentionUntil: Column<R>;\n /** Persists exact detached Type before protected pending work can start. */\n readonly encodeInsert: (input: {\n readonly intent: OAuthRegistrationIntent;\n readonly commandId: string;\n readonly fingerprint: string;\n readonly registration: Registration;\n readonly provisioningIdentity: string;\n }) => R[\"insert\"];\n}\n\nexport interface OAuthUnlinkCommandTable<U extends Table> {\n readonly table: U[\"table\"];\n readonly moduleId: Column<U>;\n readonly commandId: Column<U>;\n readonly subjectId: Column<U>;\n readonly credentialId: Column<U>;\n readonly intentSnapshot: Column<U>;\n readonly decision: Column<U>;\n readonly retentionUntil: Column<U>;\n readonly encodeInsert: (input: {\n readonly moduleId: string;\n readonly commandId: string;\n readonly credential: OAuthCredentialSnapshot;\n }) => U[\"insert\"];\n}\n\nexport interface OAuthEligibilityFact {\n readonly credentialId: string;\n readonly revision: SecurityRevision;\n readonly usablePrimary: boolean;\n readonly factors: ReadonlyArray<AuthenticationFactor>;\n readonly userVerified: boolean;\n readonly phishingResistant: boolean;\n}\n\n/** Each descriptor reads only its own subject-scoped method rows. The native row\n * projector and SQL condition must express the same installed method eligibility.\n * All source/identifier/policy mutations advance subject securityRevision. D1 also\n * guards exact selected IDs/versions and absence/count assumptions, never just a\n * stale boolean. An over-limit graph fails closed rather than truncating. */\nexport interface OAuthEligibilityTable<\n T extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n> {\n readonly table: T[\"table\"];\n readonly subjectId: Column<T>;\n readonly credentialId: Column<T>;\n readonly revision: Column<T>;\n readonly scope: string;\n readonly condition: (subjectId: N) => Expression;\n readonly decode: (row: T[\"select\"]) => OAuthEligibilityFact | undefined;\n}\n\n/** Authenticated command replay uses current subject status and this additional\n * nonconsuming SQL policy. It never consumes a fresh action factor. */\nexport interface OAuthMetadataPolicy<N, Expression extends SqlExpression = SqlExpression> {\n readonly condition: (subjectId: N) => Expression;\n}\n\nexport interface OAuthCleanupTable<\n T extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n> {\n readonly table: T[\"table\"];\n readonly subjectId: Column<T>;\n /** Bound to this subject's old revision; no opaque independently committing service. */\n readonly condition: (input: {\n readonly subjectId: N;\n readonly revision: OAuthAccountRevision;\n readonly removedCredentialId?: string;\n }) => Expression;\n readonly disposition: \"delete\";\n}\n\nexport interface OAuthRegistrationEligibility<N, Expression extends SqlExpression = SqlExpression> {\n /** Pure SQL guards for mutable app policy; evaluated again after app writes. */\n readonly condition: (input: {\n readonly intent: OAuthRegistrationIntent;\n readonly nativeSubjectId?: N;\n }) => Expression;\n}\n\nexport interface OAuthD1Mapping {\n readonly d1: { readonly primary: true };\n}\n\nexport const requiredOAuthSignInConstraints = {\n flow: \"unique(flow.moduleId,flow.flowId)\",\n command: \"unique(flow.moduleId,flow.commandId)\",\n stateDigest: \"unique(flow.stateDigest)\",\n ownership: \"unique(ownership.identityKey)\",\n credentialId: \"unique(credential.credentialId)\",\n credentialIdentity: \"unique(credential.identityKey)\",\n authorityCredential: \"unique(authority.subjectId,authority.credentialId)\",\n} as const;\n\nexport const requiredOAuthTupleConstraints = { identityKey: \"unique(tuple.identityKey)\" } as const;\n\nexport const requiredOAuthRegistrationConstraints = {\n intentReference: \"unique(intent.moduleId,intent.reference)\",\n intentFlow: \"unique(intent.moduleId,intent.flowId)\",\n command: \"unique(registrationCommand.moduleId,registrationCommand.commandId)\",\n} as const;\n\nexport const requiredOAuthAccountsConstraints = {\n unlinkCommand: \"unique(unlinkCommand.moduleId,unlinkCommand.commandId)\",\n} as const;\n\nexport interface OAuthSignInMapping<\n S extends Table,\n O extends Table,\n C extends Table,\n AC extends Table,\n F extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n> {\n readonly subject: OAuthSubjectReadTable<S, Expression>;\n readonly ownership: OAuthOwnershipReadTable<O, N, Expression>;\n readonly credential: OAuthCredentialReadTable<C, Expression>;\n readonly authority: OAuthAuthorityReadTable<AC, Expression>;\n readonly flow: OAuthFlowTable<F>;\n readonly subjectId: SubjectIdCodec<N>;\n readonly clock: OAuthClock<Expression>;\n readonly constraints: typeof requiredOAuthSignInConstraints;\n}\n\nexport type OAuthOwnershipMutation<\n T extends Table,\n O extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n> =\n | { readonly mode: \"integrated\"; readonly tuple: OAuthTupleAuthorityTable<T, N> }\n | {\n readonly mode: \"separate\";\n readonly tuple: OAuthTupleAuthorityTable<T, N>;\n readonly external: OAuthOwnershipTable<O, N, Expression>;\n };\n\nexport interface OAuthRegistrationIntentMapping<\n S extends Table,\n O extends Table,\n C extends Table,\n AC extends Table,\n F extends Table,\n T extends Table,\n I extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n> {\n readonly signIn: OAuthSignInMapping<S, O, C, AC, F, N, Expression>;\n readonly ownership: OAuthOwnershipMutation<T, O, N, Expression>;\n readonly intent: OAuthRegistrationIntentTable<I>;\n readonly tupleConstraints: typeof requiredOAuthTupleConstraints;\n readonly registrationConstraints: Pick<\n typeof requiredOAuthRegistrationConstraints,\n \"intentReference\" | \"intentFlow\"\n >;\n readonly eligibility: OAuthRegistrationEligibility<N, Expression>;\n}\n\nexport interface OAuthRegistrationBase<\n Registration,\n T extends Table,\n O extends Table,\n I extends Table,\n R extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n Descriptor extends object = object,\n> {\n readonly ownership: OAuthOwnershipMutation<T, O, N, Expression>;\n readonly intent: OAuthRegistrationIntentTable<I>;\n readonly command: OAuthRegistrationCommandTable<R, Registration>;\n readonly clock: OAuthClock<Expression>;\n readonly tupleConstraints: typeof requiredOAuthTupleConstraints;\n readonly constraints: typeof requiredOAuthRegistrationConstraints;\n readonly inspect: (input: {\n readonly intent: OAuthRegistrationIntent;\n readonly registration: Registration;\n }) => Effect.Effect<\n { readonly fingerprint: string; readonly eligible: boolean },\n PersistenceMappingError\n >;\n /** Required for an explicitly bound native/DO command: no asynchronous callback\n * is evaluated inside the physical owner. Standalone inspection is pre-owner. */\n readonly inspectSync?: (input: {\n readonly intent: OAuthRegistrationIntent;\n readonly registration: Registration;\n }) => { readonly fingerprint: string; readonly eligible: boolean };\n /** Type projection, never the original wire transformation. */\n readonly snapshot: (\n registration: Registration,\n ) => Effect.Effect<Registration, PersistenceMappingError>;\n readonly snapshotSync?: (registration: Registration) => Registration;\n /** Canonical bounded storage of Registration.Type. These are Type codecs, not\n * the original wire decoder/encoder; decode(encode(value)) must encode identically.\n * The engine writes and roundtrip-checks this exact string (maximum 1 MiB). */\n readonly application: {\n readonly encode: (registration: Registration) => string;\n readonly decode: (stored: string) => Registration;\n };\n readonly eligibility: {\n /** Stable application authority anchors, in one configured global order.\n * Omit only for immutable/tuple-local policy or an equivalent explicit outer\n * owner lock. Each scope must match 1..64 rows, never an absent quota row.\n * Locks precede tuple/intent/command locks; postcondition owns changed state. */\n readonly guards?: ReadonlyArray<\n OAuthRegistrationGuardDescriptor<Registration, N, Expression, Descriptor>\n >;\n readonly admission: (input: {\n readonly intent: OAuthRegistrationIntent;\n readonly registration: Registration;\n readonly nativeSubjectId?: N;\n }) => Expression;\n /** Evaluated after subject/application writes, including appended coordinator\n * writes. May assert consumption of the admission invitation/quota. */\n readonly postcondition: (input: {\n readonly intent: OAuthRegistrationIntent;\n readonly registration: Registration;\n readonly nativeSubjectId?: N;\n }) => Expression;\n };\n readonly allocateProvisioningIdentity: Effect.Effect<string, PersistenceMappingError>;\n readonly retentionMillis: number;\n}\n\nexport interface OAuthRegistrationGuardTable<\n T extends Table,\n Registration,\n N,\n Expression extends SqlExpression = SqlExpression,\n> {\n readonly table: T[\"table\"];\n readonly orderBy: Column<T>;\n readonly condition: (input: {\n readonly intent: OAuthRegistrationIntent;\n readonly registration: Registration;\n readonly nativeSubjectId?: N;\n }) => Expression;\n}\n\nexport interface OAuthRegistrationGuardDescriptor<\n Registration,\n N,\n Expression extends SqlExpression = SqlExpression,\n Descriptor extends object = object,\n> {\n readonly table: Descriptor;\n readonly orderBy: string;\n readonly condition: OAuthRegistrationGuardTable<Table, Registration, N, Expression>[\"condition\"];\n}\n\nexport const oauthRegistrationGuardTable = <\n T extends Table,\n Registration,\n N,\n Expression extends SqlExpression = SqlExpression,\n>(\n input: OAuthRegistrationGuardTable<T, Registration, N, Expression>,\n): OAuthRegistrationGuardDescriptor<Registration, N, Expression, T[\"table\"]> =>\n Object.freeze({\n table: input.table,\n orderBy: input.orderBy,\n condition: input.condition,\n });\n\nexport type OAuthRegistrationMapping<\n Registration,\n S extends Table,\n O extends Table,\n C extends Table,\n AC extends Table,\n T extends Table,\n I extends Table,\n R extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n Descriptor extends object = object,\n> = OAuthRegistrationBase<Registration, T, O, I, R, N, Expression, Descriptor> &\n (\n | {\n readonly mode: \"pending\";\n readonly allocatePendingReference: Effect.Effect<string, PersistenceMappingError>;\n }\n | {\n readonly mode: \"atomic\";\n readonly subjectId: SubjectIdCodec<N>;\n readonly subject: OAuthSubjectReadTable<S, Expression>;\n readonly credential: OAuthCredentialTable<C, N, Expression>;\n readonly authority: OAuthAuthorityTable<AC, N, Expression>;\n readonly allocateSubjectId: Effect.Effect<N, PersistenceMappingError>;\n readonly allocateCredentialId: Effect.Effect<string, PersistenceMappingError>;\n readonly allocateRevision: Effect.Effect<SecurityRevision, PersistenceMappingError>;\n readonly encodeSubjectInsert: (\n input: { readonly intent: OAuthRegistrationIntent; readonly registration: Registration },\n ids: { readonly subjectId: N; readonly securityRevision: SecurityRevision },\n ) => S[\"insert\"];\n }\n );\n\n/** Heterogeneous descriptors are made by typed factories and projected privately. */\nexport interface OAuthEligibilityDescriptor<\n N,\n Expression extends SqlExpression = SqlExpression,\n Descriptor extends object = object,\n> {\n readonly _tag: \"OAuthEligibilityDescriptor\";\n readonly scope: string;\n readonly table: Descriptor;\n readonly subjectId: string;\n readonly credentialId: string;\n readonly revision: string;\n readonly condition: (subjectId: N) => Expression;\n readonly decode: (row: unknown) => OAuthEligibilityFact | undefined;\n}\n\nexport const oauthEligibilityTable = <\n T extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n>(\n input: OAuthEligibilityTable<T, N, Expression>,\n): OAuthEligibilityDescriptor<N, Expression, T[\"table\"]> => {\n const { table, subjectId, credentialId, revision, scope, condition, decode } = input;\n\n return Object.freeze({\n _tag: \"OAuthEligibilityDescriptor\",\n table,\n subjectId,\n credentialId,\n revision,\n scope,\n condition,\n // The query owner supplies rows selected from this descriptor's mapped table.\n decode: (row: unknown) => decode(row as T[\"select\"]),\n });\n};\n\nexport interface OAuthCleanupDescriptor<\n N,\n Expression extends SqlExpression = SqlExpression,\n Descriptor extends object = object,\n> {\n readonly table: Descriptor;\n readonly subjectId: string;\n readonly condition: OAuthCleanupTable<Table, N, Expression>[\"condition\"];\n}\n\nexport const oauthCleanupTable = <\n T extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n>(\n input: OAuthCleanupTable<T, N, Expression>,\n): OAuthCleanupDescriptor<N, Expression, T[\"table\"]> =>\n Object.freeze({ table: input.table, subjectId: input.subjectId, condition: input.condition });\n\n/** A stable application/reference lock acquired before an ownership target.\n * Missing rows retain ownership. Conditions use detached native IDs; every\n * writer of the guarded reference follows the same order. */\nexport interface OAuthReferenceGuardTable<\n T extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n> {\n readonly table: T[\"table\"];\n readonly orderBy: Column<T>;\n readonly condition: (input: {\n readonly identity: typeof OAuthExternalIdentity.Type;\n readonly identityKey: string;\n readonly subjectId: N;\n }) => Expression | Effect.Effect<Expression, PlatformError.PlatformError, Crypto.Crypto>;\n}\n\nexport interface OAuthReferenceGuardDescriptor<\n N,\n Expression extends SqlExpression = SqlExpression,\n Descriptor extends object = object,\n> {\n readonly table: Descriptor;\n readonly orderBy: string;\n readonly condition: OAuthReferenceGuardTable<Table, N, Expression>[\"condition\"];\n}\n\nexport const oauthReferenceGuardTable = <\n T extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n>(\n input: OAuthReferenceGuardTable<T, N, Expression>,\n): OAuthReferenceGuardDescriptor<N, Expression, T[\"table\"]> =>\n Object.freeze({\n table: input.table,\n orderBy: input.orderBy,\n condition: input.condition,\n });\n\nexport interface OAuthAccountsMapping<\n S extends Table,\n O extends Table,\n C extends Table,\n AC extends Table,\n F extends Table,\n T extends Table,\n U extends Table,\n N,\n Expression extends SqlExpression = SqlExpression,\n Descriptor extends object = object,\n> {\n readonly subject: OAuthSubjectTable<S, Expression>;\n readonly ownership: OAuthOwnershipMutation<T, O, N, Expression>;\n readonly credential: OAuthCredentialTable<C, N, Expression>;\n readonly authority: OAuthAuthorityTable<AC, N, Expression>;\n readonly flow: OAuthFlowTable<F>;\n readonly command: OAuthUnlinkCommandTable<U>;\n readonly subjectId: SubjectIdCodec<N>;\n readonly clock: OAuthClock<Expression>;\n readonly constraints: typeof requiredOAuthSignInConstraints &\n typeof requiredOAuthAccountsConstraints;\n readonly tupleConstraints: typeof requiredOAuthTupleConstraints;\n readonly eligibility: ReadonlyArray<OAuthEligibilityDescriptor<N, Expression, Descriptor>>;\n readonly cleanup: ReadonlyArray<OAuthCleanupDescriptor<N, Expression, Descriptor>>;\n readonly metadata: OAuthMetadataPolicy<N, Expression>;\n readonly sessionInvalidation: \"same-authority-immediate\" | \"original-absolute-expiry\";\n /** Omit only when connected access is absent. A predicate alone conservatively\n * retains ownership; release also needs all configured guard rows below. */\n readonly connectedReference?: (input: {\n readonly identityKey: string;\n readonly subjectId: N;\n }) => Expression;\n /** At most 32 descriptors, each locking 1..64 stable rows in supplied order.\n * Missing/empty guards retain Owned, even when the reference predicate is false. */\n readonly connectedReferenceGuards?: ReadonlyArray<\n OAuthReferenceGuardDescriptor<N, Expression, Descriptor>\n >;\n readonly allocateCredentialId: Effect.Effect<string, PersistenceMappingError>;\n readonly allocateRevision: Effect.Effect<SecurityRevision, PersistenceMappingError>;\n}\n\nexport interface OAuthRegistrationAuthority<Registration> {\n readonly read: (\n access: OAuthRegistrationAccess,\n ) => Effect.Effect<OAuthRegistrationInspection | undefined, OAuthUnavailable>;\n readonly inspect: (input: {\n readonly intent: OAuthRegistrationIntent;\n readonly registration: Registration;\n }) => Effect.Effect<\n {\n readonly fingerprint: TokenDigest;\n readonly eligible: boolean;\n },\n OAuthUnavailable\n >;\n readonly register: <A>(\n input: {\n readonly access: OAuthRegistrationAccess;\n readonly intent: OAuthRegistrationIntent;\n readonly commandId: typeof OAuthCommandId.Type;\n readonly registration: Registration;\n readonly fingerprint: TokenDigest;\n },\n prepare: PrepareOAuthCommit<OAuthRegistrationDecision, A>,\n ) => Effect.Effect<PreparedCommit<A>, OAuthUnavailable>;\n readonly cleanup: <A>(\n input: OAuthCleanupInput,\n prepare: PrepareOAuthCommit<{ readonly removed: number; readonly hasMore: boolean }, A>,\n ) => Effect.Effect<PreparedCommit<A>, OAuthUnavailable>;\n}\n"],"mappings":";AAoUA,MAAa,iCAAiC;CAC5C,MAAM;CACN,SAAS;CACT,aAAa;CACb,WAAW;CACX,cAAc;CACd,oBAAoB;CACpB,qBAAqB;AACvB;AAEA,MAAa,gCAAgC,EAAE,aAAa,4BAA4B;AAExF,MAAa,uCAAuC;CAClD,iBAAiB;CACjB,YAAY;CACZ,SAAS;AACX;AAEA,MAAa,mCAAmC,EAC9C,eAAe,yDACjB;AAoJA,MAAa,+BAMX,UAEA,OAAO,OAAO;CACZ,OAAO,MAAM;CACb,SAAS,MAAM;CACf,WAAW,MAAM;AACnB,CAAC;AAoDH,MAAa,yBAKX,UAC0D;CAC1D,MAAM,EAAE,OAAO,WAAW,cAAc,UAAU,OAAO,WAAW,WAAW;CAE/E,OAAO,OAAO,OAAO;EACnB,MAAM;EACN;EACA;EACA;EACA;EACA;EACA;EAEA,SAAS,QAAiB,OAAO,GAAkB;CACrD,CAAC;AACH;AAYA,MAAa,qBAKX,UAEA,OAAO,OAAO;CAAE,OAAO,MAAM;CAAO,WAAW,MAAM;CAAW,WAAW,MAAM;AAAU,CAAC;AA6B9F,MAAa,4BAKX,UAEA,OAAO,OAAO;CACZ,OAAO,MAAM;CACb,SAAS,MAAM;CACf,WAAW,MAAM;AACnB,CAAC"}