elseware-nodejs 1.5.1 → 1.5.2
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/index.cjs +28 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +28 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1863,8 +1863,8 @@ declare const validate: (schema: Schema) => (req: Request, _res: Response, next:
|
|
|
1863
1863
|
interface JWTServiceOptions {
|
|
1864
1864
|
accessSecret: string;
|
|
1865
1865
|
refreshSecret: string;
|
|
1866
|
-
accessExpires?: SignOptions["expiresIn"];
|
|
1867
|
-
refreshExpires?: SignOptions["expiresIn"];
|
|
1866
|
+
accessExpires?: SignOptions["expiresIn"] | string;
|
|
1867
|
+
refreshExpires?: SignOptions["expiresIn"] | string;
|
|
1868
1868
|
nodeEnv?: string;
|
|
1869
1869
|
refreshCookieName?: string;
|
|
1870
1870
|
}
|
|
@@ -1884,6 +1884,8 @@ declare class JWTService {
|
|
|
1884
1884
|
setRefreshTokenCookie(res: Response, refreshToken: string): void;
|
|
1885
1885
|
clearRefreshTokenCookie(res: Response): void;
|
|
1886
1886
|
sendAuthTokens(res: Response, payload: object): string;
|
|
1887
|
+
private normalizeToken;
|
|
1888
|
+
private parseExpires;
|
|
1887
1889
|
}
|
|
1888
1890
|
|
|
1889
1891
|
declare function errorToString(error: unknown): string;
|
package/dist/index.d.ts
CHANGED
|
@@ -1863,8 +1863,8 @@ declare const validate: (schema: Schema) => (req: Request, _res: Response, next:
|
|
|
1863
1863
|
interface JWTServiceOptions {
|
|
1864
1864
|
accessSecret: string;
|
|
1865
1865
|
refreshSecret: string;
|
|
1866
|
-
accessExpires?: SignOptions["expiresIn"];
|
|
1867
|
-
refreshExpires?: SignOptions["expiresIn"];
|
|
1866
|
+
accessExpires?: SignOptions["expiresIn"] | string;
|
|
1867
|
+
refreshExpires?: SignOptions["expiresIn"] | string;
|
|
1868
1868
|
nodeEnv?: string;
|
|
1869
1869
|
refreshCookieName?: string;
|
|
1870
1870
|
}
|
|
@@ -1884,6 +1884,8 @@ declare class JWTService {
|
|
|
1884
1884
|
setRefreshTokenCookie(res: Response, refreshToken: string): void;
|
|
1885
1885
|
clearRefreshTokenCookie(res: Response): void;
|
|
1886
1886
|
sendAuthTokens(res: Response, payload: object): string;
|
|
1887
|
+
private normalizeToken;
|
|
1888
|
+
private parseExpires;
|
|
1887
1889
|
}
|
|
1888
1890
|
|
|
1889
1891
|
declare function errorToString(error: unknown): string;
|
package/dist/index.js
CHANGED
|
@@ -5297,8 +5297,8 @@ var JWTService = class {
|
|
|
5297
5297
|
constructor(options) {
|
|
5298
5298
|
this.accessSecret = options.accessSecret;
|
|
5299
5299
|
this.refreshSecret = options.refreshSecret;
|
|
5300
|
-
this.accessExpires = options.accessExpires
|
|
5301
|
-
this.refreshExpires = options.refreshExpires
|
|
5300
|
+
this.accessExpires = this.parseExpires(options.accessExpires, "15m");
|
|
5301
|
+
this.refreshExpires = this.parseExpires(options.refreshExpires, "30d");
|
|
5302
5302
|
this.nodeEnv = options.nodeEnv || "development";
|
|
5303
5303
|
this.refreshCookieName = options.refreshCookieName || "refreshJwt";
|
|
5304
5304
|
}
|
|
@@ -5338,14 +5338,18 @@ var JWTService = class {
|
|
|
5338
5338
|
// Token Extraction
|
|
5339
5339
|
// ---------------------------------
|
|
5340
5340
|
extractToken(req) {
|
|
5341
|
+
let token = null;
|
|
5341
5342
|
if (req.headers.authorization?.startsWith("Bearer ")) {
|
|
5342
|
-
|
|
5343
|
+
token = req.headers.authorization.split(" ")[1];
|
|
5344
|
+
return token ? this.normalizeToken(token) : null;
|
|
5343
5345
|
}
|
|
5344
5346
|
if (req.cookies?.[this.refreshCookieName]) {
|
|
5345
|
-
|
|
5347
|
+
token = req.cookies[this.refreshCookieName];
|
|
5348
|
+
return token ? this.normalizeToken(token) : null;
|
|
5346
5349
|
}
|
|
5347
5350
|
if (req.cookies?.jwt) {
|
|
5348
|
-
|
|
5351
|
+
token = req.cookies.jwt;
|
|
5352
|
+
return token ? this.normalizeToken(token) : null;
|
|
5349
5353
|
}
|
|
5350
5354
|
return null;
|
|
5351
5355
|
}
|
|
@@ -5378,6 +5382,25 @@ var JWTService = class {
|
|
|
5378
5382
|
this.setRefreshTokenCookie(res, refreshToken);
|
|
5379
5383
|
return accessToken;
|
|
5380
5384
|
}
|
|
5385
|
+
// ---------------------------------
|
|
5386
|
+
// Internal Helpers
|
|
5387
|
+
// ---------------------------------
|
|
5388
|
+
normalizeToken(token) {
|
|
5389
|
+
token = token.trim();
|
|
5390
|
+
if (token.startsWith('"') && token.endsWith('"')) {
|
|
5391
|
+
try {
|
|
5392
|
+
return JSON.parse(token);
|
|
5393
|
+
} catch {
|
|
5394
|
+
return token.slice(1, -1);
|
|
5395
|
+
}
|
|
5396
|
+
}
|
|
5397
|
+
return token;
|
|
5398
|
+
}
|
|
5399
|
+
parseExpires(value, fallback) {
|
|
5400
|
+
if (!value) return fallback;
|
|
5401
|
+
if (typeof value === "number") return value;
|
|
5402
|
+
return value;
|
|
5403
|
+
}
|
|
5381
5404
|
};
|
|
5382
5405
|
|
|
5383
5406
|
// src/utils/time.ts
|