Merge pull request 'chore: standardize protocol' (#2) from chore/standardize-protocol into main

Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
2026-02-14 16:57:15 +00:00
18 changed files with 3090 additions and 1239 deletions

View File

@@ -226,34 +226,39 @@ class DefaultController extends ControllerAbstract {
return match ($operation) { return match ($operation) {
// Provider operations // Provider operations
'provider.list' => $this->providerList($tenantId, $userId, $data), 'provider.list' => $this->providerList($tenantId, $userId, $data),
'provider.fetch' => $this->providerFetch($tenantId, $userId, $data),
'provider.extant' => $this->providerExtant($tenantId, $userId, $data), 'provider.extant' => $this->providerExtant($tenantId, $userId, $data),
// Service operations // Service operations
'service.list' => $this->serviceList($tenantId, $userId, $data), 'service.list' => $this->serviceList($tenantId, $userId, $data),
'service.extant' => $this->serviceExtant($tenantId, $userId, $data),
'service.fetch' => $this->serviceFetch($tenantId, $userId, $data), 'service.fetch' => $this->serviceFetch($tenantId, $userId, $data),
'service.discover' => $this->serviceDiscover($tenantId, $userId, $data), 'service.extant' => $this->serviceExtant($tenantId, $userId, $data),
'service.test' => $this->serviceTest($tenantId, $userId, $data),
'service.create' => $this->serviceCreate($tenantId, $userId, $data), 'service.create' => $this->serviceCreate($tenantId, $userId, $data),
'service.update' => $this->serviceUpdate($tenantId, $userId, $data), 'service.update' => $this->serviceUpdate($tenantId, $userId, $data),
'service.delete' => $this->serviceDelete($tenantId, $userId, $data), 'service.delete' => $this->serviceDelete($tenantId, $userId, $data),
'service.discover' => $this->serviceDiscover($tenantId, $userId, $data),
'service.test' => $this->serviceTest($tenantId, $userId, $data),
// Collection operations // Collection operations
'collection.list' => $this->collectionList($tenantId, $userId, $data), 'collection.list' => $this->collectionList($tenantId, $userId, $data),
'collection.extant' => $this->collectionExtant($tenantId, $userId, $data),
'collection.fetch' => $this->collectionFetch($tenantId, $userId, $data), 'collection.fetch' => $this->collectionFetch($tenantId, $userId, $data),
'collection.extant' => $this->collectionExtant($tenantId, $userId, $data),
'collection.create' => $this->collectionCreate($tenantId, $userId, $data), 'collection.create' => $this->collectionCreate($tenantId, $userId, $data),
'collection.modify' => $this->collectionModify($tenantId, $userId, $data), 'collection.update' => $this->collectionUpdate($tenantId, $userId, $data),
'collection.destroy' => $this->collectionDestroy($tenantId, $userId, $data), 'collection.delete' => $this->collectionDelete($tenantId, $userId, $data),
'collection.delta' => throw new InvalidArgumentException('Operation not implemented: ' . $operation),
'collection.move' => throw new InvalidArgumentException('Operation not implemented: ' . $operation),
// Entity operations // Entity operations
'entity.list' => $this->entityList($tenantId, $userId, $data), 'entity.list' => $this->entityList($tenantId, $userId, $data),
'entity.delta' => $this->entityDelta($tenantId, $userId, $data),
'entity.extant' => $this->entityExtant($tenantId, $userId, $data),
'entity.fetch' => $this->entityFetch($tenantId, $userId, $data), 'entity.fetch' => $this->entityFetch($tenantId, $userId, $data),
'entity.extant' => $this->entityExtant($tenantId, $userId, $data),
'entity.create' => throw new InvalidArgumentException('Operation not implemented: ' . $operation), 'entity.create' => throw new InvalidArgumentException('Operation not implemented: ' . $operation),
'entity.update' => throw new InvalidArgumentException('Operation not implemented: ' . $operation), 'entity.update' => throw new InvalidArgumentException('Operation not implemented: ' . $operation),
'entity.delete' => throw new InvalidArgumentException('Operation not implemented: ' . $operation), 'entity.delete' => throw new InvalidArgumentException('Operation not implemented: ' . $operation),
'entity.delta' => $this->entityDelta($tenantId, $userId, $data),
'entity.move' => throw new InvalidArgumentException('Operation not implemented: ' . $operation),
'entity.copy' => throw new InvalidArgumentException('Operation not implemented: ' . $operation),
'entity.transmit' => $this->entityTransmit($tenantId, $userId, $data), 'entity.transmit' => $this->entityTransmit($tenantId, $userId, $data),
default => throw new InvalidArgumentException('Unknown operation: ' . $operation) default => throw new InvalidArgumentException('Unknown operation: ' . $operation)
@@ -289,6 +294,18 @@ class DefaultController extends ControllerAbstract {
} }
private function providerFetch(string $tenantId, string $userId, array $data): mixed {
if (!isset($data['identifier'])) {
throw new InvalidArgumentException(self::ERR_MISSING_IDENTIFIER);
}
if (!is_string($data['identifier'])) {
throw new InvalidArgumentException(self::ERR_INVALID_IDENTIFIER);
}
return $this->mailManager->providerFetch($tenantId, $userId, $data['identifier']);
}
// ==================== Service Operations ===================== // ==================== Service Operations =====================
private function serviceList(string $tenantId, string $userId, array $data): mixed { private function serviceList(string $tenantId, string $userId, array $data): mixed {
@@ -536,7 +553,7 @@ class DefaultController extends ControllerAbstract {
); );
} }
private function collectionModify(string $tenantId, string $userId, array $data): mixed { private function collectionUpdate(string $tenantId, string $userId, array $data): mixed {
if (!isset($data['provider'])) { if (!isset($data['provider'])) {
throw new InvalidArgumentException(self::ERR_MISSING_PROVIDER); throw new InvalidArgumentException(self::ERR_MISSING_PROVIDER);
} }
@@ -562,7 +579,7 @@ class DefaultController extends ControllerAbstract {
throw new InvalidArgumentException(self::ERR_INVALID_DATA); throw new InvalidArgumentException(self::ERR_INVALID_DATA);
} }
return $this->mailManager->collectionModify( return $this->mailManager->collectionUpdate(
$tenantId, $tenantId,
$userId, $userId,
$data['provider'], $data['provider'],
@@ -572,7 +589,7 @@ class DefaultController extends ControllerAbstract {
); );
} }
private function collectionDestroy(string $tenantId, string $userId, array $data): mixed { private function collectionDelete(string $tenantId, string $userId, array $data): mixed {
if (!isset($data['provider'])) { if (!isset($data['provider'])) {
throw new InvalidArgumentException(self::ERR_MISSING_PROVIDER); throw new InvalidArgumentException(self::ERR_MISSING_PROVIDER);
} }
@@ -592,7 +609,7 @@ class DefaultController extends ControllerAbstract {
throw new InvalidArgumentException(self::ERR_INVALID_IDENTIFIER); throw new InvalidArgumentException(self::ERR_INVALID_IDENTIFIER);
} }
return $this->mailManager->collectionDestroy( return $this->mailManager->collectionDelete(
$tenantId, $tenantId,
$userId, $userId,
$data['provider'], $data['provider'],

View File

@@ -621,7 +621,7 @@ class Manager {
* @return CollectionBaseInterface * @return CollectionBaseInterface
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function collectionModify(string $tenantId, string $userId, string $providerId, string|int $serviceId, string|int $collectionId, CollectionMutableInterface|array $object): CollectionBaseInterface { public function collectionUpdate(string $tenantId, string $userId, string $providerId, string|int $serviceId, string|int $collectionId, CollectionMutableInterface|array $object): CollectionBaseInterface {
// retrieve service // retrieve service
$service = $this->serviceFetch($tenantId, $userId, $providerId, $serviceId); $service = $this->serviceFetch($tenantId, $userId, $providerId, $serviceId);
@@ -629,8 +629,8 @@ class Manager {
if (!($service instanceof ServiceCollectionMutableInterface)) { if (!($service instanceof ServiceCollectionMutableInterface)) {
throw new InvalidArgumentException("Service does not support collection mutations"); throw new InvalidArgumentException("Service does not support collection mutations");
} }
if (!$service->capable(ServiceCollectionMutableInterface::CAPABILITY_COLLECTION_MODIFY)) { if (!$service->capable(ServiceCollectionMutableInterface::CAPABILITY_COLLECTION_UPDATE)) {
throw new InvalidArgumentException("Service is not capable of modifying collections"); throw new InvalidArgumentException("Service is not capable of updating collections");
} }
if (is_array($object)) { if (is_array($object)) {
@@ -640,12 +640,12 @@ class Manager {
$collection = $object; $collection = $object;
} }
// Modify collection // Update collection
return $service->collectionModify($collectionId, $collection); return $service->collectionUpdate($collectionId, $collection);
} }
/** /**
* Destroy a specific collection * Delete a specific collection
* *
* @since 2025.05.01 * @since 2025.05.01
* *
@@ -657,23 +657,23 @@ class Manager {
* *
* @return CollectionBaseInterface|null * @return CollectionBaseInterface|null
*/ */
public function collectionDestroy(string $tenantId, ?string $userId, string $providerId, string|int $serviceId, string|int $collectionId, array $options = []): bool { public function collectionDelete(string $tenantId, ?string $userId, string $providerId, string|int $serviceId, string|int $collectionId, array $options = []): bool {
// retrieve service // retrieve service
$service = $this->serviceFetch($tenantId, $userId, $providerId, $serviceId); $service = $this->serviceFetch($tenantId, $userId, $providerId, $serviceId);
// Check if service supports collection destruction // Check if service supports collection deletion
if (!($service instanceof ServiceCollectionMutableInterface)) { if (!($service instanceof ServiceCollectionMutableInterface)) {
throw new InvalidArgumentException("Service does not support collection mutations"); throw new InvalidArgumentException("Service does not support collection mutations");
} }
if (!$service->capable(ServiceCollectionMutableInterface::CAPABILITY_COLLECTION_DESTROY)) { if (!$service->capable(ServiceCollectionMutableInterface::CAPABILITY_COLLECTION_DELETE)) {
throw new InvalidArgumentException("Service is not capable of destroying collections"); throw new InvalidArgumentException("Service is not capable of deleting collections");
} }
$force = $options['force'] ?? false; $force = $options['force'] ?? false;
$recursive = $options['recursive'] ?? false; $recursive = $options['recursive'] ?? false;
// destroy collection // delete collection
return $service->collectionDestroy($collectionId, $force, $recursive); return $service->collectionDelete($collectionId, $force, $recursive);
} }
// ==================== Message Operations ==================== // ==================== Message Operations ====================

1500
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -37,6 +37,7 @@ export function useMailSync(options: SyncOptions = {}) {
const lastSync = ref<Date | null>(null); const lastSync = ref<Date | null>(null);
const error = ref<string | null>(null); const error = ref<string | null>(null);
const sources = ref<SyncSource[]>([]); const sources = ref<SyncSource[]>([]);
const signatures = ref<Record<string, Record<string, Record<string, string>>>>({});
let syncInterval: ReturnType<typeof setInterval> | null = null; let syncInterval: ReturnType<typeof setInterval> | null = null;
@@ -101,12 +102,12 @@ export function useMailSync(options: SyncOptions = {}) {
// Add collections to check with their signatures // Add collections to check with their signatures
source.collections.forEach(collection => { source.collections.forEach(collection => {
// Look up signature from entities store first (updated by delta), fallback to collections store // Look up signature from local tracking (updated by delta)
let signature = entitiesStore.signatures[source.provider]?.[String(source.service)]?.[String(collection)]; let signature = signatures.value[source.provider]?.[String(source.service)]?.[String(collection)];
// Fallback to collection signature if not yet synced // Fallback to collection signature if not yet synced
if (!signature) { if (!signature) {
const collectionData = collectionsStore.collections[source.provider]?.[String(source.service)]?.[String(collection)]; const collectionData = collectionsStore.collection(source.provider, source.service, collection);
signature = collectionData?.signature || ''; signature = collectionData?.signature || '';
} }
@@ -118,7 +119,7 @@ export function useMailSync(options: SyncOptions = {}) {
}); });
// Get delta changes // Get delta changes
const deltaResponse = await entitiesStore.getDelta(deltaSources); const deltaResponse = await entitiesStore.delta(deltaSources);
// If fetchDetails is enabled, fetch full entity data for additions and modifications // If fetchDetails is enabled, fetch full entity data for additions and modifications
if (fetchDetails) { if (fetchDetails) {
const fetchPromises: Promise<any>[] = []; const fetchPromises: Promise<any>[] = [];
@@ -131,6 +132,18 @@ export function useMailSync(options: SyncOptions = {}) {
return; return;
} }
// Update signature tracking
if (collectionData.signature) {
if (!signatures.value[provider]) {
signatures.value[provider] = {};
}
if (!signatures.value[provider][service]) {
signatures.value[provider][service] = {};
}
signatures.value[provider][service][collection] = collectionData.signature;
console.log(`[Sync] Updated signature for ${provider}/${service}/${collection}: "${collectionData.signature}"`);
}
// Check if signature actually changed (if not, skip fetching) // Check if signature actually changed (if not, skip fetching)
const oldSignature = deltaSources[provider]?.[service]?.[collection]; const oldSignature = deltaSources[provider]?.[service]?.[collection];
const newSignature = collectionData.signature; const newSignature = collectionData.signature;
@@ -149,7 +162,7 @@ export function useMailSync(options: SyncOptions = {}) {
if (identifiersToFetch.length > 0) { if (identifiersToFetch.length > 0) {
console.log(`[Sync] Fetching ${identifiersToFetch.length} entities for ${provider}/${service}/${collection}`); console.log(`[Sync] Fetching ${identifiersToFetch.length} entities for ${provider}/${service}/${collection}`);
fetchPromises.push( fetchPromises.push(
entitiesStore.getMessages( entitiesStore.fetch(
provider, provider,
service, service,
collection, collection,

View File

@@ -12,28 +12,74 @@ import type {
CollectionFetchResponse, CollectionFetchResponse,
CollectionCreateRequest, CollectionCreateRequest,
CollectionCreateResponse, CollectionCreateResponse,
CollectionModifyRequest, CollectionUpdateResponse,
CollectionModifyResponse, CollectionUpdateRequest,
CollectionDestroyRequest, CollectionDeleteResponse,
CollectionDestroyResponse CollectionDeleteRequest,
CollectionInterface,
} from '../types/collection'; } from '../types/collection';
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
import { CollectionObject } from '../models';
/**
* 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('mail_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 = { export const collectionService = {
/** /**
* List all available collections * Retrieve list of collections, optionally filtered by source selector
* *
* @param request - Collection list request parameters * @param request - list request parameters
* @returns Promise with collection list grouped by provider and service *
* @returns Promise with collection object list grouped by provider, service, and collection identifier
*/ */
async list(request: CollectionListRequest = {}): Promise<CollectionListResponse> { async list(request: CollectionListRequest = {}): Promise<Record<string, Record<string, Record<string, CollectionObject>>>> {
return await transceivePost<CollectionListRequest, CollectionListResponse>('collection.list', request); 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).forEach(([collectionId, collectionData]) => {
collectionList[collectionId] = createCollectionObject(collectionData);
});
serviceList[serviceId] = collectionList;
});
providerList[providerId] = serviceList;
});
return providerList;
}, },
/** /**
* Check which collections exist/are available * Retrieve a specific collection by provider and identifier
*
* @param request - fetch request parameters
*
* @returns Promise with collection object
*/
async fetch(request: CollectionFetchRequest): Promise<CollectionObject> {
const response = await transceivePost<CollectionFetchRequest, CollectionFetchResponse>('collection.fetch', request);
return createCollectionObject(response);
},
/**
* Retrieve collection availability status for a given source selector
*
* @param request - extant request parameters
* *
* @param request - Collection extant request with source selector
* @returns Promise with collection availability status * @returns Promise with collection availability status
*/ */
async extant(request: CollectionExtantRequest): Promise<CollectionExtantResponse> { async extant(request: CollectionExtantRequest): Promise<CollectionExtantResponse> {
@@ -41,43 +87,38 @@ export const collectionService = {
}, },
/** /**
* Fetch a specific collection * Create a new collection
* *
* @param request - Collection fetch request * @param request - create request parameters
* @returns Promise with collection details *
* @returns Promise with created collection object
*/ */
async fetch(request: CollectionFetchRequest): Promise<CollectionFetchResponse> { async create(request: CollectionCreateRequest): Promise<CollectionObject> {
return await transceivePost<CollectionFetchRequest, CollectionFetchResponse>('collection.fetch', request); const response = await transceivePost<CollectionCreateRequest, CollectionCreateResponse>('collection.create', request);
return createCollectionObject(response);
}, },
/** /**
* Create a new collection/folder * Update an existing collection
* *
* @param request - Collection creation parameters * @param request - update request parameters
* @returns Promise with created collection details *
* @returns Promise with updated collection object
*/ */
async create(request: CollectionCreateRequest): Promise<CollectionCreateResponse> { async update(request: CollectionUpdateRequest): Promise<CollectionObject> {
return await transceivePost<CollectionCreateRequest, CollectionCreateResponse>('collection.create', request); const response = await transceivePost<CollectionUpdateRequest, CollectionUpdateResponse>('collection.update', request);
return createCollectionObject(response);
}, },
/** /**
* Modify an existing collection/folder * Delete a collection
* *
* @param request - Collection modification parameters * @param request - delete request parameters
* @returns Promise with modified collection details
*/
async modify(request: CollectionModifyRequest): Promise<CollectionModifyResponse> {
return await transceivePost<CollectionModifyRequest, CollectionModifyResponse>('collection.modify', request);
},
/**
* Destroy/delete a collection/folder
* *
* @param request - Collection destroy parameters * @returns Promise with deletion result
* @returns Promise with destroy operation result
*/ */
async destroy(request: CollectionDestroyRequest): Promise<CollectionDestroyResponse> { async delete(request: CollectionDeleteRequest): Promise<CollectionDeleteResponse> {
return await transceivePost<CollectionDestroyRequest, CollectionDestroyResponse>('collection.destroy', request); return await transceivePost<CollectionDeleteRequest, CollectionDeleteResponse>('collection.delete', request);
}, },
}; };

View File

@@ -1,119 +1,161 @@
/** /**
* Message/Entity management service * Entity management service
*/ */
import { transceivePost } from './transceive'; import { transceivePost } from './transceive';
import type { import type {
MessageListRequest, EntityListRequest,
MessageListResponse, EntityListResponse,
MessageDeltaRequest, EntityFetchRequest,
MessageDeltaResponse, EntityFetchResponse,
MessageExtantRequest, EntityExtantRequest,
MessageExtantResponse, EntityExtantResponse,
MessageFetchRequest, EntityCreateRequest,
MessageFetchResponse, EntityCreateResponse,
MessageSearchRequest, EntityUpdateRequest,
MessageSearchResponse, EntityUpdateResponse,
MessageSendRequest, EntityDeleteRequest,
MessageSendResponse, EntityDeleteResponse,
MessageCreateRequest, EntityDeltaRequest,
MessageCreateResponse, EntityDeltaResponse,
MessageUpdateRequest, EntityTransmitRequest,
MessageUpdateResponse, EntityTransmitResponse,
MessageDestroyRequest, EntityInterface,
MessageDestroyResponse,
} from '../types/entity'; } 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('mail_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 = { export const entityService = {
/** /**
* List all available messages * Retrieve list of entities, optionally filtered by source selector
* *
* @param request - Message list request parameters * @param request - list request parameters
* @returns Promise with message list grouped by provider, service, and collection *
* @returns Promise with entity object list grouped by provider, service, collection, and entity identifier
*/ */
async list(request: MessageListRequest = {}): Promise<MessageListResponse> { async list(request: EntityListRequest = {}): Promise<Record<string, Record<string, Record<string, Record<string, EntityObject>>>>> {
return await transceivePost<MessageListRequest, MessageListResponse>('entity.list', request); 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 messages * Retrieve a specific entity by provider and identifier
*
* @param request - fetch request parameters
*
* @returns Promise with entity objects keyed by identifier
*/
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;
},
/**
* Retrieve entity availability status for a given source selector
*
* @param request - extant request parameters
*
* @returns Promise with entity availability status
*/
async extant(request: EntityExtantRequest): Promise<EntityExtantResponse> {
return await transceivePost<EntityExtantRequest, EntityExtantResponse>('entity.extant', request);
},
/**
* Create a new entity
*
* @param request - create request parameters
*
* @returns Promise with created entity object
*/
async create(request: EntityCreateRequest): Promise<EntityObject> {
const response = await transceivePost<EntityCreateRequest, EntityCreateResponse>('entity.create', request);
return createEntityObject(response);
},
/**
* Update an existing entity
*
* @param request - update request parameters
*
* @returns Promise with updated entity object
*/
async update(request: EntityUpdateRequest): Promise<EntityObject> {
const response = await transceivePost<EntityUpdateRequest, EntityUpdateResponse>('entity.update', request);
return createEntityObject(response);
},
/**
* Delete an entity
*
* @param request - delete request parameters
*
* @returns Promise with deletion result
*/
async delete(request: EntityDeleteRequest): Promise<EntityDeleteResponse> {
return await transceivePost<EntityDeleteRequest, EntityDeleteResponse>('entity.delete', request);
},
/**
* Retrieve delta changes for entities
*
* @param request - delta request parameters
* *
* @param request - Message delta request with source selector
* @returns Promise with delta changes (created, modified, deleted) * @returns Promise with delta changes (created, modified, deleted)
*/ */
async delta(request: MessageDeltaRequest): Promise<MessageDeltaResponse> { async delta(request: EntityDeltaRequest): Promise<EntityDeltaResponse> {
return await transceivePost('entity.delta', request); return await transceivePost<EntityDeltaRequest, EntityDeltaResponse>('entity.delta', request);
}, },
/** /**
* Check which messages exist/are available * Send an entity
* *
* @param request - Message extant request with source selector * @param request - transmit request parameters
* @returns Promise with message availability status
*/
async extant(request: MessageExtantRequest): Promise<MessageExtantResponse> {
return await transceivePost('entity.extant', request);
},
/**
* Fetch specific messages
* *
* @param request - Message fetch request * @returns Promise with transmission result
* @returns Promise with message details
*/ */
async fetch(request: MessageFetchRequest): Promise<MessageFetchResponse> { async transmit(request: EntityTransmitRequest): Promise<EntityTransmitResponse> {
return await transceivePost('entity.fetch', request); return await transceivePost<EntityTransmitRequest, EntityTransmitResponse>('entity.transmit', request);
},
/**
* Search messages
*
* @param request - Message search request
* @returns Promise with search results
*/
async search(request: MessageSearchRequest): Promise<MessageSearchResponse> {
return await transceivePost('entity.search', request);
},
/**
* Send a message
*
* @param request - Message send request
* @returns Promise with send result
*/
async send(request: MessageSendRequest): Promise<MessageSendResponse> {
return await transceivePost('entity.send', request);
},
/**
* Create a new message (draft)
*
* @param request - Message create request
* @returns Promise with created message details
*/
async create(request: MessageCreateRequest): Promise<MessageCreateResponse> {
return await transceivePost('entity.create', request);
},
/**
* Update an existing message (flags, labels, etc.)
*
* @param request - Message update request
* @returns Promise with update result
*/
async update(request: MessageUpdateRequest): Promise<MessageUpdateResponse> {
return await transceivePost('entity.update', request);
},
/**
* Delete/destroy a message
*
* @param request - Message destroy request
* @returns Promise with destroy result
*/
async destroy(request: MessageDestroyRequest): Promise<MessageDestroyResponse> {
return await transceivePost('entity.destroy', request);
}, },
}; };

View File

@@ -9,17 +9,31 @@ import type {
ProviderExtantResponse, ProviderExtantResponse,
ProviderFetchRequest, ProviderFetchRequest,
ProviderFetchResponse, ProviderFetchResponse,
ProviderInterface,
} from '../types/provider'; } from '../types/provider';
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
import { transceivePost } from './transceive'; import { transceivePost } from './transceive';
import { ProviderObject } from '../models/provider'; 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('mail_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 = { export const providerService = {
/** /**
* List available providers * Retrieve list of providers, optionally filtered by source selector
* *
* @param request - List request parameters * @param request - list request parameters
* *
* @returns Promise with provider object list keyed by provider identifier * @returns Promise with provider object list keyed by provider identifier
*/ */
@@ -29,28 +43,28 @@ export const providerService = {
// Convert response to ProviderObject instances // Convert response to ProviderObject instances
const list: Record<string, ProviderObject> = {}; const list: Record<string, ProviderObject> = {};
Object.entries(response).forEach(([providerId, providerData]) => { Object.entries(response).forEach(([providerId, providerData]) => {
list[providerId] = new ProviderObject().fromJson(providerData); list[providerId] = createProviderObject(providerData);
}); });
return list; return list;
}, },
/** /**
* Fetch a specific provider * Retrieve specific provider by identifier
* *
* @param request - Fetch request parameters * @param request - fetch request parameters
* *
* @returns Promise with provider object * @returns Promise with provider object
*/ */
async fetch(request: ProviderFetchRequest): Promise<ProviderObject> { async fetch(request: ProviderFetchRequest): Promise<ProviderObject> {
const response = await transceivePost<ProviderFetchRequest, ProviderFetchResponse>('provider.fetch', request); const response = await transceivePost<ProviderFetchRequest, ProviderFetchResponse>('provider.fetch', request);
return new ProviderObject().fromJson(response); return createProviderObject(response);
}, },
/** /**
* Check which providers exist/are available * Retrieve provider availability status for a given source selector
* *
* @param request - Extant request parameters * @param request - extant request parameters
* *
* @returns Promise with provider availability status * @returns Promise with provider availability status
*/ */

View File

@@ -18,13 +18,15 @@ import type {
ServiceCreateRequest, ServiceCreateRequest,
ServiceUpdateResponse, ServiceUpdateResponse,
ServiceUpdateRequest, ServiceUpdateRequest,
ServiceDeleteResponse,
ServiceDeleteRequest,
} from '../types/service'; } from '../types/service';
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
import { transceivePost } from './transceive'; import { transceivePost } from './transceive';
import { ServiceObject } from '../models/service'; import { ServiceObject } from '../models/service';
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
/** /**
* Helper to create the right service model class based on provider * Helper to create the right service model class based on provider identifier
* Uses provider-specific factory if available, otherwise returns base ServiceObject * Uses provider-specific factory if available, otherwise returns base ServiceObject
*/ */
function createServiceObject(data: ServiceInterface): ServiceObject { function createServiceObject(data: ServiceInterface): ServiceObject {
@@ -39,9 +41,9 @@ function createServiceObject(data: ServiceInterface): ServiceObject {
export const serviceService = { export const serviceService = {
/** /**
* List available services * Retrieve list of services, optionally filtered by source selector
* *
* @param request - Service list request parameters * @param request - list request parameters
* *
* @returns Promise with service object list grouped by provider and keyed by service identifier * @returns Promise with service object list grouped by provider and keyed by service identifier
*/ */
@@ -49,31 +51,23 @@ export const serviceService = {
const response = await transceivePost<ServiceListRequest, ServiceListResponse>('service.list', request); const response = await transceivePost<ServiceListRequest, ServiceListResponse>('service.list', request);
// Convert nested response to ServiceObject instances // Convert nested response to ServiceObject instances
const list: Record<string, Record<string, ServiceObject>> = {}; const providerList: Record<string, Record<string, ServiceObject>> = {};
Object.entries(response).forEach(([providerId, providerServices]) => { Object.entries(response).forEach(([providerId, providerServices]) => {
list[providerId] = {}; const serviceList: Record<string, ServiceObject> = {};
Object.entries(providerServices).forEach(([serviceId, serviceData]) => { Object.entries(providerServices).forEach(([serviceId, serviceData]) => {
list[providerId][serviceId] = createServiceObject(serviceData); serviceList[serviceId] = createServiceObject(serviceData);
}); });
providerList[providerId] = serviceList;
}); });
return list; return providerList;
}, },
/** /**
* Check which services exist/are available * Retrieve a specific service by provider and identifier
* *
* @param request - Service extant request with source selector * @param request - fetch request parameters
* @returns Promise with service availability status
*/
async extant(request: ServiceExtantRequest): Promise<ServiceExtantResponse> {
return await transceivePost<ServiceExtantRequest, ServiceExtantResponse>('service.extant', request);
},
/**
* Fetch a specific service
* *
* @param request - Service fetch request with provider and service IDs
* @returns Promise with service object * @returns Promise with service object
*/ */
async fetch(request: ServiceFetchRequest): Promise<ServiceObject> { async fetch(request: ServiceFetchRequest): Promise<ServiceObject> {
@@ -82,9 +76,21 @@ export const serviceService = {
}, },
/** /**
* Discover mail service configuration from identity * Retrieve service availability status for a given source selector
*
* @param request - extant request parameters
*
* @returns Promise with service availability status
*/
async extant(request: ServiceExtantRequest): Promise<ServiceExtantResponse> {
return await transceivePost<ServiceExtantRequest, ServiceExtantResponse>('service.extant', request);
},
/**
* Retrieve discoverable services for a given source selector, sorted by provider
*
* @param request - discover request parameters
* *
* @param request - Discovery request with identity and optional hints
* @returns Promise with array of discovered services sorted by provider * @returns Promise with array of discovered services sorted by provider
*/ */
async discover(request: ServiceDiscoverRequest): Promise<ServiceObject[]> { async discover(request: ServiceDiscoverRequest): Promise<ServiceObject[]> {
@@ -109,7 +115,7 @@ export const serviceService = {
}, },
/** /**
* Test a mail service connection * Test service connectivity and configuration
* *
* @param request - Service test request * @param request - Service test request
* @returns Promise with test results * @returns Promise with test results
@@ -121,7 +127,8 @@ export const serviceService = {
/** /**
* Create a new service * Create a new service
* *
* @param request - Service create request with provider ID and service data * @param request - create request parameters
*
* @returns Promise with created service object * @returns Promise with created service object
*/ */
async create(request: ServiceCreateRequest): Promise<ServiceObject> { async create(request: ServiceCreateRequest): Promise<ServiceObject> {
@@ -132,7 +139,8 @@ export const serviceService = {
/** /**
* Update a existing service * Update a existing service
* *
* @param request - Service update request with provider ID, service ID, and updated data * @param request - update request parameters
*
* @returns Promise with updated service object * @returns Promise with updated service object
*/ */
async update(request: ServiceUpdateRequest): Promise<ServiceObject> { async update(request: ServiceUpdateRequest): Promise<ServiceObject> {
@@ -143,11 +151,12 @@ export const serviceService = {
/** /**
* Delete a service * Delete a service
* *
* @param request - Service delete request with provider ID and service ID * @param request - delete request parameters
*
* @returns Promise with deletion result * @returns Promise with deletion result
*/ */
async delete(request: { provider: string; identifier: string | number }): Promise<any> { async delete(request: { provider: string; identifier: string | number }): Promise<any> {
return await transceivePost('service.delete', request); return await transceivePost<ServiceDeleteRequest, ServiceDeleteResponse>('service.delete', request);
}, },
}; };

View File

@@ -1,169 +1,329 @@
/**
* Collections Store
*/
import { ref, computed, readonly } from 'vue'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { collectionService } from '../services' import { collectionService } from '../services'
import type { CollectionInterface, CollectionCreateRequest } from '../types' import { CollectionObject } from '../models/collection'
import { CollectionObject, CollectionPropertiesObject } from '../models/collection' import type { SourceSelector, ListFilter, ListSort, CollectionMutableProperties } from '../types'
export const useCollectionsStore = defineStore('mail-collections', { export const useCollectionsStore = defineStore('mailCollectionsStore', () => {
state: () => ({ // State
collections: {} as Record<string, Record<string, Record<string, CollectionObject>>>, const _collections = ref<Record<string, CollectionObject>>({})
loading: false, const transceiving = ref(false)
error: null as string | null,
}),
actions: { /**
async loadCollections(sources?: any) { * Get count of collections in store
this.loading = true */
this.error = null const count = computed(() => Object.keys(_collections.value).length)
/**
* Check if any collections are present in store
*/
const has = computed(() => count.value > 0)
/**
* Get all collections present in store
*/
const collections = computed(() => Object.values(_collections.value))
/**
* Get all collections present in store grouped by service
*/
const collectionsByService = computed(() => {
const groups: Record<string, CollectionObject[]> = {}
Object.values(_collections.value).forEach((collection) => {
const serviceKey = `${collection.provider}:${collection.service}`
if (!groups[serviceKey]) {
groups[serviceKey] = []
}
groups[serviceKey].push(collection)
})
return groups
})
/**
* Get a specific collection from store, with optional retrieval
*
* @param provider - provider identifier
* @param service - service identifier
* @param identifier - collection identifier
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
*
* @returns Collection object or null
*/
function collection(provider: string, service: string | number, identifier: string | number, retrieve: boolean = false): CollectionObject | null {
const key = identifierKey(provider, service, identifier)
if (retrieve === true && !_collections.value[key]) {
console.debug(`[Mail Manager][Store] - Force fetching collection "${key}"`)
fetch(provider, service, identifier)
}
return _collections.value[key] || null
}
/**
* Get all collections for a specific service
*
* @param provider - provider identifier
* @param service - service identifier
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
*
* @returns Array of collection objects
*/
function collectionsForService(provider: string, service: string | number, retrieve: boolean = false): CollectionObject[] {
const serviceKeyPrefix = `${provider}:${service}:`
const serviceCollections = Object.entries(_collections.value)
.filter(([key]) => key.startsWith(serviceKeyPrefix))
.map(([_, collection]) => collection)
if (retrieve === true && serviceCollections.length === 0) {
console.debug(`[Mail Manager][Store] - Force fetching collections for service "${provider}:${service}"`)
const sources: SourceSelector = {
[provider]: {
[String(service)]: true
}
}
list(sources)
}
return serviceCollections
}
function collectionsInCollection(provider: string, service: string | number, collectionId: string | number, retrieve: boolean = false): CollectionObject[] {
const collectionKeyPrefix = `${provider}:${service}:${collectionId}:`
const nestedCollections = Object.entries(_collections.value)
.filter(([key]) => key.startsWith(collectionKeyPrefix))
.map(([_, collection]) => collection)
if (retrieve === true && nestedCollections.length === 0) {
console.debug(`[Mail Manager][Store] - Force fetching collections in collection "${provider}:${service}:${collectionId}"`)
const sources: SourceSelector = {
[provider]: {
[String(service)]: {
[String(collectionId)]: true
}
}
}
list(sources)
}
return nestedCollections
}
/**
* Create unique key for a collection
*/
function identifierKey(provider: string, service: string | number | null, identifier: string | number | null): string {
return `${provider}:${service ?? ''}:${identifier ?? ''}`
}
// Actions
/**
* Retrieve all or specific collections, optionally filtered by source selector
*
* @param sources - optional source selector
* @param filter - optional list filter
* @param sort - optional list sort
*
* @returns Promise with collection object list keyed by provider, service, and collection identifier
*/
async function list(sources?: SourceSelector, filter?: ListFilter, sort?: ListSort): Promise<Record<string, CollectionObject>> {
transceiving.value = true
try { try {
const response = await collectionService.list({ sources }) const response = await collectionService.list({ sources, filter, sort })
// Response is already in nested object format: provider -> service -> collection // Flatten nested structure: provider:service:collection -> "provider:service:collection": object
// Transform to CollectionObject instances const collections: Record<string, CollectionObject> = {}
const transformed: Record<string, Record<string, Record<string, CollectionObject>>> = {} Object.entries(response).forEach(([_providerId, providerServices]) => {
Object.entries(providerServices).forEach(([_serviceId, serviceCollections]) => {
Object.entries(serviceCollections).forEach(([_collectionId, collectionObj]) => {
const key = identifierKey(collectionObj.provider, collectionObj.service, collectionObj.identifier)
collections[key] = collectionObj
})
})
})
for (const [providerId, providerData] of Object.entries(response)) { // Merge retrieved collections into state
transformed[providerId] = {} _collections.value = { ..._collections.value, ...collections }
for (const [serviceId, collections] of Object.entries(providerData as any)) { console.debug('[Mail Manager][Store] - Successfully retrieved', Object.keys(collections).length, 'collections')
transformed[providerId][serviceId] = {} return collections
// Collections come as an object keyed by identifier
for (const [collectionId, collection] of Object.entries(collections as any)) {
// Create CollectionObject instance with provider and service set
const collectionData = {
...collection,
provider: providerId,
service: serviceId,
} as CollectionInterface
transformed[providerId][serviceId][collectionId] = new CollectionObject().fromJson(collectionData)
}
}
}
this.collections = transformed
} catch (error: any) { } catch (error: any) {
this.error = error.message console.error('[Mail Manager][Store] - Failed to retrieve collections:', error)
throw error throw error
} finally { } finally {
this.loading = false transceiving.value = false
}
} }
},
async getCollection(provider: string, service: string | number, collectionId: string | number) { /**
this.loading = true * Retrieve a specific collection by provider, service, and identifier
this.error = null *
* @param provider - provider identifier
* @param service - service identifier
* @param identifier - collection identifier
*
* @returns Promise with collection object
*/
async function fetch(provider: string, service: string | number, identifier: string | number): Promise<CollectionObject> {
transceiving.value = true
try { try {
const response = await collectionService.fetch({ const response = await collectionService.fetch({ provider, service, collection: identifier })
// Merge fetched collection into state
const key = identifierKey(response.provider, response.service, response.identifier)
_collections.value[key] = response
console.debug('[Mail Manager][Store] - Successfully fetched collection:', key)
return response
} catch (error: any) {
console.error('[Mail Manager][Store] - Failed to fetch collection:', error)
throw error
} finally {
transceiving.value = false
}
}
/**
* Retrieve collection availability status for a given source selector
*
* @param sources - source selector to check availability for
*
* @returns Promise with collection availability status
*/
async function extant(sources: SourceSelector) {
transceiving.value = true
try {
const response = await collectionService.extant({ sources })
console.debug('[Mail Manager][Store] - Successfully checked', sources ? Object.keys(sources).length : 0, 'collections')
return response
} catch (error: any) {
console.error('[Mail Manager][Store] - Failed to check collections:', error)
throw error
} finally {
transceiving.value = false
}
}
/**
* Create a new collection with given provider, service, and data
*
* @param provider - provider identifier for the new collection
* @param service - service identifier for the new collection
* @param collection - optional parent collection identifier
* @param data - collection properties for creation
*
* @returns Promise with created collection object
*/
async function create(provider: string, service: string | number, collection: string | number | null, data: CollectionMutableProperties): Promise<CollectionObject> {
transceiving.value = true
try {
const response = await collectionService.create({
provider, provider,
service, service,
collection: collectionId collection,
properties: data
}) })
// Create CollectionObject instance // Merge created collection into state
const collectionObject = new CollectionObject().fromJson(response) const key = identifierKey(response.provider, response.service, response.identifier)
_collections.value[key] = response
// Update in store console.debug('[Mail Manager][Store] - Successfully created collection:', key)
if (!this.collections[provider]) { return response
this.collections[provider] = {}
}
if (!this.collections[provider][String(service)]) {
this.collections[provider][String(service)] = {}
}
this.collections[provider][String(service)][String(collectionId)] = collectionObject
return collectionObject
} catch (error: any) { } catch (error: any) {
this.error = error.message console.error('[Mail Manager][Store] - Failed to create collection:', error)
throw error throw error
} finally { } finally {
this.loading = false transceiving.value = false
}
} }
},
async createCollection(params: {
provider: string
service: string | number
collection?: string | number | null
properties: CollectionPropertiesObject
}): Promise<CollectionObject> {
this.loading = true
this.error = null
/**
* Update an existing collection with given provider, service, identifier, and data
*
* @param provider - provider identifier for the collection to update
* @param service - service identifier for the collection to update
* @param identifier - collection identifier for the collection to update
* @param data - collection properties for update
*
* @returns Promise with updated collection object
*/
async function update(provider: string, service: string | number, identifier: string | number, data: CollectionMutableProperties): Promise<CollectionObject> {
transceiving.value = true
try { try {
// Prepare request data from CollectionPropertiesObject const response = await collectionService.update({
const requestData: CollectionCreateRequest = { provider,
provider: params.provider, service,
service: params.service, identifier,
collection: params.collection ?? null, properties: data
properties: { })
'@type': 'mail.collection',
label: params.properties.label,
role: params.properties.role ?? null,
rank: params.properties.rank ?? 0,
subscribed: params.properties.subscribed ?? true,
},
}
// Call service to create collection // Merge updated collection into state
const response = await collectionService.create(requestData) const key = identifierKey(response.provider, response.service, response.identifier)
_collections.value[key] = response
// Create CollectionObject instance console.debug('[Mail Manager][Store] - Successfully updated collection:', key)
const collectionObject = new CollectionObject().fromJson(response) return response
// Update store with new collection
const provider = response.provider
const service = String(response.service)
const identifier = String(response.identifier)
if (!this.collections[provider]) {
this.collections[provider] = {}
}
if (!this.collections[provider][service]) {
this.collections[provider][service] = {}
}
this.collections[provider][service][identifier] = collectionObject
return collectionObject
} catch (error: any) { } catch (error: any) {
this.error = error.message console.error('[Mail Manager][Store] - Failed to update collection:', error)
throw error throw error
} finally { } finally {
this.loading = false transceiving.value = false
}
} }
},
},
getters: { /**
collectionList: (state) => { * Delete a collection by provider, service, and identifier
const list: CollectionObject[] = [] *
Object.values(state.collections).forEach(providerCollections => { * @param provider - provider identifier for the collection to delete
Object.values(providerCollections).forEach(serviceCollections => { * @param service - service identifier for the collection to delete
Object.values(serviceCollections).forEach(collection => { * @param identifier - collection identifier for the collection to delete
list.push(collection) *
}) * @returns Promise with deletion result
}) */
}) async function remove(provider: string, service: string | number, identifier: string | number): Promise<any> {
return list transceiving.value = true
}, try {
await collectionService.delete({ provider, service, identifier })
collectionCount: (state) => { // Remove deleted collection from state
let count = 0 const key = identifierKey(provider, service, identifier)
Object.values(state.collections).forEach(providerCollections => { delete _collections.value[key]
Object.values(providerCollections).forEach(serviceCollections => {
count += Object.keys(serviceCollections).length
})
})
return count
},
hasCollections: (state) => { console.debug('[Mail Manager][Store] - Successfully deleted collection:', key)
return Object.values(state.collections).some(providerCollections => } catch (error: any) {
Object.values(providerCollections).some(serviceCollections => console.error('[Mail Manager][Store] - Failed to delete collection:', error)
Object.keys(serviceCollections).length > 0 throw error
) } finally {
) transceiving.value = false
}, }
}, }
// Return public API
return {
// State (readonly)
transceiving: readonly(transceiving),
// Getters
count,
has,
collections,
collectionsByService,
collectionsForService,
collectionsInCollection,
// Actions
collection,
list,
fetch,
extant,
create,
update,
delete: remove,
}
}) })

View File

@@ -1,261 +1,369 @@
/**
* Entities Store
*/
import { ref, computed, readonly } from 'vue'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { entityService } from '../services' import { entityService } from '../services'
import type { MessageObject, EntityWrapper, MessageSendRequest } from '../types' import { EntityObject } from '../models'
import type { EntityTransmitRequest, EntityTransmitResponse } from '../types/entity'
import type { SourceSelector, ListFilter, ListSort, ListRange } from '../types/common'
export const useEntitiesStore = defineStore('mail-entities', { export const useEntitiesStore = defineStore('mailEntitiesStore', () => {
state: () => ({ // State
messages: {} as Record<string, Record<string, Record<string, Record<string, EntityWrapper<MessageObject>>>>>, const _entities = ref<Record<string, EntityObject>>({})
signatures: {} as Record<string, Record<string, Record<string, string>>>, // Track delta signatures const transceiving = ref(false)
loading: false,
error: null as string | null,
}),
actions: { /**
async loadMessages(sources?: any, filter?: any, sort?: any, range?: any) { * Get count of entities in store
this.loading = true */
this.error = null const count = computed(() => Object.keys(_entities.value).length)
/**
* Check if any entities are present in store
*/
const has = computed(() => count.value > 0)
/**
* Get all entities present in store
*/
const entities = computed(() => Object.values(_entities.value))
/**
* Get a specific entity from store, with optional retrieval
*
* @param provider - provider identifier
* @param service - service identifier
* @param collection - collection identifier
* @param identifier - entity identifier
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
*
* @returns Entity object or null
*/
function entity(provider: string, service: string | number, collection: string | number, identifier: string | number, retrieve: boolean = false): EntityObject | null {
const key = identifierKey(provider, service, collection, identifier)
if (retrieve === true && !_entities.value[key]) {
console.debug(`[Mail Manager][Store] - Force fetching entity "${key}"`)
fetch(provider, service, collection, [identifier])
}
return _entities.value[key] || null
}
/**
* Get all entities for a specific collection
*
* @param provider - provider identifier
* @param service - service identifier
* @param collection - collection identifier
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
*
* @returns Array of entity objects
*/
function entitiesForCollection(provider: string, service: string | number, collection: string | number, retrieve: boolean = false): EntityObject[] {
const collectionKeyPrefix = `${provider}:${service}:${collection}:`
const collectionEntities = Object.entries(_entities.value)
.filter(([key]) => key.startsWith(collectionKeyPrefix))
.map(([_, entity]) => entity)
if (retrieve === true && collectionEntities.length === 0) {
console.debug(`[Mail Manager][Store] - Force fetching entities for collection "${provider}:${service}:${collection}"`)
const sources: SourceSelector = {
[provider]: {
[String(service)]: {
[String(collection)]: true
}
}
}
list(sources)
}
return collectionEntities
}
/**
* Create unique key for an entity
*/
function identifierKey(provider: string, service: string | number, collection: string | number, identifier: string | number): string {
return `${provider}:${service}:${collection}:${identifier}`
}
// Actions
/**
* Retrieve all or specific entities, optionally filtered by source selector
*
* @param sources - optional source selector
* @param filter - optional list filter
* @param sort - optional list sort
* @param range - optional list range
*
* @returns Promise with entity object list keyed by identifier
*/
async function list(sources?: SourceSelector, filter?: ListFilter, sort?: ListSort, range?: ListRange): Promise<Record<string, EntityObject>> {
transceiving.value = true
try { try {
const response = await entityService.list({ sources, filter, sort, range }) const response = await entityService.list({ sources, filter, sort, range })
// Entities come as objects keyed by identifier // Flatten nested structure: provider:service:collection:entity -> "provider:service:collection:entity": object
Object.entries(response).forEach(([provider, providerData]) => { const entities: Record<string, EntityObject> = {}
Object.entries(providerData).forEach(([service, serviceData]) => { Object.entries(response).forEach(([providerId, providerServices]) => {
Object.entries(serviceData).forEach(([collection, entities]) => { Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
if (!this.messages[provider]) { Object.entries(serviceCollections).forEach(([collectionId, collectionEntities]) => {
this.messages[provider] = {} Object.entries(collectionEntities).forEach(([entityId, entityData]) => {
} const key = identifierKey(providerId, serviceId, collectionId, entityId)
if (!this.messages[provider][service]) { entities[key] = entityData
this.messages[provider][service] = {} })
} })
if (!this.messages[provider][service][collection]) { })
this.messages[provider][service][collection] = {} })
}
// Entities are already keyed by identifier // Merge retrieved entities into state
this.messages[provider][service][collection] = entities as Record<string, EntityWrapper<MessageObject>> _entities.value = { ..._entities.value, ...entities }
})
}) console.debug('[Mail Manager][Store] - Successfully retrieved', Object.keys(entities).length, 'entities')
}) return entities
} catch (error: any) { } catch (error: any) {
this.error = error.message console.error('[Mail Manager][Store] - Failed to retrieve entities:', error)
throw error throw error
} finally { } finally {
this.loading = false transceiving.value = false
}
} }
},
async getMessages( /**
provider: string, * Retrieve specific entities by provider, service, collection, and identifiers
service: string | number, *
collection: string | number, * @param provider - provider identifier
identifiers: (string | number)[], * @param service - service identifier
properties?: string[] * @param collection - collection identifier
) { * @param identifiers - array of entity identifiers to fetch
this.loading = true *
this.error = null * @returns Promise with entity objects keyed by identifier
*/
async function fetch(provider: string, service: string | number, collection: string | number, identifiers: (string | number)[]): Promise<Record<string, EntityObject>> {
transceiving.value = true
try { try {
const response = await entityService.fetch({ const response = await entityService.fetch({ provider, service, collection, identifiers })
provider,
service, // Merge fetched entities into state
collection, const entities: Record<string, EntityObject> = {}
identifiers, Object.entries(response).forEach(([identifier, entityData]) => {
properties const key = identifierKey(provider, service, collection, identifier)
entities[key] = entityData
_entities.value[key] = entityData
}) })
// Update in store console.debug('[Mail Manager][Store] - Successfully fetched', Object.keys(entities).length, 'entities')
if (!this.messages[provider]) { return entities
this.messages[provider] = {} } catch (error: any) {
console.error('[Mail Manager][Store] - Failed to fetch entities:', error)
throw error
} finally {
transceiving.value = false
} }
if (!this.messages[provider][String(service)]) {
this.messages[provider][String(service)] = {}
}
if (!this.messages[provider][String(service)][String(collection)]) {
this.messages[provider][String(service)][String(collection)] = {}
} }
// Index fetched entities by identifier /**
response.entities.forEach((entity: EntityWrapper<MessageObject>) => { * Retrieve entity availability status for a given source selector
this.messages[provider][String(service)][String(collection)][entity.identifier] = entity *
}) * @param sources - source selector to check availability for
*
* @returns Promise with entity availability status
*/
async function extant(sources: SourceSelector) {
transceiving.value = true
try {
const response = await entityService.extant({ sources })
console.debug('[Mail Manager][Store] - Successfully checked entity availability')
return response return response
} catch (error: any) { } catch (error: any) {
this.error = error.message console.error('[Mail Manager][Store] - Failed to check entity availability:', error)
throw error throw error
} finally { } finally {
this.loading = false transceiving.value = false
}
} }
},
async searchMessages( /**
provider: string, * Create a new entity with given provider, service, collection, and data
service: string | number, *
query: string, * @param provider - provider identifier for the new entity
collections?: (string | number)[], * @param service - service identifier for the new entity
filter?: any, * @param collection - collection identifier for the new entity
sort?: any, * @param data - entity properties for creation
range?: any *
) { * @returns Promise with created entity object
this.loading = true */
this.error = null async function create(provider: string, service: string | number, collection: string | number, data: any): Promise<EntityObject> {
transceiving.value = true
try { try {
const response = await entityService.search({ const response = await entityService.create({ provider, service, collection, properties: data })
provider,
service, // Add created entity to state
query, const key = identifierKey(response.provider, response.service, response.collection, response.identifier)
collections, _entities.value[key] = response
filter,
sort, console.debug('[Mail Manager][Store] - Successfully created entity:', key)
range
})
return response return response
} catch (error: any) { } catch (error: any) {
this.error = error.message console.error('[Mail Manager][Store] - Failed to create entity:', error)
throw error throw error
} finally { } finally {
this.loading = false transceiving.value = false
}
} }
},
async sendMessage(request: MessageSendRequest) { /**
this.loading = true * Update an existing entity with given provider, service, collection, identifier, and data
this.error = null *
* @param provider - provider identifier for the entity to update
* @param service - service identifier for the entity to update
* @param collection - collection identifier for the entity to update
* @param identifier - entity identifier for the entity to update
* @param data - entity properties for update
*
* @returns Promise with updated entity object
*/
async function update(provider: string, service: string | number, collection: string | number, identifier: string | number, data: any): Promise<EntityObject> {
transceiving.value = true
try { try {
const response = await entityService.send(request) const response = await entityService.update({ provider, service, collection, identifier, properties: data })
// Update entity in state
const key = identifierKey(response.provider, response.service, response.collection, response.identifier)
_entities.value[key] = response
console.debug('[Mail Manager][Store] - Successfully updated entity:', key)
return response return response
} catch (error: any) { } catch (error: any) {
this.error = error.message console.error('[Mail Manager][Store] - Failed to update entity:', error)
throw error throw error
} finally { } finally {
this.loading = false transceiving.value = false
}
} }
},
async getDelta(sources: any) { /**
this.loading = true * Delete an entity by provider, service, collection, and identifier
this.error = null *
* @param provider - provider identifier for the entity to delete
* @param service - service identifier for the entity to delete
* @param collection - collection identifier for the entity to delete
* @param identifier - entity identifier for the entity to delete
*
* @returns Promise with deletion result
*/
async function remove(provider: string, service: string | number, collection: string | number, identifier: string | number): Promise<any> {
transceiving.value = true
try {
const response = await entityService.delete({ provider, service, collection, identifier })
// Remove entity from state
const key = identifierKey(provider, service, collection, identifier)
delete _entities.value[key]
console.debug('[Mail Manager][Store] - Successfully deleted entity:', key)
return response
} catch (error: any) {
console.error('[Mail Manager][Store] - Failed to delete entity:', error)
throw error
} finally {
transceiving.value = false
}
}
/**
* Retrieve delta changes for entities
*
* @param sources - source selector for delta check
*
* @returns Promise with delta changes (additions, modifications, deletions)
*
* Note: Delta returns only identifiers, not full entities.
* Caller should fetch full entities for additions/modifications separately.
*/
async function delta(sources: SourceSelector) {
transceiving.value = true
try { try {
// Sources are already in correct format: { provider: { service: { collection: signature } } }
const response = await entityService.delta({ sources }) const response = await entityService.delta({ sources })
// Process delta and update store // Process delta and update store
Object.entries(response).forEach(([provider, providerData]) => { Object.entries(response).forEach(([provider, providerData]) => {
// Skip if no changes for provider
if (providerData === false) return
Object.entries(providerData).forEach(([service, serviceData]) => { Object.entries(providerData).forEach(([service, serviceData]) => {
// Skip if no changes for service
if (serviceData === false) return
Object.entries(serviceData).forEach(([collection, collectionData]) => { Object.entries(serviceData).forEach(([collection, collectionData]) => {
// Skip if no changes (server returns false or string signature) // Skip if no changes for collection
if (collectionData === false || typeof collectionData === 'string') { if (collectionData === false) return
return
}
if (!this.messages[provider]) { // Process deletions (remove from store)
this.messages[provider] = {} if (collectionData.deletions && collectionData.deletions.length > 0) {
} collectionData.deletions.forEach((identifier) => {
if (!this.messages[provider][service]) { const key = identifierKey(provider, service, collection, identifier)
this.messages[provider][service] = {} delete _entities.value[key]
}
if (!this.messages[provider][service][collection]) {
this.messages[provider][service][collection] = {}
}
const collectionMessages = this.messages[provider][service][collection]
// Update signature if provided
if (typeof collectionData === 'object' && collectionData.signature) {
if (!this.signatures[provider]) {
this.signatures[provider] = {}
}
if (!this.signatures[provider][service]) {
this.signatures[provider][service] = {}
}
this.signatures[provider][service][collection] = collectionData.signature
console.log(`[Store] Updated signature for ${provider}/${service}/${collection}: "${collectionData.signature}"`)
}
// Process additions (from delta response format)
if (collectionData.additions) {
// Note: additions are just identifiers, need to fetch full entities separately
// This is handled by the sync composable
}
// Process modifications
if (collectionData.modifications) {
// Note: modifications are just identifiers, need to fetch full entities separately
}
// Remove deleted messages
if (collectionData.deletions) {
collectionData.deletions.forEach((id: string | number) => {
delete collectionMessages[String(id)]
}) })
} }
// Legacy support: Also handle created/modified/deleted format // Note: additions and modifications contain only identifiers
if (collectionData.created) { // The caller should fetch full entities using the fetch() method
collectionData.created.forEach((entity: EntityWrapper<MessageObject>) => {
collectionMessages[entity.identifier] = entity
})
}
if (collectionData.modified) {
collectionData.modified.forEach((entity: EntityWrapper<MessageObject>) => {
collectionMessages[entity.identifier] = entity
})
}
if (collectionData.deleted) {
collectionData.deleted.forEach((id: string | number) => {
delete collectionMessages[String(id)]
})
}
}) })
}) })
}) })
console.debug('[Mail Manager][Store] - Successfully processed delta changes')
return response return response
} catch (error: any) { } catch (error: any) {
this.error = error.message console.error('[Mail Manager][Store] - Failed to process delta:', error)
throw error throw error
} finally { } finally {
this.loading = false transceiving.value = false
}
} }
},
},
getters: { /**
messageList: (state) => { * Send/transmit an entity
const list: EntityWrapper<MessageObject>[] = [] *
Object.values(state.messages).forEach(providerMessages => { * @param request - transmit request parameters
Object.values(providerMessages).forEach(serviceMessages => { *
Object.values(serviceMessages).forEach(collectionMessages => { * @returns Promise with transmission result
Object.values(collectionMessages).forEach(message => { */
list.push(message) async function transmit(request: EntityTransmitRequest): Promise<EntityTransmitResponse> {
}) transceiving.value = true
}) try {
}) const response = await entityService.transmit(request)
}) console.debug('[Mail Manager][Store] - Successfully transmitted entity')
return list return response
}, } catch (error: any) {
console.error('[Mail Manager][Store] - Failed to transmit entity:', error)
throw error
} finally {
transceiving.value = false
}
}
messageCount: (state) => { // Return public API
let count = 0 return {
Object.values(state.messages).forEach(providerMessages => { // State (readonly)
Object.values(providerMessages).forEach(serviceMessages => { transceiving: readonly(transceiving),
Object.values(serviceMessages).forEach(collectionMessages => { // Getters
count += Object.keys(collectionMessages).length count,
}) has,
}) entities,
}) entitiesForCollection,
return count // Actions
}, entity,
list,
hasMessages: (state) => { fetch,
return Object.values(state.messages).some(providerMessages => extant,
Object.values(providerMessages).some(serviceMessages => create,
Object.values(serviceMessages).some(collectionMessages => update,
Object.keys(collectionMessages).length > 0 delete: remove,
) delta,
) transmit,
) }
},
},
}) })

View File

@@ -12,59 +12,60 @@ export const useProvidersStore = defineStore('mailProvidersStore', () => {
// State // State
const _providers = ref<Record<string, ProviderObject>>({}) const _providers = ref<Record<string, ProviderObject>>({})
const transceiving = ref(false) const transceiving = ref(false)
const error = ref<string | null>(null)
// Getters /**
* Get count of providers in store
*/
const count = computed(() => Object.keys(_providers.value).length) const count = computed(() => Object.keys(_providers.value).length)
/**
* Check if any providers are present in store
*/
const has = computed(() => count.value > 0) const has = computed(() => count.value > 0)
/** /**
* Get providers as an array * Get all providers present in store
* @returns Array of provider objects
*/ */
const providers = computed(() => Object.values(_providers.value)) const providers = computed(() => Object.values(_providers.value))
/** /**
* Get a specific provider by identifier from cache * Get a specific provider from store, with optional retrieval
*
* @param identifier - Provider identifier * @param identifier - Provider identifier
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
*
* @returns Provider object or null * @returns Provider object or null
*/ */
function provider(identifier: string): ProviderObject | null { function provider(identifier: string, retrieve: boolean = false): ProviderObject | null {
if (retrieve === true && !_providers.value[identifier]) {
console.debug(`[Mail Manager][Store] - Force fetching provider "${identifier}"`)
fetch(identifier)
}
return _providers.value[identifier] || null return _providers.value[identifier] || null
} }
// Actions // Actions
/** /**
* Retrieve all or specific providers * Retrieve all or specific providers, optionally filtered by source selector
*
* @param request - list request parameters
*
* @returns Promise with provider object list keyed by provider identifier
*/ */
async function list(sources?: SourceSelector): Promise<Record<string, ProviderObject>> { async function list(sources?: SourceSelector): Promise<Record<string, ProviderObject>> {
transceiving.value = true transceiving.value = true
error.value = null
try { try {
const response = await providerService.list({ sources }) const providers = await providerService.list({ sources })
console.debug('[Mail Manager](Store) - Successfully retrieved', Object.keys(response).length, 'providers') // Merge retrieved providers into state
_providers.value = { ..._providers.value, ...providers }
_providers.value = response console.debug('[Mail Manager][Store] - Successfully retrieved', Object.keys(providers).length, 'providers')
return response return providers
} catch (err: any) {
console.error('[Mail Manager](Store) - Failed to retrieve providers:', err)
error.value = err.message
throw err
} finally {
transceiving.value = false
}
}
/**
* Fetch a specific provider
*/
async function fetch(identifier: string): Promise<ProviderObject> {
transceiving.value = true
try {
return await providerService.fetch({ identifier })
} catch (error: any) { } catch (error: any) {
console.error('[Mail Manager](Store) - Failed to fetch provider:', error) console.error('[Mail Manager][Store] - Failed to retrieve providers:', error)
throw error throw error
} finally { } finally {
transceiving.value = false transceiving.value = false
@@ -72,19 +73,53 @@ export const useProvidersStore = defineStore('mailProvidersStore', () => {
} }
/** /**
* Check which providers exist/are available * Retrieve a specific provider by identifier
*
* @param identifier - provider identifier
*
* @returns Promise with provider object
*/
async function fetch(identifier: string): Promise<ProviderObject> {
transceiving.value = true
try {
const provider = await providerService.fetch({ identifier })
// Merge fetched provider into state
_providers.value[provider.identifier] = provider
console.debug('[Mail Manager][Store] - Successfully fetched provider:', provider.identifier)
return provider
} catch (error: any) {
console.error('[Mail Manager][Store] - Failed to fetch provider:', error)
throw error
} finally {
transceiving.value = false
}
}
/**
* Retrieve provider availability status for a given source selector
*
* @param sources - source selector to check availability for
*
* @returns Promise with provider availability status
*/ */
async function extant(sources: SourceSelector) { async function extant(sources: SourceSelector) {
transceiving.value = true transceiving.value = true
error.value = null
try { try {
const response = await providerService.extant({ sources }) const response = await providerService.extant({ sources })
console.debug('[Mail Manager](Store) - Successfully checked', sources ? Object.keys(sources).length : 0, 'providers')
Object.entries(response).forEach(([providerId, providerStatus]) => {
if (providerStatus === false) {
delete _providers.value[providerId]
}
})
console.debug('[Mail Manager][Store] - Successfully checked', sources ? Object.keys(sources).length : 0, 'providers')
return response return response
} catch (err: any) { } catch (error: any) {
console.error('[Mail Manager](Store) - Failed to check providers:', err) console.error('[Mail Manager][Store] - Failed to check providers:', error)
error.value = err.message throw error
throw err
} finally { } finally {
transceiving.value = false transceiving.value = false
} }
@@ -94,7 +129,6 @@ export const useProvidersStore = defineStore('mailProvidersStore', () => {
return { return {
// State // State
transceiving: readonly(transceiving), transceiving: readonly(transceiving),
error: readonly(error),
// computed // computed
count, count,
has, has,

View File

@@ -10,27 +10,31 @@ import type {
ServiceLocation, ServiceLocation,
SourceSelector, SourceSelector,
ServiceIdentity, ServiceIdentity,
ServiceInterface,
} from '../types' } from '../types'
export const useServicesStore = defineStore('mailServicesStore', () => { export const useServicesStore = defineStore('mailServicesStore', () => {
// State // State
const _services = ref<Record<string, ServiceObject>>({}) const _services = ref<Record<string, ServiceObject>>({})
const transceiving = ref(false) const transceiving = ref(false)
const lastTestResult = ref<any>(null)
// Getters /**
* Get count of services in store
*/
const count = computed(() => Object.keys(_services.value).length) const count = computed(() => Object.keys(_services.value).length)
/**
* Check if any services are present in store
*/
const has = computed(() => count.value > 0) const has = computed(() => count.value > 0)
/** /**
* Get services as an array * Get all services present in store
* @returns Array of service objects
*/ */
const services = computed(() => Object.values(_services.value)) const services = computed(() => Object.values(_services.value))
/** /**
* Get services grouped by provider * Get all services present in store grouped by provider
* @returns Services grouped by provider ID
*/ */
const servicesByProvider = computed(() => { const servicesByProvider = computed(() => {
const groups: Record<string, ServiceObject[]> = {} const groups: Record<string, ServiceObject[]> = {}
@@ -45,9 +49,60 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
return groups return groups
}) })
// Actions
/** /**
* Retrieve for all or specific services * Get a specific service from store, with optional retrieval
*
* @param provider - provider identifier
* @param identifier - service identifier
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
*
* @returns Service object or null
*/
function service(provider: string, identifier: string | number, retrieve: boolean = false): ServiceObject | null {
const key = identifierKey(provider, identifier)
if (retrieve === true && !_services.value[key]) {
console.debug(`[Mail Manager][Store] - Force fetching service "${key}"`)
fetch(provider, identifier)
}
return _services.value[key] || null
}
/**
* Get a service from store matching a given address, with optional retrieval
*
* @param address - email address to match against primary and secondary addresses
* @param retrieve - Retrieve behavior: true = fetch if missing, false = cache only
*
* @returns Service object or null
*/
function serviceForAddress(address: string, retrieve: boolean = false): ServiceObject | null {
const service = Object.values(_services.value).find(s => s.primaryAddress === address || s.secondaryAddresses?.includes(address))
if (retrieve === true && !service) {
console.debug(`[Mail Manager][Store] - No service found for address "${address}", discovery may be needed`)
// TODO: Implement retrieving service by address
}
return service || null
}
/**
* Unique key for a service
*/
function identifierKey(provider: string, identifier: string | number | null): string {
return `${provider}:${identifier ?? ''}`
}
// Actions
/**
* Retrieve all or specific services, optionally filtered by source selector
*
* @param sources - optional source selector
*
* @returns Promise with service object list keyed by provider and service identifier
*/ */
async function list(sources?: SourceSelector): Promise<Record<string, ServiceObject>> { async function list(sources?: SourceSelector): Promise<Record<string, ServiceObject>> {
transceiving.value = true transceiving.value = true
@@ -55,20 +110,21 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
const response = await serviceService.list({ sources }) const response = await serviceService.list({ sources })
// Flatten nested structure: provider-id: { service-id: object } -> "provider-id:service-id": object // Flatten nested structure: provider-id: { service-id: object } -> "provider-id:service-id": object
const flattened: Record<string, ServiceObject> = {} const services: Record<string, ServiceObject> = {}
Object.entries(response).forEach(([_providerId, providerServices]) => { Object.entries(response).forEach(([_providerId, providerServices]) => {
Object.entries(providerServices).forEach(([_serviceId, serviceObj]) => { Object.entries(providerServices).forEach(([_serviceId, serviceObj]) => {
const key = `${serviceObj.provider}:${serviceObj.identifier}` const key = identifierKey(serviceObj.provider, serviceObj.identifier)
flattened[key] = serviceObj services[key] = serviceObj
}) })
}) })
console.debug('[Mail Manager](Store) - Successfully retrieved', Object.keys(flattened).length, 'services') // Merge retrieved services into state
_services.value = { ..._services.value, ...services }
_services.value = flattened console.debug('[Mail Manager][Store] - Successfully retrieved', Object.keys(services).length, 'services')
return flattened return services
} catch (error: any) { } catch (error: any) {
console.error('[Mail Manager](Store) - Failed to retrieve services:', error) console.error('[Mail Manager][Store] - Failed to retrieve services:', error)
throw error throw error
} finally { } finally {
transceiving.value = false transceiving.value = false
@@ -76,14 +132,26 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
} }
/** /**
* Fetch a specific service * Retrieve a specific service by provider and identifier
*
* @param provider - provider identifier
* @param identifier - service identifier
*
* @returns Promise with service object
*/ */
async function fetch(provider: string, identifier: string | number): Promise<ServiceObject> { async function fetch(provider: string, identifier: string | number): Promise<ServiceObject> {
transceiving.value = true transceiving.value = true
try { try {
return await serviceService.fetch({ provider, identifier }) const service = await serviceService.fetch({ provider, identifier })
// Merge fetched service into state
const key = identifierKey(service.provider, service.identifier)
_services.value[key] = service
console.debug('[Mail Manager][Store] - Successfully fetched service:', key)
return service
} catch (error: any) { } catch (error: any) {
console.error('[Mail Manager](Store) - Failed to fetch service:', error) console.error('[Mail Manager][Store] - Failed to fetch service:', error)
throw error throw error
} finally { } finally {
transceiving.value = false transceiving.value = false
@@ -91,9 +159,117 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
} }
/** /**
* Discover service configuration * Retrieve service availability status for a given source selector
* *
* @returns Array of discovered services sorted by provider * @param sources - source selector to check availability for
*
* @returns Promise with service availability status
*/
async function extant(sources: SourceSelector) {
transceiving.value = true
try {
const response = await serviceService.extant({ sources })
console.debug('[Mail Manager][Store] - Successfully checked', sources ? Object.keys(sources).length : 0, 'services')
return response
} catch (error: any) {
console.error('[Mail Manager][Store] - Failed to check services:', error)
throw error
} finally {
transceiving.value = false
}
}
/**
* Create a new service with given provider and data
*
* @param provider - provider identifier for the new service
* @param data - partial service data for creation
*
* @returns Promise with created service object
*/
async function create(provider: string, data: Partial<ServiceInterface>): Promise<ServiceObject> {
transceiving.value = true
try {
const service = await serviceService.create({ provider, data })
// Merge created service into state
const key = identifierKey(service.provider, service.identifier)
_services.value[key] = service
console.debug('[Mail Manager][Store] - Successfully created service:', key)
return service
} catch (error: any) {
console.error('[Mail Manager][Store] - Failed to create service:', error)
throw error
} finally {
transceiving.value = false
}
}
/**
* Update an existing service with given provider, identifier, and data
*
* @param provider - provider identifier for the service to update
* @param identifier - service identifier for the service to update
* @param data - partial service data for update
*
* @returns Promise with updated service object
*/
async function update(provider: string, identifier: string | number, data: Partial<ServiceInterface>): Promise<ServiceObject> {
transceiving.value = true
try {
const service = await serviceService.update({ provider, identifier, data })
// Merge updated service into state
const key = identifierKey(service.provider, service.identifier)
_services.value[key] = service
console.debug('[Mail Manager][Store] - Successfully updated service:', key)
return service
} catch (error: any) {
console.error('[Mail Manager][Store] - Failed to update service:', error)
throw error
} finally {
transceiving.value = false
}
}
/**
* Delete a service by provider and identifier
*
* @param provider - provider identifier for the service to delete
* @param identifier - service identifier for the service to delete
*
* @returns Promise with deletion result
*/
async function remove(provider: string, identifier: string | number): Promise<any> {
transceiving.value = true
try {
await serviceService.delete({ provider, identifier })
// Remove deleted service from state
const key = identifierKey(provider, identifier)
delete _services.value[key]
console.debug('[Mail Manager][Store] - Successfully deleted service:', key)
} catch (error: any) {
console.error('[Mail Manager][Store] - Failed to delete service:', error)
throw error
} finally {
transceiving.value = false
}
}
/**
* Discover services based on provided parameters
*
* @param identity - optional service identity for discovery
* @param secret - optional secret for discovery
* @param location - optional location for discovery
* @param provider - optional provider identifier for discovery
*
* @returns Promise with list of discovered service objects
*/ */
async function discover( async function discover(
identity: string, identity: string,
@@ -105,16 +281,27 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
try { try {
const services = await serviceService.discover({identity, secret, location, provider}) const services = await serviceService.discover({identity, secret, location, provider})
console.debug('[Mail Manager](Store) - Successfully discovered', services.length, 'services')
console.debug('[Mail Manager][Store] - Successfully discovered', services.length, 'services')
return services return services
} catch (error: any) { } catch (error: any) {
console.error('[Mail Manager](Store) - Failed to discover service:', error) console.error('[Mail Manager][Store] - Failed to discover service:', error)
throw error throw error
} finally { } finally {
transceiving.value = false transceiving.value = false
} }
} }
/**
* Test service connectivity and configuration
*
* @param provider - provider identifier for the service to test
* @param identifier - optional service identifier for testing existing service
* @param location - optional service location for testing new configuration
* @param identity - optional service identity for testing new configuration
*
* @return Promise with test results
*/
async function test( async function test(
provider: string, provider: string,
identifier?: string | number | null, identifier?: string | number | null,
@@ -124,62 +311,11 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
transceiving.value = true transceiving.value = true
try { try {
const response = await serviceService.test({ provider, identifier, location, identity }) const response = await serviceService.test({ provider, identifier, location, identity })
lastTestResult.value = response
console.debug('[Mail Manager][Store] - Successfully tested service:', provider, identifier || location)
return response return response
} catch (error: any) { } catch (error: any) {
console.error('[Mail Manager](Store) - Failed to test service:', error) console.error('[Mail Manager][Store] - Failed to test service:', error)
throw error
} finally {
transceiving.value = false
}
}
async function create(provider: string, data: any) {
transceiving.value = true
try {
const serviceObj = await serviceService.create({ provider, data })
// Add to store with composite key
const key = `${serviceObj.provider}:${serviceObj.identifier}`
_services.value[key] = serviceObj
return serviceObj
} catch (error: any) {
console.error('[Mail Manager](Store) - Failed to create service:', error)
throw error
} finally {
transceiving.value = false
}
}
async function update(provider: string, identifier: string | number, data: any) {
transceiving.value = true
try {
const serviceObj = await serviceService.update({ provider, identifier, data })
// Update in store with composite key
const key = `${serviceObj.provider}:${serviceObj.identifier}`
_services.value[key] = serviceObj
return serviceObj
} catch (error: any) {
console.error('[Mail Manager](Store) - Failed to update service:', error)
throw error
} finally {
transceiving.value = false
}
}
async function remove(provider: string, identifier: string | number) {
transceiving.value = true
try {
await serviceService.delete({ provider, identifier })
// Remove from store using composite key
const key = `${provider}:${identifier}`
delete _services.value[key]
} catch (error: any) {
console.error('[Mail Manager](Store) - Failed to delete service:', error)
throw error throw error
} finally { } finally {
transceiving.value = false transceiving.value = false
@@ -190,7 +326,6 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
return { return {
// State (readonly) // State (readonly)
transceiving: readonly(transceiving), transceiving: readonly(transceiving),
lastTestResult: readonly(lastTestResult),
// Getters // Getters
count, count,
has, has,
@@ -198,12 +333,15 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
servicesByProvider, servicesByProvider,
// Actions // Actions
service,
serviceForAddress,
list, list,
fetch, fetch,
discover, extant,
test,
create, create,
update, update,
delete: remove, delete: remove,
discover,
test,
} }
}) })

View File

@@ -1,10 +1,10 @@
/** /**
* Collection-related type definitions for Mail Manager * Collection type definitions
*/ */
import type { SourceSelector } from './common'; import type { ListFilter, ListSort, SourceSelector } from './common';
/** /**
* Collection interface (mailbox/folder) * Collection information
*/ */
export interface CollectionInterface { export interface CollectionInterface {
provider: string; provider: string;
@@ -22,41 +22,29 @@ export interface CollectionBaseProperties {
version: number; version: number;
} }
/**
* Immutable collection properties (computed by server)
*/
export interface CollectionImmutableProperties extends CollectionBaseProperties { export interface CollectionImmutableProperties extends CollectionBaseProperties {
total?: number; total?: number;
unread?: number; unread?: number;
role?: string | null; role?: string | null;
} }
/**
* Mutable collection properties (can be modified by user)
*/
export interface CollectionMutableProperties extends CollectionBaseProperties { export interface CollectionMutableProperties extends CollectionBaseProperties {
label: string; label: string;
rank?: number; rank?: number;
subscribed?: boolean; subscribed?: boolean;
} }
/**
* Full collection properties (what server returns)
*/
export interface CollectionPropertiesInterface extends CollectionMutableProperties, CollectionImmutableProperties {} export interface CollectionPropertiesInterface extends CollectionMutableProperties, CollectionImmutableProperties {}
/** /**
* Collection list request * Collection list
*/ */
export interface CollectionListRequest { export interface CollectionListRequest {
sources?: SourceSelector; sources?: SourceSelector;
filter?: any; filter?: ListFilter;
sort?: any; sort?: ListSort;
} }
/**
* Collection list response
*/
export interface CollectionListResponse { export interface CollectionListResponse {
[providerId: string]: { [providerId: string]: {
[serviceId: string]: { [serviceId: string]: {
@@ -66,15 +54,23 @@ export interface CollectionListResponse {
} }
/** /**
* Collection extant request * Collection fetch
*/
export interface CollectionFetchRequest {
provider: string;
service: string | number;
collection: string | number;
}
export interface CollectionFetchResponse extends CollectionInterface {}
/**
* Collection extant
*/ */
export interface CollectionExtantRequest { export interface CollectionExtantRequest {
sources: SourceSelector; sources: SourceSelector;
} }
/**
* Collection extant response
*/
export interface CollectionExtantResponse { export interface CollectionExtantResponse {
[providerId: string]: { [providerId: string]: {
[serviceId: string]: { [serviceId: string]: {
@@ -84,21 +80,7 @@ export interface CollectionExtantResponse {
} }
/** /**
* Collection fetch request * Collection create
*/
export interface CollectionFetchRequest {
provider: string;
service: string | number;
collection: string | number;
}
/**
* Collection fetch response
*/
export interface CollectionFetchResponse extends CollectionInterface {}
/**
* Collection create request
*/ */
export interface CollectionCreateRequest { export interface CollectionCreateRequest {
provider: string; provider: string;
@@ -107,42 +89,33 @@ export interface CollectionCreateRequest {
properties: CollectionMutableProperties; properties: CollectionMutableProperties;
} }
/**
* Collection create response
*/
export interface CollectionCreateResponse extends CollectionInterface {} export interface CollectionCreateResponse extends CollectionInterface {}
/** /**
* Collection modify request * Collection modify
*/ */
export interface CollectionModifyRequest { export interface CollectionUpdateRequest {
provider: string; provider: string;
service: string | number; service: string | number;
identifier: string | number; identifier: string | number;
properties: CollectionMutableProperties; properties: CollectionMutableProperties;
} }
/** export interface CollectionUpdateResponse extends CollectionInterface {}
* Collection modify response
*/
export interface CollectionModifyResponse extends CollectionInterface {}
/** /**
* Collection destroy request * Collection delete
*/ */
export interface CollectionDestroyRequest { export interface CollectionDeleteRequest {
provider: string; provider: string;
service: string | number; service: string | number;
identifier: string | number; identifier: string | number;
options?: { options?: {
force?: boolean; // Whether to force destroy even if collection is not empty force?: boolean; // Whether to force delete even if collection is not empty
recursive?: boolean; // Whether to destroy child collections/items as well recursive?: boolean; // Whether to delete child collections/items as well
}; };
} }
/** export interface CollectionDeleteResponse {
* Collection destroy response
*/
export interface CollectionDestroyResponse {
success: boolean; success: boolean;
} }

View File

@@ -1,5 +1,5 @@
/** /**
* Common types shared across Mail Manager services * Common types shared across provider, service, collection, and entity request and responses.
*/ */
/** /**
@@ -44,8 +44,19 @@ export interface ApiErrorResponse {
export type ApiResponse<T = any> = ApiSuccessResponse<T> | ApiErrorResponse; export type ApiResponse<T = any> = ApiSuccessResponse<T> | ApiErrorResponse;
/** /**
* Source selector structure for hierarchical resource selection * Selector for targeting specific providers, services, collections, or entities in list or extant operations.
* Structure: Provider -> Service -> Collection -> Message *
* Example usage:
* {
* "provider1": true, // Select all services/collections/entities under provider1
* "provider2": {
* "serviceA": true, // Select all collections/entities under serviceA of provider2
* "serviceB": {
* "collectionX": true, // Select all entities under collectionX of serviceB of provider2
* "collectionY": [1, 2, 3] // Select entities with identifiers 1, 2, and 3 under collectionY of serviceB of provider2
* }
* }
* }
*/ */
export type SourceSelector = { export type SourceSelector = {
[provider: string]: boolean | ServiceSelector; [provider: string]: boolean | ServiceSelector;
@@ -56,38 +67,90 @@ export type ServiceSelector = {
}; };
export type CollectionSelector = { export type CollectionSelector = {
[collection: string | number]: boolean | MessageSelector; [collection: string | number]: boolean | EntitySelector;
}; };
export type MessageSelector = (string | number)[]; export type EntitySelector = (string | number)[];
/** /**
* Filter condition for building complex queries * Filter comparison for list operations
*/ */
export interface FilterCondition { export const ListFilterComparisonOperator = {
field: string; EQ: 1, // Equal
operator: string; NEQ: 2, // Not Equal
value: any; GT: 4, // Greater Than
} LT: 8, // Less Than
GTE: 16, // Greater Than or Equal
LTE: 32, // Less Than or Equal
IN: 64, // In Array
NIN: 128, // Not In Array
LIKE: 256, // Like
NLIKE: 512, // Not Like
} as const;
export type ListFilterComparisonOperator = typeof ListFilterComparisonOperator[keyof typeof ListFilterComparisonOperator];
/** /**
* Filter criteria for list operations * Filter conjunction for list operations
*/
export const ListFilterConjunctionOperator = {
NONE: '',
AND: 'AND',
OR: 'OR',
} as const;
export type ListFilterConjunctionOperator = typeof ListFilterConjunctionOperator[keyof typeof ListFilterConjunctionOperator];
/**
* Filter condition for list operations
*
* Tuple format: [value, comparator?, conjunction?]
*/
export type ListFilterCondition = [
string | number | boolean | string[] | number[],
ListFilterComparisonOperator?,
ListFilterConjunctionOperator?
];
/**
* Filter for list operations
*
* Values can be:
* - Simple primitives (string | number | boolean) for default equality comparison
* - ListFilterCondition tuple for explicit comparator/conjunction
*
* Examples:
* - Simple usage: { name: "John" }
* - With comparator: { age: [25, ListFilterComparisonOperator.GT] }
* - With conjunction: { age: [25, ListFilterComparisonOperator.GT, ListFilterConjunctionOperator.AND] }
* - With array value for IN operator: { status: [["active", "pending"], ListFilterComparisonOperator.IN] }
*/ */
export interface ListFilter { export interface ListFilter {
[key: string]: any; [attribute: string]: string | number | boolean | ListFilterCondition;
} }
/** /**
* Sort options for list operations * Sort for list operations
*
* Values can be:
* - true for ascending
* - false for descending
*/ */
export interface ListSort { export interface ListSort {
[key: string]: boolean; [attribute: string]: boolean;
} }
/** /**
* Range specification for pagination/limiting results * Range for list operations
*
* Values can be:
* - relative based on item identifier
* - absolute based on item count
*/ */
export interface ListRange { export interface ListRange {
start: number; type: 'tally';
limit: number; anchor: 'relative' | 'absolute';
position: string | number;
tally: number;
} }

View File

@@ -1,11 +1,11 @@
/** /**
* Entity type definitions for mail * Entity type definitions
*/ */
import type { SourceSelector } from './common'; import type { SourceSelector, ListFilter, ListSort, ListRange } from './common';
import type { MessageInterface } from './message'; import type { MessageInterface } from './message';
/** /**
* Entity wrapper with metadata * Entity definition
*/ */
export interface EntityInterface<T = MessageInterface> { export interface EntityInterface<T = MessageInterface> {
provider: string; provider: string;
@@ -19,18 +19,15 @@ export interface EntityInterface<T = MessageInterface> {
} }
/** /**
* Entity list request * Entity list
*/ */
export interface EntityListRequest { export interface EntityListRequest {
sources?: SourceSelector; sources?: SourceSelector;
filter?: any; filter?: ListFilter;
sort?: any; sort?: ListSort;
range?: { start: number; limit: number }; range?: ListRange;
} }
/**
* Entity list response
*/
export interface EntityListResponse { export interface EntityListResponse {
[providerId: string]: { [providerId: string]: {
[serviceId: string]: { [serviceId: string]: {
@@ -42,68 +39,38 @@ export interface EntityListResponse {
} }
/** /**
* Entity delta request * Entity fetch
*/
export interface EntityDeltaRequest {
sources: SourceSelector;
}
/**
* Entity delta response
*/
export interface EntityDeltaResponse {
[providerId: string]: {
[serviceId: string]: {
[collectionId: string]: {
signature: string;
created?: EntityInterface<MessageInterface>[];
modified?: EntityInterface<MessageInterface>[];
deleted?: string[];
};
};
};
}
/**
* Entity extant request
*/
export interface EntityExtantRequest {
sources: SourceSelector;
}
/**
* Entity extant response
*/
export interface EntityExtantResponse {
[providerId: string]: {
[serviceId: string]: {
[collectionId: string]: {
[messageId: string]: boolean;
};
};
};
}
/**
* Entity fetch request
*/ */
export interface EntityFetchRequest { export interface EntityFetchRequest {
provider: string; provider: string;
service: string | number; service: string | number;
collection: string | number; collection: string | number;
identifiers: (string | number)[]; identifiers: (string | number)[];
properties?: string[];
} }
/**
* Entity fetch response
*/
export interface EntityFetchResponse { export interface EntityFetchResponse {
entities: EntityInterface<MessageInterface>[]; [identifier: string]: EntityInterface<MessageInterface>;
} }
/** /**
* Entity create request * Entity extant
*/
export interface EntityExtantRequest {
sources: SourceSelector;
}
export interface EntityExtantResponse {
[providerId: string]: {
[serviceId: string]: {
[collectionId: string]: {
[identifier: string]: boolean;
};
};
};
}
/**
* Entity create
*/ */
export interface EntityCreateRequest<T = MessageInterface> { export interface EntityCreateRequest<T = MessageInterface> {
provider: string; provider: string;
@@ -112,17 +79,12 @@ export interface EntityCreateRequest<T = MessageInterface> {
properties: T; properties: T;
} }
/** export interface EntityCreateResponse<T = MessageInterface> extends EntityInterface<T> {}
* Entity create response
*/
export interface EntityCreateResponse<T = MessageInterface> {
entity: EntityInterface<T>;
}
/** /**
* Entity modify request * Entity update
*/ */
export interface EntityModifyRequest<T = MessageInterface> { export interface EntityUpdateRequest<T = MessageInterface> {
provider: string; provider: string;
service: string | number; service: string | number;
collection: string | number; collection: string | number;
@@ -130,35 +92,46 @@ export interface EntityModifyRequest<T = MessageInterface> {
properties: T; properties: T;
} }
/** export interface EntityUpdateResponse<T = MessageInterface> extends EntityInterface<T> {}
* Entity modify response
*/
export interface EntityModifyResponse<T = MessageInterface> {
success: boolean;
entity?: EntityInterface<T>;
}
/** /**
* Entity destroy request * Entity delete
*/ */
export interface EntityDestroyRequest { export interface EntityDeleteRequest {
provider: string; provider: string;
service: string | number; service: string | number;
collection: string | number; collection: string | number;
identifier: string | number; identifier: string | number;
} }
/** export interface EntityDeleteResponse {
* Entity destroy response
*/
export interface EntityDestroyResponse {
success: boolean; success: boolean;
} }
/** /**
* Entity send request * Entity delta
*/ */
export interface EntitySendRequest { export interface EntityDeltaRequest {
sources: SourceSelector;
}
export interface EntityDeltaResponse {
[providerId: string]: false | {
[serviceId: string]: false | {
[collectionId: string]: false | {
signature: string;
additions: (string | number)[];
modifications: (string | number)[];
deletions: (string | number)[];
};
};
};
}
/**
* Entity transmit
*/
export interface EntityTransmitRequest {
message: { message: {
from?: string; from?: string;
to: string[]; to: string[];
@@ -181,10 +154,7 @@ export interface EntitySendRequest {
}; };
} }
/** export interface EntityTransmitResponse {
* Entity send response
*/
export interface EntitySendResponse {
id: string; id: string;
status: 'queued' | 'sent'; status: 'queued' | 'sent';
} }

View File

@@ -29,41 +29,32 @@ export interface ProviderInterface {
} }
/** /**
* Provider list request * Provider list
*/ */
export interface ProviderListRequest { export interface ProviderListRequest {
sources?: SourceSelector; sources?: SourceSelector;
} }
/**
* Provider list response
*/
export interface ProviderListResponse { export interface ProviderListResponse {
[identifier: string]: ProviderInterface; [identifier: string]: ProviderInterface;
} }
/** /**
* Provider fetch request * Provider fetch
*/ */
export interface ProviderFetchRequest { export interface ProviderFetchRequest {
identifier: string; identifier: string;
} }
/**
* Provider fetch response
*/
export interface ProviderFetchResponse extends ProviderInterface {} export interface ProviderFetchResponse extends ProviderInterface {}
/** /**
* Provider extant request * Provider extant
*/ */
export interface ProviderExtantRequest { export interface ProviderExtantRequest {
sources: SourceSelector; sources: SourceSelector;
} }
/**
* Provider extant response
*/
export interface ProviderExtantResponse { export interface ProviderExtantResponse {
[identifier: string]: boolean; [identifier: string]: boolean;
} }

View File

@@ -1,7 +1,7 @@
/** /**
* Service-related type definitions * Service type definitions
*/ */
import type { SourceSelector } from './common'; import type { SourceSelector, ListFilterComparisonOperator } from './common';
/** /**
* Service capabilities * Service capabilities
@@ -9,29 +9,29 @@ import type { SourceSelector } from './common';
export interface ServiceCapabilitiesInterface { export interface ServiceCapabilitiesInterface {
// Collection capabilities // Collection capabilities
CollectionList?: boolean; CollectionList?: boolean;
CollectionListFilter?: boolean | { [field: string]: string }; CollectionListFilter?: ServiceListFilterCollection;
CollectionListSort?: boolean | string[]; CollectionListSort?: ServiceListSortCollection;
CollectionExtant?: boolean; CollectionExtant?: boolean;
CollectionFetch?: boolean; CollectionFetch?: boolean;
CollectionCreate?: boolean; CollectionCreate?: boolean;
CollectionModify?: boolean; CollectionUpdate?: boolean;
CollectionDelete?: boolean; CollectionDelete?: boolean;
// Message capabilities // Message capabilities
EntityList?: boolean; EntityList?: boolean;
EntityListFilter?: boolean | { [field: string]: string }; EntityListFilter?: ServiceListFilterEntity;
EntityListSort?: boolean | string[]; EntityListSort?: ServiceListSortEntity;
EntityListRange?: boolean | { tally?: string[] }; EntityListRange?: ServiceListRange;
EntityDelta?: boolean; EntityDelta?: boolean;
EntityExtant?: boolean; EntityExtant?: boolean;
EntityFetch?: boolean; EntityFetch?: boolean;
EntityCreate?: boolean; EntityCreate?: boolean;
EntityModify?: boolean; EntityUpdate?: boolean;
EntityDelete?: boolean; EntityDelete?: boolean;
EntityMove?: boolean; EntityMove?: boolean;
EntityCopy?: boolean; EntityCopy?: boolean;
// Send capability // Send capability
EntityTransmit?: boolean; EntityTransmit?: boolean;
[key: string]: boolean | object | string[] | undefined; [key: string]: boolean | object | string | string[] | undefined;
} }
/** /**
@@ -52,15 +52,12 @@ export interface ServiceInterface {
} }
/** /**
* Service list request * Service list
*/ */
export interface ServiceListRequest { export interface ServiceListRequest {
sources?: SourceSelector; sources?: SourceSelector;
} }
/**
* Service list response
*/
export interface ServiceListResponse { export interface ServiceListResponse {
[provider: string]: { [provider: string]: {
[identifier: string]: ServiceInterface; [identifier: string]: ServiceInterface;
@@ -68,15 +65,22 @@ export interface ServiceListResponse {
} }
/** /**
* Service extant request * Service fetch
*/
export interface ServiceFetchRequest {
provider: string;
identifier: string | number;
}
export interface ServiceFetchResponse extends ServiceInterface {}
/**
* Service extant
*/ */
export interface ServiceExtantRequest { export interface ServiceExtantRequest {
sources: SourceSelector; sources: SourceSelector;
} }
/**
* Service extant response
*/
export interface ServiceExtantResponse { export interface ServiceExtantResponse {
[provider: string]: { [provider: string]: {
[identifier: string]: boolean; [identifier: string]: boolean;
@@ -84,45 +88,17 @@ export interface ServiceExtantResponse {
} }
/** /**
* Service fetch request * Service create
*/
export interface ServiceFetchRequest {
provider: string;
identifier: string | number;
}
/**
* Service fetch response
*/
export interface ServiceFetchResponse extends ServiceInterface {}
/**
* Service find by address request
*/
export interface ServiceFindByAddressRequest {
address: string;
}
/**
* Service find by address response
*/
export interface ServiceFindByAddressResponse extends ServiceInterface {}
/**
* Service create request
*/ */
export interface ServiceCreateRequest { export interface ServiceCreateRequest {
provider: string; provider: string;
data: Partial<ServiceInterface>; data: Partial<ServiceInterface>;
} }
/**
* Service create response
*/
export interface ServiceCreateResponse extends ServiceInterface {} export interface ServiceCreateResponse extends ServiceInterface {}
/** /**
* Service update request * Service update
*/ */
export interface ServiceUpdateRequest { export interface ServiceUpdateRequest {
provider: string; provider: string;
@@ -130,29 +106,20 @@ export interface ServiceUpdateRequest {
data: Partial<ServiceInterface>; data: Partial<ServiceInterface>;
} }
/**
* Service update response
*/
export interface ServiceUpdateResponse extends ServiceInterface {} export interface ServiceUpdateResponse extends ServiceInterface {}
/** /**
* Service delete request * Service delete
*/ */
export interface ServiceDeleteRequest { export interface ServiceDeleteRequest {
provider: string; provider: string;
identifier: string | number; identifier: string | number;
} }
/**
* Service delete response
*/
export interface ServiceDeleteResponse {} export interface ServiceDeleteResponse {}
// ==================== Discovery Types ====================
/** /**
* Service discovery request - NEW VERSION * Service discovery
* Supports identity-based discovery with optional hints
*/ */
export interface ServiceDiscoverRequest { export interface ServiceDiscoverRequest {
identity: string; // Email address or domain identity: string; // Email address or domain
@@ -161,42 +128,36 @@ export interface ServiceDiscoverRequest {
secret?: string; // Optional: password/token for credential validation secret?: string; // Optional: password/token for credential validation
} }
/**
* Service discovery response - NEW VERSION
* Provider-keyed map of discovered service locations
*/
export interface ServiceDiscoverResponse { export interface ServiceDiscoverResponse {
[provider: string]: ServiceLocation; // Uses existing ServiceLocation discriminated union [provider: string]: ServiceLocation; // Uses existing ServiceLocation discriminated union
} }
/** /**
* Discovery status tracking for real-time UI updates * Service connection test
* Used by store to track per-provider discovery progress
*/ */
export interface ProviderDiscoveryStatus { export interface ServiceTestRequest {
provider: string; provider: string;
status: 'pending' | 'discovering' | 'success' | 'failed'; // For existing service
location?: ServiceLocation; identifier?: string | number | null;
error?: string; // For fresh configuration
metadata?: { location?: ServiceLocation | null;
host?: string; identity?: ServiceIdentity | null;
port?: number;
protocol?: string;
};
} }
// ==================== Service Testing Types ==================== export interface ServiceTestResponse {
success: boolean;
message: string;
}
/** /**
* Base service location interface * Service location - Base
*/ */
export interface ServiceLocationBase { export interface ServiceLocationBase {
type: 'URI' | 'SOCKET_SOLE' | 'SOCKET_SPLIT' | 'FILE'; type: 'URI' | 'SOCKET_SOLE' | 'SOCKET_SPLIT' | 'FILE';
} }
/** /**
* URI-based service location for API and web services * Service location - URI-based type
* Used by: JMAP, Gmail API, etc.
*/ */
export interface ServiceLocationUri extends ServiceLocationBase { export interface ServiceLocationUri extends ServiceLocationBase {
type: 'URI'; type: 'URI';
@@ -209,8 +170,7 @@ export interface ServiceLocationUri extends ServiceLocationBase {
} }
/** /**
* Single socket-based service location * Service location - Single socket-based type (combined inbound/outbound configuration)
* Used by: services using a single host/port combination
*/ */
export interface ServiceLocationSocketSole extends ServiceLocationBase { export interface ServiceLocationSocketSole extends ServiceLocationBase {
type: 'SOCKET_SOLE'; type: 'SOCKET_SOLE';
@@ -222,8 +182,7 @@ export interface ServiceLocationSocketSole extends ServiceLocationBase {
} }
/** /**
* Split socket-based service location * Service location - Split socket-based type (separate inbound/outbound configurations)
* Used by: traditional IMAP/SMTP configurations
*/ */
export interface ServiceLocationSocketSplit extends ServiceLocationBase { export interface ServiceLocationSocketSplit extends ServiceLocationBase {
type: 'SOCKET_SPLIT'; type: 'SOCKET_SPLIT';
@@ -240,8 +199,7 @@ export interface ServiceLocationSocketSplit extends ServiceLocationBase {
} }
/** /**
* File-based service location * Service location - File-based type (e.g., for local mail delivery or Unix socket)
* Used by: local file system providers
*/ */
export interface ServiceLocationFile extends ServiceLocationBase { export interface ServiceLocationFile extends ServiceLocationBase {
type: 'FILE'; type: 'FILE';
@@ -249,7 +207,7 @@ export interface ServiceLocationFile extends ServiceLocationBase {
} }
/** /**
* Discriminated union of all service location types * Service location types
*/ */
export type ServiceLocation = export type ServiceLocation =
| ServiceLocationUri | ServiceLocationUri
@@ -257,24 +215,22 @@ export type ServiceLocation =
| ServiceLocationSocketSplit | ServiceLocationSocketSplit
| ServiceLocationFile; | ServiceLocationFile;
// ==================== Service Identity Types ====================
/** /**
* Base service identity interface * Service identity - base
*/ */
export interface ServiceIdentityBase { export interface ServiceIdentityBase {
type: 'NA' | 'BA' | 'TA' | 'OA' | 'CC'; type: 'NA' | 'BA' | 'TA' | 'OA' | 'CC';
} }
/** /**
* No authentication * Service identity - No authentication
*/ */
export interface ServiceIdentityNone extends ServiceIdentityBase { export interface ServiceIdentityNone extends ServiceIdentityBase {
type: 'NA'; type: 'NA';
} }
/** /**
* Basic authentication (username/password) * Service identity - Basic authentication type
*/ */
export interface ServiceIdentityBasic extends ServiceIdentityBase { export interface ServiceIdentityBasic extends ServiceIdentityBase {
type: 'BA'; type: 'BA';
@@ -324,21 +280,58 @@ export type ServiceIdentity =
| ServiceIdentityCertificate; | ServiceIdentityCertificate;
/** /**
* Service connection test request * List filter specification format
*
* Format: "type:length:defaultComparator:supportedComparators"
*
* Examples:
* - "s:200:256:771" = String field, max 200 chars, default LIKE, supports EQ|NEQ|LIKE|NLIKE
* - "a:10:64:192" = Array field, max 10 items, default IN, supports IN|NIN
* - "i:0:1:31" = Integer field, default EQ, supports EQ|NEQ|GT|LT|GTE|LTE
*
* Type codes:
* - s = string
* - i = integer
* - b = boolean
* - a = array
*
* Comparator values are bitmasks that can be combined
*/ */
export interface ServiceTestRequest { export type ServiceListFilterCollection = {
provider: string; 'label'?: string;
// For existing service 'rank'?: string;
identifier?: string | number | null; [attribute: string]: string | undefined;
// For fresh configuration };
location?: ServiceLocation | null;
identity?: ServiceIdentity | null; export type ServiceListFilterEntity = {
'*'?: string;
'from'?: string;
'to'?: string;
'cc'?: string;
'bcc'?: string;
'subject'?: string;
'body'?: string;
'before'?: string;
'after'?: string;
'min'?: string;
'max'?: string;
[attribute: string]: string | undefined;
} }
/** /**
* Service connection test response * Service list sort specification
*/ */
export interface ServiceTestResponse { export type ServiceListSortCollection = ("label" | "rank" | string)[];
success: boolean; export type ServiceListSortEntity = ("from" | "to" | "subject" | "received" | "sent" | "size" | string)[];
message: string;
export type ServiceListRange = {
'tally'?: string[];
};
export interface ServiceListFilterDefinition {
type: 'string' | 'integer' | 'date' | 'boolean' | 'array';
length: number;
defaultComparator: ListFilterComparisonOperator;
supportedComparators: ListFilterComparisonOperator[];
} }

View File

@@ -1,276 +1,61 @@
/** /**
* Helper functions for working with service identity and location types * Helper functions for working with service types
*/ */
import type { import type { ServiceListFilterDefinition } from '@/types/service';
ServiceIdentity, import { ListFilterComparisonOperator } from '@/types/common';
ServiceIdentityNone,
ServiceIdentityBasic,
ServiceIdentityToken,
ServiceIdentityOAuth,
ServiceIdentityCertificate,
ServiceLocation,
ServiceLocationUri,
ServiceLocationSocketSole,
ServiceLocationSocketSplit,
ServiceLocationFile
} from '@/types/service';
// ==================== Identity Helpers ====================
/** /**
* Create a "None" identity (no authentication) * Parse a filter specification string into its components
*
* @param spec - Filter specification string (e.g., "s:200:256:771")
* @returns Parsed filter specification object
*
* @example
* parseFilterSpec("s:200:256:771")
* // Returns: {
* // type: 'string',
* // length: 200,
* // defaultComparator: 256 (LIKE),
* // supportedComparators: [1, 2, 256, 512] (EQ, NEQ, LIKE, NLIKE)
* // }
*/ */
export function createIdentityNone(): ServiceIdentityNone { export function parseFilterSpec(spec: string): ServiceListFilterDefinition {
return { type: 'NA' }; const [typeCode, lengthStr, defaultComparatorStr, supportedComparatorsStr] = spec.split(':');
const typeMap: Record<string, ServiceListFilterDefinition['type']> = {
's': 'string',
'i': 'integer',
'd': 'date',
'b': 'boolean',
'a': 'array',
};
const type = typeMap[typeCode];
if (!type) {
throw new Error(`Invalid filter type code: ${typeCode}`);
}
const length = parseInt(lengthStr, 10);
const defaultComparator = parseInt(defaultComparatorStr, 10) as ListFilterComparisonOperator;
// Parse supported comparators from bitmask
const supportedComparators: ListFilterComparisonOperator[] = [];
const supportedBitmask = parseInt(supportedComparatorsStr, 10);
if (supportedBitmask !== 0) {
const allComparators = Object.values(ListFilterComparisonOperator).filter(v => typeof v === 'number') as number[];
for (const comparator of allComparators) {
if ((supportedBitmask & comparator) === comparator) {
supportedComparators.push(comparator as ListFilterComparisonOperator);
}
}
} }
/**
* Create a Basic Auth identity
*/
export function createIdentityBasic(identity: string, secret: string): ServiceIdentityBasic {
return { return {
type: 'BA', type,
identity, length,
secret defaultComparator,
supportedComparators,
}; };
} }
/**
* Create a Token Auth identity
*/
export function createIdentityToken(token: string): ServiceIdentityToken {
return {
type: 'TA',
token
};
}
/**
* Create an OAuth identity
*/
export function createIdentityOAuth(
accessToken: string,
options?: {
accessScope?: string[];
accessExpiry?: number;
refreshToken?: string;
refreshLocation?: string;
}
): ServiceIdentityOAuth {
return {
type: 'OA',
accessToken,
...options
};
}
/**
* Create a Certificate identity
*/
export function createIdentityCertificate(
certificate: string,
privateKey: string,
passphrase?: string
): ServiceIdentityCertificate {
return {
type: 'CC',
certificate,
privateKey,
...(passphrase && { passphrase })
};
}
// ==================== Location Helpers ====================
/**
* Create a URI-based location
*/
export function createLocationUri(
host: string,
options?: {
scheme?: 'http' | 'https';
port?: number;
path?: string;
verifyPeer?: boolean;
verifyHost?: boolean;
}
): ServiceLocationUri {
return {
type: 'URI',
scheme: options?.scheme || 'https',
host,
port: options?.port || (options?.scheme === 'http' ? 80 : 443),
...(options?.path && { path: options.path }),
verifyPeer: options?.verifyPeer ?? true,
verifyHost: options?.verifyHost ?? true
};
}
/**
* Create a URI location from a full URL string
*/
export function createLocationFromUrl(url: string): ServiceLocationUri {
try {
const parsed = new URL(url);
return {
type: 'URI',
scheme: parsed.protocol.replace(':', '') as 'http' | 'https',
host: parsed.hostname,
port: parsed.port ? parseInt(parsed.port) : (parsed.protocol === 'https:' ? 443 : 80),
path: parsed.pathname,
verifyPeer: true,
verifyHost: true
};
} catch (error) {
throw new Error(`Invalid URL: ${url}`);
}
}
/**
* Create a single socket location (IMAP, SMTP on same server)
*/
export function createLocationSocketSole(
host: string,
port: number,
encryption: 'none' | 'ssl' | 'tls' | 'starttls' = 'ssl',
options?: {
verifyPeer?: boolean;
verifyHost?: boolean;
}
): ServiceLocationSocketSole {
return {
type: 'SOCKET_SOLE',
host,
port,
encryption,
verifyPeer: options?.verifyPeer ?? true,
verifyHost: options?.verifyHost ?? true
};
}
/**
* Create a split socket location (separate IMAP/SMTP servers)
*/
export function createLocationSocketSplit(
config: {
inboundHost: string;
inboundPort: number;
inboundEncryption?: 'none' | 'ssl' | 'tls' | 'starttls';
outboundHost: string;
outboundPort: number;
outboundEncryption?: 'none' | 'ssl' | 'tls' | 'starttls';
inboundVerifyPeer?: boolean;
inboundVerifyHost?: boolean;
outboundVerifyPeer?: boolean;
outboundVerifyHost?: boolean;
}
): ServiceLocationSocketSplit {
return {
type: 'SOCKET_SPLIT',
inboundHost: config.inboundHost,
inboundPort: config.inboundPort,
inboundEncryption: config.inboundEncryption || 'ssl',
outboundHost: config.outboundHost,
outboundPort: config.outboundPort,
outboundEncryption: config.outboundEncryption || 'ssl',
inboundVerifyPeer: config.inboundVerifyPeer ?? true,
inboundVerifyHost: config.inboundVerifyHost ?? true,
outboundVerifyPeer: config.outboundVerifyPeer ?? true,
outboundVerifyHost: config.outboundVerifyHost ?? true
};
}
/**
* Create a file-based location
*/
export function createLocationFile(path: string): ServiceLocationFile {
return {
type: 'FILE',
path
};
}
// ==================== Validation Helpers ====================
/**
* Validate that an identity object is properly formed
*/
export function validateIdentity(identity: ServiceIdentity): boolean {
switch (identity.type) {
case 'NA':
return true;
case 'BA':
return !!(identity as ServiceIdentityBasic).identity &&
!!(identity as ServiceIdentityBasic).secret;
case 'TA':
return !!(identity as ServiceIdentityToken).token;
case 'OA':
return !!(identity as ServiceIdentityOAuth).accessToken;
case 'CC':
return !!(identity as ServiceIdentityCertificate).certificate &&
!!(identity as ServiceIdentityCertificate).privateKey;
default:
return false;
}
}
/**
* Validate that a location object is properly formed
*/
export function validateLocation(location: ServiceLocation): boolean {
switch (location.type) {
case 'URI':
return !!(location as ServiceLocationUri).host &&
!!(location as ServiceLocationUri).port;
case 'SOCKET_SOLE':
return !!(location as ServiceLocationSocketSole).host &&
!!(location as ServiceLocationSocketSole).port;
case 'SOCKET_SPLIT':
const split = location as ServiceLocationSocketSplit;
return !!split.inboundHost && !!split.inboundPort &&
!!split.outboundHost && !!split.outboundPort;
case 'FILE':
return !!(location as ServiceLocationFile).path;
default:
return false;
}
}
// ==================== Type Guards ====================
export function isIdentityNone(identity: ServiceIdentity): identity is ServiceIdentityNone {
return identity.type === 'NA';
}
export function isIdentityBasic(identity: ServiceIdentity): identity is ServiceIdentityBasic {
return identity.type === 'BA';
}
export function isIdentityToken(identity: ServiceIdentity): identity is ServiceIdentityToken {
return identity.type === 'TA';
}
export function isIdentityOAuth(identity: ServiceIdentity): identity is ServiceIdentityOAuth {
return identity.type === 'OA';
}
export function isIdentityCertificate(identity: ServiceIdentity): identity is ServiceIdentityCertificate {
return identity.type === 'CC';
}
export function isLocationUri(location: ServiceLocation): location is ServiceLocationUri {
return location.type === 'URI';
}
export function isLocationSocketSole(location: ServiceLocation): location is ServiceLocationSocketSole {
return location.type === 'SOCKET_SOLE';
}
export function isLocationSocketSplit(location: ServiceLocation): location is ServiceLocationSocketSplit {
return location.type === 'SOCKET_SPLIT';
}
export function isLocationFile(location: ServiceLocation): location is ServiceLocationFile {
return location.type === 'FILE';
}