@icure/api 8.6.7 → 8.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/icc-api/api/IccAccesslogApi.d.ts +14 -0
  2. package/icc-api/api/IccAccesslogApi.js +31 -0
  3. package/icc-api/api/IccAccesslogApi.js.map +1 -1
  4. package/icc-api/model/AbstractFilterAccessLog.d.ts +15 -0
  5. package/icc-api/model/AbstractFilterAccessLog.js +21 -0
  6. package/icc-api/model/AbstractFilterAccessLog.js.map +1 -0
  7. package/icc-api/model/ChapterParagraph.d.ts +16 -0
  8. package/icc-api/model/ChapterParagraph.js +21 -0
  9. package/icc-api/model/ChapterParagraph.js.map +1 -0
  10. package/icc-api/model/Reimbursement.d.ts +2 -0
  11. package/icc-api/model/Reimbursement.js.map +1 -1
  12. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js +2 -2
  13. package/icc-x-api/crypto/ExtendedApisUtilsImpl.js.map +1 -1
  14. package/icc-x-api/filters/AccessLogByDataOwnerPatientDateFilter.d.ts +22 -0
  15. package/icc-x-api/filters/AccessLogByDataOwnerPatientDateFilter.js +24 -0
  16. package/icc-x-api/filters/AccessLogByDataOwnerPatientDateFilter.js.map +1 -0
  17. package/icc-x-api/filters/AccessLogByDateFilter.d.ts +20 -0
  18. package/icc-x-api/filters/AccessLogByDateFilter.js +24 -0
  19. package/icc-x-api/filters/AccessLogByDateFilter.js.map +1 -0
  20. package/icc-x-api/filters/AccessLogByUserIdUserTypeDateFilter.d.ts +21 -0
  21. package/icc-x-api/filters/AccessLogByUserIdUserTypeDateFilter.js +24 -0
  22. package/icc-x-api/filters/AccessLogByUserIdUserTypeDateFilter.js.map +1 -0
  23. package/icc-x-api/icc-contact-x-api.js +3 -3
  24. package/icc-x-api/icc-contact-x-api.js.map +1 -1
  25. package/icc-x-api/utils/crypto-utils.d.ts +2 -1
  26. package/icc-x-api/utils/crypto-utils.js +57 -6
  27. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  28. package/package.json +1 -1
  29. package/test/icc-x-api/crypto/anonymous-delegations-test.js +1 -1
  30. package/test/icc-x-api/crypto/anonymous-delegations-test.js.map +1 -1
  31. package/test/icc-x-api/crypto/cryptoTest.js +99 -1
  32. package/test/icc-x-api/crypto/cryptoTest.js.map +1 -1
  33. package/test/icc-x-api/crypto/legacy-metadata-migration-test.js +3 -3
  34. package/test/icc-x-api/crypto/legacy-metadata-migration-test.js.map +1 -1
  35. package/test/icc-x-api/entity-with-attachments-api-test.js +2 -2
  36. package/test/icc-x-api/entity-with-attachments-api-test.js.map +1 -1
  37. package/test/icc-x-api/icc-user-x-api-test.js +1 -1
  38. package/test/icc-x-api/icc-user-x-api-test.js.map +1 -1
  39. package/test/support/CSM-243.js +5 -5
  40. package/test/support/CSM-243.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"entity-with-attachments-api-test.js","sourceRoot":"","sources":["../../../test/icc-x-api/entity-with-attachments-api-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAAyB;AACzB,oDAAyG;AACzG,iCAA8B;AAG9B,+CAAyD;AACzD,IAAO,OAAO,GAAG,sBAAS,CAAC,OAAO,CAAA;AAClC,+BAA6B;AAC7B,mDAAmE;AAEnE,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AACtB,IAAI,GAAa,CAAA;AACjB,IAAI,IAAU,CAAA;AACd,IAAI,IAAU,CAAA;AASd,MAAM,wBAAwB,GAAG;IAC/B,iBAAiB,EAAE,CAAC,IAAU,EAAE,WAAiB,EAAE,EAAE,CACnD,CAA0C;QAClC,YAAY;;gBAChB,OAAO,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,MAAM,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAA;YACzF,CAAC;SAAA;QACD,uBAAuB,CAAC,MAAuB,EAAE,UAAoC;YACnF,OAAO,IAAI,CAAC,WAAW,CAAC,+BAA+B,CAA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AA,aAAM,EAAC,gBAAgB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAA;gBACnC,MAAM,kBAAkB,GAAG,sCAAsC,CAAA;gBACjE,MAAM,oBAAoB,GAAG,MAAM,aAAa,CAAC,uBAAuB,CAAC,mBAAmB,EAAE,IAAA,oBAAQ,EAAC,kBAAkB,CAAC,CAAC,CAAA;gBAC3H,MAAM,oBAAoB,GAAG,MAAM,aAAa,CAAC,uBAAuB,CAAC,oBAAoB,EAAE,CAAO,CAAC,EAAE,EAAE;oBACzG,IAAI,CAAC;wBACH,OAAO,IAAA,mBAAO,EAAC,CAAC,CAAC,KAAK,kBAAkB,CAAA;oBAC1C,CAAC;oBAAC,WAAM,CAAC;wBACP,OAAO,KAAK,CAAA;oBACd,CAAC;gBACH,CAAC,CAAA,CAAC,CAAA;gBACF,IAAA,aAAM,EAAC,IAAA,mBAAO,EAAC,oBAAoB,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAA;gBAClE,MAAM,oBAAoB,GAAG,MAAM,aAAa,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,CAAA;gBAC7F,IAAI,iBAAiB,CAAA;gBACrB,IAAI,CAAC;oBACH,iBAAiB,GAAG,IAAA,mBAAO,EAAC,oBAAoB,CAAC,KAAK,kBAAkB,CAAA;gBAC1E,CAAC;gBAAC,WAAM,CAAC;oBACP,iBAAiB,GAAG,IAAI,CAAA;gBAC1B,CAAC;gBACD,IAAA,aAAM,EAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAA;YACtC,CAAC,CAAA,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CAAA,CAAC,CAAA","sourcesContent":["import 'isomorphic-fetch'\nimport { getEnvironmentInitializer, hcp1Username, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport { before } from 'mocha'\nimport * as models from '../../icc-api/model/models'\nimport { User } from '../../icc-api/model/User'\nimport { Apis, ua2utf8, utf8_2ua } from '../../icc-x-api'\nimport initApi = TestUtils.initApi\nimport { expect } from 'chai'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\n\nsetLocalStorage(fetch)\nlet env: TestVars\nlet apis: Apis\nlet user: User\n\ninterface EntityWithAttachmentApi<T> {\n createEntity(): Promise<T>\n encryptAndSetAttachment(entity: T, attachment: ArrayBuffer | Uint8Array): Promise<T>\n getAndDecryptAttachment(entity: T, validator: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer>\n getEncryptedAttachment(entity: T): Promise<ArrayBuffer>\n}\n\nconst entityWithAttachmentApis = {\n docMainAttachment: (apis: Apis, currentUser: User) =>\n <EntityWithAttachmentApi<models.Document>>{\n async createEntity(): Promise<models.Document> {\n return apis.documentApi.createDocument(await apis.documentApi.newInstance(currentUser))\n },\n encryptAndSetAttachment(entity: models.Document, attachment: ArrayBuffer | Uint8Array): Promise<models.Document> {\n return apis.documentApi.encryptAndSetDocumentAttachment(entity, attachment)\n },\n getAndDecryptAttachment(entity: models.Document, validator: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer> {\n return apis.documentApi.getAndDecryptDocumentAttachment(entity, validator)\n },\n getEncryptedAttachment(entity: models.Document): Promise<ArrayBuffer> {\n return apis.documentApi.getDocumentAttachment(entity.id!, 'unused')\n },\n },\n docSecondaryAttachment: (apis: Apis, currentUser: User) =>\n <EntityWithAttachmentApi<models.Document>>{\n async createEntity(): Promise<models.Document> {\n return apis.documentApi.createDocument(await apis.documentApi.newInstance(currentUser))\n },\n encryptAndSetAttachment(entity: models.Document, attachment: ArrayBuffer | Uint8Array): Promise<models.Document> {\n return apis.documentApi.encryptAndSetSecondaryDocumentAttachment(entity, 'secondary', attachment)\n },\n getAndDecryptAttachment(entity: models.Document, validator: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer> {\n return apis.documentApi.getAndDecryptSecondaryDocumentAttachment(entity, 'secondary', validator)\n },\n getEncryptedAttachment(entity: models.Document): Promise<ArrayBuffer> {\n return apis.documentApi.getSecondaryAttachment(entity.id!, 'secondary')\n },\n },\n receipt: (apis: Apis, currentUser: User) =>\n <EntityWithAttachmentApi<models.Receipt>>{\n async createEntity(): Promise<models.Receipt> {\n return apis.receiptApi.createReceipt(await apis.receiptApi.newInstance(currentUser, {}))\n },\n async encryptAndSetAttachment(entity: models.Receipt, attachment: ArrayBuffer | Uint8Array): Promise<models.Receipt> {\n return apis.receiptApi.encryptAndSetReceiptAttachment(entity, 'tack', attachment)\n },\n getAndDecryptAttachment(entity: models.Receipt, validator: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer> {\n return apis.receiptApi.getAndDecryptReceiptAttachment(entity, (entity.attachmentIds ?? {})['tack'], validator)\n },\n getEncryptedAttachment(entity: models.Receipt): Promise<ArrayBuffer> {\n return apis.receiptApi.getReceiptAttachment(entity.id!, (entity.attachmentIds ?? {})['tack'])\n },\n },\n}\n\nbefore(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n for (const [a, b] of Object.entries(env.dataOwnerDetails)) {\n console.log(a)\n console.log(b.password)\n console.log('')\n }\n apis = await initApi(env!, hcp1Username)\n user = await apis.userApi.getCurrentUser()\n})\n\ndescribe('Entity attachment update methods', async function () {\n Object.entries(entityWithAttachmentApis).forEach(([type, attachmentApiInitialiser]) => {\n it(`should automatically encrypt and decrypt attachments (${type})`, async () => {\n const attachmentApi = attachmentApiInitialiser(apis, user)\n const entity = await attachmentApi.createEntity()\n console.log(`entity id ${entity.id}`)\n const attachmentContent = 'This is some secret attachment'\n const entityWithEncrypted = await attachmentApi.encryptAndSetAttachment(entity, utf8_2ua(attachmentContent))\n const decryptedAttachment = await attachmentApi.getAndDecryptAttachment(entityWithEncrypted, async (d) => {\n try {\n return ua2utf8(d) === attachmentContent\n } catch {\n return false\n }\n })\n expect(ua2utf8(decryptedAttachment)).to.equal(attachmentContent)\n const encryptedAttachment = await attachmentApi.getEncryptedAttachment(entityWithEncrypted)\n let conversionFailed\n try {\n conversionFailed = ua2utf8(encryptedAttachment) !== attachmentContent\n } catch {\n conversionFailed = true\n }\n expect(conversionFailed).to.be.true\n const attachmentContent2 = 'This is an updated secret attachment'\n const entityWithEncrypted2 = await attachmentApi.encryptAndSetAttachment(entityWithEncrypted, utf8_2ua(attachmentContent2))\n const decryptedAttachment2 = await attachmentApi.getAndDecryptAttachment(entityWithEncrypted2, async (d) => {\n try {\n return ua2utf8(d) === attachmentContent2\n } catch {\n return false\n }\n })\n expect(ua2utf8(decryptedAttachment2)).to.equal(attachmentContent2)\n const encryptedAttachment2 = await attachmentApi.getEncryptedAttachment(entityWithEncrypted2)\n let conversionFailed2\n try {\n conversionFailed2 = ua2utf8(encryptedAttachment2) !== attachmentContent2\n } catch {\n conversionFailed2 = true\n }\n expect(conversionFailed2).to.be.true\n })\n })\n})\n"]}
