aws-appsync-subscription-link 2.2.4 → 2.2.7

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,37 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ <a name="2.2.7"></a>
7
+ ## [2.2.7](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-subscription-link@2.2.5...aws-appsync-subscription-link@2.2.7) (2022-03-04)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * Port over Amplify fix for subscription race conditions for ApolloV2 ([#509](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/509)) ([#705](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/705)) ([f5022ba](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/f5022ba))
13
+ * **aws-appsync-subscription-link:** graphql header refactor to fix IAM-based auth for Apollo V2 packages ([#679](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/679)) ([09fc430](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/09fc430))
14
+
15
+
16
+
17
+
18
+ <a name="2.2.6"></a>
19
+ ## [2.2.6](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-subscription-link@2.2.5...aws-appsync-subscription-link@2.2.6) (2021-10-18)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * **aws-appsync-subscription-link:** graphql header refactor to fix IAM-based auth for Apollo V2 packages ([#679](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/679)) ([09fc430](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/09fc430))
25
+
26
+
27
+
28
+
29
+ <a name="2.2.5"></a>
30
+ ## [2.2.5](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-subscription-link@2.2.4...aws-appsync-subscription-link@2.2.5) (2021-09-24)
31
+
32
+
33
+
34
+
35
+ **Note:** Version bump only for package aws-appsync-subscription-link
36
+
6
37
  <a name="2.2.4"></a>
7
38
  ## [2.2.4](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-subscription-link@2.2.3...aws-appsync-subscription-link@2.2.4) (2021-09-24)
8
39
 
package/lib/index.js CHANGED
@@ -28,7 +28,7 @@ function createSubscriptionHandshakeLink(infoOrUrl, theResultsFetcherLink) {
28
28
  link: new apollo_link_1.ApolloLink(function (operation, _forward) {
29
29
  return new apollo_link_1.Observable(function (observer) {
30
30
  var _a;
31
- var _b = operation.variables, _c = subscription_handshake_link_1.CONTROL_EVENTS_KEY, controlEvents = _b[_c], variables = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
31
+ var _b = operation, _c = _b.variables, _d = subscription_handshake_link_1.CONTROL_EVENTS_KEY, controlEvents = _c[_d], variables = __rest(_c, [typeof _d === "symbol" ? _d : _d + ""]);
32
32
  if (typeof controlEvents !== "undefined") {
33
33
  operation.variables = variables;
34
34
  }
@@ -9,7 +9,5 @@ export declare class NonTerminatingLink extends ApolloLink {
9
9
  constructor(contextKey: string, { link }: {
10
10
  link: ApolloLink;
11
11
  });
12
- request(operation: any, forward?: NextLink): import("apollo-link").Observable<import("apollo-link").FetchResult<{
13
- [key: string]: any;
14
- }, Record<string, any>, Record<string, any>>>;
12
+ request(operation: any, forward?: NextLink): ReturnType<ApolloLink['request']>;
15
13
  }
@@ -2,7 +2,7 @@
2
2
  * Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { ApolloLink, Observable, Operation } from "apollo-link";
5
+ import { ApolloLink, Observable, Operation, FetchResult } from "apollo-link";
6
6
  import { UrlInfo } from "./types";
7
7
  export declare const CONTROL_EVENTS_KEY = "@@controlEvents";
8
8
  export declare class AppSyncRealTimeSubscriptionHandshakeLink extends ApolloLink {
@@ -16,11 +16,13 @@ export declare class AppSyncRealTimeSubscriptionHandshakeLink extends ApolloLink
16
16
  private subscriptionObserverMap;
17
17
  private promiseArray;
18
18
  constructor({ url: theUrl, region: theRegion, auth: theAuth }: UrlInfo);
19
- request(operation: Operation): Observable<any>;
19
+ request(operation: Operation): Observable<FetchResult<{
20
+ [key: string]: any;
21
+ }, Record<string, any>, Record<string, any>>>;
20
22
  private _verifySubscriptionAlreadyStarted;
21
23
  private _sendUnsubscriptionMessage;
22
24
  private _removeSubscriptionObserver;
23
- private _closeSocketWhenFlushed;
25
+ private _closeSocketIfRequired;
24
26
  private _startSubscriptionWithAWSAppSyncRealTime;
25
27
  private _initializeWebSocketConnection;
26
28
  private _awsRealTimeHeaderBasedAuth;
@@ -77,9 +77,9 @@ exports.CONTROL_EVENTS_KEY = "@@controlEvents";
77
77
  var NON_RETRYABLE_CODES = [400, 401, 403];
78
78
  var SERVICE = "appsync";
79
79
  var APPSYNC_REALTIME_HEADERS = {
80
- accept: 'application/json, text/javascript',
81
- 'content-encoding': 'amz-1.0',
82
- 'content-type': 'application/json; charset=UTF-8'
80
+ accept: "application/json, text/javascript",
81
+ "content-encoding": "amz-1.0",
82
+ "content-type": "application/json; charset=UTF-8",
83
83
  };
84
84
  /**
85
85
  * Time in milliseconds to wait for GQL_CONNECTION_INIT message
@@ -129,22 +129,23 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
129
129
  _this.auth.type === aws_appsync_auth_link_1.AUTH_TYPE.OPENID_CONNECT
130
130
  ? _this.auth.jwtToken
131
131
  : null;
132
- token = _this.auth.type === aws_appsync_auth_link_1.AUTH_TYPE.AWS_LAMBDA ? _this.auth.token : token;
132
+ token =
133
+ _this.auth.type === aws_appsync_auth_link_1.AUTH_TYPE.AWS_LAMBDA ? _this.auth.token : token;
133
134
  var options = {
134
135
  appSyncGraphqlEndpoint: _this.url,
135
136
  authenticationType: _this.auth.type,
136
137
  query: graphql_1.print(query),
137
138
  region: _this.region,
138
- graphql_headers: function () { return (headers); },
139
+ graphql_headers: function () { return headers; },
139
140
  variables: variables,
140
141
  apiKey: _this.auth.type === aws_appsync_auth_link_1.AUTH_TYPE.API_KEY ? _this.auth.apiKey : "",
141
142
  credentials: _this.auth.type === aws_appsync_auth_link_1.AUTH_TYPE.AWS_IAM ? _this.auth.credentials : null,
142
- token: token
143
+ token: token,
143
144
  };
144
145
  _this._startSubscriptionWithAWSAppSyncRealTime({
145
146
  options: options,
146
147
  observer: observer,
147
- subscriptionId: subscriptionId_1
148
+ subscriptionId: subscriptionId_1,
148
149
  });
149
150
  return function () { return __awaiter(_this, void 0, void 0, function () {
150
151
  var subscriptionState;
@@ -190,7 +191,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
190
191
  variables: variables,
191
192
  query: query,
192
193
  subscriptionReadyCallback: res,
193
- subscriptionFailedCallback: rej
194
+ subscriptionFailedCallback: rej,
194
195
  });
195
196
  })];
196
197
  }
@@ -206,7 +207,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
206
207
  // Preparing unsubscribe message to stop receiving messages for that subscription
207
208
  var unsubscribeMessage = {
208
209
  id: subscriptionId,
209
- type: types_1.MESSAGE_TYPES.GQL_STOP
210
+ type: types_1.MESSAGE_TYPES.GQL_STOP,
210
211
  };
211
212
  var stringToAWSRealTime = JSON.stringify(unsubscribeMessage);
212
213
  this.awsRealTimeSocket.send(stringToAWSRealTime);
@@ -220,22 +221,25 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
220
221
  };
221
222
  AppSyncRealTimeSubscriptionHandshakeLink.prototype._removeSubscriptionObserver = function (subscriptionId) {
222
223
  this.subscriptionObserverMap.delete(subscriptionId);
223
- if (this.subscriptionObserverMap.size === 0) {
224
- // Socket could be sending data to unsubscribe so is required to wait until is flushed
225
- this._closeSocketWhenFlushed();
226
- }
224
+ // Verifying for 1000ms after removing subscription in case there are new subscriptions on mount / unmount
225
+ setTimeout(this._closeSocketIfRequired.bind(this), 1000);
227
226
  };
228
- AppSyncRealTimeSubscriptionHandshakeLink.prototype._closeSocketWhenFlushed = function () {
229
- logger("closing WebSocket...");
230
- clearTimeout(this.keepAliveTimeoutId);
227
+ AppSyncRealTimeSubscriptionHandshakeLink.prototype._closeSocketIfRequired = function () {
228
+ if (this.subscriptionObserverMap.size > 0) {
229
+ // There are active subscriptions on the WebSocket
230
+ return;
231
+ }
231
232
  if (!this.awsRealTimeSocket) {
232
233
  this.socketStatus = types_1.SOCKET_STATUS.CLOSED;
233
234
  return;
234
235
  }
235
236
  if (this.awsRealTimeSocket.bufferedAmount > 0) {
236
- setTimeout(this._closeSocketWhenFlushed.bind(this), 1000);
237
+ // There is still data on the WebSocket
238
+ setTimeout(this._closeSocketIfRequired.bind(this), 1000);
237
239
  }
238
240
  else {
241
+ logger("closing WebSocket...");
242
+ clearTimeout(this.keepAliveTimeoutId);
239
243
  var tempSocket = this.awsRealTimeSocket;
240
244
  tempSocket.close(1000);
241
245
  this.awsRealTimeSocket = null;
@@ -245,17 +249,17 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
245
249
  AppSyncRealTimeSubscriptionHandshakeLink.prototype._startSubscriptionWithAWSAppSyncRealTime = function (_a) {
246
250
  var options = _a.options, observer = _a.observer, subscriptionId = _a.subscriptionId;
247
251
  return __awaiter(this, void 0, void 0, function () {
248
- var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, _b, graphql_headers, credentials, token, subscriptionState, data, dataString, headerObj, _c, _d, subscriptionMessage, stringToAWSRealTime, err_1, _e, message, subscriptionFailedCallback_1, _f, subscriptionFailedCallback, subscriptionReadyCallback;
249
- var _g;
252
+ var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, _b, graphql_headers, credentials, token, subscriptionState, data, dataString, headerObj, _c, subscriptionMessage, stringToAWSRealTime, err_1, _d, message, subscriptionFailedCallback_1, _e, subscriptionFailedCallback, subscriptionReadyCallback;
253
+ var _f;
250
254
  var _this = this;
251
- return __generator(this, function (_h) {
252
- switch (_h.label) {
255
+ return __generator(this, function (_g) {
256
+ switch (_g.label) {
253
257
  case 0:
254
258
  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 () { return ({}); } : _b, credentials = options.credentials, token = options.token;
255
259
  subscriptionState = types_1.SUBSCRIPTION_STATUS.PENDING;
256
260
  data = {
257
261
  query: query,
258
- variables: variables
262
+ variables: variables,
259
263
  };
260
264
  // Having a subscription id map will make it simple to forward messages received
261
265
  this.subscriptionObserverMap.set(subscriptionId, {
@@ -275,45 +279,43 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
275
279
  canonicalUri: "",
276
280
  region: region,
277
281
  credentials: credentials,
278
- token: token
282
+ token: token,
283
+ graphql_headers: graphql_headers,
279
284
  })];
280
285
  case 1:
281
- _d = [__assign.apply(void 0, _c.concat([(_h.sent())]))];
282
- return [4 /*yield*/, graphql_headers()];
283
- case 2:
284
- headerObj = __assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_h.sent())])), (_g = {}, _g[aws_appsync_auth_link_1.USER_AGENT_HEADER] = aws_appsync_auth_link_1.USER_AGENT, _g)]);
286
+ headerObj = __assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_g.sent())])), (_f = {}, _f[aws_appsync_auth_link_1.USER_AGENT_HEADER] = aws_appsync_auth_link_1.USER_AGENT, _f)]);
285
287
  subscriptionMessage = {
286
288
  id: subscriptionId,
287
289
  payload: {
288
290
  data: dataString,
289
291
  extensions: {
290
- authorization: __assign({}, headerObj)
291
- }
292
+ authorization: __assign({}, headerObj),
293
+ },
292
294
  },
