oro-sdk-apis 1.11.1 → 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.
@@ -1,7 +1,17 @@
1
+ import { sha256 } from 'hash.js';
2
+ import { Buffer } from 'buffer/';
1
3
  import createAuthRefreshInterceptor from 'axios-auth-refresh';
2
4
  import axios from 'axios';
3
- import { Buffer } from 'buffer/';
4
- import { sha256 } from 'hash.js';
5
+
6
+ /**
7
+ * This function return a base64 string representation of a hashed string
8
+ * @param value the string to hash
9
+ * @returns a base64 string representation of a hashed value
10
+ */
11
+
12
+ function hashToBase64String(value) {
13
+ return Buffer.from(sha256().update(value).digest('hex'), 'hex').toString('base64');
14
+ }
5
15
 
6
16
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
7
17
  try {
@@ -1032,11 +1042,19 @@ var AxiosService = /*#__PURE__*/function () {
1032
1042
  var APIService = /*#__PURE__*/function (_AxiosService) {
1033
1043
  _inheritsLoose(APIService, _AxiosService);
1034
1044
 
1035
- function APIService(config, tokenRefreshFailureCallback) {
1045
+ /**
1046
+ * The API Service lets you use an axios API and handles oro backend services authentification via JWT tokens
1047
+ * @param useLocalStorage if set to true, tokens will be stored in localStorage
1048
+ * @param config (optional) an axios config
1049
+ * @param tokenRefreshFailureCallback (optional) callback to call when failing to refresh the auth token
1050
+ */
1051
+ function APIService(useLocalStorage, config, tokenRefreshFailureCallback) {
1036
1052
  var _this;
1037
1053
 
1038
1054
  _this = _AxiosService.call(this, config) || this;
1055
+ _this.useLocalStorage = useLocalStorage;
1039
1056
  _this.tokenRefreshFailureCallback = tokenRefreshFailureCallback;
1057
+ _this.tokens = {};
1040
1058
 
1041
1059
  var self = _assertThisInitialized(_this);
1042
1060
 
@@ -1110,23 +1128,142 @@ var APIService = /*#__PURE__*/function (_AxiosService) {
1110
1128
  };
1111
1129
 
1112
1130
  _proto.setTokens = function setTokens(tokens) {
1113
- localStorage.setItem('tokens', JSON.stringify(tokens));
1131
+ if (this.useLocalStorage) {
1132
+ localStorage.setItem('tokens', JSON.stringify(tokens));
1133
+ }
1134
+
1135
+ this.tokens = tokens;
1114
1136
  };
1115
1137
 
1116
1138
  _proto.getTokens = function getTokens() {
1117
- var tokens = {};
1118
- var item = localStorage.getItem('tokens');
1139
+ if (this.useLocalStorage) {
1140
+ var tokens = {};
1141
+ var item = localStorage.getItem('tokens');
1119
1142
 
1120
- if (item) {
1121
- tokens = JSON.parse(item);
1122
- }
1143
+ if (item) {
1144
+ tokens = JSON.parse(item);
1145
+ }
1123
1146
 
1124
- return tokens;
1147
+ return tokens;
1148
+ } else {
1149
+ return this.tokens;
1150
+ }
1125
1151
  };
1126
1152
 
1127
1153
  return APIService;
1128
1154
  }(AxiosService);
1129
1155
 
1156
+ /**
1157
+ * This service enables you to handle one authentication token per practice
1158
+ */
1159
+
1160
+ var ApisPracticeManager = /*#__PURE__*/function () {
1161
+ /**
1162
+ * The constructor
1163
+ * @param serviceCollReq the services to initialize. Only filled urls will get corresponding service to be initialized.
1164
+ * It will be used each time a new practices needs a `ServiceCollection`
1165
+ * @param getAuthTokenCbk the callback function used to get a new JWT token
1166
+ * @param useLocalStorage (default: false) if true store tokens into local storage (only for browsers)
1167
+ */
1168
+ function ApisPracticeManager(serviceCollReq, getAuthTokenCbk, useLocalStorage) {
1169
+ if (useLocalStorage === void 0) {
1170
+ useLocalStorage = false;
1171
+ }
1172
+
1173
+ this.serviceCollReq = serviceCollReq;
1174
+ this.getAuthTokenCbk = getAuthTokenCbk;
1175
+ this.useLocalStorage = useLocalStorage;
1176
+ this.practiceInstances = new Map();
1177
+ }
1178
+ /**
1179
+ * This function is used to get a `ServiceCollection` associated to a practice. If missing, it will initialize a new `ServiceCollection`.
1180
+ * @param practiceUuid the uuid of the practice
1181
+ * @returns a promise holding a `ServiceCollection`
1182
+ */
1183
+
1184
+
1185
+ var _proto = ApisPracticeManager.prototype;
1186
+
1187
+ _proto.get =
1188
+ /*#__PURE__*/
1189
+ function () {
1190
+ var _get = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(practiceUuid) {
1191
+ var _this = this;
1192
+
1193
+ var practiceInstance, newPracticeInstance, authTokenFunc;
1194
+ return runtime_1.wrap(function _callee2$(_context2) {
1195
+ while (1) {
1196
+ switch (_context2.prev = _context2.next) {
1197
+ case 0:
1198
+ practiceInstance = this.practiceInstances.get(practiceUuid);
1199
+
1200
+ if (!practiceInstance) {
1201
+ _context2.next = 3;
1202
+ break;
1203
+ }
1204
+
1205
+ return _context2.abrupt("return", practiceInstance);
1206
+
1207
+ case 3:
1208
+ newPracticeInstance = init(this.serviceCollReq, undefined, this.useLocalStorage); // Create one auth token callback per practice since the practice uuid needs to change
1209
+
1210
+ authTokenFunc = /*#__PURE__*/function () {
1211
+ var _ref = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
1212
+ return runtime_1.wrap(function _callee$(_context) {
1213
+ while (1) {
1214
+ switch (_context.prev = _context.next) {
1215
+ case 0:
1216
+ if (!newPracticeInstance.guardService) {
1217
+ _context.next = 7;
1218
+ break;
1219
+ }
1220
+
1221
+ console.log("\x1B[36m[Auth] Refresh auth called (practiceUuid: " + practiceUuid + ")\x1B[36m");
1222
+ _context.next = 4;
1223
+ return _this.getAuthTokenCbk(newPracticeInstance.guardService, practiceUuid);
1224
+
1225
+ case 4:
1226
+ return _context.abrupt("return", _context.sent);
1227
+
1228
+ case 7:
1229
+ throw Error('[Auth] Unable to refresh token guard service is undefined');
1230
+
1231
+ case 8:
1232
+ case "end":
1233
+ return _context.stop();
1234
+ }
1235
+ }
1236
+ }, _callee);
1237
+ }));
1238
+
1239
+ return function authTokenFunc() {
1240
+ return _ref.apply(this, arguments);
1241
+ };
1242
+ }(); // Set the refresh tokens callback
1243
+
1244
+
1245
+ newPracticeInstance.apiService.setAuthRefreshFn(authTokenFunc);
1246
+ this.practiceInstances.set(practiceUuid, newPracticeInstance);
1247
+ return _context2.abrupt("return", newPracticeInstance);
1248
+
1249
+ case 8:
1250
+ case "end":
1251
+ return _context2.stop();
1252
+ }
1253
+ }
1254
+ }, _callee2, this);
1255
+ }));
1256
+
1257
+ function get(_x) {
1258
+ return _get.apply(this, arguments);
1259
+ }
1260
+
1261
+ return get;
1262
+ }();
1263
+
1264
+ return ApisPracticeManager;
1265
+ }();
1266
+
1130
1267
  var AssistantType;
