@aws-amplify/api 4.0.34-cloud-logging.7 → 4.0.34-cloud-logging.8

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.
@@ -10245,17 +10245,12 @@ __webpack_require__.r(__webpack_exports__);
10245
10245
 
10246
10246
  "use strict";
10247
10247
  __webpack_require__.r(__webpack_exports__);
10248
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GRAPHQL_AUTH_MODE", function() { return GRAPHQL_AUTH_MODE; });
10249
10248
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GraphQLAuthError", function() { return GraphQLAuthError; });
10250
- var GRAPHQL_AUTH_MODE;
10249
+ /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @aws-amplify/auth */ "@aws-amplify/auth");
10250
+ /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_0__);
10251
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GRAPHQL_AUTH_MODE", function() { return _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_0__["GRAPHQL_AUTH_MODE"]; });
10252
+
10251
10253
 
10252
- (function (GRAPHQL_AUTH_MODE) {
10253
- GRAPHQL_AUTH_MODE["API_KEY"] = "API_KEY";
10254
- GRAPHQL_AUTH_MODE["AWS_IAM"] = "AWS_IAM";
10255
- GRAPHQL_AUTH_MODE["OPENID_CONNECT"] = "OPENID_CONNECT";
10256
- GRAPHQL_AUTH_MODE["AMAZON_COGNITO_USER_POOLS"] = "AMAZON_COGNITO_USER_POOLS";
10257
- GRAPHQL_AUTH_MODE["AWS_LAMBDA"] = "AWS_LAMBDA";
10258
- })(GRAPHQL_AUTH_MODE || (GRAPHQL_AUTH_MODE = {}));
10259
10254
 
10260
10255
  var GraphQLAuthError;
10261
10256
 
