@aws-amplify/core 4.7.9-unstable.2 → 4.7.9

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 (74) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/aws-amplify-core.js +673 -45
  3. package/dist/aws-amplify-core.js.map +1 -1
  4. package/dist/aws-amplify-core.min.js +4 -4
  5. package/dist/aws-amplify-core.min.js.map +1 -1
  6. package/lib/Credentials.js +1 -1
  7. package/lib/Credentials.js.map +1 -1
  8. package/lib/Util/BackgroundProcessManager.js +444 -0
  9. package/lib/Util/BackgroundProcessManager.js.map +1 -0
  10. package/lib/Util/Retry.js +76 -34
  11. package/lib/Util/Retry.js.map +1 -1
  12. package/lib/Util/index.js +1 -0
  13. package/lib/Util/index.js.map +1 -1
  14. package/lib-esm/Credentials.d.ts +1 -1
  15. package/lib-esm/Credentials.js +1 -1
  16. package/lib-esm/Credentials.js.map +1 -1
  17. package/lib-esm/Util/BackgroundProcessManager.d.ts +204 -0
  18. package/lib-esm/Util/BackgroundProcessManager.js +442 -0
  19. package/lib-esm/Util/BackgroundProcessManager.js.map +1 -0
  20. package/lib-esm/Util/Retry.d.ts +2 -2
  21. package/lib-esm/Util/Retry.js +76 -34
  22. package/lib-esm/Util/Retry.js.map +1 -1
  23. package/lib-esm/Util/index.d.ts +1 -0
  24. package/lib-esm/Util/index.js +1 -0
  25. package/lib-esm/Util/index.js.map +1 -1
  26. package/package.json +2 -2
  27. package/src/Credentials.ts +13 -14
  28. package/src/Util/BackgroundProcessManager.ts +449 -0
  29. package/src/Util/Retry.ts +66 -31
  30. package/src/Util/index.ts +1 -0
  31. package/lib/Amplify.d.ts +0 -31
  32. package/lib/ClientDevice/android.d.ts +0 -5
  33. package/lib/ClientDevice/browser.d.ts +0 -25
  34. package/lib/ClientDevice/index.d.ts +0 -27
  35. package/lib/ClientDevice/ios.d.ts +0 -7
  36. package/lib/ClientDevice/reactnative.d.ts +0 -14
  37. package/lib/Credentials.d.ts +0 -51
  38. package/lib/Errors.d.ts +0 -2
  39. package/lib/Hub.d.ts +0 -31
  40. package/lib/I18n/I18n.d.ts +0 -59
  41. package/lib/I18n/index.d.ts +0 -53
  42. package/lib/I18n/types.d.ts +0 -3
  43. package/lib/JS.d.ts +0 -56
  44. package/lib/Logger/ConsoleLogger.d.ts +0 -80
  45. package/lib/Logger/index.d.ts +0 -1
  46. package/lib/Logger/logger-interface.d.ts +0 -12
  47. package/lib/OAuthHelper/FacebookOAuth.d.ts +0 -10
  48. package/lib/OAuthHelper/GoogleOAuth.d.ts +0 -10
  49. package/lib/OAuthHelper/index.d.ts +0 -4
  50. package/lib/Parser.d.ts +0 -12
  51. package/lib/Platform/index.d.ts +0 -11
  52. package/lib/Platform/version.d.ts +0 -1
  53. package/lib/Providers/AWSCloudWatchProvider.d.ts +0 -34
  54. package/lib/Providers/index.d.ts +0 -1
  55. package/lib/RNComponents/index.d.ts +0 -5
  56. package/lib/RNComponents/reactnative.d.ts +0 -3
  57. package/lib/ServiceWorker/ServiceWorker.d.ts +0 -72
  58. package/lib/ServiceWorker/index.d.ts +0 -13
  59. package/lib/Signer.d.ts +0 -45
  60. package/lib/StorageHelper/index.d.ts +0 -45
  61. package/lib/StorageHelper/reactnative.d.ts +0 -17
  62. package/lib/UniversalStorage/index.d.ts +0 -23
  63. package/lib/Util/Constants.d.ts +0 -8
  64. package/lib/Util/DateUtils.d.ts +0 -7
  65. package/lib/Util/Mutex.d.ts +0 -45
  66. package/lib/Util/Reachability.d.ts +0 -13
  67. package/lib/Util/Reachability.native.d.ts +0 -11
  68. package/lib/Util/Retry.d.ts +0 -20
  69. package/lib/Util/StringUtils.d.ts +0 -2
  70. package/lib/Util/index.d.ts +0 -6
  71. package/lib/constants.d.ts +0 -6
  72. package/lib/index.d.ts +0 -30
  73. package/lib/types/index.d.ts +0 -1
  74. package/lib/types/types.d.ts +0 -43
