@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
@@ -1 +1 @@
1
- {"version":3,"file":"email-kernel.mjs","names":[],"sources":["../../src/internal/email-kernel.ts"],"sourcesContent":["import {\n EmailAddressPersistence,\n type EmailAddressMutation,\n type EmailAction,\n type EmailCredentialSnapshot,\n EmailSignInTargets,\n EmailUnavailable,\n snapshotEmailCredential,\n snapshotEmailRequirement,\n snapshotEmailRevision,\n} from \"@yielded/auth/Email\";\nimport {\n coordinateCommit,\n CurrentCommitJournal,\n hasCommitScope,\n type CommitJournal,\n type PreparedCommit,\n LifecycleHooks,\n HookConfigurationError,\n} from \"@yielded/auth/Hooks\";\nimport type { LoginIdentifier } from \"@yielded/auth/Identity\";\nimport { reportPersistenceFailure } from \"@yielded/auth/Persistence\";\nimport {\n ProofUnavailable,\n type ProofCompletionDecision,\n type ProofCompletionInput,\n} from \"@yielded/auth/Proofs\";\nimport {\n assessAuthentication,\n snapshotAuthenticationEvidence,\n type AuthenticationRevision,\n type SecurityRevision,\n} from \"@yielded/auth/Sessions\";\nimport { Cause, Context, DateTime, Effect, Option, Schema } from \"effect\";\nimport type * as SqlError from \"effect/sql/SqlError\";\n\nimport { isMappedConstraintConflict, PersistenceMappingError } from \"./mapping-error\";\nimport {\n type AnyEmailAddressMapping,\n type AnyEmailSignInMapping,\n requiredEmailAddressConstraints,\n requiredEmailSignInConstraints,\n} from \"./models/email-model\";\nimport {\n CurrentProofSql,\n type makeProofKernel,\n type ProofSqlConfiguration,\n type ProofSqlDatabase,\n} from \"./proof-kernel\";\n/* oxlint-disable no-explicit-any -- the shared dialect kernel erases consumer Drizzle table types internally. */\nimport type { QueryFailure } from \"./query-operations\";\nimport type { QueryOperations, SqlFragment, SqlColumn } from \"./query-operations\";\nimport type { NativeDatabase } from \"./transaction-kernel\";\n\ntype AdapterFailure = QueryFailure | PersistenceMappingError | SqlError.SqlError;\ntype SignInMapping = AnyEmailSignInMapping;\n\nexport interface EmailSqlQuery<A = ReadonlyArray<any>> extends Effect.Effect<A, AdapterFailure> {\n readonly getSQL: () => ReturnType<QueryOperations[\"sql\"]>;\n readonly from: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly where: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly limit: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly orderBy: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly for: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly set: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly values: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly returning: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly innerJoin: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly onConflictDoNothing: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly onDuplicateKeyUpdate: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly $returningId: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n}\n\nexport interface EmailSqlDatabase {\n readonly select: (...args: ReadonlyArray<any>) => EmailSqlQuery;\n readonly insert: (...args: ReadonlyArray<any>) => EmailSqlQuery;\n readonly update: (...args: ReadonlyArray<any>) => EmailSqlQuery;\n readonly delete: (...args: ReadonlyArray<any>) => EmailSqlQuery;\n readonly transaction: <A, E, R>(\n body: (transaction: EmailSqlDatabase) => Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E | SqlError.SqlError, R>;\n}\n\nexport class CurrentEmailSql extends Context.Service<CurrentEmailSql, EmailSqlDatabase>()(\n \"effect-auth/CurrentEmailSql\",\n) {}\n\nexport interface EmailSqlConfiguration {\n readonly mode: \"interactive\" | \"synchronous\";\n readonly locking: boolean;\n readonly standaloneGuard: Effect.Effect<void, EmailUnavailable>;\n readonly coordinated?: boolean;\n readonly proof?: {\n readonly mapping: any;\n readonly configuration: ProofSqlConfiguration;\n };\n}\n\nexport interface CurrentAddress {\n readonly nativeSubjectId: unknown;\n readonly subject: any;\n readonly revision: AuthenticationRevision;\n readonly source?: {\n readonly credential: any;\n readonly identifier: any;\n readonly snapshot: EmailCredentialSnapshot;\n };\n readonly targetIdentifier?: any;\n readonly targetCredential?: any;\n readonly targetIdentifierRevision?: SecurityRevision;\n readonly eligible: boolean;\n}\n\nexport const makeEmailKernel = <\n Fragment extends SqlFragment = SqlFragment,\n Column extends SqlColumn = SqlColumn,\n>(\n operations: QueryOperations<Fragment, Column>,\n proofs: Pick<ReturnType<typeof makeProofKernel>, \"completeProofPlanIn\">,\n) => {\n type AddressMapping = AnyEmailAddressMapping<Fragment>;\n\n const { and, eq, inArray, lte, column, updateValues } = operations;\n const { completeProofPlanIn } = proofs;\n const unavailable = () => EmailUnavailable.make({});\n\n const translateFailure = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n ): Effect.Effect<A, EmailUnavailable, R> =>\n reportPersistenceFailure(\n effect,\n (error) =>\n Schema.is(EmailUnavailable)(error) ||\n Schema.is(ProofUnavailable)(error) ||\n Schema.is(HookConfigurationError)(error),\n ).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => unavailable()))));\n\n const nowMillis = Effect.map(DateTime.now, DateTime.toEpochMillis);\n\n const selectRows = (query: EmailSqlQuery, locking: boolean) =>\n locking && typeof query.for === \"function\" ? query.for(\"update\") : query;\n\n const sameIdentifier = (left: LoginIdentifier, right: LoginIdentifier) =>\n left.namespace === right.namespace && left.value === right.value;\n\n const validEmailSignInConstraints = (mapping: SignInMapping) =>\n Object.entries(requiredEmailSignInConstraints).every(\n ([key, value]) =>\n mapping.constraints[key as keyof typeof requiredEmailSignInConstraints] === value,\n );\n\n const validAddressConstraints = (mapping: AddressMapping) =>\n Object.entries(requiredEmailAddressConstraints).every(\n ([key, value]) =>\n mapping.constraints[key as keyof typeof requiredEmailAddressConstraints] === value,\n );\n\n const subjectColumns = (mapping: SignInMapping) => ({\n id: column(mapping.subject.table, mapping.subject.id),\n status: column(mapping.subject.table, mapping.subject.status),\n securityRevision: column(mapping.subject.table, mapping.subject.securityRevision),\n });\n\n const identifierColumns = (mapping: SignInMapping) => ({\n namespace: column(mapping.identifier.table, mapping.identifier.namespace),\n value: column(mapping.identifier.table, mapping.identifier.value),\n subjectId: column(mapping.identifier.table, mapping.identifier.subjectId),\n verifiedAt: column(mapping.identifier.table, mapping.identifier.verifiedAt),\n bindingRevision: column(mapping.identifier.table, mapping.identifier.bindingRevision),\n });\n\n const credentialColumns = (mapping: SignInMapping) => ({\n moduleId: column(mapping.credential.table, mapping.credential.moduleId),\n subjectId: column(mapping.credential.table, mapping.credential.subjectId),\n credentialId: column(mapping.credential.table, mapping.credential.credentialId),\n identifierNamespace: column(mapping.credential.table, mapping.credential.identifierNamespace),\n identifierValue: column(mapping.credential.table, mapping.credential.identifierValue),\n credentialRevision: column(mapping.credential.table, mapping.credential.credentialRevision),\n status: column(mapping.credential.table, mapping.credential.status),\n });\n\n const authorityColumns = (mapping: AddressMapping) => ({\n subjectId: column(mapping.authorityCredential.table, mapping.authorityCredential.subjectId),\n credentialId: column(\n mapping.authorityCredential.table,\n mapping.authorityCredential.credentialId,\n ),\n revision: column(mapping.authorityCredential.table, mapping.authorityCredential.revision),\n status: column(mapping.authorityCredential.table, mapping.authorityCredential.status),\n });\n\n const commandColumns = (mapping: AddressMapping) => ({\n moduleId: column(mapping.command.table, mapping.command.moduleId),\n commandId: column(mapping.command.table, mapping.command.commandId),\n action: column(mapping.command.table, mapping.command.action),\n bindingDigest: column(mapping.command.table, mapping.command.bindingDigest),\n retentionUntil: column(mapping.command.table, mapping.command.retentionUntil),\n });\n\n const allocate = <A>(\n mode: EmailSqlConfiguration[\"mode\"],\n asynchronous: Effect.Effect<A, PersistenceMappingError> | undefined,\n synchronous: (() => A) | undefined,\n ) => {\n if (mode === \"synchronous\")\n return synchronous === undefined\n ? Effect.fail(unavailable())\n : Effect.try({\n try: synchronous,\n catch: (cause) => new PersistenceMappingError({ operation: \"mapping\", cause }),\n });\n if (asynchronous !== undefined) return asynchronous;\n\n return synchronous === undefined\n ? Effect.fail(unavailable())\n : Effect.try({\n try: synchronous,\n catch: (cause) => new PersistenceMappingError({ operation: \"mapping\", cause }),\n });\n };\n\n const nextSecurityRevision = (\n mapping: AddressMapping,\n mode: EmailSqlConfiguration[\"mode\"],\n current: SecurityRevision,\n ) => {\n if (mode === \"synchronous\")\n return mapping.subject.nextSecurityRevisionSync === undefined\n ? Effect.fail(unavailable())\n : Effect.try({\n try: () => mapping.subject.nextSecurityRevisionSync!(current),\n catch: (cause) => new PersistenceMappingError({ operation: \"mapping\", cause }),\n });\n if (mapping.subject.nextSecurityRevision !== undefined)\n return mapping.subject.nextSecurityRevision(current);\n if (mapping.subject.nextSecurityRevisionSync !== undefined)\n return Effect.try({\n try: () => mapping.subject.nextSecurityRevisionSync!(current),\n catch: (cause) => new PersistenceMappingError({ operation: \"mapping\", cause }),\n });\n\n return Effect.fail(unavailable());\n };\n\n const safeRead = <A, E, R>(\n database: EmailSqlDatabase,\n configuration: EmailSqlConfiguration,\n body: Effect.Effect<A, E, R>,\n ) =>\n Effect.gen(function* () {\n if (configuration.coordinated !== true) {\n if (yield* hasCommitScope) return yield* unavailable();\n yield* configuration.standaloneGuard;\n }\n\n return yield* database.transaction((transaction) =>\n body.pipe(\n Effect.provideService(CurrentEmailSql, transaction),\n Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),\n ),\n );\n });\n\n const owned = <A, E, R>(\n database: EmailSqlDatabase,\n configuration: EmailSqlConfiguration,\n body: Effect.Effect<A, E, R>,\n ) => {\n const run = coordinateCommit(\n () =>\n database.transaction((transaction) =>\n body.pipe(\n Effect.provideService(CurrentEmailSql, transaction),\n Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),\n ),\n ),\n { mode: configuration.mode },\n ).pipe(Effect.map((result) => result.value));\n\n return configuration.coordinated !== true\n ? Effect.gen(function* () {\n if (yield* hasCommitScope) return yield* unavailable();\n yield* configuration.standaloneGuard;\n\n return yield* run;\n })\n : run;\n };\n\n const emailLookupQuery = (\n mapping: SignInMapping,\n moduleId: string,\n identifier: LoginIdentifier,\n ) => {\n const subject = subjectColumns(mapping),\n binding = identifierColumns(mapping),\n credential = credentialColumns(mapping);\n\n return {\n fields: {\n subject: mapping.subject.table,\n identifier: mapping.identifier.table,\n credential: mapping.credential.table,\n },\n from: mapping.identifier.table,\n subjectTable: mapping.subject.table,\n subjectJoin: eq(subject.id, binding.subjectId),\n credentialTable: mapping.credential.table,\n credentialJoin: and(\n eq(credential.moduleId, moduleId),\n eq(credential.subjectId, binding.subjectId),\n eq(credential.identifierNamespace, binding.namespace),\n eq(credential.identifierValue, binding.value),\n ),\n predicate: and(\n eq(binding.namespace, identifier.namespace),\n eq(binding.value, identifier.value),\n ),\n limit: 1,\n };\n };\n\n const emailLookupRows = Effect.fn(\"Drizzle.emailLookupRows\")(function* (\n mapping: SignInMapping,\n moduleId: string,\n identifier: LoginIdentifier,\n ) {\n const database = yield* CurrentEmailSql;\n const query = emailLookupQuery(mapping, moduleId, identifier);\n\n return yield* database\n .select(query.fields)\n .from(query.from)\n .innerJoin(query.subjectTable, query.subjectJoin)\n .innerJoin(query.credentialTable, query.credentialJoin)\n .where(query.predicate)\n .limit(query.limit);\n });\n\n const decodeEmailSnapshot = Effect.fn(\"DrizzleEmail.decodeSnapshot\")(function* (\n mapping: SignInMapping,\n moduleId: string,\n requested: LoginIdentifier,\n row: any,\n ) {\n if (\n !mapping.subject.isActiveStatus(row.subject[mapping.subject.status]) ||\n !mapping.identifier.isCurrent(row.identifier) ||\n !mapping.credential.isActiveStatus(row.credential[mapping.credential.status])\n )\n return undefined;\n\n const snapshot = yield* mapping.credential\n .decode({\n moduleId,\n subject: row.subject,\n identifier: row.identifier,\n credential: row.credential,\n })\n .pipe(Effect.flatMap(snapshotEmailCredential));\n\n const subjectId = yield* mapping.subjectId.toSubject(row.subject[mapping.subject.id]);\n\n const verifiedAtMillis = yield* mapping.decodeInstant(\n row.identifier[mapping.identifier.verifiedAt],\n );\n\n if (\n snapshot.moduleId !== moduleId ||\n !sameIdentifier(snapshot.identifier, requested) ||\n snapshot.revision.subjectId !== subjectId ||\n snapshot.revision.securityRevision !== row.subject[mapping.subject.securityRevision] ||\n snapshot.identifierRevision !== row.identifier[mapping.identifier.bindingRevision] ||\n snapshot.verifiedAtMillis !== verifiedAtMillis ||\n snapshot.credentialId !== row.credential[mapping.credential.credentialId] ||\n snapshot.credentialRevision !== row.credential[mapping.credential.credentialRevision]\n )\n return undefined;\n\n return snapshot;\n });\n\n const makeSqlEmailSignInTargets = Effect.fn(\"makeSqlEmailSignInTargets\")(function* (\n mapping: SignInMapping,\n configuration: EmailSqlConfiguration,\n ): Effect.fn.Return<\n EmailSignInTargets[\"Service\"],\n EmailUnavailable,\n CurrentEmailSql | NativeDatabase\n > {\n const database = yield* CurrentEmailSql;\n\n if (!configuration.coordinated)\n yield* (\n operations.validateStorage?.({\n ...mapping,\n proof: configuration.proof?.mapping,\n }) ?? Effect.void\n ).pipe(Effect.mapError(unavailable));\n\n return EmailSignInTargets.of({\n lookup: (input) =>\n (validEmailSignInConstraints(mapping)\n ? safeRead(\n database,\n configuration,\n Effect.gen(function* () {\n const row = (yield* emailLookupRows(mapping, input.moduleId, input.identifier))[0];\n\n if (row === undefined) return Option.none();\n\n const snapshot = yield* decodeEmailSnapshot(\n mapping,\n input.moduleId,\n input.identifier,\n row,\n );\n\n return snapshot === undefined ? Option.none() : Option.some(snapshot);\n }),\n )\n : Effect.fail(unavailable())\n ).pipe(Effect.provideService(CurrentEmailSql, database), translateFailure),\n });\n });\n\n const readSubject = Effect.fn(\"DrizzleEmail.readSubject\")(function* (\n mapping: AddressMapping,\n subjectId: string,\n locking: boolean,\n ) {\n const database = yield* CurrentEmailSql;\n\n const nativeSubjectId = yield* mapping.subjectId.toNative(subjectId as any);\n const s = subjectColumns(mapping);\n\n const subject = (yield* selectRows(\n database.select().from(mapping.subject.table).where(eq(s.id, nativeSubjectId)).limit(1),\n locking,\n ))[0];\n\n return { nativeSubjectId, subject };\n });\n\n const identifierRow = Effect.fn(\"Drizzle.identifierRow\")(function* (\n mapping: SignInMapping,\n identifier: LoginIdentifier,\n locking: boolean,\n ) {\n const database = yield* CurrentEmailSql;\n\n const i = identifierColumns(mapping);\n\n return yield* selectRows(\n database\n .select()\n .from(mapping.identifier.table)\n .where(and(eq(i.namespace, identifier.namespace), eq(i.value, identifier.value)))\n .limit(1),\n locking,\n );\n });\n\n const credentialById = Effect.fn(\"Drizzle.credentialById\")(function* (\n mapping: SignInMapping,\n moduleId: string,\n credentialId: string,\n locking: boolean,\n ) {\n const database = yield* CurrentEmailSql;\n\n const c = credentialColumns(mapping);\n\n return yield* selectRows(\n database\n .select()\n .from(mapping.credential.table)\n .where(and(eq(c.moduleId, moduleId), eq(c.credentialId, credentialId)))\n .limit(1),\n locking,\n );\n });\n\n const credentialByIdentifier = Effect.fn(\"Drizzle.credentialByIdentifier\")(function* (\n mapping: SignInMapping,\n moduleId: string,\n identifier: LoginIdentifier,\n locking: boolean,\n ) {\n const database = yield* CurrentEmailSql;\n\n const c = credentialColumns(mapping);\n\n return yield* selectRows(\n database\n .select()\n .from(mapping.credential.table)\n .where(\n and(\n eq(c.moduleId, moduleId),\n eq(c.identifierNamespace, identifier.namespace),\n eq(c.identifierValue, identifier.value),\n ),\n )\n .limit(1),\n locking,\n );\n });\n\n const currentAddress = Effect.fn(\"DrizzleEmail.currentAddress\")(function* (\n mapping: AddressMapping,\n input: {\n readonly moduleId: string;\n readonly subjectId: string;\n readonly target: LoginIdentifier;\n readonly sourceCredentialId?: string;\n },\n locking: boolean,\n ) {\n const database = yield* CurrentEmailSql;\n\n const locked = yield* readSubject(mapping, input.subjectId, locking);\n\n if (\n locked.subject === undefined ||\n !mapping.subject.isActiveStatus(locked.subject[mapping.subject.status])\n )\n return undefined;\n\n const discoveredSource =\n input.sourceCredentialId === undefined\n ? undefined\n : (yield* credentialById(mapping, input.moduleId, input.sourceCredentialId, false))[0];\n\n const sourceIdentifier: LoginIdentifier | undefined =\n discoveredSource === undefined\n ? undefined\n : {\n namespace: discoveredSource[mapping.credential.identifierNamespace],\n value: discoveredSource[mapping.credential.identifierValue],\n };\n\n const identifiers = [\n input.target,\n ...(sourceIdentifier === undefined ? [] : [sourceIdentifier]),\n ]\n .filter(\n (value, index, values) =>\n values.findIndex((candidate) => sameIdentifier(candidate, value)) === index,\n )\n .sort((left, right) =>\n `${left.namespace}\\u0000${left.value}`.localeCompare(\n `${right.namespace}\\u0000${right.value}`,\n ),\n );\n\n const lockedIdentifiers = new Map<string, any>();\n\n for (const identifier of identifiers) {\n const row = (yield* identifierRow(mapping, identifier, locking))[0];\n\n if (row !== undefined)\n lockedIdentifiers.set(`${identifier.namespace}\\u0000${identifier.value}`, row);\n }\n\n const sourceCredential =\n input.sourceCredentialId === undefined\n ? undefined\n : (yield* credentialById(mapping, input.moduleId, input.sourceCredentialId, locking))[0];\n\n const targetCredential = (yield* credentialByIdentifier(\n mapping,\n input.moduleId,\n input.target,\n locking,\n ))[0];\n\n const a = authorityColumns(mapping);\n\n const authority = yield* selectRows(\n database\n .select()\n .from(mapping.authorityCredential.table)\n .where(eq(a.subjectId, locked.nativeSubjectId))\n .orderBy(a.credentialId),\n locking,\n );\n\n const activeAuthority = authority.filter((row: any) =>\n mapping.authorityCredential.isActiveStatus(row[mapping.authorityCredential.status]),\n );\n\n const subjectId = yield* mapping.subjectId.toSubject(locked.nativeSubjectId);\n\n const revision: AuthenticationRevision = Object.freeze({\n subjectId,\n securityRevision: locked.subject[mapping.subject.securityRevision],\n credentials: Object.freeze(\n activeAuthority.map((row: any) =>\n Object.freeze({\n credentialId: row[mapping.authorityCredential.credentialId],\n revision: row[mapping.authorityCredential.revision],\n }),\n ),\n ),\n });\n\n const targetIdentifier = lockedIdentifiers.get(\n `${input.target.namespace}\\u0000${input.target.value}`,\n );\n\n const targetOwned =\n targetIdentifier !== undefined &&\n mapping.subjectId.equals(\n targetIdentifier[mapping.identifier.subjectId],\n locked.nativeSubjectId,\n );\n\n const targetMutable =\n targetOwned &&\n mapping.identifier.isMutableTarget(targetIdentifier) &&\n (targetCredential === undefined ||\n (!mapping.credential.isActiveStatus(targetCredential[mapping.credential.status]) &&\n mapping.subjectId.equals(\n targetCredential[mapping.credential.subjectId],\n locked.nativeSubjectId,\n )));\n\n let source: CurrentAddress[\"source\"];\n\n if (input.sourceCredentialId !== undefined) {\n if (\n sourceCredential === undefined ||\n sourceIdentifier === undefined ||\n !mapping.subjectId.equals(\n sourceCredential[mapping.credential.subjectId],\n locked.nativeSubjectId,\n ) ||\n !mapping.credential.isActiveStatus(sourceCredential[mapping.credential.status])\n )\n return undefined;\n\n const sourceIdentifierRow = lockedIdentifiers.get(\n `${sourceIdentifier.namespace}\\u0000${sourceIdentifier.value}`,\n );\n\n if (\n sourceIdentifierRow === undefined ||\n !mapping.identifier.isCurrent(sourceIdentifierRow) ||\n !mapping.subjectId.equals(\n sourceIdentifierRow[mapping.identifier.subjectId],\n locked.nativeSubjectId,\n )\n )\n return undefined;\n\n const snapshot = yield* mapping.credential\n .decode({\n moduleId: input.moduleId,\n subject: locked.subject,\n identifier: sourceIdentifierRow,\n credential: sourceCredential,\n })\n .pipe(Effect.flatMap(snapshotEmailCredential));\n\n source = { credential: sourceCredential, identifier: sourceIdentifierRow, snapshot };\n }\n let eligible = targetIdentifier === undefined ? targetCredential === undefined : targetMutable;\n\n if (input.sourceCredentialId !== undefined && source === undefined) eligible = false;\n if (source !== undefined && sameIdentifier(source.snapshot.identifier, input.target))\n eligible = false;\n if (mapping.addressCardinality === \"single\" && input.sourceCredentialId === undefined) {\n const c = credentialColumns(mapping);\n\n const rows = yield* selectRows(\n database\n .select()\n .from(mapping.credential.table)\n .where(and(eq(c.moduleId, input.moduleId), eq(c.subjectId, locked.nativeSubjectId))),\n locking,\n );\n\n if (\n rows.some((row: any) => mapping.credential.isActiveStatus(row[mapping.credential.status]))\n )\n eligible = false;\n }\n\n return {\n nativeSubjectId: locked.nativeSubjectId,\n subject: locked.subject,\n revision,\n ...(source === undefined ? {} : { source }),\n ...(targetIdentifier === undefined ? {} : { targetIdentifier }),\n ...(targetCredential === undefined ? {} : { targetCredential }),\n ...(targetMutable\n ? { targetIdentifierRevision: targetIdentifier[mapping.identifier.bindingRevision] }\n : {}),\n eligible,\n };\n });\n\n const sameEmailRevision = (left: AuthenticationRevision, right: AuthenticationRevision) => {\n if (\n left.subjectId !== right.subjectId ||\n left.securityRevision !== right.securityRevision ||\n left.credentials.length !== right.credentials.length\n )\n return false;\n\n const expected = [...left.credentials].sort((a, b) =>\n a.credentialId.localeCompare(b.credentialId),\n );\n\n const actual = [...right.credentials].sort((a, b) =>\n a.credentialId.localeCompare(b.credentialId),\n );\n\n return expected.every(\n (item, index) =>\n item.credentialId === actual[index]!.credentialId &&\n item.revision === actual[index]!.revision,\n );\n };\n\n const actionModule = (moduleId: string, action: EmailAction) =>\n `${moduleId}/${action === \"verify-address\" ? \"verify-address\" : \"change-address\"}`;\n\n const actionPurpose = (action: EmailAction) =>\n action === \"verify-address\" ? \"email-address-verification\" : \"email-address-change\";\n\n const completionMatches = (input: EmailAddressMutation, action: EmailAction) => {\n const completion = input.completion.input;\n const binding = completion.binding;\n\n return (\n completion.moduleId === actionModule(input.moduleId, action) &&\n completion.purpose === actionPurpose(action) &&\n binding._tag === \"IdentifierChange\" &&\n sameIdentifier(binding.identifier, input.target) &&\n sameEmailRevision(binding.revision, input.captured.revision)\n );\n };\n\n const snapshotEmailMutation = Effect.fn(\"DrizzleEmail.snapshotMutation\")(function* (\n input: EmailAddressMutation,\n ) {\n const evidence = yield* snapshotAuthenticationEvidence(input.authorization.evidence).pipe(\n Effect.mapError(unavailable),\n );\n\n const requirement = yield* snapshotEmailRequirement(input.authorization.requirement);\n\n const source =\n input.captured.source === undefined\n ? undefined\n : yield* snapshotEmailCredential(input.captured.source);\n\n return Object.freeze({\n ...input,\n target: Object.freeze({ ...input.target }),\n ...(input.invalidation === undefined\n ? {}\n : { invalidation: Object.freeze({ ...input.invalidation }) }),\n captured: Object.freeze({\n eligible: input.captured.eligible,\n revision: snapshotEmailRevision(input.captured.revision),\n ...(input.captured.targetIdentifierRevision === undefined\n ? {}\n : { targetIdentifierRevision: input.captured.targetIdentifierRevision }),\n ...(source === undefined ? {} : { source }),\n }),\n authorization: Object.freeze({\n challenge: Object.freeze({\n ...input.authorization.challenge,\n target: Object.freeze({ ...input.authorization.challenge.target }),\n revision: snapshotEmailRevision(input.authorization.challenge.revision),\n }),\n evidence,\n requirement,\n }),\n });\n });\n\n const validateEmailAuthority = Effect.fn(\"DrizzleEmail.validateAuthority\")(function* (\n mapping: AddressMapping,\n configuration: EmailSqlConfiguration,\n input: EmailAddressMutation,\n action: EmailAction,\n ) {\n const confirmsExisting =\n action === \"verify-address\" && input.captured.targetIdentifierRevision !== undefined;\n\n if (\n !input.captured.eligible ||\n !completionMatches(input, action) ||\n input.authorization.challenge.moduleId !== input.moduleId ||\n input.authorization.challenge.action !== action ||\n input.authorization.challenge.commandId !== input.commandId ||\n !sameIdentifier(input.authorization.challenge.target, input.target) ||\n input.authorization.challenge.sourceCredentialId !== input.captured.source?.credentialId ||\n !sameEmailRevision(input.authorization.challenge.revision, input.captured.revision) ||\n input.authorization.challenge.targetIdentifierRevision !==\n input.captured.targetIdentifierRevision ||\n (input.authorization.evidence.flowId as string) !== (input.commandId as string) ||\n input.authorization.evidence.bindingDigest !== input.authorization.challenge.bindingDigest ||\n !sameEmailRevision(input.authorization.evidence.revision, input.captured.revision) ||\n (action === \"verify-address\" && input.captured.source !== undefined) ||\n (action === \"change-address\" && input.captured.source === undefined) ||\n confirmsExisting !== (input.invalidation === undefined) ||\n (input.invalidation?.existingSessions === \"immediate\" &&\n mapping.sessionInvalidation !== \"same-authority-immediate\")\n )\n return undefined;\n\n const current = yield* currentAddress(\n mapping,\n {\n moduleId: input.moduleId,\n subjectId: input.captured.revision.subjectId,\n target: input.target,\n ...(input.captured.source === undefined\n ? {}\n : { sourceCredentialId: input.captured.source.credentialId }),\n },\n configuration.locking,\n );\n\n if (\n current === undefined ||\n !current.eligible ||\n !sameEmailRevision(current.revision, input.captured.revision) ||\n current.targetIdentifierRevision !== input.captured.targetIdentifierRevision ||\n (input.captured.source !== undefined &&\n (current.source === undefined ||\n current.source.snapshot.identifierRevision !== input.captured.source.identifierRevision ||\n current.source.snapshot.credentialRevision !== input.captured.source.credentialRevision ||\n !sameIdentifier(current.source.snapshot.identifier, input.captured.source.identifier)))\n )\n return undefined;\n\n const currentRequirement = yield* mapping.subject.decodeActionRequirement(\n current.subject,\n action,\n );\n\n const original = yield* assessAuthentication(\n input.authorization.evidence,\n input.authorization.requirement,\n ).pipe(Effect.mapError(unavailable));\n\n const configured = yield* assessAuthentication(\n input.authorization.evidence,\n currentRequirement,\n ).pipe(Effect.mapError(unavailable));\n\n return original.satisfied && configured.satisfied ? current : undefined;\n });\n\n const commandExists = Effect.fn(\"Drizzle.commandExists\")(function* (\n mapping: AddressMapping,\n moduleId: string,\n commandId: string,\n locking: boolean,\n ) {\n const database = yield* CurrentEmailSql;\n\n const c = commandColumns(mapping);\n\n return yield* selectRows(\n database\n .select()\n .from(mapping.command.table)\n .where(and(eq(c.moduleId, moduleId), eq(c.commandId, commandId)))\n .limit(1),\n locking,\n );\n });\n\n const applyMutation = Effect.fn(\"DrizzleEmail.applyMutation\")(function* (\n mapping: AddressMapping,\n input: EmailAddressMutation,\n action: EmailAction,\n current: CurrentAddress,\n allocated: {\n readonly targetCredentialId: string;\n readonly targetIdentifierRevision: SecurityRevision;\n readonly targetCredentialRevision: SecurityRevision;\n readonly sourceIdentifierRevision: SecurityRevision;\n readonly sourceCredentialRevision: SecurityRevision;\n readonly nextSecurityRevision: SecurityRevision;\n },\n now: number,\n ) {\n const database = yield* CurrentEmailSql;\n\n const i = identifierColumns(mapping);\n const c = credentialColumns(mapping);\n const a = authorityColumns(mapping);\n const s = subjectColumns(mapping);\n\n const targetCredentialId =\n current.targetCredential?.[mapping.credential.credentialId] ?? allocated.targetCredentialId;\n\n if (action === \"change-address\") {\n const source = current.source!;\n\n yield* database\n .update(mapping.identifier.table)\n .set(\n mapping.identifier.encodeRetirement({\n source: source.snapshot.identifier,\n bindingRevision: allocated.sourceIdentifierRevision,\n }),\n )\n .where(\n and(\n eq(i.namespace, source.snapshot.identifier.namespace),\n eq(i.value, source.snapshot.identifier.value),\n eq(i.subjectId, current.nativeSubjectId),\n eq(i.bindingRevision, source.snapshot.identifierRevision),\n ),\n );\n yield* database\n .update(mapping.credential.table)\n .set(\n mapping.credential.encodeRetirement({\n source: source.snapshot.identifier,\n credentialRevision: allocated.sourceCredentialRevision,\n }),\n )\n .where(\n and(\n eq(c.moduleId, input.moduleId),\n eq(c.credentialId, source.snapshot.credentialId),\n eq(c.subjectId, current.nativeSubjectId),\n eq(c.credentialRevision, source.snapshot.credentialRevision),\n ),\n );\n yield* database\n .update(mapping.authorityCredential.table)\n .set(mapping.authorityCredential.encodeRetirement(allocated.sourceCredentialRevision))\n .where(\n and(\n eq(a.subjectId, current.nativeSubjectId),\n eq(a.credentialId, source.snapshot.credentialId),\n eq(a.revision, source.snapshot.credentialRevision),\n ),\n );\n }\n if (current.targetIdentifier === undefined) {\n yield* database.insert(mapping.identifier.table).values(\n mapping.identifier.encodeVerifiedInsert({\n identifier: input.target,\n subjectId: current.nativeSubjectId,\n verifiedAtMillis: now,\n bindingRevision: allocated.targetIdentifierRevision,\n }),\n );\n } else {\n yield* database\n .update(mapping.identifier.table)\n .set(\n mapping.identifier.encodeVerification({\n verifiedAtMillis: now,\n bindingRevision: allocated.targetIdentifierRevision,\n }),\n )\n .where(\n and(\n eq(i.namespace, input.target.namespace),\n eq(i.value, input.target.value),\n eq(i.subjectId, current.nativeSubjectId),\n eq(i.bindingRevision, current.targetIdentifier![mapping.identifier.bindingRevision]),\n ),\n );\n }\n if (current.targetCredential === undefined) {\n yield* database.insert(mapping.credential.table).values(\n mapping.credential.encodeVerifiedInsert({\n moduleId: input.moduleId,\n subjectId: current.nativeSubjectId,\n credentialId: targetCredentialId,\n identifier: input.target,\n credentialRevision: allocated.targetCredentialRevision,\n }),\n );\n yield* database.insert(mapping.authorityCredential.table).values(\n mapping.authorityCredential.encodeInsert({\n subjectId: current.nativeSubjectId,\n credentialId: targetCredentialId,\n revision: allocated.targetCredentialRevision,\n }),\n );\n } else {\n const oldRevision = current.targetCredential[mapping.credential.credentialRevision];\n\n yield* database\n .update(mapping.credential.table)\n .set(\n mapping.credential.encodeActivation({\n identifier: input.target,\n credentialRevision: allocated.targetCredentialRevision,\n }),\n )\n .where(\n and(\n eq(c.moduleId, input.moduleId),\n eq(c.credentialId, targetCredentialId),\n eq(c.subjectId, current.nativeSubjectId),\n eq(c.credentialRevision, oldRevision),\n ),\n );\n yield* database\n .update(mapping.authorityCredential.table)\n .set(mapping.authorityCredential.encodeActivation(allocated.targetCredentialRevision))\n .where(\n and(\n eq(a.subjectId, current.nativeSubjectId),\n eq(a.credentialId, targetCredentialId),\n eq(a.revision, oldRevision),\n ),\n );\n }\n yield* database\n .update(mapping.subject.table)\n .set(updateValues([[mapping.subject.securityRevision, allocated.nextSecurityRevision]]))\n .where(\n and(\n eq(s.id, current.nativeSubjectId),\n eq(s.securityRevision, input.captured.revision.securityRevision),\n ),\n );\n yield* database.insert(mapping.command.table).values(\n mapping.command.encodeInsert({\n moduleId: input.moduleId,\n commandId: input.commandId,\n action,\n bindingDigest: input.authorization.challenge.bindingDigest,\n retentionUntilMillis: now + mapping.commandRetentionMillis,\n }),\n );\n\n const sourceStillActive =\n action === \"verify-address\"\n ? []\n : yield* selectRows(\n database\n .select()\n .from(mapping.credential.table)\n .where(\n and(\n eq(c.moduleId, input.moduleId),\n eq(c.credentialId, current.source!.snapshot.credentialId),\n eq(c.subjectId, current.nativeSubjectId),\n ),\n ),\n false,\n );\n\n const target = (yield* emailLookupRows(mapping, input.moduleId, input.target))[0];\n\n const targetAuthority = yield* selectRows(\n database\n .select()\n .from(mapping.authorityCredential.table)\n .where(\n and(eq(a.subjectId, current.nativeSubjectId), eq(a.credentialId, targetCredentialId)),\n )\n .limit(1),\n false,\n );\n\n const command = yield* selectRows(\n database\n .select()\n .from(mapping.command.table)\n .where(\n and(\n eq(commandColumns(mapping).moduleId, input.moduleId),\n eq(commandColumns(mapping).commandId, input.commandId),\n eq(commandColumns(mapping).action, action),\n eq(commandColumns(mapping).bindingDigest, input.authorization.challenge.bindingDigest),\n eq(\n commandColumns(mapping).retentionUntil,\n mapping.encodeInstant(now + mapping.commandRetentionMillis),\n ),\n ),\n )\n .limit(1),\n false,\n );\n\n const targetVerifiedAt =\n target === undefined\n ? undefined\n : yield* mapping.decodeInstant(target.identifier[mapping.identifier.verifiedAt]);\n\n const sourceIdentifier =\n action === \"verify-address\"\n ? []\n : yield* identifierRow(mapping, current.source!.snapshot.identifier, false);\n\n const sourceAuthority =\n action === \"verify-address\"\n ? []\n : yield* selectRows(\n database\n .select()\n .from(mapping.authorityCredential.table)\n .where(\n and(\n eq(a.subjectId, current.nativeSubjectId),\n eq(a.credentialId, current.source!.snapshot.credentialId),\n ),\n )\n .limit(1),\n false,\n );\n\n return (\n target !== undefined &&\n mapping.subjectId.equals(target.subject[mapping.subject.id], current.nativeSubjectId) &&\n mapping.subject.isActiveStatus(target.subject[mapping.subject.status]) &&\n target.subject[mapping.subject.securityRevision] === allocated.nextSecurityRevision &&\n target.identifier[mapping.identifier.bindingRevision] ===\n allocated.targetIdentifierRevision &&\n targetVerifiedAt === now &&\n target.credential[mapping.credential.credentialRevision] ===\n allocated.targetCredentialRevision &&\n target.credential[mapping.credential.credentialId] === targetCredentialId &&\n mapping.subjectId.equals(\n target.credential[mapping.credential.subjectId],\n current.nativeSubjectId,\n ) &&\n mapping.identifier.isCurrent(target.identifier) &&\n mapping.credential.isActiveStatus(target.credential[mapping.credential.status]) &&\n targetAuthority.length === 1 &&\n targetAuthority[0]![mapping.authorityCredential.revision] ===\n allocated.targetCredentialRevision &&\n mapping.authorityCredential.isActiveStatus(\n targetAuthority[0]![mapping.authorityCredential.status],\n ) &&\n command.length === 1 &&\n (action === \"verify-address\" ||\n (sourceStillActive.length === 1 &&\n sourceStillActive[0]![mapping.credential.credentialRevision] ===\n allocated.sourceCredentialRevision &&\n !mapping.credential.isActiveStatus(sourceStillActive[0]![mapping.credential.status]) &&\n sourceIdentifier.length === 1 &&\n mapping.subjectId.equals(\n sourceIdentifier[0]![mapping.identifier.subjectId],\n current.nativeSubjectId,\n ) &&\n sourceIdentifier[0]![mapping.identifier.bindingRevision] ===\n allocated.sourceIdentifierRevision &&\n !mapping.identifier.isCurrent(sourceIdentifier[0]!) &&\n sourceAuthority.length === 1 &&\n sourceAuthority[0]![mapping.authorityCredential.revision] ===\n allocated.sourceCredentialRevision &&\n !mapping.authorityCredential.isActiveStatus(\n sourceAuthority[0]![mapping.authorityCredential.status],\n )))\n );\n });\n\n const probeProofCompletion = Effect.fn(\"Drizzle.probeProofCompletion\")(function* (\n configuration: EmailSqlConfiguration,\n input: ProofCompletionInput,\n ) {\n const database = yield* CurrentEmailSql;\n\n if (configuration.proof === undefined) return yield* Effect.fail(unavailable());\n const validProbe = { _tag: \"EmailProofCompletionValid\" } as const;\n\n const plan = {\n input,\n prepare: <A>(\n decision: ProofCompletionDecision,\n journal: CommitJournal,\n project: (decision: ProofCompletionDecision) => A,\n ) => journal.prepare(project(decision)),\n };\n\n const probe = coordinateCommit(\n () =>\n database.transaction((transaction) =>\n completeProofPlanIn(\n configuration.proof!.mapping,\n configuration.proof!.configuration,\n plan,\n Effect.fail(validProbe),\n () => false,\n ).pipe(\n Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),\n ),\n ),\n { mode: configuration.mode },\n );\n\n return yield* probe.pipe(\n Effect.as(false),\n Effect.catchCause((cause) => {\n const reason = cause.reasons[0];\n\n return cause.reasons.length === 1 &&\n reason !== undefined &&\n Cause.isFailReason(reason) &&\n reason.error === validProbe\n ? Effect.succeed(true)\n : Effect.failCause(cause);\n }),\n );\n });\n\n const prepareRejected = Effect.fn(\"Drizzle.prepareRejected\")(function* <A>(\n configuration: EmailSqlConfiguration,\n prepare: (value: \"rejected\", journal: CommitJournal) => PreparedCommit<A>,\n ) {\n const database = yield* CurrentEmailSql;\n\n return yield* owned(\n database,\n configuration,\n Effect.gen(function* () {\n const journal = yield* CurrentCommitJournal;\n\n return yield* Effect.succeed(prepare(\"rejected\", journal));\n }),\n );\n });\n\n const makeSqlEmailAddressPersistence = Effect.fn(\"makeSqlEmailAddressPersistence\")(function* (\n mapping: AddressMapping,\n configuration: EmailSqlConfiguration,\n ): Effect.fn.Return<\n EmailAddressPersistence[\"Service\"],\n EmailUnavailable,\n LifecycleHooks | CurrentEmailSql | NativeDatabase\n > {\n const database = yield* CurrentEmailSql;\n\n if (!configuration.coordinated)\n yield* (\n operations.validateStorage?.({\n ...mapping,\n proof: configuration.proof?.mapping,\n }) ?? Effect.void\n ).pipe(Effect.mapError(unavailable));\n const hooks = yield* LifecycleHooks;\n\n return EmailAddressPersistence.of({\n target: (input) =>\n (validAddressConstraints(mapping)\n ? safeRead(\n database,\n configuration,\n Effect.gen(function* () {\n const current = yield* currentAddress(mapping, input, configuration.locking);\n\n if (current === undefined) return yield* unavailable();\n\n return Object.freeze({\n revision: snapshotEmailRevision(current.revision),\n eligible: current.eligible,\n ...(current.targetIdentifierRevision === undefined\n ? {}\n : { targetIdentifierRevision: current.targetIdentifierRevision }),\n ...(current.source === undefined\n ? {}\n : { source: yield* snapshotEmailCredential(current.source.snapshot) }),\n });\n }),\n )\n : Effect.fail(unavailable())\n ).pipe(\n Effect.provideService(CurrentEmailSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n checkCompletion: (input) => {\n if (configuration.proof === undefined || input.binding._tag !== \"IdentifierChange\")\n return Effect.succeed(false).pipe(\n Effect.provideService(CurrentEmailSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n );\n const binding = input.binding;\n\n return safeRead(\n database,\n configuration,\n Effect.gen(function* () {\n const action: EmailAction | undefined =\n input.moduleId.endsWith(\"/verify-address\") &&\n input.purpose === \"email-address-verification\"\n ? \"verify-address\"\n : input.moduleId.endsWith(\"/change-address\") &&\n input.purpose === \"email-address-change\"\n ? \"change-address\"\n : undefined;\n\n if (action === undefined) return false;\n const moduleId = input.moduleId.slice(0, -`/${action}`.length);\n\n const current = yield* currentAddress(\n mapping,\n {\n moduleId,\n subjectId: binding.revision.subjectId,\n target: binding.identifier,\n },\n false,\n );\n\n return current !== undefined && sameEmailRevision(current.revision, binding.revision);\n }),\n )\n .pipe(\n Effect.flatMap((current) =>\n current ? probeProofCompletion(configuration, input) : Effect.succeed(false),\n ),\n )\n .pipe(\n Effect.provideService(CurrentEmailSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n );\n },\n verifyWithProof: (uncaptured, prepare) =>\n mutateAddress(mapping, configuration, uncaptured, \"verify-address\", prepare).pipe(\n Effect.provideService(CurrentEmailSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n changeWithProof: (uncaptured, prepare) =>\n mutateAddress(mapping, configuration, uncaptured, \"change-address\", prepare).pipe(\n Effect.provideService(CurrentEmailSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n cleanup: (input, prepare) =>\n owned(\n database,\n configuration,\n Effect.gen(function* () {\n const transaction = yield* CurrentEmailSql;\n const journal = yield* CurrentCommitJournal;\n\n const c = commandColumns(mapping);\n const now = yield* nowMillis;\n\n const rows = yield* selectRows(\n transaction\n .select({ commandId: c.commandId })\n .from(mapping.command.table)\n .where(\n and(\n eq(c.moduleId, input.moduleId),\n lte(c.retentionUntil, mapping.encodeInstant(now)),\n ),\n )\n .limit(input.limit + 1),\n configuration.locking,\n );\n\n const selected = rows.slice(0, input.limit);\n\n const receipt = prepare(\n { removed: selected.length, hasMore: rows.length > input.limit },\n journal,\n );\n\n if (selected.length > 0)\n yield* transaction.delete(mapping.command.table).where(\n and(\n eq(c.moduleId, input.moduleId),\n inArray(\n c.commandId,\n selected.map((row: any) => row.commandId),\n ),\n lte(c.retentionUntil, mapping.encodeInstant(now)),\n ),\n );\n\n return receipt;\n }),\n ).pipe(\n Effect.provideService(CurrentEmailSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n });\n });\n\n const mutateAddress = Effect.fn(\"Drizzle.mutateAddress\")(function* <A>(\n mapping: AddressMapping,\n configuration: EmailSqlConfiguration,\n uncaptured: EmailAddressMutation,\n action: EmailAction,\n prepare: (value: \"changed\" | \"rejected\", journal: CommitJournal) => PreparedCommit<A>,\n ) {\n const database = yield* CurrentEmailSql;\n\n if (!validAddressConstraints(mapping) || configuration.proof === undefined)\n return yield* unavailable();\n const input = yield* snapshotEmailMutation(uncaptured);\n\n const targetCredentialId = yield* allocate(\n configuration.mode,\n mapping.allocateCredentialId,\n mapping.allocateCredentialIdSync,\n );\n\n const targetIdentifierRevision = yield* allocate(\n configuration.mode,\n mapping.allocateRevision,\n mapping.allocateRevisionSync,\n );\n\n const targetCredentialRevision = yield* allocate(\n configuration.mode,\n mapping.allocateRevision,\n mapping.allocateRevisionSync,\n );\n\n const sourceIdentifierRevision = yield* allocate(\n configuration.mode,\n mapping.allocateRevision,\n mapping.allocateRevisionSync,\n );\n\n const sourceCredentialRevision = yield* allocate(\n configuration.mode,\n mapping.allocateRevision,\n mapping.allocateRevisionSync,\n );\n\n const confirmsExisting =\n action === \"verify-address\" && input.captured.targetIdentifierRevision !== undefined;\n\n const nextRevision = confirmsExisting\n ? input.captured.revision.securityRevision\n : yield* nextSecurityRevision(\n mapping,\n configuration.mode,\n input.captured.revision.securityRevision,\n );\n\n if (\n (!confirmsExisting && nextRevision === input.captured.revision.securityRevision) ||\n [\n targetIdentifierRevision,\n targetCredentialRevision,\n sourceIdentifierRevision,\n sourceCredentialRevision,\n ].some((value) => input.captured.revision.credentials.some((item) => item.revision === value))\n )\n return yield* unavailable();\n\n const run = owned(\n database,\n configuration,\n Effect.gen(function* () {\n const journal = yield* CurrentCommitJournal;\n\n const current = yield* validateEmailAuthority(mapping, configuration, input, action);\n\n if (current === undefined) return prepare(\"rejected\", journal);\n if (\n (yield* commandExists(mapping, input.moduleId, input.commandId, configuration.locking))\n .length > 0\n )\n return prepare(\"rejected\", journal);\n let receipt: PreparedCommit<A> | undefined;\n\n yield* completeProofPlanIn(\n configuration.proof!.mapping,\n configuration.proof!.configuration,\n input.completion,\n Effect.gen(function* () {\n // The proof helper may wait on continuation/series locks. Read the\n // commit clock and reassess both policies only after those locks.\n const currentRequirement = yield* mapping.subject.decodeActionRequirement(\n current.subject,\n action,\n );\n\n const original = yield* assessAuthentication(\n input.authorization.evidence,\n input.authorization.requirement,\n ).pipe(Effect.mapError(unavailable));\n\n const configured = yield* assessAuthentication(\n input.authorization.evidence,\n currentRequirement,\n ).pipe(Effect.mapError(unavailable));\n\n if (!original.satisfied || !configured.satisfied) return false;\n const now = yield* nowMillis;\n\n return yield* applyMutation(\n mapping,\n input,\n action,\n current,\n {\n targetCredentialId,\n targetIdentifierRevision,\n targetCredentialRevision,\n sourceIdentifierRevision,\n sourceCredentialRevision,\n nextSecurityRevision: nextRevision,\n },\n now,\n );\n }),\n (decision) => {\n receipt = prepare(decision === \"completed\" ? \"changed\" : \"rejected\", journal);\n\n return decision;\n },\n );\n\n return receipt ?? prepare(\"rejected\", journal);\n }),\n );\n\n return yield* run.pipe(\n Effect.catchCause((cause) =>\n (cause.reasons.every(Cause.isFailReason) &&\n isMappedConstraintConflict(mapping.isCommandConflict, cause)) ||\n (cause.reasons.every(Cause.isFailReason) &&\n isMappedConstraintConflict(mapping.isIdentifierConflict, cause)) ||\n (cause.reasons.every(Cause.isFailReason) &&\n isMappedConstraintConflict(mapping.isCredentialConflict, cause))\n ? prepareRejected(configuration, prepare)\n : Effect.failCause(cause),\n ),\n );\n });\n\n return {\n validEmailSignInConstraints,\n emailLookupQuery,\n decodeE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,KACrC,2BAA2B,QAAQ,sBAAsB,KAAK,KAC/D,MAAM,QAAQ,MAAM,MAAM,YAAY,KACrC,2BAA2B,QAAQ,sBAAsB,KAAK,IAC5D,gBAAgB,eAAe,OAAO,IACtC,OAAO,UAAU,KAAK,CAC5B,CACF;CACF,CAAC;CAED,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"email-kernel.mjs","names":[],"sources":["../../src/internal/email-kernel.ts"],"sourcesContent":["import {\n EmailAddressPersistence,\n type EmailAddressMutation,\n type EmailAction,\n type EmailCredentialSnapshot,\n EmailSignInTargets,\n EmailUnavailable,\n snapshotEmailCredential,\n snapshotEmailRequirement,\n snapshotEmailRevision,\n} from \"@yielded/auth/Email\";\nimport {\n coordinateCommit,\n CurrentCommitJournal,\n hasCommitScope,\n type CommitJournal,\n type PreparedCommit,\n LifecycleHooks,\n HookConfigurationError,\n} from \"@yielded/auth/Hooks\";\nimport type { LoginIdentifier } from \"@yielded/auth/Identity\";\nimport { reportPersistenceFailure } from \"@yielded/auth/Persistence\";\nimport {\n ProofUnavailable,\n type ProofCompletionDecision,\n type ProofCompletionInput,\n} from \"@yielded/auth/Proofs\";\nimport {\n assessAuthentication,\n snapshotAuthenticationEvidence,\n type AuthenticationRevision,\n type SecurityRevision,\n} from \"@yielded/auth/Sessions\";\nimport { Cause, Context, DateTime, Effect, Option, Schema } from \"effect\";\nimport type * as SqlError from \"effect/sql/SqlError\";\n\nimport { isMappedConstraintConflict, PersistenceMappingError } from \"./mapping-error\";\nimport {\n type AnyEmailAddressMapping,\n type AnyEmailSignInMapping,\n requiredEmailAddressConstraints,\n requiredEmailSignInConstraints,\n} from \"./models/email-model\";\nimport {\n CurrentProofSql,\n type makeProofKernel,\n type ProofSqlConfiguration,\n type ProofSqlDatabase,\n} from \"./proof-kernel\";\n/* oxlint-disable no-explicit-any -- the shared dialect kernel erases consumer Drizzle table types internally. */\nimport type { QueryFailure } from \"./query-operations\";\nimport type { QueryOperations, SqlFragment, SqlColumn } from \"./query-operations\";\nimport type { NativeDatabase } from \"./transaction-kernel\";\n\ntype AdapterFailure = QueryFailure | PersistenceMappingError | SqlError.SqlError;\ntype SignInMapping = AnyEmailSignInMapping;\n\nexport interface EmailSqlQuery<A = ReadonlyArray<any>> extends Effect.Effect<A, AdapterFailure> {\n readonly getSQL: () => ReturnType<QueryOperations[\"sql\"]>;\n readonly from: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly where: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly limit: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly orderBy: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly for: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly set: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly values: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly returning: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly innerJoin: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly onConflictDoNothing: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly onDuplicateKeyUpdate: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n readonly $returningId: (...args: ReadonlyArray<any>) => EmailSqlQuery<A>;\n}\n\nexport interface EmailSqlDatabase {\n readonly select: (...args: ReadonlyArray<any>) => EmailSqlQuery;\n readonly insert: (...args: ReadonlyArray<any>) => EmailSqlQuery;\n readonly update: (...args: ReadonlyArray<any>) => EmailSqlQuery;\n readonly delete: (...args: ReadonlyArray<any>) => EmailSqlQuery;\n readonly transaction: <A, E, R>(\n body: (transaction: EmailSqlDatabase) => Effect.Effect<A, E, R>,\n ) => Effect.Effect<A, E | SqlError.SqlError, R>;\n}\n\nexport class CurrentEmailSql extends Context.Service<CurrentEmailSql, EmailSqlDatabase>()(\n \"effect-auth/CurrentEmailSql\",\n) {}\n\nexport interface EmailSqlConfiguration {\n readonly mode: \"interactive\" | \"synchronous\";\n readonly locking: boolean;\n readonly standaloneGuard: Effect.Effect<void, EmailUnavailable>;\n readonly coordinated?: boolean;\n readonly proof?: {\n readonly mapping: any;\n readonly configuration: ProofSqlConfiguration;\n };\n}\n\nexport interface CurrentAddress {\n readonly nativeSubjectId: unknown;\n readonly subject: any;\n readonly revision: AuthenticationRevision;\n readonly source?: {\n readonly credential: any;\n readonly identifier: any;\n readonly snapshot: EmailCredentialSnapshot;\n };\n readonly targetIdentifier?: any;\n readonly targetCredential?: any;\n readonly targetIdentifierRevision?: SecurityRevision;\n readonly eligible: boolean;\n}\n\nexport const makeEmailKernel = <\n Fragment extends SqlFragment = SqlFragment,\n Column extends SqlColumn = SqlColumn,\n>(\n operations: QueryOperations<Fragment, Column>,\n proofs: Pick<ReturnType<typeof makeProofKernel>, \"completeProofPlanIn\">,\n) => {\n type AddressMapping = AnyEmailAddressMapping<Fragment>;\n\n const { and, eq, inArray, lte, column, updateValues } = operations;\n const { completeProofPlanIn } = proofs;\n const unavailable = () => EmailUnavailable.make({});\n\n const translateFailure = <A, E, R>(\n effect: Effect.Effect<A, E, R>,\n ): Effect.Effect<A, EmailUnavailable, R> =>\n reportPersistenceFailure(\n effect,\n (error) =>\n Schema.is(EmailUnavailable)(error) ||\n Schema.is(ProofUnavailable)(error) ||\n Schema.is(HookConfigurationError)(error),\n ).pipe(Effect.catchCause((cause) => Effect.failCause(Cause.map(cause, () => unavailable()))));\n\n const nowMillis = Effect.map(DateTime.now, DateTime.toEpochMillis);\n\n const selectRows = (query: EmailSqlQuery, locking: boolean) =>\n locking && typeof query.for === \"function\" ? query.for(\"update\") : query;\n\n const sameIdentifier = (left: LoginIdentifier, right: LoginIdentifier) =>\n left.namespace === right.namespace && left.value === right.value;\n\n const validEmailSignInConstraints = (mapping: SignInMapping) =>\n Object.entries(requiredEmailSignInConstraints).every(\n ([key, value]) =>\n mapping.constraints[key as keyof typeof requiredEmailSignInConstraints] === value,\n );\n\n const validAddressConstraints = (mapping: AddressMapping) =>\n Object.entries(requiredEmailAddressConstraints).every(\n ([key, value]) =>\n mapping.constraints[key as keyof typeof requiredEmailAddressConstraints] === value,\n );\n\n const subjectColumns = (mapping: SignInMapping) => ({\n id: column(mapping.subject.table, mapping.subject.id),\n status: column(mapping.subject.table, mapping.subject.status),\n securityRevision: column(mapping.subject.table, mapping.subject.securityRevision),\n });\n\n const identifierColumns = (mapping: SignInMapping) => ({\n namespace: column(mapping.identifier.table, mapping.identifier.namespace),\n value: column(mapping.identifier.table, mapping.identifier.value),\n subjectId: column(mapping.identifier.table, mapping.identifier.subjectId),\n verifiedAt: column(mapping.identifier.table, mapping.identifier.verifiedAt),\n bindingRevision: column(mapping.identifier.table, mapping.identifier.bindingRevision),\n });\n\n const credentialColumns = (mapping: SignInMapping) => ({\n moduleId: column(mapping.credential.table, mapping.credential.moduleId),\n subjectId: column(mapping.credential.table, mapping.credential.subjectId),\n credentialId: column(mapping.credential.table, mapping.credential.credentialId),\n identifierNamespace: column(mapping.credential.table, mapping.credential.identifierNamespace),\n identifierValue: column(mapping.credential.table, mapping.credential.identifierValue),\n credentialRevision: column(mapping.credential.table, mapping.credential.credentialRevision),\n status: column(mapping.credential.table, mapping.credential.status),\n });\n\n const authorityColumns = (mapping: AddressMapping) => ({\n subjectId: column(mapping.authorityCredential.table, mapping.authorityCredential.subjectId),\n credentialId: column(\n mapping.authorityCredential.table,\n mapping.authorityCredential.credentialId,\n ),\n revision: column(mapping.authorityCredential.table, mapping.authorityCredential.revision),\n status: column(mapping.authorityCredential.table, mapping.authorityCredential.status),\n });\n\n const commandColumns = (mapping: AddressMapping) => ({\n moduleId: column(mapping.command.table, mapping.command.moduleId),\n commandId: column(mapping.command.table, mapping.command.commandId),\n action: column(mapping.command.table, mapping.command.action),\n bindingDigest: column(mapping.command.table, mapping.command.bindingDigest),\n retentionUntil: column(mapping.command.table, mapping.command.retentionUntil),\n });\n\n const allocate = <A>(\n mode: EmailSqlConfiguration[\"mode\"],\n asynchronous: Effect.Effect<A, PersistenceMappingError> | undefined,\n synchronous: (() => A) | undefined,\n ) => {\n if (mode === \"synchronous\")\n return synchronous === undefined\n ? Effect.fail(unavailable())\n : Effect.try({\n try: synchronous,\n catch: (cause) => new PersistenceMappingError({ operation: \"mapping\", cause }),\n });\n if (asynchronous !== undefined) return asynchronous;\n\n return synchronous === undefined\n ? Effect.fail(unavailable())\n : Effect.try({\n try: synchronous,\n catch: (cause) => new PersistenceMappingError({ operation: \"mapping\", cause }),\n });\n };\n\n const nextSecurityRevision = (\n mapping: AddressMapping,\n mode: EmailSqlConfiguration[\"mode\"],\n current: SecurityRevision,\n ) => {\n if (mode === \"synchronous\")\n return mapping.subject.nextSecurityRevisionSync === undefined\n ? Effect.fail(unavailable())\n : Effect.try({\n try: () => mapping.subject.nextSecurityRevisionSync!(current),\n catch: (cause) => new PersistenceMappingError({ operation: \"mapping\", cause }),\n });\n if (mapping.subject.nextSecurityRevision !== undefined)\n return mapping.subject.nextSecurityRevision(current);\n if (mapping.subject.nextSecurityRevisionSync !== undefined)\n return Effect.try({\n try: () => mapping.subject.nextSecurityRevisionSync!(current),\n catch: (cause) => new PersistenceMappingError({ operation: \"mapping\", cause }),\n });\n\n return Effect.fail(unavailable());\n };\n\n const safeRead = <A, E, R>(\n database: EmailSqlDatabase,\n configuration: EmailSqlConfiguration,\n body: Effect.Effect<A, E, R>,\n ) =>\n Effect.gen(function* () {\n if (configuration.coordinated !== true) {\n if (yield* hasCommitScope) return yield* unavailable();\n yield* configuration.standaloneGuard;\n }\n\n return yield* database.transaction((transaction) =>\n body.pipe(\n Effect.provideService(CurrentEmailSql, transaction),\n Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),\n ),\n );\n });\n\n const owned = <A, E, R>(\n database: EmailSqlDatabase,\n configuration: EmailSqlConfiguration,\n body: Effect.Effect<A, E, R>,\n ) => {\n const run = coordinateCommit(\n () =>\n database.transaction((transaction) =>\n body.pipe(\n Effect.provideService(CurrentEmailSql, transaction),\n Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),\n ),\n ),\n { mode: configuration.mode },\n ).pipe(Effect.map((result) => result.value));\n\n return configuration.coordinated !== true\n ? Effect.gen(function* () {\n if (yield* hasCommitScope) return yield* unavailable();\n yield* configuration.standaloneGuard;\n\n return yield* run;\n })\n : run;\n };\n\n const emailLookupQuery = (\n mapping: SignInMapping,\n moduleId: string,\n identifier: LoginIdentifier,\n ) => {\n const subject = subjectColumns(mapping),\n binding = identifierColumns(mapping),\n credential = credentialColumns(mapping);\n\n return {\n fields: {\n subject: mapping.subject.table,\n identifier: mapping.identifier.table,\n credential: mapping.credential.table,\n },\n from: mapping.identifier.table,\n subjectTable: mapping.subject.table,\n subjectJoin: eq(subject.id, binding.subjectId),\n credentialTable: mapping.credential.table,\n credentialJoin: and(\n eq(credential.moduleId, moduleId),\n eq(credential.subjectId, binding.subjectId),\n eq(credential.identifierNamespace, binding.namespace),\n eq(credential.identifierValue, binding.value),\n ),\n predicate: and(\n eq(binding.namespace, identifier.namespace),\n eq(binding.value, identifier.value),\n ),\n limit: 1,\n };\n };\n\n const emailLookupRows = Effect.fn(\"Drizzle.emailLookupRows\")(function* (\n mapping: SignInMapping,\n moduleId: string,\n identifier: LoginIdentifier,\n ) {\n const database = yield* CurrentEmailSql;\n const query = emailLookupQuery(mapping, moduleId, identifier);\n\n return yield* database\n .select(query.fields)\n .from(query.from)\n .innerJoin(query.subjectTable, query.subjectJoin)\n .innerJoin(query.credentialTable, query.credentialJoin)\n .where(query.predicate)\n .limit(query.limit);\n });\n\n const decodeEmailSnapshot = Effect.fn(\"DrizzleEmail.decodeSnapshot\")(function* (\n mapping: SignInMapping,\n moduleId: string,\n requested: LoginIdentifier,\n row: any,\n ) {\n if (\n !mapping.subject.isActiveStatus(row.subject[mapping.subject.status]) ||\n !mapping.identifier.isCurrent(row.identifier) ||\n !mapping.credential.isActiveStatus(row.credential[mapping.credential.status])\n )\n return undefined;\n\n const snapshot = yield* mapping.credential\n .decode({\n moduleId,\n subject: row.subject,\n identifier: row.identifier,\n credential: row.credential,\n })\n .pipe(Effect.flatMap(snapshotEmailCredential));\n\n const subjectId = yield* mapping.subjectId.toSubject(row.subject[mapping.subject.id]);\n\n const verifiedAtMillis = yield* mapping.decodeInstant(\n row.identifier[mapping.identifier.verifiedAt],\n );\n\n if (\n snapshot.moduleId !== moduleId ||\n !sameIdentifier(snapshot.identifier, requested) ||\n snapshot.revision.subjectId !== subjectId ||\n snapshot.revision.securityRevision !== row.subject[mapping.subject.securityRevision] ||\n snapshot.identifierRevision !== row.identifier[mapping.identifier.bindingRevision] ||\n snapshot.verifiedAtMillis !== verifiedAtMillis ||\n snapshot.credentialId !== row.credential[mapping.credential.credentialId] ||\n snapshot.credentialRevision !== row.credential[mapping.credential.credentialRevision]\n )\n return undefined;\n\n return snapshot;\n });\n\n const makeSqlEmailSignInTargets = Effect.fn(\"makeSqlEmailSignInTargets\")(function* (\n mapping: SignInMapping,\n configuration: EmailSqlConfiguration,\n ): Effect.fn.Return<\n EmailSignInTargets[\"Service\"],\n EmailUnavailable,\n CurrentEmailSql | NativeDatabase\n > {\n const database = yield* CurrentEmailSql;\n\n if (!configuration.coordinated)\n yield* (\n operations.validateStorage?.({\n ...mapping,\n proof: configuration.proof?.mapping,\n }) ?? Effect.void\n ).pipe(Effect.mapError(unavailable));\n\n return EmailSignInTargets.of({\n lookup: (input) =>\n (validEmailSignInConstraints(mapping)\n ? safeRead(\n database,\n configuration,\n Effect.gen(function* () {\n const row = (yield* emailLookupRows(mapping, input.moduleId, input.identifier))[0];\n\n if (row === undefined) return Option.none();\n\n const snapshot = yield* decodeEmailSnapshot(\n mapping,\n input.moduleId,\n input.identifier,\n row,\n );\n\n return snapshot === undefined ? Option.none() : Option.some(snapshot);\n }),\n )\n : Effect.fail(unavailable())\n ).pipe(Effect.provideService(CurrentEmailSql, database), translateFailure),\n });\n });\n\n const readSubject = Effect.fn(\"DrizzleEmail.readSubject\")(function* (\n mapping: AddressMapping,\n subjectId: string,\n locking: boolean,\n ) {\n const database = yield* CurrentEmailSql;\n\n const nativeSubjectId = yield* mapping.subjectId.toNative(subjectId as any);\n const s = subjectColumns(mapping);\n\n const subject = (yield* selectRows(\n database.select().from(mapping.subject.table).where(eq(s.id, nativeSubjectId)).limit(1),\n locking,\n ))[0];\n\n return { nativeSubjectId, subject };\n });\n\n const identifierRow = Effect.fn(\"Drizzle.identifierRow\")(function* (\n mapping: SignInMapping,\n identifier: LoginIdentifier,\n locking: boolean,\n ) {\n const database = yield* CurrentEmailSql;\n\n const i = identifierColumns(mapping);\n\n return yield* selectRows(\n database\n .select()\n .from(mapping.identifier.table)\n .where(and(eq(i.namespace, identifier.namespace), eq(i.value, identifier.value)))\n .limit(1),\n locking,\n );\n });\n\n const credentialById = Effect.fn(\"Drizzle.credentialById\")(function* (\n mapping: SignInMapping,\n moduleId: string,\n credentialId: string,\n locking: boolean,\n ) {\n const database = yield* CurrentEmailSql;\n\n const c = credentialColumns(mapping);\n\n return yield* selectRows(\n database\n .select()\n .from(mapping.credential.table)\n .where(and(eq(c.moduleId, moduleId), eq(c.credentialId, credentialId)))\n .limit(1),\n locking,\n );\n });\n\n const credentialByIdentifier = Effect.fn(\"Drizzle.credentialByIdentifier\")(function* (\n mapping: SignInMapping,\n moduleId: string,\n identifier: LoginIdentifier,\n locking: boolean,\n ) {\n const database = yield* CurrentEmailSql;\n\n const c = credentialColumns(mapping);\n\n return yield* selectRows(\n database\n .select()\n .from(mapping.credential.table)\n .where(\n and(\n eq(c.moduleId, moduleId),\n eq(c.identifierNamespace, identifier.namespace),\n eq(c.identifierValue, identifier.value),\n ),\n )\n .limit(1),\n locking,\n );\n });\n\n const currentAddress = Effect.fn(\"DrizzleEmail.currentAddress\")(function* (\n mapping: AddressMapping,\n input: {\n readonly moduleId: string;\n readonly subjectId: string;\n readonly target: LoginIdentifier;\n readonly sourceCredentialId?: string;\n },\n locking: boolean,\n ) {\n const database = yield* CurrentEmailSql;\n\n const locked = yield* readSubject(mapping, input.subjectId, locking);\n\n if (\n locked.subject === undefined ||\n !mapping.subject.isActiveStatus(locked.subject[mapping.subject.status])\n )\n return undefined;\n\n const discoveredSource =\n input.sourceCredentialId === undefined\n ? undefined\n : (yield* credentialById(mapping, input.moduleId, input.sourceCredentialId, false))[0];\n\n const sourceIdentifier: LoginIdentifier | undefined =\n discoveredSource === undefined\n ? undefined\n : {\n namespace: discoveredSource[mapping.credential.identifierNamespace],\n value: discoveredSource[mapping.credential.identifierValue],\n };\n\n const identifiers = [\n input.target,\n ...(sourceIdentifier === undefined ? [] : [sourceIdentifier]),\n ]\n .filter(\n (value, index, values) =>\n values.findIndex((candidate) => sameIdentifier(candidate, value)) === index,\n )\n .sort((left, right) =>\n `${left.namespace}\\u0000${left.value}`.localeCompare(\n `${right.namespace}\\u0000${right.value}`,\n ),\n );\n\n const lockedIdentifiers = new Map<string, any>();\n\n for (const identifier of identifiers) {\n const row = (yield* identifierRow(mapping, identifier, locking))[0];\n\n if (row !== undefined)\n lockedIdentifiers.set(`${identifier.namespace}\\u0000${identifier.value}`, row);\n }\n\n const sourceCredential =\n input.sourceCredentialId === undefined\n ? undefined\n : (yield* credentialById(mapping, input.moduleId, input.sourceCredentialId, locking))[0];\n\n const targetCredential = (yield* credentialByIdentifier(\n mapping,\n input.moduleId,\n input.target,\n locking,\n ))[0];\n\n const a = authorityColumns(mapping);\n\n const authority = yield* selectRows(\n database\n .select()\n .from(mapping.authorityCredential.table)\n .where(eq(a.subjectId, locked.nativeSubjectId))\n .orderBy(a.credentialId),\n locking,\n );\n\n const activeAuthority = authority.filter((row: any) =>\n mapping.authorityCredential.isActiveStatus(row[mapping.authorityCredential.status]),\n );\n\n const subjectId = yield* mapping.subjectId.toSubject(locked.nativeSubjectId);\n\n const revision: AuthenticationRevision = Object.freeze({\n subjectId,\n securityRevision: locked.subject[mapping.subject.securityRevision],\n credentials: Object.freeze(\n activeAuthority.map((row: any) =>\n Object.freeze({\n credentialId: row[mapping.authorityCredential.credentialId],\n revision: row[mapping.authorityCredential.revision],\n }),\n ),\n ),\n });\n\n const targetIdentifier = lockedIdentifiers.get(\n `${input.target.namespace}\\u0000${input.target.value}`,\n );\n\n const targetOwned =\n targetIdentifier !== undefined &&\n mapping.subjectId.equals(\n targetIdentifier[mapping.identifier.subjectId],\n locked.nativeSubjectId,\n );\n\n const targetMutable =\n targetOwned &&\n mapping.identifier.isMutableTarget(targetIdentifier) &&\n (targetCredential === undefined ||\n (!mapping.credential.isActiveStatus(targetCredential[mapping.credential.status]) &&\n mapping.subjectId.equals(\n targetCredential[mapping.credential.subjectId],\n locked.nativeSubjectId,\n )));\n\n let source: CurrentAddress[\"source\"];\n\n if (input.sourceCredentialId !== undefined) {\n if (\n sourceCredential === undefined ||\n sourceIdentifier === undefined ||\n !mapping.subjectId.equals(\n sourceCredential[mapping.credential.subjectId],\n locked.nativeSubjectId,\n ) ||\n !mapping.credential.isActiveStatus(sourceCredential[mapping.credential.status])\n )\n return undefined;\n\n const sourceIdentifierRow = lockedIdentifiers.get(\n `${sourceIdentifier.namespace}\\u0000${sourceIdentifier.value}`,\n );\n\n if (\n sourceIdentifierRow === undefined ||\n !mapping.identifier.isCurrent(sourceIdentifierRow) ||\n !mapping.subjectId.equals(\n sourceIdentifierRow[mapping.identifier.subjectId],\n locked.nativeSubjectId,\n )\n )\n return undefined;\n\n const snapshot = yield* mapping.credential\n .decode({\n moduleId: input.moduleId,\n subject: locked.subject,\n identifier: sourceIdentifierRow,\n credential: sourceCredential,\n })\n .pipe(Effect.flatMap(snapshotEmailCredential));\n\n source = { credential: sourceCredential, identifier: sourceIdentifierRow, snapshot };\n }\n let eligible = targetIdentifier === undefined ? targetCredential === undefined : targetMutable;\n\n if (input.sourceCredentialId !== undefined && source === undefined) eligible = false;\n if (source !== undefined && sameIdentifier(source.snapshot.identifier, input.target))\n eligible = false;\n if (mapping.addressCardinality === \"single\" && input.sourceCredentialId === undefined) {\n const c = credentialColumns(mapping);\n\n const rows = yield* selectRows(\n database\n .select()\n .from(mapping.credential.table)\n .where(and(eq(c.moduleId, input.moduleId), eq(c.subjectId, locked.nativeSubjectId))),\n locking,\n );\n\n if (\n rows.some((row: any) => mapping.credential.isActiveStatus(row[mapping.credential.status]))\n )\n eligible = false;\n }\n\n return {\n nativeSubjectId: locked.nativeSubjectId,\n subject: locked.subject,\n revision,\n ...(source === undefined ? {} : { source }),\n ...(targetIdentifier === undefined ? {} : { targetIdentifier }),\n ...(targetCredential === undefined ? {} : { targetCredential }),\n ...(targetMutable\n ? { targetIdentifierRevision: targetIdentifier[mapping.identifier.bindingRevision] }\n : {}),\n eligible,\n };\n });\n\n const sameEmailRevision = (left: AuthenticationRevision, right: AuthenticationRevision) => {\n if (\n left.subjectId !== right.subjectId ||\n left.securityRevision !== right.securityRevision ||\n left.credentials.length !== right.credentials.length\n )\n return false;\n\n const expected = [...left.credentials].sort((a, b) =>\n a.credentialId.localeCompare(b.credentialId),\n );\n\n const actual = [...right.credentials].sort((a, b) =>\n a.credentialId.localeCompare(b.credentialId),\n );\n\n return expected.every(\n (item, index) =>\n item.credentialId === actual[index]!.credentialId &&\n item.revision === actual[index]!.revision,\n );\n };\n\n const actionModule = (moduleId: string, action: EmailAction) =>\n `${moduleId}/${action === \"verify-address\" ? \"verify-address\" : \"change-address\"}`;\n\n const actionPurpose = (action: EmailAction) =>\n action === \"verify-address\" ? \"email-address-verification\" : \"email-address-change\";\n\n const completionMatches = (input: EmailAddressMutation, action: EmailAction) => {\n const completion = input.completion.input;\n const binding = completion.binding;\n\n return (\n completion.moduleId === actionModule(input.moduleId, action) &&\n completion.purpose === actionPurpose(action) &&\n binding._tag === \"IdentifierChange\" &&\n sameIdentifier(binding.identifier, input.target) &&\n sameEmailRevision(binding.revision, input.captured.revision)\n );\n };\n\n const snapshotEmailMutation = Effect.fn(\"DrizzleEmail.snapshotMutation\")(function* (\n input: EmailAddressMutation,\n ) {\n const evidence = yield* snapshotAuthenticationEvidence(input.authorization.evidence).pipe(\n Effect.mapError(unavailable),\n );\n\n const requirement = yield* snapshotEmailRequirement(input.authorization.requirement);\n\n const source =\n input.captured.source === undefined\n ? undefined\n : yield* snapshotEmailCredential(input.captured.source);\n\n return Object.freeze({\n ...input,\n target: Object.freeze({ ...input.target }),\n ...(input.invalidation === undefined\n ? {}\n : { invalidation: Object.freeze({ ...input.invalidation }) }),\n captured: Object.freeze({\n eligible: input.captured.eligible,\n revision: snapshotEmailRevision(input.captured.revision),\n ...(input.captured.targetIdentifierRevision === undefined\n ? {}\n : { targetIdentifierRevision: input.captured.targetIdentifierRevision }),\n ...(source === undefined ? {} : { source }),\n }),\n authorization: Object.freeze({\n challenge: Object.freeze({\n ...input.authorization.challenge,\n target: Object.freeze({ ...input.authorization.challenge.target }),\n revision: snapshotEmailRevision(input.authorization.challenge.revision),\n }),\n evidence,\n requirement,\n }),\n });\n });\n\n const validateEmailAuthority = Effect.fn(\"DrizzleEmail.validateAuthority\")(function* (\n mapping: AddressMapping,\n configuration: EmailSqlConfiguration,\n input: EmailAddressMutation,\n action: EmailAction,\n ) {\n const confirmsExisting =\n action === \"verify-address\" && input.captured.targetIdentifierRevision !== undefined;\n\n if (\n !input.captured.eligible ||\n !completionMatches(input, action) ||\n input.authorization.challenge.moduleId !== input.moduleId ||\n input.authorization.challenge.action !== action ||\n input.authorization.challenge.commandId !== input.commandId ||\n !sameIdentifier(input.authorization.challenge.target, input.target) ||\n input.authorization.challenge.sourceCredentialId !== input.captured.source?.credentialId ||\n !sameEmailRevision(input.authorization.challenge.revision, input.captured.revision) ||\n input.authorization.challenge.targetIdentifierRevision !==\n input.captured.targetIdentifierRevision ||\n (input.authorization.evidence.flowId as string) !== (input.commandId as string) ||\n input.authorization.evidence.bindingDigest !== input.authorization.challenge.bindingDigest ||\n !sameEmailRevision(input.authorization.evidence.revision, input.captured.revision) ||\n (action === \"verify-address\" && input.captured.source !== undefined) ||\n (action === \"change-address\" && input.captured.source === undefined) ||\n confirmsExisting !== (input.invalidation === undefined) ||\n ((input.invalidation?.existingSessions === \"immediate\" ||\n input.invalidation?.existingSessions === \"cache-expiry\") &&\n mapping.sessionInvalidation !== \"same-authority-immediate\")\n )\n return undefined;\n\n const current = yield* currentAddress(\n mapping,\n {\n moduleId: input.moduleId,\n subjectId: input.captured.revision.subjectId,\n target: input.target,\n ...(input.captured.source === undefined\n ? {}\n : { sourceCredentialId: input.captured.source.credentialId }),\n },\n configuration.locking,\n );\n\n if (\n current === undefined ||\n !current.eligible ||\n !sameEmailRevision(current.revision, input.captured.revision) ||\n current.targetIdentifierRevision !== input.captured.targetIdentifierRevision ||\n (input.captured.source !== undefined &&\n (current.source === undefined ||\n current.source.snapshot.identifierRevision !== input.captured.source.identifierRevision ||\n current.source.snapshot.credentialRevision !== input.captured.source.credentialRevision ||\n !sameIdentifier(current.source.snapshot.identifier, input.captured.source.identifier)))\n )\n return undefined;\n\n const currentRequirement = yield* mapping.subject.decodeActionRequirement(\n current.subject,\n action,\n );\n\n const original = yield* assessAuthentication(\n input.authorization.evidence,\n input.authorization.requirement,\n ).pipe(Effect.mapError(unavailable));\n\n const configured = yield* assessAuthentication(\n input.authorization.evidence,\n currentRequirement,\n ).pipe(Effect.mapError(unavailable));\n\n return original.satisfied && configured.satisfied ? current : undefined;\n });\n\n const commandExists = Effect.fn(\"Drizzle.commandExists\")(function* (\n mapping: AddressMapping,\n moduleId: string,\n commandId: string,\n locking: boolean,\n ) {\n const database = yield* CurrentEmailSql;\n\n const c = commandColumns(mapping);\n\n return yield* selectRows(\n database\n .select()\n .from(mapping.command.table)\n .where(and(eq(c.moduleId, moduleId), eq(c.commandId, commandId)))\n .limit(1),\n locking,\n );\n });\n\n const applyMutation = Effect.fn(\"DrizzleEmail.applyMutation\")(function* (\n mapping: AddressMapping,\n input: EmailAddressMutation,\n action: EmailAction,\n current: CurrentAddress,\n allocated: {\n readonly targetCredentialId: string;\n readonly targetIdentifierRevision: SecurityRevision;\n readonly targetCredentialRevision: SecurityRevision;\n readonly sourceIdentifierRevision: SecurityRevision;\n readonly sourceCredentialRevision: SecurityRevision;\n readonly nextSecurityRevision: SecurityRevision;\n },\n now: number,\n ) {\n const database = yield* CurrentEmailSql;\n\n const i = identifierColumns(mapping);\n const c = credentialColumns(mapping);\n const a = authorityColumns(mapping);\n const s = subjectColumns(mapping);\n\n const targetCredentialId =\n current.targetCredential?.[mapping.credential.credentialId] ?? allocated.targetCredentialId;\n\n if (action === \"change-address\") {\n const source = current.source!;\n\n yield* database\n .update(mapping.identifier.table)\n .set(\n mapping.identifier.encodeRetirement({\n source: source.snapshot.identifier,\n bindingRevision: allocated.sourceIdentifierRevision,\n }),\n )\n .where(\n and(\n eq(i.namespace, source.snapshot.identifier.namespace),\n eq(i.value, source.snapshot.identifier.value),\n eq(i.subjectId, current.nativeSubjectId),\n eq(i.bindingRevision, source.snapshot.identifierRevision),\n ),\n );\n yield* database\n .update(mapping.credential.table)\n .set(\n mapping.credential.encodeRetirement({\n source: source.snapshot.identifier,\n credentialRevision: allocated.sourceCredentialRevision,\n }),\n )\n .where(\n and(\n eq(c.moduleId, input.moduleId),\n eq(c.credentialId, source.snapshot.credentialId),\n eq(c.subjectId, current.nativeSubjectId),\n eq(c.credentialRevision, source.snapshot.credentialRevision),\n ),\n );\n yield* database\n .update(mapping.authorityCredential.table)\n .set(mapping.authorityCredential.encodeRetirement(allocated.sourceCredentialRevision))\n .where(\n and(\n eq(a.subjectId, current.nativeSubjectId),\n eq(a.credentialId, source.snapshot.credentialId),\n eq(a.revision, source.snapshot.credentialRevision),\n ),\n );\n }\n if (current.targetIdentifier === undefined) {\n yield* database.insert(mapping.identifier.table).values(\n mapping.identifier.encodeVerifiedInsert({\n identifier: input.target,\n subjectId: current.nativeSubjectId,\n verifiedAtMillis: now,\n bindingRevision: allocated.targetIdentifierRevision,\n }),\n );\n } else {\n yield* database\n .update(mapping.identifier.table)\n .set(\n mapping.identifier.encodeVerification({\n verifiedAtMillis: now,\n bindingRevision: allocated.targetIdentifierRevision,\n }),\n )\n .where(\n and(\n eq(i.namespace, input.target.namespace),\n eq(i.value, input.target.value),\n eq(i.subjectId, current.nativeSubjectId),\n eq(i.bindingRevision, current.targetIdentifier![mapping.identifier.bindingRevision]),\n ),\n );\n }\n if (current.targetCredential === undefined) {\n yield* database.insert(mapping.credential.table).values(\n mapping.credential.encodeVerifiedInsert({\n moduleId: input.moduleId,\n subjectId: current.nativeSubjectId,\n credentialId: targetCredentialId,\n identifier: input.target,\n credentialRevision: allocated.targetCredentialRevision,\n }),\n );\n yield* database.insert(mapping.authorityCredential.table).values(\n mapping.authorityCredential.encodeInsert({\n subjectId: current.nativeSubjectId,\n credentialId: targetCredentialId,\n revision: allocated.targetCredentialRevision,\n }),\n );\n } else {\n const oldRevision = current.targetCredential[mapping.credential.credentialRevision];\n\n yield* database\n .update(mapping.credential.table)\n .set(\n mapping.credential.encodeActivation({\n identifier: input.target,\n credentialRevision: allocated.targetCredentialRevision,\n }),\n )\n .where(\n and(\n eq(c.moduleId, input.moduleId),\n eq(c.credentialId, targetCredentialId),\n eq(c.subjectId, current.nativeSubjectId),\n eq(c.credentialRevision, oldRevision),\n ),\n );\n yield* database\n .update(mapping.authorityCredential.table)\n .set(mapping.authorityCredential.encodeActivation(allocated.targetCredentialRevision))\n .where(\n and(\n eq(a.subjectId, current.nativeSubjectId),\n eq(a.credentialId, targetCredentialId),\n eq(a.revision, oldRevision),\n ),\n );\n }\n yield* database\n .update(mapping.subject.table)\n .set(updateValues([[mapping.subject.securityRevision, allocated.nextSecurityRevision]]))\n .where(\n and(\n eq(s.id, current.nativeSubjectId),\n eq(s.securityRevision, input.captured.revision.securityRevision),\n ),\n );\n yield* database.insert(mapping.command.table).values(\n mapping.command.encodeInsert({\n moduleId: input.moduleId,\n commandId: input.commandId,\n action,\n bindingDigest: input.authorization.challenge.bindingDigest,\n retentionUntilMillis: now + mapping.commandRetentionMillis,\n }),\n );\n\n const sourceStillActive =\n action === \"verify-address\"\n ? []\n : yield* selectRows(\n database\n .select()\n .from(mapping.credential.table)\n .where(\n and(\n eq(c.moduleId, input.moduleId),\n eq(c.credentialId, current.source!.snapshot.credentialId),\n eq(c.subjectId, current.nativeSubjectId),\n ),\n ),\n false,\n );\n\n const target = (yield* emailLookupRows(mapping, input.moduleId, input.target))[0];\n\n const targetAuthority = yield* selectRows(\n database\n .select()\n .from(mapping.authorityCredential.table)\n .where(\n and(eq(a.subjectId, current.nativeSubjectId), eq(a.credentialId, targetCredentialId)),\n )\n .limit(1),\n false,\n );\n\n const command = yield* selectRows(\n database\n .select()\n .from(mapping.command.table)\n .where(\n and(\n eq(commandColumns(mapping).moduleId, input.moduleId),\n eq(commandColumns(mapping).commandId, input.commandId),\n eq(commandColumns(mapping).action, action),\n eq(commandColumns(mapping).bindingDigest, input.authorization.challenge.bindingDigest),\n eq(\n commandColumns(mapping).retentionUntil,\n mapping.encodeInstant(now + mapping.commandRetentionMillis),\n ),\n ),\n )\n .limit(1),\n false,\n );\n\n const targetVerifiedAt =\n target === undefined\n ? undefined\n : yield* mapping.decodeInstant(target.identifier[mapping.identifier.verifiedAt]);\n\n const sourceIdentifier =\n action === \"verify-address\"\n ? []\n : yield* identifierRow(mapping, current.source!.snapshot.identifier, false);\n\n const sourceAuthority =\n action === \"verify-address\"\n ? []\n : yield* selectRows(\n database\n .select()\n .from(mapping.authorityCredential.table)\n .where(\n and(\n eq(a.subjectId, current.nativeSubjectId),\n eq(a.credentialId, current.source!.snapshot.credentialId),\n ),\n )\n .limit(1),\n false,\n );\n\n return (\n target !== undefined &&\n mapping.subjectId.equals(target.subject[mapping.subject.id], current.nativeSubjectId) &&\n mapping.subject.isActiveStatus(target.subject[mapping.subject.status]) &&\n target.subject[mapping.subject.securityRevision] === allocated.nextSecurityRevision &&\n target.identifier[mapping.identifier.bindingRevision] ===\n allocated.targetIdentifierRevision &&\n targetVerifiedAt === now &&\n target.credential[mapping.credential.credentialRevision] ===\n allocated.targetCredentialRevision &&\n target.credential[mapping.credential.credentialId] === targetCredentialId &&\n mapping.subjectId.equals(\n target.credential[mapping.credential.subjectId],\n current.nativeSubjectId,\n ) &&\n mapping.identifier.isCurrent(target.identifier) &&\n mapping.credential.isActiveStatus(target.credential[mapping.credential.status]) &&\n targetAuthority.length === 1 &&\n targetAuthority[0]![mapping.authorityCredential.revision] ===\n allocated.targetCredentialRevision &&\n mapping.authorityCredential.isActiveStatus(\n targetAuthority[0]![mapping.authorityCredential.status],\n ) &&\n command.length === 1 &&\n (action === \"verify-address\" ||\n (sourceStillActive.length === 1 &&\n sourceStillActive[0]![mapping.credential.credentialRevision] ===\n allocated.sourceCredentialRevision &&\n !mapping.credential.isActiveStatus(sourceStillActive[0]![mapping.credential.status]) &&\n sourceIdentifier.length === 1 &&\n mapping.subjectId.equals(\n sourceIdentifier[0]![mapping.identifier.subjectId],\n current.nativeSubjectId,\n ) &&\n sourceIdentifier[0]![mapping.identifier.bindingRevision] ===\n allocated.sourceIdentifierRevision &&\n !mapping.identifier.isCurrent(sourceIdentifier[0]!) &&\n sourceAuthority.length === 1 &&\n sourceAuthority[0]![mapping.authorityCredential.revision] ===\n allocated.sourceCredentialRevision &&\n !mapping.authorityCredential.isActiveStatus(\n sourceAuthority[0]![mapping.authorityCredential.status],\n )))\n );\n });\n\n const probeProofCompletion = Effect.fn(\"Drizzle.probeProofCompletion\")(function* (\n configuration: EmailSqlConfiguration,\n input: ProofCompletionInput,\n ) {\n const database = yield* CurrentEmailSql;\n\n if (configuration.proof === undefined) return yield* Effect.fail(unavailable());\n const validProbe = { _tag: \"EmailProofCompletionValid\" } as const;\n\n const plan = {\n input,\n prepare: <A>(\n decision: ProofCompletionDecision,\n journal: CommitJournal,\n project: (decision: ProofCompletionDecision) => A,\n ) => journal.prepare(project(decision)),\n };\n\n const probe = coordinateCommit(\n () =>\n database.transaction((transaction) =>\n completeProofPlanIn(\n configuration.proof!.mapping,\n configuration.proof!.configuration,\n plan,\n Effect.fail(validProbe),\n () => false,\n ).pipe(\n Effect.provideService(CurrentProofSql, transaction as unknown as ProofSqlDatabase),\n ),\n ),\n { mode: configuration.mode },\n );\n\n return yield* probe.pipe(\n Effect.as(false),\n Effect.catchCause((cause) => {\n const reason = cause.reasons[0];\n\n return cause.reasons.length === 1 &&\n reason !== undefined &&\n Cause.isFailReason(reason) &&\n reason.error === validProbe\n ? Effect.succeed(true)\n : Effect.failCause(cause);\n }),\n );\n });\n\n const prepareRejected = Effect.fn(\"Drizzle.prepareRejected\")(function* <A>(\n configuration: EmailSqlConfiguration,\n prepare: (value: \"rejected\", journal: CommitJournal) => PreparedCommit<A>,\n ) {\n const database = yield* CurrentEmailSql;\n\n return yield* owned(\n database,\n configuration,\n Effect.gen(function* () {\n const journal = yield* CurrentCommitJournal;\n\n return yield* Effect.succeed(prepare(\"rejected\", journal));\n }),\n );\n });\n\n const makeSqlEmailAddressPersistence = Effect.fn(\"makeSqlEmailAddressPersistence\")(function* (\n mapping: AddressMapping,\n configuration: EmailSqlConfiguration,\n ): Effect.fn.Return<\n EmailAddressPersistence[\"Service\"],\n EmailUnavailable,\n LifecycleHooks | CurrentEmailSql | NativeDatabase\n > {\n const database = yield* CurrentEmailSql;\n\n if (!configuration.coordinated)\n yield* (\n operations.validateStorage?.({\n ...mapping,\n proof: configuration.proof?.mapping,\n }) ?? Effect.void\n ).pipe(Effect.mapError(unavailable));\n const hooks = yield* LifecycleHooks;\n\n return EmailAddressPersistence.of({\n target: (input) =>\n (validAddressConstraints(mapping)\n ? safeRead(\n database,\n configuration,\n Effect.gen(function* () {\n const current = yield* currentAddress(mapping, input, configuration.locking);\n\n if (current === undefined) return yield* unavailable();\n\n return Object.freeze({\n revision: snapshotEmailRevision(current.revision),\n eligible: current.eligible,\n ...(current.targetIdentifierRevision === undefined\n ? {}\n : { targetIdentifierRevision: current.targetIdentifierRevision }),\n ...(current.source === undefined\n ? {}\n : { source: yield* snapshotEmailCredential(current.source.snapshot) }),\n });\n }),\n )\n : Effect.fail(unavailable())\n ).pipe(\n Effect.provideService(CurrentEmailSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n checkCompletion: (input) => {\n if (configuration.proof === undefined || input.binding._tag !== \"IdentifierChange\")\n return Effect.succeed(false).pipe(\n Effect.provideService(CurrentEmailSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n );\n const binding = input.binding;\n\n return safeRead(\n database,\n configuration,\n Effect.gen(function* () {\n const action: EmailAction | undefined =\n input.moduleId.endsWith(\"/verify-address\") &&\n input.purpose === \"email-address-verification\"\n ? \"verify-address\"\n : input.moduleId.endsWith(\"/change-address\") &&\n input.purpose === \"email-address-change\"\n ? \"change-address\"\n : undefined;\n\n if (action === undefined) return false;\n const moduleId = input.moduleId.slice(0, -`/${action}`.length);\n\n const current = yield* currentAddress(\n mapping,\n {\n moduleId,\n subjectId: binding.revision.subjectId,\n target: binding.identifier,\n },\n false,\n );\n\n return current !== undefined && sameEmailRevision(current.revision, binding.revision);\n }),\n )\n .pipe(\n Effect.flatMap((current) =>\n current ? probeProofCompletion(configuration, input) : Effect.succeed(false),\n ),\n )\n .pipe(\n Effect.provideService(CurrentEmailSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n );\n },\n verifyWithProof: (uncaptured, prepare) =>\n mutateAddress(mapping, configuration, uncaptured, \"verify-address\", prepare).pipe(\n Effect.provideService(CurrentEmailSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n changeWithProof: (uncaptured, prepare) =>\n mutateAddress(mapping, configuration, uncaptured, \"change-address\", prepare).pipe(\n Effect.provideService(CurrentEmailSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n cleanup: (input, prepare) =>\n owned(\n database,\n configuration,\n Effect.gen(function* () {\n const transaction = yield* CurrentEmailSql;\n const journal = yield* CurrentCommitJournal;\n\n const c = commandColumns(mapping);\n const now = yield* nowMillis;\n\n const rows = yield* selectRows(\n transaction\n .select({ commandId: c.commandId })\n .from(mapping.command.table)\n .where(\n and(\n eq(c.moduleId, input.moduleId),\n lte(c.retentionUntil, mapping.encodeInstant(now)),\n ),\n )\n .limit(input.limit + 1),\n configuration.locking,\n );\n\n const selected = rows.slice(0, input.limit);\n\n const receipt = prepare(\n { removed: selected.length, hasMore: rows.length > input.limit },\n journal,\n );\n\n if (selected.length > 0)\n yield* transaction.delete(mapping.command.table).where(\n and(\n eq(c.moduleId, input.moduleId),\n inArray(\n c.commandId,\n selected.map((row: any) => row.commandId),\n ),\n lte(c.retentionUntil, mapping.encodeInstant(now)),\n ),\n );\n\n return receipt;\n }),\n ).pipe(\n Effect.provideService(CurrentEmailSql, database),\n Effect.provideService(LifecycleHooks, hooks),\n translateFailure,\n ),\n });\n });\n\n const mutateAddress = Effect.fn(\"Drizzle.mutateAddress\")(function* <A>(\n mapping: AddressMapping,\n configuration: EmailSqlConfiguration,\n uncaptured: EmailAddressMutation,\n action: EmailAction,\n prepare: (value: \"changed\" | \"rejected\", journal: CommitJournal) => PreparedCommit<A>,\n ) {\n const database = yield* CurrentEmailSql;\n\n if (!validAddressConstraints(mapping) || configuration.proof === undefined)\n return yield* unavailable();\n const input = yield* snapshotEmailMutation(uncaptured);\n\n const targetCredentialId = yield* allocate(\n configuration.mode,\n mapping.allocateCredentialId,\n mapping.allocateCredentialIdSync,\n );\n\n const targetIdentifierRevision = yield* allocate(\n configuration.mode,\n mapping.allocateRevision,\n mapping.allocateRevisionSync,\n );\n\n const targetCredentialRevision = yield* allocate(\n configuration.mode,\n mapping.allocateRevision,\n mapping.allocateRevisionSync,\n );\n\n const sourceIdentifierRevision = yield* allocate(\n configuration.mode,\n mapping.allocateRevision,\n mapping.allocateRevisionSync,\n );\n\n const sourceCredentialRevision = yield* allocate(\n configuration.mode,\n mapping.allocateRevision,\n mapping.allocateRevisionSync,\n );\n\n const confirmsExisting =\n action === \"verify-address\" && input.captured.targetIdentifierRevision !== undefined;\n\n const nextRevision = confirmsExisting\n ? input.captured.revision.securityRevision\n : yield* nextSecurityRevision(\n mapping,\n configuration.mode,\n input.captured.revision.securityRevision,\n );\n\n if (\n (!confirmsExisting && nextRevision === input.captured.revision.securityRevision) ||\n [\n targetIdentifierRevision,\n targetCredentialRevision,\n sourceIdentifierRevision,\n sourceCredentialRevision,\n ].some((value) => input.captured.revision.credentials.some((item) => item.revision === value))\n )\n return yield* unavailable();\n\n const run = owned(\n database,\n configuration,\n Effect.gen(function* () {\n const journal = yield* CurrentCommitJournal;\n\n const current = yield* validateEmailAuthority(mapping, configuration, input, action);\n\n if (current === undefined) return prepare(\"rejected\", journal);\n if (\n (yield* commandExists(mapping, input.moduleId, input.commandId, configuration.locking))\n .length > 0\n )\n return prepare(\"rejected\", journal);\n let receipt: PreparedCommit<A> | undefined;\n\n yield* completeProofPlanIn(\n configuration.proof!.mapping,\n configuration.proof!.configuration,\n input.completion,\n Effect.gen(function* () {\n // The proof helper may wait on continuation/series locks. Read the\n // commit clock and reassess both policies only after those locks.\n const currentRequirement = yield* mapping.subject.decodeActionRequirement(\n current.subject,\n action,\n );\n\n const original = yield* assessAuthentication(\n input.authorization.evidence,\n input.authorization.requirement,\n ).pipe(Effect.mapError(unavailable));\n\n const configured = yield* assessAuthentication(\n input.authorization.evidence,\n currentRequirement,\n ).pipe(Effect.mapError(unavailable));\n\n if (!original.satisfied || !configured.satisfied) return false;\n const now = yield* nowMillis;\n\n return yield* applyMutation(\n mapping,\n input,\n action,\n current,\n {\n targetCredentialId,\n targetIdentifierRevision,\n targetCredentialRevision,\n sourceIdentifierRevision,\n sourceCredentialRevision,\n nextSecurityRevision: nextRevision,\n },\n now,\n );\n }),\n (decision) => {\n receipt = prepare(decision === \"completed\" ? \"changed\" : \"rejected\", journal);\n\n return decision;\n },\n );\n\n return receipt ?? prepare(\"rejected\", journal);\n }),\n );\n\n return yield* run.pipe(\n Effect.catchCause((cause) =>\n (cause.reasons.every(Cause.isFailReason) &&\n isMappedConstraintConflict(mapping.isCommandConflict, cause)) ||\n (cause.reasons.every(Cause.isFailReason) &&\n isMappedConstraintConflict(mapping.isIdentifierConflict, cause)) ||\n (cause.reasons.every(Cause.isFailReason) &&\n isMappedConstraintConflict(mapping.isCredentialConflict, cause))\n ? prepareRejected(configuration, prepare)\n : Effect.failCause(cause),\n ),\n );\n });\n\n return {\n validEmailSignInConstraints,\n emailLookupQuery,\n decodeEmailSnapshot,\n makeSqlEmailSignInTargets,\n currentAddress,\n sameEmailRevision,\n snapshotEmailMutation,\n validateEmailAuthority,\n makeSqlEmailAddressPersistence,\n };\n};\n"],"mappings":";;;;;;;;;;AAmFA,IAAa,kBAAb,cAAqC,QAAQ,QAA2C,CAAC,CACvF,6BACF,CAAC,CAAC,CAAC;AA4BH,MAAa,mBAIX,YACA,WACG;CAGH,MAAM,EAAE,KAAK,IAAI,SAAS,KAAK,QAAQ,iBAAiB;CACxD,MAAM,EAAE,wBAAwB;CAChC,MAAM,oBAAoB,iBAAiB,KAAK,CAAC,CAAC;CAElD,MAAM,oBACJ,WAEA,yBACE,SACC,UACC,OAAO,GAAG,gBAAgB,CAAC,CAAC,KAAK,KACjC,OAAO,GAAG,gBAAgB,CAAC,CAAC,KAAK,KACjC,OAAO,GAAG,sBAAsB,CAAC,CAAC,KAAK,CAC3C,CAAC,CAAC,KAAK,OAAO,YAAY,UAAU,OAAO,UAAU,MAAM,IAAI,aAAa,YAAY,CAAC,CAAC,CAAC,CAAC;CAE9F,MAAM,YAAY,OAAO,IAAI,SAAS,KAAK,SAAS,aAAa;CAEjE,MAAM,cAAc,OAAsB,YACxC,WAAW,OAAO,MAAM,QAAQ,aAAa,MAAM,IAAI,QAAQ,IAAI;CAErE,MAAM,kBAAkB,MAAuB,UAC7C,KAAK,cAAc,MAAM,aAAa,KAAK,UAAU,MAAM;CAE7D,MAAM,+BAA+B,YACnC,OAAO,QAAQ,8BAA8B,CAAC,CAAC,OAC5C,CAAC,KAAK,WACL,QAAQ,YAAY,SAAwD,KAChF;CAEF,MAAM,2BAA2B,YAC/B,OAAO,QAAQ,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