-
Notifications
You must be signed in to change notification settings - Fork 5.6k
13409 components intelliprint #19216
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
Open
luancazarine
wants to merge
7
commits into
master
Choose a base branch
from
13409-components-intelliprint
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+355
−37
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
877ba58
Implement Intelliprint API integration with new create print job action
luancazarine 70da9d0
pnpm update
luancazarine c7a8420
Add constants for print job options in Intelliprint
luancazarine 2426314
Update components/intelliprint/actions/create-a-print-job/create-a-pr…
luancazarine 2132ccb
Enhance create-a-print-job action with new options and utility function
luancazarine d1060ad
Refactor create-a-print-job action properties for clarity
luancazarine c43de70
Update create-a-print-job action to enhance property types and form d…
luancazarine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
203 changes: 203 additions & 0 deletions
203
components/intelliprint/actions/create-a-print-job/create-a-print-job.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| /* 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 } 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 printing.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, | ||
| }, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| confidential: { | ||
| type: "boolean", | ||
| label: "Confidential", | ||
| description: "Whether to mark letters of this Print Job as confidential.", | ||
| optional: true, | ||
| }, | ||
| removeLetters: { | ||
| type: "string", | ||
| label: "Remove Letters", | ||
| description: "Remove letter objects that have this phrase in their content.", | ||
| 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: "string", | ||
| 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, | ||
| }, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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, | ||
| }, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| async run({ $ }) { | ||
| try { | ||
| const { | ||
| intelliprint, | ||
| filePath, | ||
| syncDir, | ||
| ...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, | ||
| }); | ||
| for (const [ | ||
| key, | ||
| value, | ||
| ] of Object.entries(data)) { | ||
| formData.append(camelCaseToSnakeCase(key), `${value}`); | ||
| } | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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}`); | ||
| } | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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", | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export const camelCaseToSnakeCase = (str) => { | ||
| return str?.replace(/([A-Z])/g, "_$1").toLowerCase(); | ||
| }; | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| }); | ||
| }, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.