Skip to content

Commit 145048b

Browse files
committed
Merge remote-tracking branch 'origin/master' into connect/invocation-sdk-fixes
2 parents f4153fc + 6e824a8 commit 145048b

File tree

15 files changed

+244
-223
lines changed

15 files changed

+244
-223
lines changed

components/mailerlite/actions/create-subscriber/create-subscriber.mjs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import mailerlite from "../../mailerlite.app.mjs";
44
export default {
55
key: "mailerlite-create-subscriber",
66
name: "Create Subscriber",
7-
description: "Create a new subscriber. [See docs](https://developers.mailerlite.com/docs/subscribers.html#create-update-subscriber)",
8-
version: "0.0.3",
7+
description: "Create a new subscriber. [See the documentation](https://developers.mailerlite.com/docs/subscribers.html#create-update-subscriber)",
8+
version: "0.0.4",
99
type: "action",
1010
props: {
1111
mailerlite,
@@ -34,11 +34,16 @@ export default {
3434
async run({ $ }) {
3535
const data = {
3636
email: this.email,
37-
name: this.name,
38-
type: this.type,
37+
fields: {
38+
name: this.name,
39+
},
40+
status: this.type,
3941
};
4042

41-
const resp = await this.mailerlite.createSubscriber(utils.removeUndefined(data));
43+
const resp = await this.mailerlite.createSubscriber({
44+
$,
45+
data: utils.removeUndefined(data),
46+
});
4247
$.export("$summary", "Successfully created subscriber");
4348
return resp;
4449
},

components/mailerlite/actions/list-subscribers/list-subscribers.mjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import mailerlite from "../../mailerlite.app.mjs";
44
export default {
55
key: "mailerlite-list-subscribers",
66
name: "List Subscribers",
7-
description: "Lists all subscribers in a group. [See the docs here](https://developers.mailerlite.com/docs/subscribers.html#list-all-subscribers)",
8-
version: "0.0.3",
7+
description: "Lists all subscribers in a group. [See the documentation](https://developers.mailerlite.com/docs/subscribers.html#list-all-subscribers)",
8+
version: "0.0.4",
99
type: "action",
1010
props: {
1111
mailerlite,
@@ -42,7 +42,11 @@ export default {
4242
let resp;
4343

4444
do {
45-
resp = await this.mailerlite.listSubscribers(this.group, params);
45+
resp = await this.mailerlite.listSubscribers({
46+
$,
47+
group: this.group,
48+
params,
49+
});
4650
subscribers.push(...resp);
4751
params.offset += params.limit;
4852
} while (resp?.length === params.limit);

components/mailerlite/actions/remove-subscriber-from-group/remove-subscriber-from-group.mjs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import mailerlite from "../../mailerlite.app.mjs";
33
export default {
44
key: "mailerlite-remove-subscriber-from-group",
55
name: "Remove Subscriber From Group",
6-
description: "Removes single subscriber from specified group. [See the docs here](https://developers.mailerlite.com/docs/groups.html#unassign-subscriber-from-a-group)",
7-
version: "0.0.4",
6+
description: "Removes single subscriber from specified group. [See the documentation](https://developers.mailerlite.com/docs/groups.html#unassign-subscriber-from-a-group)",
7+
version: "0.0.5",
88
type: "action",
99
props: {
1010
mailerlite,
@@ -37,10 +37,11 @@ export default {
3737
},
3838
},
3939
async run({ $ }) {
40-
const response = await this.mailerlite.removeSubscriberFromGroup(
41-
this.group,
42-
encodeURIComponent(this.subscriber),
43-
);
40+
const response = await this.mailerlite.removeSubscriberFromGroup({
41+
$,
42+
subscriber: this.subscriber,
43+
group: this.group,
44+
});
4445

4546
$.export("$summary", "Removed subscriber from group");
4647

components/mailerlite/actions/subscribe-to-group/subscribe-to-group.mjs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import mailerlite from "../../mailerlite.app.mjs";
33
export default {
44
key: "mailerlite-subscribe-to-group",
55
name: "Subscribe to MailerLite Group",
6-
description: "Add a subscriber to a group. [See the docs here](https://developers.mailerlite.com/docs/groups.html#assign-subscriber-to-a-group)",
7-
version: "0.3.2",
6+
description: "Add a subscriber to a group. [See the documentation](https://developers.mailerlite.com/docs/groups.html#assign-subscriber-to-a-group)",
7+
version: "0.3.3",
88
type: "action",
99
props: {
1010
mailerlite,
@@ -14,19 +14,20 @@ export default {
1414
"group",
1515
],
1616
},
17-
email: {
17+
subscriber: {
1818
propDefinition: [
1919
mailerlite,
2020
"subscriber",
2121
],
22-
description: "Email of the active subscriber to add to group",
22+
description: "ID of the active subscriber to add to group",
2323
},
2424
},
2525
async run({ $ }) {
26-
const data = {
27-
email: this.email,
28-
};
29-
const resp = await this.mailerlite.addSubscriberToGroup(data, this.group);
26+
const resp = await this.mailerlite.addSubscriberToGroup({
27+
$,
28+
subscriber: this.subscriber,
29+
group: this.group,
30+
});
3031
$.export("$summary", "Added subscriber to group");
3132
return resp;
3233
},

components/mailerlite/actions/update-subscriber/update-subscriber.mjs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import mailerlite from "../../mailerlite.app.mjs";
33
export default {
44
key: "mailerlite-update-subscriber",
55
name: "Update Subscriber",
6-
description: "Updates single active subscriber. [See docs](https://developers.mailerlite.com/docs/subscribers.html#create-update-subscriber)",
7-
version: "0.0.3",
6+
description: "Updates single active subscriber. [See the documentation](https://developers.mailerlite.com/docs/subscribers.html#create-update-subscriber)",
7+
version: "0.0.4",
88
type: "action",
99
props: {
1010
mailerlite,
@@ -34,6 +34,9 @@ export default {
3434
},
3535
async additionalProps() {
3636
const props = {};
37+
if (!this.fields?.length) {
38+
return props;
39+
}
3740
for (const field of this.fields) {
3841
props[field.value] = {
3942
type: "string",
@@ -45,14 +48,20 @@ export default {
4548
},
4649
async run({ $ }) {
4750
const fields = {};
48-
for (const field of this.fields) {
49-
fields[field.value] = this[field.value];
51+
if (this.fields?.length) {
52+
for (const field of this.fields) {
53+
fields[field.value] = this[field.value];
54+
}
5055
}
5156
const data = {
52-
type: this.type,
57+
status: this.type,
5358
fields,
5459
};
55-
const resp = await this.mailerlite.updateSubscriber(data, this.subscriber);
60+
const resp = await this.mailerlite.updateSubscriber({
61+
$,
62+
subscriber: this.subscriber,
63+
data,
64+
});
5665
$.export("$summary", "Successfully updated subscriber");
5766
return resp;
5867
},

components/mailerlite/mailerlite.app.mjs

Lines changed: 104 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import MailerLite from "mailerlite-api-v2-node";
1+
import { axios } from "@pipedream/platform";
22
import constants from "./common/constants.mjs";
33

44
export default {
@@ -54,11 +54,14 @@ export default {
5454
limit,
5555
offset,
5656
};
57-
const subscribers = await this.listSubscribers(group, params);
57+
const subscribers = await this.listSubscribers({
58+
group,
59+
params,
60+
});
5861
return {
5962
options: subscribers.map((subscriber) => ({
60-
label: subscriber.name,
61-
value: subscriber.email,
63+
label: subscriber.email,
64+
value: subscriber.id,
6265
})),
6366
context: {
6467
offset: offset + limit,
@@ -77,7 +80,9 @@ export default {
7780
limit,
7881
offset,
7982
};
80-
const groups = await this.listGroups(params);
83+
const groups = await this.listGroups({
84+
params,
85+
});
8186
return {
8287
options: groups.map((group) => ({
8388
label: group.name,
@@ -106,67 +111,100 @@ export default {
106111
},
107112
},
108113
methods: {
109-
_getApiKey() {
110-
return this.$auth.api_key;
111-
},
112-
async _getClient(baseAPI) {
113-
let options;
114-
if (baseAPI === "connect") {
115-
options = {
116-
baseURL: "https://connect.mailerlite.com/api",
117-
headers: {
118-
Authorization: `Bearer ${this._getApiKey()}`,
119-
},
120-
};
121-
}
122-
const client = MailerLite.default;
123-
return client(this._getApiKey(), options);
124-
},
125-
async listGroups(params) {
126-
const client = await this._getClient();
127-
return client.getGroups(params);
128-
},
129-
async listSubscribers(group, params = {}) {
130-
const client = await this._getClient();
131-
if (group) {
132-
const { type = "active" } = params;
133-
delete params.type;
134-
return client.getGroupSubscribersByType(group, type, params);
135-
}
136-
// getSubscribers returns active subscribers only
137-
return client.getSubscribers(params);
138-
},
139-
async listFields() {
140-
const client = await this._getClient();
141-
return client.getFields();
142-
},
143-
async listCampaigns(status = "sent") {
144-
const client = await this._getClient();
145-
return client.getCampaigns(status);
146-
},
147-
async createSubscriber(data) {
148-
const client = await this._getClient();
149-
return client.addSubscriber(data);
150-
},
151-
async createHook(data) {
152-
const client = await this._getClient("connect");
153-
return client.createWebhook(data);
154-
},
155-
async updateSubscriber(data, subscriber) {
156-
const client = await this._getClient();
157-
return client.updateSubscriber(subscriber, data);
158-
},
159-
async addSubscriberToGroup(data, group) {
160-
const client = await this._getClient();
161-
return client.addSubscriberToGroup(group, data);
162-
},
163-
async removeHook(hookId) {
164-
const client = await this._getClient("connect");
165-
return client.removeWebhook(hookId);
166-
},
167-
async removeSubscriberFromGroup(group, subscriber) {
168-
const client = await this._getClient();
169-
return client.removeGroupSubscriber(group, subscriber);
114+
_baseUrl() {
115+
return "https://connect.mailerlite.com/api";
116+
},
117+
_makeRequest({
118+
$ = this,
119+
path,
120+
...args
121+
}) {
122+
return axios($, {
123+
url: `${this._baseUrl()}${path}`,
124+
headers: {
125+
Authorization: `Bearer ${this.$auth.api_key}`,
126+
},
127+
...args,
128+
});
129+
},
130+
async listGroups(opts = {}) {
131+
const { data } = await this._makeRequest({
132+
path: "/groups",
133+
...opts,
134+
});
135+
return data;
136+
},
137+
async listSubscribers({
138+
group, params = {}, ...opts
139+
}) {
140+
const { type = "active" } = params;
141+
delete params.type;
142+
params["filter[status]"] = type;
143+
const { data } = await this._makeRequest({
144+
path: group
145+
? `/groups/${group}/subscribers`
146+
: "/subscribers",
147+
params,
148+
...opts,
149+
});
150+
return data;
151+
},
152+
async listFields(opts = {}) {
153+
const { data } = await this._makeRequest({
154+
path: "/fields",
155+
...opts,
156+
});
157+
return data;
158+
},
159+
createSubscriber(opts = {}) {
160+
return this._makeRequest({
161+
method: "POST",
162+
path: "/subscribers",
163+
...opts,
164+
});
165+
},
166+
createHook(opts = {}) {
167+
return this._makeRequest({
168+
method: "POST",
169+
path: "/webhooks",
170+
...opts,
171+
});
172+
},
173+
updateSubscriber({
174+
subscriber, ...opts
175+
}) {
176+
return this._makeRequest({
177+
method: "PUT",
178+
path: `/subscribers/${subscriber}`,
179+
...opts,
180+
});
181+
},
182+
addSubscriberToGroup({
183+
subscriber, group, ...opts
184+
}) {
185+
return this._makeRequest({
186+
method: "POST",
187+
path: `/subscribers/${subscriber}/groups/${group}`,
188+
...opts,
189+
});
190+
},
191+
removeHook({
192+
hookId, ...opts
193+
}) {
194+
return this._makeRequest({
195+
method: "DELETE",
196+
path: `/webhooks/${hookId}`,
197+
...opts,
198+
});
199+
},
200+
removeSubscriberFromGroup({
201+
subscriber, group, ...opts
202+
}) {
203+
return this._makeRequest({
204+
method: "DELETE",
205+
path: `/subscribers/${subscriber}/groups/${group}`,
206+
...opts,
207+
});
170208
},
171209
},
172210
};

components/mailerlite/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/mailerlite",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Pipedream Mailerlite Components",
55
"main": "mailerlite.app.mjs",
66
"keywords": [
@@ -14,7 +14,7 @@
1414
"access": "public"
1515
},
1616
"dependencies": {
17-
"lodash.pickby": "^4.6.0",
18-
"mailerlite-api-v2-node": "^1.2.0"
17+
"@pipedream/platform": "^3.0.3",
18+
"lodash.pickby": "^4.6.0"
1919
}
2020
}

0 commit comments

Comments
 (0)