@icure/api 6.4.2 → 6.4.4

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.
Files changed (57) hide show
  1. package/icc-api/api/IccAuthApi.d.ts +19 -0
  2. package/icc-api/api/IccAuthApi.js +46 -1
  3. package/icc-api/api/IccAuthApi.js.map +1 -1
  4. package/icc-api/api/IccBesamv2Api.d.ts +6 -0
  5. package/icc-api/api/IccBesamv2Api.js +13 -0
  6. package/icc-api/api/IccBesamv2Api.js.map +1 -1
  7. package/icc-api/api/IccGroupApi.d.ts +6 -0
  8. package/icc-api/api/IccGroupApi.js +13 -0
  9. package/icc-api/api/IccGroupApi.js.map +1 -1
  10. package/icc-api/index.d.ts +0 -1
  11. package/icc-api/index.js +0 -1
  12. package/icc-api/index.js.map +1 -1
  13. package/icc-api/model/AuthenticationToken.d.ts +1 -0
  14. package/icc-api/model/AuthenticationToken.js.map +1 -1
  15. package/icc-api/model/CalendarItem.d.ts +1 -0
  16. package/icc-api/model/CalendarItem.js.map +1 -1
  17. package/icc-api/model/FlatRateTarification.d.ts +4 -1
  18. package/icc-api/model/FlatRateTarification.js +3 -0
  19. package/icc-api/model/FlatRateTarification.js.map +1 -1
  20. package/icc-api/model/ModelHelper.js +5 -4
  21. package/icc-api/model/ModelHelper.js.map +1 -1
  22. package/icc-api/model/UserGroup.d.ts +1 -0
  23. package/icc-api/model/UserGroup.js.map +1 -1
  24. package/icc-api/model/models.d.ts +2 -2
  25. package/icc-x-api/auth/AuthenticationProvider.d.ts +34 -2
  26. package/icc-x-api/auth/AuthenticationProvider.js +28 -6
  27. package/icc-x-api/auth/AuthenticationProvider.js.map +1 -1
  28. package/icc-x-api/auth/EnsembleAuthService.d.ts +6 -2
  29. package/icc-x-api/auth/EnsembleAuthService.js +9 -0
  30. package/icc-x-api/auth/EnsembleAuthService.js.map +1 -1
  31. package/icc-x-api/auth/JwtAuthService.d.ts +6 -5
  32. package/icc-x-api/auth/JwtAuthService.js +11 -23
  33. package/icc-x-api/auth/JwtAuthService.js.map +1 -1
  34. package/icc-x-api/auth/JwtBridgedAuthService.d.ts +26 -0
  35. package/icc-x-api/auth/JwtBridgedAuthService.js +129 -0
  36. package/icc-x-api/auth/JwtBridgedAuthService.js.map +1 -0
  37. package/icc-x-api/crypto/AES.js +3 -3
  38. package/icc-x-api/crypto/AES.js.map +1 -1
  39. package/icc-x-api/filters/ServiceByHcPartyTagCodeDateFilter.d.ts +1 -0
  40. package/icc-x-api/filters/ServiceByHcPartyTagCodeDateFilter.js.map +1 -1
  41. package/icc-x-api/filters/filters.d.ts +1 -1
  42. package/icc-x-api/icc-bekmehr-x-api.d.ts +1 -1
  43. package/icc-x-api/icc-crypto-x-api.d.ts +4 -6
  44. package/icc-x-api/icc-crypto-x-api.js +74 -75
  45. package/icc-x-api/icc-crypto-x-api.js.map +1 -1
  46. package/icc-x-api/icc-maintenance-task-x-api.js +1 -1
  47. package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
  48. package/icc-x-api/index.d.ts +7 -2
  49. package/icc-x-api/index.js +6 -4
  50. package/icc-x-api/index.js.map +1 -1
  51. package/icc-x-api/utils/asn1-packer.d.ts +1 -1
  52. package/icc-x-api/utils/asn1-parser.d.ts +1 -1
  53. package/icc-x-api/utils/net-utils.d.ts +2 -2
  54. package/package.json +1 -1
  55. package/icc-api/api/IccBemikronoApi.d.ts +0 -81
  56. package/icc-api/api/IccBemikronoApi.js +0 -162
  57. package/icc-api/api/IccBemikronoApi.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"EnsembleAuthService.js","sourceRoot":"","sources":["../../../icc-x-api/auth/EnsembleAuthService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAOA,MAAa,mBAAmB;IAK9B,YACmB,OAA8B,EAC9B,WAA0B,EAC1B,SAA2B;QAF3B,YAAO,GAAP,OAAO,CAAuB;QAC9B,gBAAW,GAAX,WAAW,CAAe;QAC1B,cAAS,GAAT,SAAS,CAAkB;Q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,EAAE;gBACvB,oEAAoE;gBACpE,MAAM,IAAI,CAAC,KAAK,CAAA;aACjB;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;aACvC;QACH,CAAC;KAAA;IAED,gBAAgB,CAAC,KAAY;;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE;YACvB,MAAA,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,0CAAE,gBAAgB,CAAC,KAAK,CAAC,CAAA;SAChE;IACH,CAAC;CACF;AA/CD,kDA+CC","sourcesContent":["import { AuthService } from './AuthService'\nimport { XHR } from '../../icc-api/api/XHR'\nimport { JwtAuthService } from './JwtAuthService'\nimport { NoAuthService } from './NoAuthService'\nimport { BasicAuthService } from './BasicAuthService'\nimport Header = XHR.Header\n\nexport class EnsembleAuthService implements AuthService {\n private currentState: string | null\n private error: Error | null = null\n private stateMap: { [key: string]: { state: AuthService | null; next: string | null } }\n\n constructor(\n private readonly jwtAuth: JwtAuthService | null,\n private readonly sessionAuth: NoAuthService,\n private readonly basicAuth: BasicAuthService\n ) {\n this.stateMap = {\n start: { state: null, next: 'jwt' },\n jwt: { state: this.jwtAuth, next: 'session' },\n session: { state: this.sessionAuth, next: 'basic' },\n basic: { state: this.basicAuth, next: null },\n }\n this.currentState = 'start'\n }\n\n async getAuthHeaders(): Promise<Array<Header>> {\n this.currentState = !!this.currentState ? this.stateMap[this.currentState].next : this.currentState\n\n if (!!this.currentState) {\n // If I have a state I return the headers, otherwise I return empty headers\n // And delegate the responsibility of handling the error to the next call\n return !!this.stateMap[this.currentState].state\n ? this.stateMap[this.currentState].state!.getAuthHeaders().catch((e) => {\n // If I get an error, it is also responsibility of the next call, but I give a warning\n console.warn(e.message)\n this.error = e\n return []\n })\n : Promise.resolve([])\n } else if (!!this.error) {\n // If I have no more states, I throw the last error or a default one\n throw this.error\n } else {\n throw new Error('Cannot authenticate')\n }\n }\n\n invalidateHeader(error: Error): void {\n this.error = error\n if (!!this.currentState) {\n this.stateMap[this.currentState].state?.invalidateHeader(error)\n }\n }\n}\n"]}
