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

@financial-times/o-tracking

Package Overview
Dependencies
Maintainers
0
Versions
53
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@financial-times/o-tracking - npm Package Compare versions

Comparing version 4.5.4 to 4.6.0

7

CHANGELOG.md
# Changelog
## [4.6.0](https://github.com/Financial-Times/origami/compare/o-tracking-v4.5.4...o-tracking-v4.6.0) (2024-11-14)
### Features
* add timestamp to session generations in o-tracking ([37ed21f](https://github.com/Financial-Times/origami/commit/37ed21f8e75128e7fd9f52be86c5c744f4148479))
## [4.5.4](https://github.com/Financial-Times/origami/compare/o-tracking-v4.5.3...o-tracking-v4.5.4) (2024-05-01)

@@ -4,0 +11,0 @@

2

package.json
{
"name": "@financial-times/o-tracking",
"version": "4.5.4",
"version": "4.6.0",
"description": "Provides tracking for a product. Tracking requests are sent to the Spoor API.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -58,2 +58,3 @@ import {addAndRun} from './core/send.js';

spoor_session_is_new: currentSession.isNew,
spoor_session_timestamp: currentSession.timestamp,
spoor_id: userID(),

@@ -60,0 +61,0 @@ },

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

import {is, merge, isUndefined, guid} from '../utils.js';
import {is, merge, isUndefined, guid, namedLog} from '../utils.js';
import {Store} from './store.js';

@@ -8,5 +8,7 @@

* @property {boolean} isNew - Whether it is a brand new session
* @property {number} timestamp - The timestamp of the session generation
*/
let store;
const logger = namedLog('Core.Session')
const defaultSessionConfig = {

@@ -24,10 +26,16 @@ storage: 'best',

*/
function setSession(session) {
function setSession(session, timestamp) {
const d = new Date();
d.setTime(d.getTime() + store.config.expires);
store.write({
const sessionData = {
value: session,
expiry: d.valueOf()
});
expiry: d.valueOf(),
}
if(timestamp) {
sessionData.timestamp = timestamp;
}
logger('Setting session', sessionData)
store.write(sessionData);
}

@@ -44,5 +52,9 @@

let isNew = false;
let sessionTimestamp;
if (s) {
const d = new Date().valueOf();
logger("Found session", s)
const currentDate = new Date();
const d = currentDate.valueOf();
const timestamp = currentDate.getTime();
const exp = parseInt(s.expiry, 10);

@@ -53,4 +65,13 @@

session = s.value;
sessionTimestamp = s.timestamp;
// session is active but no generated timestamp
if(!sessionTimestamp) {
logger("Session is valid but no timestamp, generating timestamp.")
sessionTimestamp = timestamp;
}
} else {
// session has expired, generate a new one
// session has expired, generate a new one along with a new timestamp
logger("Session has expired, generating new one")
sessionTimestamp = timestamp;
session = guid();

@@ -63,3 +84,5 @@ isNew = true;

if (!session) {
logger("No session found, generating new one")
session = guid();
sessionTimestamp = new Date().getTime();
isNew = true;

@@ -69,6 +92,7 @@ }

// Refreshes the cookie...
setSession(session);
setSession(session, sessionTimestamp);
return {
id: session,
timestamp: sessionTimestamp,
isNew: isNew

@@ -75,0 +99,0 @@ };

@@ -20,3 +20,3 @@ import {set, get, destroy as destroySetting} from './core/settings.js';

*/
const version = '4.5.4';
const version = '4.6.0';

@@ -23,0 +23,0 @@ /**

@@ -31,2 +31,22 @@ /**

/**
* Creates a logging function that logs messages to the console with a specified namespace.
*
* @function namedLog
* @param {string} namespace - The namespace to be prefixed to each log message.
* @returns {function} A function that logs messages to the console with the given namespace if the configuration allows.
*
* @example
* const log = namedLog('MyNamespace');
* log('This is a message');
* // Output: [MyNamespace]: This is a message
*/
function namedLog(namespace) {
return function(...args) {
if(get('config').test && window.console) {
window.console.log(`%c[${namespace}]:`, 'color: teal', ...args)
}
}
}
/**
* Tests if variable is a certain type. Defaults to check for undefined if no type specified.

@@ -393,2 +413,3 @@ *

log,
namedLog,
is,

@@ -395,0 +416,0 @@ is as isUndefined,

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