From 2dd8ce4b398f27906f34fc36a5b203f845c57a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20Dostie?= <35579930+gdostie@users.noreply.github.com> Date: Tue, 25 Jun 2024 16:54:00 -0400 Subject: [PATCH] feat(extensions): add listVersions and getVersion methods (#836) --- src/resources/Extensions/Extensions.ts | 22 ++++++++++++++++++- .../Extensions/ExtensionsInterfaces.ts | 18 +++++++++++++++ .../Extensions/tests/Extensions.spec.ts | 19 ++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/resources/Extensions/Extensions.ts b/src/resources/Extensions/Extensions.ts index d78726c3b..ea25e7d10 100644 --- a/src/resources/Extensions/Extensions.ts +++ b/src/resources/Extensions/Extensions.ts @@ -1,6 +1,12 @@ import API from '../../APICore.js'; import Resource from '../Resource.js'; -import {CreateExtension, ExtensionCompileCode, ExtensionCompileResult, ExtensionModel} from './ExtensionsInterfaces.js'; +import { + CreateExtension, + ExtensionCompileCode, + ExtensionCompileResult, + ExtensionContentVersionModel, + ExtensionModel, +} from './ExtensionsInterfaces.js'; export default class Extension extends Resource { static baseUrl = `/rest/organizations/${API.orgPlaceholder}/extensions`; @@ -33,6 +39,20 @@ export default class Extension extends Resource { return this.api.get(Extension.baseUrl); } + /** + * Lists all versions of an [extension](https://docs.coveo.com/en/206/) in a [Coveo Cloud organization](https://docs.coveo.com/en/185/). + */ + listVersions(extensionId: string) { + return this.api.get(`${Extension.baseUrl}/${extensionId}/versions`); + } + + /** + * Shows a specific version of an [extension](https://docs.coveo.com/en/206/) in a [Coveo Cloud organization](https://docs.coveo.com/en/185/). + */ + getVersion(extensionId: string, versionId: string) { + return this.api.get(`${Extension.baseUrl}/${extensionId}/versions/${versionId}`); + } + /** * Validates the extension's script * diff --git a/src/resources/Extensions/ExtensionsInterfaces.ts b/src/resources/Extensions/ExtensionsInterfaces.ts index ed02969ef..00da9e3b0 100644 --- a/src/resources/Extensions/ExtensionsInterfaces.ts +++ b/src/resources/Extensions/ExtensionsInterfaces.ts @@ -93,3 +93,21 @@ export interface ExtensionCompileError { */ type: string; } + +/** + * An [extension](https://docs.coveo.com/en/206/) version. + */ +export interface ExtensionContentVersionModel { + /** + * The date at which the extension version was created (in number of milliseconds since UNIX epoch), i.e., the date of the modification of the extension when this extension version was created. + * + * @example 1556308241000 + */ + lastModified: number; + /** + * The unique identifier of the extension target version. + * + * @example hdJSDb4hTkdnsCynNtF.d657FgLSDydcj + */ + id: string; +} diff --git a/src/resources/Extensions/tests/Extensions.spec.ts b/src/resources/Extensions/tests/Extensions.spec.ts index 02ba8822e..02c8c89ae 100644 --- a/src/resources/Extensions/tests/Extensions.spec.ts +++ b/src/resources/Extensions/tests/Extensions.spec.ts @@ -105,4 +105,23 @@ describe('Extension', () => { expect(api.post).toHaveBeenCalledWith(`${Extension.baseUrl}/test/compile`, testExtensionCode); }); }); + + describe('listVersions', () => { + it('makes a GET call to the specific extension versions url', () => { + const extensionId = '1'; + extension.listVersions(extensionId); + expect(api.get).toHaveBeenCalledTimes(1); + expect(api.get).toHaveBeenCalledWith('/rest/organizations/{organizationName}/extensions/1/versions'); + }); + }); + + describe('getVersion', () => { + it('make a get call to the extension version url', () => { + const extensionId = '1'; + const versionId = 'a'; + extension.getVersion(extensionId, versionId); + expect(api.get).toHaveBeenCalledTimes(1); + expect(api.get).toHaveBeenCalledWith('/rest/organizations/{organizationName}/extensions/1/versions/a'); + }); + }); });