@aws-amplify/api-graphql 4.4.3 → 4.4.4-unstable.5d549c3.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 (93) hide show
  1. package/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js +98 -0
  2. package/dist/cjs/Providers/AWSAppSyncEventsProvider/index.js.map +1 -0
  3. package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +34 -731
  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 +624 -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 +97 -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/esm/Providers/AWSAppSyncEventsProvider/index.d.ts +43 -0
  32. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs +97 -0
  33. package/dist/esm/Providers/AWSAppSyncEventsProvider/index.mjs.map +1 -0
  34. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +24 -71
  35. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +34 -731
  36. package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
  37. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.d.ts +21 -0
  38. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs +106 -0
  39. package/dist/esm/Providers/AWSWebSocketProvider/appsyncUrl.mjs.map +1 -0
  40. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.d.ts +8 -0
  41. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs +97 -0
  42. package/dist/esm/Providers/AWSWebSocketProvider/authHeaders.mjs.map +1 -0
  43. package/dist/esm/Providers/AWSWebSocketProvider/index.d.ts +89 -0
  44. package/dist/esm/Providers/AWSWebSocketProvider/index.mjs +622 -0
  45. package/dist/esm/Providers/AWSWebSocketProvider/index.mjs.map +1 -0
  46. package/dist/esm/Providers/constants.d.ts +33 -3
  47. package/dist/esm/Providers/constants.mjs +32 -2
  48. package/dist/esm/Providers/constants.mjs.map +1 -1
  49. package/dist/esm/index.d.ts +3 -0
  50. package/dist/esm/index.mjs +2 -0
  51. package/dist/esm/index.mjs.map +1 -1
  52. package/dist/esm/internals/InternalGraphQLAPI.d.ts +0 -1
  53. package/dist/esm/internals/InternalGraphQLAPI.mjs +9 -68
  54. package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
  55. package/dist/esm/internals/events/appsyncRequest.d.ts +14 -0
  56. package/dist/esm/internals/events/appsyncRequest.mjs +96 -0
  57. package/dist/esm/internals/events/appsyncRequest.mjs.map +1 -0
  58. package/dist/esm/internals/events/index.d.ts +47 -0
  59. package/dist/esm/internals/events/index.mjs +93 -0
  60. package/dist/esm/internals/events/index.mjs.map +1 -0
  61. package/dist/esm/internals/events/types.d.ts +59 -0
  62. package/dist/esm/internals/events/types.mjs +2 -0
  63. package/dist/esm/internals/events/types.mjs.map +1 -0
  64. package/dist/esm/internals/events/utils.d.ts +16 -0
  65. package/dist/esm/internals/events/utils.mjs +53 -0
  66. package/dist/esm/internals/events/utils.mjs.map +1 -0
  67. package/dist/esm/internals/graphqlAuth.d.ts +3 -0
  68. package/dist/esm/internals/graphqlAuth.mjs +64 -0
  69. package/dist/esm/internals/graphqlAuth.mjs.map +1 -0
  70. package/dist/esm/internals/graphqlRequest.d.ts +3 -0
  71. package/dist/esm/internals/graphqlRequest.mjs +18 -0
  72. package/dist/esm/internals/graphqlRequest.mjs.map +1 -0
  73. package/dist/esm/utils/ConnectionStateMonitor.d.ts +29 -1
  74. package/dist/esm/utils/ReconnectionMonitor.d.ts +1 -1
  75. package/dist/esm/utils/ReconnectionMonitor.mjs +1 -1
  76. package/dist/esm/utils/ReconnectionMonitor.mjs.map +1 -1
  77. package/package.json +4 -4
  78. package/src/Providers/AWSAppSyncEventsProvider/index.ts +192 -0
  79. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +56 -1049
  80. package/src/Providers/AWSWebSocketProvider/appsyncUrl.ts +151 -0
  81. package/src/Providers/AWSWebSocketProvider/authHeaders.ts +146 -0
  82. package/src/Providers/AWSWebSocketProvider/index.ts +932 -0
  83. package/src/Providers/constants.ts +32 -2
  84. package/src/index.ts +5 -0
  85. package/src/internals/InternalGraphQLAPI.ts +15 -102
  86. package/src/internals/events/appsyncRequest.ts +169 -0
  87. package/src/internals/events/index.ts +161 -0
  88. package/src/internals/events/types.ts +71 -0
  89. package/src/internals/events/utils.ts +77 -0
  90. package/src/internals/graphqlAuth.ts +87 -0
  91. package/src/internals/graphqlRequest.ts +30 -0
  92. package/src/utils/ConnectionStateMonitor.ts +2 -13
  93. package/src/utils/ReconnectionMonitor.ts +1 -1
