import * as uuid from 'uuid' /** A subject represents the person that's giving consent. * * A Subject might have two different ids. When he/she is not identified in the system, this SDK will generate * a random UUID to identify the current browser. Once the Subject is logged into the system, it can be * _converted_ to a verified Subject. A verified Subject has a custom id provided by the system. */ export class Subject { /** Builds a verified Subject. * @param id Custom id provided by the system. * @return the new Subject that uses the verified id. */ static verified(id: string): Subject { return new Subject(id, undefined) } /** Builds an anonymous Subject and assigns a random UUID. * @return the new anonymous Subject. */ static anonymous(id?: string): Subject { return new Subject(undefined, id || uuid.v4()) } private constructor( /** Verified user identifier. */ readonly verifiedId?: string, /** Random UUID generated by the SDK. */ readonly anonymousId?: string ) {} get id(): string | undefined { return this.verifiedId || this.anonymousId } }