@aws-amplify/pubsub 6.0.1-api-v6-models.9351bcf.0 → 6.0.1-api-v6-models.891fe0d.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.
@@ -3,10 +3,9 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.ConnectionStateMonitor = exports.CONNECTION_CHANGE = void 0;
6
- var tslib_1 = require("tslib");
7
- var rxjs_1 = require("rxjs");
8
- var PubSub_1 = require("../types/PubSub");
9
- var ReachabilityMonitor_1 = require("./ReachabilityMonitor");
6
+ const rxjs_1 = require("rxjs");
7
+ const PubSub_1 = require("../types/PubSub");
8
+ const ReachabilityMonitor_1 = require("./ReachabilityMonitor");
10
9
  exports.CONNECTION_CHANGE = {
11
10
  KEEP_ALIVE_MISSED: { keepAliveState: 'unhealthy' },
12
11
  KEEP_ALIVE: { keepAliveState: 'healthy' },
@@ -24,9 +23,8 @@ exports.CONNECTION_CHANGE = {
24
23
  ONLINE: { networkState: 'connected' },
25
24
  OFFLINE: { networkState: 'disconnected' },
26
25
  };
27
- var ConnectionStateMonitor = /** @class */ (function () {
28
- function ConnectionStateMonitor() {
29
- var _this = this;
26
+ class ConnectionStateMonitor {
27
+ constructor() {
30
28
  this._networkMonitoringSubscription = undefined;
31
29
  this._linkedConnectionState = {
32
30
  networkState: 'connected',
@@ -35,73 +33,61 @@ var ConnectionStateMonitor = /** @class */ (function () {
35
33
  keepAliveState: 'healthy',
36
34
  };
37
35
  // Attempt to update the state with the current actual network state
38
- this._initialNetworkStateSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(function (_a) {
39
- var _b;
40
- var online = _a.online;
41
- _this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
42
- (_b = _this._initialNetworkStateSubscription) === null || _b === void 0 ? void 0 : _b.unsubscribe();
36
+ this._initialNetworkStateSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(({ online }) => {
37
+ this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
38
+ this._initialNetworkStateSubscription?.unsubscribe();
43
39
  });
44
40
  this._linkedConnectionStateObservable =
45
- new rxjs_1.Observable(function (connectionStateObserver) {
46
- connectionStateObserver.next(_this._linkedConnectionState);
47
- _this._linkedConnectionStateObserver = connectionStateObserver;
41
+ new rxjs_1.Observable(connectionStateObserver => {
42
+ connectionStateObserver.next(this._linkedConnectionState);
43
+ this._linkedConnectionStateObserver = connectionStateObserver;
48
44
  });
49
45
  }
50
46
  /**
51
47
  * Turn network state monitoring on if it isn't on already
52
48
  */
53
- ConnectionStateMonitor.prototype.enableNetworkMonitoring = function () {
54
- var _this = this;
55
- var _a;
49
+ enableNetworkMonitoring() {
56
50
  // If no initial network state was discovered, stop trying
57
- (_a = this._initialNetworkStateSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
51
+ this._initialNetworkStateSubscription?.unsubscribe();
58
52
  // Maintain the network state based on the reachability monitor
59
53
  if (this._networkMonitoringSubscription === undefined) {
60
- this._networkMonitoringSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(function (_a) {
61
- var online = _a.online;
62
- _this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
54
+ this._networkMonitoringSubscription = (0, ReachabilityMonitor_1.ReachabilityMonitor)().subscribe(({ online }) => {
55
+ this.record(online ? exports.CONNECTION_CHANGE.ONLINE : exports.CONNECTION_CHANGE.OFFLINE);
63
56
  });
64
57
  }
65
- };
58
+ }
66
59
  /**
67
60
  * Turn network state monitoring off if it isn't off already
68
61
  */
69
- ConnectionStateMonitor.prototype.disableNetworkMonitoring = function () {
70
- var _a;
71
- (_a = this._networkMonitoringSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
62
+ disableNetworkMonitoring() {
63
+ this._networkMonitoringSubscription?.unsubscribe();
72
64
  this._networkMonitoringSubscription = undefined;
73
- };
74
- Object.defineProperty(ConnectionStateMonitor.prototype, "connectionStateObservable", {
75
- /**
76
- * Get the observable that allows us to monitor the connection state
77
- *
78
- * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
79
- */
80
- get: function () {
81
- var _this = this;
82
- var previous;
83
- // The linked state aggregates state changes to any of the network, connection,
84
- // intendedConnection and keepAliveHealth. Some states will change these independent
85
- // states without changing the overall connection state.
86
- // After translating from linked states to ConnectionState, then remove any duplicates
87
- return this._linkedConnectionStateObservable
88
- .pipe((0, rxjs_1.map)(function (value) {
89
- return _this.connectionStatesTranslator(value);
90
- }))
91
- .pipe((0, rxjs_1.filter)(function (current) {
92
- var toInclude = current !== previous;
93
- previous = current;
94
- return toInclude;
95
- }));
96
- },
97
- enumerable: false,
98
- configurable: true
99
- });
65
+ }
66
+ /**
67
+ * Get the observable that allows us to monitor the connection state
68
+ *
69
+ * @returns {Observable<ConnectionState>} - The observable that emits ConnectionState updates
70
+ */
71
+ get connectionStateObservable() {
72
+ let previous;
73
+ // The linked state aggregates state changes to any of the network, connection,
74
+ // intendedConnection and keepAliveHealth. Some states will change these independent
75
+ // states without changing the overall connection state.
76
+ // After translating from linked states to ConnectionState, then remove any duplicates
77
+ return this._linkedConnectionStateObservable
78
+ .pipe((0, rxjs_1.map)(value => {
79
+ return this.connectionStatesTranslator(value);
80
+ }))
81
+ .pipe((0, rxjs_1.filter)(current => {
82
+ const toInclude = current !== previous;
83
+ previous = current;
84
+ return toInclude;
85
+ }));
86
+ }
100
87
  /*
101
88
  * Updates local connection state and emits the full state to the observer.
102
89
  */
103
- ConnectionStateMonitor.prototype.record = function (statusUpdates) {
104
- var _a;
90
+ record(statusUpdates) {
105
91
  // Maintain the network monitor
106
92
  if (statusUpdates.intendedConnectionState === 'connected') {
107
93
  this.enableNetworkMonitoring();
@@ -110,15 +96,17 @@ var ConnectionStateMonitor = /** @class */ (function () {
110
96
  this.disableNetworkMonitoring();
111
97
  }
112
98
  // Maintain the socket state
113
- var newSocketStatus = tslib_1.__assign(tslib_1.__assign({}, this._linkedConnectionState), statusUpdates);
114
- this._linkedConnectionState = tslib_1.__assign({}, newSocketStatus);
115
- (_a = this._linkedConnectionStateObserver) === null || _a === void 0 ? void 0 : _a.next(this._linkedConnectionState);
116
- };
99
+ const newSocketStatus = {
100
+ ...this._linkedConnectionState,
101
+ ...statusUpdates,
102
+ };
103
+ this._linkedConnectionState = { ...newSocketStatus };
104
+ this._linkedConnectionStateObserver?.next(this._linkedConnectionState);
105
+ }
117
106
  /*
118
107
  * Translate the ConnectionState structure into a specific ConnectionState string literal union
119
108
  */
120
- ConnectionStateMonitor.prototype.connectionStatesTranslator = function (_a) {
121
- var connectionState = _a.connectionState, networkState = _a.networkState, intendedConnectionState = _a.intendedConnectionState, keepAliveState = _a.keepAliveState;
109
+ connectionStatesTranslator({ connectionState, networkState, intendedConnectionState, keepAliveState, }) {
122
110
  if (connectionState === 'connected' && networkState === 'disconnected')
123
111
  return PubSub_1.ConnectionState.ConnectedPendingNetwork;
124
112
  if (connectionState === 'connected' &&
@@ -139,7 +127,6 @@ var ConnectionStateMonitor = /** @class */ (function () {
139
127
  if (connectionState === 'disconnected')
140
128
  return PubSub_1.ConnectionState.Disconnected;
141
129
  return PubSub_1.ConnectionState.Connected;
142
- };
143
- return ConnectionStateMonitor;
144
- }());
130
+ }
131
+ }
145
132
  exports.ConnectionStateMonitor = ConnectionStateMonitor;
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReachabilityMonitor = void 0;
4
4
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
5
  // SPDX-License-Identifier: Apache-2.0
6
- var utils_1 = require("@aws-amplify/core/internals/utils");
7
- var ReachabilityMonitor = function () { return new utils_1.Reachability().networkMonitor(); };
6
+ const utils_1 = require("@aws-amplify/core/internals/utils");
7
+ const ReachabilityMonitor = () => new utils_1.Reachability().networkMonitor();
8
8
  exports.ReachabilityMonitor = ReachabilityMonitor;
@@ -3,10 +3,8 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.ReachabilityMonitor = void 0;
6
- var tslib_1 = require("tslib");
7
- var utils_1 = require("@aws-amplify/core/internals/utils");
8
- var netinfo_1 = tslib_1.__importDefault(require("@react-native-community/netinfo"));
9
- var ReachabilityMonitor = function () {
10
- return new utils_1.Reachability().networkMonitor(netinfo_1.default);
11
- };
6
+ const tslib_1 = require("tslib");
7
+ const utils_1 = require("@aws-amplify/core/internals/utils");
8
+ const netinfo_1 = tslib_1.__importDefault(require("@react-native-community/netinfo"));
9
+ const ReachabilityMonitor = () => new utils_1.Reachability().networkMonitor(netinfo_1.default);
12
10
  exports.ReachabilityMonitor = ReachabilityMonitor;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReconnectionMonitor = exports.ReconnectEvent = void 0;
4
- var constants_1 = require("../Providers/constants");
4
+ const constants_1 = require("../Providers/constants");
5
5
  var ReconnectEvent;
6
6
  (function (ReconnectEvent) {
7
7
  ReconnectEvent["START_RECONNECT"] = "START_RECONNECT";
@@ -13,31 +13,30 @@ var ReconnectEvent;
13
13
  * Attempting to reconnect only once creates unrecoverable states when the network state isn't
14
14
  * supported by the browser, so this keeps retrying every minute until halted.
15
15
  */
16
- var ReconnectionMonitor = /** @class */ (function () {
17
- function ReconnectionMonitor() {
16
+ class ReconnectionMonitor {
17
+ constructor() {
18
18
  this.reconnectObservers = [];
19
19
  }
20
20
  /**
21
21
  * Add reconnect observer to the list of observers to alert on reconnect
22
22
  */
23
- ReconnectionMonitor.prototype.addObserver = function (reconnectObserver) {
23
+ addObserver(reconnectObserver) {
24
24
  this.reconnectObservers.push(reconnectObserver);
25
- };
25
+ }
26
26
  /**
27
27
  * Given a reconnect event, start the appropriate behavior
28
28
  */
29
- ReconnectionMonitor.prototype.record = function (event) {
30
- var _this = this;
29
+ record(event) {
31
30
  if (event === ReconnectEvent.START_RECONNECT) {
32
31
  // If the reconnection hasn't been started
33
32
  if (this.reconnectSetTimeoutId === undefined &&
34
33
  this.reconnectIntervalId === undefined) {
35
- this.reconnectSetTimeoutId = setTimeout(function () {
34
+ this.reconnectSetTimeoutId = setTimeout(() => {
36
35
  // Reconnect now
37
- _this._triggerReconnect();
36
+ this._triggerReconnect();
38
37
  // Retry reconnect every periodically until it works
39
- _this.reconnectIntervalId = setInterval(function () {
40
- _this._triggerReconnect();
38
+ this.reconnectIntervalId = setInterval(() => {
39
+ this._triggerReconnect();
41
40
  }, constants_1.RECONNECT_INTERVAL);
42
41
  }, constants_1.RECONNECT_DELAY);
43
42
  }
@@ -52,22 +51,19 @@ var ReconnectionMonitor = /** @class */ (function () {
52
51
  this.reconnectSetTimeoutId = undefined;
53
52
  }
54
53
  }
55
- };
54
+ }
56
55
  /**
57
56
  * Complete all reconnect observers
58
57
  */
59
- ReconnectionMonitor.prototype.close = function () {
60
- this.reconnectObservers.forEach(function (reconnectObserver) {
61
- var _a;
62
- (_a = reconnectObserver.complete) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
58
+ close() {
59
+ this.reconnectObservers.forEach(reconnectObserver => {
60
+ reconnectObserver.complete?.();
63
61
  });
64
- };
65
- ReconnectionMonitor.prototype._triggerReconnect = function () {
66
- this.reconnectObservers.forEach(function (reconnectObserver) {
67
- var _a;
68
- (_a = reconnectObserver.next) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
62
+ }
63
+ _triggerReconnect() {
64
+ this.reconnectObservers.forEach(reconnectObserver => {
65
+ reconnectObserver.next?.();
69
66
  });
70
- };
71
- return ReconnectionMonitor;
72
- }());
67
+ }
68
+ }
73
69
  exports.ReconnectionMonitor = ReconnectionMonitor;
@@ -1,53 +1,30 @@
1
- import { __awaiter, __extends, __generator } from "tslib";
2
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
2
  // SPDX-License-Identifier: Apache-2.0
4
3
  import { MqttOverWS } from './MqttOverWS';
5
4
  import { Signer } from '@aws-amplify/core/internals/utils';
6
5
  import { fetchAuthSession } from '@aws-amplify/core';
7
- var SERVICE_NAME = 'iotdevicegateway';
8
- var AWSIoT = /** @class */ (function (_super) {
9
- __extends(AWSIoT, _super);
10
- function AWSIoT(options) {
11
- if (options === void 0) { options = {}; }
12
- return _super.call(this, options) || this;
6
+ const SERVICE_NAME = 'iotdevicegateway';
7
+ export class AWSIoT extends MqttOverWS {
8
+ constructor(options = {}) {
9
+ super(options);
13
10
  }
14
- Object.defineProperty(AWSIoT.prototype, "region", {
15
- get: function () {
16
- var _a;
17
- return (_a = this.options) === null || _a === void 0 ? void 0 : _a.region;
18
- },
19
- enumerable: false,
20
- configurable: true
21
- });
22
- Object.defineProperty(AWSIoT.prototype, "endpoint", {
23
- get: function () {
24
- var _this = this;
25
- return (function () { return __awaiter(_this, void 0, void 0, function () {
26
- var endpoint, serviceInfo, session, _a, access_key, secret_key, session_token, result;
27
- return __generator(this, function (_b) {
28
- switch (_b.label) {
29
- case 0:
30
- endpoint = this.options.endpoint;
31
- serviceInfo = {
32
- service: SERVICE_NAME,
33
- region: this.region,
34
- };
35
- return [4 /*yield*/, fetchAuthSession()];
36
- case 1:
37
- session = _b.sent();
38
- if (!session.credentials) {
39
- throw new Error('No auth session credentials');
40
- }
41
- _a = session.credentials, access_key = _a.accessKeyId, secret_key = _a.secretAccessKey, session_token = _a.sessionToken;
42
- result = Signer.signUrl(endpoint, { access_key: access_key, secret_key: secret_key, session_token: session_token }, serviceInfo);
43
- return [2 /*return*/, result];
44
- }
45
- });
46
- }); })();
47
- },
48
- enumerable: false,
49
- configurable: true
50
- });
51
- return AWSIoT;
52
- }(MqttOverWS));
53
- export { AWSIoT };
11
+ get region() {
12
+ return this.options?.region;
13
+ }
14
+ get endpoint() {
15
+ return (async () => {
16
+ const endpoint = this.options.endpoint;
17
+ const serviceInfo = {
18
+ service: SERVICE_NAME,
19
+ region: this.region,
20
+ };
21
+ const session = await fetchAuthSession();
22
+ if (!session.credentials) {
23
+ throw new Error('No auth session credentials');
24
+ }
25
+ const { accessKeyId: access_key, secretAccessKey: secret_key, sessionToken: session_token, } = session.credentials;
26
+ const result = Signer.signUrl(endpoint, { access_key, secret_key, session_token }, serviceInfo);
27
+ return result;
28
+ })();
29
+ }
30
+ }
@@ -1,6 +1,6 @@
1
1
  import { Observable } from 'rxjs';
2
2
  import { AbstractPubSub } from './PubSub';
3
- import { PubSubContentObserver, PubSubContent, PubSubOptions } from '../types/PubSub';
3
+ import { PubSubContentObserver, PubSubContent, PubSubOptions, PublishInput, SubscribeInput } from '../types/PubSub';
4
4
  export declare function mqttTopicMatch(filter: string, topic: string): boolean;
5
5
  export interface MqttOptions extends PubSubOptions {
6
6
  clientId?: string;
@@ -47,10 +47,12 @@ export declare class MqttOverWS extends AbstractPubSub<MqttOptions> {
47
47
  newClient({ url, clientId }: MqttOptions): Promise<PahoClient>;
48
48
  protected connect(clientId: string, options?: MqttOptions): Promise<PahoClient | undefined>;
49
49
  protected disconnect(clientId: string): Promise<void>;
50
- publish(topics: string[] | string, msg: PubSubContent): Promise<void>;
50
+ publish({ topics, message }: PublishInput): Promise<void>;
51
51
  protected _topicObservers: Map<string, Set<PubSubContentObserver>>;
52
52
  protected _clientIdObservers: Map<string, Set<PubSubContentObserver>>;
53
53
  private _onMessage;
54
- subscribe(topics: string[] | string, options?: MqttOptions): Observable<PubSubContent>;
54
+ subscribe({ topics, options, }: SubscribeInput & {
55
+ options?: MqttOptions;
56
+ }): Observable<PubSubContent>;
55
57
  }
56
58
  export {};