diff --git a/components/chartly/chartly.app.mjs b/components/chartly/chartly.app.mjs index 1c2b4c02cd299..173ca99ae82d2 100644 --- a/components/chartly/chartly.app.mjs +++ b/components/chartly/chartly.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/cryptlex/cryptlex.app.mjs b/components/cryptlex/cryptlex.app.mjs index 3daa8ca640514..0b6ebe74b7c4e 100644 --- a/components/cryptlex/cryptlex.app.mjs +++ b/components/cryptlex/cryptlex.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/docuwriter_ai/docuwriter_ai.app.mjs b/components/docuwriter_ai/docuwriter_ai.app.mjs index 601e827d809d7..aad14a5637b0b 100644 --- a/components/docuwriter_ai/docuwriter_ai.app.mjs +++ b/components/docuwriter_ai/docuwriter_ai.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/genpage/genpage.app.mjs b/components/genpage/genpage.app.mjs index ca36b094d73a7..63a27ebe0d1ee 100644 --- a/components/genpage/genpage.app.mjs +++ b/components/genpage/genpage.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/hybrid_analysis/hybrid_analysis.app.mjs b/components/hybrid_analysis/hybrid_analysis.app.mjs index 3669182e3395f..41e8042ac9cd0 100644 --- a/components/hybrid_analysis/hybrid_analysis.app.mjs +++ b/components/hybrid_analysis/hybrid_analysis.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/intelliprint/README.md b/components/intelliprint/README.md deleted file mode 100644 index 50ae497253ee4..0000000000000 --- a/components/intelliprint/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Overview - -The Intelliprint API offers a suite of printing solutions, enabling developers to automate the process of sending documents for print. With this API, you can create workflows in Pipedream to programmatically manage print jobs, customize printing options, and track the status of each task. It's ideal for businesses looking to integrate print capabilities into their services without the overhead of managing printers and supplies. - -# Example Use Cases - -- **Automated Invoice Printing**: Trigger a Pipedream workflow to send invoices for print automatically whenever a new sale is recorded in your e-commerce platform. This can ensure that all paperwork is printed and ready for dispatch without manual intervention. - -- **Custom Business Cards on Demand**: Set up a Pipedream workflow that listens for a webhook from a CRM app when new employees are added. The workflow can then use the Intelliprint API to print business cards with the employee's details, streamlining the onboarding process. - -- **Print Job Status Tracking**: Construct a Pipedream workflow that periodically checks the status of print jobs submitted through Intelliprint. When a job is complete, the workflow could send a notification via apps like Slack or email, keeping relevant teams informed. diff --git a/components/intelliprint/actions/create-a-print-job/create-a-print-job.mjs b/components/intelliprint/actions/create-a-print-job/create-a-print-job.mjs new file mode 100644 index 0000000000000..ca49f0b2ed39b --- /dev/null +++ b/components/intelliprint/actions/create-a-print-job/create-a-print-job.mjs @@ -0,0 +1,251 @@ +/* eslint-disable no-unused-vars */ +import { + ConfigurationError, + getFileStreamAndMetadata, +} from "@pipedream/platform"; +import FormData from "form-data"; +import { + DOUBLE_SIDED_OPTIONS, + IDEAL_ENVELOPE_OPTIONS, + POSTAGE_SERVICE_OPTIONS, + SPLITTING_METHOD_OPTIONS, +} from "../../common/constants.mjs"; +import { + camelCaseToSnakeCase, parseObject, +} from "../../common/utils.mjs"; +import intelliprint from "../../intelliprint.app.mjs"; + +export default { + key: "intelliprint-create-a-print-job", + name: "Create a Print Job", + description: "Creates a new print job in the Intelliprint API. [See the documentation](https://api-docs.intelliprint.net/?_gl=1*19r3k2k*_gcl_au*MTU2NDU2MDgzMS4xNzY0MDIwNDQx#print_jobs-create)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: false, + }, + props: { + intelliprint, + filePath: { + type: "string", + label: "File Path", + description: "The file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)", + }, + reference: { + type: "string", + label: "Reference", + description: "An user-provided reference for this Print Job.", + optional: true, + }, + confirmed: { + type: "boolean", + label: "Confirmed", + description: "Whether to confirm this Print Job immediately, or to leave it as a draft.", + optional: true, + }, + testmode: { + type: "boolean", + label: "Test Mode", + description: "Whether to mark this Print Job as a test.", + optional: true, + }, + splittingMethod: { + type: "string", + label: "Splitting Method", + description: "The method to use to split the Print Job into multiple Print Jobs.", + options: SPLITTING_METHOD_OPTIONS, + optional: true, + }, + splitOnPhrase: { + type: "string", + label: "Split On Phrase", + description: "The word or phrase to split letters using. Only used when **Splitting Method** is set to `split_on_phrase`.", + optional: true, + }, + splitOnPage: { + type: "integer", + label: "Split On Page", + description: "The number of pages each letter should be. Only used when **Splitting Method** is set to `split_on_page`.", + optional: true, + }, + doubleSided: { + type: "string", + label: "Double Sided", + description: "Whether to print these letters double sided.", + options: DOUBLE_SIDED_OPTIONS, + optional: true, + }, + doubleSidedSpecificPages: { + type: "string", + label: "Double Sided Specific Pages", + description: "The array of pages to print double sided. Only used when **Double Sided** is set to `mixed`. Example: **1-3,6-7**.", + optional: true, + }, + premiumQuality: { + type: "boolean", + label: "Premium Quality", + description: "Whether to print these letters in premium quality.", + optional: true, + }, + postageService: { + type: "string", + label: "Postage Service", + description: "The postage service to use for this Print Job.", + options: POSTAGE_SERVICE_OPTIONS, + optional: true, + }, + idealEnvelope: { + type: "string", + label: "Ideal Envelope", + description: "The ideal envelope size for these letters.", + options: IDEAL_ENVELOPE_OPTIONS, + optional: true, + }, + mailDate: { + type: "string", + label: "Mail Date", + description: "The date to send this letter out on. Format: **YYYY-MM-DD**", + optional: true, + }, + backgroundFirstPage: { + type: "string", + label: "Background First Page", + description: "The ID of the Background to apply to the first page of these letters.", + optional: true, + }, + backgroundOtherPages: { + type: "string", + label: "Background Other Pages", + description: "The ID of the Background to apply to the other pages of these letters.", + optional: true, + }, + confidential: { + type: "boolean", + label: "Confidential", + description: "Whether to mark letters of this Print Job as confidential.", + optional: true, + }, + removeLettersWithPhrase: { + type: "string", + label: "Remove Letters With Phrase", + description: "Remove letter objects that have this phrase in their content.", + optional: true, + }, + removeLettersSeries: { + type: "string[]", + label: "Remove Letters Series", + description: "An array of letters' indexes that have been removed.", + optional: true, + }, + nudgeX: { + type: "integer", + label: "Nudge X", + description: "What amount in mm to move the first page of each letter horizontally. A positive number moves the page right, a negative number moves the page left.", + optional: true, + }, + nudgeY: { + type: "integer", + label: "Nudge Y", + description: "What amount in mm to move the first page of each letter vertically. A positive number moves the page down, a negative number moves the page up.", + optional: true, + }, + confirmationEmail: { + type: "boolean", + label: "Confirmation Email", + description: "Whether a confirmation email should be sent to the user or account's email address when this letter is confirmed.", + optional: true, + }, + metadata: { + type: "object", + label: "Metadata", + description: "A key-value object for storing any information you want to along with this Print Job.", + optional: true, + }, + syncDir: { + type: "dir", + accessMode: "read", + sync: true, + optional: false, + }, + }, + async run({ $ }) { + + try { + const { + intelliprint, + confirmed, + testmode, + filePath, + syncDir, + splittingMethod, + splitOnPhrase, + splitOnPage, + doubleSided, + doubleSidedSpecificPages, + premiumQuality, + postageService, + idealEnvelope, + mailDate, + backgroundFirstPage, + backgroundOtherPages, + nudgeX, + nudgeY, + confidential, + removeLettersWithPhrase, + removeLettersSeries, + confirmationEmail, + ...data + } = this; + + const { + stream, metadata, + } = await getFileStreamAndMetadata(filePath); + + const formData = new FormData(); + formData.append("file", stream, { + contentType: metadata.contentType, + knownLength: metadata.size, + filename: metadata.name, + }); + + if (confirmed) formData.append("confirmed", `${confirmed}`); + if (testmode) formData.append("testmode", `${testmode}`); + if (doubleSided) formData.append("printing.double_sided", doubleSided); + if (doubleSidedSpecificPages) formData.append("printing.double_sided_specific_pages", doubleSidedSpecificPages); + if (premiumQuality) formData.append("printing.premium_quality", `${premiumQuality}`); + if (splittingMethod) formData.append("splitting.method", splittingMethod); + if (splitOnPhrase) formData.append("splitting.phrase", splitOnPhrase); + if (splitOnPage) formData.append("splitting.pages", splitOnPage); + if (postageService) formData.append("postage.service", postageService); + if (idealEnvelope) formData.append("postage.ideal_envelope", idealEnvelope); + if (mailDate) formData.append("postage.mail_date", Date.parse(mailDate) / 1000); + if (backgroundFirstPage) formData.append("background.first_page", backgroundFirstPage); + if (backgroundOtherPages) formData.append("background.other_pages", backgroundOtherPages); + if (nudgeX) formData.append("nudge.x", nudgeX); + if (nudgeY) formData.append("nudge.y", nudgeY); + if (confidential) formData.append("confidential", `${confidential}`); + if (removeLettersWithPhrase) formData.append("remove_letters.with_phrase", removeLettersWithPhrase); + if (removeLettersSeries) formData.append("remove_letters.series", JSON.stringify(parseObject(removeLettersSeries))); + if (confirmationEmail) formData.append("confirmation_email", `${confirmationEmail}`); + for (const [ + key, + value, + ] of Object.entries(data)) { + formData.append(camelCaseToSnakeCase(key), `${value}`); + } + + const response = await intelliprint.createPrintJob({ + $, + data: formData, + headers: formData.getHeaders(), + }); + + $.export("$summary", `Successfully created print job with ID: ${response.id}`); + return response; + } catch (error) { + throw new ConfigurationError(`Error creating print job: ${error.response.data.error.message}`); + } + }, +}; diff --git a/components/intelliprint/common/constants.mjs b/components/intelliprint/common/constants.mjs new file mode 100644 index 0000000000000..81b5ac39dd665 --- /dev/null +++ b/components/intelliprint/common/constants.mjs @@ -0,0 +1,27 @@ +export const SPLITTING_METHOD_OPTIONS = [ + "none", + "split_on_phrase", + "split_on_page", +]; + +export const DOUBLE_SIDED_OPTIONS = [ + "no", + "yes", + "mixed", +]; + +export const POSTAGE_SERVICE_OPTIONS = [ + "uk_first_class", + "uk_second_class", + "uk_first_class_signed_for", + "uk_second_class_signed_for", + "uk_special_delivery", + "international", +]; + +export const IDEAL_ENVELOPE_OPTIONS = [ + "c4", + "c5", + "c4_plus", + "a4_box", +]; diff --git a/components/intelliprint/common/utils.mjs b/components/intelliprint/common/utils.mjs new file mode 100644 index 0000000000000..326e0fd09cee5 --- /dev/null +++ b/components/intelliprint/common/utils.mjs @@ -0,0 +1,28 @@ +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 item; + } + } + return item; + }); + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (e) { + return obj; + } + } + return obj; +}; + +export const camelCaseToSnakeCase = (str) => { + return str?.replace(/([A-Z])/g, "_$1").toLowerCase(); +}; diff --git a/components/intelliprint/intelliprint.app.mjs b/components/intelliprint/intelliprint.app.mjs index 70daa1172ea63..0ce9fbdf851ba 100644 --- a/components/intelliprint/intelliprint.app.mjs +++ b/components/intelliprint/intelliprint.app.mjs @@ -1,11 +1,34 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "intelliprint", propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _apiUrl() { + return "https://api.rnbdata.uk/v1"; + }, + _getAuth() { + return { + "username": this.$auth.api_key, + "password": "", + }; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: `${this._apiUrl()}/${path}`, + auth: this._getAuth(), + ...opts, + }); + }, + createPrintJob(args = {}) { + return this._makeRequest({ + method: "POST", + path: "prints", + ...args, + }); }, }, }; diff --git a/components/intelliprint/package.json b/components/intelliprint/package.json index dabe9e4eda77b..d24c569f1aa7e 100644 --- a/components/intelliprint/package.json +++ b/components/intelliprint/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/intelliprint", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Intelliprint Components", "main": "intelliprint.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.1" } } diff --git a/components/just_invoice/just_invoice.app.mjs b/components/just_invoice/just_invoice.app.mjs index 3f97512f53de3..fd9191be42eac 100644 --- a/components/just_invoice/just_invoice.app.mjs +++ b/components/just_invoice/just_invoice.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/pinpoint/pinpoint.app.mjs b/components/pinpoint/pinpoint.app.mjs index 8e0def9e2f4cc..309d8c69a8090 100644 --- a/components/pinpoint/pinpoint.app.mjs +++ b/components/pinpoint/pinpoint.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/pod_ai/pod_ai.app.mjs b/components/pod_ai/pod_ai.app.mjs index 4731ef0dae512..2c15f7756e0cc 100644 --- a/components/pod_ai/pod_ai.app.mjs +++ b/components/pod_ai/pod_ai.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/productify_ai/productify_ai.app.mjs b/components/productify_ai/productify_ai.app.mjs index b7324ef298853..72a2f2e4edb3e 100644 --- a/components/productify_ai/productify_ai.app.mjs +++ b/components/productify_ai/productify_ai.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/proovl/proovl.app.mjs b/components/proovl/proovl.app.mjs index 15774a017071b..00eb58c0c1ecf 100644 --- a/components/proovl/proovl.app.mjs +++ b/components/proovl/proovl.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/transcript_downloader/transcript_downloader.app.mjs b/components/transcript_downloader/transcript_downloader.app.mjs index 0a93c50679884..b103128c125fc 100644 --- a/components/transcript_downloader/transcript_downloader.app.mjs +++ b/components/transcript_downloader/transcript_downloader.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/upsales/upsales.app.mjs b/components/upsales/upsales.app.mjs index 25742c2e6da57..a25cb38c3794c 100644 --- a/components/upsales/upsales.app.mjs +++ b/components/upsales/upsales.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/vatfix_plus/vatfix_plus.app.mjs b/components/vatfix_plus/vatfix_plus.app.mjs index fa80a9ce2469c..6302f6d6cfee6 100644 --- a/components/vatfix_plus/vatfix_plus.app.mjs +++ b/components/vatfix_plus/vatfix_plus.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/wics/wics.app.mjs b/components/wics/wics.app.mjs index 5b5b15cd03c3a..eacfec1860d65 100644 --- a/components/wics/wics.app.mjs +++ b/components/wics/wics.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/components/xero_payroll/xero_payroll.app.mjs b/components/xero_payroll/xero_payroll.app.mjs index 43ded58f0da08..6636a5fb991fb 100644 --- a/components/xero_payroll/xero_payroll.app.mjs +++ b/components/xero_payroll/xero_payroll.app.mjs @@ -8,4 +8,4 @@ export default { console.log(Object.keys(this.$auth)); }, }, -}; \ No newline at end of file +}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ff169f8733652..af840093065b9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7495,7 +7495,11 @@ importers: specifier: ^1.6.8 version: 1.6.8 - components/intelliprint: {} + components/intelliprint: + dependencies: + '@pipedream/platform': + specifier: ^3.1.1 + version: 3.1.1 components/intercom: dependencies: