mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
improve facebook-js-sdk types (#35467)
This commit is contained in:
parent
3a0cae806d
commit
b578fe0b29
@ -182,3 +182,14 @@ FB.ui({
|
||||
method: 'canvas_preview',
|
||||
canvas_id: '<CANVAS_ID>'
|
||||
});
|
||||
|
||||
FB.Event.subscribe('auth.authResponseChange', response => {
|
||||
if (response.status === 'connected') {
|
||||
response.authResponse.accessToken;
|
||||
}
|
||||
});
|
||||
|
||||
FB.Event.unsubscribe('auth.authResponseChange', () => {});
|
||||
|
||||
FB.api('/me', response => {});
|
||||
FB.api('/me', 'get', { fields: ['last_name'] }, response => {});
|
||||
|
||||
155
types/facebook-js-sdk/index.d.ts
vendored
155
types/facebook-js-sdk/index.d.ts
vendored
@ -1,20 +1,65 @@
|
||||
// Type definitions for the Facebook Javascript SDK 3.2
|
||||
// Type definitions for the Facebook Javascript SDK 3.3
|
||||
// Project: https://developers.facebook.com/docs/javascript
|
||||
// Definitions by: Amrit Kahlon <https://github.com/amritk>
|
||||
// Mahmoud Zohdi <https://github.com/mahmoudzohdi>
|
||||
// Marc Knaup <https://github.com/fluidsonic>
|
||||
// Ben Grynhaus <https://github.com/bengry>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import fb = facebook;
|
||||
declare var FB: fb.FacebookStatic;
|
||||
declare namespace facebook {
|
||||
type FacebookEventType =
|
||||
| 'auth.authResponseChange'
|
||||
| 'auth.logout'
|
||||
| 'auth.login'
|
||||
| 'auth.statusChange'
|
||||
| 'xfbml.render';
|
||||
|
||||
type LoginStatus =
|
||||
| 'authorization_expired'
|
||||
| 'connected'
|
||||
| 'not_authorized'
|
||||
| 'unknown';
|
||||
|
||||
type FacebookEventCallback<
|
||||
TEvent extends FacebookEventType
|
||||
> = TEvent extends 'xfbl.render'
|
||||
? () => void
|
||||
: (response: StatusResponse) => void;
|
||||
|
||||
interface FacebookStaticEvent {
|
||||
subscribe<TEvent extends FacebookEventType>(
|
||||
event: TEvent,
|
||||
callback: FacebookEventCallback<TEvent>
|
||||
): void;
|
||||
unsubscribe<TEvent extends FacebookEventType>(
|
||||
event: TEvent,
|
||||
callback: FacebookEventCallback<TEvent>
|
||||
): void;
|
||||
}
|
||||
|
||||
interface FacebookStatic {
|
||||
api: any;
|
||||
api<TResponse>(
|
||||
path: string,
|
||||
callback: (response: TResponse) => void
|
||||
): void;
|
||||
api<TParams extends object, TResponse>(
|
||||
path: string,
|
||||
params: TParams,
|
||||
callback: (response: TResponse) => void
|
||||
): void;
|
||||
api<TParams extends object, TResponse>(
|
||||
path: string,
|
||||
method: 'get' | 'post' | 'delete',
|
||||
params: TParams,
|
||||
callback: (response: TResponse) => void
|
||||
): void;
|
||||
|
||||
AppEvents: any;
|
||||
Canvas: any;
|
||||
Event: any;
|
||||
Event: FacebookStaticEvent;
|
||||
|
||||
/**
|
||||
* The method FB.getAuthResponse() is a synchronous accessor for the current authResponse.
|
||||
@ -31,7 +76,10 @@ declare namespace facebook {
|
||||
* @param callback function to handle the response.
|
||||
* @param roundtrip force a roundtrip to Facebook - effectively refreshing the cache of the response object
|
||||
*/
|
||||
getLoginStatus(callback: (response: StatusResponse) => void, roundtrip?: boolean): void;
|
||||
getLoginStatus(
|
||||
callback: (response: StatusResponse) => void,
|
||||
roundtrip?: boolean
|
||||
): void;
|
||||
|
||||
/**
|
||||
* The method FB.init() is used to initialize and setup the SDK.
|
||||
@ -50,7 +98,10 @@ declare namespace facebook {
|
||||
* @param callback function to handle the response.
|
||||
* @param options optional ILoginOption to add params such as scope.
|
||||
*/
|
||||
login(callback: (response: StatusResponse) => void, options?: LoginOptions): void;
|
||||
login(
|
||||
callback: (response: StatusResponse) => void,
|
||||
options?: LoginOptions
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Use this function to log the user in
|
||||
@ -73,67 +124,106 @@ declare namespace facebook {
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/sharing/reference/share-dialog
|
||||
*/
|
||||
ui(params: ShareDialogParams, callback?: (response: ShareDialogResponse) => void): void;
|
||||
ui(
|
||||
params: ShareDialogParams,
|
||||
callback?: (response: ShareDialogResponse) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/sharing/reference/share-dialog
|
||||
*/
|
||||
ui(params: ShareOpenGraphDialogParams, callback?: (response: ShareOpenGraphDialogResponse) => void): void;
|
||||
ui(
|
||||
params: ShareOpenGraphDialogParams,
|
||||
callback?: (response: ShareOpenGraphDialogResponse) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/pages/page-tab-dialog
|
||||
*/
|
||||
ui(params: AddPageTabDialogParams, callback?: (response: DialogResponse) => void): void;
|
||||
ui(
|
||||
params: AddPageTabDialogParams,
|
||||
callback?: (response: DialogResponse) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/games/services/gamerequests
|
||||
*/
|
||||
ui(params: GameRequestDialogParams, callback?: (response: GameRequestDialogResponse) => void): void;
|
||||
ui(
|
||||
params: GameRequestDialogParams,
|
||||
callback?: (response: GameRequestDialogResponse) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/payments/reference/paydialog
|
||||
*/
|
||||
ui(params: PayDialogParams, callback?: (response: PayDialogResponse) => void): void;
|
||||
ui(
|
||||
params: PayDialogParams,
|
||||
callback?: (response: PayDialogResponse) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/games_payments/payments_lite
|
||||
*/
|
||||
ui(params: PaymentsLiteDialogParams, callback?: (response: PaymentsLiteDialogResponse) => void): void;
|
||||
ui(
|
||||
params: PaymentsLiteDialogParams,
|
||||
callback?: (response: PaymentsLiteDialogResponse) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/videos/live-video/exploring-live#golivedialog
|
||||
*/
|
||||
ui(params: LiveDialogParams, callback?: (response: LiveDialogResponse) => void): void;
|
||||
ui(
|
||||
params: LiveDialogParams,
|
||||
callback?: (response: LiveDialogResponse) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/sharing/reference/send-dialog
|
||||
*/
|
||||
ui(params: SendDialogParams, callback?: (response: DialogResponse) => void): void;
|
||||
ui(
|
||||
params: SendDialogParams,
|
||||
callback?: (response: DialogResponse) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/marketing-api/guides/offer-ads/#create-offer-dialog
|
||||
*/
|
||||
ui(params: CreateOfferDialogParams, callback?: (response: CreateOfferDialogResponse) => void): void;
|
||||
ui(
|
||||
params: CreateOfferDialogParams,
|
||||
callback?: (response: CreateOfferDialogResponse) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/marketing-api/guides/lead-ads/create#create-leadgen-dialog
|
||||
*/
|
||||
ui(params: LeadgenDialogParams, callback?: (response: LeadgenDialogResponse) => void): void;
|
||||
ui(
|
||||
params: LeadgenDialogParams,
|
||||
callback?: (response: LeadgenDialogResponse) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/marketing-api/guides/canvas-ads#canvas-ads-dialog
|
||||
*/
|
||||
ui(params: InstantExperiencesAdsDialogParams, callback?: (response: InstantExperiencesAdsDialogResponse) => void): void;
|
||||
ui(
|
||||
params: InstantExperiencesAdsDialogParams,
|
||||
callback?: (response: InstantExperiencesAdsDialogResponse) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/marketing-api/guides/canvas-ads#canvas-preview-dialog
|
||||
*/
|
||||
ui(params: InstantExperiencesPreviewDialogParams, callback?: (response: DialogResponse) => void): void;
|
||||
ui(
|
||||
params: InstantExperiencesPreviewDialogParams,
|
||||
callback?: (response: DialogResponse) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* @see https://developers.facebook.com/docs/marketing-api/guides/collection#collection-ads-dialog
|
||||
*/
|
||||
ui(params: CollectionAdsDialogParams, callback?: (response: CollectionAdsDialogResponse) => void): void;
|
||||
ui(
|
||||
params: CollectionAdsDialogParams,
|
||||
callback?: (response: CollectionAdsDialogResponse) => void
|
||||
): void;
|
||||
|
||||
XFBML: any;
|
||||
}
|
||||
@ -198,7 +288,10 @@ declare namespace facebook {
|
||||
action_type?: 'send' | 'askfor' | 'turn';
|
||||
data?: string;
|
||||
exclude_ids?: string[];
|
||||
filters?: 'app_users' | 'app_non_users' | Array<{ name: string, user_ids: string[] }>;
|
||||
filters?:
|
||||
| 'app_users'
|
||||
| 'app_non_users'
|
||||
| Array<{ name: string; user_ids: string[] }>;
|
||||
max_recipients?: number;
|
||||
object_id?: string;
|
||||
suggestions?: string[];
|
||||
@ -224,12 +317,12 @@ declare namespace facebook {
|
||||
test_currency?: string;
|
||||
}
|
||||
|
||||
interface PaymentsLiteDialogParams extends DialogParams {
|
||||
interface PaymentsLiteDialogParams extends DialogParams {
|
||||
method: 'pay';
|
||||
action: 'purchaseiap';
|
||||
product_id: string;
|
||||
developer_payload?: string;
|
||||
quantity?: number;
|
||||
quantity?: number;
|
||||
}
|
||||
|
||||
interface LiveDialogParams extends DialogParams {
|
||||
@ -243,7 +336,13 @@ declare namespace facebook {
|
||||
account_id: string;
|
||||
display: 'popup';
|
||||
method: 'create_offer';
|
||||
objective: 'APP_INSTALLS' | 'CONVERSIONS' | 'LINK_CLICKS' | 'OFFER_CLAIMS' | 'PRODUCT_CATALOG_SALES' | 'STORE_VISITS';
|
||||
objective:
|
||||
| 'APP_INSTALLS'
|
||||
| 'CONVERSIONS'
|
||||
| 'LINK_CLICKS'
|
||||
| 'OFFER_CLAIMS'
|
||||
| 'PRODUCT_CATALOG_SALES'
|
||||
| 'STORE_VISITS';
|
||||
page_id: string;
|
||||
}
|
||||
|
||||
@ -268,7 +367,8 @@ declare namespace facebook {
|
||||
canvas_id: string;
|
||||
}
|
||||
|
||||
interface CollectionAdsDialogParams extends InstantExperiencesAdsDialogParams {
|
||||
interface CollectionAdsDialogParams
|
||||
extends InstantExperiencesAdsDialogParams {
|
||||
account_id: string;
|
||||
canvas_id?: undefined;
|
||||
template_id: string;
|
||||
@ -291,7 +391,7 @@ declare namespace facebook {
|
||||
}
|
||||
|
||||
interface StatusResponse {
|
||||
status: 'authorization_expired' | 'connected' | 'not_authorized' | 'unknown';
|
||||
status: LoginStatus;
|
||||
authResponse: AuthResponse;
|
||||
}
|
||||
|
||||
@ -323,7 +423,7 @@ declare namespace facebook {
|
||||
signed_request: string;
|
||||
}
|
||||
|
||||
interface PaymentsLiteDialogResponse extends DialogResponse {
|
||||
interface PaymentsLiteDialogResponse extends DialogResponse {
|
||||
app_id: number;
|
||||
developer_payload?: string;
|
||||
payment_id: number;
|
||||
@ -355,5 +455,6 @@ declare namespace facebook {
|
||||
success: boolean;
|
||||
}
|
||||
|
||||
interface CollectionAdsDialogResponse extends InstantExperiencesAdsDialogResponse {}
|
||||
interface CollectionAdsDialogResponse
|
||||
extends InstantExperiencesAdsDialogResponse {}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user