Skip to content
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
65 changes: 65 additions & 0 deletions components/papersign/actions/copy-document/copy-document.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import papersign from "../../papersign.app.mjs";

export default {
key: "papersign-copy-document",
name: "Copy Document",
description: "Duplicates a given document. [See the documentation](https://paperform.readme.io/reference/papersigncopydocument)",
version: "0.0.1",
type: "action",
props: {
papersign,
documentId: {
propDefinition: [
papersign,
"documentId",
],
},
name: {
type: "string",
label: "Name",
description: "The new name of the copied document",
optional: true,
},
spaceId: {
propDefinition: [
papersign,
"spaceId",
],
optional: true,
},
path: {
type: "string",
label: "Path",
description: "The path to copy the document to. Maximum depth is 4 levels. Any missing folders will be created.",
optional: true,
},
folderId: {
propDefinition: [
papersign,
"folderId",
],
optional: true,
},
},
async run({ $ }) {
const data = {};
if (this.folderId) {
data.folder_id = this.folderId;
} else {
data.space_id = this.spaceId;
data.path = this.path;
}

const response = await this.papersign.duplicateDocument({
$,
documentId: this.documentId,
data: {
...data,
name: this.name,
},
});

$.export("$summary", `Successfully copied document: ${response.results.document.name}`);
return response;
},
};
27 changes: 27 additions & 0 deletions components/papersign/actions/get-document/get-document.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import papersign from "../../papersign.app.mjs";

export default {
key: "papersign-get-document",
name: "Get Document",
description: "Retrieve a document using a specified ID. [See the documentation](https://paperform.readme.io/reference/getpapersigndocument)",
version: "0.0.1",
type: "action",
props: {
papersign,
documentId: {
propDefinition: [
papersign,
"documentId",
],
},
},
async run({ $ }) {
const response = await this.papersign.getDocument({
$,
documentId: this.documentId,
});

$.export("$summary", `Successfully retrieved document with ID: ${this.documentId}`);
return response;
},
};
115 changes: 115 additions & 0 deletions components/papersign/actions/send-document/send-document.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { ConfigurationError } from "@pipedream/platform";
import { parseObject } from "../../common/utils.mjs";
import papersign from "../../papersign.app.mjs";

export default {
key: "papersign-send-document",
name: "Send Document",
description: "Dispatches a document to a specified recipient. [See the documentation](https://paperform.readme.io/reference/papersignsenddocument)",
version: "0.0.1",
type: "action",
props: {
papersign,
documentId: {
propDefinition: [
papersign,
"documentId",
],
},
expiration: {
type: "string",
label: "Expiration",
description: "The expiration date of the document. Must be at least 30 minutes in the future. **Format: YYYY-MM-DDTHH:MM:SS.SSSZ**",
optional: true,
},
inviteMessage: {
type: "string",
label: "Invite Message",
description: "The message to include in the invitation email, up to 1000 characters.",
optional: true,
},
fromUserEmail: {
type: "string",
label: "From User Email",
description: "The email address of a User on your team's account to send the document from.",
optional: true,
},
documentRecipientEmails: {
type: "string[]",
label: "Document Recipient Emails",
description: "An array of recipient emails for the document.",
optional: true,
},
firstAfterDays: {
type: "integer",
label: "Automatic Reminder - First After Days",
description: "The number of days after the document is sent to send the reminder.",
optional: true,
},
followUpEveryDays: {
type: "integer",
label: "Automatic Reminder - Follow Up Every Days",
description: "The number of days to wait between reminders.",
optional: true,
},
signers: {
type: "string[]",
label: "Signers",
description: "An array of objects of signers. **Object format: {\"key\": \"123\",\"name\": \"Jack Smith\",\"email\": \"[email protected]\",\"phone\": \"123 456 7899\",\"job_title\": \"Account Manager\",\"company\": \"Explosive Startup\",\"custom_attributes\": [{\"key\": \"Relationship\",\"label\": \"Relationship to the company\",\"value\": \"CEO\"}]}**",
optional: true,
},
variables: {
type: "object",
label: "Variables",
description: "The key: value of the document variables.",
optional: true,
},
copy: {
type: "boolean",
label: "Copy",
description: "Whether to copy before sending.",
optional: true,
},
},
async run({ $ }) {
if (
(this.firstAfterDays && !this.followUpEveryDays) ||
(!this.firstAfterDays && this.followUpEveryDays)
) {
throw new ConfigurationError("You must fill in the fields 'First After Days' and 'Follow Up Every Days' or none of them");
}

const automaticReminders = {};
if (this.firstAfterDays) {
automaticReminders.first_after_days = this.firstAfterDays;
automaticReminders.follow_up_every_days = this.followUpEveryDays;
}

const variables = [];
if (this.variables) {
for (const key of Object.keys(parseObject(this.variables))) {
variables.push({
key,
value: this.variables[key],
});
}
}

const response = await this.papersign.sendDocument({
$,
documentId: this.documentId,
data: {
expiration: this.expiration,
inviteMessage: this.inviteMessage,
fromUserEmail: this.fromUserEmail,
documentRecipientEmails: parseObject(this.documentRecipientEmails),
automaticReminders,
signers: parseObject(this.signers),
variables,
copy: this.copy,
},
});
$.export("$summary", `Document sent successfully with ID ${this.documentId}`);
return response;
},
};
12 changes: 12 additions & 0 deletions components/papersign/common/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const LIMIT = 100;

export const SCOPE_OPTIONS = [
{
label: "Direct Children",
value: "folder.direct_children",
},
{
label: "All Descendants",
value: "folder.all_descendants",
},
];
32 changes: 32 additions & 0 deletions components/papersign/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return parseObject(item);
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
if (typeof obj === "object") {
for (const [
key,
value,
] of Object.entries(obj)) {
obj[key] = parseObject(value);
}
}
return obj;
};
7 changes: 5 additions & 2 deletions components/papersign/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/papersign",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream Papersign Components",
"main": "papersign.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.0.3"
}
}
}
Loading
Loading