@shivaedev/identity 0.5.1 → 0.6.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/README.md
CHANGED
|
@@ -373,7 +373,7 @@ const handlers = Api.toLayer({
|
|
|
373
373
|
});
|
|
374
374
|
```
|
|
375
375
|
|
|
376
|
-
Here `changes` is the application's `makeLiveServer` service. Keep `resolveChanges` in the invocation; resolving it while building a shared Layer would lose request identity. Pass the authorized subscription and context to `changes.subscribe`; it uses the query scopes to identify affected references and rechecks the same policies before hints leave.
|
|
376
|
+
Here `changes` is the application's `makeLiveServer` service. Pass the native RPC definition to `resolveChanges` so its typed failures and required services follow the policies declared by that contract. Keep `resolveChanges` in the invocation; resolving it while building a shared Layer would lose request identity. Pass the authorized subscription and context to `changes.subscribe`; it uses the query scopes to identify affected references and rechecks the same policies before hints leave.
|
|
377
377
|
|
|
378
378
|
Custom authentication middleware supplies the same boundary by validating the transport session, then wrapping scoped commands with `commandChanges` before providing `Identity`:
|
|
379
379
|
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import type { Rpc } from "effect/rpc";
|
|
3
3
|
import type { KeyContext } from "@shivaedev/changes/keys.ts";
|
|
4
|
+
import { type QuerySubscription } from "@shivaedev/contract/querySubscription.ts";
|
|
5
|
+
import { type PolicyChannels } from "@shivaedev/contract/readPolicy.ts";
|
|
6
|
+
import type { MissingReadPolicy, QueryReadDenied } from "@shivaedev/contract/readPolicyErrors.ts";
|
|
4
7
|
import { type QueryReference } from "@shivaedev/contract/serverMetadata.ts";
|
|
5
8
|
export declare function sessionKeyContext(rpc: Pick<Rpc.AnyWithProps, "annotations">): Effect.Effect<KeyContext | undefined>;
|
|
6
|
-
export declare
|
|
7
|
-
context: KeyContext | undefined;
|
|
8
|
-
subscription:
|
|
9
|
-
|
|
10
|
-
keys: import("@shivaedev/changes/keys.ts").Key[];
|
|
11
|
-
scopes: (readonly import("@shivaedev/changes/keys.ts").Key[])[];
|
|
12
|
-
};
|
|
13
|
-
}, import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy | import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, never>;
|
|
9
|
+
export declare function resolveChanges<TRpc extends Rpc.Any>(rpc: TRpc, references: readonly QueryReference[]): Effect.Effect<{
|
|
10
|
+
readonly context: KeyContext | undefined;
|
|
11
|
+
readonly subscription: QuerySubscription<PolicyChannels<TRpc>["error"], PolicyChannels<TRpc>["services"]>;
|
|
12
|
+
}, PolicyChannels<TRpc>["error"] | MissingReadPolicy | QueryReadDenied, PolicyChannels<TRpc>["services"]>;
|
|
14
13
|
//# sourceMappingURL=sessionKeys.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionKeys.d.ts","sourceRoot":"","sources":["../../src/server/sessionKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAU,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"sessionKeys.d.ts","sourceRoot":"","sources":["../../src/server/sessionKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,MAAM,EAAU,MAAM,QAAQ,CAAC;AACjD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,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,EAAY,KAAK,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAGtF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,aAAa,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC,CAWnH;AAED,wBAAgB,cAAc,CAAC,IAAI,SAAS,GAAG,CAAC,GAAG,EAClD,GAAG,EAAE,IAAI,EACT,UAAU,EAAE,SAAS,cAAc,EAAE,GACnC,MAAM,CAAC,MAAM,CACf;IACC,QAAQ,CAAC,OAAO,EAAE,UAAU,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,YAAY,EAAE,iBAAiB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;CAC1G,EACD,cAAc,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,iBAAiB,GAAG,eAAe,EACnE,cAAc,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,CAChC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context, Effect, Option } from "effect";
|
|
2
2
|
import { querySubscription } from "@shivaedev/contract/querySubscription.ts";
|
|
3
3
|
import { CurrentViewer } from "@shivaedev/contract/readPolicy.ts";
|
|
4
|
-
import {
|
|
4
|
+
import { KeyScope } from "@shivaedev/contract/serverMetadata.ts";
|
|
5
5
|
import { Identity } from "#identity.ts";
|
|
6
6
|
export function sessionKeyContext(rpc) {
|
|
7
7
|
if (Option.isNone(Context.getOption(rpc.annotations, KeyScope))) {
|
|
@@ -15,12 +15,13 @@ export function sessionKeyContext(rpc) {
|
|
|
15
15
|
return { scope: identity.value.id };
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
18
|
+
export function resolveChanges(rpc, references) {
|
|
19
|
+
return Effect.fnUntraced(function* () {
|
|
20
|
+
const identity = yield* Effect.serviceOption(Identity);
|
|
21
|
+
const current = yield* CurrentViewer;
|
|
22
|
+
const viewer = Option.orElse(identity, () => current);
|
|
23
|
+
const subscription = yield* querySubscription(rpc, references, viewer);
|
|
24
|
+
return { context: yield* sessionKeyContext(rpc), subscription };
|
|
25
|
+
})();
|
|
26
|
+
}
|
|
26
27
|
//# sourceMappingURL=sessionKeys.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionKeys.js","sourceRoot":"","sources":["../../src/server/sessionKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGjD,OAAO,
|
|
1
|
+
{"version":3,"file":"sessionKeys.js","sourceRoot":"","sources":["../../src/server/sessionKeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGjD,OAAO,EAA0B,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AACrG,OAAO,EAAE,aAAa,EAAuB,MAAM,mCAAmC,CAAC;AAEvF,OAAO,EAAE,QAAQ,EAAuB,MAAM,uCAAuC,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,MAAM,UAAU,iBAAiB,CAAC,GAA0C;IAC3E,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC;QACjE,OAAO,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QAC1B,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC7B,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC,CAAC;QACpG,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;IACrC,CAAC,CAAC,CAAC;AACJ,CAAC;AAaD,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,YAAY,GAAG,KAAK,CAAC,CAAC,iBAAiB,CAAC,GAAG,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;QACvE,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,YAAY,EAAE,CAAC;IACjE,CAAC,CAAC,EAAE,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Context, Effect, Option } from "effect";
|
|
2
2
|
import type { Rpc } from "effect/rpc";
|
|
3
3
|
import type { KeyContext } from "@shivaedev/changes/keys.ts";
|
|
4
|
-
import { querySubscription } from "@shivaedev/contract/querySubscription.ts";
|
|
5
|
-
import { CurrentViewer } from "@shivaedev/contract/readPolicy.ts";
|
|
6
|
-
import {
|
|
4
|
+
import { type QuerySubscription, querySubscription } from "@shivaedev/contract/querySubscription.ts";
|
|
5
|
+
import { CurrentViewer, type PolicyChannels } from "@shivaedev/contract/readPolicy.ts";
|
|
6
|
+
import type { MissingReadPolicy, QueryReadDenied } from "@shivaedev/contract/readPolicyErrors.ts";
|
|
7
|
+
import { KeyScope, type QueryReference } from "@shivaedev/contract/serverMetadata.ts";
|
|
7
8
|
import { Identity } from "#identity.ts";
|
|
8
9
|
|
|
9
10
|
export function sessionKeyContext(rpc: Pick<Rpc.AnyWithProps, "annotations">): Effect.Effect<KeyContext | undefined> {
|
|
@@ -19,11 +20,23 @@ export function sessionKeyContext(rpc: Pick<Rpc.AnyWithProps, "annotations">): E
|
|
|
19
20
|
});
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
23
|
+
export function resolveChanges<TRpc extends Rpc.Any>(
|
|
24
|
+
rpc: TRpc,
|
|
25
|
+
references: readonly QueryReference[],
|
|
26
|
+
): Effect.Effect<
|
|
27
|
+
{
|
|
28
|
+
readonly context: KeyContext | undefined;
|
|
29
|
+
readonly subscription: QuerySubscription<PolicyChannels<TRpc>["error"], PolicyChannels<TRpc>["services"]>;
|
|
30
|
+
},
|
|
31
|
+
PolicyChannels<TRpc>["error"] | MissingReadPolicy | QueryReadDenied,
|
|
32
|
+
PolicyChannels<TRpc>["services"]
|
|
33
|
+
>;
|
|
34
|
+
export function resolveChanges(rpc: Rpc.Any, references: readonly QueryReference[]) {
|
|
35
|
+
return Effect.fnUntraced(function* () {
|
|
36
|
+
const identity = yield* Effect.serviceOption(Identity);
|
|
37
|
+
const current = yield* CurrentViewer;
|
|
38
|
+
const viewer = Option.orElse(identity, () => current);
|
|
39
|
+
const subscription = yield* querySubscription(rpc, references, viewer);
|
|
40
|
+
return { context: yield* sessionKeyContext(rpc), subscription };
|
|
41
|
+
})();
|
|
42
|
+
}
|