Skip to content

Commit

Permalink
chore: separation of concerns and refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-bompart committed Jan 18, 2024
1 parent b357a81 commit 9f03074
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 148 deletions.
9 changes: 0 additions & 9 deletions src/resources/BaseInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@ export type PageModel<T = any, TItemsKey extends string = 'items'> = {

export type New<T, K extends keyof T | null = null> = Omit<T, 'id' | NonNullable<K>>;

export type NewHostedInterface<T, K extends keyof T | null = null> = Omit<
Partial<T> & {name: string},
'id' | 'created' | 'createdBy' | 'updated' | 'updatedBy' | NonNullable<K>
>;
export type ExistingHostedInterface<T, K extends keyof T | null = null> = Omit<
T,
'id' | 'created' | 'createdBy' | 'updated' | 'updatedBy' | NonNullable<K>
>;

export interface IdAndDisplayNameModel {
id: string;
displayName?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,59 @@ export interface HostedInterfaceConfiguration {
*/
tabs: HostedInterfaceTab[];
}

export interface IManifestResponse<Configuration> {
/**
* The HTML markup of the search interface along with configured placeholders.
*/
markup: string;
/**
* The Atomic results configuration information.
*/
results: IPageManifestResults;
/**
* The Atomic related styling in CSS format.
*/
style: IPageManifestStyle;
/**
* The complete search interface configuration.
*/
config: Configuration;
}

export interface IPageManifestResultTemplate {
/**
* The HTML markup of the content of the result template.
*/
markup: string;
/**
* The Atomic [result template component](https://docs.coveo.com/en/atomic/latest/reference/components/atomic-result-template/)'s properties.
*/
attributes: Record<string, string>;
}

export interface IPageManifestResults {
/**
* The placeholder for the result list and result templates.
*/
placeholder?: string;
/**
* The Atomic [result list component](https://docs.coveo.com/en/atomic/latest/reference/components/atomic-result-list/#properties)'s properties.
*/
attributes: Record<string, string>;
/**
* The Atomic result template configuration information.
*/
templates: IPageManifestResultTemplate[];
}

export interface IPageManifestStyle {
/**
* The CSS to set [Atomic theme variables](https://docs.coveo.com/en/atomic/latest/usage/themes-and-visual-customization/#theme-variables).
*/
theme: string;
/**
* The page layout CSS.
*/
layout: string;
}
73 changes: 73 additions & 0 deletions src/resources/HostedInterfacesCore/HostedInterfaceVersionsCore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Paginated} from '../BaseInterfaces.js';
import {SortingBy, SortingOrder} from '../Enums.js';

export interface HostedInterfaceChangeInfo {
/**
Expand Down Expand Up @@ -126,3 +127,75 @@ export interface RestoreInterfaceVersionParams {
*/
label?: string;
}

export type NewHostedInterface<T, K extends keyof T | null = null> = Omit<
Partial<T> & {name: string},
'id' | 'created' | 'createdBy' | 'updated' | 'updatedBy' | NonNullable<K>
>;
export type ExistingHostedInterface<T, K extends keyof T | null = null> = Omit<
T,
'id' | 'created' | 'createdBy' | 'updated' | 'updatedBy' | NonNullable<K>
>;

export interface IAccesses {
/**
* The list of users that are allowed to access the search interface.
*/
users: string[];

/**
* The list of domains that are allowed to access the search interface.
*/
domains: string[];

/**
* When set to true, all users can share and see the search page.
*/
sharingLinkEnabled?: boolean;

/**
* When set to true, the domain sharing is enabled. Otherwise, only users that have explicitly access to the search page can access it.
*/
sharingDomainEnabled?: boolean;
}

export interface ISortCriteria {
/**
* Indicates the kind of sort criterion.
*/
by: SortingBy;

/**
* Label of the sort criterion.
*/
label: string;

/**
* Specify the sort order if applicable.
* Default value when sorting by date is descending.
* Default value when sorting by field is ascending.
* No sort order value is applicable when sorting by relevancy.
*/
order?: SortingOrder;

/**
* The [field](https://docs.coveo.com/en/200) on which the sort is based on. For example: filetype.
* Required when sorting by field.
* This property is ignored unless you are sorting by field.
*/
field?: string;
}

export interface IManifestParameters {
/**
* The placeholders for the page.
*/
pagePlaceholders?: IPagePlaceholders;
}

export interface IPagePlaceholders {
/**
* A placeholder for the result list and result templates.
*/
results?: string;
}
8 changes: 6 additions & 2 deletions src/resources/IPXInterfaces/IPXInterface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import API from '../../APICore.js';
import {ExistingHostedInterface, NewHostedInterface, PageModel} from '../BaseInterfaces.js';
import {ListHostedInterfacesParams} from '../HostedInterfacesCore/index.js';
import {PageModel} from '../BaseInterfaces.js';
import {
ExistingHostedInterface,
ListHostedInterfacesParams,
NewHostedInterface,
} from '../HostedInterfacesCore/index.js';
import Resource from '../Resource.js';
import {IPXInterfaceConfiguration} from './IPXInterface.model.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
HostedInterfaceResultTemplateBadge,
IAccesses,
ISortCriteria,
} from '../index.js';
} from '../HostedInterfacesCore/index.js';

