@twilio/mcs-client 0.6.0-rc.2 → 0.6.0-rc.5

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/CHANGELOG.md CHANGED
@@ -3,6 +3,34 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.6.0-rc.5](https://github.com/twilio/rtd-sdk-monorepo-js/compare/@twilio/mcs-client@0.6.0-rc.4...@twilio/mcs-client@0.6.0-rc.5) (2022-05-18)
7
+
8
+
9
+ ### Reverts
10
+
11
+ * Revert "chore(release): Publish" ([03b27ca](https://github.com/twilio/rtd-sdk-monorepo-js/commit/03b27ca9830bc6aba2d37febebe6e53f7abddb2d))
12
+
13
+
14
+
15
+ ## [0.6.0-rc.4](https://github.com/twilio/rtd-sdk-monorepo-js/compare/@twilio/mcs-client@0.6.0-rc.3...@twilio/mcs-client@0.6.0-rc.4) (2022-05-04)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * Add cancellable promise export from conversations ([04bd2fc](https://github.com/twilio/rtd-sdk-monorepo-js/commit/04bd2fc10ca1331fbcddf94a186eec351ea922f1))
21
+ * Fix onCancel storing in Cancellable promise ([2dfaccd](https://github.com/twilio/rtd-sdk-monorepo-js/commit/2dfaccd7a984cc3b608bada7cf649473a145fe8b))
22
+ * Fix promise cancelling retrier ([9b30ce2](https://github.com/twilio/rtd-sdk-monorepo-js/commit/9b30ce2750b7447f28e745513f7e1a29e2c48127))
23
+
24
+
25
+
26
+ ## [0.6.0-rc.3](https://github.com/twilio/rtd-sdk-monorepo-js/compare/@twilio/mcs-client@0.6.0-rc.2...@twilio/mcs-client@0.6.0-rc.3) (2022-05-02)
27
+
28
+ **Note:** Version bump only for package @twilio/mcs-client
29
+
30
+
31
+
32
+
33
+
6
34
  ## [0.6.0-rc.2](https://github.com/twilio/rtd-sdk-monorepo-js/compare/@twilio/mcs-client@0.6.0-rc.1...@twilio/mcs-client@0.6.0-rc.2) (2022-05-02)
7
35
 
8
36
 
package/builds/browser.js CHANGED
@@ -28,12 +28,12 @@ var global =
28
28
 
29
29
  Object.defineProperty(exports, '__esModule', { value: true });
30
30
 
31
- require('core-js/modules/es.promise.js');
32
- var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
33
31
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
32
+ require('core-js/modules/es.promise.js');
34
33
  require('core-js/modules/es.array.iterator.js');
35
34
  require('core-js/modules/es.map.js');
36
35
  require('core-js/modules/web.dom-collections.iterator.js');
36
+ var _asyncToGenerator = require('@babel/runtime/helpers/asyncToGenerator');
37
37
  require('core-js/modules/web.dom-collections.for-each.js');
38
38
  var _regeneratorRuntime = require('@babel/runtime/regenerator');
39
39
  require('core-js/modules/es.array.from.js');
@@ -69,11 +69,196 @@ function _interopNamespace(e) {
69
69
  return Object.freeze(n);
70
70
  }
71
71
 
72
- var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
73
72
  var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
73
+ var _asyncToGenerator__default = /*#__PURE__*/_interopDefaultLegacy(_asyncToGenerator);
74
74
  var _regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(_regeneratorRuntime);
75
75
  var log__namespace = /*#__PURE__*/_interopNamespace(log$2);
76
76
 
77
+ var rngBrowser = {exports: {}};
78
+
79
+ // browser this is a little complicated due to unknown quality of Math.random()
80
+ // and inconsistent support for the `crypto` API. We do the best we can via
81
+ // feature-detection
82
+ // getRandomValues needs to be invoked in a context where "this" is a Crypto
83
+ // implementation. Also, find the complete implementation of crypto on IE11.
84
+
85
+ var getRandomValues = typeof crypto != 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto != 'undefined' && typeof window.msCrypto.getRandomValues == 'function' && msCrypto.getRandomValues.bind(msCrypto);
86
+
87
+ if (getRandomValues) {
88
+ // WHATWG crypto RNG - http://wiki.whatwg.org/wiki/Crypto
89
+ var rnds8 = new Uint8Array(16); // eslint-disable-line no-undef
90
+
91
+ rngBrowser.exports = function whatwgRNG() {
92
+ getRandomValues(rnds8);
93
+ return rnds8;
94
+ };
95
+ } else {
96
+ // Math.random()-based (RNG)
97
+ //
98
+ // If all else fails, use Math.random(). It's fast, but is of unspecified
99
+ // quality.
100
+ var rnds = new Array(16);
101
+
102
+ rngBrowser.exports = function mathRNG() {
103
+ for (var i = 0, r; i < 16; i++) {
104
+ if ((i & 0x03) === 0) r = Math.random() * 0x100000000;
105
+ rnds[i] = r >>> ((i & 0x03) << 3) & 0xff;
106
+ }
107
+
108
+ return rnds;
109
+ };
110
+ }
111
+
112
+ /**
113
+ * Convert array of 16 byte values to UUID string format of the form:
114
+ * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
115
+ */
116
+ var byteToHex = [];
117
+
118
+ for (var i = 0; i < 256; ++i) {
119
+ byteToHex[i] = (i + 0x100).toString(16).substr(1);
120
+ }
121
+
122
+ function bytesToUuid$2(buf, offset) {
123
+ var i = offset || 0;
124
+ var bth = byteToHex; // join used to fix memory issue caused by concatenation: https://bugs.chromium.org/p/v8/issues/detail?id=3175#c4
125
+
126
+ return [bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], '-', bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]], bth[buf[i++]]].join('');
127
+ }
128
+
129
+ var bytesToUuid_1 = bytesToUuid$2;
130
+
131
+ var rng$1 = rngBrowser.exports;
132
+ var bytesToUuid$1 = bytesToUuid_1; // **`v1()` - Generate time-based UUID**
133
+ //
134
+ // Inspired by https://github.com/LiosK/UUID.js
135
+ // and http://docs.python.org/library/uuid.html
136
+
137
+ var _nodeId;
138
+
139
+ var _clockseq; // Previous uuid creation time
140
+
141
+
142
+ var _lastMSecs = 0;
143
+ var _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details
144
+
145
+ function v1$1(options, buf, offset) {
146
+ var i = buf && offset || 0;
147
+ var b = buf || [];
148
+ options = options || {};
149
+ var node = options.node || _nodeId;
150
+ var clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not
151
+ // specified. We do this lazily to minimize issues related to insufficient
152
+ // system entropy. See #189
153
+
154
+ if (node == null || clockseq == null) {
155
+ var seedBytes = rng$1();
156
+
157
+ if (node == null) {
158
+ // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1)
159
+ node = _nodeId = [seedBytes[0] | 0x01, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]];
160
+ }
161
+
162
+ if (clockseq == null) {
163
+ // Per 4.2.2, randomize (14 bit) clockseq
164
+ clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff;
165
+ }
166
+ } // UUID timestamps are 100 nano-second units since the Gregorian epoch,
167
+ // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so
168
+ // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs'
169
+ // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00.
170
+
171
+
172
+ var msecs = options.msecs !== undefined ? options.msecs : new Date().getTime(); // Per 4.2.1.2, use count of uuid's generated during the current clock
173
+ // cycle to simulate higher resolution clock
174
+
175
+ var nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs)
176
+
177
+ var dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression
178
+
179
+ if (dt < 0 && options.clockseq === undefined) {
180
+ clockseq = clockseq + 1 & 0x3fff;
181
+ } // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new
182
+ // time interval
183
+
184
+
185
+ if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) {
186
+ nsecs = 0;
187
+ } // Per 4.2.1.2 Throw error if too many uuids are requested
188
+
189
+
190
+ if (nsecs >= 10000) {
191
+ throw new Error('uuid.v1(): Can\'t create more than 10M uuids/sec');
192
+ }
193
+
194
+ _lastMSecs = msecs;
195
+ _lastNSecs = nsecs;
196
+ _clockseq = clockseq; // Per 4.1.4 - Convert from unix epoch to Gregorian epoch
197
+
198
+ msecs += 12219292800000; // `time_low`
199
+
200
+ var tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000;
201
+ b[i++] = tl >>> 24 & 0xff;
202
+ b[i++] = tl >>> 16 & 0xff;
203
+ b[i++] = tl >>> 8 & 0xff;
204
+ b[i++] = tl & 0xff; // `time_mid`
205
+
206
+ var tmh = msecs / 0x100000000 * 10000 & 0xfffffff;
207
+ b[i++] = tmh >>> 8 & 0xff;
208
+ b[i++] = tmh & 0xff; // `time_high_and_version`
209
+
210
+ b[i++] = tmh >>> 24 & 0xf | 0x10; // include version
211
+
212
+ b[i++] = tmh >>> 16 & 0xff; // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant)
213
+
214
+ b[i++] = clockseq >>> 8 | 0x80; // `clock_seq_low`
215
+
216
+ b[i++] = clockseq & 0xff; // `node`
217
+
218
+ for (var n = 0; n < 6; ++n) {
219
+ b[i + n] = node[n];
220
+ }
221
+
222
+ return buf ? buf : bytesToUuid$1(b);
223
+ }
224
+
225
+ var v1_1 = v1$1;
226
+
227
+ var rng = rngBrowser.exports;
228
+ var bytesToUuid = bytesToUuid_1;
229
+
230
+ function v4$1(options, buf, offset) {
231
+ var i = buf && offset || 0;
232
+
233
+ if (typeof options == 'string') {
234
+ buf = options === 'binary' ? new Array(16) : null;
235
+ options = null;
236
+ }
237
+
238
+ options = options || {};
239
+ var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
240
+
241
+ rnds[6] = rnds[6] & 0x0f | 0x40;
242
+ rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
243
+
244
+ if (buf) {
245
+ for (var ii = 0; ii < 16; ++ii) {
246
+ buf[i + ii] = rnds[ii];
247
+ }
248
+ }
249
+
250
+ return buf || bytesToUuid(rnds);
251
+ }
252
+
253
+ var v4_1 = v4$1;
254
+
255
+ var v1 = v1_1;
256
+ var v4 = v4_1;
257
+ var uuid = v4;
258
+ uuid.v1 = v1;
259
+ uuid.v4 = v4;
260
+ var uuid_1 = uuid;
261
+
77
262
  /**
78
263
  * Cancellable promise. Extends the functionality of the native Promise to include the cancel method.
79
264
  *
@@ -97,6 +282,7 @@ var log__namespace = /*#__PURE__*/_interopNamespace(log$2);
97
282
  * cancellableFetchPromise.cancel();
98
283
  * ```
99
284
  */
285
+
100
286
  class CancellablePromise extends Promise {
101
287
  /**
102
288
  * Creates a new CancellablePromise.
@@ -106,15 +292,21 @@ class CancellablePromise extends Promise {
106
292
  * and an onCancel callback used to define behavior of cancellation.
107
293
  */
108
294
  constructor(executor) {
109
- var outerCancellationFunction;
295
+ var outerId = uuid_1.v4();
110
296
  var outerRejectPromise;
111
297
  super((resolve, reject) => {
112
298
  outerRejectPromise = reject;
113
- return executor(resolve, reject, cancellationFunction => {
114
- outerCancellationFunction = cancellationFunction;
299
+ return executor(value => {
300
+ CancellablePromise.cancellationMap.delete(outerId);
301
+ resolve(value);
302
+ }, reason => {
303
+ CancellablePromise.cancellationMap.delete(outerId);
304
+ reject(reason);
305
+ }, cancellationFunction => {
306
+ CancellablePromise.cancellationMap.set(outerId, cancellationFunction);
115
307
  });
116
308
  });
117
- this.cancel = outerCancellationFunction;
309
+ this.id = outerId;
118
310
  this.rejectPromise = outerRejectPromise;
119
311
  }
120
312
  /**
@@ -123,17 +315,21 @@ class CancellablePromise extends Promise {
123
315
 
124
316
 
125
317
  cancel() {
126
- if (this.onCancel) {
127
- this.onCancel();
128
- }
318
+ var onCancel = CancellablePromise.cancellationMap.get(this.id);
319
+ onCancel === null || onCancel === void 0 ? void 0 : onCancel();
129
320
 
130
321
  if (this.rejectPromise) {
322
+ this.catch(() => void 0);
131
323
  this.rejectPromise(new Error("Promise was cancelled"));
132
324
  }
325
+
326
+ return this;
133
327
  }
134
328
 
135
329
  }
136
330
 
331
+ _defineProperty__default["default"](CancellablePromise, "cancellationMap", new Map());
332
+
137
333
  /******************************************************************************
138
334
  Copyright (c) Microsoft Corporation.
139
335
 
@@ -589,35 +785,40 @@ class Network {
589
785
  switch (_context2.prev = _context2.next) {
590
786
  case 0:
591
787
  retrier = new operationRetrier.Retrier(_this.backoffConfig());
592
- onCancel(() => {
593
- request.cancel();
594
- retrier.removeAllListeners();
595
- retrier.cancel();
596
- });
597
788
  codesToRetryOn = [502, 503, 504];
598
789
 
599
790
  if (retryWhenThrottled) {
600
791
  codesToRetryOn.push(429);
601
792
  }
602
793
 
794
+ onCancel(() => {
795
+ retrier.cancel();
796
+ retrier.removeAllListeners();
797
+ });
603
798
  retrier.on("attempt", /*#__PURE__*/_asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
604
- var result;
799
+ var requestPromise, result;
605
800
  return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
606
801
  while (1) {
607
802
  switch (_context.prev = _context.next) {
608
803
  case 0:
609
804
  _context.prev = 0;
610
- _context.next = 3;
611
- return request();
805
+ requestPromise = request();
806
+ onCancel(() => {
807
+ requestPromise.cancel();
808
+ retrier.cancel();
809
+ retrier.removeAllListeners();
810
+ });
811
+ _context.next = 5;
812
+ return requestPromise;
612
813
 
613
- case 3:
814
+ case 5:
614
815
  result = _context.sent;
615
816
  retrier.succeeded(result);
616
- _context.next = 10;
817
+ _context.next = 12;
617
818
  break;
618
819
 
619
- case 7:
620
- _context.prev = 7;
820
+ case 9:
821
+ _context.prev = 9;
621
822
  _context.t0 = _context["catch"](0);
622
823
 
623
824
  if (codesToRetryOn.indexOf(_context.t0.status) > -1) {
@@ -632,12 +833,12 @@ class Network {
632
833
  reject(_context.t0);
633
834
  }
634
835
 
635
- case 10:
836
+ case 12:
636
837
  case "end":
637
838
  return _context.stop();
638
839
  }
639
840
  }
640
- }, _callee, null, [[0, 7]]);
841
+ }, _callee, null, [[0, 9]]);
641
842
  })));
642
843
  retrier.on("succeeded", result => {
643
844
  resolve(result);
@@ -786,7 +987,7 @@ class Network {
786
987
 
787
988
  }
788
989
 
789
- var version = "0.6.0-rc.2";
990
+ var version = "0.6.0-rc.5";
790
991
 
791
992
  var _class;
792
993
  var log = Logger.scope("");