@warlock.js/auth 4.0.31 → 4.0.41
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/cjs/index.js +725 -1
- package/cjs/index.js.map +1 -1
- package/esm/index.js +705 -1
- package/esm/index.js.map +1 -1
- package/package.json +48 -34
- package/cjs/commands/auth-cleanup-command.d.ts +0 -10
- package/cjs/commands/auth-cleanup-command.d.ts.map +0 -1
- package/cjs/commands/auth-cleanup-command.js +0 -29
- package/cjs/commands/auth-cleanup-command.js.map +0 -1
- package/cjs/commands/jwt-secret-generator-command.d.ts +0 -2
- package/cjs/commands/jwt-secret-generator-command.d.ts.map +0 -1
- package/cjs/commands/jwt-secret-generator-command.js +0 -7
- package/cjs/commands/jwt-secret-generator-command.js.map +0 -1
- package/cjs/contracts/auth-contract.d.ts +0 -23
- package/cjs/contracts/auth-contract.d.ts.map +0 -1
- package/cjs/contracts/index.d.ts +0 -3
- package/cjs/contracts/index.d.ts.map +0 -1
- package/cjs/contracts/types.d.ts +0 -134
- package/cjs/contracts/types.d.ts.map +0 -1
- package/cjs/contracts/types.js +0 -20
- package/cjs/contracts/types.js.map +0 -1
- package/cjs/index.d.ts +0 -8
- package/cjs/index.d.ts.map +0 -1
- package/cjs/middleware/auth.middleware.d.ts +0 -2
- package/cjs/middleware/auth.middleware.d.ts.map +0 -1
- package/cjs/middleware/auth.middleware.js +0 -73
- package/cjs/middleware/auth.middleware.js.map +0 -1
- package/cjs/middleware/index.d.ts +0 -2
- package/cjs/middleware/index.d.ts.map +0 -1
- package/cjs/models/access-token/access-token.d.ts +0 -12
- package/cjs/models/access-token/access-token.d.ts.map +0 -1
- package/cjs/models/access-token/access-token.js +0 -16
- package/cjs/models/access-token/access-token.js.map +0 -1
- package/cjs/models/access-token/index.d.ts +0 -3
- package/cjs/models/access-token/index.d.ts.map +0 -1
- package/cjs/models/access-token/migration.d.ts +0 -3
- package/cjs/models/access-token/migration.d.ts.map +0 -1
- package/cjs/models/access-token/migration.js +0 -10
- package/cjs/models/access-token/migration.js.map +0 -1
- package/cjs/models/auth.d.ts +0 -47
- package/cjs/models/auth.d.ts.map +0 -1
- package/cjs/models/auth.js +0 -58
- package/cjs/models/auth.js.map +0 -1
- package/cjs/models/casts/cast-password.d.ts +0 -7
- package/cjs/models/casts/cast-password.d.ts.map +0 -1
- package/cjs/models/casts/cast-password.js +0 -9
- package/cjs/models/casts/cast-password.js.map +0 -1
- package/cjs/models/casts/index.d.ts +0 -2
- package/cjs/models/casts/index.d.ts.map +0 -1
- package/cjs/models/index.d.ts +0 -5
- package/cjs/models/index.d.ts.map +0 -1
- package/cjs/models/refresh-token/index.d.ts +0 -2
- package/cjs/models/refresh-token/index.d.ts.map +0 -1
- package/cjs/models/refresh-token/migration.d.ts +0 -3
- package/cjs/models/refresh-token/migration.d.ts.map +0 -1
- package/cjs/models/refresh-token/refresh-token.d.ts +0 -32
- package/cjs/models/refresh-token/refresh-token.d.ts.map +0 -1
- package/cjs/models/refresh-token/refresh-token.js +0 -52
- package/cjs/models/refresh-token/refresh-token.js.map +0 -1
- package/cjs/services/auth-events.d.ts +0 -84
- package/cjs/services/auth-events.d.ts.map +0 -1
- package/cjs/services/auth-events.js +0 -65
- package/cjs/services/auth-events.js.map +0 -1
- package/cjs/services/auth.service.d.ts +0 -78
- package/cjs/services/auth.service.d.ts.map +0 -1
- package/cjs/services/auth.service.js +0 -265
- package/cjs/services/auth.service.js.map +0 -1
- package/cjs/services/generate-jwt-secret.d.ts +0 -2
- package/cjs/services/generate-jwt-secret.d.ts.map +0 -1
- package/cjs/services/generate-jwt-secret.js +0 -26
- package/cjs/services/generate-jwt-secret.js.map +0 -1
- package/cjs/services/index.d.ts +0 -5
- package/cjs/services/index.d.ts.map +0 -1
- package/cjs/services/jwt.d.ts +0 -23
- package/cjs/services/jwt.d.ts.map +0 -1
- package/cjs/services/jwt.js +0 -39
- package/cjs/services/jwt.js.map +0 -1
- package/cjs/utils/auth-error-codes.d.ts +0 -18
- package/cjs/utils/auth-error-codes.d.ts.map +0 -1
- package/cjs/utils/auth-error-codes.js +0 -18
- package/cjs/utils/auth-error-codes.js.map +0 -1
- package/cjs/utils/duration.d.ts +0 -45
- package/cjs/utils/duration.d.ts.map +0 -1
- package/cjs/utils/duration.js +0 -93
- package/cjs/utils/duration.js.map +0 -1
- package/cjs/utils/index.d.ts +0 -3
- package/cjs/utils/index.d.ts.map +0 -1
- package/esm/commands/auth-cleanup-command.d.ts +0 -10
- package/esm/commands/auth-cleanup-command.d.ts.map +0 -1
- package/esm/commands/auth-cleanup-command.js +0 -29
- package/esm/commands/auth-cleanup-command.js.map +0 -1
- package/esm/commands/jwt-secret-generator-command.d.ts +0 -2
- package/esm/commands/jwt-secret-generator-command.d.ts.map +0 -1
- package/esm/commands/jwt-secret-generator-command.js +0 -7
- package/esm/commands/jwt-secret-generator-command.js.map +0 -1
- package/esm/contracts/auth-contract.d.ts +0 -23
- package/esm/contracts/auth-contract.d.ts.map +0 -1
- package/esm/contracts/index.d.ts +0 -3
- package/esm/contracts/index.d.ts.map +0 -1
- package/esm/contracts/types.d.ts +0 -134
- package/esm/contracts/types.d.ts.map +0 -1
- package/esm/contracts/types.js +0 -20
- package/esm/contracts/types.js.map +0 -1
- package/esm/index.d.ts +0 -8
- package/esm/index.d.ts.map +0 -1
- package/esm/middleware/auth.middleware.d.ts +0 -2
- package/esm/middleware/auth.middleware.d.ts.map +0 -1
- package/esm/middleware/auth.middleware.js +0 -73
- package/esm/middleware/auth.middleware.js.map +0 -1
- package/esm/middleware/index.d.ts +0 -2
- package/esm/middleware/index.d.ts.map +0 -1
- package/esm/models/access-token/access-token.d.ts +0 -12
- package/esm/models/access-token/access-token.d.ts.map +0 -1
- package/esm/models/access-token/access-token.js +0 -16
- package/esm/models/access-token/access-token.js.map +0 -1
- package/esm/models/access-token/index.d.ts +0 -3
- package/esm/models/access-token/index.d.ts.map +0 -1
- package/esm/models/access-token/migration.d.ts +0 -3
- package/esm/models/access-token/migration.d.ts.map +0 -1
- package/esm/models/access-token/migration.js +0 -10
- package/esm/models/access-token/migration.js.map +0 -1
- package/esm/models/auth.d.ts +0 -47
- package/esm/models/auth.d.ts.map +0 -1
- package/esm/models/auth.js +0 -58
- package/esm/models/auth.js.map +0 -1
- package/esm/models/casts/cast-password.d.ts +0 -7
- package/esm/models/casts/cast-password.d.ts.map +0 -1
- package/esm/models/casts/cast-password.js +0 -9
- package/esm/models/casts/cast-password.js.map +0 -1
- package/esm/models/casts/index.d.ts +0 -2
- package/esm/models/casts/index.d.ts.map +0 -1
- package/esm/models/index.d.ts +0 -5
- package/esm/models/index.d.ts.map +0 -1
- package/esm/models/refresh-token/index.d.ts +0 -2
- package/esm/models/refresh-token/index.d.ts.map +0 -1
- package/esm/models/refresh-token/migration.d.ts +0 -3
- package/esm/models/refresh-token/migration.d.ts.map +0 -1
- package/esm/models/refresh-token/refresh-token.d.ts +0 -32
- package/esm/models/refresh-token/refresh-token.d.ts.map +0 -1
- package/esm/models/refresh-token/refresh-token.js +0 -52
- package/esm/models/refresh-token/refresh-token.js.map +0 -1
- package/esm/services/auth-events.d.ts +0 -84
- package/esm/services/auth-events.d.ts.map +0 -1
- package/esm/services/auth-events.js +0 -65
- package/esm/services/auth-events.js.map +0 -1
- package/esm/services/auth.service.d.ts +0 -78
- package/esm/services/auth.service.d.ts.map +0 -1
- package/esm/services/auth.service.js +0 -265
- package/esm/services/auth.service.js.map +0 -1
- package/esm/services/generate-jwt-secret.d.ts +0 -2
- package/esm/services/generate-jwt-secret.d.ts.map +0 -1
- package/esm/services/generate-jwt-secret.js +0 -26
- package/esm/services/generate-jwt-secret.js.map +0 -1
- package/esm/services/index.d.ts +0 -5
- package/esm/services/index.d.ts.map +0 -1
- package/esm/services/jwt.d.ts +0 -23
- package/esm/services/jwt.d.ts.map +0 -1
- package/esm/services/jwt.js +0 -39
- package/esm/services/jwt.js.map +0 -1
- package/esm/utils/auth-error-codes.d.ts +0 -18
- package/esm/utils/auth-error-codes.d.ts.map +0 -1
- package/esm/utils/auth-error-codes.js +0 -18
- package/esm/utils/auth-error-codes.js.map +0 -1
- package/esm/utils/duration.d.ts +0 -45
- package/esm/utils/duration.d.ts.map +0 -1
- package/esm/utils/duration.js +0 -93
- package/esm/utils/duration.js.map +0 -1
- package/esm/utils/index.d.ts +0 -3
- package/esm/utils/index.d.ts.map +0 -1
|
@@ -1,29 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,7 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,23 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/esm/contracts/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/contracts/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
|
package/esm/contracts/types.d.ts
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { type Algorithm } from "fast-jwt";
|
|
2
|
-
import type { Auth } from "../models/auth";
|
|
3
|
-
import type { Duration, ExpiresIn } from "../utils/duration";
|
|
4
|
-
/**
|
|
5
|
-
* Symbol to indicate no expiration for tokens
|
|
6
|
-
* Use this when you explicitly want tokens to never expire
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* // src/config/auth.ts
|
|
11
|
-
* import { NO_EXPIRATION, type AuthConfigurations } from "@warlock.js/auth";
|
|
12
|
-
*
|
|
13
|
-
* const authConfigurations: AuthConfigurations = {
|
|
14
|
-
* jwt: {
|
|
15
|
-
* secret: env("JWT_SECRET"),
|
|
16
|
-
* expiresIn: NO_EXPIRATION, // Token never expires
|
|
17
|
-
* },
|
|
18
|
-
* };
|
|
19
|
-
*
|
|
20
|
-
* export default authConfigurations;
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export declare const NO_EXPIRATION: unique symbol;
|
|
24
|
-
export type AuthConfigurations = {
|
|
25
|
-
/**
|
|
26
|
-
* Define all user types
|
|
27
|
-
* This is important to differentiate between user types when validating and generating tokens
|
|
28
|
-
*/
|
|
29
|
-
userType: {
|
|
30
|
-
[userType: string]: typeof Auth;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* JWT configurations
|
|
34
|
-
*/
|
|
35
|
-
jwt: {
|
|
36
|
-
/**
|
|
37
|
-
* JWT secret key for signing access tokens
|
|
38
|
-
*/
|
|
39
|
-
secret: string;
|
|
40
|
-
/**
|
|
41
|
-
* JWT algorithm
|
|
42
|
-
* @default "HS256"
|
|
43
|
-
*/
|
|
44
|
-
algorithm?: Algorithm;
|
|
45
|
-
/**
|
|
46
|
-
* Access token expiration time
|
|
47
|
-
* Supports Duration object, string format, or NO_EXPIRATION
|
|
48
|
-
* @example { hours: 1 }, { days: 7, hours: 12 }, "1h", "1d 2h", NO_EXPIRATION
|
|
49
|
-
* @default { hours: 1 }
|
|
50
|
-
*/
|
|
51
|
-
expiresIn?: ExpiresIn;
|
|
52
|
-
/**
|
|
53
|
-
* Refresh token configurations
|
|
54
|
-
*/
|
|
55
|
-
refresh?: {
|
|
56
|
-
/**
|
|
57
|
-
* Separate secret for refresh tokens (recommended for security)
|
|
58
|
-
* If not provided, falls back to main JWT secret
|
|
59
|
-
*/
|
|
60
|
-
secret?: string;
|
|
61
|
-
/**
|
|
62
|
-
* Refresh token expiration time
|
|
63
|
-
* Supports Duration object or string format
|
|
64
|
-
* @example { days: 7 }, { weeks: 1 }, "7d", "1w"
|
|
65
|
-
* @default { days: 7 }
|
|
66
|
-
*/
|
|
67
|
-
expiresIn?: Duration | string | number;
|
|
68
|
-
/**
|
|
69
|
-
* Enable token rotation (issue new refresh token on each use)
|
|
70
|
-
* Old refresh token is invalidated after use
|
|
71
|
-
* @default true
|
|
72
|
-
*/
|
|
73
|
-
rotation?: boolean;
|
|
74
|
-
/**
|
|
75
|
-
* Maximum number of active refresh tokens per user
|
|
76
|
-
* When exceeded, oldest tokens are revoked
|
|
77
|
-
* @default 5
|
|
78
|
-
*/
|
|
79
|
-
maxPerUser?: number;
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
/**
|
|
83
|
-
* Password configurations
|
|
84
|
-
*/
|
|
85
|
-
password?: {
|
|
86
|
-
/**
|
|
87
|
-
* Password salt
|
|
88
|
-
* The higher the salt, the more secure the password is
|
|
89
|
-
* But, it will take more time to generate the password
|
|
90
|
-
* @default 12
|
|
91
|
-
*/
|
|
92
|
-
salt?: number;
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
/**
|
|
96
|
-
* Token pair returned after login or token refresh
|
|
97
|
-
*/
|
|
98
|
-
export type TokenPair = {
|
|
99
|
-
/**
|
|
100
|
-
* JWT access token (short-lived)
|
|
101
|
-
*/
|
|
102
|
-
accessToken: string;
|
|
103
|
-
/**
|
|
104
|
-
* JWT refresh token (long-lived)
|
|
105
|
-
*/
|
|
106
|
-
refreshToken: string;
|
|
107
|
-
/**
|
|
108
|
-
* Access token expiration time in seconds or time string
|
|
109
|
-
*/
|
|
110
|
-
expiresIn: number | string;
|
|
111
|
-
};
|
|
112
|
-
/**
|
|
113
|
-
* Device information for session tracking
|
|
114
|
-
*/
|
|
115
|
-
export type DeviceInfo = {
|
|
116
|
-
/**
|
|
117
|
-
* User agent string from request
|
|
118
|
-
*/
|
|
119
|
-
userAgent?: string;
|
|
120
|
-
/**
|
|
121
|
-
* Client IP address
|
|
122
|
-
*/
|
|
123
|
-
ip?: string;
|
|
124
|
-
/**
|
|
125
|
-
* Optional device identifier
|
|
126
|
-
*/
|
|
127
|
-
deviceId?: string;
|
|
128
|
-
/**
|
|
129
|
-
* Token family ID (for rotation tracking)
|
|
130
|
-
* @internal
|
|
131
|
-
*/
|
|
132
|
-
familyId?: string;
|
|
133
|
-
};
|
|
134
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/contracts/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE7D;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,eAA0B,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;OAGG;IACH,QAAQ,EAAE;QACR,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,IAAI,CAAC;KACjC,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;;;;;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;SACrB,CAAC;KACH,CAAC;IACF;;OAEG;IACH,QAAQ,CAAC,EAAE;QACT;;;;;WAKG;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;CAC5B,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;CACnB,CAAC"}
|
package/esm/contracts/types.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../src/contracts/types.ts"],"sourcesContent":[null],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;AAkBG;MACU,aAAa,GAAG,MAAM,CAAC,eAAe"}
|
package/esm/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from "./commands/auth-cleanup-command";
|
|
2
|
-
export * from "./commands/jwt-secret-generator-command";
|
|
3
|
-
export * from "./contracts";
|
|
4
|
-
export * from "./middleware";
|
|
5
|
-
export * from "./models";
|
|
6
|
-
export * from "./services";
|
|
7
|
-
export * from "./utils";
|
|
8
|
-
//# sourceMappingURL=index.d.ts.map
|
package/esm/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,yCAAyC,CAAC;AACxD,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.middleware.d.ts","sourceRoot":"","sources":["../../src/middleware/auth.middleware.ts"],"names":[],"mappings":"AAMA,wBAAgB,cAAc,CAAC,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,cAuFjE"}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import {t,config}from'@warlock.js/core';import {log}from'@warlock.js/logger';import {AccessToken}from'../models/access-token/access-token.js';import'../models/access-token/migration.js';import {jwt}from'../services/jwt.js';import {AuthErrorCodes}from'../utils/auth-error-codes.js';function authMiddleware(allowedUserType) {
|
|
2
|
-
const allowedTypes = !allowedUserType
|
|
3
|
-
? []
|
|
4
|
-
: Array.isArray(allowedUserType)
|
|
5
|
-
? allowedUserType
|
|
6
|
-
: [allowedUserType];
|
|
7
|
-
const auth = async (request, response) => {
|
|
8
|
-
try {
|
|
9
|
-
const authorizationValue = request.authorizationValue;
|
|
10
|
-
if (!allowedTypes.length && !authorizationValue)
|
|
11
|
-
return;
|
|
12
|
-
if (!authorizationValue) {
|
|
13
|
-
return response.unauthorized({
|
|
14
|
-
error: t("auth.errors.missingAccessToken"),
|
|
15
|
-
errorCode: AuthErrorCodes.MissingAccessToken,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
// get current user jwt
|
|
19
|
-
const user = await jwt.verify(authorizationValue);
|
|
20
|
-
// store decoded access token object in request object
|
|
21
|
-
request.decodedAccessToken = user;
|
|
22
|
-
// use our own jwt verify to verify the token
|
|
23
|
-
const accessToken = await AccessToken.first({
|
|
24
|
-
token: authorizationValue,
|
|
25
|
-
});
|
|
26
|
-
if (!accessToken) {
|
|
27
|
-
return response.unauthorized({
|
|
28
|
-
error: t("auth.errors.invalidAccessToken"),
|
|
29
|
-
errorCode: AuthErrorCodes.InvalidAccessToken,
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
// now, we need to get an instance of user using its corresponding model
|
|
33
|
-
const userType = user.userType || accessToken.get("userType");
|
|
34
|
-
// check if the user type is allowed
|
|
35
|
-
if (allowedTypes.length && !allowedTypes.includes(userType)) {
|
|
36
|
-
return response.unauthorized({
|
|
37
|
-
error: t("auth.errors.unauthorized"),
|
|
38
|
-
errorCode: AuthErrorCodes.Unauthorized,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
// get user model class
|
|
42
|
-
const UserModel = config.key(`auth.userType.${userType}`);
|
|
43
|
-
if (!UserModel) {
|
|
44
|
-
throw new Error(`User type ${userType} is unknown type.`);
|
|
45
|
-
}
|
|
46
|
-
// get user model instance
|
|
47
|
-
const currentUser = await UserModel.find(user.id);
|
|
48
|
-
if (!currentUser) {
|
|
49
|
-
accessToken.destroy();
|
|
50
|
-
return response.unauthorized({
|
|
51
|
-
error: t("auth.errors.invalidAccessToken"),
|
|
52
|
-
errorCode: AuthErrorCodes.InvalidAccessToken,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
// update last access
|
|
56
|
-
accessToken.silentSaving({
|
|
57
|
-
lastAccess: new Date(),
|
|
58
|
-
});
|
|
59
|
-
// set current user
|
|
60
|
-
request.user = currentUser;
|
|
61
|
-
}
|
|
62
|
-
catch (err) {
|
|
63
|
-
log.error("http", "auth", err);
|
|
64
|
-
// unset current user
|
|
65
|
-
request.clearCurrentUser();
|
|
66
|
-
return response.unauthorized({
|
|
67
|
-
error: t("auth.errors.invalidAccessToken"),
|
|
68
|
-
errorCode: AuthErrorCodes.InvalidAccessToken,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
return auth;
|
|
73
|
-
}export{authMiddleware};//# sourceMappingURL=auth.middleware.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.middleware.js","sources":["../../src/middleware/auth.middleware.ts"],"sourcesContent":[null],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Model, type Casts } from "@warlock.js/cascade";
|
|
2
|
-
export declare class AccessToken extends Model {
|
|
3
|
-
/**
|
|
4
|
-
* {@inheritDoc}
|
|
5
|
-
*/
|
|
6
|
-
static collection: string;
|
|
7
|
-
/**
|
|
8
|
-
* {@inheritDoc}
|
|
9
|
-
*/
|
|
10
|
-
protected casts: Casts;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=access-token.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"access-token.d.ts","sourceRoot":"","sources":["../../../src/models/access-token/access-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAExD,qBAAa,WAAY,SAAQ,KAAK;IACpC;;OAEG;IACH,OAAc,UAAU,SAAkB;IAE1C;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,KAAK,CAMpB;CACH"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {Model}from'@warlock.js/cascade';class AccessToken extends Model {
|
|
2
|
-
/**
|
|
3
|
-
* {@inheritDoc}
|
|
4
|
-
*/
|
|
5
|
-
static collection = "accessTokens";
|
|
6
|
-
/**
|
|
7
|
-
* {@inheritDoc}
|
|
8
|
-
*/
|
|
9
|
-
casts = {
|
|
10
|
-
lastAccess: "date",
|
|
11
|
-
token: "string",
|
|
12
|
-
"user.id": "int",
|
|
13
|
-
"user._id": "string",
|
|
14
|
-
"user.userType": "string",
|
|
15
|
-
};
|
|
16
|
-
}export{AccessToken};//# sourceMappingURL=access-token.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"access-token.js","sources":["../../../src/models/access-token/access-token.ts"],"sourcesContent":[null],"names":[],"mappings":"wCAEM,MAAO,WAAY,SAAQ,KAAK,CAAA;AACpC;;AAEG;AACI,IAAA,OAAO,UAAU,GAAG,cAAc,CAAC;AAE1C;;AAEG;AACO,IAAA,KAAK,GAAU;AACvB,QAAA,UAAU,EAAE,MAAM;AAClB,QAAA,KAAK,EAAE,QAAQ;AACf,QAAA,SAAS,EAAE,KAAK;AAChB,QAAA,UAAU,EAAE,QAAQ;AACpB,QAAA,eAAe,EAAE,QAAQ;KAC1B,CAAC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/models/access-token/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/models/access-token/migration.ts"],"names":[],"mappings":";AAGA,wBASG"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import {migrationOffice}from'@warlock.js/cascade';import {AccessToken}from'./access-token.js';migrationOffice.register({
|
|
2
|
-
name: "accessToken",
|
|
3
|
-
blueprint: AccessToken.blueprint(),
|
|
4
|
-
up: blueprint => {
|
|
5
|
-
blueprint.index("token");
|
|
6
|
-
},
|
|
7
|
-
down: blueprint => {
|
|
8
|
-
blueprint.dropUniqueIndex("token");
|
|
9
|
-
},
|
|
10
|
-
});//# sourceMappingURL=migration.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migration.js","sources":["../../../src/models/access-token/migration.ts"],"sourcesContent":[null],"names":[],"mappings":"8FAGe,eAAe,CAAC,QAAQ,CAAC;AACtC,IAAA,IAAI,EAAE,aAAa;AACnB,IAAA,SAAS,EAAE,WAAW,CAAC,SAAS,EAAE;IAClC,EAAE,EAAE,SAAS,IAAG;AACd,QAAA,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;KAC1B;IACD,IAAI,EAAE,SAAS,IAAG;AAChB,QAAA,SAAS,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;KACpC;AACF,CAAA,CAAC"}
|
package/esm/models/auth.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { ChildModel } from "@warlock.js/cascade";
|
|
2
|
-
import { Model } from "@warlock.js/cascade";
|
|
3
|
-
import type { DeviceInfo, TokenPair } from "../contracts/types";
|
|
4
|
-
import type { RefreshToken } from "./refresh-token/refresh-token";
|
|
5
|
-
export declare abstract class Auth extends Model {
|
|
6
|
-
/**
|
|
7
|
-
* Get user type
|
|
8
|
-
*/
|
|
9
|
-
abstract get userType(): string;
|
|
10
|
-
/**
|
|
11
|
-
* Get access token payload
|
|
12
|
-
*/
|
|
13
|
-
accessTokenPayload(): any;
|
|
14
|
-
/**
|
|
15
|
-
* Create both access and refresh tokens
|
|
16
|
-
*/
|
|
17
|
-
createTokenPair(deviceInfo?: DeviceInfo): Promise<TokenPair>;
|
|
18
|
-
/**
|
|
19
|
-
* Generate access token
|
|
20
|
-
*/
|
|
21
|
-
generateAccessToken(data?: any): Promise<string>;
|
|
22
|
-
/**
|
|
23
|
-
* Generate refresh token
|
|
24
|
-
*/
|
|
25
|
-
generateRefreshToken(deviceInfo?: DeviceInfo): Promise<RefreshToken>;
|
|
26
|
-
/**
|
|
27
|
-
* Remove current access token
|
|
28
|
-
*/
|
|
29
|
-
removeAccessToken(token: string): Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
* Revoke all tokens (logout from all devices)
|
|
32
|
-
*/
|
|
33
|
-
revokeAllTokens(): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Get active sessions
|
|
36
|
-
*/
|
|
37
|
-
activeSessions(): Promise<RefreshToken[]>;
|
|
38
|
-
/**
|
|
39
|
-
* Attempt to login the user
|
|
40
|
-
*/
|
|
41
|
-
static attempt<T>(this: ChildModel<T>, data: any): Promise<T | null>;
|
|
42
|
-
/**
|
|
43
|
-
* Confirm password
|
|
44
|
-
*/
|
|
45
|
-
confirmPassword(password: string): boolean;
|
|
46
|
-
}
|
|
47
|
-
//# sourceMappingURL=auth.d.ts.map
|
package/esm/models/auth.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/models/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAElE,8BAAsB,IAAK,SAAQ,KAAK;IACtC;;OAEG;IACH,aAAoB,QAAQ,IAAI,MAAM,CAAC;IAEvC;;OAEG;IACI,kBAAkB;IAMzB;;OAEG;IACU,eAAe,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC;IAIzE;;OAEG;IACU,mBAAmB,CAAC,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAI7D;;OAEG;IACU,oBAAoB,CAAC,UAAU,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,YAAY,CAAC;IAIjF;;OAEG;IACU,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5D;;OAEG;IACU,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAI7C;;OAEG;IACU,cAAc,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;IAItD;;OAEG;WACiB,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAIjF;;OAEG;IACI,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;CAGlD"}
|
package/esm/models/auth.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import {Model}from'@warlock.js/cascade';import'@mongez/events';import {authService}from'../services/auth.service.js';import'@mongez/fs';import'@mongez/reinforcements';import'@warlock.js/core';import'@warlock.js/logger';import'fast-jwt';class Auth extends Model {
|
|
2
|
-
/**
|
|
3
|
-
* Get access token payload
|
|
4
|
-
*/
|
|
5
|
-
accessTokenPayload() {
|
|
6
|
-
// Dynamically import to avoid circular dependency
|
|
7
|
-
const { authService } = require("../services/auth.service");
|
|
8
|
-
return authService.buildAccessTokenPayload(this);
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Create both access and refresh tokens
|
|
12
|
-
*/
|
|
13
|
-
async createTokenPair(deviceInfo) {
|
|
14
|
-
return authService.createTokenPair(this, deviceInfo);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Generate access token
|
|
18
|
-
*/
|
|
19
|
-
async generateAccessToken(data) {
|
|
20
|
-
return authService.generateAccessToken(this, data);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Generate refresh token
|
|
24
|
-
*/
|
|
25
|
-
async generateRefreshToken(deviceInfo) {
|
|
26
|
-
return authService.createRefreshToken(this, deviceInfo);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Remove current access token
|
|
30
|
-
*/
|
|
31
|
-
async removeAccessToken(token) {
|
|
32
|
-
return authService.removeAccessToken(this, token);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Revoke all tokens (logout from all devices)
|
|
36
|
-
*/
|
|
37
|
-
async revokeAllTokens() {
|
|
38
|
-
return authService.revokeAllTokens(this);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Get active sessions
|
|
42
|
-
*/
|
|
43
|
-
async activeSessions() {
|
|
44
|
-
return authService.getActiveSessions(this);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Attempt to login the user
|
|
48
|
-
*/
|
|
49
|
-
static async attempt(data) {
|
|
50
|
-
return authService.attemptLogin(this, data);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Confirm password
|
|
54
|
-
*/
|
|
55
|
-
confirmPassword(password) {
|
|
56
|
-
return authService.verifyPassword(this.get("password"), password);
|
|
57
|
-
}
|
|
58
|
-
}export{Auth};//# sourceMappingURL=auth.js.map
|
package/esm/models/auth.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sources":["../../src/models/auth.ts"],"sourcesContent":[null],"names":[],"mappings":"4OAMM,MAAgB,IAAK,SAAQ,KAAK,CAAA;AAMtC;;AAEG;IACI,kBAAkB,GAAA;;QAEvB,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAC5D,QAAA,OAAO,WAAW,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC;KAClD;AAED;;AAEG;IACI,MAAM,eAAe,CAAC,UAAuB,EAAA;QAClD,OAAO,WAAW,CAAC,eAAe,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;KACtD;AAED;;AAEG;IACI,MAAM,mBAAmB,CAAC,IAAU,EAAA;QACzC,OAAO,WAAW,CAAC,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;KACpD;AAED;;AAEG;IACI,MAAM,oBAAoB,CAAC,UAAuB,EAAA;QACvD,OAAO,WAAW,CAAC,kBAAkB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;KACzD;AAED;;AAEG;IACI,MAAM,iBAAiB,CAAC,KAAa,EAAA;QAC1C,OAAO,WAAW,CAAC,iBAAiB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;KACnD;AAED;;AAEG;AACI,IAAA,MAAM,eAAe,GAAA;AAC1B,QAAA,OAAO,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;KAC1C;AAED;;AAEG;AACI,IAAA,MAAM,cAAc,GAAA;AACzB,QAAA,OAAO,WAAW,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;KAC5C;AAED;;AAEG;AACI,IAAA,aAAa,OAAO,CAAyB,IAAS,EAAA;QAC3D,OAAO,WAAW,CAAC,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;KAC7C;AAED;;AAEG;AACI,IAAA,eAAe,CAAC,QAAgB,EAAA;AACrC,QAAA,OAAO,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAC;KACnE;AACF"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Model } from "@warlock.js/cascade";
|
|
2
|
-
/**
|
|
3
|
-
* Cast password on model save
|
|
4
|
-
* If the password is not changed, keep it as is
|
|
5
|
-
*/
|
|
6
|
-
export declare function castPassword(value: any, column: string, model: Model): any;
|
|
7
|
-
//# sourceMappingURL=cast-password.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cast-password.d.ts","sourceRoot":"","sources":["../../../src/models/casts/cast-password.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAGjD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,OAIpE"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {hash}from'@mongez/password';import {config}from'@warlock.js/core';/**
|
|
2
|
-
* Cast password on model save
|
|
3
|
-
* If the password is not changed, keep it as is
|
|
4
|
-
*/
|
|
5
|
-
function castPassword(value, column, model) {
|
|
6
|
-
return value
|
|
7
|
-
? hash(String(value), config.key("auth.password.salt", 12))
|
|
8
|
-
: model.getInitial(column);
|
|
9
|
-
}export{castPassword};//# sourceMappingURL=cast-password.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cast-password.js","sources":["../../../src/models/casts/cast-password.ts"],"sourcesContent":[null],"names":[],"mappings":"0EAIA;;;AAGG;SACa,YAAY,CAAC,KAAU,EAAE,MAAc,EAAE,KAAY,EAAA;AACnE,IAAA,OAAO,KAAK;AACV,UAAE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,oBAAoB,EAAE,EAAE,CAAC,CAAC;AAC3D,UAAE,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAC/B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/models/casts/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
package/esm/models/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/models/refresh-token/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../../src/models/refresh-token/migration.ts"],"names":[],"mappings":";AAGA,wBAeG"}
|