Skip to content

Commit

Permalink
feat: add back flow types (#1289)
Browse files Browse the repository at this point in the history
  • Loading branch information
vonovak committed May 24, 2024
1 parent 1a66656 commit a28c55c
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions index.js.flow
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// @flow
import * as React from 'react';
import { typeof View } from 'react-native';

export type ConfigureParams = $ReadOnly<{|
iosClientId?: string,
googleServicePlistPath?: string,
offlineAccess?: boolean,
webClientId?: string,
scopes?: string[],
hostedDomain?: string,
forceCodeForRefreshToken?: boolean,
accountName?: string,
openIdRealm?: string,
profileImageSize?: number,
|}>;

export type SignInParams = $ReadOnly<{|
loginHint?: string,
|}>;

export type AddScopesParams = $ReadOnly<{|
/**
* The Google API scopes to request access to. Default is email and profile.
*/
scopes?: string[],
|}>;

export type GoogleSigninButtonProps = $ReadOnly<{|
...React.ElementConfig<View>,
size?: number,
color?: string,
disabled?: boolean,
onPress?: () => any,
|}>;

declare export class GoogleSigninButton extends React.Component<GoogleSigninButtonProps> {
static Size: {
Icon: number,
Standard: number,
Wide: number,
};

static Color: {
Auto: string,
Light: string,
Dark: string,
};
}

export type HasPlayServicesParams = $ReadOnly<{|
showPlayServicesUpdateDialog: boolean,
|}>;

export type User = {|
user: {|
id: string,
name: ?string, // full name
email: string,
photo: ?string, // url
familyName: ?string,
givenName: ?string,
|},
scopes: string[], // on iOS this is empty array if no additional scopes are defined
idToken: string,
/**
* Not null only if a valid webClientId and offlineAccess: true was
* specified in configure().
*/
serverAuthCode: ?string,
|};

// Android Status codes: https://developers.google.com/android/reference/com/google/android/gms/auth/api/signin/GoogleSignInStatusCodes
type StatusCodes = $ReadOnly<{
SIGN_IN_CANCELLED: string,
IN_PROGRESS: string,
PLAY_SERVICES_NOT_AVAILABLE: string,
SIGN_IN_REQUIRED: string,
}>;

declare export var statusCodes: StatusCodes;

// the functions are not static in fact, but the module exports a
// singleton instance of the class; not the class itself
// using static keyword works well for this case
declare export class GoogleSignin {
static hasPlayServices: (params?: HasPlayServicesParams) => Promise<boolean>;
static configure: (params?: ConfigureParams) => void;
static signInSilently: () => Promise<User>;
static signIn: (params?: SignInParams) => Promise<User>;
static addScopes: (params: AddScopesParams) => Promise<User | null>;
static signOut: () => Promise<null>;
static revokeAccess: () => Promise<null>;
static hasPreviousSignIn: () => boolean;
static getCurrentUser(): User | null;
static clearCachedAccessToken(token: string): Promise<null>;
static getTokens(): Promise<{ idToken: string, accessToken: string }>;
}

0 comments on commit a28c55c

Please sign in to comment.