@aws-amplify/pubsub 4.2.5 → 4.2.6-custom-pk.79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/CHANGELOG.md +149 -0
  2. package/dist/aws-amplify-pubsub.js +404 -339
  3. package/dist/aws-amplify-pubsub.js.map +1 -1
  4. package/dist/aws-amplify-pubsub.min.js +2 -2
  5. package/dist/aws-amplify-pubsub.min.js.map +1 -1
  6. package/lib/Providers/AWSAppSyncProvider.d.ts +3 -0
  7. package/lib/Providers/AWSAppSyncProvider.js +3 -0
  8. package/lib/Providers/AWSAppSyncProvider.js.map +1 -1
  9. package/lib/Providers/AWSAppSyncRealTimeProvider/constants.d.ts +82 -0
  10. package/lib/Providers/AWSAppSyncRealTimeProvider/constants.js +90 -0
  11. package/lib/Providers/AWSAppSyncRealTimeProvider/constants.js.map +1 -0
  12. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +64 -0
  13. package/lib/Providers/{AWSAppSyncRealTimeProvider.js → AWSAppSyncRealTimeProvider/index.js} +214 -273
  14. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -0
  15. package/lib/Providers/AWSIotProvider.d.ts +6 -1
  16. package/lib/Providers/AWSIotProvider.js +3 -2
  17. package/lib/Providers/AWSIotProvider.js.map +1 -1
  18. package/lib/Providers/MqttOverWSProvider.d.ts +14 -11
  19. package/lib/Providers/MqttOverWSProvider.js +17 -10
  20. package/lib/Providers/MqttOverWSProvider.js.map +1 -1
  21. package/lib/Providers/PubSubProvider.d.ts +7 -7
  22. package/lib/Providers/PubSubProvider.js.map +1 -1
  23. package/lib/PubSub.d.ts +6 -6
  24. package/lib/PubSub.js +2 -2
  25. package/lib/PubSub.js.map +1 -1
  26. package/lib/types/Provider.d.ts +3 -3
  27. package/lib/types/PubSub.d.ts +5 -1
  28. package/lib-esm/Providers/AWSAppSyncProvider.d.ts +3 -0
  29. package/lib-esm/Providers/AWSAppSyncProvider.js +3 -0
  30. package/lib-esm/Providers/AWSAppSyncProvider.js.map +1 -1
  31. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.d.ts +82 -0
  32. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js +88 -0
  33. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js.map +1 -0
  34. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +64 -0
  35. package/lib-esm/Providers/{AWSAppSyncRealTimeProvider.js → AWSAppSyncRealTimeProvider/index.js} +188 -247
  36. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -0
  37. package/lib-esm/Providers/AWSIotProvider.d.ts +6 -1
  38. package/lib-esm/Providers/AWSIotProvider.js +3 -2
  39. package/lib-esm/Providers/AWSIotProvider.js.map +1 -1
  40. package/lib-esm/Providers/MqttOverWSProvider.d.ts +14 -11
  41. package/lib-esm/Providers/MqttOverWSProvider.js +17 -10
  42. package/lib-esm/Providers/MqttOverWSProvider.js.map +1 -1
  43. package/lib-esm/Providers/PubSubProvider.d.ts +7 -7
  44. package/lib-esm/Providers/PubSubProvider.js.map +1 -1
  45. package/lib-esm/PubSub.d.ts +6 -6
  46. package/lib-esm/PubSub.js +2 -2
  47. package/lib-esm/PubSub.js.map +1 -1
  48. package/lib-esm/types/Provider.d.ts +3 -3
  49. package/lib-esm/types/PubSub.d.ts +5 -1
  50. package/package.json +13 -7
  51. package/src/Providers/AWSAppSyncProvider.ts +27 -26
  52. package/src/Providers/AWSAppSyncRealTimeProvider/constants.ts +95 -0
  53. package/src/Providers/{AWSAppSyncRealTimeProvider.ts → AWSAppSyncRealTimeProvider/index.ts} +276 -303
  54. package/src/Providers/AWSIotProvider.ts +10 -1
  55. package/src/Providers/MqttOverWSProvider.ts +52 -33
  56. package/src/Providers/PubSubProvider.ts +8 -8
  57. package/src/PubSub.ts +10 -10
  58. package/src/types/Provider.ts +3 -7
  59. package/src/types/PubSub.ts +6 -1
  60. package/lib/Providers/AWSAppSyncRealTimeProvider.d.ts +0 -38
  61. package/lib/Providers/AWSAppSyncRealTimeProvider.js.map +0 -1
  62. package/lib-esm/Providers/AWSAppSyncRealTimeProvider.d.ts +0 -38
  63. package/lib-esm/Providers/AWSAppSyncRealTimeProvider.js.map +0 -1
@@ -7305,6 +7305,9 @@ var __spread = undefined && undefined.__spread || function () {
7305
7305
 
7306
7306
 
7307
7307
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["ConsoleLogger"]('AWSAppSyncProvider');
7308
+ /**
7309
+ * @deprecated Unused, all usecases have migrated to AWSAppSyncRealtimeProvider
7310
+ */
7308
7311
 
7309
7312
  var AWSAppSyncProvider =
7310
7313
  /** @class */
@@ -7611,10 +7614,135 @@ function (_super) {
7611
7614
 
7612
7615
  /***/ }),
7613
7616
 
