feat: add setupConnection and setSession methods for session restoration
This commit is contained in:
@@ -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
|
* Call RPC method on server
|
||||||
* @param {string} methodName - RPC method name (e.g., 'model.party.party.read')
|
* @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
|
// Establecer la sesión sin hacer login
|
||||||
this.session = sessionToken;
|
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
|
// Verificar que la sesión sigue siendo válida
|
||||||
const proxy = this.connection?.getConnection();
|
const proxy = this.connection?.getConnection();
|
||||||
if (!proxy) {
|
if (!proxy) {
|
||||||
|
|||||||
@@ -646,6 +646,23 @@ export class ServerPool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update session for all connections
|
||||||
|
* @param {string} session - New session string
|
||||||
|
*/
|
||||||
|
setSession(session: string): void {
|
||||||
|
this.session = session;
|
||||||
|
this.options.session = session;
|
||||||
|
|
||||||
|
// Update session for all existing connections
|
||||||
|
for (const conn of this.pool) {
|
||||||
|
(conn as any).session = session;
|
||||||
|
}
|
||||||
|
for (const conn of this.used) {
|
||||||
|
(conn as any).session = session;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get connection from pool or create new one
|
* Get connection from pool or create new one
|
||||||
* @returns {ServerProxy} - Server proxy instance
|
* @returns {ServerProxy} - Server proxy instance
|
||||||
|
|||||||
Reference in New Issue
Block a user