Skip to content
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
47 changes: 47 additions & 0 deletions components/loops_so/actions/common/common-create-update.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable no-unused-vars */
import pickBy from "lodash.pickby";
import { parseObject } from "../../common/utils.mjs";
import loops from "../../loops_so.app.mjs";

export default {
Expand Down Expand Up @@ -31,17 +34,61 @@ export default {
"lastName",
],
},
source: {
propDefinition: [
loops,
"source",
],
},
subscribed: {
propDefinition: [
loops,
"subscribed",
],
},
userGroup: {
propDefinition: [
loops,
"userGroup",
],
},
userId: {
propDefinition: [
loops,
"userId",
],
},
mailingLists: {
propDefinition: [
loops,
"mailingLists",
],
},
customFields: {
propDefinition: [
loops,
"customFields",
],
},
},
methods: {
prepareData() {
const {
loops,
customFields,
mailingLists,
...data
} = this;

const mailingListObject = {};
for (const item of (parseObject(mailingLists) || [])) {
mailingListObject[item] = true;
}

return pickBy({
mailingLists: mailingListObject,
...data,
});
},
},
};
15 changes: 3 additions & 12 deletions components/loops_so/actions/create-contact/create-contact.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,11 @@ export default {
key: "loops_so-create-contact",
name: "Create Contact",
description: "Creates a new contact. [See the Documentation](https://loops.so/docs/add-users/api-reference#add)",
version: "0.1.1",
version: "0.2.0",
type: "action",
async run({ $ }) {
const { // eslint-disable-next-line no-unused-vars
loops, email, firstName, lastName, userGroup, customFields, ...data
} = this;
const response = await loops.createContact({
data: {
email,
firstName,
lastName,
userGroup,
...data,
},
const response = await this.loops.createContact({
data: this.prepareData(),
$,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "loops_so-delete-contact",
name: "Delete Contact",
description: "Delete an existing contact. [See the documentation](https://loops.so/docs/api-reference/delete-contact)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
loops,
Expand Down
2 changes: 1 addition & 1 deletion components/loops_so/actions/find-contact/find-contact.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "loops_so-find-contact",
name: "Find Contact",
description: "Search for a contact by email address. [See the Documentation](https://loops.so/docs/add-users/api-reference#find)",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
loops,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "loops_so-list-custom-fields",
name: "List Custom Fields",
description: "List your account's custom contact properties. [See the documentation](https://loops.so/docs/api-reference/list-custom-fields)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
loops,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "loops_so-list-mailing-lists",
name: "List Mailing Lists",
description: "List your account's mailing lists. [See the documentation](https://loops.so/docs/api-reference/list-mailing-lists)",
version: "0.0.1",
version: "0.0.2",
type: "action",
props: {
loops,
Expand Down
2 changes: 1 addition & 1 deletion components/loops_so/actions/send-event/send-event.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "loops_so-send-event",
name: "Send Event",
description: "Send an event to an email address. [See the Documentation](https://loops.so/docs/add-users/api-reference#send)",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
loops,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
key: "loops_so-send-transactional-email",
name: "Send Transactional Email",
description: "Send a transactional email. [See the Documentation](https://loops.so/docs/transactional/guide#send-your-email)",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
loops,
Expand Down
16 changes: 3 additions & 13 deletions components/loops_so/actions/update-contact/update-contact.mjs
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
import common from "../common/common-create-update.mjs";
import pickBy from "lodash.pickby";

export default {
...common,
key: "loops_so-update-contact",
name: "Update Contact",
description: "Updates an existing contact by email. If email not found, a new contact will be created. [See the Documentation](https://loops.so/docs/add-users/api-reference#update)",
version: "0.1.1",
version: "0.2.0",
type: "action",
async run({ $ }) {
const { // eslint-disable-next-line no-unused-vars
loops, email, firstName, lastName, userGroup, customFields, ...data
} = this;
const response = await loops.updateContact({
data: pickBy({
email,
firstName,
lastName,
userGroup,
...data,
}),
const response = await this.loops.updateContact({
data: this.prepareData(),
$,
});

Expand Down
24 changes: 24 additions & 0 deletions components/loops_so/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
34 changes: 34 additions & 0 deletions components/loops_so/loops_so.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,46 @@ export default {
description: "The last name of the contact",
optional: true,
},
source: {
type: "string",
label: "Source",
description: "A custom source value to replace the default **API**. [Read more](https://loops.so/docs/contacts/properties#source).",
optional: true,
},
subscribed: {
type: "boolean",
label: "Subscribed",
description: "Whether the contact will receive campaign and loops emails. [Read more](https://loops.so/docs/contacts/properties#subscribed).",
optional: true,
},
userGroup: {
type: "string",
label: "User Group",
description: "User group of the contact",
optional: true,
},
userId: {
type: "string",
label: "User Id",
description: "A unique user ID (for example, from an external application). [Read more](https://loops.so/docs/contacts/properties#user-id).",
optional: true,
},
mailingLists: {
type: "string[]",
label: "Mailing Lists",
description: "A list of mailing list IDs",
async options() {
const data = await this.listMailingLists();
return data.map(({
id: value,
name: label,
}) => ({
label,
value,
}));
},
optional: true,
},
customFields: {
type: "string[]",
label: "Custom Fields",
Expand Down
2 changes: 1 addition & 1 deletion components/loops_so/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/loops_so",
"version": "0.3.0",
"version": "0.3.1",
"description": "Pipedream Loops.so Components",
"main": "loops_so.app.mjs",
"keywords": [
Expand Down
Loading