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

validator: company #623

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 41 additions & 21 deletions flatfilers/sandbox/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
import type { FlatfileEvent, FlatfileListener } from '@flatfile/listener'
import { automap } from '@flatfile/plugin-automap'
import { DelimiterExtractor } from '@flatfile/plugin-delimiter-extractor'
import { ExcelExtractor } from '@flatfile/plugin-xlsx-extractor'
import type { FlatfileListener } from '@flatfile/listener'
import { companyValidationPlugin } from '@flatfile/plugin-company-validator'
import { configureSpace } from '@flatfile/plugin-space-configure'

export default async function (listener: FlatfileListener) {
listener.use(
ExcelExtractor({
skipEmptyLines: true,
companyValidationPlugin({
sheetSlug: 'companies',
validateAddress: true,
validateEIN: true,
})
)
listener.use(
DelimiterExtractor('txt', { delimiter: ',', skipEmptyLines: true })
)

listener.use(
automap({
accuracy: 'confident',
defaultTargetSheet: 'contacts',
matchFilename: /test/,
debug: true,
onFailure: (event: FlatfileEvent) => {
// send an SMS, an email, post to an endpoint, etc.
console.error(
`Please visit https://spaces.flatfile.com/space/${event.context.spaceId}/files?mode=import to manually import file.`
)
},
configureSpace({
workbooks: [
{
name: 'Sandbox',
sheets: [
{
name: 'Companies',
slug: 'companies',
fields: [
{
key: 'company_name',
type: 'string',
label: 'Name',
},
{
key: 'company_website',
type: 'string',
label: 'Website',
},
{
key: 'company_address',
type: 'string',
label: 'Address',
},
{
key: 'company_ein',
type: 'string',
label: 'EIN',
},
],
},
],
},
],
})
)
}
129 changes: 124 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions validators/company-validator/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<!-- START_INFOCARD -->

# @flatfile/plugin-company-validator
**Validate company information including name, website, address, and EIN.**

The `@flatfile/plugin-company-validator` plugin is a validator that will validate company information including name, website, address, and EIN.

**Event Type:**
`listener.on('commit:created')`

<!-- END_INFOCARD -->


The plugin performs the following validations:

1. Company Name: Checks if the name is longer than 1 character
2. Company Website: Validates the website format using a regex pattern
3. Company Address (optional): Uses Google Maps API to verify the address
4. EIN (optional): Verifies the EIN using the EIN Verification API

For each invalid field, the plugin adds an error message to the record. The record is then returned, allowing Flatfile to display the errors to the user.

Note: Address and EIN validations are performed only if the respective configuration options are set to true.


## Parameters

#### `sheetSlug` - `string` - (required)

The `sheetSlug` parameter indicates the slug name of the sheet you want to monitor.

#### `googleMapsApiKey` - `string` - (optional)

The `googleMapsApiKey` parameter allows you to specify your Google Maps API key for address validation.

#### `einVerificationApiKey` - `string` - (optional)

The `einVerificationApiKey` parameter allows you to specify your EIN Verification API key.

#### `validateAddress` - `boolean` - (optional)

The `validateAddress` parameter allows you to specify if the plugin should validate company addresses.

#### `validateEIN` - `boolean` - (optional)

The `validateEIN` parameter allows you to specify if the plugin should validate EINs.


## Usage

**Environment Variables**

Add the following environment variables to your space:

- `GOOGLE_MAPS_API_KEY`
- `EIN_VERIFICATION_API_KEY`

**install**
```bash
npm install @flatfile/plugin-company-validation
```

**import**
```js
import { companyValidationPlugin } from "@flatfile/plugin-company-validation";
```

**listener.js**
```js
listener.use(companyValidationPlugin({
sheetSlug: "companies",
validateAddress: true,
validateEIN: true,
}));
```
Loading
Loading