@shivaedev/identity 0.27.0 → 0.29.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.
- package/CHANGELOG.md +15 -0
- package/README.md +43 -42
- package/dist/accountPreferences.d.ts +24 -15
- package/dist/accountPreferences.d.ts.map +1 -1
- package/dist/server/account-clock/boundary.d.ts +3 -0
- package/dist/server/account-clock/boundary.d.ts.map +1 -0
- package/dist/server/account-clock/boundary.js +7 -0
- package/dist/server/account-clock/boundary.js.map +1 -0
- package/dist/server/account-clock/dayRange.d.ts +1 -1
- package/dist/server/account-clock/dayRange.d.ts.map +1 -1
- package/dist/server/account-clock/dayRange.js +4 -3
- package/dist/server/account-clock/dayRange.js.map +1 -1
- package/dist/server/account-clock/initialize.d.ts +2 -2
- package/dist/server/account-clock/initialize.d.ts.map +1 -1
- package/dist/server/account-clock/initialize.js +3 -10
- package/dist/server/account-clock/initialize.js.map +1 -1
- package/dist/server/account-clock/logicalDay.d.ts +1 -1
- package/dist/server/account-clock/logicalDay.d.ts.map +1 -1
- package/dist/server/account-clock/logicalDay.js +6 -3
- package/dist/server/account-clock/logicalDay.js.map +1 -1
- package/dist/server/{AccountClock.d.ts → account-clock/service.d.ts} +1 -1
- package/dist/server/account-clock/service.d.ts.map +1 -0
- package/dist/server/account-clock/service.js +14 -0
- package/dist/server/account-clock/service.js.map +1 -0
- package/dist/server/account-preferences/{initialize.d.ts → Rows.d.ts} +7 -6
- package/dist/server/account-preferences/Rows.d.ts.map +1 -0
- package/dist/server/account-preferences/{initialize.js → Rows.js} +7 -2
- package/dist/server/account-preferences/Rows.js.map +1 -0
- package/dist/server/account-preferences/capture.d.ts +2 -3
- package/dist/server/account-preferences/capture.d.ts.map +1 -1
- package/dist/server/account-preferences/capture.js +5 -5
- package/dist/server/account-preferences/capture.js.map +1 -1
- package/dist/server/account-preferences/get.d.ts +2 -3
- package/dist/server/account-preferences/get.d.ts.map +1 -1
- package/dist/server/account-preferences/get.js +5 -5
- package/dist/server/account-preferences/get.js.map +1 -1
- package/dist/server/{AccountPreferencesStore.d.ts → account-preferences/service.d.ts} +6 -6
- package/dist/server/account-preferences/service.d.ts.map +1 -0
- package/dist/server/account-preferences/service.js +13 -0
- package/dist/server/account-preferences/service.js.map +1 -0
- package/dist/server/account-preferences/set.d.ts +2 -3
- package/dist/server/account-preferences/set.d.ts.map +1 -1
- package/dist/server/account-preferences/set.js +7 -7
- package/dist/server/account-preferences/set.js.map +1 -1
- package/dist/server/account-preferences/store.d.ts +3 -0
- package/dist/server/account-preferences/store.d.ts.map +1 -0
- package/dist/server/account-preferences/store.js +5 -0
- package/dist/server/account-preferences/store.js.map +1 -0
- package/dist/server/accountPreferencesHandlers.js +1 -1
- package/dist/server/accountPreferencesHandlers.js.map +1 -1
- package/dist/server/{currentSessionContext.d.ts → adapters/currentSessionContext.d.ts} +1 -1
- package/dist/server/adapters/currentSessionContext.d.ts.map +1 -0
- package/dist/server/{currentSessionContext.js → adapters/currentSessionContext.js} +1 -1
- package/dist/server/adapters/currentSessionContext.js.map +1 -0
- package/dist/server/adapters/permissionRoute.d.ts +7 -0
- package/dist/server/adapters/permissionRoute.d.ts.map +1 -0
- package/dist/server/adapters/permissionRoute.js +26 -0
- package/dist/server/adapters/permissionRoute.js.map +1 -0
- package/dist/server/adapters/socketMonitor.d.ts +3 -0
- package/dist/server/adapters/socketMonitor.d.ts.map +1 -0
- package/dist/server/adapters/socketMonitor.js +11 -0
- package/dist/server/adapters/socketMonitor.js.map +1 -0
- package/dist/server/better-auth/adapters/accountPreferenceOptions.js +1 -1
- package/dist/server/better-auth/adapters/accountPreferenceOptions.js.map +1 -1
- package/dist/server/better-auth/{accountRoleSeed.d.ts → adapters/accountRoleSeed.d.ts} +3 -3
- package/dist/server/better-auth/adapters/accountRoleSeed.d.ts.map +1 -0
- package/dist/server/better-auth/{accountRoleSeed.js → adapters/accountRoleSeed.js} +2 -2
- package/dist/server/better-auth/adapters/accountRoleSeed.js.map +1 -0
- package/dist/server/better-auth/adapters/{clientIp.d.ts → clientIpHeaders.d.ts} +1 -1
- package/dist/server/better-auth/adapters/clientIpHeaders.d.ts.map +1 -0
- package/dist/server/better-auth/adapters/{clientIp.js → clientIpHeaders.js} +1 -1
- package/dist/server/better-auth/adapters/clientIpHeaders.js.map +1 -0
- package/dist/server/better-auth/adapters/mount.d.ts +1 -1
- package/dist/server/better-auth/adapters/mount.d.ts.map +1 -1
- package/dist/server/better-auth/adapters/mount.js +2 -2
- package/dist/server/better-auth/adapters/mount.js.map +1 -1
- package/dist/server/better-auth/adapters/mountSettings.js +1 -1
- package/dist/server/better-auth/adapters/mountSettings.js.map +1 -1
- package/dist/server/better-auth/adapters/roleSeedOptions.d.ts +1 -1
- package/dist/server/better-auth/adapters/roleSeedOptions.d.ts.map +1 -1
- package/dist/server/better-auth/adapters/routeHandler.js +1 -1
- package/dist/server/better-auth/adapters/routeHandler.js.map +1 -1
- package/dist/server/{permissions.d.ts → permissionLayer.d.ts} +2 -4
- package/dist/server/permissionLayer.d.ts.map +1 -0
- package/dist/server/{permissions.js → permissionLayer.js} +1 -19
- package/dist/server/permissionLayer.js.map +1 -0
- package/dist/server/revalidateStream.js +1 -1
- package/dist/server/revalidateStream.js.map +1 -1
- package/dist/server/socketSession.d.ts.map +1 -1
- package/dist/server/socketSession.js +3 -8
- package/dist/server/socketSession.js.map +1 -1
- package/dist/sessions.d.ts +26 -5
- package/dist/sessions.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/server/account-clock/boundary.ts +13 -0
- package/src/server/account-clock/dayRange.ts +4 -3
- package/src/server/account-clock/initialize.ts +3 -12
- package/src/server/account-clock/logicalDay.ts +6 -3
- package/src/server/{AccountClock.ts → account-clock/service.ts} +5 -5
- package/src/server/account-preferences/{initialize.ts → Rows.ts} +7 -3
- package/src/server/account-preferences/capture.ts +5 -6
- package/src/server/account-preferences/get.ts +9 -10
- package/src/server/account-preferences/service.ts +13 -0
- package/src/server/account-preferences/set.ts +7 -8
- package/src/server/account-preferences/store.ts +5 -0
- package/src/server/accountPreferencesHandlers.ts +1 -1
- package/src/server/{currentSessionContext.ts → adapters/currentSessionContext.ts} +2 -2
- package/src/server/adapters/permissionRoute.ts +43 -0
- package/src/server/adapters/socketMonitor.ts +19 -0
- package/src/server/better-auth/adapters/accountPreferenceOptions.ts +1 -1
- package/src/server/better-auth/{accountRoleSeed.ts → adapters/accountRoleSeed.ts} +2 -2
- package/src/server/better-auth/adapters/mount.ts +3 -3
- package/src/server/better-auth/adapters/mountSettings.ts +1 -1
- package/src/server/better-auth/adapters/roleSeedOptions.ts +1 -1
- package/src/server/better-auth/adapters/routeHandler.ts +1 -1
- package/src/server/{permissions.ts → permissionLayer.ts} +0 -30
- package/src/server/revalidateStream.ts +1 -1
- package/src/server/socketSession.ts +3 -16
- package/dist/server/AccountClock.d.ts.map +0 -1
- package/dist/server/AccountClock.js +0 -14
- package/dist/server/AccountClock.js.map +0 -1
- package/dist/server/AccountPreferencesStore.d.ts.map +0 -1
- package/dist/server/AccountPreferencesStore.js +0 -13
- package/dist/server/AccountPreferencesStore.js.map +0 -1
- package/dist/server/account-preferences/initialize.d.ts.map +0 -1
- package/dist/server/account-preferences/initialize.js.map +0 -1
- package/dist/server/better-auth/accountRoleSeed.d.ts.map +0 -1
- package/dist/server/better-auth/accountRoleSeed.js.map +0 -1
- package/dist/server/better-auth/adapters/clientIp.d.ts.map +0 -1
- package/dist/server/better-auth/adapters/clientIp.js.map +0 -1
- package/dist/server/currentSessionContext.d.ts.map +0 -1
- package/dist/server/currentSessionContext.js.map +0 -1
- package/dist/server/permissions.d.ts.map +0 -1
- package/dist/server/permissions.js.map +0 -1
- package/src/server/AccountPreferencesStore.ts +0 -13
- /package/src/server/better-auth/adapters/{clientIp.ts → clientIpHeaders.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { RpcSchema } from "effect/rpc";
|
|
3
|
-
import { currentSessionContext } from "
|
|
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,
|
|
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,2CAA2C,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,UAAU,gBAAgB,CAC/B,GAAqB,EACrB,EAAU,EACV,MAAiF;IAEjF,OAAO,CAAU,MAA8B,EAAE,EAAE;QAClD,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;YAClD,OAAO,MAAM,CAAC;QACf,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,qBAAqB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;QAC/D,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,MAAM,EAAE,EAAE,CAC/C,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,0BAA0B,IAAI,YAAY,CAAC,CAAC,CACrG,CAAC;IACH,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"socketSession.d.ts","sourceRoot":"","sources":["../../src/server/socketSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"socketSession.d.ts","sourceRoot":"","sources":["../../src/server/socketSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAEhF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,MAAM,eAAe,GAAG,YAAY,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE;QAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,UAAU,EAAE,CAAA;KAAE,CAAA;CAAE,CAAC;AACjH,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,EAAE,eAAe,GAAG,SAAS,CAAC,CAAC;;qBAKtE,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;;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,
|
|
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: (
|
|
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,
|
|
1
|
+
{"version":3,"file":"socketSession.js","sourceRoot":"","sources":["../../src/server/socketSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAiB,MAAM,EAAE,MAAM,EAAc,MAAM,QAAQ,CAAC;AAG5E,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAMlE,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,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACpI,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACzB,CAAC;YACD,OAAO,KAAK,CAAC,CAAC,KAAK,CAAC;QACrB,CAAC,CAAC;QACH,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC;KAC9B,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,UAAU,iBAAiB,CAAO,KAAgC,EAAE,QAAwB;IACjG,OAAO,MAAM,CAAC,OAAO,CACpB,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,EACnC,MAAM,CAAC,KAAK,CAAC;QACZ,MAAM,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;QAChF,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;KACxD,CAAC,CACF,CAAC;AACH,CAAC"}
|
package/dist/sessions.d.ts
CHANGED
|
@@ -100,7 +100,28 @@ export declare const Sessions: import("@shivaedev/contract/contract.ts").Contrac
|
|
|
100
100
|
readonly queryIndexes: Schema.optional<Schema.$Array<Schema.Number>>;
|
|
101
101
|
}>, Schema.Struct<{
|
|
102
102
|
readonly _tag: Schema.Literal<"Resync">;
|
|
103
|
-
}>]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, ...
|
|
103
|
+
}>]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, ...Schema.Struct<{
|
|
104
|
+
_tag: Schema.Literal<"Result">;
|
|
105
|
+
query: Schema.Literal<"list">;
|
|
106
|
+
queryIndex: Schema.Number;
|
|
107
|
+
value: Schema.Struct<{
|
|
108
|
+
readonly next: Schema.OptionFromNullOr<Schema.Struct<{
|
|
109
|
+
readonly id: Schema.String;
|
|
110
|
+
readonly lastActivityAt: Schema.DateTimeUtcFromString;
|
|
111
|
+
}>>;
|
|
112
|
+
readonly sessions: Schema.$Array<Schema.Struct<{
|
|
113
|
+
readonly expiresAt: Schema.DateTimeUtcFromDate;
|
|
114
|
+
readonly id: Schema.String;
|
|
115
|
+
readonly lastActivityAt: Schema.DateTimeUtcFromDate;
|
|
116
|
+
readonly startedAt: Schema.DateTimeUtcFromDate;
|
|
117
|
+
readonly user: Schema.Struct<{
|
|
118
|
+
readonly email: Schema.String;
|
|
119
|
+
readonly id: Schema.String;
|
|
120
|
+
readonly name: Schema.String;
|
|
121
|
+
}>;
|
|
122
|
+
}>>;
|
|
123
|
+
}>;
|
|
124
|
+
}>[]]>, 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 Forbidden | typeof AuthUnavailable)[]>[]]>>, Schema.Never, typeof SessionsPermission | (import("effect/Context").Reference<<A, E, R>(effect: Effect.Effect<A, E, R>, request: {
|
|
104
125
|
readonly rpc: import("effect/rpc/Rpc").Any;
|
|
105
126
|
readonly payload: unknown;
|
|
106
127
|
}) => 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>> & {
|
|
@@ -108,7 +129,9 @@ export declare const Sessions: import("@shivaedev/contract/contract.ts").Contrac
|
|
|
108
129
|
"~ClientError": never;
|
|
109
130
|
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
131
|
requiredForClient: false;
|
|
111
|
-
}), never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.
|
|
132
|
+
}), never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.revoke", Schema.Struct<{
|
|
133
|
+
id: Schema.String;
|
|
134
|
+
}>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable)[]>, typeof SessionsPermission, never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.list", Schema.Struct<{
|
|
112
135
|
readonly cursor: Schema.optionalKey<Schema.Struct<{
|
|
113
136
|
readonly id: Schema.String;
|
|
114
137
|
readonly lastActivityAt: Schema.DateTimeUtcFromString;
|
|
@@ -138,7 +161,5 @@ export declare const Sessions: import("@shivaedev/contract/contract.ts").Contrac
|
|
|
138
161
|
"~ClientError": never;
|
|
139
162
|
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]>;
|
|
140
163
|
requiredForClient: false;
|
|
141
|
-
}), never
|
|
142
|
-
id: Schema.String;
|
|
143
|
-
}>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable)[]>, typeof SessionsPermission, never>, readonly [], undefined>;
|
|
164
|
+
}), never>, readonly [], undefined>;
|
|
144
165
|
//# sourceMappingURL=sessions.d.ts.map
|
package/dist/sessions.d.ts.map
CHANGED
|
@@ -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
|
|
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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/identity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "Request identity, sessions, transport trust and permission enforcement for Effect RPC servers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -47,22 +47,22 @@
|
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@shivaedev/access": "0.6.0",
|
|
49
49
|
"@shivaedev/changes": "0.11.0",
|
|
50
|
-
"@shivaedev/contract": "0.
|
|
50
|
+
"@shivaedev/contract": "0.41.0",
|
|
51
51
|
"@shivaedev/errors": "0.10.0",
|
|
52
|
-
"@shivaedev/rate-limit": "0.6.
|
|
52
|
+
"@shivaedev/rate-limit": "0.6.2",
|
|
53
53
|
"@shivaedev/service": "0.8.0",
|
|
54
|
-
"@shivaedev/sql": "0.
|
|
54
|
+
"@shivaedev/sql": "0.44.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@better-auth/oauth-provider": "1.7.14",
|
|
58
58
|
"@effect/platform-node": "4.1.0",
|
|
59
59
|
"@effect/sql-pg": "4.1.0",
|
|
60
|
-
"@shivaedev/admin": "0.
|
|
61
|
-
"@shivaedev/quality": "0.
|
|
62
|
-
"@shivaedev/server": "0.
|
|
63
|
-
"@shivaedev/test-kits": "0.
|
|
64
|
-
"@shivaedev/test-sql": "0.24.
|
|
65
|
-
"@shivaedev/test-story": "0.
|
|
60
|
+
"@shivaedev/admin": "0.22.0",
|
|
61
|
+
"@shivaedev/quality": "0.67.0",
|
|
62
|
+
"@shivaedev/server": "0.29.0",
|
|
63
|
+
"@shivaedev/test-kits": "0.9.0",
|
|
64
|
+
"@shivaedev/test-sql": "0.24.2",
|
|
65
|
+
"@shivaedev/test-story": "0.43.0",
|
|
66
66
|
"@types/node": "24.19.2",
|
|
67
67
|
"better-auth": "1.7.14",
|
|
68
68
|
"effect": "4.1.0",
|
|
@@ -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({
|
|
6
|
+
export function dayRange({ minutes, timezone }: Effect.Success<typeof initialize>) {
|
|
6
7
|
const decodeDay = Schema.decodeUnknownEffect(LogicalDay);
|
|
7
|
-
return Effect.
|
|
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 {
|
|
2
|
-
import { AccountPreferencesStore } from "#server/
|
|
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
|
-
|
|
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({
|
|
5
|
-
return Effect.
|
|
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
|
|
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/
|
|
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 {
|
|
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
|
-
|
|
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
|
|
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
|
|
4
|
+
import { AccountPreferenceRows } from "./Rows.ts";
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
3
|
+
import { AccountPreferenceRows } from "./Rows.ts";
|
|
4
4
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
4
|
+
import { AccountPreferenceRows } from "./Rows.ts";
|
|
5
5
|
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { AccountPreferences } from "#accountPreferences.ts";
|
|
3
|
-
import { AccountPreferencesStore } from "#server/
|
|
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 "
|
|
5
|
-
import type { SessionShape } from "
|
|
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/
|
|
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 {
|
|
7
|
-
import {
|
|
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 {
|
|
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(
|
|
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);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BetterAuthOptions } from "better-auth";
|
|
2
2
|
import { Config, Effect, Option, Redacted } from "effect";
|
|
3
|
-
import { PEER_IP_HEADER } from "#server/better-auth/adapters/
|
|
3
|
+
import { PEER_IP_HEADER } from "#server/better-auth/adapters/clientIpHeaders.ts";
|
|
4
4
|
|
|
5
5
|
export const mountSettings = Effect.fnUntraced(function* (options: BetterAuthOptions, clientIp?: "railway") {
|
|
6
6
|
const secret = options.secret ?? Redacted.value(yield* Config.Redacted("BETTER_AUTH_SECRET"));
|
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
3
3
|
import * as HttpStatus from "effect/http/HttpStatus";
|
|
4
|
-
import { clientIpHeaders } from "#server/better-auth/adapters/
|
|
4
|
+
import { clientIpHeaders } from "#server/better-auth/adapters/clientIpHeaders.ts";
|
|
5
5
|
import { type MountedAuth, type MountRouteOptions, response } from "#server/better-auth/adapters/response.ts";
|
|
6
6
|
import { providerFailure } from "#server/providerFailure.ts";
|
|
7
7
|
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { type Context, Effect, Layer, Option } from "effect";
|
|
2
|
-
import { type HttpServerRequest, HttpServerResponse } from "effect/http";
|
|
3
|
-
import * as HttpStatus from "effect/http/HttpStatus";
|
|
4
2
|
import type { RpcMiddleware } from "effect/rpc";
|
|
5
3
|
import type { Permission } from "@shivaedev/access/permission.ts";
|
|
6
4
|
import { forbidden } from "@shivaedev/access/refusal.ts";
|
|
7
5
|
import { requirePermission } from "@shivaedev/access/requirePermission.ts";
|
|
8
|
-
import type { AuthUnavailable, Forbidden, Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
9
6
|
import { Identity, SessionUser } from "#identity.ts";
|
|
10
7
|
import type { IdentityFailures } from "#middleware.ts";
|
|
11
8
|
import { hasPermission } from "#permission.ts";
|
|
@@ -42,30 +39,3 @@ export function permissionLayer<TMiddleware>(
|
|
|
42
39
|
}),
|
|
43
40
|
);
|
|
44
41
|
}
|
|
45
|
-
function rejection(error: Unauthorized | Forbidden | AuthUnavailable) {
|
|
46
|
-
return HttpServerResponse.empty({
|
|
47
|
-
headers: { "cache-control": "private, no-store" },
|
|
48
|
-
status: {
|
|
49
|
-
AuthUnavailable: HttpStatus.fromLiteral("ServiceUnavailable"),
|
|
50
|
-
Forbidden: HttpStatus.fromLiteral("Forbidden"),
|
|
51
|
-
Unauthorized: HttpStatus.fromLiteral("Unauthorized"),
|
|
52
|
-
}[error._tag],
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function permissionRoute(permission: Permission) {
|
|
57
|
-
return <E, R>(handler: (request: HttpServerRequest.HttpServerRequest) => Effect.Effect<HttpServerResponse.HttpServerResponse, E, R>) =>
|
|
58
|
-
(
|
|
59
|
-
request: HttpServerRequest.HttpServerRequest,
|
|
60
|
-
): Effect.Effect<HttpServerResponse.HttpServerResponse, E, SessionPolicy | Exclude<R, Identity | SessionUser>> =>
|
|
61
|
-
Effect.andThen(
|
|
62
|
-
Effect.flatMap(SessionUser, (user) => requirePermission(user, permission)),
|
|
63
|
-
Effect.context<Identity | SessionUser>(),
|
|
64
|
-
).pipe(
|
|
65
|
-
withSessionUser(request.headers, request.url),
|
|
66
|
-
Effect.matchEffect({
|
|
67
|
-
onFailure: (error) => Effect.succeed(rejection(error)),
|
|
68
|
-
onSuccess: (context) => Effect.provideContext(handler(request), context),
|
|
69
|
-
}),
|
|
70
|
-
);
|
|
71
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, type Option } from "effect";
|
|
2
2
|
import { type Rpc, RpcSchema } from "effect/rpc";
|
|
3
3
|
import type { AuthUnavailable, Forbidden } from "@shivaedev/errors/taxonomy.ts";
|
|
4
|
-
import { currentSessionContext } from "
|
|
4
|
+
import { currentSessionContext } from "#server/adapters/currentSessionContext.ts";
|
|
5
5
|
import { SessionPolicy } from "./SessionPolicy.ts";
|
|
6
6
|
import type { SessionShape } from "./session.ts";
|
|
7
7
|
import { revalidateSession } from "./socketSession.ts";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Context,
|
|
1
|
+
import { Context, type Duration, Effect, Option, type Scope } from "effect";
|
|
2
2
|
import type { Permission } from "@shivaedev/access/permission.ts";
|
|
3
3
|
import type { AuthUnavailable, Forbidden } from "@shivaedev/errors/taxonomy.ts";
|
|
4
|
+
import { socketMonitor } from "#server/adapters/socketMonitor.ts";
|
|
4
5
|
import type { SessionShape } from "./session.ts";
|
|
5
6
|
|
|
6
7
|
export type SessionSnapshot = SessionShape & { readonly user: { readonly permissions?: readonly Permission[] } };
|
|
@@ -32,21 +33,7 @@ export const makeSocketSession = Effect.fnUntraced(function* (interval: Duration
|
|
|
32
33
|
}
|
|
33
34
|
return yield* batch;
|
|
34
35
|
}),
|
|
35
|
-
monitor:
|
|
36
|
-
Effect.gen(function* () {
|
|
37
|
-
const context = yield* Effect.context<R>();
|
|
38
|
-
const ended = yield* Deferred.make<never, E>();
|
|
39
|
-
const run = check.pipe(
|
|
40
|
-
Effect.provideContext(context),
|
|
41
|
-
Effect.catchCause((cause) => Deferred.failCause(ended, cause)),
|
|
42
|
-
Effect.asVoid,
|
|
43
|
-
);
|
|
44
|
-
yield* Effect.acquireRelease(
|
|
45
|
-
Effect.sync(() => checks.add(run)),
|
|
46
|
-
() => Effect.sync(() => checks.delete(run)),
|
|
47
|
-
);
|
|
48
|
-
return yield* Deferred.await(ended);
|
|
49
|
-
}),
|
|
36
|
+
monitor: socketMonitor(checks),
|
|
50
37
|
});
|
|
51
38
|
});
|
|
52
39
|
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|