@withstudiocms/auth-kit 0.1.0-beta.2 → 0.1.0-beta.4
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/config.js +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/modules/encryption.d.ts +2 -2
- package/dist/modules/session.d.ts +5 -5
- package/dist/modules/user.d.ts +2 -2
- package/dist/utils/libravatar.d.ts +1 -1
- package/dist/utils/password.d.ts +4 -4
- package/dist/utils/session.d.ts +2 -2
- package/dist/utils/user.d.ts +2 -2
- package/package.json +2 -2
package/dist/config.js
CHANGED
|
@@ -22,7 +22,7 @@ function makePasswordModConfig({
|
|
|
22
22
|
throw new Error(`CMS_ENCRYPTION_KEY must decode to 16 bytes, got ${raw.byteLength}`);
|
|
23
23
|
}
|
|
24
24
|
const clamp = (v, min, max) => Number.isSafeInteger(v) ? Math.min(max, Math.max(min, v)) : min;
|
|
25
|
-
const env = (k) =>
|
|
25
|
+
const env = (k) => process?.env?.[k];
|
|
26
26
|
const parsedN = Number.parseInt(env("SCRYPT_N") ?? "", 10);
|
|
27
27
|
const parsedR = Number.parseInt(env("SCRYPT_R") ?? "", 10);
|
|
28
28
|
const parsedP = Number.parseInt(env("SCRYPT_P") ?? "", 10);
|
package/dist/index.d.ts
CHANGED
|
@@ -7,15 +7,15 @@ export { Password } from './modules/password.js';
|
|
|
7
7
|
* @param scrypt - The scrypt configuration object from `PasswordModConfigFinal`.
|
|
8
8
|
* @returns An Effect that provides an object with a `run` method for performing scrypt operations.
|
|
9
9
|
*/
|
|
10
|
-
export declare const makeScrypt: (config: PasswordModConfigFinal) => Effect.Effect
|
|
10
|
+
export declare const makeScrypt: (config: PasswordModConfigFinal) => Effect.Effect<Effect.Effect<{
|
|
11
11
|
run: (password: import("crypto").BinaryLike) => Effect.Effect<Buffer<ArrayBufferLike>, import("@withstudiocms/effect/scrypt").ScryptError, never>;
|
|
12
|
-
}, never, never>, Error, never
|
|
12
|
+
}, never, never>, Error, never>;
|
|
13
13
|
declare const AuthKit_base: Effect.Service.Class<AuthKit, "@withstudiocms/AuthKit", {
|
|
14
14
|
readonly effect: Effect.Effect<{
|
|
15
15
|
readonly Encryption: Effect.Effect<{
|
|
16
|
-
readonly encrypt: (data: Uint8Array<ArrayBufferLike>) => Effect.Effect
|
|
16
|
+
readonly encrypt: (data: Uint8Array<ArrayBufferLike>) => Effect.Effect<Uint8Array<ArrayBufferLike>, import("./errors.js").EncryptionError, never>;
|
|
17
17
|
readonly encryptToString: (data: string) => Effect.Effect<Uint8Array<ArrayBufferLike>, import("./errors.js").EncryptionError, never>;
|
|
18
|
-
readonly decrypt: (data: Uint8Array<ArrayBufferLike>) => Effect.Effect
|
|
18
|
+
readonly decrypt: (data: Uint8Array<ArrayBufferLike>) => Effect.Effect<Uint8Array<ArrayBufferLike>, import("./errors.js").DecryptionError, never>;
|
|
19
19
|
readonly decryptToString: (data: Uint8Array<ArrayBufferLike>) => Effect.Effect<string, import("./errors.js").DecryptionError, never>;
|
|
20
20
|
}, import("./errors.js").EncryptionError, never>;
|
|
21
21
|
readonly Password: Effect.Effect<{
|
|
@@ -24,18 +24,18 @@ declare const AuthKit_base: Effect.Service.Class<AuthKit, "@withstudiocms/AuthKi
|
|
|
24
24
|
readonly verifyPasswordStrength: (pass: string) => Effect.Effect<string | true, import("./errors.js").PasswordError | import("./errors.js").CheckIfUnsafeError | import("@effect/platform/HttpClientError").ResponseError, never>;
|
|
25
25
|
}, never, never>;
|
|
26
26
|
readonly Session: Effect.Effect<{
|
|
27
|
-
readonly generateSessionToken: () => Effect.Effect
|
|
27
|
+
readonly generateSessionToken: () => Effect.Effect<string, import("./errors.js").SessionError, never>;
|
|
28
28
|
readonly createSession: (token: string, userId: string) => Effect.Effect<import("./types.js").UserSession, import("./errors.js").SessionError, never>;
|
|
29
29
|
readonly validateSessionToken: (token: string) => Effect.Effect<import("./types.js").SessionValidationResult, import("./errors.js").SessionError, never>;
|
|
30
|
-
readonly invalidateSession: (sessionId: string) => Effect.Effect
|
|
31
|
-
readonly setSessionTokenCookie: (context: import("astro").APIContext<Record<string, any>, Record<string, string | undefined>> | import("astro").AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, token: string, expiresAt: Date, secure?: boolean | undefined) => Effect.Effect
|
|
32
|
-
readonly deleteSessionTokenCookie: (context: import("astro").APIContext<Record<string, any>, Record<string, string | undefined>> | import("astro").AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, secure?: boolean | undefined) => Effect.Effect
|
|
33
|
-
readonly setOAuthSessionTokenCookie: (context: import("astro").APIContext<Record<string, any>, Record<string, string | undefined>> | import("astro").AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, key: string, value: string, secure?: boolean | undefined) => Effect.Effect
|
|
30
|
+
readonly invalidateSession: (sessionId: string) => Effect.Effect<void, import("./errors.js").SessionError, never>;
|
|
31
|
+
readonly setSessionTokenCookie: (context: import("astro").APIContext<Record<string, any>, Record<string, string | undefined>> | import("astro").AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, token: string, expiresAt: Date, secure?: boolean | undefined) => Effect.Effect<void, import("./errors.js").SessionError, never>;
|
|
32
|
+
readonly deleteSessionTokenCookie: (context: import("astro").APIContext<Record<string, any>, Record<string, string | undefined>> | import("astro").AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, secure?: boolean | undefined) => Effect.Effect<void, import("./errors.js").SessionError, never>;
|
|
33
|
+
readonly setOAuthSessionTokenCookie: (context: import("astro").APIContext<Record<string, any>, Record<string, string | undefined>> | import("astro").AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, key: string, value: string, secure?: boolean | undefined) => Effect.Effect<void, import("./errors.js").SessionError, never>;
|
|
34
34
|
readonly createUserSession: (userId: string, context: import("astro").APIContext<Record<string, any>, Record<string, string | undefined>> | import("astro").AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, secure?: boolean | undefined) => Effect.Effect<void, import("./errors.js").SessionError, never>;
|
|
35
35
|
}, import("./errors.js").SessionError, never>;
|
|
36
36
|
readonly User: Effect.Effect<{
|
|
37
37
|
readonly verifyUsernameInput: (username: string) => Effect.Effect<string | true, import("./errors.js").CheckIfUnsafeError | import("./errors.js").UserError, never>;
|
|
38
|
-
readonly createUserAvatar: (email: string) => Effect.Effect
|
|
38
|
+
readonly createUserAvatar: (email: string) => Effect.Effect<string, import("./errors.js").UserError, never>;
|
|
39
39
|
readonly createLocalUser: (name: string, username: string, email: string, password: string) => Effect.Effect<{
|
|
40
40
|
name: string;
|
|
41
41
|
username: string;
|
|
@@ -79,7 +79,7 @@ declare const AuthKit_base: Effect.Service.Class<AuthKit, "@withstudiocms/AuthKi
|
|
|
79
79
|
notifications: string | null;
|
|
80
80
|
}, import("@withstudiocms/effect/scrypt").ScryptError | import("./errors.js").UserError, never>;
|
|
81
81
|
readonly getUserPasswordHash: (userId: string) => Effect.Effect<string, import("./errors.js").UserError, never>;
|
|
82
|
-
readonly getUserFromEmail: (email: string) => Effect.Effect
|
|
82
|
+
readonly getUserFromEmail: (email: string) => Effect.Effect<import("./types.js").CombinedUserData | null | undefined, import("./errors.js").UserError, never>;
|
|
83
83
|
readonly getUserData: (context: import("astro").APIContext<Record<string, any>, Record<string, string | undefined>> | import("astro").AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>) => Effect.Effect<import("./types.js").UserSessionData, import("./errors.js").SessionError | import("./errors.js").UserError, never>;
|
|
84
84
|
readonly getUserPermissionLevel: (userData: import("./types.js").UserSessionData | import("./types.js").CombinedUserData | null) => Effect.Effect<import("./types.js").UserPermissionLevel, import("./errors.js").UserError, never>;
|
|
85
85
|
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>;
|
|
@@ -15,8 +15,8 @@ import { Effect } from '@withstudiocms/effect';
|
|
|
15
15
|
* Throws errors if encryption or decryption fails, or if the input data is invalid.
|
|
16
16
|
*/
|
|
17
17
|
export declare const Encryption: (CMS_ENCRYPTION_KEY: string) => Effect.Effect<{
|
|
18
|
-
readonly encrypt: (data: Uint8Array<ArrayBufferLike>) => Effect.Effect
|
|
18
|
+
readonly encrypt: (data: Uint8Array<ArrayBufferLike>) => Effect.Effect<Uint8Array<ArrayBufferLike>, import("../errors.js").EncryptionError, never>;
|
|
19
19
|
readonly encryptToString: (data: string) => Effect.Effect<Uint8Array<ArrayBufferLike>, import("../errors.js").EncryptionError, never>;
|
|
20
|
-
readonly decrypt: (data: Uint8Array<ArrayBufferLike>) => Effect.Effect
|
|
20
|
+
readonly decrypt: (data: Uint8Array<ArrayBufferLike>) => Effect.Effect<Uint8Array<ArrayBufferLike>, import("../errors.js").DecryptionError, never>;
|
|
21
21
|
readonly decryptToString: (data: Uint8Array<ArrayBufferLike>) => Effect.Effect<string, import("../errors.js").DecryptionError, never>;
|
|
22
22
|
}, import("../errors.js").EncryptionError, never>;
|
|
@@ -23,12 +23,12 @@ import type { SessionConfig, SessionValidationResult } from '../types.js';
|
|
|
23
23
|
* @throws {SessionError} If required session tools are not provided in the configuration.
|
|
24
24
|
*/
|
|
25
25
|
export declare const Session: (config: SessionConfig) => Effect.Effect<{
|
|
26
|
-
readonly generateSessionToken: () => Effect.Effect
|
|
26
|
+
readonly generateSessionToken: () => Effect.Effect<string, SessionError, never>;
|
|
27
27
|
readonly createSession: (token: string, userId: string) => Effect.Effect<import("../types.js").UserSession, SessionError, never>;
|
|
28
28
|
readonly validateSessionToken: (token: string) => Effect.Effect<SessionValidationResult, SessionError, never>;
|
|
29
|
-
readonly invalidateSession: (sessionId: string) => Effect.Effect
|
|
30
|
-
readonly setSessionTokenCookie: (context: APIContext<Record<string, any>, Record<string, string | undefined>> | AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, token: string, expiresAt: Date, secure?: boolean | undefined) => Effect.Effect
|
|
31
|
-
readonly deleteSessionTokenCookie: (context: APIContext<Record<string, any>, Record<string, string | undefined>> | AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, secure?: boolean | undefined) => Effect.Effect
|
|
32
|
-
readonly setOAuthSessionTokenCookie: (context: APIContext<Record<string, any>, Record<string, string | undefined>> | AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, key: string, value: string, secure?: boolean | undefined) => Effect.Effect
|
|
29
|
+
readonly invalidateSession: (sessionId: string) => Effect.Effect<void, SessionError, never>;
|
|
30
|
+
readonly setSessionTokenCookie: (context: APIContext<Record<string, any>, Record<string, string | undefined>> | AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, token: string, expiresAt: Date, secure?: boolean | undefined) => Effect.Effect<void, SessionError, never>;
|
|
31
|
+
readonly deleteSessionTokenCookie: (context: APIContext<Record<string, any>, Record<string, string | undefined>> | AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, secure?: boolean | undefined) => Effect.Effect<void, SessionError, never>;
|
|
32
|
+
readonly setOAuthSessionTokenCookie: (context: APIContext<Record<string, any>, Record<string, string | undefined>> | AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, key: string, value: string, secure?: boolean | undefined) => Effect.Effect<void, SessionError, never>;
|
|
33
33
|
readonly createUserSession: (userId: string, context: APIContext<Record<string, any>, Record<string, string | undefined>> | AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>, secure?: boolean | undefined) => Effect.Effect<void, SessionError, never>;
|
|
34
34
|
}, SessionError, never>;
|
package/dist/modules/user.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ import { UserPermissionLevel } from '../types.js';
|
|
|
34
34
|
*/
|
|
35
35
|
export declare const User: ({ Scrypt, session, userTools }: UserConfig) => Effect.Effect<{
|
|
36
36
|
readonly verifyUsernameInput: (username: string) => Effect.Effect<string | true, import("../errors.js").CheckIfUnsafeError | UserError, never>;
|
|
37
|
-
readonly createUserAvatar: (email: string) => Effect.Effect
|
|
37
|
+
readonly createUserAvatar: (email: string) => Effect.Effect<string, UserError, never>;
|
|
38
38
|
readonly createLocalUser: (name: string, username: string, email: string, password: string) => Effect.Effect<{
|
|
39
39
|
name: string;
|
|
40
40
|
username: string;
|
|
@@ -78,7 +78,7 @@ export declare const User: ({ Scrypt, session, userTools }: UserConfig) => Effec
|
|
|
78
78
|
notifications: string | null;
|
|
79
79
|
}, import("@withstudiocms/effect/scrypt").ScryptError | UserError, never>;
|
|
80
80
|
readonly getUserPasswordHash: (userId: string) => Effect.Effect<string, UserError, never>;
|
|
81
|
-
readonly getUserFromEmail: (email: string) => Effect.Effect
|
|
81
|
+
readonly getUserFromEmail: (email: string) => Effect.Effect<CombinedUserData | null | undefined, UserError, never>;
|
|
82
82
|
readonly getUserData: (context: APIContext<Record<string, any>, Record<string, string | undefined>> | AstroGlobal<Record<string, any>, import("astro/runtime/server/index.js").AstroComponentFactory, Record<string, string | undefined>>) => Effect.Effect<UserSessionData, import("../errors.js").SessionError | UserError, never>;
|
|
83
83
|
readonly getUserPermissionLevel: (userData: UserSessionData | CombinedUserData | null) => Effect.Effect<UserPermissionLevel, UserError, never>;
|
|
84
84
|
readonly isUserAllowed: (userData: UserSessionData | CombinedUserData | null, requiredPerms: "owner" | "admin" | "editor" | "visitor" | "unknown") => Effect.Effect<boolean, UserError, never>;
|
|
@@ -14,7 +14,7 @@ interface UserIdentity {
|
|
|
14
14
|
hash: string | null;
|
|
15
15
|
domain: string | null;
|
|
16
16
|
}
|
|
17
|
-
type TargetComponents = [string | null, number | null];
|
|
17
|
+
export type TargetComponents = [string | null, number | null];
|
|
18
18
|
/**
|
|
19
19
|
* Return the right (target, port) pair from a list of SRV records.
|
|
20
20
|
*/
|
package/dist/utils/password.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export declare const buildSecurePassword: (args_0: {
|
|
|
33
33
|
generation: string;
|
|
34
34
|
salt: string;
|
|
35
35
|
hash: string;
|
|
36
|
-
}) => Effect.Effect
|
|
36
|
+
}) => Effect.Effect<string, never, never>;
|
|
37
37
|
/**
|
|
38
38
|
* Breaks down a secure password hash into its components.
|
|
39
39
|
*
|
|
@@ -44,15 +44,15 @@ export declare const buildSecurePassword: (args_0: {
|
|
|
44
44
|
* @param hash - The secure password hash to break down.
|
|
45
45
|
* @returns An object containing the generation, salt, and hash value.
|
|
46
46
|
*/
|
|
47
|
-
export declare const breakSecurePassword: (hash: string) => Effect.Effect
|
|
47
|
+
export declare const breakSecurePassword: (hash: string) => Effect.Effect<{
|
|
48
48
|
generation: string;
|
|
49
49
|
salt: string;
|
|
50
50
|
hash: string;
|
|
51
|
-
}, PasswordError, never
|
|
51
|
+
}, PasswordError, never>;
|
|
52
52
|
/**
|
|
53
53
|
* @private Internal function for the `verifyPasswordStrength` function
|
|
54
54
|
*/
|
|
55
|
-
export declare const verifyPasswordLength: (pass: string) => Effect.Effect
|
|
55
|
+
export declare const verifyPasswordLength: (pass: string) => Effect.Effect<"Password must be between 6 and 255 characters long." | undefined, PasswordError, never>;
|
|
56
56
|
/**
|
|
57
57
|
* @private Internal function for the `verifyPasswordStrength` function
|
|
58
58
|
*/
|
package/dist/utils/session.d.ts
CHANGED
|
@@ -15,8 +15,8 @@ export declare const defaultSessionConfig: SessionConfig;
|
|
|
15
15
|
/**
|
|
16
16
|
* Generates a session ID by hashing the provided token using SHA-256 and encoding it in hexadecimal format.
|
|
17
17
|
*/
|
|
18
|
-
export declare const makeSessionId: (token: string) => Effect.Effect
|
|
18
|
+
export declare const makeSessionId: (token: string) => Effect.Effect<string, import("../errors.js").SessionError, never>;
|
|
19
19
|
/**
|
|
20
20
|
* Generates a new expiration date for a session.
|
|
21
21
|
*/
|
|
22
|
-
export declare const makeExpirationDate: (expTime: number) => Effect.Effect
|
|
22
|
+
export declare const makeExpirationDate: (expTime: number) => Effect.Effect<Date, import("../errors.js").SessionError, never>;
|
package/dist/utils/user.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare const verifyUsernameLength: (username: string) => Effect.Effect<s
|
|
|
19
19
|
* @param username - The username string to validate.
|
|
20
20
|
* @returns An error message if the username contains invalid characters, otherwise `undefined`.
|
|
21
21
|
*/
|
|
22
|
-
export declare const verifyUsernameCharacters: (username: string) => Effect.Effect
|
|
22
|
+
export declare const verifyUsernameCharacters: (username: string) => Effect.Effect<string | undefined, import("../errors.js").UserError, never>;
|
|
23
23
|
/**
|
|
24
24
|
* Verifies if the provided username is considered unsafe (e.g., commonly used usernames like "admin", "root", etc.).
|
|
25
25
|
*
|
|
@@ -40,7 +40,7 @@ export declare const verifyUsernameSafe: (username: string) => Effect.Effect<str
|
|
|
40
40
|
*
|
|
41
41
|
* @returns {Effect<UserSessionData>} An Effect containing the default UserSessionData.
|
|
42
42
|
*/
|
|
43
|
-
export declare const getDefaultUserSession: () => Effect.Effect
|
|
43
|
+
export declare const getDefaultUserSession: () => Effect.Effect<UserSessionData, never, never>;
|
|
44
44
|
/**
|
|
45
45
|
* Determines the user's permission level based on the provided user data.
|
|
46
46
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@withstudiocms/auth-kit",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.4",
|
|
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.
|
|
62
|
+
"@withstudiocms/effect": "0.1.0-beta.5"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@types/node": "^22.0.0"
|