@shivaedev/identity 0.26.2 → 0.28.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 (133) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +42 -43
  3. package/dist/accountPreferences.d.ts +15 -15
  4. package/dist/accountPreferences.d.ts.map +1 -1
  5. package/dist/server/account-clock/boundary.d.ts +3 -0
  6. package/dist/server/account-clock/boundary.d.ts.map +1 -0
  7. package/dist/server/account-clock/boundary.js +7 -0
  8. package/dist/server/account-clock/boundary.js.map +1 -0
  9. package/dist/server/account-clock/dayRange.d.ts +1 -1
  10. package/dist/server/account-clock/dayRange.d.ts.map +1 -1
  11. package/dist/server/account-clock/dayRange.js +4 -3
  12. package/dist/server/account-clock/dayRange.js.map +1 -1
  13. package/dist/server/account-clock/initialize.d.ts +2 -2
  14. package/dist/server/account-clock/initialize.d.ts.map +1 -1
  15. package/dist/server/account-clock/initialize.js +3 -10
  16. package/dist/server/account-clock/initialize.js.map +1 -1
  17. package/dist/server/account-clock/logicalDay.d.ts +1 -1
  18. package/dist/server/account-clock/logicalDay.d.ts.map +1 -1
  19. package/dist/server/account-clock/logicalDay.js +6 -3
  20. package/dist/server/account-clock/logicalDay.js.map +1 -1
  21. package/dist/server/{AccountClock.d.ts → account-clock/service.d.ts} +1 -1
  22. package/dist/server/account-clock/service.d.ts.map +1 -0
  23. package/dist/server/account-clock/service.js +14 -0
  24. package/dist/server/account-clock/service.js.map +1 -0
  25. package/dist/server/account-preferences/{initialize.d.ts → Rows.d.ts} +7 -6
  26. package/dist/server/account-preferences/Rows.d.ts.map +1 -0
  27. package/dist/server/account-preferences/{initialize.js → Rows.js} +7 -2
  28. package/dist/server/account-preferences/Rows.js.map +1 -0
  29. package/dist/server/account-preferences/capture.d.ts +2 -3
  30. package/dist/server/account-preferences/capture.d.ts.map +1 -1
  31. package/dist/server/account-preferences/capture.js +5 -5
  32. package/dist/server/account-preferences/capture.js.map +1 -1
  33. package/dist/server/account-preferences/get.d.ts +2 -3
  34. package/dist/server/account-preferences/get.d.ts.map +1 -1
  35. package/dist/server/account-preferences/get.js +5 -5
  36. package/dist/server/account-preferences/get.js.map +1 -1
  37. package/dist/server/{AccountPreferencesStore.d.ts → account-preferences/service.d.ts} +6 -6
  38. package/dist/server/account-preferences/service.d.ts.map +1 -0
  39. package/dist/server/account-preferences/service.js +13 -0
  40. package/dist/server/account-preferences/service.js.map +1 -0
  41. package/dist/server/account-preferences/set.d.ts +2 -3
  42. package/dist/server/account-preferences/set.d.ts.map +1 -1
  43. package/dist/server/account-preferences/set.js +7 -7
  44. package/dist/server/account-preferences/set.js.map +1 -1
  45. package/dist/server/account-preferences/store.d.ts +3 -0
  46. package/dist/server/account-preferences/store.d.ts.map +1 -0
  47. package/dist/server/account-preferences/store.js +5 -0
  48. package/dist/server/account-preferences/store.js.map +1 -0
  49. package/dist/server/accountPreferencesHandlers.js +1 -1
  50. package/dist/server/accountPreferencesHandlers.js.map +1 -1
  51. package/dist/server/{currentSessionContext.d.ts → adapters/currentSessionContext.d.ts} +1 -1
  52. package/dist/server/adapters/currentSessionContext.d.ts.map +1 -0
  53. package/dist/server/{currentSessionContext.js → adapters/currentSessionContext.js} +1 -1
  54. package/dist/server/adapters/currentSessionContext.js.map +1 -0
  55. package/dist/server/adapters/permissionRoute.d.ts +7 -0
  56. package/dist/server/adapters/permissionRoute.d.ts.map +1 -0
  57. package/dist/server/adapters/permissionRoute.js +26 -0
  58. package/dist/server/adapters/permissionRoute.js.map +1 -0
  59. package/dist/server/adapters/socketMonitor.d.ts +3 -0
  60. package/dist/server/adapters/socketMonitor.d.ts.map +1 -0
  61. package/dist/server/adapters/socketMonitor.js +11 -0
  62. package/dist/server/adapters/socketMonitor.js.map +1 -0
  63. package/dist/server/better-auth/adapters/accountPreferenceOptions.js +1 -1
  64. package/dist/server/better-auth/adapters/accountPreferenceOptions.js.map +1 -1
  65. package/dist/server/better-auth/{accountRoleSeed.d.ts → adapters/accountRoleSeed.d.ts} +3 -3
  66. package/dist/server/better-auth/adapters/accountRoleSeed.d.ts.map +1 -0
  67. package/dist/server/better-auth/{accountRoleSeed.js → adapters/accountRoleSeed.js} +2 -2
  68. package/dist/server/better-auth/adapters/accountRoleSeed.js.map +1 -0
  69. package/dist/server/better-auth/adapters/mount.d.ts +1 -1
  70. package/dist/server/better-auth/adapters/mount.d.ts.map +1 -1
  71. package/dist/server/better-auth/adapters/mount.js +2 -2
  72. package/dist/server/better-auth/adapters/mount.js.map +1 -1
  73. package/dist/server/better-auth/adapters/roleSeedOptions.d.ts +1 -1
  74. package/dist/server/better-auth/adapters/roleSeedOptions.d.ts.map +1 -1
  75. package/dist/server/localOwner.d.ts +4 -3
  76. package/dist/server/localOwner.d.ts.map +1 -1
  77. package/dist/server/localOwner.js +4 -3
  78. package/dist/server/localOwner.js.map +1 -1
  79. package/dist/server/machineTokens.d.ts +4 -3
  80. package/dist/server/machineTokens.d.ts.map +1 -1
  81. package/dist/server/machineTokens.js +6 -4
  82. package/dist/server/machineTokens.js.map +1 -1
  83. package/dist/server/{permissions.d.ts → permissionLayer.d.ts} +2 -4
  84. package/dist/server/permissionLayer.d.ts.map +1 -0
  85. package/dist/server/{permissions.js → permissionLayer.js} +1 -19
  86. package/dist/server/permissionLayer.js.map +1 -0
  87. package/dist/server/revalidateStream.js +1 -1
  88. package/dist/server/revalidateStream.js.map +1 -1
  89. package/dist/server/socketSession.d.ts.map +1 -1
  90. package/dist/server/socketSession.js +3 -8
  91. package/dist/server/socketSession.js.map +1 -1
  92. package/dist/sessions.d.ts +4 -4
  93. package/dist/sessions.d.ts.map +1 -1
  94. package/package.json +18 -18
  95. package/src/server/account-clock/boundary.ts +13 -0
  96. package/src/server/account-clock/dayRange.ts +4 -3
  97. package/src/server/account-clock/initialize.ts +3 -12
  98. package/src/server/account-clock/logicalDay.ts +6 -3
  99. package/src/server/{AccountClock.ts → account-clock/service.ts} +5 -5
  100. package/src/server/account-preferences/{initialize.ts → Rows.ts} +7 -3
  101. package/src/server/account-preferences/capture.ts +5 -6
  102. package/src/server/account-preferences/get.ts +9 -10
  103. package/src/server/account-preferences/service.ts +13 -0
  104. package/src/server/account-preferences/set.ts +7 -8
  105. package/src/server/account-preferences/store.ts +5 -0
  106. package/src/server/accountPreferencesHandlers.ts +1 -1
  107. package/src/server/{currentSessionContext.ts → adapters/currentSessionContext.ts} +2 -2
  108. package/src/server/adapters/permissionRoute.ts +43 -0
  109. package/src/server/adapters/socketMonitor.ts +19 -0
  110. package/src/server/better-auth/adapters/accountPreferenceOptions.ts +1 -1
  111. package/src/server/better-auth/{accountRoleSeed.ts → adapters/accountRoleSeed.ts} +2 -2
  112. package/src/server/better-auth/adapters/mount.ts +3 -3
  113. package/src/server/better-auth/adapters/roleSeedOptions.ts +1 -1
  114. package/src/server/localOwner.ts +4 -3
  115. package/src/server/machineTokens.ts +6 -4
  116. package/src/server/{permissions.ts → permissionLayer.ts} +0 -30
  117. package/src/server/revalidateStream.ts +1 -1
  118. package/src/server/socketSession.ts +3 -16
  119. package/dist/server/AccountClock.d.ts.map +0 -1
  120. package/dist/server/AccountClock.js +0 -14
  121. package/dist/server/AccountClock.js.map +0 -1
  122. package/dist/server/AccountPreferencesStore.d.ts.map +0 -1
  123. package/dist/server/AccountPreferencesStore.js +0 -13
  124. package/dist/server/AccountPreferencesStore.js.map +0 -1
  125. package/dist/server/account-preferences/initialize.d.ts.map +0 -1
  126. package/dist/server/account-preferences/initialize.js.map +0 -1
  127. package/dist/server/better-auth/accountRoleSeed.d.ts.map +0 -1
  128. package/dist/server/better-auth/accountRoleSeed.js.map +0 -1
  129. package/dist/server/currentSessionContext.d.ts.map +0 -1
  130. package/dist/server/currentSessionContext.js.map +0 -1
  131. package/dist/server/permissions.d.ts.map +0 -1
  132. package/dist/server/permissions.js.map +0 -1
  133. package/src/server/AccountPreferencesStore.ts +0 -13
@@ -1 +1 @@
1
- {"version":3,"file":"machineTokens.js","sourceRoot":"","sources":["../../src/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MAAM,CAAC,KAAK,CAAC,KAAK,EAAE;gBACpF,IAAI,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,MAAM,EAAE;aACrC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QACF,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,sBAAsB,CAAC,CAAC,CAAC,EAAU,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;KAC/G,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -1,5 +1,4 @@
1
- import { type Context, Effect, Layer } from "effect";
2
- import { type HttpServerRequest, HttpServerResponse } from "effect/http";
1
+ import { type Context, Layer } from "effect";
3
2
  import type { RpcMiddleware } from "effect/rpc";
4
3
  import type { Permission } from "@shivaedev/access/permission.ts";
5
4
  import { Identity, SessionUser } from "#identity.ts";
@@ -8,5 +7,4 @@ import { SessionPolicy } from "./SessionPolicy.ts";
8
7
  export declare function permissionLayer<TMiddleware>(middleware: Context.Key<TMiddleware, RpcMiddleware.RpcMiddleware<Identity | SessionUser, IdentityFailures, never>> & {
9
8
  readonly permission: Permission;
10
9
  }): Layer.Layer<TMiddleware, never, SessionPolicy>;
11
- export declare function permissionRoute(permission: Permission): <E, R>(handler: (request: HttpServerRequest.HttpServerRequest) => Effect.Effect<HttpServerResponse.HttpServerResponse, E, R>) => (request: HttpServerRequest.HttpServerRequest) => Effect.Effect<HttpServerResponse.HttpServerResponse, E, SessionPolicy | Exclude<R, Identity | SessionUser>>;
12
- //# sourceMappingURL=permissions.d.ts.map
10
+ //# sourceMappingURL=permissionLayer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissionLayer.d.ts","sourceRoot":"","sources":["../../src/server/permissionLayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAU,KAAK,EAAU,MAAM,QAAQ,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAGlE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIvD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,wBAAgB,eAAe,CAAC,WAAW,EAC1C,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,aAAa,CAAC,aAAa,CAAC,QAAQ,GAAG,WAAW,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC,GAAG;IACpH,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;CAChC,kDAwBD"}
@@ -1,6 +1,4 @@
1
1
  import { Effect, Layer, Option } from "effect";
2
- import { HttpServerResponse } from "effect/http";
3
- import * as HttpStatus from "effect/http/HttpStatus";
4
2
  import { forbidden } from "@shivaedev/access/refusal.ts";
5
3
  import { requirePermission } from "@shivaedev/access/requirePermission.ts";
6
4
  import { Identity, SessionUser } from "#identity.ts";
@@ -19,20 +17,4 @@ export function permissionLayer(middleware) {
19
17
  return guard;
20
18
  }));
