@pipedream/printautopilot 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.
@@ -0,0 +1,45 @@
1
+ import printAutopilot from "../../printautopilot.app.mjs";
2
+ import fs from "fs";
3
+
4
+ export default {
5
+ key: "printautopilot-add-pdf-to-queue",
6
+ name: "Add PDF to Print Autopilot Queue",
7
+ description: "Uploads a PDF document to the print-autopilot queue. [See the documentation](https://documenter.getpostman.com/view/1334461/TW6wJonb#53f82327-4f23-416d-b2f0-ce17b8037933)",
8
+ version: "0.0.1",
9
+ type: "action",
10
+ props: {
11
+ printAutopilot,
12
+ filePath: {
13
+ type: "string",
14
+ label: "File Path",
15
+ description: "The path to the file saved to the [`/tmp` directory](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory) (e.g. `/tmp/myFile.pdf`).",
16
+ },
17
+ fileName: {
18
+ type: "string",
19
+ label: "File Name",
20
+ description: "The name of the new file",
21
+ },
22
+ token: {
23
+ type: "string",
24
+ label: "Print Queue Token",
25
+ description: "An API Token associated with the intended print queue",
26
+ secret: true,
27
+ },
28
+ },
29
+ async run({ $ }) {
30
+ const filePath = this.filePath.includes("/tmp")
31
+ ? this.filePath
32
+ : `/tmp/${this.filePath}`;
33
+ const fileContent = Buffer.from(fs.readFileSync(filePath)).toString("base64");
34
+ const response = await this.printAutopilot.addDocumentToQueue({
35
+ token: this.token,
36
+ data: {
37
+ fileName: this.fileName,
38
+ base64: fileContent,
39
+ },
40
+ $,
41
+ });
42
+ $.export("$summary", `Successfully uploaded PDF with path \`${this.filePath}\` to the queue.`);
43
+ return response;
44
+ },
45
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/printautopilot",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "Pipedream PrintAutopilot Components",
5
5
  "main": "printautopilot.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
  }
@@ -1,11 +1,37 @@
1
+ import { axios } from "@pipedream/platform";
2
+
1
3
  export default {
2
4
  type: "app",
3
5
  app: "printautopilot",
4
6
  propDefinitions: {},
5
7
  methods: {
6
- // this.$auth contains connected account data
7
- authKeys() {
8
- console.log(Object.keys(this.$auth));
8
+ _baseUrl() {
9
+ return "https://printautopilot.com/api";
10
+ },
11
+ _headers(token) {
12
+ return {
13
+ "Authorization": `Bearer ${token || this.$auth.connection_token}`,
14
+ };
15
+ },
16
+ _makeRequest(opts = {}) {
17
+ const {
18
+ $ = this,
19
+ path,
20
+ token,
21
+ ...otherOpts
22
+ } = opts;
23
+ return axios($, {
24
+ ...otherOpts,
25
+ url: `${this._baseUrl()}${path}`,
26
+ headers: this._headers(token),
27
+ });
28
+ },
29
+ addDocumentToQueue(opts = {}) {
30
+ return this._makeRequest({
31
+ method: "POST",
32
+ path: "/document/create",
33
+ ...opts,
34
+ });
9
35
  },
10
36
  },
11
- };
37
+ };