mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
add auditing to webhook parser
This commit is contained in:
9
src/components/CodeEditor/rowy.d.ts
vendored
9
src/components/CodeEditor/rowy.d.ts
vendored
@@ -20,4 +20,13 @@ declare namespace rowy {
|
||||
* Gets the secret defined in Google Cloud Secret
|
||||
*/
|
||||
async function getSecret(name: string, v?: string): Promise<string | null>;
|
||||
|
||||
async function getServiceAccountUser(): Promise<{
|
||||
email: string;
|
||||
emailVerified: boolean;
|
||||
displayName: string;
|
||||
photoURL: string;
|
||||
uid: string;
|
||||
timestamp: number;
|
||||
}>;
|
||||
}
|
||||
|
||||
@@ -44,20 +44,36 @@ export const webhookBasic = {
|
||||
parser: {
|
||||
additionalVariables,
|
||||
extraLibs: parserExtraLibs,
|
||||
template: `const basicParser: Parser = async({req, db,ref}) => {
|
||||
template: (table) => `const basicParser: Parser = async({req, db,ref}) => {
|
||||
// request is the request object from the webhook
|
||||
// db is the database object
|
||||
// ref is the reference to collection of the table
|
||||
// the returned object will be added as a new row to the table
|
||||
// eg: adding the webhook body as row
|
||||
const {body} = req;
|
||||
${
|
||||
table.audit !== false
|
||||
? `
|
||||
// auditField
|
||||
const ${
|
||||
table.auditFieldCreatedBy ?? "_createdBy"
|
||||
} = await rowy.getServiceAccountUser()
|
||||
return {
|
||||
...body,
|
||||
${table.auditFieldCreatedBy ?? "_createdBy"}
|
||||
}
|
||||
`
|
||||
: `
|
||||
return body;
|
||||
`
|
||||
}
|
||||
|
||||
}`,
|
||||
},
|
||||
condition: {
|
||||
additionalVariables,
|
||||
extraLibs: conditionExtraLibs,
|
||||
template: `const condition: Condition = async({ref,req,db}) => {
|
||||
template: (table) => `const condition: Condition = async({ref,req,db}) => {
|
||||
// feel free to add your own code logic here
|
||||
return true;
|
||||
}`,
|
||||
|
||||
@@ -6,8 +6,13 @@ export const webhookSendgrid = {
|
||||
parser: {
|
||||
additionalVariables: null,
|
||||
extraLibs: null,
|
||||
template: `const sendgridParser: Parser = async({req, db,ref}) =>{
|
||||
|
||||
template: (
|
||||
table
|
||||
) => `const sendgridParser: Parser = async({req, db,ref}) =>{
|
||||
// sendgrid webhook events docs : https://docs.sendgrid.com/for-developers/tracking-events/event#event-objects
|
||||
|
||||
// sengrid sends request body with an array of events
|
||||
// eg:
|
||||
// {
|
||||
// "email": "example@test.com",
|
||||
// "timestamp": 1513299569,
|
||||
@@ -24,7 +29,7 @@ export const webhookSendgrid = {
|
||||
condition: {
|
||||
additionalVariables: null,
|
||||
extraLibs: null,
|
||||
template: `const condition: Condition = async({ref,req,db}) => {
|
||||
template: (table) => `const condition: Condition = async({ref,req,db}) => {
|
||||
// feel free to add your own code logic here
|
||||
return true;
|
||||
}`,
|
||||
|
||||
@@ -6,15 +6,16 @@ export const webhookTypeform = {
|
||||
parser: {
|
||||
additionalVariables: null,
|
||||
extraLibs: null,
|
||||
|
||||
template: `const typeformParser: Parser = async({req, db,ref}) =>{
|
||||
template: (
|
||||
table
|
||||
) => `const typeformParser: Parser = async({req, db,ref}) =>{
|
||||
// this reduces the form submission into a single object of key value pairs
|
||||
// eg: {name: "John", age: 20}
|
||||
// ⚠️ ensure that you have assigned ref values of the fields
|
||||
// set the ref value to field key you would like to sync to
|
||||
// docs: https://help.typeform.com/hc/en-us/articles/360050447552-Block-reference-format-restrictions
|
||||
const {submitted_at,hidden,answers} = req.body.form_response
|
||||
return ({
|
||||
const submission = ({
|
||||
_createdAt: submitted_at,
|
||||
...hidden,
|
||||
...answers.reduce((accRow, currAnswer) => {
|
||||
@@ -42,12 +43,30 @@ export const webhookTypeform = {
|
||||
};
|
||||
}
|
||||
}, {}),
|
||||
})};`,
|
||||
})
|
||||
|
||||
${
|
||||
table.audit !== false
|
||||
? `
|
||||
// auditField
|
||||
const ${
|
||||
table.auditFieldCreatedBy ?? "_createdBy"
|
||||
} = await rowy.getServiceAccountUser()
|
||||
return {
|
||||
...submission,
|
||||
${table.auditFieldCreatedBy ?? "_createdBy"}
|
||||
}
|
||||
`
|
||||
: `
|
||||
return submission
|
||||
`
|
||||
}
|
||||
};`,
|
||||
},
|
||||
condition: {
|
||||
additionalVariables: null,
|
||||
extraLibs: null,
|
||||
template: `const condition: Condition = async({ref,req,db}) => {
|
||||
template: (table) => `const condition: Condition = async({ref,req,db}) => {
|
||||
// feel free to add your own code logic here
|
||||
return true;
|
||||
}`,
|
||||
|
||||
@@ -76,19 +76,16 @@ export const webhookSchemas = {
|
||||
|
||||
export function emptyWebhookObject(
|
||||
type: WebhookType,
|
||||
user: IWebhookEditor
|
||||
user: IWebhookEditor,
|
||||
table
|
||||
): IWebhook {
|
||||
return {
|
||||
name: "Untitled webhook",
|
||||
name: `${type} webhook`,
|
||||
active: false,
|
||||
endpoint: generateRandomId(),
|
||||
type,
|
||||
parser:
|
||||
webhookSchemas[type].parser?.template ??
|
||||
webhookSchemas["basic"].parser.template,
|
||||
conditions:
|
||||
webhookSchemas[type].condition?.template ??
|
||||
webhookSchemas["basic"].condition.template,
|
||||
parser: webhookSchemas[type].parser?.template(table),
|
||||
conditions: webhookSchemas[type].condition?.template(table),
|
||||
lastEditor: user,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ const WIKI_PATHS = {
|
||||
fieldTypesSupportedFields: "/field-types/supported-fields",
|
||||
fieldTypesDerivative: "/field-types/derivative",
|
||||
fieldTypesConnectTable: "/field-types/connect-table",
|
||||
fieldTypesConnectService: "/field-types/connect-service",
|
||||
fieldTypesAction: "/field-types/action",
|
||||
fieldTypesAdd: "/field-types/add",
|
||||
|
||||
|
||||
Reference in New Issue
Block a user