293
- type: types_1.MESSAGE_TYPES.GQL_START
295
+ type: types_1.MESSAGE_TYPES.GQL_START,
294
296
  };
295
297
  stringToAWSRealTime = JSON.stringify(subscriptionMessage);
296
- _h.label = 3;
297
- case 3:
298
- _h.trys.push([3, 5, , 6]);
298
+ _g.label = 2;
299
+ case 2:
300
+ _g.trys.push([2, 4, , 5]);
299
301
  return [4 /*yield*/, this._initializeWebSocketConnection({
300
302
  apiKey: apiKey,
301
303
  appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
302
304
  authenticationType: authenticationType,
303
305
  region: region,
304
306
  credentials: credentials,
305
- token: token
307
+ token: token,
306
308
  })];
309
+ case 3:
310
+ _g.sent();
311
+ return [3 /*break*/, 5];
307
312
  case 4:
308
- _h.sent();
309
- return [3 /*break*/, 6];
310
- case 5:
311
- err_1 = _h.sent();
312
- _e = err_1.message, message = _e === void 0 ? "" : _e;
313
+ err_1 = _g.sent();
314
+ _d = err_1.message, message = _d === void 0 ? "" : _d;
313
315
  observer.error({
314
316
  errors: [
315
- __assign({}, new graphql_1.GraphQLError("Connection failed: " + message))
316
- ]
317
+ __assign({}, new graphql_1.GraphQLError("Connection failed: " + message)),
318
+ ],
317
319
  });
