@aws-amplify/api-graphql 4.4.1-events.619318.0 → 4.4.1

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.
Files changed (98) hide show
  1. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +732 -35
  2. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
  3. package/dist/cjs/Providers/constants.js +2 -32
  4. package/dist/cjs/Providers/constants.js.map +1 -1
  5. package/dist/cjs/index.js +1 -4
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/cjs/internals/InternalGraphQLAPI.js +67 -8
  8. package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
  9. package/dist/cjs/utils/ReconnectionMonitor.js +1 -1
  10. package/dist/cjs/utils/ReconnectionMonitor.js.map +1 -1
  11. package/dist/cjs/utils/resolveConfig.js +0 -19
  12. package/dist/cjs/utils/resolveConfig.js.map +1 -1
  13. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +71 -24
  14. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +732 -35
  15. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
  16. package/dist/esm/Providers/constants.d.ts +3 -33
  17. package/dist/esm/Providers/constants.mjs +2 -32
  18. package/dist/esm/Providers/constants.mjs.map +1 -1
  19. package/dist/esm/index.d.ts +0 -3
  20. package/dist/esm/index.mjs +0 -2
  21. package/dist/esm/index.mjs.map +1 -1
  22. package/dist/esm/internals/InternalGraphQLAPI.d.ts +1 -0
  23. package/dist/esm/internals/InternalGraphQLAPI.mjs +68 -9
  24. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  25. package/dist/esm/utils/ConnectionStateMonitor.d.ts +1 -29
  26. package/dist/esm/utils/ReconnectionMonitor.d.ts +1 -1
  27. package/dist/esm/utils/ReconnectionMonitor.mjs +1 -1
  28. package/dist/esm/utils/ReconnectionMonitor.mjs.map +1 -1
  29. package/dist/esm/utils/resolveConfig.mjs +0 -19
  30. package/dist/esm/utils/resolveConfig.mjs.map +1 -1
  31. package/package.json +4 -4
  32. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +1051 -58
  33. package/src/Providers/constants.ts +2 -32
  34. package/src/index.ts +0 -5
  35. package/src/internals/InternalGraphQLAPI.ts +102 -15
  36. package/src/utils/ConnectionStateMonitor.ts +13 -2
  37. package/src/utils/ReconnectionMonitor.ts +1 -1
  38. package/src/utils/resolveConfig.ts +0 -23
  39. package/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js +0 -94
  40. package/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js.map +0 -1
  41. package/dist/cjs/Providers/AWSWebSocketProvider/appsyncUrl.js +0 -112
  42. package/dist/cjs/Providers/AWSWebSocketProvider/appsyncUrl.js.map +0 -1
  43. package/dist/cjs/Providers/AWSWebSocketProvider/authHeaders.js +0 -99
  44. package/dist/cjs/Providers/AWSWebSocketProvider/authHeaders.js.map +0 -1
  45. package/dist/cjs/Providers/AWSWebSocketProvider/index.js +0 -623
  46. package/dist/cjs/Providers/AWSWebSocketProvider/index.js.map +0 -1
  47. package/dist/cjs/internals/events/appsyncRequest.js +0 -97
  48. package/dist/cjs/internals/events/appsyncRequest.js.map +0 -1
  49. package/dist/cjs/internals/events/index.js +0 -73
  50. package/dist/cjs/internals/events/index.js.map +0 -1
  51. package/dist/cjs/internals/events/types.js +0 -6
  52. package/dist/cjs/internals/events/types.js.map +0 -1
  53. package/dist/cjs/internals/events/utils.js +0 -57
  54. package/dist/cjs/internals/events/utils.js.map +0 -1
  55. package/dist/cjs/internals/graphqlAuth.js +0 -64
  56. package/dist/cjs/internals/graphqlAuth.js.map +0 -1
  57. package/dist/cjs/internals/graphqlRequest.js +0 -20
  58. package/dist/cjs/internals/graphqlRequest.js.map +0 -1
  59. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.d.ts +0 -42
  60. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs +0 -93
  61. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs.map +0 -1
  62. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.d.ts +0 -21
  63. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs +0 -106
  64. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs.map +0 -1
  65. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.d.ts +0 -8
  66. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs +0 -97
  67. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs.map +0 -1
  68. package/dist/esm/Providers/AWSWebSocketProvider/index.d.ts +0 -83
  69. package/dist/esm/Providers/AWSWebSocketProvider/index.mjs +0 -621
  70. package/dist/esm/Providers/AWSWebSocketProvider/index.mjs.map +0 -1
  71. package/dist/esm/internals/events/appsyncRequest.d.ts +0 -14
  72. package/dist/esm/internals/events/appsyncRequest.mjs +0 -96
  73. package/dist/esm/internals/events/appsyncRequest.mjs.map +0 -1
  74. package/dist/esm/internals/events/index.d.ts +0 -17
  75. package/dist/esm/internals/events/index.mjs +0 -69
  76. package/dist/esm/internals/events/index.mjs.map +0 -1
  77. package/dist/esm/internals/events/types.d.ts +0 -23
  78. package/dist/esm/internals/events/types.mjs +0 -2
  79. package/dist/esm/internals/events/types.mjs.map +0 -1
  80. package/dist/esm/internals/events/utils.d.ts +0 -16
  81. package/dist/esm/internals/events/utils.mjs +0 -53
  82. package/dist/esm/internals/events/utils.mjs.map +0 -1
  83. package/dist/esm/internals/graphqlAuth.d.ts +0 -3
  84. package/dist/esm/internals/graphqlAuth.mjs +0 -64
  85. package/dist/esm/internals/graphqlAuth.mjs.map +0 -1
  86. package/dist/esm/internals/graphqlRequest.d.ts +0 -3
  87. package/dist/esm/internals/graphqlRequest.mjs +0 -18
  88. package/dist/esm/internals/graphqlRequest.mjs.map +0 -1
  89. package/src/Providers/AWSAppSyncEventsProvider/index.ts +0 -187
  90. package/src/Providers/AWSWebSocketProvider/appsyncUrl.ts +0 -151
  91. package/src/Providers/AWSWebSocketProvider/authHeaders.ts +0 -146
  92. package/src/Providers/AWSWebSocketProvider/index.ts +0 -925
  93. package/src/internals/events/appsyncRequest.ts +0 -169
  94. package/src/internals/events/index.ts +0 -138
  95. package/src/internals/events/types.ts +0 -35
  96. package/src/internals/events/utils.ts +0 -77
  97. package/src/internals/graphqlAuth.ts +0 -87
  98. package/src/internals/graphqlRequest.ts +0 -30
