Comparing version 2.7.6 to 2.8.0
@@ -0,3 +1,7 @@ | ||
var webpackConfig = require('./tasks/config').webpack | ||
module.exports = function (config) { | ||
if (!process.env.DEBUG) { | ||
var reporters = ['progress'] | ||
if (process.env.TRAVIS) { | ||
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) { | ||
@@ -7,2 +11,4 @@ console.log('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.') | ||
} | ||
reporters.push('saucelabs') | ||
} | ||
@@ -43,3 +49,3 @@ | ||
basePath: '', | ||
frameworks: ['browserify', 'mocha'], | ||
frameworks: ['mocha'], | ||
files: [ | ||
@@ -50,11 +56,9 @@ 'test/tests.js' | ||
preprocessors: { | ||
'test/**/*.js': ['browserify'] | ||
'test/**/*.js': ['webpack'] | ||
}, | ||
browserify: { | ||
debug: true, | ||
transform: [ | ||
'brfs', | ||
['babelify', {presets: ['es2015']}] | ||
] | ||
webpack: webpackConfig.dev, | ||
webpackMiddleware: { | ||
noInfo: true | ||
}, | ||
@@ -71,3 +75,3 @@ | ||
reporters: ['progress', 'saucelabs'], | ||
reporters: reporters, | ||
port: 9876, | ||
@@ -78,3 +82,3 @@ colors: true, | ||
customLaunchers: customLaunchers, | ||
browsers: process.env.DEBUG ? ['Chrome'] : Object.keys(customLaunchers), | ||
browsers: process.env.TRAVIS ? Object.keys(customLaunchers) : ['Chrome'], | ||
singleRun: false, | ||
@@ -81,0 +85,0 @@ concurrency: 2, |
{ | ||
"name": "ipfs-api", | ||
"version": "2.7.6", | ||
"version": "2.8.0", | ||
"description": "A client library for the IPFS API", | ||
"main": "src/index.js", | ||
"dependencies": { | ||
"brfs": "^1.4.0", | ||
"merge-stream": "^1.0.0", | ||
"multiaddr": "^1.0.0", | ||
"multipart-stream": "^2.0.0", | ||
"request": "^2.65.0", | ||
"qs": "^6.0.0", | ||
"vinyl": "^1.1.0", | ||
"vinyl-fs-browser": "^2.1.1-1", | ||
"vinyl-multipart-stream": "^1.2.6" | ||
"vinyl-multipart-stream": "^1.2.6", | ||
"wreck": "^7.0.0" | ||
}, | ||
"browserify": { | ||
"transform": [ | ||
"brfs" | ||
] | ||
}, | ||
"engines": { | ||
@@ -29,6 +24,7 @@ "node": "^4.0.0" | ||
"devDependencies": { | ||
"babel-core": "^6.1.21", | ||
"babel-eslint": "^4.1.3", | ||
"babel-loader": "^6.2.0", | ||
"babel-plugin-transform-runtime": "^6.1.18", | ||
"babel-preset-es2015": "^6.0.15", | ||
"babelify": "^7.2.0", | ||
"browserify": "^12.0.1", | ||
"concurrently": "^1.0.0", | ||
@@ -42,22 +38,24 @@ "eslint-config-standard": "^4.4.0", | ||
"gulp-size": "^2.0.0", | ||
"gulp-sourcemaps": "^1.6.0", | ||
"gulp-uglify": "^1.5.1", | ||
"gulp-util": "^3.0.7", | ||
"https-browserify": "0.0.1", | ||
"ipfsd-ctl": "^0.6.1", | ||
"json-loader": "^0.5.3", | ||
"karma": "^0.13.11", | ||
"karma-browserify": "^4.4.0", | ||
"karma-chrome-launcher": "^0.2.1", | ||
"karma-mocha": "^0.2.0", | ||
"karma-sauce-launcher": "^0.3.0", | ||
"karma-webpack": "^1.7.0", | ||
"mocha": "^2.3.3", | ||
"pre-commit": "^1.0.6", | ||
"raw-loader": "^0.5.1", | ||
"require-dir": "^0.3.0", | ||
"rimraf": "^2.4.3", | ||
"run-sequence": "^1.1.4", | ||
"stream-http": "^2.0.2", | ||
"uglify-js": "^2.4.24", | ||
"vinyl-buffer": "^1.0.0", | ||
"vinyl-source-stream": "^1.1.0" | ||
"vinyl-source-stream": "^1.1.0", | ||
"webpack-stream": "^2.1.1" | ||
}, | ||
"scripts": { | ||
"testD": "DEBUG=true gulp test:browser", | ||
"test": "gulp test", | ||
@@ -64,0 +62,0 @@ "test:node": "gulp test:node", |
var multiaddr = require('multiaddr') | ||
var getConfig = require('./config') | ||
var getRequestAPI = require('./request-api') | ||
var request = require('request') | ||
var Wreck = require('wreck') | ||
@@ -68,9 +68,12 @@ exports = module.exports = IpfsAPI | ||
if (typeof files === 'string' && files.startsWith('http')) { | ||
files = request.get({ | ||
url: files, | ||
withCredentials: false | ||
Wreck.request('GET', files, null, (err, res) => { | ||
if (err) return cb(err) | ||
requestAPI('add', null, opts, res, cb) | ||
}) | ||
return | ||
} | ||
return requestAPI('add', null, opts, files, cb) | ||
requestAPI('add', null, opts, files, cb) | ||
} | ||
@@ -77,0 +80,0 @@ |
'use strict' | ||
const request = require('request') | ||
const Wreck = require('wreck') | ||
const Qs = require('qs') | ||
const getFilesStream = require('./get-files-stream') | ||
const stream = require('stream') | ||
@@ -11,4 +11,4 @@ const isNode = !global.window | ||
function onEnd (buffer, result, passThrough, cb) { | ||
return (err, res, body) => { | ||
function onEnd (buffer, cb) { | ||
return (err, res) => { | ||
if (err) { | ||
@@ -18,78 +18,40 @@ return cb(err) | ||
const stream = !!res.headers['x-stream-output'] | ||
const chunkedObjects = !!res.headers['x-chunked-output'] | ||
if (res.statusCode >= 400 || !res.statusCode) { | ||
var error = new Error(`Server responded with ${res.statuscode}: ${body}`) | ||
try { | ||
body = JSON.parse(body) | ||
error.code = body.Code | ||
error.message = body.Message | ||
} catch (e) { | ||
error.body = body | ||
} | ||
return cb(error) | ||
} | ||
var error = new Error(`Server responded with ${res.statusCode}`) | ||
if (result.stream) { | ||
cb(null, passThrough) | ||
passThrough.resume() | ||
passThrough.end() | ||
return | ||
Wreck.read(res, {json: true}, (err, payload) => { | ||
if (err) { | ||
error.code = payload.Code | ||
error.message = payload.Message | ||
} | ||
cb(error) | ||
}) | ||
} | ||
if ((result.stream && !buffer) || | ||
(result.chunkedObjects && buffer)) { | ||
return cb(null, body) | ||
} | ||
if (stream && !buffer) return cb(null, res) | ||
if (result.chunkedObjects) return cb(null, result.objects) | ||
let parsedBody | ||
try { | ||
parsedBody = JSON.parse(body) | ||
} catch (e) { | ||
parsedBody = body | ||
} | ||
cb(null, parsedBody) | ||
} | ||
} | ||
function onData (result, passThrough) { | ||
return chunk => { | ||
if (result.stream) { | ||
passThrough.write(chunk) | ||
if (chunkedObjects) { | ||
const parsed = [] | ||
res.on('data', chunk => parsed.push(JSON.parse(chunk))) | ||
res.on('end', () => cb(null, parsed)) | ||
return | ||
} | ||
if (!result.chunkedObjects) return | ||
try { | ||
const obj = JSON.parse(chunk.toString()) | ||
result.objects.push(obj) | ||
} catch (e) { | ||
result.chunkedObjects = false | ||
} | ||
} | ||
} | ||
Wreck.read(res, null, (err, payload) => { | ||
if (err) return cb(err) | ||
function onResponse (result) { | ||
return res => { | ||
result.stream = !!res.headers['x-stream-output'] | ||
result.chunkedObjects = !!res.headers['x-chunked-output'] | ||
} | ||
} | ||
let parsed | ||
function makeRequest (opts, buffer, cb) { | ||
// this option is only used internally, not passed to daemon | ||
delete opts.qs.followSymlinks | ||
try { | ||
parsed = JSON.parse(payload.toString()) | ||
} catch (err2) { | ||
parsed = payload.toString() | ||
} | ||
const result = { | ||
stream: false, | ||
chunkedObjects: false, | ||
objects: [] | ||
cb(null, parsed) | ||
}) | ||
} | ||
var passThrough = new stream.PassThrough() | ||
return request(opts, onEnd(buffer, result, passThrough, cb)) | ||
.on('data', onData(result, passThrough)) | ||
.on('response', onResponse(result)) | ||
} | ||
@@ -120,10 +82,14 @@ | ||
let stream | ||
if (files) { | ||
stream = getFilesStream(files, qs) | ||
} | ||
// this option is only used internally, not passed to daemon | ||
delete qs.followSymlinks | ||
const opts = { | ||
method: files ? 'POST' : 'GET', | ||
uri: `http://${config.host}:${config.port}${config['api-path']}${path}`, | ||
qs: qs, | ||
useQuerystring: true, | ||
headers: {}, | ||
withCredentials: false, | ||
gzip: true | ||
uri: `http://${config.host}:${config.port}${config['api-path']}${path}?${Qs.stringify(qs, {arrayFormat: 'repeat'})}`, | ||
headers: {} | ||
} | ||
@@ -137,3 +103,2 @@ | ||
if (files) { | ||
const stream = getFilesStream(files, qs) | ||
if (!stream.boundary) { | ||
@@ -144,6 +109,7 @@ return cb(new Error('No boundary in multipart stream')) | ||
opts.headers['Content-Type'] = `multipart/form-data; boundary=${stream.boundary}` | ||
stream.pipe(makeRequest(opts, buffer, cb)) | ||
} else { | ||
makeRequest(opts, buffer, cb) | ||
opts.downstreamRes = stream | ||
opts.payload = stream | ||
} | ||
Wreck.request(opts.method, opts.uri, opts, onEnd(buffer, cb)) | ||
} | ||
@@ -150,0 +116,0 @@ |
@@ -1,18 +0,8 @@ | ||
var browserify = require('browserify') | ||
var gulp = require('gulp') | ||
var source = require('vinyl-source-stream') | ||
var buffer = require('vinyl-buffer') | ||
var runSequence = require('run-sequence') | ||
var rimraf = require('rimraf') | ||
var $ = require('gulp-load-plugins')() | ||
const gulp = require('gulp') | ||
const $ = require('gulp-load-plugins')() | ||
const webpack = require('webpack-stream') | ||
const rimraf = require('rimraf') | ||
const runSequence = require('run-sequence') | ||
function getBrowserify () { | ||
return browserify({ | ||
entries: ['./src/index.js'], | ||
debug: true, | ||
standalone: 'ipfsAPI' | ||
}) | ||
.transform('brfs') | ||
.transform('babelify', {presets: ['es2015']}) | ||
} | ||
const config = require('./config') | ||
@@ -24,20 +14,15 @@ gulp.task('clean', function (done) { | ||
gulp.task('build:nonminified', function () { | ||
return getBrowserify().bundle() | ||
.pipe(source('./ipfsapi.js')) | ||
.pipe(buffer()) | ||
return gulp.src('src/index.js') | ||
.pipe(webpack(config.webpack.dev)) | ||
.pipe($.size()) | ||
.pipe(gulp.dest('./dist/')) | ||
.pipe(gulp.dest('dist/')) | ||
}) | ||
gulp.task('build:minified', function () { | ||
return getBrowserify().bundle() | ||
.pipe(source('./ipfsapi.min.js')) | ||
.pipe(buffer()) | ||
.pipe($.sourcemaps.init({loadMaps: true})) | ||
// Add transformation tasks to the pipeline here. | ||
.pipe($.uglify()) | ||
.on('error', $.util.log) | ||
.pipe($.sourcemaps.write('./')) | ||
.pipe($.size({showFiles: true})) | ||
.pipe(gulp.dest('./dist/')) | ||
config.webpack.prod.output.filename = 'ipfsapi.min.js' | ||
return gulp.src('src/index.js') | ||
.pipe(webpack(config.webpack.prod)) | ||
.pipe($.size()) | ||
.pipe(gulp.dest('dist/')) | ||
}) | ||
@@ -44,0 +29,0 @@ |
/* global describe it before */ | ||
var ipfsAPI = require('../src/index.js') | ||
var assert = require('assert') | ||
var fs = require('fs') | ||
var path = require('path') | ||
@@ -12,3 +11,8 @@ var File = require('vinyl') | ||
var testfilePath = __dirname + '/testfile.txt' | ||
var testfile = fs.readFileSync(__dirname + '/testfile.txt') | ||
var testfile | ||
if (isNode) { | ||
testfile = require('fs').readFileSync(__dirname + '/testfile.txt') | ||
} else { | ||
testfile = require('raw!./testfile.txt') | ||
} | ||
@@ -96,3 +100,3 @@ describe('IPFS Node.js API wrapper tests', function () { | ||
if (err) throw err | ||
console.log(arguments) | ||
var added = res[0] != null ? res[0] : res | ||
@@ -190,5 +194,5 @@ assert.equal(added.Hash, 'Qma4hjFTnCasJ8PVp3mZbZK5g2vGDT4LByLJ7m8ciyRFZP') | ||
if (typeof res === 'string') { | ||
if (!res.on) { | ||
// Just a string | ||
assert.equal(res, testfile) | ||
assert.equal(res.toString(), testfile) | ||
done() | ||
@@ -288,2 +292,3 @@ return | ||
} | ||
assert(res) | ||
@@ -293,2 +298,3 @@ done() | ||
}) | ||
it('.config.replace', function (done) { | ||
@@ -384,5 +390,5 @@ this.timeout(10000) | ||
if (typeof res === 'string') { | ||
if (!res.on) { | ||
// Just a string | ||
assert.equal(res, 'blorb') | ||
assert.equal(res.toString(), 'blorb') | ||
done() | ||
@@ -436,5 +442,5 @@ return | ||
if (typeof res === 'string') { | ||
if (!res.on) { | ||
// Just a string | ||
assert.equal(res, 'testdata') | ||
assert.equal(res.toString(), 'testdata') | ||
done() | ||
@@ -441,0 +447,0 @@ return |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 4 instances 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
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 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
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
6492
0
1
1279022
33
7
+ Addedqs@^6.0.0
+ Addedwreck@^7.0.0
+ Addedboom@3.2.2(transitive)
+ Addedcall-bind-apply-helpers@1.0.1(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedget-intrinsic@1.2.6(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhoek@4.3.1(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedqs@6.13.1(transitive)
+ Addedside-channel@1.1.0(transitive)
+ Addedside-channel-list@1.0.0(transitive)
+ Addedside-channel-map@1.0.1(transitive)
+ Addedside-channel-weakmap@1.0.2(transitive)
+ Addedwreck@7.2.1(transitive)
- Removedbrfs@^1.4.0
- Removedrequest@^2.65.0
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)