Native plugin wrappers for Cordova and Ionic with TypeScript, ES6+, Promise and Observable support
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Social media integration, content sharing, and authentication for Facebook, Google+, Twitter platforms, and general content sharing capabilities.
Share content across multiple platforms and applications with customizable options and platform-specific features.
/**
* SocialSharing class for sharing content across platforms
*/
class SocialSharing {
/**
* Share content using device's native sharing dialog
* @param message Message to share (optional)
* @param subject Subject line (optional)
* @param file File path or array of file paths (optional)
* @param url URL to share (optional)
* @returns Promise indicating share completion
*/
static share(message?: string, subject?: string, file?: string | string[], url?: string): Promise<any>;
/**
* Share content via Twitter
* @param message Tweet text
* @param image Image URL or file path (optional)
* @param url URL to share (optional)
* @returns Promise indicating share completion
*/
static shareViaTwitter(message: string, image?: string, url?: string): Promise<any>;
/**
* Share content via Facebook
* @param message Message text
* @param image Image URL or file path (optional)
* @param url URL to share (optional)
* @returns Promise indicating share completion
*/
static shareViaFacebook(message: string, image?: string, url?: string): Promise<any>;
/**
* Share content via Facebook with paste message hint
* @param message Message text
* @param image Image URL or file path (optional)
* @param url URL to share (optional)
* @param pasteMessageHint Hint text for paste message
* @returns Promise indicating share completion
*/
static shareViaFacebookWithPasteMessageHint(message: string, image?: string, url?: string, pasteMessageHint: string): Promise<any>;
/**
* Share content via email
* @param message Email body
* @param subject Email subject
* @param to Array of recipient email addresses
* @param cc Array of CC email addresses (optional)
* @param bcc Array of BCC email addresses (optional)
* @param files Array of file attachments (optional)
* @returns Promise indicating share completion
*/
static shareViaEmail(message: string, subject: string, to: string[], cc?: string[], bcc?: string[], files?: string | string[]): Promise<any>;
/**
* Share content via SMS
* @param message SMS message text
* @param phonenumbers Comma-separated phone numbers
* @returns Promise indicating share completion
*/
static shareViaSMS(message: string, phonenumbers: string): Promise<any>;
/**
* Share content via WhatsApp
* @param message Message text
* @param image Image URL or file path (optional)
* @param url URL to share (optional)
* @returns Promise indicating share completion
*/
static shareViaWhatsApp(message: string, image?: string, url?: string): Promise<any>;
/**
* Share content via Instagram
* @param message Caption text
* @param image Image file path (required)
* @returns Promise indicating share completion
*/
static shareViaInstagram(message: string, image: string): Promise<any>;
/**
* Check if sharing via specific app is available
* @param appName App identifier
* @param message Message to test (optional)
* @param subject Subject to test (optional)
* @param image Image to test (optional)
* @param url URL to test (optional)
* @returns Promise resolving to availability status
*/
static canShareVia(appName: string, message?: string, subject?: string, image?: string, url?: string): Promise<any>;
/**
* Check if email sharing is available
* @returns Promise resolving to email availability
*/
static canShareViaEmail(): Promise<any>;
}Usage Examples:
import { SocialSharing } from 'ionic-native';
// General sharing functionality
class ShareService {
// Share text content
async shareText(text: string, subject?: string) {
try {
await SocialSharing.share(text, subject);
console.log('Content shared successfully');
} catch (error) {
console.error('Share failed:', error);
throw error;
}
}
// Share image with text
async shareImage(imagePath: string, message?: string) {
try {
await SocialSharing.share(message, null, imagePath);
console.log('Image shared successfully');
} catch (error) {
console.error('Image share failed:', error);
throw error;
}
}
// Share URL
async shareUrl(url: string, message?: string, subject?: string) {
try {
await SocialSharing.share(message, subject, null, url);
console.log('URL shared successfully');
} catch (error) {
console.error('URL share failed:', error);
throw error;
}
}
// Share multiple files
async shareFiles(files: string[], message?: string) {
try {
await SocialSharing.share(message, null, files);
console.log('Files shared successfully');
} catch (error) {
console.error('File share failed:', error);
throw error;
}
}
}
// Platform-specific sharing
class PlatformSharing {
// Share on Twitter
async shareOnTwitter(message: string, imageUrl?: string, linkUrl?: string) {
try {
// Check if Twitter is available
const canShare = await SocialSharing.canShareVia('twitter', message);
if (canShare) {
await SocialSharing.shareViaTwitter(message, imageUrl, linkUrl);
console.log('Shared on Twitter');
} else {
throw new Error('Twitter app not available');
}
} catch (error) {
console.error('Twitter share failed:', error);
// Fallback to web share
this.shareViaWebTwitter(message, linkUrl);
}
}
// Share on Facebook
async shareOnFacebook(message: string, imageUrl?: string, linkUrl?: string) {
try {
const canShare = await SocialSharing.canShareVia('facebook', message);
if (canShare) {
await SocialSharing.shareViaFacebook(message, imageUrl, linkUrl);
console.log('Shared on Facebook');
} else {
throw new Error('Facebook app not available');
}
} catch (error) {
console.error('Facebook share failed:', error);
// Fallback to web share
this.shareViaWebFacebook(message, linkUrl);
}
}
// Share via WhatsApp
async shareOnWhatsApp(message: string, imageUrl?: string, linkUrl?: string) {
try {
const canShare = await SocialSharing.canShareVia('whatsapp', message);
if (canShare) {
await SocialSharing.shareViaWhatsApp(message, imageUrl, linkUrl);
console.log('Shared on WhatsApp');
} else {
throw new Error('WhatsApp not available');
}
} catch (error) {
console.error('WhatsApp share failed:', error);
throw error;
}
}
// Share on Instagram (image required)
async shareOnInstagram(caption: string, imagePath: string) {
try {
const canShare = await SocialSharing.canShareVia('instagram');
if (canShare) {
await SocialSharing.shareViaInstagram(caption, imagePath);
console.log('Shared on Instagram');
} else {
throw new Error('Instagram not available');
}
} catch (error) {
console.error('Instagram share failed:', error);
throw error;
}
}
// Email sharing
async shareViaEmail(options: {
subject: string;
message: string;
to: string[];
cc?: string[];
bcc?: string[];
attachments?: string[];
}) {
try {
const canEmail = await SocialSharing.canShareViaEmail();
if (canEmail) {
await SocialSharing.shareViaEmail(
options.message,
options.subject,
options.to,
options.cc,
options.bcc,
options.attachments
);
console.log('Email sent successfully');
} else {
throw new Error('Email not available');
}
} catch (error) {
console.error('Email share failed:', error);
throw error;
}
}
// SMS sharing
async shareViaSMS(message: string, phoneNumbers: string[]) {
try {
const phones = phoneNumbers.join(',');
await SocialSharing.shareViaSMS(message, phones);
console.log('SMS shared successfully');
} catch (error) {
console.error('SMS share failed:', error);
throw error;
}
}
// Web fallback methods
private shareViaWebTwitter(text: string, url?: string) {
const twitterUrl = `https://twitter.com/intent/tweet?text=${encodeURIComponent(text)}${url ? '&url=' + encodeURIComponent(url) : ''}`;
window.open(twitterUrl, '_blank');
}
private shareViaWebFacebook(text: string, url?: string) {
const facebookUrl = `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(url || window.location.href)}"e=${encodeURIComponent(text)}`;
window.open(facebookUrl, '_blank');
}
}
// Content sharing with analytics
class AnalyticsShareService extends PlatformSharing {
async shareWithAnalytics(content: {
type: 'text' | 'image' | 'url' | 'file';
data: any;
platform?: string;
title?: string;
}) {
const shareEvent = {
contentType: content.type,
platform: content.platform || 'native',
timestamp: new Date().toISOString(),
title: content.title
};
try {
// Track share attempt
this.trackEvent('share_attempted', shareEvent);
// Perform share based on type
switch (content.type) {
case 'text':
await this.shareText(content.data, content.title);
break;
case 'image':
await this.shareImage(content.data, content.title);
break;
case 'url':
await this.shareUrl(content.data, content.title);
break;
case 'file':
await this.shareFiles(Array.isArray(content.data) ? content.data : [content.data]);
break;
}
// Track successful share
this.trackEvent('share_completed', shareEvent);
} catch (error) {
// Track failed share
this.trackEvent('share_failed', { ...shareEvent, error: error.message });
throw error;
}
}
private trackEvent(eventName: string, data: any) {
// Implement analytics tracking
console.log(`Analytics: ${eventName}`, data);
}
}Comprehensive Facebook SDK integration for authentication, API access, and social features.
/**
* Facebook login response
*/
interface FacebookLoginResponse {
/** Login status (connected, not_authorized, unknown) */
status: string;
/** Authentication response data */
authResponse: {
/** User ID */
userID: string;
/** Access token */
accessToken: string;
/** Session data */
session_key?: boolean;
/** Expiration timestamp */
expiresIn?: string;
/** Signed request */
sig?: string;
};
}
/**
* Facebook class for social authentication and API access
*/
class Facebook {
/**
* Login to Facebook
* @param permissions Array of permission strings
* @returns Promise resolving to FacebookLoginResponse
*/
static login(permissions: string[]): Promise<FacebookLoginResponse>;
/**
* Logout from Facebook
* @returns Promise indicating logout completion
*/
static logout(): Promise<any>;
/**
* Get current login status
* @returns Promise resolving to FacebookLoginResponse
*/
static getLoginStatus(): Promise<FacebookLoginResponse>;
/**
* Get current access token
* @returns Promise resolving to access token string
*/
static getAccessToken(): Promise<string>;
/**
* Show Facebook dialog
* @param options Dialog configuration options
* @returns Promise resolving to dialog result
*/
static showDialog(options: any): Promise<any>;
/**
* Make Facebook API request
* @param requestPath API endpoint path
* @param permissions Required permissions (optional)
* @returns Promise resolving to API response
*/
static api(requestPath: string, permissions?: string[]): Promise<any>;
/**
* Log Facebook Analytics event
* @param name Event name
* @param params Event parameters (optional)
* @param valueToSum Numeric value to sum (optional)
* @returns Promise indicating logging completion
*/
static logEvent(name: string, params?: Object, valueToSum?: number): Promise<any>;
/**
* Log purchase event
* @param value Purchase value
* @param currency Currency code
* @returns Promise indicating logging completion
*/
static logPurchase(value: number, currency: string): Promise<any>;
/**
* Send app invite
* @param options Invite configuration options
* @returns Promise resolving to invite result
*/
static appInvite(options: any): Promise<any>;
}Usage Examples:
import { Facebook, FacebookLoginResponse } from 'ionic-native';
// Facebook authentication service
class FacebookAuthService {
private currentUser: any = null;
private accessToken: string = '';
async login(requestedPermissions: string[] = ['public_profile', 'email']) {
try {
const response = await Facebook.login(requestedPermissions);
if (response.status === 'connected') {
this.accessToken = response.authResponse.accessToken;
this.currentUser = await this.getUserProfile();
console.log('Facebook login successful:', this.currentUser);
return {
success: true,
user: this.currentUser,
token: this.accessToken
};
} else {
throw new Error('Facebook login failed');
}
} catch (error) {
console.error('Facebook login error:', error);
throw error;
}
}
async logout() {
try {
await Facebook.logout();
this.currentUser = null;
this.accessToken = '';
console.log('Facebook logout successful');
} catch (error) {
console.error('Facebook logout error:', error);
throw error;
}
}
async getLoginStatus() {
try {
const response = await Facebook.getLoginStatus();
return response.status === 'connected';
} catch (error) {
console.error('Facebook status check error:', error);
return false;
}
}
async getUserProfile() {
try {
const profile = await Facebook.api('/me?fields=id,name,email,picture');
return profile;
} catch (error) {
console.error('Facebook profile error:', error);
throw error;
}
}
async getFriends() {
try {
const friends = await Facebook.api('/me/friends');
return friends.data;
} catch (error) {
console.error('Facebook friends error:', error);
throw error;
}
}
async postToFeed(message: string, link?: string, picture?: string) {
try {
const postData: any = { message };
if (link) postData.link = link;
if (picture) postData.picture = picture;
const result = await Facebook.api('/me/feed', ['publish_actions']);
return result;
} catch (error) {
console.error('Facebook post error:', error);
throw error;
}
}
getCurrentUser() {
return this.currentUser;
}
getAccessToken() {
return this.accessToken;
}
}
// Facebook sharing and engagement
class FacebookEngagement {
async shareLink(options: {
href: string;
description?: string;
hashtag?: string;
}) {
try {
const dialogOptions = {
method: 'share',
href: options.href,
description: options.description,
hashtag: options.hashtag
};
const result = await Facebook.showDialog(dialogOptions);
console.log('Facebook link shared:', result);
return result;
} catch (error) {
console.error('Facebook share error:', error);
throw error;
}
}
async inviteFriends(appId: string, message?: string) {
try {
const inviteOptions = {
url: `https://fb.me/${appId}`,
picture: 'https://your-app.com/invite-image.png',
message: message || 'Check out this awesome app!'
};
const result = await Facebook.appInvite(inviteOptions);
console.log('Facebook invites sent:', result);
return result;
} catch (error) {
console.error('Facebook invite error:', error);
throw error;
}
}
// Analytics integration
async trackEvent(eventName: string, parameters?: any, value?: number) {
try {
await Facebook.logEvent(eventName, parameters, value);
console.log('Facebook event tracked:', eventName);
} catch (error) {
console.error('Facebook analytics error:', error);
}
}
async trackPurchase(amount: number, currency: string = 'USD') {
try {
await Facebook.logPurchase(amount, currency);
console.log('Facebook purchase tracked:', amount, currency);
} catch (error) {
console.error('Facebook purchase tracking error:', error);
}
}
}Google+ authentication and social features integration.
/**
* GooglePlus class for Google+ authentication
*/
class GooglePlus {
/**
* Login to Google+
* @param options Login configuration options
* @returns Promise resolving to user profile data
*/
static login(options: any): Promise<any>;
/**
* Try silent login (using existing credentials)
* @param options Login configuration options
* @returns Promise resolving to user profile data
*/
static trySilentLogin(options: any): Promise<any>;
/**
* Logout from Google+
* @returns Promise indicating logout completion
*/
static logout(): Promise<any>;
/**
* Disconnect from Google+
* @returns Promise indicating disconnection completion
*/
static disconnect(): Promise<any>;
/**
* Check if Google+ services are available
* @returns Promise resolving to availability status
*/
static isAvailable(): Promise<boolean>;
}Usage Examples:
import { GooglePlus } from 'ionic-native';
// Google+ authentication service
class GooglePlusAuthService {
async login() {
try {
const isAvailable = await GooglePlus.isAvailable();
if (!isAvailable) {
throw new Error('Google+ services not available');
}
const options = {
scopes: 'profile email',
webClientId: 'your-web-client-id.apps.googleusercontent.com'
};
const user = await GooglePlus.login(options);
console.log('Google+ login successful:', user);
return {
success: true,
user: {
id: user.userId,
name: user.displayName,
email: user.email,
image: user.imageUrl,
idToken: user.idToken,
accessToken: user.accessToken
}
};
} catch (error) {
console.error('Google+ login error:', error);
throw error;
}
}
async silentLogin() {
try {
const options = {
scopes: 'profile email',
webClientId: 'your-web-client-id.apps.googleusercontent.com'
};
const user = await GooglePlus.trySilentLogin(options);
console.log('Google+ silent login successful:', user);
return user;
} catch (error) {
console.log('Google+ silent login failed:', error);
return null;
}
}
async logout() {
try {
await GooglePlus.logout();
console.log('Google+ logout successful');
} catch (error) {
console.error('Google+ logout error:', error);
throw error;
}
}
async disconnect() {
try {
await GooglePlus.disconnect();
console.log('Google+ disconnect successful');
} catch (error) {
console.error('Google+ disconnect error:', error);
throw error;
}
}
}Twitter authentication and interaction capabilities.
/**
* TwitterConnect class for Twitter authentication
*/
class TwitterConnect {
/**
* Login to Twitter
* @returns Promise resolving to user credentials
*/
static login(): Promise<any>;
/**
* Logout from Twitter
* @returns Promise indicating logout completion
*/
static logout(): Promise<any>;
/**
* Show user profile
* @param userid User ID to display
* @returns Promise resolving to user data
*/
static showUser(userid: string): Promise<any>;
}Usage Examples:
import { TwitterConnect } from 'ionic-native';
// Twitter authentication service
class TwitterAuthService {
async login() {
try {
const response = await TwitterConnect.login();
console.log('Twitter login successful:', response);
return {
success: true,
user: {
id: response.userId,
username: response.userName,
token: response.token,
secret: response.secret
}
};
} catch (error) {
console.error('Twitter login error:', error);
throw error;
}
}
async logout() {
try {
await TwitterConnect.logout();
console.log('Twitter logout successful');
} catch (error) {
console.error('Twitter logout error:', error);
throw error;
}
}
async showUserProfile(userId: string) {
try {
const user = await TwitterConnect.showUser(userId);
console.log('Twitter user profile:', user);
return user;
} catch (error) {
console.error('Twitter profile error:', error);
throw error;
}
}
}Unified service for managing multiple social authentication providers.
// Unified social authentication service
class SocialAuthManager {
private providers: Map<string, any> = new Map();
constructor() {
// Initialize available providers
this.providers.set('facebook', new FacebookAuthService());
this.providers.set('google', new GooglePlusAuthService());
this.providers.set('twitter', new TwitterAuthService());
}
async login(provider: string, options?: any) {
const authService = this.providers.get(provider);
if (!authService) {
throw new Error(`Provider ${provider} not supported`);
}
try {
const result = await authService.login(options);
// Store authentication info
this.storeAuthInfo(provider, result);
return result;
} catch (error) {
console.error(`${provider} login failed:`, error);
throw error;
}
}
async logout(provider: string) {
const authService = this.providers.get(provider);
if (!authService) {
throw new Error(`Provider ${provider} not supported`);
}
try {
await authService.logout();
this.clearAuthInfo(provider);
} catch (error) {
console.error(`${provider} logout failed:`, error);
throw error;
}
}
async logoutAll() {
const logoutPromises = Array.from(this.providers.keys()).map(provider =>
this.logout(provider).catch(error =>
console.error(`Failed to logout from ${provider}:`, error)
)
);
await Promise.all(logoutPromises);
}
isLoggedIn(provider: string): boolean {
const authInfo = localStorage.getItem(`${provider}_auth`);
return !!authInfo;
}
getAuthInfo(provider: string): any {
const authInfo = localStorage.getItem(`${provider}_auth`);
return authInfo ? JSON.parse(authInfo) : null;
}
private storeAuthInfo(provider: string, authInfo: any) {
localStorage.setItem(`${provider}_auth`, JSON.stringify(authInfo));
}
private clearAuthInfo(provider: string) {
localStorage.removeItem(`${provider}_auth`);
}
getSupportedProviders(): string[] {
return Array.from(this.providers.keys());
}
}
// Usage example
const socialAuth = new SocialAuthManager();
// Login with different providers
async function loginWithProvider(provider: 'facebook' | 'google' | 'twitter') {
try {
const result = await socialAuth.login(provider);
console.log(`Logged in with ${provider}:`, result.user);
} catch (error) {
console.error(`Failed to login with ${provider}:`, error);
}
}
// Check login status
function checkAuthStatus() {
const providers = socialAuth.getSupportedProviders();
providers.forEach(provider => {
if (socialAuth.isLoggedIn(provider)) {
const authInfo = socialAuth.getAuthInfo(provider);
console.log(`Authenticated with ${provider}:`, authInfo.user);
}
});
}