Skip to content

New Components - mergemole #16497

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 2 commits into from
May 1, 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
84 changes: 84 additions & 0 deletions components/mergemole/actions/generate-pdf/generate-pdf.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import mergemole from "../../mergemole.app.mjs";
import { ConfigurationError } from "@pipedream/platform";
import fs from "fs";

export default {
key: "mergemole-generate-pdf",
name: "Generate PDF",
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)",
version: "0.0.1",
type: "action",
props: {
mergemole,
templateId: {
propDefinition: [
mergemole,
"templateId",
],
reloadProps: true,
},
documentName: {
type: "string",
label: "Document Name",
description: "The name of the generated PDF document",
},
},
async additionalProps() {
const props = {};
if (!this.templateId) {
return props;
}
const templateVariables = await this.mergemole.getTemplateVariables({
templateId: this.templateId,
});
if (!templateVariables?.length) {
throw new ConfigurationError(`No template variables found for template \`${this.templateId}\``);
}
for (const variable of templateVariables) {
props[variable.key] = {
type: "string",
label: variable.label,
optional: true,
};
}
return props;
},
async run({ $ }) {
const {
mergemole,
templateId,
documentName,
...templateVariables
} = this;

const data = [];
for (const [
key,
value,
] of Object.entries(templateVariables)) {
data.push({
placeholder: key,
value,
});
}

const response = await mergemole.generatePdf({
$,
data: {
data,
template_id: templateId,
document_name: documentName,
},
responseType: "arraybuffer",
});

fs.writeFileSync(`/tmp/${documentName}`, Buffer.from(response));

$.export("$summary", "Successfully generated PDF");

return {
filename: documentName,
downloadedFilepath: `/tmp/${documentName}`,
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import mergemole from "../../mergemole.app.mjs";

export default {
key: "mergemole-get-template-variables",
name: "Get Template Variables",
description: "Get all data variables of a specified template. [See the documentation](https://documenter.getpostman.com/view/41321603/2sB2j3AWqz#14da32c9-9b15-421e-89c9-8a977b04dc32)",
version: "0.0.1",
type: "action",
props: {
mergemole,
templateId: {
propDefinition: [
mergemole,
"templateId",
],
},
},
async run({ $ }) {
const response = await this.mergemole.getTemplateVariables({
$,
templateId: this.templateId,
});
$.export("$summary", `Successfully retrieved variables for template with ID: ${this.templateId}`);
return response;
},
};
30 changes: 30 additions & 0 deletions components/mergemole/actions/list-templates/list-templates.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import mergemole from "../../mergemole.app.mjs";

export default {
key: "mergemole-list-templates",
name: "List Templates",
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)",
version: "0.0.1",
type: "action",
props: {
mergemole,
search: {
type: "string",
label: "Search",
description: "Search templates by name",
optional: true,
},
},
async run({ $ }) {
const response = await this.mergemole.listTemplates({
$,
data: {
search: this.search,
},
});
$.export("$summary", `Successfully retrieved ${response.length} template${response.length === 1
? ""
: "s"}`);
return response;
},
};
62 changes: 57 additions & 5 deletions components/mergemole/mergemole.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,63 @@
import { axios } from "@pipedream/platform";

export default {
type: "app",
app: "mergemole",
propDefinitions: {},
propDefinitions: {
templateId: {
type: "string",
label: "Template ID",
description: "The identifier of a template",
async options() {
const templates = await this.listTemplates();
return templates?.map(({
id: value, label,
}) => ({
label,
value,
})) || [];
},
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_baseUrl() {
return "https://mergemole.com/api";
},
_makeRequest({
$ = this,
path,
...opts
}) {
return axios($, {
url: `${this._baseUrl()}${path}`,
headers: {
"x-api-token": `${this.$auth.api_key}`,
"x-api-secret": `${this.$auth.secret_key}`,
},
...opts,
});
},
generatePdf(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/pdf/generate",
...opts,
});
},
listTemplates(opts = {}) {
return this._makeRequest({
method: "POST",
path: "/template-files",
...opts,
});
},
getTemplateVariables({
templateId, ...opts
}) {
return this._makeRequest({
path: `/template-variables-action/${templateId}`,
...opts,
});
},
},
};
};
7 changes: 5 additions & 2 deletions components/mergemole/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/mergemole",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream MergeMole Components",
"main": "mergemole.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
8 changes: 7 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading