@pipedream/printnode 0.0.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Overview
2
+
3
+ The PrintNode API on Pipedream allows you to integrate cloud printing capabilities into workflows. It supports automating print jobs, managing printers, and querying printer status. With Pipedream's ability to connect to hundreds of apps, you can trigger print jobs from emails, forms, databases, or custom events. The API's functions can be weaved into broader business processes to streamline document handling.
4
+
5
+ # Example Use Cases
6
+
7
+ - **Print Shipping Labels on New Orders**: Automatically print shipping labels when new orders come in from an eCommerce platform like Shopify. When an order is placed, Pipedream triggers a workflow that sends the order's shipping label to a designated printer via PrintNode.
8
+
9
+ - **Print Invoices on Payment Confirmation**: Set up a workflow where invoices are automatically printed when payment is confirmed through payment processors like Stripe or PayPal. Once the payment succeeds, a PDF invoice is generated and sent to PrintNode for printing.
10
+
11
+ - **Daily Printout of Sales Reports**: Schedule a daily workflow that queries your sales database, generates a report, and prints it using PrintNode. This could be connected to apps like Google Sheets or Airtable where your sales data is updated.
@@ -0,0 +1,26 @@
1
+ import printnode from "../../printnode.app.mjs";
2
+
3
+ export default {
4
+ key: "printnode-get-printer",
5
+ name: "Get Printer",
6
+ description: "Retrieves data about a specific printer. [See the documentation](https://www.printnode.com/en/docs/api/curl#printers)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ printnode,
11
+ printerId: {
12
+ propDefinition: [
13
+ printnode,
14
+ "printerId",
15
+ ],
16
+ },
17
+ },
18
+ async run({ $ }) {
19
+ const printerData = await this.printnode.getPrinter({
20
+ $,
21
+ printerId: this.printerId,
22
+ });
23
+ $.export("$summary", `Retrieved data for printer (ID: ${this.printerId})`);
24
+ return printerData;
25
+ },
26
+ };
@@ -0,0 +1,20 @@
1
+ import printnode from "../../printnode.app.mjs";
2
+
3
+ export default {
4
+ key: "printnode-list-print-jobs",
5
+ name: "List Print Jobs",
6
+ description: "Returns a list of all print jobs that have been submitted. [See the documentation](https://www.printnode.com/en/docs/api/curl#printjob-viewing)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ printnode,
11
+ },
12
+ async run({ $ }) {
13
+ const response = await this.printnode.listPrintJobs({
14
+ $,
15
+ });
16
+
17
+ $.export("$summary", "Successfully retrieved print jobs");
18
+ return response;
19
+ },
20
+ };
@@ -0,0 +1,91 @@
1
+ import printnode from "../../printnode.app.mjs";
2
+ import { getFileStream } from "@pipedream/platform";
3
+
4
+ export default {
5
+ key: "printnode-send-print-job",
6
+ name: "Send Print Job",
7
+ description: "Sends a print job to a specified printer. [See the documentation](https://www.printnode.com/en/docs/api/curl#creating-print-jobs)",
8
+ version: "1.0.0",
9
+ type: "action",
10
+ props: {
11
+ printnode,
12
+ printerId: {
13
+ propDefinition: [
14
+ printnode,
15
+ "printerId",
16
+ ],
17
+ },
18
+ contentType: {
19
+ propDefinition: [
20
+ printnode,
21
+ "contentType",
22
+ ],
23
+ },
24
+ filePath: {
25
+ type: "string",
26
+ label: "File Path or URL",
27
+ 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`)",
28
+ },
29
+ title: {
30
+ type: "string",
31
+ label: "Title",
32
+ description: "A title to give the print job. This is the name which will appear in the operating system's print queue.",
33
+ optional: true,
34
+ },
35
+ source: {
36
+ type: "string",
37
+ label: "Source",
38
+ description: "A text description of how the print job was created or where the print job originated.",
39
+ optional: true,
40
+ },
41
+ options: {
42
+ type: "object",
43
+ label: "Options",
44
+ description: "An object describing various options which can be set for this print job. [See the documentation for more information](https://www.printnode.com/en/docs/api/curl#printjob-options).",
45
+ optional: true,
46
+ },
47
+ expireAfter: {
48
+ type: "integer",
49
+ label: "Expire After",
50
+ description: "The maximum number of seconds PrintNode should retain this print job in the event that the print job cannot be printed immediately.",
51
+ optional: true,
52
+ },
53
+ qty: {
54
+ type: "integer",
55
+ label: "Quantity",
56
+ description: "A positive integer specifying the number of times this print job should be delivered to the print queue.",
57
+ optional: true,
58
+ default: 1,
59
+ },
60
+ authentication: {
61
+ type: "object",
62
+ label: "Authentication",
63
+ description: "If access to the file URL requires HTTP Basic or Digest Authentication, specify the username and password information here. [See the documentation for more information](https://www.printnode.com/en/docs/api/curl#printjob-creating).",
64
+ optional: true,
65
+ },
66
+ },
67
+ async run({ $ }) {
68
+ const {
69
+ printnode, contentType, filePath, ...props
70
+ } = this;
71
+
72
+ const stream = await getFileStream(filePath);
73
+ const chunks = [];
74
+ for await (const chunk of stream) {
75
+ chunks.push(chunk);
76
+ }
77
+ const content = Buffer.concat(chunks).toString("base64");
78
+
79
+ const response = await printnode.createPrintJob({
80
+ $,
81
+ data: {
82
+ contentType,
83
+ content,
84
+ ...props,
85
+ },
86
+ });
87
+
88
+ $.export("$summary", `Successfully sent print job to printer with ID ${this.printerId}`);
89
+ return response;
90
+ },
91
+ };
@@ -0,0 +1,10 @@
1
+ export const PRINT_CONTENT_OPTIONS = [
2
+ {
3
+ label: "PDF (File)",
4
+ value: "pdf_base64",
5
+ },
6
+ {
7
+ label: "Raw Document (File)",
8
+ value: "raw_base64",
9
+ },
10
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/printnode",
3
- "version": "0.0.1",
3
+ "version": "0.2.0",
4
4
  "description": "Pipedream PrintNode Components",
5
5
  "main": "printnode.app.mjs",
6
6
  "keywords": [
@@ -11,5 +11,8 @@
11
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
12
12
  "publishConfig": {
13
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^3.1.0"
14
17
  }
15
18
  }
package/printnode.app.mjs CHANGED
@@ -1,11 +1,85 @@
1
+ import { axios } from "@pipedream/platform";
2
+ import { PRINT_CONTENT_OPTIONS } from "./common/constants.mjs";
3
+
1
4
  export default {
2
5
  type: "app",
3
6
  app: "printnode",
4
- propDefinitions: {},
7
+ propDefinitions: {
8
+ printerId: {
9
+ type: "integer",
10
+ label: "Printer ID",
11
+ description: "Select a Printer or provide a custom Printer ID.",
12
+ async options() {
13
+ const printers = await this.listPrinters();
14
+ return printers?.map?.(({
15
+ id, name,
16
+ }) => ({
17
+ label: name,
18
+ value: id,
19
+ }));
20
+ },
21
+ },
22
+ contentType: {
23
+ type: "string",
24
+ label: "Content Type",
25
+ description: "The type of content you are sending. [See the documentation for more information](https://www.printnode.com/en/docs/api/curl#create-printjob-content)",
26
+ options: PRINT_CONTENT_OPTIONS,
27
+ },
28
+ },
5
29
  methods: {
6
- // this.$auth contains connected account data
7
- authKeys() {
8
- console.log(Object.keys(this.$auth));
30
+ _baseUrl() {
31
+ return "https://api.printnode.com";
32
+ },
33
+ async _makeRequest({
34
+ $ = this, ...otherOpts
35
+ }) {
36
+ return axios($, {
37
+ ...otherOpts,
38
+ baseURL: this._baseUrl(),
39
+ auth: {
40
+ username: this.$auth.api_key,
41
+ password: "",
42
+ },
43
+ });
44
+ },
45
+ async createPrintJob(args) {
46
+ return this._makeRequest({
47
+ method: "POST",
48
+ url: "/printjobs",
49
+ ...args,
50
+ });
51
+ },
52
+ async getPrinter({
53
+ printerId, ...args
54
+ }) {
55
+ return this._makeRequest({
56
+ url: `/printers/${printerId}`,
57
+ ...args,
58
+ });
59
+ },
60
+ async listPrinters() {
61
+ return this._makeRequest({
62
+ url: "/printers",
63
+ });
64
+ },
65
+ async listPrintJobs(args) {
66
+ return this._makeRequest({
67
+ url: "/printjobs",
68
+ ...args,
69
+ });
70
+ },
71
+ async createWebhook(args) {
72
+ return this._makeRequest({
73
+ method: "POST",
74
+ url: "/webhook",
75
+ ...args,
76
+ });
77
+ },
78
+ async deleteWebhook(webhookId) {
79
+ return this._makeRequest({
80
+ method: "DELETE",
81
+ url: `/webhook/${webhookId}`,
82
+ });
9
83
  },
10
84
  },
11
- };
85
+ };
@@ -0,0 +1,68 @@
1
+ import printnode from "../../printnode.app.mjs";
2
+
3
+ export default {
4
+ key: "printnode-new-event-instant",
5
+ name: "New Event Instant",
6
+ description:
7
+ "Emit new event when a new printnode event is created. [See the documentation](https://www.printnode.com/en/docs/api/curl)",
8
+ version: "0.0.1",
9
+ type: "source",
10
+ dedupe: "unique",
11
+ props: {
12
+ printnode,
13
+ db: "$.service.db",
14
+ http: "$.interface.http",
15
+ eventTypes: {
16
+ type: "string[]",
17
+ label: "Event Types",
18
+ description: "The types of events you want to receive. If not specified, all available events will be emitted. [See the documentation for more information](https://www.printnode.com/en/docs/api/curl#webhooks).",
19
+ optional: true,
20
+ options: [
21
+ "computer state",
22
+ "print job state",
23
+ ],
24
+ },
25
+ },
26
+ methods: {
27
+ _getSecret() {
28
+ return this.db.get("secret");
29
+ },
30
+ _setSecret(value) {
31
+ this.db.set("secret", value);
32
+ },
33
+ _getWebhookId() {
34
+ return this.db.get("webhookId");
35
+ },
36
+ _setWebhookId(value) {
37
+ this.db.set("webhookId", value);
38
+ },
39
+ },
40
+ hooks: {
41
+ async activate() {
42
+ const secret = `pd-${Date.now()}`;
43
+ this._setSecret(secret);
44
+ const { 0: { webhookId } } = await this.printnode.createWebhook({
45
+ data: {
46
+ url: this.http.endpoint,
47
+ secret,
48
+ messages: this.eventTypes ?? [
49
+ "*",
50
+ ],
51
+ },
52
+ });
53
+ this._setWebhookId(webhookId);
54
+ },
55
+ async deactivate() {
56
+ const id = this._getWebhookId();
57
+ await this.printnode.deleteWebhook(id);
58
+ },
59
+ },
60
+ async run({ body }) {
61
+ const ts = Date.now();
62
+ this.$emit(body, {
63
+ id: body.id ?? ts,
64
+ summary: `New event ${body.id ?? body.message ?? ""}`,
65
+ ts,
66
+ });
67
+ },
68
+ };