@hellotext/hellotext 2.5.6 → 2.5.8
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 +5 -26
- package/dist/hellotext.js +1 -1
- package/dist/hellotext.js.LICENSE.txt +1 -1
- package/index.d.ts +15 -6
- package/lib/api/acks.cjs +17 -31
- package/lib/api/acks.js +17 -42
- package/lib/api/businesses.cjs +14 -28
- package/lib/api/businesses.js +13 -36
- package/lib/api/events.cjs +26 -40
- package/lib/api/events.js +28 -52
- package/lib/api/forms.cjs +24 -40
- package/lib/api/forms.js +24 -57
- package/lib/api/identifications.cjs +15 -29
- package/lib/api/identifications.js +15 -40
- package/lib/api/index.cjs +26 -46
- package/lib/api/index.js +28 -49
- package/lib/api/push/identities.cjs +43 -0
- package/lib/api/push/identities.js +35 -0
- package/lib/api/response.cjs +30 -52
- package/lib/api/response.js +31 -60
- package/lib/api/submissions.cjs +18 -34
- package/lib/api/submissions.js +18 -48
- package/lib/api/webchat/messages.cjs +44 -64
- package/lib/api/webchat/messages.js +44 -80
- package/lib/api/webchats.cjs +37 -56
- package/lib/api/webchats.js +37 -65
- package/lib/api/whatsapp_widgets.cjs +49 -72
- package/lib/api/whatsapp_widgets.js +48 -91
- package/lib/builders/input_builder.cjs +36 -48
- package/lib/builders/input_builder.js +36 -48
- package/lib/builders/logo_builder.cjs +10 -29
- package/lib/builders/logo_builder.js +20 -28
- package/lib/channels/application_channel.cjs +136 -178
- package/lib/channels/application_channel.js +137 -180
- package/lib/channels/webchat_channel.cjs +125 -170
- package/lib/channels/webchat_channel.js +125 -170
- package/lib/controllers/form_controller.cjs +82 -121
- package/lib/controllers/form_controller.js +82 -130
- package/lib/controllers/message_controller.cjs +211 -282
- package/lib/controllers/message_controller.js +209 -284
- package/lib/controllers/mixins/usePopover.cjs +3 -6
- package/lib/controllers/mixins/usePopover.js +17 -22
- package/lib/controllers/webchat/emoji_picker_controller.cjs +106 -150
- package/lib/controllers/webchat/emoji_picker_controller.js +105 -170
- package/lib/controllers/webchat/useBehaviour.js +5 -5
- package/lib/controllers/webchat/useOpeningSequence.js +6 -6
- package/lib/controllers/webchat/useTeaser.js +9 -9
- package/lib/controllers/webchat_controller.cjs +916 -1088
- package/lib/controllers/webchat_controller.js +926 -1152
- package/lib/core/configuration/forms.cjs +21 -35
- package/lib/core/configuration/forms.js +20 -35
- package/lib/core/configuration/locale.cjs +36 -71
- package/lib/core/configuration/locale.js +36 -70
- package/lib/core/configuration/push.cjs +16 -0
- package/lib/core/configuration/push.js +10 -0
- package/lib/core/configuration/webchat.cjs +142 -182
- package/lib/core/configuration/webchat.js +145 -189
- package/lib/core/configuration/whatsapp.cjs +76 -102
- package/lib/core/configuration/whatsapp.js +76 -105
- package/lib/core/configuration.cjs +62 -75
- package/lib/core/configuration.js +61 -75
- package/lib/core/event.cjs +36 -59
- package/lib/core/event.js +35 -61
- package/lib/core/sanitize_html.js +4 -4
- package/lib/errors/invalid_event.cjs +5 -26
- package/lib/errors/invalid_event.js +5 -26
- package/lib/errors/not_initialized_error.cjs +5 -26
- package/lib/errors/not_initialized_error.js +5 -26
- package/lib/hellotext.cjs +186 -211
- package/lib/hellotext.js +189 -236
- package/lib/index.js +1 -1
- package/lib/models/business.cjs +115 -152
- package/lib/models/business.js +118 -162
- package/lib/models/cookies.cjs +34 -51
- package/lib/models/cookies.js +34 -51
- package/lib/models/fingerprint.cjs +8 -23
- package/lib/models/fingerprint.js +25 -58
- package/lib/models/form.cjs +106 -142
- package/lib/models/form.js +105 -153
- package/lib/models/form_collection.cjs +63 -101
- package/lib/models/form_collection.js +61 -107
- package/lib/models/index.cjs +7 -0
- package/lib/models/index.js +1 -0
- package/lib/models/page.cjs +106 -129
- package/lib/models/page.js +106 -131
- package/lib/models/push.cjs +345 -0
- package/lib/models/push.js +339 -0
- package/lib/models/query.cjs +21 -41
- package/lib/models/query.js +21 -41
- package/lib/models/session.cjs +33 -65
- package/lib/models/session.js +30 -63
- package/lib/models/user.cjs +29 -51
- package/lib/models/user.js +29 -51
- package/lib/models/utm.cjs +15 -27
- package/lib/models/utm.js +17 -32
- package/lib/models/webchat.cjs +52 -76
- package/lib/models/webchat.js +52 -90
- package/lib/models/whatsapp_widget.cjs +41 -59
- package/lib/models/whatsapp_widget.js +41 -73
- package/lib/vanilla.cjs +4 -7
- package/lib/vanilla.js +2 -1
- package/package.json +2 -10
- package/src/api/index.js +5 -0
- package/src/api/push/identities.js +42 -0
- package/src/core/configuration/push.js +12 -0
- package/src/core/configuration.js +5 -0
- package/src/hellotext.js +15 -1
- package/src/index.bundle.js +0 -1
- package/src/models/business.js +1 -0
- package/src/models/index.js +1 -0
- package/src/models/push.js +397 -0
- package/src/vanilla.js +2 -1
- package/styles/index.css +0 -30
|
@@ -1,8 +1,3 @@
|
|
|
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
1
|
/**
|
|
7
2
|
* @typedef {'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'} Placement
|
|
8
3
|
* @description Valid placements for the WhatsApp widget.
|
|
@@ -11,7 +6,7 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
11
6
|
/**
|
|
12
7
|
* @enum {Placement}
|
|
13
8
|
*/
|
|
14
|
-
|
|
9
|
+
const placements = {
|
|
15
10
|
TOP_LEFT: 'top-left',
|
|
16
11
|
TOP_RIGHT: 'top-right',
|
|
17
12
|
BOTTOM_LEFT: 'bottom-left',
|
|
@@ -34,114 +29,90 @@ var placements = {
|
|
|
34
29
|
* @property {String} body - Prefilled WhatsApp compose text.
|
|
35
30
|
* @property {WhatsAppWidgetAppearance} appearance - Appearance overrides.
|
|
36
31
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
32
|
+
class WhatsApp {
|
|
33
|
+
static _id;
|
|
34
|
+
static _container = 'body';
|
|
35
|
+
static _placement = 'bottom-right';
|
|
36
|
+
static _appearance = {};
|
|
37
|
+
static _number = null;
|
|
38
|
+
static _body = null;
|
|
39
|
+
static set id(value) {
|
|
40
|
+
this._id = value;
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
static get id() {
|
|
43
|
+
return this._id;
|
|
44
|
+
}
|
|
45
|
+
static set container(value) {
|
|
46
|
+
this._container = value;
|
|
47
|
+
}
|
|
48
|
+
static get container() {
|
|
49
|
+
return this._container;
|
|
50
|
+
}
|
|
51
|
+
static set placement(value) {
|
|
52
|
+
if (!Object.values(placements).includes(value)) {
|
|
53
|
+
throw new Error(`Invalid placement value: ${value}`);
|
|
48
54
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
this._placement = value;
|
|
56
|
+
}
|
|
57
|
+
static get placement() {
|
|
58
|
+
return this._placement;
|
|
59
|
+
}
|
|
60
|
+
static get appearance() {
|
|
61
|
+
return this._appearance;
|
|
62
|
+
}
|
|
63
|
+
static set appearance(value) {
|
|
64
|
+
if (!this.isPlainObject(value)) {
|
|
65
|
+
throw new Error('Appearance must be an object');
|
|
56
66
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return this._placement;
|
|
61
|
-
},
|
|
62
|
-
set: function set(value) {
|
|
63
|
-
if (!Object.values(placements).includes(value)) {
|
|
64
|
-
throw new Error("Invalid placement value: ".concat(value));
|
|
67
|
+
Object.entries(value).forEach(([key, nestedValue]) => {
|
|
68
|
+
if (key !== 'launcher') {
|
|
69
|
+
throw new Error(`Invalid appearance property: ${key}`);
|
|
65
70
|
}
|
|
66
|
-
this.
|
|
67
|
-
|
|
68
|
-
}, {
|
|
69
|
-
key: "appearance",
|
|
70
|
-
get: function get() {
|
|
71
|
-
return this._appearance;
|
|
72
|
-
},
|
|
73
|
-
set: function set(value) {
|
|
74
|
-
if (!this.isPlainObject(value)) {
|
|
75
|
-
throw new Error('Appearance must be an object');
|
|
71
|
+
if (!this.isPlainObject(nestedValue)) {
|
|
72
|
+
throw new Error(`Appearance ${key} must be an object`);
|
|
76
73
|
}
|
|
77
|
-
Object.entries(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
Object.entries(nestedValue).forEach(([nestedKey, propertyValue]) => {
|
|
75
|
+
if (nestedKey !== 'iconUrl') {
|
|
76
|
+
throw new Error(`Invalid appearance launcher property: ${nestedKey}`);
|
|
77
|
+
}
|
|
78
|
+
if (propertyValue == null) {
|
|
79
|
+
return;
|
|
81
80
|
}
|
|
82
|
-
if (
|
|
83
|
-
throw new Error(
|
|
81
|
+
if (typeof propertyValue !== 'string') {
|
|
82
|
+
throw new Error(`Invalid appearance ${key}.${nestedKey} value: ${propertyValue}`);
|
|
84
83
|
}
|
|
85
|
-
Object.entries(nestedValue).forEach(_ref2 => {
|
|
86
|
-
var [nestedKey, propertyValue] = _ref2;
|
|
87
|
-
if (nestedKey !== 'iconUrl') {
|
|
88
|
-
throw new Error("Invalid appearance launcher property: ".concat(nestedKey));
|
|
89
|
-
}
|
|
90
|
-
if (propertyValue == null) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (typeof propertyValue !== 'string') {
|
|
94
|
-
throw new Error("Invalid appearance ".concat(key, ".").concat(nestedKey, " value: ").concat(propertyValue));
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
84
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
throw new Error("Invalid number value: ".concat(value));
|
|
108
|
-
}
|
|
109
|
-
this._number = value;
|
|
110
|
-
}
|
|
111
|
-
}, {
|
|
112
|
-
key: "body",
|
|
113
|
-
get: function get() {
|
|
114
|
-
return this._body;
|
|
115
|
-
},
|
|
116
|
-
set: function set(value) {
|
|
117
|
-
if (value != null && typeof value !== 'string') {
|
|
118
|
-
throw new Error("Invalid body value: ".concat(value));
|
|
119
|
-
}
|
|
120
|
-
this._body = value;
|
|
85
|
+
});
|
|
86
|
+
this._appearance = value;
|
|
87
|
+
}
|
|
88
|
+
static get number() {
|
|
89
|
+
return this._number;
|
|
90
|
+
}
|
|
91
|
+
static set number(value) {
|
|
92
|
+
if (value != null && typeof value !== 'string') {
|
|
93
|
+
throw new Error(`Invalid number value: ${value}`);
|
|
121
94
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
return this;
|
|
95
|
+
this._number = value;
|
|
96
|
+
}
|
|
97
|
+
static get body() {
|
|
98
|
+
return this._body;
|
|
99
|
+
}
|
|
100
|
+
static set body(value) {
|
|
101
|
+
if (value != null && typeof value !== 'string') {
|
|
102
|
+
throw new Error(`Invalid body value: ${value}`);
|
|
132
103
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
104
|
+
this._body = value;
|
|
105
|
+
}
|
|
106
|
+
static assign(props) {
|
|
107
|
+
if (props) {
|
|
108
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
109
|
+
this[key] = value;
|
|
110
|
+
});
|
|
137
111
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
WhatsApp._appearance = {};
|
|
145
|
-
WhatsApp._number = null;
|
|
146
|
-
WhatsApp._body = null;
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
static isPlainObject(value) {
|
|
115
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
147
118
|
export { WhatsApp };
|
|
@@ -8,11 +8,7 @@ var _forms = require("./configuration/forms");
|
|
|
8
8
|
var _locale = require("./configuration/locale");
|
|
9
9
|
var _webchat = require("./configuration/webchat");
|
|
10
10
|
var _whatsapp = require("./configuration/whatsapp");
|
|
11
|
-
|
|
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); }
|
|
11
|
+
var _push = require("./configuration/push");
|
|
16
12
|
/**
|
|
17
13
|
* @class Configuration
|
|
18
14
|
* @classdesc
|
|
@@ -22,79 +18,70 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
22
18
|
* @property {Forms} [forms] - form configuration
|
|
23
19
|
* @property {Webchat} [webchat] - webchat configuration
|
|
24
20
|
* @property {WhatsApp} [whatsappWidget] - WhatsApp widget configuration
|
|
21
|
+
* @property {Push} [push] - push subscription configuration
|
|
25
22
|
* @property {Locale} [locale] - locale configuration
|
|
26
23
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
|
|
24
|
+
class Configuration {
|
|
25
|
+
static apiRoot = 'https://api.hellotext.com/v1';
|
|
26
|
+
static actionCableUrl = 'wss://www.hellotext.com/cable';
|
|
27
|
+
static autoGenerateSession = true;
|
|
28
|
+
static session = null;
|
|
29
|
+
static forms = _forms.Forms;
|
|
30
|
+
static webchat = _webchat.Webchat;
|
|
31
|
+
static whatsapp = _whatsapp.WhatsApp;
|
|
32
|
+
static push = _push.Push;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param props
|
|
37
|
+
* @param {Boolean} [props.autoGenerateSession=true] - whether to auto generate session or not
|
|
38
|
+
* @param {String} [props.session] - session id
|
|
39
|
+
* @param {Object} [props.forms] - form configuration
|
|
40
|
+
* @returns {Configuration}
|
|
41
|
+
*/
|
|
42
|
+
static assign(props) {
|
|
43
|
+
if (props) {
|
|
44
|
+
const shouldInferActionCableUrl = Object.prototype.hasOwnProperty.call(props, 'apiRoot') && !Object.prototype.hasOwnProperty.call(props, 'actionCableUrl');
|
|
45
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
46
|
+
if (key === 'forms') {
|
|
47
|
+
this.forms = _forms.Forms.assign(value);
|
|
48
|
+
} else if (key === 'webchat') {
|
|
49
|
+
this.webchat = _webchat.Webchat.assign(value);
|
|
50
|
+
} else if (key === 'whatsappWidget') {
|
|
51
|
+
this.whatsapp = _whatsapp.WhatsApp.assign(value);
|
|
52
|
+
} else if (key === 'push') {
|
|
53
|
+
this.push = _push.Push.assign(value);
|
|
54
|
+
} else {
|
|
55
|
+
this[key] = value;
|
|
58
56
|
}
|
|
57
|
+
});
|
|
58
|
+
if (shouldInferActionCableUrl) {
|
|
59
|
+
this.actionCableUrl = this.actionCableUrlForApiRoot(this.apiRoot);
|
|
59
60
|
}
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
}, {
|
|
63
|
-
key: "locale",
|
|
64
|
-
get: function () {
|
|
65
|
-
return _locale.Locale.toString();
|
|
66
|
-
},
|
|
67
|
-
set: function (locale) {
|
|
68
|
-
_locale.Locale.identifier = locale;
|
|
69
61
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
static set locale(locale) {
|
|
65
|
+
_locale.Locale.identifier = locale;
|
|
66
|
+
}
|
|
67
|
+
static get locale() {
|
|
68
|
+
return _locale.Locale.toString();
|
|
69
|
+
}
|
|
70
|
+
static endpoint(path) {
|
|
71
|
+
return `${this.apiRoot}/${path}`;
|
|
72
|
+
}
|
|
73
|
+
static actionCableUrlForApiRoot(apiRoot) {
|
|
74
|
+
try {
|
|
75
|
+
const url = new URL(apiRoot);
|
|
76
|
+
const protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
77
|
+
url.protocol = protocol;
|
|
78
|
+
url.pathname = '/cable';
|
|
79
|
+
url.search = '';
|
|
80
|
+
url.hash = '';
|
|
81
|
+
return url.toString();
|
|
82
|
+
} catch (_) {
|
|
83
|
+
return this.actionCableUrl;
|
|
89
84
|
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
exports.Configuration = Configuration;
|
|
94
|
-
Configuration.apiRoot = 'https://api.hellotext.com/v1';
|
|
95
|
-
Configuration.actionCableUrl = 'wss://www.hellotext.com/cable';
|
|
96
|
-
Configuration.autoGenerateSession = true;
|
|
97
|
-
Configuration.session = null;
|
|
98
|
-
Configuration.forms = _forms.Forms;
|
|
99
|
-
Configuration.webchat = _webchat.Webchat;
|
|
100
|
-
Configuration.whatsapp = _whatsapp.WhatsApp;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.Configuration = Configuration;
|
|
@@ -1,12 +1,8 @@
|
|
|
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
1
|
import { Forms } from './configuration/forms';
|
|
7
2
|
import { Locale } from './configuration/locale';
|
|
8
3
|
import { Webchat } from './configuration/webchat';
|
|
9
4
|
import { WhatsApp } from './configuration/whatsapp';
|
|
5
|
+
import { Push } from './configuration/push';
|
|
10
6
|
|
|
11
7
|
/**
|
|
12
8
|
* @class Configuration
|
|
@@ -17,80 +13,70 @@ import { WhatsApp } from './configuration/whatsapp';
|
|
|
17
13
|
* @property {Forms} [forms] - form configuration
|
|
18
14
|
* @property {Webchat} [webchat] - webchat configuration
|
|
19
15
|
* @property {WhatsApp} [whatsappWidget] - WhatsApp widget configuration
|
|
16
|
+
* @property {Push} [push] - push subscription configuration
|
|
20
17
|
* @property {Locale} [locale] - locale configuration
|
|
21
18
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
this
|
|
19
|
+
class Configuration {
|
|
20
|
+
static apiRoot = 'https://api.hellotext.com/v1';
|
|
21
|
+
static actionCableUrl = 'wss://www.hellotext.com/cable';
|
|
22
|
+
static autoGenerateSession = true;
|
|
23
|
+
static session = null;
|
|
24
|
+
static forms = Forms;
|
|
25
|
+
static webchat = Webchat;
|
|
26
|
+
static whatsapp = WhatsApp;
|
|
27
|
+
static push = Push;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param props
|
|
32
|
+
* @param {Boolean} [props.autoGenerateSession=true] - whether to auto generate session or not
|
|
33
|
+
* @param {String} [props.session] - session id
|
|
34
|
+
* @param {Object} [props.forms] - form configuration
|
|
35
|
+
* @returns {Configuration}
|
|
36
|
+
*/
|
|
37
|
+
static assign(props) {
|
|
38
|
+
if (props) {
|
|
39
|
+
const shouldInferActionCableUrl = Object.prototype.hasOwnProperty.call(props, 'apiRoot') && !Object.prototype.hasOwnProperty.call(props, 'actionCableUrl');
|
|
40
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
41
|
+
if (key === 'forms') {
|
|
42
|
+
this.forms = Forms.assign(value);
|
|
43
|
+
} else if (key === 'webchat') {
|
|
44
|
+
this.webchat = Webchat.assign(value);
|
|
45
|
+
} else if (key === 'whatsappWidget') {
|
|
46
|
+
this.whatsapp = WhatsApp.assign(value);
|
|
47
|
+
} else if (key === 'push') {
|
|
48
|
+
this.push = Push.assign(value);
|
|
49
|
+
} else {
|
|
50
|
+
this[key] = value;
|
|
54
51
|
}
|
|
52
|
+
});
|
|
53
|
+
if (shouldInferActionCableUrl) {
|
|
54
|
+
this.actionCableUrl = this.actionCableUrlForApiRoot(this.apiRoot);
|
|
55
55
|
}
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
}, {
|
|
59
|
-
key: "locale",
|
|
60
|
-
get: function get() {
|
|
61
|
-
return Locale.toString();
|
|
62
|
-
},
|
|
63
|
-
set: function set(locale) {
|
|
64
|
-
Locale.identifier = locale;
|
|
65
56
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
57
|
+
return this;
|
|
58
|
+
}
|
|
59
|
+
static set locale(locale) {
|
|
60
|
+
Locale.identifier = locale;
|
|
61
|
+
}
|
|
62
|
+
static get locale() {
|
|
63
|
+
return Locale.toString();
|
|
64
|
+
}
|
|
65
|
+
static endpoint(path) {
|
|
66
|
+
return `${this.apiRoot}/${path}`;
|
|
67
|
+
}
|
|
68
|
+
static actionCableUrlForApiRoot(apiRoot) {
|
|
69
|
+
try {
|
|
70
|
+
const url = new URL(apiRoot);
|
|
71
|
+
const protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
72
|
+
url.protocol = protocol;
|
|
73
|
+
url.pathname = '/cable';
|
|
74
|
+
url.search = '';
|
|
75
|
+
url.hash = '';
|
|
76
|
+
return url.toString();
|
|
77
|
+
} catch (_) {
|
|
78
|
+
return this.actionCableUrl;
|
|
85
79
|
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
}();
|
|
89
|
-
Configuration.apiRoot = 'https://api.hellotext.com/v1';
|
|
90
|
-
Configuration.actionCableUrl = 'wss://www.hellotext.com/cable';
|
|
91
|
-
Configuration.autoGenerateSession = true;
|
|
92
|
-
Configuration.session = null;
|
|
93
|
-
Configuration.forms = Forms;
|
|
94
|
-
Configuration.webchat = Webchat;
|
|
95
|
-
Configuration.whatsapp = WhatsApp;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
96
82
|
export { Configuration };
|
package/lib/core/event.cjs
CHANGED
|
@@ -5,67 +5,44 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _errors = require("../errors");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
class Event {
|
|
9
|
+
static events = ['session-set', 'utm-set', 'forms:collected', 'form:completed', 'webchat:mounted', 'webchat:opened', 'webchat:closed', 'webchat:message:sent', 'webchat:message:received', 'cart.added'];
|
|
10
|
+
static valid(name) {
|
|
11
|
+
return Event.exists(name);
|
|
12
|
+
}
|
|
13
|
+
static invalid(name) {
|
|
14
|
+
return !this.valid(name);
|
|
15
|
+
}
|
|
16
|
+
static exists(name) {
|
|
17
|
+
return this.events.find(eventName => eventName === name) !== undefined;
|
|
18
|
+
}
|
|
19
|
+
constructor() {
|
|
16
20
|
this.subscribers = {};
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (Event.invalid(eventName)) {
|
|
22
|
-
throw new _errors.InvalidEvent(eventName);
|
|
23
|
-
}
|
|
24
|
-
this.subscribers = {
|
|
25
|
-
...this.subscribers,
|
|
26
|
-
[eventName]: this.subscribers[eventName] ? [...this.subscribers[eventName], callback] : [callback]
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}, {
|
|
30
|
-
key: "removeSubscriber",
|
|
31
|
-
value: function removeSubscriber(eventName, callback) {
|
|
32
|
-
if (Event.invalid(eventName)) {
|
|
33
|
-
throw new _errors.InvalidEvent(eventName);
|
|
34
|
-
}
|
|
35
|
-
if (this.subscribers[eventName]) {
|
|
36
|
-
this.subscribers[eventName] = this.subscribers[eventName].filter(cb => cb !== callback);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}, {
|
|
40
|
-
key: "dispatch",
|
|
41
|
-
value: function dispatch(eventName, data) {
|
|
42
|
-
var _this$subscribers$eve;
|
|
43
|
-
(_this$subscribers$eve = this.subscribers[eventName]) === null || _this$subscribers$eve === void 0 ? void 0 : _this$subscribers$eve.forEach(subscriber => {
|
|
44
|
-
subscriber(data);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}, {
|
|
48
|
-
key: "listeners",
|
|
49
|
-
get: function () {
|
|
50
|
-
return Object.keys(this.subscribers).length !== 0;
|
|
22
|
+
addSubscriber(eventName, callback) {
|
|
23
|
+
if (Event.invalid(eventName)) {
|
|
24
|
+
throw new _errors.InvalidEvent(eventName);
|
|
51
25
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return !this.valid(name);
|
|
26
|
+
this.subscribers = {
|
|
27
|
+
...this.subscribers,
|
|
28
|
+
[eventName]: this.subscribers[eventName] ? [...this.subscribers[eventName], callback] : [callback]
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
removeSubscriber(eventName, callback) {
|
|
32
|
+
if (Event.invalid(eventName)) {
|
|
33
|
+
throw new _errors.InvalidEvent(eventName);
|
|
61
34
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
value: function exists(name) {
|
|
65
|
-
return this.events.find(eventName => eventName === name) !== undefined;
|
|
35
|
+
if (this.subscribers[eventName]) {
|
|
36
|
+
this.subscribers[eventName] = this.subscribers[eventName].filter(cb => cb !== callback);
|
|
66
37
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
38
|
+
}
|
|
39
|
+
dispatch(eventName, data) {
|
|
40
|
+
this.subscribers[eventName]?.forEach(subscriber => {
|
|
41
|
+
subscriber(data);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
get listeners() {
|
|
45
|
+
return Object.keys(this.subscribers).length !== 0;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.default = Event;
|