@withstudiocms/auth-kit 0.1.0-beta.6 → 0.1.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/dist/errors.d.ts CHANGED
@@ -155,4 +155,12 @@ export declare const useUserError: <A>(_try: () => A) => Effect.Effect<A, UserEr
155
155
  * @returns An `Effect` that resolves with the value of type `A` or fails with a `UserError`.
156
156
  */
157
157
  export declare const useUserErrorPromise: <A>(_try: () => Promise<A>) => Effect.Effect<A, UserError>;
158
+ declare const AuthKitError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
159
+ readonly _tag: "AuthKitError";
160
+ } & Readonly<A>;
161
+ export declare class AuthKitError extends AuthKitError_base<{
162
+ message: string;
163
+ cause?: unknown;
164
+ }> {
165
+ }
158
166
  export {};
package/dist/errors.js CHANGED
@@ -43,7 +43,10 @@ const useUserErrorPromise = (_try) => Effect.tryPromise({
43
43
  try: _try,
44
44
  catch: (cause) => new UserError({ cause })
45
45
  });
46
+ class AuthKitError extends Data.TaggedError("AuthKitError") {
47
+ }
46
48
  export {
49
+ AuthKitError,
47
50
  CheckIfUnsafeError,
48
51
  DecryptionError,
49
52
  EncryptionError,
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Effect } from '@withstudiocms/effect';
2
2
  import { AuthKitOptions, PasswordModConfigFinal, type RawAuthKitConfig } from './config.js';
3
+ import { AuthKitError } from './errors.js';
3
4
  export { Password } from './modules/password.js';
4
5
  /**
5
6
  * Creates a scrypt password hashing utility using the provided scrypt configuration.
@@ -9,7 +10,7 @@ export { Password } from './modules/password.js';
9
10
  */
10
11
  export declare const makeScrypt: (config: PasswordModConfigFinal) => Effect.Effect<Effect.Effect<{
11
12
  run: (password: import("crypto").BinaryLike) => Effect.Effect<Buffer<ArrayBufferLike>, import("@withstudiocms/effect/scrypt").ScryptError, never>;
12
- }, never, never>, Error, never>;
13
+ }, never, never>, AuthKitError, never>;
13
14
  declare const AuthKit_base: Effect.Service.Class<AuthKit, "@withstudiocms/AuthKit", {
14
15
  readonly effect: Effect.Effect<{
15
16
  readonly Encryption: Effect.Effect<{
@@ -48,7 +49,7 @@ declare const AuthKit_base: Effect.Service.Class<AuthKit, "@withstudiocms/AuthKi
48
49
  readonly getUserPermissionLevel: (userData: import("./types.js").UserSessionData | import("./types.js").CombinedUserData | null) => Effect.Effect<import("./types.js").UserPermissionLevel, import("./errors.js").UserError, never>;
49
50
  readonly isUserAllowed: (userData: import("./types.js").UserSessionData | import("./types.js").CombinedUserData | null, requiredPerms: "owner" | "admin" | "editor" | "visitor" | "unknown") => Effect.Effect<boolean, import("./errors.js").UserError, never>;
50
51
  }, import("./errors.js").SessionError | import("./errors.js").UserError, never>;
51
- }, Error, AuthKitOptions>;
52
+ }, AuthKitError, AuthKitOptions>;
52
53
  }>;
