From 3da30314df2e65115588a10ea76b2c5726b1787a Mon Sep 17 00:00:00 2001 From: Menushka Weeratunga Date: Fri, 23 Mar 2018 10:27:10 -0400 Subject: [PATCH 1/6] Added types for FBInstant --- types/fbinstant/fbinstant-tests.ts | 60 ++++++++ types/fbinstant/index.d.ts | 221 +++++++++++++++++++++++++++++ types/fbinstant/tsconfig.json | 23 +++ types/fbinstant/tslint.json | 8 ++ 4 files changed, 312 insertions(+) create mode 100644 types/fbinstant/fbinstant-tests.ts create mode 100644 types/fbinstant/index.d.ts create mode 100644 types/fbinstant/tsconfig.json create mode 100644 types/fbinstant/tslint.json diff --git a/types/fbinstant/fbinstant-tests.ts b/types/fbinstant/fbinstant-tests.ts new file mode 100644 index 0000000000..f4a72ea70e --- /dev/null +++ b/types/fbinstant/fbinstant-tests.ts @@ -0,0 +1,60 @@ +declare const FBInstant: FBInstant; + +export class FBInstantTest { + winStreak: number; + + init() { + FBInstant.initializeAsync().then(() => { + FBInstant.setLoadingProgress(100); + FBInstant.startGameAsync().then(() => { + this.startGame(); + }); + }); + } + + startGame() { + const contextId = FBInstant.context.getID(); + const contextType = FBInstant.context.getType(); + + const playerName = FBInstant.player.getName(); + const playerPic = FBInstant.player.getPhoto(); + const playerId = FBInstant.player.getID(); + } + + saveState() { + FBInstant.player.setDataAsync({ + score: this.winStreak + }); + } + + getState() { + FBInstant.player.getDataAsync(['score']) + .then((data) => { + if (typeof data['score'] !== 'undefined') { + this.winStreak = +data['score']; + } + }); + } + + update() { + FBInstant.updateAsync({ + action: 'CUSTOM', + cta: 'Play', + image: '', + text: { + default: 'Edgar played their move', + localizations: { + en_US: 'Edgar played their move', + es_LA: '\u00A1Edgar jug\u00F3 su jugada!' + } + }, + template: 'play_turn', + data: { myReplayData: '...' }, + strategy: 'IMMEDIATE', + notification: 'NO_PUSH' + }).then(() => { + // closes the game after the update is posted. + FBInstant.quit(); + }); + } +} diff --git a/types/fbinstant/index.d.ts b/types/fbinstant/index.d.ts new file mode 100644 index 0000000000..c2237c749c --- /dev/null +++ b/types/fbinstant/index.d.ts @@ -0,0 +1,221 @@ +// Type definitions for FBInstant 6.1 +// Project: https://developers.facebook.com/docs/games/instant-games +// Definitions by: Menushka Weeratunga +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare class FBInstant { + player: Player; + context: Context; + payments: Payments; + + getLocale(): string; + getPlatform(): string; + getSDKVersion(): string; + initializeAsync(): Promise; + setLoadingProgress(progress: number): void; + getSupportedAPIs(): string[]; + getEntryPointData(): any; + getEntryPointAsync(): Promise; + setSessionData(sessionData: any): void; + startGameAsync(): Promise; + shareAsync(payload: SharePayload): Promise; + updateAsync(payload: UpdatePayload): Promise; + switchGameAsync(appID: string, data: string): Promise; + canCreateShortcutAsync(): Promise; + createShortcutAsync(): Promise; + quit(): void; + logEvent(eventName: string, valueToSum?: number, parameter?: any): APIError; + onPause(func: () => void): void; + getInterstitialAdAsync(placementID: string): Promise; + getRewardedVideoAsync(placementID: string): Promise; + matchPlayerAsync(matchTag: string, switchContextWhenMatched?: boolean): Promise; + checkCanPlayerMatchAsync(): Promise; + getLeaderboardAsync(name: string): Promise; +} + +declare class Player { + getID(): string; + getSignedPlayerInfoAsync(requestPayload: string): Promise; + canSubscribeBotAsync(): Promise; + subscribeBotAsync(): Promise; + getName(): string; + getPhoto(): string; + getDataAsync(keys: string[]): Promise; + setDataAsync(data: DataObject): Promise; + flushDataAsync(): Promise; + getStatsAsync(keys: string[]): Promise; + setStatsAsync(stats: StatsObject): Promise; + incrementStatsAsync(increments: IncrementObject): Promise; + getConnectedPlayersAsync(): Promise; +} + +declare class Context { + getID(): string; + getType(): Type; + isSizeBetween(minSize: number, maxSize: number): ContextSizeResponse; + switchAsync(id: string): Promise; + chooseAsync(options: ContextOptions): Promise; + createAsync(playerID: string): Promise; + getPlayersAsync(): Promise; +} + +declare class Leaderboard { + getName(): string; + getContextID(): string; + getEntryCountAsync(): Promise; + setScoreAsync(score: number, extraData: string): Promise; + getPlayerEntryAsync(): Promise; + getEntriesAsync(count: number, offset: number): Promise; +} + +declare class LeaderboardEntry { + getScore(): number; + getFormattedScore(): string; + getTimestamp(): number; + getRank(): number; + getExtraData(): string; + getPlayer(): LeaderboardPlayer; +} + +declare class LeaderboardPlayer { + getName(): string; + getPhoto(): string; + getID(): string; +} + +declare class ConnectedPlayer { + getID(): string; + getName(): string; + getPhoto(): string; +} + +declare class SignedPlayerInfo { + getPlayerID(): string; + getSignature(): string; +} + +declare class ContextPlayer { + getID(): string; + getName(): string; + getPhoto(): string; +} + +declare class AdInstance { + getPlacementID(): string; + loadAsync(): Promise; + showAsync(): Promise; +} + +declare class Payments { + purchaseAsync(purchaseConfig: PurchaseConfig): Promise; + getPurchasesAsync(): Promise; + consumePurchaseAsync(purchaseToken: string): Promise; + onReady(callback: () => void): void; +} + +declare interface Product { + title: string; + productID: string; + description?: string; + imageURI?: string; + price: string; + priceCurrencyCode: string; +} + +declare interface ContextSizeResponse { + answer: boolean; + minSize?: number; + maxSize?: number; +} + +declare interface Purchase { + developerPayload?: string; + paymentID: string; + productID: string; + purchaseTime: string; + purchaseToken: string; + signedRequest: SignedPurchaseRequest; +} + +declare interface ContextOptions { + filters?: ContextFilter[]; + maxSize?: number; + minSize?: number; +} + +declare interface SharePayload { + intent?: Intent; + image?: string; + text?: string; + data?: any; +} + +declare interface APIError { + code: ErrorCodeType; + message: string; +} + +declare interface PurchaseConfig { + productID: string; + developerPayload?: string; +} + +declare interface UpdatePayload { + action?: UpdateAction; + template?: string; + cta?: (string | LocalizableContent); + image?: string; + text?: (string | LocalizableContent); + data?: any; + strategy?: string; + notification?: string; +} + +declare interface LeaderboardUpdatePayload { + action: UpdateAction; + name: string; + text?: string; +} + +declare interface LocalizableContent { + default: string; + localizations: LocalizationsDict; +} + +declare interface DataObject { [ key: string ]: string | number; } + +declare interface StatsObject { [ key: string ]: string | number; } + +declare interface IncrementObject { [ key: string ]: number; } + +declare type LocalizationsDict = any; + +declare type SignedPurchaseRequest = string; + +declare type ContextFilter = "NEW_CONTEXT_ONLY" | "INCLUDE_EXISTING_CHALLENGES" | "NEW_PLAYERS_ONLY"; + +declare type UpdateAction = "CUSTOM" | "LEADERBOARD"; + +declare type Platform = "IOS" | "ANDROID" | "WEB" | "MOBILE_WEB"; + +declare type Type = "POST" | "THREAD" | "GROUP" | "SOLO"; + +declare type Intent = "INVITE" | "REQUEST" | "CHALLENGE" | "SHARE"; + +declare 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"; diff --git a/types/fbinstant/tsconfig.json b/types/fbinstant/tsconfig.json new file mode 100644 index 0000000000..7cb5ffc8ae --- /dev/null +++ b/types/fbinstant/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "fbinstant-tests.ts" + ] +} diff --git a/types/fbinstant/tslint.json b/types/fbinstant/tslint.json new file mode 100644 index 0000000000..71918edac3 --- /dev/null +++ b/types/fbinstant/tslint.json @@ -0,0 +1,8 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + // Needs to be declares as it cannot be imported in typescript + // using the standard import statement + "strict-export-declare-modifiers": false + } +} From a5dcf5b5994927caa3bcb1d50d8ae0c9b66c8d1d Mon Sep 17 00:00:00 2001 From: Menushka Weeratunga Date: Fri, 23 Mar 2018 10:59:29 -0400 Subject: [PATCH 2/6] Move into single class and namspace to avoid name conflicts --- types/fbinstant/index.d.ts | 390 +++++++++++++++++++------------------ 1 file changed, 196 insertions(+), 194 deletions(-) diff --git a/types/fbinstant/index.d.ts b/types/fbinstant/index.d.ts index c2237c749c..9b337bbc5e 100644 --- a/types/fbinstant/index.d.ts +++ b/types/fbinstant/index.d.ts @@ -4,9 +4,9 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped declare class FBInstant { - player: Player; - context: Context; - payments: Payments; + player: FBInstant.Player; + context: FBInstant.Context; + payments: FBInstant.Payments; getLocale(): string; getPlatform(): string; @@ -18,204 +18,206 @@ declare class FBInstant { getEntryPointAsync(): Promise; setSessionData(sessionData: any): void; startGameAsync(): Promise; - shareAsync(payload: SharePayload): Promise; - updateAsync(payload: UpdatePayload): Promise; + shareAsync(payload: FBInstant.SharePayload): Promise; + updateAsync(payload: FBInstant.UpdatePayload): Promise; switchGameAsync(appID: string, data: string): Promise; canCreateShortcutAsync(): Promise; createShortcutAsync(): Promise; quit(): void; - logEvent(eventName: string, valueToSum?: number, parameter?: any): APIError; + logEvent(eventName: string, valueToSum?: number, parameter?: any): FBInstant.APIError; onPause(func: () => void): void; - getInterstitialAdAsync(placementID: string): Promise; - getRewardedVideoAsync(placementID: string): Promise; + getInterstitialAdAsync(placementID: string): Promise; + getRewardedVideoAsync(placementID: string): Promise; matchPlayerAsync(matchTag: string, switchContextWhenMatched?: boolean): Promise; checkCanPlayerMatchAsync(): Promise; - getLeaderboardAsync(name: string): Promise; + getLeaderboardAsync(name: string): Promise; } -declare class Player { - getID(): string; - getSignedPlayerInfoAsync(requestPayload: string): Promise; - canSubscribeBotAsync(): Promise; - subscribeBotAsync(): Promise; - getName(): string; - getPhoto(): string; - getDataAsync(keys: string[]): Promise; - setDataAsync(data: DataObject): Promise; - flushDataAsync(): Promise; - getStatsAsync(keys: string[]): Promise; - setStatsAsync(stats: StatsObject): Promise; - incrementStatsAsync(increments: IncrementObject): Promise; - getConnectedPlayersAsync(): Promise; +declare namespace FBInstant { + class Player { + getID(): string; + getSignedPlayerInfoAsync(requestPayload: string): Promise; + canSubscribeBotAsync(): Promise; + subscribeBotAsync(): Promise; + getName(): string; + getPhoto(): string; + getDataAsync(keys: string[]): Promise; + setDataAsync(data: DataObject): Promise; + flushDataAsync(): Promise; + getStatsAsync(keys: string[]): Promise; + setStatsAsync(stats: StatsObject): Promise; + incrementStatsAsync(increments: IncrementObject): Promise; + getConnectedPlayersAsync(): Promise; + } + + class Context { + getID(): string; + getType(): Type; + isSizeBetween(minSize: number, maxSize: number): ContextSizeResponse; + switchAsync(id: string): Promise; + chooseAsync(options: ContextOptions): Promise; + createAsync(playerID: string): Promise; + getPlayersAsync(): Promise; + } + + class Leaderboard { + getName(): string; + getContextID(): string; + getEntryCountAsync(): Promise; + setScoreAsync(score: number, extraData: string): Promise; + getPlayerEntryAsync(): Promise; + getEntriesAsync(count: number, offset: number): Promise; + } + + class LeaderboardEntry { + getScore(): number; + getFormattedScore(): string; + getTimestamp(): number; + getRank(): number; + getExtraData(): string; + getPlayer(): LeaderboardPlayer; + } + + class LeaderboardPlayer { + getName(): string; + getPhoto(): string; + getID(): string; + } + + class ConnectedPlayer { + getID(): string; + getName(): string; + getPhoto(): string; + } + + class SignedPlayerInfo { + getPlayerID(): string; + getSignature(): string; + } + + class ContextPlayer { + getID(): string; + getName(): string; + getPhoto(): string; + } + + class AdInstance { + getPlacementID(): string; + loadAsync(): Promise; + showAsync(): Promise; + } + + class Payments { + purchaseAsync(purchaseConfig: PurchaseConfig): Promise; + getPurchasesAsync(): Promise; + consumePurchaseAsync(purchaseToken: string): Promise; + onReady(callback: () => void): void; + } + + interface Product { + title: string; + productID: string; + description?: string; + imageURI?: string; + price: string; + priceCurrencyCode: string; + } + + interface ContextSizeResponse { + answer: boolean; + minSize?: number; + maxSize?: number; + } + + interface Purchase { + developerPayload?: string; + paymentID: string; + productID: string; + purchaseTime: string; + purchaseToken: string; + signedRequest: SignedPurchaseRequest; + } + + interface ContextOptions { + filters?: ContextFilter[]; + maxSize?: number; + minSize?: number; + } + + interface SharePayload { + intent?: Intent; + image?: string; + text?: string; + data?: any; + } + + interface APIError { + code: ErrorCodeType; + message: string; + } + + interface PurchaseConfig { + productID: string; + developerPayload?: string; + } + + interface UpdatePayload { + action?: UpdateAction; + template?: string; + cta?: (string | LocalizableContent); + image?: string; + text?: (string | LocalizableContent); + data?: any; + strategy?: string; + notification?: string; + } + + interface LeaderboardUpdatePayload { + action: UpdateAction; + name: string; + text?: string; + } + + interface LocalizableContent { + default: string; + localizations: LocalizationsDict; + } + + interface DataObject { [ key: string ]: string | number; } + + interface StatsObject { [ key: string ]: string | number; } + + interface IncrementObject { [ key: string ]: number; } + + type LocalizationsDict = any; + + type SignedPurchaseRequest = string; + + type ContextFilter = "NEW_CONTEXT_ONLY" | "INCLUDE_EXISTING_CHALLENGES" | "NEW_PLAYERS_ONLY"; + + type UpdateAction = "CUSTOM" | "LEADERBOARD"; + + type Platform = "IOS" | "ANDROID" | "WEB" | "MOBILE_WEB"; + + type Type = "POST" | "THREAD" | "GROUP" | "SOLO"; + + 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"; } - -declare class Context { - getID(): string; - getType(): Type; - isSizeBetween(minSize: number, maxSize: number): ContextSizeResponse; - switchAsync(id: string): Promise; - chooseAsync(options: ContextOptions): Promise; - createAsync(playerID: string): Promise; - getPlayersAsync(): Promise; -} - -declare class Leaderboard { - getName(): string; - getContextID(): string; - getEntryCountAsync(): Promise; - setScoreAsync(score: number, extraData: string): Promise; - getPlayerEntryAsync(): Promise; - getEntriesAsync(count: number, offset: number): Promise; -} - -declare class LeaderboardEntry { - getScore(): number; - getFormattedScore(): string; - getTimestamp(): number; - getRank(): number; - getExtraData(): string; - getPlayer(): LeaderboardPlayer; -} - -declare class LeaderboardPlayer { - getName(): string; - getPhoto(): string; - getID(): string; -} - -declare class ConnectedPlayer { - getID(): string; - getName(): string; - getPhoto(): string; -} - -declare class SignedPlayerInfo { - getPlayerID(): string; - getSignature(): string; -} - -declare class ContextPlayer { - getID(): string; - getName(): string; - getPhoto(): string; -} - -declare class AdInstance { - getPlacementID(): string; - loadAsync(): Promise; - showAsync(): Promise; -} - -declare class Payments { - purchaseAsync(purchaseConfig: PurchaseConfig): Promise; - getPurchasesAsync(): Promise; - consumePurchaseAsync(purchaseToken: string): Promise; - onReady(callback: () => void): void; -} - -declare interface Product { - title: string; - productID: string; - description?: string; - imageURI?: string; - price: string; - priceCurrencyCode: string; -} - -declare interface ContextSizeResponse { - answer: boolean; - minSize?: number; - maxSize?: number; -} - -declare interface Purchase { - developerPayload?: string; - paymentID: string; - productID: string; - purchaseTime: string; - purchaseToken: string; - signedRequest: SignedPurchaseRequest; -} - -declare interface ContextOptions { - filters?: ContextFilter[]; - maxSize?: number; - minSize?: number; -} - -declare interface SharePayload { - intent?: Intent; - image?: string; - text?: string; - data?: any; -} - -declare interface APIError { - code: ErrorCodeType; - message: string; -} - -declare interface PurchaseConfig { - productID: string; - developerPayload?: string; -} - -declare interface UpdatePayload { - action?: UpdateAction; - template?: string; - cta?: (string | LocalizableContent); - image?: string; - text?: (string | LocalizableContent); - data?: any; - strategy?: string; - notification?: string; -} - -declare interface LeaderboardUpdatePayload { - action: UpdateAction; - name: string; - text?: string; -} - -declare interface LocalizableContent { - default: string; - localizations: LocalizationsDict; -} - -declare interface DataObject { [ key: string ]: string | number; } - -declare interface StatsObject { [ key: string ]: string | number; } - -declare interface IncrementObject { [ key: string ]: number; } - -declare type LocalizationsDict = any; - -declare type SignedPurchaseRequest = string; - -declare type ContextFilter = "NEW_CONTEXT_ONLY" | "INCLUDE_EXISTING_CHALLENGES" | "NEW_PLAYERS_ONLY"; - -declare type UpdateAction = "CUSTOM" | "LEADERBOARD"; - -declare type Platform = "IOS" | "ANDROID" | "WEB" | "MOBILE_WEB"; - -declare type Type = "POST" | "THREAD" | "GROUP" | "SOLO"; - -declare type Intent = "INVITE" | "REQUEST" | "CHALLENGE" | "SHARE"; - -declare 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"; From 6b2795e39eac4c2cd15fe184201d8bbbe2bdb39b Mon Sep 17 00:00:00 2001 From: Menushka Weeratunga Date: Mon, 26 Mar 2018 08:28:03 -0400 Subject: [PATCH 3/6] Made proposed changes --- .../fbinstant-tests.ts | 4 +- .../index.d.ts | 80 +++++++++---------- .../tsconfig.json | 0 types/facebook-instant-games/tslint.json | 1 + types/fbinstant/tslint.json | 8 -- 5 files changed, 41 insertions(+), 52 deletions(-) rename types/{fbinstant => facebook-instant-games}/fbinstant-tests.ts (95%) rename types/{fbinstant => facebook-instant-games}/index.d.ts (76%) rename types/{fbinstant => facebook-instant-games}/tsconfig.json (100%) create mode 100644 types/facebook-instant-games/tslint.json delete mode 100644 types/fbinstant/tslint.json diff --git a/types/fbinstant/fbinstant-tests.ts b/types/facebook-instant-games/fbinstant-tests.ts similarity index 95% rename from types/fbinstant/fbinstant-tests.ts rename to types/facebook-instant-games/fbinstant-tests.ts index f4a72ea70e..8d33e2c970 100644 --- a/types/fbinstant/fbinstant-tests.ts +++ b/types/facebook-instant-games/fbinstant-tests.ts @@ -1,6 +1,4 @@ -declare const FBInstant: FBInstant; - -export class FBInstantTest { +class FBInstantTest { winStreak: number; init() { diff --git a/types/fbinstant/index.d.ts b/types/facebook-instant-games/index.d.ts similarity index 76% rename from types/fbinstant/index.d.ts rename to types/facebook-instant-games/index.d.ts index 9b337bbc5e..4239c134fb 100644 --- a/types/fbinstant/index.d.ts +++ b/types/facebook-instant-games/index.d.ts @@ -1,40 +1,38 @@ -// Type definitions for FBInstant 6.1 +// Type definitions for facebook-instant-games 6.1 // Project: https://developers.facebook.com/docs/games/instant-games // Definitions by: Menushka Weeratunga // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare class FBInstant { - player: FBInstant.Player; - context: FBInstant.Context; - payments: FBInstant.Payments; - - getLocale(): string; - getPlatform(): string; - getSDKVersion(): string; - initializeAsync(): Promise; - setLoadingProgress(progress: number): void; - getSupportedAPIs(): string[]; - getEntryPointData(): any; - getEntryPointAsync(): Promise; - setSessionData(sessionData: any): void; - startGameAsync(): Promise; - shareAsync(payload: FBInstant.SharePayload): Promise; - updateAsync(payload: FBInstant.UpdatePayload): Promise; - switchGameAsync(appID: string, data: string): Promise; - canCreateShortcutAsync(): Promise; - createShortcutAsync(): Promise; - quit(): void; - logEvent(eventName: string, valueToSum?: number, parameter?: any): FBInstant.APIError; - onPause(func: () => void): void; - getInterstitialAdAsync(placementID: string): Promise; - getRewardedVideoAsync(placementID: string): Promise; - matchPlayerAsync(matchTag: string, switchContextWhenMatched?: boolean): Promise; - checkCanPlayerMatchAsync(): Promise; - getLeaderboardAsync(name: string): Promise; -} - declare namespace FBInstant { - class Player { + let player: Player; + let context: Context; + let payments: Payments; + + function getLocale(): string; + function getPlatform(): string; + function getSDKVersion(): string; + function initializeAsync(): Promise; + function setLoadingProgress(progress: number): void; + function getSupportedAPIs(): string[]; + function getEntryPointData(): any; + function getEntryPointAsync(): Promise; + function setSessionData(sessionData: any): void; + function startGameAsync(): Promise; + function shareAsync(payload: SharePayload): Promise; + function updateAsync(payload: UpdatePayload): Promise; + function switchGameAsync(appID: string, data: string): Promise; + function canCreateShortcutAsync(): Promise; + function createShortcutAsync(): Promise; + function quit(): void; + function logEvent(eventName: string, valueToSum?: number, parameter?: any): APIError; + function onPause(func: () => void): void; + function getInterstitialAdAsync(placementID: string): Promise; + function getRewardedVideoAsync(placementID: string): Promise; + function matchPlayerAsync(matchTag: string, switchContextWhenMatched?: boolean): Promise; + function checkCanPlayerMatchAsync(): Promise; + function getLeaderboardAsync(name: string): Promise; + + interface Player { getID(): string; getSignedPlayerInfoAsync(requestPayload: string): Promise; canSubscribeBotAsync(): Promise; @@ -50,7 +48,7 @@ declare namespace FBInstant { getConnectedPlayersAsync(): Promise; } - class Context { + interface Context { getID(): string; getType(): Type; isSizeBetween(minSize: number, maxSize: number): ContextSizeResponse; @@ -60,7 +58,7 @@ declare namespace FBInstant { getPlayersAsync(): Promise; } - class Leaderboard { + interface Leaderboard { getName(): string; getContextID(): string; getEntryCountAsync(): Promise; @@ -69,7 +67,7 @@ declare namespace FBInstant { getEntriesAsync(count: number, offset: number): Promise; } - class LeaderboardEntry { + interface LeaderboardEntry { getScore(): number; getFormattedScore(): string; getTimestamp(): number; @@ -78,36 +76,36 @@ declare namespace FBInstant { getPlayer(): LeaderboardPlayer; } - class LeaderboardPlayer { + interface LeaderboardPlayer { getName(): string; getPhoto(): string; getID(): string; } - class ConnectedPlayer { + interface ConnectedPlayer { getID(): string; getName(): string; getPhoto(): string; } - class SignedPlayerInfo { + interface SignedPlayerInfo { getPlayerID(): string; getSignature(): string; } - class ContextPlayer { + interface ContextPlayer { getID(): string; getName(): string; getPhoto(): string; } - class AdInstance { + interface AdInstance { getPlacementID(): string; loadAsync(): Promise; showAsync(): Promise; } - class Payments { + interface Payments { purchaseAsync(purchaseConfig: PurchaseConfig): Promise; getPurchasesAsync(): Promise; consumePurchaseAsync(purchaseToken: string): Promise; diff --git a/types/fbinstant/tsconfig.json b/types/facebook-instant-games/tsconfig.json similarity index 100% rename from types/fbinstant/tsconfig.json rename to types/facebook-instant-games/tsconfig.json diff --git a/types/facebook-instant-games/tslint.json b/types/facebook-instant-games/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/facebook-instant-games/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/fbinstant/tslint.json b/types/fbinstant/tslint.json deleted file mode 100644 index 71918edac3..0000000000 --- a/types/fbinstant/tslint.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - // Needs to be declares as it cannot be imported in typescript - // using the standard import statement - "strict-export-declare-modifiers": false - } -} From 7b6d712a235710822a0c1f15be2e36cee7fc53c5 Mon Sep 17 00:00:00 2001 From: Menushka Weeratunga Date: Mon, 26 Mar 2018 09:38:39 -0400 Subject: [PATCH 4/6] Renamed test file --- .../{fbinstant-tests.ts => facebook-instant-games-tests.ts} | 0 types/facebook-instant-games/tsconfig.json | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename types/facebook-instant-games/{fbinstant-tests.ts => facebook-instant-games-tests.ts} (100%) diff --git a/types/facebook-instant-games/fbinstant-tests.ts b/types/facebook-instant-games/facebook-instant-games-tests.ts similarity index 100% rename from types/facebook-instant-games/fbinstant-tests.ts rename to types/facebook-instant-games/facebook-instant-games-tests.ts diff --git a/types/facebook-instant-games/tsconfig.json b/types/facebook-instant-games/tsconfig.json index 7cb5ffc8ae..5f1b7e6ccd 100644 --- a/types/facebook-instant-games/tsconfig.json +++ b/types/facebook-instant-games/tsconfig.json @@ -18,6 +18,6 @@ }, "files": [ "index.d.ts", - "fbinstant-tests.ts" + "facebook-instant-games-tests.ts" ] } From b1b96d8190db1382f29db9593da1a494010bfe2e Mon Sep 17 00:00:00 2001 From: Menushka Weeratunga Date: Mon, 26 Mar 2018 10:32:39 -0400 Subject: [PATCH 5/6] Added missing optional tags --- types/facebook-instant-games/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/facebook-instant-games/index.d.ts b/types/facebook-instant-games/index.d.ts index 4239c134fb..82ea96e1f6 100644 --- a/types/facebook-instant-games/index.d.ts +++ b/types/facebook-instant-games/index.d.ts @@ -20,7 +20,7 @@ declare namespace FBInstant { function startGameAsync(): Promise; function shareAsync(payload: SharePayload): Promise; function updateAsync(payload: UpdatePayload): Promise; - function switchGameAsync(appID: string, data: string): Promise; + function switchGameAsync(appID: string, data?: string): Promise; function canCreateShortcutAsync(): Promise; function createShortcutAsync(): Promise; function quit(): void; @@ -28,7 +28,7 @@ declare namespace FBInstant { function onPause(func: () => void): void; function getInterstitialAdAsync(placementID: string): Promise; function getRewardedVideoAsync(placementID: string): Promise; - function matchPlayerAsync(matchTag: string, switchContextWhenMatched?: boolean): Promise; + function matchPlayerAsync(matchTag?: string, switchContextWhenMatched?: boolean): Promise; function checkCanPlayerMatchAsync(): Promise; function getLeaderboardAsync(name: string): Promise; @@ -39,10 +39,10 @@ declare namespace FBInstant { subscribeBotAsync(): Promise; getName(): string; getPhoto(): string; - getDataAsync(keys: string[]): Promise; + getDataAsync(keys?: string[]): Promise; setDataAsync(data: DataObject): Promise; flushDataAsync(): Promise; - getStatsAsync(keys: string[]): Promise; + getStatsAsync(keys?: string[]): Promise; setStatsAsync(stats: StatsObject): Promise; incrementStatsAsync(increments: IncrementObject): Promise; getConnectedPlayersAsync(): Promise; From 4f8a5c46b7e003f5a694c4817f23c0c50f897e0a Mon Sep 17 00:00:00 2001 From: Menushka Weeratunga Date: Mon, 26 Mar 2018 11:46:11 -0400 Subject: [PATCH 6/6] Minor fixes --- types/facebook-instant-games/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/facebook-instant-games/index.d.ts b/types/facebook-instant-games/index.d.ts index 82ea96e1f6..1e8a8d76fd 100644 --- a/types/facebook-instant-games/index.d.ts +++ b/types/facebook-instant-games/index.d.ts @@ -19,7 +19,7 @@ declare namespace FBInstant { function setSessionData(sessionData: any): void; function startGameAsync(): Promise; function shareAsync(payload: SharePayload): Promise; - function updateAsync(payload: UpdatePayload): Promise; + function updateAsync(payload: UpdatePayload | LeaderboardUpdatePayload): Promise; function switchGameAsync(appID: string, data?: string): Promise; function canCreateShortcutAsync(): Promise; function createShortcutAsync(): Promise; @@ -183,7 +183,7 @@ declare namespace FBInstant { interface DataObject { [ key: string ]: string | number; } - interface StatsObject { [ key: string ]: string | number; } + interface StatsObject { [ key: string ]: number; } interface IncrementObject { [ key: string ]: number; }