@hellotext/hellotext 2.2.1 → 2.3.1
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/README.md +1 -44
- package/dist/hellotext.js +1 -1
- package/index.d.ts +28 -0
- package/lib/api/identifications.cjs +42 -0
- package/lib/api/identifications.js +45 -0
- package/lib/api/index.cjs +6 -0
- package/lib/api/index.js +6 -0
- package/lib/hellotext.cjs +45 -14
- package/lib/hellotext.js +57 -15
- package/lib/models/cookies.cjs +13 -0
- package/lib/models/cookies.js +13 -0
- package/lib/models/index.cjs +7 -0
- package/lib/models/index.js +1 -0
- package/lib/models/user.cjs +53 -0
- package/lib/models/user.js +47 -0
- package/package.json +1 -1
- package/src/api/identifications.js +25 -0
- package/src/api/index.js +5 -0
- package/src/hellotext.js +45 -5
- package/src/models/cookies.js +13 -0
- package/src/models/index.js +1 -0
- package/src/models/user.js +35 -0
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
|
-
|
|
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,49 @@ 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
|
+
if (_models.User.id === externalId) {
|
|
93
|
+
return new _api.Response(true, {
|
|
94
|
+
json: async () => {
|
|
95
|
+
already_identified: true;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
const response = await _api.default.identifications.create({
|
|
100
|
+
user_id: externalId,
|
|
101
|
+
...options
|
|
102
|
+
});
|
|
103
|
+
if (response.succeeded) {
|
|
104
|
+
_models.User.remember(externalId, options.source);
|
|
105
|
+
}
|
|
106
|
+
return response;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Clears the user session, use when the user logs out to clear the hello cookies
|
|
111
|
+
*
|
|
112
|
+
* @returns {void}
|
|
113
|
+
*/
|
|
114
|
+
}, {
|
|
115
|
+
key: "forget",
|
|
116
|
+
value: function forget() {
|
|
117
|
+
_models.User.forget();
|
|
118
|
+
}
|
|
119
|
+
|
|
81
120
|
/**
|
|
82
121
|
* Registers an event listener
|
|
83
122
|
* @param event the name of the event to listen to
|
|
@@ -141,14 +180,6 @@ let Hellotext = /*#__PURE__*/function () {
|
|
|
141
180
|
}]);
|
|
142
181
|
return Hellotext;
|
|
143
182
|
}();
|
|
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
183
|
Hellotext.eventEmitter = new _core.Event();
|
|
153
184
|
Hellotext.forms = void 0;
|
|
154
185
|
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
|
-
|
|
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,60 @@ 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
|
+
if (User.id === externalId) {
|
|
98
|
+
return new Response(true, {
|
|
99
|
+
json: function () {
|
|
100
|
+
var _json = _asyncToGenerator(function* () {
|
|
101
|
+
already_identified: true;
|
|
102
|
+
});
|
|
103
|
+
function json() {
|
|
104
|
+
return _json.apply(this, arguments);
|
|
105
|
+
}
|
|
106
|
+
return json;
|
|
107
|
+
}()
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
var response = yield API.identifications.create(_objectSpread({
|
|
111
|
+
user_id: externalId
|
|
112
|
+
}, options));
|
|
113
|
+
if (response.succeeded) {
|
|
114
|
+
User.remember(externalId, options.source);
|
|
115
|
+
}
|
|
116
|
+
return response;
|
|
117
|
+
});
|
|
118
|
+
function identify(_x4) {
|
|
119
|
+
return _identify.apply(this, arguments);
|
|
120
|
+
}
|
|
121
|
+
return identify;
|
|
122
|
+
}()
|
|
123
|
+
/**
|
|
124
|
+
* Clears the user session, use when the user logs out to clear the hello cookies
|
|
125
|
+
*
|
|
126
|
+
* @returns {void}
|
|
127
|
+
*/
|
|
128
|
+
}, {
|
|
129
|
+
key: "forget",
|
|
130
|
+
value: function forget() {
|
|
131
|
+
User.forget();
|
|
132
|
+
}
|
|
133
|
+
|
|
84
134
|
/**
|
|
85
135
|
* Registers an event listener
|
|
86
136
|
* @param event the name of the event to listen to
|
|
@@ -144,14 +194,6 @@ var Hellotext = /*#__PURE__*/function () {
|
|
|
144
194
|
}]);
|
|
145
195
|
return Hellotext;
|
|
146
196
|
}();
|
|
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
197
|
Hellotext.eventEmitter = new Event();
|
|
156
198
|
Hellotext.forms = void 0;
|
|
157
199
|
Hellotext.business = void 0;
|
package/lib/models/cookies.cjs
CHANGED
|
@@ -48,6 +48,19 @@ let Cookies = /*#__PURE__*/function () {
|
|
|
48
48
|
return undefined;
|
|
49
49
|
}
|
|
50
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
|
+
}
|
|
51
64
|
}]);
|
|
52
65
|
return Cookies;
|
|
53
66
|
}();
|
package/lib/models/cookies.js
CHANGED
|
@@ -41,6 +41,19 @@ var Cookies = /*#__PURE__*/function () {
|
|
|
41
41
|
return undefined;
|
|
42
42
|
}
|
|
43
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
|
+
}
|
|
44
57
|
}]);
|
|
45
58
|
return Cookies;
|
|
46
59
|
}();
|
package/lib/models/index.cjs
CHANGED
|
@@ -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");
|
package/lib/models/index.js
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.User = void 0;
|
|
7
|
+
var _cookies = require("./cookies");
|
|
8
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
9
|
+
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); } }
|
|
10
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
11
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
12
|
+
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); }
|
|
13
|
+
let User = /*#__PURE__*/function () {
|
|
14
|
+
function User() {
|
|
15
|
+
_classCallCheck(this, User);
|
|
16
|
+
}
|
|
17
|
+
_createClass(User, null, [{
|
|
18
|
+
key: "id",
|
|
19
|
+
get: function () {
|
|
20
|
+
return _cookies.Cookies.get('hello_user_id');
|
|
21
|
+
}
|
|
22
|
+
}, {
|
|
23
|
+
key: "source",
|
|
24
|
+
get: function () {
|
|
25
|
+
return _cookies.Cookies.get('hello_user_source');
|
|
26
|
+
}
|
|
27
|
+
}, {
|
|
28
|
+
key: "remember",
|
|
29
|
+
value: function remember(id, source) {
|
|
30
|
+
if (source) {
|
|
31
|
+
_cookies.Cookies.set('hello_user_source', source);
|
|
32
|
+
}
|
|
33
|
+
_cookies.Cookies.set('hello_user_id', id);
|
|
34
|
+
}
|
|
35
|
+
}, {
|
|
36
|
+
key: "forget",
|
|
37
|
+
value: function forget() {
|
|
38
|
+
_cookies.Cookies.delete('hello_user_id');
|
|
39
|
+
_cookies.Cookies.delete('hello_user_source');
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
key: "identificationData",
|
|
43
|
+
get: function () {
|
|
44
|
+
if (!this.id) return {};
|
|
45
|
+
return {
|
|
46
|
+
id: this.id,
|
|
47
|
+
source: this.source
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}]);
|
|
51
|
+
return User;
|
|
52
|
+
}();
|
|
53
|
+
exports.User = User;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
2
|
+
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); } }
|
|
3
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
4
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
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
|
+
import { Cookies } from './cookies';
|
|
7
|
+
var User = /*#__PURE__*/function () {
|
|
8
|
+
function User() {
|
|
9
|
+
_classCallCheck(this, User);
|
|
10
|
+
}
|
|
11
|
+
_createClass(User, null, [{
|
|
12
|
+
key: "id",
|
|
13
|
+
get: function get() {
|
|
14
|
+
return Cookies.get('hello_user_id');
|
|
15
|
+
}
|
|
16
|
+
}, {
|
|
17
|
+
key: "source",
|
|
18
|
+
get: function get() {
|
|
19
|
+
return Cookies.get('hello_user_source');
|
|
20
|
+
}
|
|
21
|
+
}, {
|
|
22
|
+
key: "remember",
|
|
23
|
+
value: function remember(id, source) {
|
|
24
|
+
if (source) {
|
|
25
|
+
Cookies.set('hello_user_source', source);
|
|
26
|
+
}
|
|
27
|
+
Cookies.set('hello_user_id', id);
|
|
28
|
+
}
|
|
29
|
+
}, {
|
|
30
|
+
key: "forget",
|
|
31
|
+
value: function forget() {
|
|
32
|
+
Cookies.delete('hello_user_id');
|
|
33
|
+
Cookies.delete('hello_user_source');
|
|
34
|
+
}
|
|
35
|
+
}, {
|
|
36
|
+
key: "identificationData",
|
|
37
|
+
get: function get() {
|
|
38
|
+
if (!this.id) return {};
|
|
39
|
+
return {
|
|
40
|
+
id: this.id,
|
|
41
|
+
source: this.source
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}]);
|
|
45
|
+
return User;
|
|
46
|
+
}();
|
|
47
|
+
export { User };
|
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Hellotext from '../hellotext'
|
|
2
|
+
|
|
3
|
+
import { Configuration } from '../core'
|
|
4
|
+
import { Response } from './response'
|
|
5
|
+
|
|
6
|
+
class IdentificationsAPI {
|
|
7
|
+
static get endpoint() {
|
|
8
|
+
return Configuration.endpoint('public/identifications')
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static async create(data = {}) {
|
|
12
|
+
const response = await fetch(this.endpoint, {
|
|
13
|
+
method: 'POST',
|
|
14
|
+
headers: Hellotext.headers,
|
|
15
|
+
body: JSON.stringify({
|
|
16
|
+
session: Hellotext.session,
|
|
17
|
+
...data,
|
|
18
|
+
}),
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
return new Response(response.ok, response)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default IdentificationsAPI
|
package/src/api/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import BusinessesAPI from './businesses'
|
|
2
2
|
import EventsAPI from './events'
|
|
3
3
|
import FormsAPI from './forms'
|
|
4
|
+
import IdentificationsAPI from './identifications'
|
|
4
5
|
import WebchatsAPI from './webchats'
|
|
5
6
|
|
|
6
7
|
export default class API {
|
|
@@ -19,6 +20,10 @@ export default class API {
|
|
|
19
20
|
static get webchats() {
|
|
20
21
|
return WebchatsAPI
|
|
21
22
|
}
|
|
23
|
+
|
|
24
|
+
static get identifications() {
|
|
25
|
+
return IdentificationsAPI
|
|
26
|
+
}
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
export { Response } from './response'
|