refactor: standardize frontend
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
+131
-82
@@ -2,50 +2,131 @@
|
||||
* Class model for Collection Interface
|
||||
*/
|
||||
|
||||
import type {
|
||||
CollectionInterface,
|
||||
CollectionContentsInterface,
|
||||
CollectionPermissionsInterface,
|
||||
CollectionRolesInterface
|
||||
} from "@/types/collection";
|
||||
import type { CollectionContentTypes, CollectionInterface, CollectionPropertiesInterface } from "@/types/collection";
|
||||
|
||||
export class CollectionObject implements CollectionInterface {
|
||||
|
||||
_data!: CollectionInterface;
|
||||
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
'@type': 'people:collection',
|
||||
provider: null,
|
||||
service: null,
|
||||
in: null,
|
||||
id: null,
|
||||
label: null,
|
||||
description: null,
|
||||
priority: null,
|
||||
visibility: null,
|
||||
color: null,
|
||||
enabled: false,
|
||||
provider: '',
|
||||
service: '',
|
||||
collection: null,
|
||||
identifier: '',
|
||||
signature: null,
|
||||
permissions: {},
|
||||
roles: {},
|
||||
contents: {},
|
||||
created: null,
|
||||
modified: null,
|
||||
properties: new CollectionPropertiesObject(),
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: CollectionInterface) : CollectionObject {
|
||||
fromJson(data: CollectionInterface): CollectionObject {
|
||||
this._data = data;
|
||||
if (data.properties) {
|
||||
this._data.properties = new CollectionPropertiesObject().fromJson(data.properties as CollectionPropertiesInterface);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
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 {
|
||||
const cloned = new CollectionObject()
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data))
|
||||
return cloned
|
||||
const cloned = new CollectionObject();
|
||||
cloned._data = { ...this._data };
|
||||
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 */
|
||||
@@ -54,86 +135,54 @@ export class CollectionObject implements CollectionInterface {
|
||||
return this._data['@type'];
|
||||
}
|
||||
|
||||
get provider(): string | null {
|
||||
return this._data.provider
|
||||
get version(): number {
|
||||
return this._data.version;
|
||||
}
|
||||
|
||||
get service(): string | null {
|
||||
return this._data.service
|
||||
}
|
||||
|
||||
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
|
||||
get content(): CollectionContentTypes[] {
|
||||
return this._data.content || [];
|
||||
}
|
||||
|
||||
/** Mutable Properties */
|
||||
|
||||
get label(): string | null {
|
||||
return this._data.label
|
||||
}
|
||||
get label(): string {
|
||||
return this._data.label || '';
|
||||
}
|
||||
|
||||
set label(value: string ) {
|
||||
this._data.label = value
|
||||
}
|
||||
set label(value: string) {
|
||||
this._data.label = value;
|
||||
}
|
||||
|
||||
get description(): string | null {
|
||||
return this._data.description
|
||||
return this._data.description;
|
||||
}
|
||||
|
||||
set description(value: string ) {
|
||||
this._data.description = value
|
||||
set description(value: string | null) {
|
||||
this._data.description = value;
|
||||
}
|
||||
|
||||
get priority(): number | null {
|
||||
return this._data.priority
|
||||
get rank(): number | null {
|
||||
return this._data.rank;
|
||||
}
|
||||
|
||||
set priority(value: number ) {
|
||||
this._data.priority = value
|
||||
set rank(value: number | null) {
|
||||
this._data.rank = value;
|
||||
}
|
||||
|
||||
get visibility(): string | null {
|
||||
return this._data.visibility
|
||||
get visibility(): boolean | null {
|
||||
return this._data.visibility;
|
||||
}
|
||||
|
||||
set visibility(value: string ) {
|
||||
this._data.visibility = value
|
||||
set visibility(value: boolean | null) {
|
||||
this._data.visibility = value;
|
||||
}
|
||||
|
||||
get color(): string | null {
|
||||
return this._data.color
|
||||
return this._data.color;
|
||||
}
|
||||
|
||||
set color(value: string ) {
|
||||
this._data.color = value
|
||||
set color(value: string | null) {
|
||||
this._data.color = value;
|
||||
}
|
||||
|
||||
get enabled(): boolean {
|
||||
return this._data.enabled
|
||||
}
|
||||
|
||||
set enabled(value: boolean ) {
|
||||
this._data.enabled = value
|
||||
}
|
||||
|
||||
}
|
||||
+42
-88
@@ -16,138 +16,92 @@ export class EntityObject implements EntityInterface {
|
||||
|
||||
constructor() {
|
||||
this._data = {
|
||||
'@type': 'people:entity',
|
||||
version: 1,
|
||||
in: null,
|
||||
id: null,
|
||||
createdOn: null,
|
||||
createdBy: null,
|
||||
modifiedOn: null,
|
||||
modifiedBy: null,
|
||||
provider: '',
|
||||
service: '',
|
||||
collection: '',
|
||||
identifier: '',
|
||||
signature: null,
|
||||
data: null,
|
||||
created: null,
|
||||
modified: null,
|
||||
properties: new IndividualObject(),
|
||||
};
|
||||
}
|
||||
|
||||
fromJson(data: EntityInterface) : EntityObject {
|
||||
this._data = data;
|
||||
if (data.data) {
|
||||
const type = data.data.type;
|
||||
if (data.properties) {
|
||||
const type = data.properties.type;
|
||||
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') {
|
||||
this._data.data = new GroupObject().fromJson(data.data as GroupInterface);
|
||||
this._data.properties = new GroupObject().fromJson(data.properties as GroupInterface);
|
||||
} 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;
|
||||
}
|
||||
|
||||
toJson(): EntityInterface {
|
||||
const json = { ...this._data };
|
||||
if (this._data.data instanceof IndividualObject ||
|
||||
this._data.data instanceof OrganizationObject ||
|
||||
this._data.data instanceof GroupObject) {
|
||||
json.data = this._data.data.toJson();
|
||||
if (this._data.properties instanceof IndividualObject ||
|
||||
this._data.properties instanceof OrganizationObject ||
|
||||
this._data.properties instanceof GroupObject) {
|
||||
json.properties = this._data.properties.toJson();
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
clone(): EntityObject {
|
||||
const cloned = new EntityObject()
|
||||
cloned._data = JSON.parse(JSON.stringify(this._data))
|
||||
return cloned
|
||||
const cloned = new EntityObject();
|
||||
cloned._data = { ...this._data };
|
||||
return cloned;
|
||||
}
|
||||
|
||||
/** Immutable Properties */
|
||||
|
||||
get '@type'(): string {
|
||||
return this._data['@type'];
|
||||
|
||||
get provider(): string {
|
||||
return this._data.provider;
|
||||
}
|
||||
|
||||
get in(): number | string | null {
|
||||
return this._data.in;
|
||||
get service(): string {
|
||||
return this._data.service;
|
||||
}
|
||||
|
||||
get id(): number | string | null {
|
||||
return this._data.id;
|
||||
get collection(): string | number {
|
||||
return this._data.collection;
|
||||
}
|
||||
|
||||
get version(): number {
|
||||
return this._data.version;
|
||||
}
|
||||
|
||||
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 identifier(): string | number {
|
||||
return this._data.identifier;
|
||||
}
|
||||
|
||||
get signature(): string | null {
|
||||
return this._data.signature;
|
||||
}
|
||||
|
||||
/** Mutable Properties */
|
||||
|
||||
set createdOn(value: Date | null) {
|
||||
this._data.createdOn = value;
|
||||
get created(): string | null {
|
||||
return this._data.created;
|
||||
}
|
||||
|
||||
set createdBy(value: string | null) {
|
||||
this._data.createdBy = value;
|
||||
get modified(): string | null {
|
||||
return this._data.modified;
|
||||
}
|
||||
|
||||
set modifiedOn(value: Date | null) {
|
||||
this._data.modifiedOn = value;
|
||||
}
|
||||
|
||||
set modifiedBy(value: string | null) {
|
||||
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;
|
||||
get properties(): IndividualObject | OrganizationObject | GroupObject {
|
||||
if (this._data.properties instanceof IndividualObject ||
|
||||
this._data.properties instanceof OrganizationObject ||
|
||||
this._data.properties instanceof GroupObject) {
|
||||
return this._data.properties;
|
||||
}
|
||||
|
||||
if (this._data.data) {
|
||||
const type = this._data.data.type;
|
||||
let hydrated;
|
||||
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;
|
||||
const defaultProperties = new IndividualObject();
|
||||
this._data.properties = defaultProperties;
|
||||
return defaultProperties;
|
||||
}
|
||||
|
||||
set data(value: IndividualObject | OrganizationObject | GroupObject | null) {
|
||||
this._data.data = value;
|
||||
set properties(value: IndividualObject | OrganizationObject | GroupObject) {
|
||||
this._data.properties = value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 })
|
||||
};
|
||||
}
|
||||
}
|
||||
+2
-6
@@ -1,11 +1,7 @@
|
||||
/**
|
||||
* Central export point for all People Manager models
|
||||
*/
|
||||
|
||||
export { ProviderObject } from './provider';
|
||||
export { ServiceObject } from './service';
|
||||
export { CollectionObject } from './collection';
|
||||
export { EntityObject } from './entity';
|
||||
export { GroupObject } from './group';
|
||||
export { IndividualObject } from './individual';
|
||||
export { OrganizationObject } from './organization';
|
||||
export { ProviderObject } from './provider';
|
||||
export { ServiceObject } from './service';
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ export class ProviderObject implements ProviderInterface {
|
||||
constructor() {
|
||||
this._data = {
|
||||
'@type': 'people:provider',
|
||||
id: '',
|
||||
identifier: '',
|
||||
label: '',
|
||||
capabilities: {},
|
||||
};
|
||||
@@ -30,9 +30,10 @@ export class ProviderObject implements ProviderInterface {
|
||||
}
|
||||
|
||||
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 {
|
||||
if (this._data.capabilities) {
|
||||
return this._data.capabilities[capability];
|
||||
@@ -46,8 +47,8 @@ export class ProviderObject implements ProviderInterface {
|
||||
return this._data['@type'];
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
return this._data.id;
|
||||
get identifier(): string {
|
||||
return this._data.identifier;
|
||||
}
|
||||
|
||||
get label(): string {
|
||||
@@ -58,4 +59,4 @@ export class ProviderObject implements ProviderInterface {
|
||||
return this._data.capabilities;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+57
-10
@@ -4,8 +4,12 @@
|
||||
|
||||
import type {
|
||||
ServiceInterface,
|
||||
ServiceCapabilitiesInterface
|
||||
ServiceCapabilitiesInterface,
|
||||
ServiceIdentity,
|
||||
ServiceLocation
|
||||
} from "@/types/service";
|
||||
import { Identity } from './identity';
|
||||
import { Location } from './location';
|
||||
|
||||
export class ServiceObject implements ServiceInterface {
|
||||
|
||||
@@ -15,10 +19,10 @@ export class ServiceObject implements ServiceInterface {
|
||||
this._data = {
|
||||
'@type': 'people:service',
|
||||
provider: '',
|
||||
id: '',
|
||||
label: '',
|
||||
capabilities: {},
|
||||
identifier: null,
|
||||
label: null,
|
||||
enabled: false,
|
||||
capabilities: {}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -32,7 +36,8 @@ export class ServiceObject implements ServiceInterface {
|
||||
}
|
||||
|
||||
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 {
|
||||
@@ -52,8 +57,8 @@ export class ServiceObject implements ServiceInterface {
|
||||
return this._data.provider;
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
return this._data.id;
|
||||
get identifier(): string | number | null {
|
||||
return this._data.identifier;
|
||||
}
|
||||
|
||||
get capabilities(): ServiceCapabilitiesInterface | undefined {
|
||||
@@ -62,11 +67,11 @@ export class ServiceObject implements ServiceInterface {
|
||||
|
||||
/** Mutable Properties */
|
||||
|
||||
get label(): string {
|
||||
get label(): string | null {
|
||||
return this._data.label;
|
||||
}
|
||||
|
||||
set label(value: string) {
|
||||
set label(value: string | null) {
|
||||
this._data.label = value;
|
||||
}
|
||||
|
||||
@@ -78,4 +83,46 @@ export class ServiceObject implements ServiceInterface {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user