@yielded/auth-persistence 0.1.0-beta.21 → 0.1.0-beta.23
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.
- package/dist/Adapter.d.mts +4 -2
- package/dist/Adapter.mjs +3 -1
- package/dist/internal/authority-snapshot.mjs +53 -0
- package/dist/internal/authority-snapshot.mjs.map +1 -0
- package/dist/internal/configuration.d.mts +1 -1
- package/dist/internal/configuration.mjs.map +1 -1
- package/dist/internal/models/password-model.d.mts +3 -53
- package/dist/internal/models/password-model.mjs +0 -2
- package/dist/internal/models/password-model.mjs.map +1 -1
- package/dist/internal/native-sql-table.d.mts +30 -0
- package/dist/internal/native-sql-table.mjs +104 -0
- package/dist/internal/native-sql-table.mjs.map +1 -0
- package/dist/internal/passkey/target.d.mts +1 -1
- package/dist/internal/passkeys.mjs +1 -1
- package/dist/internal/password-attempts.d.mts +12 -0
- package/dist/internal/password-attempts.mjs +197 -0
- package/dist/internal/password-attempts.mjs.map +1 -0
- package/dist/internal/password-kernel.d.mts +15 -12
- package/dist/internal/password-kernel.mjs +39 -202
- package/dist/internal/password-kernel.mjs.map +1 -1
- package/dist/internal/persistence.d.mts +2 -0
- package/dist/internal/persistence.mjs +4 -4
- package/dist/internal/persistence.mjs.map +1 -1
- package/dist/internal/session-kernel.d.mts +3 -1
- package/dist/internal/session-kernel.mjs +22 -12
- package/dist/internal/session-kernel.mjs.map +1 -1
- package/dist/internal/sql-persistence.mjs +3 -1
- package/dist/internal/sql-persistence.mjs.map +1 -1
- package/dist/internal/storage-mapping.mjs +1 -30
- package/dist/internal/storage-mapping.mjs.map +1 -1
- package/dist/internal/storage-tables.d.mts +0 -43
- package/dist/internal/storage-tables.mjs +0 -26
- package/dist/internal/storage-tables.mjs.map +1 -1
- package/dist/internal/transaction-execution-kernel.d.mts +1 -1
- package/dist/internal/transaction-kernel.d.mts +1 -1
- package/package.json +1 -1
- package/src/Adapter.ts +9 -4
- package/src/internal/authority-snapshot.ts +91 -0
- package/src/internal/configuration.ts +1 -6
- package/src/internal/models/password-model.ts +0 -64
- package/src/internal/native-sql-table.ts +164 -0
- package/src/internal/password-attempts.ts +466 -0
- package/src/internal/password-kernel.ts +102 -623
- package/src/internal/persistence.ts +5 -10
- package/src/internal/session-kernel.ts +89 -27
- package/src/internal/sql-persistence.ts +2 -0
- package/src/internal/storage-mapping.ts +0 -29
- package/src/internal/storage-tables.ts +0 -15
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { PersistenceConfigurationError } from "./configuration.mjs";
|
|
2
|
+
import { Table } from "./sql-table.mjs";
|
|
3
|
+
import { makeNativeSqlTables } from "./native-sql-table.mjs";
|
|
2
4
|
import { makeComposedPasskeys } from "./passkeys.mjs";
|
|
3
5
|
import { createPersistence } from "./persistence.mjs";
|
|
4
|
-
import { Table } from "./sql-table.mjs";
|
|
5
6
|
import { makeSqlDatabase, sqlQueryOperations } from "./sql-query.mjs";
|
|
6
7
|
import { Effect } from "effect";
|
|
7
8
|
import { SqlClient } from "effect/sql";
|
|
@@ -17,6 +18,7 @@ const AuthPersistence = {
|
|
|
17
18
|
unique: table.unique
|
|
18
19
|
}),
|
|
19
20
|
operations: sqlQueryOperations,
|
|
21
|
+
nativeTables: (client) => makeNativeSqlTables(client),
|
|
20
22
|
passkeys: makeComposedPasskeys(sqlQueryOperations),
|
|
21
23
|
acquire: Effect.gen(function* () {
|
|
22
24
|
const dialect = (yield* SqlClient.SqlClient).onDialectOrElse({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-persistence.mjs","names":[],"sources":["../../src/internal/sql-persistence.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport { SqlClient } from \"effect/sql\";\n\nimport { PersistenceConfigurationError, type PersistenceApi } from \"./configuration\";\nimport { makeComposedPasskeys } from \"./passkeys\";\nimport { createPersistence } from \"./persistence\";\nimport { makeSqlDatabase, sqlQueryOperations } from \"./sql-query\";\nimport { Table } from \"./sql-table\";\nimport type { StorageTable } from \"./storage-tables\";\n\nconst table = (definition: StorageTable) =>\n new Table(definition.name, definition.columns, definition.unique, definition.schema);\n\nexport const AuthPersistence: PersistenceApi<Table> & { readonly table: typeof table } = {\n ...createPersistence({\n makeTable: table,\n describe: (table: Table): StorageTable => ({\n name: table.name,\n ...(table.schema === undefined ? {} : { schema: table.schema }),\n columns: Object.fromEntries(\n Object.entries(table.columns).map(([key, column]) => [key, column.options]),\n ),\n unique: table.unique,\n }),\n operations: sqlQueryOperations,\n passkeys: makeComposedPasskeys(sqlQueryOperations),\n acquire: Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n const dialect = sql.onDialectOrElse({\n pg: () => \"pg\" as const,\n sqlite: () => \"sqlite\" as const,\n orElse: () => undefined,\n });\n\n if (dialect === undefined)\n return yield* PersistenceConfigurationError.make({\n reason: \"Use an explicit adapter for this SQL dialect\",\n });\n\n return yield* makeSqlDatabase(dialect);\n }),\n }),\n table,\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"sql-persistence.mjs","names":[],"sources":["../../src/internal/sql-persistence.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport { SqlClient } from \"effect/sql\";\n\nimport { PersistenceConfigurationError, type PersistenceApi } from \"./configuration\";\nimport { makeNativeSqlTables } from \"./native-sql-table\";\nimport { makeComposedPasskeys } from \"./passkeys\";\nimport { createPersistence } from \"./persistence\";\nimport { makeSqlDatabase, sqlQueryOperations } from \"./sql-query\";\nimport { Table } from \"./sql-table\";\nimport type { StorageTable } from \"./storage-tables\";\n\nconst table = (definition: StorageTable) =>\n new Table(definition.name, definition.columns, definition.unique, definition.schema);\n\nexport const AuthPersistence: PersistenceApi<Table> & { readonly table: typeof table } = {\n ...createPersistence({\n makeTable: table,\n describe: (table: Table): StorageTable => ({\n name: table.name,\n ...(table.schema === undefined ? {} : { schema: table.schema }),\n columns: Object.fromEntries(\n Object.entries(table.columns).map(([key, column]) => [key, column.options]),\n ),\n unique: table.unique,\n }),\n operations: sqlQueryOperations,\n nativeTables: (client) => makeNativeSqlTables(client),\n passkeys: makeComposedPasskeys(sqlQueryOperations),\n acquire: Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n const dialect = sql.onDialectOrElse({\n pg: () => \"pg\" as const,\n sqlite: () => \"sqlite\" as const,\n orElse: () => undefined,\n });\n\n if (dialect === undefined)\n return yield* PersistenceConfigurationError.make({\n reason: \"Use an explicit adapter for this SQL dialect\",\n });\n\n return yield* makeSqlDatabase(dialect);\n }),\n }),\n table,\n};\n"],"mappings":";;;;;;;;;AAWA,MAAM,SAAS,eACb,IAAI,MAAM,WAAW,MAAM,WAAW,SAAS,WAAW,QAAQ,WAAW,MAAM;AAErF,MAAa,kBAA4E;CACvF,GAAG,kBAAkB;EACnB,WAAW;EACX,WAAW,WAAgC;GACzC,MAAM,MAAM;GACZ,GAAI,MAAM,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQ,MAAM,OAAO;GAC7D,SAAS,OAAO,YACd,OAAO,QAAQ,MAAM,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,YAAY,CAAC,KAAK,OAAO,OAAO,CAAC,CAC5E;GACA,QAAQ,MAAM;EAChB;EACA,YAAY;EACZ,eAAe,WAAW,oBAAoB,MAAM;EACpD,UAAU,qBAAqB,kBAAkB;EACjD,SAAS,OAAO,IAAI,aAAa;GAG/B,MAAM,WAAU,OAFG,UAAU,UAAA,CAET,gBAAgB;IAClC,UAAU;IACV,cAAc;IACd,cAAc,KAAA;GAChB,CAAC;GAED,IAAI,YAAY,KAAA,GACd,OAAO,OAAO,8BAA8B,KAAK,EAC/C,QAAQ,+CACV,CAAC;GAEH,OAAO,OAAO,gBAAgB,OAAO;EACvC,CAAC;CACH,CAAC;CACD;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { randomId } from "./crypto.mjs";
|
|
2
1
|
import { PersistenceMappingError } from "./mapping-error.mjs";
|
|
2
|
+
import { randomId } from "./crypto.mjs";
|
|
3
3
|
import { requiredProofConstraints } from "./models/proof-model.mjs";
|
|
4
4
|
import { storageTables } from "./storage-tables.mjs";
|
|
5
5
|
import { requiredEmailAddressConstraints } from "./models/email-model.mjs";
|
|
@@ -327,12 +327,6 @@ const makeMappings = Effect.fnUntraced(function* (input) {
|
|
|
327
327
|
authorityCredential: authorityCredential(),
|
|
328
328
|
constraints: requiredPasswordConstraints,
|
|
329
329
|
isCommandConflict: () => false,
|
|
330
|
-
isRateScopeConflict: () => false,
|
|
331
|
-
scopeKeys: ({ moduleId, action, identifier, subjectId }) => ({
|
|
332
|
-
action: tuple([moduleId, action]),
|
|
333
|
-
identifier: tuple([identifier.namespace, identifier.value]),
|
|
334
|
-
...subjectId === void 0 ? {} : { subject: subjectId }
|
|
335
|
-
}),
|
|
336
330
|
encodeInstant: instant,
|
|
337
331
|
decodeInstant: readInstant,
|
|
338
332
|
allocateAttemptId: allocate.pipe(Effect.map(PasswordAttemptId.make)),
|
|
@@ -439,29 +433,6 @@ const makeMappings = Effect.fnUntraced(function* (input) {
|
|
|
439
433
|
state
|
|
440
434
|
})
|
|
441
435
|
},
|
|
442
|
-
rateScope: {
|
|
443
|
-
...mapped("passwordScopes"),
|
|
444
|
-
moduleId: "moduleId",
|
|
445
|
-
action: "action",
|
|
446
|
-
scopeKind: "scopeKind",
|
|
447
|
-
scopeKey: "scopeKey",
|
|
448
|
-
encodeInsert: (row) => ({ ...row })
|
|
449
|
-
},
|
|
450
|
-
charge: {
|
|
451
|
-
...mapped("passwordCharges"),
|
|
452
|
-
moduleId: "moduleId",
|
|
453
|
-
action: "action",
|
|
454
|
-
scopeKind: "scopeKind",
|
|
455
|
-
scopeKey: "scopeKey",
|
|
456
|
-
attemptId: "attemptId",
|
|
457
|
-
occurredAt: "occurredAt",
|
|
458
|
-
retentionUntil: "retentionUntil",
|
|
459
|
-
encodeInsert: (row) => ({
|
|
460
|
-
...row,
|
|
461
|
-
occurredAt: instant(row.occurredAtMillis),
|
|
462
|
-
retentionUntil: instant(row.retentionUntilMillis)
|
|
463
|
-
})
|
|
464
|
-
},
|
|
465
436
|
command: {
|
|
466
437
|
...mapped("passwordCommands"),
|
|
467
438
|
moduleId: "moduleId",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-mapping.mjs","names":["ProofRecord"],"sources":["../../src/internal/storage-mapping.ts"],"sourcesContent":["import { EmailCredentialSnapshot } from \"@yielded/auth/Email\";\nimport { LoginIdentifier } from \"@yielded/auth/Identity\";\nimport {\n PasswordAttemptId,\n PasswordCredentialSnapshot,\n EncodedPasswordHash,\n type PasswordReplacement,\n} from \"@yielded/auth/Password\";\nimport {\n ProofBinding,\n ProofContinuationId,\n ProofDeliveryId,\n ProofId,\n ProofPurpose,\n ProofRequestId,\n ProofRequestReceipt,\n ProofVersion,\n} from \"@yielded/auth/Proofs\";\nimport { TokenDigest } from \"@yielded/auth/Schema\";\nimport {\n SecurityRevision,\n SessionId,\n SessionMetadata,\n SessionAuthenticationProvenance,\n SessionCredentialVersion,\n type StatefulSessionRecord,\n} from \"@yielded/auth/Sessions\";\nimport { Crypto, DateTime, Effect, Redacted, Schema } from \"effect\";\n\nimport type { MappingInput } from \"./configuration\";\nimport { randomId } from \"./crypto\";\nimport { PersistenceMappingError } from \"./mapping-error\";\nimport { requiredEmailAddressConstraints, type AnyEmailAddressMapping } from \"./models/email-model\";\nimport {\n requiredPasswordConstraints,\n type AnyPasswordPersistenceMapping,\n} from \"./models/password-model\";\nimport { requiredProofConstraints, type AnyProofPersistenceMapping } from \"./models/proof-model\";\nimport type { StatefulSessionMapping } from \"./models/session-model\";\nimport type { TableModel, SqlFragment } from \"./query-operations\";\nimport { storageTables, type StorageRole } from \"./storage-tables\";\n\nconst failure = (cause: unknown) => PersistenceMappingError.make({ operation: \"decode\", cause });\n\nconst decode = <S extends Schema.Codec<unknown, unknown>>(schema: S, value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError(failure));\n\nconst string = (value: unknown) => Schema.decodeUnknownSync(Schema.String)(value);\nconst tuple = Schema.encodeSync(Schema.fromJsonString(Schema.Array(Schema.String)));\nconst bindingJson = Schema.fromJsonString(ProofBinding);\nconst receiptJson = Schema.fromJsonString(ProofRequestReceipt);\n\nconst ProofRecord = Schema.Struct({\n moduleId: Schema.String,\n purpose: ProofPurpose,\n proofId: ProofId,\n requestId: ProofRequestId,\n fingerprint: TokenDigest,\n deliveryId: ProofDeliveryId,\n binding: ProofBinding,\n verifier: Schema.Struct({ keyId: Schema.String, digest: TokenDigest }),\n issuedAtMillis: Schema.Int,\n expiresAtMillis: Schema.Int,\n version: ProofVersion,\n});\n\nconst ProofContinuation = Schema.Struct({\n moduleId: Schema.String,\n purpose: ProofPurpose,\n continuationId: ProofContinuationId,\n digest: TokenDigest,\n proofId: ProofId,\n seriesKey: Schema.String,\n binding: ProofBinding,\n expiresAtMillis: Schema.Int,\n version: ProofVersion,\n});\n\n/** Derive shared row mappings from a managed or custom storage layout.\n * Acquire Effect Crypto once; the returned allocators retain that implementation.\n * Each factory requires its role tables to exist. Adapter authors supply typed\n * table handles and dialect-specific clocks/commit predicates, and may refine\n * authority policy for explicit services. This does not alter composed defaults.\n */\nexport const makeMappings = Effect.fnUntraced(function* (input: MappingInput) {\n const crypto = yield* Crypto.Crypto;\n\n const allocate = randomId.pipe(\n Effect.provideService(Crypto.Crypto, crypto),\n Effect.mapError(failure),\n );\n\n const table = (role: StorageRole) => {\n const found = input.tables[role];\n\n if (found === undefined) throw failure(`Missing ${role} mapping`);\n\n return found;\n };\n\n const mapped = (role: StorageRole) => ({\n table: table(role),\n ...Object.fromEntries(Object.keys(storageTables[role].columns).map((key) => [key, key])),\n });\n\n const { subjects: s, encodeInstant: instant, decodeInstant: readInstant } = input;\n const subjectId = { toNative: s.toNative, toSubject: s.toSubject, equals: Object.is };\n\n const subject = {\n table: s.table,\n id: s.id,\n status: s.status,\n securityRevision: s.securityRevision,\n isActiveStatus: (value: unknown) => Object.is(value, s.activeValue),\n d1ActiveStatusValue: s.activeValue,\n decodeRequirement: s.requirements,\n decodeActionRequirement: s.actionRequirements,\n nextSecurityRevision: () => allocate.pipe(Effect.map(SecurityRevision.make)),\n };\n\n const authorityCredential = () => ({\n ...mapped(\"credentials\"),\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n revision: \"revision\",\n status: \"active\",\n isActiveStatus: (value: unknown) => value === true,\n encodeInsert: (row: object) => ({ ...row, active: true }),\n encodeRevision: (revision: SecurityRevision) => ({ revision }),\n });\n\n const authority = () => ({ subjectId, subject, credential: authorityCredential() });\n\n const proofs = (): AnyProofPersistenceMapping<SqlFragment> => ({\n constraints: requiredProofConstraints,\n encodeInstant: instant,\n decodeInstant: readInstant,\n allocateVersion: allocate.pipe(Effect.map(ProofVersion.make)),\n isRequestConflict: () => false,\n isSeriesConflict: () => false,\n isCommandConflict: () => false,\n scopeKeys: ({ binding }) => ({\n series: tuple([\n binding.identifier.namespace,\n binding.identifier.value,\n binding._tag === \"Identifier\" ? \"anonymous\" : binding.revision.subjectId,\n ]),\n identifier: tuple([binding.identifier.namespace, binding.identifier.value]),\n subject: binding._tag === \"Identifier\" ? \"anonymous\" : binding.revision.subjectId,\n }),\n authority: {\n ...authority(),\n identifier: {\n table: table(\"identifiers\"),\n namespace: \"namespace\",\n value: \"value\",\n isCurrent: (request, rows) =>\n request.binding._tag === \"Identifier\"\n ? rows.length === 0\n : request.binding._tag === \"IdentifierChange\"\n ? rows.length === 0 ||\n (rows.length === 1 &&\n rows.every(\n (row) =>\n Object.is(row.subjectId, request.nativeSubjectId) &&\n row.active === true &&\n row.verifiedAt === null,\n ))\n : rows.length === 1 &&\n rows.every(\n (row) => Object.is(row.subjectId, request.nativeSubjectId) && row.active === true,\n ),\n },\n },\n request: {\n ...mapped(\"proofRequests\"),\n moduleId: \"moduleId\",\n requestId: \"requestId\",\n fingerprint: \"fingerprint\",\n proofId: \"proofId\",\n purpose: \"purpose\",\n keyId: \"keyId\",\n createdAt: \"createdAt\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: ({ record, retentionUntilMillis }) => ({\n moduleId: record.moduleId,\n requestId: record.requestId,\n fingerprint: record.fingerprint,\n proofId: record.proofId,\n purpose: record.purpose,\n keyId: record.verifier.keyId,\n createdAt: instant(record.issuedAtMillis),\n retentionUntil: instant(retentionUntilMillis),\n receipt: Schema.encodeSync(receiptJson)({\n requestId: record.requestId,\n reference: {\n proofId: record.proofId,\n purpose: record.purpose,\n keyId: record.verifier.keyId,\n },\n }),\n }),\n decodeReceipt: (row) => decode(receiptJson, row.receipt),\n },\n series: {\n ...mapped(\"proofSeries\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n scopeKey: \"scopeKey\",\n activeProofId: \"activeProofId\",\n lastIssueAt: \"lastIssueAt\",\n version: \"version\",\n encodeInsert: (row) => ({ ...row, activeProofId: null, lastIssueAt: null }),\n },\n generation: {\n ...mapped(\"proofGenerations\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n proofId: \"proofId\",\n requestId: \"requestId\",\n seriesKey: \"seriesKey\",\n deliveryId: \"deliveryId\",\n binding: \"binding\",\n verifierKeyId: \"verifierKeyId\",\n verifierDigest: \"verifierDigest\",\n issuedAt: \"issuedAt\",\n expiresAt: \"expiresAt\",\n version: \"version\",\n state: \"state\",\n sendCount: \"sendCount\",\n deliveryState: \"deliveryState\",\n claimVersion: \"claimVersion\",\n claimDeadline: \"claimDeadline\",\n retryAt: \"retryAt\",\n deliveryRetryMillis: \"deliveryRetryMillis\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: ({\n record,\n seriesKey,\n retentionUntilMillis,\n state,\n deliveryState,\n policy,\n }) => ({\n moduleId: record.moduleId,\n purpose: record.purpose,\n proofId: record.proofId,\n requestId: record.requestId,\n seriesKey,\n deliveryId: record.deliveryId,\n binding: Schema.encodeSync(bindingJson)(record.binding),\n verifierKeyId: record.verifier.keyId,\n verifierDigest: record.verifier.digest,\n issuedAt: instant(record.issuedAtMillis),\n expiresAt: instant(record.expiresAtMillis),\n version: record.version,\n state,\n sendCount: 0,\n deliveryState,\n claimVersion: null,\n claimDeadline: null,\n retryAt: null,\n deliveryRetryMillis: policy.deliveryRetryMillis,\n retentionUntil: instant(retentionUntilMillis),\n fingerprint: record.fingerprint,\n }),\n decodeBinding: (row) => decode(bindingJson, row.binding),\n decodeRecord: (row) =>\n Effect.gen(function* () {\n return yield* decode(ProofRecord, {\n moduleId: row.moduleId,\n purpose: row.purpose,\n proofId: row.proofId,\n requestId: row.requestId,\n fingerprint: row.fingerprint,\n deliveryId: row.deliveryId,\n binding: yield* decode(bindingJson, row.binding),\n verifier: { keyId: row.verifierKeyId, digest: row.verifierDigest },\n issuedAtMillis: yield* readInstant(row.issuedAt),\n expiresAtMillis: yield* readInstant(row.expiresAt),\n version: row.version,\n });\n }),\n },\n continuation: {\n ...mapped(\"proofContinuations\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n continuationId: \"continuationId\",\n digest: \"digest\",\n proofId: \"proofId\",\n seriesKey: \"seriesKey\",\n binding: \"binding\",\n expiresAt: \"expiresAt\",\n consumed: \"consumed\",\n version: \"version\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (record) => ({\n ...record,\n binding: Schema.encodeSync(bindingJson)(record.binding),\n expiresAt: instant(record.expiresAtMillis),\n consumed: false,\n retentionUntil: instant(record.retentionUntilMillis),\n }),\n decode: (row) =>\n Effect.gen(function* () {\n return yield* decode(ProofContinuation, {\n ...row,\n binding: yield* decode(bindingJson, row.binding),\n expiresAtMillis: yield* readInstant(row.expiresAt),\n });\n }),\n },\n rateScope: {\n ...mapped(\"proofScopes\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n action: \"action\",\n scopeKind: \"scopeKind\",\n scopeKey: \"scopeKey\",\n encodeInsert: (row) => ({ ...row }),\n },\n abuseEvent: {\n ...mapped(\"proofAbuse\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n action: \"action\",\n scopeKind: \"scopeKind\",\n scopeKey: \"scopeKey\",\n commandId: \"commandId\",\n occurredAt: \"occurredAt\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({\n ...row,\n occurredAt: instant(row.occurredAtMillis),\n retentionUntil: instant(row.retentionUntilMillis),\n }),\n },\n failureEvent: {\n ...mapped(\"proofFailures\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n seriesKey: \"seriesKey\",\n commandId: \"commandId\",\n occurredAt: \"occurredAt\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({\n ...row,\n occurredAt: instant(row.occurredAtMillis),\n retentionUntil: instant(row.retentionUntilMillis),\n }),\n },\n command: {\n ...mapped(\"proofCommands\"),\n moduleId: \"moduleId\",\n commandId: \"commandId\",\n kind: \"kind\",\n decision: \"decision\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({ ...row, retentionUntil: instant(row.retentionUntilMillis) }),\n },\n });\n\n const passwords = (): AnyPasswordPersistenceMapping<SqlFragment> => {\n const verifier = (replacement: PasswordReplacement) => ({\n verifier: Redacted.value(replacement.verifier),\n normalization: replacement.normalization,\n });\n\n return {\n subjectId,\n subject,\n authorityCredential: authorityCredential(),\n constraints: requiredPasswordConstraints,\n isCommandConflict: () => false,\n isRateScopeConflict: () => false,\n scopeKeys: ({ moduleId, action, identifier, subjectId }) => ({\n action: tuple([moduleId, action]),\n identifier: tuple([identifier.namespace, identifier.value]),\n ...(subjectId === undefined ? {} : { subject: subjectId }),\n }),\n encodeInstant: instant,\n decodeInstant: readInstant,\n allocateAttemptId: allocate.pipe(Effect.map(PasswordAttemptId.make)),\n allocateCredentialId: allocate,\n allocateRevision: allocate.pipe(Effect.map(SecurityRevision.make)),\n commandRetentionMillis: 86_400_000,\n sessionInvalidation: \"same-authority-immediate\",\n identifier: {\n table: table(\"identifiers\"),\n namespace: \"namespace\",\n value: \"value\",\n subjectId: \"subjectId\",\n verifiedAt: \"verifiedAt\",\n bindingRevision: \"revision\",\n isCurrent: (row) => row.active === true,\n encodeInitialInsert: (identifier, subjectId, revision) => ({\n ...identifier,\n subjectId,\n revision,\n verifiedAt: null,\n active: true,\n }),\n },\n credential: {\n ...mapped(\"passwords\"),\n moduleId: \"moduleId\",\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n credentialRevision: \"credentialRevision\",\n verifierVersion: \"verifierVersion\",\n verifier: \"verifier\",\n normalization: \"normalization\",\n encodeInsert: ({ replacement, ...row }) => ({ ...row, ...verifier(replacement) }),\n encodeVerifier: (hash, verifierVersion) => ({\n verifier: Redacted.value(hash),\n verifierVersion,\n }),\n encodeReplacement: ({ replacement, ...row }) => ({ ...row, ...verifier(replacement) }),\n decode: ({ moduleId, subject: row, identifier, credential }) =>\n Effect.gen(function* () {\n const id = yield* s.toSubject(row[s.id]);\n const hash = yield* decode(EncodedPasswordHash, credential.verifier);\n\n return yield* decode(PasswordCredentialSnapshot, {\n moduleId,\n revision: {\n subjectId: id,\n securityRevision: row[s.securityRevision],\n credentials: [\n {\n credentialId: credential.credentialId,\n revision: credential.credentialRevision,\n },\n ],\n },\n credentialId: credential.credentialId,\n credentialRevision: credential.credentialRevision,\n verifierVersion: credential.verifierVersion,\n verifier: hash,\n normalization: credential.normalization,\n identifier: yield* decode(LoginIdentifier, {\n namespace: identifier.namespace,\n value: identifier.value,\n }),\n identifierBindingRevision: identifier.revision,\n ...(identifier.verifiedAt === null\n ? {}\n : { identifierVerifiedAtMillis: yield* readInstant(identifier.verifiedAt) }),\n });\n }),\n },\n attempt: {\n ...mapped(\"passwordAttempts\"),\n moduleId: \"moduleId\",\n action: \"action\",\n attemptId: \"attemptId\",\n identifierNamespace: \"identifierNamespace\",\n identifierValue: \"identifierValue\",\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n securityRevision: \"securityRevision\",\n credentialRevision: \"credentialRevision\",\n verifierVersion: \"verifierVersion\",\n identifierBindingRevision: \"identifierBindingRevision\",\n admittedAt: \"admittedAt\",\n deadline: \"deadline\",\n retentionUntil: \"retentionUntil\",\n state: \"state\",\n encodeInsert: (row, { nativeSubjectId, state }) => ({\n moduleId: row.moduleId,\n action: row.action,\n attemptId: row.attemptId,\n identifierNamespace: row.identifier.namespace,\n identifierValue: row.identifier.value,\n subjectId: nativeSubjectId ?? null,\n credentialId: row.credentialId ?? null,\n securityRevision: row.securityRevision ?? null,\n credentialRevision: row.credentialRevision ?? null,\n verifierVersion: row.verifierVersion ?? null,\n identifierBindingRevision: row.identifierBindingRevision ?? null,\n admittedAt: instant(row.admittedAtMillis),\n deadline: instant(row.deadlineMillis),\n retentionUntil: instant(row.retentionUntilMillis),\n state,\n }),\n },\n rateScope: {\n ...mapped(\"passwordScopes\"),\n moduleId: \"moduleId\",\n action: \"action\",\n scopeKind: \"scopeKind\",\n scopeKey: \"scopeKey\",\n encodeInsert: (row) => ({ ...row }),\n },\n charge: {\n ...mapped(\"passwordCharges\"),\n moduleId: \"moduleId\",\n action: \"action\",\n scopeKind: \"scopeKind\",\n scopeKey: \"scopeKey\",\n attemptId: \"attemptId\",\n occurredAt: \"occurredAt\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({\n ...row,\n occurredAt: instant(row.occurredAtMillis),\n retentionUntil: instant(row.retentionUntilMillis),\n }),\n },\n command: {\n ...mapped(\"passwordCommands\"),\n moduleId: \"moduleId\",\n commandId: \"commandId\",\n action: \"action\",\n bindingDigest: \"bindingDigest\",\n decision: \"decision\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({ ...row, retentionUntil: instant(row.retentionUntilMillis) }),\n },\n };\n };\n\n const emails = (): AnyEmailAddressMapping<SqlFragment> => ({\n subjectId,\n subject,\n constraints: requiredEmailAddressConstraints,\n addressCardinality: \"single\",\n changeDisposition: \"retire-source\",\n encodeInstant: instant,\n decodeInstant: readInstant,\n allocateCredentialId: allocate,\n allocateRevision: allocate.pipe(Effect.map(SecurityRevision.make)),\n commandRetentionMillis: 86_400_000,\n sessionInvalidation: \"same-authority-immediate\",\n isCommandConflict: () => false,\n isIdentifierConflict: () => false,\n isCredentialConflict: () => false,\n authorityCredential: {\n ...authorityCredential(),\n encodeActivation: (revision) => ({ revision, active: true }),\n encodeRetirement: (revision) => ({ revision, active: false }),\n },\n identifier: {\n table: table(\"identifiers\"),\n namespace: \"namespace\",\n value: \"value\",\n subjectId: \"subjectId\",\n verifiedAt: \"verifiedAt\",\n bindingRevision: \"revision\",\n isCurrent: (row) => row.active === true && row.verifiedAt !== null,\n isMutableTarget: (row) => row.active === true && row.verifiedAt === null,\n encodeVerifiedInsert: ({ identifier, subjectId, verifiedAtMillis, bindingRevision }) => ({\n ...identifier,\n subjectId,\n verifiedAt: instant(verifiedAtMillis),\n revision: bindingRevision,\n active: true,\n }),\n encodeVerification: ({ verifiedAtMillis, bindingRevision }) => ({\n verifiedAt: instant(verifiedAtMillis),\n revision: bindingRevision,\n active: true,\n }),\n encodeRetirement: ({ bindingRevision }) => ({ revision: bindingRevision, active: false }),\n },\n credential: {\n table: table(\"emailCredentials\"),\n moduleId: \"moduleId\",\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n identifierNamespace: \"identifierNamespace\",\n identifierValue: \"identifierValue\",\n credentialRevision: \"credentialRevision\",\n status: \"active\",\n isActiveStatus: (value) => value === true,\n encodeVerifiedInsert: ({ identifier, ...row }) => ({\n ...row,\n identifierNamespace: identifier.namespace,\n identifierValue: identifier.value,\n active: true,\n }),\n encodeActivation: ({ identifier, credentialRevision }) => ({\n identifierNamespace: identifier.namespace,\n identifierValue: identifier.value,\n credentialRevision,\n active: true,\n }),\n encodeRetirement: ({ credentialRevision }) => ({ credentialRevision, active: false }),\n decode: ({ moduleId, subject: row, identifier, credential }) =>\n Effect.gen(function* () {\n return yield* decode(EmailCredentialSnapshot, {\n moduleId,\n identifier: { namespace: identifier.namespace, value: identifier.value },\n identifierRevision: identifier.revision,\n verifiedAtMillis: yield* readInstant(identifier.verifiedAt),\n credentialId: credential.credentialId,\n credentialRevision: credential.credentialRevision,\n revision: {\n subjectId: yield* s.toSubject(row[s.id]),\n securityRevision: row[s.securityRevision],\n credentials: [\n { credentialId: credential.credentialId, revision: credential.credentialRevision },\n ],\n },\n });\n }),\n },\n command: {\n table: table(\"emailCommands\"),\n moduleId: \"moduleId\",\n commandId: \"commandId\",\n action: \"action\",\n bindingDigest: \"bindingDigest\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: ({ retentionUntilMillis, ...row }) => ({\n ...row,\n retentionUntil: instant(retentionUntilMillis),\n }),\n },\n });\n\n const sessions = <C extends Schema.Codec<unknown, unknown, never, never>>(\n claims: C,\n ): StatefulSessionMapping<\n C[\"Type\"],\n TableModel,\n TableModel,\n TableModel,\n TableModel,\n TableModel,\n unknown,\n string\n > => {\n const record = Schema.fromJsonString(\n Schema.Struct({\n ...SessionMetadata.fields,\n claims: Schema.Unknown,\n digest: TokenDigest,\n version: SecurityRevision,\n provenance: SessionAuthenticationProvenance,\n credentialVersion: SessionCredentialVersion,\n }),\n );\n\n const encodeRow = (value: StatefulSessionRecord<C[\"Type\"]>) => ({\n digest: value.digest,\n version: value.version,\n securityRevision: value.securityRevision,\n issuedAt: instant(DateTime.toEpochMillis(value.issuedAt)),\n expiresAt: instant(DateTime.toEpochMillis(value.expiresAt)),\n absoluteExpiresAt: instant(DateTime.toEpochMillis(value.absoluteExpiresAt)),\n record: Schema.encodeSync(record)({\n ...value,\n claims: Schema.encodeSync(claims)(value.claims),\n }),\n });\n\n return {\n ...authority(),\n isConstraintConflict: () => false,\n constraints: { sessionDigest: \"unique(session.digest)\", flowId: \"unique(flow.flowId)\" },\n sessionId: {\n toNative: (id) => Effect.succeed(id),\n toSession: (id) => decode(SessionId, id),\n equals: Object.is,\n },\n flow: {\n table: table(\"sessionFlows\"),\n flowId: \"flowId\",\n subjectId: \"subjectId\",\n state: \"state\",\n pendingDigest: \"pendingDigest\",\n dedupUntil: \"dedupUntil\",\n pendingStateValue: \"pending\",\n establishedStateValue: \"established\",\n encodeInstant: (date) => instant(DateTime.toEpochMillis(date)),\n decodeInstant: (value) => readInstant(value).pipe(Effect.map(DateTime.makeUnsafe)),\n encodePendingInsert: (row) => ({\n flowId: row.evidence.flowId,\n subjectId: row.subjectId,\n state: \"pending\",\n pendingDigest: row.pendingDigest,\n dedupUntil: instant(DateTime.toEpochMillis(row.dedupUntil)),\n }),\n encodeEstablishedInsert: (row) => ({\n flowId: row.evidence.flowId,\n subjectId: row.subjectId,\n state: \"established\",\n pendingDigest: null,\n dedupUntil: instant(DateTime.toEpochMillis(row.dedupUntil)),\n }),\n },\n session: {\n table: table(\"sessions\"),\n sessionId: \"sessionId\",\n subjectId: \"subjectId\",\n digest: \"digest\",\n version: \"version\",\n securityRevision: \"securityRevision\",\n issuedAt: \"issuedAt\",\n expiresAt: \"expiresAt\",\n absoluteExpiresAt: \"absoluteExpiresAt\",\n encodeInstant: (date) => instant(DateTime.toEpochMillis(date)),\n allocateId: allocate,\n allocateVersion: allocate.pipe(Effect.map(SecurityRevision.make)),\n encodeInsert: (value, ids) => ({ ...encodeRow(value), ...ids }),\n encodeRotation: encodeRow,\n decode: (row) =>\n Effect.gen(function* () {\n const saved = yield* decode(record, row.record);\n const decodedClaims = yield* decode(claims, saved.claims);\n\n return { ...saved, claims: decodedClaims };\n }),\n },\n };\n };\n\n return { table, authority, proofs, passwords, emails, sessions, string };\n});\n"],"mappings":";;;;;;;;;;;;;;AA0CA,MAAM,WAAW,UAAmB,wBAAwB,KAAK;CAAE,WAAW;CAAU;AAAM,CAAC;AAE/F,MAAM,UAAoD,QAAW,UACnE,OAAO,oBAAoB,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,CAAC;AAEzE,MAAM,UAAU,UAAmB,OAAO,kBAAkB,OAAO,MAAM,CAAC,CAAC,KAAK;AAChF,MAAM,QAAQ,OAAO,WAAW,OAAO,eAAe,OAAO,MAAM,OAAO,MAAM,CAAC,CAAC;AAClF,MAAM,cAAc,OAAO,eAAe,YAAY;AACtD,MAAM,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O;EAAE;EAAO;EAAW;EAAQ;EAAW;EAAQ;EAAU;CAAO;AACzE,CAAC"}
|
|
1
|
+
{"version":3,"file":"storage-mapping.mjs","names":["ProofRecord"],"sources":["../../src/internal/storage-mapping.ts"],"sourcesContent":["import { EmailCredentialSnapshot } from \"@yielded/auth/Email\";\nimport { LoginIdentifier } from \"@yielded/auth/Identity\";\nimport {\n PasswordAttemptId,\n PasswordCredentialSnapshot,\n EncodedPasswordHash,\n type PasswordReplacement,\n} from \"@yielded/auth/Password\";\nimport {\n ProofBinding,\n ProofContinuationId,\n ProofDeliveryId,\n ProofId,\n ProofPurpose,\n ProofRequestId,\n ProofRequestReceipt,\n ProofVersion,\n} from \"@yielded/auth/Proofs\";\nimport { TokenDigest } from \"@yielded/auth/Schema\";\nimport {\n SecurityRevision,\n SessionId,\n SessionMetadata,\n SessionAuthenticationProvenance,\n SessionCredentialVersion,\n type StatefulSessionRecord,\n} from \"@yielded/auth/Sessions\";\nimport { Crypto, DateTime, Effect, Redacted, Schema } from \"effect\";\n\nimport type { MappingInput } from \"./configuration\";\nimport { randomId } from \"./crypto\";\nimport { PersistenceMappingError } from \"./mapping-error\";\nimport { requiredEmailAddressConstraints, type AnyEmailAddressMapping } from \"./models/email-model\";\nimport {\n requiredPasswordConstraints,\n type AnyPasswordPersistenceMapping,\n} from \"./models/password-model\";\nimport { requiredProofConstraints, type AnyProofPersistenceMapping } from \"./models/proof-model\";\nimport type { StatefulSessionMapping } from \"./models/session-model\";\nimport type { TableModel, SqlFragment } from \"./query-operations\";\nimport { storageTables, type StorageRole } from \"./storage-tables\";\n\nconst failure = (cause: unknown) => PersistenceMappingError.make({ operation: \"decode\", cause });\n\nconst decode = <S extends Schema.Codec<unknown, unknown>>(schema: S, value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(Effect.mapError(failure));\n\nconst string = (value: unknown) => Schema.decodeUnknownSync(Schema.String)(value);\nconst tuple = Schema.encodeSync(Schema.fromJsonString(Schema.Array(Schema.String)));\nconst bindingJson = Schema.fromJsonString(ProofBinding);\nconst receiptJson = Schema.fromJsonString(ProofRequestReceipt);\n\nconst ProofRecord = Schema.Struct({\n moduleId: Schema.String,\n purpose: ProofPurpose,\n proofId: ProofId,\n requestId: ProofRequestId,\n fingerprint: TokenDigest,\n deliveryId: ProofDeliveryId,\n binding: ProofBinding,\n verifier: Schema.Struct({ keyId: Schema.String, digest: TokenDigest }),\n issuedAtMillis: Schema.Int,\n expiresAtMillis: Schema.Int,\n version: ProofVersion,\n});\n\nconst ProofContinuation = Schema.Struct({\n moduleId: Schema.String,\n purpose: ProofPurpose,\n continuationId: ProofContinuationId,\n digest: TokenDigest,\n proofId: ProofId,\n seriesKey: Schema.String,\n binding: ProofBinding,\n expiresAtMillis: Schema.Int,\n version: ProofVersion,\n});\n\n/** Derive shared row mappings from a managed or custom storage layout.\n * Acquire Effect Crypto once; the returned allocators retain that implementation.\n * Each factory requires its role tables to exist. Adapter authors supply typed\n * table handles and dialect-specific clocks/commit predicates, and may refine\n * authority policy for explicit services. This does not alter composed defaults.\n */\nexport const makeMappings = Effect.fnUntraced(function* (input: MappingInput) {\n const crypto = yield* Crypto.Crypto;\n\n const allocate = randomId.pipe(\n Effect.provideService(Crypto.Crypto, crypto),\n Effect.mapError(failure),\n );\n\n const table = (role: StorageRole) => {\n const found = input.tables[role];\n\n if (found === undefined) throw failure(`Missing ${role} mapping`);\n\n return found;\n };\n\n const mapped = (role: StorageRole) => ({\n table: table(role),\n ...Object.fromEntries(Object.keys(storageTables[role].columns).map((key) => [key, key])),\n });\n\n const { subjects: s, encodeInstant: instant, decodeInstant: readInstant } = input;\n const subjectId = { toNative: s.toNative, toSubject: s.toSubject, equals: Object.is };\n\n const subject = {\n table: s.table,\n id: s.id,\n status: s.status,\n securityRevision: s.securityRevision,\n isActiveStatus: (value: unknown) => Object.is(value, s.activeValue),\n d1ActiveStatusValue: s.activeValue,\n decodeRequirement: s.requirements,\n decodeActionRequirement: s.actionRequirements,\n nextSecurityRevision: () => allocate.pipe(Effect.map(SecurityRevision.make)),\n };\n\n const authorityCredential = () => ({\n ...mapped(\"credentials\"),\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n revision: \"revision\",\n status: \"active\",\n isActiveStatus: (value: unknown) => value === true,\n encodeInsert: (row: object) => ({ ...row, active: true }),\n encodeRevision: (revision: SecurityRevision) => ({ revision }),\n });\n\n const authority = () => ({ subjectId, subject, credential: authorityCredential() });\n\n const proofs = (): AnyProofPersistenceMapping<SqlFragment> => ({\n constraints: requiredProofConstraints,\n encodeInstant: instant,\n decodeInstant: readInstant,\n allocateVersion: allocate.pipe(Effect.map(ProofVersion.make)),\n isRequestConflict: () => false,\n isSeriesConflict: () => false,\n isCommandConflict: () => false,\n scopeKeys: ({ binding }) => ({\n series: tuple([\n binding.identifier.namespace,\n binding.identifier.value,\n binding._tag === \"Identifier\" ? \"anonymous\" : binding.revision.subjectId,\n ]),\n identifier: tuple([binding.identifier.namespace, binding.identifier.value]),\n subject: binding._tag === \"Identifier\" ? \"anonymous\" : binding.revision.subjectId,\n }),\n authority: {\n ...authority(),\n identifier: {\n table: table(\"identifiers\"),\n namespace: \"namespace\",\n value: \"value\",\n isCurrent: (request, rows) =>\n request.binding._tag === \"Identifier\"\n ? rows.length === 0\n : request.binding._tag === \"IdentifierChange\"\n ? rows.length === 0 ||\n (rows.length === 1 &&\n rows.every(\n (row) =>\n Object.is(row.subjectId, request.nativeSubjectId) &&\n row.active === true &&\n row.verifiedAt === null,\n ))\n : rows.length === 1 &&\n rows.every(\n (row) => Object.is(row.subjectId, request.nativeSubjectId) && row.active === true,\n ),\n },\n },\n request: {\n ...mapped(\"proofRequests\"),\n moduleId: \"moduleId\",\n requestId: \"requestId\",\n fingerprint: \"fingerprint\",\n proofId: \"proofId\",\n purpose: \"purpose\",\n keyId: \"keyId\",\n createdAt: \"createdAt\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: ({ record, retentionUntilMillis }) => ({\n moduleId: record.moduleId,\n requestId: record.requestId,\n fingerprint: record.fingerprint,\n proofId: record.proofId,\n purpose: record.purpose,\n keyId: record.verifier.keyId,\n createdAt: instant(record.issuedAtMillis),\n retentionUntil: instant(retentionUntilMillis),\n receipt: Schema.encodeSync(receiptJson)({\n requestId: record.requestId,\n reference: {\n proofId: record.proofId,\n purpose: record.purpose,\n keyId: record.verifier.keyId,\n },\n }),\n }),\n decodeReceipt: (row) => decode(receiptJson, row.receipt),\n },\n series: {\n ...mapped(\"proofSeries\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n scopeKey: \"scopeKey\",\n activeProofId: \"activeProofId\",\n lastIssueAt: \"lastIssueAt\",\n version: \"version\",\n encodeInsert: (row) => ({ ...row, activeProofId: null, lastIssueAt: null }),\n },\n generation: {\n ...mapped(\"proofGenerations\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n proofId: \"proofId\",\n requestId: \"requestId\",\n seriesKey: \"seriesKey\",\n deliveryId: \"deliveryId\",\n binding: \"binding\",\n verifierKeyId: \"verifierKeyId\",\n verifierDigest: \"verifierDigest\",\n issuedAt: \"issuedAt\",\n expiresAt: \"expiresAt\",\n version: \"version\",\n state: \"state\",\n sendCount: \"sendCount\",\n deliveryState: \"deliveryState\",\n claimVersion: \"claimVersion\",\n claimDeadline: \"claimDeadline\",\n retryAt: \"retryAt\",\n deliveryRetryMillis: \"deliveryRetryMillis\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: ({\n record,\n seriesKey,\n retentionUntilMillis,\n state,\n deliveryState,\n policy,\n }) => ({\n moduleId: record.moduleId,\n purpose: record.purpose,\n proofId: record.proofId,\n requestId: record.requestId,\n seriesKey,\n deliveryId: record.deliveryId,\n binding: Schema.encodeSync(bindingJson)(record.binding),\n verifierKeyId: record.verifier.keyId,\n verifierDigest: record.verifier.digest,\n issuedAt: instant(record.issuedAtMillis),\n expiresAt: instant(record.expiresAtMillis),\n version: record.version,\n state,\n sendCount: 0,\n deliveryState,\n claimVersion: null,\n claimDeadline: null,\n retryAt: null,\n deliveryRetryMillis: policy.deliveryRetryMillis,\n retentionUntil: instant(retentionUntilMillis),\n fingerprint: record.fingerprint,\n }),\n decodeBinding: (row) => decode(bindingJson, row.binding),\n decodeRecord: (row) =>\n Effect.gen(function* () {\n return yield* decode(ProofRecord, {\n moduleId: row.moduleId,\n purpose: row.purpose,\n proofId: row.proofId,\n requestId: row.requestId,\n fingerprint: row.fingerprint,\n deliveryId: row.deliveryId,\n binding: yield* decode(bindingJson, row.binding),\n verifier: { keyId: row.verifierKeyId, digest: row.verifierDigest },\n issuedAtMillis: yield* readInstant(row.issuedAt),\n expiresAtMillis: yield* readInstant(row.expiresAt),\n version: row.version,\n });\n }),\n },\n continuation: {\n ...mapped(\"proofContinuations\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n continuationId: \"continuationId\",\n digest: \"digest\",\n proofId: \"proofId\",\n seriesKey: \"seriesKey\",\n binding: \"binding\",\n expiresAt: \"expiresAt\",\n consumed: \"consumed\",\n version: \"version\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (record) => ({\n ...record,\n binding: Schema.encodeSync(bindingJson)(record.binding),\n expiresAt: instant(record.expiresAtMillis),\n consumed: false,\n retentionUntil: instant(record.retentionUntilMillis),\n }),\n decode: (row) =>\n Effect.gen(function* () {\n return yield* decode(ProofContinuation, {\n ...row,\n binding: yield* decode(bindingJson, row.binding),\n expiresAtMillis: yield* readInstant(row.expiresAt),\n });\n }),\n },\n rateScope: {\n ...mapped(\"proofScopes\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n action: \"action\",\n scopeKind: \"scopeKind\",\n scopeKey: \"scopeKey\",\n encodeInsert: (row) => ({ ...row }),\n },\n abuseEvent: {\n ...mapped(\"proofAbuse\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n action: \"action\",\n scopeKind: \"scopeKind\",\n scopeKey: \"scopeKey\",\n commandId: \"commandId\",\n occurredAt: \"occurredAt\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({\n ...row,\n occurredAt: instant(row.occurredAtMillis),\n retentionUntil: instant(row.retentionUntilMillis),\n }),\n },\n failureEvent: {\n ...mapped(\"proofFailures\"),\n moduleId: \"moduleId\",\n purpose: \"purpose\",\n seriesKey: \"seriesKey\",\n commandId: \"commandId\",\n occurredAt: \"occurredAt\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({\n ...row,\n occurredAt: instant(row.occurredAtMillis),\n retentionUntil: instant(row.retentionUntilMillis),\n }),\n },\n command: {\n ...mapped(\"proofCommands\"),\n moduleId: \"moduleId\",\n commandId: \"commandId\",\n kind: \"kind\",\n decision: \"decision\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({ ...row, retentionUntil: instant(row.retentionUntilMillis) }),\n },\n });\n\n const passwords = (): AnyPasswordPersistenceMapping<SqlFragment> => {\n const verifier = (replacement: PasswordReplacement) => ({\n verifier: Redacted.value(replacement.verifier),\n normalization: replacement.normalization,\n });\n\n return {\n subjectId,\n subject,\n authorityCredential: authorityCredential(),\n constraints: requiredPasswordConstraints,\n isCommandConflict: () => false,\n encodeInstant: instant,\n decodeInstant: readInstant,\n allocateAttemptId: allocate.pipe(Effect.map(PasswordAttemptId.make)),\n allocateCredentialId: allocate,\n allocateRevision: allocate.pipe(Effect.map(SecurityRevision.make)),\n commandRetentionMillis: 86_400_000,\n sessionInvalidation: \"same-authority-immediate\",\n identifier: {\n table: table(\"identifiers\"),\n namespace: \"namespace\",\n value: \"value\",\n subjectId: \"subjectId\",\n verifiedAt: \"verifiedAt\",\n bindingRevision: \"revision\",\n isCurrent: (row) => row.active === true,\n encodeInitialInsert: (identifier, subjectId, revision) => ({\n ...identifier,\n subjectId,\n revision,\n verifiedAt: null,\n active: true,\n }),\n },\n credential: {\n ...mapped(\"passwords\"),\n moduleId: \"moduleId\",\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n credentialRevision: \"credentialRevision\",\n verifierVersion: \"verifierVersion\",\n verifier: \"verifier\",\n normalization: \"normalization\",\n encodeInsert: ({ replacement, ...row }) => ({ ...row, ...verifier(replacement) }),\n encodeVerifier: (hash, verifierVersion) => ({\n verifier: Redacted.value(hash),\n verifierVersion,\n }),\n encodeReplacement: ({ replacement, ...row }) => ({ ...row, ...verifier(replacement) }),\n decode: ({ moduleId, subject: row, identifier, credential }) =>\n Effect.gen(function* () {\n const id = yield* s.toSubject(row[s.id]);\n const hash = yield* decode(EncodedPasswordHash, credential.verifier);\n\n return yield* decode(PasswordCredentialSnapshot, {\n moduleId,\n revision: {\n subjectId: id,\n securityRevision: row[s.securityRevision],\n credentials: [\n {\n credentialId: credential.credentialId,\n revision: credential.credentialRevision,\n },\n ],\n },\n credentialId: credential.credentialId,\n credentialRevision: credential.credentialRevision,\n verifierVersion: credential.verifierVersion,\n verifier: hash,\n normalization: credential.normalization,\n identifier: yield* decode(LoginIdentifier, {\n namespace: identifier.namespace,\n value: identifier.value,\n }),\n identifierBindingRevision: identifier.revision,\n ...(identifier.verifiedAt === null\n ? {}\n : { identifierVerifiedAtMillis: yield* readInstant(identifier.verifiedAt) }),\n });\n }),\n },\n attempt: {\n ...mapped(\"passwordAttempts\"),\n moduleId: \"moduleId\",\n action: \"action\",\n attemptId: \"attemptId\",\n identifierNamespace: \"identifierNamespace\",\n identifierValue: \"identifierValue\",\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n securityRevision: \"securityRevision\",\n credentialRevision: \"credentialRevision\",\n verifierVersion: \"verifierVersion\",\n identifierBindingRevision: \"identifierBindingRevision\",\n admittedAt: \"admittedAt\",\n deadline: \"deadline\",\n retentionUntil: \"retentionUntil\",\n state: \"state\",\n encodeInsert: (row, { nativeSubjectId, state }) => ({\n moduleId: row.moduleId,\n action: row.action,\n attemptId: row.attemptId,\n identifierNamespace: row.identifier.namespace,\n identifierValue: row.identifier.value,\n subjectId: nativeSubjectId ?? null,\n credentialId: row.credentialId ?? null,\n securityRevision: row.securityRevision ?? null,\n credentialRevision: row.credentialRevision ?? null,\n verifierVersion: row.verifierVersion ?? null,\n identifierBindingRevision: row.identifierBindingRevision ?? null,\n admittedAt: instant(row.admittedAtMillis),\n deadline: instant(row.deadlineMillis),\n retentionUntil: instant(row.retentionUntilMillis),\n state,\n }),\n },\n command: {\n ...mapped(\"passwordCommands\"),\n moduleId: \"moduleId\",\n commandId: \"commandId\",\n action: \"action\",\n bindingDigest: \"bindingDigest\",\n decision: \"decision\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: (row) => ({ ...row, retentionUntil: instant(row.retentionUntilMillis) }),\n },\n };\n };\n\n const emails = (): AnyEmailAddressMapping<SqlFragment> => ({\n subjectId,\n subject,\n constraints: requiredEmailAddressConstraints,\n addressCardinality: \"single\",\n changeDisposition: \"retire-source\",\n encodeInstant: instant,\n decodeInstant: readInstant,\n allocateCredentialId: allocate,\n allocateRevision: allocate.pipe(Effect.map(SecurityRevision.make)),\n commandRetentionMillis: 86_400_000,\n sessionInvalidation: \"same-authority-immediate\",\n isCommandConflict: () => false,\n isIdentifierConflict: () => false,\n isCredentialConflict: () => false,\n authorityCredential: {\n ...authorityCredential(),\n encodeActivation: (revision) => ({ revision, active: true }),\n encodeRetirement: (revision) => ({ revision, active: false }),\n },\n identifier: {\n table: table(\"identifiers\"),\n namespace: \"namespace\",\n value: \"value\",\n subjectId: \"subjectId\",\n verifiedAt: \"verifiedAt\",\n bindingRevision: \"revision\",\n isCurrent: (row) => row.active === true && row.verifiedAt !== null,\n isMutableTarget: (row) => row.active === true && row.verifiedAt === null,\n encodeVerifiedInsert: ({ identifier, subjectId, verifiedAtMillis, bindingRevision }) => ({\n ...identifier,\n subjectId,\n verifiedAt: instant(verifiedAtMillis),\n revision: bindingRevision,\n active: true,\n }),\n encodeVerification: ({ verifiedAtMillis, bindingRevision }) => ({\n verifiedAt: instant(verifiedAtMillis),\n revision: bindingRevision,\n active: true,\n }),\n encodeRetirement: ({ bindingRevision }) => ({ revision: bindingRevision, active: false }),\n },\n credential: {\n table: table(\"emailCredentials\"),\n moduleId: \"moduleId\",\n subjectId: \"subjectId\",\n credentialId: \"credentialId\",\n identifierNamespace: \"identifierNamespace\",\n identifierValue: \"identifierValue\",\n credentialRevision: \"credentialRevision\",\n status: \"active\",\n isActiveStatus: (value) => value === true,\n encodeVerifiedInsert: ({ identifier, ...row }) => ({\n ...row,\n identifierNamespace: identifier.namespace,\n identifierValue: identifier.value,\n active: true,\n }),\n encodeActivation: ({ identifier, credentialRevision }) => ({\n identifierNamespace: identifier.namespace,\n identifierValue: identifier.value,\n credentialRevision,\n active: true,\n }),\n encodeRetirement: ({ credentialRevision }) => ({ credentialRevision, active: false }),\n decode: ({ moduleId, subject: row, identifier, credential }) =>\n Effect.gen(function* () {\n return yield* decode(EmailCredentialSnapshot, {\n moduleId,\n identifier: { namespace: identifier.namespace, value: identifier.value },\n identifierRevision: identifier.revision,\n verifiedAtMillis: yield* readInstant(identifier.verifiedAt),\n credentialId: credential.credentialId,\n credentialRevision: credential.credentialRevision,\n revision: {\n subjectId: yield* s.toSubject(row[s.id]),\n securityRevision: row[s.securityRevision],\n credentials: [\n { credentialId: credential.credentialId, revision: credential.credentialRevision },\n ],\n },\n });\n }),\n },\n command: {\n table: table(\"emailCommands\"),\n moduleId: \"moduleId\",\n commandId: \"commandId\",\n action: \"action\",\n bindingDigest: \"bindingDigest\",\n retentionUntil: \"retentionUntil\",\n encodeInsert: ({ retentionUntilMillis, ...row }) => ({\n ...row,\n retentionUntil: instant(retentionUntilMillis),\n }),\n },\n });\n\n const sessions = <C extends Schema.Codec<unknown, unknown, never, never>>(\n claims: C,\n ): StatefulSessionMapping<\n C[\"Type\"],\n TableModel,\n TableModel,\n TableModel,\n TableModel,\n TableModel,\n unknown,\n string\n > => {\n const record = Schema.fromJsonString(\n Schema.Struct({\n ...SessionMetadata.fields,\n claims: Schema.Unknown,\n digest: TokenDigest,\n version: SecurityRevision,\n provenance: SessionAuthenticationProvenance,\n credentialVersion: SessionCredentialVersion,\n }),\n );\n\n const encodeRow = (value: StatefulSessionRecord<C[\"Type\"]>) => ({\n digest: value.digest,\n version: value.version,\n securityRevision: value.securityRevision,\n issuedAt: instant(DateTime.toEpochMillis(value.issuedAt)),\n expiresAt: instant(DateTime.toEpochMillis(value.expiresAt)),\n absoluteExpiresAt: instant(DateTime.toEpochMillis(value.absoluteExpiresAt)),\n record: Schema.encodeSync(record)({\n ...value,\n claims: Schema.encodeSync(claims)(value.claims),\n }),\n });\n\n return {\n ...authority(),\n isConstraintConflict: () => false,\n constraints: { sessionDigest: \"unique(session.digest)\", flowId: \"unique(flow.flowId)\" },\n sessionId: {\n toNative: (id) => Effect.succeed(id),\n toSession: (id) => decode(SessionId, id),\n equals: Object.is,\n },\n flow: {\n table: table(\"sessionFlows\"),\n flowId: \"flowId\",\n subjectId: \"subjectId\",\n state: \"state\",\n pendingDigest: \"pendingDigest\",\n dedupUntil: \"dedupUntil\",\n pendingStateValue: \"pending\",\n establishedStateValue: \"established\",\n encodeInstant: (date) => instant(DateTime.toEpochMillis(date)),\n decodeInstant: (value) => readInstant(value).pipe(Effect.map(DateTime.makeUnsafe)),\n encodePendingInsert: (row) => ({\n flowId: row.evidence.flowId,\n subjectId: row.subjectId,\n state: \"pending\",\n pendingDigest: row.pendingDigest,\n dedupUntil: instant(DateTime.toEpochMillis(row.dedupUntil)),\n }),\n encodeEstablishedInsert: (row) => ({\n flowId: row.evidence.flowId,\n subjectId: row.subjectId,\n state: \"established\",\n pendingDigest: null,\n dedupUntil: instant(DateTime.toEpochMillis(row.dedupUntil)),\n }),\n },\n session: {\n table: table(\"sessions\"),\n sessionId: \"sessionId\",\n subjectId: \"subjectId\",\n digest: \"digest\",\n version: \"version\",\n securityRevision: \"securityRevision\",\n issuedAt: \"issuedAt\",\n expiresAt: \"expiresAt\",\n absoluteExpiresAt: \"absoluteExpiresAt\",\n encodeInstant: (date) => instant(DateTime.toEpochMillis(date)),\n allocateId: allocate,\n allocateVersion: allocate.pipe(Effect.map(SecurityRevision.make)),\n encodeInsert: (value, ids) => ({ ...encodeRow(value), ...ids }),\n encodeRotation: encodeRow,\n decode: (row) =>\n Effect.gen(function* () {\n const saved = yield* decode(record, row.record);\n const decodedClaims = yield* decode(claims, saved.claims);\n\n return { ...saved, claims: decodedClaims };\n }),\n },\n };\n };\n\n return { table, authority, proofs, passwords, emails, sessions, string };\n});\n"],"mappings":";;;;;;;;;;;;;;AA0CA,MAAM,WAAW,UAAmB,wBAAwB,KAAK;CAAE,WAAW;CAAU;AAAM,CAAC;AAE/F,MAAM,UAAoD,QAAW,UACnE,OAAO,oBAAoB,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,OAAO,SAAS,OAAO,CAAC;AAEzE,MAAM,UAAU,UAAmB,OAAO,kBAAkB,OAAO,MAAM,CAAC,CAAC,KAAK;AAChF,MAAM,QAAQ,OAAO,WAAW,OAAO,eAAe,OAAO,MAAM,OAAO,MAAM,CAAC,CAAC;AAClF,MAAM,cAAc,OAAO,eAAe,YAAY;AACtD,MAAM,cAAc,OAAO,eAAe,mBAAmB;AAE7D,MAAMA,gBAAc,OAAO,OAAO;CAChC,UAAU,OAAO;CACjB,SAAS;CACT,SAAS;CACT,WAAW;CACX,aAAa;CACb,YAAY;CACZ,SAAS;CACT,UAAU,OAAO,OAAO;EAAE,OAAO,OAAO;EAAQ,QAAQ;CAAY,CAAC;CACrE,gBAAgB,OAAO;CACvB,iBAAiB,OAAO;CACxB,SAAS;AACX,CAAC;AAED,MAAM,oBAAoB,OAAO,OAAO;CACtC,UAAU,OAAO;CACjB,SAAS;CACT,gBAAgB;CAChB,QAAQ;CACR,SAAS;CACT,WAAW,OAAO;CAClB,SAAS;CACT,iBAAiB,OAAO;CACxB,SAAS;AACX,CAAC;;;;;;;AAQD,MAAa,eAAe,OAAO,WAAW,WAAW,OAAqB;CAC5E,MAAM,SAAS,OAAO,OAAO;CAE7B,MAAM,WAAW,SAAS,KACxB,OAAO,eAAe,OAAO,QAAQ,MAAM,GAC3C,OAAO,SAAS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AAc;IAC3C,CAAC;GACL;EACF;CACF;CAEA,OAAO;EAAE;EAAO;EAAW;EAAQ;EAAW;EAAQ;EAAU;CAAO;AACzE,CAAC"}
|
|
@@ -155,49 +155,6 @@ export declare const storageTables: {
|
|
|
155
155
|
};
|
|
156
156
|
unique: readonly (readonly ("action" | "admittedAt" | "attemptId" | "credentialId" | "credentialRevision" | "deadline" | "identifierBindingRevision" | "identifierNamespace" | "identifierValue" | "moduleId" | "retentionUntil" | "securityRevision" | "state" | "subjectId" | "verifierVersion")[])[];
|
|
157
157
|
};
|
|
158
|
-
readonly passwordScopes: {
|
|
159
|
-
columns: {
|
|
160
|
-
moduleId: {
|
|
161
|
-
type: "text";
|
|
162
|
-
};
|
|
163
|
-
action: {
|
|
164
|
-
type: "text";
|
|
165
|
-
};
|
|
166
|
-
scopeKind: {
|
|
167
|
-
type: "text";
|
|
168
|
-
};
|
|
169
|
-
scopeKey: {
|
|
170
|
-
type: "text";
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
unique: readonly (readonly ("action" | "moduleId" | "scopeKey" | "scopeKind")[])[];
|
|
174
|
-
};
|
|
175
|
-
readonly passwordCharges: {
|
|
176
|
-
columns: {
|
|
177
|
-
moduleId: {
|
|
178
|
-
type: "text";
|
|
179
|
-
};
|
|
180
|
-
action: {
|
|
181
|
-
type: "text";
|
|
182
|
-
};
|
|
183
|
-
scopeKind: {
|
|
184
|
-
type: "text";
|
|
185
|
-
};
|
|
186
|
-
scopeKey: {
|
|
187
|
-
type: "text";
|
|
188
|
-
};
|
|
189
|
-
attemptId: {
|
|
190
|
-
type: "text";
|
|
191
|
-
};
|
|
192
|
-
occurredAt: {
|
|
193
|
-
type: "integer";
|
|
194
|
-
};
|
|
195
|
-
retentionUntil: {
|
|
196
|
-
type: "integer";
|
|
197
|
-
};
|
|
198
|
-
};
|
|
199
|
-
unique: readonly (readonly ("action" | "attemptId" | "moduleId" | "occurredAt" | "retentionUntil" | "scopeKey" | "scopeKind")[])[];
|
|
200
|
-
};
|
|
201
158
|
readonly passwordCommands: {
|
|
202
159
|
columns: {
|
|
203
160
|
moduleId: {
|
|
@@ -77,32 +77,6 @@ const storageTables = {
|
|
|
77
77
|
retentionUntil: integer,
|
|
78
78
|
state: text
|
|
79
79
|
}, [["moduleId", "attemptId"]]),
|
|
80
|
-
passwordScopes: spec({
|
|
81
|
-
moduleId: text,
|
|
82
|
-
action: text,
|
|
83
|
-
scopeKind: text,
|
|
84
|
-
scopeKey: text
|
|
85
|
-
}, [[
|
|
86
|
-
"moduleId",
|
|
87
|
-
"action",
|
|
88
|
-
"scopeKind",
|
|
89
|
-
"scopeKey"
|
|
90
|
-
]]),
|
|
91
|
-
passwordCharges: spec({
|
|
92
|
-
moduleId: text,
|
|
93
|
-
action: text,
|
|
94
|
-
scopeKind: text,
|
|
95
|
-
scopeKey: text,
|
|
96
|
-
attemptId: text,
|
|
97
|
-
occurredAt: integer,
|
|
98
|
-
retentionUntil: integer
|
|
99
|
-
}, [[
|
|
100
|
-
"moduleId",
|
|
101
|
-
"action",
|
|
102
|
-
"scopeKind",
|
|
103
|
-
"scopeKey",
|
|
104
|
-
"attemptId"
|
|
105
|
-
]]),
|
|
106
80
|
passwordCommands: spec({
|
|
107
81
|
moduleId: text,
|
|
108
82
|
commandId: text,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-tables.mjs","names":[],"sources":["../../src/internal/storage-tables.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nexport const StorageColumn = Schema.Struct({\n name: Schema.NonEmptyString,\n type: Schema.Literals([\"text\", \"integer\", \"boolean\"]),\n nullable: Schema.optionalKey(Schema.Boolean),\n});\n\nexport const StorageTable = Schema.Struct({\n name: Schema.NonEmptyString,\n schema: Schema.optionalKey(Schema.NonEmptyString),\n columns: Schema.Record(Schema.String, StorageColumn),\n unique: Schema.Array(Schema.Array(Schema.String)),\n});\n\nexport type StorageTable = typeof StorageTable.Type;\n\nconst text = { type: \"text\" as const };\nconst integer = { type: \"integer\" as const };\nconst boolean = { type: \"boolean\" as const };\nconst optionalText = { ...text, nullable: true };\nconst optionalInteger = { ...integer, nullable: true };\n\nconst spec = <C extends Readonly<Record<string, Omit<typeof StorageColumn.Type, \"name\">>>>(\n columns: C,\n unique: ReadonlyArray<ReadonlyArray<Extract<keyof C, string>>>,\n) => ({ columns, unique });\n\n/** Logical roles are independent of table names and migration ownership. */\nexport const storageTables = {\n subjects: spec({ id: text, active: boolean, securityRevision: text }, [[\"id\"]]),\n identifiers: spec(\n {\n namespace: text,\n value: text,\n subjectId: text,\n revision: text,\n verifiedAt: optionalInteger,\n active: boolean,\n },\n [[\"namespace\", \"value\"]],\n ),\n credentials: spec({ credentialId: text, subjectId: text, revision: text, active: boolean }, [\n [\"credentialId\"],\n ]),\n passwords: spec(\n {\n moduleId: text,\n subjectId: text,\n credentialId: text,\n credentialRevision: text,\n verifierVersion: text,\n verifier: text,\n normalization: text,\n },\n [\n [\"moduleId\", \"subjectId\"],\n [\"moduleId\", \"credentialId\"],\n ],\n ),\n passwordAttempts: spec(\n {\n moduleId: text,\n action: text,\n attemptId: text,\n identifierNamespace: text,\n identifierValue: text,\n subjectId: optionalText,\n credentialId: optionalText,\n securityRevision: optionalText,\n credentialRevision: optionalText,\n verifierVersion: optionalText,\n identifierBindingRevision: optionalText,\n admittedAt: integer,\n deadline: integer,\n retentionUntil: integer,\n state: text,\n },\n [[\"moduleId\", \"attemptId\"]],\n ),\n passwordScopes: spec({ moduleId: text, action: text, scopeKind: text, scopeKey: text }, [\n [\"moduleId\", \"action\", \"scopeKind\", \"scopeKey\"],\n ]),\n passwordCharges: spec(\n {\n moduleId: text,\n action: text,\n scopeKind: text,\n scopeKey: text,\n attemptId: text,\n occurredAt: integer,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"action\", \"scopeKind\", \"scopeKey\", \"attemptId\"]],\n ),\n passwordCommands: spec(\n {\n moduleId: text,\n commandId: text,\n action: text,\n bindingDigest: text,\n decision: text,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"commandId\"]],\n ),\n passwordRegistrations: spec({ moduleId: text, requestId: text }, [[\"moduleId\", \"requestId\"]]),\n emailCredentials: spec(\n {\n moduleId: text,\n subjectId: text,\n credentialId: text,\n identifierNamespace: text,\n identifierValue: text,\n credentialRevision: text,\n active: boolean,\n },\n [\n [\"moduleId\", \"credentialId\"],\n [\"moduleId\", \"identifierNamespace\", \"identifierValue\"],\n ],\n ),\n emailCommands: spec(\n { moduleId: text, commandId: text, action: text, bindingDigest: text, retentionUntil: integer },\n [[\"moduleId\", \"commandId\"]],\n ),\n phoneState: spec({ scope: text, state: text, version: text }, [[\"scope\"]]),\n passkeyCredentials: spec(\n {\n credentialId: text,\n subjectId: text,\n rpId: text,\n protocolCredentialId: text,\n credentialKey: text,\n handleKey: text,\n userHandle: text,\n publicKey: text,\n algorithm: integer,\n profile: text,\n credentialRevision: text,\n active: boolean,\n primarySignIn: boolean,\n enrollmentUserVerified: boolean,\n backupEligible: boolean,\n backupState: boolean,\n counter: integer,\n maximumCounter: integer,\n name: text,\n createdAt: integer,\n lastUsedAt: optionalInteger,\n },\n [[\"credentialId\"], [\"credentialKey\"]],\n ),\n passkeyOwnership: spec(\n {\n credentialKey: text,\n rpId: text,\n protocolCredentialId: text,\n subjectId: optionalText,\n credentialId: optionalText,\n state: text,\n version: text,\n reservationId: optionalText,\n },\n [[\"credentialKey\"]],\n ),\n passkeyHandles: spec(\n {\n handleKey: text,\n rpId: text,\n userHandle: text,\n subjectId: optionalText,\n state: text,\n version: text,\n reservationId: optionalText,\n },\n [[\"handleKey\"], [\"rpId\", \"subjectId\"]],\n ),\n passkeyModules: spec(\n {\n moduleId: text,\n active: boolean,\n policyRevision: text,\n policy: text,\n },\n [[\"moduleId\"]],\n ),\n passkeyFlows: spec(\n {\n moduleId: text,\n flowId: text,\n commandId: text,\n purpose: text,\n state: text,\n version: text,\n generation: integer,\n snapshot: text,\n policySnapshot: text,\n requestBindingVerifier: text,\n requestBindingExpiresAt: integer,\n issuedAt: integer,\n expiresAt: integer,\n retentionUntil: integer,\n claimId: optionalText,\n claimedAt: optionalInteger,\n claimExpiresAt: optionalInteger,\n credentialSnapshot: optionalText,\n subjectScope: optionalText,\n targetScope: optionalText,\n },\n [\n [\"moduleId\", \"flowId\"],\n [\"moduleId\", \"commandId\"],\n ],\n ),\n passkeyAdmissions: spec(\n {\n authorityScope: text,\n moduleId: text,\n version: text,\n ownerMarker: text,\n admittedAt: optionalInteger,\n },\n [[\"authorityScope\", \"moduleId\"]],\n ),\n passkeyCharges: spec(\n {\n moduleId: text,\n flowId: text,\n purpose: text,\n kind: text,\n scope: text,\n originalWindowMillis: integer,\n admittedAt: optionalInteger,\n retainUntil: optionalInteger,\n version: text,\n ownerMarker: text,\n },\n [[\"moduleId\", \"flowId\", \"kind\"]],\n ),\n passkeyCommands: spec(\n {\n moduleId: text,\n commandId: text,\n subjectId: text,\n credentialId: text,\n intent: text,\n decision: text,\n retentionUntil: integer,\n version: text,\n },\n [[\"moduleId\", \"commandId\"]],\n ),\n proofRequests: spec(\n {\n moduleId: text,\n requestId: text,\n fingerprint: text,\n proofId: text,\n purpose: text,\n keyId: text,\n createdAt: integer,\n retentionUntil: integer,\n receipt: text,\n },\n [[\"moduleId\", \"requestId\"]],\n ),\n proofSeries: spec(\n {\n moduleId: text,\n purpose: text,\n scopeKey: text,\n activeProofId: optionalText,\n lastIssueAt: optionalInteger,\n version: text,\n },\n [[\"moduleId\", \"purpose\", \"scopeKey\"]],\n ),\n proofGenerations: spec(\n {\n moduleId: text,\n purpose: text,\n proofId: text,\n requestId: text,\n seriesKey: text,\n deliveryId: text,\n binding: text,\n verifierKeyId: text,\n verifierDigest: text,\n issuedAt: integer,\n expiresAt: integer,\n version: text,\n state: text,\n sendCount: integer,\n deliveryState: text,\n claimVersion: optionalText,\n claimDeadline: optionalInteger,\n retryAt: optionalInteger,\n deliveryRetryMillis: integer,\n retentionUntil: integer,\n fingerprint: text,\n },\n [\n [\"moduleId\", \"proofId\"],\n [\"moduleId\", \"deliveryId\"],\n ],\n ),\n proofContinuations: spec(\n {\n moduleId: text,\n purpose: text,\n continuationId: text,\n digest: text,\n proofId: text,\n seriesKey: text,\n binding: text,\n expiresAt: integer,\n consumed: boolean,\n version: text,\n retentionUntil: integer,\n },\n [\n [\"moduleId\", \"continuationId\"],\n [\"moduleId\", \"digest\"],\n ],\n ),\n proofScopes: spec(\n { moduleId: text, purpose: text, action: text, scopeKind: text, scopeKey: text },\n [[\"moduleId\", \"purpose\", \"action\", \"scopeKind\", \"scopeKey\"]],\n ),\n proofAbuse: spec(\n {\n moduleId: text,\n purpose: text,\n action: text,\n scopeKind: text,\n scopeKey: text,\n commandId: text,\n occurredAt: integer,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"action\", \"scopeKind\", \"scopeKey\", \"commandId\"]],\n ),\n proofFailures: spec(\n {\n moduleId: text,\n purpose: text,\n seriesKey: text,\n commandId: text,\n occurredAt: integer,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"seriesKey\", \"commandId\"]],\n ),\n proofCommands: spec(\n { moduleId: text, commandId: text, kind: text, decision: text, retentionUntil: integer },\n [[\"moduleId\", \"commandId\"]],\n ),\n sessions: spec(\n {\n sessionId: text,\n subjectId: text,\n digest: text,\n version: text,\n securityRevision: text,\n issuedAt: integer,\n expiresAt: integer,\n absoluteExpiresAt: integer,\n record: text,\n },\n [[\"sessionId\"], [\"digest\"]],\n ),\n sessionFlows: spec(\n {\n flowId: text,\n subjectId: text,\n state: text,\n pendingDigest: optionalText,\n dedupUntil: integer,\n },\n [[\"flowId\"]],\n ),\n} as const;\n\nexport type StorageRole = keyof typeof storageTables;\n\nexport const tableDefinition = (\n role: StorageRole,\n name: string,\n subjectType: \"text\" | \"integer\" = \"text\",\n): StorageTable => {\n const table = storageTables[role];\n\n return {\n name,\n columns: Object.fromEntries(\n Object.entries(table.columns).map(([key, column]) => [\n key,\n {\n ...column,\n name: key.replace(/[A-Z]/g, (letter) => \"_\" + letter.toLowerCase()),\n ...(key === \"subjectId\" ? { type: subjectType } : {}),\n },\n ]),\n ),\n unique: table.unique,\n };\n};\n"],"mappings":";;AAEA,MAAa,gBAAgB,OAAO,OAAO;CACzC,MAAM,OAAO;CACb,MAAM,OAAO,SAAS;EAAC;EAAQ;EAAW;CAAS,CAAC;CACpD,UAAU,OAAO,YAAY,OAAO,OAAO;AAC7C,CAAC;AAED,MAAa,eAAe,OAAO,OAAO;CACxC,MAAM,OAAO;CACb,QAAQ,OAAO,YAAY,OAAO,cAAc;CAChD,SAAS,OAAO,OAAO,OAAO,QAAQ,aAAa;CACnD,QAAQ,OAAO,MAAM,OAAO,MAAM,OAAO,MAAM,CAAC;AAClD,CAAC;AAID,MAAM,OAAO,EAAE,MAAM,OAAgB;AACrC,MAAM,UAAU,EAAE,MAAM,UAAmB;AAC3C,MAAM,UAAU,EAAE,MAAM,UAAmB;AAC3C,MAAM,eAAe;CAAE,GAAG;CAAM,UAAU;AAAK;AAC/C,MAAM,kBAAkB;CAAE,GAAG;CAAS,UAAU;AAAK;AAErD,MAAM,QACJ,SACA,YACI;CAAE;CAAS;AAAO;;AAGxB,MAAa,gBAAgB;CAC3B,UAAU,KAAK;EAAE,IAAI;EAAM,QAAQ;EAAS,kBAAkB;CAAK,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;CAC9E,aAAa,KACX;EACE,WAAW;EACX,OAAO;EACP,WAAW;EACX,UAAU;EACV,YAAY;EACZ,QAAQ;CACV,GACA,CAAC,CAAC,aAAa,OAAO,CAAC,CACzB;CACA,aAAa,KAAK;EAAE,cAAc;EAAM,WAAW;EAAM,UAAU;EAAM,QAAQ;CAAQ,GAAG,CAC1F,CAAC,cAAc,CACjB,CAAC;CACD,WAAW,KACT;EACE,UAAU;EACV,WAAW;EACX,cAAc;EACd,oBAAoB;EACpB,iBAAiB;EACjB,UAAU;EACV,eAAe;CACjB,GACA,CACE,CAAC,YAAY,WAAW,GACxB,CAAC,YAAY,cAAc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;EAAU;EAAa;CAAU,CAAC,CAC7D;CACA,YAAY,KACV;EACE,UAAU;EACV,SAAS;EACT,QAAQ;EACR,WAAW;EACX,UAAU;EACV,WAAW;EACX,YAAY;EACZ,gBAAgB;CAClB,GACA,CAAC;EAAC;EAAY;EAAU;EAAa;EAAY;CAAW,CAAC,CAC/D;CACA,eAAe,KACb;EACE,UAAU;EACV,SAAS;EACT,WAAW;EACX,WAAW;EACX,YAAY;EACZ,gBAAgB;CAClB,GACA,CAAC;EAAC;EAAY;EAAa;CAAW,CAAC,CACzC;CACA,eAAe,KACb;EAAE,UAAU;EAAM,WAAW;EAAM,MAAM;EAAM,UAAU;EAAM,gBAAgB;CAAQ,GACvF,CAAC,CAAC,YAAY,WAAW,CAAC,CAC5B;CACA,UAAU,KACR;EACE,WAAW;EACX,WAAW;EACX,QAAQ;EACR,SAAS;EACT,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,mBAAmB;EACnB,QAAQ;CACV,GACA,CAAC,CAAC,WAAW,GAAG,CAAC,QAAQ,CAAC,CAC5B;CACA,cAAc,KACZ;EACE,QAAQ;EACR,WAAW;EACX,OAAO;EACP,eAAe;EACf,YAAY;CACd,GACA,CAAC,CAAC,QAAQ,CAAC,CACb;AACF;AAIA,MAAa,mBACX,MACA,MACA,cAAkC,WACjB;CACjB,MAAM,QAAQ,cAAc;CAE5B,OAAO;EACL;EACA,SAAS,OAAO,YACd,OAAO,QAAQ,MAAM,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,YAAY,CACnD,KACA;GACE,GAAG;GACH,MAAM,IAAI,QAAQ,WAAW,WAAW,MAAM,OAAO,YAAY,CAAC;GAClE,GAAI,QAAQ,cAAc,EAAE,MAAM,YAAY,IAAI,CAAC;EACrD,CACF,CAAC,CACH;EACA,QAAQ,MAAM;CAChB;AACF"}
|
|
1
|
+
{"version":3,"file":"storage-tables.mjs","names":[],"sources":["../../src/internal/storage-tables.ts"],"sourcesContent":["import { Schema } from \"effect\";\n\nexport const StorageColumn = Schema.Struct({\n name: Schema.NonEmptyString,\n type: Schema.Literals([\"text\", \"integer\", \"boolean\"]),\n nullable: Schema.optionalKey(Schema.Boolean),\n});\n\nexport const StorageTable = Schema.Struct({\n name: Schema.NonEmptyString,\n schema: Schema.optionalKey(Schema.NonEmptyString),\n columns: Schema.Record(Schema.String, StorageColumn),\n unique: Schema.Array(Schema.Array(Schema.String)),\n});\n\nexport type StorageTable = typeof StorageTable.Type;\n\nconst text = { type: \"text\" as const };\nconst integer = { type: \"integer\" as const };\nconst boolean = { type: \"boolean\" as const };\nconst optionalText = { ...text, nullable: true };\nconst optionalInteger = { ...integer, nullable: true };\n\nconst spec = <C extends Readonly<Record<string, Omit<typeof StorageColumn.Type, \"name\">>>>(\n columns: C,\n unique: ReadonlyArray<ReadonlyArray<Extract<keyof C, string>>>,\n) => ({ columns, unique });\n\n/** Logical roles are independent of table names and migration ownership. */\nexport const storageTables = {\n subjects: spec({ id: text, active: boolean, securityRevision: text }, [[\"id\"]]),\n identifiers: spec(\n {\n namespace: text,\n value: text,\n subjectId: text,\n revision: text,\n verifiedAt: optionalInteger,\n active: boolean,\n },\n [[\"namespace\", \"value\"]],\n ),\n credentials: spec({ credentialId: text, subjectId: text, revision: text, active: boolean }, [\n [\"credentialId\"],\n ]),\n passwords: spec(\n {\n moduleId: text,\n subjectId: text,\n credentialId: text,\n credentialRevision: text,\n verifierVersion: text,\n verifier: text,\n normalization: text,\n },\n [\n [\"moduleId\", \"subjectId\"],\n [\"moduleId\", \"credentialId\"],\n ],\n ),\n passwordAttempts: spec(\n {\n moduleId: text,\n action: text,\n attemptId: text,\n identifierNamespace: text,\n identifierValue: text,\n subjectId: optionalText,\n credentialId: optionalText,\n securityRevision: optionalText,\n credentialRevision: optionalText,\n verifierVersion: optionalText,\n identifierBindingRevision: optionalText,\n admittedAt: integer,\n deadline: integer,\n retentionUntil: integer,\n state: text,\n },\n [[\"moduleId\", \"attemptId\"]],\n ),\n passwordCommands: spec(\n {\n moduleId: text,\n commandId: text,\n action: text,\n bindingDigest: text,\n decision: text,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"commandId\"]],\n ),\n passwordRegistrations: spec({ moduleId: text, requestId: text }, [[\"moduleId\", \"requestId\"]]),\n emailCredentials: spec(\n {\n moduleId: text,\n subjectId: text,\n credentialId: text,\n identifierNamespace: text,\n identifierValue: text,\n credentialRevision: text,\n active: boolean,\n },\n [\n [\"moduleId\", \"credentialId\"],\n [\"moduleId\", \"identifierNamespace\", \"identifierValue\"],\n ],\n ),\n emailCommands: spec(\n { moduleId: text, commandId: text, action: text, bindingDigest: text, retentionUntil: integer },\n [[\"moduleId\", \"commandId\"]],\n ),\n phoneState: spec({ scope: text, state: text, version: text }, [[\"scope\"]]),\n passkeyCredentials: spec(\n {\n credentialId: text,\n subjectId: text,\n rpId: text,\n protocolCredentialId: text,\n credentialKey: text,\n handleKey: text,\n userHandle: text,\n publicKey: text,\n algorithm: integer,\n profile: text,\n credentialRevision: text,\n active: boolean,\n primarySignIn: boolean,\n enrollmentUserVerified: boolean,\n backupEligible: boolean,\n backupState: boolean,\n counter: integer,\n maximumCounter: integer,\n name: text,\n createdAt: integer,\n lastUsedAt: optionalInteger,\n },\n [[\"credentialId\"], [\"credentialKey\"]],\n ),\n passkeyOwnership: spec(\n {\n credentialKey: text,\n rpId: text,\n protocolCredentialId: text,\n subjectId: optionalText,\n credentialId: optionalText,\n state: text,\n version: text,\n reservationId: optionalText,\n },\n [[\"credentialKey\"]],\n ),\n passkeyHandles: spec(\n {\n handleKey: text,\n rpId: text,\n userHandle: text,\n subjectId: optionalText,\n state: text,\n version: text,\n reservationId: optionalText,\n },\n [[\"handleKey\"], [\"rpId\", \"subjectId\"]],\n ),\n passkeyModules: spec(\n {\n moduleId: text,\n active: boolean,\n policyRevision: text,\n policy: text,\n },\n [[\"moduleId\"]],\n ),\n passkeyFlows: spec(\n {\n moduleId: text,\n flowId: text,\n commandId: text,\n purpose: text,\n state: text,\n version: text,\n generation: integer,\n snapshot: text,\n policySnapshot: text,\n requestBindingVerifier: text,\n requestBindingExpiresAt: integer,\n issuedAt: integer,\n expiresAt: integer,\n retentionUntil: integer,\n claimId: optionalText,\n claimedAt: optionalInteger,\n claimExpiresAt: optionalInteger,\n credentialSnapshot: optionalText,\n subjectScope: optionalText,\n targetScope: optionalText,\n },\n [\n [\"moduleId\", \"flowId\"],\n [\"moduleId\", \"commandId\"],\n ],\n ),\n passkeyAdmissions: spec(\n {\n authorityScope: text,\n moduleId: text,\n version: text,\n ownerMarker: text,\n admittedAt: optionalInteger,\n },\n [[\"authorityScope\", \"moduleId\"]],\n ),\n passkeyCharges: spec(\n {\n moduleId: text,\n flowId: text,\n purpose: text,\n kind: text,\n scope: text,\n originalWindowMillis: integer,\n admittedAt: optionalInteger,\n retainUntil: optionalInteger,\n version: text,\n ownerMarker: text,\n },\n [[\"moduleId\", \"flowId\", \"kind\"]],\n ),\n passkeyCommands: spec(\n {\n moduleId: text,\n commandId: text,\n subjectId: text,\n credentialId: text,\n intent: text,\n decision: text,\n retentionUntil: integer,\n version: text,\n },\n [[\"moduleId\", \"commandId\"]],\n ),\n proofRequests: spec(\n {\n moduleId: text,\n requestId: text,\n fingerprint: text,\n proofId: text,\n purpose: text,\n keyId: text,\n createdAt: integer,\n retentionUntil: integer,\n receipt: text,\n },\n [[\"moduleId\", \"requestId\"]],\n ),\n proofSeries: spec(\n {\n moduleId: text,\n purpose: text,\n scopeKey: text,\n activeProofId: optionalText,\n lastIssueAt: optionalInteger,\n version: text,\n },\n [[\"moduleId\", \"purpose\", \"scopeKey\"]],\n ),\n proofGenerations: spec(\n {\n moduleId: text,\n purpose: text,\n proofId: text,\n requestId: text,\n seriesKey: text,\n deliveryId: text,\n binding: text,\n verifierKeyId: text,\n verifierDigest: text,\n issuedAt: integer,\n expiresAt: integer,\n version: text,\n state: text,\n sendCount: integer,\n deliveryState: text,\n claimVersion: optionalText,\n claimDeadline: optionalInteger,\n retryAt: optionalInteger,\n deliveryRetryMillis: integer,\n retentionUntil: integer,\n fingerprint: text,\n },\n [\n [\"moduleId\", \"proofId\"],\n [\"moduleId\", \"deliveryId\"],\n ],\n ),\n proofContinuations: spec(\n {\n moduleId: text,\n purpose: text,\n continuationId: text,\n digest: text,\n proofId: text,\n seriesKey: text,\n binding: text,\n expiresAt: integer,\n consumed: boolean,\n version: text,\n retentionUntil: integer,\n },\n [\n [\"moduleId\", \"continuationId\"],\n [\"moduleId\", \"digest\"],\n ],\n ),\n proofScopes: spec(\n { moduleId: text, purpose: text, action: text, scopeKind: text, scopeKey: text },\n [[\"moduleId\", \"purpose\", \"action\", \"scopeKind\", \"scopeKey\"]],\n ),\n proofAbuse: spec(\n {\n moduleId: text,\n purpose: text,\n action: text,\n scopeKind: text,\n scopeKey: text,\n commandId: text,\n occurredAt: integer,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"action\", \"scopeKind\", \"scopeKey\", \"commandId\"]],\n ),\n proofFailures: spec(\n {\n moduleId: text,\n purpose: text,\n seriesKey: text,\n commandId: text,\n occurredAt: integer,\n retentionUntil: integer,\n },\n [[\"moduleId\", \"seriesKey\", \"commandId\"]],\n ),\n proofCommands: spec(\n { moduleId: text, commandId: text, kind: text, decision: text, retentionUntil: integer },\n [[\"moduleId\", \"commandId\"]],\n ),\n sessions: spec(\n {\n sessionId: text,\n subjectId: text,\n digest: text,\n version: text,\n securityRevision: text,\n issuedAt: integer,\n expiresAt: integer,\n absoluteExpiresAt: integer,\n record: text,\n },\n [[\"sessionId\"], [\"digest\"]],\n ),\n sessionFlows: spec(\n {\n flowId: text,\n subjectId: text,\n state: text,\n pendingDigest: optionalText,\n dedupUntil: integer,\n },\n [[\"flowId\"]],\n ),\n} as const;\n\nexport type StorageRole = keyof typeof storageTables;\n\nexport const tableDefinition = (\n role: StorageRole,\n name: string,\n subjectType: \"text\" | \"integer\" = \"text\",\n): StorageTable => {\n const table = storageTables[role];\n\n return {\n name,\n columns: Object.fromEntries(\n Object.entries(table.columns).map(([key, column]) => [\n key,\n {\n ...column,\n name: key.replace(/[A-Z]/g, (letter) => \"_\" + letter.toLowerCase()),\n ...(key === \"subjectId\" ? { type: subjectType } : {}),\n },\n ]),\n ),\n unique: table.unique,\n };\n};\n"],"mappings":";;AAEA,MAAa,gBAAgB,OAAO,OAAO;CACzC,MAAM,OAAO;CACb,MAAM,OAAO,SAAS;EAAC;EAAQ;EAAW;CAAS,CAAC;CACpD,UAAU,OAAO,YAAY,OAAO,OAAO;AAC7C,CAAC;AAED,MAAa,eAAe,OAAO,OAAO;CACxC,MAAM,OAAO;CACb,QAAQ,OAAO,YAAY,OAAO,cAAc;CAChD,SAAS,OAAO,OAAO,OAAO,QAAQ,aAAa;CACnD,QAAQ,OAAO,MAAM,OAAO,MAAM,OAAO,MAAM,CAAC;AAClD,CAAC;AAID,MAAM,OAAO,EAAE,MAAM,OAAgB;AACrC,MAAM,UAAU,EAAE,MAAM,UAAmB;AAC3C,MAAM,UAAU,EAAE,MAAM,UAAmB;AAC3C,MAAM,eAAe;CAAE,GAAG;CAAM,UAAU;AAAK;AAC/C,MAAM,kBAAkB;CAAE,GAAG;CAAS,UAAU;AAAK;AAErD,MAAM,QACJ,SACA,YACI;CAAE;CAAS;AAAO;;AAGxB,MAAa,gBAAgB;CAC3B,UAAU,KAAK;EAAE,IAAI;EAAM,QAAQ;EAAS,kBAAkB;CAAK,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;CAC9E,aAAa,KACX;EACE,WAAW;EACX,OAAO;EACP,WAAW;EACX,UAAU;EACV,YAAY;EACZ,QAAQ;CACV,GACA,CAAC,CAAC,aAAa,OAAO,CAAC,CACzB;CACA,aAAa,KAAK;EAAE,cAAc;EAAM,WAAW;EAAM,UAAU;EAAM,QAAQ;CAAQ,GAAG,CAC1F,CAAC,cAAc,CACjB,CAAC;CACD,WAAW,KACT;EACE,UAAU;EACV,WAAW;EACX,cAAc;EACd,oBAAoB;EACpB,iBAAiB;EACjB,UAAU;EACV,eAAe;CACjB,GACA,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WAAW;EACX,WAAW;EACX,YAAY;EACZ,gBAAgB;CAClB,GACA,CAAC;EAAC;EAAY;EAAa;CAAW,CAAC,CACzC;CACA,eAAe,KACb;EAAE,UAAU;EAAM,WAAW;EAAM,MAAM;EAAM,UAAU;EAAM,gBAAgB;CAAQ,GACvF,CAAC,CAAC,YAAY,WAAW,CAAC,CAC5B;CACA,UAAU,KACR;EACE,WAAW;EACX,WAAW;EACX,QAAQ;EACR,SAAS;EACT,kBAAkB;EAClB,UAAU;EACV,WAAW;EACX,mBAAmB;EACnB,QAAQ;CACV,GACA,CAAC,CAAC,WAAW,GAAG,CAAC,QAAQ,CAAC,CAC5B;CACA,cAAc,KACZ;EACE,QAAQ;EACR,WAAW;EACX,OAAO;EACP,eAAe;EACf,YAAY;CACd,GACA,CAAC,CAAC,QAAQ,CAAC,CACb;AACF;AAIA,MAAa,mBACX,MACA,MACA,cAAkC,WACjB;CACjB,MAAM,QAAQ,cAAc;CAE5B,OAAO;EACL;EACA,SAAS,OAAO,YACd,OAAO,QAAQ,MAAM,OAAO,CAAC,CAAC,KAAK,CAAC,KAAK,YAAY,CACnD,KACA;GACE,GAAG;GACH,MAAM,IAAI,QAAQ,WAAW,WAAW,MAAM,OAAO,YAAY,CAAC;GAClE,GAAI,QAAQ,cAAc,EAAE,MAAM,YAAY,IAAI,CAAC;EACrD,CACF,CAAC,CACH;EACA,QAAQ,MAAM;CAChB;AACF"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { NativeDatabase, TransactionNativeDatabase, TransactionOwner, makeTransactionKernel } from "./transaction-kernel.mjs";
|
|
2
2
|
import { Context, Crypto, Effect, PlatformError } from "effect";
|
|
3
|
+
import { Statement } from "effect/sql/Statement";
|
|
3
4
|
import { CurrentCommitJournal, HookConfigurationError, LifecycleHooks } from "@yielded/auth/Hooks";
|
|
4
5
|
import * as SqlClient$1 from "effect/sql/SqlClient";
|
|
5
|
-
import { Statement } from "effect/sql/Statement";
|
|
6
6
|
import * as SqlError$1 from "effect/sql/SqlError";
|
|
7
7
|
//#region src/internal/transaction-execution-kernel.d.ts
|
|
8
8
|
export interface TransactionTargetConfiguration<Failure> {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { QueryOperations, SqlColumn, SqlExpression, SqlFragment } from "./query-operations.mjs";
|
|
2
2
|
import { Context, Effect } from "effect";
|
|
3
|
+
import { Statement } from "effect/sql/Statement";
|
|
3
4
|
import { CommitJournal, PreparedCommit } from "@yielded/auth/Hooks";
|
|
4
5
|
import * as SqlClient$1 from "effect/sql/SqlClient";
|
|
5
|
-
import { Statement } from "effect/sql/Statement";
|
|
6
6
|
import { SqlError } from "effect/sql/SqlError";
|
|
7
7
|
//#region src/internal/transaction-kernel.d.ts
|
|
8
8
|
type Table = object;
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@yielded/auth-persistence","version":"0.1.0-beta.
|
|
1
|
+
{"name":"@yielded/auth-persistence","version":"0.1.0-beta.23","dependencies":{"@yielded/auth":"0.1.0-beta.23"},"devDependencies":{"@effect/platform-node":"4.0.0","@effect/sql-libsql":"4.0.0","@effect/sql-sqlite-node":"4.0.0","@effect/vitest":"4.0.0","@yielded/crypto":"0.1.0-beta.23","@yielded/jose":"0.1.0-beta.23","effect":"4.0.0","typescript":"7.0.2","vite-plus":"0.3.3"},"peerDependencies":{"effect":"^4.0.0"},"exports":{".":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"./Adapter":{"types":"./dist/Adapter.d.mts","default":"./dist/Adapter.mjs"}},"description":"Direct Effect SQL persistence and shared storage contracts for Yielded Auth.","homepage":"https://yielded.dev/auth/","bugs":{"url":"https://github.com/yielded-dev/auth/issues"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/yielded-dev/auth.git","directory":"packages/auth-persistence"},"files":["dist","src"],"type":"module","sideEffects":[],"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","check":"tsc --noEmit -p tsconfig.json","test":"vp test --passWithNoTests"}}
|
package/src/Adapter.ts
CHANGED
|
@@ -101,16 +101,12 @@ export {
|
|
|
101
101
|
export {
|
|
102
102
|
type PasswordAttemptAction,
|
|
103
103
|
type PasswordAttemptState,
|
|
104
|
-
type PasswordRateScopeKind,
|
|
105
|
-
type PasswordScopeKeys,
|
|
106
104
|
type PasswordSubjectTable,
|
|
107
105
|
type PasswordIdentifierTable,
|
|
108
106
|
type PasswordAuthorityCredentialTable,
|
|
109
107
|
type PasswordCredentialTable,
|
|
110
108
|
type PasswordAttemptRecord,
|
|
111
109
|
type PasswordAttemptTable,
|
|
112
|
-
type PasswordRateScopeTable,
|
|
113
|
-
type PasswordChargeTable,
|
|
114
110
|
type PasswordCommandTable,
|
|
115
111
|
type RequiredPasswordConstraints,
|
|
116
112
|
requiredPasswordConstraints,
|
|
@@ -304,3 +300,12 @@ export {
|
|
|
304
300
|
type PhysicalStorageTable,
|
|
305
301
|
type StorageValidation,
|
|
306
302
|
} from "./internal/storage-validation";
|
|
303
|
+
|
|
304
|
+
export {
|
|
305
|
+
makeNativeSqlTables,
|
|
306
|
+
nativeSqlAlias,
|
|
307
|
+
type NativeSqlTables,
|
|
308
|
+
type SqlTable,
|
|
309
|
+
} from "./internal/native-sql-table";
|
|
310
|
+
|
|
311
|
+
export { samePasswordCredentialSnapshot } from "./internal/password-attempts";
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { SubjectId } from "@yielded/auth/Schema";
|
|
2
|
+
import { AuthenticationRevision, StaleAuthentication } from "@yielded/auth/Sessions";
|
|
3
|
+
import { Effect, Schema } from "effect";
|
|
4
|
+
|
|
5
|
+
import type { SessionAuthorityTables } from "./models/session-model";
|
|
6
|
+
import { sqlMapping, type NativeSqlTables } from "./native-sql-table";
|
|
7
|
+
import type { AnyTableModel } from "./query-operations";
|
|
8
|
+
import { NativeDatabase } from "./transaction-kernel";
|
|
9
|
+
|
|
10
|
+
/** One unlocked statement reads the subject and requested credentials: a coherent
|
|
11
|
+
* preflight view, or a commit owner's view where writers are already serialized.
|
|
12
|
+
* Row-locking commit owners lock and revalidate through their ordered reads.
|
|
13
|
+
*/
|
|
14
|
+
export const makeAuthoritySnapshot = (
|
|
15
|
+
tables: NativeSqlTables,
|
|
16
|
+
mapping: SessionAuthorityTables<AnyTableModel, AnyTableModel, unknown>,
|
|
17
|
+
) =>
|
|
18
|
+
Effect.fnUntraced(function* (subjectId: SubjectId, credentialIds: ReadonlyArray<string>) {
|
|
19
|
+
const sql = (yield* NativeDatabase).$client.withoutTransforms();
|
|
20
|
+
|
|
21
|
+
if (new Set(credentialIds).size !== credentialIds.length)
|
|
22
|
+
return yield* StaleAuthentication.make({});
|
|
23
|
+
|
|
24
|
+
const { s, c } = yield* sqlMapping(() => ({
|
|
25
|
+
s: tables(mapping.subject.table).as("auth_subject"),
|
|
26
|
+
c: tables(mapping.credential.table).as("auth_credential"),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
const nativeId = yield* sqlMapping(() => mapping.subjectId.toNative(subjectId)).pipe(
|
|
30
|
+
Effect.flatten,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const requested = [...credentialIds].sort((a, b) => a.localeCompare(b));
|
|
34
|
+
|
|
35
|
+
const rows = yield* sqlMapping(
|
|
36
|
+
() => sql<Record<string, unknown>>`select ${s.fields("s_")}
|
|
37
|
+
${requested.length === 0 ? sql.literal("") : sql`, ${c.fields("c_")}`}
|
|
38
|
+
from ${s.name}
|
|
39
|
+
${
|
|
40
|
+
requested.length === 0
|
|
41
|
+
? sql.literal("")
|
|
42
|
+
: sql`inner join ${c.name} on
|
|
43
|
+
${c.column(mapping.credential.subjectId)} = ${c.value(mapping.credential.subjectId, nativeId)}
|
|
44
|
+
and ${sql.or(requested.map((id) => sql`${c.column(mapping.credential.credentialId)} = ${c.value(mapping.credential.credentialId, id)}`))}`
|
|
45
|
+
}
|
|
46
|
+
where ${s.column(mapping.subject.id)} = ${s.value(mapping.subject.id, nativeId)}`,
|
|
47
|
+
).pipe(Effect.flatten);
|
|
48
|
+
|
|
49
|
+
const first = rows[0];
|
|
50
|
+
|
|
51
|
+
if (first === undefined || rows.length !== Math.max(1, requested.length))
|
|
52
|
+
return yield* StaleAuthentication.make({});
|
|
53
|
+
|
|
54
|
+
const subject = yield* sqlMapping(() => s.decode(first, "s_"));
|
|
55
|
+
|
|
56
|
+
if (!(yield* sqlMapping(() => mapping.subject.isActiveStatus(subject[mapping.subject.status]))))
|
|
57
|
+
return yield* StaleAuthentication.make({});
|
|
58
|
+
|
|
59
|
+
const credentials = yield* sqlMapping(() =>
|
|
60
|
+
requested.length === 0 ? [] : rows.map((row) => c.decode(row, "c_")),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
if (
|
|
64
|
+
yield* sqlMapping(() =>
|
|
65
|
+
credentials.some(
|
|
66
|
+
(row) =>
|
|
67
|
+
mapping.credential.status !== undefined &&
|
|
68
|
+
mapping.credential.isActiveStatus?.(row[mapping.credential.status]) !== true,
|
|
69
|
+
),
|
|
70
|
+
)
|
|
71
|
+
)
|
|
72
|
+
return yield* StaleAuthentication.make({});
|
|
73
|
+
|
|
74
|
+
const revision = yield* Schema.decodeUnknownEffect(AuthenticationRevision)({
|
|
75
|
+
subjectId,
|
|
76
|
+
securityRevision: subject[mapping.subject.securityRevision],
|
|
77
|
+
credentials: credentials.map((row) => ({
|
|
78
|
+
credentialId: row[mapping.credential.credentialId],
|
|
79
|
+
revision: row[mapping.credential.revision],
|
|
80
|
+
})),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const sorted = [...revision.credentials].sort((a, b) =>
|
|
84
|
+
a.credentialId.localeCompare(b.credentialId),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
if (sorted.some((item, index) => item.credentialId !== requested[index]))
|
|
88
|
+
return yield* StaleAuthentication.make({});
|
|
89
|
+
|
|
90
|
+
return { subject, revision: { ...revision, credentials: sorted } };
|
|
91
|
+
});
|
|
@@ -151,12 +151,7 @@ export type Roles<C extends ClaimsCodec, Id extends string, A extends Definition
|
|
|
151
151
|
| "sessionFlows"
|
|
152
152
|
| (Enabled<A, "password"> extends never
|
|
153
153
|
? never
|
|
154
|
-
:
|
|
155
|
-
| "passwords"
|
|
156
|
-
| "passwordAttempts"
|
|
157
|
-
| "passwordScopes"
|
|
158
|
-
| "passwordCharges"
|
|
159
|
-
| "passwordCommands")
|
|
154
|
+
: "passwords" | "passwordAttempts" | "passwordCommands")
|
|
160
155
|
| (ManagedPassword<A> extends never ? never : "passwordRegistrations")
|
|
161
156
|
| (Enabled<A, "phone"> extends never ? never : "phoneState")
|
|
162
157
|
| (Enabled<A, "email"> extends never ? never : "emailCredentials" | "emailCommands")
|