@aws-amplify/pubsub 4.2.9-unstable.9 → 4.2.10-cloud-logging.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -44
- package/dist/aws-amplify-pubsub.js +258 -209
- 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.d.ts +19 -4
- package/lib/Providers/AWSAppSyncRealTimeProvider.js +192 -159
- package/lib/Providers/AWSAppSyncRealTimeProvider.js.map +1 -1
- 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.d.ts +19 -4
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider.js +192 -159
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider.js.map +1 -1
- 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 +5 -5
- package/src/Providers/AWSAppSyncProvider.ts +27 -26
- package/src/Providers/AWSAppSyncRealTimeProvider.ts +276 -214
- 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
|
@@ -97,8 +97,7 @@ import Auth from '@aws-amplify/auth';
|
|
|
97
97
|
import { AbstractPubSubProvider } from './PubSubProvider';
|
|
98
98
|
import { CONTROL_MSG } from '../index';
|
|
99
99
|
var logger = new Logger('AWSAppSyncRealTimeProvider');
|
|
100
|
-
var AMPLIFY_SYMBOL = (typeof Symbol !== 'undefined' &&
|
|
101
|
-
typeof Symbol.for === 'function'
|
|
100
|
+
var AMPLIFY_SYMBOL = (typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'
|
|
102
101
|
? Symbol.for('amplify_default')
|
|
103
102
|
: '@@amplify_default');
|
|
104
103
|
var dispatchApiEvent = function (event, data, message) {
|
|
@@ -219,9 +218,9 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
219
218
|
};
|
|
220
219
|
AWSAppSyncRealTimeProvider.prototype.subscribe = function (_topics, options) {
|
|
221
220
|
var _this = this;
|
|
222
|
-
var appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint;
|
|
221
|
+
var appSyncGraphqlEndpoint = options === null || options === void 0 ? void 0 : options.appSyncGraphqlEndpoint;
|
|
223
222
|
return new Observable(function (observer) {
|
|
224
|
-
if (!appSyncGraphqlEndpoint) {
|
|
223
|
+
if (!options || !appSyncGraphqlEndpoint) {
|
|
225
224
|
observer.error({
|
|
226
225
|
errors: [
|
|
227
226
|
__assign({}, new GraphQLError("Subscribe only available for AWS AppSync endpoint")),
|
|
@@ -290,14 +289,15 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
290
289
|
});
|
|
291
290
|
AWSAppSyncRealTimeProvider.prototype._startSubscriptionWithAWSAppSyncRealTime = function (_a) {
|
|
292
291
|
var options = _a.options, observer = _a.observer, subscriptionId = _a.subscriptionId;
|
|
292
|
+
var _b, _c;
|
|
293
293
|
return __awaiter(this, void 0, void 0, function () {
|
|
294
|
-
var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region,
|
|
295
|
-
var
|
|
294
|
+
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;
|
|
295
|
+
var _j;
|
|
296
296
|
var _this = this;
|
|
297
|
-
return __generator(this, function (
|
|
298
|
-
switch (
|
|
297
|
+
return __generator(this, function (_k) {
|
|
298
|
+
switch (_k.label) {
|
|
299
299
|
case 0:
|
|
300
|
-
appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint, authenticationType = options.authenticationType, query = options.query, variables = options.variables, apiKey = options.apiKey, region = options.region,
|
|
300
|
+
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;
|
|
301
301
|
subscriptionState = SUBSCRIPTION_STATUS.PENDING;
|
|
302
302
|
data = {
|
|
303
303
|
query: query,
|
|
@@ -306,13 +306,13 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
306
306
|
// Having a subscription id map will make it simple to forward messages received
|
|
307
307
|
this.subscriptionObserverMap.set(subscriptionId, {
|
|
308
308
|
observer: observer,
|
|
309
|
-
query: query,
|
|
310
|
-
variables: variables,
|
|
309
|
+
query: query !== null && query !== void 0 ? query : '',
|
|
310
|
+
variables: variables !== null && variables !== void 0 ? variables : {},
|
|
311
311
|
subscriptionState: subscriptionState,
|
|
312
|
-
startAckTimeoutId:
|
|
312
|
+
startAckTimeoutId: undefined,
|
|
313
313
|
});
|
|
314
314
|
dataString = JSON.stringify(data);
|
|
315
|
-
|
|
315
|
+
_f = [{}];
|
|
316
316
|
return [4 /*yield*/, this._awsRealTimeHeaderBasedAuth({
|
|
317
317
|
apiKey: apiKey,
|
|
318
318
|
appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
|
|
@@ -323,10 +323,10 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
323
323
|
additionalHeaders: additionalHeaders,
|
|
324
324
|
})];
|
|
325
325
|
case 1:
|
|
326
|
-
|
|
326
|
+
_g = [__assign.apply(void 0, _f.concat([(_k.sent())]))];
|
|
327
327
|
return [4 /*yield*/, graphql_headers()];
|
|
328
328
|
case 2:
|
|
329
|
-
headerObj = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0,
|
|
329
|
+
headerObj = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _g.concat([(_k.sent())])), additionalHeaders]), (_j = {}, _j[USER_AGENT_HEADER] = Constants.userAgent, _j)]);
|
|
330
330
|
subscriptionMessage = {
|
|
331
331
|
id: subscriptionId,
|
|
332
332
|
payload: {
|
|
@@ -338,9 +338,9 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
338
338
|
type: MESSAGE_TYPES.GQL_START,
|
|
339
339
|
};
|
|
340
340
|
stringToAWSRealTime = JSON.stringify(subscriptionMessage);
|
|
341
|
-
|
|
341
|
+
_k.label = 3;
|
|
342
342
|
case 3:
|
|
343
|
-
|
|
343
|
+
_k.trys.push([3, 5, , 6]);
|
|
344
344
|
return [4 /*yield*/, this._initializeWebSocketConnection({
|
|
345
345
|
apiKey: apiKey,
|
|
346
346
|
appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
|
|
@@ -349,12 +349,12 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
349
349
|
additionalHeaders: additionalHeaders,
|
|
350
350
|
})];
|
|
351
351
|
case 4:
|
|
352
|
-
|
|
352
|
+
_k.sent();
|
|
353
353
|
return [3 /*break*/, 6];
|
|
354
354
|
case 5:
|
|
355
|
-
err_2 =
|
|
355
|
+
err_2 = _k.sent();
|
|
356
356
|
logger.debug({ err: err_2 });
|
|
357
|
-
|
|
357
|
+
message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
|
|
358
358
|
observer.error({
|
|
359
359
|
errors: [
|
|
360
360
|
__assign({}, new GraphQLError(CONTROL_MSG.CONNECTION_FAILED + ": " + message)),
|
|
@@ -368,13 +368,13 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
368
368
|
}
|
|
369
369
|
return [2 /*return*/];
|
|
370
370
|
case 6:
|
|
371
|
-
|
|
371
|
+
_h = (_c = this.subscriptionObserverMap.get(subscriptionId)) !== null && _c !== void 0 ? _c : {}, subscriptionFailedCallback = _h.subscriptionFailedCallback, subscriptionReadyCallback = _h.subscriptionReadyCallback;
|
|
372
372
|
// This must be done before sending the message in order to be listening immediately
|
|
373
373
|
this.subscriptionObserverMap.set(subscriptionId, {
|
|
374
374
|
observer: observer,
|
|
375
375
|
subscriptionState: subscriptionState,
|
|
376
|
-
|
|
377
|
-
|
|
376
|
+
query: query !== null && query !== void 0 ? query : '',
|
|
377
|
+
variables: variables !== null && variables !== void 0 ? variables : {},
|
|
378
378
|
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
379
379
|
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
380
380
|
startAckTimeoutId: setTimeout(function () {
|
|
@@ -392,23 +392,26 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
392
392
|
// Waiting that subscription has been connected before trying to unsubscribe
|
|
393
393
|
AWSAppSyncRealTimeProvider.prototype._waitForSubscriptionToBeConnected = function (subscriptionId) {
|
|
394
394
|
return __awaiter(this, void 0, void 0, function () {
|
|
395
|
-
var subscriptionState;
|
|
395
|
+
var subscriptionObserver, subscriptionState;
|
|
396
396
|
var _this = this;
|
|
397
397
|
return __generator(this, function (_a) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
observer
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
398
|
+
subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
|
|
399
|
+
if (subscriptionObserver) {
|
|
400
|
+
subscriptionState = subscriptionObserver.subscriptionState;
|
|
401
|
+
// This in case unsubscribe is invoked before sending start subscription message
|
|
402
|
+
if (subscriptionState === SUBSCRIPTION_STATUS.PENDING) {
|
|
403
|
+
return [2 /*return*/, new Promise(function (res, rej) {
|
|
404
|
+
var observer = subscriptionObserver.observer, subscriptionState = subscriptionObserver.subscriptionState, variables = subscriptionObserver.variables, query = subscriptionObserver.query;
|
|
405
|
+
_this.subscriptionObserverMap.set(subscriptionId, {
|
|
406
|
+
observer: observer,
|
|
407
|
+
subscriptionState: subscriptionState,
|
|
408
|
+
variables: variables,
|
|
409
|
+
query: query,
|
|
410
|
+
subscriptionReadyCallback: res,
|
|
411
|
+
subscriptionFailedCallback: rej,
|
|
412
|
+
});
|
|
413
|
+
})];
|
|
414
|
+
}
|
|
412
415
|
}
|
|
413
416
|
return [2 /*return*/];
|
|
414
417
|
});
|
|
@@ -453,21 +456,32 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
453
456
|
}
|
|
454
457
|
else {
|
|
455
458
|
logger.debug('closing WebSocket...');
|
|
456
|
-
|
|
459
|
+
if (this.keepAliveTimeoutId)
|
|
460
|
+
clearTimeout(this.keepAliveTimeoutId);
|
|
457
461
|
var tempSocket = this.awsRealTimeSocket;
|
|
458
462
|
// Cleaning callbacks to avoid race condition, socket still exists
|
|
459
|
-
tempSocket.onclose =
|
|
460
|
-
tempSocket.onerror =
|
|
463
|
+
tempSocket.onclose = null;
|
|
464
|
+
tempSocket.onerror = null;
|
|
461
465
|
tempSocket.close(1000);
|
|
462
|
-
this.awsRealTimeSocket =
|
|
466
|
+
this.awsRealTimeSocket = undefined;
|
|
463
467
|
this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
464
468
|
}
|
|
465
469
|
};
|
|
466
470
|
AWSAppSyncRealTimeProvider.prototype._handleIncomingSubscriptionMessage = function (message) {
|
|
467
|
-
|
|
471
|
+
if (message.data && message.data === '{"type":"ka"}') {
|
|
472
|
+
logger.verbose("subscription message from AWS AppSync RealTime: " + message.data);
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
logger.debug("subscription message from AWS AppSync RealTime: " + message.data);
|
|
476
|
+
}
|
|
468
477
|
var _a = JSON.parse(message.data), _b = _a.id, id = _b === void 0 ? '' : _b, payload = _a.payload, type = _a.type;
|
|
469
478
|
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;
|
|
470
|
-
|
|
479
|
+
if (!id && !observer && !query && Object.keys(variables).length === 0) {
|
|
480
|
+
logger.verbose({ id: id, observer: observer, query: query, variables: variables });
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
logger.debug({ id: id, observer: observer, query: query, variables: variables });
|
|
484
|
+
}
|
|
471
485
|
if (type === MESSAGE_TYPES.GQL_DATA && payload && payload.data) {
|
|
472
486
|
if (observer) {
|
|
473
487
|
observer.next(payload);
|
|
@@ -482,46 +496,53 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
482
496
|
if (typeof subscriptionReadyCallback === 'function') {
|
|
483
497
|
subscriptionReadyCallback();
|
|
484
498
|
}
|
|
485
|
-
|
|
499
|
+
if (startAckTimeoutId)
|
|
500
|
+
clearTimeout(startAckTimeoutId);
|
|
486
501
|
dispatchApiEvent(CONTROL_MSG.SUBSCRIPTION_ACK, { query: query, variables: variables }, 'Connection established for subscription');
|
|
487
502
|
var subscriptionState = SUBSCRIPTION_STATUS.CONNECTED;
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
503
|
+
if (observer) {
|
|
504
|
+
this.subscriptionObserverMap.set(id, {
|
|
505
|
+
observer: observer,
|
|
506
|
+
query: query,
|
|
507
|
+
variables: variables,
|
|
508
|
+
startAckTimeoutId: undefined,
|
|
509
|
+
subscriptionState: subscriptionState,
|
|
510
|
+
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
511
|
+
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
512
|
+
});
|
|
513
|
+
}
|
|
497
514
|
// TODO: emit event on hub but it requires to store the id first
|
|
498
515
|
return;
|
|
499
516
|
}
|
|
500
517
|
if (type === MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) {
|
|
501
|
-
|
|
518
|
+
if (this.keepAliveTimeoutId)
|
|
519
|
+
clearTimeout(this.keepAliveTimeoutId);
|
|
502
520
|
this.keepAliveTimeoutId = setTimeout(this._errorDisconnect.bind(this, CONTROL_MSG.TIMEOUT_DISCONNECT), this.keepAliveTimeout);
|
|
503
521
|
return;
|
|
504
522
|
}
|
|
505
523
|
if (type === MESSAGE_TYPES.GQL_ERROR) {
|
|
506
524
|
var subscriptionState = SUBSCRIPTION_STATUS.FAILED;
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
+
if (observer) {
|
|
526
|
+
this.subscriptionObserverMap.set(id, {
|
|
527
|
+
observer: observer,
|
|
528
|
+
query: query,
|
|
529
|
+
variables: variables,
|
|
530
|
+
startAckTimeoutId: startAckTimeoutId,
|
|
531
|
+
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
532
|
+
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
533
|
+
subscriptionState: subscriptionState,
|
|
534
|
+
});
|
|
535
|
+
observer.error({
|
|
536
|
+
errors: [
|
|
537
|
+
__assign({}, new GraphQLError(CONTROL_MSG.CONNECTION_FAILED + ": " + JSON.stringify(payload))),
|
|
538
|
+
],
|
|
539
|
+
});
|
|
540
|
+
if (startAckTimeoutId)
|
|
541
|
+
clearTimeout(startAckTimeoutId);
|
|
542
|
+
observer.complete();
|
|
543
|
+
if (typeof subscriptionFailedCallback === 'function') {
|
|
544
|
+
subscriptionFailedCallback();
|
|
545
|
+
}
|
|
525
546
|
}
|
|
526
547
|
}
|
|
527
548
|
};
|
|
@@ -542,29 +563,32 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
542
563
|
this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
543
564
|
};
|
|
544
565
|
AWSAppSyncRealTimeProvider.prototype._timeoutStartSubscriptionAck = function (subscriptionId) {
|
|
545
|
-
var
|
|
546
|
-
if (
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
observer.error({
|
|
557
|
-
errors: [
|
|
558
|
-
__assign({}, new GraphQLError("Subscription timeout " + JSON.stringify({
|
|
559
|
-
query: query,
|
|
560
|
-
variables: variables,
|
|
561
|
-
}))),
|
|
562
|
-
],
|
|
566
|
+
var subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
|
|
567
|
+
if (subscriptionObserver) {
|
|
568
|
+
var observer = subscriptionObserver.observer, query = subscriptionObserver.query, variables = subscriptionObserver.variables;
|
|
569
|
+
if (!observer) {
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
this.subscriptionObserverMap.set(subscriptionId, {
|
|
573
|
+
observer: observer,
|
|
574
|
+
query: query,
|
|
575
|
+
variables: variables,
|
|
576
|
+
subscriptionState: SUBSCRIPTION_STATUS.FAILED,
|
|
563
577
|
});
|
|
564
|
-
|
|
565
|
-
|
|
578
|
+
if (observer && !observer.closed) {
|
|
579
|
+
observer.error({
|
|
580
|
+
errors: [
|
|
581
|
+
__assign({}, new GraphQLError("Subscription timeout " + JSON.stringify({
|
|
582
|
+
query: query,
|
|
583
|
+
variables: variables,
|
|
584
|
+
}))),
|
|
585
|
+
],
|
|
586
|
+
});
|
|
587
|
+
// Cleanup will be automatically executed
|
|
588
|
+
observer.complete();
|
|
589
|
+
}
|
|
590
|
+
logger.debug('timeoutStartSubscription', JSON.stringify({ query: query, variables: variables }));
|
|
566
591
|
}
|
|
567
|
-
logger.debug('timeoutStartSubscription', JSON.stringify({ query: query, variables: variables }));
|
|
568
592
|
};
|
|
569
593
|
AWSAppSyncRealTimeProvider.prototype._initializeWebSocketConnection = function (_a) {
|
|
570
594
|
var _this = this;
|
|
@@ -598,19 +622,22 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
598
622
|
headerString = _b.apply(_a, [_c.sent()]);
|
|
599
623
|
headerQs = Buffer.from(headerString).toString('base64');
|
|
600
624
|
payloadQs = Buffer.from(payloadString).toString('base64');
|
|
601
|
-
discoverableEndpoint = appSyncGraphqlEndpoint;
|
|
625
|
+
discoverableEndpoint = appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '';
|
|
602
626
|
if (this.isCustomDomain(discoverableEndpoint)) {
|
|
603
|
-
discoverableEndpoint =
|
|
627
|
+
discoverableEndpoint =
|
|
628
|
+
discoverableEndpoint.concat(customDomainPath);
|
|
604
629
|
}
|
|
605
630
|
else {
|
|
606
|
-
discoverableEndpoint = discoverableEndpoint
|
|
631
|
+
discoverableEndpoint = discoverableEndpoint
|
|
632
|
+
.replace('appsync-api', 'appsync-realtime-api')
|
|
633
|
+
.replace('gogi-beta', 'grt-beta');
|
|
607
634
|
}
|
|
608
635
|
protocol = this.isSSLEnabled ? 'wss://' : 'ws://';
|
|
609
636
|
discoverableEndpoint = discoverableEndpoint
|
|
610
637
|
.replace('https://', protocol)
|
|
611
638
|
.replace('http://', protocol);
|
|
612
639
|
awsRealTimeUrl = discoverableEndpoint + "?header=" + headerQs + "&payload=" + payloadQs;
|
|
613
|
-
return [4 /*yield*/, this._initializeRetryableHandshake(
|
|
640
|
+
return [4 /*yield*/, this._initializeRetryableHandshake(awsRealTimeUrl)];
|
|
614
641
|
case 3:
|
|
615
642
|
_c.sent();
|
|
616
643
|
this.promiseArray.forEach(function (_a) {
|
|
@@ -632,7 +659,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
632
659
|
this.awsRealTimeSocket.readyState === WebSocket.OPEN) {
|
|
633
660
|
this.awsRealTimeSocket.close(3001);
|
|
634
661
|
}
|
|
635
|
-
this.awsRealTimeSocket =
|
|
662
|
+
this.awsRealTimeSocket = undefined;
|
|
636
663
|
this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
637
664
|
return [3 /*break*/, 5];
|
|
638
665
|
case 5: return [2 /*return*/];
|
|
@@ -640,25 +667,23 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
640
667
|
});
|
|
641
668
|
}); });
|
|
642
669
|
};
|
|
643
|
-
AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (
|
|
644
|
-
var awsRealTimeUrl = _a.awsRealTimeUrl;
|
|
670
|
+
AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (awsRealTimeUrl) {
|
|
645
671
|
return __awaiter(this, void 0, void 0, function () {
|
|
646
|
-
return __generator(this, function (
|
|
647
|
-
switch (
|
|
672
|
+
return __generator(this, function (_a) {
|
|
673
|
+
switch (_a.label) {
|
|
648
674
|
case 0:
|
|
649
675
|
logger.debug("Initializaling retryable Handshake");
|
|
650
|
-
return [4 /*yield*/, jitteredExponentialRetry(this._initializeHandshake.bind(this), [
|
|
676
|
+
return [4 /*yield*/, jitteredExponentialRetry(this._initializeHandshake.bind(this), [awsRealTimeUrl], MAX_DELAY_MS)];
|
|
651
677
|
case 1:
|
|
652
|
-
|
|
678
|
+
_a.sent();
|
|
653
679
|
return [2 /*return*/];
|
|
654
680
|
}
|
|
655
681
|
});
|
|
656
682
|
});
|
|
657
683
|
};
|
|
658
|
-
AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (
|
|
659
|
-
var awsRealTimeUrl = _a.awsRealTimeUrl;
|
|
684
|
+
AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (awsRealTimeUrl) {
|
|
660
685
|
return __awaiter(this, void 0, void 0, function () {
|
|
661
|
-
var err_4, errorType, errorCode;
|
|
686
|
+
var err_4, _a, errorType, errorCode;
|
|
662
687
|
var _this = this;
|
|
663
688
|
return __generator(this, function (_b) {
|
|
664
689
|
switch (_b.label) {
|
|
@@ -687,48 +712,53 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
687
712
|
// Step 2: wait for ack from AWS AppSyncReaTime after sending init
|
|
688
713
|
return [4 /*yield*/, (function () {
|
|
689
714
|
return new Promise(function (res, rej) {
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
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
|
-
|
|
715
|
+
if (_this.awsRealTimeSocket) {
|
|
716
|
+
var ackOk_1 = false;
|
|
717
|
+
_this.awsRealTimeSocket.onerror = function (error) {
|
|
718
|
+
logger.debug("WebSocket error " + JSON.stringify(error));
|
|
719
|
+
};
|
|
720
|
+
_this.awsRealTimeSocket.onclose = function (event) {
|
|
721
|
+
logger.debug("WebSocket closed " + event.reason);
|
|
722
|
+
rej(new Error(JSON.stringify(event)));
|
|
723
|
+
};
|
|
724
|
+
_this.awsRealTimeSocket.onmessage = function (message) {
|
|
725
|
+
logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
|
|
726
|
+
var data = JSON.parse(message.data);
|
|
727
|
+
var type = data.type, _a = data.payload, _b = (_a === void 0 ? {} : _a).connectionTimeoutMs, connectionTimeoutMs = _b === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _b;
|
|
728
|
+
if (type === MESSAGE_TYPES.GQL_CONNECTION_ACK) {
|
|
729
|
+
ackOk_1 = true;
|
|
730
|
+
if (_this.awsRealTimeSocket) {
|
|
731
|
+
_this.keepAliveTimeout = connectionTimeoutMs;
|
|
732
|
+
_this.awsRealTimeSocket.onmessage =
|
|
733
|
+
_this._handleIncomingSubscriptionMessage.bind(_this);
|
|
734
|
+
_this.awsRealTimeSocket.onerror = function (err) {
|
|
735
|
+
logger.debug(err);
|
|
736
|
+
_this._errorDisconnect(CONTROL_MSG.CONNECTION_CLOSED);
|
|
737
|
+
};
|
|
738
|
+
_this.awsRealTimeSocket.onclose = function (event) {
|
|
739
|
+
logger.debug("WebSocket closed " + event.reason);
|
|
740
|
+
_this._errorDisconnect(CONTROL_MSG.CONNECTION_CLOSED);
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
res('Cool, connected to AWS AppSyncRealTime');
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
if (type === MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
|
|
747
|
+
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;
|
|
748
|
+
rej({ errorType: errorType, errorCode: errorCode });
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
var gqlInit = {
|
|
752
|
+
type: MESSAGE_TYPES.GQL_CONNECTION_INIT,
|
|
753
|
+
};
|
|
754
|
+
_this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
|
|
755
|
+
setTimeout(checkAckOk.bind(_this, ackOk_1), CONNECTION_INIT_TIMEOUT);
|
|
756
|
+
}
|
|
757
|
+
function checkAckOk(ackOk) {
|
|
727
758
|
if (!ackOk) {
|
|
728
759
|
rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + CONNECTION_INIT_TIMEOUT + " ms"));
|
|
729
760
|
}
|
|
730
761
|
}
|
|
731
|
-
setTimeout(checkAckOk.bind(_this), CONNECTION_INIT_TIMEOUT);
|
|
732
762
|
});
|
|
733
763
|
})()];
|
|
734
764
|
case 3:
|
|
@@ -737,7 +767,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
737
767
|
return [3 /*break*/, 5];
|
|
738
768
|
case 4:
|
|
739
769
|
err_4 = _b.sent();
|
|
740
|
-
errorType =
|
|
770
|
+
_a = err_4, errorType = _a.errorType, errorCode = _a.errorCode;
|
|
741
771
|
if (NON_RETRYABLE_CODES.includes(errorCode)) {
|
|
742
772
|
throw new NonRetryableError(errorType);
|
|
743
773
|
}
|
|
@@ -767,12 +797,12 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
767
797
|
AMAZON_COGNITO_USER_POOLS: this._awsRealTimeCUPHeader.bind(this),
|
|
768
798
|
AWS_LAMBDA: this._customAuthHeader,
|
|
769
799
|
};
|
|
800
|
+
if (!(!authenticationType || !headerHandler[authenticationType])) return [3 /*break*/, 1];
|
|
801
|
+
logger.debug("Authentication type " + authenticationType + " not supported");
|
|
802
|
+
return [2 /*return*/, ''];
|
|
803
|
+
case 1:
|
|
770
804
|
handler = headerHandler[authenticationType];
|
|
771
|
-
|
|
772
|
-
logger.debug("Authentication type " + authenticationType + " not supported");
|
|
773
|
-
return [2 /*return*/, ''];
|
|
774
|
-
}
|
|
775
|
-
host = url.parse(appSyncGraphqlEndpoint).host;
|
|
805
|
+
host = url.parse(appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
|
|
776
806
|
return [4 /*yield*/, handler({
|
|
777
807
|
payload: payload,
|
|
778
808
|
canonicalUri: canonicalUri,
|
|
@@ -782,7 +812,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
782
812
|
host: host,
|
|
783
813
|
additionalHeaders: additionalHeaders,
|
|
784
814
|
})];
|
|
785
|
-
case
|
|
815
|
+
case 2:
|
|
786
816
|
result = _b.sent();
|
|
787
817
|
return [2 /*return*/, result];
|
|
788
818
|
}
|
|
@@ -869,11 +899,14 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
869
899
|
if (!credentialsOK) {
|
|
870
900
|
throw new Error('No credentials');
|
|
871
901
|
}
|
|
872
|
-
return [4 /*yield*/, Credentials.get().then(function (credentials) {
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
902
|
+
return [4 /*yield*/, Credentials.get().then(function (credentials) {
|
|
903
|
+
var _a = credentials, secretAccessKey = _a.secretAccessKey, accessKeyId = _a.accessKeyId, sessionToken = _a.sessionToken;
|
|
904
|
+
return {
|
|
905
|
+
secret_key: secretAccessKey,
|
|
906
|
+
access_key: accessKeyId,
|
|
907
|
+
session_token: sessionToken,
|
|
908
|
+
};
|
|
909
|
+
})];
|
|
877
910
|
case 2:
|
|
878
911
|
creds = _b.sent();
|
|
879
912
|
request = {
|
|
@@ -890,7 +923,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function (_super) {
|
|
|
890
923
|
};
|
|
891
924
|
AWSAppSyncRealTimeProvider.prototype._customAuthHeader = function (_a) {
|
|
892
925
|
var host = _a.host, additionalHeaders = _a.additionalHeaders;
|
|
893
|
-
if (!additionalHeaders
|
|
926
|
+
if (!additionalHeaders || !additionalHeaders['Authorization']) {
|
|
894
927
|
throw new Error('No auth token specified');
|
|
895
928
|
}
|
|
896
929
|
return {
|