1
+ {"version":3,"file":"entity-with-attachments-api-test.js","sourceRoot":"","sources":["../../../test/icc-x-api/entity-with-attachments-api-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4BAAyB;AACzB,oDAAyG;AACzG,iCAA8B;AAG9B,+CAAyD;AACzD,IAAO,OAAO,GAAG,sBAAS,CAAC,OAAO,CAAA;AAClC,+BAA6B;AAC7B,mDAAmE;AAEnE,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AACtB,IAAI,GAAa,CAAA;AACjB,IAAI,IAAU,CAAA;AACd,IAAI,IAAU,CAAA;AASd,MAAM,wBAAwB,GAAG;IAC/B,iBAAiB,EAAE,CAAC,IAAU,EAAE,WAAiB,EAAE,EAAE,CACnD,CAA0C;QAClC,YAAY;;gBAChB,OAAO,IAAI,CAAC,WAAW,CAAC,sBAAsB,CAAC,WAAW,EAAE,MAAM,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAA;YAC9G,CAAC;SAAA;QACD,uBAAuB,CAAC,MAA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} from '../utils/test_utils'\nimport { before } from 'mocha'\nimport * as models from '../../icc-api/model/models'\nimport { User } from '../../icc-api/model/User'\nimport { Apis, ua2utf8, utf8_2ua } from '../../icc-x-api'\nimport initApi = TestUtils.initApi\nimport { expect } from 'chai'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\n\nsetLocalStorage(fetch)\nlet env: TestVars\nlet apis: Apis\nlet user: User\n\ninterface EntityWithAttachmentApi<T> {\n createEntity(): Promise<T>\n encryptAndSetAttachment(entity: T, attachment: ArrayBuffer | Uint8Array): Promise<T>\n getAndDecryptAttachment(entity: T, validator: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer>\n getEncryptedAttachment(entity: T): Promise<ArrayBuffer>\n}\n\nconst entityWithAttachmentApis = {\n docMainAttachment: (apis: Apis, currentUser: User) =>\n <EntityWithAttachmentApi<models.Document>>{\n async createEntity(): Promise<models.Document> {\n return apis.documentApi.createDocumentWithUser(currentUser, await apis.documentApi.newInstance(currentUser))\n },\n encryptAndSetAttachment(entity: models.Document, attachment: ArrayBuffer | Uint8Array): Promise<models.Document> {\n return apis.documentApi.encryptAndSetDocumentAttachment(entity, attachment)\n },\n getAndDecryptAttachment(entity: models.Document, validator: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer> {\n return apis.documentApi.getAndDecryptDocumentAttachment(entity, validator)\n },\n getEncryptedAttachment(entity: models.Document): Promise<ArrayBuffer> {\n return apis.documentApi.getDocumentAttachment(entity.id!, 'unused')\n },\n },\n docSecondaryAttachment: (apis: Apis, currentUser: User) =>\n <EntityWithAttachmentApi<models.Document>>{\n async createEntity(): Promise<models.Document> {\n return apis.documentApi.createDocumentWithUser(currentUser, await apis.documentApi.newInstance(currentUser))\n },\n encryptAndSetAttachment(entity: models.Document, attachment: ArrayBuffer | Uint8Array): Promise<models.Document> {\n return apis.documentApi.encryptAndSetSecondaryDocumentAttachment(entity, 'secondary', attachment)\n },\n getAndDecryptAttachment(entity: models.Document, validator: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer> {\n return apis.documentApi.getAndDecryptSecondaryDocumentAttachment(entity, 'secondary', validator)\n },\n getEncryptedAttachment(entity: models.Document): Promise<ArrayBuffer> {\n return apis.documentApi.getSecondaryAttachment(entity.id!, 'secondary')\n },\n },\n receipt: (apis: Apis, currentUser: User) =>\n <EntityWithAttachmentApi<models.Receipt>>{\n async createEntity(): Promise<models.Receipt> {\n return apis.receiptApi.createReceipt(await apis.receiptApi.newInstance(currentUser, {}))\n },\n async encryptAndSetAttachment(entity: models.Receipt, attachment: ArrayBuffer | Uint8Array): Promise<models.Receipt> {\n return apis.receiptApi.encryptAndSetReceiptAttachment(entity, 'tack', attachment)\n },\n getAndDecryptAttachment(entity: models.Receipt, validator: (decrypted: ArrayBuffer) => Promise<boolean>): Promise<ArrayBuffer> {\n return apis.receiptApi.getAndDecryptReceiptAttachment(entity, (entity.attachmentIds ?? {})['tack'], validator)\n },\n getEncryptedAttachment(entity: models.Receipt): Promise<ArrayBuffer> {\n return apis.receiptApi.getReceiptAttachment(entity.id!, (entity.attachmentIds ?? {})['tack'])\n },\n },\n}\n\nbefore(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n for (const [a, b] of Object.entries(env.dataOwnerDetails)) {\n console.log(a)\n console.log(b.password)\n console.log('')\n }\n apis = await initApi(env!, hcp1Username)\n user = await apis.userApi.getCurrentUser()\n})\n\ndescribe('Entity attachment update methods', async function () {\n Object.entries(entityWithAttachmentApis).forEach(([type, attachmentApiInitialiser]) => {\n it(`should automatically encrypt and decrypt attachments (${type})`, async () => {\n const attachmentApi = attachmentApiInitialiser(apis, user)\n const entity = await attachmentApi.createEntity()\n console.log(`entity id ${entity.id}`)\n const attachmentContent = 'This is some secret attachment'\n const entityWithEncrypted = await attachmentApi.encryptAndSetAttachment(entity, utf8_2ua(attachmentContent))\n const decryptedAttachment = await attachmentApi.getAndDecryptAttachment(entityWithEncrypted, async (d) => {\n try {\n return ua2utf8(d) === attachmentContent\n } catch {\n return false\n }\n })\n expect(ua2utf8(decryptedAttachment)).to.equal(attachmentContent)\n const encryptedAttachment = await attachmentApi.getEncryptedAttachment(entityWithEncrypted)\n let conversionFailed\n try {\n conversionFailed = ua2utf8(encryptedAttachment) !== attachmentContent\n } catch {\n conversionFailed = true\n }\n expect(conversionFailed).to.be.true\n const attachmentContent2 = 'This is an updated secret attachment'\n const entityWithEncrypted2 = await attachmentApi.encryptAndSetAttachment(entityWithEncrypted, utf8_2ua(attachmentContent2))\n const decryptedAttachment2 = await attachmentApi.getAndDecryptAttachment(entityWithEncrypted2, async (d) => {\n try {\n return ua2utf8(d) === attachmentContent2\n } catch {\n return false\n }\n })\n expect(ua2utf8(decryptedAttachment2)).to.equal(attachmentContent2)\n const encryptedAttachment2 = await attachmentApi.getEncryptedAttachment(entityWithEncrypted2)\n let conversionFailed2\n try {\n conversionFailed2 = ua2utf8(encryptedAttachment2) !== attachmentContent2\n } catch {\n conversionFailed2 = true\n }\n expect(conversionFailed2).to.be.true\n })\n })\n})\n"]}
@@ -45,7 +45,7 @@ describe('icc-x-user-api Tests', () => {
45
45
  }));
