diff --git a/src/resources/BaseInterfaces.ts b/src/resources/BaseInterfaces.ts index 6156b57fb..fede3369d 100644 --- a/src/resources/BaseInterfaces.ts +++ b/src/resources/BaseInterfaces.ts @@ -7,6 +7,15 @@ export type PageModel = { export type New = Omit>; +export type NewHostedInterface = Omit< + Partial & {name: string}, + 'id' | 'created' | 'createdBy' | 'updated' | 'updatedBy' | NonNullable +>; +export type ExistingHostedInterface = Omit< + T, + 'id' | 'created' | 'createdBy' | 'updated' | 'updatedBy' | NonNullable +>; + export interface IdAndDisplayNameModel { id: string; displayName?: string; diff --git a/src/resources/IPXInterfaces/IPXInterface.ts b/src/resources/IPXInterfaces/IPXInterface.ts index ae680bed9..1339fd4ea 100644 --- a/src/resources/IPXInterfaces/IPXInterface.ts +++ b/src/resources/IPXInterfaces/IPXInterface.ts @@ -1,5 +1,5 @@ import API from '../../APICore.js'; -import {New, PageModel} from '../BaseInterfaces.js'; +import {ExistingHostedInterface, NewHostedInterface, PageModel} from '../BaseInterfaces.js'; import {ListHostedInterfacesParams} from '../HostedInterfacesCore/index.js'; import Resource from '../Resource.js'; import {IPXInterfaceConfiguration} from './IPXInterface.model.js'; @@ -11,7 +11,7 @@ export default class IPXInterface extends Resource { return this.api.get>(this.buildPath(IPXInterface.baseUrl, options)); } - create(ipxInterfaceConfig: New) { + create(ipxInterfaceConfig: NewHostedInterface) { return this.api.post(IPXInterface.baseUrl, ipxInterfaceConfig); } @@ -23,19 +23,16 @@ export default class IPXInterface extends Resource { return this.api.get(`${IPXInterface.baseUrl}/${ipxInterfaceId}`); } - update(ipxInterfaceConfig: IPXInterfaceConfiguration) { - return this.api.put( - `${IPXInterface.baseUrl}/${ipxInterfaceConfig.id}`, - ipxInterfaceConfig, - ); + update(ipxInterfaceId: string, ipxInterfaceConfig: NewHostedInterface) { + return this.api.put(`${IPXInterface.baseUrl}/${ipxInterfaceId}`, ipxInterfaceConfig); } getLoader(ipxInterfaceId: string) { return this.api.get(`${IPXInterface.baseUrl}/${ipxInterfaceId}/loader`); } - generatePreview(ipxInterfaceConfig: IPXInterfaceConfiguration) { - return this.api.post(`${IPXInterface.baseUrl}/${ipxInterfaceConfig.id}/preview`, ipxInterfaceConfig); + generatePreview(ipxId: string, ipxInterfaceConfig: ExistingHostedInterface) { + return this.api.post(`${IPXInterface.baseUrl}/${ipxId}/preview`, ipxInterfaceConfig); } getEditInterface(ipxInterfaceId: string) { diff --git a/src/resources/IPXInterfaces/tests/IPXInterface.spec.ts b/src/resources/IPXInterfaces/tests/IPXInterface.spec.ts index 1e7b0f38f..34582acb1 100644 --- a/src/resources/IPXInterfaces/tests/IPXInterface.spec.ts +++ b/src/resources/IPXInterfaces/tests/IPXInterface.spec.ts @@ -171,10 +171,10 @@ describe('IPXInterface', () => { it('should make an UPDATE call to the IPXInterface base url', () => { const id = 'IPInterface-id-to-update'; - ipxInterface.update({...config, id}); + ipxInterface.update(id, config); expect(api.put).toHaveBeenCalledTimes(1); - expect(api.put).toHaveBeenCalledWith(`${IPXInterface.baseUrl}/${id}`, {...config, id}); + expect(api.put).toHaveBeenCalledWith(`${IPXInterface.baseUrl}/${id}`, config); }); }); @@ -204,10 +204,10 @@ describe('IPXInterface', () => { it('should make a POST call to the IPXInterface base url appended with /preview', () => { const id = 'IPInterface-id-to-preview'; - ipxInterface.generatePreview({...config, id}); + ipxInterface.generatePreview(id, config); expect(api.post).toHaveBeenCalledTimes(1); - expect(api.post).toHaveBeenCalledWith(`${IPXInterface.baseUrl}/${id}/preview`, {...config, id}); + expect(api.post).toHaveBeenCalledWith(`${IPXInterface.baseUrl}/${id}/preview`, config); }); }); diff --git a/src/resources/NextGenSearchPages/NextGenSearchPages.model.ts b/src/resources/NextGenSearchPages/NextGenSearchPages.model.ts index 9e3b6e7f5..3f121085c 100644 --- a/src/resources/NextGenSearchPages/NextGenSearchPages.model.ts +++ b/src/resources/NextGenSearchPages/NextGenSearchPages.model.ts @@ -5,7 +5,6 @@ import { HostedInterfaceResultTemplateBadge, IAccesses, ISortCriteria, - New, } from '../index.js'; export enum SearchPageResultActions { @@ -155,8 +154,3 @@ export interface SearchPageInterfaceConfiguration extends Omit, - 'created' | 'createdBy' | 'updated' | 'updatedBy' ->; diff --git a/src/resources/NextGenSearchPages/NextGenSearchPages.ts b/src/resources/NextGenSearchPages/NextGenSearchPages.ts index cc0cf26ce..5cabde7b2 100644 --- a/src/resources/NextGenSearchPages/NextGenSearchPages.ts +++ b/src/resources/NextGenSearchPages/NextGenSearchPages.ts @@ -1,19 +1,27 @@ import API from '../../APICore.js'; import Resource from '../Resource.js'; -import {IAccesses, ListHostedInterfacesParams, PageModel} from '../index.js'; -import {NewSearchPageInterfaceConfiguration, SearchPageInterfaceConfiguration} from './NextGenSearchPages.model.js'; +import { + ExistingHostedInterface, + IAccesses, + ListHostedInterfacesParams, + NewHostedInterface, + PageModel, +} from '../index.js'; +import {SearchPageInterfaceConfiguration} from './NextGenSearchPages.model.js'; export default class NextGenSearchPages extends Resource { - static getBaseUrl = `/rest/organizations/${API.orgPlaceholder}/searchpage/v1/interfaces`; + static baseUrl = `/rest/organizations/${API.orgPlaceholder}/searchpage/v1/interfaces`; list(options?: ListHostedInterfacesParams): Promise> { return this.api.get>( - this.buildPath(NextGenSearchPages.getBaseUrl, options), + this.buildPath(NextGenSearchPages.baseUrl, options), ); } - create(searchPageConfiguration: NewSearchPageInterfaceConfiguration): Promise { - return this.api.post(NextGenSearchPages.getBaseUrl, searchPageConfiguration); + create( + searchPageConfiguration: NewHostedInterface, + ): Promise { + return this.api.post(NextGenSearchPages.baseUrl, searchPageConfiguration); } delete(searchPageId: string): Promise { @@ -21,64 +29,64 @@ export default class NextGenSearchPages extends Resource { } get(searchPageId: string): Promise { - return this.api.get(`${NextGenSearchPages.getBaseUrl}/${searchPageId}`); + return this.api.get(`${NextGenSearchPages.baseUrl}/${searchPageId}`); } update( searchPageId: string, - searchPageConfiguration: NewSearchPageInterfaceConfiguration, + searchPageConfiguration: NewHostedInterface, ): Promise { return this.api.put( - `${NextGenSearchPages.getBaseUrl}/${searchPageId}`, + `${NextGenSearchPages.baseUrl}/${searchPageId}`, searchPageConfiguration, ); } - generatePreview(searchPageConfiguration: NewSearchPageInterfaceConfiguration & {id: string}): Promise { - return this.api.post( - `${NextGenSearchPages.getBaseUrl}/${searchPageConfiguration.id}/preview`, - searchPageConfiguration, - ); + generatePreview( + searchPageId: string, + searchPageConfiguration: ExistingHostedInterface, + ): Promise { + return this.api.post(`${NextGenSearchPages.baseUrl}/${searchPageId}/preview`, searchPageConfiguration); } getView(searchPageId: string): Promise { - return this.api.get(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/preview`); + return this.api.get(`${NextGenSearchPages.baseUrl}/${searchPageId}/preview`); } getToken(searchPageId: string): Promise<{token: string}> { - return this.api.get<{token: string}>(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/token`); + return this.api.get<{token: string}>(`${NextGenSearchPages.baseUrl}/${searchPageId}/token`); } getEditInterface(searchPageId: string): Promise { - return this.api.get(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/edit`); + return this.api.get(`${NextGenSearchPages.baseUrl}/${searchPageId}/edit`); } getLoader(searchPageId: string): Promise { - return this.api.get(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/loader`); + return this.api.get(`${NextGenSearchPages.baseUrl}/${searchPageId}/loader`); } getLoginPage(searchPageId: string): Promise { - return this.api.get(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/login`); + return this.api.get(`${NextGenSearchPages.baseUrl}/${searchPageId}/login`); } getAccesses(searchPageId: string): Promise { - return this.api.get(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/accesses`); + return this.api.get(`${NextGenSearchPages.baseUrl}/${searchPageId}/accesses`); } updateAccesses(searchPageId: string, accesses: IAccesses): Promise { return this.api.put( - `${NextGenSearchPages.getBaseUrl}/${searchPageId}/accesses`, + `${NextGenSearchPages.baseUrl}/${searchPageId}/accesses`, accesses, ); } getAccessesUsers(searchPageId: string): Promise { - return this.api.get(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/accesses/users`); + return this.api.get(`${NextGenSearchPages.baseUrl}/${searchPageId}/accesses/users`); } updateAccessesUsers(searchPageId: string, users: string[]): Promise { return this.api.put( - `${NextGenSearchPages.getBaseUrl}/${searchPageId}/accesses/users`, + `${NextGenSearchPages.baseUrl}/${searchPageId}/accesses/users`, users, ); } @@ -91,12 +99,12 @@ export default class NextGenSearchPages extends Resource { ): Promise { const body = message ? {users, message} : {users}; return this.api.post( - `${NextGenSearchPages.getBaseUrl}/${searchPageId}/accesses/users${notify ? '?notify=1' : ''}`, + `${NextGenSearchPages.baseUrl}/${searchPageId}/accesses/users${notify ? '?notify=1' : ''}`, body, ); } requestAccess(searchPageId: string): Promise { - return this.api.post(`${NextGenSearchPages.getBaseUrl}/${searchPageId}/accesses/request`); + return this.api.post(`${NextGenSearchPages.baseUrl}/${searchPageId}/accesses/request`); } } diff --git a/src/resources/NextGenSearchPages/tests/NextGenSearchPages.spec.ts b/src/resources/NextGenSearchPages/tests/NextGenSearchPages.spec.ts index f9eb50306..1c52b3acb 100644 --- a/src/resources/NextGenSearchPages/tests/NextGenSearchPages.spec.ts +++ b/src/resources/NextGenSearchPages/tests/NextGenSearchPages.spec.ts @@ -1,7 +1,8 @@ import API from '../../../APICore.js'; import { + ExistingHostedInterface, HostedInterfaceConditionOperator, - NewSearchPageInterfaceConfiguration, + SearchPageInterfaceConfiguration, SearchPageLayout, SortingBy, } from '../../../Entry.js'; @@ -15,7 +16,7 @@ describe('NextGenSearchPages', () => { const api = new APIMock() as jest.Mocked; const serverlessApi = new APIMock() as jest.Mocked; - const config: NewSearchPageInterfaceConfiguration = { + const config: ExistingHostedInterface = { name: 'some search page name', facets: [ { @@ -115,7 +116,7 @@ describe('NextGenSearchPages', () => { expect(api.get).toHaveBeenCalledTimes(1); expect(api.get).toHaveBeenCalledWith( - `${NextGenSearchPages.getBaseUrl}?page=2&perPage=10&filter=Accounting&order=asc`, + `${NextGenSearchPages.baseUrl}?page=2&perPage=10&filter=Accounting&order=asc`, ); }); @@ -123,28 +124,28 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.list({page: 2}); expect(api.get).toHaveBeenCalledTimes(1); - expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}?page=2`); + expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}?page=2`); }); it('should make a GET call with perPage', () => { nextGenSearchPages.list({perPage: 10}); expect(api.get).toHaveBeenCalledTimes(1); - expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}?perPage=10`); + expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}?perPage=10`); }); it('should make a GET call with filter', () => { nextGenSearchPages.list({filter: 'Accounting'}); expect(api.get).toHaveBeenCalledTimes(1); - expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}?filter=Accounting`); + expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}?filter=Accounting`); }); it('should make a GET call with order', () => { nextGenSearchPages.list({order: 'asc'}); expect(api.get).toHaveBeenCalledTimes(1); - expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}?order=asc`); + expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}?order=asc`); }); }); @@ -153,7 +154,7 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.create(config); expect(api.post).toHaveBeenCalledTimes(1); - expect(api.post).toHaveBeenCalledWith(NextGenSearchPages.getBaseUrl, config); + expect(api.post).toHaveBeenCalledWith(NextGenSearchPages.baseUrl, config); }); }); @@ -175,7 +176,7 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.get(id); expect(api.get).toHaveBeenCalledTimes(1); - expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}/${id}`); + expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}/${id}`); }); }); @@ -186,7 +187,7 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.update(id, config); expect(api.put).toHaveBeenCalledTimes(1); - expect(api.put).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}/${id}`, config); + expect(api.put).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}/${id}`, config); }); }); @@ -194,10 +195,10 @@ describe('NextGenSearchPages', () => { it('should make a POST call to the NextGenSearchPages base url appended with /preview', () => { const id = 'NextGenSearchPages-id-to-preview'; - nextGenSearchPages.generatePreview({...config, id}); + nextGenSearchPages.generatePreview(id, config); expect(api.post).toHaveBeenCalledTimes(1); - expect(api.post).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}/${id}/preview`, {...config, id}); + expect(api.post).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}/${id}/preview`, config); }); }); @@ -208,7 +209,7 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.getView(id); expect(api.get).toHaveBeenCalledTimes(1); - expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}/${id}/preview`); + expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}/${id}/preview`); }); }); @@ -219,7 +220,7 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.getToken(id); expect(api.get).toHaveBeenCalledTimes(1); - expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}/${id}/token`); + expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}/${id}/token`); }); }); @@ -230,7 +231,7 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.getEditInterface(id); expect(api.get).toHaveBeenCalledTimes(1); - expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}/${id}/edit`); + expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}/${id}/edit`); }); }); @@ -241,7 +242,7 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.getLoader(id); expect(api.get).toHaveBeenCalledTimes(1); - expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}/${id}/loader`); + expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}/${id}/loader`); }); }); @@ -252,7 +253,7 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.getLoginPage(id); expect(api.get).toHaveBeenCalledTimes(1); - expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}/${id}/login`); + expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}/${id}/login`); }); }); @@ -263,7 +264,7 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.getAccesses(id); expect(api.get).toHaveBeenCalledTimes(1); - expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}/${id}/accesses`); + expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}/${id}/accesses`); }); }); @@ -274,7 +275,7 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.updateAccesses(id, config.accesses); expect(api.put).toHaveBeenCalledTimes(1); - expect(api.put).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}/${id}/accesses`, config.accesses); + expect(api.put).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}/${id}/accesses`, config.accesses); }); }); @@ -285,7 +286,7 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.getAccessesUsers(id); expect(api.get).toHaveBeenCalledTimes(1); - expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}/${id}/accesses/users`); + expect(api.get).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}/${id}/accesses/users`); }); }); @@ -297,7 +298,7 @@ describe('NextGenSearchPages', () => { expect(api.put).toHaveBeenCalledTimes(1); expect(api.put).toHaveBeenCalledWith( - `${NextGenSearchPages.getBaseUrl}/${id}/accesses/users`, + `${NextGenSearchPages.baseUrl}/${id}/accesses/users`, config.accesses.users, ); }); @@ -310,7 +311,7 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.addAccessesUsers(id, config.accesses.users); expect(api.post).toHaveBeenCalledTimes(1); - expect(api.post).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}/${id}/accesses/users`, { + expect(api.post).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}/${id}/accesses/users`, { users: config.accesses.users, }); }); @@ -323,7 +324,7 @@ describe('NextGenSearchPages', () => { nextGenSearchPages.requestAccess(id); expect(api.post).toHaveBeenCalledTimes(1); - expect(api.post).toHaveBeenCalledWith(`${NextGenSearchPages.getBaseUrl}/${id}/accesses/request`); + expect(api.post).toHaveBeenCalledWith(`${NextGenSearchPages.baseUrl}/${id}/accesses/request`); }); }); });