@hellotext/hellotext 2.3.5 → 2.3.6

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.
@@ -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
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
14
+ 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); }
15
+ let AcksAPI = /*#__PURE__*/function () {
16
+ function AcksAPI() {
17
+ _classCallCheck(this, AcksAPI);
18
+ }
19
+ _createClass(AcksAPI, null, [{
20
+ key: "endpoint",
21
+ get: function () {
22
+ return _core.Configuration.endpoint('public/acks');
23
+ }
24
+ }, {
25
+ key: "send",
26
+ value: async function send() {
27
+ const payload = {
28
+ session: _hellotext.default.session,
29
+ at: new Date().toISOString()
30
+ };
31
+ fetch(this.endpoint, {
32
+ method: 'POST',
33
+ headers: _hellotext.default.headers,
34
+ body: JSON.stringify(payload),
35
+ keepalive: true
36
+ });
37
+ }
38
+ }]);
39
+ return AcksAPI;
40
+ }();
41
+ var _default = AcksAPI;
42
+ exports.default = _default;
@@ -0,0 +1,42 @@
1
+ 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
+ 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
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+ 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); } }
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
7
+ 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); }
8
+ import Hellotext from '../hellotext';
9
+ import { Configuration } from '../core';
10
+ var AcksAPI = /*#__PURE__*/function () {
11
+ function AcksAPI() {
12
+ _classCallCheck(this, AcksAPI);
13
+ }
14
+ _createClass(AcksAPI, null, [{
15
+ key: "endpoint",
16
+ get: function get() {
17
+ return Configuration.endpoint('public/acks');
18
+ }
19
+ }, {
20
+ key: "send",
21
+ value: function () {
22
+ var _send = _asyncToGenerator(function* () {
23
+ var payload = {
24
+ session: Hellotext.session,
25
+ at: new Date().toISOString()
26
+ };
27
+ fetch(this.endpoint, {
28
+ method: 'POST',
29
+ headers: Hellotext.headers,
30
+ body: JSON.stringify(payload),
31
+ keepalive: true
32
+ });
33
+ });
34
+ function send() {
35
+ return _send.apply(this, arguments);
36
+ }
37
+ return send;
38
+ }()
39
+ }]);
40
+ return AcksAPI;
41
+ }();
42
+ export default AcksAPI;
package/lib/api/index.cjs CHANGED
@@ -15,6 +15,7 @@ var _events = _interopRequireDefault(require("./events"));
15
15
  var _forms = _interopRequireDefault(require("./forms"));
16
16
  var _identifications = _interopRequireDefault(require("./identifications"));
17
17
  var _webchats = _interopRequireDefault(require("./webchats"));
18
+ var _acks = _interopRequireDefault(require("./acks"));
18
19
  var _response = require("./response");
19
20
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
21
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -51,6 +52,11 @@ let API = /*#__PURE__*/function () {
51
52
  get: function () {
52
53
  return _identifications.default;
53
54
  }
55
+ }, {
56
+ key: "acks",
57
+ get: function () {
58
+ return _acks.default;
59
+ }
54
60
  }]);
55
61
  return API;
56
62
  }();
package/lib/api/index.js CHANGED
@@ -8,6 +8,7 @@ import EventsAPI from './events';
8
8
  import FormsAPI from './forms';
9
9
  import IdentificationsAPI from './identifications';
10
10
  import WebchatsAPI from './webchats';
11
+ import AcksAPI from './acks';
11
12
  var API = /*#__PURE__*/function () {
12
13
  function API() {
13
14
  _classCallCheck(this, API);
@@ -37,6 +38,11 @@ var API = /*#__PURE__*/function () {
37
38
  get: function get() {
38
39
  return IdentificationsAPI;
39
40
  }
41
+ }, {
42
+ key: "acks",
43
+ get: function get() {
44
+ return AcksAPI;
45
+ }
40
46
  }]);
41
47
  return API;
42
48
  }();