318
320
  observer.complete();
319
321
  subscriptionFailedCallback_1 = (this.subscriptionObserverMap.get(subscriptionId) || {}).subscriptionFailedCallback;
@@ -322,8 +324,8 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
322
324
  subscriptionFailedCallback_1();
323
325
  }
324
326
  return [2 /*return*/];
325
- case 6:
326
- _f = this.subscriptionObserverMap.get(subscriptionId), subscriptionFailedCallback = _f.subscriptionFailedCallback, subscriptionReadyCallback = _f.subscriptionReadyCallback;
327
+ case 5:
328
+ _e = this.subscriptionObserverMap.get(subscriptionId), subscriptionFailedCallback = _e.subscriptionFailedCallback, subscriptionReadyCallback = _e.subscriptionReadyCallback;
327
329
  // This must be done before sending the message in order to be listening immediately
328
330
  this.subscriptionObserverMap.set(subscriptionId, {
329
331
  observer: observer,
@@ -334,7 +336,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
334
336
  subscriptionFailedCallback: subscriptionFailedCallback,
335
337
  startAckTimeoutId: setTimeout(function () {
336
338
  _this._timeoutStartSubscriptionAck.call(_this, subscriptionId);
337
- }, START_ACK_TIMEOUT)
339
+ }, START_ACK_TIMEOUT),
338
340
  });
