diff --git a/package.json b/package.json index e7eac39..832be91 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/fb.d.ts b/src/fb.d.ts new file mode 100644 index 0000000..3365166 --- /dev/null +++ b/src/fb.d.ts @@ -0,0 +1,82 @@ +interface FBOptions { + accessToken: string; + appId: string; + appSecret: string; + version?: string; + proxy?: string; + timeout?: number; + scope?: string; + redirectUri?: string; + Promise?: Promise; +} + +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 { + constructor(options?: FBOptions); + + api(path: string): Promise; + + api(path: string, method: string): Promise; + + api(path: string, params: any): Promise; + + api(path: string, method: string, params: any): Promise; + + 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;