@aws-amplify/pubsub 4.2.5 → 4.2.6-custom-pk.86
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 +149 -0
- package/dist/aws-amplify-pubsub.js +404 -339
- package/dist/aws-amplify-pubsub.js.map +1 -1
- package/dist/aws-amplify-pubsub.min.js +2 -2
- package/dist/aws-amplify-pubsub.min.js.map +1 -1
- package/lib/Providers/AWSAppSyncProvider.d.ts +3 -0
- package/lib/Providers/AWSAppSyncProvider.js +3 -0
- package/lib/Providers/AWSAppSyncProvider.js.map +1 -1
- package/lib/Providers/AWSAppSyncRealTimeProvider/constants.d.ts +82 -0
- package/lib/Providers/AWSAppSyncRealTimeProvider/constants.js +90 -0
- package/lib/Providers/AWSAppSyncRealTimeProvider/constants.js.map +1 -0
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +64 -0
- package/lib/Providers/{AWSAppSyncRealTimeProvider.js → AWSAppSyncRealTimeProvider/index.js} +214 -273
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -0
- package/lib/Providers/AWSIotProvider.d.ts +6 -1
- package/lib/Providers/AWSIotProvider.js +3 -2
- package/lib/Providers/AWSIotProvider.js.map +1 -1
- package/lib/Providers/MqttOverWSProvider.d.ts +14 -11
- package/lib/Providers/MqttOverWSProvider.js +17 -10
- package/lib/Providers/MqttOverWSProvider.js.map +1 -1
- package/lib/Providers/PubSubProvider.d.ts +7 -7
- package/lib/Providers/PubSubProvider.js.map +1 -1
- package/lib/PubSub.d.ts +6 -6
- package/lib/PubSub.js +2 -2
- package/lib/PubSub.js.map +1 -1
- package/lib/types/Provider.d.ts +3 -3
- package/lib/types/PubSub.d.ts +5 -1
- package/lib-esm/Providers/AWSAppSyncProvider.d.ts +3 -0
- package/lib-esm/Providers/AWSAppSyncProvider.js +3 -0
- package/lib-esm/Providers/AWSAppSyncProvider.js.map +1 -1
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.d.ts +82 -0
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js +88 -0
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/constants.js.map +1 -0
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +64 -0
- package/lib-esm/Providers/{AWSAppSyncRealTimeProvider.js → AWSAppSyncRealTimeProvider/index.js} +188 -247
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -0
- package/lib-esm/Providers/AWSIotProvider.d.ts +6 -1
- package/lib-esm/Providers/AWSIotProvider.js +3 -2
- package/lib-esm/Providers/AWSIotProvider.js.map +1 -1
- package/lib-esm/Providers/MqttOverWSProvider.d.ts +14 -11
- package/lib-esm/Providers/MqttOverWSProvider.js +17 -10
- package/lib-esm/Providers/MqttOverWSProvider.js.map +1 -1
- package/lib-esm/Providers/PubSubProvider.d.ts +7 -7
- package/lib-esm/Providers/PubSubProvider.js.map +1 -1
- package/lib-esm/PubSub.d.ts +6 -6
- package/lib-esm/PubSub.js +2 -2
- package/lib-esm/PubSub.js.map +1 -1
- package/lib-esm/types/Provider.d.ts +3 -3
- package/lib-esm/types/PubSub.d.ts +5 -1
- package/package.json +13 -7
- package/src/Providers/AWSAppSyncProvider.ts +27 -26
- package/src/Providers/AWSAppSyncRealTimeProvider/constants.ts +95 -0
- package/src/Providers/{AWSAppSyncRealTimeProvider.ts → AWSAppSyncRealTimeProvider/index.ts} +276 -303
- package/src/Providers/AWSIotProvider.ts +10 -1
- package/src/Providers/MqttOverWSProvider.ts +52 -33
- package/src/Providers/PubSubProvider.ts +8 -8
- package/src/PubSub.ts +10 -10
- package/src/types/Provider.ts +3 -7
- package/src/types/PubSub.ts +6 -1
- package/lib/Providers/AWSAppSyncRealTimeProvider.d.ts +0 -38
- package/lib/Providers/AWSAppSyncRealTimeProvider.js.map +0 -1
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider.d.ts +0 -38
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider.js.map +0 -1
|
@@ -106,112 +106,28 @@ var buffer_1 = require("buffer");
|
|
|
106
106
|
var core_1 = require("@aws-amplify/core");
|
|
107
107
|
var cache_1 = __importDefault(require("@aws-amplify/cache"));
|
|
108
108
|
var auth_1 = __importDefault(require("@aws-amplify/auth"));
|
|
109
|
-
var PubSubProvider_1 = require("
|
|
110
|
-
var index_1 = require("
|
|
109
|
+
var PubSubProvider_1 = require("../PubSubProvider");
|
|
110
|
+
var index_1 = require("../../index");
|
|
111
|
+
var constants_1 = require("./constants");
|
|
111
112
|
var logger = new core_1.Logger('AWSAppSyncRealTimeProvider');
|
|
112
|
-
var AMPLIFY_SYMBOL = (typeof Symbol !== 'undefined' &&
|
|
113
|
-
typeof Symbol.for === 'function'
|
|
114
|
-
? Symbol.for('amplify_default')
|
|
115
|
-
: '@@amplify_default');
|
|
116
113
|
var dispatchApiEvent = function (event, data, message) {
|
|
117
|
-
core_1.Hub.dispatch('api', { event: event, data: data, message: message }, 'PubSub', AMPLIFY_SYMBOL);
|
|
114
|
+
core_1.Hub.dispatch('api', { event: event, data: data, message: message }, 'PubSub', constants_1.AMPLIFY_SYMBOL);
|
|
118
115
|
};
|
|
119
|
-
var MAX_DELAY_MS = 5000;
|
|
120
|
-
var NON_RETRYABLE_CODES = [400, 401, 403];
|
|
121
|
-
var MESSAGE_TYPES;
|
|
122
|
-
(function (MESSAGE_TYPES) {
|
|
123
|
-
/**
|
|
124
|
-
* Client -> Server message.
|
|
125
|
-
* This message type is the first message after handshake and this will initialize AWS AppSync RealTime communication
|
|
126
|
-
*/
|
|
127
|
-
MESSAGE_TYPES["GQL_CONNECTION_INIT"] = "connection_init";
|
|
128
|
-
/**
|
|
129
|
-
* Server -> Client message
|
|
130
|
-
* This message type is in case there is an issue with AWS AppSync RealTime when establishing connection
|
|
131
|
-
*/
|
|
132
|
-
MESSAGE_TYPES["GQL_CONNECTION_ERROR"] = "connection_error";
|
|
133
|
-
/**
|
|
134
|
-
* Server -> Client message.
|
|
135
|
-
* This message type is for the ack response from AWS AppSync RealTime for GQL_CONNECTION_INIT message
|
|
136
|
-
*/
|
|
137
|
-
MESSAGE_TYPES["GQL_CONNECTION_ACK"] = "connection_ack";
|
|
138
|
-
/**
|
|
139
|
-
* Client -> Server message.
|
|
140
|
-
* This message type is for register subscriptions with AWS AppSync RealTime
|
|
141
|
-
*/
|
|
142
|
-
MESSAGE_TYPES["GQL_START"] = "start";
|
|
143
|
-
/**
|
|
144
|
-
* Server -> Client message.
|
|
145
|
-
* This message type is for the ack response from AWS AppSync RealTime for GQL_START message
|
|
146
|
-
*/
|
|
147
|
-
MESSAGE_TYPES["GQL_START_ACK"] = "start_ack";
|
|
148
|
-
/**
|
|
149
|
-
* Server -> Client message.
|
|
150
|
-
* This message type is for subscription message from AWS AppSync RealTime
|
|
151
|
-
*/
|
|
152
|
-
MESSAGE_TYPES["GQL_DATA"] = "data";
|
|
153
|
-
/**
|
|
154
|
-
* Server -> Client message.
|
|
155
|
-
* This message type helps the client to know is still receiving messages from AWS AppSync RealTime
|
|
156
|
-
*/
|
|
157
|
-
MESSAGE_TYPES["GQL_CONNECTION_KEEP_ALIVE"] = "ka";
|
|
158
|
-
/**
|
|
159
|
-
* Client -> Server message.
|
|
160
|
-
* This message type is for unregister subscriptions with AWS AppSync RealTime
|
|
161
|
-
*/
|
|
162
|
-
MESSAGE_TYPES["GQL_STOP"] = "stop";
|
|
163
|
-
/**
|
|
164
|
-
* Server -> Client message.
|
|
165
|
-
* This message type is for the ack response from AWS AppSync RealTime for GQL_STOP message
|
|
166
|
-
*/
|
|
167
|
-
MESSAGE_TYPES["GQL_COMPLETE"] = "complete";
|
|
168
|
-
/**
|
|
169
|
-
* Server -> Client message.
|
|
170
|
-
* This message type is for sending error messages from AWS AppSync RealTime to the client
|
|
171
|
-
*/
|
|
172
|
-
MESSAGE_TYPES["GQL_ERROR"] = "error";
|
|
173
|
-
})(MESSAGE_TYPES || (MESSAGE_TYPES = {}));
|
|
174
|
-
var SUBSCRIPTION_STATUS;
|
|
175
|
-
(function (SUBSCRIPTION_STATUS) {
|
|
176
|
-
SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["PENDING"] = 0] = "PENDING";
|
|
177
|
-
SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["CONNECTED"] = 1] = "CONNECTED";
|
|
178
|
-
SUBSCRIPTION_STATUS[SUBSCRIPTION_STATUS["FAILED"] = 2] = "FAILED";
|
|
179
|
-
})(SUBSCRIPTION_STATUS || (SUBSCRIPTION_STATUS = {}));
|
|
180
|
-
var SOCKET_STATUS;
|
|
181
|
-
(function (SOCKET_STATUS) {
|
|
182
|
-
SOCKET_STATUS[SOCKET_STATUS["CLOSED"] = 0] = "CLOSED";
|
|
183
|
-
SOCKET_STATUS[SOCKET_STATUS["READY"] = 1] = "READY";
|
|
184
|
-
SOCKET_STATUS[SOCKET_STATUS["CONNECTING"] = 2] = "CONNECTING";
|
|
185
|
-
})(SOCKET_STATUS || (SOCKET_STATUS = {}));
|
|
186
|
-
var AWS_APPSYNC_REALTIME_HEADERS = {
|
|
187
|
-
accept: 'application/json, text/javascript',
|
|
188
|
-
'content-encoding': 'amz-1.0',
|
|
189
|
-
'content-type': 'application/json; charset=UTF-8',
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* Time in milleseconds to wait for GQL_CONNECTION_INIT message
|
|
193
|
-
*/
|
|
194
|
-
var CONNECTION_INIT_TIMEOUT = 15000;
|
|
195
|
-
/**
|
|
196
|
-
* Time in milleseconds to wait for GQL_START_ACK message
|
|
197
|
-
*/
|
|
198
|
-
var START_ACK_TIMEOUT = 15000;
|
|
199
|
-
/**
|
|
200
|
-
* Default Time in milleseconds to wait for GQL_CONNECTION_KEEP_ALIVE message
|
|
201
|
-
*/
|
|
202
|
-
var DEFAULT_KEEP_ALIVE_TIMEOUT = 5 * 60 * 1000;
|
|
203
116
|
var standardDomainPattern = /^https:\/\/\w{26}\.appsync\-api\.\w{2}(?:(?:\-\w{2,})+)\-\d\.amazonaws.com\/graphql$/i;
|
|
204
117
|
var customDomainPath = '/realtime';
|
|
205
118
|
var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
206
119
|
__extends(AWSAppSyncRealTimeProvider, _super);
|
|
207
120
|
function AWSAppSyncRealTimeProvider() {
|
|
208
121
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
209
|
-
_this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
210
|
-
_this.keepAliveTimeout = DEFAULT_KEEP_ALIVE_TIMEOUT;
|
|
122
|
+
_this.socketStatus = constants_1.SOCKET_STATUS.CLOSED;
|
|
123
|
+
_this.keepAliveTimeout = constants_1.DEFAULT_KEEP_ALIVE_TIMEOUT;
|
|
211
124
|
_this.subscriptionObserverMap = new Map();
|
|
212
125
|
_this.promiseArray = [];
|
|
213
126
|
return _this;
|
|
214
127
|
}
|
|
128
|
+
AWSAppSyncRealTimeProvider.prototype.getNewWebSocket = function (url, protocol) {
|
|
129
|
+
return new WebSocket(url, protocol);
|
|
130
|
+
};
|
|
215
131
|
AWSAppSyncRealTimeProvider.prototype.getProviderName = function () {
|
|
216
132
|
return 'AWSAppSyncRealTimeProvider';
|
|
217
133
|
};
|
|
@@ -231,9 +147,9 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
231
147
|
};
|
|
232
148
|
AWSAppSyncRealTimeProvider.prototype.subscribe = function (_topics, options) {
|
|
233
149
|
var _this = this;
|
|
234
|
-
var appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint;
|
|
150
|
+
var appSyncGraphqlEndpoint = options === null || options === void 0 ? void 0 : options.appSyncGraphqlEndpoint;
|
|
235
151
|
return new zen_observable_ts_1.default(function (observer) {
|
|
236
|
-
if (!appSyncGraphqlEndpoint) {
|
|
152
|
+
if (!options || !appSyncGraphqlEndpoint) {
|
|
237
153
|
observer.error({
|
|
238
154
|
errors: [
|
|
239
155
|
__assign({}, new graphql_1.GraphQLError("Subscribe only available for AWS AppSync endpoint")),
|
|
@@ -271,7 +187,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
271
187
|
// subscription already unsubscribed
|
|
272
188
|
return [2 /*return*/];
|
|
273
189
|
}
|
|
274
|
-
if (subscriptionState === SUBSCRIPTION_STATUS.CONNECTED) {
|
|
190
|
+
if (subscriptionState === constants_1.SUBSCRIPTION_STATUS.CONNECTED) {
|
|
275
191
|
this._sendUnsubscriptionMessage(subscriptionId_1);
|
|
276
192
|
}
|
|
277
193
|
else {
|
|
@@ -302,15 +218,16 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
302
218
|
});
|
|
303
219
|
AWSAppSyncRealTimeProvider.prototype._startSubscriptionWithAWSAppSyncRealTime = function (_a) {
|
|
304
220
|
var options = _a.options, observer = _a.observer, subscriptionId = _a.subscriptionId;
|
|
221
|
+
var _b, _c;
|
|
305
222
|
return __awaiter(this, void 0, void 0, function () {
|
|
306
|
-
var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region,
|
|
307
|
-
var
|
|
223
|
+
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;
|
|
224
|
+
var _j;
|
|
308
225
|
var _this = this;
|
|
309
|
-
return __generator(this, function (
|
|
310
|
-
switch (
|
|
226
|
+
return __generator(this, function (_k) {
|
|
227
|
+
switch (_k.label) {
|
|
311
228
|
case 0:
|
|
312
|
-
appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint, authenticationType = options.authenticationType, query = options.query, variables = options.variables, apiKey = options.apiKey, region = options.region,
|
|
313
|
-
subscriptionState = SUBSCRIPTION_STATUS.PENDING;
|
|
229
|
+
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;
|
|
230
|
+
subscriptionState = constants_1.SUBSCRIPTION_STATUS.PENDING;
|
|
314
231
|
data = {
|
|
315
232
|
query: query,
|
|
316
233
|
variables: variables,
|
|
@@ -318,13 +235,13 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
318
235
|
// Having a subscription id map will make it simple to forward messages received
|
|
319
236
|
this.subscriptionObserverMap.set(subscriptionId, {
|
|
320
237
|
observer: observer,
|
|
321
|
-
query: query,
|
|
322
|
-
variables: variables,
|
|
238
|
+
query: query !== null && query !== void 0 ? query : '',
|
|
239
|
+
variables: variables !== null && variables !== void 0 ? variables : {},
|
|
323
240
|
subscriptionState: subscriptionState,
|
|
324
|
-
startAckTimeoutId:
|
|
241
|
+
startAckTimeoutId: undefined,
|
|
325
242
|
});
|
|
326
243
|
dataString = JSON.stringify(data);
|
|
327
|
-
|
|
244
|
+
_f = [{}];
|
|
328
245
|
return [4 /*yield*/, this._awsRealTimeHeaderBasedAuth({
|
|
329
246
|
apiKey: apiKey,
|
|
330
247
|
appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
|
|
@@ -335,10 +252,10 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
335
252
|
additionalHeaders: additionalHeaders,
|
|
336
253
|
})];
|
|
337
254
|
case 1:
|
|
338
|
-
|
|
255
|
+
_g = [__assign.apply(void 0, _f.concat([(_k.sent())]))];
|
|
339
256
|
return [4 /*yield*/, graphql_headers()];
|
|
340
257
|
case 2:
|
|
341
|
-
headerObj = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0,
|
|
258
|
+
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)]);
|
|
342
259
|
subscriptionMessage = {
|
|
343
260
|
id: subscriptionId,
|
|
344
261
|
payload: {
|
|
@@ -347,12 +264,12 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
347
264
|
authorization: __assign({}, headerObj),
|
|
348
265
|
},
|
|
349
266
|
},
|
|
350
|
-
type: MESSAGE_TYPES.GQL_START,
|
|
267
|
+
type: constants_1.MESSAGE_TYPES.GQL_START,
|
|
351
268
|
};
|
|
352
269
|
stringToAWSRealTime = JSON.stringify(subscriptionMessage);
|
|
353
|
-
|
|
270
|
+
_k.label = 3;
|
|
354
271
|
case 3:
|
|
355
|
-
|
|
272
|
+
_k.trys.push([3, 5, , 6]);
|
|
356
273
|
return [4 /*yield*/, this._initializeWebSocketConnection({
|
|
357
274
|
apiKey: apiKey,
|
|
358
275
|
appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
|
|
@@ -361,12 +278,12 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
361
278
|
additionalHeaders: additionalHeaders,
|
|
362
279
|
})];
|
|
363
280
|
case 4:
|
|
364
|
-
|
|
281
|
+
_k.sent();
|
|
365
282
|
return [3 /*break*/, 6];
|
|
366
283
|
case 5:
|
|
367
|
-
err_2 =
|
|
284
|
+
err_2 = _k.sent();
|
|
368
285
|
logger.debug({ err: err_2 });
|
|
369
|
-
|
|
286
|
+
message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
|
|
370
287
|
observer.error({
|
|
371
288
|
errors: [
|
|
372
289
|
__assign({}, new graphql_1.GraphQLError(index_1.CONTROL_MSG.CONNECTION_FAILED + ": " + message)),
|
|
@@ -380,18 +297,18 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
380
297
|
}
|
|
381
298
|
return [2 /*return*/];
|
|
382
299
|
case 6:
|
|
383
|
-
|
|
300
|
+
_h = (_c = this.subscriptionObserverMap.get(subscriptionId)) !== null && _c !== void 0 ? _c : {}, subscriptionFailedCallback = _h.subscriptionFailedCallback, subscriptionReadyCallback = _h.subscriptionReadyCallback;
|
|
384
301
|
// This must be done before sending the message in order to be listening immediately
|
|
385
302
|
this.subscriptionObserverMap.set(subscriptionId, {
|
|
386
303
|
observer: observer,
|
|
387
304
|
subscriptionState: subscriptionState,
|
|
388
|
-
|
|
389
|
-
|
|
305
|
+
query: query !== null && query !== void 0 ? query : '',
|
|
306
|
+
variables: variables !== null && variables !== void 0 ? variables : {},
|
|
390
307
|
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
391
308
|
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
392
309
|
startAckTimeoutId: setTimeout(function () {
|
|
393
310
|
_this._timeoutStartSubscriptionAck.call(_this, subscriptionId);
|
|
394
|
-
}, START_ACK_TIMEOUT),
|
|
311
|
+
}, constants_1.START_ACK_TIMEOUT),
|
|
395
312
|
});
|
|
396
313
|
if (this.awsRealTimeSocket) {
|
|
397
314
|
this.awsRealTimeSocket.send(stringToAWSRealTime);
|
|
@@ -404,23 +321,26 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
404
321
|
// Waiting that subscription has been connected before trying to unsubscribe
|
|
405
322
|
AWSAppSyncRealTimeProvider.prototype._waitForSubscriptionToBeConnected = function (subscriptionId) {
|
|
406
323
|
return __awaiter(this, void 0, void 0, function () {
|
|
407
|
-
var subscriptionState;
|
|
324
|
+
var subscriptionObserver, subscriptionState;
|
|
408
325
|
var _this = this;
|
|
409
326
|
return __generator(this, function (_a) {
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
observer
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
327
|
+
subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
|
|
328
|
+
if (subscriptionObserver) {
|
|
329
|
+
subscriptionState = subscriptionObserver.subscriptionState;
|
|
330
|
+
// This in case unsubscribe is invoked before sending start subscription message
|
|
331
|
+
if (subscriptionState === constants_1.SUBSCRIPTION_STATUS.PENDING) {
|
|
332
|
+
return [2 /*return*/, new Promise(function (res, rej) {
|
|
333
|
+
var observer = subscriptionObserver.observer, subscriptionState = subscriptionObserver.subscriptionState, variables = subscriptionObserver.variables, query = subscriptionObserver.query;
|
|
334
|
+
_this.subscriptionObserverMap.set(subscriptionId, {
|
|
335
|
+
observer: observer,
|
|
336
|
+
subscriptionState: subscriptionState,
|
|
337
|
+
variables: variables,
|
|
338
|
+
query: query,
|
|
339
|
+
subscriptionReadyCallback: res,
|
|
340
|
+
subscriptionFailedCallback: rej,
|
|
341
|
+
});
|
|
342
|
+
})];
|
|
343
|
+
}
|
|
424
344
|
}
|
|
425
345
|
return [2 /*return*/];
|
|
426
346
|
});
|
|
@@ -430,11 +350,11 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
430
350
|
try {
|
|
431
351
|
if (this.awsRealTimeSocket &&
|
|
432
352
|
this.awsRealTimeSocket.readyState === WebSocket.OPEN &&
|
|
433
|
-
this.socketStatus === SOCKET_STATUS.READY) {
|
|
353
|
+
this.socketStatus === constants_1.SOCKET_STATUS.READY) {
|
|
434
354
|
// Preparing unsubscribe message to stop receiving messages for that subscription
|
|
435
355
|
var unsubscribeMessage = {
|
|
436
356
|
id: subscriptionId,
|
|
437
|
-
type: MESSAGE_TYPES.GQL_STOP,
|
|
357
|
+
type: constants_1.MESSAGE_TYPES.GQL_STOP,
|
|
438
358
|
};
|
|
439
359
|
var stringToAWSRealTime = JSON.stringify(unsubscribeMessage);
|
|
440
360
|
this.awsRealTimeSocket.send(stringToAWSRealTime);
|
|
@@ -456,7 +376,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
456
376
|
return;
|
|
457
377
|
}
|
|
458
378
|
if (!this.awsRealTimeSocket) {
|
|
459
|
-
this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
379
|
+
this.socketStatus = constants_1.SOCKET_STATUS.CLOSED;
|
|
460
380
|
return;
|
|
461
381
|
}
|
|
462
382
|
if (this.awsRealTimeSocket.bufferedAmount > 0) {
|
|
@@ -465,14 +385,15 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
465
385
|
}
|
|
466
386
|
else {
|
|
467
387
|
logger.debug('closing WebSocket...');
|
|
468
|
-
|
|
388
|
+
if (this.keepAliveTimeoutId)
|
|
389
|
+
clearTimeout(this.keepAliveTimeoutId);
|
|
469
390
|
var tempSocket = this.awsRealTimeSocket;
|
|
470
391
|
// Cleaning callbacks to avoid race condition, socket still exists
|
|
471
|
-
tempSocket.onclose =
|
|
472
|
-
tempSocket.onerror =
|
|
392
|
+
tempSocket.onclose = null;
|
|
393
|
+
tempSocket.onerror = null;
|
|
473
394
|
tempSocket.close(1000);
|
|
474
|
-
this.awsRealTimeSocket =
|
|
475
|
-
this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
395
|
+
this.awsRealTimeSocket = undefined;
|
|
396
|
+
this.socketStatus = constants_1.SOCKET_STATUS.CLOSED;
|
|
476
397
|
}
|
|
477
398
|
};
|
|
478
399
|
AWSAppSyncRealTimeProvider.prototype._handleIncomingSubscriptionMessage = function (message) {
|
|
@@ -480,7 +401,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
480
401
|
var _a = JSON.parse(message.data), _b = _a.id, id = _b === void 0 ? '' : _b, payload = _a.payload, type = _a.type;
|
|
481
402
|
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, startAckTimeoutId = _c.startAckTimeoutId, subscriptionReadyCallback = _c.subscriptionReadyCallback, subscriptionFailedCallback = _c.subscriptionFailedCallback;
|
|
482
403
|
logger.debug({ id: id, observer: observer, query: query, variables: variables });
|
|
483
|
-
if (type === MESSAGE_TYPES.GQL_DATA && payload && payload.data) {
|
|
404
|
+
if (type === constants_1.MESSAGE_TYPES.GQL_DATA && payload && payload.data) {
|
|
484
405
|
if (observer) {
|
|
485
406
|
observer.next(payload);
|
|
486
407
|
}
|
|
@@ -489,51 +410,58 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
489
410
|
}
|
|
490
411
|
return;
|
|
491
412
|
}
|
|
492
|
-
if (type === MESSAGE_TYPES.GQL_START_ACK) {
|
|
413
|
+
if (type === constants_1.MESSAGE_TYPES.GQL_START_ACK) {
|
|
493
414
|
logger.debug("subscription ready for " + JSON.stringify({ query: query, variables: variables }));
|
|
494
415
|
if (typeof subscriptionReadyCallback === 'function') {
|
|
495
416
|
subscriptionReadyCallback();
|
|
496
417
|
}
|
|
497
|
-
|
|
418
|
+
if (startAckTimeoutId)
|
|
419
|
+
clearTimeout(startAckTimeoutId);
|
|
498
420
|
dispatchApiEvent(index_1.CONTROL_MSG.SUBSCRIPTION_ACK, { query: query, variables: variables }, 'Connection established for subscription');
|
|
499
|
-
var subscriptionState = SUBSCRIPTION_STATUS.CONNECTED;
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
421
|
+
var subscriptionState = constants_1.SUBSCRIPTION_STATUS.CONNECTED;
|
|
422
|
+
if (observer) {
|
|
423
|
+
this.subscriptionObserverMap.set(id, {
|
|
424
|
+
observer: observer,
|
|
425
|
+
query: query,
|
|
426
|
+
variables: variables,
|
|
427
|
+
startAckTimeoutId: undefined,
|
|
428
|
+
subscriptionState: subscriptionState,
|
|
429
|
+
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
430
|
+
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
509
433
|
// TODO: emit event on hub but it requires to store the id first
|
|
510
434
|
return;
|
|
511
435
|
}
|
|
512
|
-
if (type === MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) {
|
|
513
|
-
|
|
436
|
+
if (type === constants_1.MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) {
|
|
437
|
+
if (this.keepAliveTimeoutId)
|
|
438
|
+
clearTimeout(this.keepAliveTimeoutId);
|
|
514
439
|
this.keepAliveTimeoutId = setTimeout(this._errorDisconnect.bind(this, index_1.CONTROL_MSG.TIMEOUT_DISCONNECT), this.keepAliveTimeout);
|
|
515
440
|
return;
|
|
516
441
|
}
|
|
517
|
-
if (type === MESSAGE_TYPES.GQL_ERROR) {
|
|
518
|
-
var subscriptionState = SUBSCRIPTION_STATUS.FAILED;
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
442
|
+
if (type === constants_1.MESSAGE_TYPES.GQL_ERROR) {
|
|
443
|
+
var subscriptionState = constants_1.SUBSCRIPTION_STATUS.FAILED;
|
|
444
|
+
if (observer) {
|
|
445
|
+
this.subscriptionObserverMap.set(id, {
|
|
446
|
+
observer: observer,
|
|
447
|
+
query: query,
|
|
448
|
+
variables: variables,
|
|
449
|
+
startAckTimeoutId: startAckTimeoutId,
|
|
450
|
+
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
451
|
+
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
452
|
+
subscriptionState: subscriptionState,
|
|
453
|
+
});
|
|
454
|
+
observer.error({
|
|
455
|
+
errors: [
|
|
456
|
+
__assign({}, new graphql_1.GraphQLError(index_1.CONTROL_MSG.CONNECTION_FAILED + ": " + JSON.stringify(payload))),
|
|
457
|
+
],
|
|
458
|
+
});
|
|
459
|
+
if (startAckTimeoutId)
|
|
460
|
+
clearTimeout(startAckTimeoutId);
|
|
461
|
+
observer.complete();
|
|
462
|
+
if (typeof subscriptionFailedCallback === 'function') {
|
|
463
|
+
subscriptionFailedCallback();
|
|
464
|
+
}
|
|
537
465
|
}
|
|
538
466
|
}
|
|
539
467
|
};
|
|
@@ -551,37 +479,40 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
551
479
|
if (this.awsRealTimeSocket) {
|
|
552
480
|
this.awsRealTimeSocket.close();
|
|
553
481
|
}
|
|
554
|
-
this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
482
|
+
this.socketStatus = constants_1.SOCKET_STATUS.CLOSED;
|
|
555
483
|
};
|
|
556
484
|
AWSAppSyncRealTimeProvider.prototype._timeoutStartSubscriptionAck = function (subscriptionId) {
|
|
557
|
-
var
|
|
558
|
-
if (
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
observer.error({
|
|
569
|
-
errors: [
|
|
570
|
-
__assign({}, new graphql_1.GraphQLError("Subscription timeout " + JSON.stringify({
|
|
571
|
-
query: query,
|
|
572
|
-
variables: variables,
|
|
573
|
-
}))),
|
|
574
|
-
],
|
|
485
|
+
var subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
|
|
486
|
+
if (subscriptionObserver) {
|
|
487
|
+
var observer = subscriptionObserver.observer, query = subscriptionObserver.query, variables = subscriptionObserver.variables;
|
|
488
|
+
if (!observer) {
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
this.subscriptionObserverMap.set(subscriptionId, {
|
|
492
|
+
observer: observer,
|
|
493
|
+
query: query,
|
|
494
|
+
variables: variables,
|
|
495
|
+
subscriptionState: constants_1.SUBSCRIPTION_STATUS.FAILED,
|
|
575
496
|
});
|
|
576
|
-
|
|
577
|
-
|
|
497
|
+
if (observer && !observer.closed) {
|
|
498
|
+
observer.error({
|
|
499
|
+
errors: [
|
|
500
|
+
__assign({}, new graphql_1.GraphQLError("Subscription timeout " + JSON.stringify({
|
|
501
|
+
query: query,
|
|
502
|
+
variables: variables,
|
|
503
|
+
}))),
|
|
504
|
+
],
|
|
505
|
+
});
|
|
506
|
+
// Cleanup will be automatically executed
|
|
507
|
+
observer.complete();
|
|
508
|
+
}
|
|
509
|
+
logger.debug('timeoutStartSubscription', JSON.stringify({ query: query, variables: variables }));
|
|
578
510
|
}
|
|
579
|
-
logger.debug('timeoutStartSubscription', JSON.stringify({ query: query, variables: variables }));
|
|
580
511
|
};
|
|
581
512
|
AWSAppSyncRealTimeProvider.prototype._initializeWebSocketConnection = function (_a) {
|
|
582
513
|
var _this = this;
|
|
583
514
|
var appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, authenticationType = _a.authenticationType, apiKey = _a.apiKey, region = _a.region, additionalHeaders = _a.additionalHeaders;
|
|
584
|
-
if (this.socketStatus === SOCKET_STATUS.READY) {
|
|
515
|
+
if (this.socketStatus === constants_1.SOCKET_STATUS.READY) {
|
|
585
516
|
return;
|
|
586
517
|
}
|
|
587
518
|
return new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -590,11 +521,11 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
590
521
|
switch (_c.label) {
|
|
591
522
|
case 0:
|
|
592
523
|
this.promiseArray.push({ res: res, rej: rej });
|
|
593
|
-
if (!(this.socketStatus === SOCKET_STATUS.CLOSED)) return [3 /*break*/, 5];
|
|
524
|
+
if (!(this.socketStatus === constants_1.SOCKET_STATUS.CLOSED)) return [3 /*break*/, 5];
|
|
594
525
|
_c.label = 1;
|
|
595
526
|
case 1:
|
|
596
527
|
_c.trys.push([1, 4, , 5]);
|
|
597
|
-
this.socketStatus = SOCKET_STATUS.CONNECTING;
|
|
528
|
+
this.socketStatus = constants_1.SOCKET_STATUS.CONNECTING;
|
|
598
529
|
payloadString = '{}';
|
|
599
530
|
_b = (_a = JSON).stringify;
|
|
600
531
|
return [4 /*yield*/, this._awsRealTimeHeaderBasedAuth({
|
|
@@ -610,19 +541,22 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
610
541
|
headerString = _b.apply(_a, [_c.sent()]);
|
|
611
542
|
headerQs = buffer_1.Buffer.from(headerString).toString('base64');
|
|
612
543
|
payloadQs = buffer_1.Buffer.from(payloadString).toString('base64');
|
|
613
|
-
discoverableEndpoint = appSyncGraphqlEndpoint;
|
|
544
|
+
discoverableEndpoint = appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '';
|
|
614
545
|
if (this.isCustomDomain(discoverableEndpoint)) {
|
|
615
|
-
discoverableEndpoint =
|
|
546
|
+
discoverableEndpoint =
|
|
547
|
+
discoverableEndpoint.concat(customDomainPath);
|
|
616
548
|
}
|
|
617
549
|
else {
|
|
618
|
-
discoverableEndpoint = discoverableEndpoint
|
|
550
|
+
discoverableEndpoint = discoverableEndpoint
|
|
551
|
+
.replace('appsync-api', 'appsync-realtime-api')
|
|
552
|
+
.replace('gogi-beta', 'grt-beta');
|
|
619
553
|
}
|
|
620
554
|
protocol = this.isSSLEnabled ? 'wss://' : 'ws://';
|
|
621
555
|
discoverableEndpoint = discoverableEndpoint
|
|
622
556
|
.replace('https://', protocol)
|
|
623
557
|
.replace('http://', protocol);
|
|
624
558
|
awsRealTimeUrl = discoverableEndpoint + "?header=" + headerQs + "&payload=" + payloadQs;
|
|
625
|
-
return [4 /*yield*/, this._initializeRetryableHandshake(
|
|
559
|
+
return [4 /*yield*/, this._initializeRetryableHandshake(awsRealTimeUrl)];
|
|
626
560
|
case 3:
|
|
627
561
|
_c.sent();
|
|
628
562
|
this.promiseArray.forEach(function (_a) {
|
|
@@ -630,7 +564,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
630
564
|
logger.debug('Notifying connection successful');
|
|
631
565
|
res();
|
|
632
566
|
});
|
|
633
|
-
this.socketStatus = SOCKET_STATUS.READY;
|
|
567
|
+
this.socketStatus = constants_1.SOCKET_STATUS.READY;
|
|
634
568
|
this.promiseArray = [];
|
|
635
569
|
return [3 /*break*/, 5];
|
|
636
570
|
case 4:
|
|
@@ -644,33 +578,31 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
644
578
|
this.awsRealTimeSocket.readyState === WebSocket.OPEN) {
|
|
645
579
|
this.awsRealTimeSocket.close(3001);
|
|
646
580
|
}
|
|
647
|
-
this.awsRealTimeSocket =
|
|
648
|
-
this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
581
|
+
this.awsRealTimeSocket = undefined;
|
|
582
|
+
this.socketStatus = constants_1.SOCKET_STATUS.CLOSED;
|
|
649
583
|
return [3 /*break*/, 5];
|
|
650
584
|
case 5: return [2 /*return*/];
|
|
651
585
|
}
|
|
652
586
|
});
|
|
653
587
|
}); });
|
|
654
588
|
};
|
|
655
|
-
AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (
|
|
656
|
-
var awsRealTimeUrl = _a.awsRealTimeUrl;
|
|
589
|
+
AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (awsRealTimeUrl) {
|
|
657
590
|
return __awaiter(this, void 0, void 0, function () {
|
|
658
|
-
return __generator(this, function (
|
|
659
|
-
switch (
|
|
591
|
+
return __generator(this, function (_a) {
|
|
592
|
+
switch (_a.label) {
|
|
660
593
|
case 0:
|
|
661
594
|
logger.debug("Initializaling retryable Handshake");
|
|
662
|
-
return [4 /*yield*/, core_1.jitteredExponentialRetry(this._initializeHandshake.bind(this), [
|
|
595
|
+
return [4 /*yield*/, core_1.jitteredExponentialRetry(this._initializeHandshake.bind(this), [awsRealTimeUrl], constants_1.MAX_DELAY_MS)];
|
|
663
596
|
case 1:
|
|
664
|
-
|
|
597
|
+
_a.sent();
|
|
665
598
|
return [2 /*return*/];
|
|
666
599
|
}
|
|
667
600
|
});
|
|
668
601
|
});
|
|
669
602
|
};
|
|
670
|
-
AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (
|
|
671
|
-
var awsRealTimeUrl = _a.awsRealTimeUrl;
|
|
603
|
+
AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (awsRealTimeUrl) {
|
|
672
604
|
return __awaiter(this, void 0, void 0, function () {
|
|
673
|
-
var err_4, errorType, errorCode;
|
|
605
|
+
var err_4, _a, errorType, errorCode;
|
|
674
606
|
var _this = this;
|
|
675
607
|
return __generator(this, function (_b) {
|
|
676
608
|
switch (_b.label) {
|
|
@@ -681,7 +613,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
681
613
|
_b.trys.push([1, 4, , 5]);
|
|
682
614
|
return [4 /*yield*/, (function () {
|
|
683
615
|
return new Promise(function (res, rej) {
|
|
684
|
-
var newSocket =
|
|
616
|
+
var newSocket = _this.getNewWebSocket(awsRealTimeUrl, 'graphql-ws');
|
|
685
617
|
newSocket.onerror = function () {
|
|
686
618
|
logger.debug("WebSocket connection error");
|
|
687
619
|
};
|
|
@@ -699,48 +631,53 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
699
631
|
// Step 2: wait for ack from AWS AppSyncReaTime after sending init
|
|
700
632
|
return [4 /*yield*/, (function () {
|
|
701
633
|
return new Promise(function (res, rej) {
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
634
|
+
if (_this.awsRealTimeSocket) {
|
|
635
|
+
var ackOk_1 = false;
|
|
636
|
+
_this.awsRealTimeSocket.onerror = function (error) {
|
|
637
|
+
logger.debug("WebSocket error " + JSON.stringify(error));
|
|
638
|
+
};
|
|
639
|
+
_this.awsRealTimeSocket.onclose = function (event) {
|
|
640
|
+
logger.debug("WebSocket closed " + event.reason);
|
|
641
|
+
rej(new Error(JSON.stringify(event)));
|
|
642
|
+
};
|
|
643
|
+
_this.awsRealTimeSocket.onmessage = function (message) {
|
|
644
|
+
logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
|
|
645
|
+
var data = JSON.parse(message.data);
|
|
646
|
+
var type = data.type, _a = data.payload, _b = (_a === void 0 ? {} : _a).connectionTimeoutMs, connectionTimeoutMs = _b === void 0 ? constants_1.DEFAULT_KEEP_ALIVE_TIMEOUT : _b;
|
|
647
|
+
if (type === constants_1.MESSAGE_TYPES.GQL_CONNECTION_ACK) {
|
|
648
|
+
ackOk_1 = true;
|
|
649
|
+
if (_this.awsRealTimeSocket) {
|
|
650
|
+
_this.keepAliveTimeout = connectionTimeoutMs;
|
|
651
|
+
_this.awsRealTimeSocket.onmessage =
|
|
652
|
+
_this._handleIncomingSubscriptionMessage.bind(_this);
|
|
653
|
+
_this.awsRealTimeSocket.onerror = function (err) {
|
|
654
|
+
logger.debug(err);
|
|
655
|
+
_this._errorDisconnect(index_1.CONTROL_MSG.CONNECTION_CLOSED);
|
|
656
|
+
};
|
|
657
|
+
_this.awsRealTimeSocket.onclose = function (event) {
|
|
658
|
+
logger.debug("WebSocket closed " + event.reason);
|
|
659
|
+
_this._errorDisconnect(index_1.CONTROL_MSG.CONNECTION_CLOSED);
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
res('Cool, connected to AWS AppSyncRealTime');
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
if (type === constants_1.MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
|
|
666
|
+
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;
|
|
667
|
+
rej({ errorType: errorType, errorCode: errorCode });
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
var gqlInit = {
|
|
671
|
+
type: constants_1.MESSAGE_TYPES.GQL_CONNECTION_INIT,
|
|
672
|
+
};
|
|
673
|
+
_this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
|
|
674
|
+
setTimeout(checkAckOk.bind(_this, ackOk_1), constants_1.CONNECTION_INIT_TIMEOUT);
|
|
675
|
+
}
|
|
676
|
+
function checkAckOk(ackOk) {
|
|
739
677
|
if (!ackOk) {
|
|
740
|
-
rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + CONNECTION_INIT_TIMEOUT + " ms"));
|
|
678
|
+
rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + constants_1.CONNECTION_INIT_TIMEOUT + " ms"));
|
|
741
679
|
}
|
|
742
680
|
}
|
|
743
|
-
setTimeout(checkAckOk.bind(_this), CONNECTION_INIT_TIMEOUT);
|
|
744
681
|
});
|
|
745
682
|
})()];
|
|
746
683
|
case 3:
|
|
@@ -749,8 +686,8 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
749
686
|
return [3 /*break*/, 5];
|
|
750
687
|
case 4:
|
|
751
688
|
err_4 = _b.sent();
|
|
752
|
-
errorType =
|
|
753
|
-
if (NON_RETRYABLE_CODES.includes(errorCode)) {
|
|
689
|
+
_a = err_4, errorType = _a.errorType, errorCode = _a.errorCode;
|
|
690
|
+
if (constants_1.NON_RETRYABLE_CODES.includes(errorCode)) {
|
|
754
691
|
throw new core_1.NonRetryableError(errorType);
|
|
755
692
|
}
|
|
756
693
|
else if (errorType) {
|
|
@@ -779,12 +716,13 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
779
716
|
AMAZON_COGNITO_USER_POOLS: this._awsRealTimeCUPHeader.bind(this),
|
|
780
717
|
AWS_LAMBDA: this._customAuthHeader,
|
|
781
718
|
};
|
|
719
|
+
if (!(!authenticationType || !headerHandler[authenticationType])) return [3 /*break*/, 1];
|
|
720
|
+
logger.debug("Authentication type " + authenticationType + " not supported");
|
|
721
|
+
return [2 /*return*/, ''];
|
|
722
|
+
case 1:
|
|
782
723
|
handler = headerHandler[authenticationType];
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
return [2 /*return*/, ''];
|
|
786
|
-
}
|
|
787
|
-
host = url.parse(appSyncGraphqlEndpoint).host;
|
|
724
|
+
host = url.parse(appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
|
|
725
|
+
logger.debug("Authenticating with " + authenticationType);
|
|
788
726
|
return [4 /*yield*/, handler({
|
|
789
727
|
payload: payload,
|
|
790
728
|
canonicalUri: canonicalUri,
|
|
@@ -794,7 +732,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
794
732
|
host: host,
|
|
795
733
|
additionalHeaders: additionalHeaders,
|
|
796
734
|
})];
|
|
797
|
-
case
|
|
735
|
+
case 2:
|
|
798
736
|
result = _b.sent();
|
|
799
737
|
return [2 /*return*/, result];
|
|
800
738
|
}
|
|
@@ -881,18 +819,21 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
881
819
|
if (!credentialsOK) {
|
|
882
820
|
throw new Error('No credentials');
|
|
883
821
|
}
|
|
884
|
-
return [4 /*yield*/, core_1.Credentials.get().then(function (credentials) {
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
822
|
+
return [4 /*yield*/, core_1.Credentials.get().then(function (credentials) {
|
|
823
|
+
var _a = credentials, secretAccessKey = _a.secretAccessKey, accessKeyId = _a.accessKeyId, sessionToken = _a.sessionToken;
|
|
824
|
+
return {
|
|
825
|
+
secret_key: secretAccessKey,
|
|
826
|
+
access_key: accessKeyId,
|
|
827
|
+
session_token: sessionToken,
|
|
828
|
+
};
|
|
829
|
+
})];
|
|
889
830
|
case 2:
|
|
890
831
|
creds = _b.sent();
|
|
891
832
|
request = {
|
|
892
833
|
url: "" + appSyncGraphqlEndpoint + canonicalUri,
|
|
893
834
|
data: payload,
|
|
894
835
|
method: 'POST',
|
|
895
|
-
headers: __assign({}, AWS_APPSYNC_REALTIME_HEADERS),
|
|
836
|
+
headers: __assign({}, constants_1.AWS_APPSYNC_REALTIME_HEADERS),
|
|
896
837
|
};
|
|
897
838
|
signed_params = core_1.Signer.sign(request, creds, endpointInfo);
|
|
898
839
|
return [2 /*return*/, signed_params.headers];
|
|
@@ -902,7 +843,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
902
843
|
};
|
|
903
844
|
AWSAppSyncRealTimeProvider.prototype._customAuthHeader = function (_a) {
|
|
904
845
|
var host = _a.host, additionalHeaders = _a.additionalHeaders;
|
|
905
|
-
if (!additionalHeaders
|
|
846
|
+
if (!additionalHeaders || !additionalHeaders['Authorization']) {
|
|
906
847
|
throw new Error('No auth token specified');
|
|
907
848
|
}
|
|
908
849
|
return {
|
|
@@ -930,4 +871,4 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
930
871
|
return AWSAppSyncRealTimeProvider;
|
|
931
872
|
}(PubSubProvider_1.AbstractPubSubProvider));
|
|
932
873
|
exports.AWSAppSyncRealTimeProvider = AWSAppSyncRealTimeProvider;
|
|
933
|
-
//# sourceMappingURL=
|
|
874
|
+
//# sourceMappingURL=index.js.map
|