Skip to content

Commit bc99aff

Browse files
committed
New endpoint for errors and updates Lockr library
1 parent 81bd6e4 commit bc99aff

11 files changed

+434
-84
lines changed

Gruntfile.js gruntfile.js

File renamed without changes.

lib/amd/bugsense.js

+142-27
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
* MIT License | (c) Dustin Diaz 2014
1515
*/
1616

17-
!function (name, definition) {
18-
if (typeof module != 'undefined' && module.exports) module.exports['browser'] = definition()
19-
else if (typeof define == 'function') define(definition)
20-
else this[name] = definition()
21-
}('bowser', function () {
17+
(function () {
2218
/**
2319
* See useragents.js for examples of navigator.userAgent
2420
*/
@@ -245,8 +241,9 @@
245241
*/
246242
bowser._detect = detect;
247243

248-
return bowser
249-
});
244+
this.bowser = bowser;
245+
}).call(this);
246+
250247
/*
251248
TraceKit - Cross brower stack traces - github.com/occ/TraceKit
252249
MIT license
@@ -1534,28 +1531,121 @@
15341531
};
15351532
};
15361533

1537-
(function() {
1538-
this.Lockr = {};
1534+
(function(root, factory) {
1535+
1536+
if (typeof define === 'function' && define.amd) {
1537+
define(['exports'], function(exports) {
1538+
root.Lockr = factory(root, exports);
1539+
});
1540+
} else {
1541+
root.Lockr = factory(root, {});
1542+
}
1543+
1544+
}(this, function(root, Lockr) {
1545+
'use strict';
1546+
1547+
root.Lockr = Lockr;
1548+
1549+
if (!Array.prototype.indexOf) {
1550+
Array.prototype.indexOf = function(elt /*, from*/)
1551+
{
1552+
var len = this.length >>> 0;
1553+
1554+
var from = Number(arguments[1]) || 0;
1555+
from = (from < 0)
1556+
? Math.ceil(from)
1557+
: Math.floor(from);
1558+
if (from < 0)
1559+
from += len;
1560+
1561+
for (; from < len; from++)
1562+
{
1563+
if (from in this &&
1564+
this[from] === elt)
1565+
return from;
1566+
}
1567+
return -1;
1568+
};
1569+
}
1570+
1571+
Lockr.prefix = "";
1572+
1573+
Lockr._getPrefixedKey = function(key, options) {
1574+
options = options || {};
1575+
1576+
if (options.noPrefix) {
1577+
return key;
1578+
} else {
1579+
return this.prefix + key;
1580+
}
15391581

1540-
Lockr.set = function (key, value) {
1541-
localStorage.setItem(key, value);
15421582
};
15431583

1544-
Lockr.hset = function (key, hashObj) {
1545-
localStorage.setItem(key, JSON.stringify(hashObj));
1584+
Lockr.set = function (key, value, options) {
1585+
var query_key = this._getPrefixedKey(key, options);
1586+
1587+
try {
1588+
localStorage.setItem(query_key, JSON.stringify({"data": value}));
1589+
} catch (e) {
1590+
if (console) console.warn("Lockr didn't successfully save the '{"+ key +": "+ value +"}' pair, because the localStorage is full.");
1591+
}
15461592
};
1547-
Lockr.get = function (key, callback) {
1548-
var value = localStorage.getItem(key);
1549-
if (value == null)
1550-
return undefined;
1551-
if (value.match(/[\{\}\:\[\]]/)) /* hash objects */
1552-
return JSON.parse(value);
1553-
else if (value.match(/^\d+(?:\.\d+$)/)) /* floating number */
1554-
return parseFloat(value);
1555-
else if (value.match(/^\d+$/)) /* integer number */
1556-
return parseInt(value);
1593+
1594+
Lockr.get = function (key, missing, options) {
1595+
var query_key = this._getPrefixedKey(key, options),
1596+
value;
1597+
1598+
try {
1599+
value = JSON.parse(localStorage.getItem(query_key));
1600+
} catch (e) {
1601+
value = null;
1602+
}
1603+
if(value === null)
1604+
return missing;
15571605
else
1558-
return value;
1606+
return (value.data || missing);
1607+
};
1608+
1609+
Lockr.sadd = function(key, value, options) {
1610+
var query_key = this._getPrefixedKey(key, options),
1611+
json;
1612+
1613+
var values = Lockr.smembers(key);
1614+
1615+
if (values.indexOf(value) > -1) {
1616+
return null;
1617+
}
1618+
1619+
try {
1620+
values.push(value);
1621+
json = JSON.stringify({"data": values});
1622+
localStorage.setItem(query_key, json);
1623+
} catch (e) {
1624+
console.log(e);
1625+
if (console) console.warn("Lockr didn't successfully add the "+ value +" to "+ key +" set, because the localStorage is full.");
1626+
}
1627+
};
1628+
1629+
Lockr.smembers = function(key, options) {
1630+
var query_key = this._getPrefixedKey(key, options),
1631+
value;
1632+
1633+
try {
1634+
value = JSON.parse(localStorage.getItem(query_key));
1635+
} catch (e) {
1636+
value = null;
1637+
}
1638+
1639+
if (value === null)
1640+
return [];
1641+
else
1642+
return (value.data || []);
1643+
};
1644+
1645+
Lockr.sismember = function(key, value, options) {
1646+
var query_key = this._getPrefixedKey(key, options);
1647+
1648+
return Lockr.smembers(key).indexOf(value) > -1;
15591649
};
15601650

15611651
Lockr.getAll = function () {
@@ -1566,12 +1656,37 @@
15661656
});
15671657
};
15681658

1659+
Lockr.srem = function(key, value, options) {
1660+
var query_key = this._getPrefixedKey(key, options),
1661+
json,
1662+
index;
1663+
1664+
var values = Lockr.smembers(key, value);
1665+
1666+
index = values.indexOf(value);
1667+
1668+
if (index > -1)
1669+
values.splice(index, 1);
1670+
1671+
json = JSON.stringify({"data": values});
1672+
1673+
try {
1674+
localStorage.setItem(query_key, json);
1675+
} catch (e) {
1676+
if (console) console.warn("Lockr couldn't remove the "+ value +" from the set "+ key);
1677+
}
1678+
};
1679+
1680+
Lockr.rm = function (key) {
1681+
localStorage.removeItem(key);
1682+
};
1683+
15691684
Lockr.flush = function () {
15701685
localStorage.clear();
15711686
};
15721687
return Lockr;
15731688

1574-
}).call(this);
1689+
}));
15751690

15761691
var md5cycle = function(x, k) {
15771692
var a = x[0], b = x[1], c = x[2], d = x[3];
@@ -1746,7 +1861,7 @@
17461861
appVersion: null,
17471862
appname: null,
17481863
osver: null,
1749-
url: 'https://www.bugsense.com/api/errors',
1864+
url: 'https://mint.splunk.com/api/errors',
17501865
disableOnError: false,
17511866
context: window
17521867
};
@@ -1971,7 +2086,7 @@
19712086
this.sendCachedReport();
19722087
},
19732088
update: function () {
1974-
Lockr.hset('bugsense_cache', this._queue);
2089+
Lockr.set('bugsense_cache', this._queue);
19752090
},
19762091
sendCachedReport: function() {
19772092
// do stuff here

lib/amd/bugsense.min.js

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)