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

@bustle/apple-news

Package Overview
Dependencies
Maintainers
22
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bustle/apple-news - npm Package Compare versions

Comparing version 2.3.0 to 3.0.0

13

lib/encode-form-data.js

@@ -9,3 +9,3 @@ 'use strict';

const seriesEach = require('eachy');
const fileType = require('file-type');
const FileType = require('file-type');
const objectAssign = require('object-assign');

@@ -58,3 +58,3 @@

const contentObj = fileType(body);
const contentObj = FileType.fromBuffer(body);
if (!contentObj) {

@@ -72,3 +72,3 @@ return callback(new Error('filetype error: ' + value));

});
}, function (err, callback) {
}, function (err) {
if (err) {

@@ -86,5 +86,8 @@ return cb(err);

converter.on('finish', function () {
const headers = form.getHeaders();
const buffer = Buffer.concat(chunks);
headers['content-length'] = String(buffer.length);
return cb(null, {
headers: form.getHeaders(),
buffer: Buffer.concat(chunks)
headers: headers,
buffer: buffer
});

@@ -91,0 +94,0 @@ });

'use strict';
const Buffer = require('safe-buffer').Buffer;
const crypto = require('crypto');

@@ -12,7 +11,7 @@ const objectAssign = require('object-assign');

module.exports = function (config) {
function sendRequest (method, endpoint, post, cb) {
function sendRequest (method, endpoint, post, callback) {
const host = config.host || defaultHost;
const date = new Date().toISOString().replace(/\.\d{3}Z$/, 'Z'); // remove milliseconds
let canonicalRequest = Buffer(method + 'https://' + host + endpoint + date +
(post ? post.headers['content-type'] : ''), 'ascii');
let canonicalRequest = Buffer.from(method + 'https://' + host + endpoint + date +
(post ? post.headers['content-type'] : ''));
if (post) {

@@ -22,3 +21,3 @@ canonicalRequest = Buffer.concat([canonicalRequest, post.buffer]);

const key = new Buffer(config.apiSecret, 'base64');
const key = Buffer.from(config.apiSecret, 'base64');
const signature = crypto.createHmac('sha256', key)

@@ -31,2 +30,9 @@ .update(canonicalRequest, 'utf8')

let done = false;
function cb (err, res, body) {
if (done) return;
done = true;
callback(err, res, body);
}
const req = https.request({

@@ -42,51 +48,44 @@ method: method,

}, post ? post.headers : {})
});
req.on('response', function (res) {
}, function (res) {
let result = '';
let done = false;
res.setEncoding('utf8');
res.on('data', function (chunk) {
result += chunk.toString();
result += chunk;
});
res.on('error', function (err) {
if (!done) {
done = true;
cb(err);
}
});
res.on('error', cb);
res.on('end', function () {
if (!done) {
done = true;
let parsed = null;
let parsed = null;
if (!result) {
return cb(null, res, null);
}
if (!result) {
return cb(null, res, null);
}
try {
parsed = JSON.parse(result);
} catch (e) {
return cb(e);
}
try {
parsed = JSON.parse(result);
} catch (e) {
return cb(e);
}
if (parsed.data) {
parsed.data.meta = parsed.meta
return cb(null, res, parsed.data);
}
if (parsed.data) {
parsed.data.meta = parsed.meta;
return cb(null, res, parsed.data);
}
if (parsed.errors && Array.isArray(parsed.errors) &&
parsed.errors.length > 0 && parsed.errors[0].code) {
const e = new Error(result);
e.apiError = parsed.errors[0];
return cb(e);
}
if (parsed.errors && Array.isArray(parsed.errors) &&
parsed.errors.length > 0 && parsed.errors[0].code) {
const e = new Error(result);
e.apiError = parsed.errors[0];
return cb(e);
}
return cb(new Error(result));
}
return cb(new Error(result));
});
});
req.on('error', cb);
if (post) {

@@ -93,0 +92,0 @@ req.write(post.buffer);

@@ -9,3 +9,3 @@ const assert = require('assert');

const channelId = process.env.CHANNEL_ID;
const async = require('async');
const series = require('async/series');
const http = require('http');

@@ -26,3 +26,3 @@ const path = require('path');

async.series([
series([
function (callback) {

@@ -29,0 +29,0 @@ server = http.createServer(function (req, res) {

{
"name": "@bustle/apple-news",
"version": "2.3.0",
"version": "3.0.0",
"description": "Node.js client for Apple News API",

@@ -22,25 +22,24 @@ "main": "index.js",

"devDependencies": {
"async": "^2.5.0",
"eslint": "^4.12.1",
"async": "^3.2.0",
"eslint": "^4.19.1",
"eslint-config-semistandard": "^11.0.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^5.2.1",
"eslint-plugin-promise": "^3.6.0",
"eslint-plugin-standard": "^3.0.1",
"nyc": "^8.3.0",
"pem": "^1.8.1",
"tape": "^4.5.1"
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"nyc": "^15.0.1",
"pem": "^1.14.4",
"tape": "^4.13.2"
},
"dependencies": {
"eachy": "^1.0.5",
"file-type": "^3.8.0",
"form-data": "^2.0.0",
"object-assign": "^4.0.1",
"safe-buffer": "^5.1.1"
"file-type": "^14.1.4",
"form-data": "^3.0.0",
"object-assign": "^4.0.1"
},
"engines": {
"node": ">=4.0.0",
"node": ">=6.0.0",
"npm": ">=5.0.0"
}
}

@@ -8,3 +8,3 @@ # Apple News API client

**For Node versions < 4, use `apple-news@^1`. For Node versions >= 4 use `apple-news@^2`**
**For Node versions < 4, use `apple-news@^1`. For Node versions >= 4 use `apple-news@^2`. For Node versions >= 6 use `apple-news@^3`**

@@ -11,0 +11,0 @@ ## Install

@@ -12,3 +12,3 @@ 'use strict';

const pem = require('pem');
const async = require('async');
const series = require('async/series');
const https = require('https');

@@ -21,3 +21,3 @@ const test = require('tape');

test('api', function (t) {
t.plan(14);
t.plan(12);

@@ -32,35 +32,23 @@ let client = null;

if (req.url === '/channels/cccccccc-cccc-cccc-cccc-cccccccccccc') {
res.end(JSON.stringify({ data: {} }));
t.pass('read channel');
return;
return res.end(JSON.stringify({ data: {} }));
}
if (req.url === '/channels/cccccccc-cccc-cccc-cccc-cccccccccccc/sections') {
res.end(JSON.stringify({ data: [ { id: sectionId } ] }));
t.pass('list sections');
return;
return res.end(JSON.stringify({ data: [ { id: sectionId } ] }));
}
if (req.url === '/sections/99999999-9999-9999-9999-999999999999') {
res.end(JSON.stringify({ data: { id: sectionId } }));
t.pass('read section');
return;
return res.end(JSON.stringify({ data: { id: sectionId } }));
}
if (req.url === '/articles/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa') {
res.end(JSON.stringify({ data: { id: articleId } }));
t.pass('read article');
return;
return res.end(JSON.stringify({ data: { id: articleId } }));
}
if (req.url === '/sections/99999999-9999-9999-9999-999999999999/articles') {
res.end(JSON.stringify({ data: [ { id: articleId } ] }));
t.pass('search articles by section');
return;
return res.end(JSON.stringify({ data: [ { id: articleId } ] }));
}
if (req.url === '/channels/cccccccc-cccc-cccc-cccc-cccccccccccc/articles') {
res.end(JSON.stringify({ data: [ { id: articleId } ] }));
t.pass('search articles by channel');
return;
return res.end(JSON.stringify({ data: [ { id: articleId } ] }));
}

@@ -70,5 +58,3 @@

res.writeHead(200);
fs.createReadStream(path.resolve(__dirname, 'image.jpg')).pipe(res);
t.pass('download image 1');
return;
return fs.createReadStream(path.resolve(__dirname, 'image.jpg')).pipe(res);
}

@@ -78,5 +64,3 @@

res.writeHead(200);
fs.createReadStream(path.resolve(__dirname, 'image.png')).pipe(res);
t.pass('download image 2');
return;
return fs.createReadStream(path.resolve(__dirname, 'image.png')).pipe(res);
}

@@ -86,4 +70,3 @@

res.writeHead(404);
res.end(0);
return;
return res.end(0);
}

@@ -93,13 +76,15 @@ }

if (req.method === 'POST') {
req.on('data', function () {});
if (req.url === '/channels/cccccccc-cccc-cccc-cccc-cccccccccccc/articles') {
res.writeHead(201);
res.end(JSON.stringify({ data: { id: articleId } }));
t.pass('create article');
return;
return req.on('end', function () {
res.writeHead(201);
res.end(JSON.stringify({ data: { id: articleId } }));
});
}
if (req.url === '/articles/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa') {
res.end(JSON.stringify({ data: { id: articleId } }));
t.pass('update article');
return;
return req.on('end', function () {
res.end(JSON.stringify({ data: { id: articleId } }));
});
}

@@ -111,5 +96,3 @@ }

res.writeHead(204);
res.end(JSON.stringify({ data: { id: articleId } }));
t.pass('delete article');
return;
return res.end(JSON.stringify({ data: { id: articleId } }));
}

@@ -121,3 +104,15 @@ }

async.series([
function checkTest (msg, callback) {
return function (err) {
if (err) {
console.error(err);
t.fail(msg);
} else {
t.pass(msg);
}
callback(err);
};
}
series([
function (callback) {

@@ -140,9 +135,9 @@ pem.createCertificate({ days: 5, selfSigned: true }, function (err, keys) {

function (callback) {
client.readChannel({ channelId: channelId }, callback);
client.readChannel({ channelId: channelId }, checkTest('read channel', callback));
},
function (callback) {
client.listSections({ channelId: channelId }, callback);
client.listSections({ channelId: channelId }, checkTest('list sections', callback));
},
function (callback) {
client.readSection({ sectionId: sectionId }, callback);
client.readSection({ sectionId: sectionId }, checkTest('read section', callback));
},

@@ -162,18 +157,18 @@ function (callback) {

]
}, callback);
}, checkTest('create article', callback));
},
function (callback) {
client.updateArticle({ articleId: articleId, revision: revision, article: article }, callback);
client.updateArticle({ articleId: articleId, revision: revision, article: article }, checkTest('update article', callback));
},
function (callback) {
client.readArticle({ articleId: articleId }, callback);
client.readArticle({ articleId: articleId }, checkTest('read article', callback));
},
function (callback) {
client.searchArticles({ sectionId: sectionId }, callback);
client.searchArticles({ sectionId: sectionId }, checkTest('search articles by section', callback));
},
function (callback) {
client.searchArticles({ channelId: channelId }, callback);
client.searchArticles({ channelId: channelId }, checkTest('search articles by channel', callback));
},
function (callback) {
client.deleteArticle({ articleId: articleId }, callback);
client.deleteArticle({ articleId: articleId }, checkTest('delete article', callback));
},

@@ -180,0 +175,0 @@ function (callback) {

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