@hellotext/hellotext 2.2.0 → 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.
package/index.d.ts CHANGED
@@ -35,6 +35,18 @@ export interface TrackingParams {
35
35
  object_type?: string
36
36
  }
37
37
 
38
+ export interface IdentificationOptions {
39
+ email?: string
40
+ phone?: string
41
+ name?: string
42
+ source?: string
43
+ }
44
+
45
+ export interface IdentificationData {
46
+ id: string
47
+ source?: string
48
+ }
49
+
38
50
  export interface Response {
39
51
  data: any
40
52
  succeeded: boolean
@@ -44,6 +56,8 @@ export interface Response {
44
56
  declare class Hellotext {
45
57
  static initialize(businessId: string, config?: HellotextConfig): Promise<void>
46
58
  static track(action: string, params?: TrackingParams): Promise<Response>
59
+ static identify(userId: string, options?: IdentificationOptions): Promise<Response>
60
+ static forget(): void
47
61
  static on(event: string, callback: (data: any) => void): void
48
62
  static removeEventListener(event: string, callback: (data: any) => void): void
49
63
  static get session(): string
@@ -53,6 +67,20 @@ declare class Hellotext {
53
67
  static webchat: any
54
68
  }
55
69
 
70
+ export declare class User {
71
+ static get id(): string | undefined
72
+ static get source(): string | undefined
73
+ static remember(id: string, source?: string): void
74
+ static forget(): void
75
+ static get identificationData(): IdentificationData | Record<string, never>
76
+ }
77
+
78
+ export declare class Cookies {
79
+ static get(name: string): string | undefined
80
+ static set(name: string, value: string): string
81
+ static delete(name: string): void
82
+ }
83
+
56
84
  export default Hellotext
57
85
 
58
86
  // Declare the CSS module
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _hellotext = _interopRequireDefault(require("../hellotext"));
8
+ var _core = require("../core");
9
+ var _response = require("./response");
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
12
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
13
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
14
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
15
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
16
+ let IdentificationsAPI = /*#__PURE__*/function () {
17
+ function IdentificationsAPI() {
18
+ _classCallCheck(this, IdentificationsAPI);
19
+ }
20
+ _createClass(IdentificationsAPI, null, [{
21
+ key: "endpoint",
22
+ get: function () {
23
+ return _core.Configuration.endpoint('public/identifications');
24
+ }
25
+ }, {
26
+ key: "create",
27
+ value: async function create(data = {}) {
28
+ const response = await fetch(this.endpoint, {
29
+ method: 'POST',
30
+ headers: _hellotext.default.headers,
31
+ body: JSON.stringify({
32
+ session: _hellotext.default.session,
33
+ ...data
34
+ })
35
+ });
36
+ return new _response.Response(response.ok, response);
37
+ }
38
+ }]);
39
+ return IdentificationsAPI;
40
+ }();
41
+ var _default = IdentificationsAPI;
42
+ exports.default = _default;
@@ -0,0 +1,45 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
5
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
8
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
9
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
+ import Hellotext from '../hellotext';
12
+ import { Configuration } from '../core';
13
+ import { Response } from './response';
14
+ var IdentificationsAPI = /*#__PURE__*/function () {
15
+ function IdentificationsAPI() {
16
+ _classCallCheck(this, IdentificationsAPI);
17
+ }
18
+ _createClass(IdentificationsAPI, null, [{
19
+ key: "endpoint",
20
+ get: function get() {
21
+ return Configuration.endpoint('public/identifications');
22
+ }
23
+ }, {
24
+ key: "create",
25
+ value: function () {
26
+ var _create = _asyncToGenerator(function* () {
27
+ var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
28
+ var response = yield fetch(this.endpoint, {
29
+ method: 'POST',
30
+ headers: Hellotext.headers,
31
+ body: JSON.stringify(_objectSpread({
32
+ session: Hellotext.session
33
+ }, data))
34
+ });
35
+ return new Response(response.ok, response);
36
+ });
37
+ function create() {
38
+ return _create.apply(this, arguments);
39
+ }
40
+ return create;
41
+ }()
42
+ }]);
43
+ return IdentificationsAPI;
44
+ }();
45
+ export default IdentificationsAPI;
package/lib/api/index.cjs CHANGED
@@ -13,6 +13,7 @@ exports.default = void 0;
13
13
  var _businesses = _interopRequireDefault(require("./businesses"));
14
14
  var _events = _interopRequireDefault(require("./events"));
15
15
  var _forms = _interopRequireDefault(require("./forms"));
16
+ var _identifications = _interopRequireDefault(require("./identifications"));
16
17
  var _webchats = _interopRequireDefault(require("./webchats"));
17
18
  var _response = require("./response");
18
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -45,6 +46,11 @@ let API = /*#__PURE__*/function () {
45
46
  get: function () {
46
47
  return _webchats.default;
47
48
  }
49
+ }, {
50
+ key: "identifications",
51
+ get: function () {
52
+ return _identifications.default;
53
+ }
48
54
  }]);
49
55
  return API;
50
56
  }();