@@ -0,0 +1,97 @@
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
+ * @experimental API may change in future versions
13
+ *
14
+ * Establish a WebSocket connection to an Events channel
15
+ *
16
+ * @example
17
+ * const channel = await events.connect("default/channel")
18
+ *
19
+ * channel.subscribe({
20
+ * next: (data) => { console.log(data) },
21
+ * error: (err) => { console.error(err) },
22
+ * })
23
+ *
24
+ * @example // authMode override
25
+ * const channel = await events.connect("default/channel", { authMode: "userPool" })
26
+ *
27
+ * @param channel - channel path; `<namespace>/<channel>`
28
+ * @param options - request overrides: `authMode`, `authToken`
29
+ *
30
+ */
31
+ async function connect(channel, options) {
32
+ const providerOptions = (0, utils_1.configure)();
33
+ providerOptions.authenticationType = (0, utils_1.normalizeAuth)(options?.authMode, providerOptions.authenticationType);
34
+ await AWSAppSyncEventsProvider_1.AppSyncEventProvider.connect(providerOptions);
35
+ let _subscription;
36
+ const sub = (observer, subOptions) => {
37
+ const subscribeOptions = { ...providerOptions, query: channel };
38
+ subscribeOptions.authenticationType = (0, utils_1.normalizeAuth)(subOptions?.authMode, subscribeOptions.authenticationType);
39
+ _subscription = AWSAppSyncEventsProvider_1.AppSyncEventProvider
40
+ .subscribe(subscribeOptions)
41
+ .subscribe(observer);
42
+ return _subscription;
43
+ };
44
+ const close = () => {
45
+ _subscription && _subscription.unsubscribe();
46
+ };
47
+ return {
48
+ subscribe: sub,
49
+ close,
50
+ // publish: pub,
51
+ };
52
+ }
53
+ exports.connect = connect;
54
+ /**
55
+ * @experimental API may change in future versions
56
+ *
57
+ * Publish events to a channel via HTTP request
58
+ *
59
+ * @example
60
+ * await events.post("default/channel", { some: "event" })
61
+ *
62
+ * @example // event batching
63
+ * await events.post("default/channel", [{ some: "event" }, { some: "event2" }])
64
+ *
65
+ * @example // authMode override
66
+ * await events.post("default/channel", { some: "event" }, { authMode: "userPool" })
67
+ *
68
+ * @param channel - channel path; `<namespace>/<channel>`
69
+ * @param event - JSON-serializable value or an array of values
70
+ * @param options - request overrides: `authMode`, `authToken`
71
+ *
72
+ * @returns void on success
73
+ * @throws on error
74
+ */
75
+ async function post(channel, event, options) {
76
+ const providerOptions = (0, utils_1.configure)();
77
+ providerOptions.authenticationType = (0, utils_1.normalizeAuth)(options?.authMode, providerOptions.authenticationType);
78
+ // trailing slash required in publish
79
+ const normalizedChannelName = channel[0] === '/' ? channel : `/${channel}`;
80
+ const publishOptions = {
81
+ ...providerOptions,
82
+ query: normalizedChannelName,
83
+ variables: (0, utils_1.serializeEvents)(event),
84
+ authToken: options?.authToken,
85
+ };
86
+ const abortController = new AbortController();
87
+ const res = await (0, appsyncRequest_1.appsyncRequest)(core_1.Amplify, publishOptions, {}, abortController);
88
+ if (res.failed?.length > 0) {
89
+ return res.failed;
90
+ }
91
+ }
92
+ exports.post = post;
93
+ function closeAll() {
94
+ AWSAppSyncEventsProvider_1.AppSyncEventProvider.close();
95
+ }
96
+ exports.closeAll = closeAll;
97
+ //# 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 * @experimental API may change in future versions\n *\n * Establish a WebSocket connection to an Events channel\n *\n * @example\n * const channel = await events.connect(\"default/channel\")\n *\n * channel.subscribe({\n * next: (data) => { console.log(data) },\n * error: (err) => { console.error(err) },\n * })\n *\n * @example // authMode override\n * const channel = await events.connect(\"default/channel\", { authMode: \"userPool\" })\n *\n * @param channel - channel path; `<namespace>/<channel>`\n * @param options - request overrides: `authMode`, `authToken`\n *\n */\nasync function connect(channel, 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: channel };\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: channel,\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 subscribe: sub,\n close,\n // publish: pub,\n };\n}\nexports.connect = connect;\n/**\n * @experimental API may change in future versions\n *\n * Publish events to a channel via HTTP request\n *\n * @example\n * await events.post(\"default/channel\", { some: \"event\" })\n *\n * @example // event batching\n * await events.post(\"default/channel\", [{ some: \"event\" }, { some: \"event2\" }])\n *\n * @example // authMode override\n * await events.post(\"default/channel\", { some: \"event\" }, { authMode: \"userPool\" })\n *\n * @param channel - channel path; `<namespace>/<channel>`\n * @param event - JSON-serializable value or an array of values\n * @param options - request overrides: `authMode`, `authToken`\n *\n * @returns void on success\n * @throws on error\n */\nasync function post(channel, 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 = channel[0] === '/' ? channel : `/${channel}`;\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,CAAC,CAAC;AAC9D,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC;AAC3D,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,0BAA0B,GAAG,OAAO,CAAC,0CAA0C,CAAC,CAAC;AACvF,MAAM,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AACrD,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE;AACzC,IAAI,MAAM,eAA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,eAAe,CAAC,kBAAkB,GAAG,IAAI,OAAO,CAAC,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC,kBAAkB,CAAC,CAAC;AAC3H;AACA,IAAI,MAAM,qBAAqB,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,GAAG,GAAG,OAAO,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;AAC/E,IAAI,MAAM,cAAc,GAAG;AAC3B,QAAQ,GAAG,eAAe;AAC1B,QAAQ,KAAK,EAAE,qBAAqB;AACpC,QAAQ,SAAS,EAAE,IAAI,OAAO,CAAC,eAAe,EAAE,KAAK,CAAC;AACtD,QAAQ,SAAS,EAAE,OAAO,EAAE,SAAS;AACrC,KAAK,CAAC;AACN,IAAI,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;AAClD,IAAI,MAAM,GAAG,GAAG,MAAM,IAAI,gBAAgB,CAAC,cAAc,EAAE,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,eAAe,CAAC,CAAC;AAChH,IAAI,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE;AAChC,QAAQ,OAAO,GAAG,CAAC,MAAM,CAAC;AAC1B,KAAK;AACL,CAAC;AACD,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;AACpB,SAAS,QAAQ,GAAG;AACpB,IAAI,0BAA0B,CAAC,oBAAoB,CAAC,KAAK,EAAE,CAAC;AAC5D,CAAC;AACD,OAAO,CAAC,QAAQ,GAAG,QAAQ;;"}
@@ -0,0 +1,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];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AI,OAAO,OAAO,CAAC;AACnB,CAAC,CAAC;AACF,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;AAC9B;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,eAAe,GAAG,CAAC,MAAM,KAAK;AACpC,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;AAC/B,QAAQ,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,KAAK;AACvC,YAAY,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;AACjD,YAAY,IAAI,SAAS,KAAK,SAAS,EAAE;AACzC,gBAAgB,MAAM,IAAI,KAAK,CAAC,CAAC,2CAA2C,EAAE,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;AACpG,aAAa;AACb,YAAY,OAAO,SAAS,CAAC;AAC7B,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AAC7C,IAAI,IAAI,SAAS,KAAK,SAAS,EAAE;AACjC,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,2CAA2C,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AAChF,KAAK;AACL,IAAI,OAAO,CAAC,SAAS,CAAC,CAAC;AACvB,CAAC,CAAC;AACF,OAAO,CAAC,eAAe,GAAG,eAAe;;"}
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.headerBasedAuth = void 0;
7
+ const errors_1 = require("../utils/errors");
8
+ const constants_1 = require("../utils/errors/constants");
9
+ async function headerBasedAuth(amplify, authMode, apiKey, additionalHeaders = {}) {
10
+ let headers = {};
11
+ switch (authMode) {
12
+ case 'apiKey':
13
+ if (!apiKey) {
14
+ throw new errors_1.GraphQLApiError(constants_1.NO_API_KEY);
15
+ }
16
+ headers = {
17
+ 'X-Api-Key': apiKey,
18
+ };
19
+ break;
20
+ case 'iam': {
21
+ const session = await amplify.Auth.fetchAuthSession();
22
+ if (session.credentials === undefined) {
23
+ throw new errors_1.GraphQLApiError(constants_1.NO_VALID_CREDENTIALS);
24
+ }
25
+ break;
26
+ }
27
+ case 'oidc':
28
+ case 'userPool': {
29
+ let token;
30
+ try {
31
+ token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();
32
+ }
33
+ catch (e) {
34
+ // fetchAuthSession failed
35
+ throw new errors_1.GraphQLApiError({
36
+ ...constants_1.NO_SIGNED_IN_USER,
37
+ underlyingError: e,
38
+ });
39
+ }
40
+ // `fetchAuthSession()` succeeded but didn't return `tokens`.
41
+ // This may happen when unauthenticated access is enabled and there is
42
+ // no user signed in.
43
+ if (!token) {
44
+ throw new errors_1.GraphQLApiError(constants_1.NO_VALID_AUTH_TOKEN);
45
+ }
46
+ headers = {
47
+ Authorization: token,
48
+ };
49
+ break;
50
+ }
51
+ case 'lambda':
52
+ if (typeof additionalHeaders === 'object' &&
53
+ !additionalHeaders.Authorization) {
54
+ throw new errors_1.GraphQLApiError(constants_1.NO_AUTH_TOKEN_HEADER);
55
+ }
56
+ headers = {
57
+ Authorization: additionalHeaders.Authorization,
58
+ };
59
+ break;
60
+ }
61
+ return headers;
62
+ }
63
+ exports.headerBasedAuth = headerBasedAuth;
64
+ //# sourceMappingURL=graphqlAuth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphqlAuth.js","sources":["../../../src/internals/graphqlAuth.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.headerBasedAuth = void 0;\nconst errors_1 = require(\"../utils/errors\");\nconst constants_1 = require(\"../utils/errors/constants\");\nasync function headerBasedAuth(amplify, authMode, apiKey, additionalHeaders = {}) {\n let headers = {};\n switch (authMode) {\n case 'apiKey':\n if (!apiKey) {\n throw new errors_1.GraphQLApiError(constants_1.NO_API_KEY);\n }\n headers = {\n 'X-Api-Key': apiKey,\n };\n break;\n case 'iam': {\n const session = await amplify.Auth.fetchAuthSession();\n if (session.credentials === undefined) {\n throw new errors_1.GraphQLApiError(constants_1.NO_VALID_CREDENTIALS);\n }\n break;\n }\n case 'oidc':\n case 'userPool': {\n let token;\n try {\n token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();\n }\n catch (e) {\n // fetchAuthSession failed\n throw new errors_1.GraphQLApiError({\n ...constants_1.NO_SIGNED_IN_USER,\n underlyingError: e,\n });\n }\n // `fetchAuthSession()` succeeded but didn't return `tokens`.\n // This may happen when unauthenticated access is enabled and there is\n // no user signed in.\n if (!token) {\n throw new errors_1.GraphQLApiError(constants_1.NO_VALID_AUTH_TOKEN);\n }\n headers = {\n Authorization: token,\n };\n break;\n }\n case 'lambda':\n if (typeof additionalHeaders === 'object' &&\n !additionalHeaders.Authorization) {\n throw new errors_1.GraphQLApiError(constants_1.NO_AUTH_TOKEN_HEADER);\n }\n headers = {\n Authorization: additionalHeaders.Authorization,\n };\n break;\n case 'none':\n break;\n default:\n break;\n }\n return headers;\n}\nexports.headerBasedAuth = headerBasedAuth;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC;AACjC,MAAM,QAAQ,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAC5C,MAAM,WAAW,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AACzD,eAAe,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,GAAG,EAAE,EAAE;AAClF,IAA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,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,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;AACL;AACA;AACA;AACA,IAAI,MAAM,CAAC,KAAK,EAAE;AAClB,QAAQ,IAAI,KAAK,KAAK,cAAc,CAAC,eAAe,EAAE;AACtD;AACA,YAAY,IAAI,IAAI,CAAC,qBAAqB,KAAK,SAAS;AACxD,gBAAgB,IAAI,CAAC,mBAAmB,KAAK,SAAS,EAAE;AACxD,gBAAgB,IAAI,CAAC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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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jE,wBAAwB,IAAI,CAAC,iBAAiB,EAAE,CAAC;AACjD,qBAAqB,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAAC;AACvD,iBAAiB,EAAE,WAAW,CAAC,eAAe,CAAC,CAAC;AAChD,aAAa;AACb,SAAS;AACT,QAAQ,IAAI,KAAK,KAAK,cAAc,CAAC,cAAc,EAAE;AACrD,YAAY,IAAI,IAAI,CAAC,mBAAmB,EAAE;AAC1C,gBAAgB,aAAa,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;AACxD,gBAAgB,IAAI,CAAC,mBAAmB,GAAG,SAAS,CAAC;AACrD,aAAa;AACb,YAAY,IAAI,IAAI,CAAC,qBAAqB,EAAE;AAC5C,gBAAgB,YAAY,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;AACzD,gBAAgB,IAAI,CAAC,qBAAqB,GAAG,SAAS,CAAC;AACvD,aAAa;AACb,SAAS;AACT,KAAK;AACL;AACA;AACA;AACA,IAAI,KAAK,GAAG;AACZ,QAAQ,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,iBAAiB,IAAI;AAC7D,YAAY,iBAAiB,CAAC,QAAQ,IAAI,CAAC;AAC3C,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,iBAAiB,GAAG;AACxB,QAAQ,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,iBAAiB,IAAI;AAC7D,YAAY,iBAAiB,CAAC,IAAI,IAAI,CAAC;AACvC,SAAS,CAAC,CAAC;AACX,KAAK;AACL,CAAC;AACD,OAAO,CAAC,mBAAmB,GAAG,mBAAmB;;"}
@@ -0,0 +1,43 @@
1
+ import { CustomUserAgentDetails, DocumentType, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
2
+ import { CustomHeaders } from '@aws-amplify/data-schema/runtime';
3
+ import { AWSWebSocketProvider } from '../AWSWebSocketProvider';
4
+ type ResolvedGraphQLAuthModes = Exclude<GraphQLAuthMode, 'identityPool'>;
5
+ interface AWSAppSyncEventProviderOptions {
6
+ appSyncGraphqlEndpoint?: string;
7
+ authenticationType?: ResolvedGraphQLAuthModes;
8
+ query?: string;
9
+ variables?: DocumentType;
10
+ apiKey?: string;
11
+ region?: string;
12
+ libraryConfigHeaders?(): Promise<Record<string, unknown> | Headers>;
13
+ additionalHeaders?: CustomHeaders;
14
+ additionalCustomHeaders?: Record<string, string>;
15
+ authToken?: string;
16
+ }
17
+ interface DataResponse {
18
+ id: string;
19
+ payload: string;
20
+ type: string;
21
+ }
22
+ declare class AWSAppSyncEventProvider extends AWSWebSocketProvider {
23
+ constructor();
24
+ getProviderName(): string;
25
+ connect(options: AWSAppSyncEventProviderOptions): Promise<void>;
26
+ subscribe(options?: AWSAppSyncEventProviderOptions, customUserAgentDetails?: CustomUserAgentDetails): import("rxjs").Observable<Record<string, unknown>>;
27
+ publish(options: AWSAppSyncEventProviderOptions, customUserAgentDetails?: CustomUserAgentDetails): Promise<void>;
28
+ protected _prepareSubscriptionPayload({ options, subscriptionId, customUserAgentDetails, additionalCustomHeaders, libraryConfigHeaders, publish, }: {
29
+ options: AWSAppSyncEventProviderOptions;
30
+ subscriptionId: string;
31
+ customUserAgentDetails: CustomUserAgentDetails | undefined;
32
+ additionalCustomHeaders: Record<string, string>;
33
+ libraryConfigHeaders: Record<string, string>;
34
+ publish?: boolean;
35
+ }): Promise<string>;
36
+ protected _handleSubscriptionData(message: MessageEvent): [boolean, DataResponse];
37
+ protected _unsubscribeMessage(subscriptionId: string): {
38
+ id: string;
39
+ type: string;
40
+ };
41
+ }
42
+ export declare const AppSyncEventProvider: AWSAppSyncEventProvider;
43
+ export {};
@@ -0,0 +1,97 @@
1
+ import { USER_AGENT_HEADER, getAmplifyUserAgent } from '@aws-amplify/core/internals/utils';
2
+ import { MESSAGE_TYPES } from '../constants.mjs';
3
+ import { AWSWebSocketProvider } from '../AWSWebSocketProvider/index.mjs';
4
+ import { awsRealTimeHeaderBasedAuth } from '../AWSWebSocketProvider/authHeaders.mjs';
5
+
6
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
7
+ // SPDX-License-Identifier: Apache-2.0
8
+ const PROVIDER_NAME = 'AWSAppSyncEventsProvider';
9
+ const WS_PROTOCOL_NAME = 'aws-appsync-event-ws';
10
+ class AWSAppSyncEventProvider extends AWSWebSocketProvider {
11
+ constructor() {
12
+ super({ providerName: PROVIDER_NAME, wsProtocolName: WS_PROTOCOL_NAME });
13
+ }
14
+ getProviderName() {
15
+ return PROVIDER_NAME;
16
+ }
17
+ async connect(options) {
18
+ super.connect(options);
19
+ }
20
+ subscribe(options, customUserAgentDetails) {
21
+ return super.subscribe(options, customUserAgentDetails).pipe();
22
+ }
23
+ async publish(options, customUserAgentDetails) {
24
+ super.publish(options, customUserAgentDetails);
25
+ }
26
+ async _prepareSubscriptionPayload({ options, subscriptionId, customUserAgentDetails, additionalCustomHeaders, libraryConfigHeaders, publish, }) {
27
+ const { appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, } = options;
28
+ // This will be needed for WS publish
29
+ // const data = {
30
+ // events: [variables],
31
+ // };
32
+ const serializedData = JSON.stringify([variables]);
33
+ const headers = {
34
+ ...(await awsRealTimeHeaderBasedAuth({
35
+ apiKey,
36
+ appSyncGraphqlEndpoint,
37
+ authenticationType,
38
+ payload: serializedData,
39
+ canonicalUri: '',
40
+ region,
41
+ additionalCustomHeaders,
42
+ })),
43
+ ...libraryConfigHeaders,
44
+ ...additionalCustomHeaders,
45
+ [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),
46
+ };
47
+ // Commented out code will be needed for WS publish
48
+ const subscriptionMessage = {
49
+ id: subscriptionId,
50
+ channel: query,
51
+ // events: [JSON.stringify(variables)],
52
+ authorization: {
53
+ ...headers,
54
+ },
55
+ // payload: {
56
+ // events: serializedData,
57
+ // extensions: {
58
+ // authorization: {
59
+ // ...headers,
60
+ // },
61
+ // },
62
+ // },
63
+ type: publish
64
+ ? MESSAGE_TYPES.EVENT_PUBLISH
65
+ : MESSAGE_TYPES.EVENT_SUBSCRIBE,
66
+ };
67
+ const serializedSubscriptionMessage = JSON.stringify(subscriptionMessage);
68
+ return serializedSubscriptionMessage;
69
+ }
70
+ _handleSubscriptionData(message) {
71
+ this.logger.debug(`subscription message from AWS AppSync Events: ${message.data}`);
72
+ const { id = '', event: payload, type, } = JSON.parse(String(message.data));
73
+ const { observer = null, query = '', variables = {}, } = this.subscriptionObserverMap.get(id) || {};
74
+ this.logger.debug({ id, observer, query, variables });
75
+ if (type === MESSAGE_TYPES.DATA && payload) {
76
+ const deserializedEvent = JSON.parse(payload);
77
+ if (observer) {
78
+ observer.next(deserializedEvent);
79
+ }
80
+ else {
81
+ this.logger.debug(`observer not found for id: ${id}`);
82
+ }
83
+ return [true, { id, type, payload: deserializedEvent }];
84
+ }
85
+ return [false, { id, type, payload }];
86
+ }
87
+ _unsubscribeMessage(subscriptionId) {
88
+ return {
89
+ id: subscriptionId,
90
+ type: MESSAGE_TYPES.EVENT_STOP,
91
+ };
92
+ }
93
+ }
94
+ const AppSyncEventProvider = new AWSAppSyncEventProvider();
95
+
96
+ export { AppSyncEventProvider };
97
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/Providers/AWSAppSyncEventsProvider/index.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { USER_AGENT_HEADER, getAmplifyUserAgent, } from '@aws-amplify/core/internals/utils';\nimport { MESSAGE_TYPES } from '../constants';\nimport { AWSWebSocketProvider } from '../AWSWebSocketProvider';\nimport { awsRealTimeHeaderBasedAuth } from '../AWSWebSocketProvider/authHeaders';\nconst PROVIDER_NAME = 'AWSAppSyncEventsProvider';\nconst WS_PROTOCOL_NAME = 'aws-appsync-event-ws';\nclass AWSAppSyncEventProvider extends AWSWebSocketProvider {\n constructor() {\n super({ providerName: PROVIDER_NAME, wsProtocolName: WS_PROTOCOL_NAME });\n }\n getProviderName() {\n return PROVIDER_NAME;\n }\n async connect(options) {\n super.connect(options);\n }\n subscribe(options, customUserAgentDetails) {\n return super.subscribe(options, customUserAgentDetails).pipe();\n }\n async publish(options, customUserAgentDetails) {\n super.publish(options, customUserAgentDetails);\n }\n async _prepareSubscriptionPayload({ options, subscriptionId, customUserAgentDetails, additionalCustomHeaders, libraryConfigHeaders, publish, }) {\n const { appSyncGraphqlEndpoint, authenticationType, query, variables, apiKey, region, } = options;\n // This will be needed for WS publish\n // const data = {\n // \tevents: [variables],\n // };\n const serializedData = JSON.stringify([variables]);\n const headers = {\n ...(await awsRealTimeHeaderBasedAuth({\n apiKey,\n appSyncGraphqlEndpoint,\n authenticationType,\n payload: serializedData,\n canonicalUri: '',\n region,\n additionalCustomHeaders,\n })),\n ...libraryConfigHeaders,\n ...additionalCustomHeaders,\n [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),\n };\n // Commented out code will be needed for WS publish\n const subscriptionMessage = {\n id: subscriptionId,\n channel: query,\n // events: [JSON.stringify(variables)],\n authorization: {\n ...headers,\n },\n // payload: {\n // \tevents: serializedData,\n // \textensions: {\n // \t\tauthorization: {\n // \t\t\t...headers,\n // \t\t},\n // \t},\n // },\n type: publish\n ? MESSAGE_TYPES.EVENT_PUBLISH\n : MESSAGE_TYPES.EVENT_SUBSCRIBE,\n };\n const serializedSubscriptionMessage = JSON.stringify(subscriptionMessage);\n return serializedSubscriptionMessage;\n }\n _handleSubscriptionData(message) {\n this.logger.debug(`subscription message from AWS AppSync Events: ${message.data}`);\n const { id = '', event: payload, type, } = JSON.parse(String(message.data));\n const { observer = null, query = '', variables = {}, } = this.subscriptionObserverMap.get(id) || {};\n this.logger.debug({ id, observer, query, variables });\n if (type === MESSAGE_TYPES.DATA && payload) {\n const deserializedEvent = JSON.parse(payload);\n if (observer) {\n observer.next(deserializedEvent);\n }\n else {\n this.logger.debug(`observer not found for id: ${id}`);\n }\n return [true, { id, type, payload: deserializedEvent }];\n }\n return [false, { id, type, payload }];\n }\n _unsubscribeMessage(subscriptionId) {\n return {\n id: subscriptionId,\n type: MESSAGE_TYPES.EVENT_STOP,\n };\n }\n}\nexport const AppSyncEventProvider = new AWSAppSyncEventProvider();\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAKA,MAAM,aAAa,GAAG,0BAA0B,CAAC;AACjD,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAChD,MAAM,uBAAuB,SAAS,oBAAoB,CAAC;AAC3D,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAC,CAAC;AACjF,KAAK;AACL,IAAI,eAAe,GAAG;AACtB,QAAQ,OAAO,aAAa,CAAC;AAC7B,KAAK;AACL,IAAI,MAAM,OAAO,CAAC,OAAO,EAAE;AAC3B,QAAQ,KAAK,CAAC,OAAO,CAAC,OAAO,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,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,OAAO,GAAG,EAAE;AACpJ,QAAQ,MAAM,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG,OAAO,CAAC;AAC1G;AACA;AACA;AACA;AACA,QAAQ,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAA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,IAAI,EAAE,KAAK,GAAG,EAAE,EAAE,SAAS,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC;AAC5G,QAAQ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AAC9D,QAAQ,IAAI,IAAI,KAAK,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;
46
27
  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;
28
+ subscribe(options?: AWSAppSyncRealTimeProviderOptions, customUserAgentDetails?: CustomUserAgentDetails): import("rxjs").Observable<Record<string, unknown>>;
29
+ protected _prepareSubscriptionPayload({ options, subscriptionId, customUserAgentDetails, additionalCustomHeaders, libraryConfigHeaders, }: {
30
+ options: AWSAppSyncRealTimeProviderOptions;
31
+ subscriptionId: string;
32
+ customUserAgentDetails: CustomUserAgentDetails | undefined;
33
+ additionalCustomHeaders: Record<string, string>;
34
+ libraryConfigHeaders: Record<string, string>;
35
+ }): Promise<string>;
36
+ protected _handleSubscriptionData(message: MessageEvent): [boolean, DataPayload];
37
+ protected _unsubscribeMessage(subscriptionId: string): {
38
+ id: string;
39
+ type: string;
40
+ };
88
41
  }
89
42
  export {};