@shivaedev/identity 0.23.1 → 0.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +102 -2
  3. package/dist/accountPreferences.d.ts +112 -0
  4. package/dist/accountPreferences.d.ts.map +1 -0
  5. package/dist/accountPreferences.js +37 -0
  6. package/dist/accountPreferences.js.map +1 -0
  7. package/dist/server/AccountClock.d.ts +11 -0
  8. package/dist/server/AccountClock.d.ts.map +1 -0
  9. package/dist/server/AccountClock.js +14 -0
  10. package/dist/server/AccountClock.js.map +1 -0
  11. package/dist/server/AccountPreferencesStore.d.ts +25 -0
  12. package/dist/server/AccountPreferencesStore.d.ts.map +1 -0
  13. package/dist/server/AccountPreferencesStore.js +13 -0
  14. package/dist/server/AccountPreferencesStore.js.map +1 -0
  15. package/dist/server/UserProvisioning.d.ts +15 -0
  16. package/dist/server/UserProvisioning.d.ts.map +1 -0
  17. package/dist/server/UserProvisioning.js +4 -0
  18. package/dist/server/UserProvisioning.js.map +1 -0
  19. package/dist/server/account-clock/dayRange.d.ts +7 -0
  20. package/dist/server/account-clock/dayRange.d.ts.map +1 -0
  21. package/dist/server/account-clock/dayRange.js +11 -0
  22. package/dist/server/account-clock/dayRange.js.map +1 -0
  23. package/dist/server/account-clock/initialize.d.ts +7 -0
  24. package/dist/server/account-clock/initialize.d.ts.map +1 -0
  25. package/dist/server/account-clock/initialize.js +18 -0
  26. package/dist/server/account-clock/initialize.js.map +1 -0
  27. package/dist/server/account-clock/logicalDay.d.ts +4 -0
  28. package/dist/server/account-clock/logicalDay.d.ts.map +1 -0
  29. package/dist/server/account-clock/logicalDay.js +10 -0
  30. package/dist/server/account-clock/logicalDay.js.map +1 -0
  31. package/dist/server/account-clock/settings.d.ts +5 -0
  32. package/dist/server/account-clock/settings.d.ts.map +1 -0
  33. package/dist/server/account-clock/settings.js +8 -0
  34. package/dist/server/account-clock/settings.js.map +1 -0
  35. package/dist/server/account-export/check.d.ts +15 -0
  36. package/dist/server/account-export/check.d.ts.map +1 -0
  37. package/dist/server/account-export/check.js +33 -0
  38. package/dist/server/account-export/check.js.map +1 -0
  39. package/dist/server/account-preferences/capture.d.ts +8 -0
  40. package/dist/server/account-preferences/capture.d.ts.map +1 -0
  41. package/dist/server/account-preferences/capture.js +8 -0
  42. package/dist/server/account-preferences/capture.js.map +1 -0
  43. package/dist/server/account-preferences/get.d.ts +12 -0
  44. package/dist/server/account-preferences/get.d.ts.map +1 -0
  45. package/dist/server/account-preferences/get.js +8 -0
  46. package/dist/server/account-preferences/get.js.map +1 -0
  47. package/dist/server/account-preferences/initialize.d.ts +59 -0
  48. package/dist/server/account-preferences/initialize.d.ts.map +1 -0
  49. package/dist/server/account-preferences/initialize.js +16 -0
  50. package/dist/server/account-preferences/initialize.js.map +1 -0
  51. package/dist/server/account-preferences/set.d.ts +8 -0
  52. package/dist/server/account-preferences/set.d.ts.map +1 -0
  53. package/dist/server/account-preferences/set.js +10 -0
  54. package/dist/server/account-preferences/set.js.map +1 -0
  55. package/dist/server/accountExport.d.ts +14 -0
  56. package/dist/server/accountExport.d.ts.map +1 -0
  57. package/dist/server/accountExport.js +15 -0
  58. package/dist/server/accountExport.js.map +1 -0
  59. package/dist/server/accountPreferencesHandlers.d.ts +2 -0
  60. package/dist/server/accountPreferencesHandlers.d.ts.map +1 -0
  61. package/dist/server/accountPreferencesHandlers.js +19 -0
  62. package/dist/server/accountPreferencesHandlers.js.map +1 -0
  63. package/dist/server/adapters/accountPreferencesMigration.d.ts +4 -0
  64. package/dist/server/adapters/accountPreferencesMigration.d.ts.map +1 -0
  65. package/dist/server/adapters/accountPreferencesMigration.js +12 -0
  66. package/dist/server/adapters/accountPreferencesMigration.js.map +1 -0
  67. package/dist/server/better-auth/adapters/SeedOptions.d.ts +14 -0
  68. package/dist/server/better-auth/adapters/SeedOptions.d.ts.map +1 -0
  69. package/dist/server/better-auth/adapters/SeedOptions.js +2 -0
  70. package/dist/server/better-auth/adapters/SeedOptions.js.map +1 -0
  71. package/dist/server/better-auth/adapters/accountPreferenceOptions.d.ts +14 -0
  72. package/dist/server/better-auth/adapters/accountPreferenceOptions.d.ts.map +1 -0
  73. package/dist/server/better-auth/adapters/accountPreferenceOptions.js +32 -0
  74. package/dist/server/better-auth/adapters/accountPreferenceOptions.js.map +1 -0
  75. package/dist/server/better-auth/adapters/acquire.d.ts +37 -1
  76. package/dist/server/better-auth/adapters/acquire.d.ts.map +1 -1
  77. package/dist/server/better-auth/adapters/acquire.js +4 -1
  78. package/dist/server/better-auth/adapters/acquire.js.map +1 -1
  79. package/dist/server/better-auth/adapters/assertSeedDatabase.d.ts +10 -0
  80. package/dist/server/better-auth/adapters/assertSeedDatabase.d.ts.map +1 -0
  81. package/dist/server/better-auth/adapters/assertSeedDatabase.js +12 -0
  82. package/dist/server/better-auth/adapters/assertSeedDatabase.js.map +1 -0
  83. package/dist/server/better-auth/adapters/defineSeed.d.ts +4 -0
  84. package/dist/server/better-auth/adapters/defineSeed.d.ts.map +1 -0
  85. package/dist/server/better-auth/adapters/defineSeed.js +19 -0
  86. package/dist/server/better-auth/adapters/defineSeed.js.map +1 -0
  87. package/dist/server/better-auth/adapters/emailOptions.d.ts.map +1 -1
  88. package/dist/server/better-auth/adapters/emailOptions.js +19 -8
  89. package/dist/server/better-auth/adapters/emailOptions.js.map +1 -1
  90. package/dist/server/better-auth/adapters/mount.d.ts +82 -41
  91. package/dist/server/better-auth/adapters/mount.d.ts.map +1 -1
  92. package/dist/server/better-auth/adapters/mount.js +8 -25
  93. package/dist/server/better-auth/adapters/mount.js.map +1 -1
  94. package/dist/server/better-auth/adapters/mountSettings.d.ts +51 -0
  95. package/dist/server/better-auth/adapters/mountSettings.d.ts.map +1 -0
  96. package/dist/server/better-auth/adapters/mountSettings.js +26 -0
  97. package/dist/server/better-auth/adapters/mountSettings.js.map +1 -0
  98. package/dist/server/better-auth/adapters/preferencesClient.d.ts +3 -0
  99. package/dist/server/better-auth/adapters/preferencesClient.d.ts.map +1 -0
  100. package/dist/server/better-auth/adapters/preferencesClient.js +24 -0
  101. package/dist/server/better-auth/adapters/preferencesClient.js.map +1 -0
  102. package/dist/server/better-auth/adapters/userDataExport.d.ts +38 -0
  103. package/dist/server/better-auth/adapters/userDataExport.d.ts.map +1 -0
  104. package/dist/server/better-auth/adapters/userDataExport.js +55 -0
  105. package/dist/server/better-auth/adapters/userDataExport.js.map +1 -0
  106. package/dist/server/better-auth/adapters/userProvisioning.d.ts +9 -0
  107. package/dist/server/better-auth/adapters/userProvisioning.d.ts.map +1 -0
  108. package/dist/server/better-auth/adapters/userProvisioning.js +22 -0
  109. package/dist/server/better-auth/adapters/userProvisioning.js.map +1 -0
  110. package/dist/server/better-auth/emails.d.ts +1 -0
  111. package/dist/server/better-auth/emails.d.ts.map +1 -1
  112. package/dist/server/better-auth/seedUsers.d.ts +6 -0
  113. package/dist/server/better-auth/seedUsers.d.ts.map +1 -0
  114. package/dist/server/better-auth/seedUsers.js +15 -0
  115. package/dist/server/better-auth/seedUsers.js.map +1 -0
  116. package/dist/server/better-auth/testDatabase.d.ts.map +1 -1
  117. package/dist/server/better-auth/testDatabase.js +4 -1
  118. package/dist/server/better-auth/testDatabase.js.map +1 -1
  119. package/dist/server/userDataExport.d.ts +13 -0
  120. package/dist/server/userDataExport.d.ts.map +1 -0
  121. package/dist/server/userDataExport.js +2 -0
  122. package/dist/server/userDataExport.js.map +1 -0
  123. package/package.json +16 -15
  124. package/src/accountPreferences.ts +42 -0
  125. package/src/server/AccountClock.ts +14 -0
  126. package/src/server/AccountPreferencesStore.ts +13 -0
  127. package/src/server/UserProvisioning.ts +16 -0
  128. package/src/server/account-clock/dayRange.ts +12 -0
  129. package/src/server/account-clock/initialize.ts +20 -0
  130. package/src/server/account-clock/logicalDay.ts +11 -0
  131. package/src/server/account-clock/settings.ts +15 -0
  132. package/src/server/account-export/check.ts +38 -0
  133. package/src/server/account-preferences/capture.ts +10 -0
  134. package/src/server/account-preferences/get.ts +13 -0
  135. package/src/server/account-preferences/initialize.ts +18 -0
  136. package/src/server/account-preferences/set.ts +12 -0
  137. package/src/server/accountExport.ts +40 -0
  138. package/src/server/accountPreferencesHandlers.ts +22 -0
  139. package/src/server/adapters/accountPreferencesMigration.ts +12 -0
  140. package/src/server/better-auth/adapters/SeedOptions.ts +12 -0
  141. package/src/server/better-auth/adapters/accountPreferenceOptions.ts +33 -0
  142. package/src/server/better-auth/adapters/acquire.ts +4 -1
  143. package/src/server/better-auth/adapters/assertSeedDatabase.ts +15 -0
  144. package/src/server/better-auth/adapters/defineSeed.ts +23 -0
  145. package/src/server/better-auth/adapters/emailOptions.ts +27 -8
  146. package/src/server/better-auth/adapters/mount.ts +11 -27
  147. package/src/server/better-auth/adapters/mountSettings.ts +29 -0
  148. package/src/server/better-auth/adapters/preferencesClient.ts +25 -0
  149. package/src/server/better-auth/adapters/userDataExport.ts +57 -0
  150. package/src/server/better-auth/adapters/userProvisioning.ts +25 -0
  151. package/src/server/better-auth/emails.ts +1 -0
  152. package/src/server/better-auth/seedUsers.ts +21 -0
  153. package/src/server/better-auth/testDatabase.ts +4 -3
  154. package/src/server/userDataExport.ts +15 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.25.0 - 2026-11-04
