@celljs/jwt 3.7.8 → 3.9.0
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/esm/node/errors.d.ts +7 -0
- package/esm/node/errors.js +12 -0
- package/esm/node/errors.js.map +1 -0
- package/esm/node/index.d.ts +4 -0
- package/esm/node/index.js +5 -0
- package/esm/node/index.js.map +1 -0
- package/esm/node/jwt-protocol.d.ts +30 -0
- package/esm/node/jwt-protocol.js +3 -0
- package/esm/node/jwt-protocol.js.map +1 -0
- package/esm/node/jwt-secret-service.d.ts +6 -0
- package/esm/node/jwt-secret-service.js +41 -0
- package/esm/node/jwt-secret-service.js.map +1 -0
- package/esm/node/jwt-service.d.ts +8 -0
- package/esm/node/jwt-service.js +64 -0
- package/esm/node/jwt-service.js.map +1 -0
- package/esm/node/module.d.ts +3 -0
- package/esm/node/module.js +4 -0
- package/esm/node/module.js.map +1 -0
- package/esm/package.json +3 -0
- package/lib/node/errors.d.ts.map +1 -1
- package/lib/node/errors.js.map +1 -1
- package/lib/node/jwt-secret-service.d.ts.map +1 -1
- package/lib/node/jwt-secret-service.js +6 -4
- package/lib/node/jwt-secret-service.js.map +1 -1
- package/lib/node/jwt-service.d.ts.map +1 -1
- package/lib/node/jwt-service.js +7 -4
- package/lib/node/jwt-service.js.map +1 -1
- package/lib/node/module.d.ts.map +1 -1
- package/lib/node/module.js.map +1 -1
- package/lib/package.spec.d.ts +1 -0
- package/lib/package.spec.js +5 -2
- package/lib/package.spec.js.map +1 -1
- package/package.json +31 -9
- package/src/node/jwt-service.ts +1 -1
- package/src/package.spec.ts +1 -0
- package/LICENSE +0 -21
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CustomError } from '@celljs/core';
|
|
2
|
+
export class PublicKeyNotFoundError extends CustomError {
|
|
3
|
+
constructor() {
|
|
4
|
+
super('Public key not found');
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export class PrivateKeyNotFoundError extends CustomError {
|
|
8
|
+
constructor() {
|
|
9
|
+
super('Private key not found');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/node/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,OAAO,sBAAuB,SAAQ,WAAW;IACnD;QACI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAClC,CAAC;CACJ;AAED,MAAM,OAAO,uBAAwB,SAAQ,WAAW;IACpD;QACI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACnC,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as jwt from 'jsonwebtoken';
|
|
2
|
+
export declare const JwtService: unique symbol;
|
|
3
|
+
export declare const JwtSecretService: unique symbol;
|
|
4
|
+
export interface JwtOptions {
|
|
5
|
+
signOptions?: jwt.SignOptions;
|
|
6
|
+
secret?: string | Buffer;
|
|
7
|
+
publicKey?: string | Buffer;
|
|
8
|
+
privateKey?: jwt.Secret;
|
|
9
|
+
verifyOptions?: jwt.VerifyOptions;
|
|
10
|
+
}
|
|
11
|
+
export interface SignOptions extends jwt.SignOptions {
|
|
12
|
+
}
|
|
13
|
+
export interface VerifyOptions extends jwt.VerifyOptions {
|
|
14
|
+
}
|
|
15
|
+
export interface DecodeOptions extends jwt.DecodeOptions {
|
|
16
|
+
}
|
|
17
|
+
export interface Jwt extends jwt.Jwt {
|
|
18
|
+
}
|
|
19
|
+
export interface JwtPayload extends jwt.JwtPayload {
|
|
20
|
+
}
|
|
21
|
+
export type Secret = jwt.Secret;
|
|
22
|
+
export interface JwtService {
|
|
23
|
+
sign(payload: string | Buffer | object, options?: SignOptions, privateKey?: Secret): Promise<string>;
|
|
24
|
+
verify<T extends object = any>(token: string, options?: VerifyOptions, publicKey?: string | Buffer): Promise<T>;
|
|
25
|
+
decode(token: string, options?: DecodeOptions): Promise<JwtPayload | string | undefined>;
|
|
26
|
+
}
|
|
27
|
+
export interface JwtSecretService {
|
|
28
|
+
getPublicKey(): Promise<string | Buffer>;
|
|
29
|
+
getPrivateKey(): Promise<Secret>;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-protocol.js","sourceRoot":"","sources":["../../src/node/jwt-protocol.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAC/C,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { JwtOptions, JwtSecretService, Secret } from './jwt-protocol.js';
|
|
2
|
+
export declare class jwtSecretService implements JwtSecretService {
|
|
3
|
+
protected readonly jwtOptions?: JwtOptions;
|
|
4
|
+
getPublicKey(): Promise<string | Buffer>;
|
|
5
|
+
getPrivateKey(): Promise<Secret>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Component, Value } from '@celljs/core';
|
|
11
|
+
import { PrivateKeyNotFoundError, PublicKeyNotFoundError } from './errors.js';
|
|
12
|
+
import { JwtSecretService } from './jwt-protocol.js';
|
|
13
|
+
let jwtSecretService = class jwtSecretService {
|
|
14
|
+
async getPublicKey() {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
var _c;
|
|
17
|
+
const secret = (_c = (_a = this.jwtOptions) === null || _a === void 0 ? void 0 : _a.publicKey) !== null && _c !== void 0 ? _c : (_b = this.jwtOptions) === null || _b === void 0 ? void 0 : _b.secret;
|
|
18
|
+
if (secret) {
|
|
19
|
+
return secret;
|
|
20
|
+
}
|
|
21
|
+
throw new PublicKeyNotFoundError();
|
|
22
|
+
}
|
|
23
|
+
async getPrivateKey() {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
var _c;
|
|
26
|
+
const secret = (_c = (_a = this.jwtOptions) === null || _a === void 0 ? void 0 : _a.privateKey) !== null && _c !== void 0 ? _c : (_b = this.jwtOptions) === null || _b === void 0 ? void 0 : _b.secret;
|
|
27
|
+
if (secret) {
|
|
28
|
+
return secret;
|
|
29
|
+
}
|
|
30
|
+
throw new PrivateKeyNotFoundError();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
__decorate([
|
|
34
|
+
Value('cell.jwt'),
|
|
35
|
+
__metadata("design:type", Object)
|
|
36
|
+
], jwtSecretService.prototype, "jwtOptions", void 0);
|
|
37
|
+
jwtSecretService = __decorate([
|
|
38
|
+
Component(JwtSecretService)
|
|
39
|
+
], jwtSecretService);
|
|
40
|
+
export { jwtSecretService };
|
|
41
|
+
//# sourceMappingURL=jwt-secret-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-secret-service.js","sourceRoot":"","sources":["../../src/node/jwt-secret-service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAC3E,OAAO,EAAc,gBAAgB,EAAU,MAAM,gBAAgB,CAAC;AAG/D,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAKzB,KAAK,CAAC,YAAY;;;QACd,MAAM,MAAM,SAAG,MAAA,IAAI,CAAC,UAAU,0CAAE,SAAS,mCAAI,MAAA,IAAI,CAAC,UAAU,0CAAE,MAAM,CAAC;QACrE,IAAI,MAAM,EAAE,CAAC;YACT,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,MAAM,IAAI,sBAAsB,EAAE,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,aAAa;;;QACf,MAAM,MAAM,SAAG,MAAA,IAAI,CAAC,UAAU,0CAAE,UAAU,mCAAI,MAAA,IAAI,CAAC,UAAU,0CAAE,MAAM,CAAC;QACtE,IAAI,MAAM,EAAE,CAAC;YACT,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,MAAM,IAAI,uBAAuB,EAAE,CAAC;IACxC,CAAC;CACJ,CAAA;AAjBsB;IADlB,KAAK,CAAC,UAAU,CAAC;;oDACyB;AAHlC,gBAAgB;IAD5B,SAAS,CAAC,gBAAgB,CAAC;GACf,gBAAgB,CAoB5B"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DecodeOptions, JwtOptions, JwtPayload, JwtSecretService, JwtService, Secret, SignOptions, VerifyOptions } from './jwt-protocol.js';
|
|
2
|
+
export declare class JwtServiceImpl implements JwtService {
|
|
3
|
+
protected readonly jwtOptions?: JwtOptions;
|
|
4
|
+
protected readonly jwtSecretService: JwtSecretService;
|
|
5
|
+
sign(payload: string | object | Buffer, options?: SignOptions, privateKey?: Secret): Promise<string>;
|
|
6
|
+
verify<T extends object = any>(token: string, options?: VerifyOptions, publicKey?: string | Buffer): Promise<T>;
|
|
7
|
+
decode(token: string, options?: DecodeOptions): Promise<JwtPayload | string | undefined>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { Autowired, Component, Value } from '@celljs/core';
|
|
11
|
+
import { JwtSecretService, JwtService } from './jwt-protocol.js';
|
|
12
|
+
import jwt from 'jsonwebtoken';
|
|
13
|
+
let JwtServiceImpl = class JwtServiceImpl {
|
|
14
|
+
async sign(payload, options, privateKey) {
|
|
15
|
+
var _a;
|
|
16
|
+
const mergedOptions = { ...(_a = this.jwtOptions) === null || _a === void 0 ? void 0 : _a.signOptions, ...options };
|
|
17
|
+
const secret = privateKey !== null && privateKey !== void 0 ? privateKey : await this.jwtSecretService.getPrivateKey();
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
jwt.sign(payload, secret, mergedOptions, (err, token) => {
|
|
20
|
+
if (err) {
|
|
21
|
+
reject(err);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
resolve(token || '');
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
async verify(token, options, publicKey) {
|
|
30
|
+
var _a;
|
|
31
|
+
const mergedOptions = { ...(_a = this.jwtOptions) === null || _a === void 0 ? void 0 : _a.verifyOptions, ...options };
|
|
32
|
+
const secret = publicKey !== null && publicKey !== void 0 ? publicKey : await this.jwtSecretService.getPublicKey();
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
jwt.verify(token, secret, mergedOptions, (err, decoded) => {
|
|
35
|
+
if (err) {
|
|
36
|
+
reject(err);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
resolve(decoded);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async decode(token, options) {
|
|
45
|
+
const decoded = jwt.decode(token, options);
|
|
46
|
+
if (!decoded) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return decoded;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
__decorate([
|
|
53
|
+
Value('cell.jwt'),
|
|
54
|
+
__metadata("design:type", Object)
|
|
55
|
+
], JwtServiceImpl.prototype, "jwtOptions", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
Autowired(JwtSecretService),
|
|
58
|
+
__metadata("design:type", Object)
|
|
59
|
+
], JwtServiceImpl.prototype, "jwtSecretService", void 0);
|
|
60
|
+
JwtServiceImpl = __decorate([
|
|
61
|
+
Component(JwtService)
|
|
62
|
+
], JwtServiceImpl);
|
|
63
|
+
export { JwtServiceImpl };
|
|
64
|
+
//# sourceMappingURL=jwt-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-service.js","sourceRoot":"","sources":["../../src/node/jwt-service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAyC,gBAAgB,EAAE,UAAU,EAAsC,MAA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BACN,MAAM,CAAC,GAAG,CAAC,CAAC;gBAChB,CAAC;qBAAM,CAAC;oBACJ,OAAO,CAAC,OAAY,CAAC,CAAC;gBAC1B,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,OAAuB;QAC/C,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC3C,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;CAEJ,CAAA;AAzCsB;IADlB,KAAK,CAAC,UAAU,CAAC;;kDACyB;AAGxB;IADlB,SAAS,CAAC,gBAAgB,CAAC;;wDAC0B;AAN7C,cAAc;IAD1B,SAAS,CAAC,UAAU,CAAC;GACT,cAAc,CA4C1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,SAAS,CAAC;AAEjB,eAAe,QAAQ,EAAE,CAAC"}
|
package/esm/package.json
ADDED
package/lib/node/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/node/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,qBAAa,sBAAuB,SAAQ,WAAW
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/node/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,qBAAa,sBAAuB,SAAQ,WAAW;IACnD,cAEC;CACJ;AAED,qBAAa,uBAAwB,SAAQ,WAAW;IACpD,cAEC;CACJ"}
|
package/lib/node/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/node/errors.ts"],"names":[],"mappings":";;;AAAA,uCAA2C;AAE3C,
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/node/errors.ts"],"names":[],"mappings":";;;AAAA,uCAA2C;AAE3C,4BAAoC,SAAQ,kBAAW;IACnD;QACI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAClC,CAAC;CACJ;;AAED,6BAAqC,SAAQ,kBAAW;IACpD;QACI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IACnC,CAAC;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt-secret-service.d.ts","sourceRoot":"","sources":["../../src/node/jwt-secret-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEtE,qBACa,gBAAiB,YAAW,gBAAgB;IAGrD,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IAErC,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"jwt-secret-service.d.ts","sourceRoot":"","sources":["../../src/node/jwt-secret-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAEtE,qBACa,gBAAiB,YAAW,gBAAgB;IAGrD,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IAErC,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,CAM7C;IAEK,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAMrC;CACJ"}
|
|
@@ -15,16 +15,18 @@ const errors_1 = require("./errors");
|
|
|
15
15
|
const jwt_protocol_1 = require("./jwt-protocol");
|
|
16
16
|
let jwtSecretService = class jwtSecretService {
|
|
17
17
|
async getPublicKey() {
|
|
18
|
-
var _a, _b
|
|
19
|
-
|
|
18
|
+
var _a, _b;
|
|
19
|
+
var _c;
|
|
20
|
+
const secret = (_c = (_a = this.jwtOptions) === null || _a === void 0 ? void 0 : _a.publicKey) !== null && _c !== void 0 ? _c : (_b = this.jwtOptions) === null || _b === void 0 ? void 0 : _b.secret;
|
|
20
21
|
if (secret) {
|
|
21
22
|
return secret;
|
|
22
23
|
}
|
|
23
24
|
throw new errors_1.PublicKeyNotFoundError();
|
|
24
25
|
}
|
|
25
26
|
async getPrivateKey() {
|
|
26
|
-
var _a, _b
|
|
27
|
-
|
|
27
|
+
var _a, _b;
|
|
28
|
+
var _c;
|
|
29
|
+
const secret = (_c = (_a = this.jwtOptions) === null || _a === void 0 ? void 0 : _a.privateKey) !== null && _c !== void 0 ? _c : (_b = this.jwtOptions) === null || _b === void 0 ? void 0 : _b.secret;
|
|
28
30
|
if (secret) {
|
|
29
31
|
return secret;
|
|
30
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt-secret-service.js","sourceRoot":"","sources":["../../src/node/jwt-secret-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAgD;AAChD,qCAA2E;AAC3E,iDAAsE;AAG/D,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAKzB,KAAK,CAAC,YAAY
|
|
1
|
+
{"version":3,"file":"jwt-secret-service.js","sourceRoot":"","sources":["../../src/node/jwt-secret-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAgD;AAChD,qCAA2E;AAC3E,iDAAsE;AAG/D,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAKzB,KAAK,CAAC,YAAY;;;QACd,MAAM,MAAM,SAAG,MAAA,IAAI,CAAC,UAAU,0CAAE,SAAS,mCAAI,MAAA,IAAI,CAAC,UAAU,0CAAE,MAAM,CAAC;QACrE,IAAI,MAAM,EAAE,CAAC;YACT,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,MAAM,IAAI,+BAAsB,EAAE,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,aAAa;;;QACf,MAAM,MAAM,SAAG,MAAA,IAAI,CAAC,UAAU,0CAAE,UAAU,mCAAI,MAAA,IAAI,CAAC,UAAU,0CAAE,MAAM,CAAC;QACtE,IAAI,MAAM,EAAE,CAAC;YACT,OAAO,MAAM,CAAC;QAClB,CAAC;QACD,MAAM,IAAI,gCAAuB,EAAE,CAAC;IACxC,CAAC;CACJ,CAAA;;AAjBsB;IADlB,IAAA,YAAK,EAAC,UAAU,CAAC;;oDACyB;2BAHlC,gBAAgB;IAD5B,IAAA,gBAAS,EAAC,+BAAgB,CAAC;GACf,gBAAgB,CAoB5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt-service.d.ts","sourceRoot":"","sources":["../../src/node/jwt-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGzI,qBACa,cAAe,YAAW,UAAU;IAG7C,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IAG3C,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAEhD,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"jwt-service.d.ts","sourceRoot":"","sources":["../../src/node/jwt-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGzI,qBACa,cAAe,YAAW,UAAU;IAG7C,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC;IAG3C,SAAS,CAAC,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAEhD,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAYzG;IAEK,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAYpH;IAEK,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC,CAM7F;CAEJ"}
|
package/lib/node/jwt-service.js
CHANGED
|
@@ -8,18 +8,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.JwtServiceImpl = void 0;
|
|
13
16
|
const core_1 = require("@celljs/core");
|
|
14
17
|
const jwt_protocol_1 = require("./jwt-protocol");
|
|
15
|
-
const
|
|
18
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
16
19
|
let JwtServiceImpl = class JwtServiceImpl {
|
|
17
20
|
async sign(payload, options, privateKey) {
|
|
18
21
|
var _a;
|
|
19
22
|
const mergedOptions = { ...(_a = this.jwtOptions) === null || _a === void 0 ? void 0 : _a.signOptions, ...options };
|
|
20
23
|
const secret = privateKey !== null && privateKey !== void 0 ? privateKey : await this.jwtSecretService.getPrivateKey();
|
|
21
24
|
return new Promise((resolve, reject) => {
|
|
22
|
-
|
|
25
|
+
jsonwebtoken_1.default.sign(payload, secret, mergedOptions, (err, token) => {
|
|
23
26
|
if (err) {
|
|
24
27
|
reject(err);
|
|
25
28
|
}
|
|
@@ -34,7 +37,7 @@ let JwtServiceImpl = class JwtServiceImpl {
|
|
|
34
37
|
const mergedOptions = { ...(_a = this.jwtOptions) === null || _a === void 0 ? void 0 : _a.verifyOptions, ...options };
|
|
35
38
|
const secret = publicKey !== null && publicKey !== void 0 ? publicKey : await this.jwtSecretService.getPublicKey();
|
|
36
39
|
return new Promise((resolve, reject) => {
|
|
37
|
-
|
|
40
|
+
jsonwebtoken_1.default.verify(token, secret, mergedOptions, (err, decoded) => {
|
|
38
41
|
if (err) {
|
|
39
42
|
reject(err);
|
|
40
43
|
}
|
|
@@ -45,7 +48,7 @@ let JwtServiceImpl = class JwtServiceImpl {
|
|
|
45
48
|
});
|
|
46
49
|
}
|
|
47
50
|
async decode(token, options) {
|
|
48
|
-
const decoded =
|
|
51
|
+
const decoded = jsonwebtoken_1.default.decode(token, options);
|
|
49
52
|
if (!decoded) {
|
|
50
53
|
return undefined;
|
|
51
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt-service.js","sourceRoot":"","sources":["../../src/node/jwt-service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jwt-service.js","sourceRoot":"","sources":["../../src/node/jwt-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,uCAA2D;AAC3D,iDAAyI;AACzI,gEAA+B;AAGxB,IAAM,cAAc,GAApB,MAAM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OAAY,CAAC,CAAC;gBAC1B,CAAC;YACL,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,OAAuB;QAC/C,MAAM,OAAO,GAAG,sBAAG,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC3C,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,OAAO,SAAS,CAAC;QACrB,CAAC;QACD,OAAO,OAAO,CAAC;IACnB,CAAC;CAEJ,CAAA;;AAzCsB;IADlB,IAAA,YAAK,EAAC,UAAU,CAAC;;kDACyB;AAGxB;IADlB,IAAA,gBAAS,EAAC,+BAAgB,CAAC;;wDAC0B;yBAN7C,cAAc;IAD1B,IAAA,gBAAS,EAAC,yBAAU,CAAC;GACT,cAAc,CA4C1B"}
|
package/lib/node/module.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,CAAC
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,CAAC"}
|
package/lib/node/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,mBAAiB;
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,mBAAiB;kBAEF,IAAA,eAAQ,GAAE"}
|
package/lib/package.spec.d.ts
CHANGED
package/lib/package.spec.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const bun_test_1 = require("bun:test");
|
|
4
|
+
(0, bun_test_1.describe)('jwt package', () => {
|
|
5
|
+
(0, bun_test_1.it)('support code coverage statistics', () => { });
|
|
3
6
|
});
|
|
4
7
|
//# sourceMappingURL=package.spec.js.map
|
package/lib/package.spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"package.spec.js","sourceRoot":"","sources":["../src/package.spec.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,IAAA,mBAAQ,EAAC,aAAa,EAAE,GAAG,EAAE;IAEzB,IAAA,aAAE,EAAC,kCAAkC,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACrD,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/jwt",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cell-component"
|
|
@@ -18,27 +18,49 @@
|
|
|
18
18
|
"typings": "lib/node/index.d.ts",
|
|
19
19
|
"files": [
|
|
20
20
|
"lib",
|
|
21
|
+
"esm",
|
|
21
22
|
"src",
|
|
22
23
|
"cell.yml"
|
|
23
24
|
],
|
|
24
25
|
"scripts": {
|
|
25
|
-
"build": "
|
|
26
|
-
"clean": "
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"watch": "cell-component watch"
|
|
26
|
+
"build": "tsc -b && bun ../../scripts/build-esm.ts",
|
|
27
|
+
"clean": "rm -rf lib esm *.tsbuildinfo",
|
|
28
|
+
"test": "bun test --preload reflect-metadata ./lib",
|
|
29
|
+
"watch": "tsc -b -w --preserveWatchOutput"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@celljs/core": "3.
|
|
32
|
+
"@celljs/core": "3.9.0",
|
|
33
33
|
"jsonwebtoken": "^9.0.0",
|
|
34
34
|
"tslib": "^2.8.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@celljs/component": "3.7.8",
|
|
38
37
|
"@types/jsonwebtoken": "^8.5.8"
|
|
39
38
|
},
|
|
40
39
|
"publishConfig": {
|
|
41
40
|
"access": "public"
|
|
42
41
|
},
|
|
43
|
-
"
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"webpack": "./lib/node/index.js",
|
|
45
|
+
"import": "./esm/node/index.js",
|
|
46
|
+
"default": "./lib/node/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./package.json": "./package.json",
|
|
49
|
+
"./lib/node": {
|
|
50
|
+
"webpack": "./lib/node/index.js",
|
|
51
|
+
"import": "./esm/node/index.js",
|
|
52
|
+
"default": "./lib/node/index.js"
|
|
53
|
+
},
|
|
54
|
+
"./lib/*.js": {
|
|
55
|
+
"webpack": "./lib/*.js",
|
|
56
|
+
"import": "./esm/*.js",
|
|
57
|
+
"default": "./lib/*.js"
|
|
58
|
+
},
|
|
59
|
+
"./lib/*": {
|
|
60
|
+
"webpack": "./lib/*.js",
|
|
61
|
+
"import": "./esm/*.js",
|
|
62
|
+
"default": "./lib/*.js"
|
|
63
|
+
},
|
|
64
|
+
"./*": "./*"
|
|
65
|
+
}
|
|
44
66
|
}
|
package/src/node/jwt-service.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Autowired, Component, Value } from '@celljs/core';
|
|
2
2
|
import { DecodeOptions, JwtOptions, JwtPayload, JwtSecretService, JwtService, Secret, SignOptions, VerifyOptions } from './jwt-protocol';
|
|
3
|
-
import
|
|
3
|
+
import jwt from 'jsonwebtoken';
|
|
4
4
|
|
|
5
5
|
@Component(JwtService)
|
|
6
6
|
export class JwtServiceImpl implements JwtService {
|
package/src/package.spec.ts
CHANGED
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2019 Cellbang
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|