Skip to content
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-792 Add events service v2 in agreement-platformstate-writer #987

Merged
merged 520 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
520 commits
Select commit Hold shift + click to select a range
bb0ee8d
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r Sep 24, 2024
1860616
Refactor tables setup
taglioni-r Sep 24, 2024
f6e9a08
Update model
taglioni-r Sep 24, 2024
5dbf0bd
Update platform-states table
taglioni-r Sep 24, 2024
3d9664b
Fix
taglioni-r Sep 24, 2024
4f9904a
Update token-generation-states table
taglioni-r Sep 24, 2024
abc158a
Update aws config
taglioni-r Sep 24, 2024
8b6db83
Rename descriptorStateToItemState function
shuyec Sep 24, 2024
3d12bff
Update key types usage
taglioni-r Sep 24, 2024
fda73c2
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r Sep 24, 2024
7a3fc3e
Merge branch 'IMN-798_catalog-platformstate-writer-v2' of https://git…
taglioni-r Sep 24, 2024
6ad6e6f
Fix
taglioni-r Sep 24, 2024
b9b3c4b
Fix test split
taglioni-r Sep 24, 2024
80fd523
Remove describe utils in test file
shuyec Sep 24, 2024
2061be8
Merge branch 'IMN-798_catalog-platformstate-writer-v2' of https://git…
shuyec Sep 24, 2024
ddd4bdc
Minor fix
taglioni-r Sep 24, 2024
8e58388
Fix test structure
taglioni-r Sep 24, 2024
ab04510
Fix tests
taglioni-r Sep 24, 2024
3e3769f
Fix
taglioni-r Sep 24, 2024
daddb4b
Improve tests
taglioni-r Sep 24, 2024
c875827
Refactor
taglioni-r Sep 24, 2024
b2fe9a8
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r Sep 24, 2024
0b27fbe
Refactor test
taglioni-r Sep 24, 2024
d8a6f37
Rename test file for events V2
shuyec Sep 24, 2024
3d8d605
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r Sep 24, 2024
4c4d753
Fix typo
shuyec Sep 24, 2024
609b392
Fix
taglioni-r Sep 24, 2024
0f51a67
Update tests
taglioni-r Sep 24, 2024
ca4eac5
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r Sep 24, 2024
b0a0be9
Remove api spec
taglioni-r Sep 24, 2024
1b8b684
Refactor
taglioni-r Sep 24, 2024
0a046dc
Remove comment
taglioni-r Sep 24, 2024
b39d50f
Remove commented code
taglioni-r Sep 24, 2024
2780594
Fix comments
taglioni-r Sep 24, 2024
4bfcfd7
Revert string literal
taglioni-r Sep 24, 2024
6c445ed
Add env var
taglioni-r Sep 24, 2024
6917d52
WIP, broken commit
Carminepo2 Sep 24, 2024
09e27ea
Fix types
Carminepo2 Sep 25, 2024
1bbe00c
Revert "Fix types"
taglioni-r Sep 25, 2024
2b59066
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r Sep 25, 2024
ebb6db9
Revert "WIP, broken commit"
taglioni-r Sep 25, 2024
c745838
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r Sep 25, 2024
ee86ce3
Merge branch 'IMN-522_client-assertion-validation' into IMN-790_agree…
taglioni-r Sep 25, 2024
9ae27a7
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Sep 25, 2024
0cd01be
Refactor test setup
taglioni-r Sep 25, 2024
9aba0d8
Refactor test split
taglioni-r Sep 25, 2024
84575f2
Fix test
taglioni-r Sep 25, 2024
260f2de
Refactor
taglioni-r Sep 25, 2024
3b5beae
Fix env
taglioni-r Sep 25, 2024
f05c1c7
Fix model
taglioni-r Sep 25, 2024
386639f
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r Sep 25, 2024
460fc94
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r Sep 25, 2024
f0a2a87
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r Sep 25, 2024
12cc203
Merge branch 'IMN-522_client-assertion-validation' into IMN-790_agree…
taglioni-r Sep 25, 2024
97b39d3
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Sep 25, 2024
d1a6344
Remove comment
taglioni-r Sep 25, 2024
1a0877a
Fix import
taglioni-r Sep 25, 2024
905aa06
Fix agreementDescriptorId type
shuyec Sep 25, 2024
b2810da
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
shuyec Sep 25, 2024
03426ba
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
shuyec Sep 25, 2024
ed4cb24
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
shuyec Sep 25, 2024
b6687e3
Merge branch 'IMN-522_client-assertion-validation' into IMN-790_agree…
taglioni-r Sep 25, 2024
19efc7e
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Sep 25, 2024
c3f442d
Update tables setup
taglioni-r Sep 25, 2024
121fdb8
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r Sep 25, 2024
fbb1c7c
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r Sep 25, 2024
a4b4be6
Merge branch 'IMN-522_client-assertion-validation' into IMN-790_agree…
taglioni-r Sep 25, 2024
1215e29
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Sep 25, 2024
4607d2c
Fix
taglioni-r Sep 25, 2024
99355d9
Fix util
taglioni-r Sep 25, 2024
dfce359
Fix
taglioni-r Sep 25, 2024
a6aac62
Update tests
taglioni-r Sep 25, 2024
58005a7
Fix test util
taglioni-r Sep 25, 2024
268ddb3
Fix
taglioni-r Sep 25, 2024
c41382a
Add comment
taglioni-r Sep 25, 2024
b492bcf
Merge branch 'feature/IMN-517_authorization-server' into IMN-796_cata…
taglioni-r Sep 26, 2024
0ddcd8e
Move tables definition
taglioni-r Sep 26, 2024
c5ea4c1
Update test utils
taglioni-r Sep 26, 2024
5acb0f4
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r Sep 26, 2024
a38d762
Remove unused error
taglioni-r Sep 26, 2024
ad1dac8
Fix digest type
taglioni-r Sep 26, 2024
fcdb6c0
Fix types in validation request
taglioni-r Sep 26, 2024
4a5c9d6
Remove comments
taglioni-r Sep 26, 2024
ac9b00f
Fix validateSub
taglioni-r Sep 26, 2024
74b2612
Fix check on digest
taglioni-r Sep 26, 2024
1a394e4
Partial revert
taglioni-r Sep 26, 2024
0609f35
Fix digest errors
taglioni-r Sep 26, 2024
b37c400
Remove comment
taglioni-r Sep 26, 2024
7c4e32c
Fix check on strings
taglioni-r Sep 26, 2024
92972b5
Fix checks
taglioni-r Sep 26, 2024
a02f448
Renaming
taglioni-r Sep 26, 2024
207b048
Remove digest from mock
taglioni-r Sep 26, 2024
8edfd7f
Add tests
taglioni-r Sep 26, 2024
d4662d4
Update kid regex
taglioni-r Sep 27, 2024
ea45031
Add type checks
taglioni-r Sep 27, 2024
8e84a58
Add comment
taglioni-r Sep 27, 2024
58dd973
Add tests
taglioni-r Sep 27, 2024
2896889
Merge similar tests
taglioni-r Sep 27, 2024
263e59c
Update test title
taglioni-r Sep 27, 2024
f369a39
Renaming
taglioni-r Sep 27, 2024
20e5711
Renaming
taglioni-r Sep 27, 2024
98a5387
Renaming
taglioni-r Sep 27, 2024
0e24d73
Improve error
taglioni-r Sep 27, 2024
db141fe
Update error message
taglioni-r Sep 27, 2024
ba8178b
Update signature errors
taglioni-r Sep 27, 2024
294c349
Refactor branded ids
taglioni-r Sep 27, 2024
ce476f0
Fix import
taglioni-r Sep 27, 2024
7d9ca9c
Fix typos
shuyec Sep 27, 2024
c032bcd
Fix GSI names
taglioni-r Sep 27, 2024
28402dc
Update aws region
taglioni-r Sep 27, 2024
86f08e3
Update aws region
taglioni-r Sep 27, 2024
fa46fd7
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r Sep 27, 2024
d5a28bd
Refactor
taglioni-r Sep 27, 2024
7040666
Merge branch 'IMN-798_catalog-platformstate-writer-v2' of https://git…
taglioni-r Sep 27, 2024
7a84286
Fix GSI name
taglioni-r Sep 27, 2024
149a7ec
Remove commented code
taglioni-r Sep 27, 2024
178296c
Fix GSI names
taglioni-r Sep 27, 2024
ccc27d2
Minor improvement
taglioni-r Sep 27, 2024
fd81ebb
Fix mock
taglioni-r Sep 27, 2024
44cc824
Rename tests
taglioni-r Sep 27, 2024
df2b57b
Update aws region
taglioni-r Sep 27, 2024
6dc781a
Update descriptor audience
taglioni-r Sep 27, 2024
3015935
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r Sep 30, 2024
aa2cbfa
Fix
taglioni-r Sep 30, 2024
b52c801
Refactor
taglioni-r Sep 30, 2024
cc0ea48
Rename tests
taglioni-r Sep 30, 2024
f76e677
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r Sep 30, 2024
97fb884
Refactor
taglioni-r Sep 30, 2024
d84473f
Refactor
taglioni-r Sep 30, 2024
b7467cd
Remove types check
taglioni-r Sep 30, 2024
33b1014
Add check
taglioni-r Sep 30, 2024
ca6b288
Add test
taglioni-r Sep 30, 2024
f2192dd
Merge branch 'IMN-522_client-assertion-validation' into IMN-790_agree…
taglioni-r Sep 30, 2024
8c20ee6
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Sep 30, 2024
38a77a9
Fix
taglioni-r Sep 30, 2024
6326944
Fix
taglioni-r Sep 30, 2024
22bdaff
Fix GSI name
taglioni-r Sep 30, 2024
aeffad7
Fix
taglioni-r Sep 30, 2024
cee7db9
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r Oct 1, 2024
3122d67
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r Oct 1, 2024
2621cfe
Merge branch 'IMN-522_client-assertion-validation' into IMN-790_agree…
taglioni-r Oct 1, 2024
8a7f4ea
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 1, 2024
0cfd319
Fix
taglioni-r Oct 1, 2024
abf77f0
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r Oct 1, 2024
72df606
Merge branch 'IMN-522_client-assertion-validation' into IMN-790_agree…
taglioni-r Oct 1, 2024
73b5a7b
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 1, 2024
d14718f
Renaming
taglioni-r Oct 1, 2024
4e3b338
Remove env vars
taglioni-r Oct 1, 2024
865c4c8
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r Oct 1, 2024
6135980
Fix
taglioni-r Oct 1, 2024
bac370e
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r Oct 1, 2024
e6bbca3
Fix
taglioni-r Oct 1, 2024
6c3d128
Fix
taglioni-r Oct 1, 2024
cc1dccd
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r Oct 1, 2024
f4e3ca0
Remove not needed params
taglioni-r Oct 1, 2024
6b2643e
Rename container
taglioni-r Oct 1, 2024
573ed39
Refactor
taglioni-r Oct 1, 2024
5adc54b
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r Oct 1, 2024
ba7233f
Fix import
taglioni-r Oct 1, 2024
0e8f1b5
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r Oct 1, 2024
f5376ce
Refactor
taglioni-r Oct 1, 2024
c191fd8
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r Oct 1, 2024
2078571
Update error
taglioni-r Oct 1, 2024
497ce62
Improve test
taglioni-r Oct 1, 2024
a0bfaa8
Merge branch 'IMN-522_client-assertion-validation' into IMN-790_agree…
taglioni-r Oct 1, 2024
82ca754
Fix
taglioni-r Oct 1, 2024
dc93027
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 1, 2024
b71eec3
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r Oct 1, 2024
f57b13f
Fix
taglioni-r Oct 1, 2024
6353335
Fix
taglioni-r Oct 1, 2024
c23596a
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r Oct 1, 2024
efc1408
Merge branch 'IMN-522_client-assertion-validation' into IMN-790_agree…
taglioni-r Oct 1, 2024
f6044eb
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 1, 2024
d08535a
Fix
taglioni-r Oct 1, 2024
cca2121
Fix
taglioni-r Oct 1, 2024
5f06c56
Fix
taglioni-r Oct 1, 2024
6ea4bed
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 1, 2024
6f31a3f
Fix
taglioni-r Oct 1, 2024
c1e3bc8
Add test
taglioni-r Oct 2, 2024
5f2337b
Add tests
taglioni-r Oct 2, 2024
0e9258b
Refactor
taglioni-r Oct 2, 2024
db891b9
Add tests
taglioni-r Oct 2, 2024
132b4b7
Refactor
taglioni-r Oct 2, 2024
9d29955
Refactor
taglioni-r Oct 3, 2024
686aa59
Adjust key utils
taglioni-r Oct 3, 2024
059e489
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r Oct 3, 2024
f5dbec0
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r Oct 3, 2024
f6cb113
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r Oct 3, 2024
01d014d
Merge branch 'IMN-522_client-assertion-validation' into IMN-790_agree…
taglioni-r Oct 3, 2024
f62d23d
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 3, 2024
5710920
Merge branch 'main' into IMN-790_agreement-platform-state-writer-scaf…
taglioni-r Oct 4, 2024
cf262b0
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 4, 2024
42be492
Add skip
taglioni-r Oct 7, 2024
d9e8c28
Refactor
taglioni-r Oct 7, 2024
a5c4fb4
Fix
taglioni-r Oct 8, 2024
91e1fb5
Merge branch 'main' into IMN-790_agreement-platform-state-writer-scaf…
taglioni-r Oct 8, 2024
de68f6a
Update env
taglioni-r Oct 8, 2024
a973e8b
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 8, 2024
ec6a35d
Fix tests
taglioni-r Oct 8, 2024
cc0e68c
Fix
taglioni-r Oct 8, 2024
b676cd6
Remove duplicate test
taglioni-r Oct 8, 2024
6500147
Fix import
taglioni-r Oct 8, 2024
a469511
Fix
taglioni-r Oct 8, 2024
b9e3172
Remove utils test placeholder
taglioni-r Oct 8, 2024
1825de9
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 8, 2024
ce83959
Merge branch 'main' into IMN-790_agreement-platform-state-writer-scaf…
taglioni-r Oct 8, 2024
9964cf9
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 8, 2024
42a4b3a
Fix
taglioni-r Oct 8, 2024
3b01b9d
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' of ht…
taglioni-r Oct 8, 2024
9f5b01f
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 8, 2024
2d91410
Renaming
taglioni-r Oct 9, 2024
a523345
Renaming
taglioni-r Oct 9, 2024
93887a0
Renaming
taglioni-r Oct 9, 2024
7ed15fe
Remove not needed dependency
taglioni-r Oct 10, 2024
00573af
Merge branch 'main' into IMN-790_agreement-platform-state-writer-scaf…
taglioni-r Oct 10, 2024
95b5ed2
Merge branch 'main' into IMN-790_agreement-platform-state-writer-scaf…
taglioni-r Oct 11, 2024
7afec29
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 11, 2024
2ff3ed1
Merge branch 'main' into IMN-790_agreement-platform-state-writer-scaf…
taglioni-r Oct 11, 2024
5a1145f
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 11, 2024
2589132
Merge branch 'main' into IMN-790_agreement-platform-state-writer-scaf…
taglioni-r Oct 16, 2024
e899bcc
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 16, 2024
1dc7860
Merge branch 'main' into IMN-790_agreement-platform-state-writer-scaf…
taglioni-r Oct 21, 2024
5582cda
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 21, 2024
fa88179
Renaming
taglioni-r Oct 24, 2024
26a3a49
Remove eslint-disable
taglioni-r Oct 24, 2024
753e744
Fix renaming
taglioni-r Oct 24, 2024
bf83ece
Improve tests
taglioni-r Oct 24, 2024
d60ef78
Merge branch 'main' into IMN-790_agreement-platform-state-writer-scaf…
taglioni-r Oct 24, 2024
e524e25
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 24, 2024
83ab8ad
Fix correlationId
taglioni-r Oct 24, 2024
ecb91d6
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 24, 2024
e1beee0
Fix types
taglioni-r Oct 24, 2024
00efde9
Merge branch 'IMN-790_agreement-platform-state-writer-scaffold' into …
taglioni-r Oct 24, 2024
58b6664
Merge branch 'main' into IMN-792_agreement-platform-state-writer-v2
taglioni-r Oct 24, 2024
e0ee921
Fix
taglioni-r Oct 24, 2024
f108830
Merge branch 'main' into IMN-792_agreement-platform-state-writer-v2
taglioni-r Oct 25, 2024
5bd9383
Merge branch 'main' into IMN-792_agreement-platform-state-writer-v2
taglioni-r Oct 25, 2024
b1d2969
Fix renaming
taglioni-r Oct 28, 2024
1bf0575
Fix
taglioni-r Oct 29, 2024
5956cff
Fix
taglioni-r Oct 29, 2024
4b5dc1b
Add check on agreement stamp
taglioni-r Oct 29, 2024
14c9080
Replicate tests for specific events
taglioni-r Oct 29, 2024
2493865
Merge branch 'main' into IMN-792_agreement-platform-state-writer-v2
taglioni-r Oct 30, 2024
294a575
Move catalog entry retrieval
taglioni-r Oct 30, 2024
8bde5b6
Merge branch 'IMN-792_agreement-platform-state-writer-v2' of https://…
taglioni-r Oct 30, 2024
9f06493
Add tests for specific events
taglioni-r Oct 30, 2024
6501e07
Check isLatestAgreement in AgreementActivated
taglioni-r Oct 30, 2024
94c659d
Remove errors in case of missing catalog entry
taglioni-r Oct 30, 2024
28645d2
Rename tests
taglioni-r Oct 30, 2024
e788970
Merge branch 'main' into IMN-792_agreement-platform-state-writer-v2
taglioni-r Oct 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
293 changes: 283 additions & 10 deletions packages/agreement-platformstate-writer/src/consumerServiceV2.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,292 @@
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { AgreementEventEnvelopeV2 } from "pagopa-interop-models";
import {
Agreement,
AgreementEventEnvelopeV2,
AgreementV2,
fromAgreementV2,
genericInternalError,
makeGSIPKConsumerIdEServiceId,
makeGSIPKEServiceIdDescriptorId,
makePlatformStatesAgreementPK,
makePlatformStatesEServiceDescriptorPK,
PlatformStatesAgreementEntry,
PlatformStatesCatalogEntry,
} from "pagopa-interop-models";
import { match } from "ts-pattern";
import {
agreementStateToItemState,
deleteAgreementEntry,
readAgreementEntry,
readCatalogEntry,
updateAgreementStateInPlatformStatesEntry,
updateAgreementStateOnTokenStates,
updateAgreementStateAndDescriptorInfoOnTokenStates,
writeAgreementEntry,
isLatestAgreement,
} from "./utils.js";

