@aws-amplify/api-graphql 4.4.3-unstable.847fb51.0 → 4.4.3

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 (93) hide show
  1. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +731 -34
  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/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +71 -24
  12. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +731 -34
  13. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
  14. package/dist/esm/Providers/constants.d.ts +3 -33
  15. package/dist/esm/Providers/constants.mjs +2 -32
  16. package/dist/esm/Providers/constants.mjs.map +1 -1
  17. package/dist/esm/index.d.ts +0 -3
  18. package/dist/esm/index.mjs +0 -2
  19. package/dist/esm/index.mjs.map +1 -1
  20. package/dist/esm/internals/InternalGraphQLAPI.d.ts +1 -0
  21. package/dist/esm/internals/InternalGraphQLAPI.mjs +68 -9
  22. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  23. package/dist/esm/utils/ConnectionStateMonitor.d.ts +1 -29
  24. package/dist/esm/utils/ReconnectionMonitor.d.ts +1 -1
  25. package/dist/esm/utils/ReconnectionMonitor.mjs +1 -1
  26. package/dist/esm/utils/ReconnectionMonitor.mjs.map +1 -1
  27. package/package.json +4 -4
  28. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +1049 -56
  29. package/src/Providers/constants.ts +2 -32
  30. package/src/index.ts +0 -5
  31. package/src/internals/InternalGraphQLAPI.ts +102 -15
  32. package/src/utils/ConnectionStateMonitor.ts +13 -2
  33. package/src/utils/ReconnectionMonitor.ts +1 -1
  34. package/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js +0 -98
  35. package/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js.map +0 -1
  36. package/dist/cjs/Providers/AWSWebSocketProvider/appsyncUrl.js +0 -112
  37. package/dist/cjs/Providers/AWSWebSocketProvider/appsyncUrl.js.map +0 -1
  38. package/dist/cjs/Providers/AWSWebSocketProvider/authHeaders.js +0 -99
  39. package/dist/cjs/Providers/AWSWebSocketProvider/authHeaders.js.map +0 -1
  40. package/dist/cjs/Providers/AWSWebSocketProvider/index.js +0 -624
  41. package/dist/cjs/Providers/AWSWebSocketProvider/index.js.map +0 -1
  42. package/dist/cjs/internals/events/appsyncRequest.js +0 -97
  43. package/dist/cjs/internals/events/appsyncRequest.js.map +0 -1
  44. package/dist/cjs/internals/events/index.js +0 -73
  45. package/dist/cjs/internals/events/index.js.map +0 -1
  46. package/dist/cjs/internals/events/types.js +0 -6
  47. package/dist/cjs/internals/events/types.js.map +0 -1
  48. package/dist/cjs/internals/events/utils.js +0 -57
  49. package/dist/cjs/internals/events/utils.js.map +0 -1
  50. package/dist/cjs/internals/graphqlAuth.js +0 -64
  51. package/dist/cjs/internals/graphqlAuth.js.map +0 -1
  52. package/dist/cjs/internals/graphqlRequest.js +0 -20
  53. package/dist/cjs/internals/graphqlRequest.js.map +0 -1
  54. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.d.ts +0 -43
  55. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs +0 -97
  56. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs.map +0 -1
  57. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.d.ts +0 -21
  58. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs +0 -106
  59. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs.map +0 -1
  60. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.d.ts +0 -8
  61. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs +0 -97
  62. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs.map +0 -1
  63. package/dist/esm/Providers/AWSWebSocketProvider/index.d.ts +0 -89
  64. package/dist/esm/Providers/AWSWebSocketProvider/index.mjs +0 -622
  65. package/dist/esm/Providers/AWSWebSocketProvider/index.mjs.map +0 -1
  66. package/dist/esm/internals/events/appsyncRequest.d.ts +0 -14
  67. package/dist/esm/internals/events/appsyncRequest.mjs +0 -96
  68. package/dist/esm/internals/events/appsyncRequest.mjs.map +0 -1
  69. package/dist/esm/internals/events/index.d.ts +0 -17
  70. package/dist/esm/internals/events/index.mjs +0 -69
  71. package/dist/esm/internals/events/index.mjs.map +0 -1
  72. package/dist/esm/internals/events/types.d.ts +0 -23
  73. package/dist/esm/internals/events/types.mjs +0 -2
  74. package/dist/esm/internals/events/types.mjs.map +0 -1
  75. package/dist/esm/internals/events/utils.d.ts +0 -16
  76. package/dist/esm/internals/events/utils.mjs +0 -53
  77. package/dist/esm/internals/events/utils.mjs.map +0 -1
  78. package/dist/esm/internals/graphqlAuth.d.ts +0 -3
  79. package/dist/esm/internals/graphqlAuth.mjs +0 -64
  80. package/dist/esm/internals/graphqlAuth.mjs.map +0 -1
  81. package/dist/esm/internals/graphqlRequest.d.ts +0 -3
  82. package/dist/esm/internals/graphqlRequest.mjs +0 -18
  83. package/dist/esm/internals/graphqlRequest.mjs.map +0 -1
  84. package/src/Providers/AWSAppSyncEventsProvider/index.ts +0 -192
  85. package/src/Providers/AWSWebSocketProvider/appsyncUrl.ts +0 -151
  86. package/src/Providers/AWSWebSocketProvider/authHeaders.ts +0 -146
  87. package/src/Providers/AWSWebSocketProvider/index.ts +0 -932
  88. package/src/internals/events/appsyncRequest.ts +0 -169
  89. package/src/internals/events/index.ts +0 -138
  90. package/src/internals/events/types.ts +0 -35
  91. package/src/internals/events/utils.ts +0 -77
  92. package/src/internals/graphqlAuth.ts +0 -87
  93. package/src/internals/graphqlRequest.ts +0 -30
