Skip to content

Commit 7c98955

Browse files
authored
New Components - mergemole (#16497)
* new components * pnpm-lock.yaml
1 parent 302aec1 commit 7c98955

File tree

6 files changed

+207
-8
lines changed

6 files changed

+207
-8
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 <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
15-
}
18+
}

pnpm-lock.yaml

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)