gdc-sdk-client-ts 1.0.3 → 1.1.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.
Files changed (318) hide show
  1. package/README.md +8 -9
  2. package/dist/ClientSDK.d.ts +56 -0
  3. package/dist/ClientSDK.js +202 -0
  4. package/dist/JobManager.d.ts +39 -0
  5. package/dist/JobManager.js +258 -0
  6. package/dist/ProfileManager.d.ts +72 -0
  7. package/dist/ProfileManager.js +113 -0
  8. package/dist/ProfileRegistry.d.ts +14 -0
  9. package/dist/ProfileRegistry.js +38 -0
  10. package/dist/SmartTokenManager.d.ts +62 -0
  11. package/dist/SmartTokenManager.js +223 -0
  12. package/dist/VerifierService.d.ts +39 -0
  13. package/dist/VerifierService.js +116 -0
  14. package/dist/frontend-services/BaseApiService.d.ts +73 -0
  15. package/dist/frontend-services/BaseApiService.js +205 -0
  16. package/dist/frontend-services/base/BaseProfessionalService.d.ts +22 -0
  17. package/dist/frontend-services/base/BaseProfessionalService.js +44 -0
  18. package/dist/frontend-services/capabilities/AppointmentService.d.ts +29 -0
  19. package/dist/frontend-services/capabilities/AppointmentService.js +32 -0
  20. package/dist/frontend-services/capabilities/MedicationService.d.ts +25 -0
  21. package/dist/frontend-services/capabilities/MedicationService.js +62 -0
  22. package/dist/frontend-services/capabilities/TaskService.d.ts +21 -0
  23. package/dist/frontend-services/capabilities/TaskService.js +40 -0
  24. package/dist/frontend-services/common/CommonAuthService.d.ts +36 -0
  25. package/dist/frontend-services/common/CommonAuthService.js +158 -0
  26. package/dist/frontend-services/family-admin/FamilyAdminService.d.ts +39 -0
  27. package/dist/frontend-services/family-admin/FamilyAdminService.js +74 -0
  28. package/dist/frontend-services/family-admin/FamilyItService.d.ts +24 -0
  29. package/dist/frontend-services/family-admin/FamilyItService.js +34 -0
  30. package/dist/frontend-services/individual/IndividualService.d.ts +18 -0
  31. package/dist/frontend-services/individual/IndividualService.js +33 -0
  32. package/dist/frontend-services/org-admin/OrgAdminService.d.ts +56 -0
  33. package/dist/frontend-services/org-admin/OrgAdminService.js +107 -0
  34. package/dist/frontend-services/org-admin/OrgItService.d.ts +25 -0
  35. package/dist/frontend-services/org-admin/OrgItService.js +39 -0
  36. package/dist/frontend-services/professional/emergencies/ParamedicService.d.ts +12 -0
  37. package/dist/frontend-services/professional/emergencies/ParamedicService.js +15 -0
  38. package/dist/frontend-services/professional/health-care/PhysicianService.d.ts +33 -0
  39. package/dist/frontend-services/professional/health-care/PhysicianService.js +35 -0
  40. package/dist/index.d.ts +16 -0
  41. package/{src/index.ts → dist/index.js} +6 -14
  42. package/dist/interfaces/IJobManager.d.ts +23 -0
  43. package/dist/interfaces/IJobManager.js +3 -0
  44. package/{src/interfaces/IParams.ts → dist/interfaces/IParams.d.ts} +20 -29
  45. package/dist/interfaces/IParams.js +3 -0
  46. package/dist/interfaces/IProfile.d.ts +15 -0
  47. package/dist/interfaces/IProfile.js +3 -0
  48. package/{src/interfaces/ISchemaorg.ts → dist/interfaces/ISchemaorg.d.ts} +23 -115
  49. package/dist/interfaces/ISchemaorg.js +184 -0
  50. package/dist/interfaces/ISmartTokenManager.d.ts +38 -0
  51. package/dist/interfaces/ISmartTokenManager.js +3 -0
  52. package/dist/interfaces/ITrustRegistry.d.ts +39 -0
  53. package/dist/interfaces/ITrustRegistry.js +3 -0
  54. package/dist/interfaces/IVaultRepository.d.ts +35 -0
  55. package/dist/interfaces/IVaultRepository.js +14 -0
  56. package/{src/interfaces/index.ts → dist/interfaces/index.d.ts} +0 -5
  57. package/dist/interfaces/index.js +10 -0
  58. package/dist/interfaces/others.d.ts +91 -0
  59. package/dist/interfaces/others.js +3 -0
  60. package/dist/models/claims/ClaimsAllergyIntolerance.model.d.ts +51 -0
  61. package/dist/models/claims/ClaimsAllergyIntolerance.model.js +15 -0
  62. package/dist/models/claims/ClaimsBase.common.model.d.ts +32 -0
  63. package/dist/models/claims/ClaimsBase.common.model.js +14 -0
  64. package/dist/models/claims/ClaimsCondition.model.d.ts +45 -0
  65. package/dist/models/claims/ClaimsCondition.model.js +14 -0
  66. package/dist/models/claims/ClaimsConsent.model.d.ts +118 -0
  67. package/dist/models/claims/ClaimsConsent.model.js +40 -0
  68. package/dist/models/claims/ClaimsDevice.model.d.ts +79 -0
  69. package/dist/models/claims/ClaimsDevice.model.js +39 -0
  70. package/dist/models/claims/ClaimsDeviceAssociation.model.d.ts +67 -0
  71. package/dist/models/claims/ClaimsDeviceAssociation.model.js +32 -0
  72. package/dist/models/claims/ClaimsDeviceUsage.model.d.ts +77 -0
  73. package/dist/models/claims/ClaimsDeviceUsage.model.js +37 -0
  74. package/dist/models/claims/ClaimsMedicationStatement.model.d.ts +45 -0
  75. package/dist/models/claims/ClaimsMedicationStatement.model.js +14 -0
  76. package/dist/models/claims/ClaimsObservation.model.d.ts +45 -0
  77. package/dist/models/claims/ClaimsObservation.model.js +14 -0
  78. package/dist/models/claims/ClaimsRelatedPerson.model.d.ts +52 -0
  79. package/dist/models/claims/ClaimsRelatedPerson.model.js +16 -0
  80. package/{src/models/claims/index.ts → dist/models/claims/index.d.ts} +0 -4
  81. package/dist/models/claims/index.js +11 -0
  82. package/dist/models/hl7-personal-relationship.d.ts +6 -0
  83. package/dist/models/hl7-personal-relationship.js +217 -0
  84. package/{src/models/index.ts → dist/models/index.d.ts} +0 -2
  85. package/dist/models/index.js +5 -0
  86. package/dist/models/profileRegistry.d.ts +12 -0
  87. package/dist/models/profileRegistry.js +3 -0
  88. package/dist/models/roleIsco.d.ts +32 -0
  89. package/dist/models/roleIsco.js +41 -0
  90. package/dist/models/rolesHL7.d.ts +26 -0
  91. package/dist/models/rolesHL7.js +33 -0
  92. package/dist/roleRegistry.d.ts +55 -0
  93. package/dist/roleRegistry.js +77 -0
  94. package/dist/serviceSelectorRegistry.d.ts +50 -0
  95. package/dist/serviceSelectorRegistry.js +278 -0
  96. package/dist/uhc-fhir-utils-ts/models/AtcModel.d.ts +15 -0
  97. package/dist/uhc-fhir-utils-ts/models/AtcModel.js +2 -0
  98. package/dist/uhc-fhir-utils-ts/models/CommonModels.d.ts +70 -0
  99. package/dist/uhc-fhir-utils-ts/models/CommonModels.js +55 -0
  100. package/dist/uhc-fhir-utils-ts/models/DicomModels.d.ts +29 -0
  101. package/dist/uhc-fhir-utils-ts/models/DicomModels.js +2 -0
  102. package/{src/uhc-fhir-utils-ts/models/FhirModels.ts → dist/uhc-fhir-utils-ts/models/FhirModels.d.ts} +23 -33
  103. package/dist/uhc-fhir-utils-ts/models/FhirModels.js +34 -0
  104. package/dist/uhc-fhir-utils-ts/models/LoincModels.d.ts +24 -0
  105. package/dist/uhc-fhir-utils-ts/models/LoincModels.js +2 -0
  106. package/dist/uhc-fhir-utils-ts/models/SnomedModels.d.ts +13 -0
  107. package/dist/uhc-fhir-utils-ts/models/SnomedModels.js +2 -0
  108. package/{src/uhc-fhir-utils-ts/models/index.ts → dist/uhc-fhir-utils-ts/models/index.d.ts} +2 -5
  109. package/dist/uhc-fhir-utils-ts/models/index.js +8 -0
  110. package/dist/uhc-fhir-utils-ts/models/params/AdverseEvent.params.model.d.ts +14 -0
  111. package/dist/uhc-fhir-utils-ts/models/params/AdverseEvent.params.model.js +16 -0
  112. package/dist/uhc-fhir-utils-ts/models/params/AllergyIntolerance.params.model.d.ts +24 -0
  113. package/dist/uhc-fhir-utils-ts/models/params/AllergyIntolerance.params.model.js +27 -0
  114. package/dist/uhc-fhir-utils-ts/models/params/Appointment.params.model.d.ts +12 -0
  115. package/dist/uhc-fhir-utils-ts/models/params/Appointment.params.model.js +14 -0
  116. package/dist/uhc-fhir-utils-ts/models/params/ClinicalImpression.params.model.d.ts +14 -0
  117. package/dist/uhc-fhir-utils-ts/models/params/ClinicalImpression.params.model.js +15 -0
  118. package/dist/uhc-fhir-utils-ts/models/params/Condition.params.model.d.ts +16 -0
  119. package/dist/uhc-fhir-utils-ts/models/params/Condition.params.model.js +17 -0
  120. package/dist/uhc-fhir-utils-ts/models/params/DetectedIssue.params.model.d.ts +9 -0
  121. package/dist/uhc-fhir-utils-ts/models/params/DetectedIssue.params.model.js +11 -0
  122. package/dist/uhc-fhir-utils-ts/models/params/DiagnosticReport.params.model.d.ts +13 -0
  123. package/dist/uhc-fhir-utils-ts/models/params/DiagnosticReport.params.model.js +14 -0
  124. package/dist/uhc-fhir-utils-ts/models/params/Encounter.params.model.d.ts +15 -0
  125. package/dist/uhc-fhir-utils-ts/models/params/Encounter.params.model.js +17 -0
  126. package/dist/uhc-fhir-utils-ts/models/params/Immunization.params.model.d.ts +14 -0
  127. package/dist/uhc-fhir-utils-ts/models/params/Immunization.params.model.js +16 -0
  128. package/dist/uhc-fhir-utils-ts/models/params/Medication.params.model.d.ts +35 -0
  129. package/dist/uhc-fhir-utils-ts/models/params/Medication.params.model.js +45 -0
  130. package/dist/uhc-fhir-utils-ts/models/params/Observation.params.model.d.ts +320 -0
  131. package/dist/uhc-fhir-utils-ts/models/params/Observation.params.model.js +239 -0
  132. package/dist/uhc-fhir-utils-ts/models/params/Procedure.params.model.d.ts +15 -0
  133. package/dist/uhc-fhir-utils-ts/models/params/Procedure.params.model.js +17 -0
  134. package/dist/uhc-fhir-utils-ts/models/params/Search.params.model.d.ts +75 -0
  135. package/dist/uhc-fhir-utils-ts/models/params/Search.params.model.js +69 -0
  136. package/dist/uhc-fhir-utils-ts/models/params/ServiceRequest.params.model.d.ts +14 -0
  137. package/dist/uhc-fhir-utils-ts/models/params/ServiceRequest.params.model.js +16 -0
  138. package/dist/uhc-fhir-utils-ts/models/params/Specimen.params.model.d.ts +10 -0
  139. package/dist/uhc-fhir-utils-ts/models/params/Specimen.params.model.js +12 -0
  140. package/dist/uhc-fhir-utils-ts/models/params/index.d.ts +15 -0
  141. package/dist/uhc-fhir-utils-ts/models/params/index.js +15 -0
  142. package/{src/uhc-fhir-utils-ts/models/templates/AdverseEvent.template.model.ts → dist/uhc-fhir-utils-ts/models/templates/AdverseEvent.template.model.d.ts} +2 -10
  143. package/dist/uhc-fhir-utils-ts/models/templates/AdverseEvent.template.model.js +2 -0
  144. package/dist/uhc-fhir-utils-ts/models/templates/AllergyIntolerance.template.model.d.ts +24 -0
  145. package/dist/uhc-fhir-utils-ts/models/templates/AllergyIntolerance.template.model.js +1 -0
  146. package/dist/uhc-fhir-utils-ts/models/templates/Appointment.template.model.d.ts +13 -0
  147. package/dist/uhc-fhir-utils-ts/models/templates/Appointment.template.model.js +1 -0
  148. package/dist/uhc-fhir-utils-ts/models/templates/ClinicalImpression.template.model.d.ts +16 -0
  149. package/dist/uhc-fhir-utils-ts/models/templates/ClinicalImpression.template.model.js +1 -0
  150. package/dist/uhc-fhir-utils-ts/models/templates/Condition.template.model.d.ts +18 -0
  151. package/dist/uhc-fhir-utils-ts/models/templates/Condition.template.model.js +1 -0
  152. package/dist/uhc-fhir-utils-ts/models/templates/DetectedIssue.template.model.d.ts +11 -0
  153. package/dist/uhc-fhir-utils-ts/models/templates/DetectedIssue.template.model.js +1 -0
  154. package/dist/uhc-fhir-utils-ts/models/templates/DiagnosticReport.template.model.d.ts +15 -0
  155. package/dist/uhc-fhir-utils-ts/models/templates/DiagnosticReport.template.model.js +1 -0
  156. package/dist/uhc-fhir-utils-ts/models/templates/Encounter.template.model.d.ts +17 -0
  157. package/dist/uhc-fhir-utils-ts/models/templates/Encounter.template.model.js +1 -0
  158. package/dist/uhc-fhir-utils-ts/models/templates/Immunization.template.model.d.ts +18 -0
  159. package/dist/uhc-fhir-utils-ts/models/templates/Immunization.template.model.js +2 -0
  160. package/dist/uhc-fhir-utils-ts/models/templates/Medication.template.model.d.ts +37 -0
  161. package/dist/uhc-fhir-utils-ts/models/templates/Medication.template.model.js +1 -0
  162. package/dist/uhc-fhir-utils-ts/models/templates/Observation.template.model.d.ts +34 -0
  163. package/dist/uhc-fhir-utils-ts/models/templates/Observation.template.model.js +1 -0
  164. package/dist/uhc-fhir-utils-ts/models/templates/Procedure.template.model.d.ts +17 -0
  165. package/dist/uhc-fhir-utils-ts/models/templates/Procedure.template.model.js +1 -0
  166. package/dist/uhc-fhir-utils-ts/models/templates/ServiceRequest.template.model.d.ts +16 -0
  167. package/dist/uhc-fhir-utils-ts/models/templates/ServiceRequest.template.model.js +1 -0
  168. package/dist/uhc-fhir-utils-ts/models/templates/Specimen.template.model.d.ts +12 -0
  169. package/dist/uhc-fhir-utils-ts/models/templates/Specimen.template.model.js +1 -0
  170. package/dist/uhc-fhir-utils-ts/models/templates/index.d.ts +14 -0
  171. package/dist/uhc-fhir-utils-ts/models/templates/index.js +14 -0
  172. package/dist/uhc-fhir-utils-ts/utils/fhirRelatedPerson.d.ts +8 -0
  173. package/dist/uhc-fhir-utils-ts/utils/fhirRelatedPerson.js +57 -0
  174. package/dist/uhc-fhir-utils-ts/utils/fhirToken.d.ts +12 -0
  175. package/dist/uhc-fhir-utils-ts/utils/fhirToken.js +32 -0
  176. package/dist/uhc-fhir-utils-ts/utils/index.js +3 -0
  177. package/dist/uhc-fhir-utils-ts/utils/telecom.d.ts +2 -0
  178. package/dist/uhc-fhir-utils-ts/utils/telecom.js +12 -0
  179. package/dist/utils/capabilityMapper.d.ts +20 -0
  180. package/dist/utils/capabilityMapper.js +124 -0
  181. package/dist/utils/deriveObservations.d.ts +42 -0
  182. package/dist/utils/deriveObservations.js +21 -0
  183. package/dist/utils/entitlements.d.ts +10 -0
  184. package/dist/utils/entitlements.js +21 -0
  185. package/dist/utils/index.d.ts +4 -0
  186. package/dist/utils/index.js +7 -0
  187. package/dist/utils/mockData.d.ts +23 -0
  188. package/dist/utils/mockData.js +68 -0
  189. package/dist/utils/rule.d.ts +12 -0
  190. package/dist/utils/rule.js +45 -0
  191. package/dist/utils/scopeBuilder.d.ts +20 -0
  192. package/dist/utils/scopeBuilder.js +89 -0
  193. package/package.json +19 -4
  194. package/__tests__/BaseApiService.test.ts +0 -158
  195. package/__tests__/BaseProfessionalService.test.ts +0 -26
  196. package/__tests__/ClientSDK.test.ts +0 -114
  197. package/__tests__/CommonAuthService.test.ts +0 -170
  198. package/__tests__/ConversationToObservations.test.ts +0 -231
  199. package/__tests__/IStorageAdapter.ts +0 -39
  200. package/__tests__/IVaultRepository-backend.ts +0 -55
  201. package/__tests__/IndividualService.test.ts +0 -126
  202. package/__tests__/JobManager.test.ts +0 -338
  203. package/__tests__/OrgAdminService.test.ts +0 -157
  204. package/__tests__/ProfileManager.test.ts +0 -137
  205. package/__tests__/Services.test.ts +0 -148
  206. package/__tests__/SmartTokenManager.test.ts +0 -110
  207. package/__tests__/StorageAdapter-mem.ts +0 -46
  208. package/__tests__/VaultRepository-mem-frontend.ts +0 -95
  209. package/__tests__/VaultRepository.mem.ts +0 -122
  210. package/__tests__/VerifierService.test.ts +0 -89
  211. package/__tests__/capabilityMapper.test.ts +0 -67
  212. package/__tests__/integration/apiIntegratorsGuide.e2e.test.ts +0 -215
  213. package/__tests__/mockData.test.ts +0 -43
  214. package/__tests__/repository.ts +0 -14
  215. package/__tests__/rule.test.ts +0 -23
  216. package/__tests__/scopeBuilder.test.ts +0 -72
  217. package/__tests__/stubs/multibasehash.ts +0 -8
  218. package/__tests__/stubs/stablelib-base64.ts +0 -40
  219. package/__tests__/stubs/stablelib-utf8.ts +0 -23
  220. package/__tests__/testUtils.ts +0 -94
  221. package/babel.config.cjs +0 -6
  222. package/data/demo/credential.data.ts +0 -89
  223. package/data/demo/didProvider.data.ts +0 -68
  224. package/data/demo/entityKeys.data.ts +0 -15
  225. package/data/demo/example-payloads.data.ts +0 -369
  226. package/data/demo/offer.data.ts +0 -19
  227. package/data/demo/org-base.data.ts +0 -118
  228. package/data/demo/trust.registry.data.ts +0 -56
  229. package/data/demo/urn.data.ts +0 -10
  230. package/jest.config.ts +0 -27
  231. package/scripts/run-e2e-external.sh +0 -60
  232. package/src/ClientSDK.ts +0 -265
  233. package/src/JobManager.ts +0 -315
  234. package/src/ProfileManager.ts +0 -177
  235. package/src/ProfileRegistry.ts +0 -59
  236. package/src/SmartTokenManager.ts +0 -288
  237. package/src/VerifierService.ts +0 -140
  238. package/src/frontend-services/BaseApiService.ts +0 -282
  239. package/src/frontend-services/base/BaseProfessionalService.ts +0 -67
  240. package/src/frontend-services/capabilities/AppointmentService.ts +0 -58
  241. package/src/frontend-services/capabilities/MedicationService.ts +0 -88
  242. package/src/frontend-services/capabilities/TaskService.ts +0 -66
  243. package/src/frontend-services/common/CommonAuthService.ts +0 -217
  244. package/src/frontend-services/family-admin/FamilyAdminService.ts +0 -124
  245. package/src/frontend-services/family-admin/FamilyItService.ts +0 -53
  246. package/src/frontend-services/individual/IndividualService.ts +0 -46
  247. package/src/frontend-services/org-admin/OrgAdminService.ts +0 -131
  248. package/src/frontend-services/org-admin/OrgItService.ts +0 -59
  249. package/src/frontend-services/professional/emergencies/ParamedicService.ts +0 -28
  250. package/src/frontend-services/professional/health-care/PhysicianService.ts +0 -56
  251. package/src/interfaces/IJobManager.ts +0 -31
  252. package/src/interfaces/IProfile.ts +0 -23
  253. package/src/interfaces/ISmartTokenManager.ts +0 -44
  254. package/src/interfaces/ITrustRegistry.ts +0 -48
  255. package/src/interfaces/IVaultRepository.ts +0 -47
  256. package/src/interfaces/others.ts +0 -100
  257. package/src/models/claims/ClaimsAllergyIntolerance.model.ts +0 -62
  258. package/src/models/claims/ClaimsBase.common.model.ts +0 -37
  259. package/src/models/claims/ClaimsCondition.model.ts +0 -55
  260. package/src/models/claims/ClaimsConsent.model.ts +0 -148
  261. package/src/models/claims/ClaimsDevice.model.ts +0 -93
  262. package/src/models/claims/ClaimsDeviceAssociation.model.ts +0 -78
  263. package/src/models/claims/ClaimsDeviceUsage.model.ts +0 -93
  264. package/src/models/claims/ClaimsMedicationStatement.model.ts +0 -55
  265. package/src/models/claims/ClaimsObservation.model.ts +0 -55
  266. package/src/models/claims/ClaimsRelatedPerson.model.ts +0 -63
  267. package/src/models/hl7-personal-relationship.ts +0 -227
  268. package/src/models/profileRegistry.ts +0 -16
  269. package/src/models/roleIsco.ts +0 -45
  270. package/src/models/rolesHL7.ts +0 -36
  271. package/src/roleRegistry.ts +0 -120
  272. package/src/serviceSelectorRegistry.ts +0 -297
  273. package/src/uhc-fhir-utils-ts/models/AtcModel.ts +0 -20
  274. package/src/uhc-fhir-utils-ts/models/CommonModels.ts +0 -82
  275. package/src/uhc-fhir-utils-ts/models/DicomModels.ts +0 -36
  276. package/src/uhc-fhir-utils-ts/models/LoincModels.ts +0 -30
  277. package/src/uhc-fhir-utils-ts/models/SnomedModels.ts +0 -13
  278. package/src/uhc-fhir-utils-ts/models/params/AdverseEvent.params.model.ts +0 -16
  279. package/src/uhc-fhir-utils-ts/models/params/AllergyIntolerance.params.model.ts +0 -27
  280. package/src/uhc-fhir-utils-ts/models/params/Appointment.params.model.ts +0 -14
  281. package/src/uhc-fhir-utils-ts/models/params/ClinicalImpression.params.model.ts +0 -15
  282. package/src/uhc-fhir-utils-ts/models/params/Condition.params.model.ts +0 -17
  283. package/src/uhc-fhir-utils-ts/models/params/DetectedIssue.params.model.ts +0 -13
  284. package/src/uhc-fhir-utils-ts/models/params/DiagnosticReport.params.model.ts +0 -14
  285. package/src/uhc-fhir-utils-ts/models/params/Encounter.params.model.ts +0 -19
  286. package/src/uhc-fhir-utils-ts/models/params/Immunization.params.model.ts +0 -17
  287. package/src/uhc-fhir-utils-ts/models/params/Medication.params.model.ts +0 -45
  288. package/src/uhc-fhir-utils-ts/models/params/Observation.params.model.ts +0 -399
  289. package/src/uhc-fhir-utils-ts/models/params/Procedure.params.model.ts +0 -17
  290. package/src/uhc-fhir-utils-ts/models/params/Search.params.model.ts +0 -164
  291. package/src/uhc-fhir-utils-ts/models/params/ServiceRequest.params.model.ts +0 -16
  292. package/src/uhc-fhir-utils-ts/models/params/Specimen.params.model.ts +0 -12
  293. package/src/uhc-fhir-utils-ts/models/params/index.ts +0 -16
  294. package/src/uhc-fhir-utils-ts/models/templates/AllergyIntolerance.template.model.ts +0 -28
  295. package/src/uhc-fhir-utils-ts/models/templates/Appointment.template.model.ts +0 -17
  296. package/src/uhc-fhir-utils-ts/models/templates/ClinicalImpression.template.model.ts +0 -19
  297. package/src/uhc-fhir-utils-ts/models/templates/Condition.template.model.ts +0 -20
  298. package/src/uhc-fhir-utils-ts/models/templates/DetectedIssue.template.model.ts +0 -14
  299. package/src/uhc-fhir-utils-ts/models/templates/DiagnosticReport.template.model.ts +0 -19
  300. package/src/uhc-fhir-utils-ts/models/templates/Encounter.template.model.ts +0 -20
  301. package/src/uhc-fhir-utils-ts/models/templates/Immunization.template.model.ts +0 -21
  302. package/src/uhc-fhir-utils-ts/models/templates/Medication.template.model.ts +0 -52
  303. package/src/uhc-fhir-utils-ts/models/templates/Observation.template.model.ts +0 -53
  304. package/src/uhc-fhir-utils-ts/models/templates/Procedure.template.model.ts +0 -20
  305. package/src/uhc-fhir-utils-ts/models/templates/ServiceRequest.template.model.ts +0 -19
  306. package/src/uhc-fhir-utils-ts/models/templates/Specimen.template.model.ts +0 -15
  307. package/src/uhc-fhir-utils-ts/models/templates/index.ts +0 -15
  308. package/src/uhc-fhir-utils-ts/utils/fhirRelatedPerson.ts +0 -59
  309. package/src/uhc-fhir-utils-ts/utils/fhirToken.ts +0 -34
  310. package/src/uhc-fhir-utils-ts/utils/telecom.ts +0 -12
  311. package/src/utils/capabilityMapper.ts +0 -137
  312. package/src/utils/deriveObservations.ts +0 -73
  313. package/src/utils/index.ts +0 -7
  314. package/src/utils/mockData.ts +0 -88
  315. package/src/utils/rule.ts +0 -55
  316. package/src/utils/scopeBuilder.ts +0 -109
  317. package/tsconfig.json +0 -13
  318. /package/{src/uhc-fhir-utils-ts/utils/index.ts → dist/uhc-fhir-utils-ts/utils/index.d.ts} +0 -0
