mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
Updating n8n front-end to use the new search endpoint powered by TypeSense. Endpoint is deployed on staging API so, in order to test it, use this env var: ```export N8N_TEMPLATES_HOST=https://api-staging.n8n.io/api``` **NOTE**: This PR should not be merged until [backend changes](https://github.com/n8n-io/creators-site/pull/118) are merged and released. ## Related tickets and issues https://linear.app/n8n/issue/ADO-1555/update-in-app-search-to-work-with-the-new-back-end ## Review / Merge checklist - [x] PR title and summary are descriptive. **Remember, the title automatically goes into the changelog. Use `(no-changelog)` otherwise.** ([conventions](https://github.com/n8n-io/n8n/blob/master/.github/pull_request_title_conventions.md)) - [ ] Tests included. > A bug is not considered fixed, unless a test is added to prevent it from happening again. > A feature is not complete without tests.
87 lines
2.2 KiB
TypeScript
87 lines
2.2 KiB
TypeScript
import type {
|
|
ITemplatesCategory,
|
|
ITemplatesCollection,
|
|
ITemplatesQuery,
|
|
ITemplatesWorkflow,
|
|
ITemplatesCollectionResponse,
|
|
ITemplatesWorkflowResponse,
|
|
IWorkflowTemplate,
|
|
TemplateSearchFacet,
|
|
} from '@/Interface';
|
|
import type { IDataObject } from 'n8n-workflow';
|
|
import { get } from '@/utils/apiUtils';
|
|
|
|
function stringifyArray(arr: number[]) {
|
|
return arr.join(',');
|
|
}
|
|
|
|
export async function testHealthEndpoint(apiEndpoint: string) {
|
|
return get(apiEndpoint, '/health');
|
|
}
|
|
|
|
export async function getCategories(
|
|
apiEndpoint: string,
|
|
headers?: IDataObject,
|
|
): Promise<{ categories: ITemplatesCategory[] }> {
|
|
return get(apiEndpoint, '/templates/categories', undefined, headers);
|
|
}
|
|
|
|
export async function getCollections(
|
|
apiEndpoint: string,
|
|
query: ITemplatesQuery,
|
|
headers?: IDataObject,
|
|
): Promise<{ collections: ITemplatesCollection[] }> {
|
|
return get(
|
|
apiEndpoint,
|
|
'/templates/collections',
|
|
{ category: stringifyArray(query.categories || []), search: query.search },
|
|
headers,
|
|
);
|
|
}
|
|
|
|
export async function getWorkflows(
|
|
apiEndpoint: string,
|
|
query: { page: number; limit: number; categories: number[]; search: string },
|
|
headers?: IDataObject,
|
|
): Promise<{
|
|
totalWorkflows: number;
|
|
workflows: ITemplatesWorkflow[];
|
|
filters: TemplateSearchFacet[];
|
|
}> {
|
|
return get(
|
|
apiEndpoint,
|
|
'/templates/search',
|
|
{
|
|
page: query.page,
|
|
rows: query.limit,
|
|
category: stringifyArray(query.categories),
|
|
search: query.search,
|
|
},
|
|
headers,
|
|
);
|
|
}
|
|
|
|
export async function getCollectionById(
|
|
apiEndpoint: string,
|
|
collectionId: string,
|
|
headers?: IDataObject,
|
|
): Promise<{ collection: ITemplatesCollectionResponse }> {
|
|
return get(apiEndpoint, `/templates/collections/${collectionId}`, undefined, headers);
|
|
}
|
|
|
|
export async function getTemplateById(
|
|
apiEndpoint: string,
|
|
templateId: string,
|
|
headers?: IDataObject,
|
|
): Promise<{ workflow: ITemplatesWorkflowResponse }> {
|
|
return get(apiEndpoint, `/templates/workflows/${templateId}`, undefined, headers);
|
|
}
|
|
|
|
export async function getWorkflowTemplate(
|
|
apiEndpoint: string,
|
|
templateId: string,
|
|
headers?: IDataObject,
|
|
): Promise<IWorkflowTemplate> {
|
|
return get(apiEndpoint, `/workflows/templates/${templateId}`, undefined, headers);
|
|
}
|