53
54
  /**
54
55
  * The `AuthKit` service provides a collection of authentication utilities for use within the
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Effect } from "@withstudiocms/effect";
2
2
  import { Scrypt as _Scrypt } from "@withstudiocms/effect/scrypt";
3
3
  import { AuthKitOptions, PasswordModConfigFinal } from "./config.js";
4
+ import { AuthKitError } from "./errors.js";
4
5
  import { _Encryption, _Password, _Session, _User } from "./modules/index.js";
5
6
  import { Password } from "./modules/password.js";
6
7
  const makeScrypt = Effect.fn(
@@ -9,7 +10,10 @@ const makeScrypt = Effect.fn(
9
10
  const { run } = yield* _Scrypt;
10
11
  return { run };
11
12
  }).pipe(Effect.provide(_Scrypt.makeLive(config.scrypt))),
12
- catch: (error) => new Error(`Failed to create Scrypt instance: ${error.message}`)
13
+ catch: (error) => new AuthKitError({
14
+ message: `Failed to create Scrypt instance: ${error.message}`,
15
+ cause: error
16
+ })
13
17
  })
14
18
  );
15
19
  class AuthKit extends Effect.Service()("@withstudiocms/AuthKit", {
@@ -8,21 +8,19 @@ const Session = (config) => Effect.gen(function* () {
8
8
  ...config
9
9
  };
10
10
  if (!sessionTools) {
11
- return yield* Effect.fail(
12
- new SessionError({ cause: "Session tools must be provided in the configuration" })
13
- );
11
+ return yield* new SessionError({
12
+ cause: "Session tools must be provided in the configuration"
13
+ });
14
14
  }
15
15
  if (!Number.isFinite(expTime) || expTime <= 0) {
16
- return yield* Effect.fail(
17
- new SessionError({
18
- cause: "Invalid session config: expTime must be a positive number (ms)"
19
- })
20
- );
16
+ return yield* new SessionError({
17
+ cause: "Invalid session config: expTime must be a positive number (ms)"
18
+ });
21
19
  }
22
20
  if (typeof cookieName !== "string" || cookieName.trim().length === 0) {
23
- return yield* Effect.fail(
24
- new SessionError({ cause: "Invalid session config: cookieName must be a non-empty string" })
25
- );
21
+ return yield* new SessionError({
22
+ cause: "Invalid session config: cookieName must be a non-empty string"
23
+ });
26
24
  }
27
25
  const expTimeHalf = expTime / 2;
28
26
  const defaultSecure = process.env.NODE_ENV === "production";
@@ -15,7 +15,7 @@ import { Session as _Session } from "./session.js";
15
15
  const User = ({ Scrypt, session, userTools }) => Effect.gen(function* () {
16
16
  const [Password, Session] = yield* Effect.all([_Password(Scrypt), _Session(session)]);
17
17
  if (!userTools) {
18
- return yield* Effect.fail(new UserError({ cause: "User tools are not available" }));
18
+ return yield* new UserError({ cause: "User tools are not available" });
19
19
  }
20
20
  const notifier = userTools.notifier;
21
21
  const verifyUsernameInput = Effect.fn(
@@ -85,7 +85,7 @@ const User = ({ Scrypt, session, userTools }) => Effect.gen(function* () {
85
85
  const newHash = yield* Password.hashPassword(password);
86
86
  const data = yield* useUserErrorPromise(() => userTools.getUserById(userId));
87
87
  if (!data) {
88
- return yield* Effect.fail(new UserError({ cause: "User not found" }));
88
+ return yield* new UserError({ cause: "User not found" });
89
89
  }
90
90
  const { avatar, email, emailVerified, name, notifications, id, username, url } = data;
91
91
  return yield* useUserErrorPromise(
@@ -108,9 +108,8 @@ const User = ({ Scrypt, session, userTools }) => Effect.gen(function* () {
108
108
  "@withstudiocms/AuthKit/modules/user.getUserPasswordHash"
109
109
  )(function* (userId) {
110
110
  const user = yield* useUserErrorPromise(() => userTools.getUserById(userId));
111
- if (!user) return yield* Effect.fail(new UserError({ cause: "User not found" }));
112
- if (!user.password)
113
- return yield* Effect.fail(new UserError({ cause: "User has no password" }));
111
+ if (!user) return yield* new UserError({ cause: "User not found" });
112
+ if (!user.password) return yield* new UserError({ cause: "User has no password" });
114
113
  return user.password;
115
114
  });
116
115
  const getUserFromEmail = Effect.fn("@withstudiocms/AuthKit/modules/user.getUserFromEmail")(
package/dist/types.d.ts CHANGED
@@ -36,27 +36,27 @@ export interface UserSession {
36
36
  */
37
37
  export interface UserData {
38
38
  readonly username: string;
39
- readonly password: string | null | undefined;
39
+ readonly password?: string | null | undefined;
40
40
  readonly name: string;
41
- readonly notifications: string | null | undefined;
41
+ readonly notifications?: string | null | undefined;
42
42
  readonly id: string;
43
43
  readonly updatedAt: Date;
44
- readonly url: string | null | undefined;
45
- readonly email: string | null | undefined;
46
- readonly avatar: string | null | undefined;
44
+ readonly url?: string | null | undefined;
45
+ readonly email?: string | null | undefined;
46
+ readonly avatar?: string | null | undefined;
47
47
  readonly createdAt: Date;
48
48
  readonly emailVerified: boolean;
49
49
  }
50
50
  export interface UserDataInsert {
51
51
  readonly username: string;
52
- readonly password: string | null | undefined;
52
+ readonly password?: string | null | undefined;
53
53
  readonly name: string;
54
- readonly notifications: string | null | undefined;
54
+ readonly notifications?: string | null | undefined;
55
55
  readonly id: string;
56
56
  readonly updatedAt: string;
57
- readonly url: string | null | undefined;
58
- readonly email: string | null | undefined;
59
- readonly avatar: string | null | undefined;
57
+ readonly url?: string | null | undefined;
58
+ readonly email?: string | null | undefined;
59
+ readonly avatar?: string | null | undefined;
60
60
  readonly createdAt: string | undefined;
61
61
  readonly emailVerified: boolean;
62
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@withstudiocms/auth-kit",
3
- "version": "0.1.0-beta.6",
3
+ "version": "0.1.0",
4
4
  "description": "Utilities for managing authentication",
5
5
  "author": {
6
6
  "name": "withstudiocms",
@@ -59,7 +59,7 @@
59
59
  "@oslojs/binary": "^1.0.0",
60
60
  "@oslojs/crypto": "^1.0.1",
61
61
  "@oslojs/encoding": "^1.1.0",
62
- "@withstudiocms/effect": "0.1.0-beta.7"
62
+ "@withstudiocms/effect": "0.1.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@types/node": "^22.0.0"
@@ -74,6 +74,8 @@
74
74
  "build": "pnpm update:lists && pnpm buildkit build 'src/**/*.{ts,astro,css,json,png}'",
75
75
  "dev": "pnpm update:lists && pnpm buildkit dev 'src/**/*.{ts,astro,css,json,png}'",
76
76
  "test": "vitest",
77
+ "effect-check": "pnpm effect-language-service diagnostics --project tsconfig.tspc.json",
78
+ "ci:effect-check": "pnpm effect-check --format github-actions",
77
79
  "typecheck": "tspc -p tsconfig.tspc.json"
78
80
  }
79
81
  }