@aws-amplify/api-graphql 4.4.1 → 4.4.2-events.538dd9f.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/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js +98 -0
- package/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js.map +1 -0
- package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +34 -731
- package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
- package/dist/cjs/Providers/AWSWebSocketProvider/appsyncUrl.js +112 -0
- package/dist/cjs/Providers/AWSWebSocketProvider/appsyncUrl.js.map +1 -0
- package/dist/cjs/Providers/AWSWebSocketProvider/authHeaders.js +99 -0
- package/dist/cjs/Providers/AWSWebSocketProvider/authHeaders.js.map +1 -0
- package/dist/cjs/Providers/AWSWebSocketProvider/index.js +624 -0
- package/dist/cjs/Providers/AWSWebSocketProvider/index.js.map +1 -0
- package/dist/cjs/Providers/constants.js +32 -2
- package/dist/cjs/Providers/constants.js.map +1 -1
- package/dist/cjs/index.js +4 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internals/InternalGraphQLAPI.js +8 -67
- package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
- package/dist/cjs/internals/events/appsyncRequest.js +97 -0
- package/dist/cjs/internals/events/appsyncRequest.js.map +1 -0
- package/dist/cjs/internals/events/index.js +73 -0
- package/dist/cjs/internals/events/index.js.map +1 -0
- package/dist/cjs/internals/events/types.js +6 -0
- package/dist/cjs/internals/events/types.js.map +1 -0
- package/dist/cjs/internals/events/utils.js +57 -0
- package/dist/cjs/internals/events/utils.js.map +1 -0
- package/dist/cjs/internals/graphqlAuth.js +64 -0
- package/dist/cjs/internals/graphqlAuth.js.map +1 -0
- package/dist/cjs/internals/graphqlRequest.js +20 -0
- package/dist/cjs/internals/graphqlRequest.js.map +1 -0
- package/dist/cjs/utils/ReconnectionMonitor.js +1 -1
- package/dist/cjs/utils/ReconnectionMonitor.js.map +1 -1
- package/dist/esm/Providers/AWSAppSyncEventsProvider/index.d.ts +43 -0
- package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs +97 -0
- package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs.map +1 -0
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +24 -71
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +34 -731
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
- package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.d.ts +21 -0
- package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs +106 -0
- package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs.map +1 -0
- package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.d.ts +8 -0
- package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs +97 -0
- package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs.map +1 -0
- package/dist/esm/Providers/AWSWebSocketProvider/index.d.ts +89 -0
- package/dist/esm/Providers/AWSWebSocketProvider/index.mjs +622 -0
- package/dist/esm/Providers/AWSWebSocketProvider/index.mjs.map +1 -0
- package/dist/esm/Providers/constants.d.ts +33 -3
- package/dist/esm/Providers/constants.mjs +32 -2
- package/dist/esm/Providers/constants.mjs.map +1 -1
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.mjs +2 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.d.ts +0 -1
- package/dist/esm/internals/InternalGraphQLAPI.mjs +9 -68
- package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
- package/dist/esm/internals/events/appsyncRequest.d.ts +14 -0
- package/dist/esm/internals/events/appsyncRequest.mjs +96 -0
- package/dist/esm/internals/events/appsyncRequest.mjs.map +1 -0
- package/dist/esm/internals/events/index.d.ts +17 -0
- package/dist/esm/internals/events/index.mjs +69 -0
- package/dist/esm/internals/events/index.mjs.map +1 -0
- package/dist/esm/internals/events/types.d.ts +23 -0
- package/dist/esm/internals/events/types.mjs +2 -0
- package/dist/esm/internals/events/types.mjs.map +1 -0
- package/dist/esm/internals/events/utils.d.ts +16 -0
- package/dist/esm/internals/events/utils.mjs +53 -0
- package/dist/esm/internals/events/utils.mjs.map +1 -0
- package/dist/esm/internals/graphqlAuth.d.ts +3 -0
- package/dist/esm/internals/graphqlAuth.mjs +64 -0
- package/dist/esm/internals/graphqlAuth.mjs.map +1 -0
- package/dist/esm/internals/graphqlRequest.d.ts +3 -0
- package/dist/esm/internals/graphqlRequest.mjs +18 -0
- package/dist/esm/internals/graphqlRequest.mjs.map +1 -0
- package/dist/esm/utils/ConnectionStateMonitor.d.ts +29 -1
- package/dist/esm/utils/ReconnectionMonitor.d.ts +1 -1
- package/dist/esm/utils/ReconnectionMonitor.mjs +1 -1
- package/dist/esm/utils/ReconnectionMonitor.mjs.map +1 -1
- package/package.json +4 -4
- package/src/Providers/AWSAppSyncEventsProvider/index.ts +192 -0
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +56 -1049
- package/src/Providers/AWSWebSocketProvider/appsyncUrl.ts +151 -0
- package/src/Providers/AWSWebSocketProvider/authHeaders.ts +146 -0
- package/src/Providers/AWSWebSocketProvider/index.ts +932 -0
- package/src/Providers/constants.ts +32 -2
- package/src/index.ts +5 -0
- package/src/internals/InternalGraphQLAPI.ts +15 -102
- package/src/internals/events/appsyncRequest.ts +169 -0
- package/src/internals/events/index.ts +138 -0
- package/src/internals/events/types.ts +35 -0
- package/src/internals/events/utils.ts +77 -0
- package/src/internals/graphqlAuth.ts +87 -0
- package/src/internals/graphqlRequest.ts +30 -0
- package/src/utils/ConnectionStateMonitor.ts +2 -13
- package/src/utils/ReconnectionMonitor.ts +1 -1
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.closeAll = exports.post = exports.connect = void 0;
|
|
7
|
+
const core_1 = require("@aws-amplify/core");
|
|
8
|
+
const AWSAppSyncEventsProvider_1 = require("../../Providers/AWSAppSyncEventsProvider");
|
|
9
|
+
const appsyncRequest_1 = require("./appsyncRequest");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
/**
|
|
12
|
+
* Establish a WebSocket connection to an Events channel
|
|
13
|
+
*
|
|
14
|
+
*/
|
|
15
|
+
async function connect(channelName, options) {
|
|
16
|
+
const providerOptions = (0, utils_1.configure)();
|
|
17
|
+
providerOptions.authenticationType = (0, utils_1.normalizeAuth)(options?.authMode, providerOptions.authenticationType);
|
|
18
|
+
await AWSAppSyncEventsProvider_1.AppSyncEventProvider.connect(providerOptions);
|
|
19
|
+
let _subscription;
|
|
20
|
+
const sub = (observer, subOptions) => {
|
|
21
|
+
const subscribeOptions = { ...providerOptions, query: channelName };
|
|
22
|
+
subscribeOptions.authenticationType = (0, utils_1.normalizeAuth)(subOptions?.authMode, subscribeOptions.authenticationType);
|
|
23
|
+
_subscription = AWSAppSyncEventsProvider_1.AppSyncEventProvider
|
|
24
|
+
.subscribe(subscribeOptions)
|
|
25
|
+
.subscribe(observer);
|
|
26
|
+
return _subscription;
|
|
27
|
+
};
|
|
28
|
+
const close = () => {
|
|
29
|
+
_subscription && _subscription.unsubscribe();
|
|
30
|
+
};
|
|
31
|
+
return {
|
|
32
|
+
/**
|
|
33
|
+
* Subscribe to incoming events
|
|
34
|
+
*/
|
|
35
|
+
subscribe: sub,
|
|
36
|
+
/**
|
|
37
|
+
* Close channel and any active subscriptions
|
|
38
|
+
*/
|
|
39
|
+
close,
|
|
40
|
+
// publish: pub,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
exports.connect = connect;
|
|
44
|
+
/**
|
|
45
|
+
* Publish events to a channel via REST request
|
|
46
|
+
*
|
|
47
|
+
* @param channelName - publish destination
|
|
48
|
+
* @param event - JSON-serializable value or an array of values
|
|
49
|
+
* @param options
|
|
50
|
+
*/
|
|
51
|
+
async function post(channelName, event, options) {
|
|
52
|
+
const providerOptions = (0, utils_1.configure)();
|
|
53
|
+
providerOptions.authenticationType = (0, utils_1.normalizeAuth)(options?.authMode, providerOptions.authenticationType);
|
|
54
|
+
// trailing slash required in publish
|
|
55
|
+
const normalizedChannelName = channelName[0] === '/' ? channelName : `/${channelName}`;
|
|
56
|
+
const publishOptions = {
|
|
57
|
+
...providerOptions,
|
|
58
|
+
query: normalizedChannelName,
|
|
59
|
+
variables: (0, utils_1.serializeEvents)(event),
|
|
60
|
+
authToken: options?.authToken,
|
|
61
|
+
};
|
|
62
|
+
const abortController = new AbortController();
|
|
63
|
+
const res = await (0, appsyncRequest_1.appsyncRequest)(core_1.Amplify, publishOptions, {}, abortController);
|
|
64
|
+
if (res.failed?.length > 0) {
|
|
65
|
+
return res.failed;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.post = post;
|
|
69
|
+
function closeAll() {
|
|
70
|
+
AWSAppSyncEventsProvider_1.AppSyncEventProvider.close();
|
|
71
|
+
}
|
|
72
|
+
exports.closeAll = closeAll;
|
|
73
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/internals/events/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.closeAll = exports.post = exports.connect = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst AWSAppSyncEventsProvider_1 = require(\"../../Providers/AWSAppSyncEventsProvider\");\nconst appsyncRequest_1 = require(\"./appsyncRequest\");\nconst utils_1 = require(\"./utils\");\n/**\n * Establish a WebSocket connection to an Events channel\n *\n */\nasync function connect(channelName, options) {\n const providerOptions = (0, utils_1.configure)();\n providerOptions.authenticationType = (0, utils_1.normalizeAuth)(options?.authMode, providerOptions.authenticationType);\n await AWSAppSyncEventsProvider_1.AppSyncEventProvider.connect(providerOptions);\n let _subscription;\n const sub = (observer, subOptions) => {\n const subscribeOptions = { ...providerOptions, query: channelName };\n subscribeOptions.authenticationType = (0, utils_1.normalizeAuth)(subOptions?.authMode, subscribeOptions.authenticationType);\n _subscription = AWSAppSyncEventsProvider_1.AppSyncEventProvider\n .subscribe(subscribeOptions)\n .subscribe(observer);\n return _subscription;\n };\n // WS publish is not enabled in the service yet. It will be a follow up feature\n const _pub = async (event, pubOptions) => {\n const publishOptions = {\n ...providerOptions,\n query: channelName,\n variables: event,\n };\n publishOptions.authenticationType = (0, utils_1.normalizeAuth)(pubOptions?.authMode, publishOptions.authenticationType);\n return AWSAppSyncEventsProvider_1.AppSyncEventProvider.publish(publishOptions);\n };\n const close = () => {\n _subscription && _subscription.unsubscribe();\n };\n return {\n /**\n * Subscribe to incoming events\n */\n subscribe: sub,\n /**\n * Close channel and any active subscriptions\n */\n close,\n // publish: pub,\n };\n}\nexports.connect = connect;\n/**\n * Publish events to a channel via REST request\n *\n * @param channelName - publish destination\n * @param event - JSON-serializable value or an array of values\n * @param options\n */\nasync function post(channelName, event, options) {\n const providerOptions = (0, utils_1.configure)();\n providerOptions.authenticationType = (0, utils_1.normalizeAuth)(options?.authMode, providerOptions.authenticationType);\n // trailing slash required in publish\n const normalizedChannelName = channelName[0] === '/' ? channelName : `/${channelName}`;\n const publishOptions = {\n ...providerOptions,\n query: normalizedChannelName,\n variables: (0, utils_1.serializeEvents)(event),\n authToken: options?.authToken,\n };\n const abortController = new AbortController();\n const res = await (0, appsyncRequest_1.appsyncRequest)(core_1.Amplify, publishOptions, {}, abortController);\n if (res.failed?.length > 0) {\n return res.failed;\n }\n}\nexports.post = post;\nfunction closeAll() {\n AWSAppSyncEventsProvider_1.AppSyncEventProv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,MAAM,GAAG,CAAC,EAAE;AAChC,QAAQ,OAAO,GAAG,CAAC,MAAM,CAAC;AAC1B,KAAK;AACL,CAAC;AACD,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;AACpB,SAAS,QAAQ,GAAG;AACpB,IAAI,0BAA0B,CAAC,oBAAoB,CAAC,KAAK,EAAE,CAAC;AAC5D,CAAC;AACD,OAAO,CAAC,QAAQ,GAAG,QAAQ;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../../src/internals/events/types.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;;"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.serializeEvents = exports.configure = exports.normalizeAuth = void 0;
|
|
5
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
const core_1 = require("@aws-amplify/core");
|
|
8
|
+
const normalizeAuth = (explicitAuthMode, defaultAuthMode) => {
|
|
9
|
+
if (!explicitAuthMode) {
|
|
10
|
+
return defaultAuthMode;
|
|
11
|
+
}
|
|
12
|
+
if (explicitAuthMode === 'identityPool') {
|
|
13
|
+
return 'iam';
|
|
14
|
+
}
|
|
15
|
+
return explicitAuthMode;
|
|
16
|
+
};
|
|
17
|
+
exports.normalizeAuth = normalizeAuth;
|
|
18
|
+
const configure = () => {
|
|
19
|
+
const config = core_1.Amplify.getConfig();
|
|
20
|
+
const eventsConfig = config.API?.Events;
|
|
21
|
+
if (!eventsConfig) {
|
|
22
|
+
throw new Error('Amplify configuration is missing. Have you called Amplify.configure()?');
|
|
23
|
+
}
|
|
24
|
+
const configAuthMode = (0, exports.normalizeAuth)(eventsConfig.defaultAuthMode, 'apiKey');
|
|
25
|
+
const options = {
|
|
26
|
+
appSyncGraphqlEndpoint: eventsConfig.endpoint,
|
|
27
|
+
region: eventsConfig.region,
|
|
28
|
+
authenticationType: configAuthMode,
|
|
29
|
+
apiKey: eventsConfig.apiKey,
|
|
30
|
+
};
|
|
31
|
+
return options;
|
|
32
|
+
};
|
|
33
|
+
exports.configure = configure;
|
|
34
|
+
/**
|
|
35
|
+
* Event API expects and array of JSON strings
|
|
36
|
+
*
|
|
37
|
+
* @param events - JSON-serializable value or an array of values
|
|
38
|
+
* @returns array of JSON strings
|
|
39
|
+
*/
|
|
40
|
+
const serializeEvents = (events) => {
|
|
41
|
+
if (Array.isArray(events)) {
|
|
42
|
+
return events.map((ev, idx) => {
|
|
43
|
+
const eventJson = JSON.stringify(ev);
|
|
44
|
+
if (eventJson === undefined) {
|
|
45
|
+
throw new Error(`Event must be a valid JSON value. Received ${ev} at index ${idx}`);
|
|
46
|
+
}
|
|
47
|
+
return eventJson;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
const eventJson = JSON.stringify(events);
|
|
51
|
+
if (eventJson === undefined) {
|
|
52
|
+
throw new Error(`Event must be a valid JSON value. Received ${events}`);
|
|
53
|
+
}
|
|
54
|
+
return [eventJson];
|
|
55
|
+
};
|
|
56
|
+
exports.serializeEvents = serializeEvents;
|
|
57
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../../src/internals/events/utils.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.serializeEvents = exports.configure = exports.normalizeAuth = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst core_1 = require(\"@aws-amplify/core\");\nconst normalizeAuth = (explicitAuthMode, defaultAuthMode) => {\n if (!explicitAuthMode) {\n return defaultAuthMode;\n }\n if (explicitAuthMode === 'identityPool') {\n return 'iam';\n }\n return explicitAuthMode;\n};\nexports.normalizeAuth = normalizeAuth;\nconst configure = () => {\n const config = core_1.Amplify.getConfig();\n const eventsConfig = config.API?.Events;\n if (!eventsConfig) {\n throw new Error('Amplify configuration is missing. Have you called Amplify.configure()?');\n }\n const configAuthMode = (0, exports.normalizeAuth)(eventsConfig.defaultAuthMode, 'apiKey');\n const options = {\n appSyncGraphqlEndpoint: eventsConfig.endpoint,\n region: eventsConfig.region,\n authenticationType: configAuthMode,\n apiKey: eventsConfig.apiKey,\n };\n return options;\n};\nexports.configure = configure;\n/**\n * Event API expects and array of JSON strings\n *\n * @param events - JSON-serializable value or an array of values\n * @returns array of JSON strings\n */\nconst serializeEvents = (events) => {\n if (Array.isArray(events)) {\n return events.map((ev, idx) => {\n const eventJson = JSON.stringify(ev);\n if (eventJson === undefined) {\n throw new Error(`Event must be a valid JSON value. Received ${ev} at index ${idx}`);\n }\n return eventJson;\n });\n }\n const eventJson = JSON.stringify(events);\n if (eventJson === undefined) {\n throw new Error(`Event must be a valid JSON value. Received ${events}`);\n }\n return [eventJson];\n};\nexports.serializeEvents = serializeEvents;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,eAAe,GAAG,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;AAC7E;AACA;AACA,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,aAAa,GAAG,CAAC,gBAAgB,EAAE,eAAe,KAAK;AAC7D,IAAI,IAAI,CAAC,gBAAgB,EAAE;AAC3B,QAAQ,OAAO,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AAI,KAAK,CAAC,CAAC,2CAA2C,EAAE,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AACpG,aAAa;AACb,YAAY,OAAO,SAAS,CAAC;AAC7B,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAC7C,IAAI,IAAI,SAAS,KAAK,SAAS,EAAE;AACjC,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,2CAA2C,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AAChF,KAAK;AACL,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;AACvB,CAAC,CAAC;AACF,OAAO,CAAC,eAAe,GAAG,eAAe;;"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.headerBasedAuth = void 0;
|
|
7
|
+
const errors_1 = require("../utils/errors");
|
|
8
|
+
const constants_1 = require("../utils/errors/constants");
|
|
9
|
+
async function headerBasedAuth(amplify, authMode, apiKey, additionalHeaders = {}) {
|
|
10
|
+
let headers = {};
|
|
11
|
+
switch (authMode) {
|
|
12
|
+
case 'apiKey':
|
|
13
|
+
if (!apiKey) {
|
|
14
|
+
throw new errors_1.GraphQLApiError(constants_1.NO_API_KEY);
|
|
15
|
+
}
|
|
16
|
+
headers = {
|
|
17
|
+
'X-Api-Key': apiKey,
|
|
18
|
+
};
|
|
19
|
+
break;
|
|
20
|
+
case 'iam': {
|
|
21
|
+
const session = await amplify.Auth.fetchAuthSession();
|
|
22
|
+
if (session.credentials === undefined) {
|
|
23
|
+
throw new errors_1.GraphQLApiError(constants_1.NO_VALID_CREDENTIALS);
|
|
24
|
+
}
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
case 'oidc':
|
|
28
|
+
case 'userPool': {
|
|
29
|
+
let token;
|
|
30
|
+
try {
|
|
31
|
+
token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
// fetchAuthSession failed
|
|
35
|
+
throw new errors_1.GraphQLApiError({
|
|
36
|
+
...constants_1.NO_SIGNED_IN_USER,
|
|
37
|
+
underlyingError: e,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
// `fetchAuthSession()` succeeded but didn't return `tokens`.
|
|
41
|
+
// This may happen when unauthenticated access is enabled and there is
|
|
42
|
+
// no user signed in.
|
|
43
|
+
if (!token) {
|
|
44
|
+
throw new errors_1.GraphQLApiError(constants_1.NO_VALID_AUTH_TOKEN);
|
|
45
|
+
}
|
|
46
|
+
headers = {
|
|
47
|
+
Authorization: token,
|
|
48
|
+
};
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case 'lambda':
|
|
52
|
+
if (typeof additionalHeaders === 'object' &&
|
|
53
|
+
!additionalHeaders.Authorization) {
|
|
54
|
+
throw new errors_1.GraphQLApiError(constants_1.NO_AUTH_TOKEN_HEADER);
|
|
55
|
+
}
|
|
56
|
+
headers = {
|
|
57
|
+
Authorization: additionalHeaders.Authorization,
|
|
58
|
+
};
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
return headers;
|
|
62
|
+
}
|
|
63
|
+
exports.headerBasedAuth = headerBasedAuth;
|
|
64
|
+
//# sourceMappingURL=graphqlAuth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphqlAuth.js","sources":["../../../src/internals/graphqlAuth.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.headerBasedAuth = void 0;\nconst errors_1 = require(\"../utils/errors\");\nconst constants_1 = require(\"../utils/errors/constants\");\nasync function headerBasedAuth(amplify, authMode, apiKey, additionalHeaders = {}) {\n let headers = {};\n switch (authMode) {\n case 'apiKey':\n if (!apiKey) {\n throw new errors_1.GraphQLApiError(constants_1.NO_API_KEY);\n }\n headers = {\n 'X-Api-Key': apiKey,\n };\n break;\n case 'iam': {\n const session = await amplify.Auth.fetchAuthSession();\n if (session.credentials === undefined) {\n throw new errors_1.GraphQLApiError(constants_1.NO_VALID_CREDENTIALS);\n }\n break;\n }\n case 'oidc':\n case 'userPool': {\n let token;\n try {\n token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();\n }\n catch (e) {\n // fetchAuthSession failed\n throw new errors_1.GraphQLApiError({\n ...constants_1.NO_SIGNED_IN_USER,\n underlyingError: e,\n });\n }\n // `fetchAuthSession()` succeeded but didn't return `tokens`.\n // This may happen when unauthenticated access is enabled and there is\n // no user signed in.\n if (!token) {\n throw new errors_1.GraphQLApiError(constants_1.NO_VALID_AUTH_TOKEN);\n }\n headers = {\n Authorization: token,\n };\n break;\n }\n case 'lambda':\n if (typeof additionalHeaders === 'object' &&\n !additionalHeaders.Authorization) {\n throw new errors_1.GraphQLApiError(constants_1.NO_AUTH_TOKEN_HEADER);\n }\n headers = {\n Authorization: additionalHeaders.Authorization,\n };\n break;\n case 'none':\n break;\n default:\n break;\n }\n return headers;\n}\nexports.headerBasedAuth = headerBasedAuth;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC;AACjC,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC5C,MAAM,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACzD,eAAe,eAAe,CAAC,OAAO,EAAE,QAAQ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C;AACpF,aAAa;AACb,YAAY,OAAO,GAAG;AACtB,gBAAgB,aAAa,EAAE,KAAK;AACpC,aAAa,CAAC;AACd,YAAY,MAAM;AAClB,SAAS;AACT,QAAQ,KAAK,QAAQ;AACrB,YAAY,IAAI,OAAO,iBAAiB,KAAK,QAAQ;AACrD,gBAAgB,CAAC,iBAAiB,CAAC,aAAa,EAAE;AAClD,gBAAgB,MAAM,IAAI,QAAQ,CAAC,eAAe,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAAC;AACrF,aAAa;AACb,YAAY,OAAO,GAAG;AACtB,gBAAgB,aAAa,EAAE,iBAAiB,CAAC,aAAa;AAC9D,aAAa,CAAC;AACd,YAAY,MAAM;AAKlB,KAAK;AACL,IAAI,OAAO,OAAO,CAAC;AACnB,CAAC;AACD,OAAO,CAAC,eAAe,GAAG,eAAe;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.graphqlRequest = void 0;
|
|
7
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
|
+
const internals_1 = require("@aws-amplify/api-rest/internals");
|
|
9
|
+
async function graphqlRequest(amplify, url, options, abortController, _post) {
|
|
10
|
+
const p = _post ?? internals_1.post;
|
|
11
|
+
const { body: responseBody } = await p(amplify, {
|
|
12
|
+
url: new utils_1.AmplifyUrl(url),
|
|
13
|
+
options,
|
|
14
|
+
abortController,
|
|
15
|
+
});
|
|
16
|
+
const response = await responseBody.json();
|
|
17
|
+
return response;
|
|
18
|
+
}
|
|
19
|
+
exports.graphqlRequest = graphqlRequest;
|
|
20
|
+
//# sourceMappingURL=graphqlRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphqlRequest.js","sources":["../../../src/internals/graphqlRequest.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.graphqlRequest = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst internals_1 = require(\"@aws-amplify/api-rest/internals\");\nasync function graphqlRequest(amplify, url, options, abortController, _post) {\n const p = _post ?? internals_1.post;\n const { body: responseBody } = await p(amplify, {\n url: new utils_1.AmplifyUrl(url),\n options,\n abortController,\n });\n const response = await responseBody.json();\n return response;\n}\nexports.graphqlRequest = graphqlRequest;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;AAChC,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,WAAW,GAAG,OAAO,CAAC,iCAAiC,CAAC,CAAC;AAC/D,eAAe,cAAc,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE;AAC7E,IAAI,MAAM,CAAC,GAAG,KAAK,IAAI,WAAW,CAAC,IAAI,CAAC;AACxC,IAAI,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC,CAAC,OAAO,EAAE;AACpD,QAAQ,GAAG,EAAE,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;AACxC,QAAQ,OAAO;AACf,QAAQ,eAAe;AACvB,KAAK,CAAC,CAAC;AACP,IAAI,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,IAAI,EAAE,CAAC;AAC/C,IAAI,OAAO,QAAQ,CAAC;AACpB,CAAC;AACD,OAAO,CAAC,cAAc,GAAG,cAAc;;"}
|
|
@@ -10,7 +10,7 @@ var ReconnectEvent;
|
|
|
10
10
|
})(ReconnectEvent = exports.ReconnectEvent || (exports.ReconnectEvent = {}));
|
|
11
11
|
/**
|
|
12
12
|
* Captures the reconnect event logic used to determine when to reconnect to PubSub providers.
|
|
13
|
-
*
|
|
13
|
+
* Reconnect attempts are delayed by 5 seconds to let the interface settle.
|
|
14
14
|
* Attempting to reconnect only once creates unrecoverable states when the network state isn't
|
|
15
15
|
* supported by the browser, so this keeps retrying every minute until halted.
|
|
16
16
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReconnectionMonitor.js","sources":["../../../src/utils/ReconnectionMonitor.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ReconnectionMonitor = exports.ReconnectEvent = void 0;\nconst constants_1 = require(\"../Providers/constants\");\nvar ReconnectEvent;\n(function (ReconnectEvent) {\n ReconnectEvent[\"START_RECONNECT\"] = \"START_RECONNECT\";\n ReconnectEvent[\"HALT_RECONNECT\"] = \"HALT_RECONNECT\";\n})(ReconnectEvent = exports.ReconnectEvent || (exports.ReconnectEvent = {}));\n/**\n * Captures the reconnect event logic used to determine when to reconnect to PubSub providers.\n *
|
|
1
|
+
{"version":3,"file":"ReconnectionMonitor.js","sources":["../../../src/utils/ReconnectionMonitor.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.ReconnectionMonitor = exports.ReconnectEvent = void 0;\nconst constants_1 = require(\"../Providers/constants\");\nvar ReconnectEvent;\n(function (ReconnectEvent) {\n ReconnectEvent[\"START_RECONNECT\"] = \"START_RECONNECT\";\n ReconnectEvent[\"HALT_RECONNECT\"] = \"HALT_RECONNECT\";\n})(ReconnectEvent = exports.ReconnectEvent || (exports.ReconnectEvent = {}));\n/**\n * Captures the reconnect event logic used to determine when to reconnect to PubSub providers.\n * Reconnect attempts are delayed by 5 seconds to let the interface settle.\n * Attempting to reconnect only once creates unrecoverable states when the network state isn't\n * supported by the browser, so this keeps retrying every minute until halted.\n */\nclass ReconnectionMonitor {\n constructor() {\n this.reconnectObservers = [];\n }\n /**\n * Add reconnect observer to the list of observers to alert on reconnect\n */\n addObserver(reconnectObserver) {\n this.reconnectObservers.push(reconnectObserver);\n }\n /**\n * Given a reconnect event, start the appropriate behavior\n */\n record(event) {\n if (event === ReconnectEvent.START_RECONNECT) {\n // If the reconnection hasn't been started\n if (this.reconnectSetTimeoutId === undefined &&\n this.reconnectIntervalId === undefined) {\n this.reconnectSetTimeoutId = setTimeout(() => {\n // Reconnect now\n this._triggerReconnect();\n // Retry reconnect every periodically until it works\n this.reconnectIntervalId = setInterval(() => {\n this._triggerReconnect();\n }, constants_1.RECONNECT_INTERVAL);\n }, constants_1.RECONNECT_DELAY);\n }\n }\n if (event === ReconnectEvent.HALT_RECONNECT) {\n if (this.reconnectIntervalId) {\n clearInterval(this.reconnectIntervalId);\n this.reconnectIntervalId = undefined;\n }\n if (this.reconnectSetTimeoutId) {\n clearTimeout(this.reconnectSetTimeoutId);\n this.reconnectSetTimeoutId = undefined;\n }\n }\n }\n /**\n * Complete all reconnect observers\n */\n close() {\n this.reconnectObservers.forEach(reconnectObserver => {\n reconnectObserver.complete?.();\n });\n }\n _triggerReconnect() {\n this.reconnectObservers.forEach(reconnectObserver => {\n reconnectObserver.next?.();\n });\n }\n}\nexports.ReconnectionMonitor = ReconnectionMonitor;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,mBAAmB,GAAG,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;AAC9D,MAAM,WAAW,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC;AACtD,IAAI,cAAc,CAAC;AACnB,CAAC,UAAU,cAAc,EAAE;AAC3B,IAAI,cAAc,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,CAAC;AAC1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AAY,IAAI,IAAI,CAAC,qBAAqB,EAAE;AAC5C,gBAAgB,YAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;AACzD,gBAAgB,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;AACvD,aAAa;AACb,SAAS;AACT,KAAK;AACL;AACA;AACA;AACA,IAAI,KAAK,GAAG;AACZ,QAAQ,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,iBAAiB,IAAI;AAC7D,YAAY,iBAAiB,CAAC,QAAQ,IAAI,CAAC;AAC3C,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,iBAAiB,GAAG;AACxB,QAAQ,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,iBAAiB,IAAI;AAC7D,YAAY,iBAAiB,CAAC,IAAI,IAAI,CAAC;AACvC,SAAS,CAAC,CAAC;AACX,KAAK;AACL,CAAC;AACD,OAAO,CAAC,mBAAmB,GAAG,mBAAmB;;"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CustomUserAgentDetails, DocumentType, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
2
|
+
import { CustomHeaders } from '@aws-amplify/data-schema/runtime';
|
|
3
|
+
import { AWSWebSocketProvider } from '../AWSWebSocketProvider';
|
|
4
|
+
type ResolvedGraphQLAuthModes = Exclude<GraphQLAuthMode, 'identityPool'>;
|
|
5
|
+
interface AWSAppSyncEventProviderOptions {
|
|
6
|
+
appSyncGraphqlEndpoint?: string;
|
|
7
|
+
authenticationType?: ResolvedGraphQLAuthModes;
|
|
8
|
+
query?: string;
|
|
9
|
+
variables?: DocumentType;
|
|
10
|
+
apiKey?: string;
|
|
11
|
+
region?: string;
|
|
12
|
+
libraryConfigHeaders?(): Promise<Record<string, unknown> | Headers>;
|
|
13
|
+
additionalHeaders?: CustomHeaders;
|
|
14
|
+
additionalCustomHeaders?: Record<string, string>;
|
|
15
|
+
authToken?: string;
|
|
16
|
+
}
|
|
17
|
+
interface DataResponse {
|
|
18
|
+
id: string;
|
|
19
|
+
payload: string;
|
|
20
|
+
type: string;
|
|
21
|
+
}
|
|
22
|
+
declare class AWSAppSyncEventProvider extends AWSWebSocketProvider {
|
|
23
|
+
constructor();
|
|
24
|
+
getProviderName(): string;
|
|
25
|
+
connect(options: AWSAppSyncEventProviderOptions): Promise<void>;
|
|
26
|
+
subscribe(options?: AWSAppSyncEventProviderOptions, customUserAgentDetails?: CustomUserAgentDetails): import("rxjs").Observable<Record<string, unknown>>;
|
|
27
|
+
publish(options: AWSAppSyncEventProviderOptions, customUserAgentDetails?: CustomUserAgentDetails): Promise<void>;
|
|
28
|
+
protected _prepareSubscriptionPayload({ options, subscriptionId, customUserAgentDetails, additionalCustomHeaders, libraryConfigHeaders, publish, }: {
|
|
29
|
+
options: AWSAppSyncEventProviderOptions;
|
|
30
|
+
subscriptionId: string;
|
|
31
|
+
customUserAgentDetails: CustomUserAgentDetails | undefined;
|
|
32
|
+
additionalCustomHeaders: Record<string, string>;
|
|
33
|
+
libraryConfigHeaders: Record<string, string>;
|
|
34
|
+
publish?: boolean;
|
|
35
|
+
}): Promise<string>;
|
|
36
|
+
protected _handleSubscriptionData(message: MessageEvent): [boolean, DataResponse];
|
|
37
|
+
protected _unsubscribeMessage(subscriptionId: string): {
|
|
38
|
+
id: string;
|
|
39
|
+
type: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export declare const AppSyncEventProvider: AWSAppSyncEventProvider;
|
|
43
|
+
export {};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { USER_AGENT_HEADER, getAmplifyUserAgent } from '@aws-amplify/core/internals/utils';
|
|
2
|
+
import { MESSAGE_TYPES } from '../constants.mjs';
|
|
3
|
+
import { AWSWebSocketProvider } from '../AWSWebSocketProvider/index.mjs';
|
|
4
|
+
import { awsRealTimeHeaderBasedAuth } from '../AWSWebSocketProvider/authHeaders.mjs';
|
|
5
|
+
|
|
6
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
7
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
8
|
+
const PROVIDER_NAME = 'AWSAppSyncEventsProvider';
|
|
9
|
+
const WS_PROTOCOL_NAME = 'aws-appsync-event-ws';
|
|
10
|
+
class AWSAppSyncEventProvider extends AWSWebSocketProvider {
|
|
11
|
+
constructor() {
|
|
12
|
+
super({ providerName: PROVIDER_NAME, wsProtocolName: WS_PROTOCOL_NAME });
|
|
13
|
+
}
|
|
14
|
+
getProviderName() {
|
|
15
|
+
return PROVIDER_NAME;
|
|
16
|
+
}
|
|
17
|
+
async connect(options) {
|
|
18
|
+
super.connect(options);
|
|
19
|
+
}
|
|
20
|
+
subscribe(options, customUserAgentDetails) {
|
|
21
|
+
return super.subscribe(options, customUserAgentDetails).pipe();
|
|
22
|
+
}
|
|
23
|
+
async publish(options, customUserAgentDetails) {
|
|
24
|
+
super.publish(options, customUserAgentDetails);
|
|
25
|
+
}
|
|
26
|
+
async _prepareSubscriptionPayload({ options, subscriptionId, customUserAgentDetails, additionalCustomHeaders, libraryConfigHeaders, publish, }) {
|
|
27
|
+
const { appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, } = options;
|
|
28
|
+
// This will be needed for WS publish
|
|
29
|
+
// const data = {
|
|
30
|
+
// events: [variables],
|
|
31
|
+
// };
|
|
32
|
+
const serializedData = JSON.stringify([variables]);
|
|
33
|
+
const headers = {
|
|
34
|
+
...(await awsRealTimeHeaderBasedAuth({
|
|
35
|
+
apiKey,
|
|
36
|
+
appSyncGraphqlEndpoint,
|
|
37
|
+
authenticationType,
|
|
38
|
+
payload: serializedData,
|
|
39
|
+
canonicalUri: '',
|
|
40
|
+
region,
|
|
41
|
+
additionalCustomHeaders,
|
|
42
|
+
})),
|
|
43
|
+
...libraryConfigHeaders,
|
|
44
|
+
...additionalCustomHeaders,
|
|
45
|
+
[USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),
|
|
46
|
+
};
|
|
47
|
+
// Commented out code will be needed for WS publish
|
|
48
|
+
const subscriptionMessage = {
|
|
49
|
+
id: subscriptionId,
|
|
50
|
+
channel: query,
|
|
51
|
+
// events: [JSON.stringify(variables)],
|
|
52
|
+
authorization: {
|
|
53
|
+
...headers,
|
|
54
|
+
},
|
|
55
|
+
// payload: {
|
|
56
|
+
// events: serializedData,
|
|
57
|
+
// extensions: {
|
|
58
|
+
// authorization: {
|
|
59
|
+
// ...headers,
|
|
60
|
+
// },
|
|
61
|
+
// },
|
|
62
|
+
// },
|
|
63
|
+
type: publish
|
|
64
|
+
? MESSAGE_TYPES.EVENT_PUBLISH
|
|
65
|
+
: MESSAGE_TYPES.EVENT_SUBSCRIBE,
|
|
66
|
+
};
|
|
67
|
+
const serializedSubscriptionMessage = JSON.stringify(subscriptionMessage);
|
|
68
|
+
return serializedSubscriptionMessage;
|
|
69
|
+
}
|
|
70
|
+
_handleSubscriptionData(message) {
|
|
71
|
+
this.logger.debug(`subscription message from AWS AppSync Events: ${message.data}`);
|
|
72
|
+
const { id = '', event: payload, type, } = JSON.parse(String(message.data));
|
|
73
|
+
const { observer = null, query = '', variables = {}, } = this.subscriptionObserverMap.get(id) || {};
|
|
74
|
+
this.logger.debug({ id, observer, query, variables });
|
|
75
|
+
if (type === MESSAGE_TYPES.DATA && payload) {
|
|
76
|
+
const deserializedEvent = JSON.parse(payload);
|
|
77
|
+
if (observer) {
|
|
78
|
+
observer.next(deserializedEvent);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.logger.debug(`observer not found for id: ${id}`);
|
|
82
|
+
}
|
|
83
|
+
return [true, { id, type, payload: deserializedEvent }];
|
|
84
|
+
}
|
|
85
|
+
return [false, { id, type, payload }];
|
|
86
|
+
}
|
|
87
|
+
_unsubscribeMessage(subscriptionId) {
|
|
88
|
+
return {
|
|
89
|
+
id: subscriptionId,
|
|
90
|
+
type: MESSAGE_TYPES.EVENT_STOP,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const AppSyncEventProvider = new AWSAppSyncEventProvider();
|
|
95
|
+
|
|
96
|
+
export { AppSyncEventProvider };
|
|
97
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../../src/Providers/AWSAppSyncEventsProvider/index.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { USER_AGENT_HEADER, getAmplifyUserAgent, } from '@aws-amplify/core/internals/utils';\nimport { MESSAGE_TYPES } from '../constants';\nimport { AWSWebSocketProvider } from '../AWSWebSocketProvider';\nimport { awsRealTimeHeaderBasedAuth } from '../AWSWebSocketProvider/authHeaders';\nconst PROVIDER_NAME = 'AWSAppSyncEventsProvider';\nconst WS_PROTOCOL_NAME = 'aws-appsync-event-ws';\nclass AWSAppSyncEventProvider extends AWSWebSocketProvider {\n constructor() {\n super({ providerName: PROVIDER_NAME, wsProtocolName: WS_PROTOCOL_NAME });\n }\n getProviderName() {\n return PROVIDER_NAME;\n }\n async connect(options) {\n super.connect(options);\n }\n subscribe(options, customUserAgentDetails) {\n return super.subscribe(options, customUserAgentDetails).pipe();\n }\n async publish(options, customUserAgentDetails) {\n super.publish(options, customUserAgentDetails);\n }\n async _prepareSubscriptionPayload({ options, subscriptionId, customUserAgentDetails, additionalCustomHeaders, libraryConfigHeaders, publish, }) {\n const { appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, } = options;\n // This will be needed for WS publish\n // const data = {\n // \tevents: [variables],\n // };\n const serializedData = JSON.stringify([variables]);\n const headers = {\n ...(await awsRealTimeHeaderBasedAuth({\n apiKey,\n appSyncGraphqlEndpoint,\n authenticationType,\n payload: serializedData,\n canonicalUri: '',\n region,\n additionalCustomHeaders,\n })),\n ...libraryConfigHeaders,\n ...additionalCustomHeaders,\n [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),\n };\n // Commented out code will be needed for WS publish\n const subscriptionMessage = {\n id: subscriptionId,\n channel: query,\n // events: [JSON.stringify(variables)],\n authorization: {\n ...headers,\n },\n // payload: {\n // \tevents: serializedData,\n // \textensions: {\n // \t\tauthorization: {\n // \t\t\t...headers,\n // \t\t},\n // \t},\n // },\n type: publish\n ? MESSAGE_TYPES.EVENT_PUBLISH\n : MESSAGE_TYPES.EVENT_SUBSCRIBE,\n };\n const serializedSubscriptionMessage = JSON.stringify(subscriptionMessage);\n return serializedSubscriptionMessage;\n }\n _handleSubscriptionData(message) {\n this.logger.debug(`subscription message from AWS AppSync Events: ${message.data}`);\n const { id = '', event: payload, type, } = JSON.parse(String(message.data));\n const { observer = null, query = '', variables = {}, } = this.subscriptionObserverMap.get(id) || {};\n this.logger.debug({ id, observer, query, variables });\n if (type === MESSAGE_TYPES.DATA && payload) {\n const deserializedEvent = JSON.parse(payload);\n if (observer) {\n observer.next(deserializedEvent);\n }\n else {\n this.logger.debug(`observer not found for id: ${id}`);\n }\n return [true, { id, type, payload: deserializedEvent }];\n }\n return [false, { id, type, payload }];\n }\n _unsubscribeMessage(subscriptionId) {\n return {\n id: subscriptionId,\n type: MESSAGE_TYPES.EVENT_STOP,\n };\n }\n}\nexport const AppSyncEventProvider = new AWSAppSyncEventProvider();\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAKA,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAChD,MAAM,uBAAuB,SAAS,oBAAoB,CAAC;AAC3D,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAC,CAAC;AACjF,KAAK;AACL,IAAI,eAAe,GAAG;AACtB,QAAQ,OAAO,aAAa,CAAC;AAC7B,KAAK;AACL,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE;AAC3B,QAAQ,KAAK,CAAC,OAAO,CAAC,OAAO,CAA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CAAC,CAAC,CAAC;AACtE,aAAa;AACb,YAAY,OAAO,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC,CAAC;AACpE,SAAS;AACT,QAAQ,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;AAC9C,KAAK;AACL,IAAI,mBAAmB,CAAC,cAAc,EAAE;AACxC,QAAQ,OAAO;AACf,YAAY,EAAE,EAAE,cAAc;AAC9B,YAAY,IAAI,EAAE,aAAa,CAAC,UAAU;AAC1C,SAAS,CAAC;AACV,KAAK;AACL,CAAC;AACW,MAAC,oBAAoB,GAAG,IAAI,uBAAuB;;;;"}
|
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
1
|
import { CustomUserAgentDetails, DocumentType, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
3
2
|
import { CustomHeaders } from '@aws-amplify/data-schema/runtime';
|
|
4
|
-
import {
|
|
5
|
-
import { SUBSCRIPTION_STATUS } from '../constants';
|
|
3
|
+
import { AWSWebSocketProvider } from '../AWSWebSocketProvider';
|
|
6
4
|
type ResolvedGraphQLAuthModes = Exclude<GraphQLAuthMode, 'identityPool'>;
|
|
7
|
-
export interface ObserverQuery {
|
|
8
|
-
observer: PubSubContentObserver;
|
|
9
|
-
query: string;
|
|
10
|
-
variables: Record<string, DocumentType>;
|
|
11
|
-
subscriptionState: SUBSCRIPTION_STATUS;
|
|
12
|
-
subscriptionReadyCallback?(): void;
|
|
13
|
-
subscriptionFailedCallback?(reason?: any): void;
|
|
14
|
-
startAckTimeoutId?: ReturnType<typeof setTimeout>;
|
|
15
|
-
}
|
|
16
5
|
export interface AWSAppSyncRealTimeProviderOptions {
|
|
17
6
|
appSyncGraphqlEndpoint?: string;
|
|
18
7
|
authenticationType?: ResolvedGraphQLAuthModes;
|
|
19
8
|
query?: string;
|
|
20
|
-
variables?:
|
|
9
|
+
variables?: DocumentType;
|
|
21
10
|
apiKey?: string;
|
|
22
11
|
region?: string;
|
|
23
12
|
libraryConfigHeaders?(): Promise<Record<string, unknown> | Headers>;
|
|
@@ -25,65 +14,29 @@ export interface AWSAppSyncRealTimeProviderOptions {
|
|
|
25
14
|
additionalCustomHeaders?: Record<string, string>;
|
|
26
15
|
authToken?: string;
|
|
27
16
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
private readonly connectionStateMonitor;
|
|
38
|
-
private readonly reconnectionMonitor;
|
|
39
|
-
private connectionStateMonitorSubscription;
|
|
17
|
+
interface DataObject extends Record<string, unknown> {
|
|
18
|
+
data: Record<string, unknown>;
|
|
19
|
+
}
|
|
20
|
+
interface DataPayload {
|
|
21
|
+
id: string;
|
|
22
|
+
payload: DataObject;
|
|
23
|
+
type: string;
|
|
24
|
+
}
|
|
25
|
+
export declare class AWSAppSyncRealTimeProvider extends AWSWebSocketProvider {
|
|
40
26
|
constructor();
|
|
41
|
-
/**
|
|
42
|
-
* Mark the socket closed and release all active listeners
|
|
43
|
-
*/
|
|
44
|
-
close(): void;
|
|
45
|
-
getNewWebSocket(url: string, protocol: string[]): WebSocket;
|
|
46
27
|
getProviderName(): string;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
*/
|
|
61
|
-
private _extractNonAuthHeaders;
|
|
62
|
-
/**
|
|
63
|
-
*
|
|
64
|
-
* @param headers - http headers
|
|
65
|
-
* @returns uri-encoded query parameters derived from custom headers
|
|
66
|
-
*/
|
|
67
|
-
private _queryParamsFromCustomHeaders;
|
|
68
|
-
/**
|
|
69
|
-
* Normalizes AppSync realtime endpoint URL
|
|
70
|
-
*
|
|
71
|
-
* @param appSyncGraphqlEndpoint - AppSync endpointUri from config
|
|
72
|
-
* @param urlParams - URLSearchParams
|
|
73
|
-
* @returns fully resolved string realtime endpoint URL
|
|
74
|
-
*/
|
|
75
|
-
private _realtimeUrlWithQueryString;
|
|
76
|
-
private _initializeWebSocketConnection;
|
|
77
|
-
private _initializeRetryableHandshake;
|
|
78
|
-
/**
|
|
79
|
-
*
|
|
80
|
-
* @param subprotocol -
|
|
81
|
-
*/
|
|
82
|
-
private _initializeHandshake;
|
|
83
|
-
private _awsRealTimeHeaderBasedAuth;
|
|
84
|
-
private _awsAuthTokenHeader;
|
|
85
|
-
private _awsRealTimeApiKeyHeader;
|
|
86
|
-
private _awsRealTimeIAMHeader;
|
|
87
|
-
private _customAuthHeader;
|
|
28
|
+
subscribe(options?: AWSAppSyncRealTimeProviderOptions, customUserAgentDetails?: CustomUserAgentDetails): import("rxjs").Observable<Record<string, unknown>>;
|
|
29
|
+
protected _prepareSubscriptionPayload({ options, subscriptionId, customUserAgentDetails, additionalCustomHeaders, libraryConfigHeaders, }: {
|
|
30
|
+
options: AWSAppSyncRealTimeProviderOptions;
|
|
31
|
+
subscriptionId: string;
|
|
32
|
+
customUserAgentDetails: CustomUserAgentDetails | undefined;
|
|
33
|
+
additionalCustomHeaders: Record<string, string>;
|
|
34
|
+
libraryConfigHeaders: Record<string, string>;
|
|
35
|
+
}): Promise<string>;
|
|
36
|
+
protected _handleSubscriptionData(message: MessageEvent): [boolean, DataPayload];
|
|
37
|
+
protected _unsubscribeMessage(subscriptionId: string): {
|
|
38
|
+
id: string;
|
|
39
|
+
type: string;
|
|
40
|
+
};
|
|
88
41
|
}
|
|
89
42
|
export {};
|