7614
- /***/ "./lib-esm/Providers/AWSAppSyncRealTimeProvider.js":
7615
- /*!*********************************************************!*\
7616
- !*** ./lib-esm/Providers/AWSAppSyncRealTimeProvider.js ***!
7617
- \*********************************************************/
7617
+ /***/ "./lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js":
7618
+ /*!*******************************************************************!*\
7619
+ !*** ./lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js ***!
7620
+ \*******************************************************************/
7621
+ /*! exports provided: MAX_DELAY_MS, NON_RETRYABLE_CODES, MESSAGE_TYPES, SUBSCRIPTION_STATUS, SOCKET_STATUS, AMPLIFY_SYMBOL, AWS_APPSYNC_REALTIME_HEADERS, CONNECTION_INIT_TIMEOUT, START_ACK_TIMEOUT, DEFAULT_KEEP_ALIVE_TIMEOUT */
7622
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
7623
+
7624
+ "use strict";
7625
+ __webpack_require__.r(__webpack_exports__);
7626
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MAX_DELAY_MS", function() { return MAX_DELAY_MS; });
7627
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "NON_RETRYABLE_CODES", function() { return NON_RETRYABLE_CODES; });
7628
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MESSAGE_TYPES", function() { return MESSAGE_TYPES; });
7629
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SUBSCRIPTION_STATUS", function() { return SUBSCRIPTION_STATUS; });
7630
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SOCKET_STATUS", function() { return SOCKET_STATUS; });
7631
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AMPLIFY_SYMBOL", function() { return AMPLIFY_SYMBOL; });
7632
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AWS_APPSYNC_REALTIME_HEADERS", function() { return AWS_APPSYNC_REALTIME_HEADERS; });
7633
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_INIT_TIMEOUT", function() { return CONNECTION_INIT_TIMEOUT; });
7634
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "START_ACK_TIMEOUT", function() { return START_ACK_TIMEOUT; });
7635
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_TIMEOUT; });
7636
+ var MAX_DELAY_MS = 5000;
7637
+ var NON_RETRYABLE_CODES = [400, 401, 403];
7638
+ var MESSAGE_TYPES;
7639
+
7640
+ (function (MESSAGE_TYPES) {
7641
+ /**
7642
+ * Client -> Server message.
7643
+ * This message type is the first message after handshake and this will initialize AWS AppSync RealTime communication
7644
+ */
7645
+ MESSAGE_TYPES["GQL_CONNECTION_INIT"] = "connection_init";
7646
+ /**
7647
+ * Server -> Client message
7648
+ * This message type is in case there is an issue with AWS AppSync RealTime when establishing connection
7649
+ */
7650
+
7651
+ MESSAGE_TYPES["GQL_CONNECTION_ERROR"] = "connection_error";
7652
+ /**
7653
+ * Server -> Client message.
7654
+ * This message type is for the ack response from AWS AppSync RealTime for GQL_CONNECTION_INIT message
7655
+ */
7656
+
7657
+ MESSAGE_TYPES["GQL_CONNECTION_ACK"] = "connection_ack";
7658
+ /**
7659
+ * Client -> Server message.
7660
+ * This message type is for register subscriptions with AWS AppSync RealTime
7661
+ */
7662
+
7663
+ MESSAGE_TYPES["GQL_START"] = "start";
7664
+ /**
7665
+ * Server -> Client message.
7666
+ * This message type is for the ack response from AWS AppSync RealTime for GQL_START message
7667
+ */
7668
+
7669
+ MESSAGE_TYPES["GQL_START_ACK"] = "start_ack";
7670
+ /**
7671
+ * Server -> Client message.
7672
+ * This message type is for subscription message from AWS AppSync RealTime
7673
+ */
7674
+
7675
+ MESSAGE_TYPES["GQL_DATA"] = "data";
7676
+ /**
7677
+ * Server -> Client message.
7678
+ * This message type helps the client to know is still receiving messages from AWS AppSync RealTime
7679
+ */
7680
+
7681
+ MESSAGE_TYPES["GQL_CONNECTION_KEEP_ALIVE"] = "ka";
7682
+ /**
7683
+ * Client -> Server message.
7684
+ * This message type is for unregister subscriptions with AWS AppSync RealTime
7685
+ */
7686
+
7687
+ MESSAGE_TYPES["GQL_STOP"] = "stop";
7688
+ /**
7689
+ * Server -> Client message.
7690
+ * This message type is for the ack response from AWS AppSync RealTime for GQL_STOP message
7691
+ */
7692
+
7693
+ MESSAGE_TYPES["GQL_COMPLETE"] = "complete";
7694
+ /**
7695
+ * Server -> Client message.
7696
+ * This message type is for sending error messages from AWS AppSync RealTime to the client
7697
+ */
7698
+
7699
+ MESSAGE_TYPES["GQL_ERROR"] = "error";
7700
+ })(MESSAGE_TYPES || (MESSAGE_TYPES = {}));
7701
+
7702
+ var SUBSCRIPTION_STATUS;
7703
+
7704
+ (function (SUBSCRIPTION_STATUS) {
7705
+ SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["PENDING"] = 0] = "PENDING";
7706
+ SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["CONNECTED"] = 1] = "CONNECTED";
7707
+ SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["FAILED"] = 2] = "FAILED";
7708
+ })(SUBSCRIPTION_STATUS || (SUBSCRIPTION_STATUS = {}));
7709
+
7710
+ var SOCKET_STATUS;
7711
+
7712
+ (function (SOCKET_STATUS) {
7713
+ SOCKET_STATUS[SOCKET_STATUS["CLOSED"] = 0] = "CLOSED";
7714
+ SOCKET_STATUS[SOCKET_STATUS["READY"] = 1] = "READY";
7715
+ SOCKET_STATUS[SOCKET_STATUS["CONNECTING"] = 2] = "CONNECTING";
7716
+ })(SOCKET_STATUS || (SOCKET_STATUS = {}));
7717
+
7718
+ var AMPLIFY_SYMBOL = typeof Symbol !== 'undefined' && typeof Symbol["for"] === 'function' ? Symbol["for"]('amplify_default') : '@@amplify_default';
7719
+ var AWS_APPSYNC_REALTIME_HEADERS = {
7720
+ accept: 'application/json, text/javascript',
7721
+ 'content-encoding': 'amz-1.0',
7722
+ 'content-type': 'application/json; charset=UTF-8'
7723
+ };
7724
+ /**
7725
+ * Time in milleseconds to wait for GQL_CONNECTION_INIT message
7726
+ */
7727
+
7728
+ var CONNECTION_INIT_TIMEOUT = 15000;
7729
+ /**
7730
+ * Time in milleseconds to wait for GQL_START_ACK message
7731
+ */
7732
+
7733
+ var START_ACK_TIMEOUT = 15000;
7734
+ /**
7735
+ * Default Time in milleseconds to wait for GQL_CONNECTION_KEEP_ALIVE message
7736
+ */
7737
+
7738
+ var DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000;
7739
+
7740
+ /***/ }),
7741
+
7742
+ /***/ "./lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js":
7743
+ /*!***************************************************************!*\
7744
+ !*** ./lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js ***!
7745
+ \***************************************************************/
7618
7746
  /*! exports provided: AWSAppSyncRealTimeProvider */
7619
7747
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
7620
7748
 
@@ -7636,8 +7764,9 @@ __webpack_require__.r(__webpack_exports__);
7636
7764
  /* harmony import */ var _aws_amplify_cache__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_cache__WEBPACK_IMPORTED_MODULE_6__);
7637
7765
  /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @aws-amplify/auth */ "@aws-amplify/auth");
7638
7766
  /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_7__);
7639
- /* harmony import */ var _PubSubProvider__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./PubSubProvider */ "./lib-esm/Providers/PubSubProvider.js");
7640
- /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../index */ "./lib-esm/index.js");
7767
+ /* harmony import */ var _PubSubProvider__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../PubSubProvider */ "./lib-esm/Providers/PubSubProvider.js");
7768
+ /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../index */ "./lib-esm/index.js");
7769
+ /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./constants */ "./lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js");
7641
7770
  var __extends = undefined && undefined.__extends || function () {
7642
7771
  var _extendStatics = function extendStatics(d, b) {
7643
7772
  _extendStatics = Object.setPrototypeOf || {
@@ -7873,119 +8002,17 @@ var __read = undefined && undefined.__read || function (o, n) {
7873
8002
 
7874
8003
 
7875
8004
 
8005
+
7876
8006
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Logger"]('AWSAppSyncRealTimeProvider');
7877
- var AMPLIFY_SYMBOL = typeof Symbol !== 'undefined' && typeof Symbol["for"] === 'function' ? Symbol["for"]('amplify_default') : '@@amplify_default';
7878
8007
 
7879
8008
  var dispatchApiEvent = function dispatchApiEvent(event, data, message) {
7880
8009
  _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Hub"].dispatch('api', {
7881
8010
  event: event,
7882
8011
  data: data,
7883
8012
  message: message
7884
- }, 'PubSub', AMPLIFY_SYMBOL);
8013
+ }, 'PubSub', _constants__WEBPACK_IMPORTED_MODULE_10__["AMPLIFY_SYMBOL"]);
7885
8014
  };
7886
8015
 
