@shivaedev/identity 0.43.0 → 0.44.1
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/CHANGELOG.md +16 -0
- package/README.md +19 -8
- package/dist/server/account-clock/boundary.d.ts +1 -1
- package/dist/server/account-clock/boundary.d.ts.map +1 -1
- package/dist/server/account-clock/boundary.js +2 -2
- package/dist/server/account-clock/boundary.js.map +1 -1
- package/dist/server/account-clock/dayRange.d.ts +2 -3
- package/dist/server/account-clock/dayRange.d.ts.map +1 -1
- package/dist/server/account-clock/dayRange.js +6 -4
- package/dist/server/account-clock/dayRange.js.map +1 -1
- package/dist/server/account-clock/initialize.d.ts +1 -6
- package/dist/server/account-clock/initialize.d.ts.map +1 -1
- package/dist/server/account-clock/initialize.js +1 -9
- package/dist/server/account-clock/initialize.js.map +1 -1
- package/dist/server/account-clock/logicalDay.d.ts +1 -2
- package/dist/server/account-clock/logicalDay.d.ts.map +1 -1
- package/dist/server/account-clock/logicalDay.js +6 -4
- package/dist/server/account-clock/logicalDay.js.map +1 -1
- package/dist/server/account-clock/service.d.ts +4 -5
- package/dist/server/account-clock/service.d.ts.map +1 -1
- package/dist/server/account-clock/service.js +2 -3
- package/dist/server/account-clock/service.js.map +1 -1
- package/dist/server/account-clock/zone.d.ts +3 -0
- package/dist/server/account-clock/zone.d.ts.map +1 -0
- package/dist/server/account-clock/zone.js +8 -0
- package/dist/server/account-clock/zone.js.map +1 -0
- package/dist/server/better-auth/adapters/evictCachedAccount.d.ts +7 -0
- package/dist/server/better-auth/adapters/evictCachedAccount.d.ts.map +1 -0
- package/dist/server/better-auth/adapters/evictCachedAccount.js +36 -0
- package/dist/server/better-auth/adapters/evictCachedAccount.js.map +1 -0
- package/dist/server/better-auth/deleteAccount.d.ts.map +1 -1
- package/dist/server/better-auth/deleteAccount.js +3 -0
- package/dist/server/better-auth/deleteAccount.js.map +1 -1
- package/dist/server/better-auth/deleteUserRows.d.ts.map +1 -1
- package/dist/server/better-auth/deleteUserRows.js +6 -3
- package/dist/server/better-auth/deleteUserRows.js.map +1 -1
- package/package.json +8 -8
- package/src/server/account-clock/boundary.ts +2 -2
- package/src/server/account-clock/dayRange.ts +7 -5
- package/src/server/account-clock/initialize.ts +1 -9
- package/src/server/account-clock/logicalDay.ts +6 -5
- package/src/server/account-clock/service.ts +2 -3
- package/src/server/account-clock/zone.ts +8 -0
- package/src/server/better-auth/adapters/evictCachedAccount.ts +41 -0
- package/src/server/better-auth/deleteAccount.ts +3 -0
- package/src/server/better-auth/deleteUserRows.ts +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.44.1 - 2026-11-21
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Update `@shivaedev/contract` from 0.58.0 to 0.59.0.
|
|
8
|
+
|
|
9
|
+
## 0.44.0 - 2026-11-21
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- The account `delete` command works when the auth declaration configures `secondaryStorage`. It previously failed on the `verification` table, which Better Auth does not create there. Inside its transaction it now revokes the person's sessions in `secondaryStorage` as Better Auth does, so none of them resolves a user afterwards, with or without `storeSessionInDatabase`. It records Better Auth's revoked-before time, which alone ends a session created before the deletion, and deletes the listed sessions whether the store's client returns JSON text or parsed values. It also deletes the email codes of their exact address kept there.
|
|
14
|
+
|
|
15
|
+
### Breaking
|
|
16
|
+
|
|
17
|
+
- `AccountClock` is a global service that answers for any account: `logicalDay(account, instant?)` and `dayRange(account, day)` take the account id first and read that account's saved timezone on each call, and the Layer requires `AccountPreferencesStore` and `AccountDayStart` instead of `Subject`. Replace `clock.logicalDay()` with `clock.logicalDay((yield* Subject).id)` and `clock.dayRange(day)` with `clock.dayRange((yield* Subject).id, day)`, and move the clock's Layer from `requestServices` to `services`, for example `AccountClock.layer.pipe(Layer.provide(Layer.succeed(AccountDayStart, 240)), Layer.provideMerge(accountPreferencesStore))`. Both methods now fail with `AuthUnavailable` when the account's preferences cannot be read, where the old clock failed its request Layer's construction, and `dayRange` keeps its `SchemaError` for a `day` that is not an ISO calendar date. A defined module's operation, a job, and a native handler whose contract declares a subject or identity middleware carry `AuthUnavailable` with nothing to add; a native contract without either adds `rejections: { AuthUnavailable }` to the query.
|
|
18
|
+
|
|
3
19
|
## 0.43.0 - 2026-11-21
|
|
4
20
|
|
|
5
21
|
### Added
|
package/README.md
CHANGED
|
@@ -156,24 +156,35 @@ export const auth = createAuthClient({ plugins: [preferencesPlugin()] });
|
|
|
156
156
|
|
|
157
157
|
The client sends its `Intl.DateTimeFormat` timezone and locale to the auth mount in the `x-platform-account-timezone` and `x-platform-account-locale` headers, whose names `accountPreferenceHeaders` from `@shivaedev/identity/accountPreferenceHeaders.ts` exports. It sends them only where a global `window` exists, as in a browser, a WebView or React Native, so a server-side auth call does not report the server's zone. A successful first sign-in captures those values with metric units. After redirect-based sign-in, the client's first `getSession` captures them. Missing or invalid timezone data leaves preferences uncaptured; a later session can capture them. A bundled native shell installs the same plugin (see [Bundled native clients](#bundled-native-clients)). Clients without a Better Auth client can call the `capture` contract with their own defaults.
|
|
158
158
|
|
|
159
|
-
`AccountClock` from `@shivaedev/identity/server/account-clock/service.ts` is a
|
|
159
|
+
`AccountClock` from `@shivaedev/identity/server/account-clock/service.ts` answers which logical day it is for any account. It is a global service: its Layer requires `AccountPreferencesStore` and `AccountDayStart`, not `Subject`, and each call reads the named account's saved timezone, so a request, a roster of many accounts, an RPC without a subject and a worker job use the same clock. Register its Layer once in global `services`, beside the store it reads. Configure `AccountDayStart` from `@shivaedev/identity/server/account-clock/settings.ts` in minutes after local midnight; it defaults to zero and accepts integers from 0 through 1439. The same module exports `LogicalDay`.
|
|
160
160
|
|
|
161
161
|
```ts
|
|
162
|
-
import {
|
|
162
|
+
import { Effect, Layer } from "effect";
|
|
163
|
+
import { Migrator } from "effect/sql";
|
|
164
|
+
import { AccountPreferences } from "@shivaedev/identity/AccountPreferences.ts";
|
|
163
165
|
import { AccountClock } from "@shivaedev/identity/server/account-clock/service.ts";
|
|
164
166
|
import { AccountDayStart } from "@shivaedev/identity/server/account-clock/settings.ts";
|
|
167
|
+
import { accountPreferencesStore } from "@shivaedev/identity/server/account-preferences/store.ts";
|
|
168
|
+
import { accountPreferencesMigration } from "@shivaedev/identity/server/accountPreferencesMigration.ts";
|
|
169
|
+
import { Subject } from "@shivaedev/identity/subject.ts";
|
|
170
|
+
import type { AppModule } from "@shivaedev/server/AppModule.ts";
|
|
171
|
+
|
|
172
|
+
export const preferencesModule = {
|
|
173
|
+
migrations: { loader: Migrator.fromRecord({ "0005_account_preferences": accountPreferencesMigration }) },
|
|
174
|
+
module: AccountPreferences,
|
|
175
|
+
services: AccountClock.layer.pipe(Layer.provide(Layer.succeed(AccountDayStart, 240)), Layer.provideMerge(accountPreferencesStore)),
|
|
176
|
+
} satisfies AppModule;
|
|
165
177
|
|
|
166
|
-
export const requestServices = AccountClock.layer.pipe(Layer.provide(Layer.succeed(AccountDayStart, 240)), Layer.orDie);
|
|
167
178
|
const today = Effect.gen(function* () {
|
|
168
179
|
const clock = yield* AccountClock;
|
|
169
|
-
const
|
|
170
|
-
return yield* clock.dayRange(
|
|
180
|
+
const account = (yield* Subject).id;
|
|
181
|
+
return yield* clock.dayRange(account, yield* clock.logicalDay(account));
|
|
171
182
|
});
|
|
172
183
|
```
|
|
173
184
|
|
|
174
|
-
|
|
185
|
+
The registration provides the store to the clock and to the module's operations at once. A self read passes `(yield* Subject).id`, a read that already takes its owner passes that id, and a roster asks once per account. Each call that cannot read the account's preferences fails with `AuthUnavailable`, in the call's own error channel, and `dayRange` also fails with `SchemaError` when `day` is not an ISO calendar date. A contract's subject or identity middleware already declares `AuthUnavailable`; a native query without either declares `rejections: { AuthUnavailable }`.
|
|
175
186
|
|
|
176
|
-
`logicalDay(instant)` returns
|
|
187
|
+
`logicalDay(account, instant)` returns the account's ISO calendar date; omitting the instant uses Effect's current clock. An account without saved preferences reads `UTC`. `dayRange(account, day)` returns UTC `DateTime` values `{ start, end }`, with an inclusive start and exclusive end. Endpoints are constructed separately in local calendar time: a 04:00 New York day spanning spring DST lasts 23 hours, and one spanning autumn DST lasts 25 hours. The exact boundary belongs to the new logical day. Applications use `timestamp >= start && timestamp < end` when grouping records. Day starts within a DST gap use Effect's compatible disambiguation (later in a gap, earlier in an overlap).
|
|
177
188
|
|
|
178
189
|
### Once per application: contracts and session policy
|
|
179
190
|
|
|
@@ -1126,7 +1137,7 @@ A failing hand-over, a failing erase or a failing auth delete rolls everything b
|
|
|
1126
1137
|
|
|
1127
1138
|
The mount closes Better Auth's `/delete-user` and `/delete-user/callback`, even when the options enable `user.deleteUser`, and the admin plugin's `/admin/remove-user`, so this command is the one HTTP route that deletes an account. Better Auth deletes outside any transaction and erases no owned rows, and its `user.delete.before` hooks do not run here: move such a hook's body into the hand-over. Server code that calls Better Auth's `auth.api` directly is not covered by the closed routes.
|
|
1128
1139
|
|
|
1129
|
-
The deletion reads and writes Better Auth's tables through the application's SQL client.
|
|
1140
|
+
The deletion reads and writes Better Auth's tables through the application's SQL client. Once it commits, none of the person's sessions resolves a `SessionUser`, with sessions in the database, in Better Auth's cookie cache or in `secondaryStorage`, with or without `storeSessionInDatabase`. Their database sessions go with the user row, and identity resolves every request past the cookie cache. With `secondaryStorage`, the last step inside the transaction makes the same writes Better Auth makes when it revokes a user's sessions there: it records the revocation time Better Auth's session lookup checks, which alone ends every session created before the deletion, and deletes the sessions the store lists for the person, whether its client returns that list as JSON text or already parsed. It also deletes the `email-verification`, `sign-in` and `forget-password` codes of their exact address there; a password-reset token, change-email or two-factor code kept in `secondaryStorage` is keyed by what only the email holds, so it stays until it expires and names an id that no longer exists. Better Auth's own `/get-session` route still answers from the cookie cache until it expires when the declaration states no roles, so a browser session check can report the person signed in while every request is refused. Accounts that sign in only through a provider have no password to confirm with and are refused.
|
|
1130
1141
|
|
|
1131
1142
|
### Signed-in story preconditions
|
|
1132
1143
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { DateTime, Effect } from "effect";
|
|
2
|
-
export declare const boundary: (day: string,
|
|
2
|
+
export declare const boundary: (day: string, timeZone: DateTime.TimeZone, minutes: number) => Effect.Effect<DateTime.Utc, never, never>;
|
|
3
3
|
//# sourceMappingURL=boundary.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE1C,eAAO,MAAM,QAAQ
|
|
1
|
+
{"version":3,"file":"boundary.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE1C,eAAO,MAAM,QAAQ,0GAUpB,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DateTime, Effect } from "effect";
|
|
2
|
-
export const boundary = Effect.fn("AccountClock.boundary")((day,
|
|
2
|
+
export const boundary = Effect.fn("AccountClock.boundary")((day, timeZone, minutes) => Effect.sync(() => DateTime.toUtc(DateTime.makeZonedUnsafe(`${day}T00:00:00.000Z`, {
|
|
3
3
|
adjustForTimeZone: true,
|
|
4
4
|
disambiguation: "compatible",
|
|
5
|
-
timeZone
|
|
5
|
+
timeZone,
|
|
6
6
|
}).pipe(DateTime.setParts({ hour: Math.floor(minutes / 60), minute: minutes % 60 })))));
|
|
7
7
|
//# sourceMappingURL=boundary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundary.js","sourceRoot":"","sources":["../../../src/server/account-clock/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE1C,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC,uBAAuB,CAAC,CAAC,CAAC,GAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"boundary.js","sourceRoot":"","sources":["../../../src/server/account-clock/boundary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE1C,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAC,uBAAuB,CAAC,CAAC,CAAC,GAAW,EAAE,QAA2B,EAAE,OAAe,EAAE,EAAE,CACxH,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAChB,QAAQ,CAAC,KAAK,CACb,QAAQ,CAAC,eAAe,CAAC,GAAG,GAAG,gBAAgB,EAAE;IAChD,iBAAiB,EAAE,IAAI;IACvB,cAAc,EAAE,YAAY;IAC5B,QAAQ;CACR,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,EAAE,EAAE,CAAC,CAAC,CACpF,CACD,CACD,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DateTime, Effect, Schema } from "effect";
|
|
2
|
-
|
|
3
|
-
export declare function dayRange({ minutes, timezone }: Effect.Success<typeof initialize>): (day: string) => Effect.Effect<{
|
|
2
|
+
export declare function dayRange(minutes: number): (account: string, day: string) => Effect.Effect<{
|
|
4
3
|
end: DateTime.Utc;
|
|
5
4
|
start: DateTime.Utc;
|
|
6
|
-
}, Schema.SchemaError,
|
|
5
|
+
}, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | Schema.SchemaError, "@shivaedev/identity/AccountPreferencesStore">;
|
|
7
6
|
//# sourceMappingURL=dayRange.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dayRange.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/dayRange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"dayRange.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/dayRange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAOlD,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM;;;gIAMvC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { DateTime, Effect, Schema } from "effect";
|
|
2
2
|
import { boundary } from "#server/account-clock/boundary.ts";
|
|
3
3
|
import { LogicalDay } from "#server/account-clock/settings.ts";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { zone } from "#server/account-clock/zone.ts";
|
|
5
|
+
const decodeDay = Schema.decodeUnknownEffect(LogicalDay.pipe(Schema.decodeTo(Schema.DateTimeUtcFromString)));
|
|
6
|
+
export function dayRange(minutes) {
|
|
7
|
+
return Effect.fn("AccountClock.dayRange")(function* (account, day) {
|
|
7
8
|
const next = DateTime.formatIsoDateUtc(DateTime.add(yield* decodeDay(day), { days: 1 }));
|
|
8
|
-
|
|
9
|
+
const timeZone = yield* zone(account);
|
|
10
|
+
return { end: yield* boundary(next, timeZone, minutes), start: yield* boundary(day, timeZone, minutes) };
|
|
9
11
|
});
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=dayRange.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dayRange.js","sourceRoot":"","sources":["../../../src/server/account-clock/dayRange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"dayRange.js","sourceRoot":"","sources":["../../../src/server/account-clock/dayRange.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,MAAM,SAAS,GAAG,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;AAE7G,MAAM,UAAU,QAAQ,CAAC,OAAe;IACvC,OAAO,MAAM,CAAC,EAAE,CAAC,uBAAuB,CAAC,CAAC,QAAQ,CAAC,EAAE,OAAe,EAAE,GAAW;QAChF,MAAM,IAAI,GAAG,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACzF,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtC,OAAO,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC;IAC1G,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
|
-
|
|
3
|
-
export declare const initialize: Effect.Effect<{
|
|
4
|
-
minutes: number;
|
|
5
|
-
timezone: string;
|
|
6
|
-
zone: import("effect/DateTime").TimeZone.Named;
|
|
7
|
-
}, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | Schema.SchemaError, "@shivaedev/identity/AccountPreferencesStore" | Subject>;
|
|
2
|
+
export declare const initialize: Effect.Effect<number, Schema.SchemaError, never>;
|
|
8
3
|
//# sourceMappingURL=initialize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGxC,
|
|
1
|
+
{"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGxC,eAAO,MAAM,UAAU,kDAAwE,CAAC"}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { AccountDayStart, DayStart } from "#server/account-clock/settings.ts";
|
|
3
|
-
|
|
4
|
-
import { Subject } from "#subject.ts";
|
|
5
|
-
export const initialize = Effect.gen(function* () {
|
|
6
|
-
const { id } = yield* Subject;
|
|
7
|
-
const { timezone } = yield* (yield* AccountPreferencesStore).get(id);
|
|
8
|
-
const minutes = yield* Schema.decodeUnknownEffect(DayStart)(yield* AccountDayStart);
|
|
9
|
-
const zone = yield* Schema.decodeUnknownEffect(Schema.TimeZoneNamedFromString)(timezone);
|
|
10
|
-
return { minutes, timezone, zone };
|
|
11
|
-
});
|
|
3
|
+
export const initialize = Effect.flatMap(AccountDayStart, Schema.decodeUnknownEffect(DayStart));
|
|
12
4
|
//# sourceMappingURL=initialize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../src/server/account-clock/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../src/server/account-clock/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAE9E,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { DateTime, Effect } from "effect";
|
|
2
|
-
|
|
3
|
-
export declare function logicalDay({ minutes, timezone, zone }: Effect.Success<typeof initialize>): (instant?: DateTime.Utc | undefined) => Effect.Effect<string, never, never>;
|
|
2
|
+
export declare function logicalDay(minutes: number): (account: string, instant?: DateTime.Utc | undefined) => Effect.Effect<string, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, "@shivaedev/identity/AccountPreferencesStore">;
|
|
4
3
|
//# sourceMappingURL=logicalDay.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logicalDay.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/logicalDay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"logicalDay.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/logicalDay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAI1C,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,0LAQzC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { DateTime, Effect } from "effect";
|
|
2
2
|
import { boundary } from "#server/account-clock/boundary.ts";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { zone } from "#server/account-clock/zone.ts";
|
|
4
|
+
export function logicalDay(minutes) {
|
|
5
|
+
return Effect.fn("AccountClock.logicalDay")(function* (account, instant) {
|
|
5
6
|
const now = instant ?? (yield* DateTime.now);
|
|
6
|
-
const
|
|
7
|
+
const timeZone = yield* zone(account);
|
|
8
|
+
const local = DateTime.setZone(now, timeZone);
|
|
7
9
|
const day = DateTime.formatIsoDate(local);
|
|
8
|
-
return DateTime.isLessThan(now, yield* boundary(day,
|
|
10
|
+
return DateTime.isLessThan(now, yield* boundary(day, timeZone, minutes)) ? DateTime.formatIsoDate(DateTime.subtract(local, { days: 1 })) : day;
|
|
9
11
|
});
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=logicalDay.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logicalDay.js","sourceRoot":"","sources":["../../../src/server/account-clock/logicalDay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"logicalDay.js","sourceRoot":"","sources":["../../../src/server/account-clock/logicalDay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAErD,MAAM,UAAU,UAAU,CAAC,OAAe;IACzC,OAAO,MAAM,CAAC,EAAE,CAAC,yBAAyB,CAAC,CAAC,QAAQ,CAAC,EAAE,OAAe,EAAE,OAAsB;QAC7F,MAAM,GAAG,GAAG,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC7C,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACtC,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QAC9C,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1C,OAAO,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAChJ,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { Subject } from "#subject.ts";
|
|
2
1
|
export declare const AccountClock: import("effect/Context").Service<"@shivaedev/identity/AccountClock", Readonly<{
|
|
3
|
-
readonly dayRange: (day: string) => import("effect/Effect").Effect<{
|
|
2
|
+
readonly dayRange: (account: string, day: string) => import("effect/Effect").Effect<{
|
|
4
3
|
end: import("effect/DateTime").Utc;
|
|
5
4
|
start: import("effect/DateTime").Utc;
|
|
6
|
-
}, import("effect/Schema").SchemaError, never>;
|
|
7
|
-
readonly logicalDay: (instant?: import("effect/DateTime").Utc | undefined) => import("effect/Effect").Effect<string,
|
|
5
|
+
}, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("effect/Schema").SchemaError, never>;
|
|
6
|
+
readonly logicalDay: (account: string, instant?: import("effect/DateTime").Utc | undefined) => import("effect/Effect").Effect<string, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
|
|
8
7
|
}>> & {
|
|
9
|
-
readonly layer: import("effect/Layer").Layer<"@shivaedev/identity/AccountClock", import("
|
|
8
|
+
readonly layer: import("effect/Layer").Layer<"@shivaedev/identity/AccountClock", import("effect/Schema").SchemaError, "@shivaedev/identity/AccountPreferencesStore">;
|
|
10
9
|
};
|
|
11
10
|
//# sourceMappingURL=service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/service.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY;;;;;;;;CAKvB,CAAC"}
|
|
@@ -4,11 +4,10 @@ import { initialize } from "#server/account-clock/initialize.ts";
|
|
|
4
4
|
import { logicalDay } from "#server/account-clock/logicalDay.ts";
|
|
5
5
|
import { AccountDayStart } from "#server/account-clock/settings.ts";
|
|
6
6
|
import { AccountPreferencesStore } from "#server/account-preferences/service.ts";
|
|
7
|
-
import { Subject } from "#subject.ts";
|
|
8
7
|
export const AccountClock = defineService({
|
|
9
8
|
id: "@shivaedev/identity/AccountClock",
|
|
10
9
|
initialize,
|
|
11
|
-
methods: (
|
|
12
|
-
requires: [AccountPreferencesStore,
|
|
10
|
+
methods: (minutes) => ({ dayRange: dayRange(minutes), logicalDay: logicalDay(minutes) }),
|
|
11
|
+
requires: [AccountPreferencesStore, AccountDayStart],
|
|
13
12
|
});
|
|
14
13
|
//# sourceMappingURL=service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/server/account-clock/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/server/account-clock/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEjF,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC;IACzC,EAAE,EAAE,kCAAkC;IACtC,UAAU;IACV,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;IACxF,QAAQ,EAAE,CAAC,uBAAuB,EAAE,eAAe,CAAC;CACpD,CAAC,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
export declare const zone: (account: string) => Effect.Effect<import("effect/DateTime").TimeZone.Named, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, "@shivaedev/identity/AccountPreferencesStore">;
|
|
3
|
+
//# sourceMappingURL=zone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zone.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/zone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAGxC,eAAO,MAAM,IAAI,sLAIf,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { AccountPreferencesStore } from "#server/account-preferences/service.ts";
|
|
3
|
+
export const zone = Effect.fn("AccountClock.zone")(function* (account) {
|
|
4
|
+
const { timezone } = yield* (yield* AccountPreferencesStore).get(account);
|
|
5
|
+
// The store returns only timezones its row schema has checked, so a timezone that does not decode here is a broken invariant.
|
|
6
|
+
return yield* Schema.decodeUnknownEffect(Schema.TimeZoneNamedFromString)(timezone).pipe(Effect.orDie);
|
|
7
|
+
});
|
|
8
|
+
//# sourceMappingURL=zone.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zone.js","sourceRoot":"","sources":["../../../src/server/account-clock/zone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEjF,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC,EAAE,CAAC,mBAAmB,CAAC,CAAC,QAAQ,CAAC,EAAE,OAAe;IAC5E,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,uBAAuB,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC1E,8HAA8H;IAC9H,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACvG,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { BetterAuthOptions } from "better-auth";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
export declare const evictCachedAccount: (options: Omit<BetterAuthOptions, "database">, user: {
|
|
4
|
+
readonly email: string;
|
|
5
|
+
readonly id: string;
|
|
6
|
+
}) => Effect.Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
|
|
7
|
+
//# sourceMappingURL=evictCachedAccount.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evictCachedAccount.d.ts","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/evictCachedAccount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAS,MAAM,EAAU,MAAM,QAAQ,CAAC;AAW/C,eAAO,MAAM,kBAAkB;oBAEN,MAAM;iBAAe,MAAM;yFA0BlD,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Clock, Effect, Schema } from "effect";
|
|
2
|
+
import { providerFailure } from "#server/providerFailure.ts";
|
|
3
|
+
const References = Schema.Array(Schema.Struct({ token: Schema.String }));
|
|
4
|
+
// Better Auth reads the list through safeJSONParse, which takes a JSON string or a value the store's client already parsed.
|
|
5
|
+
const StoredReferences = Schema.Union([Schema.fromJsonString(References), References]);
|
|
6
|
+
const ADDRESS_CODES = ["email-verification", "sign-in", "forget-password"];
|
|
7
|
+
// Better Auth 1.7 keeps these keys in secondary storage and revokes a user's sessions with the same writes in deleteCachedUserSessions:
|
|
8
|
+
// a revoked-before time its session lookup checks, and the tokens listed as the user's active sessions. Its other codes are keyed by
|
|
9
|
+
// a token or a new address that only the email holds, so only the exact address codes can be found here.
|
|
10
|
+
export const evictCachedAccount = Effect.fn("Identity.evictCachedAccount")(function* (options, user) {
|
|
11
|
+
const storage = options.secondaryStorage;
|
|
12
|
+
if (storage === undefined) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
function call(run) {
|
|
16
|
+
return Effect.tryPromise(async () => await run()).pipe(Effect.catch(providerFailure));
|
|
17
|
+
}
|
|
18
|
+
const revokedKey = `revoked-sessions-before-${user.id}`;
|
|
19
|
+
const activeKey = `active-sessions-${user.id}`;
|
|
20
|
+
const lifetime = Math.max(options.session?.expiresIn || 604_800, 86_400);
|
|
21
|
+
const now = yield* Clock.currentTimeMillis;
|
|
22
|
+
const previous = Number(yield* call(() => storage.get(revokedKey))) || 0;
|
|
23
|
+
yield* call(() => storage.set(revokedKey, String(Math.max(now, previous)), lifetime));
|
|
24
|
+
const listed = yield* call(() => storage.get(activeKey));
|
|
25
|
+
const references = yield* Schema.decodeUnknownEffect(StoredReferences)(listed).pipe(Effect.orElseSucceed(() => []));
|
|
26
|
+
for (const { token } of references) {
|
|
27
|
+
yield* call(() => storage.delete(token));
|
|
28
|
+
}
|
|
29
|
+
yield* call(() => storage.delete(activeKey));
|
|
30
|
+
if (options.verification?.storeInDatabase !== true) {
|
|
31
|
+
for (const type of ADDRESS_CODES) {
|
|
32
|
+
yield* call(() => storage.delete(`verification:${type}-otp-${user.email}`));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
//# sourceMappingURL=evictCachedAccount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evictCachedAccount.js","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/evictCachedAccount.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AACzE,4HAA4H;AAC5H,MAAM,gBAAgB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;AACvF,MAAM,aAAa,GAAG,CAAC,oBAAoB,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC;AAE3E,wIAAwI;AACxI,qIAAqI;AACrI,yGAAyG;AACzG,MAAM,CAAC,MAAM,kBAAkB,GAAG,MA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gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IACpH,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,UAAU,EAAE,CAAC;QACpC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC1C,CAAC;IACD,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IAC7C,IAAI,OAAO,CAAC,YAAY,EAAE,eAAe,KAAK,IAAI,EAAE,CAAC;QACpD,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;YAClC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,IAAI,QAAQ,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC7E,CAAC;IACF,CAAC;AACF,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteAccount.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/deleteAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;
|
|
1
|
+
{"version":3,"file":"deleteAccount.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/deleteAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAUrF,eAAO,MAAM,aAAa,4kBAexB,CAAC"}
|
|
@@ -5,11 +5,13 @@ import { invalidateOnCommit, transact } from "@shivaedev/sql/transact.ts";
|
|
|
5
5
|
import { SessionUser } from "#identity.ts";
|
|
6
6
|
import { AccountDeletionPolicy } from "#server/better-auth/AccountDeletionPolicy.ts";
|
|
7
7
|
import { accountData } from "#server/better-auth/accountData.ts";
|
|
8
|
+
import { evictCachedAccount } from "#server/better-auth/adapters/evictCachedAccount.ts";
|
|
8
9
|
import { confirmPassword } from "#server/better-auth/confirmPassword.ts";
|
|
9
10
|
import { deleteUserRows } from "#server/better-auth/deleteUserRows.ts";
|
|
10
11
|
import { sessionKeys } from "#signedInSessions.ts";
|
|
11
12
|
import { userKeys } from "#users.ts";
|
|
12
13
|
// An erase that cannot run is the operator's to fix, so its failure is reported with its tables rather than answered to the person.
|
|
14
|
+
// Cached sessions are evicted last inside the transaction, so a failed eviction deletes nothing and a failed commit only signs out.
|
|
13
15
|
export const deleteAccount = Effect.fn("Identity.deleteAccount")(function* (password) {
|
|
14
16
|
const { id } = yield* SessionUser;
|
|
15
17
|
const { auth, handOver } = yield* AccountDeletionPolicy;
|
|
@@ -22,6 +24,7 @@ export const deleteAccount = Effect.fn("Identity.deleteAccount")(function* (pass
|
|
|
22
24
|
.eraseOwnedRows(id)
|
|
23
25
|
.pipe(Effect.catchTags({ OwnedModelsUncollected: Effect.die, OwnedTableCycle: Effect.die, UncoveredUserColumns: Effect.die }));
|
|
24
26
|
yield* deleteUserRows(auth.options);
|
|
27
|
+
yield* evictCachedAccount(auth.options, yield* SessionUser);
|
|
25
28
|
yield* invalidateOnCommit(invalidationKeys([userKeys.item(id), sessionKeys.list]));
|
|
26
29
|
}).pipe(transact());
|
|
27
30
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteAccount.js","sourceRoot":"","sources":["../../../src/server/better-auth/deleteAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ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AC,CAAC;AACrB,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteUserRows.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/deleteUserRows.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"deleteUserRows.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/deleteUserRows.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAO3C,eAAO,MAAM,cAAc,gIAYzB,CAAC"}
|
|
@@ -2,7 +2,8 @@ import { getAuthTables } from "better-auth/db";
|
|
|
2
2
|
import { Effect } from "effect";
|
|
3
3
|
import { SqlClient } from "effect/sql";
|
|
4
4
|
import { SessionUser } from "#identity.ts";
|
|
5
|
-
// Better Auth's session and account tables cascade from the user row, so one delete removes the person's sign-ins with it.
|
|
5
|
+
// Better Auth's session and account tables cascade from the user row, so one delete removes the person's sign-ins with it. It keeps
|
|
6
|
+
// no verification table when verifications live in secondary storage.
|
|
6
7
|
// Verification rows carry no key to the user, so these are the exact identifiers Better Auth 1.7 writes for one person: the user id
|
|
7
8
|
// as a reset or deletion token's value, the address in an email code's identifier, and the id leading a change-email or two-factor code's.
|
|
8
9
|
const ADDRESS_CODES = ["email-verification", "sign-in", "forget-password"];
|
|
@@ -13,8 +14,10 @@ export const deleteUserRows = Effect.fn("Identity.deleteUserRows")(function* (op
|
|
|
13
14
|
const identifier = sql(verification?.fields.identifier?.fieldName ?? "identifier");
|
|
14
15
|
const value = sql(verification?.fields.value?.fieldName ?? "value");
|
|
15
16
|
const codes = ADDRESS_CODES.map((type) => `${type}-otp-${email}`);
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
if (verification !== undefined) {
|
|
18
|
+
yield* sql `delete from ${sql(verification.modelName)} where ${value} = ${id} or ${identifier} in ${sql.in(codes)}
|
|
19
|
+
or starts_with(${identifier}, ${`change-email-otp-${id}:`}) or starts_with(${identifier}, ${`2fa-otp-${id}!`})`;
|
|
20
|
+
}
|
|
18
21
|
yield* sql `delete from ${sql(user?.modelName ?? "user")} where id = ${id}`;
|
|
19
22
|
});
|
|
20
23
|
//# sourceMappingURL=deleteUserRows.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteUserRows.js","sourceRoot":"","sources":["../../../src/server/better-auth/deleteUserRows.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,
|
|
1
|
+
{"version":3,"file":"deleteUserRows.js","sourceRoot":"","sources":["../../../src/server/better-auth/deleteUserRows.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,oIAAoI;AACpI,sEAAsE;AACtE,oIAAoI;AACpI,2IAA2I;AAC3I,MAAM,aAAa,GAAG,CAAC,oBAAoB,EAAE,SAAS,EAAE,iBAAiB,C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|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.1",
|
|
4
4
|
"description": "Request identity, sessions, transport trust and permission enforcement for Effect RPC servers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@shivaedev/access": "0.7.0",
|
|
50
50
|
"@shivaedev/changes": "0.14.1",
|
|
51
|
-
"@shivaedev/contract": "0.
|
|
51
|
+
"@shivaedev/contract": "0.59.0",
|
|
52
52
|
"@shivaedev/errors": "0.14.1",
|
|
53
53
|
"@shivaedev/rate-limit": "0.8.1",
|
|
54
54
|
"@shivaedev/service": "0.9.2",
|
|
@@ -58,13 +58,13 @@
|
|
|
58
58
|
"@better-auth/oauth-provider": "1.7.23",
|
|
59
59
|
"@effect/platform-node": "4.1.4",
|
|
60
60
|
"@effect/sql-pg": "4.1.4",
|
|
61
|
-
"@shivaedev/admin": "0.29.
|
|
62
|
-
"@shivaedev/build": "0.
|
|
63
|
-
"@shivaedev/quality": "0.84.
|
|
64
|
-
"@shivaedev/server": "0.46.
|
|
65
|
-
"@shivaedev/test-kits": "0.16.
|
|
61
|
+
"@shivaedev/admin": "0.29.8",
|
|
62
|
+
"@shivaedev/build": "0.10.0",
|
|
63
|
+
"@shivaedev/quality": "0.84.2",
|
|
64
|
+
"@shivaedev/server": "0.46.2",
|
|
65
|
+
"@shivaedev/test-kits": "0.16.12",
|
|
66
66
|
"@shivaedev/test-sql": "0.26.1",
|
|
67
|
-
"@shivaedev/test-story": "0.52.
|
|
67
|
+
"@shivaedev/test-story": "0.52.6",
|
|
68
68
|
"@types/node": "24.19.2",
|
|
69
69
|
"better-auth": "1.7.23",
|
|
70
70
|
"effect": "4.1.4",
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { DateTime, Effect } from "effect";
|
|
2
2
|
|
|
3
|
-
export const boundary = Effect.fn("AccountClock.boundary")((day: string,
|
|
3
|
+
export const boundary = Effect.fn("AccountClock.boundary")((day: string, timeZone: DateTime.TimeZone, minutes: number) =>
|
|
4
4
|
Effect.sync(() =>
|
|
5
5
|
DateTime.toUtc(
|
|
6
6
|
DateTime.makeZonedUnsafe(`${day}T00:00:00.000Z`, {
|
|
7
7
|
adjustForTimeZone: true,
|
|
8
8
|
disambiguation: "compatible",
|
|
9
|
-
timeZone
|
|
9
|
+
timeZone,
|
|
10
10
|
}).pipe(DateTime.setParts({ hour: Math.floor(minutes / 60), minute: minutes % 60 })),
|
|
11
11
|
),
|
|
12
12
|
),
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { DateTime, Effect, Schema } from "effect";
|
|
2
2
|
import { boundary } from "#server/account-clock/boundary.ts";
|
|
3
|
-
import type { initialize } from "#server/account-clock/initialize.ts";
|
|
4
3
|
import { LogicalDay } from "#server/account-clock/settings.ts";
|
|
4
|
+
import { zone } from "#server/account-clock/zone.ts";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const decodeDay = Schema.decodeUnknownEffect(LogicalDay.pipe(Schema.decodeTo(Schema.DateTimeUtcFromString)));
|
|
7
|
+
|
|
8
|
+
export function dayRange(minutes: number) {
|
|
9
|
+
return Effect.fn("AccountClock.dayRange")(function* (account: string, day: string) {
|
|
9
10
|
const next = DateTime.formatIsoDateUtc(DateTime.add(yield* decodeDay(day), { days: 1 }));
|
|
10
|
-
|
|
11
|
+
const timeZone = yield* zone(account);
|
|
12
|
+
return { end: yield* boundary(next, timeZone, minutes), start: yield* boundary(day, timeZone, minutes) };
|
|
11
13
|
});
|
|
12
14
|
}
|
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { AccountDayStart, DayStart } from "#server/account-clock/settings.ts";
|
|
3
|
-
import { AccountPreferencesStore } from "#server/account-preferences/service.ts";
|
|
4
|
-
import { Subject } from "#subject.ts";
|
|
5
3
|
|
|
6
|
-
export const initialize = Effect.
|
|
7
|
-
const { id } = yield* Subject;
|
|
8
|
-
const { timezone } = yield* (yield* AccountPreferencesStore).get(id);
|
|
9
|
-
const minutes = yield* Schema.decodeUnknownEffect(DayStart)(yield* AccountDayStart);
|
|
10
|
-
const zone = yield* Schema.decodeUnknownEffect(Schema.TimeZoneNamedFromString)(timezone);
|
|
11
|
-
return { minutes, timezone, zone };
|
|
12
|
-
});
|
|
4
|
+
export const initialize = Effect.flatMap(AccountDayStart, Schema.decodeUnknownEffect(DayStart));
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { DateTime, Effect } from "effect";
|
|
2
2
|
import { boundary } from "#server/account-clock/boundary.ts";
|
|
3
|
-
import
|
|
3
|
+
import { zone } from "#server/account-clock/zone.ts";
|
|
4
4
|
|
|
5
|
-
export function logicalDay(
|
|
6
|
-
return Effect.fn("AccountClock.logicalDay")(function* (instant?: DateTime.Utc) {
|
|
5
|
+
export function logicalDay(minutes: number) {
|
|
6
|
+
return Effect.fn("AccountClock.logicalDay")(function* (account: string, instant?: DateTime.Utc) {
|
|
7
7
|
const now = instant ?? (yield* DateTime.now);
|
|
8
|
-
const
|
|
8
|
+
const timeZone = yield* zone(account);
|
|
9
|
+
const local = DateTime.setZone(now, timeZone);
|
|
9
10
|
const day = DateTime.formatIsoDate(local);
|
|
10
|
-
return DateTime.isLessThan(now, yield* boundary(day,
|
|
11
|
+
return DateTime.isLessThan(now, yield* boundary(day, timeZone, minutes)) ? DateTime.formatIsoDate(DateTime.subtract(local, { days: 1 })) : day;
|
|
11
12
|
});
|
|
12
13
|
}
|
|
@@ -4,11 +4,10 @@ import { initialize } from "#server/account-clock/initialize.ts";
|
|
|
4
4
|
import { logicalDay } from "#server/account-clock/logicalDay.ts";
|
|
5
5
|
import { AccountDayStart } from "#server/account-clock/settings.ts";
|
|
6
6
|
import { AccountPreferencesStore } from "#server/account-preferences/service.ts";
|
|
7
|
-
import { Subject } from "#subject.ts";
|
|
8
7
|
|
|
9
8
|
export const AccountClock = defineService({
|
|
10
9
|
id: "@shivaedev/identity/AccountClock",
|
|
11
10
|
initialize,
|
|
12
|
-
methods: (
|
|
13
|
-
requires: [AccountPreferencesStore,
|
|
11
|
+
methods: (minutes) => ({ dayRange: dayRange(minutes), logicalDay: logicalDay(minutes) }),
|
|
12
|
+
requires: [AccountPreferencesStore, AccountDayStart],
|
|
14
13
|
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { AccountPreferencesStore } from "#server/account-preferences/service.ts";
|
|
3
|
+
|
|
4
|
+
export const zone = Effect.fn("AccountClock.zone")(function* (account: string) {
|
|
5
|
+
const { timezone } = yield* (yield* AccountPreferencesStore).get(account);
|
|
6
|
+
// The store returns only timezones its row schema has checked, so a timezone that does not decode here is a broken invariant.
|
|
7
|
+
return yield* Schema.decodeUnknownEffect(Schema.TimeZoneNamedFromString)(timezone).pipe(Effect.orDie);
|
|
8
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { BetterAuthOptions } from "better-auth";
|
|
2
|
+
import { Clock, Effect, Schema } from "effect";
|
|
3
|
+
import { providerFailure } from "#server/providerFailure.ts";
|
|
4
|
+
|
|
5
|
+
const References = Schema.Array(Schema.Struct({ token: Schema.String }));
|
|
6
|
+
// Better Auth reads the list through safeJSONParse, which takes a JSON string or a value the store's client already parsed.
|
|
7
|
+
const StoredReferences = Schema.Union([Schema.fromJsonString(References), References]);
|
|
8
|
+
const ADDRESS_CODES = ["email-verification", "sign-in", "forget-password"];
|
|
9
|
+
|
|
10
|
+
// Better Auth 1.7 keeps these keys in secondary storage and revokes a user's sessions with the same writes in deleteCachedUserSessions:
|
|
11
|
+
// a revoked-before time its session lookup checks, and the tokens listed as the user's active sessions. Its other codes are keyed by
|
|
12
|
+
// a token or a new address that only the email holds, so only the exact address codes can be found here.
|
|
13
|
+
export const evictCachedAccount = Effect.fn("Identity.evictCachedAccount")(function* (
|
|
14
|
+
options: Omit<BetterAuthOptions, "database">,
|
|
15
|
+
user: { readonly email: string; readonly id: string },
|
|
16
|
+
) {
|
|
17
|
+
const storage = options.secondaryStorage;
|
|
18
|
+
if (storage === undefined) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
function call<A>(run: () => A | Promise<A>) {
|
|
22
|
+
return Effect.tryPromise(async () => await run()).pipe(Effect.catch(providerFailure));
|
|
23
|
+
}
|
|
24
|
+
const revokedKey = `revoked-sessions-before-${user.id}`;
|
|
25
|
+
const activeKey = `active-sessions-${user.id}`;
|
|
26
|
+
const lifetime = Math.max(options.session?.expiresIn || 604_800, 86_400);
|
|
27
|
+
const now = yield* Clock.currentTimeMillis;
|
|
28
|
+
const previous = Number(yield* call(() => storage.get(revokedKey))) || 0;
|
|
29
|
+
yield* call(() => storage.set(revokedKey, String(Math.max(now, previous)), lifetime));
|
|
30
|
+
const listed = yield* call(() => storage.get(activeKey));
|
|
31
|
+
const references = yield* Schema.decodeUnknownEffect(StoredReferences)(listed).pipe(Effect.orElseSucceed(() => []));
|
|
32
|
+
for (const { token } of references) {
|
|
33
|
+
yield* call(() => storage.delete(token));
|
|
34
|
+
}
|
|
35
|
+
yield* call(() => storage.delete(activeKey));
|
|
36
|
+
if (options.verification?.storeInDatabase !== true) {
|
|
37
|
+
for (const type of ADDRESS_CODES) {
|
|
38
|
+
yield* call(() => storage.delete(`verification:${type}-otp-${user.email}`));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
});
|
|
@@ -5,12 +5,14 @@ import { invalidateOnCommit, transact } from "@shivaedev/sql/transact.ts";
|
|
|
5
5
|
import { SessionUser } from "#identity.ts";
|
|
6
6
|
import { AccountDeletionPolicy } from "#server/better-auth/AccountDeletionPolicy.ts";
|
|
7
7
|
import { accountData } from "#server/better-auth/accountData.ts";
|
|
8
|
+
import { evictCachedAccount } from "#server/better-auth/adapters/evictCachedAccount.ts";
|
|
8
9
|
import { confirmPassword } from "#server/better-auth/confirmPassword.ts";
|
|
9
10
|
import { deleteUserRows } from "#server/better-auth/deleteUserRows.ts";
|
|
10
11
|
import { sessionKeys } from "#signedInSessions.ts";
|
|
11
12
|
import { userKeys } from "#users.ts";
|
|
12
13
|
|
|
13
14
|
// An erase that cannot run is the operator's to fix, so its failure is reported with its tables rather than answered to the person.
|
|
15
|
+
// Cached sessions are evicted last inside the transaction, so a failed eviction deletes nothing and a failed commit only signs out.
|
|
14
16
|
export const deleteAccount = Effect.fn("Identity.deleteAccount")(function* (password: string) {
|
|
15
17
|
const { id } = yield* SessionUser;
|
|
16
18
|
const { auth, handOver } = yield* AccountDeletionPolicy;
|
|
@@ -23,6 +25,7 @@ export const deleteAccount = Effect.fn("Identity.deleteAccount")(function* (pass
|
|
|
23
25
|
.eraseOwnedRows(id)
|
|
24
26
|
.pipe(Effect.catchTags({ OwnedModelsUncollected: Effect.die, OwnedTableCycle: Effect.die, UncoveredUserColumns: Effect.die }));
|
|
25
27
|
yield* deleteUserRows(auth.options);
|
|
28
|
+
yield* evictCachedAccount(auth.options, yield* SessionUser);
|
|
26
29
|
yield* invalidateOnCommit(invalidationKeys([userKeys.item(id), sessionKeys.list]));
|
|
27
30
|
}).pipe(transact());
|
|
28
31
|
});
|
|
@@ -4,7 +4,8 @@ import { Effect } from "effect";
|
|
|
4
4
|
import { SqlClient } from "effect/sql";
|
|
5
5
|
import { SessionUser } from "#identity.ts";
|
|
6
6
|
|
|
7
|
-
// Better Auth's session and account tables cascade from the user row, so one delete removes the person's sign-ins with it.
|
|
7
|
+
// Better Auth's session and account tables cascade from the user row, so one delete removes the person's sign-ins with it. It keeps
|
|
8
|
+
// no verification table when verifications live in secondary storage.
|
|
8
9
|
// Verification rows carry no key to the user, so these are the exact identifiers Better Auth 1.7 writes for one person: the user id
|
|
9
10
|
// as a reset or deletion token's value, the address in an email code's identifier, and the id leading a change-email or two-factor code's.
|
|
10
11
|
const ADDRESS_CODES = ["email-verification", "sign-in", "forget-password"];
|
|
@@ -15,7 +16,9 @@ export const deleteUserRows = Effect.fn("Identity.deleteUserRows")(function* (op
|
|
|
15
16
|
const identifier = sql(verification?.fields.identifier?.fieldName ?? "identifier");
|
|
16
17
|
const value = sql(verification?.fields.value?.fieldName ?? "value");
|
|
17
18
|
const codes = ADDRESS_CODES.map((type) => `${type}-otp-${email}`);
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
if (verification !== undefined) {
|
|
20
|
+
yield* sql`delete from ${sql(verification.modelName)} where ${value} = ${id} or ${identifier} in ${sql.in(codes)}
|
|
21
|
+
or starts_with(${identifier}, ${`change-email-otp-${id}:`}) or starts_with(${identifier}, ${`2fa-otp-${id}!`})`;
|
|
22
|
+
}
|
|
20
23
|
yield* sql`delete from ${sql(user?.modelName ?? "user")} where id = ${id}`;
|
|
21
24
|
});
|