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. 8
      packages/nocodb/src/lib/meta/helpers/webhookHelpers.ts
  2. 3
      packages/nocodb/src/lib/models/HookLog.ts

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

@ -301,6 +301,7 @@ 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),
}); });
if (process.env.NC_AUTOMATION_LOG_LEVEL === 'ALL') {
hookLog = { hookLog = {
...hook, ...hook,
fk_hook_id: hook.id, fk_hook_id: hook.id,
@ -310,6 +311,7 @@ export async function invokeWebhook(
triggered_by: user?.email, triggered_by: user?.email,
}; };
} }
}
break; break;
case 'URL': case 'URL':
{ {
@ -323,6 +325,7 @@ export async function invokeWebhook(
newData newData
); );
if (process.env.NC_AUTOMATION_LOG_LEVEL === 'ALL') {
hookLog = { hookLog = {
...hook, ...hook,
fk_hook_id: hook.id, fk_hook_id: hook.id,
@ -343,6 +346,7 @@ export async function invokeWebhook(
triggered_by: user?.email, triggered_by: user?.email,
}; };
} }
}
break; break;
default: default:
{ {
@ -357,6 +361,7 @@ export async function invokeWebhook(
}) })
); );
if (process.env.NC_AUTOMATION_LOG_LEVEL === 'ALL') {
hookLog = { hookLog = {
...hook, ...hook,
fk_hook_id: hook.id, fk_hook_id: hook.id,
@ -366,10 +371,12 @@ export async function invokeWebhook(
triggered_by: user?.email, triggered_by: user?.email,
}; };
} }
}
break; break;
} }
} catch (e) { } catch (e) {
console.log(e); console.log(e);
if (['ERROR', 'ALL'].includes(process.env.NC_AUTOMATION_LOG_LEVEL)) {
hookLog = { hookLog = {
...hook, ...hook,
type: notification.type, type: notification.type,
@ -380,6 +387,7 @@ export async function invokeWebhook(
error: JSON.stringify(e), error: JSON.stringify(e),
triggered_by: user?.email, 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