@@ -113,6 +113,7 @@ export async function archiveCustomer(vendorPortalApi: VendorPortalApi, customer
113113 }
114114}
115115
116+
116117export async function getUsedKubernetesDistributions ( vendorPortalApi : VendorPortalApi , appSlug : string ) : Promise < KubernetesDistribution [ ] > {
117118 const http = await vendorPortalApi . client ( ) ;
118119
@@ -151,3 +152,41 @@ export async function getUsedKubernetesDistributions(vendorPortalApi: VendorPort
151152
152153 return kubernetesDistributions ;
153154}
155+
156+ export async function listCustomersByName ( vendorPortalApi : VendorPortalApi , appSlug : string , customerName : string ) : Promise < CustomerSummary [ ] > {
157+ const http = await vendorPortalApi . client ( ) ;
158+
159+ // 1. get the app
160+ const app = await getApplicationDetails ( vendorPortalApi , appSlug ) ;
161+
162+ // 2. list customers filtered by name
163+ const listCustomersUri = `${ vendorPortalApi . endpoint } /app/${ app . id } /customers?name=${ encodeURIComponent ( customerName ) } ` ;
164+ const listCustomersRes = await http . get ( listCustomersUri ) ;
165+ if ( listCustomersRes . message . statusCode != 200 ) {
166+ let body = "" ;
167+ try {
168+ body = await listCustomersRes . readBody ( ) ;
169+ } catch ( err ) {
170+ // ignore
171+ }
172+ throw new Error ( `Failed to list customers: Server responded with ${ listCustomersRes . message . statusCode } : ${ body } ` ) ;
173+ }
174+ const listCustomersBody : any = JSON . parse ( await listCustomersRes . readBody ( ) ) ;
175+
176+ // 3. Convert response body into CustomerSummary array
177+ let customers : CustomerSummary [ ] = [ ] ;
178+
179+ // check if listCustomersBody.customers is undefined
180+ if ( ! listCustomersBody . customers ) {
181+ return customers ;
182+ }
183+
184+ for ( const customer of listCustomersBody . customers ) {
185+ customers . push ( {
186+ name : customer . name ,
187+ customerId : customer . id
188+ } ) ;
189+ }
190+
191+ return customers ;
192+ }
0 commit comments