@aws-amplify/api-graphql 4.4.3 → 4.4.4-events.fade122.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 +113 -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 +107 -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 +152 -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 @@
1
+ {"version":3,"file":"appsyncRequest.mjs","sources":["../../../../src/internals/events/appsyncRequest.ts"],"sourcesContent":["import { AmplifyUrl, getAmplifyUserAgent, } from '@aws-amplify/core/internals/utils';\nimport { post } from '@aws-amplify/api-rest/internals';\nimport { resolveLibraryOptions } from '../../utils';\nimport { repackageUnauthorizedError } from '../../utils/errors/repackageAuthError';\nimport { headerBasedAuth } from '../graphqlAuth';\nimport { isGraphQLResponseWithErrors } from '../utils/runtimeTypeGuards/isGraphQLResponseWithErrors';\nconst USER_AGENT_HEADER = 'x-amz-user-agent';\n// This is effectively a copy of InternalGraphQLAPI.ts._graphql(...)\n// Our existing unit tests are tightly coupled to the implementation, so i was unable to refactor\n// and extend _graphql() without having to change a bunch of tests as well... which in turn reduces confidence\n// that this feature will _not affect_ GQL behavior.\nexport async function appsyncRequest(amplify, options, additionalHeaders = {}, abortController, customUserAgentDetails) {\n const { region, appSyncGraphqlEndpoint: endpoint, authenticationType: authMode, query, variables, } = options;\n if (!endpoint) {\n throw new Error('No endpoint');\n }\n const { withCredentials } = resolveLibraryOptions(amplify);\n const headers = await requestHeaders(amplify, options, additionalHeaders, customUserAgentDetails);\n const body = {\n channel: query,\n events: variables,\n };\n const signingServiceInfo = ['apiKey', 'none'].includes(authMode)\n ? undefined\n : {\n service: 'appsync',\n region,\n };\n const { body: responseBody } = await post(amplify, {\n url: new AmplifyUrl(endpoint),\n options: {\n headers,\n body,\n signingServiceInfo,\n withCredentials,\n },\n abortController,\n });\n const response = await responseBody.json();\n if (isGraphQLResponseWithErrors(response)) {\n throw repackageUnauthorizedError(response);\n }\n return response;\n}\n/**\n * Computes all the necessary HTTP headers for the request based on:\n * 1. Operation-level header options\n * 2. Amplify.configure custom headers\n * 3. AuthZ headers for explicit auth mode specified for operation ?? default auth mode in config\n *\n * @returns HTTP request headers key/value\n */\nasync function requestHeaders(amplify, options, additionalHeaders, customUserAgentDetails) {\n const { apiKey, appSyncGraphqlEndpoint: endpoint, authenticationType: authMode, query, variables, authToken, } = options;\n const { headers: customHeadersFn } = resolveLibraryOptions(amplify);\n let additionalCustomHeaders;\n if (typeof additionalHeaders === 'function') {\n const requestOptions = {\n method: 'POST',\n url: new AmplifyUrl(endpoint).toString(),\n queryString: query,\n };\n additionalCustomHeaders = await additionalHeaders(requestOptions);\n }\n else {\n additionalCustomHeaders = additionalHeaders;\n }\n // if an authorization header is set, have the operation-level authToken take precedence\n if (authToken) {\n additionalCustomHeaders = {\n ...additionalCustomHeaders,\n Authorization: authToken,\n };\n }\n const authHeaders = await headerBasedAuth(amplify, authMode, apiKey, additionalCustomHeaders);\n const customHeaders = customHeadersFn &&\n (await customHeadersFn({\n query,\n variables: variables,\n }));\n const headers = {\n ...authHeaders,\n // Custom headers included in Amplify configuration options:\n ...customHeaders,\n // Custom headers from individual requests or API client configuration:\n ...additionalCustomHeaders,\n // User agent headers:\n [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),\n };\n return headers;\n}\n"],"names":[],"mappings":";;;;;;;;AAMA,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AAC7C;AACA;AACA;AACA;AACO,eAAe,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,iBAAiB,GAAG,EAAE,EAAE,eAAe,EAAE,sBAAsB,EAAE;AACxH,IAAI,MAAM,EAAE,MAAM,EAAE,sBAAsB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,GAAG,GAAG,OAAO,CAAC;AAClH,IAAI,IAAI,CAAC,QAAQ,EAAE;AACnB,QAAQ,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;AACvC,KAAK;AACL,IAAI,MAAM,EAAE,eAAe,EAAE,GAAG,qBAAqB,CAAC,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EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;AACxE,IAAI,IAAI,uBAAuB,CAAC;AAChC,IAAI,IAAI,OAAO,iBAAiB,KAAK,UAAU,EAAE;AACjD,QAAQ,MAAM,cAAc,GAAG;AAC/B,YAAY,MAAM,EAAE,MAAM;AAC1B,YAAY,GAAG,EAAE,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC,QAAQ,EAAE;AACpD,YAAY,WAAW,EAAE,KAAK;AAC9B,SAAS,CAAC;AACV,QAAQ,uBAAuB,GAAG,MAAM,iBAAiB,CAAC,cAAc,CAAC,CAAC;AAC1E,KAAK;AACL,SAAS;AACT,QAAQ,uBAAuB,GAAG,iBAAiB,CAAC;AACpD,KAAK;AACL;AACA,IAAI,IAAI,SAAS,EAAE;AACnB,QAAQ,uBAAuB,GAAG;AAClC,YAAY,GAAG,uBAAuB;AACtC,YAAY,aAAa,EAAE,SAAS;AACpC,SAAS,CAAC;AACV,KAAK;AACL,IAAI,MAAM,WAAW,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,uBAAuB,CAAC,CAAC;AAClG,IAAI,MAAM,aAAa,GAAG,eAAe;AACzC,SAAS,MAAM,eAAe,CAAC;AAC/B,YAAY,KAAK;AACjB,YAAY,SAAS,EAAE,SAAS;AAChC,SAAS,CAAC,CAAC,CAAC;AACZ,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,GAAG,WAAW;AACtB;AACA,QAAQ,GAAG,aAAa;AACxB;AACA,QAAQ,GAAG,uBAAuB;AAClC;AACA,QAAQ,CAAC,iBAAiB,GAAG,mBAAmB,CAAC,sBAAsB,CAAC;AACxE,KAAK,CAAC;AACN,IAAI,OAAO,OAAO,CAAC;AACnB;;;;"}
@@ -0,0 +1,47 @@
1
+ import { DocumentType } from '@aws-amplify/core/internals/utils';
2
+ import type { EventsChannel, EventsOptions, PublishedEvent } from './types';
3
+ /**
4
+ * @experimental API may change in future versions
5
+ *
6
+ * Establish a WebSocket connection to an Events channel
7
+ *
8
+ * @example
9
+ * const channel = await events.connect("default/channel")
10
+ *
11
+ * channel.subscribe({
12
+ * next: (data) => { console.log(data) },
13
+ * error: (err) => { console.error(err) },
14
+ * })
15
+ *
16
+ * @example // authMode override
17
+ * const channel = await events.connect("default/channel", { authMode: "userPool" })
18
+ *
19
+ * @param channel - channel path; `<namespace>/<channel>`
20
+ * @param options - request overrides: `authMode`, `authToken`
21
+ *
22
+ */
23
+ declare function connect(channel: string, options?: EventsOptions): Promise<EventsChannel>;
24
+ /**
25
+ * @experimental API may change in future versions
26
+ *
27
+ * Publish events to a channel via HTTP request
28
+ *
29
+ * @example
30
+ * await events.post("default/channel", { some: "event" })
31
+ *
32
+ * @example // event batching
33
+ * await events.post("default/channel", [{ some: "event" }, { some: "event2" }])
34
+ *
35
+ * @example // authMode override
36
+ * await events.post("default/channel", { some: "event" }, { authMode: "userPool" })
37
+ *
38
+ * @param channel - channel path; `<namespace>/<channel>`
39
+ * @param event - JSON-serializable value or an array of values
40
+ * @param options - request overrides: `authMode`, `authToken`
41
+ *
42
+ * @returns void on success
43
+ * @throws on error
44
+ */
45
+ declare function post(channel: string, event: DocumentType | DocumentType[], options?: EventsOptions): Promise<void | PublishedEvent[]>;
46
+ declare function closeAll(): void;
47
+ export { connect, post, closeAll };
@@ -0,0 +1,93 @@
1
+ import { Amplify } from '@aws-amplify/core';
2
+ import { AppSyncEventProvider } from '../../Providers/AWSAppSyncEventsProvider/index.mjs';
3
+ import { appsyncRequest } from './appsyncRequest.mjs';
4
+ import { configure, normalizeAuth, serializeEvents } from './utils.mjs';
5
+
6
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
7
+ // SPDX-License-Identifier: Apache-2.0
8
+ /**
9
+ * @experimental API may change in future versions
10
+ *
11
+ * Establish a WebSocket connection to an Events channel
12
+ *
13
+ * @example
14
+ * const channel = await events.connect("default/channel")
15
+ *
16
+ * channel.subscribe({
17
+ * next: (data) => { console.log(data) },
18
+ * error: (err) => { console.error(err) },
19
+ * })
20
+ *
21
+ * @example // authMode override
22
+ * const channel = await events.connect("default/channel", { authMode: "userPool" })
23
+ *
24
+ * @param channel - channel path; `<namespace>/<channel>`
25
+ * @param options - request overrides: `authMode`, `authToken`
26
+ *
27
+ */
28
+ async function connect(channel, options) {
29
+ const providerOptions = configure();
30
+ providerOptions.authenticationType = normalizeAuth(options?.authMode, providerOptions.authenticationType);
31
+ await AppSyncEventProvider.connect(providerOptions);
32
+ let _subscription;
33
+ const sub = (observer, subOptions) => {
34
+ const subscribeOptions = { ...providerOptions, query: channel };
35
+ subscribeOptions.authenticationType = normalizeAuth(subOptions?.authMode, subscribeOptions.authenticationType);
36
+ _subscription = AppSyncEventProvider
37
+ .subscribe(subscribeOptions)
38
+ .subscribe(observer);
39
+ return _subscription;
40
+ };
41
+ const close = () => {
42
+ _subscription && _subscription.unsubscribe();
43
+ };
44
+ return {
45
+ subscribe: sub,
46
+ close,
47
+ // publish: pub,
48
+ };
49
+ }
50
+ /**
51
+ * @experimental API may change in future versions
52
+ *
53
+ * Publish events to a channel via HTTP request
54
+ *
55
+ * @example
56
+ * await events.post("default/channel", { some: "event" })
57
+ *
58
+ * @example // event batching
59
+ * await events.post("default/channel", [{ some: "event" }, { some: "event2" }])
60
+ *
61
+ * @example // authMode override
62
+ * await events.post("default/channel", { some: "event" }, { authMode: "userPool" })
63
+ *
64
+ * @param channel - channel path; `<namespace>/<channel>`
65
+ * @param event - JSON-serializable value or an array of values
66
+ * @param options - request overrides: `authMode`, `authToken`
67
+ *
68
+ * @returns void on success
69
+ * @throws on error
70
+ */
71
+ async function post(channel, event, options) {
72
+ const providerOptions = configure();
73
+ providerOptions.authenticationType = normalizeAuth(options?.authMode, providerOptions.authenticationType);
74
+ // trailing slash required in publish
75
+ const normalizedChannelName = channel[0] === '/' ? channel : `/${channel}`;
76
+ const publishOptions = {
77
+ ...providerOptions,
78
+ query: normalizedChannelName,
79
+ variables: serializeEvents(event),
80
+ authToken: options?.authToken,
81
+ };
82
+ const abortController = new AbortController();
83
+ const res = await appsyncRequest(Amplify, publishOptions, {}, abortController);
84
+ if (res.failed?.length > 0) {
85
+ return res.failed;
86
+ }
87
+ }
88
+ function closeAll() {
89
+ AppSyncEventProvider.close();
90
+ }
91
+
92
+ export { closeAll, connect, post };
93
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/internals/events/index.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify } from '@aws-amplify/core';\nimport { AppSyncEventProvider as eventProvider } from '../../Providers/AWSAppSyncEventsProvider';\nimport { appsyncRequest } from './appsyncRequest';\nimport { configure, normalizeAuth, serializeEvents } from './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 = configure();\n providerOptions.authenticationType = normalizeAuth(options?.authMode, providerOptions.authenticationType);\n await eventProvider.connect(providerOptions);\n let _subscription;\n const sub = (observer, subOptions) => {\n const subscribeOptions = { ...providerOptions, query: channel };\n subscribeOptions.authenticationType = normalizeAuth(subOptions?.authMode, subscribeOptions.authenticationType);\n _subscription = eventProvider\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 = normalizeAuth(pubOptions?.authMode, publishOptions.authenticationType);\n return eventProvider.publish(publishOptions);\n };\n const close = () => {\n _subscription && _subscription.unsubscribe();\n };\n return {\n subscribe: sub,\n close,\n // publish: pub,\n };\n}\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 = configure();\n providerOptions.authenticationType = 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: serializeEvents(event),\n authToken: options?.authToken,\n };\n const abortController = new AbortController();\n const res = await appsyncRequest(Amplify, publishOptions, {}, abortController);\n if (res.failed?.length > 0) {\n return res.failed;\n }\n}\nfunction closeAll() {\n eventProvider.close();\n}\nexport { connect, post, closeAll };\n"],"names":["eventProvider"],"mappings":";;;;;AAAA;AACA;AAKA;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,eAAe,GAAG,SAAS,EAAE,CAAC;AACxC,IAAI,eAAe,CAAC,kBAAkB,GAAG,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,eAAe,CAAC,kBAAkB,CAAC,CAAC;AAC9G,IAAI,MAAMA,oBAAa,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;AACjD,IAAI,IAAI,aAAa,CAAC;AACtB,I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QAAQ,SAAS,EAAE,OAAO,EAAE,SAAS;AACrC,KAAK,CAAC;AACN,IAAI,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;AAClD,IAAI,MAAM,GAAG,GAAG,MAAM,cAAc,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,EAAE,eAAe,CAAC,CAAC;AACnF,IAAI,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,EAAE;AAChC,QAAQ,OAAO,GAAG,CAAC,MAAM,CAAC;AAC1B,KAAK;AACL,CAAC;AACD,SAAS,QAAQ,GAAG;AACpB,IAAIA,oBAAa,CAAC,KAAK,EAAE,CAAC;AAC1B;;;;"}
@@ -0,0 +1,59 @@
1
+ import { Subscription } from 'rxjs';
2
+ import type { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
3
+ export interface SubscriptionObserver<T> {
4
+ next(value: T): void;
5
+ error(errorValue: any): void;
6
+ }
7
+ export interface EventsChannel {
8
+ /**
9
+ * @experimental API may change in future versions
10
+ *
11
+ * Subscribe to Events
12
+ *
13
+ * @example
14
+ * const channel = await events.connect("default/channel")
15
+ *
16
+ * channel.subscribe({
17
+ * next: (data) => { console.log(data) },
18
+ * error: (err) => { console.error(err) },
19
+ * })
20
+ *
21
+ * @example // authMode override
22
+ * channel.subscribe({
23
+ * next: (data) => { console.log(data) },
24
+ * error: (err) => { console.error(err) },
25
+ * }, { authMode: 'userPool' })
26
+ *
27
+ * @param observer - observer callback handlers
28
+ * `{ next: () => {}, error: () => {}}`
29
+ *
30
+ * @param options - subscribe overrides: `authMode`, `authToken`
31
+ *
32
+ */
33
+ subscribe(observer: SubscriptionObserver<any>, subOptions?: EventsOptions): Subscription;
34
+ /**
35
+ * @experimental API may change in future versions
36
+ *
37
+ * Close channel and any active subscriptions
38
+ *
39
+ * @example
40
+ * const channel = await events.connect("default/channel")
41
+ *
42
+ * channel.close()
43
+ *
44
+ */
45
+ close(): void;
46
+ }
47
+ export type ResolvedGraphQLAuthModes = Exclude<GraphQLAuthMode, 'identityPool'>;
48
+ export interface EventsOptions {
49
+ authMode?: GraphQLAuthMode;
50
+ authToken?: string;
51
+ }
52
+ export interface PublishedEvent {
53
+ identifier: string;
54
+ index: number;
55
+ }
56
+ export interface PublishResponse {
57
+ failed: PublishedEvent[];
58
+ successful: PublishedEvent[];
59
+ }
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ import { DocumentType, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
2
+ import type { ResolvedGraphQLAuthModes } from './types';
3
+ export declare const normalizeAuth: (explicitAuthMode: GraphQLAuthMode | undefined, defaultAuthMode: ResolvedGraphQLAuthModes) => ResolvedGraphQLAuthModes;
4
+ export declare const configure: () => {
5
+ appSyncGraphqlEndpoint: string;
6
+ region: string | undefined;
7
+ authenticationType: ResolvedGraphQLAuthModes;
8
+ apiKey: string | undefined;
9
+ };
10
+ /**
11
+ * Event API expects and array of JSON strings
12
+ *
13
+ * @param events - JSON-serializable value or an array of values
14
+ * @returns array of JSON strings
15
+ */
16
+ export declare const serializeEvents: (events: DocumentType | DocumentType[]) => string[];
@@ -0,0 +1,53 @@
1
+ import { Amplify } from '@aws-amplify/core';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ const normalizeAuth = (explicitAuthMode, defaultAuthMode) => {
6
+ if (!explicitAuthMode) {
7
+ return defaultAuthMode;
8
+ }
9
+ if (explicitAuthMode === 'identityPool') {
10
+ return 'iam';
11
+ }
12
+ return explicitAuthMode;
13
+ };
14
+ const configure = () => {
15
+ const config = Amplify.getConfig();
16
+ const eventsConfig = config.API?.Events;
17
+ if (!eventsConfig) {
18
+ throw new Error('Amplify configuration is missing. Have you called Amplify.configure()?');
19
+ }
20
+ const configAuthMode = normalizeAuth(eventsConfig.defaultAuthMode, 'apiKey');
21
+ const options = {
22
+ appSyncGraphqlEndpoint: eventsConfig.endpoint,
23
+ region: eventsConfig.region,
24
+ authenticationType: configAuthMode,
25
+ apiKey: eventsConfig.apiKey,
26
+ };
27
+ return options;
28
+ };
29
+ /**
30
+ * Event API expects and array of JSON strings
31
+ *
32
+ * @param events - JSON-serializable value or an array of values
33
+ * @returns array of JSON strings
34
+ */
35
+ const serializeEvents = (events) => {
36
+ if (Array.isArray(events)) {
37
+ return events.map((ev, idx) => {
38
+ const eventJson = JSON.stringify(ev);
39
+ if (eventJson === undefined) {
40
+ throw new Error(`Event must be a valid JSON value. Received ${ev} at index ${idx}`);
41
+ }
42
+ return eventJson;
43
+ });
44
+ }
45
+ const eventJson = JSON.stringify(events);
46
+ if (eventJson === undefined) {
47
+ throw new Error(`Event must be a valid JSON value. Received ${events}`);
48
+ }
49
+ return [eventJson];
50
+ };
51
+
52
+ export { configure, normalizeAuth, serializeEvents };
53
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sources":["../../../../src/internals/events/utils.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify } from '@aws-amplify/core';\nexport const normalizeAuth = (explicitAuthMode, defaultAuthMode) => {\n if (!explicitAuthMode) {\n return defaultAuthMode;\n }\n if (explicitAuthMode === 'identityPool') {\n return 'iam';\n }\n return explicitAuthMode;\n};\nexport const configure = () => {\n const config = 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 = 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};\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 */\nexport const 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};\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,aAAa,GAAG,CAAC,gBAAgB,EAAE,eAAe,KAAK;AACpE,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,EAAE;AACU,MAAC,SAAS,GAAG,MAAM;AAC/B,IAAI,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;AACvC,IAAI,MAAM,YAAY,GAAG,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC;AAC5C,IAAI,IAAI,CAAC,YAAY,EAAE;AACvB,QAAQ,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;AAClG,KAAK;AACL,IAAI,MAAM,cAAc,GAAG,aAAa,CAAC,YAAY,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;AACjF,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,sBAAsB,EAAE,YAAY,CAAC,QAAQ;AACrD,QAAQ,MAAM,EAAE,YAAY,CAAC,MAAM;AACnC,QAAQ,kBAAkB,EAAE,cAAc;AAC1C,QAAQ,MAAM,EAAE,YAAY,CAAC,MAAM;AACnC,KAAK,CAAC;AACN,IAAI,OAAO,OAAO,CAAC;AACnB,EAAE;AACF;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,eAAe,GAAG,CAAC,MAAM,KAAK;AAC3C,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;;;;"}
@@ -0,0 +1,3 @@
1
+ import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
2
+ import { AmplifyClassV6 } from '@aws-amplify/core';
3
+ export declare function headerBasedAuth(amplify: AmplifyClassV6, authMode: GraphQLAuthMode, apiKey: string | undefined, additionalHeaders?: Record<string, string>): Promise<{}>;
@@ -0,0 +1,64 @@
1
+ import { GraphQLApiError } from '../utils/errors/GraphQLApiError.mjs';
2
+ import '../utils/errors/validation.mjs';
3
+ import 'graphql';
4
+ import { NO_AUTH_TOKEN_HEADER, NO_SIGNED_IN_USER, NO_VALID_AUTH_TOKEN, NO_VALID_CREDENTIALS, NO_API_KEY } from '../utils/errors/constants.mjs';
5
+
6
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
7
+ // SPDX-License-Identifier: Apache-2.0
8
+ async function headerBasedAuth(amplify, authMode, apiKey, additionalHeaders = {}) {
9
+ let headers = {};
10
+ switch (authMode) {
11
+ case 'apiKey':
12
+ if (!apiKey) {
13
+ throw new GraphQLApiError(NO_API_KEY);
14
+ }
15
+ headers = {
16
+ 'X-Api-Key': apiKey,
17
+ };
18
+ break;
19
+ case 'iam': {
20
+ const session = await amplify.Auth.fetchAuthSession();
21
+ if (session.credentials === undefined) {
22
+ throw new GraphQLApiError(NO_VALID_CREDENTIALS);
23
+ }
24
+ break;
25
+ }
26
+ case 'oidc':
27
+ case 'userPool': {
28
+ let token;
29
+ try {
30
+ token = (await amplify.Auth.fetchAuthSession()).tokens?.accessToken.toString();
31
+ }
32
+ catch (e) {
33
+ // fetchAuthSession failed
34
+ throw new GraphQLApiError({
35
+ ...NO_SIGNED_IN_USER,
36
+ underlyingError: e,
37
+ });
38
+ }
39
+ // `fetchAuthSession()` succeeded but didn't return `tokens`.
40
+ // This may happen when unauthenticated access is enabled and there is
41
+ // no user signed in.
42
+ if (!token) {
43
+ throw new GraphQLApiError(NO_VALID_AUTH_TOKEN);
44
+ }
45
+ headers = {
46
+ Authorization: token,
47
+ };
48
+ break;
49
+ }
50
+ case 'lambda':
51
+ if (typeof additionalHeaders === 'object' &&
52
+ !additionalHeaders.Authorization) {
53
+ throw new GraphQLApiError(NO_AUTH_TOKEN_HEADER);
54
+ }
55
+ headers = {
56
+ Authorization: additionalHeaders.Authorization,
57
+ };
58
+ break;
59
+ }
60
+ return headers;
61
+ }
62
+
63
+ export { headerBasedAuth };
64
+ //# sourceMappingURL=graphqlAuth.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphqlAuth.mjs","sources":["../../../src/internals/graphqlAuth.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { GraphQLApiError } from '../utils/errors';\nimport { NO_API_KEY, NO_AUTH_TOKEN_HEADER, NO_SIGNED_IN_USER, NO_VALID_AUTH_TOKEN, NO_VALID_CREDENTIALS, } from '../utils/errors/constants';\nexport async function headerBasedAuth(amplify, authMode, apiKey, additionalHeaders = {}) {\n let headers = {};\n switch (authMode) {\n case 'apiKey':\n if (!apiKey) {\n throw new GraphQLApiError(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 GraphQLApiError(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 GraphQLApiError({\n ...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 GraphQLApiError(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 GraphQLApiError(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}\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAGO,eAAe,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,iBAAiB,GAAG,EAAE,EAAE;AACzF,IAAI,IAAI,OAAO,GAAG,EAAE,CAAC;AACrB,IAAI,QAAQ,QAAQ;AACpB,QAAQ,KAAK,QAAQ;AACrB,YAAY,IAAI,CAAC,MAAM,EAAE;AACzB,gBAAgB,MAAM,IAAI,eAAe,CAAC,UAAU,CAAC,CAAC;AACtD,aAAa;AACb,YAAY,OAAO,GAAG;AACtB,gBAAgB,WAAW,E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AC;AACd,YAAY,MAAM;AAKlB,KAAK;AACL,IAAI,OAAO,OAAO,CAAC;AACnB;;;;"}
@@ -0,0 +1,3 @@
1
+ import { AmplifyClassV6 } from '@aws-amplify/core';
2
+ import { post } from '@aws-amplify/api-rest/internals';
3
+ export declare function graphqlRequest(amplify: AmplifyClassV6, url: string, options: any, abortController: AbortController, _post?: typeof post): Promise<import("@aws-amplify/core/internals/utils").DocumentType>;
@@ -0,0 +1,18 @@
1
+ import { AmplifyUrl } from '@aws-amplify/core/internals/utils';
2
+ import { post } from '@aws-amplify/api-rest/internals';
3
+
4
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
+ // SPDX-License-Identifier: Apache-2.0
6
+ async function graphqlRequest(amplify, url, options, abortController, _post) {
7
+ const p = _post ?? post;
8
+ const { body: responseBody } = await p(amplify, {
9
+ url: new AmplifyUrl(url),
10
+ options,
11
+ abortController,
12
+ });
13
+ const response = await responseBody.json();
14
+ return response;
15
+ }
16
+
17
+ export { graphqlRequest };
18
+ //# sourceMappingURL=graphqlRequest.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphqlRequest.mjs","sources":["../../../src/internals/graphqlRequest.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AmplifyUrl } from '@aws-amplify/core/internals/utils';\nimport { \n// cancel as cancelREST,\npost,\n// updateRequestToBeCancellable,\n } from '@aws-amplify/api-rest/internals';\nexport async function graphqlRequest(amplify, url, options, abortController, _post) {\n const p = _post ?? post;\n const { body: responseBody } = await p(amplify, {\n url: new AmplifyUrl(url),\n options,\n abortController,\n });\n const response = await responseBody.json();\n return response;\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAOO,eAAe,cAAc,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE;AACpF,IAAI,MAAM,CAAC,GAAG,KAAK,IAAI,IAAI,CAAC;AAC5B,IAAI,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC,CAAC,OAAO,EAAE;AACpD,QAAQ,GAAG,EAAE,IAAI,UAAU,CAAC,GAAG,CAAC;AAChC,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;;;;"}
@@ -9,7 +9,35 @@ interface LinkedConnectionStates {
9
9
  keepAliveState: LinkedHealthState;
10
10
  }
