Skip to content

Commit 8683ffe

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

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-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: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 interface CreateImportTemplateParams extends IDataSourceParams {
11+
name: string;
12+
description?: string;
13+
sharing: SharingMode.PRIVATE | SharingMode.SOURCE;
14+
/**
15+
* Whether the destination is an edge or a node.
16+
*/
17+
entityType: EntityType;
18+
/**
19+
* The reference of the node that the edge starts from. Only defined if the destination is an edge.
20+
*/
21+
sourceNode?: ImportTemplateNodeReference;
22+
/**
23+
* The reference of the node that the edge ends to. Only defined if the destination is an edge.
24+
*/
25+
targetNode?: ImportTemplateNodeReference;
26+
/**
27+
* The destination node category / edge type.
28+
*/
29+
itemType: string;
30+
/**
31+
* How to map imported fields to node/edge properties.
32+
*/
33+
properties: ImportTemplatePropertyMapping[];
34+
}
35+
36+
export interface ImportTemplatePropertyMapping {
37+
/**
38+
* The field in the imported file.
39+
*/
40+
sourceField: string;
41+
/**
42+
* The destination property key on the node/edge.
43+
*/
44+
targetProperty: string;
45+
}
46+
47+
export interface ImportTemplateNodeReference {
48+
/**
49+
* The field in the imported file.
50+
*/
51+
sourceField: string;
52+
/**
53+
* The destination node category.
54+
*/
55+
targetCategory: string;
56+
/**
57+
* The destination property key on the node. If it is undefined, the destination is the native
58+
* ID of the node.
59+
*/
60+
targetProperty?: string;
61+
}
62+
63+
export interface DeleteImportTemplateParams extends IDataSourceParams {
64+
id: number;
65+
}
66+
67+
export interface GetImportTemplatesParams extends IDataSourceParams {
68+
entityType?: EntityType;
69+
}
70+
71+
export type ImportTemplate = CreateImportTemplateParams & {
72+
id: number;
73+
sourceKey: string;
74+
};

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)