@aws-amplify/pubsub 4.5.11 → 4.5.12-unstable.2

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 (102) hide show
  1. package/CHANGELOG.md +0 -8
  2. package/lib/.tsbuildinfo +3 -0
  3. package/lib/Providers/AWSAppSyncProvider.d.ts +21 -0
  4. package/lib/Providers/AWSAppSyncProvider.js +20 -102
  5. package/lib/Providers/AWSAppSyncProvider.js.map +1 -1
  6. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +75 -0
  7. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +158 -210
  8. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
  9. package/lib/Providers/AWSIotProvider.d.ts +11 -0
  10. package/lib/Providers/AWSIotProvider.js +6 -64
  11. package/lib/Providers/AWSIotProvider.js.map +1 -1
  12. package/lib/Providers/MqttOverWSProvider.d.ts +41 -0
  13. package/lib/Providers/MqttOverWSProvider.js +158 -204
  14. package/lib/Providers/MqttOverWSProvider.js.map +1 -1
  15. package/lib/Providers/PubSubProvider.d.ts +13 -0
  16. package/lib/Providers/PubSubProvider.js +3 -13
  17. package/lib/Providers/PubSubProvider.js.map +1 -1
  18. package/lib/Providers/constants.d.ts +95 -0
  19. package/lib/Providers/constants.js +8 -0
  20. package/lib/Providers/constants.js.map +1 -1
  21. package/lib/Providers/index.d.ts +5 -0
  22. package/lib/Providers/index.js +13 -20
  23. package/lib/Providers/index.js.map +1 -1
  24. package/lib/PubSub.d.ts +51 -0
  25. package/lib/PubSub.js +8 -56
  26. package/lib/PubSub.js.map +1 -1
  27. package/lib/index.d.ts +4 -0
  28. package/lib/index.js +9 -20
  29. package/lib/index.js.map +1 -1
  30. package/lib/types/Provider.d.ts +14 -0
  31. package/lib/types/PubSub.d.ts +24 -0
  32. package/lib/types/PubSub.js +2 -12
  33. package/lib/types/PubSub.js.map +1 -1
  34. package/lib/types/index.d.ts +2 -0
  35. package/lib/types/index.js +2 -4
  36. package/lib/types/index.js.map +1 -1
  37. package/lib/utils/ConnectionStateMonitor.d.ts +41 -0
  38. package/lib/utils/ConnectionStateMonitor.js +16 -29
  39. package/lib/utils/ConnectionStateMonitor.js.map +1 -1
  40. package/lib/utils/ReachabilityMonitor/index.d.ts +3 -0
  41. package/lib/utils/ReachabilityMonitor/index.native.d.ts +3 -0
  42. package/lib/utils/ReachabilityMonitor/index.native.js +2 -4
  43. package/lib/utils/ReachabilityMonitor/index.native.js.map +1 -1
  44. package/lib/utils/ReconnectionMonitor.d.ts +29 -0
  45. package/lib/utils/ReconnectionMonitor.js +73 -0
  46. package/lib/utils/ReconnectionMonitor.js.map +1 -0
  47. package/lib-esm/.tsbuildinfo +3 -0
  48. package/lib-esm/Providers/AWSAppSyncProvider.js +1 -80
  49. package/lib-esm/Providers/AWSAppSyncProvider.js.map +1 -1
  50. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +8 -0
  51. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +126 -168
  52. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
  53. package/lib-esm/Providers/AWSIotProvider.js +3 -61
  54. package/lib-esm/Providers/AWSIotProvider.js.map +1 -1
  55. package/lib-esm/Providers/MqttOverWSProvider.d.ts +2 -4
  56. package/lib-esm/Providers/MqttOverWSProvider.js +139 -175
  57. package/lib-esm/Providers/MqttOverWSProvider.js.map +1 -1
  58. package/lib-esm/Providers/PubSubProvider.js +1 -11
  59. package/lib-esm/Providers/PubSubProvider.js.map +1 -1
  60. package/lib-esm/Providers/constants.d.ts +8 -0
  61. package/lib-esm/Providers/constants.js +8 -0
  62. package/lib-esm/Providers/constants.js.map +1 -1
  63. package/lib-esm/Providers/index.d.ts +5 -5
  64. package/lib-esm/Providers/index.js +7 -17
  65. package/lib-esm/Providers/index.js.map +1 -1
  66. package/lib-esm/PubSub.js +3 -48
  67. package/lib-esm/PubSub.js.map +1 -1
  68. package/lib-esm/index.d.ts +2 -7
  69. package/lib-esm/index.js +4 -19
  70. package/lib-esm/index.js.map +1 -1
  71. package/lib-esm/types/Provider.d.ts +0 -4
  72. package/lib-esm/types/PubSub.js +2 -12
  73. package/lib-esm/types/PubSub.js.map +1 -1
  74. package/lib-esm/types/index.js.map +1 -1
  75. package/lib-esm/utils/ConnectionStateMonitor.d.ts +1 -0
  76. package/lib-esm/utils/ConnectionStateMonitor.js +13 -23
  77. package/lib-esm/utils/ConnectionStateMonitor.js.map +1 -1
  78. package/lib-esm/utils/ReconnectionMonitor.d.ts +29 -0
  79. package/lib-esm/utils/ReconnectionMonitor.js +71 -0
  80. package/lib-esm/utils/ReconnectionMonitor.js.map +1 -0
  81. package/package.json +14 -10
  82. package/src/Providers/AWSAppSyncProvider.ts +2 -12
  83. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +142 -89
  84. package/src/Providers/AWSIotProvider.ts +2 -12
  85. package/src/Providers/MqttOverWSProvider.ts +90 -79
  86. package/src/Providers/PubSubProvider.ts +2 -12
  87. package/src/Providers/constants.ts +10 -0
  88. package/src/Providers/index.ts +15 -17
  89. package/src/PubSub.ts +2 -12
  90. package/src/index.ts +15 -23
  91. package/src/types/Provider.ts +2 -17
  92. package/src/types/PubSub.ts +2 -12
  93. package/src/types/index.ts +2 -12
  94. package/src/utils/ConnectionStateMonitor.ts +16 -12
  95. package/src/utils/ReconnectionMonitor.ts +74 -0
  96. package/build.js +0 -5
  97. package/dist/aws-amplify-pubsub.js +0 -10314
  98. package/dist/aws-amplify-pubsub.js.map +0 -1
  99. package/dist/aws-amplify-pubsub.min.js +0 -11
  100. package/dist/aws-amplify-pubsub.min.js.map +0 -1
  101. package/index.js +0 -7
  102. package/webpack.config.dev.js +0 -6
