screenshotone-api-sdk 1.0.9 → 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.
- package/dist/main.js +162 -113
- package/package.json +4 -3
- package/tsconfig.json +1 -3
package/dist/main.js
CHANGED
|
@@ -1,263 +1,312 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
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 };
|
|
7
35
|
}
|
|
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
36
|
};
|
|
25
|
-
var
|
|
26
|
-
|
|
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));
|
|
27
45
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const big_js_1 = __importDefault(require("big.js"));
|
|
32
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
46
|
+
import * as crypto from 'crypto';
|
|
47
|
+
import Big from 'big.js';
|
|
48
|
+
import fetch from 'node-fetch';
|
|
33
49
|
/**
|
|
34
50
|
* Represents an API client for the screenshotone.com API.
|
|
35
51
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
52
|
+
var Client = /** @class */ (function () {
|
|
53
|
+
function Client(accessKey, secretKey) {
|
|
38
54
|
this.API_BASE_URL = "https://api.screenshotone.com";
|
|
39
55
|
this.API_TAKE_PATH = "/take";
|
|
40
56
|
this.accessKey = accessKey;
|
|
41
57
|
this.secretKey = secretKey;
|
|
42
58
|
}
|
|
43
|
-
generateTakeURL(options) {
|
|
44
|
-
|
|
59
|
+
Client.prototype.generateTakeURL = function (options) {
|
|
60
|
+
var query = options.toQuery();
|
|
45
61
|
query.append("access_key", this.accessKey);
|
|
46
|
-
|
|
47
|
-
|
|
62
|
+
var queryString = query.toString();
|
|
63
|
+
var signature = crypto.createHmac("sha256", this.secretKey)
|
|
48
64
|
.update(queryString, 'utf-8')
|
|
49
65
|
.digest('hex');
|
|
50
66
|
queryString += '&signature=' + signature;
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
+
});
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
return Client;
|
|
88
|
+
}());
|
|
89
|
+
export { Client };
|
|
63
90
|
/**
|
|
64
91
|
* Represents options for taking screenshots.
|
|
65
92
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
93
|
+
var TakeOptions = /** @class */ (function () {
|
|
94
|
+
function TakeOptions(url) {
|
|
95
|
+
var query = new URLSearchParams();
|
|
69
96
|
query.append("url", url);
|
|
70
97
|
this.query = query;
|
|
71
98
|
}
|
|
72
99
|
/**
|
|
73
100
|
* Initializes take screenshot options with provided website URL.
|
|
74
101
|
*/
|
|
75
|
-
|
|
102
|
+
TakeOptions.url = function (url) {
|
|
76
103
|
return new TakeOptions(url);
|
|
77
|
-
}
|
|
78
|
-
put(key
|
|
79
|
-
|
|
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];
|
|
80
112
|
this.query.append(key, value);
|
|
81
113
|
}
|
|
82
|
-
}
|
|
114
|
+
};
|
|
83
115
|
;
|
|
84
116
|
/**
|
|
85
117
|
* Renders the full page.
|
|
86
118
|
*/
|
|
87
|
-
fullPage(fullPage) {
|
|
119
|
+
TakeOptions.prototype.fullPage = function (fullPage) {
|
|
88
120
|
this.put("full_page", fullPage ? "true" : "false");
|
|
89
121
|
return this;
|
|
90
|
-
}
|
|
122
|
+
};
|
|
91
123
|
/**
|
|
92
124
|
* Sets response format, one of: "png", "jpeg", "webp" or "jpg".
|
|
93
125
|
*/
|
|
94
|
-
format(format) {
|
|
126
|
+
TakeOptions.prototype.format = function (format) {
|
|
95
127
|
this.put("format", format);
|
|
96
128
|
return this;
|
|
97
|
-
}
|
|
129
|
+
};
|
|
98
130
|
/**
|
|
99
131
|
* Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp".
|
|
100
132
|
*/
|
|
101
|
-
imageQuality(imageQuality) {
|
|
133
|
+
TakeOptions.prototype.imageQuality = function (imageQuality) {
|
|
102
134
|
this.put("image_quality", imageQuality.toString());
|
|
103
135
|
return this;
|
|
104
|
-
}
|
|
136
|
+
};
|
|
105
137
|
/**
|
|
106
138
|
* Renders a transparent background for the image. Works only if the site has not defined background color.
|
|
107
139
|
* Available for the following response formats: "png", "webp".
|
|
108
140
|
*/
|
|
109
|
-
omitBackground(omitBackground) {
|
|
141
|
+
TakeOptions.prototype.omitBackground = function (omitBackground) {
|
|
110
142
|
this.put("omit_background", omitBackground ? "true" : "false");
|
|
111
143
|
return this;
|
|
112
|
-
}
|
|
144
|
+
};
|
|
113
145
|
/**
|
|
114
146
|
* Sets the width of the browser viewport (pixels).
|
|
115
147
|
*/
|
|
116
|
-
viewportWidth(viewportWidth) {
|
|
148
|
+
TakeOptions.prototype.viewportWidth = function (viewportWidth) {
|
|
117
149
|
this.put("viewport_width", viewportWidth.toString());
|
|
118
150
|
return this;
|
|
119
|
-
}
|
|
151
|
+
};
|
|
120
152
|
/**
|
|
121
153
|
* Sets the height of the browser viewport (pixels).
|
|
122
154
|
*/
|
|
123
|
-
viewportHeight(viewportHeight) {
|
|
155
|
+
TakeOptions.prototype.viewportHeight = function (viewportHeight) {
|
|
124
156
|
this.put("viewport_height", viewportHeight.toString());
|
|
125
157
|
return this;
|
|
126
|
-
}
|
|
158
|
+
};
|
|
127
159
|
/**
|
|
128
160
|
* Sets the device scale factor. Acceptable value is one of: 1, 2 or 3.
|
|
129
161
|
*/
|
|
130
|
-
deviceScaleFactor(deviceScaleFactor) {
|
|
162
|
+
TakeOptions.prototype.deviceScaleFactor = function (deviceScaleFactor) {
|
|
131
163
|
this.put("device_scale_factor", deviceScaleFactor.toString());
|
|
132
164
|
return this;
|
|
133
|
-
}
|
|
165
|
+
};
|
|
134
166
|
/**
|
|
135
167
|
* Sets geolocation latitude for the request.
|
|
136
168
|
* Both latitude and longitude are required if one of them is set.
|
|
137
169
|
*/
|
|
138
|
-
geolocationLatitude(latitude) {
|
|
139
|
-
this.put("geolocation_latitude", new
|
|
170
|
+
TakeOptions.prototype.geolocationLatitude = function (latitude) {
|
|
171
|
+
this.put("geolocation_latitude", new Big(latitude).toFixed(20).replace(/0+$/, ""));
|
|
140
172
|
return this;
|
|
141
|
-
}
|
|
173
|
+
};
|
|
142
174
|
/**
|
|
143
175
|
* Sets geolocation longitude for the request. Both latitude and longitude are required if one of them is set.
|
|
144
176
|
*/
|
|
145
|
-
geolocationLongitude(longitude) {
|
|
146
|
-
this.put("geolocation_longitude", new
|
|
177
|
+
TakeOptions.prototype.geolocationLongitude = function (longitude) {
|
|
178
|
+
this.put("geolocation_longitude", new Big(longitude).toFixed(20).replace(/0+$/, ""));
|
|
147
179
|
return this;
|
|
148
|
-
}
|
|
180
|
+
};
|
|
149
181
|
/**
|
|
150
182
|
* Sets the geolocation accuracy in meters.
|
|
151
183
|
*/
|
|
152
|
-
geolocationAccuracy(accuracy) {
|
|
184
|
+
TakeOptions.prototype.geolocationAccuracy = function (accuracy) {
|
|
153
185
|
this.put("geolocation_accuracy", accuracy.toString());
|
|
154
186
|
return this;
|
|
155
|
-
}
|
|
187
|
+
};
|
|
156
188
|
/**
|
|
157
189
|
* Blocks ads.
|
|
158
190
|
*/
|
|
159
|
-
blockAds(blockAds) {
|
|
191
|
+
TakeOptions.prototype.blockAds = function (blockAds) {
|
|
160
192
|
this.put("block_ads", blockAds ? "true" : "false");
|
|
161
193
|
return this;
|
|
162
|
-
}
|
|
194
|
+
};
|
|
163
195
|
/**
|
|
164
196
|
* Blocks trackers.
|
|
165
197
|
*/
|
|
166
|
-
blockTrackers(blockTrackers) {
|
|
198
|
+
TakeOptions.prototype.blockTrackers = function (blockTrackers) {
|
|
167
199
|
this.put("block_trackers", blockTrackers ? "true" : "false");
|
|
168
200
|
return this;
|
|
169
|
-
}
|
|
201
|
+
};
|
|
170
202
|
/**
|
|
171
203
|
* Blocks requests by specifying URL, domain, or even a simple pattern.
|
|
172
204
|
*/
|
|
173
|
-
blockRequests(
|
|
174
|
-
|
|
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));
|
|
175
211
|
return this;
|
|
176
|
-
}
|
|
212
|
+
};
|
|
177
213
|
/**
|
|
178
214
|
* Blocks loading resources by type. Available resource types are: "document", "stylesheet", "image", "media",
|
|
179
215
|
* "font", "script", "texttrack", "xhr", "fetch", "eventsource", "websocket", "manifest", "other".
|
|
180
216
|
*/
|
|
181
|
-
blockResources(
|
|
182
|
-
|
|
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));
|
|
183
223
|
return this;
|
|
184
|
-
}
|
|
224
|
+
};
|
|
185
225
|
/**
|
|
186
226
|
* Enables caching.
|
|
187
227
|
*/
|
|
188
|
-
cache(cache) {
|
|
228
|
+
TakeOptions.prototype.cache = function (cache) {
|
|
189
229
|
this.put("cache", cache ? "true" : "false");
|
|
190
230
|
return this;
|
|
191
|
-
}
|
|
231
|
+
};
|
|
192
232
|
/**
|
|
193
233
|
* Sets cache TTL.
|
|
194
234
|
*/
|
|
195
|
-
cacheTtl(cacheTTL) {
|
|
235
|
+
TakeOptions.prototype.cacheTtl = function (cacheTTL) {
|
|
196
236
|
this.put("cache_ttl", cacheTTL.toString());
|
|
197
237
|
return this;
|
|
198
|
-
}
|
|
238
|
+
};
|
|
199
239
|
/**
|
|
200
240
|
* Sets cache key.
|
|
201
241
|
*/
|
|
202
|
-
cacheKey(cacheKey) {
|
|
242
|
+
TakeOptions.prototype.cacheKey = function (cacheKey) {
|
|
203
243
|
this.put("cache_key", cacheKey);
|
|
204
244
|
return this;
|
|
205
|
-
}
|
|
245
|
+
};
|
|
206
246
|
/**
|
|
207
247
|
* Sets a user agent for the request.
|
|
208
248
|
*/
|
|
209
|
-
userAgent(userAgent) {
|
|
249
|
+
TakeOptions.prototype.userAgent = function (userAgent) {
|
|
210
250
|
this.put("user_agent", userAgent);
|
|
211
251
|
return this;
|
|
212
|
-
}
|
|
252
|
+
};
|
|
213
253
|
/**
|
|
214
254
|
* Sets an authorization header for the request.
|
|
215
255
|
*/
|
|
216
|
-
authorization(authorization) {
|
|
256
|
+
TakeOptions.prototype.authorization = function (authorization) {
|
|
217
257
|
this.put("authorization", authorization);
|
|
218
258
|
return this;
|
|
219
|
-
}
|
|
259
|
+
};
|
|
220
260
|
/**
|
|
221
261
|
* Set cookies for the request.
|
|
222
262
|
*/
|
|
223
|
-
cookies(
|
|
224
|
-
|
|
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));
|
|
225
269
|
return this;
|
|
226
|
-
}
|
|
270
|
+
};
|
|
227
271
|
/**
|
|
228
272
|
* Sets extra headers for the request.
|
|
229
273
|
*/
|
|
230
|
-
headers(
|
|
231
|
-
|
|
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));
|
|
232
280
|
return this;
|
|
233
|
-
}
|
|
281
|
+
};
|
|
234
282
|
/**
|
|
235
283
|
* TimeZone sets time zone for the request.
|
|
236
284
|
* Available time zones are: "America/Santiago", "Asia/Shanghai", "Europe/Berlin", "America/Guayaquil",
|
|
237
285
|
* "Europe/Madrid", "Pacific/Majuro", "Asia/Kuala_Lumpur", "Pacific/Auckland", "Europe/Lisbon", "Europe/Kiev",
|
|
238
286
|
* "Asia/Tashkent", "Europe/London".
|
|
239
287
|
*/
|
|
240
|
-
timeZone(timeZone) {
|
|
288
|
+
TakeOptions.prototype.timeZone = function (timeZone) {
|
|
241
289
|
this.put("time_zone", timeZone);
|
|
242
290
|
return this;
|
|
243
|
-
}
|
|
291
|
+
};
|
|
244
292
|
/**
|
|
245
293
|
* Sets delay.
|
|
246
294
|
*/
|
|
247
|
-
delay(delay) {
|
|
295
|
+
TakeOptions.prototype.delay = function (delay) {
|
|
248
296
|
this.put("delay", delay.toString());
|
|
249
297
|
return this;
|
|
250
|
-
}
|
|
298
|
+
};
|
|
251
299
|
/**
|
|
252
300
|
* Sets timeout.
|
|
253
301
|
*/
|
|
254
|
-
timeout(timeout) {
|
|
302
|
+
TakeOptions.prototype.timeout = function (timeout) {
|
|
255
303
|
this.put("timeout", timeout.toString());
|
|
256
304
|
return this;
|
|
257
|
-
}
|
|
258
|
-
toQuery() {
|
|
305
|
+
};
|
|
306
|
+
TakeOptions.prototype.toQuery = function () {
|
|
259
307
|
return new URLSearchParams(this.query.toString());
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
|
|
308
|
+
};
|
|
309
|
+
return TakeOptions;
|
|
310
|
+
}());
|
|
311
|
+
export { TakeOptions };
|
|
263
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.
|
|
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
|
-
"
|
|
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",
|