@aws-amplify/api-graphql 4.4.0 → 4.4.1-events.619318.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.
Files changed (98) hide show
  1. package/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js +94 -0
  2. package/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js.map +1 -0
  3. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +35 -732
  4. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
  5. package/dist/cjs/Providers/AWSWebSocketProvider/appsyncUrl.js +112 -0
  6. package/dist/cjs/Providers/AWSWebSocketProvider/appsyncUrl.js.map +1 -0
  7. package/dist/cjs/Providers/AWSWebSocketProvider/authHeaders.js +99 -0
  8. package/dist/cjs/Providers/AWSWebSocketProvider/authHeaders.js.map +1 -0
  9. package/dist/cjs/Providers/AWSWebSocketProvider/index.js +623 -0
  10. package/dist/cjs/Providers/AWSWebSocketProvider/index.js.map +1 -0
  11. package/dist/cjs/Providers/constants.js +32 -2
  12. package/dist/cjs/Providers/constants.js.map +1 -1
  13. package/dist/cjs/index.js +4 -1
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/internals/InternalGraphQLAPI.js +8 -67
  16. package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
  17. package/dist/cjs/internals/events/appsyncRequest.js +97 -0
  18. package/dist/cjs/internals/events/appsyncRequest.js.map +1 -0
  19. package/dist/cjs/internals/events/index.js +73 -0
  20. package/dist/cjs/internals/events/index.js.map +1 -0
  21. package/dist/cjs/internals/events/types.js +6 -0
  22. package/dist/cjs/internals/events/types.js.map +1 -0
  23. package/dist/cjs/internals/events/utils.js +57 -0
  24. package/dist/cjs/internals/events/utils.js.map +1 -0
  25. package/dist/cjs/internals/graphqlAuth.js +64 -0
  26. package/dist/cjs/internals/graphqlAuth.js.map +1 -0
  27. package/dist/cjs/internals/graphqlRequest.js +20 -0
  28. package/dist/cjs/internals/graphqlRequest.js.map +1 -0
  29. package/dist/cjs/utils/ReconnectionMonitor.js +1 -1
  30. package/dist/cjs/utils/ReconnectionMonitor.js.map +1 -1
  31. package/dist/cjs/utils/resolveConfig.js +19 -0
  32. package/dist/cjs/utils/resolveConfig.js.map +1 -1
  33. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.d.ts +42 -0
  34. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs +93 -0
  35. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs.map +1 -0
  36. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +24 -71
  37. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +35 -732
  38. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
  39. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.d.ts +21 -0
  40. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs +106 -0
  41. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs.map +1 -0
  42. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.d.ts +8 -0
  43. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs +97 -0
  44. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs.map +1 -0
  45. package/dist/esm/Providers/AWSWebSocketProvider/index.d.ts +83 -0
  46. package/dist/esm/Providers/AWSWebSocketProvider/index.mjs +621 -0
  47. package/dist/esm/Providers/AWSWebSocketProvider/index.mjs.map +1 -0
  48. package/dist/esm/Providers/constants.d.ts +33 -3
  49. package/dist/esm/Providers/constants.mjs +32 -2
  50. package/dist/esm/Providers/constants.mjs.map +1 -1
  51. package/dist/esm/index.d.ts +3 -0
  52. package/dist/esm/index.mjs +2 -0
  53. package/dist/esm/index.mjs.map +1 -1
  54. package/dist/esm/internals/InternalGraphQLAPI.d.ts +0 -1
  55. package/dist/esm/internals/InternalGraphQLAPI.mjs +9 -68
  56. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  57. package/dist/esm/internals/events/appsyncRequest.d.ts +14 -0
  58. package/dist/esm/internals/events/appsyncRequest.mjs +96 -0
  59. package/dist/esm/internals/events/appsyncRequest.mjs.map +1 -0
  60. package/dist/esm/internals/events/index.d.ts +17 -0
  61. package/dist/esm/internals/events/index.mjs +69 -0
  62. package/dist/esm/internals/events/index.mjs.map +1 -0
  63. package/dist/esm/internals/events/types.d.ts +23 -0
  64. package/dist/esm/internals/events/types.mjs +2 -0
  65. package/dist/esm/internals/events/types.mjs.map +1 -0
  66. package/dist/esm/internals/events/utils.d.ts +16 -0
  67. package/dist/esm/internals/events/utils.mjs +53 -0
  68. package/dist/esm/internals/events/utils.mjs.map +1 -0
  69. package/dist/esm/internals/graphqlAuth.d.ts +3 -0
  70. package/dist/esm/internals/graphqlAuth.mjs +64 -0
  71. package/dist/esm/internals/graphqlAuth.mjs.map +1 -0
  72. package/dist/esm/internals/graphqlRequest.d.ts +3 -0
  73. package/dist/esm/internals/graphqlRequest.mjs +18 -0
  74. package/dist/esm/internals/graphqlRequest.mjs.map +1 -0
  75. package/dist/esm/utils/ConnectionStateMonitor.d.ts +29 -1
  76. package/dist/esm/utils/ReconnectionMonitor.d.ts +1 -1
  77. package/dist/esm/utils/ReconnectionMonitor.mjs +1 -1
  78. package/dist/esm/utils/ReconnectionMonitor.mjs.map +1 -1
  79. package/dist/esm/utils/resolveConfig.mjs +19 -0
  80. package/dist/esm/utils/resolveConfig.mjs.map +1 -1
  81. package/package.json +4 -4
  82. package/src/Providers/AWSAppSyncEventsProvider/index.ts +187 -0
  83. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +58 -1051
  84. package/src/Providers/AWSWebSocketProvider/appsyncUrl.ts +151 -0
  85. package/src/Providers/AWSWebSocketProvider/authHeaders.ts +146 -0
  86. package/src/Providers/AWSWebSocketProvider/index.ts +925 -0
  87. package/src/Providers/constants.ts +32 -2
  88. package/src/index.ts +5 -0
  89. package/src/internals/InternalGraphQLAPI.ts +15 -102
  90. package/src/internals/events/appsyncRequest.ts +169 -0
  91. package/src/internals/events/index.ts +138 -0
  92. package/src/internals/events/types.ts +35 -0
  93. package/src/internals/events/utils.ts +77 -0
  94. package/src/internals/graphqlAuth.ts +87 -0
  95. package/src/internals/graphqlRequest.ts +30 -0
  96. package/src/utils/ConnectionStateMonitor.ts +2 -13
  97. package/src/utils/ReconnectionMonitor.ts +1 -1
  98. package/src/utils/resolveConfig.ts +23 -0
