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-415 add consumerServiceV2 in tenant-readmodel-writer #339

Merged
Merged
Show file tree
Hide file tree
Changes from 155 commits
Commits
Show all changes
161 commits
Select commit Hold shift + click to select a range
604355c
Update Logger Message
rGregnanin Mar 5, 2024
419f2ca
Merge branch 'main' into IMN-259_operationLogging_in_tenant
rGregnanin Mar 5, 2024
2a28a97
Merge branch 'main' into IMN-259_operationLogging_in_tenant
rGregnanin Mar 8, 2024
f578e52
Updated logger message
rGregnanin Mar 8, 2024
92c4dfa
Deleted unused function
rGregnanin Mar 11, 2024
8da8879
Merge branch 'main' into IMN-259_operationLogging_in_tenant
rGregnanin Mar 11, 2024
9b652f4
Merge branch 'main' into IMN-259_operationLogging_in_tenant
rGregnanin Mar 11, 2024
800f19b
Merge branch 'main' into IMN-259_operationLogging_in_tenant
rGregnanin Mar 15, 2024
bbaa84c
refactor logic function
rGregnanin Mar 15, 2024
a1d67ba
Merge branch 'IMN-259_operationLogging_in_tenant' into IMN-352_refact…
rGregnanin Mar 15, 2024
77ad263
changed log position
rGregnanin Mar 15, 2024
6d27473
changed return type
rGregnanin Mar 15, 2024
fcbed4b
Merge branch 'main' into IMN-259_operationLogging_in_tenant
rGregnanin Mar 15, 2024
f08e8ad
Merge branch 'IMN-259_operationLogging_in_tenant' into IMN-352_refact…
rGregnanin Mar 15, 2024
a2b96cf
Merge branch 'IMN-352_refactor_logic_function_in_tenant-process' into…
rGregnanin Mar 15, 2024
3eebf11
deleted updateTenant from open-api
rGregnanin Mar 15, 2024
c89a5eb
Fix
rGregnanin Mar 15, 2024
db014ef
Merge branch 'main' into IMN-259_operationLogging_in_tenant
rGregnanin Mar 19, 2024
a759564
Merge branch 'IMN-259_operationLogging_in_tenant' into IMN-352_refact…
rGregnanin Mar 19, 2024
39b6e31
Merge branch 'IMN-352_refactor_logic_function_in_tenant-process' into…
rGregnanin Mar 19, 2024
a922d66
Added logger before the retrive
rGregnanin Mar 27, 2024
1dcd77c
Merge branch 'main' into IMN-352_refactor_logic_function_in_tenant-pr…
rGregnanin Mar 27, 2024
64afdcf
Merge branch 'IMN-352_refactor_logic_function_in_tenant-process' into…
rGregnanin Mar 27, 2024
d9cbe14
Add protobuf definitions
taglioni-r Apr 3, 2024
0403d89
Add converters
taglioni-r Apr 3, 2024
b2af17e
Update index.ts
taglioni-r Apr 3, 2024
09c8f57
Fix end of file
taglioni-r Apr 3, 2024
836e08a
Add event definition
rGregnanin Apr 3, 2024
29bb190
Merge branch 'IMN-384_tenant-events-v2' of https://github.com/pagopa/…
rGregnanin Apr 3, 2024
3fe36df
refactor
rGregnanin Apr 3, 2024
eb4bdd0
Added extensionDate event
rGregnanin Apr 3, 2024
31095be
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Apr 3, 2024
a7b31dd
refactor and use new events
rGregnanin Apr 3, 2024
7ee4a3e
updated events in utils.ts
rGregnanin Apr 3, 2024
1d942f9
added converterV1 file
rGregnanin Apr 3, 2024
3880827
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 3, 2024
6eee4d2
Removed not needed line
rGregnanin Apr 3, 2024
a423d48
Merge branch 'IMN-381_move_toTenantV1' of https://github.com/pagopa/i…
rGregnanin Apr 3, 2024
5fc0a6d
added handleMessageV2
rGregnanin Apr 3, 2024
248c9f6
Merge branch 'main' into IMN-384_tenant-events-v2
rGregnanin Apr 4, 2024
ba1d22e
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Apr 4, 2024
3804536
updated test with eventV2
rGregnanin Apr 4, 2024
1d2a524
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 4, 2024
1b6d2fb
Fix test
rGregnanin Apr 4, 2024
84962a6
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 4, 2024
d6c86ac
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Apr 4, 2024
2e253e3
Merge branch 'main' into IMN-384_tenant-events-v2
rGregnanin Apr 4, 2024
3650d87
Merge branch 'main' into IMN-384_tenant-events-v2
rGregnanin Apr 4, 2024
b10c8ab
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Apr 4, 2024
e957160
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 4, 2024
5057ffd
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Apr 4, 2024
50a4c3b
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 4, 2024
39f9ac2
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Apr 4, 2024
32c3e60
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 4, 2024
790f536
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Apr 4, 2024
fe7ac97
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 5, 2024
c2f1473
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Apr 5, 2024
4701d64
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 5, 2024
2145463
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Apr 5, 2024
7f19202
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 5, 2024
8286a96
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 5, 2024
e9a7b94
Minor fixes
taglioni-r Apr 8, 2024
72a08e5
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 8, 2024
26d896c
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 8, 2024
4ec3698
Upgrade proto version
taglioni-r Apr 8, 2024
1bf8c20
Fix numbers in proto enums
taglioni-r Apr 8, 2024
7ea6695
Remove required
taglioni-r Apr 8, 2024
3234abf
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 8, 2024
892ed53
Fix after upgrade to proto3
taglioni-r Apr 8, 2024
bdb2998
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Apr 9, 2024
9c6a105
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 9, 2024
9187644
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Apr 9, 2024
74c27d8
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 9, 2024
57b0f62
removed try catch in index.ts
rGregnanin Apr 9, 2024
30c9780
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 9, 2024
f3172aa
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Apr 9, 2024
a7185f4
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 9, 2024
6c8d11e
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Apr 9, 2024
50c0a1e
Remove reserved
taglioni-r Apr 9, 2024
03f73a9
Fix definition
taglioni-r Apr 9, 2024
10de6ab
Remove default
taglioni-r Apr 9, 2024
3c58b07
Fix missing selfcareId
taglioni-r Apr 9, 2024
34d5b1a
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 9, 2024
3a0a5d7
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Apr 10, 2024
a40c9a8
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 10, 2024
511b457
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Apr 10, 2024
4f96036
Fix tests
rGregnanin Apr 10, 2024
11299de
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 10, 2024
7c936f0
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Apr 10, 2024
a58816b
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 11, 2024
761e7ac
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Apr 12, 2024
ad5b07f
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 12, 2024
74aa39e
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Apr 12, 2024
bcaa352
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 15, 2024
199d3c8
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Apr 16, 2024
0d5e85e
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 16, 2024
8f8b007
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Apr 16, 2024
0c6fd93
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 19, 2024
aa79ea0
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 23, 2024
5728bd7
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Apr 23, 2024
d41a505
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 23, 2024
2c9eee4
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Apr 23, 2024
c73abc0
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 24, 2024
9520eb1
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 29, 2024
7a95359
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Apr 29, 2024
54643a8
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 29, 2024
48a37a4
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Apr 29, 2024
88ea62f
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Apr 30, 2024
31eac0a
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Apr 30, 2024
a26f2d1
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Apr 30, 2024
be46b13
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Apr 30, 2024
df85986
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r May 2, 2024
6e818f0
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r May 2, 2024
072098b
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r May 3, 2024
e569d1e
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r May 6, 2024
60a70cc
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r May 8, 2024
ba816ae
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r May 9, 2024
b0946de
Fix
taglioni-r May 9, 2024
eab7dac
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r May 9, 2024
5940482
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin May 9, 2024
0e2912a
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin May 9, 2024
d6e0e26
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin May 9, 2024
df29f55
refactor
rGregnanin May 9, 2024
53705c8
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r May 14, 2024
316f8e6
Refactor
taglioni-r May 14, 2024
539c427
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r May 15, 2024
64d84e5
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin May 15, 2024
1886833
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Jun 12, 2024
bbcab41
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Jun 13, 2024
5f89b2e
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Jun 13, 2024
9724a4b
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Jun 13, 2024
9facc96
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Jun 13, 2024
6c04eca
fix test
rGregnanin Jun 14, 2024
4d7f700
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Jun 14, 2024
fc9aac6
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Jun 14, 2024
c1b1c4d
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Jun 17, 2024
6a0faa3
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Jun 18, 2024
39d03cf
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Jun 21, 2024
69f0361
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Jun 21, 2024
1b105ec
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Jun 21, 2024
061ea35
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Jun 25, 2024
52e5f5e
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Jul 1, 2024
069579c
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Jul 1, 2024
aa9e511
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Jul 2, 2024
0a2a20e
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Jul 2, 2024
39fdf11
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Jul 2, 2024
36fe1a7
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Jul 2, 2024
d70918a
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Jul 2, 2024
cff91ae
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Jul 4, 2024
0d92c4f
Fix workflow
taglioni-r Jul 4, 2024
d687f2b
Fix workflow
taglioni-r Jul 4, 2024
dd0ddbc
Merge branch 'main' into IMN-384_tenant-events-v2
taglioni-r Jul 4, 2024
05b4621
Merge branch 'IMN-384_tenant-events-v2' into IMN-414_eventV2_on_imple…
rGregnanin Jul 4, 2024
15b2ab2
Merge branch 'IMN-414_eventV2_on_implementedPost' into IMN-381_move_t…
rGregnanin Jul 4, 2024
7757ffd
Merge branch 'IMN-381_move_toTenantV1' into IMN-415_add_ConsumerServi…
rGregnanin Jul 4, 2024
68dd543
Merge branch 'main' into IMN-415_add_ConsumerServiceV2_in_tenant_read…
rGregnanin Jul 15, 2024
e6146eb
Merge branch 'main' into IMN-415_add_ConsumerServiceV2_in_tenant_read…
rGregnanin Jul 15, 2024
b08e8bd
Added "e" to "$lt"
rGregnanin Jul 15, 2024
4132772
Merge branch 'main' into IMN-415_add_ConsumerServiceV2_in_tenant_read…
rGregnanin Jul 15, 2024
8b692d1
Merge branch 'main' into IMN-415_add_ConsumerServiceV2_in_tenant_read…
rGregnanin Jul 17, 2024
6c05e9d
Merge branch 'main' into IMN-415_add_ConsumerServiceV2_in_tenant_read…
rGregnanin Jul 17, 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
63 changes: 63 additions & 0 deletions packages/models/proto/v2/tenant/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
syntax = "proto3";