@@ -36,9 +36,9 @@ export enum MESSAGE_TYPES {
36
36
  GQL_START_ACK = 'start_ack',
37
37
  /**
38
38
  * Server -> Client message.
39
- * This message type is for subscription message from AWS AppSync RealTime or Events
39
+ * This message type is for subscription message from AWS AppSync RealTime
40
40
  */
41
- DATA = 'data',
41
+ GQL_DATA = 'data',
42
42
  /**
43
43
  * Server -> Client message.
44
44
  * This message type helps the client to know is still receiving messages from AWS AppSync RealTime
@@ -59,36 +59,6 @@ export enum MESSAGE_TYPES {
59
59
  * This message type is for sending error messages from AWS AppSync RealTime to the client
60
60
  */
61
61
  GQL_ERROR = 'error', // Server -> Client
62
- /**
63
- * Client -> Server message.
64
- * This message type is for registering subscriptions with Events
65
- */
66
- EVENT_SUBSCRIBE = 'subscribe',
67
- /**
68
- * Client -> Server message.
69
- * This message type is for publishing a message with Events
70
- */
71
- EVENT_PUBLISH = 'publish',
72
- /**
73
- * Server -> Client message.
74
- * Server acknowledges successful subscription
75
- */
76
- EVENT_SUBSCRIBE_ACK = 'subscribe_success',
77
- /**
78
- * Server -> Client message.
79
- * Server acknowledges successful publish
80
- */
81
- EVENT_PUBLISH_ACK = 'publish_success',
82
- /**
83
- * Client -> Server message.
84
- * This message type is for unregister subscriptions with AWS AppSync RealTime
85
- */
86
- EVENT_STOP = 'unsubscribe',
87
- /**
88
- * Server -> Client message.
89
- * This is the ack response from AWS AppSync Events to EVENT_STOP message
90
- */
91
- EVENT_COMPLETE = 'unsubscribe_success',
92
62
  }
93
63
 