@@ -11713,6 +11708,9 @@ var __spread = undefined && undefined.__spread || function () {
11713
11708
 
11714
11709
 
11715
11710
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["ConsoleLogger"]('AWSAppSyncProvider');
11711
+ /**
11712
+ * @deprecated Unused, all usecases have migrated to AWSAppSyncRealtimeProvider
11713
+ */
11716
11714
 
11717
11715
  var AWSAppSyncProvider =
11718
11716
  /** @class */
@@ -12436,9 +12434,9 @@ function (_super) {
12436
12434
  AWSAppSyncRealTimeProvider.prototype.subscribe = function (_topics, options) {
12437
12435
  var _this = this;
12438
12436
 
12439
- var appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint;
12437
+ var appSyncGraphqlEndpoint = options === null || options === void 0 ? void 0 : options.appSyncGraphqlEndpoint;
12440
12438
  return new zen_observable_ts__WEBPACK_IMPORTED_MODULE_0__["default"](function (observer) {
12441
- if (!appSyncGraphqlEndpoint) {
12439
+ if (!options || !appSyncGraphqlEndpoint) {
12442
12440
  observer.error({
12443
12441
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscribe only available for AWS AppSync endpoint"))]
12444
12442
  });
@@ -12531,19 +12529,22 @@ function (_super) {
12531
12529
  var options = _a.options,
12532
12530
  observer = _a.observer,
12533
12531
  subscriptionId = _a.subscriptionId;
12532
+
12533
+ var _b, _c;
12534
+
12534
12535
  return __awaiter(this, void 0, void 0, function () {
12535
- var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, _b, graphql_headers, _c, additionalHeaders, subscriptionState, data, dataString, headerObj, _d, _e, subscriptionMessage, stringToAWSRealTime, err_2, _f, message, subscriptionFailedCallback_1, _g, subscriptionFailedCallback, subscriptionReadyCallback;
12536
+ var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, _d, graphql_headers, _e, additionalHeaders, subscriptionState, data, dataString, headerObj, _f, _g, subscriptionMessage, stringToAWSRealTime, err_2, message, subscriptionFailedCallback_1, _h, subscriptionFailedCallback, subscriptionReadyCallback;
12536
12537
 
12537
- var _h;
12538
+ var _j;
12538
12539
 
12539
12540
  var _this = this;
12540
12541
 
12541
- return __generator(this, function (_j) {
12542
- switch (_j.label) {
12542
+ return __generator(this, function (_k) {
12543
+ switch (_k.label) {
12543
12544
  case 0:
12544
- appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint, authenticationType = options.authenticationType, query = options.query, variables = options.variables, apiKey = options.apiKey, region = options.region, _b = options.graphql_headers, graphql_headers = _b === void 0 ? function () {
12545
+ appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint, authenticationType = options.authenticationType, query = options.query, variables = options.variables, apiKey = options.apiKey, region = options.region, _d = options.graphql_headers, graphql_headers = _d === void 0 ? function () {
12545
12546
  return {};
12546
- } : _b, _c = options.additionalHeaders, additionalHeaders = _c === void 0 ? {} : _c;
12547
+ } : _d, _e = options.additionalHeaders, additionalHeaders = _e === void 0 ? {} : _e;
12547
12548
  subscriptionState = SUBSCRIPTION_STATUS.PENDING;
12548
12549
  data = {
12549
12550
  query: query,
@@ -12552,13 +12553,13 @@ function (_super) {
12552
12553
 
12553
12554
  this.subscriptionObserverMap.set(subscriptionId, {
12554
12555
  observer: observer,
12555
- query: query,
12556
- variables: variables,
12556
+ query: query !== null && query !== void 0 ? query : '',
12557
+ variables: variables !== null && variables !== void 0 ? variables : {},
12557
12558
  subscriptionState: subscriptionState,
12558
- startAckTimeoutId: null
12559
+ startAckTimeoutId: undefined
12559
12560
  });
12560
12561
  dataString = JSON.stringify(data);
12561
- _d = [{}];
12562
+ _f = [{}];
12562
12563
  return [4
12563
12564
  /*yield*/
12564
12565
  , this._awsRealTimeHeaderBasedAuth({
@@ -12572,13 +12573,13 @@ function (_super) {
12572
12573
  })];
12573
12574
 
12574
12575
  case 1:
12575
- _e = [__assign.apply(void 0, _d.concat([_j.sent()]))];
12576
+ _g = [__assign.apply(void 0, _f.concat([_k.sent()]))];
12576
12577
  return [4
12577
12578
  /*yield*/
12578
12579
  , graphql_headers()];
12579
12580
 
12580
12581
  case 2:
12581
- headerObj = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _e.concat([_j.sent()])), additionalHeaders]), (_h = {}, _h[_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["USER_AGENT_HEADER"]] = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Constants"].userAgent, _h)]);
12582
+ headerObj = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _g.concat([_k.sent()])), additionalHeaders]), (_j = {}, _j[_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["USER_AGENT_HEADER"]] = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Constants"].userAgent, _j)]);
12582
12583
  subscriptionMessage = {
12583
12584
  id: subscriptionId,
12584
12585
  payload: {
@@ -12590,10 +12591,10 @@ function (_super) {
12590
12591
  type: MESSAGE_TYPES.GQL_START
12591
12592
  };
12592
12593
  stringToAWSRealTime = JSON.stringify(subscriptionMessage);
12593
- _j.label = 3;
12594
+ _k.label = 3;
12594
12595
 
12595
12596
  case 3:
12596
- _j.trys.push([3, 5,, 6]);
12597
+ _k.trys.push([3, 5,, 6]);
12597
12598
 
12598
12599
  return [4
12599
12600
  /*yield*/
@@ -12606,18 +12607,18 @@ function (_super) {
12606
12607
  })];
12607
12608
 
12608
12609
  case 4:
12609
- _j.sent();
12610
+ _k.sent();
12610
12611
 
12611
12612
  return [3
12612
12613
  /*break*/
12613
12614
  , 6];
12614
12615
 
12615
12616
  case 5:
12616
- err_2 = _j.sent();
12617
+ err_2 = _k.sent();
12617
12618
  logger.debug({
12618
12619
  err: err_2
12619
12620
  });
12620
- _f = err_2.message, message = _f === void 0 ? '' : _f;
12621
+ message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
12621
12622
  observer.error({
12622
12623
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
12623
12624
  });
@@ -12633,13 +12634,13 @@ function (_super) {
12633
12634
  ];
12634
12635
 
12635
12636
  case 6:
12636
- _g = this.subscriptionObserverMap.get(subscriptionId), subscriptionFailedCallback = _g.subscriptionFailedCallback, subscriptionReadyCallback = _g.subscriptionReadyCallback; // This must be done before sending the message in order to be listening immediately
12637
+ _h = (_c = this.subscriptionObserverMap.get(subscriptionId)) !== null && _c !== void 0 ? _c : {}, subscriptionFailedCallback = _h.subscriptionFailedCallback, subscriptionReadyCallback = _h.subscriptionReadyCallback; // This must be done before sending the message in order to be listening immediately
12637
12638
 
12638
12639
  this.subscriptionObserverMap.set(subscriptionId, {
12639
12640
  observer: observer,
12640
12641
  subscriptionState: subscriptionState,
12641
- variables: variables,
12642
- query: query,
12642
+ query: query !== null && query !== void 0 ? query : '',
12643
+ variables: variables !== null && variables !== void 0 ? variables : {},
12643
12644
  subscriptionReadyCallback: subscriptionReadyCallback,
12644
12645
  subscriptionFailedCallback: subscriptionFailedCallback,
12645
12646
  startAckTimeoutId: setTimeout(function () {
@@ -12662,32 +12663,35 @@ function (_super) {
12662
12663
 
12663
12664
  AWSAppSyncRealTimeProvider.prototype._waitForSubscriptionToBeConnected = function (subscriptionId) {
12664
12665
  return __awaiter(this, void 0, void 0, function () {
12665
- var subscriptionState;
12666
+ var subscriptionObserver, subscriptionState;
12666
12667
 
12667
12668
  var _this = this;
12668
12669
 
12669
12670
  return __generator(this, function (_a) {
12670
- subscriptionState = this.subscriptionObserverMap.get(subscriptionId).subscriptionState; // This in case unsubscribe is invoked before sending start subscription message
12671
+ subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
12671
12672
 
12672
- if (subscriptionState === SUBSCRIPTION_STATUS.PENDING) {
12673
- return [2
12674
- /*return*/
12675
- , new Promise(function (res, rej) {
12676
- var _a = _this.subscriptionObserverMap.get(subscriptionId),
12677
- observer = _a.observer,
12678
- subscriptionState = _a.subscriptionState,
12679
- variables = _a.variables,
12680
- query = _a.query;
12681
-
12682
- _this.subscriptionObserverMap.set(subscriptionId, {
12683
- observer: observer,
12684
- subscriptionState: subscriptionState,
12685
- variables: variables,
12686
- query: query,
12687
- subscriptionReadyCallback: res,
12688
- subscriptionFailedCallback: rej
12689
- });
12690
- })];
12673
+ if (subscriptionObserver) {
12674
+ subscriptionState = subscriptionObserver.subscriptionState; // This in case unsubscribe is invoked before sending start subscription message
12675
+
12676
+ if (subscriptionState === SUBSCRIPTION_STATUS.PENDING) {
12677
+ return [2
12678
+ /*return*/
12679
+ , new Promise(function (res, rej) {
12680
+ var observer = subscriptionObserver.observer,
12681
+ subscriptionState = subscriptionObserver.subscriptionState,
12682
+ variables = subscriptionObserver.variables,
12683
+ query = subscriptionObserver.query;
12684
+
12685
+ _this.subscriptionObserverMap.set(subscriptionId, {
12686
+ observer: observer,
12687
+ subscriptionState: subscriptionState,
12688
+ variables: variables,
12689
+ query: query,
12690
+ subscriptionReadyCallback: res,
12691
+ subscriptionFailedCallback: rej
12692
+ });
12693
+ })];
12694
+ }
12691
12695
  }
12692
12696
 
12693
12697
  return [2
@@ -12738,13 +12742,13 @@ function (_super) {
12738
12742
  setTimeout(this._closeSocketIfRequired.bind(this), 1000);
12739
12743
  } else {
12740
12744
  logger.debug('closing WebSocket...');
12741
- clearTimeout(this.keepAliveTimeoutId);
12745
+ if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
12742
12746
  var tempSocket = this.awsRealTimeSocket; // Cleaning callbacks to avoid race condition, socket still exists
12743
12747
 
12744
- tempSocket.onclose = undefined;
12745
- tempSocket.onerror = undefined;
12748
+ tempSocket.onclose = null;
12749
+ tempSocket.onerror = null;
12746
12750
  tempSocket.close(1000);
12747
- this.awsRealTimeSocket = null;
12751
+ this.awsRealTimeSocket = undefined;
12748
12752
  this.socketStatus = SOCKET_STATUS.CLOSED;
12749
12753
  }
12750
12754
  };
@@ -12809,50 +12813,57 @@ function (_super) {
12809
12813
  subscriptionReadyCallback();
12810
12814
  }
12811
12815
 
12812
- clearTimeout(startAckTimeoutId);
12816
+ if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
12813
12817
  dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].SUBSCRIPTION_ACK, {
12814
12818
  query: query,
12815
12819
  variables: variables
12816
12820
  }, 'Connection established for subscription');
12817
12821
  var subscriptionState = SUBSCRIPTION_STATUS.CONNECTED;
12818
- this.subscriptionObserverMap.set(id, {
12819
- observer: observer,
12820
- query: query,
12821
- variables: variables,
12822
- startAckTimeoutId: null,
12823
- subscriptionState: subscriptionState,
12824
- subscriptionReadyCallback: subscriptionReadyCallback,
12825
- subscriptionFailedCallback: subscriptionFailedCallback
12826
- }); // TODO: emit event on hub but it requires to store the id first
12822
+
12823
+ if (observer) {
12824
+ this.subscriptionObserverMap.set(id, {
12825
+ observer: observer,
12826
+ query: query,
12827
+ variables: variables,
12828
+ startAckTimeoutId: undefined,
12829
+ subscriptionState: subscriptionState,
12830
+ subscriptionReadyCallback: subscriptionReadyCallback,
12831
+ subscriptionFailedCallback: subscriptionFailedCallback
12832
+ });
12833
+ } // TODO: emit event on hub but it requires to store the id first
12834
+
12827
12835
 
12828
12836
  return;
12829
12837
  }
12830
12838
 
12831
12839
  if (type === MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) {
12832
- clearTimeout(this.keepAliveTimeoutId);
12840
+ if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
12833
12841
  this.keepAliveTimeoutId = setTimeout(this._errorDisconnect.bind(this, _index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT), this.keepAliveTimeout);
12834
12842
  return;
12835
12843
  }
12836
12844
 
12837
12845
  if (type === MESSAGE_TYPES.GQL_ERROR) {
12838
12846
  var subscriptionState = SUBSCRIPTION_STATUS.FAILED;
12839
- this.subscriptionObserverMap.set(id, {
12840
- observer: observer,
12841
- query: query,
12842
- variables: variables,
12843
- startAckTimeoutId: startAckTimeoutId,
12844
- subscriptionReadyCallback: subscriptionReadyCallback,
12845
- subscriptionFailedCallback: subscriptionFailedCallback,
12846
- subscriptionState: subscriptionState
12847
- });
12848
- observer.error({
12849
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
12850
- });
12851
- clearTimeout(startAckTimeoutId);
12852
- observer.complete();
12853
12847
 
12854
- if (typeof subscriptionFailedCallback === 'function') {
12855
- subscriptionFailedCallback();
12848
+ if (observer) {
12849
+ this.subscriptionObserverMap.set(id, {
12850
+ observer: observer,
12851
+ query: query,
12852
+ variables: variables,
12853
+ startAckTimeoutId: startAckTimeoutId,
12854
+ subscriptionReadyCallback: subscriptionReadyCallback,
12855
+ subscriptionFailedCallback: subscriptionFailedCallback,
12856
+ subscriptionState: subscriptionState
12857
+ });
12858
+ observer.error({
12859
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
12860
+ });
12861
+ if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
12862
+ observer.complete();
12863
+
12864
+ if (typeof subscriptionFailedCallback === 'function') {
12865
+ subscriptionFailedCallback();
12866
+ }
12856
12867
  }
12857
12868
  }
12858
12869
  };
@@ -12878,37 +12889,40 @@ function (_super) {
12878
12889
  };
12879
12890
 
12880
12891
  AWSAppSyncRealTimeProvider.prototype._timeoutStartSubscriptionAck = function (subscriptionId) {
12881
- var _a = this.subscriptionObserverMap.get(subscriptionId) || {},
12882
- observer = _a.observer,
12883
- query = _a.query,
12884
- variables = _a.variables;
12892
+ var subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
12885
12893
 
12886
- if (!observer) {
12887
- return;
12888
- }
12894
+ if (subscriptionObserver) {
12895
+ var observer = subscriptionObserver.observer,
12896
+ query = subscriptionObserver.query,
12897
+ variables = subscriptionObserver.variables;
12889
12898
 
12890
- this.subscriptionObserverMap.set(subscriptionId, {
12891
- observer: observer,
12892
- query: query,
12893
- variables: variables,
12894
- subscriptionState: SUBSCRIPTION_STATUS.FAILED
12895
- });
12899
+ if (!observer) {
12900
+ return;
12901
+ }
12896
12902
 
12897
- if (observer && !observer.closed) {
12898
- observer.error({
12899
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscription timeout " + JSON.stringify({
12900
- query: query,
12901
- variables: variables
12902
- })))]
12903
- }); // Cleanup will be automatically executed
12903
+ this.subscriptionObserverMap.set(subscriptionId, {
12904
+ observer: observer,
12905
+ query: query,
12906
+ variables: variables,
12907
+ subscriptionState: SUBSCRIPTION_STATUS.FAILED
12908
+ });
12904
12909
 
12905
- observer.complete();
12906
- }
12910
+ if (observer && !observer.closed) {
12911
+ observer.error({
12912
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscription timeout " + JSON.stringify({
12913
+ query: query,
12914
+ variables: variables
12915
+ })))]
12916
+ }); // Cleanup will be automatically executed
12907
12917
 
12908
- logger.debug('timeoutStartSubscription', JSON.stringify({
12909
- query: query,
12910
- variables: variables
12911
- }));
12918
+ observer.complete();
12919
+ }
12920
+
12921
+ logger.debug('timeoutStartSubscription', JSON.stringify({
12922
+ query: query,
12923
+ variables: variables
12924
+ }));
12925
+ }
12912
12926
  };
12913
12927
 
12914
12928
  AWSAppSyncRealTimeProvider.prototype._initializeWebSocketConnection = function (_a) {
@@ -12962,7 +12976,7 @@ function (_super) {
12962
12976
  headerString = _b.apply(_a, [_c.sent()]);
12963
12977
  headerQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(headerString).toString('base64');
12964
12978
  payloadQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(payloadString).toString('base64');
12965
- discoverableEndpoint = appSyncGraphqlEndpoint;
12979
+ discoverableEndpoint = appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '';
12966
12980
 
12967
12981
  if (this.isCustomDomain(discoverableEndpoint)) {
12968
12982
  discoverableEndpoint = discoverableEndpoint.concat(customDomainPath);
@@ -12975,9 +12989,7 @@ function (_super) {
12975
12989
  awsRealTimeUrl = discoverableEndpoint + "?header=" + headerQs + "&payload=" + payloadQs;
12976
12990
  return [4
12977
12991
  /*yield*/
12978
- , this._initializeRetryableHandshake({
12979
- awsRealTimeUrl: awsRealTimeUrl
12980
- })];
12992
+ , this._initializeRetryableHandshake(awsRealTimeUrl)];
12981
12993
 
12982
12994
  case 3:
12983
12995
  _c.sent();
@@ -13005,7 +13017,7 @@ function (_super) {
13005
13017
  this.awsRealTimeSocket.close(3001);
13006
13018
  }
13007
13019
 
13008
- this.awsRealTimeSocket = null;
13020
+ this.awsRealTimeSocket = undefined;
13009
13021
  this.socketStatus = SOCKET_STATUS.CLOSED;
13010
13022
  return [3
13011
13023
  /*break*/
@@ -13021,21 +13033,18 @@ function (_super) {
13021
13033
  });
13022
13034
  };
13023
13035
 
13024
- AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (_a) {
13025
- var awsRealTimeUrl = _a.awsRealTimeUrl;
13036
+ AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (awsRealTimeUrl) {
13026
13037
  return __awaiter(this, void 0, void 0, function () {
13027
- return __generator(this, function (_b) {
13028
- switch (_b.label) {
13038
+ return __generator(this, function (_a) {
13039
+ switch (_a.label) {
13029
13040
  case 0:
13030
13041
  logger.debug("Initializaling retryable Handshake");
13031
13042
  return [4
13032
13043
  /*yield*/
13033
- , Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [{
13034
- awsRealTimeUrl: awsRealTimeUrl
13035
- }], MAX_DELAY_MS)];
13044
+ , Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [awsRealTimeUrl], MAX_DELAY_MS)];
13036
13045
 
13037
13046
  case 1:
13038
- _b.sent();
13047
+ _a.sent();
13039
13048
 
13040
13049
  return [2
13041
13050
  /*return*/
@@ -13045,10 +13054,9 @@ function (_super) {
13045
13054
  });
13046
13055
  };
13047
13056
 
13048
- AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (_a) {
13049
- var awsRealTimeUrl = _a.awsRealTimeUrl;
13057
+ AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (awsRealTimeUrl) {
13050
13058
  return __awaiter(this, void 0, void 0, function () {
13051
- var err_4, errorType, errorCode;
13059
+ var err_4, _a, errorType, errorCode;
13052
13060
 
13053
13061
  var _this = this;
13054
13062
 
@@ -13090,77 +13098,82 @@ function (_super) {
13090
13098
  /*yield*/
13091
13099
  , function () {
13092
13100
  return new Promise(function (res, rej) {
13093
- var ackOk = false;
13101
+ if (_this.awsRealTimeSocket) {
13102
+ var ackOk_1 = false;
13094
13103
 
13095
- _this.awsRealTimeSocket.onerror = function (error) {
13096
- logger.debug("WebSocket error " + JSON.stringify(error));
13097
- };
13104
+ _this.awsRealTimeSocket.onerror = function (error) {
13105
+ logger.debug("WebSocket error " + JSON.stringify(error));
13106
+ };
13098
13107
 
13099
- _this.awsRealTimeSocket.onclose = function (event) {
13100
- logger.debug("WebSocket closed " + event.reason);
13101
- rej(new Error(JSON.stringify(event)));
13102
- };
13108
+ _this.awsRealTimeSocket.onclose = function (event) {
13109
+ logger.debug("WebSocket closed " + event.reason);
13110
+ rej(new Error(JSON.stringify(event)));
13111
+ };
13103
13112
 
13104
- _this.awsRealTimeSocket.onmessage = function (message) {
13105
- logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
13106
- var data = JSON.parse(message.data);
13107
- var type = data.type,
13108
- _a = data.payload,
13109
- _b = (_a === void 0 ? {} : _a).connectionTimeoutMs,
13110
- connectionTimeoutMs = _b === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _b;
13113
+ _this.awsRealTimeSocket.onmessage = function (message) {
13114
+ logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
13115
+ var data = JSON.parse(message.data);
13116
+ var type = data.type,
13117
+ _a = data.payload,
13118
+ _b = (_a === void 0 ? {} : _a).connectionTimeoutMs,
13119
+ connectionTimeoutMs = _b === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _b;
13111
13120
 
13112
- if (type === MESSAGE_TYPES.GQL_CONNECTION_ACK) {
13113
- ackOk = true;
13114
- _this.keepAliveTimeout = connectionTimeoutMs;
13115
- _this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
13121
+ if (type === MESSAGE_TYPES.GQL_CONNECTION_ACK) {
13122
+ ackOk_1 = true;
13116
13123
 
13117
- _this.awsRealTimeSocket.onerror = function (err) {
13118
- logger.debug(err);
13124
+ if (_this.awsRealTimeSocket) {
13125
+ _this.keepAliveTimeout = connectionTimeoutMs;
13126
+ _this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
13119
13127
 
13120
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
13121
- };
13128
+ _this.awsRealTimeSocket.onerror = function (err) {
13129
+ logger.debug(err);
13122
13130
 
13123
- _this.awsRealTimeSocket.onclose = function (event) {
13124
- logger.debug("WebSocket closed " + event.reason);
13131
+ _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
13132
+ };
13125
13133
 
13126
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
13127
- };
13134
+ _this.awsRealTimeSocket.onclose = function (event) {
13135
+ logger.debug("WebSocket closed " + event.reason);
13128
13136
 
13129
- res('Cool, connected to AWS AppSyncRealTime');
13130
- return;
13131
- }
13137
+ _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
13138
+ };
13139
+ }
13132
13140
 
13133
- if (type === MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
13134
- var _c = data.payload,
13135
- _d = (_c === void 0 ? {} : _c).errors,
13136
- _e = __read(_d === void 0 ? [] : _d, 1),
13137
- _f = _e[0],
13138
- _g = _f === void 0 ? {} : _f,
13139
- _h = _g.errorType,
13140
- errorType = _h === void 0 ? '' : _h,
13141
- _j = _g.errorCode,
13142
- errorCode = _j === void 0 ? 0 : _j;
13143
-
13144
- rej({
13145
- errorType: errorType,
13146
- errorCode: errorCode
13147
- });
13148
- }
13149
- };
13141
+ res('Cool, connected to AWS AppSyncRealTime');
13142
+ return;
13143
+ }
13150
13144
 
13151
- var gqlInit = {
13152
- type: MESSAGE_TYPES.GQL_CONNECTION_INIT
13153
- };
13145
+ if (type === MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
13146
+ var _c = data.payload,
13147
+ _d = (_c === void 0 ? {} : _c).errors,
13148
+ _e = __read(_d === void 0 ? [] : _d, 1),
13149
+ _f = _e[0],
13150
+ _g = _f === void 0 ? {} : _f,
13151
+ _h = _g.errorType,
13152
+ errorType = _h === void 0 ? '' : _h,
13153
+ _j = _g.errorCode,
13154
+ errorCode = _j === void 0 ? 0 : _j;
13155
+
13156
+ rej({
13157
+ errorType: errorType,
13158
+ errorCode: errorCode
13159
+ });
13160
+ }
13161
+ };
13162
+
13163
+ var gqlInit = {
13164
+ type: MESSAGE_TYPES.GQL_CONNECTION_INIT
13165
+ };
13154
13166
 
13155
- _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
13167
+ _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
13156
13168
 
13157
- function checkAckOk() {
13169
+ setTimeout(checkAckOk.bind(_this, ackOk_1), CONNECTION_INIT_TIMEOUT);
13170
+ }
13171
+
13172
+ function checkAckOk(ackOk) {
13158
13173
  if (!ackOk) {
13159
13174
  rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + CONNECTION_INIT_TIMEOUT + " ms"));
13160
13175
  }
13161
13176
  }
13162
-
13163
- setTimeout(checkAckOk.bind(_this), CONNECTION_INIT_TIMEOUT);
13164
13177
  });
13165
13178
  }()];
13166
13179
 
@@ -13174,7 +13187,7 @@ function (_super) {
13174
13187
 
13175
13188
  case 4:
13176
13189
  err_4 = _b.sent();
13177
- errorType = err_4.errorType, errorCode = err_4.errorCode;
13190
+ _a = err_4, errorType = _a.errorType, errorCode = _a.errorCode;
13178
13191
 
13179
13192
  if (NON_RETRYABLE_CODES.includes(errorCode)) {
13180
13193
  throw new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["NonRetryableError"](errorType);
@@ -13217,16 +13230,17 @@ function (_super) {
13217
13230
  AMAZON_COGNITO_USER_POOLS: this._awsRealTimeCUPHeader.bind(this),
13218
13231
  AWS_LAMBDA: this._customAuthHeader
13219
13232
  };
13220
- handler = headerHandler[authenticationType];
13221
-
13222
- if (typeof handler !== 'function') {
13223
- logger.debug("Authentication type " + authenticationType + " not supported");
13224
- return [2
13225
- /*return*/
13226
- , ''];
13227
- }
13233
+ if (!(!authenticationType || !headerHandler[authenticationType])) return [3
13234
+ /*break*/
13235
+ , 1];
13236
+ logger.debug("Authentication type " + authenticationType + " not supported");
13237
+ return [2
13238
+ /*return*/
13239
+ , ''];
13228
13240
 
13229
- host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint).host;
13241
+ case 1:
13242
+ handler = headerHandler[authenticationType];
13243
+ host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
13230
13244
  return [4
13231
13245
  /*yield*/
13232
13246
  , handler({
@@ -13239,7 +13253,7 @@ function (_super) {
13239
13253
  additionalHeaders: additionalHeaders
13240
13254
  })];
13241
13255
 
13242
- case 1:
13256
+ case 2:
13243
13257
  result = _b.sent();
13244
13258
  return [2
13245
13259
  /*return*/
@@ -13371,10 +13385,14 @@ function (_super) {
13371
13385
  return [4
13372
13386
  /*yield*/
13373
13387
  , _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Credentials"].get().then(function (credentials) {
13388
+ var _a = credentials,
13389
+ secretAccessKey = _a.secretAccessKey,
13390
+ accessKeyId = _a.accessKeyId,
13391
+ sessionToken = _a.sessionToken;
13374
13392
  return {
13375
- secret_key: credentials.secretAccessKey,
13376
- access_key: credentials.accessKeyId,
13377
- session_token: credentials.sessionToken
13393
+ secret_key: secretAccessKey,
13394
+ access_key: accessKeyId,
13395
+ session_token: sessionToken
13378
13396
  };
13379
13397
  })];
13380
13398
 
@@ -13399,7 +13417,7 @@ function (_super) {
13399
13417
  var host = _a.host,
13400
13418
  additionalHeaders = _a.additionalHeaders;
13401
13419
 
13402
- if (!additionalHeaders.Authorization) {
13420
+ if (!additionalHeaders || !additionalHeaders['Authorization']) {
13403
13421
  throw new Error('No auth token specified');
13404
13422
  }
13405
13423
 
@@ -13636,8 +13654,12 @@ var AWSIoTProvider =
13636
13654
  function (_super) {
13637
13655
  __extends(AWSIoTProvider, _super);
13638
13656
 
13639
- function AWSIoTProvider() {
13640
- return _super !== null && _super.apply(this, arguments) || this;
13657
+ function AWSIoTProvider(options) {
13658
+ if (options === void 0) {
13659
+ options = {};
13660
+ }
13661
+
13662
+ return _super.call(this, options) || this;
13641
13663
  }
13642
13664
 
13643
13665
  Object.defineProperty(AWSIoTProvider.prototype, "region", {
@@ -13967,21 +13989,27 @@ function () {
13967
13989
 
13968
13990
  ClientsQueue.prototype.get = function (clientId, clientFactory) {
13969
13991
  return __awaiter(this, void 0, void 0, function () {
13970
- var promise;
13992
+ var cachedPromise, newPromise;
13971
13993
  return __generator(this, function (_a) {
13972
- promise = this.promises.get(clientId);
13994
+ cachedPromise = this.promises.get(clientId);
13973
13995
 
13974
- if (promise) {
13996
+ if (cachedPromise) {
13975
13997
  return [2
13976
13998
  /*return*/
13977
- , promise];
13999
+ , cachedPromise];
14000
+ }
14001
+
14002
+ if (clientFactory) {
14003
+ newPromise = clientFactory(clientId);
14004
+ this.promises.set(clientId, newPromise);
14005
+ return [2
14006
+ /*return*/
14007
+ , newPromise];
13978
14008
  }
13979
14009
 
13980
- promise = clientFactory(clientId);
13981
- this.promises.set(clientId, promise);
13982
14010
  return [2
13983
14011
  /*return*/
13984
- , promise];
14012
+ , undefined];
13985
14013
  });
13986
14014
  });
13987
14015
  };
@@ -14073,6 +14101,10 @@ function (_super) {
14073
14101
  }, args), null, 2));
14074
14102
  var topicsToDelete_1 = [];
14075
14103
 
14104
+ if (!clientId) {
14105
+ return;
14106
+ }
14107
+
14076
14108
  var clientIdObservers = this._clientIdObservers.get(clientId);
14077
14109
 
14078
14110
  if (!clientIdObservers) {
@@ -14191,9 +14223,7 @@ function (_super) {
14191
14223
  case 0:
14192
14224
  return [4
14193
14225
  /*yield*/
14194
- , this.clientsQueue.get(clientId, function () {
14195
- return null;
14196
- })];
14226
+ , this.clientsQueue.get(clientId)];
14197
14227
 
14198
14228
  case 1:
14199
14229
  client = _a.sent();
@@ -14372,13 +14402,14 @@ function (_super) {
14372
14402
  })();
14373
14403
 
14374
14404
  return function () {
14405
+ var _a, _b;
14406
+
14375
14407
  logger.debug('Unsubscribing from topic(s)', targetTopics.join(','));
14376
14408
 
14377
14409
  if (client) {
14378
- _this._clientIdObservers.get(clientId)["delete"](observer); // No more observers per client => client not needed anymore
14379
-
14410
+ (_a = _this._clientIdObservers.get(clientId)) === null || _a === void 0 ? void 0 : _a["delete"](observer); // No more observers per client => client not needed anymore
14380
14411
 
14381
- if (_this._clientIdObservers.get(clientId).size === 0) {
14412
+ if (((_b = _this._clientIdObservers.get(clientId)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
14382
14413
  _this.disconnect(clientId);
14383
14414
 
14384
14415
  _this._clientIdObservers["delete"](clientId);
@@ -14713,7 +14744,7 @@ function () {
14713
14744
  * @param {PubSubOptions} options - Configuration object for PubSub
14714
14745
  */
14715
14746
  function PubSubClass(options) {
14716
- this._options = options;
14747
+ this._options = options !== null && options !== void 0 ? options : {};
14717
14748
  logger.debug('PubSub Options', this._options);
14718
14749
  this._pluggables = [];
14719
14750
  this.subscribe = this.subscribe.bind(this);
@@ -14902,7 +14933,7 @@ function () {
14902
14933
  }();
14903
14934
 
14904
14935
 
14905
- var PubSub = new PubSubClass(null);
14936
+ var PubSub = new PubSubClass();
14906
14937
  _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Amplify"].register(PubSub);
14907
14938
 
14908
14939
  /***/ }),