Skip to content

Commit a00078f

Browse files
13409 components intelliprint (#19216)
* Implement Intelliprint API integration with new create print job action - Added methods for API interaction in intelliprint.app.mjs, including authentication and request handling. - Introduced create-a-print-job action with detailed properties for job configuration. - Updated package version to 0.1.0 and added dependency on @pipedream/platform. - Removed outdated README.md file and added utility function for camelCase to snake_case conversion. * pnpm update * Add constants for print job options in Intelliprint - Introduced a new constants file to define options for splitting methods, double-sided printing, postage services, and ideal envelope sizes. - Updated the create-a-print-job action to utilize these constants for improved maintainability and clarity. * Update components/intelliprint/actions/create-a-print-job/create-a-print-job.mjs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Enhance create-a-print-job action with new options and utility function - Added 'removeLettersSeries' and updated 'removeLettersWithPhrase' properties to the create-a-print-job action for improved letter management. - Introduced 'parseObject' utility function to handle parsing of letter series input. - Updated form data submission to include new properties for better API interaction. * Refactor create-a-print-job action properties for clarity - Renamed 'removeLettersSeries' to 'nudgeX' with updated description for horizontal page adjustment. - Changed 'firstPageBackground' and 'otherPagesBackground' to 'backgroundFirstPage' and 'backgroundOtherPages' for consistency. - Updated form data handling to reflect new property names. * Update create-a-print-job action to enhance property types and form data handling - Changed 'removeLettersSeries' type from string to string[] for better input handling. - Updated 'confirmationEmail' type from string to boolean to reflect its true nature. - Adjusted form data submission to include the new 'confirmation_email' property for API compatibility. * Refactor create-a-print-job action for improved form data handling - Updated 'doubleSidedSpecificPages' type from string to string[] for better input handling. - Enhanced form data submission by restructuring how properties are appended, improving clarity and maintainability. - Ensured all relevant properties are conditionally appended to formData for better API interaction. * Refactor create-a-print-job action to improve double-sided printing handling - Changed 'doubleSidedSpecificPages' type from string[] to string for simplified input. - Updated example format in the description for clarity. - Adjusted form data submission for 'doubleSidedSpecificPages' to directly append the value. - Enhanced error logging for better debugging during print job creation. * Enhance create-a-print-job action with additional form data parameters - Added support for 'confirmed' and 'testmode' parameters in form data submission. - Updated handling of 'mailDate' to ensure proper timestamp conversion. - Included 'confidential' parameter for improved data handling during print job creation. * Remove redundant error logging in create-a-print-job action for cleaner error handling --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent e01ceec commit a00078f

File tree

20 files changed

+354
-29
lines changed

20 files changed

+354
-29
lines changed

components/chartly/chartly.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/cryptlex/cryptlex.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/docuwriter_ai/docuwriter_ai.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/genpage/genpage.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/hybrid_analysis/hybrid_analysis.app.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export default {
88
console.log(Object.keys(this.$auth));
99
},
1010
},
11-
};
11+
};

components/intelliprint/README.md

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
/* eslint-disable no-unused-vars */
2+
import {
3+
ConfigurationError,
4+
getFileStreamAndMetadata,
5+
} from "@pipedream/platform";
6+
import FormData from "form-data";
7+
import {
8+
DOUBLE_SIDED_OPTIONS,
9+
IDEAL_ENVELOPE_OPTIONS,
10+
POSTAGE_SERVICE_OPTIONS,
11+
SPLITTING_METHOD_OPTIONS,
12+
} from "../../common/constants.mjs";
13+
import {
14+
camelCaseToSnakeCase, parseObject,
15+
} from "../../common/utils.mjs";
16+
import intelliprint from "../../intelliprint.app.mjs";
17+
18+
export default {
19+
key: "intelliprint-create-a-print-job",
20+
name: "Create a Print Job",
21+
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)",
22+
version: "0.0.1",
23+
type: "action",
24+
annotations: {
25+
destructiveHint: false,
26+
openWorldHint: true,
27+
readOnlyHint: false,
28+
},
29+
props: {
30+
intelliprint,
31+
filePath: {
32+
type: "string",
33+
label: "File Path",
34+
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`)",
35+
},
36+
reference: {
37+
type: "string",
38+
label: "Reference",
39+
description: "An user-provided reference for this Print Job.",
40+
optional: true,
41+
},
42+
confirmed: {
43+
type: "boolean",
44+
label: "Confirmed",
45+
description: "Whether to confirm this Print Job immediately, or to leave it as a draft.",
46+
optional: true,
47+
},
48+
testmode: {
49+
type: "boolean",
50+
label: "Test Mode",
51+
description: "Whether to mark this Print Job as a test.",
52+
optional: true,
53+
},
54+
splittingMethod: {
55+
type: "string",
56+
label: "Splitting Method",
57+
description: "The method to use to split the Print Job into multiple Print Jobs.",
58+
options: SPLITTING_METHOD_OPTIONS,
59+
optional: true,
60+
},
61+
splitOnPhrase: {
62+
type: "string",
63+
label: "Split On Phrase",
64+
description: "The word or phrase to split letters using. Only used when **Splitting Method** is set to `split_on_phrase`.",
65+
optional: true,
66+
},
67+
splitOnPage: {
68+
type: "integer",
69+
label: "Split On Page",
70+
description: "The number of pages each letter should be. Only used when **Splitting Method** is set to `split_on_page`.",
71+
optional: true,
72+
},
73+
doubleSided: {
74+
type: "string",
75+
label: "Double Sided",
76+
description: "Whether to print these letters double sided.",
77+
options: DOUBLE_SIDED_OPTIONS,
78+
optional: true,
79+
},
80+
doubleSidedSpecificPages: {
81+
type: "string",
82+
label: "Double Sided Specific Pages",
83+
description: "The array of pages to print double sided. Only used when **Double Sided** is set to `mixed`. Example: **1-3,6-7**.",
84+
optional: true,
85+
},
86+
premiumQuality: {
87+
type: "boolean",
88+
label: "Premium Quality",
89+
description: "Whether to print these letters in premium quality.",
90+
optional: true,
91+
},
92+
postageService: {
93+
type: "string",
94+
label: "Postage Service",
95+
description: "The postage service to use for this Print Job.",
96+
options: POSTAGE_SERVICE_OPTIONS,
97+
optional: true,
98+
},
99+
idealEnvelope: {
100+
type: "string",
101+
label: "Ideal Envelope",
102+
description: "The ideal envelope size for these letters.",
103+
options: IDEAL_ENVELOPE_OPTIONS,
104+
optional: true,
105+
},
106+
mailDate: {
107+
type: "string",
108+
label: "Mail Date",
109+
description: "The date to send this letter out on. Format: **YYYY-MM-DD**",
110+
optional: true,
111+
},
112+
backgroundFirstPage: {
113+
type: "string",
114+
label: "Background First Page",
115+
description: "The ID of the Background to apply to the first page of these letters.",
116+
optional: true,
117+
},
118+
backgroundOtherPages: {
119+
type: "string",
120+
label: "Background Other Pages",
121+
description: "The ID of the Background to apply to the other pages of these letters.",
122+
optional: true,
123+
},
124+
confidential: {
125+
type: "boolean",
126+
label: "Confidential",
127+
description: "Whether to mark letters of this Print Job as confidential.",
128+
optional: true,
129+
},
130+
removeLettersWithPhrase: {
131+
type: "string",
132+
label: "Remove Letters With Phrase",
133+
description: "Remove letter objects that have this phrase in their content.",
134+
optional: true,
135+
},
136+
removeLettersSeries: {
137+
type: "string[]",
138+
label: "Remove Letters Series",
139+
description: "An array of letters' indexes that have been removed.",
140+
optional: true,
141+
},
142+
nudgeX: {
143+
type: "integer",
144+
label: "Nudge X",
145+
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.",
146+
optional: true,
147+
},
148+
nudgeY: {
149+
type: "integer",
150+
label: "Nudge Y",
151+
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.",
152+
optional: true,
153+
},
154+
confirmationEmail: {
155+
type: "boolean",
156+
label: "Confirmation Email",
157+
description: "Whether a confirmation email should be sent to the user or account's email address when this letter is confirmed.",
158+
optional: true,
159+
},
160+
metadata: {
161+
type: "object",
162+
label: "Metadata",
163+
description: "A key-value object for storing any information you want to along with this Print Job.",
164+
optional: true,
165+
},
166+
syncDir: {
167+
type: "dir",
168+
accessMode: "read",
169+
sync: true,
170+
optional: false,
171+
},
172+
},
173+
async run({ $ }) {
174+
175+
try {
176+
const {
177+
intelliprint,
178+
confirmed,
179+
testmode,
180+
filePath,
181+
syncDir,
182+
splittingMethod,
183+
splitOnPhrase,
184+
splitOnPage,
185+
doubleSided,
186+
doubleSidedSpecificPages,
187+
premiumQuality,
188+
postageService,
189+
idealEnvelope,
190+
mailDate,
191+
backgroundFirstPage,
192+
backgroundOtherPages,
193+
nudgeX,
194+
nudgeY,
195+
confidential,
196+
removeLettersWithPhrase,
197+
removeLettersSeries,
198+
confirmationEmail,
199+
...data
200+
} = this;
201+
202+
const {
203+
stream, metadata,
204+
} = await getFileStreamAndMetadata(filePath);
205+
206+
const formData = new FormData();
207+
formData.append("file", stream, {
208+
contentType: metadata.contentType,
209+
knownLength: metadata.size,
210+
filename: metadata.name,
211+
});
212+
213+
if (confirmed) formData.append("confirmed", `${confirmed}`);
214+
if (testmode) formData.append("testmode", `${testmode}`);
215+
if (doubleSided) formData.append("printing.double_sided", doubleSided);
216+
if (doubleSidedSpecificPages) formData.append("printing.double_sided_specific_pages", doubleSidedSpecificPages);
217+
if (premiumQuality) formData.append("printing.premium_quality", `${premiumQuality}`);
218+
if (splittingMethod) formData.append("splitting.method", splittingMethod);
219+
if (splitOnPhrase) formData.append("splitting.phrase", splitOnPhrase);
220+
if (splitOnPage) formData.append("splitting.pages", splitOnPage);
221+
if (postageService) formData.append("postage.service", postageService);
222+
if (idealEnvelope) formData.append("postage.ideal_envelope", idealEnvelope);
223+
if (mailDate) formData.append("postage.mail_date", Date.parse(mailDate) / 1000);
224+
if (backgroundFirstPage) formData.append("background.first_page", backgroundFirstPage);
225+
if (backgroundOtherPages) formData.append("background.other_pages", backgroundOtherPages);
226+
if (nudgeX) formData.append("nudge.x", nudgeX);
227+
if (nudgeY) formData.append("nudge.y", nudgeY);
228+
if (confidential) formData.append("confidential", `${confidential}`);
229+
if (removeLettersWithPhrase) formData.append("remove_letters.with_phrase", removeLettersWithPhrase);
230+
if (removeLettersSeries) formData.append("remove_letters.series", JSON.stringify(parseObject(removeLettersSeries)));
231+
if (confirmationEmail) formData.append("confirmation_email", `${confirmationEmail}`);
232+
for (const [
233+
key,
234+
value,
235+
] of Object.entries(data)) {
236+
formData.append(camelCaseToSnakeCase(key), `${value}`);
237+
}
238+
239+
const response = await intelliprint.createPrintJob({
240+
$,
241+
data: formData,
242+
headers: formData.getHeaders(),
243+
});
244+
245+
$.export("$summary", `Successfully created print job with ID: ${response.id}`);
246+
return response;
247+
} catch (error) {
248+
throw new ConfigurationError(`Error creating print job: ${error.response.data.error.message}`);
249+
}
250+
},
251+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export const SPLITTING_METHOD_OPTIONS = [
2+
"none",
3+
"split_on_phrase",
4+
"split_on_page",
5+
];
6+
7+
export const DOUBLE_SIDED_OPTIONS = [
8+
"no",
9+
"yes",
10+
"mixed",
11+
];
12+
13+
export const POSTAGE_SERVICE_OPTIONS = [
14+
"uk_first_class",
15+
"uk_second_class",
16+
"uk_first_class_signed_for",
17+
"uk_second_class_signed_for",
18+
"uk_special_delivery",
19+
"international",
20+
];
21+
22+
export const IDEAL_ENVELOPE_OPTIONS = [
23+
"c4",
24+
"c5",
25+
"c4_plus",
26+
"a4_box",
27+
];
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export const parseObject = (obj) => {
2+
if (!obj) return undefined;
3+
4+
if (Array.isArray(obj)) {
5+
return obj.map((item) => {
6+
if (typeof item === "string") {
7+
try {
8+
return JSON.parse(item);
9+
} catch (e) {
10+
return item;
11+
}
12+
}
13+
return item;
14+
});
15+
}
16+
if (typeof obj === "string") {
17+
try {
18+
return JSON.parse(obj);
19+
} catch (e) {
20+
return obj;
21+
}
22+
}
23+
return obj;
24+
};
25+
26+
export const camelCaseToSnakeCase = (str) => {
27+
return str?.replace(/([A-Z])/g, "_$1").toLowerCase();
28+
};
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "intelliprint",
46
propDefinitions: {},
57
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
8+
_apiUrl() {
9+
return "https://api.rnbdata.uk/v1";
10+
},
11+
_getAuth() {
12+
return {
13+
"username": this.$auth.api_key,
14+
"password": "",
15+
};
16+
},
17+
_makeRequest({
18+
$ = this, path, ...opts
19+
}) {
20+
return axios($, {
21+
url: `${this._apiUrl()}/${path}`,
22+
auth: this._getAuth(),
23+
...opts,
24+
});
25+
},
26+
createPrintJob(args = {}) {
27+
return this._makeRequest({
28+
method: "POST",
29+
path: "prints",
30+
...args,
31+
});
932
},
1033
},
1134
};

0 commit comments

Comments
 (0)