aws-appsync-subscription-link 3.1.2 → 3.2.0-alpha.da776601

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/jest.config.js CHANGED
@@ -1,6 +1,10 @@
1
1
  module.exports = {
2
2
  transform: {
3
- "^.+\\.tsx?$": "ts-jest"
3
+ "^.+\\.tsx?$": ["ts-jest", {
4
+ tsconfig: {
5
+ target: "es2017"
6
+ }
7
+ }]
4
8
  },
5
9
  testRegex: "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
6
10
  collectCoverageFrom: [
package/lib/index.js CHANGED
@@ -11,8 +11,9 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  return t;
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.createSubscriptionHandshakeLink = exports.CONTROL_EVENTS_KEY = void 0;
14
15
  var subscription_handshake_link_1 = require("./subscription-handshake-link");
15
- exports.CONTROL_EVENTS_KEY = subscription_handshake_link_1.CONTROL_EVENTS_KEY;
16
+ Object.defineProperty(exports, "CONTROL_EVENTS_KEY", { enumerable: true, get: function () { return subscription_handshake_link_1.CONTROL_EVENTS_KEY; } });
16
17
  var core_1 = require("@apollo/client/core");
17
18
  var http_1 = require("@apollo/client/link/http");
18
19
  var utilities_1 = require("@apollo/client/utilities");
@@ -22,7 +23,7 @@ function createSubscriptionHandshakeLink(infoOrUrl, theResultsFetcherLink) {
22
23
  var resultsFetcherLink, subscriptionLinks;
23
24
  if (typeof infoOrUrl === "string") {
24
25
  resultsFetcherLink =
25
- theResultsFetcherLink || http_1.createHttpLink({ uri: infoOrUrl });
26
+ theResultsFetcherLink || (0, http_1.createHttpLink)({ uri: infoOrUrl });
26
27
  subscriptionLinks = core_1.ApolloLink.from([
27
28
  new non_terminating_link_1.NonTerminatingLink("controlMessages", {
28
29
  link: new core_1.ApolloLink(function (operation, _forward) {
@@ -43,12 +44,12 @@ function createSubscriptionHandshakeLink(infoOrUrl, theResultsFetcherLink) {
43
44
  }
44
45
  else {
45
46
  var url = infoOrUrl.url;
46
- resultsFetcherLink = theResultsFetcherLink || http_1.createHttpLink({ uri: url });
47
+ resultsFetcherLink = theResultsFetcherLink || (0, http_1.createHttpLink)({ uri: url });
47
48
  subscriptionLinks = new realtime_subscription_handshake_link_1.AppSyncRealTimeSubscriptionHandshakeLink(infoOrUrl);
48
49
  }
49
50
  return core_1.ApolloLink.split(function (operation) {
50
51
  var query = operation.query;
51
- var _a = utilities_1.getMainDefinition(query), kind = _a.kind, graphqlOperation = _a.operation;
52
+ var _a = (0, utilities_1.getMainDefinition)(query), kind = _a.kind, graphqlOperation = _a.operation;
52
53
  var isSubscription = kind === "OperationDefinition" && graphqlOperation === "subscription";
53
54
  return isSubscription;
54
55
  }, subscriptionLinks, resultsFetcherLink);
@@ -2,8 +2,8 @@
2
2
  * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { HttpOptions } from '@apollo/client/link/http';
5
+ import { HttpLink } from '@apollo/client/link/http';
6
6
  import { NonTerminatingLink } from './non-terminating-link';
7
7
  export declare class NonTerminatingHttpLink extends NonTerminatingLink {
8
- constructor(contextKey: string, options: HttpOptions);
8
+ constructor(contextKey: string, options: HttpLink.Options);
9
9
  }
@@ -3,16 +3,19 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
15
  };
14
16
  })();
15
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.NonTerminatingHttpLink = void 0;
16
19
  /*!
17
20
  * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
18
21
  * SPDX-License-Identifier: Apache-2.0
@@ -22,10 +25,8 @@ var non_terminating_link_1 = require("./non-terminating-link");
22
25
  var NonTerminatingHttpLink = /** @class */ (function (_super) {
23
26
  __extends(NonTerminatingHttpLink, _super);
24
27
  function NonTerminatingHttpLink(contextKey, options) {
25
- var _this = this;
26
- var link = http_1.createHttpLink(options);
27
- _this = _super.call(this, contextKey, { link: link }) || this;
28
- return _this;
28
+ var link = (0, http_1.createHttpLink)(options);
29
+ return _super.call(this, contextKey, { link: link }) || this;
29
30
  }
30
31
  return NonTerminatingHttpLink;
31
32
  }(non_terminating_link_1.NonTerminatingLink));
@@ -3,13 +3,13 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { ApolloLink } from '@apollo/client/core';
6
- import type { NextLink, FetchResult } from '@apollo/client/core';
7
- import type { Observable } from 'zen-observable-ts';
6
+ import type { FetchResult } from '@apollo/client/core';
7
+ import type { Observable } from 'rxjs';
8
8
  export declare class NonTerminatingLink extends ApolloLink {
9
9
  private contextKey;
10
10
  private link;
11
11
  constructor(contextKey: string, { link }: {
12
12
  link: ApolloLink;
13
13
  });
14
- request(operation: any, forward?: NextLink): Observable<FetchResult>;
14
+ request(operation: any, forward?: ApolloLink.ForwardFunction): Observable<FetchResult>;
15
15
  }
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -38,7 +40,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
40
  function verb(n) { return function (v) { return step([n, v]); }; }
39
41
  function step(op) {
40
42
  if (f) throw new TypeError("Generator is already executing.");
41
- while (_) try {
43
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
42
44
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
43
45
  if (y = 0, t) op = [op[0] & 2, t.value];
44
46
  switch (op[0]) {
@@ -60,6 +62,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
60
62
  }
61
63
  };
62
64
  Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.NonTerminatingLink = void 0;
63
66
  /*!
64
67
  * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
65
68
  * SPDX-License-Identifier: Apache-2.0
@@ -77,14 +80,14 @@ var NonTerminatingLink = /** @class */ (function (_super) {
77
80
  }
78
81
  NonTerminatingLink.prototype.request = function (operation, forward) {
79
82
  var _this = this;
80
- return (context_1.setContext(function (_request, prevContext) { return __awaiter(_this, void 0, void 0, function () {
83
+ return ((0, context_1.setContext)(function (_request, prevContext) { return __awaiter(_this, void 0, void 0, function () {
81
84
  var result;
82
85
  var _a;
83
86
  var _this = this;
84
87
  return __generator(this, function (_b) {
85
88
  switch (_b.label) {
86
89
  case 0: return [4 /*yield*/, new Promise(function (resolve, reject) {
87
- _this.link.request(operation).subscribe({
90
+ _this.link.request(operation, forward).subscribe({
88
91
  next: resolve,
89
92
  error: reject,
90
93
  });
@@ -0,0 +1 @@
1
+ export declare let Observable: any;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ try {
4
+ // Try Apollo Client's Observable first (v3)
5
+ var apolloClient = require("@apollo/client/core");
6
+ exports.Observable = apolloClient.Observable;
7
+ }
8
+ catch (e) {
9
+ try {
10
+ // Fallback to rxjs (v4)
11
+ var rxjs = require("rxjs");
12
+ exports.Observable = rxjs.Observable;
13
+ }
14
+ catch (e2) {
15
+ // Final fallback to zen-observable
16
+ var zenObservable = require("zen-observable-ts");
17
+ exports.Observable = zenObservable.default || zenObservable;
18
+ }
19
+ }
@@ -2,7 +2,7 @@
2
2
  * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { ApolloLink, Observable, Operation, FetchResult } from "@apollo/client/core";
5
+ import { ApolloLink, Observable, Operation } from "@apollo/client/core";
6
6
  import { AppSyncRealTimeSubscriptionConfig } from "./types";
7
7
  export declare const CONTROL_EVENTS_KEY = "@@controlEvents";
8
8
  export declare class AppSyncRealTimeSubscriptionHandshakeLink extends ApolloLink {
@@ -17,7 +17,7 @@ export declare class AppSyncRealTimeSubscriptionHandshakeLink extends ApolloLink
17
17
  private promiseArray;
18
18
  constructor({ url: theUrl, region: theRegion, auth: theAuth, keepAliveTimeoutMs }: AppSyncRealTimeSubscriptionConfig);
19
19
  private isCustomDomain;
20
- request(operation: Operation): Observable<FetchResult<Record<string, any>, Record<string, any>, Record<string, any>>>;
20
+ request(operation: Operation): Observable<import("graphql").FormattedExecutionResult<Record<string, any>, Record<string, any>>>;
21
21
  private _verifySubscriptionAlreadyStarted;
22
22
  private _sendUnsubscriptionMessage;
23
23
  private _removeSubscriptionObserver;
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -38,7 +40,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
40
  function verb(n) { return function (v) { return step([n, v]); }; }
39
41
  function step(op) {
40
42
  if (f) throw new TypeError("Generator is already executing.");
41
- while (_) try {
43
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
42
44
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
43
45
  if (y = 0, t) op = [op[0] & 2, t.value];
44
46
  switch (op[0]) {
@@ -60,11 +62,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
60
62
  }
61
63
  };
62
64
  Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.AppSyncRealTimeSubscriptionHandshakeLink = exports.CONTROL_EVENTS_KEY = void 0;
63
66
  /*!
64
67
  * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
65
68
  * SPDX-License-Identifier: Apache-2.0
66
69
  */
67
70
  var core_1 = require("@apollo/client/core");
71
+ var operators_1 = require("rxjs/operators");
68
72
  var utils_1 = require("./utils");
69
73
  var aws_appsync_auth_link_1 = require("aws-appsync-auth-link");
70
74
  var graphql_1 = require("graphql");
@@ -114,7 +118,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
114
118
  _this.keepAliveTimeout = keepAliveTimeoutMs;
115
119
  if (_this.keepAliveTimeout < SERVER_KEEP_ALIVE_TIMEOUT) {
116
120
  var configName = 'keepAliveTimeoutMs';
117
- throw new Error(configName + " must be greater than or equal to " + SERVER_KEEP_ALIVE_TIMEOUT + " (" + _this.keepAliveTimeout + " used).");
121
+ throw new Error("".concat(configName, " must be greater than or equal to ").concat(SERVER_KEEP_ALIVE_TIMEOUT, " (").concat(_this.keepAliveTimeout, " used)."));
118
122
  }
119
123
  return _this;
120
124
  }
@@ -126,9 +130,9 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
126
130
  var _a;
127
131
  var _this = this;
128
132
  var query = operation.query, variables = operation.variables;
129
- var _b = operation.getContext(), _c = _b.controlMessages, _d = exports.CONTROL_EVENTS_KEY, controlEvents = (_c === void 0 ? (_a = {},
133
+ var _b = operation.getContext(), _c = _b.controlMessages, _d = _c === void 0 ? (_a = {},
130
134
  _a[exports.CONTROL_EVENTS_KEY] = undefined,
131
- _a) : _c)[_d], headers = _b.headers;
135
+ _a) : _c, _e = exports.CONTROL_EVENTS_KEY, controlEvents = _d[_e], headers = _b.headers;
132
136
  return new core_1.Observable(function (observer) {
133
137
  if (!_this.url) {
134
138
  observer.error({
@@ -139,7 +143,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
139
143
  observer.complete();
140
144
  }
141
145
  else {
142
- var subscriptionId_1 = uuid_1.v4();
146
+ var subscriptionId_1 = (0, uuid_1.v4)();
143
147
  var token = _this.auth.type === aws_appsync_auth_link_1.AUTH_TYPE.AMAZON_COGNITO_USER_POOLS ||
144
148
  _this.auth.type === aws_appsync_auth_link_1.AUTH_TYPE.OPENID_CONNECT
145
149
  ? _this.auth.jwtToken
@@ -148,7 +152,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
148
152
  var options = {
149
153
  appSyncGraphqlEndpoint: _this.url,
150
154
  authenticationType: _this.auth.type,
151
- query: graphql_1.print(query),
155
+ query: (0, graphql_1.print)(query),
152
156
  region: _this.region,
153
157
  graphql_headers: function () { return (headers); },
154
158
  variables: variables,
@@ -183,11 +187,11 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
183
187
  });
184
188
  }); };
185
189
  }
186
- }).filter(function (data) {
187
- var _a = data.extensions, _b = (_a === void 0 ? {} : _a).controlMsgType, controlMsgType = _b === void 0 ? undefined : _b;
190
+ }).pipe((0, operators_1.filter)(function (data) {
191
+ var _a = data.extensions, _b = _a === void 0 ? {} : _a, _c = _b.controlMsgType, controlMsgType = _c === void 0 ? undefined : _c;
188
192
  var isControlMsg = typeof controlMsgType !== "undefined";
189
193
  return controlEvents === true || !isControlMsg;
190
- });
194
+ }));
191
195
  };
192
196
  AppSyncRealTimeSubscriptionHandshakeLink.prototype._verifySubscriptionAlreadyStarted = function (subscriptionId) {
193
197
  return __awaiter(this, void 0, void 0, function () {
@@ -328,7 +332,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
328
332
  _d = err_1.message, message = _d === void 0 ? "" : _d;
329
333
  observer.error({
330
334
  errors: [
331
- __assign({}, new graphql_1.GraphQLError("Connection failed: " + message))
335
+ __assign({}, new graphql_1.GraphQLError("Connection failed: ".concat(message)))
332
336
  ]
333
337
  });
334
338
  observer.complete();
@@ -339,7 +343,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
339
343
  }
340
344
  return [2 /*return*/];
341
345
  case 5:
342
- _e = this.subscriptionObserverMap.get(subscriptionId), subscriptionFailedCallback = _e.subscriptionFailedCallback, subscriptionReadyCallback = _e.subscriptionReadyCallback;
346
+ _e = this.subscriptionObserverMap.get(subscriptionId) || {}, subscriptionFailedCallback = _e.subscriptionFailedCallback, subscriptionReadyCallback = _e.subscriptionReadyCallback;
343
347
  // This must be done before sending the message in order to be listening immediately
344
348
  this.subscriptionObserverMap.set(subscriptionId, {
345
349
  observer: observer,
@@ -404,7 +408,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
404
408
  discoverableEndpoint = discoverableEndpoint
405
409
  .replace("https://", "wss://")
406
410
  .replace('http://', 'ws://');
407
- awsRealTimeUrl = discoverableEndpoint + "?header=" + headerQs + "&payload=" + payloadQs;
411
+ awsRealTimeUrl = "".concat(discoverableEndpoint, "?header=").concat(headerQs, "&payload=").concat(payloadQs);
408
412
  return [4 /*yield*/, this._initializeRetryableHandshake({ awsRealTimeUrl: awsRealTimeUrl })];
409
413
  case 3:
410
414
  _c.sent();
@@ -451,7 +455,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
451
455
  };
452
456
  handler = headerHandler[authenticationType];
453
457
  if (typeof handler !== "function") {
454
- logger("Authentication type " + authenticationType + " not supported");
458
+ logger("Authentication type ".concat(authenticationType, " not supported"));
455
459
  return [2 /*return*/, {}];
456
460
  }
457
461
  host = url.parse(appSyncGraphqlEndpoint).host;
@@ -476,24 +480,25 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
476
480
  AppSyncRealTimeSubscriptionHandshakeLink.prototype._awsRealTimeAuthorizationHeader = function (_a) {
477
481
  var host = _a.host, token = _a.token, graphql_headers = _a.graphql_headers;
478
482
  return __awaiter(this, void 0, void 0, function () {
479
- var _b, _c, _d;
483
+ var _b, _c;
484
+ var _d;
480
485
  return __generator(this, function (_e) {
481
486
  switch (_e.label) {
482
487
  case 0:
483
- _b = {};
488
+ _d = {};
484
489
  if (!(typeof token === "function")) return [3 /*break*/, 2];
485
490
  return [4 /*yield*/, token.call(undefined)];
486
491
  case 1:
487
- _c = _e.sent();
492
+ _b = _e.sent();
488
493
  return [3 /*break*/, 4];
489
494
  case 2: return [4 /*yield*/, token];
490
495
  case 3:
491
- _c = _e.sent();
496
+ _b = _e.sent();
492
497
  _e.label = 4;
493
498
  case 4:
494
- _d = [(_b.Authorization = _c, _b.host = host, _b)];
499
+ _c = [(_d.Authorization = _b, _d.host = host, _d)];
495
500
  return [4 /*yield*/, graphql_headers()];
496
- case 5: return [2 /*return*/, __assign.apply(void 0, _d.concat([(_e.sent())]))];
501
+ case 5: return [2 /*return*/, __assign.apply(void 0, _c.concat([(_e.sent())]))];
497
502
  }
498
503
  });
499
504
  });
@@ -546,7 +551,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
546
551
  session_token: sessionToken
547
552
  };
548
553
  request = {
549
- url: "" + appSyncGraphqlEndpoint + canonicalUri,
554
+ url: "".concat(appSyncGraphqlEndpoint).concat(canonicalUri),
550
555
  body: payload,
551
556
  method: "POST",
552
557
  headers: __assign({}, APPSYNC_REALTIME_HEADERS)
@@ -564,7 +569,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
564
569
  switch (_b.label) {
565
570
  case 0:
566
571
  logger("Initializaling retryable Handshake");
567
- return [4 /*yield*/, retry_1.jitteredExponentialRetry(this._initializeHandshake.bind(this), [
572
+ return [4 /*yield*/, (0, retry_1.jitteredExponentialRetry)(this._initializeHandshake.bind(this), [
568
573
  { awsRealTimeUrl: awsRealTimeUrl }
569
574
  ])];
570
575
  case 1:
@@ -582,7 +587,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
582
587
  return __generator(this, function (_b) {
583
588
  switch (_b.label) {
584
589
  case 0:
585
- logger("Initializing handshake " + awsRealTimeUrl);
590
+ logger("Initializing handshake ".concat(awsRealTimeUrl));
586
591
  _b.label = 1;
587
592
  case 1:
588
593
  _b.trys.push([1, 4, , 5]);
@@ -608,17 +613,17 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
608
613
  return new Promise(function (res, rej) {
609
614
  var ackOk = false;
610
615
  _this.awsRealTimeSocket.onerror = function (error) {
611
- logger("WebSocket closed " + JSON.stringify(error));
616
+ logger("WebSocket closed ".concat(JSON.stringify(error)));
612
617
  };
613
618
  _this.awsRealTimeSocket.onclose = function (event) {
614
- logger("WebSocket closed " + event.reason);
619
+ logger("WebSocket closed ".concat(event.reason));
615
620
  rej(new Error(JSON.stringify(event)));
616
621
  };
617
622
  _this.awsRealTimeSocket.onmessage = function (message) {
618
623
  var _a;
619
- logger("subscription message from AWS AppSyncRealTime: " + message.data + " ");
624
+ logger("subscription message from AWS AppSyncRealTime: ".concat(message.data, " "));
620
625
  var data = JSON.parse(message.data);
621
- var type = data.type, _b = data.payload, _c = (_b === void 0 ? {} : _b).connectionTimeoutMs, connectionTimeoutMs = _c === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _c;
626
+ var type = data.type, _b = data.payload, _c = _b === void 0 ? {} : _b, _d = _c.connectionTimeoutMs, connectionTimeoutMs = _d === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _d;
622
627
  if (type === types_1.MESSAGE_TYPES.GQL_CONNECTION_ACK) {
623
628
  ackOk = true;
624
629
  _this.keepAliveTimeout = (_a = _this.keepAliveTimeout) !== null && _a !== void 0 ? _a : connectionTimeoutMs;
@@ -628,14 +633,14 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
628
633
  _this._errorDisconnect(types_1.CONTROL_MSG.CONNECTION_CLOSED);
629
634
  };
630
635
  _this.awsRealTimeSocket.onclose = function (event) {
631
- logger("WebSocket closed " + event.reason);
636
+ logger("WebSocket closed ".concat(event.reason));
632
637
  _this._errorDisconnect(types_1.CONTROL_MSG.CONNECTION_CLOSED);
633
638
  };
634
639
  res("Cool, connected to AWS AppSyncRealTime");
635
640
  return;
636
641
  }
637
642
  if (type === types_1.MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
638
- var _d = data.payload, _e = (_d === void 0 ? {} : _d).errors, _f = (_e === void 0 ? [] : _e)[0], _g = _f === void 0 ? {} : _f, _h = _g.errorType, errorType = _h === void 0 ? "" : _h, _j = _g.errorCode, errorCode = _j === void 0 ? 0 : _j;
643
+ var _e = data.payload, _f = _e === void 0 ? {} : _e, _g = _f.errors, _h = _g === void 0 ? [] : _g, _j = _h[0], _k = _j === void 0 ? {} : _j, _l = _k.errorType, errorType = _l === void 0 ? "" : _l, _m = _k.errorCode, errorCode = _m === void 0 ? 0 : _m;
639
644
  rej({ errorType: errorType, errorCode: errorCode });
640
645
  }
641
646
  };
@@ -645,7 +650,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
645
650
  _this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
646
651
  function checkAckOk() {
647
652
  if (!ackOk) {
648
- rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + CONNECTION_INIT_TIMEOUT + " ms"));
653
+ rej(new Error("Connection timeout: ack from AWSRealTime was not received on ".concat(CONNECTION_INIT_TIMEOUT, " ms")));
649
654
  }
650
655
  }
651
656
  setTimeout(checkAckOk.bind(_this), CONNECTION_INIT_TIMEOUT);
@@ -674,7 +679,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
674
679
  });
675
680
  };
676
681
  AppSyncRealTimeSubscriptionHandshakeLink.prototype._handleIncomingSubscriptionMessage = function (message) {
677
- logger("subscription message from AWS AppSync RealTime: " + message.data);
682
+ logger("subscription message from AWS AppSync RealTime: ".concat(message.data));
678
683
  var _a = JSON.parse(message.data), _b = _a.id, id = _b === void 0 ? "" : _b, payload = _a.payload, type = _a.type;
679
684
  var _c = this.subscriptionObserverMap.get(id) || {}, _d = _c.observer, observer = _d === void 0 ? null : _d, _e = _c.query, query = _e === void 0 ? "" : _e, _f = _c.variables, variables = _f === void 0 ? {} : _f, _g = _c.startAckTimeoutId, startAckTimeoutId = _g === void 0 ? 0 : _g, _h = _c.subscriptionReadyCallback, subscriptionReadyCallback = _h === void 0 ? null : _h, _j = _c.subscriptionFailedCallback, subscriptionFailedCallback = _j === void 0 ? null : _j;
680
685
  logger({ id: id, observer: observer, query: query, variables: variables });
@@ -683,12 +688,12 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
683
688
  observer.next(payload);
684
689
  }
685
690
  else {
686
- logger("observer not found for id: " + id);
691
+ logger("observer not found for id: ".concat(id));
687
692
  }
688
693
  return;
689
694
  }
690
695
  if (type === types_1.MESSAGE_TYPES.GQL_START_ACK) {
691
- logger("subscription ready for " + JSON.stringify({ query: query, variables: variables }));
696
+ logger("subscription ready for ".concat(JSON.stringify({ query: query, variables: variables })));
692
697
  if (typeof subscriptionReadyCallback === "function") {
693
698
  subscriptionReadyCallback();
694
699
  }
@@ -702,7 +707,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
702
707
  });
703
708
  }
704
709
  else {
705
- logger("observer not found for id: " + id);
710
+ logger("observer not found for id: ".concat(id));
706
711
  }
707
712
  var subscriptionState = types_1.SUBSCRIPTION_STATUS.CONNECTED;
708
713
  this.subscriptionObserverMap.set(id, {
@@ -736,13 +741,13 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
736
741
  if (observer) {
737
742
  observer.error({
738
743
  errors: [
739
- __assign({}, new graphql_1.GraphQLError("Connection failed: " + JSON.stringify(payload)))
744
+ __assign({}, new graphql_1.GraphQLError("Connection failed: ".concat(JSON.stringify(payload))))
740
745
  ]
741
746
  });
742
747
  observer.complete();
743
748
  }
744
749
  else {
745
- logger("observer not found for id: " + id);
750
+ logger("observer not found for id: ".concat(id));
746
751
  }
747
752
  if (typeof subscriptionFailedCallback === "function") {
748
753
  subscriptionFailedCallback();
@@ -750,7 +755,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
750
755
  }
751
756
  };
752
757
  AppSyncRealTimeSubscriptionHandshakeLink.prototype._errorDisconnect = function (msg) {
753
- logger("Disconnect error: " + msg);
758
+ logger("Disconnect error: ".concat(msg));
754
759
  this.subscriptionObserverMap.forEach(function (_a) {
755
760
  var observer = _a.observer;
756
761
  if (observer && !observer.closed) {
@@ -779,7 +784,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
779
784
  if (observer && !observer.closed) {
780
785
  observer.error({
781
786
  errors: [
782
- __assign({}, new graphql_1.GraphQLError("Subscription timeout " + JSON.stringify({ query: query, variables: variables })))
787
+ __assign({}, new graphql_1.GraphQLError("Subscription timeout ".concat(JSON.stringify({ query: query, variables: variables }))))
783
788
  ]
784
789
  });
785
790
  // Cleanup will be automatically executed
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { ApolloLink, Observable, Operation, FetchResult } from "@apollo/client/core";
6
6
  import * as ZenObservable from 'zen-observable-ts';
7
- declare type MqttConnectionInfo = {
7
+ type MqttConnectionInfo = {
8
8
  client: string;
9
9
  url: string;
10
10
  topics: string[];
@@ -3,10 +3,12 @@ var __extends = (this && this.__extends) || (function () {
3
3
  var extendStatics = function (d, b) {
4
4
  extendStatics = Object.setPrototypeOf ||
5
5
  ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
7
  return extendStatics(d, b);
8
8
  };
9
9
  return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
10
12
  extendStatics(d, b);
11
13
  function __() { this.constructor = d; }
12
14
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -38,7 +40,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
40
  function verb(n) { return function (v) { return step([n, v]); }; }
39
41
  function step(op) {
40
42
  if (f) throw new TypeError("Generator is already executing.");
41
- while (_) try {
43
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
42
44
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
43
45
  if (y = 0, t) op = [op[0] & 2, t.value];
44
46
  switch (op[0]) {
@@ -71,11 +73,14 @@ var __rest = (this && this.__rest) || function (s, e) {
71
73
  return t;
72
74
  };
73
75
  Object.defineProperty(exports, "__esModule", { value: true });
76
+ exports.SubscriptionHandshakeLink = exports.CONTROL_EVENTS_KEY = void 0;
74
77
  /*!
75
78
  * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
76
79
  * SPDX-License-Identifier: Apache-2.0
77
80
  */
78
81
  var core_1 = require("@apollo/client/core");
82
+ var errors_1 = require("@apollo/client/errors");
83
+ var operators_1 = require("rxjs/operators");
79
84
  var utils_1 = require("./utils");
80
85
  var Paho = require("./vendor/paho-mqtt");
81
86
  var utilities_1 = require("@apollo/client/utilities");
@@ -108,15 +113,11 @@ var SubscriptionHandshakeLink = /** @class */ (function (_super) {
108
113
  SubscriptionHandshakeLink.prototype.request = function (operation) {
109
114
  var _a;
110
115
  var _this = this;
111
- var _b = operation.getContext(), _c = this.subsInfoContextKey, subsInfo = _b[_c], _d = _b.controlMessages, _e = exports.CONTROL_EVENTS_KEY, controlEvents = (_d === void 0 ? (_a = {}, _a[exports.CONTROL_EVENTS_KEY] = undefined, _a) : _d)[_e];
112
- var _f = subsInfo.extensions, _g = (_f === void 0 ? { subscription: { newSubscriptions: {}, mqttConnections: [] } } : _f).subscription, newSubscriptions = _g.newSubscriptions, mqttConnections = _g.mqttConnections, _h = subsInfo.errors, errors = _h === void 0 ? [] : _h;
116
+ var _b = operation.getContext(), _c = this.subsInfoContextKey, subsInfo = _b[_c], _d = _b.controlMessages, _e = _d === void 0 ? (_a = {}, _a[exports.CONTROL_EVENTS_KEY] = undefined, _a) : _d, _f = exports.CONTROL_EVENTS_KEY, controlEvents = _e[_f];
117
+ var _g = subsInfo.extensions, _h = _g === void 0 ? { subscription: { newSubscriptions: {}, mqttConnections: [] } } : _g, _j = _h.subscription, newSubscriptions = _j.newSubscriptions, mqttConnections = _j.mqttConnections, _k = subsInfo.errors, errors = _k === void 0 ? [] : _k;
113
118
  if (errors && errors.length) {
114
119
  return new core_1.Observable(function (observer) {
115
- observer.error(new core_1.ApolloError({
116
- errorMessage: 'Error during subscription handshake',
117
- extraInfo: { errors: errors },
118
- graphQLErrors: errors
119
- }));
120
+ observer.error(new errors_1.CombinedGraphQLErrors({ errors: errors, data: null }));
120
121
  return function () { };
121
122
  });
122
123
  }
@@ -169,11 +170,11 @@ var SubscriptionHandshakeLink = /** @class */ (function (_super) {
169
170
  return observers.size > 0;
170
171
  }));
171
172
  };
172
- }).filter(function (data) {
173
- var _a = data.extensions, _b = (_a === void 0 ? {} : _a).controlMsgType, controlMsgType = _b === void 0 ? undefined : _b;
173
+ }).pipe((0, operators_1.filter)(function (data) {
174
+ var _a = data.extensions, _b = _a === void 0 ? {} : _a, _c = _b.controlMsgType, controlMsgType = _c === void 0 ? undefined : _c;
174
175
  var isControlMsg = typeof controlMsgType !== 'undefined';
175
176
  return controlEvents === true || !isControlMsg;
176
- });
177
+ }));
177
178
  };
178
179
  SubscriptionHandshakeLink.prototype.connectNewClients = function (connectionInfo, observer, operation) {
179
180
  return __awaiter(this, void 0, void 0, function () {
@@ -181,7 +182,7 @@ var SubscriptionHandshakeLink = /** @class */ (function (_super) {
181
182
  var _this = this;
182
183
  return __generator(this, function (_a) {
183
184
  query = operation.query;
184
- selectionNames = utilities_1.getMainDefinition(query).selectionSet.selections.map(function (_a) {
185
+ selectionNames = (0, utilities_1.getMainDefinition)(query).selectionSet.selections.map(function (_a) {
185
186
  var value = _a.name.value;
186
187
  return value;
187
188
  });
@@ -67,15 +67,15 @@ export declare enum CONTROL_MSG {
67
67
  TIMEOUT_DISCONNECT = "Timeout disconnect",
68
68
  SUBSCRIPTION_ACK = "Subscription ack"
69
69
  }
70
- export declare type UrlInfo = {
70
+ export type UrlInfo = {
71
71
  url: string;
72
72
  auth: AuthOptions;
73
73
  region: string;
74
74
  };
75
- export declare type AppSyncRealTimeSubscriptionConfig = UrlInfo & {
75
+ export type AppSyncRealTimeSubscriptionConfig = UrlInfo & {
76
76
  keepAliveTimeoutMs?: number;
77
77
  };
78
- export declare type ObserverQuery = {
78
+ export type ObserverQuery = {
79
79
  observer: ZenObservable.SubscriptionObserver<any>;
80
80
  query: string;
81
81
  variables: object;
@@ -84,4 +84,4 @@ export declare type ObserverQuery = {
84
84
  subscriptionFailedCallback?: Function;
85
85
  startAckTimeoutId?: number;
86
86
  };
87
- export declare type DelayFunction = (attempt: number, args?: any[], error?: Error) => number | false;
87
+ export type DelayFunction = (attempt: number, args?: any[], error?: Error) => number | false;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CONTROL_MSG = exports.MESSAGE_TYPES = exports.SOCKET_STATUS = exports.SUBSCRIPTION_STATUS = void 0;
3
4
  //#region Subscription link enums
4
5
  var SUBSCRIPTION_STATUS;
5
6
  (function (SUBSCRIPTION_STATUS) {
@@ -0,0 +1,4 @@
1
+ import { Observable as ApolloObservable } from '@apollo/client/core';
2
+ export type CompatibleObservable<T> = ApolloObservable<T>;
3
+ export declare const Observable: typeof ApolloObservable;
4
+ export declare function isApolloClientV4(): boolean;