@textback/notification-widget 2.0.3 → 2.0.4-110501

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.
Files changed (126) hide show
  1. package/build/index.js +12 -0
  2. package/{release/builds/textback/notificationwidget/build → build}/sdk.js +2 -2
  3. package/package.json +2 -2
  4. package/src/widget/components/tb-notification-widget/index.js +22 -6
  5. package/src/widget/components/tb-nw-wahunter/index.js +4 -2
  6. package/src/widget/icons/tb-logo-dark-en.svg +17 -0
  7. package/src/widget/icons/tb-logo-dark-ru.svg +17 -0
  8. package/src/widget/icons/tb-logo-dark.svg +16 -0
  9. package/src/widget/icons/tb-logo-light-en.svg +17 -0
  10. package/src/widget/icons/tb-logo-light-ru.svg +17 -0
  11. package/src/widget/icons/tb-logo-white.svg +16 -0
  12. package/src/widget/icons/tb-logo.svg +15 -20
  13. package/release/builds/textback/notificationwidget/.eslintrc.js +0 -291
  14. package/release/builds/textback/notificationwidget/.gitlab-ci.yml +0 -34
  15. package/release/builds/textback/notificationwidget/build/index.js +0 -12
  16. package/release/builds/textback/notificationwidget/package-lock.json +0 -9985
  17. package/release/builds/textback/notificationwidget/package.json +0 -70
  18. package/release/builds/textback/notificationwidget/promote_tag.sh +0 -2
  19. package/release/builds/textback/notificationwidget/readme.md +0 -569
  20. package/release/builds/textback/notificationwidget/server.js +0 -224
  21. package/release/builds/textback/notificationwidget/src/libraries/ai.1.0.11.js +0 -4089
  22. package/release/builds/textback/notificationwidget/src/libraries/localization/getLocale.js +0 -17
  23. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/.tern-port +0 -1
  24. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/cs.js +0 -23
  25. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/en.js +0 -23
  26. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/index.js +0 -9
  27. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/pl.js +0 -23
  28. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/ro.js +0 -23
  29. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/ru.js +0 -22
  30. package/release/builds/textback/notificationwidget/src/libraries/localization/locales/uk.js +0 -23
  31. package/release/builds/textback/notificationwidget/src/libraries/localization/text.js +0 -9
  32. package/release/builds/textback/notificationwidget/src/libraries/t.js +0 -82
  33. package/release/builds/textback/notificationwidget/src/sdk/channels/channel.js +0 -31
  34. package/release/builds/textback/notificationwidget/src/sdk/channels/facebook.js +0 -13
  35. package/release/builds/textback/notificationwidget/src/sdk/channels/factory.js +0 -34
  36. package/release/builds/textback/notificationwidget/src/sdk/channels/skype.js +0 -13
  37. package/release/builds/textback/notificationwidget/src/sdk/channels/telegram.js +0 -18
  38. package/release/builds/textback/notificationwidget/src/sdk/channels/viber.js +0 -13
  39. package/release/builds/textback/notificationwidget/src/sdk/channels/vk-modal/vk-modal.html +0 -17
  40. package/release/builds/textback/notificationwidget/src/sdk/channels/vk-modal/vk-modal.js +0 -25
  41. package/release/builds/textback/notificationwidget/src/sdk/channels/vk-modal/vk-modal.scss +0 -116
  42. package/release/builds/textback/notificationwidget/src/sdk/channels/vk.js +0 -195
  43. package/release/builds/textback/notificationwidget/src/sdk/channels/whatsapp.js +0 -27
  44. package/release/builds/textback/notificationwidget/src/sdk/channels/whatsappb.js +0 -27
  45. package/release/builds/textback/notificationwidget/src/sdk/events/observer.js +0 -46
  46. package/release/builds/textback/notificationwidget/src/sdk/index.js +0 -6
  47. package/release/builds/textback/notificationwidget/src/sdk/sdk.entry.js +0 -1
  48. package/release/builds/textback/notificationwidget/src/sdk/sdk.js +0 -67
  49. package/release/builds/textback/notificationwidget/src/sdk/utils/apiErrorHandler.js +0 -12
  50. package/release/builds/textback/notificationwidget/src/sdk/utils/appInsights.js +0 -88
  51. package/release/builds/textback/notificationwidget/src/sdk/utils/browserInfo.js +0 -9
  52. package/release/builds/textback/notificationwidget/src/sdk/utils/constants.js +0 -18
  53. package/release/builds/textback/notificationwidget/src/sdk/utils/cookies.js +0 -67
  54. package/release/builds/textback/notificationwidget/src/sdk/utils/find.js +0 -8
  55. package/release/builds/textback/notificationwidget/src/sdk/utils/loadConfig.js +0 -21
  56. package/release/builds/textback/notificationwidget/src/sdk/utils/loadDeepLink.js +0 -48
  57. package/release/builds/textback/notificationwidget/src/sdk/utils/loadScript.js +0 -26
  58. package/release/builds/textback/notificationwidget/src/sdk/utils/loadSubscriptions.js +0 -6
  59. package/release/builds/textback/notificationwidget/src/sdk/utils/parseQueryString.js +0 -34
  60. package/release/builds/textback/notificationwidget/src/sdk/utils/windowHelper.js +0 -25
  61. package/release/builds/textback/notificationwidget/src/sdk/widget/widget.js +0 -192
  62. package/release/builds/textback/notificationwidget/src/widget/components/index.js +0 -52
  63. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/facebook.js +0 -55
  64. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/index.js +0 -35
  65. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/styles.scss +0 -657
  66. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/telegram.js +0 -55
  67. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/viber.js +0 -57
  68. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/vk.js +0 -92
  69. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/whatsapp.js +0 -58
  70. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-button/whatsappb.js +0 -58
  71. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-widget/index.js +0 -678
  72. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-widget/normalize.scss +0 -395
  73. package/release/builds/textback/notificationwidget/src/widget/components/tb-notification-widget/styles.scss +0 -543
  74. package/release/builds/textback/notificationwidget/src/widget/components/tb-nw-wahunter/index.js +0 -259
  75. package/release/builds/textback/notificationwidget/src/widget/components/tb-nw-wahunter/styles.scss +0 -471
  76. package/release/builds/textback/notificationwidget/src/widget/config.js +0 -5
  77. package/release/builds/textback/notificationwidget/src/widget/icons/bell-icon.png +0 -0
  78. package/release/builds/textback/notificationwidget/src/widget/icons/broadcast-icon.png +0 -0
  79. package/release/builds/textback/notificationwidget/src/widget/icons/icon_chat_window.svg +0 -1
  80. package/release/builds/textback/notificationwidget/src/widget/icons/icon_close.svg +0 -1
  81. package/release/builds/textback/notificationwidget/src/widget/icons/icon_facebook.svg +0 -7
  82. package/release/builds/textback/notificationwidget/src/widget/icons/icon_facebook_circle.svg +0 -7
  83. package/release/builds/textback/notificationwidget/src/widget/icons/icon_instagram_circle.svg +0 -96
  84. package/release/builds/textback/notificationwidget/src/widget/icons/icon_skype.svg +0 -44
  85. package/release/builds/textback/notificationwidget/src/widget/icons/icon_skype_circle.svg +0 -46
  86. package/release/builds/textback/notificationwidget/src/widget/icons/icon_skype_new.svg +0 -114
  87. package/release/builds/textback/notificationwidget/src/widget/icons/icon_tg.svg +0 -25
  88. package/release/builds/textback/notificationwidget/src/widget/icons/icon_tg_circle.svg +0 -17
  89. package/release/builds/textback/notificationwidget/src/widget/icons/icon_viber.svg +0 -75
  90. package/release/builds/textback/notificationwidget/src/widget/icons/icon_viber_circle.svg +0 -67
  91. package/release/builds/textback/notificationwidget/src/widget/icons/icon_viber_new.svg +0 -102
  92. package/release/builds/textback/notificationwidget/src/widget/icons/icon_vk.svg +0 -14
  93. package/release/builds/textback/notificationwidget/src/widget/icons/icon_vk_circle.svg +0 -16
  94. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsapp.svg +0 -147
  95. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsapp_circle.svg +0 -4
  96. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsapp_hollow.svg +0 -128
  97. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsapp_new.svg +0 -127
  98. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsappb.svg +0 -147
  99. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsappb_circle.svg +0 -4
  100. package/release/builds/textback/notificationwidget/src/widget/icons/icon_whatsappb_new.svg +0 -127
  101. package/release/builds/textback/notificationwidget/src/widget/icons/paper-plane-arrow.svg +0 -3
  102. package/release/builds/textback/notificationwidget/src/widget/icons/paper-plane-icon.png +0 -0
  103. package/release/builds/textback/notificationwidget/src/widget/icons/tb-logo.svg +0 -21
  104. package/release/builds/textback/notificationwidget/src/widget/index.js +0 -29
  105. package/release/builds/textback/notificationwidget/src/widget/locales/cs.js +0 -42
  106. package/release/builds/textback/notificationwidget/src/widget/locales/en.js +0 -42
  107. package/release/builds/textback/notificationwidget/src/widget/locales/index.js +0 -9
  108. package/release/builds/textback/notificationwidget/src/widget/locales/pl.js +0 -42
  109. package/release/builds/textback/notificationwidget/src/widget/locales/ro.js +0 -41
  110. package/release/builds/textback/notificationwidget/src/widget/locales/ru.js +0 -41
  111. package/release/builds/textback/notificationwidget/src/widget/locales/uk.js +0 -41
  112. package/release/builds/textback/notificationwidget/src/widget/utils/cookiesEx.js +0 -41
  113. package/release/builds/textback/notificationwidget/src/widget/utils/getLocale.js +0 -17
  114. package/release/builds/textback/notificationwidget/src/widget/utils/stringifyAttributes.js +0 -19
  115. package/release/builds/textback/notificationwidget/src/widget/utils/text.js +0 -10
  116. package/release/builds/textback/notificationwidget/src/widget/utils/widgetsStorage.js +0 -28
  117. package/release/builds/textback/notificationwidget/src/widget/widget.entry.js +0 -3
  118. package/release/builds/textback/notificationwidget/tests/gf.html +0 -35
  119. package/release/builds/textback/notificationwidget/tests/gf.js +0 -22
  120. package/release/builds/textback/notificationwidget/tests/index.js +0 -62
  121. package/release/builds/textback/notificationwidget/views/examples.ejs +0 -51
  122. package/release/builds/textback/notificationwidget/views/sdk.html +0 -274
  123. package/release/builds/textback/notificationwidget/webpack.common.js +0 -72
  124. package/release/builds/textback/notificationwidget/webpack.dev.js +0 -15
  125. package/release/builds/textback/notificationwidget/webpack.prod.js +0 -10
  126. package/widget.tar.gz +0 -0
