screenshotone-api-sdk 1.0.5 → 1.0.8
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 +83 -161
- package/package.json +4 -2
- package/tsconfig.json +6 -5
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
82
|
-
|
|
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
|
-
|
|
89
|
-
|
|
43
|
+
generateTakeURL(options) {
|
|
44
|
+
const query = options.toQuery();
|
|
90
45
|
query.append("access_key", this.accessKey);
|
|
91
|
-
|
|
92
|
-
|
|
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
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
75
|
+
static url(url) {
|
|
132
76
|
return new TakeOptions(url);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
235
|
-
|
|
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
|
-
|
|
247
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
293
|
-
|
|
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
|
-
|
|
304
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
254
|
+
timeout(timeout) {
|
|
332
255
|
this.put("timeout", timeout.toString());
|
|
333
256
|
return this;
|
|
334
|
-
}
|
|
335
|
-
|
|
257
|
+
}
|
|
258
|
+
toQuery() {
|
|
336
259
|
return new URLSearchParams(this.query.toString());
|
|
337
|
-
}
|
|
338
|
-
|
|
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.
|
|
4
|
+
"version": "1.0.8",
|
|
5
5
|
"description": "Use ScreenshotOne.com API to generate screenshots of any website.",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
"url": "https://github.com/screenshotone/tssdk/issues"
|
|
29
29
|
},
|
|
30
30
|
"main": "dist/main.js",
|
|
31
|
-
"types": "dist/index
|
|
31
|
+
"types": "dist/@types/index",
|
|
32
|
+
"typings": "dist/@types/index",
|
|
33
|
+
"type": "module",
|
|
32
34
|
"devDependencies": {
|
|
33
35
|
"typescript": "^4.7.3",
|
|
34
36
|
"@types/node": "^17.0.40",
|
package/tsconfig.json
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"
|
|
4
|
-
"
|
|
3
|
+
"lib": ["es2021"],
|
|
4
|
+
"target": "es2020",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"module": "commonjs",
|
|
7
|
+
"esModuleInterop": true,
|
|
5
8
|
"outDir": "./dist",
|
|
6
9
|
"strict": true,
|
|
7
10
|
"noImplicitAny": true,
|
|
8
11
|
"removeComments": false,
|
|
9
12
|
"preserveConstEnums": true,
|
|
10
13
|
"sourceMap": true,
|
|
11
|
-
"moduleResolution": "node",
|
|
12
14
|
"declaration": true,
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
+
"declarationDir": "dist/@types",
|
|
15
16
|
},
|
|
16
17
|
"include": ["src/**/*"],
|
|
17
18
|
"exclude": ["node_modules"]
|