Final updates for Fortellis to pass certification and remove logging.

This commit is contained in:
Patrick Fic
2026-01-09 10:16:33 -08:00
parent 3cf1d9a59d
commit f4b45c693a
4 changed files with 114 additions and 54 deletions

View File

@@ -38,8 +38,6 @@ const defaultFortellisTTL = 60 * 60;
async function GetAuthToken() {
//Done with Authorization Code Flow
//https://docs.fortellis.io/docs/tutorials/solution-integration/authorization-code-flow/
//TODO: This should get stored in the redis cache and only be refreshed when it expires.
const {
data: { access_token, expires_in, token_type }
} = await axios.post(
@@ -221,6 +219,22 @@ async function MakeFortellisCall({
console.log(JSON.stringify(result.data, null, 4));
}
// await writeFortellisLogToFile({
// timestamp: new Date().toISOString(),
// reqId: ReqId,
// url: fullUrl,
// request:
// {
// requestcurl: result.config.curlCommand,
// reqid: result.config.headers["Request-Id"] || null,
// subscriptionId: result.config.headers["Subscription-Id"] || null,
// resultdata: result.data,
// resultStatus: result.status
// },
// user: socket?.user?.email,
// jobid: socket?.recordid
// });
if (result.data.checkStatusAfterSeconds) {
return DelayedCallback({
delayMeta: result.data,
@@ -231,6 +245,8 @@ async function MakeFortellisCall({
});
}
logger.log(
"fortellis-log-event-json",
"DEBUG",
@@ -256,6 +272,21 @@ async function MakeFortellisCall({
errorStatusText: error.response?.statusText,
originalError: error
};
// await writeFortellisLogToFile({
// timestamp: new Date().toISOString(),
// reqId: ReqId,
// url: fullUrl,
// request:
// {
// requestcurl: error.config.curlCommand,
// reqid: error.config.headers["Request-Id"] || null,
// subscriptionId: error.config.headers["Subscription-Id"] || null,
// resultdata: error.message,
// resultStatus: error.status
// },
// user: socket?.user?.email,
// jobid: socket?.recordid
// });
logger.log(
"fortellis-log-event-error",
@@ -263,10 +294,11 @@ async function MakeFortellisCall({
socket?.user?.email,
socket?.recordid,
{
wsmessage: "",//message,
curl: error?.config.curlCommand,
reqid: error.config?.headers["Request-Id"] || null,
subscriptionId: error.config?.headers["Subscription-Id"] || null,
requestcurl: error.config.curlCommand,
reqid: error.config.headers["Request-Id"] || null,
subscriptionId: error.config.headers["Subscription-Id"] || null,
resultdata: error.message,
resultStatus: error.status
},
true
);
@@ -302,6 +334,19 @@ async function DelayedCallback({ delayMeta, access_token, SubscriptionID, ReqId,
//"Department-Id": departmentIds[0].id
}
});
// await writeFortellisLogToFile({
// timestamp: new Date().toISOString(),
// reqId: ReqId,
// url: statusResult.data._links.result.href,
// request:
// {
// requestcurl: batchResult.config.curlCommand,
// reqid: batchResult.config.headers["Request-Id"] || null,
// subscriptionId: batchResult.config.headers["Subscription-Id"] || null,
// resultdata: batchResult.data,
// resultStatus: batchResult.status
// },
// });
return batchResult;
} else {
return "Error!!! Still need to implement batch waiting.";
@@ -313,6 +358,7 @@ function sleep(ms) {
}
async function writeFortellisLogToFile(logObject) {
//The was only used for the certification. Commented out in case of future need.
try {
const logsDir = path.join(process.cwd(), 'logs');
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
@@ -336,9 +382,6 @@ async function writeFortellisLogToFile(logObject) {
async function WriteToIOEventLog({ apiName, type, fullUrl, bodyshopid, useremail, logger, socket }) {
try {
await client.request(INSERT_IOEVENT, {
event: {
operationname: `fortellis-${apiName}-${type}`,