package/lib/api/index.js CHANGED
@@ -6,6 +6,7 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
6
6
  import BusinessesAPI from './businesses';
7
7
  import EventsAPI from './events';
8
8
  import FormsAPI from './forms';
9
+ import IdentificationsAPI from './identifications';
9
10
  import WebchatsAPI from './webchats';
10
11
  var API = /*#__PURE__*/function () {
11
12
  function API() {
@@ -31,6 +32,11 @@ var API = /*#__PURE__*/function () {
31
32
  get: function get() {
32
33
  return WebchatsAPI;
33
34
  }
35
+ }, {
36
+ key: "identifications",
37
+ get: function get() {
38
+ return IdentificationsAPI;
39
+ }
34
40
  }]);
35
41
  return API;
36
42
  }();
package/lib/hellotext.cjs CHANGED
@@ -15,11 +15,6 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
15
15
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
16
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
17
17
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
18
- function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
19
- var id = 0;
20
- function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
21
- var _session = /*#__PURE__*/_classPrivateFieldLooseKey("session");
22
- var _query = /*#__PURE__*/_classPrivateFieldLooseKey("query");
23
18
  let Hellotext = /*#__PURE__*/function () {
24
19
  function Hellotext() {
25
20
  _classCallCheck(this, Hellotext);
@@ -38,7 +33,7 @@ let Hellotext = /*#__PURE__*/function () {
38
33
  this.page = new _models.Page();
39
34
  this.business = new _models.Business(business);
40
35
  this.forms = new _models.FormCollection();
41
- _classPrivateFieldLooseBase(this, _query)[_query] = new _models.Query();
36
+ this.query = new _models.Query();
42
37
  if (_core.Configuration.webchat.id) {
43
38
  this.webchat = await _models.Webchat.load(_core.Configuration.webchat.id);
44
39
  }
@@ -67,6 +62,7 @@ let Hellotext = /*#__PURE__*/function () {
67
62
  const pageInstance = params && params.url ? new _models.Page(params.url) : this.page;
68
63
  const body = {
69
64
  session: this.session,
65
+ user: _models.User.identificationData,
70
66
  action,
71
67
  ...params,
72
68
  ...pageInstance.trackingData
@@ -78,6 +74,42 @@ let Hellotext = /*#__PURE__*/function () {
78
74
  });
79
75
  }
80
76
 
77
+ /**
78
+ * @typedef { Object } IdentificationOptions
79
+ * @property { String } [email] - the email of the user
80
+ * @property { String } [phone] - the phone number of the user
81
+ * @property { String } [name] - the name of the user
82
+ * @property { String } [source] - the platform specific identifier where this pixel is running on.
83
+ *
84
+ * Identifies a user and attaches the hello_session to the user ID
85
+ * @param { String } externalId - the user ID
86
+ * @param { IdentificationOptions } options - the options for the identification
87
+ * @returns {Promise<Response>}
88
+ */
89
+ }, {
90
+ key: "identify",
91
+ value: async function identify(externalId, options = {}) {
92
+ const response = await _api.default.identifications.create({
93
+ user_id: externalId,
94
+ ...options
95
+ });
96
+ if (response.succeeded) {
97
+ _models.User.remember(externalId, options.source);
98
+ }
99
+ return response;
100
+ }
101
+
102
+ /**
103
+ * Clears the user session, use when the user logs out to clear the hello cookies
104
+ *
105
+ * @returns {void}
106
+ */
107
+ }, {
108
+ key: "forget",
109
+ value: function forget() {
110
+ _models.User.forget();
111
+ }
112
+
81
113
  /**
82
114
  * Registers an event listener
83
115
  * @param event the name of the event to listen to
@@ -141,14 +173,6 @@ let Hellotext = /*#__PURE__*/function () {
141
173
  }]);
142
174
  return Hellotext;
143
175
  }();
