21 Commits

Author SHA1 Message Date
6e79ae9d86 chore(deps): update vitest monorepo to v4.1.8
Some checks failed
Build Test / test (pull_request) Successful in 37s
JS Unit Tests / test (pull_request) Failing after 30s
PHP Unit Tests / test (pull_request) Successful in 1m10s
2026-06-07 03:04:33 +00:00
0e4bd905a2 Merge pull request 'feat: mail entity download' (#37) from feat/mail-entity-download into main
Some checks failed
Renovate / renovate (push) Failing after 1m50s
Reviewed-on: #37
2026-05-29 03:22:55 +00:00
935743963f feat: mail entity download
Some checks failed
Build Test / test (pull_request) Successful in 32s
JS Unit Tests / test (pull_request) Failing after 31s
PHP Unit Tests / test (pull_request) Successful in 1m1s
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-05-28 23:22:02 -04:00
502b18962c Merge pull request 'fix(deps): update dependency vue-router to v5' (#32) from renovate/vue-router-5.x into main
Some checks failed
Renovate / renovate (push) Failing after 1m38s
Reviewed-on: #32
2026-05-21 03:45:36 +00:00
138b5adcac fix(deps): update dependency vue-router to v5
Some checks failed
JS Unit Tests / test (pull_request) Failing after 36s
Build Test / test (pull_request) Successful in 40s
PHP Unit Tests / test (pull_request) Successful in 1m6s
2026-05-21 03:45:14 +00:00
e2192be442 Merge pull request 'fix(deps): update dependency pinia to v3' (#31) from renovate/pinia-3.x into main
Reviewed-on: #31
2026-05-21 03:43:24 +00:00
e86de50f2e Merge pull request 'chore(deps): update dependency phpunit/phpunit to v11.5.55' (#26) from renovate/phpunit-phpunit-11.x-lockfile into main
Reviewed-on: #26
2026-05-21 03:42:44 +00:00
4b0ffa95cb fix(deps): update dependency pinia to v3
Some checks failed
Build Test / test (pull_request) Successful in 27s
JS Unit Tests / test (pull_request) Failing after 27s
PHP Unit Tests / test (pull_request) Successful in 1m20s
2026-05-21 03:42:33 +00:00
bc389ed4c0 chore(deps): update dependency phpunit/phpunit to v11.5.55
Some checks failed
JS Unit Tests / test (pull_request) Failing after 31s
Build Test / test (pull_request) Successful in 33s
PHP Unit Tests / test (pull_request) Successful in 1m50s
2026-05-21 03:42:28 +00:00
da696cd104 Merge pull request 'chore(deps): update dependency typescript to v6' (#29) from renovate/typescript-6.x into main
Reviewed-on: #29
2026-05-21 03:39:09 +00:00
111decce15 Merge pull request 'chore(deps): update vitest monorepo to v4.1.7' (#36) from renovate/vitest-monorepo into main
Reviewed-on: #36
2026-05-21 03:38:54 +00:00
adabcd7c9a Merge pull request 'chore(deps): update dependency vue-tsc to v3.3.1' (#35) from renovate/vue-tsc-3.x-lockfile into main
Reviewed-on: #35
2026-05-21 03:38:44 +00:00
751ec564ae chore(deps): update dependency typescript to v6
Some checks failed
JS Unit Tests / test (pull_request) Failing after 38s
Build Test / test (pull_request) Successful in 41s
PHP Unit Tests / test (pull_request) Successful in 1m23s
2026-05-21 03:38:43 +00:00
9b46bb81a1 chore(deps): update vitest monorepo to v4.1.7
Some checks failed
Build Test / test (pull_request) Successful in 37s
JS Unit Tests / test (pull_request) Failing after 30s
PHP Unit Tests / test (pull_request) Successful in 1m25s
2026-05-21 03:38:40 +00:00
2e14440b95 chore(deps): update dependency vue-tsc to v3.3.1
Some checks failed
Build Test / test (pull_request) Successful in 42s
JS Unit Tests / test (pull_request) Failing after 43s
PHP Unit Tests / test (pull_request) Successful in 1m27s
2026-05-21 03:38:35 +00:00
aaec58c7e6 Merge pull request 'fix(deps): update dependency vuetify to v4' (#33) from renovate/vuetify-4.x into main
Reviewed-on: #33
2026-05-21 03:35:22 +00:00
f56cc681a6 Merge pull request 'chore(deps): update dependency @vue/tsconfig to ^0.9.0' (#28) from renovate/vue-tsconfig-0.x into main
Reviewed-on: #28
2026-05-21 03:34:54 +00:00
ef94d6dede Merge pull request 'chore(deps): update dependency vite to v8' (#30) from renovate/vite-8.x into main
Reviewed-on: #30
2026-05-21 03:34:46 +00:00
b4e379bccd fix(deps): update dependency vuetify to v4
Some checks failed
JS Unit Tests / test (pull_request) Failing after 34s
Build Test / test (pull_request) Successful in 36s
PHP Unit Tests / test (pull_request) Successful in 1m7s
2026-05-21 01:44:09 +00:00
b67d1498e3 chore(deps): update dependency vite to v8
Some checks failed
JS Unit Tests / test (pull_request) Failing after 44s
Build Test / test (pull_request) Successful in 48s
PHP Unit Tests / test (pull_request) Successful in 1m37s
2026-05-21 01:44:00 +00:00
3567fa6f20 chore(deps): update dependency @vue/tsconfig to ^0.9.0
Some checks failed
JS Unit Tests / test (pull_request) Failing after 47s
Build Test / test (pull_request) Successful in 50s
PHP Unit Tests / test (pull_request) Successful in 2m25s
2026-05-21 01:43:49 +00:00
8 changed files with 1514 additions and 1013 deletions

View File

@@ -13,6 +13,7 @@ use InvalidArgumentException;
use KTXC\Http\Response\JsonResponse;
use KTXC\Http\Response\Response;
use KTXC\Http\Response\StreamedNdJsonResponse;
use KTXC\Http\Response\StreamedResponse;
use KTXC\SessionIdentity;
use KTXC\SessionTenant;
use KTXF\Controller\ControllerAbstract;
@@ -31,12 +32,6 @@ use KTXM\MailManager\Manager;
use Psr\Log\LoggerInterface;
use Throwable;
/**
* Default Controller - Unified Mail API
*
* Handles all mail operations in JMAP-style API pattern.
* Supports both single operations and batches with result references.
*/
class DefaultController extends ControllerAbstract {
private const ERR_MISSING_PROVIDER = 'Missing parameter: provider';
@@ -168,6 +163,7 @@ class DefaultController extends ControllerAbstract {
'entity.move' => $this->entityMove($tenantId, $userId, $data),
'entity.copy' => throw new InvalidArgumentException('Operation not implemented: ' . $operation),
'entity.transmit' => $this->entityTransmit($tenantId, $userId, $data),
'entity.download' => $this->entityDownload($tenantId, $userId, $data),
default => throw new InvalidArgumentException(self::ERR_INVALID_OPERATION . $operation)
};
@@ -558,14 +554,14 @@ class DefaultController extends ControllerAbstract {
if (is_bool($result)) {
return [
'outcome' => 'deleted'
'disposition' => 'deleted'
];
}
if ($result instanceof JsonSerializable) {
return [
'outcome' => 'moved',
'data' => $result
'disposition' => 'moved',
'mutation' => $result
];
}
@@ -773,21 +769,21 @@ class DefaultController extends ControllerAbstract {
}
private function entityDelete(string $tenantId, string $userId, array $data): mixed {
if (!isset($data['sources'])) {
throw new InvalidArgumentException(self::ERR_MISSING_SOURCES);
if (!isset($data['targets'])) {
throw new InvalidArgumentException(self::ERR_MISSING_TARGETS);
}
if (!is_array($data['sources'])) {
throw new InvalidArgumentException(self::ERR_INVALID_SOURCES);
if (!is_array($data['targets'])) {
throw new InvalidArgumentException(self::ERR_INVALID_TARGETS);
}
$sources = ResourceIdentifiers::fromArray($data['sources']);
foreach ($sources as $source) {
if (!$source instanceof EntityIdentifier) {
throw new InvalidArgumentException('Invalid parameter: sources must contain provider:service:collection:entity identifiers');
$targets = ResourceIdentifiers::fromArray($data['targets']);
foreach ($targets as $target) {
if (!$target instanceof EntityIdentifier) {
throw new InvalidArgumentException('Invalid parameter: targets must contain provider:service:collection:entity identifiers');
}
}
return $this->mailManager->entityDelete($tenantId, $userId, ...$sources->all());
return $this->mailManager->entityDelete($tenantId, $userId, ...$targets->all());
}
private function entityPatch(string $tenantId, string $userId, array $data): mixed {
@@ -868,4 +864,46 @@ class DefaultController extends ControllerAbstract {
return ['jobId' => $jobId];
}
private function entityDownload(string $tenantId, string $userId, array $data): mixed {
if (!isset($data['target'])) {
throw new InvalidArgumentException(self::ERR_MISSING_TARGET);
}
if (!is_string($data['target'])) {
throw new InvalidArgumentException(self::ERR_INVALID_IDENTIFIER);
}
// 'part' is optional — null means full RFC 822 message download
$part = isset($data['part']) && is_array($data['part']) ? $data['part'] : null;
$target = ResourceIdentifier::fromString($data['target']);
$logger = $this->logger;
$result = $this->mailManager->entityDownload($tenantId, $userId, $target, $part);
$filename = $result->filename();
$asciiFilename = preg_replace('/[^\x20-\x7E]|[\\\\"]/', '_', $filename);
$encodedFilename = rawurlencode($filename);
$disposition = sprintf(
'attachment; filename="%s"; filename*=UTF-8\'\'%s',
$asciiFilename,
$encodedFilename,
);
$responseGenerator = (static function () use ($result, $logger): \Generator {
try {
yield from $result->stream();
} catch (\Throwable $t) {
$logger->error('Error streaming entity download', ['exception' => $t]);
// Headers already sent — cannot change status code; stop output cleanly
}
})();
return new StreamedResponse($responseGenerator, 200, [
'Content-Disposition' => $disposition,
'Content-Type' => $result->mimeType(),
'Content-Transfer-Encoding' => 'binary',
'Cache-Control' => 'no-store',
]);
}
}

View File

@@ -20,6 +20,7 @@ use KTXF\Mail\Service\ServiceCollectionMutableInterface;
use KTXF\Mail\Service\ServiceConfigurableInterface;
use KTXF\Mail\Service\ServiceEntityMutableInterface;
use KTXF\Mail\Service\ServiceMutableInterface;
use KTXF\Resource\BinaryResource;
use KTXF\Resource\Filter\IFilter;
use KTXF\Resource\Identifier\CollectionIdentifier;
use KTXF\Resource\Identifier\EntityIdentifier;
@@ -951,6 +952,13 @@ class Manager {
}
}
public function entityDownload(string $tenantId, string $userId, EntityIdentifier $targetEntity, array|null $targetPart): BinaryResource {
// retrieve service
$service = $this->serviceFetch($tenantId, $userId, $targetEntity->provider(), $targetEntity->service());
// download entity
return $service->entityDownload($targetEntity, $targetPart);
}
/**
* Check if messages exist
*
@@ -1294,5 +1302,4 @@ class Manager {
return $operationOutcome;
}
}

2261
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -18,18 +18,18 @@
"test:coverage": "vitest run --coverage --config tests/js/vitest.config.ts"
},
"dependencies": {
"pinia": "^2.3.1",
"pinia": "^3.0.0",
"vue": "^3.5.18",
"vue-router": "^4.5.1",
"vuetify": "^3.10.2"
"vue-router": "^5.0.0",
"vuetify": "^4.0.0"
},
"devDependencies": {
"@vitejs/plugin-vue": "^6.0.1",
"@vitest/coverage-v8": "^4.0.18",
"@vitest/ui": "^4.0.18",
"@vue/tsconfig": "^0.7.0",
"typescript": "~5.8.3",
"vite": "^7.1.2",
"@vue/tsconfig": "^0.9.0",
"typescript": "~6.0.0",
"vite": "^8.0.0",
"vue-tsc": "^3.0.5"
}
}

View File

@@ -2,7 +2,7 @@
* Entity management service
*/
import { transceivePost, transceiveStream } from './transceive';
import { transceivePost, transceiveStream, transceiveDownload } from './transceive';
import type {
EntityFetchRequest,
EntityFetchResponse,
@@ -27,6 +27,7 @@ import type {
EntityListBulkRequest,
EntityPatchResponse,
EntityPatchRequest,
EntityDownloadRequest,
} from '../types/entity';
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
import { EntityObject } from '../models';
@@ -110,7 +111,7 @@ export const entityService = {
// Convert response to EntityObject instances
const list: Record<string, EntityObject> = {};
Object.entries(response).forEach(([identifier, entity]) => {
Object.entries(response).forEach(([, entity]) => {
list[entity.identifier] = createEntityObject(entity);
});
@@ -216,6 +217,16 @@ export const entityService = {
async transmit(request: EntityTransmitRequest): Promise<EntityTransmitResponse> {
return await transceivePost<EntityTransmitRequest, EntityTransmitResponse>('entity.transmit', request);
},
/**
* Submit a browser-native attachment download request.
*
* The backend download endpoint is expected to honor the supplied selector
* and respond with an attachment payload rather than JSON.
*/
download(request: EntityDownloadRequest): { transaction: string } {
return transceiveDownload<EntityDownloadRequest>('entity.download', request);
},
};
export default entityService;

View File

@@ -141,3 +141,84 @@ export async function transceiveStream<TRequest, TData>(
return { total };
}
/**
* Submit a browser-native file download request via a top-level form POST.
*
* This avoids buffering the response body in application-managed JavaScript
* memory. The backend is expected to accept form fields where `data` contains
* the serialized operation payload and to return an attachment response.
*/
export function transceiveDownload<TRequest>(
operation: string,
data: TRequest,
user?: string,
): { transaction: string } {
if (typeof document === 'undefined' || typeof window === 'undefined') {
throw new Error('Browser window is not available for download submission');
}
const request: ApiRequest<TRequest> = {
version: API_VERSION,
transaction: generateTransactionId(),
operation,
data,
user,
};
const form = document.createElement('form');
form.method = 'POST';
form.action = API_URL;
form.target = '_blank';
form.style.display = 'none';
appendHiddenField(form, 'version', String(request.version));
appendHiddenField(form, 'transaction', request.transaction);
appendHiddenField(form, 'operation', request.operation);
appendFormValue(form, 'data', request.data);
if (request.user) {
appendHiddenField(form, 'user', request.user);
}
document.body.appendChild(form);
form.submit();
form.remove();
return { transaction: request.transaction };
}
function appendHiddenField(form: HTMLFormElement, name: string, value: string): void {
const input = document.createElement('input');
input.type = 'hidden';
input.name = name;
input.value = value;
form.appendChild(input);
}
function appendFormValue(form: HTMLFormElement, name: string, value: unknown): void {
if (value === undefined) {
return;
}
if (value === null) {
appendHiddenField(form, name, '');
return;
}
if (Array.isArray(value)) {
value.forEach((item, index) => {
appendFormValue(form, `${name}[${index}]`, item);
});
return;
}
if (typeof value === 'object') {
Object.entries(value as Record<string, unknown>).forEach(([key, nestedValue]) => {
appendFormValue(form, `${name}[${key}]`, nestedValue);
});
return;
}
appendHiddenField(form, name, String(value));
}

View File

@@ -7,7 +7,8 @@ import { defineStore } from 'pinia'
import { entityService } from '../services'
import { EntityObject, MessageObject } from '../models'
import type {
EntityListStreamRequest,
EntityBlobSelector,
EntityDownloadRequest,
EntityTransmitRequest,
EntityTransmitResponse,
} from '../types/entity'
@@ -18,7 +19,7 @@ import type {
ListRange,
ListSort,
} from '../types/common'
import type { MessageInterface } from '@/types/message'
import type { MessageInterface, MessagePartInterface } from '@/types/message'
export const useEntitiesStore = defineStore('mailEntitiesStore', () => {
// State
@@ -184,15 +185,15 @@ export const useEntitiesStore = defineStore('mailEntitiesStore', () => {
const response = await entityService.delta({ sources })
// Process delta and update store
Object.entries(response).forEach(([provider, providerData]) => {
Object.entries(response).forEach(([, providerData]) => {
// Skip if no changes for provider
if (providerData === false) return
Object.entries(providerData).forEach(([service, serviceData]) => {
Object.entries(providerData).forEach(([, serviceData]) => {
// Skip if no changes for service
if (serviceData === false) return
Object.entries(serviceData).forEach(([collection, collectionData]) => {
Object.entries(serviceData).forEach(([, collectionData]) => {
// Skip if no changes for collection
if (collectionData === false) return
@@ -474,6 +475,39 @@ export const useEntitiesStore = defineStore('mailEntitiesStore', () => {
}
}
async function download(target: EntityIdentifier, part?: Partial<MessagePartInterface>) {
let targetPart: EntityBlobSelector | undefined = undefined
if (part && (part.blobId || part.partId || part.cid)) {
targetPart = {
blobId: part.blobId ?? undefined,
partId: part.partId ?? undefined,
cid: part.cid ?? undefined,
}
}
let filename: string
if (part && part.name && part.name.trim().length > 0) {
filename = part.name.trim()
} else if (part) {
filename = `attachment-${part.partId || part.blobId || part.cid || 'unknown'}`
} else {
filename = 'message.eml'
}
const request: EntityDownloadRequest = {
target,
part: targetPart,
filename,
}
try {
entityService.download(request)
} catch (error: any) {
console.error('[Mail Manager][Store] - Failed to submit attachment download:', error)
throw error
}
}
// Return public API
return {
// State (readonly)
@@ -495,5 +529,6 @@ export const useEntitiesStore = defineStore('mailEntitiesStore', () => {
delta,
move,
transmit,
download,
}
})

View File

@@ -205,4 +205,32 @@ export interface EntityTransmitRequest {
export interface EntityTransmitResponse {
id: string;
status: 'queued' | 'sent';
}
}
/**
* Entity Blob Fetch
*/
export interface EntityBlobSelector {
blobId?: string;
partId?: string;
cid?: string;
}
export interface EntityDownloadRequest {
target: EntityIdentifier;
part?: EntityBlobSelector;
filename?: string | null;
}
export interface EntityBlobsRequest {
target: EntityIdentifier;
parts: EntityBlobSelector[];
}
export interface EntityBlobsResult {
source: EntityIdentifier;
part: EntityBlobSelector;
blob: Blob;
}
export interface EntityBlobsResponse extends Array<EntityBlobsResult> {}