orshot 0.1.1 → 0.1.2

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
@@ -43,6 +43,13 @@ const response = await Orshot.renderFromTemplate({templateId, modifications, res
43
43
  console.log(response);
44
44
  ```
45
45
 
46
+ ### Generate signed URL
47
+
48
+ ```js
49
+ const response = await Orshot.renderFromTemplate({templateId, modifications, expiresAt: 1744276943, renderType: "images", responseFormat: "png"});
50
+ console.log(response);
51
+ ```
52
+
46
53
  ## Example
47
54
 
48
55
  ### `Base64` response format
@@ -135,6 +142,26 @@ createWriteStream("og.png").write(buffer);
135
142
 
136
143
  This example writes the binary image to the file `og.png` in the current directory.
137
144
 
145
+ ### Signed URL
146
+
147
+ ```js
148
+ import { Orshot } from "orshot";
149
+
150
+ const orshot = new Orshot("os-ha2jdus1cbz1dpt4mktgjyvx");
151
+
152
+ let templateId = "open-graph-image-1";
153
+ let modifications = {
154
+ title: "Orshot",
155
+ description: "Create Visuals and Automate Image Generation",
156
+ textColor: "",
157
+ backgroundImageUrl: "",
158
+ backgroundColor: ""
159
+ }
160
+
161
+ const response = await Orshot.renderFromTemplate({templateId, modifications, expiresAt: 1744276943, renderType: "images", responseFormat: "png"});
162
+ console.log(response);
163
+ ```
164
+
138
165
  ## renderFromTemplate
139
166
 
140
167
  Use this function to render an image/pdf. Render template takes in 4 options passed as an object
@@ -157,13 +184,36 @@ Use this function to render an image/pdf. Render template takes in 4 options pas
157
184
 
158
185
  For available templates and their modifications refer [Orshot Templates Page](https://orshot.com/templates)
159
186
 
187
+ ## generateSignedUrl
188
+
189
+ Use this function to generate signed URL.
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`). |
208
+
209
+
160
210
  ## Local development and testing
161
211
 
162
212
  Run these from the project
163
213
 
164
214
  `npm run build`
165
215
 
166
- `npm run link`
216
+ `npm link`
167
217
 
168
218
  Create a test directory and add `index.js` file
169
219
 
@@ -3,3 +3,4 @@ export declare const ORSHOT_API_BASE_URL = "https://api.orshot.com";
3
3
  export declare const ORSHOT_API_VERSION = "v1";
4
4
  export declare const DEFAULT_RESPONSE_TYPE = "base64";
5
5
  export declare const DEFAULT_RESPONSE_FORMAT = "png";
6
+ export declare const DEFAULT_RENDER_TYPE = "images";
package/dist/constants.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
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;
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
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
7
  exports.DEFAULT_RESPONSE_TYPE = "base64";
8
8
  exports.DEFAULT_RESPONSE_FORMAT = "png";
9
+ exports.DEFAULT_RENDER_TYPE = "images";
9
10
  //# sourceMappingURL=constants.js.map
@@ -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,QAAQ,CAAC;AACjC,QAAA,uBAAuB,GAAG,KAAK,CAAC"}
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 CHANGED
@@ -1,4 +1,4 @@
1
- import { TemplateRenderOptions } from "./types";
1
+ import { TemplateRenderOptions, SignedUrlOptions } from "./types";
2
2
  export declare class Orshot {
3
3
  private readonly apiKey;
4
4
  constructor(apiKey: string);
@@ -8,5 +8,6 @@ export declare class Orshot {
8
8
  Authorization: string;
9
9
  };
10
10
  renderFromTemplate(renderOptions: TemplateRenderOptions): Promise<any>;
11
+ generateSignedUrl(signedUrlOptions: SignedUrlOptions): Promise<any>;
11
12
  }
12
13
  export default Orshot;
package/dist/index.js CHANGED
@@ -56,6 +56,33 @@ class Orshot {
56
56
  return response;
57
57
  }
58
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
+ }
59
86
  }
60
87
  exports.Orshot = Orshot;
61
88
  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,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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AC;YACN,OAAO,QAAQ,CAAC;QAClB,CAAC;IACH,CAAC;IAEM,KAAK,CAAC,iBAAiB,CAAC,gBAAkC;QAC/D,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,SAAS,EAAE,GAAG,gBAAgB,CAAC;QAE5F,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,UAAU,GAAG,+BAAmB,CAAC;QACnC,CAAC;QAED,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,cAAc,GAAG,mCAAuB,CAAC;QAC3C,CAAC;QAED,IAAI,QAAQ,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,oBAAoB,CAAC;QAExD,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,UAAU,EAAE,UAAU;gBACtB,UAAU,EAAE,UAAU;gBACtB,cAAc,EAAE,cAAc;gBAC9B,aAAa,EAAE,aAAa;gBAC5B,MAAM,EAAE,yBAAa;gBACrB,SAAS,EAAE,SAAS;aACrB,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,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACvC,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AApGD,wBAoGC;AAED,kBAAe,MAAM,CAAC"}
package/dist/types.d.ts CHANGED
@@ -1,8 +1,16 @@
1
1
  export type ResponseType = "base64" | "binary" | "url";
2
2
  export type ResponseFormat = "png" | "webp" | "pdf" | "jpg" | "jpeg";
3
+ export type RenderType = "images" | "pdfs";
3
4
  export type TemplateRenderOptions = {
4
5
  templateId: string;
5
6
  modifications: any;
6
7
  responseType?: ResponseType;
7
8
  responseFormat?: ResponseFormat;
8
9
  };
10
+ export type SignedUrlOptions = {
11
+ templateId: string;
12
+ modifications: any;
13
+ renderType?: RenderType;
14
+ responseFormat?: ResponseFormat;
15
+ expiresAt: number;
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orshot",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Orshot API SDK for Node.js",
5
5
  "homepage": "https://orshot.com",
6
6
  "bugs": {
package/src/constants.ts CHANGED
@@ -2,4 +2,5 @@ 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
4
  export const DEFAULT_RESPONSE_TYPE = "base64";
5
- export const DEFAULT_RESPONSE_FORMAT = "png";
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 } 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,40 @@ 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
+ }
70
104
  }
71
105
 
72
106
  export default Orshot;
package/src/types.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type ResponseType = "base64" | "binary" | "url";
2
2
  export type ResponseFormat = "png" | "webp" | "pdf" | "jpg" | "jpeg" ;
3
+ export type RenderType = "images" | "pdfs";
3
4
 
4
5
  export type TemplateRenderOptions = {
5
6
  templateId: string;
@@ -7,3 +8,11 @@ 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
+ };