21
19
  }
22
- function rejection(error) {
23
- return HttpServerResponse.empty({
24
- headers: { "cache-control": "private, no-store" },
25
- status: {
26
- AuthUnavailable: HttpStatus.fromLiteral("ServiceUnavailable"),
27
- Forbidden: HttpStatus.fromLiteral("Forbidden"),
28
- Unauthorized: HttpStatus.fromLiteral("Unauthorized"),
29
- }[error._tag],
30
- });
31
- }
32
- export function permissionRoute(permission) {
33
- return (handler) => (request) => Effect.andThen(Effect.flatMap(SessionUser, (user) => requirePermission(user, permission)), Effect.context()).pipe(withSessionUser(request.headers, request.url), Effect.matchEffect({
34
- onFailure: (error) => Effect.succeed(rejection(error)),
35
- onSuccess: (context) => Effect.provideContext(handler(request), context),
36
- }));
37
- }
38
- //# sourceMappingURL=permissions.js.map
20
+ //# sourceMappingURL=permissionLayer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permissionLayer.js","sourceRoot":"","sources":["../../src/server/permissionLayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG7D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAErD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,MAAM,UAAU,eAAe,CAC9B,UAEC;IAED,MAAM,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC;IACzC,OAAO,KAAK,CAAC,MAAM,CAClB,UAAU,EACV,MAAM,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE;QACpC,MAAM,KAAK,GAAiF,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE;YACxH,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,CACxE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAC3H,CAAC;YACF,OAAO,MAAM,CAAC,IAAI,CACjB,CAAC,UAAU,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,gBAAgB,CAAC,GAAG,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC,EACxG,CAAC,UAAU,EAAE,EAAE,CACd,MAAM,CAAC,OAAO,CACb,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,EAC1E,UAAU,CACV,EACF,eAAe,CAAC,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC,EAClC,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,MAAM,CAAC,CAC5C,CAAC;QACH,CAAC,CAAC;QACF,OAAO,KAAK,CAAC;IACd,CAAC,CAAC,CACF,CAAC;AACH,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { Effect } from "effect";
2
2
  import { RpcSchema } from "effect/rpc";
3
- import { currentSessionContext } from "./currentSessionContext.js";
3
+ import { currentSessionContext } from "#server/adapters/currentSessionContext.ts";
4
4
  import { SessionPolicy } from "./SessionPolicy.js";
5
5
  import { revalidateSession } from "./socketSession.js";
6
6
  export function revalidateStream(rpc, id, lookup) {
@@ -1 +1 @@
1
- {"version":3,"file":"revalidateStream.js","sourceRoot":"","sources":["../../src/server/revalidateStream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAe,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAY,SAAS,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,iBAAi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AC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;;AAJxG,qBAAa,aAAc,SAAQ,kBAMK;CAAG;AAE3C,eAAO,MAAM,iBAAiB;qBALX,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM;sBACtC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;sBAwBtG,CAAC;AAEH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,KAAK,8BAQjG"}
@@ -1,4 +1,5 @@
1
- import { Context, Deferred, Effect, Option } from "effect";
1
+ import { Context, Effect, Option } from "effect";
2
+ import { socketMonitor } from "#server/adapters/socketMonitor.ts";
2
3
  export class SocketSession extends Context.Service()("@shivaedev/identity/SocketSession") {
3
4
  }
4
5
  export const makeSocketSession = Effect.fnUntraced(function* (interval) {
@@ -14,13 +15,7 @@ export const makeSocketSession = Effect.fnUntraced(function* (interval) {
14
15
  }
15
16
  return yield* batch;
16
17
  }),
17
- monitor: (check) => Effect.gen(function* () {
18
- const context = yield* Effect.context();
19
- const ended = yield* Deferred.make();
20
- const run = check.pipe(Effect.provideContext(context), Effect.catchCause((cause) => Deferred.failCause(ended, cause)), Effect.asVoid);
21
- yield* Effect.acquireRelease(Effect.sync(() => checks.add(run)), () => Effect.sync(() => checks.delete(run)));
22
- return yield* Deferred.await(ended);
23
- }),
18
+ monitor: socketMonitor(checks),
24
19
  });
25
20
  });
