Skip to content

Commit 310be99

Browse files
Merge branch 'master' into danny/updating-connect-oauth-client-docs
2 parents 79c8ec0 + 4227fec commit 310be99

File tree

17 files changed

+450
-22
lines changed

17 files changed

+450
-22
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import mergemole from "../../mergemole.app.mjs";
2+
import { ConfigurationError } from "@pipedream/platform";
3+
import fs from "fs";
4+
5+
export default {
6+
key: "mergemole-generate-pdf",
7+
name: "Generate PDF",
8+
description: "Generate a PDF document based on the specified template. [See the documentation](https://documenter.getpostman.com/view/41321603/2sB2j3AWqz#a389449f-ada9-4e2e-9d8a-f1bde20da980)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
mergemole,
13+
templateId: {
14+
propDefinition: [
15+
mergemole,
16+
"templateId",
17+
],
18+
reloadProps: true,
19+
},
20+
documentName: {
21+
type: "string",
22+
label: "Document Name",
23+
description: "The name of the generated PDF document",
24+
},
25+
},
26+
async additionalProps() {
27+
const props = {};
28+
if (!this.templateId) {
29+
return props;
30+
}
31+
const templateVariables = await this.mergemole.getTemplateVariables({
32+
templateId: this.templateId,
33+
});
34+
if (!templateVariables?.length) {
35+
throw new ConfigurationError(`No template variables found for template \`${this.templateId}\``);
36+
}
37+
for (const variable of templateVariables) {
38+
props[variable.key] = {
39+
type: "string",
40+
label: variable.label,
41+
optional: true,
42+
};
43+
}
44+
return props;
45+
},
46+
async run({ $ }) {
47+
const {
48+
mergemole,
49+
templateId,
50+
documentName,
51+
...templateVariables
52+
} = this;
53+
54+
const data = [];
55+
for (const [
56+
key,
57+
value,
58+
] of Object.entries(templateVariables)) {
59+
data.push({
60+
placeholder: key,
61+
value,
62+
});
63+
}
64+
65+
const response = await mergemole.generatePdf({
66+
$,
67+
data: {
68+
data,
69+
template_id: templateId,
70+
document_name: documentName,
71+
},
72+
responseType: "arraybuffer",
73+
});
74+
75+
fs.writeFileSync(`/tmp/${documentName}`, Buffer.from(response));
76+
77+
$.export("$summary", "Successfully generated PDF");
78+
79+
return {
80+
filename: documentName,
81+
downloadedFilepath: `/tmp/${documentName}`,
82+
};
83+
},
84+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import mergemole from "../../mergemole.app.mjs";
2+
3+
export default {
4+
key: "mergemole-get-template-variables",
5+
name: "Get Template Variables",
6+
description: "Get all data variables of a specified template. [See the documentation](https://documenter.getpostman.com/view/41321603/2sB2j3AWqz#14da32c9-9b15-421e-89c9-8a977b04dc32)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
mergemole,
11+
templateId: {
12+
propDefinition: [
13+
mergemole,
14+
"templateId",
15+
],
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.mergemole.getTemplateVariables({
20+
$,
21+
templateId: this.templateId,
22+
});
23+
$.export("$summary", `Successfully retrieved variables for template with ID: ${this.templateId}`);
24+
return response;
25+
},
26+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import mergemole from "../../mergemole.app.mjs";
2+
3+
export default {
4+
key: "mergemole-list-templates",
5+
name: "List Templates",
6+
description: "Retrieve a list of all templates under your account. [See the documentation](https://documenter.getpostman.com/view/41321603/2sB2j3AWqz#f75d7ffa-df2e-42ca-ad32-1db280acb9e2)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
mergemole,
11+
search: {
12+
type: "string",
13+
label: "Search",
14+
description: "Search templates by name",
15+
optional: true,
16+
},
17+
},
18+
async run({ $ }) {
19+
const response = await this.mergemole.listTemplates({
20+
$,
21+
data: {
22+
search: this.search,
23+
},
24+
});
25+
$.export("$summary", `Successfully retrieved ${response.length} template${response.length === 1
26+
? ""
27+
: "s"}`);
28+
return response;
29+
},
30+
};
Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,63 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "mergemole",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
templateId: {
8+
type: "string",
9+
label: "Template ID",
10+
description: "The identifier of a template",
11+
async options() {
12+
const templates = await this.listTemplates();
13+
return templates?.map(({
14+
id: value, label,
15+
}) => ({
16+
label,
17+
value,
18+
})) || [];
19+
},
20+
},
21+
},
522
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
23+
_baseUrl() {
24+
return "https://mergemole.com/api";
25+
},
26+
_makeRequest({
27+
$ = this,
28+
path,
29+
...opts
30+
}) {
31+
return axios($, {
32+
url: `${this._baseUrl()}${path}`,
33+
headers: {
34+
"x-api-token": `${this.$auth.api_key}`,
35+
"x-api-secret": `${this.$auth.secret_key}`,
36+
},
37+
...opts,
38+
});
39+
},
40+
generatePdf(opts = {}) {
41+
return this._makeRequest({
42+
method: "POST",
43+
path: "/pdf/generate",
44+
...opts,
45+
});
46+
},
47+
listTemplates(opts = {}) {
48+
return this._makeRequest({
49+
method: "POST",
50+
path: "/template-files",
51+
...opts,
52+
});
53+
},
54+
getTemplateVariables({
55+
templateId, ...opts
56+
}) {
57+
return this._makeRequest({
58+
path: `/template-variables-action/${templateId}`,
59+
...opts,
60+
});
961
},
1062
},
11-
};
63+
};