@@ -33991,6 +33991,569 @@ var UniversalStorage = /** @class */function () {
33991
33991
  }();
33992
33992
 
33993
33993
 
33994
+ /***/ }),
33995
+
33996
+ /***/ "./lib-esm/Util/BackgroundProcessManager.js":
33997
+ /*!**************************************************!*\
33998
+ !*** ./lib-esm/Util/BackgroundProcessManager.js ***!
33999
+ \**************************************************/
34000
+ /*! exports provided: BackgroundProcessManager, BackgroundManagerNotOpenError, BackgroundProcessManagerState */
34001
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
34002
+
34003
+ "use strict";
34004
+ __webpack_require__.r(__webpack_exports__);
34005
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "BackgroundProcessManager", function() { return BackgroundProcessManager; });
34006
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "BackgroundManagerNotOpenError", function() { return BackgroundManagerNotOpenError; });
34007
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "BackgroundProcessManagerState", function() { return BackgroundProcessManagerState; });
34008
+ var __extends = undefined && undefined.__extends || function () {
34009
+ var _extendStatics = function extendStatics(d, b) {
34010
+ _extendStatics = Object.setPrototypeOf || {
34011
+ __proto__: []
34012
+ } instanceof Array && function (d, b) {
34013
+ d.__proto__ = b;
34014
+ } || function (d, b) {
34015
+ for (var p in b) {
34016
+ if (b.hasOwnProperty(p)) d[p] = b[p];
34017
+ }
34018
+ };
34019
+ return _extendStatics(d, b);
34020
+ };
34021
+ return function (d, b) {
34022
+ _extendStatics(d, b);
34023
+ function __() {
34024
+ this.constructor = d;
34025
+ }
34026
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
34027
+ };
34028
+ }();
34029
+ var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
34030
+ function adopt(value) {
34031
+ return value instanceof P ? value : new P(function (resolve) {
34032
+ resolve(value);
34033
+ });
34034
+ }
34035
+ return new (P || (P = Promise))(function (resolve, reject) {
34036
+ function fulfilled(value) {
34037
+ try {
34038
+ step(generator.next(value));
34039
+ } catch (e) {
34040
+ reject(e);
34041
+ }
34042
+ }
34043
+ function rejected(value) {
34044
+ try {
34045
+ step(generator["throw"](value));
34046
+ } catch (e) {
34047
+ reject(e);
34048
+ }
34049
+ }
34050
+ function step(result) {
34051
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
34052
+ }
34053
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
34054
+ });
34055
+ };
34056
+ var __generator = undefined && undefined.__generator || function (thisArg, body) {
34057
+ var _ = {
34058
+ label: 0,
34059
+ sent: function sent() {
34060
+ if (t[0] & 1) throw t[1];
34061
+ return t[1];
34062
+ },
34063
+ trys: [],
34064
+ ops: []
34065
+ },
34066
+ f,
34067
+ y,
34068
+ t,
34069
+ g;
34070
+ return g = {
34071
+ next: verb(0),
34072
+ "throw": verb(1),
34073
+ "return": verb(2)
34074
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
34075
+ return this;
34076
+ }), g;
34077
+ function verb(n) {
34078
+ return function (v) {
34079
+ return step([n, v]);
34080
+ };
34081
+ }
34082
+ function step(op) {
34083
+ if (f) throw new TypeError("Generator is already executing.");
34084
+ while (_) {
34085
+ try {
34086
+ 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;
34087
+ if (y = 0, t) op = [op[0] & 2, t.value];
34088
+ switch (op[0]) {
34089
+ case 0:
34090
+ case 1:
34091
+ t = op;
34092
+ break;
34093
+ case 4:
34094
+ _.label++;
34095
+ return {
34096
+ value: op[1],
34097
+ done: false
34098
+ };
34099
+ case 5:
34100
+ _.label++;
34101
+ y = op[1];
34102
+ op = [0];
34103
+ continue;
34104
+ case 7:
34105
+ op = _.ops.pop();
34106
+ _.trys.pop();
34107
+ continue;
34108
+ default:
34109
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
34110
+ _ = 0;
34111
+ continue;
34112
+ }
34113
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
34114
+ _.label = op[1];
34115
+ break;
34116
+ }
34117
+ if (op[0] === 6 && _.label < t[1]) {
34118
+ _.label = t[1];
34119
+ t = op;
34120
+ break;
34121
+ }
34122
+ if (t && _.label < t[2]) {
34123
+ _.label = t[2];
34124
+ _.ops.push(op);
34125
+ break;
34126
+ }
34127
+ if (t[2]) _.ops.pop();
34128
+ _.trys.pop();
34129
+ continue;
34130
+ }
34131
+ op = body.call(thisArg, _);
34132
+ } catch (e) {
34133
+ op = [6, e];
34134
+ y = 0;
34135
+ } finally {
34136
+ f = t = 0;
34137
+ }
34138
+ }
34139
+ if (op[0] & 5) throw op[1];
34140
+ return {
34141
+ value: op[0] ? op[1] : void 0,
34142
+ done: true
34143
+ };
34144
+ }
34145
+ };
34146
+ var __values = undefined && undefined.__values || function (o) {
34147
+ var s = typeof Symbol === "function" && Symbol.iterator,
34148
+ m = s && o[s],
34149
+ i = 0;
34150
+ if (m) return m.call(o);
34151
+ if (o && typeof o.length === "number") return {
34152
+ next: function next() {
34153
+ if (o && i >= o.length) o = void 0;
34154
+ return {
34155
+ value: o && o[i++],
34156
+ done: !o
34157
+ };
34158
+ }
34159
+ };
34160
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
34161
+ };
34162
+ /**
34163
+ * @private For internal Amplify use.
34164
+ *
34165
+ * Creates a new scope for promises, observables, and other types of work or
34166
+ * processes that may be running in the background. This manager provides
34167
+ * an singular entrypoint to request termination and await completion.
34168
+ *
34169
+ * As work completes on its own prior to close, the manager removes them
34170
+ * from the registry to avoid holding references to completed jobs.
34171
+ */
34172
+ var BackgroundProcessManager = /** @class */function () {
34173
+ /**
34174
+ * Creates a new manager for promises, observables, and other types
34175
+ * of work that may be running in the background. This manager provides
34176
+ * a centralized mechanism to request termination and await completion.
34177
+ */
34178
+ function BackgroundProcessManager() {
34179
+ /**
34180
+ * A string indicating whether the manager is accepting new work ("Open"),
34181
+ * waiting for work to complete ("Closing"), or fully done with all
34182
+ * submitted work and *not* accepting new jobs ("Closed").
34183
+ */
34184
+ this._state = BackgroundProcessManagerState.Open;
34185
+ /**
34186
+ * The list of outstanding jobs we'll need to wait for upon `close()`
34187
+ */
34188
+ this.jobs = new Set();
34189
+ }
34190
+ BackgroundProcessManager.prototype.add = function (jobOrDescription, optionalDescription) {
34191
+ var job;
34192
+ var description;
34193
+ if (typeof jobOrDescription === 'string') {
34194
+ job = undefined;
34195
+ description = jobOrDescription;
34196
+ } else {
34197
+ job = jobOrDescription;
34198
+ description = optionalDescription;
34199
+ }
34200
+ var error = this.closedFailure(description);
34201
+ if (error) return error;
34202
+ if (job === undefined) {
34203
+ return this.addHook(description);
34204
+ } else if (typeof job === 'function') {
34205
+ return this.addFunction(job, description);
34206
+ } else if (job instanceof BackgroundProcessManager) {
34207
+ return this.addManager(job, description);
34208
+ } else {
34209
+ throw new Error('If `job` is provided, it must be an Observable, Function, or BackgroundProcessManager.');
34210
+ }
34211
+ };
34212
+ /**
34213
+ * Adds a **cleaner** function that doesn't immediately get executed.
34214
+ * Instead, the caller gets a **terminate** function back. The *cleaner* is
34215
+ * invoked only once the mananger *closes* or the returned **terminate**
34216
+ * function is called.
34217
+ *
34218
+ * @param clean The cleanup function.
34219
+ * @param description Optional description to help identify pending jobs.
34220
+ * @returns A terminate function.
34221
+ */
34222
+ BackgroundProcessManager.prototype.addCleaner = function (clean, description) {
34223
+ var _this = this;
34224
+ var _a = this.addHook(description),
34225
+ resolve = _a.resolve,
34226
+ onTerminate = _a.onTerminate;
34227
+ var proxy = function proxy() {
34228
+ return __awaiter(_this, void 0, void 0, function () {
34229
+ return __generator(this, function (_a) {
34230
+ switch (_a.label) {
34231
+ case 0:
34232
+ return [4 /*yield*/, clean()];
34233
+ case 1:
34234
+ _a.sent();
34235
+ resolve();
34236
+ return [2 /*return*/];
34237
+ }
34238
+ });
34239
+ });
34240
+ };
34241
+
34242
+ onTerminate.then(proxy);
34243
+ return proxy;
34244
+ };
34245
+ BackgroundProcessManager.prototype.addFunction = function (job, description) {
34246
+ // the function we call when we want to try to terminate this job.
34247
+ var terminate;
34248
+ // the promise the job can opt into listening to for termination.
34249
+ var onTerminate = new Promise(function (resolve) {
34250
+ terminate = resolve;
34251
+ });
34252
+ // finally! start the job.
34253
+ var jobResult = job(onTerminate);
34254
+ // depending on what the job gives back, register the result
34255
+ // so we can monitor for completion.
34256
+ if (typeof (jobResult === null || jobResult === void 0 ? void 0 : jobResult.then) === 'function') {
34257
+ this.registerPromise(jobResult, terminate, description);
34258
+ }
34259
+ // At the end of the day, or you know, method call, it doesn't matter
34260
+ // what the return value is at all; we just pass it through to the
34261
+ // caller.
34262
+ return jobResult;
34263
+ };
34264
+ BackgroundProcessManager.prototype.addManager = function (manager, description) {
34265
+ var _this = this;
34266
+ this.addCleaner(function () {
34267
+ return __awaiter(_this, void 0, void 0, function () {
34268
+ return __generator(this, function (_a) {
34269
+ switch (_a.label) {
34270
+ case 0:
34271
+ return [4 /*yield*/, manager.close()];
34272
+ case 1:
34273
+ return [2 /*return*/, _a.sent()];
34274
+ }
34275
+ });
34276
+ });
34277
+ }, description);
34278
+ };
34279
+ /**
34280
+ * Creates and registers a fabricated job for processes that need to operate
34281
+ * with callbacks/hooks. The returned `resolve` and `reject`
34282
+ * functions can be used to signal the job is done successfully or not.
34283
+ * The returned `onTerminate` is a promise that will resolve when the
34284
+ * manager is requesting the termination of the job.
34285
+ *
34286
+ * @param description Optional description to help identify pending jobs.
34287
+ * @returns `{ resolve, reject, onTerminate }`
34288
+ */
34289
+ BackgroundProcessManager.prototype.addHook = function (description) {
34290
+ // the resolve/reject functions we'll provide to the caller to signal
34291
+ // the state of the job.
34292
+ var resolve;
34293
+ var reject;
34294
+ // the underlying promise we'll use to manage it, pretty much like
34295
+ // any other promise.
34296
+ var promise = new Promise(function (res, rej) {
34297
+ resolve = res;
34298
+ reject = rej;
34299
+ });
34300
+ // the function we call when we want to try to terminate this job.
34301
+ var terminate;
34302
+ // the promise the job can opt into listening to for termination.
34303
+ var onTerminate = new Promise(function (resolveTerminate) {
34304
+ terminate = resolveTerminate;
34305
+ });
34306
+ this.registerPromise(promise, terminate, description);
34307
+ return {
34308
+ resolve: resolve,
34309
+ reject: reject,
34310
+ onTerminate: onTerminate
34311
+ };
34312
+ };
34313
+ /**
34314
+ * Adds a Promise based job to the list of jobs for monitoring and listens
34315
+ * for either a success or failure, upon which the job is considered "done"
34316
+ * and removed from the registry.
34317
+ *
34318
+ * @param promise A promise that is on its way to being returned to a
34319
+ * caller, which needs to be tracked as a background job.
34320
+ * @param terminate The termination function to register, which can be
34321
+ * invoked to request the job stop.
34322
+ * @param description Optional description to help identify pending jobs.
34323
+ */
34324
+ BackgroundProcessManager.prototype.registerPromise = function (promise, terminate, description) {
34325
+ var _this = this;
34326
+ var jobEntry = {
34327
+ promise: promise,
34328
+ terminate: terminate,
34329
+ description: description
34330
+ };
34331
+ this.jobs.add(jobEntry);
34332
+ // in all of my testing, it is safe to multi-subscribe to a promise.
34333
+ // so, rather than create another layer of promising, we're just going
34334
+ // to hook into the promise we already have, and when it's done
34335
+ // (successfully or not), we no longer need to wait for it upon close.
34336
+ //
34337
+ // sorry this is a bit hand-wavy:
34338
+ //
34339
+ // i believe we use `.then` and `.catch` instead of `.finally` because
34340
+ // `.finally` is invoked in a different order in the sequence, and this
34341
+ // breaks assumptions throughout and causes failures.
34342
+ promise.then(function () {
34343
+ _this.jobs["delete"](jobEntry);
34344
+ })["catch"](function () {
34345
+ _this.jobs["delete"](jobEntry);
34346
+ });
34347
+ };
34348
+ Object.defineProperty(BackgroundProcessManager.prototype, "length", {
34349
+ /**
34350
+ * The number of jobs being waited on.
34351
+ *
34352
+ * We don't use this for anything. It's just informational for the caller,
34353
+ * and can be used in logging and testing.
34354
+ *
34355
+ * @returns the number of jobs.
34356
+ */
34357
+ get: function get() {
34358
+ return this.jobs.size;
34359
+ },
34360
+ enumerable: true,
34361
+ configurable: true
34362
+ });
34363
+ Object.defineProperty(BackgroundProcessManager.prototype, "state", {
34364
+ /**
34365
+ * The execution state of the manager. One of:
34366
+ *
34367
+ * 1. "Open" -> Accepting new jobs
34368
+ * 1. "Closing" -> Not accepting new work. Waiting for jobs to complete.
34369
+ * 1. "Closed" -> Not accepting new work. All submitted jobs are complete.
34370
+ */
34371
+ get: function get() {
34372
+ return this._state;
34373
+ },
34374
+ enumerable: true,
34375
+ configurable: true
34376
+ });
34377
+ Object.defineProperty(BackgroundProcessManager.prototype, "pending", {
34378
+ /**
34379
+ * The registered `description` of all still-pending jobs.
34380
+ *
34381
+ * @returns descriptions as an array.
34382
+ */
34383
+ get: function get() {
34384
+ return Array.from(this.jobs).map(function (job) {
34385
+ return job.description;
34386
+ });
34387
+ },
34388
+ enumerable: true,
34389
+ configurable: true
34390
+ });
34391
+ Object.defineProperty(BackgroundProcessManager.prototype, "isOpen", {
34392
+ /**
34393
+ * Whether the manager is accepting new jobs.
34394
+ */
34395
+ get: function get() {
34396
+ return this._state === BackgroundProcessManagerState.Open;
34397
+ },
34398
+ enumerable: true,
34399
+ configurable: true
34400
+ });
34401
+ Object.defineProperty(BackgroundProcessManager.prototype, "isClosing", {
34402
+ /**
34403
+ * Whether the manager is rejecting new work, but still waiting for
34404
+ * submitted work to complete.
34405
+ */
34406
+ get: function get() {
34407
+ return this._state === BackgroundProcessManagerState.Closing;
34408
+ },
34409
+ enumerable: true,
34410
+ configurable: true
34411
+ });
34412
+ Object.defineProperty(BackgroundProcessManager.prototype, "isClosed", {
34413
+ /**
34414
+ * Whether the manager is rejecting work and done waiting for submitted
34415
+ * work to complete.
34416
+ */
34417
+ get: function get() {
34418
+ return this._state === BackgroundProcessManagerState.Closed;
34419
+ },
34420
+ enumerable: true,
34421
+ configurable: true
34422
+ });
34423
+ BackgroundProcessManager.prototype.closedFailure = function (description) {
34424
+ if (!this.isOpen) {
34425
+ return Promise.reject(new BackgroundManagerNotOpenError(["The manager is " + this.state + ".", "You tried to add \"" + description + "\".", "Pending jobs: [\n" + this.pending.map(function (t) {
34426
+ return ' ' + t;
34427
+ }).join(',\n') + "\n]"].join('\n')));
34428
+ }
34429
+ };
34430
+ /**
34431
+ * Signals jobs to stop (for those that accept interruptions) and waits
34432
+ * for confirmation that jobs have stopped.
34433
+ *
34434
+ * This immediately puts the manager into a closing state and just begins
34435
+ * to reject new work. After all work in the manager is complete, the
34436
+ * manager goes into a `Completed` state and `close()` returns.
34437
+ *
34438
+ * This call is idempotent.
34439
+ *
34440
+ * If the manager is already closing or closed, `finalCleaup` is not executed.
34441
+ *
34442
+ * @param onClosed
34443
+ * @returns The settled results of each still-running job's promise. If the
34444
+ * manager is already closed, this will contain the results as of when the
34445
+ * manager's `close()` was called in an `Open` state.
34446
+ */
34447
+ BackgroundProcessManager.prototype.close = function () {
34448
+ return __awaiter(this, void 0, void 0, function () {
34449
+ var _a, _b, job;
34450
+ var e_1, _c;
34451
+ return __generator(this, function (_d) {
34452
+ switch (_d.label) {
34453
+ case 0:
34454
+ if (!this.isOpen) return [3 /*break*/, 2];
34455
+ this._state = BackgroundProcessManagerState.Closing;
34456
+ try {
34457
+ for (_a = __values(Array.from(this.jobs)), _b = _a.next(); !_b.done; _b = _a.next()) {
34458
+ job = _b.value;
34459
+ try {
34460
+ job.terminate();
34461
+ } catch (error) {
34462
+ // Due to potential races with a job's natural completion, it's
34463
+ // reasonable to expect the termination call to fail. Hence,
34464
+ // not logging as an error.
34465
+ console.warn("Failed to send termination signal to job. Error: " + error.message, job);
34466
+ }
34467
+ }
34468
+ } catch (e_1_1) {
34469
+ e_1 = {
34470
+ error: e_1_1
34471
+ };
34472
+ } finally {
34473
+ try {
34474
+ if (_b && !_b.done && (_c = _a["return"])) _c.call(_a);
34475
+ } finally {
34476
+ if (e_1) throw e_1.error;
34477
+ }
34478
+ }
34479
+ // Use `allSettled()` because we want to wait for all to finish. We do
34480
+ // not want to stop waiting if there is a failure.
34481
+ this._closingPromise = Promise.allSettled(Array.from(this.jobs).map(function (j) {
34482
+ return j.promise;
34483
+ }));
34484
+ return [4 /*yield*/, this._closingPromise];
34485
+ case 1:
34486
+ _d.sent();
34487
+ this._state = BackgroundProcessManagerState.Closed;
34488
+ _d.label = 2;
34489
+ case 2:
34490
+ return [2 /*return*/, this._closingPromise];
34491
+ }
34492
+ });
34493
+ });
34494
+ };
34495
+ /**
34496
+ * Signals the manager to start accepting work (again) and returns once
34497
+ * the manager is ready to do so.
34498
+ *
34499
+ * If the state is already `Open`, this call is a no-op.
34500
+ *
34501
+ * If the state is `Closed`, this call simply updates state and returns.
34502
+ *
34503
+ * If the state is `Closing`, this call waits for completion before it
34504
+ * updates the state and returns.
34505
+ */
34506
+ BackgroundProcessManager.prototype.open = function () {
34507
+ return __awaiter(this, void 0, void 0, function () {
34508
+ return __generator(this, function (_a) {
34509
+ switch (_a.label) {
34510
+ case 0:
34511
+ if (!this.isClosing) return [3 /*break*/, 2];
34512
+ return [4 /*yield*/, this.close()];
34513
+ case 1:
34514
+ _a.sent();
34515
+ _a.label = 2;
34516
+ case 2:
34517
+ this._state = BackgroundProcessManagerState.Open;
34518
+ return [2 /*return*/];
34519
+ }
34520
+ });
34521
+ });
34522
+ };
34523
+
34524
+ return BackgroundProcessManager;
34525
+ }();
34526
+
34527
+ /**
34528
+ *
34529
+ */
34530
+ var BackgroundManagerNotOpenError = /** @class */function (_super) {
34531
+ __extends(BackgroundManagerNotOpenError, _super);
34532
+ function BackgroundManagerNotOpenError(message) {
34533
+ return _super.call(this, "BackgroundManagerNotOpenError: " + message) || this;
34534
+ }
34535
+ return BackgroundManagerNotOpenError;
34536
+ }(Error);
34537
+
34538
+ /**
34539
+ * All possible states a `BackgroundProcessManager` instance can be in.
34540
+ */
34541
+ var BackgroundProcessManagerState;
34542
+ (function (BackgroundProcessManagerState) {
34543
+ /**
34544
+ * Accepting new jobs.
34545
+ */
34546
+ BackgroundProcessManagerState["Open"] = "Open";
34547
+ /**
34548
+ * Not accepting new jobs. Waiting for submitted jobs to complete.
34549
+ */
34550
+ BackgroundProcessManagerState["Closing"] = "Closing";
34551
+ /**
34552
+ * Not accepting new jobs. All submitted jobs are complete.
34553
+ */
34554
+ BackgroundProcessManagerState["Closed"] = "Closed";
34555
+ })(BackgroundProcessManagerState || (BackgroundProcessManagerState = {}));
34556
+
33994
34557
  /***/ }),