7887
- var MAX_DELAY_MS = 5000;
7888
- var NON_RETRYABLE_CODES = [400, 401, 403];
7889
- var MESSAGE_TYPES;
7890
-
7891
- (function (MESSAGE_TYPES) {
7892
- /**
7893
- * Client -> Server message.
7894
- * This message type is the first message after handshake and this will initialize AWS AppSync RealTime communication
7895
- */
7896
- MESSAGE_TYPES["GQL_CONNECTION_INIT"] = "connection_init";
7897
- /**
7898
- * Server -> Client message
7899
- * This message type is in case there is an issue with AWS AppSync RealTime when establishing connection
7900
- */
7901
-
7902
- MESSAGE_TYPES["GQL_CONNECTION_ERROR"] = "connection_error";
7903
- /**
7904
- * Server -> Client message.
7905
- * This message type is for the ack response from AWS AppSync RealTime for GQL_CONNECTION_INIT message
7906
- */
7907
-
7908
- MESSAGE_TYPES["GQL_CONNECTION_ACK"] = "connection_ack";
7909
- /**
7910
- * Client -> Server message.
7911
- * This message type is for register subscriptions with AWS AppSync RealTime
7912
- */
7913
-
7914
- MESSAGE_TYPES["GQL_START"] = "start";
7915
- /**
7916
- * Server -> Client message.
7917
- * This message type is for the ack response from AWS AppSync RealTime for GQL_START message
7918
- */
7919
-
7920
- MESSAGE_TYPES["GQL_START_ACK"] = "start_ack";
7921
- /**
7922
- * Server -> Client message.
7923
- * This message type is for subscription message from AWS AppSync RealTime
7924
- */
7925
-
7926
- MESSAGE_TYPES["GQL_DATA"] = "data";
7927
- /**
7928
- * Server -> Client message.
7929
- * This message type helps the client to know is still receiving messages from AWS AppSync RealTime
7930
- */
7931
-
7932
- MESSAGE_TYPES["GQL_CONNECTION_KEEP_ALIVE"] = "ka";
7933
- /**
7934
- * Client -> Server message.
7935
- * This message type is for unregister subscriptions with AWS AppSync RealTime
7936
- */
7937
-
7938
- MESSAGE_TYPES["GQL_STOP"] = "stop";
7939
- /**
7940
- * Server -> Client message.
7941
- * This message type is for the ack response from AWS AppSync RealTime for GQL_STOP message
7942
- */
7943
-
7944
- MESSAGE_TYPES["GQL_COMPLETE"] = "complete";
7945
- /**
7946
- * Server -> Client message.
7947
- * This message type is for sending error messages from AWS AppSync RealTime to the client
7948
- */
7949
-
7950
- MESSAGE_TYPES["GQL_ERROR"] = "error";
7951
- })(MESSAGE_TYPES || (MESSAGE_TYPES = {}));
7952
-
7953
- var SUBSCRIPTION_STATUS;
7954
-
7955
- (function (SUBSCRIPTION_STATUS) {
7956
- SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["PENDING"] = 0] = "PENDING";
7957
- SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["CONNECTED"] = 1] = "CONNECTED";
7958
- SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["FAILED"] = 2] = "FAILED";
7959
- })(SUBSCRIPTION_STATUS || (SUBSCRIPTION_STATUS = {}));
7960
-
7961
- var SOCKET_STATUS;
7962
-
7963
- (function (SOCKET_STATUS) {
7964
- SOCKET_STATUS[SOCKET_STATUS["CLOSED"] = 0] = "CLOSED";
7965
- SOCKET_STATUS[SOCKET_STATUS["READY"] = 1] = "READY";
7966
- SOCKET_STATUS[SOCKET_STATUS["CONNECTING"] = 2] = "CONNECTING";
7967
- })(SOCKET_STATUS || (SOCKET_STATUS = {}));
7968
-
7969
- var AWS_APPSYNC_REALTIME_HEADERS = {
7970
- accept: 'application/json, text/javascript',
7971
- 'content-encoding': 'amz-1.0',
7972
- 'content-type': 'application/json; charset=UTF-8'
7973
- };
7974
- /**
7975
- * Time in milleseconds to wait for GQL_CONNECTION_INIT message
7976
- */
7977
-
7978
- var CONNECTION_INIT_TIMEOUT = 15000;
7979
- /**
7980
- * Time in milleseconds to wait for GQL_START_ACK message
7981
- */
7982
-
7983
- var START_ACK_TIMEOUT = 15000;
7984
- /**
7985
- * Default Time in milleseconds to wait for GQL_CONNECTION_KEEP_ALIVE message
7986
- */
7987
-
7988
- var DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000;
7989
8016
  var standardDomainPattern = /^https:\/\/\w{26}\.appsync\-api\.\w{2}(?:(?:\-\w{2,})+)\-\d\.amazonaws.com\/graphql$/i;
7990
8017
  var customDomainPath = '/realtime';
7991
8018
 
