@trycourier/react-provider 1.9.2-internal.776d32d.0 → 1.10.1

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.
@@ -5,10 +5,28 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports["default"] = void 0;
7
7
 
8
- var _trackEvent = require("../actions/track-event");
8
+ var _clientGraphql = require("@trycourier/client-graphql");
9
9
 
10
- var useCourierActions = function useCourierActions(dispatch) {
10
+ var useCourierActions = function useCourierActions(state, dispatch) {
11
+ var courierClient = (0, _clientGraphql.createCourierClient)({
12
+ apiUrl: state.apiUrl,
13
+ clientKey: state.clientKey,
14
+ userId: state.userId,
15
+ userSignature: state.userSignature
16
+ });
17
+ var brands = (0, _clientGraphql.Brands)({
18
+ client: courierClient
19
+ });
20
+ var events = (0, _clientGraphql.Events)({
21
+ client: courierClient
22
+ });
11
23
  return {
24
+ init: function init(payload) {
25
+ dispatch({
26
+ type: "root/INIT",
27
+ payload: payload
28
+ });
29
+ },
12
30
  initToast: function initToast(payload) {
13
31
  dispatch({
14
32
  type: "toast/INIT",
@@ -21,19 +39,33 @@ var useCourierActions = function useCourierActions(dispatch) {
21
39
  payload: payload
22
40
  });
23
41
  },
42
+ getBrand: function getBrand(brandId) {
43
+ dispatch({
44
+ type: "root/GET_BRAND",
45
+ payload: function payload() {
46
+ return brands.getBrand(brandId);
47
+ }
48
+ });
49
+ },
50
+ setBrand: function setBrand(brand) {
51
+ dispatch({
52
+ type: "root/GET_BRAND/DONE",
53
+ payload: brand
54
+ });
55
+ },
24
56
  createTrackEvent: function createTrackEvent(trackingId) {
25
57
  dispatch({
26
58
  type: "CREATE_TRACKING_EVENT",
27
- payload: function payload(_, getState) {
28
- return (0, _trackEvent.updateTrackEvent)(getState().graphQLClient, trackingId);
59
+ payload: function payload() {
60
+ return events.trackEvent(trackingId);
29
61
  }
30
62
  });
31
63
  },
32
64
  createBatchTrackEvent: function createBatchTrackEvent(eventType) {
33
65
  dispatch({
34
66
  type: "CREATE_TRACKING_EVENT_BATCH",
35
- payload: function payload(_, getState) {
36
- return (0, _trackEvent.updateTrackEventBatch)(getState().graphQLClient, eventType);
67
+ payload: function payload() {
68
+ return events.trackEventBatch(eventType);
37
69
  }
38
70
  });
39
71
  }
package/dist/index.js CHANGED
@@ -24,16 +24,12 @@ var _react = _interopRequireWildcard(require("react"));
24
24
 
25
25
  var _createReducer = _interopRequireDefault(require("react-use/lib/factory/createReducer"));
26
26
 
27
- var _graphQl = _interopRequireDefault(require("./graph-ql"));
28
-
29
27
  var _courier = require("./transports/courier");
30
28
 
31
29
  var _reducer = _interopRequireWildcard(require("./reducer"));
32
30
 
33
31
  var _middleware2 = _interopRequireDefault(require("./middleware"));
34
32
 
35
- var _brand2 = require("./actions/brand");
36
-
37
33
  var _useCourierActions = _interopRequireDefault(require("./hooks/use-courier-actions"));
38
34
 
39
35
  var _transports = require("./transports");
@@ -98,14 +94,6 @@ var CourierProvider = function CourierProvider(_ref) {
98
94
 
99
95
  var middleware = [].concat((0, _toConsumableArray2["default"])(_middleware), (0, _toConsumableArray2["default"])(_middleware2["default"]));
100
96
  var useReducer = (0, _react.useCallback)(_createReducer["default"].apply(void 0, (0, _toConsumableArray2["default"])(middleware)), [_middleware]);
101
- var graphQLClient = (0, _react.useMemo)(function () {
102
- return new _graphQl["default"]({
103
- clientKey: clientKey,
104
- userId: userId,
105
- userSignature: userSignature,
106
- apiUrl: apiUrl
107
- });
108
- }, [clientKey, userId, userSignature, apiUrl]);
109
97
  var transport = (0, _react.useMemo)(function () {
110
98
  if (_transport) {
111
99
  return _transport;
@@ -124,7 +112,6 @@ var CourierProvider = function CourierProvider(_ref) {
124
112
  apiUrl: apiUrl,
125
113
  brand: brand,
126
114
  brandId: brandId,
127
- graphQLClient: graphQLClient,
128
115
  clientKey: clientKey,
129
116
  transport: transport,
130
117
  userId: userId,
@@ -135,7 +122,7 @@ var CourierProvider = function CourierProvider(_ref) {
135
122
  state = _useReducer2[0],
136
123
  dispatch = _useReducer2[1];
137
124
 
138
- var actions = (0, _useCourierActions["default"])(dispatch);
125
+ var actions = (0, _useCourierActions["default"])(state, dispatch);
139
126
  (0, _react.useEffect)(function () {
140
127
  if (_transport) {
141
128
  // this means the transport was passed in and we shouldn't subscribe
@@ -176,36 +163,23 @@ var CourierProvider = function CourierProvider(_ref) {
176
163
  return;
177
164
  }
178
165
 
179
- dispatch({
180
- type: "root/INIT",
181
- payload: {
182
- apiUrl: apiUrl,
183
- brandId: brandId,
184
- graphQLClient: graphQLClient,
185
- clientKey: clientKey,
186
- transport: transport,
187
- userId: userId,
188
- userSignature: userSignature
189
- }
166
+ actions.init({
167
+ apiUrl: apiUrl,
168
+ brandId: brandId,
169
+ clientKey: clientKey,
170
+ transport: transport,
171
+ userId: userId,
172
+ userSignature: userSignature
190
173
  });
191
- }, [apiUrl, graphQLClient, clientKey, transport, userId, userSignature, brandId]);
174
+ }, [apiUrl, clientKey, transport, userId, userSignature, brandId]);
192
175
  (0, _react.useEffect)(function () {
193
176
  if (brand) {
194
177
  // if we pass in brand, don't fetch it
195
178
  return;
196
179
  }
197
180
 
198
- if (!graphQLClient.client) {
199
- return;
200
- }
201
-
202
- dispatch({
203
- type: "root/GET_BRAND",
204
- payload: function payload() {
205
- return (0, _brand2.getBrand)(graphQLClient, brandId);
206
- }
207
- });
208
- }, [graphQLClient, brand, brandId]);
181
+ actions.getBrand(brandId);
182
+ }, [brand, brandId]);
209
183
  (0, _react.useEffect)(function () {
210
184
  if (!state.brand || !clientKey || !userId) {
211
185
  return;
@@ -227,10 +201,7 @@ var CourierProvider = function CourierProvider(_ref) {
227
201
  var _JSON$parse = JSON.parse(localStorageState),
228
202
  _brand = _JSON$parse.brand;
229
203
 
230
- dispatch({
231
- type: "root/GET_BRAND/DONE",
232
- payload: _brand
233
- });
204
+ actions.setBrand(_brand);
234
205
  } catch (ex) {
235
206
  console.log("error", ex);
236
207
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trycourier/react-provider",
3
- "version": "1.9.2-internal.776d32d.0+776d32d",
3
+ "version": "1.10.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "typings/index.d.ts",
@@ -16,6 +16,7 @@
16
16
  },
17
17
  "license": "ISC",
18
18
  "dependencies": {
19
+ "@trycourier/client-graphql": "^1.10.1",
19
20
  "buffer": "^6.0.3",
20
21
  "graphql": "^15.5.0",
21
22
  "react-use": "^17.2.1",
@@ -31,5 +32,5 @@
31
32
  "dist/",
32
33
  "typings/"
33
34
  ],
34
- "gitHead": "776d32db0ced6569ccd6ca04864501cd9e4099cf"
35
+ "gitHead": "69cfbf44f074d5b7c9a630eb82ac7491801bb9e7"
35
36
  }
@@ -1,6 +1,9 @@
1
- declare const useCourierActions: (dispatch: any) => {
1
+ declare const useCourierActions: (state: any, dispatch: any) => {
2
+ init: (payload: any) => void;
2
3
  initToast: (payload: any) => void;
3
4
  initInbox: (payload: any) => void;
5
+ getBrand: (brandId: any) => void;
6
+ setBrand: (brand: any) => void;
4
7
  createTrackEvent: (trackingId: any) => void;
5
8
  createBatchTrackEvent: (eventType: any) => void;
6
9
  };
@@ -1 +1 @@
1
- {"version":3,"file":"use-courier-actions.d.ts","sourceRoot":"","sources":["../../src/hooks/use-courier-actions.ts"],"names":[],"mappings":"AAEA,QAAA,MAAM,iBAAiB;;;;;CA6BtB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"use-courier-actions.d.ts","sourceRoot":"","sources":["../../src/hooks/use-courier-actions.ts"],"names":[],"mappings":"AAMA,QAAA,MAAM,iBAAiB;;;;;;;;CAuDtB,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAOA,OAAO,KAA0C,MAAM,OAAO,CAAC;AAG/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;AAK/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,4CAE1B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAC,qBAAqB,CA6K1E,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAOA,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,4CAE1B,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,iBAAiB,CAAC,qBAAqB,CAmJ1E,CAAC"}
@@ -1,75 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.getBrand = void 0;
9
-
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
- var brandProps = "\nsettings {\n colors {\n primary\n secondary\n tertiary\n }\n inapp {\n borderRadius\n disableMessageIcon\n disableCourierFooter\n placement\n emptyState {\n textColor\n text\n }\n widgetBackground {\n topColor\n bottomColor\n }\n colors {\n invertHeader\n invertButtons\n }\n icons {\n bell\n message\n }\n toast {\n timerAutoClose\n borderRadius\n }\n }\n}\npreferenceTemplates {\n nodes {\n defaultStatus\n templateName\n templateId\n }\n}\n";
15
- var GET_BRAND = "\nquery GetBrand($brandId: String!) {\n brand(brandId: $brandId) {\n ".concat(brandProps, "\n }\n}\n");
16
- var GET_INAPP_BRAND = "\nquery GetInAppBrand {\n inAppBrand {\n ".concat(brandProps, "\n }\n}\n");
17
-
18
- var getBrand = /*#__PURE__*/function () {
19
- var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(client, brandId) {
20
- var _results$data, _brand$settings, _brand$settings2, _brand$preferenceTemp;
21
-
22
- var results, brandProp, brand, colors, inapp, preferenceTemplates;
23
- return _regenerator["default"].wrap(function _callee$(_context) {
24
- while (1) {
25
- switch (_context.prev = _context.next) {
26
- case 0:
27
- if (!brandId) {
28
- _context.next = 6;
29
- break;
30
- }
31
-
32
- _context.next = 3;
33
- return client.query(GET_BRAND, {
34
- brandId: brandId
35
- });
36
-
37
- case 3:
38
- _context.t0 = _context.sent;
39
- _context.next = 9;
40
- break;
41
-
42
- case 6:
43
- _context.next = 8;
44
- return client.query(GET_INAPP_BRAND);
45
-
46
- case 8:
47
- _context.t0 = _context.sent;
48
-
49
- case 9:
50
- results = _context.t0;
51
- brandProp = brandId ? "brand" : "inAppBrand";
52
- brand = results === null || results === void 0 ? void 0 : (_results$data = results.data) === null || _results$data === void 0 ? void 0 : _results$data[brandProp];
53
- colors = brand === null || brand === void 0 ? void 0 : (_brand$settings = brand.settings) === null || _brand$settings === void 0 ? void 0 : _brand$settings.colors;
54
- inapp = brand === null || brand === void 0 ? void 0 : (_brand$settings2 = brand.settings) === null || _brand$settings2 === void 0 ? void 0 : _brand$settings2.inapp;
55
- preferenceTemplates = brand === null || brand === void 0 ? void 0 : (_brand$preferenceTemp = brand.preferenceTemplates) === null || _brand$preferenceTemp === void 0 ? void 0 : _brand$preferenceTemp.nodes;
56
- return _context.abrupt("return", {
57
- colors: colors,
58
- inapp: inapp,
59
- preferenceTemplates: preferenceTemplates
60
- });
61
-
62
- case 16:
63
- case "end":
64
- return _context.stop();
65
- }
66
- }
67
- }, _callee);
68
- }));
69
-
70
- return function getBrand(_x, _x2) {
71
- return _ref.apply(this, arguments);
72
- };
73
- }();
74
-
75
- exports.getBrand = getBrand;
@@ -1,67 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.updateTrackEventBatch = exports.updateTrackEvent = void 0;
9
-
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
13
-
14
- var UPDATE_TRACK_EVENT = "\n mutation TrackEvent($trackingId: String!) {\n trackEvent(trackingId: $trackingId) {\n id\n }\n }\n";
15
- var UPDATE_TRACK_EVENT_BATCH = "\n mutation BatchTrackEvent($eventType: String!) {\n batchTrackEvent(eventType: $eventType) {\n ids\n }\n }\n";
16
-
17
- var updateTrackEvent = /*#__PURE__*/function () {
18
- var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(client, trackingId) {
19
- return _regenerator["default"].wrap(function _callee$(_context) {
20
- while (1) {
21
- switch (_context.prev = _context.next) {
22
- case 0:
23
- _context.next = 2;
24
- return client.mutate(UPDATE_TRACK_EVENT, {
25
- trackingId: trackingId
26
- });
27
-
28
- case 2:
29
- case "end":
30
- return _context.stop();
31
- }
32
- }
33
- }, _callee);
34
- }));
35
-
36
- return function updateTrackEvent(_x, _x2) {
37
- return _ref.apply(this, arguments);
38
- };
39
- }();
40
-
41
- exports.updateTrackEvent = updateTrackEvent;
42
-
43
- var updateTrackEventBatch = /*#__PURE__*/function () {
44
- var _ref2 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(client, eventType) {
45
- return _regenerator["default"].wrap(function _callee2$(_context2) {
46
- while (1) {
47
- switch (_context2.prev = _context2.next) {
48
- case 0:
49
- _context2.next = 2;
50
- return client.mutate(UPDATE_TRACK_EVENT_BATCH, {
51
- eventType: eventType
52
- });
53
-
54
- case 2:
55
- case "end":
56
- return _context2.stop();
57
- }
58
- }
59
- }, _callee2);
60
- }));
61
-
62
- return function updateTrackEventBatch(_x3, _x4) {
63
- return _ref2.apply(this, arguments);
64
- };
65
- }();
66
-
67
- exports.updateTrackEventBatch = updateTrackEventBatch;
@@ -1,6 +0,0 @@
1
- export declare const getBrand: (client: any, brandId: any) => Promise<{
2
- colors: any;
3
- inapp: any;
4
- preferenceTemplates: any;
5
- }>;
6
- //# sourceMappingURL=brand.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"brand.d.ts","sourceRoot":"","sources":["../../src/actions/brand.ts"],"names":[],"mappings":"AA2DA,eAAO,MAAM,QAAQ;;;;EAmBpB,CAAC"}
@@ -1,3 +0,0 @@
1
- export declare const updateTrackEvent: (client: any, trackingId: any) => Promise<void>;
2
- export declare const updateTrackEventBatch: (client: any, eventType: any) => Promise<void>;
3
- //# sourceMappingURL=track-event.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"track-event.d.ts","sourceRoot":"","sources":["../../src/actions/track-event.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,gBAAgB,iDAI5B,CAAC;AAEF,eAAO,MAAM,qBAAqB,gDAIjC,CAAC"}