screenshotone-api-sdk 1.0.7 → 1.0.10

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