feat: add setupConnection and setSession methods for session restoration

This commit is contained in:
2025-10-15 15:19:34 -05:00
parent 31d7cab487
commit 7d8a85f01e
2 changed files with 44 additions and 0 deletions

View File

@@ -158,6 +158,28 @@ export class TrytonClient {
}
}
/**
* Setup connection pool without authentication
* Used when restoring an existing session
* @returns {Promise<void>}
*/
async setupConnection(): Promise<void> {
this.connection = new ServerPool(
this.hostname,
this.port,
this.database,
{
session: undefined, // Session will be set by restoreSession()
cache: this.options.cache !== false ? [] : null,
verbose: this.options.verbose || false,
connectTimeout: this.options.connectTimeout || CONNECT_TIMEOUT,
timeout: this.options.timeout || DEFAULT_TIMEOUT,
keepMax: this.options.keepMax || 4,
useHttps: this.useHttps,
}
);
}
/**
* Call RPC method on server
* @param {string} methodName - RPC method name (e.g., 'model.party.party.read')
@@ -521,6 +543,11 @@ export class TrytonClient {
// Establecer la sesión sin hacer login
this.session = sessionToken;
// Actualizar la sesión en el connection pool
if (this.connection) {
this.connection.setSession(sessionToken);
}
// Verificar que la sesión sigue siendo válida
const proxy = this.connection?.getConnection();
if (!proxy) {