Compare commits
1 Commits
main
...
8f995a7f45
| Author | SHA1 | Date | |
|---|---|---|---|
| 8f995a7f45 |
39
.github/workflows/build-test.yml
vendored
39
.github/workflows/build-test.yml
vendored
@@ -4,47 +4,20 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Retrieve Server Install Action
|
- name: Checkout
|
||||||
uses: actions/checkout@v6.0.2
|
uses: actions/checkout@v6.0.2
|
||||||
with:
|
|
||||||
repository: Nodarx/action-server-install
|
|
||||||
ref: main
|
|
||||||
path: action-server-install
|
|
||||||
github-server-url: https://git.ktrix.dev
|
|
||||||
|
|
||||||
- name: Install Server
|
- name: Set up Node.js
|
||||||
uses: ./action-server-install
|
uses: actions/setup-node@v6.2.0
|
||||||
with:
|
with:
|
||||||
install-php: 'false'
|
node-version: 24
|
||||||
install-node: 'true'
|
cache: npm
|
||||||
php-version: '8.5'
|
|
||||||
node-version: '24'
|
|
||||||
server-path: './server'
|
|
||||||
|
|
||||||
- name: Install Mail Manager
|
|
||||||
uses: actions/checkout@v6.0.2
|
|
||||||
with:
|
|
||||||
repository: Nodarx/mail_manager
|
|
||||||
ref: main
|
|
||||||
path: server/modules/mail_manager
|
|
||||||
github-server-url: https://git.ktrix.dev
|
|
||||||
|
|
||||||
- name: Checkout Pull Request
|
|
||||||
uses: actions/checkout@v6.0.2
|
|
||||||
with:
|
|
||||||
repository: ${{ github.repository }}
|
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
|
||||||
path: server/modules/provider_jmapc
|
|
||||||
github-server-url: https://git.ktrix.dev
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
working-directory: server/modules/provider_jmapc
|
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: npm run build
|
run: npm run build
|
||||||
working-directory: server/modules/provider_jmapc
|
|
||||||
|
|||||||
35
.github/workflows/js-unit-tests.yml
vendored
35
.github/workflows/js-unit-tests.yml
vendored
@@ -6,45 +6,18 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Retrieve Server Install Action
|
- name: Checkout
|
||||||
uses: actions/checkout@v6.0.2
|
uses: actions/checkout@v6.0.2
|
||||||
with:
|
|
||||||
repository: Nodarx/action-server-install
|
|
||||||
ref: main
|
|
||||||
path: action-server-install
|
|
||||||
github-server-url: https://git.ktrix.dev
|
|
||||||
|
|
||||||
- name: Install Server
|
- name: Set up Node.js
|
||||||
uses: ./action-server-install
|
uses: actions/setup-node@v6.2.0
|
||||||
with:
|
with:
|
||||||
install-php: 'false'
|
|
||||||
install-node: 'true'
|
|
||||||
php-version: '8.5'
|
|
||||||
node-version: '24'
|
node-version: '24'
|
||||||
server-path: './server'
|
cache: 'npm'
|
||||||
|
|
||||||
- name: Install Mail Manager
|
|
||||||
uses: actions/checkout@v6.0.2
|
|
||||||
with:
|
|
||||||
repository: Nodarx/mail_manager
|
|
||||||
ref: main
|
|
||||||
path: server/modules/mail_manager
|
|
||||||
github-server-url: https://git.ktrix.dev
|
|
||||||
|
|
||||||
- name: Checkout Pull Request
|
|
||||||
uses: actions/checkout@v6.0.2
|
|
||||||
with:
|
|
||||||
repository: ${{ github.repository }}
|
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
|
||||||
path: server/modules/provider_jmapc
|
|
||||||
github-server-url: https://git.ktrix.dev
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
working-directory: server/modules/provider_jmapc
|
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: npm run test:unit
|
run: npm run test:unit
|
||||||
working-directory: server/modules/provider_jmapc
|
|
||||||
|
|||||||
36
.github/workflows/php-unit-tests.yml
vendored
36
.github/workflows/php-unit-tests.yml
vendored
@@ -6,45 +6,19 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Retrieve Server Install Action
|
- name: Checkout
|
||||||
uses: actions/checkout@v6.0.2
|
uses: actions/checkout@v6.0.2
|
||||||
with:
|
|
||||||
repository: Nodarx/action-server-install
|
|
||||||
ref: main
|
|
||||||
path: action-server-install
|
|
||||||
github-server-url: https://git.ktrix.dev
|
|
||||||
|
|
||||||
- name: Install Server
|
- name: Set up PHP
|
||||||
uses: ./action-server-install
|
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1
|
||||||
with:
|
with:
|
||||||
install-php: 'true'
|
|
||||||
install-node: 'false'
|
|
||||||
php-version: '8.5'
|
php-version: '8.5'
|
||||||
node-version: '24'
|
tools: composer:v2
|
||||||
server-path: './server'
|
extensions: ctype, iconv, mongodb
|
||||||
|
|
||||||
- name: Install Mail Manager
|
|
||||||
uses: actions/checkout@v6.0.2
|
|
||||||
with:
|
|
||||||
repository: Nodarx/mail_manager
|
|
||||||
ref: main
|
|
||||||
path: server/modules/mail_manager
|
|
||||||
github-server-url: https://git.ktrix.dev
|
|
||||||
|
|
||||||
- name: Checkout Pull Request
|
|
||||||
uses: actions/checkout@v6.0.2
|
|
||||||
with:
|
|
||||||
repository: ${{ github.repository }}
|
|
||||||
ref: ${{ github.event.pull_request.head.sha }}
|
|
||||||
path: server/modules/provider_jmapc
|
|
||||||
github-server-url: https://git.ktrix.dev
|
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: composer install --prefer-dist --no-progress
|
run: composer install --prefer-dist --no-progress
|
||||||
working-directory: server/modules/provider_jmapc
|
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: composer test:unit
|
run: composer test:unit
|
||||||
working-directory: server/modules/provider_jmapc
|
|
||||||
|
|||||||
@@ -37,16 +37,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"KTXT\\ProviderJmapc\\": "tests/php/"
|
"KTXT\\ProviderJmapc\\": "tests/php/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"post-install-cmd": [
|
"post-install-cmd": [
|
||||||
],
|
],
|
||||||
"post-update-cmd": [
|
"post-update-cmd": [
|
||||||
],
|
],
|
||||||
"test:unit": "phpunit --configuration tests/php/phpunit.unit.xml --colors=always --testdox",
|
"test:unit": "phpunit --configuration tests/php/phpunit.unit.xml --colors=always --testdox",
|
||||||
"test:coverage": "XDEBUG_MODE=coverage phpunit --configuration tests/php/phpunit.unit.xml --coverage-html .phpunit.coverage --coverage-text"
|
"test:coverage": "XDEBUG_MODE=coverage phpunit --configuration tests/php/phpunit.unit.xml --coverage-html .phpunit.coverage --coverage-text"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ use KTXF\Resource\Provider\ProviderInterface;
|
|||||||
use KTXM\ProviderJmapc\Providers\Mail\Provider as MailProvider;
|
use KTXM\ProviderJmapc\Providers\Mail\Provider as MailProvider;
|
||||||
use KTXM\ProviderJmapc\Providers\Chrono\Provider as ChronoProvider;
|
use KTXM\ProviderJmapc\Providers\Chrono\Provider as ChronoProvider;
|
||||||
use KTXM\ProviderJmapc\Providers\People\Provider as PeopleProvider;
|
use KTXM\ProviderJmapc\Providers\People\Provider as PeopleProvider;
|
||||||
use KTXM\ProviderJmapc\Providers\Document\Provider as DocumentProvider;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JMAP Client Provider Module
|
* JMAP Client Provider Module
|
||||||
@@ -69,9 +68,8 @@ class Module extends ModuleInstanceAbstract implements ModuleBrowserInterface
|
|||||||
{
|
{
|
||||||
// Register JMAP providers - all three share the same service store
|
// Register JMAP providers - all three share the same service store
|
||||||
$this->providerManager->register(ProviderInterface::TYPE_MAIL, 'jmap', MailProvider::class);
|
$this->providerManager->register(ProviderInterface::TYPE_MAIL, 'jmap', MailProvider::class);
|
||||||
//$this->providerManager->register(ProviderInterface::TYPE_CHRONO, 'jmap', ChronoProvider::class);
|
$this->providerManager->register(ProviderInterface::TYPE_CHRONO, 'jmap', ChronoProvider::class);
|
||||||
//$this->providerManager->register(ProviderInterface::TYPE_PEOPLE, 'jmap', PeopleProvider::class);
|
$this->providerManager->register(ProviderInterface::TYPE_PEOPLE, 'jmap', PeopleProvider::class);
|
||||||
$this->providerManager->register(ProviderInterface::TYPE_DOCUMENT, 'jmap', DocumentProvider::class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerBI(): array {
|
public function registerBI(): array {
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace KTXM\ProviderJmapc\Providers\Document;
|
|
||||||
|
|
||||||
use KTXF\Resource\Documents\Collection\CollectionPropertiesMutableAbstract;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Document Collection Properties Implementation
|
|
||||||
*/
|
|
||||||
class CollectionProperties extends CollectionPropertiesMutableAbstract {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert JMAP parameters array to document collection properties object
|
|
||||||
*
|
|
||||||
* @param array $parameters JMAP parameters array
|
|
||||||
*/
|
|
||||||
public function fromJmap(array $parameters): static {
|
|
||||||
|
|
||||||
if (isset($parameters['name'])) {
|
|
||||||
$this->data['label'] = $parameters['name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert mail collection properties object to JMAP parameters array
|
|
||||||
*/
|
|
||||||
public function toJmap(): array {
|
|
||||||
|
|
||||||
$parameters = [];
|
|
||||||
|
|
||||||
if (isset($this->data['label'])) {
|
|
||||||
$parameters['name'] = $this->data['label'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace KTXM\ProviderJmapc\Providers\Document;
|
|
||||||
|
|
||||||
use KTXF\Resource\Documents\Collection\CollectionMutableAbstract;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Document Collection Resource Implementation
|
|
||||||
*/
|
|
||||||
class CollectionResource extends CollectionMutableAbstract {
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
string $provider = 'jmapc',
|
|
||||||
string|int|null $service = null,
|
|
||||||
) {
|
|
||||||
parent::__construct($provider, $service);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts JMAP parameters array to document collection object
|
|
||||||
*
|
|
||||||
* @param array $parameters JMAP parameters array
|
|
||||||
*/
|
|
||||||
public function fromJmap(array $parameters): static {
|
|
||||||
|
|
||||||
if (isset($parameters['parentId'])) {
|
|
||||||
$this->data['collection'] = $parameters['parentId'];
|
|
||||||
}
|
|
||||||
if (isset($parameters['id'])) {
|
|
||||||
$this->data['identifier'] = $parameters['id'];
|
|
||||||
}
|
|
||||||
if (isset($parameters['created'])) {
|
|
||||||
$this->data['created'] = $parameters['created'];
|
|
||||||
}
|
|
||||||
if (isset($parameters['modified'])) {
|
|
||||||
$this->data['modified'] = $parameters['modified'];
|
|
||||||
}
|
|
||||||
if (isset($parameters['signature'])) {
|
|
||||||
$this->data['signature'] = $parameters['signature'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->getProperties()->fromJmap($parameters);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert document collection object to JMAP parameters array
|
|
||||||
*/
|
|
||||||
public function toJmap(): array {
|
|
||||||
|
|
||||||
$parameters = [];
|
|
||||||
|
|
||||||
if (isset($this->data['collection'])) {
|
|
||||||
$parameters['parentId'] = $this->data['collection'];
|
|
||||||
}
|
|
||||||
if (isset($this->data['identifier'])) {
|
|
||||||
$parameters['id'] = $this->data['identifier'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$parameters = array_merge($parameters, $this->getProperties()->toJmap());
|
|
||||||
|
|
||||||
return $parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function getProperties(): CollectionProperties {
|
|
||||||
if (!isset($this->properties)) {
|
|
||||||
$this->properties = new CollectionProperties([]);
|
|
||||||
}
|
|
||||||
return $this->properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace KTXM\ProviderJmapc\Providers\Document;
|
|
||||||
|
|
||||||
use KTXF\Resource\Documents\Entity\EntityPropertiesMutableAbstract;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Document Collection Properties Implementation
|
|
||||||
*/
|
|
||||||
class EntityProperties extends EntityPropertiesMutableAbstract {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert JMAP parameters array to document entity properties object
|
|
||||||
*
|
|
||||||
* @param array $parameters JMAP parameters array
|
|
||||||
*/
|
|
||||||
public function fromJmap(array $parameters): static {
|
|
||||||
|
|
||||||
if (isset($data['size'])) {
|
|
||||||
$this->data[self::JSON_PROPERTY_SIZE] = (int) $data['size'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data['label'])) {
|
|
||||||
$this->data[self::JSON_PROPERTY_LABEL] = (string) $data['name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data['mime'])) {
|
|
||||||
$this->data[self::JSON_PROPERTY_MIME] = (string) $data['type'];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data['format'])) {
|
|
||||||
$this->data[self::JSON_PROPERTY_FORMAT] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data['encoding'])) {
|
|
||||||
$this->data[self::JSON_PROPERTY_ENCODING] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert document entity properties object to JMAP parameters array
|
|
||||||
*/
|
|
||||||
public function toJmap(): array {
|
|
||||||
|
|
||||||
$parameters = array_filter([
|
|
||||||
'name' => $this->data[self::JSON_PROPERTY_LABEL],
|
|
||||||
'type' => $this->data[self::JSON_PROPERTY_MIME] ?? 'application/octet-stream'
|
|
||||||
], static fn($value) => $value !== null);
|
|
||||||
|
|
||||||
return $parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace KTXM\ProviderJmapc\Providers\Document;
|
|
||||||
|
|
||||||
use KTXF\Resource\Documents\Entity\EntityMutableAbstract;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mail Entity Resource Implementation
|
|
||||||
*/
|
|
||||||
class EntityResource extends EntityMutableAbstract {
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
string $provider = 'jmapc',
|
|
||||||
string|int|null $service = null,
|
|
||||||
) {
|
|
||||||
parent::__construct($provider, $service);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert JMAP parameters array to mail entity object
|
|
||||||
*
|
|
||||||
* @param array $parameters JMAP parameters array
|
|
||||||
*/
|
|
||||||
public function fromJmap(array $parameters): static {
|
|
||||||
|
|
||||||
if (isset($parameters['parentId'])) {
|
|
||||||
$this->data['collection'] = $parameters['parentId'];
|
|
||||||
}
|
|
||||||
if (isset($parameters['id'])) {
|
|
||||||
$this->data['identifier'] = $parameters['id'];
|
|
||||||
}
|
|
||||||
if (isset($parameters['signature'])) {
|
|
||||||
$this->data['signature'] = $parameters['signature'];
|
|
||||||
}
|
|
||||||
if (isset($parameters['created'])) {
|
|
||||||
$this->data['created'] = $parameters['created'] ?? $parameters['created'];
|
|
||||||
}
|
|
||||||
if (isset($parameters['modified'])) {
|
|
||||||
$this->data['modified'] = $parameters['modified'];
|
|
||||||
}
|
|
||||||
if (isset($parameters['accessed']))
|
|
||||||
|
|
||||||
$this->getProperties()->fromJmap($parameters);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert mail entity object to JMAP parameters array
|
|
||||||
*/
|
|
||||||
public function toJmap(): array {
|
|
||||||
|
|
||||||
$parameters = [];
|
|
||||||
|
|
||||||
if (isset($this->data['collection'])) {
|
|
||||||
$parameters['parentId'] = $this->data['collection'];
|
|
||||||
}
|
|
||||||
if (isset($this->data['identifier'])) {
|
|
||||||
$parameters['id'] = $this->data['identifier'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$parameters = array_merge($parameters, $this->getProperties()->toJmap());
|
|
||||||
|
|
||||||
return $parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritDoc
|
|
||||||
*/
|
|
||||||
public function getProperties(): EntityProperties {
|
|
||||||
if (!isset($this->properties)) {
|
|
||||||
$this->properties = new EntityProperties([]);
|
|
||||||
}
|
|
||||||
return $this->properties;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,201 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace KTXM\ProviderJmapc\Providers\Document;
|
|
||||||
|
|
||||||
use KTXF\Resource\Documents\Provider\ProviderBaseInterface;
|
|
||||||
use KTXF\Resource\Documents\Provider\ProviderServiceMutateInterface;
|
|
||||||
use KTXF\Resource\Documents\Provider\ProviderServiceTestInterface;
|
|
||||||
use KTXF\Resource\Documents\Service\ServiceBaseInterface;
|
|
||||||
use KTXF\Resource\Documents\Service\ServiceMutableInterface;
|
|
||||||
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
|
|
||||||
use KTXF\Resource\Provider\ResourceServiceMutateInterface;
|
|
||||||
use KTXM\ProviderJmapc\Service\Discovery;
|
|
||||||
use KTXM\ProviderJmapc\Service\Remote\RemoteService;
|
|
||||||
use KTXM\ProviderJmapc\Stores\ServiceStore;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JMAP Mail Provider
|
|
||||||
*/
|
|
||||||
class Provider implements ProviderServiceMutateInterface, ProviderServiceTestInterface
|
|
||||||
{
|
|
||||||
|
|
||||||
public const JSON_TYPE = ProviderBaseInterface::JSON_TYPE;
|
|
||||||
protected const PROVIDER_IDENTIFIER = 'jmap';
|
|
||||||
protected const PROVIDER_LABEL = 'JMAP Documents Provider';
|
|
||||||
protected const PROVIDER_DESCRIPTION = 'Provides documents services via JMAP protocol (RFC 8620)';
|
|
||||||
protected const PROVIDER_ICON = 'mdi-file-sync';
|
|
||||||
|
|
||||||
protected array $providerAbilities = [
|
|
||||||
self::CAPABILITY_SERVICE_LIST => true,
|
|
||||||
self::CAPABILITY_SERVICE_FETCH => true,
|
|
||||||
self::CAPABILITY_SERVICE_EXTANT => true,
|
|
||||||
self::CAPABILITY_SERVICE_CREATE => true,
|
|
||||||
self::CAPABILITY_SERVICE_MODIFY => true,
|
|
||||||
self::CAPABILITY_SERVICE_DESTROY => true,
|
|
||||||
self::CAPABILITY_SERVICE_TEST => true,
|
|
||||||
];
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
private readonly ServiceStore $serviceStore,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function jsonSerialize(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
self::JSON_PROPERTY_TYPE => self::JSON_TYPE,
|
|
||||||
self::JSON_PROPERTY_IDENTIFIER => self::PROVIDER_IDENTIFIER,
|
|
||||||
self::JSON_PROPERTY_LABEL => self::PROVIDER_LABEL,
|
|
||||||
self::JSON_PROPERTY_CAPABILITIES => $this->providerAbilities,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function jsonDeserialize(array|string $data): static
|
|
||||||
{
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function type(): string
|
|
||||||
{
|
|
||||||
return self::TYPE_MAIL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function identifier(): string
|
|
||||||
{
|
|
||||||
return self::PROVIDER_IDENTIFIER;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function label(): string
|
|
||||||
{
|
|
||||||
return self::PROVIDER_LABEL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function description(): string
|
|
||||||
{
|
|
||||||
return self::PROVIDER_DESCRIPTION;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function icon(): string
|
|
||||||
{
|
|
||||||
return self::PROVIDER_ICON;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function capable(string $value): bool
|
|
||||||
{
|
|
||||||
return !empty($this->providerAbilities[$value]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function capabilities(): array
|
|
||||||
{
|
|
||||||
return $this->providerAbilities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function serviceList(string $tenantId, string $userId, array $filter = []): array
|
|
||||||
{
|
|
||||||
$list = $this->serviceStore->list($tenantId, $userId, $filter);
|
|
||||||
foreach ($list as $serviceData) {
|
|
||||||
$serviceInstance = $this->serviceFresh()->fromStore($serviceData);
|
|
||||||
$list[$serviceInstance->identifier()] = $serviceInstance;
|
|
||||||
}
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function serviceFetch(string $tenantId, string $userId, string|int $identifier): ?Service
|
|
||||||
{
|
|
||||||
$serviceData = $this->serviceStore->fetch($tenantId, $userId, $identifier);
|
|
||||||
if ($serviceData === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
$serviceInstance = $this->serviceFresh()->fromStore($serviceData);
|
|
||||||
return $serviceInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function serviceExtant(string $tenantId, string $userId, string|int ...$identifiers): array
|
|
||||||
{
|
|
||||||
return $this->serviceStore->extant($tenantId, $userId, $identifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function serviceFresh(): ServiceMutableInterface
|
|
||||||
{
|
|
||||||
return new Service();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function serviceCreate(string $tenantId, string $userId, ResourceServiceMutateInterface $service): string
|
|
||||||
{
|
|
||||||
if (!($service instanceof Service)) {
|
|
||||||
throw new \InvalidArgumentException('Service must be instance of JMAP Service');
|
|
||||||
}
|
|
||||||
|
|
||||||
$created = $this->serviceStore->create($tenantId, $userId, $service);
|
|
||||||
return (string) $created['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function serviceModify(string $tenantId, string $userId, ResourceServiceMutateInterface $service): string
|
|
||||||
{
|
|
||||||
if (!($service instanceof Service)) {
|
|
||||||
throw new \InvalidArgumentException('Service must be instance of JMAP Service');
|
|
||||||
}
|
|
||||||
|
|
||||||
$updated = $this->serviceStore->modify($tenantId, $userId, $service);
|
|
||||||
return (string) $updated['id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function serviceDestroy(string $tenantId, string $userId, ResourceServiceMutateInterface $service): bool
|
|
||||||
{
|
|
||||||
if (!($service instanceof Service)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->serviceStore->delete($tenantId, $userId, $service->identifier());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function serviceDiscover(
|
|
||||||
string $tenantId,
|
|
||||||
string $userId,
|
|
||||||
string $identity,
|
|
||||||
?string $location = null,
|
|
||||||
?string $secret = null
|
|
||||||
): ResourceServiceLocationInterface|null {
|
|
||||||
$discovery = new Discovery();
|
|
||||||
|
|
||||||
// TODO: Make SSL verification configurable based on tenant/user settings
|
|
||||||
$verifySSL = true;
|
|
||||||
|
|
||||||
return $discovery->discover($identity, $location, $secret, $verifySSL);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function serviceTest(ServiceBaseInterface $service, array $options = []): array {
|
|
||||||
$startTime = microtime(true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (!($service instanceof Service)) {
|
|
||||||
throw new \InvalidArgumentException('Service must be instance of JMAP Service');
|
|
||||||
}
|
|
||||||
|
|
||||||
$client = RemoteService::freshClient($service);
|
|
||||||
$session = $client->connect();
|
|
||||||
|
|
||||||
$latency = round((microtime(true) - $startTime) * 1000); // ms4
|
|
||||||
|
|
||||||
return [
|
|
||||||
'success' => true,
|
|
||||||
'message' => 'JMAP connection successful'
|
|
||||||
. ' (Account ID: ' . ($session->username() ?? 'N/A') . ')'
|
|
||||||
. ' (Latency: ' . $latency . ' ms)',
|
|
||||||
];
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$latency = round((microtime(true) - $startTime) * 1000);
|
|
||||||
return [
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'Test failed: ' . $e->getMessage(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,482 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace KTXM\ProviderJmapc\Providers\Document;
|
|
||||||
|
|
||||||
use Generator;
|
|
||||||
use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
|
|
||||||
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
|
|
||||||
use KTXF\Resource\Delta\Delta;
|
|
||||||
use KTXF\Resource\Documents\Collection\CollectionBaseInterface;
|
|
||||||
use KTXF\Resource\Documents\Collection\CollectionMutableInterface;
|
|
||||||
use KTXF\Resource\Documents\Service\ServiceBaseInterface;
|
|
||||||
use KTXF\Resource\Documents\Service\ServiceCollectionMutableInterface;
|
|
||||||
use KTXF\Resource\Documents\Service\ServiceConfigurableInterface;
|
|
||||||
use KTXF\Resource\Documents\Service\ServiceMutableInterface;
|
|
||||||
use KTXF\Resource\Filter\Filter;
|
|
||||||
use KTXF\Resource\Filter\IFilter;
|
|
||||||
use KTXF\Resource\Range\IRange;
|
|
||||||
use KTXF\Resource\Range\Range;
|
|
||||||
use KTXF\Resource\Range\RangeType;
|
|
||||||
use KTXF\Resource\Sort\ISort;
|
|
||||||
use KTXF\Resource\Sort\Sort;
|
|
||||||
use KTXM\ProviderJmapc\Providers\ServiceIdentityBasic;
|
|
||||||
use KTXM\ProviderJmapc\Providers\ServiceLocation;
|
|
||||||
use KTXM\ProviderJmapc\Service\Remote\RemoteFilesService;
|
|
||||||
use KTXM\ProviderJmapc\Service\Remote\RemoteService;
|
|
||||||
|
|
||||||
class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceConfigurableInterface, ServiceCollectionMutableInterface
|
|
||||||
{
|
|
||||||
public const JSON_TYPE = ServiceBaseInterface::JSON_TYPE;
|
|
||||||
|
|
||||||
private const PROVIDER_IDENTIFIER = 'jmap';
|
|
||||||
|
|
||||||
private ?string $serviceTenantId = null;
|
|
||||||
private ?string $serviceUserId = null;
|
|
||||||
private ?string $serviceIdentifier = null;
|
|
||||||
private ?string $serviceLabel = null;
|
|
||||||
private bool $serviceEnabled = false;
|
|
||||||
private bool $serviceDebug = false;
|
|
||||||
private ?ServiceLocation $location = null;
|
|
||||||
private ?ServiceIdentityBasic $identity = null;
|
|
||||||
private array $auxiliary = [];
|
|
||||||
|
|
||||||
private array $serviceAbilities = [
|
|
||||||
self::CAPABILITY_COLLECTION_LIST => true,
|
|
||||||
self::CAPABILITY_COLLECTION_LIST_FILTER => [
|
|
||||||
self::CAPABILITY_COLLECTION_FILTER_LABEL => 's:100:256:256',
|
|
||||||
],
|
|
||||||
self::CAPABILITY_COLLECTION_LIST_SORT => [
|
|
||||||
self::CAPABILITY_COLLECTION_SORT_LABEL,
|
|
||||||
],
|
|
||||||
self::CAPABILITY_COLLECTION_EXTANT => true,
|
|
||||||
self::CAPABILITY_COLLECTION_FETCH => true,
|
|
||||||
self::CAPABILITY_COLLECTION_CREATE => true,
|
|
||||||
self::CAPABILITY_COLLECTION_UPDATE => true,
|
|
||||||
self::CAPABILITY_COLLECTION_DELETE => true,
|
|
||||||
self::CAPABILITY_ENTITY_LIST => true,
|
|
||||||
self::CAPABILITY_ENTITY_LIST_FILTER => [
|
|
||||||
self::CAPABILITY_ENTITY_FILTER_ALL => 's:200:256:256',
|
|
||||||
],
|
|
||||||
self::CAPABILITY_ENTITY_LIST_SORT => [
|
|
||||||
self::CAPABILITY_ENTITY_SORT_LABEL
|
|
||||||
],
|
|
||||||
self::CAPABILITY_ENTITY_LIST_RANGE => [
|
|
||||||
'tally' => ['absolute', 'relative']
|
|
||||||
],
|
|
||||||
self::CAPABILITY_ENTITY_DELTA => true,
|
|
||||||
self::CAPABILITY_ENTITY_EXTANT => true,
|
|
||||||
self::CAPABILITY_ENTITY_FETCH => true,
|
|
||||||
];
|
|
||||||
|
|
||||||
private readonly RemoteFilesService $remoteService;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
) {}
|
|
||||||
|
|
||||||
private function initialize(): void {
|
|
||||||
if (!isset($this->remoteService)) {
|
|
||||||
$client = RemoteService::freshClient($this);
|
|
||||||
$this->remoteService = RemoteService::documentsService($client);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function toStore(): array {
|
|
||||||
return array_filter([
|
|
||||||
'tid' => $this->serviceTenantId,
|
|
||||||
'uid' => $this->serviceUserId,
|
|
||||||
'sid' => $this->serviceIdentifier,
|
|
||||||
'label' => $this->serviceLabel,
|
|
||||||
'enabled' => $this->serviceEnabled,
|
|
||||||
'debug' => $this->serviceDebug,
|
|
||||||
'location' => $this->location?->toStore(),
|
|
||||||
'identity' => $this->identity?->toStore(),
|
|
||||||
'auxiliary' => $this->auxiliary,
|
|
||||||
], fn($v) => $v !== null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fromStore(array $data): static {
|
|
||||||
$this->serviceTenantId = $data['tid'] ?? null;
|
|
||||||
$this->serviceUserId = $data['uid'] ?? null;
|
|
||||||
$this->serviceIdentifier = $data['sid'];
|
|
||||||
$this->serviceLabel = $data['label'] ?? '';
|
|
||||||
$this->serviceEnabled = $data['enabled'] ?? false;
|
|
||||||
$this->serviceDebug = $data['debug'] ?? false;
|
|
||||||
|
|
||||||
if (isset($data['location'])) {
|
|
||||||
$this->location = (new ServiceLocation())->fromStore($data['location']);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data['identity'])) {
|
|
||||||
$this->identity = (new ServiceIdentityBasic())->fromStore($data['identity']);
|
|
||||||
}
|
|
||||||
if (isset($data['auxiliary']) && is_array($data['auxiliary'])) {
|
|
||||||
$this->auxiliary = $data['auxiliary'];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function jsonSerialize(): array {
|
|
||||||
return array_filter([
|
|
||||||
self::JSON_PROPERTY_TYPE => self::JSON_TYPE,
|
|
||||||
self::JSON_PROPERTY_PROVIDER => self::PROVIDER_IDENTIFIER,
|
|
||||||
self::JSON_PROPERTY_IDENTIFIER => $this->serviceIdentifier,
|
|
||||||
self::JSON_PROPERTY_LABEL => $this->serviceLabel,
|
|
||||||
self::JSON_PROPERTY_ENABLED => $this->serviceEnabled,
|
|
||||||
self::JSON_PROPERTY_CAPABILITIES => $this->serviceAbilities,
|
|
||||||
self::JSON_PROPERTY_LOCATION => $this->location?->jsonSerialize(),
|
|
||||||
self::JSON_PROPERTY_IDENTITY => $this->identity?->jsonSerialize(),
|
|
||||||
self::JSON_PROPERTY_AUXILIARY => $this->auxiliary,
|
|
||||||
], fn($v) => $v !== null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function jsonDeserialize(array|string $data): static {
|
|
||||||
if (is_string($data)) {
|
|
||||||
$data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($data[self::JSON_PROPERTY_LABEL])) {
|
|
||||||
$this->setLabel($data[self::JSON_PROPERTY_LABEL]);
|
|
||||||
}
|
|
||||||
if (isset($data[self::JSON_PROPERTY_ENABLED])) {
|
|
||||||
$this->setEnabled($data[self::JSON_PROPERTY_ENABLED]);
|
|
||||||
}
|
|
||||||
if (isset($data[self::JSON_PROPERTY_LOCATION])) {
|
|
||||||
$this->setLocation($this->freshLocation(null, $data[self::JSON_PROPERTY_LOCATION]));
|
|
||||||
}
|
|
||||||
if (isset($data[self::JSON_PROPERTY_IDENTITY])) {
|
|
||||||
$this->setIdentity($this->freshIdentity(null, $data[self::JSON_PROPERTY_IDENTITY]));
|
|
||||||
}
|
|
||||||
if (isset($data[self::JSON_PROPERTY_AUXILIARY]) && is_array($data[self::JSON_PROPERTY_AUXILIARY])) {
|
|
||||||
$this->setAuxiliary($data[self::JSON_PROPERTY_AUXILIARY]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function capable(string $value): bool
|
|
||||||
{
|
|
||||||
return isset($this->serviceAbilities[$value]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function capabilities(): array {
|
|
||||||
return $this->serviceAbilities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function provider(): string
|
|
||||||
{
|
|
||||||
return self::PROVIDER_IDENTIFIER;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function identifier(): string|int
|
|
||||||
{
|
|
||||||
return $this->serviceIdentifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLabel(): string|null
|
|
||||||
{
|
|
||||||
return $this->serviceLabel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setLabel(string $label): static
|
|
||||||
{
|
|
||||||
$this->serviceLabel = $label;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getEnabled(): bool
|
|
||||||
{
|
|
||||||
return $this->serviceEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setEnabled(bool $enabled): static
|
|
||||||
{
|
|
||||||
$this->serviceEnabled = $enabled;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLocation(): ServiceLocation
|
|
||||||
{
|
|
||||||
return $this->location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setLocation(ResourceServiceLocationInterface $location): static
|
|
||||||
{
|
|
||||||
$this->location = $location;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function freshLocation(string|null $type = null, array $data = []): ServiceLocation
|
|
||||||
{
|
|
||||||
$location = new ServiceLocation();
|
|
||||||
$location->jsonDeserialize($data);
|
|
||||||
return $location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getIdentity(): ServiceIdentityBasic
|
|
||||||
{
|
|
||||||
return $this->identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setIdentity(ResourceServiceIdentityInterface $identity): static
|
|
||||||
{
|
|
||||||
$this->identity = $identity;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function freshIdentity(string|null $type, array $data = []): ServiceIdentityBasic
|
|
||||||
{
|
|
||||||
$identity = new ServiceIdentityBasic();
|
|
||||||
$identity->jsonDeserialize($data);
|
|
||||||
return $identity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDebug(): bool
|
|
||||||
{
|
|
||||||
return $this->serviceDebug;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setDebug(bool $debug): static
|
|
||||||
{
|
|
||||||
$this->serviceDebug = $debug;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAuxiliary(): array
|
|
||||||
{
|
|
||||||
return $this->auxiliary;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setAuxiliary(array $auxiliary): static
|
|
||||||
{
|
|
||||||
$this->auxiliary = $auxiliary;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collection operations
|
|
||||||
|
|
||||||
public function collectionList(string|int|null $location, ?IFilter $filter = null, ?ISort $sort = null): array
|
|
||||||
{
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
$collections = $this->remoteService->collectionList($location, $filter, $sort);
|
|
||||||
|
|
||||||
foreach ($collections as &$collection) {
|
|
||||||
if (is_array($collection) && isset($collection['id'])) {
|
|
||||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
|
||||||
$object->fromJmap($collection);
|
|
||||||
$collection = $object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $collections;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function collectionListFilter(): Filter
|
|
||||||
{
|
|
||||||
return new Filter($this->serviceAbilities[self::CAPABILITY_COLLECTION_LIST_FILTER] ?? []);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function collectionListSort(): Sort
|
|
||||||
{
|
|
||||||
return new Sort($this->serviceAbilities[self::CAPABILITY_COLLECTION_LIST_SORT] ?? []);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function collectionExtant(string|int|null $location, string|int ...$identifiers): array
|
|
||||||
{
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
return $this->remoteService->collectionExtant($location, ...$identifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function collectionFetch(string|int|null $identifier): ?CollectionBaseInterface
|
|
||||||
{
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
$collection = $this->remoteService->collectionFetch($identifier);
|
|
||||||
|
|
||||||
if (is_array($collection) && isset($collection['id'])) {
|
|
||||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
|
||||||
$object->fromJmap($collection);
|
|
||||||
$collection = $object;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $collection;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function collectionFresh(): CollectionMutableInterface
|
|
||||||
{
|
|
||||||
return new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function collectionCreate(string|int|null $location, CollectionMutableInterface $collection, array $options = []): CollectionBaseInterface
|
|
||||||
{
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
if ($collection instanceof CollectionResource === false) {
|
|
||||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
|
||||||
$object->jsonDeserialize($collection->jsonSerialize());
|
|
||||||
$collection = $object;
|
|
||||||
}
|
|
||||||
|
|
||||||
$collection = $collection->toJmap();
|
|
||||||
$collection = $this->remoteService->collectionCreate($location, $collection, $options);
|
|
||||||
|
|
||||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
|
||||||
$object->fromJmap($collection);
|
|
||||||
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function collectionUpdate(string|int $identifier, CollectionMutableInterface $collection): CollectionBaseInterface
|
|
||||||
{
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
if ($collection instanceof CollectionResource === false) {
|
|
||||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
|
||||||
$object->jsonDeserialize($collection->jsonSerialize());
|
|
||||||
$collection = $object;
|
|
||||||
}
|
|
||||||
|
|
||||||
$collection = $collection->toJmap();
|
|
||||||
$collection = $this->remoteService->collectionModify($identifier, $collection);
|
|
||||||
|
|
||||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
|
||||||
$object->fromJmap($collection);
|
|
||||||
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function collectionDelete(string|int $identifier, bool $force = false, bool $recursive = false): bool
|
|
||||||
{
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
return $this->remoteService->collectionDestroy($identifier, $force, $recursive) !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function collectionMove(string|int $identifier, string|int|null $targetLocation): CollectionBaseInterface
|
|
||||||
{
|
|
||||||
// TODO: Implement collection move
|
|
||||||
$this->initialize();
|
|
||||||
$collection = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
|
||||||
return $collection;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Entity operations
|
|
||||||
|
|
||||||
public function entityList(string|int|null $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): array
|
|
||||||
{
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
$result = $this->remoteService->entityList($collection, $filter, $sort, $range, $properties);
|
|
||||||
|
|
||||||
$list = [];
|
|
||||||
foreach ($result['list'] as $index => $entry) {
|
|
||||||
if (is_array($entry) && isset($entry['id'])) {
|
|
||||||
$object = new EntityResource(provider: $this->provider(), service: $this->identifier());
|
|
||||||
$object->fromJmap($entry);
|
|
||||||
$list[$object->identifier()] = $object;
|
|
||||||
}
|
|
||||||
unset($result['list'][$index]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function entityListStream(string|int $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): Generator
|
|
||||||
{
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
$result = $this->remoteService->entityList($collection, $filter, $sort, $range, $properties);
|
|
||||||
|
|
||||||
foreach ($result['list'] as $index => $entry) {
|
|
||||||
if (is_array($entry) && isset($entry['id'])) {
|
|
||||||
$object = new EntityResource(provider: $this->provider(), service: $this->identifier());
|
|
||||||
$object->fromJmap($entry);
|
|
||||||
yield $object;
|
|
||||||
}
|
|
||||||
unset($result['list'][$index]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function entityListFilter(): Filter
|
|
||||||
{
|
|
||||||
return new Filter($this->serviceAbilities[self::CAPABILITY_ENTITY_LIST_FILTER] ?? []);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function entityListSort(): Sort
|
|
||||||
{
|
|
||||||
return new Sort($this->serviceAbilities[self::CAPABILITY_ENTITY_LIST_SORT] ?? []);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function entityListRange(RangeType $type): IRange
|
|
||||||
{
|
|
||||||
return new Range();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function entityDelta(string|int|null $collection, string $signature, string $detail = 'ids'): Delta
|
|
||||||
{
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
return $this->remoteService->entityDelta($collection, $signature, $detail);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function entityExtant(string|int|null $collection, string|int ...$identifiers): array
|
|
||||||
{
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
return $this->remoteService->entityExtant(...$identifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function entityFetch(string|int|null $collection, string|int ...$identifiers): array
|
|
||||||
{
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
$entities = $this->remoteService->entityFetch(...$identifiers);
|
|
||||||
|
|
||||||
foreach ($entities as &$entity) {
|
|
||||||
if (is_array($entity) && isset($entity['id'])) {
|
|
||||||
$object = new EntityResource(provider: $this->provider(), service: $this->identifier());
|
|
||||||
$object->fromJmap($entity);
|
|
||||||
$entity = $object;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $entities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function entityRead(string|int|null $collection, string|int $identifier): ?string
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Node operations
|
|
||||||
|
|
||||||
public function nodeList(string|int|null $collection, bool $recursive = false, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): array
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function nodeListFilter(): IFilter
|
|
||||||
{
|
|
||||||
return new Filter(['']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function nodeListSort(): ISort
|
|
||||||
{
|
|
||||||
return new Sort(['']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function nodeDelta(string|int|null $collection, string $signature, string $detail = 'ids'): Delta
|
|
||||||
{
|
|
||||||
return new Delta();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -30,7 +30,7 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
|||||||
$this->data['size'] = $parameters['size'];
|
$this->data['size'] = $parameters['size'];
|
||||||
}
|
}
|
||||||
if (isset($parameters['receivedAt'])) {
|
if (isset($parameters['receivedAt'])) {
|
||||||
$this->data['received'] = $parameters['receivedAt'];
|
$this->data['receivedDate'] = $parameters['receivedAt'];
|
||||||
}
|
}
|
||||||
if (isset($parameters['sentAt'])) {
|
if (isset($parameters['sentAt'])) {
|
||||||
$this->data['date'] = $parameters['sentAt'];
|
$this->data['date'] = $parameters['sentAt'];
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ use KTXM\ProviderJmapc\Stores\ServiceStore;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* JMAP Mail Provider
|
* JMAP Mail Provider
|
||||||
|
*
|
||||||
|
* Provides Mail services via JMAP protocol.
|
||||||
|
* Filters services by urn:ietf:params:jmap:mail capability.
|
||||||
*/
|
*/
|
||||||
class Provider implements ProviderServiceMutateInterface, ProviderServiceDiscoverInterface, ProviderServiceTestInterface
|
class Provider implements ProviderServiceMutateInterface, ProviderServiceDiscoverInterface, ProviderServiceTestInterface
|
||||||
{
|
{
|
||||||
@@ -99,21 +102,22 @@ class Provider implements ProviderServiceMutateInterface, ProviderServiceDiscove
|
|||||||
public function serviceList(string $tenantId, string $userId, array $filter = []): array
|
public function serviceList(string $tenantId, string $userId, array $filter = []): array
|
||||||
{
|
{
|
||||||
$list = $this->serviceStore->list($tenantId, $userId, $filter);
|
$list = $this->serviceStore->list($tenantId, $userId, $filter);
|
||||||
foreach ($list as $serviceData) {
|
foreach ($list as $entry) {
|
||||||
$serviceInstance = $this->serviceFresh()->fromStore($serviceData);
|
$service = new Service();
|
||||||
$list[$serviceInstance->identifier()] = $serviceInstance;
|
$service->fromStore($entry);
|
||||||
|
$list[$service->identifier()] = $service;
|
||||||
}
|
}
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function serviceExtant(string $tenantId, string $userId, string|int ...$identifiers): array
|
||||||
|
{
|
||||||
|
return $this->serviceStore->extant($tenantId, $userId, $identifiers);
|
||||||
|
}
|
||||||
|
|
||||||
public function serviceFetch(string $tenantId, string $userId, string|int $identifier): ?Service
|
public function serviceFetch(string $tenantId, string $userId, string|int $identifier): ?Service
|
||||||
{
|
{
|
||||||
$serviceData = $this->serviceStore->fetch($tenantId, $userId, $identifier);
|
return $this->serviceStore->fetch($tenantId, $userId, $identifier);
|
||||||
if ($serviceData === null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
$serviceInstance = $this->serviceFresh()->fromStore($serviceData);
|
|
||||||
return $serviceInstance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serviceFindByAddress(string $tenantId, string $userId, string $address): ?Service
|
public function serviceFindByAddress(string $tenantId, string $userId, string $address): ?Service
|
||||||
@@ -128,12 +132,7 @@ class Provider implements ProviderServiceMutateInterface, ProviderServiceDiscove
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serviceExtant(string $tenantId, string $userId, string|int ...$identifiers): array
|
public function serviceFresh(): ResourceServiceMutateInterface
|
||||||
{
|
|
||||||
return $this->serviceStore->extant($tenantId, $userId, $identifiers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function serviceFresh(): Service
|
|
||||||
{
|
{
|
||||||
return new Service();
|
return new Service();
|
||||||
}
|
}
|
||||||
@@ -145,7 +144,7 @@ class Provider implements ProviderServiceMutateInterface, ProviderServiceDiscove
|
|||||||
}
|
}
|
||||||
|
|
||||||
$created = $this->serviceStore->create($tenantId, $userId, $service);
|
$created = $this->serviceStore->create($tenantId, $userId, $service);
|
||||||
return (string) $created['id'];
|
return (string) $created->identifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serviceModify(string $tenantId, string $userId, ResourceServiceMutateInterface $service): string
|
public function serviceModify(string $tenantId, string $userId, ResourceServiceMutateInterface $service): string
|
||||||
@@ -155,7 +154,7 @@ class Provider implements ProviderServiceMutateInterface, ProviderServiceDiscove
|
|||||||
}
|
}
|
||||||
|
|
||||||
$updated = $this->serviceStore->modify($tenantId, $userId, $service);
|
$updated = $this->serviceStore->modify($tenantId, $userId, $service);
|
||||||
return (string) $updated['id'];
|
return (string) $updated->identifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serviceDestroy(string $tenantId, string $userId, ResourceServiceMutateInterface $service): bool
|
public function serviceDestroy(string $tenantId, string $userId, ResourceServiceMutateInterface $service): bool
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace KTXM\ProviderJmapc\Providers\Mail;
|
namespace KTXM\ProviderJmapc\Providers\Mail;
|
||||||
|
|
||||||
use Generator;
|
|
||||||
use KTXF\Mail\Collection\CollectionBaseInterface;
|
use KTXF\Mail\Collection\CollectionBaseInterface;
|
||||||
use KTXF\Mail\Collection\CollectionMutableInterface;
|
use KTXF\Mail\Collection\CollectionMutableInterface;
|
||||||
use KTXF\Mail\Object\Address;
|
use KTXF\Mail\Object\Address;
|
||||||
@@ -17,7 +16,6 @@ use KTXF\Mail\Object\AddressInterface;
|
|||||||
use KTXF\Mail\Service\ServiceBaseInterface;
|
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\ServiceMutableInterface;
|
use KTXF\Mail\Service\ServiceMutableInterface;
|
||||||
use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
|
use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
|
||||||
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
|
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
|
||||||
@@ -34,6 +32,11 @@ use KTXM\ProviderJmapc\Providers\ServiceLocation;
|
|||||||
use KTXM\ProviderJmapc\Service\Remote\RemoteMailService;
|
use KTXM\ProviderJmapc\Service\Remote\RemoteMailService;
|
||||||
use KTXM\ProviderJmapc\Service\Remote\RemoteService;
|
use KTXM\ProviderJmapc\Service\Remote\RemoteService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JMAP Service
|
||||||
|
*
|
||||||
|
* Represents a configured JMAP account
|
||||||
|
*/
|
||||||
class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceConfigurableInterface, ServiceCollectionMutableInterface
|
class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceConfigurableInterface, ServiceCollectionMutableInterface
|
||||||
{
|
{
|
||||||
public const JSON_TYPE = ServiceBaseInterface::JSON_TYPE;
|
public const JSON_TYPE = ServiceBaseInterface::JSON_TYPE;
|
||||||
@@ -102,14 +105,16 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
private function initialize(): void {
|
private function initialize(): void
|
||||||
|
{
|
||||||
if (!isset($this->mailService)) {
|
if (!isset($this->mailService)) {
|
||||||
$client = RemoteService::freshClient($this);
|
$client = RemoteService::freshClient($this);
|
||||||
$this->mailService = RemoteService::mailService($client);
|
$this->mailService = RemoteService::mailService($client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function toStore(): array {
|
public function toStore(): array
|
||||||
|
{
|
||||||
return array_filter([
|
return array_filter([
|
||||||
'tid' => $this->serviceTenantId,
|
'tid' => $this->serviceTenantId,
|
||||||
'uid' => $this->serviceUserId,
|
'uid' => $this->serviceUserId,
|
||||||
@@ -125,7 +130,8 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
], fn($v) => $v !== null);
|
], fn($v) => $v !== null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fromStore(array $data): static {
|
public function fromStore(array $data): static
|
||||||
|
{
|
||||||
$this->serviceTenantId = $data['tid'] ?? null;
|
$this->serviceTenantId = $data['tid'] ?? null;
|
||||||
$this->serviceUserId = $data['uid'] ?? null;
|
$this->serviceUserId = $data['uid'] ?? null;
|
||||||
$this->serviceIdentifier = $data['sid'];
|
$this->serviceIdentifier = $data['sid'];
|
||||||
@@ -154,7 +160,8 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jsonSerialize(): array {
|
public function jsonSerialize(): array
|
||||||
|
{
|
||||||
return array_filter([
|
return array_filter([
|
||||||
self::JSON_PROPERTY_TYPE => self::JSON_TYPE,
|
self::JSON_PROPERTY_TYPE => self::JSON_TYPE,
|
||||||
self::JSON_PROPERTY_PROVIDER => self::PROVIDER_IDENTIFIER,
|
self::JSON_PROPERTY_PROVIDER => self::PROVIDER_IDENTIFIER,
|
||||||
@@ -170,7 +177,8 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
], fn($v) => $v !== null);
|
], fn($v) => $v !== null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jsonDeserialize(array|string $data): static {
|
public function jsonDeserialize(array|string $data): static
|
||||||
|
{
|
||||||
if (is_string($data)) {
|
if (is_string($data)) {
|
||||||
$data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
|
$data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
|
||||||
}
|
}
|
||||||
@@ -210,9 +218,14 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
return isset($this->serviceAbilities[$value]);
|
return isset($this->serviceAbilities[$value]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function capabilities(): array {
|
public function capabilities(): array
|
||||||
return $this->serviceAbilities;
|
{
|
||||||
}
|
$caps = [];
|
||||||
|
foreach (array_keys($this->serviceAbilities) as $cap) {
|
||||||
|
$caps[$cap] = true;
|
||||||
|
}
|
||||||
|
return $caps;
|
||||||
|
}
|
||||||
|
|
||||||
public function provider(): string
|
public function provider(): string
|
||||||
{
|
{
|
||||||
@@ -473,22 +486,6 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function entityListStream(string|int $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): Generator
|
|
||||||
{
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
$result = $this->mailService->entityList($collection, $filter, $sort, $range, $properties);
|
|
||||||
|
|
||||||
foreach ($result['list'] as $index => $entry) {
|
|
||||||
if (is_array($entry) && isset($entry['id'])) {
|
|
||||||
$object = new EntityResource(provider: $this->provider(), service: $this->identifier());
|
|
||||||
$object->fromJmap($entry);
|
|
||||||
yield $object;
|
|
||||||
}
|
|
||||||
unset($result['list'][$index]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function entityListFilter(): Filter
|
public function entityListFilter(): Filter
|
||||||
{
|
{
|
||||||
return new Filter($this->serviceAbilities[self::CAPABILITY_ENTITY_LIST_FILTER] ?? []);
|
return new Filter($this->serviceAbilities[self::CAPABILITY_ENTITY_LIST_FILTER] ?? []);
|
||||||
@@ -535,12 +532,4 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
return $entities;
|
return $entities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function entityMove(string|int $target, array $sources): array
|
|
||||||
{
|
|
||||||
$this->initialize();
|
|
||||||
|
|
||||||
$result = $this->mailService->entityMove($target, $sources);
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,726 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SPDX-FileCopyrightText: Sebastian Krupinski <krupinski01@gmail.com>
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace KTXM\ProviderJmapc\Service\Remote;
|
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use JmapClient\Client;
|
|
||||||
use JmapClient\Requests\Files\NodeGet;
|
|
||||||
use JmapClient\Requests\Files\NodeQuery;
|
|
||||||
use JmapClient\Requests\Files\NodeParameters as NodeParametersRequest;
|
|
||||||
use JmapClient\Requests\Files\NodeQueryChanges;
|
|
||||||
use JmapClient\Requests\Files\NodeSet;
|
|
||||||
use JmapClient\Responses\Files\NodeParameters as NodeParametersResponse;
|
|
||||||
use JmapClient\Responses\ResponseException;
|
|
||||||
use KTXF\Resource\Delta\Delta;
|
|
||||||
use KTXF\Resource\Delta\DeltaCollection;
|
|
||||||
use KTXF\Resource\Filter\Filter;
|
|
||||||
use KTXF\Resource\Filter\IFilter;
|
|
||||||
use KTXF\Resource\Range\IRange;
|
|
||||||
use KTXF\Resource\Range\RangeAnchorType;
|
|
||||||
use KTXF\Resource\Range\RangeTally;
|
|
||||||
use KTXF\Resource\Sort\ISort;
|
|
||||||
use KTXF\Resource\Sort\Sort;
|
|
||||||
use KTXM\ProviderJmapc\Exception\JmapUnknownMethod;
|
|
||||||
|
|
||||||
class RemoteFilesService {
|
|
||||||
|
|
||||||
private const ROOT_ID = '00000000-0000-0000-0000-000000000000';
|
|
||||||
private const COLLECTION_FILTER_ATTRIBUTES = ['any', 'label', 'role', 'roles', 'createdBefore', 'createdAfter', 'modifiedBefore', 'modifiedAfter'];
|
|
||||||
private const COLLECTION_SORT_ATTRIBUTES = ['tree'];
|
|
||||||
private const ENTITY_FILTER_ATTRIBUTES = ['any', 'label', 'createdBefore', 'createdAfter', 'modifiedBefore', 'modifiedAfter'];
|
|
||||||
private const ENTITY_SORT_ATTRIBUTES = ['tree'];
|
|
||||||
|
|
||||||
protected Client $dataStore;
|
|
||||||
protected string $dataAccount;
|
|
||||||
|
|
||||||
protected ?string $resourceNamespace = null;
|
|
||||||
protected ?string $resourceCollectionLabel = null;
|
|
||||||
protected ?string $resourceEntityLabel = null;
|
|
||||||
|
|
||||||
public function __construct() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public function initialize(Client $dataStore, ?string $dataAccount = null) {
|
|
||||||
|
|
||||||
$this->dataStore = $dataStore;
|
|
||||||
// evaluate if client is connected
|
|
||||||
if (!$this->dataStore->sessionStatus()) {
|
|
||||||
$this->dataStore->connect();
|
|
||||||
}
|
|
||||||
// determine account
|
|
||||||
if ($dataAccount === null) {
|
|
||||||
if ($this->resourceNamespace !== null) {
|
|
||||||
$account = $dataStore->sessionAccountDefault($this->resourceNamespace, false);
|
|
||||||
} else {
|
|
||||||
$account = $dataStore->sessionAccountDefault('filenode');
|
|
||||||
}
|
|
||||||
$this->dataAccount = $account !== null ? $account->id() : '';
|
|
||||||
} else {
|
|
||||||
$this->dataAccount = $dataAccount;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* list of collections in remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function collectionList(?string $location = null, IFilter|null $filter = null, ISort|null $sort = null, IRange|null $range = null): array {
|
|
||||||
// construct request
|
|
||||||
$r0 = new NodeQuery($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
$r0->filter()->is(false);
|
|
||||||
$r0->depth(1);
|
|
||||||
// define location
|
|
||||||
if (!empty($location) && $location !== self::ROOT_ID) {
|
|
||||||
$r0->filter()->in($location);
|
|
||||||
}
|
|
||||||
// define filter
|
|
||||||
if ($filter !== null) {
|
|
||||||
foreach ($filter->conditions() as $condition) {
|
|
||||||
$value = $condition['value'];
|
|
||||||
match($condition['attribute']) {
|
|
||||||
'label' => $r0->filter()->labelMatches($value),
|
|
||||||
default => null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// define order
|
|
||||||
if ($sort !== null) {
|
|
||||||
foreach ($sort->conditions() as $condition) {
|
|
||||||
$direction = $condition['direction'];
|
|
||||||
match($condition['attribute']) {
|
|
||||||
'tree' => $r0->sort()->tree($direction),
|
|
||||||
default => null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// construct request
|
|
||||||
$r1 = new NodeGet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
// define target
|
|
||||||
//$r1->targetFromRequest($r0, '/ids');
|
|
||||||
if (!empty($location) && $location !== self::ROOT_ID) {
|
|
||||||
$r1->target($location);
|
|
||||||
}
|
|
||||||
// transceive
|
|
||||||
//$bundle = $this->dataStore->perform([$r1]);
|
|
||||||
$bundle = $this->dataStore->perform([$r0, $r1]);
|
|
||||||
// extract response
|
|
||||||
//$response = $bundle->response(0);
|
|
||||||
$response = $bundle->response(1);
|
|
||||||
// check for command error
|
|
||||||
if ($response instanceof ResponseException) {
|
|
||||||
if ($response->type() === 'unknownMethod') {
|
|
||||||
throw new JmapUnknownMethod($response->description(), 1);
|
|
||||||
} else {
|
|
||||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// convert jmap objects to collection objects
|
|
||||||
$list = [];
|
|
||||||
foreach ($response->objects() as $so) {
|
|
||||||
if (!$so instanceof NodeParametersResponse) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$id = $so->id();
|
|
||||||
$list[$id] = $so->parametersRaw();
|
|
||||||
$list[$id]['signature'] = $response->state();
|
|
||||||
}
|
|
||||||
// return collection of collections
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fresh instance of collection filter object
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function collectionListFilter(): Filter {
|
|
||||||
return new Filter(self::COLLECTION_FILTER_ATTRIBUTES);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fresh instance of collection sort object
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function collectionListSort(): Sort {
|
|
||||||
return new Sort([self::COLLECTION_SORT_ATTRIBUTES]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* check existence of collections in remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function collectionExtant(string ...$identifiers): array {
|
|
||||||
$extant = [];
|
|
||||||
// construct request
|
|
||||||
$r0 = new NodeGet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
$r0->target(...$identifiers);
|
|
||||||
$r0->property('id');
|
|
||||||
// transceive
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
// check for command error
|
|
||||||
if ($response instanceof ResponseException) {
|
|
||||||
if ($response->type() === 'unknownMethod') {
|
|
||||||
throw new JmapUnknownMethod($response->description(), 1);
|
|
||||||
} else {
|
|
||||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// convert jmap objects to collection objects
|
|
||||||
foreach ($response->objects() as $so) {
|
|
||||||
if (!$so instanceof NodeParametersResponse) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$extant[$so->id()] = true;
|
|
||||||
}
|
|
||||||
return $extant;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* retrieve properties for specific collection
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function collectionFetch(string $identifier): ?array {
|
|
||||||
// construct request
|
|
||||||
$r0 = new NodeGet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
$r0->target($identifier);
|
|
||||||
// transceive
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
// check for command error
|
|
||||||
if ($response instanceof ResponseException) {
|
|
||||||
if ($response->type() === 'unknownMethod') {
|
|
||||||
throw new JmapUnknownMethod($response->description(), 1);
|
|
||||||
} else {
|
|
||||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// convert jmap object to collection object
|
|
||||||
$so = $response->object(0);
|
|
||||||
$to = null;
|
|
||||||
if ($so instanceof NodeParametersResponse) {
|
|
||||||
$to = $so->parametersRaw();
|
|
||||||
$to['signature'] = $response->state();
|
|
||||||
}
|
|
||||||
return $to;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* create collection in remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function collectionCreate(string|null $location, array $so): ?array {
|
|
||||||
// convert entity
|
|
||||||
$to = new NodeParametersRequest();
|
|
||||||
$to->parametersRaw($so);
|
|
||||||
// define location
|
|
||||||
if (!empty($location) && $location !== self::ROOT_ID) {
|
|
||||||
$to->in($location);
|
|
||||||
}
|
|
||||||
$id = uniqid();
|
|
||||||
// construct request
|
|
||||||
$r0 = new NodeSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
$r0->create($id, $to);
|
|
||||||
// transceive
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
// check for command error
|
|
||||||
if ($response instanceof ResponseException) {
|
|
||||||
if ($response->type() === 'unknownMethod') {
|
|
||||||
throw new JmapUnknownMethod($response->description(), 1);
|
|
||||||
} else {
|
|
||||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// check for success
|
|
||||||
$result = $response->createSuccess($id);
|
|
||||||
if ($result !== null) {
|
|
||||||
return array_merge($so, $result);
|
|
||||||
}
|
|
||||||
// check for failure
|
|
||||||
$result = $response->createFailure($id);
|
|
||||||
if ($result !== null) {
|
|
||||||
$type = $result['type'] ?? 'unknownError';
|
|
||||||
$description = $result['description'] ?? 'An unknown error occurred during collection creation.';
|
|
||||||
throw new Exception("$type: $description", 1);
|
|
||||||
}
|
|
||||||
// return null if creation failed without failure reason
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* modify collection in remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function collectionModify(string $identifier, array $so): ?array {
|
|
||||||
// convert entity
|
|
||||||
$to = new NodeParametersRequest();
|
|
||||||
$to->parametersRaw($so);
|
|
||||||
// construct request
|
|
||||||
$r0 = new NodeSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
$r0->update($identifier, $to);
|
|
||||||
// transceive
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
// check for command error
|
|
||||||
if ($response instanceof ResponseException) {
|
|
||||||
if ($response->type() === 'unknownMethod') {
|
|
||||||
throw new JmapUnknownMethod($response->description(), 1);
|
|
||||||
} else {
|
|
||||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// check for success
|
|
||||||
$result = $response->updateSuccess($identifier);
|
|
||||||
if ($result !== null) {
|
|
||||||
return array_merge($so, $result);
|
|
||||||
}
|
|
||||||
// check for failure
|
|
||||||
$result = $response->updateFailure($identifier);
|
|
||||||
if ($result !== null) {
|
|
||||||
$type = $result['type'] ?? 'unknownError';
|
|
||||||
$description = $result['description'] ?? 'An unknown error occurred during collection modification.';
|
|
||||||
throw new Exception("$type: $description", 1);
|
|
||||||
}
|
|
||||||
// return null if modification failed without failure reason
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* delete collection in remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function collectionDestroy(string $identifier, bool $force = false, bool $recursive = false): ?string {
|
|
||||||
// construct request
|
|
||||||
$r0 = new NodeSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
$r0->delete($identifier);
|
|
||||||
if ($force) {
|
|
||||||
$r0->destroyContents(true);
|
|
||||||
}
|
|
||||||
// transceive
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
// check for command error
|
|
||||||
if ($response instanceof ResponseException) {
|
|
||||||
if ($response->type() === 'unknownMethod') {
|
|
||||||
throw new JmapUnknownMethod($response->description(), 1);
|
|
||||||
} else {
|
|
||||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// check for success
|
|
||||||
$result = $response->deleteSuccess($identifier);
|
|
||||||
if ($result !== null) {
|
|
||||||
return (string)$result['id'];
|
|
||||||
}
|
|
||||||
// check for failure
|
|
||||||
$result = $response->deleteFailure($identifier);
|
|
||||||
if ($result !== null) {
|
|
||||||
$type = $result['type'] ?? 'unknownError';
|
|
||||||
$description = $result['description'] ?? 'An unknown error occurred during collection deletion.';
|
|
||||||
throw new Exception("$type: $description", 1);
|
|
||||||
}
|
|
||||||
// return null if deletion failed without failure reason
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* retrieve entities from remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function entityList(?string $location = null, IFilter|null $filter = null, ISort|null $sort = null, IRange|null $range = null, string|null $granularity = null): array {
|
|
||||||
// construct request
|
|
||||||
$r0 = new NodeQuery($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
// define location
|
|
||||||
if (!empty($location)) {
|
|
||||||
$r0->filter()->in($location);
|
|
||||||
}
|
|
||||||
// define filter
|
|
||||||
if ($filter !== null) {
|
|
||||||
foreach ($filter->conditions() as $condition) {
|
|
||||||
$value = $condition['value'];
|
|
||||||
match($condition['attribute']) {
|
|
||||||
'any' => $r0->filter()->text($value),
|
|
||||||
'in' => $r0->filter()->in($value),
|
|
||||||
'label' => $r0->filter()->labelMatches($value),
|
|
||||||
'format' => $r0->filter()->formatIs($value),
|
|
||||||
default => null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// define order
|
|
||||||
if ($sort !== null) {
|
|
||||||
foreach ($sort->conditions() as $condition) {
|
|
||||||
$direction = $condition['direction'];
|
|
||||||
match($condition['attribute']) {
|
|
||||||
'type' => $r0->sort()->type($direction),
|
|
||||||
default => null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// define range
|
|
||||||
if ($range !== null) {
|
|
||||||
if ($range instanceof RangeTally && $range->getAnchor() === RangeAnchorType::ABSOLUTE) {
|
|
||||||
$r0->limitAbsolute($range->getPosition(), $range->getTally());
|
|
||||||
}
|
|
||||||
if ($range instanceof RangeTally && $range->getAnchor() === RangeAnchorType::RELATIVE) {
|
|
||||||
$r0->limitRelative($range->getPosition(), $range->getTally());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// construct get request
|
|
||||||
$r1 = new NodeGet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
// set target to query request
|
|
||||||
//$r1->targetFromRequest($r0, '/ids');
|
|
||||||
if (!empty($location)) {
|
|
||||||
$r1->target($location);
|
|
||||||
}
|
|
||||||
// transmit request and receive response
|
|
||||||
$bundle = $this->dataStore->perform([$r1]);
|
|
||||||
//$bundle = $this->dataStore->perform([$r0, $r1]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
//$response = $bundle->response(1);
|
|
||||||
// convert json objects to message objects
|
|
||||||
$state = $response->state();
|
|
||||||
$list = $response->objects();
|
|
||||||
foreach ($list as $id => $entry) {
|
|
||||||
if (!$entry instanceof NodeParametersResponse) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$list[$id] = $entry->parametersRaw();
|
|
||||||
}
|
|
||||||
// return message collection
|
|
||||||
return ['list' => $list, 'state' => $state];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fresh instance of object filter
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function entityListFilter(): Filter {
|
|
||||||
return new Filter(self::ENTITY_FILTER_ATTRIBUTES);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fresh instance of object sort
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function entityListSort(): Sort {
|
|
||||||
return new Sort(self::ENTITY_SORT_ATTRIBUTES);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* fresh instance of object range
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function entityListRange(): RangeTally {
|
|
||||||
return new RangeTally();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* check existence of entities in remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function entityExtant(string ...$identifiers): array {
|
|
||||||
$extant = [];
|
|
||||||
// construct request
|
|
||||||
$r0 = new NodeGet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
$r0->target(...$identifiers);
|
|
||||||
$r0->property('id');
|
|
||||||
// transmit request and receive response
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
// convert json objects to message objects
|
|
||||||
foreach ($response->objects() as $so) {
|
|
||||||
if (!$so instanceof NodeParametersResponse) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$extant[$so->id()] = true;
|
|
||||||
}
|
|
||||||
return $extant;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* delta for entities in remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*
|
|
||||||
* @return Delta
|
|
||||||
*/
|
|
||||||
public function entityDelta(?string $location, string $state, string $granularity = 'D'): Delta {
|
|
||||||
|
|
||||||
if (empty($state)) {
|
|
||||||
$results = $this->entityList($location, null, null, null, 'B');
|
|
||||||
$delta = new Delta();
|
|
||||||
$delta->signature = $results['state'];
|
|
||||||
foreach ($results['list'] as $entry) {
|
|
||||||
$delta->additions[] = $entry['id'];
|
|
||||||
}
|
|
||||||
return $delta;
|
|
||||||
}
|
|
||||||
if (empty($location)) {
|
|
||||||
return $this->entityDeltaDefault($state, $granularity);
|
|
||||||
} else {
|
|
||||||
return $this->entityDeltaSpecific($location, $state, $granularity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* delta of changes for specific collection in remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function entityDeltaSpecific(?string $location, string $state, string $granularity = 'D'): Delta {
|
|
||||||
// construct set request
|
|
||||||
$r0 = new NodeQueryChanges($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
// set location constraint
|
|
||||||
if (!empty($location)) {
|
|
||||||
$r0->filter()->in($location);
|
|
||||||
}
|
|
||||||
// set state constraint
|
|
||||||
if (!empty($state)) {
|
|
||||||
$r0->state($state);
|
|
||||||
} else {
|
|
||||||
$r0->state('0');
|
|
||||||
}
|
|
||||||
// transceive
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
// check for command error
|
|
||||||
if ($response instanceof ResponseException) {
|
|
||||||
if ($response->type() === 'unknownMethod') {
|
|
||||||
throw new JmapUnknownMethod($response->description(), 1);
|
|
||||||
} else {
|
|
||||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// convert jmap object to delta object
|
|
||||||
$delta = new Delta();
|
|
||||||
$delta->signature = $response->stateNew();
|
|
||||||
$delta->additions = new DeltaCollection(array_column($response->added(), 'id'));
|
|
||||||
$delta->modifications = new DeltaCollection([]);
|
|
||||||
$delta->deletions = new DeltaCollection(array_column($response->removed(), 'id'));
|
|
||||||
|
|
||||||
return $delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* delta of changes in remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function entityDeltaDefault(string $state, string $granularity = 'D'): Delta {
|
|
||||||
// construct set request
|
|
||||||
$r0 = new NodeQueryChanges($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
// set state constraint
|
|
||||||
if (!empty($state)) {
|
|
||||||
$r0->state($state);
|
|
||||||
} else {
|
|
||||||
$r0->state('');
|
|
||||||
}
|
|
||||||
// transceive
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
// check for command error
|
|
||||||
if ($response instanceof ResponseException) {
|
|
||||||
if ($response->type() === 'unknownMethod') {
|
|
||||||
throw new JmapUnknownMethod($response->description(), 1);
|
|
||||||
} else {
|
|
||||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// convert jmap object to delta object
|
|
||||||
$delta = new Delta();
|
|
||||||
$delta->signature = $response->stateNew();
|
|
||||||
$delta->additions = new DeltaCollection(array_column($response->added(), 'id'));
|
|
||||||
$delta->modifications = new DeltaCollection([]);
|
|
||||||
$delta->deletions = new DeltaCollection(array_column($response->removed(), 'id'));
|
|
||||||
|
|
||||||
return $delta;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* retrieve entity from remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function entityFetch(string ...$identifiers): ?array {
|
|
||||||
// construct request
|
|
||||||
$r0 = new NodeGet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
$r0->target(...$identifiers);
|
|
||||||
// transmit request and receive response
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
// convert json objects to message objects
|
|
||||||
$list = [];
|
|
||||||
foreach ($response->objects() as $so) {
|
|
||||||
if (!$so instanceof NodeParametersResponse) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$id = $so->id();
|
|
||||||
$list[$id] = $so->parametersRaw();
|
|
||||||
$list[$id]['signature'] = $response->state();
|
|
||||||
}
|
|
||||||
// return message collection
|
|
||||||
return $list;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* create entity in remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function entityCreate(string $location, array $so): ?array {
|
|
||||||
// convert entity
|
|
||||||
$to = new NodeParametersRequest();
|
|
||||||
$to->parametersRaw($so);
|
|
||||||
$to->in($location);
|
|
||||||
$id = uniqid();
|
|
||||||
// construct request
|
|
||||||
$r0 = new NodeSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
$r0->create($id, $to);
|
|
||||||
// transceive
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
// check for command error
|
|
||||||
if ($response instanceof ResponseException) {
|
|
||||||
if ($response->type() === 'unknownMethod') {
|
|
||||||
throw new JmapUnknownMethod($response->description(), 1);
|
|
||||||
} else {
|
|
||||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// check for success
|
|
||||||
$result = $response->createSuccess($id);
|
|
||||||
if ($result !== null) {
|
|
||||||
return array_merge($so, $result);
|
|
||||||
}
|
|
||||||
// check for failure
|
|
||||||
$result = $response->createFailure($id);
|
|
||||||
if ($result !== null) {
|
|
||||||
$type = $result['type'] ?? 'unknownError';
|
|
||||||
$description = $result['description'] ?? 'An unknown error occurred during collection creation.';
|
|
||||||
throw new Exception("$type: $description", 1);
|
|
||||||
}
|
|
||||||
// return null if creation failed without failure reason
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* update entity in remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function entityModify(array $so): ?array {
|
|
||||||
// extract entity id
|
|
||||||
$id = $so['id'];
|
|
||||||
// convert entity
|
|
||||||
$to = new NodeParametersRequest();
|
|
||||||
$to->parametersRaw($so);
|
|
||||||
// construct request
|
|
||||||
$r0 = new NodeSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
$r0->update($id, $to);
|
|
||||||
// transmit request and receive response
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
// determine if command succeeded
|
|
||||||
if (array_key_exists($id, $response->updated())) {
|
|
||||||
// update entity
|
|
||||||
$ro = $response->updated()[$id];
|
|
||||||
$so = array_merge($so, $ro);
|
|
||||||
return $so;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* delete entity from remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public function entityDelete(string $id): ?string {
|
|
||||||
// construct set request
|
|
||||||
$r0 = new NodeSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
// construct object
|
|
||||||
$r0->delete($id);
|
|
||||||
// transmit request and receive response
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
// determine if command succeeded
|
|
||||||
if (array_search($id, $response->deleted()) !== false) {
|
|
||||||
return $response->stateNew();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* copy entity in remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function entityCopy(string $location, MailMessageObject $so): ?MailMessageObject {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* move entity in remote storage
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public function entityMove(string $location, array $so): ?array {
|
|
||||||
// extract entity id
|
|
||||||
$id = $so['id'];
|
|
||||||
// construct request
|
|
||||||
$r0 = new NodeSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
|
||||||
$r0->update($id)->in($location);
|
|
||||||
// transmit request and receive response
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
|
||||||
// extract response
|
|
||||||
$response = $bundle->response(0);
|
|
||||||
// determine if command succeeded
|
|
||||||
if (array_key_exists($id, $response->updated())) {
|
|
||||||
$so = array_merge($so, ['mailboxIds' => [$location => true]]);
|
|
||||||
return $so;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,6 @@ use JmapClient\Requests\Mail\MailQuery;
|
|||||||
use JmapClient\Requests\Mail\MailQueryChanges;
|
use JmapClient\Requests\Mail\MailQueryChanges;
|
||||||
use JmapClient\Requests\Mail\MailSet;
|
use JmapClient\Requests\Mail\MailSet;
|
||||||
use JmapClient\Requests\Mail\MailSubmissionSet;
|
use JmapClient\Requests\Mail\MailSubmissionSet;
|
||||||
use JmapClient\Requests\RequestBundle;
|
|
||||||
use JmapClient\Responses\Mail\MailboxParameters as MailboxParametersResponse;
|
use JmapClient\Responses\Mail\MailboxParameters as MailboxParametersResponse;
|
||||||
use JmapClient\Responses\Mail\MailParameters as MailParametersResponse;
|
use JmapClient\Responses\Mail\MailParameters as MailParametersResponse;
|
||||||
use JmapClient\Responses\ResponseException;
|
use JmapClient\Responses\ResponseException;
|
||||||
@@ -636,7 +635,7 @@ class RemoteMailService {
|
|||||||
// select properties to return
|
// select properties to return
|
||||||
$r0->property(...$this->defaultMailProperties);
|
$r0->property(...$this->defaultMailProperties);
|
||||||
$r0->bodyAll(true);
|
$r0->bodyAll(true);
|
||||||
// transceive
|
// transmit request and receive response
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
$bundle = $this->dataStore->perform([$r0]);
|
||||||
// extract response
|
// extract response
|
||||||
$response = $bundle->response(0);
|
$response = $bundle->response(0);
|
||||||
@@ -710,7 +709,7 @@ class RemoteMailService {
|
|||||||
// construct request
|
// construct request
|
||||||
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||||
$r0->update($id, $to);
|
$r0->update($id, $to);
|
||||||
// transceive
|
// transmit request and receive response
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
$bundle = $this->dataStore->perform([$r0]);
|
||||||
// extract response
|
// extract response
|
||||||
$response = $bundle->response(0);
|
$response = $bundle->response(0);
|
||||||
@@ -734,7 +733,7 @@ class RemoteMailService {
|
|||||||
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||||
// construct object
|
// construct object
|
||||||
$r0->delete($id);
|
$r0->delete($id);
|
||||||
// transceive
|
// transmit request and receive response
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
$bundle = $this->dataStore->perform([$r0]);
|
||||||
// extract response
|
// extract response
|
||||||
$response = $bundle->response(0);
|
$response = $bundle->response(0);
|
||||||
@@ -751,8 +750,8 @@ class RemoteMailService {
|
|||||||
* @since Release 1.0.0
|
* @since Release 1.0.0
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function entityCopy(string $target, array $sources): array {
|
public function entityCopy(string $location, MailMessageObject $so): ?MailMessageObject {
|
||||||
return [];
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -761,42 +760,22 @@ class RemoteMailService {
|
|||||||
* @since Release 1.0.0
|
* @since Release 1.0.0
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function entityMove(string $target, array $sources): array {
|
public function entityMove(string $location, array $so): ?array {
|
||||||
|
// extract entity id
|
||||||
// extract identifiers from sources
|
$id = $so['id'];
|
||||||
$identifiers = [];
|
|
||||||
foreach ($sources as $source) {
|
|
||||||
$identifiers = array_merge($identifiers, $source);
|
|
||||||
}
|
|
||||||
// construct request
|
// construct request
|
||||||
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||||
foreach ($identifiers as $id) {
|
$r0->update($id)->in($location);
|
||||||
$r0->update($id)->in($target);
|
// transmit request and receive response
|
||||||
}
|
|
||||||
// transceive
|
|
||||||
$bundle = $this->dataStore->perform([$r0]);
|
$bundle = $this->dataStore->perform([$r0]);
|
||||||
// extract response
|
// extract response
|
||||||
$response = $bundle->first();
|
$response = $bundle->response(0);
|
||||||
// check for command error
|
// determine if command succeeded
|
||||||
if ($response instanceof ResponseException) {
|
if (array_key_exists($id, $response->updated())) {
|
||||||
if ($response->type() === 'unknownMethod') {
|
$so = array_merge($so, ['mailboxIds' => [$location => true]]);
|
||||||
throw new JmapUnknownMethod($response->description(), 1);
|
return $so;
|
||||||
} else {
|
|
||||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
$results = [];
|
|
||||||
// check for success
|
|
||||||
foreach ($response->updateSuccesses() as $identifier => $data) {
|
|
||||||
$results[$identifier] = true;
|
|
||||||
}
|
|
||||||
// check for failure
|
|
||||||
foreach ($response->updateFailures() as $identifier => $data) {
|
|
||||||
$results[$identifier] = $data['type'] ?? 'unknownError';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -845,7 +824,7 @@ class RemoteMailService {
|
|||||||
$e1->message('#1');
|
$e1->message('#1');
|
||||||
$e1->from($from);
|
$e1->from($from);
|
||||||
$e1->to($to);
|
$e1->to($to);
|
||||||
// transceive
|
// transmit request and receive response
|
||||||
$bundle = $this->dataStore->perform([$r0, $r1]);
|
$bundle = $this->dataStore->perform([$r0, $r1]);
|
||||||
// extract response
|
// extract response
|
||||||
$response = $bundle->response(1);
|
$response = $bundle->response(1);
|
||||||
|
|||||||
@@ -14,17 +14,12 @@ use JmapClient\Authentication\Bearer;
|
|||||||
use JmapClient\Authentication\JsonBasic;
|
use JmapClient\Authentication\JsonBasic;
|
||||||
use JmapClient\Authentication\JsonBasicCookie;
|
use JmapClient\Authentication\JsonBasicCookie;
|
||||||
use JmapClient\Client as JmapClient;
|
use JmapClient\Client as JmapClient;
|
||||||
use KTXC\Server;
|
|
||||||
use KTXF\Resource\Provider\ResourceServiceBaseInterface;
|
use KTXF\Resource\Provider\ResourceServiceBaseInterface;
|
||||||
use KTXF\Resource\Provider\ResourceServiceIdentityBasic;
|
use KTXF\Resource\Provider\ResourceServiceIdentityBasic;
|
||||||
use KTXF\Resource\Provider\ResourceServiceIdentityBearer;
|
use KTXF\Resource\Provider\ResourceServiceIdentityBearer;
|
||||||
use KTXF\Resource\Provider\ResourceServiceIdentityOAuth;
|
use KTXF\Resource\Provider\ResourceServiceIdentityOAuth;
|
||||||
use KTXF\Resource\Provider\ResourceServiceLocationUri;
|
use KTXF\Resource\Provider\ResourceServiceLocationUri;
|
||||||
use KTXM\ProviderJmapc\Providers\Mail\Service as MailService;
|
use KTXM\ProviderJmapc\Providers\Mail\Service;
|
||||||
use KTXM\ProviderJmapc\Providers\Contacts\Service as ContactsService;
|
|
||||||
use KTXM\ProviderJmapc\Providers\Events\Service as EventsService;
|
|
||||||
use KTXM\ProviderJmapc\Providers\Tasks\Service as TasksService;
|
|
||||||
use KTXM\ProviderJmapc\Providers\Document\Service as FilesService;
|
|
||||||
use KTXM\ProviderJmapc\Service\Remote\FM\RemoteContactsServiceFM;
|
use KTXM\ProviderJmapc\Service\Remote\FM\RemoteContactsServiceFM;
|
||||||
use KTXM\ProviderJmapc\Service\Remote\FM\RemoteCoreServiceFM;
|
use KTXM\ProviderJmapc\Service\Remote\FM\RemoteCoreServiceFM;
|
||||||
use KTXM\ProviderJmapc\Service\Remote\FM\RemoteEventsServiceFM;
|
use KTXM\ProviderJmapc\Service\Remote\FM\RemoteEventsServiceFM;
|
||||||
@@ -38,7 +33,7 @@ class RemoteService {
|
|||||||
*
|
*
|
||||||
* @since Release 1.0.0
|
* @since Release 1.0.0
|
||||||
*/
|
*/
|
||||||
public static function freshClient(MailService|FilesService $service): JmapClient {
|
public static function freshClient(Service $service): JmapClient {
|
||||||
|
|
||||||
// defaults
|
// defaults
|
||||||
$client = new JmapClient();
|
$client = new JmapClient();
|
||||||
@@ -103,7 +98,7 @@ class RemoteService {
|
|||||||
}
|
}
|
||||||
// construct service based on capabilities
|
// construct service based on capabilities
|
||||||
if ($Client->sessionCapable('https://www.fastmail.com/dev/user', false)) {
|
if ($Client->sessionCapable('https://www.fastmail.com/dev/user', false)) {
|
||||||
//$service = new RemoteCoreServiceFM();
|
$service = new RemoteCoreServiceFM();
|
||||||
} else {
|
} else {
|
||||||
$service = new RemoteCoreService();
|
$service = new RemoteCoreService();
|
||||||
}
|
}
|
||||||
@@ -181,21 +176,6 @@ class RemoteService {
|
|||||||
return $service;
|
return $service;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Appropriate Documents Service for Connection
|
|
||||||
*
|
|
||||||
* @since Release 1.0.0
|
|
||||||
*/
|
|
||||||
public static function documentsService(JmapClient $Client, ?string $dataAccount = null): RemoteFilesService {
|
|
||||||
// determine if client is connected
|
|
||||||
if (!$Client->sessionStatus()) {
|
|
||||||
$Client->connect();
|
|
||||||
}
|
|
||||||
$service = new RemoteFilesService();
|
|
||||||
$service->initialize($Client, $dataAccount);
|
|
||||||
return $service;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function cookieStoreRetrieve(mixed $id): ?array {
|
public static function cookieStoreRetrieve(mixed $id): ?array {
|
||||||
|
|
||||||
$file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc';
|
$file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc';
|
||||||
@@ -205,7 +185,7 @@ class RemoteService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data = file_get_contents($file);
|
$data = file_get_contents($file);
|
||||||
$crypto = Server::getInstance()->container()->get(\KTXF\Security\Crypto::class);
|
$crypto = \OC::$server->get(\OCP\Security\ICrypto::class);
|
||||||
$data = $crypto->decrypt($data);
|
$data = $crypto->decrypt($data);
|
||||||
|
|
||||||
if (!empty($data)) {
|
if (!empty($data)) {
|
||||||
@@ -222,7 +202,7 @@ class RemoteService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$crypto = Server::getInstance()->container()->get(\KTXF\Security\Crypto::class);
|
$crypto = \OC::$server->get(\OCP\Security\ICrypto::class);
|
||||||
$data = $crypto->encrypt(json_encode($value));
|
$data = $crypto->encrypt(json_encode($value));
|
||||||
|
|
||||||
$file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc';
|
$file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc';
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ class ServiceStore
|
|||||||
/**
|
/**
|
||||||
* Retrieve a single service by ID
|
* Retrieve a single service by ID
|
||||||
*/
|
*/
|
||||||
public function fetch(string $tenantId, string $userId, string|int $serviceId): ?array
|
public function fetch(string $tenantId, string $userId, string|int $serviceId): ?Service
|
||||||
{
|
{
|
||||||
$document = $this->dataStore->selectCollection(self::COLLECTION_NAME)->findOne([
|
$document = $this->dataStore->selectCollection(self::COLLECTION_NAME)->findOne([
|
||||||
'tid' => $tenantId,
|
'tid' => $tenantId,
|
||||||
@@ -107,13 +107,13 @@ class ServiceStore
|
|||||||
$document['identity']['secret'] = $this->crypto->decrypt($document['identity']['secret']);
|
$document['identity']['secret'] = $this->crypto->decrypt($document['identity']['secret']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $document;
|
return (new Service())->fromStore($document);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new service
|
* Create a new service
|
||||||
*/
|
*/
|
||||||
public function create(string $tenantId, string $userId, Service $service): array
|
public function create(string $tenantId, string $userId, Service $service): Service
|
||||||
{
|
{
|
||||||
$document = $service->toStore();
|
$document = $service->toStore();
|
||||||
|
|
||||||
@@ -129,15 +129,15 @@ class ServiceStore
|
|||||||
|
|
||||||
$result = $this->dataStore->selectCollection(self::COLLECTION_NAME)->insertOne($document);
|
$result = $this->dataStore->selectCollection(self::COLLECTION_NAME)->insertOne($document);
|
||||||
|
|
||||||
return $document;
|
return (new Service())->fromStore($document);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modify an existing service
|
* Modify an existing service
|
||||||
*/
|
*/
|
||||||
public function modify(string $tenantId, string $userId, Service $service): array
|
public function modify(string $tenantId, string $userId, Service $service): Service
|
||||||
{
|
{
|
||||||
$serviceId = $service->identifier();
|
$serviceId = $service->id();
|
||||||
if (empty($serviceId)) {
|
if (empty($serviceId)) {
|
||||||
throw new \InvalidArgumentException('Service ID is required for update');
|
throw new \InvalidArgumentException('Service ID is required for update');
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ class ServiceStore
|
|||||||
['$set' => $document]
|
['$set' => $document]
|
||||||
);
|
);
|
||||||
|
|
||||||
return $document;
|
return (new Service())->fromStore($document);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,229 +1,3 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { ref, watch, computed } from 'vue'
|
|
||||||
import type { ServiceLocationUri } from '@KTXM/MailManager/types/service'
|
|
||||||
|
|
||||||
// Types
|
|
||||||
interface ServiceConfiguration {
|
|
||||||
label?: string
|
|
||||||
auth?: 'BA' | 'OA' | 'JB'
|
|
||||||
bauth_id?: string
|
|
||||||
bauth_secret?: string
|
|
||||||
oauth_id?: string
|
|
||||||
oauth_access_token?: string
|
|
||||||
location_host?: string
|
|
||||||
location_protocol?: string
|
|
||||||
location_security?: boolean
|
|
||||||
location_port?: string
|
|
||||||
location_path?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
modelValue?: ServiceLocationUri
|
|
||||||
discoveredLocation?: ServiceLocationUri
|
|
||||||
service?: ServiceConfiguration
|
|
||||||
}>()
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
|
||||||
'update:modelValue': [value: ServiceLocationUri]
|
|
||||||
'update:service': [value: ServiceConfiguration]
|
|
||||||
}>()
|
|
||||||
|
|
||||||
// Initialize from discovered location or create new
|
|
||||||
function buildSessionUrl(location?: ServiceLocationUri): string {
|
|
||||||
if (!location || location.type !== 'URI') return ''
|
|
||||||
|
|
||||||
const protocol = location.scheme || 'https'
|
|
||||||
const host = location.host || ''
|
|
||||||
const port = location.port || (protocol === 'https' ? 443 : 80)
|
|
||||||
const path = location.path || '/.well-known/jmap'
|
|
||||||
|
|
||||||
// Don't include port if it's the default for the protocol
|
|
||||||
const portStr = (protocol === 'https' && port === 443) || (protocol === 'http' && port === 80)
|
|
||||||
? ''
|
|
||||||
: `:${port}`
|
|
||||||
|
|
||||||
return `${protocol}://${host}${portStr}${path}`
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseSessionUrl(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 || '/.well-known/jmap',
|
|
||||||
verifyPeer: verifyPeer.value,
|
|
||||||
verifyHost: verifyHost.value
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
return {
|
|
||||||
type: 'URI',
|
|
||||||
scheme: 'https',
|
|
||||||
host: '',
|
|
||||||
port: 443,
|
|
||||||
path: '/.well-known/jmap',
|
|
||||||
verifyPeer: verifyPeer.value,
|
|
||||||
verifyHost: verifyHost.value
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Account configuration fields
|
|
||||||
const accountLabel = ref(props.service?.label || 'New Connection')
|
|
||||||
const authType = ref<'BA' | 'OA' | 'JB'>(props.service?.auth || 'BA')
|
|
||||||
const bauthId = ref(props.service?.bauth_id || '')
|
|
||||||
const bauthSecret = ref(props.service?.bauth_secret || '')
|
|
||||||
const oauthId = ref(props.service?.oauth_id || '')
|
|
||||||
const oauthToken = ref(props.service?.oauth_access_token || '')
|
|
||||||
|
|
||||||
// Manual configuration toggle and fields
|
|
||||||
const configureManually = ref(false)
|
|
||||||
const serviceHost = ref(props.service?.location_host || '')
|
|
||||||
const serviceProtocol = ref(props.service?.location_protocol || 'https')
|
|
||||||
const servicePort = ref(props.service?.location_port || '')
|
|
||||||
const servicePath = ref(props.service?.location_path || '')
|
|
||||||
|
|
||||||
// Local state - protocol settings only
|
|
||||||
const sessionUrl = ref(buildSessionUrl(props.modelValue || props.discoveredLocation))
|
|
||||||
const capabilities = ref<string[]>(['urn:ietf:params:jmap:mail'])
|
|
||||||
const timeout = ref(30)
|
|
||||||
const verifyPeer = ref(
|
|
||||||
props.service?.location_security ?? props.modelValue?.verifyPeer ?? props.discoveredLocation?.verifyPeer ?? true
|
|
||||||
)
|
|
||||||
const verifyHost = ref(
|
|
||||||
props.modelValue?.verifyHost ?? props.discoveredLocation?.verifyHost ?? true
|
|
||||||
)
|
|
||||||
|
|
||||||
// Validation rules
|
|
||||||
const rules = {
|
|
||||||
required: (value: any) => !!value || 'This field is required',
|
|
||||||
url: (value: string) => {
|
|
||||||
try {
|
|
||||||
new URL(value)
|
|
||||||
return true
|
|
||||||
} catch {
|
|
||||||
return 'Please enter a valid URL'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build location from current state
|
|
||||||
const currentLocation = computed((): ServiceLocationUri | null => {
|
|
||||||
if (configureManually.value) {
|
|
||||||
// Build from manual fields
|
|
||||||
if (!serviceHost.value) return null
|
|
||||||
|
|
||||||
const port = servicePort.value
|
|
||||||
? parseInt(servicePort.value)
|
|
||||||
: (serviceProtocol.value === 'https' ? 443 : 80)
|
|
||||||
|
|
||||||
return {
|
|
||||||
type: 'URI',
|
|
||||||
scheme: serviceProtocol.value as 'http' | 'https',
|
|
||||||
host: serviceHost.value,
|
|
||||||
port,
|
|
||||||
path: servicePath.value || '/.well-known/jmap',
|
|
||||||
verifyPeer: verifyPeer.value,
|
|
||||||
verifyHost: verifyHost.value
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Build from session URL
|
|
||||||
if (!sessionUrl.value) return null
|
|
||||||
return parseSessionUrl(sessionUrl.value)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Build service configuration from current state
|
|
||||||
const currentService = computed((): ServiceConfiguration => {
|
|
||||||
return {
|
|
||||||
label: accountLabel.value,
|
|
||||||
auth: authType.value,
|
|
||||||
bauth_id: bauthId.value,
|
|
||||||
bauth_secret: bauthSecret.value,
|
|
||||||
oauth_id: oauthId.value,
|
|
||||||
oauth_access_token: oauthToken.value,
|
|
||||||
location_host: serviceHost.value,
|
|
||||||
location_protocol: serviceProtocol.value,
|
|
||||||
location_security: verifyPeer.value,
|
|
||||||
location_port: servicePort.value,
|
|
||||||
location_path: servicePath.value
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Emit location whenever it changes
|
|
||||||
watch(
|
|
||||||
[sessionUrl, serviceHost, serviceProtocol, servicePort, servicePath, verifyPeer, verifyHost, configureManually],
|
|
||||||
() => {
|
|
||||||
if (currentLocation.value) {
|
|
||||||
emit('update:modelValue', currentLocation.value)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ immediate: true }
|
|
||||||
)
|
|
||||||
|
|
||||||
// Emit service configuration whenever it changes
|
|
||||||
watch(
|
|
||||||
[accountLabel, authType, bauthId, bauthSecret, oauthId, oauthToken, serviceHost, serviceProtocol, servicePort, servicePath, verifyPeer],
|
|
||||||
() => {
|
|
||||||
emit('update:service', currentService.value)
|
|
||||||
},
|
|
||||||
{ immediate: true }
|
|
||||||
)
|
|
||||||
|
|
||||||
// Update local state when props change
|
|
||||||
watch(
|
|
||||||
() => props.modelValue,
|
|
||||||
(newValue) => {
|
|
||||||
if (newValue) {
|
|
||||||
sessionUrl.value = buildSessionUrl(newValue)
|
|
||||||
verifyPeer.value = newValue.verifyPeer ?? true
|
|
||||||
verifyHost.value = newValue.verifyHost ?? true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => props.discoveredLocation,
|
|
||||||
(newValue) => {
|
|
||||||
if (newValue && !props.modelValue) {
|
|
||||||
sessionUrl.value = buildSessionUrl(newValue)
|
|
||||||
verifyPeer.value = newValue.verifyPeer ?? true
|
|
||||||
verifyHost.value = newValue.verifyHost ?? true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ immediate: true }
|
|
||||||
)
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => props.service,
|
|
||||||
(newValue) => {
|
|
||||||
if (newValue) {
|
|
||||||
accountLabel.value = newValue.label || 'New Connection'
|
|
||||||
authType.value = newValue.auth || 'BA'
|
|
||||||
bauthId.value = newValue.bauth_id || ''
|
|
||||||
bauthSecret.value = newValue.bauth_secret || ''
|
|
||||||
oauthId.value = newValue.oauth_id || ''
|
|
||||||
oauthToken.value = newValue.oauth_access_token || ''
|
|
||||||
serviceHost.value = newValue.location_host || ''
|
|
||||||
serviceProtocol.value = newValue.location_protocol || 'https'
|
|
||||||
servicePort.value = newValue.location_port || ''
|
|
||||||
servicePath.value = newValue.location_path || ''
|
|
||||||
verifyPeer.value = newValue.location_security ?? true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
const jmapCapabilities = [
|
|
||||||
{ title: 'Mail', value: 'urn:ietf:params:jmap:mail' },
|
|
||||||
{ title: 'Contacts', value: 'urn:ietf:params:jmap:contacts' },
|
|
||||||
{ title: 'Calendars', value: 'urn:ietf:params:jmap:calendars' },
|
|
||||||
{ title: 'Tasks', value: 'urn:ietf:params:jmap:tasks' },
|
|
||||||
{ title: 'Notes', value: 'urn:ietf:params:jmap:notes' },
|
|
||||||
]
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="jmap-config-panel">
|
<div class="jmap-config-panel">
|
||||||
<h3 class="text-h6 mb-4">Connection</h3>
|
<h3 class="text-h6 mb-4">Connection</h3>
|
||||||
@@ -469,6 +243,232 @@ const jmapCapabilities = [
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref, watch, computed } from 'vue'
|
||||||
|
import type { ServiceLocationUri } from '@KTXM/MailManager/types/service'
|
||||||
|
|
||||||
|
// Types
|
||||||
|
interface ServiceConfiguration {
|
||||||
|
label?: string
|
||||||
|
auth?: 'BA' | 'OA' | 'JB'
|
||||||
|
bauth_id?: string
|
||||||
|
bauth_secret?: string
|
||||||
|
oauth_id?: string
|
||||||
|
oauth_access_token?: string
|
||||||
|
location_host?: string
|
||||||
|
location_protocol?: string
|
||||||
|
location_security?: boolean
|
||||||
|
location_port?: string
|
||||||
|
location_path?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
modelValue?: ServiceLocationUri
|
||||||
|
discoveredLocation?: ServiceLocationUri
|
||||||
|
service?: ServiceConfiguration
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:modelValue': [value: ServiceLocationUri]
|
||||||
|
'update:service': [value: ServiceConfiguration]
|
||||||
|
}>()
|
||||||
|
|
||||||
|
// Initialize from discovered location or create new
|
||||||
|
function buildSessionUrl(location?: ServiceLocationUri): string {
|
||||||
|
if (!location || location.type !== 'URI') return ''
|
||||||
|
|
||||||
|
const protocol = location.scheme || 'https'
|
||||||
|
const host = location.host || ''
|
||||||
|
const port = location.port || (protocol === 'https' ? 443 : 80)
|
||||||
|
const path = location.path || '/.well-known/jmap'
|
||||||
|
|
||||||
|
// Don't include port if it's the default for the protocol
|
||||||
|
const portStr = (protocol === 'https' && port === 443) || (protocol === 'http' && port === 80)
|
||||||
|
? ''
|
||||||
|
: `:${port}`
|
||||||
|
|
||||||
|
return `${protocol}://${host}${portStr}${path}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseSessionUrl(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 || '/.well-known/jmap',
|
||||||
|
verifyPeer: verifyPeer.value,
|
||||||
|
verifyHost: verifyHost.value
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return {
|
||||||
|
type: 'URI',
|
||||||
|
scheme: 'https',
|
||||||
|
host: '',
|
||||||
|
port: 443,
|
||||||
|
path: '/.well-known/jmap',
|
||||||
|
verifyPeer: verifyPeer.value,
|
||||||
|
verifyHost: verifyHost.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Account configuration fields
|
||||||
|
const accountLabel = ref(props.service?.label || 'New Connection')
|
||||||
|
const authType = ref<'BA' | 'OA' | 'JB'>(props.service?.auth || 'BA')
|
||||||
|
const bauthId = ref(props.service?.bauth_id || '')
|
||||||
|
const bauthSecret = ref(props.service?.bauth_secret || '')
|
||||||
|
const oauthId = ref(props.service?.oauth_id || '')
|
||||||
|
const oauthToken = ref(props.service?.oauth_access_token || '')
|
||||||
|
|
||||||
|
// Manual configuration toggle and fields
|
||||||
|
const configureManually = ref(false)
|
||||||
|
const serviceHost = ref(props.service?.location_host || '')
|
||||||
|
const serviceProtocol = ref(props.service?.location_protocol || 'https')
|
||||||
|
const servicePort = ref(props.service?.location_port || '')
|
||||||
|
const servicePath = ref(props.service?.location_path || '')
|
||||||
|
|
||||||
|
// Local state - protocol settings only
|
||||||
|
const sessionUrl = ref(buildSessionUrl(props.modelValue || props.discoveredLocation))
|
||||||
|
const capabilities = ref<string[]>(['urn:ietf:params:jmap:mail'])
|
||||||
|
const timeout = ref(30)
|
||||||
|
const verifyPeer = ref(
|
||||||
|
props.service?.location_security ?? props.modelValue?.verifyPeer ?? props.discoveredLocation?.verifyPeer ?? true
|
||||||
|
)
|
||||||
|
const verifyHost = ref(
|
||||||
|
props.modelValue?.verifyHost ?? props.discoveredLocation?.verifyHost ?? true
|
||||||
|
)
|
||||||
|
|
||||||
|
// Validation rules
|
||||||
|
const rules = {
|
||||||
|
required: (value: any) => !!value || 'This field is required',
|
||||||
|
url: (value: string) => {
|
||||||
|
try {
|
||||||
|
new URL(value)
|
||||||
|
return true
|
||||||
|
} catch {
|
||||||
|
return 'Please enter a valid URL'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build location from current state
|
||||||
|
const currentLocation = computed((): ServiceLocationUri | null => {
|
||||||
|
if (configureManually.value) {
|
||||||
|
// Build from manual fields
|
||||||
|
if (!serviceHost.value) return null
|
||||||
|
|
||||||
|
const port = servicePort.value
|
||||||
|
? parseInt(servicePort.value)
|
||||||
|
: (serviceProtocol.value === 'https' ? 443 : 80)
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'URI',
|
||||||
|
scheme: serviceProtocol.value as 'http' | 'https',
|
||||||
|
host: serviceHost.value,
|
||||||
|
port,
|
||||||
|
path: servicePath.value || '/.well-known/jmap',
|
||||||
|
verifyPeer: verifyPeer.value,
|
||||||
|
verifyHost: verifyHost.value
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Build from session URL
|
||||||
|
if (!sessionUrl.value) return null
|
||||||
|
return parseSessionUrl(sessionUrl.value)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Build service configuration from current state
|
||||||
|
const currentService = computed((): ServiceConfiguration => {
|
||||||
|
return {
|
||||||
|
label: accountLabel.value,
|
||||||
|
auth: authType.value,
|
||||||
|
bauth_id: bauthId.value,
|
||||||
|
bauth_secret: bauthSecret.value,
|
||||||
|
oauth_id: oauthId.value,
|
||||||
|
oauth_access_token: oauthToken.value,
|
||||||
|
location_host: serviceHost.value,
|
||||||
|
location_protocol: serviceProtocol.value,
|
||||||
|
location_security: verifyPeer.value,
|
||||||
|
location_port: servicePort.value,
|
||||||
|
location_path: servicePath.value
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Emit location whenever it changes
|
||||||
|
watch(
|
||||||
|
[sessionUrl, serviceHost, serviceProtocol, servicePort, servicePath, verifyPeer, verifyHost, configureManually],
|
||||||
|
() => {
|
||||||
|
if (currentLocation.value) {
|
||||||
|
emit('update:modelValue', currentLocation.value)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
// Emit service configuration whenever it changes
|
||||||
|
watch(
|
||||||
|
[accountLabel, authType, bauthId, bauthSecret, oauthId, oauthToken, serviceHost, serviceProtocol, servicePort, servicePath, verifyPeer],
|
||||||
|
() => {
|
||||||
|
emit('update:service', currentService.value)
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
// Update local state when props change
|
||||||
|
watch(
|
||||||
|
() => props.modelValue,
|
||||||
|
(newValue) => {
|
||||||
|
if (newValue) {
|
||||||
|
sessionUrl.value = buildSessionUrl(newValue)
|
||||||
|
verifyPeer.value = newValue.verifyPeer ?? true
|
||||||
|
verifyHost.value = newValue.verifyHost ?? true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.discoveredLocation,
|
||||||
|
(newValue) => {
|
||||||
|
if (newValue && !props.modelValue) {
|
||||||
|
sessionUrl.value = buildSessionUrl(newValue)
|
||||||
|
verifyPeer.value = newValue.verifyPeer ?? true
|
||||||
|
verifyHost.value = newValue.verifyHost ?? true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{ immediate: true }
|
||||||
|
)
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.service,
|
||||||
|
(newValue) => {
|
||||||
|
if (newValue) {
|
||||||
|
accountLabel.value = newValue.label || 'New Connection'
|
||||||
|
authType.value = newValue.auth || 'BA'
|
||||||
|
bauthId.value = newValue.bauth_id || ''
|
||||||
|
bauthSecret.value = newValue.bauth_secret || ''
|
||||||
|
oauthId.value = newValue.oauth_id || ''
|
||||||
|
oauthToken.value = newValue.oauth_access_token || ''
|
||||||
|
serviceHost.value = newValue.location_host || ''
|
||||||
|
serviceProtocol.value = newValue.location_protocol || 'https'
|
||||||
|
servicePort.value = newValue.location_port || ''
|
||||||
|
servicePath.value = newValue.location_path || ''
|
||||||
|
verifyPeer.value = newValue.location_security ?? true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const jmapCapabilities = [
|
||||||
|
{ title: 'Mail', value: 'urn:ietf:params:jmap:mail' },
|
||||||
|
{ title: 'Contacts', value: 'urn:ietf:params:jmap:contacts' },
|
||||||
|
{ title: 'Calendars', value: 'urn:ietf:params:jmap:calendars' },
|
||||||
|
{ title: 'Tasks', value: 'urn:ietf:params:jmap:tasks' },
|
||||||
|
{ title: 'Notes', value: 'urn:ietf:params:jmap:notes' },
|
||||||
|
]
|
||||||
|
</script>
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.jmap-config-panel {
|
.jmap-config-panel {
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
|
|||||||
@@ -1,3 +1,124 @@
|
|||||||
|
<template>
|
||||||
|
<div class="jmap-auth-panel">
|
||||||
|
<h3 class="text-h6 mb-4">Authentication</h3>
|
||||||
|
<p class="text-body-2 mb-6">Choose your authentication method and enter your credentials.</p>
|
||||||
|
|
||||||
|
<v-alert type="info" variant="tonal" class="mb-4">
|
||||||
|
<template #prepend>
|
||||||
|
<v-icon>mdi-information</v-icon>
|
||||||
|
</template>
|
||||||
|
<div class="text-caption">
|
||||||
|
JMAP supports multiple authentication methods. Choose the one your server uses.
|
||||||
|
</div>
|
||||||
|
</v-alert>
|
||||||
|
|
||||||
|
<!-- Authentication Type Selection -->
|
||||||
|
<div class="mb-4">
|
||||||
|
<label class="text-subtitle-2 mb-2 d-block">Authentication Method</label>
|
||||||
|
<v-btn-toggle
|
||||||
|
v-model="authType"
|
||||||
|
color="primary"
|
||||||
|
variant="outlined"
|
||||||
|
mandatory
|
||||||
|
divided
|
||||||
|
class="mb-4"
|
||||||
|
>
|
||||||
|
<v-btn value="BA">
|
||||||
|
<v-icon start>mdi-account-key</v-icon>
|
||||||
|
Basic Auth
|
||||||
|
</v-btn>
|
||||||
|
<v-btn value="TA">
|
||||||
|
<v-icon start>mdi-key</v-icon>
|
||||||
|
Bearer Token
|
||||||
|
</v-btn>
|
||||||
|
<v-btn value="OA">
|
||||||
|
<v-icon start>mdi-shield-account</v-icon>
|
||||||
|
OAuth 2.0
|
||||||
|
</v-btn>
|
||||||
|
</v-btn-toggle>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Basic Authentication -->
|
||||||
|
<template v-if="authType === 'BA'">
|
||||||
|
<v-text-field
|
||||||
|
v-model="basicIdentity"
|
||||||
|
label="Username / Email"
|
||||||
|
hint="Your account username or email address"
|
||||||
|
persistent-hint
|
||||||
|
variant="outlined"
|
||||||
|
prepend-inner-icon="mdi-account"
|
||||||
|
class="mb-4"
|
||||||
|
autocomplete="username"
|
||||||
|
autocorrect="off"
|
||||||
|
autocapitalize="none"
|
||||||
|
:rules="[rules.required]"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<v-text-field
|
||||||
|
v-model="basicSecret"
|
||||||
|
type="password"
|
||||||
|
label="Password"
|
||||||
|
hint="Your account password"
|
||||||
|
persistent-hint
|
||||||
|
variant="outlined"
|
||||||
|
prepend-inner-icon="mdi-lock"
|
||||||
|
class="mb-4"
|
||||||
|
autocomplete="current-password"
|
||||||
|
:rules="[rules.required]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Bearer Token Authentication -->
|
||||||
|
<template v-else-if="authType === 'TA'">
|
||||||
|
<v-textarea
|
||||||
|
v-model="bearerToken"
|
||||||
|
label="Bearer Token"
|
||||||
|
hint="Enter your API token or bearer token"
|
||||||
|
persistent-hint
|
||||||
|
variant="outlined"
|
||||||
|
prepend-inner-icon="mdi-key"
|
||||||
|
class="mb-4"
|
||||||
|
rows="3"
|
||||||
|
autocomplete="off"
|
||||||
|
autocorrect="off"
|
||||||
|
autocapitalize="none"
|
||||||
|
:rules="[rules.required]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- OAuth 2.0 -->
|
||||||
|
<template v-else-if="authType === 'OA'">
|
||||||
|
<v-alert type="warning" variant="tonal" class="mb-4">
|
||||||
|
<template #prepend>
|
||||||
|
<v-icon>mdi-alert</v-icon>
|
||||||
|
</template>
|
||||||
|
<div class="text-caption">
|
||||||
|
OAuth 2.0 implementation is pending. This will launch a browser window
|
||||||
|
for secure authentication with your JMAP provider.
|
||||||
|
</div>
|
||||||
|
</v-alert>
|
||||||
|
|
||||||
|
<v-btn
|
||||||
|
v-if="!oauthSuccess"
|
||||||
|
color="primary"
|
||||||
|
size="large"
|
||||||
|
block
|
||||||
|
@click="initiateOAuth"
|
||||||
|
:loading="oauthLoading"
|
||||||
|
:disabled="true"
|
||||||
|
>
|
||||||
|
<v-icon start>mdi-login</v-icon>
|
||||||
|
Authorize with OAuth 2.0
|
||||||
|
</v-btn>
|
||||||
|
|
||||||
|
<div v-else class="text-center py-4">
|
||||||
|
<v-icon color="success" size="64">mdi-check-circle</v-icon>
|
||||||
|
<p class="text-subtitle-1 mt-2">OAuth Authorized Successfully</p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, watch } from 'vue'
|
import { ref, computed, watch } from 'vue'
|
||||||
import type { ServiceIdentity } from '@KTXM/MailManager/types/service'
|
import type { ServiceIdentity } from '@KTXM/MailManager/types/service'
|
||||||
@@ -140,127 +261,6 @@ async function initiateOAuth() {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="jmap-auth-panel">
|
|
||||||
<h3 class="text-h6 mb-4">Authentication</h3>
|
|
||||||
<p class="text-body-2 mb-6">Choose your authentication method and enter your credentials.</p>
|
|
||||||
|
|
||||||
<v-alert type="info" variant="tonal" class="mb-4">
|
|
||||||
<template #prepend>
|
|
||||||
<v-icon>mdi-information</v-icon>
|
|
||||||
</template>
|
|
||||||
<div class="text-caption">
|
|
||||||
JMAP supports multiple authentication methods. Choose the one your server uses.
|
|
||||||
</div>
|
|
||||||
</v-alert>
|
|
||||||
|
|
||||||
<!-- Authentication Type Selection -->
|
|
||||||
<div class="mb-4">
|
|
||||||
<label class="text-subtitle-2 mb-2 d-block">Authentication Method</label>
|
|
||||||
<v-btn-toggle
|
|
||||||
v-model="authType"
|
|
||||||
color="primary"
|
|
||||||
variant="outlined"
|
|
||||||
mandatory
|
|
||||||
divided
|
|
||||||
class="mb-4"
|
|
||||||
>
|
|
||||||
<v-btn value="BA">
|
|
||||||
<v-icon start>mdi-account-key</v-icon>
|
|
||||||
Basic Auth
|
|
||||||
</v-btn>
|
|
||||||
<v-btn value="TA">
|
|
||||||
<v-icon start>mdi-key</v-icon>
|
|
||||||
Bearer Token
|
|
||||||
</v-btn>
|
|
||||||
<v-btn value="OA">
|
|
||||||
<v-icon start>mdi-shield-account</v-icon>
|
|
||||||
OAuth 2.0
|
|
||||||
</v-btn>
|
|
||||||
</v-btn-toggle>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Basic Authentication -->
|
|
||||||
<template v-if="authType === 'BA'">
|
|
||||||
<v-text-field
|
|
||||||
v-model="basicIdentity"
|
|
||||||
label="Username / Email"
|
|
||||||
hint="Your account username or email address"
|
|
||||||
persistent-hint
|
|
||||||
variant="outlined"
|
|
||||||
prepend-inner-icon="mdi-account"
|
|
||||||
class="mb-4"
|
|
||||||
autocomplete="username"
|
|
||||||
autocorrect="off"
|
|
||||||
autocapitalize="none"
|
|
||||||
:rules="[rules.required]"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<v-text-field
|
|
||||||
v-model="basicSecret"
|
|
||||||
type="password"
|
|
||||||
label="Password"
|
|
||||||
hint="Your account password"
|
|
||||||
persistent-hint
|
|
||||||
variant="outlined"
|
|
||||||
prepend-inner-icon="mdi-lock"
|
|
||||||
class="mb-4"
|
|
||||||
autocomplete="current-password"
|
|
||||||
:rules="[rules.required]"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- Bearer Token Authentication -->
|
|
||||||
<template v-else-if="authType === 'TA'">
|
|
||||||
<v-textarea
|
|
||||||
v-model="bearerToken"
|
|
||||||
label="Bearer Token"
|
|
||||||
hint="Enter your API token or bearer token"
|
|
||||||
persistent-hint
|
|
||||||
variant="outlined"
|
|
||||||
prepend-inner-icon="mdi-key"
|
|
||||||
class="mb-4"
|
|
||||||
rows="3"
|
|
||||||
autocomplete="off"
|
|
||||||
autocorrect="off"
|
|
||||||
autocapitalize="none"
|
|
||||||
:rules="[rules.required]"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- OAuth 2.0 -->
|
|
||||||
<template v-else-if="authType === 'OA'">
|
|
||||||
<v-alert type="warning" variant="tonal" class="mb-4">
|
|
||||||
<template #prepend>
|
|
||||||
<v-icon>mdi-alert</v-icon>
|
|
||||||
</template>
|
|
||||||
<div class="text-caption">
|
|
||||||
OAuth 2.0 implementation is pending. This will launch a browser window
|
|
||||||
for secure authentication with your JMAP provider.
|
|
||||||
</div>
|
|
||||||
</v-alert>
|
|
||||||
|
|
||||||
<v-btn
|
|
||||||
v-if="!oauthSuccess"
|
|
||||||
color="primary"
|
|
||||||
size="large"
|
|
||||||
block
|
|
||||||
@click="initiateOAuth"
|
|
||||||
:loading="oauthLoading"
|
|
||||||
:disabled="true"
|
|
||||||
>
|
|
||||||
<v-icon start>mdi-login</v-icon>
|
|
||||||
Authorize with OAuth 2.0
|
|
||||||
</v-btn>
|
|
||||||
|
|
||||||
<div v-else class="text-center py-4">
|
|
||||||
<v-icon color="success" size="64">mdi-check-circle</v-icon>
|
|
||||||
<p class="text-subtitle-1 mt-2">OAuth Authorized Successfully</p>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.jmap-auth-panel {
|
.jmap-auth-panel {
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
|
|||||||
@@ -1,3 +1,156 @@
|
|||||||
|
<template>
|
||||||
|
<div class="jmap-config-panel">
|
||||||
|
<h3 class="text-h6 mb-4">JMAP Connection Settings</h3>
|
||||||
|
<p class="text-body-2 mb-6">Configure how to connect to your JMAP server.</p>
|
||||||
|
|
||||||
|
<!-- Manual Configuration Toggle -->
|
||||||
|
<v-switch
|
||||||
|
v-model="configureManually"
|
||||||
|
label="Configure server manually"
|
||||||
|
color="primary"
|
||||||
|
class="mb-4"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- Session URL (Simple Mode) -->
|
||||||
|
<template v-if="!configureManually">
|
||||||
|
<v-text-field
|
||||||
|
v-model="sessionUrl"
|
||||||
|
label="JMAP Session URL"
|
||||||
|
hint="e.g., https://jmap.example.com/.well-known/jmap"
|
||||||
|
persistent-hint
|
||||||
|
variant="outlined"
|
||||||
|
prepend-inner-icon="mdi-link"
|
||||||
|
class="mb-4"
|
||||||
|
:rules="[rules.required, rules.url]"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Manual Configuration Fields -->
|
||||||
|
<template v-if="configureManually">
|
||||||
|
<v-text-field
|
||||||
|
v-model="serviceHost"
|
||||||
|
label="Service Address"
|
||||||
|
hint="Domain or IP Address"
|
||||||
|
persistent-hint
|
||||||
|
variant="outlined"
|
||||||
|
prepend-inner-icon="mdi-server"
|
||||||
|
class="mb-4"
|
||||||
|
autocomplete="off"
|
||||||
|
autocorrect="off"
|
||||||
|
autocapitalize="none"
|
||||||
|
:rules="[rules.required]"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="mb-4">
|
||||||
|
<label class="text-subtitle-2 mb-2 d-block">Service Protocol</label>
|
||||||
|
<v-btn-toggle
|
||||||
|
v-model="serviceProtocol"
|
||||||
|
color="primary"
|
||||||
|
variant="outlined"
|
||||||
|
mandatory
|
||||||
|
divided
|
||||||
|
>
|
||||||
|
<v-btn value="http">http</v-btn>
|
||||||
|
<v-btn value="https">https</v-btn>
|
||||||
|
</v-btn-toggle>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<v-switch
|
||||||
|
v-model="verifyPeer"
|
||||||
|
label="Secure Transport Verification (SSL Certificate Verification)"
|
||||||
|
color="primary"
|
||||||
|
class="mb-4"
|
||||||
|
hint="Should always be ON, unless connecting to a service over a secure internal network"
|
||||||
|
persistent-hint
|
||||||
|
/>
|
||||||
|
|
||||||
|
<v-text-field
|
||||||
|
v-model="servicePort"
|
||||||
|
label="Service Port"
|
||||||
|
hint="Leave empty for default. http (80) https (443)"
|
||||||
|
persistent-hint
|
||||||
|
variant="outlined"
|
||||||
|
prepend-inner-icon="mdi-numeric"
|
||||||
|
class="mb-4"
|
||||||
|
autocomplete="off"
|
||||||
|
autocorrect="off"
|
||||||
|
autocapitalize="none"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<v-text-field
|
||||||
|
v-model="servicePath"
|
||||||
|
label="Service Path"
|
||||||
|
hint="Leave empty for default path (/.well-known/jmap)"
|
||||||
|
persistent-hint
|
||||||
|
variant="outlined"
|
||||||
|
prepend-inner-icon="mdi-folder"
|
||||||
|
class="mb-4"
|
||||||
|
autocomplete="off"
|
||||||
|
autocorrect="off"
|
||||||
|
autocapitalize="none"
|
||||||
|
/>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<!-- Advanced Settings -->
|
||||||
|
<v-expansion-panels class="mt-4">
|
||||||
|
<v-expansion-panel>
|
||||||
|
<v-expansion-panel-title>
|
||||||
|
<v-icon start>mdi-cog</v-icon>
|
||||||
|
Advanced Settings
|
||||||
|
</v-expansion-panel-title>
|
||||||
|
<v-expansion-panel-text>
|
||||||
|
<v-select
|
||||||
|
v-model="capabilities"
|
||||||
|
:items="jmapCapabilities"
|
||||||
|
label="Enabled Capabilities"
|
||||||
|
multiple
|
||||||
|
chips
|
||||||
|
variant="outlined"
|
||||||
|
hint="Select which JMAP capabilities to enable"
|
||||||
|
persistent-hint
|
||||||
|
/>
|
||||||
|
|
||||||
|
<v-text-field
|
||||||
|
v-model.number="timeout"
|
||||||
|
type="number"
|
||||||
|
label="Timeout (seconds)"
|
||||||
|
variant="outlined"
|
||||||
|
class="mt-4"
|
||||||
|
hint="Connection timeout in seconds"
|
||||||
|
persistent-hint
|
||||||
|
:min="5"
|
||||||
|
:max="300"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<v-switch
|
||||||
|
v-model="verifyHost"
|
||||||
|
label="Verify SSL Hostname"
|
||||||
|
color="primary"
|
||||||
|
hint="Verify the certificate matches the hostname"
|
||||||
|
persistent-hint
|
||||||
|
/>
|
||||||
|
</v-expansion-panel-text>
|
||||||
|
</v-expansion-panel>
|
||||||
|
</v-expansion-panels>
|
||||||
|
|
||||||
|
<!-- Info Alert -->
|
||||||
|
<v-alert
|
||||||
|
type="info"
|
||||||
|
variant="tonal"
|
||||||
|
density="compact"
|
||||||
|
class="mt-4"
|
||||||
|
>
|
||||||
|
<template #prepend>
|
||||||
|
<v-icon>mdi-information</v-icon>
|
||||||
|
</template>
|
||||||
|
<div class="text-caption">
|
||||||
|
JMAP is a modern protocol for mail access. Most JMAP servers use
|
||||||
|
<code>/.well-known/jmap</code> for autodiscovery.
|
||||||
|
</div>
|
||||||
|
</v-alert>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch, computed } from 'vue'
|
import { ref, watch, computed } from 'vue'
|
||||||
import type { ServiceLocationUri, ServiceLocation } from '@KTXM/MailManager/types/service'
|
import type { ServiceLocationUri, ServiceLocation } from '@KTXM/MailManager/types/service'
|
||||||
@@ -173,159 +326,6 @@ const jmapCapabilities = [
|
|||||||
]
|
]
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
|
||||||
<div class="jmap-config-panel">
|
|
||||||
<h3 class="text-h6 mb-4">JMAP Connection Settings</h3>
|
|
||||||
<p class="text-body-2 mb-6">Configure how to connect to your JMAP server.</p>
|
|
||||||
|
|
||||||
<!-- Manual Configuration Toggle -->
|
|
||||||
<v-switch
|
|
||||||
v-model="configureManually"
|
|
||||||
label="Configure server manually"
|
|
||||||
color="primary"
|
|
||||||
class="mb-4"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- Session URL (Simple Mode) -->
|
|
||||||
<template v-if="!configureManually">
|
|
||||||
<v-text-field
|
|
||||||
v-model="sessionUrl"
|
|
||||||
label="JMAP Session URL"
|
|
||||||
hint="e.g., https://jmap.example.com/.well-known/jmap"
|
|
||||||
persistent-hint
|
|
||||||
variant="outlined"
|
|
||||||
prepend-inner-icon="mdi-link"
|
|
||||||
class="mb-4"
|
|
||||||
:rules="[rules.required, rules.url]"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- Manual Configuration Fields -->
|
|
||||||
<template v-if="configureManually">
|
|
||||||
<v-text-field
|
|
||||||
v-model="serviceHost"
|
|
||||||
label="Service Address"
|
|
||||||
hint="Domain or IP Address"
|
|
||||||
persistent-hint
|
|
||||||
variant="outlined"
|
|
||||||
prepend-inner-icon="mdi-server"
|
|
||||||
class="mb-4"
|
|
||||||
autocomplete="off"
|
|
||||||
autocorrect="off"
|
|
||||||
autocapitalize="none"
|
|
||||||
:rules="[rules.required]"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<div class="mb-4">
|
|
||||||
<label class="text-subtitle-2 mb-2 d-block">Service Protocol</label>
|
|
||||||
<v-btn-toggle
|
|
||||||
v-model="serviceProtocol"
|
|
||||||
color="primary"
|
|
||||||
variant="outlined"
|
|
||||||
mandatory
|
|
||||||
divided
|
|
||||||
>
|
|
||||||
<v-btn value="http">http</v-btn>
|
|
||||||
<v-btn value="https">https</v-btn>
|
|
||||||
</v-btn-toggle>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<v-switch
|
|
||||||
v-model="verifyPeer"
|
|
||||||
label="Secure Transport Verification (SSL Certificate Verification)"
|
|
||||||
color="primary"
|
|
||||||
class="mb-4"
|
|
||||||
hint="Should always be ON, unless connecting to a service over a secure internal network"
|
|
||||||
persistent-hint
|
|
||||||
/>
|
|
||||||
|
|
||||||
<v-text-field
|
|
||||||
v-model="servicePort"
|
|
||||||
label="Service Port"
|
|
||||||
hint="Leave empty for default. http (80) https (443)"
|
|
||||||
persistent-hint
|
|
||||||
variant="outlined"
|
|
||||||
prepend-inner-icon="mdi-numeric"
|
|
||||||
class="mb-4"
|
|
||||||
autocomplete="off"
|
|
||||||
autocorrect="off"
|
|
||||||
autocapitalize="none"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<v-text-field
|
|
||||||
v-model="servicePath"
|
|
||||||
label="Service Path"
|
|
||||||
hint="Leave empty for default path (/.well-known/jmap)"
|
|
||||||
persistent-hint
|
|
||||||
variant="outlined"
|
|
||||||
prepend-inner-icon="mdi-folder"
|
|
||||||
class="mb-4"
|
|
||||||
autocomplete="off"
|
|
||||||
autocorrect="off"
|
|
||||||
autocapitalize="none"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<!-- Advanced Settings -->
|
|
||||||
<v-expansion-panels class="mt-4">
|
|
||||||
<v-expansion-panel>
|
|
||||||
<v-expansion-panel-title>
|
|
||||||
<v-icon start>mdi-cog</v-icon>
|
|
||||||
Advanced Settings
|
|
||||||
</v-expansion-panel-title>
|
|
||||||
<v-expansion-panel-text>
|
|
||||||
<v-select
|
|
||||||
v-model="capabilities"
|
|
||||||
:items="jmapCapabilities"
|
|
||||||
label="Enabled Capabilities"
|
|
||||||
multiple
|
|
||||||
chips
|
|
||||||
variant="outlined"
|
|
||||||
hint="Select which JMAP capabilities to enable"
|
|
||||||
persistent-hint
|
|
||||||
/>
|
|
||||||
|
|
||||||
<v-text-field
|
|
||||||
v-model.number="timeout"
|
|
||||||
type="number"
|
|
||||||
label="Timeout (seconds)"
|
|
||||||
variant="outlined"
|
|
||||||
class="mt-4"
|
|
||||||
hint="Connection timeout in seconds"
|
|
||||||
persistent-hint
|
|
||||||
:min="5"
|
|
||||||
:max="300"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<v-switch
|
|
||||||
v-model="verifyHost"
|
|
||||||
label="Verify SSL Hostname"
|
|
||||||
color="primary"
|
|
||||||
hint="Verify the certificate matches the hostname"
|
|
||||||
persistent-hint
|
|
||||||
/>
|
|
||||||
</v-expansion-panel-text>
|
|
||||||
</v-expansion-panel>
|
|
||||||
</v-expansion-panels>
|
|
||||||
|
|
||||||
<!-- Info Alert -->
|
|
||||||
<v-alert
|
|
||||||
type="info"
|
|
||||||
variant="tonal"
|
|
||||||
density="compact"
|
|
||||||
class="mt-4"
|
|
||||||
>
|
|
||||||
<template #prepend>
|
|
||||||
<v-icon>mdi-information</v-icon>
|
|
||||||
</template>
|
|
||||||
<div class="text-caption">
|
|
||||||
JMAP is a modern protocol for mail access. Most JMAP servers use
|
|
||||||
<code>/.well-known/jmap</code> for autodiscovery.
|
|
||||||
</div>
|
|
||||||
</v-alert>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
<style scoped>
|
||||||
.jmap-config-panel {
|
.jmap-config-panel {
|
||||||
max-width: 800px;
|
max-width: 800px;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { ModuleIntegrations } from "@KTXC/types/moduleTypes";
|
import type { ModuleIntegrations } from "@KTXC/types/moduleTypes";
|
||||||
|
import type { ProviderMetadata } from "@KTXM/MailManager/types/provider";
|
||||||
import type { ServiceInterface } from "@KTXM/MailManager/types/service";
|
import type { ServiceInterface } from "@KTXM/MailManager/types/service";
|
||||||
import { JmapServiceObject } from './models/JmapServiceObject'
|
import { JmapServiceObject } from './models/JmapServiceObject'
|
||||||
|
|
||||||
@@ -31,7 +32,25 @@ const integrations: ModuleIntegrations = {
|
|||||||
label: 'JMAP',
|
label: 'JMAP',
|
||||||
description: 'Modern JSON-based mail API protocol',
|
description: 'Modern JSON-based mail API protocol',
|
||||||
icon: 'mdi-api',
|
icon: 'mdi-api',
|
||||||
}
|
auth: {
|
||||||
|
methods: ['BA', 'OA', 'TA'],
|
||||||
|
default: 'BA',
|
||||||
|
allowMethodSelection: true,
|
||||||
|
oauth: {
|
||||||
|
// OAuth config will be provider-specific
|
||||||
|
// Some JMAP providers use OAuth (e.g., Fastmail)
|
||||||
|
authorizeUrl: '', // Configured per-instance
|
||||||
|
tokenUrl: '',
|
||||||
|
scopes: ['mail'],
|
||||||
|
flowType: 'authorization_code'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
supportsDiscovery: true,
|
||||||
|
meta: {
|
||||||
|
protocol: 'JMAP',
|
||||||
|
wellKnownPath: '/.well-known/jmap'
|
||||||
|
}
|
||||||
|
} as ProviderMetadata
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
81
src/services/serviceService.ts
Normal file
81
src/services/serviceService.ts
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import { fetchWrapper } from '@KTXC/utils/helpers/fetch-wrapper';
|
||||||
|
import type {
|
||||||
|
Service,
|
||||||
|
ConnectionTestRequest,
|
||||||
|
ConnectionTestResponse,
|
||||||
|
CollectionsResponse,
|
||||||
|
DiscoverResponse
|
||||||
|
} from '@/models/service';
|
||||||
|
|
||||||
|
const BASE_PATH = '/m/provider_jmapc';
|
||||||
|
|
||||||
|
export const serviceService = {
|
||||||
|
/**
|
||||||
|
* List all JMAP services for current user
|
||||||
|
*/
|
||||||
|
async list(capability?: string): Promise<{ services: Service[] }> {
|
||||||
|
const params = capability ? `?capability=${encodeURIComponent(capability)}` : '';
|
||||||
|
return fetchWrapper.get(`${BASE_PATH}/services${params}`);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a single service by ID
|
||||||
|
*/
|
||||||
|
async fetch(id: string): Promise<Service> {
|
||||||
|
return fetchWrapper.get(`${BASE_PATH}/services/${id}`);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new service
|
||||||
|
*/
|
||||||
|
async create(service: Partial<Service>): Promise<Service> {
|
||||||
|
return fetchWrapper.post(`${BASE_PATH}/services`, service);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing service
|
||||||
|
*/
|
||||||
|
async update(id: string, service: Partial<Service>): Promise<Service> {
|
||||||
|
return fetchWrapper.put(`${BASE_PATH}/services/${id}`, service);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a service
|
||||||
|
*/
|
||||||
|
async destroy(id: string): Promise<{ success: boolean }> {
|
||||||
|
return fetchWrapper.delete(`${BASE_PATH}/services/${id}`);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test JMAP connection
|
||||||
|
*/
|
||||||
|
async test(request: ConnectionTestRequest): Promise<ConnectionTestResponse> {
|
||||||
|
return fetchWrapper.post(`${BASE_PATH}/services/test`, request);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-discover JMAP endpoint from hostname
|
||||||
|
*/
|
||||||
|
async discover(hostname: string, protocol?: string, port?: number, path?: string): Promise<DiscoverResponse> {
|
||||||
|
return fetchWrapper.post(`${BASE_PATH}/services/discover`, {
|
||||||
|
hostname,
|
||||||
|
protocol,
|
||||||
|
port,
|
||||||
|
path
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch collections for a service
|
||||||
|
*/
|
||||||
|
async fetchCollections(id: string): Promise<CollectionsResponse> {
|
||||||
|
return fetchWrapper.get(`${BASE_PATH}/services/${id}/collections`);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh collections for a service (re-query remote server)
|
||||||
|
*/
|
||||||
|
async refreshCollections(id: string): Promise<CollectionsResponse> {
|
||||||
|
return fetchWrapper.post(`${BASE_PATH}/services/${id}/collections/refresh`, {});
|
||||||
|
},
|
||||||
|
};
|
||||||
208
src/stores/servicesStore.ts
Normal file
208
src/stores/servicesStore.ts
Normal file
@@ -0,0 +1,208 @@
|
|||||||
|
import { defineStore } from 'pinia';
|
||||||
|
import { serviceService } from '@/services/serviceService';
|
||||||
|
import { ServiceModel } from '@/models/service';
|
||||||
|
import type { Service } from '@/models/service';
|
||||||
|
|
||||||
|
export const useServicesStore = defineStore('jmapc_services', {
|
||||||
|
state: () => ({
|
||||||
|
services: [] as ServiceModel[],
|
||||||
|
loading: false,
|
||||||
|
error: null as string | null,
|
||||||
|
}),
|
||||||
|
|
||||||
|
getters: {
|
||||||
|
/**
|
||||||
|
* Get services filtered by capability
|
||||||
|
*/
|
||||||
|
byCapability: (state) => (capability: string) => {
|
||||||
|
return state.services.filter(s => s.capabilities.includes(capability));
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get mail services
|
||||||
|
*/
|
||||||
|
mailServices: (state) => {
|
||||||
|
return state.services.filter(s => s.hasMail());
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get contact services
|
||||||
|
*/
|
||||||
|
contactServices: (state) => {
|
||||||
|
return state.services.filter(s => s.hasContacts());
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get calendar services
|
||||||
|
*/
|
||||||
|
calendarServices: (state) => {
|
||||||
|
return state.services.filter(s => s.hasCalendars());
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get service by ID
|
||||||
|
*/
|
||||||
|
getById: (state) => (id: string) => {
|
||||||
|
return state.services.find(s => s.id === id);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
/**
|
||||||
|
* Load all services from API
|
||||||
|
*/
|
||||||
|
async loadServices(capability?: string) {
|
||||||
|
this.loading = true;
|
||||||
|
this.error = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await serviceService.list(capability);
|
||||||
|
this.services = response.services.map(s => new ServiceModel(s));
|
||||||
|
} catch (error: any) {
|
||||||
|
this.error = error.message || 'Failed to load services';
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a single service
|
||||||
|
*/
|
||||||
|
async loadService(id: string) {
|
||||||
|
this.loading = true;
|
||||||
|
this.error = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const service = await serviceService.fetch(id);
|
||||||
|
const model = new ServiceModel(service);
|
||||||
|
|
||||||
|
// Update or add to store
|
||||||
|
const index = this.services.findIndex(s => s.id === id);
|
||||||
|
if (index >= 0) {
|
||||||
|
this.services[index] = model;
|
||||||
|
} else {
|
||||||
|
this.services.push(model);
|
||||||
|
}
|
||||||
|
|
||||||
|
return model;
|
||||||
|
} catch (error: any) {
|
||||||
|
this.error = error.message || 'Failed to load service';
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new service
|
||||||
|
*/
|
||||||
|
async createService(service: Partial<Service>) {
|
||||||
|
this.loading = true;
|
||||||
|
this.error = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const created = await serviceService.create(service);
|
||||||
|
const model = new ServiceModel(created);
|
||||||
|
this.services.push(model);
|
||||||
|
return model;
|
||||||
|
} catch (error: any) {
|
||||||
|
this.error = error.message || 'Failed to create service';
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing service
|
||||||
|
*/
|
||||||
|
async updateService(id: string, service: Partial<Service>) {
|
||||||
|
this.loading = true;
|
||||||
|
this.error = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const updated = await serviceService.update(id, service);
|
||||||
|
const model = new ServiceModel(updated);
|
||||||
|
|
||||||
|
const index = this.services.findIndex(s => s.id === id);
|
||||||
|
if (index >= 0) {
|
||||||
|
this.services[index] = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
return model;
|
||||||
|
} catch (error: any) {
|
||||||
|
this.error = error.message || 'Failed to update service';
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a service
|
||||||
|
*/
|
||||||
|
async deleteService(id: string) {
|
||||||
|
this.loading = true;
|
||||||
|
this.error = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await serviceService.destroy(id);
|
||||||
|
this.services = this.services.filter(s => s.id !== id);
|
||||||
|
} catch (error: any) {
|
||||||
|
this.error = error.message || 'Failed to delete service';
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
this.loading = false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test connection with provided settings
|
||||||
|
*/
|
||||||
|
async testConnection(config: any) {
|
||||||
|
return serviceService.test(config);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-discover JMAP endpoint
|
||||||
|
*/
|
||||||
|
async discover(hostname: string, protocol?: string, port?: number, path?: string) {
|
||||||
|
return serviceService.discover(hostname, protocol, port, path);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch collections for a service
|
||||||
|
*/
|
||||||
|
async fetchCollections(id: string) {
|
||||||
|
return serviceService.fetchCollections(id);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh collections for a service
|
||||||
|
*/
|
||||||
|
async refreshCollections(id: string) {
|
||||||
|
const result = await serviceService.refreshCollections(id);
|
||||||
|
|
||||||
|
// Update local service with fresh collection data
|
||||||
|
const service = this.getById(id);
|
||||||
|
if (service && result.success) {
|
||||||
|
service.collections = {
|
||||||
|
contacts: result.contacts || [],
|
||||||
|
calendars: result.calendars || []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear all services
|
||||||
|
*/
|
||||||
|
reset() {
|
||||||
|
this.services = [];
|
||||||
|
this.error = null;
|
||||||
|
this.loading = false;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user