@creator.co/wapi 1.2.1-beta3 → 1.2.1-beta5
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/package.json +1 -1
- package/dist/src/Crypto/JWT.d.ts +2 -2
- package/dist/src/Crypto/JWT.js +21 -66
- package/dist/src/Crypto/JWT.js.map +1 -1
- package/package.json +1 -1
- package/src/Crypto/JWT.ts +3 -3
package/dist/package.json
CHANGED
package/dist/src/Crypto/JWT.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export default class JWT {
|
|
|
10
10
|
private readonly tokenSecret;
|
|
11
11
|
private readonly defaultExpiration;
|
|
12
12
|
constructor(tokenSecret: string, defaultExpiration?: string);
|
|
13
|
-
createToken(data: object, expiration?: string, overrideToken?: string, opts?: any):
|
|
14
|
-
validateToken(token: string):
|
|
13
|
+
createToken(data: object, expiration?: string, overrideToken?: string, opts?: any): string;
|
|
14
|
+
validateToken(token: string): JWTValidationResponse;
|
|
15
15
|
}
|
|
16
16
|
export {};
|
package/dist/src/Crypto/JWT.js
CHANGED
|
@@ -10,42 +10,6 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
14
|
var jwt = require("jsonwebtoken");
|
|
51
15
|
var JWT = /** @class */ (function () {
|
|
@@ -55,38 +19,29 @@ var JWT = /** @class */ (function () {
|
|
|
55
19
|
}
|
|
56
20
|
//
|
|
57
21
|
JWT.prototype.createToken = function (data, expiration, overrideToken, opts) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return __generator(this, function (_a) {
|
|
61
|
-
exp = expiration || this.defaultExpiration;
|
|
62
|
-
return [2 /*return*/, jwt.sign(data, overrideToken || this.tokenSecret, exp ? __assign({ expiresIn: exp }, (opts || {})) : opts || {})];
|
|
63
|
-
});
|
|
64
|
-
});
|
|
22
|
+
var exp = expiration || this.defaultExpiration;
|
|
23
|
+
return jwt.sign(data, overrideToken || this.tokenSecret, exp ? __assign({ expiresIn: exp }, (opts || {})) : opts || {});
|
|
65
24
|
};
|
|
66
25
|
JWT.prototype.validateToken = function (token) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
return [2 /*return*/, { isValid: false }];
|
|
88
|
-
});
|
|
89
|
-
});
|
|
26
|
+
try {
|
|
27
|
+
// Check if is valid
|
|
28
|
+
var isValid = jwt.verify(token, this.tokenSecret);
|
|
29
|
+
if (!isValid)
|
|
30
|
+
throw new Error("Issue with token validation!");
|
|
31
|
+
else {
|
|
32
|
+
var payload = jwt.decode(token, { json: true });
|
|
33
|
+
if (payload)
|
|
34
|
+
return { isValid: true, decodedToken: payload };
|
|
35
|
+
else
|
|
36
|
+
throw new Error("Issue while decoding token!");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
console.error(err);
|
|
41
|
+
if (err instanceof jwt.TokenExpiredError)
|
|
42
|
+
return { isValid: false, isExpired: true };
|
|
43
|
+
}
|
|
44
|
+
return { isValid: false };
|
|
90
45
|
};
|
|
91
46
|
return JWT;
|
|
92
47
|
}());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JWT.js","sourceRoot":"","sources":["../../../src/Crypto/JWT.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"JWT.js","sourceRoot":"","sources":["../../../src/Crypto/JWT.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,kCAAmC;AASnC;IAGE,aAAY,WAAmB,EAAE,iBAA0B;QACzD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAA;IAC5C,CAAC;IACD,EAAE;IACF,yBAAW,GAAX,UACE,IAAY,EACZ,UAAmB,EACnB,aAAsB,EACtB,IAAU;QAEV,IAAM,GAAG,GAAG,UAAU,IAAI,IAAI,CAAC,iBAAiB,CAAA;QAChD,OAAO,GAAG,CAAC,IAAI,CACb,IAAI,EACJ,aAAa,IAAI,IAAI,CAAC,WAAW,EACjC,GAAG,CAAC,CAAC,YAAG,SAAS,EAAE,GAAG,IAAK,CAAC,IAAI,IAAI,EAAE,CAAC,EAAG,CAAC,CAAC,IAAI,IAAI,EAAE,CACvD,CAAA;IACH,CAAC;IACD,2BAAa,GAAb,UAAc,KAAa;QACzB,IAAI;YACF,oBAAoB;YACpB,IAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;YACnD,IAAI,CAAC,OAAO;gBAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;iBACxD;gBACH,IAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAA;gBACjD,IAAI,OAAO;oBAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,CAAA;;oBACvD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;aACpD;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAClB,IAAI,GAAG,YAAY,GAAG,CAAC,iBAAiB;gBACtC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAA;SAC7C;QACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA;IAC3B,CAAC;IACH,UAAC;AAAD,CAAC,AAtCD,IAsCC"}
|
package/package.json
CHANGED
package/src/Crypto/JWT.ts
CHANGED
|
@@ -15,12 +15,12 @@ export default class JWT {
|
|
|
15
15
|
this.defaultExpiration = defaultExpiration
|
|
16
16
|
}
|
|
17
17
|
//
|
|
18
|
-
|
|
18
|
+
createToken(
|
|
19
19
|
data: object,
|
|
20
20
|
expiration?: string,
|
|
21
21
|
overrideToken?: string,
|
|
22
22
|
opts?: any,
|
|
23
|
-
):
|
|
23
|
+
): string {
|
|
24
24
|
const exp = expiration || this.defaultExpiration
|
|
25
25
|
return jwt.sign(
|
|
26
26
|
data,
|
|
@@ -28,7 +28,7 @@ export default class JWT {
|
|
|
28
28
|
exp ? { expiresIn: exp, ...(opts || {}) } : opts || {},
|
|
29
29
|
)
|
|
30
30
|
}
|
|
31
|
-
|
|
31
|
+
validateToken(token: string): JWTValidationResponse {
|
|
32
32
|
try {
|
|
33
33
|
// Check if is valid
|
|
34
34
|
const isValid = jwt.verify(token, this.tokenSecret)
|