144
- Object.defineProperty(Hellotext, _session, {
145
- writable: true,
146
- value: void 0
147
- });
148
- Object.defineProperty(Hellotext, _query, {
149
- writable: true,
150
- value: void 0
151
- });
152
176
  Hellotext.eventEmitter = new _core.Event();
153
177
  Hellotext.forms = void 0;
154
178
  Hellotext.business = void 0;
package/lib/hellotext.js CHANGED
@@ -8,15 +8,10 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
8
8
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
9
9
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
10
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
- function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; }
12
- var id = 0;
13
- function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
14
11
  import { Configuration, Event } from './core';
15
12
  import API, { Response } from './api';
16
- import { Business, FormCollection, Page, Query, Session, Webchat } from './models';
13
+ import { Business, FormCollection, Page, Query, Session, User, Webchat } from './models';
17
14
  import { NotInitializedError } from './errors';
18
- var _session = /*#__PURE__*/_classPrivateFieldLooseKey("session");
19
- var _query = /*#__PURE__*/_classPrivateFieldLooseKey("query");
20
15
  var Hellotext = /*#__PURE__*/function () {
21
16
  function Hellotext() {
22
17
  _classCallCheck(this, Hellotext);
@@ -36,7 +31,7 @@ var Hellotext = /*#__PURE__*/function () {
36
31
  this.page = new Page();
37
32
  this.business = new Business(business);
38
33
  this.forms = new FormCollection();
39
- _classPrivateFieldLooseBase(this, _query)[_query] = new Query();
34
+ this.query = new Query();
40
35
  if (Configuration.webchat.id) {
41
36
  this.webchat = yield Webchat.load(Configuration.webchat.id);
42
37
  }
@@ -68,6 +63,7 @@ var Hellotext = /*#__PURE__*/function () {
68
63
  var pageInstance = params && params.url ? new Page(params.url) : this.page;
69
64
  var body = _objectSpread(_objectSpread({
70
65
  session: this.session,
66
+ user: User.identificationData,
71
67
  action
72
68
  }, params), pageInstance.trackingData);
73
69
  delete body.headers;
@@ -81,6 +77,47 @@ var Hellotext = /*#__PURE__*/function () {
81
77
  }
82
78
  return track;
83
79
  }()
80
+ /**
81
+ * @typedef { Object } IdentificationOptions
82
+ * @property { String } [email] - the email of the user
83
+ * @property { String } [phone] - the phone number of the user
84
+ * @property { String } [name] - the name of the user
85
+ * @property { String } [source] - the platform specific identifier where this pixel is running on.
86
+ *
87
+ * Identifies a user and attaches the hello_session to the user ID
88
+ * @param { String } externalId - the user ID
89
+ * @param { IdentificationOptions } options - the options for the identification
90
+ * @returns {Promise<Response>}
91
+ */
92
+ }, {
93
+ key: "identify",
94
+ value: function () {
95
+ var _identify = _asyncToGenerator(function* (externalId) {
96
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
97
+ var response = yield API.identifications.create(_objectSpread({
98
+ user_id: externalId
99
+ }, options));
100
+ if (response.succeeded) {
101
+ User.remember(externalId, options.source);
102
+ }
103
+ return response;
104
+ });
105
+ function identify(_x4) {
106
+ return _identify.apply(this, arguments);
107
+ }
108
+ return identify;
109
+ }()
110
+ /**
111
+ * Clears the user session, use when the user logs out to clear the hello cookies
112
+ *
113
+ * @returns {void}
114
+ */
115
+ }, {
116
+ key: "forget",
117
+ value: function forget() {
118
+ User.forget();
119
+ }
120
+
84
121
  /**
85
122
  * Registers an event listener
86
123
  * @param event the name of the event to listen to
@@ -144,14 +181,6 @@ var Hellotext = /*#__PURE__*/function () {
144
181
  }]);
145
182
  return Hellotext;
146
183
  }();
147
- Object.defineProperty(Hellotext, _session, {
148
- writable: true,
149
- value: void 0
150
- });
151
- Object.defineProperty(Hellotext, _query, {
152
- writable: true,
153
- value: void 0
154
- });
155
184
  Hellotext.eventEmitter = new Event();