11
11
  export declare const CONNECTION_CHANGE: {
12
- [key in 'KEEP_ALIVE_MISSED' | 'KEEP_ALIVE' | 'CONNECTION_ESTABLISHED' | 'CONNECTION_FAILED' | 'CLOSING_CONNECTION' | 'OPENING_CONNECTION' | 'CLOSED' | 'ONLINE' | 'OFFLINE']: Partial<LinkedConnectionStates>;
12
+ readonly KEEP_ALIVE_MISSED: {
13
+ readonly keepAliveState: "unhealthy";
14
+ };
15
+ readonly KEEP_ALIVE: {
16
+ readonly keepAliveState: "healthy";
17
+ };
18
+ readonly CONNECTION_ESTABLISHED: {
19
+ readonly connectionState: "connected";
20
+ };
21
+ readonly CONNECTION_FAILED: {
22
+ readonly intendedConnectionState: "disconnected";
23
+ readonly connectionState: "disconnected";
24
+ };
25
+ readonly CLOSING_CONNECTION: {
26
+ readonly intendedConnectionState: "disconnected";
27
+ };
28
+ readonly OPENING_CONNECTION: {
29
+ readonly intendedConnectionState: "connected";
30
+ readonly connectionState: "connecting";
31
+ };
32
+ readonly CLOSED: {
33
+ readonly connectionState: "disconnected";
34
+ };
35
+ readonly ONLINE: {
36
+ readonly networkState: "connected";
37
+ };
38
+ readonly OFFLINE: {
39
+ readonly networkState: "disconnected";
40
+ };
13
41
  };
