refactor: standardize frontend

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-02-24 17:38:48 -05:00
parent 20d3a46d7b
commit 0c4c9e52cd
24 changed files with 2448 additions and 1232 deletions

View File

@@ -1,13 +1,10 @@
/** /**
* People Manager Module Boot Script * People Manager Module Boot
*
* This script is executed when the people_manager module is loaded.
* It initializes the peopleStore which manages contacts and address books state.
*/ */
console.log('[PeopleManager] Booting People Manager module...') console.log('[People Manager] Booting module...')
console.log('[PeopleManager] People Manager module booted successfully') console.log('[People Manager] Module booted successfully...')
// CSS will be injected by build process // CSS will be injected by build process
//export const css = ['__CSS_FILENAME_PLACEHOLDER__'] //export const css = ['__CSS_FILENAME_PLACEHOLDER__']

View File

@@ -2,12 +2,7 @@
* Class model for Collection Interface * Class model for Collection Interface
*/ */
import type { import type { CollectionContentTypes, CollectionInterface, CollectionPropertiesInterface } from "@/types/collection";
CollectionInterface,
CollectionContentsInterface,
CollectionPermissionsInterface,
CollectionRolesInterface
} from "@/types/collection";
export class CollectionObject implements CollectionInterface { export class CollectionObject implements CollectionInterface {
@@ -15,37 +10,123 @@ export class CollectionObject implements CollectionInterface {
constructor() { constructor() {
this._data = { this._data = {
'@type': 'people:collection', provider: '',
provider: null, service: '',
service: null, collection: null,
in: null, identifier: '',
id: null,
label: null,
description: null,
priority: null,
visibility: null,
color: null,
enabled: false,
signature: null, signature: null,
permissions: {}, created: null,
roles: {}, modified: null,
contents: {}, properties: new CollectionPropertiesObject(),
}; };
} }
fromJson(data: CollectionInterface) : CollectionObject { fromJson(data: CollectionInterface): CollectionObject {
this._data = data; this._data = data;
if (data.properties) {
this._data.properties = new CollectionPropertiesObject().fromJson(data.properties as CollectionPropertiesInterface);
}
return this; return this;
} }
toJson(): CollectionInterface { toJson(): CollectionInterface {
return this._data; const json = { ...this._data };
if (this._data.properties instanceof CollectionPropertiesObject) {
json.properties = this._data.properties.toJson();
}
return json;
} }
clone(): CollectionObject { clone(): CollectionObject {
const cloned = new CollectionObject() const cloned = new CollectionObject();
cloned._data = JSON.parse(JSON.stringify(this._data)) cloned._data = { ...this._data };
return cloned cloned._data.properties = this.properties.clone();
return cloned;
}
/** Immutable Properties */
get provider(): string {
return this._data.provider;
}
get service(): string | number {
return this._data.service;
}
get collection(): string | number | null {
return this._data.collection;
}
get identifier(): string | number {
return this._data.identifier;
}
get signature(): string | null | undefined {
return this._data.signature;
}
get created(): string | null | undefined {
return this._data.created;
}
get modified(): string | null | undefined {
return this._data.modified;
}
get properties(): CollectionPropertiesObject {
if (this._data.properties instanceof CollectionPropertiesObject) {
return this._data.properties;
}
if (this._data.properties) {
const hydrated = new CollectionPropertiesObject().fromJson(this._data.properties as CollectionPropertiesInterface);
this._data.properties = hydrated;
return hydrated;
}
return new CollectionPropertiesObject();
}
set properties(value: CollectionPropertiesObject) {
if (value instanceof CollectionPropertiesObject) {
this._data.properties = value as any;
} else {
this._data.properties = value;
}
}
}
export class CollectionPropertiesObject implements CollectionPropertiesInterface {
_data!: CollectionPropertiesInterface;
constructor() {
this._data = {
'@type': 'people:collection',
version: 1,
content: [],
label: '',
description: null,
rank: null,
visibility: null,
color: null,
};
}
fromJson(data: CollectionPropertiesInterface): CollectionPropertiesObject {
this._data = data;
return this;
}
toJson(): CollectionPropertiesInterface {
return this._data;
}
clone(): CollectionPropertiesObject {
const cloned = new CollectionPropertiesObject();
cloned._data = { ...this._data };
return cloned;
} }
/** Immutable Properties */ /** Immutable Properties */
@@ -54,86 +135,54 @@ export class CollectionObject implements CollectionInterface {
return this._data['@type']; return this._data['@type'];
} }
get provider(): string | null { get version(): number {
return this._data.provider return this._data.version;
} }
get service(): string | null { get content(): CollectionContentTypes[] {
return this._data.service return this._data.content || [];
}
get in(): number | string | null {
return this._data.in
}
get id(): number | string | null {
return this._data.id
}
get signature(): string | null {
return this._data.signature
}
get permissions(): CollectionPermissionsInterface {
return this._data.permissions
}
get roles(): CollectionRolesInterface {
return this._data.roles
}
get contents(): CollectionContentsInterface {
return this._data.contents
} }
/** Mutable Properties */ /** Mutable Properties */
get label(): string | null { get label(): string {
return this._data.label return this._data.label || '';
} }
set label(value: string ) { set label(value: string) {
this._data.label = value this._data.label = value;
} }
get description(): string | null { get description(): string | null {
return this._data.description return this._data.description;
} }
set description(value: string ) { set description(value: string | null) {
this._data.description = value this._data.description = value;
} }
get priority(): number | null { get rank(): number | null {
return this._data.priority return this._data.rank;
} }
set priority(value: number ) { set rank(value: number | null) {
this._data.priority = value this._data.rank = value;
} }
get visibility(): string | null { get visibility(): boolean | null {
return this._data.visibility return this._data.visibility;
} }
set visibility(value: string ) { set visibility(value: boolean | null) {
this._data.visibility = value this._data.visibility = value;
} }
get color(): string | null { get color(): string | null {
return this._data.color return this._data.color;
} }
set color(value: string ) { set color(value: string | null) {
this._data.color = value this._data.color = value;
}
get enabled(): boolean {
return this._data.enabled
}
set enabled(value: boolean ) {
this._data.enabled = value
} }
} }

View File

@@ -16,138 +16,92 @@ export class EntityObject implements EntityInterface {
constructor() { constructor() {
this._data = { this._data = {
'@type': 'people:entity', provider: '',
version: 1, service: '',
in: null, collection: '',
id: null, identifier: '',
createdOn: null,
createdBy: null,
modifiedOn: null,
modifiedBy: null,
signature: null, signature: null,
data: null, created: null,
modified: null,
properties: new IndividualObject(),
}; };
} }
fromJson(data: EntityInterface) : EntityObject { fromJson(data: EntityInterface) : EntityObject {
this._data = data; this._data = data;
if (data.data) { if (data.properties) {
const type = data.data.type; const type = data.properties.type;
if (type === 'organization') { if (type === 'organization') {
this._data.data = new OrganizationObject().fromJson(data.data as OrganizationInterface); this._data.properties = new OrganizationObject().fromJson(data.properties as OrganizationInterface);
} else if (type === 'group') { } else if (type === 'group') {
this._data.data = new GroupObject().fromJson(data.data as GroupInterface); this._data.properties = new GroupObject().fromJson(data.properties as GroupInterface);
} else { } else {
this._data.data = new IndividualObject().fromJson(data.data as IndividualInterface); this._data.properties = new IndividualObject().fromJson(data.properties as IndividualInterface);
} }
} else {
this._data.data = null;
} }
return this; return this;
} }
toJson(): EntityInterface { toJson(): EntityInterface {
const json = { ...this._data }; const json = { ...this._data };
if (this._data.data instanceof IndividualObject || if (this._data.properties instanceof IndividualObject ||
this._data.data instanceof OrganizationObject || this._data.properties instanceof OrganizationObject ||
this._data.data instanceof GroupObject) { this._data.properties instanceof GroupObject) {
json.data = this._data.data.toJson(); json.properties = this._data.properties.toJson();
} }
return json; return json;
} }
clone(): EntityObject { clone(): EntityObject {
const cloned = new EntityObject() const cloned = new EntityObject();
cloned._data = JSON.parse(JSON.stringify(this._data)) cloned._data = { ...this._data };
return cloned return cloned;
} }
/** Immutable Properties */ /** Immutable Properties */
get '@type'(): string { get provider(): string {
return this._data['@type']; return this._data.provider;
} }
get in(): number | string | null { get service(): string {
return this._data.in; return this._data.service;
} }
get id(): number | string | null { get collection(): string | number {
return this._data.id; return this._data.collection;
} }
get version(): number { get identifier(): string | number {
return this._data.version; return this._data.identifier;
}
get createdOn(): Date | null {
return this._data.createdOn;
}
get createdBy(): string | null {
return this._data.createdBy;
}
get modifiedOn(): Date | null {
return this._data.modifiedOn;
}
get modifiedBy(): string | null {
return this._data.modifiedBy;
} }
get signature(): string | null { get signature(): string | null {
return this._data.signature; return this._data.signature;
} }
/** Mutable Properties */ get created(): string | null {
return this._data.created;
set createdOn(value: Date | null) {
this._data.createdOn = value;
} }
set createdBy(value: string | null) { get modified(): string | null {
this._data.createdBy = value; return this._data.modified;
} }
set modifiedOn(value: Date | null) { get properties(): IndividualObject | OrganizationObject | GroupObject {
this._data.modifiedOn = value; if (this._data.properties instanceof IndividualObject ||
} this._data.properties instanceof OrganizationObject ||
this._data.properties instanceof GroupObject) {
set modifiedBy(value: string | null) { return this._data.properties;
this._data.modifiedBy = value;
}
set signature(value: string | null) {
this._data.signature = value;
}
get data(): IndividualObject | OrganizationObject | GroupObject | null {
if (this._data.data instanceof IndividualObject ||
this._data.data instanceof OrganizationObject ||
this._data.data instanceof GroupObject) {
return this._data.data;
} }
if (this._data.data) { const defaultProperties = new IndividualObject();
const type = this._data.data.type; this._data.properties = defaultProperties;
let hydrated; return defaultProperties;
if (type === 'organization') {
hydrated = new OrganizationObject().fromJson(this._data.data as OrganizationInterface);
} else if (type === 'group') {
hydrated = new GroupObject().fromJson(this._data.data as GroupInterface);
} else {
hydrated = new IndividualObject().fromJson(this._data.data as IndividualInterface);
}
this._data.data = hydrated;
return hydrated;
}
return null;
} }
set data(value: IndividualObject | OrganizationObject | GroupObject | null) { set properties(value: IndividualObject | OrganizationObject | GroupObject) {
this._data.data = value; this._data.properties = value;
} }
} }

196
src/models/identity.ts Normal file
View File

@@ -0,0 +1,196 @@
/**
* Identity implementation classes for Mail Manager services
*/
import type {
ServiceIdentity,
ServiceIdentityNone,
ServiceIdentityBasic,
ServiceIdentityToken,
ServiceIdentityOAuth,
ServiceIdentityCertificate
} from '@/types/service';
/**
* Base Identity class
*/
export abstract class Identity {
abstract toJson(): ServiceIdentity;
static fromJson(data: ServiceIdentity): Identity {
switch (data.type) {
case 'NA':
return IdentityNone.fromJson(data);
case 'BA':
return IdentityBasic.fromJson(data);
case 'TA':
return IdentityToken.fromJson(data);
case 'OA':
return IdentityOAuth.fromJson(data);
case 'CC':
return IdentityCertificate.fromJson(data);
default:
throw new Error(`Unknown identity type: ${(data as any).type}`);
}
}
}
/**
* No authentication
*/
export class IdentityNone extends Identity {
readonly type = 'NA' as const;
static fromJson(_data: ServiceIdentityNone): IdentityNone {
return new IdentityNone();
}
toJson(): ServiceIdentityNone {
return {
type: this.type
};
}
}
/**
* Basic authentication (username/password)
*/
export class IdentityBasic extends Identity {
readonly type = 'BA' as const;
identity: string;
secret: string;
constructor(identity: string = '', secret: string = '') {
super();
this.identity = identity;
this.secret = secret;
}
static fromJson(data: ServiceIdentityBasic): IdentityBasic {
return new IdentityBasic(data.identity, data.secret);
}
toJson(): ServiceIdentityBasic {
return {
type: this.type,
identity: this.identity,
secret: this.secret
};
}
}
/**
* Token authentication (API key, static token)
*/
export class IdentityToken extends Identity {
readonly type = 'TA' as const;
token: string;
constructor(token: string = '') {
super();
this.token = token;
}
static fromJson(data: ServiceIdentityToken): IdentityToken {
return new IdentityToken(data.token);
}
toJson(): ServiceIdentityToken {
return {
type: this.type,
token: this.token
};
}
}
/**
* OAuth authentication
*/
export class IdentityOAuth extends Identity {
readonly type = 'OA' as const;
accessToken: string;
accessScope?: string[];
accessExpiry?: number;
refreshToken?: string;
refreshLocation?: string;
constructor(
accessToken: string = '',
accessScope?: string[],
accessExpiry?: number,
refreshToken?: string,
refreshLocation?: string
) {
super();
this.accessToken = accessToken;
this.accessScope = accessScope;
this.accessExpiry = accessExpiry;
this.refreshToken = refreshToken;
this.refreshLocation = refreshLocation;
}
static fromJson(data: ServiceIdentityOAuth): IdentityOAuth {
return new IdentityOAuth(
data.accessToken,
data.accessScope,
data.accessExpiry,
data.refreshToken,
data.refreshLocation
);
}
toJson(): ServiceIdentityOAuth {
return {
type: this.type,
accessToken: this.accessToken,
...(this.accessScope && { accessScope: this.accessScope }),
...(this.accessExpiry && { accessExpiry: this.accessExpiry }),
...(this.refreshToken && { refreshToken: this.refreshToken }),
...(this.refreshLocation && { refreshLocation: this.refreshLocation })
};
}
isExpired(): boolean {
if (!this.accessExpiry) return false;
return Date.now() / 1000 >= this.accessExpiry;
}
expiresIn(): number {
if (!this.accessExpiry) return Infinity;
return Math.max(0, this.accessExpiry - Date.now() / 1000);
}
}
/**
* Client certificate authentication (mTLS)
*/
export class IdentityCertificate extends Identity {
readonly type = 'CC' as const;
certificate: string;
privateKey: string;
passphrase?: string;
constructor(certificate: string = '', privateKey: string = '', passphrase?: string) {
super();
this.certificate = certificate;
this.privateKey = privateKey;
this.passphrase = passphrase;
}
static fromJson(data: ServiceIdentityCertificate): IdentityCertificate {
return new IdentityCertificate(
data.certificate,
data.privateKey,
data.passphrase
);
}
toJson(): ServiceIdentityCertificate {
return {
type: this.type,
certificate: this.certificate,
privateKey: this.privateKey,
...(this.passphrase && { passphrase: this.passphrase })
};
}
}