package tenant.v2;

import "v2/tenant/tenant.proto";

message TenantOnboardedV2 {
TenantV2 tenant = 1;
}

message TenantOnboardDetailsUpdatedV2 {
TenantV2 tenant = 1;
}

message TenantCertifiedAttributeAssignedV2 {
string attributeId = 1;
TenantV2 tenant = 2;
}

message TenantCertifiedAttributeRevokedV2 {
string attributeId = 1;
TenantV2 tenant = 2;
}

message TenantDeclaredAttributeAssignedV2 {
string attributeId = 1;
TenantV2 tenant = 2;
}

message TenantDeclaredAttributeRevokedV2 {
string attributeId = 1;
TenantV2 tenant = 2;
}

message TenantVerifiedAttributeAssignedV2 {
string attributeId = 1;
TenantV2 tenant = 2;
}

message TenantVerifiedAttributeRevokedV2 {
string attributeId = 1;
TenantV2 tenant = 2;
}

message TenantVerifiedAttributeExpirationUpdatedV2 {
string attributeId = 1;
TenantV2 tenant = 2;
}

message TenantVerifiedAttributeExtensionUpdatedV2 {
string attributeId = 1;
TenantV2 tenant = 2;
}

message MaintenanceTenantDeletedV2 {
string tenantId = 1;
TenantV2 tenant = 2;
}

