Skip to content

Commit

Permalink
feat(extensions): add listVersions and getVersion methods (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdostie authored Jun 25, 2024
1 parent 5098b9d commit 2dd8ce4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/resources/Extensions/Extensions.ts
Original file line number Diff line number Diff line change
@@ -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`;
Expand Down Expand Up @@ -33,6 +39,20 @@ export default class Extension extends Resource {
return this.api.get<ExtensionModel[]>(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<ExtensionContentVersionModel[]>(`${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<ExtensionModel>(`${Extension.baseUrl}/${extensionId}/versions/${versionId}`);
}

/**
* Validates the extension's script
*
Expand Down
18 changes: 18 additions & 0 deletions src/resources/Extensions/ExtensionsInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
19 changes: 19 additions & 0 deletions src/resources/Extensions/tests/Extensions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});

0 comments on commit 2dd8ce4

Please sign in to comment.