View File

@@ -1,11 +1,7 @@
/** export { ProviderObject } from './provider';
* Central export point for all People Manager models export { ServiceObject } from './service';
*/
export { CollectionObject } from './collection'; export { CollectionObject } from './collection';
export { EntityObject } from './entity'; export { EntityObject } from './entity';
export { GroupObject } from './group'; export { GroupObject } from './group';
export { IndividualObject } from './individual'; export { IndividualObject } from './individual';
export { OrganizationObject } from './organization'; export { OrganizationObject } from './organization';
export { ProviderObject } from './provider';
export { ServiceObject } from './service';

240
src/models/location.ts Normal file
View File

@@ -0,0 +1,240 @@
/**
* Location implementation classes for Mail Manager services
*/
import type {
ServiceLocation,
ServiceLocationUri,
ServiceLocationSocketSole,
ServiceLocationSocketSplit,
ServiceLocationFile
} from '@/types/service';
/**
* Base Location class
*/
export abstract class Location {
abstract toJson(): ServiceLocation;
static fromJson(data: ServiceLocation): Location {
switch (data.type) {
case 'URI':
return LocationUri.fromJson(data);
case 'SOCKET_SOLE':
return LocationSocketSole.fromJson(data);
case 'SOCKET_SPLIT':
return LocationSocketSplit.fromJson(data);
case 'FILE':
return LocationFile.fromJson(data);
default:
throw new Error(`Unknown location type: ${(data as any).type}`);
}
}
}
/**
* URI-based service location for API and web services
* Used by: JMAP, Gmail API, etc.
*/
export class LocationUri extends Location {
readonly type = 'URI' as const;
scheme: string;
host: string;
port: number;
path?: string;
verifyPeer: boolean;
verifyHost: boolean;
constructor(
scheme: string = 'https',
host: string = '',
port: number = 443,
path?: string,
verifyPeer: boolean = true,
verifyHost: boolean = true
) {
super();
this.scheme = scheme;
this.host = host;
this.port = port;
this.path = path;
this.verifyPeer = verifyPeer;
this.verifyHost = verifyHost;
}
static fromJson(data: ServiceLocationUri): LocationUri {
return new LocationUri(
data.scheme,
data.host,
data.port,
data.path,
data.verifyPeer ?? true,
data.verifyHost ?? true
);
}
toJson(): ServiceLocationUri {
return {
type: this.type,
scheme: this.scheme,
host: this.host,
port: this.port,
...(this.path && { path: this.path }),
...(this.verifyPeer !== undefined && { verifyPeer: this.verifyPeer }),
...(this.verifyHost !== undefined && { verifyHost: this.verifyHost })
};
}
getUrl(): string {
const path = this.path || '';
return `${this.scheme}://${this.host}:${this.port}${path}`;
}
}
/**
* Single socket-based service location
* Used by: services using a single host/port combination
*/
export class LocationSocketSole extends Location {
readonly type = 'SOCKET_SOLE' as const;
host: string;
port: number;
encryption: 'none' | 'ssl' | 'tls' | 'starttls';
verifyPeer: boolean;
verifyHost: boolean;
constructor(
host: string = '',
port: number = 993,
encryption: 'none' | 'ssl' | 'tls' | 'starttls' = 'ssl',
verifyPeer: boolean = true,
verifyHost: boolean = true
) {
super();
this.host = host;
this.port = port;
this.encryption = encryption;
this.verifyPeer = verifyPeer;
this.verifyHost = verifyHost;
}
static fromJson(data: ServiceLocationSocketSole): LocationSocketSole {
return new LocationSocketSole(
data.host,
data.port,
data.encryption,
data.verifyPeer ?? true,
data.verifyHost ?? true
);
}
toJson(): ServiceLocationSocketSole {
return {
type: this.type,
host: this.host,
port: this.port,
encryption: this.encryption,
...(this.verifyPeer !== undefined && { verifyPeer: this.verifyPeer }),
...(this.verifyHost !== undefined && { verifyHost: this.verifyHost })
};
}
}
/**
* Split socket-based service location
* Used by: traditional IMAP/SMTP configurations
*/
export class LocationSocketSplit extends Location {
readonly type = 'SOCKET_SPLIT' as const;
inboundHost: string;
inboundPort: number;
inboundEncryption: 'none' | 'ssl' | 'tls' | 'starttls';
outboundHost: string;
outboundPort: number;
outboundEncryption: 'none' | 'ssl' | 'tls' | 'starttls';
inboundVerifyPeer: boolean;
inboundVerifyHost: boolean;
outboundVerifyPeer: boolean;
outboundVerifyHost: boolean;
constructor(
inboundHost: string = '',
inboundPort: number = 993,
inboundEncryption: 'none' | 'ssl' | 'tls' | 'starttls' = 'ssl',
outboundHost: string = '',
outboundPort: number = 465,
outboundEncryption: 'none' | 'ssl' | 'tls' | 'starttls' = 'ssl',
inboundVerifyPeer: boolean = true,
inboundVerifyHost: boolean = true,
outboundVerifyPeer: boolean = true,
outboundVerifyHost: boolean = true
) {
super();
this.inboundHost = inboundHost;
this.inboundPort = inboundPort;
this.inboundEncryption = inboundEncryption;
this.outboundHost = outboundHost;
this.outboundPort = outboundPort;
this.outboundEncryption = outboundEncryption;
this.inboundVerifyPeer = inboundVerifyPeer;
this.inboundVerifyHost = inboundVerifyHost;
this.outboundVerifyPeer = outboundVerifyPeer;
this.outboundVerifyHost = outboundVerifyHost;
}
static fromJson(data: ServiceLocationSocketSplit): LocationSocketSplit {
return new LocationSocketSplit(
data.inboundHost,
data.inboundPort,
data.inboundEncryption,
data.outboundHost,
data.outboundPort,
data.outboundEncryption,
data.inboundVerifyPeer ?? true,
data.inboundVerifyHost ?? true,
data.outboundVerifyPeer ?? true,
data.outboundVerifyHost ?? true
);
}
toJson(): ServiceLocationSocketSplit {
return {
type: this.type,
inboundHost: this.inboundHost,
inboundPort: this.inboundPort,
inboundEncryption: this.inboundEncryption,
outboundHost: this.outboundHost,
outboundPort: this.outboundPort,
outboundEncryption: this.outboundEncryption,
...(this.inboundVerifyPeer !== undefined && { inboundVerifyPeer: this.inboundVerifyPeer }),
...(this.inboundVerifyHost !== undefined && { inboundVerifyHost: this.inboundVerifyHost }),
...(this.outboundVerifyPeer !== undefined && { outboundVerifyPeer: this.outboundVerifyPeer }),
...(this.outboundVerifyHost !== undefined && { outboundVerifyHost: this.outboundVerifyHost })
};
}
}
/**
* File-based service location
* Used by: local file system providers
*/
export class LocationFile extends Location {
readonly type = 'FILE' as const;
path: string;
constructor(path: string = '') {
super();
this.path = path;
}
static fromJson(data: ServiceLocationFile): LocationFile {
return new LocationFile(data.path);
}
toJson(): ServiceLocationFile {
return {
type: this.type,
path: this.path
};
}
}

View File

