ismx-nexo-node-app 0.4.155 → 0.4.158
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/js/business/utils/ObjectUtils.js +3 -0
- package/dist/js/repository/utils/JwtUtils.js +26 -0
- package/dist/types/business/utils/ObjectUtils.d.ts +1 -0
- package/dist/types/repository/utils/JwtUtils.d.ts +25 -0
- package/package.json +1 -1
- package/src/main/node/business/utils/ObjectUtils.ts +4 -0
- package/src/main/node/repository/RepositoryDatabasePostgres.ts +1 -0
- package/src/main/node/repository/utils/JwtUtils.ts +52 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
class ObjectUtils {
|
|
4
|
+
static camelToSnake(str) {
|
|
5
|
+
return str.replace(/([A-Z])/g, '_$1').toLowerCase();
|
|
6
|
+
}
|
|
4
7
|
static snakeToCamel(obj) {
|
|
5
8
|
if (typeof obj === 'string')
|
|
6
9
|
return obj.toLowerCase().replace(/([-_][a-z])/g, group => group.toUpperCase().replace('-', '').replace('_', ''));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const buffer_1 = require("buffer");
|
|
4
|
+
class JwtUtils {
|
|
5
|
+
static decodeBase64Url(base64Url) {
|
|
6
|
+
// Reemplaza caracteres de base64url
|
|
7
|
+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
8
|
+
// Decodifica en UTF-8
|
|
9
|
+
return decodeURIComponent(buffer_1.Buffer.from(base64, 'base64').toString("utf-8")
|
|
10
|
+
.split("")
|
|
11
|
+
.map(c => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2))
|
|
12
|
+
.join(""));
|
|
13
|
+
}
|
|
14
|
+
static decode(jwt) {
|
|
15
|
+
const [headerB64, payloadB64, signature] = jwt.split(".");
|
|
16
|
+
const header = JSON.parse(JwtUtils.decodeBase64Url(headerB64));
|
|
17
|
+
const payload = JSON.parse(JwtUtils.decodeBase64Url(payloadB64));
|
|
18
|
+
// Si tiene campos de tiempo, conviértelos a fecha legible
|
|
19
|
+
if (payload.iat)
|
|
20
|
+
payload.iat_date = new Date(payload.iat * 1000).toISOString();
|
|
21
|
+
if (payload.exp)
|
|
22
|
+
payload.exp_date = new Date(payload.exp * 1000).toISOString();
|
|
23
|
+
return { header, payload, signature };
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.default = JwtUtils;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default class JwtUtils {
|
|
2
|
+
private static decodeBase64Url;
|
|
3
|
+
static decode(jwt: string): Jwt;
|
|
4
|
+
}
|
|
5
|
+
export interface JwtHeader {
|
|
6
|
+
alg: string;
|
|
7
|
+
typ: string;
|
|
8
|
+
kid?: string;
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
export interface JwtPayload {
|
|
12
|
+
exp?: number;
|
|
13
|
+
iat?: number;
|
|
14
|
+
nbf?: number;
|
|
15
|
+
iss?: string;
|
|
16
|
+
aud?: string | string[];
|
|
17
|
+
sub?: string;
|
|
18
|
+
jti?: string;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}
|
|
21
|
+
export interface Jwt {
|
|
22
|
+
header: JwtHeader;
|
|
23
|
+
payload: JwtPayload;
|
|
24
|
+
signature: string;
|
|
25
|
+
}
|
package/package.json
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export default class ObjectUtils {
|
|
2
2
|
|
|
3
|
+
static camelToSnake(str: string) {
|
|
4
|
+
return str.replace(/([A-Z])/g, '_$1').toLowerCase();
|
|
5
|
+
}
|
|
6
|
+
|
|
3
7
|
static snakeToCamel(obj: any): any {
|
|
4
8
|
if (typeof obj === 'string')
|
|
5
9
|
return obj.toLowerCase().replace(/([-_][a-z])/g, group =>
|
|
@@ -213,6 +213,7 @@ export default class RepositoryDatabasePostgres extends RepositoryDatabase
|
|
|
213
213
|
let [ table, schema, column ] = [ this.tables[tableName], this.tables[tableName][0].schema, PostgresUtils.camelToSnake(select) ];
|
|
214
214
|
if (PostgresUtils.isReservedWord(column)) column = `"${column}"`;
|
|
215
215
|
|
|
216
|
+
|
|
216
217
|
if (!PostgresUtils.columns(table).includes(column)) throw new Error(`column ${column} does not exist in table ${tableName}`);
|
|
217
218
|
let { where, values } = this.toWhere(tableName, filters);
|
|
218
219
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
|
|
3
|
+
export default class JwtUtils
|
|
4
|
+
{
|
|
5
|
+
private static decodeBase64Url(base64Url: string) {
|
|
6
|
+
// Reemplaza caracteres de base64url
|
|
7
|
+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
8
|
+
// Decodifica en UTF-8
|
|
9
|
+
return decodeURIComponent(
|
|
10
|
+
Buffer.from(base64, 'base64').toString("utf-8")
|
|
11
|
+
.split("")
|
|
12
|
+
.map(c => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2))
|
|
13
|
+
.join("")
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static decode(jwt: string): Jwt {
|
|
18
|
+
const [headerB64, payloadB64, signature] = jwt.split(".");
|
|
19
|
+
const header: JwtHeader = JSON.parse(JwtUtils.decodeBase64Url(headerB64));
|
|
20
|
+
const payload: JwtPayload = JSON.parse(JwtUtils.decodeBase64Url(payloadB64));
|
|
21
|
+
|
|
22
|
+
// Si tiene campos de tiempo, conviértelos a fecha legible
|
|
23
|
+
if (payload.iat) payload.iat_date = new Date(payload.iat * 1000).toISOString();
|
|
24
|
+
if (payload.exp) payload.exp_date = new Date(payload.exp * 1000).toISOString();
|
|
25
|
+
|
|
26
|
+
return { header, payload, signature };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface JwtHeader {
|
|
31
|
+
alg: string; // Algorithm (e.g., "RS256")
|
|
32
|
+
typ: string; // Token type (usually "JWT")
|
|
33
|
+
kid?: string; // Key ID (optional)
|
|
34
|
+
[key: string]: any; // Allow other custom header fields
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface JwtPayload {
|
|
38
|
+
exp?: number; // Expiration time (Unix timestamp)
|
|
39
|
+
iat?: number; // Issued at
|
|
40
|
+
nbf?: number; // Not before
|
|
41
|
+
iss?: string; // Issuer
|
|
42
|
+
aud?: string | string[]; // Audience
|
|
43
|
+
sub?: string; // Subject (usually user ID)
|
|
44
|
+
jti?: string; // JWT ID
|
|
45
|
+
[key: string]: any; // Allow extra claims
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface Jwt {
|
|
49
|
+
header: JwtHeader;
|
|
50
|
+
payload: JwtPayload;
|
|
51
|
+
signature: string;
|
|
52
|
+
}
|