Initial commit

This commit is contained in:
root
2025-12-21 09:57:43 -05:00
committed by Sebastian Krupinski
commit db42b6699c
35 changed files with 6458 additions and 0 deletions
+72
View File
@@ -0,0 +1,72 @@
/**
* File Manager API Service
* Central service for making API calls to the file manager backend
*/
import { createFetchWrapper } from '@KTXC/utils/helpers/fetch-wrapper-core';
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;
+195
View File
@@ -0,0 +1,195 @@
/**
* Collection management service
*/
import { fileManagerApi } from './api';
import type { FilterCondition, SortCondition } from '@/types/common';
import type { FileCollection } from '@/types/node';
export const collectionService = {
/**
* List collections within a location
*
* @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
*/
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,
});
},
/**
* Check if a collection exists
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param identifier - Collection identifier
* @returns Promise with extant status
*/
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;
},
/**
* Fetch a specific collection
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param identifier - Collection identifier
* @returns Promise with collection details
*/
async fetch(
provider: string,
service: string,
identifier: string
): Promise<FileCollection> {
return await fileManagerApi.execute<FileCollection>('collection.fetch', {
provider,
service,
identifier,
});
},
/**
* Create a new collection (folder)
*
* @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
*/
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 ?? {},
});
},
/**
* Modify 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
*/
async modify(
provider: string,
service: string,
identifier: string,
data: Partial<FileCollection>
): Promise<FileCollection> {
return await fileManagerApi.execute<FileCollection>('collection.modify', {
provider,
service,
identifier,
data,
});
},
/**
* Delete a collection
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param identifier - Collection identifier
* @returns Promise with success status
*/
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;
},
/**
* 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;
+293
View File
@@ -0,0 +1,293 @@
/**
* Entity (file) 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';
export const entityService = {
/**
* List entities within a collection
*
* @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
*/
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,
});
},
/**
* Get delta changes for entities since a signature
*
* @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
*/
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,
});
},
/**
* Check which entities exist
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param collection - Collection identifier
* @param identifiers - Entity identifiers to check
* @returns Promise with existence map
*/
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,
});
},
/**
* Fetch specific entities
*
* @param provider - Provider identifier
* @param service - Service identifier
* @param collection - Collection identifier
* @param identifiers - Entity identifiers to fetch
* @returns Promise with entity list
*/
async fetch(
provider: string,
service: string,
collection: string,
identifiers: string[]
): Promise<FileEntity[]> {
return await fileManagerApi.execute<FileEntity[]>('entity.fetch', {
provider,
service,
collection,
identifiers,
});
},
/**
* Read entity content
*
* @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 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
*/
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,
});
},
/**
* 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
*/
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;
},
/**
* Copy an entity to a new location
*
* @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
*/
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,
});
},
/**
* Move an entity to a new location
*
* @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
*/
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,
});
},
/**
* 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
*/
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',
});
return result.bytesWritten;
},
};
export default entityService;
+10
View File
@@ -0,0 +1,10 @@
/**
* Central export point for all File Manager services
*/
export { fileManagerApi } from './api';
export { providerService } from './providerService';
export { serviceService } from './serviceService';
export { collectionService } from './collectionService';
export { entityService } from './entityService';
export { nodeService } from './nodeService';
+74
View File
@@ -0,0 +1,74 @@
/**
* 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';
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,
});
},
/**
* 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,
});
},
};
export default nodeService;
+34
View File
@@ -0,0 +1,34 @@
/**
* Provider management service
*/
import { fileManagerApi } from './api';
import type { SourceSelector } from '@/types/common';
import type { ProviderRecord } from '@/types/provider';
export const providerService = {
/**
* List all available providers
*
* @param sources - Optional source selector to filter providers
* @returns Promise with provider list keyed by provider ID
*/
async list(sources?: SourceSelector): Promise<ProviderRecord> {
return await fileManagerApi.execute<ProviderRecord>('provider.list', {
sources: sources || null
});
},
/**
* Check which providers exist/are available
*
* @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 });
},
};
export default providerService;
+48
View File
@@ -0,0 +1,48 @@
/**
* Service management service
*/
import { fileManagerApi } from './api';
import type { SourceSelector } from '@/types/common';
import type { ServiceInterface, ServiceRecord } from '@/types/service';
export const serviceService = {
/**
* List all available services
*
* @param sources - Optional source selector to filter services
* @returns Promise with service list grouped by provider
*/
async list(sources?: SourceSelector): Promise<ServiceRecord> {
return await fileManagerApi.execute<ServiceRecord>('service.list', {
sources: sources || null
});
},
/**
* Check which services exist/are available
*
* @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 });
},
/**
* Fetch a specific service
*
* @param provider - Provider identifier
* @param identifier - Service identifier
* @returns Promise with service details
*/
async fetch(provider: string, identifier: string): Promise<ServiceInterface> {
return await fileManagerApi.execute<ServiceInterface>('service.fetch', {
provider,
identifier
});
},
};
export default serviceService;