@@ -14,7 +14,7 @@ export class ProviderObject implements ProviderInterface {
constructor() { constructor() {
this._data = { this._data = {
'@type': 'people:provider', '@type': 'people:provider',
id: '', identifier: '',
label: '', label: '',
capabilities: {}, capabilities: {},
}; };
@@ -30,8 +30,9 @@ export class ProviderObject implements ProviderInterface {
} }
capable(capability: keyof ProviderCapabilitiesInterface): boolean { capable(capability: keyof ProviderCapabilitiesInterface): boolean {
return !!(this._data.capabilities && this._data.capabilities[capability]); const value = this._data.capabilities?.[capability];
} return value !== undefined && value !== false;
}
capability(capability: keyof ProviderCapabilitiesInterface): any | null { capability(capability: keyof ProviderCapabilitiesInterface): any | null {
if (this._data.capabilities) { if (this._data.capabilities) {
@@ -46,8 +47,8 @@ export class ProviderObject implements ProviderInterface {
return this._data['@type']; return this._data['@type'];
} }
get id(): string { get identifier(): string {
return this._data.id; return this._data.identifier;
} }
get label(): string { get label(): string {

View File

@@ -4,8 +4,12 @@
import type { import type {
ServiceInterface, ServiceInterface,
ServiceCapabilitiesInterface ServiceCapabilitiesInterface,
ServiceIdentity,
ServiceLocation
} from "@/types/service"; } from "@/types/service";
import { Identity } from './identity';
import { Location } from './location';
export class ServiceObject implements ServiceInterface { export class ServiceObject implements ServiceInterface {
@@ -15,10 +19,10 @@ export class ServiceObject implements ServiceInterface {
this._data = { this._data = {
'@type': 'people:service', '@type': 'people:service',
provider: '', provider: '',
id: '', identifier: null,
label: '', label: null,
capabilities: {},
enabled: false, enabled: false,
capabilities: {}
}; };
} }
@@ -32,7 +36,8 @@ export class ServiceObject implements ServiceInterface {
} }
capable(capability: keyof ServiceCapabilitiesInterface): boolean { capable(capability: keyof ServiceCapabilitiesInterface): boolean {
return !!(this._data.capabilities && this._data.capabilities[capability]); const value = this._data.capabilities?.[capability];
return value !== undefined && value !== false;
} }
capability(capability: keyof ServiceCapabilitiesInterface): any | null { capability(capability: keyof ServiceCapabilitiesInterface): any | null {
@@ -52,8 +57,8 @@ export class ServiceObject implements ServiceInterface {
return this._data.provider; return this._data.provider;
} }
get id(): string { get identifier(): string | number | null {
return this._data.id; return this._data.identifier;
} }
get capabilities(): ServiceCapabilitiesInterface | undefined { get capabilities(): ServiceCapabilitiesInterface | undefined {
@@ -62,11 +67,11 @@ export class ServiceObject implements ServiceInterface {
/** Mutable Properties */ /** Mutable Properties */
get label(): string { get label(): string | null {
return this._data.label; return this._data.label;
} }
set label(value: string) { set label(value: string | null) {
this._data.label = value; this._data.label = value;
} }
@@ -78,4 +83,46 @@ export class ServiceObject implements ServiceInterface {
this._data.enabled = value; this._data.enabled = value;
} }
get location(): ServiceLocation | null {
return this._data.location ?? null;
}
set location(value: ServiceLocation | null) {
this._data.location = value;
}
get identity(): ServiceIdentity | null {
return this._data.identity ?? null;
}
set identity(value: ServiceIdentity | null) {
this._data.identity = value;
}
get auxiliary(): Record<string, any> {
return this._data.auxiliary ?? {};
}
set auxiliary(value: Record<string, any>) {
this._data.auxiliary = value;
}
/** Helper Methods */
/**
* Get identity as a class instance for easier manipulation
*/
getIdentity(): Identity | null {
if (!this._data.identity) return null;
return Identity.fromJson(this._data.identity);
}
/**
* Get location as a class instance for easier manipulation
*/
getLocation(): Location | null {
if (!this._data.location) return null;
return Location.fromJson(this._data.location);
}
} }

View File

@@ -12,72 +12,119 @@ import type {
CollectionFetchResponse, CollectionFetchResponse,
CollectionCreateRequest, CollectionCreateRequest,
CollectionCreateResponse, CollectionCreateResponse,
CollectionModifyRequest, CollectionUpdateResponse,
CollectionModifyResponse, CollectionUpdateRequest,
CollectionDestroyRequest, CollectionDeleteResponse,
CollectionDestroyResponse, CollectionDeleteRequest,
CollectionInterface,
} from '../types/collection'; } from '../types/collection';
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
import { CollectionObject, CollectionPropertiesObject } from '../models/collection';
/**
* Helper to create the right collection model class based on provider identifier
* Uses provider-specific factory if available, otherwise returns base CollectionObject
*/
function createCollectionObject(data: CollectionInterface): CollectionObject {
const integrationStore = useIntegrationStore();
const factoryItem = integrationStore.getItemById('people_collection_factory', data.provider) as any;
const factory = factoryItem?.factory;
// Use provider factory if available, otherwise base class
return factory ? factory(data) : new CollectionObject().fromJson(data);
}
export const collectionService = { export const collectionService = {
/** /**
* List all available collections * Retrieve list of collections, optionally filtered by source selector
* *
* @param request - Collection list request parameters * @param request - list request parameters
* @returns Promise with collection list grouped by provider and service *
* @returns Promise with collection object list grouped by provider, service, and collection identifier
*/ */
async list(request: CollectionListRequest = {}): Promise<CollectionListResponse> { async list(request: CollectionListRequest = {}): Promise<Record<string, Record<string, Record<string, CollectionObject>>>> {
return await transceivePost<CollectionListRequest, CollectionListResponse>('collection.list', request); const response = await transceivePost<CollectionListRequest, CollectionListResponse>('collection.list', request);
// Convert nested response to CollectionObject instances
const providerList: Record<string, Record<string, Record<string, CollectionObject>>> = {};
Object.entries(response).forEach(([providerId, providerServices]) => {
const serviceList: Record<string, Record<string, CollectionObject>> = {};
Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
const collectionList: Record<string, CollectionObject> = {};
Object.entries(serviceCollections).forEach(([collectionId, collectionData]) => {
collectionList[collectionId] = createCollectionObject(collectionData);
});
serviceList[serviceId] = collectionList;
});
providerList[providerId] = serviceList;
});
return providerList;
}, },
/** /**
* Check which collections exist/are available * Retrieve a specific collection by provider and identifier
*
* @param request - fetch request parameters
*
* @returns Promise with collection object
*/
async fetch(request: CollectionFetchRequest): Promise<CollectionObject> {
const response = await transceivePost<CollectionFetchRequest, CollectionFetchResponse>('collection.fetch', request);
return createCollectionObject(response);
},
/**
* Retrieve collection availability status for a given source selector
*
* @param request - extant request parameters
* *
* @param request - Collection extant request with source selector
* @returns Promise with collection availability status * @returns Promise with collection availability status
*/ */
async extant(request: CollectionExtantRequest): Promise<CollectionExtantResponse> { async extant(request: CollectionExtantRequest): Promise<CollectionExtantResponse> {
return await transceivePost('collection.extant', request); return await transceivePost<CollectionExtantRequest, CollectionExtantResponse>('collection.extant', request);
},
/**
* Fetch a specific collection
*
* @param request - Collection fetch request
* @returns Promise with collection details
*/
async fetch(request: CollectionFetchRequest): Promise<CollectionFetchResponse> {
return await transceivePost('collection.fetch', request);
}, },
/** /**
* Create a new collection * Create a new collection
* *
* @param request - Collection create request * @param request - create request parameters
* @returns Promise with created collection *
* @returns Promise with created collection object
*/ */
async create(request: CollectionCreateRequest): Promise<CollectionCreateResponse> { async create(request: CollectionCreateRequest): Promise<CollectionObject> {
return await transceivePost('collection.create', request); if (request.properties instanceof CollectionPropertiesObject) {
request.properties = request.properties.toJson();
}
const response = await transceivePost<CollectionCreateRequest, CollectionCreateResponse>('collection.create', request);
return createCollectionObject(response);
}, },
/** /**
* Modify an existing collection * Update an existing collection
* *
* @param request - Collection modify request * @param request - update request parameters
* @returns Promise with modified collection *
* @returns Promise with updated collection object
*/ */
async modify(request: CollectionModifyRequest): Promise<CollectionModifyResponse> { async update(request: CollectionUpdateRequest): Promise<CollectionObject> {
return await transceivePost('collection.modify', request); if (request.properties instanceof CollectionPropertiesObject) {
request.properties = request.properties.toJson();
}
const response = await transceivePost<CollectionUpdateRequest, CollectionUpdateResponse>('collection.update', request);
return createCollectionObject(response);
}, },
/** /**
* Delete a collection * Delete a collection
* *
* @param request - Collection destroy request * @param request - delete request parameters
*
* @returns Promise with deletion result * @returns Promise with deletion result
*/ */
async destroy(request: CollectionDestroyRequest): Promise<CollectionDestroyResponse> { async delete(request: CollectionDeleteRequest): Promise<CollectionDeleteResponse> {
return await transceivePost('collection.destroy', request); return await transceivePost<CollectionDeleteRequest, CollectionDeleteResponse>('collection.delete', request);
}, },
}; };

View File

@@ -6,91 +6,145 @@ import { transceivePost } from './transceive';
import type { import type {
EntityListRequest, EntityListRequest,
EntityListResponse, EntityListResponse,
EntityDeltaRequest,
EntityDeltaResponse,
EntityExtantRequest,
EntityExtantResponse,
EntityFetchRequest, EntityFetchRequest,
EntityFetchResponse, EntityFetchResponse,
EntityExtantRequest,
EntityExtantResponse,
EntityCreateRequest, EntityCreateRequest,
EntityCreateResponse, EntityCreateResponse,
EntityModifyRequest, EntityUpdateRequest,
EntityModifyResponse, EntityUpdateResponse,
EntityDestroyRequest, EntityDeleteRequest,
EntityDestroyResponse, EntityDeleteResponse,
EntityDeltaRequest,
EntityDeltaResponse,
EntityInterface,
} from '../types/entity'; } from '../types/entity';
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
import { EntityObject } from '../models';
/**
* Helper to create the right entity model class based on provider identifier
* Uses provider-specific factory if available, otherwise returns base EntityObject
*/
function createEntityObject(data: EntityInterface): EntityObject {
const integrationStore = useIntegrationStore();
const factoryItem = integrationStore.getItemById('people_entity_factory', data.provider) as any;
const factory = factoryItem?.factory;
// Use provider factory if available, otherwise base class
return factory ? factory(data) : new EntityObject().fromJson(data);
}
export const entityService = { export const entityService = {
/** /**
* List all available entities (events, tasks, journals) * Retrieve list of entities, optionally filtered by source selector
* *
* @param request - Entity list request parameters * @param request - list request parameters
* @returns Promise with entity list grouped by provider, service, and collection *
* @returns Promise with entity object list grouped by provider, service, collection, and entity identifier
*/ */
async list(request: EntityListRequest = {}): Promise<EntityListResponse> { async list(request: EntityListRequest = {}): Promise<Record<string, Record<string, Record<string, Record<string, EntityObject>>>>> {
return await transceivePost<EntityListRequest, EntityListResponse>('entity.list', request); const response = await transceivePost<EntityListRequest, EntityListResponse>('entity.list', request);
// Convert nested response to EntityObject instances
const providerList: Record<string, Record<string, Record<string, Record<string, EntityObject>>>> = {};
Object.entries(response).forEach(([providerId, providerServices]) => {
const serviceList: Record<string, Record<string, Record<string, EntityObject>>> = {};
Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
const collectionList: Record<string, Record<string, EntityObject>> = {};
Object.entries(serviceCollections).forEach(([collectionId, collectionEntities]) => {
const entityList: Record<string, EntityObject> = {};
Object.entries(collectionEntities).forEach(([entityId, entityData]) => {
entityList[entityId] = createEntityObject(entityData);
});
collectionList[collectionId] = entityList;
});
serviceList[serviceId] = collectionList;
});
providerList[providerId] = serviceList;
});
return providerList;
}, },
/** /**
* Get delta changes for entities * Retrieve a specific entity by provider and identifier
* *
* @param request - Entity delta request with source selector * @param request - fetch request parameters
* @returns Promise with delta changes (created, modified, deleted) *
* @returns Promise with entity objects keyed by identifier
*/ */
async delta(request: EntityDeltaRequest): Promise<EntityDeltaResponse> { async fetch(request: EntityFetchRequest): Promise<Record<string, EntityObject>> {
return await transceivePost('entity.delta', request); const response = await transceivePost<EntityFetchRequest, EntityFetchResponse>('entity.fetch', request);
// Convert response to EntityObject instances
const list: Record<string, EntityObject> = {};
Object.entries(response).forEach(([identifier, entityData]) => {
list[identifier] = createEntityObject(entityData);
});
return list;
}, },
/** /**
* Check which entities exist/are available * Retrieve entity availability status for a given source selector
*
* @param request - extant request parameters
* *
* @param request - Entity extant request with source selector
* @returns Promise with entity availability status * @returns Promise with entity availability status
*/ */
async extant(request: EntityExtantRequest): Promise<EntityExtantResponse> { async extant(request: EntityExtantRequest): Promise<EntityExtantResponse> {
return await transceivePost('entity.extant', request); return await transceivePost<EntityExtantRequest, EntityExtantResponse>('entity.extant', request);
},
/**
* Fetch specific entities
*
* @param request - Entity fetch request
* @returns Promise with entity details
*/
async fetch(request: EntityFetchRequest): Promise<EntityFetchResponse> {
return await transceivePost('entity.fetch', request);
}, },
/** /**
* Create a new entity * Create a new entity
* *
* @param request - Entity create request * @param request - create request parameters
* @returns Promise with created entity *
* @returns Promise with created entity object
*/ */
async create(request: EntityCreateRequest): Promise<EntityCreateResponse> { async create(request: EntityCreateRequest): Promise<EntityObject> {
return await transceivePost('entity.create', request); const response = await transceivePost<EntityCreateRequest, EntityCreateResponse>('entity.create', request);
return createEntityObject(response);
}, },
/** /**
* Modify an existing entity * Update an existing entity
* *
* @param request - Entity modify request * @param request - update request parameters
* @returns Promise with modified entity *
* @returns Promise with updated entity object
*/ */
async modify(request: EntityModifyRequest): Promise<EntityModifyResponse> { async update(request: EntityUpdateRequest): Promise<EntityObject> {
return await transceivePost('entity.modify', request); const response = await transceivePost<EntityUpdateRequest, EntityUpdateResponse>('entity.update', request);
return createEntityObject(response);
}, },
/** /**
* Delete an entity * Delete an entity
* *
* @param request - Entity destroy request * @param request - delete request parameters
*
* @returns Promise with deletion result * @returns Promise with deletion result
*/ */
async destroy(request: EntityDestroyRequest): Promise<EntityDestroyResponse> { async delete(request: EntityDeleteRequest): Promise<EntityDeleteResponse> {
return await transceivePost('entity.destroy', request); return await transceivePost<EntityDeleteRequest, EntityDeleteResponse>('entity.delete', request);
}, },
/**
* Retrieve delta changes for entities
*
* @param request - delta request parameters
*
* @returns Promise with delta changes (created, modified, deleted)
*/
async delta(request: EntityDeltaRequest): Promise<EntityDeltaResponse> {
return await transceivePost<EntityDeltaRequest, EntityDeltaResponse>('entity.delta', request);
},
}; };
export default entityService; export default entityService;

View File

@@ -1,16 +1,4 @@
/**
* Central export point for all People Manager services
*/
// Services
export { providerService } from './providerService'; export { providerService } from './providerService';
export { serviceService } from './serviceService'; export { serviceService } from './serviceService';
export { collectionService } from './collectionService'; export { collectionService } from './collectionService';
export { entityService } from './entityService'; export { entityService } from './entityService';
// Type exports
export type * from '../types/common';
export type * from '../types/provider';
export type * from '../types/service';
export type * from '../types/collection';
export type * from '../types/entity';

View File

@@ -2,30 +2,74 @@
* Provider management service * Provider management service
*/ */
import type {
ProviderListRequest,
ProviderListResponse,
ProviderExtantRequest,
ProviderExtantResponse,
ProviderFetchRequest,
ProviderFetchResponse,
ProviderInterface,
} from '../types/provider';
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
import { transceivePost } from './transceive'; import { transceivePost } from './transceive';
import type { ProviderListResponse, ProviderExtantResponse } from '../types/provider'; import { ProviderObject } from '../models/provider';
import type { SourceSelector } from '../types/common';
/**
* Helper to create the right provider model class based on provider identifier
* Uses provider-specific factory if available, otherwise returns base ProviderObject
*/
function createProviderObject(data: ProviderInterface): ProviderObject {
const integrationStore = useIntegrationStore();
const factoryItem = integrationStore.getItemById('people_provider_factory', data.identifier) as any;
const factory = factoryItem?.factory;
// Use provider factory if available, otherwise base class
return factory ? factory(data) : new ProviderObject().fromJson(data);
}
export const providerService = { export const providerService = {
/** /**
* List all available providers * Retrieve list of providers, optionally filtered by source selector
* *
* @returns Promise with provider list keyed by provider ID * @param request - list request parameters
*
* @returns Promise with provider object list keyed by provider identifier
*/ */
async list(): Promise<ProviderListResponse> { async list(request: ProviderListRequest = {}): Promise<Record<string, ProviderObject>> {
return await transceivePost<{}, ProviderListResponse>('provider.list', {}); const response = await transceivePost<ProviderListRequest, ProviderListResponse>('provider.list', request);
// Convert response to ProviderObject instances
const list: Record<string, ProviderObject> = {};
Object.entries(response).forEach(([providerId, providerData]) => {
list[providerId] = createProviderObject(providerData);
});
return list;
}, },
/** /**
* Check which providers exist/are available * Retrieve specific provider by identifier
* *
* @param sources - Source selector with provider IDs to check * @param request - fetch request parameters
*
* @returns Promise with provider object
*/
async fetch(request: ProviderFetchRequest): Promise<ProviderObject> {
const response = await transceivePost<ProviderFetchRequest, ProviderFetchResponse>('provider.fetch', request);
return createProviderObject(response);
},
/**
* Retrieve provider availability status for a given source selector
*
* @param request - extant request parameters
* *
* @returns Promise with provider availability status * @returns Promise with provider availability status
*/ */
async extant(sources: SourceSelector): Promise<ProviderExtantResponse> { async extant(request: ProviderExtantRequest): Promise<ProviderExtantResponse> {
return await transceivePost('provider.extant', { sources }); return await transceivePost<ProviderExtantRequest, ProviderExtantResponse>('provider.extant', request);
}, },
}; };

View File

@@ -2,46 +2,161 @@
* Service management service * Service management service
*/ */
import { transceivePost } from './transceive';
import type { import type {
ServiceListRequest, ServiceListRequest,
ServiceListResponse, ServiceListResponse,
ServiceExtantRequest,
ServiceExtantResponse,
ServiceFetchRequest, ServiceFetchRequest,
ServiceFetchResponse, ServiceFetchResponse,
ServiceExtantRequest,
ServiceExtantResponse,
ServiceCreateResponse,
ServiceCreateRequest,
ServiceUpdateResponse,
ServiceUpdateRequest,
ServiceDeleteResponse,
ServiceDeleteRequest,
ServiceDiscoverRequest,
ServiceDiscoverResponse,
ServiceTestRequest,
ServiceTestResponse,
ServiceInterface,
} from '../types/service'; } from '../types/service';
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
import { transceivePost } from './transceive';
import { ServiceObject } from '../models/service';
/**
* Helper to create the right service model class based on provider identifier
* Uses provider-specific factory if available, otherwise returns base ServiceObject
*/
function createServiceObject(data: ServiceInterface): ServiceObject {
const integrationStore = useIntegrationStore();
const factoryItem = integrationStore.getItemById('people_service_factory', data.provider) as any;
const factory = factoryItem?.factory;
// Use provider factory if available, otherwise base class
return factory ? factory(data) : new ServiceObject().fromJson(data);
}
export const serviceService = { export const serviceService = {
/** /**
* List all available services * Retrieve list of services, optionally filtered by source selector
* *
* @param request - Service list request parameters * @param request - list request parameters
* @returns Promise with service list grouped by provider *
* @returns Promise with service object list grouped by provider and keyed by service identifier
*/ */
async list(request: ServiceListRequest = {}): Promise<ServiceListResponse> { async list(request: ServiceListRequest = {}): Promise<Record<string, Record<string, ServiceObject>>> {
return await transceivePost<ServiceListRequest, ServiceListResponse>('service.list', request); const response = await transceivePost<ServiceListRequest, ServiceListResponse>('service.list', request);
// Convert nested response to ServiceObject instances
const providerList: Record<string, Record<string, ServiceObject>> = {};
Object.entries(response).forEach(([providerId, providerServices]) => {
const serviceList: Record<string, ServiceObject> = {};
Object.entries(providerServices).forEach(([serviceId, serviceData]) => {
serviceList[serviceId] = createServiceObject(serviceData);
});
providerList[providerId] = serviceList;
});
return providerList;
}, },
/** /**
* Check which services exist/are available * Retrieve a specific service by provider and identifier
*
* @param request - fetch request parameters
*
* @returns Promise with service object
*/
async fetch(request: ServiceFetchRequest): Promise<ServiceObject> {
const response = await transceivePost<ServiceFetchRequest, ServiceFetchResponse>('service.fetch', request);
return createServiceObject(response);
},
/**
* Retrieve service availability status for a given source selector
*
* @param request - extant request parameters
* *
* @param request - Service extant request with source selector
* @returns Promise with service availability status * @returns Promise with service availability status
*/ */
async extant(request: ServiceExtantRequest): Promise<ServiceExtantResponse> { async extant(request: ServiceExtantRequest): Promise<ServiceExtantResponse> {
return await transceivePost('service.extant', request); return await transceivePost<ServiceExtantRequest, ServiceExtantResponse>('service.extant', request);
}, },
/** /**
* Fetch a specific service * Retrieve discoverable services for a given source selector, sorted by provider
* *
* @param request - Service fetch request with provider and service IDs * @param request - discover request parameters
* @returns Promise with service details *
* @returns Promise with array of discovered services sorted by provider
*/ */
async fetch(request: ServiceFetchRequest): Promise<ServiceFetchResponse> { async discover(request: ServiceDiscoverRequest): Promise<ServiceObject[]> {
return await transceivePost('service.fetch', request); const response = await transceivePost<ServiceDiscoverRequest, ServiceDiscoverResponse>('service.discover', request);
// Convert discovery results to ServiceObjects
const services: ServiceObject[] = [];
Object.entries(response).forEach(([providerId, location]) => {
const serviceData: ServiceInterface = {
'@type': 'people:service',
provider: providerId,
identifier: null,
label: null,
enabled: false,
location: location,
};
services.push(createServiceObject(serviceData));
});
// Sort by provider
return services.sort((a, b) => a.provider.localeCompare(b.provider));
},
/**
* Test service connectivity and configuration
*
* @param request - Service test request
* @returns Promise with test results
*/
async test(request: ServiceTestRequest): Promise<ServiceTestResponse> {
return await transceivePost<ServiceTestRequest, ServiceTestResponse>('service.test', request);
},
/**
* Create a new service
*
* @param request - create request parameters
*
* @returns Promise with created service object
*/
async create(request: ServiceCreateRequest): Promise<ServiceObject> {
const response = await transceivePost<ServiceCreateRequest, ServiceCreateResponse>('service.create', request);
return createServiceObject(response);
},
/**
* Update a existing service
*
* @param request - update request parameters
*
* @returns Promise with updated service object
*/
async update(request: ServiceUpdateRequest): Promise<ServiceObject> {
const response = await transceivePost<ServiceUpdateRequest, ServiceUpdateResponse>('service.update', request);
return createServiceObject(response);
},
/**
* Delete a service
*
* @param request - delete request parameters
*
* @returns Promise with deletion result
*/
async delete(request: { provider: string; identifier: string | number }): Promise<any> {
return await transceivePost<ServiceDeleteRequest, ServiceDeleteResponse>('service.delete', request);
}, },
}; };

View File

@@ -1,203 +1,307 @@
/** /**
* People Manager - Collections Store * Collections Store
*/ */
import { defineStore } from 'pinia'; import { ref, computed, readonly } from 'vue'
import { ref } from 'vue'; import { defineStore } from 'pinia'
import { collectionService } from '../services/collectionService'; import { collectionService } from '../services'
import type { import { CollectionObject, CollectionPropertiesObject } from '../models/collection'
SourceSelector, import type { SourceSelector, ListFilter, ListSort } from '../types'
ListFilter,
ListSort,
} from '../types/common';
import { CollectionObject } from '../models/collection';
import type { ServiceObject } from '../models/service';
import type { CollectionInterface } from '../types/collection';
export const useCollectionsStore = defineStore('collectionsStore', () => { export const useCollectionsStore = defineStore('peopleCollectionsStore', () => {
// State // State
const collections = ref<CollectionObject[]>([]); const _collections = ref<Record<string, CollectionObject>>({})
const transceiving = ref(false)
/**
* Get count of collections in store
*/
const count = computed(() => Object.keys(_collections.value).length)
/**
* Check if any collections are present in store
*/
const has = computed(() => count.value > 0)
/**
* Get all collections present in store
*/
const collections = computed(() => Object.values(_collections.value))
/**
* Get all collections present in store grouped by service
*/
const collectionsByService = computed(() => {
const groups: Record<string, CollectionObject[]> = {}
Object.values(_collections.value).forEach((collection) => {
const serviceKey = `${collection.provider}:${collection.service}`
if (!groups[serviceKey]) {
groups[serviceKey] = []
}
groups[serviceKey].push(collection)
})
return groups
})
/**
* Get a specific collection from store, with optional retrieval
*
* @param provider - provider identifier
* @param service - service identifier
* @param identifier - collection identifier
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
*
* @returns Collection object or null
*/
function collection(provider: string, service: string | number, identifier: string | number, retrieve: boolean = false): CollectionObject | null {
const key = identifierKey(provider, service, identifier)
if (retrieve === true && !_collections.value[key]) {
console.debug(`[People Manager][Store] - Force fetching collection "${key}"`)
fetch(provider, service, identifier)
}
return _collections.value[key] || null
}
/**
* Get all collections for a specific service
*
* @param provider - provider identifier
* @param service - service identifier
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
*
* @returns Array of collection objects
*/
function collectionsForService(provider: string, service: string | number, retrieve: boolean = false): CollectionObject[] {
const serviceKeyPrefix = `${provider}:${service}:`
const serviceCollections = Object.entries(_collections.value)
.filter(([key]) => key.startsWith(serviceKeyPrefix))
.map(([_, collection]) => collection)
if (retrieve === true && serviceCollections.length === 0) {
console.debug(`[People Manager][Store] - Force fetching collections for service "${provider}:${service}"`)
const sources: SourceSelector = {
[provider]: {
[String(service)]: true
}
}
list(sources)
}
return serviceCollections
}
/**
* Create unique key for a collection
*/
function identifierKey(provider: string, service: string | number | null, identifier: string | number | null): string {
return `${provider}:${service ?? ''}:${identifier ?? ''}`
}
// Actions // Actions
/** /**
* Retrieve collections from the server * Retrieve all or specific collections, optionally filtered by source selector
*
* @param sources - optional source selector
* @param filter - optional list filter
* @param sort - optional list sort
*
* @returns Promise with collection object list keyed by provider, service, and collection identifier
*/ */
async function list( async function list(sources?: SourceSelector, filter?: ListFilter, sort?: ListSort): Promise<Record<string, CollectionObject>> {
sources?: SourceSelector, transceiving.value = true
filter?: ListFilter,
sort?: ListSort,
uid?: string
): Promise<CollectionObject[]> {
try { try {
const response = await collectionService.list({ sources, filter, sort, uid }); const response = await collectionService.list({ sources, filter, sort })
// Flatten the nested response into a flat array // Flatten nested structure: provider:service:collection -> "provider:service:collection": object
const flatCollections: CollectionObject[] = []; const collections: Record<string, CollectionObject> = {}
Object.entries(response).forEach(([_providerId, providerCollections]) => { Object.entries(response).forEach(([_providerId, providerServices]) => {
Object.entries(providerCollections).forEach(([_serviceId, serviceCollections]) => { Object.entries(providerServices).forEach(([_serviceId, serviceCollections]) => {
Object.values(serviceCollections).forEach((collection: CollectionInterface) => { Object.entries(serviceCollections).forEach(([_collectionId, collectionObj]) => {
flatCollections.push(new CollectionObject().fromJson(collection)); const key = identifierKey(collectionObj.provider, collectionObj.service, collectionObj.identifier)
}); collections[key] = collectionObj
}); })
}); })
})
console.debug('[People Manager](Store) - Successfully retrieved', flatCollections.length, 'collections:', flatCollections.map(c => ({ // Merge retrieved collections into state
id: c.id, _collections.value = { ..._collections.value, ...collections }
label: c.label,
service: c.service,
provider: c.provider
})));
collections.value = flatCollections; console.debug('[People Manager][Store] - Successfully retrieved', Object.keys(collections).length, 'collections')
return flatCollections; return collections
} catch (error: any) { } catch (error: any) {
console.error('[People Manager](Store) - Failed to retrieve collections:', error); console.error('[People Manager][Store] - Failed to retrieve collections:', error)
throw error; throw error
} finally {
transceiving.value = false
} }
} }
/** /**
* Fetch a specific collection * Retrieve a specific collection by provider, service, and identifier
*
* @param provider - provider identifier
* @param service - service identifier
* @param identifier - collection identifier
*
* @returns Promise with collection object
*/ */
async function fetch( async function fetch(provider: string, service: string | number, identifier: string | number): Promise<CollectionObject> {
provider: string, transceiving.value = true
service: string,
identifier: string | number,
uid?: string
): Promise<CollectionObject | null> {
try { try {
const response = await collectionService.fetch({ provider, service, identifier, uid }); const response = await collectionService.fetch({ provider, service, collection: identifier })
return new CollectionObject().fromJson(response); // Merge fetched collection into state
const key = identifierKey(response.provider, response.service, response.identifier)
_collections.value[key] = response
console.debug('[People Manager][Store] - Successfully fetched collection:', key)
return response
} catch (error: any) { } catch (error: any) {
console.error('[People Manager](Store) - Failed to fetch collection:', error); console.error('[People Manager][Store] - Failed to fetch collection:', error)
throw error; throw error
} finally {
transceiving.value = false
} }
} }
/** /**
* Create a fresh collection object with default values * Retrieve collection availability status for a given source selector
*
* @param sources - source selector to check availability for
*
* @returns Promise with collection availability status
*/ */
function fresh(): CollectionObject { async function extant(sources: SourceSelector) {
return new CollectionObject(); transceiving.value = true
try {
const response = await collectionService.extant({ sources })
console.debug('[People Manager][Store] - Successfully checked', sources ? Object.keys(sources).length : 0, 'collections')
return response
} catch (error: any) {
console.error('[People Manager][Store] - Failed to check collections:', error)
throw error
} finally {
transceiving.value = false
}
} }
/** /**
* Create a new collection * Create a new collection with given provider, service, and data
*
* @param provider - provider identifier for the new collection
* @param service - service identifier for the new collection
* @param collection - optional parent collection identifier
* @param data - collection properties for creation
*
* @returns Promise with created collection object
*/ */
async function create( async function create(provider: string, service: string | number, collection: string | number | null, data: CollectionPropertiesObject): Promise<CollectionObject> {
service: ServiceObject, transceiving.value = true
collection: CollectionObject,
options?: string[],
uid?: string
): Promise<CollectionObject | null> {
try { try {
if (service.provider === null || service.id === null) {
throw new Error('Invalid service object, must have a provider and identifier');
}
const response = await collectionService.create({ const response = await collectionService.create({
provider: service.provider, provider,
service: service.id, service,
data: collection.toJson(), collection,
options, properties: data
uid })
});
const createdCollection = new CollectionObject().fromJson(response); // Merge created collection into state
collections.value.push(createdCollection); const key = identifierKey(response.provider, response.service, response.identifier)
_collections.value[key] = response
console.debug('[People Manager](Store) - Successfully created collection'); console.debug('[People Manager][Store] - Successfully created collection:', key)
return response
return createdCollection;
} catch (error: any) { } catch (error: any) {
console.error('[People Manager](Store) - Failed to create collection:', error); console.error('[People Manager][Store] - Failed to create collection:', error)
throw error; throw error
} finally {
transceiving.value = false
} }
} }
/** /**
* Modify an existing collection * Update an existing collection with given provider, service, identifier, and data
*
* @param provider - provider identifier for the collection to update
* @param service - service identifier for the collection to update
* @param identifier - collection identifier for the collection to update
* @param data - collection properties for update
*
* @returns Promise with updated collection object
*/ */
async function modify( async function update(provider: string, service: string | number, identifier: string | number, data: CollectionPropertiesObject): Promise<CollectionObject> {
collection: CollectionObject, transceiving.value = true
uid?: string
): Promise<CollectionObject | null> {
try { try {
if (!collection.provider || !collection.service || !collection.id) { const response = await collectionService.update({
throw new Error('Collection must have provider, service, and id'); provider,
} service,
identifier,
properties: data
})
const response = await collectionService.modify({ // Merge updated collection into state
provider: collection.provider, const key = identifierKey(response.provider, response.service, response.identifier)
service: collection.service, _collections.value[key] = response
identifier: collection.id,
data: collection.toJson(),
uid
});
const modifiedCollection = new CollectionObject().fromJson(response); console.debug('[People Manager][Store] - Successfully updated collection:', key)
const index = collections.value.findIndex(c => c.id === collection.id); return response
if (index !== -1) {
collections.value[index] = modifiedCollection;
}
console.debug('[People Manager](Store) - Successfully modified collection');
return modifiedCollection;
} catch (error: any) { } catch (error: any) {
console.error('[People Manager](Store) - Failed to modify collection:', error); console.error('[People Manager][Store] - Failed to update collection:', error)
throw error; throw error
} finally {
transceiving.value = false
} }
} }
/** /**
* Delete a collection * Delete a collection by provider, service, and identifier
*
* @param provider - provider identifier for the collection to delete
* @param service - service identifier for the collection to delete
* @param identifier - collection identifier for the collection to delete
*
* @returns Promise with deletion result
*/ */
async function destroy( async function remove(provider: string, service: string | number, identifier: string | number): Promise<any> {
collection: CollectionObject, transceiving.value = true
uid?: string
): Promise<boolean> {
try { try {
if (!collection.provider || !collection.service || !collection.id) { await collectionService.delete({ provider, service, identifier })
throw new Error('Collection must have provider, service, and id');
}
const response = await collectionService.destroy({ // Remove deleted collection from state
provider: collection.provider, const key = identifierKey(provider, service, identifier)
service: collection.service, delete _collections.value[key]
identifier: collection.id,
uid
});
if (response.success) { console.debug('[People Manager][Store] - Successfully deleted collection:', key)
const index = collections.value.findIndex(c => c.id === collection.id);
if (index !== -1) {
collections.value.splice(index, 1);
}
}
console.debug('[People Manager](Store) - Successfully destroyed collection');
return response.success;
} catch (error: any) { } catch (error: any) {
console.error('[People Manager](Store) - Failed to destroy collection:', error); console.error('[People Manager][Store] - Failed to delete collection:', error)
throw error; throw error
} finally {
transceiving.value = false
} }
} }
// Return public API
return { return {
// State // State (readonly)
transceiving: readonly(transceiving),
// Getters
count,
has,
collections, collections,
collectionsByService,
collectionsForService,
// Actions // Actions
collection,
list, list,
fetch, fetch,
fresh, extant,
create, create,
modify, update,
destroy, delete: remove,
}; }
}); })

View File

@@ -1,276 +1,346 @@
/** /**
* People Manager - Entities Store * Entities Store
*/ */
import { defineStore } from 'pinia'; import { ref, computed, readonly } from 'vue'
import { ref } from 'vue'; import { defineStore } from 'pinia'
import { entityService } from '../services/entityService'; import { entityService } from '../services'
import type { import { EntityObject } from '../models'
SourceSelector, import type { SourceSelector, ListFilter, ListSort, ListRange } from '../types/common'
ListFilter,
ListSort,
ListRange,
} from '../types/common';
import type {
EntityInterface,
} from '../types/entity';
import type { CollectionObject } from '../models/collection';
import { EntityObject } from '../models/entity'
import { IndividualObject } from '../models/individual';
import { OrganizationObject } from '../models/organization';
import { GroupObject } from '../models/group';
export const useEntitiesStore = defineStore('peopleEntitiesStore', () => { export const useEntitiesStore = defineStore('peopleEntitiesStore', () => {
// State // State
const entities = ref<EntityObject[]>([]); const _entities = ref<Record<string, EntityObject>>({})
const transceiving = ref(false)
/**
* Get count of entities in store
*/
const count = computed(() => Object.keys(_entities.value).length)
/**
* Check if any entities are present in store
*/
const has = computed(() => count.value > 0)
/**
* Get all entities present in store
*/
const entities = computed(() => Object.values(_entities.value))
/**
* Get a specific entity from store, with optional retrieval
*
* @param provider - provider identifier
* @param service - service identifier
* @param collection - collection identifier
* @param identifier - entity identifier
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
*
* @returns Entity object or null
*/
function entity(provider: string, service: string | number, collection: string | number, identifier: string | number, retrieve: boolean = false): EntityObject | null {
const key = identifierKey(provider, service, collection, identifier)
if (retrieve === true && !_entities.value[key]) {
console.debug(`[People Manager][Store] - Force fetching entity "${key}"`)
fetch(provider, service, collection, [identifier])
}
return _entities.value[key] || null
}
/**
* Get all entities for a specific collection
*
* @param provider - provider identifier
* @param service - service identifier
* @param collection - collection identifier
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
*
* @returns Array of entity objects
*/
function entitiesForCollection(provider: string, service: string | number, collection: string | number, retrieve: boolean = false): EntityObject[] {
const collectionKeyPrefix = `${provider}:${service}:${collection}:`
const collectionEntities = Object.entries(_entities.value)
.filter(([key]) => key.startsWith(collectionKeyPrefix))
.map(([_, entity]) => entity)
if (retrieve === true && collectionEntities.length === 0) {
console.debug(`[People Manager][Store] - Force fetching entities for collection "${provider}:${service}:${collection}"`)
const sources: SourceSelector = {
[provider]: {
[String(service)]: {
[String(collection)]: true
}
}
}
list(sources)
}
return collectionEntities
}
/**
* Create unique key for an entity
*/
function identifierKey(provider: string, service: string | number, collection: string | number, identifier: string | number): string {
return `${provider}:${service}:${collection}:${identifier}`
}
// Actions // Actions
/** /**
* Reset the store to initial state * Retrieve all or specific entities, optionally filtered by source selector
*
* @param sources - optional source selector
* @param filter - optional list filter
* @param sort - optional list sort
* @param range - optional list range
*
* @returns Promise with entity object list keyed by identifier
*/ */
function reset(): void { async function list(sources?: SourceSelector, filter?: ListFilter, sort?: ListSort, range?: ListRange): Promise<Record<string, EntityObject>> {
entities.value = []; transceiving.value = true
}
/**
* List entities for all or specific collection
*/
async function list(
provider: string | null,
service: string | null,
collection: string | number | null,
filter?: ListFilter,
sort?: ListSort,
range?: ListRange,
uid?: string
): Promise<EntityObject[]> {
try { try {
// Validate hierarchical requirements const response = await entityService.list({ sources, filter, sort, range })
if (collection !== null && (service === null || provider === null)) {
throw new Error('Collection requires both service and provider');
}
if (service !== null && provider === null) {
throw new Error('Service requires provider');
}
// Build sources object level by level // Flatten nested structure: provider:service:collection:entity -> "provider:service:collection:entity": object
const sources: SourceSelector = {}; const entities: Record<string, EntityObject> = {}
if (provider !== null) { Object.entries(response).forEach(([providerId, providerServices]) => {
if (service !== null) { Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
if (collection !== null) { Object.entries(serviceCollections).forEach(([collectionId, collectionEntities]) => {
sources[provider] = { [service]: { [collection]: true } }; Object.entries(collectionEntities).forEach(([entityId, entityData]) => {
} else { const key = identifierKey(providerId, serviceId, collectionId, entityId)
sources[provider] = { [service]: true }; entities[key] = entityData
} })
} else { })
sources[provider] = true; })
} })
}
// Transmit // Merge retrieved entities into state
const response = await entityService.list({ sources, filter, sort, range, uid }); _entities.value = { ..._entities.value, ...entities }
// Flatten the nested response into a flat array console.debug('[People Manager][Store] - Successfully retrieved', Object.keys(entities).length, 'entities')
const flatEntities: EntityObject[] = []; return entities
Object.entries(response).forEach(([, providerEntities]) => {
Object.entries(providerEntities).forEach(([, serviceEntities]) => {
Object.entries(serviceEntities).forEach(([, collectionEntities]) => {
Object.values(collectionEntities).forEach((entity: EntityInterface) => {
flatEntities.push(new EntityObject().fromJson(entity));
});
});
});
});
console.debug('[People Manager](Store) - Successfully retrieved', flatEntities.length, 'entities');
entities.value = flatEntities;
return flatEntities;
} catch (error: any) { } catch (error: any) {
console.error('[People Manager](Store) - Failed to retrieve entities:', error); console.error('[People Manager][Store] - Failed to retrieve entities:', error)
throw error; throw error
} finally {
transceiving.value = false
} }
} }
/** /**
* Fetch entities for a specific collection * Retrieve specific entities by provider, service, collection, and identifiers
*
* @param provider - provider identifier
* @param service - service identifier
* @param collection - collection identifier
* @param identifiers - array of entity identifiers to fetch
*
* @returns Promise with entity objects keyed by identifier
*/ */
async function fetch( async function fetch(provider: string, service: string | number, collection: string | number, identifiers: (string | number)[]): Promise<Record<string, EntityObject>> {
collection: CollectionObject, transceiving.value = true
identifiers: (string | number)[],
uid?: string
): Promise<EntityObject[]> {
try { try {
if (!collection.provider || !collection.service || !collection.id) { const response = await entityService.fetch({ provider, service, collection, identifiers })
throw new Error('Collection must have provider, service, and id');
}
const response = await entityService.fetch({ // Merge fetched entities into state
provider: collection.provider, const entities: Record<string, EntityObject> = {}
service: collection.service, Object.entries(response).forEach(([identifier, entityData]) => {
collection: collection.id, const key = identifierKey(provider, service, collection, identifier)
identifiers, entities[key] = entityData
uid _entities.value[key] = entityData
}); })
return Object.values(response).map(entity => new EntityObject().fromJson(entity)); console.debug('[People Manager][Store] - Successfully fetched', Object.keys(entities).length, 'entities')
return entities
} catch (error: any) { } catch (error: any) {
console.error('[People Manager](Store) - Failed to fetch entities:', error); console.error('[People Manager][Store] - Failed to fetch entities:', error)
throw error; throw error
} finally {
transceiving.value = false
} }
} }
/** /**
* Create a fresh entity object * Retrieve entity availability status for a given source selector
*
* @param sources - source selector to check availability for
*
* @returns Promise with entity availability status
*/ */
function fresh(type: string): EntityObject { async function extant(sources: SourceSelector) {
const entity = new EntityObject(); transceiving.value = true
if (type === 'organization') {
entity.data = new OrganizationObject();
} else if (type === 'group') {
entity.data = new GroupObject();
} else {
entity.data = new IndividualObject();
}
entity.data.created = new Date();
return entity;
}
/**
* Create a new entity
*/
async function create(
collection: CollectionObject,
entity: EntityObject,
options?: string[],
uid?: string
): Promise<EntityObject | null> {
try { try {
if (!collection.provider || !collection.service || !collection.id) { const response = await entityService.extant({ sources })
throw new Error('Collection must have provider, service, and id'); console.debug('[People Manager][Store] - Successfully checked entity availability')
} return response
const response = await entityService.create({
provider: collection.provider,
service: collection.service,
collection: collection.id,
data: entity.toJson(),
options,
uid
});
const createdEntity = new EntityObject().fromJson(response);
entities.value.push(createdEntity);
console.debug('[People Manager](Store) - Successfully created entity');
return createdEntity;
} catch (error: any) { } catch (error: any) {
console.error('[People Manager](Store) - Failed to create entity:', error); console.error('[People Manager][Store] - Failed to check entity availability:', error)
throw error; throw error
} } finally {
} transceiving.value = false
/**
* Modify an existing entity
*/
async function modify(
collection: CollectionObject,
entity: EntityObject,
uid?: string
): Promise<EntityObject | null> {
try {
if (!collection.provider || !collection.service || !collection.id) {
throw new Error('Collection must have provider, service, and id');
}
if (!entity.in || !entity.id) {
throw new Error('Invalid entity object, must have an collection and entity identifier');
}
if (collection.id !== entity.in) {
throw new Error('Invalid entity object, does not belong to the specified collection');
}
const response = await entityService.modify({
provider: collection.provider,
service: collection.service,
collection: collection.id,
identifier: entity.id,
data: entity.toJson(),
uid
});
const modifiedEntity = new EntityObject().fromJson(response);
const index = entities.value.findIndex(e => e.id === entity.id);
if (index !== -1) {
entities.value[index] = modifiedEntity;
}
console.debug('[People Manager](Store) - Successfully modified entity');
return modifiedEntity;
} catch (error: any) {
console.error('[People Manager](Store) - Failed to modify entity:', error);
throw error;
} }
} }
/** /**
* Delete an entity * Create a new entity with given provider, service, collection, and data
*
* @param provider - provider identifier for the new entity
* @param service - service identifier for the new entity
* @param collection - collection identifier for the new entity
* @param data - entity properties for creation
*
* @returns Promise with created entity object
*/ */
async function destroy( async function create(provider: string, service: string | number, collection: string | number, data: any): Promise<EntityObject> {
collection: CollectionObject, transceiving.value = true
entity: EntityObject,
uid?: string
): Promise<boolean> {
try { try {
if (!collection.provider || !collection.service || !collection.id) { const response = await entityService.create({ provider, service, collection, properties: data })
throw new Error('Collection must have provider, service, and id');
}
if (!entity.in || !entity.id) {
throw new Error('Invalid entity object, must have an collection and entity identifier');
}
if (collection.id !== entity.in) {
throw new Error('Invalid entity object, does not belong to the specified collection');
}
const response = await entityService.destroy({ // Add created entity to state
provider: collection.provider, const key = identifierKey(response.provider, response.service, response.collection, response.identifier)
service: collection.service, _entities.value[key] = response
collection: collection.id,
identifier: entity.id,
uid
});
if (response.success) { console.debug('[People Manager][Store] - Successfully created entity:', key)
const index = entities.value.findIndex(e => e.id === entity.id); return response
if (index !== -1) {
entities.value.splice(index, 1);
}
}
console.debug('[People Manager](Store) - Successfully destroyed entity');
return response.success;
} catch (error: any) { } catch (error: any) {
console.error('[People Manager](Store) - Failed to destroy entity:', error); console.error('[People Manager][Store] - Failed to create entity:', error)
throw error; throw error
} finally {
transceiving.value = false
} }
} }
/**
* Update an existing entity with given provider, service, collection, identifier, and data
*
* @param provider - provider identifier for the entity to update
* @param service - service identifier for the entity to update
* @param collection - collection identifier for the entity to update
* @param identifier - entity identifier for the entity to update
* @param data - entity properties for update
*
* @returns Promise with updated entity object
*/
async function update(provider: string, service: string | number, collection: string | number, identifier: string | number, data: any): Promise<EntityObject> {
transceiving.value = true
try {
const response = await entityService.update({ provider, service, collection, identifier, properties: data })
// Update entity in state
const key = identifierKey(response.provider, response.service, response.collection, response.identifier)
_entities.value[key] = response
console.debug('[People Manager][Store] - Successfully updated entity:', key)
return response
} catch (error: any) {
console.error('[People Manager][Store] - Failed to update entity:', error)
throw error
} finally {
transceiving.value = false
}
}
/**
* Delete an entity by provider, service, collection, and identifier
*
* @param provider - provider identifier for the entity to delete
* @param service - service identifier for the entity to delete
* @param collection - collection identifier for the entity to delete
* @param identifier - entity identifier for the entity to delete
*
* @returns Promise with deletion result
*/
async function remove(provider: string, service: string | number, collection: string | number, identifier: string | number): Promise<any> {
transceiving.value = true
try {
const response = await entityService.delete({ provider, service, collection, identifier })
// Remove entity from state
const key = identifierKey(provider, service, collection, identifier)
delete _entities.value[key]
console.debug('[People Manager][Store] - Successfully deleted entity:', key)
return response
} catch (error: any) {
console.error('[People Manager][Store] - Failed to delete entity:', error)
throw error
} finally {
transceiving.value = false
}
}
/**
* Retrieve delta changes for entities
*
* @param sources - source selector for delta check
*
* @returns Promise with delta changes (additions, modifications, deletions)
*
* Note: Delta returns only identifiers, not full entities.
* Caller should fetch full entities for additions/modifications separately.
*/
async function delta(sources: SourceSelector) {
transceiving.value = true
try {
const response = await entityService.delta({ sources })
// Process delta and update store
Object.entries(response).forEach(([provider, providerData]) => {
// Skip if no changes for provider
if (providerData === false) return
Object.entries(providerData).forEach(([service, serviceData]) => {
// Skip if no changes for service
if (serviceData === false) return
Object.entries(serviceData).forEach(([collection, collectionData]) => {
// Skip if no changes for collection
if (collectionData === false) return
// Process deletions (remove from store)
if (collectionData.deletions && collectionData.deletions.length > 0) {
collectionData.deletions.forEach((identifier) => {
const key = identifierKey(provider, service, collection, identifier)
delete _entities.value[key]
})
}
// Note: additions and modifications contain only identifiers
// The caller should fetch full entities using the fetch() method
})
})
})
console.debug('[People Manager][Store] - Successfully processed delta changes')
return response
} catch (error: any) {
console.error('[People Manager][Store] - Failed to process delta:', error)
throw error
} finally {
transceiving.value = false
}
}
// Return public API
return { return {
// State // State (readonly)
transceiving: readonly(transceiving),
// Getters
count,
has,
entities, entities,
entitiesForCollection,
// Actions // Actions
reset, entity,
list, list,
fetch, fetch,
fresh, extant,
create, create,
modify, update,
destroy, delete: remove,
delta,
} }
}); })

View File

@@ -1,8 +1,4 @@
/**
* Central export point for all People Manager stores
*/
export { useCollectionsStore } from './collectionsStore';
export { useEntitiesStore } from './entitiesStore';
export { useProvidersStore } from './providersStore'; export { useProvidersStore } from './providersStore';
export { useServicesStore } from './servicesStore'; export { useServicesStore } from './servicesStore';
export { useCollectionsStore } from './collectionsStore';
export { useEntitiesStore } from './entitiesStore';

View File

@@ -1,62 +1,142 @@
/** /**
* People Manager - Providers Store * Providers Store
*/ */
import { defineStore } from 'pinia'; import { ref, computed, readonly } from 'vue'
import { ref } from 'vue'; import { defineStore } from 'pinia'
import { providerService } from '../services/providerService'; import { providerService } from '../services'
import type { import { ProviderObject } from '../models/provider'
SourceSelector, import type { SourceSelector } from '../types'
ProviderInterface,
} from '../types';
export const useProvidersStore = defineStore('providersStore', () => { export const useProvidersStore = defineStore('peopleProvidersStore', () => {
// State // State
const providers = ref<Record<string, ProviderInterface>>({}); const _providers = ref<Record<string, ProviderObject>>({})
const transceiving = ref(false)
/**
* Get count of providers in store
*/
const count = computed(() => Object.keys(_providers.value).length)
/**
* Check if any providers are present in store
*/
const has = computed(() => count.value > 0)
/**
* Get all providers present in store
*/
const providers = computed(() => Object.values(_providers.value))
/**
* Get a specific provider from store, with optional retrieval
*
* @param identifier - Provider identifier
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
*
* @returns Provider object or null
*/
function provider(identifier: string, retrieve: boolean = false): ProviderObject | null {
if (retrieve === true && !_providers.value[identifier]) {
console.debug(`[People Manager][Store] - Force fetching provider "${identifier}"`)
fetch(identifier)
}
return _providers.value[identifier] || null
}
// Actions // Actions
/** /**
* List all available providers * Retrieve all or specific providers, optionally filtered by source selector
* *
* @returns Promise with provider list keyed by provider ID * @param request - list request parameters
*
* @returns Promise with provider object list keyed by provider identifier
*/ */
async function list(): Promise<Record<string, ProviderInterface>> { async function list(sources?: SourceSelector): Promise<Record<string, ProviderObject>> {
transceiving.value = true
try { try {
const response = await providerService.list(); const providers = await providerService.list({ sources })
console.debug('[People Manager](Store) - Successfully retrieved', Object.keys(response).length, 'providers:', Object.keys(response)); // Merge retrieved providers into state
_providers.value = { ..._providers.value, ...providers }
providers.value = response; console.debug('[People Manager][Store] - Successfully retrieved', Object.keys(providers).length, 'providers')
return response; return providers
} catch (error: any) { } catch (error: any) {
console.error('[People Manager](Store) - Failed to retrieve providers:', error); console.error('[People Manager][Store] - Failed to retrieve providers:', error)
throw error; throw error
} finally {
transceiving.value = false
} }
} }
/** /**
* Check which providers exist/are available * Retrieve a specific provider by identifier
* *
* @param sources - Source selector with provider IDs to check * @param identifier - provider identifier
* @returns Promise with provider availability status *
* @returns Promise with provider object
*/ */
async function extant(sources: SourceSelector): Promise<Record<string, boolean>> { async function fetch(identifier: string): Promise<ProviderObject> {
transceiving.value = true
try { try {
const response = await providerService.extant(sources); const provider = await providerService.fetch({ identifier })
return response;
// Merge fetched provider into state
_providers.value[provider.identifier] = provider
console.debug('[People Manager][Store] - Successfully fetched provider:', provider.identifier)
return provider
} catch (error: any) { } catch (error: any) {
console.error('[People Manager](Store) - Failed to check provider existence:', error); console.error('[People Manager][Store] - Failed to fetch provider:', error)
throw error; throw error
} finally {
transceiving.value = false
} }
} }
/**
* Retrieve provider availability status for a given source selector
*
* @param sources - source selector to check availability for
*
* @returns Promise with provider availability status
*/
async function extant(sources: SourceSelector) {
transceiving.value = true
try {
const response = await providerService.extant({ sources })
Object.entries(response).forEach(([providerId, providerStatus]) => {
if (providerStatus === false) {
delete _providers.value[providerId]
}
})
console.debug('[People Manager][Store] - Successfully checked', sources ? Object.keys(sources).length : 0, 'providers')
return response
} catch (error: any) {
console.error('[People Manager][Store] - Failed to check providers:', error)
throw error
} finally {
transceiving.value = false
}
}
// Return public API
return { return {
// State // State
transceiving: readonly(transceiving),
// computed
count,
has,
providers, providers,
provider,
// Actions // functions
list, list,
fetch,
extant, extant,
}; }
}); })

View File

@@ -1,95 +1,259 @@
/** /**
* People Manager - Services Store * Services Store
*/ */
import { defineStore } from 'pinia'; import { ref, computed, readonly } from 'vue'
import { ref } from 'vue'; import { defineStore } from 'pinia'
import { serviceService } from '../services/serviceService'; import { serviceService } from '../services'
import { ServiceObject } from '../models/service'; import { ServiceObject } from '../models/service'
import type { ServiceInterface } from '../types/service';
import type { import type {
SourceSelector, SourceSelector,
ListFilter, ServiceInterface,
ListSort, } from '../types'
} from '../types/common';
export const useServicesStore = defineStore('peopleServicesStore', () => { export const useServicesStore = defineStore('peopleServicesStore', () => {
// State // State
const services = ref<ServiceObject[]>([]); const _services = ref<Record<string, ServiceObject>>({})
const transceiving = ref(false)
/**
* Get count of services in store
*/
const count = computed(() => Object.keys(_services.value).length)
/**
* Check if any services are present in store
*/
const has = computed(() => count.value > 0)
/**
* Get all services present in store
*/
const services = computed(() => Object.values(_services.value))
/**
* Get all services present in store grouped by provider
*/
const servicesByProvider = computed(() => {
const groups: Record<string, ServiceObject[]> = {}
Object.values(_services.value).forEach((service) => {
const providerServices = (groups[service.provider] ??= [])
providerServices.push(service)
})
return groups
})
/**
* Get a specific service from store, with optional retrieval
*
* @param provider - provider identifier
* @param identifier - service identifier
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
*
* @returns Service object or null
*/
function service(provider: string, identifier: string | number, retrieve: boolean = false): ServiceObject | null {
const key = identifierKey(provider, identifier)
if (retrieve === true && !_services.value[key]) {
console.debug(`[People Manager][Store] - Force fetching service "${key}"`)
fetch(provider, identifier)
}
return _services.value[key] || null
}
/**
* Unique key for a service
*/
function identifierKey(provider: string, identifier: string | number | null): string {
return `${provider}:${identifier ?? ''}`
}
// Actions // Actions
/** /**
* Retrieve services from the server * Retrieve all or specific services, optionally filtered by source selector
*
* @param sources - optional source selector
*
* @returns Promise with service object list keyed by provider and service identifier
*/ */
async function list( async function list(sources?: SourceSelector): Promise<Record<string, ServiceObject>> {
sources?: SourceSelector, transceiving.value = true
filter?: ListFilter,
sort?: ListSort,
uid?: string
): Promise<ServiceObject[]> {
try { try {
const response = await serviceService.list({ sources, filter, sort, uid }); const response = await serviceService.list({ sources })
// Flatten the nested response into a flat array // Flatten nested structure: provider-id: { service-id: object } -> "provider-id:service-id": object
const flatServices: ServiceObject[] = []; const services: Record<string, ServiceObject> = {}
Object.entries(response).forEach(([providerId, providerServices]) => { Object.entries(response).forEach(([_providerId, providerServices]) => {
Object.values(providerServices).forEach((service: ServiceInterface) => { Object.entries(providerServices).forEach(([_serviceId, serviceObj]) => {
// Ensure provider is set on the service object const key = identifierKey(serviceObj.provider, serviceObj.identifier)
service.provider = service.provider || providerId; services[key] = serviceObj
flatServices.push(new ServiceObject().fromJson(service)); })
}); })
});
console.debug('[People Manager](Store) - Successfully retrieved', flatServices.length, 'services:', flatServices.map(s => ({ // Merge retrieved services into state
id: s.id, _services.value = { ..._services.value, ...services }
label: s.label,
provider: s.provider
})));
services.value = flatServices; console.debug('[People Manager][Store] - Successfully retrieved', Object.keys(services).length, 'services')
return flatServices; return services
} catch (error: any) { } catch (error: any) {
console.error('[People Manager](Store) - Failed to retrieve services:', error); console.error('[People Manager][Store] - Failed to retrieve services:', error)
throw error; throw error
} finally {
transceiving.value = false
} }
} }
/** /**
* Fetch a specific service * Retrieve a specific service by provider and identifier
*
* @param provider - provider identifier
* @param identifier - service identifier
* *
* @param provider - Provider identifier
* @param identifier - Service identifier
* @param uid - Optional user identifier
* @returns Promise with service object * @returns Promise with service object
*/ */
async function fetch( async function fetch(provider: string, identifier: string | number): Promise<ServiceObject> {
provider: string, transceiving.value = true
identifier: string,
uid?: string
): Promise<ServiceObject | null> {
try { try {
const response = await serviceService.fetch({ provider, service: identifier, uid }); const service = await serviceService.fetch({ provider, identifier })
return new ServiceObject().fromJson(response);
// Merge fetched service into state
const key = identifierKey(service.provider, service.identifier)
_services.value[key] = service
console.debug('[People Manager][Store] - Successfully fetched service:', key)
return service
} catch (error: any) { } catch (error: any) {
console.error('[People Manager](Store) - Failed to fetch service:', error); console.error('[People Manager][Store] - Failed to fetch service:', error)
throw error; throw error
} finally {
transceiving.value = false
} }
} }
/** /**
* Create a fresh service object with default values * Retrieve service availability status for a given source selector
*
* @param sources - source selector to check availability for
*
* @returns Promise with service availability status
*/ */
function fresh(): ServiceObject { async function extant(sources: SourceSelector) {
return new ServiceObject(); transceiving.value = true
try {
const response = await serviceService.extant({ sources })
console.debug('[People Manager][Store] - Successfully checked', sources ? Object.keys(sources).length : 0, 'services')
return response
} catch (error: any) {
console.error('[People Manager][Store] - Failed to check services:', error)
throw error
} finally {
transceiving.value = false
}
} }
/**
* Create a new service with given provider and data
*
* @param provider - provider identifier for the new service
* @param data - partial service data for creation
*
* @returns Promise with created service object
*/
async function create(provider: string, data: Partial<ServiceInterface>): Promise<ServiceObject> {
transceiving.value = true
try {
const service = await serviceService.create({ provider, data })
// Merge created service into state
const key = identifierKey(service.provider, service.identifier)
_services.value[key] = service
console.debug('[People Manager][Store] - Successfully created service:', key)
return service
} catch (error: any) {
console.error('[People Manager][Store] - Failed to create service:', error)
throw error
} finally {
transceiving.value = false
}
}
/**
* Update an existing service with given provider, identifier, and data
*
* @param provider - provider identifier for the service to update
* @param identifier - service identifier for the service to update
* @param data - partial service data for update
*
* @returns Promise with updated service object
*/
async function update(provider: string, identifier: string | number, data: Partial<ServiceInterface>): Promise<ServiceObject> {
transceiving.value = true
try {
const service = await serviceService.update({ provider, identifier, data })
// Merge updated service into state
const key = identifierKey(service.provider, service.identifier)
_services.value[key] = service
console.debug('[People Manager][Store] - Successfully updated service:', key)
return service
} catch (error: any) {
console.error('[People Manager][Store] - Failed to update service:', error)
throw error
} finally {
transceiving.value = false
}
}
/**
* Delete a service by provider and identifier
*
* @param provider - provider identifier for the service to delete
* @param identifier - service identifier for the service to delete
*
* @returns Promise with deletion result
*/
async function remove(provider: string, identifier: string | number): Promise<any> {
transceiving.value = true
try {
await serviceService.delete({ provider, identifier })
// Remove deleted service from state
const key = identifierKey(provider, identifier)
delete _services.value[key]
console.debug('[People Manager][Store] - Successfully deleted service:', key)
} catch (error: any) {
console.error('[People Manager][Store] - Failed to delete service:', error)
throw error
} finally {
transceiving.value = false
}
}
// Return public API
return { return {
// State // State (readonly)
transceiving: readonly(transceiving),
// Getters
count,
has,
services, services,
servicesByProvider,
// Actions // Actions
service,
list, list,
fetch, fetch,
fresh, extant,
}; create,
}); update,
delete: remove,
}
})

View File

@@ -1,68 +1,45 @@
/** /**
* Collection-related type definitions for People Manager * Collection type definitions
*/ */
import type { ListFilter, ListSort, SourceSelector } from './common';
import type { ListFilter, ListSort, SourceSelector } from "./common";
/** /**
* Permission settings for a collection * Collection information
*/
export interface CollectionPermissionInterface {
view: boolean;
create: boolean;
modify: boolean;
destroy: boolean;
share: boolean;
}
/**
* Permissions settings for multiple users in a collection
*/
export interface CollectionPermissionsInterface {
[userId: string]: CollectionPermissionInterface;
}
/**
* Role settings for a collection
*/
export interface CollectionRolesInterface {
individual?: boolean;
[roleType: string]: boolean | undefined;
}
/**
* Content type settings for a collection
*/
export interface CollectionContentsInterface {
individual?: boolean;
organization?: boolean;
group?: boolean;
[contentType: string]: boolean | undefined;
}
/**
* Represents a collection within a service
*/ */
export interface CollectionInterface { export interface CollectionInterface {
'@type': string; provider: string;
provider: string | null; service: string | number;
service: string | null; collection: string | number | null;
in: number | string | null; identifier: string | number;
id: number | string | null; signature?: string | null;
label: string | null; created?: string | null;
description: string | null; modified?: string | null;
priority: number | null; properties: CollectionPropertiesInterface;
visibility: string | null;
color: string | null;
enabled: boolean;
signature: string | null;
permissions: CollectionPermissionsInterface;
roles: CollectionRolesInterface;
contents: CollectionContentsInterface;
} }
export type CollectionContentTypes = 'individual' | 'organization' | 'group';
export interface CollectionBaseProperties {
'@type': string;
version: number;
}
export interface CollectionImmutableProperties extends CollectionBaseProperties {
content: CollectionContentTypes[];
}
export interface CollectionMutableProperties extends CollectionBaseProperties {
label: string;
description: string | null;
rank: number | null;
visibility: boolean | null;
color: string | null;
}
export interface CollectionPropertiesInterface extends CollectionMutableProperties, CollectionImmutableProperties {}
/** /**
* Request to collection list endpoint * Collection list
*/ */
export interface CollectionListRequest { export interface CollectionListRequest {
sources?: SourceSelector; sources?: SourceSelector;
@@ -70,9 +47,6 @@ export interface CollectionListRequest {
sort?: ListSort; sort?: ListSort;
} }
/**
* Response from collection list endpoint
*/
export interface CollectionListResponse { export interface CollectionListResponse {
[providerId: string]: { [providerId: string]: {
[serviceId: string]: { [serviceId: string]: {
@@ -82,15 +56,23 @@ export interface CollectionListResponse {
} }
/** /**
* Request to collection extant endpoint * Collection fetch
*/
export interface CollectionFetchRequest {
provider: string;
service: string | number;
collection: string | number;
}
export interface CollectionFetchResponse extends CollectionInterface {}
/**
* Collection extant
*/ */
export interface CollectionExtantRequest { export interface CollectionExtantRequest {
sources: SourceSelector; sources: SourceSelector;
} }
/**
* Response from collection extant endpoint
*/
export interface CollectionExtantResponse { export interface CollectionExtantResponse {
[providerId: string]: { [providerId: string]: {
[serviceId: string]: { [serviceId: string]: {
@@ -100,62 +82,41 @@ export interface CollectionExtantResponse {
} }
/** /**
* Request to collection fetch endpoint * Collection create
*/
export interface CollectionFetchRequest {
provider: string;
service: string;
identifier: string | number;
}
/**
* Response from collection fetch endpoint
*/
export interface CollectionFetchResponse extends CollectionInterface {}
/**
* Request to collection create endpoint
*/ */
export interface CollectionCreateRequest { export interface CollectionCreateRequest {
provider: string; provider: string;
service: string; service: string | number;
data: CollectionInterface; collection?: string | number | null; // Parent Collection Identifier
options?: (string)[]; properties: CollectionMutableProperties;
} }
/** export interface CollectionCreateResponse extends CollectionInterface {}
* Response from collection create endpoint
*/
export interface CollectionCreateResponse extends CollectionInterface {}
/** /**
* Request to collection modify endpoint * Collection modify
*/ */
export interface CollectionModifyRequest { export interface CollectionUpdateRequest {
provider: string; provider: string;
service: string; service: string | number;
identifier: string | number; identifier: string | number;
data: CollectionInterface; properties: CollectionMutableProperties;
} }
/** export interface CollectionUpdateResponse extends CollectionInterface {}
* Response from collection modify endpoint
*/
export interface CollectionModifyResponse extends CollectionInterface {}
/** /**
* Request to collection destroy endpoint * Collection delete
*/ */
export interface CollectionDestroyRequest { export interface CollectionDeleteRequest {
provider: string; provider: string;
service: string; service: string | number;
identifier: string | number; identifier: string | number;
options?: {
force?: boolean; // Whether to force delete even if collection is not empty
};
} }
export interface CollectionDeleteResponse {
/**
* Response from collection destroy endpoint
*/
export interface CollectionDestroyResponse {
success: boolean; success: boolean;
} }

View File

@@ -1,9 +1,7 @@
/** /**
* Common types shared across People Manager services * Common types shared across provider, service, collection, and entity request and responses.
*/ */
import type { FilterComparisonOperator, FilterConjunctionOperator } from './service';
/** /**
* Base API request envelope * Base API request envelope
*/ */
@@ -46,14 +44,19 @@ export interface ApiErrorResponse {
export type ApiResponse<T = any> = ApiSuccessResponse<T> | ApiErrorResponse; export type ApiResponse<T = any> = ApiSuccessResponse<T> | ApiErrorResponse;
/** /**
* Source selector structure for hierarchical resource selection * Selector for targeting specific providers, services, collections, or entities in list or extant operations.
* Structure: Provider -> Service -> Collection -> Entity
* *
* Examples: * Example usage:
* - Simple boolean: { "local": true } * {
* - Nested services: { "system": { "personal": true, "recents": true } } * "provider1": true, // Select all services/collections/entities under provider1
* - Collection IDs: { "system": { "personal": { "299": true, "176": true } } } * "provider2": {
* - Entity IDs: { "system": { "personal": { "299": [1350, 1353, 5000] } } } * "serviceA": true, // Select all collections/entities under serviceA of provider2
* "serviceB": {
* "collectionX": true, // Select all entities under collectionX of serviceB of provider2
* "collectionY": [1, 2, 3] // Select entities with identifiers 1, 2, and 3 under collectionY of serviceB of provider2
* }
* }
* }
*/ */
export type SourceSelector = { export type SourceSelector = {
[provider: string]: boolean | ServiceSelector; [provider: string]: boolean | ServiceSelector;
@@ -69,39 +72,85 @@ export type CollectionSelector = {
export type EntitySelector = (string | number)[]; export type EntitySelector = (string | number)[];
/**
* Filter condition for building complex queries
*/
export interface FilterCondition {
attribute: string;
value: string | number | boolean | any[];
comparator?: FilterComparisonOperator;
conjunction?: FilterConjunctionOperator;
}
/** /**
* Filter criteria for list operations * Filter comparison for list operations
* Can be simple key-value pairs or complex filter conditions */
export const ListFilterComparisonOperator = {
EQ: 1, // Equal
NEQ: 2, // Not Equal
GT: 4, // Greater Than
LT: 8, // Less Than
GTE: 16, // Greater Than or Equal
LTE: 32, // Less Than or Equal
IN: 64, // In Array
NIN: 128, // Not In Array
LIKE: 256, // Like
NLIKE: 512, // Not Like
} as const;
export type ListFilterComparisonOperator = typeof ListFilterComparisonOperator[keyof typeof ListFilterComparisonOperator];
/**
* Filter conjunction for list operations
*/
export const ListFilterConjunctionOperator = {
NONE: '',
AND: 'AND',
OR: 'OR',
} as const;
export type ListFilterConjunctionOperator = typeof ListFilterConjunctionOperator[keyof typeof ListFilterConjunctionOperator];
/**
* Filter condition for list operations
*
* Tuple format: [value, comparator?, conjunction?]
*/
export type ListFilterCondition = [
string | number | boolean | string[] | number[],
ListFilterComparisonOperator?,
ListFilterConjunctionOperator?
];
/**
* Filter for list operations
*
* Values can be:
* - Simple primitives (string | number | boolean) for default equality comparison
* - ListFilterCondition tuple for explicit comparator/conjunction
*
* Examples:
* - Simple usage: { name: "John" }
* - With comparator: { age: [25, ListFilterComparisonOperator.GT] }
* - With conjunction: { age: [25, ListFilterComparisonOperator.GT, ListFilterConjunctionOperator.AND] }
* - With array value for IN operator: { status: [["active", "pending"], ListFilterComparisonOperator.IN] }
*/ */
export interface ListFilter { export interface ListFilter {
label?: string; [attribute: string]: string | number | boolean | ListFilterCondition;
[key: string]: any;
} }
/** /**
* Sort options for list operations * Sort for list operations
*
* Values can be:
* - true for ascending
* - false for descending
*/ */
export interface ListSort { export interface ListSort {
[key: string]: boolean; [attribute: string]: boolean;
} }
/** /**
* Range specification for pagination/limiting results * Range for list operations
*
* Values can be:
* - relative based on item identifier
* - absolute based on item count
*/ */
export interface ListRange { export interface ListRange {
type: 'tally'; type: 'tally';
anchor: 'absolute' | 'relative'; anchor: 'relative' | 'absolute';
position: number; position: string | number;
tally: number; tally: number;
} }

View File

@@ -1,30 +1,27 @@
/**
* Entity type definitions
*/
import type { ListFilter, ListRange, ListSort, SourceSelector } from './common'; import type { ListFilter, ListRange, ListSort, SourceSelector } from './common';
import type { GroupInterface } from './group';
import type { IndividualInterface } from './individual'; import type { IndividualInterface } from './individual';
import type { OrganizationInterface } from './organization'; import type { OrganizationInterface } from './organization';
import type { GroupInterface } from './group';
/** /**
* Entity-related type definitions for People Manager * Entity definition
*/ */
export interface EntityInterface<T = IndividualInterface | OrganizationInterface | GroupInterface> {
/** provider: string;
* Represents a person entity (contact) service: string;
*/ collection: string | number;
export interface EntityInterface { identifier: string | number;
'@type': string;
version: number;
in: string | number | null;
id: string | number | null;
createdOn: Date | null;
createdBy: string | null;
modifiedOn: Date | null;
modifiedBy: string | null;
signature: string | null; signature: string | null;
data: IndividualInterface | OrganizationInterface | GroupInterface | null; created: string | null;
modified: string | null;
properties: T;
} }
/** /**
* Request to entity list endpoint * Entity list
*/ */
export interface EntityListRequest { export interface EntityListRequest {
sources?: SourceSelector; sources?: SourceSelector;
@@ -33,127 +30,102 @@ export interface EntityListRequest {
range?: ListRange; range?: ListRange;
} }
/**
* Response from entity list endpoint
*/
export interface EntityListResponse { export interface EntityListResponse {
[providerId: string]: { [providerId: string]: {
[serviceId: string]: { [serviceId: string]: {
[collectionId: string]: { [collectionId: string]: {
[entityId: string]: EntityInterface; [identifier: string]: EntityInterface<IndividualInterface | OrganizationInterface | GroupInterface>;
}; };
}; };
}; };
} }
/** /**
* Request to entity delta endpoint * Entity fetch
*/ */
export interface EntityDeltaRequest { export interface EntityFetchRequest {
sources: SourceSelector; provider: string;
service: string | number;
collection: string | number;
identifiers: (string | number)[];
}
export interface EntityFetchResponse {
[identifier: string]: EntityInterface<IndividualInterface | OrganizationInterface | GroupInterface>;
} }
/** /**
* Response from entity delta endpoint * Entity extant
*/
export interface EntityDeltaResponse {
[providerId: string]: {
[serviceId: string]: {
[collectionId: string]: {
signature: string;
created?: {
[entityId: string]: EntityInterface;
};
modified?: {
[entityId: string]: EntityInterface;
};
deleted?: string[]; // Array of deleted entity IDs
};
};
};
}
/**
* Request to entity extant endpoint
*/ */
export interface EntityExtantRequest { export interface EntityExtantRequest {
sources: SourceSelector; sources: SourceSelector;
} }
/**
* Response from entity extant endpoint
*/
export interface EntityExtantResponse { export interface EntityExtantResponse {
[providerId: string]: { [providerId: string]: {
[serviceId: string]: { [serviceId: string]: {
[collectionId: string]: { [collectionId: string]: {
[entityId: string]: boolean; [identifier: string]: boolean;
}; };
}; };
}; };
} }
/** /**
* Request to entity fetch endpoint * Entity create
*/ */
export interface EntityFetchRequest { export interface EntityCreateRequest<T = IndividualInterface | OrganizationInterface | GroupInterface> {
provider: string; provider: string;
service: string; service: string | number;
collection: string | number; collection: string | number;
identifiers: (string | number)[]; properties: T;
} }
/** export interface EntityCreateResponse<T = IndividualInterface | OrganizationInterface | GroupInterface> extends EntityInterface<T> {}
* Response from entity fetch endpoint
*/
export interface EntityFetchResponse extends Record<string, EntityInterface> {}
/** /**
* Request to entity create endpoint * Entity update
*/ */
export interface EntityCreateRequest { export interface EntityUpdateRequest<T = IndividualInterface | OrganizationInterface | GroupInterface> {
provider: string; provider: string;
service: string; service: string | number;
collection: string | number;
data: EntityInterface;
options?: (string)[];
}
/**
* Response from entity create endpoint
*/
export interface EntityCreateResponse extends EntityInterface {}
/**
* Request to entity modify endpoint
*/
export interface EntityModifyRequest {
provider: string;
service: string;
collection: string | number; collection: string | number;
identifier: string | number; identifier: string | number;
data: EntityInterface; properties: T;
options?: (string)[];
} }
/** export interface EntityUpdateResponse<T = IndividualInterface | OrganizationInterface | GroupInterface> extends EntityInterface<T> {}
* Response from entity modify endpoint
*/
export interface EntityModifyResponse extends EntityInterface {}
/** /**
* Request to entity destroy endpoint * Entity delete
*/ */
export interface EntityDestroyRequest { export interface EntityDeleteRequest {
provider: string; provider: string;
service: string; service: string | number;
collection: string | number; collection: string | number;
identifier: string | number; identifier: string | number;
} }
/** export interface EntityDeleteResponse {
* Response from entity destroy endpoint
*/
export interface EntityDestroyResponse {
success: boolean; success: boolean;
} }
/**
* Entity delta
*/
export interface EntityDeltaRequest {
sources: SourceSelector;
}
export interface EntityDeltaResponse {
[providerId: string]: false | {
[serviceId: string]: false | {
[collectionId: string]: false | {
signature: string;
additions: (string | number)[];
modifications: (string | number)[];
deletions: (string | number)[];
};
};
};
}

View File

@@ -1,7 +1,3 @@
/**
* Central export point for all People Manager types
*/
export type * from './collection'; export type * from './collection';
export type * from './common'; export type * from './common';
export type * from './entity'; export type * from './entity';

View File

@@ -1,5 +1,5 @@
/** /**
* Provider-specific types * Provider type definitions
*/ */
import type { SourceSelector } from "./common"; import type { SourceSelector } from "./common";
@@ -11,9 +11,11 @@ export interface ProviderCapabilitiesInterface {
ServiceFetch?: boolean; ServiceFetch?: boolean;
ServiceExtant?: boolean; ServiceExtant?: boolean;
ServiceCreate?: boolean; ServiceCreate?: boolean;
ServiceModify?: boolean; ServiceUpdate?: boolean;
ServiceDelete?: boolean; ServiceDelete?: boolean;
[key: string]: boolean | undefined; ServiceDiscover?: boolean;
ServiceTest?: boolean;
[key: string]: boolean | object | string[] | undefined;
} }
/** /**
@@ -21,33 +23,38 @@ export interface ProviderCapabilitiesInterface {
*/ */
export interface ProviderInterface { export interface ProviderInterface {
'@type': string; '@type': string;
id: string; identifier: string;
label: string; label: string;
capabilities: ProviderCapabilitiesInterface; capabilities: ProviderCapabilitiesInterface;
} }
/** /**
* Request to provider list endpoint * Provider list
*/ */
export interface ProviderListRequest {} export interface ProviderListRequest {
sources?: SourceSelector;
}
/**
* Response from provider list endpoint
*/
export interface ProviderListResponse { export interface ProviderListResponse {
[providerId: string]: ProviderInterface; [identifier: string]: ProviderInterface;
} }
/** /**
* Request to provider extant endpoint * Provider fetch
*/
export interface ProviderFetchRequest {
identifier: string;
}
export interface ProviderFetchResponse extends ProviderInterface {}
/**
* Provider extant
*/ */
export interface ProviderExtantRequest { export interface ProviderExtantRequest {
sources: SourceSelector; sources: SourceSelector;
} }
/**
* Response from provider extant endpoint
*/
export interface ProviderExtantResponse { export interface ProviderExtantResponse {
[providerId: string]: boolean; [identifier: string]: boolean;
} }

View File

@@ -1,40 +1,252 @@
/** /**
* Service-related type definitions for People Manager * Service type definitions
*/ */
import type { SourceSelector, ListFilterComparisonOperator } from './common';
import type { ListFilter, ListSort, SourceSelector } from "./common";
/** /**
* Filter comparison operators (bitmask values) * Service capabilities
*/ */
export const FilterComparisonOperator = { export interface ServiceCapabilitiesInterface {
EQ: 1, // Equal // Collection capabilities
NEQ: 2, // Not Equal CollectionList?: boolean;
GT: 4, // Greater Than CollectionListFilter?: ServiceListFilterCollection;
LT: 8, // Less Than CollectionListSort?: ServiceListSortCollection;
GTE: 16, // Greater Than or Equal CollectionExtant?: boolean;
LTE: 32, // Less Than or Equal CollectionFetch?: boolean;
IN: 64, // In Array CollectionCreate?: boolean;
NIN: 128, // Not In Array CollectionUpdate?: boolean;
LIKE: 256, // Like (pattern matching) CollectionDelete?: boolean;
NLIKE: 512, // Not Like // Message capabilities
} as const; EntityList?: boolean;
EntityListFilter?: ServiceListFilterEntity;
export type FilterComparisonOperator = typeof FilterComparisonOperator[keyof typeof FilterComparisonOperator]; EntityListSort?: ServiceListSortEntity;
EntityListRange?: ServiceListRange;
EntityDelta?: boolean;
EntityExtant?: boolean;
EntityFetch?: boolean;
EntityCreate?: boolean;
EntityUpdate?: boolean;
EntityDelete?: boolean;
EntityMove?: boolean;
EntityCopy?: boolean;
[key: string]: boolean | object | string | string[] | undefined;
}
/** /**
* Filter conjunction operators * Service information
*/ */
export const FilterConjunctionOperator = { export interface ServiceInterface {
NONE: '', '@type': string;
AND: 'AND', provider: string;
OR: 'OR', identifier: string | number | null;
} as const; label: string | null;
enabled: boolean;
export type FilterConjunctionOperator = typeof FilterConjunctionOperator[keyof typeof FilterConjunctionOperator]; capabilities?: ServiceCapabilitiesInterface;
location?: ServiceLocation | null;
identity?: ServiceIdentity | null;
auxiliary?: Record<string, any>; // Provider-specific extension data
}
/** /**
* Filter specification format * Service list
*/
export interface ServiceListRequest {
sources?: SourceSelector;
}
export interface ServiceListResponse {
[provider: string]: {
[identifier: string]: ServiceInterface;
};
}
/**
* Service fetch
*/
export interface ServiceFetchRequest {
provider: string;
identifier: string | number;
}
export interface ServiceFetchResponse extends ServiceInterface {}
/**
* Service extant
*/
export interface ServiceExtantRequest {
sources: SourceSelector;
}
export interface ServiceExtantResponse {
[provider: string]: {
[identifier: string]: boolean;
};
}
/**
* Service create
*/
export interface ServiceCreateRequest {
provider: string;
data: Partial<ServiceInterface>;
}
export interface ServiceCreateResponse extends ServiceInterface {}
/**
* Service update
*/
export interface ServiceUpdateRequest {
provider: string;
identifier: string | number;
data: Partial<ServiceInterface>;
}
export interface ServiceUpdateResponse extends ServiceInterface {}
/**
* Service delete
*/
export interface ServiceDeleteRequest {
provider: string;
identifier: string | number;
}
export interface ServiceDeleteResponse {}
/**
* Service discovery
*/
export interface ServiceDiscoverRequest {
identity: string; // Email address or domain
provider?: string; // Optional: specific provider ('jmap', 'smtp', etc.) or null for all
location?: string; // Optional: known hostname (bypasses DNS lookup)
secret?: string; // Optional: password/token for credential validation
}
export interface ServiceDiscoverResponse {
[provider: string]: ServiceLocation; // Uses existing ServiceLocation discriminated union
}
/**
* Service connection test
*/
export interface ServiceTestRequest {
provider: string;
// For existing service
identifier?: string | number | null;
// For fresh configuration
location?: ServiceLocation | null;
identity?: ServiceIdentity | null;
}
export interface ServiceTestResponse {
success: boolean;
message: string;
}
/**
* Service location - Base
*/
export interface ServiceLocationBase {
type: 'URI' | 'FILE';
}
/**
* Service location - URI-based type
*/
export interface ServiceLocationUri extends ServiceLocationBase {
type: 'URI';
scheme: string; // e.g., 'https', 'http'
host: string; // e.g., 'api.example.com'
port: number; // e.g., 443
path?: string; // e.g., '/v1/api'
verifyPeer?: boolean; // Verify SSL/TLS peer certificate
verifyHost?: boolean; // Verify SSL/TLS certificate host
}
/**
* Service location - File-based type (e.g., for local mail delivery or Unix socket)
*/
export interface ServiceLocationFile extends ServiceLocationBase {
type: 'FILE';
path: string; // File system path
}
/**
* Service location types
*/
export type ServiceLocation =
| ServiceLocationUri
| ServiceLocationFile;
/**
* Service identity - base
*/
export interface ServiceIdentityBase {
type: 'NA' | 'BA' | 'TA' | 'OA' | 'CC';
}
/**
* Service identity - No authentication
*/
export interface ServiceIdentityNone extends ServiceIdentityBase {
type: 'NA';
}
/**
* Service identity - Basic authentication type
*/
export interface ServiceIdentityBasic extends ServiceIdentityBase {
type: 'BA';
identity: string; // Username/email
secret: string; // Password
}
/**
* Token authentication (API key, static token)
*/
export interface ServiceIdentityToken extends ServiceIdentityBase {
type: 'TA';
token: string; // Authentication token/API key
}
/**
* OAuth authentication
*/
export interface ServiceIdentityOAuth extends ServiceIdentityBase {
type: 'OA';
accessToken: string; // Current access token
accessScope?: string[]; // Token scopes
accessExpiry?: number; // Unix timestamp when token expires
refreshToken?: string; // Refresh token for getting new access tokens
refreshLocation?: string; // Token refresh endpoint URL
}
/**
* Client certificate authentication (mTLS)
*/
export interface ServiceIdentityCertificate extends ServiceIdentityBase {
type: 'CC';
certificate: string; // X.509 certificate (PEM format or file path)
privateKey: string; // Private key (PEM format or file path)
passphrase?: string; // Optional passphrase for encrypted private key
}
/**
* Service identity configuration
* Discriminated union of all identity types
*/
export type ServiceIdentity =
| ServiceIdentityNone
| ServiceIdentityBasic
| ServiceIdentityToken
| ServiceIdentityOAuth
| ServiceIdentityCertificate;
/**
* List filter specification format
*
* Format: "type:length:defaultComparator:supportedComparators" * Format: "type:length:defaultComparator:supportedComparators"
* *
* Examples: * Examples:
@@ -50,162 +262,39 @@ export type FilterConjunctionOperator = typeof FilterConjunctionOperator[keyof t
* *
* Comparator values are bitmasks that can be combined * Comparator values are bitmasks that can be combined
*/ */
export type FilterSpec = string; export type ServiceListFilterCollection = {
'label'?: string;
'rank'?: string;
[attribute: string]: string | undefined;
};
export type ServiceListFilterEntity = {
'text'?: string;
'label'?: string;
'name'?: string;
'name.given'?: string;
'name.family'?: string;
'organization'?: string;
'email'?: string;
'phone'?: string;
'address'?: string;
[attribute: string]: string | undefined;
}
/** /**
* Parsed filter specification * Service list sort specification
*/ */
export interface ParsedFilterSpec { export type ServiceListSortCollection = ("label" | "rank" | string)[];
type: 'string' | 'integer' | 'boolean' | 'array'; export type ServiceListSortEntity = ( "label" | "name" | "name.given" | "name.family" | string)[];
export type ServiceListRange = {
'tally'?: string[];
};
export interface ServiceListFilterDefinition {
type: 'string' | 'integer' | 'date' | 'boolean' | 'array';
length: number; length: number;
defaultComparator: FilterComparisonOperator; defaultComparator: ListFilterComparisonOperator;
supportedComparators: FilterComparisonOperator[]; supportedComparators: ListFilterComparisonOperator[];
} }
/**
* Parse a filter specification string into its components
*
* @param spec - Filter specification string (e.g., "s:200:256:771")
* @returns Parsed filter specification object
*
* @example
* parseFilterSpec("s:200:256:771")
* // Returns: {
* // type: 'string',
* // length: 200,
* // defaultComparator: 256 (LIKE),
* // supportedComparators: [1, 2, 256, 512] (EQ, NEQ, LIKE, NLIKE)
* // }
*/
export function parseFilterSpec(spec: FilterSpec): ParsedFilterSpec {
const [typeCode, lengthStr, defaultComparatorStr, supportedComparatorsStr] = spec.split(':');
const typeMap: Record<string, ParsedFilterSpec['type']> = {
's': 'string',
'i': 'integer',
'b': 'boolean',
'a': 'array',
};
const type = typeMap[typeCode];
if (!type) {
throw new Error(`Invalid filter type code: ${typeCode}`);
}
const length = parseInt(lengthStr, 10);
const defaultComparator = parseInt(defaultComparatorStr, 10) as FilterComparisonOperator;
// Parse supported comparators from bitmask
const supportedComparators: FilterComparisonOperator[] = [];
const supportedBitmask = parseInt(supportedComparatorsStr, 10);
if (supportedBitmask !== 0) {
const allComparators = Object.values(FilterComparisonOperator).filter(v => typeof v === 'number') as number[];
for (const comparator of allComparators) {
if ((supportedBitmask & comparator) === comparator) {
supportedComparators.push(comparator as FilterComparisonOperator);
}
}
}
return {
type,
length,
defaultComparator,
supportedComparators,
};
}
/**
* Capabilities available for a service
*/
export interface ServiceCapabilitiesInterface {
// Collection capabilities
CollectionList?: boolean;
CollectionListFilter?: {
[key: string]: FilterSpec;
};
CollectionListSort?: string[];
CollectionExtant?: boolean;
CollectionFetch?: boolean;
CollectionCreate?: boolean;
CollectionModify?: boolean;
CollectionDestroy?: boolean;
// Entity capabilities
EntityList?: boolean;
EntityListFilter?: {
[key: string]: FilterSpec;
};
EntityListSort?: string[];
EntityListRange?: {
[rangeType: string]: string[]; // e.g., { "tally": ["absolute", "relative"] }
};
EntityDelta?: boolean;
EntityExtant?: boolean;
EntityFetch?: boolean;
EntityCreate?: boolean;
EntityModify?: boolean;
EntityDestroy?: boolean;
EntityCopy?: boolean;
EntityMove?: boolean;
}
/**
* Represents a service within a provider
*/
export interface ServiceInterface {
'@type': string;
provider: string;
id: string;
label: string;
capabilities?: ServiceCapabilitiesInterface;
enabled: boolean;
}
/**
* Request to service list endpoint
*/
export interface ServiceListRequest {
sources?: SourceSelector;
filter?: ListFilter;
sort?: ListSort;
}
/**
* Response from service list endpoint
*/
export interface ServiceListResponse {
[providerId: string]: {
[serviceId: string]: ServiceInterface;
};
}
/**
* Request to service extant endpoint
*/
export interface ServiceExtantRequest {
sources: SourceSelector;
}
/**
* Response from service extant endpoint
*/
export interface ServiceExtantResponse {
[providerId: string]: {
[serviceId: string]: boolean;
};
}
/**
* Request to service fetch endpoint
*/
export interface ServiceFetchRequest {
provider: string;
service: string;
}
/**
* Response from service fetch endpoint
*/
export interface ServiceFetchResponse extends ServiceInterface {}