@shivaedev/identity 0.31.1 → 0.32.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 +21 -0
- package/README.md +20 -5
- package/dist/AccountPreferences.d.ts +52 -0
- package/dist/AccountPreferences.d.ts.map +1 -0
- package/dist/AccountPreferences.js +37 -0
- package/dist/AccountPreferences.js.map +1 -0
- package/dist/Sessions.d.ts +40 -0
- package/dist/Sessions.d.ts.map +1 -0
- package/dist/Sessions.js +30 -0
- package/dist/Sessions.js.map +1 -0
- package/dist/accountPreferenceValues.d.ts +9 -0
- package/dist/accountPreferenceValues.d.ts.map +1 -0
- package/dist/accountPreferenceValues.js +10 -0
- package/dist/accountPreferenceValues.js.map +1 -0
- package/dist/generated/AccountPreferences.d.ts +58 -0
- package/dist/generated/AccountPreferences.d.ts.map +1 -0
- package/dist/generated/AccountPreferences.js +28 -0
- package/dist/generated/AccountPreferences.js.map +1 -0
- package/dist/generated/Sessions.d.ts +76 -0
- package/dist/generated/Sessions.d.ts.map +1 -0
- package/dist/generated/Sessions.js +26 -0
- package/dist/generated/Sessions.js.map +1 -0
- package/dist/server/account-preferences/Rows.js +1 -1
- package/dist/server/account-preferences/Rows.js.map +1 -1
- package/dist/server/account-preferences/get.d.ts +3 -7
- package/dist/server/account-preferences/get.d.ts.map +1 -1
- package/dist/server/account-preferences/get.js +2 -1
- package/dist/server/account-preferences/get.js.map +1 -1
- package/dist/server/account-preferences/service.d.ts +3 -7
- package/dist/server/account-preferences/service.d.ts.map +1 -1
- package/dist/server/better-auth/adapters/accountPreferenceOptions.js +1 -1
- package/dist/server/better-auth/adapters/accountPreferenceOptions.js.map +1 -1
- package/dist/server/better-auth/sessionAdministration.d.ts +3 -18
- package/dist/server/better-auth/sessionAdministration.d.ts.map +1 -1
- package/dist/server/better-auth/sessionAdministration.js +3 -2
- package/dist/server/better-auth/sessionAdministration.js.map +1 -1
- package/dist/signedInSessions.d.ts +29 -0
- package/dist/signedInSessions.d.ts.map +1 -0
- package/dist/signedInSessions.js +16 -0
- package/dist/signedInSessions.js.map +1 -0
- package/dist/users.d.ts +2 -2
- package/dist/users.d.ts.map +1 -1
- package/package.json +27 -25
- package/src/AccountPreferences.ts +40 -0
- package/src/Sessions.ts +32 -0
- package/src/accountPreferenceValues.ts +14 -0
- package/src/generated/AccountPreferences.ts +33 -0
- package/src/generated/README.md +1 -0
- package/src/generated/Sessions.ts +31 -0
- package/src/server/account-preferences/Rows.ts +1 -1
- package/src/server/account-preferences/capture.ts +1 -1
- package/src/server/account-preferences/get.ts +5 -2
- package/src/server/account-preferences/set.ts +1 -1
- package/src/server/better-auth/adapters/accountPreferenceOptions.ts +1 -1
- package/src/server/better-auth/sessionAdministration.ts +3 -2
- package/src/signedInSessions.ts +23 -0
- package/dist/accountPreferences.d.ts +0 -106
- package/dist/accountPreferences.d.ts.map +0 -1
- package/dist/accountPreferences.js +0 -37
- package/dist/accountPreferences.js.map +0 -1
- package/dist/server/accountPreferencesHandlers.d.ts +0 -2
- package/dist/server/accountPreferencesHandlers.d.ts.map +0 -1
- package/dist/server/accountPreferencesHandlers.js +0 -19
- package/dist/server/accountPreferencesHandlers.js.map +0 -1
- package/dist/server/better-auth/sessionsHandlers.d.ts +0 -2
- package/dist/server/better-auth/sessionsHandlers.d.ts.map +0 -1
- package/dist/server/better-auth/sessionsHandlers.js +0 -7
- package/dist/server/better-auth/sessionsHandlers.js.map +0 -1
- package/dist/sessions.d.ts +0 -150
- package/dist/sessions.d.ts.map +0 -1
- package/dist/sessions.js +0 -39
- package/dist/sessions.js.map +0 -1
- package/src/accountPreferences.ts +0 -42
- package/src/server/accountPreferencesHandlers.ts +0 -22
- package/src/server/better-auth/sessionsHandlers.ts +0 -7
- package/src/sessions.ts +0 -42
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"accountPreferenceOptions.js","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/accountPreferenceOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"accountPreferenceOptions.js","sourceRoot":"","sources":["../../../../src/server/better-auth/adapters/accountPreferenceOptions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEjF,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAsC,OAAiB;IACzH,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,uBAAuB,CAAC;IAC7C,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,EAAS,CAAC;IAChD,MAAM,OAAO,GAAG,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACtD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC;QACtE,MAAM,MAAM,GAAG,MAAM,CAAC,mBAAmB,CAAC,uBAAuB,CAAC,CAAC;YAClE,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,2BAA2B,CAAC;YACzD,QAAQ,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,6BAA6B,CAAC;YAC7D,KAAK,EAAE,QAAQ;SACf,CAAC,CAAC;QACH,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;YACxE,MAAM,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1H,CAAC;IACF,CAAC,CAAC,CAAC;IACH,MAAM,MAAM,GAAG;QACd,KAAK,EAAE;YACN,KAAK,EAAE;gBACN;oBACC,OAAO,EAAE,OAAO;oBAChB,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,cAAc,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,KAAK,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC;iBAC1I;aACD;SACD;QACD,EAAE,EAAE,8BAA8B;KACP,CAAC;IAC7B,OAAO,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,EAA8B,CAAC;AAClG,CAAC,CAAC,CAAC"}
|
|
@@ -1,29 +1,14 @@
|
|
|
1
|
-
import { DateTime, Effect
|
|
1
|
+
import { DateTime, Effect } from "effect";
|
|
2
2
|
import { SqlClient } from "effect/sql";
|
|
3
3
|
import { AuthUnavailable, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
4
4
|
import { SessionUser } from "#identity.ts";
|
|
5
|
+
import { type SessionList } from "#signedInSessions.ts";
|
|
5
6
|
export declare const listSessions: (input: {
|
|
6
7
|
readonly cursor?: {
|
|
7
8
|
readonly id: string;
|
|
8
9
|
readonly lastActivityAt: DateTime.Utc;
|
|
9
10
|
};
|
|
10
11
|
readonly limit: number;
|
|
11
|
-
}) => Effect.Effect<
|
|
12
|
-
next: Option.Option<{
|
|
13
|
-
readonly id: string;
|
|
14
|
-
readonly lastActivityAt: DateTime.Utc;
|
|
15
|
-
}>;
|
|
16
|
-
sessions: readonly {
|
|
17
|
-
readonly expiresAt: DateTime.Utc;
|
|
18
|
-
readonly id: string;
|
|
19
|
-
readonly lastActivityAt: DateTime.Utc;
|
|
20
|
-
readonly startedAt: DateTime.Utc;
|
|
21
|
-
readonly user: {
|
|
22
|
-
readonly email: string;
|
|
23
|
-
readonly id: string;
|
|
24
|
-
readonly name: string;
|
|
25
|
-
};
|
|
26
|
-
}[];
|
|
27
|
-
}, AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden, SessionUser | SqlClient.SqlClient>;
|
|
12
|
+
}) => Effect.Effect<SessionList, AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden, SessionUser | SqlClient.SqlClient>;
|
|
28
13
|
export declare const revokeSession: (id: string) => Effect.Effect<undefined, AuthUnavailable | import("@shivaedev/errors/taxonomy.ts").Forbidden | NotFound, SessionUser | SqlClient.SqlClient>;
|
|
29
14
|
//# sourceMappingURL=sessionAdministration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionAdministration.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/sessionAdministration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"sessionAdministration.d.ts","sourceRoot":"","sources":["../../../src/server/better-auth/sessionAdministration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAkB,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAE1E,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAAE,KAAK,WAAW,EAA0C,MAAM,sBAAsB,CAAC;AAMhG,eAAO,MAAM,YAAY;;;;;;wIAuBvB,CAAC;AAEH,eAAO,MAAM,aAAa,6JAYxB,CAAC"}
|
|
@@ -5,7 +5,7 @@ import { AuthUnavailable, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
|
5
5
|
import { keysetPage } from "@shivaedev/sql/keysetPage.ts";
|
|
6
6
|
import { SessionUser } from "#identity.ts";
|
|
7
7
|
import { ManageSessions } from "#sessionPermissions.ts";
|
|
8
|
-
import { SignedInSession } from "#
|
|
8
|
+
import { SignedInSession } from "#signedInSessions.ts";
|
|
9
9
|
function unavailable() {
|
|
10
10
|
return new AuthUnavailable({ message: "Could not access signed-in sessions" });
|
|
11
11
|
}
|
|
@@ -29,7 +29,8 @@ export const listSessions = Effect.fn("Identity.listSessions")(function* (input)
|
|
|
29
29
|
})(undefined),
|
|
30
30
|
tieBreaker: { column: sql `s.id`, direction: "desc", value: (cursor) => cursor.id },
|
|
31
31
|
}).pipe(Effect.mapError(unavailable));
|
|
32
|
-
|
|
32
|
+
const list = { next: page.next, sessions: page.rows };
|
|
33
|
+
return list;
|
|
33
34
|
});
|
|
34
35
|
export const revokeSession = Effect.fn("Identity.revokeSession")(function* (id) {
|
|
35
36
|
yield* requirePermission(yield* SessionUser, ManageSessions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessionAdministration.js","sourceRoot":"","sources":["../../../src/server/better-auth/sessionAdministration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wCAAwC,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,
|
|
1
|
+
{"version":3,"file":"sessionAdministration.js","sourceRoot":"","sources":["../../../src/server/better-auth/sessionAdministration.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Option, Schema } from "effect";
|
|
2
|
+
export declare const sessionKeys: import("@shivaedev/changes/keys.ts").Collection<"identity.sessions", string, Record<never, never>, Record<never, never>>;
|
|
3
|
+
export declare const SignedInSession: Schema.Struct<{
|
|
4
|
+
readonly expiresAt: Schema.DateTimeUtcFromDate;
|
|
5
|
+
readonly id: Schema.String;
|
|
6
|
+
readonly lastActivityAt: Schema.DateTimeUtcFromDate;
|
|
7
|
+
readonly startedAt: Schema.DateTimeUtcFromDate;
|
|
8
|
+
readonly user: Schema.Struct<{
|
|
9
|
+
readonly email: Schema.String;
|
|
10
|
+
readonly id: Schema.String;
|
|
11
|
+
readonly name: Schema.String;
|
|
12
|
+
}>;
|
|
13
|
+
}>;
|
|
14
|
+
export declare const SessionCursor: Schema.Struct<{
|
|
15
|
+
readonly id: Schema.String;
|
|
16
|
+
readonly lastActivityAt: Schema.DateTimeUtcFromString;
|
|
17
|
+
}>;
|
|
18
|
+
export declare const SessionListInput: Schema.Struct<{
|
|
19
|
+
readonly cursor: Schema.optionalKey<Schema.Struct<{
|
|
20
|
+
readonly id: Schema.String;
|
|
21
|
+
readonly lastActivityAt: Schema.DateTimeUtcFromString;
|
|
22
|
+
}>>;
|
|
23
|
+
readonly limit: Schema.Number;
|
|
24
|
+
}>;
|
|
25
|
+
export interface SessionList {
|
|
26
|
+
readonly next: Option.Option<typeof SessionCursor.Type>;
|
|
27
|
+
readonly sessions: readonly (typeof SignedInSession.Type)[];
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=signedInSessions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signedInSessions.d.ts","sourceRoot":"","sources":["../src/signedInSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAG7C,eAAO,MAAM,WAAW,0HAAiD,CAAC;AAE1E,eAAO,MAAM,eAAe;;;;;;;;;;EAM1B,CAAC;AAEH,eAAO,MAAM,aAAa;;;EAAqF,CAAC;AAChH,eAAO,MAAM,gBAAgB;;;;;;EAG3B,CAAC;AAEH,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC;IACxD,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC,OAAO,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;CAC5D"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { collection } from "@shivaedev/changes/keys.ts";
|
|
3
|
+
export const sessionKeys = collection("identity.sessions", Schema.String);
|
|
4
|
+
export const SignedInSession = Schema.Struct({
|
|
5
|
+
expiresAt: Schema.DateTimeUtcFromDate,
|
|
6
|
+
id: Schema.String,
|
|
7
|
+
lastActivityAt: Schema.DateTimeUtcFromDate,
|
|
8
|
+
startedAt: Schema.DateTimeUtcFromDate,
|
|
9
|
+
user: Schema.Struct({ email: Schema.String, id: Schema.String, name: Schema.String }),
|
|
10
|
+
});
|
|
11
|
+
export const SessionCursor = Schema.Struct({ id: Schema.String, lastActivityAt: Schema.DateTimeUtcFromString });
|
|
12
|
+
export const SessionListInput = Schema.Struct({
|
|
13
|
+
cursor: Schema.optionalKey(SessionCursor),
|
|
14
|
+
limit: Schema.Number.check(Schema.isInt(), Schema.isBetween({ maximum: 100, minimum: 1 })),
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=signedInSessions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signedInSessions.js","sourceRoot":"","sources":["../src/signedInSessions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAExD,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;AAE1E,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC;IAC5C,SAAS,EAAE,MAAM,CAAC,mBAAmB;IACrC,EAAE,EAAE,MAAM,CAAC,MAAM;IACjB,cAAc,EAAE,MAAM,CAAC,mBAAmB;IAC1C,SAAS,EAAE,MAAM,CAAC,mBAAmB;IACrC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC;CACrF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,CAAC,qBAAqB,EAAE,CAAC,CAAC;AAChH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7C,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,aAAa,CAAC;IACzC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC;CAC1F,CAAC,CAAC"}
|
package/dist/users.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
export declare const userKeys: import("@shivaedev/changes/keys.ts").Collection<"identity.users", string, Record<never, never>>;
|
|
3
|
-
export declare const roleKeys: import("@shivaedev/changes/keys.ts").Collection<"identity.roles", string, Record<never, never>>;
|
|
2
|
+
export declare const userKeys: import("@shivaedev/changes/keys.ts").Collection<"identity.users", string, Record<never, never>, Record<never, never>>;
|
|
3
|
+
export declare const roleKeys: import("@shivaedev/changes/keys.ts").Collection<"identity.roles", string, Record<never, never>, Record<never, never>>;
|
|
4
4
|
export declare const DirectoryUser: Schema.Struct<{
|
|
5
5
|
readonly createdAt: Schema.DateTimeUtcFromDate;
|
|
6
6
|
readonly email: Schema.String;
|
package/dist/users.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../src/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,eAAO,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"users.d.ts","sourceRoot":"","sources":["../src/users.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGhC,eAAO,MAAM,QAAQ,uHAA8C,CAAC;AACpE,eAAO,MAAM,QAAQ,uHAA8C,CAAC;AAEpE,eAAO,MAAM,aAAa;;;;;;EAMxB,CAAC;AACH,eAAO,MAAM,aAAa;;;EAGxB,CAAC;AACH,eAAO,MAAM,QAAQ;;;;;;;;;EAAsG,CAAC;AAC5H,eAAO,MAAM,WAAW;;;EAA4D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shivaedev/identity",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.32.0",
|
|
4
4
|
"description": "Request identity, sessions, transport trust and permission enforcement for Effect RPC servers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect"
|
|
@@ -46,34 +46,35 @@
|
|
|
46
46
|
"README.md"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@shivaedev/access": "0.6.
|
|
50
|
-
"@shivaedev/changes": "0.
|
|
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.3",
|
|
50
|
+
"@shivaedev/changes": "0.12.0",
|
|
51
|
+
"@shivaedev/contract": "0.44.0",
|
|
52
|
+
"@shivaedev/errors": "0.12.0",
|
|
53
|
+
"@shivaedev/rate-limit": "0.6.10",
|
|
54
|
+
"@shivaedev/service": "0.9.1",
|
|
55
|
+
"@shivaedev/sql": "0.47.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/
|
|
63
|
-
"@shivaedev/
|
|
64
|
-
"@shivaedev/
|
|
65
|
-
"@shivaedev/test-
|
|
66
|
-
"@shivaedev/test-
|
|
58
|
+
"@better-auth/oauth-provider": "1.7.16",
|
|
59
|
+
"@effect/platform-node": "4.1.2",
|
|
60
|
+
"@effect/sql-pg": "4.1.2",
|
|
61
|
+
"@shivaedev/admin": "0.25.0",
|
|
62
|
+
"@shivaedev/build": "0.1.1",
|
|
63
|
+
"@shivaedev/quality": "0.78.0",
|
|
64
|
+
"@shivaedev/server": "0.34.1",
|
|
65
|
+
"@shivaedev/test-kits": "0.12.1",
|
|
66
|
+
"@shivaedev/test-sql": "0.25.0",
|
|
67
|
+
"@shivaedev/test-story": "0.47.1",
|
|
67
68
|
"@types/node": "24.19.2",
|
|
68
|
-
"better-auth": "1.7.
|
|
69
|
-
"effect": "4.1.
|
|
69
|
+
"better-auth": "1.7.16",
|
|
70
|
+
"effect": "4.1.2",
|
|
70
71
|
"typescript": "7.0.2",
|
|
71
|
-
"vitest": "5.0
|
|
72
|
+
"vitest": "5.1.0"
|
|
72
73
|
},
|
|
73
74
|
"peerDependencies": {
|
|
74
|
-
"@better-auth/oauth-provider": "1.7.
|
|
75
|
-
"better-auth": "1.7.
|
|
76
|
-
"effect": "4.1.
|
|
75
|
+
"@better-auth/oauth-provider": "1.7.16",
|
|
76
|
+
"better-auth": "1.7.16",
|
|
77
|
+
"effect": "4.1.2"
|
|
77
78
|
},
|
|
78
79
|
"peerDependenciesMeta": {
|
|
79
80
|
"@better-auth/oauth-provider": {
|
|
@@ -91,9 +92,10 @@
|
|
|
91
92
|
"provenance": true
|
|
92
93
|
},
|
|
93
94
|
"scripts": {
|
|
94
|
-
"build": "node --eval \"import('node:fs').then(({ rmSync }) => rmSync('dist', { force: true, recursive: true }))\" && tsc --project tsconfig.build.json",
|
|
95
|
+
"build": "node --eval \"import('node:fs').then(({ rmSync }) => rmSync('dist', { force: true, recursive: true }))\" && pnpm generate && tsc --project tsconfig.build.json",
|
|
96
|
+
"generate": "shivaedev-build generate",
|
|
95
97
|
"ready": "pnpm typecheck && pnpm test && pnpm build",
|
|
96
98
|
"test": "vitest run",
|
|
97
|
-
"typecheck": "tsc --noEmit"
|
|
99
|
+
"typecheck": "pnpm generate && tsc --noEmit"
|
|
98
100
|
}
|
|
99
101
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defineModule } from "@shivaedev/contract/defineModule.ts";
|
|
2
|
+
import { command, query } from "@shivaedev/contract/operation.ts";
|
|
3
|
+
import { AccountPreferenceValues, accountPreferenceKeys } from "#accountPreferenceValues.ts";
|
|
4
|
+
import { identityAccountPreferencesWire } from "#generated/AccountPreferences.ts";
|
|
5
|
+
import { AccountPreferencesStore } from "#server/account-preferences/service.ts";
|
|
6
|
+
import { Subject, selfSubject } from "#subject.ts";
|
|
7
|
+
|
|
8
|
+
const GetPreferences = query("get", {
|
|
9
|
+
reads: () => [accountPreferenceKeys.list],
|
|
10
|
+
*run() {
|
|
11
|
+
const { id } = yield* Subject;
|
|
12
|
+
return yield* (yield* AccountPreferencesStore).get(id);
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const SetPreferences = command("set", {
|
|
17
|
+
invalidates: () => [accountPreferenceKeys.list],
|
|
18
|
+
payload: AccountPreferenceValues.fields,
|
|
19
|
+
*run(values) {
|
|
20
|
+
const { id } = yield* Subject;
|
|
21
|
+
yield* (yield* AccountPreferencesStore).set(id, values);
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const CapturePreferences = command("capture", {
|
|
26
|
+
invalidates: () => [accountPreferenceKeys.list],
|
|
27
|
+
payload: AccountPreferenceValues.fields,
|
|
28
|
+
*run(values) {
|
|
29
|
+
const { id } = yield* Subject;
|
|
30
|
+
yield* (yield* AccountPreferencesStore).capture(id, values);
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export const AccountPreferences = defineModule({
|
|
35
|
+
name: "identity.accountPreferences",
|
|
36
|
+
operations: [GetPreferences, SetPreferences, CapturePreferences],
|
|
37
|
+
requires: [AccountPreferencesStore],
|
|
38
|
+
subject: selfSubject,
|
|
39
|
+
wire: identityAccountPreferencesWire,
|
|
40
|
+
});
|
package/src/Sessions.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { SqlClient } from "effect/sql";
|
|
3
|
+
import { defineModule } from "@shivaedev/contract/defineModule.ts";
|
|
4
|
+
import { command, query } from "@shivaedev/contract/operation.ts";
|
|
5
|
+
import { identitySessionsWire } from "#generated/Sessions.ts";
|
|
6
|
+
import { listSessions, revokeSession } from "#server/better-auth/sessionAdministration.ts";
|
|
7
|
+
import { SessionsPermission } from "#sessionPermissions.ts";
|
|
8
|
+
import { SessionListInput, sessionKeys } from "#signedInSessions.ts";
|
|
9
|
+
|
|
10
|
+
const ListSessions = query("list", {
|
|
11
|
+
payload: SessionListInput.fields,
|
|
12
|
+
reads: () => [sessionKeys.list],
|
|
13
|
+
*run(input) {
|
|
14
|
+
return yield* listSessions(input);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const RevokeSession = command("revoke", {
|
|
19
|
+
invalidates: () => [sessionKeys.list],
|
|
20
|
+
payload: { id: Schema.String },
|
|
21
|
+
*run({ id }) {
|
|
22
|
+
yield* revokeSession(id);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export const Sessions = defineModule({
|
|
27
|
+
middleware: SessionsPermission,
|
|
28
|
+
name: "identity.sessions",
|
|
29
|
+
operations: [ListSessions, RevokeSession],
|
|
30
|
+
requires: [SqlClient.SqlClient],
|
|
31
|
+
wire: identitySessionsWire,
|
|
32
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DateTime, Option, Schema } from "effect";
|
|
2
|
+
import { collection } from "@shivaedev/changes/keys.ts";
|
|
3
|
+
|
|
4
|
+
export const AccountTimezone = Schema.String.check(
|
|
5
|
+
Schema.makeFilter((value) => Option.isSome(DateTime.zoneMakeNamed(value)), { expected: "an IANA timezone" }),
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
export const AccountPreferenceValues = Schema.Struct({
|
|
9
|
+
locale: Schema.NonEmptyString,
|
|
10
|
+
timezone: AccountTimezone,
|
|
11
|
+
units: Schema.Literals(["metric", "imperial"]),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const accountPreferenceKeys = collection("identity.accountPreferences", Schema.String);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Generated by @shivaedev/build from src/AccountPreferences.ts. Do not edit or commit this file; run `pnpm generate` to write it again.
|
|
2
|
+
import type { AccountPreferences as AccountPreferencesModule } from "#AccountPreferences.ts";
|
|
3
|
+
import { AccountPreferenceValues, accountPreferenceKeys } from "#accountPreferenceValues.ts";
|
|
4
|
+
import { selfSubject } from "#subject.ts";
|
|
5
|
+
import { clientContract } from "@shivaedev/contract/clientContract.ts";
|
|
6
|
+
import type { ClientMatchesModule } from "@shivaedev/contract/clientMatchesModule.ts";
|
|
7
|
+
import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
|
|
8
|
+
import { Schema } from "effect";
|
|
9
|
+
|
|
10
|
+
export const identityAccountPreferencesWire = {
|
|
11
|
+
capture: { rejections: { AuthUnavailable }, success: Schema.Void },
|
|
12
|
+
get: { rejections: { AuthUnavailable }, success: Schema.Struct({ locale: Schema.String, timezone: Schema.String, units: Schema.Literals(["imperial", "metric"]) }) },
|
|
13
|
+
set: { rejections: { AuthUnavailable }, success: Schema.Void },
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
export const AccountPreferences = clientContract({
|
|
17
|
+
commands: {
|
|
18
|
+
capture: { invalidates: () => [accountPreferenceKeys.list] },
|
|
19
|
+
set: { invalidates: () => [accountPreferenceKeys.list] },
|
|
20
|
+
},
|
|
21
|
+
name: "identity.accountPreferences",
|
|
22
|
+
payloads: {
|
|
23
|
+
capture: AccountPreferenceValues.fields,
|
|
24
|
+
set: AccountPreferenceValues.fields,
|
|
25
|
+
},
|
|
26
|
+
queries: {
|
|
27
|
+
get: { reads: () => [accountPreferenceKeys.list] },
|
|
28
|
+
},
|
|
29
|
+
subject: selfSubject,
|
|
30
|
+
wire: identityAccountPreferencesWire,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
export const identityAccountPreferencesMatchModule: ClientMatchesModule<typeof AccountPreferences, typeof AccountPreferencesModule> = true;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This folder is written by `pnpm generate`.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Generated by @shivaedev/build from src/Sessions.ts. Do not edit or commit this file; run `pnpm generate` to write it again.
|
|
2
|
+
import type { Sessions as SessionsModule } from "#Sessions.ts";
|
|
3
|
+
import { SessionsPermission } from "#sessionPermissions.ts";
|
|
4
|
+
import { SessionListInput, sessionKeys } from "#signedInSessions.ts";
|
|
5
|
+
import { clientContract } from "@shivaedev/contract/clientContract.ts";
|
|
6
|
+
import type { ClientMatchesModule } from "@shivaedev/contract/clientMatchesModule.ts";
|
|
7
|
+
import { AuthUnavailable, Forbidden, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
8
|
+
import { Schema } from "effect";
|
|
9
|
+
|
|
10
|
+
export const identitySessionsWire = {
|
|
11
|
+
list: { rejections: { AuthUnavailable, Forbidden }, success: Schema.Struct({ next: Schema.Option(Schema.Struct({ id: Schema.String, lastActivityAt: Schema.DateTimeUtc })), sessions: Schema.Array(Schema.Struct({ expiresAt: Schema.DateTimeUtc, id: Schema.String, lastActivityAt: Schema.DateTimeUtc, startedAt: Schema.DateTimeUtc, user: Schema.Struct({ email: Schema.String, id: Schema.String, name: Schema.String }) })) }) },
|
|
12
|
+
revoke: { rejections: { AuthUnavailable, Forbidden, NotFound }, success: Schema.Void },
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
export const Sessions = clientContract({
|
|
16
|
+
commands: {
|
|
17
|
+
revoke: { invalidates: () => [sessionKeys.list] },
|
|
18
|
+
},
|
|
19
|
+
middleware: SessionsPermission,
|
|
20
|
+
name: "identity.sessions",
|
|
21
|
+
payloads: {
|
|
22
|
+
list: SessionListInput.fields,
|
|
23
|
+
revoke: { id: Schema.String },
|
|
24
|
+
},
|
|
25
|
+
queries: {
|
|
26
|
+
list: { reads: () => [sessionKeys.list] },
|
|
27
|
+
},
|
|
28
|
+
wire: identitySessionsWire,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const identitySessionsMatchModule: ClientMatchesModule<typeof Sessions, typeof SessionsModule> = true;
|
|
@@ -2,7 +2,7 @@ import { Schema } from "effect";
|
|
|
2
2
|
import { Model } from "effect/schema";
|
|
3
3
|
import { defineRepository } from "@shivaedev/sql/defineRepository.ts";
|
|
4
4
|
import { makeRepository } from "@shivaedev/sql/repository.ts";
|
|
5
|
-
import { AccountPreferenceValues } from "#
|
|
5
|
+
import { AccountPreferenceValues } from "#accountPreferenceValues.ts";
|
|
6
6
|
|
|
7
7
|
class StoredPreferences extends Model.Class<StoredPreferences>("AccountPreferences")({
|
|
8
8
|
id: Schema.String,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import type { AccountPreferenceValues } from "#
|
|
2
|
+
import type { AccountPreferenceValues } from "#accountPreferenceValues.ts";
|
|
3
3
|
import { AccountPreferenceRows } from "#server/account-preferences/Rows.ts";
|
|
4
4
|
import { providerFailure } from "#server/providerFailure.ts";
|
|
5
5
|
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
+
import type { AccountPreferenceValues } from "#accountPreferenceValues.ts";
|
|
2
3
|
import { AccountPreferenceRows } from "#server/account-preferences/Rows.ts";
|
|
3
4
|
import { providerFailure } from "#server/providerFailure.ts";
|
|
4
5
|
|
|
6
|
+
const DEFAULTS: typeof AccountPreferenceValues.Type = { locale: "en", timezone: "UTC", units: "metric" };
|
|
7
|
+
|
|
5
8
|
export const get = Effect.fn("AccountPreferencesStore.get")(function* (id: string) {
|
|
6
9
|
const repository = yield* AccountPreferenceRows;
|
|
7
10
|
return yield* repository.findById(id).pipe(
|
|
8
|
-
Effect.map(({ locale, timezone, units }) => ({ locale, timezone, units })),
|
|
9
|
-
Effect.catchTag("NoSuchElementError", () => Effect.succeed(
|
|
11
|
+
Effect.map(({ locale, timezone, units }): typeof AccountPreferenceValues.Type => ({ locale, timezone, units })),
|
|
12
|
+
Effect.catchTag("NoSuchElementError", () => Effect.succeed(DEFAULTS)),
|
|
10
13
|
Effect.catch(providerFailure),
|
|
11
14
|
);
|
|
12
15
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
|
-
import type { AccountPreferenceValues } from "#
|
|
2
|
+
import type { AccountPreferenceValues } from "#accountPreferenceValues.ts";
|
|
3
3
|
import { AccountPreferenceRows } from "#server/account-preferences/Rows.ts";
|
|
4
4
|
import { providerFailure } from "#server/providerFailure.ts";
|
|
5
5
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BetterAuthOptions, BetterAuthPlugin } from "better-auth";
|
|
2
2
|
import { createAuthMiddleware } from "better-auth/api";
|
|
3
3
|
import { Effect, Option, Schema } from "effect";
|
|
4
|
-
import { AccountPreferenceValues } from "#
|
|
4
|
+
import { AccountPreferenceValues } from "#accountPreferenceValues.ts";
|
|
5
5
|
import { AccountPreferencesStore } from "#server/account-preferences/service.ts";
|
|
6
6
|
|
|
7
7
|
export const accountPreferenceOptions = Effect.fnUntraced(function* <TOptions extends BetterAuthOptions>(options: TOptions) {
|
|
@@ -5,7 +5,7 @@ import { AuthUnavailable, NotFound } from "@shivaedev/errors/taxonomy.ts";
|
|
|
5
5
|
import { keysetPage } from "@shivaedev/sql/keysetPage.ts";
|
|
6
6
|
import { SessionUser } from "#identity.ts";
|
|
7
7
|
import { ManageSessions } from "#sessionPermissions.ts";
|
|
8
|
-
import { type SessionListInput, SignedInSession } from "#
|
|
8
|
+
import { type SessionList, type SessionListInput, SignedInSession } from "#signedInSessions.ts";
|
|
9
9
|
|
|
10
10
|
function unavailable() {
|
|
11
11
|
return new AuthUnavailable({ message: "Could not access signed-in sessions" });
|
|
@@ -32,7 +32,8 @@ export const listSessions = Effect.fn("Identity.listSessions")(function* (input:
|
|
|
32
32
|
})(undefined),
|
|
33
33
|
tieBreaker: { column: sql`s.id`, direction: "desc", value: (cursor) => cursor.id },
|
|
34
34
|
}).pipe(Effect.mapError(unavailable));
|
|
35
|
-
|
|
35
|
+
const list: SessionList = { next: page.next, sessions: page.rows };
|
|
36
|
+
return list;
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
export const revokeSession = Effect.fn("Identity.revokeSession")(function* (id: string) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type Option, Schema } from "effect";
|
|
2
|
+
import { collection } from "@shivaedev/changes/keys.ts";
|
|
3
|
+
|
|
4
|
+
export const sessionKeys = collection("identity.sessions", Schema.String);
|
|
5
|
+
|
|
6
|
+
export const SignedInSession = Schema.Struct({
|
|
7
|
+
expiresAt: Schema.DateTimeUtcFromDate,
|
|
8
|
+
id: Schema.String,
|
|
9
|
+
lastActivityAt: Schema.DateTimeUtcFromDate,
|
|
10
|
+
startedAt: Schema.DateTimeUtcFromDate,
|
|
11
|
+
user: Schema.Struct({ email: Schema.String, id: Schema.String, name: Schema.String }),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export const SessionCursor = Schema.Struct({ id: Schema.String, lastActivityAt: Schema.DateTimeUtcFromString });
|
|
15
|
+
export const SessionListInput = Schema.Struct({
|
|
16
|
+
cursor: Schema.optionalKey(SessionCursor),
|
|
17
|
+
limit: Schema.Number.check(Schema.isInt(), Schema.isBetween({ maximum: 100, minimum: 1 })),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export interface SessionList {
|
|
21
|
+
readonly next: Option.Option<typeof SessionCursor.Type>;
|
|
22
|
+
readonly sessions: readonly (typeof SignedInSession.Type)[];
|
|
23
|
+
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
2
|
-
import { AuthUnavailable } from "@shivaedev/errors/taxonomy.ts";
|
|
3
|
-
export declare const AccountTimezone: Schema.String;
|
|
4
|
-
export declare const AccountPreferenceValues: Schema.Struct<{
|
|
5
|
-
readonly locale: Schema.NonEmptyString;
|
|
6
|
-
readonly timezone: Schema.String;
|
|
7
|
-
readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
|
|
8
|
-
}>;
|
|
9
|
-
export declare const accountPreferenceKeys: import("@shivaedev/changes/keys.ts").Collection<"identity.accountPreferences", string, Record<never, never>>;
|
|
10
|
-
export declare const AccountPreferences: import("@shivaedev/contract/contract.ts").Contract<"identity.accountPreferences", readonly [NoInfer<import("@shivaedev/contract/operation.ts").Query<"get", Schema.Void, Schema.Struct<{
|
|
11
|
-
readonly locale: Schema.NonEmptyString;
|
|
12
|
-
readonly timezone: Schema.String;
|
|
13
|
-
readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
|
|
14
|
-
}>, {
|
|
15
|
-
readonly AuthUnavailable: typeof AuthUnavailable;
|
|
16
|
-
}, never>>], readonly [NoInfer<import("@shivaedev/contract/operation.ts").Command<"capture", Schema.Struct<{
|
|
17
|
-
readonly locale: Schema.NonEmptyString;
|
|
18
|
-
readonly timezone: Schema.String;
|
|
19
|
-
readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
|
|
20
|
-
}>, Schema.Void, {
|
|
21
|
-
readonly AuthUnavailable: typeof AuthUnavailable;
|
|
22
|
-
}>>, NoInfer<import("@shivaedev/contract/operation.ts").Command<"set", Schema.Struct<{
|
|
23
|
-
readonly locale: Schema.NonEmptyString;
|
|
24
|
-
readonly timezone: Schema.String;
|
|
25
|
-
readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
|
|
26
|
-
}>, Schema.Void, {
|
|
27
|
-
readonly AuthUnavailable: typeof AuthUnavailable;
|
|
28
|
-
}>>], import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.$changes", Schema.Struct<{
|
|
29
|
-
queries: Schema.$Array<Schema.Union<readonly Schema.Struct<{
|
|
30
|
-
query: Schema.Literal<"get">;
|
|
31
|
-
payload: Schema.Void;
|
|
32
|
-
}>[]>>;
|
|
33
|
-
}>, import("effect/rpc/RpcSchema").Stream<Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, ...(Schema.Struct<{
|
|
34
|
-
readonly _tag: Schema.Literal<"Unchanged">;
|
|
35
|
-
readonly queryIndex: Schema.Number;
|
|
36
|
-
}> | Schema.Struct<{
|
|
37
|
-
_tag: Schema.Literal<"Result">;
|
|
38
|
-
query: Schema.Literal<"get">;
|
|
39
|
-
queryIndex: Schema.Number;
|
|
40
|
-
value: Schema.Struct<{
|
|
41
|
-
readonly locale: Schema.NonEmptyString;
|
|
42
|
-
readonly timezone: Schema.String;
|
|
43
|
-
readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
|
|
44
|
-
}>;
|
|
45
|
-
}>)[]]>, Schema.Union<readonly [typeof import("@shivaedev/contract/readPolicyErrors.ts").MissingReadPolicy, typeof import("@shivaedev/contract/readPolicyErrors.ts").QueryReadDenied, typeof import("@shivaedev/contract/WebSocketRequired.ts").WebSocketRequired, ...Schema.Union<readonly (typeof AuthUnavailable)[]>[]]>>, Schema.Never, (import("effect/Context").Reference<<A, E, R>(effect: Effect.Effect<A, E, R>, request: {
|
|
46
|
-
readonly rpc: import("effect/rpc/Rpc").Any;
|
|
47
|
-
readonly payload: unknown;
|
|
48
|
-
}) => 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>> & {
|
|
49
|
-
"~effect/rpc/RpcMiddleware": "~effect/rpc/RpcMiddleware";
|
|
50
|
-
"~ClientError": never;
|
|
51
|
-
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]>;
|
|
52
|
-
requiredForClient: false;
|
|
53
|
-
}) | (import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/subjectMiddleware.ts").SubjectMiddleware<{
|
|
54
|
-
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]>;
|
|
55
|
-
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
56
|
-
}>, `@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> & {
|
|
57
|
-
"@shivaedev/contract/SubjectDeclaration": {
|
|
58
|
-
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]>;
|
|
59
|
-
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
60
|
-
};
|
|
61
|
-
}), never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.capture", Schema.Struct<{
|
|
62
|
-
readonly locale: Schema.NonEmptyString;
|
|
63
|
-
readonly timezone: Schema.String;
|
|
64
|
-
readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
|
|
65
|
-
}>, Schema.Void, Schema.Union<readonly (typeof AuthUnavailable)[]>, import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/subjectMiddleware.ts").SubjectMiddleware<{
|
|
66
|
-
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]>;
|
|
67
|
-
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
68
|
-
}>, `@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> & {
|
|
69
|
-
"@shivaedev/contract/SubjectDeclaration": {
|
|
70
|
-
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]>;
|
|
71
|
-
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
72
|
-
};
|
|
73
|
-
}, never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.set", Schema.Struct<{
|
|
74
|
-
readonly locale: Schema.NonEmptyString;
|
|
75
|
-
readonly timezone: Schema.String;
|
|
76
|
-
readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
|
|
77
|
-
}>, Schema.Void, Schema.Union<readonly (typeof AuthUnavailable)[]>, import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/subjectMiddleware.ts").SubjectMiddleware<{
|
|
78
|
-
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]>;
|
|
79
|
-
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
80
|
-
}>, `@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> & {
|
|
81
|
-
"@shivaedev/contract/SubjectDeclaration": {
|
|
82
|
-
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]>;
|
|
83
|
-
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
84
|
-
};
|
|
85
|
-
}, never> | import("effect/rpc/Rpc").Rpc<"identity.accountPreferences.get", Schema.Void, Schema.Struct<{
|
|
86
|
-
readonly locale: Schema.NonEmptyString;
|
|
87
|
-
readonly timezone: Schema.String;
|
|
88
|
-
readonly units: Schema.Literals<readonly ["metric", "imperial"]>;
|
|
89
|
-
}>, 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: {
|
|
90
|
-
readonly rpc: import("effect/rpc/Rpc").Any;
|
|
91
|
-
readonly payload: unknown;
|
|
92
|
-
}) => 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>> & {
|
|
93
|
-
"~effect/rpc/RpcMiddleware": "~effect/rpc/RpcMiddleware";
|
|
94
|
-
"~ClientError": never;
|
|
95
|
-
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]>;
|
|
96
|
-
requiredForClient: false;
|
|
97
|
-
}) | (import("effect/rpc/RpcMiddleware").ServiceClass<import("@shivaedev/contract/subjectMiddleware.ts").SubjectMiddleware<{
|
|
98
|
-
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]>;
|
|
99
|
-
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
100
|
-
}>, `@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> & {
|
|
101
|
-
"@shivaedev/contract/SubjectDeclaration": {
|
|
102
|
-
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]>;
|
|
103
|
-
middleware: Effect.Effect<import("#subject.ts").SubjectMiddleware<never, never>, never, import("#subject.ts").SubjectResolver>;
|
|
104
|
-
};
|
|
105
|
-
}), never>, readonly [], undefined>;
|
|
106
|
-
//# sourceMappingURL=accountPreferences.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"accountPreferences.d.ts","sourceRoot":"","sources":["../src/accountPreferences.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAI1D,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGhE,eAAO,MAAM,eAAe,eAE3B,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;;EAIlC,CAAC;AAEH,eAAO,MAAM,qBAAqB,8GAA2D,CAAC;AAE9F,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mCAsB7B,CAAC"}
|