export type OnlineAccessUrl = { /** * - The generated file URL. */ URL: string; /** * - The description of the URL (used by ECHO10). */ URLDescription: string; /** * - The description of the URL (used by UMMG). */ Description: string; /** * - The type of the URL (used by ECHO10/UMMG). */ Type: string; }; export type CMRConstructorParams = import('@cumulus/cmr-client/CMR').CMRConstructorParams; export type DistributionBucketMap = import('@cumulus/distribution-utils/dist/types').DistributionBucketMap; export type ApiFileGranuleIdOptional = import('@cumulus/types').ApiFileGranuleIdOptional; export type ApiFileWithFilePath = ApiFileGranuleIdOptional & { filepath?: string; }; export type CmrFile = { /** * - The S3 bucket name */ bucket: string; /** * - The S3 key for the metadata file */ key: string; /** * - The granule ID associated with the file */ granuleId: string; /** * - Optional entity tag for file versioning */ etag?: string | undefined; }; /** * * /** */ export type CmrCredentials = { provider: string; clientId: string; username?: string; password?: string; token?: string; }; export type Echo10URLObject = { URL: string; Type?: string | undefined; Description?: string | undefined; URLDescription?: string | undefined; }; export type Echo10MetadataObject = { /** * - The root ECHO10 granule object */ Granule: { OnlineAccessURLs?: { OnlineAccessURL?: Echo10URLObject[] | undefined; } | undefined; OnlineResources?: { OnlineResource?: Echo10URLObject[] | undefined; } | undefined; AssociatedBrowseImageUrls?: { ProviderBrowseUrl?: Echo10URLObject[] | undefined; } | undefined; }; }; export type getS3UrlOfFileFile = { /** * - Full S3 URI (e.g., s3://bucket/key) */ filename?: string | undefined; /** * - Bucket name (used with `key` or `filepath`) */ bucket?: string | undefined; /** * - S3 key (used with `bucket`) */ key?: string | undefined; /** * - Alternate key for the file within the bucket */ filepath?: string | undefined; }; /** * Add ETags to file objects as some downstream functions expect this structure. * * @param {Object} granule - input granule object * @param {Object} etags - map of s3URIs and ETags * @returns {Object} - updated granule object */ export function addEtagsToFileObjects(granule: Object, etags: Object): Object; /** * Creates the query object used in POSTing to CMR. * This query is a compound conditional using JSONQueryLanguage supported by CMR. * This returns every collection that matches any of the short_name version pairs provided. * the final query should be like * {"condition": * { "or": [{ "and": [{"short_name": "sn1"}, {"version": "001"}] }, * { "and": [{"short_name": "sn2"}, {"version": "006"}] }, * { "and": [{"short_name": "sn3"}, {"version": "001"}] }, * .... ] } } * * @param {Array} results - objects with keys "short_name" and "version" * @returns {Object} - query object for a post to CMR that will return all of the collections that * match any of the results. */ export function buildCMRQuery(results: Array): Object; export function constructCmrConceptLink(conceptId: any, extension: any): string; /** * @typedef {Object} OnlineAccessUrl * @property {string} URL - The generated file URL. * @property {string} URLDescription - The description of the URL (used by ECHO10). * @property {string} Description - The description of the URL (used by UMMG). * @property {string} Type - The type of the URL (used by ECHO10/UMMG). */ /** * Construct online access url for a given file and a url type. * * @param {Object} params * @param {ApiFileWithFilePath} params.file - File object * @param {string} params.distEndpoint - Distribution endpoint from config * @param {{ [key: string]: string }} params.bucketTypes - Map of bucket names to bucket types * @param {'distribution' | 's3'} params.urlType - URL type: 'distribution' or 's3' * @param {DistributionBucketMap} params.distributionBucketMap - Map of bucket to distribution path * @param {boolean} [params.useDirectS3Type=false] - Whether to use direct S3 Type * @returns {Echo10URLObject | undefined} - Online access URL object, or undefined if not applicable */ export function constructOnlineAccessUrl({ file, distEndpoint, bucketTypes, urlType, distributionBucketMap, useDirectS3Type, }: { file: ApiFileWithFilePath; distEndpoint: string; bucketTypes: { [key: string]: string; }; urlType: 'distribution' | 's3'; distributionBucketMap: DistributionBucketMap; useDirectS3Type?: boolean | undefined; }): Echo10URLObject | undefined; /** * Construct a list of online access urls grouped by link type. * * @param {Object} params * @param {ApiFileWithFilePath[]} params.files - Array of file objects * @param {string} params.distEndpoint - Distribution endpoint from config * @param {{ [key: string]: string }} params.bucketTypes - Map of bucket name to bucket type * @param {DistributionBucketMap} params.distributionBucketMap - Mapping of bucket to * distribution path * @param {string} [params.cmrGranuleUrlType=both] - Granule URL type: 's3', * 'distribution', or 'both' * @param {boolean} [params.useDirectS3Type=false] - Whether direct S3 URL types are used * @returns {Echo10URLObject[]} Array of online access URL objects */ export function constructOnlineAccessUrls({ bucketTypes, cmrGranuleUrlType, distEndpoint, distributionBucketMap, files, useDirectS3Type, }: { files: ApiFileWithFilePath[]; distEndpoint: string; bucketTypes: { [key: string]: string; }; distributionBucketMap: DistributionBucketMap; cmrGranuleUrlType?: string | undefined; useDirectS3Type?: boolean | undefined; }): Echo10URLObject[]; export function generateEcho10XMLString(granule: any): string; /** * generate a url for a given file and a url type. * * @param {Object} params - input parameters * @param {Object} params.file - file object * @param {string} params.distEndpoint - distribution endpoint from config * @param {string} [params.urlType = 'distribution'] - url type, distribution or s3 * @param {Object} params.distributionBucketMap - Object with bucket:tea-path mapping * for all distribution buckets * @returns {(string | undefined)} online access url object, undefined if no URL exists */ export function generateFileUrl({ file, distEndpoint, urlType, distributionBucketMap, }: { file: Object; distEndpoint: string; urlType?: string | undefined; distributionBucketMap: Object; }): (string | undefined); /** * Get collectionId from cmr metadata * @param {object} cmrObject - cmr metadata object * @param {string} cmrFileName - used to know how to parse this object * @returns {string} */ export function getCMRCollectionId(cmrObject: object, cmrFileName: string): string; /** * Helper to build an CMR settings object, used to initialize CMR. * * @param {Object} cmrConfig - CMR configuration object * @param {string} cmrConfig.oauthProvider - Oauth provider: launchpad or earthdata * @param {string} cmrConfig.provider - the CMR provider * @param {string} cmrConfig.clientId - Client id for CMR requests * @param {string} cmrConfig.passphraseSecretName - Launchpad passphrase secret name * @param {string} cmrConfig.api - Launchpad api * @param {string} cmrConfig.certificate - Launchpad certificate * @param {string} cmrConfig.username - EDL username * @param {string} cmrConfig.passwordSecretName - CMR password secret name * @returns {Promise} object to create CMR instance - contains the * provider, clientId, and either launchpad token or EDL username and * password */ export function getCmrSettings(cmrConfig?: { oauthProvider: string; provider: string; clientId: string; passphraseSecretName: string; api: string; certificate: string; username: string; passwordSecretName: string; }): Promise; /** * Call CMR to get the all matching Collections information with a compound query call. * * @param {Array} results - pared results from a Cumulus collection search. * @returns {Promise} - resolves to the CMR return * containing the found collections */ export function getCollectionsByShortNameAndVersion(results: Array): Promise; export function getFileDescription(file: any, urlType?: string): string; /** * Returns the file 'name' of a given object. * * Accepts multiple file shapes commonly used throughout Cumulus and resolves * them to a valid `s3://bucket/key` URI. * * @param {ApiFileWithFilePath} file - API File * @returns {string | undefined} - The file name, or undefined if not found */ export function getFilename(file: ApiFileWithFilePath): string | undefined; /** * Extract temporal information from granule object * * @param {Object} granule - granule object * @returns {Promise} * - temporal information (beginningDateTime, * endingDateTime, productionDateTime, lastUpdateDateTime) of the granule if * available. */ export function getGranuleTemporalInfo(granule: Object): Promise; /** * Returns the S3 URI for a given file object. * * Accepts multiple file shapes commonly used throughout Cumulus and resolves * them to a valid `s3://bucket/key` URI. * * @param {getS3UrlOfFileFile} file - File object containing filename or bucket/key data * @returns {string} - A string representing the S3 URI (e.g., `s3://bucket/key`) * @throws {Error} if the file does not contain enough information to construct the URI */ export function getS3UrlOfFile(file: getS3UrlOfFileFile): string; /** * Call CMR to get a list of bucket/paths that a user has access to * * @param {string} edlUser - users earthdata login name * @param {string} cmrProvider - cumulus CMR provider name * @returns {Object} list of bucket/paths that a user has access to */ export function getUserAccessibleBuckets(edlUser: string, cmrProvider?: string): Object; /** * Gets metadata for a CMR XML file from S3. * * @param {string} xmlFilePath - S3 URI to the XML metadata document * @param {string} [etag] - optional entity tag for the desired version of the * CMR file * @returns {Promise} stringified XML document downloaded from S3 */ export function getXMLMetadataAsString(xmlFilePath: string, etag?: string | undefined): Promise; /** * Reduce granule object array to CMR files array * * @param {Array} granules - granule objects array * @param {Function} filterFunc - function to determine if the given file object is a CMR file; defaults to `isCMRFile` * * @returns {Array} - CMR file object array: { etag, bucket, key, granuleId } */ export function granulesToCmrFileObjects(granules: Array, filterFunc?: Function): Array; /** * Extracts CMR file objects from the specified granule object. * * @param {Object} granule - granule object containing CMR files within its * `files` property * @param {Array} granule.files - array of files for a granule * @param {string} granule.granuleId - granule ID * @param {Function} filterFunc - function to determine if the given file object is a CMR file; defaults to `isCMRFile` * @returns {Array} an array of CMR file objects, each with properties * `granuleId`, `bucket`, `key`, and possibly `etag` (if present on input) */ export function granuleToCmrFileObject({ granuleId, files }: { files: Array; granuleId: string; }, filterFunc?: Function): Array; /** * Returns True if this object can be determined to be a cmrMetadata object. * * @param {Object} fileobject * @returns {boolean} true if object references cmr metadata. */ export function isCMRFile(fileobject: Object): boolean; export function isCMRFilename(filename: any): any; export function isCMRISOFilename(filename: any): any; export function isECHO10Filename(filename: any): any; /** * Returns True if this object can be determined to be an ISO file object. * * @param {Object} fileobject * @returns {boolean} true if object references an ISO file metadata. */ export function isISOFile(fileobject: Object): boolean; export function isISOFilename(filename: any): any; export function isUMMGFilename(filename: any): any; /** * Maps etag values from the specified granules' files. * * @param {Object[]} files - array of file objects with `bucket`, `key` and * `etag` properties * @returns {Object} mapping of file S3 URIs to etags */ export function mapFileEtags(files: Object[]): Object; /** * Returns CMR metadata object from a CMR ECHO-10 XML file or CMR UMMG JSON * file in S3. * * @param {string} cmrFilename - S3 path to CMR file * @param {string} [etag] - optional entity tag for the desired version of the * CMR file * @returns {Promise} metadata object from the file * @throws {Error} if the specified filename does not represent an ECHO-10 XML * file or a UMMG file * @see isECHO10Filename * @see isUMMGFilename */ export function metadataObjectFromCMRFile(cmrFilename: string, etag?: string | undefined): Promise; /** * Parse an xml string * * @param {string} xml - xml to parse * @returns {Promise} promise resolves to object version of the xml */ export function parseXmlString(xml: string): Promise; /** * Determines what type of metadata object and posts either ECHO10XML or UMMG * JSON data to CMR. * * @param {Object} cmrPublishObject - * @param {string} cmrPublishObject.filename - the cmr filename * @param {Object} cmrPublishObject.metadataObject - the UMMG JSON cmr metadata * @param {Object} cmrPublishObject.granuleId - the metadata's granuleId * @param {Object} creds - credentials needed to post to CMR service * @param {string} creds.provider - the name of the Provider used on the CMR side * @param {string} creds.clientId - the clientId used to generate CMR token * @param {string} creds.username - the CMR username, not used if creds.token is provided * @param {string} creds.password - the CMR password, not used if creds.token is provided * @param {string} creds.token - the CMR or Launchpad token, * @param {string} cmrRevisionId - Optional CMR Revision ID * if not provided, CMR username and password are used to get a cmr token */ export function publish2CMR(cmrPublishObject: { filename: string; metadataObject: Object; granuleId: Object; }, creds: { provider: string; clientId: string; username: string; password: string; token: string; }, cmrRevisionId: string): Promise; /** * Update CMR Metadata record with the information contained in updatedFiles * @param {Object} params - parameter object * @param {string} params.granuleId - granuleId * @param {Object} params.updatedFiles - list of file objects that might have different * information from the cmr metadatafile and the CMR service. * @param {string} params.distEndpoint - distribution endpoint URL * @param {boolean} params.published - boolean true if the data should be published to * the CMR service. * @param {{ [key: string]: string }} params.bucketTypes - map of bucket names to bucket types * @param {string} params.cmrGranuleUrlType - type of granule CMR url * @param {distributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path mapping * for all distribution buckets */ export function reconcileCMRMetadata({ granuleId, updatedFiles, distEndpoint, published, bucketTypes, cmrGranuleUrlType, distributionBucketMap, }: { granuleId: string; updatedFiles: Object; distEndpoint: string; published: boolean; bucketTypes: { [key: string]: string; }; cmrGranuleUrlType: string; distributionBucketMap: any; }): Promise; /** * Remove ETags to match output schema * * @param {Object} granule - output granule object * @returns {undefined} */ export function removeEtagsFromFileObjects(granule: Object): undefined; /** * Remove granule from CMR. * * @param {string} granuleUR - the granuleUR * @param {CmrCredentials} creds - credentials needed to post to CMR service */ export function removeFromCMR(granuleUR: string, creds: CmrCredentials): Promise; /** * Update collection in an ECHO10 cmr metadata object * * @param {object} cmrObject - CMR metadata object * @param {{ name: string, version: string }} collection - collection name and version to update to * @returns {object} */ export function setECHO10Collection(cmrObject: object, collection: { name: string; version: string; }): object; /** * Update collection in an UMMG cmr metadata object * * @param {object} cmrObject - CMR metadata object * @param {{ name: string, version: string }} collection - collection name and version to update to * @returns {object} */ export function setUMMGCollection(cmrObject: object, collection: { name: string; version: string; }): object; /** * Modifies cmr metadata file with file's URLs updated to their new locations. * * @param {Object} params - parameter object * @param {string} params.granuleId - granuleId * @param {string} [params.producerGranuleId] - producer granuleId * @param {CmrFile} params.cmrFile - cmr file to be updated * @param {ApiFileWithFilePath[]} params.files - array of file objects * @param {string} params.distEndpoint - distribution enpoint from config * @param {boolean} params.published - indicate if publish is needed * @param {{ [key: string]: string }} params.bucketTypes - map of bucket names to bucket types * @param {string} params.cmrGranuleUrlType - type of granule CMR url * @param {boolean} [params.updateGranuleIdentifiers=false] * - If true, update the GranuleUR and ProducerGranuleId in metadata * @param {boolean} [params.excludeDataGranule=false] - Whether to add or update the DataGranule * node in the granule's metadata * @param {any} [params.testOverrides] * - Optional test overrides for internal functions * @param {DistributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path * mapping for all distribution buckets * @returns {Promise} CMR file object with the `etag` of the newly * updated metadata file */ export function updateCMRMetadata({ granuleId, producerGranuleId, cmrFile, files, distEndpoint, published, bucketTypes, cmrGranuleUrlType, updateGranuleIdentifiers, excludeDataGranule, distributionBucketMap, testOverrides, }: { granuleId: string; producerGranuleId?: string | undefined; cmrFile: CmrFile; files: ApiFileWithFilePath[]; distEndpoint: string; published: boolean; bucketTypes: { [key: string]: string; }; cmrGranuleUrlType: string; updateGranuleIdentifiers?: boolean | undefined; excludeDataGranule?: boolean | undefined; testOverrides?: any; distributionBucketMap: DistributionBucketMap; }): Promise; /** * Updates an ECHO10 CMR XML metadata file on S3 to reflect new URLs and optionally * a new GranuleUR and ProducerGranuleId. * * @param {Object} params * @param {string} params.granuleId - New GranuleUR to set in metadata * @param {string} params.producerGranuleId - Original ProducerGranuleId to record * @param {CmrFile} params.cmrFile - The cmr xml file to be updated * @param {ApiFileWithFilePath[]} params.files - List of granule files used * to generate OnlineAccess URLs * @param {string} params.distEndpoint - Distribution endpoint for download URLs * @param {{ [bucket: string]: string }} params.bucketTypes - Mapping of bucket names to their types * @param {string} [params.cmrGranuleUrlType] * - Type of URLs to generate ('distribution' | 's3' | 'both') * @param {DistributionBucketMap} params.distributionBucketMap * - Maps buckets to distribution paths * @param {boolean} [params.updateGranuleIdentifiers=false] * - If true, update the GranuleUR and ProducerGranuleId in metadata * @param {boolean} [params.excludeDataGranule=false] - Whether to add or update the DataGranule * node in the granule's metadata * @param {any} [params.testOverrides] * - Optional test overrides for internal functions * @returns {Promise<{ metadataObject: any, etag: string }>} * The updated metadata object and resulting ETag */ export function updateEcho10XMLMetadata({ granuleId, producerGranuleId, cmrFile, files, distEndpoint, bucketTypes, cmrGranuleUrlType, distributionBucketMap, updateGranuleIdentifiers, excludeDataGranule, testOverrides, }: { granuleId: string; producerGranuleId: string; cmrFile: CmrFile; files: ApiFileWithFilePath[]; distEndpoint: string; bucketTypes: { [bucket: string]: string; }; cmrGranuleUrlType?: string | undefined; distributionBucketMap: DistributionBucketMap; updateGranuleIdentifiers?: boolean | undefined; excludeDataGranule?: boolean | undefined; testOverrides?: any; }): Promise<{ metadataObject: any; etag: string; }>; /** * Updates the OnlineAccessURLs, OnlineResources, and AssociatedBrowseImageUrls * fields of an ECHO10 CMR metadata object with newly constructed URLs. * * This function: * - Extracts the original URL sets from the ECHO10 XML metadata. * - Constructs new URL entries based on the provided file list and configuration. * - Merges new URLs with original ones, removing outdated or irrelevant URLs. * - Returns a new metadata object with an updated `Granule` field. * * @param {Object} params - Input parameters * @param {Echo10MetadataObject} params.metadataObject - The parsed ECHO10 metadata XML * object (as a JavaScript object), expected to include a `Granule` key * @param {ApiFileWithFilePath[]} params.files - Granule files to generate * updated URLs from * @param {string} params.distEndpoint - The base distribution endpoint URL * (e.g., CloudFront origin) * @param {{ [bucketName: string]: string }} params.bucketTypes - Mapping of bucket names * to access types ('public', 'protected', etc.) * @param {string} [params.cmrGranuleUrlType='both'] - Type of URLs to generate * for CMR: 'distribution', 's3', or 'both' * @param {DistributionBucketMap} params.distributionBucketMap - Maps S3 buckets to their * distribution URL paths * * @returns {Echo10MetadataObject} A new ECHO10 metadata object with updated * `Granule.OnlineAccessURLs`, `Granule.OnlineResources`, and `Granule.AssociatedBrowseImageUrls` * fields */ export function updateEcho10XMLMetadataObjectUrls({ metadataObject, files, distEndpoint, bucketTypes, cmrGranuleUrlType, distributionBucketMap, }: { metadataObject: Echo10MetadataObject; files: ApiFileWithFilePath[]; distEndpoint: string; bucketTypes: { [bucketName: string]: string; }; cmrGranuleUrlType?: string | undefined; distributionBucketMap: DistributionBucketMap; }): Echo10MetadataObject; /** * After files are moved, create new online access URLs and then update the S3 * UMMG cmr.json file with this information. * * @param {Object} params - parameter object * @param {CmrFile} params.cmrFile - cmr.json file whose contents will be updated. * @param {ApiFileWithFilePath[]} params.files - array of moved file objects. * @param {string} params.distEndpoint - distribution endpoint form config. * @param {{ [bucket: string]: string }} params.bucketTypes - map of bucket names to bucket types * @param {string} params.cmrGranuleUrlType - cmrGranuleUrlType from config * @param {DistributionBucketMap} params.distributionBucketMap - Object with bucket:tea-path * mapping for all distribution buckets * @param {string} params.producerGranuleId - producer granule id * @param {string} params.granuleId - granule id * @param {boolean} [params.updateGranuleIdentifiers=false] - whether to update the granule UR/add * producerGranuleID to the CMR metadata object * @param {boolean} [params.excludeDataGranule=false] - whether to add or update the DataGranule * node in the granule's metadata * @param {any} [params.testOverrides] - overrides for testing * @returns {Promise<{ metadataObject: Object, etag: string | undefined}>} an object * containing a `metadataObject` (the updated UMMG metadata object) and the * `etag` of the uploaded CMR file */ export function updateUMMGMetadata({ cmrFile, files, distEndpoint, bucketTypes, cmrGranuleUrlType, distributionBucketMap, producerGranuleId, granuleId, updateGranuleIdentifiers, excludeDataGranule, testOverrides, }: { cmrFile: CmrFile; files: ApiFileWithFilePath[]; distEndpoint: string; bucketTypes: { [bucket: string]: string; }; cmrGranuleUrlType: string; distributionBucketMap: DistributionBucketMap; producerGranuleId: string; granuleId: string; updateGranuleIdentifiers?: boolean | undefined; excludeDataGranule?: boolean | undefined; testOverrides?: any; }): Promise<{ metadataObject: Object; etag: string | undefined; }>; /** * Update the UMMG cmr metadata object to have corrected urls * * @param {Object} params - Parameters for updating the metadata object * @param {Object} params.metadataObject - The existing UMMG CMR metadata object to update * @param {ApiFileWithFilePath[]} params.files - Array of file * objects used to generate URLs * @param {string} params.distEndpoint - Base URL for distribution endpoints (e.g., CloudFront) * @param {{ [bucket: string]: string }} params.bucketTypes - Map of bucket names * to types (e.g., public, protected) * @param {string} [params.cmrGranuleUrlType='both'] - Type of URLs to generate: 'distribution', * 's3', or 'both' * @param {DistributionBucketMap} params.distributionBucketMap - Mapping of bucket names to * distribution paths * * @returns {Object} - A deep clone of the original metadata object with updated RelatedUrls */ export function updateUMMGMetadataObject({ metadataObject, files, distEndpoint, bucketTypes, cmrGranuleUrlType, distributionBucketMap, }: { metadataObject: Object; files: ApiFileWithFilePath[]; distEndpoint: string; bucketTypes: { [bucket: string]: string; }; cmrGranuleUrlType?: string | undefined; distributionBucketMap: DistributionBucketMap; }): Object; /** * Updates CMR xml file with 'xml' string * * @param {string} xml - XML to write to cmrFile * @param {Object} cmrFile - cmr file object to write xml to * @returns {Promise} returns promised promiseS3Upload response */ export function uploadEcho10CMRFile(xml: string, cmrFile: Object): Promise; /** * Updates CMR JSON file with stringified 'metadataObject' * * @param {Object} metadataObject - JSON Object to stringify * @param {CmrFile} cmrFile - cmr file object to write body to * @returns {Promise<{[key: string]: any, ETag?: string | undefined }>} returns promised * promiseS3Upload response */ export function uploadUMMGJSONCMRFile(metadataObject: Object, cmrFile: CmrFile): Promise<{ [key: string]: any; ETag?: string | undefined; }>; //# sourceMappingURL=cmr-utils.d.ts.map