chore: standardize protocol #2
@@ -226,34 +226,39 @@ class DefaultController extends ControllerAbstract {
|
||||
return match ($operation) {
|
||||
// Provider operations
|
||||
'provider.list' => $this->providerList($tenantId, $userId, $data),
|
||||
'provider.fetch' => $this->providerFetch($tenantId, $userId, $data),
|
||||
'provider.extant' => $this->providerExtant($tenantId, $userId, $data),
|
||||
|
||||
// Service operations
|
||||
'service.list' => $this->serviceList($tenantId, $userId, $data),
|
||||
'service.extant' => $this->serviceExtant($tenantId, $userId, $data),
|
||||
'service.fetch' => $this->serviceFetch($tenantId, $userId, $data),
|
||||
'service.discover' => $this->serviceDiscover($tenantId, $userId, $data),
|
||||
'service.test' => $this->serviceTest($tenantId, $userId, $data),
|
||||
'service.extant' => $this->serviceExtant($tenantId, $userId, $data),
|
||||
'service.create' => $this->serviceCreate($tenantId, $userId, $data),
|
||||
'service.update' => $this->serviceUpdate($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.list' => $this->collectionList($tenantId, $userId, $data),
|
||||
'collection.extant' => $this->collectionExtant($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.modify' => $this->collectionModify($tenantId, $userId, $data),
|
||||
'collection.destroy' => $this->collectionDestroy($tenantId, $userId, $data),
|
||||
'collection.update' => $this->collectionUpdate($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.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.extant' => $this->entityExtant($tenantId, $userId, $data),
|
||||
'entity.create' => 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.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),
|
||||
|
||||
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 =====================
|
||||
|
||||
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'])) {
|
||||
throw new InvalidArgumentException(self::ERR_MISSING_PROVIDER);
|
||||
}
|
||||
@@ -562,7 +579,7 @@ class DefaultController extends ControllerAbstract {
|
||||
throw new InvalidArgumentException(self::ERR_INVALID_DATA);
|
||||
}
|
||||
|
||||
return $this->mailManager->collectionModify(
|
||||
return $this->mailManager->collectionUpdate(
|
||||
$tenantId,
|
||||
$userId,
|
||||
$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'])) {
|
||||
throw new InvalidArgumentException(self::ERR_MISSING_PROVIDER);
|
||||
}
|
||||
@@ -592,7 +609,7 @@ class DefaultController extends ControllerAbstract {
|
||||
throw new InvalidArgumentException(self::ERR_INVALID_IDENTIFIER);
|
||||
}
|
||||
|
||||
return $this->mailManager->collectionDestroy(
|
||||
return $this->mailManager->collectionDelete(
|
||||
$tenantId,
|
||||
$userId,
|
||||
$data['provider'],
|
||||
|
||||
@@ -621,7 +621,7 @@ class Manager {
|
||||
* @return CollectionBaseInterface
|
||||
* @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
|
||||
$service = $this->serviceFetch($tenantId, $userId, $providerId, $serviceId);
|
||||
|
||||
@@ -629,8 +629,8 @@ class Manager {
|
||||
if (!($service instanceof ServiceCollectionMutableInterface)) {
|
||||
throw new InvalidArgumentException("Service does not support collection mutations");
|
||||
}
|
||||
if (!$service->capable(ServiceCollectionMutableInterface::CAPABILITY_COLLECTION_MODIFY)) {
|
||||
throw new InvalidArgumentException("Service is not capable of modifying collections");
|
||||
if (!$service->capable(ServiceCollectionMutableInterface::CAPABILITY_COLLECTION_UPDATE)) {
|
||||
throw new InvalidArgumentException("Service is not capable of updating collections");
|
||||
}
|
||||
|
||||
if (is_array($object)) {
|
||||
@@ -640,12 +640,12 @@ class Manager {
|
||||
$collection = $object;
|
||||
}
|
||||
|
||||
// Modify collection
|
||||
return $service->collectionModify($collectionId, $collection);
|
||||
// Update collection
|
||||
return $service->collectionUpdate($collectionId, $collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy a specific collection
|
||||
* Delete a specific collection
|
||||
*
|
||||
* @since 2025.05.01
|
||||
*
|
||||
@@ -657,23 +657,23 @@ class Manager {
|
||||
*
|
||||
* @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
|
||||
$service = $this->serviceFetch($tenantId, $userId, $providerId, $serviceId);
|
||||
|
||||
// Check if service supports collection destruction
|
||||
// Check if service supports collection deletion
|
||||
if (!($service instanceof ServiceCollectionMutableInterface)) {
|
||||
throw new InvalidArgumentException("Service does not support collection mutations");
|
||||
}
|
||||
if (!$service->capable(ServiceCollectionMutableInterface::CAPABILITY_COLLECTION_DESTROY)) {
|
||||
throw new InvalidArgumentException("Service is not capable of destroying collections");
|
||||
if (!$service->capable(ServiceCollectionMutableInterface::CAPABILITY_COLLECTION_DELETE)) {
|
||||
throw new InvalidArgumentException("Service is not capable of deleting collections");
|
||||
}
|
||||
|
||||
$force = $options['force'] ?? false;
|
||||
$recursive = $options['recursive'] ?? false;
|
||||
|
||||
// destroy collection
|
||||
return $service->collectionDestroy($collectionId, $force, $recursive);
|
||||
// delete collection
|
||||
return $service->collectionDelete($collectionId, $force, $recursive);
|
||||
}
|
||||
|
||||
// ==================== Message Operations ====================
|
||||
|
||||
1500
package-lock.json
generated
Normal file
1500
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -37,6 +37,7 @@ export function useMailSync(options: SyncOptions = {}) {
|
||||
const lastSync = ref<Date | null>(null);
|
||||
const error = ref<string | null>(null);
|
||||
const sources = ref<SyncSource[]>([]);
|
||||
const signatures = ref<Record<string, Record<string, Record<string, string>>>>({});
|
||||
|
||||
let syncInterval: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
@@ -101,12 +102,12 @@ export function useMailSync(options: SyncOptions = {}) {
|
||||
|
||||
// Add collections to check with their signatures
|
||||
source.collections.forEach(collection => {
|
||||
// Look up signature from entities store first (updated by delta), fallback to collections store
|
||||
let signature = entitiesStore.signatures[source.provider]?.[String(source.service)]?.[String(collection)];
|
||||
// Look up signature from local tracking (updated by delta)
|
||||
let signature = signatures.value[source.provider]?.[String(source.service)]?.[String(collection)];
|
||||
|
||||
// Fallback to collection signature if not yet synced
|
||||
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 || '';
|
||||
}
|
||||
|
||||
@@ -118,7 +119,7 @@ export function useMailSync(options: SyncOptions = {}) {
|
||||
});
|
||||
|
||||
// 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) {
|
||||
const fetchPromises: Promise<any>[] = [];
|
||||
@@ -131,6 +132,18 @@ export function useMailSync(options: SyncOptions = {}) {
|
||||
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)
|
||||
const oldSignature = deltaSources[provider]?.[service]?.[collection];
|
||||
const newSignature = collectionData.signature;
|
||||
@@ -149,7 +162,7 @@ export function useMailSync(options: SyncOptions = {}) {
|
||||
if (identifiersToFetch.length > 0) {
|
||||
console.log(`[Sync] Fetching ${identifiersToFetch.length} entities for ${provider}/${service}/${collection}`);
|
||||
fetchPromises.push(
|
||||
entitiesStore.getMessages(
|
||||
entitiesStore.fetch(
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
|
||||
@@ -12,28 +12,74 @@ import type {
|
||||
CollectionFetchResponse,
|
||||
CollectionCreateRequest,
|
||||
CollectionCreateResponse,
|
||||
CollectionModifyRequest,
|
||||
CollectionModifyResponse,
|
||||
CollectionDestroyRequest,
|
||||
CollectionDestroyResponse
|
||||
CollectionUpdateResponse,
|
||||
CollectionUpdateRequest,
|
||||
CollectionDeleteResponse,
|
||||
CollectionDeleteRequest,
|
||||
CollectionInterface,
|
||||
} 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 = {
|
||||
|
||||
/**
|
||||
* List all available collections
|
||||
* Retrieve list of collections, optionally filtered by source selector
|
||||
*
|
||||
* @param request - Collection list request parameters
|
||||
* @returns Promise with collection list grouped by provider and service
|
||||
* @param request - list request parameters
|
||||
*
|
||||
* @returns Promise with collection object list grouped by provider, service, and collection identifier
|
||||
*/
|
||||
async list(request: CollectionListRequest = {}): Promise<CollectionListResponse> {
|
||||
return await transceivePost<CollectionListRequest, CollectionListResponse>('collection.list', request);
|
||||
async list(request: CollectionListRequest = {}): Promise<Record<string, Record<string, Record<string, CollectionObject>>>> {
|
||||
const response = await transceivePost<CollectionListRequest, CollectionListResponse>('collection.list', request);
|
||||
|
||||
// Convert nested response to CollectionObject instances
|
||||
const providerList: Record<string, Record<string, Record<string, CollectionObject>>> = {};
|
||||
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||
const serviceList: Record<string, Record<string, CollectionObject>> = {};
|
||||
Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
|
||||
const collectionList: Record<string, CollectionObject> = {};
|
||||
Object.entries(serviceCollections).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
|
||||
*/
|
||||
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
|
||||
* @returns Promise with collection details
|
||||
* @param request - create request parameters
|
||||
*
|
||||
* @returns Promise with created collection object
|
||||
*/
|
||||
async fetch(request: CollectionFetchRequest): Promise<CollectionFetchResponse> {
|
||||
return await transceivePost<CollectionFetchRequest, CollectionFetchResponse>('collection.fetch', request);
|
||||
async create(request: CollectionCreateRequest): Promise<CollectionObject> {
|
||||
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
|
||||
* @returns Promise with created collection details
|
||||
* @param request - update request parameters
|
||||
*
|
||||
* @returns Promise with updated collection object
|
||||
*/
|
||||
async create(request: CollectionCreateRequest): Promise<CollectionCreateResponse> {
|
||||
return await transceivePost<CollectionCreateRequest, CollectionCreateResponse>('collection.create', request);
|
||||
async update(request: CollectionUpdateRequest): Promise<CollectionObject> {
|
||||
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
|
||||
* @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 - delete request parameters
|
||||
*
|
||||
* @param request - Collection destroy parameters
|
||||
* @returns Promise with destroy operation result
|
||||
* @returns Promise with deletion result
|
||||
*/
|
||||
async destroy(request: CollectionDestroyRequest): Promise<CollectionDestroyResponse> {
|
||||
return await transceivePost<CollectionDestroyRequest, CollectionDestroyResponse>('collection.destroy', request);
|
||||
async delete(request: CollectionDeleteRequest): Promise<CollectionDeleteResponse> {
|
||||
return await transceivePost<CollectionDeleteRequest, CollectionDeleteResponse>('collection.delete', request);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,119 +1,161 @@
|
||||
/**
|
||||
* Message/Entity management service
|
||||
* Entity management service
|
||||
*/
|
||||
|
||||
import { transceivePost } from './transceive';
|
||||
import type {
|
||||
MessageListRequest,
|
||||
MessageListResponse,
|
||||
MessageDeltaRequest,
|
||||
MessageDeltaResponse,
|
||||
MessageExtantRequest,
|
||||
MessageExtantResponse,
|
||||
MessageFetchRequest,
|
||||
MessageFetchResponse,
|
||||
MessageSearchRequest,
|
||||
MessageSearchResponse,
|
||||
MessageSendRequest,
|
||||
MessageSendResponse,
|
||||
MessageCreateRequest,
|
||||
MessageCreateResponse,
|
||||
MessageUpdateRequest,
|
||||
MessageUpdateResponse,
|
||||
MessageDestroyRequest,
|
||||
MessageDestroyResponse,
|
||||
EntityListRequest,
|
||||
EntityListResponse,
|
||||
EntityFetchRequest,
|
||||
EntityFetchResponse,
|
||||
EntityExtantRequest,
|
||||
EntityExtantResponse,
|
||||
EntityCreateRequest,
|
||||
EntityCreateResponse,
|
||||
EntityUpdateRequest,
|
||||
EntityUpdateResponse,
|
||||
EntityDeleteRequest,
|
||||
EntityDeleteResponse,
|
||||
EntityDeltaRequest,
|
||||
EntityDeltaResponse,
|
||||
EntityTransmitRequest,
|
||||
EntityTransmitResponse,
|
||||
EntityInterface,
|
||||
} from '../types/entity';
|
||||
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||
import { EntityObject } from '../models';
|
||||
|
||||
/**
|
||||
* Helper to create the right entity model class based on provider identifier
|
||||
* Uses provider-specific factory if available, otherwise returns base EntityObject
|
||||
*/
|
||||
function createEntityObject(data: EntityInterface): EntityObject {
|
||||
const integrationStore = useIntegrationStore();
|
||||
const factoryItem = integrationStore.getItemById('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 = {
|
||||
|
||||
/**
|
||||
* List all available messages
|
||||
* Retrieve list of entities, optionally filtered by source selector
|
||||
*
|
||||
* @param request - Message list request parameters
|
||||
* @returns Promise with message list grouped by provider, service, and collection
|
||||
* @param request - list request parameters
|
||||
*
|
||||
* @returns Promise with entity object list grouped by provider, service, collection, and entity identifier
|
||||
*/
|
||||
async list(request: MessageListRequest = {}): Promise<MessageListResponse> {
|
||||
return await transceivePost<MessageListRequest, MessageListResponse>('entity.list', request);
|
||||
async list(request: EntityListRequest = {}): Promise<Record<string, Record<string, Record<string, Record<string, EntityObject>>>>> {
|
||||
const response = await transceivePost<EntityListRequest, EntityListResponse>('entity.list', request);
|
||||
|
||||
// Convert nested response to EntityObject instances
|
||||
const providerList: Record<string, Record<string, Record<string, Record<string, EntityObject>>>> = {};
|
||||
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||
const serviceList: Record<string, Record<string, Record<string, EntityObject>>> = {};
|
||||
Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
|
||||
const collectionList: Record<string, Record<string, EntityObject>> = {};
|
||||
Object.entries(serviceCollections).forEach(([collectionId, collectionEntities]) => {
|
||||
const entityList: Record<string, EntityObject> = {};
|
||||
Object.entries(collectionEntities).forEach(([entityId, entityData]) => {
|
||||
entityList[entityId] = createEntityObject(entityData);
|
||||
});
|
||||
collectionList[collectionId] = entityList;
|
||||
});
|
||||
serviceList[serviceId] = collectionList;
|
||||
});
|
||||
providerList[providerId] = serviceList;
|
||||
});
|
||||
|
||||
return providerList;
|
||||
},
|
||||
|
||||
/**
|
||||
* Get delta changes for 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)
|
||||
*/
|
||||
async delta(request: MessageDeltaRequest): Promise<MessageDeltaResponse> {
|
||||
return await transceivePost('entity.delta', request);
|
||||
async delta(request: EntityDeltaRequest): Promise<EntityDeltaResponse> {
|
||||
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
|
||||
* @returns Promise with message availability status
|
||||
*/
|
||||
async extant(request: MessageExtantRequest): Promise<MessageExtantResponse> {
|
||||
return await transceivePost('entity.extant', request);
|
||||
},
|
||||
|
||||
/**
|
||||
* Fetch specific messages
|
||||
* @param request - transmit request parameters
|
||||
*
|
||||
* @param request - Message fetch request
|
||||
* @returns Promise with message details
|
||||
* @returns Promise with transmission result
|
||||
*/
|
||||
async fetch(request: MessageFetchRequest): Promise<MessageFetchResponse> {
|
||||
return await transceivePost('entity.fetch', 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);
|
||||
async transmit(request: EntityTransmitRequest): Promise<EntityTransmitResponse> {
|
||||
return await transceivePost<EntityTransmitRequest, EntityTransmitResponse>('entity.transmit', request);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -8,18 +8,32 @@ import type {
|
||||
ProviderExtantRequest,
|
||||
ProviderExtantResponse,
|
||||
ProviderFetchRequest,
|
||||
ProviderFetchResponse,
|
||||
ProviderFetchResponse,
|
||||
ProviderInterface,
|
||||
} from '../types/provider';
|
||||
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||
import { transceivePost } from './transceive';
|
||||
import { ProviderObject } from '../models/provider';
|
||||
|
||||
/**
|
||||
* Helper to create the right provider model class based on provider identifier
|
||||
* Uses provider-specific factory if available, otherwise returns base ProviderObject
|
||||
*/
|
||||
function createProviderObject(data: ProviderInterface): ProviderObject {
|
||||
const integrationStore = useIntegrationStore();
|
||||
const factoryItem = integrationStore.getItemById('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 = {
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -29,28 +43,28 @@ export const providerService = {
|
||||
// Convert response to ProviderObject instances
|
||||
const list: Record<string, ProviderObject> = {};
|
||||
Object.entries(response).forEach(([providerId, providerData]) => {
|
||||
list[providerId] = new ProviderObject().fromJson(providerData);
|
||||
list[providerId] = createProviderObject(providerData);
|
||||
});
|
||||
|
||||
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
|
||||
*/
|
||||
async fetch(request: ProviderFetchRequest): Promise<ProviderObject> {
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -18,13 +18,15 @@ import type {
|
||||
ServiceCreateRequest,
|
||||
ServiceUpdateResponse,
|
||||
ServiceUpdateRequest,
|
||||
ServiceDeleteResponse,
|
||||
ServiceDeleteRequest,
|
||||
} from '../types/service';
|
||||
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||
import { transceivePost } from './transceive';
|
||||
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
|
||||
*/
|
||||
function createServiceObject(data: ServiceInterface): ServiceObject {
|
||||
@@ -39,9 +41,9 @@ function createServiceObject(data: ServiceInterface): ServiceObject {
|
||||
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
|
||||
*/
|
||||
@@ -49,31 +51,23 @@ export const serviceService = {
|
||||
const response = await transceivePost<ServiceListRequest, ServiceListResponse>('service.list', request);
|
||||
|
||||
// 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]) => {
|
||||
list[providerId] = {};
|
||||
const serviceList: Record<string, ServiceObject> = {};
|
||||
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
|
||||
* @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 - fetch request parameters
|
||||
*
|
||||
* @param request - Service fetch request with provider and service IDs
|
||||
* @returns Promise with service object
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
* @returns Promise with test results
|
||||
@@ -121,7 +127,8 @@ export const serviceService = {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
async create(request: ServiceCreateRequest): Promise<ServiceObject> {
|
||||
@@ -132,7 +139,8 @@ export const serviceService = {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
async update(request: ServiceUpdateRequest): Promise<ServiceObject> {
|
||||
@@ -143,11 +151,12 @@ export const serviceService = {
|
||||
/**
|
||||
* Delete a service
|
||||
*
|
||||
* @param request - Service delete request with provider ID and service ID
|
||||
* @param request - delete request parameters
|
||||
*
|
||||
* @returns Promise with deletion result
|
||||
*/
|
||||
async delete(request: { provider: string; identifier: string | number }): Promise<any> {
|
||||
return await transceivePost('service.delete', request);
|
||||
return await transceivePost<ServiceDeleteRequest, ServiceDeleteResponse>('service.delete', request);
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -1,169 +1,329 @@
|
||||
/**
|
||||
* Collections Store
|
||||
*/
|
||||
|
||||
import { ref, computed, readonly } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
import { collectionService } from '../services'
|
||||
import type { CollectionInterface, CollectionCreateRequest } from '../types'
|
||||
import { CollectionObject, CollectionPropertiesObject } from '../models/collection'
|
||||
import { CollectionObject } from '../models/collection'
|
||||
import type { SourceSelector, ListFilter, ListSort, CollectionMutableProperties } from '../types'
|
||||
|
||||
export const useCollectionsStore = defineStore('mail-collections', {
|
||||
state: () => ({
|
||||
collections: {} as Record<string, Record<string, Record<string, CollectionObject>>>,
|
||||
loading: false,
|
||||
error: null as string | null,
|
||||
}),
|
||||
export const useCollectionsStore = defineStore('mailCollectionsStore', () => {
|
||||
// State
|
||||
const _collections = ref<Record<string, CollectionObject>>({})
|
||||
const transceiving = ref(false)
|
||||
|
||||
actions: {
|
||||
async loadCollections(sources?: any) {
|
||||
this.loading = true
|
||||
this.error = null
|
||||
try {
|
||||
const response = await collectionService.list({ sources })
|
||||
|
||||
// Response is already in nested object format: provider -> service -> collection
|
||||
// Transform to CollectionObject instances
|
||||
const transformed: Record<string, Record<string, Record<string, CollectionObject>>> = {}
|
||||
|
||||
for (const [providerId, providerData] of Object.entries(response)) {
|
||||
transformed[providerId] = {}
|
||||
|
||||
for (const [serviceId, collections] of Object.entries(providerData as any)) {
|
||||
transformed[providerId][serviceId] = {}
|
||||
|
||||
// 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)
|
||||
}
|
||||
/**
|
||||
* Get count of collections in store
|
||||
*/
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
this.collections = transformed
|
||||
} catch (error: any) {
|
||||
this.error = error.message
|
||||
throw error
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
list(sources)
|
||||
}
|
||||
|
||||
return nestedCollections
|
||||
}
|
||||
|
||||
async getCollection(provider: string, service: string | number, collectionId: string | number) {
|
||||
this.loading = true
|
||||
this.error = null
|
||||
try {
|
||||
const response = await collectionService.fetch({
|
||||
provider,
|
||||
service,
|
||||
collection: collectionId
|
||||
})
|
||||
|
||||
// Create CollectionObject instance
|
||||
const collectionObject = new CollectionObject().fromJson(response)
|
||||
|
||||
// Update in store
|
||||
if (!this.collections[provider]) {
|
||||
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) {
|
||||
this.error = error.message
|
||||
throw error
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Create unique key for a collection
|
||||
*/
|
||||
function identifierKey(provider: string, service: string | number | null, identifier: string | number | null): string {
|
||||
return `${provider}:${service ?? ''}:${identifier ?? ''}`
|
||||
}
|
||||
|
||||
async createCollection(params: {
|
||||
provider: string
|
||||
service: string | number
|
||||
collection?: string | number | null
|
||||
properties: CollectionPropertiesObject
|
||||
}): Promise<CollectionObject> {
|
||||
this.loading = true
|
||||
this.error = null
|
||||
|
||||
try {
|
||||
// Prepare request data from CollectionPropertiesObject
|
||||
const requestData: CollectionCreateRequest = {
|
||||
provider: params.provider,
|
||||
service: params.service,
|
||||
collection: params.collection ?? null,
|
||||
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
|
||||
const response = await collectionService.create(requestData)
|
||||
|
||||
// Create CollectionObject instance
|
||||
const collectionObject = new CollectionObject().fromJson(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) {
|
||||
this.error = error.message
|
||||
throw error
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
},
|
||||
// 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 {
|
||||
const response = await collectionService.list({ sources, filter, sort })
|
||||
|
||||
getters: {
|
||||
collectionList: (state) => {
|
||||
const list: CollectionObject[] = []
|
||||
Object.values(state.collections).forEach(providerCollections => {
|
||||
Object.values(providerCollections).forEach(serviceCollections => {
|
||||
Object.values(serviceCollections).forEach(collection => {
|
||||
list.push(collection)
|
||||
// Flatten nested structure: provider:service:collection -> "provider:service:collection": object
|
||||
const collections: 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
|
||||
})
|
||||
})
|
||||
})
|
||||
return list
|
||||
},
|
||||
|
||||
collectionCount: (state) => {
|
||||
let count = 0
|
||||
Object.values(state.collections).forEach(providerCollections => {
|
||||
Object.values(providerCollections).forEach(serviceCollections => {
|
||||
count += Object.keys(serviceCollections).length
|
||||
})
|
||||
// Merge retrieved collections into state
|
||||
_collections.value = { ..._collections.value, ...collections }
|
||||
|
||||
console.debug('[Mail Manager][Store] - Successfully retrieved', Object.keys(collections).length, 'collections')
|
||||
return collections
|
||||
} catch (error: any) {
|
||||
console.error('[Mail Manager][Store] - Failed to retrieve collections:', error)
|
||||
throw error
|
||||
} finally {
|
||||
transceiving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a specific collection by provider, service, and identifier
|
||||
*
|
||||
* @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 {
|
||||
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,
|
||||
service,
|
||||
collection,
|
||||
properties: data
|
||||
})
|
||||
return count
|
||||
},
|
||||
|
||||
// Merge created collection into state
|
||||
const key = identifierKey(response.provider, response.service, response.identifier)
|
||||
_collections.value[key] = response
|
||||
|
||||
console.debug('[Mail Manager][Store] - Successfully created collection:', key)
|
||||
return response
|
||||
} catch (error: any) {
|
||||
console.error('[Mail Manager][Store] - Failed to create collection:', error)
|
||||
throw error
|
||||
} finally {
|
||||
transceiving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
hasCollections: (state) => {
|
||||
return Object.values(state.collections).some(providerCollections =>
|
||||
Object.values(providerCollections).some(serviceCollections =>
|
||||
Object.keys(serviceCollections).length > 0
|
||||
)
|
||||
)
|
||||
},
|
||||
},
|
||||
/**
|
||||
* 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 {
|
||||
const response = await collectionService.update({
|
||||
provider,
|
||||
service,
|
||||
identifier,
|
||||
properties: data
|
||||
})
|
||||
|
||||
// Merge updated collection into state
|
||||
const key = identifierKey(response.provider, response.service, response.identifier)
|
||||
_collections.value[key] = response
|
||||
|
||||
console.debug('[Mail Manager][Store] - Successfully updated collection:', key)
|
||||
return response
|
||||
} catch (error: any) {
|
||||
console.error('[Mail Manager][Store] - Failed to update collection:', error)
|
||||
throw error
|
||||
} finally {
|
||||
transceiving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a collection by provider, service, and identifier
|
||||
*
|
||||
* @param provider - provider identifier for the collection to delete
|
||||
* @param service - service identifier for the collection to delete
|
||||
* @param identifier - collection identifier for the collection to delete
|
||||
*
|
||||
* @returns Promise with deletion result
|
||||
*/
|
||||
async function remove(provider: string, service: string | number, identifier: string | number): Promise<any> {
|
||||
transceiving.value = true
|
||||
try {
|
||||
await collectionService.delete({ provider, service, identifier })
|
||||
|
||||
// Remove deleted collection from state
|
||||
const key = identifierKey(provider, service, identifier)
|
||||
delete _collections.value[key]
|
||||
|
||||
console.debug('[Mail Manager][Store] - Successfully deleted collection:', key)
|
||||
} catch (error: any) {
|
||||
console.error('[Mail Manager][Store] - Failed to delete collection:', error)
|
||||
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,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,261 +1,369 @@
|
||||
/**
|
||||
* Entities Store
|
||||
*/
|
||||
|
||||
import { ref, computed, readonly } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
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', {
|
||||
state: () => ({
|
||||
messages: {} as Record<string, Record<string, Record<string, Record<string, EntityWrapper<MessageObject>>>>>,
|
||||
signatures: {} as Record<string, Record<string, Record<string, string>>>, // Track delta signatures
|
||||
loading: false,
|
||||
error: null as string | null,
|
||||
}),
|
||||
export const useEntitiesStore = defineStore('mailEntitiesStore', () => {
|
||||
// State
|
||||
const _entities = ref<Record<string, EntityObject>>({})
|
||||
const transceiving = ref(false)
|
||||
|
||||
actions: {
|
||||
async loadMessages(sources?: any, filter?: any, sort?: any, range?: any) {
|
||||
this.loading = true
|
||||
this.error = null
|
||||
try {
|
||||
const response = await entityService.list({ sources, filter, sort, range })
|
||||
|
||||
// Entities come as objects keyed by identifier
|
||||
Object.entries(response).forEach(([provider, providerData]) => {
|
||||
Object.entries(providerData).forEach(([service, serviceData]) => {
|
||||
Object.entries(serviceData).forEach(([collection, entities]) => {
|
||||
if (!this.messages[provider]) {
|
||||
this.messages[provider] = {}
|
||||
}
|
||||
if (!this.messages[provider][service]) {
|
||||
this.messages[provider][service] = {}
|
||||
}
|
||||
if (!this.messages[provider][service][collection]) {
|
||||
this.messages[provider][service][collection] = {}
|
||||
}
|
||||
|
||||
// Entities are already keyed by identifier
|
||||
this.messages[provider][service][collection] = entities as Record<string, EntityWrapper<MessageObject>>
|
||||
})
|
||||
})
|
||||
})
|
||||
} catch (error: any) {
|
||||
this.error = error.message
|
||||
throw error
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Get count of entities in store
|
||||
*/
|
||||
const count = computed(() => Object.keys(_entities.value).length)
|
||||
|
||||
async getMessages(
|
||||
provider: string,
|
||||
service: string | number,
|
||||
collection: string | number,
|
||||
identifiers: (string | number)[],
|
||||
properties?: string[]
|
||||
) {
|
||||
this.loading = true
|
||||
this.error = null
|
||||
try {
|
||||
const response = await entityService.fetch({
|
||||
provider,
|
||||
service,
|
||||
collection,
|
||||
identifiers,
|
||||
properties
|
||||
})
|
||||
|
||||
// Update in store
|
||||
if (!this.messages[provider]) {
|
||||
this.messages[provider] = {}
|
||||
/**
|
||||
* 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
|
||||
}
|
||||
}
|
||||
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>) => {
|
||||
this.messages[provider][String(service)][String(collection)][entity.identifier] = entity
|
||||
})
|
||||
|
||||
return response
|
||||
} catch (error: any) {
|
||||
this.error = error.message
|
||||
throw error
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
list(sources)
|
||||
}
|
||||
|
||||
return collectionEntities
|
||||
}
|
||||
|
||||
async searchMessages(
|
||||
provider: string,
|
||||
service: string | number,
|
||||
query: string,
|
||||
collections?: (string | number)[],
|
||||
filter?: any,
|
||||
sort?: any,
|
||||
range?: any
|
||||
) {
|
||||
this.loading = true
|
||||
this.error = null
|
||||
try {
|
||||
const response = await entityService.search({
|
||||
provider,
|
||||
service,
|
||||
query,
|
||||
collections,
|
||||
filter,
|
||||
sort,
|
||||
range
|
||||
})
|
||||
return response
|
||||
} catch (error: any) {
|
||||
this.error = error.message
|
||||
throw error
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 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}`
|
||||
}
|
||||
|
||||
async sendMessage(request: MessageSendRequest) {
|
||||
this.loading = true
|
||||
this.error = null
|
||||
try {
|
||||
const response = await entityService.send(request)
|
||||
return response
|
||||
} catch (error: any) {
|
||||
this.error = error.message
|
||||
throw error
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
// 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 {
|
||||
const response = await entityService.list({ sources, filter, sort, range })
|
||||
|
||||
async getDelta(sources: any) {
|
||||
this.loading = true
|
||||
this.error = null
|
||||
try {
|
||||
// Sources are already in correct format: { provider: { service: { collection: signature } } }
|
||||
const response = await entityService.delta({ sources })
|
||||
|
||||
// Process delta and update store
|
||||
Object.entries(response).forEach(([provider, providerData]) => {
|
||||
Object.entries(providerData).forEach(([service, serviceData]) => {
|
||||
Object.entries(serviceData).forEach(([collection, collectionData]) => {
|
||||
// Skip if no changes (server returns false or string signature)
|
||||
if (collectionData === false || typeof collectionData === 'string') {
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.messages[provider]) {
|
||||
this.messages[provider] = {}
|
||||
}
|
||||
if (!this.messages[provider][service]) {
|
||||
this.messages[provider][service] = {}
|
||||
}
|
||||
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
|
||||
if (collectionData.created) {
|
||||
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)]
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return response
|
||||
} catch (error: any) {
|
||||
this.error = error.message
|
||||
throw error
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
getters: {
|
||||
messageList: (state) => {
|
||||
const list: EntityWrapper<MessageObject>[] = []
|
||||
Object.values(state.messages).forEach(providerMessages => {
|
||||
Object.values(providerMessages).forEach(serviceMessages => {
|
||||
Object.values(serviceMessages).forEach(collectionMessages => {
|
||||
Object.values(collectionMessages).forEach(message => {
|
||||
list.push(message)
|
||||
// Flatten nested structure: provider:service:collection:entity -> "provider:service:collection:entity": object
|
||||
const entities: Record<string, EntityObject> = {}
|
||||
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||
Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
|
||||
Object.entries(serviceCollections).forEach(([collectionId, collectionEntities]) => {
|
||||
Object.entries(collectionEntities).forEach(([entityId, entityData]) => {
|
||||
const key = identifierKey(providerId, serviceId, collectionId, entityId)
|
||||
entities[key] = entityData
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
return list
|
||||
},
|
||||
|
||||
messageCount: (state) => {
|
||||
let count = 0
|
||||
Object.values(state.messages).forEach(providerMessages => {
|
||||
Object.values(providerMessages).forEach(serviceMessages => {
|
||||
Object.values(serviceMessages).forEach(collectionMessages => {
|
||||
count += Object.keys(collectionMessages).length
|
||||
// Merge retrieved entities into state
|
||||
_entities.value = { ..._entities.value, ...entities }
|
||||
|
||||
console.debug('[Mail Manager][Store] - Successfully retrieved', Object.keys(entities).length, 'entities')
|
||||
return entities
|
||||
} catch (error: any) {
|
||||
console.error('[Mail Manager][Store] - Failed to retrieve entities:', error)
|
||||
throw error
|
||||
} finally {
|
||||
transceiving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve specific entities by provider, service, collection, and identifiers
|
||||
*
|
||||
* @param provider - provider identifier
|
||||
* @param service - service identifier
|
||||
* @param collection - collection identifier
|
||||
* @param identifiers - array of entity identifiers to fetch
|
||||
*
|
||||
* @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 {
|
||||
const response = await entityService.fetch({ provider, service, collection, identifiers })
|
||||
|
||||
// Merge fetched entities into state
|
||||
const entities: Record<string, EntityObject> = {}
|
||||
Object.entries(response).forEach(([identifier, entityData]) => {
|
||||
const key = identifierKey(provider, service, collection, identifier)
|
||||
entities[key] = entityData
|
||||
_entities.value[key] = entityData
|
||||
})
|
||||
|
||||
console.debug('[Mail Manager][Store] - Successfully fetched', Object.keys(entities).length, 'entities')
|
||||
return entities
|
||||
} catch (error: any) {
|
||||
console.error('[Mail Manager][Store] - Failed to fetch entities:', error)
|
||||
throw error
|
||||
} finally {
|
||||
transceiving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve entity availability status for a given source selector
|
||||
*
|
||||
* @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
|
||||
} catch (error: any) {
|
||||
console.error('[Mail Manager][Store] - Failed to check entity availability:', error)
|
||||
throw error
|
||||
} finally {
|
||||
transceiving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new entity with given provider, service, collection, and data
|
||||
*
|
||||
* @param provider - provider identifier for the new entity
|
||||
* @param service - service identifier for the new entity
|
||||
* @param collection - collection identifier for the new entity
|
||||
* @param data - entity properties for creation
|
||||
*
|
||||
* @returns Promise with created entity object
|
||||
*/
|
||||
async function create(provider: string, service: string | number, collection: string | number, data: any): Promise<EntityObject> {
|
||||
transceiving.value = true
|
||||
try {
|
||||
const response = await entityService.create({ provider, service, collection, properties: data })
|
||||
|
||||
// Add created entity to state
|
||||
const key = identifierKey(response.provider, response.service, response.collection, response.identifier)
|
||||
_entities.value[key] = response
|
||||
|
||||
console.debug('[Mail Manager][Store] - Successfully created entity:', key)
|
||||
return response
|
||||
} catch (error: any) {
|
||||
console.error('[Mail Manager][Store] - Failed to create entity:', error)
|
||||
throw error
|
||||
} finally {
|
||||
transceiving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing entity with given provider, service, collection, identifier, and data
|
||||
*
|
||||
* @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 {
|
||||
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
|
||||
} catch (error: any) {
|
||||
console.error('[Mail Manager][Store] - Failed to update entity:', error)
|
||||
throw error
|
||||
} finally {
|
||||
transceiving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an entity by provider, service, collection, and identifier
|
||||
*
|
||||
* @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 {
|
||||
const response = await entityService.delta({ sources })
|
||||
|
||||
// Process delta and update store
|
||||
Object.entries(response).forEach(([provider, providerData]) => {
|
||||
// Skip if no changes for provider
|
||||
if (providerData === false) return
|
||||
|
||||
Object.entries(providerData).forEach(([service, serviceData]) => {
|
||||
// Skip if no changes for service
|
||||
if (serviceData === false) return
|
||||
|
||||
Object.entries(serviceData).forEach(([collection, collectionData]) => {
|
||||
// Skip if no changes for collection
|
||||
if (collectionData === false) return
|
||||
|
||||
// Process deletions (remove from store)
|
||||
if (collectionData.deletions && collectionData.deletions.length > 0) {
|
||||
collectionData.deletions.forEach((identifier) => {
|
||||
const key = identifierKey(provider, service, collection, identifier)
|
||||
delete _entities.value[key]
|
||||
})
|
||||
}
|
||||
|
||||
// Note: additions and modifications contain only identifiers
|
||||
// The caller should fetch full entities using the fetch() method
|
||||
})
|
||||
})
|
||||
})
|
||||
return count
|
||||
},
|
||||
|
||||
hasMessages: (state) => {
|
||||
return Object.values(state.messages).some(providerMessages =>
|
||||
Object.values(providerMessages).some(serviceMessages =>
|
||||
Object.values(serviceMessages).some(collectionMessages =>
|
||||
Object.keys(collectionMessages).length > 0
|
||||
)
|
||||
)
|
||||
)
|
||||
},
|
||||
},
|
||||
console.debug('[Mail Manager][Store] - Successfully processed delta changes')
|
||||
return response
|
||||
} catch (error: any) {
|
||||
console.error('[Mail Manager][Store] - Failed to process delta:', error)
|
||||
throw error
|
||||
} finally {
|
||||
transceiving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send/transmit an entity
|
||||
*
|
||||
* @param request - transmit request parameters
|
||||
*
|
||||
* @returns Promise with transmission result
|
||||
*/
|
||||
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 response
|
||||
} catch (error: any) {
|
||||
console.error('[Mail Manager][Store] - Failed to transmit entity:', error)
|
||||
throw error
|
||||
} finally {
|
||||
transceiving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Return public API
|
||||
return {
|
||||
// State (readonly)
|
||||
transceiving: readonly(transceiving),
|
||||
// Getters
|
||||
count,
|
||||
has,
|
||||
entities,
|
||||
entitiesForCollection,
|
||||
// Actions
|
||||
entity,
|
||||
list,
|
||||
fetch,
|
||||
extant,
|
||||
create,
|
||||
update,
|
||||
delete: remove,
|
||||
delta,
|
||||
transmit,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -12,59 +12,60 @@ export const useProvidersStore = defineStore('mailProvidersStore', () => {
|
||||
// State
|
||||
const _providers = ref<Record<string, ProviderObject>>({})
|
||||
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)
|
||||
|
||||
/**
|
||||
* Check if any providers are present in store
|
||||
*/
|
||||
const has = computed(() => count.value > 0)
|
||||
|
||||
/**
|
||||
* Get providers as an array
|
||||
* @returns Array of provider objects
|
||||
* Get all providers present in store
|
||||
*/
|
||||
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 retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
|
||||
*
|
||||
* @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
|
||||
}
|
||||
|
||||
// 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>> {
|
||||
transceiving.value = true
|
||||
error.value = null
|
||||
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
|
||||
return response
|
||||
} 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 })
|
||||
console.debug('[Mail Manager][Store] - Successfully retrieved', Object.keys(providers).length, 'providers')
|
||||
return providers
|
||||
} 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
|
||||
} finally {
|
||||
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) {
|
||||
transceiving.value = true
|
||||
error.value = null
|
||||
try {
|
||||
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
|
||||
} catch (err: any) {
|
||||
console.error('[Mail Manager](Store) - Failed to check providers:', err)
|
||||
error.value = err.message
|
||||
throw err
|
||||
} catch (error: any) {
|
||||
console.error('[Mail Manager][Store] - Failed to check providers:', error)
|
||||
throw error
|
||||
} finally {
|
||||
transceiving.value = false
|
||||
}
|
||||
@@ -94,7 +129,6 @@ export const useProvidersStore = defineStore('mailProvidersStore', () => {
|
||||
return {
|
||||
// State
|
||||
transceiving: readonly(transceiving),
|
||||
error: readonly(error),
|
||||
// computed
|
||||
count,
|
||||
has,
|
||||
|
||||
@@ -10,27 +10,31 @@ import type {
|
||||
ServiceLocation,
|
||||
SourceSelector,
|
||||
ServiceIdentity,
|
||||
ServiceInterface,
|
||||
} from '../types'
|
||||
|
||||
export const useServicesStore = defineStore('mailServicesStore', () => {
|
||||
// State
|
||||
const _services = ref<Record<string, ServiceObject>>({})
|
||||
const transceiving = ref(false)
|
||||
const lastTestResult = ref<any>(null)
|
||||
|
||||
// Getters
|
||||
/**
|
||||
* Get count of services in store
|
||||
*/
|
||||
const count = computed(() => Object.keys(_services.value).length)
|
||||
|
||||
/**
|
||||
* Check if any services are present in store
|
||||
*/
|
||||
const has = computed(() => count.value > 0)
|
||||
|
||||
/**
|
||||
* Get services as an array
|
||||
* @returns Array of service objects
|
||||
* Get all services present in store
|
||||
*/
|
||||
const services = computed(() => Object.values(_services.value))
|
||||
|
||||
/**
|
||||
* Get services grouped by provider
|
||||
* @returns Services grouped by provider ID
|
||||
* Get all services present in store grouped by provider
|
||||
*/
|
||||
const servicesByProvider = computed(() => {
|
||||
const groups: Record<string, ServiceObject[]> = {}
|
||||
@@ -45,9 +49,60 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
|
||||
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>> {
|
||||
transceiving.value = true
|
||||
@@ -55,20 +110,21 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
|
||||
const response = await serviceService.list({ sources })
|
||||
|
||||
// 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(providerServices).forEach(([_serviceId, serviceObj]) => {
|
||||
const key = `${serviceObj.provider}:${serviceObj.identifier}`
|
||||
flattened[key] = serviceObj
|
||||
const key = identifierKey(serviceObj.provider, serviceObj.identifier)
|
||||
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
|
||||
return flattened
|
||||
console.debug('[Mail Manager][Store] - Successfully retrieved', Object.keys(services).length, 'services')
|
||||
return services
|
||||
} 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
|
||||
} finally {
|
||||
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> {
|
||||
transceiving.value = true
|
||||
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) {
|
||||
console.error('[Mail Manager](Store) - Failed to fetch service:', error)
|
||||
console.error('[Mail Manager][Store] - Failed to fetch service:', error)
|
||||
throw error
|
||||
} finally {
|
||||
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(
|
||||
identity: string,
|
||||
@@ -105,16 +281,27 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
|
||||
|
||||
try {
|
||||
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
|
||||
} 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
|
||||
} finally {
|
||||
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(
|
||||
provider: string,
|
||||
identifier?: string | number | null,
|
||||
@@ -124,62 +311,11 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
|
||||
transceiving.value = true
|
||||
try {
|
||||
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
|
||||
} catch (error: any) {
|
||||
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)
|
||||
console.error('[Mail Manager][Store] - Failed to test service:', error)
|
||||
throw error
|
||||
} finally {
|
||||
transceiving.value = false
|
||||
@@ -190,7 +326,6 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
|
||||
return {
|
||||
// State (readonly)
|
||||
transceiving: readonly(transceiving),
|
||||
lastTestResult: readonly(lastTestResult),
|
||||
// Getters
|
||||
count,
|
||||
has,
|
||||
@@ -198,12 +333,15 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
|
||||
servicesByProvider,
|
||||
|
||||
// Actions
|
||||
service,
|
||||
serviceForAddress,
|
||||
list,
|
||||
fetch,
|
||||
discover,
|
||||
test,
|
||||
extant,
|
||||
create,
|
||||
update,
|
||||
delete: remove,
|
||||
discover,
|
||||
test,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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 {
|
||||
provider: string;
|
||||
@@ -22,41 +22,29 @@ export interface CollectionBaseProperties {
|
||||
version: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Immutable collection properties (computed by server)
|
||||
*/
|
||||
export interface CollectionImmutableProperties extends CollectionBaseProperties {
|
||||
total?: number;
|
||||
unread?: number;
|
||||
role?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutable collection properties (can be modified by user)
|
||||
*/
|
||||
export interface CollectionMutableProperties extends CollectionBaseProperties {
|
||||
label: string;
|
||||
rank?: number;
|
||||
subscribed?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Full collection properties (what server returns)
|
||||
*/
|
||||
export interface CollectionPropertiesInterface extends CollectionMutableProperties, CollectionImmutableProperties {}
|
||||
|
||||
/**
|
||||
* Collection list request
|
||||
* Collection list
|
||||
*/
|
||||
export interface CollectionListRequest {
|
||||
sources?: SourceSelector;
|
||||
filter?: any;
|
||||
sort?: any;
|
||||
filter?: ListFilter;
|
||||
sort?: ListSort;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection list response
|
||||
*/
|
||||
export interface CollectionListResponse {
|
||||
[providerId: 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 {
|
||||
sources: SourceSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection extant response
|
||||
*/
|
||||
export interface CollectionExtantResponse {
|
||||
[providerId: string]: {
|
||||
[serviceId: string]: {
|
||||
@@ -84,21 +80,7 @@ export interface CollectionExtantResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection fetch request
|
||||
*/
|
||||
export interface CollectionFetchRequest {
|
||||
provider: string;
|
||||
service: string | number;
|
||||
collection: string | number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection fetch response
|
||||
*/
|
||||
export interface CollectionFetchResponse extends CollectionInterface {}
|
||||
|
||||
/**
|
||||
* Collection create request
|
||||
* Collection create
|
||||
*/
|
||||
export interface CollectionCreateRequest {
|
||||
provider: string;
|
||||
@@ -107,42 +89,33 @@ export interface CollectionCreateRequest {
|
||||
properties: CollectionMutableProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection create response
|
||||
*/
|
||||
export interface CollectionCreateResponse extends CollectionInterface {}
|
||||
|
||||
/**
|
||||
* Collection modify request
|
||||
* Collection modify
|
||||
*/
|
||||
export interface CollectionModifyRequest {
|
||||
export interface CollectionUpdateRequest {
|
||||
provider: string;
|
||||
service: string | number;
|
||||
identifier: string | number;
|
||||
properties: CollectionMutableProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection modify response
|
||||
*/
|
||||
export interface CollectionModifyResponse extends CollectionInterface {}
|
||||
export interface CollectionUpdateResponse extends CollectionInterface {}
|
||||
|
||||
/**
|
||||
* Collection destroy request
|
||||
* Collection delete
|
||||
*/
|
||||
export interface CollectionDestroyRequest {
|
||||
export interface CollectionDeleteRequest {
|
||||
provider: string;
|
||||
service: string | number;
|
||||
identifier: string | number;
|
||||
options?: {
|
||||
force?: boolean; // Whether to force destroy even if collection is not empty
|
||||
recursive?: boolean; // Whether to destroy child collections/items as well
|
||||
force?: boolean; // Whether to force delete even if collection is not empty
|
||||
recursive?: boolean; // Whether to delete child collections/items as well
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Collection destroy response
|
||||
*/
|
||||
export interface CollectionDestroyResponse {
|
||||
export interface CollectionDeleteResponse {
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* Source selector structure for hierarchical resource selection
|
||||
* Structure: Provider -> Service -> Collection -> Message
|
||||
* Selector for targeting specific providers, services, collections, or entities in list or extant operations.
|
||||
*
|
||||
* 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 = {
|
||||
[provider: string]: boolean | ServiceSelector;
|
||||
@@ -56,38 +67,90 @@ export type ServiceSelector = {
|
||||
};
|
||||
|
||||
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 {
|
||||
field: string;
|
||||
operator: string;
|
||||
value: any;
|
||||
}
|
||||
export const ListFilterComparisonOperator = {
|
||||
EQ: 1, // Equal
|
||||
NEQ: 2, // Not Equal
|
||||
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 {
|
||||
[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 {
|
||||
[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 {
|
||||
start: number;
|
||||
limit: number;
|
||||
}
|
||||
type: 'tally';
|
||||
anchor: 'relative' | 'absolute';
|
||||
position: string | number;
|
||||
tally: number;
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
/**
|
||||
* Entity wrapper with metadata
|
||||
* Entity definition
|
||||
*/
|
||||
export interface EntityInterface<T = MessageInterface> {
|
||||
provider: string;
|
||||
@@ -19,18 +19,15 @@ export interface EntityInterface<T = MessageInterface> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity list request
|
||||
* Entity list
|
||||
*/
|
||||
export interface EntityListRequest {
|
||||
sources?: SourceSelector;
|
||||
filter?: any;
|
||||
sort?: any;
|
||||
range?: { start: number; limit: number };
|
||||
filter?: ListFilter;
|
||||
sort?: ListSort;
|
||||
range?: ListRange;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity list response
|
||||
*/
|
||||
export interface EntityListResponse {
|
||||
[providerId: string]: {
|
||||
[serviceId: string]: {
|
||||
@@ -42,68 +39,38 @@ export interface EntityListResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity delta request
|
||||
*/
|
||||
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
|
||||
* Entity fetch
|
||||
*/
|
||||
export interface EntityFetchRequest {
|
||||
provider: string;
|
||||
service: string | number;
|
||||
collection: string | number;
|
||||
identifiers: (string | number)[];
|
||||
properties?: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity fetch response
|
||||
*/
|
||||
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> {
|
||||
provider: string;
|
||||
@@ -112,17 +79,12 @@ export interface EntityCreateRequest<T = MessageInterface> {
|
||||
properties: T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity create response
|
||||
*/
|
||||
export interface EntityCreateResponse<T = MessageInterface> {
|
||||
entity: EntityInterface<T>;
|
||||
}
|
||||
export interface EntityCreateResponse<T = MessageInterface> extends EntityInterface<T> {}
|
||||
|
||||
/**
|
||||
* Entity modify request
|
||||
* Entity update
|
||||
*/
|
||||
export interface EntityModifyRequest<T = MessageInterface> {
|
||||
export interface EntityUpdateRequest<T = MessageInterface> {
|
||||
provider: string;
|
||||
service: string | number;
|
||||
collection: string | number;
|
||||
@@ -130,35 +92,46 @@ export interface EntityModifyRequest<T = MessageInterface> {
|
||||
properties: T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity modify response
|
||||
*/
|
||||
export interface EntityModifyResponse<T = MessageInterface> {
|
||||
success: boolean;
|
||||
entity?: EntityInterface<T>;
|
||||
}
|
||||
export interface EntityUpdateResponse<T = MessageInterface> extends EntityInterface<T> {}
|
||||
|
||||
/**
|
||||
* Entity destroy request
|
||||
* Entity delete
|
||||
*/
|
||||
export interface EntityDestroyRequest {
|
||||
export interface EntityDeleteRequest {
|
||||
provider: string;
|
||||
service: string | number;
|
||||
collection: string | number;
|
||||
identifier: string | number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity destroy response
|
||||
*/
|
||||
export interface EntityDestroyResponse {
|
||||
export interface EntityDeleteResponse {
|
||||
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: {
|
||||
from?: string;
|
||||
to: string[];
|
||||
@@ -181,10 +154,7 @@ export interface EntitySendRequest {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Entity send response
|
||||
*/
|
||||
export interface EntitySendResponse {
|
||||
export interface EntityTransmitResponse {
|
||||
id: string;
|
||||
status: 'queued' | 'sent';
|
||||
}
|
||||
@@ -29,41 +29,32 @@ export interface ProviderInterface {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider list request
|
||||
* Provider list
|
||||
*/
|
||||
export interface ProviderListRequest {
|
||||
sources?: SourceSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider list response
|
||||
*/
|
||||
export interface ProviderListResponse {
|
||||
[identifier: string]: ProviderInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider fetch request
|
||||
* Provider fetch
|
||||
*/
|
||||
export interface ProviderFetchRequest {
|
||||
identifier: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider fetch response
|
||||
*/
|
||||
export interface ProviderFetchResponse extends ProviderInterface {}
|
||||
|
||||
/**
|
||||
* Provider extant request
|
||||
* Provider extant
|
||||
*/
|
||||
export interface ProviderExtantRequest {
|
||||
sources: SourceSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provider extant response
|
||||
*/
|
||||
export interface ProviderExtantResponse {
|
||||
[identifier: string]: boolean;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Service-related type definitions
|
||||
* Service type definitions
|
||||
*/
|
||||
import type { SourceSelector } from './common';
|
||||
import type { SourceSelector, ListFilterComparisonOperator } from './common';
|
||||
|
||||
/**
|
||||
* Service capabilities
|
||||
@@ -9,29 +9,29 @@ import type { SourceSelector } from './common';
|
||||
export interface ServiceCapabilitiesInterface {
|
||||
// Collection capabilities
|
||||
CollectionList?: boolean;
|
||||
CollectionListFilter?: boolean | { [field: string]: string };
|
||||
CollectionListSort?: boolean | string[];
|
||||
CollectionListFilter?: ServiceListFilterCollection;
|
||||
CollectionListSort?: ServiceListSortCollection;
|
||||
CollectionExtant?: boolean;
|
||||
CollectionFetch?: boolean;
|
||||
CollectionCreate?: boolean;
|
||||
CollectionModify?: boolean;
|
||||
CollectionUpdate?: boolean;
|
||||
CollectionDelete?: boolean;
|
||||
// Message capabilities
|
||||
EntityList?: boolean;
|
||||
EntityListFilter?: boolean | { [field: string]: string };
|
||||
EntityListSort?: boolean | string[];
|
||||
EntityListRange?: boolean | { tally?: string[] };
|
||||
EntityListFilter?: ServiceListFilterEntity;
|
||||
EntityListSort?: ServiceListSortEntity;
|
||||
EntityListRange?: ServiceListRange;
|
||||
EntityDelta?: boolean;
|
||||
EntityExtant?: boolean;
|
||||
EntityFetch?: boolean;
|
||||
EntityCreate?: boolean;
|
||||
EntityModify?: boolean;
|
||||
EntityUpdate?: boolean;
|
||||
EntityDelete?: boolean;
|
||||
EntityMove?: boolean;
|
||||
EntityCopy?: boolean;
|
||||
// Send capability
|
||||
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 {
|
||||
sources?: SourceSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Service list response
|
||||
*/
|
||||
export interface ServiceListResponse {
|
||||
[provider: string]: {
|
||||
[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 {
|
||||
sources: SourceSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Service extant response
|
||||
*/
|
||||
export interface ServiceExtantResponse {
|
||||
[provider: string]: {
|
||||
[identifier: string]: boolean;
|
||||
@@ -84,45 +88,17 @@ export interface ServiceExtantResponse {
|
||||
}
|
||||
|
||||
/**
|
||||
* Service fetch request
|
||||
*/
|
||||
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
|
||||
* Service create
|
||||
*/
|
||||
export interface ServiceCreateRequest {
|
||||
provider: string;
|
||||
data: Partial<ServiceInterface>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Service create response
|
||||
*/
|
||||
export interface ServiceCreateResponse extends ServiceInterface {}
|
||||
|
||||
/**
|
||||
* Service update request
|
||||
* Service update
|
||||
*/
|
||||
export interface ServiceUpdateRequest {
|
||||
provider: string;
|
||||
@@ -130,29 +106,20 @@ export interface ServiceUpdateRequest {
|
||||
data: Partial<ServiceInterface>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Service update response
|
||||
*/
|
||||
export interface ServiceUpdateResponse extends ServiceInterface {}
|
||||
|
||||
/**
|
||||
* Service delete request
|
||||
* Service delete
|
||||
*/
|
||||
export interface ServiceDeleteRequest {
|
||||
provider: string;
|
||||
identifier: string | number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Service delete response
|
||||
*/
|
||||
export interface ServiceDeleteResponse {}
|
||||
|
||||
// ==================== Discovery Types ====================
|
||||
|
||||
/**
|
||||
* Service discovery request - NEW VERSION
|
||||
* Supports identity-based discovery with optional hints
|
||||
* Service discovery
|
||||
*/
|
||||
export interface ServiceDiscoverRequest {
|
||||
identity: string; // Email address or domain
|
||||
@@ -161,42 +128,36 @@ export interface ServiceDiscoverRequest {
|
||||
secret?: string; // Optional: password/token for credential validation
|
||||
}
|
||||
|
||||
/**
|
||||
* Service discovery response - NEW VERSION
|
||||
* Provider-keyed map of discovered service locations
|
||||
*/
|
||||
export interface ServiceDiscoverResponse {
|
||||
[provider: string]: ServiceLocation; // Uses existing ServiceLocation discriminated union
|
||||
}
|
||||
|
||||
/**
|
||||
* Discovery status tracking for real-time UI updates
|
||||
* Used by store to track per-provider discovery progress
|
||||
* Service connection test
|
||||
*/
|
||||
export interface ProviderDiscoveryStatus {
|
||||
export interface ServiceTestRequest {
|
||||
provider: string;
|
||||
status: 'pending' | 'discovering' | 'success' | 'failed';
|
||||
location?: ServiceLocation;
|
||||
error?: string;
|
||||
metadata?: {
|
||||
host?: string;
|
||||
port?: number;
|
||||
protocol?: string;
|
||||
};
|
||||
// For existing service
|
||||
identifier?: string | number | null;
|
||||
// For fresh configuration
|
||||
location?: ServiceLocation | null;
|
||||
identity?: ServiceIdentity | null;
|
||||
}
|
||||
|
||||
// ==================== Service Testing Types ====================
|
||||
export interface ServiceTestResponse {
|
||||
success: boolean;
|
||||
message: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Base service location interface
|
||||
* Service location - Base
|
||||
*/
|
||||
export interface ServiceLocationBase {
|
||||
type: 'URI' | 'SOCKET_SOLE' | 'SOCKET_SPLIT' | 'FILE';
|
||||
}
|
||||
|
||||
/**
|
||||
* URI-based service location for API and web services
|
||||
* Used by: JMAP, Gmail API, etc.
|
||||
* Service location - URI-based type
|
||||
*/
|
||||
export interface ServiceLocationUri extends ServiceLocationBase {
|
||||
type: 'URI';
|
||||
@@ -209,8 +170,7 @@ export interface ServiceLocationUri extends ServiceLocationBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Single socket-based service location
|
||||
* Used by: services using a single host/port combination
|
||||
* Service location - Single socket-based type (combined inbound/outbound configuration)
|
||||
*/
|
||||
export interface ServiceLocationSocketSole extends ServiceLocationBase {
|
||||
type: 'SOCKET_SOLE';
|
||||
@@ -222,8 +182,7 @@ export interface ServiceLocationSocketSole extends ServiceLocationBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Split socket-based service location
|
||||
* Used by: traditional IMAP/SMTP configurations
|
||||
* Service location - Split socket-based type (separate inbound/outbound configurations)
|
||||
*/
|
||||
export interface ServiceLocationSocketSplit extends ServiceLocationBase {
|
||||
type: 'SOCKET_SPLIT';
|
||||
@@ -240,8 +199,7 @@ export interface ServiceLocationSocketSplit extends ServiceLocationBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* File-based service location
|
||||
* Used by: local file system providers
|
||||
* Service location - File-based type (e.g., for local mail delivery or Unix socket)
|
||||
*/
|
||||
export interface ServiceLocationFile extends ServiceLocationBase {
|
||||
type: 'FILE';
|
||||
@@ -249,7 +207,7 @@ export interface ServiceLocationFile extends ServiceLocationBase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Discriminated union of all service location types
|
||||
* Service location types
|
||||
*/
|
||||
export type ServiceLocation =
|
||||
| ServiceLocationUri
|
||||
@@ -257,24 +215,22 @@ export type ServiceLocation =
|
||||
| ServiceLocationSocketSplit
|
||||
| ServiceLocationFile;
|
||||
|
||||
// ==================== Service Identity Types ====================
|
||||
|
||||
/**
|
||||
* Base service identity interface
|
||||
* Service identity - base
|
||||
*/
|
||||
export interface ServiceIdentityBase {
|
||||
type: 'NA' | 'BA' | 'TA' | 'OA' | 'CC';
|
||||
}
|
||||
|
||||
/**
|
||||
* No authentication
|
||||
* Service identity - No authentication
|
||||
*/
|
||||
export interface ServiceIdentityNone extends ServiceIdentityBase {
|
||||
type: 'NA';
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic authentication (username/password)
|
||||
* Service identity - Basic authentication type
|
||||
*/
|
||||
export interface ServiceIdentityBasic extends ServiceIdentityBase {
|
||||
type: 'BA';
|
||||
@@ -324,21 +280,58 @@ export type ServiceIdentity =
|
||||
| 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 {
|
||||
provider: string;
|
||||
// For existing service
|
||||
identifier?: string | number | null;
|
||||
// For fresh configuration
|
||||
location?: ServiceLocation | null;
|
||||
identity?: ServiceIdentity | null;
|
||||
export type ServiceListFilterCollection = {
|
||||
'label'?: string;
|
||||
'rank'?: string;
|
||||
[attribute: string]: string | undefined;
|
||||
};
|
||||
|
||||
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 {
|
||||
success: boolean;
|
||||
message: string;
|
||||
export type ServiceListSortCollection = ("label" | "rank" | string)[];
|
||||
export type ServiceListSortEntity = ("from" | "to" | "subject" | "received" | "sent" | "size" | string)[];
|
||||
|
||||
export type ServiceListRange = {
|
||||
'tally'?: string[];
|
||||
};
|
||||
|
||||
|
||||
export interface ServiceListFilterDefinition {
|
||||
type: 'string' | 'integer' | 'date' | 'boolean' | 'array';
|
||||
length: number;
|
||||
defaultComparator: ListFilterComparisonOperator;
|
||||
supportedComparators: ListFilterComparisonOperator[];
|
||||
}
|
||||
|
||||
@@ -1,276 +1,61 @@
|
||||
/**
|
||||
* Helper functions for working with service identity and location types
|
||||
* Helper functions for working with service types
|
||||
*/
|
||||
|
||||
import type {
|
||||
ServiceIdentity,
|
||||
ServiceIdentityNone,
|
||||
ServiceIdentityBasic,
|
||||
ServiceIdentityToken,
|
||||
ServiceIdentityOAuth,
|
||||
ServiceIdentityCertificate,
|
||||
ServiceLocation,
|
||||
ServiceLocationUri,
|
||||
ServiceLocationSocketSole,
|
||||
ServiceLocationSocketSplit,
|
||||
ServiceLocationFile
|
||||
} from '@/types/service';
|
||||
|
||||
// ==================== Identity Helpers ====================
|
||||
import type { ServiceListFilterDefinition } from '@/types/service';
|
||||
import { ListFilterComparisonOperator } from '@/types/common';
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
return { type: 'NA' };
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Basic Auth identity
|
||||
*/
|
||||
export function createIdentityBasic(identity: string, secret: string): ServiceIdentityBasic {
|
||||
return {
|
||||
type: 'BA',
|
||||
identity,
|
||||
secret
|
||||
export function parseFilterSpec(spec: string): ServiceListFilterDefinition {
|
||||
const [typeCode, lengthStr, defaultComparatorStr, supportedComparatorsStr] = spec.split(':');
|
||||
|
||||
const typeMap: Record<string, ServiceListFilterDefinition['type']> = {
|
||||
's': 'string',
|
||||
'i': 'integer',
|
||||
'd': 'date',
|
||||
'b': 'boolean',
|
||||
'a': 'array',
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
const type = typeMap[typeCode];
|
||||
if (!type) {
|
||||
throw new Error(`Invalid filter type code: ${typeCode}`);
|
||||
}
|
||||
): ServiceIdentityOAuth {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'OA',
|
||||
accessToken,
|
||||
...options
|
||||
type,
|
||||
length,
|
||||
defaultComparator,
|
||||
supportedComparators,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 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';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user