156
185
  Hellotext.forms = void 0;
157
186
  Hellotext.business = void 0;
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.Cookies = void 0;
7
7
  var _hellotext = _interopRequireDefault(require("../hellotext"));
8
+ var _page = require("./page");
8
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
10
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
11
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
@@ -19,7 +20,15 @@ let Cookies = /*#__PURE__*/function () {
19
20
  key: "set",
20
21
  value: function set(name, value) {
21
22
  if (typeof document !== 'undefined') {
22
- document.cookie = `${name}=${value}; path=/;`;
23
+ const secure = window.location.protocol === 'https:' ? '; Secure' : '';
24
+ const domain = _page.Page.getRootDomain();
25
+ const maxAge = 10 * 365 * 24 * 60 * 60; // 10 years in seconds
26
+
27
+ if (domain) {
28
+ document.cookie = `${name}=${value}; path=/${secure}; domain=${domain}; max-age=${maxAge}; SameSite=Lax`;
29
+ } else {
30
+ document.cookie = `${name}=${value}; path=/${secure}; max-age=${maxAge}; SameSite=Lax`;
31
+ }
23
32
  }
24
33
  if (name === 'hello_session') {
25
34
  _hellotext.default.eventEmitter.dispatch('session-set', value);
@@ -39,6 +48,19 @@ let Cookies = /*#__PURE__*/function () {
39
48
  return undefined;
40
49
  }
41
50
  }
51
+ }, {
52
+ key: "delete",
53
+ value: function _delete(name) {
54
+ if (typeof document !== 'undefined') {
55
+ const domain = _page.Page.getRootDomain();
56
+ const secure = window.location.protocol === 'https:' ? '; Secure' : '';
57
+ if (domain) {
58
+ document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${secure}; domain=${domain}; SameSite=Lax`;
59
+ } else {
60
+ document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT${secure}; SameSite=Lax`;
61
+ }
62
+ }
63
+ }
42
64
  }]);
43
65
  return Cookies;
44
66
  }();
@@ -4,6 +4,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
4
4
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
5
5
  function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
6
6
  import Hellotext from '../hellotext';
7
+ import { Page } from './page';
7
8
  var Cookies = /*#__PURE__*/function () {
8
9
  function Cookies() {
9
10
  _classCallCheck(this, Cookies);
@@ -12,7 +13,15 @@ var Cookies = /*#__PURE__*/function () {
12
13
  key: "set",
13
14
  value: function set(name, value) {
14
15
  if (typeof document !== 'undefined') {
15
- document.cookie = "".concat(name, "=").concat(value, "; path=/;");
16
+ var secure = window.location.protocol === 'https:' ? '; Secure' : '';
17
+ var domain = Page.getRootDomain();
18
+ var maxAge = 10 * 365 * 24 * 60 * 60; // 10 years in seconds
19
+
20
+ if (domain) {
21
+ document.cookie = "".concat(name, "=").concat(value, "; path=/").concat(secure, "; domain=").concat(domain, "; max-age=").concat(maxAge, "; SameSite=Lax");
22
+ } else {
23
+ document.cookie = "".concat(name, "=").concat(value, "; path=/").concat(secure, "; max-age=").concat(maxAge, "; SameSite=Lax");
24
+ }
16
25
  }
17
26
  if (name === 'hello_session') {
18
27
  Hellotext.eventEmitter.dispatch('session-set', value);
@@ -32,6 +41,19 @@ var Cookies = /*#__PURE__*/function () {
32
41
  return undefined;
33
42
  }
34
43
  }
44
+ }, {
45
+ key: "delete",
46
+ value: function _delete(name) {
47
+ if (typeof document !== 'undefined') {
48
+ var domain = Page.getRootDomain();
49
+ var secure = window.location.protocol === 'https:' ? '; Secure' : '';
50
+ if (domain) {
51
+ document.cookie = "".concat(name, "=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT").concat(secure, "; domain=").concat(domain, "; SameSite=Lax");
52
+ } else {
53
+ document.cookie = "".concat(name, "=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT").concat(secure, "; SameSite=Lax");
54
+ }
55
+ }
56
+ }
35
57
  }]);
36
58
  return Cookies;
37
59
  }();