4
+
5
+ ### Added
6
+
7
+ - Auth emails accept per-kind `windows` overrides, falling back to the existing `window` and its one-minute default.
8
+ - Declare local demo personas with `defineSeed`: find or create password users, assign their application roles and run an Effect as each user. Non-local database URLs are refused before connecting.
9
+ - Provision password users through `UserProvisioning` and `betterAuthUserProvisioning`, reusing accounts by email without replacing their profile or password.
10
+ - Compose domain-owned user data export registrations into one typed account export. Check PostgreSQL foreign keys before exporting and report user-referencing tables that have no registration.
11
+ - Register Better Auth profile, linked-account and session data for export without passwords or authentication tokens.
12
+
13
+ ### Fixed
14
+
15
+ - Preserve Better Auth email continuations in the app link's `callbackURL`, accepting only continuations on the configured app route's origin.
16
+ - Expire auth test sessions relative to the Effect clock so controlled-clock stories agree with session sweeps and the auth provider.
17
+ - Enable native Better Auth database joins by default so interrupted session lookups release PostgreSQL queries without fallback join console errors or account ids. Explicit `advanced.database.joins` options still take precedence.
18
+
19
+ ## 0.24.0 - 2026-11-04
20
+
21
+ ### Added
22
+
23
+ - store account timezone, locale and units through authenticated preference contracts. Browser sign-in capture preserves subsequent edits.
24
+ - provide an account clock with a configurable local day start and DST-aware logical days and half-open day ranges.
25
+
26
+ ### Breaking
27
+
28
+ - import `AccountDayStart` and `LogicalDay` from `@shivaedev/identity/server/account-clock/settings.ts`. `server/AccountClock.ts` exports the service only.
29
+ - TypeScript source exports now use `@shivaedev/source` instead of `source`. Replace `source` with `@shivaedev/source` in Node `--conditions`, TypeScript `customConditions`, and Vite/Vitest `resolve.conditions`. Bare `source` selects built JavaScript; no compatibility alias is provided.
30
+
3
31
  ## 0.23.1 - 2026-11-04
4
32
 
5
33
  ### Changed
package/README.md CHANGED
@@ -73,6 +73,40 @@ Pass `subject: delegated` to the contract. A delegated request selects the accou
73
73
 