export async function handleMessageV2(
message: AgreementEventEnvelopeV2,
_dynamoDBClient: DynamoDBClient
dynamoDBClient: DynamoDBClient
): Promise<void> {
await match(message)
.with({ type: "AgreementActivated" }, async (msg) => {
taglioni-r marked this conversation as resolved.
Show resolved Hide resolved
const agreement = parseAgreement(msg.data.agreement);
const primaryKey = makePlatformStatesAgreementPK(agreement.id);

const existingAgreementEntry = await readAgreementEntry(
primaryKey,
dynamoDBClient
);
const GSIPK_consumerId_eserviceId = makeGSIPKConsumerIdEServiceId({
consumerId: agreement.consumerId,
eserviceId: agreement.eserviceId,
});

if (existingAgreementEntry) {
if (existingAgreementEntry.version > msg.version) {
// Stops processing if the message is older than the agreement entry
return Promise.resolve();
} else {
await updateAgreementStateInPlatformStatesEntry(
dynamoDBClient,
primaryKey,
agreementStateToItemState(agreement.state),
msg.version
);
}
} else {
if (!agreement.stamps.activation) {
throw genericInternalError(
"An activated agreement should have activation stamp"
);
}
const agreementEntry: PlatformStatesAgreementEntry = {
PK: primaryKey,
state: agreementStateToItemState(agreement.state),
version: msg.version,
updatedAt: new Date().toISOString(),
GSIPK_consumerId_eserviceId,
GSISK_agreementTimestamp:
agreement.stamps.activation.when.toISOString(),
agreementDescriptorId: agreement.descriptorId,
};

await writeAgreementEntry(agreementEntry, dynamoDBClient);
}

if (
await isLatestAgreement(
GSIPK_consumerId_eserviceId,
agreement.id,
dynamoDBClient
)
) {
const pkCatalogEntry = makePlatformStatesEServiceDescriptorPK({
eserviceId: agreement.eserviceId,
descriptorId: agreement.descriptorId,
});
const catalogEntry = await readCatalogEntry(
pkCatalogEntry,
dynamoDBClient
);

const GSIPK_eserviceId_descriptorId = makeGSIPKEServiceIdDescriptorId({
eserviceId: agreement.eserviceId,
descriptorId: agreement.descriptorId,
});

// token-generation-states
await updateAgreementStateAndDescriptorInfoOnTokenStates({
GSIPK_consumerId_eserviceId,
agreementState: agreement.state,
dynamoDBClient,
GSIPK_eserviceId_descriptorId,
catalogEntry,
});
}
})
.with(
{ type: "AgreementAdded" },
{ type: "AgreementDeleted" },
{ type: "DraftAgreementUpdated" },
{ type: "AgreementSubmitted" },
{ type: "AgreementActivated" },
{ type: "AgreementUnsuspendedByProducer" },
{ type: "AgreementUnsuspendedByConsumer" },
{ type: "AgreementUnsuspendedByPlatform" },
{ type: "AgreementArchivedByConsumer" },
{ type: "AgreementArchivedByUpgrade" },
{ type: "AgreementUpgraded" },
{ type: "AgreementSuspendedByProducer" },
{ type: "AgreementSuspendedByConsumer" },
{ type: "AgreementSuspendedByPlatform" },
async (msg) => {
const agreement = parseAgreement(msg.data.agreement);
const primaryKey = makePlatformStatesAgreementPK(agreement.id);
const agreementEntry = await readAgreementEntry(
primaryKey,
dynamoDBClient
);

if (!agreementEntry || agreementEntry.version > msg.version) {
return Promise.resolve();
} else {
await updateAgreementStateInPlatformStatesEntry(
dynamoDBClient,
primaryKey,
agreementStateToItemState(agreement.state),
msg.version
);

const GSIPK_consumerId_eserviceId = makeGSIPKConsumerIdEServiceId({
consumerId: agreement.consumerId,
eserviceId: agreement.eserviceId,
});

if (
await isLatestAgreement(
GSIPK_consumerId_eserviceId,
agreement.id,
dynamoDBClient
)
) {
// token-generation-states only if agreement is the latest

await updateAgreementStateOnTokenStates({
GSIPK_consumerId_eserviceId,
agreementState: agreement.state,
dynamoDBClient,
});
}
}
}
)
.with({ type: "AgreementUpgraded" }, async (msg) => {
const agreement = parseAgreement(msg.data.agreement);
const primaryKey = makePlatformStatesAgreementPK(agreement.id);
const agreementEntry = await readAgreementEntry(
primaryKey,
dynamoDBClient
);

const pkCatalogEntry = makePlatformStatesEServiceDescriptorPK({
eserviceId: agreement.eserviceId,
descriptorId: agreement.descriptorId,
});

const GSIPK_consumerId_eserviceId = makeGSIPKConsumerIdEServiceId({
consumerId: agreement.consumerId,
eserviceId: agreement.eserviceId,
});

if (agreementEntry) {
if (agreementEntry.version > msg.version) {
return Promise.resolve();
} else {
await updateAgreementStateInPlatformStatesEntry(
dynamoDBClient,
primaryKey,
agreementStateToItemState(agreement.state),
msg.version
);
}
} else {
if (!agreement.stamps.activation) {
throw genericInternalError(
"An activated agreement should have activation stamp"
);
}
const newAgreementEntry: PlatformStatesAgreementEntry = {
PK: primaryKey,
state: agreementStateToItemState(agreement.state),
version: msg.version,
updatedAt: new Date().toISOString(),
GSIPK_consumerId_eserviceId,
GSISK_agreementTimestamp:
agreement.stamps.activation.when.toISOString(),
agreementDescriptorId: agreement.descriptorId,
};

await writeAgreementEntry(newAgreementEntry, dynamoDBClient);
}

const updateLatestAgreementOnTokenStates = async (
catalogEntry: PlatformStatesCatalogEntry | undefined
): Promise<void> => {
if (
await isLatestAgreement(
GSIPK_consumerId_eserviceId,
agreement.id,
dynamoDBClient
)
) {
// token-generation-states only if agreement is the latest
const GSIPK_eserviceId_descriptorId = makeGSIPKEServiceIdDescriptorId(
{
eserviceId: agreement.eserviceId,
descriptorId: agreement.descriptorId,
}
);

await updateAgreementStateAndDescriptorInfoOnTokenStates({
GSIPK_consumerId_eserviceId,
agreementState: agreement.state,
dynamoDBClient,
GSIPK_eserviceId_descriptorId,
catalogEntry,
});
}
};

const catalogEntry = await readCatalogEntry(
pkCatalogEntry,
dynamoDBClient
);

await updateLatestAgreementOnTokenStates(catalogEntry);

const updatedCatalogEntry = await readCatalogEntry(
pkCatalogEntry,
dynamoDBClient
);

if (
updatedCatalogEntry &&
(!catalogEntry || updatedCatalogEntry.state !== catalogEntry.state)
) {
await updateLatestAgreementOnTokenStates(updatedCatalogEntry);
}
})
.with({ type: "AgreementArchivedByUpgrade" }, async (msg) => {
const agreement = parseAgreement(msg.data.agreement);
const pk = makePlatformStatesAgreementPK(agreement.id);
await deleteAgreementEntry(pk, dynamoDBClient);
})
.with({ type: "AgreementArchivedByConsumer" }, async (msg) => {
const agreement = parseAgreement(msg.data.agreement);

const primaryKey = makePlatformStatesAgreementPK(agreement.id);
const GSIPK_consumerId_eserviceId = makeGSIPKConsumerIdEServiceId({
consumerId: agreement.consumerId,
eserviceId: agreement.eserviceId,
});

if (
await isLatestAgreement(
GSIPK_consumerId_eserviceId,
agreement.id,
dynamoDBClient
)
) {
// token-generation-states only if agreement is the latest

await updateAgreementStateOnTokenStates({
GSIPK_consumerId_eserviceId,
agreementState: agreement.state,
dynamoDBClient,
});
}

await deleteAgreementEntry(primaryKey, dynamoDBClient);
})
.with(
{ type: "AgreementAdded" },
{ type: "AgreementDeleted" },
{ type: "DraftAgreementUpdated" },
{ type: "AgreementSubmitted" },
{ type: "AgreementRejected" },
{ type: "AgreementConsumerDocumentAdded" },
{ type: "AgreementConsumerDocumentRemoved" },
Expand All @@ -31,3 +296,11 @@ export async function handleMessageV2(
)
.exhaustive();
}

const parseAgreement = (agreementV2: AgreementV2 | undefined): Agreement => {
if (!agreementV2) {
throw genericInternalError(`Agreement not found in message data`);
}

return fromAgreementV2(agreementV2);
};
Loading