orshot 0.1.2 → 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 +120 -143
- package/package.json +1 -1
- package/src/constants.ts +1 -1
- package/src/index.ts +64 -1
- package/src/types.ts +46 -1
- package/dist/constants.d.ts +0 -6
- package/dist/constants.js +0 -10
- package/dist/constants.js.map +0 -1
- package/dist/index.d.ts +0 -13
- package/dist/index.js +0 -89
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts +0 -16
- package/dist/types.js +0 -3
- package/dist/types.js.map +0 -1
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,151 @@ 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
|
-
|
|
72
|
-
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
API Response
|
|
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
|
|
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
|
+
```
|
|
74
|
+
|
|
75
|
+
### Generate Video
|
|
88
76
|
|
|
89
77
|
```js
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
backgroundColor: ""
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const response = await orshot.renderFromTemplate({templateId, modifications, responseType: "url", responseFormat: "png"});
|
|
104
|
-
console.log(response);
|
|
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: { trimStart: 0, trimEnd: 20, muted: false, loop: true },
|
|
87
|
+
});
|
|
105
88
|
```
|
|
106
89
|
|
|
107
|
-
|
|
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
|
-
}
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
### `Binary` response format
|
|
90
|
+
### Publish to Social Accounts
|
|
120
91
|
|
|
121
92
|
```js
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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);
|
|
93
|
+
const response = await orshot.renderFromStudioTemplate({
|
|
94
|
+
templateId: 1234,
|
|
95
|
+
modifications: { title: "Check out our latest update!" },
|
|
96
|
+
response: { type: "url", format: "png" },
|
|
97
|
+
publish: {
|
|
98
|
+
accounts: [1, 2],
|
|
99
|
+
content: "Check out our latest design!",
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
// response.publish => [{ platform: "twitter", username: "acmehq", status: "published" }, ...]
|
|
141
103
|
```
|
|
142
104
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
### Signed URL
|
|
105
|
+
### Schedule a Post
|
|
146
106
|
|
|
147
107
|
```js
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
108
|
+
const response = await orshot.renderFromStudioTemplate({
|
|
109
|
+
templateId: 1234,
|
|
110
|
+
modifications: { title: "Scheduled post" },
|
|
111
|
+
response: { type: "url", format: "png" },
|
|
112
|
+
publish: {
|
|
113
|
+
accounts: [1],
|
|
114
|
+
content: "This will be posted later!",
|
|
115
|
+
schedule: { scheduledFor: "2026-04-01T10:00:00Z" },
|
|
116
|
+
timezone: "America/New_York",
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Parameters
|
|
122
|
+
|
|
123
|
+
| key | required | description |
|
|
124
|
+
| ------------------------------- | -------- | ------------------------------------------------------------------------------ |
|
|
125
|
+
| `templateId` | Yes | ID of the Studio template (integer). |
|
|
126
|
+
| `modifications` | No | Object of dynamic modifications for the template. |
|
|
127
|
+
| `response.type` | No | `base64`, `binary`, `url` (Defaults to `url`). |
|
|
128
|
+
| `response.format` | No | `png`, `webp`, `jpg`, `jpeg`, `pdf`, `mp4`, `webm`, `gif` (Defaults to `png`). |
|
|
129
|
+
| `response.scale` | No | Scale of the output (`1` = original, `2` = double). Defaults to `1`. |
|
|
130
|
+
| `response.includePages` | No | Page numbers to render for multi-page templates (e.g. `[1, 3]`). |
|
|
131
|
+
| `response.fileName` | No | Custom file name (without extension). Works with `url` and `binary` types. |
|
|
132
|
+
| `pdfOptions` | No | `{ margin, rangeFrom, rangeTo, colorMode, dpi }` |
|
|
133
|
+
| `videoOptions` | No | `{ trimStart, trimEnd, muted, loop }` |
|
|
134
|
+
| `publish.accounts` | No | Array of social account IDs from your workspace. |
|
|
135
|
+
| `publish.content` | No | Caption/text for the social post. |
|
|
136
|
+
| `publish.isDraft` | No | `true` to save as draft instead of publishing. |
|
|
137
|
+
| `publish.schedule.scheduledFor` | No | ISO date string to schedule the post. |
|
|
138
|
+
| `publish.timezone` | No | Timezone string (e.g. `"America/New_York"`). |
|
|
139
|
+
| `publish.platformOptions` | No | Per-account options keyed by account ID. |
|
|
140
|
+
|
|
141
|
+
---
|
|
164
142
|
|
|
165
143
|
## renderFromTemplate
|
|
166
144
|
|
|
167
|
-
|
|
145
|
+
Render from a pre-built Orshot template.
|
|
168
146
|
|
|
169
|
-
```
|
|
170
|
-
{
|
|
171
|
-
templateId,
|
|
172
|
-
modifications,
|
|
173
|
-
responseType,
|
|
174
|
-
responseFormat
|
|
175
|
-
}
|
|
147
|
+
```js
|
|
148
|
+
const response = await orshot.renderFromTemplate({
|
|
149
|
+
templateId: "open-graph-image-1",
|
|
150
|
+
modifications: { title: "Hello World", description: "Description here" },
|
|
151
|
+
responseType: "url",
|
|
152
|
+
responseFormat: "png",
|
|
153
|
+
});
|
|
176
154
|
```
|
|
177
155
|
|
|
178
|
-
| key
|
|
179
|
-
|
|
180
|
-
| `templateId`
|
|
181
|
-
| `modifications`
|
|
182
|
-
| `responseType`
|
|
183
|
-
| `responseFormat` | No
|
|
156
|
+
| key | required | description |
|
|
157
|
+
| ---------------- | -------- | ---------------------------------------------------------------- |
|
|
158
|
+
| `templateId` | Yes | ID of the template (`open-graph-image-1`, `tweet-image-1`, etc.) |
|
|
159
|
+
| `modifications` | Yes | Modifications for the selected template. |
|
|
160
|
+
| `responseType` | No | `base64`, `binary`, `url` (Defaults to `url`). |
|
|
161
|
+
| `responseFormat` | No | `png`, `webp`, `pdf`, `jpg`, `jpeg` (Defaults to `png`). |
|
|
184
162
|
|
|
185
163
|
For available templates and their modifications refer [Orshot Templates Page](https://orshot.com/templates)
|
|
186
164
|
|
|
187
165
|
## generateSignedUrl
|
|
188
166
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
```
|
|
192
|
-
{
|
|
193
|
-
templateId,
|
|
194
|
-
modifications,
|
|
195
|
-
renderType,
|
|
196
|
-
responseFormat,
|
|
197
|
-
expiresAt
|
|
198
|
-
}
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
| key | required | description |
|
|
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`). |
|
|
167
|
+
Generate a signed URL for a template.
|
|
208
168
|
|
|
169
|
+
```js
|
|
170
|
+
const response = await orshot.generateSignedUrl({
|
|
171
|
+
templateId: "open-graph-image-1",
|
|
172
|
+
modifications: { title: "Hello World" },
|
|
173
|
+
expiresAt: 1744276943,
|
|
174
|
+
renderType: "images",
|
|
175
|
+
responseFormat: "png",
|
|
176
|
+
});
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
| key | required | description |
|
|
180
|
+
| ---------------- | -------- | -------------------------------------------------------- |
|
|
181
|
+
| `templateId` | Yes | ID of the template. |
|
|
182
|
+
| `modifications` | Yes | Modifications for the selected template. |
|
|
183
|
+
| `expiresAt` | Yes | Expires at in unix timestamp (Number). |
|
|
184
|
+
| `renderType` | No | `images`, `pdfs` (Defaults to `images`). |
|
|
185
|
+
| `responseFormat` | No | `png`, `webp`, `pdf`, `jpg`, `jpeg` (Defaults to `png`). |
|
|
209
186
|
|
|
210
187
|
## Local development and testing
|
|
211
188
|
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const ORSHOT_SOURCE = "orshot-node-sdk";
|
|
2
2
|
export const ORSHOT_API_BASE_URL = "https://api.orshot.com";
|
|
3
3
|
export const ORSHOT_API_VERSION = "v1";
|
|
4
|
-
export const DEFAULT_RESPONSE_TYPE = "
|
|
4
|
+
export const DEFAULT_RESPONSE_TYPE = "url";
|
|
5
5
|
export const DEFAULT_RESPONSE_FORMAT = "png";
|
|
6
6
|
export const DEFAULT_RENDER_TYPE = "images";
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TemplateRenderOptions, SignedUrlOptions } from "./types";
|
|
1
|
+
import { TemplateRenderOptions, SignedUrlOptions, StudioRenderOptions } from "./types";
|
|
2
2
|
import { DEFAULT_RESPONSE_TYPE, DEFAULT_RESPONSE_FORMAT, DEFAULT_RENDER_TYPE, ORSHOT_API_BASE_URL, ORSHOT_API_VERSION, ORSHOT_SOURCE } from "./constants";
|
|
3
3
|
|
|
4
4
|
export class Orshot {
|
|
@@ -101,6 +101,69 @@ export class Orshot {
|
|
|
101
101
|
const jsonData = await response.json();
|
|
102
102
|
return jsonData;
|
|
103
103
|
}
|
|
104
|
+
|
|
105
|
+
public async renderFromStudioTemplate(options: StudioRenderOptions) {
|
|
106
|
+
const { templateId, modifications, response: responseOptions, pdfOptions, videoOptions, publish } = options;
|
|
107
|
+
|
|
108
|
+
const endpoint = `${this.getBaseUrl()}/studio/render`;
|
|
109
|
+
|
|
110
|
+
const body: Record<string, any> = {
|
|
111
|
+
templateId,
|
|
112
|
+
source: ORSHOT_SOURCE,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
if (modifications) {
|
|
116
|
+
body.modifications = modifications;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
body.response = {
|
|
120
|
+
type: responseOptions?.type ?? DEFAULT_RESPONSE_TYPE,
|
|
121
|
+
format: responseOptions?.format ?? DEFAULT_RESPONSE_FORMAT,
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
if (responseOptions?.scale !== undefined) {
|
|
125
|
+
body.response.scale = responseOptions.scale;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (responseOptions?.includePages) {
|
|
129
|
+
body.response.includePages = responseOptions.includePages;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (responseOptions?.fileName) {
|
|
133
|
+
body.response.fileName = responseOptions.fileName;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (pdfOptions) {
|
|
137
|
+
body.pdfOptions = pdfOptions;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (videoOptions) {
|
|
141
|
+
body.videoOptions = videoOptions;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (publish) {
|
|
145
|
+
body.publish = publish;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const response = await fetch(endpoint, {
|
|
149
|
+
method: "POST",
|
|
150
|
+
headers: this.getHeaders(),
|
|
151
|
+
body: JSON.stringify(body),
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
if (!response.ok) {
|
|
155
|
+
throw new Error("Failed to render studio template: " + response.status);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const responseType = responseOptions?.type ?? DEFAULT_RESPONSE_TYPE;
|
|
159
|
+
|
|
160
|
+
if (responseType === "base64" || responseType === "url") {
|
|
161
|
+
const jsonData = await response.json();
|
|
162
|
+
return jsonData;
|
|
163
|
+
} else {
|
|
164
|
+
return response;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
104
167
|
}
|
|
105
168
|
|
|
106
169
|
export default Orshot;
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type ResponseType = "base64" | "binary" | "url";
|
|
2
|
-
export type ResponseFormat = "png" | "webp" | "pdf" | "jpg" | "jpeg" ;
|
|
2
|
+
export type ResponseFormat = "png" | "webp" | "pdf" | "jpg" | "jpeg" | "mp4" | "webm" | "gif";
|
|
3
3
|
export type RenderType = "images" | "pdfs";
|
|
4
4
|
|
|
5
5
|
export type TemplateRenderOptions = {
|
|
@@ -16,3 +16,48 @@ export type SignedUrlOptions = {
|
|
|
16
16
|
responseFormat?: ResponseFormat;
|
|
17
17
|
expiresAt: number;
|
|
18
18
|
};
|
|
19
|
+
|
|
20
|
+
export type StudioResponseOptions = {
|
|
21
|
+
type?: ResponseType;
|
|
22
|
+
format?: ResponseFormat;
|
|
23
|
+
scale?: number;
|
|
24
|
+
includePages?: number[];
|
|
25
|
+
fileName?: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type PdfOptions = {
|
|
29
|
+
margin?: string;
|
|
30
|
+
rangeFrom?: number | null;
|
|
31
|
+
rangeTo?: number | null;
|
|
32
|
+
colorMode?: "rgb" | "cmyk";
|
|
33
|
+
dpi?: number;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type VideoOptions = {
|
|
37
|
+
trimStart?: number;
|
|
38
|
+
trimEnd?: number;
|
|
39
|
+
muted?: boolean;
|
|
40
|
+
loop?: boolean;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type PublishSchedule = {
|
|
44
|
+
scheduledFor?: string;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type PublishOptions = {
|
|
48
|
+
accounts: number[];
|
|
49
|
+
content?: string;
|
|
50
|
+
isDraft?: boolean;
|
|
51
|
+
schedule?: PublishSchedule;
|
|
52
|
+
timezone?: string;
|
|
53
|
+
platformOptions?: Record<string, any>;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export type StudioRenderOptions = {
|
|
57
|
+
templateId: number;
|
|
58
|
+
modifications?: Record<string, any>;
|
|
59
|
+
response?: StudioResponseOptions;
|
|
60
|
+
pdfOptions?: PdfOptions;
|
|
61
|
+
videoOptions?: VideoOptions;
|
|
62
|
+
publish?: PublishOptions;
|
|
63
|
+
};
|
package/dist/constants.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const ORSHOT_SOURCE = "orshot-node-sdk";
|
|
2
|
-
export declare const ORSHOT_API_BASE_URL = "https://api.orshot.com";
|
|
3
|
-
export declare const ORSHOT_API_VERSION = "v1";
|
|
4
|
-
export declare const DEFAULT_RESPONSE_TYPE = "base64";
|
|
5
|
-
export declare const DEFAULT_RESPONSE_FORMAT = "png";
|
|
6
|
-
export declare const DEFAULT_RENDER_TYPE = "images";
|
package/dist/constants.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_RENDER_TYPE = exports.DEFAULT_RESPONSE_FORMAT = exports.DEFAULT_RESPONSE_TYPE = exports.ORSHOT_API_VERSION = exports.ORSHOT_API_BASE_URL = exports.ORSHOT_SOURCE = void 0;
|
|
4
|
-
exports.ORSHOT_SOURCE = "orshot-node-sdk";
|
|
5
|
-
exports.ORSHOT_API_BASE_URL = "https://api.orshot.com";
|
|
6
|
-
exports.ORSHOT_API_VERSION = "v1";
|
|
7
|
-
exports.DEFAULT_RESPONSE_TYPE = "base64";
|
|
8
|
-
exports.DEFAULT_RESPONSE_FORMAT = "png";
|
|
9
|
-
exports.DEFAULT_RENDER_TYPE = "images";
|
|
10
|
-
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,QAAQ,CAAC;AACjC,QAAA,uBAAuB,GAAG,KAAK,CAAC;AAChC,QAAA,mBAAmB,GAAG,QAAQ,CAAC"}
|
package/dist/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { TemplateRenderOptions, SignedUrlOptions } from "./types";
|
|
2
|
-
export declare class Orshot {
|
|
3
|
-
private readonly apiKey;
|
|
4
|
-
constructor(apiKey: string);
|
|
5
|
-
getBaseUrl(version?: string): string;
|
|
6
|
-
getHeaders(): {
|
|
7
|
-
'Content-Type': string;
|
|
8
|
-
Authorization: string;
|
|
9
|
-
};
|
|
10
|
-
renderFromTemplate(renderOptions: TemplateRenderOptions): Promise<any>;
|
|
11
|
-
generateSignedUrl(signedUrlOptions: SignedUrlOptions): Promise<any>;
|
|
12
|
-
}
|
|
13
|
-
export default Orshot;
|
package/dist/index.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Orshot = void 0;
|
|
4
|
-
const constants_1 = require("./constants");
|
|
5
|
-
class Orshot {
|
|
6
|
-
apiKey;
|
|
7
|
-
constructor(apiKey) {
|
|
8
|
-
if (!apiKey) {
|
|
9
|
-
throw new Error("API Key is required.");
|
|
10
|
-
}
|
|
11
|
-
this.apiKey = apiKey;
|
|
12
|
-
}
|
|
13
|
-
getBaseUrl(version) {
|
|
14
|
-
const baseUrl = constants_1.ORSHOT_API_BASE_URL;
|
|
15
|
-
let apiVersion = constants_1.ORSHOT_API_VERSION;
|
|
16
|
-
if (version) {
|
|
17
|
-
apiVersion = version;
|
|
18
|
-
}
|
|
19
|
-
return `${baseUrl}/${apiVersion}`;
|
|
20
|
-
}
|
|
21
|
-
getHeaders() {
|
|
22
|
-
return {
|
|
23
|
-
'Content-Type': 'application/json',
|
|
24
|
-
'Authorization': `Bearer ${this.apiKey}`
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
async renderFromTemplate(renderOptions) {
|
|
28
|
-
let { templateId, modifications, responseType, responseFormat } = renderOptions;
|
|
29
|
-
if (!responseType) {
|
|
30
|
-
responseType = constants_1.DEFAULT_RESPONSE_TYPE;
|
|
31
|
-
}
|
|
32
|
-
if (!responseFormat) {
|
|
33
|
-
responseFormat = constants_1.DEFAULT_RESPONSE_FORMAT;
|
|
34
|
-
}
|
|
35
|
-
let endpoint = `${this.getBaseUrl()}/generate/images/${templateId}`;
|
|
36
|
-
const response = await fetch(endpoint, {
|
|
37
|
-
method: "POST",
|
|
38
|
-
headers: this.getHeaders(),
|
|
39
|
-
body: JSON.stringify({
|
|
40
|
-
response: {
|
|
41
|
-
type: responseType,
|
|
42
|
-
format: responseFormat
|
|
43
|
-
},
|
|
44
|
-
modifications: modifications,
|
|
45
|
-
source: constants_1.ORSHOT_SOURCE
|
|
46
|
-
}),
|
|
47
|
-
});
|
|
48
|
-
if (!response.ok) {
|
|
49
|
-
throw new Error("Failed to fetch image: " + response.status);
|
|
50
|
-
}
|
|
51
|
-
if (responseType === "base64" || responseType === "url") {
|
|
52
|
-
const jsonData = await response.json();
|
|
53
|
-
return jsonData;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
return response;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async generateSignedUrl(signedUrlOptions) {
|
|
60
|
-
let { templateId, modifications, renderType, responseFormat, expiresAt } = signedUrlOptions;
|
|
61
|
-
if (!renderType) {
|
|
62
|
-
renderType = constants_1.DEFAULT_RENDER_TYPE;
|
|
63
|
-
}
|
|
64
|
-
if (!responseFormat) {
|
|
65
|
-
responseFormat = constants_1.DEFAULT_RESPONSE_FORMAT;
|
|
66
|
-
}
|
|
67
|
-
let endpoint = `${this.getBaseUrl()}/signed-url/create`;
|
|
68
|
-
const response = await fetch(endpoint, {
|
|
69
|
-
method: "POST",
|
|
70
|
-
headers: this.getHeaders(),
|
|
71
|
-
body: JSON.stringify({
|
|
72
|
-
templateId: templateId,
|
|
73
|
-
renderType: renderType,
|
|
74
|
-
responseFormat: responseFormat,
|
|
75
|
-
modifications: modifications,
|
|
76
|
-
source: constants_1.ORSHOT_SOURCE,
|
|
77
|
-
expiresAt: expiresAt
|
|
78
|
-
}),
|
|
79
|
-
});
|
|
80
|
-
if (!response.ok) {
|
|
81
|
-
throw new Error("Failed to fetch image: " + response.status);
|
|
82
|
-
}
|
|
83
|
-
const jsonData = await response.json();
|
|
84
|
-
return jsonData;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.Orshot = Orshot;
|
|
88
|
-
exports.default = Orshot;
|
|
89
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,2CAA0J;AAE1J,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,M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 -1,16 +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
|
-
export type TemplateRenderOptions = {
|
|
5
|
-
templateId: string;
|
|
6
|
-
modifications: any;
|
|
7
|
-
responseType?: ResponseType;
|
|
8
|
-
responseFormat?: ResponseFormat;
|
|
9
|
-
};
|
|
10
|
-
export type SignedUrlOptions = {
|
|
11
|
-
templateId: string;
|
|
12
|
-
modifications: any;
|
|
13
|
-
renderType?: RenderType;
|
|
14
|
-
responseFormat?: ResponseFormat;
|
|
15
|
-
expiresAt: number;
|
|
16
|
-
};
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|