From d3b0d4a5215b8c2dce8bed542f3943b9f57035e9 Mon Sep 17 00:00:00 2001 From: Amrit Kahlon Date: Mon, 15 Feb 2016 17:42:46 -0800 Subject: [PATCH 1/3] Added some definitions for Facebook Javascript SDK --- facebook-js-sdk/facebook-js-sdk.d.ts | 85 ++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 facebook-js-sdk/facebook-js-sdk.d.ts diff --git a/facebook-js-sdk/facebook-js-sdk.d.ts b/facebook-js-sdk/facebook-js-sdk.d.ts new file mode 100644 index 0000000000..5734121753 --- /dev/null +++ b/facebook-js-sdk/facebook-js-sdk.d.ts @@ -0,0 +1,85 @@ +// Type definitions for the Facebook Javascript SDK +// Project: https://developers.facebook.com/docs/javascript +// Definitions by: Amrit Kahlon +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import fb = facebook; +declare var FB: fb.IFacebookStatic; +declare module facebook { + + interface IFacebookStatic { + // api: any; + // AppEvents: any; + // Canvas: any; + // Event: any; + // getAccessToken: any; + // getAuthResponse: any; + /** + * FB.getLoginStatus() allows you to determine if a user is + * logged in to Facebook and has authenticated your app. + * + * @param callback function to handle the response. + */ + getLoginStatus(callback: (response: ILoginStatusResp) => void): void; + /** + * The method FB.init() is used to initialize and setup the SDK. + * + * @param params params for the initialization. + */ + init(params: IInitParams): void; + /** + * Use this function to log the user in + * + * Calling FB.login() results in the JS SDK attempting to open a popup window. + * As such, this method should only be called after a user click event, otherwise + * the popup window will be blocked by most browsers. + * + * @param callback function to handle the response. + * @param options optional ILoginOption to add params such as scope. + */ + login(callback: (response: ILoginStatusResp) => void, options?: ILoginOptions): void; + /** + * The method FB.logout() logs the user out of your site and, in some cases, Facebook. + * + * @param callback function to handle the response + */ + logout(callback: (response: ILoginStatusResp) => void): void; + // ui: any; + // XFBML: any; + } + + interface IInitParams { + appId: string; + version?: string; + cookie?: boolean; + status?: boolean; + xfbml?: boolean; + frictionlessRequests?: boolean; + hideFlashCallback?: boolean; + } + + interface ILoginOptions { + auth_type?: string; + scope?: string; + return_scopes?: boolean; + enable_profile_selector?: boolean; + profile_selector_ids?: string; + } + + + //////////////////////// + // + // RESPONSES + // + //////////////////////// + + interface ILoginStatusResp { + status: string; + authResponse: { + accessToken: string; + expiresIn: number; + signedRequest: string; + userID: string; + } + } +} From a8834b599c3da89ff937b509a1d46df6d7d183e6 Mon Sep 17 00:00:00 2001 From: Amrit Kahlon Date: Mon, 15 Feb 2016 18:03:09 -0800 Subject: [PATCH 2/3] Added tests for facebook-js-sdk definitions --- facebook-js-sdk/facebook-js-sdk-tests.ts | 35 ++++++++++++++++++++++++ facebook-js-sdk/facebook-js-sdk.d.ts | 9 ++++-- 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 facebook-js-sdk/facebook-js-sdk-tests.ts diff --git a/facebook-js-sdk/facebook-js-sdk-tests.ts b/facebook-js-sdk/facebook-js-sdk-tests.ts new file mode 100644 index 0000000000..b13c4df1e4 --- /dev/null +++ b/facebook-js-sdk/facebook-js-sdk-tests.ts @@ -0,0 +1,35 @@ +/// + +FB.init({ + appId: '***********', + version: 'v2.5', + status: true, + cookie: true, + xfbml: true +}); + +FB.getLoginStatus(function(response: fb.ILoginStatusResp) { + console.log(response); + console.log(response.status); + console.log(response.authResponse.accessToken); +}); + +FB.getAuthResponse(function(response: fb.ILoginStatusResp) { + console.log(response); + console.log(response.status); + console.log(response.authResponse.accessToken); +}); + +FB.login(function(response: fb.ILoginStatusResp) { + console.log(response); + console.log(response.status); + console.log(response.authResponse.accessToken); +}, { + scope: 'public_profile' +}); + +FB.logout(function(response: fb.ILoginStatusResp) { + console.log(response); + console.log(response.status); + console.log(response.authResponse.accessToken); +}); diff --git a/facebook-js-sdk/facebook-js-sdk.d.ts b/facebook-js-sdk/facebook-js-sdk.d.ts index 5734121753..1b6fb6111e 100644 --- a/facebook-js-sdk/facebook-js-sdk.d.ts +++ b/facebook-js-sdk/facebook-js-sdk.d.ts @@ -12,8 +12,13 @@ declare module facebook { // AppEvents: any; // Canvas: any; // Event: any; - // getAccessToken: any; - // getAuthResponse: any; + /** + * The method FB.getAuthResponse() is a synchronous accessor for the current authResponse. + * The synchronous nature of this method is what sets it apart from the other login methods. + * + * @param callback function to handle the response. + */ + getAuthResponse(callback: (response: ILoginStatusResp) => void): void; /** * FB.getLoginStatus() allows you to determine if a user is * logged in to Facebook and has authenticated your app. From 950aefe678e62d92bfdb12641b6ac73d8cdb1030 Mon Sep 17 00:00:00 2001 From: Amrit Kahlon Date: Wed, 17 Feb 2016 11:10:46 -0800 Subject: [PATCH 3/3] Fixed naming conventions --- facebook-js-sdk/facebook-js-sdk-tests.ts | 8 ++++---- facebook-js-sdk/facebook-js-sdk.d.ts | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/facebook-js-sdk/facebook-js-sdk-tests.ts b/facebook-js-sdk/facebook-js-sdk-tests.ts index b13c4df1e4..49e615f529 100644 --- a/facebook-js-sdk/facebook-js-sdk-tests.ts +++ b/facebook-js-sdk/facebook-js-sdk-tests.ts @@ -8,19 +8,19 @@ FB.init({ xfbml: true }); -FB.getLoginStatus(function(response: fb.ILoginStatusResp) { +FB.getLoginStatus(function(response: fb.AuthResponse) { console.log(response); console.log(response.status); console.log(response.authResponse.accessToken); }); -FB.getAuthResponse(function(response: fb.ILoginStatusResp) { +FB.getAuthResponse(function(response: fb.AuthResponse) { console.log(response); console.log(response.status); console.log(response.authResponse.accessToken); }); -FB.login(function(response: fb.ILoginStatusResp) { +FB.login(function(response: fb.AuthResponse) { console.log(response); console.log(response.status); console.log(response.authResponse.accessToken); @@ -28,7 +28,7 @@ FB.login(function(response: fb.ILoginStatusResp) { scope: 'public_profile' }); -FB.logout(function(response: fb.ILoginStatusResp) { +FB.logout(function(response: fb.AuthResponse) { console.log(response); console.log(response.status); console.log(response.authResponse.accessToken); diff --git a/facebook-js-sdk/facebook-js-sdk.d.ts b/facebook-js-sdk/facebook-js-sdk.d.ts index 1b6fb6111e..e4243283f8 100644 --- a/facebook-js-sdk/facebook-js-sdk.d.ts +++ b/facebook-js-sdk/facebook-js-sdk.d.ts @@ -4,10 +4,10 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped import fb = facebook; -declare var FB: fb.IFacebookStatic; +declare var FB: fb.FacebookStatic; declare module facebook { - interface IFacebookStatic { + interface FacebookStatic { // api: any; // AppEvents: any; // Canvas: any; @@ -18,20 +18,20 @@ declare module facebook { * * @param callback function to handle the response. */ - getAuthResponse(callback: (response: ILoginStatusResp) => void): void; + getAuthResponse(callback: (response: AuthResponse) => void): void; /** * FB.getLoginStatus() allows you to determine if a user is * logged in to Facebook and has authenticated your app. * * @param callback function to handle the response. */ - getLoginStatus(callback: (response: ILoginStatusResp) => void): void; + getLoginStatus(callback: (response: AuthResponse) => void): void; /** * The method FB.init() is used to initialize and setup the SDK. * * @param params params for the initialization. */ - init(params: IInitParams): void; + init(params: InitParams): void; /** * Use this function to log the user in * @@ -42,18 +42,18 @@ declare module facebook { * @param callback function to handle the response. * @param options optional ILoginOption to add params such as scope. */ - login(callback: (response: ILoginStatusResp) => void, options?: ILoginOptions): void; + login(callback: (response: AuthResponse) => void, options?: LoginOptions): void; /** * The method FB.logout() logs the user out of your site and, in some cases, Facebook. * * @param callback function to handle the response */ - logout(callback: (response: ILoginStatusResp) => void): void; + logout(callback: (response: AuthResponse) => void): void; // ui: any; // XFBML: any; } - interface IInitParams { + interface InitParams { appId: string; version?: string; cookie?: boolean; @@ -63,7 +63,7 @@ declare module facebook { hideFlashCallback?: boolean; } - interface ILoginOptions { + interface LoginOptions { auth_type?: string; scope?: string; return_scopes?: boolean; @@ -78,7 +78,7 @@ declare module facebook { // //////////////////////// - interface ILoginStatusResp { + interface AuthResponse { status: string; authResponse: { accessToken: string;