components/mergemole/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/mergemole",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream MergeMole Components",
55
"main": "mergemole.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import common from "../../../notiff_io/actions/create-notification/create-notification.mjs";
2+
import { adjustPropDefinitions } from "../../common/utils.mjs";
3+
import app from "../../notiff.app.mjs";
4+
5+
const props = adjustPropDefinitions(common.props, app);
6+
7+
export default {
8+
...common,
9+
key: "notiff-create-notification",
10+
name: "Create Notification",
11+
description: "Send a new notification to a user or system via notiff.io. [See the documentation](https://notiff.io/articles/welcome-to-notiff-getting-started-with-your-notification-center)",
12+
version: "0.0.1",
13+
type: "action",
14+
methods: {
15+
getNotificationSourceId() {
16+
return this.app.$auth.notification_source_id;
17+
},
18+
},
19+
props: {
20+
app,
21+
...props,
22+
},
23+
};

components/notiff/common/utils.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
export function adjustPropDefinitions(props, app) {
2+
return Object.fromEntries(
3+
Object.entries(props).map(([
4+
key,
5+
prop,
6+
]) => {
7+
const {
8+
propDefinition, ...otherValues
9+
} = prop;
10+
if (propDefinition) {
11+
const [
12+
, ...otherDefs
13+
] = propDefinition;
14+
return [
15+
key,
16+
{
17+
propDefinition: [
18+
app,
19+
...otherDefs,
20+
],
21+
...otherValues,
22+
},
23+
];
24+
}
25+
return [
26+
key,
27+
otherValues.type === "app"
28+
? null
29+
: otherValues,
30+
];
31+
})
32+
.filter(([
33+
key,
34+
value,
35+
]) => key != "idNotificationSource" && (value)),
36+
);
37+
}

components/notiff/notiff.app.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
import notiffIo from "../notiff_io/notiff_io.app.mjs";
2+
13
export default {
4+
...notiffIo,
25
type: "app",
36
app: "notiff",
4-
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
8+
...notiffIo.methods,
9+
_headers() {
10+
return {
11+
"Content-Type": "application/json",
12+
};
913
},
1014
},
1115
};

components/notiff/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/notiff",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Notiff Components",
55
"main": "notiff.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import app from "../../notiff_io.app.mjs";
2+
3+
export default {
4+
key: "notiff_io-create-notification",
5+
name: "Create Notification",
6+
description: "Send a new notification to a user or system via notiff.io. [See the documentation](https://notiff.io/articles/welcome-to-notiff-getting-started-with-your-notification-center)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
idNotificationSource: {
12+
type: "string",
13+
label: "ID Notification Source",
14+
description: "To get your Notification Source ID, sign in to Notiff, go to the Settings menu with the gear icon on the top right, click the \"Settings\" option. Copy your Notification Source ID from the list.",
15+
secret: true,
16+
},
17+
title: {
18+
propDefinition: [
19+
app,
20+
"title",
21+
],
22+
},
23+
description: {
24+
propDefinition: [
25+
app,
26+
"description",
27+
],
28+
},
29+
url: {
30+
propDefinition: [
31+
app,
32+
"url",
33+
],
34+
},
35+
},
36+
methods: {
37+
getNotificationSourceId() {
38+
return this.idNotificationSource;
39+
},
40+
},
41+
async run({ $ }) {
42+
const response = await this.app.createNotification({
43+
$,
44+
data: {
45+
id_notification_source: this.getNotificationSourceId(),
46+
title: this.title,
47+
description: this.description,
48+
url: this.url,
49+
},
50+
});
51+
52+
$.export("$summary", `Notification titled "${this.title}" created successfully!`);
53+
return response;
54+
},
55+
};

0 commit comments

Comments
 (0)