screenshotone-api-sdk
Advanced tools
Comparing version 1.0.14 to 1.0.15
265
dist/main.js
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
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; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TakeOptions = exports.Client = void 0; | ||
var crypto = require("crypto"); | ||
var big_js_1 = require("big.js"); | ||
var cross_fetch_1 = require("cross-fetch"); | ||
const crypto = __importStar(require("crypto")); | ||
const big_js_1 = __importDefault(require("big.js")); | ||
const cross_fetch_1 = __importDefault(require("cross-fetch")); | ||
/** | ||
* Represents an API client for the screenshotone.com API. | ||
*/ | ||
var Client = /** @class */ (function () { | ||
function Client(accessKey, secretKey) { | ||
class Client { | ||
constructor(accessKey, secretKey) { | ||
this.API_BASE_URL = "https://api.screenshotone.com"; | ||
@@ -62,32 +43,21 @@ this.API_TAKE_PATH = "/take"; | ||
} | ||
Client.prototype.generateTakeURL = function (options) { | ||
var query = options.toQuery(); | ||
generateTakeURL(options) { | ||
const query = options.toQuery(); | ||
query.append("access_key", this.accessKey); | ||
var queryString = query.toString(); | ||
var signature = crypto.createHmac("sha256", this.secretKey) | ||
let queryString = query.toString(); | ||
const signature = crypto.createHmac("sha256", this.secretKey) | ||
.update(queryString, 'utf-8') | ||
.digest('hex'); | ||
queryString += '&signature=' + signature; | ||
return "".concat(this.API_BASE_URL).concat(this.API_TAKE_PATH, "?").concat(queryString); | ||
}; | ||
Client.prototype.take = function (options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
url = this.generateTakeURL(options); | ||
return [4 /*yield*/, (0, cross_fetch_1.default)(url)]; | ||
case 1: | ||
response = _a.sent(); | ||
if (!response.ok) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, response.blob()]; | ||
case 2: return [2 /*return*/, _a.sent()]; | ||
case 3: throw new Error("failed to take screenshot, response returned ".concat(response.status, " ").concat(response.statusText)); | ||
} | ||
}); | ||
}); | ||
}; | ||
return Client; | ||
}()); | ||
return `${this.API_BASE_URL}${this.API_TAKE_PATH}?${queryString}`; | ||
} | ||
async take(options) { | ||
const url = this.generateTakeURL(options); | ||
const response = await (0, cross_fetch_1.default)(url); | ||
if (response.ok) { | ||
return await response.blob(); | ||
} | ||
throw new Error(`failed to take screenshot, response returned ${response.status} ${response.statusText}`); | ||
} | ||
} | ||
exports.Client = Client; | ||
@@ -97,5 +67,5 @@ /** | ||
*/ | ||
var TakeOptions = /** @class */ (function () { | ||
function TakeOptions(url) { | ||
var query = new URLSearchParams(); | ||
class TakeOptions { | ||
constructor(url) { | ||
const query = new URLSearchParams(); | ||
query.append("url", url); | ||
@@ -107,15 +77,10 @@ this.query = query; | ||
*/ | ||
TakeOptions.url = function (url) { | ||
static url(url) { | ||
return new TakeOptions(url); | ||
}; | ||
TakeOptions.prototype.put = function (key) { | ||
var values = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
values[_i - 1] = arguments[_i]; | ||
} | ||
for (var _a = 0, values_1 = values; _a < values_1.length; _a++) { | ||
var value = values_1[_a]; | ||
} | ||
put(key, ...values) { | ||
for (const value of values) { | ||
this.query.append(key, value); | ||
} | ||
}; | ||
} | ||
; | ||
@@ -125,20 +90,20 @@ /** | ||
*/ | ||
TakeOptions.prototype.fullPage = function (fullPage) { | ||
fullPage(fullPage) { | ||
this.put("full_page", fullPage ? "true" : "false"); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Sets response format, one of: "png", "jpeg", "webp" or "jpg". | ||
*/ | ||
TakeOptions.prototype.format = function (format) { | ||
format(format) { | ||
this.put("format", format); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Renders image with the specified quality. Available for the next formats: "jpeg" ("jpg"), "webp". | ||
*/ | ||
TakeOptions.prototype.imageQuality = function (imageQuality) { | ||
imageQuality(imageQuality) { | ||
this.put("image_quality", imageQuality.toString()); | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -148,27 +113,27 @@ * Renders a transparent background for the image. Works only if the site has not defined background color. | ||
*/ | ||
TakeOptions.prototype.omitBackground = function (omitBackground) { | ||
omitBackground(omitBackground) { | ||
this.put("omit_background", omitBackground ? "true" : "false"); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Sets the width of the browser viewport (pixels). | ||
*/ | ||
TakeOptions.prototype.viewportWidth = function (viewportWidth) { | ||
viewportWidth(viewportWidth) { | ||
this.put("viewport_width", viewportWidth.toString()); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Sets the height of the browser viewport (pixels). | ||
*/ | ||
TakeOptions.prototype.viewportHeight = function (viewportHeight) { | ||
viewportHeight(viewportHeight) { | ||
this.put("viewport_height", viewportHeight.toString()); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Sets the device scale factor. Acceptable value is one of: 1, 2 or 3. | ||
*/ | ||
TakeOptions.prototype.deviceScaleFactor = function (deviceScaleFactor) { | ||
deviceScaleFactor(deviceScaleFactor) { | ||
this.put("device_scale_factor", deviceScaleFactor.toString()); | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -178,45 +143,41 @@ * Sets geolocation latitude for the request. | ||
*/ | ||
TakeOptions.prototype.geolocationLatitude = function (latitude) { | ||
geolocationLatitude(latitude) { | ||
this.put("geolocation_latitude", new big_js_1.default(latitude).toFixed(20).replace(/0+$/, "")); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Sets geolocation longitude for the request. Both latitude and longitude are required if one of them is set. | ||
*/ | ||
TakeOptions.prototype.geolocationLongitude = function (longitude) { | ||
geolocationLongitude(longitude) { | ||
this.put("geolocation_longitude", new big_js_1.default(longitude).toFixed(20).replace(/0+$/, "")); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Sets the geolocation accuracy in meters. | ||
*/ | ||
TakeOptions.prototype.geolocationAccuracy = function (accuracy) { | ||
geolocationAccuracy(accuracy) { | ||
this.put("geolocation_accuracy", accuracy.toString()); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Blocks ads. | ||
*/ | ||
TakeOptions.prototype.blockAds = function (blockAds) { | ||
blockAds(blockAds) { | ||
this.put("block_ads", blockAds ? "true" : "false"); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Blocks trackers. | ||
*/ | ||
TakeOptions.prototype.blockTrackers = function (blockTrackers) { | ||
blockTrackers(blockTrackers) { | ||
this.put("block_trackers", blockTrackers ? "true" : "false"); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Blocks requests by specifying URL, domain, or even a simple pattern. | ||
*/ | ||
TakeOptions.prototype.blockRequests = function () { | ||
var blockRequests = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
blockRequests[_i] = arguments[_i]; | ||
} | ||
this.put.apply(this, __spreadArray(["block_requests"], blockRequests, false)); | ||
blockRequests(...blockRequests) { | ||
this.put("block_requests", ...blockRequests); | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -226,67 +187,55 @@ * Blocks loading resources by type. Available resource types are: "document", "stylesheet", "image", "media", | ||
*/ | ||
TakeOptions.prototype.blockResources = function () { | ||
var blockResources = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
blockResources[_i] = arguments[_i]; | ||
} | ||
this.put.apply(this, __spreadArray(["block_resources"], blockResources, false)); | ||
blockResources(...blockResources) { | ||
this.put("block_resources", ...blockResources); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Enables caching. | ||
*/ | ||
TakeOptions.prototype.cache = function (cache) { | ||
cache(cache) { | ||
this.put("cache", cache ? "true" : "false"); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Sets cache TTL. | ||
*/ | ||
TakeOptions.prototype.cacheTtl = function (cacheTTL) { | ||
cacheTtl(cacheTTL) { | ||
this.put("cache_ttl", cacheTTL.toString()); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Sets cache key. | ||
*/ | ||
TakeOptions.prototype.cacheKey = function (cacheKey) { | ||
cacheKey(cacheKey) { | ||
this.put("cache_key", cacheKey); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Sets a user agent for the request. | ||
*/ | ||
TakeOptions.prototype.userAgent = function (userAgent) { | ||
userAgent(userAgent) { | ||
this.put("user_agent", userAgent); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Sets an authorization header for the request. | ||
*/ | ||
TakeOptions.prototype.authorization = function (authorization) { | ||
authorization(authorization) { | ||
this.put("authorization", authorization); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Set cookies for the request. | ||
*/ | ||
TakeOptions.prototype.cookies = function () { | ||
var cookies = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
cookies[_i] = arguments[_i]; | ||
} | ||
this.put.apply(this, __spreadArray(["cookies"], cookies, false)); | ||
cookies(...cookies) { | ||
this.put("cookies", ...cookies); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Sets extra headers for the request. | ||
*/ | ||
TakeOptions.prototype.headers = function () { | ||
var headers = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
headers[_i] = arguments[_i]; | ||
} | ||
this.put.apply(this, __spreadArray(["headers"], headers, false)); | ||
headers(...headers) { | ||
this.put("headers", ...headers); | ||
return this; | ||
}; | ||
} | ||
/** | ||
@@ -298,26 +247,24 @@ * TimeZone sets time zone for the request. | ||
*/ | ||
TakeOptions.prototype.timeZone = function (timeZone) { | ||
timeZone(timeZone) { | ||
this.put("time_zone", timeZone); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Sets delay. | ||
*/ | ||
TakeOptions.prototype.delay = function (delay) { | ||
delay(delay) { | ||
this.put("delay", delay.toString()); | ||
return this; | ||
}; | ||
} | ||
/** | ||
* Sets timeout. | ||
*/ | ||
TakeOptions.prototype.timeout = function (timeout) { | ||
timeout(timeout) { | ||
this.put("timeout", timeout.toString()); | ||
return this; | ||
}; | ||
TakeOptions.prototype.toQuery = function () { | ||
} | ||
toQuery() { | ||
return new URLSearchParams(this.query.toString()); | ||
}; | ||
return TakeOptions; | ||
}()); | ||
} | ||
} | ||
exports.TakeOptions = TakeOptions; | ||
//# sourceMappingURL=main.js.map |
{ | ||
"name": "screenshotone-api-sdk", | ||
"homepage": "https://screenshotone.com", | ||
"version": "1.0.14", | ||
"version": "1.0.15", | ||
"description": "Use ScreenshotOne.com API to generate screenshots of any website.", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -11,3 +11,6 @@ { | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true | ||
"forceConsistentCasingInFileNames": true, | ||
"outDir": "dist", | ||
"declarationDir": "dist/@types", | ||
"declaration": true, | ||
}, | ||
@@ -14,0 +17,0 @@ "include": [ |
19393
7
516