export enum SearchPageResultActions {
copyToClipboard = 'copyToClipboard',
Expand Down
6 changes: 4 additions & 2 deletions src/resources/NextGenSearchPages/NextGenSearchPages.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import API from '../../APICore.js';
import Resource from '../Resource.js';
import {PageModel} from '../BaseInterfaces.js';
import {
ExistingHostedInterface,
IAccesses,
IManifestParameters,
IManifestResponse,
ListHostedInterfacesParams,
NewHostedInterface,
PageModel,
} from '../index.js';
} from '../HostedInterfacesCore/index.js';
import {SearchPageInterfaceConfiguration} from './NextGenSearchPages.model.js';

export default class NextGenSearchPages extends Resource {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import API from '../../../APICore.js';
import {
ExistingHostedInterface,
HostedInterfaceConditionOperator,
SearchPageInterfaceConfiguration,
SearchPageLayout,
SortingBy,
} from '../../../Entry.js';
import {SortingBy} from '../../Enums.js';
import {ExistingHostedInterface, HostedInterfaceConditionOperator} from '../../HostedInterfacesCore/index.js';
import NextGenSearchPages from '../NextGenSearchPages.js';
import {SearchPageInterfaceConfiguration, SearchPageLayout} from '../NextGenSearchPages.model.js';
jest.mock('../../../APICore.js');

const APIMock: jest.Mock<API> = API as any;
Expand Down
121 changes: 1 addition & 120 deletions src/resources/SearchInterfaces/SearchInterfaces.model.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
import {Paginated} from '../BaseInterfaces.js';
import {SortingBy, SortingOrder} from '../Enums.js';

export interface IAccesses {
/**
* The list of users that are allowed to access the search interface.
*/
users: string[];

/**
* The list of domains that are allowed to access the search interface.
*/
domains: string[];

/**
* When set to true, all users can share and see the search page.
*/
sharingLinkEnabled?: boolean;

/**
* When set to true, the domain sharing is enabled. Otherwise, only users that have explicitly access to the search page can access it.
*/
sharingDomainEnabled?: boolean;
}
import {IAccesses, ISortCriteria} from '../HostedInterfacesCore/index.js';

export interface IFacet {
/**
Expand All @@ -35,33 +13,6 @@ export interface IFacet {
label: string;
}

export interface ISortCriteria {
/**
* Indicates the kind of sort criterion.
*/
by: SortingBy;

/**
* Label of the sort criterion.
*/
label: string;

/**
* Specify the sort order if applicable.
* Default value when sorting by date is descending.
* Default value when sorting by field is ascending.
* No sort order value is applicable when sorting by relevancy.
*/
order?: SortingOrder;

/**
* The [field](https://docs.coveo.com/en/200) on which the sort is based on. For example: filetype.
* Required when sorting by field.
* This property is ignored unless you are sorting by field.
*/
field?: string;
}

export interface ISearchInterfaceConfiguration {
/**
* The configuration identifier.
Expand Down Expand Up @@ -137,73 +88,3 @@ export interface IListSearchInterfacesParameters extends Paginated {
*/
perPage?: number;
}

export interface IManifestParameters {
/**
* The placeholders for the page.
*/
pagePlaceholders?: IPagePlaceholders;
}

export interface IPagePlaceholders {
/**
* A placeholder for the result list and result templates.
*/
results?: string;
}

export interface IManifestResponse {
/**
* The HTML markup of the search interface along with configured placeholders.
*/
markup: string;
/**
* The Atomic results configuration information.
*/
results: IPageManifestResults;
/**
* The Atomic related styling in CSS format.
*/
style: IPageManifestStyle;
/**
* The complete search interface configuration.
*/
config: ISearchInterfaceConfigurationResponse;
}

export interface IPageManifestResultTemplate {
/**
* The HTML markup of the content of the result template.
*/
markup: string;
/**
* The Atomic [result template component](https://docs.coveo.com/en/atomic/latest/reference/components/atomic-result-template/)'s properties.
*/
attributes: Record<string, string>;
}

export interface IPageManifestResults {
/**
* The placeholder for the result list and result templates.
*/
placeholder?: string;
/**
* The Atomic [result list component](https://docs.coveo.com/en/atomic/latest/reference/components/atomic-result-list/#properties)'s properties.
*/
attributes: Record<string, string>;
/**
* The Atomic result template configuration information.
*/
templates: IPageManifestResultTemplate[];
}

export interface IPageManifestStyle {
/**
* The CSS to set [Atomic theme variables](https://docs.coveo.com/en/atomic/latest/usage/themes-and-visual-customization/#theme-variables).
*/
theme: string;
/**
* The page layout CSS.
*/
layout: string;
}
11 changes: 6 additions & 5 deletions src/resources/SearchInterfaces/SearchInterfaces.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import API from '../../APICore.js';
import {New, PageModel} from '../../Entry.js';
import Resource from '../Resource.js';
import {New, PageModel} from '../BaseInterfaces.js';
import {IAccesses, IManifestParameters, IManifestResponse} from '../HostedInterfacesCore/index.js';
import {
IAccesses,
IListSearchInterfacesParameters,
ISearchInterfaceConfiguration,
ISearchInterfaceConfigurationResponse,
IManifestParameters,
IManifestResponse,
} from './SearchInterfaces.model.js';

export default class SearchInterfaces extends Resource {
Expand Down Expand Up @@ -57,7 +55,10 @@ export default class SearchInterfaces extends Resource {
);
}

manifest(interfaceId: string, options?: IManifestParameters): Promise<IManifestResponse> {
manifest(
interfaceId: string,
options?: IManifestParameters,
): Promise<IManifestResponse<ISearchInterfaceConfiguration>> {
return this.api.post(`${SearchInterfaces.baseUrl}/${interfaceId}/manifest/v1`, options);
}
}
5 changes: 3 additions & 2 deletions src/resources/SearchInterfaces/tests/SearchInterfaces.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import API from '../../../APICore.js';
import {IManifestParameters, New} from '../../../Entry.js';
import {New} from '../../BaseInterfaces.js';
import {SortingBy, SortingOrder} from '../../Enums.js';
import {IAccesses, IManifestParameters} from '../../HostedInterfacesCore/index.js';
import SearchInterfaces from '../SearchInterfaces.js';
import {IAccesses, ISearchInterfaceConfiguration} from '../SearchInterfaces.model.js';
import {ISearchInterfaceConfiguration} from '../SearchInterfaces.model.js';

jest.mock('../../../APICore.js');

Expand Down

0 comments on commit 9f03074

Please sign in to comment.