import { SchemaModel } from '@verb/src/libs/shared/base/base.model'; import { SubSchema } from '@verb/src/libs/shared/json-schema-validator/schema-types'; // TODO: should be replaced with AuthenticatedUser model export class OwnerModel implements SchemaModel { public clientId = ''; public userId = ''; public constructor(ownerSchema?: OwnerSchema) { if (ownerSchema) { this.fromSchema(ownerSchema); } } public get sub() { return `${this.clientId}|${this.userId}`; } public set sub(_value: string) { const tokens = _value.split('|'); if (tokens.length !== 2) { throw new Error('Invalid owner subject'); } this.clientId = tokens[0]; this.userId = tokens[1]; } public fromSchema(ownerSchema: OwnerSchema) { this.clientId = ownerSchema.client_id; this.userId = ownerSchema.user_id; } public toSchema(): OwnerSchema { return { client_id: this.clientId, user_id: this.userId, }; } } export interface OwnerSchema { client_id: string; user_id: string; } export const ownerValidationSchema: SubSchema = { additionalProperties: false, description: 'Owner Schema Validation', properties: { client_id: { description: 'Client ID for the user', minLength: 1, type: 'string', }, user_id: { description: 'User ID for the user', minLength: 1, type: 'string', }, }, required: ['client_id', 'user_id'], type: 'object', };