refactor: front end
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -1,72 +0,0 @@
|
||||
/**
|
||||
* File Manager API Service
|
||||
* Central service for making API calls to the file manager backend
|
||||
*/
|
||||
|
||||
import { createFetchWrapper } from '@KTXC';
|
||||
|
||||
const fetchWrapper = createFetchWrapper();
|
||||
|
||||
const BASE_URL = '/m/file_manager/v1';
|
||||
|
||||
interface ApiRequest {
|
||||
version: number;
|
||||
transaction: string;
|
||||
operation: string;
|
||||
data?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
interface ApiSuccessResponse<T> {
|
||||
version: number;
|
||||
transaction: string;
|
||||
operation: string;
|
||||
status: 'success';
|
||||
data: T;
|
||||
}
|
||||
|
||||
interface ApiErrorResponse {
|
||||
version: number;
|
||||
transaction: string;
|
||||
operation: string;
|
||||
status: 'error';
|
||||
error: {
|
||||
code: number;
|
||||
message: string;
|
||||
};
|
||||
}
|
||||
|
||||
type ApiResponseRaw<T> = ApiSuccessResponse<T> | ApiErrorResponse;
|
||||
|
||||
/**
|
||||
* Generate a unique transaction ID
|
||||
*/
|
||||
function generateTransactionId(): string {
|
||||
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute an API operation
|
||||
*/
|
||||
async function execute<T>(operation: string, data: Record<string, unknown> = {}): Promise<T> {
|
||||
const request: ApiRequest = {
|
||||
version: 1,
|
||||
transaction: generateTransactionId(),
|
||||
operation,
|
||||
data,
|
||||
};
|
||||
|
||||
const response: ApiResponseRaw<T> = await fetchWrapper.post(BASE_URL, request);
|
||||
|
||||
if (response.status === 'error') {
|
||||
throw new Error(response.error.message);
|
||||
}
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export const fileManagerApi = {
|
||||
execute,
|
||||
generateTransactionId,
|
||||
};
|
||||
|
||||
export default fileManagerApi;
|
||||
+113
-153
@@ -2,194 +2,154 @@
|
||||
* Collection management service
|
||||
*/
|
||||
|
||||
import { fileManagerApi } from './api';
|
||||
import type { FilterCondition, SortCondition } from '@/types/common';
|
||||
import type { FileCollection } from '@/types/node';
|
||||
import { transceivePost } from './transceive';
|
||||
import type {
|
||||
CollectionListRequest,
|
||||
CollectionListResponse,
|
||||
CollectionExtantRequest,
|
||||
CollectionExtantResponse,
|
||||
CollectionFetchRequest,
|
||||
CollectionFetchResponse,
|
||||
CollectionCreateRequest,
|
||||
CollectionCreateResponse,
|
||||
CollectionUpdateResponse,
|
||||
CollectionUpdateRequest,
|
||||
CollectionDeleteResponse,
|
||||
CollectionDeleteRequest,
|
||||
CollectionInterface,
|
||||
} from '../types/collection';
|
||||
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||
import { CollectionObject, CollectionPropertiesObject } from '../models/collection';
|
||||
|
||||
function isCollectionPayload(value: unknown): value is CollectionInterface {
|
||||
if (!value || typeof value !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const candidate = value as Record<string, unknown>;
|
||||
return (
|
||||
('identifier' in candidate || 'provider' in candidate || 'service' in candidate)
|
||||
&& 'properties' in candidate
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to create the right collection model class based on provider identifier
|
||||
* Uses provider-specific factory if available, otherwise returns base CollectionObject
|
||||
*/
|
||||
function createCollectionObject(data: CollectionInterface): CollectionObject {
|
||||
const integrationStore = useIntegrationStore();
|
||||
const factoryItem = integrationStore.getItemById('documents_collection_factory', data.provider) as any;
|
||||
const factory = factoryItem?.factory;
|
||||
|
||||
// Use provider factory if available, otherwise base class
|
||||
return factory ? factory(data) : new CollectionObject().fromJson(data);
|
||||
}
|
||||
|
||||
export const collectionService = {
|
||||
|
||||
/**
|
||||
* List collections within a location
|
||||
* Retrieve list of collections, optionally filtered by source selector
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param location - Parent collection ID (null for root)
|
||||
* @param filter - Optional filter conditions
|
||||
* @param sort - Optional sort conditions
|
||||
* @returns Promise with collection list
|
||||
* @param request - list request parameters
|
||||
*
|
||||
* @returns Promise with collection object list grouped by provider, service, and collection identifier
|
||||
*/
|
||||
async list(
|
||||
provider: string,
|
||||
service: string,
|
||||
location?: string | null,
|
||||
filter?: FilterCondition[] | null,
|
||||
sort?: SortCondition[] | null
|
||||
): Promise<FileCollection[]> {
|
||||
return await fileManagerApi.execute<FileCollection[]>('collection.list', {
|
||||
provider,
|
||||
service,
|
||||
location: location ?? null,
|
||||
filter: filter ?? null,
|
||||
sort: sort ?? null,
|
||||
async list(request: CollectionListRequest = {}): Promise<Record<string, Record<string, Record<string, CollectionObject>>>> {
|
||||
const response = await transceivePost<CollectionListRequest, CollectionListResponse>('collection.list', request);
|
||||
|
||||
// Convert nested response to CollectionObject instances
|
||||
const providerList: Record<string, Record<string, Record<string, CollectionObject>>> = {};
|
||||
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||
const serviceList: Record<string, Record<string, CollectionObject>> = {};
|
||||
Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
|
||||
const collectionList: Record<string, CollectionObject> = {};
|
||||
Object.entries(serviceCollections as Record<string, unknown>).forEach(([collectionId, collectionData]) => {
|
||||
if (isCollectionPayload(collectionData)) {
|
||||
collectionList[collectionId] = createCollectionObject(collectionData);
|
||||
return;
|
||||
}
|
||||
|
||||
if (collectionData && typeof collectionData === 'object') {
|
||||
Object.entries(collectionData as Record<string, unknown>).forEach(([nestedCollectionId, nestedCollectionData]) => {
|
||||
if (isCollectionPayload(nestedCollectionData)) {
|
||||
collectionList[nestedCollectionId] = createCollectionObject(nestedCollectionData);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
serviceList[serviceId] = collectionList;
|
||||
});
|
||||
providerList[providerId] = serviceList;
|
||||
});
|
||||
|
||||
return providerList;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if a collection exists
|
||||
* Retrieve a specific collection by provider and identifier
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param identifier - Collection identifier
|
||||
* @returns Promise with extant status
|
||||
* @param request - fetch request parameters
|
||||
*
|
||||
* @returns Promise with collection object
|
||||
*/
|
||||
async extant(
|
||||
provider: string,
|
||||
service: string,
|
||||
identifier: string
|
||||
): Promise<boolean> {
|
||||
const result = await fileManagerApi.execute<{ extant: boolean }>('collection.extant', {
|
||||
provider,
|
||||
service,
|
||||
identifier,
|
||||
});
|
||||
return result.extant;
|
||||
async fetch(request: CollectionFetchRequest): Promise<CollectionObject> {
|
||||
const response = await transceivePost<CollectionFetchRequest, CollectionFetchResponse>('collection.fetch', request);
|
||||
return createCollectionObject(response);
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch a specific collection
|
||||
* Retrieve collection availability status for a given source selector
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param identifier - Collection identifier
|
||||
* @returns Promise with collection details
|
||||
* @param request - extant request parameters
|
||||
*
|
||||
* @returns Promise with collection availability status
|
||||
*/
|
||||
async fetch(
|
||||
provider: string,
|
||||
service: string,
|
||||
identifier: string
|
||||
): Promise<FileCollection> {
|
||||
return await fileManagerApi.execute<FileCollection>('collection.fetch', {
|
||||
provider,
|
||||
service,
|
||||
identifier,
|
||||
});
|
||||
async extant(request: CollectionExtantRequest): Promise<CollectionExtantResponse> {
|
||||
return await transceivePost<CollectionExtantRequest, CollectionExtantResponse>('collection.extant', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new collection (folder)
|
||||
* Create a new collection
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param location - Parent collection ID (null for root)
|
||||
* @param data - Collection data (label, etc.)
|
||||
* @param options - Additional options
|
||||
* @returns Promise with created collection
|
||||
* @param request - create request parameters
|
||||
*
|
||||
* @returns Promise with created collection object
|
||||
*/
|
||||
async create(
|
||||
provider: string,
|
||||
service: string,
|
||||
location: string | null,
|
||||
data: Partial<FileCollection>,
|
||||
options?: Record<string, unknown>
|
||||
): Promise<FileCollection> {
|
||||
return await fileManagerApi.execute<FileCollection>('collection.create', {
|
||||
provider,
|
||||
service,
|
||||
location,
|
||||
data,
|
||||
options: options ?? {},
|
||||
});
|
||||
async create(request: CollectionCreateRequest): Promise<CollectionObject> {
|
||||
if (request.properties instanceof CollectionPropertiesObject) {
|
||||
request.properties = request.properties.toJson();
|
||||
}
|
||||
const response = await transceivePost<CollectionCreateRequest, CollectionCreateResponse>('collection.create', request);
|
||||
return createCollectionObject(response);
|
||||
},
|
||||
|
||||
/**
|
||||
* Modify an existing collection
|
||||
* Update an existing collection
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param identifier - Collection identifier
|
||||
* @param data - Data to modify
|
||||
* @returns Promise with modified collection
|
||||
* @param request - update request parameters
|
||||
*
|
||||
* @returns Promise with updated collection object
|
||||
*/
|
||||
async modify(
|
||||
provider: string,
|
||||
service: string,
|
||||
identifier: string,
|
||||
data: Partial<FileCollection>
|
||||
): Promise<FileCollection> {
|
||||
return await fileManagerApi.execute<FileCollection>('collection.modify', {
|
||||
provider,
|
||||
service,
|
||||
identifier,
|
||||
data,
|
||||
});
|
||||
async update(request: CollectionUpdateRequest): Promise<CollectionObject> {
|
||||
if (request.properties instanceof CollectionPropertiesObject) {
|
||||
request.properties = request.properties.toJson();
|
||||
}
|
||||
const response = await transceivePost<CollectionUpdateRequest, CollectionUpdateResponse>('collection.update', request);
|
||||
return createCollectionObject(response);
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete a collection
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param identifier - Collection identifier
|
||||
* @returns Promise with success status
|
||||
* @param request - delete request parameters
|
||||
*
|
||||
* @returns Promise with deletion result
|
||||
*/
|
||||
async destroy(
|
||||
provider: string,
|
||||
service: string,
|
||||
identifier: string
|
||||
): Promise<boolean> {
|
||||
const result = await fileManagerApi.execute<{ success: boolean }>('collection.destroy', {
|
||||
provider,
|
||||
service,
|
||||
identifier,
|
||||
});
|
||||
return result.success;
|
||||
async delete(request: CollectionDeleteRequest): Promise<CollectionDeleteResponse> {
|
||||
return await transceivePost<CollectionDeleteRequest, CollectionDeleteResponse>('collection.delete', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy a collection to a new location
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param identifier - Collection identifier to copy
|
||||
* @param location - Destination parent collection ID (null for root)
|
||||
* @returns Promise with copied collection
|
||||
*/
|
||||
async copy(
|
||||
provider: string,
|
||||
service: string,
|
||||
identifier: string,
|
||||
location?: string | null
|
||||
): Promise<FileCollection> {
|
||||
return await fileManagerApi.execute<FileCollection>('collection.copy', {
|
||||
provider,
|
||||
service,
|
||||
identifier,
|
||||
location: location ?? null,
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Move a collection to a new location
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param identifier - Collection identifier to move
|
||||
* @param location - Destination parent collection ID (null for root)
|
||||
* @returns Promise with moved collection
|
||||
*/
|
||||
async move(
|
||||
provider: string,
|
||||
service: string,
|
||||
identifier: string,
|
||||
location?: string | null
|
||||
): Promise<FileCollection> {
|
||||
return await fileManagerApi.execute<FileCollection>('collection.move', {
|
||||
provider,
|
||||
service,
|
||||
identifier,
|
||||
location: location ?? null,
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
export default collectionService;
|
||||
|
||||
+117
-234
@@ -1,292 +1,175 @@
|
||||
/**
|
||||
* Entity (file) management service
|
||||
* Entity management service
|
||||
*/
|
||||
|
||||
import { fileManagerApi } from './api';
|
||||
import type { FilterCondition, SortCondition, RangeCondition } from '@/types/common';
|
||||
import type { FileEntity } from '@/types/node';
|
||||
import type { EntityDeltaResult } from '@/types/api';
|
||||
import { transceivePost } from './transceive';
|
||||
import type {
|
||||
EntityListRequest,
|
||||
EntityListResponse,
|
||||
EntityFetchRequest,
|
||||
EntityFetchResponse,
|
||||
EntityExtantRequest,
|
||||
EntityExtantResponse,
|
||||
EntityCreateRequest,
|
||||
EntityCreateResponse,
|
||||
EntityUpdateRequest,
|
||||
EntityUpdateResponse,
|
||||
EntityDeleteRequest,
|
||||
EntityDeleteResponse,
|
||||
EntityDeltaRequest,
|
||||
EntityDeltaResponse,
|
||||
EntityReadRequest,
|
||||
EntityReadResponse,
|
||||
EntityWriteRequest,
|
||||
EntityWriteResponse,
|
||||
EntityInterface,
|
||||
} from '../types/entity';
|
||||
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||
import { EntityObject } from '../models';
|
||||
|
||||
/**
|
||||
* Helper to create the right entity model class based on provider identifier
|
||||
* Uses provider-specific factory if available, otherwise returns base EntityObject
|
||||
*/
|
||||
function createEntityObject(data: EntityInterface): EntityObject {
|
||||
const integrationStore = useIntegrationStore();
|
||||
const factoryItem = integrationStore.getItemById('documents_entity_factory', data.provider) as any;
|
||||
const factory = factoryItem?.factory;
|
||||
|
||||
// Use provider factory if available, otherwise base class
|
||||
return factory ? factory(data) : new EntityObject().fromJson(data);
|
||||
}
|
||||
|
||||
export const entityService = {
|
||||
|
||||
/**
|
||||
* List entities within a collection
|
||||
* Retrieve list of entities, optionally filtered by source selector
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param collection - Collection identifier
|
||||
* @param filter - Optional filter conditions
|
||||
* @param sort - Optional sort conditions
|
||||
* @param range - Optional range/pagination conditions
|
||||
* @returns Promise with entity list
|
||||
* @param request - list request parameters
|
||||
*
|
||||
* @returns Promise with entity object list grouped by provider, service, collection, and entity identifier
|
||||
*/
|
||||
async list(
|
||||
provider: string,
|
||||
service: string,
|
||||
collection: string,
|
||||
filter?: FilterCondition[] | null,
|
||||
sort?: SortCondition[] | null,
|
||||
range?: RangeCondition | null
|
||||
): Promise<FileEntity[]> {
|
||||
return await fileManagerApi.execute<FileEntity[]>('entity.list', {
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
filter: filter ?? null,
|
||||
sort: sort ?? null,
|
||||
range: range ?? null,
|
||||
async list(request: EntityListRequest = {}): Promise<Record<string, Record<string, Record<string, Record<string, EntityObject>>>>> {
|
||||
const response = await transceivePost<EntityListRequest, EntityListResponse>('entity.list', request);
|
||||
|
||||
// Convert nested response to EntityObject instances
|
||||
const providerList: Record<string, Record<string, Record<string, Record<string, EntityObject>>>> = {};
|
||||
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||
const serviceList: Record<string, Record<string, Record<string, EntityObject>>> = {};
|
||||
Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
|
||||
const collectionList: Record<string, Record<string, EntityObject>> = {};
|
||||
Object.entries(serviceCollections).forEach(([collectionId, collectionEntities]) => {
|
||||
const entityList: Record<string, EntityObject> = {};
|
||||
Object.entries(collectionEntities).forEach(([entityId, entityData]) => {
|
||||
entityList[entityId] = createEntityObject(entityData);
|
||||
});
|
||||
collectionList[collectionId] = entityList;
|
||||
});
|
||||
serviceList[serviceId] = collectionList;
|
||||
});
|
||||
providerList[providerId] = serviceList;
|
||||
});
|
||||
|
||||
return providerList;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get delta changes for entities since a signature
|
||||
* Retrieve a specific entity by provider and identifier
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param collection - Collection identifier
|
||||
* @param signature - Previous sync signature
|
||||
* @param detail - Detail level ('ids' or 'full')
|
||||
* @returns Promise with delta changes
|
||||
* @param request - fetch request parameters
|
||||
*
|
||||
* @returns Promise with entity objects keyed by identifier
|
||||
*/
|
||||
async delta(
|
||||
provider: string,
|
||||
service: string,
|
||||
collection: string,
|
||||
signature: string,
|
||||
detail: 'ids' | 'full' = 'ids'
|
||||
): Promise<EntityDeltaResult> {
|
||||
return await fileManagerApi.execute<EntityDeltaResult>('entity.delta', {
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
signature,
|
||||
detail,
|
||||
async fetch(request: EntityFetchRequest): Promise<Record<string, EntityObject>> {
|
||||
const response = await transceivePost<EntityFetchRequest, EntityFetchResponse>('entity.fetch', request);
|
||||
|
||||
// Convert response to EntityObject instances
|
||||
const list: Record<string, EntityObject> = {};
|
||||
Object.entries(response).forEach(([identifier, entityData]) => {
|
||||
list[identifier] = createEntityObject(entityData);
|
||||
});
|
||||
|
||||
return list;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check which entities exist
|
||||
* Retrieve entity availability status for a given source selector
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param collection - Collection identifier
|
||||
* @param identifiers - Entity identifiers to check
|
||||
* @returns Promise with existence map
|
||||
* @param request - extant request parameters
|
||||
*
|
||||
* @returns Promise with entity availability status
|
||||
*/
|
||||
async extant(
|
||||
provider: string,
|
||||
service: string,
|
||||
collection: string,
|
||||
identifiers: string[]
|
||||
): Promise<Record<string, boolean>> {
|
||||
return await fileManagerApi.execute<Record<string, boolean>>('entity.extant', {
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
identifiers,
|
||||
});
|
||||
async extant(request: EntityExtantRequest): Promise<EntityExtantResponse> {
|
||||
return await transceivePost<EntityExtantRequest, EntityExtantResponse>('entity.extant', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch specific entities
|
||||
* Create a new entity
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param collection - Collection identifier
|
||||
* @param identifiers - Entity identifiers to fetch
|
||||
* @returns Promise with entity list
|
||||
* @param request - create request parameters
|
||||
*
|
||||
* @returns Promise with created entity object
|
||||
*/
|
||||
async fetch(
|
||||
provider: string,
|
||||
service: string,
|
||||
collection: string,
|
||||
identifiers: string[]
|
||||
): Promise<FileEntity[]> {
|
||||
return await fileManagerApi.execute<FileEntity[]>('entity.fetch', {
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
identifiers,
|
||||
});
|
||||
async create(request: EntityCreateRequest): Promise<EntityObject> {
|
||||
const response = await transceivePost<EntityCreateRequest, EntityCreateResponse>('entity.create', request);
|
||||
return createEntityObject(response);
|
||||
},
|
||||
|
||||
/**
|
||||
* Read entity content
|
||||
* Update an existing entity
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param collection - Collection identifier
|
||||
* @param identifier - Entity identifier
|
||||
* @returns Promise with base64 encoded content
|
||||
*/
|
||||
async read(
|
||||
provider: string,
|
||||
service: string,
|
||||
collection: string,
|
||||
identifier: string
|
||||
): Promise<{ content: string | null; encoding: 'base64' }> {
|
||||
return await fileManagerApi.execute<{ content: string | null; encoding: 'base64' }>('entity.read', {
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
identifier,
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new entity (file)
|
||||
* @param request - update request parameters
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param collection - Collection identifier (null for root)
|
||||
* @param data - Entity data (label, mime, etc.)
|
||||
* @param options - Additional options
|
||||
* @returns Promise with created entity
|
||||
* @returns Promise with updated entity object
|
||||
*/
|
||||
async create(
|
||||
provider: string,
|
||||
service: string,
|
||||
collection: string | null,
|
||||
data: Partial<FileEntity>,
|
||||
options?: Record<string, unknown>
|
||||
): Promise<FileEntity> {
|
||||
return await fileManagerApi.execute<FileEntity>('entity.create', {
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
data,
|
||||
options: options ?? {},
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Modify an existing entity
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param collection - Collection identifier (can be null)
|
||||
* @param identifier - Entity identifier
|
||||
* @param data - Data to modify
|
||||
* @returns Promise with modified entity
|
||||
*/
|
||||
async modify(
|
||||
provider: string,
|
||||
service: string,
|
||||
collection: string | null,
|
||||
identifier: string,
|
||||
data: Partial<FileEntity>
|
||||
): Promise<FileEntity> {
|
||||
return await fileManagerApi.execute<FileEntity>('entity.modify', {
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
identifier,
|
||||
data,
|
||||
});
|
||||
async update(request: EntityUpdateRequest): Promise<EntityObject> {
|
||||
const response = await transceivePost<EntityUpdateRequest, EntityUpdateResponse>('entity.update', request);
|
||||
return createEntityObject(response);
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete an entity
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param collection - Collection identifier (can be null)
|
||||
* @param identifier - Entity identifier
|
||||
* @returns Promise with success status
|
||||
* @param request - delete request parameters
|
||||
*
|
||||
* @returns Promise with deletion result
|
||||
*/
|
||||
async destroy(
|
||||
provider: string,
|
||||
service: string,
|
||||
collection: string | null,
|
||||
identifier: string
|
||||
): Promise<boolean> {
|
||||
const result = await fileManagerApi.execute<{ success: boolean }>('entity.destroy', {
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
identifier,
|
||||
});
|
||||
return result.success;
|
||||
async delete(request: EntityDeleteRequest): Promise<EntityDeleteResponse> {
|
||||
return await transceivePost<EntityDeleteRequest, EntityDeleteResponse>('entity.delete', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Copy an entity to a new location
|
||||
* Retrieve delta changes for entities
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param collection - Source collection identifier (can be null)
|
||||
* @param identifier - Entity identifier to copy
|
||||
* @param destination - Destination collection ID (null for root)
|
||||
* @returns Promise with copied entity
|
||||
* @param request - delta request parameters
|
||||
*
|
||||
* @returns Promise with delta changes (created, modified, deleted)
|
||||
*/
|
||||
async copy(
|
||||
provider: string,
|
||||
service: string,
|
||||
collection: string | null,
|
||||
identifier: string,
|
||||
destination?: string | null
|
||||
): Promise<FileEntity> {
|
||||
return await fileManagerApi.execute<FileEntity>('entity.copy', {
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
identifier,
|
||||
destination: destination ?? null,
|
||||
});
|
||||
async delta(request: EntityDeltaRequest): Promise<EntityDeltaResponse> {
|
||||
return await transceivePost<EntityDeltaRequest, EntityDeltaResponse>('entity.delta', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Move an entity to a new location
|
||||
* Read entity content
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param collection - Source collection identifier (can be null)
|
||||
* @param identifier - Entity identifier to move
|
||||
* @param destination - Destination collection ID (null for root)
|
||||
* @returns Promise with moved entity
|
||||
* @param request - read request parameters
|
||||
* @returns Promise with base64 encoded content
|
||||
*/
|
||||
async move(
|
||||
provider: string,
|
||||
service: string,
|
||||
collection: string | null,
|
||||
identifier: string,
|
||||
destination?: string | null
|
||||
): Promise<FileEntity> {
|
||||
return await fileManagerApi.execute<FileEntity>('entity.move', {
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
identifier,
|
||||
destination: destination ?? null,
|
||||
});
|
||||
async read(request: EntityReadRequest): Promise<EntityReadResponse> {
|
||||
return await transceivePost<EntityReadRequest, EntityReadResponse>('entity.read', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Write content to an entity
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param collection - Collection identifier (can be null)
|
||||
* @param identifier - Entity identifier
|
||||
* @param content - Content to write (base64 encoded)
|
||||
* @returns Promise with bytes written
|
||||
* @param request - write request parameters
|
||||
* @returns Promise with write result
|
||||
*/
|
||||
async write(
|
||||
provider: string,
|
||||
service: string,
|
||||
collection: string | null,
|
||||
identifier: string,
|
||||
content: string
|
||||
): Promise<number> {
|
||||
const result = await fileManagerApi.execute<{ bytesWritten: number }>('entity.write', {
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
identifier,
|
||||
content,
|
||||
encoding: 'base64',
|
||||
async write(request: EntityWriteRequest): Promise<EntityWriteResponse> {
|
||||
return await transceivePost<EntityWriteRequest, EntityWriteResponse>('entity.write', {
|
||||
...request,
|
||||
encoding: request.encoding ?? 'base64',
|
||||
});
|
||||
return result.bytesWritten;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
* Central export point for all File Manager services
|
||||
*/
|
||||
|
||||
export { fileManagerApi } from './api';
|
||||
export { providerService } from './providerService';
|
||||
export { serviceService } from './serviceService';
|
||||
export { collectionService } from './collectionService';
|
||||
|
||||
+57
-63
@@ -2,73 +2,67 @@
|
||||
* Node (unified collection/entity) management service
|
||||
*/
|
||||
|
||||
import { fileManagerApi } from './api';
|
||||
import type { FilterCondition, SortCondition, RangeCondition } from '@/types/common';
|
||||
import type { FileNode } from '@/types/node';
|
||||
import type { NodeDeltaResult } from '@/types/api';
|
||||
import { transceivePost } from './transceive'
|
||||
import type { ListFilter, ListSort, ListRange } from '../types/common'
|
||||
import type { CollectionInterface } from '../types/collection'
|
||||
import type { EntityInterface } from '../types/entity'
|
||||
|
||||
export type NodeItem = CollectionInterface | EntityInterface
|
||||
|
||||
export interface NodeListRequest {
|
||||
provider: string
|
||||
service: string | number
|
||||
location?: string | number | null
|
||||
recursive?: boolean
|
||||
filter?: ListFilter | null
|
||||
sort?: ListSort | null
|
||||
range?: ListRange | null
|
||||
}
|
||||
|
||||
export type NodeListResponse = Record<string, NodeItem>
|
||||
|
||||
export interface NodeDeltaRequest {
|
||||
provider: string
|
||||
service: string | number
|
||||
location?: string | number | null
|
||||
signature: string
|
||||
recursive?: boolean
|
||||
detail?: 'ids' | 'full'
|
||||
}
|
||||
|
||||
export interface NodeDeltaResult {
|
||||
added: Array<string | number | NodeItem>
|
||||
modified: Array<string | number | NodeItem>
|
||||
removed: Array<string | number>
|
||||
signature: string
|
||||
}
|
||||
|
||||
export const nodeService = {
|
||||
|
||||
/**
|
||||
* List all nodes (collections and entities) within a location
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param location - Parent collection ID (null for root)
|
||||
* @param recursive - Whether to list recursively
|
||||
* @param filter - Optional filter conditions
|
||||
* @param sort - Optional sort conditions
|
||||
* @param range - Optional range/pagination conditions
|
||||
* @returns Promise with node list
|
||||
*/
|
||||
async list(
|
||||
provider: string,
|
||||
service: string,
|
||||
location?: string | null,
|
||||
recursive: boolean = false,
|
||||
filter?: FilterCondition[] | null,
|
||||
sort?: SortCondition[] | null,
|
||||
range?: RangeCondition | null
|
||||
): Promise<FileNode[]> {
|
||||
return await fileManagerApi.execute<FileNode[]>('node.list', {
|
||||
provider,
|
||||
service,
|
||||
location: location ?? null,
|
||||
recursive,
|
||||
filter: filter ?? null,
|
||||
sort: sort ?? null,
|
||||
range: range ?? null,
|
||||
});
|
||||
async list(request: NodeListRequest): Promise<NodeItem[]> {
|
||||
const response = await transceivePost<NodeListRequest, NodeListResponse>('node.list', {
|
||||
provider: request.provider,
|
||||
service: request.service,
|
||||
location: request.location ?? null,
|
||||
recursive: request.recursive ?? false,
|
||||
filter: request.filter ?? null,
|
||||
sort: request.sort ?? null,
|
||||
range: request.range ?? null,
|
||||
})
|
||||
|
||||
return Object.values(response)
|
||||
},
|
||||
|
||||
/**
|
||||
* Get delta changes for nodes since a signature
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param service - Service identifier
|
||||
* @param location - Parent collection ID (null for root)
|
||||
* @param signature - Previous sync signature
|
||||
* @param recursive - Whether to get delta recursively
|
||||
* @param detail - Detail level ('ids' or 'full')
|
||||
* @returns Promise with delta changes
|
||||
*/
|
||||
async delta(
|
||||
provider: string,
|
||||
service: string,
|
||||
location: string | null,
|
||||
signature: string,
|
||||
recursive: boolean = false,
|
||||
detail: 'ids' | 'full' = 'ids'
|
||||
): Promise<NodeDeltaResult> {
|
||||
return await fileManagerApi.execute<NodeDeltaResult>('node.delta', {
|
||||
provider,
|
||||
service,
|
||||
location,
|
||||
signature,
|
||||
recursive,
|
||||
detail,
|
||||
});
|
||||
async delta(request: NodeDeltaRequest): Promise<NodeDeltaResult> {
|
||||
return await transceivePost<NodeDeltaRequest, NodeDeltaResult>('node.delta', {
|
||||
provider: request.provider,
|
||||
service: request.service,
|
||||
location: request.location ?? null,
|
||||
signature: request.signature,
|
||||
recursive: request.recursive ?? false,
|
||||
detail: request.detail ?? 'ids',
|
||||
})
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export default nodeService;
|
||||
export default nodeService
|
||||
|
||||
@@ -2,32 +2,74 @@
|
||||
* Provider management service
|
||||
*/
|
||||
|
||||
import { fileManagerApi } from './api';
|
||||
import type { SourceSelector } from '@/types/common';
|
||||
import type { ProviderRecord } from '@/types/provider';
|
||||
import type {
|
||||
ProviderListRequest,
|
||||
ProviderListResponse,
|
||||
ProviderExtantRequest,
|
||||
ProviderExtantResponse,
|
||||
ProviderFetchRequest,
|
||||
ProviderFetchResponse,
|
||||
ProviderInterface,
|
||||
} from '../types/provider';
|
||||
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||
import { transceivePost } from './transceive';
|
||||
import { ProviderObject } from '../models/provider';
|
||||
|
||||
/**
|
||||
* Helper to create the right provider model class based on provider identifier
|
||||
* Uses provider-specific factory if available, otherwise returns base ProviderObject
|
||||
*/
|
||||
function createProviderObject(data: ProviderInterface): ProviderObject {
|
||||
const integrationStore = useIntegrationStore();
|
||||
const factoryItem = integrationStore.getItemById('documents_provider_factory', data.identifier) as any;
|
||||
const factory = factoryItem?.factory;
|
||||
|
||||
// Use provider factory if available, otherwise base class
|
||||
return factory ? factory(data) : new ProviderObject().fromJson(data);
|
||||
}
|
||||
|
||||
export const providerService = {
|
||||
|
||||
/**
|
||||
* List all available providers
|
||||
* Retrieve list of providers, optionally filtered by source selector
|
||||
*
|
||||
* @param sources - Optional source selector to filter providers
|
||||
* @returns Promise with provider list keyed by provider ID
|
||||
* @param request - list request parameters
|
||||
*
|
||||
* @returns Promise with provider object list keyed by provider identifier
|
||||
*/
|
||||
async list(sources?: SourceSelector): Promise<ProviderRecord> {
|
||||
return await fileManagerApi.execute<ProviderRecord>('provider.list', {
|
||||
sources: sources || null
|
||||
async list(request: ProviderListRequest = {}): Promise<Record<string, ProviderObject>> {
|
||||
const response = await transceivePost<ProviderListRequest, ProviderListResponse>('provider.list', request);
|
||||
|
||||
// Convert response to ProviderObject instances
|
||||
const list: Record<string, ProviderObject> = {};
|
||||
Object.entries(response).forEach(([providerId, providerData]) => {
|
||||
list[providerId] = createProviderObject(providerData);
|
||||
});
|
||||
|
||||
return list;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check which providers exist/are available
|
||||
* Retrieve specific provider by identifier
|
||||
*
|
||||
* @param request - fetch request parameters
|
||||
*
|
||||
* @returns Promise with provider object
|
||||
*/
|
||||
async fetch(request: ProviderFetchRequest): Promise<ProviderObject> {
|
||||
const response = await transceivePost<ProviderFetchRequest, ProviderFetchResponse>('provider.fetch', request);
|
||||
return createProviderObject(response);
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve provider availability status for a given source selector
|
||||
*
|
||||
* @param request - extant request parameters
|
||||
*
|
||||
* @param sources - Source selector with provider IDs to check
|
||||
* @returns Promise with provider availability status
|
||||
*/
|
||||
async extant(sources: SourceSelector): Promise<Record<string, boolean>> {
|
||||
return await fileManagerApi.execute<Record<string, boolean>>('provider.extant', { sources });
|
||||
async extant(request: ProviderExtantRequest): Promise<ProviderExtantResponse> {
|
||||
return await transceivePost<ProviderExtantRequest, ProviderExtantResponse>('provider.extant', request);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
+136
-21
@@ -2,46 +2,161 @@
|
||||
* Service management service
|
||||
*/
|
||||
|
||||
import { fileManagerApi } from './api';
|
||||
import type { SourceSelector } from '@/types/common';
|
||||
import type { ServiceInterface, ServiceRecord } from '@/types/service';
|
||||
import type {
|
||||
ServiceListRequest,
|
||||
ServiceListResponse,
|
||||
ServiceFetchRequest,
|
||||
ServiceFetchResponse,
|
||||
ServiceExtantRequest,
|
||||
ServiceExtantResponse,
|
||||
ServiceCreateResponse,
|
||||
ServiceCreateRequest,
|
||||
ServiceUpdateResponse,
|
||||
ServiceUpdateRequest,
|
||||
ServiceDeleteResponse,
|
||||
ServiceDeleteRequest,
|
||||
ServiceDiscoverRequest,
|
||||
ServiceDiscoverResponse,
|
||||
ServiceTestRequest,
|
||||
ServiceTestResponse,
|
||||
ServiceInterface,
|
||||
} from '../types/service';
|
||||
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||
import { transceivePost } from './transceive';
|
||||
import { ServiceObject } from '../models/service';
|
||||
|
||||
/**
|
||||
* Helper to create the right service model class based on provider identifier
|
||||
* Uses provider-specific factory if available, otherwise returns base ServiceObject
|
||||
*/
|
||||
function createServiceObject(data: ServiceInterface): ServiceObject {
|
||||
const integrationStore = useIntegrationStore();
|
||||
const factoryItem = integrationStore.getItemById('documents_service_factory', data.provider) as any;
|
||||
const factory = factoryItem?.factory;
|
||||
|
||||
// Use provider factory if available, otherwise base class
|
||||
return factory ? factory(data) : new ServiceObject().fromJson(data);
|
||||
}
|
||||
|
||||
export const serviceService = {
|
||||
|
||||
/**
|
||||
* List all available services
|
||||
* Retrieve list of services, optionally filtered by source selector
|
||||
*
|
||||
* @param sources - Optional source selector to filter services
|
||||
* @returns Promise with service list grouped by provider
|
||||
* @param request - list request parameters
|
||||
*
|
||||
* @returns Promise with service object list grouped by provider and keyed by service identifier
|
||||
*/
|
||||
async list(sources?: SourceSelector): Promise<ServiceRecord> {
|
||||
return await fileManagerApi.execute<ServiceRecord>('service.list', {
|
||||
sources: sources || null
|
||||
async list(request: ServiceListRequest = {}): Promise<Record<string, Record<string, ServiceObject>>> {
|
||||
const response = await transceivePost<ServiceListRequest, ServiceListResponse>('service.list', request);
|
||||
|
||||
// Convert nested response to ServiceObject instances
|
||||
const providerList: Record<string, Record<string, ServiceObject>> = {};
|
||||
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||
const serviceList: Record<string, ServiceObject> = {};
|
||||
Object.entries(providerServices).forEach(([serviceId, serviceData]) => {
|
||||
serviceList[serviceId] = createServiceObject(serviceData);
|
||||
});
|
||||
providerList[providerId] = serviceList;
|
||||
});
|
||||
|
||||
return providerList;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check which services exist/are available
|
||||
* Retrieve a specific service by provider and identifier
|
||||
*
|
||||
* @param request - fetch request parameters
|
||||
*
|
||||
* @returns Promise with service object
|
||||
*/
|
||||
async fetch(request: ServiceFetchRequest): Promise<ServiceObject> {
|
||||
const response = await transceivePost<ServiceFetchRequest, ServiceFetchResponse>('service.fetch', request);
|
||||
return createServiceObject(response);
|
||||
},
|
||||
|
||||
/**
|
||||
* Retrieve service availability status for a given source selector
|
||||
*
|
||||
* @param request - extant request parameters
|
||||
*
|
||||
* @param sources - Source selector with service IDs to check
|
||||
* @returns Promise with service availability status
|
||||
*/
|
||||
async extant(sources: SourceSelector): Promise<Record<string, boolean>> {
|
||||
return await fileManagerApi.execute<Record<string, boolean>>('service.extant', { sources });
|
||||
async extant(request: ServiceExtantRequest): Promise<ServiceExtantResponse> {
|
||||
return await transceivePost<ServiceExtantRequest, ServiceExtantResponse>('service.extant', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch a specific service
|
||||
* Retrieve discoverable services for a given source selector, sorted by provider
|
||||
*
|
||||
* @param provider - Provider identifier
|
||||
* @param identifier - Service identifier
|
||||
* @returns Promise with service details
|
||||
* @param request - discover request parameters
|
||||
*
|
||||
* @returns Promise with array of discovered services sorted by provider
|
||||
*/
|
||||
async fetch(provider: string, identifier: string): Promise<ServiceInterface> {
|
||||
return await fileManagerApi.execute<ServiceInterface>('service.fetch', {
|
||||
provider,
|
||||
identifier
|
||||
async discover(request: ServiceDiscoverRequest): Promise<ServiceObject[]> {
|
||||
const response = await transceivePost<ServiceDiscoverRequest, ServiceDiscoverResponse>('service.discover', request);
|
||||
|
||||
// Convert discovery results to ServiceObjects
|
||||
const services: ServiceObject[] = [];
|
||||
Object.entries(response).forEach(([providerId, location]) => {
|
||||
const serviceData: ServiceInterface = {
|
||||
'@type': 'documents:service',
|
||||
provider: providerId,
|
||||
identifier: null,
|
||||
label: null,
|
||||
enabled: false,
|
||||
location: location,
|
||||
};
|
||||
services.push(createServiceObject(serviceData));
|
||||
});
|
||||
|
||||
// Sort by provider
|
||||
return services.sort((a, b) => a.provider.localeCompare(b.provider));
|
||||
},
|
||||
|
||||
/**
|
||||
* Test service connectivity and configuration
|
||||
*
|
||||
* @param request - Service test request
|
||||
* @returns Promise with test results
|
||||
*/
|
||||
async test(request: ServiceTestRequest): Promise<ServiceTestResponse> {
|
||||
return await transceivePost<ServiceTestRequest, ServiceTestResponse>('service.test', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new service
|
||||
*
|
||||
* @param request - create request parameters
|
||||
*
|
||||
* @returns Promise with created service object
|
||||
*/
|
||||
async create(request: ServiceCreateRequest): Promise<ServiceObject> {
|
||||
const response = await transceivePost<ServiceCreateRequest, ServiceCreateResponse>('service.create', request);
|
||||
return createServiceObject(response);
|
||||
},
|
||||
|
||||
/**
|
||||
* Update a existing service
|
||||
*
|
||||
* @param request - update request parameters
|
||||
*
|
||||
* @returns Promise with updated service object
|
||||
*/
|
||||
async update(request: ServiceUpdateRequest): Promise<ServiceObject> {
|
||||
const response = await transceivePost<ServiceUpdateRequest, ServiceUpdateResponse>('service.update', request);
|
||||
return createServiceObject(response);
|
||||
},
|
||||
|
||||
/**
|
||||
* Delete a service
|
||||
*
|
||||
* @param request - delete request parameters
|
||||
*
|
||||
* @returns Promise with deletion result
|
||||
*/
|
||||
async delete(request: { provider: string; identifier: string | number }): Promise<any> {
|
||||
return await transceivePost<ServiceDeleteRequest, ServiceDeleteResponse>('service.delete', request);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* API Client for Documents Manager
|
||||
* Provides a centralized way to make API calls with envelope wrapping/unwrapping
|
||||
*/
|
||||
|
||||
import { createFetchWrapper } from '@KTXC';
|
||||
import type { ApiRequest, ApiResponse } from '../types/common';
|
||||
|
||||
const fetchWrapper = createFetchWrapper();
|
||||
const API_URL = '/m/documents_manager/v1';
|
||||
const API_VERSION = 1;
|
||||
|
||||
/**
|
||||
* Generate a unique transaction ID
|
||||
*/
|
||||
export function generateTransactionId(): string {
|
||||
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an API call with automatic envelope wrapping and unwrapping
|
||||
*
|
||||
* @param operation - Operation name (e.g., 'provider.list', 'service.autodiscover')
|
||||
* @param data - Operation-specific request data
|
||||
* @param user - Optional user identifier override
|
||||
* @returns Promise with unwrapped response data
|
||||
* @throws Error if the API returns an error status
|
||||
*/
|
||||
export async function transceivePost<TRequest, TResponse>(
|
||||
operation: string,
|
||||
data: TRequest,
|
||||
user?: string
|
||||
): Promise<TResponse> {
|
||||
const request: ApiRequest<TRequest> = {
|
||||
version: API_VERSION,
|
||||
transaction: generateTransactionId(),
|
||||
operation,
|
||||
data,
|
||||
user
|
||||
};
|
||||
|
||||
const response: ApiResponse<TResponse> = await fetchWrapper.post(API_URL, request);
|
||||
|
||||
if (response.status === 'error') {
|
||||
const errorMessage = `[${operation}] ${response.data.message}${response.data.code ? ` (code: ${response.data.code})` : ''}`;
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
|
||||
return response.data;
|
||||
}
|
||||
Reference in New Issue
Block a user