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

fh-sync-js

Package Overview
Dependencies
Maintainers
3
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fh-sync-js - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

src/clientIdProvider.js

4

dist/fh-sync.min.js

@@ -1,2 +0,2 @@

!function(a){if("object"==typeof exports)module.exports=a();else if("function"==typeof define&&define.amd)define(a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.fhsync=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){(function(c){__browserify_shim_require__=a,function(a,b,c,d,e){var f=f||function(a,b){var c={},d=c.lib={},e=d.Base=function(){function a(){}return{extend:function(b){a.prototype=this;var c=new a;return b&&c.mixIn(b),c.hasOwnProperty("init")||(c.init=function(){c.$super.init.apply(this,arguments)}),c.init.prototype=c,c.$super=this,c},create:function(){var a=this.extend();return a.init.apply(a,arguments),a},init:function(){},mixIn:function(a){for(var b in a)a.hasOwnProperty(b)&&(this[b]=a[b]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),f=d.WordArray=e.extend({init:function(a,c){a=this.words=a||[],c!=b?this.sigBytes=c:this.sigBytes=4*a.length},toString:function(a){return(a||h).stringify(this)},concat:function(a){var b=this.words,c=a.words,d=this.sigBytes,e=a.sigBytes;if(this.clamp(),d%4)for(var f=0;e>f;f++){var g=c[f>>>2]>>>24-f%4*8&255;b[d+f>>>2]|=g<<24-(d+f)%4*8}else if(c.length>65535)for(var f=0;e>f;f+=4)b[d+f>>>2]=c[f>>>2];else b.push.apply(b,c);return this.sigBytes+=e,this},clamp:function(){var b=this.words,c=this.sigBytes;b[c>>>2]&=4294967295<<32-c%4*8,b.length=a.ceil(c/4)},clone:function(){var a=e.clone.call(this);return a.words=this.words.slice(0),a},random:function(b){for(var c=[],d=0;b>d;d+=4)c.push(4294967296*a.random()|0);return new f.init(c,b)}}),g=c.enc={},h=g.Hex={stringify:function(a){for(var b=a.words,c=a.sigBytes,d=[],e=0;c>e;e++){var f=b[e>>>2]>>>24-e%4*8&255;d.push((f>>>4).toString(16)),d.push((15&f).toString(16))}return d.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d+=2)c[d>>>3]|=parseInt(a.substr(d,2),16)<<24-d%8*4;return new f.init(c,b/2)}},i=g.Latin1={stringify:function(a){for(var b=a.words,c=a.sigBytes,d=[],e=0;c>e;e++){var f=b[e>>>2]>>>24-e%4*8&255;d.push(String.fromCharCode(f))}return d.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d++)c[d>>>2]|=(255&a.charCodeAt(d))<<24-d%4*8;return new f.init(c,b)}},j=g.Utf8={stringify:function(a){try{return decodeURIComponent(escape(i.stringify(a)))}catch(b){throw new Error("Malformed UTF-8 data")}},parse:function(a){return i.parse(unescape(encodeURIComponent(a)))}},k=d.BufferedBlockAlgorithm=e.extend({reset:function(){this._data=new f.init,this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=j.parse(a)),this._data.concat(a),this._nDataBytes+=a.sigBytes},_process:function(b){var c=this._data,d=c.words,e=c.sigBytes,g=this.blockSize,h=4*g,i=e/h;i=b?a.ceil(i):a.max((0|i)-this._minBufferSize,0);var j=i*g,k=a.min(4*j,e);if(j){for(var l=0;j>l;l+=g)this._doProcessBlock(d,l);var m=d.splice(0,j);c.sigBytes-=k}return new f.init(m,k)},clone:function(){var a=e.clone.call(this);return a._data=this._data.clone(),a},_minBufferSize:0}),l=(d.Hasher=k.extend({cfg:e.extend(),init:function(a){this.cfg=this.cfg.extend(a),this.reset()},reset:function(){k.reset.call(this),this._doReset()},update:function(a){return this._append(a),this._process(),this},finalize:function(a){a&&this._append(a);var b=this._doFinalize();return b},blockSize:16,_createHelper:function(a){return function(b,c){return new a.init(c).finalize(b)}},_createHmacHelper:function(a){return function(b,c){return new l.HMAC.init(a,c).finalize(b)}}}),c.algo={});return c}(Math);f.lib.Cipher||function(a){var b=f,c=b.lib,d=c.Base,e=c.WordArray,g=c.BufferedBlockAlgorithm,h=b.enc,i=(h.Utf8,h.Base64),j=b.algo,k=j.EvpKDF,l=c.Cipher=g.extend({cfg:d.extend(),createEncryptor:function(a,b){return this.create(this._ENC_XFORM_MODE,a,b)},createDecryptor:function(a,b){return this.create(this._DEC_XFORM_MODE,a,b)},init:function(a,b,c){this.cfg=this.cfg.extend(c),this._xformMode=a,this._key=b,this.reset()},reset:function(){g.reset.call(this),this._doReset()},process:function(a){return this._append(a),this._process()},finalize:function(a){a&&this._append(a);var b=this._doFinalize();return b},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function a(a){return"string"==typeof a?x:u}return function(b){return{encrypt:function(c,d,e){return a(d).encrypt(b,c,d,e)},decrypt:function(c,d,e){return a(d).decrypt(b,c,d,e)}}}}()}),m=(c.StreamCipher=l.extend({_doFinalize:function(){var a=this._process(!0);return a},blockSize:1}),b.mode={}),n=c.BlockCipherMode=d.extend({createEncryptor:function(a,b){return this.Encryptor.create(a,b)},createDecryptor:function(a,b){return this.Decryptor.create(a,b)},init:function(a,b){this._cipher=a,this._iv=b}}),o=m.CBC=function(){function b(b,c,d){var e=this._iv;if(e){var f=e;this._iv=a}else var f=this._prevBlock;for(var g=0;d>g;g++)b[c+g]^=f[g]}var c=n.extend();return c.Encryptor=c.extend({processBlock:function(a,c){var d=this._cipher,e=d.blockSize;b.call(this,a,c,e),d.encryptBlock(a,c),this._prevBlock=a.slice(c,c+e)}}),c.Decryptor=c.extend({processBlock:function(a,c){var d=this._cipher,e=d.blockSize,f=a.slice(c,c+e);d.decryptBlock(a,c),b.call(this,a,c,e),this._prevBlock=f}}),c}(),p=b.pad={},q=p.Pkcs7={pad:function(a,b){for(var c=4*b,d=c-a.sigBytes%c,f=d<<24|d<<16|d<<8|d,g=[],h=0;d>h;h+=4)g.push(f);var i=e.create(g,d);a.concat(i)},unpad:function(a){var b=255&a.words[a.sigBytes-1>>>2];a.sigBytes-=b}},r=(c.BlockCipher=l.extend({cfg:l.cfg.extend({mode:o,padding:q}),reset:function(){l.reset.call(this);var a=this.cfg,b=a.iv,c=a.mode;if(this._xformMode==this._ENC_XFORM_MODE)var d=c.createEncryptor;else{var d=c.createDecryptor;this._minBufferSize=1}this._mode=d.call(c,this,b&&b.words)},_doProcessBlock:function(a,b){this._mode.processBlock(a,b)},_doFinalize:function(){var a=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){a.pad(this._data,this.blockSize);var b=this._process(!0)}else{var b=this._process(!0);a.unpad(b)}return b},blockSize:4}),c.CipherParams=d.extend({init:function(a){this.mixIn(a)},toString:function(a){return(a||this.formatter).stringify(this)}})),s=b.format={},t=s.OpenSSL={stringify:function(a){var b=a.ciphertext,c=a.salt;if(c)var d=e.create([1398893684,1701076831]).concat(c).concat(b);else var d=b;return d.toString(i)},parse:function(a){var b=i.parse(a),c=b.words;if(1398893684==c[0]&&1701076831==c[1]){var d=e.create(c.slice(2,4));c.splice(0,4),b.sigBytes-=16}return r.create({ciphertext:b,salt:d})}},u=c.SerializableCipher=d.extend({cfg:d.extend({format:t}),encrypt:function(a,b,c,d){d=this.cfg.extend(d);var e=a.createEncryptor(c,d),f=e.finalize(b),g=e.cfg;return r.create({ciphertext:f,key:c,iv:g.iv,algorithm:a,mode:g.mode,padding:g.padding,blockSize:a.blockSize,formatter:d.format})},decrypt:function(a,b,c,d){d=this.cfg.extend(d),b=this._parse(b,d.format);var e=a.createDecryptor(c,d).finalize(b.ciphertext);return e},_parse:function(a,b){return"string"==typeof a?b.parse(a,this):a}}),v=b.kdf={},w=v.OpenSSL={execute:function(a,b,c,d){d||(d=e.random(8));var f=k.create({keySize:b+c}).compute(a,d),g=e.create(f.words.slice(b),4*c);return f.sigBytes=4*b,r.create({key:f,iv:g,salt:d})}},x=c.PasswordBasedCipher=u.extend({cfg:u.cfg.extend({kdf:w}),encrypt:function(a,b,c,d){d=this.cfg.extend(d);var e=d.kdf.execute(c,a.keySize,a.ivSize);d.iv=e.iv;var f=u.encrypt.call(this,a,b,e.key,d);return f.mixIn(e),f},decrypt:function(a,b,c,d){d=this.cfg.extend(d),b=this._parse(b,d.format);var e=d.kdf.execute(c,a.keySize,a.ivSize,b.salt);d.iv=e.iv;var f=u.decrypt.call(this,a,b,e.key,d);return f}})}(),function(){var a=f,b=a.lib,c=b.WordArray,d=b.Hasher,e=a.algo,g=[],h=e.SHA1=d.extend({_doReset:function(){this._hash=new c.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(a,b){for(var c=this._hash.words,d=c[0],e=c[1],f=c[2],h=c[3],i=c[4],j=0;80>j;j++){if(16>j)g[j]=0|a[b+j];else{var k=g[j-3]^g[j-8]^g[j-14]^g[j-16];g[j]=k<<1|k>>>31}var l=(d<<5|d>>>27)+i+g[j];l+=20>j?(e&f|~e&h)+1518500249:40>j?(e^f^h)+1859775393:60>j?(e&f|e&h|f&h)-1894007588:(e^f^h)-899497514,i=h,h=f,f=e<<30|e>>>2,e=d,d=l}c[0]=c[0]+d|0,c[1]=c[1]+e|0,c[2]=c[2]+f|0,c[3]=c[3]+h|0,c[4]=c[4]+i|0},_doFinalize:function(){var a=this._data,b=a.words,c=8*this._nDataBytes,d=8*a.sigBytes;return b[d>>>5]|=128<<24-d%32,b[(d+64>>>9<<4)+14]=Math.floor(c/4294967296),b[(d+64>>>9<<4)+15]=c,a.sigBytes=4*b.length,this._process(),this._hash},clone:function(){var a=d.clone.call(this);return a._hash=this._hash.clone(),a}});a.SHA1=d._createHelper(h),a.HmacSHA1=d._createHmacHelper(h)}(),function(a){var b=f,c=b.lib,d=c.Base,e=c.WordArray,g=b.x64={};g.Word=d.extend({init:function(a,b){this.high=a,this.low=b}}),g.WordArray=d.extend({init:function(b,c){b=this.words=b||[],c!=a?this.sigBytes=c:this.sigBytes=8*b.length},toX32:function(){for(var a=this.words,b=a.length,c=[],d=0;b>d;d++){var f=a[d];c.push(f.high),c.push(f.low)}return e.create(c,this.sigBytes)},clone:function(){for(var a=d.clone.call(this),b=a.words=this.words.slice(0),c=b.length,e=0;c>e;e++)b[e]=b[e].clone();return a}})}(),e("undefined"!=typeof f?f:window.CryptoJS)}.call(c,void 0,void 0,void 0,void 0,function(a){b.exports=a})}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(a,b,c){(function(c){__browserify_shim_require__=a,function(a,b,c,d,e){var f=function(a,b){if(!(this instanceof f))return new f(a,b);if(!JSON)throw"JSON unavailable! Include http://www.json.org/json2.js to fix.";if(!(arguments.length<=2&&arguments.length>0))throw"Incorrect # of ctor args!";if(b="function"==typeof arguments[0]?arguments[0]:arguments[1],a="function"==typeof arguments[0]?{}:arguments[0],"function"!=typeof b)throw"No callback was provided";this.record=a.record||"record",this.name=a.name||"records";var c;if(a.adapter){"string"==typeof a.adapter&&(a.adapter=[a.adapter]);for(var d=0,e=a.adapter.length;e>d;d++){for(var g=f.adapters.length-1;g>=0&&(f.adapters[g].adapter!==a.adapter[d]||!(c=f.adapters[g].valid()?f.adapters[g]:void 0));g--);if(c)break}}else for(var g=0,h=f.adapters.length;h>g&&!(c=f.adapters[g].valid()?f.adapters[g]:void 0);g++);if(!c)throw"No valid adapter.";for(var d in c)this[d]=c[d];for(var g=0,h=f.plugins.length;h>g;g++)f.plugins[g].call(this);this.init(a,b)};f.adapters=[],f.adapter=function(a,b){b.adapter=a;var c="adapter valid init keys save batch get exists all remove nuke".split(" "),d=this.prototype.indexOf;for(var e in b)if(-1===d(c,e))throw"Invalid adapter! Nonstandard method: "+e;f.adapters.splice(0,0,b)},f.plugins=[],f.plugin=function(a){for(var b in a)"init"===b?f.plugins.push(a[b]):this.prototype[b]=a[b]},f.prototype={isArray:Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},indexOf:function(a,b,c,d){if(a.indexOf)return a.indexOf(b);for(c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},lambda:function(a){return this.fn(this.record,a)},fn:function(a,b){return"string"==typeof b?new Function(a,b):b},uuid:function(){var a=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)};return a()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a()},each:function(a){var b=this.lambda(a);if(this.__results)for(var c=0,d=this.__results.length;d>c;c++)b.call(this,this.__results[c],c);else this.all(function(a){for(var c=0,d=a.length;d>c;c++)b.call(this,a[c],c)});return this}},f.adapter("window-name",function(){"undefined"==typeof window&&(window={top:{}});var a={};try{a=JSON.parse(window.top.name)}catch(b){}return{valid:function(){return"undefined"!=typeof window.top.name},init:function(b,c){return a[this.name]=a[this.name]||{index:[],store:{}},this.index=a[this.name].index,this.store=a[this.name].store,this.fn(this.name,c).call(this,this),this},keys:function(a){return this.fn("keys",a).call(this,this.index),this},save:function(b,c){var d=b.key||this.uuid();return this.exists(d,function(e){e||(b.key&&delete b.key,this.index.push(d)),this.store[d]=b;try{window.top.name=JSON.stringify(a)}catch(f){throw e||(this.index.pop(),delete this.store[d]),f}c&&(b.key=d,this.lambda(c).call(this,b))}),this},batch:function(a,b){for(var c=[],d=0,e=a.length;e>d;d++)this.save(a[d],function(a){c.push(a)});return b&&this.lambda(b).call(this,c),this},get:function(a,b){var c;if(this.isArray(a)){c=[];for(var d=0,e=a.length;e>d;d++)c.push(this.store[a[d]])}else c=this.store[a],c&&(c.key=a);return b&&this.lambda(b).call(this,c),this},exists:function(a,b){return this.lambda(b).call(this,!!this.store[a]),this},all:function(a){for(var b=[],c=0,d=this.index.length;d>c;c++){var e=this.store[this.index[c]];e.key=this.index[c],b.push(e)}return this.fn(this.name,a).call(this,b),this},remove:function(b,c){for(var d=this.isArray(b)?b:[b],e=0,f=d.length;f>e;e++){var g=d[e].key?d[e].key:d[e],h=this.indexOf(this.index,g);0>h||(delete this.store[g],this.index.splice(h,1))}return window.top.name=JSON.stringify(a),c&&this.lambda(c).call(this),this},nuke:function(b){return this.store=a[this.name].store={},this.index=a[this.name].index=[],window.top.name=JSON.stringify(a),b&&this.lambda(b).call(this),this}}}()),f.adapter("dom",function(){var a=null;try{a=window.localStorage}catch(b){}var c=function(b){return{key:b+"._index_",all:function(){var b=a.getItem(this.key);return b&&(b=JSON.parse(b)),null===b&&a.setItem(this.key,JSON.stringify([])),JSON.parse(a.getItem(this.key))},add:function(b){var c=this.all();c.push(b),a.setItem(this.key,JSON.stringify(c))},del:function(b){for(var c=this.all(),d=[],e=0,f=c.length;f>e;e++)c[e]!=b&&d.push(c[e]);a.setItem(this.key,JSON.stringify(d))},find:function(a){for(var b=this.all(),c=0,d=b.length;d>c;c++)if(a===b[c])return c;return!1}}};return{valid:function(){return!!a&&function(){var b=!0,c=Math.random();try{a.setItem(c,c)}catch(d){b=!1}return a.removeItem(c),b}()},init:function(a,b){this.indexer=c(this.name),b&&this.fn(this.name,b).call(this,this)},save:function(b,c){var d=b.key?this.name+"."+b.key:this.name+"."+this.uuid();return delete b.key,a.setItem(d,JSON.stringify(b)),this.indexer.find(d)===!1&&this.indexer.add(d),b.key=d.slice(this.name.length+1),c&&this.lambda(c).call(this,b),this},batch:function(a,b){for(var c=[],d=0,e=a.length;e>d;d++)this.save(a[d],function(a){c.push(a)});return b&&this.lambda(b).call(this,c),this},keys:function(a){if(a){var b=this.name,c=this.indexer.all(),d=[];if(Array.prototype.map)d=c.map(function(a){return a.replace(b+".","")});else for(var e in c)d.push(e.replace(b+".",""));this.fn("keys",a).call(this,d)}return this},get:function(b,c){if(this.isArray(b)){for(var d=[],e=0,f=b.length;f>e;e++){var g=this.name+"."+b[e],h=a.getItem(g);h&&(h=JSON.parse(h),h.key=b[e]),d.push(h)}c&&this.lambda(c).call(this,d)}else{var g=this.name+"."+b,h=a.getItem(g);h&&(h=JSON.parse(h),h.key=b),c&&this.lambda(c).call(this,h)}return this},exists:function(a,b){var c=this.indexer.find(this.name+"."+a)===!1?!1:!0;return this.lambda(b).call(this,c),this},all:function(b){for(var c,d,e=this.indexer.all(),f=[],g=0,h=e.length;h>g;g++)d=e[g],c=JSON.parse(a.getItem(d)),c.key=d.replace(this.name+".",""),f.push(c);return b&&this.fn(this.name,b).call(this,f),this},remove:function(b,c){var d=this;if(this.isArray(b)){var e,f=b.length,g=function(a){d.remove(b[a],function(){--f>0||c&&d.lambda(c).call(d)})};for(e=0;e<b.length;e++)g(e);return this}var h=this.name+"."+(b.key?b.key:b);return this.indexer.del(h),a.removeItem(h),c&&this.lambda(c).call(this),this},nuke:function(a){return this.all(function(b){for(var c=0,d=b.length;d>c;c++)this.remove(b[c]);a&&this.lambda(a).call(this)}),this}}}()),f.adapter("webkit-sqlite",function(){var a=function(a,b){console&&console.log("error in sqlite adaptor!",a,b)},b=function(){return new Date};return{valid:function(){return!!window.openDatabase},init:function(b,c){var d=this,e=d.fn(d.name,c),f="CREATE TABLE IF NOT EXISTS "+this.record+" (id NVARCHAR(32) UNIQUE PRIMARY KEY, value TEXT, timestamp REAL)",g=function(){return e.call(d,d)};b&&"function"==typeof b.fail&&(a=b.fail),this.db=openDatabase(this.name,"1.0.0",this.name,65536),this.db.transaction(function(b){b.executeSql(f,[],g,a)})},keys:function(b){var c=this.lambda(b),d=this,e="SELECT id FROM "+this.record+" ORDER BY timestamp DESC";return this.db.readTransaction(function(b){var f=function(a,b){if(0==b.rows.length)c.call(d,[]);else{for(var e=[],f=0,g=b.rows.length;g>f;f++)e.push(b.rows.item(f).id);c.call(d,e)}};b.executeSql(e,[],f,a)}),this},save:function(c,d,e){var f=this;objs=(this.isArray(c)?c:[c]).map(function(a){return a.key||(a.key=f.uuid()),a}),ins="INSERT OR REPLACE INTO "+this.record+" (value, timestamp, id) VALUES (?,?,?)",win=function(){d&&f.lambda(d).call(f,f.isArray(c)?objs:objs[0])},e=e||function(){},insvals=[],ts=b();try{for(var g=0,h=objs.length;h>g;g++)insvals[g]=[JSON.stringify(objs[g]),ts,objs[g].key]}catch(i){throw a(i),i}return f.db.transaction(function(a){for(var b=0,c=objs.length;c>b;b++)a.executeSql(ins,insvals[b])},function(b,c){a(b,c)},win),this},batch:function(a,b){return this.save(a,b)},get:function(b,c){var d=this,e="",f=this.isArray(b)?b:[b];e="SELECT id, value FROM "+this.record+" WHERE id IN ("+f.map(function(){return"?"}).join(",")+")";var g=function(a,e){for(var g,h,i={},j=0,k=e.rows.length;k>j;j++)g=JSON.parse(e.rows.item(j).value),g.key=e.rows.item(j).id,i[g.key]=g;h=f.map(function(a){return i[a]}),d.isArray(b)||(h=h.length?h[0]:null),c&&d.lambda(c).call(d,h)};return this.db.readTransaction(function(b){b.executeSql(e,f,g,a)}),this},exists:function(b,c){var d="SELECT * FROM "+this.record+" WHERE id = ?",e=this,f=function(a,b){c&&e.fn("exists",c).call(e,b.rows.length>0)};return this.db.readTransaction(function(c){c.executeSql(d,[b],f,a)}),this},all:function(b){var c=this,d="SELECT * FROM "+this.record,e=[],f=this.fn(this.name,b)||void 0,g=function(a,b){if(0!=b.rows.length)for(var d=0,g=b.rows.length;g>d;d++){var h=JSON.parse(b.rows.item(d).value);h.key=b.rows.item(d).id,e.push(h)}f&&f.call(c,e)};return this.db.readTransaction(function(b){b.executeSql(d,[],g,a)}),this},remove:function(b,c){var d,e=this,f="DELETE FROM "+this.record+" WHERE id ",g=function(){c&&e.lambda(c).call(e)};return this.isArray(b)?(d=b,f+="IN ("+d.map(function(){return"?"}).join(",")+")"):(f+="= ?",d=[b]),d=d.map(function(a){return a.key?a.key:a}),this.db.transaction(function(b){b.executeSql(f,d,g,a)}),this},nuke:function(b){var c="DELETE FROM "+this.record,d=this,e=b?function(){d.lambda(b).call(d)}:function(){};return this.db.transaction(function(b){b.executeSql(c,[],e,a)}),this}}}()),f.adapter("indexed-db",function(){function a(a,b){console&&console.log("error in indexed-db adapter!"+a.message,a,b)}function b(){return window.indexedDB||window.webkitIndexedDB||window.mozIndexedDB||window.oIndexedDB||window.msIndexedDB}return{valid:function(){return!!b()},init:function(c,d){this.idb=b(),this.waiting=[];var e=this.idb.open(this.name,2),f=this,g=f.fn(f.name,d),h=function(){return g.call(f,f)};c&&"function"==typeof c.fail&&(a=c.fail),e.onupgradeneeded=function(a){f.store=e.result.createObjectStore("teststore",{autoIncrement:!0});for(var b=0;b<f.waiting.length;b++)f.waiting[b].call(f);f.waiting=[],h()},e.onsuccess=function(b){if(f.db=e.result,"2.0"!=f.db.version){if("function"==typeof f.db.setVersion){var c=f.db.setVersion("2.0");c.onsuccess=function(a){f.store=f.db.createObjectStore("teststore",{autoIncrement:!0});for(var b=0;b<f.waiting.length;b++)f.waiting[b].call(f);f.waiting=[],h()},c.onerror=function(b){a(b)}}}else{f.store={};for(var d=0;d<f.waiting.length;d++)f.waiting[d].call(f);f.waiting=[],h()}},e.onerror=a},save:function(b,c){if(!this.store)return void this.waiting.push(function(){this.save(b,c)});var d=this,e=function(a){c&&(b.key=a.target.result,d.lambda(c).call(d,b))},f="readwrite",g=this.db.transaction(["teststore"],f),h=g.objectStore("teststore"),i=b.key?h.put(b,b.key):h.put(b);return i.onsuccess=e,i.onerror=a,this},batch:function(a,b){for(var c=[],d=!1,e=this,f=function(b){c.push(b),d=c.length===a.length},g=setInterval(function(){d&&(b&&e.lambda(b).call(e,c),clearInterval(g))},200),h=0,i=a.length;i>h;h++)this.save(a[h],f);return this},get:function(b,c){if(!this.store||!this.db)return void this.waiting.push(function(){this.get(b,c)});var d=this,e=function(a){c&&d.lambda(c).call(d,a.target.result)};if(this.isArray(b))for(var f=[],g=!1,h=b,i=function(a){f.push(a),g=f.length===h.length},j=setInterval(function(){g&&(c&&d.lambda(c).call(d,f),clearInterval(j))},200),k=0,l=h.length;l>k;k++)this.get(h[k],i);else{var m=this.db.transaction("teststore").objectStore("teststore").get(b);m.onsuccess=e,m.onerror=function(b){a(b)}}return this},all:function(a){if(!this.store)return void this.waiting.push(function(){this.all(a)});var b=this.fn(this.name,a)||void 0,c=this,d=this.db.transaction("teststore").objectStore("teststore"),e=[];return d.openCursor().onsuccess=function(a){var d=a.target.result;d?(e.push(d.value),d["continue"]()):b&&b.call(c,e)},this},remove:function(b,c){if(!this.store)return void this.waiting.push(function(){this.remove(b,c)});"object"==typeof b&&(b=b.key);var d=this,e=function(){c&&d.lambda(c).call(d)},f=this.db.transaction(["teststore"],"readwrite").objectStore("teststore")["delete"](b);return f.onsuccess=e,f.onerror=a,this},nuke:function(b){if(!this.store)return void this.waiting.push(function(){this.nuke(b)});var c=this,d=b?function(){c.lambda(b).call(c)}:function(){};try{this.db.transaction(["teststore"],"readwrite").objectStore("teststore").clear().onsuccess=d}catch(e){a()}return this}}}()),f.adapter("html5-filesystem",function(a){var b=function(a){console&&console.error(a,a.name)},c=function(a,d,e){var f=e||[];a.readEntries(function(b){b.length?c(a,d,f.concat(Array.prototype.slice.call(b))):d&&d(f.map(function(a){return a.name}))},b)},d={},e=function(a,b){var c=d[a.name];c?b(c):setTimeout(function(){e(a,b)},10)},f=function(){var a=-1===document.URL.indexOf("http://")&&-1===document.URL.indexOf("https://");return a?!0:!1},g=function(a){var b;if(f())b=a;else{var c="application/json";try{b=new Blob([a],{type:c})}catch(d){var e=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder;if("TypeError"==d.name&&e){var g=new e;g.append([a.buffer]),b=g.getBlob(c)}else b=a}}return b};return{valid:function(){var b=a.requestFileSystem||a.webkitRequestFileSystem||a.moz_requestFileSystem;return!!b},init:function(c,e){function f(b){var c=a.requestFileSystem||a.webkitRequestFileSystem||a.moz_requestFileSystem,f=window.PERSISTENT;"undefined"!=typeof LocalFileSystem&&"undefined"!=typeof LocalFileSystem.PERSISTENT&&(f=LocalFileSystem.PERSISTENT),c(f,b,function(a){a.root.getDirectory(j,{create:!0},function(a){d[j]=a,e&&g.fn(g.name,e).call(g,g)},function(a){h(a)})},function(a){h(a)})}var g=this,h=function(a){b(a),e&&g.fn(g.name,e).call(g,g)},i=c.size||104857600,j=this.name;g.backup=!1,"undefined"!=typeof c.backup&&(g.backup=c.backup),"undefined"!=typeof navigator.webkitPersistentStorage?navigator.webkitPersistentStorage.requestQuota(i,f,function(){logger.warn("User declined file storage"),h("User declined file storage")}):f(0)},keys:function(a){var b=this;return e(this,function(d){c(d.createReader(),function(c){a&&b.fn("keys",a).call(b,c)})}),this},save:function(a,c){var d=this,f=a.key||this.uuid();a.key=f;var h=function(a){b(a),c&&d.lambda(c).call(d)};return e(this,function(b){var e=function(b,e){b.createWriter(function(b){b.onerror=e,b.onwriteend=function(){this.onwriteend=null,this.truncate(this.position),c&&d.lambda(c).call(d,a)};var f=JSON.stringify(a),h=g(f);b.write(h)},e)};b.getFile(f,{create:!0},function(a){"function"!=typeof a.setMetadata||d.backup!==!1&&"false"!==d.backup?e(a,h):a.setMetadata(function(){e(a,h)},function(){e(a,h)},{"com.apple.MobileBackup":1})},h)}),this},batch:function(a,b){for(var c=this,d=[],e=0,f=a.length;f>e;e++)c.save(a[e],function(a){d.push(a),d.length===f&&b&&c.lambda(b).call(c,d)});return this},get:function(a,c){var d=this;if(this.isArray(a))for(var f=[],g=0,h=a.length;h>g;g++)d.get(a[g],function(a){a&&f.push(a),f.length===h&&c&&d.lambda(c).call(d,f)});else{var i=function(a){b(a),c&&d.lambda(c).call(d)};e(this,function(b){b.getFile(a,{create:!1},function(b){b.file(function(b){var e=new FileReader;e.onerror=i,e.onload=function(b){var e={};try{e=JSON.parse(b.target.result),e.key=a}catch(b){e={key:a}}c&&d.lambda(c).call(d,e)},e.readAsText(b)},i)},i)})}return this},exists:function(a,b){var c=this;return e(this,function(d){d.getFile(a,{create:!1},function(){b&&c.lambda(b).call(c,!0)},function(){b&&c.lambda(b).call(c,!1)})}),this},all:function(a){var b=this;return a&&this.keys(function(c){c.length?b.get(c,function(c){b.fn(b.name,a).call(b,c)}):b.fn(b.name,a).call(b,[])}),this},remove:function(a,c){var d=this,f=function(a){b(a),c&&d.lambda(c).call(d)};return e(this,function(b){b.getFile("string"==typeof a?a:a.key,{create:!1},function(a){a.remove(function(){c&&d.lambda(c).call(d)},f)},f)}),this},nuke:function(a){var b=this,c=0;return this.keys(function(d){if(d.length)for(var e=0,f=d.length;f>e;e++)b.remove(d[e],function(){c++,c===f&&a&&b.lambda(a).call(b)});else a&&b.lambda(a).call(b)}),this}}}(this)),f.adapter("memory",function(){var a={};return{valid:function(){return!0},init:function(b,c){a[this.name]=a[this.name]||{index:[],store:{}},this.index=a[this.name].index,this.store=a[this.name].store;var d=this.fn(this.name,c);return d&&d.call(this,this),this},keys:function(a){return this.fn("keys",a).call(this,this.index),this},save:function(a,b){var c=a.key||this.uuid();return this.exists(c,function(d){d||(a.key&&delete a.key,this.index.push(c)),this.store[c]=a,b&&(a.key=c,this.lambda(b).call(this,a))}),this},batch:function(a,b){for(var c=[],d=0,e=a.length;e>d;d++)this.save(a[d],function(a){c.push(a)});return b&&this.lambda(b).call(this,c),this},get:function(a,b){var c;if(this.isArray(a)){c=[];for(var d=0,e=a.length;e>d;d++)c.push(this.store[a[d]])}else c=this.store[a],c&&(c.key=a);return b&&this.lambda(b).call(this,c),this},exists:function(a,b){return this.lambda(b).call(this,!!this.store[a]),this},all:function(a){for(var b=[],c=0,d=this.index.length;d>c;c++){var e=this.store[this.index[c]];e.key=this.index[c],b.push(e)}return this.fn(this.name,a).call(this,b),this},remove:function(a,b){for(var c=this.isArray(a)?a:[a],d=0,e=c.length;e>d;d++){var f=c[d].key?c[d].key:c[d],g=this.indexOf(this.index,f);0>g||(delete this.store[f],this.index.splice(g,1))}return b&&this.lambda(b).call(this),this},nuke:function(b){return this.store=a[this.name].store={},this.index=a[this.name].index=[],b&&this.lambda(b).call(this),this}}}()),e("undefined"!=typeof f?f:window.Lawnchair)}.call(c,void 0,void 0,void 0,void 0,function(a){b.exports=a})}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],3:[function(a,b,c){var d,e,f=function(a,b,c){e||(e="/sync/");var f=d+e+a.dataset_id,g=JSON.stringify(a.req),h=new XMLHttpRequest;h.open("POST",f,!0),h.setRequestHeader("Content-type","application/json; charset=utf-8"),h.onreadystatechange=function(){if(h.readyState===XMLHttpRequest.DONE)if(h.status>=200&&h.status<300||304===h.status){var a;try{h.responseText&&(a=JSON.parse(h.responseText))}catch(d){return c(d)}b(a)}else c(h.responseText)},h.send(g)},g=function(a,b){d=a,e=b};b.exports={handler:f,init:g}},{}],4:[function(a,b,c){var d=a("./sync-client"),e=window.$fh=window.$fh||{};e.sync=d},{"./sync-client":5}],5:[function(a,b,c){var d=a("../libs/generated/crypto"),e=a("../libs/generated/lawnchair"),f=a("./cloudHandler"),g={defaults:{sync_frequency:10,auto_sync_local_updates:!0,notify_client_storage_failed:!0,notify_sync_started:!0,notify_sync_complete:!0,notify_offline_update:!0,notify_collision_detected:!0,notify_remote_update_failed:!0,notify_local_update_applied:!0,notify_remote_update_applied:!0,notify_delta_received:!0,notify_record_delta_received:!0,notify_sync_failed:!0,do_console_log:!1,crashed_count_wait:10,resend_crashed_updates:!0,sync_active:!0,storage_strategy:"html5-filesystem",file_system_quota:61644800,icloud_backup:!1},notifications:{CLIENT_STORAGE_FAILED:"client_storage_failed",SYNC_STARTED:"sync_started",SYNC_COMPLETE:"sync_complete",OFFLINE_UPDATE:"offline_update",COLLISION_DETECTED:"collision_detected",REMOTE_UPDATE_FAILED:"remote_update_failed",REMOTE_UPDATE_APPLIED:"remote_update_applied",LOCAL_UPDATE_APPLIED:"local_update_applied",DELTA_RECEIVED:"delta_received",RECORD_DELTA_RECEIVED:"record_delta_received",SYNC_FAILED:"sync_failed"},datasets:{},config:void 0,notify_callback:void 0,notify_callback_map:{},init_is_called:!1,uid_map:{},init:function(a){g.consoleLog("sync - init called"),g.config=JSON.parse(JSON.stringify(g.defaults));for(var b in a)g.config[b]=a[b];g.init_is_called||(g.init_is_called=!0,g.datasetMonitor()),f.init(g.config.cloudUrl,g.config.cloudPath)},notify:function(a,b){1===arguments.length&&"function"==typeof a?g.notify_callback=a:g.notify_callback_map[a]=b},manage:function(a,b,c,d,e){g.consoleLog("manage - START"),g.config||(g.config=JSON.parse(JSON.stringify(g.defaults)));var f=b||{},h=function(b){g.consoleLog("doManage dataset :: initialised = "+b.initialised+" :: "+a+" :: "+JSON.stringify(f));var h=b.config?b.config:g.config,i=g.setOptions(h,f);b.query_params=c||b.query_params||{},b.meta_data=d||b.meta_data||{},b.config=i,b.syncRunning=!1,b.syncPending=!0,b.initialised=!0,"undefined"==typeof b.meta&&(b.meta={}),g.saveDataSet(a,function(){e&&e()})};g.getDataSet(a,function(a){g.consoleLog("manage - dataset already loaded"),h(a)},function(b){g.consoleLog("manage - dataset not loaded... trying to load"),g.loadDataSet(a,function(b){g.consoleLog("manage - dataset loaded from local storage"),g.doNotify(a,null,g.notifications.LOCAL_UPDATE_APPLIED,"load"),h(b)},function(b){g.consoleLog("manage - Creating new dataset for id "+a);var c={};c.data={},c.pending={},c.meta={},g.datasets[a]=c,h(c)})})},setOptions:function(a,b){a||(a=JSON.parse(JSON.stringify(g.defaults)));var c=JSON.parse(JSON.stringify(a)),d=JSON.parse(JSON.stringify(b));for(var e in d)c[e]=d[e];return c},list:function(a,b,c){g.getDataSet(a,function(a){if(a&&a.data){var d=JSON.parse(JSON.stringify(a.data));b(d)}else c&&c("no_data")},function(a,b){c&&c(a,b)})},getUID:function(a){var b=g.uid_map[a];return b||0===b?b:a},create:function(a,b,c,d){return null==b&&d?d("null_data"):void g.addPendingObj(a,null,b,"create",c,d)},read:function(a,b,c,d){g.getDataSet(a,function(a){b=g.getUID(b);var e=a.data[b];if(e){var f=JSON.parse(JSON.stringify(e));c(f)}else d("unknown_uid")},function(a,b){d&&d(a,b)})},update:function(a,b,c,d,e){b=g.getUID(b),g.addPendingObj(a,b,c,"update",d,e)},"delete":function(a,b,c,d){b=g.getUID(b),g.addPendingObj(a,b,null,"delete",c,d)},getPending:function(a,b){g.getDataSet(a,function(a){var c;a&&(c=a.pending),b(c)},function(a,b){g.consoleLog(a)})},clearPending:function(a,b){g.getDataSet(a,function(c){c.pending={},g.saveDataSet(a,b)})},listCollisions:function(a,b,c){g.getDataSet(a,function(d){g.doCloudCall({dataset_id:a,req:{fn:"listCollisions",meta_data:d.meta_data}},b,c)},c)},removeCollision:function(a,b,c,d){g.getDataSet(a,function(e){g.doCloudCall({dataset_id:a,req:{fn:"removeCollision",hash:b,meta_data:e.meta_data}},c,d)})},isOnline:function(a){var b=!0;if("undefined"!=typeof navigator.onLine&&(b=navigator.onLine),b&&"undefined"!=typeof navigator.network&&"undefined"!=typeof navigator.network.connection){var c=navigator.network.connection.type;("none"===c||null===c)&&(b=!1)}return a(b)},doNotify:function(a,b,c,d){if(g.notify_callback||g.notify_callback_map[a]){var e=g.notify_callback_map[a]||g.notify_callback;if(g.config["notify_"+c]){var f={dataset_id:a,uid:b,code:c,message:d};setTimeout(function(){e(f)},0);
}}},getDataSet:function(a,b,c){var d=g.datasets[a];d?b(d):c&&c("unknown_dataset "+a,a)},getQueryParams:function(a,b,c){var d=g.datasets[a];d?b(d.query_params):c&&c("unknown_dataset "+a,a)},setQueryParams:function(a,b,c,d){var e=g.datasets[a];e?(e.query_params=b,g.saveDataSet(a),c&&c(e.query_params)):d&&d("unknown_dataset "+a,a)},getMetaData:function(a,b,c){var d=g.datasets[a];d?b(d.meta_data):c&&c("unknown_dataset "+a,a)},setMetaData:function(a,b,c,d){var e=g.datasets[a];e?(e.meta_data=b,g.saveDataSet(a),c&&c(e.meta_data)):d&&d("unknown_dataset "+a,a)},getConfig:function(a,b,c){var d=g.datasets[a];d?b(d.config):c&&c("unknown_dataset "+a,a)},setConfig:function(a,b,c,d){var e=g.datasets[a];if(e){var f=g.setOptions(e.config,b);e.config=f,g.saveDataSet(a),c&&c(e.config)}else d&&d("unknown_dataset "+a,a)},stopSync:function(a,b,c){g.setConfig(a,{sync_active:!1},function(){b&&b()},c)},startSync:function(a,b,c){g.setConfig(a,{sync_active:!0},function(){b&&b()},c)},doSync:function(a,b,c){var d=g.datasets[a];d?(d.syncPending=!0,g.saveDataSet(a),b&&b()):c&&c("unknown_dataset "+a,a)},forceSync:function(a,b,c){var d=g.datasets[a];d?(d.syncForced=!0,g.saveDataSet(a),b&&b()):c&&c("unknown_dataset "+a,a)},sortObject:function(a){if("object"!=typeof a||null===a)return a;var b=[];return Object.keys(a).sort().forEach(function(c){b.push({key:c,value:g.sortObject(a[c])})}),b},sortedStringify:function(a){var b="";try{b=JSON.stringify(g.sortObject(a))}catch(c){console.error("Error stringifying sorted object:"+c)}return b},generateHash:function(a){var b=d.SHA1(g.sortedStringify(a));return b.toString()},addPendingObj:function(a,b,c,d,e,f){function h(c){c.hash=c.hash||g.generateHash(c),g.getDataSet(a,function(f){f.pending[c.hash]=c,g.updateDatasetFromLocal(f,c),g.config.auto_sync_local_updates&&(f.syncPending=!0),g.saveDataSet(a),g.doNotify(a,b,g.notifications.LOCAL_UPDATE_APPLIED,d),e(c)},function(a,b){f&&f(a,b)})}g.isOnline(function(c){c||g.doNotify(a,b,g.notifications.OFFLINE_UPDATE,d)});var i={};i.inFlight=!1,i.action=d,i.post=JSON.parse(JSON.stringify(c)),i.postHash=g.generateHash(i.post),i.timestamp=(new Date).getTime(),"create"===d?(i.hash=g.generateHash(i),i.uid=i.hash,h(i)):g.read(a,b,function(a){i.uid=b,i.pre=a.data,i.preHash=g.generateHash(a.data),h(i)},function(a,b){f&&f(a,b)})},syncLoop:function(a){g.getDataSet(a,function(b){b.syncPending=!1,b.syncRunning=!0,b.syncLoopStart=(new Date).getTime(),g.doNotify(a,null,g.notifications.SYNC_STARTED,null),g.isOnline(function(c){if(c){var d={};d.fn="sync",d.dataset_id=a,d.query_params=b.query_params,d.config=b.config,d.meta_data=b.meta_data,d.dataset_hash=b.hash,d.acknowledgements=b.acknowledgements||[];var e=b.pending,f=[];for(var h in e)e[h].inFlight||e[h].crashed||e[h].delayed||(e[h].inFlight=!0,e[h].inFlightDate=(new Date).getTime(),f.push(e[h]));d.pending=f,f.length>0&&g.consoleLog("Starting sync loop - global hash = "+b.hash+" :: params = "+JSON.stringify(d,null,2)),g.doCloudCall({dataset_id:a,req:d},function(c){function d(c,d,f){if(c)for(var h in c)e=c[h],f.push(e),b.pending[h]&&b.pending[h].inFlight&&(delete b.pending[h],g.doNotify(a,e.uid,d,e))}var e;if(g.updateCrashedInFlightFromNewData(a,b,c),g.updateDelayedFromNewData(a,b,c),g.updateMetaFromNewData(a,b,c),c.updates){var f=[];g.checkUidChanges(b,c.updates.applied),d(c.updates.applied,g.notifications.REMOTE_UPDATE_APPLIED,f),d(c.updates.failed,g.notifications.REMOTE_UPDATE_FAILED,f),d(c.updates.collisions,g.notifications.COLLISION_DETECTED,f),b.acknowledgements=f}c.hash&&c.hash!==b.hash?(g.consoleLog("Local dataset stale - syncing records :: local hash= "+b.hash+" - remoteHash="+c.hash),g.syncRecords(a)):(g.consoleLog("Local dataset up to date"),g.syncComplete(a,"online",g.notifications.SYNC_COMPLETE))},function(c,d){g.markInFlightAsCrashed(b),g.consoleLog("syncLoop failed : msg="+c+" :: err = "+d),g.syncComplete(a,c,g.notifications.SYNC_FAILED)})}else g.syncComplete(a,"offline",g.notifications.SYNC_FAILED)})})},syncRecords:function(a){g.getDataSet(a,function(b){var c=b.data||{},d={};for(var e in c){var f=e,h=c[e].hash;d[f]=h}var i={};i.fn="syncRecords",i.dataset_id=a,i.query_params=b.query_params,i.clientRecs=d,g.consoleLog("syncRecParams :: "+JSON.stringify(i)),g.doCloudCall({dataset_id:a,req:i},function(d){g.consoleLog("syncRecords Res before applying pending changes :: "+JSON.stringify(d)),g.applyPendingChangesToRecords(b,d),g.consoleLog("syncRecords Res after apply pending changes :: "+JSON.stringify(d));var e;if(d.create)for(e in d.create)c[e]={hash:d.create[e].hash,data:d.create[e].data},g.doNotify(a,e,g.notifications.RECORD_DELTA_RECEIVED,"create");if(d.update)for(e in d.update)c[e].hash=d.update[e].hash,c[e].data=d.update[e].data,g.doNotify(a,e,g.notifications.RECORD_DELTA_RECEIVED,"update");if(d["delete"])for(e in d["delete"])delete c[e],g.doNotify(a,e,g.notifications.RECORD_DELTA_RECEIVED,"delete");g.doNotify(a,d.hash,g.notifications.DELTA_RECEIVED,"partial dataset"),b.data=c,d.hash&&(b.hash=d.hash),g.syncComplete(a,"online",g.notifications.SYNC_COMPLETE)},function(b,c){g.consoleLog("syncRecords failed : msg="+b+" :: err="+c),g.syncComplete(a,b,g.notifications.SYNC_FAILED)})})},syncComplete:function(a,b,c){g.getDataSet(a,function(d){d.syncRunning=!1,d.syncLoopEnd=(new Date).getTime(),g.saveDataSet(a),g.doNotify(a,d.hash,c,b)})},applyPendingChangesToRecords:function(a,b){var c=a.pending;for(var d in c)if(c.hasOwnProperty(d)){var e=c[d],f=e.uid;if(b.create){var g=b.create;g&&g[f]&&delete g[f]}if(b.update){var h=b.update;h&&h[f]&&delete h[f]}if(b["delete"]){var i=b["delete"];i&&i[f]&&delete i[f]}}},checkUidChanges:function(a,b){if(b){var c={},d=0;for(var e in b)if(b.hasOwnProperty(e)){var f=b[e],h=f.action;if(h&&"create"===h){var i=f.uid,j=f.hash;d++,g.uid_map[j]=i,c[j]=i;var k=a.data[j];k&&(a.data[i]=k,delete a.data[j]);var l=a.meta[j];l&&(a.meta[i]=l,delete a.meta[j])}}if(d>0)for(var m in a.pending)if(a.pending.hasOwnProperty(m)){var n=a.pending[m],o=n.uid;c[o]&&(n.uid=c[o])}}},checkDatasets:function(){for(var a in g.datasets)if(g.datasets.hasOwnProperty(a)){var b=g.datasets[a];if(b&&!b.syncRunning&&(b.config.sync_active||b.syncForced)){var c=b.syncLoopStart,d=b.syncLoopEnd;if(b.syncForced)b.syncPending=!0;else if(null==c)g.consoleLog(a+" - Performing initial sync"),b.syncPending=!0;else if(null!=d){var e=(new Date).getTime()-d,f=1e3*b.config.sync_frequency;e>f&&(b.syncPending=!0)}b.syncPending&&(b.syncForced=!1,g.syncLoop(a))}}},setCloudHandler:function(a){g.cloudHandler=a},doCloudCall:function(a,b,c){g.cloudHandler&&"function"==typeof g.cloudHandler?g.cloudHandler(a,b,c):console.log("Missing cloud handler for sync. Please refer to documentation")},datasetMonitor:function(){g.checkDatasets(),setTimeout(function(){g.datasetMonitor()},500)},getStorageAdapter:function(a,b,c){var d=function(c,d){var e=(b?"save to":"load from")+" local storage failed msg: "+c+" err: "+d;g.doNotify(a,null,g.notifications.CLIENT_STORAGE_FAILED,e),g.consoleLog(e)};e({fail:d,adapter:g.config.storage_strategy,size:g.config.file_system_quota,backup:g.config.icloud_backup},function(){return c(null,this)})},saveDataSet:function(a,b){g.getDataSet(a,function(c){g.getStorageAdapter(a,!0,function(d,e){e.save({key:"dataset_"+a,val:c},function(){return b?b():void 0})})})},loadDataSet:function(a,b,c){g.getStorageAdapter(a,!1,function(d,e){e.get("dataset_"+a,function(d){if(d&&d.val){var e=d.val;if("string"==typeof e&&(e=JSON.parse(e)),e.initialised=!1,g.datasets[a]=e,g.consoleLog("load from local storage success for dataset_id :"+a),b)return b(e)}else if(c)return c()})})},clearCache:function(a,b){delete g.datasets[a],g.notify_callback_map[a]=null,g.getStorageAdapter(a,!0,function(c,d){d.remove("dataset_"+a,function(){return g.consoleLog("local cache is cleared for dataset : "+a),b?b():void 0})})},updateDatasetFromLocal:function(a,b){var c,d,e=a.pending,f=b.uid;g.consoleLog("updating local dataset for uid "+f+" - action = "+b.action),a.meta[f]=a.meta[f]||{},"create"===b.action&&(a.data[f]&&(g.consoleLog("dataset already exists for uid in create :: "+JSON.stringify(a.data[f])),a.meta[f].fromPending&&(c=a.meta[f].pendingUid,delete e[c])),a.data[f]={}),"update"===b.action&&a.data[f]&&a.meta[f].fromPending&&(g.consoleLog("updating an existing pending record for dataset :: "+JSON.stringify(a.data[f])),c=a.meta[f].pendingUid,d=e[c],d&&(d.inFlight?(g.consoleLog("existing in-inflight pending record = "+JSON.stringify(d)),b.delayed=!0,b.waiting=d.hash):(g.consoleLog("existing pre-flight pending record = "+JSON.stringify(d)),d.post=b.post,d.postHash=b.postHash,delete e[b.hash],b.hash=c))),"delete"===b.action&&a.data[f]&&(a.meta[f].fromPending&&(g.consoleLog("Deleting an existing pending record for dataset :: "+JSON.stringify(a.data[f])),c=a.meta[f].pendingUid,d=e[c],d&&(d.inFlight?(g.consoleLog("existing in-inflight pending record = "+JSON.stringify(d)),b.delayed=!0,b.waiting=d.hash):(g.consoleLog("existing pending record = "+JSON.stringify(d)),"create"===d.action&&(delete e[b.hash],delete e[c]),"update"===d.action&&(b.pre=d.pre,b.preHash=d.preHash,b.inFlight=!1,delete e[c])))),delete a.data[f]),a.data[f]&&(a.data[f].data=b.post,a.data[f].hash=b.postHash,a.meta[f].fromPending=!0,a.meta[f].pendingUid=b.hash)},updateCrashedInFlightFromNewData:function(a,b,c){var d,e,f=({applied:g.notifications.REMOTE_UPDATE_APPLIED,failed:g.notifications.REMOTE_UPDATE_FAILED,collisions:g.notifications.COLLISION_DETECTED},b.pending);if(f){for(d in f)if(f.hasOwnProperty(d)&&(e=f[d],e.inFlight&&e.crashed))if(g.consoleLog("updateCrashedInFlightFromNewData - Found crashed inFlight pending record uid="+e.uid+" :: hash="+e.hash),c&&c.updates&&c.updates.hashes){var h=c.updates.hashes[d];h||(e.crashedCount?e.crashedCount++:e.crashedCount=1)}else e.crashedCount?e.crashedCount++:e.crashedCount=1;for(d in f)f.hasOwnProperty(d)&&(e=f[d],e.inFlight&&e.crashed&&e.crashedCount>b.config.crashed_count_wait&&(g.consoleLog("updateCrashedInFlightFromNewData - Crashed inflight pending record has reached crashed_count_wait limit : "+JSON.stringify(e)),g.consoleLog("updateCrashedInFlightFromNewData - Retryig crashed inflight pending record"),e.crashed=!1,e.inFlight=!1))}},updateDelayedFromNewData:function(a,b,c){var d,e,f=b.pending;if(f)for(d in f)if(f.hasOwnProperty(d)&&(e=f[d],e.delayed&&e.waiting&&(g.consoleLog("updateDelayedFromNewData - Found delayed pending record uid="+e.uid+" :: hash="+e.hash+" :: waiting="+e.waiting),c&&c.updates&&c.updates.hashes))){var h=c.updates.hashes[e.waiting];h&&(g.consoleLog("updateDelayedFromNewData - Waiting pending record is resolved rec="+JSON.stringify(h)),e.delayed=!1,e.waiting=void 0)}},updateMetaFromNewData:function(a,b,c){var d=b.meta;if(d&&c&&c.updates&&c.updates.hashes)for(var e in d)if(d.hasOwnProperty(e)){var f=d[e],h=f.pendingUid;g.consoleLog("updateMetaFromNewData - Found metadata with uid = "+e+" :: pendingHash = "+h);var i=!0;if(h){i=!1;var j=c.updates.hashes[h];j&&(g.consoleLog("updateMetaFromNewData - Found pendingUid in meta data resolved - resolved = "+JSON.stringify(j)),f.pendingUid=void 0,i=!0)}i&&(g.consoleLog("updateMetaFromNewData - both previous and current pendings are resolved for meta data with uid "+e+". Delete it."),delete d[e])}},markInFlightAsCrashed:function(a){var b,c,d=a.pending;if(d){var e={};for(b in d)d.hasOwnProperty(b)&&(c=d[b],c.inFlight&&(g.consoleLog("Marking in flight pending record as crashed : "+b),c.crashed=!0,e[c.uid]=c))}},consoleLog:function(a){g.config.do_console_log&&console.log(a)}};!function(){g.config=g.defaults}(),g.setCloudHandler(f.handler),b.exports={init:g.init,manage:g.manage,notify:g.notify,doList:g.list,getUID:g.getUID,doCreate:g.create,doRead:g.read,doUpdate:g.update,doDelete:g["delete"],listCollisions:g.listCollisions,removeCollision:g.removeCollision,getPending:g.getPending,clearPending:g.clearPending,getDataset:g.getDataSet,getQueryParams:g.getQueryParams,setQueryParams:g.setQueryParams,getMetaData:g.getMetaData,setMetaData:g.setMetaData,getConfig:g.getConfig,setConfig:g.setConfig,startSync:g.startSync,stopSync:g.stopSync,doSync:g.doSync,forceSync:g.forceSync,generateHash:g.generateHash,loadDataSet:g.loadDataSet,clearCache:g.clearCache,setCloudHandler:g.setCloudHandler,doCloudCall:g.doCloudCall}},{"../libs/generated/crypto":1,"../libs/generated/lawnchair":2,"./cloudHandler":3}]},{},[4])(4)});
!function(a){if("object"==typeof exports)module.exports=a();else if("function"==typeof define&&define.amd)define(a);else{var b;"undefined"!=typeof window?b=window:"undefined"!=typeof global?b=global:"undefined"!=typeof self&&(b=self),b.fhsync=a()}}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){(function(c){__browserify_shim_require__=a,function(a,b,c,d,e){var f=f||function(a,b){var c={},d=c.lib={},e=d.Base=function(){function a(){}return{extend:function(b){a.prototype=this;var c=new a;return b&&c.mixIn(b),c.hasOwnProperty("init")||(c.init=function(){c.$super.init.apply(this,arguments)}),c.init.prototype=c,c.$super=this,c},create:function(){var a=this.extend();return a.init.apply(a,arguments),a},init:function(){},mixIn:function(a){for(var b in a)a.hasOwnProperty(b)&&(this[b]=a[b]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),f=d.WordArray=e.extend({init:function(a,c){a=this.words=a||[],c!=b?this.sigBytes=c:this.sigBytes=4*a.length},toString:function(a){return(a||h).stringify(this)},concat:function(a){var b=this.words,c=a.words,d=this.sigBytes,e=a.sigBytes;if(this.clamp(),d%4)for(var f=0;e>f;f++){var g=c[f>>>2]>>>24-f%4*8&255;b[d+f>>>2]|=g<<24-(d+f)%4*8}else if(c.length>65535)for(var f=0;e>f;f+=4)b[d+f>>>2]=c[f>>>2];else b.push.apply(b,c);return this.sigBytes+=e,this},clamp:function(){var b=this.words,c=this.sigBytes;b[c>>>2]&=4294967295<<32-c%4*8,b.length=a.ceil(c/4)},clone:function(){var a=e.clone.call(this);return a.words=this.words.slice(0),a},random:function(b){for(var c=[],d=0;b>d;d+=4)c.push(4294967296*a.random()|0);return new f.init(c,b)}}),g=c.enc={},h=g.Hex={stringify:function(a){for(var b=a.words,c=a.sigBytes,d=[],e=0;c>e;e++){var f=b[e>>>2]>>>24-e%4*8&255;d.push((f>>>4).toString(16)),d.push((15&f).toString(16))}return d.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d+=2)c[d>>>3]|=parseInt(a.substr(d,2),16)<<24-d%8*4;return new f.init(c,b/2)}},i=g.Latin1={stringify:function(a){for(var b=a.words,c=a.sigBytes,d=[],e=0;c>e;e++){var f=b[e>>>2]>>>24-e%4*8&255;d.push(String.fromCharCode(f))}return d.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d++)c[d>>>2]|=(255&a.charCodeAt(d))<<24-d%4*8;return new f.init(c,b)}},j=g.Utf8={stringify:function(a){try{return decodeURIComponent(escape(i.stringify(a)))}catch(b){throw new Error("Malformed UTF-8 data")}},parse:function(a){return i.parse(unescape(encodeURIComponent(a)))}},k=d.BufferedBlockAlgorithm=e.extend({reset:function(){this._data=new f.init,this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=j.parse(a)),this._data.concat(a),this._nDataBytes+=a.sigBytes},_process:function(b){var c=this._data,d=c.words,e=c.sigBytes,g=this.blockSize,h=4*g,i=e/h;i=b?a.ceil(i):a.max((0|i)-this._minBufferSize,0);var j=i*g,k=a.min(4*j,e);if(j){for(var l=0;j>l;l+=g)this._doProcessBlock(d,l);var m=d.splice(0,j);c.sigBytes-=k}return new f.init(m,k)},clone:function(){var a=e.clone.call(this);return a._data=this._data.clone(),a},_minBufferSize:0}),l=(d.Hasher=k.extend({cfg:e.extend(),init:function(a){this.cfg=this.cfg.extend(a),this.reset()},reset:function(){k.reset.call(this),this._doReset()},update:function(a){return this._append(a),this._process(),this},finalize:function(a){a&&this._append(a);var b=this._doFinalize();return b},blockSize:16,_createHelper:function(a){return function(b,c){return new a.init(c).finalize(b)}},_createHmacHelper:function(a){return function(b,c){return new l.HMAC.init(a,c).finalize(b)}}}),c.algo={});return c}(Math);f.lib.Cipher||function(a){var b=f,c=b.lib,d=c.Base,e=c.WordArray,g=c.BufferedBlockAlgorithm,h=b.enc,i=(h.Utf8,h.Base64),j=b.algo,k=j.EvpKDF,l=c.Cipher=g.extend({cfg:d.extend(),createEncryptor:function(a,b){return this.create(this._ENC_XFORM_MODE,a,b)},createDecryptor:function(a,b){return this.create(this._DEC_XFORM_MODE,a,b)},init:function(a,b,c){this.cfg=this.cfg.extend(c),this._xformMode=a,this._key=b,this.reset()},reset:function(){g.reset.call(this),this._doReset()},process:function(a){return this._append(a),this._process()},finalize:function(a){a&&this._append(a);var b=this._doFinalize();return b},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function a(a){return"string"==typeof a?x:u}return function(b){return{encrypt:function(c,d,e){return a(d).encrypt(b,c,d,e)},decrypt:function(c,d,e){return a(d).decrypt(b,c,d,e)}}}}()}),m=(c.StreamCipher=l.extend({_doFinalize:function(){var a=this._process(!0);return a},blockSize:1}),b.mode={}),n=c.BlockCipherMode=d.extend({createEncryptor:function(a,b){return this.Encryptor.create(a,b)},createDecryptor:function(a,b){return this.Decryptor.create(a,b)},init:function(a,b){this._cipher=a,this._iv=b}}),o=m.CBC=function(){function b(b,c,d){var e=this._iv;if(e){var f=e;this._iv=a}else var f=this._prevBlock;for(var g=0;d>g;g++)b[c+g]^=f[g]}var c=n.extend();return c.Encryptor=c.extend({processBlock:function(a,c){var d=this._cipher,e=d.blockSize;b.call(this,a,c,e),d.encryptBlock(a,c),this._prevBlock=a.slice(c,c+e)}}),c.Decryptor=c.extend({processBlock:function(a,c){var d=this._cipher,e=d.blockSize,f=a.slice(c,c+e);d.decryptBlock(a,c),b.call(this,a,c,e),this._prevBlock=f}}),c}(),p=b.pad={},q=p.Pkcs7={pad:function(a,b){for(var c=4*b,d=c-a.sigBytes%c,f=d<<24|d<<16|d<<8|d,g=[],h=0;d>h;h+=4)g.push(f);var i=e.create(g,d);a.concat(i)},unpad:function(a){var b=255&a.words[a.sigBytes-1>>>2];a.sigBytes-=b}},r=(c.BlockCipher=l.extend({cfg:l.cfg.extend({mode:o,padding:q}),reset:function(){l.reset.call(this);var a=this.cfg,b=a.iv,c=a.mode;if(this._xformMode==this._ENC_XFORM_MODE)var d=c.createEncryptor;else{var d=c.createDecryptor;this._minBufferSize=1}this._mode=d.call(c,this,b&&b.words)},_doProcessBlock:function(a,b){this._mode.processBlock(a,b)},_doFinalize:function(){var a=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){a.pad(this._data,this.blockSize);var b=this._process(!0)}else{var b=this._process(!0);a.unpad(b)}return b},blockSize:4}),c.CipherParams=d.extend({init:function(a){this.mixIn(a)},toString:function(a){return(a||this.formatter).stringify(this)}})),s=b.format={},t=s.OpenSSL={stringify:function(a){var b=a.ciphertext,c=a.salt;if(c)var d=e.create([1398893684,1701076831]).concat(c).concat(b);else var d=b;return d.toString(i)},parse:function(a){var b=i.parse(a),c=b.words;if(1398893684==c[0]&&1701076831==c[1]){var d=e.create(c.slice(2,4));c.splice(0,4),b.sigBytes-=16}return r.create({ciphertext:b,salt:d})}},u=c.SerializableCipher=d.extend({cfg:d.extend({format:t}),encrypt:function(a,b,c,d){d=this.cfg.extend(d);var e=a.createEncryptor(c,d),f=e.finalize(b),g=e.cfg;return r.create({ciphertext:f,key:c,iv:g.iv,algorithm:a,mode:g.mode,padding:g.padding,blockSize:a.blockSize,formatter:d.format})},decrypt:function(a,b,c,d){d=this.cfg.extend(d),b=this._parse(b,d.format);var e=a.createDecryptor(c,d).finalize(b.ciphertext);return e},_parse:function(a,b){return"string"==typeof a?b.parse(a,this):a}}),v=b.kdf={},w=v.OpenSSL={execute:function(a,b,c,d){d||(d=e.random(8));var f=k.create({keySize:b+c}).compute(a,d),g=e.create(f.words.slice(b),4*c);return f.sigBytes=4*b,r.create({key:f,iv:g,salt:d})}},x=c.PasswordBasedCipher=u.extend({cfg:u.cfg.extend({kdf:w}),encrypt:function(a,b,c,d){d=this.cfg.extend(d);var e=d.kdf.execute(c,a.keySize,a.ivSize);d.iv=e.iv;var f=u.encrypt.call(this,a,b,e.key,d);return f.mixIn(e),f},decrypt:function(a,b,c,d){d=this.cfg.extend(d),b=this._parse(b,d.format);var e=d.kdf.execute(c,a.keySize,a.ivSize,b.salt);d.iv=e.iv;var f=u.decrypt.call(this,a,b,e.key,d);return f}})}(),function(){var a=f,b=a.lib,c=b.WordArray,d=b.Hasher,e=a.algo,g=[],h=e.SHA1=d.extend({_doReset:function(){this._hash=new c.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(a,b){for(var c=this._hash.words,d=c[0],e=c[1],f=c[2],h=c[3],i=c[4],j=0;80>j;j++){if(16>j)g[j]=0|a[b+j];else{var k=g[j-3]^g[j-8]^g[j-14]^g[j-16];g[j]=k<<1|k>>>31}var l=(d<<5|d>>>27)+i+g[j];l+=20>j?(e&f|~e&h)+1518500249:40>j?(e^f^h)+1859775393:60>j?(e&f|e&h|f&h)-1894007588:(e^f^h)-899497514,i=h,h=f,f=e<<30|e>>>2,e=d,d=l}c[0]=c[0]+d|0,c[1]=c[1]+e|0,c[2]=c[2]+f|0,c[3]=c[3]+h|0,c[4]=c[4]+i|0},_doFinalize:function(){var a=this._data,b=a.words,c=8*this._nDataBytes,d=8*a.sigBytes;return b[d>>>5]|=128<<24-d%32,b[(d+64>>>9<<4)+14]=Math.floor(c/4294967296),b[(d+64>>>9<<4)+15]=c,a.sigBytes=4*b.length,this._process(),this._hash},clone:function(){var a=d.clone.call(this);return a._hash=this._hash.clone(),a}});a.SHA1=d._createHelper(h),a.HmacSHA1=d._createHmacHelper(h)}(),function(a){var b=f,c=b.lib,d=c.Base,e=c.WordArray,g=b.x64={};g.Word=d.extend({init:function(a,b){this.high=a,this.low=b}}),g.WordArray=d.extend({init:function(b,c){b=this.words=b||[],c!=a?this.sigBytes=c:this.sigBytes=8*b.length},toX32:function(){for(var a=this.words,b=a.length,c=[],d=0;b>d;d++){var f=a[d];c.push(f.high),c.push(f.low)}return e.create(c,this.sigBytes)},clone:function(){for(var a=d.clone.call(this),b=a.words=this.words.slice(0),c=b.length,e=0;c>e;e++)b[e]=b[e].clone();return a}})}(),e("undefined"!=typeof f?f:window.CryptoJS)}.call(c,void 0,void 0,void 0,void 0,function(a){b.exports=a})}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],2:[function(a,b,c){(function(c){__browserify_shim_require__=a,function(a,b,c,d,e){var f=function(a,b){if(!(this instanceof f))return new f(a,b);if(!JSON)throw"JSON unavailable! Include http://www.json.org/json2.js to fix.";if(!(arguments.length<=2&&arguments.length>0))throw"Incorrect # of ctor args!";if(b="function"==typeof arguments[0]?arguments[0]:arguments[1],a="function"==typeof arguments[0]?{}:arguments[0],"function"!=typeof b)throw"No callback was provided";this.record=a.record||"record",this.name=a.name||"records";var c;if(a.adapter){"string"==typeof a.adapter&&(a.adapter=[a.adapter]);for(var d=0,e=a.adapter.length;e>d;d++){for(var g=f.adapters.length-1;g>=0&&(f.adapters[g].adapter!==a.adapter[d]||!(c=f.adapters[g].valid()?f.adapters[g]:void 0));g--);if(c)break}}else for(var g=0,h=f.adapters.length;h>g&&!(c=f.adapters[g].valid()?f.adapters[g]:void 0);g++);if(!c)throw"No valid adapter.";for(var d in c)this[d]=c[d];for(var g=0,h=f.plugins.length;h>g;g++)f.plugins[g].call(this);this.init(a,b)};f.adapters=[],f.adapter=function(a,b){b.adapter=a;var c="adapter valid init keys save batch get exists all remove nuke".split(" "),d=this.prototype.indexOf;for(var e in b)if(-1===d(c,e))throw"Invalid adapter! Nonstandard method: "+e;f.adapters.splice(0,0,b)},f.plugins=[],f.plugin=function(a){for(var b in a)"init"===b?f.plugins.push(a[b]):this.prototype[b]=a[b]},f.prototype={isArray:Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)},indexOf:function(a,b,c,d){if(a.indexOf)return a.indexOf(b);for(c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},lambda:function(a){return this.fn(this.record,a)},fn:function(a,b){return"string"==typeof b?new Function(a,b):b},uuid:function(){var a=function(){return(65536*(1+Math.random())|0).toString(16).substring(1)};return a()+a()+"-"+a()+"-"+a()+"-"+a()+"-"+a()+a()+a()},each:function(a){var b=this.lambda(a);if(this.__results)for(var c=0,d=this.__results.length;d>c;c++)b.call(this,this.__results[c],c);else this.all(function(a){for(var c=0,d=a.length;d>c;c++)b.call(this,a[c],c)});return this}},f.adapter("window-name",function(){"undefined"==typeof window&&(window={top:{}});var a={};try{a=JSON.parse(window.top.name)}catch(b){}return{valid:function(){return"undefined"!=typeof window.top.name},init:function(b,c){return a[this.name]=a[this.name]||{index:[],store:{}},this.index=a[this.name].index,this.store=a[this.name].store,this.fn(this.name,c).call(this,this),this},keys:function(a){return this.fn("keys",a).call(this,this.index),this},save:function(b,c){var d=b.key||this.uuid();return this.exists(d,function(e){e||(b.key&&delete b.key,this.index.push(d)),this.store[d]=b;try{window.top.name=JSON.stringify(a)}catch(f){throw e||(this.index.pop(),delete this.store[d]),f}c&&(b.key=d,this.lambda(c).call(this,b))}),this},batch:function(a,b){for(var c=[],d=0,e=a.length;e>d;d++)this.save(a[d],function(a){c.push(a)});return b&&this.lambda(b).call(this,c),this},get:function(a,b){var c;if(this.isArray(a)){c=[];for(var d=0,e=a.length;e>d;d++)c.push(this.store[a[d]])}else c=this.store[a],c&&(c.key=a);return b&&this.lambda(b).call(this,c),this},exists:function(a,b){return this.lambda(b).call(this,!!this.store[a]),this},all:function(a){for(var b=[],c=0,d=this.index.length;d>c;c++){var e=this.store[this.index[c]];e.key=this.index[c],b.push(e)}return this.fn(this.name,a).call(this,b),this},remove:function(b,c){for(var d=this.isArray(b)?b:[b],e=0,f=d.length;f>e;e++){var g=d[e].key?d[e].key:d[e],h=this.indexOf(this.index,g);0>h||(delete this.store[g],this.index.splice(h,1))}return window.top.name=JSON.stringify(a),c&&this.lambda(c).call(this),this},nuke:function(b){return this.store=a[this.name].store={},this.index=a[this.name].index=[],window.top.name=JSON.stringify(a),b&&this.lambda(b).call(this),this}}}()),f.adapter("dom",function(){var a=null;try{a=window.localStorage}catch(b){}var c=function(b){return{key:b+"._index_",all:function(){var b=a.getItem(this.key);return b&&(b=JSON.parse(b)),null===b&&a.setItem(this.key,JSON.stringify([])),JSON.parse(a.getItem(this.key))},add:function(b){var c=this.all();c.push(b),a.setItem(this.key,JSON.stringify(c))},del:function(b){for(var c=this.all(),d=[],e=0,f=c.length;f>e;e++)c[e]!=b&&d.push(c[e]);a.setItem(this.key,JSON.stringify(d))},find:function(a){for(var b=this.all(),c=0,d=b.length;d>c;c++)if(a===b[c])return c;return!1}}};return{valid:function(){return!!a&&function(){var b=!0,c=Math.random();try{a.setItem(c,c)}catch(d){b=!1}return a.removeItem(c),b}()},init:function(a,b){this.indexer=c(this.name),b&&this.fn(this.name,b).call(this,this)},save:function(b,c){var d=b.key?this.name+"."+b.key:this.name+"."+this.uuid();return delete b.key,a.setItem(d,JSON.stringify(b)),this.indexer.find(d)===!1&&this.indexer.add(d),b.key=d.slice(this.name.length+1),c&&this.lambda(c).call(this,b),this},batch:function(a,b){for(var c=[],d=0,e=a.length;e>d;d++)this.save(a[d],function(a){c.push(a)});return b&&this.lambda(b).call(this,c),this},keys:function(a){if(a){var b=this.name,c=this.indexer.all(),d=[];if(Array.prototype.map)d=c.map(function(a){return a.replace(b+".","")});else for(var e in c)d.push(e.replace(b+".",""));this.fn("keys",a).call(this,d)}return this},get:function(b,c){if(this.isArray(b)){for(var d=[],e=0,f=b.length;f>e;e++){var g=this.name+"."+b[e],h=a.getItem(g);h&&(h=JSON.parse(h),h.key=b[e]),d.push(h)}c&&this.lambda(c).call(this,d)}else{var g=this.name+"."+b,h=a.getItem(g);h&&(h=JSON.parse(h),h.key=b),c&&this.lambda(c).call(this,h)}return this},exists:function(a,b){var c=this.indexer.find(this.name+"."+a)===!1?!1:!0;return this.lambda(b).call(this,c),this},all:function(b){for(var c,d,e=this.indexer.all(),f=[],g=0,h=e.length;h>g;g++)d=e[g],c=JSON.parse(a.getItem(d)),c.key=d.replace(this.name+".",""),f.push(c);return b&&this.fn(this.name,b).call(this,f),this},remove:function(b,c){var d=this;if(this.isArray(b)){var e,f=b.length,g=function(a){d.remove(b[a],function(){--f>0||c&&d.lambda(c).call(d)})};for(e=0;e<b.length;e++)g(e);return this}var h=this.name+"."+(b.key?b.key:b);return this.indexer.del(h),a.removeItem(h),c&&this.lambda(c).call(this),this},nuke:function(a){return this.all(function(b){for(var c=0,d=b.length;d>c;c++)this.remove(b[c]);a&&this.lambda(a).call(this)}),this}}}()),f.adapter("webkit-sqlite",function(){var a=function(a,b){console&&console.log("error in sqlite adaptor!",a,b)},b=function(){return new Date};return{valid:function(){return!!window.openDatabase},init:function(b,c){var d=this,e=d.fn(d.name,c),f="CREATE TABLE IF NOT EXISTS "+this.record+" (id NVARCHAR(32) UNIQUE PRIMARY KEY, value TEXT, timestamp REAL)",g=function(){return e.call(d,d)};b&&"function"==typeof b.fail&&(a=b.fail),this.db=openDatabase(this.name,"1.0.0",this.name,65536),this.db.transaction(function(b){b.executeSql(f,[],g,a)})},keys:function(b){var c=this.lambda(b),d=this,e="SELECT id FROM "+this.record+" ORDER BY timestamp DESC";return this.db.readTransaction(function(b){var f=function(a,b){if(0==b.rows.length)c.call(d,[]);else{for(var e=[],f=0,g=b.rows.length;g>f;f++)e.push(b.rows.item(f).id);c.call(d,e)}};b.executeSql(e,[],f,a)}),this},save:function(c,d,e){var f=this;objs=(this.isArray(c)?c:[c]).map(function(a){return a.key||(a.key=f.uuid()),a}),ins="INSERT OR REPLACE INTO "+this.record+" (value, timestamp, id) VALUES (?,?,?)",win=function(){d&&f.lambda(d).call(f,f.isArray(c)?objs:objs[0])},e=e||function(){},insvals=[],ts=b();try{for(var g=0,h=objs.length;h>g;g++)insvals[g]=[JSON.stringify(objs[g]),ts,objs[g].key]}catch(i){throw a(i),i}return f.db.transaction(function(a){for(var b=0,c=objs.length;c>b;b++)a.executeSql(ins,insvals[b])},function(b,c){a(b,c)},win),this},batch:function(a,b){return this.save(a,b)},get:function(b,c){var d=this,e="",f=this.isArray(b)?b:[b];e="SELECT id, value FROM "+this.record+" WHERE id IN ("+f.map(function(){return"?"}).join(",")+")";var g=function(a,e){for(var g,h,i={},j=0,k=e.rows.length;k>j;j++)g=JSON.parse(e.rows.item(j).value),g.key=e.rows.item(j).id,i[g.key]=g;h=f.map(function(a){return i[a]}),d.isArray(b)||(h=h.length?h[0]:null),c&&d.lambda(c).call(d,h)};return this.db.readTransaction(function(b){b.executeSql(e,f,g,a)}),this},exists:function(b,c){var d="SELECT * FROM "+this.record+" WHERE id = ?",e=this,f=function(a,b){c&&e.fn("exists",c).call(e,b.rows.length>0)};return this.db.readTransaction(function(c){c.executeSql(d,[b],f,a)}),this},all:function(b){var c=this,d="SELECT * FROM "+this.record,e=[],f=this.fn(this.name,b)||void 0,g=function(a,b){if(0!=b.rows.length)for(var d=0,g=b.rows.length;g>d;d++){var h=JSON.parse(b.rows.item(d).value);h.key=b.rows.item(d).id,e.push(h)}f&&f.call(c,e)};return this.db.readTransaction(function(b){b.executeSql(d,[],g,a)}),this},remove:function(b,c){var d,e=this,f="DELETE FROM "+this.record+" WHERE id ",g=function(){c&&e.lambda(c).call(e)};return this.isArray(b)?(d=b,f+="IN ("+d.map(function(){return"?"}).join(",")+")"):(f+="= ?",d=[b]),d=d.map(function(a){return a.key?a.key:a}),this.db.transaction(function(b){b.executeSql(f,d,g,a)}),this},nuke:function(b){var c="DELETE FROM "+this.record,d=this,e=b?function(){d.lambda(b).call(d)}:function(){};return this.db.transaction(function(b){b.executeSql(c,[],e,a)}),this}}}()),f.adapter("indexed-db",function(){function a(a,b){console&&console.log("error in indexed-db adapter!"+a.message,a,b)}function b(){return window.indexedDB||window.webkitIndexedDB||window.mozIndexedDB||window.oIndexedDB||window.msIndexedDB}return{valid:function(){return!!b()},init:function(c,d){this.idb=b(),this.waiting=[];var e=this.idb.open(this.name,2),f=this,g=f.fn(f.name,d),h=function(){return g.call(f,f)};c&&"function"==typeof c.fail&&(a=c.fail),e.onupgradeneeded=function(a){f.store=e.result.createObjectStore("teststore",{autoIncrement:!0});for(var b=0;b<f.waiting.length;b++)f.waiting[b].call(f);f.waiting=[],h()},e.onsuccess=function(b){if(f.db=e.result,"2.0"!=f.db.version){if("function"==typeof f.db.setVersion){var c=f.db.setVersion("2.0");c.onsuccess=function(a){f.store=f.db.createObjectStore("teststore",{autoIncrement:!0});for(var b=0;b<f.waiting.length;b++)f.waiting[b].call(f);f.waiting=[],h()},c.onerror=function(b){a(b)}}}else{f.store={};for(var d=0;d<f.waiting.length;d++)f.waiting[d].call(f);f.waiting=[],h()}},e.onerror=a},save:function(b,c){if(!this.store)return void this.waiting.push(function(){this.save(b,c)});var d=this,e=function(a){c&&(b.key=a.target.result,d.lambda(c).call(d,b))},f="readwrite",g=this.db.transaction(["teststore"],f),h=g.objectStore("teststore"),i=b.key?h.put(b,b.key):h.put(b);return i.onsuccess=e,i.onerror=a,this},batch:function(a,b){for(var c=[],d=!1,e=this,f=function(b){c.push(b),d=c.length===a.length},g=setInterval(function(){d&&(b&&e.lambda(b).call(e,c),clearInterval(g))},200),h=0,i=a.length;i>h;h++)this.save(a[h],f);return this},get:function(b,c){if(!this.store||!this.db)return void this.waiting.push(function(){this.get(b,c)});var d=this,e=function(a){c&&d.lambda(c).call(d,a.target.result)};if(this.isArray(b))for(var f=[],g=!1,h=b,i=function(a){f.push(a),g=f.length===h.length},j=setInterval(function(){g&&(c&&d.lambda(c).call(d,f),clearInterval(j))},200),k=0,l=h.length;l>k;k++)this.get(h[k],i);else{var m=this.db.transaction("teststore").objectStore("teststore").get(b);m.onsuccess=e,m.onerror=function(b){a(b)}}return this},all:function(a){if(!this.store)return void this.waiting.push(function(){this.all(a)});var b=this.fn(this.name,a)||void 0,c=this,d=this.db.transaction("teststore").objectStore("teststore"),e=[];return d.openCursor().onsuccess=function(a){var d=a.target.result;d?(e.push(d.value),d["continue"]()):b&&b.call(c,e)},this},remove:function(b,c){if(!this.store)return void this.waiting.push(function(){this.remove(b,c)});"object"==typeof b&&(b=b.key);var d=this,e=function(){c&&d.lambda(c).call(d)},f=this.db.transaction(["teststore"],"readwrite").objectStore("teststore")["delete"](b);return f.onsuccess=e,f.onerror=a,this},nuke:function(b){if(!this.store)return void this.waiting.push(function(){this.nuke(b)});var c=this,d=b?function(){c.lambda(b).call(c)}:function(){};try{this.db.transaction(["teststore"],"readwrite").objectStore("teststore").clear().onsuccess=d}catch(e){a()}return this}}}()),f.adapter("html5-filesystem",function(a){var b=function(a){console&&console.error(a,a.name)},c=function(a,d,e){var f=e||[];a.readEntries(function(b){b.length?c(a,d,f.concat(Array.prototype.slice.call(b))):d&&d(f.map(function(a){return a.name}))},b)},d={},e=function(a,b){var c=d[a.name];c?b(c):setTimeout(function(){e(a,b)},10)},f=function(){var a=-1===document.URL.indexOf("http://")&&-1===document.URL.indexOf("https://");return a?!0:!1},g=function(a){var b;if(f())b=a;else{var c="application/json";try{b=new Blob([a],{type:c})}catch(d){var e=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder;if("TypeError"==d.name&&e){var g=new e;g.append([a.buffer]),b=g.getBlob(c)}else b=a}}return b};return{valid:function(){var b=a.requestFileSystem||a.webkitRequestFileSystem||a.moz_requestFileSystem;return!!b},init:function(c,e){function f(b){var c=a.requestFileSystem||a.webkitRequestFileSystem||a.moz_requestFileSystem,f=window.PERSISTENT;"undefined"!=typeof LocalFileSystem&&"undefined"!=typeof LocalFileSystem.PERSISTENT&&(f=LocalFileSystem.PERSISTENT),c(f,b,function(a){a.root.getDirectory(j,{create:!0},function(a){d[j]=a,e&&g.fn(g.name,e).call(g,g)},function(a){h(a)})},function(a){h(a)})}var g=this,h=function(a){b(a),e&&g.fn(g.name,e).call(g,g)},i=c.size||104857600,j=this.name;g.backup=!1,"undefined"!=typeof c.backup&&(g.backup=c.backup),"undefined"!=typeof navigator.webkitPersistentStorage?navigator.webkitPersistentStorage.requestQuota(i,f,function(){logger.warn("User declined file storage"),h("User declined file storage")}):f(0)},keys:function(a){var b=this;return e(this,function(d){c(d.createReader(),function(c){a&&b.fn("keys",a).call(b,c)})}),this},save:function(a,c){var d=this,f=a.key||this.uuid();a.key=f;var h=function(a){b(a),c&&d.lambda(c).call(d)};return e(this,function(b){var e=function(b,e){b.createWriter(function(b){b.onerror=e,b.onwriteend=function(){this.onwriteend=null,this.truncate(this.position),c&&d.lambda(c).call(d,a)};var f=JSON.stringify(a),h=g(f);b.write(h)},e)};b.getFile(f,{create:!0},function(a){"function"!=typeof a.setMetadata||d.backup!==!1&&"false"!==d.backup?e(a,h):a.setMetadata(function(){e(a,h)},function(){e(a,h)},{"com.apple.MobileBackup":1})},h)}),this},batch:function(a,b){for(var c=this,d=[],e=0,f=a.length;f>e;e++)c.save(a[e],function(a){d.push(a),d.length===f&&b&&c.lambda(b).call(c,d)});return this},get:function(a,c){var d=this;if(this.isArray(a))for(var f=[],g=0,h=a.length;h>g;g++)d.get(a[g],function(a){a&&f.push(a),f.length===h&&c&&d.lambda(c).call(d,f)});else{var i=function(a){b(a),c&&d.lambda(c).call(d)};e(this,function(b){b.getFile(a,{create:!1},function(b){b.file(function(b){var e=new FileReader;e.onerror=i,e.onload=function(b){var e={};try{e=JSON.parse(b.target.result),e.key=a}catch(b){e={key:a}}c&&d.lambda(c).call(d,e)},e.readAsText(b)},i)},i)})}return this},exists:function(a,b){var c=this;return e(this,function(d){d.getFile(a,{create:!1},function(){b&&c.lambda(b).call(c,!0)},function(){b&&c.lambda(b).call(c,!1)})}),this},all:function(a){var b=this;return a&&this.keys(function(c){c.length?b.get(c,function(c){b.fn(b.name,a).call(b,c)}):b.fn(b.name,a).call(b,[])}),this},remove:function(a,c){var d=this,f=function(a){b(a),c&&d.lambda(c).call(d)};return e(this,function(b){b.getFile("string"==typeof a?a:a.key,{create:!1},function(a){a.remove(function(){c&&d.lambda(c).call(d)},f)},f)}),this},nuke:function(a){var b=this,c=0;return this.keys(function(d){if(d.length)for(var e=0,f=d.length;f>e;e++)b.remove(d[e],function(){c++,c===f&&a&&b.lambda(a).call(b)});else a&&b.lambda(a).call(b)}),this}}}(this)),f.adapter("memory",function(){var a={};return{valid:function(){return!0},init:function(b,c){a[this.name]=a[this.name]||{index:[],store:{}},this.index=a[this.name].index,this.store=a[this.name].store;var d=this.fn(this.name,c);return d&&d.call(this,this),this},keys:function(a){return this.fn("keys",a).call(this,this.index),this},save:function(a,b){var c=a.key||this.uuid();return this.exists(c,function(d){d||(a.key&&delete a.key,this.index.push(c)),this.store[c]=a,b&&(a.key=c,this.lambda(b).call(this,a))}),this},batch:function(a,b){for(var c=[],d=0,e=a.length;e>d;d++)this.save(a[d],function(a){c.push(a)});return b&&this.lambda(b).call(this,c),this},get:function(a,b){var c;if(this.isArray(a)){c=[];for(var d=0,e=a.length;e>d;d++)c.push(this.store[a[d]])}else c=this.store[a],c&&(c.key=a);return b&&this.lambda(b).call(this,c),this},exists:function(a,b){return this.lambda(b).call(this,!!this.store[a]),this},all:function(a){for(var b=[],c=0,d=this.index.length;d>c;c++){var e=this.store[this.index[c]];e.key=this.index[c],b.push(e)}return this.fn(this.name,a).call(this,b),this},remove:function(a,b){for(var c=this.isArray(a)?a:[a],d=0,e=c.length;e>d;d++){var f=c[d].key?c[d].key:c[d],g=this.indexOf(this.index,f);0>g||(delete this.store[f],this.index.splice(g,1))}return b&&this.lambda(b).call(this),this},nuke:function(b){return this.store=a[this.name].store={},this.index=a[this.name].index=[],b&&this.lambda(b).call(this),this}}}()),e("undefined"!=typeof f?f:window.Lawnchair)}.call(c,void 0,void 0,void 0,void 0,function(a){b.exports=a})}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],3:[function(a,b,c){var d=a("./v1"),e=a("./v4"),f=e;f.v1=d,f.v4=e,b.exports=f},{"./v1":6,"./v4":7}],4:[function(a,b,c){function d(a,b){var c=b||0,d=e;return d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+"-"+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]+d[a[c++]]}for(var e=[],f=0;256>f;++f)e[f]=(f+256).toString(16).substr(1);b.exports=d},{}],5:[function(a,b,c){(function(a){var c,d=a.crypto||a.msCrypto;if(d&&d.getRandomValues){var e=new Uint8Array(16);c=function(){return d.getRandomValues(e),e}}if(!c){var f=new Array(16);c=function(){for(var a,b=0;16>b;b++)0===(3&b)&&(a=4294967296*Math.random()),f[b]=a>>>((3&b)<<3)&255;return f}}b.exports=c}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],6:[function(a,b,c){function d(a,b,c){var d=b&&c||0,e=b||[];a=a||{};var g=void 0!==a.clockseq?a.clockseq:i,l=void 0!==a.msecs?a.msecs:(new Date).getTime(),m=void 0!==a.nsecs?a.nsecs:k+1,n=l-j+(m-k)/1e4;if(0>n&&void 0===a.clockseq&&(g=g+1&16383),(0>n||l>j)&&void 0===a.nsecs&&(m=0),m>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");j=l,k=m,i=g,l+=122192928e5;var o=(1e4*(268435455&l)+m)%4294967296;e[d++]=o>>>24&255,e[d++]=o>>>16&255,e[d++]=o>>>8&255,e[d++]=255&o;var p=l/4294967296*1e4&268435455;e[d++]=p>>>8&255,e[d++]=255&p,e[d++]=p>>>24&15|16,e[d++]=p>>>16&255,e[d++]=g>>>8|128,e[d++]=255&g;for(var q=a.node||h,r=0;6>r;++r)e[d+r]=q[r];return b?b:f(e)}var e=a("./lib/rng"),f=a("./lib/bytesToUuid"),g=e(),h=[1|g[0],g[1],g[2],g[3],g[4],g[5]],i=16383&(g[6]<<8|g[7]),j=0,k=0;b.exports=d},{"./lib/bytesToUuid":4,"./lib/rng":5}],7:[function(a,b,c){function d(a,b,c){var d=b&&c||0;"string"==typeof a&&(b="binary"==a?new Array(16):null,a=null),a=a||{};var g=a.random||(a.rng||e)();if(g[6]=15&g[6]|64,g[8]=63&g[8]|128,b)for(var h=0;16>h;++h)b[d+h]=g[h];return b||f(g)}var e=a("./lib/rng"),f=a("./lib/bytesToUuid");b.exports=d},{"./lib/bytesToUuid":4,"./lib/rng":5}],8:[function(a,b,c){function d(){if(window&&window.device)return window.device.uuid;if(navigator&&navigator.device)return navigator.device.uuid;if(window&&window.localStorage){var a=window.localStorage.getItem(f);return a||(a=e(),localStorage.setItem(f,a)),a}throw Error("Cannot create and store client id")}var e=a("uuid").v1,f="feedhenry_sync_client";b.exports={getClientId:d}},{uuid:3}],9:[function(a,b,c){var d,e,f=a("./clientIdProvider"),g=function(a,b,c){e||(e="/sync/");var g=d+e+a.dataset_id,h=a.req;h.__fh={cuid:f.getClientId()};var i=JSON.stringify(h),j=new XMLHttpRequest;j.open("POST",g,!0),j.setRequestHeader("Content-type","application/json; charset=utf-8"),j.onreadystatechange=function(){if(j.readyState===XMLHttpRequest.DONE)if(j.status>=200&&j.status<300||304===j.status){var a;try{j.responseText&&(a=JSON.parse(j.responseText))}catch(d){return c(d)}b(a)}else c(j.responseText)},j.send(i)},h=function(a,b){d=a,e=b};b.exports={handler:g,init:h}},{"./clientIdProvider":8}],10:[function(a,b,c){var d=a("./sync-client"),e=window.$fh=window.$fh||{};e.sync=d,b.exports=e.sync},{"./sync-client":11}],11:[function(a,b,c){var d=a("../libs/generated/crypto"),e=a("../libs/generated/lawnchair"),f=a("./cloudHandler"),g={defaults:{sync_frequency:10,auto_sync_local_updates:!0,notify_client_storage_failed:!0,notify_sync_started:!0,notify_sync_complete:!0,notify_offline_update:!0,notify_collision_detected:!0,notify_remote_update_failed:!0,notify_local_update_applied:!0,notify_remote_update_applied:!0,notify_delta_received:!0,notify_record_delta_received:!0,notify_sync_failed:!0,do_console_log:!1,crashed_count_wait:10,resend_crashed_updates:!0,sync_active:!0,storage_strategy:"html5-filesystem",file_system_quota:61644800,icloud_backup:!1},notifications:{CLIENT_STORAGE_FAILED:"client_storage_failed",SYNC_STARTED:"sync_started",SYNC_COMPLETE:"sync_complete",OFFLINE_UPDATE:"offline_update",COLLISION_DETECTED:"collision_detected",REMOTE_UPDATE_FAILED:"remote_update_failed",REMOTE_UPDATE_APPLIED:"remote_update_applied",LOCAL_UPDATE_APPLIED:"local_update_applied",DELTA_RECEIVED:"delta_received",RECORD_DELTA_RECEIVED:"record_delta_received",SYNC_FAILED:"sync_failed"},datasets:{},config:void 0,notify_callback:void 0,notify_callback_map:{},init_is_called:!1,uid_map:{},init:function(a){g.consoleLog("sync - init called"),g.config=JSON.parse(JSON.stringify(g.defaults));for(var b in a)g.config[b]=a[b];g.init_is_called||(g.init_is_called=!0,g.datasetMonitor()),f.init(g.config.cloudUrl,g.config.cloudPath)},notify:function(a,b){1===arguments.length&&"function"==typeof a?g.notify_callback=a:g.notify_callback_map[a]=b},manage:function(a,b,c,d,e){g.consoleLog("manage - START"),g.config||(g.config=JSON.parse(JSON.stringify(g.defaults)));var f=b||{},h=function(b){g.consoleLog("doManage dataset :: initialised = "+b.initialised+" :: "+a+" :: "+JSON.stringify(f));var h=b.config?b.config:g.config,i=g.setOptions(h,f);
b.query_params=c||b.query_params||{},b.meta_data=d||b.meta_data||{},b.config=i,b.syncRunning=!1,b.syncPending=!0,b.initialised=!0,"undefined"==typeof b.meta&&(b.meta={}),g.saveDataSet(a,function(){e&&e()})};g.getDataSet(a,function(a){g.consoleLog("manage - dataset already loaded"),h(a)},function(b){g.consoleLog("manage - dataset not loaded... trying to load"),g.loadDataSet(a,function(b){g.consoleLog("manage - dataset loaded from local storage"),g.doNotify(a,null,g.notifications.LOCAL_UPDATE_APPLIED,"load"),h(b)},function(b){g.consoleLog("manage - Creating new dataset for id "+a);var c={};c.data={},c.pending={},c.meta={},g.datasets[a]=c,h(c)})})},setOptions:function(a,b){a||(a=JSON.parse(JSON.stringify(g.defaults)));var c=JSON.parse(JSON.stringify(a)),d=JSON.parse(JSON.stringify(b));for(var e in d)c[e]=d[e];return c},list:function(a,b,c){g.getDataSet(a,function(a){if(a&&a.data){var d=JSON.parse(JSON.stringify(a.data));b(d)}else c&&c("no_data")},function(a,b){c&&c(a,b)})},getUID:function(a){var b=g.uid_map[a];return b||0===b?b:a},create:function(a,b,c,d){return null==b&&d?d("null_data"):void g.addPendingObj(a,null,b,"create",c,d)},read:function(a,b,c,d){g.getDataSet(a,function(a){b=g.getUID(b);var e=a.data[b];if(e){var f=JSON.parse(JSON.stringify(e));c(f)}else d("unknown_uid")},function(a,b){d&&d(a,b)})},update:function(a,b,c,d,e){b=g.getUID(b),g.addPendingObj(a,b,c,"update",d,e)},"delete":function(a,b,c,d){b=g.getUID(b),g.addPendingObj(a,b,null,"delete",c,d)},getPending:function(a,b){g.getDataSet(a,function(a){var c;a&&(c=a.pending),b(c)},function(a,b){g.consoleLog(a)})},clearPending:function(a,b){g.getDataSet(a,function(c){c.pending={},g.saveDataSet(a,b)})},listCollisions:function(a,b,c){g.getDataSet(a,function(d){g.doCloudCall({dataset_id:a,req:{fn:"listCollisions",meta_data:d.meta_data}},b,c)},c)},removeCollision:function(a,b,c,d){g.getDataSet(a,function(e){g.doCloudCall({dataset_id:a,req:{fn:"removeCollision",hash:b,meta_data:e.meta_data}},c,d)})},isOnline:function(a){var b=!0;if("undefined"!=typeof navigator.onLine&&(b=navigator.onLine),b&&"undefined"!=typeof navigator.network&&"undefined"!=typeof navigator.network.connection){var c=navigator.network.connection.type;("none"===c||null===c)&&(b=!1)}return a(b)},doNotify:function(a,b,c,d){if(g.notify_callback||g.notify_callback_map[a]){var e=g.notify_callback_map[a]||g.notify_callback;if(g.config["notify_"+c]){var f={dataset_id:a,uid:b,code:c,message:d};setTimeout(function(){e(f)},0)}}},getDataSet:function(a,b,c){var d=g.datasets[a];d?b(d):c&&c("unknown_dataset "+a,a)},getQueryParams:function(a,b,c){var d=g.datasets[a];d?b(d.query_params):c&&c("unknown_dataset "+a,a)},setQueryParams:function(a,b,c,d){var e=g.datasets[a];e?(e.query_params=b,g.saveDataSet(a),c&&c(e.query_params)):d&&d("unknown_dataset "+a,a)},getMetaData:function(a,b,c){var d=g.datasets[a];d?b(d.meta_data):c&&c("unknown_dataset "+a,a)},setMetaData:function(a,b,c,d){var e=g.datasets[a];e?(e.meta_data=b,g.saveDataSet(a),c&&c(e.meta_data)):d&&d("unknown_dataset "+a,a)},getConfig:function(a,b,c){var d=g.datasets[a];d?b(d.config):c&&c("unknown_dataset "+a,a)},setConfig:function(a,b,c,d){var e=g.datasets[a];if(e){var f=g.setOptions(e.config,b);e.config=f,g.saveDataSet(a),c&&c(e.config)}else d&&d("unknown_dataset "+a,a)},stopSync:function(a,b,c){g.setConfig(a,{sync_active:!1},function(){b&&b()},c)},startSync:function(a,b,c){g.setConfig(a,{sync_active:!0},function(){b&&b()},c)},doSync:function(a,b,c){var d=g.datasets[a];d?(d.syncPending=!0,g.saveDataSet(a),b&&b()):c&&c("unknown_dataset "+a,a)},forceSync:function(a,b,c){var d=g.datasets[a];d?(d.syncForced=!0,g.saveDataSet(a),b&&b()):c&&c("unknown_dataset "+a,a)},sortObject:function(a){if("object"!=typeof a||null===a)return a;var b=[];return Object.keys(a).sort().forEach(function(c){b.push({key:c,value:g.sortObject(a[c])})}),b},sortedStringify:function(a){var b="";try{b=JSON.stringify(g.sortObject(a))}catch(c){console.error("Error stringifying sorted object:"+c)}return b},generateHash:function(a){var b=g.getHashMethod(g.sortedStringify(a));return b.toString()},addPendingObj:function(a,b,c,d,e,f){function h(c){c.hash=c.hash||g.generateHash(c),g.getDataSet(a,function(f){f.pending[c.hash]=c,g.updateDatasetFromLocal(f,c),g.config.auto_sync_local_updates&&(f.syncPending=!0),g.saveDataSet(a),g.doNotify(a,b,g.notifications.LOCAL_UPDATE_APPLIED,d),e(c)},function(a,b){f&&f(a,b)})}g.isOnline(function(c){c||g.doNotify(a,b,g.notifications.OFFLINE_UPDATE,d)});var i={};i.inFlight=!1,i.action=d,i.post=JSON.parse(JSON.stringify(c)),i.postHash=g.generateHash(i.post),i.timestamp=(new Date).getTime(),"create"===d?(i.hash=g.generateHash(i),i.uid=i.hash,h(i)):g.read(a,b,function(a){i.uid=b,i.pre=a.data,i.preHash=g.generateHash(a.data),h(i)},function(a,b){f&&f(a,b)})},syncLoop:function(a){g.getDataSet(a,function(b){b.syncPending=!1,b.syncRunning=!0,b.syncLoopStart=(new Date).getTime(),g.doNotify(a,null,g.notifications.SYNC_STARTED,null),g.isOnline(function(c){if(c){var d={};d.fn="sync",d.dataset_id=a,d.query_params=b.query_params,d.config=b.config,d.meta_data=b.meta_data,d.dataset_hash=b.hash,d.acknowledgements=b.acknowledgements||[];var e=b.pending,f=[];for(var h in e)e[h].inFlight||e[h].crashed||e[h].delayed||(e[h].inFlight=!0,e[h].inFlightDate=(new Date).getTime(),f.push(e[h]));d.pending=f,f.length>0&&g.consoleLog("Starting sync loop - global hash = "+b.hash+" :: params = "+JSON.stringify(d,null,2)),g.doCloudCall({dataset_id:a,req:d},function(c){function d(c,d,f){if(c)for(var h in c)e=c[h],f.push(e),b.pending[h]&&b.pending[h].inFlight&&(delete b.pending[h],g.doNotify(a,e.uid,d,e))}var e;if(g.updateCrashedInFlightFromNewData(a,b,c),g.updateDelayedFromNewData(a,b,c),g.updateMetaFromNewData(a,b,c),c.updates){var f=[];g.checkUidChanges(b,c.updates.applied),d(c.updates.applied,g.notifications.REMOTE_UPDATE_APPLIED,f),d(c.updates.failed,g.notifications.REMOTE_UPDATE_FAILED,f),d(c.updates.collisions,g.notifications.COLLISION_DETECTED,f),b.acknowledgements=f}c.hash&&c.hash!==b.hash?(g.consoleLog("Local dataset stale - syncing records :: local hash= "+b.hash+" - remoteHash="+c.hash),g.syncRecords(a)):(g.consoleLog("Local dataset up to date"),g.syncComplete(a,"online",g.notifications.SYNC_COMPLETE))},function(c,d){g.markInFlightAsCrashed(b),g.consoleLog("syncLoop failed : msg="+c+" :: err = "+d),g.syncComplete(a,c,g.notifications.SYNC_FAILED)})}else g.syncComplete(a,"offline",g.notifications.SYNC_FAILED)})})},syncRecords:function(a){g.getDataSet(a,function(b){var c=b.data||{},d={};for(var e in c){var f=e,h=c[e].hash;d[f]=h}var i={};i.fn="syncRecords",i.dataset_id=a,i.query_params=b.query_params,i.clientRecs=d,g.consoleLog("syncRecParams :: "+JSON.stringify(i)),g.doCloudCall({dataset_id:a,req:i},function(d){g.consoleLog("syncRecords Res before applying pending changes :: "+JSON.stringify(d)),g.applyPendingChangesToRecords(b,d),g.consoleLog("syncRecords Res after apply pending changes :: "+JSON.stringify(d));var e;if(d.create)for(e in d.create)c[e]={hash:d.create[e].hash,data:d.create[e].data},g.doNotify(a,e,g.notifications.RECORD_DELTA_RECEIVED,"create");if(d.update)for(e in d.update)c[e].hash=d.update[e].hash,c[e].data=d.update[e].data,g.doNotify(a,e,g.notifications.RECORD_DELTA_RECEIVED,"update");if(d["delete"])for(e in d["delete"])delete c[e],g.doNotify(a,e,g.notifications.RECORD_DELTA_RECEIVED,"delete");g.doNotify(a,d.hash,g.notifications.DELTA_RECEIVED,"partial dataset"),b.data=c,d.hash&&(b.hash=d.hash),g.syncComplete(a,"online",g.notifications.SYNC_COMPLETE)},function(b,c){g.consoleLog("syncRecords failed : msg="+b+" :: err="+c),g.syncComplete(a,b,g.notifications.SYNC_FAILED)})})},syncComplete:function(a,b,c){g.getDataSet(a,function(d){d.syncRunning=!1,d.syncLoopEnd=(new Date).getTime(),g.saveDataSet(a),g.doNotify(a,d.hash,c,b)})},applyPendingChangesToRecords:function(a,b){var c=a.pending;for(var d in c)if(c.hasOwnProperty(d)){var e=c[d],f=e.uid;if(b.create){var g=b.create;g&&g[f]&&delete g[f]}if(b.update){var h=b.update;h&&h[f]&&delete h[f]}if(b["delete"]){var i=b["delete"];i&&i[f]&&delete i[f]}}},checkUidChanges:function(a,b){if(b){var c={},d=0;for(var e in b)if(b.hasOwnProperty(e)){var f=b[e],h=f.action;if(h&&"create"===h){var i=f.uid,j=f.hash;d++,g.uid_map[j]=i,c[j]=i;var k=a.data[j];k&&(a.data[i]=k,delete a.data[j]);var l=a.meta[j];l&&(a.meta[i]=l,delete a.meta[j])}}if(d>0)for(var m in a.pending)if(a.pending.hasOwnProperty(m)){var n=a.pending[m],o=n.uid;c[o]&&(n.uid=c[o])}}},checkDatasets:function(){for(var a in g.datasets)if(g.datasets.hasOwnProperty(a)){var b=g.datasets[a];if(b&&!b.syncRunning&&(b.config.sync_active||b.syncForced)){var c=b.syncLoopStart,d=b.syncLoopEnd;if(b.syncForced)b.syncPending=!0;else if(null==c)g.consoleLog(a+" - Performing initial sync"),b.syncPending=!0;else if(null!=d){var e=(new Date).getTime()-d,f=1e3*b.config.sync_frequency;e>f&&(b.syncPending=!0)}b.syncPending&&(b.syncForced=!1,g.syncLoop(a))}}},setCloudHandler:function(a){g.cloudHandler=a},doCloudCall:function(a,b,c){g.cloudHandler&&"function"==typeof g.cloudHandler?g.cloudHandler(a,b,c):console.log("Missing cloud handler for sync. Please refer to documentation")},datasetMonitor:function(){g.checkDatasets(),setTimeout(function(){g.datasetMonitor()},500)},setStorageAdapter:function(a){g.getStorageAdapter=a},setHashMethod:function(a){g.getHashMethod=a},getStorageAdapter:function(a,b,c){var d=function(c,d){var e=(b?"save to":"load from")+" local storage failed msg: "+c+" err: "+d;g.doNotify(a,null,g.notifications.CLIENT_STORAGE_FAILED,e),g.consoleLog(e)};e({fail:d,adapter:g.config.storage_strategy,size:g.config.file_system_quota,backup:g.config.icloud_backup},function(){return c(null,this)})},getHashMethod:d.SHA1,saveDataSet:function(a,b){g.getDataSet(a,function(c){g.getStorageAdapter(a,!0,function(d,e){e.save({key:"dataset_"+a,val:c},function(){return b?b():void 0})})})},loadDataSet:function(a,b,c){g.getStorageAdapter(a,!1,function(d,e){e.get("dataset_"+a,function(d){if(d&&d.val){var e=d.val;if("string"==typeof e&&(e=JSON.parse(e)),e.initialised=!1,g.datasets[a]=e,g.consoleLog("load from local storage success for dataset_id :"+a),b)return b(e)}else if(c)return c()})})},clearCache:function(a,b){delete g.datasets[a],g.notify_callback_map[a]=null,g.getStorageAdapter(a,!0,function(c,d){d.remove("dataset_"+a,function(){return g.consoleLog("local cache is cleared for dataset : "+a),b?b():void 0})})},updateDatasetFromLocal:function(a,b){var c,d,e=a.pending,f=b.uid;g.consoleLog("updating local dataset for uid "+f+" - action = "+b.action),a.meta[f]=a.meta[f]||{},"create"===b.action&&(a.data[f]&&(g.consoleLog("dataset already exists for uid in create :: "+JSON.stringify(a.data[f])),a.meta[f].fromPending&&(c=a.meta[f].pendingUid,delete e[c])),a.data[f]={}),"update"===b.action&&a.data[f]&&a.meta[f].fromPending&&(g.consoleLog("updating an existing pending record for dataset :: "+JSON.stringify(a.data[f])),c=a.meta[f].pendingUid,d=e[c],d&&(d.inFlight?(g.consoleLog("existing in-inflight pending record = "+JSON.stringify(d)),b.delayed=!0,b.waiting=d.hash):(g.consoleLog("existing pre-flight pending record = "+JSON.stringify(d)),d.post=b.post,d.postHash=b.postHash,delete e[b.hash],b.hash=c))),"delete"===b.action&&a.data[f]&&(a.meta[f].fromPending&&(g.consoleLog("Deleting an existing pending record for dataset :: "+JSON.stringify(a.data[f])),c=a.meta[f].pendingUid,d=e[c],d&&(d.inFlight?(g.consoleLog("existing in-inflight pending record = "+JSON.stringify(d)),b.delayed=!0,b.waiting=d.hash):(g.consoleLog("existing pending record = "+JSON.stringify(d)),"create"===d.action&&(delete e[b.hash],delete e[c]),"update"===d.action&&(b.pre=d.pre,b.preHash=d.preHash,b.inFlight=!1,delete e[c])))),delete a.data[f]),a.data[f]&&(a.data[f].data=b.post,a.data[f].hash=b.postHash,a.meta[f].fromPending=!0,a.meta[f].pendingUid=b.hash)},updateCrashedInFlightFromNewData:function(a,b,c){var d,e,f=({applied:g.notifications.REMOTE_UPDATE_APPLIED,failed:g.notifications.REMOTE_UPDATE_FAILED,collisions:g.notifications.COLLISION_DETECTED},b.pending);if(f){for(d in f)if(f.hasOwnProperty(d)&&(e=f[d],e.inFlight&&e.crashed))if(g.consoleLog("updateCrashedInFlightFromNewData - Found crashed inFlight pending record uid="+e.uid+" :: hash="+e.hash),c&&c.updates&&c.updates.hashes){var h=c.updates.hashes[d];h||(e.crashedCount?e.crashedCount++:e.crashedCount=1)}else e.crashedCount?e.crashedCount++:e.crashedCount=1;for(d in f)f.hasOwnProperty(d)&&(e=f[d],e.inFlight&&e.crashed&&e.crashedCount>b.config.crashed_count_wait&&(g.consoleLog("updateCrashedInFlightFromNewData - Crashed inflight pending record has reached crashed_count_wait limit : "+JSON.stringify(e)),g.consoleLog("updateCrashedInFlightFromNewData - Retryig crashed inflight pending record"),e.crashed=!1,e.inFlight=!1))}},updateDelayedFromNewData:function(a,b,c){var d,e,f=b.pending;if(f)for(d in f)if(f.hasOwnProperty(d)&&(e=f[d],e.delayed&&e.waiting&&(g.consoleLog("updateDelayedFromNewData - Found delayed pending record uid="+e.uid+" :: hash="+e.hash+" :: waiting="+e.waiting),c&&c.updates&&c.updates.hashes))){var h=c.updates.hashes[e.waiting];h&&(g.consoleLog("updateDelayedFromNewData - Waiting pending record is resolved rec="+JSON.stringify(h)),e.delayed=!1,e.waiting=void 0)}},updateMetaFromNewData:function(a,b,c){var d=b.meta;if(d&&c&&c.updates&&c.updates.hashes)for(var e in d)if(d.hasOwnProperty(e)){var f=d[e],h=f.pendingUid;g.consoleLog("updateMetaFromNewData - Found metadata with uid = "+e+" :: pendingHash = "+h);var i=!0;if(h){i=!1;var j=c.updates.hashes[h];j&&(g.consoleLog("updateMetaFromNewData - Found pendingUid in meta data resolved - resolved = "+JSON.stringify(j)),f.pendingUid=void 0,i=!0)}i&&(g.consoleLog("updateMetaFromNewData - both previous and current pendings are resolved for meta data with uid "+e+". Delete it."),delete d[e])}},markInFlightAsCrashed:function(a){var b,c,d=a.pending;if(d){var e={};for(b in d)d.hasOwnProperty(b)&&(c=d[b],c.inFlight&&(g.consoleLog("Marking in flight pending record as crashed : "+b),c.crashed=!0,e[c.uid]=c))}},consoleLog:function(a){g.config.do_console_log&&console.log(a)}};!function(){g.config=g.defaults}(),g.setCloudHandler(f.handler),b.exports={init:g.init,manage:g.manage,notify:g.notify,doList:g.list,getUID:g.getUID,doCreate:g.create,doRead:g.read,doUpdate:g.update,doDelete:g["delete"],listCollisions:g.listCollisions,removeCollision:g.removeCollision,getPending:g.getPending,clearPending:g.clearPending,getDataset:g.getDataSet,getQueryParams:g.getQueryParams,setQueryParams:g.setQueryParams,getMetaData:g.getMetaData,setMetaData:g.setMetaData,getConfig:g.getConfig,setConfig:g.setConfig,startSync:g.startSync,stopSync:g.stopSync,doSync:g.doSync,forceSync:g.forceSync,generateHash:g.generateHash,loadDataSet:g.loadDataSet,clearCache:g.clearCache,setCloudHandler:g.setCloudHandler,doCloudCall:g.doCloudCall,setStorageAdapter:g.setStorageAdapter,setHashMethod:g.setHashMethod}},{"../libs/generated/crypto":1,"../libs/generated/lawnchair":2,"./cloudHandler":9}]},{},[10])(10)});
// Type definitions for fh-sync-js 2.18.0
// Project: https://github.com/feedhenry/fh-sync-js
// Definitions by: Aiden Keating <akeating@redhat.com>
// Definitions by: feedhenry-raincatcher@redhat.com
/** @module SyncClient */
declare module SyncClient {
/**
* Interface for the data provided in the NotifyCallback in the notify function.
*
* @interface NotificationData
*/
interface NotificationData {
dataset_id: string;
uid: string;
message?: string;
code: string;
}
/**
* Interface for the options object provided to the init function.
*
* @interface SyncOptions
*/
interface SyncOptions {
sync_frequency?: number;
auto_sync_local_updates?: boolean;
notify_client_storage_failed?: boolean;
notify_sync_started?: boolean;
notify_sync_complete?: boolean;
notify_offline_update?: boolean;
notify_collision_detected?: boolean;
notify_local_update_applied?: boolean;
notify_remote_update_failed?: boolean;
notify_remote_update_applied?: boolean;
notify_delta_received?: boolean;
notify_record_delta_received?: boolean;
notify_sync_failed?: boolean;
do_console_log?: boolean;
crashed_count_wait?: number;
resend_crashed_updates?: boolean;
sync_active?: boolean;
storage_strategy?: "html5-filesystem" | "dom" | "webkit-sqlite" | "indexed-db";
file_system_quota?: number;
icloud_backup?: boolean;
}
/**
* Interface for the data provided in the NotifyCallback in the notify function.
* @interface NotificationData
*/
interface NotificationData {
dataset_id: string;
uid: string;
message?: string;
code: string;
}
/**
* Interface for the callback used in the notify function.
*
* @interface NotifyCallback
*/
interface NotifyCallback {
(data: NotificationData)
}
/**
* Interface for the options object provided to the init function.
*
* @interface SyncOptions
*/
interface SyncOptions {
/**
* Sync cloud url (used by default handler to call server)
*/
cloudUrl: string,
/**
* Initialize the client data sync service.
*
* @param {Object} options
* @param {Number} [options.sync_frequency=10] - How often to synchronize data with the cloud, in seconds.
* @param {Boolean} [options.auto_sync_local_updates=true] - Should local changes be synchronized to the cloud immediately, or should they wait for the next synchronization interval.
* @param {Boolean} [options.notify_client_storage_failed=true] - Should a notification event be triggered when loading or saving to client storage fails.
* @param {Boolean} [options.notify_sync_started=true] - Should a notification event be triggered when a synchronization cycle with the server has been started.
* @param {Boolean} [options.notify_sync_complete=true] - Should a notification event be triggered when a synchronization cycle with the server has been completed.
* @param {Boolean} [options.notify_offline_update=true] - Should a notification event be triggered when an attempt was made to update a record while offline.
* @param {Boolean} [options.notify_collision_detected=true] - Should a notification event be triggered when an update failed due to data collision.
* @param {Boolean} [options.notify_local_update_applied=true] - Should a notification event be triggered when an update was applied to the local data store.
* @param {Boolean} [options.notify_remote_update_failed=true] - Should a notification event be triggered when an update failed for a reason other than data collision.
* @param {Boolean} [options.notify_remote_update_applied=true] - Should a notification event be triggered when an update was applied to the remote data store.
* @param {Boolean} [options.notify_delta_received=true] - Should a notification event be triggered when a delta was received from the remote data store.
* @param {Boolean} [options.notify_record_delta_received=true] - Should a notification event be triggered when a delta was received from the remote data store for a record.
* @param {Boolean} [options.notify_sync_failed=true] - Should a notification event be triggered when the synchronization loop failed to complete.
* @param {Boolean} [options.do_console_log=false] - Should log statements be written to console.log. Will be useful for debugging.
* @param {Number} [options.crashed_count_wait=10] - How many synchronization cycles to check for updates on crashed in-flight updates.
* @param {Boolean} [options.resend_crashed_updates=true] - If crashed_count_wait limit is reached, should the client retry sending the crashed in flight pending records.
* @param {Boolean} [options.sync_active=true] - Is the background synchronization with the cloud currently active. If this is set to false, the synchronization loop will not start automatically. You need to call startSync to start the synchronization loop.
* @param {String} [options.storage_strategy=html5_filesystem] - Storage strategy to use for the underlying client storage framework Lawnchair. Valid values include 'dom', 'html5-filesystem', 'webkit-sqlite', 'indexed-db'. Multiple values can be specified as an array and the first valid storage option will be used. If the app is running on Titanium, the only support value is 'titanium'.
* @param {Number} [options.file_system_quota=52428800] - Amount of space to request from the HTML5 filesystem API when running in browser
* @param {Boolean} [options.icloud_backup=false] - iOS only. If set to true, the file will be backed by iCloud.
*/
function init(options: SyncOptions);
/**
* How often to synchronize data with the cloud, in seconds.
* Optional. Default: 10
*/
sync_frequency?: number,
/**
* Register a callback function to be invoked when the sync service has notifications to communicate to the client.
*
* @param {Function} callback
*/
function notify(dataset_id:string, callback:NotifyCallback);
/**
* Put a dataset under the management of the sync service.
*
* @param {String} datasetId
* @param {Object} options
* @param {Number} [options.sync_frequency=10] - How often to synchronize data with the cloud, in seconds.
* @param {Boolean} [options.auto_sync_local_updates=true] - Should local changes be synchronized to the cloud immediately, or should they wait for the next synchronization interval.
* @param {Boolean} [options.notify_client_storage_failed=true] - Should a notification event be triggered when loading or saving to client storage fails.
* @param {Boolean} [options.notify_sync_started=true] - Should a notification event be triggered when a synchronization cycle with the server has been started.
* @param {Boolean} [options.notify_sync_complete=true] - Should a notification event be triggered when a synchronization cycle with the server has been completed.
* @param {Boolean} [options.notify_offline_update=true] - Should a notification event be triggered when an attempt was made to update a record while offline.
* @param {Boolean} [options.notify_collision_detected=true] - Should a notification event be triggered when an update failed due to data collision.
* @param {Boolean} [options.notify_local_update_applied=true] - Should a notification event be triggered when an update was applied to the local data store.
* @param {Boolean} [options.notify_remote_update_failed=true] - Should a notification event be triggered when an update failed for a reason other than data collision.
* @param {Boolean} [options.notify_remote_update_applied=true] - Should a notification event be triggered when an update was applied to the remote data store.
* @param {Boolean} [options.notify_delta_received=true] - Should a notification event be triggered when a delta was received from the remote data store.
* @param {Boolean} [options.notify_record_delta_received=true] - Should a notification event be triggered when a delta was received from the remote data store for a record.
* @param {Boolean} [options.notify_sync_failed=true] - Should a notification event be triggered when the synchronization loop failed to complete.
* @param {Boolean} [options.do_console_log=false] - Should log statements be written to console.log. Will be useful for debugging.
* @param {Number} [options.crashed_count_wait=10] - How many synchronization cycles to check for updates on crashed in-flight updates.
* @param {Boolean} [options.resend_crashed_updates=true] - If crashed_count_wait limit is reached, should the client retry sending the crashed in flight pending records.
* @param {Boolean} [options.sync_active=true] - Is the background synchronization with the cloud currently active. If this is set to false, the synchronization loop will not start automatically. You need to call startSync to start the synchronization loop.
* @param {String} [options.storage_strategy=html5_filesystem] - Storage strategy to use for the underlying client storage framework Lawnchair. Valid values include 'dom', 'html5-filesystem', 'webkit-sqlite', 'indexed-db'. Multiple values can be specified as an array and the first valid storage option will be used. If the app is running on Titanium, the only support value is 'titanium'.
* @param {Number} [options.file_system_quota=52428800] - Amount of space to request from the HTML5 filesystem API when running in browser
* @param {Boolean} [options.icloud_backup=false] - iOS only. If set to true, the file will be backed by iCloud.
* @param {Object} query_params
* @param {Object} meta_data
* @param {Function} callback
*/
function manage(datasetId: string, options: SyncOptions, query_params: {}, meta_data: {}, callback: () => void);
/**
* Should local changes be synchronized to the cloud immediately, or should they wait for the next synchronization interval.
* Optional. Default: true
*/
auto_sync_local_updates?: boolean,
/**
* Get a list of the records for the dataset.
*
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function doList(datasetId: string, success: (dataset: any) => void, failure: (err: string, datasetId: string) => void);
/**
* Should a notification event be triggered when loading or saving to client storage fails.
* Optional. Default: true
*/
notify_client_storage_failed?: boolean,
/**
* Update the data associated with the unique id.
*
* @param {String} datasetId
* @param {Object} data
* @param {Function} success
* @param {Function} [failure]
*/
function doCreate(datasetId: string, data: any, success: (obj: any) => void, failure?: (err: string, datasetId: string) => void);
/**
* Should a notification event be triggered when a synchronization cycle with the server has been started.
* Optional. Default: true
*/
notify_sync_started?: boolean,
/**
* Read a single data record.
*
* @param {String} datasetId
* @param {String} uid
* @param {Function} success
* @param {Function} failure
*/
function doRead(datasetId: string, uid: string, success: (record: any) => void, failure?: (err: string, datasetId: string) => void);
/**
* Should a notification event be triggered when a synchronization cycle with the server has been completed.
* Optional. Default: true
*/
notify_sync_complete?: boolean,
/**
* Update the data associated with the unique id.
*
* @param {String} datasetId
* @param {String} uid
* @param {Object} data
* @param {Function} success
* @param {Function} failure
*/
function doUpdate(datasetId: string, uid: string, data: any, success: (obj: any) => void, failure?: (err: string, datasetId: string) => void);
/**
* Should a notification event be triggered when an attempt was made to update a record while offline.
* Optional. Default: true
*/
notify_offline_update?: boolean,
/**
* Delete the data associated with the unique id.
*
* @param {String} datasetId
* @param {String} uid
* @param {Function} success
* @param {Function} failure
*/
function doDelete(datasetId: string, uid: string, success: (obj: any) => void, failure?: (err: string, datasetId: string) => void);
/**
* Should a notification event be triggered when an update failed due to data collision.
* Optional. Default: true
*/
notify_collision_detected?: boolean,
/**
* Start the sync loop if `sync_active` option is set to false.
*
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function startSync(datasetId: string, success: () => void, failure?: (obj: any) => void);
/**
* Should a notification event be triggered when an update was applied to the local data store.
* Optional. Default: true
*/
notify_local_update_applied?: boolean,
/**
* Stop the sync loop for a dataset.
*
* @param {String} datasetId
* @param {Function} [success]
* @param {Function} [failure]
*/
function stopSync(datasetId: string, success?: () => void, failure?: (obj: any) => void);
/**
* Should a notification event be triggered when an update failed for a reason other than data collision.
* Optional. Default: true
*/
notify_remote_update_failed?: boolean,
/**
* Run the sync loop almost immediately (within next 500 ms) if `sync_active` is true.
*
* @param {String} datasetId
* @param {Function} [success]
* @param {Function} [failure]
*/
function doSync(datasetId: string, success?: () => void, failure?: (err: string, datasetId: string) => void);
/**
* Should a notification event be triggered when an update was applied to the remote data store.
* Optional. Default: true
*/
notify_remote_update_applied?: boolean,
/**
* Run the sync loop almost immediately (within next 500 ms) even if `sync_active` is false.
*
* @param {String} datasetId
* @param {Function} [success]
* @param {Function} [failure]
*/
function forceSync(datasetId: string, success?: () => void, failure?: (err: string, datasetId: string) => void);
/**
* Should a notification event be triggered when a delta was received from the remote data store.
* Optional. Default: true
*/
notify_delta_received?: boolean,
/**
* List collisions in sync
*
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function listCollisions(datasetId: string, success: (res: any) => void, failure?: (msg: string, err: any) => void);
/**
* Should a notification event be triggered when a delta was received from the remote data store for a record.
* Optional. Default: true
*/
notify_record_delta_received?: boolean,
/**
* Remove a collision in sync
*
* @param {String} datasetId
* @param {String} collisionHash
* @param {Function} success
* @param {Function} failure
*/
function removeCollision(datasetId: string, collisionHash: string, success: (res: any) => void, failure: (msg: string, err: any) => void);
/**
* Should a notification event be triggered when the synchronization loop failed to complete.
* Optional. Default: true
*/
notify_sync_failed?: boolean,
/**
* @param {String} datasetId
* @param {Function} callback
*/
function getPending(datasetId: string, callback: () => void);
/**
* How many synchronization cycles to check for updates on crashed in-flight updates.
* Optional. Default: 10
*/
crashed_count_wait?: number,
/**
* @param {String} datasetId
* @param {Function} callback
*/
function clearPending(datasetId: string, callback: () => void);
/**
* If crashed_count_wait limit is reached, should the client retry sending the crashed in flight pending records.
* Optional. Default: true
*/
resend_crashed_updates?: boolean,
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function getDataSet(datasetId: string, success: (dataset: any) => void, failure: (err: string, datasetId: string) => void);
/**
* Is the background synchronization with the cloud currently active. If this is set to false, the synchronization loop will not start automatically.
* You need to call startSync to start the synchronization loop. Optional. Default: true
*/
sync_active?: boolean,
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function getQueryParams(datasetId: string, success: (queryParams: any) => void, failure: (err: string, datasetId: string) => void);
/**
* Storage strategy to use for the underlying client storage framework Lawnchair. Valid values include 'dom', 'html5-filesystem', 'webkit-sqlite', 'indexed-db'.
* Multiple values can be specified as an array and the first valid storage option will be used.
* Optional. Default: 'html5-filesystem'
*/
storage_strategy?: "html5-filesystem" | "dom" | "webkit-sqlite" | "indexed-db"
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function setQueryParams(datasetId: string, success: (queryParams: any) => void, failure: (err: string, datasetId: string) => void);
/**
* Amount of space to request from the HTML5 filesystem API when running in browser
* Optional. Default: 50 * 1024 * 1024
*/
file_system_quota?: number,
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function getMetaData(datasetId: string, success: (queryParams: any) => void, failure: (err: string, datasetId: string) => void);
/**
* iOS only. If set to true, the file will be backed by iCloud. Default to false;
*/
icloud_backup?: boolean
}
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function setMetaData(datasetId: string, metaData: any, success: (metaData: any) => void, failure: (err: string, datasetId: string) => void);
/**
* Interface for the callback used in the notify function.
*
* @interface NotifyCallback
*/
interface NotifyCallback {
(data: NotificationData): any
}
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function getConfig(datasetId: string, success: (config: any) => void, failure: (err: string, datasetId: string) => void);
/**
* Initialize the client data sync service.
*
* @param {Object} options
* @param {String} [options.cloudUrl=""] - Sync cloud url (used by default handler to call server)
* @param {Number} [options.sync_frequency=10] - How often to synchronize data with the cloud, in seconds.
* @param {Boolean} [options.auto_sync_local_updates=true] - Should local changes be synchronized to the cloud immediately, or should they wait for the next synchronization interval.
* @param {Boolean} [options.notify_client_storage_failed=true] - Should a notification event be triggered when loading or saving to client storage fails.
* @param {Boolean} [options.notify_sync_started=true] - Should a notification event be triggered when a synchronization cycle with the server has been started.
* @param {Boolean} [options.notify_sync_complete=true] - Should a notification event be triggered when a synchronization cycle with the server has been completed.
* @param {Boolean} [options.notify_offline_update=true] - Should a notification event be triggered when an attempt was made to update a record while offline.
* @param {Boolean} [options.notify_collision_detected=true] - Should a notification event be triggered when an update failed due to data collision.
* @param {Boolean} [options.notify_local_update_applied=true] - Should a notification event be triggered when an update was applied to the local data store.
* @param {Boolean} [options.notify_remote_update_failed=true] - Should a notification event be triggered when an update failed for a reason other than data collision.
* @param {Boolean} [options.notify_remote_update_applied=true] - Should a notification event be triggered when an update was applied to the remote data store.
* @param {Boolean} [options.notify_delta_received=true] - Should a notification event be triggered when a delta was received from the remote data store.
* @param {Boolean} [options.notify_record_delta_received=true] - Should a notification event be triggered when a delta was received from the remote data store for a record.
* @param {Boolean} [options.notify_sync_failed=true] - Should a notification event be triggered when the synchronization loop failed to complete.
* @param {Boolean} [options.do_console_log=false] - Should log statements be written to console.log. Will be useful for debugging.
* @param {Number} [options.crashed_count_wait=10] - How many synchronization cycles to check for updates on crashed in-flight updates.
* @param {Boolean} [options.resend_crashed_updates=true] - If crashed_count_wait limit is reached, should the client retry sending the crashed in flight pending records.
* @param {Boolean} [options.sync_active=true] - Is the background synchronization with the cloud currently active. If this is set to false, the synchronization loop will not start automatically. You need to call startSync to start the synchronization loop.
* @param {String} [options.storage_strategy=html5_filesystem] - Storage strategy to use for the underlying client storage framework Lawnchair. Valid values include 'dom', 'html5-filesystem', 'webkit-sqlite', 'indexed-db'. Multiple values can be specified as an array and the first valid storage option will be used. If the app is running on Titanium, the only support value is 'titanium'.
* @param {Number} [options.file_system_quota=52428800] - Amount of space to request from the HTML5 filesystem API when running in browser
* @param {Boolean} [options.icloud_backup=false] - iOS only. If set to true, the file will be backed by iCloud.
*/
function init(options: SyncOptions): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function setConfig(datasetId: string, config: any, success: (config: any) => void, failure: (err: string, datasetId: string) => void);
/**
* Register a callback function to be invoked when the sync service has notifications to communicate to the client.
*
* @param dataset_id - dataset identifier
* @param {Function} callback
*/
function notify(dataset_id: string, callback: NotifyCallback): void;
/**
* Put a dataset under the management of the sync service.
*
* @param {String} datasetId
* @param {Object} options
* @param {String} [options.cloudUrl=""] - Sync cloud url (used by default handler to call server)
* @param {Number} [options.sync_frequency=10] - How often to synchronize data with the cloud, in seconds.
* @param {Boolean} [options.auto_sync_local_updates=true] - Should local changes be synchronized to the cloud immediately, or should they wait for the next synchronization interval.
* @param {Boolean} [options.notify_client_storage_failed=true] - Should a notification event be triggered when loading or saving to client storage fails.
* @param {Boolean} [options.notify_sync_started=true] - Should a notification event be triggered when a synchronization cycle with the server has been started.
* @param {Boolean} [options.notify_sync_complete=true] - Should a notification event be triggered when a synchronization cycle with the server has been completed.
* @param {Boolean} [options.notify_offline_update=true] - Should a notification event be triggered when an attempt was made to update a record while offline.
* @param {Boolean} [options.notify_collision_detected=true] - Should a notification event be triggered when an update failed due to data collision.
* @param {Boolean} [options.notify_local_update_applied=true] - Should a notification event be triggered when an update was applied to the local data store.
* @param {Boolean} [options.notify_remote_update_failed=true] - Should a notification event be triggered when an update failed for a reason other than data collision.
* @param {Boolean} [options.notify_remote_update_applied=true] - Should a notification event be triggered when an update was applied to the remote data store.
* @param {Boolean} [options.notify_delta_received=true] - Should a notification event be triggered when a delta was received from the remote data store.
* @param {Boolean} [options.notify_record_delta_received=true] - Should a notification event be triggered when a delta was received from the remote data store for a record.
* @param {Boolean} [options.notify_sync_failed=true] - Should a notification event be triggered when the synchronization loop failed to complete.
* @param {Boolean} [options.do_console_log=false] - Should log statements be written to console.log. Will be useful for debugging.
* @param {Number} [options.crashed_count_wait=10] - How many synchronization cycles to check for updates on crashed in-flight updates.
* @param {Boolean} [options.resend_crashed_updates=true] - If crashed_count_wait limit is reached, should the client retry sending the crashed in flight pending records.
* @param {Boolean} [options.sync_active=true] - Is the background synchronization with the cloud currently active. If this is set to false, the synchronization loop will not start automatically. You need to call startSync to start the synchronization loop.
* @param {String} [options.storage_strategy=html5_filesystem] - Storage strategy to use for the underlying client storage framework Lawnchair. Valid values include 'dom', 'html5-filesystem', 'webkit-sqlite', 'indexed-db'. Multiple values can be specified as an array and the first valid storage option will be used. If the app is running on Titanium, the only support value is 'titanium'.
* @param {Number} [options.file_system_quota=52428800] - Amount of space to request from the HTML5 filesystem API when running in browser
* @param {Boolean} [options.icloud_backup=false] - iOS only. If set to true, the file will be backed by iCloud.
* @param {Object} query_params
* @param {Object} meta_data
* @param {Function} callback
*/
function manage(datasetId: string, options: SyncOptions, query_params: {}, meta_data: {}, callback: () => void): void;
/**
* Produces a SHA1 hash of the provided object (sorted before hash) or string.
*
* @param {Object|String} toHash - Object to hash
* @returns {String} - SHA1 hash of the provided string or object.
*/
function generateHash(toHash: {} | string): string;
/**
* Get a list of the records for the dataset.
*
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function doList(datasetId: string, success: (dataset: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function loadDataSet(datasetId: string, success: (dataset: any) => void, failure: () => void);
/**
* Update the data associated with the unique id.
*
* @param {String} datasetId
* @param {Object} data
* @param {Function} success
* @param {Function} [failure]
*/
function doCreate(datasetId: string, data: any, success: (obj: any) => void, failure?: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} callback
*/
function clearCache(datasetId: string, callback?: () => void);
/**
* Read a single data record.
*
* @param {String} datasetId
* @param {String} uid
* @param {Function} success
* @param {Function} failure
*/
function doRead(datasetId: string, uid: string, success: (record: any) => void, failure?: (err: string, datasetId: string) => void): void;
/**
* Sets cloud call handler for sync. Required to make any sync requests to the server side (sync cloud)
*/
function setCloudHandler(handler: (params: any, success: (result:any) => void, failure: (error:any) => void) => void);
/**
* Allows to override default storage adapter
*
* @param handler - function that wraps underlying storage solution
*/
function setStorageAdapter(handler: (dataset_id:string, isSave: boolean, cb: any) => void);
/**
* Update the data associated with the unique id.
*
* @param {String} datasetId
* @param {String} uid
* @param {Object} data
* @param {Function} success
* @param {Function} failure
*/
function doUpdate(datasetId: string, uid: string, data: any, success: (obj: any) => void, failure?: (err: string, datasetId: string) => void): void;
/**
* Delete the data associated with the unique id.
*
* @param {String} datasetId
* @param {String} uid
* @param {Function} success
* @param {Function} failure
*/
function doDelete(datasetId: string, uid: string, success: (obj: any) => void, failure?: (err: string, datasetId: string) => void): void;
/**
* Start the sync loop if `sync_active` option is set to false.
*
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function startSync(datasetId: string, success: () => void, failure?: (obj: any) => void): void;
/**
* Stop the sync loop for a dataset.
*
* @param {String} datasetId
* @param {Function} [success]
* @param {Function} [failure]
*/
function stopSync(datasetId: string, success?: () => void, failure?: (obj: any) => void): void;
/**
* Run the sync loop almost immediately (within next 500 ms) if `sync_active` is true.
*
* @param {String} datasetId
* @param {Function} [success]
* @param {Function} [failure]
*/
function doSync(datasetId: string, success?: () => void, failure?: (err: string, datasetId: string) => void): void;
/**
* Run the sync loop almost immediately (within next 500 ms) even if `sync_active` is false.
*
* @param {String} datasetId
* @param {Function} [success]
* @param {Function} [failure]
*/
function forceSync(datasetId: string, success?: () => void, failure?: (err: string, datasetId: string) => void): void;
/**
* List collisions in sync
*
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function listCollisions(datasetId: string, success: (res: any) => void, failure?: (msg: string, err: any) => void): void;
/**
* Remove a collision in sync
*
* @param {String} datasetId
* @param {String} collisionHash
* @param {Function} success
* @param {Function} failure
*/
function removeCollision(datasetId: string, collisionHash: string, success: (res: any) => void, failure: (msg: string, err: any) => void): void;
/**
* @param {String} datasetId
* @param {Function} callback
*/
function getPending(datasetId: string, callback: () => void): void;
/**
* @param {String} datasetId
* @param {Function} callback
*/
function clearPending(datasetId: string, callback: () => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function getDataSet(datasetId: string, success: (dataset: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function getQueryParams(datasetId: string, success: (queryParams: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function setQueryParams(datasetId: string, success: (queryParams: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function getMetaData(datasetId: string, success: (queryParams: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function setMetaData(datasetId: string, metaData: any, success: (metaData: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function getConfig(datasetId: string, success: (config: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function setConfig(datasetId: string, config: any, success: (config: any) => void, failure: (err: string, datasetId: string) => void): void;
/**
* Produces a SHA1 hash of the provided object (sorted before hash) or string.
*
* @param {Object|String} toHash - Object to hash
* @returns {String} - SHA1 hash of the provided string or object.
*/
function generateHash(toHash: {} | string): string;
/**
* @param {String} datasetId
* @param {Function} success
* @param {Function} failure
*/
function loadDataSet(datasetId: string, success: (dataset: any) => void, failure: () => void): void;
/**
* @param {String} datasetId
* @param {Function} callback
*/
function clearCache(datasetId: string, callback?: () => void): void;
/**
* Sets cloud call handler for sync. Required to make any sync requests to the server side (sync cloud)
*
* @param {Function} handler - method responsible for handling network requests
*/
function setCloudHandler(handler: (params: any, success: (result: any) => void, failure: (error: any) => void) => void): void;
/**
* Allows to override default storage adapter
*
* @param handler - function that wraps underlying storage solution
*/
function setStorageAdapter(handler: (dataset_id: string, isSave: boolean, cb: any) => void): void;
/**
* Allows to override default hashing method
*
* @param method - function that wraps underlying hashing method
*/
function setHashMethod(method: () => any): void;
}
export = SyncClient;

@@ -7,3 +7,3 @@ {

"version": "0.6.0",
"from": "loglevel@>=0.6.0 <0.7.0",
"from": "https://registry.npmjs.org/loglevel/-/loglevel-0.6.0.tgz",
"resolved": "https://registry.npmjs.org/loglevel/-/loglevel-0.6.0.tgz"

@@ -13,3 +13,3 @@ },

"version": "0.6.0",
"from": "process@>=0.6.0 <0.7.0",
"from": "https://registry.npmjs.org/process/-/process-0.6.0.tgz",
"resolved": "https://registry.npmjs.org/process/-/process-0.6.0.tgz"

@@ -19,3 +19,3 @@ },

"version": "2.0.1",
"from": "type-of@>=2.0.1 <2.1.0",
"from": "https://registry.npmjs.org/type-of/-/type-of-2.0.1.tgz",
"resolved": "https://registry.npmjs.org/type-of/-/type-of-2.0.1.tgz"

@@ -25,6 +25,11 @@ },

"version": "1.6.0",
"from": "underscore@>=1.6.0 <1.7.0",
"from": "https://registry.npmjs.org/underscore/-/underscore-1.6.0.tgz",
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.6.0.tgz"
},
"uuid": {
"version": "3.0.1",
"from": "uuid@latest",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.0.1.tgz"
}
}
}
{
"name": "fh-sync-js",
"version": "1.0.2",
"version": "1.0.3",
"description": "Javascript client for fh-sync offline synchronization library",
"main": "src/index.js",
"types": "./fh-js-sdk.d.ts",
"types": "./fh-sync-js.d.ts",
"browserify-shim": {

@@ -34,6 +34,7 @@ "JSON": {

"dependencies": {
"loglevel": "~0.6.0",
"process": "~0.6.0",
"type-of": "~2.0.1",
"loglevel": "~0.6.0",
"underscore": "~1.6.0",
"process": "~0.6.0"
"uuid": "^3.0.1"
},

@@ -40,0 +41,0 @@ "devDependencies": {

FeedHenry Sync Javascript client
========================
[Note] This repository it's currently in development for production version
please refer to fh-js-sdk npm module.
Data synchonization javascript client.
Library can be used for offline storage of mobile applications data.
## Required setup
Sync client using default Ajax handler to call sync server.
Server URL can be configured using following variables
To use the sync client you need a sync server setup first see https://github.com/feedhenry/fh-sync .
Sync client using default Ajax handler to call sync server.
Server URL can be configured using following variables

@@ -15,4 +16,6 @@ - cloudUrl - URL to sync server

For example:
```javascript
syncClient.init({

@@ -26,4 +29,6 @@ cloudUrl:"http://localhost:3000",

});
```
## Building

@@ -37,2 +42,1 @@

Feedhenry JS SDK contains various libraries and also includes fh-sync-js library.
var cloudURL;
var cloudPath;
var cidProvider = require('./clientIdProvider');

@@ -14,4 +15,7 @@ /**

var url = cloudURL + cloudPath + params.dataset_id;
var json = JSON.stringify(params.req);
var payload = params.req;
payload.__fh = {
cuid: cidProvider.getClientId()
};
var json = JSON.stringify(payload);
var xhr = new XMLHttpRequest();

@@ -53,3 +57,3 @@ xhr.open("POST", url, true);

handler: handler,
init: init
init: init,
};

@@ -530,3 +530,3 @@ var CryptoJS = require("../libs/generated/crypto");

generateHash: function(object) {
var hash = CryptoJS.SHA1(self.sortedStringify(object));
var hash = self.getHashMethod(self.sortedStringify(object));
return hash.toString();

@@ -912,2 +912,7 @@ },

},
/** Allow to set custom hasing method **/
setHashMethod: function(method){
self.getHashMethod = method;
},

@@ -925,2 +930,4 @@ getStorageAdapter: function(dataset_id, isSave, cb){

getHashMethod: CryptoJS.SHA1,
saveDataSet: function (dataset_id, cb) {

@@ -1266,3 +1273,4 @@ self.getDataSet(dataset_id, function(dataset) {

doCloudCall: self.doCloudCall,
setStorageAdapter: self.setStorageAdapter
setStorageAdapter: self.setStorageAdapter,
setHashMethod: self.setHashMethod
};

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