339
341
  if (this.awsRealTimeSocket) {
340
342
  this.awsRealTimeSocket.send(stringToAWSRealTime);
@@ -372,7 +374,8 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
372
374
  appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
373
375
  region: region,
374
376
  credentials: credentials,
375
- token: token
377
+ token: token,
378
+ graphql_headers: function () { },
376
379
  })];
377
380
  case 2:
378
381
  headerString = _b.apply(_a, [_c.sent()]);
@@ -410,7 +413,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
410
413
  }); });
411
414
  };
412
415
  AppSyncRealTimeSubscriptionHandshakeLink.prototype._awsRealTimeHeaderBasedAuth = function (_a) {
413
- var authenticationType = _a.authenticationType, payload = _a.payload, canonicalUri = _a.canonicalUri, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, apiKey = _a.apiKey, region = _a.region, credentials = _a.credentials, token = _a.token;
416
+ var authenticationType = _a.authenticationType, payload = _a.payload, canonicalUri = _a.canonicalUri, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, apiKey = _a.apiKey, region = _a.region, credentials = _a.credentials, token = _a.token, graphql_headers = _a.graphql_headers;
414
417
  return __awaiter(this, void 0, void 0, function () {
415
418
  var headerHandler, handler, host, result;
416
419
  return __generator(this, function (_b) {
@@ -421,7 +424,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
421
424
  AWS_IAM: this._awsRealTimeIAMHeader.bind(this),
422
425
  OPENID_CONNECT: this._awsRealTimeAuthorizationHeader.bind(this),
423
426
  AMAZON_COGNITO_USER_POOLS: this._awsRealTimeAuthorizationHeader.bind(this),
424
- AWS_LAMBDA: this._awsRealTimeAuthorizationHeader.bind(this)
427
+ AWS_LAMBDA: this._awsRealTimeAuthorizationHeader.bind(this),
425
428
  };
426
429
  handler = headerHandler[authenticationType];
427
430
  if (typeof handler !== "function") {
@@ -437,7 +440,8 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
437
440
  region: region,
438
441
  host: host,
439
442
  credentials: credentials,
440
- token: token
443
+ token: token,
444
+ graphql_headers: graphql_headers,
441
445
  })];
442
446
  case 1:
443
447
  result = _b.sent();
@@ -447,41 +451,43 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
447
451
  });
