feat(core): Use WebCrypto to generate all random numbers and strings (#9786)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-06-19 13:33:57 +02:00
committed by GitHub
parent cfc4db00e3
commit 65c5609ab5
49 changed files with 254 additions and 214 deletions

View File

@@ -6,7 +6,7 @@ import type {
JsonObject,
IRequestOptions,
} from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
import { NodeApiError, randomInt } from 'n8n-workflow';
const serviceJSONRPC = 'object';
const methodJSONRPC = 'execute';
@@ -65,7 +65,7 @@ export interface IOdooNameValueFields {
}>;
}
export interface IOdooResponceFields {
export interface IOdooResponseFields {
fields: Array<{
field: string;
fromList?: boolean;
@@ -97,8 +97,8 @@ export function processNameValueFields(value: IDataObject) {
}, {});
}
// function processResponceFields(value: IDataObject) {
// const data = value as unknown as IOdooResponceFields;
// function processResponseFields(value: IDataObject) {
// const data = value as unknown as IOdooResponseFields;
// return data?.fields?.map((entry) => entry.field);
// }
@@ -121,13 +121,13 @@ export async function odooJSONRPCRequest(
json: true,
};
const responce = await this.helpers.request(options);
if (responce.error) {
throw new NodeApiError(this.getNode(), responce.error.data as JsonObject, {
message: responce.error.data.message,
const response = await this.helpers.request(options);
if (response.error) {
throw new NodeApiError(this.getNode(), response.error.data as JsonObject, {
message: response.error.data.message,
});
}
return responce.result;
return response.result;
} catch (error) {
throw new NodeApiError(this.getNode(), error as JsonObject);
}
@@ -158,7 +158,7 @@ export async function odooGetModelFields(
['string', 'type', 'help', 'required', 'name'],
],
},
id: Math.floor(Math.random() * 100),
id: randomInt(100),
};
const result = await odooJSONRPCRequest.call(this, body, url);
@@ -194,7 +194,7 @@ export async function odooCreate(
newItem || {},
],
},
id: Math.floor(Math.random() * 100),
id: randomInt(100),
};
const result = await odooJSONRPCRequest.call(this, body, url);
@@ -238,7 +238,7 @@ export async function odooGet(
fieldsToReturn || [],
],
},
id: Math.floor(Math.random() * 100),
id: randomInt(100),
};
const result = await odooJSONRPCRequest.call(this, body, url);
@@ -279,7 +279,7 @@ export async function odooGetAll(
limit,
],
},
id: Math.floor(Math.random() * 100),
id: randomInt(100),
};
const result = await odooJSONRPCRequest.call(this, body, url);
@@ -329,7 +329,7 @@ export async function odooUpdate(
fieldsToUpdate,
],
},
id: Math.floor(Math.random() * 100),
id: randomInt(100),
};
await odooJSONRPCRequest.call(this, body, url);
@@ -371,7 +371,7 @@ export async function odooDelete(
itemsID ? [+itemsID] : [],
],
},
id: Math.floor(Math.random() * 100),
id: randomInt(100),
};
await odooJSONRPCRequest.call(this, body, url);
@@ -397,7 +397,7 @@ export async function odooGetUserID(
method: 'login',
args: [db, username, password],
},
id: Math.floor(Math.random() * 100),
id: randomInt(100),
};
const loginResult = await odooJSONRPCRequest.call(this, body, url);
return loginResult as unknown as number;
@@ -419,7 +419,7 @@ export async function odooGetServerVersion(
method: 'version',
args: [],
},
id: Math.floor(Math.random() * 100),
id: randomInt(100),
};
const result = await odooJSONRPCRequest.call(this, body, url);
return result;