Skip to content

Commit

Permalink
Merge pull request #4626 from activepieces/feat/zerobounce
Browse files Browse the repository at this point in the history
feat(zerobounce): validate email action
  • Loading branch information
abuaboud committed May 4, 2024
2 parents 5823f0c + a58a9bc commit 957ecdf
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/pieces/community/apollo/package.json
@@ -1,4 +1,4 @@
{
"name": "@activepieces/piece-apollo",
"version": "0.0.2"
"version": "0.0.3"
}
21 changes: 16 additions & 5 deletions packages/pieces/community/apollo/src/lib/actions/enrich-company.ts
@@ -1,5 +1,5 @@
import { apolloAuth } from '../../';
import { Property, createAction } from '@activepieces/pieces-framework';
import { Property, StoreScope, createAction } from '@activepieces/pieces-framework';
import {
HttpMethod,
httpClient,
Expand All @@ -15,12 +15,20 @@ export const enrichCompany = createAction({
description: '',
required: true,
}),
cacheResponse: Property.Checkbox({
displayName: 'Cache Response',
description: 'Store the response in the project store for future use.',
required: false,
defaultValue: true,
}),
},
auth: apolloAuth,
async run({ propsValue, auth, store }) {
const cachedResult = await store.get(`_apollo_org_${propsValue.domain}`)
if (cachedResult) {
return cachedResult;
if (propsValue.cacheResponse) {
const cachedResult = await store.get(`_apollo_org_${propsValue.domain}`, StoreScope.PROJECT);
if (cachedResult) {
return cachedResult;
}
}
const result = await httpClient.sendRequest<{ organization: Record<string, unknown> }>({
method: HttpMethod.GET,
Expand All @@ -30,7 +38,10 @@ export const enrichCompany = createAction({
},
});
const resultOrg = result.body.organization || {};
await store.put(`_apollo_org_${propsValue.domain}`, resultOrg);
if (propsValue.cacheResponse) {
await store.put(`_apollo_org_${propsValue.domain}`, resultOrg, StoreScope.PROJECT);

}
return resultOrg;
},
});
22 changes: 16 additions & 6 deletions packages/pieces/community/apollo/src/lib/actions/match-person.ts
@@ -1,6 +1,6 @@
import { apolloAuth } from '../../';
import { HttpMethod, httpClient } from '@activepieces/pieces-common';
import { Property, createAction } from '@activepieces/pieces-framework';
import { Property, StoreScope, createAction } from '@activepieces/pieces-framework';

