@aws-amplify/pubsub 4.2.10-cloud-logging.7 → 4.2.10-cloud-logging.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +24 -49
  2. package/dist/aws-amplify-pubsub.js +238 -202
  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.d.ts +19 -4
  10. package/lib/Providers/AWSAppSyncRealTimeProvider.js +174 -154
  11. package/lib/Providers/AWSAppSyncRealTimeProvider.js.map +1 -1
  12. package/lib/Providers/AWSIotProvider.d.ts +6 -1
  13. package/lib/Providers/AWSIotProvider.js +3 -2
  14. package/lib/Providers/AWSIotProvider.js.map +1 -1
  15. package/lib/Providers/MqttOverWSProvider.d.ts +14 -11
  16. package/lib/Providers/MqttOverWSProvider.js +17 -10
  17. package/lib/Providers/MqttOverWSProvider.js.map +1 -1
  18. package/lib/Providers/PubSubProvider.d.ts +7 -7
  19. package/lib/Providers/PubSubProvider.js.map +1 -1
  20. package/lib/PubSub.d.ts +6 -6
  21. package/lib/PubSub.js +2 -2
  22. package/lib/PubSub.js.map +1 -1
  23. package/lib/types/Provider.d.ts +3 -3
  24. package/lib/types/PubSub.d.ts +5 -1
  25. package/lib-esm/Providers/AWSAppSyncProvider.d.ts +3 -0
  26. package/lib-esm/Providers/AWSAppSyncProvider.js +3 -0
  27. package/lib-esm/Providers/AWSAppSyncProvider.js.map +1 -1
  28. package/lib-esm/Providers/AWSAppSyncRealTimeProvider.d.ts +19 -4
  29. package/lib-esm/Providers/AWSAppSyncRealTimeProvider.js +174 -154
  30. package/lib-esm/Providers/AWSAppSyncRealTimeProvider.js.map +1 -1
  31. package/lib-esm/Providers/AWSIotProvider.d.ts +6 -1
  32. package/lib-esm/Providers/AWSIotProvider.js +3 -2
  33. package/lib-esm/Providers/AWSIotProvider.js.map +1 -1
  34. package/lib-esm/Providers/MqttOverWSProvider.d.ts +14 -11
  35. package/lib-esm/Providers/MqttOverWSProvider.js +17 -10
  36. package/lib-esm/Providers/MqttOverWSProvider.js.map +1 -1
  37. package/lib-esm/Providers/PubSubProvider.d.ts +7 -7
  38. package/lib-esm/Providers/PubSubProvider.js.map +1 -1
  39. package/lib-esm/PubSub.d.ts +6 -6
  40. package/lib-esm/PubSub.js +2 -2
  41. package/lib-esm/PubSub.js.map +1 -1
  42. package/lib-esm/types/Provider.d.ts +3 -3
  43. package/lib-esm/types/PubSub.d.ts +5 -1
  44. package/package.json +5 -5
  45. package/src/Providers/AWSAppSyncProvider.ts +27 -26
  46. package/src/Providers/AWSAppSyncRealTimeProvider.ts +247 -191
  47. package/src/Providers/AWSIotProvider.ts +10 -1
  48. package/src/Providers/MqttOverWSProvider.ts +52 -33
  49. package/src/Providers/PubSubProvider.ts +8 -8
  50. package/src/PubSub.ts +10 -10
  51. package/src/types/Provider.ts +3 -7
  52. package/src/types/PubSub.ts +6 -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 */
