Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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 { configureSpace } from '@flatfile/plugin-space-configure'
import { companyValidationPlugin } from '@flatfile/plugin-validate-company'

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',
},
],
},
],
},
],
})
)
}
46 changes: 33 additions & 13 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 validate/company/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<!-- START_INFOCARD -->

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

The `@flatfile/plugin-validate-company` 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,
}));
```
105 changes: 105 additions & 0 deletions validate/company/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"timestamp": "2024-09-24T07-11-09-392Z",
"task": "Develop a company/business validation Flatfile Listener plugin:\n - Create a RecordHook to validate company information\n - Implement company name and address validation using external APIs (e.g., Google Places API)\n - Verify business registration numbers or tax IDs\n - Check for company existence in business databases\n - Add error messages or warnings for unverified business information\n - Give the user reasonable config options to specify the Sheet Slug, the Field(s) that are the company information(s), whether the validation should be done automatically",
"summary": "This solution implements a company validation RecordHook plugin for Flatfile. It validates company information including name, website, address, EIN, and business registration. The plugin uses external APIs for address validation and business verification. It includes configuration options and provides detailed error messages and warnings for unverified information.",
"steps": [
[
"Retrieve information about Flatfile Listeners and RecordHook plugin.\n",
"#E1",
"PineconeAssistant",
"Provide information on Flatfile Listeners and RecordHook plugin, including their structure and usage",
"Plan: Retrieve information about Flatfile Listeners and RecordHook plugin.\n#E1 = PineconeAssistant[Provide information on Flatfile Listeners and RecordHook plugin, including their structure and usage]"
],
[
"Create a basic structure for the company validation RecordHook.\n",
"#E2",
"LLM",
"Create a basic structure for a Flatfile RecordHook plugin for company validation, using the information from #E1",
"Plan: Create a basic structure for the company validation RecordHook.\n#E2 = LLM[Create a basic structure for a Flatfile RecordHook plugin for company validation, using the information from #E1]"
],
[
"Implement company name and address validation using Google Places API.\n",
"#E3",
"Google",
"How to use Google Places API for company name and address validation",
"Plan: Implement company name and address validation using Google Places API.\n#E3 = Google[How to use Google Places API for company name and address validation]"
],
[
"Integrate Google Places API validation into the RecordHook.\n",
"#E4",
"LLM",
"Integrate Google Places API validation into the RecordHook structure from #E2, using the information from #E3",
"Plan: Integrate Google Places API validation into the RecordHook.\n#E4 = LLM[Integrate Google Places API validation into the RecordHook structure from #E2, using the information from #E3]"
],
[
"Implement business registration number and tax ID verification.\n",
"#E5",
"Google",
"API for verifying business registration numbers and tax IDs",
"Plan: Implement business registration number and tax ID verification.\n#E5 = Google[API for verifying business registration numbers and tax IDs]"
],
[
"Add business registration and tax ID verification to the RecordHook.\n",
"#E6",
"LLM",
"Add business registration and tax ID verification to the RecordHook using the information from #E5 and #E4",
"Plan: Add business registration and tax ID verification to the RecordHook.\n#E6 = LLM[Add business registration and tax ID verification to the RecordHook using the information from #E5 and #E4]"
],
[
"Implement company existence check in business databases.\n",
"#E7",
"Google",
"API for checking company existence in business databases",
"Plan: Implement company existence check in business databases.\n#E7 = Google[API for checking company existence in business databases]"
],
[
"Integrate company existence check into the RecordHook.\n",
"#E8",
"LLM",
"Integrate company existence check into the RecordHook using the information from #E7 and #E6",
"Plan: Integrate company existence check into the RecordHook.\n#E8 = LLM[Integrate company existence check into the RecordHook using the information from #E7 and #E6]"
],
[
"Add error messages and warnings for unverified business information.\n",
"#E9",
"LLM",
"Add error messages and warnings for unverified business information to the RecordHook from #E8",
"Plan: Add error messages and warnings for unverified business information.\n#E9 = LLM[Add error messages and warnings for unverified business information to the RecordHook from #E8]"
],
[
"Implement configuration options for the RecordHook.\n",
"#E10",
"LLM",
"Add configuration options to the RecordHook for specifying Sheet Slug, company information fields, and automatic validation toggle, using the structure from #E9",
"Plan: Implement configuration options for the RecordHook.\n#E10 = LLM[Add configuration options to the RecordHook for specifying Sheet Slug, company information fields, and automatic validation toggle, using the structure from #E9]"
],
[
"Verify the final RecordHook implementation and ensure it uses valid Event Topics.\n",
"#E11",
"PineconeAssistant",
"Verify the RecordHook implementation from #E10 and ensure it uses valid Event Topics",
"Plan: Verify the final RecordHook implementation and ensure it uses valid Event Topics.\n#E11 = PineconeAssistant[Verify the RecordHook implementation from #E10 and ensure it uses valid Event Topics]"
],
[
"Optimize the code and remove any unused imports or elements.\n",
"#E12",
"LLM",
"Optimize the RecordHook code from #E11, remove unused imports, and ensure all plugins and utils are correctly used",
"Plan: Optimize the code and remove any unused imports or elements.\n#E12 = LLM[Optimize the RecordHook code from #E11, remove unused imports, and ensure all plugins and utils are correctly used]"
],
[
"Create documentation for the company validation RecordHook plugin.\n",
"#E13",
"LLM",
"Create documentation for the company validation RecordHook plugin, including setup instructions, configuration options, and usage examples",
"Plan: Create documentation for the company validation RecordHook plugin.\n#E13 = LLM[Create documentation for the company validation RecordHook plugin, including setup instructions, configuration options, and usage examples]"
]
],
"metrics": {
"tokens": {
"plan": 4474,
"state": 5636,
"total": 10110
}
}
}
Loading