export const matchPerson = createAction({
name: 'matchPerson',
Expand All @@ -11,13 +11,21 @@ export const matchPerson = createAction({
displayName: 'Email',
description: '',
required: true,
})
}),
cacheResponse: Property.Checkbox({
displayName: 'Cache Response',
description: 'Store the response in the project store for future use.',
required: false,
defaultValue: true,
}),
},
auth: apolloAuth,
async run({ propsValue, auth, store }) {
const cachedResult = await store.get(`_apollo_person_${propsValue.email}`)
if (cachedResult) {
return cachedResult;
if (propsValue.cacheResponse) {
const cachedResult = await store.get(`_apollo_person_${propsValue.email}`, StoreScope.PROJECT);
if (cachedResult) {
return cachedResult;
}
}
const result = await httpClient.sendRequest<{ person: Record<string, unknown> }>({
method: HttpMethod.POST,
Expand All @@ -31,7 +39,9 @@ export const matchPerson = createAction({
}
});
const personResult = result.body.person || {};
await store.put(`_apollo_person_${propsValue.email}`, personResult);
if (propsValue.cacheResponse) {
await store.put(`_apollo_person_${propsValue.email}`, personResult, StoreScope.PROJECT);
}
return personResult;
},
});
33 changes: 33 additions & 0 deletions packages/pieces/community/zerobounce/.eslintrc.json
@@ -0,0 +1,33 @@
{
"extends": [
"../../../../.eslintrc.base.json"
],
"ignorePatterns": [
"!**/*"
],
"overrides": [
{
"files": [
"*.ts",
"*.tsx",
"*.js",
"*.jsx"
],
"rules": {}
},
{
"files": [
"*.ts",
"*.tsx"
],
"rules": {}
},
{
"files": [
"*.js",
"*.jsx"
],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions packages/pieces/community/zerobounce/README.md
@@ -0,0 +1,7 @@
# pieces-zerobounce

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build pieces-zerobounce` to build the library.
4 changes: 4 additions & 0 deletions packages/pieces/community/zerobounce/package.json
@@ -0,0 +1,4 @@
{
"name": "@activepieces/piece-zerobounce",
"version": "0.0.1"
}
38 changes: 38 additions & 0 deletions packages/pieces/community/zerobounce/project.json
@@ -0,0 +1,38 @@
{
"name": "pieces-zerobounce",
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/pieces/community/zerobounce/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": [
"{options.outputPath}"
],
"options": {
"outputPath": "dist/packages/pieces/community/zerobounce",
"tsConfig": "packages/pieces/community/zerobounce/tsconfig.lib.json",
"packageJson": "packages/pieces/community/zerobounce/package.json",
"main": "packages/pieces/community/zerobounce/src/index.ts",
"assets": [
"packages/pieces/community/zerobounce/*.md"
],
"buildableProjectDepsInPackageJsonType": "dependencies",
"updateBuildableProjectDepsInPackageJson": true
}
},
"publish": {
"command": "node tools/scripts/publish.mjs pieces-zerobounce {args.ver} {args.tag}",
"dependsOn": [
"build"
]
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": [
"{options.outputFile}"
]
}
},
"tags": []
}
19 changes: 19 additions & 0 deletions packages/pieces/community/zerobounce/src/index.ts
@@ -0,0 +1,19 @@

import { createPiece, PieceAuth } from "@activepieces/pieces-framework";
import { validateEmail } from "./lib/actions/validate-email";

export const zerobounceAuth = PieceAuth.SecretText({
displayName: 'API Key',
required: true,
});

export const zerobounce = createPiece({
displayName: "ZeroBounce",
auth: zerobounceAuth,
description: "ZeroBounce is an email validation service that helps you reduce bounces, improve email deliverability and increase email marketing ROI.",
minimumSupportedRelease: '0.20.0',
logoUrl: "https://cdn.activepieces.com/pieces/zerobounce.png",
authors: ["abuaboud"],
actions: [validateEmail],
triggers: [],
});
@@ -0,0 +1,40 @@
import { zerobounceAuth } from '../..';
import { createAction, Property, StoreScope } from '@activepieces/pieces-framework';
import { httpClient, HttpMethod } from '@activepieces/pieces-common';
import { isNil } from '@activepieces/shared';

export const validateEmail = createAction({
name: 'validateEmail',
displayName: 'Validate Email',
description: '',
props: {
email: Property.ShortText({
displayName: 'Email',
required: true,
}),
cacheResponse: Property.Checkbox({
displayName: 'Cache Response',
description: 'Store the response in the project store for future use.',
required: false,
defaultValue: true,
}),
},
auth: zerobounceAuth,
async run({ store, propsValue, auth }) {
const key = `_zerobounce_${propsValue.email}`;
if (propsValue.cacheResponse) {
const cachedResponse = await store.get(key, StoreScope.PROJECT);
if (!isNil(cachedResponse)) {
return cachedResponse
}
}
const res = await httpClient.sendRequest<string[]>({
method: HttpMethod.GET,
url: `https://api.zerobounce.net/v2/validate?email=${propsValue.email}&api_key=${auth}`,
});
if (propsValue.cacheResponse) {
await store.put(key, res.body, StoreScope.PROJECT);
}
return res.body;
},
});
19 changes: 19 additions & 0 deletions packages/pieces/community/zerobounce/tsconfig.json
@@ -0,0 +1,19 @@
{
"extends": "../../../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
}
]
}
11 changes: 11 additions & 0 deletions packages/pieces/community/zerobounce/tsconfig.lib.json
@@ -0,0 +1,11 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"outDir": "../../../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"]
}
3 changes: 3 additions & 0 deletions tsconfig.base.json
Expand Up @@ -572,6 +572,9 @@
"@activepieces/piece-zendesk": [
"packages/pieces/community/zendesk/src/index.ts"
],
"@activepieces/piece-zerobounce": [
"packages/pieces/community/zerobounce/src/index.ts"
],
"@activepieces/piece-zoho-crm": [
"packages/pieces/community/zoho-crm/src/index.ts"
],
Expand Down

0 comments on commit 957ecdf

Please sign in to comment.