-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IMN-657 GET EService descriptor by ID #712
Merged
Merged
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
a02dc84
Implements get Eservice's descriptor by id
Viktor-K b6d1ce8
Fix assertion on GetEserivcesDescriptorById
Viktor-K af35559
Fix types from API clients package
Viktor-K 56a0277
remove wrong changes
Viktor-K b1ac408
Fix linting
Viktor-K 8f82ffe
Merge branch 'main' into IMN-657-getEserviceDescriptorById
Viktor-K 87effa8
Move converter to properly ApiConverter file
Viktor-K 6b080a5
Fix linting
Viktor-K 107daaa
Create getter help methods in catalog service
Viktor-K 17be40e
Rename converter catalog API converter method
Viktor-K 6006856
Fix var naming
Viktor-K 33b8648
Fix toBffCatalogApiEserviceRiskAnalysis conversion in Bff tuility
Viktor-K 392cb8c
Fix toBffCatalogApiEserviceRiskAnalysis conversion in Bff tuility
Viktor-K 43848ef
uniform tenant client creation
Viktor-K 480d433
Reduce unsafeBrandId usages
Viktor-K 5bb768c
Minor fix rename variable name
Viktor-K dfba69b
Merge branch 'main' into IMN-657-getEserviceDescriptorById
Viktor-K 6429d36
Fix linting
Viktor-K 9cf1835
Merge branch 'main' into IMN-657-getEserviceDescriptorById
Viktor-K 7dc73a2
Refactorize validators and mapper on catalogService
Viktor-K 846effd
move agreement upgredeable veirification in mapper file
Viktor-K 98a7bad
Move getTenant email to mappers
Viktor-K 748d8c6
Add proper type during risk anlysis converter
Viktor-K 9fe126b
Merge branch 'main' into IMN-657-getEserviceDescriptorById
Viktor-K 9e9d46e
fix linting
Viktor-K 3d974f2
Rename BFF validator
Viktor-K 00e0562
Minor Fix : renaming function and vars
Viktor-K 1b30f5a
Update packages/bff/src/model/modelMappingUtils.ts
Viktor-K 28954da
Fix typo
Viktor-K d3d4657
Merge branch 'main' into IMN-657-getEserviceDescriptorById
Viktor-K 5ba6040
Rename const variable
Viktor-K 31c5dcd
IMN-656 get producer eservice detail by ID (#730)
Viktor-K 11026a3
Add operative log
Viktor-K c41d3ec
Merge branch 'main' into IMN-657-getEserviceDescriptorById
Viktor-K File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
219 changes: 219 additions & 0 deletions
219
packages/bff/src/model/api/converters/catalogClientApiConverter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
/* eslint-disable functional/immutable-data */ | ||
/* eslint-disable max-params */ | ||
import { DescriptorWithOnlyAttributes } from "pagopa-interop-agreement-lifecycle"; | ||
import { | ||
agreementApi, | ||
attributeRegistryApi, | ||
bffApi, | ||
catalogApi, | ||
tenantApi, | ||
} from "pagopa-interop-api-clients"; | ||
import { EServiceAttribute, unsafeBrandId } from "pagopa-interop-models"; | ||
import { attributeNotExists } from "../../domain/errors.js"; | ||
import { getTenantEmail, isUpgradable } from "../../modelMappingUtils.js"; | ||
import { catalogApiDescriptorState } from "../apiTypes.js"; | ||
|
||
export function toEserviceCatalogProcessQueryParams( | ||
queryParams: bffApi.BffGetCatalogQueryParam | ||
): catalogApi.GetCatalogQueryParam { | ||
return { | ||
...queryParams, | ||
eservicesIds: [], | ||
name: queryParams.q, | ||
}; | ||
} | ||
|
||
export function toBffCatalogApiEService( | ||
eservice: catalogApi.EService, | ||
producerTenant: tenantApi.Tenant, | ||
hasCertifiedAttributes: boolean, | ||
isRequesterEqProducer: boolean, | ||
activeDescriptor?: catalogApi.EServiceDescriptor, | ||
agreement?: agreementApi.Agreement | ||
): bffApi.CatalogEService { | ||
const partialEnhancedEservice = { | ||
id: eservice.id, | ||
name: eservice.name, | ||
description: eservice.description, | ||
producer: { | ||
id: eservice.producerId, | ||
name: producerTenant.name, | ||
}, | ||
isMine: isRequesterEqProducer, | ||
hasCertifiedAttributes, | ||
}; | ||
|
||
return { | ||
...partialEnhancedEservice, | ||
...(activeDescriptor | ||
? { | ||
activeDescriptor: { | ||
id: activeDescriptor.id, | ||
version: activeDescriptor.version, | ||
audience: activeDescriptor.audience, | ||
state: activeDescriptor.state, | ||
}, | ||
} | ||
: {}), | ||
...(agreement | ||
? { | ||
agreement: { | ||
id: agreement.id, | ||
state: agreement.state, | ||
canBeUpgraded: isUpgradable(eservice, agreement), | ||
}, | ||
} | ||
: {}), | ||
}; | ||
} | ||
|
||
export function toBffCatalogApiDescriptorAttribute( | ||
attributes: attributeRegistryApi.Attribute[], | ||
descriptorAttributes: catalogApi.Attribute[] | ||
): bffApi.DescriptorAttribute[] { | ||
return descriptorAttributes.map((attribute) => { | ||
const foundAttribute = attributes.find((att) => att.id === attribute.id); | ||
if (!foundAttribute) { | ||
throw attributeNotExists(unsafeBrandId(attribute.id)); | ||
} | ||
|
||
return { | ||
id: attribute.id, | ||
name: foundAttribute.name, | ||
description: foundAttribute.description, | ||
explicitAttributeVerification: attribute.explicitAttributeVerification, | ||
}; | ||
}); | ||
} | ||
|
||
export function toBffCatalogApiDescriptorDoc( | ||
document: catalogApi.EServiceDoc | ||
): bffApi.EServiceDoc { | ||
return { | ||
id: document.id, | ||
name: document.name, | ||
contentType: document.contentType, | ||
prettyName: document.prettyName, | ||
}; | ||
} | ||
|
||
export function toBffCatalogApiEserviceRiskAnalysis( | ||
riskAnalysis: catalogApi.EServiceRiskAnalysis | ||
): bffApi.EServiceRiskAnalysis { | ||
const answers: bffApi.RiskAnalysisForm["answers"] = | ||
riskAnalysis.riskAnalysisForm.singleAnswers | ||
.concat( | ||
riskAnalysis.riskAnalysisForm.multiAnswers.flatMap((multiAnswer) => | ||
multiAnswer.values.map((answerValue) => ({ | ||
id: multiAnswer.id, | ||
value: answerValue, | ||
key: multiAnswer.key, | ||
})) | ||
) | ||
) | ||
.reduce((answers: bffApi.RiskAnalysisForm["answers"], answer) => { | ||
const key = answer.key; | ||
if (answers[key] && answer.value) { | ||
answers[key] = [...answers[key], answer.value]; | ||
} else { | ||
answers[key] = []; | ||
} | ||
|
||
return answers; | ||
}, {}); | ||
|
||
const riskAnalysisForm: bffApi.RiskAnalysisForm = { | ||
riskAnalysisId: riskAnalysis.id, | ||
version: riskAnalysis.riskAnalysisForm.version, | ||
answers, | ||
}; | ||
|
||
return { | ||
id: riskAnalysis.id, | ||
name: riskAnalysis.name, | ||
createdAt: riskAnalysis.createdAt, | ||
riskAnalysisForm, | ||
}; | ||
} | ||
|
||
export function toBffCatalogApiProducerDescriptorEService( | ||
eservice: catalogApi.EService, | ||
producer: tenantApi.Tenant | ||
): bffApi.ProducerDescriptorEService { | ||
const producerMail = getTenantEmail(producer); | ||
|
||
const notDraftDecriptors: bffApi.CompactDescriptor[] = | ||
eservice.descriptors.filter( | ||
(d) => d.state !== catalogApiDescriptorState.DRAFT | ||
); | ||
|
||
const draftDescriptor: bffApi.CompactDescriptor | undefined = | ||
eservice.descriptors.find( | ||
(d) => d.state === catalogApiDescriptorState.DRAFT | ||
); | ||
|
||
return { | ||
id: eservice.id, | ||
name: eservice.name, | ||
description: eservice.description, | ||
technology: eservice.technology, | ||
mode: eservice.mode, | ||
mail: producerMail && { | ||
address: producerMail.address, | ||
description: producerMail.description, | ||
}, | ||
draftDescriptor, | ||
riskAnalysis: eservice.riskAnalysis.map( | ||
toBffCatalogApiEserviceRiskAnalysis | ||
), | ||
descriptors: notDraftDecriptors, | ||
}; | ||
} | ||
|
||
export function toEserviceAttribute( | ||
attributes: catalogApi.Attribute[] | ||
): EServiceAttribute[] { | ||
return attributes.map((attribute) => ({ | ||
...attribute, | ||
id: unsafeBrandId(attribute.id), | ||
})); | ||
} | ||
|
||
export function toDescriptorWithOnlyAttributes( | ||
descriptor: catalogApi.EServiceDescriptor | ||
): DescriptorWithOnlyAttributes { | ||
return { | ||
...descriptor, | ||
attributes: { | ||
certified: descriptor.attributes.certified.map(toEserviceAttribute), | ||
declared: descriptor.attributes.declared.map(toEserviceAttribute), | ||
verified: descriptor.attributes.verified.map(toEserviceAttribute), | ||
}, | ||
}; | ||
} | ||
|
||
export function toBffCatalogApiDescriptorAttributes( | ||
attributes: attributeRegistryApi.Attribute[], | ||
descriptor: catalogApi.EServiceDescriptor | ||
): bffApi.DescriptorAttributes { | ||
return { | ||
certified: [ | ||
toBffCatalogApiDescriptorAttribute( | ||
attributes, | ||
descriptor.attributes.certified.flat() | ||
), | ||
], | ||
declared: [ | ||
toBffCatalogApiDescriptorAttribute( | ||
attributes, | ||
descriptor.attributes.declared.flat() | ||
), | ||
], | ||
verified: [ | ||
toBffCatalogApiDescriptorAttribute( | ||
attributes, | ||
descriptor.attributes.verified.flat() | ||
), | ||
], | ||
}; | ||
} |
64 changes: 64 additions & 0 deletions
64
packages/bff/src/model/api/converters/tenantClientApiConverters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { TenantWithOnlyAttributes } from "pagopa-interop-agreement-lifecycle"; | ||
import { tenantApi } from "pagopa-interop-api-clients"; | ||
import { | ||
CertifiedTenantAttribute, | ||
DeclaredTenantAttribute, | ||
TenantAttribute, | ||
VerifiedTenantAttribute, | ||
tenantAttributeType, | ||
unsafeBrandId, | ||
} from "pagopa-interop-models"; | ||
|
||
export function toTenantAttribute( | ||
att: tenantApi.TenantAttribute | ||
): TenantAttribute[] { | ||
const certified: CertifiedTenantAttribute | undefined = att.certified && { | ||
id: unsafeBrandId(att.certified.id), | ||
type: tenantAttributeType.CERTIFIED, | ||
revocationTimestamp: att.certified.revocationTimestamp | ||
? new Date(att.certified.revocationTimestamp) | ||
: undefined, | ||
assignmentTimestamp: new Date(att.certified.assignmentTimestamp), | ||
}; | ||
|
||
const verified: VerifiedTenantAttribute | undefined = att.verified && { | ||
id: unsafeBrandId(att.verified.id), | ||
type: tenantAttributeType.VERIFIED, | ||
assignmentTimestamp: new Date(att.verified.assignmentTimestamp), | ||
verifiedBy: att.verified.verifiedBy.map((v) => ({ | ||
id: v.id, | ||
verificationDate: new Date(v.verificationDate), | ||
expirationDate: v.expirationDate ? new Date(v.expirationDate) : undefined, | ||
extensionDate: v.extensionDate ? new Date(v.extensionDate) : undefined, | ||
})), | ||
revokedBy: att.verified.revokedBy.map((r) => ({ | ||
id: r.id, | ||
verificationDate: new Date(r.verificationDate), | ||
revocationDate: new Date(r.revocationDate), | ||
expirationDate: r.expirationDate ? new Date(r.expirationDate) : undefined, | ||
extensionDate: r.extensionDate ? new Date(r.extensionDate) : undefined, | ||
})), | ||
}; | ||
|
||
const declared: DeclaredTenantAttribute | undefined = att.declared && { | ||
id: unsafeBrandId(att.declared.id), | ||
type: tenantAttributeType.DECLARED, | ||
assignmentTimestamp: new Date(att.declared.assignmentTimestamp), | ||
revocationTimestamp: att.declared.revocationTimestamp | ||
? new Date(att.declared.revocationTimestamp) | ||
: undefined, | ||
}; | ||
|
||
return [certified, verified, declared].filter( | ||
(a): a is TenantAttribute => !!a | ||
); | ||
} | ||
|
||
export function toTenantWithOnlyAttributes( | ||
tenant: tenantApi.Tenant | ||
): TenantWithOnlyAttributes { | ||
return { | ||
...tenant, | ||
attributes: tenant.attributes.map(toTenantAttribute).flat(), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are using runtime resources to change something at type level, I know the performance impact could be negligible but I saw this in a lot of part of the monorepo and I'm wondering if it is worth discussing.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Carminepo2 good point 👍🏻
unfortunately branded type usages requires mapping like this, so we need to choose what we want encourage. Id as string are very error prone when they are function's parameter, branded type is a sort of guard to avoid bugs, meanwhile every time we convert models it's necessary this wrapping...
I suggest to discuss a possible policy offline.