@aws-amplify/api 4.0.38-unstable.1 → 4.0.38-unstable.3

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.
@@ -12434,9 +12434,9 @@ function (_super) {
12434
12434
  AWSAppSyncRealTimeProvider.prototype.subscribe = function (_topics, options) {
12435
12435
  var _this = this;
12436
12436
 
12437
- var appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint;
12437
+ var appSyncGraphqlEndpoint = options === null || options === void 0 ? void 0 : options.appSyncGraphqlEndpoint;
12438
12438
  return new zen_observable_ts__WEBPACK_IMPORTED_MODULE_0__["default"](function (observer) {
12439
- if (!appSyncGraphqlEndpoint) {
12439
+ if (!options || !appSyncGraphqlEndpoint) {
12440
12440
  observer.error({
12441
12441
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscribe only available for AWS AppSync endpoint"))]
12442
12442
  });
@@ -12529,19 +12529,22 @@ function (_super) {
12529
12529
  var options = _a.options,
12530
12530
  observer = _a.observer,
12531
12531
  subscriptionId = _a.subscriptionId;
12532
+
12533
+ var _b, _c;
12534
+
12532
12535
  return __awaiter(this, void 0, void 0, function () {
12533
- 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;
12534
12537
 
12535
- var _h;
12538
+ var _j;
12536
12539
 
12537
12540
  var _this = this;
12538
12541
 
12539
- return __generator(this, function (_j) {
12540
- switch (_j.label) {
12542
+ return __generator(this, function (_k) {
12543
+ switch (_k.label) {
12541
12544
  case 0:
12542
- 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 () {
12543
12546
  return {};
12544
- } : _b, _c = options.additionalHeaders, additionalHeaders = _c === void 0 ? {} : _c;
12547
+ } : _d, _e = options.additionalHeaders, additionalHeaders = _e === void 0 ? {} : _e;
12545
12548
  subscriptionState = SUBSCRIPTION_STATUS.PENDING;
12546
12549
  data = {
12547
12550
  query: query,
@@ -12550,13 +12553,13 @@ function (_super) {
12550
12553
 
12551
12554
  this.subscriptionObserverMap.set(subscriptionId, {
12552
12555
  observer: observer,
12553
- query: query,
12554
- variables: variables,
12556
+ query: query !== null && query !== void 0 ? query : '',
12557
+ variables: variables !== null && variables !== void 0 ? variables : {},
12555
12558
  subscriptionState: subscriptionState,
12556
- startAckTimeoutId: null
12559
+ startAckTimeoutId: undefined
12557
12560
  });
12558
12561
  dataString = JSON.stringify(data);
12559
- _d = [{}];
12562
+ _f = [{}];
12560
12563
  return [4
12561
12564
  /*yield*/
12562
12565
  , this._awsRealTimeHeaderBasedAuth({
@@ -12570,13 +12573,13 @@ function (_super) {
12570
12573
  })];
12571
12574
 
12572
12575
  case 1:
12573
- _e = [__assign.apply(void 0, _d.concat([_j.sent()]))];
12576
+ _g = [__assign.apply(void 0, _f.concat([_k.sent()]))];
12574
12577
  return [4
12575
12578
  /*yield*/
12576
12579
  , graphql_headers()];
12577
12580
 
12578
12581
  case 2:
12579
- 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)]);
12580
12583
  subscriptionMessage = {
12581
12584
  id: subscriptionId,
12582
12585
  payload: {
@@ -12588,10 +12591,10 @@ function (_super) {
12588
12591
  type: MESSAGE_TYPES.GQL_START
12589
12592
  };
12590
12593
  stringToAWSRealTime = JSON.stringify(subscriptionMessage);
12591
- _j.label = 3;
12594
+ _k.label = 3;
12592
12595
 
12593
12596
  case 3:
12594
- _j.trys.push([3, 5,, 6]);
12597
+ _k.trys.push([3, 5,, 6]);
12595
12598
 
12596
12599
  return [4
12597
12600
  /*yield*/
@@ -12604,18 +12607,18 @@ function (_super) {
12604
12607
  })];
12605
12608
 
12606
12609
  case 4:
12607
- _j.sent();
12610
+ _k.sent();
12608
12611
 
12609
12612
  return [3
12610
12613
  /*break*/
12611
12614
  , 6];
12612
12615
 
12613
12616
  case 5:
12614
- err_2 = _j.sent();
12617
+ err_2 = _k.sent();
12615
12618
  logger.debug({
12616
12619
  err: err_2
12617
12620
  });
12618
- _f = err_2.message, message = _f === void 0 ? '' : _f;
12621
+ message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
12619
12622
  observer.error({
12620
12623
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
12621
12624
  });
@@ -12631,13 +12634,13 @@ function (_super) {
12631
12634
  ];
12632
12635
 
12633
12636
  case 6:
12634
- _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
12635
12638
 
12636
12639
  this.subscriptionObserverMap.set(subscriptionId, {
12637
12640
  observer: observer,
12638
12641
  subscriptionState: subscriptionState,
12639
- variables: variables,
12640
- query: query,
12642
+ query: query !== null && query !== void 0 ? query : '',
12643
+ variables: variables !== null && variables !== void 0 ? variables : {},
12641
12644
  subscriptionReadyCallback: subscriptionReadyCallback,
12642
12645
  subscriptionFailedCallback: subscriptionFailedCallback,
12643
12646
  startAckTimeoutId: setTimeout(function () {
@@ -12660,32 +12663,35 @@ function (_super) {
12660
12663
 
12661
12664
  AWSAppSyncRealTimeProvider.prototype._waitForSubscriptionToBeConnected = function (subscriptionId) {
12662
12665
  return __awaiter(this, void 0, void 0, function () {
12663
- var subscriptionState;
12666
+ var subscriptionObserver, subscriptionState;
12664
12667
 
12665
12668
  var _this = this;
12666
12669
 
12667
12670
  return __generator(this, function (_a) {
12668
- subscriptionState = this.subscriptionObserverMap.get(subscriptionId).subscriptionState; // This in case unsubscribe is invoked before sending start subscription message
12671
+ subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
12669
12672
 
12670
- if (subscriptionState === SUBSCRIPTION_STATUS.PENDING) {
12671
- return [2
12672
- /*return*/
12673
- , new Promise(function (res, rej) {
12674
- var _a = _this.subscriptionObserverMap.get(subscriptionId),
12675
- observer = _a.observer,
12676
- subscriptionState = _a.subscriptionState,
12677
- variables = _a.variables,
12678
- query = _a.query;
12679
-
12680
- _this.subscriptionObserverMap.set(subscriptionId, {
12681
- observer: observer,
12682
- subscriptionState: subscriptionState,
12683
- variables: variables,
12684
- query: query,
12685
- subscriptionReadyCallback: res,
12686
- subscriptionFailedCallback: rej
12687
- });
12688
- })];
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
+ }
12689
12695
  }
12690
12696
 
12691
12697
  return [2
@@ -12736,13 +12742,13 @@ function (_super) {
12736
12742
  setTimeout(this._closeSocketIfRequired.bind(this), 1000);
12737
12743
  } else {
12738
12744
  logger.debug('closing WebSocket...');
12739
- clearTimeout(this.keepAliveTimeoutId);
12745
+ if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
12740
12746
  var tempSocket = this.awsRealTimeSocket; // Cleaning callbacks to avoid race condition, socket still exists
12741
12747
 
12742
- tempSocket.onclose = undefined;
12743
- tempSocket.onerror = undefined;
12748
+ tempSocket.onclose = null;
12749
+ tempSocket.onerror = null;
12744
12750
  tempSocket.close(1000);
12745
- this.awsRealTimeSocket = null;
12751
+ this.awsRealTimeSocket = undefined;
12746
12752
  this.socketStatus = SOCKET_STATUS.CLOSED;
12747
12753
  }
12748
12754
  };
@@ -12794,50 +12800,57 @@ function (_super) {
12794
12800
  subscriptionReadyCallback();
12795
12801
  }
12796
12802
 
12797
- clearTimeout(startAckTimeoutId);
12803
+ if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
12798
12804
  dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].SUBSCRIPTION_ACK, {
12799
12805
  query: query,
12800
12806
  variables: variables
12801
12807
  }, 'Connection established for subscription');
12802
12808
  var subscriptionState = SUBSCRIPTION_STATUS.CONNECTED;
12803
- this.subscriptionObserverMap.set(id, {
12804
- observer: observer,
12805
- query: query,
12806
- variables: variables,
12807
- startAckTimeoutId: null,
12808
- subscriptionState: subscriptionState,
12809
- subscriptionReadyCallback: subscriptionReadyCallback,
12810
- subscriptionFailedCallback: subscriptionFailedCallback
12811
- }); // TODO: emit event on hub but it requires to store the id first
12809
+
12810
+ if (observer) {
12811
+ this.subscriptionObserverMap.set(id, {
12812
+ observer: observer,
12813
+ query: query,
12814
+ variables: variables,
12815
+ startAckTimeoutId: undefined,
12816
+ subscriptionState: subscriptionState,
12817
+ subscriptionReadyCallback: subscriptionReadyCallback,
12818
+ subscriptionFailedCallback: subscriptionFailedCallback
12819
+ });
12820
+ } // TODO: emit event on hub but it requires to store the id first
12821
+
12812
12822
 
12813
12823
  return;
12814
12824
  }
12815
12825
 
12816
12826
  if (type === MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) {
12817
- clearTimeout(this.keepAliveTimeoutId);
12827
+ if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
12818
12828
  this.keepAliveTimeoutId = setTimeout(this._errorDisconnect.bind(this, _index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT), this.keepAliveTimeout);
12819
12829
  return;
12820
12830
  }
12821
12831
 
12822
12832
  if (type === MESSAGE_TYPES.GQL_ERROR) {
12823
12833
  var subscriptionState = SUBSCRIPTION_STATUS.FAILED;
12824
- this.subscriptionObserverMap.set(id, {
12825
- observer: observer,
12826
- query: query,
12827
- variables: variables,
12828
- startAckTimeoutId: startAckTimeoutId,
12829
- subscriptionReadyCallback: subscriptionReadyCallback,
12830
- subscriptionFailedCallback: subscriptionFailedCallback,
12831
- subscriptionState: subscriptionState
12832
- });
12833
- observer.error({
12834
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
12835
- });
12836
- clearTimeout(startAckTimeoutId);
12837
- observer.complete();
12838
12834
 
12839
- if (typeof subscriptionFailedCallback === 'function') {
12840
- subscriptionFailedCallback();
12835
+ if (observer) {
12836
+ this.subscriptionObserverMap.set(id, {
12837
+ observer: observer,
12838
+ query: query,
12839
+ variables: variables,
12840
+ startAckTimeoutId: startAckTimeoutId,
12841
+ subscriptionReadyCallback: subscriptionReadyCallback,
12842
+ subscriptionFailedCallback: subscriptionFailedCallback,
12843
+ subscriptionState: subscriptionState
12844
+ });
12845
+ observer.error({
12846
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
12847
+ });
12848
+ if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
12849
+ observer.complete();
12850
+
12851
+ if (typeof subscriptionFailedCallback === 'function') {
12852
+ subscriptionFailedCallback();
12853
+ }
12841
12854
  }
12842
12855
  }
12843
12856
  };
@@ -12863,37 +12876,40 @@ function (_super) {
12863
12876
  };
12864
12877
 
12865
12878
  AWSAppSyncRealTimeProvider.prototype._timeoutStartSubscriptionAck = function (subscriptionId) {
12866
- var _a = this.subscriptionObserverMap.get(subscriptionId) || {},
12867
- observer = _a.observer,
12868
- query = _a.query,
12869
- variables = _a.variables;
12879
+ var subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
12870
12880
 
12871
- if (!observer) {
12872
- return;
12873
- }
12881
+ if (subscriptionObserver) {
12882
+ var observer = subscriptionObserver.observer,
12883
+ query = subscriptionObserver.query,
12884
+ variables = subscriptionObserver.variables;
12874
12885
 
12875
- this.subscriptionObserverMap.set(subscriptionId, {
12876
- observer: observer,
12877
- query: query,
12878
- variables: variables,
12879
- subscriptionState: SUBSCRIPTION_STATUS.FAILED
12880
- });
12886
+ if (!observer) {
12887
+ return;
12888
+ }
12881
12889
 
12882
- if (observer && !observer.closed) {
12883
- observer.error({
12884
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscription timeout " + JSON.stringify({
12885
- query: query,
12886
- variables: variables
12887
- })))]
12888
- }); // Cleanup will be automatically executed
12890
+ this.subscriptionObserverMap.set(subscriptionId, {
12891
+ observer: observer,
12892
+ query: query,
12893
+ variables: variables,
12894
+ subscriptionState: SUBSCRIPTION_STATUS.FAILED
12895
+ });
12889
12896
 
12890
- observer.complete();
12891
- }
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
12892
12904
 
12893
- logger.debug('timeoutStartSubscription', JSON.stringify({
12894
- query: query,
12895
- variables: variables
12896
- }));
12905
+ observer.complete();
12906
+ }
12907
+
12908
+ logger.debug('timeoutStartSubscription', JSON.stringify({
12909
+ query: query,
12910
+ variables: variables
12911
+ }));
12912
+ }
12897
12913
  };
12898
12914
 
12899
12915
  AWSAppSyncRealTimeProvider.prototype._initializeWebSocketConnection = function (_a) {
@@ -12947,7 +12963,7 @@ function (_super) {
12947
12963
  headerString = _b.apply(_a, [_c.sent()]);
12948
12964
  headerQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(headerString).toString('base64');
12949
12965
  payloadQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(payloadString).toString('base64');
12950
- discoverableEndpoint = appSyncGraphqlEndpoint;
12966
+ discoverableEndpoint = appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '';
12951
12967
 
12952
12968
  if (this.isCustomDomain(discoverableEndpoint)) {
12953
12969
  discoverableEndpoint = discoverableEndpoint.concat(customDomainPath);
@@ -12960,9 +12976,7 @@ function (_super) {
12960
12976
  awsRealTimeUrl = discoverableEndpoint + "?header=" + headerQs + "&payload=" + payloadQs;
12961
12977
  return [4
12962
12978
  /*yield*/
12963
- , this._initializeRetryableHandshake({
12964
- awsRealTimeUrl: awsRealTimeUrl
12965
- })];
12979
+ , this._initializeRetryableHandshake(awsRealTimeUrl)];
12966
12980
 
12967
12981
  case 3:
12968
12982
  _c.sent();
@@ -12990,7 +13004,7 @@ function (_super) {
12990
13004
  this.awsRealTimeSocket.close(3001);
12991
13005
  }
12992
13006
 
12993
- this.awsRealTimeSocket = null;
13007
+ this.awsRealTimeSocket = undefined;
12994
13008
  this.socketStatus = SOCKET_STATUS.CLOSED;
12995
13009
  return [3
12996
13010
  /*break*/
@@ -13006,21 +13020,18 @@ function (_super) {
13006
13020
  });
13007
13021
  };
13008
13022
 
13009
- AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (_a) {
13010
- var awsRealTimeUrl = _a.awsRealTimeUrl;
13023
+ AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (awsRealTimeUrl) {
13011
13024
  return __awaiter(this, void 0, void 0, function () {
13012
- return __generator(this, function (_b) {
13013
- switch (_b.label) {
13025
+ return __generator(this, function (_a) {
13026
+ switch (_a.label) {
13014
13027
  case 0:
13015
13028
  logger.debug("Initializaling retryable Handshake");
13016
13029
  return [4
13017
13030
  /*yield*/
13018
- , Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [{
13019
- awsRealTimeUrl: awsRealTimeUrl
13020
- }], MAX_DELAY_MS)];
13031
+ , Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [awsRealTimeUrl], MAX_DELAY_MS)];
13021
13032
 
13022
13033
  case 1:
13023
- _b.sent();
13034
+ _a.sent();
13024
13035
 
13025
13036
  return [2
13026
13037
  /*return*/
@@ -13030,10 +13041,9 @@ function (_super) {
13030
13041
  });
13031
13042
  };
13032
13043
 
13033
- AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (_a) {
13034
- var awsRealTimeUrl = _a.awsRealTimeUrl;
13044
+ AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (awsRealTimeUrl) {
13035
13045
  return __awaiter(this, void 0, void 0, function () {
13036
- var err_4, errorType, errorCode;
13046
+ var err_4, _a, errorType, errorCode;
13037
13047
 
13038
13048
  var _this = this;
13039
13049
 
@@ -13075,77 +13085,82 @@ function (_super) {
13075
13085
  /*yield*/
13076
13086
  , function () {
13077
13087
  return new Promise(function (res, rej) {
13078
- var ackOk = false;
13088
+ if (_this.awsRealTimeSocket) {
13089
+ var ackOk_1 = false;
13079
13090
 
13080
- _this.awsRealTimeSocket.onerror = function (error) {
13081
- logger.debug("WebSocket error " + JSON.stringify(error));
13082
- };
13091
+ _this.awsRealTimeSocket.onerror = function (error) {
13092
+ logger.debug("WebSocket error " + JSON.stringify(error));
13093
+ };
13083
13094
 
13084
- _this.awsRealTimeSocket.onclose = function (event) {
13085
- logger.debug("WebSocket closed " + event.reason);
13086
- rej(new Error(JSON.stringify(event)));
13087
- };
13095
+ _this.awsRealTimeSocket.onclose = function (event) {
13096
+ logger.debug("WebSocket closed " + event.reason);
13097
+ rej(new Error(JSON.stringify(event)));
13098
+ };
13088
13099
 
13089
- _this.awsRealTimeSocket.onmessage = function (message) {
13090
- logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
13091
- var data = JSON.parse(message.data);
13092
- var type = data.type,
13093
- _a = data.payload,
13094
- _b = (_a === void 0 ? {} : _a).connectionTimeoutMs,
13095
- connectionTimeoutMs = _b === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _b;
13100
+ _this.awsRealTimeSocket.onmessage = function (message) {
13101
+ logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
13102
+ var data = JSON.parse(message.data);
13103
+ var type = data.type,
13104
+ _a = data.payload,
13105
+ _b = (_a === void 0 ? {} : _a).connectionTimeoutMs,
13106
+ connectionTimeoutMs = _b === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _b;
13096
13107
 
13097
- if (type === MESSAGE_TYPES.GQL_CONNECTION_ACK) {
13098
- ackOk = true;
13099
- _this.keepAliveTimeout = connectionTimeoutMs;
13100
- _this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
13108
+ if (type === MESSAGE_TYPES.GQL_CONNECTION_ACK) {
13109
+ ackOk_1 = true;
13101
13110
 
13102
- _this.awsRealTimeSocket.onerror = function (err) {
13103
- logger.debug(err);
13111
+ if (_this.awsRealTimeSocket) {
13112
+ _this.keepAliveTimeout = connectionTimeoutMs;
13113
+ _this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
13104
13114
 
13105
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
13106
- };
13115
+ _this.awsRealTimeSocket.onerror = function (err) {
13116
+ logger.debug(err);
13107
13117
 
13108
- _this.awsRealTimeSocket.onclose = function (event) {
13109
- logger.debug("WebSocket closed " + event.reason);
13118
+ _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
13119
+ };
13110
13120
 
13111
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
13112
- };
13121
+ _this.awsRealTimeSocket.onclose = function (event) {
13122
+ logger.debug("WebSocket closed " + event.reason);
13113
13123
 
13114
- res('Cool, connected to AWS AppSyncRealTime');
13115
- return;
13116
- }
13124
+ _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
13125
+ };
13126
+ }
13117
13127
 
13118
- if (type === MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
13119
- var _c = data.payload,
13120
- _d = (_c === void 0 ? {} : _c).errors,
13121
- _e = __read(_d === void 0 ? [] : _d, 1),
13122
- _f = _e[0],
13123
- _g = _f === void 0 ? {} : _f,
13124
- _h = _g.errorType,
13125
- errorType = _h === void 0 ? '' : _h,
13126
- _j = _g.errorCode,
13127
- errorCode = _j === void 0 ? 0 : _j;
13128
-
13129
- rej({
13130
- errorType: errorType,
13131
- errorCode: errorCode
13132
- });
13133
- }
13134
- };
13128
+ res('Cool, connected to AWS AppSyncRealTime');
13129
+ return;
13130
+ }
13135
13131
 
13136
- var gqlInit = {
13137
- type: MESSAGE_TYPES.GQL_CONNECTION_INIT
13138
- };
13132
+ if (type === MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
13133
+ var _c = data.payload,
13134
+ _d = (_c === void 0 ? {} : _c).errors,
13135
+ _e = __read(_d === void 0 ? [] : _d, 1),
13136
+ _f = _e[0],
13137
+ _g = _f === void 0 ? {} : _f,
13138
+ _h = _g.errorType,
13139
+ errorType = _h === void 0 ? '' : _h,
13140
+ _j = _g.errorCode,
13141
+ errorCode = _j === void 0 ? 0 : _j;
13142
+
13143
+ rej({
13144
+ errorType: errorType,
13145
+ errorCode: errorCode
13146
+ });
13147
+ }
13148
+ };
13139
13149
 
13140
- _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
13150
+ var gqlInit = {
13151
+ type: MESSAGE_TYPES.GQL_CONNECTION_INIT
13152
+ };
13141
13153
 
13142
- function checkAckOk() {
13154
+ _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
13155
+
13156
+ setTimeout(checkAckOk.bind(_this, ackOk_1), CONNECTION_INIT_TIMEOUT);
13157
+ }
13158
+
13159
+ function checkAckOk(ackOk) {
13143
13160
  if (!ackOk) {
13144
13161
  rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + CONNECTION_INIT_TIMEOUT + " ms"));
13145
13162
  }
13146
13163
  }
13147
-
13148
- setTimeout(checkAckOk.bind(_this), CONNECTION_INIT_TIMEOUT);
13149
13164
  });
13150
13165
  }()];
13151
13166
 
@@ -13159,7 +13174,7 @@ function (_super) {
13159
13174
 
13160
13175
  case 4:
13161
13176
  err_4 = _b.sent();
13162
- errorType = err_4.errorType, errorCode = err_4.errorCode;
13177
+ _a = err_4, errorType = _a.errorType, errorCode = _a.errorCode;
13163
13178
 
13164
13179
  if (NON_RETRYABLE_CODES.includes(errorCode)) {
13165
13180
  throw new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["NonRetryableError"](errorType);
@@ -13202,16 +13217,17 @@ function (_super) {
13202
13217
  AMAZON_COGNITO_USER_POOLS: this._awsRealTimeCUPHeader.bind(this),
13203
13218
  AWS_LAMBDA: this._customAuthHeader
13204
13219
  };
13205
- handler = headerHandler[authenticationType];
13206
-
13207
- if (typeof handler !== 'function') {
13208
- logger.debug("Authentication type " + authenticationType + " not supported");
13209
- return [2
13210
- /*return*/
13211
- , ''];
13212
- }
13220
+ if (!(!authenticationType || !headerHandler[authenticationType])) return [3
13221
+ /*break*/
13222
+ , 1];
13223
+ logger.debug("Authentication type " + authenticationType + " not supported");
13224
+ return [2
13225
+ /*return*/
13226
+ , ''];
13213
13227
 
13214
- host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint).host;
13228
+ case 1:
13229
+ handler = headerHandler[authenticationType];
13230
+ host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
13215
13231
  return [4
13216
13232
  /*yield*/
13217
13233
  , handler({
@@ -13224,7 +13240,7 @@ function (_super) {
13224
13240
  additionalHeaders: additionalHeaders
13225
13241
  })];
13226
13242
 
13227
- case 1:
13243
+ case 2:
13228
13244
  result = _b.sent();
13229
13245
  return [2
13230
13246
  /*return*/
@@ -13356,10 +13372,14 @@ function (_super) {
13356
13372
  return [4
13357
13373
  /*yield*/
13358
13374
  , _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Credentials"].get().then(function (credentials) {
13375
+ var _a = credentials,
13376
+ secretAccessKey = _a.secretAccessKey,
13377
+ accessKeyId = _a.accessKeyId,
13378
+ sessionToken = _a.sessionToken;
13359
13379
  return {
13360
- secret_key: credentials.secretAccessKey,
13361
- access_key: credentials.accessKeyId,
13362
- session_token: credentials.sessionToken
13380
+ secret_key: secretAccessKey,
13381
+ access_key: accessKeyId,
13382
+ session_token: sessionToken
13363
13383
  };
13364
13384
  })];
13365
13385
 
@@ -13384,7 +13404,7 @@ function (_super) {
13384
13404
  var host = _a.host,
13385
13405
  additionalHeaders = _a.additionalHeaders;
13386
13406
 
13387
- if (!additionalHeaders.Authorization) {
13407
+ if (!additionalHeaders || !additionalHeaders['Authorization']) {
13388
13408
  throw new Error('No auth token specified');
13389
13409
  }
13390
13410
 
@@ -13956,21 +13976,27 @@ function () {
13956
13976
 
13957
13977
  ClientsQueue.prototype.get = function (clientId, clientFactory) {
13958
13978
  return __awaiter(this, void 0, void 0, function () {
13959
- var promise;
13979
+ var cachedPromise, newPromise;
13960
13980
  return __generator(this, function (_a) {
13961
- promise = this.promises.get(clientId);
13981
+ cachedPromise = this.promises.get(clientId);
13962
13982
 
13963
- if (promise) {
13983
+ if (cachedPromise) {
13964
13984
  return [2
13965
13985
  /*return*/
13966
- , promise];
13986
+ , cachedPromise];
13987
+ }
13988
+
13989
+ if (clientFactory) {
13990
+ newPromise = clientFactory(clientId);
13991
+ this.promises.set(clientId, newPromise);
13992
+ return [2
13993
+ /*return*/
13994
+ , newPromise];
13967
13995
  }
13968
13996
 
13969
- promise = clientFactory(clientId);
13970
- this.promises.set(clientId, promise);
13971
13997
  return [2
13972
13998
  /*return*/
13973
- , promise];
13999
+ , undefined];
13974
14000
  });
13975
14001
  });
13976
14002
  };
@@ -14062,6 +14088,10 @@ function (_super) {
14062
14088
  }, args), null, 2));
14063
14089
  var topicsToDelete_1 = [];
14064
14090
 
14091
+ if (!clientId) {
14092
+ return;
14093
+ }
14094
+
14065
14095
  var clientIdObservers = this._clientIdObservers.get(clientId);
14066
14096
 
14067
14097
  if (!clientIdObservers) {
@@ -14180,9 +14210,7 @@ function (_super) {
14180
14210
  case 0:
14181
14211
  return [4
14182
14212
  /*yield*/
14183
- , this.clientsQueue.get(clientId, function () {
14184
- return null;
14185
- })];
14213
+ , this.clientsQueue.get(clientId)];
14186
14214
 
14187
14215
  case 1:
14188
14216
  client = _a.sent();
@@ -14361,13 +14389,14 @@ function (_super) {
14361
14389
  })();
14362
14390
 
14363
14391
  return function () {
14392
+ var _a, _b;
14393
+
14364
14394
  logger.debug('Unsubscribing from topic(s)', targetTopics.join(','));
14365
14395
 
14366
14396
  if (client) {
14367
- _this._clientIdObservers.get(clientId)["delete"](observer); // No more observers per client => client not needed anymore
14368
-
14397
+ (_a = _this._clientIdObservers.get(clientId)) === null || _a === void 0 ? void 0 : _a["delete"](observer); // No more observers per client => client not needed anymore
14369
14398
 
14370
- if (_this._clientIdObservers.get(clientId).size === 0) {
14399
+ if (((_b = _this._clientIdObservers.get(clientId)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
14371
14400
  _this.disconnect(clientId);
14372
14401
 
14373
14402
  _this._clientIdObservers["delete"](clientId);