diff --git a/package.json b/package.json index aa1d558..f0c63c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pagopa/interop-outbound-models", - "version": "1.0.6", + "version": "1.0.7", "description": "PagoPA Interoperability outbound models", "main": "dist", "type": "module", diff --git a/proto/v2/eservice/eservice.proto b/proto/v2/eservice/eservice.proto index 1f20184..bd311df 100644 --- a/proto/v2/eservice/eservice.proto +++ b/proto/v2/eservice/eservice.proto @@ -28,6 +28,11 @@ message EServiceAttributesV2 { repeated EServiceAttributeV2 verified = 3; } +message DescriptorRejectionReasonV2 { + string rejectionReason = 1; + int64 rejectedAt = 2; +} + message EServiceDescriptorV2 { string id = 1; int64 version = 2; @@ -47,6 +52,7 @@ message EServiceDescriptorV2 { optional int64 deprecatedAt = 16; optional int64 archivedAt = 17; EServiceAttributesV2 attributes = 18; + repeated DescriptorRejectionReasonV2 rejectedReasons = 19; } message EServiceDocumentV2 { @@ -64,6 +70,7 @@ enum EServiceDescriptorStateV2 { DEPRECATED = 2; SUSPENDED = 3; ARCHIVED = 4; + WAITING_FOR_APPROVAL = 5; } enum EServiceTechnologyV2 { diff --git a/proto/v2/eservice/events.proto b/proto/v2/eservice/events.proto index 0b7c97a..0bceca0 100644 --- a/proto/v2/eservice/events.proto +++ b/proto/v2/eservice/events.proto @@ -102,3 +102,13 @@ message EServiceDescriptorDocumentDeletedV2 { message EServiceDescriptionUpdatedV2 { EServiceV2 eservice = 1; } + +message EServiceDescriptorApprovedV2 { + string descriptorId = 1; + EServiceV2 eservice = 2; +} + +message EServiceDescriptorRejectedV2 { + string descriptorId = 1; + EServiceV2 eservice = 2; +} diff --git a/src/eservice/eventsV2.ts b/src/eservice/eventsV2.ts index b21e571..d556ed7 100644 --- a/src/eservice/eventsV2.ts +++ b/src/eservice/eventsV2.ts @@ -21,6 +21,8 @@ import { EServiceDraftDescriptorUpdatedV2, EServiceDescriptorQuotasUpdatedV2, EServiceDescriptionUpdatedV2, + EServiceDescriptorApprovedV2, + EServiceDescriptorRejectedV2, } from "../gen/v2/eservice/events.js"; export function eServiceEventToBinaryDataV2( @@ -84,6 +86,12 @@ export function eServiceEventToBinaryDataV2( .with({ type: "EServiceDescriptionUpdated" }, ({ data }) => EServiceDescriptionUpdatedV2.toBinary(data) ) + .with({ type: "EServiceDescriptorApproved" }, ({ data }) => + EServiceDescriptorApprovedV2.toBinary(data) + ) + .with({ type: "EServiceDescriptorRejected" }, ({ data }) => + EServiceDescriptorRejectedV2.toBinary(data) + ) .exhaustive(); } @@ -240,6 +248,22 @@ export const EServiceEventV2 = z.discriminatedUnion("type", [ version: z.number(), timestamp: z.coerce.date(), }), + z.object({ + event_version: z.literal(2), + type: z.literal("EServiceDescriptorApproved"), + data: protobufDecoder(EServiceDescriptorApprovedV2), + stream_id: z.string(), + version: z.number(), + timestamp: z.coerce.date(), + }), + z.object({ + event_version: z.literal(2), + type: z.literal("EServiceDescriptorRejected"), + data: protobufDecoder(EServiceDescriptorRejectedV2), + stream_id: z.string(), + version: z.number(), + timestamp: z.coerce.date(), + }), ]); export type EServiceEventV2 = z.infer; diff --git a/tests/eservice.test.ts b/tests/eservice.test.ts index 58eeec6..0099f85 100644 --- a/tests/eservice.test.ts +++ b/tests/eservice.test.ts @@ -3,15 +3,49 @@ import { encodeOutboundEServiceEvent, decodeOutboundEServiceEvent, EServiceEvent, + EServiceModeV2, + EServiceTechnologyV2, + EServiceDescriptorStateV2, + AgreementApprovalPolicyV2, } from "../src/index.js"; describe("eservice", () => { - it("should correctly encode and decode EServiceDeleted event", () => { + it("should correctly encode and decode EServiceDescriptorArchived event", () => { const event: EServiceEvent = { - event_version: 1, - type: "EServiceDeleted", + event_version: 2, + type: "EServiceDescriptorArchived", data: { - eserviceId: "123", + descriptorId: "testtea", + eservice: { + id: "test", + createdAt: 1n, + producerId: "test", + mode: EServiceModeV2.DELIVER, + description: "testtest", + name: "test", + technology: EServiceTechnologyV2.REST, + descriptors: [ + { + id: "id", + version: 1n, + docs: [], + state: EServiceDescriptorStateV2.DRAFT, + audience: [], + voucherLifespan: 60, + dailyCallsPerConsumer: 10, + dailyCallsTotal: 1000, + createdAt: 1n, + serverUrls: ["pagopa.it"], + agreementApprovalPolicy: AgreementApprovalPolicyV2.AUTOMATIC, + attributes: { + certified: [], + verified: [], + declared: [], + }, + rejectedReasons: [], + }, + ], + }, }, stream_id: "123", timestamp: new Date(),