Skip to content
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 type definitions to make it Typescript compatible #176

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
"url": "https://github.com/node-facebook/facebook-node-sdk.git"
},
"main": "./lib/fb.js",
"types": "./lib/fb.d.ts",
"scripts": {
"precommit": "lint-staged",
"lint": "eslint .",
"build": "babel src/ -d lib/",
"buildw": "babel -w src/ -d lib/",
"build": "babel src/ -d lib/ --copy-files",
"buildw": "babel -w src/ -d lib/ --copy-files",
"test": "npm run build && node ./node_modules/mocha/bin/mocha --recursive",
"test-live": "npm run build && node ./node_modules/mocha/bin/mocha --require test_live/_supports/ci-safe --recursive test_live",
"prepublish": "npm run build"
Expand Down
82 changes: 82 additions & 0 deletions src/fb.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
interface FBOptions {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bunch of options appear to be missing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used the ones mentioned in the README. Turns out the list wasn't exhaustive. I'll update the options with the ones listed in the source code.

accessToken: string;
appId: string;
appSecret: string;
version?: string;
proxy?: string;
timeout?: number;
scope?: string;
redirectUri?: string;
Promise?: Promise<any>;
}

interface SignedRequestResponse {
oauthToken: string;
userId: string;
userCountry: string;
}

interface UsageInterface {
callCount: number;
totalTime: number;
totalCPUTime: number;
}

interface FBError {
name: string;
message: string;
response: number;
}

interface FBResponseObject {
data: any;
error: any;
}

export class Facebook {
shibulijack marked this conversation as resolved.
Show resolved Hide resolved
constructor(options?: FBOptions);

api(path: string): Promise<any>;

api(path: string, method: string): Promise<any>;

api(path: string, params: any): Promise<any>;

api(path: string, method: string, params: any): Promise<any>;

extend(options: FBOptions): Facebook;

getAccessToken(): string;

getAppUsage(): UsageInterface;

getPageUsage(): UsageInterface;

getLoginUrl(options: FBOptions): string;

napi(path: string): void;

napi(path: string, method: string): void;

napi(path: string, params: any): void;

napi(path: string, method: string, params: any): void;

options(): FBOptions;

options(key: string): string;

options(options: FBOptions): void;

parseSignedRequest(signedRequest: string, appSecret: string): SignedRequestResponse;

setAccessToken(accessToken: string): void;

withAccessToken(accessToken: string): Facebook;
}

export const version: string;

export function FacebookApiException(res: FBResponseObject): FBError;

export const FB: Facebook;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a default export.