Skip to content

Commit

Permalink
Merge branch 'feature/MLX-451-add-new-endpoint-to-platform-client' of…
Browse files Browse the repository at this point in the history
… github.com:coveo/platform-client into feature/MLX-451-add-new-endpoint-to-platform-client
  • Loading branch information
JTangCoveo committed Oct 6, 2023
2 parents 9851f38 + 34ea44e commit 6a4f9e0
Show file tree
Hide file tree
Showing 20 changed files with 1,819 additions and 1,111 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
environment: Release
steps:
- name: Checkout
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
with:
fetch-depth: 0
- name: Setup
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: CI
steps:
- name: Checkout
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- name: Setup
uses: ./.github/actions/setup
- name: Check lockfiles
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/renovate-config-validator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
renovate-config:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3
with:
cache: 'npm'
Expand Down
2,198 changes: 1,276 additions & 922 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@
"devDependencies": {
"@commitlint/cli": "17.7.1",
"@commitlint/config-conventional": "17.7.0",
"@types/jest": "29.5.4",
"@typescript-eslint/eslint-plugin": "6.6.0",
"@typescript-eslint/parser": "6.6.0",
"@types/jest": "29.5.5",
"@typescript-eslint/eslint-plugin": "6.7.2",
"@typescript-eslint/parser": "6.7.2",
"abortcontroller-polyfill": "1.7.5",
"cz-conventional-changelog": "3.3.0",
"eslint": "8.49.0",
"eslint": "8.50.0",
"eslint-config-prettier": "9.0.0",
"eslint-config-typescript": "3.0.0",
"eslint-plugin-jest": "27.2.3",
"eslint-plugin-jest": "27.4.0",
"eslint-plugin-prettier": "5.0.0",
"husky": "8.0.3",
"jest": "29.6.4",
"jest": "29.7.0",
"jest-fetch-mock": "3.0.3",
"jest-runner-eslint": "2.1.1",
"jest-runner-eslint": "2.1.2",
"lint-staged": "14.0.1",
"prettier": "3.0.3",
"semantic-release": "21.1.1",
"semantic-release": "22.0.5",
"ts-jest": "29.1.1",
"tsjs": "5.0.1",
"tslib": "2.6.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ export interface ModelInformationQS {
[key: string]: any;
}

export interface ModelInformationPQS extends ModelInformationQS {
catalogIdOpt: string;
}

