@warlock.js/auth 4.0.158 โ†’ 4.0.162

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.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Register the auth:cleanup CLI command
3
+ *
4
+ * @example
5
+ * ```bash
6
+ * warlock auth:cleanup
7
+ * ```
8
+ */
9
+ export declare function registerAuthCleanupCommand(): any;
10
+ //# sourceMappingURL=auth-cleanup-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-cleanup-command.d.ts","sourceRoot":"","sources":["../../src/commands/auth-cleanup-command.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,QAqBzC"}
@@ -0,0 +1,29 @@
1
+ import {colors}from'@mongez/copper';import {command}from'@warlock.js/core';import {authService}from'../services/auth.service.js';/**
2
+ * Register the auth:cleanup CLI command
3
+ *
4
+ * @example
5
+ * ```bash
6
+ * warlock auth:cleanup
7
+ * ```
8
+ */
9
+ function registerAuthCleanupCommand() {
10
+ return command({
11
+ name: "auth.cleanup",
12
+ description: "Remove expired refresh tokens from the database",
13
+ preload: {
14
+ env: true,
15
+ config: ["auth", "database"],
16
+ connectors: ["database"],
17
+ },
18
+ action: async () => {
19
+ console.log(colors.cyan("๐Ÿงน Cleaning up expired tokens..."));
20
+ const count = await authService.cleanupExpiredTokens();
21
+ if (count === 0) {
22
+ console.log(colors.green("โœ… No expired tokens found."));
23
+ }
24
+ else {
25
+ console.log(colors.green(`โœ… Removed ${count} expired token(s).`));
26
+ }
27
+ },
28
+ });
29
+ }export{registerAuthCleanupCommand};//# sourceMappingURL=auth-cleanup-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-cleanup-command.js","sources":["../../src/commands/auth-cleanup-command.ts"],"sourcesContent":[null],"names":[],"mappings":"iIAIA;;;;;;;AAOG;SACa,0BAA0B,GAAA;AACxC,IAAA,OAAO,OAAO,CAAC;AACb,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,WAAW,EAAE,iDAAiD;AAC9D,QAAA,OAAO,EAAE;AACP,YAAA,GAAG,EAAE,IAAI;AACT,YAAA,MAAM,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC;YAC5B,UAAU,EAAE,CAAC,UAAU,CAAC;AACzB,SAAA;QACD,MAAM,EAAE,YAAW;YACjB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC,CAAC;AAE7D,YAAA,MAAM,KAAK,GAAG,MAAM,WAAW,CAAC,oBAAoB,EAAE,CAAC;YAEvD,IAAI,KAAK,KAAK,CAAC,EAAE;gBACf,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC,CAAC;AACzD,aAAA;AAAM,iBAAA;AACL,gBAAA,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA,UAAA,EAAa,KAAK,CAAA,kBAAA,CAAoB,CAAC,CAAC,CAAC;AACnE,aAAA;SACF;AACF,KAAA,CAAC,CAAC;AACL"}
@@ -0,0 +1,2 @@
1
+ export declare function registerJWTSecretGeneratorCommand(): any;
2
+ //# sourceMappingURL=jwt-secret-generator-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-secret-generator-command.d.ts","sourceRoot":"","sources":["../../src/commands/jwt-secret-generator-command.ts"],"names":[],"mappings":"AAGA,wBAAgB,iCAAiC,QAMhD"}
@@ -0,0 +1,7 @@
1
+ import {command}from'@warlock.js/core';import {generateJWTSecret}from'../services/generate-jwt-secret.js';function registerJWTSecretGeneratorCommand() {
2
+ return command({
3
+ name: "jwt.generate",
4
+ description: "Generate JWT Secret key in .env file",
5
+ action: generateJWTSecret,
6
+ });
7
+ }export{registerJWTSecretGeneratorCommand};//# sourceMappingURL=jwt-secret-generator-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt-secret-generator-command.js","sources":["../../src/commands/jwt-secret-generator-command.ts"],"sourcesContent":[null],"names":[],"mappings":"mHAGgB,iCAAiC,GAAA;AAC/C,IAAA,OAAO,OAAO,CAAC;AACb,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,WAAW,EAAE,sCAAsC;AACnD,QAAA,MAAM,EAAE,iBAAiB;AAC1B,KAAA,CAAC,CAAC;AACL"}
@@ -0,0 +1,23 @@
1
+ export interface Authenticable {
2
+ /**
3
+ * Generate access token
4
+ */
5
+ generateAccessToken(): Promise<string>;
6
+ /**
7
+ * Generate refresh token
8
+ */
9
+ generateRefreshToken(): Promise<string>;
10
+ /**
11
+ * Change password
12
+ */
13
+ changePassword(password: string): Promise<void>;
14
+ /**
15
+ * Verify Password
16
+ */
17
+ verifyPassword(password: string): Promise<boolean>;
18
+ /**
19
+ * Get user type
20
+ */
21
+ getUserType(): string;
22
+ }
23
+ //# sourceMappingURL=auth-contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-contract.d.ts","sourceRoot":"","sources":["../../src/contracts/auth-contract.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvC;;OAEG;IACH,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAExC;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEhD;;OAEG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEnD;;OAEG;IACH,WAAW,IAAI,MAAM,CAAC;CACvB"}
@@ -0,0 +1,3 @@
1
+ export * from "./auth-contract";
2
+ export * from "./types";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
@@ -0,0 +1,167 @@
1
+ import { ChildModel } from "@warlock.js/cascade";
2
+ import { type Algorithm } from "fast-jwt";
3
+ import type { Auth } from "../models/auth.model";
4
+ import type { Duration, ExpiresIn } from "../utils/duration";
5
+ /**
6
+ * Symbol to indicate no expiration for tokens
7
+ * Use this when you explicitly want tokens to never expire
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * // src/config/auth.ts
12
+ * import { NO_EXPIRATION, type AuthConfigurations } from "@warlock.js/auth";
13
+ *
14
+ * const authConfigurations: AuthConfigurations = {
15
+ * jwt: {
16
+ * secret: env("JWT_SECRET"),
17
+ * expiresIn: NO_EXPIRATION, // Token never expires
18
+ * },
19
+ * };
20
+ *
21
+ * export default authConfigurations;
22
+ * ```
23
+ */
24
+ export declare const NO_EXPIRATION: unique symbol;
25
+ /**
26
+ * Behavior when logout is called without a refresh token
27
+ * - "revoke-all": Revoke all refresh tokens for the user (secure default)
28
+ * - "error": Return an error requiring the refresh token
29
+ */
30
+ export type LogoutWithoutTokenBehavior = "revoke-all" | "error";
31
+ export type AuthConfigurations = {
32
+ /**
33
+ * Define all user types
34
+ * This is important to differentiate between user types when validating and generating tokens
35
+ */
36
+ userType: {
37
+ [userType: string]: ChildModel<Auth>;
38
+ };
39
+ /**
40
+ * JWT configurations
41
+ */
42
+ jwt: {
43
+ /**
44
+ * JWT secret key for signing access tokens
45
+ */
46
+ secret: string;
47
+ /**
48
+ * JWT algorithm
49
+ * @default "HS256"
50
+ */
51
+ algorithm?: Algorithm;
52
+ /**
53
+ * Access token expiration time
54
+ * Supports Duration object, string format, or NO_EXPIRATION
55
+ * @example { hours: 1 }, { days: 7, hours: 12 }, "1h", "1d 2h", NO_EXPIRATION
56
+ * @default { hours: 1 }
57
+ */
58
+ expiresIn?: ExpiresIn;
59
+ /**
60
+ * Refresh token configurations
61
+ */
62
+ refresh?: {
63
+ /**
64
+ * Separate secret for refresh tokens (recommended for security)
65
+ * If not provided, falls back to main JWT secret
66
+ */
67
+ secret?: string;
68
+ /**
69
+ * Enable refresh token
70
+ * @default true
71
+ */
72
+ enabled?: boolean;
73
+ /**
74
+ * Refresh token expiration time
75
+ * Supports Duration object or string format
76
+ * @example { days: 7 }, { weeks: 1 }, "7d", "1w"
77
+ * @default { days: 7 }
78
+ */
79
+ expiresIn?: Duration | string | number;
80
+ /**
81
+ * Enable token rotation (issue new refresh token on each use)
82
+ * Old refresh token is invalidated after use
83
+ * @default true
84
+ */
85
+ rotation?: boolean;
86
+ /**
87
+ * Maximum number of active refresh tokens per user
88
+ * When exceeded, oldest tokens are revoked
89
+ * @default 5
90
+ */
91
+ maxPerUser?: number;
92
+ /**
93
+ * Behavior when logout is called without a refresh token
94
+ * - "revoke-all": Revoke all tokens for security (default)
95
+ * - "error": Require refresh token, return error if missing
96
+ * @default "revoke-all"
97
+ */
98
+ logoutWithoutToken?: LogoutWithoutTokenBehavior;
99
+ };
100
+ };
101
+ /**
102
+ * Password configurations
103
+ */
104
+ password?: {
105
+ /**
106
+ * Password salt
107
+ * The higher the salt, the more secure the password is
108
+ * But, it will take more time to generate the password
109
+ * @default 12
110
+ */
111
+ salt?: number;
112
+ };
113
+ };
114
+ export type AccessTokenOutput = {
115
+ /**
116
+ * JWT Token
117
+ */
118
+ token: string;
119
+ /**
120
+ * Exprie time in ISO format UTC time
121
+ */
122
+ expiresAt: string;
123
+ };
124
+ /**
125
+ * Token pair returned after login or token refresh
126
+ */
127
+ export type TokenPair = {
128
+ /**
129
+ * JWT access token (short-lived)
130
+ */
131
+ accessToken: AccessTokenOutput;
132
+ /**
133
+ * JWT refresh token (long-lived)
134
+ */
135
+ refreshToken?: AccessTokenOutput;
136
+ };
137
+ /**
138
+ * Device information for session tracking
139
+ */
140
+ export type DeviceInfo = {
141
+ /**
142
+ * User agent string from request
143
+ */
144
+ userAgent?: string;
145
+ /**
146
+ * Client IP address
147
+ */
148
+ ip?: string;
149
+ /**
150
+ * Optional device identifier
151
+ */
152
+ deviceId?: string;
153
+ /**
154
+ * Token family ID (for rotation tracking)
155
+ * @internal
156
+ */
157
+ familyId?: string;
158
+ /**
159
+ * Access token payload
160
+ */
161
+ payload?: Record<string, any>;
162
+ };
163
+ export type LoginResult<UserType extends Auth> = {
164
+ user: UserType;
165
+ tokens: TokenPair;
166
+ };
167
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/contracts/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,eAA0B,CAAC;AAErD;;;;GAIG;AACH,MAAM,MAAM,0BAA0B,GAAG,YAAY,GAAG,OAAO,CAAC;AAEhE,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,QAAQ,EAAE;QACR,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;KACtC,CAAC;IACF;;OAEG;IACH,GAAG,EAAE;QACH;;WAEG;QACH,MAAM,EAAE,MAAM,CAAC;QACf;;;WAGG;QACH,SAAS,CAAC,EAAE,SAAS,CAAC;QACtB;;;;;WAKG;QACH,SAAS,CAAC,EAAE,SAAS,CAAC;QACtB;;WAEG;QACH,OAAO,CAAC,EAAE;YACR;;;eAGG;YACH,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB;;;eAGG;YACH,OAAO,CAAC,EAAE,OAAO,CAAC;YAClB;;;;;eAKG;YACH,SAAS,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;YACvC;;;;eAIG;YACH,QAAQ,CAAC,EAAE,OAAO,CAAC;YACnB;;;;eAIG;YACH,UAAU,CAAC,EAAE,MAAM,CAAC;YACpB;;;;;eAKG;YACH,kBAAkB,CAAC,EAAE,0BAA0B,CAAC;SACjD,CAAC;KACH,CAAC;IACF;;OAEG;IACH,QAAQ,CAAC,EAAE;QACT;;;;;WAKG;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB;;OAEG;IACH,WAAW,EAAE,iBAAiB,CAAC;IAC/B;;OAEG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;CAClC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,IAAI,IAAI;IAC/C,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Symbol to indicate no expiration for tokens
3
+ * Use this when you explicitly want tokens to never expire
4
+ *
5
+ * @example
6
+ * ```typescript
7
+ * // src/config/auth.ts
8
+ * import { NO_EXPIRATION, type AuthConfigurations } from "@warlock.js/auth";
9
+ *
10
+ * const authConfigurations: AuthConfigurations = {
11
+ * jwt: {
12
+ * secret: env("JWT_SECRET"),
13
+ * expiresIn: NO_EXPIRATION, // Token never expires
14
+ * },
15
+ * };
16
+ *
17
+ * export default authConfigurations;
18
+ * ```
19
+ */
20
+ const NO_EXPIRATION = Symbol("NO_EXPIRATION");export{NO_EXPIRATION};//# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sources":["../../src/contracts/types.ts"],"sourcesContent":[null],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;AAkBG;MACU,aAAa,GAAG,MAAM,CAAC,eAAe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@warlock.js/auth",
3
- "version": "4.0.158",
3
+ "version": "4.0.162",
4
4
  "description": "Authentication system for Warlock.js applications",
5
5
  "main": "./esm/index.js",
6
6
  "dependencies": {
@@ -12,10 +12,10 @@
12
12
  "@mongez/events": "^2.1.0",
13
13
  "@mongez/fs": "^3.0.5",
14
14
  "@mongez/reinforcements": "^2.3.17",
15
- "@warlock.js/cascade": "4.0.158",
16
- "@warlock.js/core": "4.0.158",
17
- "@warlock.js/logger": "4.0.158",
18
- "@warlock.js/seal": "4.0.158"
15
+ "@warlock.js/cascade": "4.0.162",
16
+ "@warlock.js/core": "4.0.162",
17
+ "@warlock.js/logger": "4.0.162",
18
+ "@warlock.js/seal": "4.0.162"
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",