orshot 0.1.1 → 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 +127 -100
- package/package.json +1 -1
- package/src/constants.ts +3 -2
- package/src/index.ts +99 -2
- package/src/types.ts +55 -1
- package/dist/constants.d.ts +0 -5
- package/dist/constants.js +0 -9
- package/dist/constants.js.map +0 -1
- package/dist/index.d.ts +0 -12
- package/dist/index.js +0 -62
- package/dist/index.js.map +0 -1
- package/dist/types.d.ts +0 -8
- 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,126 +38,151 @@ import { Orshot } from "orshot";
|
|
|
36
38
|
const orshot = new Orshot("Your API key");
|
|
37
39
|
```
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
```js
|
|
42
|
-
const response = await Orshot.renderFromTemplate({templateId, modifications, responseType: "base64", responseFormat: "png"});
|
|
43
|
-
console.log(response);
|
|
44
|
-
```
|
|
41
|
+
## renderFromStudioTemplate
|
|
45
42
|
|
|
46
|
-
|
|
43
|
+
Render from a custom [Studio template](https://orshot.com/features/orshot-studio). Supports image, PDF, video generation and publishing to social accounts.
|
|
47
44
|
|
|
48
|
-
###
|
|
45
|
+
### Generate Image
|
|
49
46
|
|
|
50
47
|
```js
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
textColor: "",
|
|
60
|
-
backgroundImageUrl: "",
|
|
61
|
-
backgroundColor: ""
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const response = await orshot.renderFromTemplate({templateId, modifications, responseType: "base64", responseFormat: "png"});
|
|
65
|
-
console.log(response);
|
|
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
|
+
});
|
|
66
56
|
```
|
|
67
57
|
|
|
68
|
-
|
|
69
|
-
```
|
|
70
|
-
{
|
|
71
|
-
data: {
|
|
72
|
-
content: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABLAAAAJ2CAYAAABPQHtcAAAAAXNSR0IArs4c6QAAIABJREFUeJzs3XmYJXdZL/Bvna37dM90FghLCBAQkC1BCBAMShLFBJAgKnofroBeFUUF5LrhiihXcV8BQRYVUUAlIewIGPbFmLCFLWwCYZEtzPR+trp/TM/......',
|
|
73
|
-
format: 'png',
|
|
74
|
-
type: 'base64',
|
|
75
|
-
responseTime: 3375.72
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### `URL` response format
|
|
58
|
+
### Generate PDF
|
|
81
59
|
|
|
82
60
|
```js
|
|
83
|
-
|
|
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
|
|
84
76
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const response = await orshot.renderFromTemplate({templateId, modifications, responseType: "url", responseFormat: "png"});
|
|
97
|
-
console.log(response);
|
|
77
|
+
```js
|
|
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
|
+
});
|
|
98
88
|
```
|
|
99
89
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
90
|
+
### Publish to Social Accounts
|
|
91
|
+
|
|
92
|
+
```js
|
|
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" }, ...]
|
|
110
103
|
```
|
|
111
104
|
|
|
112
|
-
###
|
|
105
|
+
### Schedule a Post
|
|
113
106
|
|
|
114
107
|
```js
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
---
|
|
117
142
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
let templateId = "open-graph-image-1";
|
|
121
|
-
let modifications = {
|
|
122
|
-
title: "Orshot",
|
|
123
|
-
description: "Create Visuals and Automate Image Generation",
|
|
124
|
-
textColor: "",
|
|
125
|
-
backgroundImageUrl: "",
|
|
126
|
-
backgroundColor: ""
|
|
127
|
-
}
|
|
143
|
+
## renderFromTemplate
|
|
128
144
|
|
|
129
|
-
|
|
130
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
131
|
-
const buffer = Buffer.from(arrayBuffer);
|
|
145
|
+
Render from a pre-built Orshot template.
|
|
132
146
|
|
|
133
|
-
|
|
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
|
+
});
|
|
134
154
|
```
|
|
135
155
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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`). |
|
|
139
162
|
|
|
140
|
-
|
|
163
|
+
For available templates and their modifications refer [Orshot Templates Page](https://orshot.com/templates)
|
|
141
164
|
|
|
142
|
-
|
|
143
|
-
{
|
|
144
|
-
templateId,
|
|
145
|
-
modifications,
|
|
146
|
-
responseType,
|
|
147
|
-
responseFormat
|
|
148
|
-
}
|
|
149
|
-
```
|
|
165
|
+
## generateSignedUrl
|
|
150
166
|
|
|
151
|
-
|
|
152
|
-
|----------|----------|-------------|
|
|
153
|
-
| `templateId` | Yes | ID of the template (`open-graph-image-1`, `tweet-image-1`, `beautify-screenshot-1`, ...) |
|
|
154
|
-
| `modifications` | Yes | Modifications for the selected template. |
|
|
155
|
-
| `responseType` | No | `base64`, `binary`, `url` (Defaults to `base64`). |
|
|
156
|
-
| `responseFormat` | No | `png`, `webp`, `pdf`, `jpg`, `jpeg` (Defaults to `png`). |
|
|
167
|
+
Generate a signed URL for a template.
|
|
157
168
|
|
|
158
|
-
|
|
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`). |
|
|
159
186
|
|
|
160
187
|
## Local development and testing
|
|
161
188
|
|
|
@@ -163,7 +190,7 @@ Run these from the project
|
|
|
163
190
|
|
|
164
191
|
`npm run build`
|
|
165
192
|
|
|
166
|
-
`npm
|
|
193
|
+
`npm link`
|
|
167
194
|
|
|
168
195
|
Create a test directory and add `index.js` file
|
|
169
196
|
|
package/package.json
CHANGED
package/src/constants.ts
CHANGED
|
@@ -1,5 +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 = "
|
|
5
|
-
export const DEFAULT_RESPONSE_FORMAT = "png";
|
|
4
|
+
export const DEFAULT_RESPONSE_TYPE = "url";
|
|
5
|
+
export const DEFAULT_RESPONSE_FORMAT = "png";
|
|
6
|
+
export const DEFAULT_RENDER_TYPE = "images";
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TemplateRenderOptions } from "./types";
|
|
2
|
-
import { DEFAULT_RESPONSE_TYPE, DEFAULT_RESPONSE_FORMAT, ORSHOT_API_BASE_URL, ORSHOT_API_VERSION, ORSHOT_SOURCE } from "./constants";
|
|
1
|
+
import { TemplateRenderOptions, SignedUrlOptions, StudioRenderOptions } 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
3
|
|
|
4
4
|
export class Orshot {
|
|
5
5
|
private readonly apiKey: string;
|
|
@@ -67,6 +67,103 @@ export class Orshot {
|
|
|
67
67
|
return response;
|
|
68
68
|
}
|
|
69
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
|
+
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
|
+
}
|
|
70
167
|
}
|
|
71
168
|
|
|
72
169
|
export default Orshot;
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
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
|
+
export type RenderType = "images" | "pdfs";
|
|
3
4
|
|
|
4
5
|
export type TemplateRenderOptions = {
|
|
5
6
|
templateId: string;
|
|
@@ -7,3 +8,56 @@ export type TemplateRenderOptions = {
|
|
|
7
8
|
responseType?: ResponseType;
|
|
8
9
|
responseFormat?: ResponseFormat;
|
|
9
10
|
};
|
|
11
|
+
|
|
12
|
+
export type SignedUrlOptions = {
|
|
13
|
+
templateId: string;
|
|
14
|
+
modifications: any;
|
|
15
|
+
renderType?: RenderType;
|
|
16
|
+
responseFormat?: ResponseFormat;
|
|
17
|
+
expiresAt: number;
|
|
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,5 +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";
|
package/dist/constants.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
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
|
-
//# 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"}
|
package/dist/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { TemplateRenderOptions } 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
|
-
}
|
|
12
|
-
export default Orshot;
|
package/dist/index.js
DELETED
|
@@ -1,62 +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
|
-
}
|
|
60
|
-
exports.Orshot = Orshot;
|
|
61
|
-
exports.default = Orshot;
|
|
62
|
-
//# 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,2CAAqI;AAErI,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,CAAC;QAEpC,IAAI,OAAO,EAAE,CAAC;YACZ,UAAU,GAAG,OAAO,CAAC;QACvB,CAAC;QAED,OAAO,GAAG,OAAO,IAAI,UAAU,EAAE,CAAC;IACpC,CAAC;IAEM,UAAU;QACf,OAAO;YACL,cAAc,EAAE,kBAAkB;YAClC,eAAe,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE;SACzC,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,kBAAkB,CAAC,aAAoC;QAClE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,cAAc,EAAE,GAAG,aAAa,CAAC;QAEhF,IAAI,CAAC,YAAY,EAAE,CAAC;YAClB,YAAY,GAAG,iCAAqB,CAAC;QACvC,CAAC;QAED,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,cAAc,GAAG,mCAAuB,CAAC;QAC3C,CAAC;QAED,IAAI,QAAQ,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,oBAAoB,UAAU,EAAE,CAAC;QAEpE,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE;YACrC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;YAC1B,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,QAAQ,EAAE;oBACR,IAAI,EAAE,YAAY;oBAClB,MAAM,EAAE,cAAc;iBACvB;gBACD,aAAa,EAAE,aAAa;gBAC5B,MAAM,EAAE,yBAAa;aACtB,CAAC;SACH,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,yBAAyB,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,YAAY,KAAK,QAAQ,IAAI,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;AAlED,wBAkEC;AAED,kBAAe,MAAM,CAAC"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export type ResponseType = "base64" | "binary" | "url";
|
|
2
|
-
export type ResponseFormat = "png" | "webp" | "pdf" | "jpg" | "jpeg";
|
|
3
|
-
export type TemplateRenderOptions = {
|
|
4
|
-
templateId: string;
|
|
5
|
-
modifications: any;
|
|
6
|
-
responseType?: ResponseType;
|
|
7
|
-
responseFormat?: ResponseFormat;
|
|
8
|
-
};
|
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":""}
|