screenshotone-api-sdk 1.0.5 → 1.0.6

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