@@ -51,6 +51,12 @@ Object.defineProperty(exports, "UTM", {
51
51
  return _utm.UTM;
52
52
  }
53
53
  });
54
+ Object.defineProperty(exports, "User", {
55
+ enumerable: true,
56
+ get: function () {
57
+ return _user.User;
58
+ }
59
+ });
54
60
  Object.defineProperty(exports, "Webchat", {
55
61
  enumerable: true,
56
62
  get: function () {
@@ -64,5 +70,6 @@ var _form_collection = require("./form_collection");
64
70
  var _page = require("./page");
65
71
  var _query = require("./query");
66
72
  var _session = require("./session");
73
+ var _user = require("./user");
67
74
  var _utm = require("./utm");
68
75
  var _webchat = require("./webchat");
@@ -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';
@@ -24,7 +24,7 @@ let Page = /*#__PURE__*/function () {
24
24
  _createClass(Page, [{
25
25
  key: "url",
26
26
  get: function () {
27
- return this._url || window.location.href;
27
+ return this._url !== null && this._url !== undefined ? this._url : window.location.href;
28
28
  }
29
29
 
30
30
  /**
@@ -80,6 +80,84 @@ let Page = /*#__PURE__*/function () {
80
80
  utm_params: this.utmParams
81
81
  };
82
82
  }
83
+
84
+ /**
85
+ * Get the current page domain (root domain for cookie sharing)
86
+ * @returns {string} The root domain with leading dot, or null if no valid URL
87
+ */
88
+ }, {
89
+ key: "domain",
90
+ get: function () {
91
+ try {
92
+ const url = this.url;
93
+ if (!url) {
94
+ return null;
95
+ }
96
+ const hostname = new URL(url).hostname;
97
+ return Page.getRootDomain(hostname);
98
+ } catch (e) {
99
+ return null;
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Get the root domain from a hostname (static method, no instance needed)
105
+ * @param {string} hostname - The hostname to parse
106
+ * @returns {string} The root domain with leading dot, or null if invalid
107
+ */
108
+ }], [{
109
+ key: "getRootDomain",
110
+ value: function getRootDomain(hostname = null) {
111
+ try {
112
+ if (!hostname) {
113
+ var _window$location;
114
+ if (typeof window === 'undefined' || !((_window$location = window.location) !== null && _window$location !== void 0 && _window$location.hostname)) {
115
+ return null;
116
+ }
117
+ hostname = window.location.hostname;
118
+ }
119
+ const parts = hostname.split('.');
120
+
121
+ // Handle localhost or single-part domains
122
+ if (parts.length <= 1) {
123
+ return hostname;
124
+ }
125
+
126
+ // Handle e-commerce platform domains where store identifier must be preserved
127
+ // Examples:
128
+ // storename.myshopify.com -> .storename.myshopify.com
129
+ // storename.vtexcommercestable.com.br -> .storename.vtexcommercestable.com.br
130
+ // storename.wixsite.com -> .storename.wixsite.com
131
+ const platformSuffixes = ['myshopify.com', 'vtexcommercestable.com.br', 'myvtex.com', 'wixsite.com'];
132
+ for (const suffix of platformSuffixes) {
133
+ const suffixParts = suffix.split('.');
134
+ // Get the last N parts of the hostname (e.g., last 2 parts for 'myshopify.com')
135
+ const domainTail = parts.slice(-suffixParts.length).join('.');
136
+
137
+ // Check if the tail exactly matches the platform suffix
138
+ // and there are additional parts for the store identifier
139
+ if (domainTail === suffix && parts.length > suffixParts.length) {
140
+ // Include store identifier + platform suffix
141
+ // e.g., ['secure', 'mystore', 'myshopify', 'com'] -> '.mystore.myshopify.com'
142
+ return `.${parts.slice(-(suffixParts.length + 1)).join('.')}`;
143
+ }
144
+ }
145
+
146
+ // Simple heuristic: if TLD is 2 chars and second-level is short (<=3 chars),
147
+ // it's likely a multi-part TLD like .com.br, .co.uk
148
+ const tld = parts[parts.length - 1];
149
+ const secondLevel = parts[parts.length - 2];
150
+ if (parts.length > 2 && tld.length === 2 && secondLevel.length <= 3) {
151
+ // Multi-part TLD: take last 3 parts (e.g., store.com.br)
152
+ return `.${parts.slice(-3).join('.')}`;
153
+ }
154
+
155
+ // Regular TLD: take last 2 parts (e.g., example.com)
156
+ return `.${parts.slice(-2).join('.')}`;
157
+ } catch (e) {
158
+ return null;
159
+ }
160
+ }
83
161
  }]);
84
162
  return Page;
85
163
  }();
@@ -19,7 +19,7 @@ var Page = /*#__PURE__*/function () {
19
19
  _createClass(Page, [{
20
20
  key: "url",
21
21
  get: function get() {
22
- return this._url || window.location.href;
22
+ return this._url !== null && this._url !== undefined ? this._url : window.location.href;
23
23
  }
24
24
 
25
25
  /**
@@ -75,6 +75,85 @@ var Page = /*#__PURE__*/function () {
75
75
  utm_params: this.utmParams
76
76
  };
77
77
  }
78
+
79
+ /**
80
+ * Get the current page domain (root domain for cookie sharing)
81
+ * @returns {string} The root domain with leading dot, or null if no valid URL
82
+ */
83
+ }, {
84
+ key: "domain",
85
+ get: function get() {
86
+ try {
87
+ var url = this.url;
88
+ if (!url) {
89
+ return null;
90
+ }
91
+ var hostname = new URL(url).hostname;
92
+ return Page.getRootDomain(hostname);
93
+ } catch (e) {
94
+ return null;
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Get the root domain from a hostname (static method, no instance needed)
100
+ * @param {string} hostname - The hostname to parse
101
+ * @returns {string} The root domain with leading dot, or null if invalid
102
+ */
103
+ }], [{
104
+ key: "getRootDomain",
105
+ value: function getRootDomain() {
106
+ var hostname = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
107
+ try {
108
+ if (!hostname) {
109
+ var _window$location;
110
+ if (typeof window === 'undefined' || !((_window$location = window.location) !== null && _window$location !== void 0 && _window$location.hostname)) {
111
+ return null;
112
+ }
113
+ hostname = window.location.hostname;
114
+ }
115
+ var parts = hostname.split('.');
116
+
117
+ // Handle localhost or single-part domains
118
+ if (parts.length <= 1) {
119
+ return hostname;
120
+ }
121
+
122
+ // Handle e-commerce platform domains where store identifier must be preserved
123
+ // Examples:
124
+ // storename.myshopify.com -> .storename.myshopify.com
125
+ // storename.vtexcommercestable.com.br -> .storename.vtexcommercestable.com.br
126
+ // storename.wixsite.com -> .storename.wixsite.com
127
+ var platformSuffixes = ['myshopify.com', 'vtexcommercestable.com.br', 'myvtex.com', 'wixsite.com'];
128
+ for (var suffix of platformSuffixes) {
129
+ var suffixParts = suffix.split('.');
130
+ // Get the last N parts of the hostname (e.g., last 2 parts for 'myshopify.com')
131
+ var domainTail = parts.slice(-suffixParts.length).join('.');
132
+
133
+ // Check if the tail exactly matches the platform suffix
134
+ // and there are additional parts for the store identifier
135
+ if (domainTail === suffix && parts.length > suffixParts.length) {
136
+ // Include store identifier + platform suffix
137
+ // e.g., ['secure', 'mystore', 'myshopify', 'com'] -> '.mystore.myshopify.com'
138
+ return ".".concat(parts.slice(-(suffixParts.length + 1)).join('.'));
139
+ }
140
+ }
141
+
142
+ // Simple heuristic: if TLD is 2 chars and second-level is short (<=3 chars),
143
+ // it's likely a multi-part TLD like .com.br, .co.uk
144
+ var tld = parts[parts.length - 1];
145
+ var secondLevel = parts[parts.length - 2];
146
+ if (parts.length > 2 && tld.length === 2 && secondLevel.length <= 3) {
147
+ // Multi-part TLD: take last 3 parts (e.g., store.com.br)
148
+ return ".".concat(parts.slice(-3).join('.'));
149
+ }
150
+
151
+ // Regular TLD: take last 2 parts (e.g., example.com)
152
+ return ".".concat(parts.slice(-2).join('.'));
153
+ } catch (e) {
154
+ return null;
155
+ }
156
+ }
78
157
  }]);
79
158
  return Page;
80
159
  }();