urlbox-next
Advanced tools
Comparing version 3.0.5 to 3.1.5
@@ -0,0 +0,0 @@ export interface UrlboxOptions { |
@@ -1,8 +0,85 @@ | ||
'use strict' | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./urlbox-next.cjs.production.min.js') | ||
} else { | ||
module.exports = require('./urlbox-next.cjs.development.js') | ||
"use strict"; | ||
// const includes = require("lodash.includes"); | ||
// const qs = require("qs"); | ||
import qs from "qs"; | ||
import hmacSha256 from "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" | ||
}; | ||
export default function (key, secret, prefix) { | ||
if (prefix === void 0) { prefix = DEFAULT_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 (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 "".concat(prefix).concat(key, "/").concat(token, "/").concat(options.format || "png", "?").concat(query); | ||
} | ||
else { | ||
// tokenless URL | ||
return "".concat(prefix).concat(key, "/").concat(options.format || "png", "?").concat(query); | ||
} | ||
}, | ||
buildUrls: function (options) { | ||
options = validateOptions(options); | ||
var query = toQueryString(options); | ||
var token = generateToken(query, secret); | ||
// console.log("got token", token); | ||
return { | ||
unauthenticated: "".concat(prefix).concat(key, "/").concat(options.format || "png", "?").concat(query), | ||
authenticated: "".concat(prefix).concat(key, "/").concat(token, "/").concat(options.format || "png", "?").concat(query), | ||
postJSON: "curl -X POST https://api.urlbox.io/v1/render -H \"Authorization: Bearer ".concat(secret, "\" -H \"Content-Type: application/json\" -d '").concat(JSON.stringify(options), "'"), | ||
postForm: "curl ".concat(prefix, "render"), | ||
}; | ||
}, | ||
}; | ||
} | ||
var generateToken = function (queryString, secret) { | ||
return hmacSha256(queryString, secret); | ||
}; | ||
var toQueryString = function (options) { | ||
var filterFunc = function (key, value) { | ||
if (key === "format" || key === "token" || key === "key" || !value) { | ||
return; | ||
} | ||
return value; | ||
}; | ||
var fixedEncodeURIComponent = function (str) { | ||
var result = encodeURIComponent(str).replace(/[!'()*]/g, function (c) { return "%" + c.charCodeAt(0).toString(16).toUpperCase(); }); | ||
return result; | ||
}; | ||
return qs.stringify(options, { | ||
encoder: fixedEncodeURIComponent, | ||
filter: filterFunc, | ||
arrayFormat: "repeat", | ||
}); | ||
}; | ||
var validateOptions = function (options) { | ||
if (!options) { | ||
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.html === null) { | ||
throw new Error("url or html option is required"); | ||
} | ||
return Object.assign({}, DEFAULT_OPTIONS, options); | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"version": "3.0.5", | ||
"version": "3.1.5", | ||
"license": "MIT", | ||
@@ -15,42 +15,15 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"start": "tsdx watch", | ||
"build": "tsdx build", | ||
"test": "tsdx test", | ||
"lint": "tsdx lint", | ||
"prepare": "tsdx build", | ||
"size": "size-limit", | ||
"analyze": "size-limit --why" | ||
"dev": "tsc --watch", | ||
"build": "tsc -b tsconfig.json" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "tsdx lint" | ||
} | ||
}, | ||
"name": "urlbox-next", | ||
"author": "Chris", | ||
"module": "dist/urlbox-next.esm.js", | ||
"size-limit": [ | ||
{ | ||
"path": "dist/urlbox-next.cjs.production.min.js", | ||
"limit": "10 KB" | ||
}, | ||
{ | ||
"path": "dist/urlbox-next.esm.js", | ||
"limit": "10 KB" | ||
} | ||
], | ||
"devDependencies": { | ||
"@size-limit/preset-small-lib": "^4.10.1", | ||
"@types/crypto-js": "^4.1.0", | ||
"husky": "^5.2.0", | ||
"size-limit": "^4.10.1", | ||
"tsdx": "^0.14.1", | ||
"tslib": "^2.1.0", | ||
"typescript": "^4.2.3" | ||
"@types/crypto-js": "^4.1.2", | ||
"typescript": "^5.2.2" | ||
}, | ||
"dependencies": { | ||
"crypto-js": "4.1.1", | ||
"mixpanel": "^0.13.0", | ||
"qs": "6.10.1" | ||
"qs": "6.11.2" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
2
2
1
1
14832
7
197
1
+ Addedqs@6.11.2(transitive)
- Removedmixpanel@^0.13.0
- Removedagent-base@6.0.2(transitive)
- Removeddebug@4.4.0(transitive)
- Removedhttps-proxy-agent@5.0.0(transitive)
- Removedmixpanel@0.13.0(transitive)
- Removedms@2.1.3(transitive)
- Removedqs@6.10.1(transitive)
Updatedqs@6.11.2