Skip to content

Commit 877ba58

Browse files
committed
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.
1 parent 6845b85 commit 877ba58

File tree

5 files changed

+250
-15
lines changed

5 files changed

+250
-15
lines changed

components/intelliprint/README.md

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
/* eslint-disable no-unused-vars */
2+
import {
3+
ConfigurationError,
4+
getFileStreamAndMetadata,
5+
} from "@pipedream/platform";
6+
import FormData from "form-data";
7+
import { camelCaseToSnakeCase } from "../../common/utils.mjs";
8+
import intelliprint from "../../intelliprint.app.mjs";
9+
10+
export default {
11+
key: "intelliprint-create-a-print-job",
12+
name: "Create a Print Job",
13+
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)",
14+
version: "0.0.1",
15+
type: "action",
16+
annotations: {
17+
destructiveHint: false,
18+
openWorldHint: true,
19+
readOnlyHint: false,
20+
},
21+
props: {
22+
intelliprint,
23+
filePath: {
24+
type: "string",
25+
label: "File Path",
26+
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`)",
27+
},
28+
reference: {
29+
type: "string",
30+
label: "Reference",
31+
description: "An user-provided reference for this Print Job.",
32+
optional: true,
33+
},
34+
confirmed: {
35+
type: "boolean",
36+
label: "Confirmed",
37+
description: "Whether to confirm this Print Job immediately, or to leave it as a draft.",
38+
optional: true,
39+
},
40+
testmode: {
41+
type: "boolean",
42+
label: "Test Mode",
43+
description: "Whether to mark this Print Job as a test.",
44+
optional: true,
45+
},
46+
splittingMethod: {
47+
type: "string",
48+
label: "Splitting Method",
49+
description: "The method to use to split the Print Job into multiple Print Jobs.",
50+
options: [
51+
"none",
52+
"split_on_phrase",
53+
"split_on_page",
54+
],
55+
optional: true,
56+
},
57+
splitOnPhrase: {
58+
type: "string",
59+
label: "Split On Phrase",
60+
description: "The word or phrase to split letters using. Only used when **Splitting Method** is set to `split_on_phrase`.",
61+
optional: true,
62+
},
63+
splitOnPage: {
64+
type: "integer",
65+
label: "Split On Page",
66+
description: "The number of pages each letter should be. Only used when **Splitting Method** is set to `split_on_page`.",
67+
optional: true,
68+
},
69+
doubleSided: {
70+
type: "string",
71+
label: "Double Sided",
72+
description: "Whether to print these letters double sided.",
73+
options: [
74+
"no",
75+
"yes",
76+
"mixed",
77+
],
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 printing.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: [
97+
"uk_first_class",
98+
"uk_second_class",
99+
"uk_first_class_signed_for",
100+
"uk_second_class_signed_for",
101+
"uk_special_delivery",
102+
"international",
103+
],
104+
optional: true,
105+
},
106+
idealEnvelope: {
107+
type: "string",
108+
label: "Ideal Envelope",
109+
description: "The ideal envelope size for these letters.",
110+
options: [
111+
"c4",
112+
"c5",
113+
"c4_plus",
114+
"a4_box",
115+
],
116+
optional: true,
117+
},
118+
mailDate: {
119+
type: "string",
120+
label: "Mail Date",
121+
description: "The date to send this letter out on. Format: **YYYY-MM-DD**",
122+
optional: true,
123+
},
124+
backgroundFirstPage: {
125+
type: "string",
126+
label: "Background First Page",
127+
description: "The ID of the Background to apply to the first page of these letters.",
128+
optional: true,
129+
},
130+
backgroundOtherPages: {
131+
type: "string",
132+
label: "Background Other Pages",
133+
description: "The ID of the Background to apply to the other pages of these letters.",
134+
optional: true,
135+
},
136+
confidential: {
137+
type: "boolean",
138+
label: "Confidential",
139+
description: "Whether to mark letters of this Print Job as confidential.",
140+
optional: true,
141+
},
142+
removeLetters: {
143+
type: "string",
144+
label: "Remove Letters",
145+
description: "Remove letter objects that have this phrase in their content.",
146+
optional: true,
147+
},
148+
nudgeX: {
149+
type: "integer",
150+
label: "Nudge X",
151+
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.",
152+
optional: true,
153+
},
154+
nudgeY: {
155+
type: "integer",
156+
label: "Nudge Y",
157+
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.",
158+
optional: true,
159+
},
160+
confirmationEmail: {
161+
type: "string",
162+
label: "Confirmation Email",
163+
description: "Whether a confirmation email should be sent to the user or account's email address when this letter is confirmed.",
164+
optional: true,
165+
},
166+
metadata: {
167+
type: "object",
168+
label: "Metadata",
169+
description: "A key-value object for storing any information you want to along with this Print Job.",
170+
optional: true,
171+
},
172+
syncDir: {
173+
type: "dir",
174+
accessMode: "read",
175+
sync: true,
176+
optional: false,
177+
},
178+
},
179+
async run({ $ }) {
180+
try {
181+
const {
182+
intelliprint,
183+
filePath,
184+
syncDir,
185+
...data
186+
} = this;
187+
188+
const {
189+
stream, metadata,
190+
} = await getFileStreamAndMetadata(filePath);
191+
192+
const formData = new FormData();
193+
formData.append("file", stream, {
194+
contentType: metadata.contentType,
195+
knownLength: metadata.size,
196+
filename: metadata.name,
197+
});
198+
for (const [
199+
key,
200+
value,
201+
] of Object.entries(data)) {
202+
formData.append(camelCaseToSnakeCase(key), `${value}`);
203+
}
204+
205+
const response = await intelliprint.createPrintJob({
206+
$,
207+
data: formData,
208+
headers: formData.getHeaders(),
209+
});
210+
211+
$.export("$summary", `Successfully created print job with ID: ${response.id}`);
212+
return response;
213+
} catch (error) {
214+
throw new ConfigurationError(`Error creating print job: ${error.response.data.error.message}`);
215+
}
216+
},
217+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const camelCaseToSnakeCase = (str) => {
2+
return str?.replace(/([A-Z])/g, "_$1").toLowerCase();
3+
};
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
};

components/intelliprint/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/intelliprint",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream Intelliprint Components",
55
"main": "intelliprint.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.1.1"
1417
}
1518
}

0 commit comments

Comments
 (0)