@hellotext/hellotext 2.4.52 → 2.4.53

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/lib/api/acks.cjs CHANGED
@@ -23,8 +23,9 @@ let AcksAPI = /*#__PURE__*/function () {
23
23
  }
24
24
  }, {
25
25
  key: "send",
26
- value: async function send() {
26
+ value: async function send(params = {}) {
27
27
  const payload = {
28
+ ...params,
28
29
  session: _hellotext.default.session,
29
30
  at: new Date().toISOString()
30
31
  };
package/lib/api/acks.js CHANGED
@@ -1,3 +1,6 @@
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; }
1
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); } }
2
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); }); }; }
3
6
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -20,10 +23,11 @@ var AcksAPI = /*#__PURE__*/function () {
20
23
  key: "send",
21
24
  value: function () {
22
25
  var _send = _asyncToGenerator(function* () {
23
- var payload = {
26
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
27
+ var payload = _objectSpread(_objectSpread({}, params), {}, {
24
28
  session: Hellotext.session,
25
29
  at: new Date().toISOString()
26
- };
30
+ });
27
31
  fetch(this.endpoint, {
28
32
  method: 'POST',
29
33
  headers: Hellotext.headers,
package/lib/hellotext.cjs CHANGED
@@ -29,9 +29,9 @@ let Hellotext = /*#__PURE__*/function () {
29
29
  */
30
30
  async function initialize(business, config = {}) {
31
31
  this.business = new _models.Business(business);
32
- _core.Configuration.assign(config);
33
- _models.Session.initialize();
34
32
  this.page = new _models.Page();
33
+ _core.Configuration.assign(config);
34
+ _models.Session.initialize(this.page);
35
35
  this.forms = new _models.FormCollection();
36
36
  this.query = new _models.Query();
37
37
  const businessData = await this.business.hydrate();
package/lib/hellotext.js CHANGED
@@ -28,9 +28,9 @@ var Hellotext = /*#__PURE__*/function () {
28
28
  var _initialize = _asyncToGenerator(function* (business) {
29
29
  var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
30
30
  this.business = new Business(business);
31
- Configuration.assign(config);
32
- Session.initialize();
33
31
  this.page = new Page();
32
+ Configuration.assign(config);
33
+ Session.initialize(this.page);
34
34
  this.forms = new FormCollection();
35
35
  this.query = new Query();
36
36
  var businessData = yield this.business.hydrate();
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.Session = void 0;
7
7
  var _core = require("../core");
8
8
  var _cookies = require("./cookies");
9
+ var _page2 = require("./page");
9
10
  var _query2 = require("./query");
10
11
  var _api = _interopRequireDefault(require("../api"));
11
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -19,6 +20,7 @@ var id = 0;
19
20
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
20
21
  var _session = /*#__PURE__*/_classPrivateFieldLooseKey("session");
21
22
  var _query = /*#__PURE__*/_classPrivateFieldLooseKey("query");
23
+ var _page = /*#__PURE__*/_classPrivateFieldLooseKey("page");
22
24
  let Session = /*#__PURE__*/function () {
23
25
  function Session() {
24
26
  _classCallCheck(this, Session);
@@ -36,14 +38,23 @@ let Session = /*#__PURE__*/function () {
36
38
  _cookies.Cookies.delete('hello_session_ack_at');
37
39
  }
38
40
  if (!_cookies.Cookies.get('hello_session_ack_at')) {
39
- _api.default.acks.send();
41
+ _api.default.acks.send(this.ackPayload);
40
42
  _cookies.Cookies.set('hello_session_ack_at', new Date().toISOString());
41
43
  }
42
44
  return _classPrivateFieldLooseBase(this, _session)[_session];
43
45
  }
46
+ }, {
47
+ key: "ackPayload",
48
+ get: function () {
49
+ var _classPrivateFieldLoo;
50
+ return {
51
+ utm_params: ((_classPrivateFieldLoo = _classPrivateFieldLooseBase(this, _page)[_page]) === null || _classPrivateFieldLoo === void 0 ? void 0 : _classPrivateFieldLoo.utmParams) || {}
52
+ };
53
+ }
44
54
  }, {
45
55
  key: "initialize",
46
- value: function initialize() {
56
+ value: function initialize(page = new _page2.Page()) {
57
+ _classPrivateFieldLooseBase(this, _page)[_page] = page;
47
58
  _classPrivateFieldLooseBase(this, _query)[_query] = new _query2.Query();
48
59
  this.session = _classPrivateFieldLooseBase(this, _query)[_query].session || _core.Configuration.session || _cookies.Cookies.get('hello_session');
49
60
  if (!this.session && _core.Configuration.autoGenerateSession) {
@@ -61,4 +72,8 @@ Object.defineProperty(Session, _session, {
61
72
  Object.defineProperty(Session, _query, {
62
73
  writable: true,
63
74
  value: void 0
75
+ });
76
+ Object.defineProperty(Session, _page, {
77
+ writable: true,
78
+ value: void 0
64
79
  });
@@ -8,10 +8,12 @@ var id = 0;
8
8
  function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
9
9
  import { Configuration } from '../core';
10
10
  import { Cookies } from './cookies';
11
+ import { Page } from './page';
11
12
  import { Query } from './query';
12
13
  import API from '../api';
13
14
  var _session = /*#__PURE__*/_classPrivateFieldLooseKey("session");
14
15
  var _query = /*#__PURE__*/_classPrivateFieldLooseKey("query");
16
+ var _page = /*#__PURE__*/_classPrivateFieldLooseKey("page");
15
17
  var Session = /*#__PURE__*/function () {
16
18
  function Session() {
17
19
  _classCallCheck(this, Session);
@@ -29,14 +31,24 @@ var Session = /*#__PURE__*/function () {
29
31
  Cookies.delete('hello_session_ack_at');
30
32
  }
31
33
  if (!Cookies.get('hello_session_ack_at')) {
32
- API.acks.send();
34
+ API.acks.send(this.ackPayload);
33
35
  Cookies.set('hello_session_ack_at', new Date().toISOString());
34
36
  }
35
37
  return _classPrivateFieldLooseBase(this, _session)[_session];
36
38
  }
39
+ }, {
40
+ key: "ackPayload",
41
+ get: function get() {
42
+ var _classPrivateFieldLoo;
43
+ return {
44
+ utm_params: ((_classPrivateFieldLoo = _classPrivateFieldLooseBase(this, _page)[_page]) === null || _classPrivateFieldLoo === void 0 ? void 0 : _classPrivateFieldLoo.utmParams) || {}
45
+ };
46
+ }
37
47
  }, {
38
48
  key: "initialize",
39
49
  value: function initialize() {
50
+ var page = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : new Page();
51
+ _classPrivateFieldLooseBase(this, _page)[_page] = page;
40
52
  _classPrivateFieldLooseBase(this, _query)[_query] = new Query();
41
53
  this.session = _classPrivateFieldLooseBase(this, _query)[_query].session || Configuration.session || Cookies.get('hello_session');
42
54
  if (!this.session && Configuration.autoGenerateSession) {
@@ -54,4 +66,8 @@ Object.defineProperty(Session, _query, {
54
66
  writable: true,
55
67
  value: void 0
56
68
  });
69
+ Object.defineProperty(Session, _page, {
70
+ writable: true,
71
+ value: void 0
72
+ });
57
73
  export { Session };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hellotext/hellotext",
3
- "version": "2.4.52",
3
+ "version": "2.4.53",
4
4
  "description": "Hellotext JavaScript Client",
5
5
  "source": "src/index.js",
6
6
  "main": "lib/index.cjs",
package/src/api/acks.js CHANGED
@@ -7,8 +7,9 @@ class AcksAPI {
7
7
  return Configuration.endpoint('public/acks')
8
8
  }
9
9
 
10
- static async send() {
10
+ static async send(params = {}) {
11
11
  const payload = {
12
+ ...params,
12
13
  session: Hellotext.session,
13
14
  at: new Date().toISOString(),
14
15
  }
package/src/hellotext.js CHANGED
@@ -1,7 +1,16 @@
1
1
  import { Configuration, Event } from './core'
2
2
 
3
3
  import API, { Response, keepaliveFor } from './api'
4
- import { Business, Fingerprint, FormCollection, Page, Query, Session, User, Webchat } from './models'
4
+ import {
5
+ Business,
6
+ Fingerprint,
7
+ FormCollection,
8
+ Page,
9
+ Query,
10
+ Session,
11
+ User,
12
+ Webchat,
13
+ } from './models'
5
14
 
6
15
  import { NotInitializedError } from './errors'
7
16
 
@@ -18,25 +27,28 @@ class Hellotext {
18
27
  */
19
28
  static async initialize(business, config = {}) {
20
29
  this.business = new Business(business)
30
+ this.page = new Page()
21
31
 
22
32
  Configuration.assign(config)
23
- Session.initialize()
33
+ Session.initialize(this.page)
24
34
 
25
- this.page = new Page()
26
35
  this.forms = new FormCollection()
27
36
 
28
37
  this.query = new Query()
29
38
 
30
39
  const businessData = await this.business.hydrate()
31
- const webchatConfig = config.webchat === false ?
32
- false :
33
- this.mergeWebchatConfig((businessData && businessData.webchat) || {}, config.webchat || {})
34
-
35
- const hasExplicitBehaviourOverride = (
40
+ const webchatConfig =
41
+ config.webchat === false
42
+ ? false
43
+ : this.mergeWebchatConfig(
44
+ (businessData && businessData.webchat) || {},
45
+ config.webchat || {},
46
+ )
47
+
48
+ const hasExplicitBehaviourOverride =
36
49
  config.webchat &&
37
50
  config.webchat !== false &&
38
51
  Object.prototype.hasOwnProperty.call(config.webchat, 'behaviour')
39
- )
40
52
  Configuration.webchat.behaviourOverride = hasExplicitBehaviourOverride
41
53
 
42
54
  if (webchatConfig && webchatConfig.id) {
@@ -147,11 +159,7 @@ class Hellotext {
147
159
  })
148
160
 
149
161
  if (response.succeeded) {
150
- User.remember(
151
- externalId,
152
- options.source,
153
- fingerprint,
154
- )
162
+ User.remember(externalId, options.source, fingerprint)
155
163
  }
156
164
 
157
165
  return response
@@ -1,16 +1,24 @@
1
1
  import { Configuration } from '../core'
2
2
  import { Cookies } from './cookies'
3
+ import { Page } from './page'
3
4
  import { Query } from './query'
4
5
  import API from '../api'
5
6
 
6
7
  class Session {
7
8
  static #session
8
9
  static #query
10
+ static #page
9
11
 
10
12
  static get session() {
11
13
  return this.#session
12
14
  }
13
15
 
16
+ static get ackPayload() {
17
+ return {
18
+ utm_params: this.#page?.utmParams || {},
19
+ }
20
+ }
21
+
14
22
  static set session(value) {
15
23
  const oldSession = Cookies.get('hello_session')
16
24
 
@@ -22,14 +30,15 @@ class Session {
22
30
  }
23
31
 
24
32
  if (!Cookies.get('hello_session_ack_at')) {
25
- API.acks.send()
33
+ API.acks.send(this.ackPayload)
26
34
  Cookies.set('hello_session_ack_at', new Date().toISOString())
27
35
  }
28
36
 
29
37
  return this.#session
30
38
  }
31
39
 
32
- static initialize() {
40
+ static initialize(page = new Page()) {
41
+ this.#page = page
33
42
  this.#query = new Query()
34
43
 
35
44
  this.session = this.#query.session || Configuration.session || Cookies.get('hello_session')