Skip to content

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 3 commits into from
Jul 9, 2025
Merged
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
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 components/smashsend/actions/delete-contact/delete-contact.mjs
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 components/smashsend/actions/list-contacts/list-contacts.mjs
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 components/smashsend/actions/search-contacts/search-contacts.mjs
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;
},
};
25 changes: 25 additions & 0 deletions components/smashsend/common/utils.mjs
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;
};
7 changes: 5 additions & 2 deletions components/smashsend/package.json
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": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.0"
}
}
}
129 changes: 125 additions & 4 deletions components/smashsend/smashsend.app.mjs
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;
},
},
};
Loading
Loading