@yielded/auth-persistence 0.1.0-beta.13 → 0.1.0-beta.15
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 +5 -3
- package/dist/Adapter.mjs +3 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/internal/browser-login.d.mts +10 -0
- package/dist/internal/browser-login.mjs +67 -0
- package/dist/internal/browser-login.mjs.map +1 -0
- package/dist/internal/email-kernel.d.mts +4 -3
- package/dist/internal/email-kernel.mjs +8 -0
- package/dist/internal/email-kernel.mjs.map +1 -1
- package/dist/internal/models/email-model.d.mts +5 -1
- package/dist/internal/models/email-model.mjs.map +1 -1
- package/dist/internal/models/passkey-model.d.mts +1 -1
- package/dist/internal/models/passkey-write-model.d.mts +1 -1
- package/dist/internal/models/password-model.d.mts +1 -1
- package/dist/internal/models/proof-model.d.mts +1 -1
- package/dist/internal/models/session-model.d.mts +1 -1
- package/dist/internal/models/step-up-model.d.mts +1 -1
- package/dist/internal/passkey/admission.d.mts +1 -1
- package/dist/internal/passkey/credentials.d.mts +1 -1
- package/dist/internal/passkey/flow.d.mts +1 -1
- package/dist/internal/passkey/registration-ceremony.d.mts +1 -1
- package/dist/internal/passkey/state.d.mts +1 -1
- package/dist/internal/passkey/target.d.mts +2 -1
- package/dist/internal/passkey/target.mjs +9 -8
- package/dist/internal/passkey/target.mjs.map +1 -1
- package/dist/internal/passkey/write-state.d.mts +1 -1
- package/dist/internal/passkey/write-target.mjs +4 -4
- package/dist/internal/passkey/write-target.mjs.map +1 -1
- package/dist/internal/passkey-kernel.d.mts +9 -9
- package/dist/internal/passkey-kernel.mjs +1 -1
- package/dist/internal/passkey-kernel.mjs.map +1 -1
- package/dist/internal/password-kernel.d.mts +4 -3
- package/dist/internal/password-kernel.mjs +4 -0
- package/dist/internal/password-kernel.mjs.map +1 -1
- package/dist/internal/persistence.d.mts +1 -1
- package/dist/internal/persistence.mjs +6 -6
- package/dist/internal/persistence.mjs.map +1 -1
- package/dist/internal/phone-kernel.d.mts +1 -1
- package/dist/internal/proof-kernel.d.mts +3 -2
- package/dist/internal/proof-kernel.mjs +6 -2
- package/dist/internal/proof-kernel.mjs.map +1 -1
- package/dist/internal/query-operations.d.mts +9 -4
- package/dist/internal/session-kernel.d.mts +7 -5
- package/dist/internal/session-kernel.mjs +9 -1
- package/dist/internal/session-kernel.mjs.map +1 -1
- package/dist/internal/storage-mapping.d.mts +59 -0
- package/dist/internal/storage-mapping.mjs +5 -0
- package/dist/internal/storage-mapping.mjs.map +1 -1
- package/dist/internal/storage-validation.d.mts +18 -0
- package/dist/internal/storage-validation.mjs +26 -1
- package/dist/internal/storage-validation.mjs.map +1 -1
- package/dist/internal/transaction-execution-kernel.d.mts +1 -1
- package/dist/internal/transaction-execution-kernel.mjs.map +1 -1
- package/dist/internal/transaction-kernel.d.mts +1 -1
- package/dist/internal/transaction-kernel.mjs +1 -1
- package/dist/internal/transaction-kernel.mjs.map +1 -1
- package/package.json +1 -1
- package/src/Adapter.ts +8 -4
- package/src/index.ts +1 -0
- package/src/internal/browser-login.ts +84 -0
- package/src/internal/email-kernel.ts +27 -2
- package/src/internal/models/email-model.ts +4 -0
- package/src/internal/passkey/target.ts +20 -9
- package/src/internal/passkey/write-target.ts +8 -8
- package/src/internal/passkey-kernel.ts +9 -1
- package/src/internal/password-kernel.ts +14 -1
- package/src/internal/persistence.ts +27 -6
- package/src/internal/proof-kernel.ts +50 -12
- package/src/internal/query-operations.ts +8 -0
- package/src/internal/session-kernel.ts +63 -8
- package/src/internal/storage-mapping.ts +5 -0
- package/src/internal/storage-validation.ts +83 -19
- package/src/internal/transaction-execution-kernel.ts +3 -2
- package/src/internal/transaction-kernel.ts +1 -1
package/dist/Adapter.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { QueryFailure, QueryOperations, SqlColumn, SqlExpression, SqlFragment, TableModel } from "./internal/query-operations.mjs";
|
|
2
1
|
import { PersistenceMappingError, isMappedConstraintConflict } from "./internal/mapping-error.mjs";
|
|
2
|
+
import { GuardedUpdate, NativeDatabase, Observation, Row, TransactionNativeDatabase, TransactionOwner, makeTransactionKernel } from "./internal/transaction-kernel.mjs";
|
|
3
|
+
import { QueryFailure, QueryOperations, SqlColumn, SqlExpression, SqlFragment, TableModel } from "./internal/query-operations.mjs";
|
|
3
4
|
import { SubjectIdCodec } from "./internal/models/common.mjs";
|
|
4
5
|
import { AnyEmailAddressMapping, AnyEmailRegistrationMapping, AnyEmailSignInMapping, D1EmailAddressMapping, D1EmailRegistrationMapping, EmailAddressMapping, EmailAuthorityCredentialTable, EmailCommandTable, EmailCredentialReadTable, EmailCredentialTable, EmailD1Clock, EmailIdentifierReadTable, EmailIdentifierTable, EmailRegistrationAuthorityCredentialTable, EmailRegistrationCredentialTable, EmailRegistrationIdentifierTable, EmailRegistrationIntent, EmailRegistrationMapping, EmailRegistrationProvisioning, EmailRegistrationState, EmailRegistrationTable, EmailSignInMapping, EmailSubjectReadTable, EmailSubjectTable, RequiredEmailAddressConstraints, RequiredEmailRegistrationConstraints, RequiredEmailSignInConstraints, requiredEmailAddressConstraints, requiredEmailRegistrationConstraints, requiredEmailSignInConstraints } from "./internal/models/email-model.mjs";
|
|
5
6
|
import { D1PasskeyMapping, PasskeyAdmissionTable, PasskeyCeremonyMapping, PasskeyChargeInsert, PasskeyChargeKind, PasskeyChargeTable, PasskeyClock, PasskeyColumn, PasskeyCredentialMapping, PasskeyCredentialOwnershipTable, PasskeyCredentialReadTable, PasskeyCredentialServices, PasskeyEnrollmentContextMapping, PasskeyEnrollmentContextServices, PasskeyFactorReadTable, PasskeyFlowInsert, PasskeyFlowState, PasskeyFlowTable, PasskeyHandleOwnershipTable, PasskeyHandleReadTable, PasskeyHandleReservationTable, PasskeyMappingSource, PasskeyModuleTable, PasskeyPersistenceMapping, PasskeyPersistenceServices, PasskeyPolicyGuard, PasskeySubjectIdCodec, PasskeySubjectReadTable, passkeyCredentialsLayer, passkeyEnrollmentContextLayer, passkeyPersistenceLayer, passkeyPolicyGuard, requiredPasskeyCredentialConstraints, requiredPasskeyPersistenceConstraints } from "./internal/models/passkey-model.mjs";
|
|
@@ -13,7 +14,6 @@ import { requireStandalone } from "./internal/standalone.mjs";
|
|
|
13
14
|
import { decodeStepUpIntent, encodeStepUpIntent, stepUpIntentLive, validateStepUpPlan } from "./internal/step-up-state.mjs";
|
|
14
15
|
import { CurrentProofSql, ProofSqlConfiguration, ProofSqlDatabase, ProofSqlQuery, makeProofKernel } from "./internal/proof-kernel.mjs";
|
|
15
16
|
import { CurrentAddress, CurrentEmailSql, EmailSqlConfiguration, EmailSqlDatabase, EmailSqlQuery, makeEmailKernel } from "./internal/email-kernel.mjs";
|
|
16
|
-
import { GuardedUpdate, NativeDatabase, Observation, Row, TransactionNativeDatabase, TransactionOwner, makeTransactionKernel } from "./internal/transaction-kernel.mjs";
|
|
17
17
|
import { CurrentPasskeyTransaction, PasskeyOwner } from "./internal/passkey/state.mjs";
|
|
18
18
|
import { TransactionBound, TransactionCoordinatorError, TransactionExecution, TransactionTargetConfiguration, makeTransactionExecutionKernel } from "./internal/transaction-execution-kernel.mjs";
|
|
19
19
|
import { PasskeyCoordinatorError, PasskeyExecution, PasskeyTargetConfiguration } from "./internal/passkey/target.mjs";
|
|
@@ -26,5 +26,7 @@ import { StorageTable } from "./internal/storage-tables.mjs";
|
|
|
26
26
|
import { BoundPersistence, ClaimsCodec, Definition, PersistenceApi, PersistenceConfigurationError } from "./internal/configuration.mjs";
|
|
27
27
|
import { createPersistence } from "./internal/persistence.mjs";
|
|
28
28
|
import { makeComposedPasskeys } from "./internal/passkeys.mjs";
|
|
29
|
+
import { makeMappings } from "./internal/storage-mapping.mjs";
|
|
29
30
|
import { PasswordRegistrationAuthority } from "./internal/registration-contract.mjs";
|
|
30
|
-
|
|
31
|
+
import { PhysicalStorageTable, validateStorage } from "./internal/storage-validation.mjs";
|
|
32
|
+
export { type AnyEmailAddressMapping, type AnyEmailRegistrationMapping, type AnyEmailSignInMapping, type AnyPasswordPersistenceMapping, type AnyPasswordRegistrationMapping, type AnyProofPersistenceMapping, type AuthenticationAuthorityMapping, type BoundPersistence, type ClaimsCodec, type CurrentAddress, CurrentEmailSql, CurrentPasskeyTransaction, CurrentPasswordPreparedTransaction, CurrentPasswordSql, CurrentPhoneTransaction, CurrentProofSql, CurrentSessionSql, type D1AuthenticationAuthorityMapping, type D1EmailAddressMapping, type D1EmailRegistrationMapping, type D1PasskeyMapping, type D1PasswordPersistenceMapping, type D1PendingAuthenticationMapping, type D1ProofPersistenceMapping, type D1SessionClockMapping, type D1SessionStepUpMapping, type D1SignedSessionValidityMapping, type D1StatefulSessionMapping, type Definition, type EmailAddressMapping, type EmailAuthorityCredentialTable, type EmailCommandTable, type EmailCredentialReadTable, type EmailCredentialTable, type EmailD1Clock, type EmailIdentifierReadTable, type EmailIdentifierTable, type EmailRegistrationAuthorityCredentialTable, type EmailRegistrationCredentialTable, type EmailRegistrationIdentifierTable, type EmailRegistrationIntent, type EmailRegistrationMapping, type EmailRegistrationProvisioning, type EmailRegistrationState, type EmailRegistrationTable, type EmailSignInMapping, type EmailSqlConfiguration, type EmailSqlDatabase, type EmailSqlQuery, type EmailSubjectReadTable, type EmailSubjectTable, type GuardedUpdate, NativeDatabase, type Observation, type PasskeyAdmissionTable, type PasskeyCeremonyMapping, type PasskeyChargeInsert, type PasskeyChargeKind, type PasskeyChargeTable, type PasskeyClock, type PasskeyColumn, type PasskeyCommandTable, type PasskeyCoordinatorError, type PasskeyCredentialInsert, type PasskeyCredentialMapping, type PasskeyCredentialOwnershipTable, type PasskeyCredentialReadTable, type PasskeyCredentialServices, type PasskeyEnrollmentContextMapping, type PasskeyEnrollmentContextServices, type PasskeyExecution, type PasskeyFactorReadTable, type PasskeyFlowInsert, type PasskeyFlowState, type PasskeyFlowTable, type PasskeyHandleOwnershipTable, type PasskeyHandleReadTable, type PasskeyHandleReservationTable, type PasskeyInvalidationInput, type PasskeyInvalidationMutation, type PasskeyKernel, type PasskeyManagementMapping, type PasskeyManagementServices, type PasskeyMappingSource, type PasskeyModuleTable, type PasskeyOwner, type PasskeyPersistenceMapping, type PasskeyPersistenceServices, type PasskeyPolicyGuard, type PasskeyRegistrationCeremonyCapabilities, type PasskeyRegistrationCeremonyMapping, type PasskeyRegistrationCeremonyServices, type PasskeyRegistrationIntentReadTable, type PasskeyRegistrationMapping, type PasskeyRegistrationServices, type PasskeyRegistrationWriter, type PasskeySubjectIdCodec, type PasskeySubjectReadTable, type PasskeyTargetConfiguration, type PasskeyWriteTables, type PasswordAttemptAction, type PasswordAttemptRecord, type PasswordAttemptState, type PasswordAttemptTable, type PasswordAuthorityCredentialTable, type PasswordChargeTable, type PasswordCommandTable, type PasswordConstraintClassifier, type PasswordCredentialTable, type PasswordD1Clock, type PasswordIdentifierTable, type PasswordPersistenceMapping, PasswordPreparedJournalGuards, type PasswordPreparedPostcondition, PasswordPreparedPostconditions, type PasswordRateScopeKind, type PasswordRateScopeTable, type PasswordRegistrationAuthority, type PasswordRegistrationConstraintClassifier, type PasswordRegistrationIntent, type PasswordRegistrationMapping, type PasswordRegistrationProvisioning, type PasswordRegistrationState, type PasswordRegistrationTable, type PasswordScopeKeys, type PasswordSqlConfiguration, type PasswordSqlDatabase, type PasswordSqlQuery, type PasswordSubjectTable, type PendingAuthenticationMapping, type PendingAuthenticationTables, type PersistenceApi, PersistenceConfigurationError, PersistenceMappingError, type PhysicalStorageTable, type ProofAbuseEventTable, type ProofAction, type ProofAuthorityInput, type ProofAuthorityTables, type ProofCommandDecision, type ProofCommandKind, type ProofCommandTable, type ProofConstraintClassifier, type ProofContinuationRecord, type ProofContinuationTable, type ProofD1Clock, type ProofDeliveryState, type ProofFailureEventTable, type ProofGenerationState, type ProofGenerationTable, type ProofPersistenceMapping, type ProofRateScopeTable, type ProofRequestTable, type ProofScopeKeys, type ProofScopeKind, type ProofSeriesTable, type ProofSqlConfiguration, type ProofSqlDatabase, type ProofSqlQuery, type QueryFailure, type QueryOperations, type RequiredEmailAddressConstraints, type RequiredEmailRegistrationConstraints, type RequiredEmailSignInConstraints, type RequiredPasswordConstraints, type RequiredPasswordRegistrationConstraints, type RequiredPendingAuthenticationConstraints, type RequiredProofConstraints, type RequiredSessionConstraints, type RequiredSessionStepUpConstraints, type RequiredSignedValidityConstraints, type RequiredStatefulPendingConstraints, type Row, type SessionAuthorityTables, type SessionConstraintClassifier, type SessionFlowTables, type SessionIdCodec, type SessionSqlDatabase, type SessionSqlOptions, type SessionStepUpIntentTables, type SessionStepUpMapping, type SessionStepUpSourceTables, type SessionSubjectTables, type SignedSessionValidityMapping, type SignedSessionValidityTables, type SqlColumn, type SqlExpression, type SqlFragment, type StatefulSessionMapping, type StatefulSessionTables, type StorageTable, type SubjectIdCodec, type TableModel, type TransactionBound, type TransactionCoordinatorError, type TransactionExecution, type TransactionNativeDatabase, type TransactionOwner, type TransactionTargetConfiguration, createPersistence, decodeStepUpIntent, encodeStepUpIntent, isMappedConstraintConflict, makeComposedPasskeys, makeEmailKernel, makePasskeyKernel, makePasswordKernel, makePhoneKernel, makeProofKernel, makeSessionKernel, makeMappings as makeStorageMappings, makeTransactionExecutionKernel, makeTransactionKernel, passkeyCredentialsLayer, passkeyEnrollmentContextLayer, passkeyInvalidationMutation, passkeyPersistenceLayer, passkeyPolicyGuard, requireStandalone, requiredEmailAddressConstraints, requiredEmailRegistrationConstraints, requiredEmailSignInConstraints, requiredPasskeyCredentialConstraints, requiredPasskeyManagementConstraints, requiredPasskeyPersistenceConstraints, requiredPasskeyRegistrationCeremonyConstraints, requiredPasskeyRegistrationWriteConstraints, requiredPasswordConstraints, requiredPasswordRegistrationConstraints, requiredPendingAuthenticationConstraints, requiredProofConstraints, requiredSessionConstraints, requiredSessionStepUpConstraints, requiredSignedValidityConstraints, requiredStatefulPendingConstraints, stepUpIntentLive, validateStepUpPlan, validateStorage };
|
package/dist/Adapter.mjs
CHANGED
|
@@ -19,7 +19,9 @@ import { CurrentPasswordSql, makePasswordKernel } from "./internal/password-kern
|
|
|
19
19
|
import { CurrentPhoneTransaction, makePhoneKernel } from "./internal/phone-kernel.mjs";
|
|
20
20
|
import { decodeStepUpIntent, encodeStepUpIntent, stepUpIntentLive, validateStepUpPlan } from "./internal/step-up-state.mjs";
|
|
21
21
|
import { CurrentSessionSql, makeSessionKernel } from "./internal/session-kernel.mjs";
|
|
22
|
+
import { makeMappings } from "./internal/storage-mapping.mjs";
|
|
23
|
+
import { validateStorage } from "./internal/storage-validation.mjs";
|
|
22
24
|
import { createPersistence } from "./internal/persistence.mjs";
|
|
23
25
|
import { requiredPendingAuthenticationConstraints, requiredSessionConstraints, requiredSignedValidityConstraints, requiredStatefulPendingConstraints } from "./internal/models/session-model.mjs";
|
|
24
26
|
import { requiredSessionStepUpConstraints } from "./internal/models/step-up-model.mjs";
|
|
25
|
-
export { CurrentEmailSql, CurrentPasskeyTransaction, CurrentPasswordPreparedTransaction, CurrentPasswordSql, CurrentPhoneTransaction, CurrentProofSql, CurrentSessionSql, NativeDatabase, PasswordPreparedJournalGuards, PasswordPreparedPostconditions, PersistenceConfigurationError, PersistenceMappingError, createPersistence, decodeStepUpIntent, encodeStepUpIntent, isMappedConstraintConflict, makeComposedPasskeys, makeEmailKernel, makePasskeyKernel, makePasswordKernel, makePhoneKernel, makeProofKernel, makeSessionKernel, makeTransactionExecutionKernel, makeTransactionKernel, passkeyCredentialsLayer, passkeyEnrollmentContextLayer, passkeyInvalidationMutation, passkeyPersistenceLayer, passkeyPolicyGuard, requireStandalone, requiredEmailAddressConstraints, requiredEmailRegistrationConstraints, requiredEmailSignInConstraints, requiredPasskeyCredentialConstraints, requiredPasskeyManagementConstraints, requiredPasskeyPersistenceConstraints, requiredPasskeyRegistrationCeremonyConstraints, requiredPasskeyRegistrationWriteConstraints, requiredPasswordConstraints, requiredPasswordRegistrationConstraints, requiredPendingAuthenticationConstraints, requiredProofConstraints, requiredSessionConstraints, requiredSessionStepUpConstraints, requiredSignedValidityConstraints, requiredStatefulPendingConstraints, stepUpIntentLive, validateStepUpPlan };
|
|
27
|
+
export { CurrentEmailSql, CurrentPasskeyTransaction, CurrentPasswordPreparedTransaction, CurrentPasswordSql, CurrentPhoneTransaction, CurrentProofSql, CurrentSessionSql, NativeDatabase, PasswordPreparedJournalGuards, PasswordPreparedPostconditions, PersistenceConfigurationError, PersistenceMappingError, createPersistence, decodeStepUpIntent, encodeStepUpIntent, isMappedConstraintConflict, makeComposedPasskeys, makeEmailKernel, makePasskeyKernel, makePasswordKernel, makePhoneKernel, makeProofKernel, makeSessionKernel, makeMappings as makeStorageMappings, makeTransactionExecutionKernel, makeTransactionKernel, passkeyCredentialsLayer, passkeyEnrollmentContextLayer, passkeyInvalidationMutation, passkeyPersistenceLayer, passkeyPolicyGuard, requireStandalone, requiredEmailAddressConstraints, requiredEmailRegistrationConstraints, requiredEmailSignInConstraints, requiredPasskeyCredentialConstraints, requiredPasskeyManagementConstraints, requiredPasskeyPersistenceConstraints, requiredPasskeyRegistrationCeremonyConstraints, requiredPasskeyRegistrationWriteConstraints, requiredPasswordConstraints, requiredPasswordRegistrationConstraints, requiredPendingAuthenticationConstraints, requiredProofConstraints, requiredSessionConstraints, requiredSessionStepUpConstraints, requiredSignedValidityConstraints, requiredStatefulPendingConstraints, stepUpIntentLive, validateStepUpPlan, validateStorage };
|
package/dist/index.d.mts
CHANGED
|
@@ -3,4 +3,5 @@ import { StorageColumn, StorageTable } from "./internal/storage-tables.mjs";
|
|
|
3
3
|
import { PersistenceConfigurationError } from "./internal/configuration.mjs";
|
|
4
4
|
import { AuthPersistence } from "./internal/sql-persistence.mjs";
|
|
5
5
|
import { OAuthServerPersistence } from "./internal/oauth-server.mjs";
|
|
6
|
-
|
|
6
|
+
import { BrowserLoginPersistence } from "./internal/browser-login.mjs";
|
|
7
|
+
export { AuthPersistence, BrowserLoginPersistence, OAuthServerPersistence, PersistenceConfigurationError, PersistenceMappingError, StorageColumn, StorageTable };
|
package/dist/index.mjs
CHANGED
|
@@ -3,4 +3,5 @@ import { PersistenceMappingError } from "./internal/mapping-error.mjs";
|
|
|
3
3
|
import { StorageColumn, StorageTable } from "./internal/storage-tables.mjs";
|
|
4
4
|
import { AuthPersistence } from "./internal/sql-persistence.mjs";
|
|
5
5
|
import { OAuthServerPersistence } from "./internal/oauth-server.mjs";
|
|
6
|
-
|
|
6
|
+
import { BrowserLoginPersistence } from "./internal/browser-login.mjs";
|
|
7
|
+
export { AuthPersistence, BrowserLoginPersistence, OAuthServerPersistence, PersistenceConfigurationError, PersistenceMappingError, StorageColumn, StorageTable };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Layer } from "effect";
|
|
2
|
+
import { SqlClient } from "effect/sql";
|
|
3
|
+
import { Persistence, Unavailable } from "@yielded/auth/BrowserLogin";
|
|
4
|
+
//#region src/internal/browser-login.d.ts
|
|
5
|
+
export declare const BrowserLoginPersistence: {
|
|
6
|
+
migration: string;
|
|
7
|
+
layer: Layer.Layer<Persistence, Unavailable, SqlClient.SqlClient>;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
//# sourceMappingURL=browser-login.d.mts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { requireStandalone } from "./standalone.mjs";
|
|
2
|
+
import { Effect, Layer, Schema } from "effect";
|
|
3
|
+
import { SqlClient } from "effect/sql";
|
|
4
|
+
import { Persistence, Record, Unavailable } from "@yielded/auth/BrowserLogin";
|
|
5
|
+
//#region src/internal/browser-login.ts
|
|
6
|
+
const codec = Schema.fromJsonString(Record);
|
|
7
|
+
const Row = Schema.Struct({
|
|
8
|
+
payload: Schema.String,
|
|
9
|
+
version: Schema.String
|
|
10
|
+
});
|
|
11
|
+
const BrowserLoginPersistence = {
|
|
12
|
+
migration: `CREATE TABLE yielded_browser_login (
|
|
13
|
+
namespace TEXT NOT NULL,
|
|
14
|
+
attempt_id TEXT NOT NULL,
|
|
15
|
+
version TEXT NOT NULL,
|
|
16
|
+
expires_at_millis BIGINT NOT NULL,
|
|
17
|
+
payload TEXT NOT NULL,
|
|
18
|
+
PRIMARY KEY (namespace, attempt_id)
|
|
19
|
+
)`,
|
|
20
|
+
layer: Layer.effect(Persistence, Effect.gen(function* () {
|
|
21
|
+
const sql = yield* SqlClient.SqlClient;
|
|
22
|
+
if (!sql.onDialectOrElse({
|
|
23
|
+
sqlite: () => true,
|
|
24
|
+
pg: () => true,
|
|
25
|
+
orElse: () => false
|
|
26
|
+
})) return yield* Unavailable.make({});
|
|
27
|
+
const standalone = requireStandalone(() => Unavailable.make({}), sql.transactionService);
|
|
28
|
+
const failure = (effect) => effect.pipe(Effect.mapError(() => Unavailable.make({})));
|
|
29
|
+
const clock = sql.onDialectOrElse({
|
|
30
|
+
sqlite: () => sql.literal("CAST((julianday('now') - 2440587.5) * 86400000 AS INTEGER)"),
|
|
31
|
+
orElse: () => sql.literal("CAST(EXTRACT(EPOCH FROM clock_timestamp()) * 1000 AS BIGINT)")
|
|
32
|
+
});
|
|
33
|
+
return Persistence.of({
|
|
34
|
+
get: Effect.fnUntraced(function* (namespace, id) {
|
|
35
|
+
yield* standalone;
|
|
36
|
+
const rows = yield* sql`SELECT payload, version FROM yielded_browser_login WHERE namespace = ${namespace} AND attempt_id = ${id}`;
|
|
37
|
+
if (rows.length === 0) return void 0;
|
|
38
|
+
if (rows.length !== 1) return yield* Unavailable.make({});
|
|
39
|
+
const row = yield* Schema.decodeUnknownEffect(Row)(rows[0]);
|
|
40
|
+
const record = yield* Schema.decodeEffect(codec)(row.payload);
|
|
41
|
+
if (record.version !== row.version) return yield* Unavailable.make({});
|
|
42
|
+
return record;
|
|
43
|
+
}, failure),
|
|
44
|
+
insert: Effect.fnUntraced(function* (namespace, id, record) {
|
|
45
|
+
yield* standalone;
|
|
46
|
+
const payload = yield* Schema.encodeEffect(codec)(record);
|
|
47
|
+
return (yield* sql`INSERT INTO yielded_browser_login (namespace, attempt_id, version, expires_at_millis, payload)
|
|
48
|
+
SELECT ${namespace}, ${id}, ${record.version}, ${record.expiresAtMillis}, ${payload}
|
|
49
|
+
WHERE ${record.expiresAtMillis} > ${clock}
|
|
50
|
+
ON CONFLICT (namespace, attempt_id) DO NOTHING RETURNING version`).length === 1;
|
|
51
|
+
}, failure),
|
|
52
|
+
compareAndSet: Effect.fnUntraced(function* (namespace, id, version, record) {
|
|
53
|
+
yield* standalone;
|
|
54
|
+
if (version === record.version) return yield* Unavailable.make({});
|
|
55
|
+
const payload = yield* Schema.encodeEffect(codec)(record);
|
|
56
|
+
return (yield* sql`UPDATE yielded_browser_login SET version = ${record.version}, payload = ${payload}
|
|
57
|
+
WHERE namespace = ${namespace} AND attempt_id = ${id} AND version = ${version}
|
|
58
|
+
AND expires_at_millis = ${record.expiresAtMillis} AND expires_at_millis > ${clock}
|
|
59
|
+
RETURNING version`).length === 1;
|
|
60
|
+
}, failure)
|
|
61
|
+
});
|
|
62
|
+
}))
|
|
63
|
+
};
|
|
64
|
+
//#endregion
|
|
65
|
+
export { BrowserLoginPersistence };
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=browser-login.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-login.mjs","names":[],"sources":["../../src/internal/browser-login.ts"],"sourcesContent":["import { Persistence, Record, Unavailable } from \"@yielded/auth/BrowserLogin\";\nimport { Effect, Layer, Schema } from \"effect\";\nimport { SqlClient } from \"effect/sql\";\n\nimport { requireStandalone } from \"./standalone\";\n\nconst codec = Schema.fromJsonString(Record);\nconst Row = Schema.Struct({ payload: Schema.String, version: Schema.String });\n\n/** SQLite/D1 and PostgreSQL; apply through application migrations. Terminal\n * attempts are retained until expiry. Contains private provenance, never bearers.\n */\nconst migration = `CREATE TABLE yielded_browser_login (\n namespace TEXT NOT NULL,\n attempt_id TEXT NOT NULL,\n version TEXT NOT NULL,\n expires_at_millis BIGINT NOT NULL,\n payload TEXT NOT NULL,\n PRIMARY KEY (namespace, attempt_id)\n)`;\n\nconst layer = Layer.effect(\n Persistence,\n Effect.gen(function* () {\n const sql = yield* SqlClient.SqlClient;\n\n if (!sql.onDialectOrElse({ sqlite: () => true, pg: () => true, orElse: () => false }))\n return yield* Unavailable.make({});\n const standalone = requireStandalone(() => Unavailable.make({}), sql.transactionService);\n\n const failure = <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n effect.pipe(Effect.mapError(() => Unavailable.make({})));\n\n const clock = sql.onDialectOrElse({\n sqlite: () => sql.literal(\"CAST((julianday('now') - 2440587.5) * 86400000 AS INTEGER)\"),\n orElse: () => sql.literal(\"CAST(EXTRACT(EPOCH FROM clock_timestamp()) * 1000 AS BIGINT)\"),\n });\n\n return Persistence.of({\n get: Effect.fnUntraced(function* (namespace, id) {\n yield* standalone;\n\n const rows =\n yield* sql`SELECT payload, version FROM yielded_browser_login WHERE namespace = ${namespace} AND attempt_id = ${id}`;\n\n if (rows.length === 0) return undefined;\n if (rows.length !== 1) return yield* Unavailable.make({});\n const row = yield* Schema.decodeUnknownEffect(Row)(rows[0]);\n const record = yield* Schema.decodeEffect(codec)(row.payload);\n\n if (record.version !== row.version) return yield* Unavailable.make({});\n\n return record;\n }, failure),\n insert: Effect.fnUntraced(function* (namespace, id, record) {\n yield* standalone;\n const payload = yield* Schema.encodeEffect(codec)(record);\n\n const rows =\n yield* sql`INSERT INTO yielded_browser_login (namespace, attempt_id, version, expires_at_millis, payload)\n SELECT ${namespace}, ${id}, ${record.version}, ${record.expiresAtMillis}, ${payload}\n WHERE ${record.expiresAtMillis} > ${clock}\n ON CONFLICT (namespace, attempt_id) DO NOTHING RETURNING version`;\n\n return rows.length === 1;\n }, failure),\n compareAndSet: Effect.fnUntraced(function* (namespace, id, version, record) {\n yield* standalone;\n if (version === record.version) return yield* Unavailable.make({});\n const payload = yield* Schema.encodeEffect(codec)(record);\n\n const rows =\n yield* sql`UPDATE yielded_browser_login SET version = ${record.version}, payload = ${payload}\n WHERE namespace = ${namespace} AND attempt_id = ${id} AND version = ${version}\n AND expires_at_millis = ${record.expiresAtMillis} AND expires_at_millis > ${clock}\n RETURNING version`;\n\n return rows.length === 1;\n }, failure),\n });\n }),\n);\n\nexport const BrowserLoginPersistence = { migration, layer };\n"],"mappings":";;;;;AAMA,MAAM,QAAQ,OAAO,eAAe,MAAM;AAC1C,MAAM,MAAM,OAAO,OAAO;CAAE,SAAS,OAAO;CAAQ,SAAS,OAAO;AAAO,CAAC;AA4E5E,MAAa,0BAA0B;CAAE;;;;;;;;CAAW,OA9DtC,MAAM,OAClB,aACA,OAAO,IAAI,aAAa;EACtB,MAAM,MAAM,OAAO,UAAU;EAE7B,IAAI,CAAC,IAAI,gBAAgB;GAAE,cAAc;GAAM,UAAU;GAAM,cAAc;EAAM,CAAC,GAClF,OAAO,OAAO,YAAY,KAAK,CAAC,CAAC;EACnC,MAAM,aAAa,wBAAwB,YAAY,KAAK,CAAC,CAAC,GAAG,IAAI,kBAAkB;EAEvF,MAAM,WAAoB,WACxB,OAAO,KAAK,OAAO,eAAe,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC;EAEzD,MAAM,QAAQ,IAAI,gBAAgB;GAChC,cAAc,IAAI,QAAQ,4DAA4D;GACtF,cAAc,IAAI,QAAQ,8DAA8D;EAC1F,CAAC;EAED,OAAO,YAAY,GAAG;GACpB,KAAK,OAAO,WAAW,WAAW,WAAW,IAAI;IAC/C,OAAO;IAEP,MAAM,OACJ,OAAO,GAAG,wEAAwE,UAAU,oBAAoB;IAElH,IAAI,KAAK,WAAW,GAAG,OAAO,KAAA;IAC9B,IAAI,KAAK,WAAW,GAAG,OAAO,OAAO,YAAY,KAAK,CAAC,CAAC;IACxD,MAAM,MAAM,OAAO,OAAO,oBAAoB,GAAG,CAAC,CAAC,KAAK,EAAE;IAC1D,MAAM,SAAS,OAAO,OAAO,aAAa,KAAK,CAAC,CAAC,IAAI,OAAO;IAE5D,IAAI,OAAO,YAAY,IAAI,SAAS,OAAO,OAAO,YAAY,KAAK,CAAC,CAAC;IAErE,OAAO;GACT,GAAG,OAAO;GACV,QAAQ,OAAO,WAAW,WAAW,WAAW,IAAI,QAAQ;IAC1D,OAAO;IACP,MAAM,UAAU,OAAO,OAAO,aAAa,KAAK,CAAC,CAAC,MAAM;IAQxD,QAAO,OALE,GAAG;iBACH,UAAU,IAAI,GAAG,IAAI,OAAO,QAAQ,IAAI,OAAO,gBAAgB,IAAI,QAAQ;gBAC5E,OAAO,gBAAgB,KAAK,MAAM;0EAG/B,CAAC,WAAW;GACzB,GAAG,OAAO;GACV,eAAe,OAAO,WAAW,WAAW,WAAW,IAAI,SAAS,QAAQ;IAC1E,OAAO;IACP,IAAI,YAAY,OAAO,SAAS,OAAO,OAAO,YAAY,KAAK,CAAC,CAAC;IACjE,MAAM,UAAU,OAAO,OAAO,aAAa,KAAK,CAAC,CAAC,MAAM;IAQxD,QAAO,OALE,GAAG,8CAA8C,OAAO,QAAQ,cAAc,QAAQ;4BAC3E,UAAU,oBAAoB,GAAG,iBAAiB,QAAQ;kCACpD,OAAO,gBAAgB,2BAA2B,MAAM;2BAGvE,CAAC,WAAW;GACzB,GAAG,OAAO;EACZ,CAAC;CACH,CAAC,CAGiD;AAAM"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { QueryFailure, QueryOperations, SqlColumn, SqlFragment } from "./query-operations.mjs";
|
|
2
1
|
import { PersistenceMappingError } from "./mapping-error.mjs";
|
|
2
|
+
import { NativeDatabase } from "./transaction-kernel.mjs";
|
|
3
|
+
import { QueryFailure, QueryOperations, SqlColumn, SqlFragment } from "./query-operations.mjs";
|
|
3
4
|
import { AnyEmailAddressMapping, AnyEmailSignInMapping } from "./models/email-model.mjs";
|
|
4
5
|
import { ProofSqlConfiguration, makeProofKernel } from "./proof-kernel.mjs";
|
|
5
6
|
import { Context, DateTime, Effect, Option } from "effect";
|
|
@@ -97,7 +98,7 @@ export declare const makeEmailKernel: <Fragment extends SqlFragment = SqlFragmen
|
|
|
97
98
|
readonly moduleId: string;
|
|
98
99
|
readonly identifier: LoginIdentifier;
|
|
99
100
|
}) => Effect.Effect<Option.Option<EmailCredentialSnapshot>, EmailUnavailable>;
|
|
100
|
-
},
|
|
101
|
+
}, EmailUnavailable, CurrentEmailSql | NativeDatabase>;
|
|
101
102
|
currentAddress: (mapping: AnyEmailAddressMapping<Fragment>, input: {
|
|
102
103
|
readonly moduleId: string;
|
|
103
104
|
readonly subjectId: string;
|
|
@@ -269,7 +270,7 @@ export declare const makeEmailKernel: <Fragment extends SqlFragment = SqlFragmen
|
|
|
269
270
|
readonly removed: number;
|
|
270
271
|
readonly hasMore: boolean;
|
|
271
272
|
}, A>) => Effect.Effect<PreparedCommit<A>, EmailUnavailable>;
|
|
272
|
-
},
|
|
273
|
+
}, EmailUnavailable, CurrentEmailSql | LifecycleHooks | NativeDatabase>;
|
|
273
274
|
};
|
|
274
275
|
//#endregion
|
|
275
276
|
//# sourceMappingURL=email-kernel.d.mts.map
|
|
@@ -140,6 +140,10 @@ const makeEmailKernel = (operations, proofs) => {
|
|
|
140
140
|
});
|
|
141
141
|
const makeSqlEmailSignInTargets = Effect.fn("makeSqlEmailSignInTargets")(function* (mapping, configuration) {
|
|
142
142
|
const database = yield* CurrentEmailSql;
|
|
143
|
+
if (!configuration.coordinated) yield* (operations.validateStorage?.({
|
|
144
|
+
...mapping,
|
|
145
|
+
proof: configuration.proof?.mapping
|
|
146
|
+
}) ?? Effect.void).pipe(Effect.mapError(unavailable));
|
|
143
147
|
return EmailSignInTargets.of({ lookup: (input) => (validEmailSignInConstraints(mapping) ? safeRead(database, configuration, Effect.gen(function* () {
|
|
144
148
|
const row = (yield* emailLookupRows(mapping, input.moduleId, input.identifier))[0];
|
|
145
149
|
if (row === void 0) return Option.none();
|
|
@@ -382,6 +386,10 @@ const makeEmailKernel = (operations, proofs) => {
|
|
|
382
386
|
});
|
|
383
387
|
const makeSqlEmailAddressPersistence = Effect.fn("makeSqlEmailAddressPersistence")(function* (mapping, configuration) {
|
|
384
388
|
const database = yield* CurrentEmailSql;
|
|
389
|
+
if (!configuration.coordinated) yield* (operations.validateStorage?.({
|
|
390
|
+
...mapping,
|
|
391
|
+
proof: configuration.proof?.mapping
|
|
392
|
+
}) ?? Effect.void).pipe(Effect.mapError(unavailable));
|
|
385
393
|
const hooks = yield* LifecycleHooks;
|
|
386
394
|
return EmailAddressPersistence.of({
|
|
387
395
|
target: (input) => (validAddressConstraints(mapping) ? safeRead(database, configuration, Effect.gen(function* () {
|