orshot 0.1.0 → 0.1.1

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.
@@ -18,6 +18,7 @@ jobs:
18
18
  node-version: '20.x'
19
19
  registry-url: 'https://registry.npmjs.org'
20
20
  - run: npm ci
21
+ - run: npm run build
21
22
  - run: npm publish --provenance --access public
22
23
  env:
23
24
  NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/README.md CHANGED
@@ -172,3 +172,7 @@ Write simple code to generate an image from a template.
172
172
  From the `test` directory, run `npm link orshot`
173
173
 
174
174
  You can now run `node index.js` to test if the sdk code works as expected.
175
+
176
+ ## Publish package to NPM
177
+
178
+ Create a new release from GitHub. This will trigger a GitHub action which will publish the package to NPM.
@@ -0,0 +1,5 @@
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";
@@ -0,0 +1,9 @@
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
@@ -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,QAAQ,CAAC;AACjC,QAAA,uBAAuB,GAAG,KAAK,CAAC"}
@@ -0,0 +1,12 @@
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 ADDED
@@ -0,0 +1,62 @@
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
@@ -0,0 +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,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"}
@@ -0,0 +1,8 @@
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 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,8 +1,8 @@
1
1
  {
2
2
  "name": "orshot",
3
- "version": "0.1.0",
4
- "description": "Orshot API SDK for node.js",
5
- "homepage": "https://github.com/rishimohan/orshot-nodejs-sdk#readme",
3
+ "version": "0.1.1",
4
+ "description": "Orshot API SDK for Node.js",
5
+ "homepage": "https://orshot.com",
6
6
  "bugs": {
7
7
  "url": "https://github.com/rishimohan/orshot-nodejs-sdk/issues"
8
8
  },