diff --git a/README.md b/README.md index 53fe10e..834369c 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,14 @@ The available APIActions are: `Create`, `Read`, `Update`, `Delete` and `New_Vers const artifactType = sciRestClient.getArtifactType(''); ``` +#### Get artifact artifact metadata + +```js +const artifactMetadata = sciRestClient.getArtifactMetadata(''); +``` + +Returns an object containing the id, name, version and type of the artifact in the specified directory. + # Test The package is implemented in TypeScript and [Vitest](https://vitest.dev/) is used as a test framework. The tests need to run against a real Integration content API endpoint. The API endpoint and the credentials are read from environment variables. For executing the tests create a `.env`file inside the root directory of the package diff --git a/src/lib/client/SCIRestClient.ts b/src/lib/client/SCIRestClient.ts index f12e914..7d25cee 100644 --- a/src/lib/client/SCIRestClient.ts +++ b/src/lib/client/SCIRestClient.ts @@ -137,6 +137,8 @@ export default class SCIRestClient { * @param {string} artifactVersion - The version of the artifact. * @param {ArtifactType} artifactType - The type of the artifact. * + * @returns {Promise} - A read stream for the artifact or void if an error occurred. + * */ async getArtifact(artifactId: string, artifactVersion: string, artifactType: ArtifactType): Promise { log.info(`Reading artifact ${artifactId}...`); @@ -364,6 +366,18 @@ export default class SCIRestClient { return manifestReader.getArtifactMetadata().Type; } + /** + * Returns the metadata of the artifact in the given directory. + * + * @param {string} artifactDirectoryPath - Path to the directory containing the artifact. + * + * @returns {Artifact} - The metadata of the artifact. + */ + public getArtifactMetadata(artifactDirectoryPath: string) { + const manifestReader = new ManifestReader(artifactDirectoryPath); + return manifestReader.getArtifactMetadata(); + } + private invalidateCSRFToken() { this.csrfToken = ''; this.cookie = []; diff --git a/src/test/integration/IntegrationFlow.test.ts b/src/test/integration/IntegrationFlow.test.ts index a78c650..c5d31f6 100644 --- a/src/test/integration/IntegrationFlow.test.ts +++ b/src/test/integration/IntegrationFlow.test.ts @@ -70,4 +70,11 @@ describe('Integration flow', () => { expect(sciRestClient.isActionSupported(APIAction.New_Version, iFlowDirectory)).toBe(true); expect(sciRestClient.isActionSupported(APIAction.Delete, iFlowDirectory)).toBe(false); }); + + it('provides the metadata for the artifact in the given directory', () => { + expect(sciRestClient.getArtifactMetadata(iFlowDirectory).Id).toBe('IntegrationFlow'); + expect(sciRestClient.getArtifactMetadata(iFlowDirectory).Version).toBe('2.0.0'); + expect(sciRestClient.getArtifactMetadata(iFlowDirectory).Name).toBe('Integration Flow'); + expect(sciRestClient.getArtifactMetadata(iFlowDirectory).Type).toBe('IntegrationFlow'); + }); }); diff --git a/src/test/integration/MessageMapping.test.ts b/src/test/integration/MessageMapping.test.ts index 15873b2..61f9ee9 100644 --- a/src/test/integration/MessageMapping.test.ts +++ b/src/test/integration/MessageMapping.test.ts @@ -70,4 +70,11 @@ describe('Message mapping', () => { expect(sciRestClient.isActionSupported(APIAction.New_Version, messageMappingDirectory)).toBe(true); expect(sciRestClient.isActionSupported(APIAction.Delete, messageMappingDirectory)).toBe(false); }); + + it('provides the metadata for the artifact in the given directory', () => { + expect(sciRestClient.getArtifactMetadata(messageMappingDirectory).Id).toBe('MessageMapping'); + expect(sciRestClient.getArtifactMetadata(messageMappingDirectory).Version).toBe('2.0.0'); + expect(sciRestClient.getArtifactMetadata(messageMappingDirectory).Name).toBe('MessageMapping'); + expect(sciRestClient.getArtifactMetadata(messageMappingDirectory).Type).toBe('MessageMapping'); + }); }); diff --git a/src/test/integration/ScriptCollection.test.ts b/src/test/integration/ScriptCollection.test.ts index b8c1a51..3f28107 100644 --- a/src/test/integration/ScriptCollection.test.ts +++ b/src/test/integration/ScriptCollection.test.ts @@ -68,4 +68,11 @@ describe('Script collection', () => { expect(sciRestClient.isActionSupported(APIAction.New_Version, scriptCollectionDirectory)).toBe(true); expect(sciRestClient.isActionSupported(APIAction.Delete, scriptCollectionDirectory)).toBe(false); }); + + it('provides the metadata for the artifact in the given directory', () => { + expect(sciRestClient.getArtifactMetadata(scriptCollectionDirectory).Id).toBe('ScriptCollection'); + expect(sciRestClient.getArtifactMetadata(scriptCollectionDirectory).Version).toBe('2.0.0'); + expect(sciRestClient.getArtifactMetadata(scriptCollectionDirectory).Name).toBe('ScriptCollection'); + expect(sciRestClient.getArtifactMetadata(scriptCollectionDirectory).Type).toBe('ScriptCollection'); + }); }); diff --git a/src/test/integration/ValueMapping.test.ts b/src/test/integration/ValueMapping.test.ts index 1a00b83..ee25d48 100644 --- a/src/test/integration/ValueMapping.test.ts +++ b/src/test/integration/ValueMapping.test.ts @@ -68,4 +68,11 @@ describe('Value mapping', () => { expect(sciRestClient.isActionSupported(APIAction.New_Version, valueMappingDirectory)).toBe(true); expect(sciRestClient.isActionSupported(APIAction.Delete, valueMappingDirectory)).toBe(false); }); + + it('provides the metadata for the artifact in the given directory', () => { + expect(sciRestClient.getArtifactMetadata(valueMappingDirectory).Id).toBe('ValueMapping'); + expect(sciRestClient.getArtifactMetadata(valueMappingDirectory).Version).toBe('1.0.0'); + expect(sciRestClient.getArtifactMetadata(valueMappingDirectory).Name).toBe('ValueMapping'); + expect(sciRestClient.getArtifactMetadata(valueMappingDirectory).Type).toBe('ValueMapping'); + }); });