@subiz/widget-v4 4.0.67 → 4.0.70

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/dist/441.js CHANGED
@@ -96,6 +96,9 @@ function escape(html, encode) {
96
96
 
97
97
  const unescapeTest = /&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig;
98
98
 
99
+ /**
100
+ * @param {string} html
101
+ */
99
102
  function unescape(html) {
100
103
  // explicitly match decimal, hex, and named HTML entities
101
104
  return html.replace(unescapeTest, (_, n) => {
@@ -111,8 +114,13 @@ function unescape(html) {
111
114
  }
112
115
 
113
116
  const caret = /(^|[^\[])\^/g;
117
+
118
+ /**
119
+ * @param {string | RegExp} regex
120
+ * @param {string} opt
121
+ */
114
122
  function edit(regex, opt) {
115
- regex = regex.source || regex;
123
+ regex = typeof regex === 'string' ? regex : regex.source;
116
124
  opt = opt || '';
117
125
  const obj = {
118
126
  replace: (name, val) => {
@@ -130,6 +138,12 @@ function edit(regex, opt) {
130
138
 
131
139
  const nonWordAndColonTest = /[^\w:]/g;
132
140
  const originIndependentUrl = /^$|^[a-z][a-z0-9+.-]*:|^[?#]/i;
141
+
142
+ /**
143
+ * @param {boolean} sanitize
144
+ * @param {string} base
145
+ * @param {string} href
146
+ */
133
147
  function cleanUrl(sanitize, base, href) {
134
148
  if (sanitize) {
135
149
  let prot;
@@ -160,6 +174,10 @@ const justDomain = /^[^:]+:\/*[^/]*$/;
160
174
  const protocol = /^([^:]+:)[\s\S]*$/;
161
175
  const domain = /^([^:]+:\/*[^/]*)[\s\S]*$/;
162
176
 
177
+ /**
178
+ * @param {string} base
179
+ * @param {string} href
180
+ */
163
181
  function resolveUrl(base, href) {
164
182
  if (!baseUrls[' ' + base]) {
165
183
  // we can ignore everything in base after the last slash of its path component,
@@ -244,9 +262,14 @@ function splitCells(tableRow, count) {
244
262
  return cells;
245
263
  }
246
264
 
247
- // Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
248
- // /c*$/ is vulnerable to REDOS.
249
- // invert: Remove suffix of non-c chars instead. Default falsey.
265
+ /**
266
+ * Remove trailing 'c's. Equivalent to str.replace(/c*$/, '').
267
+ * /c*$/ is vulnerable to REDOS.
268
+ *
269
+ * @param {string} str
270
+ * @param {string} c
271
+ * @param {boolean} invert Remove suffix of non-c chars instead. Default falsey.
272
+ */
250
273
  function rtrim(str, c, invert) {
251
274
  const l = str.length;
252
275
  if (l === 0) {
@@ -268,7 +291,7 @@ function rtrim(str, c, invert) {
268
291
  }
269
292
  }
270
293
 
271
- return str.substr(0, l - suffLen);
294
+ return str.slice(0, l - suffLen);
272
295
  }
273
296
 
274
297
  function findClosingBracket(str, b) {
@@ -300,6 +323,10 @@ function checkSanitizeDeprecation(opt) {
300
323
  }
301
324
 
302
325
  // copied from https://stackoverflow.com/a/5450113/806777
326
+ /**
327
+ * @param {string} pattern
328
+ * @param {number} count
329
+ */
303
330
  function repeatString(pattern, count) {
304
331
  if (count < 1) {
305
332
  return '';
@@ -460,7 +487,7 @@ class Tokenizer {
460
487
  blockquote(src) {
461
488
  const cap = this.rules.block.blockquote.exec(src);
462
489
  if (cap) {
463
- const text = cap[0].replace(/^ *> ?/gm, '');
490
+ const text = cap[0].replace(/^ *>[ \t]?/gm, '');
464
491
 
465
492
  return {
466
493
  type: 'blockquote',
@@ -496,7 +523,7 @@ class Tokenizer {
496
523
  }
497
524
 
498
525
  // Get next list item
499
- const itemRegex = new RegExp(`^( {0,3}${bull})((?: [^\\n]*)?(?:\\n|$))`);
526
+ const itemRegex = new RegExp(`^( {0,3}${bull})((?:[\t ][^\\n]*)?(?:\\n|$))`);
500
527
 
501
528
  // Check if current bullet point can start a new List Item
502
529
  while (src) {
@@ -1083,10 +1110,10 @@ const block = {
1083
1110
  newline: /^(?: *(?:\n|$))+/,
1084
1111
  code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
1085
1112
  fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
1086
- hr: /^ {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\* *){3,})(?:\n+|$)/,
1113
+ hr: /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,
1087
1114
  heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
1088
1115
  blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
1089
- list: /^( {0,3}bull)( [^\n]+?)?(?:\n|$)/,
1116
+ list: /^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/,
1090
1117
  html: '^ {0,3}(?:' // optional indentation
1091
1118
  + '<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)' // (1)
1092
1119
  + '|comment[^\\n]*(\\n+|$)' // (2)
@@ -1240,9 +1267,9 @@ const inline = {
1240
1267
  emStrong: {
1241
1268
  lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/,
1242
1269
  // (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
1243
- // () Skip orphan delim inside strong (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
1244
- rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
1245
- rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
1270
+ // () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a
1271
+ rDelimAst: /^[^_*]*?\_\_[^_*]*?\*[^_*]*?(?=\_\_)|[^*]+(?=[^*])|[punct_](\*+)(?=[\s]|$)|[^punct*_\s](\*+)(?=[punct_\s]|$)|[punct_\s](\*+)(?=[^punct*_\s])|[\s](\*+)(?=[punct_])|[punct_](\*+)(?=[punct_])|[^punct*_\s](\*+)(?=[^punct*_\s])/,
1272
+ rDelimUnd: /^[^_*]*?\*\*[^_*]*?\_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|[punct*](\_+)(?=[\s]|$)|[^punct*_\s](\_+)(?=[punct*\s]|$)|[punct*\s](\_+)(?=[^punct*_\s])|[\s](\_+)(?=[punct*])|[punct*](\_+)(?=[punct*])/ // ^- Not allowed for _
1246
1273
  },
1247
1274
  code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
1248
1275
  br: /^( {2,}|\\)\n(?!\s*$)/,
@@ -1375,6 +1402,7 @@ inline.breaks = merge({}, inline.gfm, {
1375
1402
 
1376
1403
  /**
1377
1404
  * smartypants text replacement
1405
+ * @param {string} text
1378
1406
  */
1379
1407
  function smartypants(text) {
1380
1408
  return text
@@ -1396,6 +1424,7 @@ function smartypants(text) {
1396
1424
 
1397
1425
  /**
1398
1426
  * mangle email addresses
1427
+ * @param {string} text
1399
1428
  */
1400
1429
  function mangle(text) {
1401
1430
  let out = '',
@@ -1483,8 +1512,7 @@ class Lexer {
1483
1512
  */
1484
1513
  lex(src) {
1485
1514
  src = src
1486
- .replace(/\r\n|\r/g, '\n')
1487
- .replace(/\t/g, ' ');
1515
+ .replace(/\r\n|\r/g, '\n');
1488
1516
 
1489
1517
  this.blockTokens(src, this.tokens);
1490
1518
 
@@ -1501,8 +1529,13 @@ class Lexer {
1501
1529
  */
1502
1530
  blockTokens(src, tokens = []) {
1503
1531
  if (this.options.pedantic) {
1504
- src = src.replace(/^ +$/gm, '');
1532
+ src = src.replace(/\t/g, ' ').replace(/^ +$/gm, '');
1533
+ } else {
1534
+ src = src.replace(/^( *)(\t+)/gm, (_, leading, tabs) => {
1535
+ return leading + ' '.repeat(tabs.length);
1536
+ });
1505
1537
  }
1538
+
1506
1539
  let token, lastToken, cutSrc, lastParagraphClipped;
1507
1540
 
1508
1541
  while (src) {
@@ -1898,29 +1931,31 @@ class Renderer {
1898
1931
  + '</code></pre>\n';
1899
1932
  }
1900
1933
 
1934
+ /**
1935
+ * @param {string} quote
1936
+ */
1901
1937
  blockquote(quote) {
1902
- return '<blockquote>\n' + quote + '</blockquote>\n';
1938
+ return `<blockquote>\n${quote}</blockquote>\n`;
1903
1939
  }
1904
1940
 
1905
1941
  html(html) {
1906
1942
  return html;
1907
1943
  }
1908
1944
 
1945
+ /**
1946
+ * @param {string} text
1947
+ * @param {string} level
1948
+ * @param {string} raw
1949
+ * @param {any} slugger
1950
+ */
1909
1951
  heading(text, level, raw, slugger) {
1910
1952
  if (this.options.headerIds) {
1911
- return '<h'
1912
- + level
1913
- + ' id="'
1914
- + this.options.headerPrefix
1915
- + slugger.slug(raw)
1916
- + '">'
1917
- + text
1918
- + '</h'
1919
- + level
1920
- + '>\n';
1953
+ const id = this.options.headerPrefix + slugger.slug(raw);
1954
+ return `<h${level} id="${id}">${text}</h${level}>\n`;
1921
1955
  }
1956
+
1922
1957
  // ignore IDs
1923
- return '<h' + level + '>' + text + '</h' + level + '>\n';
1958
+ return `<h${level}>${text}</h${level}>\n`;
1924
1959
  }
1925
1960
 
1926
1961
  hr() {
@@ -1933,8 +1968,11 @@ class Renderer {
1933
1968
  return '<' + type + startatt + '>\n' + body + '</' + type + '>\n';
1934
1969
  }
1935
1970
 
1971
+ /**
1972
+ * @param {string} text
1973
+ */
1936
1974
  listitem(text) {
1937
- return '<li>' + text + '</li>\n';
1975
+ return `<li>${text}</li>\n`;
1938
1976
  }
1939
1977
 
1940
1978
  checkbox(checked) {
@@ -1945,12 +1983,19 @@ class Renderer {
1945
1983
  + '> ';
1946
1984
  }
1947
1985
 
1986
+ /**
1987
+ * @param {string} text
1988
+ */
1948
1989
  paragraph(text) {
1949
- return '<p>' + text + '</p>\n';
1990
+ return `<p>${text}</p>\n`;
1950
1991
  }
1951
1992
 
1993
+ /**
1994
+ * @param {string} header
1995
+ * @param {string} body
1996
+ */
1952
1997
  table(header, body) {
1953
- if (body) body = '<tbody>' + body + '</tbody>';
1998
+ if (body) body = `<tbody>${body}</tbody>`;
1954
1999
 
1955
2000
  return '<table>\n'
1956
2001
  + '<thead>\n'
@@ -1960,39 +2005,59 @@ class Renderer {
1960
2005
  + '</table>\n';
1961
2006
  }
1962
2007
 
2008
+ /**
2009
+ * @param {string} content
2010
+ */
1963
2011
  tablerow(content) {
1964
- return '<tr>\n' + content + '</tr>\n';
2012
+ return `<tr>\n${content}</tr>\n`;
1965
2013
  }
1966
2014
 
1967
2015
  tablecell(content, flags) {
1968
2016
  const type = flags.header ? 'th' : 'td';
1969
2017
  const tag = flags.align
1970
- ? '<' + type + ' align="' + flags.align + '">'
1971
- : '<' + type + '>';
1972
- return tag + content + '</' + type + '>\n';
2018
+ ? `<${type} align="${flags.align}">`
2019
+ : `<${type}>`;
2020
+ return tag + content + `</${type}>\n`;
1973
2021
  }
1974
2022
 
1975
- // span level renderer
2023
+ /**
2024
+ * span level renderer
2025
+ * @param {string} text
2026
+ */
1976
2027
  strong(text) {
1977
- return '<strong>' + text + '</strong>';
2028
+ return `<strong>${text}</strong>`;
1978
2029
  }
1979
2030
 
2031
+ /**
2032
+ * @param {string} text
2033
+ */
1980
2034
  em(text) {
1981
- return '<em>' + text + '</em>';
2035
+ return `<em>${text}</em>`;
1982
2036
  }
1983
2037
 
2038
+ /**
2039
+ * @param {string} text
2040
+ */
1984
2041
  codespan(text) {
1985
- return '<code>' + text + '</code>';
2042
+ return `<code>${text}</code>`;
1986
2043
  }
1987
2044
 
1988
2045
  br() {
1989
2046
  return this.options.xhtml ? '<br/>' : '<br>';
1990
2047
  }
1991
2048
 
2049
+ /**
2050
+ * @param {string} text
2051
+ */
1992
2052
  del(text) {
1993
- return '<del>' + text + '</del>';
2053
+ return `<del>${text}</del>`;
1994
2054
  }
1995
2055
 
2056
+ /**
2057
+ * @param {string} href
2058
+ * @param {string} title
2059
+ * @param {string} text
2060
+ */
1996
2061
  link(href, title, text) {
1997
2062
  href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
1998
2063
  if (href === null) {
@@ -2006,15 +2071,20 @@ class Renderer {
2006
2071
  return out;
2007
2072
  }
2008
2073
 
2074
+ /**
2075
+ * @param {string} href
2076
+ * @param {string} title
2077
+ * @param {string} text
2078
+ */
2009
2079
  image(href, title, text) {
2010
2080
  href = cleanUrl(this.options.sanitize, this.options.baseUrl, href);
2011
2081
  if (href === null) {
2012
2082
  return text;
2013
2083
  }
2014
2084
 
2015
- let out = '<img src="' + href + '" alt="' + text + '"';
2085
+ let out = `<img src="${href}" alt="${text}"`;
2016
2086
  if (title) {
2017
- out += ' title="' + title + '"';
2087
+ out += ` title="${title}"`;
2018
2088
  }
2019
2089
  out += this.options.xhtml ? '/>' : '>';
2020
2090
  return out;
@@ -2076,6 +2146,9 @@ class Slugger {
2076
2146
  this.seen = {};
2077
2147
  }
2078
2148
 
2149
+ /**
2150
+ * @param {string} value
2151
+ */
2079
2152
  serialize(value) {
2080
2153
  return value
2081
2154
  .toLowerCase()
@@ -2089,6 +2162,8 @@ class Slugger {
2089
2162
 
2090
2163
  /**
2091
2164
  * Finds the next safe (unique) slug to use
2165
+ * @param {string} originalSlug
2166
+ * @param {boolean} isDryRun
2092
2167
  */
2093
2168
  getNextSafeSlug(originalSlug, isDryRun) {
2094
2169
  let slug = originalSlug;
@@ -2109,8 +2184,9 @@ class Slugger {
2109
2184
 
2110
2185
  /**
2111
2186
  * Convert string to unique id
2112
- * @param {object} options
2113
- * @param {boolean} options.dryrun Generates the next unique slug without updating the internal accumulator.
2187
+ * @param {object} [options]
2188
+ * @param {boolean} [options.dryrun] Generates the next unique slug without
2189
+ * updating the internal accumulator.
2114
2190
  */
2115
2191
  slug(value, options = {}) {
2116
2192
  const slug = this.serialize(value);
@@ -2671,6 +2747,7 @@ marked.walkTokens = function(tokens, callback) {
2671
2747
 
2672
2748
  /**
2673
2749
  * Parse Inline
2750
+ * @param {string} src
2674
2751
  */
2675
2752
  marked.parseInline = function(src, opt) {
2676
2753
  // throw error in case of non string input
package/dist/HASH CHANGED
@@ -1 +1 @@
1
- 17ff367201e
1
+ 180455656b6
@@ -4,4 +4,4 @@
4
4
  }
5
5
  body {
6
6
  background: #ddd;
7
- }</style></head><body><script defer="defer" src="https://vcdn.subiz-cdn.com/widget-v4/public/17ff367201e.screenshoot.js"></script></body></html>
7
+ }</style></head><body><script defer="defer" src="https://vcdn.subiz-cdn.com/widget-v4/public/180455656b6.screenshoot.js"></script></body></html>
@@ -4181,6 +4181,14 @@ cookie.defaults.path = '/';
4181
4181
  cookie.expiresMultiplier = 60 * 60 * 24;
4182
4182
  cookie.defaults.expires = 3650;
4183
4183
  const MAX_CONVO = 20;
4184
+ let ga_client_id = '';
4185
+ setTimeout(() => {
4186
+ if (window.gtag) {
4187
+ window.gtag('get', 'UA-XXXXXXXX-Y', 'client_id', clientid => {
4188
+ ga_client_id = clientid;
4189
+ });
4190
+ }
4191
+ }, 100);
4184
4192
  const page_loaded = util/* default.Date.now */.Z.Date.now();
4185
4193
  class Store {
4186
4194
  constructor(ApiURL, FileURL, RealtimeURL, inmem, fakeapi, agenttoken) {
@@ -4318,7 +4326,9 @@ class Store {
4318
4326
 
4319
4327
  store_defineProperty(this, "seenQueue", []);
4320
4328
 
4321
- store_defineProperty(this, "_typing", util/* default.throttle */.Z.throttle(convoid => this.api.sendTyping(convoid), 3000));
4329
+ store_defineProperty(this, "_typing", util/* default.throttle */.Z.throttle(convoid => this.api.sendTyping(convoid), 3000, {
4330
+ trailing: false
4331
+ }));
4322
4332
 
4323
4333
  store_defineProperty(this, "onConvoEvent", (o, cb) => this.pubsub.on2(o, 'events', cb));
4324
4334
 
@@ -5016,6 +5026,7 @@ class Store {
5016
5026
  }
5017
5027
 
5018
5028
  this.kv.put('last_msg_sent', util/* default.Date.now */.Z.Date.now());
5029
+ return ret;
5019
5030
  }
5020
5031
 
5021
5032
  _setConvo(convo) {
@@ -5265,20 +5276,22 @@ const inmemCookie = {
5265
5276
  };
5266
5277
 
5267
5278
  function getGaClientId() {
5268
- var clientId = '';
5269
- if (!hasGA()) return clientId;
5279
+ if (ga_client_id) return ga_client_id;
5280
+ if (!hasGA()) return ga_client_id;
5281
+ if (!window.ga) return;
5270
5282
  var allTrackers = window.ga.getAll() || [];
5271
5283
  allTrackers.forEach(function (tracker) {
5272
- clientId = tracker.get('clientId');
5284
+ ga_client_id = tracker.get('clientId');
5273
5285
  });
5274
- return clientId;
5286
+ return ga_client_id;
5275
5287
  }
5276
5288
 
5277
- const hasGA = () => !!(window.ga && window.ga.getAll);
5289
+ const hasGA = () => !!(window.ga && window.ga.getAll || window.gtag);
5278
5290
 
5279
5291
  function getGaTrackingIds() {
5280
5292
  var trackingIds = [];
5281
5293
  if (!hasGA()) return trackingIds;
5294
+ if (!window.ga) return [];
5282
5295
  const allTrackers = window.ga.getAll() || [];
5283
5296
  allTrackers.forEach(function (tracker) {
5284
5297
  var trackingId = tracker.get('trackingId');
@@ -5297,11 +5310,18 @@ function sendToFBPixel(category, action, label) {
5297
5310
 
5298
5311
  function sendToGA(category, action, label) {
5299
5312
  if (!hasGA()) return;
5300
- const allTrackers = window.ga.getAll() || [];
5301
- allTrackers.forEach(function (tracker) {
5302
- const name = tracker.get('name');
5303
- window.ga(name + '.send', 'event', category, action, label);
5313
+ if (window.gtag) window.gtag('event', category, {
5314
+ Action: action,
5315
+ Label: label
5304
5316
  });
5317
+
5318
+ if (window.ga) {
5319
+ const allTrackers = window.ga.getAll() || [];
5320
+ allTrackers.forEach(function (tracker) {
5321
+ const name = tracker.get('name');
5322
+ window.ga(name + '.send', 'event', category, action, label);
5323
+ });
5324
+ }
5305
5325
  }
5306
5326
 
5307
5327
  function sendEventToThirdParty(category, action, label) {
@@ -5705,7 +5725,7 @@ util/* default.preloadWebfonts */.Z.preloadWebfonts(['Roboto'], [400, 500]);
5705
5725
 
5706
5726
  class Widget {
5707
5727
  constructor(ApiURL, FileURL, RealtimeURL, inmem, fake, agenttoken) {
5708
- lib_defineProperty(this, "version", () => '4.4');
5728
+ lib_defineProperty(this, "version", () => '4.5');
5709
5729
 
5710
5730
  lib_defineProperty(this, "setSetting", setting => this.store.setSetting({
5711
5731
  account_setting: setting
@@ -5789,7 +5809,21 @@ class Widget {
5789
5809
  }
5790
5810
 
5791
5811
  async sendMessage(convoid, message) {
5792
- this.store.sendConvoEvent(convoid, 'message_sent', {
5812
+ if (!convoid) {
5813
+ const {
5814
+ convo,
5815
+ error
5816
+ } = await this.store.startConvo({
5817
+ message: message.text,
5818
+ initial_by: this.store.matchUser().id
5819
+ });
5820
+ if (error) return {
5821
+ error
5822
+ };
5823
+ convoid = convo.id;
5824
+ }
5825
+
5826
+ return this.store.sendConvoEvent(convoid, 'message_sent', {
5793
5827
  message
5794
5828
  });
5795
5829
  }
@@ -5808,11 +5842,11 @@ class Widget {
5808
5842
  this.pluginMgr.hideCurrentGreeting();
5809
5843
  }
5810
5844
 
5811
- async showWidget(view, convo) {
5845
+ async showWidget(view, cid) {
5812
5846
  await this.domGate.entry();
5813
5847
  this.pluginMgr.showCurrentChatbox({
5814
5848
  view,
5815
- cid: convo
5849
+ cid: cid
5816
5850
  });
5817
5851
  }
5818
5852
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@subiz/widget-v4",
3
- "version": "4.0.67",
3
+ "version": "4.0.70",
4
4
  "main": "./compiled_src/lib.js",
5
5
  "scripts": {
6
6
  "dev": "npx webpack serve --config webpack.dev.js",
@@ -14,16 +14,16 @@
14
14
  "@subiz/storage": "0.0.8",
15
15
  "@subiz/wsclient": "^3.1.7",
16
16
  "cookie_js": "1.4.2",
17
- "core-js": "^3.21.1",
17
+ "core-js": "^3.22.1",
18
18
  "css-loader": "5.2.7",
19
19
  "file-loader": "^6.2.0",
20
20
  "less": "^4.1.2",
21
21
  "less-loader": "^10.2.0",
22
- "marked": "^4.0.12",
23
- "preact": "^10.7.0"
22
+ "marked": "^4.0.14",
23
+ "preact": "^10.7.1"
24
24
  },
25
25
  "devDependencies": {
26
- "@babel/core": "^7.17.8",
26
+ "@babel/core": "^7.17.9",
27
27
  "@babel/plugin-proposal-class-properties": "^7.16.7",
28
28
  "@babel/plugin-transform-react-jsx": "^7.17.3",
29
29
  "@babel/preset-env": "^7.16.11",
@@ -31,10 +31,10 @@
31
31
  "babel-loader": "^8.2.4",
32
32
  "babel-plugin-syntax-jsx": "^6.18.0",
33
33
  "html-webpack-plugin": "^5.5.0",
34
- "puppeteer": "^13.5.2",
35
- "webpack": "^5.70.0",
34
+ "puppeteer": "^13.6.0",
35
+ "webpack": "^5.72.0",
36
36
  "webpack-bundle-analyzer": "^4.5.0",
37
37
  "webpack-cli": "^4.9.2",
38
- "webpack-dev-server": "^4.7.4"
38
+ "webpack-dev-server": "^4.8.1"
39
39
  }
40
40
  }
package/src/lib.js CHANGED
@@ -85,7 +85,15 @@ class Widget {
85
85
  }
86
86
 
87
87
  async sendMessage(convoid, message) {
88
- this.store.sendConvoEvent(convoid, 'message_sent', {message})
88
+ if (!convoid) {
89
+ const {convo, error} = await this.store.startConvo({
90
+ message: message.text,
91
+ initial_by: this.store.matchUser().id,
92
+ })
93
+ if (error) return {error}
94
+ convoid = convo.id
95
+ }
96
+ return this.store.sendConvoEvent(convoid, 'message_sent', {message})
89
97
  }
90
98
 
91
99
  startConvo(req) {
@@ -102,9 +110,10 @@ class Widget {
102
110
  this.pluginMgr.hideCurrentGreeting()
103
111
  }
104
112
 
105
- async showWidget(view, convo) {
113
+ // view could be: chat, list, offline_form
114
+ async showWidget(view, cid) {
106
115
  await this.domGate.entry()
107
- this.pluginMgr.showCurrentChatbox({view, cid: convo})
116
+ this.pluginMgr.showCurrentChatbox({view, cid: cid})
108
117
  }
109
118
 
110
119
  async hideWidget() {
@@ -112,7 +121,7 @@ class Widget {
112
121
  this.pluginMgr.hideCurrentChatbox()
113
122
  }
114
123
 
115
- version = () => '4.4'
124
+ version = () => '4.5'
116
125
 
117
126
  setSetting = (setting) => this.store.setSetting({account_setting: setting})
118
127
  getSetting = (_) => ({account_setting: sb.cloneDeep(this.store.matchAccountSetting())})
@@ -11,6 +11,15 @@ cookie.expiresMultiplier = 60 * 60 * 24 // days
11
11
  cookie.defaults.expires = 3650 // 10 year
12
12
 
13
13
  const MAX_CONVO = 20
14
+ let ga_client_id = ''
15
+
16
+ setTimeout(() => {
17
+ if (window.gtag) {
18
+ window.gtag('get', 'UA-XXXXXXXX-Y', 'client_id', (clientid) => {
19
+ ga_client_id = clientid
20
+ })
21
+ }
22
+ }, 100)
14
23
 
15
24
  const page_loaded = sb.Date.now()
16
25
 
@@ -740,7 +749,7 @@ export default class Store {
740
749
  this._typing(cid)
741
750
  }
742
751
 
743
- _typing = sb.throttle((convoid) => this.api.sendTyping(convoid), 3000)
752
+ _typing = sb.throttle((convoid) => this.api.sendTyping(convoid), 3000, {trailing: false})
744
753
 
745
754
  async startConvo(req) {
746
755
  await this.readyGate.entry()
@@ -824,6 +833,7 @@ export default class Store {
824
833
  }
825
834
 
826
835
  this.kv.put('last_msg_sent', sb.Date.now())
836
+ return ret
827
837
  }
828
838
 
829
839
  onConvoEvent = (o, cb) => this.pubsub.on2(o, 'events', cb)
@@ -1090,19 +1100,20 @@ const inmemCookie = {
1090
1100
  // getGaClientId returns ID of the client in Google Analytics
1091
1101
  // return empty string if GA is not installed
1092
1102
  function getGaClientId() {
1093
- var clientId = ''
1094
- if (!hasGA()) return clientId
1103
+ if (ga_client_id) return ga_client_id
1104
+ if (!hasGA()) return ga_client_id
1095
1105
 
1106
+ if (!window.ga) return
1096
1107
  var allTrackers = window.ga.getAll() || []
1097
1108
  allTrackers.forEach(function (tracker) {
1098
- clientId = tracker.get('clientId')
1109
+ ga_client_id = tracker.get('clientId')
1099
1110
  })
1100
1111
 
1101
- return clientId
1112
+ return ga_client_id
1102
1113
  }
1103
1114
 
1104
1115
  // hasGA tells if the website is using Google Analytics or not
1105
- const hasGA = () => !!(window.ga && window.ga.getAll)
1116
+ const hasGA = () => !!((window.ga && window.ga.getAll) || window.gtag)
1106
1117
 
1107
1118
  // getGaTrackingIds returns all tracking ids in Google Analytics
1108
1119
  // return empty array if GA is not installed
@@ -1110,6 +1121,7 @@ function getGaTrackingIds() {
1110
1121
  var trackingIds = []
1111
1122
  if (!hasGA()) return trackingIds
1112
1123
 
1124
+ if (!window.ga) return []
1113
1125
  const allTrackers = window.ga.getAll() || []
1114
1126
  allTrackers.forEach(function (tracker) {
1115
1127
  var trackingId = tracker.get('trackingId')
@@ -1128,11 +1140,15 @@ function sendToFBPixel(category, action, label) {
1128
1140
  function sendToGA(category, action, label) {
1129
1141
  if (!hasGA()) return
1130
1142
 
1131
- const allTrackers = window.ga.getAll() || []
1132
- allTrackers.forEach(function (tracker) {
1133
- const name = tracker.get('name')
1134
- window.ga(name + '.send', 'event', category, action, label)
1135
- })
1143
+ if (window.gtag) window.gtag('event', category, {Action: action, Label: label})
1144
+
1145
+ if (window.ga) {
1146
+ const allTrackers = window.ga.getAll() || []
1147
+ allTrackers.forEach(function (tracker) {
1148
+ const name = tracker.get('name')
1149
+ window.ga(name + '.send', 'event', category, action, label)
1150
+ })
1151
+ }
1136
1152
  }
1137
1153
 
1138
1154
  function sendEventToThirdParty(category, action, label) {