26
21
  export function revalidateSession(check, interval) {
@@ -1 +1 @@
1
- {"version":3,"file":"socketSession.js","sourceRoot":"","sources":["../../src/server/socketSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAiB,MAAM,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AAQtF,MAAM,OAAO,aAAc,SAAQ,OAAO,CAAC,OAAO,EAM/C,CAAC,mCAAmC,CAAC;CAAG;AAE3C,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,QAAwB;IACrF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,MAAM,MAAM,GAAG,IAAI,GAAG,EAAuB,CAAC;IAC9C,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CACpB,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAC1B,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAChI,CACD,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC1B,OAAO,aAAa,CAAC,EAAE,CAAC;QACvB,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CACvB,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;YACnB,IAAI,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YAC7B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACzB,KAAK,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,OA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@ -108,9 +108,7 @@ export declare const Sessions: import("@shivaedev/contract/contract.ts").Contrac
108
108
  "~ClientError": never;
109
109
  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]>;
110
110
  requiredForClient: false;
111
- }), never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.revoke", Schema.Struct<{
112
- id: Schema.String;
113
- }>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable)[]>, typeof SessionsPermission, never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.list", Schema.Struct<{
111
+ }), never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.list", Schema.Struct<{
114
112
  readonly cursor: Schema.optionalKey<Schema.Struct<{
115
113
  readonly id: Schema.String;
116
114
  readonly lastActivityAt: Schema.DateTimeUtcFromString;
@@ -140,5 +138,7 @@ export declare const Sessions: import("@shivaedev/contract/contract.ts").Contrac
140
138
  "~ClientError": never;
141
139
  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]>;
142
140
  requiredForClient: false;
143
- }), never>, readonly [], undefined>;
141
+ }), never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.revoke", Schema.Struct<{
142
+ id: Schema.String;
143
+ }>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable)[]>, typeof SessionsPermission, never>, readonly [], undefined>;
144
144
  //# sourceMappingURL=sessions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIxC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAI5D,eAAO,MAAM,eAAe;;;;;;;;;;EAM1B,CAAC;AAEH,eAAO,MAAM,aAAa;;;EAAqF,CAAC;AAChH,eAAO,MAAM,gBAAgB;;;;;;EAG3B,CAAC;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;EAA2G,CAAC;AAEpI,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mCAiBY,CAAC"}