14
42
  export declare class ConnectionStateMonitor {
15
43
  /**
@@ -5,7 +5,7 @@ export declare enum ReconnectEvent {
5
5
  }
6
6
  /**
7
7
  * Captures the reconnect event logic used to determine when to reconnect to PubSub providers.
8
- * Reconnnect attempts are delayed by 5 seconds to let the interface settle.
8
+ * Reconnect attempts are delayed by 5 seconds to let the interface settle.
9
9
  * Attempting to reconnect only once creates unrecoverable states when the network state isn't
10
10
  * supported by the browser, so this keeps retrying every minute until halted.
11
11
  */
@@ -7,7 +7,7 @@ var ReconnectEvent;
7
7
  })(ReconnectEvent || (ReconnectEvent = {}));
8
8
  /**
9
9
  * Captures the reconnect event logic used to determine when to reconnect to PubSub providers.
10
- * Reconnnect attempts are delayed by 5 seconds to let the interface settle.
10
+ * Reconnect attempts are delayed by 5 seconds to let the interface settle.
11
11
  * Attempting to reconnect only once creates unrecoverable states when the network state isn't
12
12
  * supported by the browser, so this keeps retrying every minute until halted.
13
13
  */
@@ -1 +1 @@
1
- {"version":3,"file":"ReconnectionMonitor.mjs","sources":["../../../src/utils/ReconnectionMonitor.ts"],"sourcesContent":["import { RECONNECT_DELAY, RECONNECT_INTERVAL } from '../Providers/constants';\nexport var ReconnectEvent;\n(function (ReconnectEvent) {\n ReconnectEvent[\"START_RECONNECT\"] = \"START_RECONNECT\";\n ReconnectEvent[\"HALT_RECONNECT\"] = \"HALT_RECONNECT\";\n})(ReconnectEvent || (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 */\nexport class 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 }, RECONNECT_INTERVAL);\n }, 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}\n"],"names":[],"mappings":";;AACU,IAAC,eAAe;AAC1B,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,KAAK,cAAc,GAAG,EAAE,CAAC,CAAC,CAAC;AAC5C;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,mBAAmB,CAAC;AACjC,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,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_INTERVAL } from '../Providers/constants';\nexport var ReconnectEvent;\n(function (ReconnectEvent) {\n ReconnectEvent[\"START_RECONNECT\"] = \"START_RECONNECT\";\n ReconnectEvent[\"HALT_RECONNECT\"] = \"HALT_RECONNECT\";\n})(ReconnectEvent || (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 */\nexport class 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 }, RECONNECT_INTERVAL);\n }, 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}\n"],"names":[],"mappings":";;AACU,IAAC,eAAe;AAC1B,CAAC,UAAU,cAAc,EAAE;AAC3B,IAAI,cAAc,CAAC,iBAAiB,CAAC,G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;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;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/api-graphql",
3
- "version": "4.4.3",
3
+ "version": "4.4.4-events.fade122.0+fade122",
4
4
  "description": "Api-graphql category of aws-amplify",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -84,8 +84,8 @@
84
84
  "server"
85
85
  ],
86
86
  "dependencies": {
87
- "@aws-amplify/api-rest": "4.0.54",
88
- "@aws-amplify/core": "6.4.7",
87
+ "@aws-amplify/api-rest": "4.0.55-events.fade122.0+fade122",
88
+ "@aws-amplify/core": "6.4.8-events.fade122.0+fade122",
89
89
  "@aws-amplify/data-schema": "^1.7.0",
90
90
  "@aws-sdk/types": "3.387.0",
91
91
  "graphql": "15.8.0",
@@ -101,5 +101,5 @@
101
101
  "limit": "91.7 kB"
102
102
  }
103
103
  ],
104
- "gitHead": "aba109bc3502111346b0beed1b23883d7b142502"
104
+ "gitHead": "fade1228b5c5a376c166144077763b672e6bbf06"
105
105
  }