@aws-amplify/api-graphql
Advanced tools
Comparing version 4.5.1 to 4.5.2-unstable.4606279.0
@@ -93,6 +93,17 @@ 'use strict'; | ||
exports.post = post; | ||
function closeAll() { | ||
AWSAppSyncEventsProvider_1.AppSyncEventProvider.close(); | ||
/** | ||
* @experimental API may change in future versions | ||
* | ||
* Close WebSocket connection, disconnect listeners and reconnect observers | ||
* | ||
* @example | ||
* await events.closeAll() | ||
* | ||
* @returns void on success | ||
* @throws on error | ||
*/ | ||
async function closeAll() { | ||
await AWSAppSyncEventsProvider_1.AppSyncEventProvider.close(); | ||
} | ||
exports.closeAll = closeAll; | ||
//# sourceMappingURL=index.js.map |
@@ -13,5 +13,10 @@ 'use strict'; | ||
const WS_PROTOCOL_NAME = 'aws-appsync-event-ws'; | ||
const CONNECT_URI = ''; // events does not expect a connect uri | ||
class AWSAppSyncEventProvider extends AWSWebSocketProvider_1.AWSWebSocketProvider { | ||
constructor() { | ||
super({ providerName: PROVIDER_NAME, wsProtocolName: WS_PROTOCOL_NAME }); | ||
super({ | ||
providerName: PROVIDER_NAME, | ||
wsProtocolName: WS_PROTOCOL_NAME, | ||
connectUri: CONNECT_URI, | ||
}); | ||
} | ||
@@ -31,3 +36,3 @@ getProviderName() { | ||
async _prepareSubscriptionPayload({ options, subscriptionId, customUserAgentDetails, additionalCustomHeaders, libraryConfigHeaders, publish, }) { | ||
const { appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, } = options; | ||
const { appSyncGraphqlEndpoint, authenticationType, query, apiKey, region, } = options; | ||
// This will be needed for WS publish | ||
@@ -37,3 +42,3 @@ // const data = { | ||
// }; | ||
const serializedData = JSON.stringify([variables]); | ||
const serializedData = JSON.stringify({ channel: query }); | ||
const headers = { | ||
@@ -84,3 +89,3 @@ ...(await (0, authHeaders_1.awsRealTimeHeaderBasedAuth)({ | ||
if (observer) { | ||
observer.next(deserializedEvent); | ||
observer.next({ id, type, event: deserializedEvent }); | ||
} | ||
@@ -87,0 +92,0 @@ else { |
@@ -13,5 +13,10 @@ 'use strict'; | ||
const WS_PROTOCOL_NAME = 'graphql-ws'; | ||
const CONNECT_URI = '/connect'; | ||
class AWSAppSyncRealTimeProvider extends AWSWebSocketProvider_1.AWSWebSocketProvider { | ||
constructor() { | ||
super({ providerName: PROVIDER_NAME, wsProtocolName: WS_PROTOCOL_NAME }); | ||
super({ | ||
providerName: PROVIDER_NAME, | ||
wsProtocolName: WS_PROTOCOL_NAME, | ||
connectUri: CONNECT_URI, | ||
}); | ||
} | ||
@@ -18,0 +23,0 @@ getProviderName() { |
@@ -58,2 +58,3 @@ 'use strict'; | ||
this.wsProtocolName = args.wsProtocolName; | ||
this.wsConnectUri = args.connectUri; | ||
this.connectionStateMonitorSubscription = | ||
@@ -73,2 +74,18 @@ this._startConnectionStateMonitoring(); | ||
this.reconnectionMonitor.close(); | ||
return new Promise((resolve, reject) => { | ||
if (this.awsRealTimeSocket) { | ||
this.awsRealTimeSocket.onclose = (_) => { | ||
this.subscriptionObserverMap = new Map(); | ||
this.awsRealTimeSocket = undefined; | ||
resolve(); | ||
}; | ||
this.awsRealTimeSocket.onerror = (err) => { | ||
reject(err); | ||
}; | ||
this.awsRealTimeSocket.close(); | ||
} | ||
else { | ||
resolve(); | ||
} | ||
}); | ||
} | ||
@@ -498,3 +515,3 @@ subscribe(options, customUserAgentDetails) { | ||
payload: payloadString, | ||
canonicalUri: '/connect', | ||
canonicalUri: this.wsConnectUri, | ||
apiKey, | ||
@@ -501,0 +518,0 @@ appSyncGraphqlEndpoint, |
@@ -46,3 +46,14 @@ import { DocumentType } from '@aws-amplify/core/internals/utils'; | ||
declare function post(channel: string, event: DocumentType | DocumentType[], options?: EventsOptions): Promise<void | PublishedEvent[]>; | ||
declare function closeAll(): void; | ||
/** | ||
* @experimental API may change in future versions | ||
* | ||
* Close WebSocket connection, disconnect listeners and reconnect observers | ||
* | ||
* @example | ||
* await events.closeAll() | ||
* | ||
* @returns void on success | ||
* @throws on error | ||
*/ | ||
declare function closeAll(): Promise<void>; | ||
export { connect, post, closeAll }; |
@@ -19,2 +19,3 @@ import { Observable } from 'rxjs'; | ||
wsProtocolName: string; | ||
connectUri: string; | ||
} | ||
@@ -24,3 +25,3 @@ export declare abstract class AWSWebSocketProvider { | ||
protected subscriptionObserverMap: Map<string, ObserverQuery>; | ||
private awsRealTimeSocket?; | ||
protected awsRealTimeSocket?: WebSocket; | ||
private socketStatus; | ||
@@ -36,2 +37,3 @@ private keepAliveTimeoutId?; | ||
private readonly wsProtocolName; | ||
private readonly wsConnectUri; | ||
constructor(args: AWSWebSocketProviderArgs); | ||
@@ -41,3 +43,3 @@ /** | ||
*/ | ||
close(): void; | ||
close(): Promise<void>; | ||
subscribe(options?: AWSAppSyncRealTimeProviderOptions, customUserAgentDetails?: CustomUserAgentDetails): Observable<Record<string, unknown>>; | ||
@@ -44,0 +46,0 @@ protected connect(options: AWSAppSyncRealTimeProviderOptions): Promise<void>; |
{ | ||
"name": "@aws-amplify/api-graphql", | ||
"version": "4.5.1", | ||
"version": "4.5.2-unstable.4606279.0+4606279", | ||
"description": "Api-graphql category of aws-amplify", | ||
@@ -87,4 +87,4 @@ "main": "./dist/cjs/index.js", | ||
"dependencies": { | ||
"@aws-amplify/api-rest": "4.0.56", | ||
"@aws-amplify/core": "6.5.1", | ||
"@aws-amplify/api-rest": "4.0.57-unstable.4606279.0+4606279", | ||
"@aws-amplify/core": "6.5.2-unstable.4606279.0+4606279", | ||
"@aws-amplify/data-schema": "^1.7.0", | ||
@@ -105,3 +105,3 @@ "@aws-sdk/types": "3.387.0", | ||
], | ||
"gitHead": "8e9d26373f066d55668d85b72b67845c3ad9f2f4" | ||
"gitHead": "460627966350c67db890dd908e882885e93624a7" | ||
} |
@@ -157,6 +157,17 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
function closeAll(): void { | ||
eventProvider.close(); | ||
/** | ||
* @experimental API may change in future versions | ||
* | ||
* Close WebSocket connection, disconnect listeners and reconnect observers | ||
* | ||
* @example | ||
* await events.closeAll() | ||
* | ||
* @returns void on success | ||
* @throws on error | ||
*/ | ||
async function closeAll(): Promise<void> { | ||
await eventProvider.close(); | ||
} | ||
export { connect, post, closeAll }; |
@@ -46,6 +46,11 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
const WS_PROTOCOL_NAME = 'aws-appsync-event-ws'; | ||
const CONNECT_URI = ''; // events does not expect a connect uri | ||
export class AWSAppSyncEventProvider extends AWSWebSocketProvider { | ||
constructor() { | ||
super({ providerName: PROVIDER_NAME, wsProtocolName: WS_PROTOCOL_NAME }); | ||
super({ | ||
providerName: PROVIDER_NAME, | ||
wsProtocolName: WS_PROTOCOL_NAME, | ||
connectUri: CONNECT_URI, | ||
}); | ||
} | ||
@@ -94,3 +99,2 @@ | ||
query, | ||
variables, | ||
apiKey, | ||
@@ -105,3 +109,3 @@ region, | ||
const serializedData = JSON.stringify([variables]); | ||
const serializedData = JSON.stringify({ channel: query }); | ||
@@ -173,3 +177,3 @@ const headers = { | ||
if (observer) { | ||
observer.next(deserializedEvent); | ||
observer.next({ id, type, event: deserializedEvent }); | ||
} else { | ||
@@ -176,0 +180,0 @@ this.logger.debug(`observer not found for id: ${id}`); |
@@ -45,6 +45,11 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
const WS_PROTOCOL_NAME = 'graphql-ws'; | ||
const CONNECT_URI = '/connect'; | ||
export class AWSAppSyncRealTimeProvider extends AWSWebSocketProvider { | ||
constructor() { | ||
super({ providerName: PROVIDER_NAME, wsProtocolName: WS_PROTOCOL_NAME }); | ||
super({ | ||
providerName: PROVIDER_NAME, | ||
wsProtocolName: WS_PROTOCOL_NAME, | ||
connectUri: CONNECT_URI, | ||
}); | ||
} | ||
@@ -51,0 +56,0 @@ |
@@ -77,2 +77,3 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
wsProtocolName: string; | ||
connectUri: string; | ||
} | ||
@@ -84,3 +85,3 @@ | ||
private awsRealTimeSocket?: WebSocket; | ||
protected awsRealTimeSocket?: WebSocket; | ||
private socketStatus: SOCKET_STATUS = SOCKET_STATUS.CLOSED; | ||
@@ -96,2 +97,3 @@ private keepAliveTimeoutId?: ReturnType<typeof setTimeout>; | ||
private readonly wsProtocolName: string; | ||
private readonly wsConnectUri: string; | ||
@@ -101,2 +103,3 @@ constructor(args: AWSWebSocketProviderArgs) { | ||
this.wsProtocolName = args.wsProtocolName; | ||
this.wsConnectUri = args.connectUri; | ||
@@ -119,2 +122,20 @@ this.connectionStateMonitorSubscription = | ||
this.reconnectionMonitor.close(); | ||
return new Promise<void>((resolve, reject) => { | ||
if (this.awsRealTimeSocket) { | ||
this.awsRealTimeSocket.onclose = (_: CloseEvent) => { | ||
this.subscriptionObserverMap = new Map(); | ||
this.awsRealTimeSocket = undefined; | ||
resolve(); | ||
}; | ||
this.awsRealTimeSocket.onerror = (err: any) => { | ||
reject(err); | ||
}; | ||
this.awsRealTimeSocket.close(); | ||
} else { | ||
resolve(); | ||
} | ||
}); | ||
} | ||
@@ -729,3 +750,3 @@ | ||
payload: payloadString, | ||
canonicalUri: '/connect', | ||
canonicalUri: this.wsConnectUri, | ||
apiKey, | ||
@@ -732,0 +753,0 @@ appSyncGraphqlEndpoint, |
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
815182
10535
1
1
- Removed@aws-amplify/api-rest@4.0.56(transitive)
- Removed@aws-amplify/core@6.5.1(transitive)
- Removed@aws-crypto/sha256-js@5.2.0(transitive)
- Removed@aws-crypto/util@5.2.0(transitive)
- Removed@aws-sdk/types@3.398.0(transitive)
- Removed@smithy/is-array-buffer@2.2.0(transitive)
- Removed@smithy/util-buffer-from@2.2.0(transitive)
- Removed@smithy/util-hex-encoding@2.0.0(transitive)
- Removed@smithy/util-utf8@2.3.0(transitive)
- Removed@types/uuid@9.0.8(transitive)
- Removedjs-cookie@3.0.5(transitive)
Updated@aws-amplify/api-rest@4.0.57-unstable.4606279.0+4606279