@aws-amplify/api-graphql 4.0.1-console-preview.deaebd5.0 → 4.0.1-console-preview.b5a42af.0
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/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +3 -4
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +17 -14
- package/lib/internals/InternalGraphQLAPI.js +45 -33
- package/lib/tsconfig.tsbuildinfo +890 -820
- package/lib/types/index.d.ts +3 -4
- package/lib/utils/resolveConfig.d.ts +1 -1
- package/lib/utils/resolveConfig.js +1 -1
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +3 -4
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +17 -14
- package/lib-esm/internals/InternalGraphQLAPI.js +44 -32
- package/lib-esm/tsconfig.tsbuildinfo +890 -820
- package/lib-esm/types/index.d.ts +3 -4
- package/lib-esm/utils/resolveConfig.d.ts +1 -1
- package/lib-esm/utils/resolveConfig.js +1 -1
- package/package.json +5 -5
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +28 -29
- package/src/internals/InternalGraphQLAPI.ts +29 -18
- package/src/types/index.ts +3 -4
- package/src/utils/resolveConfig.ts +1 -1
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
+
import { APIAuthMode, CustomUserAgentDetails, DocumentType } from '@aws-amplify/core/internals/utils';
|
|
2
3
|
import { PubSubContentObserver } from '../../types/PubSub';
|
|
3
4
|
import { SUBSCRIPTION_STATUS } from '../constants';
|
|
4
|
-
import { CustomUserAgentDetails, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
5
|
-
import { DocumentType } from '@aws-amplify/api-rest';
|
|
6
5
|
export declare type ObserverQuery = {
|
|
7
6
|
observer: PubSubContentObserver;
|
|
8
7
|
query: string;
|
|
@@ -14,7 +13,7 @@ export declare type ObserverQuery = {
|
|
|
14
13
|
};
|
|
15
14
|
export interface AWSAppSyncRealTimeProviderOptions {
|
|
16
15
|
appSyncGraphqlEndpoint?: string;
|
|
17
|
-
authenticationType?:
|
|
16
|
+
authenticationType?: APIAuthMode;
|
|
18
17
|
query?: string;
|
|
19
18
|
variables?: Record<string, DocumentType>;
|
|
20
19
|
apiKey?: string;
|
|
@@ -58,7 +57,7 @@ export declare class AWSAppSyncRealTimeProvider {
|
|
|
58
57
|
private _initializeRetryableHandshake;
|
|
59
58
|
private _initializeHandshake;
|
|
60
59
|
private _awsRealTimeHeaderBasedAuth;
|
|
61
|
-
private
|
|
60
|
+
private _awsAuthTokenHeader;
|
|
62
61
|
private _awsRealTimeApiKeyHeader;
|
|
63
62
|
private _awsRealTimeIAMHeader;
|
|
64
63
|
private _customAuthHeader;
|
|
@@ -9,12 +9,12 @@ var url = tslib_1.__importStar(require("url"));
|
|
|
9
9
|
var uuid_1 = require("uuid");
|
|
10
10
|
var buffer_1 = require("buffer");
|
|
11
11
|
var core_1 = require("@aws-amplify/core");
|
|
12
|
-
var PubSub_1 = require("../../types/PubSub");
|
|
13
12
|
var aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
|
|
13
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
14
|
+
var PubSub_1 = require("../../types/PubSub");
|
|
14
15
|
var constants_1 = require("../constants");
|
|
15
16
|
var ConnectionStateMonitor_1 = require("../../utils/ConnectionStateMonitor");
|
|
16
17
|
var ReconnectionMonitor_1 = require("../../utils/ReconnectionMonitor");
|
|
17
|
-
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
18
18
|
var logger = new utils_1.Logger('AWSAppSyncRealTimeProvider');
|
|
19
19
|
var dispatchApiEvent = function (payload) {
|
|
20
20
|
core_1.Hub.dispatch('api', payload, 'PubSub', constants_1.AMPLIFY_SYMBOL);
|
|
@@ -85,7 +85,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
85
85
|
};
|
|
86
86
|
AWSAppSyncRealTimeProvider.prototype.subscribe = function (options, customUserAgentDetails) {
|
|
87
87
|
var _this = this;
|
|
88
|
-
var _a = options || {}, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, region = _a.region, query = _a.query, variables = _a.variables, authenticationType = _a.authenticationType, additionalHeaders = _a.additionalHeaders;
|
|
88
|
+
var _a = options || {}, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, region = _a.region, query = _a.query, variables = _a.variables, authenticationType = _a.authenticationType, additionalHeaders = _a.additionalHeaders, apiKey = _a.apiKey;
|
|
89
89
|
return new rxjs_1.Observable(function (observer) {
|
|
90
90
|
if (!options || !appSyncGraphqlEndpoint) {
|
|
91
91
|
observer.error({
|
|
@@ -109,6 +109,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
109
109
|
authenticationType: authenticationType,
|
|
110
110
|
appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
|
|
111
111
|
additionalHeaders: additionalHeaders,
|
|
112
|
+
apiKey: apiKey,
|
|
112
113
|
},
|
|
113
114
|
observer: observer,
|
|
114
115
|
subscriptionId: subscriptionId_1,
|
|
@@ -680,34 +681,36 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
680
681
|
});
|
|
681
682
|
};
|
|
682
683
|
AWSAppSyncRealTimeProvider.prototype._awsRealTimeHeaderBasedAuth = function (_a) {
|
|
683
|
-
var authenticationType = _a.authenticationType, payload = _a.payload, canonicalUri = _a.canonicalUri, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, region = _a.region, additionalHeaders = _a.additionalHeaders;
|
|
684
|
+
var apiKey = _a.apiKey, authenticationType = _a.authenticationType, payload = _a.payload, canonicalUri = _a.canonicalUri, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, region = _a.region, additionalHeaders = _a.additionalHeaders;
|
|
684
685
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
685
|
-
var headerHandler, handler, host,
|
|
686
|
+
var headerHandler, handler, host, resolvedApiKey, result;
|
|
686
687
|
return tslib_1.__generator(this, function (_b) {
|
|
687
688
|
switch (_b.label) {
|
|
688
689
|
case 0:
|
|
689
690
|
headerHandler = {
|
|
690
691
|
apiKey: this._awsRealTimeApiKeyHeader.bind(this),
|
|
691
692
|
iam: this._awsRealTimeIAMHeader.bind(this),
|
|
692
|
-
|
|
693
|
-
|
|
693
|
+
oidc: this._awsAuthTokenHeader.bind(this),
|
|
694
|
+
userPool: this._awsAuthTokenHeader.bind(this),
|
|
695
|
+
lambda: this._customAuthHeader,
|
|
696
|
+
none: this._customAuthHeader,
|
|
694
697
|
};
|
|
695
|
-
if (!(!authenticationType || !headerHandler[authenticationType
|
|
698
|
+
if (!(!authenticationType || !headerHandler[authenticationType])) return [3 /*break*/, 1];
|
|
696
699
|
logger.debug("Authentication type " + authenticationType + " not supported");
|
|
697
700
|
return [2 /*return*/, undefined];
|
|
698
701
|
case 1:
|
|
699
|
-
handler = headerHandler[authenticationType
|
|
702
|
+
handler = headerHandler[authenticationType];
|
|
700
703
|
host = url.parse(appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
|
|
701
704
|
logger.debug("Authenticating with " + JSON.stringify(authenticationType));
|
|
702
|
-
|
|
703
|
-
if (authenticationType
|
|
704
|
-
|
|
705
|
+
resolvedApiKey = void 0;
|
|
706
|
+
if (authenticationType === 'apiKey') {
|
|
707
|
+
resolvedApiKey = apiKey;
|
|
705
708
|
}
|
|
706
709
|
return [4 /*yield*/, handler({
|
|
707
710
|
payload: payload,
|
|
708
711
|
canonicalUri: canonicalUri,
|
|
709
712
|
appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
|
|
710
|
-
apiKey:
|
|
713
|
+
apiKey: resolvedApiKey,
|
|
711
714
|
region: region,
|
|
712
715
|
host: host,
|
|
713
716
|
additionalHeaders: additionalHeaders,
|
|
@@ -719,7 +722,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
719
722
|
});
|
|
720
723
|
});
|
|
721
724
|
};
|
|
722
|
-
AWSAppSyncRealTimeProvider.prototype.
|
|
725
|
+
AWSAppSyncRealTimeProvider.prototype._awsAuthTokenHeader = function (_a) {
|
|
723
726
|
var host = _a.host;
|
|
724
727
|
var _b, _c;
|
|
725
728
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
@@ -7,7 +7,7 @@ var graphql_1 = require("graphql");
|
|
|
7
7
|
var core_1 = require("@aws-amplify/core");
|
|
8
8
|
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
9
9
|
var types_1 = require("../types");
|
|
10
|
-
var
|
|
10
|
+
var internals_1 = require("@aws-amplify/api-rest/internals");
|
|
11
11
|
var AWSAppSyncRealTimeProvider_1 = require("../Providers/AWSAppSyncRealTimeProvider");
|
|
12
12
|
var USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
13
13
|
var logger = new utils_1.ConsoleLogger('GraphQLAPI');
|
|
@@ -29,7 +29,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
29
29
|
*/
|
|
30
30
|
function InternalGraphQLAPIClass(options) {
|
|
31
31
|
this.Cache = core_1.Cache;
|
|
32
|
-
this._api = { post:
|
|
32
|
+
this._api = { post: internals_1.post };
|
|
33
33
|
this._options = options;
|
|
34
34
|
logger.debug('API Options', this._options);
|
|
35
35
|
}
|
|
@@ -40,36 +40,38 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
40
40
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
41
41
|
var _a;
|
|
42
42
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
43
|
-
var config, _b, region, appSyncGraphqlEndpoint,
|
|
43
|
+
var config, _b, region, appSyncGraphqlEndpoint, apiKey, defaultAuthMode, headers, _c, session, token, e_1;
|
|
44
44
|
return tslib_1.__generator(this, function (_d) {
|
|
45
45
|
switch (_d.label) {
|
|
46
46
|
case 0:
|
|
47
47
|
config = core_1.Amplify.getConfig();
|
|
48
|
-
_b = config.API.
|
|
48
|
+
_b = config.API.GraphQL, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, apiKey = _b.apiKey, defaultAuthMode = _b.defaultAuthMode;
|
|
49
49
|
headers = {};
|
|
50
|
-
_c =
|
|
50
|
+
_c = defaultAuthMode;
|
|
51
51
|
switch (_c) {
|
|
52
52
|
case 'apiKey': return [3 /*break*/, 1];
|
|
53
53
|
case 'iam': return [3 /*break*/, 2];
|
|
54
|
-
case '
|
|
55
|
-
case '
|
|
54
|
+
case 'oidc': return [3 /*break*/, 4];
|
|
55
|
+
case 'userPool': return [3 /*break*/, 4];
|
|
56
|
+
case 'lambda': return [3 /*break*/, 8];
|
|
57
|
+
case 'none': return [3 /*break*/, 9];
|
|
56
58
|
}
|
|
57
|
-
return [3 /*break*/,
|
|
59
|
+
return [3 /*break*/, 10];
|
|
58
60
|
case 1:
|
|
59
|
-
if (!
|
|
61
|
+
if (!apiKey) {
|
|
60
62
|
throw new Error(types_1.GraphQLAuthError.NO_API_KEY);
|
|
61
63
|
}
|
|
62
64
|
headers = {
|
|
63
|
-
'X-Api-Key':
|
|
65
|
+
'X-Api-Key': apiKey,
|
|
64
66
|
};
|
|
65
|
-
return [3 /*break*/,
|
|
67
|
+
return [3 /*break*/, 11];
|
|
66
68
|
case 2: return [4 /*yield*/, core_1.fetchAuthSession()];
|
|
67
69
|
case 3:
|
|
68
70
|
session = _d.sent();
|
|
69
71
|
if (session.credentials === undefined) {
|
|
70
72
|
throw new Error(types_1.GraphQLAuthError.NO_CREDENTIALS);
|
|
71
73
|
}
|
|
72
|
-
return [3 /*break*/,
|
|
74
|
+
return [3 /*break*/, 11];
|
|
73
75
|
case 4:
|
|
74
76
|
_d.trys.push([4, 6, , 7]);
|
|
75
77
|
token = void 0;
|
|
@@ -86,7 +88,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
86
88
|
case 6:
|
|
87
89
|
e_1 = _d.sent();
|
|
88
90
|
throw new Error(types_1.GraphQLAuthError.NO_CURRENT_USER);
|
|
89
|
-
case 7: return [3 /*break*/,
|
|
91
|
+
case 7: return [3 /*break*/, 11];
|
|
90
92
|
case 8:
|
|
91
93
|
if (!additionalHeaders.Authorization) {
|
|
92
94
|
throw new Error(types_1.GraphQLAuthError.NO_AUTH_TOKEN);
|
|
@@ -94,13 +96,14 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
94
96
|
headers = {
|
|
95
97
|
Authorization: additionalHeaders.Authorization,
|
|
96
98
|
};
|
|
97
|
-
return [3 /*break*/,
|
|
98
|
-
case 9:
|
|
99
|
+
return [3 /*break*/, 11];
|
|
100
|
+
case 9: return [3 /*break*/, 11];
|
|
101
|
+
case 10:
|
|
99
102
|
headers = {
|
|
100
103
|
Authorization: null,
|
|
101
104
|
};
|
|
102
|
-
return [3 /*break*/,
|
|
103
|
-
case
|
|
105
|
+
return [3 /*break*/, 11];
|
|
106
|
+
case 11: return [2 /*return*/, headers];
|
|
104
107
|
}
|
|
105
108
|
});
|
|
106
109
|
});
|
|
@@ -149,13 +152,13 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
149
152
|
var query = _a.query, variables = _a.variables, authMode = _a.authMode;
|
|
150
153
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
151
154
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
152
|
-
var config, _b, region, appSyncGraphqlEndpoint, customGraphqlEndpoint, customEndpointRegion, headers, _c, _d, _e, _f, _g, body, endpoint, error, response, err_1, errors;
|
|
155
|
+
var config, _b, region, appSyncGraphqlEndpoint, customGraphqlEndpoint, customEndpointRegion, headers, _c, _d, _e, _f, _g, body, endpoint, error, response, responsePayload, err_1, errors;
|
|
153
156
|
var _h;
|
|
154
157
|
return tslib_1.__generator(this, function (_j) {
|
|
155
158
|
switch (_j.label) {
|
|
156
159
|
case 0:
|
|
157
160
|
config = core_1.Amplify.getConfig();
|
|
158
|
-
_b = config.API.
|
|
161
|
+
_b = config.API.GraphQL, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint;
|
|
159
162
|
customGraphqlEndpoint = null;
|
|
160
163
|
customEndpointRegion = null;
|
|
161
164
|
_c = [{}];
|
|
@@ -198,24 +201,32 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
198
201
|
}
|
|
199
202
|
_j.label = 7;
|
|
200
203
|
case 7:
|
|
201
|
-
_j.trys.push([7,
|
|
202
|
-
return [4 /*yield*/, this._api.post(
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
204
|
+
_j.trys.push([7, 10, , 11]);
|
|
205
|
+
return [4 /*yield*/, this._api.post({
|
|
206
|
+
url: new URL(endpoint),
|
|
207
|
+
options: {
|
|
208
|
+
headers: headers,
|
|
209
|
+
body: body,
|
|
210
|
+
signingServiceInfo: {
|
|
211
|
+
service: 'appsync',
|
|
212
|
+
region: region,
|
|
213
|
+
},
|
|
214
|
+
},
|
|
207
215
|
})];
|
|
208
216
|
case 8:
|
|
209
|
-
|
|
210
|
-
return [
|
|
217
|
+
responsePayload = (_j.sent()).body;
|
|
218
|
+
return [4 /*yield*/, responsePayload.json()];
|
|
211
219
|
case 9:
|
|
220
|
+
response = _j.sent();
|
|
221
|
+
return [3 /*break*/, 11];
|
|
222
|
+
case 10:
|
|
212
223
|
err_1 = _j.sent();
|
|
213
224
|
response = {
|
|
214
225
|
data: {},
|
|
215
226
|
errors: [new graphql_1.GraphQLError(err_1.message, null, null, null, null, err_1)],
|
|
216
227
|
};
|
|
217
|
-
return [3 /*break*/,
|
|
218
|
-
case
|
|
228
|
+
return [3 /*break*/, 11];
|
|
229
|
+
case 11:
|
|
219
230
|
errors = response.errors;
|
|
220
231
|
if (errors && errors.length) {
|
|
221
232
|
throw response;
|
|
@@ -229,16 +240,17 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
229
240
|
var query = _a.query, variables = _a.variables, defaultAuthenticationType = _a.authMode, authToken = _a.authToken;
|
|
230
241
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
231
242
|
var _b;
|
|
232
|
-
var
|
|
243
|
+
var GraphQL = ((_b = core_1.Amplify.getConfig().API) !== null && _b !== void 0 ? _b : {}).GraphQL;
|
|
233
244
|
if (!this.appSyncRealTime) {
|
|
234
245
|
this.appSyncRealTime = new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();
|
|
235
246
|
}
|
|
236
247
|
return this.appSyncRealTime.subscribe({
|
|
237
248
|
query: graphql_1.print(query),
|
|
238
249
|
variables: variables,
|
|
239
|
-
appSyncGraphqlEndpoint:
|
|
240
|
-
region:
|
|
241
|
-
authenticationType:
|
|
250
|
+
appSyncGraphqlEndpoint: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.endpoint,
|
|
251
|
+
region: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.region,
|
|
252
|
+
authenticationType: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.defaultAuthMode,
|
|
253
|
+
apiKey: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.apiKey,
|
|
242
254
|
});
|
|
243
255
|
};
|
|
244
256
|
return InternalGraphQLAPIClass;
|