Initial commit

This commit is contained in:
root
2026-01-04 22:05:37 -05:00
committed by Sebastian Krupinski
commit 4f979ced22
57 changed files with 11076 additions and 0 deletions

View File

@@ -0,0 +1,136 @@
<?php
declare(strict_types=1);
namespace KTXM\ProviderJmapc\Providers\People;
use KTXF\People\Provider\IProviderBase;
use KTXF\People\Provider\IProviderServiceMutate;
use KTXF\People\Service\IServiceBase;
use KTXF\People\Service\ServiceScope;
use KTXM\ProviderJmapc\Stores\ServiceStore;
/**
* JMAP Contacts Provider
*
* Provides Contacts services via JMAP protocol.
* Filters services by urn:ietf:params:jmap:contacts capability.
*/
class Provider implements IProviderBase, IProviderServiceMutate
{
protected const CONTACTS_CAPABILITY = 'urn:ietf:params:jmap:contacts';
public function __construct(
protected readonly ServiceStore $serviceStore,
) {}
public function capable(string $value): bool
{
$capabilities = [
self::CAPABILITY_SERVICE_LIST,
self::CAPABILITY_SERVICE_FETCH,
self::CAPABILITY_SERVICE_EXTANT,
self::CAPABILITY_SERVICE_FRESH,
self::CAPABILITY_SERVICE_CREATE,
self::CAPABILITY_SERVICE_MODIFY,
self::CAPABILITY_SERVICE_DESTROY,
];
return in_array($value, $capabilities, true);
}
public function capabilities(): array
{
return [
self::CAPABILITY_SERVICE_LIST => true,
self::CAPABILITY_SERVICE_FETCH => true,
self::CAPABILITY_SERVICE_EXTANT => true,
self::CAPABILITY_SERVICE_FRESH => true,
self::CAPABILITY_SERVICE_CREATE => true,
self::CAPABILITY_SERVICE_MODIFY => true,
self::CAPABILITY_SERVICE_DESTROY => true,
];
}
public function id(): string
{
return 'jmap';
}
public function label(): string
{
return 'JMAP Contacts Provider';
}
public function serviceList(string $tenantId, string $userId, array $filter): array
{
// Filter by Contacts capability
return $this->serviceStore->listServices($tenantId, $userId, [self::CONTACTS_CAPABILITY]);
}
public function serviceExtant(string $tenantId, string $userId, array $identifiers): array
{
$result = [];
foreach ($identifiers as $id) {
$service = $this->serviceStore->getService($tenantId, $userId, $id);
$result[$id] = $service !== null;
}
return $result;
}
public function serviceFetch(string $tenantId, string $userId, string|int $identifier): ?IServiceBase
{
return $this->serviceStore->getService($tenantId, $userId, $identifier);
}
public function serviceFresh(string $userId = ''): IServiceBase
{
return new Service(
scope: ServiceScope::User,
enabled: true,
);
}
public function serviceCreate(string $userId, IServiceBase $service): string
{
if (!($service instanceof Service)) {
throw new \InvalidArgumentException('Service must be instance of JMAP Service');
}
// Note: This simplified interface doesn't pass tenantId
// Will need to get it from SessionTenant in actual implementation
throw new \RuntimeException('Use Mail Provider interface for service creation');
}
public function serviceModify(string $userId, IServiceBase $service): string
{
if (!($service instanceof Service)) {
throw new \InvalidArgumentException('Service must be instance of JMAP Service');
}
throw new \RuntimeException('Use Mail Provider interface for service modification');
}
public function serviceDestroy(string $userId, IServiceBase $service): bool
{
if (!($service instanceof Service)) {
return false;
}
throw new \RuntimeException('Use Mail Provider interface for service destruction');
}
public function jsonSerialize(): array
{
return [
'@type' => 'people.provider',
'id' => $this->id(),
'label' => $this->label(),
'capabilities' => $this->capabilities(),
];
}
public function jsonDeserialize(array|string $data): static
{
return $this;
}
}