@aws-amplify/core 4.7.6 → 4.7.7-ds-allow-applicable-data.6

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 (38) hide show
  1. package/dist/aws-amplify-core.js +718 -64
  2. package/dist/aws-amplify-core.js.map +1 -1
  3. package/dist/aws-amplify-core.min.js +4 -4
  4. package/dist/aws-amplify-core.min.js.map +1 -1
  5. package/lib/Credentials.d.ts +1 -1
  6. package/lib/Credentials.js +1 -1
  7. package/lib/Credentials.js.map +1 -1
  8. package/lib/Platform/version.d.ts +1 -1
  9. package/lib/Platform/version.js +1 -1
  10. package/lib/Util/BackgroundProcessManager.d.ts +178 -0
  11. package/lib/Util/BackgroundProcessManager.js +385 -0
  12. package/lib/Util/BackgroundProcessManager.js.map +1 -0
  13. package/lib/Util/Retry.d.ts +2 -2
  14. package/lib/Util/Retry.js +76 -34
  15. package/lib/Util/Retry.js.map +1 -1
  16. package/lib/Util/index.d.ts +1 -0
  17. package/lib/Util/index.js +1 -0
  18. package/lib/Util/index.js.map +1 -1
  19. package/lib-esm/Credentials.d.ts +1 -1
  20. package/lib-esm/Credentials.js +1 -1
  21. package/lib-esm/Credentials.js.map +1 -1
  22. package/lib-esm/Platform/version.d.ts +1 -1
  23. package/lib-esm/Platform/version.js +1 -1
  24. package/lib-esm/Util/BackgroundProcessManager.d.ts +178 -0
  25. package/lib-esm/Util/BackgroundProcessManager.js +383 -0
  26. package/lib-esm/Util/BackgroundProcessManager.js.map +1 -0
  27. package/lib-esm/Util/Retry.d.ts +2 -2
  28. package/lib-esm/Util/Retry.js +76 -34
  29. package/lib-esm/Util/Retry.js.map +1 -1
  30. package/lib-esm/Util/index.d.ts +1 -0
  31. package/lib-esm/Util/index.js +1 -0
  32. package/lib-esm/Util/index.js.map +1 -1
  33. package/package.json +2 -2
  34. package/src/Credentials.ts +13 -14
  35. package/src/Platform/version.ts +1 -1
  36. package/src/Util/BackgroundProcessManager.ts +415 -0
  37. package/src/Util/Retry.ts +66 -31
  38. package/src/Util/index.ts +1 -0
@@ -32990,7 +32990,7 @@ var getAmplifyUserAgent = function getAmplifyUserAgent(content) {
32990
32990
  __webpack_require__.r(__webpack_exports__);
32991
32991
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "version", function() { return version; });
32992
32992
  // generated by genversion
32993
- var version = '4.7.5';
32993
+ var version = '4.7.6';
32994
32994
 
32995
32995
  /***/ }),
32996
32996
 