message TenantMailAddedV2 {
string mailId = 1;
TenantV2 tenant = 2;
}
100 changes: 100 additions & 0 deletions packages/models/proto/v2/tenant/tenant.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
syntax = "proto3";

package tenant.v2;

message TenantV2 {
string id = 1;
string selfcareId = 2;
ExternalIdV2 externalId = 3;
repeated TenantFeatureV2 features = 4;
repeated TenantAttributeV2 attributes = 5;
int64 createdAt = 6;
optional int64 updatedAt = 7;
repeated TenantMailV2 mails = 8;
string name = 9;
optional TenantKindV2 kind = 10;
int64 onboardedAt = 11;
optional TenantUnitTypeV2 subUnitType = 12;

}

enum TenantKindV2 {
PA = 0;
GSP = 1;
PRIVATE = 2;
}

message TenantMailV2 {
TenantMailKindV2 kind = 1;
string address = 2;
int64 createdAt = 3;
optional string description = 4;
string id = 5;
}

enum TenantMailKindV2 {
CONTACT_EMAIL = 0;
DIGITAL_ADDRESS = 1;
}

enum TenantUnitTypeV2 {
AOO = 0;
UO = 1;
}

message TenantFeatureV2 {
oneof sealed_value {
CertifierV2 certifier = 1;
}
}

