From e3d3b896999986128c633921e960ed48b99422b4 Mon Sep 17 00:00:00 2001 From: shibulijack Date: Tue, 30 Jul 2019 11:57:20 +0530 Subject: [PATCH 1/4] Added type definitions --- package.json | 4 +++- src/fb.d.ts | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/fb.d.ts diff --git a/package.json b/package.json index e7eac39..02ed21a 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ ], "author": "Thuzi LLC (https://github.com/Thuzi)", "contributors": [ - "Daniel Friesen (http://danf.ca)" + "Daniel Friesen (http://danf.ca)", + "Shibu Lijack (https://github.com/shibulijack" ], "homepage": "https://github.com/node-facebook/facebook-node-sdk", "license": "Apache-2.0", @@ -18,6 +19,7 @@ "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 .", diff --git a/src/fb.d.ts b/src/fb.d.ts new file mode 100644 index 0000000..78bcd00 --- /dev/null +++ b/src/fb.d.ts @@ -0,0 +1,39 @@ +interface FBOptions { + accessToken: string; + appId: string; + appSecret: string; + version?: string; + proxy?: string; + timeout?: number; + scope?: string; + redirectUri?: string; + Promise?: Promise; +} + +export class Facebook { + constructor(options: FBOptions); + + api(...args): Promise; + + extend(options: FBOptions): Facebook; + + getAccessToken(): string; + + getLoginUrl(): string; + + napi(...args): Promise; + + options(keyOrOptions: FBOptions): FBOptions; + + parseSignedRequest(signedRequest: string, ...args): Object; + + setAccessToken(accessToken: string): void; + + withAccessToken(accessToken: string): any; +} + +export const version: string; + +export function FacebookApiException(res: Response): void; + +export const FB: Facebook; From 1aa43a54f73ca300abb7e36473a45b95449819d0 Mon Sep 17 00:00:00 2001 From: shibulijack Date: Tue, 30 Jul 2019 12:46:42 +0530 Subject: [PATCH 2/4] Updated build commands --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 02ed21a..71e313b 100644 --- a/package.json +++ b/package.json @@ -23,8 +23,8 @@ "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" From e4bd527b0a4a808adf1f2abc0e3fd1794b7aaa83 Mon Sep 17 00:00:00 2001 From: shibulijack Date: Tue, 30 Jul 2019 15:12:05 +0530 Subject: [PATCH 3/4] Addressed review comments --- package.json | 3 +-- src/fb.d.ts | 46 +++++++++++++++++++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 71e313b..832be91 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,7 @@ ], "author": "Thuzi LLC (https://github.com/Thuzi)", "contributors": [ - "Daniel Friesen (http://danf.ca)", - "Shibu Lijack (https://github.com/shibulijack" + "Daniel Friesen (http://danf.ca)" ], "homepage": "https://github.com/node-facebook/facebook-node-sdk", "license": "Apache-2.0", diff --git a/src/fb.d.ts b/src/fb.d.ts index 78bcd00..788bf69 100644 --- a/src/fb.d.ts +++ b/src/fb.d.ts @@ -7,33 +7,61 @@ interface FBOptions { timeout?: number; scope?: string; redirectUri?: string; - Promise?: Promise; + Promise?: Promise; +} + +interface FBAPIInterface { + path: string; + method?: string; + params?: object; + callback?: Function; +} + +interface FBKeyOrOptions { + key: string; + options: FBOptions; +} + +interface SignedRequestResponse { + oauthToken: string; + userId: string; + userCountry: string; +} + +interface UsageInterface { + callCount: number; + totalTime: number; + totalCPUTime: number; } export class Facebook { - constructor(options: FBOptions); + constructor(options?: FBOptions); - api(...args): Promise; + api(arguments: FBAPIInterface): Promise; extend(options: FBOptions): Facebook; getAccessToken(): string; - getLoginUrl(): string; + getAppUsage(): UsageInterface; + + getPageUsage(): UsageInterface; + + getLoginUrl(options: FBOptions): string; - napi(...args): Promise; + napi(arguments: FBAPIInterface): void; - options(keyOrOptions: FBOptions): FBOptions; + options(keyOrOptions: keyof FBKeyOrOptions): any; - parseSignedRequest(signedRequest: string, ...args): Object; + parseSignedRequest(signedRequest: string, appSecret: string): SignedRequestResponse; setAccessToken(accessToken: string): void; - withAccessToken(accessToken: string): any; + withAccessToken(accessToken: string): Facebook; } export const version: string; -export function FacebookApiException(res: Response): void; +export function FacebookApiException(res: Response): Error; export const FB: Facebook; From 3d1933b612efe11831436feb0dd69429b1a0c32c Mon Sep 17 00:00:00 2001 From: shibulijack Date: Tue, 30 Jul 2019 17:15:37 +0530 Subject: [PATCH 4/4] More review comments --- src/fb.d.ts | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/fb.d.ts b/src/fb.d.ts index 788bf69..3365166 100644 --- a/src/fb.d.ts +++ b/src/fb.d.ts @@ -10,18 +10,6 @@ interface FBOptions { Promise?: Promise; } -interface FBAPIInterface { - path: string; - method?: string; - params?: object; - callback?: Function; -} - -interface FBKeyOrOptions { - key: string; - options: FBOptions; -} - interface SignedRequestResponse { oauthToken: string; userId: string; @@ -34,10 +22,27 @@ interface UsageInterface { totalCPUTime: number; } +interface FBError { + name: string; + message: string; + response: number; +} + +interface FBResponseObject { + data: any; + error: any; +} + export class Facebook { constructor(options?: FBOptions); - api(arguments: FBAPIInterface): Promise; + 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; @@ -49,9 +54,19 @@ export class Facebook { getLoginUrl(options: FBOptions): string; - napi(arguments: FBAPIInterface): void; + 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(keyOrOptions: keyof FBKeyOrOptions): any; + options(options: FBOptions): void; parseSignedRequest(signedRequest: string, appSecret: string): SignedRequestResponse; @@ -62,6 +77,6 @@ export class Facebook { export const version: string; -export function FacebookApiException(res: Response): Error; +export function FacebookApiException(res: FBResponseObject): FBError; export const FB: Facebook;