74
74
  `appHost` installs `subjectResolverLayer()` from `@shivaedev/identity/server/subjectResolverLayer.ts` for session hosts. Custom native RPC hosts provide that Layer with their `SessionPolicy` and install `subjectLayers(group)` from `@shivaedev/contract/subjectLayers.ts` when building the native RPC server. The subject declaration includes authentication failures in the client's error type; it needs no separate authentication middleware.
75
75
 
76
+ ### Account preferences and logical days
77
+
78
+ `AccountPreferences` from `@shivaedev/identity/accountPreferences.ts` exposes authenticated `get`, `set` and `capture` operations for the caller's timezone, locale and units (`metric` or `imperial`). `set` replaces all three values. `capture` only creates a missing record, preserving saved preferences on subsequent sign-ins. An account without a record reads `UTC`, `en` and `metric`. The contract uses `selfSubject`, so a caller cannot select another account with a transport header.
79
+
80
+ Apply `accountPreferencesMigration` from `@shivaedev/identity/server/adapters/accountPreferencesMigration.ts` as a numbered migration through `migratePostgres`. Provide `AccountPreferencesStore.layer` from `@shivaedev/identity/server/AccountPreferencesStore.ts` with the application's `SqlClient`, merge `AccountPreferences` into the RPC group, and install `accountPreferencesHandlers` from `@shivaedev/identity/server/accountPreferencesHandlers.ts`. The host supplies subject middleware as for other subject contracts.
81
+
82
+ To capture browser defaults, enable `{ accountPreferences: true }` in `betterAuthMount` and install the optional Better Auth client plugin:
83
+
84
+ ```ts
85
+ import { createAuthClient } from "better-auth/client";
86
+ import { preferencesClient } from "@shivaedev/identity/server/better-auth/adapters/preferencesClient.ts";
87
+
88
+ export const auth = createAuthClient({ plugins: [preferencesClient()] });
89
+ ```
90
+
91
+ The browser sends its `Intl.DateTimeFormat` timezone and locale to the auth mount. A successful first sign-in captures those values with metric units. After redirect-based sign-in, the browser's first `getSession` captures them. Missing or invalid browser timezone data leaves preferences uncaptured; a later browser session can capture them. Other clients can call the `capture` contract with their own defaults.
92
+
93
+ `AccountClock` from `@shivaedev/identity/server/AccountClock.ts` reads the current subject's saved timezone when its Layer is built. Build that Layer within the subject's request, providing `AccountPreferencesStore.layer`. Each new request sees the current saved timezone. 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`.
94
+
95
+ ```ts
96
+ import { DateTime, Effect, Layer } from "effect";
97
+ import { AccountClock } from "@shivaedev/identity/server/AccountClock.ts";
98
+ import { AccountDayStart } from "@shivaedev/identity/server/account-clock/settings.ts";
99
+
100
+ const clockLayer = AccountClock.layer.pipe(Layer.provide(Layer.succeed(AccountDayStart, 240)));
101
+ const today = Effect.gen(function* () {
102
+ const clock = yield* AccountClock;
103
+ const day = yield* clock.logicalDay(yield* DateTime.now);
104
+ return yield* clock.dayRange(day);
105
+ }).pipe(Effect.provide(clockLayer));
106
+ ```
107
+
108
+ `logicalDay(instant)` returns an ISO calendar date; omitting the instant uses Effect's current clock. `dayRange(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).
109
+
76
110
  ### Once per application: contracts and session policy
77
111
 
78
112
  Declare authentication middleware for actor-only boundaries. When a request acts on an account's data, declare its subject on the contract instead of accepting an owner id and checking it in each handler.