message CertifierV2 {
string certifierId = 1;
}

message TenantVerifierV2 {
string id = 1;
int64 verificationDate = 2;
optional int64 expirationDate = 3;
optional int64 extensionDate = 4;
}

message TenantRevokerV2 {
string id = 1;
int64 verificationDate = 2;
optional int64 expirationDate = 3;
optional int64 extensionDate = 4;
int64 revocationDate = 5;
}

message ExternalIdV2 {
string origin = 1;
string value = 2;
}

message TenantCertifiedAttributeV2 {
string id = 1;
int64 assignmentTimestamp = 2;
optional int64 revocationTimestamp = 3;
}

message TenantDeclaredAttributeV2 {
string id = 1;
int64 assignmentTimestamp = 2;
optional int64 revocationTimestamp = 3;
}

message TenantVerifiedAttributeV2 {
string id = 1;
int64 assignmentTimestamp = 2;
repeated TenantVerifierV2 verifiedBy = 3;
repeated TenantRevokerV2 revokedBy = 4;
}

message TenantAttributeV2 {
oneof sealed_value {
TenantCertifiedAttributeV2 certifiedAttribute = 1;
TenantDeclaredAttributeV2 declaredAttribute = 2;
TenantVerifiedAttributeV2 verifiedAttribute = 3;
}
}
6 changes: 5 additions & 1 deletion packages/models/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export * from "./institution/institution.js";

export * from "./risk-analysis/riskAnalysis.js";

export * from "./tenant/protobufConverter.js";
export * from "./tenant/tenant.js";
export * from "./tenant/tenantEvents.js";
export * from "./tenant/protobufConverterFromV1.js";
export * from "./tenant/protobufConverterFromV2.js";
export * from "./tenant/protobufConverterToV2.js";

export * from "./purpose/purpose.js";
export * from "./purpose/purposeEvents.js";
Expand Down Expand Up @@ -92,3 +94,5 @@ export * from "./gen/v2/purpose/events.js";
export * from "./gen/v2/authorization/client.js";
export * from "./gen/v2/authorization/key.js";
export * from "./gen/v2/authorization/events.js";
export * from "./gen/v2/tenant/tenant.js";
export * from "./gen/v2/tenant/events.js";
175 changes: 175 additions & 0 deletions packages/models/src/tenant/protobufConverterFromV2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import { createHash } from "crypto";
import { match } from "ts-pattern";
import { unsafeBrandId } from "../brandedIds.js";
import { genericError } from "../errors.js";
import {
TenantKindV2,
TenantMailKindV2,
TenantMailV2,
TenantFeatureV2,
TenantVerifierV2,
TenantRevokerV2,
TenantAttributeV2,
TenantV2,
TenantUnitTypeV2,
} from "../gen/v2/tenant/tenant.js";
import { bigIntToDate } from "../utils.js";
import {
TenantKind,
tenantKind,
TenantMailKind,
tenantMailKind,
TenantMail,
TenantFeatureCertifier,
TenantVerifier,
TenantRevoker,
TenantAttribute,
Tenant,
ExternalId,
tenantAttributeType,
TenantUnitType,
tenantUnitType,
} from "./tenant.js";

export const fromTenantKindV2 = (input: TenantKindV2): TenantKind => {
switch (input) {
case TenantKindV2.GSP:
return tenantKind.GSP;
case TenantKindV2.PA:
return tenantKind.PA;
case TenantKindV2.PRIVATE:
return tenantKind.PRIVATE;
}
};

export const fromTenantMailKindV2 = (
input: TenantMailKindV2
): TenantMailKind => {
switch (input) {
case TenantMailKindV2.CONTACT_EMAIL:
return tenantMailKind.ContactEmail;
case TenantMailKindV2.DIGITAL_ADDRESS:
return tenantMailKind.DigitalAddress;
}
};

