aws-appsync-subscription-link 3.0.7 → 3.0.10
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 +32 -0
- package/__tests__/link/realtime-subscription-handshake-link-test.ts +35 -1
- package/lib/index.js +1 -1
- package/lib/non-terminating-link.d.ts +4 -2
- package/lib/non-terminating-link.js +2 -2
- package/lib/realtime-subscription-handshake-link.d.ts +4 -4
- package/lib/realtime-subscription-handshake-link.js +71 -63
- package/lib/subscription-handshake-link.d.ts +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
<a name="3.0.10"></a>
|
|
7
|
+
## [3.0.10](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-subscription-link@3.0.9...aws-appsync-subscription-link@3.0.10) (2022-03-04)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* Port over Amplify fix for subscription race conditions ([#509](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/509)) ([#704](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/704)) ([92b50c4](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/92b50c4))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
<a name="3.0.9"></a>
|
|
18
|
+
## [3.0.9](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-subscription-link@3.0.8...aws-appsync-subscription-link@3.0.9) (2021-09-24)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* add type fix to subscription link to fix 'prepare' script ([#669](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/669)) ([c5202dc](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/c5202dc))
|
|
24
|
+
* **aws-appsync-subscription-link:** graphql header refactor to fix IAM-based auth ([#619](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/619)) ([#671](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/671)) ([dbf4959](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/dbf4959))
|
|
25
|
+
* remove aws-sdk V2; import aws-sdk V3 packages ([#637](https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/637)); refactor auth-link, signer, and types ([0996740](https://github.com/awslabs/aws-mobile-appsync-sdk-js/commit/0996740))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
<a name="3.0.8"></a>
|
|
31
|
+
## [3.0.8](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-subscription-link@3.0.7...aws-appsync-subscription-link@3.0.8) (2021-07-28)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
**Note:** Version bump only for package aws-appsync-subscription-link
|
|
37
|
+
|
|
6
38
|
<a name="3.0.7"></a>
|
|
7
39
|
## [3.0.7](https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync-subscription-link@3.0.6...aws-appsync-subscription-link@3.0.7) (2021-07-09)
|
|
8
40
|
|
|
@@ -6,7 +6,7 @@ import { AppSyncRealTimeSubscriptionHandshakeLink } from '../../src/realtime-sub
|
|
|
6
6
|
const query = gql`subscription { someSubscription { aField } }`
|
|
7
7
|
|
|
8
8
|
class myWebSocket implements WebSocket {
|
|
9
|
-
binaryType: BinaryType;
|
|
9
|
+
binaryType: BinaryType; bufferedAmount: number;
|
|
10
10
|
extensions: string;
|
|
11
11
|
onclose: (this: WebSocket, ev: CloseEvent) => any;
|
|
12
12
|
onerror: (this: WebSocket, ev: Event) => any;
|
|
@@ -167,4 +167,38 @@ describe("RealTime subscription link", () => {
|
|
|
167
167
|
});
|
|
168
168
|
});
|
|
169
169
|
|
|
170
|
+
test('Initialize WebSocket correctly for AWS_LAMBDA', (done) => {
|
|
171
|
+
expect.assertions(2);
|
|
172
|
+
jest.spyOn(Date.prototype, 'toISOString').mockImplementation(jest.fn(() => {
|
|
173
|
+
return "2019-11-13T18:47:04.733Z";
|
|
174
|
+
}));
|
|
175
|
+
AppSyncRealTimeSubscriptionHandshakeLink.createWebSocket = jest.fn((url, protocol) => {
|
|
176
|
+
expect(url).toBe('wss://xxxxx.appsync-realtime-api.amazonaws.com/graphql?header=eyJBdXRob3JpemF0aW9uIjoidG9rZW4iLCJob3N0IjoieHh4eHguYXBwc3luYy1hcGkuYW1hem9uYXdzLmNvbSJ9&payload=e30=');
|
|
177
|
+
expect(protocol).toBe('graphql-ws');
|
|
178
|
+
done();
|
|
179
|
+
return new myWebSocket();
|
|
180
|
+
});
|
|
181
|
+
const link = new AppSyncRealTimeSubscriptionHandshakeLink({
|
|
182
|
+
auth: {
|
|
183
|
+
type: AUTH_TYPE.AWS_LAMBDA,
|
|
184
|
+
token: 'token'
|
|
185
|
+
},
|
|
186
|
+
region: 'us-east-1',
|
|
187
|
+
url: 'https://xxxxx.appsync-api.amazonaws.com/graphql'
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
execute(link, { query }).subscribe({
|
|
191
|
+
error: (err) => {
|
|
192
|
+
fail;
|
|
193
|
+
},
|
|
194
|
+
next: (data) => {
|
|
195
|
+
done();
|
|
196
|
+
},
|
|
197
|
+
complete: () => {
|
|
198
|
+
done();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
});
|
|
202
|
+
})
|
|
203
|
+
|
|
170
204
|
});
|
package/lib/index.js
CHANGED
|
@@ -28,7 +28,7 @@ function createSubscriptionHandshakeLink(infoOrUrl, theResultsFetcherLink) {
|
|
|
28
28
|
link: new core_1.ApolloLink(function (operation, _forward) {
|
|
29
29
|
return new core_1.Observable(function (observer) {
|
|
30
30
|
var _a;
|
|
31
|
-
var _b = operation.variables,
|
|
31
|
+
var _b = operation, _c = _b.variables, _d = subscription_handshake_link_1.CONTROL_EVENTS_KEY, controlEvents = _c[_d], variables = __rest(_c, [typeof _d === "symbol" ? _d : _d + ""]);
|
|
32
32
|
if (typeof controlEvents !== "undefined") {
|
|
33
33
|
operation.variables = variables;
|
|
34
34
|
}
|
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
* Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { ApolloLink
|
|
5
|
+
import { ApolloLink } from '@apollo/client/core';
|
|
6
|
+
import type { NextLink, FetchResult } from '@apollo/client/core';
|
|
7
|
+
import type { Observable } from 'zen-observable-ts';
|
|
6
8
|
export declare class NonTerminatingLink extends ApolloLink {
|
|
7
9
|
private contextKey;
|
|
8
10
|
private link;
|
|
9
11
|
constructor(contextKey: string, { link }: {
|
|
10
12
|
link: ApolloLink;
|
|
11
13
|
});
|
|
12
|
-
request(operation: any, forward?: NextLink):
|
|
14
|
+
request(operation: any, forward?: NextLink): Observable<FetchResult>;
|
|
13
15
|
}
|
|
@@ -77,7 +77,7 @@ var NonTerminatingLink = /** @class */ (function (_super) {
|
|
|
77
77
|
}
|
|
78
78
|
NonTerminatingLink.prototype.request = function (operation, forward) {
|
|
79
79
|
var _this = this;
|
|
80
|
-
return context_1.setContext(function (_request, prevContext) { return __awaiter(_this, void 0, void 0, function () {
|
|
80
|
+
return (context_1.setContext(function (_request, prevContext) { return __awaiter(_this, void 0, void 0, function () {
|
|
81
81
|
var result;
|
|
82
82
|
var _a;
|
|
83
83
|
var _this = this;
|
|
@@ -94,7 +94,7 @@ var NonTerminatingLink = /** @class */ (function (_super) {
|
|
|
94
94
|
return [2 /*return*/, __assign(__assign({}, prevContext), (_a = {}, _a[this.contextKey] = result, _a))];
|
|
95
95
|
}
|
|
96
96
|
});
|
|
97
|
-
}); }).request(operation, forward);
|
|
97
|
+
}); })).request(operation, forward);
|
|
98
98
|
};
|
|
99
99
|
return NonTerminatingLink;
|
|
100
100
|
}(core_1.ApolloLink));
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { ApolloLink, Operation } from "@apollo/client/core";
|
|
5
|
+
import { ApolloLink, Observable, Operation, FetchResult } from "@apollo/client/core";
|
|
6
6
|
import { UrlInfo } from "./types";
|
|
7
7
|
export declare const CONTROL_EVENTS_KEY = "@@controlEvents";
|
|
8
8
|
export declare class AppSyncRealTimeSubscriptionHandshakeLink extends ApolloLink {
|
|
@@ -16,15 +16,15 @@ export declare class AppSyncRealTimeSubscriptionHandshakeLink extends ApolloLink
|
|
|
16
16
|
private subscriptionObserverMap;
|
|
17
17
|
private promiseArray;
|
|
18
18
|
constructor({ url: theUrl, region: theRegion, auth: theAuth }: UrlInfo);
|
|
19
|
-
request(operation: Operation): any
|
|
19
|
+
request(operation: Operation): Observable<FetchResult<Record<string, any>, Record<string, any>, Record<string, any>>>;
|
|
20
20
|
private _verifySubscriptionAlreadyStarted;
|
|
21
21
|
private _sendUnsubscriptionMessage;
|
|
22
22
|
private _removeSubscriptionObserver;
|
|
23
|
-
private
|
|
23
|
+
private _closeSocketIfRequired;
|
|
24
24
|
private _startSubscriptionWithAWSAppSyncRealTime;
|
|
25
25
|
private _initializeWebSocketConnection;
|
|
26
26
|
private _awsRealTimeHeaderBasedAuth;
|
|
27
|
-
private
|
|
27
|
+
private _awsRealTimeAuthorizationHeader;
|
|
28
28
|
private _awsRealTimeApiKeyHeader;
|
|
29
29
|
private _awsRealTimeIAMHeader;
|
|
30
30
|
private _initializeRetryableHandshake;
|
|
@@ -125,6 +125,11 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
|
|
|
125
125
|
}
|
|
126
126
|
else {
|
|
127
127
|
var subscriptionId_1 = uuid_1.v4();
|
|
128
|
+
var token = _this.auth.type === aws_appsync_auth_link_1.AUTH_TYPE.AMAZON_COGNITO_USER_POOLS ||
|
|
129
|
+
_this.auth.type === aws_appsync_auth_link_1.AUTH_TYPE.OPENID_CONNECT
|
|
130
|
+
? _this.auth.jwtToken
|
|
131
|
+
: null;
|
|
132
|
+
token = _this.auth.type === aws_appsync_auth_link_1.AUTH_TYPE.AWS_LAMBDA ? _this.auth.token : token;
|
|
128
133
|
var options = {
|
|
129
134
|
appSyncGraphqlEndpoint: _this.url,
|
|
130
135
|
authenticationType: _this.auth.type,
|
|
@@ -134,10 +139,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
|
|
|
134
139
|
variables: variables,
|
|
135
140
|
apiKey: _this.auth.type === aws_appsync_auth_link_1.AUTH_TYPE.API_KEY ? _this.auth.apiKey : "",
|
|
136
141
|
credentials: _this.auth.type === aws_appsync_auth_link_1.AUTH_TYPE.AWS_IAM ? _this.auth.credentials : null,
|
|
137
|
-
|
|
138
|
-
_this.auth.type === aws_appsync_auth_link_1.AUTH_TYPE.OPENID_CONNECT
|
|
139
|
-
? _this.auth.jwtToken
|
|
140
|
-
: null
|
|
142
|
+
token: token
|
|
141
143
|
};
|
|
142
144
|
_this._startSubscriptionWithAWSAppSyncRealTime({
|
|
143
145
|
options: options,
|
|
@@ -218,22 +220,25 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
|
|
|
218
220
|
};
|
|
219
221
|
AppSyncRealTimeSubscriptionHandshakeLink.prototype._removeSubscriptionObserver = function (subscriptionId) {
|
|
220
222
|
this.subscriptionObserverMap.delete(subscriptionId);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
this._closeSocketWhenFlushed();
|
|
224
|
-
}
|
|
223
|
+
// Verifying for 1000ms after removing subscription in case there are new subscriptions on mount / unmount
|
|
224
|
+
setTimeout(this._closeSocketIfRequired.bind(this), 1000);
|
|
225
225
|
};
|
|
226
|
-
AppSyncRealTimeSubscriptionHandshakeLink.prototype.
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
AppSyncRealTimeSubscriptionHandshakeLink.prototype._closeSocketIfRequired = function () {
|
|
227
|
+
if (this.subscriptionObserverMap.size > 0) {
|
|
228
|
+
// There are active subscriptions on the WebSocket
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
229
231
|
if (!this.awsRealTimeSocket) {
|
|
230
232
|
this.socketStatus = types_1.SOCKET_STATUS.CLOSED;
|
|
231
233
|
return;
|
|
232
234
|
}
|
|
233
235
|
if (this.awsRealTimeSocket.bufferedAmount > 0) {
|
|
234
|
-
|
|
236
|
+
// There is still data on the WebSocket
|
|
237
|
+
setTimeout(this._closeSocketIfRequired.bind(this), 1000);
|
|
235
238
|
}
|
|
236
239
|
else {
|
|
240
|
+
logger("closing WebSocket...");
|
|
241
|
+
clearTimeout(this.keepAliveTimeoutId);
|
|
237
242
|
var tempSocket = this.awsRealTimeSocket;
|
|
238
243
|
tempSocket.close(1000);
|
|
239
244
|
this.awsRealTimeSocket = null;
|
|
@@ -243,13 +248,13 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
|
|
|
243
248
|
AppSyncRealTimeSubscriptionHandshakeLink.prototype._startSubscriptionWithAWSAppSyncRealTime = function (_a) {
|
|
244
249
|
var options = _a.options, observer = _a.observer, subscriptionId = _a.subscriptionId;
|
|
245
250
|
return __awaiter(this, void 0, void 0, function () {
|
|
246
|
-
var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, _b, graphql_headers, credentials,
|
|
247
|
-
var
|
|
251
|
+
var appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, _b, graphql_headers, credentials, token, subscriptionState, data, dataString, headerObj, _c, subscriptionMessage, stringToAWSRealTime, err_1, _d, message, subscriptionFailedCallback_1, _e, subscriptionFailedCallback, subscriptionReadyCallback;
|
|
252
|
+
var _f;
|
|
248
253
|
var _this = this;
|
|
249
|
-
return __generator(this, function (
|
|
250
|
-
switch (
|
|
254
|
+
return __generator(this, function (_g) {
|
|
255
|
+
switch (_g.label) {
|
|
251
256
|
case 0:
|
|
252
|
-
appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint, authenticationType = options.authenticationType, query = options.query, variables = options.variables, apiKey = options.apiKey, region = options.region, _b = options.graphql_headers, graphql_headers = _b === void 0 ? function () { return ({}); } : _b, credentials = options.credentials,
|
|
257
|
+
appSyncGraphqlEndpoint = options.appSyncGraphqlEndpoint, authenticationType = options.authenticationType, query = options.query, variables = options.variables, apiKey = options.apiKey, region = options.region, _b = options.graphql_headers, graphql_headers = _b === void 0 ? function () { return ({}); } : _b, credentials = options.credentials, token = options.token;
|
|
253
258
|
subscriptionState = types_1.SUBSCRIPTION_STATUS.PENDING;
|
|
254
259
|
data = {
|
|
255
260
|
query: query,
|
|
@@ -273,13 +278,11 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
|
|
|
273
278
|
canonicalUri: "",
|
|
274
279
|
region: region,
|
|
275
280
|
credentials: credentials,
|
|
276
|
-
|
|
281
|
+
token: token,
|
|
282
|
+
graphql_headers: graphql_headers
|
|
277
283
|
})];
|
|
278
284
|
case 1:
|
|
279
|
-
|
|
280
|
-
return [4 /*yield*/, graphql_headers()];
|
|
281
|
-
case 2:
|
|
282
|
-
headerObj = __assign.apply(void 0, [__assign.apply(void 0, _d.concat([(_h.sent())])), (_g = {}, _g[aws_appsync_auth_link_1.USER_AGENT_HEADER] = aws_appsync_auth_link_1.USER_AGENT, _g)]);
|
|
285
|
+
headerObj = __assign.apply(void 0, [__assign.apply(void 0, _c.concat([(_g.sent())])), (_f = {}, _f[aws_appsync_auth_link_1.USER_AGENT_HEADER] = aws_appsync_auth_link_1.USER_AGENT, _f)]);
|
|
283
286
|
subscriptionMessage = {
|
|
284
287
|
id: subscriptionId,
|
|
285
288
|
payload: {
|
|
@@ -291,23 +294,23 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
|
|
|
291
294
|
type: types_1.MESSAGE_TYPES.GQL_START
|
|
292
295
|
};
|
|
293
296
|
stringToAWSRealTime = JSON.stringify(subscriptionMessage);
|
|
294
|
-
|
|
295
|
-
case
|
|
296
|
-
|
|
297
|
+
_g.label = 2;
|
|
298
|
+
case 2:
|
|
299
|
+
_g.trys.push([2, 4, , 5]);
|
|
297
300
|
return [4 /*yield*/, this._initializeWebSocketConnection({
|
|
298
301
|
apiKey: apiKey,
|
|
299
302
|
appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
|
|
300
303
|
authenticationType: authenticationType,
|
|
301
304
|
region: region,
|
|
302
305
|
credentials: credentials,
|
|
303
|
-
|
|
306
|
+
token: token
|
|
304
307
|
})];
|
|
308
|
+
case 3:
|
|
309
|
+
_g.sent();
|
|
310
|
+
return [3 /*break*/, 5];
|
|
305
311
|
case 4:
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
case 5:
|
|
309
|
-
err_1 = _h.sent();
|
|
310
|
-
_e = err_1.message, message = _e === void 0 ? "" : _e;
|
|
312
|
+
err_1 = _g.sent();
|
|
313
|
+
_d = err_1.message, message = _d === void 0 ? "" : _d;
|
|
311
314
|
observer.error({
|
|
312
315
|
errors: [
|
|
313
316
|
__assign({}, new graphql_1.GraphQLError("Connection failed: " + message))
|
|
@@ -320,8 +323,8 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
|
|
|
320
323
|
subscriptionFailedCallback_1();
|
|
321
324
|
}
|
|
322
325
|
return [2 /*return*/];
|
|
323
|
-
case
|
|
324
|
-
|
|
326
|
+
case 5:
|
|
327
|
+
_e = this.subscriptionObserverMap.get(subscriptionId), subscriptionFailedCallback = _e.subscriptionFailedCallback, subscriptionReadyCallback = _e.subscriptionReadyCallback;
|
|
325
328
|
// This must be done before sending the message in order to be listening immediately
|
|
326
329
|
this.subscriptionObserverMap.set(subscriptionId, {
|
|
327
330
|
observer: observer,
|
|
@@ -344,7 +347,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
|
|
|
344
347
|
};
|
|
345
348
|
AppSyncRealTimeSubscriptionHandshakeLink.prototype._initializeWebSocketConnection = function (_a) {
|
|
346
349
|
var _this = this;
|
|
347
|
-
var appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, authenticationType = _a.authenticationType, apiKey = _a.apiKey, region = _a.region, credentials = _a.credentials,
|
|
350
|
+
var appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, authenticationType = _a.authenticationType, apiKey = _a.apiKey, region = _a.region, credentials = _a.credentials, token = _a.token;
|
|
348
351
|
if (this.socketStatus === types_1.SOCKET_STATUS.READY) {
|
|
349
352
|
return;
|
|
350
353
|
}
|
|
@@ -370,7 +373,8 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
|
|
|
370
373
|
appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
|
|
371
374
|
region: region,
|
|
372
375
|
credentials: credentials,
|
|
373
|
-
|
|
376
|
+
token: token,
|
|
377
|
+
graphql_headers: function () { }
|
|
374
378
|
})];
|
|
375
379
|
case 2:
|
|
376
380
|
headerString = _b.apply(_a, [_c.sent()]);
|
|
@@ -408,7 +412,7 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
|
|
|
408
412
|
}); });
|
|
409
413
|
};
|
|
410
414
|
AppSyncRealTimeSubscriptionHandshakeLink.prototype._awsRealTimeHeaderBasedAuth = function (_a) {
|
|
411
|
-
var authenticationType = _a.authenticationType, payload = _a.payload, canonicalUri = _a.canonicalUri, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, apiKey = _a.apiKey, region = _a.region, credentials = _a.credentials,
|
|
415
|
+
var authenticationType = _a.authenticationType, payload = _a.payload, canonicalUri = _a.canonicalUri, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, apiKey = _a.apiKey, region = _a.region, credentials = _a.credentials, token = _a.token, graphql_headers = _a.graphql_headers;
|
|
412
416
|
return __awaiter(this, void 0, void 0, function () {
|
|
413
417
|
var headerHandler, handler, host, result;
|
|
414
418
|
return __generator(this, function (_b) {
|
|
@@ -417,8 +421,9 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
|
|
|
417
421
|
headerHandler = {
|
|
418
422
|
API_KEY: this._awsRealTimeApiKeyHeader.bind(this),
|
|
419
423
|
AWS_IAM: this._awsRealTimeIAMHeader.bind(this),
|
|
420
|
-
OPENID_CONNECT: this.
|
|
421
|
-
AMAZON_COGNITO_USER_POOLS: this.
|
|
424
|
+
OPENID_CONNECT: this._awsRealTimeAuthorizationHeader.bind(this),
|
|
425
|
+
AMAZON_COGNITO_USER_POOLS: this._awsRealTimeAuthorizationHeader.bind(this),
|
|
426
|
+
AWS_LAMBDA: this._awsRealTimeAuthorizationHeader.bind(this)
|
|
422
427
|
};
|
|
423
428
|
handler = headerHandler[authenticationType];
|
|
424
429
|
if (typeof handler !== "function") {
|
|
@@ -434,7 +439,8 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
|
|
|
434
439
|
region: region,
|
|
435
440
|
host: host,
|
|
436
441
|
credentials: credentials,
|
|
437
|
-
|
|
442
|
+
token: token,
|
|
443
|
+
graphql_headers: graphql_headers
|
|
438
444
|
})];
|
|
439
445
|
case 1:
|
|
440
446
|
result = _b.sent();
|
|
@@ -443,42 +449,44 @@ var AppSyncRealTimeSubscriptionHandshakeLink = /** @class */ (function (_super)
|
|
|
443
449
|
});
|
|
444
450
|
});
|
|
445
451
|
};
|
|
446
|
-
AppSyncRealTimeSubscriptionHandshakeLink.prototype.
|
|
447
|
-
var host = _a.host,
|
|
452
|
+
AppSyncRealTimeSubscriptionHandshakeLink.prototype._awsRealTimeAuthorizationHeader = function (_a) {
|
|
453
|
+
var host = _a.host, token = _a.token, graphql_headers = _a.graphql_headers;
|
|
448
454
|
return __awaiter(this, void 0, void 0, function () {
|
|
449
|
-
var _b, _c;
|
|
450
|
-
return __generator(this, function (
|
|
451
|
-
switch (
|
|
455
|
+
var _b, _c, _d;
|
|
456
|
+
return __generator(this, function (_e) {
|
|
457
|
+
switch (_e.label) {
|
|
452
458
|
case 0:
|
|
453
459
|
_b = {};
|
|
454
|
-
if (!(typeof
|
|
455
|
-
return [4 /*yield*/,
|
|
460
|
+
if (!(typeof token === "function")) return [3 /*break*/, 2];
|
|
461
|
+
return [4 /*yield*/, token.call(undefined)];
|
|
456
462
|
case 1:
|
|
457
|
-
_c =
|
|
463
|
+
_c = _e.sent();
|
|
458
464
|
return [3 /*break*/, 4];
|
|
459
|
-
case 2: return [4 /*yield*/,
|
|
465
|
+
case 2: return [4 /*yield*/, token];
|
|
460
466
|
case 3:
|
|
461
|
-
_c =
|
|
462
|
-
|
|
463
|
-
case 4:
|
|
464
|
-
|
|
465
|
-
|
|
467
|
+
_c = _e.sent();
|
|
468
|
+
_e.label = 4;
|
|
469
|
+
case 4:
|
|
470
|
+
_d = [(_b.Authorization = _c, _b.host = host, _b)];
|
|
471
|
+
return [4 /*yield*/, graphql_headers()];
|
|
472
|
+
case 5: return [2 /*return*/, __assign.apply(void 0, _d.concat([(_e.sent())]))];
|
|
466
473
|
}
|
|
467
474
|
});
|
|
468
475
|
});
|
|
469
476
|
};
|
|
470
477
|
AppSyncRealTimeSubscriptionHandshakeLink.prototype._awsRealTimeApiKeyHeader = function (_a) {
|
|
471
|
-
var apiKey = _a.apiKey, host = _a.host;
|
|
478
|
+
var apiKey = _a.apiKey, host = _a.host, graphql_headers = _a.graphql_headers;
|
|
472
479
|
return __awaiter(this, void 0, void 0, function () {
|
|
473
|
-
var dt, dtStr;
|
|
474
|
-
return __generator(this, function (
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
"x-amz-date": dtStr,
|
|
480
|
-
|
|
481
|
-
|
|
480
|
+
var dt, dtStr, _b;
|
|
481
|
+
return __generator(this, function (_c) {
|
|
482
|
+
switch (_c.label) {
|
|
483
|
+
case 0:
|
|
484
|
+
dt = new Date();
|
|
485
|
+
dtStr = dt.toISOString().replace(/[:\-]|\.\d{3}/g, "");
|
|
486
|
+
_b = [{ host: host, "x-amz-date": dtStr, "x-api-key": apiKey }];
|
|
487
|
+
return [4 /*yield*/, graphql_headers()];
|
|
488
|
+
case 1: return [2 /*return*/, __assign.apply(void 0, _b.concat([(_c.sent())]))];
|
|
489
|
+
}
|
|
482
490
|
});
|
|
483
491
|
});
|
|
484
492
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { ApolloLink, Operation, FetchResult } from "@apollo/client/core";
|
|
5
|
+
import { ApolloLink, Observable, Operation, FetchResult } from "@apollo/client/core";
|
|
6
6
|
declare type MqttConnectionInfo = {
|
|
7
7
|
client: string;
|
|
8
8
|
url: string;
|
|
@@ -14,7 +14,7 @@ export declare class SubscriptionHandshakeLink extends ApolloLink {
|
|
|
14
14
|
private topicObservers;
|
|
15
15
|
private clientObservers;
|
|
16
16
|
constructor(subsInfoContextKey: any);
|
|
17
|
-
request(operation: Operation):
|
|
17
|
+
request(operation: Operation): Observable<unknown>;
|
|
18
18
|
connectNewClients(connectionInfo: MqttConnectionInfo[], observer: ZenObservable.Observer<FetchResult>, operation: Operation): Promise<any[]>;
|
|
19
19
|
connectNewClient(connectionInfo: MqttConnectionInfo, observer: ZenObservable.Observer<FetchResult>, selectionNames: string[]): Promise<any>;
|
|
20
20
|
subscribeToTopics<T>(client: any, topics: string[], observer: ZenObservable.Observer<T>): Promise<unknown[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aws-appsync-subscription-link",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.10",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "AWS Mobile AppSync SDK for JavaScript",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"test-watch": "jest --watch"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"aws-appsync-auth-link": "^3.0.
|
|
22
|
+
"aws-appsync-auth-link": "^3.0.7",
|
|
23
23
|
"debug": "2.6.9",
|
|
24
24
|
"url": "^0.11.0"
|
|
25
25
|
},
|