orshot 0.2.0 → 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 CHANGED
@@ -83,7 +83,28 @@ const response = await orshot.renderFromStudioTemplate({
83
83
  "videoElement.trimEnd": 10,
84
84
  },
85
85
  response: { type: "url", format: "mp4" },
86
- videoOptions: { trimStart: 0, trimEnd: 20, muted: false, loop: true },
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
+ });
95
+ ```
96
+
97
+ ### Multi-page Video with Transitions
98
+
99
+ ```js
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
+ },
87
108
  });
88
109
  ```
89
110
 
@@ -120,23 +141,39 @@ const response = await orshot.renderFromStudioTemplate({
120
141
 
121
142
  ### Parameters
122
143
 
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. |
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. |
140
177
 
141
178
  ---
142
179
 
@@ -176,13 +213,42 @@ const response = await orshot.generateSignedUrl({
176
213
  });
177
214
  ```
178
215
 
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`). |
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"
241
+ }
242
+ ```
243
+
244
+ ## TypeScript
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
+ ```
186
252
 
187
253
  ## Local development and testing
188
254
 
@@ -0,0 +1,6 @@
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 = "url";
5
+ export declare const DEFAULT_RESPONSE_FORMAT = "png";
6
+ export declare const DEFAULT_RENDER_TYPE = "images";
@@ -0,0 +1,10 @@
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 = "url";
8
+ exports.DEFAULT_RESPONSE_FORMAT = "png";
9
+ exports.DEFAULT_RENDER_TYPE = "images";
10
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +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,KAAK,CAAC;AAC9B,QAAA,uBAAuB,GAAG,KAAK,CAAC;AAChC,QAAA,mBAAmB,GAAG,QAAQ,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { TemplateRenderOptions, SignedUrlOptions, StudioRenderOptions } from "./types";
2
+ export type { ResponseType, ResponseFormat, RenderType, TemplateRenderOptions, SignedUrlOptions, StudioRenderOptions, StudioResponseOptions, PdfOptions, VideoOptions, PublishOptions, PublishSchedule, } from "./types";
3
+ export declare class Orshot {
4
+ private readonly apiKey;
5
+ constructor(apiKey: string);
6
+ getBaseUrl(version?: string): string;
7
+ getHeaders(): {
8
+ 'Content-Type': string;
9
+ Authorization: string;
10
+ };
11
+ renderFromTemplate(renderOptions: TemplateRenderOptions): Promise<any>;
12
+ generateSignedUrl(signedUrlOptions: SignedUrlOptions): Promise<any>;
13
+ renderFromStudioTemplate(options: StudioRenderOptions): Promise<any>;
14
+ }
15
+ export default Orshot;
package/dist/index.js ADDED
@@ -0,0 +1,168 @@
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
+ 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);
59
+ }
60
+ if (responseType === "base64" || responseType === "url") {
61
+ const jsonData = await response.json();
62
+ return jsonData;
63
+ }
64
+ else {
65
+ return response;
66
+ }
67
+ }
68
+ async generateSignedUrl(signedUrlOptions) {
69
+ let { templateId, modifications, renderType, responseFormat, expiresAt } = signedUrlOptions;
70
+ if (!renderType) {
71
+ renderType = constants_1.DEFAULT_RENDER_TYPE;
72
+ }
73
+ if (!responseFormat) {
74
+ responseFormat = constants_1.DEFAULT_RESPONSE_FORMAT;
75
+ }
76
+ let endpoint = `${this.getBaseUrl()}/signed-url/create`;
77
+ const response = await fetch(endpoint, {
78
+ method: "POST",
79
+ headers: this.getHeaders(),
80
+ body: JSON.stringify({
81
+ templateId: templateId,
82
+ renderType: renderType,
83
+ responseFormat: responseFormat,
84
+ modifications: modifications,
85
+ source: constants_1.ORSHOT_SOURCE,
86
+ expiresAt: expiresAt
87
+ }),
88
+ });
89
+ if (!response.ok) {
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);
100
+ }
101
+ const jsonData = await response.json();
102
+ return jsonData;
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
+ }
165
+ }
166
+ exports.Orshot = Orshot;
167
+ exports.default = Orshot;
168
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mapp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AK;oBAAE,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC;qBAC3C,IAAI,SAAS,EAAE,OAAO;oBAAE,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC;YAC3D,CAAC;YAAC,MAAM,CAAC,CAAA,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;QAED,MAAM,YAAY,GAAG,eAAe,EAAE,IAAI,IAAI,iCAAqB,CAAC;QAEpE,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;AAzLD,wBAyLC;AAED,kBAAe,MAAM,CAAC"}
@@ -0,0 +1,69 @@
1
+ export type ResponseType = "base64" | "binary" | "url";
2
+ export type ResponseFormat = "png" | "webp" | "pdf" | "jpg" | "jpeg" | "avif" | "mp4" | "webm" | "gif";
3
+ export type RenderType = "images" | "pdfs" | "videos";
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 | "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;
69
+ };
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orshot",
3
- "version": "0.2.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 = "url";
5
- export const DEFAULT_RESPONSE_FORMAT = "png";
6
- export const DEFAULT_RENDER_TYPE = "images";
package/src/index.ts DELETED
@@ -1,169 +0,0 @@
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
-
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
- 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
- }
167
- }
168
-
169
- export default Orshot;
package/src/types.ts DELETED
@@ -1,63 +0,0 @@
1
- export type ResponseType = "base64" | "binary" | "url";
2
- export type ResponseFormat = "png" | "webp" | "pdf" | "jpg" | "jpeg" | "mp4" | "webm" | "gif";
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
- };
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/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
- }