-
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-799 Add scaffold for purpose-platformstate-writer #969
Merged
Merged
Changes from all commits
Commits
Show all changes
435 commits
Select commit
Hold shift + click to select a range
72a6177
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r 5312b34
Draft
taglioni-r 9c9bf27
Refactor tables setup
taglioni-r 6fa4866
Add pagination
shuyec ba70501
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
shuyec 135b036
WIP: add errors
shuyec ecc1093
Update package imports
shuyec 1eb3762
Draft
taglioni-r a26f95d
WIP: add errors
shuyec e22b041
Update errors
taglioni-r b34ed35
Update utils
taglioni-r 3c5ad7c
Draft test
taglioni-r 02eeeb4
Add placeholders for tests
taglioni-r 8562a57
Add type
taglioni-r 060e2b7
Refactor
taglioni-r 43d252a
Update tests
taglioni-r d09d7a2
Update comment
taglioni-r 3bf72b3
Fix errors data
shuyec facb19c
Refactor
taglioni-r 331b6b1
Merge branch 'IMN-522_client-assertion-validation' of https://github.…
taglioni-r 59f0aa5
Update comment
taglioni-r c1c4c3e
Fix checks
taglioni-r b72c5dc
Update test utils
taglioni-r 9ba64f6
Draft tests
taglioni-r feddfe6
Add errors
shuyec 659d4d1
Fix algorithm error
shuyec 8f774eb
Refactor validateSub
taglioni-r 3991d66
Fix mock
taglioni-r c97619f
Update tests
taglioni-r 5a49356
Remove printed errors
taglioni-r b12a6ea
Add errors
shuyec 2060029
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r e2d2de3
Fix tests
shuyec c73ddf5
Merge branch 'IMN-522_client-assertion-validation' of https://github.…
shuyec 0105452
Improvements
shuyec 98784fc
Improvements
shuyec 04c7aa4
Fix
taglioni-r 762d65b
Fix import
taglioni-r 8ea2212
Refactor
taglioni-r 2fa65e0
Add check
taglioni-r 1f8aa0e
Fix test
taglioni-r 4784b7c
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r c3814e1
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r edcfd79
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r 9a19717
Fix
taglioni-r 6a08e96
Merge branch 'IMN-522_client-assertion-validation' of https://github.…
taglioni-r d212b09
Refactor
taglioni-r e2e50a3
Add tests
taglioni-r 8b16304
Remove comment
taglioni-r 4a44eb0
Refactor
taglioni-r 56e1140
Add purpose-platformstate-writer scaffold
shuyec bb2b9d4
Update pnpm-lock.yaml
shuyec 8519e60
Refactor
taglioni-r 9a72065
Add util tests
taglioni-r f4e37aa
Add test
taglioni-r 7a8205f
Fix
taglioni-r 5f62de0
Remove hardcoded string
taglioni-r 7788383
Update comments
taglioni-r c27e3ad
Fix
taglioni-r ba9609f
Refactor
taglioni-r f9ba9db
Refactor
taglioni-r 9bdea36
Renaming
taglioni-r 7d5e486
Refactor
taglioni-r 519870b
Fix tests
taglioni-r bf36128
Refactor
taglioni-r d8a2dcc
Comment function
taglioni-r 7724295
Fix GSIPK_agreementTimestamp typo
shuyec 97872cd
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
shuyec db0de47
Revert "Fix GSIPK_agreementTimestamp typo"
shuyec fd04e3b
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
shuyec ab92c54
Remove unused line
taglioni-r 2ed47eb
Refactor
taglioni-r bb0ee8d
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r 1860616
Refactor tables setup
taglioni-r f6e9a08
Update model
taglioni-r 5dbf0bd
Update platform-states table
taglioni-r 3d9664b
Fix
taglioni-r 4f9904a
Update token-generation-states table
taglioni-r abc158a
Update aws config
taglioni-r 8b6db83
Rename descriptorStateToItemState function
shuyec 3d12bff
Update key types usage
taglioni-r fda73c2
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r 7a3fc3e
Merge branch 'IMN-798_catalog-platformstate-writer-v2' of https://git…
taglioni-r 6ad6e6f
Fix
taglioni-r b9b3c4b
Fix test split
taglioni-r 80fd523
Remove describe utils in test file
shuyec 2061be8
Merge branch 'IMN-798_catalog-platformstate-writer-v2' of https://git…
shuyec ddd4bdc
Minor fix
taglioni-r 8e58388
Fix test structure
taglioni-r ab04510
Fix tests
taglioni-r 3e3769f
Fix
taglioni-r daddb4b
Improve tests
taglioni-r c875827
Refactor
taglioni-r b2fe9a8
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r 0b27fbe
Refactor test
taglioni-r d8a6f37
Rename test file for events V2
shuyec 3d8d605
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r 4c4d753
Fix typo
shuyec 609b392
Fix
taglioni-r 0f51a67
Update tests
taglioni-r ca4eac5
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r b0a0be9
Remove api spec
taglioni-r 1b8b684
Refactor
taglioni-r 0a046dc
Remove comment
taglioni-r b39d50f
Remove commented code
taglioni-r 2780594
Fix comments
taglioni-r 4bfcfd7
Revert string literal
taglioni-r 6c445ed
Add env var
taglioni-r a568d93
Merge branch 'IMN-522_client-assertion-validation' into IMN_799-purpo…
shuyec 6917d52
WIP, broken commit
Carminepo2 09e27ea
Fix types
Carminepo2 1bbe00c
Revert "Fix types"
taglioni-r 2b59066
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r ebb6db9
Revert "WIP, broken commit"
taglioni-r c745838
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r f05c1c7
Fix model
taglioni-r 386639f
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r 460fc94
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r f0a2a87
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r 272e788
Merge branch 'IMN-522_client-assertion-validation' into IMN_799-purpo…
shuyec 905aa06
Fix agreementDescriptorId type
shuyec b2810da
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
shuyec 03426ba
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
shuyec ed4cb24
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
shuyec 5cbba53
Merge branch 'IMN-522_client-assertion-validation' into IMN_799-purpo…
shuyec c3f442d
Update tables setup
taglioni-r 121fdb8
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r fbb1c7c
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r 2d86058
Merge branch 'IMN-522_client-assertion-validation' into IMN_799-purpo…
shuyec b492bcf
Merge branch 'feature/IMN-517_authorization-server' into IMN-796_cata…
taglioni-r 0ddcd8e
Move tables definition
taglioni-r c5ea4c1
Update test utils
taglioni-r 5acb0f4
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r a38d762
Remove unused error
taglioni-r ad1dac8
Fix digest type
taglioni-r fcdb6c0
Fix types in validation request
taglioni-r 4a5c9d6
Remove comments
taglioni-r ac9b00f
Fix validateSub
taglioni-r 74b2612
Fix check on digest
taglioni-r 1a394e4
Partial revert
taglioni-r 0609f35
Fix digest errors
taglioni-r b37c400
Remove comment
taglioni-r 7c4e32c
Fix check on strings
taglioni-r 92972b5
Fix checks
taglioni-r a02f448
Renaming
taglioni-r 207b048
Remove digest from mock
taglioni-r 8edfd7f
Add tests
taglioni-r d4662d4
Update kid regex
taglioni-r ea45031
Add type checks
taglioni-r 8e84a58
Add comment
taglioni-r 58dd973
Add tests
taglioni-r 2896889
Merge similar tests
taglioni-r 263e59c
Update test title
taglioni-r f369a39
Renaming
taglioni-r 20e5711
Renaming
taglioni-r 98a5387
Renaming
taglioni-r d0d2a8d
Merge branch 'IMN-522_client-assertion-validation' into IMN_799-purpo…
shuyec eb71c07
Update .env + aws.config.local
shuyec 0e24d73
Improve error
taglioni-r db141fe
Update error message
taglioni-r ba8178b
Update signature errors
taglioni-r 294c349
Refactor branded ids
taglioni-r ce476f0
Fix import
taglioni-r 7d9ca9c
Fix typos
shuyec c032bcd
Fix GSI names
taglioni-r 28402dc
Update aws region
taglioni-r 86f08e3
Update aws region
taglioni-r fa46fd7
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r d5a28bd
Refactor
taglioni-r 7040666
Merge branch 'IMN-798_catalog-platformstate-writer-v2' of https://git…
taglioni-r 7a84286
Fix GSI name
taglioni-r 149a7ec
Remove commented code
taglioni-r 178296c
Fix GSI names
taglioni-r ccc27d2
Minor improvement
taglioni-r fd81ebb
Fix mock
taglioni-r 44cc824
Rename tests
taglioni-r df2b57b
Update aws region
taglioni-r 6dc781a
Update descriptor audience
taglioni-r 3015935
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r aa2cbfa
Fix
taglioni-r b52c801
Refactor
taglioni-r cc0ea48
Rename tests
taglioni-r f76e677
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r 97fb884
Refactor
taglioni-r d84473f
Refactor
taglioni-r b7467cd
Remove types check
taglioni-r 33b1014
Add check
taglioni-r ca6b288
Add test
taglioni-r d236a2e
Merge branch 'IMN-522_client-assertion-validation' into IMN_799-purpo…
shuyec 5ee83a1
Remove cleanup
shuyec cee7db9
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r 3122d67
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r 0cfd319
Fix
taglioni-r abf77f0
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r 4e3b338
Remove env vars
taglioni-r 865c4c8
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r 6135980
Fix
taglioni-r bac370e
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r e6bbca3
Fix
taglioni-r 6c3d128
Fix
taglioni-r cc1dccd
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r f4e3ca0
Remove not needed params
taglioni-r 6b2643e
Rename container
taglioni-r 573ed39
Refactor
taglioni-r 5adc54b
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r ba7233f
Fix import
taglioni-r 0e8f1b5
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r f5376ce
Refactor
taglioni-r c191fd8
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r 2078571
Update error
taglioni-r 497ce62
Improve test
taglioni-r b71eec3
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r 6353335
Fix
taglioni-r c23596a
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r 66a4273
Merge branch 'IMN-522_client-assertion-validation' into IMN_799-purpo…
shuyec 147a259
Remove DynamoDBClient parameters
shuyec 11432b7
Add utils
shuyec ba83402
Remove TODO comment
shuyec 686aa59
Adjust key utils
taglioni-r a971a87
Change updates to one page at a time
shuyec 059e489
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r f5dbec0
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r f6cb113
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r 4b25577
Merge branch 'main' into IMN-796_catalog-platform-state-writer-scaffold
taglioni-r ac096fa
Merge branch 'IMN-522_client-assertion-validation' into IMN_799-purpo…
shuyec f46b0af
Clean configs
shuyec 87f632c
Delete utils.ts
shuyec b7788cb
Move utils to next branch
shuyec d91995c
Merge branch 'main' into IMN-796_catalog-platform-state-writer-scaffold
taglioni-r a8fa124
Merge branch 'IMN-796_catalog-platform-state-writer-scaffold' into IM…
taglioni-r 5a36f89
Add typ
taglioni-r 2127e68
Remove todo
taglioni-r e8dc415
Merge branch 'main' into IMN-798_catalog-platformstate-writer-v2
taglioni-r 8229176
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r f2212d9
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
taglioni-r a1d56e8
Merge branch 'IMN-522_client-assertion-validation' into IMN_799-purpo…
shuyec 81b1bc6
Remove todo
shuyec 2baf099
Merge branch 'main' into IMN-798_catalog-platformstate-writer-v2
taglioni-r 7c8da7d
Merge branch 'IMN-798_catalog-platformstate-writer-v2' into IMN-797_c…
taglioni-r ae133dc
Merge branch 'main' into IMN-797_catalog-platformstate-writer-v1
taglioni-r fccb758
Remove sample test
taglioni-r f9b7271
Merge branch 'IMN-797_catalog-platformstate-writer-v1' of https://git…
taglioni-r e215a13
Merge branch 'IMN-797_catalog-platformstate-writer-v1' into IMN-522_c…
shuyec a53eaa2
Merge branch 'IMN-522_client-assertion-validation' into IMN_799-purpo…
shuyec 9d4d998
Merge branch 'main' into IMN_799-purpose-platformstate-writer-scaffold
shuyec 450504b
Create sample.test.ts
shuyec 7bde0f4
Merge branch 'main' into IMN_799-purpose-platformstate-writer-scaffold
shuyec 8a8800f
Remove testcontainers
shuyec c632a0c
Merge branch 'main' into IMN_799-purpose-platformstate-writer-scaffold
shuyec 1fb18cf
Add eof
shuyec 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
LOG_LEVEL=info | ||
|
||
KAFKA_CLIENT_ID="purpose" | ||
KAFKA_GROUP_ID="purpose-group-local" | ||
KAFKA_BROKERS="localhost:9092" | ||
KAFKA_DISABLE_AWS_IAM_AUTH="true" | ||
PURPOSE_TOPIC="event-store.purpose.events" | ||
AWS_CONFIG_FILE=aws.config.local | ||
TOKEN_GENERATION_READMODEL_TABLE_NAME_PLATFORM="platform-states" | ||
TOKEN_GENERATION_READMODEL_TABLE_NAME_TOKEN_GENERATION="token-generation-states" | ||
|
||
AWS_REGION="eu-south-1" |
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,44 @@ | ||
FROM node:20.14.0-slim@sha256:5e8ac65a0231d76a388683d07ca36a9769ab019a85d85169fe28e206f7a3208e as build | ||
|
||
RUN corepack enable | ||
|
||
WORKDIR /app | ||
COPY package.json /app/ | ||
COPY pnpm-lock.yaml /app/ | ||
COPY pnpm-workspace.yaml /app/ | ||
|
||
COPY ./packages/purpose-platformstate-writer/package.json /app/packages/purpose-platformstate-writer/package.json | ||
COPY ./packages/commons/package.json /app/packages/commons/package.json | ||
COPY ./packages/models/package.json /app/packages/models/package.json | ||
COPY ./packages/kafka-iam-auth/package.json /app/packages/kafka-iam-auth/package.json | ||
|
||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile | ||
|
||
COPY tsconfig.json /app/ | ||
COPY turbo.json /app/ | ||
COPY ./packages/purpose-platformstate-writer /app/packages/purpose-platformstate-writer | ||
COPY ./packages/commons /app/packages/commons | ||
COPY ./packages/models /app/packages/models | ||
COPY ./packages/kafka-iam-auth /app/packages/kafka-iam-auth | ||
|
||
RUN pnpm build && \ | ||
rm -rf /app/node_modules/.modules.yaml && \ | ||
rm -rf /app/node_modules/.cache && \ | ||
mkdir /out && \ | ||
cp -a --parents -t /out \ | ||
node_modules packages/purpose-platformstate-writer/node_modules \ | ||
package*.json packages/purpose-platformstate-writer/package*.json \ | ||
packages/commons \ | ||
packages/models \ | ||
packages/kafka-iam-auth \ | ||
packages/purpose-platformstate-writer/dist && \ | ||
find /out -exec touch -h --date=@0 {} \; | ||
|
||
FROM node:20.14.0-slim@sha256:5e8ac65a0231d76a388683d07ca36a9769ab019a85d85169fe28e206f7a3208e as final | ||
|
||
COPY --from=build /out /app | ||
|
||
WORKDIR /app/packages/purpose-platformstate-writer | ||
EXPOSE 3000 | ||
|
||
CMD ["node", "."] |
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,9 @@ | ||
[default] | ||
aws_access_key_id=key | ||
aws_secret_access_key=secret | ||
region=eu-south-1 | ||
services=local | ||
|
||
[services local] | ||
dynamodb= | ||
endpoint_url=http://localhost:8085 |
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,47 @@ | ||
{ | ||
"name": "pagopa-interop-purpose-platformstate-writer", | ||
"private": true, | ||
"version": "1.0.0", | ||
"description": "PagoPA Interoperability purpose consumer service that updates the token-generation-read-model", | ||
"main": "dist", | ||
"type": "module", | ||
"scripts": { | ||
"test": "vitest", | ||
"test:it": "vitest integration", | ||
"lint": "eslint . --ext .ts,.tsx", | ||
"lint:autofix": "eslint . --ext .ts,.tsx --fix", | ||
"format:check": "prettier --check src", | ||
"format:write": "prettier --write src", | ||
"start": "node --loader ts-node/esm -r 'dotenv-flow/config' --watch ./src/index.ts", | ||
"build": "tsc", | ||
"check": "tsc --project tsconfig.check.json" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@pagopa/eslint-config": "3.0.0", | ||
"@types/node": "20.14.6", | ||
"@types/uuid": "9.0.8", | ||
"date-fns": "3.6.0", | ||
"pagopa-interop-commons-test": "workspace:*", | ||
"prettier": "2.8.8", | ||
"ts-node": "10.9.2", | ||
"typescript": "5.4.5", | ||
"uuid": "10.0.0", | ||
"vitest": "1.6.0" | ||
}, | ||
"dependencies": { | ||
"@aws-sdk/client-dynamodb": "3.637.0", | ||
"@aws-sdk/util-dynamodb": "3.637.0", | ||
"@protobuf-ts/runtime": "2.9.4", | ||
"connection-string": "4.4.0", | ||
"dotenv-flow": "4.1.0", | ||
"kafka-iam-auth": "workspace:*", | ||
"kafkajs": "2.2.4", | ||
"pagopa-interop-commons": "workspace:*", | ||
"pagopa-interop-models": "workspace:*", | ||
"ts-pattern": "5.2.0", | ||
"zod": "3.23.8" | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/purpose-platformstate-writer/src/config/config.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,15 @@ | ||
import { | ||
PlatformStateWriterConfig, | ||
PurposeTopicConfig, | ||
} from "pagopa-interop-commons"; | ||
import { z } from "zod"; | ||
|
||
export const PurposePlatformStateWriterConfig = | ||
PlatformStateWriterConfig.and(PurposeTopicConfig); | ||
|
||
export type PurposePlatformStateWriterConfig = z.infer< | ||
typeof PurposePlatformStateWriterConfig | ||
>; | ||
|
||
export const config: PurposePlatformStateWriterConfig = | ||
PurposePlatformStateWriterConfig.parse(process.env); |
25 changes: 25 additions & 0 deletions
25
packages/purpose-platformstate-writer/src/consumerServiceV1.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,25 @@ | ||
import { match } from "ts-pattern"; | ||
import { PurposeEventEnvelopeV1 } from "pagopa-interop-models"; | ||
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; | ||
|
||
export async function handleMessageV1( | ||
message: PurposeEventEnvelopeV1, | ||
_dynamoDBClient: DynamoDBClient | ||
): Promise<void> { | ||
await match(message) | ||
.with( | ||
{ type: "PurposeCreated" }, | ||
{ type: "PurposeVersionCreated" }, | ||
{ type: "PurposeUpdated" }, | ||
{ type: "PurposeVersionActivated" }, | ||
{ type: "PurposeVersionSuspended" }, | ||
{ type: "PurposeVersionArchived" }, | ||
{ type: "PurposeVersionWaitedForApproval" }, | ||
{ type: "PurposeVersionRejected" }, | ||
{ type: "PurposeVersionUpdated" }, | ||
{ type: "PurposeDeleted" }, | ||
{ type: "PurposeVersionDeleted" }, | ||
() => Promise.resolve() | ||
) | ||
.exhaustive(); | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/purpose-platformstate-writer/src/consumerServiceV2.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,32 @@ | ||
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; | ||
import { PurposeEventEnvelopeV2 } from "pagopa-interop-models"; | ||
import { match } from "ts-pattern"; | ||
|
||
export async function handleMessageV2( | ||
message: PurposeEventEnvelopeV2, | ||
_dynamoDBClient: DynamoDBClient | ||
): Promise<void> { | ||
await match(message) | ||
.with( | ||
{ type: "DraftPurposeDeleted" }, | ||
{ type: "WaitingForApprovalPurposeDeleted" }, | ||
{ type: "PurposeAdded" }, | ||
{ type: "DraftPurposeUpdated" }, | ||
{ type: "NewPurposeVersionActivated" }, | ||
{ type: "NewPurposeVersionWaitingForApproval" }, | ||
{ type: "PurposeActivated" }, | ||
{ type: "PurposeArchived" }, | ||
{ type: "PurposeVersionOverQuotaUnsuspended" }, | ||
{ type: "PurposeVersionRejected" }, | ||
{ type: "PurposeVersionSuspendedByConsumer" }, | ||
{ type: "PurposeVersionSuspendedByProducer" }, | ||
{ type: "PurposeVersionUnsuspendedByConsumer" }, | ||
{ type: "PurposeVersionUnsuspendedByProducer" }, | ||
{ type: "PurposeWaitingForApproval" }, | ||
{ type: "WaitingForApprovalPurposeVersionDeleted" }, | ||
{ type: "PurposeVersionActivated" }, | ||
{ type: "PurposeCloned" }, | ||
() => Promise.resolve() | ||
) | ||
.exhaustive(); | ||
} |
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,36 @@ | ||
import { EachMessagePayload } from "kafkajs"; | ||
import { logger, decodeKafkaMessage } from "pagopa-interop-commons"; | ||
import { runConsumer } from "kafka-iam-auth"; | ||
import { PurposeEvent } from "pagopa-interop-models"; | ||
import { match } from "ts-pattern"; | ||
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"; | ||
import { handleMessageV1 } from "./consumerServiceV1.js"; | ||
import { handleMessageV2 } from "./consumerServiceV2.js"; | ||
import { config } from "./config/config.js"; | ||
|
||
const dynamoDBClient = new DynamoDBClient(); | ||
async function processMessage({ | ||
message, | ||
partition, | ||
}: EachMessagePayload): Promise<void> { | ||
const decodedMessage = decodeKafkaMessage(message, PurposeEvent); | ||
|
||
const loggerInstance = logger({ | ||
serviceName: "purpose-platformstate-writer", | ||
eventType: decodedMessage.type, | ||
eventVersion: decodedMessage.event_version, | ||
streamId: decodedMessage.stream_id, | ||
correlationId: decodedMessage.correlation_id, | ||
}); | ||
|
||
await match(decodedMessage) | ||
.with({ event_version: 1 }, (msg) => handleMessageV1(msg, dynamoDBClient)) | ||
.with({ event_version: 2 }, (msg) => handleMessageV2(msg, dynamoDBClient)) | ||
.exhaustive(); | ||
|
||
loggerInstance.info( | ||
`Token-generation read model was updated. Partition number: ${partition}. Offset: ${message.offset}` | ||
); | ||
} | ||
|
||
await runConsumer(config, [config.purposeTopic], processMessage); |
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,128 @@ | ||
import { | ||
DeleteItemCommand, | ||
DeleteItemInput, | ||
DynamoDBClient, | ||
GetItemCommand, | ||
GetItemCommandOutput, | ||
GetItemInput, | ||
PutItemCommand, | ||
PutItemInput, | ||
} from "@aws-sdk/client-dynamodb"; | ||
import { unmarshall } from "@aws-sdk/util-dynamodb"; | ||
import { | ||
genericInternalError, | ||
PlatformStatesCatalogEntry, | ||
PlatformStatesEServiceDescriptorPK, | ||
PlatformStatesPurposeEntry, | ||
PlatformStatesPurposePK, | ||
} from "pagopa-interop-models"; | ||
import { config } from "./config/config.js"; | ||
|
||
export const writePlatformPurposeEntry = async ( | ||
dynamoDBClient: DynamoDBClient, | ||
purposeEntry: PlatformStatesPurposeEntry | ||
): Promise<void> => { | ||
const input: PutItemInput = { | ||
ConditionExpression: "attribute_not_exists(PK)", | ||
Item: { | ||
PK: { | ||
S: purposeEntry.PK, | ||
}, | ||
state: { | ||
S: purposeEntry.state, | ||
}, | ||
purposeVersionId: { | ||
S: purposeEntry.purposeVersionId, | ||
}, | ||
purposeEserviceId: { | ||
S: purposeEntry.purposeEserviceId, | ||
}, | ||
purposeConsumerId: { | ||
S: purposeEntry.purposeConsumerId, | ||
}, | ||
version: { | ||
N: purposeEntry.version.toString(), | ||
}, | ||
updatedAt: { | ||
S: purposeEntry.updatedAt, | ||
}, | ||
}, | ||
TableName: config.tokenGenerationReadModelTableNamePlatform, | ||
}; | ||
const command = new PutItemCommand(input); | ||
await dynamoDBClient.send(command); | ||
}; | ||
|
||
export const readPlatformPurposeEntry = async ( | ||
dynamoDBClient: DynamoDBClient, | ||
primaryKey: PlatformStatesPurposePK | ||
): Promise<PlatformStatesPurposeEntry | undefined> => { | ||
const input: GetItemInput = { | ||
Key: { | ||
PK: { S: primaryKey }, | ||
}, | ||
TableName: config.tokenGenerationReadModelTableNamePlatform, | ||
}; | ||
const command = new GetItemCommand(input); | ||
const data: GetItemCommandOutput = await dynamoDBClient.send(command); | ||
|
||
if (!data.Item) { | ||
return undefined; | ||
} else { | ||
const unmarshalled = unmarshall(data.Item); | ||
const purposeEntry = PlatformStatesPurposeEntry.safeParse(unmarshalled); | ||
|
||
if (!purposeEntry.success) { | ||
throw genericInternalError( | ||
`Unable to parse purpose entry item: result ${JSON.stringify( | ||
purposeEntry | ||
)} - data ${JSON.stringify(data)} ` | ||
); | ||
} | ||
return purposeEntry.data; | ||
} | ||
}; | ||
|
||
export const deletePlatformPurposeEntry = async ( | ||
dynamoDBClient: DynamoDBClient, | ||
primaryKey: PlatformStatesPurposePK | ||
): Promise<void> => { | ||
const input: DeleteItemInput = { | ||
Key: { | ||
PK: { S: primaryKey }, | ||
}, | ||
TableName: config.tokenGenerationReadModelTableNamePlatform, | ||
}; | ||
const command = new DeleteItemCommand(input); | ||
await dynamoDBClient.send(command); | ||
}; | ||
|
||
export const readCatalogEntry = async ( | ||
dynamoDBClient: DynamoDBClient, | ||
primaryKey: PlatformStatesEServiceDescriptorPK | ||
): Promise<PlatformStatesCatalogEntry | undefined> => { | ||
const input: GetItemInput = { | ||
Key: { | ||
PK: { S: primaryKey }, | ||
}, | ||
TableName: config.tokenGenerationReadModelTableNamePlatform, | ||
}; | ||
const command = new GetItemCommand(input); | ||
const data: GetItemCommandOutput = await dynamoDBClient.send(command); | ||
|
||
if (!data.Item) { | ||
return undefined; | ||
} else { | ||
const unmarshalled = unmarshall(data.Item); | ||
const catalogEntry = PlatformStatesCatalogEntry.safeParse(unmarshalled); | ||
|
||
if (!catalogEntry.success) { | ||
throw genericInternalError( | ||
`Unable to parse catalog entry item: result ${JSON.stringify( | ||
catalogEntry | ||
)} - data ${JSON.stringify(data)} ` | ||
); | ||
} | ||
return catalogEntry.data; | ||
} | ||
}; |
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,7 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
describe("sample", () => { | ||
it("test", () => { | ||
expect(1).toBe(1); | ||
}); | ||
}); |
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,4 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": ["."] | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/purpose-platformstate-writer/test/vitestGlobalSetup.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,3 @@ | ||
import { setupTestContainersVitestGlobal } from "pagopa-interop-commons-test/index.js"; | ||
|
||
export default setupTestContainersVitestGlobal(); |
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,7 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"noEmit": true, | ||
}, | ||
"include": ["src", "test"] | ||
} |
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,9 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist" | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
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.
Since there write, read and delete are almost identical to the ones here would it be beneficial to declare these as generics and move to
commons
?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.
Moving to commons is being planned, but I wouldn't turn those into functions with generics, because it doesn't seem a straightforward operation, considering the differences between those entries.