export interface MetaInfoSmartSnippets extends MetaInfo {
modelId: string;
engineName: string;
Expand Down
6 changes: 6 additions & 0 deletions src/resources/PlatformResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import Vaults from './Vaults/Vaults.js';
import TableauService from './TableauService/TableauService.js';
import HostedPages from './HostedPages/HostedPages.js';
import SearchAnalysis from './SearchAnalysis/SearchAnalysis.js';
import Project from './Projects/Project.js';
import Resources from './Resources/Resources.js';

const resourcesMap: Array<{key: string; resource: typeof Resource}> = [
{key: 'activity', resource: Activity},
Expand Down Expand Up @@ -102,6 +104,8 @@ const resourcesMap: Array<{key: string; resource: typeof Resource}> = [
{key: 'privilegeEvaluator', resource: PrivilegeEvaluator},
{key: 'tableauService', resource: TableauService},
{key: 'searchAnalysis', resource: SearchAnalysis},
{key: 'project', resource: Project},
{key: 'resources', resource: Resources},
];

class PlatformResources {
Expand Down Expand Up @@ -156,6 +160,8 @@ class PlatformResources {
user: User;
vault: Vaults;
tableauService: TableauService;
project: Project;
resources: Resources;

registerAll() {
resourcesMap.forEach(({key, resource}) => {
Expand Down
77 changes: 77 additions & 0 deletions src/resources/Projects/Project.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import API from '../../APICore.js';
import {PageModel} from '../BaseInterfaces.js';
import Resource from '../Resource.js';
import {ResourceModel, ResourceParams} from '../Resources/index.js';
import {ListProjectParams, ProjectModel, BaseProjectModel, ProjectResourceType} from './ProjectInterfaces.js';

export default class Project extends Resource {
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/projects`;

/**
* Returns a paginated list of projects.
*
* @param {ListProjectParams} params
* @returns {Promise<PageModel<ProjectModel>>} A paginated list of projects
*/
list(params?: ListProjectParams): Promise<PageModel<ProjectModel>> {
return this.api.get<PageModel<ProjectModel>>(this.buildPath(Project.baseUrl, params));
}

/**
* Creates and returns a new project.
*
* @param {ProjectModel} project
* @returns {Promise<ProjectModel>} The newly created project
*/
create(project: BaseProjectModel): Promise<ProjectModel> {
return this.api.post<ProjectModel>(this.buildPath(Project.baseUrl), project);
}

/**
* Updates a project with the model sent and returns the updated project.
*
* @param {string} projectId
* @param {ProjectModel} updateProjectModel
* @returns {Promise<ProjectModel>} The updated project
*/
update(projectId: string, updateProjectModel: ProjectModel): Promise<ProjectModel> {
return this.api.put<ProjectModel>(this.buildPath(`${Project.baseUrl}/${projectId}`), updateProjectModel);
}

/**
* Returns a project.
*
* @param {string} projectId
* @returns {Promise<ProjectModel>} The project specified by the provided id
*/
get(projectId: string): Promise<ProjectModel> {
return this.api.get<ProjectModel>(this.buildPath(`${Project.baseUrl}/${projectId}`));
}

/**
* Deletes a project.
*
* @param {string} projectId
*/
delete(projectId: string): Promise<void> {
return this.api.delete(this.buildPath(`${Project.baseUrl}/${projectId}`));
}

/**
* Returns a paginated list of resources associated to a project.
*
* @param projectId
* @param resourceType
* @param {ResourceParams} params
* @returns {Promise<PageModel<ResourceModel>>} A paginated list of resources associated to a project.
*/
listResources(
projectId: string,
resourceType: ProjectResourceType,
params?: ResourceParams,
): Promise<PageModel<ResourceModel>> {
return this.api.get<PageModel<ResourceModel>>(
this.buildPath(`${Project.baseUrl}/${projectId}/resources/${resourceType}`, params),
);
}
}
117 changes: 117 additions & 0 deletions src/resources/Projects/ProjectInterfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import {Paginated} from '../BaseInterfaces.js';
import {SortingOrder} from '../Enums.js';

export enum ProjectSortBy {
name = 'NAME',
createdBy = 'CREATED_BY',
createdDate = 'CREATED_DATE',
updatedBy = 'UPDATED_BY',
updatedDate = 'UPDATED_DATE',
}

export const projectResourceTypes = [
'CATALOG',
'CASE_ASSIST',
'CRAWLING_MODULE',
'EXTENSION',
'IN_PRODUCT_EXPERIENCE',
'INSIGHT_PANEL',
'ML_MODEL',
'QUERY_PIPELINE',
'SEARCH_HUB',
'SEARCH_PAGE',
'SECURITY_PROVIDER',
'SOURCE',
'UA_REPORT',
];

export type ProjectResourceType = (typeof projectResourceTypes)[number];

export enum ProjectType {
Commerce = 'COMMERCE',
Other = 'OTHER',
Service = 'SERVICE',
Website = 'WEBSITE',
Workplace = 'WORKPLACE',
}

export interface BaseProjectModel {
/**
* The name of the project.
*/
name: string;
/**
* The description of the project.
*/
description: string;
/**
* The type of the project.
*/
type: ProjectType;
/**
* The list of usernames that will be points of contact for the project.
*
* @example: ['[email protected]', '[email protected]']
*/
pointsOfContact?: string[];
/**
* The resources associated to the project.
*
* @example: {'SOURCE': ['sourceId1', 'sourceId2']}
*/
resources?: Record<ProjectResourceType, string[]>;
}

export interface ProjectModel extends BaseProjectModel {
/**
* The unique identifier of the project.
*/
id: string;
/**
* The email of the user that created the project.
*
* @example: '[email protected]'
*/
createdBy: string;
/**
* The date of the project's creation.
* Note: ISO-8601 format
*
* @example: '2023-06-21T14:59:26.850Z'
*/
createdDate: string;
/**
* The email of the user that last updated the project.
*
* @example: '[email protected]'
*/
updatedBy: string;
/**
* The date of the project's last update.
* Note: ISO-8601 format
*
* @example: '2023-06-21T14:59:26.850Z'
*/
updatedDate: string;
}

export interface ListProjectParams extends Paginated {
/**
* The query filter to match.
* This allows you to search according to the project name.
*
* By default, results are not required to match a specific query filter.
*/
filter?: string;
/**
* The sorting criteria to apply on the results.
*
*/
sortBy?: ProjectSortBy;
/**
* The sorting order to apply on the results.
*
* @example: 'ASC'
*/
order?: SortingOrder;
}
2 changes: 2 additions & 0 deletions src/resources/Projects/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './Project.js';
export * from './ProjectInterfaces.js';
Loading

0 comments on commit 6a4f9e0

Please sign in to comment.