-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New Components - smashsend #17511
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
Merged
Merged
New Components - smashsend #17511
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
components/smashsend/actions/create-or-update-contact/create-or-update-contact.mjs
This file contains hidden or 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,76 @@ | ||
import smashsend from "../../smashsend.app.mjs"; | ||
import { parseObject } from "../../common/utils.mjs"; | ||
|
||
export default { | ||
key: "smashsend-create-or-update-contact", | ||
name: "Create or Update Contact", | ||
description: "Create a new contact or update an existing contact. [See the documentation](https://smashsend.com/docs/api/contacts)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
smashsend, | ||
email: { | ||
type: "string", | ||
label: "Email", | ||
description: "The email address of the contact. If the contact already exists, this will update the contact.", | ||
}, | ||
firstName: { | ||
type: "string", | ||
label: "First Name", | ||
description: "The first name of the contact", | ||
optional: true, | ||
}, | ||
lastName: { | ||
type: "string", | ||
label: "Last Name", | ||
description: "The last name of the contact", | ||
optional: true, | ||
}, | ||
phone: { | ||
type: "string", | ||
label: "Phone", | ||
description: "The phone number of the contact", | ||
optional: true, | ||
}, | ||
avatarUrl: { | ||
type: "string", | ||
label: "Avatar URL", | ||
description: "The URL of the contact's avatar", | ||
optional: true, | ||
}, | ||
countryCode: { | ||
type: "string", | ||
label: "Country Code", | ||
description: "Two-letter ISO country code like `US`", | ||
optional: true, | ||
}, | ||
properties: { | ||
type: "object", | ||
label: "Properties", | ||
description: "Additional properties of the contact. Properties must exist in your workspace.", | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { contact } = await this.smashsend.createContact({ | ||
$, | ||
data: { | ||
properties: { | ||
email: this.email, | ||
firstName: this.firstName, | ||
lastName: this.lastName, | ||
phone: this.phone, | ||
avatarUrl: this.avatarUrl, | ||
countryCode: this.countryCode, | ||
...parseObject(this.properties), | ||
}, | ||
}, | ||
}); | ||
if (contact?.id) { | ||
$.export("$summary", `Successfully ${contact.updatedAt | ||
? "updated" | ||
: "created"} contact ${contact.id}`); | ||
} | ||
return contact; | ||
}, | ||
}; |
26 changes: 26 additions & 0 deletions
26
components/smashsend/actions/delete-contact/delete-contact.mjs
This file contains hidden or 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,26 @@ | ||
import smashsend from "../../smashsend.app.mjs"; | ||
|
||
export default { | ||
key: "smashsend-delete-contact", | ||
name: "Delete Contact", | ||
description: "Delete a contact. [See the documentation](https://smashsend.com/docs/api/contacts)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
smashsend, | ||
contactId: { | ||
propDefinition: [ | ||
smashsend, | ||
"contactId", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.smashsend.deleteContact({ | ||
$, | ||
contactId: this.contactId, | ||
}); | ||
$.export("$summary", `Successfully deleted contact ${this.contactId}`); | ||
return response; | ||
}, | ||
}; |
62 changes: 62 additions & 0 deletions
62
components/smashsend/actions/list-contacts/list-contacts.mjs
This file contains hidden or 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,62 @@ | ||
import smashsend from "../../smashsend.app.mjs"; | ||
|
||
export default { | ||
key: "smashsend-list-contacts", | ||
name: "List Contacts", | ||
description: "List all contacts. [See the documentation](https://smashsend.com/docs/api/contacts)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
smashsend, | ||
sort: { | ||
type: "string", | ||
label: "Sort", | ||
description: "Sort order: “createdAt.desc” or “createdAt.asc” (default: “createdAt.desc”)", | ||
options: [ | ||
"createdAt.desc", | ||
"createdAt.asc", | ||
], | ||
optional: true, | ||
}, | ||
search: { | ||
type: "string", | ||
label: "Search", | ||
description: "Search for contacts by name, email, or phone number", | ||
optional: true, | ||
}, | ||
status: { | ||
type: "string", | ||
label: "Status", | ||
description: "Filter contacts by status", | ||
options: [ | ||
"SUBSCRIBED", | ||
"UNSUBSCRIBED", | ||
"BANNED", | ||
], | ||
optional: true, | ||
}, | ||
maxResults: { | ||
type: "integer", | ||
label: "Max Results", | ||
description: "The maximum number of results to return", | ||
default: 100, | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const contacts = await this.smashsend.getPaginatedResources({ | ||
fn: this.smashsend.listContacts, | ||
params: { | ||
sort: this.sort, | ||
search: this.search, | ||
status: this.status, | ||
}, | ||
resourceKey: "contacts", | ||
max: this.maxResults, | ||
}); | ||
$.export("$summary", `Successfully fetched ${contacts.length} contact${contacts.length === 1 | ||
? "" | ||
: "s"}`); | ||
return contacts; | ||
}, | ||
}; |
29 changes: 29 additions & 0 deletions
29
components/smashsend/actions/search-contacts/search-contacts.mjs
This file contains hidden or 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,29 @@ | ||
import smashsend from "../../smashsend.app.mjs"; | ||
|
||
export default { | ||
key: "smashsend-search-contacts", | ||
name: "Search Contacts", | ||
description: "Search for contacts by email address. [See the documentation](https://smashsend.com/docs/api/contacts)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
smashsend, | ||
email: { | ||
type: "string", | ||
label: "Email", | ||
description: "The email address to search for", | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const { contact } = await this.smashsend.searchContacts({ | ||
$, | ||
params: { | ||
email: this.email, | ||
}, | ||
}); | ||
if (contact?.id) { | ||
$.export("$summary", `Successfully fetched contact ${contact.id}`); | ||
} | ||
return contact; | ||
}, | ||
}; |
This file contains hidden or 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,25 @@ | ||
export const parseObject = (obj) => { | ||
if (!obj) { | ||
return {}; | ||
} | ||
if (typeof obj === "string") { | ||
try { | ||
return JSON.parse(obj); | ||
} catch { | ||
return obj; | ||
} | ||
} | ||
if (Array.isArray(obj)) { | ||
return obj.map(parseObject); | ||
} | ||
if (typeof obj === "object") { | ||
return Object.fromEntries(Object.entries(obj).map(([ | ||
key, | ||
value, | ||
]) => [ | ||
key, | ||
parseObject(value), | ||
])); | ||
} | ||
return obj; | ||
}; |
This file contains hidden or 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/smashsend", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream SmashSend Components", | ||
"main": "smashsend.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,8 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^3.1.0" | ||
} | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,11 +1,132 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "smashsend", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
contactId: { | ||
type: "string", | ||
label: "Contact ID", | ||
description: "The ID of the contact to update", | ||
async options({ prevContext }) { | ||
const params = prevContext?.cursor | ||
? { | ||
cursor: prevContext.cursor, | ||
} | ||
: {}; | ||
const { contacts } = await this.listContacts(params); | ||
const { | ||
items, cursor, | ||
} = contacts; | ||
return { | ||
options: items?.map(({ | ||
id: value, properties: { | ||
firstName, lastName, email, | ||
}, | ||
}) => ({ | ||
label: (firstName || lastName) | ||
? (`${firstName} ${lastName}`).trim() + " - " + email | ||
: email, | ||
value, | ||
})) || [], | ||
context: { | ||
cursor, | ||
}, | ||
}; | ||
}, | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://api.smashsend.com/v1"; | ||
}, | ||
_makeRequest({ | ||
$ = this, path, ...opts | ||
}) { | ||
return axios($, { | ||
url: `${this._baseUrl()}${path}`, | ||
headers: { | ||
Authorization: `Bearer ${this.$auth.api_key}`, | ||
}, | ||
...opts, | ||
}); | ||
}, | ||
createWebhook(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/webhooks", | ||
...opts, | ||
}); | ||
}, | ||
deleteWebhook({ | ||
hookId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "DELETE", | ||
path: `/webhooks/${hookId}`, | ||
...opts, | ||
}); | ||
}, | ||
listContacts(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/contacts", | ||
...opts, | ||
}); | ||
}, | ||
searchContacts(opts = {}) { | ||
return this._makeRequest({ | ||
path: "/contacts/search", | ||
...opts, | ||
}); | ||
}, | ||
createContact(opts = {}) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/contacts", | ||
...opts, | ||
}); | ||
}, | ||
deleteContact({ | ||
contactId, ...opts | ||
}) { | ||
return this._makeRequest({ | ||
method: "DELETE", | ||
path: `/contacts/${contactId}`, | ||
...opts, | ||
}); | ||
}, | ||
async *paginate({ | ||
fn, params = {}, resourceKey, max, | ||
}) { | ||
let count = 0; | ||
do { | ||
const response = await fn({ | ||
params, | ||
}); | ||
const { | ||
cursor, hasMore, items, | ||
} = response[resourceKey]; | ||
if (!items?.length) { | ||
return; | ||
} | ||
for (const item of items) { | ||
yield item; | ||
if (max && ++count >= max) { | ||
return; | ||
} | ||
} | ||
if (!hasMore) { | ||
return; | ||
} | ||
params.cursor = cursor; | ||
} while (true); | ||
}, | ||
async getPaginatedResources(opts) { | ||
const results = []; | ||
for await (const item of this.paginate(opts)) { | ||
results.push(item); | ||
} | ||
return results; | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.