screenshotone-api-sdk 1.0.9 → 1.0.12

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.
Files changed (3) hide show
  1. package/dist/main.js +158 -106
  2. package/package.json +5 -6
  3. package/tsconfig.json +20 -16
package/dist/main.js CHANGED
@@ -1,263 +1,315 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
7
36
  }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
37
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
+ if (ar || !(i in from)) {
41
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
+ ar[i] = from[i];
43
+ }
44
+ }
45
+ return to.concat(ar || Array.prototype.slice.call(from));
27
46
  };
28
47
  Object.defineProperty(exports, "__esModule", { value: true });
29
48
  exports.TakeOptions = exports.Client = void 0;
30
- const crypto = __importStar(require("crypto"));
31
- const big_js_1 = __importDefault(require("big.js"));
32
- const node_fetch_1 = __importDefault(require("node-fetch"));
49
+ var crypto = require("crypto");
50
+ var big_js_1 = require("big.js");
51
+ var node_fetch_1 = require("node-fetch");
33
52
  /**
34
53
  * Represents an API client for the screenshotone.com API.
35
54
  */
36
- class Client {
37
- constructor(accessKey, secretKey) {
55
+ var Client = /** @class */ (function () {
56
+ function Client(accessKey, secretKey) {
38
57
  this.API_BASE_URL = "https://api.screenshotone.com";
39
58
  this.API_TAKE_PATH = "/take";
40
59
  this.accessKey = accessKey;
41
60
  this.secretKey = secretKey;
42
61
  }
43
- generateTakeURL(options) {
44
- const query = options.toQuery();
62
+ Client.prototype.generateTakeURL = function (options) {
63
+ var query = options.toQuery();
45
64
  query.append("access_key", this.accessKey);
46
- let queryString = query.toString();
47
- const signature = crypto.createHmac("sha256", this.secretKey)
65
+ var queryString = query.toString();
66
+ var signature = crypto.createHmac("sha256", this.secretKey)
48
67
  .update(queryString, 'utf-8')
49
68
  .digest('hex');
50
69
  queryString += '&signature=' + signature;
51
- return `${this.API_BASE_URL}${this.API_TAKE_PATH}?${queryString}`;
52
- }
53
- async take(options) {
54
- const url = this.generateTakeURL(options);
55
- const response = await (0, node_fetch_1.default)(url);
56
- if (response.ok) {
57
- return await response.blob();
58
- }
59
- throw new Error(`failed to take screenshot, response returned ${response.status} ${response.statusText}`);
60
- }
61
- }
70
+ return "".concat(this.API_BASE_URL).concat(this.API_TAKE_PATH, "?").concat(queryString);
71
+ };
72
+ Client.prototype.take = function (options) {
73
+ return __awaiter(this, void 0, void 0, function () {
74
+ var url, response;
75
+ return __generator(this, function (_a) {
76
+ switch (_a.label) {
77
+ case 0:
78
+ url = this.generateTakeURL(options);
79
+ return [4 /*yield*/, (0, node_fetch_1.default)(url)];
80
+ case 1:
81
+ response = _a.sent();
82
+ if (!response.ok) return [3 /*break*/, 3];
83
+ return [4 /*yield*/, response.blob()];
84
+ case 2: return [2 /*return*/, _a.sent()];
85
+ case 3: throw new Error("failed to take screenshot, response returned ".concat(response.status, " ").concat(response.statusText));
86
+ }
87
+ });
88
+ });
89
+ };
90
+ return Client;
91
+ }());
62
92
  exports.Client = Client;
63
93
  /**
64
94
  * Represents options for taking screenshots.
65
95
  */
66
- class TakeOptions {
67
- constructor(url) {
68
- const query = new URLSearchParams();
96
+ var TakeOptions = /** @class */ (function () {
97
+ function TakeOptions(url) {
98
+ var query = new URLSearchParams();
69
99
  query.append("url", url);
70
100
  this.query = query;
71
101
  }
72
102
  /**
73
103
  * Initializes take screenshot options with provided website URL.
74
104
  */
75
- static url(url) {
105
+ TakeOptions.url = function (url) {
76
106
  return new TakeOptions(url);
77
- }
78
- put(key, ...values) {
79
- for (const value of values) {
107
+ };
108
+ TakeOptions.prototype.put = function (key) {
109
+ var values = [];
110
+ for (var _i = 1; _i < arguments.length; _i++) {
111
+ values[_i - 1] = arguments[_i];
112
+ }
113
+ for (var _a = 0, values_1 = values; _a < values_1.length; _a++) {
114
+ var value = values_1[_a];
80
115
  this.query.append(key, value);
81
116
  }
82
- }
117
+ };
83
118
  ;
84
119
  /**
85
120
  * Renders the full page.
86
121
  */
87
- fullPage(fullPage) {
122
+ TakeOptions.prototype.fullPage = function (fullPage) {
88
123
  this.put("full_page", fullPage ? "true" : "false");
89
124
  return this;
90
- }
125
+ };
91
126
  /**
92
127
  * Sets response format, one of: "png", "jpeg", "webp" or "jpg".
93
128
  */
94
- format(format) {
129
+ TakeOptions.prototype.format = function (format) {
95
130
  this.put("format", format);
96
131
  return this;
97
- }
132
+ };
98
133
  /**
99
134
  * Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
100
135
  */
101
- imageQuality(imageQuality) {
136
+ TakeOptions.prototype.imageQuality = function (imageQuality) {
102
137
  this.put("image_quality", imageQuality.toString());
103
138
  return this;
104
- }
139
+ };
105
140
  /**
106
141
  * Renders a transparent background for the image. Works only if the site has not defined background color.
107
142
  * Available for the following response formats: "png", "webp".
108
143
  */
109
- omitBackground(omitBackground) {
144
+ TakeOptions.prototype.omitBackground = function (omitBackground) {
110
145
  this.put("omit_background", omitBackground ? "true" : "false");
111
146
  return this;
112
- }
147
+ };
113
148
  /**
114
149
  * Sets the width of the browser viewport (pixels).
115
150
  */
116
- viewportWidth(viewportWidth) {
151
+ TakeOptions.prototype.viewportWidth = function (viewportWidth) {
117
152
  this.put("viewport_width", viewportWidth.toString());
118
153
  return this;
119
- }
154
+ };
120
155
  /**
121
156
  * Sets the height of the browser viewport (pixels).
122
157
  */
123
- viewportHeight(viewportHeight) {
158
+ TakeOptions.prototype.viewportHeight = function (viewportHeight) {
124
159
  this.put("viewport_height", viewportHeight.toString());
125
160
  return this;
126
- }
161
+ };
127
162
  /**
128
163
  * Sets the device scale factor. Acceptable value is one of: 1, 2 or 3.
129
164
  */
130
- deviceScaleFactor(deviceScaleFactor) {
165
+ TakeOptions.prototype.deviceScaleFactor = function (deviceScaleFactor) {
131
166
  this.put("device_scale_factor", deviceScaleFactor.toString());
132
167
  return this;
133
- }
168
+ };
134
169
  /**
135
170
  * Sets geolocation latitude for the request.
136
171
  * Both latitude and longitude are required if one of them is set.
137
172
  */
138
- geolocationLatitude(latitude) {
173
+ TakeOptions.prototype.geolocationLatitude = function (latitude) {
139
174
  this.put("geolocation_latitude", new big_js_1.default(latitude).toFixed(20).replace(/0+$/, ""));
140
175
  return this;
141
- }
176
+ };
142
177
  /**
143
178
  * Sets geolocation longitude for the request. Both latitude and longitude are required if one of them is set.
144
179
  */
145
- geolocationLongitude(longitude) {
180
+ TakeOptions.prototype.geolocationLongitude = function (longitude) {
146
181
  this.put("geolocation_longitude", new big_js_1.default(longitude).toFixed(20).replace(/0+$/, ""));
147
182
  return this;
148
- }
183
+ };
149
184
  /**
150
185
  * Sets the geolocation accuracy in meters.
151
186
  */
152
- geolocationAccuracy(accuracy) {
187
+ TakeOptions.prototype.geolocationAccuracy = function (accuracy) {
153
188
  this.put("geolocation_accuracy", accuracy.toString());
154
189
  return this;
155
- }
190
+ };
156
191
  /**
157
192
  * Blocks ads.
158
193
  */
159
- blockAds(blockAds) {
194
+ TakeOptions.prototype.blockAds = function (blockAds) {
160
195
  this.put("block_ads", blockAds ? "true" : "false");
161
196
  return this;
162
- }
197
+ };
163
198
  /**
164
199
  * Blocks trackers.
165
200
  */
166
- blockTrackers(blockTrackers) {
201
+ TakeOptions.prototype.blockTrackers = function (blockTrackers) {
167
202
  this.put("block_trackers", blockTrackers ? "true" : "false");
168
203
  return this;
169
- }
204
+ };
170
205
  /**
171
206
  * Blocks requests by specifying URL, domain, or even a simple pattern.
172
207
  */
173
- blockRequests(...blockRequests) {
174
- this.put("block_requests", ...blockRequests);
208
+ TakeOptions.prototype.blockRequests = function () {
209
+ var blockRequests = [];
210
+ for (var _i = 0; _i < arguments.length; _i++) {
211
+ blockRequests[_i] = arguments[_i];
212
+ }
213
+ this.put.apply(this, __spreadArray(["block_requests"], blockRequests, false));
175
214
  return this;
176
- }
215
+ };
177
216
  /**
178
217
  * Blocks loading resources by type. Available resource types are: "document", "stylesheet", "image", "media",
179
218
  * "font", "script", "texttrack", "xhr", "fetch", "eventsource", "websocket", "manifest", "other".
180
219
  */
181
- blockResources(...blockResources) {
182
- this.put("block_resources", ...blockResources);
220
+ TakeOptions.prototype.blockResources = function () {
221
+ var blockResources = [];
222
+ for (var _i = 0; _i < arguments.length; _i++) {
223
+ blockResources[_i] = arguments[_i];
224
+ }
225
+ this.put.apply(this, __spreadArray(["block_resources"], blockResources, false));
183
226
  return this;
184
- }
227
+ };
185
228
  /**
186
229
  * Enables caching.
187
230
  */
188
- cache(cache) {
231
+ TakeOptions.prototype.cache = function (cache) {
189
232
  this.put("cache", cache ? "true" : "false");
190
233
  return this;
191
- }
234
+ };
192
235
  /**
193
236
  * Sets cache TTL.
194
237
  */
195
- cacheTtl(cacheTTL) {
238
+ TakeOptions.prototype.cacheTtl = function (cacheTTL) {
196
239
  this.put("cache_ttl", cacheTTL.toString());
197
240
  return this;
198
- }
241
+ };
199
242
  /**
200
243
  * Sets cache key.
201
244
  */
202
- cacheKey(cacheKey) {
245
+ TakeOptions.prototype.cacheKey = function (cacheKey) {
203
246
  this.put("cache_key", cacheKey);
204
247
  return this;
205
- }
248
+ };
206
249
  /**
207
250
  * Sets a user agent for the request.
208
251
  */
209
- userAgent(userAgent) {
252
+ TakeOptions.prototype.userAgent = function (userAgent) {
210
253
  this.put("user_agent", userAgent);
211
254
  return this;
212
- }
255
+ };
213
256
  /**
214
257
  * Sets an authorization header for the request.
215
258
  */
216
- authorization(authorization) {
259
+ TakeOptions.prototype.authorization = function (authorization) {
217
260
  this.put("authorization", authorization);
218
261
  return this;
219
- }
262
+ };
220
263
  /**
221
264
  * Set cookies for the request.
222
265
  */
223
- cookies(...cookies) {
224
- this.put("cookies", ...cookies);
266
+ TakeOptions.prototype.cookies = function () {
267
+ var cookies = [];
268
+ for (var _i = 0; _i < arguments.length; _i++) {
269
+ cookies[_i] = arguments[_i];
270
+ }
271
+ this.put.apply(this, __spreadArray(["cookies"], cookies, false));
225
272
  return this;
226
- }
273
+ };
227
274
  /**
228
275
  * Sets extra headers for the request.
229
276
  */
230
- headers(...headers) {
231
- this.put("headers", ...headers);
277
+ TakeOptions.prototype.headers = function () {
278
+ var headers = [];
279
+ for (var _i = 0; _i < arguments.length; _i++) {
280
+ headers[_i] = arguments[_i];
281
+ }
282
+ this.put.apply(this, __spreadArray(["headers"], headers, false));
232
283
  return this;
233
- }
284
+ };
234
285
  /**
235
286
  * TimeZone sets time zone for the request.
236
287
  * Available time zones are: "America/Santiago", "Asia/Shanghai", "Europe/Berlin", "America/Guayaquil",
237
288
  * "Europe/Madrid", "Pacific/Majuro", "Asia/Kuala_Lumpur", "Pacific/Auckland", "Europe/Lisbon", "Europe/Kiev",
238
289
  * "Asia/Tashkent", "Europe/London".
239
290
  */
240
- timeZone(timeZone) {
291
+ TakeOptions.prototype.timeZone = function (timeZone) {
241
292
  this.put("time_zone", timeZone);
242
293
  return this;
243
- }
294
+ };
244
295
  /**
245
296
  * Sets delay.
246
297
  */
247
- delay(delay) {
298
+ TakeOptions.prototype.delay = function (delay) {
248
299
  this.put("delay", delay.toString());
249
300
  return this;
250
- }
301
+ };
251
302
  /**
252
303
  * Sets timeout.
253
304
  */
254
- timeout(timeout) {
305
+ TakeOptions.prototype.timeout = function (timeout) {
255
306
  this.put("timeout", timeout.toString());
256
307
  return this;
257
- }
258
- toQuery() {
308
+ };
309
+ TakeOptions.prototype.toQuery = function () {
259
310
  return new URLSearchParams(this.query.toString());
260
- }
261
- }
311
+ };
312
+ return TakeOptions;
313
+ }());
262
314
  exports.TakeOptions = TakeOptions;
263
315
  //# sourceMappingURL=main.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "screenshotone-api-sdk",
3
3
  "homepage": "https://screenshotone.com",
4
- "version": "1.0.9",
4
+ "version": "1.0.12",
5
5
  "description": "Use ScreenshotOne.com API to generate screenshots of any website.",
6
6
  "repository": {
7
7
  "type": "git",
@@ -28,8 +28,8 @@
28
28
  "url": "https://github.com/screenshotone/tssdk/issues"
29
29
  },
30
30
  "main": "dist/main.js",
31
- "types": "dist/@types/index",
32
- "typings": "dist/@types/index",
31
+ "types": "dist/@types/main.d.ts",
32
+ "typings": "dist/@types/main.d.ts",
33
33
  "devDependencies": {
34
34
  "typescript": "^4.7.3",
35
35
  "@types/node": "^17.0.40",
@@ -40,8 +40,7 @@
40
40
  "node-fetch": "^3.2.5"
41
41
  },
42
42
  "scripts": {
43
- "prepublish": "npm run build",
44
- "prepare" : "npm run build",
45
- "build": "tsc --build"
43
+ "build": "tsc",
44
+ "prepare": "npm run build"
46
45
  }
47
46
  }
package/tsconfig.json CHANGED
@@ -1,19 +1,23 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "lib": ["es2021"],
4
- "target": "es2020",
5
- "moduleResolution": "node",
6
- "module": "commonjs",
7
- "esModuleInterop": true,
8
- "outDir": "./dist",
9
- "strict": true,
10
- "noImplicitAny": true,
11
- "removeComments": false,
12
- "preserveConstEnums": true,
13
- "sourceMap": true,
14
- "declaration": true,
15
- "declarationDir": "dist/@types",
3
+ "declaration": true,
4
+ "strictNullChecks": true,
5
+ "target": "es5",
6
+ "outDir": "dist",
7
+ "module": "commonjs",
8
+ "moduleResolution": "node",
9
+ "sourceMap": true,
10
+ "lib": [
11
+ "es2015",
12
+ "dom"
13
+ ],
14
+ "rootDir": "src"
16
15
  },
17
- "include": ["src/**/*"],
18
- "exclude": ["node_modules"]
19
- }
16
+ "include": [
17
+ "src/**/*"
18
+ ],
19
+ "exclude": [
20
+ "node_modules",
21
+ "dist"
22
+ ]
23
+ }