Saxonberg Server API
    Preparing search index...

    Twitch OAuth profile data (persistent, token-bearing). A Document — plain persisted state, NOT a Stuff.

    Hierarchy (View Summary)

    Implements

    • TwitchProfile
    Index

    Constructors

    Properties

    _id?: string

    MongoDB ObjectId (undefined until saved).

    accessToken: string = ''

    OAuth access token. Plaintext in memory; encrypted at rest.

    createdAt: Date

    Created timestamp (set on construction).

    displayName: string = ''

    Display name from Twitch.

    email?: string

    Email address (present when the user:read:email scope was granted).

    expiresAt: number = 0

    Access-token expiry as epoch ms.

    login: string = ''

    Twitch login (lowercased handle).

    rawProfile: Record<string, unknown> = {}

    Raw Helix identity payload (for future use).

    refreshToken: string = ''

    OAuth refresh token. Plaintext in memory; encrypted at rest.

    scopes: string[] = []

    Granted OAuth scopes.

    twitchUserId: string = ''

    Twitch user id (unique, stable identifier from Helix).

    updatedAt: Date

    Last updated timestamp (set on every save).

    collectionName: string = 'twitch_profiles'

    MongoDB collection name.

    fieldMarshallers: {
        accessToken: "/lib/persistence/EncryptedStringMarshaller";
        refreshToken: "/lib/persistence/EncryptedStringMarshaller";
    } = ...

    Encrypt the two bearer-token fields at rest. The marshaller's toStored / fromStored run inside Document.toDocument / fromDocument, so plaintext never reaches Mongo.

    persistentFields: string[] = ...

    Persistent fields for auto-sync.

    Methods

    • Write back a refreshed token set and persist. This is the RefreshingAuthProvider.onRefresh target: the relay calls it with the rotated credentials, and save()toDocument() re-encrypts the two token fields automatically, so the rotated token never hits Mongo in plaintext.

      Parameters

      • tokens: {
            accessToken: string;
            expiresAt: number;
            refreshToken: string;
            scopes: string[];
        }

      Returns Promise<void>

    • Load data from a MongoDB document into this object.

      Symmetric to toDocument: marshallers transform their assigned fields' raw values via fromStored before bracket-assign hits the runtime setter.

      Parameters

      • doc: Record<string, unknown>

      Returns void

    • Whether this profile currently holds a given OAuth scope. The relay's outbound path reads hasScope('user:write:chat') to decide between a send and a reject-and-point into the re-consent flow.

      Parameters

      • scope: string

      Returns boolean

    • Save this object to MongoDB. Updates updatedAt automatically.

      Pre-resolves any registered field marshallers via the async resolver before the sync toDocument walk; the sync resolver lookup inside toDocument then always hits a populated cache.

      Returns Promise<void>

    • Convert this object to a plain document for MongoDB.

      Marshallers (declared via static fieldMarshallers on a mixin or class) intercept their assigned fields: the runtime value-object value is passed through marshaller.toStored before being written into the doc. Fields without a marshaller pass through bracket-read unchanged.

      Returns Record<string, unknown>

    • Wire the marshaller-resolution seam once at boot (and in tests). Keeps Document free of a StuffApi import while still reaching the Idea-rooted marshaller instances. sync mirrors StuffApi.findByTemplatePath (returns the registered instance or undefined); async mirrors StuffApi.singleton (resolves / lazy-clones the instance, warming the cache sync then hits).

      Parameters

      • sync: SyncMarshallerResolver
      • async: AsyncMarshallerResolver

      Returns void