33995
34558
 
33996
34559
  /***/ "./lib-esm/Util/Constants.js":
@@ -34325,6 +34888,15 @@ __webpack_require__.r(__webpack_exports__);
34325
34888
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "jitteredBackoff", function() { return jitteredBackoff; });
34326
34889
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "jitteredExponentialRetry", function() { return jitteredExponentialRetry; });
34327
34890
  /* harmony import */ var _Logger_ConsoleLogger__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../Logger/ConsoleLogger */ "./lib-esm/Logger/ConsoleLogger.js");
34891
+ function _typeof(obj) {
34892
+ "@babel/helpers - typeof";
34893
+
34894
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
34895
+ return typeof obj;
34896
+ } : function (obj) {
34897
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
34898
+ }, _typeof(obj);
34899
+ }
34328
34900
  var __extends = undefined && undefined.__extends || function () {
34329
34901
  var _extendStatics = function extendStatics(d, b) {
34330
34902
  _extendStatics = Object.setPrototypeOf || {
@@ -34513,50 +35085,92 @@ var isNonRetryableError = function isNonRetryableError(obj) {
34513
35085
  * @private
34514
35086
  * Internal use of Amplify only
34515
35087
  */
34516
- function retry(functionToRetry, args, delayFn, attempt) {
34517
- if (attempt === void 0) {
34518
- attempt = 1;
34519
- }
35088
+ function retry(functionToRetry, args, delayFn, onTerminate) {
34520
35089
  return __awaiter(this, void 0, void 0, function () {
34521
- var err_1, retryIn_1;
35090
+ var _this = this;
34522
35091
  return __generator(this, function (_a) {
34523
- switch (_a.label) {
34524
- case 0:
34525
- if (typeof functionToRetry !== 'function') {
34526
- throw Error('functionToRetry must be a function');
34527
- }
34528
- logger.debug(functionToRetry.name + " attempt #" + attempt + " with this vars: " + JSON.stringify(args));
34529
- _a.label = 1;
34530
- case 1:
34531
- _a.trys.push([1, 3,, 8]);
34532
- return [4 /*yield*/, functionToRetry.apply(void 0, __spread(args))];
34533
- case 2:
34534
- return [2 /*return*/, _a.sent()];
34535
- case 3:
34536
- err_1 = _a.sent();
34537
- logger.debug("error on " + functionToRetry.name, err_1);
34538
- if (isNonRetryableError(err_1)) {
34539
- logger.debug(functionToRetry.name + " non retryable error", err_1);
34540
- throw err_1;
34541
- }
34542
- retryIn_1 = delayFn(attempt, args, err_1);
34543
- logger.debug(functionToRetry.name + " retrying in " + retryIn_1 + " ms");
34544
- if (!(retryIn_1 !== false)) return [3 /*break*/, 6];
34545
- return [4 /*yield*/, new Promise(function (res) {
34546
- return setTimeout(res, retryIn_1);
34547
- })];
34548
- case 4:
34549
- _a.sent();
34550
- return [4 /*yield*/, retry(functionToRetry, args, delayFn, attempt + 1)];
34551
- case 5:
34552
- return [2 /*return*/, _a.sent()];
34553
- case 6:
34554
- throw err_1;
34555
- case 7:
34556
- return [3 /*break*/, 8];
34557
- case 8:
34558
- return [2 /*return*/];
35092
+ if (typeof functionToRetry !== 'function') {
35093
+ throw Error('functionToRetry must be a function');
34559
35094
  }
35095
+ return [2 /*return*/, new Promise(function (resolve, reject) {
35096
+ return __awaiter(_this, void 0, void 0, function () {
35097
+ var attempt, terminated, timeout, wakeUp, lastError, _loop_1, state_1;
35098
+ return __generator(this, function (_a) {
35099
+ switch (_a.label) {
35100
+ case 0:
35101
+ attempt = 0;
35102
+ terminated = false;
35103
+ wakeUp = function wakeUp() {};
35104
+ onTerminate && onTerminate.then(function () {
35105
+ // signal not to try anymore.
35106
+ terminated = true;
35107
+ // stop sleeping if we're sleeping.
35108
+ clearTimeout(timeout);
35109
+ wakeUp();
35110
+ });
35111
+ _loop_1 = function _loop_1() {
35112
+ var _a, _b, err_1, retryIn_1;
35113
+ return __generator(this, function (_c) {
35114
+ switch (_c.label) {
35115
+ case 0:
35116
+ attempt++;
35117
+ logger.debug(functionToRetry.name + " attempt #" + attempt + " with this vars: " + JSON.stringify(args));
35118
+ _c.label = 1;
35119
+ case 1:
35120
+ _c.trys.push([1, 3,, 7]);
35121
+ _a = {};
35122
+ _b = resolve;
35123
+ return [4 /*yield*/, functionToRetry.apply(void 0, __spread(args))];
35124
+ case 2:
35125
+ return [2 /*return*/, (_a.value = _b.apply(void 0, [_c.sent()]), _a)];
35126
+ case 3:
35127
+ err_1 = _c.sent();
35128
+ lastError = err_1;
35129
+ logger.debug("error on " + functionToRetry.name, err_1);
35130
+ if (isNonRetryableError(err_1)) {
35131
+ logger.debug(functionToRetry.name + " non retryable error", err_1);
35132
+ return [2 /*return*/, {
35133
+ value: reject(err_1)
35134
+ }];
35135
+ }
35136
+ retryIn_1 = delayFn(attempt, args, err_1);
35137
+ logger.debug(functionToRetry.name + " retrying in " + retryIn_1 + " ms");
35138
+ if (!(retryIn_1 === false || terminated)) return [3 /*break*/, 4];
35139
+ return [2 /*return*/, {
35140
+ value: reject(err_1)
35141
+ }];
35142
+ case 4:
35143
+ return [4 /*yield*/, new Promise(function (r) {
35144
+ wakeUp = r; // export wakeUp for onTerminate handling
35145
+ timeout = setTimeout(wakeUp, retryIn_1);
35146
+ })];
35147
+ case 5:
35148
+ _c.sent();
35149
+ _c.label = 6;
35150
+ case 6:
35151
+ return [3 /*break*/, 7];
35152
+ case 7:
35153
+ return [2 /*return*/];
35154
+ }
35155
+ });
35156
+ };
35157
+
35158
+ _a.label = 1;
35159
+ case 1:
35160
+ if (!!terminated) return [3 /*break*/, 3];
35161
+ return [5 /*yield**/, _loop_1()];
35162
+ case 2:
35163
+ state_1 = _a.sent();
35164
+ if (_typeof(state_1) === "object") return [2 /*return*/, state_1.value];
35165
+ return [3 /*break*/, 1];
35166
+ case 3:
35167
+ // reached if terminated while waiting for a timer.
35168
+ reject(lastError);
35169
+ return [2 /*return*/];
35170
+ }
35171
+ });
35172
+ });
35173
+ })];
34560
35174
  });
34561
35175
  });
34562
35176
  }
@@ -34581,11 +35195,11 @@ function jitteredBackoff(maxDelayMs) {
34581
35195
  * @private
34582
35196
  * Internal use of Amplify only
34583
35197
  */
34584
- var jitteredExponentialRetry = function jitteredExponentialRetry(functionToRetry, args, maxDelayMs) {
35198
+ var jitteredExponentialRetry = function jitteredExponentialRetry(functionToRetry, args, maxDelayMs, onTerminate) {
34585
35199
  if (maxDelayMs === void 0) {
34586
35200
  maxDelayMs = MAX_DELAY_MS;
34587
35201
  }
34588
- return retry(functionToRetry, args, jitteredBackoff(maxDelayMs));
35202
+ return retry(functionToRetry, args, jitteredBackoff(maxDelayMs), onTerminate);
34589
35203
  };
34590
35204
 
34591
35205
  /***/ }),
@@ -34618,7 +35232,7 @@ function urlSafeDecode(hex) {
34618
35232
  /*!*******************************!*\
34619
35233
  !*** ./lib-esm/Util/index.js ***!
34620
35234
  \*******************************/
34621
- /*! 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 */
35235
+ /*! 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, BackgroundManagerNotOpenError, BackgroundProcessManagerState */
34622
35236
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
34623
35237
 
34624
35238
  "use strict";
@@ -34661,6 +35275,14 @@ __webpack_require__.r(__webpack_exports__);
34661
35275
 
34662
35276
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RETRY_ERROR_CODES", function() { return _Constants__WEBPACK_IMPORTED_MODULE_5__["RETRY_ERROR_CODES"]; });
34663
35277
 
35278
+ /* harmony import */ var _BackgroundProcessManager__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./BackgroundProcessManager */ "./lib-esm/Util/BackgroundProcessManager.js");
35279
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BackgroundProcessManager", function() { return _BackgroundProcessManager__WEBPACK_IMPORTED_MODULE_6__["BackgroundProcessManager"]; });
35280
+
35281
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BackgroundManagerNotOpenError", function() { return _BackgroundProcessManager__WEBPACK_IMPORTED_MODULE_6__["BackgroundManagerNotOpenError"]; });
35282
+
35283
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BackgroundProcessManagerState", function() { return _BackgroundProcessManager__WEBPACK_IMPORTED_MODULE_6__["BackgroundProcessManagerState"]; });
35284
+
35285
+
34664
35286
 
34665
35287
 
34666
35288
 
@@ -34712,7 +35334,7 @@ var USER_AGENT_HEADER = 'x-amz-user-agent';
34712
35334
  /*!**************************!*\
34713
35335
  !*** ./lib-esm/index.js ***!
34714
35336
  \**************************/
34715
- /*! 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 */
35337
+ /*! 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, BackgroundManagerNotOpenError, BackgroundProcessManagerState, Amplify, default */
34716
35338
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
34717
35339
 
34718
35340
  "use strict";
@@ -34853,6 +35475,12 @@ __webpack_require__.r(__webpack_exports__);
34853
35475
 
34854
35476
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RETRY_ERROR_CODES", function() { return _Util__WEBPACK_IMPORTED_MODULE_18__["RETRY_ERROR_CODES"]; });
34855
35477
 
35478
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BackgroundProcessManager", function() { return _Util__WEBPACK_IMPORTED_MODULE_18__["BackgroundProcessManager"]; });
35479
+
35480
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BackgroundManagerNotOpenError", function() { return _Util__WEBPACK_IMPORTED_MODULE_18__["BackgroundManagerNotOpenError"]; });
35481
+
35482
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "BackgroundProcessManagerState", function() { return _Util__WEBPACK_IMPORTED_MODULE_18__["BackgroundProcessManagerState"]; });
35483
+
34856
35484
  /*
34857
35485
  * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
34858
35486
  *