@aws-amplify/api-graphql 2.3.1 → 2.3.2-unstable.5
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.
|
@@ -11527,9 +11527,9 @@ function (_super) {
|
|
|
11527
11527
|
AWSAppSyncRealTimeProvider.prototype.subscribe = function (_topics, options) {
|
|
11528
11528
|
var _this = this;
|
|
11529
11529
|
|
|
11530
|
-
var appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint;
|
|
11530
|
+
var appSyncGraphqlEndpoint = options === null || options === void 0 ? void 0 : options.appSyncGraphqlEndpoint;
|
|
11531
11531
|
return new zen_observable_ts__WEBPACK_IMPORTED_MODULE_0__["default"](function (observer) {
|
|
11532
|
-
if (!appSyncGraphqlEndpoint) {
|
|
11532
|
+
if (!options || !appSyncGraphqlEndpoint) {
|
|
11533
11533
|
observer.error({
|
|
11534
11534
|
errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscribe only available for AWS AppSync endpoint"))]
|
|
11535
11535
|
});
|
|
@@ -11622,19 +11622,22 @@ function (_super) {
|
|
|
11622
11622
|
var options = _a.options,
|
|
11623
11623
|
observer = _a.observer,
|
|
11624
11624
|
subscriptionId = _a.subscriptionId;
|
|
11625
|
+
|
|
11626
|
+
var _b, _c;
|
|
11627
|
+
|
|
11625
11628
|
return __awaiter(this, void 0, void 0, function () {
|
|
11626
|
-
var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region,
|
|
11629
|
+
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;
|
|
11627
11630
|
|
|
11628
|
-
var
|
|
11631
|
+
var _j;
|
|
11629
11632
|
|
|
11630
11633
|
var _this = this;
|
|
11631
11634
|
|
|
11632
|
-
return __generator(this, function (
|
|
11633
|
-
switch (
|
|
11635
|
+
return __generator(this, function (_k) {
|
|
11636
|
+
switch (_k.label) {
|
|
11634
11637
|
case 0:
|
|
11635
|
-
appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint, authenticationType = options.authenticationType, query = options.query, variables = options.variables, apiKey = options.apiKey, region = options.region,
|
|
11638
|
+
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 () {
|
|
11636
11639
|
return {};
|
|
11637
|
-
} :
|
|
11640
|
+
} : _d, _e = options.additionalHeaders, additionalHeaders = _e === void 0 ? {} : _e;
|
|
11638
11641
|
subscriptionState = SUBSCRIPTION_STATUS.PENDING;
|
|
11639
11642
|
data = {
|
|
11640
11643
|
query: query,
|
|
@@ -11643,13 +11646,13 @@ function (_super) {
|
|
|
11643
11646
|
|
|
11644
11647
|
this.subscriptionObserverMap.set(subscriptionId, {
|
|
11645
11648
|
observer: observer,
|
|
11646
|
-
query: query,
|
|
11647
|
-
variables: variables,
|
|
11649
|
+
query: query !== null && query !== void 0 ? query : '',
|
|
11650
|
+
variables: variables !== null && variables !== void 0 ? variables : {},
|
|
11648
11651
|
subscriptionState: subscriptionState,
|
|
11649
|
-
startAckTimeoutId:
|
|
11652
|
+
startAckTimeoutId: undefined
|
|
11650
11653
|
});
|
|
11651
11654
|
dataString = JSON.stringify(data);
|
|
11652
|
-
|
|
11655
|
+
_f = [{}];
|
|
11653
11656
|
return [4
|
|
11654
11657
|
/*yield*/
|
|
11655
11658
|
, this._awsRealTimeHeaderBasedAuth({
|
|
@@ -11663,13 +11666,13 @@ function (_super) {
|
|
|
11663
11666
|
})];
|
|
11664
11667
|
|
|
11665
11668
|
case 1:
|
|
11666
|
-
|
|
11669
|
+
_g = [__assign.apply(void 0, _f.concat([_k.sent()]))];
|
|
11667
11670
|
return [4
|
|
11668
11671
|
/*yield*/
|
|
11669
11672
|
, graphql_headers()];
|
|
11670
11673
|
|
|
11671
11674
|
case 2:
|
|
11672
|
-
headerObj = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0,
|
|
11675
|
+
headerObj = __assign.apply(void 0, [__assign.apply(void 0, [__assign.apply(void 0, _g.concat([_k.sent()])), additionalHeaders]), (_j = {}, _j[_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["USER_AGENT_HEADER"]] = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Constants"].userAgent, _j)]);
|
|
11673
11676
|
subscriptionMessage = {
|
|
11674
11677
|
id: subscriptionId,
|
|
11675
11678
|
payload: {
|
|
@@ -11681,10 +11684,10 @@ function (_super) {
|
|
|
11681
11684
|
type: MESSAGE_TYPES.GQL_START
|
|
11682
11685
|
};
|
|
11683
11686
|
stringToAWSRealTime = JSON.stringify(subscriptionMessage);
|
|
11684
|
-
|
|
11687
|
+
_k.label = 3;
|
|
11685
11688
|
|
|
11686
11689
|
case 3:
|
|
11687
|
-
|
|
11690
|
+
_k.trys.push([3, 5,, 6]);
|
|
11688
11691
|
|
|
11689
11692
|
return [4
|
|
11690
11693
|
/*yield*/
|
|
@@ -11697,18 +11700,18 @@ function (_super) {
|
|
|
11697
11700
|
})];
|
|
11698
11701
|
|
|
11699
11702
|
case 4:
|
|
11700
|
-
|
|
11703
|
+
_k.sent();
|
|
11701
11704
|
|
|
11702
11705
|
return [3
|
|
11703
11706
|
/*break*/
|
|
11704
11707
|
, 6];
|
|
11705
11708
|
|
|
11706
11709
|
case 5:
|
|
11707
|
-
err_2 =
|
|
11710
|
+
err_2 = _k.sent();
|
|
11708
11711
|
logger.debug({
|
|
11709
11712
|
err: err_2
|
|
11710
11713
|
});
|
|
11711
|
-
|
|
11714
|
+
message = (_b = err_2['message']) !== null && _b !== void 0 ? _b : '';
|
|
11712
11715
|
observer.error({
|
|
11713
11716
|
errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + message))]
|
|
11714
11717
|
});
|
|
@@ -11724,13 +11727,13 @@ function (_super) {
|
|
|
11724
11727
|
];
|
|
11725
11728
|
|
|
11726
11729
|
case 6:
|
|
11727
|
-
|
|
11730
|
+
_h = (_c = this.subscriptionObserverMap.get(subscriptionId)) !== null && _c !== void 0 ? _c : {}, subscriptionFailedCallback = _h.subscriptionFailedCallback, subscriptionReadyCallback = _h.subscriptionReadyCallback; // This must be done before sending the message in order to be listening immediately
|
|
11728
11731
|
|
|
11729
11732
|
this.subscriptionObserverMap.set(subscriptionId, {
|
|
11730
11733
|
observer: observer,
|
|
11731
11734
|
subscriptionState: subscriptionState,
|
|
11732
|
-
|
|
11733
|
-
|
|
11735
|
+
query: query !== null && query !== void 0 ? query : '',
|
|
11736
|
+
variables: variables !== null && variables !== void 0 ? variables : {},
|
|
11734
11737
|
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
11735
11738
|
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
11736
11739
|
startAckTimeoutId: setTimeout(function () {
|
|
@@ -11753,32 +11756,35 @@ function (_super) {
|
|
|
11753
11756
|
|
|
11754
11757
|
AWSAppSyncRealTimeProvider.prototype._waitForSubscriptionToBeConnected = function (subscriptionId) {
|
|
11755
11758
|
return __awaiter(this, void 0, void 0, function () {
|
|
11756
|
-
var subscriptionState;
|
|
11759
|
+
var subscriptionObserver, subscriptionState;
|
|
11757
11760
|
|
|
11758
11761
|
var _this = this;
|
|
11759
11762
|
|
|
11760
11763
|
return __generator(this, function (_a) {
|
|
11761
|
-
|
|
11764
|
+
subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
|
|
11762
11765
|
|
|
11763
|
-
if (
|
|
11764
|
-
|
|
11765
|
-
|
|
11766
|
-
|
|
11767
|
-
|
|
11768
|
-
|
|
11769
|
-
|
|
11770
|
-
|
|
11771
|
-
|
|
11772
|
-
|
|
11773
|
-
|
|
11774
|
-
|
|
11775
|
-
|
|
11776
|
-
|
|
11777
|
-
|
|
11778
|
-
|
|
11779
|
-
|
|
11780
|
-
|
|
11781
|
-
|
|
11766
|
+
if (subscriptionObserver) {
|
|
11767
|
+
subscriptionState = subscriptionObserver.subscriptionState; // This in case unsubscribe is invoked before sending start subscription message
|
|
11768
|
+
|
|
11769
|
+
if (subscriptionState === SUBSCRIPTION_STATUS.PENDING) {
|
|
11770
|
+
return [2
|
|
11771
|
+
/*return*/
|
|
11772
|
+
, new Promise(function (res, rej) {
|
|
11773
|
+
var observer = subscriptionObserver.observer,
|
|
11774
|
+
subscriptionState = subscriptionObserver.subscriptionState,
|
|
11775
|
+
variables = subscriptionObserver.variables,
|
|
11776
|
+
query = subscriptionObserver.query;
|
|
11777
|
+
|
|
11778
|
+
_this.subscriptionObserverMap.set(subscriptionId, {
|
|
11779
|
+
observer: observer,
|
|
11780
|
+
subscriptionState: subscriptionState,
|
|
11781
|
+
variables: variables,
|
|
11782
|
+
query: query,
|
|
11783
|
+
subscriptionReadyCallback: res,
|
|
11784
|
+
subscriptionFailedCallback: rej
|
|
11785
|
+
});
|
|
11786
|
+
})];
|
|
11787
|
+
}
|
|
11782
11788
|
}
|
|
11783
11789
|
|
|
11784
11790
|
return [2
|
|
@@ -11829,13 +11835,13 @@ function (_super) {
|
|
|
11829
11835
|
setTimeout(this._closeSocketIfRequired.bind(this), 1000);
|
|
11830
11836
|
} else {
|
|
11831
11837
|
logger.debug('closing WebSocket...');
|
|
11832
|
-
clearTimeout(this.keepAliveTimeoutId);
|
|
11838
|
+
if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
|
|
11833
11839
|
var tempSocket = this.awsRealTimeSocket; // Cleaning callbacks to avoid race condition, socket still exists
|
|
11834
11840
|
|
|
11835
|
-
tempSocket.onclose =
|
|
11836
|
-
tempSocket.onerror =
|
|
11841
|
+
tempSocket.onclose = null;
|
|
11842
|
+
tempSocket.onerror = null;
|
|
11837
11843
|
tempSocket.close(1000);
|
|
11838
|
-
this.awsRealTimeSocket =
|
|
11844
|
+
this.awsRealTimeSocket = undefined;
|
|
11839
11845
|
this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
11840
11846
|
}
|
|
11841
11847
|
};
|
|
@@ -11887,50 +11893,57 @@ function (_super) {
|
|
|
11887
11893
|
subscriptionReadyCallback();
|
|
11888
11894
|
}
|
|
11889
11895
|
|
|
11890
|
-
clearTimeout(startAckTimeoutId);
|
|
11896
|
+
if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
|
|
11891
11897
|
dispatchApiEvent(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].SUBSCRIPTION_ACK, {
|
|
11892
11898
|
query: query,
|
|
11893
11899
|
variables: variables
|
|
11894
11900
|
}, 'Connection established for subscription');
|
|
11895
11901
|
var subscriptionState = SUBSCRIPTION_STATUS.CONNECTED;
|
|
11896
|
-
|
|
11897
|
-
|
|
11898
|
-
|
|
11899
|
-
|
|
11900
|
-
|
|
11901
|
-
|
|
11902
|
-
|
|
11903
|
-
|
|
11904
|
-
|
|
11902
|
+
|
|
11903
|
+
if (observer) {
|
|
11904
|
+
this.subscriptionObserverMap.set(id, {
|
|
11905
|
+
observer: observer,
|
|
11906
|
+
query: query,
|
|
11907
|
+
variables: variables,
|
|
11908
|
+
startAckTimeoutId: undefined,
|
|
11909
|
+
subscriptionState: subscriptionState,
|
|
11910
|
+
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
11911
|
+
subscriptionFailedCallback: subscriptionFailedCallback
|
|
11912
|
+
});
|
|
11913
|
+
} // TODO: emit event on hub but it requires to store the id first
|
|
11914
|
+
|
|
11905
11915
|
|
|
11906
11916
|
return;
|
|
11907
11917
|
}
|
|
11908
11918
|
|
|
11909
11919
|
if (type === MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) {
|
|
11910
|
-
clearTimeout(this.keepAliveTimeoutId);
|
|
11920
|
+
if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId);
|
|
11911
11921
|
this.keepAliveTimeoutId = setTimeout(this._errorDisconnect.bind(this, _index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].TIMEOUT_DISCONNECT), this.keepAliveTimeout);
|
|
11912
11922
|
return;
|
|
11913
11923
|
}
|
|
11914
11924
|
|
|
11915
11925
|
if (type === MESSAGE_TYPES.GQL_ERROR) {
|
|
11916
11926
|
var subscriptionState = SUBSCRIPTION_STATUS.FAILED;
|
|
11917
|
-
this.subscriptionObserverMap.set(id, {
|
|
11918
|
-
observer: observer,
|
|
11919
|
-
query: query,
|
|
11920
|
-
variables: variables,
|
|
11921
|
-
startAckTimeoutId: startAckTimeoutId,
|
|
11922
|
-
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
11923
|
-
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
11924
|
-
subscriptionState: subscriptionState
|
|
11925
|
-
});
|
|
11926
|
-
observer.error({
|
|
11927
|
-
errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
|
|
11928
|
-
});
|
|
11929
|
-
clearTimeout(startAckTimeoutId);
|
|
11930
|
-
observer.complete();
|
|
11931
11927
|
|
|
11932
|
-
if (
|
|
11933
|
-
|
|
11928
|
+
if (observer) {
|
|
11929
|
+
this.subscriptionObserverMap.set(id, {
|
|
11930
|
+
observer: observer,
|
|
11931
|
+
query: query,
|
|
11932
|
+
variables: variables,
|
|
11933
|
+
startAckTimeoutId: startAckTimeoutId,
|
|
11934
|
+
subscriptionReadyCallback: subscriptionReadyCallback,
|
|
11935
|
+
subscriptionFailedCallback: subscriptionFailedCallback,
|
|
11936
|
+
subscriptionState: subscriptionState
|
|
11937
|
+
});
|
|
11938
|
+
observer.error({
|
|
11939
|
+
errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"](_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_FAILED + ": " + JSON.stringify(payload)))]
|
|
11940
|
+
});
|
|
11941
|
+
if (startAckTimeoutId) clearTimeout(startAckTimeoutId);
|
|
11942
|
+
observer.complete();
|
|
11943
|
+
|
|
11944
|
+
if (typeof subscriptionFailedCallback === 'function') {
|
|
11945
|
+
subscriptionFailedCallback();
|
|
11946
|
+
}
|
|
11934
11947
|
}
|
|
11935
11948
|
}
|
|
11936
11949
|
};
|
|
@@ -11956,37 +11969,40 @@ function (_super) {
|
|
|
11956
11969
|
};
|
|
11957
11970
|
|
|
11958
11971
|
AWSAppSyncRealTimeProvider.prototype._timeoutStartSubscriptionAck = function (subscriptionId) {
|
|
11959
|
-
var
|
|
11960
|
-
observer = _a.observer,
|
|
11961
|
-
query = _a.query,
|
|
11962
|
-
variables = _a.variables;
|
|
11972
|
+
var subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId);
|
|
11963
11973
|
|
|
11964
|
-
if (
|
|
11965
|
-
|
|
11966
|
-
|
|
11974
|
+
if (subscriptionObserver) {
|
|
11975
|
+
var observer = subscriptionObserver.observer,
|
|
11976
|
+
query = subscriptionObserver.query,
|
|
11977
|
+
variables = subscriptionObserver.variables;
|
|
11967
11978
|
|
|
11968
|
-
|
|
11969
|
-
|
|
11970
|
-
|
|
11971
|
-
variables: variables,
|
|
11972
|
-
subscriptionState: SUBSCRIPTION_STATUS.FAILED
|
|
11973
|
-
});
|
|
11979
|
+
if (!observer) {
|
|
11980
|
+
return;
|
|
11981
|
+
}
|
|
11974
11982
|
|
|
11975
|
-
|
|
11976
|
-
|
|
11977
|
-
|
|
11978
|
-
|
|
11979
|
-
|
|
11980
|
-
|
|
11981
|
-
}); // Cleanup will be automatically executed
|
|
11983
|
+
this.subscriptionObserverMap.set(subscriptionId, {
|
|
11984
|
+
observer: observer,
|
|
11985
|
+
query: query,
|
|
11986
|
+
variables: variables,
|
|
11987
|
+
subscriptionState: SUBSCRIPTION_STATUS.FAILED
|
|
11988
|
+
});
|
|
11982
11989
|
|
|
11983
|
-
observer.
|
|
11984
|
-
|
|
11990
|
+
if (observer && !observer.closed) {
|
|
11991
|
+
observer.error({
|
|
11992
|
+
errors: [__assign({}, new graphql__WEBPACK_IMPORTED_MODULE_1__["GraphQLError"]("Subscription timeout " + JSON.stringify({
|
|
11993
|
+
query: query,
|
|
11994
|
+
variables: variables
|
|
11995
|
+
})))]
|
|
11996
|
+
}); // Cleanup will be automatically executed
|
|
11985
11997
|
|
|
11986
|
-
|
|
11987
|
-
|
|
11988
|
-
|
|
11989
|
-
|
|
11998
|
+
observer.complete();
|
|
11999
|
+
}
|
|
12000
|
+
|
|
12001
|
+
logger.debug('timeoutStartSubscription', JSON.stringify({
|
|
12002
|
+
query: query,
|
|
12003
|
+
variables: variables
|
|
12004
|
+
}));
|
|
12005
|
+
}
|
|
11990
12006
|
};
|
|
11991
12007
|
|
|
11992
12008
|
AWSAppSyncRealTimeProvider.prototype._initializeWebSocketConnection = function (_a) {
|
|
@@ -12040,7 +12056,7 @@ function (_super) {
|
|
|
12040
12056
|
headerString = _b.apply(_a, [_c.sent()]);
|
|
12041
12057
|
headerQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(headerString).toString('base64');
|
|
12042
12058
|
payloadQs = buffer__WEBPACK_IMPORTED_MODULE_4__["Buffer"].from(payloadString).toString('base64');
|
|
12043
|
-
discoverableEndpoint = appSyncGraphqlEndpoint;
|
|
12059
|
+
discoverableEndpoint = appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '';
|
|
12044
12060
|
|
|
12045
12061
|
if (this.isCustomDomain(discoverableEndpoint)) {
|
|
12046
12062
|
discoverableEndpoint = discoverableEndpoint.concat(customDomainPath);
|
|
@@ -12053,9 +12069,7 @@ function (_super) {
|
|
|
12053
12069
|
awsRealTimeUrl = discoverableEndpoint + "?header=" + headerQs + "&payload=" + payloadQs;
|
|
12054
12070
|
return [4
|
|
12055
12071
|
/*yield*/
|
|
12056
|
-
, this._initializeRetryableHandshake(
|
|
12057
|
-
awsRealTimeUrl: awsRealTimeUrl
|
|
12058
|
-
})];
|
|
12072
|
+
, this._initializeRetryableHandshake(awsRealTimeUrl)];
|
|
12059
12073
|
|
|
12060
12074
|
case 3:
|
|
12061
12075
|
_c.sent();
|
|
@@ -12083,7 +12097,7 @@ function (_super) {
|
|
|
12083
12097
|
this.awsRealTimeSocket.close(3001);
|
|
12084
12098
|
}
|
|
12085
12099
|
|
|
12086
|
-
this.awsRealTimeSocket =
|
|
12100
|
+
this.awsRealTimeSocket = undefined;
|
|
12087
12101
|
this.socketStatus = SOCKET_STATUS.CLOSED;
|
|
12088
12102
|
return [3
|
|
12089
12103
|
/*break*/
|
|
@@ -12099,21 +12113,18 @@ function (_super) {
|
|
|
12099
12113
|
});
|
|
12100
12114
|
};
|
|
12101
12115
|
|
|
12102
|
-
AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (
|
|
12103
|
-
var awsRealTimeUrl = _a.awsRealTimeUrl;
|
|
12116
|
+
AWSAppSyncRealTimeProvider.prototype._initializeRetryableHandshake = function (awsRealTimeUrl) {
|
|
12104
12117
|
return __awaiter(this, void 0, void 0, function () {
|
|
12105
|
-
return __generator(this, function (
|
|
12106
|
-
switch (
|
|
12118
|
+
return __generator(this, function (_a) {
|
|
12119
|
+
switch (_a.label) {
|
|
12107
12120
|
case 0:
|
|
12108
12121
|
logger.debug("Initializaling retryable Handshake");
|
|
12109
12122
|
return [4
|
|
12110
12123
|
/*yield*/
|
|
12111
|
-
, Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [
|
|
12112
|
-
awsRealTimeUrl: awsRealTimeUrl
|
|
12113
|
-
}], MAX_DELAY_MS)];
|
|
12124
|
+
, Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["jitteredExponentialRetry"])(this._initializeHandshake.bind(this), [awsRealTimeUrl], MAX_DELAY_MS)];
|
|
12114
12125
|
|
|
12115
12126
|
case 1:
|
|
12116
|
-
|
|
12127
|
+
_a.sent();
|
|
12117
12128
|
|
|
12118
12129
|
return [2
|
|
12119
12130
|
/*return*/
|
|
@@ -12123,10 +12134,9 @@ function (_super) {
|
|
|
12123
12134
|
});
|
|
12124
12135
|
};
|
|
12125
12136
|
|
|
12126
|
-
AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (
|
|
12127
|
-
var awsRealTimeUrl = _a.awsRealTimeUrl;
|
|
12137
|
+
AWSAppSyncRealTimeProvider.prototype._initializeHandshake = function (awsRealTimeUrl) {
|
|
12128
12138
|
return __awaiter(this, void 0, void 0, function () {
|
|
12129
|
-
var err_4, errorType, errorCode;
|
|
12139
|
+
var err_4, _a, errorType, errorCode;
|
|
12130
12140
|
|
|
12131
12141
|
var _this = this;
|
|
12132
12142
|
|
|
@@ -12168,77 +12178,82 @@ function (_super) {
|
|
|
12168
12178
|
/*yield*/
|
|
12169
12179
|
, function () {
|
|
12170
12180
|
return new Promise(function (res, rej) {
|
|
12171
|
-
|
|
12181
|
+
if (_this.awsRealTimeSocket) {
|
|
12182
|
+
var ackOk_1 = false;
|
|
12172
12183
|
|
|
12173
|
-
|
|
12174
|
-
|
|
12175
|
-
|
|
12184
|
+
_this.awsRealTimeSocket.onerror = function (error) {
|
|
12185
|
+
logger.debug("WebSocket error " + JSON.stringify(error));
|
|
12186
|
+
};
|
|
12176
12187
|
|
|
12177
|
-
|
|
12178
|
-
|
|
12179
|
-
|
|
12180
|
-
|
|
12188
|
+
_this.awsRealTimeSocket.onclose = function (event) {
|
|
12189
|
+
logger.debug("WebSocket closed " + event.reason);
|
|
12190
|
+
rej(new Error(JSON.stringify(event)));
|
|
12191
|
+
};
|
|
12181
12192
|
|
|
12182
|
-
|
|
12183
|
-
|
|
12184
|
-
|
|
12185
|
-
|
|
12186
|
-
|
|
12187
|
-
|
|
12188
|
-
|
|
12193
|
+
_this.awsRealTimeSocket.onmessage = function (message) {
|
|
12194
|
+
logger.debug("subscription message from AWS AppSyncRealTime: " + message.data + " ");
|
|
12195
|
+
var data = JSON.parse(message.data);
|
|
12196
|
+
var type = data.type,
|
|
12197
|
+
_a = data.payload,
|
|
12198
|
+
_b = (_a === void 0 ? {} : _a).connectionTimeoutMs,
|
|
12199
|
+
connectionTimeoutMs = _b === void 0 ? DEFAULT_KEEP_ALIVE_TIMEOUT : _b;
|
|
12189
12200
|
|
|
12190
|
-
|
|
12191
|
-
|
|
12192
|
-
_this.keepAliveTimeout = connectionTimeoutMs;
|
|
12193
|
-
_this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
|
|
12201
|
+
if (type === MESSAGE_TYPES.GQL_CONNECTION_ACK) {
|
|
12202
|
+
ackOk_1 = true;
|
|
12194
12203
|
|
|
12195
|
-
|
|
12196
|
-
|
|
12204
|
+
if (_this.awsRealTimeSocket) {
|
|
12205
|
+
_this.keepAliveTimeout = connectionTimeoutMs;
|
|
12206
|
+
_this.awsRealTimeSocket.onmessage = _this._handleIncomingSubscriptionMessage.bind(_this);
|
|
12197
12207
|
|
|
12198
|
-
|
|
12199
|
-
|
|
12208
|
+
_this.awsRealTimeSocket.onerror = function (err) {
|
|
12209
|
+
logger.debug(err);
|
|
12200
12210
|
|
|
12201
|
-
|
|
12202
|
-
|
|
12211
|
+
_this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
|
|
12212
|
+
};
|
|
12203
12213
|
|
|
12204
|
-
|
|
12205
|
-
|
|
12214
|
+
_this.awsRealTimeSocket.onclose = function (event) {
|
|
12215
|
+
logger.debug("WebSocket closed " + event.reason);
|
|
12206
12216
|
|
|
12207
|
-
|
|
12208
|
-
|
|
12209
|
-
|
|
12217
|
+
_this._errorDisconnect(_index__WEBPACK_IMPORTED_MODULE_9__["CONTROL_MSG"].CONNECTION_CLOSED);
|
|
12218
|
+
};
|
|
12219
|
+
}
|
|
12210
12220
|
|
|
12211
|
-
|
|
12212
|
-
|
|
12213
|
-
|
|
12214
|
-
_e = __read(_d === void 0 ? [] : _d, 1),
|
|
12215
|
-
_f = _e[0],
|
|
12216
|
-
_g = _f === void 0 ? {} : _f,
|
|
12217
|
-
_h = _g.errorType,
|
|
12218
|
-
errorType = _h === void 0 ? '' : _h,
|
|
12219
|
-
_j = _g.errorCode,
|
|
12220
|
-
errorCode = _j === void 0 ? 0 : _j;
|
|
12221
|
-
|
|
12222
|
-
rej({
|
|
12223
|
-
errorType: errorType,
|
|
12224
|
-
errorCode: errorCode
|
|
12225
|
-
});
|
|
12226
|
-
}
|
|
12227
|
-
};
|
|
12221
|
+
res('Cool, connected to AWS AppSyncRealTime');
|
|
12222
|
+
return;
|
|
12223
|
+
}
|
|
12228
12224
|
|
|
12229
|
-
|
|
12230
|
-
|
|
12231
|
-
|
|
12225
|
+
if (type === MESSAGE_TYPES.GQL_CONNECTION_ERROR) {
|
|
12226
|
+
var _c = data.payload,
|
|
12227
|
+
_d = (_c === void 0 ? {} : _c).errors,
|
|
12228
|
+
_e = __read(_d === void 0 ? [] : _d, 1),
|
|
12229
|
+
_f = _e[0],
|
|
12230
|
+
_g = _f === void 0 ? {} : _f,
|
|
12231
|
+
_h = _g.errorType,
|
|
12232
|
+
errorType = _h === void 0 ? '' : _h,
|
|
12233
|
+
_j = _g.errorCode,
|
|
12234
|
+
errorCode = _j === void 0 ? 0 : _j;
|
|
12235
|
+
|
|
12236
|
+
rej({
|
|
12237
|
+
errorType: errorType,
|
|
12238
|
+
errorCode: errorCode
|
|
12239
|
+
});
|
|
12240
|
+
}
|
|
12241
|
+
};
|
|
12232
12242
|
|
|
12233
|
-
|
|
12243
|
+
var gqlInit = {
|
|
12244
|
+
type: MESSAGE_TYPES.GQL_CONNECTION_INIT
|
|
12245
|
+
};
|
|
12234
12246
|
|
|
12235
|
-
|
|
12247
|
+
_this.awsRealTimeSocket.send(JSON.stringify(gqlInit));
|
|
12248
|
+
|
|
12249
|
+
setTimeout(checkAckOk.bind(_this, ackOk_1), CONNECTION_INIT_TIMEOUT);
|
|
12250
|
+
}
|
|
12251
|
+
|
|
12252
|
+
function checkAckOk(ackOk) {
|
|
12236
12253
|
if (!ackOk) {
|
|
12237
12254
|
rej(new Error("Connection timeout: ack from AWSRealTime was not received on " + CONNECTION_INIT_TIMEOUT + " ms"));
|
|
12238
12255
|
}
|
|
12239
12256
|
}
|
|
12240
|
-
|
|
12241
|
-
setTimeout(checkAckOk.bind(_this), CONNECTION_INIT_TIMEOUT);
|
|
12242
12257
|
});
|
|
12243
12258
|
}()];
|
|
12244
12259
|
|
|
@@ -12252,7 +12267,7 @@ function (_super) {
|
|
|
12252
12267
|
|
|
12253
12268
|
case 4:
|
|
12254
12269
|
err_4 = _b.sent();
|
|
12255
|
-
errorType =
|
|
12270
|
+
_a = err_4, errorType = _a.errorType, errorCode = _a.errorCode;
|
|
12256
12271
|
|
|
12257
12272
|
if (NON_RETRYABLE_CODES.includes(errorCode)) {
|
|
12258
12273
|
throw new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["NonRetryableError"](errorType);
|
|
@@ -12295,16 +12310,17 @@ function (_super) {
|
|
|
12295
12310
|
AMAZON_COGNITO_USER_POOLS: this._awsRealTimeCUPHeader.bind(this),
|
|
12296
12311
|
AWS_LAMBDA: this._customAuthHeader
|
|
12297
12312
|
};
|
|
12298
|
-
|
|
12299
|
-
|
|
12300
|
-
|
|
12301
|
-
|
|
12302
|
-
|
|
12303
|
-
|
|
12304
|
-
|
|
12305
|
-
}
|
|
12313
|
+
if (!(!authenticationType || !headerHandler[authenticationType])) return [3
|
|
12314
|
+
/*break*/
|
|
12315
|
+
, 1];
|
|
12316
|
+
logger.debug("Authentication type " + authenticationType + " not supported");
|
|
12317
|
+
return [2
|
|
12318
|
+
/*return*/
|
|
12319
|
+
, ''];
|
|
12306
12320
|
|
|
12307
|
-
|
|
12321
|
+
case 1:
|
|
12322
|
+
handler = headerHandler[authenticationType];
|
|
12323
|
+
host = url__WEBPACK_IMPORTED_MODULE_2__["parse"](appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
|
|
12308
12324
|
return [4
|
|
12309
12325
|
/*yield*/
|
|
12310
12326
|
, handler({
|
|
@@ -12317,7 +12333,7 @@ function (_super) {
|
|
|
12317
12333
|
additionalHeaders: additionalHeaders
|
|
12318
12334
|
})];
|
|
12319
12335
|
|
|
12320
|
-
case
|
|
12336
|
+
case 2:
|
|
12321
12337
|
result = _b.sent();
|
|
12322
12338
|
return [2
|
|
12323
12339
|
/*return*/
|
|
@@ -12449,10 +12465,14 @@ function (_super) {
|
|
|
12449
12465
|
return [4
|
|
12450
12466
|
/*yield*/
|
|
12451
12467
|
, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_5__["Credentials"].get().then(function (credentials) {
|
|
12468
|
+
var _a = credentials,
|
|
12469
|
+
secretAccessKey = _a.secretAccessKey,
|
|
12470
|
+
accessKeyId = _a.accessKeyId,
|
|
12471
|
+
sessionToken = _a.sessionToken;
|
|
12452
12472
|
return {
|
|
12453
|
-
secret_key:
|
|
12454
|
-
access_key:
|
|
12455
|
-
session_token:
|
|
12473
|
+
secret_key: secretAccessKey,
|
|
12474
|
+
access_key: accessKeyId,
|
|
12475
|
+
session_token: sessionToken
|
|
12456
12476
|
};
|
|
12457
12477
|
})];
|
|
12458
12478
|
|
|
@@ -12477,7 +12497,7 @@ function (_super) {
|
|
|
12477
12497
|
var host = _a.host,
|
|
12478
12498
|
additionalHeaders = _a.additionalHeaders;
|
|
12479
12499
|
|
|
12480
|
-
if (!additionalHeaders
|
|
12500
|
+
if (!additionalHeaders || !additionalHeaders['Authorization']) {
|
|
12481
12501
|
throw new Error('No auth token specified');
|
|
12482
12502
|
}
|
|
12483
12503
|
|
|
@@ -13049,21 +13069,27 @@ function () {
|
|
|
13049
13069
|
|
|
13050
13070
|
ClientsQueue.prototype.get = function (clientId, clientFactory) {
|
|
13051
13071
|
return __awaiter(this, void 0, void 0, function () {
|
|
13052
|
-
var
|
|
13072
|
+
var cachedPromise, newPromise;
|
|
13053
13073
|
return __generator(this, function (_a) {
|
|
13054
|
-
|
|
13074
|
+
cachedPromise = this.promises.get(clientId);
|
|
13055
13075
|
|
|
13056
|
-
if (
|
|
13076
|
+
if (cachedPromise) {
|
|
13057
13077
|
return [2
|
|
13058
13078
|
/*return*/
|
|
13059
|
-
,
|
|
13079
|
+
, cachedPromise];
|
|
13080
|
+
}
|
|
13081
|
+
|
|
13082
|
+
if (clientFactory) {
|
|
13083
|
+
newPromise = clientFactory(clientId);
|
|
13084
|
+
this.promises.set(clientId, newPromise);
|
|
13085
|
+
return [2
|
|
13086
|
+
/*return*/
|
|
13087
|
+
, newPromise];
|
|
13060
13088
|
}
|
|
13061
13089
|
|
|
13062
|
-
promise = clientFactory(clientId);
|
|
13063
|
-
this.promises.set(clientId, promise);
|
|
13064
13090
|
return [2
|
|
13065
13091
|
/*return*/
|
|
13066
|
-
,
|
|
13092
|
+
, undefined];
|
|
13067
13093
|
});
|
|
13068
13094
|
});
|
|
13069
13095
|
};
|
|
@@ -13155,6 +13181,10 @@ function (_super) {
|
|
|
13155
13181
|
}, args), null, 2));
|
|
13156
13182
|
var topicsToDelete_1 = [];
|
|
13157
13183
|
|
|
13184
|
+
if (!clientId) {
|
|
13185
|
+
return;
|
|
13186
|
+
}
|
|
13187
|
+
|
|
13158
13188
|
var clientIdObservers = this._clientIdObservers.get(clientId);
|
|
13159
13189
|
|
|
13160
13190
|
if (!clientIdObservers) {
|
|
@@ -13273,9 +13303,7 @@ function (_super) {
|
|
|
13273
13303
|
case 0:
|
|
13274
13304
|
return [4
|
|
13275
13305
|
/*yield*/
|
|
13276
|
-
, this.clientsQueue.get(clientId
|
|
13277
|
-
return null;
|
|
13278
|
-
})];
|
|
13306
|
+
, this.clientsQueue.get(clientId)];
|
|
13279
13307
|
|
|
13280
13308
|
case 1:
|
|
13281
13309
|
client = _a.sent();
|
|
@@ -13454,13 +13482,14 @@ function (_super) {
|
|
|
13454
13482
|
})();
|
|
13455
13483
|
|
|
13456
13484
|
return function () {
|
|
13485
|
+
var _a, _b;
|
|
13486
|
+
|
|
13457
13487
|
logger.debug('Unsubscribing from topic(s)', targetTopics.join(','));
|
|
13458
13488
|
|
|
13459
13489
|
if (client) {
|
|
13460
|
-
_this._clientIdObservers.get(clientId)["delete"](observer); // No more observers per client => client not needed anymore
|
|
13461
|
-
|
|
13490
|
+
(_a = _this._clientIdObservers.get(clientId)) === null || _a === void 0 ? void 0 : _a["delete"](observer); // No more observers per client => client not needed anymore
|
|
13462
13491
|
|
|
13463
|
-
if (_this._clientIdObservers.get(clientId).size === 0) {
|
|
13492
|
+
if (((_b = _this._clientIdObservers.get(clientId)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
|
|
13464
13493
|
_this.disconnect(clientId);
|
|
13465
13494
|
|
|
13466
13495
|
_this._clientIdObservers["delete"](clientId);
|