@@ -35014,6 +35014,578 @@ function () {
35014
35014
 
35015
35015
 
35016
35016
 
35017
+ /***/ }),
35018
+
35019
+ /***/ "./lib-esm/Util/BackgroundProcessManager.js":
35020
+ /*!**************************************************!*\
35021
+ !*** ./lib-esm/Util/BackgroundProcessManager.js ***!
35022
+ \**************************************************/
35023
+ /*! exports provided: BackgroundProcessManager, BackgroundProcessManagerState */
35024
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
35025
+
35026
+ "use strict";
35027
+ __webpack_require__.r(__webpack_exports__);
35028
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "BackgroundProcessManager", function() { return BackgroundProcessManager; });
35029
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "BackgroundProcessManagerState", function() { return BackgroundProcessManagerState; });
35030
+ var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
35031
+ function adopt(value) {
35032
+ return value instanceof P ? value : new P(function (resolve) {
35033
+ resolve(value);
35034
+ });
35035
+ }
35036
+
35037
+ return new (P || (P = Promise))(function (resolve, reject) {
35038
+ function fulfilled(value) {
35039
+ try {
35040
+ step(generator.next(value));
35041
+ } catch (e) {
35042
+ reject(e);
35043
+ }
35044
+ }
35045
+
35046
+ function rejected(value) {
35047
+ try {
35048
+ step(generator["throw"](value));
35049
+ } catch (e) {
35050
+ reject(e);
35051
+ }
35052
+ }
35053
+
35054
+ function step(result) {
35055
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
35056
+ }
35057
+
35058
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35059
+ });
35060
+ };
35061
+
35062
+ var __generator = undefined && undefined.__generator || function (thisArg, body) {
35063
+ var _ = {
35064
+ label: 0,
35065
+ sent: function sent() {
35066
+ if (t[0] & 1) throw t[1];
35067
+ return t[1];
35068
+ },
35069
+ trys: [],
35070
+ ops: []
35071
+ },
35072
+ f,
35073
+ y,
35074
+ t,
35075
+ g;
35076
+ return g = {
35077
+ next: verb(0),
35078
+ "throw": verb(1),
35079
+ "return": verb(2)
35080
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
35081
+ return this;
35082
+ }), g;
35083
+
35084
+ function verb(n) {
35085
+ return function (v) {
35086
+ return step([n, v]);
35087
+ };
35088
+ }
35089
+
35090
+ function step(op) {
35091
+ if (f) throw new TypeError("Generator is already executing.");
35092
+
35093
+ while (_) {
35094
+ try {
35095
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
35096
+ if (y = 0, t) op = [op[0] & 2, t.value];
35097
+
35098
+ switch (op[0]) {
35099
+ case 0:
35100
+ case 1:
35101
+ t = op;
35102
+ break;
35103
+
35104
+ case 4:
35105
+ _.label++;
35106
+ return {
35107
+ value: op[1],
35108
+ done: false
35109
+ };
35110
+
35111
+ case 5:
35112
+ _.label++;
35113
+ y = op[1];
35114
+ op = [0];
35115
+ continue;
35116
+
35117
+ case 7:
35118
+ op = _.ops.pop();
35119
+
35120
+ _.trys.pop();
35121
+
35122
+ continue;
35123
+
35124
+ default:
35125
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
35126
+ _ = 0;
35127
+ continue;
35128
+ }
35129
+
35130
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
35131
+ _.label = op[1];
35132
+ break;
35133
+ }
35134
+
35135
+ if (op[0] === 6 && _.label < t[1]) {
35136
+ _.label = t[1];
35137
+ t = op;
35138
+ break;
35139
+ }
35140
+
35141
+ if (t && _.label < t[2]) {
35142
+ _.label = t[2];
35143
+
35144
+ _.ops.push(op);
35145
+
35146
+ break;
35147
+ }
35148
+
35149
+ if (t[2]) _.ops.pop();
35150
+
35151
+ _.trys.pop();
35152
+
35153
+ continue;
35154
+ }
35155
+
35156
+ op = body.call(thisArg, _);
35157
+ } catch (e) {
35158
+ op = [6, e];
35159
+ y = 0;
35160
+ } finally {
35161
+ f = t = 0;
35162
+ }
35163
+ }
35164
+
35165
+ if (op[0] & 5) throw op[1];
35166
+ return {
35167
+ value: op[0] ? op[1] : void 0,
35168
+ done: true
35169
+ };
35170
+ }
35171
+ };
35172
+
35173
+ var __values = undefined && undefined.__values || function (o) {
35174
+ var s = typeof Symbol === "function" && Symbol.iterator,
35175
+ m = s && o[s],
35176
+ i = 0;
35177
+ if (m) return m.call(o);
35178
+ if (o && typeof o.length === "number") return {
35179
+ next: function next() {
35180
+ if (o && i >= o.length) o = void 0;
35181
+ return {
35182
+ value: o && o[i++],
35183
+ done: !o
35184
+ };
35185
+ }
35186
+ };
35187
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
35188
+ };
35189
+ /**
35190
+ * @private For internal Amplify use.
35191
+ *
35192
+ * Creates a new scope for promises, observables, and other types of work or
35193
+ * processes that may be running in the background. This manager provides
35194
+ * an singular entrypoint to request termination and await completion.
35195
+ *
35196
+ * As work completes on its own prior to close, the manager removes them
35197
+ * from the registry to avoid holding references to completed jobs.
35198
+ */
35199
+
35200
+
35201
+ var BackgroundProcessManager =
35202
+ /** @class */
35203
+ function () {
35204
+ /**
35205
+ * Creates a new manager for promises, observables, and other types
35206
+ * of work that may be running in the background. This manager provides
35207
+ * a centralized mechanism to request termination and await completion.
35208
+ */
35209
+ function BackgroundProcessManager() {
35210
+ /**
35211
+ * A string indicating whether the manager is accepting new work ("Open"),
35212
+ * waiting for work to complete ("Closing"), or fully done with all
35213
+ * submitted work and *not* accepting new jobs ("Closed").
35214
+ */
35215
+ this._state = BackgroundProcessManagerState.Open;
35216
+ /**
35217
+ * The list of outstanding jobs we'll need to wait for upon `close()`
35218
+ */
35219
+
35220
+ this.jobs = new Set();
35221
+ }
35222
+
35223
+ BackgroundProcessManager.prototype.add = function (jobOrDescription, optionalDescription) {
35224
+ var job;
35225
+ var description;
35226
+
35227
+ if (typeof jobOrDescription === 'string') {
35228
+ job = undefined;
35229
+ description = jobOrDescription;
35230
+ } else {
35231
+ job = jobOrDescription;
35232
+ description = optionalDescription;
35233
+ }
35234
+
35235
+ var error = this.closedFailure(description);
35236
+ if (error) return error;
35237
+
35238
+ if (job === undefined) {
35239
+ return this.addHook(description);
35240
+ } else if (typeof job === 'function') {
35241
+ return this.addFunction(job, description);
35242
+ } else if (job instanceof BackgroundProcessManager) {
35243
+ return this.addManager(job, description);
35244
+ } else {
35245
+ throw new Error('If `job` is provided, it must be an Observable, Function, or BackgroundProcessManager.');
35246
+ }
35247
+ };
35248
+ /**
35249
+ * Adds a **cleaner** function that doesn't immediately get executed.
35250
+ * Instead, the caller gets a **terminate** function back. The *cleaner* is
35251
+ * invoked only once the mananger *closes* or the returned **terminate**
35252
+ * function is called.
35253
+ *
35254
+ * @param clean The cleanup function.
35255
+ * @param description Optional description to help identify pending jobs.
35256
+ * @returns A terminate function.
35257
+ */
35258
+
35259
+
35260
+ BackgroundProcessManager.prototype.addCleaner = function (clean, description) {
35261
+ var _this = this;
35262
+
35263
+ var _a = this.addHook(description),
35264
+ resolve = _a.resolve,
35265
+ onTerminate = _a.onTerminate;
35266
+
35267
+ var proxy = function proxy() {
35268
+ return __awaiter(_this, void 0, void 0, function () {
35269
+ return __generator(this, function (_a) {
35270
+ switch (_a.label) {
35271
+ case 0:
35272
+ return [4
35273
+ /*yield*/
35274
+ , clean()];
35275
+
35276
+ case 1:
35277
+ _a.sent();
35278
+
35279
+ resolve();
35280
+ return [2
35281
+ /*return*/
35282
+ ];
35283
+ }
35284
+ });
35285
+ });
35286
+ };
35287
+
35288
+ onTerminate.then(proxy);
35289
+ return proxy;
35290
+ };
35291
+
35292
+ BackgroundProcessManager.prototype.addFunction = function (job, description) {
35293
+ // the function we call when we want to try to terminate this job.
35294
+ var terminate; // the promise the job can opt into listening to for termination.
35295
+
35296
+ var onTerminate = new Promise(function (resolve) {
35297
+ terminate = resolve;
35298
+ }); // finally! start the job.
35299
+
35300
+ var jobResult = job(onTerminate); // depending on what the job gives back, register the result
35301
+ // so we can monitor for completion.
35302
+
35303
+ if (typeof (jobResult === null || jobResult === void 0 ? void 0 : jobResult.then) === 'function') {
35304
+ this.registerPromise(jobResult, terminate, description);
35305
+ } // At the end of the day, or you know, method call, it doesn't matter
35306
+ // what the return value is at all; we just pass it through to the
35307
+ // caller.
35308
+
35309
+
35310
+ return jobResult;
35311
+ };
35312
+
35313
+ BackgroundProcessManager.prototype.addManager = function (manager, description) {
35314
+ var _this = this;
35315
+
35316
+ this.addCleaner(function () {
35317
+ return __awaiter(_this, void 0, void 0, function () {
35318
+ return __generator(this, function (_a) {
35319
+ switch (_a.label) {
35320
+ case 0:
35321
+ return [4
35322
+ /*yield*/
35323
+ , manager.close()];
35324
+
35325
+ case 1:
35326
+ return [2
35327
+ /*return*/
35328
+ , _a.sent()];
35329
+ }
35330
+ });
35331
+ });
35332
+ }, description);
35333
+ };
35334
+ /**
35335
+ * Creates and registers a fabricated job for processes that need to operate
35336
+ * with callbacks/hooks. The returned `resolve` and `reject`
35337
+ * functions can be used to signal the job is done successfully or not.
35338
+ * The returned `onTerminate` is a promise that will resolve when the
35339
+ * manager is requesting the termination of the job.
35340
+ *
35341
+ * @param description Optional description to help identify pending jobs.
35342
+ * @returns `{ resolve, reject, onTerminate }`
35343
+ */
35344
+
35345
+
35346
+ BackgroundProcessManager.prototype.addHook = function (description) {
35347
+ // the resolve/reject functions we'll provide to the caller to signal
35348
+ // the state of the job.
35349
+ var resolve;
35350
+ var reject; // the underlying promise we'll use to manage it, pretty much like
35351
+ // any other promise.
35352
+
35353
+ var promise = new Promise(function (res, rej) {
35354
+ resolve = res;
35355
+ reject = rej;
35356
+ }); // the function we call when we want to try to terminate this job.
35357
+
35358
+ var terminate; // the promise the job can opt into listening to for termination.
35359
+
35360
+ var onTerminate = new Promise(function (resolveTerminate) {
35361
+ terminate = resolveTerminate;
35362
+ });
35363
+ this.registerPromise(promise, terminate, description);
35364
+ return {
35365
+ resolve: resolve,
35366
+ reject: reject,
35367
+ onTerminate: onTerminate
35368
+ };
35369
+ };
35370
+ /**
35371
+ * Adds a Promise based job to the list of jobs for monitoring and listens
35372
+ * for either a success or failure, upon which the job is considered "done"
35373
+ * and removed from the registry.
35374
+ *
35375
+ * @param promise A promise that is on its way to being returned to a
35376
+ * caller, which needs to be tracked as a background job.
35377
+ * @param terminate The termination function to register, which can be
35378
+ * invoked to request the job stop.
35379
+ * @param description Optional description to help identify pending jobs.
35380
+ */
35381
+
35382
+
35383
+ BackgroundProcessManager.prototype.registerPromise = function (promise, terminate, description) {
35384
+ var _this = this;
35385
+
35386
+ var jobEntry = {
35387
+ promise: promise,
35388
+ terminate: terminate,
35389
+ description: description
35390
+ };
35391
+ this.jobs.add(jobEntry); // in all of my testing, it is safe to multi-subscribe to a promise.
35392
+ // so, rather than create another layer of promising, we're just going
35393
+ // to hook into the promise we already have, and when it's done
35394
+ // (successfully or not), we no longer need to wait for it upon close.
35395
+ //
35396
+ // sorry this is a bit hand-wavy:
35397
+ //
35398
+ // i believe we use `.then` and `.catch` instead of `.finally` because
35399
+ // `.finally` is invoked in a different order in the sequence, and this
35400
+ // breaks assumptions throughout and causes failures.
35401
+
35402
+ promise.then(function () {
35403
+ _this.jobs["delete"](jobEntry);
35404
+ })["catch"](function () {
35405
+ _this.jobs["delete"](jobEntry);
35406
+ });
35407
+ };
35408
+
35409
+ Object.defineProperty(BackgroundProcessManager.prototype, "length", {
35410
+ /**
35411
+ * The number of jobs being waited on.
35412
+ *
35413
+ * We don't use this for anything. It's just informational for the caller,
35414
+ * and can be used in logging and testing.
35415
+ *
35416
+ * @returns the number of jobs.
35417
+ */
35418
+ get: function get() {
35419
+ return this.jobs.size;
35420
+ },
35421
+ enumerable: true,
35422
+ configurable: true
35423
+ });
35424
+ Object.defineProperty(BackgroundProcessManager.prototype, "state", {
35425
+ /**
35426
+ * The execution state of the manager. One of:
35427
+ *
35428
+ * 1. "Open" -> Accepting new jobs
35429
+ * 1. "Closing" -> Not accepting new work. Waiting for jobs to complete.
35430
+ * 1. "Closed" -> Not accepting new work. All submitted jobs are complete.
35431
+ */
35432
+ get: function get() {
35433
+ return this._state;
35434
+ },
35435
+ enumerable: true,
35436
+ configurable: true
35437
+ });
35438
+ Object.defineProperty(BackgroundProcessManager.prototype, "pending", {
35439
+ /**
35440
+ * The registered `description` of all still-pending jobs.
35441
+ *
35442
+ * @returns descriptions as an array.
35443
+ */
35444
+ get: function get() {
35445
+ return Array.from(this.jobs).map(function (job) {
35446
+ return job.description;
35447
+ });
35448
+ },
35449
+ enumerable: true,
35450
+ configurable: true
35451
+ });
35452
+ Object.defineProperty(BackgroundProcessManager.prototype, "isOpen", {
35453
+ /**
35454
+ * Whether the manager is accepting new jobs.
35455
+ */
35456
+ get: function get() {
35457
+ return this._state === BackgroundProcessManagerState.Open;
35458
+ },
35459
+ enumerable: true,
35460
+ configurable: true
35461
+ });
35462
+ Object.defineProperty(BackgroundProcessManager.prototype, "isClosing", {
35463
+ /**
35464
+ * Whether the manager is rejecting new work, but still waiting for
35465
+ * submitted work to complete.
35466
+ */
35467
+ get: function get() {
35468
+ return this._state === BackgroundProcessManagerState.Closing;
35469
+ },
35470
+ enumerable: true,
35471
+ configurable: true
35472
+ });
35473
+ Object.defineProperty(BackgroundProcessManager.prototype, "isClosed", {
35474
+ /**
35475
+ * Whether the manager is rejecting work and done waiting for submitted
35476
+ * work to complete.
35477
+ */
35478
+ get: function get() {
35479
+ return this._state === BackgroundProcessManagerState.Closed;
35480
+ },
35481
+ enumerable: true,
35482
+ configurable: true
35483
+ });
35484
+
35485
+ BackgroundProcessManager.prototype.closedFailure = function (description) {
35486
+ if (!this.isOpen) {
35487
+ return Promise.reject(new Error(['The manager is closing or closed, which occurs after `close()` has been called.', "This error occurred trying to add \"" + description + "\".", "Pending jobs: [\n" + this.pending.map(function (t) {
35488
+ return ' ' + t;
35489
+ }).join(',\n') + "\n]"].join('\n')));
35490
+ }
35491
+ };
35492
+ /**
35493
+ * Signals jobs to stop (for those that accept interruptions) and waits
35494
+ * for confirmation that jobs have stopped.
35495
+ *
35496
+ * This immediately puts the manager into a closing state and just begins
35497
+ * to reject new work. After all work in the manager is complete, the
35498
+ * manager goes into a `Completed` state and `close()` returns.
35499
+ *
35500
+ * @returns The settled results of each job's promise.
35501
+ */
35502
+
35503
+
35504
+ BackgroundProcessManager.prototype.close = function () {
35505
+ return __awaiter(this, void 0, void 0, function () {
35506
+ var _a, _b, job, results;
35507
+
35508
+ var e_1, _c;
35509
+
35510
+ return __generator(this, function (_d) {
35511
+ switch (_d.label) {
35512
+ case 0:
35513
+ // prevents more jobs from being added
35514
+ this._state = BackgroundProcessManagerState.Closing;
35515
+
35516
+ try {
35517
+ for (_a = __values(Array.from(this.jobs)), _b = _a.next(); !_b.done; _b = _a.next()) {
35518
+ job = _b.value;
35519
+
35520
+ try {
35521
+ job.terminate();
35522
+ } catch (error) {
35523
+ // Due to potential races with a job's natural completion, it's
35524
+ // reasonable to expect the termination call to fail. Hence,
35525
+ // not logging as an error.
35526
+ console.warn("Failed to send termination signal to job. Error: " + error.message, job);
35527
+ }
35528
+ }
35529
+ } catch (e_1_1) {
35530
+ e_1 = {
35531
+ error: e_1_1
35532
+ };
35533
+ } finally {
35534
+ try {
35535
+ if (_b && !_b.done && (_c = _a["return"])) _c.call(_a);
35536
+ } finally {
35537
+ if (e_1) throw e_1.error;
35538
+ }
35539
+ }
35540
+
35541
+ return [4
35542
+ /*yield*/
35543
+ , Promise.allSettled(Array.from(this.jobs).map(function (j) {
35544
+ return j.promise;
35545
+ }))];
35546
+
35547
+ case 1:
35548
+ results = _d.sent(); // At this point, we're already *not* accepting new work, and all
35549
+ // pending work is done. It's safe to set state to `Closed`. Any
35550
+ // process that's checking this property will be able to safely operate
35551
+ // on this value at this point.
35552
+
35553
+ this._state = BackgroundProcessManagerState.Closed;
35554
+ return [2
35555
+ /*return*/
35556
+ , results];
35557
+ }
35558
+ });
35559
+ });
35560
+ };
35561
+
35562
+ return BackgroundProcessManager;
35563
+ }();
35564
+
35565
+
35566
+ /**
35567
+ * All possible states a `BackgroundProcessManager` instance can be in.
35568
+ */
35569
+
35570
+ var BackgroundProcessManagerState;
35571
+
35572
+ (function (BackgroundProcessManagerState) {
35573
+ /**
35574
+ * Accepting new jobs.
35575
+ */
35576
+ BackgroundProcessManagerState["Open"] = "Open";
35577
+ /**
35578
+ * Not accepting new jobs. Waiting for submitted jobs to complete.
35579
+ */
35580
+
35581
+ BackgroundProcessManagerState["Closing"] = "Closing";
35582
+ /**
35583
+ * Not accepting new jobs. All submitted jobs are complete.
35584
+ */
35585
+
35586
+ BackgroundProcessManagerState["Closed"] = "Closed";
35587
+ })(BackgroundProcessManagerState || (BackgroundProcessManagerState = {}));
35588
+
35017
35589
  /***/ }),