export const fromTenantMailV2 = (input: TenantMailV2): TenantMail => ({
...input,
id: input.id ?? createHash("sha256").update(input.address).digest("hex"),
createdAt: bigIntToDate(input.createdAt),
kind: fromTenantMailKindV2(input.kind),
});

export const fromTenantFeatureV2 = (
input: TenantFeatureV2
): TenantFeatureCertifier =>
match<TenantFeatureV2["sealedValue"], TenantFeatureCertifier>(
input.sealedValue
)
.with({ oneofKind: "certifier" }, ({ certifier }) => ({
type: "PersistentCertifier",
certifierId: certifier.certifierId,
}))
.with({ oneofKind: undefined }, () => {
throw new Error("Unable to deserialize TenantFeature");
})
.exhaustive();

export const fromTenantVerifierV2 = (
input: TenantVerifierV2
): TenantVerifier => ({
...input,
verificationDate: bigIntToDate(input.verificationDate),
expirationDate: bigIntToDate(input.expirationDate),
extensionDate: bigIntToDate(input.extensionDate),
});

export const fromTenantRevokerV2 = (input: TenantRevokerV2): TenantRevoker => ({
...input,
expirationDate: bigIntToDate(input.expirationDate),
extensionDate: bigIntToDate(input.extensionDate),
revocationDate: bigIntToDate(input.revocationDate),
verificationDate: bigIntToDate(input.verificationDate),
});

export const fromTenantAttributesV2 = (
input: TenantAttributeV2
): TenantAttribute => {
const { sealedValue } = input;

switch (sealedValue.oneofKind) {
case "certifiedAttribute":
const { certifiedAttribute } = sealedValue;
return {
id: unsafeBrandId(certifiedAttribute.id),
assignmentTimestamp: bigIntToDate(
certifiedAttribute.assignmentTimestamp
),
type: tenantAttributeType.CERTIFIED,
};
case "verifiedAttribute":
const { verifiedAttribute } = sealedValue;
return {
id: unsafeBrandId(verifiedAttribute.id),
assignmentTimestamp: bigIntToDate(
verifiedAttribute.assignmentTimestamp
),
verifiedBy: verifiedAttribute.verifiedBy.map(fromTenantVerifierV2),
revokedBy: verifiedAttribute.revokedBy.map(fromTenantRevokerV2),
type: tenantAttributeType.VERIFIED,
};
case "declaredAttribute":
const { declaredAttribute } = sealedValue;
return {
id: unsafeBrandId(declaredAttribute.id),
assignmentTimestamp: bigIntToDate(
declaredAttribute.assignmentTimestamp
),
type: tenantAttributeType.DECLARED,
};
default:
throw genericError(`Invalid attribute kind: ${sealedValue.oneofKind}`);
}
};

export const fromTenantUnitTypeV2 = (
input: TenantUnitTypeV2
): TenantUnitType => {
switch (input) {
case TenantUnitTypeV2.AOO:
return tenantUnitType.AOO;
case TenantUnitTypeV2.UO:
return tenantUnitType.UO;
}
};

export const fromTenantV2 = (input: TenantV2): Tenant => {
/**
* The `externalId` field is required in the TenantV2 protobuf model but
* for some reasons the @protobuf-ts/protoc library generates it as optional.
* This issue has been reported here: https://github.com/timostamm/protobuf-ts/issues/340
*/
const externalId = ExternalId.safeParse(input.externalId);
if (!externalId.success) {
throw genericError(
`Error while deserializing TenantV2 (${input.id}): missing externalId`
);
}

return {
...input,
id: unsafeBrandId(input.id),
name: input.name ?? "",
createdAt: bigIntToDate(input.createdAt),
attributes: input.attributes.map(fromTenantAttributesV2),
externalId: externalId.data,
features: input.features.map(fromTenantFeatureV2),
mails: input.mails.map(fromTenantMailV2),
kind: input.kind ? fromTenantKindV2(input.kind) : undefined,
updatedAt: bigIntToDate(input.updatedAt),
onboardedAt: bigIntToDate(input.onboardedAt),
subUnitType: input.subUnitType
? fromTenantUnitTypeV2(input.subUnitType)
: undefined,
};
};
Loading