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AE,CAAC;SACvC;QACD,MAAM,KAAK,CAAC;KACb;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY;IAChC,MAAM,gBAAgB,CAAC,cAAc,CAAC,CAAC;AACzC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,MAAM,gBAAgB,CAAC,iBAAiB,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACvC,OAAO,MAAM,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;AACvD,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,OAAe,GAAG;IACpD,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE;QACnC,MAAM,IAAI,mBAAmB,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;KAChE;IAED,MAAM,8BAA8B,EAAE,CAAC;IACvC,OAAO,MAAM,gBAAgB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;AACpD,CAAC;AAED,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,cAAc,CAAC","sourcesContent":["import { UnavailabilityError } from '@unimodules/core';\nimport Constants from 'expo-constants';\nimport invariant from 'invariant';\n\nimport ExpoGoogleSignIn from './ExpoGoogleSignIn';\nimport { GoogleSignInOptions, GoogleSignInAuthResult } from './GoogleSignIn.types';\nimport GoogleUser from './GoogleUser';\n\nexport const { ERRORS, SCOPES, TYPES } = ExpoGoogleSignIn;\n\nconst DEFAULT_SCOPES = [SCOPES.PROFILE, SCOPES.EMAIL];\n\nlet _initialization: Promise<void>;\nlet _options: GoogleSignInOptions;\nlet _currentUser: GoogleUser | null = null;\nlet _isClientUsageEnabled = false;\n\nfunction setCurrentUser(currentUser: GoogleUser | null): GoogleUser | null {\n _currentUser = currentUser;\n return _currentUser;\n}\n\nfunction validateOptions(options?: GoogleSignInOptions): GoogleSignInOptions {\n if (!options) {\n return {\n scopes: DEFAULT_SCOPES,\n };\n }\n if (options.isOfflineEnabled) {\n invariant(\n typeof options.webClientId === 'string' && options.webClientId !== '',\n 'GoogleSignIn: Offline access (isOfflineEnabled: true) requires a valid google server id `webClientId`'\n );\n }\n\n return {\n ...options,\n scopes: options.scopes || DEFAULT_SCOPES,\n };\n}\n\nfunction validateOwnership() {\n invariant(\n _isClientUsageEnabled || Constants.appOwnership !== 'expo',\n 'expo-google-sign-in is not supported in the Expo Client because a custom URL scheme is required at build time. Please refer to the docs for usage outside of Expo www.npmjs.com/package/expo-google-sign-in'\n );\n}\n\nasync function ensureGoogleIsInitializedAsync(options?: GoogleSignInOptions): Promise<any> {\n if (_initialization == null) {\n return initAsync(options);\n }\n return _initialization;\n}\n\nasync function invokeAuthMethod(method: string): Promise<GoogleUser | null> {\n if (!ExpoGoogleSignIn[method]) {\n throw new UnavailabilityError('GoogleSignIn', method);\n }\n await ensureGoogleIsInitializedAsync();\n const payload = await ExpoGoogleSignIn[method]();\n const account = payload != null ? new GoogleUser(payload) : null;\n return setCurrentUser(account);\n}\n\nexport function allowInClient() {\n _isClientUsageEnabled = true;\n}\n\nexport function getCurrentUser(): GoogleUser | null {\n return _currentUser;\n}\n\nexport async function askForPlayServicesAsync(): Promise<boolean> {\n return await getPlayServiceAvailability(true);\n}\n\nexport async function getPlayServiceAvailability(shouldAsk: boolean = false): Promise<boolean> {\n validateOwnership();\n\n if (ExpoGoogleSignIn.arePlayServicesAvailableAsync) {\n return await ExpoGoogleSignIn.arePlayServicesAvailableAsync(shouldAsk);\n } else {\n return true;\n }\n}\n\nexport async function initAsync(options?: GoogleSignInOptions): Promise<void> {\n if (!ExpoGoogleSignIn.initAsync) {\n throw new UnavailabilityError('GoogleSignIn', 'initAsync');\n }\n\n _options = validateOptions(options || _options || {});\n\n const hasPlayServices = await getPlayServiceAvailability();\n if (!hasPlayServices) {\n return;\n }\n\n _initialization = ExpoGoogleSignIn.initAsync(_options || {});\n\n return _initialization;\n}\n\nexport async function isSignedInAsync(): Promise<boolean> {\n const user = await getCurrentUserAsync();\n return user != null;\n}\n\nexport async function isConnectedAsync(): Promise<boolean> {\n return await ExpoGoogleSignIn.isConnectedAsync();\n}\n\nexport async function signInSilentlyAsync(): Promise<GoogleUser | null> {\n const isConnected = await isConnectedAsync();\n if (isConnected) {\n try {\n const auth = await invokeAuthMethod('signInSilentlyAsync');\n return auth;\n } catch (error) {\n /* Return null to create parity with Android */\n if (error.code === ERRORS.SIGN_IN_REQUIRED) {\n return null;\n }\n throw error;\n }\n }\n return null;\n}\n\nexport async function signInAsync(): Promise<GoogleSignInAuthResult> {\n try {\n const user = await invokeAuthMethod('signInAsync');\n return { type: 'success', user };\n } catch (error) {\n if (error.code === ERRORS.SIGN_IN_CANCELLED) {\n return { type: 'cancel', user: null };\n }\n throw error;\n }\n}\n\nexport async function signOutAsync(): Promise<void> {\n await invokeAuthMethod('signOutAsync');\n}\n\nexport async function disconnectAsync(): Promise<void> {\n await invokeAuthMethod('disconnectAsync');\n}\n\nexport async function getCurrentUserAsync(): Promise<GoogleUser | null> {\n return await invokeAuthMethod('getCurrentUserAsync');\n}\n\nexport async function getPhotoAsync(size: number = 128): Promise<string | null> {\n if (!ExpoGoogleSignIn.getPhotoAsync) {\n throw new UnavailabilityError('GoogleSignIn', 'getPhotoAsync');\n }\n\n await ensureGoogleIsInitializedAsync();\n return await ExpoGoogleSignIn.getPhotoAsync(size);\n}\n\nexport { default as GoogleAuthData } from './GoogleAuthData';\nexport { default as GoogleAuthentication } from './GoogleAuthentication';\nexport { default as GoogleIdentity } from './GoogleIdentity';\nexport { default as GoogleUser } from './GoogleUser';\n\nexport {\n GoogleSignInType,\n GoogleSignInOptions,\n GoogleSignInAuthResultType,\n GoogleSignInAuthResult,\n} from './GoogleSignIn.types';\n"]}
\No newline at end of file