@shivaedev/identity 0.5.1 → 0.7.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 const resolveChanges: (rpc: Pick<Rpc.AnyWithProps, "annotations">, references: readonly QueryReference[]) => Effect.Effect<{
7
- context: KeyContext | undefined;
8
- subscription: {
9
- authorized: Effect.Effect<boolean, never, never>;
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;AAG7D,OAAO,EAA4B,KAAK,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAGtG,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,aAAa,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC,CAWnH;AAED,eAAO,MAAM,cAAc;;;;;;;kJAOzB,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 { ChangesQueries, KeyScope } from "@shivaedev/contract/serverMetadata.ts";
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 const resolveChanges = Effect.fnUntraced(function* (rpc, references) {
19
- const identity = yield* Effect.serviceOption(Identity);
20
- const current = yield* CurrentViewer;
21
- const viewer = Option.orElse(identity, () => current);
22
- const queries = yield* Context.getUnsafe(rpc.annotations, ChangesQueries).resolve(references);
23
- const subscription = yield* querySubscription(queries, viewer);
24
- return { context: yield* sessionKeyContext(rpc), subscription };
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,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAuB,MAAM,uCAAuC,CAAC;AACtG,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,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package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shivaedev/identity",
3
- "version": "0.5.1",
3
+ "version": "0.7.0",
4
4
  "description": "Request identity, sessions, transport trust and permission enforcement for Effect RPC servers",
5
5
  "keywords": [
6
6
  "effect"
@@ -46,7 +46,7 @@
46
46
  "dependencies": {
47
47
  "@shivaedev/access": "0.2.0",
48
48
  "@shivaedev/changes": "0.5.1",
49
- "@shivaedev/contract": "0.22.0",
49
+ "@shivaedev/contract": "0.23.0",
50
50
  "@shivaedev/errors": "0.1.2",
51
51
  "@shivaedev/sql": "0.26.1"
52
52
  },
@@ -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 { ChangesQueries, KeyScope, type QueryReference } from "@shivaedev/contract/serverMetadata.ts";
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 const resolveChanges = Effect.fnUntraced(function* (rpc: Pick<Rpc.AnyWithProps, "annotations">, references: readonly QueryReference[]) {
23
- const identity = yield* Effect.serviceOption(Identity);
24
- const current = yield* CurrentViewer;
25
- const viewer = Option.orElse(identity, () => current);
26
- const queries = yield* Context.getUnsafe(rpc.annotations, ChangesQueries).resolve(references);
27
- const subscription = yield* querySubscription(queries, viewer);
28
- return { context: yield* sessionKeyContext(rpc), subscription };
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
+ }