448
452
  };
449
453
  AppSyncRealTimeSubscriptionHandshakeLink.prototype._awsRealTimeAuthorizationHeader = function (_a) {
450
- var host = _a.host, token = _a.token;
454
+ var host = _a.host, token = _a.token, graphql_headers = _a.graphql_headers;
451
455
  return __awaiter(this, void 0, void 0, function () {
452
- var _b, _c;
453
- return __generator(this, function (_d) {
454
- switch (_d.label) {
456
+ var _b, _c, _d;
457
+ return __generator(this, function (_e) {
458
+ switch (_e.label) {
455
459
  case 0:
456
460
  _b = {};
457
461
  if (!(typeof token === "function")) return [3 /*break*/, 2];
458
462
  return [4 /*yield*/, token.call(undefined)];
459
463
  case 1:
460
- _c = _d.sent();
464
+ _c = _e.sent();
461
465
  return [3 /*break*/, 4];
462
466
  case 2: return [4 /*yield*/, token];
463
467
  case 3:
464
- _c = _d.sent();
465
- _d.label = 4;
466
- case 4: return [2 /*return*/, (_b.Authorization = _c,
467
- _b.host = host,
468
- _b)];
468
+ _c = _e.sent();
469
+ _e.label = 4;
470
+ case 4:
471
+ _d = [(_b.Authorization = _c, _b.host = host, _b)];
472
+ return [4 /*yield*/, graphql_headers()];
473
+ case 5: return [2 /*return*/, __assign.apply(void 0, _d.concat([(_e.sent())]))];
469
474
  }
470
475
  });
471
476
  });
472
477
  };
473
478
  AppSyncRealTimeSubscriptionHandshakeLink.prototype._awsRealTimeApiKeyHeader = function (_a) {
474
- var apiKey = _a.apiKey, host = _a.host;
479
+ var apiKey = _a.apiKey, host = _a.host, graphql_headers = _a.graphql_headers;
475
480
  return __awaiter(this, void 0, void 0, function () {
476
- var dt, dtStr;
477
- return __generator(this, function (_b) {
478
- dt = new Date();
479
- dtStr = dt.toISOString().replace(/[:\-]|\.\d{3}/g, "");
480
- return [2 /*return*/, {
481
- host: host,
482
- "x-amz-date": dtStr,
483
- "x-api-key": apiKey
484
- }];
481
+ var dt, dtStr, _b;
482
+ return __generator(this, function (_c) {
483
+ switch (_c.label) {
484
+ case 0:
485
+ dt = new Date();
486
+ dtStr = dt.toISOString().replace(/[:\-]|\.\d{3}/g, "");
487
+ _b = [{ host: host, "x-amz-date": dtStr, "x-api-key": apiKey }];
488
+ return [4 /*yield*/, graphql_headers()];
489
+ case 1: return [2 /*return*/, __assign.apply(void 0, _b.concat([(_c.sent())]))];
490
+ }
485
491
  });
486
492
  });
487
493
  };
@@ -494,7 +500,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
494
500
  case 0:
495
501
  endpointInfo = {
496
502
  region: region,
497
- service: SERVICE
503
+ service: SERVICE,
498
504
  };
499
505
  creds = typeof credentials === "function"
500
506
  ? credentials.call()
@@ -514,13 +520,13 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
514
520
  formattedCredentials = {
515
521
  access_key: accessKeyId,
516
522
  secret_key: secretAccessKey,
517
- session_token: sessionToken
523
+ session_token: sessionToken,
518
524
  };
519
525
  request = {
520
526
  url: "" + appSyncGraphqlEndpoint + canonicalUri,
521
527
  body: payload,
522
528
  method: "POST",
523
- headers: __assign({}, APPSYNC_REALTIME_HEADERS)
529
+ headers: __assign({}, APPSYNC_REALTIME_HEADERS),
524
530
  };
525
531
  signed_params = aws_appsync_auth_link_1.Signer.sign(request, formattedCredentials, endpointInfo);
526
532
  return [2 /*return*/, signed_params.headers];
@@ -536,7 +542,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
536
542
  case 0:
537
543
  logger("Initializaling retryable Handshake");
538
544
  return [4 /*yield*/, retry_1.jitteredExponentialRetry(this._initializeHandshake.bind(this), [
539
- { awsRealTimeUrl: awsRealTimeUrl }
545
+ { awsRealTimeUrl: awsRealTimeUrl },
540
546
  ])];
541
547
  case 1:
542
548
  _b.sent();
@@ -592,7 +598,8 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
592
598
  if (type === types_1.MESSAGE_TYPES.GQL_CONNECTION_ACK) {
593
599
  ackOk = true;
594
600
  _this.keepAliveTimeout = connectionTimeoutMs;
595
- _this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
601
+ _this.awsRealTimeSocket.onmessage =
602
+ _this._handleIncomingSubscriptionMessage.bind(_this);
596
603
  _this.awsRealTimeSocket.onerror = function (err) {
597
604
  logger(err);
598
605
  _this._errorDisconnect(types_1.CONTROL_MSG.CONNECTION_CLOSED);
@@ -610,7 +617,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
610
617
  }
611
618
  };
612
619
  var gqlInit = {
613
- type: types_1.MESSAGE_TYPES.GQL_CONNECTION_INIT
620
+ type: types_1.MESSAGE_TYPES.GQL_CONNECTION_INIT,
614
621
  };
615
622
  _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
616
623
  function checkAckOk() {
@@ -667,8 +674,8 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
667
674
  observer.next({
668
675
  data: payload,
669
676
  extensions: {
670
- controlMsgType: "CONNECTED"
671
- }
677
+ controlMsgType: "CONNECTED",
678
+ },
672
679
  });
673
680
  }
674
681
  else {
@@ -682,7 +689,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
682
689
  startAckTimeoutId: null,
683
690
  subscriptionState: subscriptionState,
684
691
  subscriptionReadyCallback: subscriptionReadyCallback,
685
- subscriptionFailedCallback: subscriptionFailedCallback
692
+ subscriptionFailedCallback: subscriptionFailedCallback,
686
693
  });
687
694
  return;
688
695
  }
@@ -700,12 +707,12 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
700
707
  startAckTimeoutId: startAckTimeoutId,
701
708
  subscriptionReadyCallback: subscriptionReadyCallback,
702
709
  subscriptionFailedCallback: subscriptionFailedCallback,
703
- subscriptionState: subscriptionState
710
+ subscriptionState: subscriptionState,
704
711
  });