@@ -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.AppSyncEventProvider.close();\n}\nexports.closeAll = closeAll;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,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,SAAS,QAAQ,GAAG;AACpB,IAAI,0BAA0B,CAAC,oBAAoB,CAAC,KAAK,EAAE,CAAC;AAC5D,CAAC;AACD,OAAO,CAAC,QAAQ,GAAG,QAAQ;;"}
@@ -0,0 +1,6 @@
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
+ //# sourceMappingURL=types.js.map
@@ -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,eAAe,CAAC;AAC/B,KAAK;AACL,IAAI,IAAI,gBAAgB,KAAK,cAAc,EAAE;AAC7C,QAAQ,OAAO,KAAK,CAAC;AACrB,KAAK;AACL,IAAI,OAAO,gBAAgB,CAAC;AAC5B,CAAC,CAAC;AACF,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC;AACtC,MAAM,SAAS,GAAG,MAAM;AACxB,IAAI,MAAM,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;AAC9C,IAAI,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC;AAC5C,IAAI,IAAI,CAAC,YAAY,EAAE;AACv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C,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 = headerB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F,aAAa;AACb,YAAY,OAAO,CAAC,EAAE;AACtB;AACA,gBAAgB,MAAM,IAAI,QAAQ,CAAC,eAAe,CAAC;AACnD,oBAAoB,GAAG,WAAW,CAAC,iBAAiB;AACpD,oBAAoB,eAAe,EAAE,CAAC;AACtC,iBAAiB,CAAC,CAAC;AACnB,aAAa;AACb;AACA;AACA;AACA,YAAY,IAAI,CAAC,KAAK,EAAE;AACxB,gBAAgB,MAAM,IAAI,QAAQ,CAAC,eAAe,CAAC,WAAW,CAAC,mBAAmB,CAAC,CAAC;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
- * Reconnnect attempts are delayed by 5 seconds to let the interface settle.
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 * Reconnnect 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;AAC1D,IAAI,cAAc,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,CAAC;AACxD,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,KAAK,OAAO,CAAC,cAAc,GAAG,EAAE,CAAC,CAAC,CAAC;AAC7E;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,mBAAmB,CAAC;AAC1B,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,kBAAkB,GAAG,EAAE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AI;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;;"}
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;AAC1D,IAAI,cAAc,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,CAAC;AACxD,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,KAAK,OAAO,CAAC,cAAc,GAAG,EAAE,CAAC,CAAC,CAAC;AAC7E;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,mBAAmB,CAAC;AAC1B,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,kBAAkB,GAAG,EAAE,CAAC;AACrC,KAAK;AACL;AACA;AACA;AACA,IAAI,WAAW,CAAC,iBAAiB,EAAE;AACnC,QAAQ,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;AACxD,KAAK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AO,CAAC,iBAAiB,IAAI;AAC7D,YAAY,iBAAiB,CAAC,IAAI,IAAI,CAAC;AACvC,SAAS,CAAC,CAAC;AACX,KAAK;AACL,CAAC;AACD,OAAO,CAAC,mBAAmB,GAAG,mBAAmB;;"}
@@ -29,4 +29,23 @@ const resolveConfig = (amplify) => {
29
29
  };
