diff --git a/types/facebook-instant-games/index.d.ts b/types/facebook-instant-games/index.d.ts index 1e8a8d76fd..5e5589a150 100644 --- a/types/facebook-instant-games/index.d.ts +++ b/types/facebook-instant-games/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for facebook-instant-games 6.1 // Project: https://developers.facebook.com/docs/games/instant-games -// Definitions by: Menushka Weeratunga +// Definitions by: Menushka Weeratunga , Øyvind Johansen Amundrud // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare namespace FBInstant { @@ -8,23 +8,23 @@ declare namespace FBInstant { let context: Context; let payments: Payments; - function getLocale(): string; - function getPlatform(): string; + function getLocale(): string | null; + function getPlatform(): Platform; function getSDKVersion(): string; - function initializeAsync(): Promise; - function setLoadingProgress(progress: number): void; + function initializeAsync(): Promise; + function setLoadingProgress(percentage: number): void; function getSupportedAPIs(): string[]; function getEntryPointData(): any; function getEntryPointAsync(): Promise; function setSessionData(sessionData: any): void; - function startGameAsync(): Promise; + function startGameAsync(): Promise; function shareAsync(payload: SharePayload): Promise; - function updateAsync(payload: UpdatePayload | LeaderboardUpdatePayload): Promise; - function switchGameAsync(appID: string, data?: string): Promise; + function updateAsync(payload: CustomUpdatePayload | LeaderboardUpdatePayload): Promise; + function switchGameAsync(appID: string, data?: any): Promise; function canCreateShortcutAsync(): Promise; function createShortcutAsync(): Promise; function quit(): void; - function logEvent(eventName: string, valueToSum?: number, parameter?: any): APIError; + function logEvent(eventName: string, valueToSum?: number, parameter?: { [key: string]: string; }): APIError | null; function onPause(func: () => void): void; function getInterstitialAdAsync(placementID: string): Promise; function getRewardedVideoAsync(placementID: string): Promise; @@ -33,13 +33,13 @@ declare namespace FBInstant { function getLeaderboardAsync(name: string): Promise; interface Player { - getID(): string; - getSignedPlayerInfoAsync(requestPayload: string): Promise; + getID(): string | null; + getSignedPlayerInfoAsync(requestPayload?: string): Promise; canSubscribeBotAsync(): Promise; subscribeBotAsync(): Promise; - getName(): string; - getPhoto(): string; - getDataAsync(keys?: string[]): Promise; + getName(): string | null; + getPhoto(): string | null; + getDataAsync(keys: string[]): Promise; setDataAsync(data: DataObject): Promise; flushDataAsync(): Promise; getStatsAsync(keys?: string[]): Promise; @@ -49,9 +49,9 @@ declare namespace FBInstant { } interface Context { - getID(): string; + getID(): string | null; getType(): Type; - isSizeBetween(minSize: number, maxSize: number): ContextSizeResponse; + isSizeBetween(minSize?: number, maxSize?: number): ContextSizeResponse | null; switchAsync(id: string): Promise; chooseAsync(options: ContextOptions): Promise; createAsync(playerID: string): Promise; @@ -60,10 +60,10 @@ declare namespace FBInstant { interface Leaderboard { getName(): string; - getContextID(): string; + getContextID(): string | null; getEntryCountAsync(): Promise; setScoreAsync(score: number, extraData: string): Promise; - getPlayerEntryAsync(): Promise; + getPlayerEntryAsync(): Promise; getEntriesAsync(count: number, offset: number): Promise; } @@ -72,20 +72,20 @@ declare namespace FBInstant { getFormattedScore(): string; getTimestamp(): number; getRank(): number; - getExtraData(): string; + getExtraData(): string | null; getPlayer(): LeaderboardPlayer; } interface LeaderboardPlayer { getName(): string; - getPhoto(): string; - getID(): string; + getPhoto(): string | null; + getID(): string | null; } interface ConnectedPlayer { getID(): string; - getName(): string; - getPhoto(): string; + getName(): string | null; + getPhoto(): string | null; } interface SignedPlayerInfo { @@ -95,8 +95,8 @@ declare namespace FBInstant { interface ContextPlayer { getID(): string; - getName(): string; - getPhoto(): string; + getName(): string | null; + getPhoto(): string | null; } interface AdInstance { @@ -106,6 +106,7 @@ declare namespace FBInstant { } interface Payments { + getCatalogAsync(): Promise; purchaseAsync(purchaseConfig: PurchaseConfig): Promise; getPurchasesAsync(): Promise; consumePurchaseAsync(purchaseToken: string): Promise; @@ -143,9 +144,9 @@ declare namespace FBInstant { } interface SharePayload { - intent?: Intent; - image?: string; - text?: string; + intent: Intent; + image: string; + text: string; data?: any; } @@ -159,12 +160,12 @@ declare namespace FBInstant { developerPayload?: string; } - interface UpdatePayload { - action?: UpdateAction; - template?: string; + interface CustomUpdatePayload { + action: UpdateAction; + template: string; cta?: (string | LocalizableContent); - image?: string; - text?: (string | LocalizableContent); + image: string; + text: (string | LocalizableContent); data?: any; strategy?: string; notification?: string; @@ -181,13 +182,15 @@ declare namespace FBInstant { localizations: LocalizationsDict; } - interface DataObject { [ key: string ]: string | number; } + interface DataObject { [ key: string ]: any; } interface StatsObject { [ key: string ]: number; } interface IncrementObject { [ key: string ]: number; } - type LocalizationsDict = any; + interface LocalizationsDict { + [x: string]: string; + } type SignedPurchaseRequest = string; @@ -202,20 +205,20 @@ declare namespace FBInstant { type Intent = "INVITE" | "REQUEST" | "CHALLENGE" | "SHARE"; type ErrorCodeType = "ADS_FREQUENT_LOAD" | - "ADS_NO_FILL" | - "ADS_NOT_LOADED" | - "ADS_TOO_MANY_INSTANCES" | - "ANALYTICS_POST_EXCEPTION" | - "CLIENT_REQUIRES_UPDATE" | - "CLIENT_UNSUPPORTED_OPERATION" | - "INVALID_OPERATION" | - "INVALID_PARAM" | - "LEADERBOARD_NOT_FOUND" | - "LEADERBOARD_WRONG_CONTEXT" | - "NETWORK_FAILURE" | - "PENDING_REQUEST" | - "RATE_LIMITED" | - "SAME_CONTEXT" | - "UNKNOWN" | - "USER_INPUT"; + "ADS_NO_FILL" | + "ADS_NOT_LOADED" | + "ADS_TOO_MANY_INSTANCES" | + "ANALYTICS_POST_EXCEPTION" | + "CLIENT_REQUIRES_UPDATE" | + "CLIENT_UNSUPPORTED_OPERATION" | + "INVALID_OPERATION" | + "INVALID_PARAM" | + "LEADERBOARD_NOT_FOUND" | + "LEADERBOARD_WRONG_CONTEXT" | + "NETWORK_FAILURE" | + "PENDING_REQUEST" | + "RATE_LIMITED" | + "SAME_CONTEXT" | + "UNKNOWN" | + "USER_INPUT"; }