@warlock.js/auth 4.1.7 → 4.1.9
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.cjs +15 -15
- package/esm/commands/auth-cleanup-command.d.mts +1 -1
- package/esm/commands/auth-cleanup-command.mjs +1 -1
- package/esm/commands/jwt-secret-generator-command.d.mts +1 -1
- package/esm/commands/jwt-secret-generator-command.mjs +1 -1
- package/esm/contracts/auth-contract.d.mts +1 -1
- package/esm/contracts/types.d.mts +1 -1
- package/esm/contracts/types.mjs +1 -1
- package/esm/middleware/auth.middleware.d.mts +1 -1
- package/esm/middleware/auth.middleware.mjs +1 -1
- package/esm/models/access-token/access-token.model.d.mts +1 -1
- package/esm/models/access-token/access-token.model.mjs +1 -1
- package/esm/models/access-token/migration.mjs +1 -1
- package/esm/models/auth.model.d.mts +1 -1
- package/esm/models/auth.model.mjs +1 -1
- package/esm/models/index.d.mts +1 -1
- package/esm/models/index.mjs +1 -1
- package/esm/models/refresh-token/migration.mjs +1 -1
- package/esm/models/refresh-token/refresh-token.model.d.mts +1 -1
- package/esm/models/refresh-token/refresh-token.model.mjs +1 -1
- package/esm/services/auth-events.d.mts +1 -1
- package/esm/services/auth-events.mjs +1 -1
- package/esm/services/auth.service.d.mts +1 -1
- package/esm/services/auth.service.mjs +1 -1
- package/esm/services/generate-jwt-secret.d.mts +1 -1
- package/esm/services/generate-jwt-secret.mjs +1 -1
- package/esm/services/jwt.d.mts +1 -1
- package/esm/services/jwt.mjs +1 -1
- package/esm/utils/auth-error-codes.d.mts +1 -1
- package/esm/utils/auth-error-codes.mjs +1 -1
- package/package.json +6 -6
package/cjs/index.cjs
CHANGED
|
@@ -39,7 +39,7 @@ let fast_jwt = require("fast-jwt");
|
|
|
39
39
|
let _warlock_js_fs = require("@warlock.js/fs");
|
|
40
40
|
let _warlock_js_logger = require("@warlock.js/logger");
|
|
41
41
|
|
|
42
|
-
//#region
|
|
42
|
+
//#region ../@warlock.js/auth/src/models/access-token/access-token.model.ts
|
|
43
43
|
const accessTokenSchema = _warlock_js_seal.v.object({
|
|
44
44
|
token: _warlock_js_seal.v.string().required(),
|
|
45
45
|
last_access: _warlock_js_seal.v.date().defaultNow().optional(),
|
|
@@ -57,7 +57,7 @@ var AccessToken = class extends _warlock_js_cascade.Model {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
//#endregion
|
|
60
|
-
//#region
|
|
60
|
+
//#region ../@warlock.js/auth/src/models/refresh-token/refresh-token.model.ts
|
|
61
61
|
const refreshTokenSchema = _warlock_js_seal.v.object({
|
|
62
62
|
token: _warlock_js_seal.v.string().required(),
|
|
63
63
|
user_id: _warlock_js_seal.v.scalar().required(),
|
|
@@ -110,7 +110,7 @@ var RefreshToken = class extends _warlock_js_cascade.Model {
|
|
|
110
110
|
};
|
|
111
111
|
|
|
112
112
|
//#endregion
|
|
113
|
-
//#region
|
|
113
|
+
//#region ../@warlock.js/auth/src/services/auth-events.ts
|
|
114
114
|
/**
|
|
115
115
|
* Event namespace prefix for auth events
|
|
116
116
|
*/
|
|
@@ -174,7 +174,7 @@ const authEvents = {
|
|
|
174
174
|
};
|
|
175
175
|
|
|
176
176
|
//#endregion
|
|
177
|
-
//#region
|
|
177
|
+
//#region ../@warlock.js/auth/src/services/jwt.ts
|
|
178
178
|
const getSecretKey = () => _warlock_js_core.config.key("auth.jwt.secret");
|
|
179
179
|
const getAlgorithm = () => _warlock_js_core.config.key("auth.jwt.algorithm", "HS256");
|
|
180
180
|
const getRefreshSecretKey = () => _warlock_js_core.config.key("auth.jwt.refresh.secret") || getSecretKey();
|
|
@@ -226,7 +226,7 @@ const jwt = {
|
|
|
226
226
|
};
|
|
227
227
|
|
|
228
228
|
//#endregion
|
|
229
|
-
//#region
|
|
229
|
+
//#region ../@warlock.js/auth/src/services/auth.service.ts
|
|
230
230
|
var AuthService = class {
|
|
231
231
|
/**
|
|
232
232
|
* Build access token payload from user
|
|
@@ -489,7 +489,7 @@ var AuthService = class {
|
|
|
489
489
|
const authService = new AuthService();
|
|
490
490
|
|
|
491
491
|
//#endregion
|
|
492
|
-
//#region
|
|
492
|
+
//#region ../@warlock.js/auth/src/commands/auth-cleanup-command.ts
|
|
493
493
|
/**
|
|
494
494
|
* Register the auth:cleanup CLI command
|
|
495
495
|
*
|
|
@@ -517,7 +517,7 @@ function registerAuthCleanupCommand() {
|
|
|
517
517
|
}
|
|
518
518
|
|
|
519
519
|
//#endregion
|
|
520
|
-
//#region
|
|
520
|
+
//#region ../@warlock.js/auth/src/services/generate-jwt-secret.ts
|
|
521
521
|
async function generateJWTSecret() {
|
|
522
522
|
let envFile = (0, _warlock_js_core.rootPath)(".env");
|
|
523
523
|
_warlock_js_logger.log.info("jwt", "generating", "Generating JWT secrets");
|
|
@@ -558,7 +558,7 @@ JWT_REFRESH_SECRET=${jwtRefreshSecret}
|
|
|
558
558
|
}
|
|
559
559
|
|
|
560
560
|
//#endregion
|
|
561
|
-
//#region
|
|
561
|
+
//#region ../@warlock.js/auth/src/commands/jwt-secret-generator-command.ts
|
|
562
562
|
function registerJWTSecretGeneratorCommand() {
|
|
563
563
|
return (0, _warlock_js_core.command)({
|
|
564
564
|
name: "jwt.generate",
|
|
@@ -568,7 +568,7 @@ function registerJWTSecretGeneratorCommand() {
|
|
|
568
568
|
}
|
|
569
569
|
|
|
570
570
|
//#endregion
|
|
571
|
-
//#region
|
|
571
|
+
//#region ../@warlock.js/auth/src/contracts/types.ts
|
|
572
572
|
/**
|
|
573
573
|
* Symbol to indicate no expiration for tokens
|
|
574
574
|
* Use this when you explicitly want tokens to never expire
|
|
@@ -591,7 +591,7 @@ function registerJWTSecretGeneratorCommand() {
|
|
|
591
591
|
const NO_EXPIRATION = "100y";
|
|
592
592
|
|
|
593
593
|
//#endregion
|
|
594
|
-
//#region
|
|
594
|
+
//#region ../@warlock.js/auth/src/utils/auth-error-codes.ts
|
|
595
595
|
let AuthErrorCodes = /* @__PURE__ */ function(AuthErrorCodes) {
|
|
596
596
|
/**
|
|
597
597
|
* Missing Access Token Error Code EC001
|
|
@@ -612,7 +612,7 @@ let AuthErrorCodes = /* @__PURE__ */ function(AuthErrorCodes) {
|
|
|
612
612
|
}({});
|
|
613
613
|
|
|
614
614
|
//#endregion
|
|
615
|
-
//#region
|
|
615
|
+
//#region ../@warlock.js/auth/src/middleware/auth.middleware.ts
|
|
616
616
|
/**
|
|
617
617
|
* Build a route gate that always requires an authenticated request.
|
|
618
618
|
*
|
|
@@ -675,7 +675,7 @@ function authMiddleware(allowedUserType) {
|
|
|
675
675
|
}
|
|
676
676
|
|
|
677
677
|
//#endregion
|
|
678
|
-
//#region
|
|
678
|
+
//#region ../@warlock.js/auth/src/models/access-token/migration.ts
|
|
679
679
|
const AccessTokenMigration = (0, _warlock_js_cascade.migrate)(AccessToken, {
|
|
680
680
|
name: "accessToken",
|
|
681
681
|
up() {
|
|
@@ -694,7 +694,7 @@ const AccessTokenMigration = (0, _warlock_js_cascade.migrate)(AccessToken, {
|
|
|
694
694
|
});
|
|
695
695
|
|
|
696
696
|
//#endregion
|
|
697
|
-
//#region
|
|
697
|
+
//#region ../@warlock.js/auth/src/models/refresh-token/migration.ts
|
|
698
698
|
const RefreshTokenMigration = (0, _warlock_js_cascade.migrate)(RefreshToken, {
|
|
699
699
|
name: "refreshToken",
|
|
700
700
|
up() {
|
|
@@ -716,7 +716,7 @@ const RefreshTokenMigration = (0, _warlock_js_cascade.migrate)(RefreshToken, {
|
|
|
716
716
|
});
|
|
717
717
|
|
|
718
718
|
//#endregion
|
|
719
|
-
//#region
|
|
719
|
+
//#region ../@warlock.js/auth/src/models/auth.model.ts
|
|
720
720
|
var Auth = class extends _warlock_js_cascade.Model {
|
|
721
721
|
/**
|
|
722
722
|
* Get access token payload
|
|
@@ -787,7 +787,7 @@ var Auth = class extends _warlock_js_cascade.Model {
|
|
|
787
787
|
};
|
|
788
788
|
|
|
789
789
|
//#endregion
|
|
790
|
-
//#region
|
|
790
|
+
//#region ../@warlock.js/auth/src/models/index.ts
|
|
791
791
|
const authMigrations = [AccessTokenMigration, RefreshTokenMigration];
|
|
792
792
|
|
|
793
793
|
//#endregion
|
|
@@ -2,7 +2,7 @@ import { authService } from "../services/auth.service.mjs";
|
|
|
2
2
|
import { colors } from "@mongez/copper";
|
|
3
3
|
import { command } from "@warlock.js/core";
|
|
4
4
|
|
|
5
|
-
//#region
|
|
5
|
+
//#region ../@warlock.js/auth/src/commands/auth-cleanup-command.ts
|
|
6
6
|
/**
|
|
7
7
|
* Register the auth:cleanup CLI command
|
|
8
8
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region
|
|
1
|
+
//#region ../@warlock.js/auth/src/commands/jwt-secret-generator-command.d.ts
|
|
2
2
|
declare function registerJWTSecretGeneratorCommand(): any;
|
|
3
3
|
//#endregion
|
|
4
4
|
export { registerJWTSecretGeneratorCommand };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { generateJWTSecret } from "../services/generate-jwt-secret.mjs";
|
|
2
2
|
import { command } from "@warlock.js/core";
|
|
3
3
|
|
|
4
|
-
//#region
|
|
4
|
+
//#region ../@warlock.js/auth/src/commands/jwt-secret-generator-command.ts
|
|
5
5
|
function registerJWTSecretGeneratorCommand() {
|
|
6
6
|
return command({
|
|
7
7
|
name: "jwt.generate",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RefreshToken } from "../models/refresh-token/refresh-token.model.mjs";
|
|
2
2
|
import { AccessTokenOutput, DeviceInfo, TokenPair } from "./types.mjs";
|
|
3
3
|
|
|
4
|
-
//#region
|
|
4
|
+
//#region ../@warlock.js/auth/src/contracts/auth-contract.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Surface every authenticable user model exposes once it extends the
|
|
7
7
|
* `Auth` base. The `Auth` class implements this contract; subclasses only
|
|
@@ -2,7 +2,7 @@ import { Auth } from "../models/auth.model.mjs";
|
|
|
2
2
|
import { ChildModel } from "@warlock.js/cascade";
|
|
3
3
|
import { Algorithm } from "fast-jwt";
|
|
4
4
|
|
|
5
|
-
//#region
|
|
5
|
+
//#region ../@warlock.js/auth/src/contracts/types.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Symbol to indicate no expiration for tokens
|
|
8
8
|
* Use this when you explicitly want tokens to never expire
|
package/esm/contracts/types.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { AuthErrorCodes } from "../utils/auth-error-codes.mjs";
|
|
|
5
5
|
import { config, t } from "@warlock.js/core";
|
|
6
6
|
import { log } from "@warlock.js/logger";
|
|
7
7
|
|
|
8
|
-
//#region
|
|
8
|
+
//#region ../@warlock.js/auth/src/middleware/auth.middleware.ts
|
|
9
9
|
/**
|
|
10
10
|
* Build a route gate that always requires an authenticated request.
|
|
11
11
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Model } from "@warlock.js/cascade";
|
|
2
2
|
|
|
3
|
-
//#region
|
|
3
|
+
//#region ../@warlock.js/auth/src/models/access-token/access-token.model.d.ts
|
|
4
4
|
declare class AccessToken extends Model {
|
|
5
5
|
/**
|
|
6
6
|
* {@inheritDoc}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Model } from "@warlock.js/cascade";
|
|
2
2
|
import { v } from "@warlock.js/seal";
|
|
3
3
|
|
|
4
|
-
//#region
|
|
4
|
+
//#region ../@warlock.js/auth/src/models/access-token/access-token.model.ts
|
|
5
5
|
const accessTokenSchema = v.object({
|
|
6
6
|
token: v.string().required(),
|
|
7
7
|
last_access: v.date().defaultNow().optional(),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AccessToken } from "./access-token.model.mjs";
|
|
2
2
|
import { migrate } from "@warlock.js/cascade";
|
|
3
3
|
|
|
4
|
-
//#region
|
|
4
|
+
//#region ../@warlock.js/auth/src/models/access-token/migration.ts
|
|
5
5
|
const AccessTokenMigration = migrate(AccessToken, {
|
|
6
6
|
name: "accessToken",
|
|
7
7
|
up() {
|
|
@@ -3,7 +3,7 @@ import { AccessTokenOutput, DeviceInfo, TokenPair } from "../contracts/types.mjs
|
|
|
3
3
|
import { Authenticable } from "../contracts/auth-contract.mjs";
|
|
4
4
|
import { ChildModel, Model, ModelSchema } from "@warlock.js/cascade";
|
|
5
5
|
|
|
6
|
-
//#region
|
|
6
|
+
//#region ../@warlock.js/auth/src/models/auth.model.d.ts
|
|
7
7
|
declare abstract class Auth<Schema extends ModelSchema = ModelSchema> extends Model<Schema> implements Authenticable {
|
|
8
8
|
/**
|
|
9
9
|
* Get user type
|
|
@@ -2,7 +2,7 @@ import { authService } from "../services/auth.service.mjs";
|
|
|
2
2
|
import "../services/index.mjs";
|
|
3
3
|
import { Model } from "@warlock.js/cascade";
|
|
4
4
|
|
|
5
|
-
//#region
|
|
5
|
+
//#region ../@warlock.js/auth/src/models/auth.model.ts
|
|
6
6
|
var Auth = class extends Model {
|
|
7
7
|
/**
|
|
8
8
|
* Get access token payload
|
package/esm/models/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RefreshToken } from "./refresh-token/refresh-token.model.mjs";
|
|
2
2
|
import { Auth } from "./auth.model.mjs";
|
|
3
3
|
import { AccessToken } from "./access-token/access-token.model.mjs";
|
|
4
|
-
//#region
|
|
4
|
+
//#region ../@warlock.js/auth/src/models/index.d.ts
|
|
5
5
|
declare const authMigrations: any[];
|
|
6
6
|
//#endregion
|
|
7
7
|
export { authMigrations };
|
package/esm/models/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { AccessTokenMigration } from "./access-token/migration.mjs";
|
|
|
6
6
|
import { RefreshTokenMigration } from "./refresh-token/migration.mjs";
|
|
7
7
|
import { Auth } from "./auth.model.mjs";
|
|
8
8
|
|
|
9
|
-
//#region
|
|
9
|
+
//#region ../@warlock.js/auth/src/models/index.ts
|
|
10
10
|
const authMigrations = [AccessTokenMigration, RefreshTokenMigration];
|
|
11
11
|
|
|
12
12
|
//#endregion
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RefreshToken } from "./refresh-token.model.mjs";
|
|
2
2
|
import { migrate } from "@warlock.js/cascade";
|
|
3
3
|
|
|
4
|
-
//#region
|
|
4
|
+
//#region ../@warlock.js/auth/src/models/refresh-token/migration.ts
|
|
5
5
|
const RefreshTokenMigration = migrate(RefreshToken, {
|
|
6
6
|
name: "refreshToken",
|
|
7
7
|
up() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Model } from "@warlock.js/cascade";
|
|
2
2
|
|
|
3
|
-
//#region
|
|
3
|
+
//#region ../@warlock.js/auth/src/models/refresh-token/refresh-token.model.d.ts
|
|
4
4
|
declare class RefreshToken extends Model {
|
|
5
5
|
/**
|
|
6
6
|
* {@inheritDoc}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Model } from "@warlock.js/cascade";
|
|
2
2
|
import { v } from "@warlock.js/seal";
|
|
3
3
|
|
|
4
|
-
//#region
|
|
4
|
+
//#region ../@warlock.js/auth/src/models/refresh-token/refresh-token.model.ts
|
|
5
5
|
const refreshTokenSchema = v.object({
|
|
6
6
|
token: v.string().required(),
|
|
7
7
|
user_id: v.scalar().required(),
|
|
@@ -3,7 +3,7 @@ import { Auth } from "../models/auth.model.mjs";
|
|
|
3
3
|
import { DeviceInfo, TokenPair } from "../contracts/types.mjs";
|
|
4
4
|
import { EventSubscription } from "@mongez/events";
|
|
5
5
|
|
|
6
|
-
//#region
|
|
6
|
+
//#region ../@warlock.js/auth/src/services/auth-events.d.ts
|
|
7
7
|
/**
|
|
8
8
|
* Auth event payload types
|
|
9
9
|
*/
|
|
@@ -3,7 +3,7 @@ import { Auth } from "../models/auth.model.mjs";
|
|
|
3
3
|
import { AccessTokenOutput, DeviceInfo, LoginResult, TokenPair } from "../contracts/types.mjs";
|
|
4
4
|
import { ChildModel } from "@warlock.js/cascade";
|
|
5
5
|
|
|
6
|
-
//#region
|
|
6
|
+
//#region ../@warlock.js/auth/src/services/auth.service.d.ts
|
|
7
7
|
declare class AuthService {
|
|
8
8
|
/**
|
|
9
9
|
* Build access token payload from user
|
|
@@ -8,7 +8,7 @@ import { config, hashPassword, verifyPassword } from "@warlock.js/core";
|
|
|
8
8
|
import { Random } from "@mongez/reinforcements";
|
|
9
9
|
import ms from "ms";
|
|
10
10
|
|
|
11
|
-
//#region
|
|
11
|
+
//#region ../@warlock.js/auth/src/services/auth.service.ts
|
|
12
12
|
var AuthService = class {
|
|
13
13
|
/**
|
|
14
14
|
* Build access token payload from user
|
|
@@ -3,7 +3,7 @@ import { Random } from "@mongez/reinforcements";
|
|
|
3
3
|
import { fileExistsAsync, getFileAsync, putFileAsync } from "@warlock.js/fs";
|
|
4
4
|
import { log } from "@warlock.js/logger";
|
|
5
5
|
|
|
6
|
-
//#region
|
|
6
|
+
//#region ../@warlock.js/auth/src/services/generate-jwt-secret.ts
|
|
7
7
|
async function generateJWTSecret() {
|
|
8
8
|
let envFile = rootPath(".env");
|
|
9
9
|
log.info("jwt", "generating", "Generating JWT secrets");
|
package/esm/services/jwt.d.mts
CHANGED
package/esm/services/jwt.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { config } from "@warlock.js/core";
|
|
|
2
2
|
import ms from "ms";
|
|
3
3
|
import { createSigner, createVerifier } from "fast-jwt";
|
|
4
4
|
|
|
5
|
-
//#region
|
|
5
|
+
//#region ../@warlock.js/auth/src/services/jwt.ts
|
|
6
6
|
const getSecretKey = () => config.key("auth.jwt.secret");
|
|
7
7
|
const getAlgorithm = () => config.key("auth.jwt.algorithm", "HS256");
|
|
8
8
|
const getRefreshSecretKey = () => config.key("auth.jwt.refresh.secret") || getSecretKey();
|
package/package.json
CHANGED
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@mongez/copper": "^2.1.2",
|
|
24
24
|
"@mongez/events": "^2.2.6",
|
|
25
|
-
"@warlock.js/fs": "
|
|
25
|
+
"@warlock.js/fs": "*",
|
|
26
26
|
"@mongez/reinforcements": "^3.2.0",
|
|
27
|
-
"@warlock.js/cascade": "
|
|
28
|
-
"@warlock.js/core": "
|
|
29
|
-
"@warlock.js/logger": "
|
|
30
|
-
"@warlock.js/seal": "
|
|
27
|
+
"@warlock.js/cascade": "*",
|
|
28
|
+
"@warlock.js/core": "*",
|
|
29
|
+
"@warlock.js/logger": "*",
|
|
30
|
+
"@warlock.js/seal": "*"
|
|
31
31
|
},
|
|
32
|
-
"version": "4.1.
|
|
32
|
+
"version": "4.1.9",
|
|
33
33
|
"main": "./cjs/index.cjs",
|
|
34
34
|
"module": "./esm/index.mjs",
|
|
35
35
|
"types": "./esm/index.d.mts",
|