@aws-amplify/api-graphql 2.2.22-unstable.9 → 2.2.23-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.
@@ -10801,6 +10801,9 @@ var __spread = undefined && undefined.__spread || function () {
10801
10801
 
10802
10802
 
10803
10803
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["ConsoleLogger"]('AWSAppSyncProvider');
10804
+ /**
10805
+ * @deprecated Unused, all usecases have migrated to AWSAppSyncRealtimeProvider
10806
+ */
10804
10807
 
10805
10808
  var AWSAppSyncProvider =
10806
10809
  /** @class */
@@ -11524,9 +11527,9 @@ function (_super) {
11524
11527
  AWSAppSyncRealTimeProvider.prototype.subscribe = function (_topics, options) {
11525
11528
  var _this = this;
11526
11529
 
11527
- var appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint;
11530
+ var appSyncGraphqlEndpoint = options === null || options === void 0 ? void 0 : options.appSyncGraphqlEndpoint;
11528
11531
  return new zen_observable_ts__WEBPACK_IMPORTED_MODULE_0__["default"](function (observer) {
11529
- if (!appSyncGraphqlEndpoint) {
11532
+ if (!options || !appSyncGraphqlEndpoint) {
11530
11533
  observer.error({
11531
11534
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscribe only available for AWS AppSync endpoint"))]
11532
11535
  });
@@ -11619,19 +11622,22 @@ function (_super) {
11619
11622
  var options = _a.options,
11620
11623
  observer = _a.observer,
11621
11624
  subscriptionId = _a.subscriptionId;
11625
+
11626
+ var _b, _c;
11627
+
11622
11628
  return __awaiter(this, void 0, void 0, function () {
11623
- 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;
11629
+ 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;
11624
11630
 
11625
- var _h;
11631
+ var _j;
11626
11632
 
11627
11633
  var _this = this;
11628
11634
 
11629
- return __generator(this, function (_j) {
11630
- switch (_j.label) {
11635
+ return __generator(this, function (_k) {
11636
+ switch (_k.label) {
11631
11637
  case 0:
11632
- 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 () {
11638
+ 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 () {
11633
11639
  return {};
11634
- } : _b, _c = options.additionalHeaders, additionalHeaders = _c === void 0 ? {} : _c;
11640
+ } : _d, _e = options.additionalHeaders, additionalHeaders = _e === void 0 ? {} : _e;
11635
11641
  subscriptionState = SUBSCRIPTION_STATUS.PENDING;
11636
11642
  data = {
11637
11643
  query: query,
@@ -11640,13 +11646,13 @@ function (_super) {
11640
11646
 
11641
11647
  this.subscriptionObserverMap.set(subscriptionId, {
11642
11648
  observer: observer,
11643
- query: query,
11644
- variables: variables,
11649
+ query: query !== null && query !== void 0 ? query : '',
11650
+ variables: variables !== null && variables !== void 0 ? variables : {},
11645
11651
  subscriptionState: subscriptionState,
11646
- startAckTimeoutId: null
11652
+ startAckTimeoutId: undefined
11647
11653
  });
11648
11654
  dataString = JSON.stringify(data);
11649
- _d = [{}];
11655
+ _f = [{}];
11650
11656
  return [4
11651
11657
  /*yield*/
11652
11658
  , this._awsRealTimeHeaderBasedAuth({
@@ -11660,13 +11666,13 @@ function (_super) {
11660
11666
  })];
11661
11667
 
11662
11668
  case 1:
11663
- _e = [__assign.apply(void 0, _d.concat([_j.sent()]))];
11669
+ _g = [__assign.apply(void 0, _f.concat([_k.sent()]))];
11664
11670
  return [4
11665
11671
  /*yield*/
11666
11672
  , graphql_headers()];
11667
11673
 
11668
11674
  case 2:
11669
- 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)]);
11675
+ 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)]);
11670
11676
  subscriptionMessage = {
11671
11677
  id: subscriptionId,
11672
11678
  payload: {
@@ -11678,10 +11684,10 @@ function (_super) {
11678
11684
  type: MESSAGE_TYPES.GQL_START
11679
11685
  };
11680
11686
  stringToAWSRealTime = JSON.stringify(subscriptionMessage);
11681
- _j.label = 3;
11687
+ _k.label = 3;
11682
11688
 
11683
11689
  case 3:
11684
- _j.trys.push([3, 5,, 6]);
11690
+ _k.trys.push([3, 5,, 6]);
11685
11691
 
11686
11692
  return [4
11687
11693
  /*yield*/
@@ -11694,18 +11700,18 @@ function (_super) {
11694
11700
  })];
11695
11701
 
11696
11702
  case 4:
11697
- _j.sent();
11703
+ _k.sent();
11698
11704
 
11699
11705
  return [3
11700
11706
  /*break*/
11701
11707
  , 6];
11702
11708
 
11703
11709
  case 5:
11704
- err_2 = _j.sent();
11710
+ err_2 = _k.sent();
11705
11711
  logger.debug({
11706
11712
  err: err_2
11707
11713
  });
11708
- _f = err_2.message, message = _f === void 0 ? '' : _f;
11714
+ message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
11709
11715
  observer.error({
11710
11716
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
11711
11717
  });
@@ -11721,13 +11727,13 @@ function (_super) {
11721
11727
  ];
11722
11728
 
11723
11729
  case 6:
11724
- _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
11730
+ _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
11725
11731
 
11726
11732
  this.subscriptionObserverMap.set(subscriptionId, {
11727
11733
  observer: observer,
11728
11734
  subscriptionState: subscriptionState,
11729
- variables: variables,
11730
- query: query,
11735
+ query: query !== null && query !== void 0 ? query : '',
11736
+ variables: variables !== null && variables !== void 0 ? variables : {},
11731
11737
  subscriptionReadyCallback: subscriptionReadyCallback,
11732
11738
  subscriptionFailedCallback: subscriptionFailedCallback,
11733
11739
  startAckTimeoutId: setTimeout(function () {
@@ -11750,32 +11756,35 @@ function (_super) {
11750
11756
 
11751
11757
  AWSAppSyncRealTimeProvider.prototype._waitForSubscriptionToBeConnected = function (subscriptionId) {
11752
11758
  return __awaiter(this, void 0, void 0, function () {
11753
- var subscriptionState;
11759
+ var subscriptionObserver, subscriptionState;
11754
11760
 
11755
11761
  var _this = this;
11756
11762
 
11757
11763
  return __generator(this, function (_a) {
11758
- subscriptionState = this.subscriptionObserverMap.get(subscriptionId).subscriptionState; // This in case unsubscribe is invoked before sending start subscription message
11764
+ subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
11759
11765
 
11760
- if (subscriptionState === SUBSCRIPTION_STATUS.PENDING) {
11761
- return [2
11762
- /*return*/
11763
- , new Promise(function (res, rej) {
11764
- var _a = _this.subscriptionObserverMap.get(subscriptionId),
11765
- observer = _a.observer,
11766
- subscriptionState = _a.subscriptionState,
11767
- variables = _a.variables,
11768
- query = _a.query;
11769
-
11770
- _this.subscriptionObserverMap.set(subscriptionId, {
11771
- observer: observer,
11772
- subscriptionState: subscriptionState,
11773
- variables: variables,
11774
- query: query,
11775
- subscriptionReadyCallback: res,
11776
- subscriptionFailedCallback: rej
11777
- });
11778
- })];
11766
+ if (subscriptionObserver) {
11767
+ subscriptionState = subscriptionObserver.subscriptionState; // This in case unsubscribe is invoked before sending start subscription message
11768
+
11769
+ if (subscriptionState === SUBSCRIPTION_STATUS.PENDING) {
11770
+ return [2
11771
+ /*return*/
11772
+ , new Promise(function (res, rej) {
11773
+ var observer = subscriptionObserver.observer,
11774
+ subscriptionState = subscriptionObserver.subscriptionState,
11775
+ variables = subscriptionObserver.variables,
11776
+ query = subscriptionObserver.query;
11777
+
11778
+ _this.subscriptionObserverMap.set(subscriptionId, {
11779
+ observer: observer,
11780
+ subscriptionState: subscriptionState,
11781
+ variables: variables,
11782
+ query: query,
11783
+ subscriptionReadyCallback: res,
11784
+ subscriptionFailedCallback: rej
11785
+ });
11786
+ })];
11787
+ }
11779
11788
  }
11780
11789
 
11781
11790
  return [2
@@ -11826,19 +11835,23 @@ function (_super) {
11826
11835
  setTimeout(this._closeSocketIfRequired.bind(this), 1000);
11827
11836
  } else {
11828
11837
  logger.debug('closing WebSocket...');
11829
- clearTimeout(this.keepAliveTimeoutId);
11838
+ if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
11830
11839
  var tempSocket = this.awsRealTimeSocket; // Cleaning callbacks to avoid race condition, socket still exists
11831
11840
 
11832
- tempSocket.onclose = undefined;
11833
- tempSocket.onerror = undefined;
11841
+ tempSocket.onclose = null;
11842
+ tempSocket.onerror = null;
11834
11843
  tempSocket.close(1000);
11835
- this.awsRealTimeSocket = null;
11844
+ this.awsRealTimeSocket = undefined;
11836
11845
  this.socketStatus = SOCKET_STATUS.CLOSED;
11837
11846
  }
11838
11847
  };
11839
11848
 
11840
11849
  AWSAppSyncRealTimeProvider.prototype._handleIncomingSubscriptionMessage = function (message) {
11841
- logger.debug("subscription message from AWS AppSync RealTime: " + message.data);
11850
+ if (message.data && message.data === '{"type":"ka"}') {
11851
+ logger.verbose("subscription message from AWS AppSync RealTime: " + message.data);
11852
+ } else {
11853
+ logger.debug("subscription message from AWS AppSync RealTime: " + message.data);
11854
+ }
11842
11855
 
11843
11856
  var _a = JSON.parse(message.data),
11844
11857
  _b = _a.id,
@@ -11857,12 +11870,21 @@ function (_super) {
11857
11870
  subscriptionReadyCallback = _c.subscriptionReadyCallback,
11858
11871
  subscriptionFailedCallback = _c.subscriptionFailedCallback;
11859
11872
 
11860
- logger.debug({
11861
- id: id,
11862
- observer: observer,
11863
- query: query,
11864
- variables: variables
11865
- });
11873
+ if (!id && !observer && !query && Object.keys(variables).length === 0) {
11874
+ logger.verbose({
11875
+ id: id,
11876
+ observer: observer,
11877
+ query: query,
11878
+ variables: variables
11879
+ });
11880
+ } else {
11881
+ logger.debug({
11882
+ id: id,
11883
+ observer: observer,
11884
+ query: query,
11885
+ variables: variables
11886
+ });
11887
+ }
11866
11888
 
11867
11889
  if (type === MESSAGE_TYPES.GQL_DATA && payload && payload.data) {
11868
11890
  if (observer) {
@@ -11884,50 +11906,57 @@ function (_super) {
11884
11906
  subscriptionReadyCallback();
11885
11907
  }
11886
11908
 
11887
- clearTimeout(startAckTimeoutId);
11909
+ if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
11888
11910
  dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].SUBSCRIPTION_ACK, {
11889
11911
  query: query,
11890
11912
  variables: variables
11891
11913
  }, 'Connection established for subscription');
11892
11914
  var subscriptionState = SUBSCRIPTION_STATUS.CONNECTED;
11893
- this.subscriptionObserverMap.set(id, {
11894
- observer: observer,
11895
- query: query,
11896
- variables: variables,
11897
- startAckTimeoutId: null,
11898
- subscriptionState: subscriptionState,
11899
- subscriptionReadyCallback: subscriptionReadyCallback,
11900
- subscriptionFailedCallback: subscriptionFailedCallback
11901
- }); // TODO: emit event on hub but it requires to store the id first
11915
+
11916
+ if (observer) {
11917
+ this.subscriptionObserverMap.set(id, {
11918
+ observer: observer,
11919
+ query: query,
11920
+ variables: variables,
11921
+ startAckTimeoutId: undefined,
11922
+ subscriptionState: subscriptionState,
11923
+ subscriptionReadyCallback: subscriptionReadyCallback,
11924
+ subscriptionFailedCallback: subscriptionFailedCallback
11925
+ });
11926
+ } // TODO: emit event on hub but it requires to store the id first
11927
+
11902
11928
 
11903
11929
  return;
11904
11930
  }
11905
11931
 
11906
11932
  if (type === MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) {
11907
- clearTimeout(this.keepAliveTimeoutId);
11933
+ if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
11908
11934
  this.keepAliveTimeoutId = setTimeout(this._errorDisconnect.bind(this, _index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT), this.keepAliveTimeout);
11909
11935
  return;
11910
11936
  }
11911
11937
 
11912
11938
  if (type === MESSAGE_TYPES.GQL_ERROR) {
11913
11939
  var subscriptionState = SUBSCRIPTION_STATUS.FAILED;
11914
- this.subscriptionObserverMap.set(id, {
11915
- observer: observer,
11916
- query: query,
11917
- variables: variables,
11918
- startAckTimeoutId: startAckTimeoutId,
11919
- subscriptionReadyCallback: subscriptionReadyCallback,
11920
- subscriptionFailedCallback: subscriptionFailedCallback,
11921
- subscriptionState: subscriptionState
11922
- });
11923
- observer.error({
11924
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
11925
- });
11926
- clearTimeout(startAckTimeoutId);
11927
- observer.complete();
11928
11940
 
11929
- if (typeof subscriptionFailedCallback === 'function') {
11930
- subscriptionFailedCallback();
11941
+ if (observer) {
11942
+ this.subscriptionObserverMap.set(id, {
11943
+ observer: observer,
11944
+ query: query,
11945
+ variables: variables,
11946
+ startAckTimeoutId: startAckTimeoutId,
11947
+ subscriptionReadyCallback: subscriptionReadyCallback,
11948
+ subscriptionFailedCallback: subscriptionFailedCallback,
11949
+ subscriptionState: subscriptionState
11950
+ });
11951
+ observer.error({
11952
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
11953
+ });
11954
+ if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
11955
+ observer.complete();
11956
+
11957
+ if (typeof subscriptionFailedCallback === 'function') {
11958
+ subscriptionFailedCallback();
11959
+ }
11931
11960
  }
11932
11961
  }
11933
11962
  };
@@ -11953,37 +11982,40 @@ function (_super) {
11953
11982
  };
11954
11983
 
11955
11984
  AWSAppSyncRealTimeProvider.prototype._timeoutStartSubscriptionAck = function (subscriptionId) {
11956
- var _a = this.subscriptionObserverMap.get(subscriptionId) || {},
11957
- observer = _a.observer,
11958
- query = _a.query,
11959
- variables = _a.variables;
11985
+ var subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
11960
11986
 
11961
- if (!observer) {
11962
- return;
11963
- }
11987
+ if (subscriptionObserver) {
11988
+ var observer = subscriptionObserver.observer,
11989
+ query = subscriptionObserver.query,
11990
+ variables = subscriptionObserver.variables;
11964
11991
 
11965
- this.subscriptionObserverMap.set(subscriptionId, {
11966
- observer: observer,
11967
- query: query,
11968
- variables: variables,
11969
- subscriptionState: SUBSCRIPTION_STATUS.FAILED
11970
- });
11992
+ if (!observer) {
11993
+ return;
11994
+ }
11971
11995
 
11972
- if (observer && !observer.closed) {
11973
- observer.error({
11974
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscription timeout " + JSON.stringify({
11975
- query: query,
11976
- variables: variables
11977
- })))]
11978
- }); // Cleanup will be automatically executed
11996
+ this.subscriptionObserverMap.set(subscriptionId, {
11997
+ observer: observer,
11998
+ query: query,
11999
+ variables: variables,
12000
+ subscriptionState: SUBSCRIPTION_STATUS.FAILED
12001
+ });
11979
12002
 
11980
- observer.complete();
11981
- }
12003
+ if (observer && !observer.closed) {
12004
+ observer.error({
12005
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscription timeout " + JSON.stringify({
12006
+ query: query,
12007
+ variables: variables
12008
+ })))]
12009
+ }); // Cleanup will be automatically executed
11982
12010
 
11983
- logger.debug('timeoutStartSubscription', JSON.stringify({
11984
- query: query,
11985
- variables: variables
11986
- }));
12011
+ observer.complete();
12012
+ }
12013
+
12014
+ logger.debug('timeoutStartSubscription', JSON.stringify({
12015
+ query: query,
12016
+ variables: variables
12017
+ }));
12018
+ }
11987
12019
  };
11988
12020
 
11989
12021
  AWSAppSyncRealTimeProvider.prototype._initializeWebSocketConnection = function (_a) {
@@ -12037,7 +12069,7 @@ function (_super) {
12037
12069
  headerString = _b.apply(_a, [_c.sent()]);
12038
12070
  headerQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(headerString).toString('base64');
12039
12071
  payloadQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(payloadString).toString('base64');
12040
- discoverableEndpoint = appSyncGraphqlEndpoint;
12072
+ discoverableEndpoint = appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '';
12041
12073
 
12042
12074
  if (this.isCustomDomain(discoverableEndpoint)) {
12043
12075
  discoverableEndpoint = discoverableEndpoint.concat(customDomainPath);
@@ -12050,9 +12082,7 @@ function (_super) {
12050
12082
  awsRealTimeUrl = discoverableEndpoint + "?header=" + headerQs + "&payload=" + payloadQs;
12051
12083
  return [4
12052
12084
  /*yield*/
12053
- , this._initializeRetryableHandshake({
12054
- awsRealTimeUrl: awsRealTimeUrl
12055
- })];
12085
+ , this._initializeRetryableHandshake(awsRealTimeUrl)];
12056
12086
 
12057
12087
  case 3:
12058
12088
  _c.sent();
@@ -12080,7 +12110,7 @@ function (_super) {
12080
12110
  this.awsRealTimeSocket.close(3001);
12081
12111
  }
12082
12112
 
12083
- this.awsRealTimeSocket = null;
12113
+ this.awsRealTimeSocket = undefined;
12084
12114
  this.socketStatus = SOCKET_STATUS.CLOSED;
12085
12115
  return [3
12086
12116
  /*break*/
@@ -12096,21 +12126,18 @@ function (_super) {
12096
12126
  });
12097
12127
  };
12098
12128
 
12099
- AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (_a) {
12100
- var awsRealTimeUrl = _a.awsRealTimeUrl;
12129
+ AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (awsRealTimeUrl) {
12101
12130
  return __awaiter(this, void 0, void 0, function () {
12102
- return __generator(this, function (_b) {
12103
- switch (_b.label) {
12131
+ return __generator(this, function (_a) {
12132
+ switch (_a.label) {
12104
12133
  case 0:
12105
12134
  logger.debug("Initializaling retryable Handshake");
12106
12135
  return [4
12107
12136
  /*yield*/
12108
- , Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [{
12109
- awsRealTimeUrl: awsRealTimeUrl
12110
- }], MAX_DELAY_MS)];
12137
+ , Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [awsRealTimeUrl], MAX_DELAY_MS)];
12111
12138
 
12112
12139
  case 1:
12113
- _b.sent();
12140
+ _a.sent();
12114
12141
 
12115
12142
  return [2
12116
12143
  /*return*/
@@ -12120,10 +12147,9 @@ function (_super) {
12120
12147
  });
12121
12148
  };
12122
12149
 
12123
- AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (_a) {
12124
- var awsRealTimeUrl = _a.awsRealTimeUrl;
12150
+ AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (awsRealTimeUrl) {
12125
12151
  return __awaiter(this, void 0, void 0, function () {
12126
- var err_4, errorType, errorCode;
12152
+ var err_4, _a, errorType, errorCode;
12127
12153
 
12128
12154
  var _this = this;
12129
12155
 
@@ -12165,77 +12191,82 @@ function (_super) {
12165
12191
  /*yield*/
12166
12192
  , function () {
12167
12193
  return new Promise(function (res, rej) {
12168
- var ackOk = false;
12194
+ if (_this.awsRealTimeSocket) {
12195
+ var ackOk_1 = false;
12169
12196
 
12170
- _this.awsRealTimeSocket.onerror = function (error) {
12171
- logger.debug("WebSocket error " + JSON.stringify(error));
12172
- };
12197
+ _this.awsRealTimeSocket.onerror = function (error) {
12198
+ logger.debug("WebSocket error " + JSON.stringify(error));
12199
+ };
12173
12200
 
12174
- _this.awsRealTimeSocket.onclose = function (event) {
12175
- logger.debug("WebSocket closed " + event.reason);
12176
- rej(new Error(JSON.stringify(event)));
12177
- };
12201
+ _this.awsRealTimeSocket.onclose = function (event) {
12202
+ logger.debug("WebSocket closed " + event.reason);
12203
+ rej(new Error(JSON.stringify(event)));
12204
+ };
12178
12205
 
12179
- _this.awsRealTimeSocket.onmessage = function (message) {
12180
- logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
12181
- var data = JSON.parse(message.data);
12182
- var type = data.type,
12183
- _a = data.payload,
12184
- _b = (_a === void 0 ? {} : _a).connectionTimeoutMs,
12185
- connectionTimeoutMs = _b === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _b;
12206
+ _this.awsRealTimeSocket.onmessage = function (message) {
12207
+ logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
12208
+ var data = JSON.parse(message.data);
12209
+ var type = data.type,
12210
+ _a = data.payload,
12211
+ _b = (_a === void 0 ? {} : _a).connectionTimeoutMs,
12212
+ connectionTimeoutMs = _b === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _b;
12186
12213
 
12187
- if (type === MESSAGE_TYPES.GQL_CONNECTION_ACK) {
12188
- ackOk = true;
12189
- _this.keepAliveTimeout = connectionTimeoutMs;
12190
- _this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
12214
+ if (type === MESSAGE_TYPES.GQL_CONNECTION_ACK) {
12215
+ ackOk_1 = true;
12191
12216
 
12192
- _this.awsRealTimeSocket.onerror = function (err) {
12193
- logger.debug(err);
12217
+ if (_this.awsRealTimeSocket) {
12218
+ _this.keepAliveTimeout = connectionTimeoutMs;
12219
+ _this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
12194
12220
 
12195
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12196
- };
12221
+ _this.awsRealTimeSocket.onerror = function (err) {
12222
+ logger.debug(err);
12197
12223
 
12198
- _this.awsRealTimeSocket.onclose = function (event) {
12199
- logger.debug("WebSocket closed " + event.reason);
12224
+ _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12225
+ };
12200
12226
 
12201
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12202
- };
12227
+ _this.awsRealTimeSocket.onclose = function (event) {
12228
+ logger.debug("WebSocket closed " + event.reason);
12203
12229
 
12204
- res('Cool, connected to AWS AppSyncRealTime');
12205
- return;
12206
- }
12230
+ _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12231
+ };
12232
+ }
12207
12233
 
12208
- if (type === MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
12209
- var _c = data.payload,
12210
- _d = (_c === void 0 ? {} : _c).errors,
12211
- _e = __read(_d === void 0 ? [] : _d, 1),
12212
- _f = _e[0],
12213
- _g = _f === void 0 ? {} : _f,
12214
- _h = _g.errorType,
12215
- errorType = _h === void 0 ? '' : _h,
12216
- _j = _g.errorCode,
12217
- errorCode = _j === void 0 ? 0 : _j;
12218
-
12219
- rej({
12220
- errorType: errorType,
12221
- errorCode: errorCode
12222
- });
12223
- }
12224
- };
12234
+ res('Cool, connected to AWS AppSyncRealTime');
12235
+ return;
12236
+ }
12225
12237
 
12226
- var gqlInit = {
12227
- type: MESSAGE_TYPES.GQL_CONNECTION_INIT
12228
- };
12238
+ if (type === MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
12239
+ var _c = data.payload,
12240
+ _d = (_c === void 0 ? {} : _c).errors,
12241
+ _e = __read(_d === void 0 ? [] : _d, 1),
12242
+ _f = _e[0],
12243
+ _g = _f === void 0 ? {} : _f,
12244
+ _h = _g.errorType,
12245
+ errorType = _h === void 0 ? '' : _h,
12246
+ _j = _g.errorCode,
12247
+ errorCode = _j === void 0 ? 0 : _j;
12248
+
12249
+ rej({
12250
+ errorType: errorType,
12251
+ errorCode: errorCode
12252
+ });
12253
+ }
12254
+ };
12255
+
12256
+ var gqlInit = {
12257
+ type: MESSAGE_TYPES.GQL_CONNECTION_INIT
12258
+ };
12259
+
12260
+ _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
12229
12261
 
12230
- _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
12262
+ setTimeout(checkAckOk.bind(_this, ackOk_1), CONNECTION_INIT_TIMEOUT);
12263
+ }
12231
12264
 
12232
- function checkAckOk() {
12265
+ function checkAckOk(ackOk) {
12233
12266
  if (!ackOk) {
12234
12267
  rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + CONNECTION_INIT_TIMEOUT + " ms"));
12235
12268
  }
12236
12269
  }
12237
-
12238
- setTimeout(checkAckOk.bind(_this), CONNECTION_INIT_TIMEOUT);
12239
12270
  });
12240
12271
  }()];
12241
12272
 
@@ -12249,7 +12280,7 @@ function (_super) {
12249
12280
 
12250
12281
  case 4:
12251
12282
  err_4 = _b.sent();
12252
- errorType = err_4.errorType, errorCode = err_4.errorCode;
12283
+ _a = err_4, errorType = _a.errorType, errorCode = _a.errorCode;
12253
12284
 
12254
12285
  if (NON_RETRYABLE_CODES.includes(errorCode)) {
12255
12286
  throw new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["NonRetryableError"](errorType);
@@ -12292,16 +12323,17 @@ function (_super) {
12292
12323
  AMAZON_COGNITO_USER_POOLS: this._awsRealTimeCUPHeader.bind(this),
12293
12324
  AWS_LAMBDA: this._customAuthHeader
12294
12325
  };
12295
- handler = headerHandler[authenticationType];
12296
-
12297
- if (typeof handler !== 'function') {
12298
- logger.debug("Authentication type " + authenticationType + " not supported");
12299
- return [2
12300
- /*return*/
12301
- , ''];
12302
- }
12326
+ if (!(!authenticationType || !headerHandler[authenticationType])) return [3
12327
+ /*break*/
12328
+ , 1];
12329
+ logger.debug("Authentication type " + authenticationType + " not supported");
12330
+ return [2
12331
+ /*return*/
12332
+ , ''];
12303
12333
 
12304
- host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint).host;
12334
+ case 1:
12335
+ handler = headerHandler[authenticationType];
12336
+ host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
12305
12337
  return [4
12306
12338
  /*yield*/
12307
12339
  , handler({
@@ -12314,7 +12346,7 @@ function (_super) {
12314
12346
  additionalHeaders: additionalHeaders
12315
12347
  })];
12316
12348
 
12317
- case 1:
12349
+ case 2:
12318
12350
  result = _b.sent();
12319
12351
  return [2
12320
12352
  /*return*/
@@ -12446,10 +12478,14 @@ function (_super) {
12446
12478
  return [4
12447
12479
  /*yield*/
12448
12480
  , _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Credentials"].get().then(function (credentials) {
12481
+ var _a = credentials,
12482
+ secretAccessKey = _a.secretAccessKey,
12483
+ accessKeyId = _a.accessKeyId,
12484
+ sessionToken = _a.sessionToken;
12449
12485
  return {
12450
- secret_key: credentials.secretAccessKey,
12451
- access_key: credentials.accessKeyId,
12452
- session_token: credentials.sessionToken
12486
+ secret_key: secretAccessKey,
12487
+ access_key: accessKeyId,
12488
+ session_token: sessionToken
12453
12489
  };
12454
12490
  })];
12455
12491
 
@@ -12474,7 +12510,7 @@ function (_super) {
12474
12510
  var host = _a.host,
12475
12511
  additionalHeaders = _a.additionalHeaders;
12476
12512
 
12477
- if (!additionalHeaders.Authorization) {
12513
+ if (!additionalHeaders || !additionalHeaders['Authorization']) {
12478
12514
  throw new Error('No auth token specified');
12479
12515
  }
12480
12516
 
@@ -12711,8 +12747,12 @@ var AWSIoTProvider =
12711
12747
  function (_super) {
12712
12748
  __extends(AWSIoTProvider, _super);
12713
12749
 
12714
- function AWSIoTProvider() {
12715
- return _super !== null && _super.apply(this, arguments) || this;
12750
+ function AWSIoTProvider(options) {
12751
+ if (options === void 0) {
12752
+ options = {};
12753
+ }
12754
+
12755
+ return _super.call(this, options) || this;
12716
12756
  }
12717
12757
 
12718
12758
  Object.defineProperty(AWSIoTProvider.prototype, "region", {
@@ -13042,21 +13082,27 @@ function () {
13042
13082
 
13043
13083
  ClientsQueue.prototype.get = function (clientId, clientFactory) {
13044
13084
  return __awaiter(this, void 0, void 0, function () {
13045
- var promise;
13085
+ var cachedPromise, newPromise;
13046
13086
  return __generator(this, function (_a) {
13047
- promise = this.promises.get(clientId);
13087
+ cachedPromise = this.promises.get(clientId);
13088
+
13089
+ if (cachedPromise) {
13090
+ return [2
13091
+ /*return*/
13092
+ , cachedPromise];
13093
+ }
13048
13094
 
13049
- if (promise) {
13095
+ if (clientFactory) {
13096
+ newPromise = clientFactory(clientId);
13097
+ this.promises.set(clientId, newPromise);
13050
13098
  return [2
13051
13099
  /*return*/
13052
- , promise];
13100
+ , newPromise];
13053
13101
  }
13054
13102
 
13055
- promise = clientFactory(clientId);
13056
- this.promises.set(clientId, promise);
13057
13103
  return [2
13058
13104
  /*return*/
13059
- , promise];
13105
+ , undefined];
13060
13106
  });
13061
13107
  });
13062
13108
  };
@@ -13148,6 +13194,10 @@ function (_super) {
13148
13194
  }, args), null, 2));
13149
13195
  var topicsToDelete_1 = [];
13150
13196
 
13197
+ if (!clientId) {
13198
+ return;
13199
+ }
13200
+
13151
13201
  var clientIdObservers = this._clientIdObservers.get(clientId);
13152
13202
 
13153
13203
  if (!clientIdObservers) {
@@ -13266,9 +13316,7 @@ function (_super) {
13266
13316
  case 0:
13267
13317
  return [4
13268
13318
  /*yield*/
13269
- , this.clientsQueue.get(clientId, function () {
13270
- return null;
13271
- })];
13319
+ , this.clientsQueue.get(clientId)];
13272
13320
 
13273
13321
  case 1:
13274
13322
  client = _a.sent();
@@ -13447,13 +13495,14 @@ function (_super) {
13447
13495
  })();
13448
13496
 
13449
13497
  return function () {
13498
+ var _a, _b;
13499
+
13450
13500
  logger.debug('Unsubscribing from topic(s)', targetTopics.join(','));
13451
13501
 
13452
13502
  if (client) {
13453
- _this._clientIdObservers.get(clientId)["delete"](observer); // No more observers per client => client not needed anymore
13503
+ (_a = _this._clientIdObservers.get(clientId)) === null || _a === void 0 ? void 0 : _a["delete"](observer); // No more observers per client => client not needed anymore
13454
13504
 
13455
-
13456
- if (_this._clientIdObservers.get(clientId).size === 0) {
13505
+ if (((_b = _this._clientIdObservers.get(clientId)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
13457
13506
  _this.disconnect(clientId);
13458
13507
 
13459
13508
  _this._clientIdObservers["delete"](clientId);
@@ -13788,7 +13837,7 @@ function () {
13788
13837
  * @param {PubSubOptions} options - Configuration object for PubSub
13789
13838
  */
13790
13839
  function PubSubClass(options) {
13791
- this._options = options;
13840
+ this._options = options !== null && options !== void 0 ? options : {};
13792
13841
  logger.debug('PubSub Options', this._options);
13793
13842
  this._pluggables = [];
13794
13843
  this.subscribe = this.subscribe.bind(this);
@@ -13977,7 +14026,7 @@ function () {
13977
14026
  }();
13978
14027
 
13979
14028
 
13980
- var PubSub = new PubSubClass(null);
14029
+ var PubSub = new PubSubClass();
13981
14030
  _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Amplify"].register(PubSub);
13982
14031
 
13983
14032
  /***/ }),
@@ -14929,17 +14978,12 @@ __webpack_require__.r(__webpack_exports__);
14929
14978
 
14930
14979
  "use strict";
14931
14980
  __webpack_require__.r(__webpack_exports__);
14932
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GRAPHQL_AUTH_MODE", function() { return GRAPHQL_AUTH_MODE; });
14933
14981
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GraphQLAuthError", function() { return GraphQLAuthError; });
14934
- var GRAPHQL_AUTH_MODE;
14935
-
14936
- (function (GRAPHQL_AUTH_MODE) {
14937
- GRAPHQL_AUTH_MODE["API_KEY"] = "API_KEY";
14938
- GRAPHQL_AUTH_MODE["AWS_IAM"] = "AWS_IAM";
14939
- GRAPHQL_AUTH_MODE["OPENID_CONNECT"] = "OPENID_CONNECT";
14940
- GRAPHQL_AUTH_MODE["AMAZON_COGNITO_USER_POOLS"] = "AMAZON_COGNITO_USER_POOLS";
14941
- GRAPHQL_AUTH_MODE["AWS_LAMBDA"] = "AWS_LAMBDA";
14942
- })(GRAPHQL_AUTH_MODE || (GRAPHQL_AUTH_MODE = {}));
14982
+ /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @aws-amplify/auth */ "@aws-amplify/auth");
14983
+ /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_0__);
14984
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GRAPHQL_AUTH_MODE", function() { return _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_0__["GRAPHQL_AUTH_MODE"]; });
14985
+
14986
+
14943
14987
 
14944
14988
  var GraphQLAuthError;
14945
14989