Skip to content

Commit 451a12e

Browse files
BRBussyclaude
andauthored
feat: prefix compliance client resource names and add enum string converters (#244)
Update client resource name format from `clients/{ULIDv2}` to `compliance/clients/{ULIDv2}` across proto definitions and regenerated Go code. Add toString/fromString converter utilities for all 6 compliance client enums in ts-web. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 150337f commit 451a12e

File tree

11 files changed

+554
-22
lines changed

11 files changed

+554
-22
lines changed

go/compliance/client/v1/client.pb.go

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/compliance/client/v1/service.pb.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/meshtrade/compliance/client/v1/client.proto

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ option java_package = "co.meshtrade.api.compliance.client.v1";
2020
*/
2121
message Client {
2222
/*
23-
The unique, immutable, and canonical name of the client resource in the format clients/{client_id}.
23+
The unique, immutable, and canonical name of the client resource in the format compliance/clients/{client_id}.
2424
The {client_id} is a system-generated unique identifier (e.g., UUID) that will never change. This name field will never change and should be used as the permanent primary key for this resource in all systems.
2525
System set on creation.
2626
*/
2727
string name = 1 [(buf.validate.field) = {
2828
cel: {
2929
id: "name.format.optional"
30-
message: "name must be empty or in the format clients/{ULIDv2}"
31-
expression: "size(this) == 0 || this.matches('^clients/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$')"
30+
message: "name must be empty or in the format compliance/clients/{ULIDv2}"
31+
expression: "size(this) == 0 || this.matches('^compliance/clients/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$')"
3232
}
3333
}];
3434

@@ -118,8 +118,8 @@ message Client {
118118
string verification_authority = 10 [(buf.validate.field) = {
119119
cel: {
120120
id: "verification_authority.format.optional"
121-
message: "verification_authority must be empty or in the format clients/{ULIDv2}"
122-
expression: "size(this) == 0 || this.matches('^clients/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$')"
121+
message: "verification_authority must be empty or in the format compliance/clients/{ULIDv2}"
122+
expression: "size(this) == 0 || this.matches('^compliance/clients/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$')"
123123
}
124124
}];
125125

proto/meshtrade/compliance/client/v1/service.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ service ClientService {
8585
message GetClientRequest {
8686
// The unique resource name of the client to be retrieved.
8787
// The name serves as the primary identifier for the client resource.
88-
// Format: "clients/{client_id}"
88+
// Format: "compliance/clients/{client_id}"
8989
string name = 1 [(buf.validate.field) = {
9090
required: true
9191
string: {
92-
len: 33
93-
pattern: "^clients/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$"
92+
len: 45
93+
pattern: "^compliance/clients/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]{26}$"
9494
}
9595
}];
9696
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { CompanyRepresentativeRole } from "./company_representative_role_pb";
2+
3+
// Get all company representative roles as enum values
4+
export const allCompanyRepresentativeRoles: CompanyRepresentativeRole[] =
5+
Object.values(CompanyRepresentativeRole).filter(
6+
(value) => typeof value === "number"
7+
) as CompanyRepresentativeRole[];
8+
9+
// Define explicit mappings between CompanyRepresentativeRole enums and custom string representations
10+
const companyRepresentativeRoleToStringMapping: {
11+
[key in CompanyRepresentativeRole]: string;
12+
} = {
13+
[CompanyRepresentativeRole.UNSPECIFIED]: "Unspecified",
14+
[CompanyRepresentativeRole.ULTIMATE_BENEFICIAL_OWNER]:
15+
"Ultimate Beneficial Owner",
16+
[CompanyRepresentativeRole.SHAREHOLDER]: "Shareholder",
17+
[CompanyRepresentativeRole.SOLE_PROPRIETOR]: "Sole Proprietor",
18+
[CompanyRepresentativeRole.PARTNER]: "Partner",
19+
[CompanyRepresentativeRole.DIRECTOR]: "Director",
20+
[CompanyRepresentativeRole.MANAGER]: "Manager",
21+
[CompanyRepresentativeRole.AUTHORIZED_SIGNATORY]: "Authorized Signatory",
22+
[CompanyRepresentativeRole.PRIMARY_CONTACT]: "Primary Contact",
23+
};
24+
25+
// Reverse mapping from string to CompanyRepresentativeRole enum
26+
const stringToCompanyRepresentativeRoleMapping: Record<
27+
string,
28+
CompanyRepresentativeRole
29+
> = {};
30+
for (const [key, value] of Object.entries(
31+
companyRepresentativeRoleToStringMapping
32+
)) {
33+
stringToCompanyRepresentativeRoleMapping[value] = Number(key);
34+
}
35+
36+
class UnsupportedCompanyRepresentativeRoleError extends Error {
37+
companyRepresentativeRole: CompanyRepresentativeRole;
38+
39+
constructor(companyRepresentativeRole: CompanyRepresentativeRole) {
40+
const message = `Unsupported CompanyRepresentativeRole: ${companyRepresentativeRole}`;
41+
super(message);
42+
this.companyRepresentativeRole = companyRepresentativeRole;
43+
}
44+
}
45+
46+
/**
47+
* Converts a CompanyRepresentativeRole enum instance to a custom string representation.
48+
* @param {CompanyRepresentativeRole} companyRepresentativeRole - The role to convert.
49+
* @returns {string} The custom string representation of the role.
50+
*/
51+
export function companyRepresentativeRoleToString(
52+
companyRepresentativeRole: CompanyRepresentativeRole
53+
): string {
54+
if (companyRepresentativeRole in companyRepresentativeRoleToStringMapping) {
55+
return companyRepresentativeRoleToStringMapping[companyRepresentativeRole];
56+
} else {
57+
throw new UnsupportedCompanyRepresentativeRoleError(
58+
companyRepresentativeRole
59+
);
60+
}
61+
}
62+
63+
class UnsupportedCompanyRepresentativeRoleStringError extends Error {
64+
companyRepresentativeRoleStr: string;
65+
66+
constructor(companyRepresentativeRoleStr: string) {
67+
const message = `Unsupported company representative role string: ${companyRepresentativeRoleStr}`;
68+
super(message);
69+
this.companyRepresentativeRoleStr = companyRepresentativeRoleStr;
70+
}
71+
}
72+
73+
/**
74+
* Converts a custom string representation to a CompanyRepresentativeRole enum instance.
75+
* @param {string} companyRepresentativeRoleStr - The custom string representation of the role.
76+
* @returns {CompanyRepresentativeRole} The corresponding CompanyRepresentativeRole enum instance.
77+
*/
78+
export function stringToCompanyRepresentativeRole(
79+
companyRepresentativeRoleStr: string
80+
): CompanyRepresentativeRole {
81+
if (
82+
companyRepresentativeRoleStr in stringToCompanyRepresentativeRoleMapping
83+
) {
84+
return stringToCompanyRepresentativeRoleMapping[
85+
companyRepresentativeRoleStr
86+
];
87+
} else {
88+
throw new UnsupportedCompanyRepresentativeRoleStringError(
89+
companyRepresentativeRoleStr
90+
);
91+
}
92+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { IdentificationDocumentType } from "./identification_document_type_pb";
2+
3+
// Get all identification document types as enum values
4+
export const allIdentificationDocumentTypes: IdentificationDocumentType[] =
5+
Object.values(IdentificationDocumentType).filter(
6+
(value) => typeof value === "number"
7+
) as IdentificationDocumentType[];
8+
9+
// Define explicit mappings between IdentificationDocumentType enums and custom string representations
10+
const identificationDocumentTypeToStringMapping: {
11+
[key in IdentificationDocumentType]: string;
12+
} = {
13+
[IdentificationDocumentType.UNSPECIFIED]: "Unspecified",
14+
[IdentificationDocumentType.PASSPORT]: "Passport",
15+
[IdentificationDocumentType.NATIONAL_ID]: "National ID",
16+
[IdentificationDocumentType.DRIVERS_LICENSE]: "Driver's License",
17+
[IdentificationDocumentType.RESIDENCE_PERMIT]: "Residence Permit",
18+
};
19+
20+
// Reverse mapping from string to IdentificationDocumentType enum
21+
const stringToIdentificationDocumentTypeMapping: Record<
22+
string,
23+
IdentificationDocumentType
24+
> = {};
25+
for (const [key, value] of Object.entries(
26+
identificationDocumentTypeToStringMapping
27+
)) {
28+
stringToIdentificationDocumentTypeMapping[value] = Number(key);
29+
}
30+
31+
class UnsupportedIdentificationDocumentTypeError extends Error {
32+
identificationDocumentType: IdentificationDocumentType;
33+
34+
constructor(identificationDocumentType: IdentificationDocumentType) {
35+
const message = `Unsupported IdentificationDocumentType: ${identificationDocumentType}`;
36+
super(message);
37+
this.identificationDocumentType = identificationDocumentType;
38+
}
39+
}
40+
41+
/**
42+
* Converts an IdentificationDocumentType enum instance to a custom string representation.
43+
* @param {IdentificationDocumentType} identificationDocumentType - The document type to convert.
44+
* @returns {string} The custom string representation of the document type.
45+
*/
46+
export function identificationDocumentTypeToString(
47+
identificationDocumentType: IdentificationDocumentType
48+
): string {
49+
if (identificationDocumentType in identificationDocumentTypeToStringMapping) {
50+
return identificationDocumentTypeToStringMapping[
51+
identificationDocumentType
52+
];
53+
} else {
54+
throw new UnsupportedIdentificationDocumentTypeError(
55+
identificationDocumentType
56+
);
57+
}
58+
}
59+
60+
class UnsupportedIdentificationDocumentTypeStringError extends Error {
61+
identificationDocumentTypeStr: string;
62+
63+
constructor(identificationDocumentTypeStr: string) {
64+
const message = `Unsupported identification document type string: ${identificationDocumentTypeStr}`;
65+
super(message);
66+
this.identificationDocumentTypeStr = identificationDocumentTypeStr;
67+
}
68+
}
69+
70+
/**
71+
* Converts a custom string representation to an IdentificationDocumentType enum instance.
72+
* @param {string} identificationDocumentTypeStr - The custom string representation.
73+
* @returns {IdentificationDocumentType} The corresponding IdentificationDocumentType enum instance.
74+
*/
75+
export function stringToIdentificationDocumentType(
76+
identificationDocumentTypeStr: string
77+
): IdentificationDocumentType {
78+
if (
79+
identificationDocumentTypeStr in stringToIdentificationDocumentTypeMapping
80+
) {
81+
return stringToIdentificationDocumentTypeMapping[
82+
identificationDocumentTypeStr
83+
];
84+
} else {
85+
throw new UnsupportedIdentificationDocumentTypeStringError(
86+
identificationDocumentTypeStr
87+
);
88+
}
89+
}

ts-web/src/meshtrade/compliance/client/v1/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,9 @@ export * from "./verification_status_pb";
4242
// export { MyCustomClass } from "./another_module";
4343
// ===================================================================
4444

45-
// TODO: Re-enable when custom grpc-web client generator is migrated to @bufbuild/es
46-
// export { ClientServiceGrpcWebClientV1 } from "./service_grpc_web_client_meshts";
45+
export * from "./company_representative_role";
46+
export * from "./identification_document_type";
47+
export * from "./natural_person_connection_type";
48+
export * from "./pep_status";
49+
export * from "./source_of_income_and_wealth";
50+
export * from "./verification_status";

0 commit comments

Comments
 (0)