adk-typescript
Version:
TypeScript port of Google's Agent Development Kit (ADK)
102 lines (101 loc) • 3.74 kB
TypeScript
/**
* Base interface for API Hub clients
*/
export interface BaseAPIHubClient {
/**
* From a given resource name, get the spec in the API Hub.
* @param resourceName The resource name
* @returns The spec content as a string
*/
getSpecContent(resourceName: string): Promise<string>;
}
/**
* Client for interacting with the API Hub service
*/
export declare class APIHubClient implements BaseAPIHubClient {
private rootUrl;
private accessToken;
private serviceAccount;
private credentialCache;
/**
* Initializes the APIHubClient.
*
* You must set either accessToken or serviceAccountJson. This
* credential is used for sending request to API Hub API.
*
* @param params Configuration parameters
* @param params.accessToken Google Access token. Generate with gcloud cli `gcloud auth print-access-token`. Useful for local testing.
* @param params.serviceAccountJson The service account configuration as a JSON string. Required if not using default service credential.
*/
constructor(params: {
accessToken?: string;
serviceAccountJson?: string;
});
/**
* From a given path, get the first spec available in the API Hub.
*
* - If path includes /apis/apiname, get the first spec of that API
* - If path includes /apis/apiname/versions/versionname, get the first spec of that API Version
* - If path includes /apis/apiname/versions/versionname/specs/specname, return that spec
*
* Path can be resource name (projects/xxx/locations/us-central1/apis/apiname),
* and URL from the UI (https://console.cloud.google.com/apigee/api-hub/apis/apiname?project=xxx)
*
* @param path The path to the API, API Version, or API Spec.
* @returns The content of the first spec available in the API Hub.
*/
getSpecContent(path: string): Promise<string>;
/**
* Lists all APIs in the specified project and location.
*
* @param project The Google Cloud project name.
* @param location The location of the API Hub resources (e.g., 'us-central1').
* @returns A list of API objects, or an empty list if an error occurs.
*/
listApis(project: string, location: string): Promise<any[]>;
/**
* Get API detail by API name.
*
* @param apiResourceName Resource name of this API, like projects/xxx/locations/us-central1/apis/apiname
* @returns An API and details
*/
getApi(apiResourceName: string): Promise<any>;
/**
* Gets details of a specific API version.
*
* @param apiVersionName The resource name of the API version.
* @returns The API version details
*/
getApiVersion(apiVersionName: string): Promise<any>;
/**
* Retrieves the content of a specific API specification.
*
* @param apiSpecResourceName The resource name of the API spec.
* @returns The decoded content of the specification
* @private
*/
private fetchSpec;
/**
* Extracts the resource names of an API, API Version, and API Spec from a given URL or path.
*
* @param urlOrPath The URL (UI or resource) or path string.
* @returns A tuple containing the API resource name, API version resource name, and API spec resource name.
* @private
*/
private extractResourceName;
/**
* Gets the access token for service account authentication
*
* @returns The access token
* @private
*/
private getAccessToken;
/**
* Checks if the credential is expired
*
* @param credential The credential to check
* @returns True if expired, false otherwise
* @private
*/
private isCredentialExpired;
}