@icure/api 8.6.7 → 8.6.9

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 (43) 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/index.d.ts +3 -2
  26. package/icc-x-api/index.js +4 -0
  27. package/icc-x-api/index.js.map +1 -1
  28. package/icc-x-api/utils/crypto-utils.d.ts +2 -1
  29. package/icc-x-api/utils/crypto-utils.js +57 -6
  30. package/icc-x-api/utils/crypto-utils.js.map +1 -1
  31. package/package.json +1 -1
  32. package/test/icc-x-api/crypto/anonymous-delegations-test.js +1 -1
  33. package/test/icc-x-api/crypto/anonymous-delegations-test.js.map +1 -1
  34. package/test/icc-x-api/crypto/cryptoTest.js +99 -1
  35. package/test/icc-x-api/crypto/cryptoTest.js.map +1 -1
  36. package/test/icc-x-api/crypto/legacy-metadata-migration-test.js +3 -3
  37. package/test/icc-x-api/crypto/legacy-metadata-migration-test.js.map +1 -1
  38. package/test/icc-x-api/entity-with-attachments-api-test.js +2 -2
  39. package/test/icc-x-api/entity-with-attachments-api-test.js.map +1 -1
  40. package/test/icc-x-api/icc-user-x-api-test.js +1 -1
  41. package/test/icc-x-api/icc-user-x-api-test.js.map +1 -1
  42. package/test/support/CSM-243.js +5 -5
  43. package/test/support/CSM-243.js.map +1 -1
@@ -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
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AU,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,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,UAAU,EAAE,EAAE;YAClE,WAAW,EAAE,MAAA,KAAK,CAAC,kBAAkB,mCAAI,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,UAAU,EAAE;YAC9E,WAAW,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,UAAU,EAAE,EAAE,MAAA,KAAK,CAAC,gBAAgB,mCAAI,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC;YACrH,QAAQ,EAAE,KAAK,CAAC,qBAAqB,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS;SACxF,CAAA;QACD,OAAO,MAAM,GAAG,CAAC,UAAU,CAAC,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAA;IACnH,CAAC;CAAA;AAED,SAAe,kBAAkB,CAC/B,GAAa,EACb,IAAU,EACV,0BAIC,EACD,4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OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,CACnG,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,+BAA+B,CAAC,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,CACnG,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.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"]}