forked from Thuzi/facebook-node-sdk
-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added basic Typescript definitions. #46
Closed
Closed
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
29ac795
Added basic Typescript definitions.
andrewstart fbdb904
Merge branch 'master' into typings
andrewstart 0236577
Updated to reflect changed API and what is actually exported from the…
andrewstart fd072b8
Use dependency's Promise TS definition.
andrewstart 7487b51
Merge remote-tracking branch 'node-facebook/master' into typings
andrewstart fe11fc4
Added missing methods, some option definitions.
andrewstart caff308
Added test for typescript definition.
andrewstart 68c9eca
Merge branch 'master' into typings
andrewstart ba5e440
Fix comma that got dropped during merge.
andrewstart 8ffe919
Clean up typings test
andrewstart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Promise = require("any-promise"); | ||
|
||
type HTTPMethods = "get" | "post" | "delete"; | ||
|
||
export interface FacebookOptions { | ||
accessToken?: string; | ||
appId?: string; | ||
appSecret?: string; | ||
version?: string; | ||
proxy?: string; | ||
timeout?: number; | ||
scope?: string; | ||
redirectUri?: string; | ||
Promise?: any; | ||
} | ||
|
||
export interface LoginUrlOptions { | ||
appId?: string; | ||
client_id?: string; | ||
redirectUri?: string; | ||
redirect_uri?: string; | ||
scope?: string; | ||
display?: string; | ||
state?: string; | ||
responseType?: string; | ||
response_type?: string; | ||
} | ||
|
||
export class Facebook { | ||
api(path: string): Promise<any>; | ||
api(path: string, callback: (response: any) => void): void; | ||
api(path: string, params: any): Promise<any>; | ||
api(path: string, params: any, callback: (response: any) => void): void; | ||
api(path: string, method: HTTPMethods): Promise<any>; | ||
api(path: string, method: HTTPMethods, callback: (response: any) => void): void; | ||
api(path: string, method: HTTPMethods, params: any): Promise<any>; | ||
api(path: string, method: HTTPMethods, params: any, callback: (response: any) => void): void; | ||
napi(path: string, callback?: (error: any, response: any) => void): void; | ||
napi(path: string, params: any, callback?: (error: any, response: any) => void): void; | ||
napi(path: string, method: HTTPMethods, callback?: (error: any, response: any) => void): void; | ||
napi(path: string, method: HTTPMethods, params: any, callback?: (error: any, response: any) => void): void; | ||
getAccessToken(): string; | ||
setAccessToken(token: string): void; | ||
parseSignedRequest(signedRequest: string, appSecret?: string): any; | ||
getLoginUrl(options?: LoginUrlOptions): string; | ||
options(): FacebookOptions; | ||
options(optionName: string): any; | ||
options(optionsDict: FacebookOptions): void; | ||
extend(options: FacebookOptions): Facebook; | ||
withAccessToken(token: string): Facebook; | ||
} | ||
|
||
export default new Facebook; | ||
export var FB: Facebook; | ||
export var version: string; | ||
|
||
export class FacebookApiException { | ||
name: string; | ||
message: string; | ||
response: any; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// so happy this relative import seems to work the same as ' import FB from "fb" ' | ||
import FB from "../../"; | ||
import {Facebook} from "../../"; | ||
|
||
// the 3 options overloads | ||
FB.options().appId; | ||
FB.options("appId"); | ||
FB.options({ | ||
appId: "alskjdfaslkdjfalsdfjk" | ||
}); | ||
// extend returns a Facebook | ||
FB.extend({ | ||
accessToken: "loremipsum" | ||
}).options("accessToken"); | ||
// withAccessToken returns a Facebook | ||
FB.withAccessToken("foobar").options("accessToken"); | ||
// setAccessToken works, getAccessToken returns a string | ||
FB.setAccessToken("foobar"); | ||
FB.getAccessToken().charAt(0); | ||
|
||
// All api calls have the documented parameters/returns | ||
FB.api("./").then((response) => { | ||
}); | ||
FB.api("./", (response) => {}); | ||
FB.api("./", {scope: "foo"}).then((response) => { | ||
}); | ||
FB.api("./", {scope: "foo"}, (response) => {}); | ||
FB.api("./", "get").then((response) => { | ||
}); | ||
FB.api("./", "post", (response) => {}); | ||
FB.api("./", "delete", {scope: "foo"}).then((response) => { | ||
}); | ||
FB.api("./", "get", {scope: "foo"}, (response) => {}); | ||
// All napi calls have the coumented parameters | ||
FB.napi("./"); | ||
FB.napi("./", (error, response) => {}); | ||
FB.napi("./", {scope: "foo"}); | ||
FB.napi("./", {scope: "foo"}, (error, response) => {}); | ||
FB.napi("./", "post"); | ||
FB.napi("./", "post", (error, response) => {}); | ||
FB.napi("./", "delete", {scope: "foo"}); | ||
FB.napi("./", "delete", {scope: "foo"}, (error, response) => {}); | ||
|
||
// can instantiate Facebook class | ||
let fb = new Facebook(); | ||
fb.api("./"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"compileOnSave": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
var tt = require('typescript-definition-tester'); | ||
|
||
describe('typescript definition tests', function() { | ||
this.slow(1800); | ||
this.timeout(2000); | ||
it('should compile examples successfully against fb.d.ts', (done) => { | ||
tt.compileDirectory( | ||
__dirname, | ||
function(fileName) { | ||
return fileName.indexOf('.ts') > -1; | ||
}, | ||
function() { | ||
done(); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this line.
Promise
can be used directly without importing it as it is part of ES6.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While that is true, that doesn't mean that everyone is using an ES6 environment, and additionally this library uses
any-promise
as the Promise implementation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's how i have seen it used in most well written typings I have used. If you are not targeting ES6, it is up to the consumer to provide the typings for
Promise
. Example from a fairy recent declaration https://github.com/facebook/dataloader/blob/master/src/index.d.tsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally, 2.0 of this library supports only NodeJS environments that support
Promise
natively ;)