35018
35590
 
35019
35591
  /***/ "./lib-esm/Util/Constants.js":
@@ -35388,6 +35960,16 @@ __webpack_require__.r(__webpack_exports__);
35388
35960
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "jitteredBackoff", function() { return jitteredBackoff; });
35389
35961
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "jitteredExponentialRetry", function() { return jitteredExponentialRetry; });
35390
35962
  /* harmony import */ var _Logger_ConsoleLogger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Logger/ConsoleLogger */ "./lib-esm/Logger/ConsoleLogger.js");
35963
+ function _typeof(obj) {
35964
+ "@babel/helpers - typeof";
35965
+
35966
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
35967
+ return typeof obj;
35968
+ } : function (obj) {
35969
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
35970
+ }, _typeof(obj);
35971
+ }
35972
+
35391
35973
  var __extends = undefined && undefined.__extends || function () {
35392
35974
  var _extendStatics = function extendStatics(d, b) {
35393
35975
  _extendStatics = Object.setPrototypeOf || {
@@ -35622,80 +36204,142 @@ var isNonRetryableError = function isNonRetryableError(obj) {
35622
36204
  */
35623
36205
 
35624
36206
 
35625
- function retry(functionToRetry, args, delayFn, attempt) {
35626
- if (attempt === void 0) {
35627
- attempt = 1;
35628
- }
35629
-
36207
+ function retry(functionToRetry, args, delayFn, onTerminate) {
35630
36208
  return __awaiter(this, void 0, void 0, function () {
35631
- var err_1, retryIn_1;
36209
+ var _this = this;
36210
+
35632
36211
  return __generator(this, function (_a) {
35633
- switch (_a.label) {
35634
- case 0:
35635
- if (typeof functionToRetry !== 'function') {
35636
- throw Error('functionToRetry must be a function');
35637
- }
36212
+ if (typeof functionToRetry !== 'function') {
36213
+ throw Error('functionToRetry must be a function');
36214
+ }
35638
36215
 
35639
- logger.debug(functionToRetry.name + " attempt #" + attempt + " with this vars: " + JSON.stringify(args));
35640
- _a.label = 1;
36216
+ return [2
36217
+ /*return*/
36218
+ , new Promise(function (resolve, reject) {
36219
+ return __awaiter(_this, void 0, void 0, function () {
36220
+ var attempt, terminated, timeout, wakeUp, lastError, _loop_1, state_1;
35641
36221
 
35642
- case 1:
35643
- _a.trys.push([1, 3,, 8]);
36222
+ return __generator(this, function (_a) {
36223
+ switch (_a.label) {
36224
+ case 0:
36225
+ attempt = 0;
36226
+ terminated = false;
35644
36227
 
35645
- return [4
35646
- /*yield*/
35647
- , functionToRetry.apply(void 0, __spread(args))];
36228
+ wakeUp = function wakeUp() {};
35648
36229
 
35649
- case 2:
35650
- return [2
35651
- /*return*/
35652
- , _a.sent()];
36230
+ onTerminate && onTerminate.then(function () {
36231
+ // signal not to try anymore.
36232
+ terminated = true; // stop sleeping if we're sleeping.
35653
36233
 
35654
- case 3:
35655
- err_1 = _a.sent();
35656
- logger.debug("error on " + functionToRetry.name, err_1);
36234
+ clearTimeout(timeout);
36235
+ wakeUp();
36236
+ });
35657
36237
 
35658
- if (isNonRetryableError(err_1)) {
35659
- logger.debug(functionToRetry.name + " non retryable error", err_1);
35660
- throw err_1;
35661
- }
36238
+ _loop_1 = function _loop_1() {
36239
+ var _a, _b, err_1, retryIn_1;
35662
36240
 
35663
- retryIn_1 = delayFn(attempt, args, err_1);
35664
- logger.debug(functionToRetry.name + " retrying in " + retryIn_1 + " ms");
35665
- if (!(retryIn_1 !== false)) return [3
35666
- /*break*/
35667
- , 6];
35668
- return [4
35669
- /*yield*/
35670
- , new Promise(function (res) {
35671
- return setTimeout(res, retryIn_1);
35672
- })];
36241
+ return __generator(this, function (_c) {
36242
+ switch (_c.label) {
36243
+ case 0:
36244
+ attempt++;
36245
+ logger.debug(functionToRetry.name + " attempt #" + attempt + " with this vars: " + JSON.stringify(args));
36246
+ _c.label = 1;
35673
36247
 
35674
- case 4:
35675
- _a.sent();
36248
+ case 1:
36249
+ _c.trys.push([1, 3,, 7]);
35676
36250
 
35677
- return [4
35678
- /*yield*/
35679
- , retry(functionToRetry, args, delayFn, attempt + 1)];
36251
+ _a = {};
36252
+ _b = resolve;
36253
+ return [4
36254
+ /*yield*/
36255
+ , functionToRetry.apply(void 0, __spread(args))];
35680
36256
 
35681
- case 5:
35682
- return [2
35683
- /*return*/
35684
- , _a.sent()];
36257
+ case 2:
36258
+ return [2
36259
+ /*return*/
36260
+ , (_a.value = _b.apply(void 0, [_c.sent()]), _a)];
36261
+
36262
+ case 3:
36263
+ err_1 = _c.sent();
36264
+ lastError = err_1;
36265
+ logger.debug("error on " + functionToRetry.name, err_1);
36266
+
36267
+ if (isNonRetryableError(err_1)) {
36268
+ logger.debug(functionToRetry.name + " non retryable error", err_1);
36269
+ return [2
36270
+ /*return*/
36271
+ , {
36272
+ value: reject(err_1)
36273
+ }];
36274
+ }
35685
36275
 
35686
- case 6:
35687
- throw err_1;
36276
+ retryIn_1 = delayFn(attempt, args, err_1);
36277
+ logger.debug(functionToRetry.name + " retrying in " + retryIn_1 + " ms");
36278
+ if (!(retryIn_1 === false || terminated)) return [3
36279
+ /*break*/
36280
+ , 4];
36281
+ return [2
36282
+ /*return*/
36283
+ , {
36284
+ value: reject(err_1)
36285
+ }];
36286
+
36287
+ case 4:
36288
+ return [4
36289
+ /*yield*/
36290
+ , new Promise(function (r) {
36291
+ wakeUp = r; // export wakeUp for onTerminate handling
35688
36292
 
35689
- case 7:
35690
- return [3
35691
- /*break*/
35692
- , 8];
36293
+ timeout = setTimeout(wakeUp, retryIn_1);
36294
+ })];
35693
36295
 
35694
- case 8:
35695
- return [2
35696
- /*return*/
35697
- ];
35698
- }
36296
+ case 5:
36297
+ _c.sent();
36298
+
36299
+ _c.label = 6;
36300
+
36301
+ case 6:
36302
+ return [3
36303
+ /*break*/
36304
+ , 7];
36305
+
36306
+ case 7:
36307
+ return [2
36308
+ /*return*/
36309
+ ];
36310
+ }
36311
+ });
36312
+ };
36313
+
36314
+ _a.label = 1;
36315
+
36316
+ case 1:
36317
+ if (!!terminated) return [3
36318
+ /*break*/
36319
+ , 3];
36320
+ return [5
36321
+ /*yield**/
36322
+ , _loop_1()];
36323
+
36324
+ case 2:
36325
+ state_1 = _a.sent();
36326
+ if (_typeof(state_1) === "object") return [2
36327
+ /*return*/
36328
+ , state_1.value];
36329
+ return [3
36330
+ /*break*/
36331
+ , 1];
36332
+
36333
+ case 3:
36334
+ // reached if terminated while waiting for a timer.
36335
+ reject(lastError);
36336
+ return [2
36337
+ /*return*/
36338
+ ];
36339
+ }
36340
+ });
36341
+ });
36342
+ })];
35699
36343
  });
35700
36344
  });
35701
36345
  }
@@ -35722,12 +36366,12 @@ function jitteredBackoff(maxDelayMs) {
35722
36366
  * Internal use of Amplify only
35723
36367
  */
35724
36368
 
35725
- var jitteredExponentialRetry = function jitteredExponentialRetry(functionToRetry, args, maxDelayMs) {
36369
+ var jitteredExponentialRetry = function jitteredExponentialRetry(functionToRetry, args, maxDelayMs, onTerminate) {
35726
36370
  if (maxDelayMs === void 0) {
35727
36371
  maxDelayMs = MAX_DELAY_MS;
35728
36372
  }
35729
36373
 
35730
- return retry(functionToRetry, args, jitteredBackoff(maxDelayMs));
36374
+ return retry(functionToRetry, args, jitteredBackoff(maxDelayMs), onTerminate);
35731
36375
  };
35732
36376
 
35733
36377
  /***/ }),
@@ -35760,7 +36404,7 @@ function urlSafeDecode(hex) {
35760
36404
  /*!*******************************!*\
35761
36405
  !*** ./lib-esm/Util/index.js ***!
35762
36406
  \*******************************/
35763
- /*! exports provided: NonRetryableError, retry, jitteredBackoff, jitteredExponentialRetry, Mutex, Reachability, DateUtils, urlSafeEncode, urlSafeDecode, AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES */
36407
+ /*! exports provided: NonRetryableError, retry, jitteredBackoff, jitteredExponentialRetry, Mutex, Reachability, DateUtils, urlSafeEncode, urlSafeDecode, AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES, BackgroundProcessManager, BackgroundProcessManagerState */
35764
36408
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
35765
36409
 
35766
36410
  "use strict";
@@ -35803,6 +36447,12 @@ __webpack_require__.r(__webpack_exports__);
35803
36447
 
35804
36448
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RETRY_ERROR_CODES", function() { return _Constants__WEBPACK_IMPORTED_MODULE_5__["RETRY_ERROR_CODES"]; });
35805
36449
 
36450
+ /* harmony import */ var _BackgroundProcessManager__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./BackgroundProcessManager */ "./lib-esm/Util/BackgroundProcessManager.js");
36451
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BackgroundProcessManager", function() { return _BackgroundProcessManager__WEBPACK_IMPORTED_MODULE_6__["BackgroundProcessManager"]; });
36452
+
36453
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BackgroundProcessManagerState", function() { return _BackgroundProcessManager__WEBPACK_IMPORTED_MODULE_6__["BackgroundProcessManagerState"]; });
36454
+
36455
+
35806
36456
 
35807
36457
 
35808
36458
 
@@ -35856,7 +36506,7 @@ var USER_AGENT_HEADER = 'x-amz-user-agent';
35856
36506
  /*!**************************!*\
35857
36507
  !*** ./lib-esm/index.js ***!
35858
36508
  \**************************/
35859
- /*! exports provided: AmplifyClass, ClientDevice, ConsoleLogger, Logger, missingConfig, invalidParameter, Hub, I18n, isEmpty, sortByField, objectLessAttributes, filenameToContentType, isTextFile, generateRandomString, makeQuerablePromise, isWebWorker, browserOrNode, transferKeyToLowerCase, transferKeyToUpperCase, isStrictObject, JS, Signer, parseMobileHubConfig, Parser, AWSCloudWatchProvider, FacebookOAuth, GoogleOAuth, Linking, AppState, AsyncStorage, Credentials, CredentialsClass, ServiceWorker, StorageHelper, MemoryStorage, UniversalStorage, Platform, getAmplifyUserAgent, INTERNAL_AWS_APPSYNC_PUBSUB_PROVIDER, INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER, USER_AGENT_HEADER, Constants, NonRetryableError, retry, jitteredBackoff, jitteredExponentialRetry, Mutex, Reachability, DateUtils, urlSafeEncode, urlSafeDecode, AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES, Amplify, default */
36509
+ /*! exports provided: AmplifyClass, ClientDevice, ConsoleLogger, Logger, missingConfig, invalidParameter, Hub, I18n, isEmpty, sortByField, objectLessAttributes, filenameToContentType, isTextFile, generateRandomString, makeQuerablePromise, isWebWorker, browserOrNode, transferKeyToLowerCase, transferKeyToUpperCase, isStrictObject, JS, Signer, parseMobileHubConfig, Parser, AWSCloudWatchProvider, FacebookOAuth, GoogleOAuth, Linking, AppState, AsyncStorage, Credentials, CredentialsClass, ServiceWorker, StorageHelper, MemoryStorage, UniversalStorage, Platform, getAmplifyUserAgent, INTERNAL_AWS_APPSYNC_PUBSUB_PROVIDER, INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER, USER_AGENT_HEADER, Constants, NonRetryableError, retry, jitteredBackoff, jitteredExponentialRetry, Mutex, Reachability, DateUtils, urlSafeEncode, urlSafeDecode, AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES, BackgroundProcessManager, BackgroundProcessManagerState, Amplify, default */
35860
36510
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
35861
36511
 
35862
36512
  "use strict";
@@ -35997,6 +36647,10 @@ __webpack_require__.r(__webpack_exports__);
35997
36647
 
35998
36648
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RETRY_ERROR_CODES", function() { return _Util__WEBPACK_IMPORTED_MODULE_18__["RETRY_ERROR_CODES"]; });
35999
36649
 
36650
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BackgroundProcessManager", function() { return _Util__WEBPACK_IMPORTED_MODULE_18__["BackgroundProcessManager"]; });
36651
+
36652
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BackgroundProcessManagerState", function() { return _Util__WEBPACK_IMPORTED_MODULE_18__["BackgroundProcessManagerState"]; });
36653
+
36000
36654
  /*
36001
36655
  * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
36002
36656
  *