46
46
  it('Can get an user by its phoneNumber', () => __awaiter(void 0, void 0, void 0, function* () {
47
47
  const primitives = new icc_x_api_1.WebCryptoPrimitives(crypto_1.webcrypto);
48
- const phoneNumber = `+${primitives.randomUuid()}`;
48
+ const phoneNumber = `+32${Math.floor(Math.random() * 900000000) + 100000000}`;
49
49
  const api = yield initMasterApi(env);
50
50
  const createdUser = yield api.userApi.createUser(new User_1.User({
51
51
  id: (0, uuid_1.v4)(),
@@ -1 +1 @@
1
- {"version":3,"file":"icc-user-x-api-test.js","sourceRoot":"","sources":["../../../test/icc-x-api/icc-user-x-api-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,oDAAoI;AACpI,iCAA8B;AAC9B,mDAA0C;AAC1C,8CAA0C;AAC1C,mDAAmE;AACnE,+CAAsI;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,CAAC,CAAA;QAC5E,IAAA,aAAM,EAAC,uBAAuB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAA;QAC1C,IAAA,aAAM,EAAC,wBAAwB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAA;QAE5C,MAAM,KAAK,GAAG,IAAA,mBAAU,GAAE,CAAA;QAC1B,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,UAAU,iCAAM,iBAAiB,KAAE,YAAY,EAAE,KAAK,IAAG,CAAA;QAE7F,IAAA,aAAM,EAAC,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAA;QAC7D,IAAA,aAAM,EAAC,wBAAwB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAA;IAC7C,CAAC,CAAA,CACF,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import { createNewHcpApi, getEnvironmentInitializer, hcp1Username, itNoLite, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport { before } from 'mocha'\nimport { crypto } from '../../node-compat'\nimport { TestApi } from '../utils/TestApi'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\nimport { AuthenticationProvider, CryptoPrimitives, WebCryptoPrimitives, IccUserXApi, NoAuthenticationProvider } from '../../icc-x-api'\nimport { webcrypto } from 'crypto'\nimport { assert, expect } from 'chai'\nimport { User } from '../../icc-api/model/User'\nimport { v4 as uuid } from 'uuid'\nimport initMasterApi = TestUtils.initMasterApi\nimport { AuthSecretDetails, AuthSecretType, SmartAuthProvider } from '../../icc-x-api/auth/SmartAuthProvider'\nimport { randomUUID } from 'crypto'\nimport { IccAuthApi, IccUserApi } from '../../icc-api'\n\nsetLocalStorage(fetch)\nlet env: TestVars\nlet authApi: IccAuthApi\n\ndescribe('icc-x-user-api Tests', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n authApi = new IccAuthApi(env.iCureUrl, {}, new NoAuthenticationProvider(), fetch)\n })\n\n function userApiWithProvider(authProvider: AuthenticationProvider): IccUserApi {\n return new IccUserXApi(env.iCureUrl, {}, authProvider, new IccAuthApi(env.iCureUrl, {}, new NoAuthenticationProvider(), fetch))\n }\n\n it('Can instantiate an API and get the current user', async () => {\n // Given\n const api = await TestApi(env.iCureUrl, env.dataOwnerDetails[hcp1Username].user, env.dataOwnerDetails[hcp1Username].password, crypto)\n await api.userApi.getCurrentUser()\n })\n\n it('Can get an user by its phoneNumber', async () => {\n const primitives = new WebCryptoPrimitives(webcrypto as any)\n const phoneNumber = `+${primitives.randomUuid()}`\n\n const api = await initMasterApi(env)\n\n const createdUser = await api.userApi.createUser(\n new User({\n id: uuid(),\n name: `user-${primitives.randomUuid()}`,\n login: `user-${primitives.randomUuid()}`,\n email: `user-${primitives.randomUuid()}@icure.com`,\n mobilePhone: phoneNumber,\n })\n )\n\n const user = await api.userApi.getUserByPhoneNumber(phoneNumber)\n\n expect(user).to.be.deep.equal(createdUser)\n })\n\n itNoLite(\n 'Should automatically ask for a more powerful secret to perform elevated-security operations if the available secret/token is not good enough. When a new token is created during this process, the modifyUser does not fail with a 409',\n async () => {\n const { credentials, api } = await createNewHcpApi(env)\n const initialUser = await api.userApi.getCurrentUser()\n const masterApi = await initMasterApi(env)\n const userToken = randomUUID()\n const userWithLongToken = await masterApi.userApi.modifyUser({\n ...initialUser,\n authenticationTokens: {\n 'test-long-lived-token': {\n token: userToken,\n creationTime: Date.now(),\n validity: 60 * 60 * 24 * 7,\n },\n },\n })\n let longLivedTokenRequested = false\n let shortLivedTokenRequested = false\n const authProvider = await SmartAuthProvider.initialise(authApi, credentials.user, {\n getSecret: async (acceptedSecrets: AuthSecretType[], previousAttempts: AuthSecretDetails[]) => {\n if (acceptedSecrets.includes(AuthSecretType.LONG_LIVED_TOKEN)) {\n longLivedTokenRequested = true\n return { value: userToken, secretType: AuthSecretType.LONG_LIVED_TOKEN }\n } else if (acceptedSecrets.includes(AuthSecretType.SHORT_LIVED_TOKEN)) {\n shortLivedTokenRequested = true\n await masterApi.userApi.getToken(userWithLongToken.id!, 'tmp', 300, '123456')\n return { value: '123456', secretType: AuthSecretType.SHORT_LIVED_TOKEN }\n } else assert.fail('Should request LONG_LIVED_TOKEN or SHORT_LIVED_TOKEN')\n },\n })\n const userApi = userApiWithProvider(authProvider)\n expect((await userApi.getCurrentUser()).rev).to.equal(userWithLongToken.rev)\n expect(longLivedTokenRequested).to.be.true\n expect(shortLivedTokenRequested).to.be.false\n\n const newPw = randomUUID()\n const userWithNewPw = await userApi.modifyUser({ ...userWithLongToken, passwordHash: newPw })\n\n expect(userWithNewPw.rev).to.not.equal(userWithLongToken.rev)\n expect(shortLivedTokenRequested).to.be.true\n }\n )\n})\n"]}
1
+ {"version":3,"file":"icc-user-x-api-test.js","sourceRoot":"","sources":["../../../test/icc-x-api/icc-user-x-api-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,oDAAoI;AACpI,iCAA8B;AAC9B,mDAA0C;AAC1C,8CAA0C;AAC1C,mDAAmE;AACnE,+CAAsI;AACtI,mCAAkC;AAClC,+BAAqC;AACrC,mDAA+C;AAC/C,+BAAiC;AACjC,IAAO,aAAa,GAAG,sBAAS,CAAC,aAAa,CAAA;AAC9C,8EAA6G;AAC7G,mCAAmC;AACnC,2CAAsD;AAEtD,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AACtB,IAAI,GAAa,CAAA;AACjB,IAAI,OAAmB,CAAA;AAEvB,QAAQ,CAAC,sBAAsB,EAAE,GAAG,EAAE;IACpC,IAAA,cAAM,EAAC;;YACL,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;YACpB,MAAM,WAAW,GAAG,MAAM,IAAA,sCAAyB,GAAE,CAAA;YACrD,GAAG,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,IAAA,uBAAe,GAAE,CAAC,CAAA;YAClD,OAAO,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AAA,aAAM,EAAC,wBAAwB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAA;IAC7C,CAAC,CAAA,CACF,CAAA;AACH,CAAC,CAAC,CAAA","sourcesContent":["import { createNewHcpApi, getEnvironmentInitializer, hcp1Username, itNoLite, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport { before } from 'mocha'\nimport { crypto } from '../../node-compat'\nimport { TestApi } from '../utils/TestApi'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\nimport { AuthenticationProvider, CryptoPrimitives, WebCryptoPrimitives, IccUserXApi, NoAuthenticationProvider } from '../../icc-x-api'\nimport { webcrypto } from 'crypto'\nimport { assert, expect } from 'chai'\nimport { User } from '../../icc-api/model/User'\nimport { v4 as uuid } from 'uuid'\nimport initMasterApi = TestUtils.initMasterApi\nimport { AuthSecretDetails, AuthSecretType, SmartAuthProvider } from '../../icc-x-api/auth/SmartAuthProvider'\nimport { randomUUID } from 'crypto'\nimport { IccAuthApi, IccUserApi } from '../../icc-api'\n\nsetLocalStorage(fetch)\nlet env: TestVars\nlet authApi: IccAuthApi\n\ndescribe('icc-x-user-api Tests', () => {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n authApi = new IccAuthApi(env.iCureUrl, {}, new NoAuthenticationProvider(), fetch)\n })\n\n function userApiWithProvider(authProvider: AuthenticationProvider): IccUserApi {\n return new IccUserXApi(env.iCureUrl, {}, authProvider, new IccAuthApi(env.iCureUrl, {}, new NoAuthenticationProvider(), fetch))\n }\n\n it('Can instantiate an API and get the current user', async () => {\n // Given\n const api = await TestApi(env.iCureUrl, env.dataOwnerDetails[hcp1Username].user, env.dataOwnerDetails[hcp1Username].password, crypto)\n await api.userApi.getCurrentUser()\n })\n\n it('Can get an user by its phoneNumber', async () => {\n const primitives = new WebCryptoPrimitives(webcrypto as any)\n const phoneNumber = `+32${Math.floor(Math.random() * 900000000) + 100000000}`\n\n const api = await initMasterApi(env)\n\n const createdUser = await api.userApi.createUser(\n new User({\n id: uuid(),\n name: `user-${primitives.randomUuid()}`,\n login: `user-${primitives.randomUuid()}`,\n email: `user-${primitives.randomUuid()}@icure.com`,\n mobilePhone: phoneNumber,\n })\n )\n\n const user = await api.userApi.getUserByPhoneNumber(phoneNumber)\n\n expect(user).to.be.deep.equal(createdUser)\n })\n\n itNoLite(\n 'Should automatically ask for a more powerful secret to perform elevated-security operations if the available secret/token is not good enough. When a new token is created during this process, the modifyUser does not fail with a 409',\n async () => {\n const { credentials, api } = await createNewHcpApi(env)\n const initialUser = await api.userApi.getCurrentUser()\n const masterApi = await initMasterApi(env)\n const userToken = randomUUID()\n const userWithLongToken = await masterApi.userApi.modifyUser({\n ...initialUser,\n authenticationTokens: {\n 'test-long-lived-token': {\n token: userToken,\n creationTime: Date.now(),\n validity: 60 * 60 * 24 * 7,\n },\n },\n })\n let longLivedTokenRequested = false\n let shortLivedTokenRequested = false\n const authProvider = await SmartAuthProvider.initialise(authApi, credentials.user, {\n getSecret: async (acceptedSecrets: AuthSecretType[], previousAttempts: AuthSecretDetails[]) => {\n if (acceptedSecrets.includes(AuthSecretType.LONG_LIVED_TOKEN)) {\n longLivedTokenRequested = true\n return { value: userToken, secretType: AuthSecretType.LONG_LIVED_TOKEN }\n } else if (acceptedSecrets.includes(AuthSecretType.SHORT_LIVED_TOKEN)) {\n shortLivedTokenRequested = true\n await masterApi.userApi.getToken(userWithLongToken.id!, 'tmp', 300, '123456')\n return { value: '123456', secretType: AuthSecretType.SHORT_LIVED_TOKEN }\n } else assert.fail('Should request LONG_LIVED_TOKEN or SHORT_LIVED_TOKEN')\n },\n })\n const userApi = userApiWithProvider(authProvider)\n expect((await userApi.getCurrentUser()).rev).to.equal(userWithLongToken.rev)\n expect(longLivedTokenRequested).to.be.true\n expect(shortLivedTokenRequested).to.be.false\n\n const newPw = randomUUID()\n const userWithNewPw = await userApi.modifyUser({ ...userWithLongToken, passwordHash: newPw })\n\n expect(userWithNewPw.rev).to.not.equal(userWithLongToken.rev)\n expect(shortLivedTokenRequested).to.be.true\n }\n )\n})\n"]}
@@ -27,7 +27,7 @@ function createMessage(api, user, props) {
27
27
  toAddresses: [api.cryptoApi.primitives.randomUuid(), (_b = props.includeToAddress) !== null && _b !== void 0 ? _b : api.cryptoApi.primitives.randomUuid()],
28
28
  received: props.includeRandomReceived ? Math.floor(Math.random() * 1000000) : undefined,
29
29
  };
30
- return yield api.messageApi.createMessage(yield api.messageApi.newInstance(user, messageBase));
30
+ return yield api.messageApi.createMessageWithUser(undefined, yield api.messageApi.newInstance(user, messageBase));
31
31
  });
32
32
  }
33
33
  function createTestMessages(api, user, propsForAccessibleMessages, propsForInaccessibleMessages) {
@@ -94,25 +94,25 @@ describe('CSM-243', function () {
94
94
  it('A user should be able to retrieve paginated messages without received date by fromAddress', function () {
95
95
  return __awaiter(this, void 0, void 0, function* () {
96
96
  const targetAddress = (0, crypto_1.randomUUID)();
97
- yield doTestWithoutReceived({ includeFromAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) => messageApi.findMessagesByFromAddress(targetAddress, nextKey, nextKeyDocId, limit));
97
+ yield doTestWithoutReceived({ includeFromAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) => messageApi.findMessagesByFromAddressWithUser(undefined, targetAddress, nextKey, nextKeyDocId, limit));
98
98
  });
99
99
  });
100
100
  it('A user should be able to retrieve paginated messages with received date by fromAddress', function () {
101
101
  return __awaiter(this, void 0, void 0, function* () {
102
102
  const targetAddress = (0, crypto_1.randomUUID)();
103
- yield doTestWithReceived({ includeFromAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) => messageApi.findMessagesByFromAddress(targetAddress, nextKey, nextKeyDocId, limit));
103
+ yield doTestWithReceived({ includeFromAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) => messageApi.findMessagesByFromAddressWithUser(undefined, targetAddress, nextKey, nextKeyDocId, limit));
104
104
  });
105
105
  });
106
106
  it('A user should be able to retrieve paginated messages without received date by toAddress', function () {
107
107
  return __awaiter(this, void 0, void 0, function* () {
108
108
  const targetAddress = (0, crypto_1.randomUUID)();
109
- yield doTestWithoutReceived({ includeToAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) => messageApi.findMessagesByToAddress(targetAddress, nextKey, nextKeyDocId, limit));
109
+ yield doTestWithoutReceived({ includeToAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) => messageApi.findMessagesByToAddressWithUser(undefined, targetAddress, nextKey, nextKeyDocId, limit));
110
110
  });
111
111
  });
112
112
  it('A user should be able to retrieve paginated messages with received date by toAddress', function () {
113
113
  return __awaiter(this, void 0, void 0, function* () {
114
114
  const targetAddress = (0, crypto_1.randomUUID)();
115
- yield doTestWithReceived({ includeToAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) => messageApi.findMessagesByToAddress(targetAddress, nextKey, nextKeyDocId, limit));
115
+ yield doTestWithReceived({ includeToAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) => messageApi.findMessagesByToAddressWithUser(undefined, targetAddress, nextKey, nextKeyDocId, limit));
116
116
  });
117
117
  });
118
118
  });
@@ -1 +1 @@
1
- {"version":3,"file":"CSM-243.js","sourceRoot":"","sources":["../../../test/support/CSM-243.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,oDAAiG;AAEjG,mCAAmC;AACnC,+BAA6C;AAC7C,4BAAyB;AACzB,mDAAmE;AAEnE,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AACtB,mDAAkD;AAIlD,IAAA,UAAO,EAAC,cAAc,CAAC,CAAA;AAEvB,IAAI,GAAa,CAAA;AAEjB,SAAe,aAAa,CAC1B,GAAa,EACb,IAAU,EACV,KAIC;;;QAED,MAAM,WAAW,GAAY;YAC3B,OAAO,EAAE,kBAAkB,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,UAAU,EAAE,EAAE;YAClE,WAAW,EAAE,MAAA,KAAK,CAAC,kBAAkB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gBAC3F,MAAM,aAAa,GAAG,IAAA,mBAAU,GAAE,CAAA;gBAClC,MAAM,kBAAkB,CAAC,EAAE,kBAAkB,EAAE,aAAa,EAAE,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,CAC3G,UAAU,CAAC,yBAAyB,CAAC,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,CAClF,CAAA;YACH,CAAC;SAAA,CAAC,CAAA;QAEF,EAAE,CAAC,yFAAyF,EAAE;;gBAC5F,MAAM,aAAa,GAAG,IAAA,mBAAU,GAAE,CAAA;gBAClC,MAAM,qBAAqB,CAAC,EAAE,gBAAgB,EAAE,aAAa,EAAE,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,CAC5G,UAAU,CAAC,uBAAuB,CAAC,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,CAChF,CAAA;YACH,CAAC;SAAA,CAAC,CAAA;QAEF,EAAE,CAAC,sFAAsF,EAAE;;gBACzF,MAAM,aAAa,GAAG,IAAA,mBAAU,GAAE,CAAA;gBAClC,MAAM,kBAAkB,CAAC,EAAE,gBAAgB,EAAE,aAAa,EAAE,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,CACzG,UAAU,CAAC,uBAAuB,CAAC,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,CAChF,CAAA;YACH,CAAC;SAAA,CAAC,CAAA;IACJ,CAAC;CAAA,CAAC,CAAA","sourcesContent":["import { createNewHcpApi, getEnvironmentInitializer, setLocalStorage } from '../utils/test_utils'\nimport { IccMessageXApi, IcureApi } from '../../icc-x-api'\nimport { randomUUID } from 'crypto'\nimport { expect, use as chaiUse } from 'chai'\nimport 'isomorphic-fetch'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\n\nsetLocalStorage(fetch)\nimport * as chaiAsPromised from 'chai-as-promised'\nimport { User } from '../../icc-api/model/User'\nimport { Message } from '../../icc-api/model/Message'\nimport { PaginatedListMessage } from '../../icc-api/model/PaginatedListMessage'\nchaiUse(chaiAsPromised)\n\nlet env: TestVars\n\nasync function createMessage(\n api: IcureApi,\n user: User,\n props: {\n includeToAddress?: string\n includeFromAddress?: string\n includeRandomReceived: boolean\n }\n): Promise<Message> {\n const messageBase: Message = {\n subject: `Test message - ${api.cryptoApi.primitives.randomUuid()}`,\n fromAddress: props.includeFromAddress ?? api.cryptoApi.primitives.randomUuid(),\n toAddresses: [api.cryptoApi.primitives.randomUuid(), props.includeToAddress ?? api.cryptoApi.primitives.randomUuid()],\n received: props.includeRandomReceived ? Math.floor(Math.random() * 1000000) : undefined,\n }\n return await api.messageApi.createMessage(await api.messageApi.newInstance(user, messageBase))\n}\n\nasync function createTestMessages(\n api: IcureApi,\n user: User,\n propsForAccessibleMessages: {\n includeToAddress?: string\n includeFromAddress?: string\n includeRandomReceived: boolean\n },\n propsForInaccessibleMessages: {\n includeToAddress?: string\n includeFromAddress?: string\n includeRandomReceived: boolean\n }\n): Promise<Message[]> {\n const expectedMessages: Message[] = []\n for (let i = 0; i < 100; i++) {\n expectedMessages.push(await createMessage(api, user, propsForAccessibleMessages))\n await createMessage(api, user, propsForInaccessibleMessages)\n }\n // Also creates some messages from an unrelated hcp and same from address that should not be retrieved by the test.\n const { api: otherApi, user: otherUser } = await createNewHcpApi(env)\n for (let i = 0; i < 100; i++) {\n await createMessage(otherApi, otherUser, propsForAccessibleMessages)\n }\n return expectedMessages\n}\n\nasync function getAllPaginatedMessages(listFunction: (nextKey?: string, nextKeyDocId?: string) => Promise<PaginatedListMessage>): Promise<Message[]> {\n let latestRetrieved: PaginatedListMessage | undefined\n let allResults: Message[] = []\n do {\n const nextKey = latestRetrieved?.nextKeyPair?.startKey\n latestRetrieved = await listFunction(nextKey ? JSON.stringify(nextKey) : undefined, latestRetrieved?.nextKeyPair?.startKeyDocId)\n allResults.push(...latestRetrieved.rows!)\n } while (latestRetrieved?.nextKeyPair?.startKey !== undefined)\n console.log(JSON.stringify(allResults.map((m) => m.received)))\n return allResults\n}\n\ndescribe('CSM-243', async function () {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n async function doTestWithoutReceived(\n propsForAccessibleMessages: {\n includeToAddress?: string\n includeFromAddress?: string\n },\n listFunction: (\n messageApi: IccMessageXApi,\n nextKey: string | undefined,\n nextKeyDocId: string | undefined,\n limit: number\n ) => Promise<PaginatedListMessage>\n ) {\n const { api, user } = await createNewHcpApi(env)\n const expectedMessages: Message[] = await createTestMessages(\n api,\n user,\n { ...propsForAccessibleMessages, includeRandomReceived: false },\n { includeRandomReceived: false }\n )\n let allResults: Message[] = await getAllPaginatedMessages((nextKey?: string, nextKeyDocId?: string) =>\n listFunction(api.messageApi, nextKey, nextKeyDocId, 30)\n )\n expect(allResults.length).to.equal(expectedMessages.length)\n expect(allResults.map((m) => m.id)).to.have.members(expectedMessages.map((m) => m.id))\n }\n\n async function doTestWithReceived(\n propsForAccessibleMessages: {\n includeToAddress?: string\n includeFromAddress?: string\n },\n listFunction: (\n messageApi: IccMessageXApi,\n nextKey: string | undefined,\n nextKeyDocId: string | undefined,\n limit: number\n ) => Promise<PaginatedListMessage>\n ) {\n const { api, user } = await createNewHcpApi(env)\n const expectedMessagesWithReceived: Message[] = await createTestMessages(\n api,\n user,\n { ...propsForAccessibleMessages, includeRandomReceived: true },\n { includeRandomReceived: true }\n )\n const messageWithoutReceived = await createMessage(api, user, { ...propsForAccessibleMessages, includeRandomReceived: false })\n let allResults: Message[] = await getAllPaginatedMessages((nextKey?: string, nextKeyDocId?: string) =>\n listFunction(api.messageApi, nextKey, nextKeyDocId, 30)\n )\n expect(allResults.length).to.equal(expectedMessagesWithReceived.length + 1)\n expect(allResults.map((m) => m.id)).to.have.members([...expectedMessagesWithReceived.map((m) => m.id), messageWithoutReceived.id!])\n expect(allResults.map((m) => m.received)).to.deep.equal([\n undefined,\n ...expectedMessagesWithReceived.sort((a, b) => b.received! - a.received!).map((m) => m.received),\n ])\n }\n it('A user should be able to retrieve paginated messages without received date by fromAddress', async function () {\n const targetAddress = randomUUID()\n await doTestWithoutReceived({ includeFromAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) =>\n messageApi.findMessagesByFromAddress(targetAddress, nextKey, nextKeyDocId, limit)\n )\n })\n\n it('A user should be able to retrieve paginated messages with received date by fromAddress', async function () {\n const targetAddress = randomUUID()\n await doTestWithReceived({ includeFromAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) =>\n messageApi.findMessagesByFromAddress(targetAddress, nextKey, nextKeyDocId, limit)\n )\n })\n\n it('A user should be able to retrieve paginated messages without received date by toAddress', async function () {\n const targetAddress = randomUUID()\n await doTestWithoutReceived({ includeToAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) =>\n messageApi.findMessagesByToAddress(targetAddress, nextKey, nextKeyDocId, limit)\n )\n })\n\n it('A user should be able to retrieve paginated messages with received date by toAddress', async function () {\n const targetAddress = randomUUID()\n await doTestWithReceived({ includeToAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) =>\n messageApi.findMessagesByToAddress(targetAddress, nextKey, nextKeyDocId, limit)\n )\n })\n})\n"]}
1
+ {"version":3,"file":"CSM-243.js","sourceRoot":"","sources":["../../../test/support/CSM-243.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,oDAAiG;AAEjG,mCAAmC;AACnC,+BAA6C;AAC7C,4BAAyB;AACzB,mDAAmE;AAEnE,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AACtB,mDAAkD;AAIlD,IAAA,UAAO,EAAC,cAAc,CAAC,CAAA;AAEvB,IAAI,GAAa,CAAA;AAEjB,SAAe,aAAa,CAC1B,GAAa,EACb,IAAU,EACV,KAIC;;;QAED,MAAM,WAAW,GAAY;YAC3B,OAAO,EAAE,kBAAkB,GA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IcureApi } from '../../icc-x-api'\nimport { randomUUID } from 'crypto'\nimport { expect, use as chaiUse } from 'chai'\nimport 'isomorphic-fetch'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\n\nsetLocalStorage(fetch)\nimport * as chaiAsPromised from 'chai-as-promised'\nimport { User } from '../../icc-api/model/User'\nimport { Message } from '../../icc-api/model/Message'\nimport { PaginatedListMessage } from '../../icc-api/model/PaginatedListMessage'\nchaiUse(chaiAsPromised)\n\nlet env: TestVars\n\nasync function createMessage(\n api: IcureApi,\n user: User,\n props: {\n includeToAddress?: string\n includeFromAddress?: string\n includeRandomReceived: boolean\n }\n): Promise<Message> {\n const messageBase: Message = {\n subject: `Test message - ${api.cryptoApi.primitives.randomUuid()}`,\n fromAddress: props.includeFromAddress ?? api.cryptoApi.primitives.randomUuid(),\n toAddresses: [api.cryptoApi.primitives.randomUuid(), props.includeToAddress ?? api.cryptoApi.primitives.randomUuid()],\n received: props.includeRandomReceived ? Math.floor(Math.random() * 1000000) : undefined,\n }\n return await api.messageApi.createMessageWithUser(undefined, await api.messageApi.newInstance(user, messageBase))\n}\n\nasync function createTestMessages(\n api: IcureApi,\n user: User,\n propsForAccessibleMessages: {\n includeToAddress?: string\n includeFromAddress?: string\n includeRandomReceived: boolean\n },\n propsForInaccessibleMessages: {\n includeToAddress?: string\n includeFromAddress?: string\n includeRandomReceived: boolean\n }\n): Promise<Message[]> {\n const expectedMessages: Message[] = []\n for (let i = 0; i < 100; i++) {\n expectedMessages.push(await createMessage(api, user, propsForAccessibleMessages))\n await createMessage(api, user, propsForInaccessibleMessages)\n }\n // Also creates some messages from an unrelated hcp and same from address that should not be retrieved by the test.\n const { api: otherApi, user: otherUser } = await createNewHcpApi(env)\n for (let i = 0; i < 100; i++) {\n await createMessage(otherApi, otherUser, propsForAccessibleMessages)\n }\n return expectedMessages\n}\n\nasync function getAllPaginatedMessages(listFunction: (nextKey?: string, nextKeyDocId?: string) => Promise<PaginatedListMessage>): Promise<Message[]> {\n let latestRetrieved: PaginatedListMessage | undefined\n let allResults: Message[] = []\n do {\n const nextKey = latestRetrieved?.nextKeyPair?.startKey\n latestRetrieved = await listFunction(nextKey ? JSON.stringify(nextKey) : undefined, latestRetrieved?.nextKeyPair?.startKeyDocId)\n allResults.push(...latestRetrieved.rows!)\n } while (latestRetrieved?.nextKeyPair?.startKey !== undefined)\n console.log(JSON.stringify(allResults.map((m) => m.received)))\n return allResults\n}\n\ndescribe('CSM-243', async function () {\n before(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n })\n\n async function doTestWithoutReceived(\n propsForAccessibleMessages: {\n includeToAddress?: string\n includeFromAddress?: string\n },\n listFunction: (\n messageApi: IccMessageXApi,\n nextKey: string | undefined,\n nextKeyDocId: string | undefined,\n limit: number\n ) => Promise<PaginatedListMessage>\n ) {\n const { api, user } = await createNewHcpApi(env)\n const expectedMessages: Message[] = await createTestMessages(\n api,\n user,\n { ...propsForAccessibleMessages, includeRandomReceived: false },\n { includeRandomReceived: false }\n )\n let allResults: Message[] = await getAllPaginatedMessages((nextKey?: string, nextKeyDocId?: string) =>\n listFunction(api.messageApi, nextKey, nextKeyDocId, 30)\n )\n expect(allResults.length).to.equal(expectedMessages.length)\n expect(allResults.map((m) => m.id)).to.have.members(expectedMessages.map((m) => m.id))\n }\n\n async function doTestWithReceived(\n propsForAccessibleMessages: {\n includeToAddress?: string\n includeFromAddress?: string\n },\n listFunction: (\n messageApi: IccMessageXApi,\n nextKey: string | undefined,\n nextKeyDocId: string | undefined,\n limit: number\n ) => Promise<PaginatedListMessage>\n ) {\n const { api, user } = await createNewHcpApi(env)\n const expectedMessagesWithReceived: Message[] = await createTestMessages(\n api,\n user,\n { ...propsForAccessibleMessages, includeRandomReceived: true },\n { includeRandomReceived: true }\n )\n const messageWithoutReceived = await createMessage(api, user, { ...propsForAccessibleMessages, includeRandomReceived: false })\n let allResults: Message[] = await getAllPaginatedMessages((nextKey?: string, nextKeyDocId?: string) =>\n listFunction(api.messageApi, nextKey, nextKeyDocId, 30)\n )\n expect(allResults.length).to.equal(expectedMessagesWithReceived.length + 1)\n expect(allResults.map((m) => m.id)).to.have.members([...expectedMessagesWithReceived.map((m) => m.id), messageWithoutReceived.id!])\n expect(allResults.map((m) => m.received)).to.deep.equal([\n undefined,\n ...expectedMessagesWithReceived.sort((a, b) => b.received! - a.received!).map((m) => m.received),\n ])\n }\n it('A user should be able to retrieve paginated messages without received date by fromAddress', async function () {\n const targetAddress = randomUUID()\n await doTestWithoutReceived({ includeFromAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) =>\n messageApi.findMessagesByFromAddressWithUser(undefined, targetAddress, nextKey, nextKeyDocId, limit)\n )\n })\n\n it('A user should be able to retrieve paginated messages with received date by fromAddress', async function () {\n const targetAddress = randomUUID()\n await doTestWithReceived({ includeFromAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) =>\n messageApi.findMessagesByFromAddressWithUser(undefined, targetAddress, nextKey, nextKeyDocId, limit)\n )\n })\n\n it('A user should be able to retrieve paginated messages without received date by toAddress', async function () {\n const targetAddress = randomUUID()\n await doTestWithoutReceived({ includeToAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) =>\n messageApi.findMessagesByToAddressWithUser(undefined, targetAddress, nextKey, nextKeyDocId, limit)\n )\n })\n\n it('A user should be able to retrieve paginated messages with received date by toAddress', async function () {\n const targetAddress = randomUUID()\n await doTestWithReceived({ includeToAddress: targetAddress }, (messageApi, nextKey, nextKeyDocId, limit) =>\n messageApi.findMessagesByToAddressWithUser(undefined, targetAddress, nextKey, nextKeyDocId, limit)\n )\n })\n})\n"]}