@icure/api 4.2.34 → 4.2.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/icc-api/api/IccAuthApi.d.ts +6 -0
- package/icc-api/api/IccAuthApi.js +15 -0
- package/icc-api/api/IccAuthApi.js.map +1 -1
- package/icc-x-api/crypto/utils.js +2 -1
- package/icc-x-api/crypto/utils.js.map +1 -1
- package/icc-x-api/icc-accesslog-x-api.d.ts +3 -3
- package/icc-x-api/icc-accesslog-x-api.js +11 -11
- package/icc-x-api/icc-accesslog-x-api.js.map +1 -1
- package/icc-x-api/icc-calendar-item-x-api.d.ts +3 -3
- package/icc-x-api/icc-calendar-item-x-api.js +13 -13
- package/icc-x-api/icc-calendar-item-x-api.js.map +1 -1
- package/icc-x-api/icc-classification-x-api.d.ts +3 -3
- package/icc-x-api/icc-classification-x-api.js +4 -4
- package/icc-x-api/icc-classification-x-api.js.map +1 -1
- package/icc-x-api/icc-contact-x-api.d.ts +3 -3
- package/icc-x-api/icc-contact-x-api.js +16 -16
- package/icc-x-api/icc-contact-x-api.js.map +1 -1
- package/icc-x-api/icc-crypto-x-api.d.ts +4 -2
- package/icc-x-api/icc-crypto-x-api.js +4 -2
- package/icc-x-api/icc-crypto-x-api.js.map +1 -1
- package/icc-x-api/icc-data-owner-x-api.d.ts +14 -0
- package/icc-x-api/icc-data-owner-x-api.js +44 -0
- package/icc-x-api/icc-data-owner-x-api.js.map +1 -0
- package/icc-x-api/icc-document-x-api.d.ts +3 -3
- package/icc-x-api/icc-document-x-api.js +5 -5
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-form-x-api.d.ts +3 -3
- package/icc-x-api/icc-form-x-api.js +5 -5
- package/icc-x-api/icc-form-x-api.js.map +1 -1
- package/icc-x-api/icc-helement-x-api.d.ts +3 -3
- package/icc-x-api/icc-helement-x-api.js +10 -10
- package/icc-x-api/icc-helement-x-api.js.map +1 -1
- package/icc-x-api/icc-invoice-x-api.d.ts +3 -3
- package/icc-x-api/icc-invoice-x-api.js +5 -5
- package/icc-x-api/icc-invoice-x-api.js.map +1 -1
- package/icc-x-api/icc-maintenance-task-x-api.d.ts +6 -3
- package/icc-x-api/icc-maintenance-task-x-api.js +21 -7
- package/icc-x-api/icc-maintenance-task-x-api.js.map +1 -1
- package/icc-x-api/icc-message-x-api.d.ts +3 -3
- package/icc-x-api/icc-message-x-api.js +4 -4
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.d.ts +3 -3
- package/icc-x-api/icc-patient-x-api.js +9 -9
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/icc-receipt-x-api.d.ts +3 -3
- package/icc-x-api/icc-receipt-x-api.js +5 -5
- package/icc-x-api/icc-receipt-x-api.js.map +1 -1
- package/icc-x-api/icc-time-table-x-api.d.ts +3 -3
- package/icc-x-api/icc-time-table-x-api.js +5 -5
- package/icc-x-api/icc-time-table-x-api.js.map +1 -1
- package/icc-x-api/icc-user-x-api.d.ts +0 -2
- package/icc-x-api/icc-user-x-api.js +0 -8
- package/icc-x-api/icc-user-x-api.js.map +1 -1
- package/icc-x-api/index.d.ts +3 -1
- package/icc-x-api/index.js +28 -20
- package/icc-x-api/index.js.map +1 -1
- package/icc-x-api/utils/uuid-encoder.js +2 -0
- package/icc-x-api/utils/uuid-encoder.js.map +1 -1
- package/package.json +1 -1
|
@@ -19,6 +19,12 @@ export declare class IccAuthApi {
|
|
|
19
19
|
constructor(host: string, headers: any, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
20
20
|
setHeaders(h: Array<XHR.Header>): void;
|
|
21
21
|
handleError(e: XHR.XHRError): never;
|
|
22
|
+
/**
|
|
23
|
+
* Check login using groupId/userId and password
|
|
24
|
+
* @summary check
|
|
25
|
+
* @param body
|
|
26
|
+
*/
|
|
27
|
+
check(body?: LoginCredentials): Promise<AuthenticationResponse>;
|
|
22
28
|
/**
|
|
23
29
|
* Login using username and password
|
|
24
30
|
* @summary login
|
|
@@ -26,6 +26,21 @@ class IccAuthApi {
|
|
|
26
26
|
handleError(e) {
|
|
27
27
|
throw e;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Check login using groupId/userId and password
|
|
31
|
+
* @summary check
|
|
32
|
+
* @param body
|
|
33
|
+
*/
|
|
34
|
+
check(body) {
|
|
35
|
+
let _body = null;
|
|
36
|
+
_body = body;
|
|
37
|
+
const _url = this.host + `/auth/check` + '?ts=' + new Date().getTime();
|
|
38
|
+
let headers = this.headers;
|
|
39
|
+
headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR_1.XHR.Header('Content-Type', 'application/json'));
|
|
40
|
+
return XHR_1.XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl)
|
|
41
|
+
.then((doc) => new AuthenticationResponse_1.AuthenticationResponse(doc.body))
|
|
42
|
+
.catch((err) => this.handleError(err));
|
|
43
|
+
}
|
|
29
44
|
/**
|
|
30
45
|
* Login using username and password
|
|
31
46
|
* @summary login
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IccAuthApi.js","sourceRoot":"","sources":["../../../icc-api/api/IccAuthApi.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;GAUG;AACH,+BAA2B;AAC3B,4EAAwE;AAGxE,MAAa,UAAU;IAKrB,YAAY,IAAY,EAAE,OAAY,EAAE,SAAyE;QAC/G,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,SAAG,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC7E,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;IAC5B,CAAC;IAED,UAAU,CAAC,CAAoB;QAC7B,IAAI,CAAC,O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C1C,CAAC;CACF;AA9GD,gCA8GC","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 { XHR } from './XHR'\nimport { AuthenticationResponse } from '../model/AuthenticationResponse'\nimport { LoginCredentials } from '../model/LoginCredentials'\n\nexport class IccAuthApi {\n host: string\n headers: Array<XHR.Header>\n fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>\n\n constructor(host: string, headers: any, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>) {\n this.host = host\n this.headers = Object.keys(headers).map((k) => new XHR.Header(k, headers[k]))\n this.fetchImpl = fetchImpl\n }\n\n setHeaders(h: Array<XHR.Header>) {\n this.headers = h\n }\n\n handleError(e: XHR.XHRError): never {\n throw e\n }\n\n /**\n * Check login using groupId/userId and password\n * @summary check\n * @param body\n */\n check(body?: LoginCredentials): Promise<AuthenticationResponse> {\n let _body = null\n _body = body\n\n const _url = this.host + `/auth/check` + '?ts=' + new Date().getTime()\n let headers = this.headers\n headers = headers.filter((h) => h.header !== 'Content-Type').concat(new XHR.Header('Content-Type', 'application/json'))\n return XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl)\n .then((doc) => new AuthenticationResponse(doc.body as JSON))\n .catch((err) => this.handleError(err))\n }\n\n /**\n * Login using username and password\n * @summary login\n * @param body\n */\n login(body?: LoginCredentials): Promise<AuthenticationResponse> {\n let _body = null\n _body = body\n\n const _url = this.host + `/auth/login` + '?ts=' + new Date().getTime()\n let headers = this.headers\n headers = headers\n .filter((h) => h.header !== 'Content-Type' && h.header?.toLowerCase() !== 'authorization')\n .concat(new XHR.Header('Content-Type', 'application/json'))\n return XHR.sendCommand('POST', _url, headers, _body, this.fetchImpl, undefined, true)\n .then((doc) => new AuthenticationResponse(doc.body as JSON))\n .catch((err) => this.handleError(err))\n }\n\n /**\n * Logout\n * @summary logout\n */\n logout(): Promise<AuthenticationResponse> {\n let _body = null\n\n const _url = this.host + `/auth/logout` + '?ts=' + new Date().getTime()\n let headers = this.headers\n return XHR.sendCommand(\n 'GET',\n _url,\n headers.filter((h) => h.header?.toLowerCase() !== 'authorization'),\n _body,\n this.fetchImpl\n )\n .then((doc) => new AuthenticationResponse(doc.body as JSON))\n .catch((err) => this.handleError(err))\n }\n\n /**\n * Logout\n * @summary logout\n */\n logoutPost(): Promise<AuthenticationResponse> {\n let _body = null\n\n const _url = this.host + `/auth/logout` + '?ts=' + new Date().getTime()\n let headers = this.headers\n return XHR.sendCommand(\n 'POST',\n _url,\n headers.filter((h) => h.header?.toLowerCase() !== 'authorization'),\n _body,\n this.fetchImpl\n )\n .then((doc) => new AuthenticationResponse(doc.body as JSON))\n .catch((err) => this.handleError(err))\n }\n\n /**\n * Get token for subsequent operation\n * @summary token\n * @param method\n * @param path\n */\n token(method: string, path: string): Promise<string> {\n let _body = null\n\n const _url = this.host + `/auth/token/${encodeURIComponent(String(method))}/${encodeURIComponent(String(path))}` + '?ts=' + new Date().getTime()\n let headers = this.headers\n return XHR.sendCommand('GET', _url, headers, _body, this.fetchImpl)\n .then((doc) => JSON.parse(JSON.stringify(doc.body)))\n .catch((err) => this.handleError(err))\n }\n}\n"]}
|
|
@@ -105,7 +105,8 @@ class UtilsClass {
|
|
|
105
105
|
if (asn1.type === 0x30 &&
|
|
106
106
|
((_b = (_a = asn1.children) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.type) === 0x30 &&
|
|
107
107
|
((_f = (_e = (_d = (_c = asn1.children) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.children) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.type) === 0x06 &&
|
|
108
|
-
binary_utils_1.ua2hex((_l = (_k = (_j = (_h = (_g = asn1.children) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.children) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.value) !== null && _l !== void 0 ? _l : new Uint8Array()) === '2a864886f70d010101')
|
|
108
|
+
binary_utils_1.ua2hex((_l = (_k = (_j = (_h = (_g = asn1.children) === null || _g === void 0 ? void 0 : _g[0]) === null || _h === void 0 ? void 0 : _h.children) === null || _j === void 0 ? void 0 : _j[0]) === null || _k === void 0 ? void 0 : _k.value) !== null && _l !== void 0 ? _l : new Uint8Array()) === '2a864886f70d010101' // pragma: allowlist secret (object identifier of RSA)
|
|
109
|
+
) {
|
|
109
110
|
modulus = (_s = (_r = (_q = (_p = (_o = (_m = asn1.children) === null || _m === void 0 ? void 0 : _m[1]) === null || _o === void 0 ? void 0 : _o.children) === null || _p === void 0 ? void 0 : _p[0]) === null || _q === void 0 ? void 0 : _q.children) === null || _r === void 0 ? void 0 : _r[0]) === null || _s === void 0 ? void 0 : _s.value;
|
|
110
111
|
exponent = (_y = (_x = (_w = (_v = (_u = (_t = asn1.children) === null || _t === void 0 ? void 0 : _t[1]) === null || _u === void 0 ? void 0 : _u.children) === null || _v === void 0 ? void 0 : _v[0]) === null || _w === void 0 ? void 0 : _w.children) === null || _x === void 0 ? void 0 : _x[1]) === null || _y === void 0 ? void 0 : _y.value;
|
|
111
112
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAgC;AAEhC,4BAA2B;AAC3B,wDAAoG;AACpG,sDAA2C;AAC3C,sDAAgD;AAEhD,MAAa,UAAU;IACrB,gBAAe,CAAC;IAEhB,aAAa,CAAI,cAAiD,EAAE,GAAW,EAAE,IAA0B;QACzG,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAA;QACpC,IAAI,CAAC,QAAQ,EAAE;YACb,O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ACH,CAAC,CAAA,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;YACrB,IAAI,GAAG,CAAC,aAAa,EAAE;gBACrB,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,SAAS,CAAC,wBAAS,CAAC,kBAAG,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;aACvE;YACD,OAAO,GAAG,CAAA;QACZ,CAAC;KAAA;CACF;AAxPD,gCAwPC;AAEY,QAAA,KAAK,GAAG,IAAI,UAAU,EAAE,CAAA","sourcesContent":["import * as moment from 'moment'\nimport { Moment } from 'moment'\nimport * as _ from 'lodash'\nimport { a2b, b2a, b64Url2ua, string2ua, ua2b64Url, ua2hex, ua2string } from '../utils/binary-utils'\nimport { pack } from '../utils/asn1-packer'\nimport { parseAsn1 } from '../utils/asn1-parser'\n\nexport class UtilsClass {\n constructor() {}\n\n notConcurrent<T>(concurrencyMap: { [key: string]: PromiseLike<T> }, key: string, proc: () => PromiseLike<T>): PromiseLike<T> {\n const inFlight = concurrencyMap[key]\n if (!inFlight) {\n return (concurrencyMap[key] = (async () => {\n try {\n return await proc()\n } finally {\n delete concurrencyMap[key]\n }\n })())\n } else {\n return concurrencyMap[key].then(() => this.notConcurrent(concurrencyMap, key, proc))\n }\n }\n\n jwk2pkcs8(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x02, '00'],\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]],\n [\n 0x04,\n [\n [\n 0x30,\n [\n [0x02, '00'],\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n [0x02, ua2hex(b64Url2ua(jwk.d))],\n [0x02, ua2hex(b64Url2ua(jwk.p))],\n [0x02, ua2hex(b64Url2ua(jwk.q))],\n [0x02, ua2hex(b64Url2ua(jwk.dp))],\n [0x02, ua2hex(b64Url2ua(jwk.dq))],\n [0x02, ua2hex(b64Url2ua(jwk.qi))],\n ],\n ],\n ],\n ],\n ],\n ])\n }\n\n jwk2pkcs1(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x02, '00'],\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n [0x02, ua2hex(b64Url2ua(jwk.d))],\n [0x02, ua2hex(b64Url2ua(jwk.p))],\n [0x02, ua2hex(b64Url2ua(jwk.q))],\n [0x02, ua2hex(b64Url2ua(jwk.dp))],\n [0x02, ua2hex(b64Url2ua(jwk.dq))],\n [0x02, ua2hex(b64Url2ua(jwk.qi))],\n ],\n ])\n }\n\n jwk2spki(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]],\n [\n 0x03,\n [\n [\n 0x30,\n [\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n ],\n ],\n ],\n ],\n ],\n ])\n }\n\n spkiToJwk(buf: Uint8Array): { kty: string; alg: string; n: string; e: string; ext: boolean } {\n const asn1 = parseAsn1(new Uint8Array(buf))\n\n var modulus: Uint8Array | undefined = undefined\n var exponent: Uint8Array | undefined = undefined\n if (\n asn1.type === 0x30 &&\n asn1.children?.[0]?.type === 0x30 &&\n asn1.children?.[0]?.children?.[0]?.type === 0x06 &&\n ua2hex(asn1.children?.[0]?.children?.[0]?.value ?? new Uint8Array()) === '2a864886f70d010101'\n ) {\n modulus = asn1.children?.[1]?.children?.[0]?.children?.[0]?.value\n exponent = asn1.children?.[1]?.children?.[0]?.children?.[1]?.value\n } else if (asn1.type === 0x30 && asn1.children?.[0]?.type === 0x02 && asn1.children?.[1]?.type === 0x02) {\n modulus = asn1.children?.[0]?.value\n exponent = asn1.children?.[1]?.value\n }\n\n if (!modulus || !exponent) {\n throw new Error('Invalid spki format')\n }\n return {\n kty: 'RSA',\n alg: 'RSA-OAEP',\n ext: true,\n n: ua2b64Url(this.minimalRep(modulus)),\n e: ua2b64Url(this.minimalRep(exponent)),\n }\n }\n\n pkcs8ToJwk(buf: Uint8Array | ArrayBuffer) {\n const parsed = parseAsn1(new Uint8Array(buf))\n const seq =\n parsed.children?.length === 3 && parsed.children[2].type === 0x04 && parsed.children[2].children?.length === 1\n ? parsed.children[2].children[0]\n : parsed\n return {\n kty: 'RSA',\n n: ua2b64Url(this.minimalRep(seq.children![1].value as Uint8Array)),\n e: ua2b64Url(this.minimalRep(seq.children![2].value as Uint8Array)),\n d: ua2b64Url(this.minimalRep(seq.children![3].value as Uint8Array)),\n p: ua2b64Url(this.minimalRep(seq.children![4].value as Uint8Array)),\n q: ua2b64Url(this.minimalRep(seq.children![5].value as Uint8Array)),\n dp: ua2b64Url(this.minimalRep(seq.children![6].value as Uint8Array)),\n dq: ua2b64Url(this.minimalRep(seq.children![7].value as Uint8Array)),\n qi: ua2b64Url(this.minimalRep(seq.children![8].value as Uint8Array)),\n }\n }\n\n minimalRep(b: Uint8Array) {\n let i = 0\n while (b[i] === 0) {\n i++\n }\n return b.slice(i)\n }\n\n /**\n * Provide a view over the given Uint8Array where any trailing null bytes at\n * the end are truncated.\n *\n * This can be used to ignore null bytes at the end of a padded UTF-8 string\n * without needing to copy that string, assuming code point U+0000 is encoded\n * in one null byte according to standards rather than in a multi-byte\n * overlong form.\n */\n truncateTrailingNulls(a: Uint8Array) {\n let end = a.byteLength - 1\n while (a[end] === 0 && end >= 0) {\n end--\n }\n // end is now either the last non-null position in a or -1; in the latter\n // case the returned array will have length 0.\n return a.subarray(0, end + 1)\n }\n\n /**\n *\n * @param buffer1 {Uint8Array}\n * @param buffer2{ Uint8Array}\n * @returns {ArrayBuffer}\n */\n appendBuffer(buffer1: ArrayBuffer, buffer2: ArrayBuffer): ArrayBuffer {\n const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength)\n tmp.set(new Uint8Array(buffer1), 0)\n tmp.set(new Uint8Array(buffer2), buffer1.byteLength)\n return tmp.buffer as ArrayBuffer\n }\n\n //Convenience methods for dates management\n after(d1: number, d2: number): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || this.moment(d1)!.isAfter(this.moment(d2)!)\n }\n\n before(d1: number, d2: number): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || this.moment(d1)!.isBefore(this.moment(d2)!)\n }\n\n moment(epochOrLongCalendar: number): Moment | null {\n if (!epochOrLongCalendar && epochOrLongCalendar !== 0) {\n return null\n }\n if (epochOrLongCalendar >= 18000101 && epochOrLongCalendar < 25400000) {\n return moment('' + epochOrLongCalendar, 'YYYYMMDD')\n } else if (epochOrLongCalendar >= 18000101000000) {\n return moment('' + epochOrLongCalendar, 'YYYYMMDDHHmmss')\n } else {\n return moment(epochOrLongCalendar)\n }\n }\n\n /**\n * Encrypt object graph recursively\n *\n * @param obj the object to encrypt\n * @param cryptor the cryptor function (returns a promise)\n * @param keys the keys to be crypted: ex for a Patient ['note', 'addresses.*.[\"street\", \"houseNumber\", \"telecoms.*.telecomNumber\"]']\n */\n async crypt(obj: any, cryptor: (obj: { [key: string]: string }) => Promise<ArrayBuffer>, keys: Array<string>) {\n const subObj = _.pick(\n obj,\n keys.filter((k) => !k.includes('*'))\n )\n obj.encryptedSelf = b2a(ua2string(await cryptor(subObj)))\n Object.keys(subObj).forEach((k) => delete obj[k])\n\n await keys\n .filter((k) => k.includes('*'))\n .reduce(async (prev: Promise<void>, k: any) => {\n await prev\n const k1 = k.split('.*.')[0]\n const k2 = k.substr(k1.length + 3)\n\n const mapped = await Promise.all((_.get(obj, k1) || []).map((so: any) => this.crypt(so, cryptor, k2.startsWith('[') ? JSON.parse(k2) : [k2])))\n _.set(obj, k1, mapped)\n }, Promise.resolve())\n\n return obj\n }\n\n /**\n * Decrypt object graph recursively\n *\n * @param obj the object to encrypt\n * @param decryptor the decryptor function (returns a promise)\n */\n async decrypt(obj: any, decryptor: (obj: Uint8Array) => Promise<{ [key: string]: string }>) {\n await Object.keys(obj).reduce(async (prev: Promise<void>, k: any) => {\n await prev\n if (Array.isArray(obj[k])) {\n await (obj[k] as Array<any>)\n .filter((o) => typeof o === 'object' && o !== null)\n .reduce(async (prev: Promise<void>, so: any) => {\n await prev\n await this.decrypt(so, decryptor)\n }, Promise.resolve())\n }\n }, Promise.resolve())\n if (obj.encryptedSelf) {\n Object.assign(obj, await decryptor(string2ua(a2b(obj.encryptedSelf))))\n }\n return obj\n }\n}\n\nexport const utils = new UtilsClass()\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAgC;AAEhC,4BAA2B;AAC3B,wDAAoG;AACpG,sDAA2C;AAC3C,sDAAgD;AAEhD,MAAa,UAAU;IACrB,gBAAe,CAAC;IAEhB,aAAa,CAAI,cAAiD,EAAE,GAAW,EAAE,IAA0B;QACzG,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAA;QACpC,IAAI,CAAC,QAAQ,EAAE;YACb,OAAO,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,GAAS,EAAE;gBACxC,IAAI;oBACF,OAAO,MAAM,IAAI,EAAE,CAAA;iBACpB;wBAAS;oBACR,OAAO,cAAc,CAAC,GAAG,CAAC,CAAA;iBAC3B;YACH,CAAC,CAAA,CAAC,EAAE,CAAC,CAAA;SACN;aAAM;YACL,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,cAAc,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAA;SACrF;IACH,CAAC;IAED,SAAS,CAAC,GAAQ;QAChB,OAAO,kBAAI,CAAC;YACV,IAAI;YACJ;gBACE,CAAC,IAAI,EAAE,IAAI,CAAC;gBACZ,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,oBAAoB,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC9C;oBACE,IAAI;oBACJ;wBACE;4BACE,IA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IAED;;;;;OAKG;IACG,OAAO,CAAC,GAAQ,EAAE,SAAkE;;YACxF,MAAM,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAO,IAAmB,EAAE,CAAM,EAAE,EAAE;gBAClE,MAAM,IAAI,CAAA;gBACV,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE;oBACzB,MAAO,GAAG,CAAC,CAAC,CAAgB;yBACzB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC;yBAClD,MAAM,CAAC,CAAO,IAAmB,EAAE,EAAO,EAAE,EAAE;wBAC7C,MAAM,IAAI,CAAA;wBACV,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,SAAS,CAAC,CAAA;oBACnC,CAAC,CAAA,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;iBACxB;YACH,CAAC,CAAA,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;YACrB,IAAI,GAAG,CAAC,aAAa,EAAE;gBACrB,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,SAAS,CAAC,wBAAS,CAAC,kBAAG,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;aACvE;YACD,OAAO,GAAG,CAAA;QACZ,CAAC;KAAA;CACF;AAxPD,gCAwPC;AAEY,QAAA,KAAK,GAAG,IAAI,UAAU,EAAE,CAAA","sourcesContent":["import * as moment from 'moment'\nimport { Moment } from 'moment'\nimport * as _ from 'lodash'\nimport { a2b, b2a, b64Url2ua, string2ua, ua2b64Url, ua2hex, ua2string } from '../utils/binary-utils'\nimport { pack } from '../utils/asn1-packer'\nimport { parseAsn1 } from '../utils/asn1-parser'\n\nexport class UtilsClass {\n constructor() {}\n\n notConcurrent<T>(concurrencyMap: { [key: string]: PromiseLike<T> }, key: string, proc: () => PromiseLike<T>): PromiseLike<T> {\n const inFlight = concurrencyMap[key]\n if (!inFlight) {\n return (concurrencyMap[key] = (async () => {\n try {\n return await proc()\n } finally {\n delete concurrencyMap[key]\n }\n })())\n } else {\n return concurrencyMap[key].then(() => this.notConcurrent(concurrencyMap, key, proc))\n }\n }\n\n jwk2pkcs8(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x02, '00'],\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]], // pragma: allowlist secret (object identifier of RSA)\n [\n 0x04,\n [\n [\n 0x30,\n [\n [0x02, '00'],\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n [0x02, ua2hex(b64Url2ua(jwk.d))],\n [0x02, ua2hex(b64Url2ua(jwk.p))],\n [0x02, ua2hex(b64Url2ua(jwk.q))],\n [0x02, ua2hex(b64Url2ua(jwk.dp))],\n [0x02, ua2hex(b64Url2ua(jwk.dq))],\n [0x02, ua2hex(b64Url2ua(jwk.qi))],\n ],\n ],\n ],\n ],\n ],\n ])\n }\n\n jwk2pkcs1(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x02, '00'],\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n [0x02, ua2hex(b64Url2ua(jwk.d))],\n [0x02, ua2hex(b64Url2ua(jwk.p))],\n [0x02, ua2hex(b64Url2ua(jwk.q))],\n [0x02, ua2hex(b64Url2ua(jwk.dp))],\n [0x02, ua2hex(b64Url2ua(jwk.dq))],\n [0x02, ua2hex(b64Url2ua(jwk.qi))],\n ],\n ])\n }\n\n jwk2spki(jwk: any): string {\n return pack([\n 0x30,\n [\n [0x30, [[0x06, '2a864886f70d010101'], [0x05]]], // pragma: allowlist secret (object identifier of RSA)\n [\n 0x03,\n [\n [\n 0x30,\n [\n [0x02, ua2hex(b64Url2ua(jwk.n))],\n [0x02, ua2hex(b64Url2ua(jwk.e))],\n ],\n ],\n ],\n ],\n ],\n ])\n }\n\n spkiToJwk(buf: Uint8Array): { kty: string; alg: string; n: string; e: string; ext: boolean } {\n const asn1 = parseAsn1(new Uint8Array(buf))\n\n var modulus: Uint8Array | undefined = undefined\n var exponent: Uint8Array | undefined = undefined\n if (\n asn1.type === 0x30 &&\n asn1.children?.[0]?.type === 0x30 &&\n asn1.children?.[0]?.children?.[0]?.type === 0x06 &&\n ua2hex(asn1.children?.[0]?.children?.[0]?.value ?? new Uint8Array()) === '2a864886f70d010101' // pragma: allowlist secret (object identifier of RSA)\n ) {\n modulus = asn1.children?.[1]?.children?.[0]?.children?.[0]?.value\n exponent = asn1.children?.[1]?.children?.[0]?.children?.[1]?.value\n } else if (asn1.type === 0x30 && asn1.children?.[0]?.type === 0x02 && asn1.children?.[1]?.type === 0x02) {\n modulus = asn1.children?.[0]?.value\n exponent = asn1.children?.[1]?.value\n }\n\n if (!modulus || !exponent) {\n throw new Error('Invalid spki format')\n }\n return {\n kty: 'RSA',\n alg: 'RSA-OAEP',\n ext: true,\n n: ua2b64Url(this.minimalRep(modulus)),\n e: ua2b64Url(this.minimalRep(exponent)),\n }\n }\n\n pkcs8ToJwk(buf: Uint8Array | ArrayBuffer) {\n const parsed = parseAsn1(new Uint8Array(buf))\n const seq =\n parsed.children?.length === 3 && parsed.children[2].type === 0x04 && parsed.children[2].children?.length === 1\n ? parsed.children[2].children[0]\n : parsed\n return {\n kty: 'RSA',\n n: ua2b64Url(this.minimalRep(seq.children![1].value as Uint8Array)),\n e: ua2b64Url(this.minimalRep(seq.children![2].value as Uint8Array)),\n d: ua2b64Url(this.minimalRep(seq.children![3].value as Uint8Array)),\n p: ua2b64Url(this.minimalRep(seq.children![4].value as Uint8Array)),\n q: ua2b64Url(this.minimalRep(seq.children![5].value as Uint8Array)),\n dp: ua2b64Url(this.minimalRep(seq.children![6].value as Uint8Array)),\n dq: ua2b64Url(this.minimalRep(seq.children![7].value as Uint8Array)),\n qi: ua2b64Url(this.minimalRep(seq.children![8].value as Uint8Array)),\n }\n }\n\n minimalRep(b: Uint8Array) {\n let i = 0\n while (b[i] === 0) {\n i++\n }\n return b.slice(i)\n }\n\n /**\n * Provide a view over the given Uint8Array where any trailing null bytes at\n * the end are truncated.\n *\n * This can be used to ignore null bytes at the end of a padded UTF-8 string\n * without needing to copy that string, assuming code point U+0000 is encoded\n * in one null byte according to standards rather than in a multi-byte\n * overlong form.\n */\n truncateTrailingNulls(a: Uint8Array) {\n let end = a.byteLength - 1\n while (a[end] === 0 && end >= 0) {\n end--\n }\n // end is now either the last non-null position in a or -1; in the latter\n // case the returned array will have length 0.\n return a.subarray(0, end + 1)\n }\n\n /**\n *\n * @param buffer1 {Uint8Array}\n * @param buffer2{ Uint8Array}\n * @returns {ArrayBuffer}\n */\n appendBuffer(buffer1: ArrayBuffer, buffer2: ArrayBuffer): ArrayBuffer {\n const tmp = new Uint8Array(buffer1.byteLength + buffer2.byteLength)\n tmp.set(new Uint8Array(buffer1), 0)\n tmp.set(new Uint8Array(buffer2), buffer1.byteLength)\n return tmp.buffer as ArrayBuffer\n }\n\n //Convenience methods for dates management\n after(d1: number, d2: number): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || this.moment(d1)!.isAfter(this.moment(d2)!)\n }\n\n before(d1: number, d2: number): boolean {\n return d1 === null || d2 === null || d1 === undefined || d2 === undefined || this.moment(d1)!.isBefore(this.moment(d2)!)\n }\n\n moment(epochOrLongCalendar: number): Moment | null {\n if (!epochOrLongCalendar && epochOrLongCalendar !== 0) {\n return null\n }\n if (epochOrLongCalendar >= 18000101 && epochOrLongCalendar < 25400000) {\n return moment('' + epochOrLongCalendar, 'YYYYMMDD')\n } else if (epochOrLongCalendar >= 18000101000000) {\n return moment('' + epochOrLongCalendar, 'YYYYMMDDHHmmss')\n } else {\n return moment(epochOrLongCalendar)\n }\n }\n\n /**\n * Encrypt object graph recursively\n *\n * @param obj the object to encrypt\n * @param cryptor the cryptor function (returns a promise)\n * @param keys the keys to be crypted: ex for a Patient ['note', 'addresses.*.[\"street\", \"houseNumber\", \"telecoms.*.telecomNumber\"]']\n */\n async crypt(obj: any, cryptor: (obj: { [key: string]: string }) => Promise<ArrayBuffer>, keys: Array<string>) {\n const subObj = _.pick(\n obj,\n keys.filter((k) => !k.includes('*'))\n )\n obj.encryptedSelf = b2a(ua2string(await cryptor(subObj)))\n Object.keys(subObj).forEach((k) => delete obj[k])\n\n await keys\n .filter((k) => k.includes('*'))\n .reduce(async (prev: Promise<void>, k: any) => {\n await prev\n const k1 = k.split('.*.')[0]\n const k2 = k.substr(k1.length + 3)\n\n const mapped = await Promise.all((_.get(obj, k1) || []).map((so: any) => this.crypt(so, cryptor, k2.startsWith('[') ? JSON.parse(k2) : [k2])))\n _.set(obj, k1, mapped)\n }, Promise.resolve())\n\n return obj\n }\n\n /**\n * Decrypt object graph recursively\n *\n * @param obj the object to encrypt\n * @param decryptor the decryptor function (returns a promise)\n */\n async decrypt(obj: any, decryptor: (obj: Uint8Array) => Promise<{ [key: string]: string }>) {\n await Object.keys(obj).reduce(async (prev: Promise<void>, k: any) => {\n await prev\n if (Array.isArray(obj[k])) {\n await (obj[k] as Array<any>)\n .filter((o) => typeof o === 'object' && o !== null)\n .reduce(async (prev: Promise<void>, so: any) => {\n await prev\n await this.decrypt(so, decryptor)\n }, Promise.resolve())\n }\n }, Promise.resolve())\n if (obj.encryptedSelf) {\n Object.assign(obj, await decryptor(string2ua(a2b(obj.encryptedSelf))))\n }\n return obj\n }\n}\n\nexport const utils = new UtilsClass()\n"]}
|
|
@@ -2,17 +2,17 @@ import { IccAccesslogApi } from '../icc-api';
|
|
|
2
2
|
import { IccCryptoXApi } from './icc-crypto-x-api';
|
|
3
3
|
import * as models from '../icc-api/model/models';
|
|
4
4
|
import { AccessLog, PaginatedListAccessLog } from '../icc-api/model/models';
|
|
5
|
-
import {
|
|
5
|
+
import { IccDataOwnerXApi } from './icc-data-owner-x-api';
|
|
6
6
|
export interface AccessLogWithPatientId extends AccessLog {
|
|
7
7
|
patientId: string;
|
|
8
8
|
}
|
|
9
9
|
export declare class IccAccesslogXApi extends IccAccesslogApi {
|
|
10
10
|
crypto: IccCryptoXApi;
|
|
11
11
|
cryptedKeys: string[];
|
|
12
|
-
|
|
12
|
+
dataOwnerApi: IccDataOwnerXApi;
|
|
13
13
|
constructor(host: string, headers: {
|
|
14
14
|
[key: string]: string;
|
|
15
|
-
}, crypto: IccCryptoXApi,
|
|
15
|
+
}, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
16
16
|
newInstance(user: models.User, patient: models.Patient, h: any): Promise<any>;
|
|
17
17
|
/**
|
|
18
18
|
* 1. Check whether there is a delegation with 'hcpartyId' or not.
|
|
@@ -15,7 +15,7 @@ const _ = require("lodash");
|
|
|
15
15
|
const utils_1 = require("./crypto/utils");
|
|
16
16
|
const binary_utils_1 = require("./utils/binary-utils");
|
|
17
17
|
class IccAccesslogXApi extends icc_api_1.IccAccesslogApi {
|
|
18
|
-
constructor(host, headers, crypto,
|
|
18
|
+
constructor(host, headers, crypto, dataOwnerApi, fetchImpl = typeof window !== 'undefined'
|
|
19
19
|
? window.fetch
|
|
20
20
|
: typeof self !== 'undefined'
|
|
21
21
|
? self.fetch
|
|
@@ -23,10 +23,10 @@ class IccAccesslogXApi extends icc_api_1.IccAccesslogApi {
|
|
|
23
23
|
super(host, headers, fetchImpl);
|
|
24
24
|
this.cryptedKeys = ['detail', 'objectId'];
|
|
25
25
|
this.crypto = crypto;
|
|
26
|
-
this.
|
|
26
|
+
this.dataOwnerApi = dataOwnerApi;
|
|
27
27
|
}
|
|
28
28
|
newInstance(user, patient, h) {
|
|
29
|
-
const dataOwnerId = this.
|
|
29
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
30
30
|
const accessslog = _.assign({
|
|
31
31
|
id: this.crypto.randomUuid(),
|
|
32
32
|
_type: 'org.taktik.icure.entities.AccessLog',
|
|
@@ -115,7 +115,7 @@ class IccAccesslogXApi extends icc_api_1.IccAccesslogApi {
|
|
|
115
115
|
}));
|
|
116
116
|
}
|
|
117
117
|
initEncryptionKeys(user, accessLog) {
|
|
118
|
-
const dataOwnerId = this.
|
|
118
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
119
119
|
return this.crypto.initEncryptionKeys(accessLog, dataOwnerId).then((eks) => {
|
|
120
120
|
let promise = Promise.resolve(_.extend(accessLog, {
|
|
121
121
|
encryptionKeys: eks.encryptionKeys,
|
|
@@ -132,7 +132,7 @@ class IccAccesslogXApi extends icc_api_1.IccAccesslogApi {
|
|
|
132
132
|
return Promise.all(accessLogs.map((accessLog) => (accessLog.encryptionKeys && Object.keys(accessLog.encryptionKeys).length
|
|
133
133
|
? Promise.resolve(accessLog)
|
|
134
134
|
: this.initEncryptionKeys(user, accessLog))
|
|
135
|
-
.then((accessLog) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.
|
|
135
|
+
.then((accessLog) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.dataOwnerApi.getDataOwnerOf(user), accessLog.id, accessLog.encryptionKeys))
|
|
136
136
|
.then((eks) => this.crypto.AES.importKey('raw', binary_utils_1.hex2ua(eks.extractedKeys[0].replace(/-/g, ''))))
|
|
137
137
|
.then((key) => utils_1.utils.crypt(accessLog, (obj) => this.crypto.AES.encrypt(key, binary_utils_1.utf8_2ua(JSON.stringify(obj))), this.cryptedKeys))));
|
|
138
138
|
}
|
|
@@ -143,7 +143,7 @@ class IccAccesslogXApi extends icc_api_1.IccAccesslogApi {
|
|
|
143
143
|
return body
|
|
144
144
|
? this.encrypt(user, [_.cloneDeep(body)])
|
|
145
145
|
.then((als) => super.createAccessLog(als[0]))
|
|
146
|
-
.then((accessLog) => this.decrypt(this.
|
|
146
|
+
.then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [accessLog]))
|
|
147
147
|
.then((als) => als[0])
|
|
148
148
|
: Promise.resolve(null);
|
|
149
149
|
}
|
|
@@ -153,7 +153,7 @@ class IccAccesslogXApi extends icc_api_1.IccAccesslogApi {
|
|
|
153
153
|
getAccessLogWithUser(user, accessLogId) {
|
|
154
154
|
return super
|
|
155
155
|
.getAccessLog(accessLogId)
|
|
156
|
-
.then((accessLog) => this.decrypt(this.
|
|
156
|
+
.then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [accessLog]))
|
|
157
157
|
.then((als) => als[0]);
|
|
158
158
|
}
|
|
159
159
|
listAccessLogs(fromEpoch, toEpoch, startKey, startDocumentId, limit) {
|
|
@@ -162,7 +162,7 @@ class IccAccesslogXApi extends icc_api_1.IccAccesslogApi {
|
|
|
162
162
|
listAccessLogsWithUser(user, fromEpoch, toEpoch, startKey, startDocumentId, limit, descending) {
|
|
163
163
|
return super
|
|
164
164
|
.listAccessLogs(fromEpoch, toEpoch, startKey, startDocumentId, limit, descending)
|
|
165
|
-
.then((accessLog) => this.decrypt(this.
|
|
165
|
+
.then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), accessLog.rows).then((dr) => Object.assign(accessLog, { rows: dr })));
|
|
166
166
|
}
|
|
167
167
|
modifyAccessLog(body) {
|
|
168
168
|
throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption');
|
|
@@ -171,7 +171,7 @@ class IccAccesslogXApi extends icc_api_1.IccAccesslogApi {
|
|
|
171
171
|
return body
|
|
172
172
|
? this.encrypt(user, [_.cloneDeep(body)])
|
|
173
173
|
.then((als) => super.modifyAccessLog(als[0]))
|
|
174
|
-
.then((accessLog) => this.decrypt(this.
|
|
174
|
+
.then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [accessLog]))
|
|
175
175
|
.then((als) => als[0])
|
|
176
176
|
: Promise.resolve(null);
|
|
177
177
|
}
|
|
@@ -181,7 +181,7 @@ class IccAccesslogXApi extends icc_api_1.IccAccesslogApi {
|
|
|
181
181
|
findByUserAfterDateWithUser(user, userId, accessType, startDate, startKey, startDocumentId, limit, descending) {
|
|
182
182
|
return super
|
|
183
183
|
.findByUserAfterDate(userId, accessType, startDate, startKey, startDocumentId, limit, descending)
|
|
184
|
-
.then((accessLog) => this.decrypt(this.
|
|
184
|
+
.then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), accessLog.rows).then((dr) => Object.assign(accessLog, { rows: dr })));
|
|
185
185
|
}
|
|
186
186
|
findLatestAccessLogsOfPatientsWithUser(user, userId, limit = 100, startDate) {
|
|
187
187
|
const _super = Object.create(null, {
|
|
@@ -194,7 +194,7 @@ class IccAccesslogXApi extends icc_api_1.IccAccesslogApi {
|
|
|
194
194
|
for (let currentIteration = 0; foundAccessLogs.length < limit && currentIteration < MAX_WHILE_ITERATIONS; currentIteration++) {
|
|
195
195
|
const currentLimit = limit - foundAccessLogs.length;
|
|
196
196
|
const { rows: logs, nextKeyPair: newNextKeyPair } = (yield _super.findByUserAfterDate.call(this, userId, 'USER_ACCESS', startDate, nextKeyPair && JSON.stringify(nextKeyPair.startKey), nextKeyPair && nextKeyPair.startKeyDocId, numberRequestedAccessLogs, true));
|
|
197
|
-
const logsWithPatientId = yield this.decrypt(this.
|
|
197
|
+
const logsWithPatientId = yield this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), logs).then((decryptedLogs) => Promise.all(_.map(decryptedLogs, (decryptedLog) => {
|
|
198
198
|
return this.crypto.extractCryptedFKs(decryptedLog, user.healthcarePartyId).then((keys) => (Object.assign(Object.assign({}, decryptedLog), { patientId: _.head(keys.extractedKeys) })));
|
|
199
199
|
})));
|
|
200
200
|
const uniqueLogs = _.chain(logsWithPatientId)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-accesslog-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-accesslog-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA4C;AAM5C,4BAA2B;AAC3B,0CAAsC;AACtC,uDAAgE;AAOhE,MAA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,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GACX,CAAA,CAC/B,CAAA;gBACH,CAAC,CAAC,CACH,CACJ,CAAA;gBAED,MAAM,UAAU,GAA6B,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC;qBACpE,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,KAAK,GAAG,CAAC,SAAS,CAAC,CAAC;qBACxF,MAAM,CAAC,CAAC,GAA2B,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC;qBACtD,KAAK,EAAE;qBACP,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAA;gBAEzB,eAAe,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,UAAU,CAAC,CAAA;gBAErD,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,yBAAyB,EAAE;oBACnD,MAAK;iBACN;qBAAM,IAAI,cAAc,EAAE;oBACzB,WAAW,GAAG,cAAc,CAAA;iBAC7B;qBAAM;oBACL,MAAK;iBACN;aACF;YAED,OAAO,eAAe,CAAA;QACxB,CAAC;KAAA;CACF;AA5TD,4CA4TC","sourcesContent":["import { IccAccesslogApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\nimport { AccessLog, PaginatedListAccessLog } from '../icc-api/model/models'\n\nimport * as _ from 'lodash'\nimport { utils } from './crypto/utils'\nimport { hex2ua, ua2utf8, utf8_2ua } from './utils/binary-utils'\nimport { IccUserXApi } from './icc-user-x-api'\n\nexport interface AccessLogWithPatientId extends AccessLog {\n patientId: string\n}\n\nexport class IccAccesslogXApi extends IccAccesslogApi {\n crypto: IccCryptoXApi\n cryptedKeys = ['detail', 'objectId']\n userApi: IccUserXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n userApi: IccUserXApi,\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, fetchImpl)\n this.crypto = crypto\n this.userApi = userApi\n }\n\n newInstance(user: models.User, patient: models.Patient, h: any) {\n const dataOwnerId = this.userApi.getDataOwnerOf(user)\n\n const accessslog = _.assign(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.AccessLog',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n date: +new Date(),\n responsible: dataOwnerId,\n author: user.id,\n codes: [],\n tags: [],\n user: user.id,\n patientId: patient.id,\n accessType: 'USER_ACCESS',\n },\n h || {}\n )\n\n return this.crypto\n .extractDelegationsSFKs(patient, dataOwnerId)\n .then((secretForeignKeys) =>\n Promise.all([\n this.crypto.initObjectDelegations(accessslog, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0]),\n this.crypto.initEncryptionKeys(accessslog, dataOwnerId!),\n ])\n )\n .then(([dels, eks]) => {\n _.extend(accessslog, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(accessslog)\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((helement) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, accessslog, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return accessslog\n })\n ))\n )\n return promise\n })\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all helements with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the helements of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n * @param keepObsoleteVersions\n */\n\n findBy(hcpartyId: string, patient: models.Patient) {\n return this.crypto\n .extractDelegationsSFKs(patient, hcpartyId)\n .then((secretForeignKeys) =>\n secretForeignKeys && secretForeignKeys.extractedKeys && secretForeignKeys.extractedKeys.length > 0\n ? this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n : Promise.resolve([])\n )\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<AccessLog> | any> {\n return super.findAccessLogsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((accesslogs) => this.decrypt(hcPartyId, accesslogs))\n }\n\n decrypt(hcpId: string, accessLogs: Array<models.AccessLog>): Promise<Array<models.AccessLog>> {\n //First check that we have no dangling delegation\n\n return Promise.all(\n accessLogs.map((accessLog) => {\n return accessLog.encryptedSelf\n ? this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(\n hcpId!,\n accessLog.id!,\n _.size(accessLog.encryptionKeys) ? accessLog.encryptionKeys! : accessLog.delegations!\n )\n .then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n //console.log(\"Cannot decrypt contact\", ctc.id)\n return Promise.resolve(accessLog)\n }\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, ''))).then((key) =>\n utils.decrypt(accessLog, (ec) =>\n this.crypto.AES.decrypt(key, ec).then((dec) => {\n const jsonContent = dec && ua2utf8(dec)\n try {\n return JSON.parse(jsonContent)\n } catch (e) {\n console.log('Cannot parse access log', accessLog.id, jsonContent || 'Invalid content')\n return {}\n }\n })\n )\n )\n })\n : Promise.resolve(accessLog)\n })\n )\n }\n\n initEncryptionKeys(user: models.User, accessLog: models.AccessLog): Promise<models.AccessLog> {\n const dataOwnerId = this.userApi.getDataOwnerOf(user)\n\n return this.crypto.initEncryptionKeys(accessLog, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(accessLog, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((accessLog) =>\n this.crypto.appendEncryptionKeys(accessLog, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(accessLog, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n encrypt(user: models.User, accessLogs: Array<models.AccessLog>): Promise<Array<models.AccessLog>> {\n return Promise.all(\n accessLogs.map((accessLog) =>\n (accessLog.encryptionKeys && Object.keys(accessLog.encryptionKeys).length\n ? Promise.resolve(accessLog)\n : this.initEncryptionKeys(user, accessLog)\n )\n .then((accessLog: AccessLog) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.userApi.getDataOwnerOf(user)!, accessLog.id!, accessLog.encryptionKeys!)\n )\n .then((eks: { extractedKeys: Array<string>; hcpartyId: string }) =>\n this.crypto.AES.importKey('raw', hex2ua(eks.extractedKeys[0].replace(/-/g, '')))\n )\n .then((key: CryptoKey) =>\n utils.crypt(accessLog, (obj: { [key: string]: string }) => this.crypto.AES.encrypt(key, utf8_2ua(JSON.stringify(obj))), this.cryptedKeys)\n )\n )\n )\n }\n\n createAccessLog(body?: models.AccessLog): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n createAccessLogWithUser(user: models.User, body?: models.AccessLog): Promise<models.AccessLog | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((als) => super.createAccessLog(als[0]))\n .then((accessLog) => this.decrypt(this.userApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n : Promise.resolve(null)\n }\n\n getAccessLog(accessLogId: string): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n getAccessLogWithUser(user: models.User, accessLogId: string): Promise<models.AccessLog | any> {\n return super\n .getAccessLog(accessLogId)\n .then((accessLog) => this.decrypt(this.userApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n }\n\n listAccessLogs(fromEpoch?: number, toEpoch?: number, startKey?: number, startDocumentId?: string, limit?: number): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n listAccessLogsWithUser(\n user: models.User,\n fromEpoch?: number,\n toEpoch?: number,\n startKey?: number,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): Promise<PaginatedListAccessLog> {\n return super\n .listAccessLogs(fromEpoch, toEpoch, startKey, startDocumentId, limit, descending)\n .then((accessLog) => this.decrypt(this.userApi.getDataOwnerOf(user)!, accessLog.rows!).then((dr) => Object.assign(accessLog, { rows: dr })))\n }\n\n modifyAccessLog(body?: models.AccessLog): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n modifyAccessLogWithUser(user: models.User, body?: models.AccessLog): Promise<models.AccessLog | null> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((als) => super.modifyAccessLog(als[0]))\n .then((accessLog) => this.decrypt(this.userApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n : Promise.resolve(null)\n }\n\n findByUserAfterDate(\n userId: string,\n accessType?: string,\n startDate?: number,\n startKey?: string,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n findByUserAfterDateWithUser(\n user: models.User,\n userId: string,\n accessType?: string,\n startDate?: number,\n startKey?: string,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): Promise<models.AccessLog | any> {\n return super\n .findByUserAfterDate(userId, accessType, startDate, startKey, startDocumentId, limit, descending)\n .then((accessLog) => this.decrypt(this.userApi.getDataOwnerOf(user)!, accessLog.rows!).then((dr) => Object.assign(accessLog, { rows: dr })))\n }\n\n async findLatestAccessLogsOfPatientsWithUser(user: models.User, userId: string, limit = 100, startDate?: number): Promise<models.AccessLog[]> {\n let foundAccessLogs: AccessLogWithPatientId[] = [],\n nextKeyPair: models.PaginatedDocumentKeyIdPairObject | undefined = undefined\n const numberRequestedAccessLogs = 100\n const MAX_WHILE_ITERATIONS = 5\n\n for (let currentIteration = 0; foundAccessLogs.length < limit && currentIteration < MAX_WHILE_ITERATIONS; currentIteration++) {\n const currentLimit = limit - foundAccessLogs.length\n const { rows: logs, nextKeyPair: newNextKeyPair }: models.PaginatedListAccessLog = (await super.findByUserAfterDate(\n userId,\n 'USER_ACCESS',\n startDate,\n nextKeyPair && JSON.stringify(nextKeyPair.startKey!),\n nextKeyPair && nextKeyPair.startKeyDocId!,\n numberRequestedAccessLogs,\n true\n )) as models.PaginatedListAccessLog\n const logsWithPatientId: AccessLogWithPatientId[] = await this.decrypt(this.userApi.getDataOwnerOf(user)!, logs as AccessLog[]).then(\n (decryptedLogs) =>\n Promise.all(\n _.map(decryptedLogs, (decryptedLog) => {\n return this.crypto.extractCryptedFKs(decryptedLog, user.healthcarePartyId as string).then(\n (keys) =>\n ({\n ...decryptedLog,\n patientId: _.head(keys.extractedKeys),\n } as AccessLogWithPatientId)\n )\n })\n )\n )\n\n const uniqueLogs: AccessLogWithPatientId[] = _.chain(logsWithPatientId)\n .reject((log) => _.some(foundAccessLogs, ({ patientId }) => patientId === log.patientId))\n .uniqBy((log: AccessLogWithPatientId) => log.patientId)\n .value()\n .slice(0, currentLimit)\n\n foundAccessLogs = [...foundAccessLogs, ...uniqueLogs]\n\n if ((logs || []).length < numberRequestedAccessLogs) {\n break\n } else if (newNextKeyPair) {\n nextKeyPair = newNextKeyPair\n } else {\n break\n }\n }\n\n return foundAccessLogs\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"icc-accesslog-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-accesslog-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA4C;AAM5C,4BAA2B;AAC3B,0CAAsC;AACtC,uDAAgE;AAOhE,MAAa,gBAAiB,SAAQ,yBAAe;IAKnD,YACE,IAAY,EACZ,OAAkC,EAClC,MAAqB,EACrB,YAA8B,EAC9B,YAA2E,OAAO,MAAM,KAAK,WAAW;QACtG,CAAC,CAAC,MAAM,CAAC,KAAK;QACd,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,KAAK;QAET,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAA;QAdjC,gBAAW,GAAG,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;QAelC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,CAAC;IAED,WAAW,CAAC,IAAiB,EAAE,OAAuB,EAAE,CAAM;QAC5D,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,cAAc,CAAC,IAAI,CAAC,CAAA;QAE1D,MAAM,UAAU,GAAG,CAAC,CAAC,MAAM,CACzB;YACE,EAAE,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;YAC5B,KAAK,EAAE,qCAAqC;YAC5C,OAAO,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC7B,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;YAC9B,IAAI,EAAE,CAAC,IAAI,IAAI,EAAE;YACjB,WAAW,EAAE,WAAW;YACxB,MAAM,EAAE,IAAI,CAAC,EAAE;YACf,KAAK,EAAE,EAAE;YAC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,CAChB,OAAO,CAAC,GAAG,CACT,CAAC,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC,YAAY,EAAE,EAAE;oBACpC,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,YAAY,EAAE,IAAI,CAAC,iBAA2B,CAAC,CAAC,IAAI,CACvF,CAAC,IAAI,EAAE,EAAE,CACP,CAAC,gCACI,YAAY,KACf,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,GACX,CAAA,CAC/B,CAAA;gBACH,CAAC,CAAC,CACH,CACJ,CAAA;gBAED,MAAM,UAAU,GAA6B,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC;qBACpE,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,KAAK,GAAG,CAAC,SAAS,CAAC,CAAC;qBACxF,MAAM,CAAC,CAAC,GAA2B,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC;qBACtD,KAAK,EAAE;qBACP,KAAK,CAAC,CAAC,EAAE,YAAY,CAAC,CAAA;gBAEzB,eAAe,GAAG,CAAC,GAAG,eAAe,EAAE,GAAG,UAAU,CAAC,CAAA;gBAErD,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,yBAAyB,EAAE;oBACnD,MAAK;iBACN;qBAAM,IAAI,cAAc,EAAE;oBACzB,WAAW,GAAG,cAAc,CAAA;iBAC7B;qBAAM;oBACL,MAAK;iBACN;aACF;YAED,OAAO,eAAe,CAAA;QACxB,CAAC;KAAA;CACF;AAhUD,4CAgUC","sourcesContent":["import { IccAccesslogApi } from '../icc-api'\nimport { IccCryptoXApi } from './icc-crypto-x-api'\n\nimport * as models from '../icc-api/model/models'\nimport { AccessLog, PaginatedListAccessLog } from '../icc-api/model/models'\n\nimport * as _ from 'lodash'\nimport { utils } from './crypto/utils'\nimport { hex2ua, ua2utf8, utf8_2ua } from './utils/binary-utils'\nimport { IccDataOwnerXApi } from './icc-data-owner-x-api'\n\nexport interface AccessLogWithPatientId extends AccessLog {\n patientId: string\n}\n\nexport class IccAccesslogXApi extends IccAccesslogApi {\n crypto: IccCryptoXApi\n cryptedKeys = ['detail', 'objectId']\n dataOwnerApi: IccDataOwnerXApi\n\n constructor(\n host: string,\n headers: { [key: string]: string },\n crypto: IccCryptoXApi,\n dataOwnerApi: IccDataOwnerXApi,\n fetchImpl: (input: RequestInfo, init?: RequestInit) => Promise<Response> = typeof window !== 'undefined'\n ? window.fetch\n : typeof self !== 'undefined'\n ? self.fetch\n : fetch\n ) {\n super(host, headers, fetchImpl)\n this.crypto = crypto\n this.dataOwnerApi = dataOwnerApi\n }\n\n newInstance(user: models.User, patient: models.Patient, h: any) {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n const accessslog = _.assign(\n {\n id: this.crypto.randomUuid(),\n _type: 'org.taktik.icure.entities.AccessLog',\n created: new Date().getTime(),\n modified: new Date().getTime(),\n date: +new Date(),\n responsible: dataOwnerId,\n author: user.id,\n codes: [],\n tags: [],\n user: user.id,\n patientId: patient.id,\n accessType: 'USER_ACCESS',\n },\n h || {}\n )\n\n return this.crypto\n .extractDelegationsSFKs(patient, dataOwnerId)\n .then((secretForeignKeys) =>\n Promise.all([\n this.crypto.initObjectDelegations(accessslog, patient, dataOwnerId!, secretForeignKeys.extractedKeys[0]),\n this.crypto.initEncryptionKeys(accessslog, dataOwnerId!),\n ])\n )\n .then(([dels, eks]) => {\n _.extend(accessslog, {\n delegations: dels.delegations,\n cryptedForeignKeys: dels.cryptedForeignKeys,\n secretForeignKeys: dels.secretForeignKeys,\n encryptionKeys: eks.encryptionKeys,\n })\n\n let promise = Promise.resolve(accessslog)\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((helement) =>\n this.crypto.addDelegationsAndEncryptionKeys(patient, accessslog, dataOwnerId!, delegateId, dels.secretId, eks.secretId).catch((e) => {\n console.log(e)\n return accessslog\n })\n ))\n )\n return promise\n })\n }\n\n // noinspection JSUnusedGlobalSymbols\n /**\n * 1. Check whether there is a delegation with 'hcpartyId' or not.\n * 2. 'fetchHcParty[hcpartyId][1]': is encrypted AES exchange key by RSA public key of him.\n * 3. Obtain the AES exchange key, by decrypting the previous step value with hcparty private key\n * 3.1. KeyPair should be fetch from cache (in jwk)\n * 3.2. if it doesn't exist in the cache, it has to be loaded from Browser Local store, and then import it to WebCrypto\n * 4. Obtain the array of delegations which are delegated to his ID (hcpartyId) in this patient\n * 5. Decrypt and collect all keys (secretForeignKeys) within delegations of previous step (with obtained AES key of step 4)\n * 6. Do the REST call to get all helements with (allSecretForeignKeysDelimitedByComa, hcpartyId)\n *\n * After these painful steps, you have the helements of the patient.\n *\n * @param hcpartyId\n * @param patient (Promise)\n * @param keepObsoleteVersions\n */\n\n findBy(hcpartyId: string, patient: models.Patient) {\n return this.crypto\n .extractDelegationsSFKs(patient, hcpartyId)\n .then((secretForeignKeys) =>\n secretForeignKeys && secretForeignKeys.extractedKeys && secretForeignKeys.extractedKeys.length > 0\n ? this.findByHCPartyPatientSecretFKeys(secretForeignKeys.hcpartyId!, _.uniq(secretForeignKeys.extractedKeys).join(','))\n : Promise.resolve([])\n )\n }\n\n findByHCPartyPatientSecretFKeys(hcPartyId: string, secretFKeys: string): Promise<Array<AccessLog> | any> {\n return super.findAccessLogsByHCPartyPatientForeignKeys(hcPartyId, secretFKeys).then((accesslogs) => this.decrypt(hcPartyId, accesslogs))\n }\n\n decrypt(hcpId: string, accessLogs: Array<models.AccessLog>): Promise<Array<models.AccessLog>> {\n //First check that we have no dangling delegation\n\n return Promise.all(\n accessLogs.map((accessLog) => {\n return accessLog.encryptedSelf\n ? this.crypto\n .extractKeysFromDelegationsForHcpHierarchy(\n hcpId!,\n accessLog.id!,\n _.size(accessLog.encryptionKeys) ? accessLog.encryptionKeys! : accessLog.delegations!\n )\n .then(({ extractedKeys: sfks }) => {\n if (!sfks || !sfks.length) {\n //console.log(\"Cannot decrypt contact\", ctc.id)\n return Promise.resolve(accessLog)\n }\n return this.crypto.AES.importKey('raw', hex2ua(sfks[0].replace(/-/g, ''))).then((key) =>\n utils.decrypt(accessLog, (ec) =>\n this.crypto.AES.decrypt(key, ec).then((dec) => {\n const jsonContent = dec && ua2utf8(dec)\n try {\n return JSON.parse(jsonContent)\n } catch (e) {\n console.log('Cannot parse access log', accessLog.id, jsonContent || 'Invalid content')\n return {}\n }\n })\n )\n )\n })\n : Promise.resolve(accessLog)\n })\n )\n }\n\n initEncryptionKeys(user: models.User, accessLog: models.AccessLog): Promise<models.AccessLog> {\n const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user)\n\n return this.crypto.initEncryptionKeys(accessLog, dataOwnerId!).then((eks) => {\n let promise = Promise.resolve(\n _.extend(accessLog, {\n encryptionKeys: eks.encryptionKeys,\n })\n )\n ;(user.autoDelegations ? (user.autoDelegations.all || []).concat(user.autoDelegations.medicalInformation || []) : []).forEach(\n (delegateId) =>\n (promise = promise.then((accessLog) =>\n this.crypto.appendEncryptionKeys(accessLog, dataOwnerId!, delegateId, eks.secretId).then((extraEks) => {\n return _.extend(accessLog, {\n encryptionKeys: extraEks.encryptionKeys,\n })\n })\n ))\n )\n return promise\n })\n }\n\n encrypt(user: models.User, accessLogs: Array<models.AccessLog>): Promise<Array<models.AccessLog>> {\n return Promise.all(\n accessLogs.map((accessLog) =>\n (accessLog.encryptionKeys && Object.keys(accessLog.encryptionKeys).length\n ? Promise.resolve(accessLog)\n : this.initEncryptionKeys(user, accessLog)\n )\n .then((accessLog: AccessLog) =>\n this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.dataOwnerApi.getDataOwnerOf(user)!, accessLog.id!, accessLog.encryptionKeys!)\n )\n .then((eks: { extractedKeys: Array<string>; hcpartyId: string }) =>\n this.crypto.AES.importKey('raw', hex2ua(eks.extractedKeys[0].replace(/-/g, '')))\n )\n .then((key: CryptoKey) =>\n utils.crypt(accessLog, (obj: { [key: string]: string }) => this.crypto.AES.encrypt(key, utf8_2ua(JSON.stringify(obj))), this.cryptedKeys)\n )\n )\n )\n }\n\n createAccessLog(body?: models.AccessLog): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n createAccessLogWithUser(user: models.User, body?: models.AccessLog): Promise<models.AccessLog | any> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((als) => super.createAccessLog(als[0]))\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n : Promise.resolve(null)\n }\n\n getAccessLog(accessLogId: string): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n getAccessLogWithUser(user: models.User, accessLogId: string): Promise<models.AccessLog | any> {\n return super\n .getAccessLog(accessLogId)\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n }\n\n listAccessLogs(fromEpoch?: number, toEpoch?: number, startKey?: number, startDocumentId?: string, limit?: number): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n listAccessLogsWithUser(\n user: models.User,\n fromEpoch?: number,\n toEpoch?: number,\n startKey?: number,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): Promise<PaginatedListAccessLog> {\n return super\n .listAccessLogs(fromEpoch, toEpoch, startKey, startDocumentId, limit, descending)\n .then((accessLog) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, accessLog.rows!).then((dr) => Object.assign(accessLog, { rows: dr }))\n )\n }\n\n modifyAccessLog(body?: models.AccessLog): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n modifyAccessLogWithUser(user: models.User, body?: models.AccessLog): Promise<models.AccessLog | null> {\n return body\n ? this.encrypt(user, [_.cloneDeep(body)])\n .then((als) => super.modifyAccessLog(als[0]))\n .then((accessLog) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, [accessLog]))\n .then((als) => als[0])\n : Promise.resolve(null)\n }\n\n findByUserAfterDate(\n userId: string,\n accessType?: string,\n startDate?: number,\n startKey?: string,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): never {\n throw new Error('Cannot call a method that returns access logs without providing a user for de/encryption')\n }\n\n findByUserAfterDateWithUser(\n user: models.User,\n userId: string,\n accessType?: string,\n startDate?: number,\n startKey?: string,\n startDocumentId?: string,\n limit?: number,\n descending?: boolean\n ): Promise<models.AccessLog | any> {\n return super\n .findByUserAfterDate(userId, accessType, startDate, startKey, startDocumentId, limit, descending)\n .then((accessLog) =>\n this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, accessLog.rows!).then((dr) => Object.assign(accessLog, { rows: dr }))\n )\n }\n\n async findLatestAccessLogsOfPatientsWithUser(user: models.User, userId: string, limit = 100, startDate?: number): Promise<models.AccessLog[]> {\n let foundAccessLogs: AccessLogWithPatientId[] = [],\n nextKeyPair: models.PaginatedDocumentKeyIdPairObject | undefined = undefined\n const numberRequestedAccessLogs = 100\n const MAX_WHILE_ITERATIONS = 5\n\n for (let currentIteration = 0; foundAccessLogs.length < limit && currentIteration < MAX_WHILE_ITERATIONS; currentIteration++) {\n const currentLimit = limit - foundAccessLogs.length\n const { rows: logs, nextKeyPair: newNextKeyPair }: models.PaginatedListAccessLog = (await super.findByUserAfterDate(\n userId,\n 'USER_ACCESS',\n startDate,\n nextKeyPair && JSON.stringify(nextKeyPair.startKey!),\n nextKeyPair && nextKeyPair.startKeyDocId!,\n numberRequestedAccessLogs,\n true\n )) as models.PaginatedListAccessLog\n const logsWithPatientId: AccessLogWithPatientId[] = await this.decrypt(this.dataOwnerApi.getDataOwnerOf(user)!, logs as AccessLog[]).then(\n (decryptedLogs) =>\n Promise.all(\n _.map(decryptedLogs, (decryptedLog) => {\n return this.crypto.extractCryptedFKs(decryptedLog, user.healthcarePartyId as string).then(\n (keys) =>\n ({\n ...decryptedLog,\n patientId: _.head(keys.extractedKeys),\n } as AccessLogWithPatientId)\n )\n })\n )\n )\n\n const uniqueLogs: AccessLogWithPatientId[] = _.chain(logsWithPatientId)\n .reject((log) => _.some(foundAccessLogs, ({ patientId }) => patientId === log.patientId))\n .uniqBy((log: AccessLogWithPatientId) => log.patientId)\n .value()\n .slice(0, currentLimit)\n\n foundAccessLogs = [...foundAccessLogs, ...uniqueLogs]\n\n if ((logs || []).length < numberRequestedAccessLogs) {\n break\n } else if (newNextKeyPair) {\n nextKeyPair = newNextKeyPair\n } else {\n break\n }\n }\n\n return foundAccessLogs\n }\n}\n"]}
|
|
@@ -2,15 +2,15 @@ import * as models from '../icc-api/model/models';
|
|
|
2
2
|
import { CalendarItem, User } from '../icc-api/model/models';
|
|
3
3
|
import { IccCryptoXApi } from './icc-crypto-x-api';
|
|
4
4
|
import { IccCalendarItemApi } from '../icc-api';
|
|
5
|
-
import {
|
|
5
|
+
import { IccDataOwnerXApi } from './icc-data-owner-x-api';
|
|
6
6
|
export declare class IccCalendarItemXApi extends IccCalendarItemApi {
|
|
7
7
|
i18n: any;
|
|
8
8
|
crypto: IccCryptoXApi;
|
|
9
|
-
|
|
9
|
+
dataOwnerApi: IccDataOwnerXApi;
|
|
10
10
|
cryptedKeys: string[];
|
|
11
11
|
constructor(host: string, headers: {
|
|
12
12
|
[key: string]: string;
|
|
13
|
-
}, crypto: IccCryptoXApi,
|
|
13
|
+
}, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
|
|
14
14
|
newInstance(user: User, ci: CalendarItem, delegates?: string[]): Promise<models.CalendarItem>;
|
|
15
15
|
newInstancePatient(user: models.User, patient: models.Patient | null, ci: any, delegates?: string[]): Promise<models.CalendarItem>;
|
|
16
16
|
initDelegationsAndEncryptionKeys(user: models.User, patient: models.Patient | null, calendarItem: models.CalendarItem, delegates?: string[]): Promise<models.CalendarItem>;
|
|
@@ -18,7 +18,7 @@ const utils_1 = require("./crypto/utils");
|
|
|
18
18
|
const icc_api_1 = require("../icc-api");
|
|
19
19
|
const binary_utils_1 = require("./utils/binary-utils");
|
|
20
20
|
class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
21
|
-
constructor(host, headers, crypto,
|
|
21
|
+
constructor(host, headers, crypto, dataOwnerApi, fetchImpl = typeof window !== 'undefined'
|
|
22
22
|
? window.fetch
|
|
23
23
|
: typeof self !== 'undefined'
|
|
24
24
|
? self.fetch
|
|
@@ -27,7 +27,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
27
27
|
this.i18n = i18n;
|
|
28
28
|
this.cryptedKeys = ['details', 'title', 'patientId'];
|
|
29
29
|
this.crypto = crypto;
|
|
30
|
-
this.
|
|
30
|
+
this.dataOwnerApi = dataOwnerApi;
|
|
31
31
|
}
|
|
32
32
|
newInstance(user, ci, delegates = []) {
|
|
33
33
|
return this.newInstancePatient(user, null, ci, delegates);
|
|
@@ -38,7 +38,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
38
38
|
_type: 'org.taktik.icure.entities.CalendarItem',
|
|
39
39
|
created: new Date().getTime(),
|
|
40
40
|
modified: new Date().getTime(),
|
|
41
|
-
responsible: this.
|
|
41
|
+
responsible: this.dataOwnerApi.getDataOwnerOf(user),
|
|
42
42
|
author: user.id,
|
|
43
43
|
codes: [],
|
|
44
44
|
tags: [],
|
|
@@ -46,7 +46,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
46
46
|
return this.initDelegationsAndEncryptionKeys(user, patient, calendarItem, delegates);
|
|
47
47
|
}
|
|
48
48
|
initDelegationsAndEncryptionKeys(user, patient, calendarItem, delegates = []) {
|
|
49
|
-
const dataOwnerId = this.
|
|
49
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
50
50
|
return this.crypto
|
|
51
51
|
.extractDelegationsSFKs(patient, dataOwnerId)
|
|
52
52
|
.then((secretForeignKeys) => Promise.all([
|
|
@@ -84,27 +84,27 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
84
84
|
return body
|
|
85
85
|
? this.encrypt(user, [_.cloneDeep(body)])
|
|
86
86
|
.then((items) => super.createCalendarItem(items[0]))
|
|
87
|
-
.then((ci) => this.decrypt(this.
|
|
87
|
+
.then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [ci]))
|
|
88
88
|
.then((cis) => cis[0])
|
|
89
89
|
: Promise.resolve(null);
|
|
90
90
|
}
|
|
91
91
|
getCalendarItemWithUser(user, calendarItemId) {
|
|
92
92
|
return super
|
|
93
93
|
.getCalendarItem(calendarItemId)
|
|
94
|
-
.then((calendarItem) => this.decrypt(this.
|
|
94
|
+
.then((calendarItem) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [calendarItem]))
|
|
95
95
|
.then((cis) => cis[0]);
|
|
96
96
|
}
|
|
97
97
|
getCalendarItem(calendarItemId) {
|
|
98
98
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
99
99
|
}
|
|
100
100
|
getCalendarItemsWithUser(user) {
|
|
101
|
-
return super.getCalendarItems().then((calendarItems) => this.decrypt(this.
|
|
101
|
+
return super.getCalendarItems().then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), calendarItems));
|
|
102
102
|
}
|
|
103
103
|
getCalendarItems() {
|
|
104
104
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
105
105
|
}
|
|
106
106
|
getCalendarItemsWithIdsWithUser(user, body) {
|
|
107
|
-
return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.
|
|
107
|
+
return super.getCalendarItemsWithIds(body).then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), calendarItems));
|
|
108
108
|
}
|
|
109
109
|
getCalendarItemsWithIds(body) {
|
|
110
110
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
@@ -112,7 +112,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
112
112
|
getCalendarItemsByPeriodAndHcPartyIdWithUser(user, startDate, endDate, hcPartyId) {
|
|
113
113
|
return super
|
|
114
114
|
.getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId)
|
|
115
|
-
.then((calendarItems) => this.decrypt(this.
|
|
115
|
+
.then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), calendarItems));
|
|
116
116
|
}
|
|
117
117
|
getCalendarItemsByPeriodAndHcPartyId(startDate, endDate, hcPartyId) {
|
|
118
118
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
@@ -120,7 +120,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
120
120
|
getCalendarsByPeriodAndAgendaIdWithUser(user, startDate, endDate, agendaId) {
|
|
121
121
|
return super
|
|
122
122
|
.getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId)
|
|
123
|
-
.then((calendarItems) => this.decrypt(this.
|
|
123
|
+
.then((calendarItems) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), calendarItems));
|
|
124
124
|
}
|
|
125
125
|
getCalendarsByPeriodAndAgendaId(startDate, endDate, agendaId) {
|
|
126
126
|
throw new Error('Cannot call a method that must en/decrypt a calendar item without providing a user for de/encryption');
|
|
@@ -147,12 +147,12 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
147
147
|
return body
|
|
148
148
|
? this.encrypt(user, [_.cloneDeep(body)])
|
|
149
149
|
.then((items) => super.modifyCalendarItem(items[0]))
|
|
150
|
-
.then((ci) => this.decrypt(this.
|
|
150
|
+
.then((ci) => this.decrypt(this.dataOwnerApi.getDataOwnerOf(user), [ci]))
|
|
151
151
|
.then((cis) => cis[0])
|
|
152
152
|
: Promise.resolve(null);
|
|
153
153
|
}
|
|
154
154
|
initEncryptionKeys(user, calendarItem) {
|
|
155
|
-
const dataOwnerId = this.
|
|
155
|
+
const dataOwnerId = this.dataOwnerApi.getDataOwnerOf(user);
|
|
156
156
|
return this.crypto.initEncryptionKeys(calendarItem, dataOwnerId).then((eks) => {
|
|
157
157
|
let promise = Promise.resolve(_.extend(calendarItem, {
|
|
158
158
|
encryptionKeys: eks.encryptionKeys,
|
|
@@ -169,7 +169,7 @@ class IccCalendarItemXApi extends icc_api_1.IccCalendarItemApi {
|
|
|
169
169
|
return Promise.all(calendarItems.map((calendarItem) => (calendarItem.encryptionKeys && Object.keys(calendarItem.encryptionKeys).length
|
|
170
170
|
? Promise.resolve(calendarItem)
|
|
171
171
|
: this.initEncryptionKeys(user, calendarItem))
|
|
172
|
-
.then((calendarItem) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.
|
|
172
|
+
.then((calendarItem) => this.crypto.extractKeysFromDelegationsForHcpHierarchy(this.dataOwnerApi.getDataOwnerOf(user), calendarItem.id, calendarItem.encryptionKeys))
|
|
173
173
|
.then((eks) => this.crypto.AES.importKey('raw', binary_utils_1.hex2ua(eks.extractedKeys[0].replace(/-/g, ''))))
|
|
174
174
|
.then((key) => utils_1.utils.crypt(calendarItem, (obj) => this.crypto.AES.encrypt(key, binary_utils_1.utf8_2ua(JSON.stringify(obj))), this.cryptedKeys))));
|
|
175
175
|
}
|