@puca/puca-core 3.10.0 → 3.11.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.
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.decode = void 0;
4
- const _ = require("lodash");
5
- const jsonwebtoken_1 = require("jsonwebtoken");
6
- const __1 = require("..");
7
- const services_1 = require("../../core/services");
8
- const services_2 = require("../../orm/services");
9
- class UserManager {
10
- constructor() {
11
- this.users = {};
12
- }
13
- async findUser(companyKey, pucaPid) {
14
- if (!this.users[companyKey]) {
15
- this.users[companyKey] = {};
16
- const userRepository = services_2.repositoryFactory.getCacheInstance({
17
- companyKey,
18
- tableName: 'puca_base_api_system_user'
19
- });
20
- const users = await userRepository.findAll();
21
- users.forEach(user => this.users[companyKey][user.puca_pid] = user);
22
- userRepository.onChange(args => {
23
- const user = args.new || args.old;
24
- const update = () => {
25
- this.users[companyKey][user.puca_pid] = user;
26
- };
27
- if (!user.login_id) {
28
- this.timeout = setTimeout(update, 10000);
29
- }
30
- else {
31
- if (this.timeout) {
32
- clearTimeout(this.timeout);
33
- }
34
- update();
35
- }
36
- });
37
- }
38
- while (_.isEqual(this.users[companyKey], {})) {
39
- await new Promise(resolve => setTimeout(resolve, 100));
40
- }
41
- return this.users[companyKey][pucaPid];
42
- }
43
- }
44
- const userManager = new UserManager();
45
- const decode = async (token) => {
46
- const pathPublicKey = (await services_1.envConfigService.getEnvByName('PATH_PUBLIC_KEY')) || './key.pub';
47
- const publicKey = await __1.fileSystemService.readStringFile(pathPublicKey, {
48
- throwErrors: false,
49
- });
50
- if (!publicKey) {
51
- throw new Error('public key not found');
52
- }
53
- const decoded = jsonwebtoken_1.verify(token, publicKey, {
54
- algorithms: ['RS256'],
55
- });
56
- if (!decoded) {
57
- return null;
58
- }
59
- if ((decoded.version || 0) < 1) {
60
- return null;
61
- }
62
- const userCache = await userManager.findUser(decoded.company.companyKey, decoded.user.puca_pid);
63
- if (userCache.login_id !== decoded.loginId) {
64
- return null;
65
- }
66
- const moduleConfig = await services_1.moduleConfigService.getModuleConfig();
67
- decoded.user.token = token;
68
- decoded.user.idRequest = __1.uuidService.v4();
69
- decoded.user.moduleName = moduleConfig.name;
70
- decoded.user.moduleVersion = moduleConfig.version;
71
- return decoded;
72
- };
73
- exports.decode = decode;
74
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/jsonwebtoken/index.ts"],"names":[],"mappings":";;;AAAA,4BAA6B;AAC7B,+CAAsC;AAGtC,0BAAoD;AACpD,kDAA4E;AAC5E,iDAAuD;AAGvD,MAAM,WAAW;IAAjB;QACmB,UAAK,GAA0D,EAAE,CAAA;IAkCpF,CAAC;IA/BC,KAAK,CAAC,QAAQ,CAAC,UAAkB,EAAE,OAAe;QAChD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE;YAC3B,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,CAAA;YAC3B,MAAM,cAAc,GAAG,4BAAiB,CAAC,gBAAgB,CAAO;gBAC9D,UAAU;gBACV,SAAS,EAAE,2BAA2B;aACvC,CAAC,CAAA;YACF,MAAM,KAAK,GAAG,MAAM,cAAc,CAAC,OAAO,EAAE,CAAA;YAC5C,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAA;YACnE,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE;gBAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAA;gBACjC,MAAM,MAAM,GAAG,GAAG,EAAE;oBAClB,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC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