@pipedream/rendex 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,63 @@
|
|
|
1
|
+
import { ConfigurationError } from "@pipedream/platform";
|
|
2
|
+
import rendex from "../../rendex.app.mjs";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
key: "rendex-render-to-image",
|
|
6
|
+
name: "Render to Image",
|
|
7
|
+
description: "Render an HTML string or a page URL to an image (or PDF) via Rendex. Returns base64-encoded image data with metadata. [See the documentation](https://rendex.dev/docs/api-reference#post-screenshot-json).",
|
|
8
|
+
version: "0.0.1",
|
|
9
|
+
type: "action",
|
|
10
|
+
annotations: {
|
|
11
|
+
destructiveHint: false,
|
|
12
|
+
openWorldHint: true,
|
|
13
|
+
readOnlyHint: false,
|
|
14
|
+
},
|
|
15
|
+
props: {
|
|
16
|
+
rendex,
|
|
17
|
+
html: {
|
|
18
|
+
propDefinition: [
|
|
19
|
+
rendex,
|
|
20
|
+
"html",
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
url: {
|
|
24
|
+
propDefinition: [
|
|
25
|
+
rendex,
|
|
26
|
+
"url",
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
format: {
|
|
30
|
+
propDefinition: [
|
|
31
|
+
rendex,
|
|
32
|
+
"format",
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
async run({ $ }) {
|
|
37
|
+
// Rendex requires exactly one of `html` or `url` per request, so reject both
|
|
38
|
+
// (not just neither) rather than silently dropping `url`.
|
|
39
|
+
const hasHtml = Boolean(this.html);
|
|
40
|
+
const hasUrl = Boolean(this.url);
|
|
41
|
+
if (hasHtml === hasUrl) {
|
|
42
|
+
throw new ConfigurationError("Provide exactly one of `html` or `url`.");
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const data = {
|
|
46
|
+
format: this.format || "png",
|
|
47
|
+
};
|
|
48
|
+
if (hasHtml) {
|
|
49
|
+
data.html = this.html;
|
|
50
|
+
} else {
|
|
51
|
+
data.url = this.url;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const response = await this.rendex.renderJson({
|
|
55
|
+
$,
|
|
56
|
+
data,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const result = response.data;
|
|
60
|
+
$.export("$summary", `Successfully rendered ${result?.format || "image"} (${result?.bytesSize ?? "unknown"} bytes)`);
|
|
61
|
+
return result;
|
|
62
|
+
},
|
|
63
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pipedream/rendex",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Pipedream Rendex Components",
|
|
5
5
|
"main": "rendex.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.1"
|
|
14
17
|
}
|
|
15
18
|
}
|
package/rendex.app.mjs
CHANGED
|
@@ -1,11 +1,68 @@
|
|
|
1
|
+
import { axios } from "@pipedream/platform";
|
|
2
|
+
|
|
1
3
|
export default {
|
|
2
4
|
type: "app",
|
|
3
5
|
app: "rendex",
|
|
4
|
-
propDefinitions: {
|
|
6
|
+
propDefinitions: {
|
|
7
|
+
html: {
|
|
8
|
+
type: "string",
|
|
9
|
+
label: "HTML",
|
|
10
|
+
description: "The HTML markup to render to an image.",
|
|
11
|
+
optional: true,
|
|
12
|
+
},
|
|
13
|
+
url: {
|
|
14
|
+
type: "string",
|
|
15
|
+
label: "URL",
|
|
16
|
+
description: "A page URL to render (alternative to HTML). Provide either `html` or `url`.",
|
|
17
|
+
optional: true,
|
|
18
|
+
},
|
|
19
|
+
format: {
|
|
20
|
+
type: "string",
|
|
21
|
+
label: "Output Format",
|
|
22
|
+
description: "Output file format. Example values: `png`, `jpeg`, `webp`, or `pdf`.",
|
|
23
|
+
optional: true,
|
|
24
|
+
default: "png",
|
|
25
|
+
options: [
|
|
26
|
+
"png",
|
|
27
|
+
"jpeg",
|
|
28
|
+
"webp",
|
|
29
|
+
"pdf",
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
5
33
|
methods: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
34
|
+
_baseUrl() {
|
|
35
|
+
return "https://api.rendex.dev";
|
|
36
|
+
},
|
|
37
|
+
_headers() {
|
|
38
|
+
return {
|
|
39
|
+
"Authorization": `Bearer ${this.$auth.api_key}`,
|
|
40
|
+
"Content-Type": "application/json",
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
_makeRequest({
|
|
44
|
+
$ = this, path, headers, ...opts
|
|
45
|
+
}) {
|
|
46
|
+
return axios($, {
|
|
47
|
+
url: `${this._baseUrl()}${path}`,
|
|
48
|
+
headers: {
|
|
49
|
+
...this._headers(),
|
|
50
|
+
...headers,
|
|
51
|
+
},
|
|
52
|
+
...opts,
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
/**
|
|
56
|
+
* Render HTML or a URL to an image/PDF via POST /v1/screenshot/json.
|
|
57
|
+
* @param {object} opts - axios options; `data` is the JSON request body.
|
|
58
|
+
* @returns {Promise<object>} `{ success, data: { image, format, bytesSize, ... }, meta }`
|
|
59
|
+
*/
|
|
60
|
+
renderJson(opts = {}) {
|
|
61
|
+
return this._makeRequest({
|
|
62
|
+
method: "POST",
|
|
63
|
+
path: "/v1/screenshot/json",
|
|
64
|
+
...opts,
|
|
65
|
+
});
|
|
9
66
|
},
|
|
10
67
|
},
|
|
11
|
-
};
|
|
68
|
+
};
|