orshot 0.1.2 → 0.3.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 +176 -133
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +81 -2
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +56 -3
- package/package.json +4 -1
- package/.github/workflows/npm-publish.yml +0 -24
- package/src/constants.ts +0 -6
- package/src/index.ts +0 -106
- package/src/types.ts +0 -18
- package/tsconfig.json +0 -18
package/README.md
CHANGED
|
@@ -5,11 +5,13 @@ View on npmjs: https://www.npmjs.com/package/orshot
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
Using `npm`
|
|
8
|
+
|
|
8
9
|
```
|
|
9
10
|
npm install --save orshot
|
|
10
11
|
```
|
|
11
12
|
|
|
12
13
|
Using `yarn`
|
|
14
|
+
|
|
13
15
|
```
|
|
14
16
|
yarn add orshot
|
|
15
17
|
```
|
|
@@ -20,13 +22,13 @@ If you don't have your API key, get one from [orshot.com](https://orshot.com)
|
|
|
20
22
|
|
|
21
23
|
### Import
|
|
22
24
|
|
|
23
|
-
```
|
|
24
|
-
const { Orshot } = require(
|
|
25
|
+
```js
|
|
26
|
+
const { Orshot } = require("orshot");
|
|
25
27
|
```
|
|
26
28
|
|
|
27
29
|
With `ES6`
|
|
28
30
|
|
|
29
|
-
```
|
|
31
|
+
```js
|
|
30
32
|
import { Orshot } from "orshot";
|
|
31
33
|
```
|
|
32
34
|
|
|
@@ -36,176 +38,217 @@ import { Orshot } from "orshot";
|
|
|
36
38
|
const orshot = new Orshot("Your API key");
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
|
|
41
|
+
## renderFromStudioTemplate
|
|
40
42
|
|
|
41
|
-
|
|
42
|
-
const response = await Orshot.renderFromTemplate({templateId, modifications, responseType: "base64", responseFormat: "png"});
|
|
43
|
-
console.log(response);
|
|
44
|
-
```
|
|
43
|
+
Render from a custom [Studio template](https://orshot.com/features/orshot-studio). Supports image, PDF, video generation and publishing to social accounts.
|
|
45
44
|
|
|
46
|
-
### Generate
|
|
45
|
+
### Generate Image
|
|
47
46
|
|
|
48
47
|
```js
|
|
49
|
-
const response = await
|
|
50
|
-
|
|
48
|
+
const response = await orshot.renderFromStudioTemplate({
|
|
49
|
+
templateId: 1234,
|
|
50
|
+
modifications: {
|
|
51
|
+
title: "Orshot Studio",
|
|
52
|
+
description: "Generate images from custom templates",
|
|
53
|
+
},
|
|
54
|
+
response: { type: "url", format: "png", scale: 2 },
|
|
55
|
+
});
|
|
51
56
|
```
|
|
52
57
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
### `Base64` response format
|
|
58
|
+
### Generate PDF
|
|
56
59
|
|
|
57
60
|
```js
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const response = await orshot.renderFromTemplate({templateId, modifications, responseType: "base64", responseFormat: "png"});
|
|
72
|
-
console.log(response);
|
|
61
|
+
const response = await orshot.renderFromStudioTemplate({
|
|
62
|
+
templateId: 1234,
|
|
63
|
+
modifications: { title: "Invoice #1234" },
|
|
64
|
+
response: { type: "url", format: "pdf" },
|
|
65
|
+
pdfOptions: {
|
|
66
|
+
margin: "20px",
|
|
67
|
+
rangeFrom: 1,
|
|
68
|
+
rangeTo: 2,
|
|
69
|
+
colorMode: "rgb",
|
|
70
|
+
dpi: 300,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
```
|
|
77
|
-
{
|
|
78
|
-
data: {
|
|
79
|
-
content: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABLAAAAJ2CAYAAABPQHtcAAAAAXNSR0IArs4c6QAAIABJREFUeJzs3XmYJXdZL/Bvna37dM90FghLCBAQkC1BCBAMShLFBJAgKnofroBeFUUF5LrhiihXcV8BQRYVUUAlIewIGPbFmLCFLWwCYZEtzPR+trp/TM/......',
|
|
80
|
-
format: 'png',
|
|
81
|
-
type: 'base64',
|
|
82
|
-
responseTime: 3375.72
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### `URL` response format
|
|
75
|
+
### Generate Video
|
|
88
76
|
|
|
89
77
|
```js
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
API Response
|
|
108
|
-
```
|
|
109
|
-
{
|
|
110
|
-
data: {
|
|
111
|
-
content: 'https://storage.orshot.com/10631481-fd26-44ff-9a61-f52cdf1b8e62/images/r1wCliKXC2B.png',
|
|
112
|
-
type: 'url',
|
|
113
|
-
format: 'png',
|
|
114
|
-
responseTime: 3550.43
|
|
115
|
-
}
|
|
116
|
-
}
|
|
78
|
+
const response = await orshot.renderFromStudioTemplate({
|
|
79
|
+
templateId: 1234,
|
|
80
|
+
modifications: {
|
|
81
|
+
videoElement: "https://example.com/custom-video.mp4",
|
|
82
|
+
"videoElement.trimStart": 0,
|
|
83
|
+
"videoElement.trimEnd": 10,
|
|
84
|
+
},
|
|
85
|
+
response: { type: "url", format: "mp4" },
|
|
86
|
+
videoOptions: {
|
|
87
|
+
trimStart: 0,
|
|
88
|
+
trimEnd: 20,
|
|
89
|
+
muted: false,
|
|
90
|
+
loop: true,
|
|
91
|
+
fps: 30,
|
|
92
|
+
audioSource: "https://example.com/audio.mp3",
|
|
93
|
+
},
|
|
94
|
+
});
|
|
117
95
|
```
|
|
118
96
|
|
|
119
|
-
###
|
|
97
|
+
### Multi-page Video with Transitions
|
|
120
98
|
|
|
121
99
|
```js
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
textColor: "",
|
|
132
|
-
backgroundImageUrl: "",
|
|
133
|
-
backgroundColor: ""
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const response = await orshot.renderFromTemplate({templateId, modifications, responseType: "binary", responseFormat: "png"});
|
|
137
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
138
|
-
const buffer = Buffer.from(arrayBuffer);
|
|
139
|
-
|
|
140
|
-
createWriteStream("og.png").write(buffer);
|
|
100
|
+
const response = await orshot.renderFromStudioTemplate({
|
|
101
|
+
templateId: 1234,
|
|
102
|
+
response: { type: "url", format: "mp4" },
|
|
103
|
+
videoOptions: {
|
|
104
|
+
combinePages: true,
|
|
105
|
+
pageTransition: "fade",
|
|
106
|
+
pageTransitionDuration: 0.5,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
141
109
|
```
|
|
142
110
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
### Signed URL
|
|
111
|
+
### Publish to Social Accounts
|
|
146
112
|
|
|
147
113
|
```js
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
114
|
+
const response = await orshot.renderFromStudioTemplate({
|
|
115
|
+
templateId: 1234,
|
|
116
|
+
modifications: { title: "Check out our latest update!" },
|
|
117
|
+
response: { type: "url", format: "png" },
|
|
118
|
+
publish: {
|
|
119
|
+
accounts: [1, 2],
|
|
120
|
+
content: "Check out our latest design!",
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
// response.publish => [{ platform: "twitter", username: "acmehq", status: "published" }, ...]
|
|
124
|
+
```
|
|
151
125
|
|
|
152
|
-
|
|
153
|
-
let modifications = {
|
|
154
|
-
title: "Orshot",
|
|
155
|
-
description: "Create Visuals and Automate Image Generation",
|
|
156
|
-
textColor: "",
|
|
157
|
-
backgroundImageUrl: "",
|
|
158
|
-
backgroundColor: ""
|
|
159
|
-
}
|
|
126
|
+
### Schedule a Post
|
|
160
127
|
|
|
161
|
-
|
|
162
|
-
|
|
128
|
+
```js
|
|
129
|
+
const response = await orshot.renderFromStudioTemplate({
|
|
130
|
+
templateId: 1234,
|
|
131
|
+
modifications: { title: "Scheduled post" },
|
|
132
|
+
response: { type: "url", format: "png" },
|
|
133
|
+
publish: {
|
|
134
|
+
accounts: [1],
|
|
135
|
+
content: "This will be posted later!",
|
|
136
|
+
schedule: { scheduledFor: "2026-04-01T10:00:00Z" },
|
|
137
|
+
timezone: "America/New_York",
|
|
138
|
+
},
|
|
139
|
+
});
|
|
163
140
|
```
|
|
164
141
|
|
|
142
|
+
### Parameters
|
|
143
|
+
|
|
144
|
+
| key | required | description |
|
|
145
|
+
| ------------------------------- | -------- | ---------------------------------------------------------------------------------------- |
|
|
146
|
+
| `templateId` | Yes | ID of the Studio template. |
|
|
147
|
+
| `modifications` | No | Object of dynamic modifications for the template. |
|
|
148
|
+
| `response.type` | No | `base64`, `binary`, `url` (Defaults to `url`). |
|
|
149
|
+
| `response.format` | No | `png`, `webp`, `jpg`, `jpeg`, `avif`, `pdf`, `mp4`, `webm`, `gif` (Defaults to `png`). |
|
|
150
|
+
| `response.scale` | No | Scale of the output (`1` = original, `2` = double). Defaults to `1`. |
|
|
151
|
+
| `response.quality` | No | Output quality (`1`-`100`). Controls compression for the rendered output. |
|
|
152
|
+
| `response.includePages` | No | Page numbers to render for multi-page templates (e.g. `[1, 3]`). |
|
|
153
|
+
| `response.fileName` | No | Custom file name (without extension). Works with `url` and `binary` types. |
|
|
154
|
+
| `pdfOptions.margin` | No | CSS margin value (e.g. `"20px"`). |
|
|
155
|
+
| `pdfOptions.rangeFrom` | No | Start page number for PDF output. |
|
|
156
|
+
| `pdfOptions.rangeTo` | No | End page number for PDF output. |
|
|
157
|
+
| `pdfOptions.colorMode` | No | `rgb` or `cmyk`. |
|
|
158
|
+
| `pdfOptions.dpi` | No | DPI for print quality (e.g. `300`). |
|
|
159
|
+
| `videoOptions.trimStart` | No | Trim start time in seconds. |
|
|
160
|
+
| `videoOptions.trimEnd` | No | Trim end time in seconds. |
|
|
161
|
+
| `videoOptions.muted` | No | Mute audio track. |
|
|
162
|
+
| `videoOptions.loop` | No | Loop the video. |
|
|
163
|
+
| `videoOptions.duration` | No | Total video duration in seconds. |
|
|
164
|
+
| `videoOptions.fps` | No | Frames per second (`1`-`30`). |
|
|
165
|
+
| `videoOptions.quality` | No | Video quality (`1`-`100`). |
|
|
166
|
+
| `videoOptions.audioSource` | No | External audio URL or array of per-page audio sources. |
|
|
167
|
+
| `videoOptions.subtitleSource` | No | Subtitle file URL. |
|
|
168
|
+
| `videoOptions.combinePages` | No | Combine multi-page templates into a single video. |
|
|
169
|
+
| `videoOptions.pageTransition` | No | Transition effect between pages (e.g. `"fade"`, `"dissolve"`, `"wipe"`, `"slide"`). |
|
|
170
|
+
| `videoOptions.pageTransitionDuration` | No | Transition duration in seconds (`0.1`-`2`). |
|
|
171
|
+
| `publish.accounts` | No | Array of social account IDs from your workspace. |
|
|
172
|
+
| `publish.content` | No | Caption/text for the social post. |
|
|
173
|
+
| `publish.isDraft` | No | `true` to save as draft instead of publishing. |
|
|
174
|
+
| `publish.schedule.scheduledFor` | No | ISO date string to schedule the post. |
|
|
175
|
+
| `publish.timezone` | No | Timezone string (e.g. `"America/New_York"`). |
|
|
176
|
+
| `publish.platformOptions` | No | Per-account options keyed by account ID. |
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
165
180
|
## renderFromTemplate
|
|
166
181
|
|
|
167
|
-
|
|
182
|
+
Render from a pre-built Orshot template.
|
|
168
183
|
|
|
169
|
-
```
|
|
170
|
-
{
|
|
171
|
-
templateId,
|
|
172
|
-
modifications,
|
|
173
|
-
responseType,
|
|
174
|
-
responseFormat
|
|
175
|
-
}
|
|
184
|
+
```js
|
|
185
|
+
const response = await orshot.renderFromTemplate({
|
|
186
|
+
templateId: "open-graph-image-1",
|
|
187
|
+
modifications: { title: "Hello World", description: "Description here" },
|
|
188
|
+
responseType: "url",
|
|
189
|
+
responseFormat: "png",
|
|
190
|
+
});
|
|
176
191
|
```
|
|
177
192
|
|
|
178
|
-
| key
|
|
179
|
-
|
|
180
|
-
| `templateId`
|
|
181
|
-
| `modifications`
|
|
182
|
-
| `responseType`
|
|
183
|
-
| `responseFormat` | No
|
|
193
|
+
| key | required | description |
|
|
194
|
+
| ---------------- | -------- | ---------------------------------------------------------------- |
|
|
195
|
+
| `templateId` | Yes | ID of the template (`open-graph-image-1`, `tweet-image-1`, etc.) |
|
|
196
|
+
| `modifications` | Yes | Modifications for the selected template. |
|
|
197
|
+
| `responseType` | No | `base64`, `binary`, `url` (Defaults to `url`). |
|
|
198
|
+
| `responseFormat` | No | `png`, `webp`, `pdf`, `jpg`, `jpeg` (Defaults to `png`). |
|
|
184
199
|
|
|
185
200
|
For available templates and their modifications refer [Orshot Templates Page](https://orshot.com/templates)
|
|
186
201
|
|
|
187
202
|
## generateSignedUrl
|
|
188
203
|
|
|
189
|
-
|
|
204
|
+
Generate a signed URL for a template.
|
|
190
205
|
|
|
206
|
+
```js
|
|
207
|
+
const response = await orshot.generateSignedUrl({
|
|
208
|
+
templateId: "open-graph-image-1",
|
|
209
|
+
modifications: { title: "Hello World" },
|
|
210
|
+
expiresAt: 1744276943,
|
|
211
|
+
renderType: "images",
|
|
212
|
+
responseFormat: "png",
|
|
213
|
+
});
|
|
191
214
|
```
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
215
|
+
|
|
216
|
+
Use `"never"` for `expiresAt` to create a non-expiring signed URL.
|
|
217
|
+
|
|
218
|
+
| key | required | description |
|
|
219
|
+
| ---------------- | -------- | ------------------------------------------------------------------ |
|
|
220
|
+
| `templateId` | Yes | ID of the template. |
|
|
221
|
+
| `modifications` | Yes | Modifications for the selected template. |
|
|
222
|
+
| `expiresAt` | Yes | Unix timestamp (number) or `"never"` for no expiration. |
|
|
223
|
+
| `renderType` | No | `images`, `pdfs`, `videos` (Defaults to `images`). |
|
|
224
|
+
| `responseFormat` | No | `png`, `webp`, `pdf`, `jpg`, `jpeg` (Defaults to `png`). |
|
|
225
|
+
|
|
226
|
+
## Error Handling
|
|
227
|
+
|
|
228
|
+
The SDK throws errors with descriptive messages from the API when a request fails.
|
|
229
|
+
|
|
230
|
+
```js
|
|
231
|
+
try {
|
|
232
|
+
const response = await orshot.renderFromStudioTemplate({
|
|
233
|
+
templateId: 1234,
|
|
234
|
+
modifications: { title: "Hello" },
|
|
235
|
+
});
|
|
236
|
+
} catch (error) {
|
|
237
|
+
console.error(error.message);
|
|
238
|
+
// e.g. "Template not found in workspace"
|
|
239
|
+
// e.g. "Subscription inactive"
|
|
240
|
+
// e.g. "Invalid API Key"
|
|
198
241
|
}
|
|
199
242
|
```
|
|
200
243
|
|
|
201
|
-
|
|
202
|
-
|----------|----------|-------------|
|
|
203
|
-
| `templateId` | Yes | ID of the template (`open-graph-image-1`, `tweet-image-1`, `beautify-screenshot-1`, ...) |
|
|
204
|
-
| `modifications` | Yes | Modifications for the selected template. |
|
|
205
|
-
| `expiresAt` | Yes | Expires at in unix timestamp (Number). |
|
|
206
|
-
| `renderType` | No | `images`, `pdfs` (Defaults to `images`). |
|
|
207
|
-
| `responseFormat` | No | `png`, `webp`, `pdf`, `jpg`, `jpeg` (Defaults to `png`). |
|
|
244
|
+
## TypeScript
|
|
208
245
|
|
|
246
|
+
All types are exported from the package:
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
import { Orshot } from "orshot";
|
|
250
|
+
import type { StudioRenderOptions, VideoOptions, PdfOptions, PublishOptions } from "orshot";
|
|
251
|
+
```
|
|
209
252
|
|
|
210
253
|
## Local development and testing
|
|
211
254
|
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const ORSHOT_SOURCE = "orshot-node-sdk";
|
|
2
2
|
export declare const ORSHOT_API_BASE_URL = "https://api.orshot.com";
|
|
3
3
|
export declare const ORSHOT_API_VERSION = "v1";
|
|
4
|
-
export declare const DEFAULT_RESPONSE_TYPE = "
|
|
4
|
+
export declare const DEFAULT_RESPONSE_TYPE = "url";
|
|
5
5
|
export declare const DEFAULT_RESPONSE_FORMAT = "png";
|
|
6
6
|
export declare const DEFAULT_RENDER_TYPE = "images";
|
package/dist/constants.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.DEFAULT_RENDER_TYPE = exports.DEFAULT_RESPONSE_FORMAT = exports.DEFAULT_
|
|
|
4
4
|
exports.ORSHOT_SOURCE = "orshot-node-sdk";
|
|
5
5
|
exports.ORSHOT_API_BASE_URL = "https://api.orshot.com";
|
|
6
6
|
exports.ORSHOT_API_VERSION = "v1";
|
|
7
|
-
exports.DEFAULT_RESPONSE_TYPE = "
|
|
7
|
+
exports.DEFAULT_RESPONSE_TYPE = "url";
|
|
8
8
|
exports.DEFAULT_RESPONSE_FORMAT = "png";
|
|
9
9
|
exports.DEFAULT_RENDER_TYPE = "images";
|
|
10
10
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,iBAAiB,CAAC;AAClC,QAAA,mBAAmB,GAAG,wBAAwB,CAAC;AAC/C,QAAA,kBAAkB,GAAG,IAAI,CAAC;AAC1B,QAAA,qBAAqB,GAAG,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,iBAAiB,CAAC;AAClC,QAAA,mBAAmB,GAAG,wBAAwB,CAAC;AAC/C,QAAA,kBAAkB,GAAG,IAAI,CAAC;AAC1B,QAAA,qBAAqB,GAAG,KAAK,CAAC;AAC9B,QAAA,uBAAuB,GAAG,KAAK,CAAC;AAChC,QAAA,mBAAmB,GAAG,QAAQ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { TemplateRenderOptions, SignedUrlOptions } from "./types";
|
|
1
|
+
import { TemplateRenderOptions, SignedUrlOptions, StudioRenderOptions } from "./types";
|
|
2
|
+
export type { ResponseType, ResponseFormat, RenderType, TemplateRenderOptions, SignedUrlOptions, StudioRenderOptions, StudioResponseOptions, PdfOptions, VideoOptions, PublishOptions, PublishSchedule, } from "./types";
|
|
2
3
|
export declare class Orshot {
|
|
3
4
|
private readonly apiKey;
|
|
4
5
|
constructor(apiKey: string);
|
|
@@ -9,5 +10,6 @@ export declare class Orshot {
|
|
|
9
10
|
};
|
|
10
11
|
renderFromTemplate(renderOptions: TemplateRenderOptions): Promise<any>;
|
|
11
12
|
generateSignedUrl(signedUrlOptions: SignedUrlOptions): Promise<any>;
|
|
13
|
+
renderFromStudioTemplate(options: StudioRenderOptions): Promise<any>;
|
|
12
14
|
}
|
|
13
15
|
export default Orshot;
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,16 @@ class Orshot {
|
|
|
46
46
|
}),
|
|
47
47
|
});
|
|
48
48
|
if (!response.ok) {
|
|
49
|
-
|
|
49
|
+
let message = `Request failed with status ${response.status}`;
|
|
50
|
+
try {
|
|
51
|
+
const errorData = await response.json();
|
|
52
|
+
if (errorData?.error)
|
|
53
|
+
message = errorData.error;
|
|
54
|
+
else if (errorData?.message)
|
|
55
|
+
message = errorData.message;
|
|
56
|
+
}
|
|
57
|
+
catch { }
|
|
58
|
+
throw new Error(message);
|
|
50
59
|
}
|
|
51
60
|
if (responseType === "base64" || responseType === "url") {
|
|
52
61
|
const jsonData = await response.json();
|
|
@@ -78,11 +87,81 @@ class Orshot {
|
|
|
78
87
|
}),
|
|
79
88
|
});
|
|
80
89
|
if (!response.ok) {
|
|
81
|
-
|
|
90
|
+
let message = `Request failed with status ${response.status}`;
|
|
91
|
+
try {
|
|
92
|
+
const errorData = await response.json();
|
|
93
|
+
if (errorData?.error)
|
|
94
|
+
message = errorData.error;
|
|
95
|
+
else if (errorData?.message)
|
|
96
|
+
message = errorData.message;
|
|
97
|
+
}
|
|
98
|
+
catch { }
|
|
99
|
+
throw new Error(message);
|
|
82
100
|
}
|
|
83
101
|
const jsonData = await response.json();
|
|
84
102
|
return jsonData;
|
|
85
103
|
}
|
|
104
|
+
async renderFromStudioTemplate(options) {
|
|
105
|
+
const { templateId, modifications, response: responseOptions, pdfOptions, videoOptions, publish } = options;
|
|
106
|
+
const endpoint = `${this.getBaseUrl()}/studio/render`;
|
|
107
|
+
const body = {
|
|
108
|
+
templateId,
|
|
109
|
+
source: constants_1.ORSHOT_SOURCE,
|
|
110
|
+
};
|
|
111
|
+
if (modifications) {
|
|
112
|
+
body.modifications = modifications;
|
|
113
|
+
}
|
|
114
|
+
body.response = {
|
|
115
|
+
type: responseOptions?.type ?? constants_1.DEFAULT_RESPONSE_TYPE,
|
|
116
|
+
format: responseOptions?.format ?? constants_1.DEFAULT_RESPONSE_FORMAT,
|
|
117
|
+
};
|
|
118
|
+
if (responseOptions?.scale !== undefined) {
|
|
119
|
+
body.response.scale = responseOptions.scale;
|
|
120
|
+
}
|
|
121
|
+
if (responseOptions?.includePages) {
|
|
122
|
+
body.response.includePages = responseOptions.includePages;
|
|
123
|
+
}
|
|
124
|
+
if (responseOptions?.quality !== undefined) {
|
|
125
|
+
body.response.quality = responseOptions.quality;
|
|
126
|
+
}
|
|
127
|
+
if (responseOptions?.fileName) {
|
|
128
|
+
body.response.fileName = responseOptions.fileName;
|
|
129
|
+
}
|
|
130
|
+
if (pdfOptions) {
|
|
131
|
+
body.pdfOptions = pdfOptions;
|
|
132
|
+
}
|
|
133
|
+
if (videoOptions) {
|
|
134
|
+
body.videoOptions = videoOptions;
|
|
135
|
+
}
|
|
136
|
+
if (publish) {
|
|
137
|
+
body.publish = publish;
|
|
138
|
+
}
|
|
139
|
+
const response = await fetch(endpoint, {
|
|
140
|
+
method: "POST",
|
|
141
|
+
headers: this.getHeaders(),
|
|
142
|
+
body: JSON.stringify(body),
|
|
143
|
+
});
|
|
144
|
+
if (!response.ok) {
|
|
145
|
+
let message = `Request failed with status ${response.status}`;
|
|
146
|
+
try {
|
|
147
|
+
const errorData = await response.json();
|
|
148
|
+
if (errorData?.error)
|
|
149
|
+
message = errorData.error;
|
|
150
|
+
else if (errorData?.message)
|
|
151
|
+
message = errorData.message;
|
|
152
|
+
}
|
|
153
|
+
catch { }
|
|
154
|
+
throw new Error(message);
|
|
155
|
+
}
|
|
156
|
+
const responseType = responseOptions?.type ?? constants_1.DEFAULT_RESPONSE_TYPE;
|
|
157
|
+
if (responseType === "base64" || responseType === "url") {
|
|
158
|
+
const jsonData = await response.json();
|
|
159
|
+
return jsonData;
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
return response;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
86
165
|
}
|
|
87
166
|
exports.Orshot = Orshot;
|
|
88
167
|
exports.default = Orshot;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,2CAA0J;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,2CAA0J;AAgB1J,MAAa,MAAM;IACA,MAAM,CAAS;IAEhC,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAA;QACzC,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,UAAU,CAAC,OAAgB;QAChC,MAAM,OAAO,GAAG,+BAAmB,CAAC;QAEpC,IAAI,UAAU,GAAG,8BAAkB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I,YAAY,KAAK,KAAK,EAAE,CAAC;YACxD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACvC,OAAO,QAAQ,CAAC;QAClB,CAAC;aAAM,CAAC;YACN,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;CACF;AAzLD,wBAyLC;AAED,kBAAe,MAAM,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type ResponseType = "base64" | "binary" | "url";
|
|
2
|
-
export type ResponseFormat = "png" | "webp" | "pdf" | "jpg" | "jpeg";
|
|
3
|
-
export type RenderType = "images" | "pdfs";
|
|
2
|
+
export type ResponseFormat = "png" | "webp" | "pdf" | "jpg" | "jpeg" | "avif" | "mp4" | "webm" | "gif";
|
|
3
|
+
export type RenderType = "images" | "pdfs" | "videos";
|
|
4
4
|
export type TemplateRenderOptions = {
|
|
5
5
|
templateId: string;
|
|
6
6
|
modifications: any;
|
|
@@ -12,5 +12,58 @@ export type SignedUrlOptions = {
|
|
|
12
12
|
modifications: any;
|
|
13
13
|
renderType?: RenderType;
|
|
14
14
|
responseFormat?: ResponseFormat;
|
|
15
|
-
expiresAt: number;
|
|
15
|
+
expiresAt: number | "never";
|
|
16
|
+
};
|
|
17
|
+
export type StudioResponseOptions = {
|
|
18
|
+
type?: ResponseType;
|
|
19
|
+
format?: ResponseFormat;
|
|
20
|
+
scale?: number;
|
|
21
|
+
quality?: number;
|
|
22
|
+
includePages?: number[];
|
|
23
|
+
fileName?: string;
|
|
24
|
+
};
|
|
25
|
+
export type PdfOptions = {
|
|
26
|
+
margin?: string;
|
|
27
|
+
rangeFrom?: number | null;
|
|
28
|
+
rangeTo?: number | null;
|
|
29
|
+
colorMode?: "rgb" | "cmyk";
|
|
30
|
+
dpi?: number;
|
|
31
|
+
};
|
|
32
|
+
export type VideoOptions = {
|
|
33
|
+
trimStart?: number;
|
|
34
|
+
trimEnd?: number;
|
|
35
|
+
muted?: boolean;
|
|
36
|
+
loop?: boolean;
|
|
37
|
+
duration?: number;
|
|
38
|
+
fps?: number;
|
|
39
|
+
quality?: number;
|
|
40
|
+
audioSource?: string | Array<{
|
|
41
|
+
url: string;
|
|
42
|
+
pageId?: string;
|
|
43
|
+
page?: number;
|
|
44
|
+
track?: string;
|
|
45
|
+
}>;
|
|
46
|
+
subtitleSource?: string;
|
|
47
|
+
combinePages?: boolean;
|
|
48
|
+
pageTransition?: string;
|
|
49
|
+
pageTransitionDuration?: number;
|
|
50
|
+
};
|
|
51
|
+
export type PublishSchedule = {
|
|
52
|
+
scheduledFor?: string;
|
|
53
|
+
};
|
|
54
|
+
export type PublishOptions = {
|
|
55
|
+
accounts: number[];
|
|
56
|
+
content?: string;
|
|
57
|
+
isDraft?: boolean;
|
|
58
|
+
schedule?: PublishSchedule;
|
|
59
|
+
timezone?: string;
|
|
60
|
+
platformOptions?: Record<string, any>;
|
|
61
|
+
};
|
|
62
|
+
export type StudioRenderOptions = {
|
|
63
|
+
templateId: number | string;
|
|
64
|
+
modifications?: Record<string, any>;
|
|
65
|
+
response?: StudioResponseOptions;
|
|
66
|
+
pdfOptions?: PdfOptions;
|
|
67
|
+
videoOptions?: VideoOptions;
|
|
68
|
+
publish?: PublishOptions;
|
|
16
69
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "orshot",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Orshot API SDK for Node.js",
|
|
5
5
|
"homepage": "https://orshot.com",
|
|
6
6
|
"bugs": {
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
"author": "Rishi Mohan <iamrishi.ms@gmail.com>",
|
|
15
15
|
"main": "dist/index.js",
|
|
16
16
|
"types": "dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
17
20
|
"scripts": {
|
|
18
21
|
"build": "tsc"
|
|
19
22
|
},
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
-
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
-
|
|
4
|
-
name: Publish Package to npmjs
|
|
5
|
-
on:
|
|
6
|
-
release:
|
|
7
|
-
types: [published]
|
|
8
|
-
jobs:
|
|
9
|
-
build:
|
|
10
|
-
runs-on: ubuntu-latest
|
|
11
|
-
permissions:
|
|
12
|
-
contents: read
|
|
13
|
-
id-token: write
|
|
14
|
-
steps:
|
|
15
|
-
- uses: actions/checkout@v4
|
|
16
|
-
- uses: actions/setup-node@v4
|
|
17
|
-
with:
|
|
18
|
-
node-version: '20.x'
|
|
19
|
-
registry-url: 'https://registry.npmjs.org'
|
|
20
|
-
- run: npm ci
|
|
21
|
-
- run: npm run build
|
|
22
|
-
- run: npm publish --provenance --access public
|
|
23
|
-
env:
|
|
24
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/src/constants.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export const ORSHOT_SOURCE = "orshot-node-sdk";
|
|
2
|
-
export const ORSHOT_API_BASE_URL = "https://api.orshot.com";
|
|
3
|
-
export const ORSHOT_API_VERSION = "v1";
|
|
4
|
-
export const DEFAULT_RESPONSE_TYPE = "base64";
|
|
5
|
-
export const DEFAULT_RESPONSE_FORMAT = "png";
|
|
6
|
-
export const DEFAULT_RENDER_TYPE = "images";
|
package/src/index.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { TemplateRenderOptions, SignedUrlOptions } from "./types";
|
|
2
|
-
import { DEFAULT_RESPONSE_TYPE, DEFAULT_RESPONSE_FORMAT, DEFAULT_RENDER_TYPE, ORSHOT_API_BASE_URL, ORSHOT_API_VERSION, ORSHOT_SOURCE } from "./constants";
|
|
3
|
-
|
|
4
|
-
export class Orshot {
|
|
5
|
-
private readonly apiKey: string;
|
|
6
|
-
|
|
7
|
-
constructor(apiKey: string) {
|
|
8
|
-
if (!apiKey) {
|
|
9
|
-
throw new Error("API Key is required.")
|
|
10
|
-
}
|
|
11
|
-
this.apiKey = apiKey;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
public getBaseUrl(version?: string) {
|
|
15
|
-
const baseUrl = ORSHOT_API_BASE_URL;
|
|
16
|
-
|
|
17
|
-
let apiVersion = ORSHOT_API_VERSION;
|
|
18
|
-
|
|
19
|
-
if (version) {
|
|
20
|
-
apiVersion = version;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return `${baseUrl}/${apiVersion}`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public getHeaders() {
|
|
27
|
-
return {
|
|
28
|
-
'Content-Type': 'application/json',
|
|
29
|
-
'Authorization': `Bearer ${this.apiKey}`
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
public async renderFromTemplate(renderOptions: TemplateRenderOptions) {
|
|
34
|
-
let { templateId, modifications, responseType, responseFormat } = renderOptions;
|
|
35
|
-
|
|
36
|
-
if (!responseType) {
|
|
37
|
-
responseType = DEFAULT_RESPONSE_TYPE;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (!responseFormat) {
|
|
41
|
-
responseFormat = DEFAULT_RESPONSE_FORMAT;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
let endpoint = `${this.getBaseUrl()}/generate/images/${templateId}`;
|
|
45
|
-
|
|
46
|
-
const response = await fetch(endpoint, {
|
|
47
|
-
method: "POST",
|
|
48
|
-
headers: this.getHeaders(),
|
|
49
|
-
body: JSON.stringify({
|
|
50
|
-
response: {
|
|
51
|
-
type: responseType,
|
|
52
|
-
format: responseFormat
|
|
53
|
-
},
|
|
54
|
-
modifications: modifications,
|
|
55
|
-
source: ORSHOT_SOURCE
|
|
56
|
-
}),
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
if (!response.ok) {
|
|
60
|
-
throw new Error("Failed to fetch image: " + response.status);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (responseType === "base64" || responseType === "url") {
|
|
64
|
-
const jsonData = await response.json();
|
|
65
|
-
return jsonData;
|
|
66
|
-
} else {
|
|
67
|
-
return response;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public async generateSignedUrl(signedUrlOptions: SignedUrlOptions) {
|
|
72
|
-
let { templateId, modifications, renderType, responseFormat, expiresAt } = signedUrlOptions;
|
|
73
|
-
|
|
74
|
-
if (!renderType) {
|
|
75
|
-
renderType = DEFAULT_RENDER_TYPE;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (!responseFormat) {
|
|
79
|
-
responseFormat = DEFAULT_RESPONSE_FORMAT;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
let endpoint = `${this.getBaseUrl()}/signed-url/create`;
|
|
83
|
-
|
|
84
|
-
const response = await fetch(endpoint, {
|
|
85
|
-
method: "POST",
|
|
86
|
-
headers: this.getHeaders(),
|
|
87
|
-
body: JSON.stringify({
|
|
88
|
-
templateId: templateId,
|
|
89
|
-
renderType: renderType,
|
|
90
|
-
responseFormat: responseFormat,
|
|
91
|
-
modifications: modifications,
|
|
92
|
-
source: ORSHOT_SOURCE,
|
|
93
|
-
expiresAt: expiresAt
|
|
94
|
-
}),
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
if (!response.ok) {
|
|
98
|
-
throw new Error("Failed to fetch image: " + response.status);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const jsonData = await response.json();
|
|
102
|
-
return jsonData;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export default Orshot;
|
package/src/types.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export type ResponseType = "base64" | "binary" | "url";
|
|
2
|
-
export type ResponseFormat = "png" | "webp" | "pdf" | "jpg" | "jpeg" ;
|
|
3
|
-
export type RenderType = "images" | "pdfs";
|
|
4
|
-
|
|
5
|
-
export type TemplateRenderOptions = {
|
|
6
|
-
templateId: string;
|
|
7
|
-
modifications: any;
|
|
8
|
-
responseType?: ResponseType;
|
|
9
|
-
responseFormat?: ResponseFormat;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type SignedUrlOptions = {
|
|
13
|
-
templateId: string;
|
|
14
|
-
modifications: any;
|
|
15
|
-
renderType?: RenderType;
|
|
16
|
-
responseFormat?: ResponseFormat;
|
|
17
|
-
expiresAt: number;
|
|
18
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"module": "commonjs",
|
|
4
|
-
"esModuleInterop": true,
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"target": "esnext",
|
|
7
|
-
"moduleResolution": "node",
|
|
8
|
-
"sourceMap": true,
|
|
9
|
-
"outDir": "dist"
|
|
10
|
-
},
|
|
11
|
-
"include": [
|
|
12
|
-
"src/**/*"
|
|
13
|
-
],
|
|
14
|
-
"exclude": [
|
|
15
|
-
"node_modules",
|
|
16
|
-
"dist"
|
|
17
|
-
]
|
|
18
|
-
}
|