1131
1268
 
1132
1269
  (function (AssistantType) {
@@ -1795,7 +1932,8 @@ var GuardService = /*#__PURE__*/function () {
1795
1932
  function GuardService(api, baseURL) {
1796
1933
  this.api = api;
1797
1934
  this.baseURL = baseURL;
1798
- this.api.setAuthRefreshFn(this.authRefresh.bind(this));
1935
+ 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
1936
+
1799
1937
  this.identityCache = {};
1800
1938
  this.whoAmICache = {};
1801
1939
  }
@@ -1818,18 +1956,17 @@ var GuardService = /*#__PURE__*/function () {
1818
1956
  this.api.setTokens(_extends({}, this.api.getTokens(), tokens));
1819
1957
  }
1820
1958
  /**
1821
- * Allow to retrieve an access token and a refresh token in order
1822
- * to do authenticated request afterward
1959
+ * Allow to retrieve a M2M token for a service
1823
1960
  *
1824
1961
  * @param req The credentials required to get an access token
1825
1962
  * @returns AuthTokenResponse
1826
1963
  */
1827
1964
  ;
1828
1965
 
1829
- _proto.authToken =
1966
+ _proto.m2mToken =
1830
1967
  /*#__PURE__*/
1831
1968
  function () {
1832
- var _authToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(req) {
1969
+ var _m2mToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(req) {
1833
1970
  var resp, config, _e$response, code;
1834
1971
 
1835
1972
  return runtime_1.wrap(function _callee$(_context) {
@@ -1841,13 +1978,12 @@ var GuardService = /*#__PURE__*/function () {
1841
1978
  skipAuthRefresh: true
1842
1979
  };
1843
1980
  _context.next = 4;
1844
- return this.api.post(this.baseURL + "/v1/auth/token", req, config);
1981
+ return this.api.post(this.baseURL + "/v1/m2m/token", req, config);
1845
1982
 
1846
1983
  case 4:
1847
1984
  resp = _context.sent;
1848
1985
  this.api.setTokens({
1849
- accessToken: resp.accessToken,
1850
- refreshToken: resp.refreshToken
1986
+ accessToken: resp.accessToken
1851
1987
  });
1852
1988
  _context.next = 20;
1853
1989
  break;
@@ -1855,6 +1991,7 @@ var GuardService = /*#__PURE__*/function () {
1855
1991
  case 8:
1856
1992
  _context.prev = 8;
1857
1993
  _context.t0 = _context["catch"](0);
1994
+ console.error('Error while posting m2m token:', _context.t0);
1858
1995
 
1859
1996
  if (!_context.t0.isAxiosError) {
1860
1997
  _context.next = 19;
@@ -1863,14 +2000,11 @@ var GuardService = /*#__PURE__*/function () {
1863
2000
 
1864
2001
  code = (_e$response = _context.t0.response) == null ? void 0 : _e$response.status;
1865
2002
  _context.t1 = code;
1866
- _context.next = _context.t1 === 400 ? 15 : _context.t1 === 424 ? 16 : _context.t1 === 500 ? 17 : _context.t1 === 401 ? 18 : 18;
2003
+ _context.next = _context.t1 === 400 ? 16 : _context.t1 === 500 ? 17 : _context.t1 === 401 ? 18 : 18;
1867
2004
  break;
1868
2005
 
1869
- case 15:
1870
- throw new AuthenticationBadRequest();
1871
-
1872
2006
  case 16:
1873
- throw new AuthenticationUnconfirmedEmail();
2007
+ throw new AuthenticationBadRequest();
1874
2008
 
1875
2009
  case 17:
1876
2010
  throw new AuthenticationServerError();
@@ -1892,7 +2026,89 @@ var GuardService = /*#__PURE__*/function () {
1892
2026
  }, _callee, this, [[0, 8]]);
1893
2027
  }));
1894
2028
 
1895
- function authToken(_x) {
2029
+ function m2mToken(_x) {
2030
+ return _m2mToken.apply(this, arguments);
2031
+ }
2032
+
2033
+ return m2mToken;
2034
+ }()
2035
+ /**
2036
+ * Allow to retrieve an access token and a refresh token in order
2037
+ * to do authenticated request afterward
2038
+ *
2039
+ * @param req The credentials required to get an access token
2040
+ * @returns AuthTokenResponse
2041
+ */
2042
+ ;
2043
+
2044
+ _proto.authToken =
2045
+ /*#__PURE__*/
2046
+ function () {
2047
+ var _authToken = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(req) {
2048
+ var resp, config, _e$response2, code;
2049
+
2050
+ return runtime_1.wrap(function _callee2$(_context2) {
2051
+ while (1) {
2052
+ switch (_context2.prev = _context2.next) {
2053
+ case 0:
2054
+ _context2.prev = 0;
2055
+ config = {
2056
+ skipAuthRefresh: true
2057
+ };
2058
+ _context2.next = 4;
2059
+ return this.api.post(this.baseURL + "/v1/auth/token", req, config);
2060
+
2061
+ case 4:
2062
+ resp = _context2.sent;
2063
+ this.api.setTokens({
2064
+ accessToken: resp.accessToken,
2065
+ refreshToken: resp.refreshToken
2066
+ });
2067
+ _context2.next = 21;
2068
+ break;
2069
+
2070
+ case 8:
2071
+ _context2.prev = 8;
2072
+ _context2.t0 = _context2["catch"](0);
2073
+ console.error('Error while posting auth token:', _context2.t0);
2074
+
2075
+ if (!_context2.t0.isAxiosError) {
2076
+ _context2.next = 20;
2077
+ break;
2078
+ }
2079
+
2080
+ code = (_e$response2 = _context2.t0.response) == null ? void 0 : _e$response2.status;
2081
+ _context2.t1 = code;
2082
+ _context2.next = _context2.t1 === 400 ? 16 : _context2.t1 === 424 ? 17 : _context2.t1 === 500 ? 18 : _context2.t1 === 401 ? 19 : 19;
2083
+ break;
2084
+
2085
+ case 16:
2086
+ throw new AuthenticationBadRequest();
2087
+
2088
+ case 17:
2089
+ throw new AuthenticationUnconfirmedEmail();
2090
+
2091
+ case 18:
2092
+ throw new AuthenticationServerError();
2093
+
2094
+ case 19:
2095
+ throw new AuthenticationFailed();
2096
+
2097
+ case 20:
2098
+ throw new AuthenticationFailed();
2099
+
2100
+ case 21:
2101
+ return _context2.abrupt("return", resp);
2102
+
2103
+ case 22:
2104
+ case "end":
2105
+ return _context2.stop();
2106
+ }
2107
+ }
2108
+ }, _callee2, this, [[0, 8]]);
2109
+ }));
2110
+
2111
+ function authToken(_x2) {
1896
2112
  return _authToken.apply(this, arguments);
1897
2113
  }
1898
2114
 
@@ -1908,27 +2124,27 @@ var GuardService = /*#__PURE__*/function () {
1908
2124
  _proto.authRefresh =
1909
2125
  /*#__PURE__*/
1910
2126
  function () {
1911
- var _authRefresh = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(refreshToken) {
2127
+ var _authRefresh = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(refreshToken) {
1912
2128
  var config;
1913
- return runtime_1.wrap(function _callee2$(_context2) {
2129
+ return runtime_1.wrap(function _callee3$(_context3) {
1914
2130
  while (1) {
1915
- switch (_context2.prev = _context2.next) {
2131
+ switch (_context3.prev = _context3.next) {
1916
2132
  case 0:
1917
2133
  config = {
1918
2134
  skipAuthRefresh: true,
1919
2135
  useRefreshToken: true
1920
2136
  };
1921
- return _context2.abrupt("return", this.api.put(this.baseURL + "/v1/auth/token", null, config));
2137
+ return _context3.abrupt("return", this.api.put(this.baseURL + "/v1/auth/token", null, config));
1922
2138
 
1923
2139
  case 2:
1924
2140
  case "end":
1925
- return _context2.stop();
2141
+ return _context3.stop();
1926
2142
  }
1927
2143
  }
1928
- }, _callee2, this);
2144
+ }, _callee3, this);
1929
2145
  }));
1930
2146
 
1931
- function authRefresh(_x2) {
2147
+ function authRefresh(_x3) {
1932
2148
  return _authRefresh.apply(this, arguments);
1933
2149
  }
1934
2150
 
@@ -1944,19 +2160,19 @@ var GuardService = /*#__PURE__*/function () {
1944
2160
  _proto.authLogout =
1945
2161
  /*#__PURE__*/
1946
2162
  function () {
1947
- var _authLogout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3() {
1948
- return runtime_1.wrap(function _callee3$(_context3) {
2163
+ var _authLogout = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4() {
2164
+ return runtime_1.wrap(function _callee4$(_context4) {
1949
2165
  while (1) {
1950
- switch (_context3.prev = _context3.next) {
2166
+ switch (_context4.prev = _context4.next) {
1951
2167
  case 0:
1952
- return _context3.abrupt("return", this.api.get(this.baseURL + "/v1/auth/logout"));
2168
+ return _context4.abrupt("return", this.api.get(this.baseURL + "/v1/auth/logout"));
1953
2169
 
1954
2170
  case 1:
1955
2171
  case "end":
1956
- return _context3.stop();
2172
+ return _context4.stop();
1957
2173
  }
1958
2174
  }
1959
- }, _callee3, this);
2175
+ }, _callee4, this);
1960
2176
  }));
1961
2177
 
1962
2178
  function authLogout() {
@@ -1976,22 +2192,22 @@ var GuardService = /*#__PURE__*/function () {
1976
2192
  _proto.authRecover =
1977
2193
  /*#__PURE__*/
1978
2194
  function () {
1979
- var _authRecover = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee4(req) {
1980
- return runtime_1.wrap(function _callee4$(_context4) {
2195
+ var _authRecover = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(req) {
2196
+ return runtime_1.wrap(function _callee5$(_context5) {
1981
2197
  while (1) {
1982
- switch (_context4.prev = _context4.next) {
2198
+ switch (_context5.prev = _context5.next) {
1983
2199
  case 0:
1984
- return _context4.abrupt("return", this.api.post(this.baseURL + "/v1/auth/recover", req));
2200
+ return _context5.abrupt("return", this.api.post(this.baseURL + "/v1/auth/recover", req));
1985
2201
 
1986
2202
  case 1:
1987
2203
  case "end":
1988
- return _context4.stop();
2204
+ return _context5.stop();
1989
2205
  }
1990
2206
  }
1991
- }, _callee4, this);
2207
+ }, _callee5, this);
1992
2208
  }));
1993
2209
 
1994
- function authRecover(_x3) {
2210
+ function authRecover(_x4) {
1995
2211
  return _authRecover.apply(this, arguments);
1996
2212
  }
1997
2213
 
@@ -2009,37 +2225,37 @@ var GuardService = /*#__PURE__*/function () {
2009
2225
  _proto.identityCreate =
2010
2226
  /*#__PURE__*/
2011
2227
  function () {
2012
- var _identityCreate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee5(req) {
2013
- var resp, _e$response2, code;
2228
+ var _identityCreate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(req) {
2229
+ var resp, _e$response3, code;
2014
2230
 
2015
- return runtime_1.wrap(function _callee5$(_context5) {
2231
+ return runtime_1.wrap(function _callee6$(_context6) {
2016
2232
  while (1) {
2017
- switch (_context5.prev = _context5.next) {
2233
+ switch (_context6.prev = _context6.next) {
2018
2234
  case 0:
2019
- _context5.prev = 0;
2020
- _context5.next = 3;
2235
+ _context6.prev = 0;
2236
+ _context6.next = 3;
2021
2237
  return this.api.post(this.baseURL + "/v1/identities", req);
2022
2238
 
2023
2239
  case 3:
2024
- resp = _context5.sent;
2240
+ resp = _context6.sent;
2025
2241
  this.api.setTokens({
2026
2242
  refreshToken: resp.refreshToken
2027
2243
  });
2028
- _context5.next = 18;
2244
+ _context6.next = 18;
2029
2245
  break;
2030
2246
 
2031
2247
  case 7:
2032
- _context5.prev = 7;
2033
- _context5.t0 = _context5["catch"](0);
2248
+ _context6.prev = 7;
2249
+ _context6.t0 = _context6["catch"](0);
2034
2250
 
2035
- if (!_context5.t0.isAxiosError) {
2036
- _context5.next = 17;
2251
+ if (!_context6.t0.isAxiosError) {
2252
+ _context6.next = 17;
2037
2253
  break;
2038
2254
  }
2039
2255
 
2040
- code = (_e$response2 = _context5.t0.response) == null ? void 0 : _e$response2.status;
2041
- _context5.t1 = code;
2042
- _context5.next = _context5.t1 === 400 ? 14 : _context5.t1 === 409 ? 15 : _context5.t1 === 500 ? 16 : 16;
2256
+ code = (_e$response3 = _context6.t0.response) == null ? void 0 : _e$response3.status;
2257
+ _context6.t1 = code;
2258
+ _context6.next = _context6.t1 === 400 ? 14 : _context6.t1 === 409 ? 15 : _context6.t1 === 500 ? 16 : 16;
2043
2259
  break;
2044
2260
 
2045
2261
  case 14:
@@ -2055,17 +2271,17 @@ var GuardService = /*#__PURE__*/function () {
2055
2271
  throw new IdentityCreationFailed();
2056
2272
 
2057
2273
  case 18:
2058
- return _context5.abrupt("return", resp);
2274
+ return _context6.abrupt("return", resp);
2059
2275
 
2060
2276
  case 19:
2061
2277
  case "end":
2062
- return _context5.stop();
2278
+ return _context6.stop();
2063
2279
  }
2064
2280
  }
2065
- }, _callee5, this, [[0, 7]]);
2281
+ }, _callee6, this, [[0, 7]]);
2066
2282
  }));
2067
2283
 
2068
- function identityCreate(_x4) {
2284
+ function identityCreate(_x5) {
2069
2285
  return _identityCreate.apply(this, arguments);
2070
2286
  }
2071
2287
 
@@ -2084,13 +2300,13 @@ var GuardService = /*#__PURE__*/function () {
2084
2300
  _proto.identityGet =
2085
2301
  /*#__PURE__*/
2086
2302
  function () {
2087
- var _identityGet = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee6(identityID, skipCache) {
2303
+ var _identityGet = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(identityID, skipCache) {
2088
2304
  var _tokens$accessToken, _tokens$refreshToken;
2089
2305
 
2090
2306
  var tokens, cacheKey, identity;
2091
- return runtime_1.wrap(function _callee6$(_context6) {
2307
+ return runtime_1.wrap(function _callee7$(_context7) {
2092
2308
  while (1) {
2093
- switch (_context6.prev = _context6.next) {
2309
+ switch (_context7.prev = _context7.next) {
2094
2310
  case 0:
2095
2311
  if (skipCache === void 0) {
2096
2312
  skipCache = false;
@@ -2100,38 +2316,38 @@ var GuardService = /*#__PURE__*/function () {
2100
2316
  cacheKey = ((_tokens$accessToken = tokens.accessToken) != null ? _tokens$accessToken : '') + ((_tokens$refreshToken = tokens.refreshToken) != null ? _tokens$refreshToken : '') + identityID;
2101
2317
 
2102
2318
  if (!(skipCache || !tokens.accessToken || !this.identityCache[cacheKey])) {
2103
- _context6.next = 10;
2319
+ _context7.next = 10;
2104
2320
  break;
2105
2321
  }
2106
2322
 
2107
- _context6.next = 6;
2323
+ _context7.next = 6;
2108
2324
  return this.api.get(this.baseURL + "/v1/identities/" + identityID);
2109
2325
 
2110
2326
  case 6:
2111
- identity = _context6.sent;
2327
+ identity = _context7.sent;
2112
2328
 
2113
2329
  if (!skipCache) {
2114
- _context6.next = 9;
2330
+ _context7.next = 9;
2115
2331
  break;
2116
2332
  }
2117
2333
 
2118
- return _context6.abrupt("return", identity);
2334
+ return _context7.abrupt("return", identity);
2119
2335
 
2120
2336
  case 9:
2121
2337
  this.identityCache[cacheKey] = identity;
2122
2338
 
2123
2339
  case 10:
2124
- return _context6.abrupt("return", this.identityCache[cacheKey]);
2340
+ return _context7.abrupt("return", this.identityCache[cacheKey]);
2125
2341
 
2126
2342
  case 11:
2127
2343
  case "end":
2128
- return _context6.stop();
2344
+ return _context7.stop();
2129
2345
  }
2130
2346
  }
2131
- }, _callee6, this);
2347
+ }, _callee7, this);
2132
2348
  }));
2133
2349
 
2134
- function identityGet(_x5, _x6) {
2350
+ function identityGet(_x6, _x7) {
2135
2351
  return _identityGet.apply(this, arguments);
2136
2352
  }
2137
2353
 
@@ -2148,13 +2364,13 @@ var GuardService = /*#__PURE__*/function () {
2148
2364
  _proto.whoAmI =
2149
2365
  /*#__PURE__*/
2150
2366
  function () {
2151
- var _whoAmI = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee7(refreshCache) {
2367
+ var _whoAmI = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(refreshCache) {
2152
2368
  var _this$api$getTokens$a;
2153
2369
 
2154
2370
  var cacheKey;
2155
- return runtime_1.wrap(function _callee7$(_context7) {
2371
+ return runtime_1.wrap(function _callee8$(_context8) {
2156
2372
  while (1) {
2157
- switch (_context7.prev = _context7.next) {
2373
+ switch (_context8.prev = _context8.next) {
2158
2374
  case 0:
2159
2375
  if (refreshCache === void 0) {
2160
2376
  refreshCache = false;
@@ -2163,28 +2379,28 @@ var GuardService = /*#__PURE__*/function () {
2163
2379
  cacheKey = (_this$api$getTokens$a = this.api.getTokens().accessToken) != null ? _this$api$getTokens$a : '';
2164
2380
 
2165
2381
  if (!(!this.whoAmICache[cacheKey] || refreshCache)) {
2166
- _context7.next = 6;
2382
+ _context8.next = 6;
2167
2383
  break;
2168
2384
  }
2169
2385
 
2170
- _context7.next = 5;
2386
+ _context8.next = 5;
2171
2387
  return this.api.get(this.baseURL + "/v1/auth/whoami");
2172
2388
 
2173
2389
  case 5:
2174
- this.whoAmICache[cacheKey] = _context7.sent;
2390
+ this.whoAmICache[cacheKey] = _context8.sent;
2175
2391
 
2176
2392
  case 6:
2177
- return _context7.abrupt("return", this.whoAmICache[cacheKey]);
2393
+ return _context8.abrupt("return", this.whoAmICache[cacheKey]);
2178
2394
 
2179
2395
  case 7:
2180
2396
  case "end":
2181
- return _context7.stop();
2397
+ return _context8.stop();
2182
2398
  }
2183
2399
  }
2184
- }, _callee7, this);
2400
+ }, _callee8, this);
2185
2401
  }));
2186
2402
 
2187
- function whoAmI(_x7) {
2403
+ function whoAmI(_x8) {
2188
2404
  return _whoAmI.apply(this, arguments);
2189
2405
  }
2190
2406
 
@@ -2202,22 +2418,22 @@ var GuardService = /*#__PURE__*/function () {
2202
2418
  _proto.identityUpdate =
2203
2419
  /*#__PURE__*/
2204
2420
  function () {
2205
- var _identityUpdate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee8(identityID, req) {
2206
- return runtime_1.wrap(function _callee8$(_context8) {
2421
+ var _identityUpdate = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(identityID, req) {
2422
+ return runtime_1.wrap(function _callee9$(_context9) {
2207
2423
  while (1) {
2208
- switch (_context8.prev = _context8.next) {
2424
+ switch (_context9.prev = _context9.next) {
2209
2425
  case 0:
2210
- return _context8.abrupt("return", this.api.put(this.baseURL + "/v1/identities/" + identityID, req));
2426
+ return _context9.abrupt("return", this.api.put(this.baseURL + "/v1/identities/" + identityID, req));
2211
2427
 
2212
2428
  case 1:
2213
2429
  case "end":
2214
- return _context8.stop();
2430
+ return _context9.stop();
2215
2431
  }
2216
2432
  }
2217
- }, _callee8, this);
2433
+ }, _callee9, this);
2218
2434
  }));
2219
2435
 
2220
- function identityUpdate(_x8, _x9) {
2436
+ function identityUpdate(_x9, _x10) {
2221
2437
  return _identityUpdate.apply(this, arguments);
2222
2438
  }
2223
2439
 
@@ -2236,16 +2452,16 @@ var GuardService = /*#__PURE__*/function () {
2236
2452
  _proto.identityMFAQRCode =
2237
2453
  /*#__PURE__*/
2238
2454
  function () {
2239
- var _identityMFAQRCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee9(identityID, password) {
2455
+ var _identityMFAQRCode = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(identityID, password) {
2240
2456
  var req;
2241
- return runtime_1.wrap(function _callee9$(_context9) {
2457
+ return runtime_1.wrap(function _callee10$(_context10) {
2242
2458
  while (1) {
2243
- switch (_context9.prev = _context9.next) {
2459
+ switch (_context10.prev = _context10.next) {
2244
2460
  case 0:
2245
2461
  req = {
2246
2462
  password: password
2247
2463
  };
2248
- return _context9.abrupt("return", this.api.post(this.baseURL + "/v1/identities/" + identityID + "/mfa", req, {
2464
+ return _context10.abrupt("return", this.api.post(this.baseURL + "/v1/identities/" + identityID + "/mfa", req, {
2249
2465
  headers: {
2250
2466
  Accept: 'application/json'
2251
2467
  }
@@ -2253,13 +2469,13 @@ var GuardService = /*#__PURE__*/function () {
2253
2469
 
2254
2470
  case 2:
2255
2471
  case "end":
2256
- return _context9.stop();
2472
+ return _context10.stop();
2257
2473
  }
2258
2474
  }
2259
- }, _callee9, this);
2475
+ }, _callee10, this);
2260
2476
  }));
2261
2477
 
2262
- function identityMFAQRCode(_x10, _x11) {
2478
+ function identityMFAQRCode(_x11, _x12) {
2263
2479
  return _identityMFAQRCode.apply(this, arguments);
2264
2480
  }
2265
2481
 
@@ -2276,26 +2492,90 @@ var GuardService = /*#__PURE__*/function () {
2276
2492
  _proto.identitySendConfirmEmail =
2277
2493
  /*#__PURE__*/
2278
2494
  function () {
2279
- var _identitySendConfirmEmail = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee10(req) {
2280
- return runtime_1.wrap(function _callee10$(_context10) {
2495
+ var _identitySendConfirmEmail = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee11(req) {
2496
+ return runtime_1.wrap(function _callee11$(_context11) {
2281
2497
  while (1) {
2282
- switch (_context10.prev = _context10.next) {
2498
+ switch (_context11.prev = _context11.next) {
2283
2499
  case 0:
2284
- return _context10.abrupt("return", this.api.post(this.baseURL + "/v1/identity/confirm", req));
2500
+ return _context11.abrupt("return", this.api.post(this.baseURL + "/v1/identity/confirm", req));
2285
2501
 
2286
2502
  case 1:
2287
2503
  case "end":
2288
- return _context10.stop();
2504
+ return _context11.stop();
2289
2505
  }
2290
2506
  }
2291
- }, _callee10, this);
2507
+ }, _callee11, this);
2292
2508
  }));
2293
2509
 
2294
- function identitySendConfirmEmail(_x12) {
2510
+ function identitySendConfirmEmail(_x13) {
2295
2511
  return _identitySendConfirmEmail.apply(this, arguments);
2296
2512
  }
2297
2513
 
2298
2514
  return identitySendConfirmEmail;
2515
+ }()
2516
+ /**
2517
+ * Get an identity using a customer email (format: customer+[b64Hash]@orohealth.me)
2518
+ *
2519
+ * @param email the customer email
2520
+ * @returns IdentityResponse
2521
+ */
2522
+ ;
2523
+
2524
+ _proto.identityGetByCustomerEmail =
2525
+ /*#__PURE__*/
2526
+ function () {
2527
+ var _identityGetByCustomerEmail = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee12(email) {
2528
+ return runtime_1.wrap(function _callee12$(_context12) {
2529
+ while (1) {
2530
+ switch (_context12.prev = _context12.next) {
2531
+ case 0:
2532
+ return _context12.abrupt("return", this.identityGetByHash(email.substring(email.indexOf('+') + 1, email.indexOf('@'))));
2533
+
2534
+ case 1:
2535
+ case "end":
2536
+ return _context12.stop();
2537
+ }
2538
+ }
2539
+ }, _callee12, this);
2540
+ }));
2541
+
2542
+ function identityGetByCustomerEmail(_x14) {
2543
+ return _identityGetByCustomerEmail.apply(this, arguments);
2544
+ }
2545
+
2546
+ return identityGetByCustomerEmail;
2547
+ }()
2548
+ /**
2549
+ * Get an identity using a base64 hash
2550
+ *
2551
+ * @param b64Hash base64 hash of the identity
2552
+ * @returns IdentityResponse
2553
+ */
2554
+ ;
2555
+
2556
+ _proto.identityGetByHash =
2557
+ /*#__PURE__*/
2558
+ function () {
2559
+ var _identityGetByHash = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee13(b64Hash) {
2560
+ return runtime_1.wrap(function _callee13$(_context13) {
2561
+ while (1) {
2562
+ switch (_context13.prev = _context13.next) {
2563
+ case 0:
2564
+ return _context13.abrupt("return", this.identityGet(b64Hash.replace('+', '-').replace('/', '_')));
2565
+
2566
+ case 1:
2567
+ case "end":
2568
+ return _context13.stop();
2569
+ }
2570
+ }
2571
+ }, _callee13, this);
2572
+ }));
2573
+
2574
+ function identityGetByHash(_x15) {
2575
+ return _identityGetByHash.apply(this, arguments);
2576
+ }
2577
+
2578
+ return identityGetByHash;
2299
2579
  }();
2300
2580
 
2301
2581
  return GuardService;
@@ -2447,7 +2727,7 @@ var PracticeService = /*#__PURE__*/function () {
2447
2727
  ;
2448
2728
 
2449
2729
  _proto.getPaymentIntentHashedEmail = function getPaymentIntentHashedEmail(email) {
2450
- return Buffer.from(sha256().update(email.toLowerCase()).digest('hex'), 'hex').toString('base64');
2730
+ return hashToBase64String(email.toLowerCase());
2451
2731
  }
2452
2732
  /**
2453
2733
  * Creates a PracticePaymentIntent
@@ -3105,11 +3385,16 @@ var WorkflowService = /*#__PURE__*/function () {
3105
3385
  /**
3106
3386
  * This function is used to initialize services with a provided url
3107
3387
  * @param services an object containing the url of the services to init
3108
- * @param (optional) authenticationCallback the authentification callback
3388
+ * @param authenticationCallback (optional) the authentification callback. Called when the token were not able to be refreshed.
3389
+ * @param useLocalStorage (default: true) if true store tokens into local storage (only for browsers)
3109
3390
  * @returns an instance of each services with a provided url
3110
3391
  */
3111
3392
 
3112
- var init = function init(services, authenticationCallback) {
3393
+ var init = function init(services, authenticationCallback, useLocalStorage) {
3394
+ if (useLocalStorage === void 0) {
3395
+ useLocalStorage = true;
3396
+ }
3397
+
3113
3398
  var tellerBaseURL = services.tellerBaseURL,
3114
3399
  practiceBaseURL = services.practiceBaseURL,
3115
3400
  consultBaseURL = services.consultBaseURL,
@@ -3117,8 +3402,9 @@ var init = function init(services, authenticationCallback) {
3117
3402
  guardBaseURL = services.guardBaseURL,
3118
3403
  workflowBaseURL = services.workflowBaseURL,
3119
3404
  diagnosisBaseURL = services.diagnosisBaseURL;
3120
- var apiService = new APIService(undefined, authenticationCallback);
3405
+ var apiService = new APIService(useLocalStorage, undefined, authenticationCallback);
3121
3406
  return {
3407
+ apiService: apiService,
3122
3408
  tellerService: tellerBaseURL ? new TellerService(apiService, tellerBaseURL) : undefined,
3123
3409
  practiceService: practiceBaseURL ? new PracticeService(apiService, practiceBaseURL) : undefined,
3124
3410
  consultService: consultBaseURL ? new ConsultService(apiService, consultBaseURL) : undefined,
@@ -3130,5 +3416,5 @@ var init = function init(services, authenticationCallback) {
3130
3416
  };
3131
3417
 
3132
3418
  export default init;
3133
- export { APIService, AssignmentStatus, AssistantType, AuthenticationBadRequest, AuthenticationFailed, AuthenticationServerError, AuthenticationUnconfirmedEmail, AxiosService, ConsultService, DiagnosisService, DocumentType, DrugType, FeeStatus, GuardService, IdentityCreationBadRequest, IdentityCreationConflict, IdentityCreationFailed, IndexKey, LicenseStatus, MedicalStatus, MetadataCategory, OtherRoleType, PaymentStatus, PeriodType, PlanStatus, PlanType, PracticeConfigKind, PracticeEmailKind, PracticeService, PractitionerStatus, PractitionnerRoleType, RateDimension, StripePriceType, SyncStatus, TaskStatus, TellerService, TransmissionKind, TransmissionStatus, VaultService, VisibilityType, WorkflowService, WorkflowType };
3419
+ export { APIService, ApisPracticeManager, AssignmentStatus, AssistantType, AuthenticationBadRequest, AuthenticationFailed, AuthenticationServerError, AuthenticationUnconfirmedEmail, AxiosService, ConsultService, DiagnosisService, DocumentType, DrugType, FeeStatus, GuardService, IdentityCreationBadRequest, IdentityCreationConflict, IdentityCreationFailed, IndexKey, LicenseStatus, MedicalStatus, MetadataCategory, OtherRoleType, PaymentStatus, PeriodType, PlanStatus, PlanType, PracticeConfigKind, PracticeEmailKind, PracticeService, PractitionerStatus, PractitionnerRoleType, RateDimension, StripePriceType, SyncStatus, TaskStatus, TellerService, TransmissionKind, TransmissionStatus, VaultService, VisibilityType, WorkflowService, WorkflowType, hashToBase64String, init };
3134
3420
  //# sourceMappingURL=oro-sdk-apis.esm.js.map