Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade to response-rejection plugin #324

Merged
merged 18 commits into from
Dec 15, 2023
Merged

Conversation

carlbrugger
Copy link
Contributor

@carlbrugger carlbrugger commented Nov 17, 2023

Guide update: FlatFilers/Guides#955
Kitchen Sink update: FlatFilers/flatfile-docs-kitchen-sink#34

This PR adds better handling of submission status to the @flatfile/util-response-rejection plugin by providing webhook with 2 options:
- Option 1: Delete all successful records and leave only rejections
- Option 2 (default): Create new (readonly) submission status column that marks each record as "submitted" or "rejected"

Also, the webhook is given the option to set a response message.

Preview video

Future updates:

  • Next URL will open in a new tab. Will be fixed soon.
  • Forced page refresh when column is added. Will be fixed soon.

Example

Clone https://github.com/carlbrugger/bun-webhook

Run:

bun
bun start

This will start a webhook server on localhost:1234.

Paste in listener.ts:

import type { FlatfileListener } from '@flatfile/listener'
import { configureSpace } from '@flatfile/plugin-space-configure'
import { webhookEgress } from '@flatfile/plugin-webhook-egress'

export default function (listener: FlatfileListener) {
  listener.use(
    webhookEgress(
      'workbook:submitActionFg',
      'http://localhost:1234/reject-non-flatfile-emails'
    )
  )

  listener.use(
    configureSpace({
      workbooks: [
        {
          name: 'Playground',
          sheets: [
            {
              name: 'Contacts',
              slug: 'contacts',
              allowAdditionalFields: true,
              fields: [
                {
                  key: 'firstName',
                  type: 'string',
                  label: 'First Name',
                },
                {
                  key: 'lastName',
                  type: 'string',
                  label: 'Last Name',
                },
                {
                  key: 'email',
                  type: 'string',
                  label: 'Email',
                },
              ],
            },
          ],
          actions: [
            {
              operation: 'submitActionFg',
              mode: 'foreground',
              label: 'Submit data',
              type: 'string',
              description: 'Submit this data to a webhook.',
              primary: true,
            },
          ],
        },
      ],
    })
  )
}

@carlbrugger carlbrugger self-assigned this Nov 17, 2023
Copy link

socket-security bot commented Nov 17, 2023

Updated dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@flatfile/api 1.6.0...1.6.2 None +0/-0 4.04 MB flatfileinfra

@carlbrugger carlbrugger marked this pull request as ready for review November 17, 2023 17:17
@carlbrugger carlbrugger enabled auto-merge (squash) November 20, 2023 19:29
carlbrugger added a commit that referenced this pull request Nov 20, 2023
@carlbrugger carlbrugger mentioned this pull request Nov 20, 2023
7 tasks
@ashleygmulligan2 ashleygmulligan2 self-requested a review November 27, 2023 15:51
Copy link
Contributor

@ashleygmulligan2 ashleygmulligan2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concern of this being a breaking change in the utl. Types names have changed. Also, the rejection handler now returns a job response object rather than a total number of rejections as before. This should be a major release. Since the plugin itself isn't impacted in that way, patch seems fine. Tho this is more than a patch/fix, and introduces new functionality, so maybe minor is better here.

Copy link
Collaborator

@bangarang bangarang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work!

plugins/webhook-egress/package.json Outdated Show resolved Hide resolved
if (
!sheet.config.fields.some((field) => field.key === 'submissionStatus')
) {
await api.sheets.addField(sheet.id, {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove this field from the sheet when submitting? I'm sure they could strip it out if they wanted but could be nice if it was cleaned up as an option

@carlbrugger carlbrugger merged commit 75ea05d into main Dec 15, 2023
4 checks passed
@carlbrugger carlbrugger deleted the feat/response-rejection branch December 15, 2023 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants