Skip to content

Commit

Permalink
koala: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bangarang committed Oct 4, 2024
1 parent b6da22e commit 10d589c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"plugins/*",
"support/*",
"utils/*",
"validators/*"
"validate/*"
],
"scripts": {
"clean": "find ./ '(' -name 'node_modules' -o -name 'dist' -o -name '.turbo' -o -name '.parcel-cache' ')' -type d -exec rm -rf {} +",
Expand Down
23 changes: 6 additions & 17 deletions validate/PDFReportGenerator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,11 @@ const defaultStyle: ReportStyle = {
}

export default function (listener: FlatfileListener) {
listener.use(
recordHook('contacts', async (record) => {
const email = record.get('email') as string

const validEmailAddress = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
if (!email || !validEmailAddress.test(email)) {
record.addError('email', 'Invalid email address')
}

return record
})
)

listener.on('action:custom', async (event: FlatfileEvent) => {
const { action, context } = event
if (action.operation === 'generate_pdf') {
listener.on(
'job:ready',
{ job: `sheet:generate_pdf` },
async (event: FlatfileEvent) => {
const { action, context } = event
try {
const userStyle: Partial<ReportStyle> = action.payload?.style || {}
const style: ReportStyle = { ...defaultStyle, ...userStyle }
Expand Down Expand Up @@ -194,5 +183,5 @@ export default function (listener: FlatfileListener) {
await event.reply('Error generating or uploading PDF')
}
}
})
)
}

0 comments on commit 10d589c

Please sign in to comment.