@@ -1,17 +1,15 @@
1
- /*
2
- * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://aws.amazon.com/apache2.0/
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
13
- export * from './PubSubProvider';
14
- export * from './AWSAppSyncProvider';
15
- export * from './AWSAppSyncRealTimeProvider';
16
- export * from './AWSIotProvider';
17
- export * from './MqttOverWSProvider';
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ export { AbstractPubSubProvider } from './PubSubProvider';
4
+ export { AWSAppSyncProvider } from './AWSAppSyncProvider';
5
+ export {
6
+ AWSAppSyncRealTimeProvider,
7
+ AWSAppSyncRealTimeProviderOptions,
8
+ ObserverQuery,
9
+ } from './AWSAppSyncRealTimeProvider';
10
+ export { AWSIoTProvider, AWSIoTProviderOptions } from './AWSIotProvider';
11
+ export {
12
+ MqttProviderOptions,
13
+ MqttOverWSProvider,
14
+ mqttTopicMatch,
15
+ } from './MqttOverWSProvider';
package/src/PubSub.ts CHANGED
@@ -1,15 +1,5 @@
1
- /*
2
- * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://aws.amazon.com/apache2.0/
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
13
3
  // import '../Common/Polyfills';
14
4
  import Observable from 'zen-observable-ts';
15
5
 
package/src/index.ts CHANGED
@@ -1,26 +1,18 @@
1
- /*
2
- * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://aws.amazon.com/apache2.0/
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
13
- import { PubSub } from './PubSub';
14
-
15
- export * from './Providers';
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
16
3
 
4
+ export { PubSub } from './PubSub';
17
5
  export { CONNECTION_STATE_CHANGE } from './Providers/constants';
18
-
19
6
  export { ConnectionState, CONTROL_MSG } from './types';
20
-
21
- export { PubSub };
22
-
23
- /**
24
- * @deprecated use named import
25
- */
26
- export default PubSub;
7
+ export {
8
+ AWSAppSyncProvider,
9
+ AWSAppSyncRealTimeProvider,
10
+ AWSAppSyncRealTimeProviderOptions,
11
+ AWSIoTProvider,
12
+ AWSIoTProviderOptions,
13
+ AbstractPubSubProvider,
14
+ MqttOverWSProvider,
15
+ MqttProviderOptions,
16
+ ObserverQuery,
17
+ mqttTopicMatch,
18
+ } from './Providers';
@@ -1,15 +1,5 @@
1
- /*
2
- * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://aws.amazon.com/apache2.0/
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
13
3
  import Observable from 'zen-observable-ts';
14
4
 
15
5
  export interface PubSubOptions {
@@ -20,11 +10,6 @@ export interface ProviderOptions {
20
10
  [key: string]: any;
21
11
  }
22
12
 
23
- /**
24
- * @deprecated Migrated to ProviderOptions
25
- */
26
- export type ProvidertOptions = ProviderOptions;
27
-
28
13
  export interface PubSubProvider {
29
14
  // configure your provider
30
15
  configure(config: object): object;
@@ -1,15 +1,5 @@
1
- /*
2
- * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://aws.amazon.com/apache2.0/
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
13
3
 
14
4
  export interface SubscriptionObserver<T> {
15
5
  closed: boolean;
@@ -1,14 +1,4 @@
1
- /*
2
- * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://aws.amazon.com/apache2.0/
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
13
3
  export * from './Provider';
14
4
  export * from './PubSub';
@@ -1,15 +1,5 @@
1
- /*
2
- * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://aws.amazon.com/apache2.0/
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
13
3
 
14
4
  import { Reachability } from '@aws-amplify/core';
15
5
  import Observable, { ZenObservable } from 'zen-observable-ts';
@@ -63,6 +53,7 @@ export class ConnectionStateMonitor {
63
53
  private _linkedConnectionStateObservable: Observable<LinkedConnectionStates>;
64
54
  private _linkedConnectionStateObserver: ZenObservable.SubscriptionObserver<LinkedConnectionStates>;
65
55
  private _networkMonitoringSubscription?: ZenObservable.Subscription;
56
+ private _initialNetworkStateSubscription?: ZenObservable.Subscription;
66
57
 
67
58
  constructor() {
68
59
  this._networkMonitoringSubscription = undefined;
@@ -73,6 +64,16 @@ export class ConnectionStateMonitor {
73
64
  keepAliveState: 'healthy',
74
65
  };
75
66
 
67
+ // Attempt to update the state with the current actual network state
68
+ this._initialNetworkStateSubscription = ReachabilityMonitor().subscribe(
69
+ ({ online }) => {
70
+ this.record(
71
+ online ? CONNECTION_CHANGE.ONLINE : CONNECTION_CHANGE.OFFLINE
72
+ );
73
+ this._initialNetworkStateSubscription?.unsubscribe();
74
+ }
75
+ );
76
+
76
77
  this._linkedConnectionStateObservable =
77
78
  new Observable<LinkedConnectionStates>(connectionStateObserver => {
78
79
  connectionStateObserver.next(this._linkedConnectionState);
@@ -84,6 +85,9 @@ export class ConnectionStateMonitor {
84
85
  * Turn network state monitoring on if it isn't on already
85
86
  */
86
87
  private enableNetworkMonitoring() {
88
+ // If no initial network state was discovered, stop trying
89
+ this._initialNetworkStateSubscription?.unsubscribe();
90
+
87
91
  // Maintain the network state based on the reachability monitor
88
92
  if (this._networkMonitoringSubscription === undefined) {
89
93
  this._networkMonitoringSubscription = ReachabilityMonitor().subscribe(
@@ -0,0 +1,74 @@
1
+ import { Observer } from 'zen-observable-ts';
2
+ import { RECONNECT_DELAY, RECONNECT_INTERVAL } from '../Providers/constants';
3
+
4
+ export enum ReconnectEvent {
5
+ START_RECONNECT = 'START_RECONNECT',
6
+ HALT_RECONNECT = 'HALT_RECONNECT',
7
+ }
8
+
9
+ /**
10
+ * Captures the reconnect event logic used to determine when to reconnect to PubSub providers.
11
+ * Reconnnect attempts are delayed by 5 seconds to let the interface settle.
12
+ * Attempting to reconnect only once creates unrecoverable states when the network state isn't
13
+ * supported by the browser, so this keeps retrying every minute until halted.
14
+ */
15
+ export class ReconnectionMonitor {
16
+ private reconnectObservers: Observer<void>[] = [];
17
+ private reconnectIntervalId?: ReturnType<typeof setInterval>;
18
+ private reconnectSetTimeoutId?: ReturnType<typeof setTimeout>;
19
+
20
+ /**
21
+ * Add reconnect observer to the list of observers to alert on reconnect
22
+ */
23
+ addObserver(reconnectObserver: Observer<void>) {
24
+ this.reconnectObservers.push(reconnectObserver);
25
+ }
26
+
27
+ /**
28
+ * Given a reconnect event, start the appropriate behavior
29
+ */
30
+ record(event: ReconnectEvent) {
31
+ if (event === ReconnectEvent.START_RECONNECT) {
32
+ // If the reconnection hasn't been started
33
+ if (
34
+ this.reconnectSetTimeoutId === undefined &&
35
+ this.reconnectIntervalId === undefined
36
+ ) {
37
+ this.reconnectSetTimeoutId = setTimeout(() => {
38
+ // Reconnect now
39
+ this._triggerReconnect();
40
+ // Retry reconnect every periodically until it works
41
+ this.reconnectIntervalId = setInterval(() => {
42
+ this._triggerReconnect();
43
+ }, RECONNECT_INTERVAL);
44
+ }, RECONNECT_DELAY);
45
+ }
46
+ }
47
+
48
+ if (event === ReconnectEvent.HALT_RECONNECT) {
49
+ if (this.reconnectIntervalId) {
50
+ clearInterval(this.reconnectIntervalId);
51
+ this.reconnectIntervalId = undefined;
52
+ }
53
+ if (this.reconnectSetTimeoutId) {
54
+ clearTimeout(this.reconnectSetTimeoutId);
55
+ this.reconnectSetTimeoutId = undefined;
56
+ }
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Complete all reconnect observers
62
+ */
63
+ close() {
64
+ this.reconnectObservers.forEach(reconnectObserver => {
65
+ reconnectObserver.complete?.();
66
+ });
67
+ }
68
+
69
+ private _triggerReconnect() {
70
+ this.reconnectObservers.forEach(reconnectObserver => {
71
+ reconnectObserver.next?.();
72
+ });
73
+ }
74
+ }
package/build.js DELETED
@@ -1,5 +0,0 @@
1
- 'use strict';
2
-
3
- const build = require('../../scripts/build');
4
-
5
- build(process.argv[2], process.argv[3]);