@@ -8028,9 +8031,9 @@ function (_super) {
8028
8031
  AWSAppSyncRealTimeProvider.prototype.subscribe = function (_topics, options) {
8029
8032
  var _this = this;
8030
8033
 
8031
- var appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint;
8034
+ var appSyncGraphqlEndpoint = options === null || options === void 0 ? void 0 : options.appSyncGraphqlEndpoint;
8032
8035
  return new zen_observable_ts__WEBPACK_IMPORTED_MODULE_0__["default"](function (observer) {
8033
- if (!appSyncGraphqlEndpoint) {
8036
+ if (!options || !appSyncGraphqlEndpoint) {
8034
8037
  observer.error({
8035
8038
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscribe only available for AWS AppSync endpoint"))]
8036
8039
  });
@@ -8123,19 +8126,22 @@ function (_super) {
8123
8126
  var options = _a.options,
8124
8127
  observer = _a.observer,
8125
8128
  subscriptionId = _a.subscriptionId;
8129
+
8130
+ var _b, _c;
8131
+
8126
8132
  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;
8133
+ 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
8134
 
8129
- var _h;
8135
+ var _j;
8130
8136
 
8131
8137
  var _this = this;
8132
8138
 
8133
- return __generator(this, function (_j) {
8134
- switch (_j.label) {
8139
+ return __generator(this, function (_k) {
8140
+ switch (_k.label) {
8135
8141
  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 () {
8142
+ 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
8143
  return {};
8138
- } : _b, _c = options.additionalHeaders, additionalHeaders = _c === void 0 ? {} : _c;
8144
+ } : _d, _e = options.additionalHeaders, additionalHeaders = _e === void 0 ? {} : _e;
8139
8145
  subscriptionState = SUBSCRIPTION_STATUS.PENDING;
8140
8146
  data = {
8141
8147
  query: query,
@@ -8144,13 +8150,13 @@ function (_super) {
8144
8150
 
8145
8151
  this.subscriptionObserverMap.set(subscriptionId, {
8146
8152
  observer: observer,
8147
- query: query,
8148
- variables: variables,
8153
+ query: query !== null && query !== void 0 ? query : '',
8154
+ variables: variables !== null && variables !== void 0 ? variables : {},
8149
8155
  subscriptionState: subscriptionState,
8150
- startAckTimeoutId: null
8156
+ startAckTimeoutId: undefined
8151
8157
  });
8152
8158
  dataString = JSON.stringify(data);
8153
- _d = [{}];
8159
+ _f = [{}];
8154
8160
  return [4
8155
8161
  /*yield*/
8156
8162
  , this._awsRealTimeHeaderBasedAuth({
@@ -8164,13 +8170,13 @@ function (_super) {
8164
8170
  })];
8165
8171
 
8166
8172
  case 1:
8167
- _e = [__assign.apply(void 0, _d.concat([_j.sent()]))];
8173
+ _g = [__assign.apply(void 0, _f.concat([_k.sent()]))];
8168
8174
  return [4
8169
8175
  /*yield*/
8170
8176
  , graphql_headers()];
8171
8177
 
8172
8178
  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)]);
8179
+ 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
8180
  subscriptionMessage = {
8175
8181
  id: subscriptionId,
8176
8182
  payload: {
@@ -8182,10 +8188,10 @@ function (_super) {
8182
8188
  type: MESSAGE_TYPES.GQL_START
8183
8189
  };
8184
8190
  stringToAWSRealTime = JSON.stringify(subscriptionMessage);
8185
- _j.label = 3;
8191
+ _k.label = 3;
8186
8192
 
8187
8193
  case 3:
8188
- _j.trys.push([3, 5,, 6]);
8194
+ _k.trys.push([3, 5,, 6]);
8189
8195
 
8190
8196
  return [4
8191
8197
  /*yield*/
@@ -8198,18 +8204,18 @@ function (_super) {
8198
8204
  })];
8199
8205
 
8200
8206
  case 4:
8201
- _j.sent();
8207
+ _k.sent();
8202
8208
 
8203
8209
  return [3
8204
8210
  /*break*/
8205
8211
  , 6];
8206
8212
 
8207
8213
  case 5:
8208
- err_2 = _j.sent();
8214
+ err_2 = _k.sent();
8209
8215
  logger.debug({
8210
8216
  err: err_2
8211
8217
  });
8212
- _f = err_2.message, message = _f === void 0 ? '' : _f;
8218
+ message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
8213
8219
  observer.error({
8214
8220
  errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
8215
8221
  });
@@ -8225,13 +8231,13 @@ function (_super) {
8225
8231
  ];
8226
8232
 
8227
8233
  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
8234
+ _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
8235
 
8230
8236
  this.subscriptionObserverMap.set(subscriptionId, {
8231
8237
  observer: observer,
8232
8238
  subscriptionState: subscriptionState,
8233
- variables: variables,
8234
- query: query,
8239
+ query: query !== null && query !== void 0 ? query : '',
8240
+ variables: variables !== null && variables !== void 0 ? variables : {},
8235
8241
  subscriptionReadyCallback: subscriptionReadyCallback,
8236
8242
  subscriptionFailedCallback: subscriptionFailedCallback,
8237
8243
  startAckTimeoutId: setTimeout(function () {
@@ -8254,32 +8260,35 @@ function (_super) {
8254
8260
 
8255
8261
  AWSAppSyncRealTimeProvider.prototype._waitForSubscriptionToBeConnected = function (subscriptionId) {
8256
8262
  return __awaiter(this, void 0, void 0, function () {
8257
- var subscriptionState;
8263
+ var subscriptionObserver, subscriptionState;
8258
8264
 
8259
8265
  var _this = this;
8260
8266
 
8261
8267
  return __generator(this, function (_a) {
8262
- subscriptionState = this.subscriptionObserverMap.get(subscriptionId).subscriptionState; // This in case unsubscribe is invoked before sending start subscription message
8268
+ subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
8263
8269
 
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
- })];
8270
+ if (subscriptionObserver) {
8271
+ subscriptionState = subscriptionObserver.subscriptionState; // This in case unsubscribe is invoked before sending start subscription message
8272
+
8273
+ if (subscriptionState === SUBSCRIPTION_STATUS.PENDING) {
8274
+ return [2
8275
+ /*return*/
8276
+ , new Promise(function (res, rej) {
8277
+ var observer = subscriptionObserver.observer,
8278
+ subscriptionState = subscriptionObserver.subscriptionState,
8279
+ variables = subscriptionObserver.variables,
8280
+ query = subscriptionObserver.query;
8281
+
8282
+ _this.subscriptionObserverMap.set(subscriptionId, {
8283
+ observer: observer,
8284
+ subscriptionState: subscriptionState,
8285
+ variables: variables,
8286
+ query: query,
8287
+ subscriptionReadyCallback: res,
8288
+ subscriptionFailedCallback: rej
8289
+ });
8290
+ })];
8291
+ }
8283
8292
  }
8284
8293
 
8285
8294
  return [2
@@ -8330,13 +8339,13 @@ function (_super) {
8330
8339
  setTimeout(this._closeSocketIfRequired.bind(this), 1000);
8331
8340
  } else {
8332
8341
  logger.debug('closing WebSocket...');
8333
- clearTimeout(this.keepAliveTimeoutId);
8342
+ if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
8334
8343
  var tempSocket = this.awsRealTimeSocket; // Cleaning callbacks to avoid race condition, socket still exists
8335
8344
 
8336
- tempSocket.onclose = undefined;
8337
- tempSocket.onerror = undefined;
8345
+ tempSocket.onclose = null;
8346
+ tempSocket.onerror = null;
8338
8347
  tempSocket.close(1000);
8339
- this.awsRealTimeSocket = null;
8348
+ this.awsRealTimeSocket = undefined;
8340
8349
  this.socketStatus = SOCKET_STATUS.CLOSED;
8341
8350
  }
8342
8351
  };
@@ -8401,50 +8410,57 @@ function (_super) {
8401
8410
  subscriptionReadyCallback();
8402
8411
  }
8403
8412
 
8404
- clearTimeout(startAckTimeoutId);
8413
+ if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
8405
8414
  dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].SUBSCRIPTION_ACK, {
8406
8415
  query: query,
8407
8416
  variables: variables
8408
8417
  }, 'Connection established for subscription');
8409
8418
  var subscriptionState = SUBSCRIPTION_STATUS.CONNECTED;
8410
- this.subscriptionObserverMap.set(id, {
8411
- observer: observer,
8412
- query: query,
8413
- variables: variables,
8414
- startAckTimeoutId: null,
8415
- subscriptionState: subscriptionState,
8416
- subscriptionReadyCallback: subscriptionReadyCallback,
8417
- subscriptionFailedCallback: subscriptionFailedCallback
8418
- }); // TODO: emit event on hub but it requires to store the id first
8419
+
8420
+ if (observer) {
8421
+ this.subscriptionObserverMap.set(id, {
8422
+ observer: observer,
8423
+ query: query,
8424
+ variables: variables,
8425
+ startAckTimeoutId: undefined,
8426
+ subscriptionState: subscriptionState,
8427
+ subscriptionReadyCallback: subscriptionReadyCallback,
8428
+ subscriptionFailedCallback: subscriptionFailedCallback
8429
+ });
8430
+ } // TODO: emit event on hub but it requires to store the id first
8431
+
8419
8432
 
8420
8433
  return;
8421
8434
  }
8422
8435
 
8423
8436
  if (type === MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) {
8424
- clearTimeout(this.keepAliveTimeoutId);
8437
+ if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
8425
8438
  this.keepAliveTimeoutId = setTimeout(this._errorDisconnect.bind(this, _index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT), this.keepAliveTimeout);
8426
8439
  return;
8427
8440
  }
8428
8441
 
8429
8442
  if (type === MESSAGE_TYPES.GQL_ERROR) {
8430
8443
  var subscriptionState = SUBSCRIPTION_STATUS.FAILED;
8431
- this.subscriptionObserverMap.set(id, {
8432
- observer: observer,
8433
- query: query,
8434
- variables: variables,
8435
- startAckTimeoutId: startAckTimeoutId,
8436
- subscriptionReadyCallback: subscriptionReadyCallback,
8437
- subscriptionFailedCallback: subscriptionFailedCallback,
8438
- subscriptionState: subscriptionState
8439
- });
8440
- observer.error({
8441
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
8442
- });
8443
- clearTimeout(startAckTimeoutId);
8444
- observer.complete();
8445
8444
 
8446
- if (typeof subscriptionFailedCallback === 'function') {
8447
- subscriptionFailedCallback();
8445
+ if (observer) {
8446
+ this.subscriptionObserverMap.set(id, {
8447
+ observer: observer,
8448
+ query: query,
8449
+ variables: variables,
8450
+ startAckTimeoutId: startAckTimeoutId,
8451
+ subscriptionReadyCallback: subscriptionReadyCallback,
8452
+ subscriptionFailedCallback: subscriptionFailedCallback,
8453
+ subscriptionState: subscriptionState
8454
+ });
8455
+ observer.error({
8456
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
8457
+ });
8458
+ if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
8459
+ observer.complete();
8460
+
8461
+ if (typeof subscriptionFailedCallback === 'function') {
8462
+ subscriptionFailedCallback();
8463
+ }
8448
8464
  }
8449
8465
  }
8450
8466
  };
@@ -8470,37 +8486,40 @@ function (_super) {
8470
8486
  };
8471
8487
 
8472
8488
  AWSAppSyncRealTimeProvider.prototype._timeoutStartSubscriptionAck = function (subscriptionId) {
8473
- var _a = this.subscriptionObserverMap.get(subscriptionId) || {},
8474
- observer = _a.observer,
8475
- query = _a.query,
8476
- variables = _a.variables;
8489
+ var subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
8477
8490
 
8478
- if (!observer) {
8479
- return;
8480
- }
8491
+ if (subscriptionObserver) {
8492
+ var observer = subscriptionObserver.observer,
8493
+ query = subscriptionObserver.query,
8494
+ variables = subscriptionObserver.variables;
8481
8495
 
8482
- this.subscriptionObserverMap.set(subscriptionId, {
8483
- observer: observer,
8484
- query: query,
8485
- variables: variables,
8486
- subscriptionState: SUBSCRIPTION_STATUS.FAILED
8487
- });
8496
+ if (!observer) {
8497
+ return;
8498
+ }
8488
8499
 
8489
- if (observer && !observer.closed) {
8490
- observer.error({
8491
- errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscription timeout " + JSON.stringify({
8492
- query: query,
8493
- variables: variables
8494
- })))]
8495
- }); // Cleanup will be automatically executed
8500
+ this.subscriptionObserverMap.set(subscriptionId, {
8501
+ observer: observer,
8502
+ query: query,
8503
+ variables: variables,
8504
+ subscriptionState: SUBSCRIPTION_STATUS.FAILED
8505
+ });
8496
8506
 
8497
- observer.complete();
8498
- }
8507
+ if (observer && !observer.closed) {
8508
+ observer.error({
8509
+ errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscription timeout " + JSON.stringify({
8510
+ query: query,
8511
+ variables: variables
8512
+ })))]
8513
+ }); // Cleanup will be automatically executed
8499
8514
 
8500
- logger.debug('timeoutStartSubscription', JSON.stringify({
8501
- query: query,
8502
- variables: variables
8503
- }));
8515
+ observer.complete();
8516
+ }
8517
+
8518
+ logger.debug('timeoutStartSubscription', JSON.stringify({
8519
+ query: query,
8520
+ variables: variables
8521
+ }));
8522
+ }
8504
8523
  };
8505
8524
 
8506
8525
  AWSAppSyncRealTimeProvider.prototype._initializeWebSocketConnection = function (_a) {
@@ -8554,7 +8573,7 @@ function (_super) {
8554
8573
  headerString = _b.apply(_a, [_c.sent()]);
8555
8574
  headerQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(headerString).toString('base64');
8556
8575
  payloadQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(payloadString).toString('base64');
8557
- discoverableEndpoint = appSyncGraphqlEndpoint;
8576
+ discoverableEndpoint = appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '';
8558
8577
 
8559
8578
  if (this.isCustomDomain(discoverableEndpoint)) {
8560
8579
  discoverableEndpoint = discoverableEndpoint.concat(customDomainPath);
@@ -8567,9 +8586,7 @@ function (_super) {
8567
8586
  awsRealTimeUrl = discoverableEndpoint + "?header=" + headerQs + "&payload=" + payloadQs;
8568
8587
  return [4
8569
8588
  /*yield*/
8570
- , this._initializeRetryableHandshake({
8571
- awsRealTimeUrl: awsRealTimeUrl
8572
- })];
8589
+ , this._initializeRetryableHandshake(awsRealTimeUrl)];
8573
8590
 
8574
8591
  case 3:
8575
8592
  _c.sent();
@@ -8597,7 +8614,7 @@ function (_super) {
8597
8614
  this.awsRealTimeSocket.close(3001);
8598
8615
  }
8599
8616
 
8600
- this.awsRealTimeSocket = null;
8617
+ this.awsRealTimeSocket = undefined;
8601
8618
  this.socketStatus = SOCKET_STATUS.CLOSED;
8602
8619
  return [3
8603
8620
  /*break*/
@@ -8613,21 +8630,18 @@ function (_super) {
8613
8630
  });
8614
8631
  };
8615
8632
 
8616
- AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (_a) {
8617
- var awsRealTimeUrl = _a.awsRealTimeUrl;
8633
+ AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (awsRealTimeUrl) {
8618
8634
  return __awaiter(this, void 0, void 0, function () {
8619
- return __generator(this, function (_b) {
8620
- switch (_b.label) {
8635
+ return __generator(this, function (_a) {
8636
+ switch (_a.label) {
8621
8637
  case 0:
8622
8638
  logger.debug("Initializaling retryable Handshake");
8623
8639
  return [4
8624
8640
  /*yield*/
8625
- , Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [{
8626
- awsRealTimeUrl: awsRealTimeUrl
8627
- }], MAX_DELAY_MS)];
8641
+ , Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [awsRealTimeUrl], MAX_DELAY_MS)];
8628
8642
 
8629
8643
  case 1:
8630
- _b.sent();
8644
+ _a.sent();
8631
8645
 
8632
8646
  return [2
8633
8647
  /*return*/
@@ -8637,10 +8651,9 @@ function (_super) {
8637
8651
  });
8638
8652
  };
8639
8653
 
8640
- AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (_a) {
8641
- var awsRealTimeUrl = _a.awsRealTimeUrl;
8654
+ AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (awsRealTimeUrl) {
8642
8655
  return __awaiter(this, void 0, void 0, function () {
8643
- var err_4, errorType, errorCode;
8656
+ var err_4, _a, errorType, errorCode;
8644
8657
 
8645
8658
  var _this = this;
8646
8659
 
@@ -8682,77 +8695,82 @@ function (_super) {
8682
8695
  /*yield*/
8683
8696
  , function () {
8684
8697
  return new Promise(function (res, rej) {
8685
- var ackOk = false;
8698
+ if (_this.awsRealTimeSocket) {
8699
+ var ackOk_1 = false;
8686
8700
 
8687
- _this.awsRealTimeSocket.onerror = function (error) {
8688
- logger.debug("WebSocket error " + JSON.stringify(error));
8689
- };
8701
+ _this.awsRealTimeSocket.onerror = function (error) {
8702
+ logger.debug("WebSocket error " + JSON.stringify(error));
8703
+ };
8690
8704
 
8691
- _this.awsRealTimeSocket.onclose = function (event) {
8692
- logger.debug("WebSocket closed " + event.reason);
8693
- rej(new Error(JSON.stringify(event)));
8694
- };
8705
+ _this.awsRealTimeSocket.onclose = function (event) {
8706
+ logger.debug("WebSocket closed " + event.reason);
8707
+ rej(new Error(JSON.stringify(event)));
8708
+ };
8695
8709
 
8696
- _this.awsRealTimeSocket.onmessage = function (message) {
8697
- logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
8698
- var data = JSON.parse(message.data);
8699
- var type = data.type,
8700
- _a = data.payload,
8701
- _b = (_a === void 0 ? {} : _a).connectionTimeoutMs,
8702
- connectionTimeoutMs = _b === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _b;
8710
+ _this.awsRealTimeSocket.onmessage = function (message) {
8711
+ logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
8712
+ var data = JSON.parse(message.data);
8713
+ var type = data.type,
8714
+ _a = data.payload,
8715
+ _b = (_a === void 0 ? {} : _a).connectionTimeoutMs,
8716
+ connectionTimeoutMs = _b === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _b;
8703
8717
 
8704
- if (type === MESSAGE_TYPES.GQL_CONNECTION_ACK) {
8705
- ackOk = true;
8706
- _this.keepAliveTimeout = connectionTimeoutMs;
8707
- _this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
8718
+ if (type === MESSAGE_TYPES.GQL_CONNECTION_ACK) {
8719
+ ackOk_1 = true;
8708
8720
 
8709
- _this.awsRealTimeSocket.onerror = function (err) {
8710
- logger.debug(err);
8721
+ if (_this.awsRealTimeSocket) {
8722
+ _this.keepAliveTimeout = connectionTimeoutMs;
8723
+ _this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
8711
8724
 
8712
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
8713
- };
8725
+ _this.awsRealTimeSocket.onerror = function (err) {
8726
+ logger.debug(err);
8714
8727
 
8715
- _this.awsRealTimeSocket.onclose = function (event) {
8716
- logger.debug("WebSocket closed " + event.reason);
8728
+ _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
8729
+ };
8717
8730
 
8718
- _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
8719
- };
8731
+ _this.awsRealTimeSocket.onclose = function (event) {
8732
+ logger.debug("WebSocket closed " + event.reason);
8720
8733
 
8721
- res('Cool, connected to AWS AppSyncRealTime');
8722
- return;
8723
- }
8734
+ _this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
8735
+ };
8736
+ }
8724
8737
 
8725
- if (type === MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
8726
- var _c = data.payload,
8727
- _d = (_c === void 0 ? {} : _c).errors,
8728
- _e = __read(_d === void 0 ? [] : _d, 1),
8729
- _f = _e[0],
8730
- _g = _f === void 0 ? {} : _f,
8731
- _h = _g.errorType,
8732
- errorType = _h === void 0 ? '' : _h,
8733
- _j = _g.errorCode,
8734
- errorCode = _j === void 0 ? 0 : _j;
8735
-
8736
- rej({
8737
- errorType: errorType,
8738
- errorCode: errorCode
8739
- });
8740
- }
8741
- };
8738
+ res('Cool, connected to AWS AppSyncRealTime');
8739
+ return;
8740
+ }
8742
8741
 
8743
- var gqlInit = {
8744
- type: MESSAGE_TYPES.GQL_CONNECTION_INIT
8745
- };
8742
+ if (type === MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
8743
+ var _c = data.payload,
8744
+ _d = (_c === void 0 ? {} : _c).errors,
8745
+ _e = __read(_d === void 0 ? [] : _d, 1),
8746
+ _f = _e[0],
8747
+ _g = _f === void 0 ? {} : _f,
8748
+ _h = _g.errorType,
8749
+ errorType = _h === void 0 ? '' : _h,
8750
+ _j = _g.errorCode,
8751
+ errorCode = _j === void 0 ? 0 : _j;
8752
+
8753
+ rej({
8754
+ errorType: errorType,
8755
+ errorCode: errorCode
8756
+ });
8757
+ }
8758
+ };
8746
8759
 
8747
- _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
8760
+ var gqlInit = {
8761
+ type: MESSAGE_TYPES.GQL_CONNECTION_INIT
8762
+ };
8748
8763
 
8749
- function checkAckOk() {
8764
+ _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
8765
+
8766
+ setTimeout(checkAckOk.bind(_this, ackOk_1), CONNECTION_INIT_TIMEOUT);
8767
+ }
8768
+
8769
+ function checkAckOk(ackOk) {
8750
8770
  if (!ackOk) {
8751
8771
  rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + CONNECTION_INIT_TIMEOUT + " ms"));
8752
8772
  }
8753
8773
  }
8754
-
8755
- setTimeout(checkAckOk.bind(_this), CONNECTION_INIT_TIMEOUT);
8756
8774
  });
8757
8775
  }()];
8758
8776
 
@@ -8766,7 +8784,7 @@ function (_super) {
8766
8784
 
8767
8785
  case 4:
8768
8786
  err_4 = _b.sent();
8769
- errorType = err_4.errorType, errorCode = err_4.errorCode;
8787
+ _a = err_4, errorType = _a.errorType, errorCode = _a.errorCode;
8770
8788
 
8771
8789
  if (NON_RETRYABLE_CODES.includes(errorCode)) {
8772
8790
  throw new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["NonRetryableError"](errorType);
@@ -8809,16 +8827,17 @@ function (_super) {
8809
8827
  AMAZON_COGNITO_USER_POOLS: this._awsRealTimeCUPHeader.bind(this),
8810
8828
  AWS_LAMBDA: this._customAuthHeader
8811
8829
  };
8812
- handler = headerHandler[authenticationType];
8813
-
8814
- if (typeof handler !== 'function') {
8815
- logger.debug("Authentication type " + authenticationType + " not supported");
8816
- return [2
8817
- /*return*/
8818
- , ''];
8819
- }
8830
+ if (!(!authenticationType || !headerHandler[authenticationType])) return [3
8831
+ /*break*/
8832
+ , 1];
8833
+ logger.debug("Authentication type " + authenticationType + " not supported");
8834
+ return [2
8835
+ /*return*/
8836
+ , ''];
8820
8837
 
8821
- host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint).host;
8838
+ case 1:
8839
+ handler = headerHandler[authenticationType];
8840
+ host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
8822
8841
  return [4
8823
8842
  /*yield*/
8824
8843
  , handler({
@@ -8831,7 +8850,7 @@ function (_super) {
8831
8850
  additionalHeaders: additionalHeaders
8832
8851
  })];
8833
8852
 
8834
- case 1:
8853
+ case 2:
8835
8854
  result = _b.sent();
8836
8855
  return [2
8837
8856
  /*return*/
@@ -8963,10 +8982,14 @@ function (_super) {
8963
8982
  return [4
8964
8983
  /*yield*/
8965
8984
  , _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Credentials"].get().then(function (credentials) {
8985
+ var _a = credentials,
8986
+ secretAccessKey = _a.secretAccessKey,
8987
+ accessKeyId = _a.accessKeyId,
8988
+ sessionToken = _a.sessionToken;
8966
8989
  return {
8967
- secret_key: credentials.secretAccessKey,
8968
- access_key: credentials.accessKeyId,
8969
- session_token: credentials.sessionToken
8990
+ secret_key: secretAccessKey,
8991
+ access_key: accessKeyId,
8992
+ session_token: sessionToken
8970
8993
  };
8971
8994
  })];
8972
8995
 
@@ -8991,7 +9014,7 @@ function (_super) {
8991
9014
  var host = _a.host,
8992
9015
  additionalHeaders = _a.additionalHeaders;
8993
9016
 
8994
- if (!additionalHeaders.Authorization) {
9017
+ if (!additionalHeaders || !additionalHeaders['Authorization']) {
8995
9018
  throw new Error('No auth token specified');
8996
9019
  }
8997
9020
 
@@ -9228,8 +9251,12 @@ var AWSIoTProvider =
9228
9251
  function (_super) {
9229
9252
  __extends(AWSIoTProvider, _super);
9230
9253
 
9231
- function AWSIoTProvider() {
9232
- return _super !== null && _super.apply(this, arguments) || this;
9254
+ function AWSIoTProvider(options) {
9255
+ if (options === void 0) {
9256
+ options = {};
9257
+ }
9258
+
9259
+ return _super.call(this, options) || this;
9233
9260
  }
9234
9261
 
9235
9262
  Object.defineProperty(AWSIoTProvider.prototype, "region", {
@@ -9559,21 +9586,27 @@ function () {
9559
9586
 
9560
9587
  ClientsQueue.prototype.get = function (clientId, clientFactory) {
9561
9588
  return __awaiter(this, void 0, void 0, function () {
9562
- var promise;
9589
+ var cachedPromise, newPromise;
9563
9590
  return __generator(this, function (_a) {
9564
- promise = this.promises.get(clientId);
9591
+ cachedPromise = this.promises.get(clientId);
9565
9592
 
9566
- if (promise) {
9593
+ if (cachedPromise) {
9567
9594
  return [2
9568
9595
  /*return*/
9569
- , promise];
9596
+ , cachedPromise];
9597
+ }
9598
+
9599
+ if (clientFactory) {
9600
+ newPromise = clientFactory(clientId);
9601
+ this.promises.set(clientId, newPromise);
9602
+ return [2
9603
+ /*return*/
9604
+ , newPromise];
9570
9605
  }
9571
9606
 
9572
- promise = clientFactory(clientId);
9573
- this.promises.set(clientId, promise);
9574
9607
  return [2
9575
9608
  /*return*/
9576
- , promise];
9609
+ , undefined];
9577
9610
  });
9578
9611
  });
9579
9612
  };
@@ -9665,6 +9698,10 @@ function (_super) {
9665
9698
  }, args), null, 2));
9666
9699
  var topicsToDelete_1 = [];
9667
9700
 
9701
+ if (!clientId) {
9702
+ return;
9703
+ }
9704
+
9668
9705
  var clientIdObservers = this._clientIdObservers.get(clientId);
9669
9706
 
9670
9707
  if (!clientIdObservers) {
@@ -9783,9 +9820,7 @@ function (_super) {
9783
9820
  case 0:
9784
9821
  return [4
9785
9822
  /*yield*/
9786
- , this.clientsQueue.get(clientId, function () {
9787
- return null;
9788
- })];
9823
+ , this.clientsQueue.get(clientId)];
9789
9824
 
9790
9825
  case 1:
9791
9826
  client = _a.sent();
@@ -9964,13 +9999,14 @@ function (_super) {
9964
9999
  })();
9965
10000
 
9966
10001
  return function () {
10002
+ var _a, _b;
10003
+
9967
10004
  logger.debug('Unsubscribing from topic(s)', targetTopics.join(','));
9968
10005
 
9969
10006
  if (client) {
9970
- _this._clientIdObservers.get(clientId)["delete"](observer); // No more observers per client => client not needed anymore
9971
-
10007
+ (_a = _this._clientIdObservers.get(clientId)) === null || _a === void 0 ? void 0 : _a["delete"](observer); // No more observers per client => client not needed anymore
9972
10008
 
9973
- if (_this._clientIdObservers.get(clientId).size === 0) {
10009
+ if (((_b = _this._clientIdObservers.get(clientId)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
9974
10010
  _this.disconnect(clientId);
9975
10011
 
9976
10012
  _this._clientIdObservers["delete"](clientId);
@@ -10305,7 +10341,7 @@ function () {
10305
10341
  * @param {PubSubOptions} options - Configuration object for PubSub
10306
10342
  */
10307
10343
  function PubSubClass(options) {
10308
- this._options = options;
10344
+ this._options = options !== null && options !== void 0 ? options : {};
10309
10345
  logger.debug('PubSub Options', this._options);
10310
10346
  this._pluggables = [];
10311
10347
  this.subscribe = this.subscribe.bind(this);
@@ -10494,7 +10530,7 @@ function () {
10494
10530
  }();
10495
10531
 
10496
10532
 
10497
- var PubSub = new PubSubClass(null);
10533
+ var PubSub = new PubSubClass();
10498
10534
  _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Amplify"].register(PubSub);
10499
10535
 
10500
10536
  /***/ }),