30
30
  };
31
31
  exports.resolveConfig = resolveConfig;
32
+ // /**
33
+ // * @internal
34
+ // */
35
+ // export const resolveEventsConfig = (amplify: AmplifyClassV6) => {
36
+ // const config = amplify.getConfig();
37
+ // if (!config.API?.Events) {
38
+ // logger.warn(
39
+ // 'The Events configuration is missing. This is likely due to Amplify.configure() not being called prior to using events.connect() or events.post().',
40
+ // );
41
+ // }
42
+ // const { apiKey, endpoint, defaultAuthMode, region } =
43
+ // config.API?.Events ?? {};
44
+ // return {
45
+ // apiKey,
46
+ // defaultAuthMode,
47
+ // appSyncGraphqlEndpoint: endpoint,
48
+ // region,
49
+ // };
50
+ // };
32
51
  //# sourceMappingURL=resolveConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveConfig.js","sources":["../../../src/utils/resolveConfig.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.resolveConfig = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst errors_1 = require(\"./errors\");\nconst logger = new core_1.ConsoleLogger('GraphQLAPI resolveConfig');\n/**\n * @internal\n */\nconst resolveConfig = (amplify) => {\n const config = amplify.getConfig();\n if (!config.API?.GraphQL) {\n logger.warn('The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().');\n }\n const { apiKey, customEndpoint, customEndpointRegion, defaultAuthMode, endpoint, region, } = config.API?.GraphQL ?? {};\n // TODO: re-enable when working in all test environments:\n // assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);\n (0, errors_1.assertValidationError)(!(!customEndpoint && customEndpointRegion), errors_1.APIValidationErrorCode.NoCustomEndpoint);\n return {\n apiKey,\n customEndpoint,\n customEndpointRegion,\n defaultAuthMode,\n endpoint,\n region,\n };\n};\nexports.resolveConfig = resolveConfig;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;AAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACrC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,0BAA0B,CAAC,CAAC;AACpE;AACA;AACA;AACA,MAAM,aAAa,GAAG,CAAC,OAAO,KAAK;AACnC,IAAI,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;AACvC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE;AAC9B,QAAQ,MAAM,CAAC,IAAI,CAAC,yHAAyH,CAAC,CAAC;AAC/I,KAAK;AACL,IAAI,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,oBAAoB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,EAAE,OAAO,IAAI,EAAE,CAAC;AAC3H;AACA;AACA,IAAI,IAAI,QAAQ,CAAC,qBAAqB,EAAE,EAAE,CAAC,cAAc,IAAI,oBAAoB,CAAC,EAAE,QAAQ,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;AACtI,IAAI,OAAO;AACX,QAAQ,MAAM;AACd,QAAQ,cAAc;AACtB,QAAQ,oBAAoB;AAC5B,QAAQ,eAAe;AACvB,QAAQ,QAAQ;AAChB,QAAQ,MAAM;AACd,KAAK,CAAC;AACN,CAAC,CAAC;AACF,OAAO,CAAC,aAAa,GAAG,aAAa;;"}
