diff --git a/components/onlinecheckwriter/actions/create-check/create-check.mjs b/components/onlinecheckwriter/actions/create-check/create-check.mjs new file mode 100644 index 0000000000000..a2cbff182fcfa --- /dev/null +++ b/components/onlinecheckwriter/actions/create-check/create-check.mjs @@ -0,0 +1,134 @@ +import app from "../../onlinecheckwriter.app.mjs"; + +export default { + key: "onlinecheckwriter-create-check", + name: "Create Check", + description: "Creates a new check. [See the documentation](https://apiv3.onlinecheckwriter.com/#211cb6e4-bda7-46de-9e84-a5e8b2709206)", + version: "0.0.1", + type: "action", + props: { + app, + bankAccountId: { + propDefinition: [ + app, + "bankAccountId", + ], + }, + payeeId: { + propDefinition: [ + app, + "payeeId", + ], + }, + categoryId: { + propDefinition: [ + app, + "categoryId", + ], + }, + issueDate: { + propDefinition: [ + app, + "issueDate", + ], + }, + amount: { + propDefinition: [ + app, + "amount", + ], + }, + memo: { + propDefinition: [ + app, + "memo", + ], + }, + note: { + propDefinition: [ + app, + "note", + ], + }, + invoiceNumber: { + propDefinition: [ + app, + "invoiceNumber", + ], + }, + noSign: { + propDefinition: [ + app, + "noSign", + ], + }, + noAmount: { + propDefinition: [ + app, + "noAmount", + ], + }, + noDate: { + propDefinition: [ + app, + "noDate", + ], + }, + noPayee: { + propDefinition: [ + app, + "noPayee", + ], + }, + }, + methods: { + createChecks(args = {}) { + return this.app.post({ + path: "/checks", + ...args, + }); + }, + }, + async run({ $ }) { + const { + createChecks, + bankAccountId, + payeeId, + categoryId, + issueDate, + amount, + memo, + note, + invoiceNumber, + noSign, + noAmount, + noDate, + noPayee, + } = this; + + const response = await createChecks({ + $, + data: { + checks: [ + { + bankAccountId, + payeeId, + categoryId, + issueDate, + amount, + memo, + note, + invoiceNumber, + noSign, + noAmount, + noDate, + noPayee, + }, + ], + }, + }); + + $.export("$summary", `Successfully created a new check with ID \`${response.data.checks[0].checkId}\`.`); + return response; + }, +}; diff --git a/components/onlinecheckwriter/actions/create-email-check/create-email-check.mjs b/components/onlinecheckwriter/actions/create-email-check/create-email-check.mjs new file mode 100644 index 0000000000000..b4d8fd366b83b --- /dev/null +++ b/components/onlinecheckwriter/actions/create-email-check/create-email-check.mjs @@ -0,0 +1,82 @@ +import app from "../../onlinecheckwriter.app.mjs"; + +export default { + key: "onlinecheckwriter-create-email-check", + name: "Create Email Check", + description: "Create an email check for a payee. [See the documentation](https://apiv3.onlinecheckwriter.com/#211cb6e4-bda7-46de-9e84-a5e8b2709206).", + version: "0.0.1", + type: "action", + props: { + app, + checkId: { + propDefinition: [ + app, + "checkId", + ], + }, + payeeEmail: { + optional: false, + propDefinition: [ + app, + "payeeEmail", + ], + }, + enableSmsInform: { + propDefinition: [ + app, + "enableSmsInform", + ], + }, + payeePhone: { + optional: false, + description: "Required if **Enable SMS Inform** is `true` and not exist any phone on associated payee,", + propDefinition: [ + app, + "payeePhone", + ], + }, + sendAttachment: { + type: "boolean", + label: "Send Attachment", + description: "This will send added attachments along with the check.", + optional: true, + }, + }, + methods: { + createEmailChecks(args = {}) { + return this.app.post({ + path: "/emailchecks", + ...args, + }); + }, + }, + async run({ $ }) { + const { + createEmailChecks, + checkId, + payeeEmail, + enableSmsInform, + payeePhone, + sendAttachment, + } = this; + + const response = await createEmailChecks({ + $, + data: { + emailChecks: [ + { + checkId, + payeeEmail, + enableSmsInform, + payeePhone, + ...(sendAttachment !== undefined && { + sendAttachment: +sendAttachment, + }), + }, + ], + }, + }); + $.export("$summary", "Successfully created email checks."); + return response; + }, +}; diff --git a/components/onlinecheckwriter/actions/create-mail-check/create-mail-check.mjs b/components/onlinecheckwriter/actions/create-mail-check/create-mail-check.mjs new file mode 100644 index 0000000000000..18a56a3e17fc6 --- /dev/null +++ b/components/onlinecheckwriter/actions/create-mail-check/create-mail-check.mjs @@ -0,0 +1,145 @@ +import app from "../../onlinecheckwriter.app.mjs"; + +export default { + key: "onlinecheckwriter-create-mail-check", + name: "Create Mail Check", + description: "Creates a mail check. [See the documentation](https://apiv3.onlinecheckwriter.com/#f4562b65-70e8-4c4d-8444-8898e61ab7f0).", + version: "0.0.1", + type: "action", + props: { + app, + isShippingToCustomAddress: { + type: "boolean", + label: "Shipping To Custom Address?", + description: "Value is `true` if sending mail to custom address. Default `false`", + optional: true, + }, + customFromAddressId: { + description: "Must be a custom from address ID. Required if **Shipping To Custom Address?** is `true`.", + propDefinition: [ + app, + "customFromAddressId", + ], + }, + customToAddressId: { + description: "Must be a custom to address ID. Required if **Shipping To Custom Address?** is `true`.", + propDefinition: [ + app, + "customToAddressId", + ], + }, + customShippingTypeId: { + label: "Custom Shipping Type ID", + description: "Must be a valid custom shipping type ID. Required if **Shipping To Custom Address?** is `true`.", + propDefinition: [ + app, + "shippingTypeId", + ], + }, + checkId: { + propDefinition: [ + app, + "checkId", + ], + }, + shippingTypeId: { + optional: false, + description: "The shipping type ID of the check.", + propDefinition: [ + app, + "shippingTypeId", + ], + }, + paperTypeId: { + propDefinition: [ + app, + "paperTypeId", + ], + }, + informTypeId: { + propDefinition: [ + app, + "informTypeId", + ], + }, + enableSmsInform: { + propDefinition: [ + app, + "enableSmsInform", + ], + }, + enableEmailInform: { + type: "boolean", + label: "Enable Email Inform", + description: "Value is `true` if email inform is enabled. Default `false`.", + optional: true, + }, + payeeEmail: { + description: "Required if **Enable Email Inform** is `true` and there is no email on the associated payee.", + propDefinition: [ + app, + "payeeEmail", + ], + }, + payeePhone: { + description: "Required if **Enable SMS Inform** is `true` and there is no phone on the associated payee.", + propDefinition: [ + app, + "payeePhone", + ], + }, + }, + methods: { + createMailChecks(args = {}) { + return this.app.post({ + path: "/mailchecks", + ...args, + }); + }, + }, + async run({ $ }) { + const { + createMailChecks, + isShippingToCustomAddress, + customFromAddressId, + customToAddressId, + customShippingTypeId, + checkId, + shippingTypeId, + paperTypeId, + informTypeId, + enableSmsInform, + enableEmailInform, + payeeEmail, + payeePhone, + } = this; + + const response = await createMailChecks({ + $, + data: { + isShippingToCustomAddress, + customFromAddressId, + customToAddressId, + customShippingTypeId, + mailChecks: [ + { + checkId, + shippingTypeId, + paperTypeId, + informTypeId, + ...(enableSmsInform !== undefined && { + enableSmsInform: +enableSmsInform, + }), + ...(enableEmailInform !== undefined && { + enableEmailInform: +enableEmailInform, + }), + payeeEmail, + payeePhone, + }, + ], + }, + }); + $.export("$summary", "Successfully created and mailed checks."); + return response; + }, +}; diff --git a/components/onlinecheckwriter/actions/create-payee/create-payee.mjs b/components/onlinecheckwriter/actions/create-payee/create-payee.mjs new file mode 100644 index 0000000000000..eed49f25a70a7 --- /dev/null +++ b/components/onlinecheckwriter/actions/create-payee/create-payee.mjs @@ -0,0 +1,117 @@ +import app from "../../onlinecheckwriter.app.mjs"; + +export default { + key: "onlinecheckwriter-create-payee", + name: "Create Payee", + description: "Registers a new payee within the system.[See the documentation](https://apiv3.onlinecheckwriter.com/#38a31300-bf13-4da1-ac97-dd81525b57b3)", + version: "0.0.1", + type: "action", + props: { + app, + name: { + type: "string", + label: "Name", + description: "The name of the payee.", + }, + company: { + type: "string", + label: "Company", + description: "The company of the payee.", + optional: true, + }, + email: { + type: "string", + label: "Email", + description: "The email of the payee.", + optional: true, + }, + phone: { + type: "string", + label: "Phone", + description: "The phone number of the payee.", + optional: true, + }, + address1: { + type: "string", + label: "Address 1", + description: "The first line of the address of the payee.", + optional: true, + }, + address2: { + type: "string", + label: "Address 2", + description: "The second line of the address of the payee.", + optional: true, + }, + country: { + type: "string", + label: "Country", + description: "The country of the payee.", + optional: true, + }, + state: { + type: "string", + label: "State", + description: "The state of the payee.", + optional: true, + }, + city: { + type: "string", + label: "City", + description: "The city of the payee.", + optional: true, + }, + zip: { + type: "string", + label: "Zip", + description: "The zip code of the payee.", + optional: true, + }, + }, + methods: { + createPayees(args = {}) { + return this.app.post({ + path: "/payees", + ...args, + }); + }, + }, + async run({ $ }) { + const { + createPayees, + name, + company, + email, + phone, + address1, + address2, + country, + state, + city, + zip, + } = this; + + const response = await createPayees({ + $, + data: { + payees: [ + { + name, + company, + email, + phone, + address1, + address2, + country, + state, + city, + zip, + }, + ], + }, + }); + + $.export("$summary", `Successfully created payee with ID \`${response.data.payees[0].payeeId}\`.`); + return response; + }, +}; diff --git a/components/onlinecheckwriter/actions/mail-pdf-document/mail-pdf-document.mjs b/components/onlinecheckwriter/actions/mail-pdf-document/mail-pdf-document.mjs new file mode 100644 index 0000000000000..daa5cb15e5fff --- /dev/null +++ b/components/onlinecheckwriter/actions/mail-pdf-document/mail-pdf-document.mjs @@ -0,0 +1,206 @@ +import fs from "fs"; +import FormData from "form-data"; +import { ConfigurationError } from "@pipedream/platform"; +import app from "../../onlinecheckwriter.app.mjs"; + +export default { + key: "onlinecheckwriter-mail-pdf-document", + name: "Mail PDF Document", + description: "Mails a PDF document to a destination. [See the documentation](https://apiv3.onlinecheckwriter.com/#878daf05-e36e-44a2-bce8-15f24d72f82e).", + version: "0.0.1", + type: "action", + props: { + app, + documentTitle: { + type: "string", + label: "Document Title", + description: "The title of the document.", + optional: true, + }, + filePath: { + type: "string", + label: "File Path", + description: "The path to the pdf file saved to the `/tmp` directory (e.g. `/tmp/example.pdf`). [See the documentation](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory).", + }, + shippingTypeId: { + optional: false, + propDefinition: [ + app, + "shippingTypeId", + ], + }, + senderName: { + type: "string", + label: "Sender Name", + description: "The name of the sender.", + optional: true, + }, + senderCompany: { + type: "string", + label: "Sender Company", + description: "The company of the sender.", + optional: true, + }, + senderAddress1: { + type: "string", + label: "Sender Address 1", + description: "The first line of the sender's address.", + optional: true, + }, + senderAddress2: { + type: "string", + label: "Sender Address 2", + description: "The second line of the sender's address.", + optional: true, + }, + senderCity: { + type: "string", + label: "Sender City", + description: "The city of the sender.", + optional: true, + }, + senderState: { + type: "string", + label: "Sender State", + description: "The state of the sender.", + optional: true, + }, + senderZip: { + type: "string", + label: "Sender Zip", + description: "The zip code of the sender.", + optional: true, + }, + senderPhone: { + type: "string", + label: "Sender Phone", + description: "The phone number of the sender.", + optional: true, + }, + senderEmail: { + type: "string", + label: "Sender Email", + description: "The email address of the sender.", + optional: true, + }, + destinationName: { + type: "string", + label: "Destination Name", + description: "The name of the recipient.", + }, + destinationCompany: { + type: "string", + label: "Destination Company", + description: "The company of the recipient.", + optional: true, + }, + destinationAddress1: { + type: "string", + label: "Destination Address 1", + description: "The first line of the recipient's address.", + }, + destinationAddress2: { + type: "string", + label: "Destination Address 2", + description: "The second line of the recipient's address.", + optional: true, + }, + destinationCity: { + type: "string", + label: "Destination City", + description: "The city of the recipient.", + }, + destinationState: { + type: "string", + label: "Destination State", + description: "The state of the recipient. Use 2 characters Eg. `Tx` instead of `Texas` for example.", + }, + destinationZip: { + type: "string", + label: "Destination Zip", + description: "The zip code of the recipient.", + }, + destinationPhone: { + type: "string", + label: "Destination Phone", + description: "The phone number of the recipient.", + optional: true, + }, + destinationEmail: { + type: "string", + label: "Destination Email", + description: "The email address of the recipient.", + optional: true, + }, + }, + methods: { + mailPdfDocument(args = {}) { + return this.app.post({ + path: "/documentmailing/mail", + ...args, + }); + }, + }, + async run({ $ }) { + const { + mailPdfDocument, + documentTitle, + filePath, + shippingTypeId, + senderName, + senderCompany, + senderAddress1, + senderAddress2, + senderCity, + senderState, + senderZip, + senderPhone, + senderEmail, + destinationName, + destinationCompany, + destinationAddress1, + destinationAddress2, + destinationCity, + destinationState, + destinationZip, + destinationPhone, + destinationEmail, + } = this; + + if (!filePath?.startsWith("/tmp/")) { + throw new ConfigurationError("The file path must start with `/tmp/`."); + } + + const data = new FormData(); + const file = fs.createReadStream(filePath); + data.append("document_details[file]", file); + data.append("document_details[title]", documentTitle || ""); + data.append("shipping[shippingTypeId]", shippingTypeId || ""); + data.append("destination[name]", destinationName || ""); + data.append("destination[company]", destinationCompany || ""); + data.append("destination[address1]", destinationAddress1 || ""); + data.append("destination[address2]", destinationAddress2 || ""); + data.append("destination[city]", destinationCity || ""); + data.append("destination[state]", destinationState || ""); + data.append("destination[zip]", destinationZip || ""); + data.append("destination[phone]", destinationPhone || ""); + data.append("destination[email]", destinationEmail || ""); + data.append("from_address[name]", senderName || ""); + data.append("from_address[company]", senderCompany || ""); + data.append("from_address[address1]", senderAddress1 || ""); + data.append("from_address[address2]", senderAddress2 || ""); + data.append("from_address[city]", senderCity || ""); + data.append("from_address[state]", senderState || ""); + data.append("from_address[zip]", senderZip || ""); + data.append("from_address[phone]", senderPhone || ""); + data.append("from_address[email]", senderEmail || ""); + const response = await mailPdfDocument({ + $, + data, + headers: data.getHeaders(), + }); + + $.export("$summary", "Successfully generated and mailed PDF document"); + return response; + }, +}; diff --git a/components/onlinecheckwriter/onlinecheckwriter.app.mjs b/components/onlinecheckwriter/onlinecheckwriter.app.mjs index c1e27e32ed3b0..c344ed01f5735 100644 --- a/components/onlinecheckwriter/onlinecheckwriter.app.mjs +++ b/components/onlinecheckwriter/onlinecheckwriter.app.mjs @@ -1,11 +1,329 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "onlinecheckwriter", - propDefinitions: {}, + propDefinitions: { + bankAccountId: { + type: "string", + label: "Bank Account ID", + description: "Must be a bank account ID.", + async options({ page }) { + const { data: { bankAccounts } } = await this.listBankAccounts({ + params: { + page, + }, + }); + return bankAccounts.map(({ + bankAccountId: value, name: label, + }) => ({ + label, + value, + })); + }, + }, + payeeId: { + type: "string", + label: "Payee ID", + description: "Must be a payee ID.", + async options({ page }) { + const { data: { payees } } = await this.listPayees({ + params: { + page, + }, + }); + return payees.map(({ + payeeId: value, name: label, + }) => ({ + label, + value, + })); + }, + }, + categoryId: { + type: "string", + label: "Category ID", + description: "Must be a category ID.", + optional: true, + async options({ page }) { + const { data: { categories } } = await this.listCategories({ + params: { + page, + }, + }); + return categories.map(({ + categoryId: value, name: label, + }) => ({ + label, + value, + })); + }, + }, + issueDate: { + type: "string", + label: "Issue Date", + description: "By default it will be check creation date, If an **Issue Date** is passed, that will override any default. Eg. `2021-12-31`.", + optional: true, + }, + amount: { + type: "string", + label: "Amount", + description: "The money value of the check.", + }, + memo: { + type: "string", + label: "Memo", + description: "Max of 150 characters to be included on the memo line of the check.", + optional: true, + }, + note: { + type: "string", + label: "Note", + description: "An internal note that identifies this check. Must be no longer than 150 characters.", + optional: true, + }, + invoiceNumber: { + type: "string", + label: "Invoice Number", + description: "Any invoice number associated with this check", + optional: true, + }, + noSign: { + type: "boolean", + label: "No Sign", + description: "if `true`, the check will be created without signature. Default `false`.", + optional: true, + }, + noAmount: { + type: "boolean", + label: "No Amount", + description: "if `true`, the check will be created without amount. Default `false`", + optional: true, + }, + noDate: { + type: "boolean", + label: "No Date", + description: "if `true`, the check will be created without date. Default `false`", + optional: true, + }, + noPayee: { + type: "boolean", + label: "No Payee", + description: "if `true`, the check will be created without payee. Default `false`", + optional: true, + }, + customFromAddressId: { + type: "string", + label: "Custom From Address ID", + description: "Must be a custom from address ID.", + optional: true, + async options({ page }) { + const { data: { addresses } } = await this.listCustomFromAddresses({ + params: { + page, + }, + }); + return addresses.map(({ + customFromAddressId: value, name: label, + }) => ({ + label, + value, + })); + }, + }, + customToAddressId: { + type: "string", + label: "Custom To Address ID", + description: "Must be a custom to address ID.", + optional: true, + async options({ page }) { + const { data: { addresses } } = await this.listCustomToAddresses({ + params: { + page, + }, + }); + return addresses.map(({ + customToAddressId: value, name: label, + }) => ({ + label, + value, + })); + }, + }, + shippingTypeId: { + type: "string", + label: "Shipping Type ID", + description: "Must be a valid shipping type ID.", + optional: true, + options: [ + { + label: "First Class", + value: "1", + }, + { + label: "First Class with Tracking", + value: "3", + }, + { + label: "Priority Mail", + value: "4", + }, + { + label: "Express Mail", + value: "5", + }, + { + label: "Standard Overnight -Fedex-By 3pm the next business day", + value: "12", + }, + { + label: "Fedex Saturday Delivery", + value: "20", + }, + ], + }, + checkId: { + type: "string", + label: "Check ID", + description: "Must be a check ID.", + async options({ + page, params, + }) { + const { data: { checks } } = await this.listChecks({ + params: { + ...params, + page, + }, + }); + return checks.map(({ + checkId: value, payee: { + name, payeeId, + }, amount, + }) => ({ + label: `${name || payeeId} - $${amount}`, + value, + })); + }, + }, + paperTypeId: { + type: "string", + label: "Paper Type ID", + description: "Must be a valid paper type ID.", + options: [ + { + label: "Regular Check Paper", + value: "7", + }, + { + label: "Hollogram Check Paper", + value: "8", + }, + { + label: "Ultra Hollogram Check Paper", + value: "9", + }, + ], + }, + informTypeId: { + type: "string", + label: "Inform Type ID", + description: "Must be a valid inform type ID.", + optional: true, + options: [ + { + label: "Notify Receiver by Sms", + value: "10", + }, + ], + }, + enableSmsInform: { + type: "boolean", + label: "Enable SMS Inform", + description: "Value is `true` if SMS inform is enabled. Default `false`", + optional: true, + }, + payeeEmail: { + type: "string", + label: "Payee Email", + description: "The email address of the payee.", + optional: true, + }, + payeePhone: { + type: "string", + label: "Payee Phone", + description: "The phone number of the payee.", + optional: true, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + getUrl(path) { + const { environment } = this.$auth; + return `${environment}/api/v3${path}`; + }, + getHeaders(headers) { + return { + "Content-Type": "application/json", + "Accept": "application/json", + "Authorization": `Bearer ${this.$auth.api_key}`, + ...headers, + }; + }, + async _makeRequest({ + $ = this, path, headers, ...args + } = {}) { + const response = await axios($, { + ...args, + url: this.getUrl(path), + headers: this.getHeaders(headers), + }); + + if (response.success === false) { + throw new Error(JSON.stringify(response)); + } + + return response; + }, + post(args = {}) { + return this._makeRequest({ + method: "POST", + ...args, + }); + }, + listBankAccounts(args = {}) { + return this._makeRequest({ + path: "/bankAccounts", + ...args, + }); + }, + listPayees(args = {}) { + return this._makeRequest({ + path: "/payees", + ...args, + }); + }, + listCategories(args = {}) { + return this._makeRequest({ + path: "/categories", + ...args, + }); + }, + listCustomFromAddresses(args = {}) { + return this._makeRequest({ + path: "/customFromAddresses", + ...args, + }); + }, + listCustomToAddresses(args = {}) { + return this._makeRequest({ + path: "/customToAddresses", + ...args, + }); + }, + listChecks(args = {}) { + return this._makeRequest({ + path: "/checks", + ...args, + }); }, }, -}; \ No newline at end of file +}; diff --git a/components/onlinecheckwriter/package.json b/components/onlinecheckwriter/package.json index f5d118d1b7ea8..b3ad9e2566d5a 100644 --- a/components/onlinecheckwriter/package.json +++ b/components/onlinecheckwriter/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/onlinecheckwriter", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream OnlineCheckWriter Components", "main": "onlinecheckwriter.app.mjs", "keywords": [ @@ -11,5 +11,9 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "3.0.3", + "form-data": "^4.0.0" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5e03173008376..c0ac6435d2eec 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6665,7 +6665,12 @@ importers: ongage: 1.1.7_node-fetch@2.7.0 components/onlinecheckwriter: - specifiers: {} + specifiers: + '@pipedream/platform': 3.0.3 + form-data: ^4.0.0 + dependencies: + '@pipedream/platform': 3.0.3 + form-data: 4.0.0 components/onlyoffice_docspace: specifiers: