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

ipfs-api

Package Overview
Dependencies
Maintainers
5
Versions
177
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ipfs-api - npm Package Compare versions

Comparing version 2.7.6 to 2.8.0

tasks/config.js

26

karma.conf.js

@@ -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

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