@icure/api 8.3.5 → 8.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/icc-api/api/IccAuthApi.d.ts +10 -1
- package/icc-api/api/IccAuthApi.js +20 -3
- package/icc-api/api/IccAuthApi.js.map +1 -1
- package/icc-api/api/IccClassificationApi.d.ts +1 -0
- package/icc-api/api/IccClassificationApi.js +12 -0
- package/icc-api/api/IccClassificationApi.js.map +1 -1
- package/icc-api/api/IccMessageApi.d.ts +0 -6
- package/icc-api/api/IccMessageApi.js +0 -15
- package/icc-api/api/IccMessageApi.js.map +1 -1
- package/icc-x-api/auth/SmartAuthProvider.d.ts +37 -13
- package/icc-x-api/auth/SmartAuthProvider.js +105 -29
- package/icc-x-api/auth/SmartAuthProvider.js.map +1 -1
- package/icc-x-api/icc-bekmehr-x-api.js +2 -1
- package/icc-x-api/icc-bekmehr-x-api.js.map +1 -1
- package/icc-x-api/icc-document-x-api.d.ts +51 -6
- package/icc-x-api/icc-document-x-api.js +231 -69
- package/icc-x-api/icc-document-x-api.js.map +1 -1
- package/icc-x-api/icc-message-x-api.d.ts +45 -6
- package/icc-x-api/icc-message-x-api.js +202 -30
- package/icc-x-api/icc-message-x-api.js.map +1 -1
- package/icc-x-api/icc-patient-x-api.d.ts +9 -1
- package/icc-x-api/icc-patient-x-api.js +92 -100
- package/icc-x-api/icc-patient-x-api.js.map +1 -1
- package/icc-x-api/index.d.ts +14 -14
- package/icc-x-api/index.js +5 -4
- package/icc-x-api/index.js.map +1 -1
- package/package.json +1 -1
- package/test/icc-api/api/IccDocumentApi.js +27 -35
- package/test/icc-api/api/IccDocumentApi.js.map +1 -1
- package/test/icc-x-api/auth/group-switch-test.js +5 -5
- package/test/icc-x-api/auth/group-switch-test.js.map +1 -1
- package/test/icc-x-api/auth/jwt-provider-test.js +1 -1
- package/test/icc-x-api/auth/jwt-provider-test.js.map +1 -1
- package/test/icc-x-api/auth/smart-auth-provider-test.js +5 -5
- package/test/icc-x-api/auth/smart-auth-provider-test.js.map +1 -1
- package/test/icc-x-api/icc-document-x-api.js +28 -4
- package/test/icc-x-api/icc-document-x-api.js.map +1 -1
- package/test/icc-x-api/icc-message-x-api.js +19 -293
- package/test/icc-x-api/icc-message-x-api.js.map +1 -1
- package/test/icc-x-api/icc-user-x-api-test.js +1 -1
- package/test/icc-x-api/icc-user-x-api-test.js.map +1 -1
- package/test/utils/test_utils.d.ts +4 -2
- package/test/utils/test_utils.js +4 -3
- package/test/utils/test_utils.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smart-auth-provider-test.js","sourceRoot":"","sources":["../../../../test/icc-x-api/auth/smart-auth-provider-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mDAAmE;AACnE,iCAA8B;AAC9B,uDAAqJ;AACrJ,kDAAkH;AAClH,8CAAyD;AACzD,4BAAyB;AACzB,iFAAgH;AAChH,+BAA6B;AAC7B,mCAAmC;AACnC,IAAO,aAAa,GAAG,sBAAS,CAAC,aAAa,CAAA;AAC9C,mCAA6B;AAC7B,qCAA8B;AAC9B,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AAEtB,IAAI,GAAa,CAAA;AACjB,IAAI,OAAmB,CAAA;AAEvB,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;IAC7C,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,GAAG,IAAI,oBAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,IAAI,oCAAwB,EAAE,EAAE,KAAK,CAAC,CAAA;QACnF,CAAC;KAAA,CAAC,CAAA;IAEF,SAAS,mBAAmB,CAAC,YAAoC;QAC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O,GAAG,MAAM,mBAAmB,CAAC,gBAAgB,EAAE,CAAA;QAC5D,MAAM,eAAe,GAAG,mBAAmB,CAAC,MAAM,YAAY,CAAC,WAAW,CAAC,YAAa,EAAE,OAAO,CAAC,CAAC,CAAA;QACnG,MAAM,YAAY,GAAG,MAAM,eAAe,CAAC,cAAc,EAAE,CAAA;QAC3D,IAAA,aAAM,EAAC,YAAY,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAA;QACzD,IAAA,aAAM,EAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,CAAA;QACnD,MAAM,cAAc,GAAG,MAAM,eAAe,CAAC,UAAU,iCAClD,YAAY,KACf,oBAAoB,EAAE;gBACpB,WAAW,EAAE;oBACX,KAAK,EAAE,IAAA,mBAAU,GAAE;oBACnB,YAAY,EAAE,IAAI,CAAC,GAAG,EAAE;oBACxB,QAAQ,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;iBAC3B;aACF,IACD,CAAA;QACF,IAAA,aAAM,EAAC,cAAc,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;QACzD,IAAA,aAAM,EAAC,MAAM,CAAC,IAAI,CAAC,MAAA,cAAc,CAAC,oBAAoB,mCAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAA;IAChF,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { getEnvVariables, TestVars } from '@icure/test-setup/types'\nimport { before } from 'mocha'\nimport { createNewHcpApi, createUserInMultipleGroups, getEnvironmentInitializer, itNoLite, setLocalStorage, TestUtils } from '../../utils/test_utils'\nimport { AuthenticationProvider, BasicAuthenticationProvider, NoAuthenticationProvider } from '../../../icc-x-api'\nimport { IccAuthApi, IccUserApi } from '../../../icc-api'\nimport 'isomorphic-fetch'\nimport { AuthSecretDetails, AuthSecretType, SmartAuthProvider } from '../../../icc-x-api/auth/SmartAuthProvider'\nimport { expect } from 'chai'\nimport { randomUUID } from 'crypto'\nimport initMasterApi = TestUtils.initMasterApi\nimport { fail } from 'assert'\nimport { TOTP } from 'otpauth'\nsetLocalStorage(fetch)\n\nlet env: TestVars\nlet authApi: IccAuthApi\n\ndescribe('Smart authentication provider', () => {\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 IccUserApi(env.iCureUrl, {}, authProvider, fetch)\n }\n\n it('Should automatically ask for secret to get a new token, and reasks the secret if it is not valid', async () => {\n const { credentials } = await createNewHcpApi(env)\n let calls = 0\n const authProvider = SmartAuthProvider.initialise(authApi, credentials.user, {\n getSecret: async (acceptedSecrets: AuthSecretType[], previousAttempts: AuthSecretDetails[]) => {\n expect(acceptedSecrets).to.include(AuthSecretType.PASSWORD)\n expect(acceptedSecrets).to.include(AuthSecretType.LONG_LIVED_TOKEN)\n expect(acceptedSecrets).to.include(AuthSecretType.SHORT_LIVED_TOKEN)\n expect(acceptedSecrets).to.not.include(AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN)\n if (calls == 0) {\n expect(previousAttempts).to.be.empty\n } else if (calls == 1) {\n expect(previousAttempts).to.have.length(1)\n expect(previousAttempts[0].value).to.equal('wrong')\n expect(previousAttempts[0].secretType).to.equal(AuthSecretType.LONG_LIVED_TOKEN)\n } else fail(`Unexpected number of calls: ${calls}`)\n return calls++ == 0\n ? { value: 'wrong', secretType: AuthSecretType.LONG_LIVED_TOKEN } // pragma: allowlist secret\n : { value: credentials.password, secretType: AuthSecretType.LONG_LIVED_TOKEN }\n },\n })\n const userApi = userApiWithProvider(authProvider)\n const user = await userApi.getCurrentUser()\n expect(user.healthcarePartyId).to.equal(credentials.dataOwnerId)\n expect(calls).to.equal(2)\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',\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 userPw = randomUUID()\n const userWithLongTokenAndPw = await masterApi.userApi.modifyUser({\n ...initialUser,\n passwordHash: userPw,\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 calls = 0\n const authProvider = SmartAuthProvider.initialise(authApi, credentials.user, {\n getSecret: async (acceptedSecrets: AuthSecretType[], previousAttempts: AuthSecretDetails[]) => {\n if (calls == 0) {\n expect(acceptedSecrets).to.include(AuthSecretType.PASSWORD)\n expect(acceptedSecrets).to.include(AuthSecretType.LONG_LIVED_TOKEN)\n expect(acceptedSecrets).to.include(AuthSecretType.SHORT_LIVED_TOKEN)\n expect(acceptedSecrets).to.not.include(AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN)\n expect(previousAttempts).to.be.empty\n calls++\n return { value: userToken, secretType: AuthSecretType.LONG_LIVED_TOKEN }\n } else if (calls == 1) {\n expect(acceptedSecrets).to.include(AuthSecretType.PASSWORD)\n expect(acceptedSecrets).to.not.include(AuthSecretType.LONG_LIVED_TOKEN)\n expect(acceptedSecrets).to.include(AuthSecretType.SHORT_LIVED_TOKEN)\n expect(acceptedSecrets).to.not.include(AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN)\n expect(previousAttempts).to.be.empty\n calls++\n return { value: userPw, secretType: AuthSecretType.PASSWORD }\n } else throw new Error(`Unexpected number of calls: ${calls}`)\n },\n })\n const userApi = userApiWithProvider(authProvider)\n expect((await userApi.getCurrentUser()).rev).to.equal(userWithLongTokenAndPw.rev)\n expect(calls).to.equal(1)\n const newPw = randomUUID()\n const userWithNewPw = await userApi.modifyUser({ ...userWithLongTokenAndPw, passwordHash: newPw })\n expect(userWithNewPw.rev).to.not.equal(userWithLongTokenAndPw.rev)\n expect(calls).to.equal(2)\n const retrievedWithNewPw = await userApiWithProvider(new BasicAuthenticationProvider(credentials.user, newPw)).getCurrentUser()\n expect(retrievedWithNewPw.rev).to.equal(userWithNewPw.rev)\n const couldRetrieveWithOldPw = await userApiWithProvider(new BasicAuthenticationProvider(credentials.user, userPw))\n .getCurrentUser()\n .then(\n () => true,\n () => false\n )\n expect(couldRetrieveWithOldPw).to.be.false\n }\n )\n\n itNoLite('Should automatically ask for TOTP after password if user has 2fa enabled', async () => {\n const { credentials, api } = await createNewHcpApi(env)\n const initialUser = await api.userApi.getCurrentUser()\n const masterApi = await initMasterApi(env)\n const totpSecret = 'AAPX7PW2RJIGZ3D4' // pragma: allowlist secret (fake secret generated only for test)\n const totp = new TOTP({\n algorithm: 'SHA1',\n digits: 6,\n period: 30,\n secret: totpSecret,\n })\n const userPw = randomUUID()\n await masterApi.userApi.enable2fa(initialUser.id!, totpSecret)\n const userWithPwAnd2fa = await masterApi.userApi.modifyUser({\n ...initialUser,\n passwordHash: userPw,\n })\n let calls = 0\n const authProvider = SmartAuthProvider.initialise(authApi, credentials.user, {\n getSecret: async (acceptedSecrets: AuthSecretType[], previousAttempts: AuthSecretDetails[]) => {\n if (calls == 0) {\n expect(acceptedSecrets).to.include(AuthSecretType.PASSWORD)\n expect(acceptedSecrets).to.include(AuthSecretType.LONG_LIVED_TOKEN)\n expect(acceptedSecrets).to.include(AuthSecretType.SHORT_LIVED_TOKEN)\n expect(acceptedSecrets).to.not.include(AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN)\n expect(previousAttempts).to.be.empty\n calls++\n return { value: userPw, secretType: AuthSecretType.PASSWORD }\n } else if (calls == 1 || calls == 2) {\n expect(acceptedSecrets).to.have.members([AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN])\n if (calls == 1) expect(previousAttempts).to.be.empty\n if (calls == 2) expect(previousAttempts).to.have.length(1)\n return calls++ == 1\n ? { value: totp.generate() + '13', secretType: AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN }\n : { value: totp.generate(), secretType: AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN }\n } else throw new Error(`Unexpected number of calls: ${calls}`)\n },\n })\n const userApi = userApiWithProvider(authProvider)\n expect((await userApi.getCurrentUser()).rev).to.equal(userWithPwAnd2fa.rev)\n expect(calls).to.equal(3)\n })\n\n itNoLite('Should ask for TOTP directly if password is cached', async () => {\n const { credentials, api } = await createNewHcpApi(env)\n const initialUser = await api.userApi.getCurrentUser()\n const masterApi = await initMasterApi(env)\n const totpSecret = 'AAPX7PW2RJIGZ3D4' // pragma: allowlist secret (fake secret generated only for test)\n const totp = new TOTP({\n algorithm: 'SHA1',\n digits: 6,\n period: 30,\n secret: totpSecret,\n })\n const userPw = randomUUID()\n await masterApi.userApi.enable2fa(initialUser.id!, totpSecret)\n const userWithPwAnd2fa = await masterApi.userApi.modifyUser({\n ...initialUser,\n passwordHash: userPw,\n })\n let calls = 0\n const authProvider = SmartAuthProvider.initialise(\n authApi,\n credentials.user,\n {\n getSecret: async (acceptedSecrets: AuthSecretType[], previousAttempts: AuthSecretDetails[]) => {\n expect(acceptedSecrets).to.have.members([AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN])\n expect(previousAttempts).to.be.empty\n expect(calls++).to.equal(0)\n return { value: totp.generate(), secretType: AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN }\n },\n },\n {\n initialSecret: { password: userPw },\n }\n )\n const userApi = userApiWithProvider(authProvider)\n expect((await userApi.getCurrentUser()).rev).to.equal(userWithPwAnd2fa.rev)\n expect(calls).to.equal(1)\n })\n\n itNoLite('Switched provider should keep cached secrets and should be able to have elevated security context', async () => {\n const details = await createUserInMultipleGroups(env)\n let calls = 0\n const authProvider = SmartAuthProvider.initialise(authApi, details.userLogin, {\n getSecret: async (acceptedSecrets: AuthSecretType[], previousAttempts: AuthSecretDetails[]) => {\n expect(acceptedSecrets).to.have.include(AuthSecretType.PASSWORD)\n expect(previousAttempts).to.be.empty\n expect(calls++).to.equal(0)\n return { value: details.userPw12, secretType: AuthSecretType.PASSWORD }\n },\n })\n const defaultGroupUserApi = userApiWithProvider(authProvider)\n const defaultGroupUser = await defaultGroupUserApi.getCurrentUser()\n const otherGroupId = details.group1.id == defaultGroupUser.groupId ? details.group2.id : details.group1.id\n const matches = await defaultGroupUserApi.getMatchingUsers()\n const switchedUserApi = userApiWithProvider(await authProvider.switchGroup(otherGroupId!, matches))\n const switchedUser = await switchedUserApi.getCurrentUser()\n expect(switchedUser.id).to.not.equal(defaultGroupUser.id)\n expect(switchedUser.groupId).to.equal(otherGroupId)\n const updatedDefault = await switchedUserApi.modifyUser({\n ...switchedUser,\n authenticationTokens: {\n 'new-token': {\n token: randomUUID(),\n creationTime: Date.now(),\n validity: 60 * 60 * 24 * 7,\n },\n },\n })\n expect(updatedDefault.rev).to.not.equal(switchedUser.rev)\n expect(Object.keys(updatedDefault.authenticationTokens ?? {})).to.not.be.empty\n })\n})\n"]}
|
|
1
|
+
{"version":3,"file":"smart-auth-provider-test.js","sourceRoot":"","sources":["../../../../test/icc-x-api/auth/smart-auth-provider-test.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,mDAAmE;AACnE,iCAA8B;AAC9B,uDAAqJ;AACrJ,kDAAkH;AAClH,8CAAyD;AACzD,4BAAyB;AACzB,iFAAgH;AAChH,+BAA6B;AAC7B,mCAAmC;AACnC,IAAO,aAAa,GAAG,sBAAS,CAAC,aAAa,CAAA;AAC9C,mCAA6B;AAC7B,qCAA8B;AAC9B,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AAEtB,IAAI,GAAa,CAAA;AACjB,IAAI,OAAmB,CAAA;AAEvB,QAAQ,CAAC,+BAA+B,EAAE,GAAG,EAAE;I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C,CAAA;QACzD,IAAA,aAAM,EAAC,MAAM,CAAC,IAAI,CAAC,MAAA,cAAc,CAAC,oBAAoB,mCAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAA;IAChF,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { getEnvVariables, TestVars } from '@icure/test-setup/types'\nimport { before } from 'mocha'\nimport { createNewHcpApi, createUserInMultipleGroups, getEnvironmentInitializer, itNoLite, setLocalStorage, TestUtils } from '../../utils/test_utils'\nimport { AuthenticationProvider, BasicAuthenticationProvider, NoAuthenticationProvider } from '../../../icc-x-api'\nimport { IccAuthApi, IccUserApi } from '../../../icc-api'\nimport 'isomorphic-fetch'\nimport { AuthSecretDetails, AuthSecretType, SmartAuthProvider } from '../../../icc-x-api/auth/SmartAuthProvider'\nimport { expect } from 'chai'\nimport { randomUUID } from 'crypto'\nimport initMasterApi = TestUtils.initMasterApi\nimport { fail } from 'assert'\nimport { TOTP } from 'otpauth'\nsetLocalStorage(fetch)\n\nlet env: TestVars\nlet authApi: IccAuthApi\n\ndescribe('Smart authentication provider', () => {\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 IccUserApi(env.iCureUrl, {}, authProvider, fetch)\n }\n\n it('Should automatically ask for secret to get a new token, and reasks the secret if it is not valid', async () => {\n const { credentials } = await createNewHcpApi(env)\n let calls = 0\n const authProvider = await SmartAuthProvider.initialise(authApi, credentials.user, {\n getSecret: async (acceptedSecrets: AuthSecretType[], previousAttempts: AuthSecretDetails[]) => {\n expect(acceptedSecrets).to.include(AuthSecretType.PASSWORD)\n expect(acceptedSecrets).to.include(AuthSecretType.LONG_LIVED_TOKEN)\n expect(acceptedSecrets).to.include(AuthSecretType.SHORT_LIVED_TOKEN)\n expect(acceptedSecrets).to.not.include(AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN)\n if (calls == 0) {\n expect(previousAttempts).to.be.empty\n } else if (calls == 1) {\n expect(previousAttempts).to.have.length(1)\n expect(previousAttempts[0].value).to.equal('wrong')\n expect(previousAttempts[0].secretType).to.equal(AuthSecretType.LONG_LIVED_TOKEN)\n } else fail(`Unexpected number of calls: ${calls}`)\n return calls++ == 0\n ? { value: 'wrong', secretType: AuthSecretType.LONG_LIVED_TOKEN } // pragma: allowlist secret\n : { value: credentials.password, secretType: AuthSecretType.LONG_LIVED_TOKEN }\n },\n })\n const userApi = userApiWithProvider(authProvider)\n const user = await userApi.getCurrentUser()\n expect(user.healthcarePartyId).to.equal(credentials.dataOwnerId)\n expect(calls).to.equal(2)\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',\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 userPw = randomUUID()\n const userWithLongTokenAndPw = await masterApi.userApi.modifyUser({\n ...initialUser,\n passwordHash: userPw,\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 calls = 0\n const authProvider = await SmartAuthProvider.initialise(authApi, credentials.user, {\n getSecret: async (acceptedSecrets: AuthSecretType[], previousAttempts: AuthSecretDetails[]) => {\n if (calls == 0) {\n expect(acceptedSecrets).to.include(AuthSecretType.PASSWORD)\n expect(acceptedSecrets).to.include(AuthSecretType.LONG_LIVED_TOKEN)\n expect(acceptedSecrets).to.include(AuthSecretType.SHORT_LIVED_TOKEN)\n expect(acceptedSecrets).to.not.include(AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN)\n expect(previousAttempts).to.be.empty\n calls++\n return { value: userToken, secretType: AuthSecretType.LONG_LIVED_TOKEN }\n } else if (calls == 1) {\n expect(acceptedSecrets).to.include(AuthSecretType.PASSWORD)\n expect(acceptedSecrets).to.not.include(AuthSecretType.LONG_LIVED_TOKEN)\n expect(acceptedSecrets).to.include(AuthSecretType.SHORT_LIVED_TOKEN)\n expect(acceptedSecrets).to.not.include(AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN)\n expect(previousAttempts).to.be.empty\n calls++\n return { value: userPw, secretType: AuthSecretType.PASSWORD }\n } else throw new Error(`Unexpected number of calls: ${calls}`)\n },\n })\n const userApi = userApiWithProvider(authProvider)\n expect((await userApi.getCurrentUser()).rev).to.equal(userWithLongTokenAndPw.rev)\n expect(calls).to.equal(1)\n const newPw = randomUUID()\n const userWithNewPw = await userApi.modifyUser({ ...userWithLongTokenAndPw, passwordHash: newPw })\n expect(userWithNewPw.rev).to.not.equal(userWithLongTokenAndPw.rev)\n expect(calls).to.equal(2)\n const retrievedWithNewPw = await userApiWithProvider(new BasicAuthenticationProvider(credentials.user, newPw)).getCurrentUser()\n expect(retrievedWithNewPw.rev).to.equal(userWithNewPw.rev)\n const couldRetrieveWithOldPw = await userApiWithProvider(new BasicAuthenticationProvider(credentials.user, userPw))\n .getCurrentUser()\n .then(\n () => true,\n () => false\n )\n expect(couldRetrieveWithOldPw).to.be.false\n }\n )\n\n itNoLite('Should automatically ask for TOTP after password if user has 2fa enabled', async () => {\n const { credentials, api } = await createNewHcpApi(env)\n const initialUser = await api.userApi.getCurrentUser()\n const masterApi = await initMasterApi(env)\n const totpSecret = 'AAPX7PW2RJIGZ3D4' // pragma: allowlist secret (fake secret generated only for test)\n const totp = new TOTP({\n algorithm: 'SHA1',\n digits: 6,\n period: 30,\n secret: totpSecret,\n })\n const userPw = randomUUID()\n await masterApi.userApi.enable2fa(initialUser.id!, totpSecret)\n const userWithPwAnd2fa = await masterApi.userApi.modifyUser({\n ...initialUser,\n passwordHash: userPw,\n })\n let calls = 0\n const authProvider = await SmartAuthProvider.initialise(authApi, credentials.user, {\n getSecret: async (acceptedSecrets: AuthSecretType[], previousAttempts: AuthSecretDetails[]) => {\n if (calls == 0) {\n expect(acceptedSecrets).to.include(AuthSecretType.PASSWORD)\n expect(acceptedSecrets).to.include(AuthSecretType.LONG_LIVED_TOKEN)\n expect(acceptedSecrets).to.include(AuthSecretType.SHORT_LIVED_TOKEN)\n expect(acceptedSecrets).to.not.include(AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN)\n expect(previousAttempts).to.be.empty\n calls++\n return { value: userPw, secretType: AuthSecretType.PASSWORD }\n } else if (calls == 1 || calls == 2) {\n expect(acceptedSecrets).to.have.members([AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN])\n if (calls == 1) expect(previousAttempts).to.be.empty\n if (calls == 2) expect(previousAttempts).to.have.length(1)\n return calls++ == 1\n ? { value: totp.generate() + '13', secretType: AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN }\n : { value: totp.generate(), secretType: AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN }\n } else throw new Error(`Unexpected number of calls: ${calls}`)\n },\n })\n const userApi = userApiWithProvider(authProvider)\n expect((await userApi.getCurrentUser()).rev).to.equal(userWithPwAnd2fa.rev)\n expect(calls).to.equal(3)\n })\n\n itNoLite('Should ask for TOTP directly if password is cached', async () => {\n const { credentials, api } = await createNewHcpApi(env)\n const initialUser = await api.userApi.getCurrentUser()\n const masterApi = await initMasterApi(env)\n const totpSecret = 'AAPX7PW2RJIGZ3D4' // pragma: allowlist secret (fake secret generated only for test)\n const totp = new TOTP({\n algorithm: 'SHA1',\n digits: 6,\n period: 30,\n secret: totpSecret,\n })\n const userPw = randomUUID()\n await masterApi.userApi.enable2fa(initialUser.id!, totpSecret)\n const userWithPwAnd2fa = await masterApi.userApi.modifyUser({\n ...initialUser,\n passwordHash: userPw,\n })\n let calls = 0\n const authProvider = await SmartAuthProvider.initialise(\n authApi,\n credentials.user,\n {\n getSecret: async (acceptedSecrets: AuthSecretType[], previousAttempts: AuthSecretDetails[]) => {\n expect(acceptedSecrets).to.have.members([AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN])\n expect(previousAttempts).to.be.empty\n expect(calls++).to.equal(0)\n return { value: totp.generate(), secretType: AuthSecretType.TWO_FACTOR_AUTHENTICATION_TOKEN }\n },\n },\n {\n initialSecret: { password: userPw },\n }\n )\n const userApi = userApiWithProvider(authProvider)\n expect((await userApi.getCurrentUser()).rev).to.equal(userWithPwAnd2fa.rev)\n expect(calls).to.equal(1)\n })\n\n itNoLite('Switched provider should keep cached secrets and should be able to have elevated security context', async () => {\n const details = await createUserInMultipleGroups(env)\n let calls = 0\n const authProvider = await SmartAuthProvider.initialise(authApi, details.userLogin, {\n getSecret: async (acceptedSecrets: AuthSecretType[], previousAttempts: AuthSecretDetails[]) => {\n expect(acceptedSecrets).to.have.include(AuthSecretType.PASSWORD)\n expect(previousAttempts).to.be.empty\n expect(calls++).to.equal(0)\n return { value: details.userPw12, secretType: AuthSecretType.PASSWORD }\n },\n })\n const defaultGroupUserApi = userApiWithProvider(authProvider)\n const defaultGroupUser = await defaultGroupUserApi.getCurrentUser()\n const otherGroupId = details.group1.id == defaultGroupUser.groupId ? details.group2.id : details.group1.id\n const matches = await defaultGroupUserApi.getMatchingUsers()\n const switchedUserApi = userApiWithProvider(await authProvider.switchGroup(otherGroupId!, matches))\n const switchedUser = await switchedUserApi.getCurrentUser()\n expect(switchedUser.id).to.not.equal(defaultGroupUser.id)\n expect(switchedUser.groupId).to.equal(otherGroupId)\n const updatedDefault = await switchedUserApi.modifyUser({\n ...switchedUser,\n authenticationTokens: {\n 'new-token': {\n token: randomUUID(),\n creationTime: Date.now(),\n validity: 60 * 60 * 24 * 7,\n },\n },\n })\n expect(updatedDefault.rev).to.not.equal(switchedUser.rev)\n expect(Object.keys(updatedDefault.authenticationTokens ?? {})).to.not.be.empty\n })\n})\n"]}
|
|
@@ -13,9 +13,11 @@ const mocha_1 = require("mocha");
|
|
|
13
13
|
require("isomorphic-fetch");
|
|
14
14
|
const icc_x_api_1 = require("../../icc-x-api");
|
|
15
15
|
const chai_1 = require("chai");
|
|
16
|
+
const crypto_1 = require("crypto");
|
|
16
17
|
const test_utils_1 = require("../utils/test_utils");
|
|
17
18
|
const types_1 = require("@icure/test-setup/types");
|
|
18
19
|
var initApi = test_utils_1.TestUtils.initApi;
|
|
20
|
+
const icc_api_1 = require("../../icc-api");
|
|
19
21
|
(0, test_utils_1.setLocalStorage)(fetch);
|
|
20
22
|
let env;
|
|
21
23
|
(0, mocha_1.before)(function () {
|
|
@@ -26,21 +28,21 @@ let env;
|
|
|
26
28
|
});
|
|
27
29
|
});
|
|
28
30
|
describe('icc-x-document-api Tests', () => {
|
|
29
|
-
it('Get and decrypt as json should work', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
(0, mocha_1.it)('Get and decrypt as json should work', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
32
|
// Given
|
|
31
33
|
const { documentApi, userApi } = yield initApi(env, test_utils_1.hcp1Username);
|
|
32
34
|
const currUser = yield userApi.getCurrentUser();
|
|
33
|
-
const document = yield documentApi.
|
|
35
|
+
const document = yield documentApi.createDocumentWithUser(undefined, yield documentApi.newInstance(currUser, undefined, {}));
|
|
34
36
|
const obj = { test: 'test' };
|
|
35
37
|
yield documentApi.encryptAndSetDocumentAttachment(document, (0, icc_x_api_1.utf8_2ua)(JSON.stringify(obj)));
|
|
36
38
|
const decrypted = yield documentApi.getAndTryDecryptMainAttachmentAs(document, 'application/json');
|
|
37
39
|
(0, chai_1.expect)(decrypted).to.deep.equal(obj);
|
|
38
40
|
}));
|
|
39
|
-
it('Get and decrypt as string should work', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
(0, mocha_1.it)('Get and decrypt as string should work', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
42
|
// Given
|
|
41
43
|
const { documentApi, userApi } = yield initApi(env, test_utils_1.hcp1Username);
|
|
42
44
|
const currUser = yield userApi.getCurrentUser();
|
|
43
|
-
const document = yield documentApi.
|
|
45
|
+
const document = yield documentApi.createDocumentWithUser(undefined, yield documentApi.newInstance(currUser, undefined, {}));
|
|
44
46
|
const obj = 'Test';
|
|
45
47
|
yield documentApi.encryptAndSetDocumentAttachment(document, (0, icc_x_api_1.utf8_2ua)(obj));
|
|
46
48
|
const decrypted = yield documentApi.getAndTryDecryptMainAttachmentAs(document, 'text/plain');
|
|
@@ -48,5 +50,27 @@ describe('icc-x-document-api Tests', () => {
|
|
|
48
50
|
const decryptedAsJson = yield documentApi.getAndTryDecryptMainAttachmentAs(document, 'application/json');
|
|
49
51
|
(0, chai_1.expect)(decryptedAsJson).to.be.undefined;
|
|
50
52
|
}));
|
|
53
|
+
(0, mocha_1.it)('Should be encrypted', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
const hcp = yield (0, test_utils_1.createNewHcpApi)(env, {
|
|
55
|
+
encryptedFieldsConfig: {
|
|
56
|
+
document: ['name'],
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
const name = 'Private.txt';
|
|
60
|
+
const externalUuid = (0, crypto_1.randomUUID)();
|
|
61
|
+
const created = yield hcp.api.documentApi.createDocumentWithUser(undefined, yield hcp.api.documentApi.newInstance(hcp.user, undefined, {
|
|
62
|
+
id: (0, crypto_1.randomUUID)(),
|
|
63
|
+
name,
|
|
64
|
+
externalUuid,
|
|
65
|
+
}));
|
|
66
|
+
(0, chai_1.expect)(created.name).to.eq(name);
|
|
67
|
+
(0, chai_1.expect)(created.externalUuid).to.eq(externalUuid);
|
|
68
|
+
const retrieved = yield hcp.api.documentApi.getDocumentWithUser(undefined, created.id);
|
|
69
|
+
(0, chai_1.expect)(retrieved.name).to.eq(name);
|
|
70
|
+
(0, chai_1.expect)(retrieved.externalUuid).to.eq(externalUuid);
|
|
71
|
+
const encrypted = yield new icc_api_1.IccDocumentApi(env.iCureUrl, {}, hcp.api.authApi.authenticationProvider, fetch).getDocument(created.id);
|
|
72
|
+
(0, chai_1.expect)(encrypted.name).to.be.undefined;
|
|
73
|
+
(0, chai_1.expect)(encrypted.externalUuid).to.eq(externalUuid);
|
|
74
|
+
}));
|
|
51
75
|
});
|
|
52
76
|
//# sourceMappingURL=icc-document-x-api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icc-document-x-api.js","sourceRoot":"","sources":["../../../test/icc-x-api/icc-document-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"icc-document-x-api.js","sourceRoot":"","sources":["../../../test/icc-x-api/icc-document-x-api.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,iCAAkC;AAElC,4BAAyB;AAEzB,+CAAyH;AAEzH,+BAAqC;AACrC,mCAAmC;AACnC,oDAAwI;AAWxI,mDAAmE;AAEnE,IAAO,OAAO,GAAG,sBAAS,CAAC,OAAO,CAAA;AAClC,2CAA6D;AAE7D,IAAA,4BAAe,EAAC,KAAK,CAAC,CAAA;AACtB,IAAI,GAAa,CAAA;AAEjB,IAAA,cAAM,EAAC;;QACL,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;QACpB,MAAM,WAAW,GAAG,MAAM,IAAA,sCAAyB,GAAE,CAAA;QACrD,GAAG,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,IAAA,uBAAe,GAAE,CAAC,CAAA;IACpD,CAAC;CAAA,CAAC,CAAA;AAEF,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,IAAA,UAAE,EAAC,qCAAqC,EAAE,GAAS,EAAE;QACnD,QAAQ;QACR,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,MAAM,OAAO,CAAC,GAAI,EAAE,yBAAY,CAAC,CAAA;QAElE,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,CAAA;QAC/C,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,sBAAsB,CAAC,SAAS,EAAE,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wBAAc,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,EAAG,CAAC,CAAA;QACpI,IAAA,aAAM,EAAC,SAAS,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,SAAS,CAAA;QACtC,IAAA,aAAM,EAAC,SAAS,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,CAAA;IACpD,CAAC,CAAA,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import { before, it } from 'mocha'\n\nimport 'isomorphic-fetch'\n\nimport { EntityWithDelegationTypeName, IccContactXApi, IccHelementXApi, IccPatientXApi, utf8_2ua } from '../../icc-x-api'\nimport { Patient } from '../../icc-api/model/Patient'\nimport { assert, expect } from 'chai'\nimport { randomUUID } from 'crypto'\nimport { createNewHcpApi, getEnvironmentInitializer, hcp1Username, hcp2Username, setLocalStorage, TestUtils } from '../utils/test_utils'\nimport { Code } from '../../icc-api/model/Code'\nimport { Contact } from '../../icc-api/model/Contact'\nimport { Service } from '../../icc-api/model/Service'\nimport { Content } from '../../icc-api/model/Content'\nimport { User } from '../../icc-api/model/User'\nimport { HealthElement } from '../../icc-api/model/HealthElement'\nimport { SubContact } from '../../icc-api/model/SubContact'\nimport { ServiceLink } from '../../icc-api/model/ServiceLink'\nimport { FilterChainService } from '../../icc-api/model/FilterChainService'\nimport { ServiceByHcPartyHealthElementIdsFilter } from '../../icc-x-api/filters/ServiceByHcPartyHealthElementIdsFilter'\nimport { getEnvVariables, TestVars } from '@icure/test-setup/types'\nimport { Measure } from '../../icc-api/model/Measure'\nimport initApi = TestUtils.initApi\nimport { IccDocumentApi, IccMessageApi } from '../../icc-api'\n\nsetLocalStorage(fetch)\nlet env: TestVars\n\nbefore(async function () {\n this.timeout(600000)\n const initializer = await getEnvironmentInitializer()\n env = await initializer.execute(getEnvVariables())\n})\n\ndescribe('icc-x-document-api Tests', () => {\n it('Get and decrypt as json should work', async () => {\n // Given\n const { documentApi, userApi } = await initApi(env!, hcp1Username)\n\n const currUser = await userApi.getCurrentUser()\n const document = await documentApi.createDocumentWithUser(undefined, await documentApi.newInstance(currUser, undefined, {}))\n const obj = { test: 'test' }\n await documentApi.encryptAndSetDocumentAttachment(document, utf8_2ua(JSON.stringify(obj)))\n const decrypted = await documentApi.getAndTryDecryptMainAttachmentAs(document, 'application/json')\n expect(decrypted).to.deep.equal(obj)\n })\n\n it('Get and decrypt as string should work', async () => {\n // Given\n const { documentApi, userApi } = await initApi(env!, hcp1Username)\n\n const currUser = await userApi.getCurrentUser()\n const document = await documentApi.createDocumentWithUser(undefined, await documentApi.newInstance(currUser, undefined, {}))\n const obj = 'Test'\n await documentApi.encryptAndSetDocumentAttachment(document, utf8_2ua(obj))\n const decrypted = await documentApi.getAndTryDecryptMainAttachmentAs(document, 'text/plain')\n expect(decrypted).to.deep.equal(obj)\n const decryptedAsJson = await documentApi.getAndTryDecryptMainAttachmentAs(document, 'application/json')\n expect(decryptedAsJson).to.be.undefined\n })\n\n it('Should be encrypted', async () => {\n const hcp = await createNewHcpApi(env, {\n encryptedFieldsConfig: {\n document: ['name'],\n },\n })\n const name = 'Private.txt'\n const externalUuid = randomUUID()\n const created = await hcp.api.documentApi.createDocumentWithUser(\n undefined,\n await hcp.api.documentApi.newInstance(hcp.user, undefined, {\n id: randomUUID(),\n name,\n externalUuid,\n })\n )\n expect(created.name).to.eq(name)\n expect(created.externalUuid).to.eq(externalUuid)\n const retrieved = await hcp.api.documentApi.getDocumentWithUser(undefined, created.id!)\n expect(retrieved.name).to.eq(name)\n expect(retrieved.externalUuid).to.eq(externalUuid)\n const encrypted = await new IccDocumentApi(env.iCureUrl, {}, hcp.api.authApi.authenticationProvider, fetch).getDocument(created.id!)\n expect(encrypted.name).to.be.undefined\n expect(encrypted.externalUuid).to.eq(externalUuid)\n })\n})\n"]}
|
|
@@ -8,31 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var _a;
|
|
12
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
12
|
require("isomorphic-fetch");
|
|
14
13
|
const test_utils_1 = require("../utils/test_utils");
|
|
15
14
|
const mocha_1 = require("mocha");
|
|
16
|
-
const icc_x_api_1 = require("../../icc-x-api");
|
|
17
|
-
const Patient_1 = require("../../icc-api/model/Patient");
|
|
18
15
|
const crypto_1 = require("crypto");
|
|
19
16
|
const types_1 = require("@icure/test-setup/types");
|
|
20
|
-
const Topic_1 = require("../../icc-api/model/Topic");
|
|
21
|
-
const SecureDelegation_1 = require("../../icc-api/model/SecureDelegation");
|
|
22
|
-
const XHR_1 = require("../../icc-api/api/XHR");
|
|
23
|
-
const Message_1 = require("../../icc-api/model/Message");
|
|
24
|
-
var initApi = test_utils_1.TestUtils.initApi;
|
|
25
|
-
const FilterChainMessage_1 = require("../../icc-api/model/FilterChainMessage");
|
|
26
|
-
const MessageByHcPartyFilter_1 = require("../../icc-x-api/filters/MessageByHcPartyFilter");
|
|
27
|
-
const MessageByHcPartyTransportGuidFilter_1 = require("../../icc-x-api/filters/MessageByHcPartyTransportGuidFilter");
|
|
28
|
-
const LatestMessageByHcPartyTransportGuidFilter_1 = require("../../icc-x-api/filters/LatestMessageByHcPartyTransportGuidFilter");
|
|
29
17
|
const chai_1 = require("chai");
|
|
30
18
|
const chaiAsPromised = require("chai-as-promised");
|
|
31
19
|
const icc_api_1 = require("../../icc-api");
|
|
32
20
|
(0, chai_1.use)(chaiAsPromised);
|
|
33
21
|
(0, test_utils_1.setLocalStorage)(fetch);
|
|
34
22
|
let env;
|
|
35
|
-
(
|
|
23
|
+
(0, mocha_1.describe)('icc-message-x-api', () => {
|
|
36
24
|
(0, mocha_1.before)(function () {
|
|
37
25
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
26
|
this.timeout(600000);
|
|
@@ -40,289 +28,27 @@ let env;
|
|
|
40
28
|
env = yield initializer.execute((0, types_1.getEnvVariables)());
|
|
41
29
|
});
|
|
42
30
|
});
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var _a, _b;
|
|
46
|
-
return messageApi.encryptAndCreateMessageInTopic(yield messageApi.newInstanceWithPatient(hcpUser, patient, new Message_1.Message({
|
|
47
|
-
id: (0, crypto_1.randomUUID)(),
|
|
48
|
-
subject: 'Message Subject',
|
|
49
|
-
sent: new Date().getTime(),
|
|
50
|
-
transportGuid: topic.id,
|
|
51
|
-
readStatus: Object.fromEntries(Object.keys((_a = topic.activeParticipants) !== null && _a !== void 0 ? _a : {})
|
|
52
|
-
.filter((p) => p != hcpUser.healthcarePartyId)
|
|
53
|
-
.map((hcpId) => [hcpId, { read: false }])),
|
|
54
|
-
fromHealthcarePartyId: hcpUser.healthcarePartyId,
|
|
55
|
-
}), {
|
|
56
|
-
additionalDelegates: Object.fromEntries(Object.keys((_b = topic.activeParticipants) !== null && _b !== void 0 ? _b : {})
|
|
57
|
-
.filter((hcpId) => hcpId != hcpUser.healthcarePartyId)
|
|
58
|
-
.map((hcpId) => [hcpId, SecureDelegation_1.SecureDelegation.AccessLevelEnum.READ])),
|
|
59
|
-
}));
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function createTopic(topicApi, hcpUser, patient, ...additionalUser) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
return topicApi.createTopic(yield topicApi.newInstance(hcpUser, patient, new Topic_1.Topic({
|
|
65
|
-
id: (0, crypto_1.randomUUID)(),
|
|
66
|
-
description: 'Topic description',
|
|
67
|
-
activeParticipants: Object.assign(Object.assign({}, Object.fromEntries(additionalUser.map((u) => [u.user.healthcarePartyId, u.role]))), { [hcpUser.healthcarePartyId]: Topic_1.TopicRole.OWNER }),
|
|
68
|
-
}), {
|
|
69
|
-
additionalDelegates: Object.fromEntries(additionalUser.map((u) => [u.user.healthcarePartyId, SecureDelegation_1.SecureDelegation.AccessLevelEnum.WRITE])),
|
|
70
|
-
}));
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
function createPatient(patientApiForHcp, hcpUser) {
|
|
74
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
return patientApiForHcp.createPatientWithUser(hcpUser, yield patientApiForHcp.newInstance(hcpUser, new Patient_1.Patient({
|
|
76
|
-
id: (0, crypto_1.randomUUID)(),
|
|
77
|
-
firstName: 'John',
|
|
78
|
-
lastName: 'Snow',
|
|
79
|
-
note: 'Winter is coming',
|
|
80
|
-
})));
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
(0, mocha_1.it)('An HCP should be able to publish a message on a topic and a participant can read it', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
-
const { userApi: userApiForHcp, topicApi: topicApiForHcp, patientApi: patientApiForHcp, messageApi: messageApiForHcp, } = yield initApi(env, test_utils_1.hcp1Username);
|
|
85
|
-
const { userApi: userApiForHcp2, messageApi: messageApiForHcp2 } = yield initApi(env, test_utils_1.hcp2Username);
|
|
86
|
-
const hcpUser = yield userApiForHcp.getCurrentUser();
|
|
87
|
-
const hcpUser2 = yield userApiForHcp2.getCurrentUser();
|
|
88
|
-
const samplePatient = yield createPatient(patientApiForHcp, hcpUser);
|
|
89
|
-
const createdTopic = yield createTopic(topicApiForHcp, hcpUser, samplePatient, { user: hcpUser2, role: Topic_1.TopicRole.PARTICIPANT });
|
|
90
|
-
const createdMessage = yield createMessage(messageApiForHcp, hcpUser, null, createdTopic);
|
|
91
|
-
const message = yield messageApiForHcp.getAndDecryptMessage(createdMessage.id);
|
|
92
|
-
const message2 = yield messageApiForHcp2.getAndDecryptMessage(createdMessage.id);
|
|
93
|
-
(0, chai_1.expect)(message).to.deep.equal(createdMessage);
|
|
94
|
-
(0, chai_1.expect)(message).to.deep.equal(message2);
|
|
95
|
-
}));
|
|
96
|
-
(0, mocha_1.it)('An HCP should be able to publish an encrypted message on a topic', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
-
const { userApi: userApiForHcp, topicApi: topicApiForHcp, patientApi: patientApiForHcp, messageApi: messageApiForHcp, } = yield initApi(env, test_utils_1.hcp1Username, {
|
|
31
|
+
(0, mocha_1.it)('Should be encrypted', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
const hcp = yield (0, test_utils_1.createNewHcpApi)(env, {
|
|
98
33
|
encryptedFieldsConfig: {
|
|
99
34
|
message: ['subject'],
|
|
100
35
|
},
|
|
101
36
|
});
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
(0, chai_1.expect)(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
(0, chai_1.expect)(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const { messageApi: messageApiForHcp3 } = yield initApi(env, test_utils_1.hcp3Username);
|
|
118
|
-
const hcpUser = yield userApiForHcp.getCurrentUser();
|
|
119
|
-
const hcpUser2 = yield userApiForHcp2.getCurrentUser();
|
|
120
|
-
const samplePatient = yield createPatient(patientApiForHcp, hcpUser);
|
|
121
|
-
const createdTopic = yield createTopic(topicApiForHcp, hcpUser, samplePatient, { user: hcpUser2, role: Topic_1.TopicRole.PARTICIPANT });
|
|
122
|
-
const createdMessage = yield createMessage(messageApiForHcp, hcpUser, null, createdTopic);
|
|
123
|
-
const message = yield messageApiForHcp.getAndDecryptMessage(createdMessage.id);
|
|
124
|
-
(0, chai_1.expect)(message).to.not.be.null;
|
|
125
|
-
yield messageApiForHcp3.getAndDecryptMessage(createdMessage.id).then(() => chai_1.expect.fail('Should not be able to read the message'), (e) => {
|
|
126
|
-
(0, chai_1.expect)(e).to.be.instanceOf(XHR_1.XHR.XHRError);
|
|
127
|
-
(0, chai_1.expect)(e.statusCode).to.equal(403);
|
|
128
|
-
});
|
|
129
|
-
}));
|
|
130
|
-
(0, mocha_1.it)('An HCP should be able to publish a message on a topic and a participant could query it through MessageByHcPartyFilter', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
131
|
-
const { userApi: userApiForHcp, topicApi: topicApiForHcp, patientApi: patientApiForHcp, messageApi: messageApiForHcp, } = yield initApi(env, test_utils_1.hcp1Username);
|
|
132
|
-
const { userApi: userApiForHcp2, messageApi: messageApiForHcp2 } = yield initApi(env, test_utils_1.hcp2Username);
|
|
133
|
-
const hcpUser = yield userApiForHcp.getCurrentUser();
|
|
134
|
-
const hcpUser2 = yield userApiForHcp2.getCurrentUser();
|
|
135
|
-
const samplePatient = yield createPatient(patientApiForHcp, hcpUser);
|
|
136
|
-
const createdTopic = yield createTopic(topicApiForHcp, hcpUser, samplePatient, { user: hcpUser2, role: Topic_1.TopicRole.PARTICIPANT });
|
|
137
|
-
const createdMessage = yield createMessage(messageApiForHcp, hcpUser, null, createdTopic);
|
|
138
|
-
const message = yield messageApiForHcp.getAndDecryptMessage(createdMessage.id);
|
|
139
|
-
const filterChain = (hcpId) => new FilterChainMessage_1.FilterChainMessage({
|
|
140
|
-
filter: new MessageByHcPartyFilter_1.MessageByHcPartyFilter({
|
|
141
|
-
hcpId: hcpId,
|
|
142
|
-
}),
|
|
143
|
-
});
|
|
144
|
-
const filterResultForHcp = yield messageApiForHcp.filterMessagesBy(filterChain(hcpUser.healthcarePartyId));
|
|
145
|
-
(0, chai_1.expect)(filterResultForHcp.rows).to.have.length.greaterThanOrEqual(1);
|
|
146
|
-
(0, chai_1.expect)(filterResultForHcp.rows.find((m) => m.id === message.id)).to.deep.equal(message);
|
|
147
|
-
const filterResultForHcp2 = yield messageApiForHcp2.filterMessagesBy(filterChain(hcpUser2.healthcarePartyId));
|
|
148
|
-
(0, chai_1.expect)(filterResultForHcp2.rows).to.have.length.greaterThanOrEqual(1);
|
|
149
|
-
(0, chai_1.expect)(filterResultForHcp2.rows.find((m) => m.id === message.id)).to.deep.equal(message);
|
|
150
|
-
})).timeout(60000);
|
|
151
|
-
(0, mocha_1.it)('An HCP should be able to publish a message on a topic and a non-participant should not be able to query it through MessageByHcPartyFilter', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
152
|
-
const { userApi: userApiForHcp, topicApi: topicApiForHcp, patientApi: patientApiForHcp, messageApi: messageApiForHcp, } = yield initApi(env, test_utils_1.hcp1Username);
|
|
153
|
-
const { userApi: userApiForHcp2, messageApi: messageApiForHcp2 } = yield initApi(env, test_utils_1.hcp2Username);
|
|
154
|
-
const { messageApi: messageApiForHcp3, userApi: userApiForHcp3 } = yield initApi(env, test_utils_1.hcp3Username);
|
|
155
|
-
const hcpUser = yield userApiForHcp.getCurrentUser();
|
|
156
|
-
const hcpUser2 = yield userApiForHcp2.getCurrentUser();
|
|
157
|
-
const hcpUser3 = yield userApiForHcp3.getCurrentUser();
|
|
158
|
-
const samplePatient = yield createPatient(patientApiForHcp, hcpUser);
|
|
159
|
-
const createdTopic = yield createTopic(topicApiForHcp, hcpUser, samplePatient, { user: hcpUser2, role: Topic_1.TopicRole.PARTICIPANT });
|
|
160
|
-
const createdMessage = yield createMessage(messageApiForHcp, hcpUser, null, createdTopic);
|
|
161
|
-
const message = yield messageApiForHcp.getAndDecryptMessage(createdMessage.id);
|
|
162
|
-
const filterChain = (hcpId) => new FilterChainMessage_1.FilterChainMessage({
|
|
163
|
-
filter: new MessageByHcPartyFilter_1.MessageByHcPartyFilter({
|
|
164
|
-
hcpId: hcpId,
|
|
165
|
-
}),
|
|
166
|
-
});
|
|
167
|
-
const filterResultForHcp = yield messageApiForHcp.filterMessagesBy(filterChain(hcpUser.healthcarePartyId));
|
|
168
|
-
(0, chai_1.expect)(filterResultForHcp.rows).to.have.length.greaterThanOrEqual(1);
|
|
169
|
-
(0, chai_1.expect)(filterResultForHcp.rows.find((m) => m.id === message.id)).to.deep.equal(message);
|
|
170
|
-
const filterResultForHcp2 = yield messageApiForHcp2.filterMessagesBy(filterChain(hcpUser2.healthcarePartyId));
|
|
171
|
-
(0, chai_1.expect)(filterResultForHcp2.rows).to.have.length.greaterThanOrEqual(1);
|
|
172
|
-
(0, chai_1.expect)(filterResultForHcp2.rows.find((m) => m.id === message.id)).to.deep.equal(message);
|
|
173
|
-
const filterResultForHcp3 = yield messageApiForHcp3.filterMessagesBy(filterChain(hcpUser3.healthcarePartyId));
|
|
174
|
-
(0, chai_1.expect)(filterResultForHcp3.rows.find((m) => m.id === message.id)).to.be.undefined;
|
|
37
|
+
const subject = 'Hello';
|
|
38
|
+
const transportGuid = (0, crypto_1.randomUUID)();
|
|
39
|
+
const created = yield hcp.api.messageApi.createMessageWithUser(undefined, yield hcp.api.messageApi.newInstance(hcp.user, {
|
|
40
|
+
id: (0, crypto_1.randomUUID)(),
|
|
41
|
+
subject,
|
|
42
|
+
transportGuid,
|
|
43
|
+
}));
|
|
44
|
+
(0, chai_1.expect)(created.subject).to.eq(subject);
|
|
45
|
+
(0, chai_1.expect)(created.transportGuid).to.eq(transportGuid);
|
|
46
|
+
const retrieved = yield hcp.api.messageApi.getMessageWithUser(undefined, created.id);
|
|
47
|
+
(0, chai_1.expect)(retrieved.subject).to.eq(subject);
|
|
48
|
+
(0, chai_1.expect)(retrieved.transportGuid).to.eq(transportGuid);
|
|
49
|
+
const encrypted = yield new icc_api_1.IccMessageApi(env.iCureUrl, {}, hcp.api.authApi.authenticationProvider, fetch).getMessage(created.id);
|
|
50
|
+
(0, chai_1.expect)(encrypted.subject).to.be.undefined;
|
|
51
|
+
(0, chai_1.expect)(encrypted.transportGuid).to.eq(transportGuid);
|
|
175
52
|
}));
|
|
176
|
-
|
|
177
|
-
const { userApi: userApiForHcp, topicApi: topicApiForHcp, patientApi: patientApiForHcp, messageApi: messageApiForHcp, } = yield initApi(env, test_utils_1.hcp1Username);
|
|
178
|
-
const { userApi: userApiForHcp2, messageApi: messageApiForHcp2 } = yield initApi(env, test_utils_1.hcp2Username);
|
|
179
|
-
const hcpUser = yield userApiForHcp.getCurrentUser();
|
|
180
|
-
const hcpUser2 = yield userApiForHcp2.getCurrentUser();
|
|
181
|
-
const samplePatient = yield createPatient(patientApiForHcp, hcpUser);
|
|
182
|
-
const createdTopic = yield createTopic(topicApiForHcp, hcpUser, samplePatient, { user: hcpUser2, role: Topic_1.TopicRole.PARTICIPANT });
|
|
183
|
-
const createdMessage = yield createMessage(messageApiForHcp, hcpUser, null, createdTopic);
|
|
184
|
-
const message = yield messageApiForHcp.getAndDecryptMessage(createdMessage.id);
|
|
185
|
-
const filterChain = (hcpId, transportGuid) => new FilterChainMessage_1.FilterChainMessage({
|
|
186
|
-
filter: new MessageByHcPartyTransportGuidFilter_1.MessageByHcPartyTransportGuidFilter({
|
|
187
|
-
healthcarePartyId: hcpId,
|
|
188
|
-
transportGuid: transportGuid,
|
|
189
|
-
}),
|
|
190
|
-
});
|
|
191
|
-
const filterResultForHcp = yield messageApiForHcp.filterMessagesBy(filterChain(hcpUser.healthcarePartyId, message.transportGuid));
|
|
192
|
-
(0, chai_1.expect)(filterResultForHcp.rows).to.have.length(1);
|
|
193
|
-
(0, chai_1.expect)(filterResultForHcp.rows.find((m) => m.id === message.id)).to.deep.equal(message);
|
|
194
|
-
const filterResultForHcp2 = yield messageApiForHcp2.filterMessagesBy(filterChain(hcpUser2.healthcarePartyId, message.transportGuid));
|
|
195
|
-
(0, chai_1.expect)(filterResultForHcp2.rows).to.have.length(1);
|
|
196
|
-
(0, chai_1.expect)(filterResultForHcp2.rows.find((m) => m.id === message.id)).to.deep.equal(message);
|
|
197
|
-
}));
|
|
198
|
-
(0, mocha_1.it)('An HCP should be able to publish a message on a topic and a non-participant should not be able to query it through MessageByHcPartyTransportGuidFilter', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
199
|
-
const { userApi: userApiForHcp, topicApi: topicApiForHcp, patientApi: patientApiForHcp, messageApi: messageApiForHcp, } = yield initApi(env, test_utils_1.hcp1Username);
|
|
200
|
-
const { userApi: userApiForHcp2, messageApi: messageApiForHcp2 } = yield initApi(env, test_utils_1.hcp2Username);
|
|
201
|
-
const { userApi: userApiForHcp3, messageApi: messageApiForHcp3 } = yield initApi(env, test_utils_1.hcp3Username);
|
|
202
|
-
const hcpUser = yield userApiForHcp.getCurrentUser();
|
|
203
|
-
const hcpUser2 = yield userApiForHcp2.getCurrentUser();
|
|
204
|
-
const hcpUser3 = yield userApiForHcp3.getCurrentUser();
|
|
205
|
-
const samplePatient = yield createPatient(patientApiForHcp, hcpUser);
|
|
206
|
-
const createdTopic = yield createTopic(topicApiForHcp, hcpUser, samplePatient, { user: hcpUser2, role: Topic_1.TopicRole.PARTICIPANT });
|
|
207
|
-
const createdMessage = yield createMessage(messageApiForHcp, hcpUser, null, createdTopic);
|
|
208
|
-
const message = yield messageApiForHcp.getAndDecryptMessage(createdMessage.id);
|
|
209
|
-
const filterChain = (hcpId, transportGuid) => new FilterChainMessage_1.FilterChainMessage({
|
|
210
|
-
filter: new MessageByHcPartyTransportGuidFilter_1.MessageByHcPartyTransportGuidFilter({
|
|
211
|
-
healthcarePartyId: hcpId,
|
|
212
|
-
transportGuid: transportGuid,
|
|
213
|
-
}),
|
|
214
|
-
});
|
|
215
|
-
const filterResultForHcp = yield messageApiForHcp.filterMessagesBy(filterChain(hcpUser.healthcarePartyId, message.transportGuid));
|
|
216
|
-
(0, chai_1.expect)(filterResultForHcp.rows).to.have.length(1);
|
|
217
|
-
(0, chai_1.expect)(filterResultForHcp.rows.find((m) => m.id === message.id)).to.deep.equal(message);
|
|
218
|
-
const filterResultForHcp2 = yield messageApiForHcp2.filterMessagesBy(filterChain(hcpUser2.healthcarePartyId, message.transportGuid));
|
|
219
|
-
(0, chai_1.expect)(filterResultForHcp2.rows).to.have.length(1);
|
|
220
|
-
(0, chai_1.expect)(filterResultForHcp2.rows.find((m) => m.id === message.id)).to.deep.equal(message);
|
|
221
|
-
const filterResultForHcp3 = yield messageApiForHcp3.filterMessagesBy(filterChain(hcpUser3.healthcarePartyId, message.transportGuid));
|
|
222
|
-
(0, chai_1.expect)(filterResultForHcp3.rows.find((m) => m.id === message.id)).to.be.undefined;
|
|
223
|
-
}));
|
|
224
|
-
(0, mocha_1.it)('An HCP should be able to publish a message on a topic and a participant should be able to query it through LatestMessageByHcPartyTransportGuidFilter', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
225
|
-
const { userApi: userApiForHcp, topicApi: topicApiForHcp, patientApi: patientApiForHcp, messageApi: messageApiForHcp, } = yield initApi(env, test_utils_1.hcp1Username);
|
|
226
|
-
const { userApi: userApiForHcp2, messageApi: messageApiForHcp2 } = yield initApi(env, test_utils_1.hcp2Username);
|
|
227
|
-
const hcpUser = yield userApiForHcp.getCurrentUser();
|
|
228
|
-
const hcpUser2 = yield userApiForHcp2.getCurrentUser();
|
|
229
|
-
const samplePatient = yield createPatient(patientApiForHcp, hcpUser);
|
|
230
|
-
const createdTopic = yield createTopic(topicApiForHcp, hcpUser, samplePatient, { user: hcpUser2, role: Topic_1.TopicRole.PARTICIPANT });
|
|
231
|
-
let latestMessage = null;
|
|
232
|
-
for (let i = 0; i < 5; i++) {
|
|
233
|
-
// Creating 5 messages
|
|
234
|
-
latestMessage = yield createMessage(messageApiForHcp, hcpUser, null, createdTopic);
|
|
235
|
-
}
|
|
236
|
-
const filterChain = (hcpId, transportGuid) => new FilterChainMessage_1.FilterChainMessage({
|
|
237
|
-
filter: new LatestMessageByHcPartyTransportGuidFilter_1.LatestMessageByHcPartyTransportGuidFilter({
|
|
238
|
-
healthcarePartyId: hcpId,
|
|
239
|
-
transportGuid: transportGuid,
|
|
240
|
-
}),
|
|
241
|
-
});
|
|
242
|
-
const filterResultForHcp2 = yield messageApiForHcp2.filterMessagesBy(filterChain(hcpUser2.healthcarePartyId, latestMessage.transportGuid));
|
|
243
|
-
(0, chai_1.expect)(filterResultForHcp2.rows).to.have.length(1); // Only one message should be returned
|
|
244
|
-
(0, chai_1.expect)(filterResultForHcp2.rows[0]).to.deep.equal(latestMessage); // It should be the latest message
|
|
245
|
-
}));
|
|
246
|
-
function doXOnYAndSubscribe(connectionPromise, x, statusListener, eventReceivedPromiseReject, eventReceivedPromise) {
|
|
247
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
248
|
-
const connection = (yield connectionPromise)
|
|
249
|
-
.onClosed(() => __awaiter(this, void 0, void 0, function* () {
|
|
250
|
-
statusListener('CLOSED');
|
|
251
|
-
yield (0, icc_x_api_1.sleep)(3000);
|
|
252
|
-
}))
|
|
253
|
-
.onConnected(() => __awaiter(this, void 0, void 0, function* () {
|
|
254
|
-
statusListener('CONNECTED');
|
|
255
|
-
yield (0, icc_x_api_1.sleep)(2000);
|
|
256
|
-
yield x();
|
|
257
|
-
}));
|
|
258
|
-
const timeout = setTimeout(eventReceivedPromiseReject, 20000);
|
|
259
|
-
yield eventReceivedPromise.then(() => clearTimeout(timeout)).catch(() => { });
|
|
260
|
-
connection.close();
|
|
261
|
-
yield (0, icc_x_api_1.sleep)(3000);
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
const subscribeAndCreateMessage = (options, eventTypes) => __awaiter(void 0, void 0, void 0, function* () {
|
|
265
|
-
const { userApi: userApiForHcp, topicApi: topicApiForHcp, patientApi: patientApiForHcp, messageApi: messageApiForHcp, } = yield initApi(env, test_utils_1.hcp2Username);
|
|
266
|
-
const loggedUser = yield userApiForHcp.getCurrentUser();
|
|
267
|
-
const connectionPromise = (options, eventListener) => __awaiter(void 0, void 0, void 0, function* () {
|
|
268
|
-
return messageApiForHcp.subscribeToMessageEvents(eventTypes, new MessageByHcPartyFilter_1.MessageByHcPartyFilter({
|
|
269
|
-
hcpId: loggedUser.healthcarePartyId,
|
|
270
|
-
}), eventListener, options);
|
|
271
|
-
});
|
|
272
|
-
const events = [];
|
|
273
|
-
const statuses = [];
|
|
274
|
-
let eventReceivedPromiseResolve;
|
|
275
|
-
let eventReceivedPromiseReject;
|
|
276
|
-
const eventReceivedPromise = new Promise((res, rej) => {
|
|
277
|
-
eventReceivedPromiseResolve = res;
|
|
278
|
-
eventReceivedPromiseReject = rej;
|
|
279
|
-
});
|
|
280
|
-
yield doXOnYAndSubscribe(connectionPromise(options, (healthcareElement) => __awaiter(void 0, void 0, void 0, function* () {
|
|
281
|
-
events.push(healthcareElement);
|
|
282
|
-
eventReceivedPromiseResolve();
|
|
283
|
-
})), () => __awaiter(void 0, void 0, void 0, function* () {
|
|
284
|
-
var _a;
|
|
285
|
-
const user = yield userApiForHcp.getCurrentUser();
|
|
286
|
-
const patient = yield patientApiForHcp.createPatientWithUser(user, yield patientApiForHcp.newInstance(user, new Patient_1.Patient({
|
|
287
|
-
firstName: 'John',
|
|
288
|
-
lastName: 'Snow',
|
|
289
|
-
note: 'Winter is coming',
|
|
290
|
-
})));
|
|
291
|
-
const topic = yield topicApiForHcp.createTopic(yield topicApiForHcp.newInstance(loggedUser, patient, new Topic_1.Topic({
|
|
292
|
-
description: 'Topic description',
|
|
293
|
-
activeParticipants: {
|
|
294
|
-
[loggedUser.healthcarePartyId]: Topic_1.TopicRole.OWNER,
|
|
295
|
-
},
|
|
296
|
-
})));
|
|
297
|
-
const createdMessage = yield messageApiForHcp.encryptAndCreateMessageInTopic(yield messageApiForHcp.newInstanceWithPatient(loggedUser, null, new Message_1.Message({
|
|
298
|
-
id: (0, crypto_1.randomUUID)(),
|
|
299
|
-
subject: 'Message Subject',
|
|
300
|
-
sent: new Date().getTime(),
|
|
301
|
-
transportGuid: topic.id,
|
|
302
|
-
readStatus: Object.fromEntries(Object.keys((_a = topic.activeParticipants) !== null && _a !== void 0 ? _a : {})
|
|
303
|
-
.filter((hcpId) => hcpId != loggedUser.healthcarePartyId)
|
|
304
|
-
.map((hcpId) => [hcpId, { read: false }])),
|
|
305
|
-
fromHealthcarePartyId: loggedUser.healthcarePartyId,
|
|
306
|
-
}), {
|
|
307
|
-
additionalDelegates: {},
|
|
308
|
-
}));
|
|
309
|
-
}), (status) => {
|
|
310
|
-
statuses.push(status);
|
|
311
|
-
}, eventReceivedPromiseReject, eventReceivedPromise);
|
|
312
|
-
events === null || events === void 0 ? void 0 : events.forEach((event) => console.log(`Event : ${event}`));
|
|
313
|
-
statuses === null || statuses === void 0 ? void 0 : statuses.forEach((status) => console.log(`Status : ${status}`));
|
|
314
|
-
(0, chai_1.expect)(statuses).to.have.length(2);
|
|
315
|
-
(0, chai_1.expect)(events).to.have.length(1);
|
|
316
|
-
(0, chai_1.expect)(events.every((event) => event instanceof Message_1.Message)).to.be.true;
|
|
317
|
-
});
|
|
318
|
-
(0, mocha_1.it)('CREATE Message without options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
319
|
-
yield subscribeAndCreateMessage({}, ['CREATE']);
|
|
320
|
-
})).timeout(60000);
|
|
321
|
-
(0, mocha_1.it)('CREATE Message with options', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
322
|
-
yield subscribeAndCreateMessage({
|
|
323
|
-
connectionRetryIntervalMs: 10000,
|
|
324
|
-
connectionMaxRetry: 5,
|
|
325
|
-
}, ['CREATE']);
|
|
326
|
-
})).timeout(60000);
|
|
327
|
-
})) === null || _a === void 0 ? void 0 : _a.timeout(60000);
|
|
53
|
+
});
|
|
328
54
|
//# sourceMappingURL=icc-message-x-api.js.map
|