@trycourier/react-provider 1.30.2-internal.c2224c8.0 → 1.32.2-internal.1062b41.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.
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
8
  exports["default"] = void 0;
7
9
 
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+
12
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
+
8
14
  var _react = require("react");
9
15
 
10
16
  var _clientGraphql = require("@trycourier/client-graphql");
@@ -17,6 +23,9 @@ var useCourierActions = function useCourierActions(state, dispatch) {
17
23
  userId: state.userId,
18
24
  userSignature: state.userSignature
19
25
  });
26
+ var initialState = (0, _clientGraphql.InitialState)({
27
+ client: courierClient
28
+ });
20
29
  var brands = (0, _clientGraphql.Brands)({
21
30
  client: courierClient
22
31
  });
@@ -24,12 +33,52 @@ var useCourierActions = function useCourierActions(state, dispatch) {
24
33
  client: courierClient
25
34
  });
26
35
  return {
27
- init: function init(payload) {
28
- dispatch({
29
- type: "root/INIT",
30
- payload: payload
31
- });
32
- },
36
+ init: function () {
37
+ var _init = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(payload) {
38
+ var response;
39
+ return _regenerator["default"].wrap(function _callee$(_context) {
40
+ while (1) {
41
+ switch (_context.prev = _context.next) {
42
+ case 0:
43
+ dispatch({
44
+ type: "root/INIT",
45
+ payload: payload
46
+ });
47
+ _context.next = 3;
48
+ return initialState.getInitialState({
49
+ brandId: payload.brandId,
50
+ skipFetchBrand: Boolean(payload.brand)
51
+ });
52
+
53
+ case 3:
54
+ response = _context.sent;
55
+
56
+ if (response !== null && response !== void 0 && response.brand) {
57
+ dispatch({
58
+ type: "root/GET_BRAND/DONE",
59
+ payload: response.brand
60
+ });
61
+ }
62
+
63
+ dispatch({
64
+ type: "inbox/FETCH_UNREAD_MESSAGE_COUNT/DONE",
65
+ payload: response === null || response === void 0 ? void 0 : response.unreadMessageCount
66
+ });
67
+
68
+ case 6:
69
+ case "end":
70
+ return _context.stop();
71
+ }
72
+ }
73
+ }, _callee);
74
+ }));
75
+
76
+ function init(_x) {
77
+ return _init.apply(this, arguments);
78
+ }
79
+
80
+ return init;
81
+ }(),
33
82
  initToast: function initToast(payload) {
34
83
  dispatch({
35
84
  type: "toast/INIT",
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ var _courier = require("../transports/courier");
11
+
12
+ var useCourierTransport = function useCourierTransport(_ref) {
13
+ var transport = _ref.transport,
14
+ clientKey = _ref.clientKey,
15
+ userSignature = _ref.userSignature,
16
+ wsOptions = _ref.wsOptions;
17
+ return (0, _react.useMemo)(function () {
18
+ if (transport) {
19
+ return transport;
20
+ }
21
+
22
+ if (clientKey && !transport) {
23
+ return new _courier.CourierTransport({
24
+ userSignature: userSignature,
25
+ clientKey: clientKey,
26
+ wsOptions: wsOptions
27
+ });
28
+ }
29
+ }, [transport, clientKey, wsOptions, userSignature]);
30
+ };
31
+
32
+ var _default = useCourierTransport;
33
+ exports["default"] = _default;
package/dist/index.js CHANGED
@@ -24,14 +24,14 @@ var _react = _interopRequireWildcard(require("react"));
24
24
 
25
25
  var _createReducer = _interopRequireDefault(require("react-use/lib/factory/createReducer"));
26
26
 
27
- var _courier = require("./transports/courier");
28
-
29
27
  var _reducer = _interopRequireWildcard(require("./reducer"));
30
28
 
31
29
  var _middleware2 = _interopRequireDefault(require("./middleware"));
32
30
 
33
31
  var _useCourierActions = _interopRequireDefault(require("./hooks/use-courier-actions"));
34
32
 
33
+ var _useTransport = _interopRequireDefault(require("./hooks/use-transport"));
34
+
35
35
  var _transports = require("./transports");
36
36
 
37
37
  Object.keys(_transports).forEach(function (key) {
@@ -100,19 +100,12 @@ var CourierProvider = function CourierProvider(_ref) {
100
100
 
101
101
  var middleware = [].concat((0, _toConsumableArray2["default"])(_middleware), (0, _toConsumableArray2["default"])(_middleware2["default"]));
102
102
  var useReducer = (0, _react.useCallback)(_createReducer["default"].apply(void 0, (0, _toConsumableArray2["default"])(middleware)), [_middleware]);
103
- var transport = (0, _react.useMemo)(function () {
104
- if (_transport) {
105
- return _transport;
106
- }
107
-
108
- if (clientKey && !_transport) {
109
- return new _courier.CourierTransport({
110
- userSignature: userSignature,
111
- clientKey: clientKey,
112
- wsOptions: wsOptions
113
- });
114
- }
115
- }, [_transport, clientKey, wsOptions, userSignature]);
103
+ var transport = (0, _useTransport["default"])({
104
+ transport: _transport,
105
+ userSignature: userSignature,
106
+ clientKey: clientKey,
107
+ wsOptions: wsOptions
108
+ });
116
109
 
117
110
  var _useReducer = useReducer(_reducer["default"], {
118
111
  apiUrl: apiUrl,
@@ -177,19 +170,7 @@ var CourierProvider = function CourierProvider(_ref) {
177
170
  userId: userId,
178
171
  userSignature: userSignature
179
172
  });
180
- }, [actions, apiUrl, clientKey, transport, userId, userSignature, brandId]);
181
- (0, _react.useEffect)(function () {
182
- if (brand) {
183
- // if we pass in brand, don't fetch it
184
- return;
185
- }
186
-
187
- if (!clientKey || !userId) {
188
- return;
189
- }
190
-
191
- actions.getBrand(brandId);
192
- }, [actions, brand, brandId, clientKey, userId]);
173
+ }, [actions, apiUrl, brandId, clientKey, transport, userId, userSignature]);
193
174
  (0, _react.useEffect)(function () {
194
175
  if (!state.brand || !clientKey || !userId) {
195
176
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/react-provider",
3
- "version": "1.30.2-internal.c2224c8.0+c2224c8",
3
+ "version": "1.32.2-internal.1062b41.0+1062b41",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "typings/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@trycourier/client-graphql": "^1.30.2-internal.c2224c8.0+c2224c8",
18
+ "@trycourier/client-graphql": "^1.32.2-internal.1062b41.0+1062b41",
19
19
  "buffer": "^6.0.3",
20
20
  "graphql": "^15.5.0",
21
21
  "localstorage-polyfill": "^1.0.1",
@@ -32,5 +32,5 @@
32
32
  "dist/",
33
33
  "typings/"
34
34
  ],
35
- "gitHead": "c2224c89e0c73e65c59e2668b79d060b685200e8"
35
+ "gitHead": "1062b414a363f62d2f48c7d24765bd8c3fbd2897"
36
36
  }
@@ -1,11 +1,13 @@
1
+ import { Brand } from "..";
2
+ import { ICourierProviderProps } from "~/types";
1
3
  declare const useCourierActions: (state: any, dispatch: any) => {
2
- init: (payload: any) => void;
4
+ init: (payload: ICourierProviderProps) => Promise<void>;
3
5
  initToast: (payload: any) => void;
4
6
  initInbox: (payload: any) => void;
5
- getBrand: (brandId: any) => void;
6
- setBrand: (brand: any) => void;
7
- createTrackEvent: (trackingId: any) => void;
8
- createBatchTrackEvent: (eventType: any) => void;
7
+ getBrand: (brandId?: string | undefined) => void;
8
+ setBrand: (brand: Brand) => void;
9
+ createTrackEvent: (trackingId: string) => void;
10
+ createBatchTrackEvent: (eventType: string) => void;
9
11
  };
10
12
  export default useCourierActions;
11
13
  //# sourceMappingURL=use-courier-actions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-courier-actions.d.ts","sourceRoot":"","sources":["../../src/hooks/use-courier-actions.ts"],"names":[],"mappings":"AAQA,QAAA,MAAM,iBAAiB;;;;;;;;CAyDtB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"use-courier-actions.d.ts","sourceRoot":"","sources":["../../src/hooks/use-courier-actions.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,EAAE,MAAM,IAAI,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEhD,QAAA,MAAM,iBAAiB;oBAcK,qBAAqB;;;;sBAyCzB,KAAK;mCAMQ,MAAM;uCAMF,MAAM;CAQ9C,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -0,0 +1,8 @@
1
+ declare const useCourierTransport: ({ transport, clientKey, userSignature, wsOptions, }: {
2
+ transport: any;
3
+ clientKey: any;
4
+ userSignature: any;
5
+ wsOptions: any;
6
+ }) => any;
7
+ export default useCourierTransport;
8
+ //# sourceMappingURL=use-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-transport.d.ts","sourceRoot":"","sources":["../../src/hooks/use-transport.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,mBAAmB;;;;;SAmBxB,CAAC;AAEF,eAAe,mBAAmB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAWA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAE/D,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,KAAK,EACL,SAAS,EACV,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAI/E,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AAExB,eAAO,MAAM,eAAe,oCAAmB,CAAC;AAEhD,YAAY,EACV,KAAK,EACL,SAAS,EACT,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,GAChB,CAAC;AAEF,eAAO,MAAM,cAAc,4CACkC,CAAC;AAE9D,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAC,qBAAqB,CAwJxE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAiC,MAAM,OAAO,CAAC;AAEtD,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,KAAK,EACL,SAAS,EACV,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAM/E,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AAExB,eAAO,MAAM,eAAe,oCAAmB,CAAC;AAEhD,YAAY,EACV,KAAK,EACL,SAAS,EACT,UAAU,EACV,YAAY,EACZ,eAAe,EACf,eAAe,GAChB,CAAC;AAEF,eAAO,MAAM,cAAc,4CACkC,CAAC;AAE9D,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAC,qBAAqB,CAoIxE,CAAC"}