feat: lots more improvements
JS Unit Tests / test (pull_request) Failing after 29s
Build Test / test (pull_request) Successful in 31s
PHP Unit Tests / test (pull_request) Successful in 1m12s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-04-25 15:41:16 -04:00
parent 86e4772d45
commit 99a68737d1
26 changed files with 902 additions and 596 deletions
+50 -8
View File
@@ -13,6 +13,10 @@ import type {
ServiceIdentity,
ServiceInterface,
} from '../types'
import {
Location,
Identity
} from '@/models'
export const useServicesStore = defineStore('mailServicesStore', () => {
// State
@@ -34,6 +38,11 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
*/
const services = computed(() => Object.values(_services.value))
/**
* Get all enabled services present in store
*/
const servicesEnabled = computed(() => services.value.filter(service => service.enabled))
/**
* Get all services present in store grouped by provider
*/
@@ -73,7 +82,11 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
function serviceByIdentifier(identifier: ServiceIdentifier, retrieve: boolean = false): ServiceObject | null {
if (retrieve === true && !_services.value[identifier]) {
console.debug(`[Mail Manager][Store] - Force fetching service "${identifier}"`)
fetch(provider, identifier)
const separatorIndex = identifier.indexOf(':')
const provider = identifier.slice(0, separatorIndex)
const serviceIdentifier = identifier.slice(separatorIndex + 1)
void fetch(provider, serviceIdentifier)
}
return _services.value[identifier] ?? null
@@ -102,8 +115,8 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
/**
* Unique key for a service
*/
function identifierKey(provider: string, identifier: string | number | null): string {
return `${provider}:${identifier ?? ''}`
function identifierKey(provider: string, identifier: string | number | null): ServiceIdentifier {
return `${provider}:${identifier ?? ''}` as ServiceIdentifier
}
// Actions
@@ -223,14 +236,23 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
*
* @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
* @param delta - whether the update is a delta (partial) update or a full replacement
* @param data - service data for update
*
* @returns Promise with updated service object
*/
async function update(provider: string, identifier: string | number, data: Partial<ServiceInterface>): Promise<ServiceObject> {
async function update(provider: string, identifier: string | number, delta: boolean, data: ServiceObject | Partial<ServiceInterface>): Promise<ServiceObject> {
transceiving.value = true
try {
const service = await serviceService.update({ provider, identifier, data })
// convert ServiceObject to JSON if needed
let payload: Partial<ServiceInterface>
if (data instanceof ServiceObject) {
payload = data.toJson(delta)
} else {
payload = data
}
const service = await serviceService.update({ provider, identifier, delta, data: payload })
// Merge updated service into state
const key = identifierKey(service.provider, service.identifier)
@@ -323,11 +345,30 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
async function test(
provider: string,
identifier?: string | number | null,
location?: ServiceLocation | null,
identity?: ServiceIdentity | null,
location?: ServiceLocation | Location | null,
identity?: ServiceIdentity | Identity | null,
): Promise<any> {
transceiving.value = true
try {
if (provider === undefined || provider === null) {
console.error('[Mail Manager][Store] - Provider is required for testing service')
throw new Error('Provider is required for testing service')
}
if (identifier === undefined && (location === undefined || location === null) && (identity === undefined || identity === null)) {
console.error('[Mail Manager][Store] - Either identifier or location/identity is required for testing service')
throw new Error('Either identifier or location/identity is required for testing service')
}
if (location && location instanceof Location) {
location = location.toJson()
}
if (identity && identity instanceof Identity) {
identity = identity.toJson()
}
const response = await serviceService.test({ provider, identifier, location, identity })
console.debug('[Mail Manager][Store] - Successfully tested service:', provider, identifier || location)
@@ -348,6 +389,7 @@ export const useServicesStore = defineStore('mailServicesStore', () => {
count,
has,
services,
servicesEnabled,
servicesByProvider,
// Actions