Skip to content

Commit

Permalink
feat: create contact on constant contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
abuaboud committed Mar 27, 2023
1 parent d7d86b7 commit 3465b8d
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/pieces/apps/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { square } from '@activepieces/piece-square';
import { delay } from '@activepieces/piece-delay';
import { dataMapper } from '@activepieces/piece-data-mapper';
import { schedule } from '@activepieces/piece-schedule';
import { constantContact } from '@activepieces/piece-constant-contact';

export const pieces: Piece[] = [
airtable,
Expand Down Expand Up @@ -98,7 +99,8 @@ export const pieces: Piece[] = [
delay,
dataMapper,
intercom,
schedule
schedule,
constantContact
].sort((a, b) => a.displayName > b.displayName ? 1 : -1);

export const getPiece = (name: string): Piece | undefined => {
Expand Down
18 changes: 18 additions & 0 deletions packages/pieces/constant-contact/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../../.eslintrc.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/constant-contact/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pieces-constant-contact

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

## Running lint

Run `nx lint pieces-constant-contact` to execute the lint via [ESLint](https://eslint.org/).
4 changes: 4 additions & 0 deletions packages/pieces/constant-contact/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@activepieces/piece-constant-contact",
"version": "0.0.1"
}
36 changes: 36 additions & 0 deletions packages/pieces/constant-contact/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "pieces-constant-contact",
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/pieces/constant-contact/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nrwl/js:tsc",
"outputs": [
"{options.outputPath}"
],
"options": {
"outputPath": "dist/packages/pieces/constant-contact",
"tsConfig": "packages/pieces/constant-contact/tsconfig.lib.json",
"packageJson": "packages/pieces/constant-contact/package.json",
"main": "packages/pieces/constant-contact/src/index.ts",
"assets": [
"packages/pieces/constant-contact/*.md"
],
"buildableProjectDepsInPackageJsonType": "dependencies"
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": [
"{options.outputFile}"
],
"options": {
"lintFilePatterns": [
"packages/pieces/constant-contact/**/*.ts"
]
}
}
},
"tags": []
}
14 changes: 14 additions & 0 deletions packages/pieces/constant-contact/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

import { createPiece } from "@activepieces/framework";
import packageJson from "../package.json";
import { createOrUpdateContact } from "./lib/actions/create-or-update-contact";

export const constantContact = createPiece({
name: "constant-contact",
displayName: "Constant Contact",
logoUrl: "https://cdn.activepieces.com/pieces/constant-contact.png",
version: packageJson.version,
authors: ["abuaboud"],
actions: [createOrUpdateContact],
triggers: [],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { AuthenticationType, createAction, httpClient, HttpMethod, OAuth2PropertyValue, Property } from "@activepieces/framework";
import { constantContactProps } from "../common/props";


export const createOrUpdateContact = createAction({
name: "create_or_update_contact",
displayName: "Create or Update Contact",
description: "Create or Update a contact in Constant Contact",
props: {
authentication: constantContactProps.authentication,
list: Property.MultiSelectDropdown({
displayName: "List",
description: "The list of the contact",
required: true,
refreshers: ['authentication'],
options: async (propsValue) => {
if (!propsValue['authentication']) {
return {
options: [],
placeholder: "Connect to Constant Contact to see the lists",
disabled: true
}
}
return {
placeholder: "Select a list",
disabled: false,
options: (await httpClient.sendRequest<{ lists: { list_id: string, name: string }[] }>({
url: "https://api.cc.email/v3/contact_lists",
method: HttpMethod.GET,
authentication: {
type: AuthenticationType.BEARER_TOKEN,
token: (propsValue['authentication'] as OAuth2PropertyValue)['access_token']
}
})).body.lists.map(list => {
return {
value: list.list_id,
label: list.name
}
})
}
}
}),
email_address: Property.ShortText({
displayName: "Email",
description: "The email of the contact",
required: true,
}),
first_name: Property.ShortText({
displayName: "First Name",
description: "The first name of the contact",
required: false,
}),
last_name: Property.ShortText({
displayName: "Last Name",
description: "The last name of the contact",
required: false,
}),
job_title: Property.ShortText({
displayName: "Job Title",
description: "The job title of the contact",
required: false,
}),
company_name: Property.ShortText({
displayName: "Company Name",
description: "The company name of the contact",
required: false,
}),
phoner_number: Property.ShortText({
displayName: "Phone Number",
description: "The phone number of the contact",
required: false,
})
},
sampleData: {
},
run: async (ctx) => {
return await httpClient.sendRequest({
url: "https://api.cc.email/v3/contacts/sign_up_form",
method: HttpMethod.POST,
authentication: {
type: AuthenticationType.BEARER_TOKEN,
token: ctx.propsValue.authentication.access_token
},
body: {
"email_address": ctx.propsValue.email_address,
"first_name": ctx.propsValue.first_name,
"last_name": ctx.propsValue.last_name,
"job_title": ctx.propsValue.job_title,
"company_name": ctx.propsValue.company_name,
"phoner_number": ctx.propsValue.phoner_number,
"list_memberships": ctx.propsValue.list
}
})
}
});
11 changes: 11 additions & 0 deletions packages/pieces/constant-contact/src/lib/common/props.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Property } from "@activepieces/framework";

export const constantContactProps = {
authentication: Property.OAuth2({
displayName: "Authentication",
required: true,
tokenUrl: "https://authz.constantcontact.com/oauth2/default/v1/token",
authUrl: "https://authz.constantcontact.com/oauth2/default/v1/authorize",
scope: ["contact_data"]
})
}
16 changes: 16 additions & 0 deletions packages/pieces/constant-contact/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
}
],
"compilerOptions": {
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
}
}
11 changes: 11 additions & 0 deletions packages/pieces/constant-contact/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
"@activepieces/piece-connections": [
"packages/pieces/connections/src/index.ts"
],
"@activepieces/piece-constant-contact": [
"packages/pieces/constant-contact/src/index.ts"
],
"@activepieces/piece-csv": ["packages/pieces/csv/src/index.ts"],
"@activepieces/piece-data-mapper": [
"packages/pieces/data-mapper/src/index.ts"
Expand Down

0 comments on commit 3465b8d

Please sign in to comment.