From 2789621f38b46d58a98b0406bc3bb5d695adde3f Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 5 Nov 2024 10:46:27 -0300 Subject: [PATCH 1/3] flexisign init --- .../send-document-using-template.mjs | 41 ++++++++++++ components/flexisign/flexisign.app.mjs | 67 +++++++++++++++++-- components/flexisign/package.json | 2 +- 3 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 components/flexisign/actions/send-document-using-template/send-document-using-template.mjs diff --git a/components/flexisign/actions/send-document-using-template/send-document-using-template.mjs b/components/flexisign/actions/send-document-using-template/send-document-using-template.mjs new file mode 100644 index 0000000000000..c67d5094d50ce --- /dev/null +++ b/components/flexisign/actions/send-document-using-template/send-document-using-template.mjs @@ -0,0 +1,41 @@ +import flexisign from "../../flexisign.app.mjs"; + +export default { + key: "flexisign-send-document-using-template", + name: "Send Document Using Template", + description: "Sends a signature request to the specified recipients for a document generated from a template. [See the documentation](https://flexisign.io/app/integrations/flexisignapi)", + version: "0.0.1", + type: "action", + props: { + flexisign, + templateId: { + propDefinition: [ + flexisign, + "templateId", + ], + }, + recipients: { + propDefinition: [ + flexisign, + "recipients", + ], + }, + message: { + propDefinition: [ + flexisign, + "message", + ], + optional: true, + }, + }, + async run({ $ }) { + const response = await this.flexisign.sendSignatureRequest({ + templateId: this.templateId, + recipients: this.recipients, + message: this.message, + }); + + $.export("$summary", `Signature request sent for template ID: ${this.templateId}`); + return response; + }, +}; diff --git a/components/flexisign/flexisign.app.mjs b/components/flexisign/flexisign.app.mjs index a9246c3435314..18060bd5de7f1 100644 --- a/components/flexisign/flexisign.app.mjs +++ b/components/flexisign/flexisign.app.mjs @@ -1,11 +1,70 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "flexisign", - propDefinitions: {}, + propDefinitions: { + templateId: { + type: "string", + label: "Template ID", + description: "The ID of the template to generate the document from", + async options() { + const templates = await this.listTemplates(); + return templates.map((template) => ({ + label: template.name, + value: template.id, + })); + }, + }, + recipients: { + type: "string[]", + label: "Recipients", + description: "An array of recipient objects, with each recipient specified as a JSON string (e.g., '[{\"email\": \"example@example.com\"}]')", + }, + message: { + type: "string", + label: "Message", + description: "A personalized message for the recipients", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.flexisign.io/v1"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, method = "GET", path = "/", headers, ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + method, + url: this._baseUrl() + path, + headers: { + ...headers, + Authorization: `Bearer ${this.$auth.api_key}`, + }, + }); + }, + async listTemplates(opts = {}) { + return this._makeRequest({ + path: "/templates", + ...opts, + }); + }, + async sendSignatureRequest(opts = {}) { + const { + templateId, recipients, message, + } = opts; + return this._makeRequest({ + method: "POST", + path: "/signature/send", + data: { + template_id: templateId, + recipients: recipients.map(JSON.parse), + message, + }, + }); }, }, }; diff --git a/components/flexisign/package.json b/components/flexisign/package.json index 9aaf220e139fe..9a5c30e453d64 100644 --- a/components/flexisign/package.json +++ b/components/flexisign/package.json @@ -12,4 +12,4 @@ "publishConfig": { "access": "public" } -} \ No newline at end of file +} From 29e0da8b988efb4691b5ac451dc67fd1b9bd4556 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 5 Nov 2024 11:21:02 -0300 Subject: [PATCH 2/3] [Components] flexisign #14491 Actions - Send Document Using Template --- .../send-document-using-template.mjs | 60 ++++++++++++----- components/flexisign/common/utils.mjs | 4 ++ components/flexisign/flexisign.app.mjs | 64 ++++++++----------- components/flexisign/package.json | 5 +- 4 files changed, 78 insertions(+), 55 deletions(-) create mode 100644 components/flexisign/common/utils.mjs diff --git a/components/flexisign/actions/send-document-using-template/send-document-using-template.mjs b/components/flexisign/actions/send-document-using-template/send-document-using-template.mjs index c67d5094d50ce..7b756883e9b9c 100644 --- a/components/flexisign/actions/send-document-using-template/send-document-using-template.mjs +++ b/components/flexisign/actions/send-document-using-template/send-document-using-template.mjs @@ -1,3 +1,4 @@ +import { snakeCaseToTitleCase } from "../../common/utils.mjs"; import flexisign from "../../flexisign.app.mjs"; export default { @@ -13,26 +14,51 @@ export default { flexisign, "templateId", ], + reloadProps: true, }, - recipients: { - propDefinition: [ - flexisign, - "recipients", - ], - }, - message: { - propDefinition: [ - flexisign, - "message", - ], - optional: true, - }, + }, + async additionalProps() { + const props = {}; + if (this.templateId) { + const { data: { bodyStructure } } = await this.flexisign.getTemplateDetails({ + params: { + templateId: this.templateId, + }, + }); + + for (const [ + key, + value, + ] of Object.entries(bodyStructure)) { + if ([ + "templateId", + "recipientsCount", + ].includes(key)) continue; + + const title = snakeCaseToTitleCase(key); + props[key] = { + type: typeof value === "number" + ? "integer" + : "string", + label: title, + description: title, + default: typeof value === "number" + ? value + : undefined, + }; + } + } + return props; }, async run({ $ }) { - const response = await this.flexisign.sendSignatureRequest({ - templateId: this.templateId, - recipients: this.recipients, - message: this.message, + const { + flexisign, + ...data + } = this; + + const response = await flexisign.sendSignatureRequest({ + $, + data, }); $.export("$summary", `Signature request sent for template ID: ${this.templateId}`); diff --git a/components/flexisign/common/utils.mjs b/components/flexisign/common/utils.mjs new file mode 100644 index 0000000000000..8b11b6b3ecf24 --- /dev/null +++ b/components/flexisign/common/utils.mjs @@ -0,0 +1,4 @@ +export const snakeCaseToTitleCase = (s) => + s.replace(/^_*(.)|_+(.)/g, (s, c, d) => c + ? c.toUpperCase() + : " " + d.toUpperCase()); diff --git a/components/flexisign/flexisign.app.mjs b/components/flexisign/flexisign.app.mjs index 18060bd5de7f1..6508323c4305f 100644 --- a/components/flexisign/flexisign.app.mjs +++ b/components/flexisign/flexisign.app.mjs @@ -9,61 +9,51 @@ export default { label: "Template ID", description: "The ID of the template to generate the document from", async options() { - const templates = await this.listTemplates(); - return templates.map((template) => ({ - label: template.name, - value: template.id, + const { data: { list } } = await this.listTemplates(); + return list.map(({ + _id: value, name: label, + }) => ({ + label, + value, })); }, }, - recipients: { - type: "string[]", - label: "Recipients", - description: "An array of recipient objects, with each recipient specified as a JSON string (e.g., '[{\"email\": \"example@example.com\"}]')", - }, - message: { - type: "string", - label: "Message", - description: "A personalized message for the recipients", - optional: true, - }, }, methods: { _baseUrl() { return "https://api.flexisign.io/v1"; }, - async _makeRequest(opts = {}) { - const { - $ = this, method = "GET", path = "/", headers, ...otherOpts - } = opts; + _headers() { + return { + "api-key": `${this.$auth.api_key}`, + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { return axios($, { - ...otherOpts, - method, url: this._baseUrl() + path, - headers: { - ...headers, - Authorization: `Bearer ${this.$auth.api_key}`, - }, + headers: this._headers(), + ...opts, }); }, - async listTemplates(opts = {}) { + listTemplates(opts = {}) { return this._makeRequest({ - path: "/templates", + path: "/templates/all", ...opts, }); }, - async sendSignatureRequest(opts = {}) { - const { - templateId, recipients, message, - } = opts; + getTemplateDetails(opts = {}) { + return this._makeRequest({ + path: "/template", + ...opts, + }); + }, + sendSignatureRequest(opts = {}) { return this._makeRequest({ method: "POST", - path: "/signature/send", - data: { - template_id: templateId, - recipients: recipients.map(JSON.parse), - message, - }, + path: "/template/create-document", + ...opts, }); }, }, diff --git a/components/flexisign/package.json b/components/flexisign/package.json index 9a5c30e453d64..1ab1776a0f90f 100644 --- a/components/flexisign/package.json +++ b/components/flexisign/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/flexisign", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream FlexiSign Components", "main": "flexisign.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } } From c33c6b03fbe334d6420bb3f1fa69e43914f6aa82 Mon Sep 17 00:00:00 2001 From: Luan Cazarine Date: Tue, 5 Nov 2024 11:21:51 -0300 Subject: [PATCH 3/3] pnpm update --- pnpm-lock.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index dfc0fe9556e70..2c44eba7f0e63 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3530,7 +3530,10 @@ importers: '@pipedream/platform': 3.0.3 components/flexisign: - specifiers: {} + specifiers: + '@pipedream/platform': ^3.0.3 + dependencies: + '@pipedream/platform': 3.0.3 components/flexmail: specifiers: @@ -23952,7 +23955,7 @@ packages: dev: false /concat-map/0.0.1: - resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} + resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} /concat-stream/2.0.0: resolution: {integrity: sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A==} @@ -36639,7 +36642,7 @@ packages: dev: false /verror/1.10.0: - resolution: {integrity: sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=} + resolution: {integrity: sha512-ZZKSmDAEFOijERBLkmYfJ+vmk3w+7hOLYDNkRCuRuMJGEmqYNCNLyBBFwWKVMhfwaEF3WOd0Zlw86U/WC/+nYw==} engines: {'0': node >=0.6.0} dependencies: assert-plus: 1.0.0