@hellotext/hellotext 2.2.1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,6 +33,19 @@ class Cookies {
33
33
  return undefined
34
34
  }
35
35
  }
36
+
37
+ static delete(name) {
38
+ if (typeof document !== 'undefined') {
39
+ const domain = Page.getRootDomain()
40
+ const secure = window.location.protocol === 'https:' ? '; Secure' : ''
41
+
42
+ if (domain) {
43
+ document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${secure}; domain=${domain}; SameSite=Lax`
44
+ } else {
45
+ document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${secure}; SameSite=Lax`
46
+ }
47
+ }
48
+ }
36
49
  }
37
50
 
38
51
  export { Cookies }
@@ -5,5 +5,6 @@ export { FormCollection } from './form_collection'
5
5
  export { Page } from './page'
6
6
  export { Query } from './query'
7
7
  export { Session } from './session'
8
+ export { User } from './user'
8
9
  export { UTM } from './utm'
9
10
  export { Webchat } from './webchat'
@@ -0,0 +1,35 @@
1
+ import { Cookies } from './cookies'
2
+
3
+ class User {
4
+ static get id() {
5
+ return Cookies.get('hello_user_id')
6
+ }
7
+
8
+ static get source() {
9
+ return Cookies.get('hello_user_source')
10
+ }
11
+
12
+ static remember(id, source) {
13
+ if (source) {
14
+ Cookies.set('hello_user_source', source)
15
+ }
16
+
17
+ Cookies.set('hello_user_id', id)
18
+ }
19
+
20
+ static forget() {
21
+ Cookies.delete('hello_user_id')
22
+ Cookies.delete('hello_user_source')
23
+ }
24
+
25
+ static get identificationData() {
26
+ if (!this.id) return {}
27
+
28
+ return {
29
+ id: this.id,
30
+ source: this.source,
31
+ }
32
+ }
33
+ }
34
+
35
+ export { User }