Skip to content

Commit 6ef398d

Browse files
authored
Merge pull request #830 from companieshouse/feature/psc-extensions-integration
Psc-Extensions SDK
2 parents 032499a + 9195a4c commit 6ef398d

File tree

4 files changed

+220
-0
lines changed

4 files changed

+220
-0
lines changed

src/client.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import RegisteredEmailAddressService from "./services/registered-email-address/s
3333
import { ClientType } from "./enums";
3434
import { PostcodeLookupService } from "./services/postcode-lookup";
3535
import PscVerificationService from "./services/psc-verification-link/service";
36+
import PscExtensionsService from "./services/psc-extensions-link/service";
3637
import { AccountsFilingService } from "./services/accounts-filing";
3738
import PscService from "./services/psc/service";
3839
import { LimitedPartnershipsService } from "./services/limited-partnerships"
@@ -75,6 +76,7 @@ export default class ApiClient {
7576
public readonly acsp: AcspService;
7677
public readonly postCodeLookup: PostcodeLookupService;
7778
public readonly pscVerificationService: PscVerificationService;
79+
public readonly pscExtensionsService: PscExtensionsService;
7880
public readonly accountsFilingService: AccountsFilingService;
7981
public readonly pscService: PscService;
8082
public readonly limitedPartnershipsService: LimitedPartnershipsService;
@@ -115,6 +117,7 @@ export default class ApiClient {
115117
this.transaction = new TransactionService(apiClient);
116118
this.registeredEmailAddressService = new RegisteredEmailAddressService(apiClient);
117119
this.postCodeLookup = new PostcodeLookupService(apiClient);
120+
this.pscExtensionsService = new PscExtensionsService(apiClient);
118121
this.pscVerificationService = new PscVerificationService(apiClient);
119122
this.accountsFilingService = new AccountsFilingService(apiClient);
120123
this.pscService = new PscService(apiClient);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./types";
2+
export { default as PscExtensionService } from "./service";
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { PscExtension, PscExtensionnData } from "./types"
2+
3+
import { Headers, HttpResponse, IHttpClient } from "../../http";
4+
import Resource, { ApiErrorResponse } from "../resource";
5+
import Mapping from "../../mapping/mapping";
6+
import { PersonWithSignificantControlResource } from "../psc/types";
7+
8+
/**
9+
* Service class for handling PSC (Person with Significant Control) extension-related operations.
10+
* This class provides methods to interact with the PSC extensions API, including creating, retrieving,
11+
* and checking the validation of PSC extensions request
12+
*/
13+
export default class PscExtensionService {
14+
constructor (private readonly client: IHttpClient) {}
15+
16+
/**
17+
* Submits a new PSC extension for a given transaction.
18+
*
19+
* @param transactionId - The unique identifier of the transaction.
20+
* @param pscExtension - The PSC extension data to be submitted.
21+
* @returns A promise that resolves to either:
22+
* - A `Resource<PscExtension>` object containing the created PSC extension details.
23+
* - An `ApiErrorResponse` object if an error occurs during the request.
24+
*/
25+
public async postPscExtension (transactionId: string, pscExtension: PscExtensionnData, headers?: Headers): Promise<Resource<PscExtension> | ApiErrorResponse> {
26+
const resourceUri = `/transactions/${transactionId}/persons-with-significant-control-extensions`;
27+
const pscExtensionResource = Mapping.snakeCaseKeys(pscExtension);
28+
const response = await this.client.httpPost(resourceUri, pscExtensionResource, headers);
29+
30+
if (response.error) {
31+
return this.handleErrorResponse(response);
32+
}
33+
34+
return this.populateFrontEndResource(response);
35+
}
36+
37+
/**
38+
* Maps the response body to a front-end resource format with camelCase keys.
39+
*
40+
* @param response - The HTTP response received from the API.
41+
* @returns A `Resource<PscExtension>` object containing the mapped resource.
42+
*/
43+
private populateFrontEndResource (response: HttpResponse): Resource<PscExtension> {
44+
const frontEndResource: Resource<PscExtension> = {
45+
httpStatusCode: response.status,
46+
resource: response.body as PscExtension
47+
};
48+
49+
const body = response.body as PersonWithSignificantControlResource;
50+
frontEndResource.resource = Mapping.camelCaseKeys<PscExtension>(body);
51+
52+
return frontEndResource;
53+
}
54+
55+
/**
56+
* Handles error responses from the API by mapping error details to camelCase keys.
57+
*
58+
* @param response - The HTTP response containing the error details.
59+
* @returns An `ApiErrorResponse` object with the mapped error details.
60+
*/
61+
private handleErrorResponse (response: HttpResponse): ApiErrorResponse {
62+
return {
63+
httpStatusCode: response.status,
64+
errors: [Mapping.camelCaseKeys(response.error)]
65+
};
66+
}
67+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
export interface PersonWithSignificantControlResource {
2+
address: AddressResource,
3+
country_of_residence: string,
4+
date_of_birth: DateOfBirthResource,
5+
ceased_on?: string,
6+
etag: string,
7+
links: ItemLinksResource,
8+
name: string,
9+
name_elements: NameElementsResource,
10+
nationality: string,
11+
natures_of_control: string[],
12+
notified_on: string,
13+
is_sanctioned?: boolean,
14+
kind?: string
15+
};
16+
17+
export interface PersonWithSignificantControl {
18+
address: Address,
19+
countryOfResidence: string,
20+
dateOfBirth: DateOfBirth,
21+
ceasedOn?: string,
22+
etag: string,
23+
links: ItemLinks,
24+
name: string,
25+
nameElements: NameElements,
26+
nationality: string,
27+
naturesOfControl: string[],
28+
notifiedOn: string,
29+
isSanctioned?: boolean,
30+
kind?: string
31+
};
32+
33+
export interface AddressResource {
34+
address_line_1: string;
35+
address_line_2?: string;
36+
careOf?: string;
37+
locality: string;
38+
poBox?: string;
39+
postal_code?: string;
40+
premises?: string;
41+
region?: string;
42+
};
43+
44+
export interface Address {
45+
addressLine1: string;
46+
addressLine2?: string;
47+
careOf?: string;
48+
locality: string;
49+
poBox?: string;
50+
postalCode?: string;
51+
premises?: string;
52+
region?: string;
53+
};
54+
55+
export interface DateOfBirthResource {
56+
day?: string;
57+
month: string;
58+
year: string;
59+
};
60+
61+
export interface DateOfBirth {
62+
day?: string;
63+
month: string;
64+
year: string;
65+
};
66+
67+
export interface ResultsLinksResource {
68+
self: string,
69+
persons_with_significant_control_statements_list?: string;
70+
};
71+
72+
export interface ResultsLinks {
73+
self: string,
74+
personsWithSignificantControlStatementsList?: string;
75+
};
76+
77+
export interface ItemLinksResource {
78+
self: string,
79+
statement?: string;
80+
};
81+
82+
export interface ItemLinks {
83+
self: string,
84+
statement?: string;
85+
};
86+
87+
export interface LinksResource {
88+
self: string,
89+
validation_status: string
90+
}
91+
92+
export interface Links {
93+
self: string,
94+
validationStatus: string
95+
}
96+
97+
export interface NameElementsResource {
98+
forename?: string,
99+
other_forenames?: string,
100+
middlename?: string,
101+
surname?: string,
102+
title?: string
103+
}
104+
105+
export interface NameElements {
106+
title?: string;
107+
forename?: string;
108+
otherForenames?: string;
109+
middleName?: string;
110+
surname: string;
111+
};
112+
113+
export interface PscVerificationResource {
114+
created_at: Date,
115+
updated_at: Date,
116+
links: LinksResource,
117+
data: PscExtensionnDataResource;
118+
}
119+
120+
export interface PscExtensionnDataResource {
121+
company_number?: string,
122+
psc_notification_id?: string,
123+
extensionDetails?: ExtensionDetailsResource
124+
}
125+
126+
export interface PscExtension {
127+
createdAt: Date,
128+
updatedAt: Date,
129+
links: Links,
130+
data: PscExtensionnData;
131+
}
132+
export interface PscExtensionnData {
133+
companyNumber?: string,
134+
pscNotificationId?: string,
135+
extensionDetails?: ExtensionDetails
136+
}
137+
138+
export interface ExtensionDetailsResource {
139+
extensionReason?: string,
140+
nameMismatchReason?: string,
141+
extensionRequestDate?: string
142+
}
143+
144+
export interface ExtensionDetails {
145+
extensionReason?: string,
146+
nameMismatchReason?: string,
147+
extensionRequestDate?: string
148+
}

0 commit comments

Comments
 (0)