@aws-amplify/api-graphql 2.2.10-in-app-messaging.60 → 2.2.10-in-app-messaging.66

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.
@@ -9824,6 +9824,16 @@ function () {
9824
9824
  RestAPIClass.prototype.cancel = function (request, message) {
9825
9825
  return this._api.cancel(request, message);
9826
9826
  };
9827
+ /**
9828
+ * Check if the request has a corresponding cancel token in the WeakMap.
9829
+ * @params request - The request promise
9830
+ * @return if the request has a corresponding cancel token.
9831
+ */
9832
+
9833
+
9834
+ RestAPIClass.prototype.hasCancelToken = function (request) {
9835
+ return this._api.hasCancelToken(request);
9836
+ };
9827
9837
  /**
9828
9838
  * Getting endpoint for API
9829
9839
  * @param {string} apiName - The name of the api
@@ -10389,9 +10399,20 @@ function () {
10389
10399
 
10390
10400
  if (source) {
10391
10401
  source.cancel(message);
10402
+ return true;
10392
10403
  }
10393
10404
 
10394
- return true;
10405
+ return false;
10406
+ };
10407
+ /**
10408
+ * Check if the request has a corresponding cancel token in the WeakMap.
10409
+ * @params request - The request promise
10410
+ * @return if the request has a corresponding cancel token.
10411
+ */
10412
+
10413
+
10414
+ RestClient.prototype.hasCancelToken = function (request) {
10415
+ return this._cancelTokenMap.has(request);
10395
10416
  };
10396
10417
  /**
10397
10418
  * Checks to see if an error thrown is from an api request cancellation
@@ -10801,6 +10822,9 @@ var __spread = undefined && undefined.__spread || function () {
10801
10822
 
10802
10823
 
10803
10824
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["ConsoleLogger"]('AWSAppSyncProvider');
10825
+ /**
10826
+ * @deprecated Unused, all usecases have migrated to AWSAppSyncRealtimeProvider
10827
+ */
10804
10828
 
10805
10829
  var AWSAppSyncProvider =
10806
10830
  /** @class */
@@ -11107,10 +11131,135 @@ function (_super) {
11107
11131
 
11108
11132
  /***/ }),
11109
11133
 
11110
- /***/ "../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider.js":
11111
- /*!*****************************************************************!*\
11112
- !*** ../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider.js ***!
11113
- \*****************************************************************/
11134
+ /***/ "../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js":
11135
+ /*!***************************************************************************!*\
11136
+ !*** ../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js ***!
11137
+ \***************************************************************************/
11138
+ /*! 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 */
11139
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
11140
+
11141
+ "use strict";
11142
+ __webpack_require__.r(__webpack_exports__);
11143
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MAX_DELAY_MS", function() { return MAX_DELAY_MS; });
11144
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "NON_RETRYABLE_CODES", function() { return NON_RETRYABLE_CODES; });
11145
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "MESSAGE_TYPES", function() { return MESSAGE_TYPES; });
11146
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SUBSCRIPTION_STATUS", function() { return SUBSCRIPTION_STATUS; });
11147
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SOCKET_STATUS", function() { return SOCKET_STATUS; });
11148
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AMPLIFY_SYMBOL", function() { return AMPLIFY_SYMBOL; });
11149
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AWS_APPSYNC_REALTIME_HEADERS", function() { return AWS_APPSYNC_REALTIME_HEADERS; });
11150
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "CONNECTION_INIT_TIMEOUT", function() { return CONNECTION_INIT_TIMEOUT; });
11151
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "START_ACK_TIMEOUT", function() { return START_ACK_TIMEOUT; });
11152
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DEFAULT_KEEP_ALIVE_TIMEOUT", function() { return DEFAULT_KEEP_ALIVE_TIMEOUT; });
11153
+ var MAX_DELAY_MS = 5000;
11154
+ var NON_RETRYABLE_CODES = [400, 401, 403];
11155
+ var MESSAGE_TYPES;
11156
+
11157
+ (function (MESSAGE_TYPES) {
11158
+ /**
11159
+ * Client -> Server message.
11160
+ * This message type is the first message after handshake and this will initialize AWS AppSync RealTime communication
11161
+ */
11162
+ MESSAGE_TYPES["GQL_CONNECTION_INIT"] = "connection_init";
11163
+ /**
11164
+ * Server -> Client message
11165
+ * This message type is in case there is an issue with AWS AppSync RealTime when establishing connection
11166
+ */
11167
+
11168
+ MESSAGE_TYPES["GQL_CONNECTION_ERROR"] = "connection_error";
11169
+ /**
11170
+ * Server -> Client message.
11171
+ * This message type is for the ack response from AWS AppSync RealTime for GQL_CONNECTION_INIT message
11172
+ */
11173
+
11174
+ MESSAGE_TYPES["GQL_CONNECTION_ACK"] = "connection_ack";
11175
+ /**
11176
+ * Client -> Server message.
11177
+ * This message type is for register subscriptions with AWS AppSync RealTime
11178
+ */
11179
+
11180
+ MESSAGE_TYPES["GQL_START"] = "start";
11181
+ /**
11182
+ * Server -> Client message.
11183
+ * This message type is for the ack response from AWS AppSync RealTime for GQL_START message
11184
+ */
11185
+
11186
+ MESSAGE_TYPES["GQL_START_ACK"] = "start_ack";
11187
+ /**
11188
+ * Server -> Client message.
11189
+ * This message type is for subscription message from AWS AppSync RealTime
11190
+ */
11191
+
11192
+ MESSAGE_TYPES["GQL_DATA"] = "data";
11193
+ /**
11194
+ * Server -> Client message.
11195
+ * This message type helps the client to know is still receiving messages from AWS AppSync RealTime
11196
+ */
11197
+
11198
+ MESSAGE_TYPES["GQL_CONNECTION_KEEP_ALIVE"] = "ka";
11199
+ /**
11200
+ * Client -> Server message.
11201
+ * This message type is for unregister subscriptions with AWS AppSync RealTime
11202
+ */
11203
+
11204
+ MESSAGE_TYPES["GQL_STOP"] = "stop";
11205
+ /**
11206
+ * Server -> Client message.
11207
+ * This message type is for the ack response from AWS AppSync RealTime for GQL_STOP message
11208
+ */
11209
+
11210
+ MESSAGE_TYPES["GQL_COMPLETE"] = "complete";
11211
+ /**
11212
+ * Server -> Client message.
11213
+ * This message type is for sending error messages from AWS AppSync RealTime to the client
11214
+ */
11215
+
11216
+ MESSAGE_TYPES["GQL_ERROR"] = "error";
11217
+ })(MESSAGE_TYPES || (MESSAGE_TYPES = {}));
11218
+
11219
+ var SUBSCRIPTION_STATUS;
11220
+
11221
+ (function (SUBSCRIPTION_STATUS) {
11222
+ SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["PENDING"] = 0] = "PENDING";
11223
+ SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["CONNECTED"] = 1] = "CONNECTED";
11224
+ SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["FAILED"] = 2] = "FAILED";
11225
+ })(SUBSCRIPTION_STATUS || (SUBSCRIPTION_STATUS = {}));
11226
+
11227
+ var SOCKET_STATUS;
11228
+
11229
+ (function (SOCKET_STATUS) {
11230
+ SOCKET_STATUS[SOCKET_STATUS["CLOSED"] = 0] = "CLOSED";
11231
+ SOCKET_STATUS[SOCKET_STATUS["READY"] = 1] = "READY";
11232
+ SOCKET_STATUS[SOCKET_STATUS["CONNECTING"] = 2] = "CONNECTING";
11233
+ })(SOCKET_STATUS || (SOCKET_STATUS = {}));
11234
+
11235
+ var AMPLIFY_SYMBOL = typeof Symbol !== 'undefined' && typeof Symbol["for"] === 'function' ? Symbol["for"]('amplify_default') : '@@amplify_default';
11236
+ var AWS_APPSYNC_REALTIME_HEADERS = {
11237
+ accept: 'application/json, text/javascript',
11238
+ 'content-encoding': 'amz-1.0',
11239
+ 'content-type': 'application/json; charset=UTF-8'
11240
+ };
11241
+ /**
11242
+ * Time in milleseconds to wait for GQL_CONNECTION_INIT message
11243
+ */
11244
+
11245
+ var CONNECTION_INIT_TIMEOUT = 15000;
11246
+ /**
11247
+ * Time in milleseconds to wait for GQL_START_ACK message
11248
+ */
11249
+
11250
+ var START_ACK_TIMEOUT = 15000;
11251
+ /**
11252
+ * Default Time in milleseconds to wait for GQL_CONNECTION_KEEP_ALIVE message
11253
+ */
11254
+
11255
+ var DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000;
11256
+
11257
+ /***/ }),
11258
+
11259
+ /***/ "../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js":
11260
+ /*!***********************************************************************!*\
11261
+ !*** ../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js ***!
11262
+ \***********************************************************************/
11114
11263
  /*! exports provided: AWSAppSyncRealTimeProvider */
