-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create contact on constant contacts
- Loading branch information
Showing
11 changed files
with
218 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "@activepieces/piece-constant-contact", | ||
"version": "0.0.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [], | ||
}); |
95 changes: 95 additions & 0 deletions
95
packages/pieces/constant-contact/src/lib/actions/create-or-update-contact.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
}) | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters