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

familysearch

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

familysearch - npm Package Compare versions

Comparing version 0.0.5 to 1.0.0

96

lib/index.js

@@ -6,4 +6,7 @@

, error = debuggers('familysearch:error')
, perf = debuggers('familysearch:perf')
, requestlog = debuggers('familysearch:request')
, CACHE_ONLY = process.env.CACHE_ONLY
, utils = require('./utils');

@@ -25,7 +28,28 @@

this.queuing = {};
this.cache_queue = {}
this.getMeta();
};
var EXTRA_LINKS = {
"person-not-a-match-template" : {
"template" : "https://familysearch.org/platform/tree/persons/{pid}/not-a-match.json{?access_token}",
"type" : "application/atom+xml,application/json,application/x-gedcomx-atom+json,application/xml,text/html",
"accept" : "*/*",
"allow" : "GET",
"title" : "Person Not A Match"
},
}
function addExtraLinks(links) {
for (var name in EXTRA_LINKS) {
links[name] = EXTRA_LINKS[name]
}
}
FS.prototype = {
metaUrl: 'https://familysearch.org/.well-known/app-meta',
onDone: function (func) {
if (this.links !== null) return func()
this.ondone.push(func)
},
getMeta: function () {

@@ -46,2 +70,3 @@ var self = this;

self.links = res.body.links;
addExtraLinks(self.links)
debug('Got meta links', self.links.length);

@@ -67,5 +92,8 @@ for (var name in self.links) {

}
if (!this.links) {
return next(new Error("Links not fetched yet..."))
}
if (!this.links[endpoint]) {
error('Invalid endpoint', endpoint);
return next('Invalid endpoint');
return next('Invalid endpoint: ' + endpoint);
}

@@ -137,2 +165,68 @@ var url = this.links[endpoint].href || this.links[endpoint].url(options)

})
},
bouncy_cached: function (collection, options, done) {
var key = options.path + ' : ' + JSON.stringify(options.data) + ' : ' + options.token
if (this.cache_queue[key]) {
perf('bounce', key)
return this.cache_queue[key].push(done)
}
var queue = this.cache_queue[key] = [done]
, that = this
this.cached(collection, options, function (err, data) {
for (var i=0; i<queue.length; i++) {
queue[i](err, data)
}
delete that.cache_queue[key]
})
},
cached: function (collection, options, done) {
var endpoint = options.path
, post = options.data
, token = options.token
, newtime = options.newtime || 0
var that = this
, start = new Date()
function gotten(err, data, res) {
if (err) return done(err, data)
perf('Made request', endpoint, post, new Date().getTime() - start.getTime())
collection.update({
endpoint: endpoint,
post: post
}, {
endpoint: endpoint,
post: post,
data: data,
etag: res.header.etag,
time: new Date()
}, {upsert: true}, function () {
perf('Saved in cache', endpoint, post, new Date().getTime() - start.getTime())
done(err, data, res)
})
}
perf('looking for', endpoint, post, start)
collection.findOne({
endpoint: endpoint,
post: post
}, function (err, cached) {
if (err) {
console.error('Error getting cached')
return that.get(endpoint, post, token, gotten)
}
if (!cached) return that.get(endpoint, post, token, gotten)
var now = new Date().getTime()
// skip the api call
if (CACHE_ONLY || (now - cached.time.getTime())/1000 < newtime) {
perf('Skipping request, cache is new enough', endpoint, post, new Date().getTime() - start.getTime())
return done(null, cached.data, null)
}
that.get(endpoint, post, token, cached.etag, function (err, data, res) {
if (err) return done(err)
if (res.status === 304) {
perf('Cache hit from request', endpoint, post, new Date().getTime() - start.getTime())
return done(null, cached.data, res)
}
gotten(err, data, res)
})
})
}

@@ -139,0 +233,0 @@ };

2

package.json
{
"name": "familysearch",
"version": "0.0.5",
"version": "1.0.0",
"description": "FamilySearch API",

@@ -5,0 +5,0 @@ "main": "index.js",

Sorry, the diff of this file is not supported yet

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