@@ -0,0 +1,72 @@
1
+ import { DidDocument } from 'gdc-common-utils-ts/models/did';
2
+ import { IWallet } from 'gdc-common-utils-ts/interfaces/IWallet';
3
+ import { JobRequest } from 'gdc-common-utils-ts/models/confidential-job';
4
+ import { IVaultRepository, VaultQuery } from './interfaces/IVaultRepository';
5
+ import { IProfile } from './interfaces/IProfile';
6
+ import { SdkConfig, AppInfo } from './interfaces/others';
7
+ import { ISmartTokenManager } from './interfaces/ISmartTokenManager';
8
+ import { IJobManager } from './interfaces/IJobManager';
9
+ import { CommonAuthService } from './frontend-services/common/CommonAuthService';
10
+ import { FamilyAdminServices, OrgAdminServices, ProfessionalServices, IndividualServices } from './roleRegistry';
11
+ interface CommonServices {
12
+ auth: CommonAuthService;
13
+ }
14
+ /**
15
+ * Configuration for the ProfileManager.
16
+ */
17
+ export interface ProfileManagerConfig {
18
+ profile: IProfile;
19
+ wallet: IWallet;
20
+ vault: IVaultRepository;
21
+ sdkConfig: SdkConfig;
22
+ appInfo: AppInfo;
23
+ orgDidDoc: DidDocument;
24
+ }
25
+ /**
26
+ * @class ProfileManager
27
+ * Represents an active user session. It is the central hub that provides access
28
+ * to namespaced API services based on the user's role.
29
+ * @sdk
30
+ */
31
+ export declare class ProfileManager {
32
+ profile: IProfile;
33
+ orgDidDoc: DidDocument;
34
+ private appInfo;
35
+ private wallet;
36
+ private vault;
37
+ private sdkConfig;
38
+ jobManager: IJobManager;
39
+ smartTokenManager: ISmartTokenManager;
40
+ orgAdmin?: OrgAdminServices;
41
+ familyAdmin?: FamilyAdminServices;
42
+ professional?: ProfessionalServices;
43
+ individual?: IndividualServices;
44
+ common: CommonServices;
45
+ constructor(config: ProfileManagerConfig);
46
+ /**
47
+ * Builds the entire API surface by calling the capabilityMapper and assigning
48
+ * the returned services to the appropriate namespaces.
49
+ */
50
+ private buildApiSurface;
51
+ /**
52
+ * Initializes all stateful services owned by this profile instance.
53
+ */
54
+ initialize(): Promise<void>;
55
+ /**
56
+ * Updates and persists the current profile in the local vault.
57
+ */
58
+ updateProfile(patch: Partial<IProfile>): Promise<void>;
59
+ /**
60
+ * Requests (or reuses) a SMART access token for the given provider and scopes.
61
+ */
62
+ getSmartToken(providerDid: string, scopes: string[], idToken: string, clientId?: string): Promise<import("./interfaces").SmartToken>;
63
+ /**
64
+ * Shuts down all services owned by this profile instance.
65
+ */
66
+ shutdown(): void;
67
+ /**
68
+ * Queries jobs from the vault for the current profile using a specific query.
69
+ */
70
+ queryJobs(query: VaultQuery): Promise<JobRequest[]>;
71
+ }
72
+ export {};
@@ -0,0 +1,113 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: client-sdk-ts/src/ProfileManager.ts
3
+ import JobManager from './JobManager.js';
4
+ import { SmartTokenManager } from './SmartTokenManager.js';
5
+ import { CommonAuthService } from './frontend-services/common/CommonAuthService.js';
6
+ import { mapCapabilitiesToServices } from './utils/capabilityMapper.js';
7
+ /**
8
+ * @class ProfileManager
9
+ * Represents an active user session. It is the central hub that provides access
10
+ * to namespaced API services based on the user's role.
11
+ * @sdk
12
+ */
13
+ export class ProfileManager {
14
+ constructor(config) {
15
+ var _a, _b, _c;
16
+ if (!config || !config.profile || !config.wallet || !config.vault || !config.sdkConfig) {
17
+ throw new Error("ProfileManager requires 'profile', 'wallet', 'vault', and 'sdkConfig'.");
18
+ }
19
+ this.profile = config.profile;
20
+ this.orgDidDoc = config.orgDidDoc;
21
+ this.appInfo = config.appInfo;
22
+ this.wallet = config.wallet;
23
+ this.vault = config.vault;
24
+ this.sdkConfig = config.sdkConfig;
25
+ this.jobManager = new JobManager({
26
+ profile: this.profile,
27
+ wallet: this.wallet,
28
+ vault: this.vault,
29
+ sdkConfig: config.sdkConfig
30
+ });
31
+ const isMock = !!((_a = this.sdkConfig.mockOptions) === null || _a === void 0 ? void 0 : _a.apiResponse) || !!((_b = this.sdkConfig.mockOptions) === null || _b === void 0 ? void 0 : _b.resolvedDidDocs);
32
+ this.smartTokenManager = new SmartTokenManager({
33
+ mode: isMock ? 'mock' : 'backend',
34
+ fetcher: this.sdkConfig.fetcher,
35
+ resolvedDidDocs: (_c = this.sdkConfig.mockOptions) === null || _c === void 0 ? void 0 : _c.resolvedDidDocs,
36
+ cryptoHelper: this.sdkConfig.crypto,
37
+ });
38
+ // The single call to our intelligent "brain" to build the API surface.
39
+ const serviceContext = this.buildApiSurface();
40
+ this.common = {
41
+ auth: new CommonAuthService(serviceContext),
42
+ };
43
+ }
44
+ /**
45
+ * Builds the entire API surface by calling the capabilityMapper and assigning
46
+ * the returned services to the appropriate namespaces.
47
+ */
48
+ buildApiSurface() {
49
+ const serviceContext = {
50
+ profile: this.profile,
51
+ jobManager: this.jobManager,
52
+ smartTokenManager: this.smartTokenManager,
53
+ sdkConfig: this.sdkConfig,
54
+ appInfo: this.appInfo, // Pass AppInfo to context
55
+ cryptoHelper: this.sdkConfig.crypto,
56
+ };
57
+ // Delegate the complex role mapping to the central mapper
58
+ const { orgAdmin, familyAdmin, professional, individual } = mapCapabilitiesToServices(serviceContext, this.profile, this.orgDidDoc, this.appInfo.appType // Pass the appType from AppInfo
59
+ );
60
+ // Assign the returned, fully instantiated and composed services
61
+ this.orgAdmin = orgAdmin;
62
+ this.familyAdmin = familyAdmin;
63
+ this.professional = professional;
64
+ this.individual = individual;
65
+ return serviceContext;
66
+ }
67
+ /**
68
+ * Initializes all stateful services owned by this profile instance.
69
+ */
70
+ async initialize() {
71
+ await this.vault.initialize();
72
+ await this.jobManager.initialize();
73
+ console.log(`[ProfileManager] Initialized for profile: ${this.profile.id}`);
74
+ }
75
+ /**
76
+ * Updates and persists the current profile in the local vault.
77
+ */
78
+ async updateProfile(patch) {
79
+ this.profile = Object.assign(Object.assign({}, this.profile), patch);
80
+ await this.vault.put('profile', this.profile);
81
+ }
82
+ /**
83
+ * Requests (or reuses) a SMART access token for the given provider and scopes.
84
+ */
85
+ async getSmartToken(providerDid, scopes, idToken, clientId) {
86
+ const resolvedClientId = clientId || this.profile.deviceDid;
87
+ if (!resolvedClientId) {
88
+ throw new Error('[ProfileManager] Missing device client_id. Activate the device before requesting SMART tokens.');
89
+ }
90
+ const normalizedScopes = Array.from(new Set(scopes.filter(Boolean))).sort();
91
+ return this.smartTokenManager.getToken(providerDid, normalizedScopes, idToken, resolvedClientId);
92
+ }
93
+ /**
94
+ * Shuts down all services owned by this profile instance.
95
+ */
96
+ shutdown() {
97
+ if (this.jobManager) {
98
+ this.jobManager.shutdown();
99
+ }
100
+ this.smartTokenManager.clearAllTokens();
101
+ console.log(`[ProfileManager] Shutdown for profile: ${this.profile.id}`);
102
+ }
103
+ /**
104
+ * Queries jobs from the vault for the current profile using a specific query.
105
+ */
106
+ async queryJobs(query) {
107
+ if (!this.jobManager) {
108
+ console.warn("[ProfileManager] Attempted to query jobs, but JobManager is not initialized.");
109
+ return [];
110
+ }
111
+ return this.jobManager.queryJobs(query);
112
+ }
113
+ }
@@ -0,0 +1,14 @@
1
+ import { IVaultRepository, VaultQuery } from './interfaces/IVaultRepository';
2
+ import { ProfileRegistryEntry } from './models/profileRegistry';
3
+ export declare class ProfileRegistry {
4
+ private vault;
5
+ constructor(vault: IVaultRepository);
6
+ initialize(): Promise<void>;
7
+ list(query?: VaultQuery): Promise<ProfileRegistryEntry[]>;
8
+ get(profileId: string): Promise<ProfileRegistryEntry | undefined>;
9
+ upsert(entry: Omit<ProfileRegistryEntry, 'id'> & {
10
+ id?: string;
11
+ }): Promise<ProfileRegistryEntry>;
12
+ markLastUsed(profileId: string): Promise<void>;
13
+ remove(profileId: string): Promise<boolean>;
14
+ }
@@ -0,0 +1,38 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: client-sdk-ts/src/ProfileRegistry.ts
3
+ const PROFILE_INDEX_COLLECTION = 'profile-index';
4
+ export class ProfileRegistry {
5
+ constructor(vault) {
6
+ this.vault = vault;
7
+ }
8
+ async initialize() {
9
+ await this.vault.initialize();
10
+ }
11
+ async list(query) {
12
+ const fallbackQuery = {
13
+ orderBy: { attribute: 'lastUsedAt', direction: 'desc' },
14
+ };
15
+ return this.vault.query(PROFILE_INDEX_COLLECTION, query !== null && query !== void 0 ? query : fallbackQuery);
16
+ }
17
+ async get(profileId) {
18
+ return this.vault.get(PROFILE_INDEX_COLLECTION, profileId);
19
+ }
20
+ async upsert(entry) {
21
+ var _a, _b, _c, _d;
22
+ const now = new Date().toISOString();
23
+ const id = entry.id || entry.profileId;
24
+ const existing = id ? await this.get(id) : undefined;
25
+ const record = Object.assign(Object.assign(Object.assign({}, existing), entry), { id, profileId: entry.profileId || (existing === null || existing === void 0 ? void 0 : existing.profileId) || id, createdAt: (_b = (_a = existing === null || existing === void 0 ? void 0 : existing.createdAt) !== null && _a !== void 0 ? _a : entry.createdAt) !== null && _b !== void 0 ? _b : now, lastUsedAt: (_d = (_c = entry.lastUsedAt) !== null && _c !== void 0 ? _c : existing === null || existing === void 0 ? void 0 : existing.lastUsedAt) !== null && _d !== void 0 ? _d : now });
26
+ await this.vault.put(PROFILE_INDEX_COLLECTION, record);
27
+ return record;
28
+ }
29
+ async markLastUsed(profileId) {
30
+ const existing = await this.get(profileId);
31
+ if (!existing)
32
+ return;
33
+ await this.vault.put(PROFILE_INDEX_COLLECTION, Object.assign(Object.assign({}, existing), { lastUsedAt: new Date().toISOString() }));
34
+ }
35
+ async remove(profileId) {
36
+ return this.vault.delete(PROFILE_INDEX_COLLECTION, profileId);
37
+ }
38
+ }
@@ -0,0 +1,62 @@
1
+ import type { ICryptoHelper } from 'gdc-common-utils-ts/interfaces/ICryptoHelper';
2
+ import { ISmartTokenManager, SmartToken } from "./interfaces/ISmartTokenManager";
3
+ export type SmartTokenManagerMode = 'mock' | 'backend';
4
+ export type SmartTokenManagerOptions = {
5
+ mode?: SmartTokenManagerMode;
6
+ fetcher?: typeof fetch;
7
+ resolvedDidDocs?: {
8
+ [did: string]: any;
9
+ };
10
+ cryptoHelper?: ICryptoHelper;
11
+ /**
12
+ * Default purpose to request in SMART token calls (backend mode).
13
+ * This is a business/policy hint, not the OAuth "audience".
14
+ */
15
+ defaultPurpose?: string;
16
+ };
17
+ /**
18
+ * A concrete implementation of the ISmartTokenManager.
19
+ *
20
+ * This implementation uses a simple in-memory cache. In a real application,
21
+ * this could be backed by secure storage. The token acquisition logic is
22
+ * currently a placeholder and would need to be replaced with a full
23
+ * OIDC/OAuth 2.0 client flow (e.g., using `expo-auth-session`).
24
+ */
25
+ export declare class SmartTokenManager implements ISmartTokenManager {
26
+ private tokenCache;
27
+ private readonly mode;
28
+ private readonly fetcher?;
29
+ private readonly resolvedDidDocs?;
30
+ private readonly cryptoHelper?;
31
+ private readonly defaultPurpose;
32
+ constructor(options?: SmartTokenManagerOptions);
33
+ private newId;
34
+ /**
35
+ * Checks if a token is expired.
36
+ * @param token The token to check.
37
+ * @returns True if the token is expired, false otherwise.
38
+ */
39
+ private isTokenExpired;
40
+ /**
41
+ * Checks if a token's scopes cover all the required scopes.
42
+ * @param tokenScopes The scopes available in the token.
43
+ * @param requiredScopes The scopes needed for the API call.
44
+ * @returns True if all required scopes are present, false otherwise.
45
+ */
46
+ private hasRequiredScopes;
47
+ /**
48
+ * (Placeholder) This function would contain the logic to initiate the
49
+ * SMART-on-FHIR OAuth 2.0 authorization code flow to get a new token.
50
+ */
51
+ /**
52
+ * (Placeholder) This function simulates a real Authorization Server.
53
+ * It now requires both a user's `id_token` and the device's `client_id` (DID)
54
+ * to simulate the `private_key_jwt` client assertion flow.
55
+ */
56
+ private acquireNewToken;
57
+ private resolveDid;
58
+ private acquireNewTokenFromBackend;
59
+ getToken(targetDid: string, requiredScopes: string[], idToken: string, clientId: string): Promise<SmartToken>;
60
+ clearToken(targetDid: string): void;
61
+ clearAllTokens(): void;
62
+ }
@@ -0,0 +1,223 @@
1
+ // Copyright 2025 Antifraud Services Inc. under the Apache License, Version 2.0.
2
+ // File: client-sdk-ts/src/SmartTokenManager.ts
3
+ import { generateServiceId } from 'gdc-common-utils-ts/utils/did';
4
+ import { EndpointKey, ENDPOINT_REGISTRY } from './serviceSelectorRegistry.js';
5
+ /**
6
+ * A concrete implementation of the ISmartTokenManager.
7
+ *
8
+ * This implementation uses a simple in-memory cache. In a real application,
9
+ * this could be backed by secure storage. The token acquisition logic is
10
+ * currently a placeholder and would need to be replaced with a full
11
+ * OIDC/OAuth 2.0 client flow (e.g., using `expo-auth-session`).
12
+ */
13
+ export class SmartTokenManager {
14
+ constructor(options = {}) {
15
+ this.tokenCache = new Map();
16
+ this.mode = options.mode || 'mock';
17
+ this.fetcher = options.fetcher;
18
+ this.resolvedDidDocs = options.resolvedDidDocs;
19
+ this.cryptoHelper = options.cryptoHelper;
20
+ this.defaultPurpose = options.defaultPurpose || 'TREAT';
21
+ }
22
+ newId() {
23
+ var _a, _b;
24
+ // Prefer the SDK's crypto helper (consistent across platforms/tests).
25
+ const fromHelper = (_b = (_a = this.cryptoHelper) === null || _a === void 0 ? void 0 : _a.randomUUID) === null || _b === void 0 ? void 0 : _b.call(_a);
26
+ if (fromHelper)
27
+ return fromHelper;
28
+ // Fallback to the platform implementation.
29
+ const anyCrypto = globalThis.crypto;
30
+ if (typeof (anyCrypto === null || anyCrypto === void 0 ? void 0 : anyCrypto.randomUUID) === 'function')
31
+ return anyCrypto.randomUUID();
32
+ // Hard failure: this SDK requires RFC 4122 UUIDs for DIDComm correlation identifiers.
33
+ throw new Error('[SmartTokenManager] Cannot generate UUID: provide sdkConfig.crypto.randomUUID() or run on a platform with globalThis.crypto.randomUUID().');
34
+ }
35
+ /**
36
+ * Checks if a token is expired.
37
+ * @param token The token to check.
38
+ * @returns True if the token is expired, false otherwise.
39
+ */
40
+ isTokenExpired(token) {
41
+ const now = Math.floor(Date.now() / 1000); // Current time in seconds
42
+ return now >= token.expiresAt;
43
+ }
44
+ /**
45
+ * Checks if a token's scopes cover all the required scopes.
46
+ * @param tokenScopes The scopes available in the token.
47
+ * @param requiredScopes The scopes needed for the API call.
48
+ * @returns True if all required scopes are present, false otherwise.
49
+ */
50
+ hasRequiredScopes(tokenScopes, requiredScopes) {
51
+ const scopeSet = new Set(tokenScopes);
52
+ return requiredScopes.every(scope => scopeSet.has(scope));
53
+ }
54
+ /**
55
+ * (Placeholder) This function would contain the logic to initiate the
56
+ * SMART-on-FHIR OAuth 2.0 authorization code flow to get a new token.
57
+ */
58
+ /**
59
+ * (Placeholder) This function simulates a real Authorization Server.
60
+ * It now requires both a user's `id_token` and the device's `client_id` (DID)
61
+ * to simulate the `private_key_jwt` client assertion flow.
62
+ */
63
+ async acquireNewToken(targetDid, requiredScopes, idToken, // Proof of user identity
64
+ clientId // Proof of device identity (used to sign the assertion)
65
+ ) {
66
+ if (this.mode === 'backend') {
67
+ if (!this.fetcher) {
68
+ throw new Error('[SmartTokenManager] backend mode requires a fetcher.');
69
+ }
70
+ return this.acquireNewTokenFromBackend(targetDid, requiredScopes, idToken, clientId);
71
+ }
72
+ console.log(`[SmartTokenManager] Simulating Authorization Server for entity '${targetDid}'`);
73
+ // In a real flow, we would use the clientId and a wallet to create a signed JWT assertion.
74
+ // For this mock, we just check that they exist.
75
+ if (!idToken || !clientId) {
76
+ throw new Error("MOCK AUTH SERVER: Both user id_token and device clientId are required.");
77
+ }
78
+ // --- MOCK AUTHORIZATION SERVER LOGIC ---
79
+ const endpointPermissions = {
80
+ 'did:web:api-provider-1.example.com': {
81
+ allowedScopes: ['individual.onboard', 'admin.organization.acceptLicenseOffer']
82
+ },
83
+ 'did:web:health.provider.com': {
84
+ allowedScopes: ['employee.healthcare.getIndexComposition']
85
+ }
86
+ };
87
+ const rules = endpointPermissions[targetDid];
88
+ if (!rules)
89
+ throw new Error(`MOCK AUTH SERVER: Unknown entity DID: ${targetDid}`);
90
+ const isAuthorized = requiredScopes.every(scope => rules.allowedScopes.includes(scope));
91
+ if (!isAuthorized) {
92
+ throw new Error(`MOCK AUTH SERVER: User is not authorized for scopes [${requiredScopes.join(', ')}]`);
93
+ }
94
+ console.log(`[SmartTokenManager] MOCK AUTH SERVER: Granting token for scopes [${requiredScopes.join(', ')}]`);
95
+ const mockToken = {
96
+ token: 'mock-access-token-string-for-testing',
97
+ expiresAt: Math.floor(Date.now() / 1000) + 3600,
98
+ scopes: requiredScopes,
99
+ };
100
+ return Promise.resolve(mockToken);
101
+ }
102
+ async resolveDid(did) {
103
+ if (this.resolvedDidDocs && this.resolvedDidDocs[did])
104
+ return this.resolvedDidDocs[did];
105
+ const fetcher = this.fetcher;
106
+ if (!fetcher)
107
+ throw new Error('[SmartTokenManager] backend mode requires a fetcher to resolve DIDs.');
108
+ const path = did.substring(8).replace(/:/g, '/');
109
+ const url = `https://${path}/.well-known/did.json`;
110
+ const resp = await fetcher(url);
111
+ if (!resp.ok)
112
+ throw new Error(`[SmartTokenManager] Failed to resolve DID document at ${url}.`);
113
+ return resp.json();
114
+ }
115
+ async acquireNewTokenFromBackend(providerDid, requiredScopes, idToken, clientId) {
116
+ var _a, _b, _c, _d;
117
+ const fetcher = this.fetcher;
118
+ if (!fetcher)
119
+ throw new Error('[SmartTokenManager] backend mode requires a fetcher.');
120
+ // Resolve the provider DID document and locate the SMART token endpoint.
121
+ const didDoc = await this.resolveDid(providerDid);
122
+ const selector = Object.assign({}, ENDPOINT_REGISTRY[EndpointKey.GET_SMART_TOKEN]);
123
+ // Sector is required for the service ID; default to "health-care" if the caller didn't encode it in the DID.
124
+ selector.sector = selector.sector || 'health-care';
125
+ const fullServiceId = `${providerDid}${generateServiceId(selector)}`;
126
+ const normalizedSelector = Object.assign(Object.assign({}, selector), { section: (_a = selector.section) === null || _a === void 0 ? void 0 : _a.toLowerCase(), format: (_b = selector.format) === null || _b === void 0 ? void 0 : _b.toLowerCase(), resourceType: (_c = selector.resourceType) === null || _c === void 0 ? void 0 : _c.toLowerCase(), action: selector.action });
127
+ const normalizedFullServiceId = `${providerDid}${generateServiceId(normalizedSelector)}`;
128
+ const service = (_d = didDoc.service) === null || _d === void 0 ? void 0 : _d.find((s) => s.id === fullServiceId || s.id === normalizedFullServiceId);
129
+ if (!(service === null || service === void 0 ? void 0 : service.serviceEndpoint)) {
130
+ throw new Error(`[SmartTokenManager] SMART token service not found in DID doc for ${providerDid} (tried '${fullServiceId}' and '${normalizedFullServiceId}').`);
131
+ }
132
+ const endpointUrl = String(service.serviceEndpoint);
133
+ // Backend expects DIDComm plaintext message with body containing SMART token request data.
134
+ const thid = this.newId();
135
+ const didcomm = {
136
+ jti: this.newId(),
137
+ thid,
138
+ iss: clientId,
139
+ aud: endpointUrl,
140
+ type: 'application/json',
141
+ body: {
142
+ expires_in: 300,
143
+ token_type: 'Bearer',
144
+ sub: clientId,
145
+ purpose: this.defaultPurpose,
146
+ scope: requiredScopes.join(' '),
147
+ },
148
+ };
149
+ const submitResp = await fetcher(endpointUrl, {
150
+ method: 'POST',
151
+ headers: {
152
+ 'content-type': 'application/didcomm-plaintext+json',
153
+ authorization: `Bearer ${idToken}`,
154
+ },
155
+ body: JSON.stringify(didcomm),
156
+ });
157
+ // Sync completion (rare)
158
+ if (submitResp.status === 200) {
159
+ const json = (await submitResp.json().catch(() => ({})));
160
+ const accessToken = json.access_token;
161
+ if (!accessToken)
162
+ throw new Error('[SmartTokenManager] Missing access_token in SMART token response.');
163
+ const expiresIn = Number(json.expires_in || 300);
164
+ return { token: accessToken, expiresAt: Math.floor(Date.now() / 1000) + expiresIn, scopes: requiredScopes };
165
+ }
166
+ if (submitResp.status !== 202) {
167
+ const text = await submitResp.text().catch(() => '');
168
+ throw new Error(`[SmartTokenManager] SMART token request failed (${submitResp.status}): ${text || submitResp.statusText}`);
169
+ }
170
+ const location = submitResp.headers.get('location');
171
+ if (!location)
172
+ throw new Error('[SmartTokenManager] Missing Location header for SMART token polling.');
173
+ const pollUrl = new URL(location).toString();
174
+ // Poll async result
175
+ for (let i = 0; i < 50; i++) {
176
+ const pollResp = await fetcher(pollUrl, {
177
+ method: 'POST',
178
+ headers: { 'content-type': 'application/json' },
179
+ body: JSON.stringify({ thid }),
180
+ });
181
+ if (pollResp.status === 202) {
182
+ await new Promise((r) => setTimeout(r, 100));
183
+ continue;
184
+ }
185
+ const json = (await pollResp.json().catch(() => ({})));
186
+ if (!pollResp.ok) {
187
+ throw new Error(`[SmartTokenManager] SMART token polling failed (${pollResp.status}).`);
188
+ }
189
+ const accessToken = json.access_token;
190
+ if (!accessToken)
191
+ throw new Error('[SmartTokenManager] Missing access_token in SMART token poll response.');
192
+ const expiresIn = Number(json.expires_in || 300);
193
+ return { token: accessToken, expiresAt: Math.floor(Date.now() / 1000) + expiresIn, scopes: requiredScopes };
194
+ }
195
+ throw new Error('[SmartTokenManager] SMART token polling timed out.');
196
+ }
197
+ async getToken(targetDid, requiredScopes, idToken, clientId) {
198
+ const scopeKey = requiredScopes.slice().sort().join(' ');
199
+ const cacheKey = `${targetDid}|${scopeKey}`;
200
+ const cachedToken = this.tokenCache.get(cacheKey);
201
+ if (cachedToken) {
202
+ if (!this.isTokenExpired(cachedToken) && this.hasRequiredScopes(cachedToken.scopes, requiredScopes)) {
203
+ return cachedToken;
204
+ }
205
+ }
206
+ const newToken = await this.acquireNewToken(targetDid, requiredScopes, idToken, clientId);
207
+ this.tokenCache.set(cacheKey, newToken);
208
+ return newToken;
209
+ }
210
+ clearToken(targetDid) {
211
+ const prefix = `${targetDid}|`;
212
+ for (const key of this.tokenCache.keys()) {
213
+ if (key.startsWith(prefix)) {
214
+ this.tokenCache.delete(key);
215
+ }
216
+ }
217
+ console.log(`[SmartTokenManager] Cleared token for entity '${targetDid}'.`);
218
+ }
219
+ clearAllTokens() {
220
+ this.tokenCache.clear();
221
+ console.log("[SmartTokenManager] All cached tokens have been cleared.");
222
+ }
223
+ }
@@ -0,0 +1,39 @@
1
+ import { VerifiableCredentialV2 } from "gdc-common-utils-ts/models/verifiable-credential";
2
+ import { ICryptography } from "gdc-common-utils-ts/interfaces/ICryptography";
3
+ import { IVerifier, VerifiablePresentation } from "./interfaces/ITrustRegistry";
4
+ /**
5
+ * A service that verifies credentials by validating the entire chain of trust,
6
+ * starting from a single, bundled, hardcoded root public key.
7
+ */
8
+ export declare class VerifierService implements IVerifier {
9
+ private cryptographyService;
10
+ private rootGoverningPublicKey;
11
+ private fetcher;
12
+ private icaCache;
13
+ constructor(cryptographyService: ICryptography, rootGoverningKeyPub: string, fetcher: typeof fetch);
14
+ /**
15
+ * Verifies an Assurance VC by validating its chain of trust.
16
+ * 1. Fetches the credential of the Intermediate CA (ICA) that issued the VC.
17
+ * 2. Verifies the ICA's credential against the hardcoded Root CA public key.
18
+ * 3. Caches the ICA's public key upon successful verification.
19
+ * 4. Verifies the original Assurance VC using the trusted ICA's public key.
20
+ */
21
+ verifyCredential(credential: VerifiableCredentialV2): Promise<boolean>;
22
+ /**
23
+ * A generic, offline signature verification function.
24
+ */
25
+ private verifySignature;
26
+ /**
27
+ * Fetches a credential from a /.well-known/self-description.json endpoint.
28
+ */
29
+ private fetchCredential;
30
+ /**
31
+ * Resolves a DID document. This is kept private as it's a utility for the trust chain, not the primary verification method.
32
+ */
33
+ private resolveDid;
34
+ private didToUrl;
35
+ /**
36
+ * Verifies a Verifiable Presentation. (Placeholder)
37
+ */
38
+ verifyPresentation(vp: VerifiablePresentation): Promise<boolean>;
39
+ }