@icure/api 8.0.77 → 8.0.79
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-x-api/crypto/ExchangeKeysManager.d.ts +1 -0
- package/icc-x-api/crypto/ExchangeKeysManager.js +26 -16
- package/icc-x-api/crypto/ExchangeKeysManager.js.map +1 -1
- package/icc-x-api/icc-hcparty-x-api.js +8 -1
- package/icc-x-api/icc-hcparty-x-api.js.map +1 -1
- package/package.json +1 -1
- package/test/icc-x-api/diocancaro.d.ts +1 -0
- package/test/icc-x-api/diocancaro.js +75 -0
- package/test/icc-x-api/diocancaro.js.map +1 -0
|
@@ -25,6 +25,7 @@ export declare class ExchangeKeysManager {
|
|
|
25
25
|
* @return all available exchange keys from the delegator-delegate pair.
|
|
26
26
|
*/
|
|
27
27
|
getDecryptionExchangeKeysFor(delegatorId: string, delegateId: string): Promise<CryptoKey[]>;
|
|
28
|
+
private decryptChunk;
|
|
28
29
|
/**
|
|
29
30
|
* Reloads all exchange keys for the cache.
|
|
30
31
|
*/
|
|
@@ -37,9 +37,28 @@ class ExchangeKeysManager {
|
|
|
37
37
|
* @return all available exchange keys from the delegator-delegate pair.
|
|
38
38
|
*/
|
|
39
39
|
getDecryptionExchangeKeysFor(delegatorId, delegateId) {
|
|
40
|
-
var _a
|
|
40
|
+
var _a;
|
|
41
41
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
|
|
42
|
+
const entry = (_a = this.cache[delegatorId]) === null || _a === void 0 ? void 0 : _a[delegateId];
|
|
43
|
+
if (entry != undefined) {
|
|
44
|
+
if ('decrypted' in entry) {
|
|
45
|
+
return yield entry.decrypted;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const decryptedPromise = this.decryptChunk(entry.encrypted);
|
|
49
|
+
this.cache[delegatorId][delegateId] = { decrypted: decryptedPromise };
|
|
50
|
+
return yield decryptedPromise;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
decryptChunk(encryptedKeys) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const decryptionKeys = this.keyManager.getDecryptionKeys();
|
|
61
|
+
return (yield this.base.tryDecryptExchangeKeys(encryptedKeys, decryptionKeys)).successfulDecryptions;
|
|
43
62
|
});
|
|
44
63
|
}
|
|
45
64
|
/**
|
|
@@ -56,11 +75,11 @@ class ExchangeKeysManager {
|
|
|
56
75
|
encryptedKeys[delegator] = {};
|
|
57
76
|
}
|
|
58
77
|
if (!encryptedKeys[delegator][dataOwner]) {
|
|
59
|
-
encryptedKeys[delegator][dataOwner] = [];
|
|
78
|
+
encryptedKeys[delegator][dataOwner] = { encrypted: [] };
|
|
60
79
|
}
|
|
61
80
|
const keysForDelegatorDelegate = encryptedKeys[delegator][dataOwner];
|
|
62
81
|
for (const encryptedEntries of Object.values(encryptedByDelegatorFp)) {
|
|
63
|
-
keysForDelegatorDelegate.push(encryptedEntries);
|
|
82
|
+
keysForDelegatorDelegate.encrypted.push(encryptedEntries);
|
|
64
83
|
}
|
|
65
84
|
}
|
|
66
85
|
for (const encryptedByDelegateId of Object.values(info.keysFromOwner)) {
|
|
@@ -69,22 +88,13 @@ class ExchangeKeysManager {
|
|
|
69
88
|
encryptedKeys[dataOwner] = {};
|
|
70
89
|
}
|
|
71
90
|
if (!encryptedKeys[dataOwner][delegate]) {
|
|
72
|
-
encryptedKeys[dataOwner][delegate] = [];
|
|
91
|
+
encryptedKeys[dataOwner][delegate] = { encrypted: [] };
|
|
73
92
|
}
|
|
74
|
-
encryptedKeys[dataOwner][delegate].push(encryptedEntries);
|
|
93
|
+
encryptedKeys[dataOwner][delegate].encrypted.push(encryptedEntries);
|
|
75
94
|
}
|
|
76
95
|
}
|
|
77
96
|
}
|
|
78
|
-
|
|
79
|
-
const decrypted = {};
|
|
80
|
-
for (const [delegator, keysByDelegate] of Object.entries(encryptedKeys)) {
|
|
81
|
-
const currDelegatorData = {};
|
|
82
|
-
for (const [delegate, keys] of Object.entries(keysByDelegate)) {
|
|
83
|
-
currDelegatorData[delegate] = (yield this.base.tryDecryptExchangeKeys(keys, decryptionKeys)).successfulDecryptions;
|
|
84
|
-
}
|
|
85
|
-
decrypted[delegator] = currDelegatorData;
|
|
86
|
-
}
|
|
87
|
-
this.cache = decrypted;
|
|
97
|
+
this.cache = encryptedKeys;
|
|
88
98
|
});
|
|
89
99
|
}
|
|
90
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExchangeKeysManager.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/ExchangeKeysManager.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"ExchangeKeysManager.js","sourceRoot":"","sources":["../../../icc-x-api/crypto/ExchangeKeysManager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAgBA;;;;;;;GAOG;AACH,MAAa,mBAAmB;IAG9B,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,uBAAuB,CAAA;IACrC,CAAC;IAED,YACmB,UAAqC,EACrC,uBAAgD,EAChD,YAA8B;QAF9B,eAAU,GAAV,UAAU,CAA2B;QACrC,4BAAuB,GAAvB,uBAAuB,CAAyB;QAChD,iBAAY,GAAZ,YAAY,CAAkB;QATzC,UAAK,GAAgE,EAAE,CAAA;IAU5E,CAAC;IAEJ;;;;;;;OAOG;IACG,4BAA4B,CAAC,WAAmB,EAAE,UAAkB;;;YACxE,MAAM,KAAK,GAAG,MAAA,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,0CAAG,UAAU,CAAC,CAAA;YACnD,IAAI,KAAK,IAAI,SAAS,EAAE;gBACtB,IAAI,WAAW,IAAI,KAAK,EAAE;oBACxB,OAAO,MAAM,KAAK,CAAC,SAAS,CAAA;iBAC7B;qBAAM;oBACL,MAAM,gBAAgB,GAAG,IAAI,CAAC,YAAY,CAA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Aa,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,EAAE;wBACxC,aAAa,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,CAAA;qBACxD;oBACD,MAAM,wBAAwB,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAA;oBACpE,KAAK,MAAM,gBAAgB,IAAI,MAAM,CAAC,MAAM,CAAC,sBAAsB,CAAC,EAAE;wBACpE,wBAAwB,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;qBAC1D;iBACF;gBACD,KAAK,MAAM,qBAAqB,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE;oBACrE,KAAK,MAAM,CAAC,QAAQ,EAAE,gBAAgB,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE;wBAChF,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE;4BAC7B,aAAa,CAAC,SAAS,CAAC,GAAG,EAAE,CAAA;yBAC9B;wBACD,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,EAAE;4BACvC,aAAa,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,CAAA;yBACvD;wBACD,aAAa,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;qBACpE;iBACF;aACF;YACD,IAAI,CAAC,KAAK,GAAG,aAAa,CAAA;QAC5B,CAAC;KAAA;CACF;AA3FD,kDA2FC","sourcesContent":["import { UserEncryptionKeysManager } from './UserEncryptionKeysManager'\nimport { BaseExchangeKeysManager } from './BaseExchangeKeysManager'\nimport { IccDataOwnerXApi } from '../icc-data-owner-x-api'\nimport { CryptoPrimitives } from './CryptoPrimitives'\nimport { CryptoStrategies } from './CryptoStrategies'\nimport { IcureStorageFacade } from '../storage/IcureStorageFacade'\nimport { DataOwnerTypeEnum } from '../../icc-api/model/DataOwnerTypeEnum'\n\ntype CacheValue =\n | {\n encrypted: { [fp: string]: string }[]\n }\n | {\n decrypted: Promise<CryptoKey[]>\n }\n\n/**\n * @internal This class is meant only for internal use and may be changed without notice.\n * More powerful version of {@link BaseExchangeKeysManager} with a simplified interface. Has the following functionalities:\n * - Caches results\n * - Automatically creates new exchange keys if none is available\n * - Automatically choose the public keys to use during the creation of new exchange keys\n * - Automatically retrieves the private keys to use during decryption.\n */\nexport class ExchangeKeysManager {\n private cache: { [delegator: string]: { [delegate: string]: CacheValue } } = {}\n\n get base(): BaseExchangeKeysManager {\n return this.baseExchangeKeysManager\n }\n\n constructor(\n private readonly keyManager: UserEncryptionKeysManager,\n private readonly baseExchangeKeysManager: BaseExchangeKeysManager,\n private readonly dataOwnerApi: IccDataOwnerXApi\n ) {}\n\n /**\n * Get all keys currently available for a delegator-delegate pair. At least one of the two data owners must be part of the hierarchy for the current\n * data owner.\n * @param delegatorId id of a delegator\n * @param delegateId id of a delegate\n * @throws if neither the delegator nor the delegate is part of the hierarchy of the current data owner.\n * @return all available exchange keys from the delegator-delegate pair.\n */\n async getDecryptionExchangeKeysFor(delegatorId: string, delegateId: string): Promise<CryptoKey[]> {\n const entry = this.cache[delegatorId]?.[delegateId]\n if (entry != undefined) {\n if ('decrypted' in entry) {\n return await entry.decrypted\n } else {\n const decryptedPromise = this.decryptChunk(entry.encrypted)\n this.cache[delegatorId][delegateId] = { decrypted: decryptedPromise }\n return await decryptedPromise\n }\n } else {\n return []\n }\n }\n\n private async decryptChunk(encryptedKeys: { [fp: string]: string }[]): Promise<CryptoKey[]> {\n const decryptionKeys = this.keyManager.getDecryptionKeys()\n return (await this.base.tryDecryptExchangeKeys(encryptedKeys, decryptionKeys)).successfulDecryptions\n }\n\n /**\n * Reloads all exchange keys for the cache.\n */\n async reloadCache(): Promise<void> {\n const hierarchy = await this.dataOwnerApi.getCurrentDataOwnerHierarchyIds()\n const encryptedKeysDataByHierarchyMember = Object.fromEntries(\n await Promise.all(\n hierarchy.map((doId) =>\n this.base.getAllExchangeKeysWith(doId, null).then(\n (\n res\n ): [\n string,\n {\n keysToOwner: { [p: string]: { [p: string]: { [p: string]: string } } }\n keysFromOwner: { [p: string]: { [p: string]: { [p: string]: string } } }\n }\n ] => [doId, res]\n )\n )\n )\n )\n const encryptedKeys: { [delegator: string]: { [delegate: string]: { encrypted: { [pubFp: string]: string }[] } } } = {}\n for (const [dataOwner, info] of Object.entries(encryptedKeysDataByHierarchyMember)) {\n for (const [delegator, encryptedByDelegatorFp] of Object.entries(info.keysToOwner)) {\n if (!encryptedKeys[delegator]) {\n encryptedKeys[delegator] = {}\n }\n if (!encryptedKeys[delegator][dataOwner]) {\n encryptedKeys[delegator][dataOwner] = { encrypted: [] }\n }\n const keysForDelegatorDelegate = encryptedKeys[delegator][dataOwner]\n for (const encryptedEntries of Object.values(encryptedByDelegatorFp)) {\n keysForDelegatorDelegate.encrypted.push(encryptedEntries)\n }\n }\n for (const encryptedByDelegateId of Object.values(info.keysFromOwner)) {\n for (const [delegate, encryptedEntries] of Object.entries(encryptedByDelegateId)) {\n if (!encryptedKeys[dataOwner]) {\n encryptedKeys[dataOwner] = {}\n }\n if (!encryptedKeys[dataOwner][delegate]) {\n encryptedKeys[dataOwner][delegate] = { encrypted: [] }\n }\n encryptedKeys[dataOwner][delegate].encrypted.push(encryptedEntries)\n }\n }\n }\n this.cache = encryptedKeys\n }\n}\n"]}
|
|
@@ -17,6 +17,8 @@ const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
|
|
|
17
17
|
const utils_1 = require("./utils");
|
|
18
18
|
const Connection_1 = require("../icc-api/model/Connection");
|
|
19
19
|
const models_1 = require("../icc-api/model/models");
|
|
20
|
+
const XHR_1 = require("../icc-api/api/XHR");
|
|
21
|
+
var XHRError = XHR_1.XHR.XHRError;
|
|
20
22
|
// noinspection JSUnusedGlobalSymbols
|
|
21
23
|
class IccHcpartyXApi extends icc_api_1.IccHcpartyApi {
|
|
22
24
|
constructor(host, headers, authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), authApi, fetchImpl = typeof window !== 'undefined'
|
|
@@ -138,7 +140,12 @@ class IccHcpartyXApi extends icc_api_1.IccHcpartyApi {
|
|
|
138
140
|
else {
|
|
139
141
|
throw new Error(`Hcp with id ${x[0]} not found`);
|
|
140
142
|
}
|
|
141
|
-
})).catch(() =>
|
|
143
|
+
})).catch((e) => {
|
|
144
|
+
if (e instanceof XHRError) {
|
|
145
|
+
throw e;
|
|
146
|
+
}
|
|
147
|
+
return null;
|
|
148
|
+
});
|
|
142
149
|
})).then((results) => results.filter((it) => it != null));
|
|
143
150
|
});
|
|
144
151
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-hcparty-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-hcparty-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAsD;AAEtD,kDAAiD;AACjD,qDAA8E;AAC9E,0EAAgG;AAEhG,mCAAsE;AACtE,4DAAwE;AACxE,oDAAmD;AAEnD,qCAAqC;AACrC,MAAa,cAAe,SAAQ,uBAAa;IAK/C,YACE,IAAY,EACZ,OAAkC,EAClC,yBAAiD,IAAI,iDAAwB,EAAE,EAC9D,OAAmB,EACpC,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,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAPtC,YAAO,GAAP,OAAO,CAAY;QARtC,qBAAgB,GAAiD,EAAE,CAAA;QACnE,iBAAY,GAA0D,EAAE,CAAA;QAEhE,0BAAqB,GAAG,MAAO,CAAA;I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,EAAE,CAAC,CAAC,CAAA;IACjF,CAAC;IAEK,gCAAgC,CACpC,UAA8C,EAC9C,MAAmD,EACnD,UAA0D,EAC1D,UAA+B,EAAE;;YAEjC,OAAO,IAAA,+BAAuB,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CACtH,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,2BAAc,CAAC,EAAE,CAAC,CAC/B,CAAA;QACH,CAAC;KAAA;CACF;AA1KD,wCA0KC","sourcesContent":["import { IccAuthApi, IccHcpartyApi } from '../icc-api'\nimport { HealthcareParty } from '../icc-api/model/HealthcareParty'\nimport * as models from '../icc-api/model/models'\nimport { findName, garnishPersonWithName, hasName } from './utils/person-util'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { AbstractFilter } from './filters/filters'\nimport { subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { ListOfIds } from '../icc-api/model/models'\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccHcpartyXApi extends IccHcpartyApi {\n hcPartyKeysCache: { [key: string]: { [key: string]: string } } = {}\n hcPartyCache: { [key: string]: [number, Promise<HealthcareParty>] } = {}\n\n private CACHE_RETENTION_IN_MS = 300_000\n constructor(\n host: string,\n headers: { [key: string]: string },\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n private readonly authApi: IccAuthApi,\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, authenticationProvider, fetchImpl)\n }\n\n private getHcPartyFromCache(key: string) {\n const hcpInCache = this.hcPartyCache[key]\n const now = Date.now()\n if (hcpInCache && hcpInCache[0] > now) {\n return hcpInCache[1]\n }\n if (!hcpInCache) {\n console.log(`Cache miss for key ${key} because not in cache`)\n } else {\n console.log(`Cache miss for key ${key} because ${hcpInCache[0]} > ${now}`)\n }\n return null\n }\n\n completeNames(hcParty?: models.HealthcareParty): models.HealthcareParty | undefined {\n if (!hcParty) {\n return hcParty\n }\n\n let finalHcParty = hcParty\n\n if ((!!finalHcParty.lastName || !!finalHcParty.name) && !hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n finalHcParty = garnishPersonWithName(\n finalHcParty,\n models.PersonName.UseEnum.Official,\n finalHcParty.lastName,\n finalHcParty.firstName,\n finalHcParty.name\n )\n }\n\n if ((!finalHcParty.lastName || !finalHcParty.name) && !!hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n let officialName = findName(finalHcParty, models.PersonName.UseEnum.Official)\n finalHcParty = {\n ...finalHcParty,\n lastName: officialName!.lastName,\n firstName: officialName!.firstNames ? officialName!.firstNames[0] : undefined,\n name: officialName!.text,\n }\n }\n\n return finalHcParty\n }\n\n putHcPartyInCache(key: string, hcpPromise: Promise<HealthcareParty>): Promise<HealthcareParty> {\n this.hcPartyCache[key] = [Date.now() + this.CACHE_RETENTION_IN_MS, hcpPromise]\n return hcpPromise\n }\n\n createHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcareParty(this.completeNames(body))\n }\n\n createHealthcarePartyInGroup(groupId: string, body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcarePartyInGroup(groupId, this.completeNames(body))\n }\n\n modifyHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty | any> {\n if (body && body.id) {\n console.log(`Evict key ${body.id} because of modification`)\n delete this.hcPartyCache[body.id]\n }\n\n return super.modifyHealthcareParty(this.completeNames(body)).then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n async getHealthcareParty(healthcarePartyId: string, bypassCache = false): Promise<HealthcareParty | any> {\n const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId)\n if (fromCache) {\n try {\n return await fromCache\n } catch {\n if (this.hcPartyCache[healthcarePartyId][1] === fromCache) {\n delete this.hcPartyCache[healthcarePartyId]\n }\n return this.getHealthcareParty(healthcarePartyId, bypassCache)\n }\n } else {\n return await this.putHcPartyInCache(healthcarePartyId, super.getHealthcareParty(healthcarePartyId))\n }\n }\n\n getHealthcarePartyHierarchyIds(healthcarePartyId: string, bypassCache = false): Promise<string[]> {\n return this.getHealthcareParty(healthcarePartyId, bypassCache).then(async (hcp: HealthcareParty) => {\n return hcp ? (hcp.parentId ? (await this.getHealthcarePartyHierarchyIds(hcp.parentId!, bypassCache)).concat([hcp.id!]) : [hcp.id!]) : []\n })\n }\n\n async getHealthcareParties(healthcarePartyIds: ListOfIds): Promise<Array<HealthcareParty> | any> {\n const ids = healthcarePartyIds.ids\n if (!ids || !ids.length) {\n return Promise.resolve([])\n }\n const cached: Array<[string, HealthcareParty | null]> = []\n for (const id of ids) {\n let hcp\n try {\n hcp = await this.getHcPartyFromCache(id)\n } catch {\n hcp = null\n delete this.hcPartyCache[id]\n }\n cached.push([id, hcp])\n }\n const toFetch = cached.filter((x) => !x[1]).map((x) => x[0])\n\n if (!toFetch.length) {\n return Promise.all(cached.map((x) => x[1]!))\n }\n\n const prom: Promise<HealthcareParty[]> = super.getHealthcareParties(new ListOfIds({ ids: toFetch }))\n return Promise.all(\n cached.map(\n (x) =>\n x[1] ??\n this.putHcPartyInCache(\n x[0],\n prom.then((hcps) => {\n const hcp = hcps.find((h) => h.id === x[0])\n if (!!hcp) {\n return hcp\n } else {\n throw new Error(`Hcp with id ${x[0]} not found`)\n }\n })\n ).catch(() => null)\n )\n ).then((results) => results.filter((it) => it != null))\n }\n\n getCurrentHealthcareParty(): Promise<HealthcareParty> {\n return super.getCurrentHealthcareParty().then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n isValidCbe(cbe: string) {\n cbe = cbe.replace(new RegExp('[^(0-9)]', 'g'), '')\n cbe = cbe.length == 9 ? '0' + cbe : cbe\n\n return 97 - (Number(cbe.substring(0, 8)) % 97) === Number(cbe.substring(8, 10))\n }\n\n async subscribeToHealthcarePartyEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<HealthcareParty> | undefined,\n eventFired: (dataSample: HealthcareParty) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n return subscribeToEntityEvents(this.host, this.authApi, 'HealthcareParty', eventTypes, filter, eventFired, options).then(\n (rs) => new ConnectionImpl(rs)\n )\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"icc-hcparty-x-api.js","sourceRoot":"","sources":["../../icc-x-api/icc-hcparty-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAAsD;AAEtD,kDAAiD;AACjD,qDAA8E;AAC9E,0EAAgG;AAEhG,mCAAsE;AACtE,4DAAwE;AACxE,oDAAmD;AACnD,4CAAwC;AACxC,IAAO,QAAQ,GAAG,SAAG,CAAC,QAAQ,CAAA;AAE9B,qCAAqC;AACrC,MAAa,cAAe,SAAQ,uBAAa;IAK/C,YACE,IAAY,EACZ,OAAkC,EAClC,yBAAiD,IAAI,iDAAwB,EAAE,EAC9D,OAAmB,EACpC,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,sBAAsB,EAAE,SAAS,CAAC,CAAA;QAPtC,YAAO,GAAP,OAAO,CAAY;QARtC,qBAAgB,GAAiD,EAAE,CAAA;QACnE,iBAAY,GAA0D,EAAE,CAAA;QAEhE,0BAAqB,GAAG,MAAO,CAAA;IAavC,CAAC;IAEO,mBAAmB,CAAC,GAAW;QACrC,MAAM,UAAU,GAAG,IAAI,CAAC,YAA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AAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;IACjF,CAAC;IAEK,gCAAgC,CACpC,UAA8C,EAC9C,MAAmD,EACnD,UAA0D,EAC1D,UAA+B,EAAE;;YAEjC,OAAO,IAAA,+BAAuB,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CACtH,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,2BAAc,CAAC,EAAE,CAAC,CAC/B,CAAA;QACH,CAAC;KAAA;CACF;AA/KD,wCA+KC","sourcesContent":["import { IccAuthApi, IccHcpartyApi } from '../icc-api'\nimport { HealthcareParty } from '../icc-api/model/HealthcareParty'\nimport * as models from '../icc-api/model/models'\nimport { findName, garnishPersonWithName, hasName } from './utils/person-util'\nimport { AuthenticationProvider, NoAuthenticationProvider } from './auth/AuthenticationProvider'\nimport { AbstractFilter } from './filters/filters'\nimport { subscribeToEntityEvents, SubscriptionOptions } from './utils'\nimport { Connection, ConnectionImpl } from '../icc-api/model/Connection'\nimport { ListOfIds } from '../icc-api/model/models'\nimport { XHR } from '../icc-api/api/XHR'\nimport XHRError = XHR.XHRError\n\n// noinspection JSUnusedGlobalSymbols\nexport class IccHcpartyXApi extends IccHcpartyApi {\n hcPartyKeysCache: { [key: string]: { [key: string]: string } } = {}\n hcPartyCache: { [key: string]: [number, Promise<HealthcareParty>] } = {}\n\n private CACHE_RETENTION_IN_MS = 300_000\n constructor(\n host: string,\n headers: { [key: string]: string },\n authenticationProvider: AuthenticationProvider = new NoAuthenticationProvider(),\n private readonly authApi: IccAuthApi,\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, authenticationProvider, fetchImpl)\n }\n\n private getHcPartyFromCache(key: string) {\n const hcpInCache = this.hcPartyCache[key]\n const now = Date.now()\n if (hcpInCache && hcpInCache[0] > now) {\n return hcpInCache[1]\n }\n if (!hcpInCache) {\n console.log(`Cache miss for key ${key} because not in cache`)\n } else {\n console.log(`Cache miss for key ${key} because ${hcpInCache[0]} > ${now}`)\n }\n return null\n }\n\n completeNames(hcParty?: models.HealthcareParty): models.HealthcareParty | undefined {\n if (!hcParty) {\n return hcParty\n }\n\n let finalHcParty = hcParty\n\n if ((!!finalHcParty.lastName || !!finalHcParty.name) && !hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n finalHcParty = garnishPersonWithName(\n finalHcParty,\n models.PersonName.UseEnum.Official,\n finalHcParty.lastName,\n finalHcParty.firstName,\n finalHcParty.name\n )\n }\n\n if ((!finalHcParty.lastName || !finalHcParty.name) && !!hasName(finalHcParty, models.PersonName.UseEnum.Official)) {\n let officialName = findName(finalHcParty, models.PersonName.UseEnum.Official)\n finalHcParty = {\n ...finalHcParty,\n lastName: officialName!.lastName,\n firstName: officialName!.firstNames ? officialName!.firstNames[0] : undefined,\n name: officialName!.text,\n }\n }\n\n return finalHcParty\n }\n\n putHcPartyInCache(key: string, hcpPromise: Promise<HealthcareParty>): Promise<HealthcareParty> {\n this.hcPartyCache[key] = [Date.now() + this.CACHE_RETENTION_IN_MS, hcpPromise]\n return hcpPromise\n }\n\n createHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcareParty(this.completeNames(body))\n }\n\n createHealthcarePartyInGroup(groupId: string, body?: HealthcareParty): Promise<HealthcareParty> {\n return super.createHealthcarePartyInGroup(groupId, this.completeNames(body))\n }\n\n modifyHealthcareParty(body?: HealthcareParty): Promise<HealthcareParty | any> {\n if (body && body.id) {\n console.log(`Evict key ${body.id} because of modification`)\n delete this.hcPartyCache[body.id]\n }\n\n return super.modifyHealthcareParty(this.completeNames(body)).then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n async getHealthcareParty(healthcarePartyId: string, bypassCache = false): Promise<HealthcareParty | any> {\n const fromCache = bypassCache ? undefined : this.getHcPartyFromCache(healthcarePartyId)\n if (fromCache) {\n try {\n return await fromCache\n } catch {\n if (this.hcPartyCache[healthcarePartyId][1] === fromCache) {\n delete this.hcPartyCache[healthcarePartyId]\n }\n return this.getHealthcareParty(healthcarePartyId, bypassCache)\n }\n } else {\n return await this.putHcPartyInCache(healthcarePartyId, super.getHealthcareParty(healthcarePartyId))\n }\n }\n\n getHealthcarePartyHierarchyIds(healthcarePartyId: string, bypassCache = false): Promise<string[]> {\n return this.getHealthcareParty(healthcarePartyId, bypassCache).then(async (hcp: HealthcareParty) => {\n return hcp ? (hcp.parentId ? (await this.getHealthcarePartyHierarchyIds(hcp.parentId!, bypassCache)).concat([hcp.id!]) : [hcp.id!]) : []\n })\n }\n\n async getHealthcareParties(healthcarePartyIds: ListOfIds): Promise<Array<HealthcareParty> | any> {\n const ids = healthcarePartyIds.ids\n if (!ids || !ids.length) {\n return Promise.resolve([])\n }\n const cached: Array<[string, HealthcareParty | null]> = []\n for (const id of ids) {\n let hcp\n try {\n hcp = await this.getHcPartyFromCache(id)\n } catch {\n hcp = null\n delete this.hcPartyCache[id]\n }\n cached.push([id, hcp])\n }\n const toFetch = cached.filter((x) => !x[1]).map((x) => x[0])\n\n if (!toFetch.length) {\n return Promise.all(cached.map((x) => x[1]!))\n }\n\n const prom: Promise<HealthcareParty[]> = super.getHealthcareParties(new ListOfIds({ ids: toFetch }))\n return Promise.all(\n cached.map(\n (x) =>\n x[1] ??\n this.putHcPartyInCache(\n x[0],\n prom.then((hcps) => {\n const hcp = hcps.find((h) => h.id === x[0])\n if (!!hcp) {\n return hcp\n } else {\n throw new Error(`Hcp with id ${x[0]} not found`)\n }\n })\n ).catch((e) => {\n if (e instanceof XHRError) {\n throw e\n }\n return null\n })\n )\n ).then((results) => results.filter((it) => it != null))\n }\n\n getCurrentHealthcareParty(): Promise<HealthcareParty> {\n return super.getCurrentHealthcareParty().then((hcp) => this.putHcPartyInCache(hcp.id!, Promise.resolve(hcp)))\n }\n\n isValidCbe(cbe: string) {\n cbe = cbe.replace(new RegExp('[^(0-9)]', 'g'), '')\n cbe = cbe.length == 9 ? '0' + cbe : cbe\n\n return 97 - (Number(cbe.substring(0, 8)) % 97) === Number(cbe.substring(8, 10))\n }\n\n async subscribeToHealthcarePartyEvents(\n eventTypes: ('CREATE' | 'UPDATE' | 'DELETE')[],\n filter: AbstractFilter<HealthcareParty> | undefined,\n eventFired: (dataSample: HealthcareParty) => Promise<void>,\n options: SubscriptionOptions = {}\n ): Promise<Connection> {\n return subscribeToEntityEvents(this.host, this.authApi, 'HealthcareParty', eventTypes, filter, eventFired, options).then(\n (rs) => new ConnectionImpl(rs)\n )\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import 'isomorphic-fetch';
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
require("isomorphic-fetch");
|
|
13
|
+
const util_1 = require("util");
|
|
14
|
+
const icc_x_api_1 = require("../../icc-x-api");
|
|
15
|
+
const crypto_1 = require("crypto");
|
|
16
|
+
function setLocalStorage(fetch) {
|
|
17
|
+
;
|
|
18
|
+
global.localStorage = new (require('node-localstorage').LocalStorage)("/Users/trema/icure-typescript-sdk/scratch", 5 * Math.pow(1024, 3));
|
|
19
|
+
global.fetch = fetch;
|
|
20
|
+
global.Storage = '';
|
|
21
|
+
global.TextDecoder = util_1.TextDecoder;
|
|
22
|
+
global.TextEncoder = util_1.TextEncoder;
|
|
23
|
+
global.headers = Headers;
|
|
24
|
+
}
|
|
25
|
+
setLocalStorage(fetch);
|
|
26
|
+
class MyCryptoStrategies {
|
|
27
|
+
dataOwnerRequiresAnonymousDelegation(dataOwner) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
generateNewKeyForDataOwner(self, cryptoPrimitives) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
return Promise.resolve(false);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
recoverAndVerifySelfHierarchyKeys(keysData, cryptoPrimitives, keyPairRecoverer) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
return {
|
|
38
|
+
"44f19c1a-8da8-4959-90df-96a2e98112f4": {
|
|
39
|
+
recoveredKeys: {
|
|
40
|
+
"a6987fd0b8335e60a59abf0203010001": yield cryptoPrimitives.RSA.importKeyPair("pkcs8", (0, icc_x_api_1.hex2ua)("privhere"), "spki", (0, icc_x_api_1.hex2ua)("30820122300d06092a864886f70d01010105000382010f003082010a0282010100a0c7b15b203e00d233f169897ad96c3f82137c3d302e490264238fbda1f609c1152f4a1e75848e5d87133db56fa00678c4e5d9c27efb51e37d59e214b2fcfd7a5d89015a60f582d53ff8ee9c6164f003ec2f08984203008ac3d2a7f169c06cee3629611f04fc6e806a2a6ef846277c9c52c0dedd78ed11185208d0d544ee641b080b7178cb15d2a14b78e9c0e5629a2dac3a97a0a5bd13e694af68daad1ca86ee34cdeecef26db26360c6773c9c6b614b8040cdcbb306a3baac726a9928c792f6801dd65277f8febac1791fbf35eab7968bb0ed16d49308dff679a5e915e73fb827e5efa13ac04c1b2595069d7f50d4fd0e8589e7ba6987fd0b8335e60a59abf0203010001"), icc_x_api_1.ShaVersion.Sha1)
|
|
41
|
+
},
|
|
42
|
+
keyAuthenticity: {}
|
|
43
|
+
},
|
|
44
|
+
"f80f2b9f-4924-4a46-a6a4-a176f33607d8": {
|
|
45
|
+
recoveredKeys: {
|
|
46
|
+
"dd1574537845c22ac062190203010001": yield cryptoPrimitives.RSA.importKeyPair("pkcs8", (0, icc_x_api_1.hex2ua)("privhere"), "spki", (0, icc_x_api_1.hex2ua)("30820122300d06092a864886f70d01010105000382010f003082010a028201010095b3e15bf00ee73c2adea786f0783cd0ddf09e8aeded45e4a0b5982c96b8025ef6e7b31e2498073fa956dc195871e7e64f37a663900aae2ba9e6c89651b8bbb3da03e77e12424dddccf2343c2ac9e64f99f2bf1dc6fa0acfe289d0c0cb41dd0dbc6c71f8cdab722ec2a6f73a241eda7600128e64bcd0f106eca8f849fd8ec1c9c27c61d88a3c4c6940c43d7d54efc01b397e835e8ef43a2c2f216aa5ad1a281399ac513d407389d4661f68b45f7c12354547666087a2a644bdc7823e06adada1142d35cf048da03106040281b6b26a213bca037d3b63fd974fcd518938c697000a738ac2c7c6578d7ee7bb9662d35133bc8b919b37dd1574537845c22ac062190203010001"), icc_x_api_1.ShaVersion.Sha1)
|
|
47
|
+
},
|
|
48
|
+
keyAuthenticity: {}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
verifyDelegatePublicKeys(delegate, publicKeys, cryptoPrimitives) {
|
|
54
|
+
throw "Unused";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
describe('Autofix anonymity tests', () => {
|
|
58
|
+
it('User', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
console.log("Start init");
|
|
60
|
+
const api = yield icc_x_api_1.IcureApi.initialise("https://api.icure.cloud", { "username": "2de6069e-b8af-4831-aac9-75953b4780cf", password: "54d3b6ba-e969-453f-bf6c-b0a2e6f26b87" }, new MyCryptoStrategies(), crypto_1.webcrypto, fetch);
|
|
61
|
+
console.log("Init done");
|
|
62
|
+
const user = yield api.userApi.getCurrentUser();
|
|
63
|
+
console.log("Getting calendar items");
|
|
64
|
+
const calendarItems = yield api.calendarItemApi.getCalendarsByPeriodAndAgendaIdWithUser(user, 20250117000000, 20250118000000, "agenda_2de6069e-b8af-4831-aac9-75953b4780cf");
|
|
65
|
+
for (const ci of calendarItems) {
|
|
66
|
+
yield api.calendarItemApi.getDataOwnersWithAccessTo(ci);
|
|
67
|
+
}
|
|
68
|
+
// console.log(calendarItems.map((x) => x.details))
|
|
69
|
+
// console.log("Getting time tables")
|
|
70
|
+
// const timeTables: Array<TimeTable> = await api.timetableApi.getTimeTablesByPeriodAndAgendaId(20250117000000, 20250118000000, "agenda_2de6069e-b8af-4831-aac9-75953b4780cf")
|
|
71
|
+
// console.log("Get types")
|
|
72
|
+
// console.log(await api.calendarItemTypeApi.getCalendarItemTypesIncludeDeletedWithPagination())
|
|
73
|
+
}));
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=diocancaro.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diocancaro.js","sourceRoot":"","sources":["../../../test/icc-x-api/diocancaro.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAAyB;AACzB,+BAA8C;AAC9C,+CAA0G;AAI1G,mCAAiC;AAIjC,SAAS,eAAe,CAAC,KAAoE;IAC3F,CAAC;IAAC,MAAc,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC,YAAY,CAAC,CAAC,2CAA2C,EAAE,CAAC,GAAG,SAAA,IAAI,EAAI,CAAC,CAAA,CAAC,CAC1I;IAAC,MAAc,CAAC,KAAK,GAAG,KAAK,CAC7B;IAAC,MAAc,CAAC,OAAO,GAAG,EAAE,CAC5B;IAAC,MAAc,CAAC,WAAW,GAAG,kBAAW,CACzC;IAAC,MAAc,CAAC,WAAW,GAAG,kBAAW,CACzC;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,EAAE,UAAU,EAAE,sCAAsC,EAAE,QAAQ,EAAE,sCAAsC,EAAC,EACvG,IAAI,kBAAkB,EAAE,EACxB,kBAAgB,EAChB,KAAK,CACN,CAAA;QACD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAA;QACxB,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,CAAA;QAC/C,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAA;QACrC,MAAM,aAAa,GAAwB,MAAM,GAAG,CAAC,eAAe,CAAC,uCAAuC,CAAC,IAAI,EAAE,cAAc,EAAE,cAAc,EAAE,6CAA6C,CAAC,CAAA;QACjM,KAAK,MAAM,EAAE,IAAI,aAAa,EAAE;YAC9B,MAAM,GAAG,CAAC,eAAe,CAAC,yBAAyB,CAAC,EAAE,CAAC,CAAA;SACxD;QACD,mDAAmD;QACnD,qCAAqC;QACrC,8KAA8K;QAC9K,2BAA2B;QAC3B,gGAAgG;IAClG,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import 'isomorphic-fetch'\nimport {TextDecoder, TextEncoder} from \"util\";\nimport {CryptoPrimitives, CryptoStrategies, hex2ua, IcureApi, KeyPair, ShaVersion} from \"../../icc-x-api\";\nimport {CryptoActorStubWithType} from \"../../icc-api/model/CryptoActorStub\";\nimport {DataOwnerWithType} from \"../../icc-api/model/DataOwnerWithType\";\nimport {KeyPairRecoverer} from \"../../icc-x-api/crypto/KeyPairRecoverer\";\nimport {webcrypto} from \"crypto\";\nimport {CalendarItem} from \"../../icc-api/model/CalendarItem\";\nimport {TimeTable} from \"../../icc-api/model/TimeTable\";\n\nfunction setLocalStorage(fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>) {\n ;(global as any).localStorage = new (require('node-localstorage').LocalStorage)(\"/Users/trema/icure-typescript-sdk/scratch\", 5 * 1024 ** 3)\n ;(global as any).fetch = fetch\n ;(global as any).Storage = ''\n ;(global as any).TextDecoder = TextDecoder\n ;(global as any).TextEncoder = TextEncoder\n ;(global as any).headers = Headers\n}\nsetLocalStorage(fetch)\n\nclass MyCryptoStrategies implements CryptoStrategies {\n dataOwnerRequiresAnonymousDelegation(dataOwner: CryptoActorStubWithType): boolean {\n return false;\n }\n\n async generateNewKeyForDataOwner(self: DataOwnerWithType, cryptoPrimitives: CryptoPrimitives): Promise<KeyPair<CryptoKey> | boolean> {\n return Promise.resolve(false);\n }\n\n async recoverAndVerifySelfHierarchyKeys(keysData: {\n dataOwner: DataOwnerWithType;\n unknownKeys: string[];\n unavailableKeys: string[]\n }[], cryptoPrimitives: CryptoPrimitives, keyPairRecoverer: KeyPairRecoverer): Promise<{\n [p: string]: { recoveredKeys: { [p: string]: KeyPair<CryptoKey> }; keyAuthenticity: { [p: string]: boolean } }\n }> {\n return {\n \"44f19c1a-8da8-4959-90df-96a2e98112f4\": {\n recoveredKeys: {\n \"a6987fd0b8335e60a59abf0203010001\": await cryptoPrimitives.RSA.importKeyPair(\n \"pkcs8\",\n hex2ua(\"privhere\"),\n \"spki\",\n hex2ua(\"30820122300d06092a864886f70d01010105000382010f003082010a0282010100a0c7b15b203e00d233f169897ad96c3f82137c3d302e490264238fbda1f609c1152f4a1e75848e5d87133db56fa00678c4e5d9c27efb51e37d59e214b2fcfd7a5d89015a60f582d53ff8ee9c6164f003ec2f08984203008ac3d2a7f169c06cee3629611f04fc6e806a2a6ef846277c9c52c0dedd78ed11185208d0d544ee641b080b7178cb15d2a14b78e9c0e5629a2dac3a97a0a5bd13e694af68daad1ca86ee34cdeecef26db26360c6773c9c6b614b8040cdcbb306a3baac726a9928c792f6801dd65277f8febac1791fbf35eab7968bb0ed16d49308dff679a5e915e73fb827e5efa13ac04c1b2595069d7f50d4fd0e8589e7ba6987fd0b8335e60a59abf0203010001\"),\n ShaVersion.Sha1\n )\n },\n keyAuthenticity: {}\n },\n \"f80f2b9f-4924-4a46-a6a4-a176f33607d8\": {\n recoveredKeys: {\n \"dd1574537845c22ac062190203010001\": await cryptoPrimitives.RSA.importKeyPair(\n \"pkcs8\",\n hex2ua(\"privhere\"),\n \"spki\",\n hex2ua(\"30820122300d06092a864886f70d01010105000382010f003082010a028201010095b3e15bf00ee73c2adea786f0783cd0ddf09e8aeded45e4a0b5982c96b8025ef6e7b31e2498073fa956dc195871e7e64f37a663900aae2ba9e6c89651b8bbb3da03e77e12424dddccf2343c2ac9e64f99f2bf1dc6fa0acfe289d0c0cb41dd0dbc6c71f8cdab722ec2a6f73a241eda7600128e64bcd0f106eca8f849fd8ec1c9c27c61d88a3c4c6940c43d7d54efc01b397e835e8ef43a2c2f216aa5ad1a281399ac513d407389d4661f68b45f7c12354547666087a2a644bdc7823e06adada1142d35cf048da03106040281b6b26a213bca037d3b63fd974fcd518938c697000a738ac2c7c6578d7ee7bb9662d35133bc8b919b37dd1574537845c22ac062190203010001\"),\n ShaVersion.Sha1\n )\n },\n keyAuthenticity: {}\n }\n }\n }\n\n verifyDelegatePublicKeys(delegate: CryptoActorStubWithType, publicKeys: string[], cryptoPrimitives: CryptoPrimitives): Promise<string[]> {\n throw \"Unused\";\n }\n\n}\n\ndescribe('Autofix anonymity tests', () => {\n it('User', async () => {\n console.log(\"Start init\")\n const api = await IcureApi.initialise(\n \"https://api.icure.cloud\",\n { \"username\": \"2de6069e-b8af-4831-aac9-75953b4780cf\", password: \"54d3b6ba-e969-453f-bf6c-b0a2e6f26b87\"},\n new MyCryptoStrategies(),\n webcrypto as any,\n fetch,\n )\n console.log(\"Init done\")\n const user = await api.userApi.getCurrentUser()\n console.log(\"Getting calendar items\")\n const calendarItems: Array<CalendarItem> = await api.calendarItemApi.getCalendarsByPeriodAndAgendaIdWithUser(user, 20250117000000, 20250118000000, \"agenda_2de6069e-b8af-4831-aac9-75953b4780cf\")\n for (const ci of calendarItems) {\n await api.calendarItemApi.getDataOwnersWithAccessTo(ci)\n }\n // console.log(calendarItems.map((x) => x.details))\n // console.log(\"Getting time tables\")\n // const timeTables: Array<TimeTable> = await api.timetableApi.getTimeTablesByPeriodAndAgendaId(20250117000000, 20250118000000, \"agenda_2de6069e-b8af-4831-aac9-75953b4780cf\")\n // console.log(\"Get types\")\n // console.log(await api.calendarItemTypeApi.getCalendarItemTypesIncludeDeletedWithPagination())\n })\n})"]}
|