Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

urlbox-next

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

urlbox-next - npm Package Compare versions

Comparing version 2.0.5 to 3.0.5

3

dist/index.d.ts

@@ -1,2 +0,2 @@

interface UrlboxOptions {
export interface UrlboxOptions {
url?: string;

@@ -15,2 +15,1 @@ html?: string;

};
export {};

@@ -5,9 +5,12 @@ 'use strict';

var qs = /*#__PURE__*/require("qs");
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var hmacSha1 = /*#__PURE__*/require("crypto-js/hmac-sha1"); // const DEFAULT_PREFIX = "https://api.urlbox.io/s";
var qs = _interopDefault(require('qs'));
var hmacSha256 = _interopDefault(require('crypto-js/hmac-sha256'));
// const hmacSha1 = require("crypto-js/hmac-sha1");
// const DEFAULT_PREFIX = "https://api.urlbox.io/s";
var DEFAULT_PREFIX = "https://api.urlbox.io/v1/";
var DEFAULT_OPTIONS = {// format: "png"
var DEFAULT_OPTIONS = {
// format: "png"
};

@@ -18,18 +21,17 @@ function index (key, secret, prefix) {

}
if (!key) {
throw new Error("Please provide your urlbox API key");
}
if (!secret) {
throw new Error("Please provide your urlbox secret key");
}
return {
buildUrl: function buildUrl(options) {
options = validateOptions(options);
console.log("got options", options);
var query = toQueryString(options);
console.log("got query", query);
if (secret) {
var token = generateToken(query, secret);
console.log("got token", token);
return "" + prefix + key + "/" + token + "/" + (options.format || "png") + "?" + query;

@@ -44,8 +46,8 @@ } else {

var query = toQueryString(options);
var token = generateToken(query, secret); // console.log("got token", token);
var token = generateToken(query, secret);
// console.log("got token", token);
return {
unauthenticated: "" + prefix + key + "/" + (options.format || "png") + "?" + query,
authenticated: "" + prefix + key + "/" + token + "/" + (options.format || "png") + "?" + query,
postJSON: "curl -X POST\n -H \"Authorization: Bearer " + secret + "\" \n -H \"Content-Type: application/json\"\n -d '" + JSON.stringify(options, null, 2) + "'\n https://api.urlbox.io/v1/render",
postJSON: "curl -X POST https://api.urlbox.io/v1/render -H \"Authorization: Bearer " + secret + "\" -H \"Content-Type: application/json\" -d '" + JSON.stringify(options) + "'",
postForm: "curl " + prefix + "render"

@@ -56,7 +58,5 @@ };

}
var generateToken = function generateToken(queryString, secret) {
return hmacSha1(queryString, secret);
return hmacSha256(queryString, secret);
};
var toQueryString = function toQueryString(options) {

@@ -67,6 +67,4 @@ var filterFunc = function filterFunc(key, value) {

}
return value;
};
var fixedEncodeURIComponent = function fixedEncodeURIComponent(str) {

@@ -78,3 +76,2 @@ var result = encodeURIComponent(str).replace(/[!'()*]/g, function (c) {

};
return qs.stringify(options, {

@@ -86,17 +83,13 @@ encoder: fixedEncodeURIComponent,

};
var validateOptions = function validateOptions(options) {
if (!options) {
throw new Error("no options object passed");
} // console.log("In validate", options.url !== null && options.url !== undefined)
}
// console.log("In validate", options.url !== null && options.url !== undefined)
if (options.url !== null && options.url !== undefined && typeof options.url !== "string") {
throw new Error("url should be of type string (something like google.com)");
}
if (options.url === null || options.html === null) {
throw new Error("url or html option is required");
}
return Object.assign({}, DEFAULT_OPTIONS, options);

@@ -103,0 +96,0 @@ };

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("qs"),e=require("crypto-js/hmac-sha1"),t={},n=function(r,t){return e(r,t)},o=function(e){return r.stringify(e,{encoder:function(r){return encodeURIComponent(r).replace(/[!'()*]/g,(function(r){return"%"+r.charCodeAt(0).toString(16).toUpperCase()}))},filter:function(r,e){if("format"!==r&&"token"!==r&&"key"!==r&&e)return e},arrayFormat:"repeat"})},i=function(r){if(!r)throw new Error("no options object passed");if(null!=r.url&&"string"!=typeof r.url)throw new Error("url should be of type string (something like google.com)");if(null===r.url||null===r.html)throw new Error("url or html option is required");return Object.assign({},t,r)};exports.default=function(r,e,t){if(void 0===t&&(t="https://api.urlbox.io/v1/"),!r)throw new Error("Please provide your urlbox API key");if(!e)throw new Error("Please provide your urlbox secret key");return{buildUrl:function(u){u=i(u);var l=o(u);if(e){var a=n(l,e);return""+t+r+"/"+a+"/"+(u.format||"png")+"?"+l}return""+t+r+"/"+(u.format||"png")+"?"+l},buildUrls:function(u){u=i(u);var l=o(u),a=n(l,e);return{unauthenticated:""+t+r+"/"+(u.format||"png")+"?"+l,authenticated:""+t+r+"/"+a+"/"+(u.format||"png")+"?"+l,postJSON:'curl -X POST\n -H "Authorization: Bearer '+e+'" \n -H "Content-Type: application/json"\n -d \''+JSON.stringify(u,null,2)+"'\n https://api.urlbox.io/v1/render",postForm:"curl "+t+"render"}}}};
"use strict";function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}Object.defineProperty(exports,"__esModule",{value:!0});var o=r(require("qs")),e=r(require("crypto-js/hmac-sha256")),t={},n=function(r,o){return e(r,o)},u=function(r){return o.stringify(r,{encoder:function(r){return encodeURIComponent(r).replace(/[!'()*]/g,(function(r){return"%"+r.charCodeAt(0).toString(16).toUpperCase()}))},filter:function(r,o){if("format"!==r&&"token"!==r&&"key"!==r&&o)return o},arrayFormat:"repeat"})},i=function(r){if(!r)throw new Error("no options object passed");if(null!=r.url&&"string"!=typeof r.url)throw new Error("url should be of type string (something like google.com)");if(null===r.url||null===r.html)throw new Error("url or html option is required");return Object.assign({},t,r)};exports.default=function(r,o,e){if(void 0===e&&(e="https://api.urlbox.io/v1/"),!r)throw new Error("Please provide your urlbox API key");if(!o)throw new Error("Please provide your urlbox secret key");return{buildUrl:function(t){t=i(t),console.log("got options",t);var l=u(t);if(console.log("got query",l),o){var a=n(l,o);return console.log("got token",a),""+e+r+"/"+a+"/"+(t.format||"png")+"?"+l}return""+e+r+"/"+(t.format||"png")+"?"+l},buildUrls:function(t){t=i(t);var l=u(t),a=n(l,o);return{unauthenticated:""+e+r+"/"+(t.format||"png")+"?"+l,authenticated:""+e+r+"/"+a+"/"+(t.format||"png")+"?"+l,postJSON:'curl -X POST https://api.urlbox.io/v1/render -H "Authorization: Bearer '+o+'" -H "Content-Type: application/json" -d \''+JSON.stringify(t)+"'",postForm:"curl "+e+"render"}}}};
//# sourceMappingURL=urlbox-next.cjs.production.min.js.map

@@ -1,8 +0,9 @@

var qs = /*#__PURE__*/require("qs");
import qs from 'qs';
import hmacSha256 from 'crypto-js/hmac-sha256';
var hmacSha1 = /*#__PURE__*/require("crypto-js/hmac-sha1"); // const DEFAULT_PREFIX = "https://api.urlbox.io/s";
// const hmacSha1 = require("crypto-js/hmac-sha1");
// const DEFAULT_PREFIX = "https://api.urlbox.io/s";
var DEFAULT_PREFIX = "https://api.urlbox.io/v1/";
var DEFAULT_OPTIONS = {// format: "png"
var DEFAULT_OPTIONS = {
// format: "png"
};

@@ -13,18 +14,17 @@ function index (key, secret, prefix) {

}
if (!key) {
throw new Error("Please provide your urlbox API key");
}
if (!secret) {
throw new Error("Please provide your urlbox secret key");
}
return {
buildUrl: function buildUrl(options) {
options = validateOptions(options);
console.log("got options", options);
var query = toQueryString(options);
console.log("got query", query);
if (secret) {
var token = generateToken(query, secret);
console.log("got token", token);
return "" + prefix + key + "/" + token + "/" + (options.format || "png") + "?" + query;

@@ -39,8 +39,8 @@ } else {

var query = toQueryString(options);
var token = generateToken(query, secret); // console.log("got token", token);
var token = generateToken(query, secret);
// console.log("got token", token);
return {
unauthenticated: "" + prefix + key + "/" + (options.format || "png") + "?" + query,
authenticated: "" + prefix + key + "/" + token + "/" + (options.format || "png") + "?" + query,
postJSON: "curl -X POST\n -H \"Authorization: Bearer " + secret + "\" \n -H \"Content-Type: application/json\"\n -d '" + JSON.stringify(options, null, 2) + "'\n https://api.urlbox.io/v1/render",
postJSON: "curl -X POST https://api.urlbox.io/v1/render -H \"Authorization: Bearer " + secret + "\" -H \"Content-Type: application/json\" -d '" + JSON.stringify(options) + "'",
postForm: "curl " + prefix + "render"

@@ -51,7 +51,5 @@ };

}
var generateToken = function generateToken(queryString, secret) {
return hmacSha1(queryString, secret);
return hmacSha256(queryString, secret);
};
var toQueryString = function toQueryString(options) {

@@ -62,6 +60,4 @@ var filterFunc = function filterFunc(key, value) {

}
return value;
};
var fixedEncodeURIComponent = function fixedEncodeURIComponent(str) {

@@ -73,3 +69,2 @@ var result = encodeURIComponent(str).replace(/[!'()*]/g, function (c) {

};
return qs.stringify(options, {

@@ -81,17 +76,13 @@ encoder: fixedEncodeURIComponent,

};
var validateOptions = function validateOptions(options) {
if (!options) {
throw new Error("no options object passed");
} // console.log("In validate", options.url !== null && options.url !== undefined)
}
// console.log("In validate", options.url !== null && options.url !== undefined)
if (options.url !== null && options.url !== undefined && typeof options.url !== "string") {
throw new Error("url should be of type string (something like google.com)");
}
if (options.url === null || options.html === null) {
throw new Error("url or html option is required");
}
return Object.assign({}, DEFAULT_OPTIONS, options);

@@ -98,0 +89,0 @@ };

{
"version": "2.0.5",
"version": "3.0.5",
"license": "MIT",

@@ -10,2 +10,3 @@ "main": "dist/index.js",

],
"type": "module",
"engines": {

@@ -23,3 +24,2 @@ "node": ">=10"

},
"peerDependencies": {},
"husky": {

@@ -30,8 +30,2 @@ "hooks": {

},
"prettier": {
"printWidth": 80,
"semi": true,
"singleQuote": false,
"trailingComma": "es5"
},
"name": "urlbox-next",

@@ -52,2 +46,3 @@ "author": "Chris",

"@size-limit/preset-small-lib": "^4.10.1",
"@types/crypto-js": "^4.1.0",
"husky": "^5.2.0",

@@ -58,3 +53,8 @@ "size-limit": "^4.10.1",

"typescript": "^4.2.3"
},
"dependencies": {
"crypto-js": "4.1.1",
"mixpanel": "^0.13.0",
"qs": "6.10.1"
}
}
"use strict";
// const includes = require("lodash.includes");
const qs = require("qs");
const hmacSha1 = require("crypto-js/hmac-sha1");
// const qs = require("qs");
import qs from "qs";
import hmacSha256 from "crypto-js/hmac-sha256";
// const hmacSha1 = require("crypto-js/hmac-sha1");

@@ -12,3 +14,3 @@ // const DEFAULT_PREFIX = "https://api.urlbox.io/s";

interface UrlboxOptions {
export interface UrlboxOptions {
url?: string;

@@ -20,3 +22,3 @@ html?: string;

export default function (key:string, secret:string, prefix = DEFAULT_PREFIX) {
export default function (key: string, secret: string, prefix = DEFAULT_PREFIX) {
if (!key) {

@@ -29,7 +31,10 @@ throw new Error("Please provide your urlbox API key");

return {
buildUrl: (options:UrlboxOptions) => {
buildUrl: (options: UrlboxOptions) => {
options = validateOptions(options);
console.log("got options", options);
const query = toQueryString(options);
console.log("got query", query);
if (secret) {
const token = generateToken(query, secret);
console.log("got token", token);
return `${prefix}${key}/${token}/${options.format || "png"}?${query}`;

@@ -41,3 +46,3 @@ } else {

},
buildUrls: (options:UrlboxOptions) => {
buildUrls: (options: UrlboxOptions) => {
options = validateOptions(options);

@@ -48,29 +53,24 @@ const query = toQueryString(options);

return {
unauthenticated: `${prefix}${key}/${options.format ||
"png"}?${query}`,
authenticated: `${prefix}${key}/${token}/${options.format ||
"png"}?${query}`,
postJSON: `curl -X POST
-H "Authorization: Bearer ${secret}"
-H "Content-Type: application/json"
-d '${JSON.stringify(options,null,2)}'
https://api.urlbox.io/v1/render`,
postForm: `curl ${prefix}render`
unauthenticated: `${prefix}${key}/${options.format || "png"}?${query}`,
authenticated: `${prefix}${key}/${token}/${
options.format || "png"
}?${query}`,
postJSON: `curl -X POST \
https://api.urlbox.io/v1/render \
-H "Authorization: Bearer ${secret}" \
-H "Content-Type: application/json" \
-d '${JSON.stringify(options)}'`,
postForm: `curl ${prefix}render`,
};
}
},
};
};
}
const generateToken = (queryString:string, secret:string) => {
return hmacSha1(queryString, secret);
const generateToken = (queryString: string, secret: string) => {
return hmacSha256(queryString, secret);
};
const toQueryString = (options:UrlboxOptions) => {
const filterFunc = (key:string, value:any) => {
if (
(key === "format") ||
key === "token" ||
key === "key" ||
!value
) {
const toQueryString = (options: UrlboxOptions) => {
const filterFunc = (key: string, value: any) => {
if (key === "format" || key === "token" || key === "key" || !value) {
return;

@@ -80,11 +80,6 @@ }

};
const fixedEncodeURIComponent = (str:string) => {
const fixedEncodeURIComponent = (str: string) => {
let result = encodeURIComponent(str).replace(
/[!'()*]/g,
c =>
"%" +
c
.charCodeAt(0)
.toString(16)
.toUpperCase()
(c) => "%" + c.charCodeAt(0).toString(16).toUpperCase()
);

@@ -96,7 +91,7 @@ return result;

filter: filterFunc,
arrayFormat: "repeat"
arrayFormat: "repeat",
});
};
const validateOptions = (options:UrlboxOptions) => {
const validateOptions = (options: UrlboxOptions) => {
if (!options) {

@@ -106,6 +101,8 @@ throw new Error("no options object passed");

// console.log("In validate", options.url !== null && options.url !== undefined)
if (options.url !== null && options.url !== undefined && typeof options.url !== "string") {
throw new Error(
"url should be of type string (something like google.com)"
);
if (
options.url !== null &&
options.url !== undefined &&
typeof options.url !== "string"
) {
throw new Error("url should be of type string (something like google.com)");
}

@@ -112,0 +109,0 @@ if (options.url === null || options.html === null) {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc