diff --git a/package.json b/package.json index 901bb3e..dbc9241 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,18 @@ "dependencies": { "superagent": "1.7.2" }, + "peerDependencies": { + "@ionic-native/core": "^3.6.1", + "@ionic-native/device": "^3.6.1", + "@ionic-native/facebook": "^3.6.1", + "@ionic-native/google-plus": "^3.6.1", + "@ionic/db": "^0.1.0" + }, "devDependencies": { + "@ionic-native/core": "^3.6.1", + "@ionic-native/device": "^3.6.1", + "@ionic-native/facebook": "^3.6.1", + "@ionic-native/google-plus": "^3.6.1", "babel-plugin-external-helpers": "^6.8.0", "babel-preset-es2015": "^6.14.0", "browserify": "^13.1.0", diff --git a/src/angular.ts b/src/angular.ts index b222a29..680c325 100644 --- a/src/angular.ts +++ b/src/angular.ts @@ -1,3 +1,7 @@ +import { Device as NativeDevice } from '@ionic-native/device'; +import { Facebook } from '@ionic-native/facebook'; +import { GooglePlus } from '@ionic-native/google-plus'; + import { Container as DIContainer } from './di'; import { EventEmitter } from './events'; import { DeferredPromise } from './promise'; @@ -12,7 +16,7 @@ export function bootstrapAngular1() { return; // No global angular--this is not an AngularJS project. } - let container = new DIContainer(); + let container = new DIContainer(new NativeDevice(), new Facebook(), new GooglePlus()); angular.element(document).ready(function() { container.core.init(); diff --git a/src/auth.ts b/src/auth.ts index d7fb39b..1a39bf1 100644 --- a/src/auth.ts +++ b/src/auth.ts @@ -1,3 +1,6 @@ +import { Facebook, FacebookLoginResponse } from '@ionic-native/facebook'; +import { GooglePlus } from '@ionic-native/google-plus'; + import { APIResponseErrorDetails, AuthDependencies, @@ -629,6 +632,13 @@ export abstract class NativeAuth { * @featured */ export class GoogleAuth extends NativeAuth implements IGoogleAuth { + private googlePlus: GooglePlus; + + constructor(deps: NativeAuthDependencies) { + super(deps); + + this.googlePlus = deps.googlePlus; + } public logout(): Promise { let deferred = new DeferredPromise(); @@ -639,7 +649,7 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth { user.unstore(); user.clear(); - window.plugins.googleplus.logout(() => { + this.googlePlus.logout().then( () => { deferred.resolve(); }, (err) => { deferred.reject(err); @@ -655,6 +665,11 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth { this.emitter.once('cordova:deviceready', () => { let scope = ['profile', 'email']; + if (!this.googlePlus) { + deferred.reject(new Error('Ionic native is not installed')); + return; + } + if (!window || !window.cordova) { deferred.reject(new Error('Cordova is missing')); return; @@ -678,7 +693,7 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth { }); } - window.plugins.googleplus.login({'webClientId': authConfig.google.webClientId, 'offline': true, 'scopes': scope.join(' ')}, (success) => { + this.googlePlus.login({'webClientId': authConfig.google.webClientId, 'offline': true, 'scopes': scope.join(' ')}).then((success) => { if (!success.serverAuthCode) { deferred.reject(new Error('Failed to retrieve offline access token.')); return; @@ -720,6 +735,13 @@ export class GoogleAuth extends NativeAuth implements IGoogleAuth { * @featured */ export class FacebookAuth extends NativeAuth implements IFacebookAuth { + private facebook: Facebook; + + constructor(deps: NativeAuthDependencies) { + super(deps); + + this.facebook = deps.facebook; + } public logout(): Promise { let deferred = new DeferredPromise(); @@ -731,8 +753,7 @@ export class FacebookAuth extends NativeAuth implements IFacebookAuth { user.clear(); // Clear the facebook auth. - - window.facebookConnectPlugin.logout(() => { + this.facebook.logout().then( () => { deferred.resolve(); }, (err) => { deferred.reject(err); @@ -755,6 +776,11 @@ export class FacebookAuth extends NativeAuth implements IFacebookAuth { } this.emitter.once('cordova:deviceready', () => { + if (!this.facebook) { + deferred.reject(new Error('Ionic native is not installed')); + return; + } + if (!window || !window.cordova) { deferred.reject(new Error('Cordova is missing.')); return; @@ -765,7 +791,7 @@ export class FacebookAuth extends NativeAuth implements IFacebookAuth { return; } - window.facebookConnectPlugin.login(scope, (r: any) => { + this.facebook.login(scope).then((r: FacebookLoginResponse) => { scope.splice(scope.indexOf('public_profile'), 1); const request_object = { 'app_id': this.config.get('app_id'), diff --git a/src/definitions.ts b/src/definitions.ts index 0216033..6b8a2fb 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -1,3 +1,8 @@ +import { Facebook } from '@ionic-native/facebook'; +import { GooglePlus } from '@ionic-native/google-plus'; +import { Device as NativeDevice } from '@ionic-native/device'; +import { IonicDBOptions } from '@ionic/db'; + /** * @hidden */ @@ -275,7 +280,7 @@ export interface DeviceIsConnectedToNetworkOptions { * @hidden */ export interface DeviceDependencies { - nativeDevice: any; + nativeDevice: NativeDevice; emitter: IEventEmitter; } @@ -283,7 +288,7 @@ export interface DeviceDependencies { * @hidden */ export interface IDevice { - native: any; + native: NativeDevice; type: string; isAndroid(): boolean; @@ -828,6 +833,8 @@ export interface NativeAuthDependencies { storage: IStorage; tokenContext: ICombinedTokenContext; emitter: IEventEmitter; + facebook: Facebook; + googlePlus: GooglePlus; } /** diff --git a/src/device.ts b/src/device.ts index 6fee72d..4187ea4 100644 --- a/src/device.ts +++ b/src/device.ts @@ -1,3 +1,5 @@ +import { Device as NativeDevice } from '@ionic-native/device'; + import { DeviceDependencies, DeviceIsConnectedToNetworkOptions, @@ -12,9 +14,7 @@ declare var navigator: any; * @hidden */ export class Device implements IDevice { - - public native: any; - + public native: NativeDevice; public type: string; /** diff --git a/src/di.ts b/src/di.ts index af5a849..bf99da0 100644 --- a/src/di.ts +++ b/src/di.ts @@ -1,3 +1,8 @@ +import { Device as NativeDevice } from '@ionic-native/device'; +import { Facebook } from '@ionic-native/facebook'; +import { GooglePlus } from '@ionic-native/google-plus'; +import { IonicDBOptions } from '@ionic/db'; + import { AppStatus, IAuth, @@ -78,6 +83,7 @@ function cache(target: any, propertyKey: string, descriptor: TypedPropertyDes * @hidden */ export class Container { + constructor(private nativeDevice: NativeDevice, private facebook: Facebook, private googlePlus: GooglePlus) { } @cache public get appStatus(): AppStatus { @@ -161,8 +167,7 @@ export class Container { @cache public get device(): IDevice { - const cordovaDevice = (window as any).device; - return new Device({'nativeDevice': cordovaDevice, 'emitter': this.eventEmitter}); + return new Device({'nativeDevice': this.nativeDevice, 'emitter': this.eventEmitter}); } @cache @@ -225,7 +230,9 @@ export class Container { 'userService': this.singleUserService, 'storage': new Storage({'strategy': this.localStorageStrategy}), 'tokenContext': this.authTokenContext, - 'emitter': this.eventEmitter + 'emitter': this.eventEmitter, + 'facebook': this.facebook, + 'googlePlus': this.googlePlus }); } @@ -237,7 +244,9 @@ export class Container { 'userService': this.singleUserService, 'storage': new Storage({'strategy': this.localStorageStrategy}), 'tokenContext': this.authTokenContext, - 'emitter': this.eventEmitter + 'emitter': this.eventEmitter, + 'facebook': this.facebook, + 'googlePlus': this.googlePlus }); } diff --git a/src/insights.ts b/src/insights.ts index b1840e8..7261028 100644 --- a/src/insights.ts +++ b/src/insights.ts @@ -224,7 +224,7 @@ export class Insights implements IInsights { * @private */ protected shouldSubmit(): boolean { - return this.batch.length >= this.options.submitCount; + return this.batch.length >= (this.options.submitCount || 0); } /**