@shivaedev/identity 0.26.2 → 0.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +3 -3
- package/dist/accountPreferences.d.ts +15 -15
- package/dist/server/localOwner.d.ts +4 -3
- package/dist/server/localOwner.d.ts.map +1 -1
- package/dist/server/localOwner.js +4 -3
- package/dist/server/localOwner.js.map +1 -1
- package/dist/server/machineTokens.d.ts +4 -3
- package/dist/server/machineTokens.d.ts.map +1 -1
- package/dist/server/machineTokens.js +6 -4
- package/dist/server/machineTokens.js.map +1 -1
- package/dist/sessions.d.ts +4 -4
- package/dist/sessions.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/server/localOwner.ts +4 -3
- package/src/server/machineTokens.ts +6 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.27.0 - 2026-11-05
|
|
4
|
+
|
|
5
|
+
### Breaking
|
|
6
|
+
|
|
7
|
+
- Require Effect 4.1.0 and its matching companion packages. Move `effect`, `@effect/platform-node`, `@effect/platform-node-shared`, `@effect/sql-pg`, `@effect/sql-sqlite-node`, `@effect/atom-react` and `@effect/vitest` to exactly 4.1.0 together. `localOwner` and `machineTokens` require `SecureRandom` and `Digest` from `effect/crypto` instead of `Crypto`; the server host provides both.
|
|
8
|
+
|
|
9
|
+
## 0.26.3 - 2026-11-05
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- Update `@shivaedev/contract` from 0.37.0 to 0.38.0.
|
|
14
|
+
|
|
3
15
|
## 0.26.2 - 2026-11-05
|
|
4
16
|
|
|
5
17
|
### Changed
|
package/README.md
CHANGED
|
@@ -38,7 +38,7 @@ An **Origin policy** is a function of the transport request's origin, headers an
|
|
|
38
38
|
|
|
39
39
|
### Declared request subjects
|
|
40
40
|
|
|
41
|
-
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
|
|
41
|
+
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` for the request. Code that needs the caller yields these services rather than taking the actor's id as an argument; a service whose operations yield them requires them in its Layer, so that Layer is built per request.
|
|
42
42
|
|
|
43
43
|
```ts
|
|
44
44
|
import { Effect, Schema } from "effect";
|
|
@@ -90,7 +90,7 @@ export const auth = createAuthClient({ plugins: [preferencesClient()] });
|
|
|
90
90
|
|
|
91
91
|
The browser sends its `Intl.DateTimeFormat` timezone and locale to the auth mount. A successful first sign-in captures those values with metric units. After redirect-based sign-in, the browser's first `getSession` captures them. Missing or invalid browser timezone data leaves preferences uncaptured; a later browser session can capture them. Other clients can call the `capture` contract with their own defaults.
|
|
92
92
|
|
|
93
|
-
`AccountClock` from `@shivaedev/identity/server/AccountClock.ts`
|
|
93
|
+
`AccountClock` from `@shivaedev/identity/server/AccountClock.ts` is a per-request service. Its Layer requires `Subject`, and its initializer captures that subject's saved timezone, so build the Layer within the subject's request, providing `AccountPreferencesStore.layer`. Each new request sees the current saved timezone. Configure `AccountDayStart` from `@shivaedev/identity/server/account-clock/settings.ts` in minutes after local midnight; it defaults to zero and accepts integers from 0 through 1439. The same module exports `LogicalDay`.
|
|
94
94
|
|
|
95
95
|
```ts
|
|
96
96
|
import { DateTime, Effect, Layer } from "effect";
|
|
@@ -134,7 +134,7 @@ The application's `auth` owns its storage and session configuration. A null look
|
|
|
134
134
|
|
|
135
135
|
### Local owners and machine callers
|
|
136
136
|
|
|
137
|
-
`localOwner` supplies a single configured person for a loopback application. Apply `machineTokenMigration` from `@shivaedev/identity/server/adapters/machineTokenMigration.ts` through the application's numbered PostgreSQL migrations, then create the provider with the application's `SqlClient` and Effect `
|
|
137
|
+
`localOwner` supplies a single configured person for a loopback application. Apply `machineTokenMigration` from `@shivaedev/identity/server/adapters/machineTokenMigration.ts` through the application's numbered PostgreSQL migrations, then create the provider with the application's `SqlClient` and Effect's `SecureRandom` and `Digest` services from `effect/crypto`:
|
|
138
138
|
|
|
139
139
|
```ts
|
|
140
140
|
import { Layer, Redacted } from "effect";
|
|
@@ -56,7 +56,7 @@ export declare const AccountPreferences: import("@shivaedev/contract/contract.ts
|
|
|
56
56
|
"~ClientError": never;
|
|
57
57
|
error: Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired]>;
|
|
58
58
|
requiredForClient: false;
|
|
59
|
-
}) | (import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/
|
|
59
|
+
}) | (import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/subjectMiddleware.ts").SubjectMiddleware<{
|
|
60
60
|
error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
|
|
61
61
|
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
62
62
|
}>, `@shivaedev/contract/Subject/${string}`, import("./identity.ts").Identity | import("./identity.ts").SessionUser | import("#subject.ts").Subject, Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, never, never, false> & {
|
|
@@ -64,11 +64,19 @@ export declare const AccountPreferences: import("@shivaedev/contract/contract.ts
|
|
|
64
64
|
error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
|
|
65
65
|
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
66
66
|
};
|
|
67
|
-
}), never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.
|
|
67
|
+
}), never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.get", Schema.Void, Schema.Struct<{
|
|
68
68
|
readonly locale: Schema.NonEmptyString;
|
|
69
69
|
readonly timezone: Schema.String;
|
|
70
70
|
readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
|
|
71
|
-
}>, Schema.
|
|
71
|
+
}>, Schema.Union<readonly [Schema.Union<readonly (typeof AuthUnavailable)[]>, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, (import("effect/Context").Reference<<A, E, R>(effect: Effect.Effect<A, E, R>, request: {
|
|
72
|
+
readonly rpc: import("effect/rpc/Rpc").Any;
|
|
73
|
+
readonly payload: unknown;
|
|
74
|
+
}) => Effect.Effect<A, E | import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy | import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied | import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired | import("effect/Types").unhandled, R>> & {
|
|
75
|
+
"~effect/rpc/RpcMiddleware": "~effect/rpc/RpcMiddleware";
|
|
76
|
+
"~ClientError": never;
|
|
77
|
+
error: Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired]>;
|
|
78
|
+
requiredForClient: false;
|
|
79
|
+
}) | (import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/subjectMiddleware.ts").SubjectMiddleware<{
|
|
72
80
|
error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
|
|
73
81
|
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
74
82
|
}>, `@shivaedev/contract/Subject/${string}`, import("./identity.ts").Identity | import("./identity.ts").SessionUser | import("#subject.ts").Subject, Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, never, never, false> & {
|
|
@@ -76,19 +84,11 @@ export declare const AccountPreferences: import("@shivaedev/contract/contract.ts
|
|
|
76
84
|
error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
|
|
77
85
|
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
78
86
|
};
|
|
79
|
-
}, never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.
|
|
87
|
+
}), never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.capture", Schema.Struct<{
|
|
80
88
|
readonly locale: Schema.NonEmptyString;
|
|
81
89
|
readonly timezone: Schema.String;
|
|
82
90
|
readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
|
|
83
|
-
}>, Schema.
|
|
84
|
-
readonly rpc: import("effect/rpc/Rpc").Any;
|
|
85
|
-
readonly payload: unknown;
|
|
86
|
-
}) => Effect.Effect<A, E | import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy | import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied | import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired | import("effect/Types").unhandled, R>> & {
|
|
87
|
-
"~effect/rpc/RpcMiddleware": "~effect/rpc/RpcMiddleware";
|
|
88
|
-
"~ClientError": never;
|
|
89
|
-
error: Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired]>;
|
|
90
|
-
requiredForClient: false;
|
|
91
|
-
}) | (import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/internal/subjectMiddleware.ts").SubjectMiddleware<{
|
|
91
|
+
}>, Schema.Void, Schema.Union<readonly (typeof AuthUnavailable)[]>, import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/subjectMiddleware.ts").SubjectMiddleware<{
|
|
92
92
|
error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
|
|
93
93
|
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
94
94
|
}>, `@shivaedev/contract/Subject/${string}`, import("./identity.ts").Identity | import("./identity.ts").SessionUser | import("#subject.ts").Subject, Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, never, never, false> & {
|
|
@@ -96,11 +96,11 @@ export declare const AccountPreferences: import("@shivaedev/contract/contract.ts
|
|
|
96
96
|
error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
|
|
97
97
|
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
98
98
|
};
|
|
99
|
-
}
|
|
99
|
+
}, never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.set", Schema.Struct<{
|
|
100
100
|
readonly locale: Schema.NonEmptyString;
|
|
101
101
|
readonly timezone: Schema.String;
|
|
102
102
|
readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
|
|
103
|
-
}>, Schema.Void, Schema.Union<readonly (typeof AuthUnavailable)[]>, import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/
|
|
103
|
+
}>, Schema.Void, Schema.Union<readonly (typeof AuthUnavailable)[]>, import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/subjectMiddleware.ts").SubjectMiddleware<{
|
|
104
104
|
error: Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>;
|
|
105
105
|
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
106
106
|
}>, `@shivaedev/contract/Subject/${string}`, import("./identity.ts").Identity | import("./identity.ts").SessionUser | import("#subject.ts").Subject, Schema.Union<readonly [typeof import("@shivaedev/errors/taxonomy.ts").Unauthorized, typeof AuthUnavailable, typeof import("@shivaedev/errors/taxonomy.ts").Forbidden, typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied]>, never, never, false> & {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Duration, Effect, Option, Redacted } from "effect";
|
|
2
|
+
import { SecureRandom } from "effect/crypto";
|
|
2
3
|
import type { RoleSet } from "@shivaedev/access/roleSet.ts";
|
|
3
4
|
import type { SessionUserValue } from "#identity.ts";
|
|
4
5
|
export declare const localOwner: (options: {
|
|
@@ -17,7 +18,7 @@ export declare const localOwner: (options: {
|
|
|
17
18
|
scope: string;
|
|
18
19
|
id: string;
|
|
19
20
|
token: Redacted.Redacted<string>;
|
|
20
|
-
}, import("effect/
|
|
21
|
+
}, import("effect/Schema").SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
21
22
|
resolve: (token: string) => Effect.Effect<Option.None<{
|
|
22
23
|
machine: {
|
|
23
24
|
id: string;
|
|
@@ -60,5 +61,5 @@ export declare const localOwner: (options: {
|
|
|
60
61
|
readonly streamRevalidationInterval?: Duration.Input | undefined;
|
|
61
62
|
};
|
|
62
63
|
token: Redacted.Redacted<string>;
|
|
63
|
-
}, import("@shivaedev/sql/repositoryCollection.ts").BucketRegistrationError | import("effect/
|
|
64
|
+
}, import("@shivaedev/sql/repositoryCollection.ts").BucketRegistrationError | import("effect/Schema").SchemaError, import("effect/crypto/Digest").Digest | SecureRandom.SecureRandom | import("effect/sql/SqlClient").SqlClient>;
|
|
64
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,
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gOAsBnD,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect, Option, Redacted } from "effect";
|
|
2
|
+
import { SecureRandom } from "effect/crypto";
|
|
2
3
|
import * as Hex from "effect/encoding/Hex";
|
|
3
4
|
import { localTransport } from "#server/adapters/local.ts";
|
|
4
5
|
import { machineTokens } from "./machineTokens.js";
|
|
5
6
|
export const localOwner = Effect.fn("Identity.localOwner")(function* (options) {
|
|
6
7
|
const { owner, roles } = options;
|
|
7
8
|
const access = yield* roles.resolve(owner.role);
|
|
8
|
-
const
|
|
9
|
-
const token = Redacted.make(Hex.encode(yield*
|
|
9
|
+
const random = yield* SecureRandom.SecureRandom;
|
|
10
|
+
const token = Redacted.make(Hex.encode(yield* random.randomBytes(32)));
|
|
10
11
|
const machines = yield* machineTokens({ owner, roles });
|
|
11
12
|
const allowed = localTransport();
|
|
12
13
|
const sessions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localOwner.js","sourceRoot":"","sources":["../../src/server/localOwner.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"localOwner.js","sourceRoot":"","sources":["../../src/server/localOwner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,GAAG,MAAM,qBAAqB,CAAC;AAG3C,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,EAAE,CAAC,qBAAqB,CAAC,CAAC,QAAQ,CAAC,EAAE,OAIrE;IACA,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IACjC,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,YAAY,CAAC,YAAY,CAAC;IAChD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACvE,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,aAAa,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;IACxD,MAAM,OAAO,GAAG,cAAc,EAAE,CAAC;IACjC,MAAM,QAAQ,GAA6B;QAC1C,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QACjH,QAAQ,EAAE;YACT,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE;gBAChB,MAAM,MAAM,GAAG,0BAA0B,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC;gBAC3F,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;oBAC1B,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;gBACtC,CAAC;gBACD,OAAO,MAAM,KAAK,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,GAAG,KAAK,EAAE,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACrI,CAAC;SACD;QACD,0BAA0B,EAAE,OAAO,CAAC,0BAA0B;KAC9D,CAAC;IACF,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AACtC,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect, Option, Redacted, Schema } from "effect";
|
|
2
|
+
import { Digest, SecureRandom } from "effect/crypto";
|
|
2
3
|
import type { RoleSet } from "@shivaedev/access/roleSet.ts";
|
|
3
4
|
import type { SessionUserValue } from "#identity.ts";
|
|
4
5
|
export declare const machineTokens: (options: {
|
|
@@ -13,7 +14,7 @@ export declare const machineTokens: (options: {
|
|
|
13
14
|
scope: string;
|
|
14
15
|
id: string;
|
|
15
16
|
token: Redacted.Redacted<string>;
|
|
16
|
-
},
|
|
17
|
+
}, Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
17
18
|
resolve: (token: string) => Effect.Effect<Option.None<{
|
|
18
19
|
machine: {
|
|
19
20
|
id: string;
|
|
@@ -48,5 +49,5 @@ export declare const machineTokens: (options: {
|
|
|
48
49
|
};
|
|
49
50
|
}>, import("@shivaedev/errors/taxonomy.ts").AuthUnavailable, never>;
|
|
50
51
|
revoke: (id: string) => Effect.Effect<void, Schema.SchemaError | import("effect/sql/SqlError").SqlError, never>;
|
|
51
|
-
}, import("@shivaedev/sql/repositoryCollection.ts").BucketRegistrationError,
|
|
52
|
+
}, import("@shivaedev/sql/repositoryCollection.ts").BucketRegistrationError, Digest.Digest | SecureRandom.SecureRandom | import("effect/sql/SqlClient").SqlClient>;
|
|
52
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,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kKAMhE,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect, Option, Redacted, Schema } from "effect";
|
|
2
|
+
import { Digest, SecureRandom } from "effect/crypto";
|
|
2
3
|
import * as Hex from "effect/encoding/Hex";
|
|
3
4
|
import { Model } from "effect/schema";
|
|
4
5
|
import { makeRepository } from "@shivaedev/sql/repository.ts";
|
|
@@ -11,19 +12,20 @@ class MachineToken extends Model.Class("IdentityMachineToken")({
|
|
|
11
12
|
}) {
|
|
12
13
|
}
|
|
13
14
|
export const machineTokens = Effect.fn("Identity.machineTokens")(function* (options) {
|
|
14
|
-
const
|
|
15
|
+
const random = yield* SecureRandom.SecureRandom;
|
|
16
|
+
const hashes = yield* Digest.Digest;
|
|
15
17
|
const repository = yield* makeRepository(MachineToken, {
|
|
16
18
|
idColumn: "id",
|
|
17
19
|
spanPrefix: "MachineTokens",
|
|
18
20
|
tableName: "identity_machine_tokens",
|
|
19
21
|
});
|
|
20
22
|
function digest(token) {
|
|
21
|
-
return
|
|
23
|
+
return hashes.digestHex(Digest.sha256, new TextEncoder().encode(token));
|
|
22
24
|
}
|
|
23
25
|
return {
|
|
24
26
|
issue: Effect.fn("MachineTokens.issue")(function* (input) {
|
|
25
27
|
yield* options.roles.resolve(input.scope);
|
|
26
|
-
const token = Hex.encode(yield*
|
|
28
|
+
const token = Hex.encode(yield* random.randomBytes(32));
|
|
27
29
|
const id = yield* digest(token);
|
|
28
30
|
yield* repository.insertVoid({ id, name: input.name, ownerId: options.owner.id, scope: input.scope });
|
|
29
31
|
return { id, ...input, token: Redacted.make(token) };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"machineTokens.js","sourceRoot":"","sources":["../../src/server/machineTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"machineTokens.js","sourceRoot":"","sources":["../../src/server/machineTokens.ts"],"names":[],"mappings":"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"}
|
package/dist/sessions.d.ts
CHANGED
|
@@ -108,9 +108,7 @@ export declare const Sessions: import("@shivaedev/contract/contract.ts").Contrac
|
|
|
108
108
|
"~ClientError": never;
|
|
109
109
|
error: Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired]>;
|
|
110
110
|
requiredForClient: false;
|
|
111
|
-
}), never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.
|
|
112
|
-
id: Schema.String;
|
|
113
|
-
}>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable)[]>, typeof SessionsPermission, never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.list", Schema.Struct<{
|
|
111
|
+
}), never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.list", Schema.Struct<{
|
|
114
112
|
readonly cursor: Schema.optionalKey<Schema.Struct<{
|
|
115
113
|
readonly id: Schema.String;
|
|
116
114
|
readonly lastActivityAt: Schema.DateTimeUtcFromString;
|
|
@@ -140,5 +138,7 @@ export declare const Sessions: import("@shivaedev/contract/contract.ts").Contrac
|
|
|
140
138
|
"~ClientError": never;
|
|
141
139
|
error: Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired]>;
|
|
142
140
|
requiredForClient: false;
|
|
143
|
-
}), never
|
|
141
|
+
}), never> | import("effect/rpc/Rpc").Rpc<"identity.sessions.revoke", Schema.Struct<{
|
|
142
|
+
id: Schema.String;
|
|
143
|
+
}>, Schema.Void, Schema.Union<readonly (typeof NotFound | typeof Forbidden | typeof AuthUnavailable)[]>, typeof SessionsPermission, never>, readonly [], undefined>;
|
|
144
144
|
//# sourceMappingURL=sessions.d.ts.map
|
package/dist/sessions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIxC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAI5D,eAAO,MAAM,eAAe;;;;;;;;;;EAM1B,CAAC;AAEH,eAAO,MAAM,aAAa;;;EAAqF,CAAC;AAChH,eAAO,MAAM,gBAAgB;;;;;;EAG3B,CAAC;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;EAA2G,CAAC;AAEpI,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../src/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIxC,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACrF,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAI5D,eAAO,MAAM,eAAe;;;;;;;;;;EAM1B,CAAC;AAEH,eAAO,MAAM,aAAa;;;EAAqF,CAAC;AAChH,eAAO,MAAM,gBAAgB;;;;;;EAG3B,CAAC;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;EAA2G,CAAC;AAEpI,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mKAiBY,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/identity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Request identity, sessions, transport trust and permission enforcement for Effect RPC servers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -45,34 +45,34 @@
|
|
|
45
45
|
"README.md"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@shivaedev/access": "0.
|
|
49
|
-
"@shivaedev/changes": "0.
|
|
50
|
-
"@shivaedev/contract": "0.
|
|
51
|
-
"@shivaedev/errors": "0.
|
|
52
|
-
"@shivaedev/rate-limit": "0.
|
|
53
|
-
"@shivaedev/service": "0.
|
|
54
|
-
"@shivaedev/sql": "0.
|
|
48
|
+
"@shivaedev/access": "0.6.0",
|
|
49
|
+
"@shivaedev/changes": "0.11.0",
|
|
50
|
+
"@shivaedev/contract": "0.39.0",
|
|
51
|
+
"@shivaedev/errors": "0.10.0",
|
|
52
|
+
"@shivaedev/rate-limit": "0.6.0",
|
|
53
|
+
"@shivaedev/service": "0.8.0",
|
|
54
|
+
"@shivaedev/sql": "0.42.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@better-auth/oauth-provider": "1.7.14",
|
|
58
|
-
"@effect/platform-node": "4.0
|
|
59
|
-
"@effect/sql-pg": "4.0
|
|
60
|
-
"@shivaedev/admin": "0.
|
|
61
|
-
"@shivaedev/quality": "0.
|
|
62
|
-
"@shivaedev/server": "0.
|
|
63
|
-
"@shivaedev/test-kits": "0.
|
|
64
|
-
"@shivaedev/test-sql": "0.
|
|
65
|
-
"@shivaedev/test-story": "0.
|
|
58
|
+
"@effect/platform-node": "4.1.0",
|
|
59
|
+
"@effect/sql-pg": "4.1.0",
|
|
60
|
+
"@shivaedev/admin": "0.21.0",
|
|
61
|
+
"@shivaedev/quality": "0.65.0",
|
|
62
|
+
"@shivaedev/server": "0.27.0",
|
|
63
|
+
"@shivaedev/test-kits": "0.8.0",
|
|
64
|
+
"@shivaedev/test-sql": "0.24.0",
|
|
65
|
+
"@shivaedev/test-story": "0.42.0",
|
|
66
66
|
"@types/node": "24.19.2",
|
|
67
67
|
"better-auth": "1.7.14",
|
|
68
|
-
"effect": "4.0
|
|
68
|
+
"effect": "4.1.0",
|
|
69
69
|
"typescript": "7.0.2",
|
|
70
70
|
"vitest": "5.0.5"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
|
73
73
|
"@better-auth/oauth-provider": "1.7.14",
|
|
74
74
|
"better-auth": "1.7.14",
|
|
75
|
-
"effect": "4.0
|
|
75
|
+
"effect": "4.1.0"
|
|
76
76
|
},
|
|
77
77
|
"peerDependenciesMeta": {
|
|
78
78
|
"@better-auth/oauth-provider": {
|
package/src/server/localOwner.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Duration, Effect, Option, Redacted } from "effect";
|
|
2
|
+
import { SecureRandom } from "effect/crypto";
|
|
2
3
|
import * as Hex from "effect/encoding/Hex";
|
|
3
4
|
import type { RoleSet } from "@shivaedev/access/roleSet.ts";
|
|
4
5
|
import type { SessionUserValue } from "#identity.ts";
|
|
@@ -13,8 +14,8 @@ export const localOwner = Effect.fn("Identity.localOwner")(function* (options: {
|
|
|
13
14
|
}) {
|
|
14
15
|
const { owner, roles } = options;
|
|
15
16
|
const access = yield* roles.resolve(owner.role);
|
|
16
|
-
const
|
|
17
|
-
const token = Redacted.make(Hex.encode(yield*
|
|
17
|
+
const random = yield* SecureRandom.SecureRandom;
|
|
18
|
+
const token = Redacted.make(Hex.encode(yield* random.randomBytes(32)));
|
|
18
19
|
const machines = yield* machineTokens({ owner, roles });
|
|
19
20
|
const allowed = localTransport();
|
|
20
21
|
const sessions: SessionPolicy["Service"] = {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect, Option, Redacted, Schema } from "effect";
|
|
2
|
+
import { Digest, SecureRandom } from "effect/crypto";
|
|
2
3
|
import * as Hex from "effect/encoding/Hex";
|
|
3
4
|
import { Model } from "effect/schema";
|
|
4
5
|
import type { RoleSet } from "@shivaedev/access/roleSet.ts";
|
|
@@ -17,19 +18,20 @@ export const machineTokens = Effect.fn("Identity.machineTokens")(function* (opti
|
|
|
17
18
|
readonly owner: Pick<SessionUserValue, "id" | "name" | "email">;
|
|
18
19
|
readonly roles: RoleSet;
|
|
19
20
|
}) {
|
|
20
|
-
const
|
|
21
|
+
const random = yield* SecureRandom.SecureRandom;
|
|
22
|
+
const hashes = yield* Digest.Digest;
|
|
21
23
|
const repository = yield* makeRepository(MachineToken, {
|
|
22
24
|
idColumn: "id",
|
|
23
25
|
spanPrefix: "MachineTokens",
|
|
24
26
|
tableName: "identity_machine_tokens",
|
|
25
27
|
});
|
|
26
28
|
function digest(token: string) {
|
|
27
|
-
return
|
|
29
|
+
return hashes.digestHex(Digest.sha256, new TextEncoder().encode(token));
|
|
28
30
|
}
|
|
29
31
|
return {
|
|
30
32
|
issue: Effect.fn("MachineTokens.issue")(function* (input: { readonly name: string; readonly scope: string }) {
|
|
31
33
|
yield* options.roles.resolve(input.scope);
|
|
32
|
-
const token = Hex.encode(yield*
|
|
34
|
+
const token = Hex.encode(yield* random.randomBytes(32));
|
|
33
35
|
const id = yield* digest(token);
|
|
34
36
|
yield* repository.insertVoid({ id, name: input.name, ownerId: options.owner.id, scope: input.scope });
|
|
35
37
|
return { id, ...input, token: Redacted.make(token) };
|