705
712
  observer.error({
706
713
  errors: [
707
- __assign({}, new graphql_1.GraphQLError("Connection failed: " + JSON.stringify(payload)))
708
- ]
714
+ __assign({}, new graphql_1.GraphQLError("Connection failed: " + JSON.stringify(payload))),
715
+ ],
709
716
  });
710
717
  clearTimeout(startAckTimeoutId);
711
718
  observer.complete();
@@ -739,13 +746,13 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
739
746
  observer: observer,
740
747
  query: query,
741
748
  variables: variables,
742
- subscriptionState: types_1.SUBSCRIPTION_STATUS.FAILED
749
+ subscriptionState: types_1.SUBSCRIPTION_STATUS.FAILED,
743
750
  });
744
751
  if (observer && !observer.closed) {
745
752
  observer.error({
746
753
  errors: [
747
- __assign({}, new graphql_1.GraphQLError("Subscription timeout " + JSON.stringify({ query: query, variables: variables })))
748
- ]
754
+ __assign({}, new graphql_1.GraphQLError("Subscription timeout " + JSON.stringify({ query: query, variables: variables }))),
755
+ ],
749
756
  });
750
757
  // Cleanup will be automatically executed
751
758
  observer.complete();
@@ -758,7 +765,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
758
765
  AppSyncRealTimeSubscriptionHandshakeLink._discoverAppSyncRealTimeEndpoint = function (url) {
759
766
  return url
760
767
  .replace("https://", "wss://")
761
- .replace('http://', 'ws://')
768
+ .replace("http://", "ws://")
762
769
  .replace("appsync-api", "appsync-realtime-api")
763
770
  .replace("gogi-beta", "grt-beta");
764
771
  };