1
+ {"version":3,"file":"resolveConfig.js","sources":["../../../src/utils/resolveConfig.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.resolveConfig = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst errors_1 = require(\"./errors\");\nconst logger = new core_1.ConsoleLogger('GraphQLAPI resolveConfig');\n/**\n * @internal\n */\nconst resolveConfig = (amplify) => {\n const config = amplify.getConfig();\n if (!config.API?.GraphQL) {\n logger.warn('The API configuration is missing. This is likely due to Amplify.configure() not being called prior to generateClient().');\n }\n const { apiKey, customEndpoint, customEndpointRegion, defaultAuthMode, endpoint, region, } = config.API?.GraphQL ?? {};\n // TODO: re-enable when working in all test environments:\n // assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);\n (0, errors_1.assertValidationError)(!(!customEndpoint && customEndpointRegion), errors_1.APIValidationErrorCode.NoCustomEndpoint);\n return {\n apiKey,\n customEndpoint,\n customEndpointRegion,\n defaultAuthMode,\n endpoint,\n region,\n };\n};\nexports.resolveConfig = resolveConfig;\n// /**\n// * @internal\n// */\n// export const resolveEventsConfig = (amplify: AmplifyClassV6) => {\n// \tconst config = amplify.getConfig();\n// \tif (!config.API?.Events) {\n// \t\tlogger.warn(\n// \t\t\t'The Events configuration is missing. This is likely due to Amplify.configure() not being called prior to using events.connect() or events.post().',\n// \t\t);\n// \t}\n// \tconst { apiKey, endpoint, defaultAuthMode, region } =\n// \t\tconfig.API?.Events ?? {};\n// \treturn {\n// \t\tapiKey,\n// \t\tdefaultAuthMode,\n// \t\tappSyncGraphqlEndpoint: endpoint,\n// \t\tregion,\n// \t};\n// };\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,aAAa,GAAG,KAAK,CAAC,CAAC;AAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACrC,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,aAAa,CAAC,0BAA0B,CAAC,CAAC;AACpE;AACA;AACA;AACA,MAAM,aAAa,GAAG,CAAC,OAAO,KAAK;AACnC,IAAI,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;AACvC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE;AAC9B,QAAQ,MAAM,CAAC,IAAI,CAAC,yHAAyH,CAAC,CAAC;AAC/I,KAAK;AACL,IAAI,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,oBAAoB,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,EAAE,OAAO,IAAI,EAAE,CAAC;AAC3H;AACA;AACA,IAAI,IAAI,QAAQ,CAAC,qBAAqB,EAAE,EAAE,CAAC,cAAc,IAAI,oBAAoB,CAAC,EAAE,QAAQ,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,CAAC;AACtI,IAAI,OAAO;AACX,QAAQ,MAAM;AACd,QAAQ,cAAc;AACtB,QAAQ,oBAAoB;AAC5B,QAAQ,eAAe;AACvB,QAAQ,QAAQ;AAChB,QAAQ,MAAM;AACd,KAAK,CAAC;AACN,CAAC,CAAC;AACF,OAAO,CAAC,aAAa,GAAG,aAAa,CAAC;AACtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;"}
@@ -0,0 +1,42 @@
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
+ connect(options: AWSAppSyncEventProviderOptions): Promise<void>;
25
+ subscribe(options?: AWSAppSyncEventProviderOptions, customUserAgentDetails?: CustomUserAgentDetails): import("rxjs").Observable<Record<string, unknown>>;
26
+ publish(options: AWSAppSyncEventProviderOptions, customUserAgentDetails?: CustomUserAgentDetails): Promise<void>;
27
+ protected _prepareSubscriptionPayload({ options, subscriptionId, customUserAgentDetails, additionalCustomHeaders, libraryConfigHeaders, publish, }: {
28
+ options: AWSAppSyncEventProviderOptions;
29
+ subscriptionId: string;
30
+ customUserAgentDetails: CustomUserAgentDetails | undefined;
31
+ additionalCustomHeaders: Record<string, string>;
32
+ libraryConfigHeaders: Record<string, string>;
33
+ publish?: boolean;
34
+ }): Promise<string>;
35
+ protected _handleSubscriptionData(message: MessageEvent): [boolean, DataResponse];
36
+ protected _unsubscribeMessage(subscriptionId: string): {
37
+ id: string;
38
+ type: string;
39
+ };
40
+ }
41
+ export declare const AppSyncEventProvider: AWSAppSyncEventProvider;
42
+ export {};
@@ -0,0 +1,93 @@
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
+ class AWSAppSyncEventProvider extends AWSWebSocketProvider {
10
+ constructor() {
11
+ super(PROVIDER_NAME);
12
+ }
13
+ async connect(options) {
14
+ super.connect(options);
15
+ }
16
+ subscribe(options, customUserAgentDetails) {
17
+ return super.subscribe(options, customUserAgentDetails).pipe();
18
+ }
19
+ async publish(options, customUserAgentDetails) {
20
+ super.publish(options, customUserAgentDetails);
21
+ }
22
+ async _prepareSubscriptionPayload({ options, subscriptionId, customUserAgentDetails, additionalCustomHeaders, libraryConfigHeaders, publish, }) {
23
+ const { appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, } = options;
24
+ // This will be needed for WS publish
25
+ // const data = {
26
+ // events: [variables],
27
+ // };
28
+ const serializedData = JSON.stringify([variables]);
29
+ const headers = {
30
+ ...(await awsRealTimeHeaderBasedAuth({
31
+ apiKey,
32
+ appSyncGraphqlEndpoint,
33
+ authenticationType,
34
+ payload: serializedData,
35
+ canonicalUri: '',
36
+ region,
37
+ additionalCustomHeaders,
38
+ })),
39
+ ...libraryConfigHeaders,
40
+ ...additionalCustomHeaders,
41
+ [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),
42
+ };
43
+ // Commented out code will be needed for WS publish
44
+ const subscriptionMessage = {
45
+ id: subscriptionId,
46
+ channel: query,
47
+ // events: [JSON.stringify(variables)],
48
+ authorization: {
49
+ ...headers,
50
+ },
51
+ // payload: {
52
+ // events: serializedData,
53
+ // extensions: {
54
+ // authorization: {
55
+ // ...headers,
56
+ // },
57
+ // },
58
+ // },
59
+ type: publish
60
+ ? MESSAGE_TYPES.EVENT_PUBLISH
61
+ : MESSAGE_TYPES.EVENT_SUBSCRIBE,
62
+ };
63
+ const serializedSubscriptionMessage = JSON.stringify(subscriptionMessage);
64
+ return serializedSubscriptionMessage;
65
+ }
66
+ _handleSubscriptionData(message) {
67
+ this.logger.debug(`subscription message from AWS AppSync Events: ${message.data}`);
68
+ const { id = '', event: payload, type, } = JSON.parse(String(message.data));
69
+ const { observer = null, query = '', variables = {}, } = this.subscriptionObserverMap.get(id) || {};
70
+ this.logger.debug({ id, observer, query, variables });
71
+ if (type === MESSAGE_TYPES.DATA && payload) {
72
+ const deserializedEvent = JSON.parse(payload);
73
+ if (observer) {
74
+ observer.next(deserializedEvent);
75
+ }
76
+ else {
77
+ this.logger.debug(`observer not found for id: ${id}`);
78
+ }
79
+ return [true, { id, type, payload: deserializedEvent }];
80
+ }
81
+ return [false, { id, type, payload }];
82
+ }
83
+ _unsubscribeMessage(subscriptionId) {
84
+ return {
85
+ id: subscriptionId,
86
+ type: MESSAGE_TYPES.EVENT_STOP,
87
+ };
88
+ }
89
+ }
90
+ const AppSyncEventProvider = new AWSAppSyncEventProvider();
91
+
92
+ export { AppSyncEventProvider };
93
+ //# 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';\nclass AWSAppSyncEventProvider extends 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 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 App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aAAa,CAAC,IAAI,IAAI,OAAO,EAAE;AACpD,YAAY,MAAM,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC1D,YAAY,IAAI,QAAQ,EAAE;AAC1B,gBAAgB,QAAQ,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;AACjD,aAAa;AACb,iBAAiB;AACjB,gBAAgB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,2BAA2B,EAAE,EAAE,CAAC,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 { PubSubContentObserver } from '../../types/PubSub';
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?: Record<string, DocumentType>;
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
- export declare class AWSAppSyncRealTimeProvider {
29
- private awsRealTimeSocket?;
30
- private socketStatus;
31
- private keepAliveTimeoutId?;
32
- private keepAliveTimeout;
33
- private keepAliveAlertTimeoutId?;
34
- private subscriptionObserverMap;
35
- private promiseArray;
36
- private connectionState;
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;
27
+ subscribe(options?: AWSAppSyncRealTimeProviderOptions, customUserAgentDetails?: CustomUserAgentDetails): import("rxjs").Observable<Record<string, unknown>>;
46
28
  getProviderName(): string;
47
- private isCustomDomain;
48
- subscribe(options?: AWSAppSyncRealTimeProviderOptions, customUserAgentDetails?: CustomUserAgentDetails): Observable<Record<string, unknown>>;
49
- private _startSubscriptionWithAWSAppSyncRealTime;
50
- private _logStartSubscriptionError;
51
- private _waitForSubscriptionToBeConnected;
52
- private _sendUnsubscriptionMessage;
53
- private _removeSubscriptionObserver;
54
- private _closeSocketIfRequired;
55
- private _handleIncomingSubscriptionMessage;
56
- private _errorDisconnect;
57
- private _timeoutStartSubscriptionAck;
58
- /**
59
- * Strips out `Authorization` header if present
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;
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 {};