94
64
  export enum SUBSCRIPTION_STATUS {
package/src/index.ts CHANGED
@@ -1,12 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import * as events from './internals/events';
5
-
6
- export { events };
7
-
8
4
  export { GraphQLAPI, GraphQLAPIClass, graphqlOperation } from './GraphQLAPI';
9
5
  export * from './types';
10
6
 
11
7
  export { CONNECTION_STATE_CHANGE } from './Providers/constants';
12
- export * from './internals/events/types';
@@ -12,6 +12,7 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
12
12
  import {
13
13
  AmplifyUrl,
14
14
  CustomUserAgentDetails,
15
+ GraphQLAuthMode,
15
16
  getAmplifyUserAgent,
16
17
  } from '@aws-amplify/core/internals/utils';
17
18
  import { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';
@@ -29,11 +30,17 @@ import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvi
29
30
  import { GraphQLOperation, GraphQLOptions, GraphQLResult } from '../types';
30
31
  import { resolveConfig, resolveLibraryOptions } from '../utils';
31
32
  import { repackageUnauthorizedError } from '../utils/errors/repackageAuthError';
32
- import { NO_ENDPOINT } from '../utils/errors/constants';
33
+ import {
34
+ NO_API_KEY,
35
+ NO_AUTH_TOKEN_HEADER,
36
+ NO_ENDPOINT,
37
+ NO_SIGNED_IN_USER,
38
+ NO_VALID_AUTH_TOKEN,
39
+ NO_VALID_CREDENTIALS,
40
+ } from '../utils/errors/constants';
33
41
  import { GraphQLApiError, createGraphQLResultWithError } from '../utils/errors';
34
42
 
35
43
  import { isGraphQLResponseWithErrors } from './utils/runtimeTypeGuards/isGraphQLResponseWithErrors';
36
- import { headerBasedAuth } from './graphqlAuth';
37
44
 
38
45
  const USER_AGENT_HEADER = 'x-amz-user-agent';
39
46
 
@@ -65,6 +72,80 @@ export class InternalGraphQLAPIClass {
65
72
  return 'InternalGraphQLAPI';
66
73
  }
67
74
 
75
+ private async _headerBasedAuth(
76
+ amplify: AmplifyClassV6,
77
+ authMode: GraphQLAuthMode,
78
+ additionalHeaders: Record<string, string> = {},
79
+ ) {
80
+ const { apiKey } = resolveConfig(amplify);
81
+
82
+ let headers = {};
83
+
84
+ switch (authMode) {
85
+ case 'apiKey':
86
+ if (!apiKey) {
87
+ throw new GraphQLApiError(NO_API_KEY);
88
+ }
89
+ headers = {
90
+ 'X-Api-Key': apiKey,
91
+ };
92
+ break;
93
+ case 'iam': {
94
+ const session = await amplify.Auth.fetchAuthSession();
95
+ if (session.credentials === undefined) {
96
+ throw new GraphQLApiError(NO_VALID_CREDENTIALS);
97
+ }
98
+ break;
99
+ }
100
+ case 'oidc':
101
+ case 'userPool': {
102
+ let token: string | undefined;
103
+
104
+ try {
105
+ token = (
106
+ await amplify.Auth.fetchAuthSession()
107
+ ).tokens?.accessToken.toString();
108
+ } catch (e) {
109
+ // fetchAuthSession failed
110
+ throw new GraphQLApiError({
111
+ ...NO_SIGNED_IN_USER,
112
+ underlyingError: e,
113
+ });
114
+ }
115
+
116
+ // `fetchAuthSession()` succeeded but didn't return `tokens`.
117
+ // This may happen when unauthenticated access is enabled and there is
118
+ // no user signed in.
119
+ if (!token) {
120
+ throw new GraphQLApiError(NO_VALID_AUTH_TOKEN);
121
+ }
122
+
123
+ headers = {
124
+ Authorization: token,
125
+ };
126
+ break;
127
+ }
128
+ case 'lambda':
129
+ if (
130
+ typeof additionalHeaders === 'object' &&
131
+ !additionalHeaders.Authorization
132
+ ) {
133
+ throw new GraphQLApiError(NO_AUTH_TOKEN_HEADER);
134
+ }
135
+
136
+ headers = {
137
+ Authorization: additionalHeaders.Authorization,
138
+ };
139
+ break;
140
+ case 'none':
141
+ break;
142
+ default:
143
+ break;
144
+ }
145
+
146
+ return headers;
147
+ }
148
+
68
149
  /**
69
150
  * to get the operation type
70
151
  * @param operation
@@ -171,7 +252,6 @@ export class InternalGraphQLAPIClass {
171
252
  authToken?: string,
172
253
  ): Promise<GraphQLResult<T>> {
173
254
  const {
174
- apiKey,
175
255
  region,
176
256
  endpoint: appSyncGraphqlEndpoint,
177
257
  customEndpoint,
@@ -223,22 +303,29 @@ export class InternalGraphQLAPIClass {
223
303
  };
224
304
  }
225
305
 
226
- const authHeaders = await headerBasedAuth(
227
- amplify,
228
- authMode,
229
- apiKey,
230
- additionalCustomHeaders,
231
- );
232
-
306
+ // TODO: Figure what we need to do to remove `!`'s.
233
307
  const headers = {
234
- ...(!customEndpoint && authHeaders),
308
+ ...(!customEndpoint &&
309
+ (await this._headerBasedAuth(
310
+ amplify,
311
+ authMode!,
312
+ additionalCustomHeaders,
313
+ ))),
235
314
  /**
236
315
  * Custom endpoint headers.
237
316
  * If there is both a custom endpoint and custom region present, we get the headers.
238
317
  * If there is a custom endpoint but no region, we return an empty object.
239
318
  * If neither are present, we return an empty object.
240
319
  */
241
- ...((customEndpoint && (customEndpointRegion ? authHeaders : {})) || {}),
320
+ ...((customEndpoint &&
321
+ (customEndpointRegion
322
+ ? await this._headerBasedAuth(
323
+ amplify,
324
+ authMode!,
325
+ additionalCustomHeaders,
326
+ )
327
+ : {})) ||
328
+ {}),
242
329
  // Custom headers included in Amplify configuration options:
243
330
  ...(customHeaders &&
244
331
  (await customHeaders({
@@ -291,9 +378,9 @@ export class InternalGraphQLAPIClass {
291
378
  let response: any;
292
379
 
293
380
  try {
294
- // // // See the inline doc of the REST `post()` API for possible errors to be thrown.
295
- // // // As these errors are catastrophic they should be caught and handled by GraphQL
296
- // // // API consumers.
381
+ // See the inline doc of the REST `post()` API for possible errors to be thrown.
382
+ // As these errors are catastrophic they should be caught and handled by GraphQL
383
+ // API consumers.
297
384
  const { body: responseBody } = await this._api.post(amplify, {
298
385
  url: new AmplifyUrl(endpoint),
299
386
  options: {
@@ -17,7 +17,18 @@ interface LinkedConnectionStates {
17
17
  keepAliveState: LinkedHealthState;
18
18
  }
19
19
 
20
- export const CONNECTION_CHANGE = {
20
+ export const CONNECTION_CHANGE: {
21
+ [key in
22
+ | 'KEEP_ALIVE_MISSED'
23
+ | 'KEEP_ALIVE'
24
+ | 'CONNECTION_ESTABLISHED'
25
+ | 'CONNECTION_FAILED'
26
+ | 'CLOSING_CONNECTION'
27
+ | 'OPENING_CONNECTION'
28
+ | 'CLOSED'
29
+ | 'ONLINE'
30
+ | 'OFFLINE']: Partial<LinkedConnectionStates>;
31
+ } = {
21
32
  KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },
22
33
  KEEP_ALIVE: { keepAliveState: 'healthy' },
23
34
  CONNECTION_ESTABLISHED: { connectionState: 'connected' },
@@ -33,7 +44,7 @@ export const CONNECTION_CHANGE = {
33
44
  CLOSED: { connectionState: 'disconnected' },
34
45
  ONLINE: { networkState: 'connected' },
35
46
  OFFLINE: { networkState: 'disconnected' },
36
- } as const;
47
+ };
37
48
 
38
49
  export class ConnectionStateMonitor {
39
50
  /**
@@ -11,7 +11,7 @@ export enum ReconnectEvent {
11
11
 
12
12
  /**
13
13
  * Captures the reconnect event logic used to determine when to reconnect to PubSub providers.
14
- * Reconnect attempts are delayed by 5 seconds to let the interface settle.
14
+ * Reconnnect attempts are delayed by 5 seconds to let the interface settle.
15
15
  * Attempting to reconnect only once creates unrecoverable states when the network state isn't
16
16
  * supported by the browser, so this keeps retrying every minute until halted.
17
17
  */
@@ -44,26 +44,3 @@ export const resolveConfig = (amplify: AmplifyClassV6) => {
44
44
  region,
45
45
  };
46
46
  };
47
-
48
- // /**
49
- // * @internal
50
- // */
51
- // export const resolveEventsConfig = (amplify: AmplifyClassV6) => {
52
- // const config = amplify.getConfig();
53
-
54
- // if (!config.API?.Events) {
55
- // logger.warn(
56
- // 'The Events configuration is missing. This is likely due to Amplify.configure() not being called prior to using events.connect() or events.post().',
57
- // );
58
- // }
59
-
60
- // const { apiKey, endpoint, defaultAuthMode, region } =
61
- // config.API?.Events ?? {};
62
-
63
- // return {
64
- // apiKey,
65
- // defaultAuthMode,
66
- // appSyncGraphqlEndpoint: endpoint,
67
- // region,
68
- // };
69
- // };
@@ -1,94 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.AppSyncEventProvider = void 0;
5
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6
- // SPDX-License-Identifier: Apache-2.0
7
- const utils_1 = require("@aws-amplify/core/internals/utils");
8
- const constants_1 = require("../constants");
9
- const AWSWebSocketProvider_1 = require("../AWSWebSocketProvider");
10
- const authHeaders_1 = require("../AWSWebSocketProvider/authHeaders");
11
- const PROVIDER_NAME = 'AWSAppSyncEventsProvider';
12
- class AWSAppSyncEventProvider extends AWSWebSocketProvider_1.AWSWebSocketProvider {
13
- constructor() {
14
- super(PROVIDER_NAME);
15
- }
16
- async connect(options) {
17
- super.connect(options);
18
- }
19
- subscribe(options, customUserAgentDetails) {
20
- return super.subscribe(options, customUserAgentDetails).pipe();
21
- }
22
- async publish(options, customUserAgentDetails) {
23
- super.publish(options, customUserAgentDetails);
24
- }
25
- async _prepareSubscriptionPayload({ options, subscriptionId, customUserAgentDetails, additionalCustomHeaders, libraryConfigHeaders, publish, }) {
26
- const { appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, } = options;
27
- // This will be needed for WS publish
28
- // const data = {
29
- // events: [variables],
30
- // };
31
- const serializedData = JSON.stringify([variables]);
32
- const headers = {
33
- ...(await (0, authHeaders_1.awsRealTimeHeaderBasedAuth)({
34
- apiKey,
35
- appSyncGraphqlEndpoint,
36
- authenticationType,
37
- payload: serializedData,
38
- canonicalUri: '',
39
- region,
40
- additionalCustomHeaders,
41
- })),
42
- ...libraryConfigHeaders,
43
- ...additionalCustomHeaders,
44
- [utils_1.USER_AGENT_HEADER]: (0, utils_1.getAmplifyUserAgent)(customUserAgentDetails),
45
- };
46
- // Commented out code will be needed for WS publish
47
- const subscriptionMessage = {
48
- id: subscriptionId,
49
- channel: query,
50
- // events: [JSON.stringify(variables)],
51
- authorization: {
52
- ...headers,
53
- },
54
- // payload: {
55
- // events: serializedData,
56
- // extensions: {
57
- // authorization: {
58
- // ...headers,
59
- // },
60
- // },
61
- // },
62
- type: publish
63
- ? constants_1.MESSAGE_TYPES.EVENT_PUBLISH
64
- : constants_1.MESSAGE_TYPES.EVENT_SUBSCRIBE,
65
- };
66
- const serializedSubscriptionMessage = JSON.stringify(subscriptionMessage);
67
- return serializedSubscriptionMessage;
68
- }
69
- _handleSubscriptionData(message) {
70
- this.logger.debug(`subscription message from AWS AppSync Events: ${message.data}`);
71
- const { id = '', event: payload, type, } = JSON.parse(String(message.data));
72
- const { observer = null, query = '', variables = {}, } = this.subscriptionObserverMap.get(id) || {};
73
- this.logger.debug({ id, observer, query, variables });
74
- if (type === constants_1.MESSAGE_TYPES.DATA && payload) {
75
- const deserializedEvent = JSON.parse(payload);
76
- if (observer) {
77
- observer.next(deserializedEvent);
78
- }
79
- else {
80
- this.logger.debug(`observer not found for id: ${id}`);
81
- }
82
- return [true, { id, type, payload: deserializedEvent }];
83
- }
84
- return [false, { id, type, payload }];
85
- }
86
- _unsubscribeMessage(subscriptionId) {
87
- return {
88
- id: subscriptionId,
89
- type: constants_1.MESSAGE_TYPES.EVENT_STOP,
90
- };
91
- }
92
- }
93
- exports.AppSyncEventProvider = new AWSAppSyncEventProvider();
94
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":["../../../../src/Providers/AWSAppSyncEventsProvider/index.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.AppSyncEventProvider = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst constants_1 = require(\"../constants\");\nconst AWSWebSocketProvider_1 = require(\"../AWSWebSocketProvider\");\nconst authHeaders_1 = require(\"../AWSWebSocketProvider/authHeaders\");\nconst PROVIDER_NAME = 'AWSAppSyncEventsProvider';\nclass AWSAppSyncEventProvider extends AWSWebSocketProvider_1.AWSWebSocketProvider {\n constructor() {\n super(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 (0, authHeaders_1.awsRealTimeHeaderBasedAuth)({\n apiKey,\n appSyncGraphqlEndpoint,\n authenticationType,\n payload: serializedData,\n canonicalUri: '',\n region,\n additionalCustomHeaders,\n })),\n ...libraryConfigHeaders,\n ...additionalCustomHeaders,\n [utils_1.USER_AGENT_HEADER]: (0, utils_1.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 ? constants_1.MESSAGE_TYPES.EVENT_PUBLISH\n : constants_1.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 === constants_1.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: constants_1.MESSAGE_TYPES.EVENT_STOP,\n };\n }\n}\nexports.AppSyncEventProvider = new AWSAppSyncEventProvider();\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,oBAAoB,GAAG,KAAK,CAAC,CAAC;AACtC;AACA;AACA,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,MAAM,sBAAsB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AAClE,MAAM,aAAa,GAAG,OAAO,CAAC,qCAAqC,CAAC,CAAC;AACrE,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,uBAAuB,SAAS,sBAAsB,CAAC,oBAAoB,CAAC;AAClF,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,aAAa,CAAC,CAAC;AAC7B,KAAK;AACL,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE;AAC3B,QAAQ,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC/B,KAAK;AACL,IAAI,SAAS,CAAC,OAAO,EAAE,sBAAsB,EAAE;AAC/C,QAAQ,OAAO,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC,IAAI,EAAE,CAAC;AACvE,KAAK;AACL,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE,sBAAsB,EAAE;AACnD,QAAQ,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,sBAAsB,CAAC,CAAC;AACvD,KAAK;AACL,IAAI,MA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K;AACL,IAAI,mBAAmB,CAAC,cAAc,EAAE;AACxC,QAAQ,OAAO;AACf,YAAY,EAAE,EAAE,cAAc;AAC9B,YAAY,IAAI,EAAE,WAAW,CAAC,aAAa,CAAC,UAAU;AACtD,SAAS,CAAC;AACV,KAAK;AACL,CAAC;AACD,OAAO,CAAC,oBAAoB,GAAG,IAAI,uBAAuB,EAAE;;"}
@@ -1,112 +0,0 @@
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.additionalHeadersFromOptions = exports.realtimeUrlWithQueryString = exports.queryParamsFromCustomHeaders = exports.getRealtimeEndpointUrl = exports.isCustomDomain = void 0;
7
- const utils_1 = require("@aws-amplify/core/internals/utils");
8
- const protocol = 'wss://';
9
- const standardDomainPattern = /^https:\/\/\w{26}\.appsync-api\.\w{2}(?:(?:-\w{2,})+)-\d\.amazonaws.com(?:\.cn)?\/graphql$/i;
10
- const eventDomainPattern = /^https:\/\/\w{26}\.ddpg-api\.\w{2}(?:(?:-\w{2,})+)-\d\.amazonaws.com(?:\.cn)?\/event$/i;
11
- const customDomainPath = '/realtime';
12
- const isCustomDomain = (url) => {
13
- return url.match(standardDomainPattern) === null;
14
- };
15
- exports.isCustomDomain = isCustomDomain;
16
- const isEventDomain = (url) => url.match(eventDomainPattern) !== null;
17
- const getRealtimeEndpointUrl = (appSyncGraphqlEndpoint) => {
18
- let realtimeEndpoint = appSyncGraphqlEndpoint ?? '';
19
- if (isEventDomain(realtimeEndpoint)) {
20
- realtimeEndpoint = realtimeEndpoint
21
- .concat(customDomainPath)
22
- .replace('ddpg-api', 'grt-gamma');
23
- }
24
- else if ((0, exports.isCustomDomain)(realtimeEndpoint)) {
25
- realtimeEndpoint = realtimeEndpoint.concat(customDomainPath);
26
- }
27
- else {
28
- realtimeEndpoint = realtimeEndpoint
29
- .replace('appsync-api', 'appsync-realtime-api')
30
- .replace('gogi-beta', 'grt-beta')
31
- .replace('ddpg-api', 'grt-gamma');
32
- }
33
- realtimeEndpoint = realtimeEndpoint
34
- .replace('https://', protocol)
35
- .replace('http://', protocol);
36
- return new utils_1.AmplifyUrl(realtimeEndpoint);
37
- };
38
- exports.getRealtimeEndpointUrl = getRealtimeEndpointUrl;
39
- /**
40
- * Strips out `Authorization` header if present
41
- */
42
- const extractNonAuthHeaders = (headers) => {
43
- if (!headers) {
44
- return {};
45
- }
46
- if ('Authorization' in headers) {
47
- const { Authorization: _, ...nonAuthHeaders } = headers;
48
- return nonAuthHeaders;
49
- }
50
- return headers;
51
- };
52
- /**
53
- *
54
- * @param headers - http headers
55
- * @returns uri-encoded query parameters derived from custom headers
56
- */
57
- const queryParamsFromCustomHeaders = (headers) => {
58
- const nonAuthHeaders = extractNonAuthHeaders(headers);
59
- const params = new utils_1.AmplifyUrlSearchParams();
60
- Object.entries(nonAuthHeaders).forEach(([k, v]) => {
61
- params.append(k, v);
62
- });
63
- return params;
64
- };
65
- exports.queryParamsFromCustomHeaders = queryParamsFromCustomHeaders;
66
- /**
67
- * Normalizes AppSync realtime endpoint URL
68
- *
69
- * @param appSyncGraphqlEndpoint - AppSync endpointUri from config
70
- * @param urlParams - URLSearchParams
71
- * @returns fully resolved string realtime endpoint URL
72
- */
73
- const realtimeUrlWithQueryString = (appSyncGraphqlEndpoint, urlParams) => {
74
- const realtimeEndpointUrl = (0, exports.getRealtimeEndpointUrl)(appSyncGraphqlEndpoint);
75
- // preserves any query params a customer might manually set in the configuration
76
- const existingParams = new utils_1.AmplifyUrlSearchParams(realtimeEndpointUrl.search);
77
- for (const [k, v] of urlParams.entries()) {
78
- existingParams.append(k, v);
79
- }
80
- realtimeEndpointUrl.search = existingParams.toString();
81
- return realtimeEndpointUrl.toString();
82
- };
83
- exports.realtimeUrlWithQueryString = realtimeUrlWithQueryString;
84
- // TODO: move to separate file?
85
- const additionalHeadersFromOptions = async (options) => {
86
- const { appSyncGraphqlEndpoint, query, libraryConfigHeaders = () => ({}), additionalHeaders = {}, authToken, } = options;
87
- let additionalCustomHeaders = {};
88
- const _libraryConfigHeaders = await libraryConfigHeaders();
89
- if (typeof additionalHeaders === 'function') {
90
- const requestOptions = {
91
- url: appSyncGraphqlEndpoint || '',
92
- queryString: query || '',
93
- };
94
- additionalCustomHeaders = await additionalHeaders(requestOptions);
95
- }
96
- else {
97
- additionalCustomHeaders = additionalHeaders;
98
- }
99
- // if an authorization header is set, have the explicit, operation-level authToken take precedence
100
- if (authToken) {
101
- additionalCustomHeaders = {
102
- ...additionalCustomHeaders,
103
- Authorization: authToken,
104
- };
105
- }
106
- return {
107
- additionalCustomHeaders,
108
- libraryConfigHeaders: _libraryConfigHeaders,
109
- };
110
- };
111
- exports.additionalHeadersFromOptions = additionalHeadersFromOptions;
112
- //# sourceMappingURL=appsyncUrl.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"appsyncUrl.js","sources":["../../../../src/Providers/AWSWebSocketProvider/appsyncUrl.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.additionalHeadersFromOptions = exports.realtimeUrlWithQueryString = exports.queryParamsFromCustomHeaders = exports.getRealtimeEndpointUrl = exports.isCustomDomain = void 0;\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst protocol = 'wss://';\nconst standardDomainPattern = /^https:\\/\\/\\w{26}\\.appsync-api\\.\\w{2}(?:(?:-\\w{2,})+)-\\d\\.amazonaws.com(?:\\.cn)?\\/graphql$/i;\nconst eventDomainPattern = /^https:\\/\\/\\w{26}\\.ddpg-api\\.\\w{2}(?:(?:-\\w{2,})+)-\\d\\.amazonaws.com(?:\\.cn)?\\/event$/i;\nconst customDomainPath = '/realtime';\nconst isCustomDomain = (url) => {\n return url.match(standardDomainPattern) === null;\n};\nexports.isCustomDomain = isCustomDomain;\nconst isEventDomain = (url) => url.match(eventDomainPattern) !== null;\nconst getRealtimeEndpointUrl = (appSyncGraphqlEndpoint) => {\n let realtimeEndpoint = appSyncGraphqlEndpoint ?? '';\n if (isEventDomain(realtimeEndpoint)) {\n realtimeEndpoint = realtimeEndpoint\n .concat(customDomainPath)\n .replace('ddpg-api', 'grt-gamma');\n }\n else if ((0, exports.isCustomDomain)(realtimeEndpoint)) {\n realtimeEndpoint = realtimeEndpoint.concat(customDomainPath);\n }\n else {\n realtimeEndpoint = realtimeEndpoint\n .replace('appsync-api', 'appsync-realtime-api')\n .replace('gogi-beta', 'grt-beta')\n .replace('ddpg-api', 'grt-gamma');\n }\n realtimeEndpoint = realtimeEndpoint\n .replace('https://', protocol)\n .replace('http://', protocol);\n return new utils_1.AmplifyUrl(realtimeEndpoint);\n};\nexports.getRealtimeEndpointUrl = getRealtimeEndpointUrl;\n/**\n * Strips out `Authorization` header if present\n */\nconst extractNonAuthHeaders = (headers) => {\n if (!headers) {\n return {};\n }\n if ('Authorization' in headers) {\n const { Authorization: _, ...nonAuthHeaders } = headers;\n return nonAuthHeaders;\n }\n return headers;\n};\n/**\n *\n * @param headers - http headers\n * @returns uri-encoded query parameters derived from custom headers\n */\nconst queryParamsFromCustomHeaders = (headers) => {\n const nonAuthHeaders = extractNonAuthHeaders(headers);\n const params = new utils_1.AmplifyUrlSearchParams();\n Object.entries(nonAuthHeaders).forEach(([k, v]) => {\n params.append(k, v);\n });\n return params;\n};\nexports.queryParamsFromCustomHeaders = queryParamsFromCustomHeaders;\n/**\n * Normalizes AppSync realtime endpoint URL\n *\n * @param appSyncGraphqlEndpoint - AppSync endpointUri from config\n * @param urlParams - URLSearchParams\n * @returns fully resolved string realtime endpoint URL\n */\nconst realtimeUrlWithQueryString = (appSyncGraphqlEndpoint, urlParams) => {\n const realtimeEndpointUrl = (0, exports.getRealtimeEndpointUrl)(appSyncGraphqlEndpoint);\n // preserves any query params a customer might manually set in the configuration\n const existingParams = new utils_1.AmplifyUrlSearchParams(realtimeEndpointUrl.search);\n for (const [k, v] of urlParams.entries()) {\n existingParams.append(k, v);\n }\n realtimeEndpointUrl.search = existingParams.toString();\n return realtimeEndpointUrl.toString();\n};\nexports.realtimeUrlWithQueryString = realtimeUrlWithQueryString;\n// TODO: move to separate file?\nconst additionalHeadersFromOptions = async (options) => {\n const { appSyncGraphqlEndpoint, query, libraryConfigHeaders = () => ({}), additionalHeaders = {}, authToken, } = options;\n let additionalCustomHeaders = {};\n const _libraryConfigHeaders = await libraryConfigHeaders();\n if (typeof additionalHeaders === 'function') {\n const requestOptions = {\n url: appSyncGraphqlEndpoint || '',\n queryString: query || '',\n };\n additionalCustomHeaders = await additionalHeaders(requestOptions);\n }\n else {\n additionalCustomHeaders = additionalHeaders;\n }\n // if an authorization header is set, have the explicit, operation-level authToken take precedence\n if (authToken) {\n additionalCustomHeaders = {\n ...additionalCustomHeaders,\n Authorization: authToken,\n };\n }\n return {\n additionalCustomHeaders,\n libraryConfigHeaders: _libraryConfigHeaders,\n };\n};\nexports.additionalHeadersFromOptions = additionalHeadersFromOptions;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,4BAA4B,GAAG,OAAO,CAAC,0BAA0B,GAAG,OAAO,CAAC,4BAA4B,GAAG,OAAO,CAAC,sBAAsB,GAAG,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;AACpL,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC;AAC1B,MAAM,qBAAqB,GAAG,6FAA6F,CAAC;AAC5H,MAAM,kBAAkB,GAAG,wFAAwF,CAAC;AACpH,MAAM,gBAAgB,GAAG,WAAW,CAAC;AACrC,MAAM,cAAc,GAAG,CAAC,GAAG,KAAK;AAChC,IAAI,OAAO,G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perty(exports, "__esModule", { value: true });
6
- exports.awsRealTimeHeaderBasedAuth = void 0;
7
- const core_1 = require("@aws-amplify/core");
8
- const aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
9
- const utils_1 = require("@aws-amplify/core/internals/utils");
10
- const constants_1 = require("../constants");
11
- const logger = new core_1.ConsoleLogger('AWSAppSyncRealTimeProvider Auth');
12
- const awsAuthTokenHeader = async ({ host }) => {
13
- const session = await (0, core_1.fetchAuthSession)();
14
- return {
15
- Authorization: session?.tokens?.accessToken?.toString(),
16
- host,
17
- };
18
- };
19
- const awsRealTimeApiKeyHeader = async ({ apiKey, host, }) => {
20
- const dt = new Date();
21
- const dtStr = dt.toISOString().replace(/[:-]|\.\d{3}/g, '');
22
- return {
23
- host,
24
- 'x-amz-date': dtStr,
25
- 'x-api-key': apiKey,
26
- };
27
- };
28
- const awsRealTimeIAMHeader = async ({ payload, canonicalUri, appSyncGraphqlEndpoint, region, }) => {
29
- const endpointInfo = {
30
- region,
31
- service: 'appsync',
32
- };
33
- const creds = (await (0, core_1.fetchAuthSession)()).credentials;
34
- const request = {
35
- url: `${appSyncGraphqlEndpoint}${canonicalUri}`,
36
- data: payload,
37
- method: 'POST',
38
- headers: { ...constants_1.AWS_APPSYNC_REALTIME_HEADERS },
39
- };
40
- const signedParams = (0, aws_client_utils_1.signRequest)({
41
- headers: request.headers,
42
- method: request.method,
43
- url: new utils_1.AmplifyUrl(request.url),
44
- body: request.data,
45
- }, {
46
- credentials: creds,
47
- signingRegion: endpointInfo.region,
48
- signingService: endpointInfo.service,
49
- });
50
- return signedParams.headers;
51
- };
52
- const customAuthHeader = async ({ host, additionalCustomHeaders, }) => {
53
- /**
54
- * If `additionalHeaders` was provided to the subscription as a function,
55
- * the headers that are returned by that function will already have been
56
- * provided before this function is called.
57
- */
58
- if (!additionalCustomHeaders?.Authorization) {
59
- throw new Error('No auth token specified');
60
- }
61
- return {
62
- Authorization: additionalCustomHeaders.Authorization,
63
- host,
64
- };
65
- };
66
- const awsRealTimeHeaderBasedAuth = async ({ apiKey, authenticationType, canonicalUri, appSyncGraphqlEndpoint, region, additionalCustomHeaders, payload, }) => {
67
- const headerHandler = {
68
- apiKey: awsRealTimeApiKeyHeader,
69
- iam: awsRealTimeIAMHeader,
70
- oidc: awsAuthTokenHeader,
71
- userPool: awsAuthTokenHeader,
72
- lambda: customAuthHeader,
73
- none: customAuthHeader,
74
- };
75
- if (!authenticationType || !headerHandler[authenticationType]) {
76
- logger.debug(`Authentication type ${authenticationType} not supported`);
77
- return undefined;
78
- }
79
- else {
80
- const handler = headerHandler[authenticationType];
81
- const host = appSyncGraphqlEndpoint
82
- ? new utils_1.AmplifyUrl(appSyncGraphqlEndpoint).host
83
- : undefined;
84
- const resolvedApiKey = authenticationType === 'apiKey' ? apiKey : undefined;
85
- logger.debug(`Authenticating with ${JSON.stringify(authenticationType)}`);
86
- const result = await handler({
87
- payload,
88
- canonicalUri,
89
- appSyncGraphqlEndpoint,
90
- apiKey: resolvedApiKey,
91
- region,
92
- host,
93
- additionalCustomHeaders,
94
- });
95
- return result;
96
- }
97
- };
98
- exports.awsRealTimeHeaderBasedAuth = awsRealTimeHeaderBasedAuth;
99
- //# sourceMappingURL=authHeaders.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authHeaders.js","sources":["../../../../src/Providers/AWSWebSocketProvider/authHeaders.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.awsRealTimeHeaderBasedAuth = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst aws_client_utils_1 = require(\"@aws-amplify/core/internals/aws-client-utils\");\nconst utils_1 = require(\"@aws-amplify/core/internals/utils\");\nconst constants_1 = require(\"../constants\");\nconst logger = new core_1.ConsoleLogger('AWSAppSyncRealTimeProvider Auth');\nconst awsAuthTokenHeader = async ({ host }) => {\n const session = await (0, core_1.fetchAuthSession)();\n return {\n Authorization: session?.tokens?.accessToken?.toString(),\n host,\n };\n};\nconst awsRealTimeApiKeyHeader = async ({ apiKey, host, }) => {\n const dt = new Date();\n const dtStr = dt.toISOString().replace(/[:-]|\\.\\d{3}/g, '');\n return {\n host,\n 'x-amz-date': dtStr,\n 'x-api-key': apiKey,\n };\n};\nconst awsRealTimeIAMHeader = async ({ payload, canonicalUri, appSyncGraphqlEndpoint, region, }) => {\n const endpointInfo = {\n region,\n service: 'appsync',\n };\n const creds = (await (0, core_1.fetchAuthSession)()).credentials;\n const request = {\n url: `${appSyncGraphqlEndpoint}${canonicalUri}`,\n data: payload,\n method: 'POST',\n headers: { ...constants_1.AWS_APPSYNC_REALTIME_HEADERS },\n };\n const signedParams = (0, aws_client_utils_1.signRequest)({\n headers: request.headers,\n method: request.method,\n url: new utils_1.AmplifyUrl(request.url),\n body: request.data,\n }, {\n credentials: creds,\n signingRegion: endpointInfo.region,\n signingService: endpointInfo.service,\n });\n return signedParams.headers;\n};\nconst customAuthHeader = async ({ host, additionalCustomHeaders, }) => {\n /**\n * If `additionalHeaders` was provided to the subscription as a function,\n * the headers that are returned by that function will already have been\n * provided before this function is called.\n */\n if (!additionalCustomHeaders?.Authorization) {\n throw new Error('No auth token specified');\n }\n return {\n Authorization: additionalCustomHeaders.Authorization,\n host,\n };\n};\nconst awsRealTimeHeaderBasedAuth = async ({ apiKey, authenticationType, canonicalUri, appSyncGraphqlEndpoint, region, additionalCustomHeaders, payload, }) => {\n const headerHandler = {\n apiKey: awsRealTimeApiKeyHeader,\n iam: awsRealTimeIAMHeader,\n oidc: awsAuthTokenHeader,\n userPool: awsAuthTokenHeader,\n lambda: customAuthHeader,\n none: customAuthHeader,\n };\n if (!authenticationType || !headerHandler[authenticationType]) {\n logger.debug(`Authentication type ${authenticationType} not supported`);\n return undefined;\n }\n else {\n const handler = headerHandler[authenticationType];\n const host = appSyncGraphqlEndpoint\n ? new utils_1.AmplifyUrl(appSyncGraphqlEndpoint).host\n : undefined;\n const resolvedApiKey = authenticationType === 'apiKey' ? apiKey : undefined;\n logger.debug(`Authenticating with ${JSON.stringify(authenticationType)}`);\n const result = await handler({\n payload,\n canonicalUri,\n appSyncGraphqlEndpoint,\n apiKey: resolvedApiKey,\n region,\n host,\n additionalCustomHeaders,\n });\n return result;\n }\n};\nexports.awsRealTimeHeaderBasedAuth = awsRealTimeHeaderBasedAuth;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,0BAA0B,GAAG,KAAK,CAAC,CAAC;AAC5C,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,kBAAkB,GAAG,OAAO,CAAC,8CAA8C,CAAC,CAAC;AACnF,MAAM,OAAO,GAAG,OAAO,CAAC,mCAAmC,CAAC,CAAC;AAC7D,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,iCAAiC,CAAC,CAAC;AAC3E,MAAM,kBAAkB,GAAG,OAAO,EAAE,IAAI,EAAE,KAAK;AAC/C,IAAI,MAAM,OAAO,GAAG,MAAM,IAAI,MAAM,CAAC,gBAAgB,GAAG,CAAC;AACzD,IAAI,OAAO;AACX,QAAQ,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE;AAC/D,QAAQ,IAAI;AACZ,KAAK,CAAC;AACN,CAAC,CAAC;AACF,MAAM,uBAAuB,GAAG,OAAO,EAAE,MAAM,EAAE,IAAI,GAAG,KAAK;AAC7D,IAAI,MAAM,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC;AAC1B,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE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