Browse Source

feat(nocodb): insert hook log based on NC_AUTOMATION_LOG_LEVEL

pull/5349/head
Wing-Kam Wong 1 year ago
parent
commit
c850074d73
  1. 98
      packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts
  2. 3
      packages/nocodb/src/lib/models/HookLog.ts

98
packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts

@ -301,14 +301,16 @@ export async function invokeWebhook(
subject: parseBody(notification?.payload?.subject, newData), subject: parseBody(notification?.payload?.subject, newData),
html: parseBody(notification?.payload?.body, newData), html: parseBody(notification?.payload?.body, newData),
}); });
hookLog = { if (process.env.NC_AUTOMATION_LOG_LEVEL === 'ALL') {
...hook, hookLog = {
fk_hook_id: hook.id, ...hook,
type: notification.type, fk_hook_id: hook.id,
payload: JSON.stringify(notification?.payload), type: notification.type,
response: JSON.stringify(res), payload: JSON.stringify(notification?.payload),
triggered_by: user?.email, response: JSON.stringify(res),
}; triggered_by: user?.email,
};
}
} }
break; break;
case 'URL': case 'URL':
@ -323,25 +325,27 @@ export async function invokeWebhook(
newData newData
); );
hookLog = { if (process.env.NC_AUTOMATION_LOG_LEVEL === 'ALL') {
...hook, hookLog = {
fk_hook_id: hook.id, ...hook,
type: notification.type, fk_hook_id: hook.id,
payload: JSON.stringify(notification?.payload), type: notification.type,
response: JSON.stringify({ payload: JSON.stringify(notification?.payload),
status: res.status, response: JSON.stringify({
statusText: res.statusText, status: res.status,
headers: res.headers, statusText: res.statusText,
config: { headers: res.headers,
url: res.config.url, config: {
method: res.config.method, url: res.config.url,
data: res.config.data, method: res.config.method,
headers: res.config.headers, data: res.config.data,
params: res.config.params, headers: res.config.headers,
}, params: res.config.params,
}), },
triggered_by: user?.email, }),
}; triggered_by: user?.email,
};
}
} }
break; break;
default: default:
@ -357,29 +361,33 @@ export async function invokeWebhook(
}) })
); );
hookLog = { if (process.env.NC_AUTOMATION_LOG_LEVEL === 'ALL') {
...hook, hookLog = {
fk_hook_id: hook.id, ...hook,
type: notification.type, fk_hook_id: hook.id,
payload: JSON.stringify(notification?.payload), type: notification.type,
response: JSON.stringify(res), payload: JSON.stringify(notification?.payload),
triggered_by: user?.email, response: JSON.stringify(res),
}; triggered_by: user?.email,
};
}
} }
break; break;
} }
} catch (e) { } catch (e) {
console.log(e); console.log(e);
hookLog = { if (['ERROR', 'ALL'].includes(process.env.NC_AUTOMATION_LOG_LEVEL)) {
...hook, hookLog = {
type: notification.type, ...hook,
payload: JSON.stringify(notification?.payload), type: notification.type,
fk_hook_id: hook.id, payload: JSON.stringify(notification?.payload),
error_code: e.error_code, fk_hook_id: hook.id,
error_message: e.message, error_code: e.error_code,
error: JSON.stringify(e), error_message: e.message,
triggered_by: user?.email, error: JSON.stringify(e),
}; triggered_by: user?.email,
};
}
if (throwErrorOnFailure) throw e; if (throwErrorOnFailure) throw e;
} finally { } finally {
if (hookLog) { if (hookLog) {

3
packages/nocodb/src/lib/models/HookLog.ts

@ -63,6 +63,9 @@ export default class HookLog implements HookLogType {
} }
public static async insert(hookLog: Partial<HookLog>, ncMeta = Noco.ncMeta) { public static async insert(hookLog: Partial<HookLog>, ncMeta = Noco.ncMeta) {
if (process.env.NC_AUTOMATION_LOG_LEVEL === 'OFF') {
return;
}
const insertObj: any = extractProps(hookLog, [ const insertObj: any = extractProps(hookLog, [
'base_id', 'base_id',
'project_id', 'project_id',

Loading…
Cancel
Save