@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 webchat.
|
|
@@ -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',
|
|
@@ -27,7 +22,7 @@ var placements = {
|
|
|
27
22
|
* @enum {Strategy}
|
|
28
23
|
*/
|
|
29
24
|
|
|
30
|
-
|
|
25
|
+
const strategies = {
|
|
31
26
|
ABSOLUTE: 'absolute',
|
|
32
27
|
FIXED: 'fixed'
|
|
33
28
|
};
|
|
@@ -39,7 +34,7 @@ var strategies = {
|
|
|
39
34
|
/**
|
|
40
35
|
* @enum {Mode}
|
|
41
36
|
*/
|
|
42
|
-
|
|
37
|
+
const modes = {
|
|
43
38
|
MODAL: 'modal',
|
|
44
39
|
POPOVER: 'popover'
|
|
45
40
|
};
|
|
@@ -79,208 +74,169 @@ var modes = {
|
|
|
79
74
|
* @property {WhatsApp} whatsapp - WhatsApp handoff overrides.
|
|
80
75
|
* @property {Strategy} strategy - the strategy used to position the webchat. Defaults to 'absolute'
|
|
81
76
|
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
|
|
78
|
+
class Webchat {
|
|
79
|
+
static _id;
|
|
80
|
+
static _container = 'body';
|
|
81
|
+
static _placement = 'bottom-right';
|
|
82
|
+
static _style = {};
|
|
83
|
+
static _appearance = {};
|
|
84
|
+
static _whatsapp = {};
|
|
85
|
+
static _mode = modes.POPOVER;
|
|
86
|
+
static _behaviour = null;
|
|
87
|
+
static _hasBehaviourOverride = false;
|
|
88
|
+
static _strategy = null;
|
|
89
|
+
static set container(value) {
|
|
90
|
+
this._container = value;
|
|
85
91
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this._container = value;
|
|
93
|
-
}
|
|
94
|
-
}, {
|
|
95
|
-
key: "placement",
|
|
96
|
-
get: function get() {
|
|
97
|
-
return this._placement;
|
|
98
|
-
},
|
|
99
|
-
set: function set(value) {
|
|
100
|
-
if (!Object.values(placements).includes(value)) {
|
|
101
|
-
throw new Error("Invalid placement value: ".concat(value));
|
|
102
|
-
}
|
|
103
|
-
this._placement = value;
|
|
104
|
-
}
|
|
105
|
-
}, {
|
|
106
|
-
key: "id",
|
|
107
|
-
get: function get() {
|
|
108
|
-
return this._id;
|
|
109
|
-
},
|
|
110
|
-
set: function set(value) {
|
|
111
|
-
this._id = value;
|
|
92
|
+
static get container() {
|
|
93
|
+
return this._container;
|
|
94
|
+
}
|
|
95
|
+
static set placement(value) {
|
|
96
|
+
if (!Object.values(placements).includes(value)) {
|
|
97
|
+
throw new Error(`Invalid placement value: ${value}`);
|
|
112
98
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
99
|
+
this._placement = value;
|
|
100
|
+
}
|
|
101
|
+
static get placement() {
|
|
102
|
+
return this._placement;
|
|
103
|
+
}
|
|
104
|
+
static set id(value) {
|
|
105
|
+
this._id = value;
|
|
106
|
+
}
|
|
107
|
+
static get id() {
|
|
108
|
+
return this._id;
|
|
109
|
+
}
|
|
110
|
+
static get isSet() {
|
|
111
|
+
return !!this._id;
|
|
112
|
+
}
|
|
113
|
+
static get style() {
|
|
114
|
+
return this._style;
|
|
115
|
+
}
|
|
116
|
+
static set style(value) {
|
|
117
|
+
if (typeof value !== 'object') {
|
|
118
|
+
throw new Error('Style must be an object');
|
|
117
119
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
return this._style;
|
|
122
|
-
},
|
|
123
|
-
set: function set(value) {
|
|
124
|
-
if (typeof value !== 'object') {
|
|
125
|
-
throw new Error('Style must be an object');
|
|
120
|
+
Object.entries(value).forEach(([key, value]) => {
|
|
121
|
+
if (!['primaryColor', 'secondaryColor', 'typography'].includes(key)) {
|
|
122
|
+
throw new Error(`Invalid style property: ${key}`);
|
|
126
123
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
if (!['primaryColor', 'secondaryColor', 'typography'].includes(key)) {
|
|
130
|
-
throw new Error("Invalid style property: ".concat(key));
|
|
131
|
-
}
|
|
132
|
-
if (key === 'typography') {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
if (!this.isHexOrRgba(value)) {
|
|
136
|
-
throw new Error("Invalid color value: ".concat(value, " for ").concat(key, ". Colors must be hex or rgb/a."));
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
this._style = value;
|
|
140
|
-
}
|
|
141
|
-
}, {
|
|
142
|
-
key: "appearance",
|
|
143
|
-
get: function get() {
|
|
144
|
-
return this._appearance;
|
|
145
|
-
},
|
|
146
|
-
set: function set(value) {
|
|
147
|
-
if (!this.isPlainObject(value)) {
|
|
148
|
-
throw new Error('Appearance must be an object');
|
|
124
|
+
if (key === 'typography') {
|
|
125
|
+
return;
|
|
149
126
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
if (key === 'launcher' && nestedKey !== 'iconUrl') {
|
|
164
|
-
throw new Error("Invalid appearance launcher property: ".concat(nestedKey));
|
|
165
|
-
}
|
|
166
|
-
if (propertyValue == null) {
|
|
167
|
-
return;
|
|
168
|
-
}
|
|
169
|
-
if (typeof propertyValue !== 'string') {
|
|
170
|
-
throw new Error("Invalid appearance ".concat(key, ".").concat(nestedKey, " value: ").concat(propertyValue));
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
this._appearance = value;
|
|
127
|
+
if (!this.isHexOrRgba(value)) {
|
|
128
|
+
throw new Error(`Invalid color value: ${value} for ${key}. Colors must be hex or rgb/a.`);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
this._style = value;
|
|
132
|
+
}
|
|
133
|
+
static get appearance() {
|
|
134
|
+
return this._appearance;
|
|
135
|
+
}
|
|
136
|
+
static set appearance(value) {
|
|
137
|
+
if (!this.isPlainObject(value)) {
|
|
138
|
+
throw new Error('Appearance must be an object');
|
|
175
139
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (!this.isPlainObject(value)) {
|
|
183
|
-
throw new Error('WhatsApp must be an object');
|
|
140
|
+
Object.entries(value).forEach(([key, nestedValue]) => {
|
|
141
|
+
if (!['header', 'launcher'].includes(key)) {
|
|
142
|
+
throw new Error(`Invalid appearance property: ${key}`);
|
|
143
|
+
}
|
|
144
|
+
if (!this.isPlainObject(nestedValue)) {
|
|
145
|
+
throw new Error(`Appearance ${key} must be an object`);
|
|
184
146
|
}
|
|
185
|
-
Object.entries(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
throw new Error("Invalid WhatsApp property: ".concat(key));
|
|
147
|
+
Object.entries(nestedValue).forEach(([nestedKey, propertyValue]) => {
|
|
148
|
+
if (key === 'header' && nestedKey !== 'name') {
|
|
149
|
+
throw new Error(`Invalid appearance header property: ${nestedKey}`);
|
|
189
150
|
}
|
|
190
|
-
if (
|
|
191
|
-
|
|
151
|
+
if (key === 'launcher' && nestedKey !== 'iconUrl') {
|
|
152
|
+
throw new Error(`Invalid appearance launcher property: ${nestedKey}`);
|
|
192
153
|
}
|
|
193
|
-
if (
|
|
194
|
-
|
|
154
|
+
if (propertyValue == null) {
|
|
155
|
+
return;
|
|
195
156
|
}
|
|
196
|
-
if (
|
|
197
|
-
throw new Error(
|
|
157
|
+
if (typeof propertyValue !== 'string') {
|
|
158
|
+
throw new Error(`Invalid appearance ${key}.${nestedKey} value: ${propertyValue}`);
|
|
198
159
|
}
|
|
199
160
|
});
|
|
200
|
-
|
|
161
|
+
});
|
|
162
|
+
this._appearance = value;
|
|
163
|
+
}
|
|
164
|
+
static get whatsapp() {
|
|
165
|
+
return this._whatsapp;
|
|
166
|
+
}
|
|
167
|
+
static set whatsapp(value) {
|
|
168
|
+
if (!this.isPlainObject(value)) {
|
|
169
|
+
throw new Error('WhatsApp must be an object');
|
|
201
170
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
return this._mode;
|
|
206
|
-
},
|
|
207
|
-
set: function set(value) {
|
|
208
|
-
if (!Object.values(modes).includes(value)) {
|
|
209
|
-
throw new Error("Invalid mode value: ".concat(value));
|
|
171
|
+
Object.entries(value).forEach(([key, nestedValue]) => {
|
|
172
|
+
if (!['number', 'restrictToChannel'].includes(key)) {
|
|
173
|
+
throw new Error(`Invalid WhatsApp property: ${key}`);
|
|
210
174
|
}
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
}, {
|
|
214
|
-
key: "behaviour",
|
|
215
|
-
get: function get() {
|
|
216
|
-
return this._behaviour;
|
|
217
|
-
},
|
|
218
|
-
set: function set(value) {
|
|
219
|
-
if (value == null) {
|
|
220
|
-
this._behaviour = value;
|
|
175
|
+
if (nestedValue == null) {
|
|
221
176
|
return;
|
|
222
177
|
}
|
|
223
|
-
if (typeof
|
|
224
|
-
throw new Error(
|
|
178
|
+
if (key === 'number' && typeof nestedValue !== 'string') {
|
|
179
|
+
throw new Error(`Invalid WhatsApp number value: ${nestedValue}`);
|
|
225
180
|
}
|
|
226
|
-
|
|
181
|
+
if (key === 'restrictToChannel' && typeof nestedValue !== 'boolean') {
|
|
182
|
+
throw new Error(`Invalid WhatsApp restrictToChannel value: ${nestedValue}`);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
this._whatsapp = value;
|
|
186
|
+
}
|
|
187
|
+
static get mode() {
|
|
188
|
+
return this._mode;
|
|
189
|
+
}
|
|
190
|
+
static set mode(value) {
|
|
191
|
+
if (!Object.values(modes).includes(value)) {
|
|
192
|
+
throw new Error(`Invalid mode value: ${value}`);
|
|
227
193
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
194
|
+
this._mode = value;
|
|
195
|
+
}
|
|
196
|
+
static get behaviour() {
|
|
197
|
+
return this._behaviour;
|
|
198
|
+
}
|
|
199
|
+
static set behaviour(value) {
|
|
200
|
+
if (value == null) {
|
|
201
|
+
this._behaviour = value;
|
|
202
|
+
return;
|
|
232
203
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
set: function set(value) {
|
|
236
|
-
this._hasBehaviourOverride = !!value;
|
|
204
|
+
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
205
|
+
throw new Error(`Invalid behaviour value: ${value}`);
|
|
237
206
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
250
|
-
this._strategy = value;
|
|
251
|
-
}
|
|
252
|
-
}, {
|
|
253
|
-
key: "assign",
|
|
254
|
-
value: function assign(props) {
|
|
255
|
-
if (props) {
|
|
256
|
-
Object.entries(props).forEach(_ref5 => {
|
|
257
|
-
var [key, value] = _ref5;
|
|
258
|
-
this[key] = value;
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
return this;
|
|
207
|
+
this._behaviour = value;
|
|
208
|
+
}
|
|
209
|
+
static get hasBehaviourOverride() {
|
|
210
|
+
return this._hasBehaviourOverride;
|
|
211
|
+
}
|
|
212
|
+
static set behaviourOverride(value) {
|
|
213
|
+
this._hasBehaviourOverride = !!value;
|
|
214
|
+
}
|
|
215
|
+
static get strategy() {
|
|
216
|
+
if (this._strategy) {
|
|
217
|
+
return this._strategy;
|
|
262
218
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
219
|
+
return this.container == 'body' ? strategies.FIXED : strategies.ABSOLUTE;
|
|
220
|
+
}
|
|
221
|
+
static set strategy(value) {
|
|
222
|
+
if (value && !Object.values(strategies).includes(value)) {
|
|
223
|
+
throw new Error(`Invalid strategy value: ${value}`);
|
|
267
224
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
225
|
+
this._strategy = value;
|
|
226
|
+
}
|
|
227
|
+
static assign(props) {
|
|
228
|
+
if (props) {
|
|
229
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
230
|
+
this[key] = value;
|
|
231
|
+
});
|
|
272
232
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
Webchat._mode = modes.POPOVER;
|
|
283
|
-
Webchat._behaviour = null;
|
|
284
|
-
Webchat._hasBehaviourOverride = false;
|
|
285
|
-
Webchat._strategy = null;
|
|
233
|
+
return this;
|
|
234
|
+
}
|
|
235
|
+
static isHexOrRgba(value) {
|
|
236
|
+
return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(value) || /^rgba?\(\s*\d{1,3},\s*\d{1,3},\s*\d{1,3},?\s*(0|1|0?\.\d+)?\s*\)$/.test(value);
|
|
237
|
+
}
|
|
238
|
+
static isPlainObject(value) {
|
|
239
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
286
242
|
export { modes, Webchat };
|
|
@@ -4,11 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.WhatsApp = void 0;
|
|
7
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
-
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); } }
|
|
9
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
-
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); }
|
|
12
7
|
/**
|
|
13
8
|
* @typedef {'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'} Placement
|
|
14
9
|
* @description Valid placements for the WhatsApp widget.
|
|
@@ -40,111 +35,90 @@ const placements = {
|
|
|
40
35
|
* @property {String} body - Prefilled WhatsApp compose text.
|
|
41
36
|
* @property {WhatsAppWidgetAppearance} appearance - Appearance overrides.
|
|
42
37
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
38
|
+
class WhatsApp {
|
|
39
|
+
static _id;
|
|
40
|
+
static _container = 'body';
|
|
41
|
+
static _placement = 'bottom-right';
|
|
42
|
+
static _appearance = {};
|
|
43
|
+
static _number = null;
|
|
44
|
+
static _body = null;
|
|
45
|
+
static set id(value) {
|
|
46
|
+
this._id = value;
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
static get id() {
|
|
49
|
+
return this._id;
|
|
50
|
+
}
|
|
51
|
+
static set container(value) {
|
|
52
|
+
this._container = value;
|
|
53
|
+
}
|
|
54
|
+
static get container() {
|
|
55
|
+
return this._container;
|
|
56
|
+
}
|
|
57
|
+
static set placement(value) {
|
|
58
|
+
if (!Object.values(placements).includes(value)) {
|
|
59
|
+
throw new Error(`Invalid placement value: ${value}`);
|
|
54
60
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
this._placement = value;
|
|
62
|
+
}
|
|
63
|
+
static get placement() {
|
|
64
|
+
return this._placement;
|
|
65
|
+
}
|
|
66
|
+
static get appearance() {
|
|
67
|
+
return this._appearance;
|
|
68
|
+
}
|
|
69
|
+
static set appearance(value) {
|
|
70
|
+
if (!this.isPlainObject(value)) {
|
|
71
|
+
throw new Error('Appearance must be an object');
|
|
62
72
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return this._placement;
|
|
67
|
-
},
|
|
68
|
-
set: function (value) {
|
|
69
|
-
if (!Object.values(placements).includes(value)) {
|
|
70
|
-
throw new Error(`Invalid placement value: ${value}`);
|
|
73
|
+
Object.entries(value).forEach(([key, nestedValue]) => {
|
|
74
|
+
if (key !== 'launcher') {
|
|
75
|
+
throw new Error(`Invalid appearance property: ${key}`);
|
|
71
76
|
}
|
|
72
|
-
this.
|
|
73
|
-
|
|
74
|
-
}, {
|
|
75
|
-
key: "appearance",
|
|
76
|
-
get: function () {
|
|
77
|
-
return this._appearance;
|
|
78
|
-
},
|
|
79
|
-
set: function (value) {
|
|
80
|
-
if (!this.isPlainObject(value)) {
|
|
81
|
-
throw new Error('Appearance must be an object');
|
|
77
|
+
if (!this.isPlainObject(nestedValue)) {
|
|
78
|
+
throw new Error(`Appearance ${key} must be an object`);
|
|
82
79
|
}
|
|
83
|
-
Object.entries(
|
|
84
|
-
if (
|
|
85
|
-
throw new Error(`Invalid appearance property: ${
|
|
80
|
+
Object.entries(nestedValue).forEach(([nestedKey, propertyValue]) => {
|
|
81
|
+
if (nestedKey !== 'iconUrl') {
|
|
82
|
+
throw new Error(`Invalid appearance launcher property: ${nestedKey}`);
|
|
83
|
+
}
|
|
84
|
+
if (propertyValue == null) {
|
|
85
|
+
return;
|
|
86
86
|
}
|
|
87
|
-
if (
|
|
88
|
-
throw new Error(`
|
|
87
|
+
if (typeof propertyValue !== 'string') {
|
|
88
|
+
throw new Error(`Invalid appearance ${key}.${nestedKey} value: ${propertyValue}`);
|
|
89
89
|
}
|
|
90
|
-
Object.entries(nestedValue).forEach(([nestedKey, propertyValue]) => {
|
|
91
|
-
if (nestedKey !== 'iconUrl') {
|
|
92
|
-
throw new Error(`Invalid appearance launcher property: ${nestedKey}`);
|
|
93
|
-
}
|
|
94
|
-
if (propertyValue == null) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (typeof propertyValue !== 'string') {
|
|
98
|
-
throw new Error(`Invalid appearance ${key}.${nestedKey} value: ${propertyValue}`);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
90
|
});
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
throw new Error(`Invalid number value: ${value}`);
|
|
112
|
-
}
|
|
113
|
-
this._number = value;
|
|
114
|
-
}
|
|
115
|
-
}, {
|
|
116
|
-
key: "body",
|
|
117
|
-
get: function () {
|
|
118
|
-
return this._body;
|
|
119
|
-
},
|
|
120
|
-
set: function (value) {
|
|
121
|
-
if (value != null && typeof value !== 'string') {
|
|
122
|
-
throw new Error(`Invalid body value: ${value}`);
|
|
123
|
-
}
|
|
124
|
-
this._body = value;
|
|
91
|
+
});
|
|
92
|
+
this._appearance = value;
|
|
93
|
+
}
|
|
94
|
+
static get number() {
|
|
95
|
+
return this._number;
|
|
96
|
+
}
|
|
97
|
+
static set number(value) {
|
|
98
|
+
if (value != null && typeof value !== 'string') {
|
|
99
|
+
throw new Error(`Invalid number value: ${value}`);
|
|
125
100
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
return this;
|
|
101
|
+
this._number = value;
|
|
102
|
+
}
|
|
103
|
+
static get body() {
|
|
104
|
+
return this._body;
|
|
105
|
+
}
|
|
106
|
+
static set body(value) {
|
|
107
|
+
if (value != null && typeof value !== 'string') {
|
|
108
|
+
throw new Error(`Invalid body value: ${value}`);
|
|
135
109
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
110
|
+
this._body = value;
|
|
111
|
+
}
|
|
112
|
+
static assign(props) {
|
|
113
|
+
if (props) {
|
|
114
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
115
|
+
this[key] = value;
|
|
116
|
+
});
|
|
140
117
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
WhatsApp
|
|
148
|
-
WhatsApp._appearance = {};
|
|
149
|
-
WhatsApp._number = null;
|
|
150
|
-
WhatsApp._body = null;
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
static isPlainObject(value) {
|
|
121
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.WhatsApp = WhatsApp;
|