From d562ceb109c43828f2048f591310ef07222e5224 Mon Sep 17 00:00:00 2001 From: "Daniel St. Jules" Date: Mon, 25 Jul 2016 21:46:30 -0700 Subject: [PATCH] 1.0.0 --- .zuul.yml | 2 +- README.md | 5 +++++ bower.json | 2 +- dist/client.js | 15 ++++++--------- dist/client.min.js | 4 ++-- dist/hub.js | 41 +++++++++-------------------------------- dist/hub.min.js | 4 ++-- package.json | 2 +- 8 files changed, 27 insertions(+), 48 deletions(-) diff --git a/.zuul.yml b/.zuul.yml index 43217d5..6ae1643 100644 --- a/.zuul.yml +++ b/.zuul.yml @@ -18,7 +18,7 @@ browsers: version: latest platform: Linux - name: safari - version: 5..7 + version: 7 - name: ie version: 8..latest - name: android diff --git a/README.md b/README.md index 95c79f7..20c37e0 100644 --- a/README.md +++ b/README.md @@ -270,6 +270,11 @@ storage.onConnect().then(function() { }); ``` +**Breaking Changes** + +API breaking changes were introduced in both 0.6 and 1.0. Refer to +[releases](https://github.com/zendesk/cross-storage/releases) for details. + **Notes on Safari 7+ (OSX, iOS)** All cross-domain local storage access is disabled by default with Safari 7+. diff --git a/bower.json b/bower.json index c618882..2aeb314 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "cross-storage", - "version": "0.8.2", + "version": "1.0.0", "description": "Cross domain local storage", "license": "Apache-2.0", "authors": [ diff --git a/dist/client.js b/dist/client.js index 08265b2..51e804d 100644 --- a/dist/client.js +++ b/dist/client.js @@ -1,7 +1,7 @@ /** * cross-storage - Cross domain local storage * - * @version 0.8.2 + * @version 1.0.0 * @link https://github.com/zendesk/cross-storage * @author Daniel St. Jules * @copyright Zendesk @@ -172,21 +172,18 @@ }; /** - * Sets a key to the specified value, optionally accepting a ttl to passively - * expire the key after a number of milliseconds. Returns a promise that is - * fulfilled on success, or rejected if any errors setting the key occurred, - * or the request timed out. + * Sets a key to the specified value. Returns a promise that is fulfilled on + * success, or rejected if any errors setting the key occurred, or the request + * timed out. * * @param {string} key The key to set * @param {*} value The value to assign - * @param {int} ttl Time to live in milliseconds * @returns {Promise} A promise that is settled on hub response or timeout */ - CrossStorageClient.prototype.set = function(key, value, ttl) { + CrossStorageClient.prototype.set = function(key, value) { return this._request('set', { key: key, - value: value, - ttl: ttl + value: value }); }; diff --git a/dist/client.min.js b/dist/client.min.js index cb749c1..c78e991 100644 --- a/dist/client.min.js +++ b/dist/client.min.js @@ -1,11 +1,11 @@ /** * cross-storage - Cross domain local storage * - * @version 0.8.2 + * @version 1.0.0 * @link https://github.com/zendesk/cross-storage * @author Daniel St. Jules * @copyright Zendesk * @license Apache-2.0 */ -!function(e){function t(e,r){r=r||{},this._id=t._generateUUID(),this._promise=r.promise||Promise,this._frameId=r.frameId||"CrossStorageClient-"+this._id,this._origin=t._getOrigin(e),this._requests={},this._connected=!1,this._closed=!1,this._count=0,this._timeout=r.timeout||5e3,this._listener=null,this._installListener();var o;r.frameId&&(o=document.getElementById(r.frameId)),o&&this._poll(),o=o||this._createFrame(e),this._hub=o.contentWindow}t.frameStyle={display:"none",position:"absolute",top:"-999px",left:"-999px"},t._getOrigin=function(e){var t,r,o;return t=document.createElement("a"),t.href=e,t.host||(t=window.location),r=t.protocol&&":"!==t.protocol?t.protocol:window.location.protocol,o=r+"//"+t.host,o=o.replace(/:80$|:443$/,"")},t._generateUUID=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0,r="x"==e?t:3&t|8;return r.toString(16)})},t.prototype.onConnect=function(){var e=this;return this._connected?this._promise.resolve():this._closed?this._promise.reject(new Error("CrossStorageClient has closed")):(this._requests.connect||(this._requests.connect=[]),new this._promise(function(t,r){var o=setTimeout(function(){r(new Error("CrossStorageClient could not connect"))},e._timeout);e._requests.connect.push(function(e){return clearTimeout(o),e?r(e):(t(),void 0)})}))},t.prototype.set=function(e,t,r){return this._request("set",{key:e,value:t,ttl:r})},t.prototype.get=function(){var e=Array.prototype.slice.call(arguments);return this._request("get",{keys:e})},t.prototype.del=function(){var e=Array.prototype.slice.call(arguments);return this._request("del",{keys:e})},t.prototype.clear=function(){return this._request("clear")},t.prototype.getKeys=function(){return this._request("getKeys")},t.prototype.close=function(){var e=document.getElementById(this._frameId);e&&e.parentNode.removeChild(e),window.removeEventListener?window.removeEventListener("message",this._listener,!1):window.detachEvent("onmessage",this._listener),this._connected=!1,this._closed=!0},t.prototype._installListener=function(){var e=this;this._listener=function(t){var r,o,n,s;if(!e._closed&&t.data&&"string"==typeof t.data&&(o="null"===t.origin?"file://":t.origin,o===e._origin))if("cross-storage:unavailable"!==t.data){if(-1!==t.data.indexOf("cross-storage:")&&!e._connected){if(e._connected=!0,!e._requests.connect)return;for(r=0;r * @copyright Zendesk @@ -160,59 +160,36 @@ }; /** - * Sets a key to the specified value. If a ttl is provided, an expiration - * timestamp is added to the object to be stored, prior to serialization. + * Sets a key to the specified value. * - * @param {object} params An object with key, value and optional ttl + * @param {object} params An object with key and value */ CrossStorageHub._set = function(params) { - var ttl, item; - - ttl = params.ttl; - if (ttl && parseInt(ttl, 10) !== ttl) { - throw new Error('ttl must be a number'); - } - - item = {value: params.value}; - if (ttl) { - item.expire = CrossStorageHub._now() + ttl; - } - - window.localStorage.setItem(params.key, JSON.stringify(item)); + window.localStorage.setItem(params.key, params.value); }; /** * Accepts an object with an array of keys for which to retrieve their values. * Returns a single value if only one key was supplied, otherwise it returns - * an array. Any keys not set, or expired, result in a null element in the - * resulting array. + * an array. Any keys not set result in a null element in the resulting array. * * @param {object} params An object with an array of keys * @returns {*|*[]} Either a single value, or an array */ CrossStorageHub._get = function(params) { - var storage, result, i, item, key; + var storage, result, i, value; storage = window.localStorage; result = []; for (i = 0; i < params.keys.length; i++) { - key = params.keys[i]; - try { - item = JSON.parse(storage.getItem(key)); + value = storage.getItem(params.keys[i]); } catch (e) { - item = null; + value = null; } - if (item === null) { - result.push(null); - } else if (item.expire && item.expire < CrossStorageHub._now()) { - storage.removeItem(key); - result.push(null); - } else { - result.push(item.value); - } + result.push(value); } return (result.length > 1) ? result : result[0]; diff --git a/dist/hub.min.js b/dist/hub.min.js index c4a22a4..fc2673e 100644 --- a/dist/hub.min.js +++ b/dist/hub.min.js @@ -1,11 +1,11 @@ /** * cross-storage - Cross domain local storage * - * @version 0.8.2 + * @version 1.0.0 * @link https://github.com/zendesk/cross-storage * @author Daniel St. Jules * @copyright Zendesk * @license Apache-2.0 */ -!function(e){var t={};t.init=function(e){var r=!0;try{window.localStorage||(r=!1)}catch(n){r=!1}if(!r)try{return window.parent.postMessage("cross-storage:unavailable","*")}catch(n){return}t._permissions=e||[],t._installListener(),window.parent.postMessage("cross-storage:ready","*")},t._installListener=function(){var e=t._listener;window.addEventListener?window.addEventListener("message",e,!1):window.attachEvent("onmessage",e)},t._listener=function(e){var r,n,o,i,s,a,l;if(r="null"===e.origin?"file://":e.origin,"cross-storage:poll"===e.data)return window.parent.postMessage("cross-storage:ready",e.origin);if("cross-storage:ready"!==e.data){try{o=JSON.parse(e.data)}catch(u){return}if(o&&"string"==typeof o.method&&(i=o.method.split("cross-storage:")[1])){if(t._permitted(r,i))try{a=t["_"+i](o.params)}catch(u){s=u.message}else s="Invalid permissions for "+i;l=JSON.stringify({id:o.id,error:s,result:a}),n="file://"===r?"*":r,window.parent.postMessage(l,n)}}},t._permitted=function(e,r){var n,o,i,s;if(n=["get","set","del","clear","getKeys"],!t._inArray(r,n))return!1;for(o=0;o1?n:n[0]},t._del=function(e){for(var t=0;te;e++)r.push(window.localStorage.key(e));return r},t._inArray=function(e,t){for(var r=0;r1?r:r[0]},t._del=function(e){for(var t=0;te;e++)r.push(window.localStorage.key(e));return r},t._inArray=function(e,t){for(var r=0;r