import { removeFileExtension } from '@sap-cloud-sdk/util' ; import levenstein from 'fast-levenshtein' ; import { getSdkVersion } from './util' ; import { Client , GenerationAndUsage , PregeneratedLibrary , SdkMetadataHeader , ServiceStatus } from './sdk-metadata-types' ; const distanceThreshold = 5 ; internal export function getSdkMetadataFileNames ( originalFileName ) { return { clientFileName : `${ originalFileName }_CLIENT_JS.json` , headerFileName : `${ originalFileName }_HEADER.json` } ; } internal export async function sdkMetadataHeader ( type , originalFileName , versionInPackageJson ? ) { return { type , name : removeFileExtension ( originalFileName ) , version : await getVersionForClient ( versionInPackageJson ) , introText : sdkMetadataHeaderIntroText } ; } internal export async function getVersionForClient ( versionInPackageJson ? ) { return versionInPackageJson || getSdkVersion ( ) ; } internal export function getSdkMetadataClient ( generationAndUsage , pregeneratedLibrary ? ) { const status = pregeneratedLibrary ? ServiceStatusValues . certified : ServiceStatusValues . verified ; return { language : 'JavaScript' , serviceStatus : status , pregeneratedLibrary , generationAndUsage } ; } param name param objectsToCheck param extractorFn returns internal export function getLevenshteinClosest < T > ( name , objectsToCheck , extractorFn ) { const distBelowThreshold = objectsToCheck . reduce ( ( prev , obj ) => { const levenshteinDist = getLevenshteinDistance ( name , extractorFn ( obj ) ) ; if ( levenshteinDist < distanceThreshold ) { return [ ... prev , { dist : levenshteinDist , obj } ] ; } return prev ; } , [ ] ) ; if ( distBelowThreshold . length > 0 ) { return distBelowThreshold . sort ( ( a , b ) => ( a . dist < b . dist ? - 1 : 1 ) ) [ 0 ] . obj ; } } function getLevenshteinDistance ( stringA , stringB ) { return levenstein . get ( getSanitizedString ( stringA ) , getSanitizedString ( stringB ) ) ; } function getSanitizedString ( text ) { return text . replace ( /[^A-Za-z]/g , '' ) . toLowerCase ( ) ; } internal export const sdkMetadataHeaderIntroText = 'The SAP Cloud SDK is a versatile set of libraries and tools for developers to build cloud-native applications on the SAP Business Technology Platform. To simplify the consumption of multiple services published on the SAP API Business Hub, the SDK offers code generators for OData and OpenAPI together with pregenerated typed client libraries. These libraries are seamlessly integrated with connectivity, authentication, multi-tenancy, and other abstractions to speed up application development.' ; internal export const ServiceStatusValues = { certified : { status : 'certified' , statusText : 'API Client available for download' , statusLongText : 'You can download our pregenerated API client for this API.' } , verified : { status : 'verified' , statusText : 'API Client generation tested but no download available' , statusLongText : 'The SAP Cloud SDK team checked for this API that generating an API client works, but no pregenerated client is available. You can generate your own client for this API.' } , unknown : { status : 'unknown' , statusText : 'API Client generation not tested' , statusLongText : 'The SAP Cloud SDK team has not tested if generating an API client for this API works. You might try to generate a client for this API if you need one.' } , failed : { status : 'failed' , statusText : 'API Client generation has failed' , statusLongText : 'The SAP Cloud SDK team checked for this API if generating an API client works, which has failed. You might try it on your own.' } } ;