oro-sdk-apis 1.14.0 → 1.15.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.
@@ -4,10 +4,20 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
6
 
7
+ var hash_js = require('hash.js');
8
+ var _ = require('buffer/');
7
9
  var createAuthRefreshInterceptor = _interopDefault(require('axios-auth-refresh'));
8
10
  var axios = _interopDefault(require('axios'));
9
- var _ = require('buffer/');
10
- var hash_js = require('hash.js');
11
+
12
+ /**
13
+ * This function return a base64 string representation of a hashed string
14
+ * @param value the string to hash
15
+ * @returns a base64 string representation of a hashed value
16
+ */
17
+
18
+ function hashToBase64String(value) {
19
+ return _.Buffer.from(hash_js.sha256().update(value).digest('hex'), 'hex').toString('base64');
20
+ }
11
21
 
12
22
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
13
23
  try {
@@ -1038,11 +1048,19 @@ var AxiosService = /*#__PURE__*/function () {
1038
1048
  var APIService = /*#__PURE__*/function (_AxiosService) {
1039
1049
  _inheritsLoose(APIService, _AxiosService);
1040
1050
 
1041
- function APIService(config, tokenRefreshFailureCallback) {
1051
+ /**
1052
+ * The API Service lets you use an axios API and handles oro backend services authentification via JWT tokens
1053
+ * @param useLocalStorage if set to true, tokens will be stored in localStorage
1054
+ * @param config (optional) an axios config
1055
+ * @param tokenRefreshFailureCallback (optional) callback to call when failing to refresh the auth token
1056
+ */
1057
+ function APIService(useLocalStorage, config, tokenRefreshFailureCallback) {
1042
1058
  var _this;
1043
1059
 
1044
1060
  _this = _AxiosService.call(this, config) || this;
1061
+ _this.useLocalStorage = useLocalStorage;
1045
1062
  _this.tokenRefreshFailureCallback = tokenRefreshFailureCallback;
1063
+ _this.tokens = {};
1046
1064
 
1047
1065
  var self = _assertThisInitialized(_this);
1048
1066
 
@@ -1116,23 +1134,142 @@ var APIService = /*#__PURE__*/function (_AxiosService) {
1116
1134
  };
1117
1135
 
1118
1136
  _proto.setTokens = function setTokens(tokens) {
1119
- localStorage.setItem('tokens', JSON.stringify(tokens));
1137
+ if (this.useLocalStorage) {
1138
+ localStorage.setItem('tokens', JSON.stringify(tokens));
1139
+ }
1140
+
1141
+ this.tokens = tokens;
1120
1142
  };
1121
1143
 
1122
1144
  _proto.getTokens = function getTokens() {
1123
- var tokens = {};
1124
- var item = localStorage.getItem('tokens');
1145
+ if (this.useLocalStorage) {
1146
+ var tokens = {};
1147
+ var item = localStorage.getItem('tokens');
1125
1148
 
1126
- if (item) {
1127
- tokens = JSON.parse(item);
1128
- }
1149
+ if (item) {
1150
+ tokens = JSON.parse(item);
1151
+ }
1129
1152
 
1130
- return tokens;
1153
+ return tokens;
1154
+ } else {
1155
+ return this.tokens;
1156
+ }
1131
1157
  };
1132
1158
 
1133
1159
  return APIService;
1134
1160
  }(AxiosService);
1135
1161
 
1162
+ /**
1163
+ * This service enables you to handle one authentication token per practice
1164
+ */
1165
+
1166
+ var ApisPracticeManager = /*#__PURE__*/function () {
1167
+ /**
1168
+ * The constructor
1169
+ * @param serviceCollReq the services to initialize. Only filled urls will get corresponding service to be initialized.
1170
+ * It will be used each time a new practices needs a `ServiceCollection`
1171
+ * @param getAuthTokenCbk the callback function used to get a new JWT token
1172
+ * @param useLocalStorage (default: false) if true store tokens into local storage (only for browsers)
1173
+ */
1174
+ function ApisPracticeManager(serviceCollReq, getAuthTokenCbk, useLocalStorage) {
1175
+ if (useLocalStorage === void 0) {
1176
+ useLocalStorage = false;
1177
+ }
1178
+
1179
+ this.serviceCollReq = serviceCollReq;
1180
+ this.getAuthTokenCbk = getAuthTokenCbk;
1181
+ this.useLocalStorage = useLocalStorage;
1182
+ this.practiceInstances = new Map();
1183
+ }
1184
+ /**
1185
+ * This function is used to get a `ServiceCollection` associated to a practice. If missing, it will initialize a new `ServiceCollection`.
1186
+ * @param practiceUuid the uuid of the practice
1187
+ * @returns a promise holding a `ServiceCollection`
1188
+ */
1189
+
1190
+
1191
+ var _proto = ApisPracticeManager.prototype;
1192
+
1193
+ _proto.get =
1194
+ /*#__PURE__*/
1195
+ function () {
1196
+ var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(practiceUuid) {
1197
+ var _this = this;
1198
+
1199
+ var practiceInstance, newPracticeInstance, authTokenFunc;
1200
+ return runtime_1.wrap(function _callee2$(_context2) {
1201
+ while (1) {
1202
+ switch (_context2.prev = _context2.next) {
1203
+ case 0:
1204
+ practiceInstance = this.practiceInstances.get(practiceUuid);
1205
+
1206
+ if (!practiceInstance) {
1207
+ _context2.next = 3;
1208
+ break;
1209
+ }
1210
+
1211
+ return _context2.abrupt("return", practiceInstance);
1212
+
1213
+ case 3:
1214
+ newPracticeInstance = init(this.serviceCollReq, undefined, this.useLocalStorage); // Create one auth token callback per practice since the practice uuid needs to change
1215
+
1216
+ authTokenFunc = /*#__PURE__*/function () {
1217
+ var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1218
+ return runtime_1.wrap(function _callee$(_context) {
1219
+ while (1) {
1220
+ switch (_context.prev = _context.next) {
1221
+ case 0:
1222
+ if (!newPracticeInstance.guardService) {
1223
+ _context.next = 7;
1224
+ break;
1225
+ }
1226
+
1227
+ console.log("\x1B[36m[Auth] Refresh auth called (practiceUuid: " + practiceUuid + ")\x1B[36m");
1228
+ _context.next = 4;
1229
+ return _this.getAuthTokenCbk(newPracticeInstance.guardService, practiceUuid);
1230
+
1231
+ case 4:
1232
+ return _context.abrupt("return", _context.sent);
1233
+
1234
+ case 7:
1235
+ throw Error('[Auth] Unable to refresh token guard service is undefined');
1236
+
1237
+ case 8:
1238
+ case "end":
1239
+ return _context.stop();
1240
+ }
1241
+ }
1242
+ }, _callee);
1243
+ }));
1244
+
1245
+ return function authTokenFunc() {
1246
+ return _ref.apply(this, arguments);
1247
+ };
1248
+ }(); // Set the refresh tokens callback
1249
+
1250
+
1251
+ newPracticeInstance.apiService.setAuthRefreshFn(authTokenFunc);
1252
+ this.practiceInstances.set(practiceUuid, newPracticeInstance);
1253
+ return _context2.abrupt("return", newPracticeInstance);
1254
+
1255
+ case 8:
1256
+ case "end":
1257
+ return _context2.stop();
1258
+ }
1259
+ }
1260
+ }, _callee2, this);
1261
+ }));
1262
+
1263
+ function get(_x) {
1264
+ return _get.apply(this, arguments);
1265
+ }
1266
+
1267
+ return get;
1268
+ }();
1269
+
1270
+ return ApisPracticeManager;
1271
+ }();
1272
+
1136
1273
  (function (AssistantType) {
1137
1274
  AssistantType["MedicalSecretary"] = "MedicalSecretary";
1138
1275
  AssistantType["Nurse"] = "Nurse";
@@ -1749,7 +1886,8 @@ var GuardService = /*#__PURE__*/function () {
1749
1886
  function GuardService(api, baseURL) {
1750
1887
  this.api = api;
1751
1888
  this.baseURL = baseURL;
1752
- this.api.setAuthRefreshFn(this.authRefresh.bind(this));
1889
+ this.api.setAuthRefreshFn(this.authRefresh.bind(this)); // This is the default behavior for User JWT tokens. If you want other kind of refresh you shall overwrite this call
1890
+
1753
1891
  this.identityCache = {};
1754
1892
  this.whoAmICache = {};
1755
1893
  }
@@ -1772,18 +1910,17 @@ var GuardService = /*#__PURE__*/function () {
1772
1910
  this.api.setTokens(_extends({}, this.api.getTokens(), tokens));
1773
1911
  }
1774
1912
  /**
1775
- * Allow to retrieve an access token and a refresh token in order
1776
- * to do authenticated request afterward
1913
+ * Allow to retrieve a M2M token for a service
1777
1914
  *
1778
1915
  * @param req The credentials required to get an access token
1779
1916
  * @returns AuthTokenResponse
1780
1917
  */
1781
1918
  ;
1782
1919
 
1783
- _proto.authToken =
1920
+ _proto.m2mToken =
1784
1921
  /*#__PURE__*/
1785
1922
  function () {
1786
- var _authToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(req) {
1923
+ var _m2mToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(req) {
1787
1924
  var resp, config, _e$response, code;
1788
1925
 
1789
1926
  return runtime_1.wrap(function _callee$(_context) {
@@ -1795,13 +1932,12 @@ var GuardService = /*#__PURE__*/function () {
1795
1932
  skipAuthRefresh: true
1796
1933
  };
1797
1934
  _context.next = 4;
1798
- return this.api.post(this.baseURL + "/v1/auth/token", req, config);
1935
+ return this.api.post(this.baseURL + "/v1/m2m/token", req, config);
1799
1936
 
1800
1937
  case 4:
1801
1938
  resp = _context.sent;
1802
1939
  this.api.setTokens({
1803
- accessToken: resp.accessToken,
1804
- refreshToken: resp.refreshToken
1940
+ accessToken: resp.accessToken
1805
1941
  });
1806
1942
  _context.next = 20;
1807
1943
  break;
@@ -1809,6 +1945,7 @@ var GuardService = /*#__PURE__*/function () {
1809
1945
  case 8:
1810
1946
  _context.prev = 8;
1811
1947
  _context.t0 = _context["catch"](0);
1948
+ console.error('Error while posting m2m token:', _context.t0);
1812
1949
 
1813
1950
  if (!_context.t0.isAxiosError) {
1814
1951
  _context.next = 19;
@@ -1817,14 +1954,11 @@ var GuardService = /*#__PURE__*/function () {
1817
1954
 
1818
1955
  code = (_e$response = _context.t0.response) == null ? void 0 : _e$response.status;
1819
1956
  _context.t1 = code;
1820
- _context.next = _context.t1 === 400 ? 15 : _context.t1 === 424 ? 16 : _context.t1 === 500 ? 17 : _context.t1 === 401 ? 18 : 18;
1957
+ _context.next = _context.t1 === 400 ? 16 : _context.t1 === 500 ? 17 : _context.t1 === 401 ? 18 : 18;
1821
1958
  break;
1822
1959
 
1823
- case 15:
1824
- throw new AuthenticationBadRequest();
1825
-
1826
1960
  case 16:
1827
- throw new AuthenticationUnconfirmedEmail();
1961
+ throw new AuthenticationBadRequest();
1828
1962
 
1829
1963
  case 17:
1830
1964
  throw new AuthenticationServerError();
@@ -1846,7 +1980,89 @@ var GuardService = /*#__PURE__*/function () {
1846
1980
  }, _callee, this, [[0, 8]]);
1847
1981
  }));
1848
1982
 
1849
- function authToken(_x) {
1983
+ function m2mToken(_x) {
1984
+ return _m2mToken.apply(this, arguments);
1985
+ }
1986
+
1987
+ return m2mToken;
1988
+ }()
1989
+ /**
1990
+ * Allow to retrieve an access token and a refresh token in order
1991
+ * to do authenticated request afterward
1992
+ *
1993
+ * @param req The credentials required to get an access token
1994
+ * @returns AuthTokenResponse
1995
+ */
1996
+ ;
1997
+
1998
+ _proto.authToken =
1999
+ /*#__PURE__*/
2000
+ function () {
2001
+ var _authToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(req) {
2002
+ var resp, config, _e$response2, code;
2003
+
2004
+ return runtime_1.wrap(function _callee2$(_context2) {
2005
+ while (1) {
2006
+ switch (_context2.prev = _context2.next) {
2007
+ case 0:
2008
+ _context2.prev = 0;
2009
+ config = {
2010
+ skipAuthRefresh: true
2011
+ };
2012
+ _context2.next = 4;
2013
+ return this.api.post(this.baseURL + "/v1/auth/token", req, config);
2014
+
2015
+ case 4:
2016
+ resp = _context2.sent;
2017
+ this.api.setTokens({
2018
+ accessToken: resp.accessToken,
2019
+ refreshToken: resp.refreshToken
2020
+ });
2021
+ _context2.next = 21;
2022
+ break;
2023
+
2024
+ case 8:
2025
+ _context2.prev = 8;
2026
+ _context2.t0 = _context2["catch"](0);
2027
+ console.error('Error while posting auth token:', _context2.t0);
2028
+
2029
+ if (!_context2.t0.isAxiosError) {
2030
+ _context2.next = 20;
2031
+ break;
2032
+ }
2033
+
2034
+ code = (_e$response2 = _context2.t0.response) == null ? void 0 : _e$response2.status;
2035
+ _context2.t1 = code;
2036
+ _context2.next = _context2.t1 === 400 ? 16 : _context2.t1 === 424 ? 17 : _context2.t1 === 500 ? 18 : _context2.t1 === 401 ? 19 : 19;
2037
+ break;
2038
+
2039
+ case 16:
2040
+ throw new AuthenticationBadRequest();
2041
+
2042
+ case 17:
2043
+ throw new AuthenticationUnconfirmedEmail();
2044
+
2045
+ case 18:
2046
+ throw new AuthenticationServerError();
2047
+
2048
+ case 19:
2049
+ throw new AuthenticationFailed();
2050
+
2051
+ case 20:
2052
+ throw new AuthenticationFailed();
2053
+
2054
+ case 21:
2055
+ return _context2.abrupt("return", resp);
2056
+
2057
+ case 22:
2058
+ case "end":
2059
+ return _context2.stop();
2060
+ }
2061
+ }
2062
+ }, _callee2, this, [[0, 8]]);
2063
+ }));
2064
+
2065
+ function authToken(_x2) {
1850
2066
  return _authToken.apply(this, arguments);
1851
2067
  }
1852
2068
 
@@ -1862,27 +2078,27 @@ var GuardService = /*#__PURE__*/function () {
1862
2078
  _proto.authRefresh =
1863
2079
  /*#__PURE__*/
1864
2080
  function () {
1865
- var _authRefresh = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(refreshToken) {
2081
+ var _authRefresh = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(refreshToken) {
1866
2082
  var config;
1867
- return runtime_1.wrap(function _callee2$(_context2) {
2083
+ return runtime_1.wrap(function _callee3$(_context3) {
1868
2084
  while (1) {
1869
- switch (_context2.prev = _context2.next) {
2085
+ switch (_context3.prev = _context3.next) {
1870
2086
  case 0:
1871
2087
  config = {
1872
2088
  skipAuthRefresh: true,
1873
2089
  useRefreshToken: true
1874
2090
  };
1875
- return _context2.abrupt("return", this.api.put(this.baseURL + "/v1/auth/token", null, config));
2091
+ return _context3.abrupt("return", this.api.put(this.baseURL + "/v1/auth/token", null, config));
1876
2092
 
1877
2093
  case 2:
1878
2094
  case "end":
1879
- return _context2.stop();
2095
+ return _context3.stop();
1880
2096
  }
1881
2097
  }
1882
- }, _callee2, this);
2098
+ }, _callee3, this);
1883
2099
  }));
1884
2100
 
1885
- function authRefresh(_x2) {
2101
+ function authRefresh(_x3) {
1886
2102
  return _authRefresh.apply(this, arguments);
1887
2103
  }
1888
2104
 
@@ -1898,19 +2114,19 @@ var GuardService = /*#__PURE__*/function () {
1898
2114
  _proto.authLogout =
1899
2115
  /*#__PURE__*/
1900
2116
  function () {
1901
- var _authLogout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
1902
- return runtime_1.wrap(function _callee3$(_context3) {
2117
+ var _authLogout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
2118
+ return runtime_1.wrap(function _callee4$(_context4) {
1903
2119
  while (1) {
1904
- switch (_context3.prev = _context3.next) {
2120
+ switch (_context4.prev = _context4.next) {
1905
2121
  case 0:
1906
- return _context3.abrupt("return", this.api.get(this.baseURL + "/v1/auth/logout"));
2122
+ return _context4.abrupt("return", this.api.get(this.baseURL + "/v1/auth/logout"));
1907
2123
 
1908
2124
  case 1:
1909
2125
  case "end":
1910
- return _context3.stop();
2126
+ return _context4.stop();
1911
2127
  }
1912
2128
  }
1913
- }, _callee3, this);
2129
+ }, _callee4, this);
1914
2130
  }));
1915
2131
 
1916
2132
  function authLogout() {
@@ -1930,22 +2146,22 @@ var GuardService = /*#__PURE__*/function () {
1930
2146
  _proto.authRecover =
1931
2147
  /*#__PURE__*/
1932
2148
  function () {
1933
- var _authRecover = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(req) {
1934
- return runtime_1.wrap(function _callee4$(_context4) {
2149
+ var _authRecover = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(req) {
2150
+ return runtime_1.wrap(function _callee5$(_context5) {
1935
2151
  while (1) {
1936
- switch (_context4.prev = _context4.next) {
2152
+ switch (_context5.prev = _context5.next) {
1937
2153
  case 0:
1938
- return _context4.abrupt("return", this.api.post(this.baseURL + "/v1/auth/recover", req));
2154
+ return _context5.abrupt("return", this.api.post(this.baseURL + "/v1/auth/recover", req));
1939
2155
 
1940
2156
  case 1:
1941
2157
  case "end":
1942
- return _context4.stop();
2158
+ return _context5.stop();
1943
2159
  }
1944
2160
  }
1945
- }, _callee4, this);
2161
+ }, _callee5, this);
1946
2162
  }));
1947
2163
 
1948
- function authRecover(_x3) {
2164
+ function authRecover(_x4) {
1949
2165
  return _authRecover.apply(this, arguments);
1950
2166
  }
1951
2167
 
@@ -1963,37 +2179,37 @@ var GuardService = /*#__PURE__*/function () {
1963
2179
  _proto.identityCreate =
1964
2180
  /*#__PURE__*/
1965
2181
  function () {
1966
- var _identityCreate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(req) {
1967
- var resp, _e$response2, code;
2182
+ var _identityCreate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(req) {
2183
+ var resp, _e$response3, code;
1968
2184
 
1969
- return runtime_1.wrap(function _callee5$(_context5) {
2185
+ return runtime_1.wrap(function _callee6$(_context6) {
1970
2186
  while (1) {
1971
- switch (_context5.prev = _context5.next) {
2187
+ switch (_context6.prev = _context6.next) {
1972
2188
  case 0:
1973
- _context5.prev = 0;
1974
- _context5.next = 3;
2189
+ _context6.prev = 0;
2190
+ _context6.next = 3;
1975
2191
  return this.api.post(this.baseURL + "/v1/identities", req);
1976
2192
 
1977
2193
  case 3:
1978
- resp = _context5.sent;
2194
+ resp = _context6.sent;
1979
2195
  this.api.setTokens({
1980
2196
  refreshToken: resp.refreshToken
1981
2197
  });
1982
- _context5.next = 18;
2198
+ _context6.next = 18;
1983
2199
  break;
1984
2200
 
1985
2201
  case 7:
1986
- _context5.prev = 7;
1987
- _context5.t0 = _context5["catch"](0);
2202
+ _context6.prev = 7;
2203
+ _context6.t0 = _context6["catch"](0);
1988
2204
 
1989
- if (!_context5.t0.isAxiosError) {
1990
- _context5.next = 17;
2205
+ if (!_context6.t0.isAxiosError) {
2206
+ _context6.next = 17;
1991
2207
  break;
1992
2208
  }
1993
2209
 
1994
- code = (_e$response2 = _context5.t0.response) == null ? void 0 : _e$response2.status;
1995
- _context5.t1 = code;
1996
- _context5.next = _context5.t1 === 400 ? 14 : _context5.t1 === 409 ? 15 : _context5.t1 === 500 ? 16 : 16;
2210
+ code = (_e$response3 = _context6.t0.response) == null ? void 0 : _e$response3.status;
2211
+ _context6.t1 = code;
2212
+ _context6.next = _context6.t1 === 400 ? 14 : _context6.t1 === 409 ? 15 : _context6.t1 === 500 ? 16 : 16;
1997
2213
  break;
1998
2214
 
1999
2215
  case 14:
@@ -2009,17 +2225,17 @@ var GuardService = /*#__PURE__*/function () {
2009
2225
  throw new IdentityCreationFailed();
2010
2226
 
2011
2227
  case 18:
2012
- return _context5.abrupt("return", resp);
2228
+ return _context6.abrupt("return", resp);
2013
2229
 
2014
2230
  case 19:
2015
2231
  case "end":
2016
- return _context5.stop();
2232
+ return _context6.stop();
2017
2233
  }
2018
2234
  }
2019
- }, _callee5, this, [[0, 7]]);
2235
+ }, _callee6, this, [[0, 7]]);
2020
2236
  }));
2021
2237
 
2022
- function identityCreate(_x4) {
2238
+ function identityCreate(_x5) {
2023
2239
  return _identityCreate.apply(this, arguments);
2024
2240
  }
2025
2241
 
@@ -2038,13 +2254,13 @@ var GuardService = /*#__PURE__*/function () {
2038
2254
  _proto.identityGet =
2039
2255
  /*#__PURE__*/
2040
2256
  function () {
2041
- var _identityGet = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(identityID, skipCache) {
2257
+ var _identityGet = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(identityID, skipCache) {
2042
2258
  var _tokens$accessToken, _tokens$refreshToken;
2043
2259
 
2044
2260
  var tokens, cacheKey, identity;
2045
- return runtime_1.wrap(function _callee6$(_context6) {
2261
+ return runtime_1.wrap(function _callee7$(_context7) {
2046
2262
  while (1) {
2047
- switch (_context6.prev = _context6.next) {
2263
+ switch (_context7.prev = _context7.next) {
2048
2264
  case 0:
2049
2265
  if (skipCache === void 0) {
2050
2266
  skipCache = false;
@@ -2054,38 +2270,38 @@ var GuardService = /*#__PURE__*/function () {
2054
2270
  cacheKey = ((_tokens$accessToken = tokens.accessToken) != null ? _tokens$accessToken : '') + ((_tokens$refreshToken = tokens.refreshToken) != null ? _tokens$refreshToken : '') + identityID;
2055
2271
 
2056
2272
  if (!(skipCache || !tokens.accessToken || !this.identityCache[cacheKey])) {
2057
- _context6.next = 10;
2273
+ _context7.next = 10;
2058
2274
  break;
2059
2275
  }
2060
2276
 
2061
- _context6.next = 6;
2277
+ _context7.next = 6;
2062
2278
  return this.api.get(this.baseURL + "/v1/identities/" + identityID);
2063
2279
 
2064
2280
  case 6:
2065
- identity = _context6.sent;
2281
+ identity = _context7.sent;
2066
2282
 
2067
2283
  if (!skipCache) {
2068
- _context6.next = 9;
2284
+ _context7.next = 9;
2069
2285
  break;
2070
2286
  }
2071
2287
 
2072
- return _context6.abrupt("return", identity);
2288
+ return _context7.abrupt("return", identity);
2073
2289
 
2074
2290
  case 9:
2075
2291
  this.identityCache[cacheKey] = identity;
2076
2292
 
2077
2293
  case 10:
2078
- return _context6.abrupt("return", this.identityCache[cacheKey]);
2294
+ return _context7.abrupt("return", this.identityCache[cacheKey]);
2079
2295
 
2080
2296
  case 11:
2081
2297
  case "end":
2082
- return _context6.stop();
2298
+ return _context7.stop();
2083
2299
  }
2084
2300
  }
2085
- }, _callee6, this);
2301
+ }, _callee7, this);
2086
2302
  }));
2087
2303
 
2088
- function identityGet(_x5, _x6) {
2304
+ function identityGet(_x6, _x7) {
2089
2305
  return _identityGet.apply(this, arguments);
2090
2306
  }
2091
2307
 
@@ -2102,13 +2318,13 @@ var GuardService = /*#__PURE__*/function () {
2102
2318
  _proto.whoAmI =
2103
2319
  /*#__PURE__*/
2104
2320
  function () {
2105
- var _whoAmI = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(refreshCache) {
2321
+ var _whoAmI = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(refreshCache) {
2106
2322
  var _this$api$getTokens$a;
2107
2323
 
2108
2324
  var cacheKey;
2109
- return runtime_1.wrap(function _callee7$(_context7) {
2325
+ return runtime_1.wrap(function _callee8$(_context8) {
2110
2326
  while (1) {
2111
- switch (_context7.prev = _context7.next) {
2327
+ switch (_context8.prev = _context8.next) {
2112
2328
  case 0:
2113
2329
  if (refreshCache === void 0) {
2114
2330
  refreshCache = false;
@@ -2117,28 +2333,28 @@ var GuardService = /*#__PURE__*/function () {
2117
2333
  cacheKey = (_this$api$getTokens$a = this.api.getTokens().accessToken) != null ? _this$api$getTokens$a : '';
2118
2334
 
2119
2335
  if (!(!this.whoAmICache[cacheKey] || refreshCache)) {
2120
- _context7.next = 6;
2336
+ _context8.next = 6;
2121
2337
  break;
2122
2338
  }
2123
2339
 
2124
- _context7.next = 5;
2340
+ _context8.next = 5;
2125
2341
  return this.api.get(this.baseURL + "/v1/auth/whoami");
2126
2342
 
2127
2343
  case 5:
2128
- this.whoAmICache[cacheKey] = _context7.sent;
2344
+ this.whoAmICache[cacheKey] = _context8.sent;
2129
2345
 
2130
2346
  case 6:
2131
- return _context7.abrupt("return", this.whoAmICache[cacheKey]);
2347
+ return _context8.abrupt("return", this.whoAmICache[cacheKey]);
2132
2348
 
2133
2349
  case 7:
2134
2350
  case "end":
2135
- return _context7.stop();
2351
+ return _context8.stop();
2136
2352
  }
2137
2353
  }
2138
- }, _callee7, this);
2354
+ }, _callee8, this);
2139
2355
  }));
2140
2356
 
2141
- function whoAmI(_x7) {
2357
+ function whoAmI(_x8) {
2142
2358
  return _whoAmI.apply(this, arguments);
2143
2359
  }
2144
2360
 
@@ -2156,22 +2372,22 @@ var GuardService = /*#__PURE__*/function () {
2156
2372
  _proto.identityUpdate =
2157
2373
  /*#__PURE__*/
2158
2374
  function () {
2159
- var _identityUpdate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(identityID, req) {
2160
- return runtime_1.wrap(function _callee8$(_context8) {
2375
+ var _identityUpdate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(identityID, req) {
2376
+ return runtime_1.wrap(function _callee9$(_context9) {
2161
2377
  while (1) {
2162
- switch (_context8.prev = _context8.next) {
2378
+ switch (_context9.prev = _context9.next) {
2163
2379
  case 0:
2164
- return _context8.abrupt("return", this.api.put(this.baseURL + "/v1/identities/" + identityID, req));
2380
+ return _context9.abrupt("return", this.api.put(this.baseURL + "/v1/identities/" + identityID, req));
2165
2381
 
2166
2382
  case 1:
2167
2383
  case "end":
2168
- return _context8.stop();
2384
+ return _context9.stop();
2169
2385
  }
2170
2386
  }
2171
- }, _callee8, this);
2387
+ }, _callee9, this);
2172
2388
  }));
2173
2389
 
2174
- function identityUpdate(_x8, _x9) {
2390
+ function identityUpdate(_x9, _x10) {
2175
2391
  return _identityUpdate.apply(this, arguments);
2176
2392
  }
2177
2393
 
@@ -2190,16 +2406,16 @@ var GuardService = /*#__PURE__*/function () {
2190
2406
  _proto.identityMFAQRCode =
2191
2407
  /*#__PURE__*/
2192
2408
  function () {
2193
- var _identityMFAQRCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(identityID, password) {
2409
+ var _identityMFAQRCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(identityID, password) {
2194
2410
  var req;
2195
- return runtime_1.wrap(function _callee9$(_context9) {
2411
+ return runtime_1.wrap(function _callee10$(_context10) {
2196
2412
  while (1) {
2197
- switch (_context9.prev = _context9.next) {
2413
+ switch (_context10.prev = _context10.next) {
2198
2414
  case 0:
2199
2415
  req = {
2200
2416
  password: password
2201
2417
  };
2202
- return _context9.abrupt("return", this.api.post(this.baseURL + "/v1/identities/" + identityID + "/mfa", req, {
2418
+ return _context10.abrupt("return", this.api.post(this.baseURL + "/v1/identities/" + identityID + "/mfa", req, {
2203
2419
  headers: {
2204
2420
  Accept: 'application/json'
2205
2421
  }
@@ -2207,13 +2423,13 @@ var GuardService = /*#__PURE__*/function () {
2207
2423
 
2208
2424
  case 2:
2209
2425
  case "end":
2210
- return _context9.stop();
2426
+ return _context10.stop();
2211
2427
  }
2212
2428
  }
2213
- }, _callee9, this);
2429
+ }, _callee10, this);
2214
2430
  }));
2215
2431
 
2216
- function identityMFAQRCode(_x10, _x11) {
2432
+ function identityMFAQRCode(_x11, _x12) {
2217
2433
  return _identityMFAQRCode.apply(this, arguments);
2218
2434
  }
2219
2435
 
@@ -2230,22 +2446,22 @@ var GuardService = /*#__PURE__*/function () {
2230
2446
  _proto.identitySendConfirmEmail =
2231
2447
  /*#__PURE__*/
2232
2448
  function () {
2233
- var _identitySendConfirmEmail = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(req) {
2234
- return runtime_1.wrap(function _callee10$(_context10) {
2449
+ var _identitySendConfirmEmail = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(req) {
2450
+ return runtime_1.wrap(function _callee11$(_context11) {
2235
2451
  while (1) {
2236
- switch (_context10.prev = _context10.next) {
2452
+ switch (_context11.prev = _context11.next) {
2237
2453
  case 0:
2238
- return _context10.abrupt("return", this.api.post(this.baseURL + "/v1/identity/confirm", req));
2454
+ return _context11.abrupt("return", this.api.post(this.baseURL + "/v1/identity/confirm", req));
2239
2455
 
2240
2456
  case 1:
2241
2457
  case "end":
2242
- return _context10.stop();
2458
+ return _context11.stop();
2243
2459
  }
2244
2460
  }
2245
- }, _callee10, this);
2461
+ }, _callee11, this);
2246
2462
  }));
2247
2463
 
2248
- function identitySendConfirmEmail(_x12) {
2464
+ function identitySendConfirmEmail(_x13) {
2249
2465
  return _identitySendConfirmEmail.apply(this, arguments);
2250
2466
  }
2251
2467
 
@@ -2262,22 +2478,22 @@ var GuardService = /*#__PURE__*/function () {
2262
2478
  _proto.identityGetByCustomerEmail =
2263
2479
  /*#__PURE__*/
2264
2480
  function () {
2265
- var _identityGetByCustomerEmail = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(email) {
2266
- return runtime_1.wrap(function _callee11$(_context11) {
2481
+ var _identityGetByCustomerEmail = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(email) {
2482
+ return runtime_1.wrap(function _callee12$(_context12) {
2267
2483
  while (1) {
2268
- switch (_context11.prev = _context11.next) {
2484
+ switch (_context12.prev = _context12.next) {
2269
2485
  case 0:
2270
- return _context11.abrupt("return", this.identityGetByHash(email.substring(email.indexOf('+') + 1, email.indexOf('@'))));
2486
+ return _context12.abrupt("return", this.identityGetByHash(email.substring(email.indexOf('+') + 1, email.indexOf('@'))));
2271
2487
 
2272
2488
  case 1:
2273
2489
  case "end":
2274
- return _context11.stop();
2490
+ return _context12.stop();
2275
2491
  }
2276
2492
  }
2277
- }, _callee11, this);
2493
+ }, _callee12, this);
2278
2494
  }));
2279
2495
 
2280
- function identityGetByCustomerEmail(_x13) {
2496
+ function identityGetByCustomerEmail(_x14) {
2281
2497
  return _identityGetByCustomerEmail.apply(this, arguments);
2282
2498
  }
2283
2499
 
@@ -2294,22 +2510,22 @@ var GuardService = /*#__PURE__*/function () {
2294
2510
  _proto.identityGetByHash =
2295
2511
  /*#__PURE__*/
2296
2512
  function () {
2297
- var _identityGetByHash = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(b64Hash) {
2298
- return runtime_1.wrap(function _callee12$(_context12) {
2513
+ var _identityGetByHash = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(b64Hash) {
2514
+ return runtime_1.wrap(function _callee13$(_context13) {
2299
2515
  while (1) {
2300
- switch (_context12.prev = _context12.next) {
2516
+ switch (_context13.prev = _context13.next) {
2301
2517
  case 0:
2302
- return _context12.abrupt("return", this.identityGet(b64Hash.replace('+', '-').replace('/', '_')));
2518
+ return _context13.abrupt("return", this.identityGet(b64Hash.replace('+', '-').replace('/', '_')));
2303
2519
 
2304
2520
  case 1:
2305
2521
  case "end":
2306
- return _context12.stop();
2522
+ return _context13.stop();
2307
2523
  }
2308
2524
  }
2309
- }, _callee12, this);
2525
+ }, _callee13, this);
2310
2526
  }));
2311
2527
 
2312
- function identityGetByHash(_x14) {
2528
+ function identityGetByHash(_x15) {
2313
2529
  return _identityGetByHash.apply(this, arguments);
2314
2530
  }
2315
2531
 
@@ -2465,7 +2681,7 @@ var PracticeService = /*#__PURE__*/function () {
2465
2681
  ;
2466
2682
 
2467
2683
  _proto.getPaymentIntentHashedEmail = function getPaymentIntentHashedEmail(email) {
2468
- return _.Buffer.from(hash_js.sha256().update(email.toLowerCase()).digest('hex'), 'hex').toString('base64');
2684
+ return hashToBase64String(email.toLowerCase());
2469
2685
  }
2470
2686
  /**
2471
2687
  * Creates a PracticePaymentIntent
@@ -3123,11 +3339,16 @@ var WorkflowService = /*#__PURE__*/function () {
3123
3339
  /**
3124
3340
  * This function is used to initialize services with a provided url
3125
3341
  * @param services an object containing the url of the services to init
3126
- * @param (optional) authenticationCallback the authentification callback
3342
+ * @param authenticationCallback (optional) the authentification callback. Called when the token were not able to be refreshed.
3343
+ * @param useLocalStorage (default: true) if true store tokens into local storage (only for browsers)
3127
3344
  * @returns an instance of each services with a provided url
3128
3345
  */
3129
3346
 
3130
- var init = function init(services, authenticationCallback) {
3347
+ var init = function init(services, authenticationCallback, useLocalStorage) {
3348
+ if (useLocalStorage === void 0) {
3349
+ useLocalStorage = true;
3350
+ }
3351
+
3131
3352
  var tellerBaseURL = services.tellerBaseURL,
3132
3353
  practiceBaseURL = services.practiceBaseURL,
3133
3354
  consultBaseURL = services.consultBaseURL,
@@ -3135,8 +3356,9 @@ var init = function init(services, authenticationCallback) {
3135
3356
  guardBaseURL = services.guardBaseURL,
3136
3357
  workflowBaseURL = services.workflowBaseURL,
3137
3358
  diagnosisBaseURL = services.diagnosisBaseURL;
3138
- var apiService = new APIService(undefined, authenticationCallback);
3359
+ var apiService = new APIService(useLocalStorage, undefined, authenticationCallback);
3139
3360
  return {
3361
+ apiService: apiService,
3140
3362
  tellerService: tellerBaseURL ? new TellerService(apiService, tellerBaseURL) : undefined,
3141
3363
  practiceService: practiceBaseURL ? new PracticeService(apiService, practiceBaseURL) : undefined,
3142
3364
  consultService: consultBaseURL ? new ConsultService(apiService, consultBaseURL) : undefined,
@@ -3148,6 +3370,7 @@ var init = function init(services, authenticationCallback) {
3148
3370
  };
3149
3371
 
3150
3372
  exports.APIService = APIService;
3373
+ exports.ApisPracticeManager = ApisPracticeManager;
3151
3374
  exports.AuthenticationBadRequest = AuthenticationBadRequest;
3152
3375
  exports.AuthenticationFailed = AuthenticationFailed;
3153
3376
  exports.AuthenticationServerError = AuthenticationServerError;
@@ -3164,4 +3387,6 @@ exports.TellerService = TellerService;
3164
3387
  exports.VaultService = VaultService;
3165
3388
  exports.WorkflowService = WorkflowService;
3166
3389
  exports.default = init;
3390
+ exports.hashToBase64String = hashToBase64String;
3391
+ exports.init = init;
3167
3392
  //# sourceMappingURL=oro-sdk-apis.cjs.development.js.map