@@ -1,97 +0,0 @@
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
@@ -1 +0,0 @@
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,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,MAAM,2BAA2B,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,sBAAsB,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SAAS,CAAC;AACV,KAAK;AACL,CAAC;AACW,MAAC,oBAAoB,GAAG,IAAI,uBAAuB;;;;"}
@@ -1,21 +0,0 @@
1
- import { AWSAppSyncRealTimeProviderOptions } from '../AWSAppSyncRealTimeProvider';
2
- export declare const isCustomDomain: (url: string) => boolean;
3
- export declare const getRealtimeEndpointUrl: (appSyncGraphqlEndpoint: string | undefined) => URL;
4
- /**
5
- *
6
- * @param headers - http headers
7
- * @returns uri-encoded query parameters derived from custom headers
8
- */
9
- export declare const queryParamsFromCustomHeaders: (headers?: AWSAppSyncRealTimeProviderOptions['additionalCustomHeaders']) => URLSearchParams;
10
- /**
11
- * Normalizes AppSync realtime endpoint URL
12
- *
13
- * @param appSyncGraphqlEndpoint - AppSync endpointUri from config
14
- * @param urlParams - URLSearchParams
15
- * @returns fully resolved string realtime endpoint URL
16
- */
17
- export declare const realtimeUrlWithQueryString: (appSyncGraphqlEndpoint: string | undefined, urlParams: URLSearchParams) => string;
18
- export declare const additionalHeadersFromOptions: (options: AWSAppSyncRealTimeProviderOptions) => Promise<{
19
- additionalCustomHeaders: {};
20
- libraryConfigHeaders: {};
21
- }>;
@@ -1,106 +0,0 @@
1
- import { AmplifyUrl, AmplifyUrlSearchParams } from '@aws-amplify/core/internals/utils';
2
-
3
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
- // SPDX-License-Identifier: Apache-2.0
5
- const protocol = 'wss://';
6
- const standardDomainPattern = /^https:\/\/\w{26}\.appsync-api\.\w{2}(?:(?:-\w{2,})+)-\d\.amazonaws.com(?:\.cn)?\/graphql$/i;
7
- const eventDomainPattern = /^https:\/\/\w{26}\.ddpg-api\.\w{2}(?:(?:-\w{2,})+)-\d\.amazonaws.com(?:\.cn)?\/event$/i;
8
- const customDomainPath = '/realtime';
9
- const isCustomDomain = (url) => {
10
- return url.match(standardDomainPattern) === null;
11
- };
12
- const isEventDomain = (url) => url.match(eventDomainPattern) !== null;
13
- const getRealtimeEndpointUrl = (appSyncGraphqlEndpoint) => {
14
- let realtimeEndpoint = appSyncGraphqlEndpoint ?? '';
15
- if (isEventDomain(realtimeEndpoint)) {
16
- realtimeEndpoint = realtimeEndpoint
17
- .concat(customDomainPath)
18
- .replace('ddpg-api', 'grt-gamma');
19
- }
20
- else if (isCustomDomain(realtimeEndpoint)) {
21
- realtimeEndpoint = realtimeEndpoint.concat(customDomainPath);
22
- }
23
- else {
24
- realtimeEndpoint = realtimeEndpoint
25
- .replace('appsync-api', 'appsync-realtime-api')
26
- .replace('gogi-beta', 'grt-beta')
27
- .replace('ddpg-api', 'grt-gamma');
28
- }
29
- realtimeEndpoint = realtimeEndpoint
30
- .replace('https://', protocol)
31
- .replace('http://', protocol);
32
- return new AmplifyUrl(realtimeEndpoint);
33
- };
34
- /**
35
- * Strips out `Authorization` header if present
36
- */
37
- const extractNonAuthHeaders = (headers) => {
38
- if (!headers) {
39
- return {};
40
- }
41
- if ('Authorization' in headers) {
42
- const { Authorization: _, ...nonAuthHeaders } = headers;
43
- return nonAuthHeaders;
44
- }
45
- return headers;
46
- };
47
- /**
48
- *
49
- * @param headers - http headers
50
- * @returns uri-encoded query parameters derived from custom headers
51
- */
52
- const queryParamsFromCustomHeaders = (headers) => {
53
- const nonAuthHeaders = extractNonAuthHeaders(headers);
54
- const params = new AmplifyUrlSearchParams();
55
- Object.entries(nonAuthHeaders).forEach(([k, v]) => {
56
- params.append(k, v);
57
- });
58
- return params;
59
- };
60
- /**
61
- * Normalizes AppSync realtime endpoint URL
62
- *
63
- * @param appSyncGraphqlEndpoint - AppSync endpointUri from config
64
- * @param urlParams - URLSearchParams
65
- * @returns fully resolved string realtime endpoint URL
66
- */
67
- const realtimeUrlWithQueryString = (appSyncGraphqlEndpoint, urlParams) => {
68
- const realtimeEndpointUrl = getRealtimeEndpointUrl(appSyncGraphqlEndpoint);
69
- // preserves any query params a customer might manually set in the configuration
70
- const existingParams = new AmplifyUrlSearchParams(realtimeEndpointUrl.search);
71
- for (const [k, v] of urlParams.entries()) {
72
- existingParams.append(k, v);
73
- }
74
- realtimeEndpointUrl.search = existingParams.toString();
75
- return realtimeEndpointUrl.toString();
76
- };
77
- // TODO: move to separate file?
78
- const additionalHeadersFromOptions = async (options) => {
79
- const { appSyncGraphqlEndpoint, query, libraryConfigHeaders = () => ({}), additionalHeaders = {}, authToken, } = options;
80
- let additionalCustomHeaders = {};
81
- const _libraryConfigHeaders = await libraryConfigHeaders();
82
- if (typeof additionalHeaders === 'function') {
83
- const requestOptions = {
84
- url: appSyncGraphqlEndpoint || '',
85
- queryString: query || '',
86
- };
87
- additionalCustomHeaders = await additionalHeaders(requestOptions);
88
- }
89
- else {
90
- additionalCustomHeaders = additionalHeaders;
91
- }
92
- // if an authorization header is set, have the explicit, operation-level authToken take precedence
93
- if (authToken) {
94
- additionalCustomHeaders = {
95
- ...additionalCustomHeaders,
96
- Authorization: authToken,
97
- };
98
- }
99
- return {
100
- additionalCustomHeaders,
101
- libraryConfigHeaders: _libraryConfigHeaders,
102
- };
103
- };
104
-
105
- export { additionalHeadersFromOptions, getRealtimeEndpointUrl, isCustomDomain, queryParamsFromCustomHeaders, realtimeUrlWithQueryString };
106
- //# sourceMappingURL=appsyncUrl.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"appsyncUrl.mjs","sources":["../../../../src/Providers/AWSWebSocketProvider/appsyncUrl.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AmplifyUrl, AmplifyUrlSearchParams, } from '@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';\nexport const isCustomDomain = (url) => {\n return url.match(standardDomainPattern) === null;\n};\nconst isEventDomain = (url) => url.match(eventDomainPattern) !== null;\nexport const 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 (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 AmplifyUrl(realtimeEndpoint);\n};\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 */\nexport const queryParamsFromCustomHeaders = (headers) => {\n const nonAuthHeaders = extractNonAuthHeaders(headers);\n const params = new AmplifyUrlSearchParams();\n Object.entries(nonAuthHeaders).forEach(([k, v]) => {\n params.append(k, v);\n });\n return params;\n};\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 */\nexport const realtimeUrlWithQueryString = (appSyncGraphqlEndpoint, urlParams) => {\n const realtimeEndpointUrl = getRealtimeEndpointUrl(appSyncGraphqlEndpoint);\n // preserves any query params a customer might manually set in the configuration\n const existingParams = new 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};\n// TODO: move to separate file?\nexport const 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};\n"],"names":[],"mappings":";;AAAA;AACA;AAEA,MAAM,QAAQ,GAAG,QAAQ,CAAC;AAC1B,MAAM,qBAAqB,GAAG,6FAA6F,CAAC;AAC5H,MAAM,kBAAkB,GAAG,wFAAwF,CAAC;AACpH,MAAM,gBAAgB,GAAG,WAAW,CAAC;AACzB,MAAC,cAAc,GAAG,CAAC,GAAG,KAAK;AACvC,IAAI,OAAO,GAAG,CAAC,KAAK,CAAC,qBAAqB,CAAC,KAAK,IAAI,CAAC;AACrD,EAAE;AACF,MAAM,aAAa,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,CAAC,kBAAkB,CAAC,KAAK,IAAI,CAAC;AAC1D,MAAC,sBAAsB,GAAG,CAAC,sBAAsB,KAAK;AAClE,IAAI,IAAI,gBAAgB,GAAG,sBAAsB,IAAI,EAAE,CAAC;AACxD,IAAI,IAAI,aAAa,CAAC,gBAAgB,CAAC,EAAE;AACzC,QAAQ,gBAAgB,GAAG,gBAAgB;AAC3C,aAAa,MAAM,CAAC,gBAAgB,CAAC;AACrC,aAAa,OAAO,CAAC,UAAU,EAAE,WAAW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AAc,CAAC,CAAC;AAC1E,KAAK;AACL,SAAS;AACT,QAAQ,uBAAuB,GAAG,iBAAiB,CAAC;AACpD,KAAK;AACL;AACA,IAAI,IAAI,SAAS,EAAE;AACnB,QAAQ,uBAAuB,GAAG;AAClC,YAAY,GAAG,uBAAuB;AACtC,YAAY,aAAa,EAAE,SAAS;AACpC,SAAS,CAAC;AACV,KAAK;AACL,IAAI,OAAO;AACX,QAAQ,uBAAuB;AAC/B,QAAQ,oBAAoB,EAAE,qBAAqB;AACnD,KAAK,CAAC;AACN;;;;"}
@@ -1,8 +0,0 @@
1
- import { AWSAppSyncRealTimeProviderOptions } from '../AWSAppSyncRealTimeProvider';
2
- type AWSAppSyncRealTimeAuthInput = Partial<AWSAppSyncRealTimeProviderOptions> & {
3
- canonicalUri: string;
4
- payload: string;
5
- host?: string | undefined;
6
- };
7
- export declare const awsRealTimeHeaderBasedAuth: ({ apiKey, authenticationType, canonicalUri, appSyncGraphqlEndpoint, region, additionalCustomHeaders, payload, }: AWSAppSyncRealTimeAuthInput) => Promise<Record<string, string | undefined> | undefined>;
8
- export {};
@@ -1,97 +0,0 @@
1
- import { ConsoleLogger, fetchAuthSession } from '@aws-amplify/core';
2
- import { signRequest } from '@aws-amplify/core/internals/aws-client-utils';
3
- import { AmplifyUrl } from '@aws-amplify/core/internals/utils';
4
- import { AWS_APPSYNC_REALTIME_HEADERS } from '../constants.mjs';
5
-
6
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
7
- // SPDX-License-Identifier: Apache-2.0
8
- const logger = new ConsoleLogger('AWSAppSyncRealTimeProvider Auth');
9
- const awsAuthTokenHeader = async ({ host }) => {
10
- const session = await fetchAuthSession();
11
- return {
12
- Authorization: session?.tokens?.accessToken?.toString(),
13
- host,
14
- };
15
- };
16
- const awsRealTimeApiKeyHeader = async ({ apiKey, host, }) => {
17
- const dt = new Date();
18
- const dtStr = dt.toISOString().replace(/[:-]|\.\d{3}/g, '');
19
- return {
20
- host,
21
- 'x-amz-date': dtStr,
22
- 'x-api-key': apiKey,
23
- };
24
- };
25
- const awsRealTimeIAMHeader = async ({ payload, canonicalUri, appSyncGraphqlEndpoint, region, }) => {
26
- const endpointInfo = {
27
- region,
28
- service: 'appsync',
29
- };
30
- const creds = (await fetchAuthSession()).credentials;
31
- const request = {
32
- url: `${appSyncGraphqlEndpoint}${canonicalUri}`,
33
- data: payload,
34
- method: 'POST',
35
- headers: { ...AWS_APPSYNC_REALTIME_HEADERS },
36
- };
37
- const signedParams = signRequest({
38
- headers: request.headers,
39
- method: request.method,
40
- url: new AmplifyUrl(request.url),
41
- body: request.data,
42
- }, {
43
- credentials: creds,
44
- signingRegion: endpointInfo.region,
45
- signingService: endpointInfo.service,
46
- });
47
- return signedParams.headers;
48
- };
49
- const customAuthHeader = async ({ host, additionalCustomHeaders, }) => {
50
- /**
51
- * If `additionalHeaders` was provided to the subscription as a function,
52
- * the headers that are returned by that function will already have been
53
- * provided before this function is called.
54
- */
55
- if (!additionalCustomHeaders?.Authorization) {
56
- throw new Error('No auth token specified');
57
- }
58
- return {
59
- Authorization: additionalCustomHeaders.Authorization,
60
- host,
61
- };
62
- };
63
- const awsRealTimeHeaderBasedAuth = async ({ apiKey, authenticationType, canonicalUri, appSyncGraphqlEndpoint, region, additionalCustomHeaders, payload, }) => {
64
- const headerHandler = {
65
- apiKey: awsRealTimeApiKeyHeader,
66
- iam: awsRealTimeIAMHeader,
67
- oidc: awsAuthTokenHeader,
68
- userPool: awsAuthTokenHeader,
69
- lambda: customAuthHeader,
70
- none: customAuthHeader,
71
- };
72
- if (!authenticationType || !headerHandler[authenticationType]) {
73
- logger.debug(`Authentication type ${authenticationType} not supported`);
74
- return undefined;
75
- }
76
- else {
77
- const handler = headerHandler[authenticationType];
78
- const host = appSyncGraphqlEndpoint
79
- ? new AmplifyUrl(appSyncGraphqlEndpoint).host
80
- : undefined;
81
- const resolvedApiKey = authenticationType === 'apiKey' ? apiKey : undefined;
82
- logger.debug(`Authenticating with ${JSON.stringify(authenticationType)}`);
83
- const result = await handler({
84
- payload,
85
- canonicalUri,
86
- appSyncGraphqlEndpoint,
87
- apiKey: resolvedApiKey,
88
- region,
89
- host,
90
- additionalCustomHeaders,
91
- });
92
- return result;
93
- }
94
- };
95
-
96
- export { awsRealTimeHeaderBasedAuth };
97
- //# sourceMappingURL=authHeaders.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"authHeaders.mjs","sources":["../../../../src/Providers/AWSWebSocketProvider/authHeaders.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger, fetchAuthSession } from '@aws-amplify/core';\nimport { signRequest } from '@aws-amplify/core/internals/aws-client-utils';\nimport { AmplifyUrl } from '@aws-amplify/core/internals/utils';\nimport { AWS_APPSYNC_REALTIME_HEADERS } from '../constants';\nconst logger = new ConsoleLogger('AWSAppSyncRealTimeProvider Auth');\nconst awsAuthTokenHeader = async ({ host }) => {\n const session = await 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 fetchAuthSession()).credentials;\n const request = {\n url: `${appSyncGraphqlEndpoint}${canonicalUri}`,\n data: payload,\n method: 'POST',\n headers: { ...AWS_APPSYNC_REALTIME_HEADERS },\n };\n const signedParams = signRequest({\n headers: request.headers,\n method: request.method,\n url: new 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};\nexport const 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 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};\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAKA,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,iCAAiC,CAAC,CAAC;AACpE,MAAM,kBAAkB,GAAG,OAAO,EAAE,IAAI,EAAE,KAAK;AAC/C,IAAI,MAAM,OAAO,GAAG,MAAM,gBAAgB,EAAE,CAAC;AAC7C,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,MAA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QAAQ,MAAM,CAAC,KAAK,CAAC,CAAC,oBAAoB,EAAE,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;AAClF,QAAQ,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;AACrC,YAAY,OAAO;AACnB,YAAY,YAAY;AACxB,YAAY,sBAAsB;AAClC,YAAY,MAAM,EAAE,cAAc;AAClC,YAAY,MAAM;AAClB,YAAY,IAAI;AAChB,YAAY,uBAAuB;AACnC,SAAS,CAAC,CAAC;AACX,QAAQ,OAAO,MAAM,CAAC;AACtB,KAAK;AACL;;;;"}
@@ -1,89 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { ConsoleLogger } from '@aws-amplify/core';
3
- import { CustomUserAgentDetails, DocumentType } from '@aws-amplify/core/internals/utils';
4
- import { PubSubContentObserver } from '../../types/PubSub';
5
- import { SUBSCRIPTION_STATUS } from '../constants';
6
- import type { AWSAppSyncRealTimeProviderOptions } from '../AWSAppSyncRealTimeProvider';
7
- export interface ObserverQuery {
8
- observer: PubSubContentObserver;
9
- query: string;
10
- variables: DocumentType;
11
- subscriptionState: SUBSCRIPTION_STATUS;
12
- subscriptionReadyCallback?(): void;
13
- subscriptionFailedCallback?(reason?: any): void;
14
- startAckTimeoutId?: ReturnType<typeof setTimeout>;
15
- }
16
- interface AWSWebSocketProviderArgs {
17
- providerName: string;
18
- wsProtocolName: string;
19
- }
20
- export declare abstract class AWSWebSocketProvider {
21
- protected logger: ConsoleLogger;
22
- protected subscriptionObserverMap: Map<string, ObserverQuery>;
23
- private awsRealTimeSocket?;
24
- private socketStatus;
25
- private keepAliveTimeoutId?;
26
- private keepAliveTimeout;
27
- private keepAliveAlertTimeoutId?;
28
- private promiseArray;
29
- private connectionState;
30
- private readonly connectionStateMonitor;
31
- private readonly reconnectionMonitor;
32
- private connectionStateMonitorSubscription;
33
- private readonly wsProtocolName;
34
- constructor(args: AWSWebSocketProviderArgs);
35
- /**
36
- * Mark the socket closed and release all active listeners
37
- */
38
- close(): void;
39
- subscribe(options?: AWSAppSyncRealTimeProviderOptions, customUserAgentDetails?: CustomUserAgentDetails): Observable<Record<string, unknown>>;
40
- protected connect(options: AWSAppSyncRealTimeProviderOptions): Promise<void>;
41
- protected publish(options: AWSAppSyncRealTimeProviderOptions, customUserAgentDetails?: CustomUserAgentDetails): Promise<void>;
42
- private _connectWebSocket;
43
- private _publishMessage;
44
- private _cleanupSubscription;
45
- private _startConnectionStateMonitoring;
46
- protected abstract _prepareSubscriptionPayload(param: {
47
- options: AWSAppSyncRealTimeProviderOptions;
48
- subscriptionId: string;
49
- customUserAgentDetails: CustomUserAgentDetails | undefined;
50
- additionalCustomHeaders: Record<string, string>;
51
- libraryConfigHeaders: Record<string, string>;
52
- publish?: boolean;
53
- }): Promise<string>;
54
- private _startSubscriptionWithAWSAppSyncRealTime;
55
- private _logStartSubscriptionError;
56
- private _waitForSubscriptionToBeConnected;
57
- protected abstract _unsubscribeMessage(subscriptionId: string): {
58
- id: string;
59
- type: string;
60
- };
61
- private _sendUnsubscriptionMessage;
62
- private _removeSubscriptionObserver;
63
- private _closeSocketIfRequired;
64
- protected abstract _handleSubscriptionData(message: MessageEvent): [
65
- boolean,
66
- {
67
- id: string;
68
- payload: string | Record<string, unknown>;
69
- type: string;
70
- }
71
- ];
72
- private _handleIncomingSubscriptionMessage;
73
- private _errorDisconnect;
74
- private _timeoutStartSubscriptionAck;
75
- private _initializeWebSocketConnection;
76
- private _establishRetryableConnection;
77
- private _openConnection;
78
- private _getNewWebSocket;
79
- private _initiateHandshake;
80
- private _registerWebsocketHandlers;
81
- /**
82
- * Open WebSocket connection & perform handshake
83
- * Ref: https://docs.aws.amazon.com/appsync/latest/devguide/real-time-websocket-client.html#appsynclong-real-time-websocket-client-implementation-guide-for-graphql-subscriptions
84
- *
85
- * @param subprotocol -
86
- */
87
- private _establishConnection;
88
- }
89
- export {};