1
+ {"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIxC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAI5D,eAAO,MAAM,eAAe;;;;;;;;;;EAM1B,CAAC;AAEH,eAAO,MAAM,aAAa;;;EAAqF,CAAC;AAChH,eAAO,MAAM,gBAAgB;;;;;;EAG3B,CAAC;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;EAA2G,CAAC;AAEpI,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mKAiBY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/identity",
3
- "version": "0.26.2",
3
+ "version": "0.28.0",
4
4
  "description": "Request identity, sessions, transport trust and permission enforcement for Effect RPC servers",
5
5
  "keywords": [
6
6
  "effect"
@@ -45,34 +45,34 @@
45
45
  "README.md"
46
46
  ],
47
47
  "dependencies": {
48
- "@shivaedev/access": "0.5.1",
49
- "@shivaedev/changes": "0.10.1",
50
- "@shivaedev/contract": "0.37.0",
51
- "@shivaedev/errors": "0.9.1",
52
- "@shivaedev/rate-limit": "0.5.3",
53
- "@shivaedev/service": "0.7.1",
54
- "@shivaedev/sql": "0.41.0"
48
+ "@shivaedev/access": "0.6.0",
49
+ "@shivaedev/changes": "0.11.0",
50
+ "@shivaedev/contract": "0.40.0",
51
+ "@shivaedev/errors": "0.10.0",
52
+ "@shivaedev/rate-limit": "0.6.1",
53
+ "@shivaedev/service": "0.8.0",
54
+ "@shivaedev/sql": "0.43.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@better-auth/oauth-provider": "1.7.14",
58
- "@effect/platform-node": "4.0.7",
59
- "@effect/sql-pg": "4.0.7",
60
- "@shivaedev/admin": "0.20.4",
61
- "@shivaedev/quality": "0.63.0",
62
- "@shivaedev/server": "0.26.0",
63
- "@shivaedev/test-kits": "0.6.0",
64
- "@shivaedev/test-sql": "0.22.0",
65
- "@shivaedev/test-story": "0.40.0",
58
+ "@effect/platform-node": "4.1.0",
59
+ "@effect/sql-pg": "4.1.0",
60
+ "@shivaedev/admin": "0.21.1",
61
+ "@shivaedev/quality": "0.66.0",
62
+ "@shivaedev/server": "0.28.0",
63
+ "@shivaedev/test-kits": "0.8.1",
64
+ "@shivaedev/test-sql": "0.24.1",
65
+ "@shivaedev/test-story": "0.42.1",
66
66
  "@types/node": "24.19.2",
67
67
  "better-auth": "1.7.14",
68
- "effect": "4.0.7",
68
+ "effect": "4.1.0",
69
69
  "typescript": "7.0.2",
70
70
  "vitest": "5.0.5"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "@better-auth/oauth-provider": "1.7.14",
74
74
  "better-auth": "1.7.14",
75
- "effect": "4.0.7"
75
+ "effect": "4.1.0"
76
76
  },
77
77
  "peerDependenciesMeta": {
78
78
  "@better-auth/oauth-provider": {
@@ -0,0 +1,13 @@
1
+ import { DateTime, Effect } from "effect";
2
+
3
+ export const boundary = Effect.fn("AccountClock.boundary")((day: string, timezone: string, minutes: number) =>
4
+ Effect.sync(() =>
5
+ DateTime.toUtc(
6
+ DateTime.makeZonedUnsafe(`${day}T00:00:00.000Z`, {
7
+ adjustForTimeZone: true,
8
+ disambiguation: "compatible",
9
+ timeZone: timezone,
10
+ }).pipe(DateTime.setParts({ hour: Math.floor(minutes / 60), minute: minutes % 60 })),
11
+ ),
12
+ ),
13
+ );
@@ -1,12 +1,13 @@
1
1
  import { DateTime, Effect, Schema } from "effect";
2
+ import { boundary } from "./boundary.ts";
2
3
  import type { initialize } from "./initialize.ts";
3
4
  import { LogicalDay } from "./settings.ts";
4
5
 
5
- export function dayRange({ boundary }: Effect.Success<typeof initialize>) {
6
+ export function dayRange({ minutes, timezone }: Effect.Success<typeof initialize>) {
6
7
  const decodeDay = Schema.decodeUnknownEffect(LogicalDay);
7
- return Effect.fnUntraced(function* (day: string) {
8
+ return Effect.fn("AccountClock.dayRange")(function* (day: string) {
8
9
  yield* decodeDay(day);
9
10
  const next = DateTime.makeUnsafe(day).pipe(DateTime.add({ days: 1 }), DateTime.formatIsoDateUtc);
10
- return { end: boundary(next), start: boundary(day) };
11
+ return { end: yield* boundary(next, timezone, minutes), start: yield* boundary(day, timezone, minutes) };
11
12
  });
12
13
  }
@@ -1,5 +1,5 @@
1
- import { DateTime, Effect, Schema } from "effect";
2
- import { AccountPreferencesStore } from "#server/AccountPreferencesStore.ts";
1
+ import { Effect, Schema } from "effect";
2
+ import { AccountPreferencesStore } from "#server/account-preferences/service.ts";
3
3
  import { Subject } from "#subject.ts";
4
4
  import { AccountDayStart, DayStart } from "./settings.ts";
5
5
 
@@ -7,14 +7,5 @@ export const initialize = Effect.gen(function* () {
7
7
  const { id } = yield* Subject;
8
8
  const { timezone } = yield* (yield* AccountPreferencesStore).get(id);
9
9
  const minutes = yield* Schema.decodeUnknownEffect(DayStart)(yield* AccountDayStart);
10
- function boundary(day: string) {
11
- return DateTime.toUtc(
12
- DateTime.makeZonedUnsafe(`${day}T00:00:00.000Z`, {
13
- adjustForTimeZone: true,
14
- disambiguation: "compatible",
15
- timeZone: timezone,
16
- }).pipe(DateTime.setParts({ hour: Math.floor(minutes / 60), minute: minutes % 60 })),
17
- );
18
- }
19
- return { boundary, timezone };
10
+ return { minutes, timezone };
20
11
  });
@@ -1,11 +1,14 @@
1
1
  import { DateTime, Effect } from "effect";
2
+ import { boundary } from "./boundary.ts";
2
3
  import type { initialize } from "./initialize.ts";
3
4
 
4
- export function logicalDay({ boundary, timezone }: Effect.Success<typeof initialize>) {
5
- return Effect.fnUntraced(function* (instant?: DateTime.Utc) {
5
+ export function logicalDay({ minutes, timezone }: Effect.Success<typeof initialize>) {
6
+ return Effect.fn("AccountClock.logicalDay")(function* (instant?: DateTime.Utc) {
6
7
  const now = instant ?? (yield* DateTime.now);
7
8
  const local = DateTime.setZoneNamedUnsafe(now, timezone);
8
9
  const day = DateTime.formatIsoDate(local);
9
- return DateTime.isLessThan(now, boundary(day)) ? DateTime.makeUnsafe(day).pipe(DateTime.subtract({ days: 1 }), DateTime.formatIsoDateUtc) : day;
10
+ return DateTime.isLessThan(now, yield* boundary(day, timezone, minutes))
11
+ ? DateTime.makeUnsafe(day).pipe(DateTime.subtract({ days: 1 }), DateTime.formatIsoDateUtc)
12
+ : day;
10
13
  });
11
14
  }
@@ -1,10 +1,10 @@
1
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";
2
+ import { AccountPreferencesStore } from "#server/account-preferences/service.ts";
7
3
  import { Subject } from "#subject.ts";
4
+ import { dayRange } from "./dayRange.ts";
5
+ import { initialize } from "./initialize.ts";
6
+ import { logicalDay } from "./logicalDay.ts";
7
+ import { AccountDayStart } from "./settings.ts";
8
8
 
9
9
  export const AccountClock = defineService({
10
10
  id: "@shivaedev/identity/AccountClock",
@@ -1,5 +1,6 @@
1
- import { type Effect, Schema } from "effect";
1
+ import { Schema } from "effect";
2
2
  import { Model } from "effect/schema";
3
+ import { defineRepository } from "@shivaedev/sql/defineRepository.ts";
3
4
  import { makeRepository } from "@shivaedev/sql/repository.ts";
4
5
  import { AccountPreferenceValues } from "#accountPreferences.ts";
5
6
 
@@ -8,11 +9,14 @@ class StoredPreferences extends Model.Class<StoredPreferences>("AccountPreferenc
8
9
  ...AccountPreferenceValues.fields,
9
10
  }) {}
10
11
 
11
- export const initialize = makeRepository(StoredPreferences, {
12
+ const initialize = makeRepository(StoredPreferences, {
12
13
  conflictColumns: ["id"],
13
14
  idColumn: "id",
14
15
  spanPrefix: "AccountPreferences",
15
16
  tableName: "identity_account_preferences",
16
17
  });
17
18
 
18
- export type PreferencesRepository = Effect.Success<typeof initialize>;
19
+ export const AccountPreferenceRows = defineRepository({
20
+ id: "@shivaedev/identity/AccountPreferenceRows",
21
+ initialize,
22
+ });
@@ -1,10 +1,9 @@
1
1
  import { Effect } from "effect";
2
2
  import type { AccountPreferenceValues } from "#accountPreferences.ts";
3
3
  import { providerFailure } from "#server/providerFailure.ts";
4
- import type { PreferencesRepository } from "./initialize.ts";
4
+ import { AccountPreferenceRows } from "./Rows.ts";
5
5
 
6
- export function capture(repository: PreferencesRepository) {
7
- return Effect.fnUntraced(function* (id: string, values: typeof AccountPreferenceValues.Type) {
8
- return yield* repository.insertOrIgnore({ id, ...values }).pipe(Effect.asVoid, Effect.catch(providerFailure));
9
- });
10
- }
6
+ export const capture = Effect.fn("AccountPreferencesStore.capture")(function* (id: string, values: typeof AccountPreferenceValues.Type) {
7
+ const repository = yield* AccountPreferenceRows;
8
+ return yield* repository.insertOrIgnore({ id, ...values }).pipe(Effect.asVoid, Effect.catch(providerFailure));
9
+ });
@@ -1,13 +1,12 @@
1
1
  import { Effect } from "effect";
2
2
  import { providerFailure } from "#server/providerFailure.ts";
3
- import type { PreferencesRepository } from "./initialize.ts";
3
+ import { AccountPreferenceRows } from "./Rows.ts";
4
4
 
5
- export function get(repository: PreferencesRepository) {
6
- return Effect.fnUntraced(function* (id: string) {
7
- return yield* repository.findById(id).pipe(
8
- Effect.map(({ locale, timezone, units }) => ({ locale, timezone, units })),
9
- Effect.catchTag("NoSuchElementError", () => Effect.succeed({ locale: "en", timezone: "UTC", units: "metric" as const })),
10
- Effect.catch(providerFailure),
11
- );
12
- });
13
- }
5
+ export const get = Effect.fn("AccountPreferencesStore.get")(function* (id: string) {
6
+ const repository = yield* AccountPreferenceRows;
7
+ return yield* repository.findById(id).pipe(
8
+ Effect.map(({ locale, timezone, units }) => ({ locale, timezone, units })),
9
+ Effect.catchTag("NoSuchElementError", () => Effect.succeed({ locale: "en", timezone: "UTC", units: "metric" as const })),
10
+ Effect.catch(providerFailure),
11
+ );
12
+ });
@@ -0,0 +1,13 @@
1
+ import { Effect } from "effect";
2
+ import { defineService } from "@shivaedev/service/defineService.ts";
3
+ import { capture } from "./capture.ts";
4
+ import { get } from "./get.ts";
5
+ import { AccountPreferenceRows } from "./Rows.ts";
6
+ import { set } from "./set.ts";
7
+
8
+ export const AccountPreferencesStore = defineService({
9
+ id: "@shivaedev/identity/AccountPreferencesStore",
10
+ initialize: Effect.void,
11
+ methods: () => ({ capture, get, set }),
12
+ requires: [AccountPreferenceRows],
13
+ });
@@ -1,12 +1,11 @@
1
1
  import { Effect } from "effect";
2
2
  import type { AccountPreferenceValues } from "#accountPreferences.ts";
3
3
  import { providerFailure } from "#server/providerFailure.ts";
4
- import type { PreferencesRepository } from "./initialize.ts";
4
+ import { AccountPreferenceRows } from "./Rows.ts";
5
5
 
6
- export function set(repository: PreferencesRepository) {
7
- return Effect.fnUntraced(function* (id: string, values: typeof AccountPreferenceValues.Type) {
8
- return yield* repository
9
- .upsert({ id, ...values }, { updateColumns: ["locale", "timezone", "units"] })
10
- .pipe(Effect.asVoid, Effect.catch(providerFailure));
11
- });
12
- }
6
+ export const set = Effect.fn("AccountPreferencesStore.set")(function* (id: string, values: typeof AccountPreferenceValues.Type) {
7
+ const repository = yield* AccountPreferenceRows;
8
+ return yield* repository
9
+ .upsert({ id, ...values }, { updateColumns: ["locale", "timezone", "units"] })
10
+ .pipe(Effect.asVoid, Effect.catch(providerFailure));
11
+ });
@@ -0,0 +1,5 @@
1
+ import { Layer } from "effect";
2
+ import { AccountPreferenceRows } from "./Rows.ts";
3
+ import { AccountPreferencesStore } from "./service.ts";
4
+
5
+ export const accountPreferencesStore = AccountPreferencesStore.layer.pipe(Layer.provide(AccountPreferenceRows.layer));
@@ -1,6 +1,6 @@
1
1
  import { Effect } from "effect";
2
2
  import { AccountPreferences } from "#accountPreferences.ts";
3
- import { AccountPreferencesStore } from "#server/AccountPreferencesStore.ts";
3
+ import { AccountPreferencesStore } from "#server/account-preferences/service.ts";
4
4
  import { Subject } from "#subject.ts";
5
5
 
6
6
  export const accountPreferencesHandlers = AccountPreferences.application.toLayer({
@@ -1,8 +1,8 @@
1
1
  import { Context, Effect, Option, Schema } from "effect";
2
2
  import { type AuthUnavailable, type Forbidden, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
3
3
  import { SessionUser, SessionUserSchema, SessionUserWithProviderAccounts } from "#identity.ts";
4
- import { providerAccountsUser } from "./providerAccountsUser.ts";
5
- import type { SessionShape } from "./session.ts";
4
+ import { providerAccountsUser } from "#server/providerAccountsUser.ts";
5
+ import type { SessionShape } from "#server/session.ts";
6
6
 
7
7
  export const currentSessionContext = Effect.fnUntraced(function* <TSession extends SessionShape, R, E = AuthUnavailable | Forbidden>(
8
8
  id: string,
@@ -0,0 +1,43 @@
1
+ import { Effect } from "effect";
2
+ import { HttpServerRequest, HttpServerResponse } from "effect/http";
3
+ import * as HttpStatus from "effect/http/HttpStatus";
4
+ import type { Permission } from "@shivaedev/access/permission.ts";
5
+ import { requirePermission } from "@shivaedev/access/requirePermission.ts";
6
+ import type { AuthUnavailable, Forbidden, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
7
+ import { type Identity, SessionUser } from "#identity.ts";
8
+ import type { SessionPolicy } from "#server/SessionPolicy.ts";
9
+ import { withSessionUser } from "#server/session.ts";
10
+
11
+ function rejection(error: Unauthorized | Forbidden | AuthUnavailable) {
12
+ return HttpServerResponse.empty({
13
+ headers: { "cache-control": "private, no-store" },
14
+ status: {
15
+ AuthUnavailable: HttpStatus.fromLiteral("ServiceUnavailable"),
16
+ Forbidden: HttpStatus.fromLiteral("Forbidden"),
17
+ Unauthorized: HttpStatus.fromLiteral("Unauthorized"),
18
+ }[error._tag],
19
+ });
20
+ }
21
+
22
+ export function permissionRoute(permission: Permission) {
23
+ return <E, R>(
24
+ handler: Effect.Effect<HttpServerResponse.HttpServerResponse, E, R>,
25
+ ): Effect.Effect<
26
+ HttpServerResponse.HttpServerResponse,
27
+ E,
28
+ HttpServerRequest.HttpServerRequest | SessionPolicy | Exclude<R, Identity | SessionUser>
29
+ > =>
30
+ Effect.gen(function* () {
31
+ const request = yield* HttpServerRequest.HttpServerRequest;
32
+ return yield* Effect.andThen(
33
+ Effect.flatMap(SessionUser, (user) => requirePermission(user, permission)),
34
+ Effect.context<Identity | SessionUser>(),
35
+ ).pipe(
36
+ withSessionUser(request.headers, request.url),
37
+ Effect.matchEffect({
38
+ onFailure: (error) => Effect.succeed(rejection(error)),
39
+ onSuccess: (context) => Effect.provideContext(handler, context),
40
+ }),
41
+ );
42
+ });
43
+ }
@@ -0,0 +1,19 @@
1
+ import { Deferred, Effect } from "effect";
2
+
3
+ export function socketMonitor(checks: Set<Effect.Effect<void>>) {
4
+ return <E, R>(check: Effect.Effect<void, E, R>) =>
5
+ Effect.gen(function* () {
6
+ const context = yield* Effect.context<R>();
7
+ const ended = yield* Deferred.make<never, E>();
8
+ const run = check.pipe(
9
+ Effect.provideContext(context),
10
+ Effect.catchCause((cause) => Deferred.failCause(ended, cause)),
11
+ Effect.asVoid,
12
+ );
13
+ yield* Effect.acquireRelease(
14
+ Effect.sync(() => checks.add(run)),
15
+ () => Effect.sync(() => checks.delete(run)),
16
+ );
17
+ return yield* Deferred.await(ended);
18
+ });
19
+ }
@@ -2,7 +2,7 @@ import type { BetterAuthOptions, BetterAuthPlugin } from "better-auth";
2
2
  import { createAuthMiddleware } from "better-auth/api";
3
3
  import { Effect, Option, Schema } from "effect";
4
4
  import { AccountPreferenceValues } from "#accountPreferences.ts";
5
- import { AccountPreferencesStore } from "#server/AccountPreferencesStore.ts";
5
+ import { AccountPreferencesStore } from "#server/account-preferences/service.ts";
6
6
 
7
7
  export const accountPreferenceOptions = Effect.fnUntraced(function* <TOptions extends BetterAuthOptions>(options: TOptions) {
8
8
  const store = yield* AccountPreferencesStore;
@@ -3,8 +3,8 @@ import { SqlClient, SqlSchema } from "effect/sql";
3
3
  import type { AccessPolicy } from "@shivaedev/access/roleSet.ts";
4
4
  import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
5
5
  import type { ProviderAccountValue } from "#identity.ts";
6
- import { type AuthTableOptions, tables } from "#server/better-auth/adapters/tables.ts";
7
- import { assignRole } from "./assignRole.ts";
6
+ import { assignRole } from "#server/better-auth/assignRole.ts";
7
+ import { type AuthTableOptions, tables } from "./tables.ts";
8
8
 
9
9
  export interface AccountRoleSeed<E> {
10
10
  readonly onSignIn: (userId: string) => Effect.Effect<void, E>;
@@ -2,8 +2,8 @@ import type { BetterAuthOptions } from "better-auth";
2
2
  import { Effect, Layer, type Scope } from "effect";
3
3
  import type { RoleSet } from "@shivaedev/access/roleSet.ts";
4
4
  import type { Store } from "@shivaedev/rate-limit/Store.ts";
5
- import { AccountPreferencesStore } from "#server/AccountPreferencesStore.ts";
6
- import type { AccountRoleSeed } from "#server/better-auth/accountRoleSeed.ts";
5
+ import { accountPreferencesStore } from "#server/account-preferences/store.ts";
6
+ import type { AccountRoleSeed } from "#server/better-auth/adapters/accountRoleSeed.ts";
7
7
  import { type BearerSessionsOptions, withBearerSessions } from "#server/better-auth/adapters/bearerSessions.ts";
8
8
  import { closeRoleEndpoints } from "#server/better-auth/adapters/closeRoleEndpoints.ts";
9
9
  import { effectHookOptions } from "#server/better-auth/adapters/effectHookOptions.ts";
@@ -62,7 +62,7 @@ const mountAuth = Effect.fn("Identity.mountAuth")(function* <const TOptions exte
62
62
  const gate = yield* signInGate(policy);
63
63
  const runtime = yield* hookRuntime<R>();
64
64
  const preferences =
65
- mount.accountPreferences === true ? yield* accountPreferenceOptions(options).pipe(Effect.provide(AccountPreferencesStore.layer)) : options;
65
+ mount.accountPreferences === true ? yield* accountPreferenceOptions(options).pipe(Effect.provide(accountPreferencesStore)) : options;
66
66
  const reset = passwordResetOptions(preferences, mount.onPasswordReset, runtime);
67
67
  const hooked = effectHookOptions(yield* emailOptions(reset, mount.emails, runtime), mount.databaseHooks, runtime);
68
68
  const configured = mount.roles === undefined ? hooked : storedRoleOptions(closeRoleEndpoints(hooked), mount);
@@ -3,7 +3,7 @@ import { APIError } from "better-auth/api";
3
3
  import { Effect, Exit } from "effect";
4
4
  import { redact } from "@shivaedev/errors/redact.ts";
5
5
  import { authRefusals } from "#authRefusal.ts";
6
- import type { AccountRoleSeed } from "#server/better-auth/accountRoleSeed.ts";
6
+ import type { AccountRoleSeed } from "#server/better-auth/adapters/accountRoleSeed.ts";
7
7
 
8
8
  export function roleSeedOptions<E>(options: BetterAuthOptions, seed: AccountRoleSeed<E> | undefined): BetterAuthOptions {
9
9
  if (seed === undefined) {
@@ -1,4 +1,5 @@
1
- import { Crypto, type Duration, Effect, Option, Redacted } from "effect";
1
+ import { type Duration, Effect, Option, Redacted } from "effect";
2
+ import { SecureRandom } from "effect/crypto";
2
3
  import * as Hex from "effect/encoding/Hex";
3
4
  import type { RoleSet } from "@shivaedev/access/roleSet.ts";
4
5
  import type { SessionUserValue } from "#identity.ts";
@@ -13,8 +14,8 @@ export const localOwner = Effect.fn("Identity.localOwner")(function* (options: {
13
14
  }) {
14
15
  const { owner, roles } = options;
15
16
  const access = yield* roles.resolve(owner.role);
16
- const crypto = yield* Crypto.Crypto;
17
- const token = Redacted.make(Hex.encode(yield* crypto.randomBytes(32)));
17
+ const random = yield* SecureRandom.SecureRandom;
18
+ const token = Redacted.make(Hex.encode(yield* random.randomBytes(32)));
18
19
  const machines = yield* machineTokens({ owner, roles });
19
20
  const allowed = localTransport();
20
21
  const sessions: SessionPolicy["Service"] = {
@@ -1,4 +1,5 @@
1
- import { Crypto, Effect, Option, Redacted, Schema } from "effect";
1
+ import { Effect, Option, Redacted, Schema } from "effect";
2
+ import { Digest, SecureRandom } from "effect/crypto";
2
3
  import * as Hex from "effect/encoding/Hex";
3
4
  import { Model } from "effect/schema";
4
5
  import type { RoleSet } from "@shivaedev/access/roleSet.ts";
@@ -17,19 +18,20 @@ export const machineTokens = Effect.fn("Identity.machineTokens")(function* (opti
17
18
  readonly owner: Pick<SessionUserValue, "id" | "name" | "email">;
18
19
  readonly roles: RoleSet;
19
20
  }) {
20
- const crypto = yield* Crypto.Crypto;
21
+ const random = yield* SecureRandom.SecureRandom;
22
+ const hashes = yield* Digest.Digest;
21
23
  const repository = yield* makeRepository(MachineToken, {
22
24
  idColumn: "id",
23
25
  spanPrefix: "MachineTokens",
24
26
  tableName: "identity_machine_tokens",
25
27
  });
26
28
  function digest(token: string) {
27
- return crypto.digest("SHA-256", new TextEncoder().encode(token)).pipe(Effect.map(Hex.encode));
29
+ return hashes.digestHex(Digest.sha256, new TextEncoder().encode(token));
28
30
  }
29
31
  return {
30
32
  issue: Effect.fn("MachineTokens.issue")(function* (input: { readonly name: string; readonly scope: string }) {
31
33
  yield* options.roles.resolve(input.scope);
32
- const token = Hex.encode(yield* crypto.randomBytes(32));
34
+ const token = Hex.encode(yield* random.randomBytes(32));
33
35
  const id = yield* digest(token);
34
36
  yield* repository.insertVoid({ id, name: input.name, ownerId: options.owner.id, scope: input.scope });
35
37
  return { id, ...input, token: Redacted.make(token) };