Merge branch 'typescript-transition'
This commit is contained in:
@@ -502,6 +502,49 @@ export class TrytonClient {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore session using saved session token
|
||||||
|
* @param sessionToken - Previously saved session string (format: "username:userId:sessionKey")
|
||||||
|
* @returns Promise<boolean> - True if session is valid
|
||||||
|
*/
|
||||||
|
async restoreSession(sessionToken: string): Promise<boolean> {
|
||||||
|
try {
|
||||||
|
// Parsear el token guardado
|
||||||
|
const parts = sessionToken.split(":");
|
||||||
|
if (parts.length < 3) {
|
||||||
|
throw new Error("Invalid session token format");
|
||||||
|
}
|
||||||
|
|
||||||
|
const [username, userId, ...sessionKeyParts] = parts;
|
||||||
|
const sessionKey = sessionKeyParts.join(":"); // Por si el sessionKey tiene ":"
|
||||||
|
|
||||||
|
// Establecer la sesión sin hacer login
|
||||||
|
this.session = sessionToken;
|
||||||
|
|
||||||
|
// Verificar que la sesión sigue siendo válida
|
||||||
|
const proxy = this.connection?.getConnection();
|
||||||
|
if (!proxy) {
|
||||||
|
throw new Error("No connection available");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test de validación de sesión
|
||||||
|
try {
|
||||||
|
await proxy.request("common.version", []);
|
||||||
|
console.log("✅ Sesión restaurada exitosamente");
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
// Sesión inválida o expirada
|
||||||
|
this.session = null;
|
||||||
|
console.log("❌ Sesión inválida o expirada");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("❌ Error restaurando sesión:", error);
|
||||||
|
this.session = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type-safe model operations factory
|
* Type-safe model operations factory
|
||||||
* Creates a typed interface for specific models
|
* Creates a typed interface for specific models
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "ES2020",
|
"target": "ES2020",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"lib": ["ES2020"],
|
"lib": ["ES2020", "esnext", "dom"],
|
||||||
"declaration": true,
|
"declaration": true,
|
||||||
"declarationMap": true,
|
"declarationMap": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
|
|||||||
Reference in New Issue
Block a user