11115
11264
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
11116
11265
 
@@ -11132,8 +11281,9 @@ __webpack_require__.r(__webpack_exports__);
11132
11281
  /* harmony import */ var _aws_amplify_cache__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_cache__WEBPACK_IMPORTED_MODULE_6__);
11133
11282
  /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! @aws-amplify/auth */ "@aws-amplify/auth");
11134
11283
  /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_7__);
11135
- /* harmony import */ var _PubSubProvider__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./PubSubProvider */ "../pubsub/lib-esm/Providers/PubSubProvider.js");
11136
- /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../index */ "../pubsub/lib-esm/index.js");
11284
+ /* harmony import */ var _PubSubProvider__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../PubSubProvider */ "../pubsub/lib-esm/Providers/PubSubProvider.js");
11285
+ /* harmony import */ var _index__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ../../index */ "../pubsub/lib-esm/index.js");
11286
+ /* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./constants */ "../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js");
11137
11287
  var __extends = undefined && undefined.__extends || function () {
11138
11288
  var _extendStatics = function extendStatics(d, b) {
11139
11289
  _extendStatics = Object.setPrototypeOf || {
@@ -11369,119 +11519,17 @@ var __read = undefined && undefined.__read || function (o, n) {
11369
11519
 
11370
11520
 
11371
11521
 
11522
+
11372
11523
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Logger"]('AWSAppSyncRealTimeProvider');
11373
- var AMPLIFY_SYMBOL = typeof Symbol !== 'undefined' && typeof Symbol["for"] === 'function' ? Symbol["for"]('amplify_default') : '@@amplify_default';
11374
11524
 
11375
11525
  var dispatchApiEvent = function dispatchApiEvent(event, data, message) {
11376
11526
  _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Hub"].dispatch('api', {
11377
11527
  event: event,
11378
11528
  data: data,
11379
11529
  message: message
11380
- }, 'PubSub', AMPLIFY_SYMBOL);
11530
+ }, 'PubSub', _constants__WEBPACK_IMPORTED_MODULE_10__["AMPLIFY_SYMBOL"]);
11381
11531
  };
11382
11532
 
11383
- var MAX_DELAY_MS = 5000;
11384
- var NON_RETRYABLE_CODES = [400, 401, 403];
11385
- var MESSAGE_TYPES;
11386
-
11387
- (function (MESSAGE_TYPES) {
11388
- /**
11389
- * Client -> Server message.
11390
- * This message type is the first message after handshake and this will initialize AWS AppSync RealTime communication
11391
- */
11392
- MESSAGE_TYPES["GQL_CONNECTION_INIT"] = "connection_init";
11393
- /**
11394
- * Server -> Client message
11395
- * This message type is in case there is an issue with AWS AppSync RealTime when establishing connection
11396
- */
11397
-
11398
- MESSAGE_TYPES["GQL_CONNECTION_ERROR"] = "connection_error";
11399
- /**
11400
- * Server -> Client message.
11401
- * This message type is for the ack response from AWS AppSync RealTime for GQL_CONNECTION_INIT message
11402
- */
11403
-
11404
- MESSAGE_TYPES["GQL_CONNECTION_ACK"] = "connection_ack";
11405
- /**
11406
- * Client -> Server message.
11407
- * This message type is for register subscriptions with AWS AppSync RealTime
11408
- */
11409
-
11410
- MESSAGE_TYPES["GQL_START"] = "start";
11411
- /**
11412
- * Server -> Client message.
11413
- * This message type is for the ack response from AWS AppSync RealTime for GQL_START message
11414
- */
11415
-
11416
- MESSAGE_TYPES["GQL_START_ACK"] = "start_ack";
11417
- /**
11418
- * Server -> Client message.
11419
- * This message type is for subscription message from AWS AppSync RealTime
11420
- */
11421
-
11422
- MESSAGE_TYPES["GQL_DATA"] = "data";
11423
- /**
11424
- * Server -> Client message.
11425
- * This message type helps the client to know is still receiving messages from AWS AppSync RealTime
11426
- */
11427
-
11428
- MESSAGE_TYPES["GQL_CONNECTION_KEEP_ALIVE"] = "ka";
11429
- /**
11430
- * Client -> Server message.
11431
- * This message type is for unregister subscriptions with AWS AppSync RealTime
11432
- */
11433
-
11434
- MESSAGE_TYPES["GQL_STOP"] = "stop";
11435
- /**
11436
- * Server -> Client message.
11437
- * This message type is for the ack response from AWS AppSync RealTime for GQL_STOP message
11438
- */
11439
-
11440
- MESSAGE_TYPES["GQL_COMPLETE"] = "complete";
11441
- /**
11442
- * Server -> Client message.
11443
- * This message type is for sending error messages from AWS AppSync RealTime to the client
11444
- */
11445
-
11446
- MESSAGE_TYPES["GQL_ERROR"] = "error";
11447
- })(MESSAGE_TYPES || (MESSAGE_TYPES = {}));
11448
-
11449
- var SUBSCRIPTION_STATUS;
11450
-
11451
- (function (SUBSCRIPTION_STATUS) {
11452
- SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["PENDING"] = 0] = "PENDING";
11453
- SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["CONNECTED"] = 1] = "CONNECTED";
11454
- SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["FAILED"] = 2] = "FAILED";
11455
- })(SUBSCRIPTION_STATUS || (SUBSCRIPTION_STATUS = {}));
11456
-
11457
- var SOCKET_STATUS;
11458
-
11459
- (function (SOCKET_STATUS) {
11460
- SOCKET_STATUS[SOCKET_STATUS["CLOSED"] = 0] = "CLOSED";
11461
- SOCKET_STATUS[SOCKET_STATUS["READY"] = 1] = "READY";
11462
- SOCKET_STATUS[SOCKET_STATUS["CONNECTING"] = 2] = "CONNECTING";
11463
- })(SOCKET_STATUS || (SOCKET_STATUS = {}));
11464
-
11465
- var AWS_APPSYNC_REALTIME_HEADERS = {
11466
- accept: 'application/json, text/javascript',
11467
- 'content-encoding': 'amz-1.0',
11468
- 'content-type': 'application/json; charset=UTF-8'
11469
- };
11470
- /**
11471
- * Time in milleseconds to wait for GQL_CONNECTION_INIT message
11472
- */
11473
-
11474
- var CONNECTION_INIT_TIMEOUT = 15000;
11475
- /**
11476
- * Time in milleseconds to wait for GQL_START_ACK message
11477
- */
11478
-
11479
- var START_ACK_TIMEOUT = 15000;
11480
- /**
11481
- * Default Time in milleseconds to wait for GQL_CONNECTION_KEEP_ALIVE message
11482
- */
11483
-
11484
- var DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000;
11485
11533
  var standardDomainPattern = /^https:\/\/\w{26}\.appsync\-api\.\w{2}(?:(?:\-\w{2,})+)\-\d\.amazonaws.com\/graphql$/i;
