/**
 * Copyright 2018 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ import * as Api from '../api/v2' ; import { OAuth2Client } from 'google-auth-library' ; import { LoginTicket , TokenPayload , } from 'google-auth-library/build/src/auth/loginticket' ; import * as common from '../../../common' ; export class Last { public seen ? : Date ; hidden constructor ( user ) { if ( user . lastSeen ) { this . seen = new Date ( user . lastSeen ) ; } } } export class Name { public display ? : string ; public family ? : string ; public given ? : string ; hidden constructor ( profile ) { this . display = profile . displayName ; this . family = profile . familyName ; this . given = profile . givenName ; } } export class Access { public token ? : string ; hidden constructor ( user ) { this . token = user . accessToken ; } } export class Profile { /**
     * Gets the Profile Payload object encoded in  Profile .
     * Only retrievable with "Google Sign In" linking type set up for account linking in the console.
     *
     * To access just the email in the payload, you can also use  User .
     *
     *  example public payload ? : TokenPayload ; public token ? : string ; hidden constructor ( user ) { this . token = user . idToken ; } hidden async _verify ( client , id ) { const login = ( await client . verifyIdToken ( { idToken : this . token ! , audience : id , } ) ) as LoginTicket ; this . payload = login . getPayload ( ) ; return this . payload ; } } export class User < TUserStorage > { example public storage : TUserStorage ; public locale : string ; public last : Last ; public permissions : Api . GoogleActionsV2UserPermissions [ ] ; /**
     * User's permissioned name info.
     * Properties will be undefined if not request with  Permission public name : Name ; /**
     * The list of all digital goods that your user purchased from
     * your published Android apps. To enable this feature, see the instructions
     * in the  https .
     *  public entitlements : Api . GoogleActionsV2PackageEntitlement [ ] ; public access : Access ; public profile : Profile ; hidden _id : string ; /**
     * Gets the user profile email.
     * Only retrievable with "Google Sign In" linking type set up for account linking in the console.
     *
     * See  Profile for all the payload properties.
     *
     *  example public email ? : string ; public verification ? : Api . GoogleActionsV2UserUserVerificationStatus ; hidden constructor ( public raw = { } , initial ? ) { const { userStorage } = this . raw ; this . storage = userStorage ? JSON . parse ( userStorage ) . data : initial || { } ; this . locale = this . raw . locale ! ; this . verification = this . raw . userVerificationStatus ; this . permissions = this . raw . permissions || [ ] ; this . last = new Last ( this . raw ) ; const profile = this . raw . profile || { } ; this . name = new Name ( profile ) ; this . entitlements = this . raw . packageEntitlements || [ ] ; this . access = new Access ( this . raw ) ; this . profile = new Profile ( this . raw ) ; } hidden _serialize ( ) { return JSON . stringify ( { data : this . storage } ) ; } hidden async _verifyProfile ( client , id ) { const payload = await this . profile . _verify ( client , id ) ; this . email = payload ! . email ; return payload ; } }