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