Skip to content

Commit

Permalink
Release/1.2.0 (#22)
Browse files Browse the repository at this point in the history
* Bump version

* Added delegation events

* Updated event names

* Revert update event names

* Updated event names

* Bump version

* Updated changelog

* Bump version

* Fix version
  • Loading branch information
Carminepo2 authored Jan 17, 2025
1 parent 5a586c9 commit 8f0db8c
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to this project will be documented in this file.

## 1.2.0

### Added

- Added `Delegation` data models
- Added delegation events: `ProducerDelegationSubmittedV2`, `ProducerDelegationApprovedV2`, `ProducerDelegationRejectedV2` and `ProducerDelegationRevokedV2`
- Added eservice events: `EServiceDescriptorSubmittedByDelegateV2`, `EServiceDescriptorApprovedByDelegatorV2` and `EServiceDescriptorRejectedByDelegatorV2`
- Added `rejectionReasons` property in `EServiceDescriptorV2` data model

## 1.1.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pagopa/interop-outbound-models",
"version": "1.1.0",
"version": "1.2.0",
"description": "PagoPA Interoperability outbound models",
"main": "dist",
"type": "module",
Expand Down
52 changes: 52 additions & 0 deletions proto/v2/delegation/delegation.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
syntax = "proto3";

package delegation.v2;

message DelegationV2 {
string id = 1;
string delegatorId = 2;
string delegateId = 3;
string eserviceId = 4;
int64 createdAt = 5;
int64 submittedAt = 6;
optional int64 approvedAt = 7;
optional int64 rejectedAt = 8;
optional string rejectionReason = 9;
optional int64 revokedAt = 10;
DelegationStateV2 state = 11;
DelegationKindV2 kind = 12;
DelegationStampsV2 stamps = 13;
optional DelegationContractDocumentV2 activationContract = 14;
optional DelegationContractDocumentV2 revocationContract = 15;
}

message DelegationContractDocumentV2 {
string id = 1;
string name = 2;
string prettyName = 3;
string contentType = 4;
int64 createdAt = 5;
}

message DelegationStampV2 {
int64 when = 1;
}

message DelegationStampsV2 {
DelegationStampV2 submission = 1;
optional DelegationStampV2 activation = 2;
optional DelegationStampV2 rejection = 3;
optional DelegationStampV2 revocation = 4;
}

enum DelegationStateV2 {
WAITING_FOR_APPROVAL= 0;
ACTIVE= 1;
REJECTED= 2;
REVOKED= 3;
}

enum DelegationKindV2 {
DELEGATED_PRODUCER = 0;
DELEGATED_CONSUMER = 1;
}
21 changes: 21 additions & 0 deletions proto/v2/delegation/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
syntax = "proto3";

package delegation.v2;

import "v2/delegation/delegation.proto";

message ProducerDelegationSubmittedV2 {
DelegationV2 delegation = 1;
}

message ProducerDelegationApprovedV2 {
DelegationV2 delegation = 1;
}

message ProducerDelegationRejectedV2 {
DelegationV2 delegation = 1;
}

message ProducerDelegationRevokedV2 {
DelegationV2 delegation = 1;
}
1 change: 1 addition & 0 deletions proto/v2/eservice/eservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ message EServiceDescriptorV2 {
optional int64 deprecatedAt = 16;
optional int64 archivedAt = 17;
EServiceAttributesV2 attributes = 18;
repeated DescriptorRejectionReasonV2 rejectionReasons = 19;
}

message EServiceDocumentV2 {
Expand Down
15 changes: 15 additions & 0 deletions proto/v2/eservice/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ message EServiceDescriptionUpdatedV2 {
EServiceV2 eservice = 1;
}

message EServiceDescriptorSubmittedByDelegateV2 {
string descriptorId = 1;
EServiceV2 eservice = 2;
}

message EServiceDescriptorApprovedByDelegatorV2 {
string descriptorId = 1;
EServiceV2 eservice = 2;
}

message EServiceDescriptorRejectedByDelegatorV2 {
string descriptorId = 1;
EServiceV2 eservice = 2;
}

message EServiceDescriptorAttributesUpdatedV2 {
string descriptorId = 1;
repeated string attributeIds = 2;
Expand Down
65 changes: 65 additions & 0 deletions src/delegation/eventsV2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { z } from "zod";
import { match } from "ts-pattern";
import {
ProducerDelegationSubmittedV2,
ProducerDelegationApprovedV2,
ProducerDelegationRejectedV2,
ProducerDelegationRevokedV2,
} from "../gen/v2/delegation/events.js";
import { protobufDecoder } from "../utils.js";

export function delegationEventToBinaryDataV2(
event: DelegationEventV2
): Uint8Array {
return match(event)
.with({ type: "ProducerDelegationSubmitted" }, ({ data }) =>
ProducerDelegationSubmittedV2.toBinary(data)
)
.with({ type: "ProducerDelegationApproved" }, ({ data }) =>
ProducerDelegationApprovedV2.toBinary(data)
)
.with({ type: "ProducerDelegationRejected" }, ({ data }) =>
ProducerDelegationRejectedV2.toBinary(data)
)
.with({ type: "ProducerDelegationRevoked" }, ({ data }) =>
ProducerDelegationRevokedV2.toBinary(data)
)
.exhaustive();
}

export const DelegationEventV2 = z.discriminatedUnion("type", [
z.object({
event_version: z.literal(2),
type: z.literal("ProducerDelegationSubmitted"),
data: protobufDecoder(ProducerDelegationSubmittedV2),
stream_id: z.string(),
version: z.number(),
timestamp: z.coerce.date(),
}),
z.object({
event_version: z.literal(2),
type: z.literal("ProducerDelegationApproved"),
data: protobufDecoder(ProducerDelegationApprovedV2),
stream_id: z.string(),
version: z.number(),
timestamp: z.coerce.date(),
}),
z.object({
event_version: z.literal(2),
type: z.literal("ProducerDelegationRejected"),
data: protobufDecoder(ProducerDelegationRejectedV2),
stream_id: z.string(),
version: z.number(),
timestamp: z.coerce.date(),
}),
z.object({
event_version: z.literal(2),
type: z.literal("ProducerDelegationRevoked"),
data: protobufDecoder(ProducerDelegationRevokedV2),
stream_id: z.string(),
version: z.number(),
timestamp: z.coerce.date(),
}),
]);

export type DelegationEventV2 = z.infer<typeof DelegationEventV2>;
49 changes: 49 additions & 0 deletions src/delegation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { match } from "ts-pattern";
import { z } from "zod";
import { VersionedEvent } from "../utils.js";
import {
DelegationEventV2,
delegationEventToBinaryDataV2,
} from "./eventsV2.js";

function delegationEventToBinaryData(event: DelegationEvent): Uint8Array {
return match(event)
.with({ event_version: 2 }, delegationEventToBinaryDataV2)
.exhaustive();
}

export function encodeOutboundDelegationEvent(event: DelegationEvent): string {
return JSON.stringify({
event_version: event.event_version,
type: event.type,
data: Buffer.from(delegationEventToBinaryData(event)).toString("hex"),
stream_id: event.stream_id,
version: event.version,
timestamp: event.timestamp,
});
}

export function decodeOutboundDelegationEvent(
encodedEvent: string
): DelegationEvent {
return DelegationEvent.parse(JSON.parse(encodedEvent));
}

export const DelegationEvent = VersionedEvent.transform((obj, ctx) => {
const res = match(obj)
.with({ event_version: 1 }, () => {
throw new Error("Unsupported event version");
})
.with({ event_version: 2 }, () => DelegationEventV2.safeParse(obj))
.exhaustive();

if (!res.success) {
res.error.issues.forEach(ctx.addIssue);
return z.NEVER;
}
return res.data;
});

export type DelegationEventType = DelegationEvent["type"];
export type DelegationEvent = z.infer<typeof DelegationEvent>;
export { DelegationEventV2 };
36 changes: 36 additions & 0 deletions src/eservice/eventsV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import {
EServiceDraftDescriptorUpdatedV2,
EServiceDescriptorQuotasUpdatedV2,
EServiceDescriptionUpdatedV2,
EServiceDescriptorSubmittedByDelegateV2,
EServiceDescriptorApprovedByDelegatorV2,
EServiceDescriptorRejectedByDelegatorV2,
EServiceDescriptorAttributesUpdatedV2,
EServiceNameUpdatedV2,
} from "../gen/v2/eservice/events.js";
Expand Down Expand Up @@ -86,6 +89,15 @@ export function eServiceEventToBinaryDataV2(
.with({ type: "EServiceDescriptionUpdated" }, ({ data }) =>
EServiceDescriptionUpdatedV2.toBinary(data)
)
.with({ type: "EServiceDescriptorSubmittedByDelegate" }, ({ data }) =>
EServiceDescriptorSubmittedByDelegateV2.toBinary(data)
)
.with({ type: "EServiceDescriptorApprovedByDelegator" }, ({ data }) =>
EServiceDescriptorApprovedByDelegatorV2.toBinary(data)
)
.with({ type: "EServiceDescriptorRejectedByDelegator" }, ({ data }) =>
EServiceDescriptorRejectedByDelegatorV2.toBinary(data)
)
.with({ type: "EServiceDescriptorAttributesUpdated" }, ({ data }) =>
EServiceDescriptorAttributesUpdatedV2.toBinary(data)
)
Expand Down Expand Up @@ -248,6 +260,30 @@ export const EServiceEventV2 = z.discriminatedUnion("type", [
version: z.number(),
timestamp: z.coerce.date(),
}),
z.object({
event_version: z.literal(2),
type: z.literal("EServiceDescriptorSubmittedByDelegate"),
data: protobufDecoder(EServiceDescriptorSubmittedByDelegateV2),
stream_id: z.string(),
version: z.number(),
timestamp: z.coerce.date(),
}),
z.object({
event_version: z.literal(2),
type: z.literal("EServiceDescriptorApprovedByDelegator"),
data: protobufDecoder(EServiceDescriptorApprovedByDelegatorV2),
stream_id: z.string(),
version: z.number(),
timestamp: z.coerce.date(),
}),
z.object({
event_version: z.literal(2),
type: z.literal("EServiceDescriptorRejectedByDelegator"),
data: protobufDecoder(EServiceDescriptorRejectedByDelegatorV2),
stream_id: z.string(),
version: z.number(),
timestamp: z.coerce.date(),
}),
z.object({
event_version: z.literal(2),
type: z.literal("EServiceDescriptorAttributesUpdated"),
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./eservice/index.js";
export * from "./agreement/index.js";
export * from "./purpose/index.js";
export * from "./tenant/index.js";
export * from "./delegation/index.js";

export * from "./gen/v1/agreement/agreement.js";
export * from "./gen/v1/agreement/events.js";
Expand All @@ -20,3 +21,5 @@ export * from "./gen/v2/purpose/purpose.js";
export * from "./gen/v2/purpose/events.js";
export * from "./gen/v2/tenant/tenant.js";
export * from "./gen/v2/tenant/events.js";
export * from "./gen/v2/delegation/delegation.js";
export * from "./gen/v2/delegation/events.js";
1 change: 1 addition & 0 deletions tests/eservice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe("eservice", () => {
verified: [],
declared: [],
},
rejectionReasons: [],
},
],
},
Expand Down

0 comments on commit 8f0db8c

Please sign in to comment.