@aws-amplify/pubsub 4.5.12-unstable.4 → 4.5.13
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 +24 -0
- package/build.js +5 -0
- package/dist/aws-amplify-pubsub.js +10278 -0
- package/dist/aws-amplify-pubsub.js.map +1 -0
- package/dist/aws-amplify-pubsub.min.js +11 -0
- package/dist/aws-amplify-pubsub.min.js.map +1 -0
- package/index.js +7 -0
- package/lib/Providers/AWSAppSyncProvider.js +102 -20
- package/lib/Providers/AWSAppSyncProvider.js.map +1 -1
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +210 -158
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
- package/lib/Providers/AWSIotProvider.js +64 -6
- package/lib/Providers/AWSIotProvider.js.map +1 -1
- package/lib/Providers/MqttOverWSProvider.js +204 -158
- package/lib/Providers/MqttOverWSProvider.js.map +1 -1
- package/lib/Providers/PubSubProvider.js +13 -3
- package/lib/Providers/PubSubProvider.js.map +1 -1
- package/lib/Providers/constants.js +0 -8
- package/lib/Providers/constants.js.map +1 -1
- package/lib/Providers/index.js +20 -13
- package/lib/Providers/index.js.map +1 -1
- package/lib/PubSub.js +56 -8
- package/lib/PubSub.js.map +1 -1
- package/lib/index.js +20 -9
- package/lib/index.js.map +1 -1
- package/lib/types/PubSub.js +12 -2
- package/lib/types/PubSub.js.map +1 -1
- package/lib/types/index.js +4 -2
- package/lib/types/index.js.map +1 -1
- package/lib/utils/ConnectionStateMonitor.js +29 -16
- package/lib/utils/ConnectionStateMonitor.js.map +1 -1
- package/lib/utils/ReachabilityMonitor/index.native.js +4 -2
- package/lib/utils/ReachabilityMonitor/index.native.js.map +1 -1
- package/lib-esm/Providers/AWSAppSyncProvider.js +80 -1
- package/lib-esm/Providers/AWSAppSyncProvider.js.map +1 -1
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +0 -8
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +168 -126
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
- package/lib-esm/Providers/AWSIotProvider.js +61 -3
- package/lib-esm/Providers/AWSIotProvider.js.map +1 -1
- package/lib-esm/Providers/MqttOverWSProvider.d.ts +4 -2
- package/lib-esm/Providers/MqttOverWSProvider.js +175 -139
- package/lib-esm/Providers/MqttOverWSProvider.js.map +1 -1
- package/lib-esm/Providers/PubSubProvider.js +11 -1
- package/lib-esm/Providers/PubSubProvider.js.map +1 -1
- package/lib-esm/Providers/constants.d.ts +0 -8
- package/lib-esm/Providers/constants.js +0 -8
- package/lib-esm/Providers/constants.js.map +1 -1
- package/lib-esm/Providers/index.d.ts +5 -5
- package/lib-esm/Providers/index.js +17 -7
- package/lib-esm/Providers/index.js.map +1 -1
- package/lib-esm/PubSub.js +48 -3
- package/lib-esm/PubSub.js.map +1 -1
- package/lib-esm/index.d.ts +7 -2
- package/lib-esm/index.js +19 -4
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/types/Provider.d.ts +4 -0
- package/lib-esm/types/PubSub.js +12 -2
- package/lib-esm/types/PubSub.js.map +1 -1
- package/lib-esm/types/index.js.map +1 -1
- package/lib-esm/utils/ConnectionStateMonitor.d.ts +0 -1
- package/lib-esm/utils/ConnectionStateMonitor.js +23 -13
- package/lib-esm/utils/ConnectionStateMonitor.js.map +1 -1
- package/package.json +10 -14
- package/src/Providers/AWSAppSyncProvider.ts +12 -2
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +89 -142
- package/src/Providers/AWSIotProvider.ts +12 -2
- package/src/Providers/MqttOverWSProvider.ts +79 -90
- package/src/Providers/PubSubProvider.ts +12 -2
- package/src/Providers/constants.ts +0 -10
- package/src/Providers/index.ts +17 -15
- package/src/PubSub.ts +12 -2
- package/src/index.ts +23 -15
- package/src/types/Provider.ts +17 -2
- package/src/types/PubSub.ts +12 -2
- package/src/types/index.ts +12 -2
- package/src/utils/ConnectionStateMonitor.ts +12 -16
- package/webpack.config.dev.js +6 -0
- package/lib/.tsbuildinfo +0 -3
- package/lib/Providers/AWSAppSyncProvider.d.ts +0 -21
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +0 -75
- package/lib/Providers/AWSIotProvider.d.ts +0 -11
- package/lib/Providers/MqttOverWSProvider.d.ts +0 -41
- package/lib/Providers/PubSubProvider.d.ts +0 -13
- package/lib/Providers/constants.d.ts +0 -95
- package/lib/Providers/index.d.ts +0 -5
- package/lib/PubSub.d.ts +0 -51
- package/lib/index.d.ts +0 -4
- package/lib/types/Provider.d.ts +0 -14
- package/lib/types/PubSub.d.ts +0 -24
- package/lib/types/index.d.ts +0 -2
- package/lib/utils/ConnectionStateMonitor.d.ts +0 -41
- package/lib/utils/ReachabilityMonitor/index.d.ts +0 -3
- package/lib/utils/ReachabilityMonitor/index.native.d.ts +0 -3
- package/lib/utils/ReconnectionMonitor.d.ts +0 -29
- package/lib/utils/ReconnectionMonitor.js +0 -73
- package/lib/utils/ReconnectionMonitor.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/utils/ReconnectionMonitor.d.ts +0 -29
- package/lib-esm/utils/ReconnectionMonitor.js +0 -71
- package/lib-esm/utils/ReconnectionMonitor.js.map +0 -1
- package/src/utils/ReconnectionMonitor.ts +0 -74
|
@@ -1,21 +1,115 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
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]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
extendStatics(d, b);
|
|
11
|
+
function __() { this.constructor = d; }
|
|
12
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
var __assign = (this && this.__assign) || function () {
|
|
16
|
+
__assign = Object.assign || function(t) {
|
|
17
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
18
|
+
s = arguments[i];
|
|
19
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
20
|
+
t[p] = s[p];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
return __assign.apply(this, arguments);
|
|
25
|
+
};
|
|
26
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
27
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
28
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
29
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
30
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
31
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
32
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
36
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
37
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
38
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
39
|
+
function step(op) {
|
|
40
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
41
|
+
while (_) try {
|
|
42
|
+
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
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
44
|
+
switch (op[0]) {
|
|
45
|
+
case 0: case 1: t = op; break;
|
|
46
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
47
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
48
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
49
|
+
default:
|
|
50
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
51
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
52
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
53
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
54
|
+
if (t[2]) _.ops.pop();
|
|
55
|
+
_.trys.pop(); continue;
|
|
56
|
+
}
|
|
57
|
+
op = body.call(thisArg, _);
|
|
58
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
59
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
63
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
64
|
+
if (!m) return o;
|
|
65
|
+
var i = m.call(o), r, ar = [], e;
|
|
66
|
+
try {
|
|
67
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
68
|
+
}
|
|
69
|
+
catch (error) { e = { error: error }; }
|
|
70
|
+
finally {
|
|
71
|
+
try {
|
|
72
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
73
|
+
}
|
|
74
|
+
finally { if (e) throw e.error; }
|
|
75
|
+
}
|
|
76
|
+
return ar;
|
|
77
|
+
};
|
|
78
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
79
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
80
|
+
};
|
|
81
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
82
|
+
if (mod && mod.__esModule) return mod;
|
|
83
|
+
var result = {};
|
|
84
|
+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
85
|
+
result["default"] = mod;
|
|
86
|
+
return result;
|
|
87
|
+
};
|
|
2
88
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
89
|
+
/*
|
|
90
|
+
* Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
91
|
+
*
|
|
92
|
+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
93
|
+
* the License. A copy of the License is located at
|
|
94
|
+
*
|
|
95
|
+
* http://aws.amazon.com/apache2.0/
|
|
96
|
+
*
|
|
97
|
+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
98
|
+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
99
|
+
* and limitations under the License.
|
|
100
|
+
*/
|
|
101
|
+
var zen_observable_ts_1 = __importDefault(require("zen-observable-ts"));
|
|
7
102
|
var graphql_1 = require("graphql");
|
|
8
|
-
var url =
|
|
103
|
+
var url = __importStar(require("url"));
|
|
9
104
|
var uuid_1 = require("uuid");
|
|
10
105
|
var buffer_1 = require("buffer");
|
|
11
106
|
var core_1 = require("@aws-amplify/core");
|
|
12
|
-
var cache_1 = require("@aws-amplify/cache");
|
|
13
|
-
var auth_1 = require("@aws-amplify/auth");
|
|
107
|
+
var cache_1 = __importDefault(require("@aws-amplify/cache"));
|
|
108
|
+
var auth_1 = __importDefault(require("@aws-amplify/auth"));
|
|
14
109
|
var PubSubProvider_1 = require("../PubSubProvider");
|
|
15
110
|
var PubSub_1 = require("../../types/PubSub");
|
|
16
111
|
var constants_1 = require("../constants");
|
|
17
112
|
var ConnectionStateMonitor_1 = require("../../utils/ConnectionStateMonitor");
|
|
18
|
-
var ReconnectionMonitor_1 = require("../../utils/ReconnectionMonitor");
|
|
19
113
|
var logger = new core_1.Logger('AWSAppSyncRealTimeProvider');
|
|
20
114
|
var dispatchApiEvent = function (event, data, message) {
|
|
21
115
|
core_1.Hub.dispatch('api', { event: event, data: data, message: message }, 'PubSub', constants_1.AMPLIFY_SYMBOL);
|
|
@@ -23,7 +117,7 @@ var dispatchApiEvent = function (event, data, message) {
|
|
|
23
117
|
var standardDomainPattern = /^https:\/\/\w{26}\.appsync\-api\.\w{2}(?:(?:\-\w{2,})+)\-\d\.amazonaws.com\/graphql$/i;
|
|
24
118
|
var customDomainPath = '/realtime';
|
|
25
119
|
var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
26
|
-
|
|
120
|
+
__extends(AWSAppSyncRealTimeProvider, _super);
|
|
27
121
|
function AWSAppSyncRealTimeProvider(options) {
|
|
28
122
|
if (options === void 0) { options = {}; }
|
|
29
123
|
var _this = _super.call(this, options) || this;
|
|
@@ -32,47 +126,15 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
32
126
|
_this.subscriptionObserverMap = new Map();
|
|
33
127
|
_this.promiseArray = [];
|
|
34
128
|
_this.connectionStateMonitor = new ConnectionStateMonitor_1.ConnectionStateMonitor();
|
|
35
|
-
_this.reconnectionMonitor = new ReconnectionMonitor_1.ReconnectionMonitor();
|
|
36
129
|
// Monitor the connection state and pass changes along to Hub
|
|
37
|
-
_this.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
_this.connectionState = connectionState;
|
|
44
|
-
// Trigger START_RECONNECT when the connection is disrupted
|
|
45
|
-
if (connectionState === PubSub_1.ConnectionState.ConnectionDisrupted) {
|
|
46
|
-
_this.reconnectionMonitor.record(ReconnectionMonitor_1.ReconnectEvent.START_RECONNECT);
|
|
47
|
-
}
|
|
48
|
-
// Trigger HALT_RECONNECT to halt reconnection attempts when the state is anything other than
|
|
49
|
-
// ConnectionDisrupted or Connecting
|
|
50
|
-
if ([
|
|
51
|
-
PubSub_1.ConnectionState.Connected,
|
|
52
|
-
PubSub_1.ConnectionState.ConnectedPendingDisconnect,
|
|
53
|
-
PubSub_1.ConnectionState.ConnectedPendingKeepAlive,
|
|
54
|
-
PubSub_1.ConnectionState.ConnectedPendingNetwork,
|
|
55
|
-
PubSub_1.ConnectionState.ConnectedPendingNetwork,
|
|
56
|
-
PubSub_1.ConnectionState.ConnectionDisruptedPendingNetwork,
|
|
57
|
-
PubSub_1.ConnectionState.Disconnected,
|
|
58
|
-
].includes(connectionState)) {
|
|
59
|
-
_this.reconnectionMonitor.record(ReconnectionMonitor_1.ReconnectEvent.HALT_RECONNECT);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
130
|
+
_this.connectionStateMonitor.connectionStateObservable.subscribe(function (ConnectionState) {
|
|
131
|
+
dispatchApiEvent(constants_1.CONNECTION_STATE_CHANGE, {
|
|
132
|
+
provider: _this,
|
|
133
|
+
connectionState: ConnectionState,
|
|
134
|
+
}, "Connection state is " + ConnectionState);
|
|
135
|
+
});
|
|
62
136
|
return _this;
|
|
63
137
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Mark the socket closed and release all active listeners
|
|
66
|
-
*/
|
|
67
|
-
AWSAppSyncRealTimeProvider.prototype.close = function () {
|
|
68
|
-
// Mark the socket closed both in status and the connection monitor
|
|
69
|
-
this.socketStatus = constants_1.SOCKET_STATUS.CLOSED;
|
|
70
|
-
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CONNECTION_FAILED);
|
|
71
|
-
// Turn off the subscription monitor Hub publishing
|
|
72
|
-
this.connectionStateMonitorSubscription.unsubscribe();
|
|
73
|
-
// Complete all reconnect observers
|
|
74
|
-
this.reconnectionMonitor.close();
|
|
75
|
-
};
|
|
76
138
|
AWSAppSyncRealTimeProvider.prototype.getNewWebSocket = function (url, protocol) {
|
|
77
139
|
return new WebSocket(url, protocol);
|
|
78
140
|
};
|
|
@@ -83,8 +145,8 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
83
145
|
throw new Error('Not used here');
|
|
84
146
|
};
|
|
85
147
|
AWSAppSyncRealTimeProvider.prototype.publish = function (_topics, _msg, _options) {
|
|
86
|
-
return
|
|
87
|
-
return
|
|
148
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
149
|
+
return __generator(this, function (_a) {
|
|
88
150
|
throw new Error('Operation not supported');
|
|
89
151
|
});
|
|
90
152
|
});
|
|
@@ -100,51 +162,35 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
100
162
|
if (!options || !appSyncGraphqlEndpoint) {
|
|
101
163
|
observer.error({
|
|
102
164
|
errors: [
|
|
103
|
-
|
|
165
|
+
__assign({}, new graphql_1.GraphQLError("Subscribe only available for AWS AppSync endpoint")),
|
|
104
166
|
],
|
|
105
167
|
});
|
|
106
168
|
observer.complete();
|
|
107
169
|
}
|
|
108
170
|
else {
|
|
109
|
-
var subscriptionStartActive_1 = false;
|
|
110
171
|
var subscriptionId_1 = uuid_1.v4();
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
subscriptionStartActive_1 = false;
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
var reconnectSubscription_1;
|
|
128
|
-
// Add an observable to the reconnection list to manage reconnection for this subscription
|
|
129
|
-
reconnectSubscription_1 = new zen_observable_ts_1.default(function (observer) {
|
|
130
|
-
_this.reconnectionMonitor.addObserver(observer);
|
|
131
|
-
}).subscribe(function () {
|
|
132
|
-
startSubscription_1();
|
|
172
|
+
_this._startSubscriptionWithAWSAppSyncRealTime({
|
|
173
|
+
options: options,
|
|
174
|
+
observer: observer,
|
|
175
|
+
subscriptionId: subscriptionId_1,
|
|
176
|
+
}).catch(function (err) {
|
|
177
|
+
observer.error({
|
|
178
|
+
errors: [
|
|
179
|
+
__assign({}, new graphql_1.GraphQLError(PubSub_1.CONTROL_MSG.REALTIME_SUBSCRIPTION_INIT_ERROR + ": " + err)),
|
|
180
|
+
],
|
|
181
|
+
});
|
|
182
|
+
_this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CLOSED);
|
|
183
|
+
observer.complete();
|
|
133
184
|
});
|
|
134
|
-
|
|
135
|
-
return function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
185
|
+
return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
136
186
|
var subscriptionState, err_1;
|
|
137
|
-
return
|
|
187
|
+
return __generator(this, function (_a) {
|
|
138
188
|
switch (_a.label) {
|
|
139
189
|
case 0:
|
|
140
|
-
|
|
141
|
-
reconnectSubscription_1 === null || reconnectSubscription_1 === void 0 ? void 0 : reconnectSubscription_1.unsubscribe();
|
|
142
|
-
_a.label = 1;
|
|
143
|
-
case 1:
|
|
144
|
-
_a.trys.push([1, 3, 4, 5]);
|
|
190
|
+
_a.trys.push([0, 2, 3, 4]);
|
|
145
191
|
// Waiting that subscription has been connected before trying to unsubscribe
|
|
146
192
|
return [4 /*yield*/, this._waitForSubscriptionToBeConnected(subscriptionId_1)];
|
|
147
|
-
case
|
|
193
|
+
case 1:
|
|
148
194
|
// Waiting that subscription has been connected before trying to unsubscribe
|
|
149
195
|
_a.sent();
|
|
150
196
|
subscriptionState = (this.subscriptionObserverMap.get(subscriptionId_1) || {}).subscriptionState;
|
|
@@ -158,15 +204,15 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
158
204
|
else {
|
|
159
205
|
throw new Error('Subscription never connected');
|
|
160
206
|
}
|
|
161
|
-
return [3 /*break*/,
|
|
162
|
-
case
|
|
207
|
+
return [3 /*break*/, 4];
|
|
208
|
+
case 2:
|
|
163
209
|
err_1 = _a.sent();
|
|
164
210
|
logger.debug("Error while unsubscribing " + err_1);
|
|
165
|
-
return [3 /*break*/,
|
|
166
|
-
case
|
|
211
|
+
return [3 /*break*/, 4];
|
|
212
|
+
case 3:
|
|
167
213
|
this._removeSubscriptionObserver(subscriptionId_1);
|
|
168
214
|
return [7 /*endfinally*/];
|
|
169
|
-
case
|
|
215
|
+
case 4: return [2 /*return*/];
|
|
170
216
|
}
|
|
171
217
|
});
|
|
172
218
|
}); };
|
|
@@ -183,15 +229,15 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
183
229
|
});
|
|
184
230
|
AWSAppSyncRealTimeProvider.prototype._startSubscriptionWithAWSAppSyncRealTime = function (_a) {
|
|
185
231
|
var options = _a.options, observer = _a.observer, subscriptionId = _a.subscriptionId;
|
|
186
|
-
var _b;
|
|
187
|
-
return
|
|
188
|
-
var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region,
|
|
189
|
-
var
|
|
232
|
+
var _b, _c;
|
|
233
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
234
|
+
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;
|
|
235
|
+
var _j;
|
|
190
236
|
var _this = this;
|
|
191
|
-
return
|
|
192
|
-
switch (
|
|
237
|
+
return __generator(this, function (_k) {
|
|
238
|
+
switch (_k.label) {
|
|
193
239
|
case 0:
|
|
194
|
-
appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint, authenticationType = options.authenticationType, query = options.query, variables = options.variables, apiKey = options.apiKey, region = options.region,
|
|
240
|
+
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 () { return ({}); } : _d, _e = options.additionalHeaders, additionalHeaders = _e === void 0 ? {} : _e;
|
|
195
241
|
subscriptionState = constants_1.SUBSCRIPTION_STATUS.PENDING;
|
|
196
242
|
data = {
|
|
197
243
|
query: query,
|
|
@@ -206,7 +252,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
206
252
|
startAckTimeoutId: undefined,
|
|
207
253
|
});
|
|
208
254
|
dataString = JSON.stringify(data);
|
|
209
|
-
|
|
255
|
+
_f = [{}];
|
|
210
256
|
return [4 /*yield*/, this._awsRealTimeHeaderBasedAuth({
|
|
211
257
|
apiKey: apiKey,
|
|
212
258
|
appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
|
|
@@ -217,24 +263,24 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
217
263
|
additionalHeaders: additionalHeaders,
|
|
218
264
|
})];
|
|
219
265
|
case 1:
|
|
220
|
-
|
|
266
|
+
_g = [__assign.apply(void 0, _f.concat([(_k.sent())]))];
|
|
221
267
|
return [4 /*yield*/, graphql_headers()];
|
|
222
268
|
case 2:
|
|
223
|
-
headerObj =
|
|
269
|
+
headerObj = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _g.concat([(_k.sent())])), additionalHeaders]), (_j = {}, _j[core_1.USER_AGENT_HEADER] = core_1.Constants.userAgent, _j)]);
|
|
224
270
|
subscriptionMessage = {
|
|
225
271
|
id: subscriptionId,
|
|
226
272
|
payload: {
|
|
227
273
|
data: dataString,
|
|
228
274
|
extensions: {
|
|
229
|
-
authorization:
|
|
275
|
+
authorization: __assign({}, headerObj),
|
|
230
276
|
},
|
|
231
277
|
},
|
|
232
278
|
type: constants_1.MESSAGE_TYPES.GQL_START,
|
|
233
279
|
};
|
|
234
280
|
stringToAWSRealTime = JSON.stringify(subscriptionMessage);
|
|
235
|
-
|
|
281
|
+
_k.label = 3;
|
|
236
282
|
case 3:
|
|
237
|
-
|
|
283
|
+
_k.trys.push([3, 5, , 6]);
|
|
238
284
|
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.OPENING_CONNECTION);
|
|
239
285
|
return [4 /*yield*/, this._initializeWebSocketConnection({
|
|
240
286
|
apiKey: apiKey,
|
|
@@ -244,14 +290,27 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
244
290
|
additionalHeaders: additionalHeaders,
|
|
245
291
|
})];
|
|
246
292
|
case 4:
|
|
247
|
-
|
|
293
|
+
_k.sent();
|
|
248
294
|
return [3 /*break*/, 6];
|
|
249
295
|
case 5:
|
|
250
|
-
err_2 =
|
|
251
|
-
|
|
296
|
+
err_2 = _k.sent();
|
|
297
|
+
logger.debug({ err: err_2 });
|
|
298
|
+
message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
|
|
299
|
+
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CLOSED);
|
|
300
|
+
observer.error({
|
|
301
|
+
errors: [
|
|
302
|
+
__assign({}, new graphql_1.GraphQLError(PubSub_1.CONTROL_MSG.CONNECTION_FAILED + ": " + message)),
|
|
303
|
+
],
|
|
304
|
+
});
|
|
305
|
+
observer.complete();
|
|
306
|
+
subscriptionFailedCallback_1 = (this.subscriptionObserverMap.get(subscriptionId) || {}).subscriptionFailedCallback;
|
|
307
|
+
// Notify concurrent unsubscription
|
|
308
|
+
if (typeof subscriptionFailedCallback_1 === 'function') {
|
|
309
|
+
subscriptionFailedCallback_1();
|
|
310
|
+
}
|
|
252
311
|
return [2 /*return*/];
|
|
253
312
|
case 6:
|
|
254
|
-
|
|
313
|
+
_h = (_c = this.subscriptionObserverMap.get(subscriptionId)) !== null && _c !== void 0 ? _c : {}, subscriptionFailedCallback = _h.subscriptionFailedCallback, subscriptionReadyCallback = _h.subscriptionReadyCallback;
|
|
255
314
|
// This must be done before sending the message in order to be listening immediately
|
|
256
315
|
this.subscriptionObserverMap.set(subscriptionId, {
|
|
257
316
|
observer: observer,
|
|
@@ -272,39 +331,12 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
272
331
|
});
|
|
273
332
|
});
|
|
274
333
|
};
|
|
275
|
-
// Log logic for start subscription failures
|
|
276
|
-
AWSAppSyncRealTimeProvider.prototype._logStartSubscriptionError = function (subscriptionId, observer, err) {
|
|
277
|
-
var _a;
|
|
278
|
-
logger.debug({ err: err });
|
|
279
|
-
var message = (_a = err['message']) !== null && _a !== void 0 ? _a : '';
|
|
280
|
-
// Resolving to give the state observer time to propogate the update
|
|
281
|
-
Promise.resolve(this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CLOSED));
|
|
282
|
-
// Capture the error only when the network didn't cause disruption
|
|
283
|
-
if (this.connectionState !== PubSub_1.ConnectionState.ConnectionDisruptedPendingNetwork) {
|
|
284
|
-
// When the error is non-retriable, error out the observable
|
|
285
|
-
if (core_1.isNonRetryableError(err)) {
|
|
286
|
-
observer.error({
|
|
287
|
-
errors: [
|
|
288
|
-
tslib_1.__assign({}, new graphql_1.GraphQLError(PubSub_1.CONTROL_MSG.CONNECTION_FAILED + ": " + message)),
|
|
289
|
-
],
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
logger.debug(PubSub_1.CONTROL_MSG.CONNECTION_FAILED + ": " + message);
|
|
294
|
-
}
|
|
295
|
-
var subscriptionFailedCallback = (this.subscriptionObserverMap.get(subscriptionId) || {}).subscriptionFailedCallback;
|
|
296
|
-
// Notify concurrent unsubscription
|
|
297
|
-
if (typeof subscriptionFailedCallback === 'function') {
|
|
298
|
-
subscriptionFailedCallback();
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
334
|
// Waiting that subscription has been connected before trying to unsubscribe
|
|
303
335
|
AWSAppSyncRealTimeProvider.prototype._waitForSubscriptionToBeConnected = function (subscriptionId) {
|
|
304
|
-
return
|
|
336
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
305
337
|
var subscriptionObserver, subscriptionState;
|
|
306
338
|
var _this = this;
|
|
307
|
-
return
|
|
339
|
+
return __generator(this, function (_a) {
|
|
308
340
|
subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
|
|
309
341
|
if (subscriptionObserver) {
|
|
310
342
|
subscriptionState = subscriptionObserver.subscriptionState;
|
|
@@ -445,14 +477,14 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
445
477
|
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
446
478
|
subscriptionState: subscriptionState,
|
|
447
479
|
});
|
|
448
|
-
logger.debug(PubSub_1.CONTROL_MSG.CONNECTION_FAILED + ": " + JSON.stringify(payload));
|
|
449
480
|
observer.error({
|
|
450
481
|
errors: [
|
|
451
|
-
|
|
482
|
+
__assign({}, new graphql_1.GraphQLError(PubSub_1.CONTROL_MSG.CONNECTION_FAILED + ": " + JSON.stringify(payload))),
|
|
452
483
|
],
|
|
453
484
|
});
|
|
454
485
|
if (startAckTimeoutId)
|
|
455
486
|
clearTimeout(startAckTimeoutId);
|
|
487
|
+
observer.complete();
|
|
456
488
|
if (typeof subscriptionFailedCallback === 'function') {
|
|
457
489
|
subscriptionFailedCallback();
|
|
458
490
|
}
|
|
@@ -461,6 +493,15 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
461
493
|
};
|
|
462
494
|
AWSAppSyncRealTimeProvider.prototype._errorDisconnect = function (msg) {
|
|
463
495
|
logger.debug("Disconnect error: " + msg);
|
|
496
|
+
this.subscriptionObserverMap.forEach(function (_a) {
|
|
497
|
+
var observer = _a.observer;
|
|
498
|
+
if (observer && !observer.closed) {
|
|
499
|
+
observer.error({
|
|
500
|
+
errors: [__assign({}, new graphql_1.GraphQLError(msg))],
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
});
|
|
504
|
+
this.subscriptionObserverMap.clear();
|
|
464
505
|
if (this.awsRealTimeSocket) {
|
|
465
506
|
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CLOSED);
|
|
466
507
|
this.awsRealTimeSocket.close();
|
|
@@ -480,7 +521,18 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
480
521
|
variables: variables,
|
|
481
522
|
subscriptionState: constants_1.SUBSCRIPTION_STATUS.FAILED,
|
|
482
523
|
});
|
|
483
|
-
|
|
524
|
+
if (observer && !observer.closed) {
|
|
525
|
+
observer.error({
|
|
526
|
+
errors: [
|
|
527
|
+
__assign({}, new graphql_1.GraphQLError("Subscription timeout " + JSON.stringify({
|
|
528
|
+
query: query,
|
|
529
|
+
variables: variables,
|
|
530
|
+
}))),
|
|
531
|
+
],
|
|
532
|
+
});
|
|
533
|
+
// Cleanup will be automatically executed
|
|
534
|
+
observer.complete();
|
|
535
|
+
}
|
|
484
536
|
logger.debug('timeoutStartSubscription', JSON.stringify({ query: query, variables: variables }));
|
|
485
537
|
}
|
|
486
538
|
};
|
|
@@ -490,9 +542,9 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
490
542
|
if (this.socketStatus === constants_1.SOCKET_STATUS.READY) {
|
|
491
543
|
return;
|
|
492
544
|
}
|
|
493
|
-
return new Promise(function (res, rej) { return
|
|
545
|
+
return new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
|
|
494
546
|
var payloadString, headerString, _a, _b, headerQs, payloadQs, discoverableEndpoint, protocol, awsRealTimeUrl, err_3;
|
|
495
|
-
return
|
|
547
|
+
return __generator(this, function (_c) {
|
|
496
548
|
switch (_c.label) {
|
|
497
549
|
case 0:
|
|
498
550
|
this.promiseArray.push({ res: res, rej: rej });
|
|
@@ -544,7 +596,6 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
544
596
|
return [3 /*break*/, 5];
|
|
545
597
|
case 4:
|
|
546
598
|
err_3 = _c.sent();
|
|
547
|
-
logger.debug('Connection exited with', err_3);
|
|
548
599
|
this.promiseArray.forEach(function (_a) {
|
|
549
600
|
var rej = _a.rej;
|
|
550
601
|
return rej(err_3);
|
|
@@ -563,8 +614,8 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
563
614
|
}); });
|
|
564
615
|
};
|
|
565
616
|
AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (awsRealTimeUrl) {
|
|
566
|
-
return
|
|
567
|
-
return
|
|
617
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
618
|
+
return __generator(this, function (_a) {
|
|
568
619
|
switch (_a.label) {
|
|
569
620
|
case 0:
|
|
570
621
|
logger.debug("Initializaling retryable Handshake");
|
|
@@ -577,10 +628,10 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
577
628
|
});
|
|
578
629
|
};
|
|
579
630
|
AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (awsRealTimeUrl) {
|
|
580
|
-
return
|
|
631
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
581
632
|
var err_4, _a, errorType, errorCode;
|
|
582
633
|
var _this = this;
|
|
583
|
-
return
|
|
634
|
+
return __generator(this, function (_b) {
|
|
584
635
|
switch (_b.label) {
|
|
585
636
|
case 0:
|
|
586
637
|
logger.debug("Initializing handshake " + awsRealTimeUrl);
|
|
@@ -594,6 +645,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
594
645
|
logger.debug("WebSocket connection error");
|
|
595
646
|
};
|
|
596
647
|
newSocket.onclose = function () {
|
|
648
|
+
_this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CONNECTION_FAILED);
|
|
597
649
|
rej(new Error('Connection handshake error'));
|
|
598
650
|
};
|
|
599
651
|
newSocket.onopen = function () {
|
|
@@ -639,7 +691,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
639
691
|
return;
|
|
640
692
|
}
|
|
641
693
|
if (type === constants_1.MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
|
|
642
|
-
var _c = data.payload, _d = (_c === void 0 ? {} : _c).errors, _e =
|
|
694
|
+
var _c = data.payload, _d = (_c === void 0 ? {} : _c).errors, _e = __read(_d === void 0 ? [] : _d, 1), _f = _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
695
|
rej({ errorType: errorType, errorCode: errorCode });
|
|
644
696
|
}
|
|
645
697
|
};
|
|
@@ -681,9 +733,9 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
681
733
|
};
|
|
682
734
|
AWSAppSyncRealTimeProvider.prototype._awsRealTimeHeaderBasedAuth = function (_a) {
|
|
683
735
|
var authenticationType = _a.authenticationType, payload = _a.payload, canonicalUri = _a.canonicalUri, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, apiKey = _a.apiKey, region = _a.region, additionalHeaders = _a.additionalHeaders;
|
|
684
|
-
return
|
|
736
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
685
737
|
var headerHandler, handler, host, result;
|
|
686
|
-
return
|
|
738
|
+
return __generator(this, function (_b) {
|
|
687
739
|
switch (_b.label) {
|
|
688
740
|
case 0:
|
|
689
741
|
headerHandler = {
|
|
@@ -718,11 +770,11 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
718
770
|
};
|
|
719
771
|
AWSAppSyncRealTimeProvider.prototype._awsRealTimeCUPHeader = function (_a) {
|
|
720
772
|
var host = _a.host;
|
|
721
|
-
return
|
|
773
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
722
774
|
var session;
|
|
723
|
-
return
|
|
775
|
+
return __generator(this, function (_b) {
|
|
724
776
|
switch (_b.label) {
|
|
725
|
-
case 0: return [4 /*yield*/, auth_1.
|
|
777
|
+
case 0: return [4 /*yield*/, auth_1.default.currentSession()];
|
|
726
778
|
case 1:
|
|
727
779
|
session = _b.sent();
|
|
728
780
|
return [2 /*return*/, {
|
|
@@ -735,17 +787,17 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
735
787
|
};
|
|
736
788
|
AWSAppSyncRealTimeProvider.prototype._awsRealTimeOPENIDHeader = function (_a) {
|
|
737
789
|
var host = _a.host;
|
|
738
|
-
return
|
|
790
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
739
791
|
var token, federatedInfo, currentUser;
|
|
740
|
-
return
|
|
792
|
+
return __generator(this, function (_b) {
|
|
741
793
|
switch (_b.label) {
|
|
742
|
-
case 0: return [4 /*yield*/, cache_1.
|
|
794
|
+
case 0: return [4 /*yield*/, cache_1.default.getItem('federatedInfo')];
|
|
743
795
|
case 1:
|
|
744
796
|
federatedInfo = _b.sent();
|
|
745
797
|
if (!federatedInfo) return [3 /*break*/, 2];
|
|
746
798
|
token = federatedInfo.token;
|
|
747
799
|
return [3 /*break*/, 4];
|
|
748
|
-
case 2: return [4 /*yield*/, auth_1.
|
|
800
|
+
case 2: return [4 /*yield*/, auth_1.default.currentAuthenticatedUser()];
|
|
749
801
|
case 3:
|
|
750
802
|
currentUser = _b.sent();
|
|
751
803
|
if (currentUser) {
|
|
@@ -766,9 +818,9 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
766
818
|
};
|
|
767
819
|
AWSAppSyncRealTimeProvider.prototype._awsRealTimeApiKeyHeader = function (_a) {
|
|
768
820
|
var apiKey = _a.apiKey, host = _a.host;
|
|
769
|
-
return
|
|
821
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
770
822
|
var dt, dtStr;
|
|
771
|
-
return
|
|
823
|
+
return __generator(this, function (_b) {
|
|
772
824
|
dt = new Date();
|
|
773
825
|
dtStr = dt.toISOString().replace(/[:\-]|\.\d{3}/g, '');
|
|
774
826
|
return [2 /*return*/, {
|
|
@@ -781,9 +833,9 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
781
833
|
};
|
|
782
834
|
AWSAppSyncRealTimeProvider.prototype._awsRealTimeIAMHeader = function (_a) {
|
|
783
835
|
var payload = _a.payload, canonicalUri = _a.canonicalUri, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, region = _a.region;
|
|
784
|
-
return
|
|
836
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
785
837
|
var endpointInfo, credentialsOK, creds, request, signed_params;
|
|
786
|
-
return
|
|
838
|
+
return __generator(this, function (_b) {
|
|
787
839
|
switch (_b.label) {
|
|
788
840
|
case 0:
|
|
789
841
|
endpointInfo = {
|
|
@@ -810,7 +862,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
810
862
|
url: "" + appSyncGraphqlEndpoint + canonicalUri,
|
|
811
863
|
data: payload,
|
|
812
864
|
method: 'POST',
|
|
813
|
-
headers:
|
|
865
|
+
headers: __assign({}, constants_1.AWS_APPSYNC_REALTIME_HEADERS),
|
|
814
866
|
};
|
|
815
867
|
signed_params = core_1.Signer.sign(request, creds, endpointInfo);
|
|
816
868
|
return [2 /*return*/, signed_params.headers];
|