@trycourier/react-provider 1.52.2 → 1.52.3-internal.400765e.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.
- package/README.md +0 -3
- package/dist/hooks/use-courier-actions.js +11 -0
- package/dist/hooks/use-page-visible.js +26 -0
- package/dist/hooks/use-transport.js +5 -3
- package/dist/index.js +57 -28
- package/dist/middleware.js +65 -2
- package/dist/reducer.js +1 -9
- package/dist/transports/base.js +27 -5
- package/dist/transports/courier/index.js +24 -4
- package/dist/ws.js +71 -27
- package/package.json +5 -4
- package/typings/hooks/use-courier-actions.d.ts +4 -2
- package/typings/hooks/use-courier-actions.d.ts.map +1 -1
- package/typings/hooks/use-page-visible.d.ts +3 -0
- package/typings/hooks/use-page-visible.d.ts.map +1 -0
- package/typings/hooks/use-transport.d.ts +3 -2
- package/typings/hooks/use-transport.d.ts.map +1 -1
- package/typings/index.d.ts +3 -1
- package/typings/index.d.ts.map +1 -1
- package/typings/middleware.d.ts +15 -1
- package/typings/middleware.d.ts.map +1 -1
- package/typings/reducer.d.ts +2 -1
- package/typings/reducer.d.ts.map +1 -1
- package/typings/transports/base.d.ts +12 -4
- package/typings/transports/base.d.ts.map +1 -1
- package/typings/transports/courier/index.d.ts +9 -2
- package/typings/transports/courier/index.d.ts.map +1 -1
- package/typings/transports/courier/types.d.ts +1 -0
- package/typings/transports/courier/types.d.ts.map +1 -1
- package/typings/transports/types.d.ts +3 -2
- package/typings/transports/types.d.ts.map +1 -1
- package/typings/types.d.ts +2 -3
- package/typings/types.d.ts.map +1 -1
- package/typings/ws.d.ts +16 -10
- package/typings/ws.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -24,9 +24,6 @@ interface ICourierProvider {
|
|
|
24
24
|
/** Allows the browser to modify or react to a received message before the message is displayed to the user */
|
|
25
25
|
onMessage?: (message?: ICourierMessage) => ICourierMessage | undefined;
|
|
26
26
|
|
|
27
|
-
/** Set to true to disable websockets */
|
|
28
|
-
disableTransport?: boolean;
|
|
29
|
-
|
|
30
27
|
/** Courier client key. Along with userId and userSignature this can be used as an alternative to the authorization field / token. */
|
|
31
28
|
clientKey?: string;
|
|
32
29
|
/** Required if using client key and signature */
|
|
@@ -20,6 +20,7 @@ var useCourierActions = function useCourierActions(state, dispatch) {
|
|
|
20
20
|
var courierClient = (0, _clientGraphql.createCourierClient)({
|
|
21
21
|
apiUrl: state.apiUrl,
|
|
22
22
|
authorization: state.authorization,
|
|
23
|
+
clientSourceId: state.clientSourceId,
|
|
23
24
|
clientKey: state.clientKey,
|
|
24
25
|
userId: state.userId,
|
|
25
26
|
userSignature: state.userSignature
|
|
@@ -68,6 +69,16 @@ var useCourierActions = function useCourierActions(state, dispatch) {
|
|
|
68
69
|
payload: payload
|
|
69
70
|
});
|
|
70
71
|
},
|
|
72
|
+
pageVisible: function pageVisible() {
|
|
73
|
+
dispatch({
|
|
74
|
+
type: "root/PAGE_VISIBLE"
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
wsReconnected: function wsReconnected() {
|
|
78
|
+
dispatch({
|
|
79
|
+
type: "root/WS_RECONNECTED"
|
|
80
|
+
});
|
|
81
|
+
},
|
|
71
82
|
getBrand: function getBrand(brandId) {
|
|
72
83
|
dispatch({
|
|
73
84
|
type: "root/GET_BRAND",
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getIsDocumentHidden = getIsDocumentHidden;
|
|
7
|
+
exports.usePageVisible = usePageVisible;
|
|
8
|
+
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
|
|
11
|
+
function getIsDocumentHidden() {
|
|
12
|
+
return !document.hidden;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function usePageVisible(callback) {
|
|
16
|
+
var onVisibilityChange = function onVisibilityChange() {
|
|
17
|
+
callback(getIsDocumentHidden());
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
(0, _react.useEffect)(function () {
|
|
21
|
+
document.addEventListener("visibilitychange", onVisibilityChange, false);
|
|
22
|
+
return function () {
|
|
23
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
}
|
|
@@ -10,9 +10,10 @@ var _react = require("react");
|
|
|
10
10
|
var _transports = require("../transports");
|
|
11
11
|
|
|
12
12
|
var useCourierTransport = function useCourierTransport(_ref) {
|
|
13
|
-
var
|
|
14
|
-
|
|
13
|
+
var authorization = _ref.authorization,
|
|
14
|
+
clientSourceId = _ref.clientSourceId,
|
|
15
15
|
clientKey = _ref.clientKey,
|
|
16
|
+
transport = _ref.transport,
|
|
16
17
|
userSignature = _ref.userSignature,
|
|
17
18
|
wsOptions = _ref.wsOptions;
|
|
18
19
|
return (0, _react.useMemo)(function () {
|
|
@@ -23,8 +24,9 @@ var useCourierTransport = function useCourierTransport(_ref) {
|
|
|
23
24
|
if ((clientKey || authorization) && !transport) {
|
|
24
25
|
return new _transports.CourierTransport({
|
|
25
26
|
authorization: authorization,
|
|
26
|
-
|
|
27
|
+
clientSourceId: clientSourceId,
|
|
27
28
|
clientKey: clientKey,
|
|
29
|
+
userSignature: userSignature,
|
|
28
30
|
wsOptions: wsOptions
|
|
29
31
|
});
|
|
30
32
|
}
|
package/dist/index.js
CHANGED
|
@@ -9,10 +9,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
9
9
|
});
|
|
10
10
|
var _exportNames = {
|
|
11
11
|
registerReducer: true,
|
|
12
|
+
registerMiddleware: true,
|
|
12
13
|
CourierContext: true,
|
|
13
14
|
CourierProvider: true
|
|
14
15
|
};
|
|
15
|
-
exports.CourierProvider = exports.CourierContext = exports.registerReducer = void 0;
|
|
16
|
+
exports.CourierProvider = exports.CourierContext = exports.registerMiddleware = exports.registerReducer = void 0;
|
|
16
17
|
|
|
17
18
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
18
19
|
|
|
@@ -24,12 +25,16 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
24
25
|
|
|
25
26
|
var _createReducer = _interopRequireDefault(require("react-use/lib/factory/createReducer"));
|
|
26
27
|
|
|
28
|
+
var uuid = _interopRequireWildcard(require("uuid"));
|
|
29
|
+
|
|
27
30
|
var _reducer = _interopRequireWildcard(require("./reducer"));
|
|
28
31
|
|
|
29
|
-
var _middleware2 =
|
|
32
|
+
var _middleware2 = _interopRequireWildcard(require("./middleware"));
|
|
30
33
|
|
|
31
34
|
var _useCourierActions = _interopRequireDefault(require("./hooks/use-courier-actions"));
|
|
32
35
|
|
|
36
|
+
var _usePageVisible = require("./hooks/use-page-visible");
|
|
37
|
+
|
|
33
38
|
var _useTransport = _interopRequireDefault(require("./hooks/use-transport"));
|
|
34
39
|
|
|
35
40
|
var _transports = require("./transports");
|
|
@@ -73,6 +78,8 @@ if (typeof window !== "undefined") {
|
|
|
73
78
|
|
|
74
79
|
var registerReducer = _reducer.registerReducer;
|
|
75
80
|
exports.registerReducer = registerReducer;
|
|
81
|
+
var registerMiddleware = _middleware2.registerMiddleware;
|
|
82
|
+
exports.registerMiddleware = registerMiddleware;
|
|
76
83
|
|
|
77
84
|
var CourierContext = /*#__PURE__*/_react["default"].createContext(undefined);
|
|
78
85
|
|
|
@@ -81,13 +88,13 @@ exports.CourierContext = CourierContext;
|
|
|
81
88
|
var CourierProvider = function CourierProvider(_ref) {
|
|
82
89
|
var _window;
|
|
83
90
|
|
|
84
|
-
var
|
|
91
|
+
var id = _ref.id,
|
|
92
|
+
apiUrl = _ref.apiUrl,
|
|
85
93
|
authorization = _ref.authorization,
|
|
86
94
|
brand = _ref.brand,
|
|
87
95
|
brandId = _ref.brandId,
|
|
88
96
|
children = _ref.children,
|
|
89
97
|
clientKey = _ref.clientKey,
|
|
90
|
-
disableTransport = _ref.disableTransport,
|
|
91
98
|
_ref$localStorage = _ref.localStorage,
|
|
92
99
|
localStorage = _ref$localStorage === void 0 ? (_window = window) === null || _window === void 0 ? void 0 : _window.localStorage : _ref$localStorage,
|
|
93
100
|
_ref$middleware = _ref.middleware,
|
|
@@ -98,10 +105,24 @@ var CourierProvider = function CourierProvider(_ref) {
|
|
|
98
105
|
userSignature = _ref.userSignature,
|
|
99
106
|
wsOptions = _ref.wsOptions;
|
|
100
107
|
|
|
108
|
+
var clientSourceId = (0, _react.useMemo)(function () {
|
|
109
|
+
var clientKeyId = id ? "".concat(clientKey, "/").concat(id) : clientKey;
|
|
110
|
+
var clientSourceIdLSKey = "".concat(clientKeyId, "/").concat(userId, "/clientSourceId");
|
|
111
|
+
var localStorageClientSourceId = localStorage.getItem(clientSourceIdLSKey);
|
|
112
|
+
|
|
113
|
+
if (localStorageClientSourceId) {
|
|
114
|
+
return localStorageClientSourceId;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
var newClientSourceId = uuid.v4();
|
|
118
|
+
localStorage.setItem(clientSourceIdLSKey, newClientSourceId);
|
|
119
|
+
return newClientSourceId;
|
|
120
|
+
}, [localStorage, clientKey, userId]);
|
|
101
121
|
var middleware = [].concat((0, _toConsumableArray2["default"])(_middleware), (0, _toConsumableArray2["default"])(_middleware2["default"]));
|
|
102
122
|
var useReducer = (0, _react.useCallback)(_createReducer["default"].apply(void 0, (0, _toConsumableArray2["default"])(middleware)), [_middleware]);
|
|
103
|
-
var transport =
|
|
123
|
+
var transport = typeof window === "undefined" ? undefined : (0, _useTransport["default"])({
|
|
104
124
|
authorization: authorization,
|
|
125
|
+
clientSourceId: clientSourceId,
|
|
105
126
|
clientKey: clientKey,
|
|
106
127
|
transport: _transport,
|
|
107
128
|
userSignature: userSignature,
|
|
@@ -113,6 +134,7 @@ var CourierProvider = function CourierProvider(_ref) {
|
|
|
113
134
|
authorization: authorization,
|
|
114
135
|
brand: brand,
|
|
115
136
|
brandId: brandId,
|
|
137
|
+
clientSourceId: clientSourceId,
|
|
116
138
|
clientKey: clientKey,
|
|
117
139
|
localStorage: localStorage,
|
|
118
140
|
middleware: middleware,
|
|
@@ -125,6 +147,14 @@ var CourierProvider = function CourierProvider(_ref) {
|
|
|
125
147
|
dispatch = _useReducer2[1];
|
|
126
148
|
|
|
127
149
|
var actions = (0, _useCourierActions["default"])(state, dispatch);
|
|
150
|
+
(0, _usePageVisible.usePageVisible)(function (isVisible) {
|
|
151
|
+
if (!isVisible) {
|
|
152
|
+
return;
|
|
153
|
+
} // this means we left the tab and came back so we should refetch
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
actions.pageVisible();
|
|
157
|
+
});
|
|
128
158
|
(0, _react.useEffect)(function () {
|
|
129
159
|
if (_transport) {
|
|
130
160
|
// this means the transport was passed in and we shouldn't subscribe
|
|
@@ -137,6 +167,12 @@ var CourierProvider = function CourierProvider(_ref) {
|
|
|
137
167
|
|
|
138
168
|
var courierTransport = transport;
|
|
139
169
|
courierTransport.subscribe(userId);
|
|
170
|
+
courierTransport.onReconnection({
|
|
171
|
+
id: "handleWSReconnection",
|
|
172
|
+
callback: function callback() {
|
|
173
|
+
actions.wsReconnected();
|
|
174
|
+
}
|
|
175
|
+
});
|
|
140
176
|
|
|
141
177
|
if (onMessage) {
|
|
142
178
|
courierTransport.intercept(onMessage);
|
|
@@ -151,11 +187,21 @@ var CourierProvider = function CourierProvider(_ref) {
|
|
|
151
187
|
return;
|
|
152
188
|
}
|
|
153
189
|
|
|
154
|
-
|
|
155
|
-
|
|
190
|
+
var parsedLocalStorageState;
|
|
191
|
+
|
|
192
|
+
if (state.localStorage) {
|
|
193
|
+
var localStorageState = state.localStorage.getItem("".concat(clientKey, "/").concat(userId, "/provider"));
|
|
194
|
+
|
|
195
|
+
if (localStorageState) {
|
|
196
|
+
try {
|
|
197
|
+
parsedLocalStorageState = JSON.parse(localStorageState);
|
|
198
|
+
} catch (ex) {
|
|
199
|
+
console.log("error", ex);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
156
202
|
}
|
|
157
203
|
|
|
158
|
-
actions.init({
|
|
204
|
+
actions.init(_objectSpread({
|
|
159
205
|
apiUrl: apiUrl,
|
|
160
206
|
authorization: authorization,
|
|
161
207
|
brandId: brandId,
|
|
@@ -164,8 +210,8 @@ var CourierProvider = function CourierProvider(_ref) {
|
|
|
164
210
|
transport: transport,
|
|
165
211
|
userId: userId,
|
|
166
212
|
userSignature: userSignature
|
|
167
|
-
});
|
|
168
|
-
}, [actions, apiUrl, authorization, brandId, clientKey,
|
|
213
|
+
}, parsedLocalStorageState));
|
|
214
|
+
}, [actions, apiUrl, authorization, brandId, clientKey, localStorage, transport, userId, userSignature]);
|
|
169
215
|
(0, _react.useEffect)(function () {
|
|
170
216
|
if (!state.brand || !clientKey || !userId || !state.localStorage) {
|
|
171
217
|
return;
|
|
@@ -175,26 +221,9 @@ var CourierProvider = function CourierProvider(_ref) {
|
|
|
175
221
|
brand: state.brand
|
|
176
222
|
}));
|
|
177
223
|
}, [state.brand, clientKey, userId, state.localStorage]);
|
|
178
|
-
(0, _react.useEffect)(function () {
|
|
179
|
-
if (!clientKey || !userId || disableTransport || !state.localStorage) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
var localStorageState = state.localStorage.getItem("".concat(clientKey, "/").concat(userId, "/provider"));
|
|
184
|
-
|
|
185
|
-
if (localStorageState) {
|
|
186
|
-
try {
|
|
187
|
-
var _JSON$parse = JSON.parse(localStorageState),
|
|
188
|
-
_brand = _JSON$parse.brand;
|
|
189
|
-
|
|
190
|
-
actions.setBrand(_brand);
|
|
191
|
-
} catch (ex) {
|
|
192
|
-
console.log("error", ex);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}, [clientKey, userId, state.localStorage]);
|
|
196
224
|
return /*#__PURE__*/_react["default"].createElement(CourierContext.Provider, {
|
|
197
225
|
value: _objectSpread(_objectSpread(_objectSpread({}, state), actions), {}, {
|
|
226
|
+
clientSourceId: clientSourceId,
|
|
198
227
|
dispatch: dispatch
|
|
199
228
|
})
|
|
200
229
|
}, children);
|
package/dist/middleware.js
CHANGED
|
@@ -5,12 +5,75 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports["default"] = void 0;
|
|
8
|
+
exports["default"] = exports.registerMiddleware = void 0;
|
|
9
9
|
|
|
10
10
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
11
|
|
|
12
12
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
13
|
|
|
14
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
15
|
+
|
|
16
|
+
function compose() {
|
|
17
|
+
for (var _len = arguments.length, funcs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
18
|
+
funcs[_key] = arguments[_key];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (funcs.length === 0) {
|
|
22
|
+
// infer the argument type so it is usable in inference down the line
|
|
23
|
+
return function (arg) {
|
|
24
|
+
return arg;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (funcs.length === 1) {
|
|
29
|
+
return funcs[0];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return funcs.reduce(function (a, b) {
|
|
33
|
+
return function () {
|
|
34
|
+
return a(b.apply(void 0, arguments));
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
var createDynamicMiddlewares = function createDynamicMiddlewares() {
|
|
40
|
+
var middlewares = [];
|
|
41
|
+
var store;
|
|
42
|
+
|
|
43
|
+
var enhancer = function enhancer(_store) {
|
|
44
|
+
store = _store;
|
|
45
|
+
return function (next) {
|
|
46
|
+
return function (action) {
|
|
47
|
+
return compose.apply(void 0, (0, _toConsumableArray2["default"])(middlewares.map(function (m) {
|
|
48
|
+
return m.middleware(store);
|
|
49
|
+
})))(next)(action);
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var registerMiddleware = function registerMiddleware(id, middleware) {
|
|
55
|
+
if (middlewares.find(function (m) {
|
|
56
|
+
return m.id === id;
|
|
57
|
+
})) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
middlewares.push({
|
|
62
|
+
id: id,
|
|
63
|
+
middleware: middleware
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
enhancer: enhancer,
|
|
69
|
+
registerMiddleware: registerMiddleware
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
var dynamicMiddlewaresInstance = createDynamicMiddlewares();
|
|
74
|
+
var registerMiddleware = dynamicMiddlewaresInstance.registerMiddleware;
|
|
75
|
+
exports.registerMiddleware = registerMiddleware;
|
|
76
|
+
|
|
14
77
|
var asyncMiddleware = function asyncMiddleware(store) {
|
|
15
78
|
return function (next) {
|
|
16
79
|
return /*#__PURE__*/function () {
|
|
@@ -71,5 +134,5 @@ var asyncMiddleware = function asyncMiddleware(store) {
|
|
|
71
134
|
};
|
|
72
135
|
};
|
|
73
136
|
|
|
74
|
-
var _default = [asyncMiddleware];
|
|
137
|
+
var _default = [asyncMiddleware, dynamicMiddlewaresInstance.enhancer];
|
|
75
138
|
exports["default"] = _default;
|
package/dist/reducer.js
CHANGED
|
@@ -44,15 +44,7 @@ var rootReducer = function rootReducer(state, action) {
|
|
|
44
44
|
switch (action.type) {
|
|
45
45
|
case "root/INIT":
|
|
46
46
|
{
|
|
47
|
-
return _objectSpread(_objectSpread({}, state),
|
|
48
|
-
apiUrl: action.payload.apiUrl,
|
|
49
|
-
brandId: action.payload.brandId,
|
|
50
|
-
clientKey: action.payload.clientKey,
|
|
51
|
-
graphQLClient: action.payload.graphQLClient,
|
|
52
|
-
transport: action.payload.transport,
|
|
53
|
-
userId: action.payload.userId,
|
|
54
|
-
userSignature: action.payload.userSignature
|
|
55
|
-
});
|
|
47
|
+
return _objectSpread(_objectSpread({}, state), action.payload);
|
|
56
48
|
}
|
|
57
49
|
|
|
58
50
|
case "root/GET_BRAND/DONE":
|
package/dist/transports/base.js
CHANGED
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.Transport = void 0;
|
|
9
9
|
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
|
|
10
12
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
13
|
|
|
12
14
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
@@ -15,18 +17,30 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
15
17
|
|
|
16
18
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
17
19
|
|
|
20
|
+
var ListenerType;
|
|
21
|
+
|
|
22
|
+
(function (ListenerType) {
|
|
23
|
+
ListenerType["message"] = "message";
|
|
24
|
+
ListenerType["event"] = "event";
|
|
25
|
+
})(ListenerType || (ListenerType = {}));
|
|
26
|
+
|
|
18
27
|
var Transport = function Transport() {
|
|
19
28
|
var _this = this;
|
|
20
29
|
|
|
21
30
|
(0, _classCallCheck2["default"])(this, Transport);
|
|
22
31
|
|
|
23
32
|
this.emit = function (courierEvent) {
|
|
24
|
-
|
|
33
|
+
var _courierEvent$type;
|
|
34
|
+
|
|
35
|
+
var eventType = (_courierEvent$type = courierEvent.type) !== null && _courierEvent$type !== void 0 ? _courierEvent$type : "message";
|
|
36
|
+
var listeners = _this.listeners[eventType];
|
|
37
|
+
|
|
38
|
+
if (!listeners.length) {
|
|
25
39
|
console.warn("No Listeners Registered");
|
|
26
40
|
return;
|
|
27
41
|
}
|
|
28
42
|
|
|
29
|
-
var _iterator = _createForOfIteratorHelper(
|
|
43
|
+
var _iterator = _createForOfIteratorHelper(listeners),
|
|
30
44
|
_step;
|
|
31
45
|
|
|
32
46
|
try {
|
|
@@ -42,8 +56,12 @@ var Transport = function Transport() {
|
|
|
42
56
|
};
|
|
43
57
|
|
|
44
58
|
this.listen = function (listener) {
|
|
59
|
+
var _listener$type;
|
|
60
|
+
|
|
45
61
|
var didReplaceListener = false;
|
|
46
|
-
|
|
62
|
+
var eventType = (_listener$type = listener.type) !== null && _listener$type !== void 0 ? _listener$type : "message";
|
|
63
|
+
var listeners = _this.listeners[eventType];
|
|
64
|
+
listeners = listeners.map(function (l) {
|
|
47
65
|
if (l.id === listener.id) {
|
|
48
66
|
didReplaceListener = true;
|
|
49
67
|
return listener;
|
|
@@ -53,17 +71,21 @@ var Transport = function Transport() {
|
|
|
53
71
|
});
|
|
54
72
|
|
|
55
73
|
if (didReplaceListener) {
|
|
74
|
+
_this.listeners[eventType] = listeners;
|
|
56
75
|
return;
|
|
57
76
|
}
|
|
58
77
|
|
|
59
|
-
_this.listeners.
|
|
78
|
+
_this.listeners[eventType] = [].concat((0, _toConsumableArray2["default"])(_this.listeners[eventType]), [listener]);
|
|
60
79
|
};
|
|
61
80
|
|
|
62
81
|
this.intercept = function (cb) {
|
|
63
82
|
_this.interceptor = cb;
|
|
64
83
|
};
|
|
65
84
|
|
|
66
|
-
this.listeners =
|
|
85
|
+
this.listeners = {
|
|
86
|
+
message: [],
|
|
87
|
+
event: []
|
|
88
|
+
};
|
|
67
89
|
this.interceptor = undefined;
|
|
68
90
|
}
|
|
69
91
|
/** Callback for emitted events */
|
|
@@ -47,10 +47,12 @@ var CourierTransport = /*#__PURE__*/function (_Transport) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
_this.authorization = options.authorization;
|
|
50
|
+
_this.clientSourceId = options.clientSourceId;
|
|
50
51
|
_this.clientKey = options.clientKey;
|
|
51
52
|
_this.userSignature = options.userSignature;
|
|
52
53
|
_this.ws = new _ws.WS({
|
|
53
54
|
authorization: options.authorization,
|
|
55
|
+
clientSourceId: options.clientSourceId,
|
|
54
56
|
clientKey: options.clientKey,
|
|
55
57
|
options: options.wsOptions,
|
|
56
58
|
userSignature: options.userSignature
|
|
@@ -62,6 +64,16 @@ var CourierTransport = /*#__PURE__*/function (_Transport) {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
(0, _createClass2["default"])(CourierTransport, [{
|
|
67
|
+
key: "closeConnection",
|
|
68
|
+
value: function closeConnection() {
|
|
69
|
+
this.ws.close();
|
|
70
|
+
}
|
|
71
|
+
}, {
|
|
72
|
+
key: "connect",
|
|
73
|
+
value: function connect() {
|
|
74
|
+
this.ws.connect();
|
|
75
|
+
}
|
|
76
|
+
}, {
|
|
65
77
|
key: "send",
|
|
66
78
|
value: function send(message) {
|
|
67
79
|
this.ws.send(_objectSpread(_objectSpread({}, message), {}, {
|
|
@@ -76,18 +88,21 @@ var CourierTransport = /*#__PURE__*/function (_Transport) {
|
|
|
76
88
|
var _this2 = this;
|
|
77
89
|
|
|
78
90
|
this.ws.subscribe(channel, event !== null && event !== void 0 ? event : "*", function (_ref) {
|
|
79
|
-
var
|
|
91
|
+
var _courierEvent$type;
|
|
92
|
+
|
|
93
|
+
var courierEvent = _ref.data;
|
|
80
94
|
|
|
81
95
|
if (_this2.interceptor) {
|
|
82
|
-
|
|
96
|
+
courierEvent = _this2.interceptor(courierEvent);
|
|
83
97
|
}
|
|
84
98
|
|
|
85
|
-
if (!
|
|
99
|
+
if (!courierEvent) {
|
|
86
100
|
return;
|
|
87
101
|
}
|
|
88
102
|
|
|
89
103
|
_this2.emit({
|
|
90
|
-
|
|
104
|
+
type: (_courierEvent$type = courierEvent.type) !== null && _courierEvent$type !== void 0 ? _courierEvent$type : "message",
|
|
105
|
+
data: courierEvent
|
|
91
106
|
});
|
|
92
107
|
});
|
|
93
108
|
}
|
|
@@ -96,6 +111,11 @@ var CourierTransport = /*#__PURE__*/function (_Transport) {
|
|
|
96
111
|
value: function unsubscribe(channel, event) {
|
|
97
112
|
this.ws.unsubscribe(channel, event !== null && event !== void 0 ? event : "*");
|
|
98
113
|
}
|
|
114
|
+
}, {
|
|
115
|
+
key: "onReconnection",
|
|
116
|
+
value: function onReconnection(handler) {
|
|
117
|
+
this.ws.onReconnection(handler);
|
|
118
|
+
}
|
|
99
119
|
}, {
|
|
100
120
|
key: "renewSession",
|
|
101
121
|
value: function renewSession(token) {
|
package/dist/ws.js
CHANGED
|
@@ -28,22 +28,35 @@ var WS = /*#__PURE__*/function () {
|
|
|
28
28
|
var authorization = _ref.authorization,
|
|
29
29
|
clientKey = _ref.clientKey,
|
|
30
30
|
options = _ref.options,
|
|
31
|
+
clientSourceId = _ref.clientSourceId,
|
|
31
32
|
userSignature = _ref.userSignature;
|
|
32
33
|
(0, _classCallCheck2["default"])(this, WS);
|
|
34
|
+
this.connectionCount = 0;
|
|
33
35
|
this.authorization = authorization;
|
|
34
36
|
this.messageCallback = null;
|
|
35
37
|
this.connection = undefined;
|
|
36
38
|
this.connected = false;
|
|
37
39
|
this.url = (options === null || options === void 0 ? void 0 : options.url) || "" || "wss://1x60p1o3h8.execute-api.us-east-1.amazonaws.com/production";
|
|
40
|
+
this.clientSourceId = clientSourceId;
|
|
38
41
|
this.clientKey = clientKey;
|
|
39
42
|
this.userSignature = userSignature;
|
|
40
43
|
this.subscriptions = [];
|
|
44
|
+
this.onReconnectionHandlers = [];
|
|
41
45
|
this.connectionTimeout = options === null || options === void 0 ? void 0 : options.connectionTimeout;
|
|
42
46
|
this.onError = options === null || options === void 0 ? void 0 : options.onError;
|
|
43
47
|
this.onClose = options === null || options === void 0 ? void 0 : options.onClose;
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
(0, _createClass2["default"])(WS, [{
|
|
51
|
+
key: "close",
|
|
52
|
+
value: function close() {
|
|
53
|
+
if (!this.connected || !this.connection) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.connection.close();
|
|
58
|
+
}
|
|
59
|
+
}, {
|
|
47
60
|
key: "connect",
|
|
48
61
|
value: function connect() {
|
|
49
62
|
this.connection = new _reconnectingWebsocket["default"]("".concat(this.url, "/?").concat(this.authorization ? "auth=".concat(this.authorization) : "clientKey=".concat(this.clientKey)), [], {
|
|
@@ -80,28 +93,46 @@ var WS = /*#__PURE__*/function () {
|
|
|
80
93
|
key: "_onOpen",
|
|
81
94
|
value: function _onOpen() {
|
|
82
95
|
this.connected = true;
|
|
96
|
+
this.connectionCount++;
|
|
83
97
|
|
|
84
|
-
|
|
85
|
-
|
|
98
|
+
if (this.connectionCount > 1) {
|
|
99
|
+
var _iterator = _createForOfIteratorHelper(this.onReconnectionHandlers),
|
|
100
|
+
_step;
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
104
|
+
var reconnectHandler = _step.value;
|
|
105
|
+
reconnectHandler.callback();
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
_iterator.e(err);
|
|
109
|
+
} finally {
|
|
110
|
+
_iterator.f();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
var _iterator2 = _createForOfIteratorHelper(this.subscriptions),
|
|
115
|
+
_step2;
|
|
86
116
|
|
|
87
117
|
try {
|
|
88
|
-
for (
|
|
89
|
-
var sub =
|
|
118
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
119
|
+
var sub = _step2.value;
|
|
90
120
|
this.send({
|
|
91
121
|
action: "subscribe",
|
|
92
122
|
data: {
|
|
93
|
-
version: "2",
|
|
94
123
|
channel: sub.channel,
|
|
95
|
-
|
|
124
|
+
clientSourceId: this.clientSourceId,
|
|
96
125
|
clientKey: this.clientKey,
|
|
97
|
-
|
|
126
|
+
event: sub.event,
|
|
127
|
+
userSignature: this.userSignature,
|
|
128
|
+
version: "3"
|
|
98
129
|
}
|
|
99
130
|
});
|
|
100
131
|
}
|
|
101
132
|
} catch (err) {
|
|
102
|
-
|
|
133
|
+
_iterator2.e(err);
|
|
103
134
|
} finally {
|
|
104
|
-
|
|
135
|
+
_iterator2.f();
|
|
105
136
|
}
|
|
106
137
|
}
|
|
107
138
|
}, {
|
|
@@ -122,27 +153,28 @@ var WS = /*#__PURE__*/function () {
|
|
|
122
153
|
return;
|
|
123
154
|
}
|
|
124
155
|
|
|
125
|
-
var
|
|
126
|
-
|
|
156
|
+
var _iterator3 = _createForOfIteratorHelper(this.subscriptions),
|
|
157
|
+
_step3;
|
|
127
158
|
|
|
128
159
|
try {
|
|
129
|
-
for (
|
|
130
|
-
var _message;
|
|
160
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
161
|
+
var _message, _message$type;
|
|
131
162
|
|
|
132
|
-
var sub =
|
|
163
|
+
var sub = _step3.value;
|
|
133
164
|
|
|
134
165
|
if (sub.event !== "*" && sub.event !== ((_message = message) === null || _message === void 0 ? void 0 : _message.event)) {
|
|
135
166
|
continue;
|
|
136
167
|
}
|
|
137
168
|
|
|
138
169
|
sub.callback({
|
|
170
|
+
type: (_message$type = message.type) !== null && _message$type !== void 0 ? _message$type : "message",
|
|
139
171
|
data: message
|
|
140
172
|
});
|
|
141
173
|
}
|
|
142
174
|
} catch (err) {
|
|
143
|
-
|
|
175
|
+
_iterator3.e(err);
|
|
144
176
|
} finally {
|
|
145
|
-
|
|
177
|
+
_iterator3.f();
|
|
146
178
|
}
|
|
147
179
|
}
|
|
148
180
|
}, {
|
|
@@ -163,11 +195,12 @@ var WS = /*#__PURE__*/function () {
|
|
|
163
195
|
this.send({
|
|
164
196
|
action: "subscribe",
|
|
165
197
|
data: {
|
|
166
|
-
version: "2",
|
|
167
198
|
channel: channel,
|
|
168
|
-
|
|
199
|
+
clientSourceId: this.clientSourceId,
|
|
169
200
|
clientKey: this.clientKey,
|
|
170
|
-
|
|
201
|
+
event: event,
|
|
202
|
+
userSignature: this.userSignature,
|
|
203
|
+
version: "3"
|
|
171
204
|
}
|
|
172
205
|
});
|
|
173
206
|
}
|
|
@@ -205,7 +238,7 @@ var WS = /*#__PURE__*/function () {
|
|
|
205
238
|
this.send({
|
|
206
239
|
action: "unsubscribe",
|
|
207
240
|
data: {
|
|
208
|
-
version: "
|
|
241
|
+
version: "3",
|
|
209
242
|
channel: channel,
|
|
210
243
|
event: event,
|
|
211
244
|
clientKey: this.clientKey,
|
|
@@ -215,21 +248,32 @@ var WS = /*#__PURE__*/function () {
|
|
|
215
248
|
}
|
|
216
249
|
}, {
|
|
217
250
|
key: "renewSession",
|
|
218
|
-
value: function renewSession(
|
|
251
|
+
value: function renewSession(newAuthorization) {
|
|
252
|
+
this.authorization = newAuthorization;
|
|
253
|
+
|
|
254
|
+
if (!this.connected || !this.connection) {
|
|
255
|
+
this.connect();
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
219
259
|
this.send({
|
|
220
260
|
action: "renewSession",
|
|
221
261
|
data: {
|
|
222
|
-
version: "
|
|
223
|
-
auth:
|
|
262
|
+
version: "3",
|
|
263
|
+
auth: newAuthorization
|
|
224
264
|
}
|
|
225
265
|
});
|
|
226
266
|
}
|
|
227
267
|
}, {
|
|
228
|
-
key: "
|
|
229
|
-
value: function
|
|
230
|
-
|
|
268
|
+
key: "onReconnection",
|
|
269
|
+
value: function onReconnection(handler) {
|
|
270
|
+
if (this.onReconnectionHandlers.find(function (h) {
|
|
271
|
+
return h.id === handler.id;
|
|
272
|
+
})) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
231
275
|
|
|
232
|
-
|
|
276
|
+
this.onReconnectionHandlers.push(handler);
|
|
233
277
|
}
|
|
234
278
|
}]);
|
|
235
279
|
return WS;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trycourier/react-provider",
|
|
3
|
-
"version": "1.52.
|
|
3
|
+
"version": "1.52.3-internal.400765e.0+400765e",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "typings/index.d.ts",
|
|
@@ -15,13 +15,14 @@
|
|
|
15
15
|
},
|
|
16
16
|
"license": "ISC",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@trycourier/client-graphql": "^1.52.
|
|
18
|
+
"@trycourier/client-graphql": "^1.52.3-internal.400765e.0+400765e",
|
|
19
19
|
"buffer": "^6.0.3",
|
|
20
20
|
"graphql": "^15.5.0",
|
|
21
21
|
"react-use": "^17.2.1",
|
|
22
22
|
"reconnecting-websocket": "^4.4.0",
|
|
23
23
|
"rimraf": "^3.0.2",
|
|
24
|
-
"urql": "^2.0.1"
|
|
24
|
+
"urql": "^2.0.1",
|
|
25
|
+
"uuid": "^9.0.0"
|
|
25
26
|
},
|
|
26
27
|
"peerDependencies": {
|
|
27
28
|
"react": "^17.0.1",
|
|
@@ -31,5 +32,5 @@
|
|
|
31
32
|
"dist/",
|
|
32
33
|
"typings/"
|
|
33
34
|
],
|
|
34
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "400765e73644f17e0eff3b7e5d7c595cca546e49"
|
|
35
36
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Brand } from "..";
|
|
2
|
-
import {
|
|
2
|
+
import { ICourierContext } from "~/types";
|
|
3
3
|
declare const useCourierActions: (state: any, dispatch: any) => {
|
|
4
|
-
init: (payload:
|
|
4
|
+
init: (payload: Partial<ICourierContext>) => Promise<void>;
|
|
5
5
|
initToast: (payload: any) => void;
|
|
6
6
|
initInbox: (payload: any) => void;
|
|
7
|
+
pageVisible: () => void;
|
|
8
|
+
wsReconnected: () => void;
|
|
7
9
|
getBrand: (brandId?: string | undefined) => void;
|
|
8
10
|
setBrand: (brand: Brand) => void;
|
|
9
11
|
createTrackEvent: (trackingId: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-courier-actions.d.ts","sourceRoot":"","sources":["../../src/hooks/use-courier-actions.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAC3B,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"use-courier-actions.d.ts","sourceRoot":"","sources":["../../src/hooks/use-courier-actions.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAC3B,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,QAAA,MAAM,iBAAiB;oBAeK,QAAQ,eAAe,CAAC;;;;;;sBAkC5B,KAAK;mCAMQ,MAAM;uCAMF,MAAM;CAc9C,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-page-visible.d.ts","sourceRoot":"","sources":["../../src/hooks/use-page-visible.ts"],"names":[],"mappings":"AAEA,wBAAgB,mBAAmB,YAElC;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,QAYpE"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Transport } from "~/transports";
|
|
2
|
-
declare const useCourierTransport: ({
|
|
3
|
-
transport: any;
|
|
2
|
+
declare const useCourierTransport: ({ authorization, clientSourceId, clientKey, transport, userSignature, wsOptions, }: {
|
|
4
3
|
authorization: any;
|
|
4
|
+
clientSourceId: any;
|
|
5
5
|
clientKey: any;
|
|
6
|
+
transport: any;
|
|
6
7
|
userSignature: any;
|
|
7
8
|
wsOptions: any;
|
|
8
9
|
}) => Transport;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-transport.d.ts","sourceRoot":"","sources":["../../src/hooks/use-transport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAoB,MAAM,cAAc,CAAC;AAE3D,QAAA,MAAM,mBAAmB
|
|
1
|
+
{"version":3,"file":"use-transport.d.ts","sourceRoot":"","sources":["../../src/hooks/use-transport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAoB,MAAM,cAAc,CAAC;AAE3D,QAAA,MAAM,mBAAmB;;;;;;;MAOrB,SAgBH,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
|
package/typings/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { Brand, ICourierContext, ICourierProviderProps, IMessage, WSOptions } from "./types";
|
|
3
3
|
import { ICourierMessage, ITextBlock, IActionBlock } from "./transports/types";
|
|
4
|
+
import { Middleware } from "./middleware";
|
|
4
5
|
export * from "./transports";
|
|
5
6
|
export * from "./hooks";
|
|
6
7
|
export declare const registerReducer: (scope: any, reducer: any) => void;
|
|
7
|
-
export
|
|
8
|
+
export declare const registerMiddleware: (id: string, middleware: Middleware) => void;
|
|
9
|
+
export type { Middleware, Brand, IActionBlock, ICourierContext, ICourierMessage, IMessage, ITextBlock, WSOptions, };
|
|
8
10
|
export declare const CourierContext: React.Context<ICourierContext | undefined>;
|
|
9
11
|
export declare const CourierProvider: React.FunctionComponent<ICourierProviderProps>;
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
package/typings/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAOA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAOA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAG/D,OAAO,EACL,KAAK,EACL,eAAe,EACf,qBAAqB,EACrB,QAAQ,EACR,SAAS,EACV,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAE/E,OAA0B,EAExB,UAAU,EACX,MAAM,cAAc,CAAC;AAKtB,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AAExB,eAAO,MAAM,eAAe,oCAAmB,CAAC;AAChD,eAAO,MAAM,kBAAkB,8CAAsB,CAAC;AAEtD,YAAY,EACV,UAAU,EACV,KAAK,EACL,YAAY,EACZ,eAAe,EACf,eAAe,EACf,QAAQ,EACR,UAAU,EACV,SAAS,GACV,CAAC;AAEF,eAAO,MAAM,cAAc,4CACkC,CAAC;AAE9D,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAC,qBAAqB,CA6KxE,CAAC"}
|
package/typings/middleware.d.ts
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
export interface Action {
|
|
2
|
+
type: any;
|
|
3
|
+
}
|
|
4
|
+
export interface Dispatch {
|
|
5
|
+
<A extends Action>(action: A): A;
|
|
6
|
+
}
|
|
7
|
+
export interface MiddlewareAPI<S> {
|
|
8
|
+
dispatch: Dispatch;
|
|
9
|
+
getState(): S;
|
|
10
|
+
}
|
|
11
|
+
export interface Middleware {
|
|
12
|
+
<S>(api: MiddlewareAPI<S>): (next: Dispatch) => Dispatch;
|
|
13
|
+
}
|
|
14
|
+
export declare const registerMiddleware: (id: string, middleware: Middleware) => void;
|
|
15
|
+
declare const _default: ((_store: any) => (next: any) => (action: any) => any)[];
|
|
2
16
|
export default _default;
|
|
3
17
|
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,GAAG,CAAC;CACX;AAED,MAAM,WAAW,QAAQ;IACvB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,IAAI,CAAC,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACzB,CAAC,CAAC,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,KAAK,QAAQ,CAAC;CAC1D;AAqCD,eAAO,MAAQ,kBAAkB,OAnBC,MAAM,cAAc,UAAU,SAmBA,CAAC;;AA6BjE,wBAAsE"}
|
package/typings/reducer.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { ICourierContext } from "./types";
|
|
1
2
|
export interface IAction {
|
|
2
3
|
type: "root/INIT";
|
|
3
4
|
payload: any;
|
|
4
5
|
}
|
|
5
6
|
export declare const registerReducer: (scope: any, reducer: any) => void;
|
|
6
|
-
declare const rootReducer: (state:
|
|
7
|
+
declare const rootReducer: (state: Partial<ICourierContext>, action: any) => any;
|
|
7
8
|
export default rootReducer;
|
|
8
9
|
//# sourceMappingURL=reducer.d.ts.map
|
package/typings/reducer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../src/reducer.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,GAAG,CAAC;CACd;AAGD,eAAO,MAAM,eAAe,oCAM3B,CAAC;AAEF,QAAA,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"reducer.d.ts","sourceRoot":"","sources":["../src/reducer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,GAAG,CAAC;CACd;AAGD,eAAO,MAAM,eAAe,oCAM3B,CAAC;AAEF,QAAA,MAAM,WAAW,UAAW,QAAQ,eAAe,CAAC,qBAyCnD,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { ICourierEvent, Interceptor } from "./types";
|
|
2
|
+
declare enum ListenerType {
|
|
3
|
+
message = "message",
|
|
4
|
+
event = "event"
|
|
5
|
+
}
|
|
2
6
|
export declare class Transport {
|
|
3
7
|
constructor();
|
|
4
8
|
/** Callback for emitted events */
|
|
5
|
-
protected listeners:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
protected listeners: {
|
|
10
|
+
[key in ListenerType]: Array<{
|
|
11
|
+
id: string;
|
|
12
|
+
listener: (courierEvent: ICourierEvent) => void;
|
|
13
|
+
}>;
|
|
14
|
+
};
|
|
9
15
|
protected interceptor?: Interceptor;
|
|
10
16
|
/** Wrapper method for emitted events */
|
|
11
17
|
protected emit: (courierEvent: ICourierEvent) => void;
|
|
12
18
|
/** Setter method for a listener */
|
|
13
19
|
listen: (listener: {
|
|
14
20
|
id: string;
|
|
21
|
+
type?: "message" | "event" | undefined;
|
|
15
22
|
listener: (courierEvent: ICourierEvent) => void;
|
|
16
23
|
}) => void;
|
|
17
24
|
intercept: (cb: Interceptor) => void;
|
|
18
25
|
}
|
|
26
|
+
export {};
|
|
19
27
|
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/transports/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAErD,qBAAa,SAAS;;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/transports/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAErD,aAAK,YAAY;IACf,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AACD,qBAAa,SAAS;;IASpB,mCAAmC;IACnC,SAAS,CAAC,SAAS,EAAE;SAClB,GAAG,IAAI,YAAY,GAAG,KAAK,CAAC;YAC3B,EAAE,EAAE,MAAM,CAAC;YACX,QAAQ,EAAE,CAAC,YAAY,EAAE,aAAa,KAAK,IAAI,CAAC;SACjD,CAAC;KACH,CAAC;IAEF,SAAS,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC;IACpC,yCAAyC;IACzC,SAAS,CAAC,IAAI,iBAAkB,aAAa,KAAG,IAAI,CAYlD;IAEF,mCAAmC;IACnC,MAAM;YACA,MAAM;;iCAEe,aAAa,KAAK,IAAI;UAC7C,IAAI,CAoBN;IAEF,SAAS,OAAQ,WAAW,KAAG,IAAI,CAEjC;CACH"}
|
|
@@ -3,15 +3,22 @@ import { Transport } from "../base";
|
|
|
3
3
|
import { Interceptor, ICourierMessage } from "../types";
|
|
4
4
|
import { ITransportOptions } from "./types";
|
|
5
5
|
export declare class CourierTransport extends Transport {
|
|
6
|
-
protected ws: WS;
|
|
7
6
|
protected authorization?: string;
|
|
7
|
+
protected clientSourceId: string;
|
|
8
8
|
protected clientKey?: string;
|
|
9
|
-
protected userSignature?: string;
|
|
10
9
|
protected interceptor?: Interceptor;
|
|
10
|
+
protected userSignature?: string;
|
|
11
|
+
protected ws: WS;
|
|
11
12
|
constructor(options: ITransportOptions);
|
|
13
|
+
closeConnection(): void;
|
|
14
|
+
connect(): void;
|
|
12
15
|
send(message: ICourierMessage): void;
|
|
13
16
|
subscribe(channel: string, event?: string): void;
|
|
14
17
|
unsubscribe(channel: string, event?: string): void;
|
|
18
|
+
onReconnection(handler: {
|
|
19
|
+
id: string;
|
|
20
|
+
callback: () => void;
|
|
21
|
+
}): void;
|
|
15
22
|
renewSession(token: string): void;
|
|
16
23
|
}
|
|
17
24
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transports/courier/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C,qBAAa,gBAAiB,SAAQ,SAAS;IAC7C,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transports/courier/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAE5C,qBAAa,gBAAiB,SAAQ,SAAS;IAC7C,SAAS,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IACjC,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC;IACjC,SAAS,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC7B,UAAkB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC5C,SAAS,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IACjC,SAAS,CAAC,EAAE,EAAE,EAAE,CAAC;gBAEL,OAAO,EAAE,iBAAiB;IAsBtC,eAAe,IAAI,IAAI;IAIvB,OAAO,IAAI,IAAI;IAIf,IAAI,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAUpC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;IAchD,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI;IAIlD,cAAc,CAAC,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,IAAI,CAAA;KAAE,GAAG,IAAI;IAInE,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAGlC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/transports/courier/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE;QACV,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;KACvC,CAAC;CACH"}
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/transports/courier/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE;QACV,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;KACvC,CAAC;CACH"}
|
|
@@ -11,6 +11,7 @@ export interface IActionBlock {
|
|
|
11
11
|
}
|
|
12
12
|
export interface ICourierMessage {
|
|
13
13
|
event?: string;
|
|
14
|
+
type?: "message" | "event";
|
|
14
15
|
error?: string;
|
|
15
16
|
messageId?: string;
|
|
16
17
|
body?: string;
|
|
@@ -35,9 +36,9 @@ export interface ICourierMessage {
|
|
|
35
36
|
brand?: Brand;
|
|
36
37
|
}
|
|
37
38
|
export interface ICourierEvent {
|
|
38
|
-
type?: "message";
|
|
39
|
+
type?: "message" | "event";
|
|
39
40
|
data?: ICourierMessage;
|
|
40
41
|
}
|
|
41
|
-
export declare type ICourierEventCallback = (
|
|
42
|
+
export declare type ICourierEventCallback = (event: ICourierEvent) => void;
|
|
42
43
|
export declare type Interceptor = (message?: ICourierMessage) => ICourierMessage | undefined;
|
|
43
44
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/transports/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AACD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;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;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,KAAK,CAAC,UAAU,GAAG,YAAY,CAAC,CAAC;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE;YACZ,iBAAiB,EAAE,MAAM,CAAC;YAC1B,iBAAiB,EAAE,MAAM,CAAC;YAC1B,eAAe,EAAE,MAAM,CAAC;YACxB,iBAAiB,EAAE,MAAM,CAAC;YAC1B,cAAc,EAAE,MAAM,CAAC;YACvB,cAAc,EAAE,MAAM,CAAC;YACvB,gBAAgB,EAAE,MAAM,CAAC;SAC1B,CAAC;QACF,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;IACF,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IAC3B,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB;AAED,oBAAY,qBAAqB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;AAEnE,oBAAY,WAAW,GAAG,CACxB,OAAO,CAAC,EAAE,eAAe,KACtB,eAAe,GAAG,SAAS,CAAC"}
|
package/typings/types.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export interface Brand {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
export interface ICourierProviderProps {
|
|
62
|
+
id?: string;
|
|
62
63
|
apiUrl?: string;
|
|
63
64
|
authorization?: string;
|
|
64
65
|
brand?: Brand;
|
|
@@ -68,8 +69,6 @@ export interface ICourierProviderProps {
|
|
|
68
69
|
localStorage?: Storage;
|
|
69
70
|
onMessage?: Interceptor;
|
|
70
71
|
transport?: Transport;
|
|
71
|
-
/** Set to true to disable websockets */
|
|
72
|
-
disableTransport?: boolean;
|
|
73
72
|
userId?: string;
|
|
74
73
|
userSignature?: string;
|
|
75
74
|
wsOptions?: WSOptions;
|
|
@@ -80,6 +79,6 @@ export interface ICourierContext extends ICourierProviderProps {
|
|
|
80
79
|
payload?: any;
|
|
81
80
|
meta?: any;
|
|
82
81
|
}) => void;
|
|
83
|
-
|
|
82
|
+
clientSourceId: string;
|
|
84
83
|
}
|
|
85
84
|
//# sourceMappingURL=types.d.ts.map
|
package/typings/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,oBAAY,iBAAiB,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;AAE5D,MAAM,WAAW,QAAQ;IACvB,MAAM,CAAC,EAAE,KAAK,CAAC,YAAY,GAAG,UAAU,CAAC,CAAC;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE;QACL,WAAW,CAAC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ChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB;AACD,MAAM,WAAW,eAAgB,SAAQ,qBAAqB;IAC5D,QAAQ,EAAE,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,GAAG,CAAC;QAAC,IAAI,CAAC,EAAE,GAAG,CAAA;KAAE,KAAK,IAAI,CAAC;IACxE,cAAc,EAAE,MAAM,CAAC;CACxB"}
|
package/typings/ws.d.ts
CHANGED
|
@@ -1,37 +1,43 @@
|
|
|
1
1
|
import { ICourierEventCallback } from "./transports/types";
|
|
2
|
-
import ReconnectingWebSocket
|
|
2
|
+
import ReconnectingWebSocket from "reconnecting-websocket";
|
|
3
3
|
import { WSOptions } from "./types";
|
|
4
4
|
export declare class WS {
|
|
5
5
|
connection?: ReconnectingWebSocket;
|
|
6
6
|
private subscriptions;
|
|
7
|
+
private clientSourceId?;
|
|
7
8
|
private authorization?;
|
|
8
9
|
private clientKey?;
|
|
9
10
|
private connectionTimeout?;
|
|
10
11
|
private onError?;
|
|
11
12
|
private onClose?;
|
|
13
|
+
private onReconnectionHandlers;
|
|
12
14
|
private url;
|
|
13
15
|
private userSignature?;
|
|
16
|
+
private connectionCount;
|
|
14
17
|
protected connected: any;
|
|
15
18
|
protected messageCallback: any;
|
|
16
|
-
constructor({ authorization, clientKey, options, userSignature, }: {
|
|
19
|
+
constructor({ authorization, clientKey, options, clientSourceId, userSignature, }: {
|
|
17
20
|
authorization?: string;
|
|
21
|
+
clientSourceId?: string;
|
|
18
22
|
clientKey?: string;
|
|
19
23
|
options?: WSOptions;
|
|
20
24
|
userSignature?: string;
|
|
21
25
|
});
|
|
26
|
+
close(): void;
|
|
22
27
|
connect(): void;
|
|
23
|
-
_onError
|
|
24
|
-
_onClose
|
|
25
|
-
_onOpen
|
|
26
|
-
_onMessage
|
|
27
|
-
data: string;
|
|
28
|
-
}): void;
|
|
28
|
+
private _onError;
|
|
29
|
+
private _onClose;
|
|
30
|
+
private _onOpen;
|
|
31
|
+
private _onMessage;
|
|
29
32
|
subscribe(channel: string, event: string, callback: ICourierEventCallback): Promise<void>;
|
|
30
33
|
send(message: {
|
|
31
34
|
[key: string]: any;
|
|
32
35
|
}): void;
|
|
33
36
|
unsubscribe(channel: string, event: string): void;
|
|
34
|
-
renewSession(
|
|
35
|
-
|
|
37
|
+
renewSession(newAuthorization: string): void;
|
|
38
|
+
onReconnection(handler: {
|
|
39
|
+
id: string;
|
|
40
|
+
callback: () => void;
|
|
41
|
+
}): void;
|
|
36
42
|
}
|
|
37
43
|
//# sourceMappingURL=ws.d.ts.map
|
package/typings/ws.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAmB,MAAM,oBAAoB,CAAC;AAC5E,OAAO,
|
|
1
|
+
{"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAmB,MAAM,oBAAoB,CAAC;AAC5E,OAAO,qBAAqC,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAqB,SAAS,EAAE,MAAM,SAAS,CAAC;AAEvD,qBAAa,EAAE;IACb,UAAU,CAAC,EAAE,qBAAqB,CAAC;IACnC,OAAO,CAAC,aAA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