@pipedream/printnode 0.0.1 → 0.1.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/actions/get-printer/get-printer.mjs +26 -0
- package/actions/list-print-jobs/list-print-jobs.mjs +20 -0
- package/actions/send-print-job/send-print-job.mjs +97 -0
- package/common/constants.mjs +18 -0
- package/package.json +4 -1
- package/printnode.app.mjs +79 -5
- package/sources/new-event-instant/new-event-instant.mjs +68 -0
|
@@ -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,97 @@
|
|
|
1
|
+
import printnode from "../../printnode.app.mjs";
|
|
2
|
+
import fs from "fs";
|
|
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: "0.0.1",
|
|
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",
|
|
27
|
+
description: "The path to a document file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#the-tmp-directory).",
|
|
28
|
+
optional: true,
|
|
29
|
+
},
|
|
30
|
+
fileUrl: {
|
|
31
|
+
type: "string",
|
|
32
|
+
label: "File URL",
|
|
33
|
+
description: "The URL to a document file.",
|
|
34
|
+
optional: true,
|
|
35
|
+
},
|
|
36
|
+
title: {
|
|
37
|
+
type: "string",
|
|
38
|
+
label: "Title",
|
|
39
|
+
description: "A title to give the print job. This is the name which will appear in the operating system's print queue.",
|
|
40
|
+
optional: true,
|
|
41
|
+
},
|
|
42
|
+
source: {
|
|
43
|
+
type: "string",
|
|
44
|
+
label: "Source",
|
|
45
|
+
description: "A text description of how the print job was created or where the print job originated.",
|
|
46
|
+
optional: true,
|
|
47
|
+
},
|
|
48
|
+
options: {
|
|
49
|
+
type: "object",
|
|
50
|
+
label: "Options",
|
|
51
|
+
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).",
|
|
52
|
+
optional: true,
|
|
53
|
+
},
|
|
54
|
+
expireAfter: {
|
|
55
|
+
type: "integer",
|
|
56
|
+
label: "Expire After",
|
|
57
|
+
description: "The maximum number of seconds PrintNode should retain this print job in the event that the print job cannot be printed immediately.",
|
|
58
|
+
optional: true,
|
|
59
|
+
},
|
|
60
|
+
qty: {
|
|
61
|
+
type: "integer",
|
|
62
|
+
label: "Quantity",
|
|
63
|
+
description: "A positive integer specifying the number of times this print job should be delivered to the print queue.",
|
|
64
|
+
optional: true,
|
|
65
|
+
default: 1,
|
|
66
|
+
},
|
|
67
|
+
authentication: {
|
|
68
|
+
type: "object",
|
|
69
|
+
label: "Authentication",
|
|
70
|
+
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).",
|
|
71
|
+
optional: true,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
async run({ $ }) {
|
|
75
|
+
const {
|
|
76
|
+
printnode, contentType, filePath, fileUrl, ...props
|
|
77
|
+
} = this;
|
|
78
|
+
const content = contentType.endsWith("base64")
|
|
79
|
+
? fs.readFileSync(filePath.includes("tmp/")
|
|
80
|
+
? filePath
|
|
81
|
+
: `/tmp/${filePath}`, {
|
|
82
|
+
encoding: "base64",
|
|
83
|
+
})
|
|
84
|
+
: fileUrl;
|
|
85
|
+
const response = await printnode.createPrintJob({
|
|
86
|
+
$,
|
|
87
|
+
data: {
|
|
88
|
+
contentType,
|
|
89
|
+
content,
|
|
90
|
+
...props,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
$.export("$summary", `Successfully sent print job to printer with ID ${this.printerId}`);
|
|
95
|
+
return response;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const PRINT_CONTENT_OPTIONS = [
|
|
2
|
+
{
|
|
3
|
+
label: "PDF (URL)",
|
|
4
|
+
value: "pdf_uri",
|
|
5
|
+
},
|
|
6
|
+
{
|
|
7
|
+
label: "PDF (File)",
|
|
8
|
+
value: "pdf_base64",
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
label: "Raw document (URL)",
|
|
12
|
+
value: "raw_uri",
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
label: "Raw Document (File)",
|
|
16
|
+
value: "raw_base64",
|
|
17
|
+
},
|
|
18
|
+
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipedream/printnode",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.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": "1.5.1"
|
|
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). You must also specify a `File Path` or `File URL`.",
|
|
26
|
+
options: PRINT_CONTENT_OPTIONS,
|
|
27
|
+
},
|
|
28
|
+
},
|
|
5
29
|
methods: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
};
|