@@ -7997,13 +8024,17 @@ function (_super) {
7997
8024
  function AWSAppSyncRealTimeProvider() {
7998
8025
  var _this = _super !== null && _super.apply(this, arguments) || this;
7999
8026
 
8000
- _this.socketStatus = SOCKET_STATUS.CLOSED;
8001
- _this.keepAliveTimeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
8027
+ _this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
8028
+ _this.keepAliveTimeout = _constants__WEBPACK_IMPORTED_MODULE_10__["DEFAULT_KEEP_ALIVE_TIMEOUT"];
8002
8029
  _this.subscriptionObserverMap = new Map();
8003
8030
  _this.promiseArray = [];
8004
8031
  return _this;
8005
8032
  }
8006
8033
 
8034
+ AWSAppSyncRealTimeProvider.prototype.getNewWebSocket = function (url, protocol) {
8035
+ return new WebSocket(url, protocol);
8036
+ };
8037
+
8007
8038
  AWSAppSyncRealTimeProvider.prototype.getProviderName = function () {
8008
8039
  return 'AWSAppSyncRealTimeProvider';
8009
8040
  };
@@ -8028,9 +8059,9 @@ function (_super) {
8028
8059
  AWSAppSyncRealTimeProvider.prototype.subscribe = function (_topics, options) {
8029
8060
  var _this = this;
8030
8061
 
8031
- var appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint;
8062
+ var appSyncGraphqlEndpoint = options === null || options === void 0 ? void 0 : options.appSyncGraphqlEndpoint;
8032
8063
  return new zen_observable_ts__WEBPACK_IMPORTED_MODULE_0__["default"](function (observer) {
8033
- if (!appSyncGraphqlEndpoint) {
8064
+ if (!options || !appSyncGraphqlEndpoint) {
8034
8065
  observer.error({
8035
8066
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscribe only available for AWS AppSync endpoint"))]
8036
8067
  });
@@ -8075,7 +8106,7 @@ function (_super) {
8075
8106
  ];
8076
8107
  }
8077
8108
 
8078
- if (subscriptionState === SUBSCRIPTION_STATUS.CONNECTED) {
8109
+ if (subscriptionState === _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].CONNECTED) {
8079
8110
  this._sendUnsubscriptionMessage(subscriptionId_1);
8080
8111
  } else {
8081
8112
  throw new Error('Subscription never connected');
@@ -8123,20 +8154,23 @@ function (_super) {
8123
8154
  var options = _a.options,
8124
8155
  observer = _a.observer,
8125
8156
  subscriptionId = _a.subscriptionId;
8157
+
8158
+ var _b, _c;
8159
+
8126
8160
  return __awaiter(this, void 0, void 0, function () {
8127
- 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;
8161
+ 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;
8128
8162
 
8129
- var _h;
8163
+ var _j;
8130
8164
 
8131
8165
  var _this = this;
8132
8166
 
8133
- return __generator(this, function (_j) {
8134
- switch (_j.label) {
8167
+ return __generator(this, function (_k) {
8168
+ switch (_k.label) {
8135
8169
  case 0:
8136
- 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 () {
8170
+ 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 () {
8137
8171
  return {};
8138
- } : _b, _c = options.additionalHeaders, additionalHeaders = _c === void 0 ? {} : _c;
8139
- subscriptionState = SUBSCRIPTION_STATUS.PENDING;
8172
+ } : _d, _e = options.additionalHeaders, additionalHeaders = _e === void 0 ? {} : _e;
8173
+ subscriptionState = _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].PENDING;
8140
8174
  data = {
8141
8175
  query: query,
8142
8176
  variables: variables
@@ -8144,13 +8178,13 @@ function (_super) {
8144
8178
 
8145
8179
  this.subscriptionObserverMap.set(subscriptionId, {
8146
8180
  observer: observer,
8147
- query: query,
8148
- variables: variables,
8181
+ query: query !== null && query !== void 0 ? query : '',
8182
+ variables: variables !== null && variables !== void 0 ? variables : {},
8149
8183
  subscriptionState: subscriptionState,
8150
- startAckTimeoutId: null
8184
+ startAckTimeoutId: undefined
8151
8185
  });
8152
8186
  dataString = JSON.stringify(data);
8153
- _d = [{}];
8187
+ _f = [{}];
8154
8188
  return [4
8155
8189
  /*yield*/
8156
8190
  , this._awsRealTimeHeaderBasedAuth({
@@ -8164,13 +8198,13 @@ function (_super) {
8164
8198
  })];
8165
8199
 
8166
8200
  case 1:
8167
- _e = [__assign.apply(void 0, _d.concat([_j.sent()]))];
8201
+ _g = [__assign.apply(void 0, _f.concat([_k.sent()]))];
8168
8202
  return [4
8169
8203
  /*yield*/
8170
8204
  , graphql_headers()];
8171
8205
 
8172
8206
  case 2:
8173
- 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)]);
8207
+ 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)]);
8174
8208
  subscriptionMessage = {
8175
8209
  id: subscriptionId,
8176
8210
  payload: {
@@ -8179,13 +8213,13 @@ function (_super) {
8179
8213
  authorization: __assign({}, headerObj)
8180
8214
  }
8181
8215
  },
8182
- type: MESSAGE_TYPES.GQL_START
8216
+ type: _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_START
8183
8217
  };
8184
8218
  stringToAWSRealTime = JSON.stringify(subscriptionMessage);
8185
- _j.label = 3;
8219
+ _k.label = 3;
8186
8220
 
8187
8221
  case 3:
8188
- _j.trys.push([3, 5,, 6]);
8222
+ _k.trys.push([3, 5,, 6]);
8189
8223
 
8190
8224
  return [4
8191
8225
  /*yield*/
@@ -8198,18 +8232,18 @@ function (_super) {
8198
8232
  })];
8199
8233
 
8200
8234
  case 4:
8201
- _j.sent();
8235
+ _k.sent();
8202
8236
 
8203
8237
  return [3
8204
8238
  /*break*/
8205
8239
  , 6];
8206
8240
 
8207
8241
  case 5:
8208
- err_2 = _j.sent();
8242
+ err_2 = _k.sent();
8209
8243
  logger.debug({
8210
8244
  err: err_2
8211
8245
  });
8212
- _f = err_2.message, message = _f === void 0 ? '' : _f;
8246
+ message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
8213
8247
  observer.error({
8214
8248
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
8215
8249
  });
@@ -8225,18 +8259,18 @@ function (_super) {
8225
8259
  ];
8226
8260
 
8227
8261
  case 6:
8228
- _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
8262
+ _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
8229
8263
 
8230
8264
  this.subscriptionObserverMap.set(subscriptionId, {
8231
8265
  observer: observer,
8232
8266
  subscriptionState: subscriptionState,
8233
- variables: variables,
8234
- query: query,
8267
+ query: query !== null && query !== void 0 ? query : '',
8268
+ variables: variables !== null && variables !== void 0 ? variables : {},
8235
8269
  subscriptionReadyCallback: subscriptionReadyCallback,
8236
8270
  subscriptionFailedCallback: subscriptionFailedCallback,
8237
8271
  startAckTimeoutId: setTimeout(function () {
8238
8272
  _this._timeoutStartSubscriptionAck.call(_this, subscriptionId);
8239
- }, START_ACK_TIMEOUT)
8273
+ }, _constants__WEBPACK_IMPORTED_MODULE_10__["START_ACK_TIMEOUT"])
8240
8274
  });
8241
8275
 
8242
8276
  if (this.awsRealTimeSocket) {
@@ -8254,32 +8288,35 @@ function (_super) {
8254
8288
 
8255
8289
  AWSAppSyncRealTimeProvider.prototype._waitForSubscriptionToBeConnected = function (subscriptionId) {
8256
8290
  return __awaiter(this, void 0, void 0, function () {
8257
- var subscriptionState;
8291
+ var subscriptionObserver, subscriptionState;
8258
8292
 
8259
8293
  var _this = this;
8260
8294
 
8261
8295
  return __generator(this, function (_a) {
8262
- subscriptionState = this.subscriptionObserverMap.get(subscriptionId).subscriptionState; // This in case unsubscribe is invoked before sending start subscription message
8296
+ subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
8263
8297
 
8264
- if (subscriptionState === SUBSCRIPTION_STATUS.PENDING) {
8265
- return [2
8266
- /*return*/
8267
- , new Promise(function (res, rej) {
8268
- var _a = _this.subscriptionObserverMap.get(subscriptionId),
8269
- observer = _a.observer,
8270
- subscriptionState = _a.subscriptionState,
8271
- variables = _a.variables,
8272
- query = _a.query;
8273
-
8274
- _this.subscriptionObserverMap.set(subscriptionId, {
8275
- observer: observer,
8276
- subscriptionState: subscriptionState,
8277
- variables: variables,
8278
- query: query,
8279
- subscriptionReadyCallback: res,
8280
- subscriptionFailedCallback: rej
8281
- });
8282
- })];
8298
+ if (subscriptionObserver) {
8299
+ subscriptionState = subscriptionObserver.subscriptionState; // This in case unsubscribe is invoked before sending start subscription message
8300
+
8301
+ if (subscriptionState === _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].PENDING) {
8302
+ return [2
8303
+ /*return*/
8304
+ , new Promise(function (res, rej) {
8305
+ var observer = subscriptionObserver.observer,
8306
+ subscriptionState = subscriptionObserver.subscriptionState,
8307
+ variables = subscriptionObserver.variables,
8308
+ query = subscriptionObserver.query;
8309
+
8310
+ _this.subscriptionObserverMap.set(subscriptionId, {
8311
+ observer: observer,
8312
+ subscriptionState: subscriptionState,
8313
+ variables: variables,
8314
+ query: query,
8315
+ subscriptionReadyCallback: res,
8316
+ subscriptionFailedCallback: rej
8317
+ });
8318
+ })];
8319
+ }
8283
8320
  }
8284
8321
 
8285
8322
  return [2
@@ -8291,11 +8328,11 @@ function (_super) {
8291
8328
 
8292
8329
  AWSAppSyncRealTimeProvider.prototype._sendUnsubscriptionMessage = function (subscriptionId) {
8293
8330
  try {
8294
- if (this.awsRealTimeSocket && this.awsRealTimeSocket.readyState === WebSocket.OPEN && this.socketStatus === SOCKET_STATUS.READY) {
8331
+ if (this.awsRealTimeSocket && this.awsRealTimeSocket.readyState === WebSocket.OPEN && this.socketStatus === _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].READY) {
8295
8332
  // Preparing unsubscribe message to stop receiving messages for that subscription
8296
8333
  var unsubscribeMessage = {
8297
8334
  id: subscriptionId,
8298
- type: MESSAGE_TYPES.GQL_STOP
8335
+ type: _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_STOP
8299
8336
  };
8300
8337
  var stringToAWSRealTime = JSON.stringify(unsubscribeMessage);
8301
8338
  this.awsRealTimeSocket.send(stringToAWSRealTime);
@@ -8321,7 +8358,7 @@ function (_super) {
8321
8358
  }
8322
8359
 
8323
8360
  if (!this.awsRealTimeSocket) {
8324
- this.socketStatus = SOCKET_STATUS.CLOSED;
8361
+ this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
8325
8362
  return;
8326
8363
  }
8327
8364
 
@@ -8330,14 +8367,14 @@ function (_super) {
8330
8367
  setTimeout(this._closeSocketIfRequired.bind(this), 1000);
8331
8368
  } else {
8332
8369
  logger.debug('closing WebSocket...');
8333
- clearTimeout(this.keepAliveTimeoutId);
8370
+ if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
8334
8371
  var tempSocket = this.awsRealTimeSocket; // Cleaning callbacks to avoid race condition, socket still exists
8335
8372
 
8336
- tempSocket.onclose = undefined;
8337
- tempSocket.onerror = undefined;
8373
+ tempSocket.onclose = null;
8374
+ tempSocket.onerror = null;
8338
8375
  tempSocket.close(1000);
8339
- this.awsRealTimeSocket = null;
8340
- this.socketStatus = SOCKET_STATUS.CLOSED;
8376
+ this.awsRealTimeSocket = undefined;
8377
+ this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
8341
8378
  }
8342
8379
  };
8343
8380
 
@@ -8368,7 +8405,7 @@ function (_super) {
8368
8405
  variables: variables
8369
8406
  });
8370
8407
 
8371
- if (type === MESSAGE_TYPES.GQL_DATA && payload && payload.data) {
8408
+ if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_DATA && payload && payload.data) {
8372
8409
  if (observer) {
8373
8410
  observer.next(payload);
8374
8411
  } else {
@@ -8378,7 +8415,7 @@ function (_super) {
8378
8415
  return;
8379
8416
  }
8380
8417
 
8381
- if (type === MESSAGE_TYPES.GQL_START_ACK) {
8418
+ if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_START_ACK) {
8382
8419
  logger.debug("subscription ready for " + JSON.stringify({
8383
8420
  query: query,
8384
8421
  variables: variables
@@ -8388,50 +8425,57 @@ function (_super) {
8388
8425
  subscriptionReadyCallback();
8389
8426
  }
8390
8427
 
8391
- clearTimeout(startAckTimeoutId);
8428
+ if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
8392
8429
  dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].SUBSCRIPTION_ACK, {
8393
8430
  query: query,
8394
8431
  variables: variables
8395
8432
  }, 'Connection established for subscription');
8396
- var subscriptionState = SUBSCRIPTION_STATUS.CONNECTED;
8397
- this.subscriptionObserverMap.set(id, {
8398
- observer: observer,
8399
- query: query,
8400
- variables: variables,
8401
- startAckTimeoutId: null,
8402
- subscriptionState: subscriptionState,
8403
- subscriptionReadyCallback: subscriptionReadyCallback,
8404
- subscriptionFailedCallback: subscriptionFailedCallback
8405
- }); // TODO: emit event on hub but it requires to store the id first
8433
+ var subscriptionState = _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].CONNECTED;
8434
+
8435
+ if (observer) {
8436
+ this.subscriptionObserverMap.set(id, {
8437
+ observer: observer,
8438
+ query: query,
8439
+ variables: variables,
8440
+ startAckTimeoutId: undefined,
8441
+ subscriptionState: subscriptionState,
8442
+ subscriptionReadyCallback: subscriptionReadyCallback,
8443
+ subscriptionFailedCallback: subscriptionFailedCallback
8444
+ });
8445
+ } // TODO: emit event on hub but it requires to store the id first
8446
+
8406
8447
 
8407
8448
  return;
8408
8449
  }
8409
8450
 
8410
- if (type === MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) {
8411
- clearTimeout(this.keepAliveTimeoutId);
8451
+ if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_CONNECTION_KEEP_ALIVE) {
8452
+ if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
8412
8453
  this.keepAliveTimeoutId = setTimeout(this._errorDisconnect.bind(this, _index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT), this.keepAliveTimeout);
8413
8454
  return;
8414
8455
  }
8415
8456
 
8416
- if (type === MESSAGE_TYPES.GQL_ERROR) {
8417
- var subscriptionState = SUBSCRIPTION_STATUS.FAILED;
8418
- this.subscriptionObserverMap.set(id, {
8419
- observer: observer,
8420
- query: query,
8421
- variables: variables,
8422
- startAckTimeoutId: startAckTimeoutId,
8423
- subscriptionReadyCallback: subscriptionReadyCallback,
8424
- subscriptionFailedCallback: subscriptionFailedCallback,
8425
- subscriptionState: subscriptionState
8426
- });
8427
- observer.error({
8428
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
8429
- });
8430
- clearTimeout(startAckTimeoutId);
8431
- observer.complete();
8457
+ if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_ERROR) {
8458
+ var subscriptionState = _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].FAILED;
8432
8459
 
8433
- if (typeof subscriptionFailedCallback === 'function') {
8434
- subscriptionFailedCallback();
8460
+ if (observer) {
8461
+ this.subscriptionObserverMap.set(id, {
8462
+ observer: observer,
8463
+ query: query,
8464
+ variables: variables,
8465
+ startAckTimeoutId: startAckTimeoutId,
8466
+ subscriptionReadyCallback: subscriptionReadyCallback,
8467
+ subscriptionFailedCallback: subscriptionFailedCallback,
8468
+ subscriptionState: subscriptionState
8469
+ });
8470
+ observer.error({
8471
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
8472
+ });
8473
+ if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
8474
+ observer.complete();
8475
+
8476
+ if (typeof subscriptionFailedCallback === 'function') {
8477
+ subscriptionFailedCallback();
8478
+ }
8435
8479
  }
8436
8480
  }
8437
8481
  };
@@ -8453,41 +8497,44 @@ function (_super) {
8453
8497
  this.awsRealTimeSocket.close();
8454
8498
  }
8455
8499
 
8456
- this.socketStatus = SOCKET_STATUS.CLOSED;
8500
+ this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
8457
8501
  };
8458
8502
 
8459
8503
  AWSAppSyncRealTimeProvider.prototype._timeoutStartSubscriptionAck = function (subscriptionId) {
8460
- var _a = this.subscriptionObserverMap.get(subscriptionId) || {},
8461
- observer = _a.observer,
8462
- query = _a.query,
8463
- variables = _a.variables;
8504
+ var subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
8464
8505
 
8465
- if (!observer) {
8466
- return;
8467
- }
8506
+ if (subscriptionObserver) {
8507
+ var observer = subscriptionObserver.observer,
8508
+ query = subscriptionObserver.query,
8509
+ variables = subscriptionObserver.variables;
8468
8510
 
8469
- this.subscriptionObserverMap.set(subscriptionId, {
8470
- observer: observer,
8471
- query: query,
8472
- variables: variables,
8473
- subscriptionState: SUBSCRIPTION_STATUS.FAILED
8474
- });
8511
+ if (!observer) {
8512
+ return;
8513
+ }
8475
8514
 
8476
- if (observer && !observer.closed) {
8477
- observer.error({
8478
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscription timeout " + JSON.stringify({
8479
- query: query,
8480
- variables: variables
8481
- })))]
8482
- }); // Cleanup will be automatically executed
8515
+ this.subscriptionObserverMap.set(subscriptionId, {
8516
+ observer: observer,
8517
+ query: query,
8518
+ variables: variables,
8519
+ subscriptionState: _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].FAILED
8520
+ });
8483
8521
 
8484
- observer.complete();
8485
- }
8522
+ if (observer && !observer.closed) {
8523
+ observer.error({
8524
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscription timeout " + JSON.stringify({
8525
+ query: query,
8526
+ variables: variables
8527
+ })))]
8528
+ }); // Cleanup will be automatically executed
8486
8529
 
8487
- logger.debug('timeoutStartSubscription', JSON.stringify({
8488
- query: query,
8489
- variables: variables
8490
- }));
8530
+ observer.complete();
8531
+ }
8532
+
8533
+ logger.debug('timeoutStartSubscription', JSON.stringify({
8534
+ query: query,
8535
+ variables: variables
8536
+ }));
8537
+ }
8491
8538
  };
8492
8539
 
8493
8540
  AWSAppSyncRealTimeProvider.prototype._initializeWebSocketConnection = function (_a) {
@@ -8499,7 +8546,7 @@ function (_super) {
8499
8546
  region = _a.region,
8500
8547
  additionalHeaders = _a.additionalHeaders;
8501
8548
 
8502
- if (this.socketStatus === SOCKET_STATUS.READY) {
8549
+ if (this.socketStatus === _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].READY) {
8503
8550
  return;
8504
8551
  }
8505
8552
 
@@ -8514,7 +8561,7 @@ function (_super) {
8514
8561
  res: res,
8515
8562
  rej: rej
8516
8563
  });
8517
- if (!(this.socketStatus === SOCKET_STATUS.CLOSED)) return [3
8564
+ if (!(this.socketStatus === _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED)) return [3
8518
8565
  /*break*/
8519
8566
  , 5];
8520
8567
  _c.label = 1;
@@ -8522,7 +8569,7 @@ function (_super) {
8522
8569
  case 1:
8523
8570
  _c.trys.push([1, 4,, 5]);
8524
8571
 
8525
- this.socketStatus = SOCKET_STATUS.CONNECTING;
8572
+ this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CONNECTING;
8526
8573
  payloadString = '{}';
8527
8574
  _b = (_a = JSON).stringify;
8528
8575
  return [4
@@ -8541,7 +8588,7 @@ function (_super) {
8541
8588
  headerString = _b.apply(_a, [_c.sent()]);
8542
8589
  headerQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(headerString).toString('base64');
8543
8590
  payloadQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(payloadString).toString('base64');
8544
- discoverableEndpoint = appSyncGraphqlEndpoint;
8591
+ discoverableEndpoint = appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '';
8545
8592
 
8546
8593
  if (this.isCustomDomain(discoverableEndpoint)) {
8547
8594
  discoverableEndpoint = discoverableEndpoint.concat(customDomainPath);
@@ -8554,9 +8601,7 @@ function (_super) {
8554
8601
  awsRealTimeUrl = discoverableEndpoint + "?header=" + headerQs + "&payload=" + payloadQs;
8555
8602
  return [4
8556
8603
  /*yield*/
8557
- , this._initializeRetryableHandshake({
8558
- awsRealTimeUrl: awsRealTimeUrl
8559
- })];
8604
+ , this._initializeRetryableHandshake(awsRealTimeUrl)];
8560
8605
 
8561
8606
  case 3:
8562
8607
  _c.sent();
@@ -8566,7 +8611,7 @@ function (_super) {
8566
8611
  logger.debug('Notifying connection successful');
8567
8612
  res();
8568
8613
  });
8569
- this.socketStatus = SOCKET_STATUS.READY;
8614
+ this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].READY;
8570
8615
  this.promiseArray = [];
8571
8616
  return [3
8572
8617
  /*break*/
@@ -8584,8 +8629,8 @@ function (_super) {
8584
8629
  this.awsRealTimeSocket.close(3001);
8585
8630
  }
8586
8631
 
8587
- this.awsRealTimeSocket = null;
8588
- this.socketStatus = SOCKET_STATUS.CLOSED;
8632
+ this.awsRealTimeSocket = undefined;
8633
+ this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
8589
8634
  return [3
8590
8635
  /*break*/
8591
8636
  , 5];
@@ -8600,21 +8645,18 @@ function (_super) {
8600
8645
  });
8601
8646
  };
8602
8647
 
8603
- AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (_a) {
8604
- var awsRealTimeUrl = _a.awsRealTimeUrl;
8648
+ AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (awsRealTimeUrl) {
8605
8649
  return __awaiter(this, void 0, void 0, function () {
8606
- return __generator(this, function (_b) {
8607
- switch (_b.label) {
8650
+ return __generator(this, function (_a) {
8651
+ switch (_a.label) {
8608
8652
  case 0:
8609
8653
  logger.debug("Initializaling retryable Handshake");
8610
8654
  return [4
8611
8655
  /*yield*/
8612
- , Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [{
8613
- awsRealTimeUrl: awsRealTimeUrl
8614
- }], MAX_DELAY_MS)];
8656
+ , Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [awsRealTimeUrl], _constants__WEBPACK_IMPORTED_MODULE_10__["MAX_DELAY_MS"])];
8615
8657
 
8616
8658
  case 1:
8617
- _b.sent();
8659
+ _a.sent();
8618
8660
 
8619
8661
  return [2
8620
8662
  /*return*/
@@ -8624,10 +8666,9 @@ function (_super) {
8624
8666
  });
8625
8667
  };
8626
8668
 
8627
- AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (_a) {
8628
- var awsRealTimeUrl = _a.awsRealTimeUrl;
8669
+ AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (awsRealTimeUrl) {
8629
8670
  return __awaiter(this, void 0, void 0, function () {
8630
- var err_4, errorType, errorCode;
8671
+ var err_4, _a, errorType, errorCode;
8631
8672
 
8632
8673
  var _this = this;
8633
8674
 
@@ -8644,7 +8685,7 @@ function (_super) {
8644
8685
  /*yield*/
8645
8686
  , function () {
8646
8687
  return new Promise(function (res, rej) {
8647
- var newSocket = new WebSocket(awsRealTimeUrl, 'graphql-ws');
8688
+ var newSocket = _this.getNewWebSocket(awsRealTimeUrl, 'graphql-ws');
8648
8689
 
8649
8690
  newSocket.onerror = function () {
8650
8691
  logger.debug("WebSocket connection error");
@@ -8669,77 +8710,82 @@ function (_super) {
8669
8710
  /*yield*/
8670
8711
  , function () {
8671
8712
  return new Promise(function (res, rej) {
8672
- var ackOk = false;
8713
+ if (_this.awsRealTimeSocket) {
8714
+ var ackOk_1 = false;
8673
8715
 
8674
- _this.awsRealTimeSocket.onerror = function (error) {
8675
- logger.debug("WebSocket error " + JSON.stringify(error));
8676
- };
8716
+ _this.awsRealTimeSocket.onerror = function (error) {
8717
+ logger.debug("WebSocket error " + JSON.stringify(error));
8718
+ };
8677
8719
 
8678
- _this.awsRealTimeSocket.onclose = function (event) {
8679
- logger.debug("WebSocket closed " + event.reason);
8680
- rej(new Error(JSON.stringify(event)));
8681
- };
8720
+ _this.awsRealTimeSocket.onclose = function (event) {
8721
+ logger.debug("WebSocket closed " + event.reason);
8722
+ rej(new Error(JSON.stringify(event)));
8723
+ };
8682
8724
 
8683
- _this.awsRealTimeSocket.onmessage = function (message) {
8684
- logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
8685
- var data = JSON.parse(message.data);
8686
- var type = data.type,
8687
- _a = data.payload,
8688
- _b = (_a === void 0 ? {} : _a).connectionTimeoutMs,
8689
- connectionTimeoutMs = _b === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _b;
8725
+ _this.awsRealTimeSocket.onmessage = function (message) {
8726
+ logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
8727
+ var data = JSON.parse(message.data);
8728
+ var type = data.type,
8729
+ _a = data.payload,
8730
+ _b = (_a === void 0 ? {} : _a).connectionTimeoutMs,
8731
+ connectionTimeoutMs = _b === void 0 ? _constants__WEBPACK_IMPORTED_MODULE_10__["DEFAULT_KEEP_ALIVE_TIMEOUT"] : _b;
8690
8732
 
8691
- if (type === MESSAGE_TYPES.GQL_CONNECTION_ACK) {
8692
- ackOk = true;
8693
- _this.keepAliveTimeout = connectionTimeoutMs;
8694
- _this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
8733
+ if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_CONNECTION_ACK) {
8734
+ ackOk_1 = true;
8695
8735
 
8696
- _this.awsRealTimeSocket.onerror = function (err) {
8697
- logger.debug(err);
8736
+ if (_this.awsRealTimeSocket) {
8737
+ _this.keepAliveTimeout = connectionTimeoutMs;
8738
+ _this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
8698
8739
 
8699
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
8700
- };
8740
+ _this.awsRealTimeSocket.onerror = function (err) {
8741
+ logger.debug(err);
8701
8742
 
8702
- _this.awsRealTimeSocket.onclose = function (event) {
8703
- logger.debug("WebSocket closed " + event.reason);
8743
+ _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
8744
+ };
8704
8745
 
8705
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
8706
- };
8746
+ _this.awsRealTimeSocket.onclose = function (event) {
8747
+ logger.debug("WebSocket closed " + event.reason);
8707
8748
 
8708
- res('Cool, connected to AWS AppSyncRealTime');
8709
- return;
8710
- }
8749
+ _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
8750
+ };
8751
+ }
8711
8752
 
8712
- if (type === MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
8713
- var _c = data.payload,
8714
- _d = (_c === void 0 ? {} : _c).errors,
8715
- _e = __read(_d === void 0 ? [] : _d, 1),
8716
- _f = _e[0],
8717
- _g = _f === void 0 ? {} : _f,
8718
- _h = _g.errorType,
8719
- errorType = _h === void 0 ? '' : _h,
8720
- _j = _g.errorCode,
8721
- errorCode = _j === void 0 ? 0 : _j;
8722
-
8723
- rej({
8724
- errorType: errorType,
8725
- errorCode: errorCode
8726
- });
8727
- }
8728
- };
8753
+ res('Cool, connected to AWS AppSyncRealTime');
8754
+ return;
8755
+ }
8729
8756
 
8730
- var gqlInit = {
8731
- type: MESSAGE_TYPES.GQL_CONNECTION_INIT
8732
- };
8757
+ if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_CONNECTION_ERROR) {
8758
+ var _c = data.payload,
8759
+ _d = (_c === void 0 ? {} : _c).errors,
8760
+ _e = __read(_d === void 0 ? [] : _d, 1),
8761
+ _f = _e[0],
8762
+ _g = _f === void 0 ? {} : _f,
8763
+ _h = _g.errorType,
8764
+ errorType = _h === void 0 ? '' : _h,
8765
+ _j = _g.errorCode,
8766
+ errorCode = _j === void 0 ? 0 : _j;
8767
+
8768
+ rej({
8769
+ errorType: errorType,
8770
+ errorCode: errorCode
8771
+ });
8772
+ }
8773
+ };
8733
8774
 
8734
- _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
8775
+ var gqlInit = {
8776
+ type: _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_CONNECTION_INIT
8777
+ };
8735
8778
 
8736
- function checkAckOk() {
8779
+ _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
8780
+
8781
+ setTimeout(checkAckOk.bind(_this, ackOk_1), _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"]);
8782
+ }
8783
+
8784
+ function checkAckOk(ackOk) {
8737
8785
  if (!ackOk) {
8738
- rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + CONNECTION_INIT_TIMEOUT + " ms"));
8786
+ rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"] + " ms"));
8739
8787
  }
8740
8788
  }
8741
-
8742
- setTimeout(checkAckOk.bind(_this), CONNECTION_INIT_TIMEOUT);
8743
8789
  });
8744
8790
  }()];
8745
8791
 
@@ -8753,9 +8799,9 @@ function (_super) {
8753
8799
 
8754
8800
  case 4:
8755
8801
  err_4 = _b.sent();
8756
- errorType = err_4.errorType, errorCode = err_4.errorCode;
8802
+ _a = err_4, errorType = _a.errorType, errorCode = _a.errorCode;
8757
8803
 
8758
- if (NON_RETRYABLE_CODES.includes(errorCode)) {
8804
+ if (_constants__WEBPACK_IMPORTED_MODULE_10__["NON_RETRYABLE_CODES"].includes(errorCode)) {
8759
8805
  throw new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["NonRetryableError"](errorType);
8760
8806
  } else if (errorType) {
8761
8807
  throw new Error(errorType);
@@ -8796,16 +8842,18 @@ function (_super) {
8796
8842
  AMAZON_COGNITO_USER_POOLS: this._awsRealTimeCUPHeader.bind(this),
8797
8843
  AWS_LAMBDA: this._customAuthHeader
8798
8844
  };
8799
- handler = headerHandler[authenticationType];
8800
-
8801
- if (typeof handler !== 'function') {
8802
- logger.debug("Authentication type " + authenticationType + " not supported");
8803
- return [2
8804
- /*return*/
8805
- , ''];
8806
- }
8845
+ if (!(!authenticationType || !headerHandler[authenticationType])) return [3
8846
+ /*break*/
8847
+ , 1];
8848
+ logger.debug("Authentication type " + authenticationType + " not supported");
8849
+ return [2
8850
+ /*return*/
8851
+ , ''];
8807
8852
 
8808
- host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint).host;
8853
+ case 1:
8854
+ handler = headerHandler[authenticationType];
8855
+ host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
8856
+ logger.debug("Authenticating with " + authenticationType);
8809
8857
  return [4
8810
8858
  /*yield*/
8811
8859
  , handler({
@@ -8818,7 +8866,7 @@ function (_super) {
8818
8866
  additionalHeaders: additionalHeaders
8819
8867
  })];
8820
8868
 
8821
- case 1:
8869
+ case 2:
8822
8870
  result = _b.sent();
8823
8871
  return [2
8824
8872
  /*return*/
@@ -8950,10 +8998,14 @@ function (_super) {
8950
8998
  return [4
8951
8999
  /*yield*/
8952
9000
  , _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Credentials"].get().then(function (credentials) {
9001
+ var _a = credentials,
9002
+ secretAccessKey = _a.secretAccessKey,
9003
+ accessKeyId = _a.accessKeyId,
9004
+ sessionToken = _a.sessionToken;
8953
9005
  return {
8954
- secret_key: credentials.secretAccessKey,
8955
- access_key: credentials.accessKeyId,
8956
- session_token: credentials.sessionToken
9006
+ secret_key: secretAccessKey,
9007
+ access_key: accessKeyId,
9008
+ session_token: sessionToken
8957
9009
  };
8958
9010
  })];
8959
9011
 
@@ -8963,7 +9015,7 @@ function (_super) {
8963
9015
  url: "" + appSyncGraphqlEndpoint + canonicalUri,
8964
9016
  data: payload,
8965
9017
  method: 'POST',
8966
- headers: __assign({}, AWS_APPSYNC_REALTIME_HEADERS)
9018
+ headers: __assign({}, _constants__WEBPACK_IMPORTED_MODULE_10__["AWS_APPSYNC_REALTIME_HEADERS"])
8967
9019
  };
8968
9020
  signed_params = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Signer"].sign(request, creds, endpointInfo);
8969
9021
  return [2
@@ -8978,7 +9030,7 @@ function (_super) {
8978
9030
  var host = _a.host,
8979
9031
  additionalHeaders = _a.additionalHeaders;
8980
9032
 
8981
- if (!additionalHeaders.Authorization) {
9033
+ if (!additionalHeaders || !additionalHeaders['Authorization']) {
8982
9034
  throw new Error('No auth token specified');
8983
9035
  }
8984
9036
 
@@ -9215,8 +9267,12 @@ var AWSIoTProvider =
9215
9267
  function (_super) {
9216
9268
  __extends(AWSIoTProvider, _super);
9217
9269
 
9218
- function AWSIoTProvider() {
9219
- return _super !== null && _super.apply(this, arguments) || this;
9270
+ function AWSIoTProvider(options) {
9271
+ if (options === void 0) {
9272
+ options = {};
9273
+ }
9274
+
9275
+ return _super.call(this, options) || this;
9220
9276
  }
9221
9277
 
9222
9278
  Object.defineProperty(AWSIoTProvider.prototype, "region", {
@@ -9546,21 +9602,27 @@ function () {
9546
9602
 
9547
9603
  ClientsQueue.prototype.get = function (clientId, clientFactory) {
9548
9604
  return __awaiter(this, void 0, void 0, function () {
9549
- var promise;
9605
+ var cachedPromise, newPromise;
9550
9606
  return __generator(this, function (_a) {
9551
- promise = this.promises.get(clientId);
9607
+ cachedPromise = this.promises.get(clientId);
9608
+
9609
+ if (cachedPromise) {
9610
+ return [2
9611
+ /*return*/
9612
+ , cachedPromise];
9613
+ }
9552
9614
 
9553
- if (promise) {
9615
+ if (clientFactory) {
9616
+ newPromise = clientFactory(clientId);
9617
+ this.promises.set(clientId, newPromise);
9554
9618
  return [2
9555
9619
  /*return*/
9556
- , promise];
9620
+ , newPromise];
9557
9621
  }
9558
9622
 
9559
- promise = clientFactory(clientId);
9560
- this.promises.set(clientId, promise);
9561
9623
  return [2
9562
9624
  /*return*/
9563
- , promise];
9625
+ , undefined];
9564
9626
  });
9565
9627
  });
9566
9628
  };
@@ -9652,6 +9714,10 @@ function (_super) {
9652
9714
  }, args), null, 2));
9653
9715
  var topicsToDelete_1 = [];
9654
9716
 
9717
+ if (!clientId) {
9718
+ return;
9719
+ }
9720
+
9655
9721
  var clientIdObservers = this._clientIdObservers.get(clientId);
9656
9722
 
9657
9723
  if (!clientIdObservers) {
@@ -9770,9 +9836,7 @@ function (_super) {
9770
9836
  case 0:
9771
9837
  return [4
9772
9838
  /*yield*/
9773
- , this.clientsQueue.get(clientId, function () {
9774
- return null;
9775
- })];
9839
+ , this.clientsQueue.get(clientId)];
9776
9840
 
9777
9841
  case 1:
9778
9842
  client = _a.sent();
@@ -9951,13 +10015,14 @@ function (_super) {
9951
10015
  })();
9952
10016
 
9953
10017
  return function () {
10018
+ var _a, _b;
10019
+
9954
10020
  logger.debug('Unsubscribing from topic(s)', targetTopics.join(','));
9955
10021
 
9956
10022
  if (client) {
9957
- _this._clientIdObservers.get(clientId)["delete"](observer); // No more observers per client => client not needed anymore
9958
-
10023
+ (_a = _this._clientIdObservers.get(clientId)) === null || _a === void 0 ? void 0 : _a["delete"](observer); // No more observers per client => client not needed anymore
9959
10024
 
9960
- if (_this._clientIdObservers.get(clientId).size === 0) {
10025
+ if (((_b = _this._clientIdObservers.get(clientId)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
9961
10026
  _this.disconnect(clientId);
9962
10027
 
9963
10028
  _this._clientIdObservers["delete"](clientId);
@@ -10074,7 +10139,7 @@ __webpack_require__.r(__webpack_exports__);
10074
10139
  /* harmony import */ var _AWSAppSyncProvider__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./AWSAppSyncProvider */ "./lib-esm/Providers/AWSAppSyncProvider.js");
10075
10140
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AWSAppSyncProvider", function() { return _AWSAppSyncProvider__WEBPACK_IMPORTED_MODULE_1__["AWSAppSyncProvider"]; });
10076
10141
 
10077
- /* harmony import */ var _AWSAppSyncRealTimeProvider__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./AWSAppSyncRealTimeProvider */ "./lib-esm/Providers/AWSAppSyncRealTimeProvider.js");
10142
+ /* harmony import */ var _AWSAppSyncRealTimeProvider__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./AWSAppSyncRealTimeProvider */ "./lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js");
10078
10143
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AWSAppSyncRealTimeProvider", function() { return _AWSAppSyncRealTimeProvider__WEBPACK_IMPORTED_MODULE_2__["AWSAppSyncRealTimeProvider"]; });
10079
10144
 
10080
10145
  /* harmony import */ var _AWSIotProvider__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./AWSIotProvider */ "./lib-esm/Providers/AWSIotProvider.js");
@@ -10292,7 +10357,7 @@ function () {
10292
10357
  * @param {PubSubOptions} options - Configuration object for PubSub
10293
10358
  */
10294
10359
  function PubSubClass(options) {
10295
- this._options = options;
10360
+ this._options = options !== null && options !== void 0 ? options : {};
10296
10361
  logger.debug('PubSub Options', this._options);
10297
10362
  this._pluggables = [];
10298
10363
  this.subscribe = this.subscribe.bind(this);
@@ -10481,7 +10546,7 @@ function () {
10481
10546
  }();
10482
10547
 
10483
10548
 
10484
- var PubSub = new PubSubClass(null);
10549
+ var PubSub = new PubSubClass();
10485
10550
  _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Amplify"].register(PubSub);
10486
10551
 
10487
10552
  /***/ }),