models/AuthResponse.js

import CurrentUser from "../CurrentUser";

export default class AuthResponse {
    /**
     * Creates a new AuthResponse instance from the provided parameters.
     *
     * @constructor AuthResponse
     * @param {Object} response - Auth response parameters
     * @param {CurrentUser} response.user - User Display name
     * @param {Object} [response.referral] - Referral data (if any)
     * @param {string} [response.referral.referrerUserId] - Referrer User ID
     * @param {string} [response.referral.token] - Token
     * @param {string} [response.referral.provider] - Provider
     * @param {boolean} [response.referral.firstMatch=false] - true if the web app is opened for the first time on this device.
     * @param {Object<string, string>} [response.referral.linkParams={}] - Referral link parameters
     * @param {boolean} [response.referral.guaranteedMatch=false] - true if the backend trust this result 100%. Fingerprint matches are always false
     * @param {Object<string, string>} [response.referral.originalData={}] - Original referral link parameters
     */
    constructor(response) {
        response = response || {};
        this.user = response.user;
        this.referral = {};
        if (response.referral) {
            this.referral.referrerUserId = response.referral.referrerUserId;
            this.referral.token = response.referral.token;
            this.referral.provider = response.referral.provider;
            this.referral.firstMatch = response.referral.firstMatch || false;
            this.referral.linkParams = response.referral.linkParams || {};
            this.referral.guaranteedMatch = response.referral
                .guaranteedMatch || false;
            this.referral.originalData = response.referral.originalData || {};
        }
    }
}