Skip to content

Commit bb64dc1

Browse files
committed
LKE-14349: Add the import template API
1 parent b4fd077 commit bb64dc1

File tree

4 files changed

+137
-0
lines changed

4 files changed

+137
-0
lines changed

index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export * from './src/api/GraphEdge';
1818
export * from './src/api/GraphNode';
1919
export * from './src/api/GraphQuery';
2020
export * from './src/api/GraphSchema';
21+
export * from './src/api/import';
2122
export * from './src/api/License';
2223
export * from './src/api/Linkurious';
2324
export * from './src/api/Plugin';

src/api/import/index.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* LINKURIOUS CONFIDENTIAL
3+
* Copyright Linkurious SAS 2012 - 2025
4+
*
5+
* - Created on 2025-11-27.
6+
*/
7+
import {Request} from '../../http/request';
8+
import {LkErrorKey} from '../../http/response';
9+
10+
import {
11+
CreateImportTemplateParams,
12+
DeleteImportTemplateParams,
13+
GetImportTemplatesParams,
14+
ImportTemplate
15+
} from './types';
16+
17+
export * from './types';
18+
19+
const {UNAUTHORIZED, DATA_SOURCE_UNAVAILABLE, FORBIDDEN, NOT_FOUND} = LkErrorKey;
20+
21+
export class ImportAPI extends Request {
22+
/**
23+
* Create a new import template.
24+
*/
25+
createImportTemplate(this: Request<ImportTemplate>, params: CreateImportTemplateParams) {
26+
return this.request({
27+
errors: [UNAUTHORIZED, FORBIDDEN, DATA_SOURCE_UNAVAILABLE],
28+
url: '/:sourceKey/imports/templates',
29+
method: 'POST',
30+
params: params
31+
});
32+
}
33+
34+
/**
35+
* Delete an existing import template.
36+
*/
37+
deleteImportTemplate(params: DeleteImportTemplateParams) {
38+
return this.request({
39+
errors: [UNAUTHORIZED, FORBIDDEN, DATA_SOURCE_UNAVAILABLE, NOT_FOUND],
40+
url: '/:sourceKey/imports/templates/:id',
41+
method: 'DELETE',
42+
params: params
43+
});
44+
}
45+
46+
/**
47+
* List all the import templates (the publicly shared ones and the private ones owned by the user).
48+
*/
49+
getImportTemplates(this: Request<{items: ImportTemplate[]}>, params: GetImportTemplatesParams) {
50+
return this.request({
51+
errors: [UNAUTHORIZED, FORBIDDEN, DATA_SOURCE_UNAVAILABLE],
52+
url: '/:sourceKey/imports/templates',
53+
method: 'GET',
54+
params: params
55+
});
56+
}
57+
}

src/api/import/types.ts

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* LINKURIOUS CONFIDENTIAL
3+
* Copyright Linkurious SAS 2012 - 2025
4+
*
5+
* - Created on 2025-11-27.
6+
*/
7+
import {IDataSourceParams, SharingMode} from '../commonTypes';
8+
import {EntityType} from '../GraphSchema';
9+
10+
export type CreateImportTemplateParams =
11+
| CreateNodeImportTemplateParams
12+
| CreateEdgeImportTemplateParams;
13+
14+
export interface CreateNodeImportTemplateParams extends CreateBaseImportTemplateParams {
15+
entityType: EntityType.NODE;
16+
}
17+
18+
export interface CreateEdgeImportTemplateParams extends CreateBaseImportTemplateParams {
19+
entityType: EntityType.EDGE;
20+
sourceNode: ImportTemplateNodeReference;
21+
targetNode: ImportTemplateNodeReference;
22+
}
23+
24+
interface CreateBaseImportTemplateParams extends IDataSourceParams {
25+
name: string;
26+
description?: string;
27+
sharing: SharingMode.PRIVATE | SharingMode.SOURCE;
28+
/**
29+
* The target node category / edge type.
30+
*/
31+
itemType: string;
32+
/**
33+
* How to map imported fields to node/edge properties.
34+
*/
35+
properties: ImportTemplatePropertyMapping[];
36+
}
37+
38+
export interface ImportTemplatePropertyMapping {
39+
/**
40+
* The field in the imported file.
41+
*/
42+
sourceField: string;
43+
/**
44+
* The destination property key on the node/edge.
45+
*/
46+
targetProperty: string;
47+
}
48+
49+
export interface ImportTemplateNodeReference {
50+
/**
51+
* The field in the imported file.
52+
*/
53+
sourceField: string;
54+
/**
55+
* The destination node category.
56+
*/
57+
targetCategory: string;
58+
/**
59+
* The destination property key on the node. If it is undefined, the destination is the native
60+
* ID of the node.
61+
*/
62+
targetProperty?: string;
63+
}
64+
65+
export interface DeleteImportTemplateParams extends IDataSourceParams {
66+
id: number;
67+
}
68+
69+
export interface GetImportTemplatesParams extends IDataSourceParams {
70+
entityType?: EntityType;
71+
}
72+
73+
export type ImportTemplate = CreateImportTemplateParams & {
74+
id: number;
75+
sourceKey: string;
76+
};

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {GraphEdgeAPI} from './api/GraphEdge';
2121
import {GraphNodeAPI} from './api/GraphNode';
2222
import {GraphQueryAPI} from './api/GraphQuery';
2323
import {GraphSchemaAPI} from './api/GraphSchema';
24+
import {ImportAPI} from './api/import';
2425
import {LicenseAPI} from './api/License';
2526
import {LinkuriousAPI} from './api/Linkurious';
2627
import {PluginAPI} from './api/Plugin';
@@ -50,6 +51,7 @@ export class RestClient extends ErrorListener {
5051
public readonly graphNode: GraphNodeAPI;
5152
public readonly graphQuery: GraphQueryAPI;
5253
public readonly graphSchema: GraphSchemaAPI;
54+
public readonly import: ImportAPI;
5355
public readonly license: LicenseAPI;
5456
public readonly linkurious: LinkuriousAPI;
5557
public readonly plugin: PluginAPI;
@@ -97,6 +99,7 @@ export class RestClient extends ErrorListener {
9799
this.graphNode = new GraphNodeAPI(moduleProps);
98100
this.graphQuery = new GraphQueryAPI(moduleProps);
99101
this.graphSchema = new GraphSchemaAPI(moduleProps);
102+
this.import = new ImportAPI(moduleProps);
100103
this.license = new LicenseAPI(moduleProps);
101104
this.linkurious = new LinkuriousAPI(moduleProps);
102105
this.plugin = new PluginAPI(moduleProps);

0 commit comments

Comments
 (0)