@@ -150,6 +184,8 @@ const authentication = Effect.gen(function* () {
150
184
 
151
185
  `betterAuthDatabase()` reads the application’s `SqlClient` and reserves connections from its PostgreSQL pool. Build it inside `appHost`’s `application` Effect, or provide sql’s `postgresLayer` for a standalone process. Set `maxConnections` and `applicationName` on the application SQL Layer. The mount does not run migrations or require identity's migration history. Use frozen numbered auth migrations as described below, or keep an existing migrator during the transition described in [Auth tables owned by another migrator](#auth-tables-owned-by-another-migrator). The application SQL Layer owns shutdown.
152
186
 
187
+ `betterAuthMount` enables Better Auth's native database joins by default. Session lookups through the Effect provider and mounted HTTP routes cancel their PostgreSQL queries quietly when interrupted, including when the user table is locked. This avoids Better Auth's fallback join error output and account ids in the console. An explicit `advanced.database.joins` option overrides the default.
188
+
153
189
  The adapter captures the SQL transaction at creation. An adapter created at startup does not join a later `transact` around an `auth.api` call: its auth writes commit independently and survive the application's rollback. For a shared boundary, create the adapter inside `transact`, and use it only within that transaction. Create the mount there too when its Effect hooks must share the application transaction:
154
190
 
155
191
  ```ts
@@ -192,6 +228,12 @@ Password resets revoke existing sessions by default. Set `emailAndPassword.revok
192
228
 
193
229
  `TRUSTED_PROXY` supplies the same address and CIDR policy used by the host. An untrusted transport peer loses `x-forwarded-for` and the configured client-IP header before Better Auth sees the request. `AUTH_CLIENT_IP_HEADER` defaults to `x-forwarded-for`. Without a trusted proxy, auth rate limiting uses the connection peer address, so different peers have separate buckets and Better Auth receives a client IP without a missing-IP warning. A trusted peer's configured forwarded header takes precedence over the peer address.
194
230
 
231
+ On Railway, pass `{ clientIp: "railway" }` as the second argument to `betterAuthMount` and set `TRUSTED_PROXY=100.64.0.0/10`. The preset selects Railway's edge-written `X-Real-IP` for session addresses and auth rate limiting, ignoring client-sent `X-Forwarded-For` even when `AUTH_CLIENT_IP_HEADER` selects that header. Proxy trust still applies: an untrusted peer or a trusted peer without `X-Real-IP` uses its connection address.
232
+
233
+ ```ts
234
+ const mounted = yield* betterAuthMount(authOptions, { clientIp: "railway" });
235
+ ```
236
+
195
237
  The auth HTTP server span records the resolved rate-limit address in `auth.rate_limit.address` and its source in `auth.rate_limit.address_source`: `forwarded` for the trusted proxy's configured header, or `peer` for the connection address. These attributes accompany counted sign-in attempts and HTTP 429 refusals, so operators can inspect the choice directly. The recorded address follows Better Auth's normalization, including IPv6 subnet grouping; a trusted peer without a forwarded header records `peer`.
196
238
 
197
239
  For email sign-in through `appHost`, the session record's `ipAddress` follows the same rule. With a trusted peer, `AUTH_CLIENT_IP_HEADER=x-real-ip` stores `X-Real-IP` even if `X-Forwarded-For` supplies a different address; the default header selects the rightmost untrusted address in the `X-Forwarded-For` chain, ignoring trusted proxy hops on the right. With an untrusted peer, neither header can supply the stored address. Sign-in attempts from an untrusted peer share one bucket per path; with a trusted peer and `x-real-ip`, changing `X-Forwarded-For` does not change the bucket, while changing `X-Real-IP` does.
@@ -246,6 +288,33 @@ const authentication = (options: BetterAuthOptions) =>
246
288
 
247
289
  The native `emailAndPassword.onPasswordReset` callback runs first. An Effect failure with `BetterAuthHookError` fields reaches the caller as HTTP 403 with its code and message. This callback follows Better Auth's post-reset lifecycle; a failure does not undo the password change.
248
290
 
291
+ ### Seed local demo users
292
+
293
+ `defineSeed` builds the PostgreSQL and Better Auth layers from `DATABASE_URL`, finds or creates each persona by email, assigns its role through `assignRole`, then evaluates `run` with that user's `Identity`, `SessionUser` and query viewer. The database must already be migrated. Only PostgreSQL URLs on `localhost`, `127.0.0.1` or `[::1]` are accepted; connection host overrides are refused before connecting.
294
+
295
+ ```ts
296
+ import { Effect, Redacted } from "effect";
297
+ import { role } from "@shivaedev/access/role.ts";
298
+ import { roleSet } from "@shivaedev/access/roleSet.ts";
299
+ import { SessionUser } from "@shivaedev/identity/identity.ts";
300
+ import { defineSeed } from "@shivaedev/identity/server/better-auth/adapters/defineSeed.ts";
301
+
302
+ const roles = roleSet(role("member", []));
303
+ const seed = defineSeed({
304
+ defaultRole: "member",
305
+ roles,
306
+ users: [{ email: "alice@demo.test", name: "alice", password: Redacted.make("local-demo-password"), role: "member" }],
307
+ run: Effect.gen(function* () {
308
+ const user = yield* SessionUser;
309
+ yield* Effect.logInfo(`Seed application data for ${user.email}`);
310
+ }),
311
+ });
312
+ ```
313
+
314
+ Pass the application's Better Auth settings as `auth` when it customizes user tables or authentication options. Existing emails reuse the same user ID, profile and password; each seed run assigns the declared role and runs the application Effect again, so application data seeding should itself be repeatable. New users receive password credentials and can sign in with the declared password.
315
+
316
+ For provisioning outside a seed, provide `betterAuthUserProvisioning(auth)` from `@shivaedev/identity/server/better-auth/adapters/userProvisioning.ts` and call `(yield* UserProvisioning).findOrCreateUser({ email, name, password })`, importing `UserProvisioning` from `@shivaedev/identity/server/UserProvisioning.ts`. This shares the seed's email-based reuse behavior without the seed's local database restriction.
317
+
249
318
  ### User directory
250
319
 
251
320
  Applications use the `UserDirectory` port from `@shivaedev/identity/server/UserDirectory.ts` instead of reading auth tables. Provide `betterAuthUserDirectory(AppAccess, authOptions)` from `@shivaedev/identity/server/better-auth/adapters/userDirectory.ts` with the application's SQL Layer. Setting `authOptions.user.modelName` to `"users"` directs directory reads to that table, including the admin Users view and its pagination. The adapter follows Better Auth's configured user model, name, email, creation and modification columns, and additional-field or plugin role mapping. It shares an existing Reactivity service when supplied and creates one otherwise.
@@ -804,6 +873,36 @@ export default Effect.gen(function* () {
804
873
 
805
874
  Run the auth schema migration before the app migration. Use `ON DELETE CASCADE` to delete owned rows with their user, or a nullable `user_id` and `ON DELETE SET NULL` to retain rows without an owner. `userReference` describes the default PostgreSQL mapping, so an application that customizes Better Auth's user table or id column must use its own mapping. Account reads and writes still go through identity; the foreign key grants no access to auth data. Quality's `boundaries/auth-sql` accepts these references while rejecting other auth SQL outside the configured owners.
806
875
 
876
+ ### Register user data exports
877
+
878
+ Each domain supplies a `UserDataExport` from `server/userDataExport.ts`: the schema-qualified tables it owns and an `export(userId)` Effect that reads that user's rows. Keep filtering and the choice of exported fields in the domain. Compose the registrations once in the application's account module:
879
+
880
+ ```ts
881
+ import { Effect } from "effect";
882
+ import { SqlClient } from "effect/sql";
883
+ import { accountExport } from "@shivaedev/identity/server/accountExport.ts";
884
+ import { betterAuthUserDataExport } from "@shivaedev/identity/server/better-auth/adapters/userDataExport.ts";
885
+
886
+ const notesExport = {
887
+ tables: [{ schema: "public", table: "notes" }],
888
+ export: Effect.fn(function* (userId: string) {
889
+ const sql = yield* SqlClient.SqlClient;
890
+ return yield* sql<{ title: string }>`select title from notes where user_id = ${userId} order by title`;
891
+ }),
892
+ };
893
+
894
+ const exports = accountExport({ account: betterAuthUserDataExport(), notes: notesExport });
895
+
896
+ const checkExportCoverage = exports.check;
897
+ const exportUser = exports.exportUser;
898
+ ```
899
+
900
+ `exportUser(userId)` checks coverage, enumerates every registration and returns one object keyed by domain, preserving each domain's result type, Effect dependencies and failures. Empty domain results remain in the export. The account handler supplies the authorized user's id; this server API does not authenticate callers. Application-owned tables with no foreign key need explicit registration too: PostgreSQL cannot discover their ownership.
901
+
902
+ Run `check` against the migrated application database in a startup check or PostgreSQL story. It reads PostgreSQL's foreign-key catalog and fails with `UnregisteredUserExportTables` from `server/account-export/check.ts` when any table referencing the user id lacks a registration. The error's `tables` names each missing `{ schema, table }` once, including references from other schemas. A registration covers its named table; the domain remains responsible for exporting the right rows and fields, which its stories should prove. An export runs the same check before reading domain data, so a newly added foreign key cannot silently leave a table out.
903
+
904
+ The default reference is `public.user(id)`. For a customized auth mapping, pass `{ schema, table, column }` as the second argument to `accountExport`. Pass the same Better Auth options to `betterAuthUserDataExport(options)`; its optional second argument selects the PostgreSQL schema. The built-in registration exports profile fields, linked-account identifiers and session metadata for that user, with timestamps as native Effect UTC values. Passwords, access tokens, refresh tokens and session tokens are excluded by explicit field selection. Add registrations for application fields and plugin-owned tables that the built-in registration does not cover.
905
+
807
906
  ### Signed-in story preconditions
808
907
 
809
908
  Use `testUtils()` from `better-auth/plugins` in a test-only Better Auth instance with the host's database, secret and cookie policy. Keep the plugin out of production auth options.
@@ -888,15 +987,16 @@ const mounted = yield* betterAuthMount(options, {
888
987
  },
889
988
  deliver: (message) => mailer.deliver(message),
890
989
  window: "1 minute",
990
+ windows: { ConfirmAccount: "2 minutes", ResetPassword: "5 minutes" },
891
991
  },
892
992
  });
893
993
  ```
894
994
 
895
- `AuthEmail` from `server/better-auth/emails.ts` is a union discriminated by `_tag`: `ConfirmAccount`, `ApproveEmailChange`, `ConfirmNewAddress`, `ResetPassword` and `AccountAlreadyExists`. Each message carries `user` and `url`. The `url` and every `token` are `Redacted<string>` so delivered messages keep their links and tokens hidden in logs and traces. Read them with `Redacted.value(message.url)` or `Redacted.value(message.token)` only when rendering the email or submitting the token. All except `AccountAlreadyExists` carry `token`; both change messages also carry `newEmail`, decoded inside identity for the reused verification callback. The new-address message's `user.email` is the destination address. The app URL preserves its own query parameters and receives the token in a `token` query parameter. A confirmation route passes that token to Better Auth's verification API; a reset page submits it with the new password to its reset API.
995
+ `AuthEmail` from `server/better-auth/emails.ts` is a union discriminated by `_tag`: `ConfirmAccount`, `ApproveEmailChange`, `ConfirmNewAddress`, `ResetPassword` and `AccountAlreadyExists`. Each message carries `user` and `url`. The `url` and every `token` are `Redacted<string>` so delivered messages keep their links and tokens hidden in logs and traces. Read them with `Redacted.value(message.url)` or `Redacted.value(message.token)` only when rendering the email or submitting the token. All except `AccountAlreadyExists` carry `token`; both change messages also carry `newEmail`, decoded inside identity for the reused verification callback. The new-address message's `user.email` is the destination address. The app URL preserves its own query parameters and receives the token in a `token` query parameter. When Better Auth supplies a continuation in its email link, identity copies it into `callbackURL` on the app link, replacing a configured `callbackURL` only when the continuation resolves to that app route's origin. Relative and absolute same-origin continuations are accepted; off-origin continuations are omitted even when Better Auth trusts that origin. Duplicate sign-up emails read `callbackURL` from the sign-up request supplied by Better Auth; server-side calls without a request keep their configured sign-in route. A confirmation page forwards both `token` and `callbackURL` to Better Auth's verification API so verification continues to the requested page, such as an invitation. A reset page submits the token with the new password to the reset API and uses the continuation after success.
896
996
 
897
997
  The wiring replaces the four delivery callbacks and preserves the other Better Auth settings. Enable the flows through native options: `emailAndPassword.enabled`, `emailVerification.sendOnSignUp` or `emailAndPassword.requireEmailVerification`, and `user.changeEmail.enabled`. Better Auth calls `onExistingUserSignUp` only with its generic duplicate-signup response enabled, such as with `requireEmailVerification`.
898
998
 
899
- Auth emails reserve one delivery attempt per account id and message kind for one minute by default in PostgreSQL. Provide the application's PostgreSQL Layer (`SqlClient` and `Reactivity`) to the mount. Include `postgresMigration` from `@shivaedev/rate-limit/adapters/postgresMigration.ts` in the application's numbered migration loader before enabling `emails`. `window` accepts an Effect Duration input. Different accounts and different kinds have separate windows; changing the destination address does not change the account key. Concurrent requests share the reservation, and another delivery is allowed at expiry. Suppressed requests return normally. A failed delivery keeps its reservation until expiry. The window uses database time and survives mount rebuilds and process restarts. Mounts sharing a database share the reservation, regardless of the `Store` supplied for request rate limits. It complements Better Auth's request rate limits. Delivery Effects use the same `BetterAuthHookError` and request runtime as database hooks.
999
+ Auth emails reserve one delivery attempt per account id and message kind for one minute by default in PostgreSQL. Provide the application's PostgreSQL Layer (`SqlClient` and `Reactivity`) to the mount. Include `postgresMigration` from `@shivaedev/rate-limit/adapters/postgresMigration.ts` in the application's numbered migration loader before enabling `emails`. `window` accepts an Effect Duration input and remains the default for every kind. The optional `windows` map overrides that duration by `AuthEmail["_tag"]`; omitted kinds still use `window`, or one minute when it is absent. Different accounts and different kinds have separate windows; changing the destination address does not change the account key. Concurrent requests share the reservation, and another delivery is allowed at expiry. Suppressed requests return normally. A failed delivery keeps its reservation until expiry. The window uses database time and survives mount rebuilds and process restarts. Mounts sharing a database share the reservation, regardless of the `Store` supplied for request rate limits. It complements Better Auth's request rate limits. Delivery Effects use the same `BetterAuthHookError` and request runtime as database hooks.
900
1000
 
901
1001
  ### Sweep expired sessions in a worker
902
1002
 
@@ -0,0 +1,112 @@
1
+ import { Effect, Schema } from "effect";
2
+ import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
3
+ export declare const AccountTimezone: Schema.String;
4
+ export declare const AccountPreferenceValues: Schema.Struct<{
5
+ readonly locale: Schema.NonEmptyString;
6
+ readonly timezone: Schema.String;
7
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
8
+ }>;
9
+ export declare const accountPreferenceKeys: import("@shivaedev/changes/keys.ts").Collection<"identity.accountPreferences", string, Record<never, never>>;
10
+ export declare const AccountPreferences: import("@shivaedev/contract/contract.ts").Contract<"identity.accountPreferences", readonly [NoInfer<import("@shivaedev/contract/operation.ts").Query<"get", Schema.Void, Schema.Struct<{
11
+ readonly locale: Schema.NonEmptyString;
12
+ readonly timezone: Schema.String;
13
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
14
+ }>, {
15
+ readonly AuthUnavailable: typeof AuthUnavailable;
16
+ }, never, undefined>>], readonly [NoInfer<import("@shivaedev/contract/operation.ts").Command<"capture", Schema.Struct<{
17
+ readonly locale: Schema.NonEmptyString;
18
+ readonly timezone: Schema.String;
19
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
20
+ }>, Schema.Void, {
21
+ readonly AuthUnavailable: typeof AuthUnavailable;
22
+ }>>, NoInfer<import("@shivaedev/contract/operation.ts").Command<"set", Schema.Struct<{
23
+ readonly locale: Schema.NonEmptyString;
24
+ readonly timezone: Schema.String;
25
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
26
+ }>, Schema.Void, {
27
+ readonly AuthUnavailable: typeof AuthUnavailable;
28
+ }>>], import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.$changes", Schema.Struct<{
29
+ queries: Schema.$Array<Schema.Union<readonly Schema.Struct<{
30
+ query: Schema.Literal<"get">;
31
+ payload: Schema.Void;
32
+ }>[]>>;
33
+ }>, import("effect/rpc/RpcSchema").Stream<Schema.Union<readonly [Schema.Union<readonly [Schema.Struct<{
34
+ readonly _tag: Schema.Literal<"Changed">;
35
+ readonly keys: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
36
+ readonly _tag: Schema.Literal<"Bucket">;
37
+ readonly collection: Schema.String;
38
+ readonly field: Schema.String;
39
+ readonly value: Schema.Union<readonly [Schema.String, Schema.Number]>;
40
+ }>, Schema.Struct<{
41
+ readonly _tag: Schema.Literal<"List">;
42
+ readonly collection: Schema.String;
43
+ }>, Schema.Struct<{
44
+ readonly _tag: Schema.Literal<"Item">;
45
+ readonly collection: Schema.String;
46
+ readonly id: Schema.Union<readonly [Schema.String, Schema.Number]>;
47
+ }>]>>;
48
+ readonly queryIndexes: Schema.optional<Schema.$Array<Schema.Number>>;
49
+ }>, Schema.Struct<{
50
+ readonly _tag: Schema.Literal<"Resync">;
51
+ }>]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, ...never[]]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired, ...Schema.Union<readonly (typeof AuthUnavailable)[]>[]]>>, Schema.Never, (import("effect/Context").Reference<<A, E, R>(effect: Effect.Effect<A, E, R>, request: {
52
+ readonly rpc: import("effect/rpc/Rpc").Any;
53
+ readonly payload: unknown;
54
+ }) => Effect.Effect<A, E | import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy | import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied | import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired | import("effect/Types").unhandled, R>> & {
55
+ "~effect/rpc/RpcMiddleware": "~effect/rpc/RpcMiddleware";
56
+ "~ClientError": never;
57
+ error: Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired]>;
58
+ requiredForClient: false;
59
+ }) | (import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/internal/subjectMiddleware.ts").SubjectMiddleware<{
60
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
61
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
62
+ }>, `@shivaedev/contract/Subject/${string}`, import("./identity.ts").Identity | import("./identity.ts").SessionUser | import("#subject.ts").Subject, Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, never, never, false> & {
63
+ "@shivaedev/contract/SubjectDeclaration": {
64
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
65
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
66
+ };
67
+ }), never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.capture", Schema.Struct<{
68
+ readonly locale: Schema.NonEmptyString;
69
+ readonly timezone: Schema.String;
70
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
71
+ }>, Schema.Void, Schema.Union<readonly (typeof AuthUnavailable)[]>, import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/internal/subjectMiddleware.ts").SubjectMiddleware<{
72
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
73
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
74
+ }>, `@shivaedev/contract/Subject/${string}`, import("./identity.ts").Identity | import("./identity.ts").SessionUser | import("#subject.ts").Subject, Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, never, never, false> & {
75
+ "@shivaedev/contract/SubjectDeclaration": {
76
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
77
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
78
+ };
79
+ }, never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.set", Schema.Struct<{
80
+ readonly locale: Schema.NonEmptyString;
81
+ readonly timezone: Schema.String;
82
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
83
+ }>, Schema.Void, Schema.Union<readonly (typeof AuthUnavailable)[]>, import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/internal/subjectMiddleware.ts").SubjectMiddleware<{
84
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
85
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
86
+ }>, `@shivaedev/contract/Subject/${string}`, import("./identity.ts").Identity | import("./identity.ts").SessionUser | import("#subject.ts").Subject, Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, never, never, false> & {
87
+ "@shivaedev/contract/SubjectDeclaration": {
88
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
89
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
90
+ };
91
+ }, never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.get", Schema.Void, Schema.Struct<{
92
+ readonly locale: Schema.NonEmptyString;
93
+ readonly timezone: Schema.String;
94
+ readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
95
+ }>, Schema.Union<readonly [Schema.Union<readonly (typeof AuthUnavailable)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, (import("effect/Context").Reference<<A, E, R>(effect: Effect.Effect<A, E, R>, request: {
96
+ readonly rpc: import("effect/rpc/Rpc").Any;
97
+ readonly payload: unknown;
98
+ }) => Effect.Effect<A, E | import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy | import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied | import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired | import("effect/Types").unhandled, R>> & {
99
+ "~effect/rpc/RpcMiddleware": "~effect/rpc/RpcMiddleware";
100
+ "~ClientError": never;
101
+ error: Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired]>;
102
+ requiredForClient: false;
103
+ }) | (import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/internal/subjectMiddleware.ts").SubjectMiddleware<{
104
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
105
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
106
+ }>, `@shivaedev/contract/Subject/${string}`, import("./identity.ts").Identity | import("./identity.ts").SessionUser | import("#subject.ts").Subject, Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, never, never, false> & {
107
+ "@shivaedev/contract/SubjectDeclaration": {
108
+ error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
109
+ middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
110
+ };
111
+ }), never>, readonly [], undefined>;
112
+ //# sourceMappingURL=accountPreferences.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountPreferences.d.ts","sourceRoot":"","sources":["../src/accountPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAI1D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGhE,eAAO,MAAM,eAAe,eAE3B,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;EAIlC,CAAC;AAEH,eAAO,MAAM,qBAAqB,8GAA2D,CAAC;AAE9F,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mCAsB7B,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { DateTime, Effect, Option, Schema } from "effect";
2
+ import { collection } from "@shivaedev/changes/keys.ts";
3
+ import { contract } from "@shivaedev/contract/contract.ts";
4
+ import { command, query } from "@shivaedev/contract/operation.ts";
5
+ import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
6
+ import { selfSubject } from "#subject.ts";
7
+ export const AccountTimezone = Schema.String.check(Schema.makeFilter((value) => Option.isSome(DateTime.zoneMakeNamed(value)), { expected: "an IANA timezone" }));
8
+ export const AccountPreferenceValues = Schema.Struct({
9
+ locale: Schema.NonEmptyString,
10
+ timezone: AccountTimezone,
11
+ units: Schema.Literals(["metric", "imperial"]),
12
+ });
13
+ export const accountPreferenceKeys = collection("identity.accountPreferences", Schema.String);
14
+ export const AccountPreferences = contract("identity.accountPreferences", {
15
+ commands: [
16
+ command("capture", {
17
+ invalidates: () => [accountPreferenceKeys.list],
18
+ payload: AccountPreferenceValues.fields,
19
+ rejections: { AuthUnavailable },
20
+ }),
21
+ command("set", {
22
+ invalidates: () => [accountPreferenceKeys.list],
23
+ payload: AccountPreferenceValues.fields,
24
+ rejections: { AuthUnavailable },
25
+ }),
26
+ ],
27
+ queries: [
28
+ query("get", {
29
+ readPolicy: () => Effect.succeed(true),
30
+ reads: () => [accountPreferenceKeys.list],
31
+ rejections: { AuthUnavailable },
32
+ success: AccountPreferenceValues,
33
+ }),
34
+ ],
35
+ subject: selfSubject,
36
+ });
37
+ //# sourceMappingURL=accountPreferences.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accountPreferences.js","sourceRoot":"","sources":["../src/accountPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CACjD,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,QAAQ,EAAE,kBAAkB,EAAE,CAAC,CAC5G,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,CAAC;IACpD,MAAM,EAAE,MAAM,CAAC,cAAc;IAC7B,QAAQ,EAAE,eAAe;IACzB,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;CAC9C,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAAC,6BAA6B,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AAE9F,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC,6BAA6B,EAAE;IACzE,QAAQ,EAAE;QACT,OAAO,CAAC,SAAS,EAAE;YAClB,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC;YAC/C,OAAO,EAAE,uBAAuB,CAAC,MAAM;YACvC,UAAU,EAAE,EAAE,eAAe,EAAE;SAC/B,CAAC;QACF,OAAO,CAAC,KAAK,EAAE;YACd,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC;YAC/C,OAAO,EAAE,uBAAuB,CAAC,MAAM;YACvC,UAAU,EAAE,EAAE,eAAe,EAAE;SAC/B,CAAC;KACF;IACD,OAAO,EAAE;QACR,KAAK,CAAC,KAAK,EAAE;YACZ,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;YACtC,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC;YACzC,UAAU,EAAE,EAAE,eAAe,EAAE;YAC/B,OAAO,EAAE,uBAAuB;SAChC,CAAC;KACF;IACD,OAAO,EAAE,WAAW;CACpB,CAAC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { Subject } from "#subject.ts";
2
+ export declare const AccountClock: import("effect/Context").Service<"@shivaedev/identity/AccountClock", Readonly<{
3
+ readonly dayRange: (day: string) => import("effect/Effect").Effect<{
4
+ end: import("effect/DateTime").Utc;
5
+ 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, never, never>;
8
+ }>> & {
9
+ readonly layer: import("effect/Layer").Layer<"@shivaedev/identity/AccountClock", import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("effect/Schema").SchemaError, "@shivaedev/identity/AccountPreferencesStore" | Subject>;
10
+ };
11
+ //# sourceMappingURL=AccountClock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountClock.d.ts","sourceRoot":"","sources":["../../src/server/AccountClock.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,eAAO,MAAM,YAAY;;;;;;;;CAKvB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { defineService } from "@shivaedev/service/defineService.ts";
2
+ import { AccountPreferencesStore } from "#server/AccountPreferencesStore.ts";
3
+ import { dayRange } from "#server/account-clock/dayRange.ts";
4
+ import { initialize } from "#server/account-clock/initialize.ts";
5
+ import { logicalDay } from "#server/account-clock/logicalDay.ts";
6
+ import { AccountDayStart } from "#server/account-clock/settings.ts";
7
+ import { Subject } from "#subject.ts";
8
+ export const AccountClock = defineService({
9
+ id: "@shivaedev/identity/AccountClock",
10
+ initialize,
11
+ methods: (state) => ({ dayRange: dayRange(state), logicalDay: logicalDay(state) }),
12
+ requires: [AccountPreferencesStore, Subject, AccountDayStart],
13
+ });
14
+ //# sourceMappingURL=AccountClock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountClock.js","sourceRoot":"","sources":["../../src/server/AccountClock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,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,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAC;IACzC,EAAE,EAAE,kCAAkC;IACtC,UAAU;IACV,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;IAClF,QAAQ,EAAE,CAAC,uBAAuB,EAAE,OAAO,EAAE,eAAe,CAAC;CAC7D,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { SqlClient } from "effect/sql";
2
+ export declare const AccountPreferencesStore: import("effect/Context").Service<"@shivaedev/identity/AccountPreferencesStore", Readonly<{
3
+ readonly capture: (id: string, values: {
4
+ readonly locale: string;
5
+ readonly timezone: string;
6
+ readonly units: "imperial" | "metric";
7
+ }) => import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
8
+ readonly get: (id: string) => import("effect/Effect").Effect<{
9
+ locale: string;
10
+ timezone: string;
11
+ units: "imperial" | "metric";
12
+ } | {
13
+ locale: string;
14
+ timezone: string;
15
+ units: "metric";
16
+ }, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
17
+ readonly set: (id: string, values: {
18
+ readonly locale: string;
19
+ readonly timezone: string;
20
+ readonly units: "imperial" | "metric";
21
+ }) => import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
22
+ }>> & {
23
+ readonly layer: import("effect/Layer").Layer<"@shivaedev/identity/AccountPreferencesStore", import("@shivaedev/sql/repositoryCollection.ts").BucketRegistrationError, SqlClient.SqlClient>;
24
+ };
25
+ //# sourceMappingURL=AccountPreferencesStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountPreferencesStore.d.ts","sourceRoot":"","sources":["../../src/server/AccountPreferencesStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAOvC,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;CAKlC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { SqlClient } from "effect/sql";
2
+ import { defineService } from "@shivaedev/service/defineService.ts";
3
+ import { capture } from "#server/account-preferences/capture.ts";
4
+ import { get } from "#server/account-preferences/get.ts";
5
+ import { initialize } from "#server/account-preferences/initialize.ts";
6
+ import { set } from "#server/account-preferences/set.ts";
7
+ export const AccountPreferencesStore = defineService({
8
+ id: "@shivaedev/identity/AccountPreferencesStore",
9
+ initialize,
10
+ methods: (state) => ({ capture: capture(state), get: get(state), set: set(state) }),
11
+ requires: [SqlClient.SqlClient],
12
+ });
13
+ //# sourceMappingURL=AccountPreferencesStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountPreferencesStore.js","sourceRoot":"","sources":["../../src/server/AccountPreferencesStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AACjE,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,2CAA2C,CAAC;AACvE,OAAO,EAAE,GAAG,EAAE,MAAM,oCAAoC,CAAC;AAEzD,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAAC;IACpD,EAAE,EAAE,6CAA6C;IACjD,UAAU;IACV,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;IACnF,QAAQ,EAAE,CAAC,SAAS,CAAC,SAAS,CAAC;CAC/B,CAAC,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { Context, type Effect, type Redacted } from "effect";
2
+ import type { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
3
+ import type { SessionUserValue } from "#identity.ts";
4
+ export interface PasswordUser {
5
+ readonly email: string;
6
+ readonly name: string;
7
+ readonly password: Redacted.Redacted<string>;
8
+ }
9
+ declare const UserProvisioning_base: Context.ServiceClass<UserProvisioning, "@shivaedev/identity/UserProvisioning", {
10
+ readonly findOrCreateUser: (user: PasswordUser) => Effect.Effect<Pick<SessionUserValue, "id" | "email" | "name">, AuthUnavailable>;
11
+ }>;
12
+ export declare class UserProvisioning extends UserProvisioning_base {
13
+ }
14
+ export {};
15
+ //# sourceMappingURL=UserProvisioning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserProvisioning.d.ts","sourceRoot":"","sources":["../../src/server/UserProvisioning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;CAC7C;;+BAK4B,CAAC,IAAI,EAAE,YAAY,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,GAAG,OAAO,GAAG,MAAM,CAAC,EAAE,eAAe,CAAC;;AAHpI,qBAAa,gBAAiB,SAAQ,qBAKK;CAAG"}
@@ -0,0 +1,4 @@
1
+ import { Context } from "effect";
2
+ export class UserProvisioning extends Context.Service()("@shivaedev/identity/UserProvisioning") {
3
+ }
4
+ //# sourceMappingURL=UserProvisioning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserProvisioning.js","sourceRoot":"","sources":["../../src/server/UserProvisioning.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAA8B,MAAM,QAAQ,CAAC;AAU7D,MAAM,OAAO,gBAAiB,SAAQ,OAAO,CAAC,OAAO,EAKlD,CAAC,sCAAsC,CAAC;CAAG"}
@@ -0,0 +1,7 @@
1
+ import { DateTime, Effect, Schema } from "effect";
2
+ import type { initialize } from "./initialize.ts";
3
+ export declare function dayRange({ boundary }: Effect.Success<typeof initialize>): (day: string) => Effect.Effect<{
4
+ end: DateTime.Utc;
5
+ start: DateTime.Utc;
6
+ }, Schema.SchemaError, never>;
7
+ //# sourceMappingURL=dayRange.d.ts.map
@@ -0,0 +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;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,UAAU,CAAC;;;8BAOvE"}
@@ -0,0 +1,11 @@
1
+ import { DateTime, Effect, Schema } from "effect";
2
+ import { LogicalDay } from "./settings.js";
3
+ export function dayRange({ boundary }) {
4
+ const decodeDay = Schema.decodeUnknownEffect(LogicalDay);
5
+ return Effect.fnUntraced(function* (day) {
6
+ yield* decodeDay(day);
7
+ const next = DateTime.makeUnsafe(day).pipe(DateTime.add({ days: 1 }), DateTime.formatIsoDateUtc);
8
+ return { end: boundary(next), start: boundary(day) };
9
+ });
10
+ }
11
+ //# sourceMappingURL=dayRange.js.map
@@ -0,0 +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;AAElD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,MAAM,UAAU,QAAQ,CAAC,EAAE,QAAQ,EAAqC;IACvE,MAAM,SAAS,GAAG,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,GAAW;QAC9C,KAAK,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACtB,MAAM,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC;QACjG,OAAO,EAAE,GAAG,EAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;IACtD,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { DateTime, Effect, Schema } from "effect";
2
+ import { Subject } from "#subject.ts";
3
+ export declare const initialize: Effect.Effect<{
4
+ boundary: (day: string) => DateTime.Utc;
5
+ timezone: string;
6
+ }, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | Schema.SchemaError, "@shivaedev/identity/AccountPreferencesStore" | Subject>;
7
+ //# sourceMappingURL=initialize.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAElD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,eAAO,MAAM,UAAU;oBAIC,MAAM;;yIAU5B,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { DateTime, Effect, Schema } from "effect";
2
+ import { AccountPreferencesStore } from "#server/AccountPreferencesStore.ts";
3
+ import { Subject } from "#subject.ts";
4
+ import { AccountDayStart, DayStart } from "./settings.js";
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
+ function boundary(day) {
10
+ return DateTime.toUtc(DateTime.makeZonedUnsafe(`${day}T00:00:00.000Z`, {
11
+ adjustForTimeZone: true,
12
+ disambiguation: "compatible",
13
+ timeZone: timezone,
14
+ }).pipe(DateTime.setParts({ hour: Math.floor(minutes / 60), minute: minutes % 60 })));
15
+ }
16
+ return { boundary, timezone };
17
+ });
18
+ //# sourceMappingURL=initialize.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../src/server/account-clock/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE1D,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAC7C,MAAM,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC;IAC9B,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,uBAAuB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACrE,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,eAAe,CAAC,CAAC;IACpF,SAAS,QAAQ,CAAC,GAAW;QAC5B,OAAO,QAAQ,CAAC,KAAK,CACpB,QAAQ,CAAC,eAAe,CAAC,GAAG,GAAG,gBAAgB,EAAE;YAChD,iBAAiB,EAAE,IAAI;YACvB,cAAc,EAAE,YAAY;YAC5B,QAAQ,EAAE,QAAQ;SAClB,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,CAAC;IACH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AAC/B,CAAC,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { DateTime, Effect } from "effect";
2
+ import type { initialize } from "./initialize.ts";
3
+ export declare function logicalDay({ boundary, timezone }: Effect.Success<typeof initialize>): (instant?: DateTime.Utc | undefined) => Effect.Effect<string, never, never>;
4
+ //# sourceMappingURL=logicalDay.d.ts.map
@@ -0,0 +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;AAC1C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,wBAAgB,UAAU,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,UAAU,CAAC,+EAOnF"}
@@ -0,0 +1,10 @@
1
+ import { DateTime, Effect } from "effect";
2
+ export function logicalDay({ boundary, timezone }) {
3
+ return Effect.fnUntraced(function* (instant) {
4
+ const now = instant ?? (yield* DateTime.now);
5
+ const local = DateTime.setZoneNamedUnsafe(now, timezone);
6
+ const day = DateTime.formatIsoDate(local);
7
+ return DateTime.isLessThan(now, boundary(day)) ? DateTime.makeUnsafe(day).pipe(DateTime.subtract({ days: 1 }), DateTime.formatIsoDateUtc) : day;
8
+ });
9
+ }
10
+ //# sourceMappingURL=logicalDay.js.map
@@ -0,0 +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;AAG1C,MAAM,UAAU,UAAU,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAqC;IACnF,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,OAAsB;QACzD,MAAM,GAAG,GAAG,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC7C,MAAM,KAAK,GAAG,QAAQ,CAAC,kBAAkB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;QACzD,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC1C,OAAO,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACjJ,CAAC,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { Context, Schema } from "effect";
2
+ export declare const LogicalDay: Schema.String;
3
+ export declare const AccountDayStart: Context.Reference<number>;
4
+ export declare const DayStart: Schema.Int;
5
+ //# sourceMappingURL=settings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../../../src/server/account-clock/settings.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAoB,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE3D,eAAO,MAAM,UAAU,eAStB,CAAC;AAEF,eAAO,MAAM,eAAe,2BAA8F,CAAC;AAC3H,eAAO,MAAM,QAAQ,YAAoE,CAAC"}