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

clearbit

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clearbit - npm Package Compare versions

Comparing version 1.0.8 to 1.1.0

src/watchlist.js

2

package.json
{
"name": "clearbit",
"version": "1.0.8",
"version": "1.1.0",
"description": "Client for Clearbit.co business intelligence APIs",

@@ -5,0 +5,0 @@ "main": "./src",

@@ -15,12 +15,17 @@ 'use strict';

assert(this instanceof ClearbitClient, 'Client must be called with new');
assert(!!config.key, 'An API key must be provided');
this.key = config.key;
this.key = config.key || process.env.CLEARBIT_KEY;
assert(!!this.key, 'An API key must be provided');
this.Company = require('./company').Company(this);
this.Person = require('./person').Person(this);
this.PersonCompany = require('./person').PersonCompany(this);
this.Company = require('./company')(this);
this.Watchlist = require('./watchlist').Watchlist(this);
this.WatchlistEntity = require('./watchlist').WatchlistEntity(this);
this.WatchlistIndividual = require('./watchlist').WatchlistIndividual(this);
}
var base = 'https://%s%s.clearbit.com/v%s';
ClearbitClient.prototype.base = function (options) {
var ENDPOINT = 'https://%s%s.clearbit.com/v%s';
ClearbitClient.prototype.endpoint = function (options) {
options = _.defaults(options, {

@@ -30,9 +35,11 @@ version: '1',

});
assert(options.api, 'An API must be specified');
return util.format.apply(util, [
base,
return util.format(
ENDPOINT,
options.api,
options.stream ? '-stream' : '',
options.version
]);
);
};

@@ -44,21 +51,14 @@

});
return this.base(options) + options.path;
return this.endpoint(options) + options.path;
};
function generateQuery () {
var query = _.omit(_.extend.apply(_, [{}].concat([].slice.apply(arguments))), _.isUndefined);
return _.isEmpty(query) ? undefined : query;
}
ClearbitClient.prototype.request = function (options) {
options = _.defaults(options, {
method: 'get',
query: {}
method: 'get'
});
return needle.requestAsync(
options.method,
this.url(options),
generateQuery({
webhook_id: options.webhook_id
}, options.query),
options.query,
{

@@ -65,0 +65,0 @@ timeout: options.stream ? 60000 : 10000,

@@ -7,17 +7,18 @@ 'use strict';

module.exports = resource.create('Company', {
api: 'company',
path: '/companies/domain/<%= domain %>'
})
.on('preFind', function (options) {
assert(options.domain, 'A domain must be provided');
}).include({
flag: function(params, options){
return this.client.request(_.extend({
api: this._options.api,
method: 'post',
path: _.template('/companies/<%= id %>/flag', this),
query: params || {}
}, options));
}
});
exports.Company = resource.create('Company', {api: 'company'})
.extend({
flag: function(options){
return this.constructor.post('/companies/' + this.id + '/flag', options);
}
},
{
find: function (options) {
options = options || {};
assert(options.domain, 'A domain must be provided');
return this.get(
'/companies/domain/' + options.domain,
_.omit(options, 'domain')
);
}
});

@@ -7,28 +7,31 @@ 'use strict';

function requireEmail (options) {
assert(options.email, 'An email must be provided');
}
exports.Person = resource.create('Person', {api: 'person'})
.extend({
flag: function(options){
return this.constructor.post('/people/' + this.id + '/flag', options);
}
},
{
find: function(options){
options = options || {};
assert(options.email, 'An email must be provided');
exports.Person = resource.create('Person', {
api: 'person',
path: '/people/email/<%= email %>',
queryKeys: 'subscribe'
})
.on('preFind', requireEmail)
.include({
flag: function(params, options){
return this.client.request(_.extend({
api: this._options.api,
method: 'post',
path: _.template('/people/<%= id %>/flag', this),
query: params || {}
}, options));
}
});
return this.get(
'/people/email/' + options.email,
_.omit(options, 'email')
);
}
});
exports.PersonCompany = resource.create('PersonCompany', {
api: 'person',
path: '/combined/email/<%= email %>',
queryKeys: 'subscribe'
})
.on('preFind', requireEmail);
exports.PersonCompany = resource.create('PersonCompany', {api: 'person'})
.extend(null, {
find: function(options){
options = options || {};
assert(options.email, 'An email must be provided');
return this.get(
'/combined/email/' + options.email,
_.omit(options, 'email')
);
}
});
'use strict';
var createError = require('create-error');
var EventEmitter = require('events').EventEmitter;
var _ = require('lodash');
var Promise = require('bluebird');
var createError = require('create-error');
var _ = require('lodash');
function isQueued (err) {
return err.type === 'queued';
}
function isUnknownRecord (err) {
return err.type === 'unknown_record';
}
function ClearbitResource (data) {

@@ -20,34 +10,35 @@ _.extend(this, data);

ClearbitResource.find = Promise.method(function (options) {
options = options || /* istanbul ignore next */ {};
this.emit('preFind', options);
return this.client.request(_.extend({
api: this._options.api,
path: this._options.template(options),
query: _.pick(options, this._options.queryKeys)
}, options))
.bind(this)
.then(function (data) {
return new this(
_.extend({}, data, {
_options: this._options,
client: this.client
})
);
})
.catch(isQueued, function () {
throw new this.QueuedError(this._name + ' lookup queued');
})
.catch(isUnknownRecord, function () {
throw new this.NotFoundError(this._name + ' not found');
});
});
ClearbitResource.get = function (path, options) {
options = _.extend({
path: path,
method: 'get',
query: extractParams(options)
}, this.options, options);
function createErrors (name) {
return {
NotFoundError: createError(name + 'NotFoundError'),
QueuedError: createError(name + 'QueuedError')
};
}
return this.client.request(options)
.bind(this)
.then(cast)
.catch(isQueued, function () {
throw new this.QueuedError(this.name + ' lookup queued');
})
.catch(isUnknownRecord, function () {
throw new this.NotFoundError(this.name + ' not found');
});
};
ClearbitResource.post = function (path, options) {
options = _.extend({
path: path,
method: 'post',
query: extractParams(options)
}, this.options, options);
return this.client.request(options)
.bind(this)
.then(cast)
.catch(isUnknownRecord, function () {
throw new this.NotFoundError(this.name + ' not found');
});
};
exports.create = function (name, options) {

@@ -58,7 +49,5 @@ var Resource = function () {

_.extend(Resource, new EventEmitter(), EventEmitter.prototype, ClearbitResource, createErrors(name), {
_name: name,
_options: _.extend({}, options, {
template: _.template(options.path)
})
_.extend(Resource, ClearbitResource, createErrors(name), {
name: name,
options: options
});

@@ -72,12 +61,39 @@

{
on: function () {
Resource.on.apply(Resource, arguments);
extend: function (proto, ctor) {
_.extend(Resource.prototype, proto);
_.extend(Resource, ctor);
return this;
},
include: function (props) {
_.extend(Resource.prototype, props);
return this;
}
});
};
function cast (data) {
/* jshint validthis:true */
return !Array.isArray(data) ? new this(data) : data.map(function (result) {
return new this(result);
}, this);
}
function isQueued (err) {
return err.type === 'queued';
}
function isUnknownRecord (err) {
return err.type === 'unknown_record';
}
function createErrors (name) {
return {
NotFoundError: createError(name + 'NotFoundError'),
QueuedError: createError(name + 'QueuedError')
};
}
function extractParams (options) {
var params = _.omit(options || {},
'path', 'method', 'params',
'client', 'api', 'stream'
);
return _.isEmpty(params) ? null : params;
}
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