import { Headers } from 'got'; import { CMRResponseBody, CMRErrorResponseBody } from './types'; import { UmmMetadata } from './UmmUtils'; export interface CMRConstructorParams { clientId: string; password?: string; passwordSecretName?: string; token?: string; username?: string; oauthProvider: string; passphrase?: string; api?: string; certificate?: string; } /** * A class to simplify requests to the CMR * * @typicalname cmrClient * * @example * const { CMR } = require('@cumulus/cmr-client'); * * const cmrClient = new CMR({ * provider: 'my-provider', * clientId: 'my-clientId', * username: 'my-username', * password: 'my-password' * }); * * or * * const cmrClient = new CMR({ * provider: 'my-provider', * clientId: 'my-clientId', * token: 'cmr_or_launchpad_token' * }); * TODO: this should be subclassed or refactored to a functional style * due to branch logic/complexity in token vs password/username handling */ export declare class CMR { private static instance?; private refreshPromise?; clientId: string; username?: string; oauthProvider: string; password?: string; passwordSecretName?: string; token?: string; passphrase?: string; api?: string; certificate?: string; /** * The constructor for the CMR class */ private constructor(); /** * Creates a new CMR singleton instance of one does not already exist, * if one does, returns it * @returns {CMR} - the existing or newly made CMR instance */ static getInstance(params: CMRConstructorParams): CMR; /** * Get the CMR password, from the AWS secret if set, else return the password * @returns {Promise.} - the CMR password */ getCmrPassword(): Promise; /** * Resets the CMR singleton instance to undefined, only used for testing with * suites that create multiple instances in sequence. */ static resetInstance(): void; /** * The method for getting the token * * @returns {Promise.} the token */ getToken(): Promise; /** * Checks if a process calling the cmrClient is in the middle of creating a new launchpad token. * This function is called when a 401 launchpad auth error is encountered when using a launchpad * token for cmr calls. It calls refreshLaunchpadToken and stores the refreshPromise * so other calls that want to get a launchpad token know that a process is already doing that. * * @returns {Promise.} refresh promise */ checkRefreshLaunchpadToken(): Promise; /** * Refreshes the launchpad token due to authentication failures with launchpad. This function * calls getValidLaunchpadToken which creates a lock file in S3 at the token's location, to tell * other processes that a token recreation is in progress, fetches a new token from launchpad, * stores it as a part of the CMR singleton class, and then uses that one for calls * * @returns {Promise.} refresh promise */ private refreshLaunchpadToken; /** * Runs a CMR operation with retry logic for launchpad failures. If the operation fails with a * 401, refresh the Launchpad token and retry. * * @param {Function} operation - the CMR function with args to execute * @param {number} [retries=5] - number of retry attempts on 401 * @returns {Promise} - result of CMR function call */ withCmrLaunchpadTokenRefreshRetry(operation: () => Promise, retries?: number): Promise; /** * Return object containing CMR request headers for PUT / POST / DELETE * * @param {Object} params * @param {string} [params.token] - CMR request token * @param {string} [params.ummgVersion] - UMMG metadata version string or null if echo10 metadata * @param {string} [params.cmrRevisionId] - CMR Revision ID * @returns {Object} CMR headers object */ getWriteHeaders(params?: { token?: string; ummgVersion?: string; cmrRevisionId?: string; }): Headers; /** * Return object containing CMR request headers for GETs * * @param {Object} params * @param {string} [params.token] - CMR request token * @returns {Object} CMR headers object */ getReadHeaders(params?: { token?: string; }): Headers; /** * Adds a collection record to the CMR * * @param {string} xml - the collection XML document * @param {string} provider - the CMR provider to target * @returns {Promise.} the CMR response */ ingestCollection(xml: string, provider: string): Promise; /** * Adds a granule record to the CMR * * @param {string} xml - the granule XML document * @param {string} provider - the CMR provider to target * @param {string} cmrRevisionId - Optional CMR Revision ID * @returns {Promise.} the CMR response */ ingestGranule(xml: string, provider: string, cmrRevisionId?: string): Promise; /** * Adds/Updates UMMG json metadata in the CMR * * @param {Object} ummgMetadata - UMMG metadata object * @param {string} provider - the CMR provider to target * @param {string} cmrRevisionId - Optional CMR Revision ID * @returns {Promise} to the CMR response object. */ ingestUMMGranule(ummgMetadata: UmmMetadata, provider: string, cmrRevisionId?: string): Promise; /** * Deletes a collection record from the CMR * * @param {string} datasetID - the collection unique id * @param {string} provider - the CMR provider to target * @returns {Promise.} the CMR response */ deleteCollection(datasetID: string, provider: string): Promise; /** * Deletes a granule record from the CMR * * @param {string} granuleUR - the granule unique id * @param {string} provider - the CMR provider to target * @returns {Promise.} the CMR response */ deleteGranule(granuleUR: string, provider: string): Promise; searchConcept(type: string, searchParams: URLSearchParams, format?: string, recursive?: boolean): Promise; /** * Search in collections * * @param {string} params - the search parameters * @param {string} provider - the CMR provider to target * @param {string} [format=json] - format of the response * @returns {Promise.} the CMR response */ searchCollections(params: { [key: string]: string; }, provider: string, format?: string): Promise; /** * Search in granules * * @param {string} params - the search parameters * @param {string} provider - the CMR provider to target * @param {string} [format='json'] - format of the response * @returns {Promise.} the CMR response */ searchGranules(params: { [key: string]: string; }, provider: string, format?: string): Promise; /** * Get the granule metadata from CMR using the cmrLink * * @param {string} cmrLink - URL to concept * @returns {Object} - metadata as a JS object, null if not found */ getGranuleMetadata(cmrLink: string): Promise; } //# sourceMappingURL=CMR.d.ts.map