@textback/notification-widget 2.0.1-103341 → 2.0.1-110209
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/build/index.js +3 -3
- package/build/sdk.js +2 -2
- package/package.json +1 -1
- package/server.js +224 -224
- package/src/sdk/sdk.js +6 -7
- package/src/sdk/widget/widget.js +7 -7
- package/src/widget/components/tb-notification-widget/index.js +2 -3
- package/src/widget/components/tb-nw-wahunter/index.js +5 -45
- package/src/widget/icons/tb-logo.svg +15 -20
- package/views/sdk.html +215 -259
- package/webpack.dev.js +2 -3
package/server.js
CHANGED
@@ -1,224 +1,224 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
const express = require('express');
|
4
|
-
const app = express();
|
5
|
-
const port = process.env.PORT || 3000;
|
6
|
-
|
7
|
-
app.use(express.static('.'));
|
8
|
-
|
9
|
-
app.get('/examples', (req, res) => {
|
10
|
-
const query = Object.assign({
|
11
|
-
//widgetPath: 'https://cdn.jsdelivr.net/npm/@textback/notification-widget/build/index.js',
|
12
|
-
widgetPath: 'http://localhost:8080/build/index.js',
|
13
|
-
apiPath: 'https://tb-apisrv-dev.textback.io/api',
|
14
|
-
widgetId: '7f4e72a9-6f97-b658-9496-016eeb97d0e4',
|
15
|
-
lang: 'ru',
|
16
|
-
data: JSON.stringify({orderId: 'insecureOrderID'})
|
17
|
-
}, req.query);
|
18
|
-
|
19
|
-
let widgetCode = `<script src='${query.widgetPath}'></script>`;
|
20
|
-
|
21
|
-
widgetCode += `\n<tb-notification-widget`;
|
22
|
-
widgetCode += `\n widget-id='${query.widgetId}'`;
|
23
|
-
|
24
|
-
if (query.apiPath) {
|
25
|
-
widgetCode += `\n api-path='${query.apiPath}'`;
|
26
|
-
}
|
27
|
-
|
28
|
-
if (query.lang) {
|
29
|
-
widgetCode += `\n lang='${query.lang}'`;
|
30
|
-
}
|
31
|
-
|
32
|
-
if (query.data) {
|
33
|
-
widgetCode += `\n data='${query.data}'`;
|
34
|
-
}
|
35
|
-
|
36
|
-
widgetCode += `>\n</tb-notification-widget>`;
|
37
|
-
|
38
|
-
res.render('examples.ejs', {
|
39
|
-
query,
|
40
|
-
widgetCode
|
41
|
-
});
|
42
|
-
});
|
43
|
-
|
44
|
-
app.get('/api/endUserNotifications/widgets/error500', (req, res) => {
|
45
|
-
res.sendStatus(500);
|
46
|
-
});
|
47
|
-
|
48
|
-
app.get('/api/endUserNotifications/widgets/error404', (req, res) => {
|
49
|
-
res.sendStatus(404);
|
50
|
-
});
|
51
|
-
|
52
|
-
app.get('/api/endUserNotifications/widgets/a', (req, res) => {
|
53
|
-
res.json({
|
54
|
-
'$error': null,
|
55
|
-
'$items': null,
|
56
|
-
'$value': {
|
57
|
-
'id': 'd43a36de-9659-45b5-9373-aed1a6d58dc5',
|
58
|
-
'vkApiId': null,
|
59
|
-
'accountId': '99bffda5-5bd1-49b1-b4f2-658854797c01',
|
60
|
-
'channels': [{
|
61
|
-
'channel': 'tg',
|
62
|
-
'id': 'rb_dev_3_bot',
|
63
|
-
'slug': '@rb_dev_3_bot',
|
64
|
-
'enabled': true,
|
65
|
-
'channelId': null
|
66
|
-
}, {
|
67
|
-
'channel': 'vk',
|
68
|
-
//'type': 'apiCall',
|
69
|
-
'id': '124981888',
|
70
|
-
'slug': 'tb_test_group',
|
71
|
-
'enabled': true,
|
72
|
-
'channelId': 29
|
73
|
-
}, {
|
74
|
-
'channel': 'facebook',
|
75
|
-
'id': '323049074708312',
|
76
|
-
'slug': 'TA0ETXSdhM8JnvkB1iUM',
|
77
|
-
'enabled': true,
|
78
|
-
'channelId': null
|
79
|
-
}, {'channel': 'viber', 'id': 'dev_', 'slug': '', 'enabled': true, 'channelId': null}],
|
80
|
-
'welcomeMessage': {
|
81
|
-
'text': null,
|
82
|
-
'markup': 'PLAIN',
|
83
|
-
'attachments': null,
|
84
|
-
'buttons': [{
|
85
|
-
'type': 'HyperLinkButton',
|
86
|
-
'text': 'Читать статью',
|
87
|
-
'link': 'https://blog.textback.ru/notifications_in_messengers'
|
88
|
-
}]
|
89
|
-
},
|
90
|
-
'title': {'value': 'test heading'},
|
91
|
-
'description': {'value': 'test desc\r\nline'},
|
92
|
-
'markUp': {
|
93
|
-
'body': {},
|
94
|
-
'icon': {'type': 'preset'},
|
95
|
-
'header': {'value': 'привет это тестовый заголовок чтобы понять какое нормальное число знак'},
|
96
|
-
'description': {'value': 'это тестовый заголовок чтобы понять какое нормальное число знаков может быть в описании чтобы было читабельно и красиво и вообще нормально. это очень длинное название, прямо очень длинное очень приоче'},
|
97
|
-
'title': {'value': 'asdadad'}
|
98
|
-
},
|
99
|
-
'displayOptions': {},
|
100
|
-
//'displayMode': 'popup'
|
101
|
-
},
|
102
|
-
'$count': 1
|
103
|
-
});
|
104
|
-
});
|
105
|
-
|
106
|
-
app.get('/api/endUserNotifications/widgets/b', (req, res) => {
|
107
|
-
res.json({
|
108
|
-
'$error': null,
|
109
|
-
'$items': null,
|
110
|
-
'$value': {
|
111
|
-
'id': 'd43a36de-9659-45b5-9373-aed1a6d58dc5',
|
112
|
-
'vkApiId': 5930339,
|
113
|
-
'accountId': '99bffda5-5bd1-49b1-b4f2-658854797c01',
|
114
|
-
'channels': [{
|
115
|
-
'channel': 'tg',
|
116
|
-
'id': 'rb_dev_3_bot',
|
117
|
-
'slug': '@rb_dev_3_bot',
|
118
|
-
'enabled': true,
|
119
|
-
'channelId': null
|
120
|
-
}, {
|
121
|
-
'channel': 'vk',
|
122
|
-
'type': 'apiCall',
|
123
|
-
'id': '124981888',
|
124
|
-
'slug': 'tb_test_group',
|
125
|
-
'enabled': true,
|
126
|
-
'channelId': 29
|
127
|
-
}, {
|
128
|
-
'channel': 'facebook',
|
129
|
-
'id': '323049074708312',
|
130
|
-
'slug': 'TA0ETXSdhM8JnvkB1iUM',
|
131
|
-
'enabled': true,
|
132
|
-
'channelId': null
|
133
|
-
}, {'channel': 'viber', 'id': 'dev_', 'slug': '', 'enabled': true, 'channelId': null}],
|
134
|
-
'welcomeMessage': {
|
135
|
-
'text': null,
|
136
|
-
'markup': 'PLAIN',
|
137
|
-
'attachments': null,
|
138
|
-
'buttons': [{
|
139
|
-
'type': 'HyperLinkButton',
|
140
|
-
'text': 'Читать статью',
|
141
|
-
'link': 'https://blog.textback.ru/notifications_in_messengers'
|
142
|
-
}]
|
143
|
-
},
|
144
|
-
'title': {'value': 'test heading'},
|
145
|
-
'description': {'value': 'test desc\r\nline'},
|
146
|
-
'markUp': {
|
147
|
-
'body': {},
|
148
|
-
'icon': {'type': 'preset'},
|
149
|
-
'header': {'value': 'привет это тестовый заголовок чтобы понять какое нормальное число знак'},
|
150
|
-
'description': {'value': 'это тестовый заголовок чтобы понять какое нормальное число знаков может быть в описании чтобы было читабельно и красиво и вообще нормально. это очень длинное название, прямо очень длинное очень приоче'},
|
151
|
-
'title': {'value': 'asdadad'}
|
152
|
-
},
|
153
|
-
'displayOptions': {},
|
154
|
-
//'displayMode': 'popup'
|
155
|
-
},
|
156
|
-
'$count': 1
|
157
|
-
});
|
158
|
-
});
|
159
|
-
|
160
|
-
app.get('/api/endUserNotifications/widgets/c', (req, res) => {
|
161
|
-
res.json({
|
162
|
-
'$error': null,
|
163
|
-
'$items': null,
|
164
|
-
'$value': {
|
165
|
-
'id': 'd43a36de-9659-45b5-9373-aed1a6d58dc5',
|
166
|
-
'vkApiId': 5930339,
|
167
|
-
'accountId': '99bffda5-5bd1-49b1-b4f2-658854797c01',
|
168
|
-
'channels': [{
|
169
|
-
'channel': 'tg',
|
170
|
-
'id': 'rb_dev_3_bot',
|
171
|
-
'slug': '@rb_dev_3_bot',
|
172
|
-
'enabled': true,
|
173
|
-
'channelId': null
|
174
|
-
}, {
|
175
|
-
'channel': 'vk',
|
176
|
-
'id': '124981888',
|
177
|
-
'slug': 'tb_test_group',
|
178
|
-
'enabled': true,
|
179
|
-
'channelId': 29
|
180
|
-
}, {
|
181
|
-
'channel': 'facebook',
|
182
|
-
'id': '323049074708312',
|
183
|
-
'slug': 'TA0ETXSdhM8JnvkB1iUM',
|
184
|
-
'enabled': true,
|
185
|
-
'channelId': null
|
186
|
-
}, {'channel': 'viber', 'id': 'dev_', 'slug': '', 'enabled': true, 'channelId': null}],
|
187
|
-
'welcomeMessage': {
|
188
|
-
'text': null,
|
189
|
-
'markup': 'PLAIN',
|
190
|
-
'attachments': null,
|
191
|
-
'buttons': [{
|
192
|
-
'type': 'HyperLinkButton',
|
193
|
-
'text': 'Читать статью',
|
194
|
-
'link': 'https://blog.textback.ru/notifications_in_messengers'
|
195
|
-
}]
|
196
|
-
},
|
197
|
-
'title': {'value': 'test heading'},
|
198
|
-
'description': {'value': 'test desc\r\nline'},
|
199
|
-
'markUp': {
|
200
|
-
'body': {},
|
201
|
-
'icon': {'type': 'preset'},
|
202
|
-
'header': {'value': 'привет это тестовый заголовок чтобы понять какое нормальное число знак'},
|
203
|
-
'description': {'value': 'это тестовый заголовок чтобы понять какое нормальное число знаков может быть в описании чтобы было читабельно и красиво и вообще нормально. это очень длинное название, прямо очень длинное очень приоче'},
|
204
|
-
'title': {'value': 'asdadad'}
|
205
|
-
},
|
206
|
-
'displayOptions': {},
|
207
|
-
'displayMode': 'popup'
|
208
|
-
},
|
209
|
-
'$count': 1
|
210
|
-
});
|
211
|
-
});
|
212
|
-
|
213
|
-
app.post('/api/endUserNotifications/deepLinks', (req, res) => {
|
214
|
-
res.json({
|
215
|
-
'$error': null,
|
216
|
-
'$items': null,
|
217
|
-
'$value': 'subscribe_XXX',
|
218
|
-
'$count': 1
|
219
|
-
});
|
220
|
-
});
|
221
|
-
|
222
|
-
app.listen(port, () => {
|
223
|
-
console.log(`Application started on http://localhost:${port}`)
|
224
|
-
});
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const express = require('express');
|
4
|
+
const app = express();
|
5
|
+
const port = process.env.PORT || 3000;
|
6
|
+
|
7
|
+
app.use(express.static('.'));
|
8
|
+
|
9
|
+
app.get('/examples', (req, res) => {
|
10
|
+
const query = Object.assign({
|
11
|
+
//widgetPath: 'https://cdn.jsdelivr.net/npm/@textback/notification-widget/build/index.js',
|
12
|
+
widgetPath: 'http://localhost:8080/build/index.js',
|
13
|
+
apiPath: 'https://tb-apisrv-dev.textback.io/api',
|
14
|
+
widgetId: '7f4e72a9-6f97-b658-9496-016eeb97d0e4',
|
15
|
+
lang: 'ru',
|
16
|
+
data: JSON.stringify({orderId: 'insecureOrderID'})
|
17
|
+
}, req.query);
|
18
|
+
|
19
|
+
let widgetCode = `<script src='${query.widgetPath}'></script>`;
|
20
|
+
|
21
|
+
widgetCode += `\n<tb-notification-widget`;
|
22
|
+
widgetCode += `\n widget-id='${query.widgetId}'`;
|
23
|
+
|
24
|
+
if (query.apiPath) {
|
25
|
+
widgetCode += `\n api-path='${query.apiPath}'`;
|
26
|
+
}
|
27
|
+
|
28
|
+
if (query.lang) {
|
29
|
+
widgetCode += `\n lang='${query.lang}'`;
|
30
|
+
}
|
31
|
+
|
32
|
+
if (query.data) {
|
33
|
+
widgetCode += `\n data='${query.data}'`;
|
34
|
+
}
|
35
|
+
|
36
|
+
widgetCode += `>\n</tb-notification-widget>`;
|
37
|
+
|
38
|
+
res.render('examples.ejs', {
|
39
|
+
query,
|
40
|
+
widgetCode
|
41
|
+
});
|
42
|
+
});
|
43
|
+
|
44
|
+
app.get('/api/endUserNotifications/widgets/error500', (req, res) => {
|
45
|
+
res.sendStatus(500);
|
46
|
+
});
|
47
|
+
|
48
|
+
app.get('/api/endUserNotifications/widgets/error404', (req, res) => {
|
49
|
+
res.sendStatus(404);
|
50
|
+
});
|
51
|
+
|
52
|
+
app.get('/api/endUserNotifications/widgets/a', (req, res) => {
|
53
|
+
res.json({
|
54
|
+
'$error': null,
|
55
|
+
'$items': null,
|
56
|
+
'$value': {
|
57
|
+
'id': 'd43a36de-9659-45b5-9373-aed1a6d58dc5',
|
58
|
+
'vkApiId': null,
|
59
|
+
'accountId': '99bffda5-5bd1-49b1-b4f2-658854797c01',
|
60
|
+
'channels': [{
|
61
|
+
'channel': 'tg',
|
62
|
+
'id': 'rb_dev_3_bot',
|
63
|
+
'slug': '@rb_dev_3_bot',
|
64
|
+
'enabled': true,
|
65
|
+
'channelId': null
|
66
|
+
}, {
|
67
|
+
'channel': 'vk',
|
68
|
+
//'type': 'apiCall',
|
69
|
+
'id': '124981888',
|
70
|
+
'slug': 'tb_test_group',
|
71
|
+
'enabled': true,
|
72
|
+
'channelId': 29
|
73
|
+
}, {
|
74
|
+
'channel': 'facebook',
|
75
|
+
'id': '323049074708312',
|
76
|
+
'slug': 'TA0ETXSdhM8JnvkB1iUM',
|
77
|
+
'enabled': true,
|
78
|
+
'channelId': null
|
79
|
+
}, {'channel': 'viber', 'id': 'dev_', 'slug': '', 'enabled': true, 'channelId': null}],
|
80
|
+
'welcomeMessage': {
|
81
|
+
'text': null,
|
82
|
+
'markup': 'PLAIN',
|
83
|
+
'attachments': null,
|
84
|
+
'buttons': [{
|
85
|
+
'type': 'HyperLinkButton',
|
86
|
+
'text': 'Читать статью',
|
87
|
+
'link': 'https://blog.textback.ru/notifications_in_messengers'
|
88
|
+
}]
|
89
|
+
},
|
90
|
+
'title': {'value': 'test heading'},
|
91
|
+
'description': {'value': 'test desc\r\nline'},
|
92
|
+
'markUp': {
|
93
|
+
'body': {},
|
94
|
+
'icon': {'type': 'preset'},
|
95
|
+
'header': {'value': 'привет это тестовый заголовок чтобы понять какое нормальное число знак'},
|
96
|
+
'description': {'value': 'это тестовый заголовок чтобы понять какое нормальное число знаков может быть в описании чтобы было читабельно и красиво и вообще нормально. это очень длинное название, прямо очень длинное очень приоче'},
|
97
|
+
'title': {'value': 'asdadad'}
|
98
|
+
},
|
99
|
+
'displayOptions': {},
|
100
|
+
//'displayMode': 'popup'
|
101
|
+
},
|
102
|
+
'$count': 1
|
103
|
+
});
|
104
|
+
});
|
105
|
+
|
106
|
+
app.get('/api/endUserNotifications/widgets/b', (req, res) => {
|
107
|
+
res.json({
|
108
|
+
'$error': null,
|
109
|
+
'$items': null,
|
110
|
+
'$value': {
|
111
|
+
'id': 'd43a36de-9659-45b5-9373-aed1a6d58dc5',
|
112
|
+
'vkApiId': 5930339,
|
113
|
+
'accountId': '99bffda5-5bd1-49b1-b4f2-658854797c01',
|
114
|
+
'channels': [{
|
115
|
+
'channel': 'tg',
|
116
|
+
'id': 'rb_dev_3_bot',
|
117
|
+
'slug': '@rb_dev_3_bot',
|
118
|
+
'enabled': true,
|
119
|
+
'channelId': null
|
120
|
+
}, {
|
121
|
+
'channel': 'vk',
|
122
|
+
'type': 'apiCall',
|
123
|
+
'id': '124981888',
|
124
|
+
'slug': 'tb_test_group',
|
125
|
+
'enabled': true,
|
126
|
+
'channelId': 29
|
127
|
+
}, {
|
128
|
+
'channel': 'facebook',
|
129
|
+
'id': '323049074708312',
|
130
|
+
'slug': 'TA0ETXSdhM8JnvkB1iUM',
|
131
|
+
'enabled': true,
|
132
|
+
'channelId': null
|
133
|
+
}, {'channel': 'viber', 'id': 'dev_', 'slug': '', 'enabled': true, 'channelId': null}],
|
134
|
+
'welcomeMessage': {
|
135
|
+
'text': null,
|
136
|
+
'markup': 'PLAIN',
|
137
|
+
'attachments': null,
|
138
|
+
'buttons': [{
|
139
|
+
'type': 'HyperLinkButton',
|
140
|
+
'text': 'Читать статью',
|
141
|
+
'link': 'https://blog.textback.ru/notifications_in_messengers'
|
142
|
+
}]
|
143
|
+
},
|
144
|
+
'title': {'value': 'test heading'},
|
145
|
+
'description': {'value': 'test desc\r\nline'},
|
146
|
+
'markUp': {
|
147
|
+
'body': {},
|
148
|
+
'icon': {'type': 'preset'},
|
149
|
+
'header': {'value': 'привет это тестовый заголовок чтобы понять какое нормальное число знак'},
|
150
|
+
'description': {'value': 'это тестовый заголовок чтобы понять какое нормальное число знаков может быть в описании чтобы было читабельно и красиво и вообще нормально. это очень длинное название, прямо очень длинное очень приоче'},
|
151
|
+
'title': {'value': 'asdadad'}
|
152
|
+
},
|
153
|
+
'displayOptions': {},
|
154
|
+
//'displayMode': 'popup'
|
155
|
+
},
|
156
|
+
'$count': 1
|
157
|
+
});
|
158
|
+
});
|
159
|
+
|
160
|
+
app.get('/api/endUserNotifications/widgets/c', (req, res) => {
|
161
|
+
res.json({
|
162
|
+
'$error': null,
|
163
|
+
'$items': null,
|
164
|
+
'$value': {
|
165
|
+
'id': 'd43a36de-9659-45b5-9373-aed1a6d58dc5',
|
166
|
+
'vkApiId': 5930339,
|
167
|
+
'accountId': '99bffda5-5bd1-49b1-b4f2-658854797c01',
|
168
|
+
'channels': [{
|
169
|
+
'channel': 'tg',
|
170
|
+
'id': 'rb_dev_3_bot',
|
171
|
+
'slug': '@rb_dev_3_bot',
|
172
|
+
'enabled': true,
|
173
|
+
'channelId': null
|
174
|
+
}, {
|
175
|
+
'channel': 'vk',
|
176
|
+
'id': '124981888',
|
177
|
+
'slug': 'tb_test_group',
|
178
|
+
'enabled': true,
|
179
|
+
'channelId': 29
|
180
|
+
}, {
|
181
|
+
'channel': 'facebook',
|
182
|
+
'id': '323049074708312',
|
183
|
+
'slug': 'TA0ETXSdhM8JnvkB1iUM',
|
184
|
+
'enabled': true,
|
185
|
+
'channelId': null
|
186
|
+
}, {'channel': 'viber', 'id': 'dev_', 'slug': '', 'enabled': true, 'channelId': null}],
|
187
|
+
'welcomeMessage': {
|
188
|
+
'text': null,
|
189
|
+
'markup': 'PLAIN',
|
190
|
+
'attachments': null,
|
191
|
+
'buttons': [{
|
192
|
+
'type': 'HyperLinkButton',
|
193
|
+
'text': 'Читать статью',
|
194
|
+
'link': 'https://blog.textback.ru/notifications_in_messengers'
|
195
|
+
}]
|
196
|
+
},
|
197
|
+
'title': {'value': 'test heading'},
|
198
|
+
'description': {'value': 'test desc\r\nline'},
|
199
|
+
'markUp': {
|
200
|
+
'body': {},
|
201
|
+
'icon': {'type': 'preset'},
|
202
|
+
'header': {'value': 'привет это тестовый заголовок чтобы понять какое нормальное число знак'},
|
203
|
+
'description': {'value': 'это тестовый заголовок чтобы понять какое нормальное число знаков может быть в описании чтобы было читабельно и красиво и вообще нормально. это очень длинное название, прямо очень длинное очень приоче'},
|
204
|
+
'title': {'value': 'asdadad'}
|
205
|
+
},
|
206
|
+
'displayOptions': {},
|
207
|
+
'displayMode': 'popup'
|
208
|
+
},
|
209
|
+
'$count': 1
|
210
|
+
});
|
211
|
+
});
|
212
|
+
|
213
|
+
app.post('/api/endUserNotifications/deepLinks', (req, res) => {
|
214
|
+
res.json({
|
215
|
+
'$error': null,
|
216
|
+
'$items': null,
|
217
|
+
'$value': 'subscribe_XXX',
|
218
|
+
'$count': 1
|
219
|
+
});
|
220
|
+
});
|
221
|
+
|
222
|
+
app.listen(port, () => {
|
223
|
+
console.log(`Application started on http://localhost:${port}`)
|
224
|
+
});
|
package/src/sdk/sdk.js
CHANGED
@@ -16,15 +16,14 @@ export default class SDK {
|
|
16
16
|
initWidget(config, preventViewCounting = false) {
|
17
17
|
if (config && config.widgetId) {
|
18
18
|
const widget = new Widget(config, this);
|
19
|
-
|
20
19
|
this.widgets[config.widgetId] = widget.initialize();
|
21
20
|
this.widgets[config.widgetId].then(widget => {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
Observer.trigger(EVENTS.WIDGET_INIT, {widgetId: config.widgetId});
|
22
|
+
|
23
|
+
// First of all, this is a restriction on the count of views for textback settings page ( = for widget preview)
|
24
|
+
if (preventViewCounting) return;
|
25
|
+
|
26
|
+
this.countWidgetView(widget);
|
28
27
|
}, err => console.error(err));
|
29
28
|
return this.widgets[config.widgetId];
|
30
29
|
} else {
|
package/src/sdk/widget/widget.js
CHANGED
@@ -1,14 +1,15 @@
|
|
1
|
-
import assign from 'lodash/assign';
|
2
1
|
import UUID from 'uuid-js';
|
2
|
+
import assign from 'lodash/assign';
|
3
3
|
|
4
|
-
import
|
5
|
-
import constants from '../utils/constants.js';
|
6
|
-
import cookies from '../utils/cookies.js';
|
7
|
-
import find from '../utils/find.js';
|
4
|
+
import apiErrorHandler from '../utils/apiErrorHandler.js';
|
8
5
|
import loadConfig from '../utils/loadConfig.js';
|
9
6
|
import loadDeepLink from '../utils/loadDeepLink.js';
|
10
7
|
import loadSubscriptions from '../utils/loadSubscriptions.js';
|
8
|
+
import cookies from '../utils/cookies.js';
|
9
|
+
import constants from '../utils/constants.js';
|
11
10
|
import parseQueryString from '../utils/parseQueryString.js';
|
11
|
+
import find from '../utils/find.js';
|
12
|
+
import appInsights from '../utils/appInsights.js';
|
12
13
|
|
13
14
|
import channelsFactory from '../channels/factory.js';
|
14
15
|
|
@@ -132,7 +133,7 @@ export default class Widget {
|
|
132
133
|
return this.channels.filter(channel => channel.enabled && !channel.hasError);
|
133
134
|
}
|
134
135
|
|
135
|
-
runWahunter(phoneNumber
|
136
|
+
runWahunter(phoneNumber) {
|
136
137
|
return fetch(`${this.initialConfig.apiPath}/wahunter`, {
|
137
138
|
method: 'POST',
|
138
139
|
headers: {
|
@@ -143,7 +144,6 @@ export default class Widget {
|
|
143
144
|
phone: phoneNumber,
|
144
145
|
insecureContext: this.insecureContext,
|
145
146
|
deeplinkId: this.deeplink,
|
146
|
-
captchaToken
|
147
147
|
}),
|
148
148
|
}).then((resp) => {
|
149
149
|
if (resp.ok) {
|
@@ -81,7 +81,6 @@ export default class Widget extends Component {
|
|
81
81
|
insecureContext: this.data,
|
82
82
|
secureContextToken: this.secureContextToken,
|
83
83
|
overrideConfig: predefinedConfig,
|
84
|
-
captchaTest: this.captchaTest
|
85
84
|
}, this.previewMode);
|
86
85
|
}
|
87
86
|
|
@@ -120,6 +119,7 @@ export default class Widget extends Component {
|
|
120
119
|
this.set({ error: err });
|
121
120
|
return this;
|
122
121
|
});
|
122
|
+
|
123
123
|
widgetsStorage.setWidget(this.widgetId, widgetInitPromise);
|
124
124
|
}
|
125
125
|
|
@@ -127,8 +127,7 @@ export default class Widget extends Component {
|
|
127
127
|
return {
|
128
128
|
widgetId: this.element.getAttribute('widget-id'),
|
129
129
|
secureContextToken: this.element.getAttribute('secure-context-token'),
|
130
|
-
apiPath: this.element.getAttribute('api-path') || config.apiPath
|
131
|
-
captchaTest: !!this.element.getAttribute('captcha-test')
|
130
|
+
apiPath: this.element.getAttribute('api-path') || config.apiPath
|
132
131
|
};
|
133
132
|
}
|
134
133
|
|
@@ -3,60 +3,24 @@ import arrowIcon from '../../icons/paper-plane-arrow.svg';
|
|
3
3
|
import waIcon from '../../icons/icon_whatsapp_new.svg';
|
4
4
|
import iconTbLogo from '../../icons/tb-logo.svg';
|
5
5
|
|
6
|
-
import
|
7
|
-
import loadScript from "../../../sdk/utils/loadScript.js";
|
6
|
+
import './styles.scss';
|
8
7
|
|
9
8
|
const parsePhoneNumber = (phoneString) => phoneString.replace(/[^\d]/g, '');
|
10
9
|
|
11
10
|
export default class Wahunter extends Component {
|
12
11
|
constructor() {
|
13
12
|
super(...arguments);
|
14
|
-
this.captcha = {};
|
15
13
|
}
|
16
14
|
|
15
|
+
|
17
16
|
render() {
|
18
17
|
this.lang = this.widgetAPI.config.lang || this.parentElement.getAttribute('lang');
|
19
18
|
|
20
19
|
super.render();
|
21
|
-
this.renderCaptcha();
|
22
20
|
this.submitFormElem = this.element.querySelector(`.${Wahunter.tagName}__submit-form`);
|
23
21
|
this.addListeners();
|
24
22
|
}
|
25
23
|
|
26
|
-
renderCaptcha() {
|
27
|
-
const {
|
28
|
-
widgetAPI: {
|
29
|
-
config: { captcha },
|
30
|
-
},
|
31
|
-
} = this;
|
32
|
-
if (!captcha || !captcha.enabled || !captcha.siteKey) return;
|
33
|
-
const render = () => {
|
34
|
-
this.captcha.widgetId = window.smartCaptcha.render(
|
35
|
-
this.element.querySelector(`.smart-captcha`),
|
36
|
-
{
|
37
|
-
sitekey: captcha.siteKey,
|
38
|
-
invisible: true,
|
39
|
-
callback: (token) => {
|
40
|
-
this.captcha.token = token;
|
41
|
-
this.submit();
|
42
|
-
},
|
43
|
-
test: this.widgetAPI.initialConfig.captchaTest,
|
44
|
-
}
|
45
|
-
);
|
46
|
-
this.captcha.rendered = true;
|
47
|
-
};
|
48
|
-
if (!window.tbCaptchaLoadingCallbacks) {
|
49
|
-
window.tbCaptchaLoadingCallbacks = [];
|
50
|
-
window.onTbCaptchaLoad = () => {
|
51
|
-
window.tbCaptchaLoadingCallbacks.forEach((cb) => cb());
|
52
|
-
};
|
53
|
-
loadScript(
|
54
|
-
`https://smartcaptcha.yandexcloud.net/captcha.js?render=onload&onload=onTbCaptchaLoad`
|
55
|
-
);
|
56
|
-
}
|
57
|
-
window.tbCaptchaLoadingCallbacks.push(render);
|
58
|
-
}
|
59
|
-
|
60
24
|
addListeners() {
|
61
25
|
this.submitFormElem.addEventListener('submit', (e) => {
|
62
26
|
e.preventDefault();
|
@@ -115,12 +79,8 @@ export default class Wahunter extends Component {
|
|
115
79
|
`;
|
116
80
|
}
|
117
81
|
|
82
|
+
|
118
83
|
submit() {
|
119
|
-
let { token: captchaToken } = this.captcha;
|
120
|
-
if (this.captcha.rendered && !captchaToken) {
|
121
|
-
window.smartCaptcha.execute(this.captcha.widgetId);
|
122
|
-
return;
|
123
|
-
}
|
124
84
|
const phoneNumber = +parsePhoneNumber(this.submitFormElem.phoneNumber.value);
|
125
85
|
|
126
86
|
if (this.widgetAPI.config.displayMode !== 'inline') {
|
@@ -130,7 +90,7 @@ export default class Wahunter extends Component {
|
|
130
90
|
this.changeSubmitFormState('pending');
|
131
91
|
|
132
92
|
setTimeout(() => {
|
133
|
-
this.widgetAPI.runWahunter(phoneNumber
|
93
|
+
this.widgetAPI.runWahunter(phoneNumber)
|
134
94
|
.then(() => this.changeSubmitFormState('success'))
|
135
95
|
.catch((error) => {
|
136
96
|
if (error.status === 400) return this.changeSubmitFormState('notFound');
|
@@ -269,7 +229,7 @@ export default class Wahunter extends Component {
|
|
269
229
|
</div>
|
270
230
|
</button>
|
271
231
|
</div>
|
272
|
-
|
232
|
+
|
273
233
|
<div class="${Wahunter.tagName}__submit-form-footer" style="${showWahunterAgreement ? '' : 'display:none'}">
|
274
234
|
<label class="${Wahunter.tagName}__agreement">
|
275
235
|
<input type="checkbox" required checked>
|