@livechat/customer-sdk 3.1.2 → 3.1.3

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 CHANGED
@@ -69,21 +69,21 @@ If you just want to look around and play with the SDK, check out our
69
69
  [sample chat widget implementation](https://codesandbox.io/s/rm3prxw88n).
70
70
 
71
71
  For the time being you need to register your application in the <a href="https://developers.livechat.com/console" target="_blank">Developers Console</a>
72
- as a "Web app (frontend, eg. JavaScript)" type. Then, you have to pass the configured `redirectUri` to the `init`, along with the regular required properties (`licenseId` and `clientId`).
72
+ as a "Web app (frontend, eg. JavaScript)" type. Then, you have to pass the configured `redirectUri` to the `init`, along with the regular required properties (`organizationId` and `clientId`).
73
73
 
74
74
  ## Using the API
75
75
 
76
76
  To use the API you will first need to create an instance using the `init` function.
77
- You will need to provide your licenseId and clientId when creating a Customer SDK instance.
77
+ You will need to provide your organizationId and clientId when creating a Customer SDK instance.
78
78
 
79
79
  Other optional configuration parameters are also available:
80
80
 
81
81
  | parameters | type | default | description |
82
82
  | -------------------- | ------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
83
- | licenseId | number | | Your license number, you receive this value when creating a new livechat account. |
83
+ | organizationId | number | | Your Organization ID, you receive this value when creating a new livechat account. |
84
84
  | clientId | string | | Your client id, you receive this value when you register your application in the LiveChat Developer Console. |
85
85
  | autoConnect | boolean | true | Optional; should the library try to reconnect on it's own. |
86
- | groupId | number | | Optional; the id of the group you wish to connect to. |
86
+ | groupId | number | 0 | Optional; the id of the group you wish to connect to. |
87
87
  | uniqueGroups | boolean | false | Optional; by default, the customer's identity is the same for all groups. If you want to create a separate customer identity for each group, set this parameter to `true`. When set to `true`, passing a `groupId` is required. |
88
88
  | region | 'dal' \| 'fra' | 'dal' | Optional; the server region your license is at. |
89
89
  | redirectUri | string | | Optional; should only be used inside ReactNative, this is the URI which your webview is redirected to after authorization. |
@@ -111,7 +111,7 @@ The `init` function will return a Customer SDK instance:
111
111
 
112
112
  ```js
113
113
  const customerSDK = CustomerSDK.init({
114
- licenseId: LICENSE_ID,
114
+ organizationId: ORGANIZATION_ID,
115
115
  clientId: CLIENT_ID,
116
116
  })
117
117
  ```
@@ -163,7 +163,7 @@ export default class App extends React.Component {
163
163
 
164
164
  componentDidMount() {
165
165
  this.customerSDK = init({
166
- licenseId: LICENSE_ID,
166
+ organizationId: ORGANIZATION_ID,
167
167
  clientId: CLIENT_ID,
168
168
  redirectUri: REDIRECT_URI,
169
169
  })
@@ -1003,7 +1003,7 @@ Parameters:
1003
1003
  ### Errors
1004
1004
 
1005
1005
  - `CHAT_ALREADY_ACTIVE` - the chat is already active and you can't activate it again.
1006
- - `GROUPS_OFFLINE` - a group in the targeted chat is offline. It can happen for licenses without continuous chats enabled.
1006
+ - `GROUPS_OFFLINE` - a group in the targeted chat is offline. It can happen when asynchronous communication is disabled.
1007
1007
 
1008
1008
  ## sendEvent
1009
1009
 
@@ -1212,7 +1212,7 @@ Parameters:
1212
1212
  ### Errors
1213
1213
 
1214
1214
  - `CHAT_LIMIT_REACHED` - the maximum limit of chats per Customer has been reached, and it's not possible to start a new one. You should activate one of the existing chats. The limit is 1.
1215
- - `GROUPS_OFFLINE` - a group in the target chat is offline. It can happen for licenses, which don't allow Customers to chat during their unavailability.
1215
+ - `GROUPS_OFFLINE` - a group in the targeted chat is offline. It can happen when asynchronous communication is disabled.
1216
1216
 
1217
1217
  ## updateChatProperties
1218
1218
 
@@ -2085,11 +2085,11 @@ Internal error. Customer SDK reconnects on its own.
2085
2085
 
2086
2086
  ## License expired
2087
2087
 
2088
- The license with the specified ID has expired. You should make sure that there are no unpaid invoices for it.
2088
+ The subscription for LiveChat product associated with the specified ID has expired. You should make sure that there are no unpaid invoices for it.
2089
2089
 
2090
2090
  ## License not found
2091
2091
 
2092
- The license with the specified ID doesn't exist. You should check the options passed in to Customer SDK and make sure that the license parameter is correct.
2092
+ The LiveChat product associated with the specified ID doesn't exist. You should check the options passed in to Customer SDK and make sure that the parameters provided are correct.
2093
2093
 
2094
2094
  This internally destroys the current instance of Customer SDK, so it won't be possible to reuse it.
2095
2095
 
@@ -2197,6 +2197,14 @@ customerSDK.on('disconnected', ({ reason }) => {
2197
2197
 
2198
2198
  # Changelog
2199
2199
 
2200
+ ## [v4.0.0] - XXXX-XX-X
2201
+
2202
+ ### Changed
2203
+
2204
+ Switched to using Customer API 3.4:
2205
+
2206
+ - Drop support for the `licenseId` parameter in the `init` method. It has been replaced by the `organizationId`.
2207
+
2200
2208
  ## [v3.1.2] - 2023-02-28
2201
2209
 
2202
2210
  ### Fixed
@@ -7,8 +7,7 @@ var mitt = require('@livechat/mitt');
7
7
  var dataUtils = require('@livechat/data-utils');
8
8
  var redux = require('redux');
9
9
  var createSideEffectsMiddleware = require('@livechat/side-effects-middleware');
10
- var deferred = require('@livechat/deferred');
11
- var promiseTry = require('@livechat/promise-try');
10
+ var promiseUtils = require('@livechat/promise-utils');
12
11
  var createBackoff = require('@livechat/backoff');
13
12
  var storage = require('@livechat/isomorphic-storage');
14
13
  var unfetch = require('unfetch');
@@ -21,8 +20,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
21
20
  var createAuth__default = /*#__PURE__*/_interopDefaultLegacy(createAuth);
22
21
  var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt);
23
22
  var createSideEffectsMiddleware__default = /*#__PURE__*/_interopDefaultLegacy(createSideEffectsMiddleware);
24
- var deferred__default = /*#__PURE__*/_interopDefaultLegacy(deferred);
25
- var promiseTry__default = /*#__PURE__*/_interopDefaultLegacy(promiseTry);
26
23
  var createBackoff__default = /*#__PURE__*/_interopDefaultLegacy(createBackoff);
27
24
  var storage__default = /*#__PURE__*/_interopDefaultLegacy(storage);
28
25
  var unfetch__default = /*#__PURE__*/_interopDefaultLegacy(unfetch);
@@ -157,6 +154,8 @@ var RECONNECTING = 'reconnecting';
157
154
  var AGENT = 'agent';
158
155
  var CUSTOMER = 'customer';
159
156
 
157
+ var LIVECHAT_ORGANIZATION_ID = 'feaf6c0e-9f43-48ff-9ad0-8e24e0350932';
158
+
160
159
  var getAllRequests = function getAllRequests(state) {
161
160
  return state.requests;
162
161
  };
@@ -180,9 +179,9 @@ var isDestroyed = function isDestroyed(state) {
180
179
  return getConnectionStatus(state) === DESTROYED;
181
180
  };
182
181
  var getEnvPart = function getEnvPart(_ref) {
183
- var licenseId = _ref.licenseId,
182
+ var organizationId = _ref.organizationId,
184
183
  env = _ref.env;
185
- if (licenseId === 1520) {
184
+ if (organizationId === LIVECHAT_ORGANIZATION_ID) {
186
185
  return '.staging';
187
186
  }
188
187
  if (env === 'production') {
@@ -196,12 +195,12 @@ var getApiOrigin = function getApiOrigin(state) {
196
195
  return "https://api" + regionPart + getEnvPart(state) + ".livechatinc.com";
197
196
  };
198
197
  var getServerUrl = function getServerUrl(state) {
199
- return getApiOrigin(state) + "/v3.3/customer";
198
+ return getApiOrigin(state) + "/v3.4/customer";
200
199
  };
201
200
  var createInitialState = function createInitialState(initialStateData) {
202
201
  var _initialStateData$app = initialStateData.application,
203
202
  application = _initialStateData$app === void 0 ? {} : _initialStateData$app,
204
- licenseId = initialStateData.licenseId,
203
+ organizationId = initialStateData.organizationId,
205
204
  _initialStateData$gro = initialStateData.groupId,
206
205
  groupId = _initialStateData$gro === void 0 ? null : _initialStateData$gro,
207
206
  env = initialStateData.env,
@@ -218,9 +217,9 @@ var createInitialState = function createInitialState(initialStateData) {
218
217
  return {
219
218
  application: _extends({}, application, {
220
219
  name: "customer_sdk",
221
- version: "3.1.2"
220
+ version: "3.1.3"
222
221
  }),
223
- licenseId: licenseId,
222
+ organizationId: organizationId,
224
223
  env: env,
225
224
  groupId: groupId,
226
225
  chats: {},
@@ -674,10 +673,10 @@ var socketDisconnected = function socketDisconnected() {
674
673
  // TODO: this thing is not really well typed and should be improved
675
674
  var sendRequestAction = function sendRequestAction(store, action) {
676
675
  action.payload.id = dataUtils.generateUniqueId(store.getState().requests);
677
- var _deferred = deferred__default['default'](),
678
- resolve = _deferred.resolve,
679
- reject = _deferred.reject,
680
- promise = _deferred.promise;
676
+ var _promiseDeferred = promiseUtils.promiseDeferred(),
677
+ resolve = _promiseDeferred.resolve,
678
+ reject = _promiseDeferred.reject,
679
+ promise = _promiseDeferred.promise;
681
680
  action.payload.promise = promise;
682
681
  action.payload.resolve = resolve;
683
682
  action.payload.reject = reject;
@@ -690,24 +689,39 @@ var CUSTOMER_BANNED$1 = 'CUSTOMER_BANNED';
690
689
  var USERS_LIMIT_REACHED = 'USERS_LIMIT_REACHED';
691
690
  var WRONG_PRODUCT_VERSION = 'WRONG_PRODUCT_VERSION';
692
691
 
693
- var getSideStorageKey = function getSideStorageKey(store) {
692
+ var getSideStorageKeyByLicense = function getSideStorageKeyByLicense(store, licenseId) {
694
693
  var _store$getState = store.getState(),
695
- licenseId = _store$getState.licenseId,
696
694
  groupId = _store$getState.groupId,
697
695
  uniqueGroups = _store$getState.uniqueGroups;
698
696
  return "side_storage_" + licenseId + (uniqueGroups ? ":" + groupId : '');
699
697
  };
700
- var getSideStorage = function getSideStorage(store) {
701
- return storage__default['default'].getItem(getSideStorageKey(store))["catch"](dataUtils.noop).then(function (sideStorage) {
702
- return JSON.parse(sideStorage || '{}');
698
+ var getSideStorageKeyByOrganization = function getSideStorageKeyByOrganization(store) {
699
+ var _store$getState2 = store.getState(),
700
+ organizationId = _store$getState2.organizationId,
701
+ groupId = _store$getState2.groupId,
702
+ uniqueGroups = _store$getState2.uniqueGroups;
703
+ return "side_storage_" + organizationId + (uniqueGroups ? ":" + groupId : '');
704
+ };
705
+ var getSideStorage = function getSideStorage(store, licenseId) {
706
+ var sideStorageLicenseKey = getSideStorageKeyByLicense(store, licenseId);
707
+ var sideStorageOrganizationKey = getSideStorageKeyByOrganization(store);
708
+ return storage__default['default'].getItem(sideStorageLicenseKey)["catch"](dataUtils.noop).then(function (sideStorage) {
709
+ if (!sideStorage) {
710
+ return storage__default['default'].getItem(sideStorageOrganizationKey)["catch"](dataUtils.noop).then(function (organizationSideStorage) {
711
+ return JSON.parse(organizationSideStorage || '{}');
712
+ })["catch"](dataUtils.noop);
713
+ }
714
+ return storage__default['default'].setItem(sideStorageOrganizationKey, sideStorage)["catch"](dataUtils.noop).then(function () {
715
+ return storage__default['default'].removeItem(sideStorageLicenseKey)["catch"](dataUtils.noop).then(function () {
716
+ return JSON.parse(sideStorage);
717
+ })["catch"](dataUtils.noop);
718
+ });
703
719
  })
704
720
  // shouldnt get triggered, just a defensive measure against malformed storage entries
705
- ["catch"](function () {
706
- return {};
707
- });
721
+ ["catch"](dataUtils.noop);
708
722
  };
709
723
  var saveSideStorage = function saveSideStorage(store, sideStorage) {
710
- return storage__default['default'].setItem(getSideStorageKey(store), JSON.stringify(sideStorage))["catch"](dataUtils.noop);
724
+ storage__default['default'].setItem(getSideStorageKeyByOrganization(store), JSON.stringify(sideStorage))["catch"](dataUtils.noop);
711
725
  };
712
726
 
713
727
  var taskChain = function taskChain(_ref, onSuccess, onError) {
@@ -715,7 +729,7 @@ var taskChain = function taskChain(_ref, onSuccess, onError) {
715
729
  var cancelled = false;
716
730
  var next = function next(intermediateResult) {
717
731
  var step = steps.shift();
718
- promiseTry__default['default'](function () {
732
+ promiseUtils.promiseTry(function () {
719
733
  return step(intermediateResult);
720
734
  }).then(function (result) {
721
735
  if (cancelled) {
@@ -748,7 +762,7 @@ var delay = function delay(ms) {
748
762
  setTimeout(resolve, ms);
749
763
  });
750
764
  };
751
- function createLoginTask(auth, customerDataProvider) {
765
+ function createLoginTask(auth, customerDataProvider, licenseId) {
752
766
  var store;
753
767
  var sentPage = null;
754
768
  var task;
@@ -769,7 +783,7 @@ function createLoginTask(auth, customerDataProvider) {
769
783
  return store.dispatch(reconnect(currentBackoffStrategy.duration()));
770
784
  };
771
785
  var getTokenAndSideStorage = function getTokenAndSideStorage() {
772
- return Promise.all([auth.getToken(), getSideStorage(store)]);
786
+ return Promise.all([auth.getToken(), getSideStorage(store, licenseId)]);
773
787
  };
774
788
  var dispatchSelfId = function dispatchSelfId(_ref2) {
775
789
  var token = _ref2[0],
@@ -909,7 +923,7 @@ var checkGoals = function checkGoals(store, auth, sessionFields) {
909
923
  return;
910
924
  }
911
925
  var query = urlUtils.buildQueryString({
912
- license_id: state.licenseId
926
+ organization_id: state.organizationId
913
927
  });
914
928
  var payload = {
915
929
  session_fields: parseCustomerSessionFields(sessionFields || {}),
@@ -1408,11 +1422,11 @@ var sendRequest$1 = function sendRequest(socket, _ref3) {
1408
1422
  {
1409
1423
  var upgradedPushes = [];
1410
1424
  socket.emit(_extends({}, frame, {
1411
- version: '3.3',
1425
+ version: '3.4',
1412
1426
  payload: _extends({}, frame.payload, {
1413
1427
  pushes: {
1414
- // '3.4': upgradedPushes,
1415
- '3.3': dataUtils.values(serverPushActions).filter(function (pushAction) {
1428
+ // '3.5': upgradedPushes,
1429
+ '3.4': dataUtils.values(serverPushActions).filter(function (pushAction) {
1416
1430
  return (
1417
1431
  // `customer_disconnected` can be sent immediately after opening the connection, before it even received login request
1418
1432
  // therefore it's not possible to subscribe for a particular version of this push - the "connection version" is always used
@@ -1582,9 +1596,10 @@ var createSideEffectsHandler = (function (_ref9) {
1582
1596
  var auth = _ref9.auth,
1583
1597
  customerDataProvider = _ref9.customerDataProvider,
1584
1598
  emitter = _ref9.emitter,
1585
- socket = _ref9.socket;
1599
+ socket = _ref9.socket,
1600
+ licenseId = _ref9.licenseId;
1586
1601
  var emit = emitter.emit;
1587
- var loginTask = createLoginTask(auth, customerDataProvider);
1602
+ var loginTask = createLoginTask(auth, customerDataProvider, licenseId);
1588
1603
 
1589
1604
  // TODO: using Store type here is a lie, middleware only provides MiddlewareAPI here
1590
1605
  return function (action, store) {
@@ -1881,7 +1896,7 @@ var initialize = function initialize(store, emitter) {
1881
1896
  var url = (getServerUrl(state) + "/rtm/ws").replace(/^https/, 'wss');
1882
1897
  return createPlatformClient__default['default'](url, {
1883
1898
  query: {
1884
- license_id: state.licenseId
1899
+ organization_id: state.organizationId
1885
1900
  },
1886
1901
  emitter: emitter
1887
1902
  });
@@ -2173,16 +2188,17 @@ var parseListChatsResponse = function parseListChatsResponse(payload) {
2173
2188
  var lastEventSummary = dataUtils.last(lastEventSummariesArray.sort(function (eventSummaryA, eventSummaryB) {
2174
2189
  return eventSummaryA.thread_id === eventSummaryB.thread_id ? dataUtils.stringCompare(eventSummaryA.event.created_at, eventSummaryB.event.created_at) : dataUtils.stringCompare(eventSummaryA.thread_created_at, eventSummaryB.thread_created_at);
2175
2190
  }));
2176
- if (lastEventSummary) {
2191
+ if (lastEventSummary && chatSummary.lastEventsPerType) {
2177
2192
  chatSummary.lastEvent = chatSummary.lastEventsPerType[lastEventSummary.event.type];
2178
2193
  }
2179
2194
  return chatSummary;
2180
2195
  });
2181
2196
  return {
2182
2197
  chatsSummary: dataUtils.numericSortBy(function (_ref4) {
2198
+ var _ref5;
2183
2199
  var lastEvent = _ref4.lastEvent,
2184
2200
  order = _ref4.order;
2185
- return -1 * (lastEvent !== undefined ? lastEvent.timestamp : order);
2201
+ return -1 * ((_ref5 = lastEvent !== undefined ? lastEvent.timestamp : order) != null ? _ref5 : 0);
2186
2202
  }, chatsSummary),
2187
2203
  totalChats: payload.total_chats,
2188
2204
  users: dataUtils.uniqBy(function (user) {
@@ -2359,9 +2375,9 @@ var parsePush = function parsePush(push) {
2359
2375
  };
2360
2376
  }
2361
2377
  };
2362
- var parseResponse = function parseResponse(_ref5) {
2363
- var request = _ref5.request,
2364
- response = _ref5.response;
2378
+ var parseResponse = function parseResponse(_ref6) {
2379
+ var request = _ref6.request,
2380
+ response = _ref6.response;
2365
2381
  switch (response.action) {
2366
2382
  case ACCEPT_GREETING:
2367
2383
  return {
@@ -2615,9 +2631,10 @@ var createTicketBody = function createTicketBody(state, _ref) {
2615
2631
  customerId = _ref.customerId,
2616
2632
  _ref$groupId = _ref.groupId,
2617
2633
  groupId = _ref$groupId === void 0 ? state.groupId : _ref$groupId,
2634
+ licenseId = _ref.licenseId,
2618
2635
  timeZone = _ref.timeZone;
2619
2636
  var ticketBody = _extends({
2620
- licence_id: state.licenseId,
2637
+ licence_id: licenseId,
2621
2638
  ticket_message: '',
2622
2639
  offline_message: '',
2623
2640
  visitor_id: customerId,
@@ -2697,6 +2714,7 @@ var createTicketBody = function createTicketBody(state, _ref) {
2697
2714
  var sendTicketForm = function sendTicketForm(store, auth, _ref2) {
2698
2715
  var filledForm = _ref2.filledForm,
2699
2716
  groupId = _ref2.groupId,
2717
+ licenseId = _ref2.licenseId,
2700
2718
  timeZone = _ref2.timeZone;
2701
2719
  return auth.getToken().then(function (token) {
2702
2720
  var state = store.getState();
@@ -2708,6 +2726,7 @@ var sendTicketForm = function sendTicketForm(store, auth, _ref2) {
2708
2726
  fields: filledForm.fields,
2709
2727
  customerId: token.entityId,
2710
2728
  groupId: groupId,
2729
+ licenseId: licenseId,
2711
2730
  timeZone: timeZone
2712
2731
  });
2713
2732
  return unfetch__default['default'](url, {
@@ -2792,7 +2811,7 @@ var uploadFile = function uploadFile(_ref, _ref2) {
2792
2811
  validateFile(file);
2793
2812
  var state = store.getState();
2794
2813
  var query = urlUtils.buildQueryString({
2795
- license_id: state.licenseId
2814
+ organization_id: state.organizationId
2796
2815
  });
2797
2816
  var url = getServerUrl(state) + "/action/" + UPLOAD_FILE + "?" + query;
2798
2817
  var payload = {
@@ -2858,7 +2877,7 @@ var makeGraylogRequest = function makeGraylogRequest(url, body) {
2858
2877
  */
2859
2878
  var log = function log(_ref) {
2860
2879
  var env = _ref.env,
2861
- licenseId = _ref.licenseId,
2880
+ organizationId = _ref.organizationId,
2862
2881
  eventName = _ref.eventName;
2863
2882
  if (env !== 'production' || "customer_sdk" !== 'customer_sdk') {
2864
2883
  return Promise.resolve();
@@ -2866,10 +2885,10 @@ var log = function log(_ref) {
2866
2885
  var message = {
2867
2886
  event_name: eventName,
2868
2887
  severity: 'Informational',
2869
- sdkVersion: "3.1.2"
2888
+ sdkVersion: "3.1.3"
2870
2889
  };
2871
2890
  var body = {
2872
- licence_id: licenseId,
2891
+ organizationId: organizationId,
2873
2892
  event_id: 'chat_widget_customer_sdk',
2874
2893
  message: JSON.stringify(message)
2875
2894
  };
@@ -2987,7 +3006,7 @@ var debug = (function (_sdk) {
2987
3006
  });
2988
3007
 
2989
3008
  var CHATS_PAGINATION_MAX_LIMIT = 25;
2990
- var init = function init(config, env) {
3009
+ var init = function init(config, env, licenseId) {
2991
3010
  if (env === void 0) {
2992
3011
  env = 'production';
2993
3012
  }
@@ -3002,12 +3021,13 @@ var init = function init(config, env) {
3002
3021
  }));
3003
3022
  var emitter = mitt__default['default']();
3004
3023
  var socket = createSocketClient(store);
3005
- var auth = typeof identityProvider === 'function' ? identityProvider() : createAuth__default['default'](instanceConfig, env);
3024
+ var auth = typeof identityProvider === 'function' ? identityProvider() : createAuth__default['default'](instanceConfig, licenseId, env);
3006
3025
  store.addSideEffectsHandler(createSideEffectsHandler({
3007
3026
  emitter: emitter,
3008
3027
  socket: socket,
3009
3028
  auth: auth,
3010
- customerDataProvider: customerDataProvider
3029
+ customerDataProvider: customerDataProvider,
3030
+ licenseId: licenseId
3011
3031
  }));
3012
3032
  socketListener(store, socket);
3013
3033
  var sendRequestAction$1 = sendRequestAction.bind(null, store);
@@ -3206,7 +3226,7 @@ var init = function init(config, env) {
3206
3226
  resumeChat: function resumeChat(data) {
3207
3227
  log({
3208
3228
  env: env,
3209
- licenseId: config.licenseId,
3229
+ organizationId: config.organizationId,
3210
3230
  eventName: 'chat_started'
3211
3231
  });
3212
3232
  return sendRequestAction$1(sendRequest(RESUME_CHAT, parseResumeChatData(data)));
@@ -3261,7 +3281,7 @@ var init = function init(config, env) {
3261
3281
  }
3262
3282
  log({
3263
3283
  env: env,
3264
- licenseId: config.licenseId,
3284
+ organizationId: config.organizationId,
3265
3285
  eventName: 'chat_started'
3266
3286
  });
3267
3287
  return sendRequestAction$1(sendRequest(START_CHAT, parseStartChatData(data)));