@aws-amplify/api-graphql
Advanced tools
Comparing version 4.7.2-graphql-data-ka.518fb2c.0 to 4.7.2-poc-list-paths.25da28f.0
@@ -24,2 +24,3 @@ 'use strict'; | ||
this.socketStatus = constants_1.SOCKET_STATUS.CLOSED; | ||
this.keepAliveTimeout = constants_1.DEFAULT_KEEP_ALIVE_TIMEOUT; | ||
this.promiseArray = []; | ||
@@ -76,3 +77,2 @@ this.connectionStateMonitor = new ConnectionStateMonitor_1.ConnectionStateMonitor(); | ||
this.awsRealTimeSocket.onclose = (_) => { | ||
this._closeSocket(); | ||
this.subscriptionObserverMap = new Map(); | ||
@@ -118,3 +118,3 @@ this.awsRealTimeSocket = undefined; | ||
this.logger.debug(`${PubSub_1.CONTROL_MSG.REALTIME_SUBSCRIPTION_INIT_ERROR}: ${err}`); | ||
this._closeSocket(); | ||
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CLOSED); | ||
}) | ||
@@ -299,3 +299,3 @@ .finally(() => { | ||
// Resolving to give the state observer time to propogate the update | ||
this._closeSocket(); | ||
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CLOSED); | ||
// Capture the error only when the network didn't cause disruption | ||
@@ -381,2 +381,8 @@ if (this.connectionState !== PubSub_1.ConnectionState.ConnectionDisruptedPendingNetwork) { | ||
this.logger.debug('closing WebSocket...'); | ||
if (this.keepAliveTimeoutId) { | ||
clearTimeout(this.keepAliveTimeoutId); | ||
} | ||
if (this.keepAliveAlertTimeoutId) { | ||
clearTimeout(this.keepAliveAlertTimeoutId); | ||
} | ||
const tempSocket = this.awsRealTimeSocket; | ||
@@ -389,24 +395,5 @@ // Cleaning callbacks to avoid race condition, socket still exists | ||
this.socketStatus = constants_1.SOCKET_STATUS.CLOSED; | ||
this._closeSocket(); | ||
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CLOSED); | ||
} | ||
} | ||
maintainKeepAlive() { | ||
this.kaTimestamp = Date.now(); | ||
} | ||
keepAliveHeartbeat(connectionTimeoutMs) { | ||
const currentTime = Date.now(); | ||
// Check for missed KA message | ||
if (this.kaTimestamp && | ||
currentTime - this.kaTimestamp > constants_1.DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT) { | ||
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.KEEP_ALIVE_MISSED); | ||
} | ||
else { | ||
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.KEEP_ALIVE); | ||
} | ||
// Recognize we are disconnected if we haven't seen messages in the keep alive timeout period | ||
if (this.kaTimestamp && | ||
currentTime - this.kaTimestamp > connectionTimeoutMs) { | ||
this._errorDisconnect(PubSub_1.CONTROL_MSG.TIMEOUT_DISCONNECT); | ||
} | ||
} | ||
_handleIncomingSubscriptionMessage(message) { | ||
@@ -417,6 +404,4 @@ if (typeof message.data !== 'string') { | ||
const [isData, data] = this._handleSubscriptionData(message); | ||
if (isData) { | ||
this.maintainKeepAlive(); | ||
if (isData) | ||
return; | ||
} | ||
const { type, id, payload } = data; | ||
@@ -453,3 +438,13 @@ const { observer = null, query = '', variables = {}, startAckTimeoutId, subscriptionReadyCallback, subscriptionFailedCallback, } = this.subscriptionObserverMap.get(id) || {}; | ||
if (type === constants_1.MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) { | ||
this.maintainKeepAlive(); | ||
if (this.keepAliveTimeoutId) | ||
clearTimeout(this.keepAliveTimeoutId); | ||
if (this.keepAliveAlertTimeoutId) | ||
clearTimeout(this.keepAliveAlertTimeoutId); | ||
this.keepAliveTimeoutId = setTimeout(() => { | ||
this._errorDisconnect(PubSub_1.CONTROL_MSG.TIMEOUT_DISCONNECT); | ||
}, this.keepAliveTimeout); | ||
this.keepAliveAlertTimeoutId = setTimeout(() => { | ||
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.KEEP_ALIVE_MISSED); | ||
}, constants_1.DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT); | ||
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.KEEP_ALIVE); | ||
return; | ||
@@ -488,3 +483,3 @@ } | ||
if (this.awsRealTimeSocket) { | ||
this._closeSocket(); | ||
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CLOSED); | ||
this.awsRealTimeSocket.close(); | ||
@@ -494,9 +489,2 @@ } | ||
} | ||
_closeSocket() { | ||
if (this.keepAliveHeartbeatIntervalId) { | ||
clearInterval(this.keepAliveHeartbeatIntervalId); | ||
this.keepAliveHeartbeatIntervalId = undefined; | ||
} | ||
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CLOSED); | ||
} | ||
_timeoutStartSubscriptionAck(subscriptionId) { | ||
@@ -515,3 +503,3 @@ const subscriptionObserver = this.subscriptionObserverMap.get(subscriptionId); | ||
}); | ||
this._closeSocket(); | ||
this.connectionStateMonitor.record(ConnectionStateMonitor_1.CONNECTION_CHANGE.CLOSED); | ||
this.logger.debug('timeoutStartSubscription', JSON.stringify({ query, variables })); | ||
@@ -589,3 +577,2 @@ } | ||
newSocket.onclose = () => { | ||
this._closeSocket(); | ||
reject(new Error('Connection handshake error')); | ||
@@ -614,3 +601,2 @@ }; | ||
this.logger.debug(`WebSocket closed ${event.reason}`); | ||
this._closeSocket(); | ||
reject(new Error(JSON.stringify(event))); | ||
@@ -658,6 +644,3 @@ }; | ||
} | ||
// Setup a keep alive heartbeat for this connection | ||
this.keepAliveHeartbeatIntervalId = setInterval(() => { | ||
this.keepAliveHeartbeat(connectionTimeoutMs); | ||
}, constants_1.DEFAULT_KEEP_ALIVE_HEARTBEAT_TIMEOUT); | ||
this.keepAliveTimeout = connectionTimeoutMs; | ||
this.awsRealTimeSocket.onmessage = | ||
@@ -671,3 +654,2 @@ this._handleIncomingSubscriptionMessage.bind(this); | ||
this.logger.debug(`WebSocket closed ${event.reason}`); | ||
this._closeSocket(); | ||
this._errorDisconnect(PubSub_1.CONTROL_MSG.CONNECTION_CLOSED); | ||
@@ -674,0 +656,0 @@ }; |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RECONNECT_INTERVAL = exports.RECONNECT_DELAY = exports.DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT = exports.DEFAULT_KEEP_ALIVE_HEARTBEAT_TIMEOUT = exports.DEFAULT_KEEP_ALIVE_TIMEOUT = exports.START_ACK_TIMEOUT = exports.CONNECTION_INIT_TIMEOUT = exports.AWS_APPSYNC_REALTIME_HEADERS = exports.SOCKET_STATUS = exports.SUBSCRIPTION_STATUS = exports.MESSAGE_TYPES = exports.CONNECTION_STATE_CHANGE = exports.NON_RETRYABLE_ERROR_TYPES = exports.NON_RETRYABLE_CODES = exports.MAX_DELAY_MS = exports.AMPLIFY_SYMBOL = void 0; | ||
exports.RECONNECT_INTERVAL = exports.RECONNECT_DELAY = exports.DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT = exports.DEFAULT_KEEP_ALIVE_TIMEOUT = exports.START_ACK_TIMEOUT = exports.CONNECTION_INIT_TIMEOUT = exports.AWS_APPSYNC_REALTIME_HEADERS = exports.SOCKET_STATUS = exports.SUBSCRIPTION_STATUS = exports.MESSAGE_TYPES = exports.CONNECTION_STATE_CHANGE = exports.NON_RETRYABLE_ERROR_TYPES = exports.NON_RETRYABLE_CODES = exports.MAX_DELAY_MS = exports.AMPLIFY_SYMBOL = void 0; | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
@@ -126,6 +126,2 @@ // SPDX-License-Identifier: Apache-2.0 | ||
/** | ||
* Default Time in milleseconds between monitoring checks of keep alive status | ||
*/ | ||
exports.DEFAULT_KEEP_ALIVE_HEARTBEAT_TIMEOUT = 5 * 1000; | ||
/** | ||
* Default Time in milleseconds to alert for missed GQL_CONNECTION_KEEP_ALIVE message | ||
@@ -132,0 +128,0 @@ */ |
@@ -26,4 +26,5 @@ import { Observable } from 'rxjs'; | ||
private socketStatus; | ||
private kaTimestamp?; | ||
private keepAliveHeartbeatIntervalId?; | ||
private keepAliveTimeoutId?; | ||
private keepAliveTimeout; | ||
private keepAliveAlertTimeoutId?; | ||
private promiseArray; | ||
@@ -79,7 +80,4 @@ private connectionState; | ||
}; | ||
private maintainKeepAlive; | ||
private keepAliveHeartbeat; | ||
private _handleIncomingSubscriptionMessage; | ||
private _errorDisconnect; | ||
private _closeSocket; | ||
private _timeoutStartSubscriptionAck; | ||
@@ -86,0 +84,0 @@ private _initializeWebSocketConnection; |
@@ -116,6 +116,2 @@ export { AMPLIFY_SYMBOL } from '@aws-amplify/core/internals/utils'; | ||
/** | ||
* Default Time in milleseconds between monitoring checks of keep alive status | ||
*/ | ||
export declare const DEFAULT_KEEP_ALIVE_HEARTBEAT_TIMEOUT: number; | ||
/** | ||
* Default Time in milleseconds to alert for missed GQL_CONNECTION_KEEP_ALIVE message | ||
@@ -122,0 +118,0 @@ */ |
{ | ||
"name": "@aws-amplify/api-graphql", | ||
"version": "4.7.2-graphql-data-ka.518fb2c.0+518fb2c", | ||
"version": "4.7.2-poc-list-paths.25da28f.0+25da28f", | ||
"description": "Api-graphql category of aws-amplify", | ||
@@ -87,4 +87,4 @@ "main": "./dist/cjs/index.js", | ||
"dependencies": { | ||
"@aws-amplify/api-rest": "4.0.67-graphql-data-ka.518fb2c.0+518fb2c", | ||
"@aws-amplify/core": "6.9.2-graphql-data-ka.518fb2c.0+518fb2c", | ||
"@aws-amplify/api-rest": "4.0.67-poc-list-paths.25da28f.0+25da28f", | ||
"@aws-amplify/core": "6.9.2-poc-list-paths.25da28f.0+25da28f", | ||
"@aws-amplify/data-schema": "^1.7.0", | ||
@@ -105,3 +105,3 @@ "@aws-sdk/types": "3.387.0", | ||
], | ||
"gitHead": "518fb2c0fa23fa4466aa30a6bea469275d2d4d9a" | ||
"gitHead": "25da28f033eff8b33c39afbfc143ab5307e8e59a" | ||
} |
@@ -26,3 +26,3 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT, | ||
DEFAULT_KEEP_ALIVE_HEARTBEAT_TIMEOUT, | ||
DEFAULT_KEEP_ALIVE_TIMEOUT, | ||
MAX_DELAY_MS, | ||
@@ -87,4 +87,5 @@ MESSAGE_TYPES, | ||
private socketStatus: SOCKET_STATUS = SOCKET_STATUS.CLOSED; | ||
private kaTimestamp?: number; | ||
private keepAliveHeartbeatIntervalId?: ReturnType<typeof setTimeout>; | ||
private keepAliveTimeoutId?: ReturnType<typeof setTimeout>; | ||
private keepAliveTimeout = DEFAULT_KEEP_ALIVE_TIMEOUT; | ||
private keepAliveAlertTimeoutId?: ReturnType<typeof setTimeout>; | ||
private promiseArray: { res(): void; rej(reason?: any): void }[] = []; | ||
@@ -123,3 +124,2 @@ private connectionState: ConnectionState | undefined; | ||
this.awsRealTimeSocket.onclose = (_: CloseEvent) => { | ||
this._closeSocket(); | ||
this.subscriptionObserverMap = new Map(); | ||
@@ -177,3 +177,3 @@ this.awsRealTimeSocket = undefined; | ||
); | ||
this._closeSocket(); | ||
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED); | ||
}) | ||
@@ -442,3 +442,3 @@ .finally(() => { | ||
// Resolving to give the state observer time to propogate the update | ||
this._closeSocket(); | ||
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED); | ||
@@ -552,3 +552,8 @@ // Capture the error only when the network didn't cause disruption | ||
this.logger.debug('closing WebSocket...'); | ||
if (this.keepAliveTimeoutId) { | ||
clearTimeout(this.keepAliveTimeoutId); | ||
} | ||
if (this.keepAliveAlertTimeoutId) { | ||
clearTimeout(this.keepAliveAlertTimeoutId); | ||
} | ||
const tempSocket = this.awsRealTimeSocket; | ||
@@ -561,3 +566,3 @@ // Cleaning callbacks to avoid race condition, socket still exists | ||
this.socketStatus = SOCKET_STATUS.CLOSED; | ||
this._closeSocket(); | ||
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED); | ||
} | ||
@@ -582,28 +587,2 @@ } | ||
private maintainKeepAlive() { | ||
this.kaTimestamp = Date.now(); | ||
} | ||
private keepAliveHeartbeat(connectionTimeoutMs: number) { | ||
const currentTime = Date.now(); | ||
// Check for missed KA message | ||
if ( | ||
this.kaTimestamp && | ||
currentTime - this.kaTimestamp > DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT | ||
) { | ||
this.connectionStateMonitor.record(CONNECTION_CHANGE.KEEP_ALIVE_MISSED); | ||
} else { | ||
this.connectionStateMonitor.record(CONNECTION_CHANGE.KEEP_ALIVE); | ||
} | ||
// Recognize we are disconnected if we haven't seen messages in the keep alive timeout period | ||
if ( | ||
this.kaTimestamp && | ||
currentTime - this.kaTimestamp > connectionTimeoutMs | ||
) { | ||
this._errorDisconnect(CONTROL_MSG.TIMEOUT_DISCONNECT); | ||
} | ||
} | ||
private _handleIncomingSubscriptionMessage(message: MessageEvent) { | ||
@@ -615,8 +594,4 @@ if (typeof message.data !== 'string') { | ||
const [isData, data] = this._handleSubscriptionData(message); | ||
if (isData) { | ||
this.maintainKeepAlive(); | ||
if (isData) return; | ||
return; | ||
} | ||
const { type, id, payload } = data; | ||
@@ -669,3 +644,12 @@ | ||
if (type === MESSAGE_TYPES.GQL_CONNECTION_KEEP_ALIVE) { | ||
this.maintainKeepAlive(); | ||
if (this.keepAliveTimeoutId) clearTimeout(this.keepAliveTimeoutId); | ||
if (this.keepAliveAlertTimeoutId) | ||
clearTimeout(this.keepAliveAlertTimeoutId); | ||
this.keepAliveTimeoutId = setTimeout(() => { | ||
this._errorDisconnect(CONTROL_MSG.TIMEOUT_DISCONNECT); | ||
}, this.keepAliveTimeout); | ||
this.keepAliveAlertTimeoutId = setTimeout(() => { | ||
this.connectionStateMonitor.record(CONNECTION_CHANGE.KEEP_ALIVE_MISSED); | ||
}, DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT); | ||
this.connectionStateMonitor.record(CONNECTION_CHANGE.KEEP_ALIVE); | ||
@@ -715,3 +699,3 @@ return; | ||
if (this.awsRealTimeSocket) { | ||
this._closeSocket(); | ||
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED); | ||
this.awsRealTimeSocket.close(); | ||
@@ -723,10 +707,2 @@ } | ||
private _closeSocket() { | ||
if (this.keepAliveHeartbeatIntervalId) { | ||
clearInterval(this.keepAliveHeartbeatIntervalId); | ||
this.keepAliveHeartbeatIntervalId = undefined; | ||
} | ||
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED); | ||
} | ||
private _timeoutStartSubscriptionAck(subscriptionId: string) { | ||
@@ -747,3 +723,3 @@ const subscriptionObserver = | ||
this._closeSocket(); | ||
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED); | ||
this.logger.debug( | ||
@@ -860,3 +836,2 @@ 'timeoutStartSubscription', | ||
newSocket.onclose = () => { | ||
this._closeSocket(); | ||
reject(new Error('Connection handshake error')); | ||
@@ -891,3 +866,2 @@ }; | ||
this.logger.debug(`WebSocket closed ${event.reason}`); | ||
this._closeSocket(); | ||
reject(new Error(JSON.stringify(event))); | ||
@@ -956,7 +930,3 @@ }; | ||
// Setup a keep alive heartbeat for this connection | ||
this.keepAliveHeartbeatIntervalId = setInterval(() => { | ||
this.keepAliveHeartbeat(connectionTimeoutMs); | ||
}, DEFAULT_KEEP_ALIVE_HEARTBEAT_TIMEOUT); | ||
this.keepAliveTimeout = connectionTimeoutMs; | ||
this.awsRealTimeSocket.onmessage = | ||
@@ -972,3 +942,2 @@ this._handleIncomingSubscriptionMessage.bind(this); | ||
this.logger.debug(`WebSocket closed ${event.reason}`); | ||
this._closeSocket(); | ||
this._errorDisconnect(CONTROL_MSG.CONNECTION_CLOSED); | ||
@@ -975,0 +944,0 @@ }; |
@@ -132,7 +132,2 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
/** | ||
* Default Time in milleseconds between monitoring checks of keep alive status | ||
*/ | ||
export const DEFAULT_KEEP_ALIVE_HEARTBEAT_TIMEOUT = 5 * 1000; | ||
/** | ||
* Default Time in milleseconds to alert for missed GQL_CONNECTION_KEEP_ALIVE message | ||
@@ -139,0 +134,0 @@ */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
842038
10921