@shivaedev/identity 0.33.0 → 0.34.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/README.md +62 -11
- package/dist/AccountPreferences.d.ts +40 -4
- package/dist/AccountPreferences.d.ts.map +1 -1
- package/dist/AccountPreferences.js +0 -1
- package/dist/AccountPreferences.js.map +1 -1
- package/dist/DelegationRuleMissing.d.ts +9 -0
- package/dist/DelegationRuleMissing.d.ts.map +1 -0
- package/dist/DelegationRuleMissing.js +7 -0
- package/dist/DelegationRuleMissing.js.map +1 -0
- package/dist/Sessions.d.ts +13 -3
- package/dist/Sessions.d.ts.map +1 -1
- package/dist/Sessions.js +0 -2
- package/dist/Sessions.js.map +1 -1
- package/dist/server/SubjectRecheck.d.ts +3 -0
- package/dist/server/SubjectRecheck.d.ts.map +1 -0
- package/dist/server/SubjectRecheck.js +5 -0
- package/dist/server/SubjectRecheck.js.map +1 -0
- package/dist/server/account-preferences/Rows.d.ts +1 -1
- package/dist/server/account-preferences/store.d.ts +1 -1
- package/dist/server/account-preferences/store.d.ts.map +1 -1
- package/dist/server/better-auth/adapters/defineSeed.d.ts +1 -1
- package/dist/server/better-auth/adapters/defineSeed.d.ts.map +1 -1
- 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/localOwner.d.ts +1 -1
- package/dist/server/localOwner.d.ts.map +1 -1
- package/dist/server/machineTokens.d.ts +1 -1
- package/dist/server/machineTokens.d.ts.map +1 -1
- package/dist/server/resolveChanges.d.ts.map +1 -1
- package/dist/server/resolveChanges.js +4 -1
- package/dist/server/resolveChanges.js.map +1 -1
- package/dist/server/subjectResolverLayer.d.ts.map +1 -1
- package/dist/server/subjectResolverLayer.js +26 -9
- package/dist/server/subjectResolverLayer.js.map +1 -1
- package/dist/subject.d.ts +20 -0
- package/dist/subject.d.ts.map +1 -1
- package/dist/subject.js +17 -1
- package/dist/subject.js.map +1 -1
- package/package.json +23 -23
- package/src/AccountPreferences.ts +0 -1
- package/src/DelegationRuleMissing.ts +7 -0
- package/src/Sessions.ts +0 -2
- package/src/server/SubjectRecheck.ts +5 -0
- package/src/server/resolveChanges.ts +4 -1
- package/src/server/subjectResolverLayer.ts +53 -10
- package/src/subject.ts +36 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.34.1 - 2026-11-20
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Update `@shivaedev/access` from 0.6.5 to 0.6.6.
|
|
8
|
+
- Update `@shivaedev/contract` from 0.49.0 to 0.50.0.
|
|
9
|
+
- Update `@shivaedev/errors` from 0.13.1 to 0.14.0.
|
|
10
|
+
- Update `@shivaedev/rate-limit` from 0.6.14 to 0.6.15.
|
|
11
|
+
- Update `@shivaedev/sql` from 0.51.0 to 0.52.0.
|
|
12
|
+
|
|
13
|
+
## 0.34.0 - 2026-11-20
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
|
|
17
|
+
- `delegatedSubject({ service, refusal, deny })` from `@shivaedev/identity/subject.ts` declares a delegation once, and a module names it as its `subject`. On each call whose subject is not the actor, the guard asks the application's rule, the service with that id in the host's `services`, `allows({ subject, module, operation, kind })` with `CurrentViewer` set to the actor, where `kind` is `read` for queries and streams and `write` for commands; `false` fails the call with the declared refusal before the handler runs. Streams ask again at every recheck, and a delegated live query's changes stream also asks before each update it sends. A host that serves such a module without the service is rejected by the compiler and fails to start with `DelegationRuleMissing`, naming the service.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Require Effect 4.1.4 and its matching platform packages.
|
|
22
|
+
|
|
23
|
+
### Breaking
|
|
24
|
+
|
|
25
|
+
- `SubjectResolver` has a third operation, `delegated(rule, deny)`. A host that provides its own `SubjectResolver` instead of `subjectResolverLayer()` adds it, or switches to `subjectResolverLayer()`.
|
|
26
|
+
|
|
3
27
|
## 0.33.0 - 2026-11-19
|
|
4
28
|
|
|
5
29
|
### Added
|
package/README.md
CHANGED
|
@@ -32,6 +32,7 @@ The browser imports `Account` as it is; the server supplies the session middlewa
|
|
|
32
32
|
Application-host query subscriptions return their first authorized value on the stream after registering read keys. Raw consumers handle `Result` alongside later hints and typed denials. Session revocation continues to end established subscriptions through the same session checks.
|
|
33
33
|
|
|
34
34
|
There are three parts to an authenticated RPC boundary:
|
|
35
|
+
|
|
35
36
|
1. **The shared contract** names the middleware tags (`Authenticated`, `MaybeAuthenticated`, `AuthenticatedUser`, permission middleware) and the request-local services they provide. These modules are browser-safe, because the client imports the contract.
|
|
36
37
|
2. **The server composition** implements the tags with Layers from `server/`. A session provider resolves a session; an Origin policy decides whether its request may reach that provider; request tracing supplies a request id and diagnostic context.
|
|
37
38
|
3. **The feature handler** reads `Identity`, `OptionalIdentity`, `SessionUser` or `RequestId` and runs application code. Authentication supplies a user id. Authorization still decides whether that user may perform this operation.
|
|
@@ -43,16 +44,20 @@ An **Origin policy** is a function of the transport request's origin, headers an
|
|
|
43
44
|
A **subject** is the account whose data this request acts on. The actor remains the session user. `Subject` from `@shivaedev/identity/subject.ts` provides `{ id: SubjectId }`, where `SubjectId` is a branded string. `selfSubject` resolves it from the session, ignoring account-selection headers. It also provides `Identity` and `SessionUser`. A `defineService` that needs the caller declares those services in `requires`, yields them in its operations and registers its Layer in the host's `requestServices` slot. The host builds it after session middleware, once per RPC call. Its callers yield the service and call its methods without providing dependencies or passing the acting user's id. Global services yield global dependencies; caller-dependent services belong in the request slot.
|
|
44
45
|
|
|
45
46
|
```ts
|
|
46
|
-
import {
|
|
47
|
-
import {
|
|
47
|
+
import { Schema } from "effect";
|
|
48
|
+
import { defineModule } from "@shivaedev/contract/defineModule.ts";
|
|
48
49
|
import { command } from "@shivaedev/contract/operation.ts";
|
|
49
50
|
import { selfSubject, Subject } from "@shivaedev/identity/subject.ts";
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
import { accountWire } from "#generated/modules/account/Account.ts";
|
|
52
|
+
|
|
53
|
+
const Save = command("save", {
|
|
54
|
+
payload: { title: Schema.String },
|
|
55
|
+
*run({ title }) {
|
|
56
|
+
const { id } = yield* Subject;
|
|
57
|
+
return `${id}: ${title}`;
|
|
58
|
+
},
|
|
55
59
|
});
|
|
60
|
+
export const Account = defineModule({ name: "account", operations: [Save], subject: selfSubject, wire: accountWire });
|
|
56
61
|
```
|
|
57
62
|
|
|
58
63
|
For delegation, use `accountSubject` with an application permission and a typed refusal:
|
|
@@ -73,6 +78,51 @@ const delegated = accountSubject({
|
|
|
73
78
|
|
|
74
79
|
Pass `subject: delegated` to the contract. A delegated call selects the account with the `x-platform-subject` header of its own RPC message, which a bound client sets from the `subject` option (see [contract's declared subjects](https://github.com/ShivaeDev/platform/tree/main/packages/contract#whose-account-a-request-acts-on)); without one, the guard falls back to that header on the transport, such as a Node client's WebSocket upgrade, and omitting both selects the session account. The subject is the only header the guard takes from the message: the session, Origin, cookies and authorization still come from the transport, so a message cannot forge them. Because each call carries its own subject, one socket, including a browser's or Capacitor app's first-frame bearer socket, serves the actor's own data and any number of subjects at once. Acting on another account requires the named permission's `any` grant. An `own` grant does not authorize another account. A refusal reaches the native client as the declared error instance before the handler runs. Every stream, including a live query's changes stream, rechecks at the session's `streamRevalidationInterval` (30 seconds by default) with its own subject: the recheck looks the session up again, shared by every stream on the same socket, and repeats the permission check for that stream's subject, so a stream whose grant was withdrawn ends with the declared refusal. Reruns after a change keep the stream's subject. `Identity` and `SessionUser` still describe the actor when `Subject` describes another account. The session provider must supply the `SessionUserSchema` profile fields, as for `AuthenticatedUser`.
|
|
75
80
|
|
|
81
|
+
#### Module delegation
|
|
82
|
+
|
|
83
|
+
When an application decides who may act for whom, such as "a coach may read an assigned client's data in these modules but change none of it", declare the delegation once with `delegatedSubject` and name it as the `subject` of each module it covers. The declaration is browser-safe; it names the service that answers for it and the typed refusal a client receives:
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { Schema } from "effect";
|
|
87
|
+
import { delegatedSubject } from "@shivaedev/identity/subject.ts";
|
|
88
|
+
|
|
89
|
+
export class NotYourClient extends Schema.TaggedError<NotYourClient>()("NotYourClient", { client: Schema.String }) {}
|
|
90
|
+
export const actsAsCoach = delegatedSubject({
|
|
91
|
+
service: "app/CoachDelegation",
|
|
92
|
+
refusal: NotYourClient,
|
|
93
|
+
deny: (client) => new NotYourClient({ client }),
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
export const Training = defineModule({ name: "training", operations: [Plan, SavePlan], subject: actsAsCoach, wire: trainingWire });
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
On the server the application answers one question with a service whose id is the declaration's `service`. Its `allows` operation receives a `DelegationRequest`, `{ subject, module, operation, kind }`, and returns whether the actor may make that call; it may fail with an identity failure, such as `AuthUnavailable`, or the declared refusal. It reads the actor from `CurrentViewer` in `@shivaedev/contract/readPolicy.ts`, which the guard sets to the actor for each question; `CurrentViewer` is a reference, so the service lists only its own dependencies in `requires` and is registered once in the host's `services`:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { Effect, Option } from "effect";
|
|
103
|
+
import { SqlClient } from "effect/sql";
|
|
104
|
+
import { CurrentViewer } from "@shivaedev/contract/readPolicy.ts";
|
|
105
|
+
import type { DelegationRequest } from "@shivaedev/identity/subject.ts";
|
|
106
|
+
|
|
107
|
+
export const allows = Effect.fn("CoachDelegation.allows")(function* ({ kind, subject }: DelegationRequest) {
|
|
108
|
+
const coach = yield* CurrentViewer;
|
|
109
|
+
if (Option.isNone(coach) || kind === "write") {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
const sql = yield* SqlClient.SqlClient;
|
|
113
|
+
const assigned = yield* sql`select 1 from coach_assignments where coach = ${coach.value.id} and client = ${subject}`.pipe(Effect.orDie);
|
|
114
|
+
return assigned.length > 0;
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The service module is an ordinary `defineService({ id: "app/CoachDelegation", requires: [SqlClient.SqlClient], initialize: Effect.void, methods: () => ({ allows }) })`. The declaration's service is a requirement of the host, so the compiler rejects a host that serves a module naming `actsAsCoach` without that service's Layer; a host built anyway fails to start with `DelegationRuleMissing`, whose message names the service id to add to the host's services.
|
|
119
|
+
|
|
120
|
+
The guard never asks when the subject is the actor: the actor's own data on the same socket always works. Otherwise it derives `kind` from the RPC at run time: a query, a live query's changes stream and any other stream are `read`, a command is `write`, and an RPC no contract marked counts as `write`. `module` and `operation` name the call. When `allows` returns `false`, the call fails with the declared refusal before the handler runs. A check that only one operation needs stays in that operation's handler and applies on top of the module's rule.
|
|
121
|
+
|
|
122
|
+
Reads need no extra read policy: a query's read policy still sees the actor as `CurrentViewer`, so the default `signedIn` policy serves an approved subject, and the handler reads the client's data through `Subject`. A query whose policy compares the payload or viewer with an owner refuses a delegated actor as it did before.
|
|
123
|
+
|
|
124
|
+
Each stream asks the rule again at every recheck, with its own subject. A delegated live query's changes stream also asks before each update it sends with data, so once the rule says `false` the stream ends with the declared refusal instead of delivering the next change. Between the revocation and the next change or recheck, the stream delivers nothing new and its client keeps showing the last result it had; a change whose rerun had already passed the question when the revocation committed can still arrive. An application stream other than a live query's changes stream is asked only at the recheck, every `streamRevalidationInterval` (30 seconds by default), and keeps sending until then.
|
|
125
|
+
|
|
76
126
|
`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.
|
|
77
127
|
|
|
78
128
|
### Account preferences and logical days
|
|
@@ -91,7 +141,6 @@ import type { AppModule } from "@shivaedev/server/AppModule.ts";
|
|
|
91
141
|
export const preferencesModule = {
|
|
92
142
|
migrations: { loader: Migrator.fromRecord({ "0005_account_preferences": accountPreferencesMigration }) },
|
|
93
143
|
module: AccountPreferences,
|
|
94
|
-
name: "accountPreferences",
|
|
95
144
|
services: accountPreferencesStore,
|
|
96
145
|
} satisfies AppModule;
|
|
97
146
|
```
|
|
@@ -674,7 +723,7 @@ type SignInFailure = Effect.Error<ReturnType<typeof signIn>>;
|
|
|
674
723
|
type Messages = Record<SignInFailure["code"], string>;
|
|
675
724
|
```
|
|
676
725
|
|
|
677
|
-
The failure's `_tag` remains `AuthFailure`; its `code` union includes the declared application codes, so `Messages` requires text for each one as well as the standard codes. Database-hook and email-delivery Effects return their application code and message through `BetterAuthHookError`. The mounted HTTP route preserves these refusals even when Better Auth catches an email-delivery error internally. Undeclared codes remain `UNKNOWN`. `AuthFailure.withCodes(ApplicationCode.literals)` supplies the corresponding native error schema when the application needs to decode a failure.
|
|
726
|
+
The failure's `_tag` remains `AuthFailure`; its `code` union includes the declared application codes, so `Messages` requires text for each one as well as the standard codes. Database-hook and email-delivery Effects return their application code and message through `BetterAuthHookError`. The mounted HTTP route preserves these refusals even when Better Auth catches an email-delivery error internally. On email sign-up, Better Auth sends the account confirmation after it saves the new user and session, so a refused confirmation answers with the refusal while both rows stay stored. Undeclared codes remain `UNKNOWN`. `AuthFailure.withCodes(ApplicationCode.literals)` supplies the corresponding native error schema when the application needs to decode a failure.
|
|
678
727
|
|
|
679
728
|
`authQuery` returns an input-to-Effect function that preserves returned provider errors and maps rejected Promises to `AuthUnavailable` from `@shivaedev/errors/taxonomy.ts`. Both call adapters pass Effect's abort signal to the supplied client function.
|
|
680
729
|
|
|
@@ -757,6 +806,7 @@ The starter ships checked-in SQL for its auth migrations and checks all numbered
|
|
|
757
806
|
### Adopting stored roles with existing users
|
|
758
807
|
|
|
759
808
|
Identity declares `user.additionalFields.role` when the mount has `roles` and `defaultRole`. Choose a default from your application's role set, such as `member`. It is a required string and cannot be supplied by sign-up input. No `additionalFields` entry or Better Auth `admin()` plugin is needed.
|
|
809
|
+
|
|
760
810
|
1. Generate a new numbered application migration with `generateBetterAuthMigration(authOptions, { defaultRole: "member" })`, following the frozen workflow above. Run it before deploying the mount with roles. PostgreSQL fills existing users when the column is added; identity also fills null roles when adopting a nullable role column. Both fresh and upgraded schemas finish with a `text NOT NULL DEFAULT 'member'` column. The migration keeps existing non-null roles.
|
|
761
811
|
2. Mount with `betterAuthMount(authOptions, { defaultRole: "member", roles: Access })`, using the same default as the migration. New users get that role. Remove any app-owned role field configuration and the admin plugin if you used it only for roles.
|
|
762
812
|
3. In a trusted server-side bootstrap process, call `assignRole(Access, existingUserId, "admin")` to make the first administrator. Provide the application's SQL Layer, as for other role changes. Alternatively, configure `accountRoleSeed` on the mount for named provider accounts. `Access` must declare `admin` with the permissions that administrator needs, including `AssignRoles` to manage other users. Do not expose the bootstrap process as an unauthenticated endpoint.
|
|
@@ -807,7 +857,7 @@ An operation on one record reads that record's owner and uses the application's
|
|
|
807
857
|
|
|
808
858
|
### Session-scoped contract keys
|
|
809
859
|
|
|
810
|
-
For self-only features,
|
|
860
|
+
For self-only features, define the module with `keyScope: "session"` and `subject: selfSubject`, as in `defineModule({ keyScope: "session", name: "preferences", operations, subject: selfSubject, wire })`. The client registry owns cache isolation. Server subscriptions use the same plain record, list and bucket keys as repository writes. Handlers read their owner from `Subject`, and queries need no additional session keys. Matching keys trigger each subscriber's read policy before it can receive a hint or result; shared dependencies can cause authorized rechecks across accounts.
|
|
811
861
|
|
|
812
862
|
The host's generated `$changes` handler accepts `{ queries: [{ query: "get", payload: { id: "theme" } }] }` and resolves the declared query dependencies during that subscription invocation. It accepts no physical subscription keys or caller-selected scope.
|
|
813
863
|
|
|
@@ -815,7 +865,7 @@ The host's generated `$changes` handler accepts `{ queries: [{ query: "get", pay
|
|
|
815
865
|
|
|
816
866
|
Declared-key publication retries twice, after 50 ms and 100 ms, without rerunning the handler. Exhausted retries preserve the committed result. On a database-backed host, they mark local live streams for Resync and attempt a broadcast Resync on the PostgreSQL change channel. If that broadcast also fails, the server logs that other hosts may remain stale. There is no durable replay: a remote host whose listener remains healthy cannot discover a notification that never reached PostgreSQL. A client reconnect reconciles its streams.
|
|
817
867
|
|
|
818
|
-
Hosted applications
|
|
868
|
+
Hosted applications let `appHost` own `$changes`: neither a defined module's handlers nor handlers built with `Api.application.toLayer(...)` serve it. A custom change handler accepts query references and resolves them inside `Stream.unwrap`, after authentication has provided `Identity`:
|
|
819
869
|
|
|
820
870
|
```ts
|
|
821
871
|
import { Effect, Stream } from "effect";
|
|
@@ -1070,6 +1120,7 @@ Import the module that defines the name; there is no package-root entry. Paths b
|
|
|
1070
1120
|
### Install, setup and limits
|
|
1071
1121
|
|
|
1072
1122
|
Install `@shivaedev/identity` with `effect` as its peer. Everything outside `server/better-auth/` works with only `effect` installed, including the Promise-based `betterAuthSessions` adapter. Better Auth mounts and test fixtures need the optional peer `better-auth` and the application’s PostgreSQL `SqlClient`; `sweepExpiredSessions` needs only the application's Effect SQL client. Browser code imports `identity.ts`, `middleware.ts`, `permission.ts` and the client contracts in `generated/`. The package's build writes `src/generated` and `dist/generated` before compiling, so the published archive holds them although the repository does not commit them.
|
|
1123
|
+
|
|
1073
1124
|
- The package needs Node 24 or newer.
|
|
1074
1125
|
- Keep the auth provider's configuration, cookie settings and resource authorization in the application. The session adapter takes a session lookup and an optional provider-account lookup and returns a session result; it does not write provider refresh cookies into RPC responses.
|
|
1075
1126
|
- Without an `HttpServerRequest`, `transportHeaders` falls back to the supplied RPC headers. An application using another transport must decide what headers it can trust.
|
|
@@ -27,7 +27,18 @@ export declare const AccountPreferences: import("@shivaedev/contract/defineModul
|
|
|
27
27
|
readonly InternalServerError: typeof import("@shivaedev/errors/taxonomy.ts").InternalServerError;
|
|
28
28
|
readonly ServiceUnavailable: typeof import("@shivaedev/errors/taxonomy.ts").ServiceUnavailable;
|
|
29
29
|
readonly AuthUnavailable: typeof import("@shivaedev/errors/taxonomy.ts").AuthUnavailable;
|
|
30
|
-
}, import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, "@shivaedev/identity/AccountPreferencesStore" | Subject>>] & readonly import("@shivaedev/contract/defineModule.ts").ModuleOperation[], readonly [import("
|
|
30
|
+
}, import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, "@shivaedev/identity/AccountPreferencesStore" | Subject>>] & readonly import("@shivaedev/contract/defineModule.ts").ModuleOperation[], import("@shivaedev/contract/moduleProof.ts").ModuleRequirements<readonly [import("@shivaedev/contract/servedOperation.ts").ServedQuery<"get", import("effect/Schema").Void, import("effect/Schema").Void, {
|
|
31
|
+
readonly InternalServerError: typeof import("@shivaedev/errors/taxonomy.ts").InternalServerError;
|
|
32
|
+
readonly ServiceUnavailable: typeof import("@shivaedev/errors/taxonomy.ts").ServiceUnavailable;
|
|
33
|
+
}, never, never, import("effect/Effect").Effect<{
|
|
34
|
+
readonly locale: string;
|
|
35
|
+
readonly timezone: string;
|
|
36
|
+
readonly units: "imperial" | "metric";
|
|
37
|
+
}, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, "@shivaedev/identity/AccountPreferencesStore" | Subject>>, import("@shivaedev/contract/servedOperation.ts").ServedCommandOf<"set", {
|
|
38
|
+
readonly locale: import("effect/Schema").NonEmptyString;
|
|
39
|
+
readonly timezone: import("effect/Schema").String;
|
|
40
|
+
readonly units: import("effect/Schema").Literals<readonly ["metric", "imperial"]>;
|
|
41
|
+
}, import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never> | import("effect/Effect").Effect<Readonly<{
|
|
31
42
|
readonly capture: (id: string, values: {
|
|
32
43
|
readonly locale: string;
|
|
33
44
|
readonly timezone: string;
|
|
@@ -43,9 +54,34 @@ export declare const AccountPreferences: import("@shivaedev/contract/defineModul
|
|
|
43
54
|
readonly timezone: string;
|
|
44
55
|
readonly units: "imperial" | "metric";
|
|
45
56
|
}) => import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
|
|
46
|
-
}
|
|
47
|
-
readonly
|
|
48
|
-
}
|
|
57
|
+
}>, never, "@shivaedev/identity/AccountPreferencesStore"> | import("effect/Effect").Effect<{
|
|
58
|
+
readonly id: import("#subject.ts").SubjectId;
|
|
59
|
+
}, never, Subject>, void>, import("@shivaedev/contract/servedOperation.ts").ServedCommandOf<"capture", {
|
|
60
|
+
readonly locale: import("effect/Schema").NonEmptyString;
|
|
61
|
+
readonly timezone: import("effect/Schema").String;
|
|
62
|
+
readonly units: import("effect/Schema").Literals<readonly ["metric", "imperial"]>;
|
|
63
|
+
}, import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never> | import("effect/Effect").Effect<Readonly<{
|
|
64
|
+
readonly capture: (id: string, values: {
|
|
65
|
+
readonly locale: string;
|
|
66
|
+
readonly timezone: string;
|
|
67
|
+
readonly units: "imperial" | "metric";
|
|
68
|
+
}) => import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
|
|
69
|
+
readonly get: (id: string) => import("effect/Effect").Effect<{
|
|
70
|
+
readonly locale: string;
|
|
71
|
+
readonly timezone: string;
|
|
72
|
+
readonly units: "imperial" | "metric";
|
|
73
|
+
}, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
|
|
74
|
+
readonly set: (id: string, values: {
|
|
75
|
+
readonly locale: string;
|
|
76
|
+
readonly timezone: string;
|
|
77
|
+
readonly units: "imperial" | "metric";
|
|
78
|
+
}) => import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
|
|
79
|
+
}>, never, "@shivaedev/identity/AccountPreferencesStore"> | import("effect/Effect").Effect<{
|
|
80
|
+
readonly id: import("#subject.ts").SubjectId;
|
|
81
|
+
}, never, Subject>, void>], never, {
|
|
82
|
+
error: import("effect/Schema").Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
|
|
83
|
+
middleware: import("effect/Effect").Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
84
|
+
}>, never, {
|
|
49
85
|
error: import("effect/Schema").Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
|
|
50
86
|
middleware: import("effect/Effect").Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
51
87
|
}, undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountPreferences.d.ts","sourceRoot":"","sources":["../src/AccountPreferences.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAe,MAAM,aAAa,CAAC;AA4BnD,eAAO,MAAM,kBAAkB
|
|
1
|
+
{"version":3,"file":"AccountPreferences.d.ts","sourceRoot":"","sources":["../src/AccountPreferences.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAe,MAAM,aAAa,CAAC;AA4BnD,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAK7B,CAAC"}
|
|
@@ -30,7 +30,6 @@ const CapturePreferences = command("capture", {
|
|
|
30
30
|
export const AccountPreferences = defineModule({
|
|
31
31
|
name: "identity.accountPreferences",
|
|
32
32
|
operations: [GetPreferences, SetPreferences, CapturePreferences],
|
|
33
|
-
requires: [AccountPreferencesStore],
|
|
34
33
|
subject: selfSubject,
|
|
35
34
|
wire: identityAccountPreferencesWire,
|
|
36
35
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountPreferences.js","sourceRoot":"","sources":["../src/AccountPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAC7F,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,cAAc,GAAG,KAAK,CAAC,KAAK,EAAE;IACnC,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC;IACzC,CAAC,GAAG;QACH,MAAM,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC;QAC9B,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,uBAAuB,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACxD,CAAC;CACD,CAAC,CAAC;AAEH,MAAM,cAAc,GAAG,OAAO,CAAC,KAAK,EAAE;IACrC,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC;IAC/C,OAAO,EAAE,uBAAuB,CAAC,MAAM;IACvC,CAAC,GAAG,CAAC,MAAM;QACV,MAAM,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC;QAC9B,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,uBAAuB,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,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, Schema.TaggedStruct<"DelegationRuleMissing", {
|
|
3
|
+
readonly service: Schema.String;
|
|
4
|
+
}>, import("effect/Cause").YieldableError>;
|
|
5
|
+
export declare class DelegationRuleMissing extends DelegationRuleMissing_base {
|
|
6
|
+
get message(): string;
|
|
7
|
+
}
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=DelegationRuleMissing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DelegationRuleMissing.d.ts","sourceRoot":"","sources":["../src/DelegationRuleMissing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;;;;AAEhC,qBAAa,qBAAsB,SAAQ,0BAAgG;IAC1I,IAAa,OAAO,WAEnB;CACD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
export class DelegationRuleMissing extends Schema.TaggedError()("DelegationRuleMissing", { service: Schema.String }) {
|
|
3
|
+
get message() {
|
|
4
|
+
return `A served module names a delegated subject whose rule is the service "${this.service}", and the host's services do not provide it. Add the Layer of the service defined with id "${this.service}" to the host's services.`;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=DelegationRuleMissing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DelegationRuleMissing.js","sourceRoot":"","sources":["../src/DelegationRuleMissing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,OAAO,qBAAsB,SAAQ,MAAM,CAAC,WAAW,EAAyB,CAAC,uBAAuB,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;IAC1I,IAAa,OAAO;QACnB,OAAO,wEAAwE,IAAI,CAAC,OAAO,+FAA+F,IAAI,CAAC,OAAO,2BAA2B,CAAC;IACnO,CAAC;CACD"}
|
package/dist/Sessions.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { SqlClient } from "effect/sql";
|
|
3
2
|
import { SessionsPermission } from "#sessionPermissions.ts";
|
|
4
3
|
export declare const Sessions: import("@shivaedev/contract/defineModule.ts").Module<"identity.sessions", readonly [import("@shivaedev/contract/servedOperation.ts").ServedQuery<"list", Schema.Struct<{
|
|
5
4
|
readonly cursor: Schema.optionalKey<Schema.Struct<{
|
|
@@ -28,7 +27,7 @@ export declare const Sessions: import("@shivaedev/contract/defineModule.ts").Mod
|
|
|
28
27
|
readonly ServiceUnavailable: typeof import("@shivaedev/errors/taxonomy.ts").ServiceUnavailable;
|
|
29
28
|
readonly AuthUnavailable: typeof import("@shivaedev/errors/taxonomy.ts").AuthUnavailable;
|
|
30
29
|
readonly Forbidden: typeof import("@shivaedev/errors/taxonomy.ts").Forbidden;
|
|
31
|
-
}, never, never, import("effect/Effect").Effect<import("#signedInSessions.ts").SessionList, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden, import("./identity.ts").SessionUser | SqlClient.SqlClient>>, import("@shivaedev/contract/servedOperation.ts").ServedCommand<"revoke", Schema.Struct<{
|
|
30
|
+
}, never, never, import("effect/Effect").Effect<import("#signedInSessions.ts").SessionList, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden, import("./identity.ts").SessionUser | import("effect/sql/SqlClient").SqlClient>>, import("@shivaedev/contract/servedOperation.ts").ServedCommand<"revoke", Schema.Struct<{
|
|
32
31
|
id: Schema.String;
|
|
33
32
|
}>, Schema.Void, {
|
|
34
33
|
readonly InternalServerError: typeof import("@shivaedev/errors/taxonomy.ts").InternalServerError;
|
|
@@ -36,5 +35,16 @@ export declare const Sessions: import("@shivaedev/contract/defineModule.ts").Mod
|
|
|
36
35
|
readonly AuthUnavailable: typeof import("@shivaedev/errors/taxonomy.ts").AuthUnavailable;
|
|
37
36
|
readonly Forbidden: typeof import("@shivaedev/errors/taxonomy.ts").Forbidden;
|
|
38
37
|
readonly NotFound: typeof import("@shivaedev/errors/taxonomy.ts").NotFound;
|
|
39
|
-
}, import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden | import("@shivaedev/errors/taxonomy.ts").NotFound, import("./identity.ts").SessionUser | SqlClient.SqlClient>>] & readonly import("@shivaedev/contract/defineModule.ts").ModuleOperation[], readonly [import("
|
|
38
|
+
}, import("effect/Effect").Effect<void, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden | import("@shivaedev/errors/taxonomy.ts").NotFound, import("./identity.ts").SessionUser | import("effect/sql/SqlClient").SqlClient>>] & readonly import("@shivaedev/contract/defineModule.ts").ModuleOperation[], import("@shivaedev/contract/moduleProof.ts").ModuleRequirements<readonly [import("@shivaedev/contract/servedOperation.ts").ServedQuery<"list", Schema.Struct<{
|
|
39
|
+
readonly cursor: Schema.optionalKey<Schema.Struct<{
|
|
40
|
+
readonly id: Schema.String;
|
|
41
|
+
readonly lastActivityAt: Schema.DateTimeUtcFromString;
|
|
42
|
+
}>>;
|
|
43
|
+
readonly limit: Schema.Number;
|
|
44
|
+
}>, Schema.Void, {
|
|
45
|
+
readonly InternalServerError: typeof import("@shivaedev/errors/taxonomy.ts").InternalServerError;
|
|
46
|
+
readonly ServiceUnavailable: typeof import("@shivaedev/errors/taxonomy.ts").ServiceUnavailable;
|
|
47
|
+
}, never, never, import("effect/Effect").Effect<import("#signedInSessions.ts").SessionList, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden, import("./identity.ts").SessionUser | import("effect/sql/SqlClient").SqlClient>>, import("@shivaedev/contract/servedOperation.ts").ServedCommandOf<"revoke", {
|
|
48
|
+
id: Schema.String;
|
|
49
|
+
}, import("effect/Effect").Effect<undefined, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden | import("@shivaedev/errors/taxonomy.ts").NotFound, import("./identity.ts").SessionUser | import("effect/sql/SqlClient").SqlClient>, void>], typeof SessionsPermission, undefined>, typeof SessionsPermission, undefined, undefined>;
|
|
40
50
|
//# 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,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"Sessions.d.ts","sourceRoot":"","sources":["../src/Sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAmB5D,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6XAKnB,CAAC"}
|
package/dist/Sessions.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { SqlClient } from "effect/sql";
|
|
3
2
|
import { defineModule } from "@shivaedev/contract/defineModule.ts";
|
|
4
3
|
import { command, query } from "@shivaedev/contract/operation.ts";
|
|
5
4
|
import { identitySessionsWire } from "#generated/Sessions.ts";
|
|
@@ -24,7 +23,6 @@ export const Sessions = defineModule({
|
|
|
24
23
|
middleware: SessionsPermission,
|
|
25
24
|
name: "identity.sessions",
|
|
26
25
|
operations: [ListSessions, RevokeSession],
|
|
27
|
-
requires: [SqlClient.SqlClient],
|
|
28
26
|
wire: identitySessionsWire,
|
|
29
27
|
});
|
|
30
28
|
//# sourceMappingURL=Sessions.js.map
|
package/dist/Sessions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sessions.js","sourceRoot":"","sources":["../src/Sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Sessions.js","sourceRoot":"","sources":["../src/Sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAErE,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,EAAE;IAClC,OAAO,EAAE,gBAAgB,CAAC,MAAM;IAChC,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;IAC/B,CAAC,GAAG,CAAC,KAAK;QACT,OAAO,KAAK,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;CACD,CAAC,CAAC;AAEH,MAAM,aAAa,GAAG,OAAO,CAAC,QAAQ,EAAE;IACvC,WAAW,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC;IACrC,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE;IAC9B,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE;QACV,KAAK,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;CACD,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,YAAY,CAAC;IACpC,UAAU,EAAE,kBAAkB;IAC9B,IAAI,EAAE,mBAAmB;IACzB,UAAU,EAAE,CAAC,YAAY,EAAE,aAAa,CAAC;IACzC,IAAI,EAAE,oBAAoB;CAC1B,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubjectRecheck.d.ts","sourceRoot":"","sources":["../../src/server/SubjectRecheck.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIzC,eAAO,MAAM,cAAc,sDAAoH,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Context, Effect } from "effect";
|
|
2
|
+
// The subject guard provides it to a delegated call; a live query's changes stream runs it before each update it sends. It never fails:
|
|
3
|
+
// once the rule refuses, it waits for the guard, which ends the call with the declared refusal.
|
|
4
|
+
export const SubjectRecheck = Context.Reference("@shivaedev/identity/SubjectRecheck", { defaultValue: () => Effect.void });
|
|
5
|
+
//# sourceMappingURL=SubjectRecheck.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SubjectRecheck.js","sourceRoot":"","sources":["../../src/server/SubjectRecheck.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEzC,wIAAwI;AACxI,gGAAgG;AAChG,MAAM,CAAC,MAAM,cAAc,GAAG,OAAO,CAAC,SAAS,CAAsB,oCAAoC,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC"}
|
|
@@ -54,7 +54,7 @@ export declare const AccountPreferenceRows: import("effect/Context").Service<"@s
|
|
|
54
54
|
readonly update: import("@shivaedev/sql/repositoryUpdate.ts").Update<typeof StoredPreferences, "id">;
|
|
55
55
|
readonly updateVoid: import("@shivaedev/sql/repositoryUpdate.ts").UpdateVoid<typeof StoredPreferences, "id">;
|
|
56
56
|
} & import("@shivaedev/sql/batchWrites.ts").BatchWrites<typeof StoredPreferences> & import("@shivaedev/sql/insertFromSelect.ts").SelectWrites<typeof StoredPreferences> & import("@shivaedev/sql/repositoryQueries.ts").Queries<typeof StoredPreferences> & import("@shivaedev/sql/conflictWrites.ts").ConflictWrites<typeof StoredPreferences, "id", never>> & {
|
|
57
|
-
layer: import("effect/Layer").Layer<"@shivaedev/identity/AccountPreferenceRows", import("@shivaedev/sql/repositoryCollection.ts").
|
|
57
|
+
layer: import("effect/Layer").Layer<"@shivaedev/identity/AccountPreferenceRows", import("@shivaedev/sql/repositoryCollection.ts").RepositoryBuildError, import("effect/sql/SqlClient").SqlClient>;
|
|
58
58
|
};
|
|
59
59
|
export {};
|
|
60
60
|
//# sourceMappingURL=Rows.d.ts.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Layer } from "effect";
|
|
2
|
-
export declare const accountPreferencesStore: Layer.Layer<"@shivaedev/identity/AccountPreferencesStore", import("@shivaedev/sql/repositoryCollection.ts").
|
|
2
|
+
export declare const accountPreferencesStore: Layer.Layer<"@shivaedev/identity/AccountPreferencesStore", import("@shivaedev/sql/repositoryCollection.ts").RepositoryBuildError, import("effect/sql/SqlClient").SqlClient>;
|
|
3
3
|
//# sourceMappingURL=store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/server/account-preferences/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAI/B,eAAO,MAAM,uBAAuB,
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/server/account-preferences/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAI/B,eAAO,MAAM,uBAAuB,6KAAiF,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Config, Effect } from "effect";
|
|
2
2
|
import type { SeedOptions } from "#server/better-auth/adapters/SeedOptions.ts";
|
|
3
|
-
export declare function defineSeed<TRole extends string, E, R>(options: SeedOptions<TRole, E, R>): Effect.Effect<void, E | import("@shivaedev/errors/taxonomy.ts").AuthUnavailable |
|
|
3
|
+
export declare function defineSeed<TRole extends string, E, R>(options: SeedOptions<TRole, E, R>): Effect.Effect<void, E | import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | Config.ConfigError | import("../../../roles.ts").LastRoleAssigner | import("#server/better-auth/adapters/assertSeedDatabase.ts").NonLocalSeedDatabase | import("@shivaedev/errors/taxonomy.ts").NotFound | import("effect/Schema").SchemaError | import("effect/sql/SqlError").SqlError | import("../UndeclaredDefaultRole.ts").UndeclaredDefaultRole | import("@shivaedev/sql/repositoryCollection.ts").RepositoryBuildError, Exclude<Exclude<Exclude<Exclude<Exclude<Exclude<R, import("../../../identity.ts").Identity>, import("../../../identity.ts").SessionUser>, never>, import("../../UserProvisioning.ts").UserProvisioning>, import("@effect/sql-pg/PgClient").PgClient | import("@effect/sql-pg/PgPool").PgPool | import("effect/reactivity/Reactivity").Reactivity | import("effect/sql/SqlClient").SqlClient>, import("effect/Scope").Scope>>;
|
|
4
4
|
//# sourceMappingURL=defineSeed.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defineSeed.d.ts","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/defineSeed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAI/E,wBAAgB,UAAU,CAAC,KAAK,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"defineSeed.d.ts","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/defineSeed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAMxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAI/E,wBAAgB,UAAU,CAAC,KAAK,SAAS,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,i5BAYvF"}
|
|
@@ -314,7 +314,7 @@ declare const mountAuth: <const TOptions extends BetterAuthOptions, E = never, R
|
|
|
314
314
|
readonly roles?: RoleSet;
|
|
315
315
|
readonly provider: import("../../session.ts").SessionProvider<import("../../session.ts").UserSessionShape>;
|
|
316
316
|
};
|
|
317
|
-
}, E | import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("
|
|
317
|
+
}, E | import("@shivaedev/errors/taxonomy.ts").AuthUnavailable | import("effect/Config").ConfigError | UndeclaredDefaultRole | import("@shivaedev/sql/repositoryCollection.ts").RepositoryBuildError, R | import("effect/reactivity/Reactivity").Reactivity | import("effect/sql/SqlClient").SqlClient | Store>;
|
|
318
318
|
type Mounted<TOptions extends BetterAuthOptions, E, R> = ReturnType<typeof mountAuth<TOptions, E, R>>;
|
|
319
319
|
export declare function betterAuthMount<const TOptions extends BetterAuthOptions, E = never, R = never>(options: TOptions, mount?: BetterAuthMountOptions<E, R> & {
|
|
320
320
|
readonly emails?: undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/mount.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,EAAE,MAAM,QAAQ,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,g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,KAAK,EAAE,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,GACjC,OAAO,CAAC,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC"}
|
|
@@ -61,5 +61,5 @@ export declare const localOwner: (options: {
|
|
|
61
61
|
readonly streamRevalidationInterval?: Duration.Input | undefined;
|
|
62
62
|
};
|
|
63
63
|
token: Redacted.Redacted<string>;
|
|
64
|
-
}, import("
|
|
64
|
+
}, import("effect/Schema").SchemaError | import("@shivaedev/sql/repositoryCollection.ts").RepositoryBuildError, import("effect/crypto/Digest").Digest | SecureRandom.SecureRandom | import("effect/sql/SqlClient").SqlClient>;
|
|
65
65
|
//# sourceMappingURL=localOwner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localOwner.d.ts","sourceRoot":"","sources":["../../src/server/localOwner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKrD,eAAO,MAAM,UAAU;oBACN,IAAI,CAAC,gBAAgB,EAAE,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE;oBAC3E,OAAO;0CACe,QAAQ,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"localOwner.d.ts","sourceRoot":"","sources":["../../src/server/localOwner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKrD,eAAO,MAAM,UAAU;oBACN,IAAI,CAAC,gBAAgB,EAAE,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE;oBAC3E,OAAO;0CACe,QAAQ,CAAC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6NAsBnD,CAAC"}
|
|
@@ -49,5 +49,5 @@ export declare const machineTokens: (options: {
|
|
|
49
49
|
};
|
|
50
50
|
}>, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
|
|
51
51
|
revoke: (id: string) => Effect.Effect<void, Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
52
|
-
}, import("@shivaedev/sql/repositoryCollection.ts").
|
|
52
|
+
}, import("@shivaedev/sql/repositoryCollection.ts").RepositoryBuildError, Digest.Digest | SecureRandom.SecureRandom | import("effect/sql/SqlClient").SqlClient>;
|
|
53
53
|
//# sourceMappingURL=machineTokens.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"machineTokens.d.ts","sourceRoot":"","sources":["../../src/server/machineTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAUrD,eAAO,MAAM,aAAa;oBACT,IAAI,CAAC,gBAAgB,EAAE,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC;oBAC/C,OAAO;;;uBAaqD,MAAM;wBAAkB,MAAM;;cAA9B,MAAM;eAAkB,MAAM;;;;;;YAmB5F,EAAE;YAAmB,IAAI;YAAqB,KAAK
|
|
1
|
+
{"version":3,"file":"machineTokens.d.ts","sourceRoot":"","sources":["../../src/server/machineTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAGrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,8BAA8B,CAAC;AAE5D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAUrD,eAAO,MAAM,aAAa;oBACT,IAAI,CAAC,gBAAgB,EAAE,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC;oBAC/C,OAAO;;;uBAaqD,MAAM;wBAAkB,MAAM;;cAA9B,MAAM;eAAkB,MAAM;;;;;;YAmB5F,EAAE;YAAmB,IAAI;YAAqB,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+JAMhE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveChanges.d.ts","sourceRoot":"","sources":["../../src/server/resolveChanges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,KAAK,iBAAiB,EAAqB,MAAM,0CAA0C,CAAC;AACrG,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAClG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"resolveChanges.d.ts","sourceRoot":"","sources":["../../src/server/resolveChanges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AACxC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,KAAK,iBAAiB,EAAqB,MAAM,0CAA0C,CAAC;AACrG,OAAO,EAAiB,KAAK,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACvF,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAClG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAI5E,wBAAgB,cAAc,CAAC,IAAI,SAAS,GAAG,CAAC,GAAG,EAClD,GAAG,EAAE,IAAI,EACT,UAAU,EAAE,SAAS,cAAc,EAAE,GACnC,MAAM,CAAC,MAAM,CACf,iBAAiB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,EAClF,cAAc,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,iBAAiB,GAAG,eAAe,EACnE,cAAc,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAChC,CAAC"}
|
|
@@ -2,12 +2,15 @@ import { Effect, Option } from "effect";
|
|
|
2
2
|
import { querySubscription } from "@shivaedev/contract/querySubscription.ts";
|
|
3
3
|
import { CurrentViewer } from "@shivaedev/contract/readPolicy.ts";
|
|
4
4
|
import { Identity } from "#identity.ts";
|
|
5
|
+
import { SubjectRecheck } from "#server/SubjectRecheck.ts";
|
|
5
6
|
export function resolveChanges(rpc, references) {
|
|
6
7
|
return Effect.fnUntraced(function* () {
|
|
7
8
|
const identity = yield* Effect.serviceOption(Identity);
|
|
8
9
|
const current = yield* CurrentViewer;
|
|
9
10
|
const viewer = Option.orElse(identity, () => current);
|
|
10
|
-
|
|
11
|
+
const recheck = yield* SubjectRecheck;
|
|
12
|
+
const subscription = yield* querySubscription(rpc, references, viewer);
|
|
13
|
+
return { ...subscription, authorized: Effect.andThen(recheck, subscription.authorized) };
|
|
11
14
|
})();
|
|
12
15
|
}
|
|
13
16
|
//# sourceMappingURL=resolveChanges.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveChanges.js","sourceRoot":"","sources":["../../src/server/resolveChanges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,EAA0B,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AACrG,OAAO,EAAE,aAAa,EAAuB,MAAM,mCAAmC,CAAC;AAGvF,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"resolveChanges.js","sourceRoot":"","sources":["../../src/server/resolveChanges.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExC,OAAO,EAA0B,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AACrG,OAAO,EAAE,aAAa,EAAuB,MAAM,mCAAmC,CAAC;AAGvF,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAU3D,MAAM,UAAU,cAAc,CAAC,GAAY,EAAE,UAAqC;IACjF,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC;QACjC,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACvD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,aAAa,CAAC;QACrC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC;QACtD,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,cAAc,CAAC;QACtC,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,iBAAiB,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;QACvE,OAAO,EAAE,GAAG,YAAY,EAAE,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;IAC1F,CAAC,CAAC,EAAE,CAAC;AACN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subjectResolverLayer.d.ts","sourceRoot":"","sources":["../../src/server/subjectResolverLayer.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"subjectResolverLayer.d.ts","sourceRoot":"","sources":["../../src/server/subjectResolverLayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,KAAK,EAAkB,MAAM,QAAQ,CAAC;AAiB1E,OAAO,EAA2F,eAAe,EAAE,MAAM,aAAa,CAAC;AA2EvI,wBAAgB,oBAAoB,+CAkBnC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Effect, Layer, Option, Schema } from "effect";
|
|
1
|
+
import { Context, Deferred, Effect, Layer, Option, Schema } from "effect";
|
|
2
|
+
import { DefinedModule } from "@shivaedev/contract/defineModule.ts";
|
|
3
|
+
import { operationKind } from "@shivaedev/contract/operationKind.ts";
|
|
2
4
|
import { CurrentViewer } from "@shivaedev/contract/readPolicy.ts";
|
|
3
5
|
import { subjectHeader } from "@shivaedev/contract/subjectHeader.ts";
|
|
4
6
|
import { Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
@@ -7,14 +9,27 @@ import { hasPermission } from "#permission.ts";
|
|
|
7
9
|
import { recheckSession } from "#server/recheckSession.ts";
|
|
8
10
|
import { revalidateStream } from "#server/revalidateStream.ts";
|
|
9
11
|
import { SessionPolicy } from "#server/SessionPolicy.ts";
|
|
12
|
+
import { SubjectRecheck } from "#server/SubjectRecheck.ts";
|
|
10
13
|
import { resolveSession } from "#server/session.ts";
|
|
11
14
|
import { transportHeaders } from "#server/transportHeaders.ts";
|
|
12
15
|
import { Subject, SubjectId, SubjectResolver } from "#subject.ts";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
function delegationRequest(rpc, subject) {
|
|
17
|
+
const module = Option.getOrElse(Context.getOption(rpc.annotations, DefinedModule), () => rpc._tag.slice(0, rpc._tag.lastIndexOf(".")));
|
|
18
|
+
return { kind: operationKind(rpc), module, operation: rpc._tag.slice(module.length + 1), subject: SubjectId(subject) };
|
|
19
|
+
}
|
|
20
|
+
// The one place that decides whether an actor may act for a subject; the guard asks it before the handler runs, at every stream
|
|
21
|
+
// recheck and, for a delegated subject, before each update a live query's changes stream sends.
|
|
22
|
+
function authorize(policy, actor, subject, rpc) {
|
|
23
|
+
if (policy.kind === "self" || subject === actor.id) {
|
|
24
|
+
return Effect.void;
|
|
25
|
+
}
|
|
26
|
+
if (policy.kind === "account") {
|
|
27
|
+
return hasPermission(actor, { ...policy.permission, strength: "any" }) ? Effect.void : Effect.fail(policy.deny(subject));
|
|
28
|
+
}
|
|
29
|
+
return policy.rule.allows(delegationRequest(rpc, subject)).pipe(Effect.provideService(CurrentViewer, Option.some({ id: actor.id })), Effect.flatMap((allowed) => (allowed ? Effect.void : Effect.fail(policy.deny(subject)))));
|
|
30
|
+
}
|
|
31
|
+
function recheckEachUpdate(check) {
|
|
32
|
+
return (effect) => Effect.flatMap(Deferred.make(), (refused) => Effect.raceFirst(Effect.provideService(effect, SubjectRecheck, Effect.catch(check, (error) => Effect.andThen(Deferred.fail(refused, error), Effect.never))), Deferred.await(refused)));
|
|
18
33
|
}
|
|
19
34
|
function guard(policy) {
|
|
20
35
|
return (effect, { headers, rpc }) => Effect.gen(function* () {
|
|
@@ -28,9 +43,10 @@ function guard(policy) {
|
|
|
28
43
|
// authorization below decides whether that is allowed, while the session, origin and cookies stay bound to the transport.
|
|
29
44
|
const wanted = subjectHeader(headers) ?? subjectHeader(yield* transportHeaders(headers));
|
|
30
45
|
const id = policy.kind === "self" ? user.id : (wanted ?? user.id);
|
|
31
|
-
yield* authorize(policy, user, id);
|
|
32
|
-
const lookup = recheckSession(headers, rpc._tag).pipe(Effect.tap((next) => (Option.isSome(next) ? authorize(policy, next.value.user, id) : Effect.void)));
|
|
33
|
-
|
|
46
|
+
yield* authorize(policy, user, id, rpc);
|
|
47
|
+
const lookup = recheckSession(headers, rpc._tag).pipe(Effect.tap((next) => (Option.isSome(next) ? authorize(policy, next.value.user, id, rpc) : Effect.void)));
|
|
48
|
+
const delegated = policy.kind === "delegated" && id !== user.id;
|
|
49
|
+
return yield* effect.pipe(delegated ? recheckEachUpdate(authorize(policy, user, id, rpc)) : (handled) => handled, revalidateStream(rpc, user.id, lookup), Effect.provideService(Subject, { id: SubjectId(id) }), Effect.provideService(Identity, { id: user.id }), Effect.provideService(SessionUser, Schema.decodeUnknownSync(SessionUserSchema)(user)), Effect.provideService(CurrentViewer, Option.some({ id: user.id })));
|
|
34
50
|
});
|
|
35
51
|
}
|
|
36
52
|
export function subjectResolverLayer() {
|
|
@@ -43,6 +59,7 @@ export function subjectResolverLayer() {
|
|
|
43
59
|
}
|
|
44
60
|
return {
|
|
45
61
|
account: (permission, deny) => resolved({ deny, kind: "account", permission }),
|
|
62
|
+
delegated: (rule, deny) => resolved({ deny, kind: "delegated", rule }),
|
|
46
63
|
self: resolved({ kind: "self" }),
|
|
47
64
|
};
|
|
48
65
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subjectResolverLayer.js","sourceRoot":"","sources":["../../src/server/subjectResolverLayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"subjectResolverLayer.js","sourceRoot":"","sources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AC,CAClE,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,oBAAoB;IACnC,OAAO,KAAK,CAAC,MAAM,CAClB,eAAe,EACf,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE;QAC5D,SAAS,QAAQ,CAAI,MAAiB;YACrC,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;YACjC,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAC1B,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC;gBACtB,CAAC,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,aAAa,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACxF,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,EAAE,OAAO,EAAE,yBAAyB,EAAE,CAAC,CAAC,CAAC;QAC3E,CAAC;QACD,OAAO;YACN,OAAO,EAAE,CAAI,UAAsB,EAAE,IAAuB,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;YAChH,SAAS,EAAE,CAAI,IAAuB,EAAE,IAAuB,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;YAC/G,IAAI,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;SAChC,CAAC;IACH,CAAC,CAAC,CACF,CAAC;AACH,CAAC"}
|
package/dist/subject.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Brand, Context, Effect, Schema } from "effect";
|
|
|
2
2
|
import type { RpcMiddleware } from "effect/rpc";
|
|
3
3
|
import type { Permission } from "@shivaedev/access/permission.ts";
|
|
4
4
|
import type { TaggedRejection } from "@shivaedev/contract/rejection.ts";
|
|
5
|
+
import { DelegationRuleMissing } from "#DelegationRuleMissing.ts";
|
|
5
6
|
import type { Identity, SessionUser } from "#identity.ts";
|
|
6
7
|
import { IdentityFailures } from "#middleware.ts";
|
|
7
8
|
export type SubjectId = string & Brand.Brand<"@shivaedev/identity/SubjectId">;
|
|
@@ -12,9 +13,19 @@ declare const Subject_base: Context.ServiceClass<Subject, "@shivaedev/identity/S
|
|
|
12
13
|
export declare class Subject extends Subject_base {
|
|
13
14
|
}
|
|
14
15
|
export type SubjectMiddleware<E = never, R = never> = RpcMiddleware.RpcMiddleware<Subject | Identity | SessionUser, IdentityFailures | E, R>;
|
|
16
|
+
export interface DelegationRequest {
|
|
17
|
+
readonly kind: "read" | "write";
|
|
18
|
+
readonly module: string;
|
|
19
|
+
readonly operation: string;
|
|
20
|
+
readonly subject: SubjectId;
|
|
21
|
+
}
|
|
22
|
+
export interface DelegationRule<E = never> {
|
|
23
|
+
readonly allows: (request: DelegationRequest) => Effect.Effect<boolean, IdentityFailures | E>;
|
|
24
|
+
}
|
|
15
25
|
declare const SubjectResolver_base: Context.ServiceClass<SubjectResolver, "@shivaedev/identity/SubjectResolver", {
|
|
16
26
|
readonly self: SubjectMiddleware;
|
|
17
27
|
readonly account: <E>(permission: Permission, deny: (id: string) => E) => SubjectMiddleware<E>;
|
|
28
|
+
readonly delegated: <E>(rule: DelegationRule<E>, deny: (id: string) => E) => SubjectMiddleware<E>;
|
|
18
29
|
}>;
|
|
19
30
|
export declare class SubjectResolver extends SubjectResolver_base {
|
|
20
31
|
}
|
|
@@ -30,5 +41,14 @@ export declare function accountSubject<TRefusal extends TaggedRejection>(options
|
|
|
30
41
|
error: Schema.Union<readonly [Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, TRefusal]>;
|
|
31
42
|
middleware: Effect.Effect<SubjectMiddleware<NoInfer<TRefusal["Type"]>, never>, never, SubjectResolver>;
|
|
32
43
|
};
|
|
44
|
+
export declare function delegatedSubject<const TService extends string, TRefusal extends TaggedRejection>(options: {
|
|
45
|
+
readonly service: TService;
|
|
46
|
+
readonly refusal: TRefusal;
|
|
47
|
+
readonly deny: (id: string) => NoInfer<TRefusal["Type"]>;
|
|
48
|
+
}): {
|
|
49
|
+
error: Schema.Union<readonly [Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, TRefusal]>;
|
|
50
|
+
middleware: Effect.Effect<SubjectMiddleware<TRefusal["Type"], never>, DelegationRuleMissing, TService | SubjectResolver>;
|
|
51
|
+
service: TService;
|
|
52
|
+
};
|
|
33
53
|
export {};
|
|
34
54
|
//# sourceMappingURL=subject.d.ts.map
|
package/dist/subject.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subject.d.ts","sourceRoot":"","sources":["../src/subject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"subject.d.ts","sourceRoot":"","sources":["../src/subject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EA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E,MAAM,KAAK,CAAC,KAAK,iBAAiB,CAAC,CAAC,CAAC;;AALnG,qBAAa,eAAgB,SAAQ,oBAOK;CAAG;AAE7C,eAAO,MAAM,WAAW;;;CAGM,CAAC;AAE/B,wBAAgB,cAAc,CAAC,QAAQ,SAAS,eAAe,EAAE,OAAO,EAAE;IACzE,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;CACzD;;;EAKA;AAED,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,QAAQ,SAAS,MAAM,EAAE,QAAQ,SAAS,eAAe,EAAE,OAAO,EAAE;IAC1G,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;CACzD;;;;EAcA"}
|
package/dist/subject.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Brand, Context, Effect, Schema } from "effect";
|
|
1
|
+
import { Brand, Context, Effect, Option, Schema } from "effect";
|
|
2
|
+
import { DelegationRuleMissing } from "#DelegationRuleMissing.ts";
|
|
2
3
|
import { IdentityFailures } from "#middleware.ts";
|
|
3
4
|
export const SubjectId = Brand.nominal();
|
|
4
5
|
export class Subject extends Context.Service()("@shivaedev/identity/Subject") {
|
|
@@ -15,4 +16,19 @@ export function accountSubject(options) {
|
|
|
15
16
|
middleware: Effect.map(SubjectResolver, (resolver) => resolver.account(options.permission, options.deny)),
|
|
16
17
|
};
|
|
17
18
|
}
|
|
19
|
+
export function delegatedSubject(options) {
|
|
20
|
+
const rule = Context.Service(options.service);
|
|
21
|
+
// The rule is looked up optionally so a host without it fails to start with a message naming it; the declared requirement
|
|
22
|
+
// still makes the compiler reject that host first.
|
|
23
|
+
const middleware = Effect.gen(function* () {
|
|
24
|
+
const resolver = yield* SubjectResolver;
|
|
25
|
+
const found = yield* Effect.serviceOption(rule);
|
|
26
|
+
if (Option.isNone(found)) {
|
|
27
|
+
return yield* new DelegationRuleMissing({ service: options.service });
|
|
28
|
+
}
|
|
29
|
+
return resolver.delegated(found.value, options.deny);
|
|
30
|
+
});
|
|
31
|
+
const declaration = { error: Schema.Union([IdentityFailures, options.refusal]), middleware };
|
|
32
|
+
return { ...declaration, service: options.service };
|
|
33
|
+
}
|
|
18
34
|
//# sourceMappingURL=subject.js.map
|
package/dist/subject.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subject.js","sourceRoot":"","sources":["../src/subject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"subject.js","sourceRoot":"","sources":["../src/subject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKhE,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAElE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,EAAa,CAAC;AACpD,MAAM,OAAO,OAAQ,SAAQ,OAAO,CAAC,OAAO,EAAuC,CAAC,6BAA6B,CAAC;CAAG;AAiBrH,MAAM,OAAO,eAAgB,SAAQ,OAAO,CAAC,OAAO,EAOjD,CAAC,qCAAqC,CAAC;CAAG;AAE7C,MAAM,CAAC,MAAM,WAAW,GAAG;IAC1B,KAAK,EAAE,gBAAgB;IACvB,UAA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AC1H,OAAO,EAAE,GAAG,WAAW,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC;AACrD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/identity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.1",
|
|
4
4
|
"description": "Request identity, sessions, transport trust and permission enforcement for Effect RPC servers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -46,35 +46,35 @@
|
|
|
46
46
|
"README.md"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@shivaedev/access": "0.6.
|
|
50
|
-
"@shivaedev/changes": "0.14.
|
|
51
|
-
"@shivaedev/contract": "0.
|
|
52
|
-
"@shivaedev/errors": "0.
|
|
53
|
-
"@shivaedev/rate-limit": "0.6.
|
|
54
|
-
"@shivaedev/service": "0.9.
|
|
55
|
-
"@shivaedev/sql": "0.
|
|
49
|
+
"@shivaedev/access": "0.6.6",
|
|
50
|
+
"@shivaedev/changes": "0.14.1",
|
|
51
|
+
"@shivaedev/contract": "0.50.0",
|
|
52
|
+
"@shivaedev/errors": "0.14.0",
|
|
53
|
+
"@shivaedev/rate-limit": "0.6.15",
|
|
54
|
+
"@shivaedev/service": "0.9.2",
|
|
55
|
+
"@shivaedev/sql": "0.52.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@better-auth/oauth-provider": "1.7.
|
|
59
|
-
"@effect/platform-node": "4.1.
|
|
60
|
-
"@effect/sql-pg": "4.1.
|
|
61
|
-
"@shivaedev/admin": "0.
|
|
62
|
-
"@shivaedev/build": "0.
|
|
63
|
-
"@shivaedev/quality": "0.78.
|
|
64
|
-
"@shivaedev/server": "0.
|
|
65
|
-
"@shivaedev/test-kits": "0.13.
|
|
66
|
-
"@shivaedev/test-sql": "0.25.
|
|
67
|
-
"@shivaedev/test-story": "0.
|
|
58
|
+
"@better-auth/oauth-provider": "1.7.22",
|
|
59
|
+
"@effect/platform-node": "4.1.4",
|
|
60
|
+
"@effect/sql-pg": "4.1.4",
|
|
61
|
+
"@shivaedev/admin": "0.27.0",
|
|
62
|
+
"@shivaedev/build": "0.3.1",
|
|
63
|
+
"@shivaedev/quality": "0.78.6",
|
|
64
|
+
"@shivaedev/server": "0.38.0",
|
|
65
|
+
"@shivaedev/test-kits": "0.13.5",
|
|
66
|
+
"@shivaedev/test-sql": "0.25.5",
|
|
67
|
+
"@shivaedev/test-story": "0.49.1",
|
|
68
68
|
"@types/node": "24.19.2",
|
|
69
|
-
"better-auth": "1.7.
|
|
70
|
-
"effect": "4.1.
|
|
69
|
+
"better-auth": "1.7.22",
|
|
70
|
+
"effect": "4.1.4",
|
|
71
71
|
"typescript": "7.0.2",
|
|
72
72
|
"vitest": "5.1.0"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
|
-
"@better-auth/oauth-provider": "1.7.
|
|
76
|
-
"better-auth": "1.7.
|
|
77
|
-
"effect": "4.1.
|
|
75
|
+
"@better-auth/oauth-provider": "1.7.22",
|
|
76
|
+
"better-auth": "1.7.22",
|
|
77
|
+
"effect": "4.1.4"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"@better-auth/oauth-provider": {
|
|
@@ -34,7 +34,6 @@ const CapturePreferences = command("capture", {
|
|
|
34
34
|
export const AccountPreferences = defineModule({
|
|
35
35
|
name: "identity.accountPreferences",
|
|
36
36
|
operations: [GetPreferences, SetPreferences, CapturePreferences],
|
|
37
|
-
requires: [AccountPreferencesStore],
|
|
38
37
|
subject: selfSubject,
|
|
39
38
|
wire: identityAccountPreferencesWire,
|
|
40
39
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
|
|
3
|
+
export class DelegationRuleMissing extends Schema.TaggedError<DelegationRuleMissing>()("DelegationRuleMissing", { service: Schema.String }) {
|
|
4
|
+
override get message() {
|
|
5
|
+
return `A served module names a delegated subject whose rule is the service "${this.service}", and the host's services do not provide it. Add the Layer of the service defined with id "${this.service}" to the host's services.`;
|
|
6
|
+
}
|
|
7
|
+
}
|
package/src/Sessions.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
import { SqlClient } from "effect/sql";
|
|
3
2
|
import { defineModule } from "@shivaedev/contract/defineModule.ts";
|
|
4
3
|
import { command, query } from "@shivaedev/contract/operation.ts";
|
|
5
4
|
import { identitySessionsWire } from "#generated/Sessions.ts";
|
|
@@ -27,6 +26,5 @@ export const Sessions = defineModule({
|
|
|
27
26
|
middleware: SessionsPermission,
|
|
28
27
|
name: "identity.sessions",
|
|
29
28
|
operations: [ListSessions, RevokeSession],
|
|
30
|
-
requires: [SqlClient.SqlClient],
|
|
31
29
|
wire: identitySessionsWire,
|
|
32
30
|
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Context, Effect } from "effect";
|
|
2
|
+
|
|
3
|
+
// The subject guard provides it to a delegated call; a live query's changes stream runs it before each update it sends. It never fails:
|
|
4
|
+
// once the rule refuses, it waits for the guard, which ends the call with the declared refusal.
|
|
5
|
+
export const SubjectRecheck = Context.Reference<Effect.Effect<void>>("@shivaedev/identity/SubjectRecheck", { defaultValue: () => Effect.void });
|
|
@@ -5,6 +5,7 @@ import { CurrentViewer, type PolicyChannels } from "@shivaedev/contract/readPoli
|
|
|
5
5
|
import type { MissingReadPolicy, QueryReadDenied } from "@shivaedev/contract/readPolicyErrors.ts";
|
|
6
6
|
import type { QueryReference } from "@shivaedev/contract/serverMetadata.ts";
|
|
7
7
|
import { Identity } from "#identity.ts";
|
|
8
|
+
import { SubjectRecheck } from "#server/SubjectRecheck.ts";
|
|
8
9
|
|
|
9
10
|
export function resolveChanges<TRpc extends Rpc.Any>(
|
|
10
11
|
rpc: TRpc,
|
|
@@ -19,6 +20,8 @@ export function resolveChanges(rpc: Rpc.Any, references: readonly QueryReference
|
|
|
19
20
|
const identity = yield* Effect.serviceOption(Identity);
|
|
20
21
|
const current = yield* CurrentViewer;
|
|
21
22
|
const viewer = Option.orElse(identity, () => current);
|
|
22
|
-
|
|
23
|
+
const recheck = yield* SubjectRecheck;
|
|
24
|
+
const subscription = yield* querySubscription(rpc, references, viewer);
|
|
25
|
+
return { ...subscription, authorized: Effect.andThen(recheck, subscription.authorized) };
|
|
23
26
|
})();
|
|
24
27
|
}
|
|
@@ -1,24 +1,64 @@
|
|
|
1
|
-
import { Effect, Layer, Option, Schema } from "effect";
|
|
1
|
+
import { Context, Deferred, Effect, Layer, Option, Schema } from "effect";
|
|
2
|
+
import type { Rpc } from "effect/rpc";
|
|
2
3
|
import type { Permission } from "@shivaedev/access/permission.ts";
|
|
4
|
+
import { DefinedModule } from "@shivaedev/contract/defineModule.ts";
|
|
5
|
+
import { operationKind } from "@shivaedev/contract/operationKind.ts";
|
|
3
6
|
import { CurrentViewer } from "@shivaedev/contract/readPolicy.ts";
|
|
4
7
|
import { subjectHeader } from "@shivaedev/contract/subjectHeader.ts";
|
|
5
8
|
import { Unauthorized } from "@shivaedev/errors/taxonomy.ts";
|
|
6
9
|
import { Identity, SessionUser, SessionUserSchema } from "#identity.ts";
|
|
10
|
+
import type { IdentityFailures } from "#middleware.ts";
|
|
7
11
|
import { hasPermission } from "#permission.ts";
|
|
8
12
|
import { recheckSession } from "#server/recheckSession.ts";
|
|
9
13
|
import { revalidateStream } from "#server/revalidateStream.ts";
|
|
10
14
|
import { SessionPolicy } from "#server/SessionPolicy.ts";
|
|
15
|
+
import { SubjectRecheck } from "#server/SubjectRecheck.ts";
|
|
11
16
|
import { resolveSession } from "#server/session.ts";
|
|
12
17
|
import { transportHeaders } from "#server/transportHeaders.ts";
|
|
13
|
-
import { Subject, SubjectId, type SubjectMiddleware, SubjectResolver } from "#subject.ts";
|
|
18
|
+
import { type DelegationRequest, type DelegationRule, Subject, SubjectId, type SubjectMiddleware, SubjectResolver } from "#subject.ts";
|
|
14
19
|
|
|
15
|
-
type Policy<E> =
|
|
20
|
+
type Policy<E> =
|
|
21
|
+
| { readonly kind: "self" }
|
|
22
|
+
| { readonly kind: "account"; readonly permission: Permission; readonly deny: (id: string) => E }
|
|
23
|
+
| { readonly kind: "delegated"; readonly rule: DelegationRule<E>; readonly deny: (id: string) => E };
|
|
16
24
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
function delegationRequest(rpc: Rpc.AnyWithProps, subject: string): DelegationRequest {
|
|
26
|
+
const module = Option.getOrElse(Context.getOption(rpc.annotations, DefinedModule), () => rpc._tag.slice(0, rpc._tag.lastIndexOf(".")));
|
|
27
|
+
return { kind: operationKind(rpc), module, operation: rpc._tag.slice(module.length + 1), subject: SubjectId(subject) };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// The one place that decides whether an actor may act for a subject; the guard asks it before the handler runs, at every stream
|
|
31
|
+
// recheck and, for a delegated subject, before each update a live query's changes stream sends.
|
|
32
|
+
function authorize<E>(
|
|
33
|
+
policy: Policy<E>,
|
|
34
|
+
actor: Parameters<typeof hasPermission>[0],
|
|
35
|
+
subject: string,
|
|
36
|
+
rpc: Rpc.AnyWithProps,
|
|
37
|
+
): Effect.Effect<void, E | IdentityFailures> {
|
|
38
|
+
if (policy.kind === "self" || subject === actor.id) {
|
|
39
|
+
return Effect.void;
|
|
40
|
+
}
|
|
41
|
+
if (policy.kind === "account") {
|
|
42
|
+
return hasPermission(actor, { ...policy.permission, strength: "any" }) ? Effect.void : Effect.fail(policy.deny(subject));
|
|
43
|
+
}
|
|
44
|
+
return policy.rule.allows(delegationRequest(rpc, subject)).pipe(
|
|
45
|
+
Effect.provideService(CurrentViewer, Option.some({ id: actor.id })),
|
|
46
|
+
Effect.flatMap((allowed) => (allowed ? Effect.void : Effect.fail(policy.deny(subject)))),
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function recheckEachUpdate<E>(check: Effect.Effect<void, E>) {
|
|
51
|
+
return <A, TError, R>(effect: Effect.Effect<A, TError, R>) =>
|
|
52
|
+
Effect.flatMap(Deferred.make<never, E>(), (refused) =>
|
|
53
|
+
Effect.raceFirst(
|
|
54
|
+
Effect.provideService(
|
|
55
|
+
effect,
|
|
56
|
+
SubjectRecheck,
|
|
57
|
+
Effect.catch(check, (error) => Effect.andThen(Deferred.fail(refused, error), Effect.never)),
|
|
58
|
+
),
|
|
59
|
+
Deferred.await(refused),
|
|
60
|
+
),
|
|
61
|
+
);
|
|
22
62
|
}
|
|
23
63
|
|
|
24
64
|
function guard<E>(policy: Policy<E>): SubjectMiddleware<E, SessionPolicy> {
|
|
@@ -34,11 +74,13 @@ function guard<E>(policy: Policy<E>): SubjectMiddleware<E, SessionPolicy> {
|
|
|
34
74
|
// authorization below decides whether that is allowed, while the session, origin and cookies stay bound to the transport.
|
|
35
75
|
const wanted = subjectHeader(headers) ?? subjectHeader(yield* transportHeaders(headers));
|
|
36
76
|
const id = policy.kind === "self" ? user.id : (wanted ?? user.id);
|
|
37
|
-
yield* authorize(policy, user, id);
|
|
77
|
+
yield* authorize(policy, user, id, rpc);
|
|
38
78
|
const lookup = recheckSession(headers, rpc._tag).pipe(
|
|
39
|
-
Effect.tap((next) => (Option.isSome(next) ? authorize(policy, next.value.user, id) : Effect.void)),
|
|
79
|
+
Effect.tap((next) => (Option.isSome(next) ? authorize(policy, next.value.user, id, rpc) : Effect.void)),
|
|
40
80
|
);
|
|
81
|
+
const delegated = policy.kind === "delegated" && id !== user.id;
|
|
41
82
|
return yield* effect.pipe(
|
|
83
|
+
delegated ? recheckEachUpdate(authorize(policy, user, id, rpc)) : (handled) => handled,
|
|
42
84
|
revalidateStream(rpc, user.id, lookup),
|
|
43
85
|
Effect.provideService(Subject, { id: SubjectId(id) }),
|
|
44
86
|
Effect.provideService(Identity, { id: user.id }),
|
|
@@ -61,6 +103,7 @@ export function subjectResolverLayer() {
|
|
|
61
103
|
}
|
|
62
104
|
return {
|
|
63
105
|
account: <E>(permission: Permission, deny: (id: string) => E) => resolved({ deny, kind: "account", permission }),
|
|
106
|
+
delegated: <E>(rule: DelegationRule<E>, deny: (id: string) => E) => resolved({ deny, kind: "delegated", rule }),
|
|
64
107
|
self: resolved({ kind: "self" }),
|
|
65
108
|
};
|
|
66
109
|
}),
|
package/src/subject.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Brand, Context, Effect, Schema } from "effect";
|
|
1
|
+
import { Brand, Context, Effect, Option, Schema } from "effect";
|
|
2
2
|
import type { RpcMiddleware } from "effect/rpc";
|
|
3
3
|
import type { Permission } from "@shivaedev/access/permission.ts";
|
|
4
4
|
import type { TaggedRejection } from "@shivaedev/contract/rejection.ts";
|
|
5
5
|
import type { SubjectDeclaration } from "@shivaedev/contract/subject.ts";
|
|
6
|
+
import { DelegationRuleMissing } from "#DelegationRuleMissing.ts";
|
|
6
7
|
import type { Identity, SessionUser } from "#identity.ts";
|
|
7
8
|
import { IdentityFailures } from "#middleware.ts";
|
|
8
9
|
|
|
@@ -12,11 +13,25 @@ export class Subject extends Context.Service<Subject, { readonly id: SubjectId }
|
|
|
12
13
|
|
|
13
14
|
export type SubjectMiddleware<E = never, R = never> = RpcMiddleware.RpcMiddleware<Subject | Identity | SessionUser, IdentityFailures | E, R>;
|
|
14
15
|
|
|
16
|
+
// What the guard asks an application's delegation rule about one call. A query, a live query's changes stream and any other stream
|
|
17
|
+
// read; a command writes.
|
|
18
|
+
export interface DelegationRequest {
|
|
19
|
+
readonly kind: "read" | "write";
|
|
20
|
+
readonly module: string;
|
|
21
|
+
readonly operation: string;
|
|
22
|
+
readonly subject: SubjectId;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface DelegationRule<E = never> {
|
|
26
|
+
readonly allows: (request: DelegationRequest) => Effect.Effect<boolean, IdentityFailures | E>;
|
|
27
|
+
}
|
|
28
|
+
|
|
15
29
|
export class SubjectResolver extends Context.Service<
|
|
16
30
|
SubjectResolver,
|
|
17
31
|
{
|
|
18
32
|
readonly self: SubjectMiddleware;
|
|
19
33
|
readonly account: <E>(permission: Permission, deny: (id: string) => E) => SubjectMiddleware<E>;
|
|
34
|
+
readonly delegated: <E>(rule: DelegationRule<E>, deny: (id: string) => E) => SubjectMiddleware<E>;
|
|
20
35
|
}
|
|
21
36
|
>()("@shivaedev/identity/SubjectResolver") {}
|
|
22
37
|
|
|
@@ -35,3 +50,23 @@ export function accountSubject<TRefusal extends TaggedRejection>(options: {
|
|
|
35
50
|
middleware: Effect.map(SubjectResolver, (resolver) => resolver.account(options.permission, options.deny)),
|
|
36
51
|
} satisfies SubjectDeclaration;
|
|
37
52
|
}
|
|
53
|
+
|
|
54
|
+
export function delegatedSubject<const TService extends string, TRefusal extends TaggedRejection>(options: {
|
|
55
|
+
readonly service: TService;
|
|
56
|
+
readonly refusal: TRefusal;
|
|
57
|
+
readonly deny: (id: string) => NoInfer<TRefusal["Type"]>;
|
|
58
|
+
}) {
|
|
59
|
+
const rule = Context.Service<TService, DelegationRule<TRefusal["Type"]>>(options.service);
|
|
60
|
+
// The rule is looked up optionally so a host without it fails to start with a message naming it; the declared requirement
|
|
61
|
+
// still makes the compiler reject that host first.
|
|
62
|
+
const middleware: Effect.Effect<SubjectMiddleware<TRefusal["Type"]>, DelegationRuleMissing, SubjectResolver | TService> = Effect.gen(function* () {
|
|
63
|
+
const resolver = yield* SubjectResolver;
|
|
64
|
+
const found = yield* Effect.serviceOption(rule);
|
|
65
|
+
if (Option.isNone(found)) {
|
|
66
|
+
return yield* new DelegationRuleMissing({ service: options.service });
|
|
67
|
+
}
|
|
68
|
+
return resolver.delegated(found.value, options.deny);
|
|
69
|
+
});
|
|
70
|
+
const declaration = { error: Schema.Union([IdentityFailures, options.refusal]), middleware } satisfies SubjectDeclaration;
|
|
71
|
+
return { ...declaration, service: options.service };
|
|
72
|
+
}
|