@@ -17,20 +17,11 @@ import {ServiceSearchClient} from "./serviceSearch-client"
1717const SERVICE_SEARCH_TIMEOUT = 3000 // 3 seconds
1818const DISTANCE_SELLING = "DistanceSelling"
1919
20- type Service = {
21- "URL" : string
22- "OrganisationSubType" : string
23- }
24-
2520type Contact = {
2621 "ContactMethodType" : string
2722 "ContactValue" : string
2823}
2924
30- export type ServiceSearchData = {
31- "value" : Array < Service >
32- }
33-
3425export type ServiceSearch3Data = {
3526 "@odata.context" : string
3627 "value" : Array < {
@@ -41,33 +32,21 @@ export type ServiceSearch3Data = {
4132}
4233
4334export const SERVICE_SEARCH_BASE_QUERY_PARAMS = {
44- "api-version" : 2 ,
35+ "api-version" : 3 ,
4536 "searchFields" : "ODSCode" ,
46- "$filter" : " OrganisationTypeId eq 'PHA' and OrganisationSubType eq 'DistanceSelling'" ,
47- "$select" : "URL ,OrganisationSubType" ,
37+ "$filter" : ` OrganisationTypeId eq 'PHA' and OrganisationSubType eq '${ DISTANCE_SELLING } '` ,
38+ "$select" : "Contacts ,OrganisationSubType" ,
4839 "$top" : 1
4940}
5041
5142export function getServiceSearchVersion ( logger : Logger | null = null ) : number {
52- const endpoint = process . env . TargetServiceSearchServer || "service-search"
53- if ( endpoint . toLowerCase ( ) . includes ( "api.service.nhs.uk" ) ) {
54- logger ?. info ( "Using service search v3 endpoint" )
55- SERVICE_SEARCH_BASE_QUERY_PARAMS [ "api-version" ] = 3
56- SERVICE_SEARCH_BASE_QUERY_PARAMS [ "$select" ] = "Contacts,OrganisationSubType"
57- return 3
58- }
59- logger ?. warn ( "Using service search v2 endpoint" )
60- return 2
43+ logger ?. info ( "Service search v3 enabled" )
44+ return 3
6145}
6246
6347export function getServiceSearchEndpoint ( logger : Logger | null = null ) : string {
64- switch ( getServiceSearchVersion ( logger ) ) {
65- case 3 :
66- return `https://${ process . env . TargetServiceSearchServer } /service-search-api/`
67- case 2 :
68- default :
69- return `https://${ process . env . TargetServiceSearchServer } /service-search`
70- }
48+ logger ?. info ( "Using service search v3 endpoint" )
49+ return `https://${ process . env . TargetServiceSearchServer } /service-search-api/`
7150}
7251
7352export class LiveServiceSearchClient implements ServiceSearchClient {
@@ -76,7 +55,6 @@ export class LiveServiceSearchClient implements ServiceSearchClient {
7655 private readonly httpsAgent : Agent
7756 private readonly outboundHeaders : {
7857 "apikey" ?: string ,
79- "Subscription-Key" ?: string ,
8058 "x-request-id" ?: string ,
8159 "x-correlation-id" ?: string
8260 }
@@ -85,7 +63,6 @@ export class LiveServiceSearchClient implements ServiceSearchClient {
8563 this . logger = logger
8664 this . logger . info ( "ServiceSearchClient configured" ,
8765 {
88- v2 : process . env . ServiceSearchApiKey !== undefined ,
8966 v3 : process . env . ServiceSearch3ApiKey !== undefined
9067 } )
9168 this . httpsAgent = new Agent ( {
@@ -149,15 +126,8 @@ export class LiveServiceSearchClient implements ServiceSearchClient {
149126 return Promise . reject ( err )
150127 } )
151128
152- const version = getServiceSearchVersion ( this . logger )
153- if ( version === 3 ) {
154- this . outboundHeaders = {
155- "apikey" : process . env . ServiceSearch3ApiKey
156- }
157- } else {
158- this . outboundHeaders = {
159- "Subscription-Key" : process . env . ServiceSearchApiKey
160- }
129+ this . outboundHeaders = {
130+ "apikey" : process . env . ServiceSearch3ApiKey
161131 }
162132 }
163133
@@ -211,11 +181,7 @@ export class LiveServiceSearchClient implements ServiceSearchClient {
211181
212182 this . logger . info ( `received response from serviceSearch for ods code ${ odsCode } ` ,
213183 { odsCode : odsCode , status : response . status , data : response . data } )
214- if ( apiVsn === 2 ) {
215- return this . handleV2Response ( odsCode , response . data )
216- } else {
217- return this . handleV3Response ( odsCode , response . data )
218- }
184+ return this . handleV3Response ( odsCode , response . data )
219185 }
220186
221187 private getReusedSocket ( request : unknown ) : boolean | undefined {
@@ -238,26 +204,8 @@ export class LiveServiceSearchClient implements ServiceSearchClient {
238204 return serviceUrl
239205 }
240206
241- handleV2Response ( odsCode : string , data : ServiceSearchData ) : URL | undefined {
242- const services = data . value
243- if ( services . length === 0 ) {
244- return undefined
245- }
246-
247- this . logger . info ( `pharmacy with ods code ${ odsCode } is of type ${ DISTANCE_SELLING } ` , { odsCode : odsCode } )
248- const service = services [ 0 ]
249- const urlString = service [ "URL" ]
250-
251- if ( urlString === null ) {
252- this . logger . warn ( `ods code ${ odsCode } has no URL but is of type ${ DISTANCE_SELLING } ` , { odsCode : odsCode } )
253- return undefined
254- }
255- const serviceUrl = handleUrl ( urlString , odsCode , this . logger )
256- return serviceUrl
257- }
258-
259207 stripApiKeyFromHeaders ( error : AxiosError ) {
260- const headerKeys = [ "subscription-key" , " apikey"]
208+ const headerKeys = [ "apikey" ]
261209 headerKeys . forEach ( ( key ) => {
262210 if ( error . response ?. headers ?. [ key ] ) {
263211 delete error . response . headers [ key ]
0 commit comments