imagekit-javascript
Advanced tools
Comparing version
@@ -17,11 +17,23 @@ module.exports = function(grunt) { | ||
} | ||
}, | ||
uglify: { | ||
options: { | ||
mangle: false | ||
}, | ||
my_target: { | ||
files: { | ||
'dist/imagekit-min.js': ['dist/imagekit.js'] | ||
} | ||
} | ||
} | ||
}); | ||
grunt.loadNpmTasks('grunt-contrib-uglify'); | ||
grunt.loadNpmTasks('grunt-browserify'); | ||
// Default task(s). | ||
grunt.registerTask('default', ['browserify:dist']); | ||
grunt.registerTask('default', ['browserify:dist','uglify']); | ||
}; | ||
@@ -15,3 +15,3 @@ /* | ||
*/ | ||
const TRANSFORMATION_PARAMETER = "tr"; | ||
var TRANSFORMATION_PARAMETER = "tr"; | ||
@@ -81,3 +81,3 @@ module.exports.buildURL = function(opts) { | ||
for(var key in transformation[i]) { | ||
let transformKey = transformationUtils.getTransformKey(key); | ||
var transformKey = transformationUtils.getTransformKey(key); | ||
if(!transformKey) { | ||
@@ -84,0 +84,0 @@ transformKey = key; |
{ | ||
"name": "imagekit-javascript", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Javascript SDK for using ImageKit.io in the browser", | ||
"main": "index.js", | ||
"main": "dist/imagekit-min.js", | ||
"dependencies": { | ||
@@ -15,2 +15,3 @@ "lodash": "^4.17.15", | ||
"grunt-browserify": "^5.3.0", | ||
"grunt-contrib-uglify": "^4.0.1", | ||
"mocha": "^7.0.1", | ||
@@ -17,0 +18,0 @@ "sinon": "^8.1.1" |
# ImageKit.io Javascript SDK | ||
 | ||
[](https://www.npmjs.com/package/imagekit-javascript) | ||
@@ -9,3 +10,3 @@ [](https://opensource.org/licenses/MIT) | ||
ImageKit is a complete image optimization and transformation solution that comes with an [image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. It can be integrated with your existing infrastructure - storages like AWS S3, web servers, your CDN and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes. | ||
ImageKit is a complete image optimization and transformation solution that comes with an [image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. It can be integrated with your existing infrastructure - storage like AWS S3, web servers, your CDN, and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes. | ||
@@ -41,3 +42,3 @@ This SDK has no dependency. | ||
*Note: Do not include your Private Key in any client side code, including this SDK or its initialization. If you pass the `privateKey` parameter while initializing this SDK, it throws an error* | ||
*Note: Do not include your Private Key in any client-side code, including this SDK or its initialization. If you pass the `privateKey` parameter while initializing this SDK, it throws an error* | ||
@@ -101,4 +102,4 @@ ## Usage | ||
| transformation | Optional. An array of objects specifying the transformation to be applied in the URL. The transformation name and the value should be specified as a key-value pair in the object. Different steps of a [chained transformation](https://docs.imagekit.io/features/image-transformations/chained-transformations) can be specified as different objects of the array. The complete list of supported transformations in the SDK and some examples of using them are given later. If you use a transformation name that is not specified in the SDK, it gets applied as it is in the URL. | | ||
| transformationPostion | Optional. Default value is `path` that places the transformation string as a path parameter in the URL. Can also be specified as `query` which adds the transformation string as the query parameter `tr` in the URL. If you use `src` parameter to create the URL, then the transformation string is always added as a query parameter. | | ||
| queryParameters | Optional. These are the other query parameters that you want to add to the final URL. These can be any query parameters and not necessarily related to ImageKit. Especially useful, if you want to add some versioning parameter to your URLs. | | ||
| transformationPostion | Optional. The default value is `path` that places the transformation string as a path parameter in the URL. It can also be specified as `query` which adds the transformation string as the query parameter `tr` in the URL. If you use `src` parameter to create the URL, then the transformation string is always added as a query parameter. | | ||
| queryParameters | Optional. These are the other query parameters that you want to add to the final URL. These can be any query parameters and not necessarily related to ImageKit. Especially useful if you want to add some versioning parameter to your URLs. | | ||
@@ -127,3 +128,3 @@ #### Examples of generating URLs | ||
There are some transforms like [Sharpening](https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation) that can be added to the URL with or without any other value. To use such transforms without specifying a value, specify the value as "-" in the transformation object, otherwise, specify the value that you want to be added to this transformation. | ||
There are some transforms like [Sharpening](https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation) that can be added to the URL with or without any other value. To use such transforms without specifying a value, specify the value as "-" in the transformation object. Otherwise, specify the value that you want to be added to this transformation. | ||
@@ -202,7 +203,7 @@ ``` | ||
Also make sure that you have specified `authenticationEndpoint` during SDK initialization. The SDK makes an HTTP GET request to this endpoint and expects a JSON response with three fields i.e. `signature`, `token` and `expire`. | ||
Also, make sure that you have specified `authenticationEndpoint` during SDK initialization. The SDK makes an HTTP GET request to this endpoint and expects a JSON response with three fields, i.e. `signature`, `token`, and `expire`. | ||
[Learn how to implement authenticationEndpoint](https://docs.imagekit.io/api-reference/upload-file-api/client-side-file-upload#how-to-implement-authenticationendpoint-endpoint) on your server. | ||
You can pass other parameters supported by the ImageKit upload API using the same parameter name as specified in the upload API documentation. For example, to specify tags for a file at the time of upload use the `tags` parameter as specified in the [documentation here](https://docs.imagekit.io/api-reference/upload-file-api/client-side-file-upload). | ||
You can pass other parameters supported by the ImageKit upload API using the same parameter name as specified in the upload API documentation. For example, to specify tags for a file at the time of upload, use the `tags` parameter as specified in the [documentation here](https://docs.imagekit.io/api-reference/upload-file-api/client-side-file-upload). | ||
@@ -212,4 +213,4 @@ Sample usage | ||
<form action="#" onsubmit="upload()"> | ||
<input type="file" id="file1" /> | ||
<input type="submit" /> | ||
<input type="file" id="file1" /> | ||
<input type="submit" /> | ||
</form> | ||
@@ -246,4 +247,4 @@ <script type="text/javascript" src="../dist/imagekit.js"></script> | ||
If the upload succeed, `err` will be `null` and the `result` will be the same as what is received from ImageKit's servers. | ||
If the upload fails, `err` will be the same as what is received from ImageKit's servers and the `result` will be null. | ||
If the upload succeeds, `err` will be `null`, and the `result` will be the same as what is received from ImageKit's servers. | ||
If the upload fails, `err` will be the same as what is received from ImageKit's servers, and the `result` will be null. | ||
@@ -253,3 +254,3 @@ | ||
The fastest way to get started is running the demo application. You can run the code locally. The source code is in [samples/sample-app](https://github.com/imagekit-developer/imagekit-javascript/tree/master/samples/sample-app). | ||
The fastest way to get started is by running the demo application. You can run the code locally. The source code is in [samples/sample-app](https://github.com/imagekit-developer/imagekit-javascript/tree/master/samples/sample-app). | ||
@@ -256,0 +257,0 @@ To run it: |
@@ -11,3 +11,3 @@ const express = require('express'); | ||
//const html = fs.readFileSync(path.join(__dirname, "../views/index.html")); | ||
const js = fs.readFileSync(path.join(__dirname, "../../../dist/imagekit.js")); | ||
const js = fs.readFileSync(path.join(__dirname, "../../../dist/imagekit-min.js")); | ||
const pugTemplatePath = path.join(__dirname, "../views/index.pug"); | ||
@@ -14,0 +14,0 @@ |
447
test/test.js
@@ -17,3 +17,3 @@ const chai = require("chai"); | ||
var ImageKit = require("../"); | ||
var ImageKit = require("../index.js"); | ||
@@ -42,263 +42,264 @@ | ||
}); | ||
}); | ||
describe(".url method", function() { | ||
it('should generate the correct url with path param', function() { | ||
const url = imagekit.url({ | ||
path: "/test_path.jpg", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}); | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/[^\/]/); | ||
expect(url).to.match(new RegExp("[^\/]\/tr:")); | ||
expect(url).to.match(new RegExp(":h-300,w-400")); | ||
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
describe(".url method", function() { | ||
it('should generate the correct url with path param', function() { | ||
const url = imagekit.url({ | ||
path: "/test_path.jpg", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}); | ||
it('should generate the correct url with path param with multiple leading slash', function() { | ||
const url = imagekit.url({ | ||
path: "///test_path.jpg", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}) | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/[^\/]/); | ||
expect(url).to.match(new RegExp("[^\/]\/tr:")); | ||
expect(url).to.match(new RegExp(":h-300,w-400")); | ||
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/[^\/]/); | ||
expect(url).to.match(new RegExp("[^\/]\/tr:")); | ||
expect(url).to.match(new RegExp(":h-300,w-400")); | ||
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
}); | ||
}); | ||
it('should generate the correct url with path param with multiple leading slash', function() { | ||
const url = imagekit.url({ | ||
path: "///test_path.jpg", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}) | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/[^\/]/); | ||
expect(url).to.match(new RegExp("[^\/]\/tr:")); | ||
expect(url).to.match(new RegExp(":h-300,w-400")); | ||
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
it('should generate the correct url with path param with overidden urlEndpoint', function() { | ||
const url = imagekit.url({ | ||
urlEndpoint: "https://ik.imagekit.io/test_url_endpoint_alt", | ||
path: "/test_path.jpg", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}) | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\_alt\/[^\/]/); | ||
expect(url).to.match(new RegExp("[^\/]\/tr:")); | ||
expect(url).to.match(new RegExp(":h-300,w-400")); | ||
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
}); | ||
it('should generate the correct url with path param with overidden urlEndpoint', function() { | ||
const url = imagekit.url({ | ||
urlEndpoint: "https://ik.imagekit.io/test_url_endpoint_alt", | ||
path: "/test_path.jpg", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}) | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\_alt\/[^\/]/); | ||
expect(url).to.match(new RegExp("[^\/]\/tr:")); | ||
expect(url).to.match(new RegExp(":h-300,w-400")); | ||
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
}); | ||
it('should generate the correct url with path param with transformationPostion as query', function() { | ||
const url = imagekit.url({ | ||
path: "/test_path.jpg", | ||
transformationPosition: "query", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}); | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/test\_path\.jpg\?/); | ||
expect(url).to.match(new RegExp('&tr=h-300%2Cw-400')); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
}); | ||
it('should generate the correct url with path param with transformationPostion as query', function() { | ||
const url = imagekit.url({ | ||
path: "/test_path.jpg", | ||
transformationPosition: "query", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}); | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/test\_path\.jpg\?/); | ||
expect(url).to.match(new RegExp('&tr=h-300%2Cw-400')); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
it('should generate the correct url with src param', function() { | ||
const url = imagekit.url({ | ||
src : "https://ik.imagekit.io/test_url_endpoint/test_path_alt.jpg", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}); | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/test\_path\_alt\.jpg[^\/]/); | ||
expect(url).to.match(new RegExp('&tr=h-300%2Cw-400')); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
}); | ||
it('should generate the correct url with src param', function() { | ||
const url = imagekit.url({ | ||
src : "https://ik.imagekit.io/test_url_endpoint/test_path_alt.jpg", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}); | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/test\_path\_alt\.jpg[^\/]/); | ||
expect(url).to.match(new RegExp('&tr=h-300%2Cw-400')); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
it('should generate the correct url with transformationPostion as query', function() { | ||
const url = imagekit.url({ | ||
src : "https://ik.imagekit.io/test_url_endpoint/test_path_alt.jpg", | ||
transformationPosition: "query", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}); | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/test\_path\_alt\.jpg\?/); | ||
expect(url).to.match(new RegExp('&tr=h-300%2Cw-400')); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
}); | ||
it('should generate the correct url with transformationPostion as query', function() { | ||
const url = imagekit.url({ | ||
src : "https://ik.imagekit.io/test_url_endpoint/test_path_alt.jpg", | ||
transformationPosition: "query", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}); | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/test\_path\_alt\.jpg\?/); | ||
expect(url).to.match(new RegExp('&tr=h-300%2Cw-400')); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
it('should generate the correct url with query params properly merged', function() { | ||
const url = imagekit.url({ | ||
src : "https://ik.imagekit.io/test_url_endpoint/test_path_alt.jpg?t1=v1", | ||
queryParameters: {t2: "v2", t3: "v3"}, | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}); | ||
it('should generate the correct url with query params properly merged', function() { | ||
const url = imagekit.url({ | ||
src : "https://ik.imagekit.io/test_url_endpoint/test_path_alt.jpg?t1=v1", | ||
queryParameters: {t2: "v2", t3: "v3"}, | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}] | ||
}); | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/test\_path\_alt\.jpg\?t1=v1\&/); | ||
expect(url).to.match(new RegExp('&t2=v2&')); | ||
expect(url).to.match(new RegExp('&t3=v3&')); | ||
expect(url).to.match(new RegExp('&tr=h-300%2Cw-400')); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
}); | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/test\_path\_alt\.jpg\?t1=v1\&/); | ||
expect(url).to.match(new RegExp('&t2=v2&')); | ||
expect(url).to.match(new RegExp('&t3=v3&')); | ||
expect(url).to.match(new RegExp('&tr=h-300%2Cw-400')); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
}); | ||
it('should generate the correct chained transformation', function() { | ||
const url = imagekit.url({ | ||
path: "/test_path.jpg", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}, { | ||
"rt": "90" | ||
}] | ||
}) | ||
it('should generate the correct chained transformation', function() { | ||
const url = imagekit.url({ | ||
path: "/test_path.jpg", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}, { | ||
"rt": "90" | ||
}] | ||
}) | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/[^\/]/); | ||
expect(url).to.match(new RegExp("[^\/]\/tr:")); | ||
expect(url).to.match(new RegExp(":h-300,w-400:rt-90")); | ||
expect(url).to.not.match(new RegExp(":rt-90:h-300,w-400")); | ||
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
}); | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/[^\/]/); | ||
expect(url).to.match(new RegExp("[^\/]\/tr:")); | ||
expect(url).to.match(new RegExp(":h-300,w-400:rt-90")); | ||
expect(url).to.not.match(new RegExp(":rt-90:h-300,w-400")); | ||
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
}); | ||
it('should generate the correct chained transformation url with new undocumented tranforamtion parameter', function() { | ||
const url = imagekit.url({ | ||
path: "/test_path.jpg", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}, { | ||
"rndm_trnsf": "abcd" | ||
}] | ||
}) | ||
it('should generate the correct chained transformation url with new undocumented tranforamtion parameter', function() { | ||
const url = imagekit.url({ | ||
path: "/test_path.jpg", | ||
transformation : [{ | ||
"height" : "300", | ||
"width" : "400" | ||
}, { | ||
"rndm_trnsf": "abcd" | ||
}] | ||
}) | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/[^\/]/); | ||
expect(url).to.match(new RegExp("[^\/]\/tr:")); | ||
expect(url).to.match(new RegExp(":h-300,w-400:rndm_trnsf-abcd")); | ||
expect(url).to.not.match(new RegExp(":rndm_trnsf-abcd:h-300,w-400")); | ||
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
}); | ||
expect(url).to.match(/^https\:\/\/ik\.imagekit\.io\/test\_url\_endpoint\/[^\/]/); | ||
expect(url).to.match(new RegExp("[^\/]\/tr:")); | ||
expect(url).to.match(new RegExp(":h-300,w-400:rndm_trnsf-abcd")); | ||
expect(url).to.not.match(new RegExp(":rndm_trnsf-abcd:h-300,w-400")); | ||
expect(url).to.match(/[^\/]\/test_path\.jpg[^\/][\?]?/); | ||
expect(url).to.match(/ik\-sdk\-version\=javascript\-\d\.\d\.\d/); | ||
}); | ||
}); | ||
describe(".upload method", function() { | ||
let orderCop; | ||
describe(".upload method", function() { | ||
let orderCop; | ||
before(function() { | ||
orderCop = sinon.spy(); | ||
sinon.stub(requestUtils, 'generateSignatureToken').callsFake(function (options, callback) { | ||
orderCop('signatureCall'); | ||
callback(null, { | ||
signature: "test_signature", | ||
expire: 123, | ||
token: "test_token" | ||
}); | ||
before(function() { | ||
orderCop = sinon.spy(); | ||
sinon.stub(requestUtils, 'generateSignatureToken').callsFake(function (options, callback) { | ||
orderCop('signatureCall'); | ||
callback(null, { | ||
signature: "test_signature", | ||
expire: 123, | ||
token: "test_token" | ||
}); | ||
sinon.stub(requestUtils, 'uploadFile').callsFake(function (options, callback) { | ||
orderCop('uploadCall'); | ||
callback(null, "success"); | ||
}); | ||
}); | ||
sinon.stub(requestUtils, 'uploadFile').callsFake(function (options, callback) { | ||
orderCop('uploadCall'); | ||
callback(null, "success"); | ||
}); | ||
beforeEach(function() { | ||
orderCop.resetHistory(); | ||
requestUtils.generateSignatureToken.resetHistory(); | ||
requestUtils.uploadFile.resetHistory(); | ||
}) | ||
}); | ||
beforeEach(function() { | ||
orderCop.resetHistory(); | ||
requestUtils.generateSignatureToken.resetHistory(); | ||
requestUtils.uploadFile.resetHistory(); | ||
}); | ||
it('calls relavant functions in order', function() { | ||
const fileOptions = { | ||
fileName: "test_file_name", | ||
file: "test_file", | ||
}; | ||
imagekit.upload(fileOptions, function(){}); | ||
it('calls relavant functions in order', function() { | ||
const fileOptions = { | ||
fileName: "test_file_name", | ||
file: "test_file", | ||
}; | ||
imagekit.upload(fileOptions, function(){}); | ||
expect(requestUtils.generateSignatureToken.calledOnce).to.be.true; | ||
expect(requestUtils.uploadFile.calledOnce).to.be.true; | ||
expect(orderCop.firstCall.args[0]).to.be.equal('signatureCall'); | ||
expect(orderCop.secondCall.args[0]).to.be.equal('uploadCall'); | ||
}); | ||
expect(requestUtils.generateSignatureToken.calledOnce).to.be.true; | ||
expect(requestUtils.uploadFile.calledOnce).to.be.true; | ||
expect(orderCop.firstCall.args[0]).to.be.equal('signatureCall'); | ||
expect(orderCop.secondCall.args[0]).to.be.equal('uploadCall'); | ||
}); | ||
it('calls functions with correct arguments', function() { | ||
it('calls functions with correct arguments', function() { | ||
const fileOptions = { | ||
fileName: "test_file_name", | ||
file: "test_file", | ||
tags : ["test_tag1", "test_tag2"], | ||
customCoordinates: "test_customCoordinates", | ||
responseFields: "tags, customCoordinates, isPrivateFile, metadata", | ||
useUniqueFileName: true | ||
}; | ||
imagekit.upload(fileOptions, function(){}); | ||
const fileOptions = { | ||
fileName: "test_file_name", | ||
file: "test_file", | ||
tags : ["test_tag1", "test_tag2"], | ||
customCoordinates: "test_customCoordinates", | ||
responseFields: "tags, customCoordinates, isPrivateFile, metadata", | ||
useUniqueFileName: true | ||
}; | ||
imagekit.upload(fileOptions, function(){}); | ||
const arg = requestUtils.uploadFile.getCall(0).args[0]; | ||
expect(arg.get('file')).to.be.equal("test_file"); | ||
expect(arg.get('fileName')).to.be.equal("test_file_name"); | ||
expect(arg.get('token')).to.be.equal("test_token"); | ||
expect(arg.get('expire')).to.be.equal("123"); | ||
expect(arg.get('signature')).to.be.equal("test_signature"); | ||
expect(arg.get('tags')).to.match(new RegExp("test_tag1")); | ||
expect(arg.get('tags')).to.match(new RegExp("test_tag2")); | ||
expect(arg.get('customCoordinates')).to.match(new RegExp("test_customCoordinates")); | ||
expect(arg.get('responseFields')).to.match(new RegExp("tags, customCoordinates, isPrivateFile, metadata")); | ||
expect(arg.get('useUniqueFileName')).to.be.equal('true'); | ||
}); | ||
it('calls functions with correct arguments for missing parameters', function() { | ||
const fileOptions = { | ||
fileName: "test_file_name", | ||
file: "test_file", | ||
}; | ||
imagekit.upload(fileOptions, function(){}); | ||
const arg = requestUtils.uploadFile.getCall(0).args[0]; | ||
expect(arg.get('file')).to.be.equal("test_file"); | ||
expect(arg.get('fileName')).to.be.equal("test_file_name"); | ||
expect(arg.get('token')).to.be.equal("test_token"); | ||
expect(arg.get('expire')).to.be.equal("123"); | ||
expect(arg.get('signature')).to.be.equal("test_signature"); | ||
expect(arg.get('tags')).to.match(new RegExp("test_tag1")); | ||
expect(arg.get('tags')).to.match(new RegExp("test_tag2")); | ||
expect(arg.get('customCoordinates')).to.match(new RegExp("test_customCoordinates")); | ||
expect(arg.get('responseFields')).to.match(new RegExp("tags, customCoordinates, isPrivateFile, metadata")); | ||
expect(arg.get('useUniqueFileName')).to.be.equal('true'); | ||
expect(arg.get('publicKey')).to.be.equal('test_public_key'); | ||
}); | ||
it('calls functions with correct arguments for missing parameters', function() { | ||
const fileOptions = { | ||
fileName: "test_file_name", | ||
file: "test_file", | ||
}; | ||
imagekit.upload(fileOptions, function(){}); | ||
const arg = requestUtils.uploadFile.getCall(0).args[0]; | ||
expect(arg.get('file')).to.be.equal("test_file"); | ||
expect(arg.get('fileName')).to.be.equal("test_file_name"); | ||
expect(arg.get('tags')).to.not.equal("undefined"); | ||
expect(arg.get('customCoordinates')).to.be.equal(undefined); | ||
expect(arg.get('customCoordinates')).to.not.equal("undefined"); | ||
expect(arg.get('responseFields')).to.be.equal(undefined); | ||
expect(arg.get('responseFields')).to.not.equal("undefined"); | ||
expect(arg.get('useUniqueFileName')).to.be.equal(undefined); | ||
expect(arg.get('useUniqueFileName')).to.not.equal("undefined"); | ||
}); | ||
const arg = requestUtils.uploadFile.getCall(0).args[0]; | ||
expect(arg.get('file')).to.be.equal("test_file"); | ||
expect(arg.get('fileName')).to.be.equal("test_file_name"); | ||
expect(arg.get('tags')).to.not.equal("undefined"); | ||
expect(arg.get('customCoordinates')).to.be.equal(undefined); | ||
expect(arg.get('customCoordinates')).to.not.equal("undefined"); | ||
expect(arg.get('responseFields')).to.be.equal(undefined); | ||
expect(arg.get('responseFields')).to.not.equal("undefined"); | ||
expect(arg.get('useUniqueFileName')).to.be.equal(undefined); | ||
expect(arg.get('useUniqueFileName')).to.not.equal("undefined"); | ||
}); | ||
it('calls functions with base64 file argument', function() { | ||
it('calls functions with base64 file argument', function() { | ||
const fileOptions = { | ||
fileName: "test_file_name", | ||
file: fs.readFileSync(test_file_path, 'base64'), | ||
}; | ||
imagekit.upload(fileOptions, function(){}); | ||
const fileOptions = { | ||
fileName: "test_file_name", | ||
file: fs.readFileSync(test_file_path, 'base64'), | ||
}; | ||
imagekit.upload(fileOptions, function(){}); | ||
const arg = requestUtils.uploadFile.getCall(0).args[0]; | ||
expect(arg.get('file')).to.match(/^[a-zA-Z0-9\+/]*={0,2}$/); | ||
expect(arg.get('fileName')).to.be.equal("test_file_name"); | ||
}); | ||
const arg = requestUtils.uploadFile.getCall(0).args[0]; | ||
expect(arg.get('file')).to.match(/^[a-zA-Z0-9\+/]*={0,2}$/); | ||
expect(arg.get('fileName')).to.be.equal("test_file_name"); | ||
}); | ||
it('calls functions with url file argument', function() { | ||
it('calls functions with url file argument', function() { | ||
const fileOptions = { | ||
fileName: "test_file_name", | ||
file: "http://test.url", | ||
}; | ||
imagekit.upload(fileOptions, function(){}); | ||
const fileOptions = { | ||
fileName: "test_file_name", | ||
file: "http://test.url", | ||
}; | ||
imagekit.upload(fileOptions, function(){}); | ||
const arg = requestUtils.uploadFile.getCall(0).args[0]; | ||
expect(arg.get('file')).to.be.equal("http://test.url"); | ||
expect(arg.get('fileName')).to.be.equal("test_file_name"); | ||
}); | ||
}); | ||
const arg = requestUtils.uploadFile.getCall(0).args[0]; | ||
expect(arg.get('file')).to.be.equal("http://test.url"); | ||
expect(arg.get('fileName')).to.be.equal("test_file_name"); | ||
}); | ||
}); | ||
@@ -305,0 +306,0 @@ }); |
@@ -15,5 +15,5 @@ function request (formData, defaultOptions, callback) { | ||
if (err) { | ||
console.log(error); | ||
console.log(err); | ||
if(typeof callback != "function") return; | ||
callback(error); | ||
callback(err); | ||
} else { | ||
@@ -79,5 +79,5 @@ callback(null, responseSucessText); | ||
module.exports = { | ||
request, | ||
request : request, | ||
generateSignatureToken: _generateSignatureToken, | ||
uploadFile: _uploadFile, | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
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
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
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
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
217121
29.14%4097
0.32%263
0.38%7
16.67%1
Infinity%9
50%