package/lib/hellotext.cjs CHANGED
@@ -28,10 +28,10 @@ let Hellotext = /*#__PURE__*/function () {
28
28
  * @param { Configuration } config
29
29
  */
30
30
  async function initialize(business, config) {
31
+ this.business = new _models.Business(business);
31
32
  _core.Configuration.assign(config);
32
33
  _models.Session.initialize();
33
34
  this.page = new _models.Page();
34
- this.business = new _models.Business(business);
35
35
  this.forms = new _models.FormCollection();
36
36
  this.query = new _models.Query();
37
37
  if (_core.Configuration.webchat.id) {
@@ -167,7 +167,7 @@ let Hellotext = /*#__PURE__*/function () {
167
167
  }, {
168
168
  key: "notInitialized",
169
169
  get: function () {
170
- return this.business.id === undefined;
170
+ return !this.business || this.business.id === undefined;
171
171
  }
172
172
  }, {
173
173
  key: "headers",
package/lib/hellotext.js CHANGED
@@ -26,10 +26,10 @@ var Hellotext = /*#__PURE__*/function () {
26
26
  */
27
27
  function () {
28
28
  var _initialize = _asyncToGenerator(function* (business, config) {
29
+ this.business = new Business(business);
29
30
  Configuration.assign(config);
30
31
  Session.initialize();
31
32
  this.page = new Page();
32
- this.business = new Business(business);
33
33
  this.forms = new FormCollection();
34
34
  this.query = new Query();
35
35
  if (Configuration.webchat.id) {
@@ -178,7 +178,7 @@ var Hellotext = /*#__PURE__*/function () {
178
178
  }, {
179
179
  key: "notInitialized",
180
180
  get: function get() {
181
- return this.business.id === undefined;
181
+ return !this.business || this.business.id === undefined;
182
182
  }
183
183
  }, {
184
184
  key: "headers",
@@ -7,6 +7,8 @@ exports.Session = void 0;
7
7
  var _core = require("../core");
8
8
  var _cookies = require("./cookies");
9
9
  var _query2 = require("./query");
10
+ var _api = _interopRequireDefault(require("../api"));
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
12
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
11
13
  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); } }
12
14
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -27,8 +29,17 @@ let Session = /*#__PURE__*/function () {
27
29
  return _classPrivateFieldLooseBase(this, _session)[_session];
28
30
  },
29
31
  set: function (value) {
32
+ const oldSession = _cookies.Cookies.get('hello_session');
30
33
  _classPrivateFieldLooseBase(this, _session)[_session] = value;
31
34
  _cookies.Cookies.set('hello_session', value);
35
+ if (oldSession !== value) {
36
+ _cookies.Cookies.delete('hello_session_ack_at');
37
+ }
38
+ if (!_cookies.Cookies.get('hello_session_ack_at')) {
39
+ _api.default.acks.send();
40
+ _cookies.Cookies.set('hello_session_ack_at', new Date().toISOString());
41
+ }
42
+ return _classPrivateFieldLooseBase(this, _session)[_session];
32
43
  }
33
44
  }, {
34
45
  key: "initialize",
@@ -9,6 +9,7 @@ function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + n
9
9
  import { Configuration } from '../core';
10
10
  import { Cookies } from './cookies';
11
11
  import { Query } from './query';
12
+ import API from '../api';
12
13
  var _session = /*#__PURE__*/_classPrivateFieldLooseKey("session");
13
14
  var _query = /*#__PURE__*/_classPrivateFieldLooseKey("query");
14
15
  var Session = /*#__PURE__*/function () {
@@ -21,8 +22,17 @@ var Session = /*#__PURE__*/function () {
21
22
  return _classPrivateFieldLooseBase(this, _session)[_session];
22
23
  },
23
24
  set: function set(value) {
25
+ var oldSession = Cookies.get('hello_session');
24
26
  _classPrivateFieldLooseBase(this, _session)[_session] = value;
25
27
  Cookies.set('hello_session', value);
28
+ if (oldSession !== value) {
29
+ Cookies.delete('hello_session_ack_at');
30
+ }
31
+ if (!Cookies.get('hello_session_ack_at')) {
32
+ API.acks.send();
33
+ Cookies.set('hello_session_ack_at', new Date().toISOString());
34
+ }
35
+ return _classPrivateFieldLooseBase(this, _session)[_session];
26
36
  }
27
37
  }, {
28
38
  key: "initialize",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hellotext/hellotext",
3
- "version": "2.3.5",
3
+ "version": "2.3.6",
4
4
  "description": "Hellotext JavaScript Client",
5
5
  "source": "src/index.js",
6
6
  "main": "lib/index.cjs",
@@ -0,0 +1,25 @@
1
+ import Hellotext from '../hellotext'
2
+
3
+ import { Configuration } from '../core'
4
+
5
+ class AcksAPI {
6
+ static get endpoint() {
7
+ return Configuration.endpoint('public/acks')
8
+ }
9
+
10
+ static async send() {
11
+ const payload = {
12
+ session: Hellotext.session,
13
+ at: new Date().toISOString(),
14
+ }
15
+
16
+ fetch(this.endpoint, {
17
+ method: 'POST',
18
+ headers: Hellotext.headers,
19
+ body: JSON.stringify(payload),
20
+ keepalive: true,
21
+ })
22
+ }
23
+ }
24
+
25
+ export default AcksAPI
package/src/api/index.js CHANGED
@@ -3,6 +3,7 @@ import EventsAPI from './events'
3
3
  import FormsAPI from './forms'
4
4
  import IdentificationsAPI from './identifications'
5
5
  import WebchatsAPI from './webchats'
6
+ import AcksAPI from './acks'
6
7
 
7
8
  export default class API {
8
9
  static get businesses() {
@@ -24,6 +25,10 @@ export default class API {
24
25
  static get identifications() {
25
26
  return IdentificationsAPI
26
27
  }
28
+
29
+ static get acks() {
30
+ return AcksAPI
31
+ }
27
32
  }
28
33
 
29
34
  export { Response } from './response'
package/src/hellotext.js CHANGED
@@ -17,11 +17,12 @@ class Hellotext {
17
17
  * @param { Configuration } config
18
18
  */
19
19
  static async initialize(business, config) {
20
+ this.business = new Business(business)
21
+
20
22
  Configuration.assign(config)
21
23
  Session.initialize()
22
24
 
23
25
  this.page = new Page()
24
- this.business = new Business(business)
25
26
  this.forms = new FormCollection()
26
27
 
27
28
  this.query = new Query()
@@ -154,7 +155,7 @@ class Hellotext {
154
155
  // private
155
156
 
156
157
  static get notInitialized() {
157
- return this.business.id === undefined
158
+ return !this.business || this.business.id === undefined
158
159
  }
159
160
 
160
161
  static get headers() {
@@ -1,6 +1,7 @@
1
1
  import { Configuration } from '../core'
2
2
  import { Cookies } from './cookies'
3
3
  import { Query } from './query'
4
+ import API from '../api'
4
5
 
5
6
  class Session {
6
7
  static #session
@@ -11,8 +12,21 @@ class Session {
11
12
  }
12
13
 
13
14
  static set session(value) {
15
+ const oldSession = Cookies.get('hello_session')
16
+
14
17
  this.#session = value
15
18
  Cookies.set('hello_session', value)
19
+
20
+ if (oldSession !== value) {
21
+ Cookies.delete('hello_session_ack_at')
22
+ }
23
+
24
+ if (!Cookies.get('hello_session_ack_at')) {
25
+ API.acks.send()
26
+ Cookies.set('hello_session_ack_at', new Date().toISOString())
27
+ }
28
+
29
+ return this.#session
16
30
  }
17
31
 
18
32
  static initialize() {