@@ -1,195 +0,0 @@
1
- import UUID from 'uuid-js';
2
-
3
- import loadScript from '../utils/loadScript.js';
4
- import apiErrorHandler from '../utils/apiErrorHandler.js';
5
-
6
- import Channel from './channel.js';
7
- import VKModal from './vk-modal/vk-modal.js';
8
- import constants from "../utils/constants";
9
-
10
- const VK_API_VERSION = '5.131';
11
- const LOGIN_TIMEOUT = 4096;
12
-
13
- function loadVkLib(){
14
- return new Promise((resolve, reject) => {
15
- if (window.VK && window.VK.Auth) {
16
- resolve('vk cache');
17
- }
18
- else {
19
- loadScript('//vk.com/js/api/openapi.js')
20
- .then(function () {
21
- resolve('vk load');
22
- }, function (err) {
23
- reject(err);
24
- });
25
- }
26
- });
27
- }
28
-
29
- function initVK(apiId) {
30
- return new Promise((resolve, reject) => {
31
- if (apiId) {
32
- if (!window.VK._apiId) {
33
- window.VK.init({apiId});
34
- }
35
- window.VK.Auth.getLoginStatus(resolve);
36
- } else {
37
- reject('noVKApiId');
38
- }
39
- });
40
- }
41
-
42
- function handleVKLoadingError(error) {
43
- console.error('Failed to load VK openapi.js. VK channel will be unavailable');
44
- return null;
45
- }
46
-
47
- // isVkAppUsed :: Object -> Boolean
48
- const isVkAppUsed = config => {
49
- return config.useVkApp
50
- ? config.useVkApp
51
- : false;
52
- };
53
-
54
- export default class VKChannel extends Channel {
55
- constructor(channelData = {}, deeplink, widget) {
56
- super(channelData, deeplink, widget);
57
-
58
- this.isDoubleCheck = widget.config.isDoubleCheck;
59
- this.vkApiId = this.widget.config.vkApiId;
60
- this.initPromise = null;
61
- this.vkPluginContainerId = null;
62
- this.authorized = false;
63
- this.landingUrl = this.config.additionalProperties ? this.config.additionalProperties.landingUrl : undefined;
64
-
65
- if (this.enabled) {
66
- this.vkPluginContainerId = UUID.create(4).hex;
67
-
68
- if (!this.widget.useVKApi) {
69
- this.initPromise = loadVkLib()
70
- .catch(err => this.__handleVKLoadingError(err));
71
- } else {
72
- this.initPromise = loadVkLib()
73
- .then(() => initVK(this.vkApiId))
74
- .then(() => {
75
- this.authorized = !!(window.VK.Auth.getSession());
76
- })
77
- .catch(err => this.__handleVKLoadingError(err));
78
- }
79
- }
80
- }
81
-
82
- subscribe() {
83
- super.subscribe();
84
- return this.landingUrl ?
85
- window.open(this.landingUrl, '_blank')
86
- :
87
- (isVkAppUsed(this.widget.config)
88
- ? window.open(`https://vk.com/app${this.widget.config.vkApiId}_-${this.config.id}#r=subscribe_${this.deeplink}&accountId=${this.widget.config.accountId}&channelId=${this.channelId}`, 'vk')
89
- : this.subscribeViaPlugin());
90
- }
91
-
92
- subscribeViaApi() {
93
- let promise = null;
94
-
95
- if (!this.authorized) {
96
- promise = this.__login().then( res => this.__allowMessagesFromGroup() );
97
- } else {
98
- promise = this.__allowMessagesFromGroup();
99
- }
100
- return promise;
101
- }
102
-
103
- __allowMessagesFromGroup () {
104
- window.VK.Api.call(
105
- 'messages.allowMessagesFromGroup',
106
- {
107
- group_id: this.id,
108
- v: VK_API_VERSION,
109
- },
110
- res => {
111
- const vkSession = window.VK.Auth.getSession();
112
- const vkUserId = vkSession.mid;
113
-
114
- if (res.response === 1) {
115
- this.__textbackSubscribe(vkUserId);
116
- } else {
117
- console.log('VK res error:', res);
118
- }
119
- }
120
- );
121
- }
122
-
123
-
124
- __login () {
125
- return new Promise(resolve => {
126
- window.VK.Auth.login(res => {
127
- resolve(res);
128
- }, LOGIN_TIMEOUT);
129
- });
130
- }
131
-
132
- __textbackSubscribe (vkUserId, channelWidgetIdx) {
133
- //we shall parse deeplink from server webhook. This method looks like artifact from age without webhhoks.
134
- if(!this.isDoubleCheck) return null;
135
-
136
- return fetch(`${this.widget.initialConfig.apiPath}/endUserNotifications/subscriptions`, {
137
- method: 'POST',
138
- headers: {
139
- 'Content-Type': 'application/json'
140
- },
141
- body: JSON.stringify({
142
- 'accountId': this.widget.config.accountId,
143
- 'insecureContext': this.widget.insecureContext,
144
- 'secureContextToken': this.widget.secureContextToken,
145
- 'address': {
146
- 'channel': 'vk',
147
- 'channelId': this.config.channelId,
148
- 'accountId': this.widget.config.accountId,
149
- 'remoteAddress': vkUserId,
150
- 'chatId': vkUserId
151
- },
152
- deepLinkId: this.deeplink.replace('subscribe_',''),
153
- widgetId: this.widget.id,
154
- 'user': {
155
- 'id': this.widget.widgetUserId
156
- }
157
- })
158
- }).then(apiErrorHandler);
159
- }
160
-
161
- __handleVKLoadingError(err) {
162
- super.reportError('Failed to load VK openapi.js. VK channel will be unavailable.', err);
163
- return null;
164
- }
165
-
166
- subscribeViaPlugin() {
167
- const modal = new VKModal(this.vkPluginContainerId);
168
- this.renderVKSubscriptionButton();
169
-
170
- modal.onClose = () => {
171
- if (this.vkSubscribeHandler) {
172
- window.VK.Observer.unsubscribe('widgets.allowMessagesFromCommunity.allowed', this.vkSubscribeHandler);
173
- this.vkSubscribeHandler = null;
174
- }
175
- };
176
- }
177
-
178
- renderVKSubscriptionButton(height = 30, containerId = this.vkPluginContainerId) {
179
- if (this.vkSubscribeHandler) {
180
- window.VK.Observer.unsubscribe('widgets.allowMessagesFromCommunity.allowed', this.vkSubscribeHandler);
181
- this.vkSubscribeHandler = null;
182
- }
183
-
184
- const options = {
185
- height,
186
- key: this.deeplink
187
- };
188
-
189
- window.VK.Widgets.AllowMessagesFromCommunity(containerId, options, this.id);
190
- if (!this.config.disableAllowMessageEvents) {
191
- this.vkSubscribeHandler = this.__textbackSubscribe.bind(this);
192
- window.VK.Observer.subscribe('widgets.allowMessagesFromCommunity.allowed', this.vkSubscribeHandler);
193
- }
194
- }
195
- }
@@ -1,27 +0,0 @@
1
- import Channel from './channel.js';
2
- import browserInfo from '../utils/browserInfo.js';
3
- import getLocale from '../../libraries/localization/getLocale.js';
4
- import text from '../../libraries/localization/text.js';
5
-
6
- export default class WhatsappChannel extends Channel {
7
- constructor(channelData = {}, deeplink, widget) {
8
- super(channelData, deeplink, widget);
9
-
10
- this.domainPrefix = browserInfo.isMobile() ? 'api' : 'web';
11
-
12
- if(channelData.hasOwnProperty('additionalProperties') && channelData.additionalProperties.hasOwnProperty('customDeeplinkValue')) {
13
- this.customText = channelData.additionalProperties.customDeeplinkValue;
14
- } else {
15
- this.customText = null;
16
- }
17
- }
18
-
19
- subscribe() {
20
- super.subscribe();
21
-
22
- let prefixText = text('whatsapp_prefixtext', getLocale());
23
- let deeplink = this.customText ? this.customText : `${prefixText} ${this.deeplink}`;
24
-
25
- window.open(`https://api.whatsapp.com/send/?phone=+${this.id}&text=${encodeURIComponent(deeplink)}&app_absent=0`, 'whatsapp');
26
- }
27
- }
@@ -1,27 +0,0 @@
1
- import Channel from './channel.js';
2
- import browserInfo from '../utils/browserInfo.js';
3
- import getLocale from '../../libraries/localization/getLocale.js';
4
- import text from '../../libraries/localization/text.js';
5
-
6
- export default class WhatsappbChannel extends Channel {
7
- constructor(channelData = {}, deeplink, widget) {
8
- super(channelData, deeplink, widget);
9
-
10
- this.domainPrefix = browserInfo.isMobile() ? 'api' : 'web';
11
-
12
- if(channelData.hasOwnProperty('additionalProperties') && channelData.additionalProperties.hasOwnProperty('customDeeplinkValue')) {
13
- this.customText = channelData.additionalProperties.customDeeplinkValue;
14
- } else {
15
- this.customText = null;
16
- }
17
- }
18
-
19
- subscribe() {
20
- super.subscribe();
21
-
22
- let prefixText = text('whatsapp_prefixtext', getLocale());
23
- let deeplink = this.customText ? this.customText : `${prefixText} ${this.deeplink}`;
24
-
25
- window.open(`https://api.whatsapp.com/send/?phone=+${this.id}&text=${encodeURIComponent(deeplink)}&app_absent=0`, 'whatsappb');
26
- }
27
- }
@@ -1,46 +0,0 @@
1
- import assign from 'lodash/assign';
2
-
3
- const EVENTS = {
4
- WIDGET_INIT: 'widget.init',
5
- SUBSCRIBE_START: 'subscribe.start',
6
- };
7
-
8
- const _handlers = {};
9
-
10
- window.TextBack = window.TextBack || {};
11
- window.TextBack.Observer = window.TextBack.Observer || {
12
- on(eventName, fn) {
13
- if (!_handlers[eventName]) {
14
- _handlers[eventName] = [ fn ];
15
- } else {
16
- _handlers[eventName].push(fn);
17
- }
18
-
19
- return () => {
20
- const fnIndex = _handlers[eventName].indexOf(fn);
21
- if (fnIndex !== -1) {
22
- _handlers[eventName].splice(fnIndex, 1);
23
- }
24
- };
25
- },
26
-
27
- trigger(eventName, data) {
28
- if (_handlers[eventName]) {
29
- const eventData = assign({}, data, { type: eventName });
30
- setTimeout(() => {
31
- _handlers[eventName].forEach(handler => {
32
- try {
33
- handler(eventData)
34
- } catch (err) {
35
- console.error(`Error occuired while executing event handler on event ${eventName}`, err);
36
- }
37
- });
38
- }, 0);
39
-
40
- }
41
- }
42
- };
43
-
44
- const Observer = window.TextBack.Observer;
45
-
46
- export { Observer, EVENTS };
@@ -1,6 +0,0 @@
1
- import SDK from './sdk.js';
2
-
3
- window.TextBack = window.TextBack || {};
4
- window.TextBack.SDK = window.TextBack.SDK || new SDK();
5
-
6
- export default window.TextBack.SDK;
@@ -1 +0,0 @@
1
- import SDK from './index.js';
@@ -1,67 +0,0 @@
1
- import apiErrorHandler from "./utils/apiErrorHandler";
2
- import 'whatwg-fetch';
3
-
4
- import Widget from './widget/widget.js';
5
- import {EVENTS, Observer} from './events/observer.js';
6
- import {deeplinkUpdater} from './utils/loadDeepLink.js';
7
-
8
- require('es6-promise').polyfill();
9
-
10
- export default class SDK {
11
- constructor() {
12
- this.widgets = {};
13
- this._deeplinkUpdater = deeplinkUpdater;
14
- }
15
-
16
- initWidget(config, preventViewCounting = false) {
17
- if (config && config.widgetId) {
18
- const widget = new Widget(config, this);
19
- this.widgets[config.widgetId] = widget.initialize();
20
- this.widgets[config.widgetId].then(widget => {
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);
27
- }, err => console.error(err));
28
- return this.widgets[config.widgetId];
29
- } else {
30
- throw new Error('Widget id is not defined');
31
- }
32
- }
33
-
34
- countWidgetView(widget) {
35
- return fetch(`${widget.initialConfig.apiPath}/endUserNotifications/subscriptions/notificationWidget/views`, {
36
- method: 'POST',
37
- headers: {
38
- 'Content-Type': 'application/json'
39
- },
40
- body: JSON.stringify({
41
- 'accountId': widget.config.accountId,
42
- 'widgetId': widget.id
43
- })
44
- }).then(apiErrorHandler);
45
- }
46
-
47
- getWidget(widgetId) {
48
- return this.widgets[widgetId] ? this.widgets[widgetId] : null;
49
- }
50
-
51
- on(eventName, fn) {
52
- return Observer.on(eventName, fn);
53
- }
54
-
55
- getDeeplinkUpdater(widgetId) {
56
- let _getWidget = this.widgets[widgetId];
57
-
58
- if (!_getWidget) return null;
59
-
60
- return _getWidget.then(x => {
61
- return this._deeplinkUpdater(
62
- x.initialConfig.apiPath,
63
- x.deeplink.split('_')[1]
64
- );
65
- });
66
- }
67
- }
@@ -1,12 +0,0 @@
1
- export default function apiErrorHandler(res) {
2
- return res.json()
3
- .then(data => {
4
- if (data.$error) {
5
- return Promise.reject(data.$error.msg || data.$error.scn);
6
- }
7
- data.headers = res.headers;
8
-
9
- return data;
10
- })
11
- .catch(() => Promise.reject(`widget error: ${res.status}`));
12
- };
@@ -1,88 +0,0 @@
1
- const appInsights = {
2
- init(aiKey, userId, accountId) {
3
- return new Promise((resolve, reject) => {
4
- window.TextBack = window.TextBack || {};
5
- let context = window.TextBack;
6
- if (aiKey) {
7
- let appInsights = context.appInsights || function (config) {
8
- //basically most below code is got from MS so it's kinda unreadable hmm.. see MS instructions on appinsigths
9
- function r(config) {
10
- t[config] = function () {
11
- let i = arguments;
12
- t.queue.push(function () {
13
- t[config].apply(t, i)
14
- })
15
- }
16
- }
17
-
18
- let t = {
19
- config: config
20
- },
21
- u = document,
22
- e = context,
23
- o = "script",
24
- s = u.createElement(o),
25
- i, f;
26
- for (s.src = config.url || "//az416426.vo.msecnd.net/scripts/a/ai.0.js", u.getElementsByTagName(o)[0].parentNode.appendChild(s), t.cookie = u.cookie, t.queue = [], i = ["Event", "Exception", "Metric", "PageView", "Trace"]; i.length;) r("track" + i.pop());
27
- return r("setAuthenticatedUserContext"), r("clearAuthenticatedUserContext"), config.disableExceptionTracking || (i = "onerror", r("​_" + i), f = e[i], e[i] = function (config, r, u, e, o) {
28
- let s = f && f(config, r, u, e, o);
29
- return s !== !0 && t["_​" + i](config, r, u, e, o), s
30
- }), t
31
- }({
32
- instrumentationKey: aiKey,
33
- // Don't log browser exceptions.
34
- disableExceptionTracking: true,
35
- // Don't log ajax calls.
36
- disableAjaxTracking: true,
37
- //this url will point to the library - use @dev for testing when updating\editing lib - use @latest for production version of lib
38
- //keep in mind that prod widget should always use @latest
39
- url: '//cdn.jsdelivr.net/npm/@textback/notification-widget@latest/src/libraries/ai.1.0.11.js'
40
- // url: '//cdn.jsdelivr.net/npm/@textback/notification-widget@dev/src/libraries/ai.1.0.11.js'
41
- //url: '//localhost:8080/src/libraries/ai.1.0.11.js',
42
- });
43
-
44
-
45
- this.accountId = accountId;
46
- context.appInsights = appInsights;
47
- //ensure appinsights is fully loaded
48
- let timer = setInterval(function () {
49
- if(appInsights._onerror){
50
- clearInterval(timer);
51
- appInsights.setAuthenticatedUserContext(userId);
52
- resolve(true);
53
- }
54
- }, 50);
55
-
56
- }
57
- //no aiKey - no telemetry
58
- else{
59
- resolve(true);
60
- }
61
- });
62
- },
63
- trackEvent(eventName, data) {
64
- let context = window.TextBack;
65
- context.appInsights && context.appInsights.trackEvent(eventName, data);
66
- },
67
- trackButtonClick(widgetId, eventName, channelType) {
68
- let payload = {
69
- channelType,
70
- widgetId,
71
- accountId: this.accountId,
72
- widgetUrl: window.location.href
73
- };
74
- this.trackEvent(eventName, payload);
75
- },
76
- trackWidgetEvent(widgetId, eventName, reason) {
77
- let payload = {
78
- reason,
79
- widgetId,
80
- accountId: this.accountId,
81
- widgetUrl: window.location.href
82
- };
83
- this.trackEvent(eventName, payload);
84
- }
85
- };
86
-
87
- export default appInsights;
88
-
@@ -1,9 +0,0 @@
1
- const isMobile = /Android|webOS|iPhone|iPad|BlackBerry|Windows Phone|Opera Mini|IEMobile|Mobile/i.test(navigator.userAgent);
2
-
3
- const browserInfo = {
4
- isMobile() {
5
- return isMobile;
6
- },
7
- };
8
-
9
- export default browserInfo;
@@ -1,18 +0,0 @@
1
- const COOKIE_NAME_PREFIX = 'tb_notif_widget_';
2
- const constants = {
3
- COOKIE_NAME_PREFIX: COOKIE_NAME_PREFIX,
4
- /**
5
- * 10 years
6
- */
7
- WIDGET_USER_ID_COOKIE_TTL: 315360000,
8
- COOKIE_WIDGET_USER_ID: `${COOKIE_NAME_PREFIX}widgetUserId`,
9
- SECONDS_IN_DAY: 86400,
10
- // make subscription using API call
11
- WIDGET_TYPE_API_CALL : 'apiCall',
12
- // make subscription using native social widget
13
- WIDGET_TYPE_WIDGET : 'widget',
14
- DEFAULT_WIDGET_TYPE : 'widget',
15
- SUBSCRIPTION_WINDOW_PROPS: 'width=600,height=800',
16
- };
17
-
18
- export default constants;
@@ -1,67 +0,0 @@
1
- /**
2
- * Created by martb on 28.06.2017.
3
- * Module for work with cookies
4
- */
5
-
6
- const cookies = {
7
- /**
8
- * возвращает cookie с именем name, если есть, если нет, то null
9
- * @param name {String}
10
- * @returns {String|null}
11
- */
12
- getCookie: function (name) {
13
- let nameEQ = name + "=";
14
- let ca = document.cookie.split(';');
15
- for (let i = 0; i < ca.length; i++) {
16
- let c = ca[i];
17
- while (c.charAt(0) === ' ') c = c.substring(1, c.length);
18
- if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
19
- }
20
- return null;
21
- },
22
-
23
- /**
24
- * устанавливает куку
25
- * @param name - имя куки
26
- * @param value - значение куки
27
- * @param t - время в секундах
28
- */
29
- setCookie: function (name, value, t) {
30
- let expires = "";
31
- if (t) {
32
- let date = new Date();
33
- t *= 1000;
34
- date.setTime(date.getTime() + t);
35
- expires = "; expires=" + date.toUTCString();
36
- }
37
- document.cookie = name + "=" + encodeURIComponent(value) + expires + "; path=/";
38
- },
39
-
40
-
41
- /*
42
- * удаляет куку по имени
43
- * @param name {String}
44
- */
45
- deleteCookie: function (name) {
46
- setCookie(name, "", -1);
47
- },
48
-
49
-
50
- getCookieObject: function () {
51
- const result = {};
52
-
53
- document.cookie
54
- .split(';')
55
- .forEach((cookieItem) => {
56
- const separatorPos = cookieItem.indexOf('=');
57
- const key = cookieItem.slice(0, separatorPos).trim();
58
- const value = cookieItem.slice(separatorPos + 1);
59
-
60
- result[key] = value;
61
- });
62
-
63
- return result;
64
- }
65
- };
66
-
67
- export default cookies;
@@ -1,8 +0,0 @@
1
- export default function find(array, predicate) {
2
- for (let i = 0; i < array.length; i++) {
3
- if (predicate(array[i], i, array)) {
4
- return array[i];
5
- }
6
- }
7
- return undefined;
8
- }
@@ -1,21 +0,0 @@
1
- import apiErrorHandler from './apiErrorHandler.js';
2
-
3
- const cache = {};
4
-
5
-
6
- export default function loadConfig(widgetId, apiPath) {
7
- if (!widgetId) {
8
- return Promise.reject('Widget id required');
9
- }
10
-
11
- if (cache[widgetId]) {
12
- return cache[widgetId];
13
- }
14
-
15
- const loadingPromise = fetch(`${apiPath}/endUserNotifications/widgets/${widgetId}`).then(apiErrorHandler);
16
- loadingPromise.then(() => {
17
- cache[widgetId] = loadingPromise;
18
- });
19
-
20
- return loadingPromise;
21
- };
@@ -1,48 +0,0 @@
1
- 'use strict';
2
-
3
- import apiErrorHandler from './apiErrorHandler.js';
4
-
5
- const cache = {};
6
-
7
- export const deeplinkUpdater = (apiPath, deeplink) => {
8
- let _promises = [];
9
-
10
- return data => {
11
- Promise.all(_promises).then(() => {
12
- let _data = JSON.stringify({
13
- id: deeplink,
14
- insecureContext: { data: data }
15
- });
16
-
17
- let _promise = fetch(
18
- `${apiPath}/endUserNotifications/deepLinks`,
19
- {
20
- method: 'PATCH',
21
- body: _data
22
- }
23
- );
24
-
25
- _promises.push(_promise);
26
-
27
- return _promises;
28
- });
29
- };
30
- };
31
-
32
- export default function loadDeepLink(apiPath, options = {}) {
33
- const body = JSON.stringify(options);
34
-
35
- if (cache[body]) {
36
- return cache[body];
37
- }
38
-
39
- cache[body] = fetch(`${apiPath}/endUserNotifications/deepLinks`, {
40
- method: 'POST',
41
- headers: {
42
- 'Content-Type': 'application/json'
43
- },
44
- body
45
- }).then(apiErrorHandler);
46
-
47
- return cache[body];
48
- };
@@ -1,26 +0,0 @@
1
- const cache = {};
2
-
3
- export default function loadScript(url) {
4
- if (cache[url]){
5
- return cache[url];
6
- }
7
-
8
- cache[url] = new Promise((resolve, reject) => {
9
- let ready = false;
10
- const scriptElement = document.createElement("script");
11
-
12
- scriptElement.type = "text/javascript";
13
- scriptElement.src = url;
14
- scriptElement.async = true;
15
- scriptElement.onload = scriptElement.onreadystatechange = function() {
16
- if (!ready && (!this.readyState || this.readyState == "complete")) {
17
- ready = true;
18
- resolve();
19
- }
20
- };
21
- scriptElement.onerror = scriptElement.onabort = reject;
22
- document.head.appendChild(scriptElement);
23
- });
24
-
25
- return cache[url];
26
- }