11486
11534
  var customDomainPath = '/realtime';
11487
11535
 
@@ -11493,13 +11541,17 @@ function (_super) {
11493
11541
  function AWSAppSyncRealTimeProvider() {
11494
11542
  var _this = _super !== null && _super.apply(this, arguments) || this;
11495
11543
 
11496
- _this.socketStatus = SOCKET_STATUS.CLOSED;
11497
- _this.keepAliveTimeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
11544
+ _this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
11545
+ _this.keepAliveTimeout = _constants__WEBPACK_IMPORTED_MODULE_10__["DEFAULT_KEEP_ALIVE_TIMEOUT"];
11498
11546
  _this.subscriptionObserverMap = new Map();
11499
11547
  _this.promiseArray = [];
11500
11548
  return _this;
11501
11549
  }
11502
11550
 
11551
+ AWSAppSyncRealTimeProvider.prototype.getNewWebSocket = function (url, protocol) {
11552
+ return new WebSocket(url, protocol);
11553
+ };
11554
+
11503
11555
  AWSAppSyncRealTimeProvider.prototype.getProviderName = function () {
11504
11556
  return 'AWSAppSyncRealTimeProvider';
11505
11557
  };
@@ -11524,9 +11576,9 @@ function (_super) {
11524
11576
  AWSAppSyncRealTimeProvider.prototype.subscribe = function (_topics, options) {
11525
11577
  var _this = this;
11526
11578
 
11527
- var appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint;
11579
+ var appSyncGraphqlEndpoint = options === null || options === void 0 ? void 0 : options.appSyncGraphqlEndpoint;
11528
11580
  return new zen_observable_ts__WEBPACK_IMPORTED_MODULE_0__["default"](function (observer) {
11529
- if (!appSyncGraphqlEndpoint) {
11581
+ if (!options || !appSyncGraphqlEndpoint) {
11530
11582
  observer.error({
11531
11583
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscribe only available for AWS AppSync endpoint"))]
11532
11584
  });
@@ -11571,7 +11623,7 @@ function (_super) {
11571
11623
  ];
11572
11624
  }
11573
11625
 
11574
- if (subscriptionState === SUBSCRIPTION_STATUS.CONNECTED) {
11626
+ if (subscriptionState === _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].CONNECTED) {
11575
11627
  this._sendUnsubscriptionMessage(subscriptionId_1);
11576
11628
  } else {
11577
11629
  throw new Error('Subscription never connected');
@@ -11619,20 +11671,23 @@ function (_super) {
11619
11671
  var options = _a.options,
11620
11672
  observer = _a.observer,
11621
11673
  subscriptionId = _a.subscriptionId;
11674
+
11675
+ var _b, _c;
11676
+
11622
11677
  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;
11678
+ 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
11679
 
11625
- var _h;
11680
+ var _j;
11626
11681
 
11627
11682
  var _this = this;
11628
11683
 
11629
- return __generator(this, function (_j) {
11630
- switch (_j.label) {
11684
+ return __generator(this, function (_k) {
11685
+ switch (_k.label) {
11631
11686
  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 () {
11687
+ 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
11688
  return {};
11634
- } : _b, _c = options.additionalHeaders, additionalHeaders = _c === void 0 ? {} : _c;
11635
- subscriptionState = SUBSCRIPTION_STATUS.PENDING;
11689
+ } : _d, _e = options.additionalHeaders, additionalHeaders = _e === void 0 ? {} : _e;
11690
+ subscriptionState = _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].PENDING;
11636
11691
  data = {
11637
11692
  query: query,
11638
11693
  variables: variables
@@ -11640,13 +11695,13 @@ function (_super) {
11640
11695
 
11641
11696
  this.subscriptionObserverMap.set(subscriptionId, {
11642
11697
  observer: observer,
11643
- query: query,
11644
- variables: variables,
11698
+ query: query !== null && query !== void 0 ? query : '',
11699
+ variables: variables !== null && variables !== void 0 ? variables : {},
11645
11700
  subscriptionState: subscriptionState,
11646
- startAckTimeoutId: null
11701
+ startAckTimeoutId: undefined
11647
11702
  });
11648
11703
  dataString = JSON.stringify(data);
11649
- _d = [{}];
11704
+ _f = [{}];
11650
11705
  return [4
11651
11706
  /*yield*/
11652
11707
  , this._awsRealTimeHeaderBasedAuth({
@@ -11660,13 +11715,13 @@ function (_super) {
11660
11715
  })];
11661
11716
 
11662
11717
  case 1:
11663
- _e = [__assign.apply(void 0, _d.concat([_j.sent()]))];
11718
+ _g = [__assign.apply(void 0, _f.concat([_k.sent()]))];
11664
11719
  return [4
11665
11720
  /*yield*/
11666
11721
  , graphql_headers()];
11667
11722
 
11668
11723
  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)]);
11724
+ 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
11725
  subscriptionMessage = {
11671
11726
  id: subscriptionId,
11672
11727
  payload: {
@@ -11675,13 +11730,13 @@ function (_super) {
11675
11730
  authorization: __assign({}, headerObj)
11676
11731
  }
11677
11732
  },
11678
- type: MESSAGE_TYPES.GQL_START
11733
+ type: _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_START
11679
11734
  };
11680
11735
  stringToAWSRealTime = JSON.stringify(subscriptionMessage);
11681
- _j.label = 3;
11736
+ _k.label = 3;
11682
11737
 
11683
11738
  case 3:
11684
- _j.trys.push([3, 5,, 6]);
11739
+ _k.trys.push([3, 5,, 6]);
11685
11740
 
11686
11741
  return [4
11687
11742
  /*yield*/
@@ -11694,18 +11749,18 @@ function (_super) {
11694
11749
  })];
11695
11750
 
11696
11751
  case 4:
11697
- _j.sent();
11752
+ _k.sent();
11698
11753
 
11699
11754
  return [3
11700
11755
  /*break*/
11701
11756
  , 6];
11702
11757
 
11703
11758
  case 5:
11704
- err_2 = _j.sent();
11759
+ err_2 = _k.sent();
11705
11760
  logger.debug({
11706
11761
  err: err_2
11707
11762
  });
11708
- _f = err_2.message, message = _f === void 0 ? '' : _f;
11763
+ message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
11709
11764
  observer.error({
11710
11765
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
11711
11766
  });
@@ -11721,18 +11776,18 @@ function (_super) {
11721
11776
  ];
11722
11777
 
11723
11778
  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
11779
+ _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
11780
 
11726
11781
  this.subscriptionObserverMap.set(subscriptionId, {
11727
11782
  observer: observer,
11728
11783
  subscriptionState: subscriptionState,
11729
- variables: variables,
11730
- query: query,
11784
+ query: query !== null && query !== void 0 ? query : '',
11785
+ variables: variables !== null && variables !== void 0 ? variables : {},
11731
11786
  subscriptionReadyCallback: subscriptionReadyCallback,
11732
11787
  subscriptionFailedCallback: subscriptionFailedCallback,
11733
11788
  startAckTimeoutId: setTimeout(function () {
11734
11789
  _this._timeoutStartSubscriptionAck.call(_this, subscriptionId);
11735
- }, START_ACK_TIMEOUT)
11790
+ }, _constants__WEBPACK_IMPORTED_MODULE_10__["START_ACK_TIMEOUT"])
11736
11791
  });
11737
11792
 
11738
11793
  if (this.awsRealTimeSocket) {
@@ -11750,32 +11805,35 @@ function (_super) {
11750
11805
 
11751
11806
  AWSAppSyncRealTimeProvider.prototype._waitForSubscriptionToBeConnected = function (subscriptionId) {
11752
11807
  return __awaiter(this, void 0, void 0, function () {
11753
- var subscriptionState;
11808
+ var subscriptionObserver, subscriptionState;
11754
11809
 
11755
11810
  var _this = this;
11756
11811
 
11757
11812
  return __generator(this, function (_a) {
11758
- subscriptionState = this.subscriptionObserverMap.get(subscriptionId).subscriptionState; // This in case unsubscribe is invoked before sending start subscription message
11813
+ subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
11759
11814
 
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
- })];
11815
+ if (subscriptionObserver) {
11816
+ subscriptionState = subscriptionObserver.subscriptionState; // This in case unsubscribe is invoked before sending start subscription message
11817
+
11818
+ if (subscriptionState === _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].PENDING) {
11819
+ return [2
11820
+ /*return*/
11821
+ , new Promise(function (res, rej) {
11822
+ var observer = subscriptionObserver.observer,
11823
+ subscriptionState = subscriptionObserver.subscriptionState,
11824
+ variables = subscriptionObserver.variables,
11825
+ query = subscriptionObserver.query;
11826
+
11827
+ _this.subscriptionObserverMap.set(subscriptionId, {
11828
+ observer: observer,
11829
+ subscriptionState: subscriptionState,
11830
+ variables: variables,
11831
+ query: query,
11832
+ subscriptionReadyCallback: res,
11833
+ subscriptionFailedCallback: rej
11834
+ });
11835
+ })];
11836
+ }
11779
11837
  }
11780
11838
 
11781
11839
  return [2
@@ -11787,11 +11845,11 @@ function (_super) {
11787
11845
 
11788
11846
  AWSAppSyncRealTimeProvider.prototype._sendUnsubscriptionMessage = function (subscriptionId) {
11789
11847
  try {
11790
- if (this.awsRealTimeSocket && this.awsRealTimeSocket.readyState === WebSocket.OPEN && this.socketStatus === SOCKET_STATUS.READY) {
11848
+ if (this.awsRealTimeSocket && this.awsRealTimeSocket.readyState === WebSocket.OPEN && this.socketStatus === _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].READY) {
11791
11849
  // Preparing unsubscribe message to stop receiving messages for that subscription
11792
11850
  var unsubscribeMessage = {
11793
11851
  id: subscriptionId,
11794
- type: MESSAGE_TYPES.GQL_STOP
11852
+ type: _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_STOP
11795
11853
  };
11796
11854
  var stringToAWSRealTime = JSON.stringify(unsubscribeMessage);
11797
11855
  this.awsRealTimeSocket.send(stringToAWSRealTime);
@@ -11817,7 +11875,7 @@ function (_super) {
11817
11875
  }
11818
11876
 
11819
11877
  if (!this.awsRealTimeSocket) {
11820
- this.socketStatus = SOCKET_STATUS.CLOSED;
11878
+ this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
11821
11879
  return;
11822
11880
  }
11823
11881
 
@@ -11826,14 +11884,14 @@ function (_super) {
11826
11884
  setTimeout(this._closeSocketIfRequired.bind(this), 1000);
11827
11885
  } else {
11828
11886
  logger.debug('closing WebSocket...');
11829
- clearTimeout(this.keepAliveTimeoutId);
11887
+ if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
11830
11888
  var tempSocket = this.awsRealTimeSocket; // Cleaning callbacks to avoid race condition, socket still exists
11831
11889
 
11832
- tempSocket.onclose = undefined;
11833
- tempSocket.onerror = undefined;
11890
+ tempSocket.onclose = null;
11891
+ tempSocket.onerror = null;
11834
11892
  tempSocket.close(1000);
11835
- this.awsRealTimeSocket = null;
11836
- this.socketStatus = SOCKET_STATUS.CLOSED;
11893
+ this.awsRealTimeSocket = undefined;
11894
+ this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
11837
11895
  }
11838
11896
  };
11839
11897
 
@@ -11864,7 +11922,7 @@ function (_super) {
11864
11922
  variables: variables
11865
11923
  });
11866
11924
 
11867
- if (type === MESSAGE_TYPES.GQL_DATA && payload && payload.data) {
11925
+ if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_DATA && payload && payload.data) {
11868
11926
  if (observer) {
11869
11927
  observer.next(payload);
11870
11928
  } else {
@@ -11874,7 +11932,7 @@ function (_super) {
11874
11932
  return;
11875
11933
  }
11876
11934
 
11877
- if (type === MESSAGE_TYPES.GQL_START_ACK) {
11935
+ if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_START_ACK) {
11878
11936
  logger.debug("subscription ready for " + JSON.stringify({
11879
11937
  query: query,
11880
11938
  variables: variables
@@ -11884,50 +11942,57 @@ function (_super) {
11884
11942
  subscriptionReadyCallback();
11885
11943
  }
11886
11944
 
11887
- clearTimeout(startAckTimeoutId);
11945
+ if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
11888
11946
  dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].SUBSCRIPTION_ACK, {
11889
11947
  query: query,
11890
11948
  variables: variables
11891
11949
  }, 'Connection established for subscription');
11892
- 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
11950
+ var subscriptionState = _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].CONNECTED;
11951
+
11952
+ if (observer) {
11953
+ this.subscriptionObserverMap.set(id, {
11954
+ observer: observer,
11955
+ query: query,
11956
+ variables: variables,
11957
+ startAckTimeoutId: undefined,
11958
+ subscriptionState: subscriptionState,
11959
+ subscriptionReadyCallback: subscriptionReadyCallback,
11960
+ subscriptionFailedCallback: subscriptionFailedCallback
11961
+ });
11962
+ } // TODO: emit event on hub but it requires to store the id first
11963
+
11902
11964
 
11903
11965
  return;
11904
11966
  }
11905
11967
 
11906
- if (type === MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) {
11907
- clearTimeout(this.keepAliveTimeoutId);
11968
+ if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_CONNECTION_KEEP_ALIVE) {
11969
+ if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
11908
11970
  this.keepAliveTimeoutId = setTimeout(this._errorDisconnect.bind(this, _index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT), this.keepAliveTimeout);
11909
11971
  return;
11910
11972
  }
11911
11973
 
11912
- if (type === MESSAGE_TYPES.GQL_ERROR) {
11913
- 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();
11974
+ if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_ERROR) {
11975
+ var subscriptionState = _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].FAILED;
11928
11976
 
11929
- if (typeof subscriptionFailedCallback === 'function') {
11930
- subscriptionFailedCallback();
11977
+ if (observer) {
11978
+ this.subscriptionObserverMap.set(id, {
11979
+ observer: observer,
11980
+ query: query,
11981
+ variables: variables,
11982
+ startAckTimeoutId: startAckTimeoutId,
11983
+ subscriptionReadyCallback: subscriptionReadyCallback,
11984
+ subscriptionFailedCallback: subscriptionFailedCallback,
11985
+ subscriptionState: subscriptionState
11986
+ });
11987
+ observer.error({
11988
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
11989
+ });
11990
+ if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
11991
+ observer.complete();
11992
+
11993
+ if (typeof subscriptionFailedCallback === 'function') {
11994
+ subscriptionFailedCallback();
11995
+ }
11931
11996
  }
11932
11997
  }
11933
11998
  };
@@ -11949,41 +12014,44 @@ function (_super) {
11949
12014
  this.awsRealTimeSocket.close();
11950
12015
  }
11951
12016
 
11952
- this.socketStatus = SOCKET_STATUS.CLOSED;
12017
+ this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
11953
12018
  };
11954
12019
 
11955
12020
  AWSAppSyncRealTimeProvider.prototype._timeoutStartSubscriptionAck = function (subscriptionId) {
11956
- var _a = this.subscriptionObserverMap.get(subscriptionId) || {},
11957
- observer = _a.observer,
11958
- query = _a.query,
11959
- variables = _a.variables;
12021
+ var subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
11960
12022
 
11961
- if (!observer) {
11962
- return;
11963
- }
12023
+ if (subscriptionObserver) {
12024
+ var observer = subscriptionObserver.observer,
12025
+ query = subscriptionObserver.query,
12026
+ variables = subscriptionObserver.variables;
11964
12027
 
11965
- this.subscriptionObserverMap.set(subscriptionId, {
11966
- observer: observer,
11967
- query: query,
11968
- variables: variables,
11969
- subscriptionState: SUBSCRIPTION_STATUS.FAILED
11970
- });
12028
+ if (!observer) {
12029
+ return;
12030
+ }
11971
12031
 
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
12032
+ this.subscriptionObserverMap.set(subscriptionId, {
12033
+ observer: observer,
12034
+ query: query,
12035
+ variables: variables,
12036
+ subscriptionState: _constants__WEBPACK_IMPORTED_MODULE_10__["SUBSCRIPTION_STATUS"].FAILED
12037
+ });
11979
12038
 
11980
- observer.complete();
11981
- }
12039
+ if (observer && !observer.closed) {
12040
+ observer.error({
12041
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscription timeout " + JSON.stringify({
12042
+ query: query,
12043
+ variables: variables
12044
+ })))]
12045
+ }); // Cleanup will be automatically executed
11982
12046
 
11983
- logger.debug('timeoutStartSubscription', JSON.stringify({
11984
- query: query,
11985
- variables: variables
11986
- }));
12047
+ observer.complete();
12048
+ }
12049
+
12050
+ logger.debug('timeoutStartSubscription', JSON.stringify({
12051
+ query: query,
12052
+ variables: variables
12053
+ }));
12054
+ }
11987
12055
  };
11988
12056
 
11989
12057
  AWSAppSyncRealTimeProvider.prototype._initializeWebSocketConnection = function (_a) {
@@ -11995,7 +12063,7 @@ function (_super) {
11995
12063
  region = _a.region,
11996
12064
  additionalHeaders = _a.additionalHeaders;
11997
12065
 
11998
- if (this.socketStatus === SOCKET_STATUS.READY) {
12066
+ if (this.socketStatus === _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].READY) {
11999
12067
  return;
12000
12068
  }
12001
12069
 
@@ -12010,7 +12078,7 @@ function (_super) {
12010
12078
  res: res,
12011
12079
  rej: rej
12012
12080
  });
12013
- if (!(this.socketStatus === SOCKET_STATUS.CLOSED)) return [3
12081
+ if (!(this.socketStatus === _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED)) return [3
12014
12082
  /*break*/
12015
12083
  , 5];
12016
12084
  _c.label = 1;
@@ -12018,7 +12086,7 @@ function (_super) {
12018
12086
  case 1:
12019
12087
  _c.trys.push([1, 4,, 5]);
12020
12088
 
12021
- this.socketStatus = SOCKET_STATUS.CONNECTING;
12089
+ this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CONNECTING;
12022
12090
  payloadString = '{}';
12023
12091
  _b = (_a = JSON).stringify;
12024
12092
  return [4
@@ -12037,7 +12105,7 @@ function (_super) {
12037
12105
  headerString = _b.apply(_a, [_c.sent()]);
12038
12106
  headerQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(headerString).toString('base64');
12039
12107
  payloadQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(payloadString).toString('base64');
12040
- discoverableEndpoint = appSyncGraphqlEndpoint;
12108
+ discoverableEndpoint = appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '';
12041
12109
 
12042
12110
  if (this.isCustomDomain(discoverableEndpoint)) {
12043
12111
  discoverableEndpoint = discoverableEndpoint.concat(customDomainPath);
@@ -12050,9 +12118,7 @@ function (_super) {
12050
12118
  awsRealTimeUrl = discoverableEndpoint + "?header=" + headerQs + "&payload=" + payloadQs;
12051
12119
  return [4
12052
12120
  /*yield*/
12053
- , this._initializeRetryableHandshake({
12054
- awsRealTimeUrl: awsRealTimeUrl
12055
- })];
12121
+ , this._initializeRetryableHandshake(awsRealTimeUrl)];
12056
12122
 
12057
12123
  case 3:
12058
12124
  _c.sent();
@@ -12062,7 +12128,7 @@ function (_super) {
12062
12128
  logger.debug('Notifying connection successful');
12063
12129
  res();
12064
12130
  });
12065
- this.socketStatus = SOCKET_STATUS.READY;
12131
+ this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].READY;
12066
12132
  this.promiseArray = [];
12067
12133
  return [3
12068
12134
  /*break*/
@@ -12080,8 +12146,8 @@ function (_super) {
12080
12146
  this.awsRealTimeSocket.close(3001);
12081
12147
  }
12082
12148
 
12083
- this.awsRealTimeSocket = null;
12084
- this.socketStatus = SOCKET_STATUS.CLOSED;
12149
+ this.awsRealTimeSocket = undefined;
12150
+ this.socketStatus = _constants__WEBPACK_IMPORTED_MODULE_10__["SOCKET_STATUS"].CLOSED;
12085
12151
  return [3
12086
12152
  /*break*/
12087
12153
  , 5];
@@ -12096,21 +12162,18 @@ function (_super) {
12096
12162
  });
12097
12163
  };
12098
12164
 
12099
- AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (_a) {
12100
- var awsRealTimeUrl = _a.awsRealTimeUrl;
12165
+ AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (awsRealTimeUrl) {
12101
12166
  return __awaiter(this, void 0, void 0, function () {
12102
- return __generator(this, function (_b) {
12103
- switch (_b.label) {
12167
+ return __generator(this, function (_a) {
12168
+ switch (_a.label) {
12104
12169
  case 0:
12105
12170
  logger.debug("Initializaling retryable Handshake");
12106
12171
  return [4
12107
12172
  /*yield*/
12108
- , Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [{
12109
- awsRealTimeUrl: awsRealTimeUrl
12110
- }], MAX_DELAY_MS)];
12173
+ , Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [awsRealTimeUrl], _constants__WEBPACK_IMPORTED_MODULE_10__["MAX_DELAY_MS"])];
12111
12174
 
12112
12175
  case 1:
12113
- _b.sent();
12176
+ _a.sent();
12114
12177
 
12115
12178
  return [2
12116
12179
  /*return*/
@@ -12120,10 +12183,9 @@ function (_super) {
12120
12183
  });
12121
12184
  };
12122
12185
 
12123
- AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (_a) {
12124
- var awsRealTimeUrl = _a.awsRealTimeUrl;
12186
+ AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (awsRealTimeUrl) {
12125
12187
  return __awaiter(this, void 0, void 0, function () {
12126
- var err_4, errorType, errorCode;
12188
+ var err_4, _a, errorType, errorCode;
12127
12189
 
12128
12190
  var _this = this;
12129
12191
 
@@ -12140,7 +12202,7 @@ function (_super) {
12140
12202
  /*yield*/
12141
12203
  , function () {
12142
12204
  return new Promise(function (res, rej) {
12143
- var newSocket = new WebSocket(awsRealTimeUrl, 'graphql-ws');
12205
+ var newSocket = _this.getNewWebSocket(awsRealTimeUrl, 'graphql-ws');
12144
12206
 
12145
12207
  newSocket.onerror = function () {
12146
12208
  logger.debug("WebSocket connection error");
@@ -12165,77 +12227,82 @@ function (_super) {
12165
12227
  /*yield*/
12166
12228
  , function () {
12167
12229
  return new Promise(function (res, rej) {
12168
- var ackOk = false;
12230
+ if (_this.awsRealTimeSocket) {
12231
+ var ackOk_1 = false;
12169
12232
 
12170
- _this.awsRealTimeSocket.onerror = function (error) {
12171
- logger.debug("WebSocket error " + JSON.stringify(error));
12172
- };
12233
+ _this.awsRealTimeSocket.onerror = function (error) {
12234
+ logger.debug("WebSocket error " + JSON.stringify(error));
12235
+ };
12173
12236
 
12174
- _this.awsRealTimeSocket.onclose = function (event) {
12175
- logger.debug("WebSocket closed " + event.reason);
12176
- rej(new Error(JSON.stringify(event)));
12177
- };
12237
+ _this.awsRealTimeSocket.onclose = function (event) {
12238
+ logger.debug("WebSocket closed " + event.reason);
12239
+ rej(new Error(JSON.stringify(event)));
12240
+ };
12178
12241
 
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;
12242
+ _this.awsRealTimeSocket.onmessage = function (message) {
12243
+ logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
12244
+ var data = JSON.parse(message.data);
12245
+ var type = data.type,
12246
+ _a = data.payload,
12247
+ _b = (_a === void 0 ? {} : _a).connectionTimeoutMs,
12248
+ connectionTimeoutMs = _b === void 0 ? _constants__WEBPACK_IMPORTED_MODULE_10__["DEFAULT_KEEP_ALIVE_TIMEOUT"] : _b;
12186
12249
 
12187
- if (type === MESSAGE_TYPES.GQL_CONNECTION_ACK) {
12188
- ackOk = true;
12189
- _this.keepAliveTimeout = connectionTimeoutMs;
12190
- _this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
12250
+ if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_CONNECTION_ACK) {
12251
+ ackOk_1 = true;
12191
12252
 
12192
- _this.awsRealTimeSocket.onerror = function (err) {
12193
- logger.debug(err);
12253
+ if (_this.awsRealTimeSocket) {
12254
+ _this.keepAliveTimeout = connectionTimeoutMs;
12255
+ _this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
12194
12256
 
12195
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12196
- };
12257
+ _this.awsRealTimeSocket.onerror = function (err) {
12258
+ logger.debug(err);
12197
12259
 
12198
- _this.awsRealTimeSocket.onclose = function (event) {
12199
- logger.debug("WebSocket closed " + event.reason);
12260
+ _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12261
+ };
12200
12262
 
12201
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12202
- };
12263
+ _this.awsRealTimeSocket.onclose = function (event) {
12264
+ logger.debug("WebSocket closed " + event.reason);
12203
12265
 
12204
- res('Cool, connected to AWS AppSyncRealTime');
12205
- return;
12206
- }
12266
+ _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
12267
+ };
12268
+ }
12207
12269
 
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
- };
12270
+ res('Cool, connected to AWS AppSyncRealTime');
12271
+ return;
12272
+ }
12225
12273
 
12226
- var gqlInit = {
12227
- type: MESSAGE_TYPES.GQL_CONNECTION_INIT
12228
- };
12274
+ if (type === _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_CONNECTION_ERROR) {
12275
+ var _c = data.payload,
12276
+ _d = (_c === void 0 ? {} : _c).errors,
12277
+ _e = __read(_d === void 0 ? [] : _d, 1),
12278
+ _f = _e[0],
12279
+ _g = _f === void 0 ? {} : _f,
12280
+ _h = _g.errorType,
12281
+ errorType = _h === void 0 ? '' : _h,
12282
+ _j = _g.errorCode,
12283
+ errorCode = _j === void 0 ? 0 : _j;
12284
+
12285
+ rej({
12286
+ errorType: errorType,
12287
+ errorCode: errorCode
12288
+ });
12289
+ }
12290
+ };
12291
+
12292
+ var gqlInit = {
12293
+ type: _constants__WEBPACK_IMPORTED_MODULE_10__["MESSAGE_TYPES"].GQL_CONNECTION_INIT
12294
+ };
12229
12295
 
12230
- _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
12296
+ _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
12231
12297
 
12232
- function checkAckOk() {
12298
+ setTimeout(checkAckOk.bind(_this, ackOk_1), _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"]);
12299
+ }
12300
+
12301
+ function checkAckOk(ackOk) {
12233
12302
  if (!ackOk) {
12234
- rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + CONNECTION_INIT_TIMEOUT + " ms"));
12303
+ rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + _constants__WEBPACK_IMPORTED_MODULE_10__["CONNECTION_INIT_TIMEOUT"] + " ms"));
12235
12304
  }
12236
12305
  }
12237
-
12238
- setTimeout(checkAckOk.bind(_this), CONNECTION_INIT_TIMEOUT);
12239
12306
  });
12240
12307
  }()];
12241
12308
 
@@ -12249,9 +12316,9 @@ function (_super) {
12249
12316
 
12250
12317
  case 4:
12251
12318
  err_4 = _b.sent();
12252
- errorType = err_4.errorType, errorCode = err_4.errorCode;
12319
+ _a = err_4, errorType = _a.errorType, errorCode = _a.errorCode;
12253
12320
 
12254
- if (NON_RETRYABLE_CODES.includes(errorCode)) {
12321
+ if (_constants__WEBPACK_IMPORTED_MODULE_10__["NON_RETRYABLE_CODES"].includes(errorCode)) {
12255
12322
  throw new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["NonRetryableError"](errorType);
12256
12323
  } else if (errorType) {
12257
12324
  throw new Error(errorType);
@@ -12292,16 +12359,18 @@ function (_super) {
12292
12359
  AMAZON_COGNITO_USER_POOLS: this._awsRealTimeCUPHeader.bind(this),
12293
12360
  AWS_LAMBDA: this._customAuthHeader
12294
12361
  };
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
- }
12362
+ if (!(!authenticationType || !headerHandler[authenticationType])) return [3
12363
+ /*break*/
12364
+ , 1];
12365
+ logger.debug("Authentication type " + authenticationType + " not supported");
12366
+ return [2
12367
+ /*return*/
12368
+ , ''];
12303
12369
 
12304
- host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint).host;
12370
+ case 1:
12371
+ handler = headerHandler[authenticationType];
12372
+ host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
12373
+ logger.debug("Authenticating with " + authenticationType);
12305
12374
  return [4
12306
12375
  /*yield*/
12307
12376
  , handler({
@@ -12314,7 +12383,7 @@ function (_super) {
12314
12383
  additionalHeaders: additionalHeaders
12315
12384
  })];
12316
12385
 
12317
- case 1:
12386
+ case 2:
12318
12387
  result = _b.sent();
12319
12388
  return [2
12320
12389
  /*return*/
@@ -12446,10 +12515,14 @@ function (_super) {
12446
12515
  return [4
12447
12516
  /*yield*/
12448
12517
  , _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Credentials"].get().then(function (credentials) {
12518
+ var _a = credentials,
12519
+ secretAccessKey = _a.secretAccessKey,
12520
+ accessKeyId = _a.accessKeyId,
12521
+ sessionToken = _a.sessionToken;
12449
12522
  return {
12450
- secret_key: credentials.secretAccessKey,
12451
- access_key: credentials.accessKeyId,
12452
- session_token: credentials.sessionToken
12523
+ secret_key: secretAccessKey,
12524
+ access_key: accessKeyId,
12525
+ session_token: sessionToken
12453
12526
  };
12454
12527
  })];
12455
12528
 
@@ -12459,7 +12532,7 @@ function (_super) {
12459
12532
  url: "" + appSyncGraphqlEndpoint + canonicalUri,
12460
12533
  data: payload,
12461
12534
  method: 'POST',
12462
- headers: __assign({}, AWS_APPSYNC_REALTIME_HEADERS)
12535
+ headers: __assign({}, _constants__WEBPACK_IMPORTED_MODULE_10__["AWS_APPSYNC_REALTIME_HEADERS"])
12463
12536
  };
12464
12537
  signed_params = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Signer"].sign(request, creds, endpointInfo);
12465
12538
  return [2
@@ -12474,7 +12547,7 @@ function (_super) {
12474
12547
  var host = _a.host,
12475
12548
  additionalHeaders = _a.additionalHeaders;
12476
12549
 
12477
- if (!additionalHeaders.Authorization) {
12550
+ if (!additionalHeaders || !additionalHeaders['Authorization']) {
12478
12551
  throw new Error('No auth token specified');
12479
12552
  }
12480
12553
 
@@ -12711,8 +12784,12 @@ var AWSIoTProvider =
12711
12784
  function (_super) {
12712
12785
  __extends(AWSIoTProvider, _super);
12713
12786
 
12714
- function AWSIoTProvider() {
12715
- return _super !== null && _super.apply(this, arguments) || this;
12787
+ function AWSIoTProvider(options) {
12788
+ if (options === void 0) {
12789
+ options = {};
12790
+ }
12791
+
12792
+ return _super.call(this, options) || this;
12716
12793
  }
12717
12794
 
12718
12795
  Object.defineProperty(AWSIoTProvider.prototype, "region", {
@@ -13042,21 +13119,27 @@ function () {
13042
13119
 
13043
13120
  ClientsQueue.prototype.get = function (clientId, clientFactory) {
13044
13121
  return __awaiter(this, void 0, void 0, function () {
13045
- var promise;
13122
+ var cachedPromise, newPromise;
13046
13123
  return __generator(this, function (_a) {
13047
- promise = this.promises.get(clientId);
13124
+ cachedPromise = this.promises.get(clientId);
13048
13125
 
13049
- if (promise) {
13126
+ if (cachedPromise) {
13050
13127
  return [2
13051
13128
  /*return*/
13052
- , promise];
13129
+ , cachedPromise];
13130
+ }
13131
+
13132
+ if (clientFactory) {
13133
+ newPromise = clientFactory(clientId);
13134
+ this.promises.set(clientId, newPromise);
13135
+ return [2
13136
+ /*return*/
13137
+ , newPromise];
13053
13138
  }
13054
13139
 
13055
- promise = clientFactory(clientId);
13056
- this.promises.set(clientId, promise);
13057
13140
  return [2
13058
13141
  /*return*/
13059
- , promise];
13142
+ , undefined];
13060
13143
  });
13061
13144
  });
13062
13145
  };
@@ -13148,6 +13231,10 @@ function (_super) {
13148
13231
  }, args), null, 2));
13149
13232
  var topicsToDelete_1 = [];
13150
13233
 
13234
+ if (!clientId) {
13235
+ return;
13236
+ }
13237
+
13151
13238
  var clientIdObservers = this._clientIdObservers.get(clientId);
13152
13239
 
13153
13240
  if (!clientIdObservers) {
@@ -13266,9 +13353,7 @@ function (_super) {
13266
13353
  case 0:
13267
13354
  return [4
13268
13355
  /*yield*/
13269
- , this.clientsQueue.get(clientId, function () {
13270
- return null;
13271
- })];
13356
+ , this.clientsQueue.get(clientId)];
13272
13357
 
13273
13358
  case 1:
13274
13359
  client = _a.sent();
@@ -13447,13 +13532,14 @@ function (_super) {
13447
13532
  })();
13448
13533
 
13449
13534
  return function () {
13535
+ var _a, _b;
13536
+
13450
13537
  logger.debug('Unsubscribing from topic(s)', targetTopics.join(','));
13451
13538
 
13452
13539
  if (client) {
13453
- _this._clientIdObservers.get(clientId)["delete"](observer); // No more observers per client => client not needed anymore
13454
-
13540
+ (_a = _this._clientIdObservers.get(clientId)) === null || _a === void 0 ? void 0 : _a["delete"](observer); // No more observers per client => client not needed anymore
13455
13541
 
13456
- if (_this._clientIdObservers.get(clientId).size === 0) {
13542
+ if (((_b = _this._clientIdObservers.get(clientId)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
13457
13543
  _this.disconnect(clientId);
13458
13544
 
13459
13545
  _this._clientIdObservers["delete"](clientId);
@@ -13570,7 +13656,7 @@ __webpack_require__.r(__webpack_exports__);
13570
13656
  /* harmony import */ var _AWSAppSyncProvider__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./AWSAppSyncProvider */ "../pubsub/lib-esm/Providers/AWSAppSyncProvider.js");
13571
13657
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AWSAppSyncProvider", function() { return _AWSAppSyncProvider__WEBPACK_IMPORTED_MODULE_1__["AWSAppSyncProvider"]; });
13572
13658
 
13573
- /* harmony import */ var _AWSAppSyncRealTimeProvider__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./AWSAppSyncRealTimeProvider */ "../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider.js");
13659
+ /* harmony import */ var _AWSAppSyncRealTimeProvider__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./AWSAppSyncRealTimeProvider */ "../pubsub/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js");
13574
13660
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AWSAppSyncRealTimeProvider", function() { return _AWSAppSyncRealTimeProvider__WEBPACK_IMPORTED_MODULE_2__["AWSAppSyncRealTimeProvider"]; });
13575
13661
 
13576
13662
  /* harmony import */ var _AWSIotProvider__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./AWSIotProvider */ "../pubsub/lib-esm/Providers/AWSIotProvider.js");
@@ -13788,7 +13874,7 @@ function () {
13788
13874
  * @param {PubSubOptions} options - Configuration object for PubSub
13789
13875
  */
13790
13876
  function PubSubClass(options) {
13791
- this._options = options;
13877
+ this._options = options !== null && options !== void 0 ? options : {};
13792
13878
  logger.debug('PubSub Options', this._options);
13793
13879
  this._pluggables = [];
13794
13880
  this.subscribe = this.subscribe.bind(this);
@@ -13977,7 +14063,7 @@ function () {
13977
14063
  }();
13978
14064
 
13979
14065
 
13980
- var PubSub = new PubSubClass(null);
14066
+ var PubSub = new PubSubClass();
13981
14067
  _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Amplify"].register(PubSub);
13982
14068
 
13983
14069
  /***/ }),
@@ -14573,9 +14659,9 @@ function () {
14573
14659
  /**
14574
14660
  * Executes a GraphQL operation
14575
14661
  *
14576
- * @param {GraphQLOptions} GraphQL Options
14577
- * @param {object} additionalHeaders headers to merge in after any `graphql_headers` set in the config
14578
- * @returns {Promise<GraphQLResult> | Observable<object>}
14662
+ * @param options - GraphQL Options
14663
+ * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
14664
+ * @returns An Observable if the query is a subscription query, else a promise of the graphql result.
14579
14665
  */
14580
14666
 
14581
14667
 
@@ -14625,9 +14711,10 @@ function () {
14625
14711
  variables: variables,
14626
14712
  authMode: authMode
14627
14713
  }, headers);
14628
- }
14629
14714
 
14630
- throw new Error("invalid operation type: " + operationType);
14715
+ default:
14716
+ throw new Error("invalid operation type: " + operationType);
14717
+ }
14631
14718
  };
14632
14719
 
14633
14720
  GraphQLAPIClass.prototype._graphql = function (_a, additionalHeaders, initParams) {
@@ -14808,6 +14895,16 @@ function () {
14808
14895
  GraphQLAPIClass.prototype.cancel = function (request, message) {
14809
14896
  return this._api.cancel(request, message);
14810
14897
  };
14898
+ /**
14899
+ * Check if the request has a corresponding cancel token in the WeakMap.
14900
+ * @params request - The request promise
14901
+ * @return if the request has a corresponding cancel token.
14902
+ */
14903
+
14904
+
14905
+ GraphQLAPIClass.prototype.hasCancelToken = function (request) {
14906
+ return this._api.hasCancelToken(request);
14907
+ };
14811
14908
 
14812
14909
  GraphQLAPIClass.prototype._graphqlSubscribe = function (_a, additionalHeaders) {
14813
14910
  var query = _a.query,
@@ -14928,17 +15025,12 @@ __webpack_require__.r(__webpack_exports__);
14928
15025
 
14929
15026
  "use strict";
14930
15027
  __webpack_require__.r(__webpack_exports__);
14931
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GRAPHQL_AUTH_MODE", function() { return GRAPHQL_AUTH_MODE; });
14932
15028
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "GraphQLAuthError", function() { return GraphQLAuthError; });
14933
- var GRAPHQL_AUTH_MODE;
14934
-
14935
- (function (GRAPHQL_AUTH_MODE) {
14936
- GRAPHQL_AUTH_MODE["API_KEY"] = "API_KEY";
14937
- GRAPHQL_AUTH_MODE["AWS_IAM"] = "AWS_IAM";
14938
- GRAPHQL_AUTH_MODE["OPENID_CONNECT"] = "OPENID_CONNECT";
14939
- GRAPHQL_AUTH_MODE["AMAZON_COGNITO_USER_POOLS"] = "AMAZON_COGNITO_USER_POOLS";
14940
- GRAPHQL_AUTH_MODE["AWS_LAMBDA"] = "AWS_LAMBDA";
14941
- })(GRAPHQL_AUTH_MODE || (GRAPHQL_AUTH_MODE = {}));
15029
+ /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @aws-amplify/auth */ "@aws-amplify/auth");
15030
+ /* harmony import */ var _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_0__);
15031
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "GRAPHQL_AUTH_MODE", function() { return _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_0__["GRAPHQL_AUTH_MODE"]; });
15032
+
15033
+
14942
15034
 
14943
15035
  var GraphQLAuthError;
14944
15036