@@ -15,7 +15,7 @@ export declare class SubscriptionHandshakeLink extends ApolloLink {
15
15
  private topicObservers;
16
16
  private clientObservers;
17
17
  constructor(subsInfoContextKey: any);
18
- request(operation: Operation): Observable<any>;
18
+ request(operation: Operation): Observable<unknown>;
19
19
  connectNewClients(connectionInfo: MqttConnectionInfo[], observer: ZenObservable.Observer<FetchResult>, operation: Operation): Promise<any[]>;
20
20
  connectNewClient(connectionInfo: MqttConnectionInfo, observer: ZenObservable.Observer<FetchResult>, selectionNames: string[]): Promise<any>;
21
21
  subscribeToTopics<T>(client: any, topics: string[], observer: ZenObservable.Observer<T>): Promise<unknown[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-appsync-subscription-link",
3
- "version": "2.2.4",
3
+ "version": "2.2.7",
4
4
  "main": "lib/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "description": "AWS Mobile AppSync SDK for JavaScript",
@@ -23,12 +23,13 @@
23
23
  "apollo-link-context": "1.0.11",
24
24
  "apollo-link-http": "1.5.8",
25
25
  "apollo-link-retry": "2.2.7",
26
- "aws-appsync-auth-link": "^2.0.5",
26
+ "aws-appsync-auth-link": "^2.0.8",
27
27
  "debug": "2.6.9",
28
28
  "url": "^0.11.0"
29
29
  },
30
30
  "devDependencies": {
31
- "@redux-offline/redux-offline": "2.5.2-native.0"
31
+ "@redux-offline/redux-offline": "2.5.2-native.0",
32
+ "apollo-client": "2.x"
32
33
  },
33
34
  "peerDependencies": {
34
35
  "apollo-client": "2.x"