refactor: service address
Build Test / test (pull_request) Successful in 37s
JS Unit Tests / test (pull_request) Failing after 37s
PHP Unit Tests / test (pull_request) Successful in 59s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-06-16 13:31:23 -04:00
parent 0e4bd905a2
commit bea7c1d0fb
10 changed files with 168 additions and 44 deletions
+11 -21
View File
@@ -50,8 +50,6 @@ class DefaultController extends ControllerAbstract {
private const ERR_INVALID_TARGETS = 'Invalid parameter: targets must be an array'; private const ERR_INVALID_TARGETS = 'Invalid parameter: targets must be an array';
private const ERR_INVALID_DATA = 'Invalid parameter: data must be an array'; private const ERR_INVALID_DATA = 'Invalid parameter: data must be an array';
private const STREAM_FLUSH_INTERVAL = 1;
public function __construct( public function __construct(
private readonly SessionTenant $tenantIdentity, private readonly SessionTenant $tenantIdentity,
private readonly SessionIdentity $userIdentity, private readonly SessionIdentity $userIdentity,
@@ -162,7 +160,7 @@ class DefaultController extends ControllerAbstract {
'entity.patch' => $this->entityPatch($tenantId, $userId, $data), 'entity.patch' => $this->entityPatch($tenantId, $userId, $data),
'entity.move' => $this->entityMove($tenantId, $userId, $data), 'entity.move' => $this->entityMove($tenantId, $userId, $data),
'entity.copy' => throw new InvalidArgumentException('Operation not implemented: ' . $operation), 'entity.copy' => throw new InvalidArgumentException('Operation not implemented: ' . $operation),
'entity.transmit' => $this->entityTransmit($tenantId, $userId, $data), 'entity.submit' => $this->entitySubmit($tenantId, $userId, $data),
'entity.download' => $this->entityDownload($tenantId, $userId, $data), 'entity.download' => $this->entityDownload($tenantId, $userId, $data),
default => throw new InvalidArgumentException(self::ERR_INVALID_OPERATION . $operation) default => throw new InvalidArgumentException(self::ERR_INVALID_OPERATION . $operation)
@@ -839,29 +837,21 @@ class DefaultController extends ControllerAbstract {
return $this->mailManager->entityMove($tenantId, $userId, $target, ...$sources->all()); return $this->mailManager->entityMove($tenantId, $userId, $target, ...$sources->all());
} }
private function entityTransmit(string $tenantId, string $userId, array $data): mixed { private function entitySubmit(string $tenantId, string $userId, array $data): mixed {
if (!isset($data['provider'])) { if (!isset($data['sender'])) {
throw new InvalidArgumentException(self::ERR_MISSING_PROVIDER); throw new InvalidArgumentException(self::ERR_MISSING_SENDER);
} }
if (!is_string($data['provider'])) { if (!is_string($data['sender'])) {
throw new InvalidArgumentException(self::ERR_INVALID_PROVIDER); throw new InvalidArgumentException(self::ERR_INVALID_SENDER);
} }
if (!isset($data['service'])) {
throw new InvalidArgumentException(self::ERR_MISSING_SERVICE); return $this->mailManager->entitySubmit(
}
if (!is_string($data['service'])) {
throw new InvalidArgumentException(self::ERR_INVALID_SERVICE);
}
$jobId = $this->mailManager->entityTransmit(
$tenantId, $tenantId,
$userId, $userId,
$data['provider'], $data['sender'],
$data['service'], $data['source'] ?? null,
$data['data'] $data['message'] ?? null,
); );
return ['jobId' => $jobId];
} }
private function entityDownload(string $tenantId, string $userId, array $data): mixed { private function entityDownload(string $tenantId, string $userId, array $data): mixed {
+30 -2
View File
@@ -10,6 +10,8 @@ use KTXF\Mail\Collection\CollectionBaseInterface;
use KTXF\Mail\Collection\CollectionPropertiesMutableInterface; use KTXF\Mail\Collection\CollectionPropertiesMutableInterface;
use KTXF\Mail\Collection\ICollectionBase; use KTXF\Mail\Collection\ICollectionBase;
use KTXF\Mail\Entity\IMessageBase; use KTXF\Mail\Entity\IMessageBase;
use KTXF\Mail\Object\Address;
use KTXF\Mail\Object\AddressInterface;
use KTXF\Mail\Object\MessagePropertiesMutableInterface; use KTXF\Mail\Object\MessagePropertiesMutableInterface;
use KTXF\Mail\Provider\ProviderBaseInterface; use KTXF\Mail\Provider\ProviderBaseInterface;
use KTXF\Mail\Provider\ProviderServiceDiscoverInterface; use KTXF\Mail\Provider\ProviderServiceDiscoverInterface;
@@ -19,11 +21,14 @@ use KTXF\Mail\Service\ServiceBaseInterface;
use KTXF\Mail\Service\ServiceCollectionMutableInterface; use KTXF\Mail\Service\ServiceCollectionMutableInterface;
use KTXF\Mail\Service\ServiceConfigurableInterface; use KTXF\Mail\Service\ServiceConfigurableInterface;
use KTXF\Mail\Service\ServiceEntityMutableInterface; use KTXF\Mail\Service\ServiceEntityMutableInterface;
use KTXF\Mail\Service\ServiceEntitySubmitInterface;
use KTXF\Mail\Service\ServiceMutableInterface; use KTXF\Mail\Service\ServiceMutableInterface;
use KTXF\Mail\Submission\EntitySubmitResult;
use KTXF\Resource\BinaryResource; use KTXF\Resource\BinaryResource;
use KTXF\Resource\Filter\IFilter; use KTXF\Resource\Filter\IFilter;
use KTXF\Resource\Identifier\CollectionIdentifier; use KTXF\Resource\Identifier\CollectionIdentifier;
use KTXF\Resource\Identifier\EntityIdentifier; use KTXF\Resource\Identifier\EntityIdentifier;
use KTXF\Resource\Identifier\EntityIdentifierInterface;
use KTXF\Resource\Identifier\ResourceIdentifiers; use KTXF\Resource\Identifier\ResourceIdentifiers;
use KTXF\Resource\Provider\ResourceServiceIdentityInterface; use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
use KTXF\Resource\Provider\ResourceServiceLocationInterface; use KTXF\Resource\Provider\ResourceServiceLocationInterface;
@@ -796,7 +801,7 @@ class Manager {
} }
// retrieve entities for each collection // retrieve entities for each collection
foreach ($collectionSelected as $collectionId) { foreach ($collectionSelected as $collectionId) {
$entities = $service->entityList($collectionId, $entityFilter, $entitySort, $entityRange, null); $entities = $service->entityListBulk($collectionId, $entityFilter, $entitySort, $entityRange, null);
// skip collections with no entities // skip collections with no entities
if ($entities === []) { if ($entities === []) {
continue; continue;
@@ -905,7 +910,7 @@ class Manager {
// group identifiers by provider/service // group identifiers by provider/service
$groupedIdentifiers = []; $groupedIdentifiers = [];
foreach ($identifiers as $identifier) { foreach ($identifiers as $identifier) {
$groupedIdentifiers[$identifier->provider()][$identifier->service()][] = $identifier->entity(); $groupedIdentifiers[$identifier->provider()][$identifier->service()][] = $identifier;
} }
// retrieve each service and fetch entities // retrieve each service and fetch entities
$list = []; $list = [];
@@ -1302,4 +1307,27 @@ class Manager {
return $operationOutcome; return $operationOutcome;
} }
public function entitySubmit(string $tenantId, string $userId, AddressInterface|string $sender, EntityIdentifierInterface|null $source = null, MessagePropertiesMutableInterface|array|null $message = null): EntitySubmitResult {
$service = $this->serviceFindByAddress($tenantId, $userId, $sender);
if ($service === null || $service->getEnabled() === false) {
throw new InvalidArgumentException("Service not found for sender '{$sender}' or service is disabled");
}
if ($service instanceof ServiceEntitySubmitInterface === false) {
throw new InvalidArgumentException("Service '{$service->identifier()}' does not support entity submission");
}
if ($source === null && $message === null) {
throw new InvalidArgumentException("At least one of source or message must be provided for entity submission");
}
if ($sender instanceof AddressInterface === false) {
$sender = new Address($sender);
}
if ($message !== null && $message instanceof MessagePropertiesMutableInterface === false) {
$message = $service->entityFresh()->getProperties()->jsonDeserialize($message);
}
return $service->entitySubmit($sender, $source, $message);
}
} }
+11 -6
View File
@@ -4,7 +4,7 @@ import { useIntegrationStore } from '@KTXC/stores/integrationStore'
import { useServicesStore } from '@MailManager/stores/servicesStore' import { useServicesStore } from '@MailManager/stores/servicesStore'
import { useProvidersStore } from '@MailManager/stores/providersStore' import { useProvidersStore } from '@MailManager/stores/providersStore'
import { ServiceObject, type ProviderObject } from '@MailManager/models' import { ServiceObject, type ProviderObject } from '@MailManager/models'
import type { ProviderDiscoveryStatus, ServiceInterface, ServiceLocation } from '@MailManager/types' import type { ProviderDiscoveryStatus, ServiceAddressInterface, ServiceInterface, ServiceLocation } from '@MailManager/types'
import DiscoveryEntryPanel from '@MailManager/components/steps/DiscoveryEntryPanel.vue' import DiscoveryEntryPanel from '@MailManager/components/steps/DiscoveryEntryPanel.vue'
import DiscoveryStatusPanel from '@MailManager/components/steps/DiscoveryStatusPanel.vue' import DiscoveryStatusPanel from '@MailManager/components/steps/DiscoveryStatusPanel.vue'
import ProviderSelectionPanel from '@MailManager/components/steps/ProviderSelectionPanel.vue' import ProviderSelectionPanel from '@MailManager/components/steps/ProviderSelectionPanel.vue'
@@ -57,6 +57,11 @@ const discoverAddress = ref<string>('')
const discoverSecret = ref<string | null>(null) const discoverSecret = ref<string | null>(null)
const discoverHostname = ref<string | null>(null) const discoverHostname = ref<string | null>(null)
// Address entered during discovery, as a service address object
const discoverServiceAddress = computed<ServiceAddressInterface | null>(() =>
discoverAddress.value ? { address: discoverAddress.value } : null
)
// Step 2: Discovery Status / Provider Selection // Step 2: Discovery Status / Provider Selection
const selectedProvider = shallowRef<ProviderObject | null>(null) const selectedProvider = shallowRef<ProviderObject | null>(null)
const selectedService = shallowRef<ServiceObject | null>(null) const selectedService = shallowRef<ServiceObject | null>(null)
@@ -154,7 +159,7 @@ function createServiceObject(
identifier: null, identifier: null,
label: data.label ?? null, label: data.label ?? null,
enabled: data.enabled ?? true, enabled: data.enabled ?? true,
primaryAddress: data.primaryAddress ?? (discoverAddress.value || null), primaryAddress: data.primaryAddress ?? discoverServiceAddress.value,
secondaryAddresses: data.secondaryAddresses ?? null, secondaryAddresses: data.secondaryAddresses ?? null,
location: data.location ?? null, location: data.location ?? null,
identity: data.identity ?? null, identity: data.identity ?? null,
@@ -300,7 +305,7 @@ async function handleProviderSelect(identifier: string) {
...discoveredJson, ...discoveredJson,
label: discoveredJson.label || discoverAddress.value, label: discoveredJson.label || discoverAddress.value,
enabled: discoveredJson.enabled ?? true, enabled: discoveredJson.enabled ?? true,
primaryAddress: discoveredJson.primaryAddress || discoverAddress.value, primaryAddress: discoveredJson.primaryAddress ?? discoverServiceAddress.value,
location: discoveredJson.location location: discoveredJson.location
}) })
setSelectedProviderAndService(identifier, service) setSelectedProviderAndService(identifier, service)
@@ -317,7 +322,7 @@ function handleProviderAdvanced(identifier: string) {
...discoveredJson, ...discoveredJson,
label: discoveredJson?.label || discoverAddress.value, label: discoveredJson?.label || discoverAddress.value,
enabled: discoveredJson?.enabled ?? true, enabled: discoveredJson?.enabled ?? true,
primaryAddress: discoveredJson?.primaryAddress || discoverAddress.value, primaryAddress: discoveredJson?.primaryAddress ?? discoverServiceAddress.value,
location: discoveredJson?.location ?? null location: discoveredJson?.location ?? null
}) })
@@ -341,7 +346,7 @@ function handleProviderManualSelect(identifier: string) {
const service = createServiceObject(identifier, { const service = createServiceObject(identifier, {
label: discoverAddress.value, label: discoverAddress.value,
enabled: true, enabled: true,
primaryAddress: discoverAddress.value, primaryAddress: discoverServiceAddress.value,
location: null, location: null,
identity: null identity: null
}) })
@@ -396,7 +401,7 @@ async function saveAccount() {
try { try {
const accountData = { const accountData = {
label: serviceData.label || discoverAddress.value, label: serviceData.label || discoverAddress.value,
primaryAddress: serviceData.primaryAddress || discoverAddress.value, primaryAddress: serviceData.primaryAddress ?? discoverServiceAddress.value,
enabled: serviceData.enabled, enabled: serviceData.enabled,
location: serviceData.location, location: serviceData.location,
identity: serviceData.identity, identity: serviceData.identity,
+2 -2
View File
@@ -134,7 +134,7 @@ watch(
<v-icon>mdi-label</v-icon> <v-icon>mdi-label</v-icon>
</template> </template>
<v-list-item-title>Account Name</v-list-item-title> <v-list-item-title>Account Name</v-list-item-title>
<v-list-item-subtitle>{{ localService.label || localService.primaryAddress || 'New Account' }}</v-list-item-subtitle> <v-list-item-subtitle>{{ localService.label || localService.primaryAddress?.address || 'New Account' }}</v-list-item-subtitle>
</v-list-item> </v-list-item>
<!-- Email Address --> <!-- Email Address -->
@@ -143,7 +143,7 @@ watch(
<v-icon>mdi-email</v-icon> <v-icon>mdi-email</v-icon>
</template> </template>
<v-list-item-title>Email Address</v-list-item-title> <v-list-item-title>Email Address</v-list-item-title>
<v-list-item-subtitle>{{ localService.primaryAddress }}</v-list-item-subtitle> <v-list-item-subtitle>{{ localService.primaryAddress?.address }}</v-list-item-subtitle>
</v-list-item> </v-list-item>
<!-- Provider --> <!-- Provider -->
+83
View File
@@ -0,0 +1,83 @@
/**
* Address implementation class for Mail Manager services
*
* Plain value object (no mutation tracking). ServiceObject getters return
* fresh instances built from raw data; mutating a getter result does not
* write back — assign through the setter to persist changes.
*/
import type { ServiceAddressInterface } from '@/types/service';
export class ServiceAddressObject implements ServiceAddressInterface {
_address: string;
_label: string | null;
constructor(address: string = '', label: string | null = null) {
this._address = address;
this._label = label;
}
static fromJson(data: ServiceAddressInterface): ServiceAddressObject {
return new ServiceAddressObject(data.address, data.label ?? null);
}
toJson(): ServiceAddressInterface {
const label = this._label?.trim() ?? '';
return {
address: this._address.trim(),
label: label.length > 0 ? label : null,
};
}
toJSON(): ServiceAddressInterface {
return this.toJson();
}
clone(): ServiceAddressObject {
return new ServiceAddressObject(this._address, this._label);
}
/** Case-insensitive address comparison, ignoring labels */
matches(address: string): boolean {
return this._address.trim().toLowerCase() === address.trim().toLowerCase();
}
equals(other: ServiceAddressObject | null | undefined): boolean {
if (!other) {
return false;
}
const current = this.toJson();
const next = other.toJson();
return current.address === next.address && (current.label ?? null) === (next.label ?? null);
}
/** Display form: "Label <address>" or bare address */
format(): string {
const { address, label } = this.toJson();
return label ? `${label} <${address}>` : address;
}
get empty(): boolean {
return this._address.trim().length === 0;
}
/** Properties (raw values for editing; normalization happens in toJson) */
get address(): string {
return this._address;
}
set address(value: string) {
this._address = value;
}
get label(): string | null {
return this._label;
}
set label(value: string | null) {
this._label = value;
}
}
+2
View File
@@ -1,5 +1,6 @@
export { ProviderObject } from './provider'; export { ProviderObject } from './provider';
export { ServiceObject } from './service'; export { ServiceObject } from './service';
export { ServiceAddressObject } from './address';
export { export {
CollectionObject, CollectionObject,
CollectionPropertiesObject CollectionPropertiesObject
@@ -7,6 +8,7 @@ export {
export { EntityObject } from './entity'; export { EntityObject } from './entity';
export { export {
MessageObject, MessageObject,
MessageAddressObject,
MessagePartObject MessagePartObject
} from './message'; } from './message';
export { export {
+9 -8
View File
@@ -8,6 +8,7 @@ import type {
ServiceLocation, ServiceLocation,
ServiceModelInterface ServiceModelInterface
} from "@/types/service"; } from "@/types/service";
import { ServiceAddressObject } from './address';
import { Identity } from './identity'; import { Identity } from './identity';
import { Location } from './location'; import { Location } from './location';
import { MutationProxy } from './mutation-proxy'; import { MutationProxy } from './mutation-proxy';
@@ -118,20 +119,20 @@ export class ServiceObject implements ServiceModelInterface {
return this._data.capabilities ?? {}; return this._data.capabilities ?? {};
} }
get primaryAddress(): string | null { get primaryAddress(): ServiceAddressObject | null {
return this._data.primaryAddress ?? null; return this._data.primaryAddress ? ServiceAddressObject.fromJson(this._data.primaryAddress) : null;
} }
set primaryAddress(value: string | null) { set primaryAddress(value: ServiceAddressObject | null) {
this._data.primaryAddress = value; this._data.primaryAddress = value ? value.toJson() : null;
} }
get secondaryAddresses(): string[] { get secondaryAddresses(): ServiceAddressObject[] {
return this._data.secondaryAddresses ?? []; return (this._data.secondaryAddresses ?? []).map(entry => ServiceAddressObject.fromJson(entry));
} }
set secondaryAddresses(value: string[] | null) { set secondaryAddresses(value: ServiceAddressObject[] | null) {
this._data.secondaryAddresses = value; this._data.secondaryAddresses = value ? value.map(entry => entry.toJson()) : null;
} }
/** Mutable Properties */ /** Mutable Properties */
+1 -1
View File
@@ -212,7 +212,7 @@ async function handleAccountSaved() {
<div> <div>
<h3 class="text-h6">{{ service.label }}</h3> <h3 class="text-h6">{{ service.label }}</h3>
<p class="text-caption text-medium-emphasis"> <p class="text-caption text-medium-emphasis">
{{ service.primaryAddress || (service.identity?.type === 'BA' ? service.identity.identity : 'No email configured') }} {{ service.primaryAddress?.address || (service.identity?.type === 'BA' ? service.identity.identity : 'No email configured') }}
</p> </p>
</div> </div>
</div> </div>
+4 -1
View File
@@ -101,7 +101,10 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
* @returns Service object or null * @returns Service object or null
*/ */
function serviceForAddress(address: string, retrieve: boolean = false): ServiceObject | 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)) const service = Object.values(_services.value).find(s =>
s.primaryAddress?.matches(address) ||
s.secondaryAddresses.some(candidate => candidate.matches(address)),
)
if (retrieve === true && !service) { if (retrieve === true && !service) {
console.debug(`[Mail Manager][Store] - No service found for address "${address}", discovery may be needed`) console.debug(`[Mail Manager][Store] - No service found for address "${address}", discovery may be needed`)
+15 -3
View File
@@ -1,6 +1,7 @@
/** /**
* Service type definitions * Service type definitions
*/ */
import type { ServiceAddressObject } from '@/models/address';
import type { Identity } from '@/models/identity'; import type { Identity } from '@/models/identity';
import type { Location } from '@/models/location'; import type { Location } from '@/models/location';
import type { import type {
@@ -40,6 +41,15 @@ export interface ServiceCapabilitiesInterface {
[key: string]: boolean | object | string | string[] | undefined; [key: string]: boolean | object | string | string[] | undefined;
} }
/**
* Service sender address (primary or secondary/alias)
* Mirrors the shared Mail AddressInterface JSON shape
*/
export interface ServiceAddressInterface {
address: string;
label?: string | null;
}
/** /**
* Service information * Service information
*/ */
@@ -53,16 +63,18 @@ export interface ServiceInterface {
capabilities?: ServiceCapabilitiesInterface; capabilities?: ServiceCapabilitiesInterface;
location?: ServiceLocation | null; location?: ServiceLocation | null;
identity?: ServiceIdentity | null; identity?: ServiceIdentity | null;
primaryAddress?: string | null; primaryAddress?: ServiceAddressInterface | null;
secondaryAddresses?: string[] | null; secondaryAddresses?: ServiceAddressInterface[] | null;
auxiliary?: Record<string, any>; // Provider-specific extension data auxiliary?: Record<string, any>; // Provider-specific extension data
} }
export interface ServiceModelInterface extends Omit<{ export interface ServiceModelInterface extends Omit<{
[K in keyof ServiceInterface]-?: Exclude<ServiceInterface[K], undefined>; [K in keyof ServiceInterface]-?: Exclude<ServiceInterface[K], undefined>;
}, '@type' | 'version' | 'location' | 'identity'> { }, '@type' | 'version' | 'location' | 'identity' | 'primaryAddress' | 'secondaryAddresses'> {
location: Location | null; location: Location | null;
identity: Identity | null; identity: Identity | null;
primaryAddress: ServiceAddressObject | null;
secondaryAddresses: ServiceAddressObject[];
} }
/** /**