1
+ {"version":3,"file":"EnsembleAuthService.js","sourceRoot":"","sources":["../../../icc-x-api/auth/EnsembleAuthService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,+CAA2C;AAK3C,IAAO,QAAQ,GAAG,SAAG,CAAC,QAAQ,CAAA;AAE9B,MAAa,mBAAmB;IAK9B,YACmB,OAAqC,EACrC,WAA0B,EAC1B,SAA2B;QAF3B,YAAO,GAAP,OAAO,CAA8B;QACrC,gBAAW,GAAX,WAAW,CAAe;QAC1B,cAAS,GAAT,SAAS,CAAkB;QANtC,UAAK,GAAiB,IAAI,CAAA;QAQhC,IAAI,CAAC,QAAQ,GAAG;YACd,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE;YACnC,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;YAC7C,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE;YACnD,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE;SAC7C,CAAA;QACD,IAAI,CAAC,YAAY,GAAG,OAAO,CAAA;IAC7B,CAAC;IAED,cAAc;;QACZ,OAAO,MAAA,MAAA,IAAI,CAAC,OAAO,0CAAE,cAAc,EAAE,mCAAK,OAAO,CAAC,OAAO,EAAyB,CAAA;IACpF,CAAC;IAEK,cAAc;;YAClB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,YAAY,CAAA;YAEnG,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE;gBACvB,2EAA2E;gBAC3E,yEAAyE;gBACzE,OAAO,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK;oBAC7C,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAM,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;wBACnE,IAAI,CAAC,YAAY,QAAQ,IAAI,CAAC,CAAC,UAAU,KAAK,GAAG,EAAE;4BACjD,MAAM,CAAC,CAAA;yBACR;wBACD,sFAAsF;wBACtF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;wBACvB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAA;wBAEd,OAAO,EAAE,CAAA;oBACX,CAAC,CAAC;oBACJ,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;aACxB;iBAAM,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE;gBACvB,oEAAoE;gBACpE,MAAM,IAAI,CAAC,KAAK,CAAA;aACjB;iBAAM;gBACL,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;aACvC;QACH,CAAC;KAAA;IAED,gBAAgB,CAAC,KAAY;;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE;YACvB,MAAA,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,KAAK,0CAAE,gBAAgB,CAAC,KAAK,CAAC,CAAA;SAChE;IACH,CAAC;CACF;AAvDD,kDAuDC","sourcesContent":["import { AuthService } from './AuthService'\nimport { XHR } from '../../icc-api/api/XHR'\nimport { JwtBridgedAuthService } from './JwtBridgedAuthService'\nimport { NoAuthService } from './NoAuthService'\nimport { BasicAuthService } from './BasicAuthService'\nimport Header = XHR.Header\nimport XHRError = XHR.XHRError\n\nexport class EnsembleAuthService implements AuthService {\n private currentState: string | null\n private error: Error | null = null\n private stateMap: { [key: string]: { state: AuthService | null; next: string | null } }\n\n constructor(\n private readonly jwtAuth: JwtBridgedAuthService | null,\n private readonly sessionAuth: NoAuthService,\n private readonly basicAuth: BasicAuthService\n ) {\n this.stateMap = {\n start: { state: null, next: 'jwt' },\n jwt: { state: this.jwtAuth, next: 'session' },\n session: { state: this.sessionAuth, next: 'basic' },\n basic: { state: this.basicAuth, next: null },\n }\n this.currentState = 'start'\n }\n\n getIcureTokens(): Promise<{ token: string; refreshToken: string } | undefined> {\n return this.jwtAuth?.getIcureTokens() ?? (Promise.resolve() as Promise<undefined>)\n }\n\n async getAuthHeaders(): Promise<Array<Header>> {\n this.currentState = !!this.currentState ? this.stateMap[this.currentState].next : this.currentState\n\n if (!!this.currentState) {\n // If I have a state I return the headers, otherwise I return empty headers\n // And delegate the responsibility of handling the error to the next call\n return !!this.stateMap[this.currentState].state\n ? this.stateMap[this.currentState].state!.getAuthHeaders().catch((e) => {\n if (e instanceof XHRError && e.statusCode === 417) {\n throw e\n }\n // If I get an error, it is also responsibility of the next call, but I give a warning\n console.warn(e.message)\n this.error = e\n\n return []\n })\n : Promise.resolve([])\n } else if (!!this.error) {\n // If I have no more states, I throw the last error or a default one\n throw this.error\n } else {\n throw new Error('Cannot authenticate')\n }\n }\n\n invalidateHeader(error: Error): void {\n this.error = error\n if (!!this.currentState) {\n this.stateMap[this.currentState].state?.invalidateHeader(error)\n }\n }\n}\n"]}
@@ -4,15 +4,16 @@ import { IccAuthApi } from '../../icc-api';
4
4
  import Header = XHR.Header;
5
5
  export declare class JwtAuthService implements AuthService {
6
6
  private authApi;
7
- private username;
8
- private password;
9
7
  private _error;
10
8
  private _currentPromise;
11
- constructor(authApi: IccAuthApi, username: string, password: string);
9
+ constructor(authApi: IccAuthApi, token: string, refreshToken: string);
10
+ getIcureTokens(): Promise<{
11
+ token: string;
12
+ refreshToken: string;
13
+ } | undefined>;
12
14
  getAuthHeaders(): Promise<Array<Header>>;
13
15
  private _refreshAuthJwt;
14
- private _loginAndGetTokens;
15
- private _isJwtExpired;
16
+ private _isJwtInvalidOrExpired;
16
17
  private _base64Decode;
17
18
  invalidateHeader(error: Error): void;
18
19
  isInErrorState(): boolean;
@@ -11,21 +11,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.JwtAuthService = void 0;
13
13
  const XHR_1 = require("../../icc-api/api/XHR");
14
- const LoginCredentials_1 = require("../../icc-api/model/LoginCredentials");
15
14
  const utils_1 = require("../utils");
16
15
  class JwtAuthService {
17
- constructor(authApi, username, password) {
16
+ constructor(authApi, token, refreshToken) {
18
17
  this.authApi = authApi;
19
- this.username = username;
20
- this.password = password;
21
18
  this._error = null;
22
- this._currentPromise = Promise.resolve({});
19
+ this._currentPromise = Promise.resolve({ authJwt: token, refreshJwt: refreshToken });
20
+ }
21
+ getIcureTokens() {
22
+ return this._currentPromise.then(({ authJwt, refreshJwt }) => ({ token: authJwt, refreshToken: refreshJwt }));
23
23
  }
24
24
  getAuthHeaders() {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
26
  return this._currentPromise
27
27
  .then(({ authJwt, refreshJwt }) => {
28
- if (!authJwt || this._isJwtExpired(authJwt)) {
28
+ if (!authJwt || this._isJwtInvalidOrExpired(authJwt)) {
29
29
  // If it does not have the JWT, tries to get it
30
30
  // If the JWT is expired, tries to refresh it
31
31
  this._currentPromise = this._refreshAuthJwt(refreshJwt).then((updatedTokens) => {
@@ -51,8 +51,8 @@ class JwtAuthService {
51
51
  return __awaiter(this, void 0, void 0, function* () {
52
52
  // If I do not have a refresh JWT or the refresh JWT is expired,
53
53
  // I have to log in again
54
- if (!refreshJwt || this._isJwtExpired(refreshJwt)) {
55
- return this._loginAndGetTokens();
54
+ if (this._isJwtInvalidOrExpired(refreshJwt)) {
55
+ throw Error('Missing or expired refresh token: please log in again');
56
56
  }
57
57
  else {
58
58
  return this.authApi.refreshAuthenticationJWT(refreshJwt).then((refreshResponse) => ({
@@ -62,25 +62,13 @@ class JwtAuthService {
62
62
  }
63
63
  });
64
64
  }
65
- _loginAndGetTokens() {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- return this.authApi
68
- .login(new LoginCredentials_1.LoginCredentials({
69
- username: this.username,
70
- password: this.password,
71
- }))
72
- .then((authResponse) => ({
73
- authJwt: authResponse.token,
74
- refreshJwt: authResponse.refreshToken,
75
- }));
76
- });
77
- }
78
- _isJwtExpired(jwt) {
65
+ _isJwtInvalidOrExpired(jwt) {
79
66
  const parts = jwt.split('.');
80
67
  if (parts.length !== 3) {
81
- return false;
68
+ return true;
82
69
  }
83
70
  const payload = this._base64Decode(parts[1]);
71
+ // Using the 'exp' string is safe to use as it is part of the JWT RFC and cannot be modified by us.
84
72
  return !('exp' in payload) || payload['exp'] * 1000 < new Date().getTime();
85
73
  }
86
74
  _base64Decode(encodedString) {
@@ -1 +1 @@
1
- {"version":3,"file":"JwtAuthService.js","sourceRoot":"","sources":["../../../icc-x-api/auth/JwtAuthService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,+CAA2C;AAE3C,2EAAuE;AAEvE,oCAA8B;AAE9B,MAAa,cAAc;IAIzB,YAAoB,OAAmB,EAAU,QAAgB,EAAU,QAAgB;QAAvE,YAAO,GAAP,OAAO,CAAY;QAAU,aAAQ,GAAR,QAAQ,CAAQ;QAAU,aAAQ,GAAR,QAAQ,CAAQ;QAHnF,WAAM,GAAiB,IAAI,CAAA;QAC3B,oBAAe,GAAuD,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;IAEH,CAAC;IAEzF,cAAc;;YAClB,OAAO,IAAI,CAAC,eAAe;iBACxB,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE;gBAChC,IAAI,CA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B,CAAC;gBACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;gBACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;aACxB,CAAC,CACH;iBACA,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;gBACvB,OAAO,EAAE,YAAY,CAAC,KAAK;gBAC3B,UAAU,EAAE,YAAY,CAAC,YAAY;aACtC,CAAC,CAAC,CAAA;QACP,CAAC;KAAA;IAEO,aAAa,CAAC,GAAW;QAC/B,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAC5B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;YACtB,OAAO,KAAK,CAAA;SACb;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QAC5C,OAAO,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;IAC5E,CAAC;IAEO,aAAa,CAAC,aAAqB;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,WAAG,EAAC,aAAa,CAAC,CAAC,CAAA;IACvC,CAAC;IAED,gBAAgB,CAAC,KAAY;QAC3B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAED,cAAc;QACZ,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAA;IACtB,CAAC;CACF;AA/ED,wCA+EC","sourcesContent":["import { AuthService } from './AuthService'\nimport { XHR } from '../../icc-api/api/XHR'\nimport { IccAuthApi } from '../../icc-api'\nimport { LoginCredentials } from '../../icc-api/model/LoginCredentials'\nimport Header = XHR.Header\nimport { a2b } from '../utils'\n\nexport class JwtAuthService implements AuthService {\n private _error: Error | null = null\n private _currentPromise: Promise<{ authJwt?: string; refreshJwt?: string }> = Promise.resolve({})\n\n constructor(private authApi: IccAuthApi, private username: string, private password: string) {}\n\n async getAuthHeaders(): Promise<Array<Header>> {\n return this._currentPromise\n .then(({ authJwt, refreshJwt }) => {\n if (!authJwt || this._isJwtExpired(authJwt)) {\n // If it does not have the JWT, tries to get it\n // If the JWT is expired, tries to refresh it\n\n this._currentPromise = this._refreshAuthJwt(refreshJwt).then((updatedTokens) => {\n // If here the token is null,\n // it goes in a suspension status\n if (!updatedTokens.authJwt) {\n throw new Error('Your iCure back-end version does not support JWT authentication')\n }\n\n return updatedTokens\n })\n } else if (!!this._error) {\n throw this._error\n }\n return this._currentPromise\n })\n .then(({ authJwt }) => {\n return [new XHR.Header('Authorization', `Bearer ${authJwt}`)]\n })\n }\n\n private async _refreshAuthJwt(refreshJwt: string | undefined): Promise<{ authJwt?: string; refreshJwt?: string }> {\n // If I do not have a refresh JWT or the refresh JWT is expired,\n // I have to log in again\n if (!refreshJwt || this._isJwtExpired(refreshJwt)) {\n return this._loginAndGetTokens()\n } else {\n return this.authApi.refreshAuthenticationJWT(refreshJwt).then((refreshResponse) => ({\n authJwt: refreshResponse.token,\n refreshJwt: refreshJwt,\n }))\n }\n }\n\n private async _loginAndGetTokens(): Promise<{ authJwt?: string; refreshJwt?: string }> {\n return this.authApi\n .login(\n new LoginCredentials({\n username: this.username,\n password: this.password,\n })\n )\n .then((authResponse) => ({\n authJwt: authResponse.token,\n refreshJwt: authResponse.refreshToken,\n }))\n }\n\n private _isJwtExpired(jwt: string): boolean {\n const parts = jwt.split('.')\n if (parts.length !== 3) {\n return false\n }\n const payload = this._base64Decode(parts[1])\n return !('exp' in payload) || payload['exp'] * 1000 < new Date().getTime()\n }\n\n private _base64Decode(encodedString: string): any {\n return JSON.parse(a2b(encodedString))\n }\n\n invalidateHeader(error: Error): void {\n this._error = error\n }\n\n isInErrorState(): boolean {\n return !!this._error\n }\n}\n"]}
1
+ {"version":3,"file":"JwtAuthService.js","sourceRoot":"","sources":["../../../icc-x-api/auth/JwtAuthService.ts"],"names":[],"mappings":";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C;CACF;AAxED,wCAwEC","sourcesContent":["import { AuthService } from './AuthService'\nimport { XHR } from '../../icc-api/api/XHR'\nimport { IccAuthApi, OAuthThirdParty } from '../../icc-api'\nimport { LoginCredentials } from '../../icc-api/model/LoginCredentials'\nimport Header = XHR.Header\nimport { a2b } from '../utils'\nimport { AuthenticationResponse } from '../../icc-api/model/AuthenticationResponse'\nimport XHRError = XHR.XHRError\n\nexport class JwtAuthService implements AuthService {\n private _error: Error | null = null\n private _currentPromise: Promise<{ authJwt: string; refreshJwt: string }>\n\n constructor(private authApi: IccAuthApi, token: string, refreshToken: string) {\n this._currentPromise = Promise.resolve({ authJwt: token, refreshJwt: refreshToken })\n }\n\n getIcureTokens(): Promise<{ token: string; refreshToken: string } | undefined> {\n return this._currentPromise.then(({ authJwt, refreshJwt }) => ({ token: authJwt, refreshToken: refreshJwt }))\n }\n\n async getAuthHeaders(): Promise<Array<Header>> {\n return this._currentPromise\n .then(({ authJwt, refreshJwt }) => {\n if (!authJwt || this._isJwtInvalidOrExpired(authJwt)) {\n // If it does not have the JWT, tries to get it\n // If the JWT is expired, tries to refresh it\n\n this._currentPromise = this._refreshAuthJwt(refreshJwt).then((updatedTokens) => {\n // If here the token is null,\n // it goes in a suspension status\n if (!updatedTokens.authJwt) {\n throw new Error('Your iCure back-end version does not support JWT authentication')\n }\n\n return updatedTokens\n })\n } else if (!!this._error) {\n throw this._error\n }\n return this._currentPromise\n })\n .then(({ authJwt }) => {\n return [new XHR.Header('Authorization', `Bearer ${authJwt}`)]\n })\n }\n\n private async _refreshAuthJwt(refreshJwt: string): Promise<{ authJwt: string; refreshJwt: string }> {\n // If I do not have a refresh JWT or the refresh JWT is expired,\n // I have to log in again\n if (this._isJwtInvalidOrExpired(refreshJwt)) {\n throw Error('Missing or expired refresh token: please log in again')\n } else {\n return this.authApi.refreshAuthenticationJWT(refreshJwt).then((refreshResponse) => ({\n authJwt: refreshResponse.token!,\n refreshJwt: refreshJwt,\n }))\n }\n }\n\n private _isJwtInvalidOrExpired(jwt: string): boolean {\n const parts = jwt.split('.')\n if (parts.length !== 3) {\n return true\n }\n const payload = this._base64Decode(parts[1])\n // Using the 'exp' string is safe to use as it is part of the JWT RFC and cannot be modified by us.\n return !('exp' in payload) || payload['exp'] * 1000 < new Date().getTime()\n }\n\n private _base64Decode(encodedString: string): any {\n return JSON.parse(a2b(encodedString))\n }\n\n invalidateHeader(error: Error): void {\n this._error = error\n }\n\n isInErrorState(): boolean {\n return !!this._error\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { AuthService } from './AuthService';
2
+ import { XHR } from '../../icc-api/api/XHR';
3
+ import { IccAuthApi } from '../../icc-api';
4
+ import Header = XHR.Header;
5
+ export declare class JwtBridgedAuthService implements AuthService {
6
+ private authApi;
7
+ private username;
8
+ private password;
9
+ private thirdPartyTokens;
10
+ private _error;
11
+ private _currentPromise;
12
+ constructor(authApi: IccAuthApi, username: string, password: string, thirdPartyTokens?: {
13
+ [thirdParty: string]: string;
14
+ });
15
+ getIcureTokens(): Promise<{
16
+ token: string;
17
+ refreshToken: string;
18
+ } | undefined>;
19
+ getAuthHeaders(): Promise<Array<Header>>;
20
+ private _refreshAuthJwt;
21
+ private _loginAndGetTokens;
22
+ private _isJwtInvalidOrExpired;
23
+ private _base64Decode;
24
+ invalidateHeader(error: Error): void;
25
+ isInErrorState(): boolean;
26
+ }
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.JwtBridgedAuthService = void 0;
13
+ const XHR_1 = require("../../icc-api/api/XHR");
14
+ const LoginCredentials_1 = require("../../icc-api/model/LoginCredentials");
15
+ const utils_1 = require("../utils");
16
+ var XHRError = XHR_1.XHR.XHRError;
17
+ class JwtBridgedAuthService {
18
+ constructor(authApi, username, password, thirdPartyTokens = {}) {
19
+ this.authApi = authApi;
20
+ this.username = username;
21
+ this.password = password;
22
+ this.thirdPartyTokens = thirdPartyTokens;
23
+ this._error = null;
24
+ this._currentPromise = Promise.resolve({});
25
+ }
26
+ getIcureTokens() {
27
+ return this.getAuthHeaders().then(() => this._currentPromise.then(({ authJwt, refreshJwt }) => ({ token: authJwt, refreshToken: refreshJwt })));
28
+ }
29
+ getAuthHeaders() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ return this._currentPromise
32
+ .then(({ authJwt, refreshJwt }) => {
33
+ if (!authJwt || this._isJwtInvalidOrExpired(authJwt)) {
34
+ // If it does not have the JWT, tries to get it
35
+ // If the JWT is expired, tries to refresh it
36
+ this._currentPromise = this._refreshAuthJwt(refreshJwt).then((updatedTokens) => {
37
+ // If here the token is null,
38
+ // it goes in a suspension status
39
+ if (!updatedTokens.authJwt) {
40
+ throw new Error('Your iCure back-end version does not support JWT authentication');
41
+ }
42
+ return updatedTokens;
43
+ });
44
+ }
45
+ else if (!!this._error) {
46
+ throw this._error;
47
+ }
48
+ return this._currentPromise;
49
+ })
50
+ .then(({ authJwt }) => {
51
+ return [new XHR_1.XHR.Header('Authorization', `Bearer ${authJwt}`)];
52
+ });
53
+ });
54
+ }
55
+ _refreshAuthJwt(refreshJwt) {
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ // If I do not have a refresh JWT or the refresh JWT is expired,
58
+ // I have to log in again
59
+ if (!refreshJwt || this._isJwtInvalidOrExpired(refreshJwt)) {
60
+ return this._loginAndGetTokens();
61
+ }
62
+ else {
63
+ return this.authApi.refreshAuthenticationJWT(refreshJwt).then((refreshResponse) => ({
64
+ authJwt: refreshResponse.token,
65
+ refreshJwt: refreshJwt,
66
+ }));
67
+ }
68
+ });
69
+ }
70
+ _loginAndGetTokens() {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ let authResponse;
73
+ let firstError;
74
+ if (this.username && this.password) {
75
+ try {
76
+ authResponse = yield this.authApi.login(new LoginCredentials_1.LoginCredentials({
77
+ username: this.username,
78
+ password: this.password,
79
+ }));
80
+ }
81
+ catch (e) {
82
+ firstError = e;
83
+ }
84
+ }
85
+ if (!authResponse) {
86
+ authResponse = yield Object.entries(this.thirdPartyTokens).reduce((acc, [thirdParty, token]) => __awaiter(this, void 0, void 0, function* () {
87
+ const prev = yield acc;
88
+ return (prev !== null && prev !== void 0 ? prev : (token
89
+ ? this.authApi.loginWithThirdPartyToken(thirdParty, token).catch((e) => {
90
+ if (!firstError) {
91
+ firstError = e;
92
+ }
93
+ return Promise.resolve();
94
+ })
95
+ : undefined));
96
+ }), Promise.resolve());
97
+ }
98
+ if (!authResponse) {
99
+ if (firstError)
100
+ throw firstError;
101
+ throw new XHRError('', 'Unknown error', 401, 'Unauthorized', new Headers());
102
+ }
103
+ return {
104
+ authJwt: authResponse.token,
105
+ refreshJwt: authResponse.refreshToken,
106
+ };
107
+ });
108
+ }
109
+ _isJwtInvalidOrExpired(jwt) {
110
+ const parts = jwt.split('.');
111
+ if (parts.length !== 3) {
112
+ return true;
113
+ }
114
+ const payload = this._base64Decode(parts[1]);
115
+ // Using the 'exp' string is safe to use as it is part of the JWT RFC and cannot be modified by us.
116
+ return !('exp' in payload) || payload['exp'] * 1000 < new Date().getTime();
117
+ }
118
+ _base64Decode(encodedString) {
119
+ return JSON.parse((0, utils_1.a2b)(encodedString));
120
+ }
121
+ invalidateHeader(error) {
122
+ this._error = error;
123
+ }
124
+ isInErrorState() {
125
+ return !!this._error;
126
+ }
127
+ }
128
+ exports.JwtBridgedAuthService = JwtBridgedAuthService;
129
+ //# sourceMappingURL=JwtB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AAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;QAC5C,mGAAmG;QACnG,OAAO,CAAC,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;IAC5E,CAAC;IAEO,aAAa,CAAC,aAAqB;QACzC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,WAAG,EAAC,aAAa,CAAC,CAAC,CAAA;IACvC,CAAC;IAED,gBAAgB,CAAC,KAAY;QAC3B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAED,cAAc;QACZ,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAA;IACtB,CAAC;CACF;AAtHD,sDAsHC","sourcesContent":["import { AuthService } from './AuthService'\nimport { XHR } from '../../icc-api/api/XHR'\nimport { IccAuthApi, OAuthThirdParty } from '../../icc-api'\nimport { LoginCredentials } from '../../icc-api/model/LoginCredentials'\nimport Header = XHR.Header\nimport { a2b } from '../utils'\nimport { AuthenticationResponse } from '../../icc-api/model/AuthenticationResponse'\nimport XHRError = XHR.XHRError\n\nexport class JwtBridgedAuthService implements AuthService {\n private _error: Error | null = null\n private _currentPromise: Promise<{ authJwt?: string; refreshJwt?: string }> = Promise.resolve({})\n\n constructor(\n private authApi: IccAuthApi,\n private username: string,\n private password: string,\n private thirdPartyTokens: { [thirdParty: string]: string } = {}\n ) {}\n\n getIcureTokens(): Promise<{ token: string; refreshToken: string } | undefined> {\n return this.getAuthHeaders().then(() => this._currentPromise.then(({ authJwt, refreshJwt }) => ({ token: authJwt!, refreshToken: refreshJwt! })))\n }\n\n async getAuthHeaders(): Promise<Array<Header>> {\n return this._currentPromise\n .then(({ authJwt, refreshJwt }) => {\n if (!authJwt || this._isJwtInvalidOrExpired(authJwt)) {\n // If it does not have the JWT, tries to get it\n // If the JWT is expired, tries to refresh it\n\n this._currentPromise = this._refreshAuthJwt(refreshJwt).then((updatedTokens) => {\n // If here the token is null,\n // it goes in a suspension status\n if (!updatedTokens.authJwt) {\n throw new Error('Your iCure back-end version does not support JWT authentication')\n }\n\n return updatedTokens\n })\n } else if (!!this._error) {\n throw this._error\n }\n return this._currentPromise\n })\n .then(({ authJwt }) => {\n return [new XHR.Header('Authorization', `Bearer ${authJwt}`)]\n })\n }\n\n private async _refreshAuthJwt(refreshJwt: string | undefined): Promise<{ authJwt?: string; refreshJwt?: string }> {\n // If I do not have a refresh JWT or the refresh JWT is expired,\n // I have to log in again\n if (!refreshJwt || this._isJwtInvalidOrExpired(refreshJwt)) {\n return this._loginAndGetTokens()\n } else {\n return this.authApi.refreshAuthenticationJWT(refreshJwt).then((refreshResponse) => ({\n authJwt: refreshResponse.token,\n refreshJwt: refreshJwt,\n }))\n }\n }\n\n private async _loginAndGetTokens(): Promise<{ authJwt?: string; refreshJwt?: string }> {\n let authResponse: AuthenticationResponse | undefined\n let firstError: XHRError | undefined\n if (this.username && this.password) {\n try {\n authResponse = await this.authApi.login(\n new LoginCredentials({\n username: this.username,\n password: this.password,\n })\n )\n } catch (e) {\n firstError = e as XHRError\n }\n }\n if (!authResponse) {\n authResponse = await (Object.entries(this.thirdPartyTokens) as [OAuthThirdParty, string][]).reduce(async (acc, [thirdParty, token]) => {\n const prev = await acc\n return (\n prev ??\n (token\n ? this.authApi.loginWithThirdPartyToken(thirdParty, token).catch((e) => {\n if (!firstError) {\n firstError = e as XHRError\n }\n return Promise.resolve() as Promise<undefined>\n })\n : undefined)\n )\n }, Promise.resolve() as Promise<AuthenticationResponse | undefined>)\n }\n\n if (!authResponse) {\n if (firstError) throw firstError\n throw new XHRError('', 'Unknown error', 401, 'Unauthorized', new Headers())\n }\n\n return {\n authJwt: authResponse.token,\n refreshJwt: authResponse.refreshToken,\n }\n }\n\n private _isJwtInvalidOrExpired(jwt: string): boolean {\n const parts = jwt.split('.')\n if (parts.length !== 3) {\n return true\n }\n const payload = this._base64Decode(parts[1])\n // Using the 'exp' string is safe to use as it is part of the JWT RFC and cannot be modified by us.\n return !('exp' in payload) || payload['exp'] * 1000 < new Date().getTime()\n }\n\n private _base64Decode(encodedString: string): any {\n return JSON.parse(a2b(encodedString))\n }\n\n invalidateHeader(error: Error): void {\n this._error = error\n }\n\n isInErrorState(): boolean {\n return !!this._error\n }\n}\n"]}
@@ -12,6 +12,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.AES = exports.AESUtils = void 0;
13
13
  const utils_1 = require("../utils");
14
14
  class AESUtils {
15
+ set debug(value) {
16
+ this._debug = value;
17
+ }
15
18
  constructor(crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : {}) {
16
19
  /********* AES Config **********/
17
20
  this.ivLength = 16;
@@ -24,9 +27,6 @@ class AESUtils {
24
27
  this._debug = false;
25
28
  this.crypto = crypto;
26
29
  }
27
- set debug(value) {
28
- this._debug = value;
29
- }
30
30
  encrypt(cryptoKey, plainData, rawKey = '<NA>') {
31
31
  return new Promise((resolve, reject) => {
32
32
  if (plainData instanceof Uint8Array) {
@@ -1 +1 @@
1
- {"version":3,"file":"AES.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/AES.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAuD;AAEvD,MAAa,QAAQ;IAmBnB,YAAY,SAAiB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,EAAa;QAlBvI,iCAAiC;QACjC,aAAQ,GAAG,EAAE,CAAA;QACb,4BAAuB,GAAG,SAAS,CAAA;QAEnC,oBAAe,GAAoB;YACjC,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,GAAG;SACZ,CAAA;QAEO,oBAAe,GAAwB,EAAE,IAAI,EAAE,IAAI,CAAC,uBAAuB,E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port class AESUtils {\n /********* AES Config **********/\n ivLength = 16\n aesAlgorithmEncryptName = 'AES-CBC'\n\n aesKeyGenParams: AesKeyGenParams = {\n name: 'AES-CBC',\n length: 256,\n }\n\n private aesImportParams: AlgorithmIdentifier = { name: this.aesAlgorithmEncryptName }\n\n private crypto: Crypto\n private _debug: boolean = false\n\n set debug(value: boolean) {\n this._debug = value\n }\n\n constructor(crypto: Crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : ({} as Crypto)) {\n this.crypto = crypto\n }\n\n encrypt(cryptoKey: CryptoKey, plainData: ArrayBuffer | Uint8Array, rawKey = '<NA>'): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject: (reason: any) => any) => {\n if (plainData instanceof Uint8Array) {\n const buffer = plainData.buffer\n plainData = (buffer.byteLength > plainData.byteLength ? buffer.slice(0, plainData.byteLength) : buffer) as ArrayBuffer\n }\n const aesAlgorithmEncrypt = {\n name: this.aesAlgorithmEncryptName,\n iv: this.generateIV(this.ivLength),\n }\n this._debug && console.log(`encrypt ${ua2hex(plainData)} with ${rawKey}`)\n this.crypto.subtle\n .encrypt(\n {\n ...aesAlgorithmEncrypt,\n } /* some ill behaved implementations change the values in place */,\n cryptoKey,\n plainData\n )\n .then(\n (cipherData) => {\n this._debug && console.log(`cipherData: ${ua2hex(cipherData)}`)\n return resolve(appendBuffer(aesAlgorithmEncrypt.iv.buffer as ArrayBuffer, cipherData))\n },\n (err) => reject('AES encryption failed: ' + err)\n )\n })\n }\n\n /**\n *\n * @param cryptoKey (CryptoKey)\n * @param encryptedData (ArrayBuffer)\n * @param rawKey\n * @returns {Promise} will be ArrayBuffer\n */\n decrypt(cryptoKey: CryptoKey, encryptedData: ArrayBuffer | Uint8Array, rawKey = '<NA>'): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject: (reason: any) => any) => {\n if (!cryptoKey) {\n return reject('No crypto key provided for decryption')\n }\n const encryptedDataUint8 = encryptedData instanceof ArrayBuffer ? new Uint8Array(encryptedData) : encryptedData\n const aesAlgorithmEncrypt = {\n name: this.aesAlgorithmEncryptName,\n iv: encryptedDataUint8.subarray(0, this.ivLength),\n\n /*\n * IF THIS BIT OF CODE PRODUCES A DOMEXCEPTION CODE 0 ERROR, IT MIGHT BE RELATED TO THIS:\n *\n * NOTOK:\n * if (!hcparty.hcPartyKeys && !hcparty.hcPartyKeys[hcpartyId] && hcparty.hcPartyKeys[hcpartyId].length !== 2) {\n * throw 'No hcPartyKey for this Healthcare party(' + hcpartyId + ').';\n * }\n * var delegateHcPartyKey = hcparty.hcPartyKeys[hcpartyId][1];\n *\n * SHOULD BE:\n * var delegatorId = patient.delegations[hcpartyId][0].owner;\n * if (!hcparty.hcPartyKeys && !hcparty.hcPartyKeys[delegatorId] && hcparty.hcPartyKeys[delegatorId].length !== 2) {\n * throw 'No hcPartyKey for this Healthcare party(' + delegatorId + ').';\n * }\n * var delegateHcPartyKey = hcparty.hcPartyKeys[delegatorId][1];\n */\n }\n this._debug && console.log(`decrypt ${ua2hex(encryptedData)} with ${rawKey}`)\n this.crypto.subtle.decrypt(aesAlgorithmEncrypt, cryptoKey, encryptedDataUint8.subarray(this.ivLength, encryptedDataUint8.length)).then(\n (decipheredData) => {\n this._debug && console.log(`decipheredData: ${ua2hex(decipheredData)}`)\n resolve(decipheredData)\n },\n (err) => {\n reject('AES decryption failed: ' + err)\n }\n )\n })\n }\n\n async decryptSome(cryptoKeys: CryptoKey[], uint8Array: Uint8Array): Promise<ArrayBuffer> {\n try {\n return this.decrypt(cryptoKeys[0], uint8Array)\n } catch (e) {\n if (cryptoKeys.length > 1) {\n return this.decryptSome(cryptoKeys.slice(1), uint8Array)\n } else {\n throw e\n }\n }\n }\n\n // generate an AES key\n // noinspection JSUnusedGlobalSymbols\n /**\n *\n * @param toHex boolean, if true, it returns hex String\n * @returns {Promise} either Hex string or CryptoKey\n */\n generateCryptoKey(toHex: false): Promise<CryptoKey>\n generateCryptoKey(toHex: true): Promise<string>\n generateCryptoKey(toHex: boolean): Promise<string | CryptoKey> {\n return new Promise((resolve: (value: CryptoKey | string) => any, reject: (reason: any) => any) => {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n const cryptoKeyPromise: Promise<CryptoKey> = this.crypto.subtle.generateKey(this.aesKeyGenParams, extractable, keyUsages) as Promise<CryptoKey>\n return toHex === undefined || !toHex\n ? cryptoKeyPromise.then(resolve, reject)\n : cryptoKeyPromise.then((k) => this.exportKey(k, 'raw'), reject).then((raw) => resolve(ua2hex(raw)), reject)\n })\n }\n\n // noinspection JSMethodCanBeStatic\n generateIV(ivByteLength: number): Uint8Array {\n return new Uint8Array(this.crypto.getRandomValues(new Uint8Array(ivByteLength)))\n }\n\n /**\n * This function return a promise which will be the key Format will be either 'raw' or 'jwk'.\n * JWK: Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11)\n *\n * @param cryptoKey CryptoKey\n * @param format will be 'raw' or 'jwk'\n * @returns {Promise} will the AES Key\n */\n exportKey(cryptoKey: CryptoKey, format: 'raw'): Promise<ArrayBuffer>\n exportKey(cryptoKey: CryptoKey, format: 'jwk'): Promise<JsonWebKey>\n exportKey(cryptoKey: CryptoKey, format: 'jwk' | 'raw'): Promise<ArrayBuffer | JsonWebKey> {\n return new Promise((resolve: (value: ArrayBuffer | JsonWebKey) => any, reject: (reason: any) => any) => {\n return this.crypto.subtle.exportKey(format as any, cryptoKey).then(resolve, reject)\n })\n }\n\n /**\n * the ability to import a key that have already been created elsewhere, for use within the web\n * application that is invoking the import function, for use within the importing web application's\n * origin. This necessiates an interoperable key format, such as JSON Web Key [JWK] which may be\n * represented as octets.\n *\n * https://chromium.googlesource.com/chromium/blink.git/+/6b902997e3ca0384c8fa6fe56f79ecd7589d3ca6/LayoutTests/crypto/resources/common.js\n *\n * @param format 'raw' or 'jwk'\n * @param aesKey\n * @returns {*}\n */\n importKey(format: 'jwk' | 'raw', aesKey: JsonWebKey | ArrayBuffer | Uint8Array): Promise<CryptoKey> {\n return new Promise((resolve: (value: CryptoKey) => any, reject: (reason: any) => any) => {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n return this.crypto.subtle\n .importKey(format as any, aesKey as any, this.aesImportParams, extractable, keyUsages)\n .catch((err) => {\n if (format == 'raw' && (aesKey instanceof ArrayBuffer || ArrayBuffer.isView(aesKey))) {\n console.warn(`Import of key ${ua2hex(aesKey)} failed`)\n }\n throw err\n })\n .then(resolve, reject)\n })\n }\n}\n\nexport const AES = new AESUtils()\n"]}
1
+ {"version":3,"file":"AES.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/AES.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAuD;AAEvD,MAAa,QAAQ;IAenB,IAAI,KAAK,CAAC,KAAc;QACtB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;IACrB,CAAC;IAED,YAAY,SAAiB,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAE,EAAa;QAlBvI,iCAAiC;QACjC,aAAQ,GAAG,EAAE,CAAA;QACb,4BAAuB,GAAG,SAAS,CAAA;QAEnC,oBAAe,GAAoB;YACjC,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,GAAG;SACZ,CAAA;QAEO,oBAAe,GAAwB,EAAE,IAAI,EAAE,IAAI,CAAC,uBAAuB,EAAE,CAAA;QAG7E,WAAM,GAAY,KAAK,CAAA;QAO7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,OAAO,CAAC,SAAoB,EAAE,SAAmC,EAAE,MAAM,GAAG,MAAM;QAChF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAoC,EAAE,MAA4B,EAAE,EAAE;YACxF,IAAI,SAAS,YAAY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AAA;QACrF,CAAC,CAAC,CAAA;IACJ,CAAC;IAED;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,MAAqB,EAAE,MAA6C;QAC5E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAkC,EAAE,MAA4B,EAAE,EAAE;YACtF,MAAM,WAAW,GAAG,IAAI,CAAA;YACxB,MAAM,SAAS,GAAe,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;YACpD,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM;iBACtB,SAAS,CAAC,MAAa,EAAE,MAAa,EAAE,IAAI,CAAC,eAAe,EAAE,WAAW,EAAE,SAAS,CAAC;iBACrF,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;gBACb,IAAI,MAAM,IAAI,KAAK,IAAI,CAAC,MAAM,YAAY,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE;oBACpF,OAAO,CAAC,IAAI,CAAC,iBAAiB,IAAA,cAAM,EAAC,MAAM,CAAC,SAAS,CAAC,CAAA;iBACvD;gBACD,MAAM,GAAG,CAAA;YACX,CAAC,CAAC;iBACD,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QAC1B,CAAC,CAAC,CAAA;IACJ,CAAC;CACF;AAnLD,4BAmLC;AAEY,QAAA,GAAG,GAAG,IAAI,QAAQ,EAAE,CAAA","sourcesContent":["import { appendBuffer, hex2ua, ua2hex } from '../utils'\n\nexport class AESUtils {\n /********* AES Config **********/\n ivLength = 16\n aesAlgorithmEncryptName = 'AES-CBC'\n\n aesKeyGenParams: AesKeyGenParams = {\n name: 'AES-CBC',\n length: 256,\n }\n\n private aesImportParams: AlgorithmIdentifier = { name: this.aesAlgorithmEncryptName }\n\n private crypto: Crypto\n private _debug: boolean = false\n\n set debug(value: boolean) {\n this._debug = value\n }\n\n constructor(crypto: Crypto = typeof window !== 'undefined' ? window.crypto : typeof self !== 'undefined' ? self.crypto : ({} as Crypto)) {\n this.crypto = crypto\n }\n\n encrypt(cryptoKey: CryptoKey, plainData: ArrayBuffer | Uint8Array, rawKey = '<NA>'): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject: (reason: any) => any) => {\n if (plainData instanceof Uint8Array) {\n const buffer = plainData.buffer\n plainData = (buffer.byteLength > plainData.byteLength ? buffer.slice(0, plainData.byteLength) : buffer) as ArrayBuffer\n }\n const aesAlgorithmEncrypt = {\n name: this.aesAlgorithmEncryptName,\n iv: this.generateIV(this.ivLength),\n }\n this._debug && console.log(`encrypt ${ua2hex(plainData)} with ${rawKey}`)\n this.crypto.subtle\n .encrypt(\n {\n ...aesAlgorithmEncrypt,\n } /* some ill behaved implementations change the values in place */,\n cryptoKey,\n plainData\n )\n .then(\n (cipherData) => {\n this._debug && console.log(`cipherData: ${ua2hex(cipherData)}`)\n return resolve(appendBuffer(aesAlgorithmEncrypt.iv.buffer as ArrayBuffer, cipherData))\n },\n (err) => reject('AES encryption failed: ' + err)\n )\n })\n }\n\n /**\n *\n * @param cryptoKey (CryptoKey)\n * @param encryptedData (ArrayBuffer)\n * @param rawKey\n * @returns {Promise} will be ArrayBuffer\n */\n decrypt(cryptoKey: CryptoKey, encryptedData: ArrayBuffer | Uint8Array, rawKey = '<NA>'): Promise<ArrayBuffer> {\n return new Promise((resolve: (value: ArrayBuffer) => any, reject: (reason: any) => any) => {\n if (!cryptoKey) {\n return reject('No crypto key provided for decryption')\n }\n const encryptedDataUint8 = encryptedData instanceof ArrayBuffer ? new Uint8Array(encryptedData) : encryptedData\n const aesAlgorithmEncrypt = {\n name: this.aesAlgorithmEncryptName,\n iv: encryptedDataUint8.subarray(0, this.ivLength),\n\n /*\n * IF THIS BIT OF CODE PRODUCES A DOMEXCEPTION CODE 0 ERROR, IT MIGHT BE RELATED TO THIS:\n *\n * NOTOK:\n * if (!hcparty.hcPartyKeys && !hcparty.hcPartyKeys[hcpartyId] && hcparty.hcPartyKeys[hcpartyId].length !== 2) {\n * throw 'No hcPartyKey for this Healthcare party(' + hcpartyId + ').';\n * }\n * var delegateHcPartyKey = hcparty.hcPartyKeys[hcpartyId][1];\n *\n * SHOULD BE:\n * var delegatorId = patient.delegations[hcpartyId][0].owner;\n * if (!hcparty.hcPartyKeys && !hcparty.hcPartyKeys[delegatorId] && hcparty.hcPartyKeys[delegatorId].length !== 2) {\n * throw 'No hcPartyKey for this Healthcare party(' + delegatorId + ').';\n * }\n * var delegateHcPartyKey = hcparty.hcPartyKeys[delegatorId][1];\n */\n }\n this._debug && console.log(`decrypt ${ua2hex(encryptedData)} with ${rawKey}`)\n this.crypto.subtle.decrypt(aesAlgorithmEncrypt, cryptoKey, encryptedDataUint8.subarray(this.ivLength, encryptedDataUint8.length)).then(\n (decipheredData) => {\n this._debug && console.log(`decipheredData: ${ua2hex(decipheredData)}`)\n resolve(decipheredData)\n },\n (err) => {\n reject('AES decryption failed: ' + err)\n }\n )\n })\n }\n\n async decryptSome(cryptoKeys: CryptoKey[], uint8Array: Uint8Array): Promise<ArrayBuffer> {\n try {\n return this.decrypt(cryptoKeys[0], uint8Array)\n } catch (e) {\n if (cryptoKeys.length > 1) {\n return this.decryptSome(cryptoKeys.slice(1), uint8Array)\n } else {\n throw e\n }\n }\n }\n\n // generate an AES key\n // noinspection JSUnusedGlobalSymbols\n /**\n *\n * @param toHex boolean, if true, it returns hex String\n * @returns {Promise} either Hex string or CryptoKey\n */\n generateCryptoKey(toHex: false): Promise<CryptoKey>\n generateCryptoKey(toHex: true): Promise<string>\n generateCryptoKey(toHex: boolean): Promise<string | CryptoKey> {\n return new Promise((resolve: (value: CryptoKey | string) => any, reject: (reason: any) => any) => {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n const cryptoKeyPromise: Promise<CryptoKey> = this.crypto.subtle.generateKey(this.aesKeyGenParams, extractable, keyUsages) as Promise<CryptoKey>\n return toHex === undefined || !toHex\n ? cryptoKeyPromise.then(resolve, reject)\n : cryptoKeyPromise.then((k) => this.exportKey(k, 'raw'), reject).then((raw) => resolve(ua2hex(raw)), reject)\n })\n }\n\n // noinspection JSMethodCanBeStatic\n generateIV(ivByteLength: number): Uint8Array {\n return new Uint8Array(this.crypto.getRandomValues(new Uint8Array(ivByteLength)))\n }\n\n /**\n * This function return a promise which will be the key Format will be either 'raw' or 'jwk'.\n * JWK: Json Web key (ref. http://tools.ietf.org/html/draft-ietf-jose-json-web-key-11)\n *\n * @param cryptoKey CryptoKey\n * @param format will be 'raw' or 'jwk'\n * @returns {Promise} will the AES Key\n */\n exportKey(cryptoKey: CryptoKey, format: 'raw'): Promise<ArrayBuffer>\n exportKey(cryptoKey: CryptoKey, format: 'jwk'): Promise<JsonWebKey>\n exportKey(cryptoKey: CryptoKey, format: 'jwk' | 'raw'): Promise<ArrayBuffer | JsonWebKey> {\n return new Promise((resolve: (value: ArrayBuffer | JsonWebKey) => any, reject: (reason: any) => any) => {\n return this.crypto.subtle.exportKey(format as any, cryptoKey).then(resolve, reject)\n })\n }\n\n /**\n * the ability to import a key that have already been created elsewhere, for use within the web\n * application that is invoking the import function, for use within the importing web application's\n * origin. This necessiates an interoperable key format, such as JSON Web Key [JWK] which may be\n * represented as octets.\n *\n * https://chromium.googlesource.com/chromium/blink.git/+/6b902997e3ca0384c8fa6fe56f79ecd7589d3ca6/LayoutTests/crypto/resources/common.js\n *\n * @param format 'raw' or 'jwk'\n * @param aesKey\n * @returns {*}\n */\n importKey(format: 'jwk' | 'raw', aesKey: JsonWebKey | ArrayBuffer | Uint8Array): Promise<CryptoKey> {\n return new Promise((resolve: (value: CryptoKey) => any, reject: (reason: any) => any) => {\n const extractable = true\n const keyUsages: KeyUsage[] = ['decrypt', 'encrypt']\n return this.crypto.subtle\n .importKey(format as any, aesKey as any, this.aesImportParams, extractable, keyUsages)\n .catch((err) => {\n if (format == 'raw' && (aesKey instanceof ArrayBuffer || ArrayBuffer.isView(aesKey))) {\n console.warn(`Import of key ${ua2hex(aesKey)} failed`)\n }\n throw err\n })\n .then(resolve, reject)\n })\n }\n}\n\nexport const AES = new AESUtils()\n"]}
@@ -22,4 +22,5 @@ export declare class ServiceByHcPartyTagCodeDateFilter extends AbstractFilterSer
22
22
  codeCode?: string;
23
23
  startValueDate?: number;
24
24
  endValueDate?: number;
25
+ descending?: boolean;
25
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceByHcPartyTagCodeDateFilter.js","sourceRoot":"","sources":["../../../icc-x-api/filters/ServiceByHcPartyTagCodeDateFilter.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,qFAAiF;AAEjF,MAAa,iCAAkC,SAAQ,6CAAqB;IAE1E,YAAY,IAAgB;QAC1B,KAAK,CAAC,IAAI,CAAC,CAAA;QAFb,UAAK,GAAW,mCAAmC,CAAA;QAIjD,MAAM,CAAC,MAAM,CAAC,IAAyC,EAAE,IAAI,CAAC,CAAA;IAChE,CAAC;CAWF;AAjBD,8EAiBC","sourcesContent":["/**\n * iCure Data Stack API Documentation\n * The iCure Data Stack Application API is the native interface to iCure. This version is obsolete, please use v2.\n *\n * OpenAPI spec version: v1\n *\n *\n * NOTE: This class is auto generated by the swagger code generator program.\n * https://github.com/swagger-api/swagger-codegen.git\n * Do not edit the class manually.\n */\nimport { AbstractFilterService } from '../../icc-api/model/AbstractFilterService'\n\nexport class ServiceByHcPartyTagCodeDateFilter extends AbstractFilterService {\n $type: string = 'ServiceByHcPartyTagCodeDateFilter'\n constructor(json: JSON | any) {\n super(json)\n\n Object.assign(this as ServiceByHcPartyTagCodeDateFilter, json)\n }\n\n desc?: string\n healthcarePartyId?: string\n patientSecretForeignKey?: string\n tagType?: string\n tagCode?: string\n codeType?: string\n codeCode?: string\n startValueDate?: number\n endValueDate?: number\n}\n"]}
1
+ {"version":3,"file":"ServiceByHcPartyTagCodeDateFilter.js","sourceRoot":"","sources":["../../../icc-x-api/filters/ServiceByHcPartyTagCodeDateFilter.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,qFAAiF;AAEjF,MAAa,iCAAkC,SAAQ,6CAAqB;IAE1E,YAAY,IAAgB;QAC1B,KAAK,CAAC,IAAI,CAAC,CAAA;QAFb,UAAK,GAAW,mCAAmC,CAAA;QAIjD,MAAM,CAAC,MAAM,CAAC,IAAyC,EAAE,IAAI,CAAC,CAAA;IAChE,CAAC;CAYF;AAlBD,8EAkBC","sourcesContent":["/**\n * iCure Data Stack API Documentation\n * The iCure Data Stack Application API is the native interface to iCure. This version is obsolete, please use v2.\n *\n * OpenAPI spec version: v1\n *\n *\n * NOTE: This class is auto generated by the swagger code generator program.\n * https://github.com/swagger-api/swagger-codegen.git\n * Do not edit the class manually.\n */\nimport { AbstractFilterService } from '../../icc-api/model/AbstractFilterService'\n\nexport class ServiceByHcPartyTagCodeDateFilter extends AbstractFilterService {\n $type: string = 'ServiceByHcPartyTagCodeDateFilter'\n constructor(json: JSON | any) {\n super(json)\n\n Object.assign(this as ServiceByHcPartyTagCodeDateFilter, json)\n }\n\n desc?: string\n healthcarePartyId?: string\n patientSecretForeignKey?: string\n tagType?: string\n tagCode?: string\n codeType?: string\n codeCode?: string\n startValueDate?: number\n endValueDate?: number\n descending?: boolean\n}\n"]}
@@ -58,7 +58,7 @@ export * from './UserByIdsFilter';
58
58
  export declare class Filter {
59
59
  static patient(): PatientFilterBuilder;
60
60
  }
61
- export declare type AbstractFilter<T> = T extends Patient ? AbstractFilterPatient | ConstantFilter<Patient> | IntersectionFilter<Patient> | UnionFilter<Patient> | ComplementFilter<Patient> : T extends Contact ? AbstractFilterContact | ConstantFilter<T> | IntersectionFilter<T> | UnionFilter<T> | ComplementFilter<T> : T extends Service ? AbstractFilterService | ConstantFilter<T> | IntersectionFilter<T> | UnionFilter<T> | ComplementFilter<T> : ConstantFilter<T> | IntersectionFilter<T> | UnionFilter<T> | ComplementFilter<T>;
61
+ export type AbstractFilter<T> = T extends Patient ? AbstractFilterPatient | ConstantFilter<Patient> | IntersectionFilter<Patient> | UnionFilter<Patient> | ComplementFilter<Patient> : T extends Contact ? AbstractFilterContact | ConstantFilter<T> | IntersectionFilter<T> | UnionFilter<T> | ComplementFilter<T> : T extends Service ? AbstractFilterService | ConstantFilter<T> | IntersectionFilter<T> | UnionFilter<T> | ComplementFilter<T> : ConstantFilter<T> | IntersectionFilter<T> | UnionFilter<T> | ComplementFilter<T>;
62
62
  declare abstract class FilterBuilder<T> {
63
63
  filterProvider?: () => AbstractFilter<T>;
64
64
  composer: (thisFilterBuilder: FilterBuilder<T>, otherFilterBuilder: FilterBuilder<T>) => FilterBuilder<T>;
@@ -5,7 +5,7 @@ import { IccDocumentXApi } from './icc-document-x-api';
5
5
  import { IccHelementXApi } from './icc-helement-x-api';
6
6
  import { Contact, Document, HealthElement, Service } from '../icc-api/model/models';
7
7
  import { AuthenticationProvider } from './auth/AuthenticationProvider';
8
- export declare type Patcher = ContactPatcher | HealthElementPatcher | DocumentPatcher | ServicePatcher;
8
+ export type Patcher = ContactPatcher | HealthElementPatcher | DocumentPatcher | ServicePatcher;
9
9
  export interface ContactPatcher {
10
10
  type: 'ContactDto';
11
11
  patch: (contacts: Contact[]) => Promise<Contact[]>;
@@ -11,7 +11,7 @@ interface DelegatorAndKeys {
11
11
  key: CryptoKey;
12
12
  rawKey: string;
13
13
  }
14
- declare type CachedDataOwner = {
14
+ type CachedDataOwner = {
15
15
  type: 'patient';
16
16
  dataOwner: Patient;
17
17
  } | {
@@ -408,13 +408,11 @@ export declare class IccCryptoXApi {
408
408
  * When a user lost his keys, people to whom he shared information may call this method to give access back to him, re-encrypting their common
409
409
  * AES key using the new user public key.
410
410
  *
411
- * @param delegateUser Delegate Data Owner User, in charge of giving access back to the person who previously gave him some access
412
- * @param ownerId Id of the data owner to which we would like to give access back
411
+ * @param accessGiver User, in charge of giving access back to the person who previously gave him some access (should be the current user)
412
+ * @param ownerId Id of the data owner to which we would like to get access back
413
413
  * @param ownerNewPublicKey New Data Owner Public Key we want to use to re-encrypt previously created AES key
414
- *
415
- * @return The DataOwner, updated by the delegateUser to add the new encrypted AES Key using the new provided public key
416
414
  */
417
- giveAccessBackTo(delegateUser: User, ownerId: string, ownerNewPublicKey: string): Promise<CachedDataOwner>;
415
+ giveAccessBackTo(accessGiver: User, ownerId: string, ownerNewPublicKey: string): Promise<void>;
418
416
  addNewKeyPairForOwnerId(maintenanceTasksApi: IccMaintenanceTaskXApi, user: User, ownerId: string, generateTransferKey?: boolean, sendMaintenanceTasks?: boolean): Promise<{
419
417
  dataOwner: HealthcareParty | Patient | Device;
420
418
  publicKey: string;