@financial-times/o-tracking
Advanced tools
Comparing version 3.0.3 to 3.0.4
@@ -58,2 +58,7 @@ import { broadcast, containsCircularPaths, decode, encode, findCircularPathsIn, is } from "../utils.js"; | ||
remove: function remove(name) { | ||
// We attempt to remove the item from the old cookie storage | ||
// because otherwise the next time o-tracking is initialised for | ||
// this user, it will import the old value which was meant to | ||
// have been removed. | ||
cookieRemove(name); | ||
return window.localStorage.removeItem(name); | ||
@@ -125,12 +130,19 @@ } | ||
try { | ||
var data = JSON.parse(oldCookieStoreData); | ||
if (this.data) { | ||
Object.assign(this.data, data); | ||
if (this.storageKey === 'spoor-id') { | ||
// spoor-id is stored directly as a string and not as an object | ||
this.data = oldCookieStoreData; | ||
} else { | ||
this.data = data; | ||
} | ||
var data = JSON.parse(oldCookieStoreData); | ||
for (var _name of Object.keys(data)) { | ||
cookieRemove(_name); | ||
if (this.data) { | ||
Object.assign(this.data, data); | ||
} else { | ||
this.data = data; | ||
} | ||
for (var _name of Object.keys(data)) { | ||
if (_name !== 'spoor-id') { | ||
cookieRemove(_name); | ||
} | ||
} | ||
} | ||
@@ -137,0 +149,0 @@ } catch (error) { |
@@ -19,3 +19,3 @@ import { set, get, destroy as destroySetting } from "./core/settings.js"; | ||
var version = '3.0.3'; | ||
var version = '3.0.4'; | ||
/** | ||
@@ -22,0 +22,0 @@ * The source of this event. |
@@ -65,2 +65,7 @@ "use strict"; | ||
remove: function remove(name) { | ||
// We attempt to remove the item from the old cookie storage | ||
// because otherwise the next time o-tracking is initialised for | ||
// this user, it will import the old value which was meant to | ||
// have been removed. | ||
cookieRemove(name); | ||
return window.localStorage.removeItem(name); | ||
@@ -132,12 +137,19 @@ } | ||
try { | ||
var data = JSON.parse(oldCookieStoreData); | ||
if (this.data) { | ||
Object.assign(this.data, data); | ||
if (this.storageKey === 'spoor-id') { | ||
// spoor-id is stored directly as a string and not as an object | ||
this.data = oldCookieStoreData; | ||
} else { | ||
this.data = data; | ||
} | ||
var data = JSON.parse(oldCookieStoreData); | ||
for (var _name of Object.keys(data)) { | ||
cookieRemove(_name); | ||
if (this.data) { | ||
Object.assign(this.data, data); | ||
} else { | ||
this.data = data; | ||
} | ||
for (var _name of Object.keys(data)) { | ||
if (_name !== 'spoor-id') { | ||
cookieRemove(_name); | ||
} | ||
} | ||
} | ||
@@ -144,0 +156,0 @@ } catch (error) { |
@@ -38,3 +38,3 @@ "use strict"; | ||
var version = '3.0.3'; | ||
var version = '3.0.4'; | ||
/** | ||
@@ -41,0 +41,0 @@ * The source of this event. |
@@ -16,3 +16,3 @@ { | ||
"name": "@financial-times/o-tracking", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "Origami module for FT tracking.", | ||
@@ -19,0 +19,0 @@ "dependencies": { |
@@ -56,2 +56,7 @@ import {broadcast, containsCircularPaths, decode, encode, findCircularPathsIn, is} from '../utils.js'; | ||
remove: function (name) { | ||
// We attempt to remove the item from the old cookie storage | ||
// because otherwise the next time o-tracking is initialised for | ||
// this user, it will import the old value which was meant to | ||
// have been removed. | ||
cookieRemove(name); | ||
return window.localStorage.removeItem(name); | ||
@@ -120,11 +125,18 @@ } | ||
try { | ||
const data = JSON.parse(oldCookieStoreData); | ||
if (this.data) { | ||
Object.assign(this.data, data); | ||
if (this.storageKey === 'spoor-id') { | ||
// spoor-id is stored directly as a string and not as an object | ||
this.data = oldCookieStoreData; | ||
} else { | ||
this.data = data; | ||
const data = JSON.parse(oldCookieStoreData); | ||
if (this.data) { | ||
Object.assign(this.data, data); | ||
} else { | ||
this.data = data; | ||
} | ||
for (const name of Object.keys(data)) { | ||
if (name !== 'spoor-id') { | ||
cookieRemove(name); | ||
} | ||
} | ||
} | ||
for (const name of Object.keys(data)) { | ||
cookieRemove(name); | ||
} | ||
} catch (error) { | ||
@@ -131,0 +143,0 @@ broadcast('oErrors', 'log', { |
@@ -20,3 +20,3 @@ import {set, get, destroy as destroySetting} from './core/settings.js'; | ||
*/ | ||
const version = '3.0.3'; | ||
const version = '3.0.4'; | ||
@@ -23,0 +23,0 @@ /** |
@@ -103,3 +103,15 @@ /* eslint-env mocha */ | ||
}); | ||
context('spoor-id migration from cookie to localstorage', function() { | ||
it('should load data from the old cookie storage system if the cookie exists', function() { | ||
const spoorID = 'ckmypa3l700003g6e6wb33708'; | ||
cookieSave('spoor-id', spoorID); | ||
const store = new Store('test', { | ||
nameOverride: 'spoor-id', | ||
}); | ||
proclaim.deepStrictEqual(store.read(), spoorID); | ||
}); | ||
}); | ||
}); | ||
}); |
339197
8328