@hellotext/hellotext
Version:
Hellotext JavaScript Client
53 lines (40 loc) • 1.13 kB
JavaScript
import { Configuration } from '../core'
import { Cookies } from './cookies'
import { Page } from './page'
import { Query } from './query'
import API from '../api'
class Session {
static
static
static
static get session() {
return this.
}
static get ackPayload() {
return {
utm_params: this.
}
}
static set session(value) {
const oldSession = Cookies.get('hello_session')
this.
Cookies.set('hello_session', value)
if (oldSession !== value) {
Cookies.delete('hello_session_ack_at')
}
if (!Cookies.get('hello_session_ack_at')) {
API.acks.send(this.ackPayload)
Cookies.set('hello_session_ack_at', new Date().toISOString())
}
return this.
}
static initialize(page = new Page()) {
this.
this.
this.session = this.
if (!this.session && Configuration.autoGenerateSession) {
this.session = crypto.randomUUID()
}
}
}
export { Session }