@verdaccio/signature 7.0.0-next.0 → 7.0.0-next.1
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/CHANGELOG.md +10 -0
- package/build/jwt-token.d.ts +4 -2
- package/build/jwt-token.js +7 -4
- package/build/jwt-token.js.map +1 -1
- package/package.json +4 -4
- package/src/jwt-token.ts +15 -11
package/CHANGELOG.md
CHANGED
package/build/jwt-token.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SignOptions } from 'jsonwebtoken';
|
|
2
|
+
import { RemoteUser } from '@verdaccio/types';
|
|
3
|
+
export type SignOptionsSignature = Pick<SignOptions, 'algorithm' | 'expiresIn' | 'notBefore'>;
|
|
2
4
|
/**
|
|
3
5
|
* Sign the payload and return JWT
|
|
4
6
|
* https://github.com/auth0/node-jsonwebtoken#jwtsignpayload-secretorprivatekey-options-callback
|
|
@@ -6,5 +8,5 @@ import { JWTSignOptions, RemoteUser } from '@verdaccio/types';
|
|
|
6
8
|
* @param secretOrPrivateKey
|
|
7
9
|
* @param options
|
|
8
10
|
*/
|
|
9
|
-
export declare function signPayload(payload: RemoteUser, secretOrPrivateKey: string, options?:
|
|
11
|
+
export declare function signPayload(payload: RemoteUser, secretOrPrivateKey: string, options?: SignOptionsSignature): Promise<string>;
|
|
10
12
|
export declare function verifyPayload(token: string, secretOrPrivateKey: string): RemoteUser;
|
package/build/jwt-token.js
CHANGED
|
@@ -19,17 +19,20 @@ const debug = (0, _debug.default)('verdaccio:auth:token:jwt');
|
|
|
19
19
|
async function signPayload(payload, secretOrPrivateKey, options = {}) {
|
|
20
20
|
return new Promise(function (resolve, reject) {
|
|
21
21
|
debug('sign jwt token');
|
|
22
|
-
|
|
22
|
+
_jsonwebtoken.default.sign(payload, secretOrPrivateKey,
|
|
23
23
|
// FIXME: upgrade to the latest library and types
|
|
24
|
-
// @ts-ignore
|
|
25
24
|
{
|
|
26
25
|
// 1 === 1ms (one millisecond)
|
|
27
26
|
notBefore: '1',
|
|
28
27
|
// Make sure the time will not rollback :)
|
|
29
28
|
...options
|
|
30
29
|
}, (error, token) => {
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
if (error) {
|
|
31
|
+
debug('error on sign jwt token %s', error.message);
|
|
32
|
+
return reject(error);
|
|
33
|
+
}
|
|
34
|
+
debug('signed jwt token successfully');
|
|
35
|
+
return resolve(token);
|
|
33
36
|
});
|
|
34
37
|
});
|
|
35
38
|
}
|
package/build/jwt-token.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt-token.js","names":["_debug","_interopRequireDefault","require","_jsonwebtoken","obj","__esModule","default","debug","buildDebug","signPayload","payload","secretOrPrivateKey","options","Promise","resolve","reject","jwt","sign","notBefore","error","token","verifyPayload","verify"],"sources":["../src/jwt-token.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport jwt from 'jsonwebtoken';\n\nimport {
|
|
1
|
+
{"version":3,"file":"jwt-token.js","names":["_debug","_interopRequireDefault","require","_jsonwebtoken","obj","__esModule","default","debug","buildDebug","signPayload","payload","secretOrPrivateKey","options","Promise","resolve","reject","jwt","sign","notBefore","error","token","message","verifyPayload","verify"],"sources":["../src/jwt-token.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport jwt, { SignOptions } from 'jsonwebtoken';\n\nimport { RemoteUser } from '@verdaccio/types';\n\nexport type SignOptionsSignature = Pick<SignOptions, 'algorithm' | 'expiresIn' | 'notBefore'>;\n\nconst debug = buildDebug('verdaccio:auth:token:jwt');\n/**\n * Sign the payload and return JWT\n * https://github.com/auth0/node-jsonwebtoken#jwtsignpayload-secretorprivatekey-options-callback\n * @param payload\n * @param secretOrPrivateKey\n * @param options\n */\nexport async function signPayload(\n payload: RemoteUser,\n secretOrPrivateKey: string,\n options: SignOptionsSignature = {}\n): Promise<string> {\n return new Promise(function (resolve, reject) {\n debug('sign jwt token');\n jwt.sign(\n payload,\n secretOrPrivateKey, // FIXME: upgrade to the latest library and types\n {\n // 1 === 1ms (one millisecond)\n notBefore: '1', // Make sure the time will not rollback :)\n ...options,\n },\n (error, token) => {\n if (error) {\n debug('error on sign jwt token %s', error.message);\n return reject(error);\n }\n debug('signed jwt token successfully');\n return resolve(token as string);\n }\n );\n });\n}\n\nexport function verifyPayload(token: string, secretOrPrivateKey: string): RemoteUser {\n debug('verify jwt token');\n return jwt.verify(token, secretOrPrivateKey) as RemoteUser;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,aAAA,GAAAF,sBAAA,CAAAC,OAAA;AAAgD,SAAAD,uBAAAG,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAMhD,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,0BAA0B,CAAC;AACpD;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeC,WAAWA,CAC/BC,OAAmB,EACnBC,kBAA0B,EAC1BC,OAA6B,GAAG,CAAC,CAAC,EACjB;EACjB,OAAO,IAAIC,OAAO,CAAC,UAAUC,OAAO,EAAEC,MAAM,EAAE;IAC5CR,KAAK,CAAC,gBAAgB,CAAC;IACvBS,qBAAG,CAACC,IAAI,CACNP,OAAO,EACPC,kBAAkB;IAAE;IACpB;MACE;MACAO,SAAS,EAAE,GAAG;MAAE;MAChB,GAAGN;IACL,CAAC,EACD,CAACO,KAAK,EAAEC,KAAK,KAAK;MAChB,IAAID,KAAK,EAAE;QACTZ,KAAK,CAAC,4BAA4B,EAAEY,KAAK,CAACE,OAAO,CAAC;QAClD,OAAON,MAAM,CAACI,KAAK,CAAC;MACtB;MACAZ,KAAK,CAAC,+BAA+B,CAAC;MACtC,OAAOO,OAAO,CAACM,KAAe,CAAC;IACjC,CACF,CAAC;EACH,CAAC,CAAC;AACJ;AAEO,SAASE,aAAaA,CAACF,KAAa,EAAET,kBAA0B,EAAc;EACnFJ,KAAK,CAAC,kBAAkB,CAAC;EACzB,OAAOS,qBAAG,CAACO,MAAM,CAACH,KAAK,EAAET,kBAAkB,CAAC;AAC9C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/signature",
|
|
3
|
-
"version": "7.0.0-next.
|
|
3
|
+
"version": "7.0.0-next.1",
|
|
4
4
|
"description": "verdaccio signature utils",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"node": ">=12"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"jsonwebtoken": "9.0.
|
|
32
|
+
"jsonwebtoken": "9.0.2",
|
|
33
33
|
"debug": "4.3.4",
|
|
34
34
|
"lodash": "4.17.21"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@verdaccio/config": "7.0.0-next.
|
|
38
|
-
"@verdaccio/types": "12.0.0-next.
|
|
37
|
+
"@verdaccio/config": "7.0.0-next.3",
|
|
38
|
+
"@verdaccio/types": "12.0.0-next.1"
|
|
39
39
|
},
|
|
40
40
|
"funding": {
|
|
41
41
|
"type": "opencollective",
|
package/src/jwt-token.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import buildDebug from 'debug';
|
|
2
|
-
import jwt from 'jsonwebtoken';
|
|
2
|
+
import jwt, { SignOptions } from 'jsonwebtoken';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { RemoteUser } from '@verdaccio/types';
|
|
5
|
+
|
|
6
|
+
export type SignOptionsSignature = Pick<SignOptions, 'algorithm' | 'expiresIn' | 'notBefore'>;
|
|
5
7
|
|
|
6
8
|
const debug = buildDebug('verdaccio:auth:token:jwt');
|
|
7
9
|
/**
|
|
@@ -14,23 +16,25 @@ const debug = buildDebug('verdaccio:auth:token:jwt');
|
|
|
14
16
|
export async function signPayload(
|
|
15
17
|
payload: RemoteUser,
|
|
16
18
|
secretOrPrivateKey: string,
|
|
17
|
-
options:
|
|
19
|
+
options: SignOptionsSignature = {}
|
|
18
20
|
): Promise<string> {
|
|
19
|
-
return new Promise(function (resolve, reject)
|
|
21
|
+
return new Promise(function (resolve, reject) {
|
|
20
22
|
debug('sign jwt token');
|
|
21
|
-
|
|
23
|
+
jwt.sign(
|
|
22
24
|
payload,
|
|
23
|
-
secretOrPrivateKey,
|
|
24
|
-
// FIXME: upgrade to the latest library and types
|
|
25
|
-
// @ts-ignore
|
|
25
|
+
secretOrPrivateKey, // FIXME: upgrade to the latest library and types
|
|
26
26
|
{
|
|
27
27
|
// 1 === 1ms (one millisecond)
|
|
28
28
|
notBefore: '1', // Make sure the time will not rollback :)
|
|
29
29
|
...options,
|
|
30
30
|
},
|
|
31
|
-
(error, token
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
(error, token) => {
|
|
32
|
+
if (error) {
|
|
33
|
+
debug('error on sign jwt token %s', error.message);
|
|
34
|
+
return reject(error);
|
|
35
|
+
}
|
|
36
|
+
debug('signed jwt token successfully');
|
|
37
|
+
return resolve(token as string);
|
|
34
38
|
}
|
|
35
39
|
);
|
|
36
40
|
});
|