fix: port by default 443
This commit is contained in:
@@ -18,12 +18,25 @@ import { TrytonClient } from "../src/client";
|
||||
// ====================================================
|
||||
// CONFIGURACIÓN - EDITA ESTOS VALORES CON TUS DATOS
|
||||
// ====================================================
|
||||
// const config = {
|
||||
// hostname: "https://demo7.6.tryton.org", // Servidor demo con HTTPS
|
||||
// port: 8000, // Puerto del servidor Tryton (generalmente 8000)
|
||||
// database: "demo7.6", // Base de datos demo
|
||||
// username: "admin", // Usuario demo
|
||||
// password: "admin", // Contraseña demo
|
||||
// language: "es", // Idioma (es, en, etc.)
|
||||
// options: {
|
||||
// verbose: true, // Mostrar información detallada de conexión
|
||||
// timeout: 30000, // Timeout en milisegundos
|
||||
// },
|
||||
// };
|
||||
|
||||
const config = {
|
||||
hostname: "https://demo7.6.tryton.org", // Servidor demo con HTTPS
|
||||
port: 8000, // Puerto del servidor Tryton (generalmente 8000)
|
||||
database: "demo7.6", // Base de datos demo
|
||||
hostname: "demo.naliia.co", // Servidor demo con HTTPS
|
||||
port: 80, // Puerto del servidor Tryton (generalmente 8000)
|
||||
database: "naliia", // Base de datos demo
|
||||
username: "admin", // Usuario demo
|
||||
password: "admin", // Contraseña demo
|
||||
password: "S0p0rt3f1n4l*", // Contraseña demo
|
||||
language: "es", // Idioma (es, en, etc.)
|
||||
options: {
|
||||
verbose: true, // Mostrar información detallada de conexión
|
||||
@@ -42,12 +55,10 @@ function validateConfig() {
|
||||
const missingFields = requiredFields.filter((field) => !config[field]);
|
||||
|
||||
if (missingFields.length > 0) {
|
||||
console.error(
|
||||
"❌ Error: Faltan los siguientes campos de configuración:"
|
||||
);
|
||||
console.error("❌ Error: Faltan los siguientes campos de configuración:");
|
||||
missingFields.forEach((field) => console.error(` - ${field}`));
|
||||
console.error(
|
||||
"\n💡 Edita este archivo y completa la configuración antes de ejecutar."
|
||||
"\n💡 Edita este archivo y completa la configuración antes de ejecutar.",
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -112,7 +123,7 @@ async function main() {
|
||||
[], // Dominio: todos los terceros (sin filtros)
|
||||
["id", "name", "code"], // Campos a obtener
|
||||
0, // Offset
|
||||
20 // Límite de resultados
|
||||
20, // Límite de resultados
|
||||
// Sin parámetro order
|
||||
);
|
||||
|
||||
@@ -125,9 +136,7 @@ async function main() {
|
||||
partiesData.forEach((party, index) => {
|
||||
const code = party.code ? ` (${party.code})` : "";
|
||||
console.log(
|
||||
`${(index + 1).toString().padStart(2)}. ${
|
||||
party.name
|
||||
}${code}`
|
||||
`${(index + 1).toString().padStart(2)}. ${party.name}${code}`,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -135,8 +144,7 @@ async function main() {
|
||||
console.log("\n🎉 ¡Ejemplo completado exitosamente!");
|
||||
} catch (error) {
|
||||
console.error("❌ Error durante la ejecución:");
|
||||
const errorMessage =
|
||||
error instanceof Error ? error.message : String(error);
|
||||
const errorMessage = error instanceof Error ? error.message : String(error);
|
||||
console.error(errorMessage);
|
||||
|
||||
if (config.options.verbose && error instanceof Error && error.stack) {
|
||||
@@ -148,9 +156,7 @@ async function main() {
|
||||
console.error("\n💡 Posibles soluciones:");
|
||||
console.error(" - Verifica que el servidor Tryton esté ejecutándose");
|
||||
console.error(" - Confirma que los datos de conexión sean correctos");
|
||||
console.error(
|
||||
" - Asegúrate de que el usuario tenga permisos adecuados"
|
||||
);
|
||||
console.error(" - Asegúrate de que el usuario tenga permisos adecuados");
|
||||
console.error(" - Verifica la conectividad de red al servidor");
|
||||
|
||||
process.exit(1);
|
||||
|
||||
@@ -55,7 +55,7 @@ export class TrytonClient {
|
||||
database,
|
||||
username,
|
||||
password,
|
||||
port = 8000,
|
||||
port = 443,
|
||||
language = "en",
|
||||
options = {},
|
||||
} = config;
|
||||
@@ -102,7 +102,7 @@ export class TrytonClient {
|
||||
username: string,
|
||||
password: string,
|
||||
port: number = 8000,
|
||||
language: string = "en"
|
||||
language: string = "en",
|
||||
): TrytonClient {
|
||||
return new TrytonClient({
|
||||
hostname,
|
||||
@@ -121,18 +121,12 @@ export class TrytonClient {
|
||||
*/
|
||||
async connect(): Promise<boolean> {
|
||||
try {
|
||||
const proxy = new ServerProxy(
|
||||
this.hostname,
|
||||
this.port,
|
||||
this.database,
|
||||
{
|
||||
const proxy = new ServerProxy(this.hostname, this.port, this.database, {
|
||||
verbose: this.options.verbose || false,
|
||||
connectTimeout:
|
||||
this.options.connectTimeout || CONNECT_TIMEOUT,
|
||||
connectTimeout: this.options.connectTimeout || CONNECT_TIMEOUT,
|
||||
timeout: this.options.timeout || DEFAULT_TIMEOUT,
|
||||
useHttps: this.useHttps,
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// Perform login
|
||||
const parameters = {
|
||||
@@ -158,12 +152,11 @@ export class TrytonClient {
|
||||
session: this.session,
|
||||
cache: this.options.cache !== false ? [] : null, // Enable cache by default
|
||||
verbose: this.options.verbose || false,
|
||||
connectTimeout:
|
||||
this.options.connectTimeout || CONNECT_TIMEOUT,
|
||||
connectTimeout: this.options.connectTimeout || CONNECT_TIMEOUT,
|
||||
timeout: this.options.timeout || DEFAULT_TIMEOUT,
|
||||
keepMax: this.options.keepMax || 4,
|
||||
useHttps: this.useHttps,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return true;
|
||||
@@ -178,11 +171,7 @@ export class TrytonClient {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async setupConnection(): Promise<void> {
|
||||
this.connection = new ServerPool(
|
||||
this.hostname,
|
||||
this.port,
|
||||
this.database,
|
||||
{
|
||||
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,
|
||||
@@ -190,8 +179,7 @@ export class TrytonClient {
|
||||
timeout: this.options.timeout || DEFAULT_TIMEOUT,
|
||||
keepMax: this.options.keepMax || 4,
|
||||
useHttps: this.useHttps,
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,7 +235,7 @@ export class TrytonClient {
|
||||
model: ModelName,
|
||||
ids: RecordIds,
|
||||
fields: FieldName[],
|
||||
context: TrytonContext = {}
|
||||
context: TrytonContext = {},
|
||||
): Promise<T[]> {
|
||||
return this.call<T[]>(`model.${model}.read`, [ids, fields, context]);
|
||||
}
|
||||
@@ -262,12 +250,9 @@ export class TrytonClient {
|
||||
async create(
|
||||
model: ModelName,
|
||||
records: Record<string, any>[],
|
||||
context: TrytonContext = {}
|
||||
context: TrytonContext = {},
|
||||
): Promise<RecordIds> {
|
||||
return this.call<RecordIds>(`model.${model}.create`, [
|
||||
records,
|
||||
context,
|
||||
]);
|
||||
return this.call<RecordIds>(`model.${model}.create`, [records, context]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -282,7 +267,7 @@ export class TrytonClient {
|
||||
model: ModelName,
|
||||
ids: RecordIds,
|
||||
values: Record<string, any>,
|
||||
context: TrytonContext = {}
|
||||
context: TrytonContext = {},
|
||||
): Promise<void> {
|
||||
return this.call<void>(`model.${model}.write`, [ids, values, context]);
|
||||
}
|
||||
@@ -297,7 +282,7 @@ export class TrytonClient {
|
||||
async delete(
|
||||
model: ModelName,
|
||||
ids: RecordIds,
|
||||
context: TrytonContext = {}
|
||||
context: TrytonContext = {},
|
||||
): Promise<void> {
|
||||
return this.call<void>(`model.${model}.delete`, [ids, context]);
|
||||
}
|
||||
@@ -318,7 +303,7 @@ export class TrytonClient {
|
||||
offset: number = 0,
|
||||
limit: number | null = null,
|
||||
order: string[] | null = null,
|
||||
context: TrytonContext = {}
|
||||
context: TrytonContext = {},
|
||||
): Promise<RecordIds> {
|
||||
return this.call<RecordIds>(`model.${model}.search`, [
|
||||
domain,
|
||||
@@ -347,7 +332,7 @@ export class TrytonClient {
|
||||
offset: number = 0,
|
||||
limit: number | null = null,
|
||||
order: string[] | null = null,
|
||||
context: TrytonContext = {}
|
||||
context: TrytonContext = {},
|
||||
): Promise<T[]> {
|
||||
return this.call<T[]>(`model.${model}.search_read`, [
|
||||
domain,
|
||||
@@ -369,12 +354,9 @@ export class TrytonClient {
|
||||
async searchCount(
|
||||
model: ModelName,
|
||||
domain: SearchDomain,
|
||||
context: TrytonContext = {}
|
||||
context: TrytonContext = {},
|
||||
): Promise<number> {
|
||||
return this.call<number>(`model.${model}.search_count`, [
|
||||
domain,
|
||||
context,
|
||||
]);
|
||||
return this.call<number>(`model.${model}.search_count`, [domain, context]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -419,7 +401,7 @@ export class TrytonClient {
|
||||
const users = await this.read<TrytonUser>(
|
||||
"res.user",
|
||||
[preferences.id],
|
||||
["id", "name", "login", "language", "company", "email"]
|
||||
["id", "name", "login", "language", "company", "email"],
|
||||
);
|
||||
if (!users || users.length === 0) {
|
||||
throw new Error("User not found");
|
||||
@@ -570,10 +552,7 @@ export class TrytonClient {
|
||||
// Test de validación de sesión
|
||||
try {
|
||||
// Usar un método que requiere autenticación para validar la sesión
|
||||
await proxy.request("model.res.user.get_preferences", [
|
||||
true,
|
||||
{},
|
||||
]);
|
||||
await proxy.request("model.res.user.get_preferences", [true, {}]);
|
||||
this.connection.putConnection(proxy); // Devolver conexión al pool
|
||||
return true;
|
||||
} catch (error) {
|
||||
@@ -595,36 +574,20 @@ export class TrytonClient {
|
||||
* Creates a typed interface for specific models
|
||||
*/
|
||||
model<T extends TrytonRecord = TrytonRecord>(
|
||||
modelName: ModelName
|
||||
modelName: ModelName,
|
||||
): TypedModelOperations<T> {
|
||||
return {
|
||||
read: (
|
||||
ids: RecordIds,
|
||||
fields: FieldName[],
|
||||
context?: TrytonContext
|
||||
) => this.read<T>(modelName, ids, fields, context),
|
||||
read: (ids: RecordIds, fields: FieldName[], context?: TrytonContext) =>
|
||||
this.read<T>(modelName, ids, fields, context),
|
||||
|
||||
create: (
|
||||
records: Partial<Omit<T, "id">>[],
|
||||
context?: TrytonContext
|
||||
) =>
|
||||
this.create(
|
||||
modelName,
|
||||
records as Record<string, any>[],
|
||||
context
|
||||
),
|
||||
create: (records: Partial<Omit<T, "id">>[], context?: TrytonContext) =>
|
||||
this.create(modelName, records as Record<string, any>[], context),
|
||||
|
||||
write: (
|
||||
ids: RecordIds,
|
||||
values: Partial<Omit<T, "id">>,
|
||||
context?: TrytonContext
|
||||
) =>
|
||||
this.write(
|
||||
modelName,
|
||||
ids,
|
||||
values as Record<string, any>,
|
||||
context
|
||||
),
|
||||
context?: TrytonContext,
|
||||
) => this.write(modelName, ids, values as Record<string, any>, context),
|
||||
|
||||
delete: (ids: RecordIds, context?: TrytonContext) =>
|
||||
this.delete(modelName, ids, context),
|
||||
@@ -634,7 +597,7 @@ export class TrytonClient {
|
||||
offset?: number,
|
||||
limit?: number,
|
||||
order?: string[],
|
||||
context?: TrytonContext
|
||||
context?: TrytonContext,
|
||||
) => this.search(modelName, domain, offset, limit, order, context),
|
||||
|
||||
searchRead: (
|
||||
@@ -643,7 +606,7 @@ export class TrytonClient {
|
||||
offset?: number,
|
||||
limit?: number,
|
||||
order?: string[],
|
||||
context?: TrytonContext
|
||||
context?: TrytonContext,
|
||||
) =>
|
||||
this.searchRead<T>(
|
||||
modelName,
|
||||
@@ -652,7 +615,7 @@ export class TrytonClient {
|
||||
offset,
|
||||
limit,
|
||||
order,
|
||||
context
|
||||
context,
|
||||
),
|
||||
|
||||
searchCount: (domain: SearchDomain, context?: TrytonContext) =>
|
||||
|
||||
Reference in New Issue
Block a user