diff --git a/index.ts b/index.ts index ae3002a5..5d69b1f9 100644 --- a/index.ts +++ b/index.ts @@ -18,6 +18,7 @@ export * from './src/api/GraphEdge'; export * from './src/api/GraphNode'; export * from './src/api/GraphQuery'; export * from './src/api/GraphSchema'; +export * from './src/api/import'; export * from './src/api/License'; export * from './src/api/Linkurious'; export * from './src/api/Plugin'; diff --git a/src/api/import/index.ts b/src/api/import/index.ts new file mode 100644 index 00000000..1a98fed4 --- /dev/null +++ b/src/api/import/index.ts @@ -0,0 +1,57 @@ +/** + * LINKURIOUS CONFIDENTIAL + * Copyright Linkurious SAS 2012 - 2025 + * + * - Created on 2025-11-27. + */ +import {Request} from '../../http/request'; +import {LkErrorKey} from '../../http/response'; + +import { + CreateImportTemplateParams, + DeleteImportTemplateParams, + GetImportTemplatesParams, + ImportTemplate +} from './types'; + +export * from './types'; + +const {UNAUTHORIZED, DATA_SOURCE_UNAVAILABLE, FORBIDDEN, NOT_FOUND} = LkErrorKey; + +export class ImportAPI extends Request { + /** + * Create a new import template. + */ + createImportTemplate(this: Request, params: CreateImportTemplateParams) { + return this.request({ + errors: [UNAUTHORIZED, FORBIDDEN, DATA_SOURCE_UNAVAILABLE], + url: '/:sourceKey/imports/templates', + method: 'POST', + params: params + }); + } + + /** + * Delete an existing import template. + */ + deleteImportTemplate(params: DeleteImportTemplateParams) { + return this.request({ + errors: [UNAUTHORIZED, FORBIDDEN, DATA_SOURCE_UNAVAILABLE, NOT_FOUND], + url: '/:sourceKey/imports/templates/:id', + method: 'DELETE', + params: params + }); + } + + /** + * List all the import templates (the publicly shared ones and the private ones owned by the user). + */ + getImportTemplates(this: Request<{items: ImportTemplate[]}>, params: GetImportTemplatesParams) { + return this.request({ + errors: [UNAUTHORIZED, FORBIDDEN, DATA_SOURCE_UNAVAILABLE], + url: '/:sourceKey/imports/templates', + method: 'GET', + params: params + }); + } +} diff --git a/src/api/import/types.ts b/src/api/import/types.ts new file mode 100644 index 00000000..91820ee1 --- /dev/null +++ b/src/api/import/types.ts @@ -0,0 +1,74 @@ +/** + * LINKURIOUS CONFIDENTIAL + * Copyright Linkurious SAS 2012 - 2025 + * + * - Created on 2025-11-27. + */ +import {IDataSourceParams, SharingMode} from '../commonTypes'; +import {EntityType} from '../GraphSchema'; + +export interface CreateImportTemplateParams extends IDataSourceParams { + name: string; + description?: string; + sharing: SharingMode.PRIVATE | SharingMode.SOURCE; + /** + * Whether the destination is an edge or a node. + */ + entityType: EntityType; + /** + * The reference of the node that the edge starts from. Only defined if the destination is an edge. + */ + sourceNode?: ImportTemplateNodeReference; + /** + * The reference of the node that the edge ends to. Only defined if the destination is an edge. + */ + targetNode?: ImportTemplateNodeReference; + /** + * The destination node category / edge type. + */ + itemType: string; + /** + * How to map imported fields to node/edge properties. + */ + properties: ImportTemplatePropertyMapping[]; +} + +export interface ImportTemplatePropertyMapping { + /** + * The field in the imported file. + */ + importedFileField: string; + /** + * The destination property key on the node/edge. + */ + destinationProperty: string; +} + +export interface ImportTemplateNodeReference { + /** + * The field in the imported file. + */ + importedFileField: string; + /** + * The destination node category. + */ + destinationCategory: string; + /** + * The destination property key on the node. If it is undefined, the destination is the native + * ID of the node. + */ + destinationProperty?: string; +} + +export interface DeleteImportTemplateParams extends IDataSourceParams { + id: number; +} + +export interface GetImportTemplatesParams extends IDataSourceParams { + entityType?: EntityType; +} + +export type ImportTemplate = CreateImportTemplateParams & { + id: number; + sourceKey: string; +}; diff --git a/src/index.ts b/src/index.ts index 2dcd7edc..5185908b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,6 +21,7 @@ import {GraphEdgeAPI} from './api/GraphEdge'; import {GraphNodeAPI} from './api/GraphNode'; import {GraphQueryAPI} from './api/GraphQuery'; import {GraphSchemaAPI} from './api/GraphSchema'; +import {ImportAPI} from './api/import'; import {LicenseAPI} from './api/License'; import {LinkuriousAPI} from './api/Linkurious'; import {PluginAPI} from './api/Plugin'; @@ -50,6 +51,7 @@ export class RestClient extends ErrorListener { public readonly graphNode: GraphNodeAPI; public readonly graphQuery: GraphQueryAPI; public readonly graphSchema: GraphSchemaAPI; + public readonly import: ImportAPI; public readonly license: LicenseAPI; public readonly linkurious: LinkuriousAPI; public readonly plugin: PluginAPI; @@ -97,6 +99,7 @@ export class RestClient extends ErrorListener { this.graphNode = new GraphNodeAPI(moduleProps); this.graphQuery = new GraphQueryAPI(moduleProps); this.graphSchema = new GraphSchemaAPI(moduleProps); + this.import = new ImportAPI(moduleProps); this.license = new LicenseAPI(moduleProps); this.linkurious = new LinkuriousAPI(moduleProps); this.plugin = new PluginAPI(moduleProps);