diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a4578d..fcae9a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,25 @@ The format is based on [keep a changelog](http://keepachangelog.com/) and this p ### Unreleased +### [2.8.0] +### Added +- Nakama: Added ability to invoke `listFriendsOfFriends` on the client which returns a list of friends of the user's friends. +- Nakama: Added a `rank_count` to `LeaderboardRecordList`. +- Nakama: Added ability to invoke `listSubscriptions` on the client which lists all the user's validated subscriptions. +- Nakama: Added ability to invoke `getSubscription` on the client which gets a subscription by product ID. +- Nakama: Added ability to invoke `deleteAccount` on the client which deletes the user's account. +- Nakama: Added ability to invoke `validatePurchaseFacebookInstant` on the client which validates a FB Instant IAP receipt. +- Nakama: Added ability to invoke `deleteTournamentRecord` on the client which deletes a tournament record. +- Nakama: Added ability to invoke `validateSubscriptionApple` and `validateSubscriptionGoogle` on the client which validates Apple and Google subscription receipts. +- Nakama: Added `cursor` parameter to `listTournamentRecordsAroundOwner` and `listLeaderboardRecordsAroundOwner`. +- Nakama: Added `authoritative` field to `Tournament`. +- Nakama: Added ability to specify whether to `persist` purchases and subscriptions when validating their receipts. +- Nakama: Added `create_time` and `update_time` to `ApiStorageObjectAck`. +- Nakama: Added `refund_time`, `update_time` and `user_id` to `ApiValidatedPurchase`. + +### Changed +- Nakama: Changed `StreamId.descriptor` to `StreamId.subcontext`. + ### [2.7.0] ### Added - Satori: Added ability to schedule, update and delete outgoing messages for Live Events. diff --git a/openapi-gen/main.go b/openapi-gen/main.go index 27c6639..023c200 100644 --- a/openapi-gen/main.go +++ b/openapi-gen/main.go @@ -50,7 +50,7 @@ export enum {{ $classname | title }} export interface {{$classname | title}} { {{- range $key, $property := $definition.Properties}} {{- $fieldname := camelToSnake $key }} - // {{- replace $property.Description "\n" " "}} + // {{ replace $property.Description "\n" " "}} {{- if eq $property.Type "integer"}} {{$fieldname}}?: number; {{- else if eq $property.Type "number" }} diff --git a/packages/nakama-js/api.gen.ts b/packages/nakama-js/api.gen.ts index b70939c..4b22596 100644 --- a/packages/nakama-js/api.gen.ts +++ b/packages/nakama-js/api.gen.ts @@ -4,6 +4,14 @@ import { buildFetchOptions } from './utils'; import { encode } from 'js-base64'; +/** A friend of a friend. */ +export interface FriendsOfFriendsListFriendOfFriend { + // The user who referred its friend. + referrer?: string; + // User. + user?: ApiUser; +} + /** A single user-role pair. */ export interface GroupUserListGroupUser { // Their relationship to the group. @@ -20,32 +28,6 @@ export interface UserGroupListUserGroup { state?: number; } -/** -* Environment where the purchase took place -*/ -export enum ValidatedPurchaseEnvironment -{ - /* - UNKNOWN: Unknown environment. */ - UNKNOWN = 0, - /* - SANDBOX: Sandbox/test environment. */ - SANDBOX = 1, - /* - PRODUCTION: Production environment. */ - PRODUCTION = 2, -} - -/** -* Validation Provider -*/ -export enum ValidatedPurchaseStore -{ - /* - APPLE_APP_STORE: Apple App Store */ - APPLE_APP_STORE = 0, - /* - GOOGLE_PLAY_STORE: Google Play Store */ - GOOGLE_PLAY_STORE = 1, - /* - HUAWEI_APP_GALLERY: Huawei App Gallery */ - HUAWEI_APP_GALLERY = 2, -} - /** Record values to write. */ export interface WriteLeaderboardRecordRequestLeaderboardRecordWrite { // Optional record metadata. @@ -76,13 +58,13 @@ export interface ApiAccount { custom_id?: string; // The devices which belong to the user's account. devices?: Array; - // The UNIX time when the user's account was disabled/banned. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the user's account was disabled/banned. disable_time?: string; // The email address of the user. email?: string; // The user object. user?: ApiUser; - // The UNIX time when the user's email was verified. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the user's email was verified. verify_time?: string; // The user's wallet data. wallet?: string; @@ -116,7 +98,7 @@ export interface ApiAccountDevice { export interface ApiAccountEmail { // A valid RFC-5322 email address. email?: string; - // A password for the user account. + // A password for the user account. Ignored with unlink operations. password?: string; // Extra information that will be bundled in the session token. vars?: Record; @@ -132,13 +114,15 @@ export interface ApiAccountFacebook { /** Send a Facebook Instant Game token to the server. Used with authenticate/link/unlink. */ export interface ApiAccountFacebookInstantGame { - // + // signed_player_info?: string; // Extra information that will be bundled in the session token. vars?: Record; } -/** Send Apple's Game Center account credentials to the server. Used with authenticate/link/unlink. */ +/** Send Apple's Game Center account credentials to the server. Used with authenticate/link/unlink. + +https://developer.apple.com/documentation/gamekit/gklocalplayer/1515407-generateidentityverificationsign */ export interface ApiAccountGameCenter { // Bundle ID (generated by GameCenter). bundle_id?: string; @@ -180,7 +164,7 @@ export interface ApiChannelMessage { code?: number; // The content payload. content?: string; - // The UNIX time when the message was created. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the message was created. create_time?: string; // The ID of the group, or an empty string if this message was not sent through a group channel. group_id?: string; @@ -192,7 +176,7 @@ export interface ApiChannelMessage { room_name?: string; // Message sender, usually a user ID. sender_id?: string; - // The UNIX time when the message was last updated. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the message was last updated. update_time?: string; // The ID of the first DM user, or an empty string if this message was not sent through a DM chat. user_id_one?: string; @@ -260,7 +244,7 @@ export interface ApiEvent { /** A friend of a user. */ export interface ApiFriend { - // The friend status. + // The friend status. one of "Friend.State". state?: number; // Time of the latest relationship update. update_time?: string; @@ -276,11 +260,19 @@ export interface ApiFriendList { friends?: Array; } +/** */ +export interface ApiFriendsOfFriendsList { + // Cursor for the next page of results, if any. + cursor?: string; + // User friends of friends. + friends_of_friends?: Array; +} + /** A group in the server. */ export interface ApiGroup { // A URL for an avatar image. avatar_url?: string; - // The UNIX time when the group was created. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the group was created. create_time?: string; // The id of the user who created the group. creator_id?: string; @@ -300,7 +292,7 @@ export interface ApiGroup { name?: string; // Anyone can join open groups, otherwise only admins can accept members. open?: boolean; - // The UNIX time when the group was last updated. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the group was last updated. update_time?: string; } @@ -322,9 +314,9 @@ export interface ApiGroupUserList { /** Represents a complete leaderboard record with all scores and associated metadata. */ export interface ApiLeaderboardRecord { - // The UNIX time when the leaderboard record was created. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the leaderboard record was created. create_time?: string; - // The UNIX time when the leaderboard record expires. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the leaderboard record expires. expiry_time?: string; // The ID of the leaderboard this score belongs to. leaderboard_id?: string; @@ -342,7 +334,7 @@ export interface ApiLeaderboardRecord { score?: string; // An optional subscore value. subscore?: string; - // The UNIX time when the leaderboard record was updated. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the leaderboard record was updated. update_time?: string; // The username of the score owner, if the owner is a user. username?: string; @@ -356,6 +348,8 @@ export interface ApiLeaderboardRecordList { owner_records?: Array; // The cursor to send when retrieving the previous page, if any. prev_cursor?: string; + // The total number of ranks available. + rank_count?: string; // A list of leaderboard records. records?: Array; } @@ -368,11 +362,19 @@ export interface ApiLinkSteamRequest { sync?: boolean; } +/** List user subscriptions. */ +export interface ApiListSubscriptionsRequest { + // + cursor?: string; + // + limit?: number; +} + /** Represents a realtime match. */ export interface ApiMatch { // True if it's an server-managed authoritative match, false otherwise. authoritative?: boolean; - // + // handler_name?: string; // Match label, if any. label?: string; @@ -380,7 +382,7 @@ export interface ApiMatch { match_id?: string; // Current number of users in the match. size?: number; - // + // tick_rate?: number; } @@ -396,7 +398,7 @@ export interface ApiNotification { code?: number; // Content of the notification in JSON. content?: string; - // The UNIX time when the notification was created. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the notification was created. create_time?: string; // ID of the Notification. id?: string; @@ -489,7 +491,7 @@ export interface ApiSessionRefreshRequest { export interface ApiStorageObject { // The collection which stores the object. collection?: string; - // The UNIX time when the object was created. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the object was created. create_time?: string; // The key of the object within the collection. key?: string; @@ -497,7 +499,7 @@ export interface ApiStorageObject { permission_read?: number; // The write access permissions for the object. permission_write?: number; - // The UNIX time when the object was last updated. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the object was last updated. update_time?: string; // The user owner of the object. user_id?: string; @@ -511,8 +513,12 @@ export interface ApiStorageObject { export interface ApiStorageObjectAck { // The collection which stores the object. collection?: string; + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the object was created. + create_time?: string; // The key of the object within the collection. key?: string; + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the object was last updated. + update_time?: string; // The owner of the object. user_id?: string; // The version hash of the object. @@ -539,13 +545,53 @@ export interface ApiStorageObjects { objects?: Array; } +/** +* Environment where a purchase/subscription took place, +*/ +export enum ApiStoreEnvironment +{ + /* - UNKNOWN: Unknown environment. */ + UNKNOWN = 0, + /* - SANDBOX: Sandbox/test environment. */ + SANDBOX = 1, + /* - PRODUCTION: Production environment. */ + PRODUCTION = 2, +} + +/** +* Validation Provider, +*/ +export enum ApiStoreProvider +{ + /* - APPLE_APP_STORE: Apple App Store */ + APPLE_APP_STORE = 0, + /* - GOOGLE_PLAY_STORE: Google Play Store */ + GOOGLE_PLAY_STORE = 1, + /* - HUAWEI_APP_GALLERY: Huawei App Gallery */ + HUAWEI_APP_GALLERY = 2, + /* - FACEBOOK_INSTANT_STORE: Facebook Instant Store */ + FACEBOOK_INSTANT_STORE = 3, +} + +/** A list of validated subscriptions stored by Nakama. */ +export interface ApiSubscriptionList { + // The cursor to send when retrieving the next page, if any. + cursor?: string; + // The cursor to send when retrieving the previous page, if any. + prev_cursor?: string; + // Stored validated subscriptions. + validated_subscriptions?: Array; +} + /** A tournament on the server. */ export interface ApiTournament { + // Whether the leaderboard was created authoritatively or not. + authoritative?: boolean; // True if the tournament is active and can enter. A computed value. can_enter?: boolean; // The category of the tournament. e.g. "vip" could be category 1. category?: number; - // The UNIX time when the tournament was created. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the tournament was created. create_time?: string; // The description of the tournament. May be blank. description?: string; @@ -553,7 +599,7 @@ export interface ApiTournament { duration?: number; // The UNIX time when the tournament stops being active until next reset. A computed value. end_active?: number; - // The UNIX time when the tournament will be stopped. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the tournament will be stopped. end_time?: string; // The ID of the tournament. id?: string; @@ -575,7 +621,7 @@ export interface ApiTournament { sort_order?: number; // The UNIX time when the tournament start being active. A computed value. start_active?: number; - // The UNIX time when the tournament will start. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the tournament will start. start_time?: string; // The title for the tournament. title?: string; @@ -597,6 +643,8 @@ export interface ApiTournamentRecordList { owner_records?: Array; // The cursor to send when retrieving the previous page (optional). prev_cursor?: string; + // The total number of ranks available. + rank_count?: string; // A list of tournament records. records?: Array; } @@ -639,7 +687,7 @@ export interface ApiUser { apple_id?: string; // A URL for an avatar image. avatar_url?: string; - // The UNIX time when the user was created. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the user was created. create_time?: string; // The display name of the user. display_name?: string; @@ -667,7 +715,7 @@ export interface ApiUser { steam_id?: string; // The timezone set by the user. timezone?: string; - // The UNIX time when the user was last updated. + // The UNIX time (for gRPC clients) or ISO string (for REST clients) when the user was last updated. update_time?: string; // The username of the user's account. username?: string; @@ -689,50 +737,120 @@ export interface ApiUsers { /** */ export interface ApiValidatePurchaseAppleRequest { + // + persist?: boolean; // Base64 encoded Apple receipt data payload. receipt?: string; } +/** */ +export interface ApiValidatePurchaseFacebookInstantRequest { + // + persist?: boolean; + // Base64 encoded Facebook Instant signedRequest receipt data payload. + signed_request?: string; +} + /** */ export interface ApiValidatePurchaseGoogleRequest { + // + persist?: boolean; // JSON encoded Google purchase payload. purchase?: string; } /** */ export interface ApiValidatePurchaseHuaweiRequest { + // + persist?: boolean; // JSON encoded Huawei InAppPurchaseData. purchase?: string; // InAppPurchaseData signature. signature?: string; } -/** */ +/** Validate IAP response. */ export interface ApiValidatePurchaseResponse { // Newly seen validated purchases. validated_purchases?: Array; } +/** */ +export interface ApiValidateSubscriptionAppleRequest { + // Persist the subscription. + persist?: boolean; + // Base64 encoded Apple receipt data payload. + receipt?: string; +} + +/** */ +export interface ApiValidateSubscriptionGoogleRequest { + // Persist the subscription. + persist?: boolean; + // JSON encoded Google purchase payload. + receipt?: string; +} + +/** Validate Subscription response. */ +export interface ApiValidateSubscriptionResponse { + // + validated_subscription?: ApiValidatedSubscription; +} + /** Validated Purchase stored by Nakama. */ export interface ApiValidatedPurchase { - // UNIX Timestamp when the receipt validation was stored in DB. + // Timestamp when the receipt validation was stored in DB. create_time?: string; // Whether the purchase was done in production or sandbox environment. - environment?: ValidatedPurchaseEnvironment; + environment?: ApiStoreEnvironment; // Purchase Product ID. product_id?: string; // Raw provider validation response. provider_response?: string; - // UNIX Timestamp when the purchase was done. + // Timestamp when the purchase was done. purchase_time?: string; + // + refund_time?: string; // Whether the purchase had already been validated by Nakama before. seen_before?: boolean; - // - store?: ValidatedPurchaseStore; + // + store?: ApiStoreProvider; // Purchase Transaction ID. transaction_id?: string; + // Timestamp when the receipt validation was updated in DB. + update_time?: string; + // Purchase User ID. + user_id?: string; +} + +/** */ +export interface ApiValidatedSubscription { + // Whether the subscription is currently active or not. + active?: boolean; + // UNIX Timestamp when the receipt validation was stored in DB. + create_time?: string; + // Whether the purchase was done in production or sandbox environment. + environment?: ApiStoreEnvironment; + // Subscription expiration time. The subscription can still be auto-renewed to extend the expiration time further. + expiry_time?: string; + // Purchase Original transaction ID (we only keep track of the original subscription, not subsequent renewals). + original_transaction_id?: string; + // Purchase Product ID. + product_id?: string; + // Raw provider notification body. + provider_notification?: string; + // Raw provider validation response body. + provider_response?: string; + // UNIX Timestamp when the purchase was done. + purchase_time?: string; + // Subscription refund time. If this time is set, the subscription was refunded. + refund_time?: string; + // + store?: ApiStoreProvider; // UNIX Timestamp when the receipt validation was updated in DB. update_time?: string; + // Subscription User ID. + user_id?: string; } /** The object to store. */ @@ -747,7 +865,7 @@ export interface ApiWriteStorageObject { permission_write?: number; // The value of the object. value?: string; - // The version hash of the object to check. Possible values are: ["", "*", "#hash#"]. + // The version hash of the object to check. Possible values are: ["", "*", "#hash#"]. if-match and if-none-match version?: string; } @@ -757,24 +875,6 @@ export interface ApiWriteStorageObjectsRequest { objects?: Array; } -/** */ -export interface ProtobufAny { - // - type_url?: string; - // - value?: string; -} - -/** */ -export interface RpcStatus { - // - code?: number; - // - details?: Array; - // - message?: string; -} - export class NakamaApi { constructor(readonly serverKey: string, readonly basePath: string, readonly timeoutMs: number) {} @@ -782,7 +882,7 @@ export class NakamaApi { /** A healthcheck which load balancers can use to check the service. */ healthcheck(bearerToken: string, options: any = {}): Promise { - + const urlPath = "/healthcheck"; const queryParams = new Map(); @@ -810,10 +910,41 @@ export class NakamaApi { ]); } + /** Delete the current user's account. */ + deleteAccount(bearerToken: string, + options: any = {}): Promise { + + const urlPath = "/v2/account"; + const queryParams = new Map(); + + let bodyJson : string = ""; + + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("DELETE", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise((_, reject) => + setTimeout(reject, this.timeoutMs, "Request timed out.") + ), + ]); +} + /** Fetch the current user's account. */ getAccount(bearerToken: string, options: any = {}): Promise { - + const urlPath = "/v2/account"; const queryParams = new Map(); @@ -845,7 +976,7 @@ export class NakamaApi { updateAccount(bearerToken: string, body:ApiUpdateAccountRequest, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -880,13 +1011,13 @@ export class NakamaApi { /** Authenticate a user with an Apple ID against the server. */ authenticateApple(basicAuthUsername: string, basicAuthPassword: string, - body:ApiAccountApple, + account:ApiAccountApple, create?:boolean, username?:string, options: any = {}): Promise { - - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/apple"; const queryParams = new Map(); @@ -894,11 +1025,13 @@ export class NakamaApi { queryParams.set("username", username); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { @@ -919,13 +1052,13 @@ export class NakamaApi { /** Authenticate a user with a custom id against the server. */ authenticateCustom(basicAuthUsername: string, basicAuthPassword: string, - body:ApiAccountCustom, + account:ApiAccountCustom, create?:boolean, username?:string, options: any = {}): Promise { - - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/custom"; const queryParams = new Map(); @@ -933,11 +1066,13 @@ export class NakamaApi { queryParams.set("username", username); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { @@ -958,13 +1093,13 @@ export class NakamaApi { /** Authenticate a user with a device id against the server. */ authenticateDevice(basicAuthUsername: string, basicAuthPassword: string, - body:ApiAccountDevice, + account:ApiAccountDevice, create?:boolean, username?:string, options: any = {}): Promise { - - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/device"; const queryParams = new Map(); @@ -972,11 +1107,13 @@ export class NakamaApi { queryParams.set("username", username); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { @@ -997,13 +1134,13 @@ export class NakamaApi { /** Authenticate a user with an email+password against the server. */ authenticateEmail(basicAuthUsername: string, basicAuthPassword: string, - body:ApiAccountEmail, + account:ApiAccountEmail, create?:boolean, username?:string, options: any = {}): Promise { - - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/email"; const queryParams = new Map(); @@ -1011,11 +1148,13 @@ export class NakamaApi { queryParams.set("username", username); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { @@ -1036,14 +1175,14 @@ export class NakamaApi { /** Authenticate a user with a Facebook OAuth token against the server. */ authenticateFacebook(basicAuthUsername: string, basicAuthPassword: string, - body:ApiAccountFacebook, + account:ApiAccountFacebook, create?:boolean, username?:string, sync?:boolean, options: any = {}): Promise { - - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/facebook"; const queryParams = new Map(); @@ -1052,11 +1191,13 @@ export class NakamaApi { queryParams.set("sync", sync); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { @@ -1077,13 +1218,13 @@ export class NakamaApi { /** Authenticate a user with a Facebook Instant Game token against the server. */ authenticateFacebookInstantGame(basicAuthUsername: string, basicAuthPassword: string, - body:ApiAccountFacebookInstantGame, + account:ApiAccountFacebookInstantGame, create?:boolean, username?:string, options: any = {}): Promise { - - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/facebookinstantgame"; const queryParams = new Map(); @@ -1091,11 +1232,13 @@ export class NakamaApi { queryParams.set("username", username); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { @@ -1116,13 +1259,13 @@ export class NakamaApi { /** Authenticate a user with Apple's GameCenter against the server. */ authenticateGameCenter(basicAuthUsername: string, basicAuthPassword: string, - body:ApiAccountGameCenter, + account:ApiAccountGameCenter, create?:boolean, username?:string, options: any = {}): Promise { - - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/gamecenter"; const queryParams = new Map(); @@ -1130,11 +1273,13 @@ export class NakamaApi { queryParams.set("username", username); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { @@ -1155,13 +1300,13 @@ export class NakamaApi { /** Authenticate a user with Google against the server. */ authenticateGoogle(basicAuthUsername: string, basicAuthPassword: string, - body:ApiAccountGoogle, + account:ApiAccountGoogle, create?:boolean, username?:string, options: any = {}): Promise { - - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/google"; const queryParams = new Map(); @@ -1169,11 +1314,13 @@ export class NakamaApi { queryParams.set("username", username); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { @@ -1194,14 +1341,14 @@ export class NakamaApi { /** Authenticate a user with Steam against the server. */ authenticateSteam(basicAuthUsername: string, basicAuthPassword: string, - body:ApiAccountSteam, + account:ApiAccountSteam, create?:boolean, username?:string, sync?:boolean, options: any = {}): Promise { - - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/steam"; const queryParams = new Map(); @@ -1210,11 +1357,13 @@ export class NakamaApi { queryParams.set("sync", sync); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { @@ -1236,7 +1385,7 @@ export class NakamaApi { linkApple(bearerToken: string, body:ApiAccountApple, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1272,7 +1421,7 @@ export class NakamaApi { linkCustom(bearerToken: string, body:ApiAccountCustom, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1308,7 +1457,7 @@ export class NakamaApi { linkDevice(bearerToken: string, body:ApiAccountDevice, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1344,7 +1493,7 @@ export class NakamaApi { linkEmail(bearerToken: string, body:ApiAccountEmail, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1378,19 +1527,19 @@ export class NakamaApi { /** Add Facebook to the social profiles on the current user's account. */ linkFacebook(bearerToken: string, - body:ApiAccountFacebook, + account:ApiAccountFacebook, sync?:boolean, options: any = {}): Promise { - - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/link/facebook"; const queryParams = new Map(); queryParams.set("sync", sync); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); @@ -1418,7 +1567,7 @@ export class NakamaApi { linkFacebookInstantGame(bearerToken: string, body:ApiAccountFacebookInstantGame, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1454,7 +1603,7 @@ export class NakamaApi { linkGameCenter(bearerToken: string, body:ApiAccountGameCenter, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1490,7 +1639,7 @@ export class NakamaApi { linkGoogle(bearerToken: string, body:ApiAccountGoogle, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1526,7 +1675,7 @@ export class NakamaApi { linkSteam(bearerToken: string, body:ApiLinkSteamRequest, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1563,7 +1712,7 @@ export class NakamaApi { basicAuthPassword: string, body:ApiSessionRefreshRequest, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1575,7 +1724,9 @@ export class NakamaApi { const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { @@ -1597,7 +1748,7 @@ export class NakamaApi { unlinkApple(bearerToken: string, body:ApiAccountApple, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1633,7 +1784,7 @@ export class NakamaApi { unlinkCustom(bearerToken: string, body:ApiAccountCustom, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1669,7 +1820,7 @@ export class NakamaApi { unlinkDevice(bearerToken: string, body:ApiAccountDevice, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1705,7 +1856,7 @@ export class NakamaApi { unlinkEmail(bearerToken: string, body:ApiAccountEmail, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1741,7 +1892,7 @@ export class NakamaApi { unlinkFacebook(bearerToken: string, body:ApiAccountFacebook, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1777,7 +1928,7 @@ export class NakamaApi { unlinkFacebookInstantGame(bearerToken: string, body:ApiAccountFacebookInstantGame, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1813,7 +1964,7 @@ export class NakamaApi { unlinkGameCenter(bearerToken: string, body:ApiAccountGameCenter, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1849,7 +2000,7 @@ export class NakamaApi { unlinkGoogle(bearerToken: string, body:ApiAccountGoogle, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1885,7 +2036,7 @@ export class NakamaApi { unlinkSteam(bearerToken: string, body:ApiAccountSteam, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -1924,7 +2075,7 @@ export class NakamaApi { forward?:boolean, cursor?:string, options: any = {}): Promise { - + if (channelId === null || channelId === undefined) { throw new Error("'channelId' is a required parameter but is null or undefined."); } @@ -1963,7 +2114,7 @@ export class NakamaApi { event(bearerToken: string, body:ApiEvent, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -2000,7 +2151,7 @@ export class NakamaApi { ids?:Array, usernames?:Array, options: any = {}): Promise { - + const urlPath = "/v2/friend"; const queryParams = new Map(); queryParams.set("ids", ids); @@ -2036,7 +2187,7 @@ export class NakamaApi { state?:number, cursor?:string, options: any = {}): Promise { - + const urlPath = "/v2/friend"; const queryParams = new Map(); queryParams.set("limit", limit); @@ -2072,7 +2223,7 @@ export class NakamaApi { ids?:Array, usernames?:Array, options: any = {}): Promise { - + const urlPath = "/v2/friend"; const queryParams = new Map(); queryParams.set("ids", ids); @@ -2107,7 +2258,7 @@ export class NakamaApi { ids?:Array, usernames?:Array, options: any = {}): Promise { - + const urlPath = "/v2/friend/block"; const queryParams = new Map(); queryParams.set("ids", ids); @@ -2139,19 +2290,19 @@ export class NakamaApi { /** Import Facebook friends and add them to a user's account. */ importFacebookFriends(bearerToken: string, - body:ApiAccountFacebook, + account:ApiAccountFacebook, reset?:boolean, options: any = {}): Promise { - - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/friend/facebook"; const queryParams = new Map(); queryParams.set("reset", reset); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); @@ -2175,21 +2326,56 @@ export class NakamaApi { ]); } + /** List friends of friends for the current user. */ + listFriendsOfFriends(bearerToken: string, + limit?:number, + cursor?:string, + options: any = {}): Promise { + + const urlPath = "/v2/friend/friends"; + const queryParams = new Map(); + queryParams.set("limit", limit); + queryParams.set("cursor", cursor); + + let bodyJson : string = ""; + + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("GET", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise((_, reject) => + setTimeout(reject, this.timeoutMs, "Request timed out.") + ), + ]); +} + /** Import Steam friends and add them to a user's account. */ importSteamFriends(bearerToken: string, - body:ApiAccountSteam, + account:ApiAccountSteam, reset?:boolean, options: any = {}): Promise { - - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/friend/steam"; const queryParams = new Map(); queryParams.set("reset", reset); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); @@ -2222,7 +2408,7 @@ export class NakamaApi { members?:number, open?:boolean, options: any = {}): Promise { - + const urlPath = "/v2/group"; const queryParams = new Map(); queryParams.set("name", name); @@ -2260,7 +2446,7 @@ export class NakamaApi { createGroup(bearerToken: string, body:ApiCreateGroupRequest, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -2296,7 +2482,7 @@ export class NakamaApi { deleteGroup(bearerToken: string, groupId:string, options: any = {}): Promise { - + if (groupId === null || groupId === undefined) { throw new Error("'groupId' is a required parameter but is null or undefined."); } @@ -2333,7 +2519,7 @@ export class NakamaApi { groupId:string, body:ApiUpdateGroupRequest, options: any = {}): Promise { - + if (groupId === null || groupId === undefined) { throw new Error("'groupId' is a required parameter but is null or undefined."); } @@ -2374,7 +2560,7 @@ export class NakamaApi { groupId:string, userIds?:Array, options: any = {}): Promise { - + if (groupId === null || groupId === undefined) { throw new Error("'groupId' is a required parameter but is null or undefined."); } @@ -2412,7 +2598,7 @@ export class NakamaApi { groupId:string, userIds?:Array, options: any = {}): Promise { - + if (groupId === null || groupId === undefined) { throw new Error("'groupId' is a required parameter but is null or undefined."); } @@ -2448,15 +2634,12 @@ export class NakamaApi { /** Demote a set of users in a group to the next role down. */ demoteGroupUsers(bearerToken: string, groupId:string, - userIds:Array, + userIds?:Array, options: any = {}): Promise { - + if (groupId === null || groupId === undefined) { throw new Error("'groupId' is a required parameter but is null or undefined."); } - if (userIds === null || userIds === undefined) { - throw new Error("'userIds' is a required parameter but is null or undefined."); - } const urlPath = "/v2/group/{groupId}/demote" .replace("{groupId}", encodeURIComponent(String(groupId))); const queryParams = new Map(); @@ -2490,7 +2673,7 @@ export class NakamaApi { joinGroup(bearerToken: string, groupId:string, options: any = {}): Promise { - + if (groupId === null || groupId === undefined) { throw new Error("'groupId' is a required parameter but is null or undefined."); } @@ -2527,7 +2710,7 @@ export class NakamaApi { groupId:string, userIds?:Array, options: any = {}): Promise { - + if (groupId === null || groupId === undefined) { throw new Error("'groupId' is a required parameter but is null or undefined."); } @@ -2564,7 +2747,7 @@ export class NakamaApi { leaveGroup(bearerToken: string, groupId:string, options: any = {}): Promise { - + if (groupId === null || groupId === undefined) { throw new Error("'groupId' is a required parameter but is null or undefined."); } @@ -2601,7 +2784,7 @@ export class NakamaApi { groupId:string, userIds?:Array, options: any = {}): Promise { - + if (groupId === null || groupId === undefined) { throw new Error("'groupId' is a required parameter but is null or undefined."); } @@ -2641,7 +2824,7 @@ export class NakamaApi { state?:number, cursor?:string, options: any = {}): Promise { - + if (groupId === null || groupId === undefined) { throw new Error("'groupId' is a required parameter but is null or undefined."); } @@ -2680,7 +2863,7 @@ export class NakamaApi { validatePurchaseApple(bearerToken: string, body:ApiValidatePurchaseAppleRequest, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -2712,11 +2895,47 @@ export class NakamaApi { ]); } + /** Validate FB Instant IAP Receipt */ + validatePurchaseFacebookInstant(bearerToken: string, + body:ApiValidatePurchaseFacebookInstantRequest, + options: any = {}): Promise { + + if (body === null || body === undefined) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/purchase/facebookinstant"; + const queryParams = new Map(); + + let bodyJson : string = ""; + bodyJson = JSON.stringify(body || {}); + + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise((_, reject) => + setTimeout(reject, this.timeoutMs, "Request timed out.") + ), + ]); +} + /** Validate Google IAP Receipt */ validatePurchaseGoogle(bearerToken: string, body:ApiValidatePurchaseGoogleRequest, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -2752,7 +2971,7 @@ export class NakamaApi { validatePurchaseHuawei(bearerToken: string, body:ApiValidatePurchaseHuaweiRequest, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -2784,11 +3003,155 @@ export class NakamaApi { ]); } + /** List user's subscriptions. */ + listSubscriptions(bearerToken: string, + body:ApiListSubscriptionsRequest, + options: any = {}): Promise { + + if (body === null || body === undefined) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription"; + const queryParams = new Map(); + + let bodyJson : string = ""; + bodyJson = JSON.stringify(body || {}); + + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise((_, reject) => + setTimeout(reject, this.timeoutMs, "Request timed out.") + ), + ]); +} + + /** Validate Apple Subscription Receipt */ + validateSubscriptionApple(bearerToken: string, + body:ApiValidateSubscriptionAppleRequest, + options: any = {}): Promise { + + if (body === null || body === undefined) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription/apple"; + const queryParams = new Map(); + + let bodyJson : string = ""; + bodyJson = JSON.stringify(body || {}); + + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise((_, reject) => + setTimeout(reject, this.timeoutMs, "Request timed out.") + ), + ]); +} + + /** Validate Google Subscription Receipt */ + validateSubscriptionGoogle(bearerToken: string, + body:ApiValidateSubscriptionGoogleRequest, + options: any = {}): Promise { + + if (body === null || body === undefined) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription/google"; + const queryParams = new Map(); + + let bodyJson : string = ""; + bodyJson = JSON.stringify(body || {}); + + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise((_, reject) => + setTimeout(reject, this.timeoutMs, "Request timed out.") + ), + ]); +} + + /** Get subscription by product id. */ + getSubscription(bearerToken: string, + productId:string, + options: any = {}): Promise { + + if (productId === null || productId === undefined) { + throw new Error("'productId' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription/{productId}" + .replace("{productId}", encodeURIComponent(String(productId))); + const queryParams = new Map(); + + let bodyJson : string = ""; + + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("GET", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise((_, reject) => + setTimeout(reject, this.timeoutMs, "Request timed out.") + ), + ]); +} + /** Delete a leaderboard record. */ deleteLeaderboardRecord(bearerToken: string, leaderboardId:string, options: any = {}): Promise { - + if (leaderboardId === null || leaderboardId === undefined) { throw new Error("'leaderboardId' is a required parameter but is null or undefined."); } @@ -2828,7 +3191,7 @@ export class NakamaApi { cursor?:string, expiry?:string, options: any = {}): Promise { - + if (leaderboardId === null || leaderboardId === undefined) { throw new Error("'leaderboardId' is a required parameter but is null or undefined."); } @@ -2867,21 +3230,21 @@ export class NakamaApi { /** Write a record to a leaderboard. */ writeLeaderboardRecord(bearerToken: string, leaderboardId:string, - body:WriteLeaderboardRecordRequestLeaderboardRecordWrite, + record:WriteLeaderboardRecordRequestLeaderboardRecordWrite, options: any = {}): Promise { - + if (leaderboardId === null || leaderboardId === undefined) { throw new Error("'leaderboardId' is a required parameter but is null or undefined."); } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === undefined) { + throw new Error("'record' is a required parameter but is null or undefined."); } const urlPath = "/v2/leaderboard/{leaderboardId}" .replace("{leaderboardId}", encodeURIComponent(String(leaderboardId))); const queryParams = new Map(); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); @@ -2911,8 +3274,9 @@ export class NakamaApi { ownerId:string, limit?:number, expiry?:string, + cursor?:string, options: any = {}): Promise { - + if (leaderboardId === null || leaderboardId === undefined) { throw new Error("'leaderboardId' is a required parameter but is null or undefined."); } @@ -2925,6 +3289,7 @@ export class NakamaApi { const queryParams = new Map(); queryParams.set("limit", limit); queryParams.set("expiry", expiry); + queryParams.set("cursor", cursor); let bodyJson : string = ""; @@ -2959,7 +3324,7 @@ export class NakamaApi { maxSize?:number, query?:string, options: any = {}): Promise { - + const urlPath = "/v2/match"; const queryParams = new Map(); queryParams.set("limit", limit); @@ -2997,7 +3362,7 @@ export class NakamaApi { deleteNotifications(bearerToken: string, ids?:Array, options: any = {}): Promise { - + const urlPath = "/v2/notification"; const queryParams = new Map(); queryParams.set("ids", ids); @@ -3031,7 +3396,7 @@ export class NakamaApi { limit?:number, cacheableCursor?:string, options: any = {}): Promise { - + const urlPath = "/v2/notification"; const queryParams = new Map(); queryParams.set("limit", limit); @@ -3063,42 +3428,42 @@ export class NakamaApi { /** Execute a Lua function on the server. */ rpcFunc2(bearerToken: string, - id:string, - payload?:string, - httpKey?:string, - options: any = {}): Promise { - - if (id === null || id === undefined) { - throw new Error("'id' is a required parameter but is null or undefined."); - } - const urlPath = "/v2/rpc/{id}" - .replace("{id}", encodeURIComponent(String(id))); - const queryParams = new Map(); - queryParams.set("payload", payload); - queryParams.set("http_key", httpKey); - - let bodyJson : string = ""; - - const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); - const fetchOptions = buildFetchOptions("GET", options, bodyJson); - if (bearerToken) { - fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; - } - - return Promise.race([ - fetch(fullUrl, fetchOptions).then((response) => { - if (response.status == 204) { - return response; - } else if (response.status >= 200 && response.status < 300) { - return response.json(); - } else { - throw response; - } - }), - new Promise((_, reject) => - setTimeout(reject, this.timeoutMs, "Request timed out.") - ), - ]); + id:string, + payload?:string, + httpKey?:string, + options: any = {}): Promise { + + if (id === null || id === undefined) { + throw new Error("'id' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/rpc/{id}" + .replace("{id}", encodeURIComponent(String(id))); + const queryParams = new Map(); + queryParams.set("payload", payload); + queryParams.set("http_key", httpKey); + + let bodyJson : string = ""; + + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("GET", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise((_, reject) => + setTimeout(reject, this.timeoutMs, "Request timed out.") + ), + ]); } /** Execute a Lua function on the server. */ @@ -3107,7 +3472,7 @@ export class NakamaApi { body:string, httpKey?:string, options: any = {}): Promise { - + if (id === null || id === undefined) { throw new Error("'id' is a required parameter but is null or undefined."); } @@ -3142,13 +3507,13 @@ export class NakamaApi { setTimeout(reject, this.timeoutMs, "Request timed out.") ), ]); -} + } /** Log out a session, invalidate a refresh token, or log out all sessions/refresh tokens for a user. */ sessionLogout(bearerToken: string, body:ApiSessionLogoutRequest, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -3184,7 +3549,7 @@ export class NakamaApi { readStorageObjects(bearerToken: string, body:ApiReadStorageObjectsRequest, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -3220,7 +3585,7 @@ export class NakamaApi { writeStorageObjects(bearerToken: string, body:ApiWriteStorageObjectsRequest, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -3256,7 +3621,7 @@ export class NakamaApi { deleteStorageObjects(bearerToken: string, body:ApiDeleteStorageObjectsRequest, options: any = {}): Promise { - + if (body === null || body === undefined) { throw new Error("'body' is a required parameter but is null or undefined."); } @@ -3295,7 +3660,7 @@ export class NakamaApi { limit?:number, cursor?:string, options: any = {}): Promise { - + if (collection === null || collection === undefined) { throw new Error("'collection' is a required parameter but is null or undefined."); } @@ -3337,7 +3702,7 @@ export class NakamaApi { limit?:number, cursor?:string, options: any = {}): Promise { - + if (collection === null || collection === undefined) { throw new Error("'collection' is a required parameter but is null or undefined."); } @@ -3384,7 +3749,7 @@ export class NakamaApi { limit?:number, cursor?:string, options: any = {}): Promise { - + const urlPath = "/v2/tournament"; const queryParams = new Map(); queryParams.set("category_start", categoryStart); @@ -3418,6 +3783,42 @@ export class NakamaApi { ]); } + /** Delete a tournament record. */ + deleteTournamentRecord(bearerToken: string, + tournamentId:string, + options: any = {}): Promise { + + if (tournamentId === null || tournamentId === undefined) { + throw new Error("'tournamentId' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/tournament/{tournamentId}" + .replace("{tournamentId}", encodeURIComponent(String(tournamentId))); + const queryParams = new Map(); + + let bodyJson : string = ""; + + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("DELETE", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise((_, reject) => + setTimeout(reject, this.timeoutMs, "Request timed out.") + ), + ]); +} + /** List tournament records. */ listTournamentRecords(bearerToken: string, tournamentId:string, @@ -3426,7 +3827,7 @@ export class NakamaApi { cursor?:string, expiry?:string, options: any = {}): Promise { - + if (tournamentId === null || tournamentId === undefined) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } @@ -3465,21 +3866,21 @@ export class NakamaApi { /** Write a record to a tournament. */ writeTournamentRecord2(bearerToken: string, tournamentId:string, - body:WriteTournamentRecordRequestTournamentRecordWrite, + record:WriteTournamentRecordRequestTournamentRecordWrite, options: any = {}): Promise { - + if (tournamentId === null || tournamentId === undefined) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === undefined) { + throw new Error("'record' is a required parameter but is null or undefined."); } const urlPath = "/v2/tournament/{tournamentId}" .replace("{tournamentId}", encodeURIComponent(String(tournamentId))); const queryParams = new Map(); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); @@ -3506,21 +3907,21 @@ export class NakamaApi { /** Write a record to a tournament. */ writeTournamentRecord(bearerToken: string, tournamentId:string, - body:WriteTournamentRecordRequestTournamentRecordWrite, + record:WriteTournamentRecordRequestTournamentRecordWrite, options: any = {}): Promise { - + if (tournamentId === null || tournamentId === undefined) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === undefined) { + throw new Error("'record' is a required parameter but is null or undefined."); } const urlPath = "/v2/tournament/{tournamentId}" .replace("{tournamentId}", encodeURIComponent(String(tournamentId))); const queryParams = new Map(); let bodyJson : string = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("PUT", options, bodyJson); @@ -3548,7 +3949,7 @@ export class NakamaApi { joinTournament(bearerToken: string, tournamentId:string, options: any = {}): Promise { - + if (tournamentId === null || tournamentId === undefined) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } @@ -3586,8 +3987,9 @@ export class NakamaApi { ownerId:string, limit?:number, expiry?:string, + cursor?:string, options: any = {}): Promise { - + if (tournamentId === null || tournamentId === undefined) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } @@ -3600,6 +4002,7 @@ export class NakamaApi { const queryParams = new Map(); queryParams.set("limit", limit); queryParams.set("expiry", expiry); + queryParams.set("cursor", cursor); let bodyJson : string = ""; @@ -3631,7 +4034,7 @@ export class NakamaApi { usernames?:Array, facebookIds?:Array, options: any = {}): Promise { - + const urlPath = "/v2/user"; const queryParams = new Map(); queryParams.set("ids", ids); @@ -3669,7 +4072,7 @@ export class NakamaApi { state?:number, cursor?:string, options: any = {}): Promise { - + if (userId === null || userId === undefined) { throw new Error("'userId' is a required parameter but is null or undefined."); } diff --git a/packages/nakama-js/client.ts b/packages/nakama-js/client.ts index 5e247bf..cf63cfc 100644 --- a/packages/nakama-js/client.ts +++ b/packages/nakama-js/client.ts @@ -53,6 +53,11 @@ import { ApiAccountApple, ApiLinkSteamRequest, ApiValidatePurchaseResponse, + ApiFriendsOfFriendsList, + ApiStoreEnvironment, + ApiStoreProvider, + ApiValidateSubscriptionResponse, + ApiValidatedSubscription, } from "./api.gen"; import { Session } from "./session"; @@ -109,12 +114,16 @@ export interface LeaderboardRecordList { owner_records?: Array; /** The cursor to send when retrieving the previous page, if any. */ prev_cursor?: string; + // The total number of ranks available. + rank_count?: number; /** A list of leaderboard records. */ records?: Array; } /** A Tournament on the server. */ export interface Tournament { + /** Whether the leaderboard was created authoritatively or not. */ + authoritative?: boolean; /** The ID of the tournament. */ id?: string; /** The title for the tournament. */ @@ -347,6 +356,22 @@ export interface Friends { cursor?: string; } +/** A friend of a friend. */ +export interface FriendOfFriend { + // The user who referred its friend. + referrer?: string; + // User. + user?: User; +} + +/** Friends of the user's friends. */ +export interface FriendsOfFriends { + // Cursor for the next page of results, if any. + cursor?: string; + // User friends of friends. + friends_of_friends?: Array; +} + /** A user-role pair representing the user's role in a group. */ export interface GroupUser { /** The user. */ @@ -441,6 +466,46 @@ export interface NotificationList { notifications?: Array; } +/* A validated subscription stored by Nakama. */ +export interface ValidatedSubscription { + // Whether the subscription is currently active or not. + active?: boolean; + // UNIX Timestamp when the receipt validation was stored in DB. + create_time?: string; + // Whether the purchase was done in production or sandbox environment. + environment?: ApiStoreEnvironment; + // Subscription expiration time. The subscription can still be auto-renewed to extend the expiration time further. + expiry_time?: string; + // Purchase Original transaction ID (we only keep track of the original subscription, not subsequent renewals). + original_transaction_id?: string; + // Purchase Product ID. + product_id?: string; + // Raw provider notification body. + provider_notification?: string; + // Raw provider validation response body. + provider_response?: string; + // UNIX Timestamp when the purchase was done. + purchase_time?: string; + // Subscription refund time. If this time is set, the subscription was refunded. + refund_time?: string; + // The validation provider. + store?: ApiStoreProvider; + // UNIX Timestamp when the receipt validation was updated in DB. + update_time?: string; + // Subscription User ID. + user_id?: string; +} + +/** A list of validated subscriptions stored by Nakama. */ +export interface SubscriptionList { + // The cursor to send when retrieving the next page, if any. + cursor?: string; + // The cursor to send when retrieving the previous page, if any. + prev_cursor?: string; + // Stored validated subscriptions. + validated_subscriptions?: Array; +} + /** A client for Nakama server. */ export class Client { @@ -698,6 +763,18 @@ export class Client { return new DefaultSocket(this.host, this.port, useSSL, verbose, adapter, sendTimeoutMs); } + /** Delete the current user's account. */ + async deleteAccount(session: Session): Promise { + if (this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) { + await this.sessionRefresh(session); + } + + return this.apiClient.deleteAccount(session.token).then((response: any) => { + return response !== undefined; + }); + } + /** Delete one or more users by ID or username. */ async deleteFriends(session: Session, ids?: Array, usernames?: Array): Promise { if (this.autoRefreshSession && session.refresh_token && @@ -746,6 +823,11 @@ export class Client { }); } + /** Delete a tournament record. */ + async deleteTournamentRecord(session: Session, tournamentId: string): Promise { + return this.apiClient.deleteTournamentRecord(session.token, tournamentId); + } + /** Demote a set of users in a group to the next role down. */ async demoteGroupUsers(session: Session, groupId: string, ids: Array): Promise { if (this.autoRefreshSession && session.refresh_token && @@ -772,7 +854,6 @@ export class Client { /** Fetch the current user's account. */ async getAccount(session: Session): Promise { - if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) { await this.sessionRefresh(session); @@ -781,6 +862,16 @@ export class Client { return this.apiClient.getAccount(session.token); } + /** Get subscription by product id. */ + async getSubscription(session: Session, productId: string): Promise { + if (this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) { + await this.sessionRefresh(session); + } + + return this.apiClient.getSubscription(session.token, productId); + } + /** Import Facebook friends and add them to a user's account. */ async importFacebookFriends(session: Session, request: ApiAccountFacebook): Promise { if (this.autoRefreshSession && session.refresh_token && @@ -1207,6 +1298,53 @@ export class Client { }); } + /** List friends of friends for the current user. */ + async listFriendsOfFriends(session: Session, limit?: number, cursor?: string) : Promise { + if (this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) { + await this.sessionRefresh(session); + } + + return this.apiClient.listFriendsOfFriends(session.token, limit, cursor).then((response: ApiFriendsOfFriendsList) => { + var result: FriendsOfFriends = { + friends_of_friends: [], + cursor: response.cursor + }; + + if (response.friends_of_friends == null) + { + return Promise.resolve(result); + } + + response.friends_of_friends!.forEach(f => { + result.friends_of_friends!.push({ + referrer: f.referrer, + user: { + avatar_url: f.user!.avatar_url, + create_time: f.user!.create_time, + display_name: f.user!.display_name, + edge_count: f.user!.edge_count ? Number(f.user!.edge_count) : 0, + facebook_id: f.user!.facebook_id, + gamecenter_id: f.user!.gamecenter_id, + google_id: f.user!.google_id, + id: f.user!.id, + lang_tag: f.user!.lang_tag, + location: f.user!.location, + online: f.user!.online, + steam_id: f.user!.steam_id, + timezone: f.user!.timezone, + update_time: f.user!.update_time, + username: f.user!.username, + metadata: f.user!.metadata ? JSON.parse(f.user!.metadata!) : undefined, + facebook_instant_game_id: f.user!.facebook_instant_game_id! + } + }) + }); + + return Promise.resolve(result); + }); + } + /** List leaderboard records */ async listLeaderboardRecords(session: Session, leaderboardId: string, ownerIds?: Array, limit?: number, cursor?: string, expiry?: string,): Promise { if (this.autoRefreshSession && session.refresh_token && @@ -1218,6 +1356,7 @@ export class Client { var list: LeaderboardRecordList = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, + rank_count: response.rank_count ? Number(response.rank_count) : 0, owner_records: [], records: [] }; @@ -1262,16 +1401,17 @@ export class Client { }); } - async listLeaderboardRecordsAroundOwner(session: Session, leaderboardId: string, ownerId: string, limit?: number, expiry?: string): Promise { + async listLeaderboardRecordsAroundOwner(session: Session, leaderboardId: string, ownerId: string, limit?: number, expiry?: string, cursor?: string): Promise { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) { await this.sessionRefresh(session); } - return this.apiClient.listLeaderboardRecordsAroundOwner(session.token, leaderboardId, ownerId, limit, expiry).then((response: ApiLeaderboardRecordList) => { + return this.apiClient.listLeaderboardRecordsAroundOwner(session.token, leaderboardId, ownerId, limit, expiry, cursor).then((response: ApiLeaderboardRecordList) => { var list: LeaderboardRecordList = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, + rank_count: response.rank_count ? Number(response.rank_count) : 0, owner_records: [], records: [] }; @@ -1425,6 +1565,7 @@ export class Client { start_time: o.start_time, end_time: o.end_time, start_active: o.start_active, + authoritative: o.authoritative }) }) } @@ -1433,6 +1574,19 @@ export class Client { }); } + /** List user subscriptions. */ + async listSubscriptions(session: Session, cursor?: string, limit?: number) : Promise { + if (this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) { + await this.sessionRefresh(session); + } + + return this.apiClient.listSubscriptions(session.token, { + cursor: cursor, + limit: limit + }); + } + /** List tournament records from a given tournament. */ async listTournamentRecords(session: Session, tournamentId: string, ownerIds?: Array, limit?: number, cursor?: string, expiry?: string): Promise { if (this.autoRefreshSession && session.refresh_token && @@ -1489,13 +1643,13 @@ export class Client { } /** List tournament records from a given tournament around the owner. */ - async listTournamentRecordsAroundOwner(session: Session, tournamentId: string, ownerId: string, limit?: number, expiry?: string): Promise { + async listTournamentRecordsAroundOwner(session: Session, tournamentId: string, ownerId: string, limit?: number, expiry?: string, cursor?: string): Promise { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) { await this.sessionRefresh(session); } - return this.apiClient.listTournamentRecordsAroundOwner(session.token, tournamentId, ownerId, limit, expiry).then((response: ApiTournamentRecordList) => { + return this.apiClient.listTournamentRecordsAroundOwner(session.token, tournamentId, ownerId, limit, expiry, cursor).then((response: ApiTournamentRecordList) => { var list: TournamentRecordList = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, @@ -1778,33 +1932,63 @@ export class Client { } /** Validate an Apple IAP receipt. */ - async validatePurchaseApple(session: Session, receipt?: string) : Promise { + async validatePurchaseApple(session: Session, receipt?: string, persist: boolean = true) : Promise { + if (this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) { + await this.sessionRefresh(session); + } + + return this.apiClient.validatePurchaseApple(session.token, {receipt: receipt, persist: persist}) + } + + /** Validate a FB Instant IAP receipt. */ + async validatePurchaseFacebookInstant(session: Session, signedRequest?: string, persist: boolean = true) : Promise { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) { await this.sessionRefresh(session); } - return this.apiClient.validatePurchaseApple(session.token, {receipt: receipt}) + return this.apiClient.validatePurchaseFacebookInstant(session.token, {signed_request: signedRequest, persist: persist}) } /** Validate a Google IAP receipt. */ - async validatePurchaseGoogle(session: Session, purchase?: string) : Promise { + async validatePurchaseGoogle(session: Session, purchase?: string, persist: boolean = true) : Promise { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) { await this.sessionRefresh(session); } - return this.apiClient.validatePurchaseGoogle(session.token, {purchase: purchase}) + return this.apiClient.validatePurchaseGoogle(session.token, {purchase: purchase, persist: persist}) } /** Validate a Huawei IAP receipt. */ - async validatePurchaseHuawei(session: Session, purchase?: string, signature?: string) : Promise { + async validatePurchaseHuawei(session: Session, purchase?: string, signature?: string, persist: boolean = true) : Promise { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) { await this.sessionRefresh(session); } - return this.apiClient.validatePurchaseHuawei(session.token, {purchase: purchase, signature: signature}) + return this.apiClient.validatePurchaseHuawei(session.token, {purchase: purchase, signature: signature, persist: persist}) + } + + /** Validate Apple Subscription Receipt */ + async validateSubscriptionApple(session: Session, receipt: string, persist: boolean = true) : Promise { + if (this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) { + await this.sessionRefresh(session); + } + + return this.apiClient.validateSubscriptionApple(session.token, {receipt: receipt, persist: persist}); + } + + /** Validate Google Subscription Receipt */ + async validateSubscriptionGoogle(session: Session, receipt: string, persist: boolean = true) : Promise { + if (this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs)/1000)) { + await this.sessionRefresh(session); + } + + return this.apiClient.validateSubscriptionGoogle(session.token, {receipt: receipt, persist: persist}); } /** Write a record to a leaderboard. */ diff --git a/packages/nakama-js/dist/api.gen.d.ts b/packages/nakama-js/dist/api.gen.d.ts index fb51d6d..79c4101 100644 --- a/packages/nakama-js/dist/api.gen.d.ts +++ b/packages/nakama-js/dist/api.gen.d.ts @@ -1,3 +1,8 @@ +/** A friend of a friend. */ +export interface FriendsOfFriendsListFriendOfFriend { + referrer?: string; + user?: ApiUser; +} /** A single user-role pair. */ export interface GroupUserListGroupUser { state?: number; @@ -8,22 +13,6 @@ export interface UserGroupListUserGroup { group?: ApiGroup; state?: number; } -/** -* Environment where the purchase took place -*/ -export declare enum ValidatedPurchaseEnvironment { - UNKNOWN = 0, - SANDBOX = 1, - PRODUCTION = 2 -} -/** -* Validation Provider -*/ -export declare enum ValidatedPurchaseStore { - APPLE_APP_STORE = 0, - GOOGLE_PLAY_STORE = 1, - HUAWEI_APP_GALLERY = 2 -} /** Record values to write. */ export interface WriteLeaderboardRecordRequestLeaderboardRecordWrite { metadata?: string; @@ -79,7 +68,9 @@ export interface ApiAccountFacebookInstantGame { signed_player_info?: string; vars?: Record; } -/** Send Apple's Game Center account credentials to the server. Used with authenticate/link/unlink. */ +/** Send Apple's Game Center account credentials to the server. Used with authenticate/link/unlink. + +https://developer.apple.com/documentation/gamekit/gklocalplayer/1515407-generateidentityverificationsign */ export interface ApiAccountGameCenter { bundle_id?: string; player_id?: string; @@ -159,6 +150,11 @@ export interface ApiFriendList { cursor?: string; friends?: Array; } +/** */ +export interface ApiFriendsOfFriendsList { + cursor?: string; + friends_of_friends?: Array; +} /** A group in the server. */ export interface ApiGroup { avatar_url?: string; @@ -204,6 +200,7 @@ export interface ApiLeaderboardRecordList { next_cursor?: string; owner_records?: Array; prev_cursor?: string; + rank_count?: string; records?: Array; } /** Link Steam to the current user's account. */ @@ -211,6 +208,11 @@ export interface ApiLinkSteamRequest { account?: ApiAccountSteam; sync?: boolean; } +/** List user subscriptions. */ +export interface ApiListSubscriptionsRequest { + cursor?: string; + limit?: number; +} /** Represents a realtime match. */ export interface ApiMatch { authoritative?: boolean; @@ -296,7 +298,9 @@ export interface ApiStorageObject { /** A storage acknowledgement. */ export interface ApiStorageObjectAck { collection?: string; + create_time?: string; key?: string; + update_time?: string; user_id?: string; version?: string; } @@ -313,8 +317,32 @@ export interface ApiStorageObjectList { export interface ApiStorageObjects { objects?: Array; } +/** +* Environment where a purchase/subscription took place, +*/ +export declare enum ApiStoreEnvironment { + UNKNOWN = 0, + SANDBOX = 1, + PRODUCTION = 2 +} +/** +* Validation Provider, +*/ +export declare enum ApiStoreProvider { + APPLE_APP_STORE = 0, + GOOGLE_PLAY_STORE = 1, + HUAWEI_APP_GALLERY = 2, + FACEBOOK_INSTANT_STORE = 3 +} +/** A list of validated subscriptions stored by Nakama. */ +export interface ApiSubscriptionList { + cursor?: string; + prev_cursor?: string; + validated_subscriptions?: Array; +} /** A tournament on the server. */ export interface ApiTournament { + authoritative?: boolean; can_enter?: boolean; category?: number; create_time?: string; @@ -345,6 +373,7 @@ export interface ApiTournamentRecordList { next_cursor?: string; owner_records?: Array; prev_cursor?: string; + rank_count?: string; records?: Array; } /** Update a user's account details. */ @@ -397,32 +426,72 @@ export interface ApiUsers { } /** */ export interface ApiValidatePurchaseAppleRequest { + persist?: boolean; receipt?: string; } /** */ +export interface ApiValidatePurchaseFacebookInstantRequest { + persist?: boolean; + signed_request?: string; +} +/** */ export interface ApiValidatePurchaseGoogleRequest { + persist?: boolean; purchase?: string; } /** */ export interface ApiValidatePurchaseHuaweiRequest { + persist?: boolean; purchase?: string; signature?: string; } -/** */ +/** Validate IAP response. */ export interface ApiValidatePurchaseResponse { validated_purchases?: Array; } +/** */ +export interface ApiValidateSubscriptionAppleRequest { + persist?: boolean; + receipt?: string; +} +/** */ +export interface ApiValidateSubscriptionGoogleRequest { + persist?: boolean; + receipt?: string; +} +/** Validate Subscription response. */ +export interface ApiValidateSubscriptionResponse { + validated_subscription?: ApiValidatedSubscription; +} /** Validated Purchase stored by Nakama. */ export interface ApiValidatedPurchase { create_time?: string; - environment?: ValidatedPurchaseEnvironment; + environment?: ApiStoreEnvironment; product_id?: string; provider_response?: string; purchase_time?: string; + refund_time?: string; seen_before?: boolean; - store?: ValidatedPurchaseStore; + store?: ApiStoreProvider; transaction_id?: string; update_time?: string; + user_id?: string; +} +/** */ +export interface ApiValidatedSubscription { + active?: boolean; + create_time?: string; + environment?: ApiStoreEnvironment; + expiry_time?: string; + original_transaction_id?: string; + product_id?: string; + provider_notification?: string; + provider_response?: string; + purchase_time?: string; + refund_time?: string; + store?: ApiStoreProvider; + update_time?: string; + user_id?: string; } /** The object to store. */ export interface ApiWriteStorageObject { @@ -437,17 +506,6 @@ export interface ApiWriteStorageObject { export interface ApiWriteStorageObjectsRequest { objects?: Array; } -/** */ -export interface ProtobufAny { - type_url?: string; - value?: string; -} -/** */ -export interface RpcStatus { - code?: number; - details?: Array; - message?: string; -} export declare class NakamaApi { readonly serverKey: string; readonly basePath: string; @@ -455,28 +513,30 @@ export declare class NakamaApi { constructor(serverKey: string, basePath: string, timeoutMs: number); /** A healthcheck which load balancers can use to check the service. */ healthcheck(bearerToken: string, options?: any): Promise; + /** Delete the current user's account. */ + deleteAccount(bearerToken: string, options?: any): Promise; /** Fetch the current user's account. */ getAccount(bearerToken: string, options?: any): Promise; /** Update fields in the current user's account. */ updateAccount(bearerToken: string, body: ApiUpdateAccountRequest, options?: any): Promise; /** Authenticate a user with an Apple ID against the server. */ - authenticateApple(basicAuthUsername: string, basicAuthPassword: string, body: ApiAccountApple, create?: boolean, username?: string, options?: any): Promise; + authenticateApple(basicAuthUsername: string, basicAuthPassword: string, account: ApiAccountApple, create?: boolean, username?: string, options?: any): Promise; /** Authenticate a user with a custom id against the server. */ - authenticateCustom(basicAuthUsername: string, basicAuthPassword: string, body: ApiAccountCustom, create?: boolean, username?: string, options?: any): Promise; + authenticateCustom(basicAuthUsername: string, basicAuthPassword: string, account: ApiAccountCustom, create?: boolean, username?: string, options?: any): Promise; /** Authenticate a user with a device id against the server. */ - authenticateDevice(basicAuthUsername: string, basicAuthPassword: string, body: ApiAccountDevice, create?: boolean, username?: string, options?: any): Promise; + authenticateDevice(basicAuthUsername: string, basicAuthPassword: string, account: ApiAccountDevice, create?: boolean, username?: string, options?: any): Promise; /** Authenticate a user with an email+password against the server. */ - authenticateEmail(basicAuthUsername: string, basicAuthPassword: string, body: ApiAccountEmail, create?: boolean, username?: string, options?: any): Promise; + authenticateEmail(basicAuthUsername: string, basicAuthPassword: string, account: ApiAccountEmail, create?: boolean, username?: string, options?: any): Promise; /** Authenticate a user with a Facebook OAuth token against the server. */ - authenticateFacebook(basicAuthUsername: string, basicAuthPassword: string, body: ApiAccountFacebook, create?: boolean, username?: string, sync?: boolean, options?: any): Promise; + authenticateFacebook(basicAuthUsername: string, basicAuthPassword: string, account: ApiAccountFacebook, create?: boolean, username?: string, sync?: boolean, options?: any): Promise; /** Authenticate a user with a Facebook Instant Game token against the server. */ - authenticateFacebookInstantGame(basicAuthUsername: string, basicAuthPassword: string, body: ApiAccountFacebookInstantGame, create?: boolean, username?: string, options?: any): Promise; + authenticateFacebookInstantGame(basicAuthUsername: string, basicAuthPassword: string, account: ApiAccountFacebookInstantGame, create?: boolean, username?: string, options?: any): Promise; /** Authenticate a user with Apple's GameCenter against the server. */ - authenticateGameCenter(basicAuthUsername: string, basicAuthPassword: string, body: ApiAccountGameCenter, create?: boolean, username?: string, options?: any): Promise; + authenticateGameCenter(basicAuthUsername: string, basicAuthPassword: string, account: ApiAccountGameCenter, create?: boolean, username?: string, options?: any): Promise; /** Authenticate a user with Google against the server. */ - authenticateGoogle(basicAuthUsername: string, basicAuthPassword: string, body: ApiAccountGoogle, create?: boolean, username?: string, options?: any): Promise; + authenticateGoogle(basicAuthUsername: string, basicAuthPassword: string, account: ApiAccountGoogle, create?: boolean, username?: string, options?: any): Promise; /** Authenticate a user with Steam against the server. */ - authenticateSteam(basicAuthUsername: string, basicAuthPassword: string, body: ApiAccountSteam, create?: boolean, username?: string, sync?: boolean, options?: any): Promise; + authenticateSteam(basicAuthUsername: string, basicAuthPassword: string, account: ApiAccountSteam, create?: boolean, username?: string, sync?: boolean, options?: any): Promise; /** Add an Apple ID to the social profiles on the current user's account. */ linkApple(bearerToken: string, body: ApiAccountApple, options?: any): Promise; /** Add a custom ID to the social profiles on the current user's account. */ @@ -486,7 +546,7 @@ export declare class NakamaApi { /** Add an email+password to the social profiles on the current user's account. */ linkEmail(bearerToken: string, body: ApiAccountEmail, options?: any): Promise; /** Add Facebook to the social profiles on the current user's account. */ - linkFacebook(bearerToken: string, body: ApiAccountFacebook, sync?: boolean, options?: any): Promise; + linkFacebook(bearerToken: string, account: ApiAccountFacebook, sync?: boolean, options?: any): Promise; /** Add Facebook Instant Game to the social profiles on the current user's account. */ linkFacebookInstantGame(bearerToken: string, body: ApiAccountFacebookInstantGame, options?: any): Promise; /** Add Apple's GameCenter to the social profiles on the current user's account. */ @@ -528,9 +588,11 @@ export declare class NakamaApi { /** Block one or more users by ID or username. */ blockFriends(bearerToken: string, ids?: Array, usernames?: Array, options?: any): Promise; /** Import Facebook friends and add them to a user's account. */ - importFacebookFriends(bearerToken: string, body: ApiAccountFacebook, reset?: boolean, options?: any): Promise; + importFacebookFriends(bearerToken: string, account: ApiAccountFacebook, reset?: boolean, options?: any): Promise; + /** List friends of friends for the current user. */ + listFriendsOfFriends(bearerToken: string, limit?: number, cursor?: string, options?: any): Promise; /** Import Steam friends and add them to a user's account. */ - importSteamFriends(bearerToken: string, body: ApiAccountSteam, reset?: boolean, options?: any): Promise; + importSteamFriends(bearerToken: string, account: ApiAccountSteam, reset?: boolean, options?: any): Promise; /** List groups based on given filters. */ listGroups(bearerToken: string, name?: string, cursor?: string, limit?: number, langTag?: string, members?: number, open?: boolean, options?: any): Promise; /** Create a new group with the current user as the owner. */ @@ -544,7 +606,7 @@ export declare class NakamaApi { /** Ban a set of users from a group. */ banGroupUsers(bearerToken: string, groupId: string, userIds?: Array, options?: any): Promise; /** Demote a set of users in a group to the next role down. */ - demoteGroupUsers(bearerToken: string, groupId: string, userIds: Array, options?: any): Promise; + demoteGroupUsers(bearerToken: string, groupId: string, userIds?: Array, options?: any): Promise; /** Immediately join an open group, or request to join a closed one. */ joinGroup(bearerToken: string, groupId: string, options?: any): Promise; /** Kick a set of users from a group. */ @@ -557,18 +619,28 @@ export declare class NakamaApi { listGroupUsers(bearerToken: string, groupId: string, limit?: number, state?: number, cursor?: string, options?: any): Promise; /** Validate Apple IAP Receipt */ validatePurchaseApple(bearerToken: string, body: ApiValidatePurchaseAppleRequest, options?: any): Promise; + /** Validate FB Instant IAP Receipt */ + validatePurchaseFacebookInstant(bearerToken: string, body: ApiValidatePurchaseFacebookInstantRequest, options?: any): Promise; /** Validate Google IAP Receipt */ validatePurchaseGoogle(bearerToken: string, body: ApiValidatePurchaseGoogleRequest, options?: any): Promise; /** Validate Huawei IAP Receipt */ validatePurchaseHuawei(bearerToken: string, body: ApiValidatePurchaseHuaweiRequest, options?: any): Promise; + /** List user's subscriptions. */ + listSubscriptions(bearerToken: string, body: ApiListSubscriptionsRequest, options?: any): Promise; + /** Validate Apple Subscription Receipt */ + validateSubscriptionApple(bearerToken: string, body: ApiValidateSubscriptionAppleRequest, options?: any): Promise; + /** Validate Google Subscription Receipt */ + validateSubscriptionGoogle(bearerToken: string, body: ApiValidateSubscriptionGoogleRequest, options?: any): Promise; + /** Get subscription by product id. */ + getSubscription(bearerToken: string, productId: string, options?: any): Promise; /** Delete a leaderboard record. */ deleteLeaderboardRecord(bearerToken: string, leaderboardId: string, options?: any): Promise; /** List leaderboard records. */ listLeaderboardRecords(bearerToken: string, leaderboardId: string, ownerIds?: Array, limit?: number, cursor?: string, expiry?: string, options?: any): Promise; /** Write a record to a leaderboard. */ - writeLeaderboardRecord(bearerToken: string, leaderboardId: string, body: WriteLeaderboardRecordRequestLeaderboardRecordWrite, options?: any): Promise; + writeLeaderboardRecord(bearerToken: string, leaderboardId: string, record: WriteLeaderboardRecordRequestLeaderboardRecordWrite, options?: any): Promise; /** List leaderboard records that belong to a user. */ - listLeaderboardRecordsAroundOwner(bearerToken: string, leaderboardId: string, ownerId: string, limit?: number, expiry?: string, options?: any): Promise; + listLeaderboardRecordsAroundOwner(bearerToken: string, leaderboardId: string, ownerId: string, limit?: number, expiry?: string, cursor?: string, options?: any): Promise; /** Fetch list of running matches. */ listMatches(bearerToken: string, limit?: number, authoritative?: boolean, label?: string, minSize?: number, maxSize?: number, query?: string, options?: any): Promise; /** Delete one or more notifications for the current user. */ @@ -593,16 +665,18 @@ export declare class NakamaApi { listStorageObjects2(bearerToken: string, collection: string, userId: string, limit?: number, cursor?: string, options?: any): Promise; /** List current or upcoming tournaments. */ listTournaments(bearerToken: string, categoryStart?: number, categoryEnd?: number, startTime?: number, endTime?: number, limit?: number, cursor?: string, options?: any): Promise; + /** Delete a tournament record. */ + deleteTournamentRecord(bearerToken: string, tournamentId: string, options?: any): Promise; /** List tournament records. */ listTournamentRecords(bearerToken: string, tournamentId: string, ownerIds?: Array, limit?: number, cursor?: string, expiry?: string, options?: any): Promise; /** Write a record to a tournament. */ - writeTournamentRecord2(bearerToken: string, tournamentId: string, body: WriteTournamentRecordRequestTournamentRecordWrite, options?: any): Promise; + writeTournamentRecord2(bearerToken: string, tournamentId: string, record: WriteTournamentRecordRequestTournamentRecordWrite, options?: any): Promise; /** Write a record to a tournament. */ - writeTournamentRecord(bearerToken: string, tournamentId: string, body: WriteTournamentRecordRequestTournamentRecordWrite, options?: any): Promise; + writeTournamentRecord(bearerToken: string, tournamentId: string, record: WriteTournamentRecordRequestTournamentRecordWrite, options?: any): Promise; /** Attempt to join an open and running tournament. */ joinTournament(bearerToken: string, tournamentId: string, options?: any): Promise; /** List tournament records for a given owner. */ - listTournamentRecordsAroundOwner(bearerToken: string, tournamentId: string, ownerId: string, limit?: number, expiry?: string, options?: any): Promise; + listTournamentRecordsAroundOwner(bearerToken: string, tournamentId: string, ownerId: string, limit?: number, expiry?: string, cursor?: string, options?: any): Promise; /** Fetch zero or more users by ID and/or username. */ getUsers(bearerToken: string, ids?: Array, usernames?: Array, facebookIds?: Array, options?: any): Promise; /** List groups the current user belongs to. */ diff --git a/packages/nakama-js/dist/client.d.ts b/packages/nakama-js/dist/client.d.ts index 1731b2d..dadd3bd 100644 --- a/packages/nakama-js/dist/client.d.ts +++ b/packages/nakama-js/dist/client.d.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ApiAccount, ApiAccountCustom, ApiAccountDevice, ApiAccountEmail, ApiAccountFacebook, ApiAccountFacebookInstantGame, ApiAccountGoogle, ApiAccountGameCenter, ApiAccountSteam, ApiCreateGroupRequest, ApiDeleteStorageObjectsRequest, ApiEvent, ApiMatchList, ApiReadStorageObjectsRequest, ApiStorageObjectAcks, ApiUpdateAccountRequest, ApiUpdateGroupRequest, ApiAccountApple, ApiLinkSteamRequest, ApiValidatePurchaseResponse } from "./api.gen"; +import { ApiAccount, ApiAccountCustom, ApiAccountDevice, ApiAccountEmail, ApiAccountFacebook, ApiAccountFacebookInstantGame, ApiAccountGoogle, ApiAccountGameCenter, ApiAccountSteam, ApiCreateGroupRequest, ApiDeleteStorageObjectsRequest, ApiEvent, ApiMatchList, ApiReadStorageObjectsRequest, ApiStorageObjectAcks, ApiUpdateAccountRequest, ApiUpdateGroupRequest, ApiAccountApple, ApiLinkSteamRequest, ApiValidatePurchaseResponse, ApiStoreEnvironment, ApiStoreProvider, ApiValidateSubscriptionResponse, ApiValidatedSubscription } from "./api.gen"; import { Session } from "./session"; import { Socket } from "./socket"; import { WebSocketAdapter } from "./web_socket_adapter"; @@ -59,11 +59,14 @@ export interface LeaderboardRecordList { owner_records?: Array; /** The cursor to send when retrieving the previous page, if any. */ prev_cursor?: string; + rank_count?: number; /** A list of leaderboard records. */ records?: Array; } /** A Tournament on the server. */ export interface Tournament { + /** Whether the leaderboard was created authoritatively or not. */ + authoritative?: boolean; /** The ID of the tournament. */ id?: string; /** The title for the tournament. */ @@ -281,6 +284,16 @@ export interface Friends { /** Cursor for the next page of results, if any. */ cursor?: string; } +/** A friend of a friend. */ +export interface FriendOfFriend { + referrer?: string; + user?: User; +} +/** Friends of the user's friends. */ +export interface FriendsOfFriends { + cursor?: string; + friends_of_friends?: Array; +} /** A user-role pair representing the user's role in a group. */ export interface GroupUser { /** The user. */ @@ -367,6 +380,27 @@ export interface NotificationList { /** Collection of notifications. */ notifications?: Array; } +export interface ValidatedSubscription { + active?: boolean; + create_time?: string; + environment?: ApiStoreEnvironment; + expiry_time?: string; + original_transaction_id?: string; + product_id?: string; + provider_notification?: string; + provider_response?: string; + purchase_time?: string; + refund_time?: string; + store?: ApiStoreProvider; + update_time?: string; + user_id?: string; +} +/** A list of validated subscriptions stored by Nakama. */ +export interface SubscriptionList { + cursor?: string; + prev_cursor?: string; + validated_subscriptions?: Array; +} /** A client for Nakama server. */ export declare class Client { readonly serverkey: string; @@ -410,6 +444,8 @@ export declare class Client { createGroup(session: Session, request: ApiCreateGroupRequest): Promise; /** A socket created with the client's configuration. */ createSocket(useSSL?: boolean, verbose?: boolean, adapter?: WebSocketAdapter, sendTimeoutMs?: number): Socket; + /** Delete the current user's account. */ + deleteAccount(session: Session): Promise; /** Delete one or more users by ID or username. */ deleteFriends(session: Session, ids?: Array, usernames?: Array): Promise; /** Delete a group the user is part of and has permissions to delete. */ @@ -418,12 +454,16 @@ export declare class Client { deleteNotifications(session: Session, ids?: Array): Promise; /** Delete one or more storage objects */ deleteStorageObjects(session: Session, request: ApiDeleteStorageObjectsRequest): Promise; + /** Delete a tournament record. */ + deleteTournamentRecord(session: Session, tournamentId: string): Promise; /** Demote a set of users in a group to the next role down. */ demoteGroupUsers(session: Session, groupId: string, ids: Array): Promise; /** Submit an event for processing in the server's registered runtime custom events handler. */ emitEvent(session: Session, request: ApiEvent): Promise; /** Fetch the current user's account. */ getAccount(session: Session): Promise; + /** Get subscription by product id. */ + getSubscription(session: Session, productId: string): Promise; /** Import Facebook friends and add them to a user's account. */ importFacebookFriends(session: Session, request: ApiAccountFacebook): Promise; /** Import Steam friends and add them to a user's account. */ @@ -465,9 +505,11 @@ export declare class Client { linkSteam(session: Session, request: ApiLinkSteamRequest): Promise; /** List all friends for the current user. */ listFriends(session: Session, state?: number, limit?: number, cursor?: string): Promise; + /** List friends of friends for the current user. */ + listFriendsOfFriends(session: Session, limit?: number, cursor?: string): Promise; /** List leaderboard records */ listLeaderboardRecords(session: Session, leaderboardId: string, ownerIds?: Array, limit?: number, cursor?: string, expiry?: string): Promise; - listLeaderboardRecordsAroundOwner(session: Session, leaderboardId: string, ownerId: string, limit?: number, expiry?: string): Promise; + listLeaderboardRecordsAroundOwner(session: Session, leaderboardId: string, ownerId: string, limit?: number, expiry?: string, cursor?: string): Promise; /** Fetch list of running matches. */ listMatches(session: Session, limit?: number, authoritative?: boolean, label?: string, minSize?: number, maxSize?: number, query?: string): Promise; /** Fetch list of notifications. */ @@ -476,10 +518,12 @@ export declare class Client { listStorageObjects(session: Session, collection: string, userId?: string, limit?: number, cursor?: string): Promise; /** List current or upcoming tournaments. */ listTournaments(session: Session, categoryStart?: number, categoryEnd?: number, startTime?: number, endTime?: number, limit?: number, cursor?: string): Promise; + /** List user subscriptions. */ + listSubscriptions(session: Session, cursor?: string, limit?: number): Promise; /** List tournament records from a given tournament. */ listTournamentRecords(session: Session, tournamentId: string, ownerIds?: Array, limit?: number, cursor?: string, expiry?: string): Promise; /** List tournament records from a given tournament around the owner. */ - listTournamentRecordsAroundOwner(session: Session, tournamentId: string, ownerId: string, limit?: number, expiry?: string): Promise; + listTournamentRecordsAroundOwner(session: Session, tournamentId: string, ownerId: string, limit?: number, expiry?: string, cursor?: string): Promise; /** Promote users in a group to the next role up. */ promoteGroupUsers(session: Session, groupId: string, ids?: Array): Promise; /** Fetch storage objects. */ @@ -515,11 +559,17 @@ export declare class Client { /** Update a group the user is part of and has permissions to update. */ updateGroup(session: Session, groupId: string, request: ApiUpdateGroupRequest): Promise; /** Validate an Apple IAP receipt. */ - validatePurchaseApple(session: Session, receipt?: string): Promise; + validatePurchaseApple(session: Session, receipt?: string, persist?: boolean): Promise; + /** Validate a FB Instant IAP receipt. */ + validatePurchaseFacebookInstant(session: Session, signedRequest?: string, persist?: boolean): Promise; /** Validate a Google IAP receipt. */ - validatePurchaseGoogle(session: Session, purchase?: string): Promise; + validatePurchaseGoogle(session: Session, purchase?: string, persist?: boolean): Promise; /** Validate a Huawei IAP receipt. */ - validatePurchaseHuawei(session: Session, purchase?: string, signature?: string): Promise; + validatePurchaseHuawei(session: Session, purchase?: string, signature?: string, persist?: boolean): Promise; + /** Validate Apple Subscription Receipt */ + validateSubscriptionApple(session: Session, receipt: string, persist?: boolean): Promise; + /** Validate Google Subscription Receipt */ + validateSubscriptionGoogle(session: Session, receipt: string, persist?: boolean): Promise; /** Write a record to a leaderboard. */ writeLeaderboardRecord(session: Session, leaderboardId: string, request: WriteLeaderboardRecord): Promise; /** Write storage objects. */ diff --git a/packages/nakama-js/dist/nakama-js.cjs.js b/packages/nakama-js/dist/nakama-js.cjs.js index c993507..796e999 100644 --- a/packages/nakama-js/dist/nakama-js.cjs.js +++ b/packages/nakama-js/dist/nakama-js.cjs.js @@ -693,6 +693,31 @@ var NakamaApi = class { ) ]); } + /** Delete the current user's account. */ + deleteAccount(bearerToken, options = {}) { + const urlPath = "/v2/account"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("DELETE", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** Fetch the current user's account. */ getAccount(bearerToken, options = {}) { const urlPath = "/v2/account"; @@ -748,19 +773,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with an Apple ID against the server. */ - authenticateApple(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateApple(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/apple"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -777,19 +804,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with a custom id against the server. */ - authenticateCustom(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateCustom(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/custom"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -806,19 +835,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with a device id against the server. */ - authenticateDevice(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateDevice(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/device"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -835,19 +866,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with an email+password against the server. */ - authenticateEmail(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateEmail(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/email"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -864,9 +897,9 @@ var NakamaApi = class { ]); } /** Authenticate a user with a Facebook OAuth token against the server. */ - authenticateFacebook(basicAuthUsername, basicAuthPassword, body, create, username, sync, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateFacebook(basicAuthUsername, basicAuthPassword, account, create, username, sync, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/facebook"; const queryParams = /* @__PURE__ */ new Map(); @@ -874,10 +907,12 @@ var NakamaApi = class { queryParams.set("username", username); queryParams.set("sync", sync); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -894,19 +929,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with a Facebook Instant Game token against the server. */ - authenticateFacebookInstantGame(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateFacebookInstantGame(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/facebookinstantgame"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -923,19 +960,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with Apple's GameCenter against the server. */ - authenticateGameCenter(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateGameCenter(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/gamecenter"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -952,19 +991,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with Google against the server. */ - authenticateGoogle(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateGoogle(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/google"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -981,9 +1022,9 @@ var NakamaApi = class { ]); } /** Authenticate a user with Steam against the server. */ - authenticateSteam(basicAuthUsername, basicAuthPassword, body, create, username, sync, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateSteam(basicAuthUsername, basicAuthPassword, account, create, username, sync, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/steam"; const queryParams = /* @__PURE__ */ new Map(); @@ -991,10 +1032,12 @@ var NakamaApi = class { queryParams.set("username", username); queryParams.set("sync", sync); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -1127,15 +1170,15 @@ var NakamaApi = class { ]); } /** Add Facebook to the social profiles on the current user's account. */ - linkFacebook(bearerToken, body, sync, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + linkFacebook(bearerToken, account, sync, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/link/facebook"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("sync", sync); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -1283,7 +1326,9 @@ var NakamaApi = class { bodyJson = JSON.stringify(body || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -1730,15 +1775,15 @@ var NakamaApi = class { ]); } /** Import Facebook friends and add them to a user's account. */ - importFacebookFriends(bearerToken, body, reset, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + importFacebookFriends(bearerToken, account, reset, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/friend/facebook"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("reset", reset); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -1759,16 +1804,43 @@ var NakamaApi = class { ) ]); } + /** List friends of friends for the current user. */ + listFriendsOfFriends(bearerToken, limit, cursor, options = {}) { + const urlPath = "/v2/friend/friends"; + const queryParams = /* @__PURE__ */ new Map(); + queryParams.set("limit", limit); + queryParams.set("cursor", cursor); + let bodyJson = ""; + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("GET", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** Import Steam friends and add them to a user's account. */ - importSteamFriends(bearerToken, body, reset, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + importSteamFriends(bearerToken, account, reset, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/friend/steam"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("reset", reset); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -1972,9 +2044,6 @@ var NakamaApi = class { if (groupId === null || groupId === void 0) { throw new Error("'groupId' is a required parameter but is null or undefined."); } - if (userIds === null || userIds === void 0) { - throw new Error("'userIds' is a required parameter but is null or undefined."); - } const urlPath = "/v2/group/{groupId}/demote".replace("{groupId}", encodeURIComponent(String(groupId))); const queryParams = /* @__PURE__ */ new Map(); queryParams.set("user_ids", userIds); @@ -2173,6 +2242,35 @@ var NakamaApi = class { ) ]); } + /** Validate FB Instant IAP Receipt */ + validatePurchaseFacebookInstant(bearerToken, body, options = {}) { + if (body === null || body === void 0) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/purchase/facebookinstant"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** Validate Google IAP Receipt */ validatePurchaseGoogle(bearerToken, body, options = {}) { if (body === null || body === void 0) { @@ -2231,6 +2329,121 @@ var NakamaApi = class { ) ]); } + /** List user's subscriptions. */ + listSubscriptions(bearerToken, body, options = {}) { + if (body === null || body === void 0) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } + /** Validate Apple Subscription Receipt */ + validateSubscriptionApple(bearerToken, body, options = {}) { + if (body === null || body === void 0) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription/apple"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } + /** Validate Google Subscription Receipt */ + validateSubscriptionGoogle(bearerToken, body, options = {}) { + if (body === null || body === void 0) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription/google"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } + /** Get subscription by product id. */ + getSubscription(bearerToken, productId, options = {}) { + if (productId === null || productId === void 0) { + throw new Error("'productId' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription/{productId}".replace("{productId}", encodeURIComponent(String(productId))); + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("GET", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** Delete a leaderboard record. */ deleteLeaderboardRecord(bearerToken, leaderboardId, options = {}) { if (leaderboardId === null || leaderboardId === void 0) { @@ -2292,17 +2505,17 @@ var NakamaApi = class { ]); } /** Write a record to a leaderboard. */ - writeLeaderboardRecord(bearerToken, leaderboardId, body, options = {}) { + writeLeaderboardRecord(bearerToken, leaderboardId, record, options = {}) { if (leaderboardId === null || leaderboardId === void 0) { throw new Error("'leaderboardId' is a required parameter but is null or undefined."); } - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === void 0) { + throw new Error("'record' is a required parameter but is null or undefined."); } const urlPath = "/v2/leaderboard/{leaderboardId}".replace("{leaderboardId}", encodeURIComponent(String(leaderboardId))); const queryParams = /* @__PURE__ */ new Map(); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -2324,7 +2537,7 @@ var NakamaApi = class { ]); } /** List leaderboard records that belong to a user. */ - listLeaderboardRecordsAroundOwner(bearerToken, leaderboardId, ownerId, limit, expiry, options = {}) { + listLeaderboardRecordsAroundOwner(bearerToken, leaderboardId, ownerId, limit, expiry, cursor, options = {}) { if (leaderboardId === null || leaderboardId === void 0) { throw new Error("'leaderboardId' is a required parameter but is null or undefined."); } @@ -2335,6 +2548,7 @@ var NakamaApi = class { const queryParams = /* @__PURE__ */ new Map(); queryParams.set("limit", limit); queryParams.set("expiry", expiry); + queryParams.set("cursor", cursor); let bodyJson = ""; const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("GET", options, bodyJson); @@ -2714,6 +2928,34 @@ var NakamaApi = class { ) ]); } + /** Delete a tournament record. */ + deleteTournamentRecord(bearerToken, tournamentId, options = {}) { + if (tournamentId === null || tournamentId === void 0) { + throw new Error("'tournamentId' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/tournament/{tournamentId}".replace("{tournamentId}", encodeURIComponent(String(tournamentId))); + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("DELETE", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** List tournament records. */ listTournamentRecords(bearerToken, tournamentId, ownerIds, limit, cursor, expiry, options = {}) { if (tournamentId === null || tournamentId === void 0) { @@ -2747,17 +2989,17 @@ var NakamaApi = class { ]); } /** Write a record to a tournament. */ - writeTournamentRecord2(bearerToken, tournamentId, body, options = {}) { + writeTournamentRecord2(bearerToken, tournamentId, record, options = {}) { if (tournamentId === null || tournamentId === void 0) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === void 0) { + throw new Error("'record' is a required parameter but is null or undefined."); } const urlPath = "/v2/tournament/{tournamentId}".replace("{tournamentId}", encodeURIComponent(String(tournamentId))); const queryParams = /* @__PURE__ */ new Map(); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -2779,17 +3021,17 @@ var NakamaApi = class { ]); } /** Write a record to a tournament. */ - writeTournamentRecord(bearerToken, tournamentId, body, options = {}) { + writeTournamentRecord(bearerToken, tournamentId, record, options = {}) { if (tournamentId === null || tournamentId === void 0) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === void 0) { + throw new Error("'record' is a required parameter but is null or undefined."); } const urlPath = "/v2/tournament/{tournamentId}".replace("{tournamentId}", encodeURIComponent(String(tournamentId))); const queryParams = /* @__PURE__ */ new Map(); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("PUT", options, bodyJson); if (bearerToken) { @@ -2839,7 +3081,7 @@ var NakamaApi = class { ]); } /** List tournament records for a given owner. */ - listTournamentRecordsAroundOwner(bearerToken, tournamentId, ownerId, limit, expiry, options = {}) { + listTournamentRecordsAroundOwner(bearerToken, tournamentId, ownerId, limit, expiry, cursor, options = {}) { if (tournamentId === null || tournamentId === void 0) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } @@ -2850,6 +3092,7 @@ var NakamaApi = class { const queryParams = /* @__PURE__ */ new Map(); queryParams.set("limit", limit); queryParams.set("expiry", expiry); + queryParams.set("cursor", cursor); let bodyJson = ""; const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("GET", options, bodyJson); @@ -3812,6 +4055,17 @@ var Client = class { createSocket(useSSL = false, verbose = false, adapter = new WebSocketAdapterText(), sendTimeoutMs = DefaultSocket.DefaultSendTimeoutMs) { return new DefaultSocket(this.host, this.port, useSSL, verbose, adapter, sendTimeoutMs); } + /** Delete the current user's account. */ + deleteAccount(session) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.deleteAccount(session.token).then((response) => { + return response !== void 0; + }); + }); + } /** Delete one or more users by ID or username. */ deleteFriends(session, ids, usernames) { return __async(this, null, function* () { @@ -3856,6 +4110,12 @@ var Client = class { }); }); } + /** Delete a tournament record. */ + deleteTournamentRecord(session, tournamentId) { + return __async(this, null, function* () { + return this.apiClient.deleteTournamentRecord(session.token, tournamentId); + }); + } /** Demote a set of users in a group to the next role down. */ demoteGroupUsers(session, groupId, ids) { return __async(this, null, function* () { @@ -3887,6 +4147,15 @@ var Client = class { return this.apiClient.getAccount(session.token); }); } + /** Get subscription by product id. */ + getSubscription(session, productId) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.getSubscription(session.token, productId); + }); + } /** Import Facebook friends and add them to a user's account. */ importFacebookFriends(session, request) { return __async(this, null, function* () { @@ -4279,6 +4548,48 @@ var Client = class { }); }); } + /** List friends of friends for the current user. */ + listFriendsOfFriends(session, limit, cursor) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.listFriendsOfFriends(session.token, limit, cursor).then((response) => { + var result = { + friends_of_friends: [], + cursor: response.cursor + }; + if (response.friends_of_friends == null) { + return Promise.resolve(result); + } + response.friends_of_friends.forEach((f) => { + result.friends_of_friends.push({ + referrer: f.referrer, + user: { + avatar_url: f.user.avatar_url, + create_time: f.user.create_time, + display_name: f.user.display_name, + edge_count: f.user.edge_count ? Number(f.user.edge_count) : 0, + facebook_id: f.user.facebook_id, + gamecenter_id: f.user.gamecenter_id, + google_id: f.user.google_id, + id: f.user.id, + lang_tag: f.user.lang_tag, + location: f.user.location, + online: f.user.online, + steam_id: f.user.steam_id, + timezone: f.user.timezone, + update_time: f.user.update_time, + username: f.user.username, + metadata: f.user.metadata ? JSON.parse(f.user.metadata) : void 0, + facebook_instant_game_id: f.user.facebook_instant_game_id + } + }); + }); + return Promise.resolve(result); + }); + }); + } /** List leaderboard records */ listLeaderboardRecords(session, leaderboardId, ownerIds, limit, cursor, expiry) { return __async(this, null, function* () { @@ -4289,6 +4600,7 @@ var Client = class { var list = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, + rank_count: response.rank_count ? Number(response.rank_count) : 0, owner_records: [], records: [] }; @@ -4330,15 +4642,16 @@ var Client = class { }); }); } - listLeaderboardRecordsAroundOwner(session, leaderboardId, ownerId, limit, expiry) { + listLeaderboardRecordsAroundOwner(session, leaderboardId, ownerId, limit, expiry, cursor) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.listLeaderboardRecordsAroundOwner(session.token, leaderboardId, ownerId, limit, expiry).then((response) => { + return this.apiClient.listLeaderboardRecordsAroundOwner(session.token, leaderboardId, ownerId, limit, expiry, cursor).then((response) => { var list = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, + rank_count: response.rank_count ? Number(response.rank_count) : 0, owner_records: [], records: [] }; @@ -4479,7 +4792,8 @@ var Client = class { create_time: o.create_time, start_time: o.start_time, end_time: o.end_time, - start_active: o.start_active + start_active: o.start_active, + authoritative: o.authoritative }); }); } @@ -4487,6 +4801,18 @@ var Client = class { }); }); } + /** List user subscriptions. */ + listSubscriptions(session, cursor, limit) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.listSubscriptions(session.token, { + cursor, + limit + }); + }); + } /** List tournament records from a given tournament. */ listTournamentRecords(session, tournamentId, ownerIds, limit, cursor, expiry) { return __async(this, null, function* () { @@ -4539,12 +4865,12 @@ var Client = class { }); } /** List tournament records from a given tournament around the owner. */ - listTournamentRecordsAroundOwner(session, tournamentId, ownerId, limit, expiry) { + listTournamentRecordsAroundOwner(session, tournamentId, ownerId, limit, expiry, cursor) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.listTournamentRecordsAroundOwner(session.token, tournamentId, ownerId, limit, expiry).then((response) => { + return this.apiClient.listTournamentRecordsAroundOwner(session.token, tournamentId, ownerId, limit, expiry, cursor).then((response) => { var list = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, @@ -4804,30 +5130,57 @@ var Client = class { }); } /** Validate an Apple IAP receipt. */ - validatePurchaseApple(session, receipt) { + validatePurchaseApple(session, receipt, persist = true) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.validatePurchaseApple(session.token, { receipt, persist }); + }); + } + /** Validate a FB Instant IAP receipt. */ + validatePurchaseFacebookInstant(session, signedRequest, persist = true) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.validatePurchaseApple(session.token, { receipt }); + return this.apiClient.validatePurchaseFacebookInstant(session.token, { signed_request: signedRequest, persist }); }); } /** Validate a Google IAP receipt. */ - validatePurchaseGoogle(session, purchase) { + validatePurchaseGoogle(session, purchase, persist = true) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.validatePurchaseGoogle(session.token, { purchase }); + return this.apiClient.validatePurchaseGoogle(session.token, { purchase, persist }); }); } /** Validate a Huawei IAP receipt. */ - validatePurchaseHuawei(session, purchase, signature) { + validatePurchaseHuawei(session, purchase, signature, persist = true) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.validatePurchaseHuawei(session.token, { purchase, signature, persist }); + }); + } + /** Validate Apple Subscription Receipt */ + validateSubscriptionApple(session, receipt, persist = true) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.validateSubscriptionApple(session.token, { receipt, persist }); + }); + } + /** Validate Google Subscription Receipt */ + validateSubscriptionGoogle(session, receipt, persist = true) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.validatePurchaseHuawei(session.token, { purchase, signature }); + return this.apiClient.validateSubscriptionGoogle(session.token, { receipt, persist }); }); } /** Write a record to a leaderboard. */ diff --git a/packages/nakama-js/dist/nakama-js.esm.mjs b/packages/nakama-js/dist/nakama-js.esm.mjs index fa94313..b022b18 100644 --- a/packages/nakama-js/dist/nakama-js.esm.mjs +++ b/packages/nakama-js/dist/nakama-js.esm.mjs @@ -667,6 +667,31 @@ var NakamaApi = class { ) ]); } + /** Delete the current user's account. */ + deleteAccount(bearerToken, options = {}) { + const urlPath = "/v2/account"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("DELETE", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** Fetch the current user's account. */ getAccount(bearerToken, options = {}) { const urlPath = "/v2/account"; @@ -722,19 +747,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with an Apple ID against the server. */ - authenticateApple(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateApple(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/apple"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -751,19 +778,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with a custom id against the server. */ - authenticateCustom(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateCustom(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/custom"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -780,19 +809,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with a device id against the server. */ - authenticateDevice(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateDevice(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/device"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -809,19 +840,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with an email+password against the server. */ - authenticateEmail(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateEmail(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/email"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -838,9 +871,9 @@ var NakamaApi = class { ]); } /** Authenticate a user with a Facebook OAuth token against the server. */ - authenticateFacebook(basicAuthUsername, basicAuthPassword, body, create, username, sync, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateFacebook(basicAuthUsername, basicAuthPassword, account, create, username, sync, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/facebook"; const queryParams = /* @__PURE__ */ new Map(); @@ -848,10 +881,12 @@ var NakamaApi = class { queryParams.set("username", username); queryParams.set("sync", sync); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -868,19 +903,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with a Facebook Instant Game token against the server. */ - authenticateFacebookInstantGame(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateFacebookInstantGame(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/facebookinstantgame"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -897,19 +934,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with Apple's GameCenter against the server. */ - authenticateGameCenter(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateGameCenter(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/gamecenter"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -926,19 +965,21 @@ var NakamaApi = class { ]); } /** Authenticate a user with Google against the server. */ - authenticateGoogle(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateGoogle(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/google"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -955,9 +996,9 @@ var NakamaApi = class { ]); } /** Authenticate a user with Steam against the server. */ - authenticateSteam(basicAuthUsername, basicAuthPassword, body, create, username, sync, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateSteam(basicAuthUsername, basicAuthPassword, account, create, username, sync, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/steam"; const queryParams = /* @__PURE__ */ new Map(); @@ -965,10 +1006,12 @@ var NakamaApi = class { queryParams.set("username", username); queryParams.set("sync", sync); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -1101,15 +1144,15 @@ var NakamaApi = class { ]); } /** Add Facebook to the social profiles on the current user's account. */ - linkFacebook(bearerToken, body, sync, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + linkFacebook(bearerToken, account, sync, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/link/facebook"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("sync", sync); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -1257,7 +1300,9 @@ var NakamaApi = class { bodyJson = JSON.stringify(body || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -1704,15 +1749,15 @@ var NakamaApi = class { ]); } /** Import Facebook friends and add them to a user's account. */ - importFacebookFriends(bearerToken, body, reset, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + importFacebookFriends(bearerToken, account, reset, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/friend/facebook"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("reset", reset); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -1733,16 +1778,43 @@ var NakamaApi = class { ) ]); } + /** List friends of friends for the current user. */ + listFriendsOfFriends(bearerToken, limit, cursor, options = {}) { + const urlPath = "/v2/friend/friends"; + const queryParams = /* @__PURE__ */ new Map(); + queryParams.set("limit", limit); + queryParams.set("cursor", cursor); + let bodyJson = ""; + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("GET", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** Import Steam friends and add them to a user's account. */ - importSteamFriends(bearerToken, body, reset, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + importSteamFriends(bearerToken, account, reset, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/friend/steam"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("reset", reset); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -1946,9 +2018,6 @@ var NakamaApi = class { if (groupId === null || groupId === void 0) { throw new Error("'groupId' is a required parameter but is null or undefined."); } - if (userIds === null || userIds === void 0) { - throw new Error("'userIds' is a required parameter but is null or undefined."); - } const urlPath = "/v2/group/{groupId}/demote".replace("{groupId}", encodeURIComponent(String(groupId))); const queryParams = /* @__PURE__ */ new Map(); queryParams.set("user_ids", userIds); @@ -2147,6 +2216,35 @@ var NakamaApi = class { ) ]); } + /** Validate FB Instant IAP Receipt */ + validatePurchaseFacebookInstant(bearerToken, body, options = {}) { + if (body === null || body === void 0) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/purchase/facebookinstant"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** Validate Google IAP Receipt */ validatePurchaseGoogle(bearerToken, body, options = {}) { if (body === null || body === void 0) { @@ -2205,6 +2303,121 @@ var NakamaApi = class { ) ]); } + /** List user's subscriptions. */ + listSubscriptions(bearerToken, body, options = {}) { + if (body === null || body === void 0) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } + /** Validate Apple Subscription Receipt */ + validateSubscriptionApple(bearerToken, body, options = {}) { + if (body === null || body === void 0) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription/apple"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } + /** Validate Google Subscription Receipt */ + validateSubscriptionGoogle(bearerToken, body, options = {}) { + if (body === null || body === void 0) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription/google"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } + /** Get subscription by product id. */ + getSubscription(bearerToken, productId, options = {}) { + if (productId === null || productId === void 0) { + throw new Error("'productId' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription/{productId}".replace("{productId}", encodeURIComponent(String(productId))); + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("GET", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** Delete a leaderboard record. */ deleteLeaderboardRecord(bearerToken, leaderboardId, options = {}) { if (leaderboardId === null || leaderboardId === void 0) { @@ -2266,17 +2479,17 @@ var NakamaApi = class { ]); } /** Write a record to a leaderboard. */ - writeLeaderboardRecord(bearerToken, leaderboardId, body, options = {}) { + writeLeaderboardRecord(bearerToken, leaderboardId, record, options = {}) { if (leaderboardId === null || leaderboardId === void 0) { throw new Error("'leaderboardId' is a required parameter but is null or undefined."); } - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === void 0) { + throw new Error("'record' is a required parameter but is null or undefined."); } const urlPath = "/v2/leaderboard/{leaderboardId}".replace("{leaderboardId}", encodeURIComponent(String(leaderboardId))); const queryParams = /* @__PURE__ */ new Map(); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -2298,7 +2511,7 @@ var NakamaApi = class { ]); } /** List leaderboard records that belong to a user. */ - listLeaderboardRecordsAroundOwner(bearerToken, leaderboardId, ownerId, limit, expiry, options = {}) { + listLeaderboardRecordsAroundOwner(bearerToken, leaderboardId, ownerId, limit, expiry, cursor, options = {}) { if (leaderboardId === null || leaderboardId === void 0) { throw new Error("'leaderboardId' is a required parameter but is null or undefined."); } @@ -2309,6 +2522,7 @@ var NakamaApi = class { const queryParams = /* @__PURE__ */ new Map(); queryParams.set("limit", limit); queryParams.set("expiry", expiry); + queryParams.set("cursor", cursor); let bodyJson = ""; const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("GET", options, bodyJson); @@ -2688,6 +2902,34 @@ var NakamaApi = class { ) ]); } + /** Delete a tournament record. */ + deleteTournamentRecord(bearerToken, tournamentId, options = {}) { + if (tournamentId === null || tournamentId === void 0) { + throw new Error("'tournamentId' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/tournament/{tournamentId}".replace("{tournamentId}", encodeURIComponent(String(tournamentId))); + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("DELETE", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** List tournament records. */ listTournamentRecords(bearerToken, tournamentId, ownerIds, limit, cursor, expiry, options = {}) { if (tournamentId === null || tournamentId === void 0) { @@ -2721,17 +2963,17 @@ var NakamaApi = class { ]); } /** Write a record to a tournament. */ - writeTournamentRecord2(bearerToken, tournamentId, body, options = {}) { + writeTournamentRecord2(bearerToken, tournamentId, record, options = {}) { if (tournamentId === null || tournamentId === void 0) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === void 0) { + throw new Error("'record' is a required parameter but is null or undefined."); } const urlPath = "/v2/tournament/{tournamentId}".replace("{tournamentId}", encodeURIComponent(String(tournamentId))); const queryParams = /* @__PURE__ */ new Map(); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -2753,17 +2995,17 @@ var NakamaApi = class { ]); } /** Write a record to a tournament. */ - writeTournamentRecord(bearerToken, tournamentId, body, options = {}) { + writeTournamentRecord(bearerToken, tournamentId, record, options = {}) { if (tournamentId === null || tournamentId === void 0) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === void 0) { + throw new Error("'record' is a required parameter but is null or undefined."); } const urlPath = "/v2/tournament/{tournamentId}".replace("{tournamentId}", encodeURIComponent(String(tournamentId))); const queryParams = /* @__PURE__ */ new Map(); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("PUT", options, bodyJson); if (bearerToken) { @@ -2813,7 +3055,7 @@ var NakamaApi = class { ]); } /** List tournament records for a given owner. */ - listTournamentRecordsAroundOwner(bearerToken, tournamentId, ownerId, limit, expiry, options = {}) { + listTournamentRecordsAroundOwner(bearerToken, tournamentId, ownerId, limit, expiry, cursor, options = {}) { if (tournamentId === null || tournamentId === void 0) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } @@ -2824,6 +3066,7 @@ var NakamaApi = class { const queryParams = /* @__PURE__ */ new Map(); queryParams.set("limit", limit); queryParams.set("expiry", expiry); + queryParams.set("cursor", cursor); let bodyJson = ""; const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("GET", options, bodyJson); @@ -3786,6 +4029,17 @@ var Client = class { createSocket(useSSL = false, verbose = false, adapter = new WebSocketAdapterText(), sendTimeoutMs = DefaultSocket.DefaultSendTimeoutMs) { return new DefaultSocket(this.host, this.port, useSSL, verbose, adapter, sendTimeoutMs); } + /** Delete the current user's account. */ + deleteAccount(session) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.deleteAccount(session.token).then((response) => { + return response !== void 0; + }); + }); + } /** Delete one or more users by ID or username. */ deleteFriends(session, ids, usernames) { return __async(this, null, function* () { @@ -3830,6 +4084,12 @@ var Client = class { }); }); } + /** Delete a tournament record. */ + deleteTournamentRecord(session, tournamentId) { + return __async(this, null, function* () { + return this.apiClient.deleteTournamentRecord(session.token, tournamentId); + }); + } /** Demote a set of users in a group to the next role down. */ demoteGroupUsers(session, groupId, ids) { return __async(this, null, function* () { @@ -3861,6 +4121,15 @@ var Client = class { return this.apiClient.getAccount(session.token); }); } + /** Get subscription by product id. */ + getSubscription(session, productId) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.getSubscription(session.token, productId); + }); + } /** Import Facebook friends and add them to a user's account. */ importFacebookFriends(session, request) { return __async(this, null, function* () { @@ -4253,6 +4522,48 @@ var Client = class { }); }); } + /** List friends of friends for the current user. */ + listFriendsOfFriends(session, limit, cursor) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.listFriendsOfFriends(session.token, limit, cursor).then((response) => { + var result = { + friends_of_friends: [], + cursor: response.cursor + }; + if (response.friends_of_friends == null) { + return Promise.resolve(result); + } + response.friends_of_friends.forEach((f) => { + result.friends_of_friends.push({ + referrer: f.referrer, + user: { + avatar_url: f.user.avatar_url, + create_time: f.user.create_time, + display_name: f.user.display_name, + edge_count: f.user.edge_count ? Number(f.user.edge_count) : 0, + facebook_id: f.user.facebook_id, + gamecenter_id: f.user.gamecenter_id, + google_id: f.user.google_id, + id: f.user.id, + lang_tag: f.user.lang_tag, + location: f.user.location, + online: f.user.online, + steam_id: f.user.steam_id, + timezone: f.user.timezone, + update_time: f.user.update_time, + username: f.user.username, + metadata: f.user.metadata ? JSON.parse(f.user.metadata) : void 0, + facebook_instant_game_id: f.user.facebook_instant_game_id + } + }); + }); + return Promise.resolve(result); + }); + }); + } /** List leaderboard records */ listLeaderboardRecords(session, leaderboardId, ownerIds, limit, cursor, expiry) { return __async(this, null, function* () { @@ -4263,6 +4574,7 @@ var Client = class { var list = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, + rank_count: response.rank_count ? Number(response.rank_count) : 0, owner_records: [], records: [] }; @@ -4304,15 +4616,16 @@ var Client = class { }); }); } - listLeaderboardRecordsAroundOwner(session, leaderboardId, ownerId, limit, expiry) { + listLeaderboardRecordsAroundOwner(session, leaderboardId, ownerId, limit, expiry, cursor) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.listLeaderboardRecordsAroundOwner(session.token, leaderboardId, ownerId, limit, expiry).then((response) => { + return this.apiClient.listLeaderboardRecordsAroundOwner(session.token, leaderboardId, ownerId, limit, expiry, cursor).then((response) => { var list = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, + rank_count: response.rank_count ? Number(response.rank_count) : 0, owner_records: [], records: [] }; @@ -4453,7 +4766,8 @@ var Client = class { create_time: o.create_time, start_time: o.start_time, end_time: o.end_time, - start_active: o.start_active + start_active: o.start_active, + authoritative: o.authoritative }); }); } @@ -4461,6 +4775,18 @@ var Client = class { }); }); } + /** List user subscriptions. */ + listSubscriptions(session, cursor, limit) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.listSubscriptions(session.token, { + cursor, + limit + }); + }); + } /** List tournament records from a given tournament. */ listTournamentRecords(session, tournamentId, ownerIds, limit, cursor, expiry) { return __async(this, null, function* () { @@ -4513,12 +4839,12 @@ var Client = class { }); } /** List tournament records from a given tournament around the owner. */ - listTournamentRecordsAroundOwner(session, tournamentId, ownerId, limit, expiry) { + listTournamentRecordsAroundOwner(session, tournamentId, ownerId, limit, expiry, cursor) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.listTournamentRecordsAroundOwner(session.token, tournamentId, ownerId, limit, expiry).then((response) => { + return this.apiClient.listTournamentRecordsAroundOwner(session.token, tournamentId, ownerId, limit, expiry, cursor).then((response) => { var list = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, @@ -4778,30 +5104,57 @@ var Client = class { }); } /** Validate an Apple IAP receipt. */ - validatePurchaseApple(session, receipt) { + validatePurchaseApple(session, receipt, persist = true) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.validatePurchaseApple(session.token, { receipt, persist }); + }); + } + /** Validate a FB Instant IAP receipt. */ + validatePurchaseFacebookInstant(session, signedRequest, persist = true) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.validatePurchaseApple(session.token, { receipt }); + return this.apiClient.validatePurchaseFacebookInstant(session.token, { signed_request: signedRequest, persist }); }); } /** Validate a Google IAP receipt. */ - validatePurchaseGoogle(session, purchase) { + validatePurchaseGoogle(session, purchase, persist = true) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.validatePurchaseGoogle(session.token, { purchase }); + return this.apiClient.validatePurchaseGoogle(session.token, { purchase, persist }); }); } /** Validate a Huawei IAP receipt. */ - validatePurchaseHuawei(session, purchase, signature) { + validatePurchaseHuawei(session, purchase, signature, persist = true) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.validatePurchaseHuawei(session.token, { purchase, signature, persist }); + }); + } + /** Validate Apple Subscription Receipt */ + validateSubscriptionApple(session, receipt, persist = true) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.validateSubscriptionApple(session.token, { receipt, persist }); + }); + } + /** Validate Google Subscription Receipt */ + validateSubscriptionGoogle(session, receipt, persist = true) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.validatePurchaseHuawei(session.token, { purchase, signature }); + return this.apiClient.validateSubscriptionGoogle(session.token, { receipt, persist }); }); } /** Write a record to a leaderboard. */ diff --git a/packages/nakama-js/dist/nakama-js.iife.js b/packages/nakama-js/dist/nakama-js.iife.js index 73bdd70..944642a 100644 --- a/packages/nakama-js/dist/nakama-js.iife.js +++ b/packages/nakama-js/dist/nakama-js.iife.js @@ -693,6 +693,31 @@ var nakamajs = (() => { ) ]); } + /** Delete the current user's account. */ + deleteAccount(bearerToken, options = {}) { + const urlPath = "/v2/account"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("DELETE", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** Fetch the current user's account. */ getAccount(bearerToken, options = {}) { const urlPath = "/v2/account"; @@ -748,19 +773,21 @@ var nakamajs = (() => { ]); } /** Authenticate a user with an Apple ID against the server. */ - authenticateApple(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateApple(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/apple"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -777,19 +804,21 @@ var nakamajs = (() => { ]); } /** Authenticate a user with a custom id against the server. */ - authenticateCustom(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateCustom(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/custom"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -806,19 +835,21 @@ var nakamajs = (() => { ]); } /** Authenticate a user with a device id against the server. */ - authenticateDevice(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateDevice(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/device"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -835,19 +866,21 @@ var nakamajs = (() => { ]); } /** Authenticate a user with an email+password against the server. */ - authenticateEmail(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateEmail(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/email"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -864,9 +897,9 @@ var nakamajs = (() => { ]); } /** Authenticate a user with a Facebook OAuth token against the server. */ - authenticateFacebook(basicAuthUsername, basicAuthPassword, body, create, username, sync, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateFacebook(basicAuthUsername, basicAuthPassword, account, create, username, sync, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/facebook"; const queryParams = /* @__PURE__ */ new Map(); @@ -874,10 +907,12 @@ var nakamajs = (() => { queryParams.set("username", username); queryParams.set("sync", sync); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -894,19 +929,21 @@ var nakamajs = (() => { ]); } /** Authenticate a user with a Facebook Instant Game token against the server. */ - authenticateFacebookInstantGame(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateFacebookInstantGame(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/facebookinstantgame"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -923,19 +960,21 @@ var nakamajs = (() => { ]); } /** Authenticate a user with Apple's GameCenter against the server. */ - authenticateGameCenter(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateGameCenter(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/gamecenter"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -952,19 +991,21 @@ var nakamajs = (() => { ]); } /** Authenticate a user with Google against the server. */ - authenticateGoogle(basicAuthUsername, basicAuthPassword, body, create, username, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateGoogle(basicAuthUsername, basicAuthPassword, account, create, username, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/google"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("create", create); queryParams.set("username", username); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -981,9 +1022,9 @@ var nakamajs = (() => { ]); } /** Authenticate a user with Steam against the server. */ - authenticateSteam(basicAuthUsername, basicAuthPassword, body, create, username, sync, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + authenticateSteam(basicAuthUsername, basicAuthPassword, account, create, username, sync, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/authenticate/steam"; const queryParams = /* @__PURE__ */ new Map(); @@ -991,10 +1032,12 @@ var nakamajs = (() => { queryParams.set("username", username); queryParams.set("sync", sync); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -1127,15 +1170,15 @@ var nakamajs = (() => { ]); } /** Add Facebook to the social profiles on the current user's account. */ - linkFacebook(bearerToken, body, sync, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + linkFacebook(bearerToken, account, sync, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/account/link/facebook"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("sync", sync); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -1283,7 +1326,9 @@ var nakamajs = (() => { bodyJson = JSON.stringify(body || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then((response) => { if (response.status == 204) { @@ -1730,15 +1775,15 @@ var nakamajs = (() => { ]); } /** Import Facebook friends and add them to a user's account. */ - importFacebookFriends(bearerToken, body, reset, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + importFacebookFriends(bearerToken, account, reset, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/friend/facebook"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("reset", reset); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -1759,16 +1804,43 @@ var nakamajs = (() => { ) ]); } + /** List friends of friends for the current user. */ + listFriendsOfFriends(bearerToken, limit, cursor, options = {}) { + const urlPath = "/v2/friend/friends"; + const queryParams = /* @__PURE__ */ new Map(); + queryParams.set("limit", limit); + queryParams.set("cursor", cursor); + let bodyJson = ""; + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("GET", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** Import Steam friends and add them to a user's account. */ - importSteamFriends(bearerToken, body, reset, options = {}) { - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + importSteamFriends(bearerToken, account, reset, options = {}) { + if (account === null || account === void 0) { + throw new Error("'account' is a required parameter but is null or undefined."); } const urlPath = "/v2/friend/steam"; const queryParams = /* @__PURE__ */ new Map(); queryParams.set("reset", reset); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -1972,9 +2044,6 @@ var nakamajs = (() => { if (groupId === null || groupId === void 0) { throw new Error("'groupId' is a required parameter but is null or undefined."); } - if (userIds === null || userIds === void 0) { - throw new Error("'userIds' is a required parameter but is null or undefined."); - } const urlPath = "/v2/group/{groupId}/demote".replace("{groupId}", encodeURIComponent(String(groupId))); const queryParams = /* @__PURE__ */ new Map(); queryParams.set("user_ids", userIds); @@ -2173,6 +2242,35 @@ var nakamajs = (() => { ) ]); } + /** Validate FB Instant IAP Receipt */ + validatePurchaseFacebookInstant(bearerToken, body, options = {}) { + if (body === null || body === void 0) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/purchase/facebookinstant"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** Validate Google IAP Receipt */ validatePurchaseGoogle(bearerToken, body, options = {}) { if (body === null || body === void 0) { @@ -2231,6 +2329,121 @@ var nakamajs = (() => { ) ]); } + /** List user's subscriptions. */ + listSubscriptions(bearerToken, body, options = {}) { + if (body === null || body === void 0) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } + /** Validate Apple Subscription Receipt */ + validateSubscriptionApple(bearerToken, body, options = {}) { + if (body === null || body === void 0) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription/apple"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } + /** Validate Google Subscription Receipt */ + validateSubscriptionGoogle(bearerToken, body, options = {}) { + if (body === null || body === void 0) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription/google"; + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } + /** Get subscription by product id. */ + getSubscription(bearerToken, productId, options = {}) { + if (productId === null || productId === void 0) { + throw new Error("'productId' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/iap/subscription/{productId}".replace("{productId}", encodeURIComponent(String(productId))); + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("GET", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** Delete a leaderboard record. */ deleteLeaderboardRecord(bearerToken, leaderboardId, options = {}) { if (leaderboardId === null || leaderboardId === void 0) { @@ -2292,17 +2505,17 @@ var nakamajs = (() => { ]); } /** Write a record to a leaderboard. */ - writeLeaderboardRecord(bearerToken, leaderboardId, body, options = {}) { + writeLeaderboardRecord(bearerToken, leaderboardId, record, options = {}) { if (leaderboardId === null || leaderboardId === void 0) { throw new Error("'leaderboardId' is a required parameter but is null or undefined."); } - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === void 0) { + throw new Error("'record' is a required parameter but is null or undefined."); } const urlPath = "/v2/leaderboard/{leaderboardId}".replace("{leaderboardId}", encodeURIComponent(String(leaderboardId))); const queryParams = /* @__PURE__ */ new Map(); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -2324,7 +2537,7 @@ var nakamajs = (() => { ]); } /** List leaderboard records that belong to a user. */ - listLeaderboardRecordsAroundOwner(bearerToken, leaderboardId, ownerId, limit, expiry, options = {}) { + listLeaderboardRecordsAroundOwner(bearerToken, leaderboardId, ownerId, limit, expiry, cursor, options = {}) { if (leaderboardId === null || leaderboardId === void 0) { throw new Error("'leaderboardId' is a required parameter but is null or undefined."); } @@ -2335,6 +2548,7 @@ var nakamajs = (() => { const queryParams = /* @__PURE__ */ new Map(); queryParams.set("limit", limit); queryParams.set("expiry", expiry); + queryParams.set("cursor", cursor); let bodyJson = ""; const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("GET", options, bodyJson); @@ -2714,6 +2928,34 @@ var nakamajs = (() => { ) ]); } + /** Delete a tournament record. */ + deleteTournamentRecord(bearerToken, tournamentId, options = {}) { + if (tournamentId === null || tournamentId === void 0) { + throw new Error("'tournamentId' is a required parameter but is null or undefined."); + } + const urlPath = "/v2/tournament/{tournamentId}".replace("{tournamentId}", encodeURIComponent(String(tournamentId))); + const queryParams = /* @__PURE__ */ new Map(); + let bodyJson = ""; + const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + const fetchOptions = buildFetchOptions("DELETE", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then((response) => { + if (response.status == 204) { + return response; + } else if (response.status >= 200 && response.status < 300) { + return response.json(); + } else { + throw response; + } + }), + new Promise( + (_, reject) => setTimeout(reject, this.timeoutMs, "Request timed out.") + ) + ]); + } /** List tournament records. */ listTournamentRecords(bearerToken, tournamentId, ownerIds, limit, cursor, expiry, options = {}) { if (tournamentId === null || tournamentId === void 0) { @@ -2747,17 +2989,17 @@ var nakamajs = (() => { ]); } /** Write a record to a tournament. */ - writeTournamentRecord2(bearerToken, tournamentId, body, options = {}) { + writeTournamentRecord2(bearerToken, tournamentId, record, options = {}) { if (tournamentId === null || tournamentId === void 0) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === void 0) { + throw new Error("'record' is a required parameter but is null or undefined."); } const urlPath = "/v2/tournament/{tournamentId}".replace("{tournamentId}", encodeURIComponent(String(tournamentId))); const queryParams = /* @__PURE__ */ new Map(); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -2779,17 +3021,17 @@ var nakamajs = (() => { ]); } /** Write a record to a tournament. */ - writeTournamentRecord(bearerToken, tournamentId, body, options = {}) { + writeTournamentRecord(bearerToken, tournamentId, record, options = {}) { if (tournamentId === null || tournamentId === void 0) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } - if (body === null || body === void 0) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === void 0) { + throw new Error("'record' is a required parameter but is null or undefined."); } const urlPath = "/v2/tournament/{tournamentId}".replace("{tournamentId}", encodeURIComponent(String(tournamentId))); const queryParams = /* @__PURE__ */ new Map(); let bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("PUT", options, bodyJson); if (bearerToken) { @@ -2839,7 +3081,7 @@ var nakamajs = (() => { ]); } /** List tournament records for a given owner. */ - listTournamentRecordsAroundOwner(bearerToken, tournamentId, ownerId, limit, expiry, options = {}) { + listTournamentRecordsAroundOwner(bearerToken, tournamentId, ownerId, limit, expiry, cursor, options = {}) { if (tournamentId === null || tournamentId === void 0) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } @@ -2850,6 +3092,7 @@ var nakamajs = (() => { const queryParams = /* @__PURE__ */ new Map(); queryParams.set("limit", limit); queryParams.set("expiry", expiry); + queryParams.set("cursor", cursor); let bodyJson = ""; const fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); const fetchOptions = buildFetchOptions("GET", options, bodyJson); @@ -3812,6 +4055,17 @@ var nakamajs = (() => { createSocket(useSSL = false, verbose = false, adapter = new WebSocketAdapterText(), sendTimeoutMs = DefaultSocket.DefaultSendTimeoutMs) { return new DefaultSocket(this.host, this.port, useSSL, verbose, adapter, sendTimeoutMs); } + /** Delete the current user's account. */ + deleteAccount(session) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.deleteAccount(session.token).then((response) => { + return response !== void 0; + }); + }); + } /** Delete one or more users by ID or username. */ deleteFriends(session, ids, usernames) { return __async(this, null, function* () { @@ -3856,6 +4110,12 @@ var nakamajs = (() => { }); }); } + /** Delete a tournament record. */ + deleteTournamentRecord(session, tournamentId) { + return __async(this, null, function* () { + return this.apiClient.deleteTournamentRecord(session.token, tournamentId); + }); + } /** Demote a set of users in a group to the next role down. */ demoteGroupUsers(session, groupId, ids) { return __async(this, null, function* () { @@ -3887,6 +4147,15 @@ var nakamajs = (() => { return this.apiClient.getAccount(session.token); }); } + /** Get subscription by product id. */ + getSubscription(session, productId) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.getSubscription(session.token, productId); + }); + } /** Import Facebook friends and add them to a user's account. */ importFacebookFriends(session, request) { return __async(this, null, function* () { @@ -4279,6 +4548,48 @@ var nakamajs = (() => { }); }); } + /** List friends of friends for the current user. */ + listFriendsOfFriends(session, limit, cursor) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.listFriendsOfFriends(session.token, limit, cursor).then((response) => { + var result = { + friends_of_friends: [], + cursor: response.cursor + }; + if (response.friends_of_friends == null) { + return Promise.resolve(result); + } + response.friends_of_friends.forEach((f) => { + result.friends_of_friends.push({ + referrer: f.referrer, + user: { + avatar_url: f.user.avatar_url, + create_time: f.user.create_time, + display_name: f.user.display_name, + edge_count: f.user.edge_count ? Number(f.user.edge_count) : 0, + facebook_id: f.user.facebook_id, + gamecenter_id: f.user.gamecenter_id, + google_id: f.user.google_id, + id: f.user.id, + lang_tag: f.user.lang_tag, + location: f.user.location, + online: f.user.online, + steam_id: f.user.steam_id, + timezone: f.user.timezone, + update_time: f.user.update_time, + username: f.user.username, + metadata: f.user.metadata ? JSON.parse(f.user.metadata) : void 0, + facebook_instant_game_id: f.user.facebook_instant_game_id + } + }); + }); + return Promise.resolve(result); + }); + }); + } /** List leaderboard records */ listLeaderboardRecords(session, leaderboardId, ownerIds, limit, cursor, expiry) { return __async(this, null, function* () { @@ -4289,6 +4600,7 @@ var nakamajs = (() => { var list = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, + rank_count: response.rank_count ? Number(response.rank_count) : 0, owner_records: [], records: [] }; @@ -4330,15 +4642,16 @@ var nakamajs = (() => { }); }); } - listLeaderboardRecordsAroundOwner(session, leaderboardId, ownerId, limit, expiry) { + listLeaderboardRecordsAroundOwner(session, leaderboardId, ownerId, limit, expiry, cursor) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.listLeaderboardRecordsAroundOwner(session.token, leaderboardId, ownerId, limit, expiry).then((response) => { + return this.apiClient.listLeaderboardRecordsAroundOwner(session.token, leaderboardId, ownerId, limit, expiry, cursor).then((response) => { var list = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, + rank_count: response.rank_count ? Number(response.rank_count) : 0, owner_records: [], records: [] }; @@ -4479,7 +4792,8 @@ var nakamajs = (() => { create_time: o.create_time, start_time: o.start_time, end_time: o.end_time, - start_active: o.start_active + start_active: o.start_active, + authoritative: o.authoritative }); }); } @@ -4487,6 +4801,18 @@ var nakamajs = (() => { }); }); } + /** List user subscriptions. */ + listSubscriptions(session, cursor, limit) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.listSubscriptions(session.token, { + cursor, + limit + }); + }); + } /** List tournament records from a given tournament. */ listTournamentRecords(session, tournamentId, ownerIds, limit, cursor, expiry) { return __async(this, null, function* () { @@ -4539,12 +4865,12 @@ var nakamajs = (() => { }); } /** List tournament records from a given tournament around the owner. */ - listTournamentRecordsAroundOwner(session, tournamentId, ownerId, limit, expiry) { + listTournamentRecordsAroundOwner(session, tournamentId, ownerId, limit, expiry, cursor) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.listTournamentRecordsAroundOwner(session.token, tournamentId, ownerId, limit, expiry).then((response) => { + return this.apiClient.listTournamentRecordsAroundOwner(session.token, tournamentId, ownerId, limit, expiry, cursor).then((response) => { var list = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, @@ -4804,30 +5130,57 @@ var nakamajs = (() => { }); } /** Validate an Apple IAP receipt. */ - validatePurchaseApple(session, receipt) { + validatePurchaseApple(session, receipt, persist = true) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.validatePurchaseApple(session.token, { receipt, persist }); + }); + } + /** Validate a FB Instant IAP receipt. */ + validatePurchaseFacebookInstant(session, signedRequest, persist = true) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.validatePurchaseApple(session.token, { receipt }); + return this.apiClient.validatePurchaseFacebookInstant(session.token, { signed_request: signedRequest, persist }); }); } /** Validate a Google IAP receipt. */ - validatePurchaseGoogle(session, purchase) { + validatePurchaseGoogle(session, purchase, persist = true) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.validatePurchaseGoogle(session.token, { purchase }); + return this.apiClient.validatePurchaseGoogle(session.token, { purchase, persist }); }); } /** Validate a Huawei IAP receipt. */ - validatePurchaseHuawei(session, purchase, signature) { + validatePurchaseHuawei(session, purchase, signature, persist = true) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.validatePurchaseHuawei(session.token, { purchase, signature, persist }); + }); + } + /** Validate Apple Subscription Receipt */ + validateSubscriptionApple(session, receipt, persist = true) { + return __async(this, null, function* () { + if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { + yield this.sessionRefresh(session); + } + return this.apiClient.validateSubscriptionApple(session.token, { receipt, persist }); + }); + } + /** Validate Google Subscription Receipt */ + validateSubscriptionGoogle(session, receipt, persist = true) { return __async(this, null, function* () { if (this.autoRefreshSession && session.refresh_token && session.isexpired((Date.now() + this.expiredTimespanMs) / 1e3)) { yield this.sessionRefresh(session); } - return this.apiClient.validatePurchaseHuawei(session.token, { purchase, signature }); + return this.apiClient.validateSubscriptionGoogle(session.token, { receipt, persist }); }); } /** Write a record to a leaderboard. */ diff --git a/packages/nakama-js/dist/nakama-js.umd.js b/packages/nakama-js/dist/nakama-js.umd.js index 47ba85b..5812d9d 100644 --- a/packages/nakama-js/dist/nakama-js.umd.js +++ b/packages/nakama-js/dist/nakama-js.umd.js @@ -925,30 +925,6 @@ // tslint:disable /* Code generated by openapi-gen/main.go. DO NOT EDIT. */ /** - * Environment where the purchase took place - */ - var ValidatedPurchaseEnvironment; - (function (ValidatedPurchaseEnvironment) { - /* - UNKNOWN: Unknown environment. */ - ValidatedPurchaseEnvironment[ValidatedPurchaseEnvironment["UNKNOWN"] = 0] = "UNKNOWN"; - /* - SANDBOX: Sandbox/test environment. */ - ValidatedPurchaseEnvironment[ValidatedPurchaseEnvironment["SANDBOX"] = 1] = "SANDBOX"; - /* - PRODUCTION: Production environment. */ - ValidatedPurchaseEnvironment[ValidatedPurchaseEnvironment["PRODUCTION"] = 2] = "PRODUCTION"; - })(ValidatedPurchaseEnvironment || (ValidatedPurchaseEnvironment = {})); - /** - * Validation Provider - */ - var ValidatedPurchaseStore; - (function (ValidatedPurchaseStore) { - /* - APPLE_APP_STORE: Apple App Store */ - ValidatedPurchaseStore[ValidatedPurchaseStore["APPLE_APP_STORE"] = 0] = "APPLE_APP_STORE"; - /* - GOOGLE_PLAY_STORE: Google Play Store */ - ValidatedPurchaseStore[ValidatedPurchaseStore["GOOGLE_PLAY_STORE"] = 1] = "GOOGLE_PLAY_STORE"; - /* - HUAWEI_APP_GALLERY: Huawei App Gallery */ - ValidatedPurchaseStore[ValidatedPurchaseStore["HUAWEI_APP_GALLERY"] = 2] = "HUAWEI_APP_GALLERY"; - })(ValidatedPurchaseStore || (ValidatedPurchaseStore = {})); - /** * Operator that can be used to override the one set in the leaderboard. */ var ApiOperator; @@ -964,6 +940,32 @@ /* - DECREMENT: Override the leaderboard operator with DECREMENT. */ ApiOperator[ApiOperator["DECREMENT"] = 4] = "DECREMENT"; })(ApiOperator || (ApiOperator = {})); + /** + * Environment where a purchase/subscription took place, + */ + var ApiStoreEnvironment; + (function (ApiStoreEnvironment) { + /* - UNKNOWN: Unknown environment. */ + ApiStoreEnvironment[ApiStoreEnvironment["UNKNOWN"] = 0] = "UNKNOWN"; + /* - SANDBOX: Sandbox/test environment. */ + ApiStoreEnvironment[ApiStoreEnvironment["SANDBOX"] = 1] = "SANDBOX"; + /* - PRODUCTION: Production environment. */ + ApiStoreEnvironment[ApiStoreEnvironment["PRODUCTION"] = 2] = "PRODUCTION"; + })(ApiStoreEnvironment || (ApiStoreEnvironment = {})); + /** + * Validation Provider, + */ + var ApiStoreProvider; + (function (ApiStoreProvider) { + /* - APPLE_APP_STORE: Apple App Store */ + ApiStoreProvider[ApiStoreProvider["APPLE_APP_STORE"] = 0] = "APPLE_APP_STORE"; + /* - GOOGLE_PLAY_STORE: Google Play Store */ + ApiStoreProvider[ApiStoreProvider["GOOGLE_PLAY_STORE"] = 1] = "GOOGLE_PLAY_STORE"; + /* - HUAWEI_APP_GALLERY: Huawei App Gallery */ + ApiStoreProvider[ApiStoreProvider["HUAWEI_APP_GALLERY"] = 2] = "HUAWEI_APP_GALLERY"; + /* - FACEBOOK_INSTANT_STORE: Facebook Instant Store */ + ApiStoreProvider[ApiStoreProvider["FACEBOOK_INSTANT_STORE"] = 3] = "FACEBOOK_INSTANT_STORE"; + })(ApiStoreProvider || (ApiStoreProvider = {})); var NakamaApi = /** @class */ (function () { function NakamaApi(serverKey, basePath, timeoutMs) { this.serverKey = serverKey; @@ -999,6 +1001,35 @@ }), ]); }; + /** Delete the current user's account. */ + NakamaApi.prototype.deleteAccount = function (bearerToken, options) { + var _this = this; + if (options === void 0) { options = {}; } + var urlPath = "/v2/account"; + var queryParams = new Map(); + var bodyJson = ""; + var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + var fetchOptions = buildFetchOptions("DELETE", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then(function (response) { + if (response.status == 204) { + return response; + } + else if (response.status >= 200 && response.status < 300) { + return response.json(); + } + else { + throw response; + } + }), + new Promise(function (_, reject) { + return setTimeout(reject, _this.timeoutMs, "Request timed out."); + }), + ]); + }; /** Fetch the current user's account. */ NakamaApi.prototype.getAccount = function (bearerToken, options) { var _this = this; @@ -1062,21 +1093,23 @@ ]); }; /** Authenticate a user with an Apple ID against the server. */ - NakamaApi.prototype.authenticateApple = function (basicAuthUsername, basicAuthPassword, body, create, username, options) { + NakamaApi.prototype.authenticateApple = function (basicAuthUsername, basicAuthPassword, account, create, username, options) { var _this = this; if (options === void 0) { options = {}; } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } var urlPath = "/v2/account/authenticate/apple"; var queryParams = new Map(); queryParams.set("create", create); queryParams.set("username", username); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then(function (response) { if (response.status == 204) { @@ -1095,21 +1128,23 @@ ]); }; /** Authenticate a user with a custom id against the server. */ - NakamaApi.prototype.authenticateCustom = function (basicAuthUsername, basicAuthPassword, body, create, username, options) { + NakamaApi.prototype.authenticateCustom = function (basicAuthUsername, basicAuthPassword, account, create, username, options) { var _this = this; if (options === void 0) { options = {}; } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } var urlPath = "/v2/account/authenticate/custom"; var queryParams = new Map(); queryParams.set("create", create); queryParams.set("username", username); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then(function (response) { if (response.status == 204) { @@ -1128,21 +1163,23 @@ ]); }; /** Authenticate a user with a device id against the server. */ - NakamaApi.prototype.authenticateDevice = function (basicAuthUsername, basicAuthPassword, body, create, username, options) { + NakamaApi.prototype.authenticateDevice = function (basicAuthUsername, basicAuthPassword, account, create, username, options) { var _this = this; if (options === void 0) { options = {}; } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } var urlPath = "/v2/account/authenticate/device"; var queryParams = new Map(); queryParams.set("create", create); queryParams.set("username", username); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then(function (response) { if (response.status == 204) { @@ -1161,21 +1198,23 @@ ]); }; /** Authenticate a user with an email+password against the server. */ - NakamaApi.prototype.authenticateEmail = function (basicAuthUsername, basicAuthPassword, body, create, username, options) { + NakamaApi.prototype.authenticateEmail = function (basicAuthUsername, basicAuthPassword, account, create, username, options) { var _this = this; if (options === void 0) { options = {}; } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } var urlPath = "/v2/account/authenticate/email"; var queryParams = new Map(); queryParams.set("create", create); queryParams.set("username", username); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then(function (response) { if (response.status == 204) { @@ -1194,11 +1233,11 @@ ]); }; /** Authenticate a user with a Facebook OAuth token against the server. */ - NakamaApi.prototype.authenticateFacebook = function (basicAuthUsername, basicAuthPassword, body, create, username, sync, options) { + NakamaApi.prototype.authenticateFacebook = function (basicAuthUsername, basicAuthPassword, account, create, username, sync, options) { var _this = this; if (options === void 0) { options = {}; } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } var urlPath = "/v2/account/authenticate/facebook"; var queryParams = new Map(); @@ -1206,10 +1245,12 @@ queryParams.set("username", username); queryParams.set("sync", sync); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then(function (response) { if (response.status == 204) { @@ -1228,21 +1269,23 @@ ]); }; /** Authenticate a user with a Facebook Instant Game token against the server. */ - NakamaApi.prototype.authenticateFacebookInstantGame = function (basicAuthUsername, basicAuthPassword, body, create, username, options) { + NakamaApi.prototype.authenticateFacebookInstantGame = function (basicAuthUsername, basicAuthPassword, account, create, username, options) { var _this = this; if (options === void 0) { options = {}; } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } var urlPath = "/v2/account/authenticate/facebookinstantgame"; var queryParams = new Map(); queryParams.set("create", create); queryParams.set("username", username); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then(function (response) { if (response.status == 204) { @@ -1261,21 +1304,23 @@ ]); }; /** Authenticate a user with Apple's GameCenter against the server. */ - NakamaApi.prototype.authenticateGameCenter = function (basicAuthUsername, basicAuthPassword, body, create, username, options) { + NakamaApi.prototype.authenticateGameCenter = function (basicAuthUsername, basicAuthPassword, account, create, username, options) { var _this = this; if (options === void 0) { options = {}; } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } var urlPath = "/v2/account/authenticate/gamecenter"; var queryParams = new Map(); queryParams.set("create", create); queryParams.set("username", username); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then(function (response) { if (response.status == 204) { @@ -1294,21 +1339,23 @@ ]); }; /** Authenticate a user with Google against the server. */ - NakamaApi.prototype.authenticateGoogle = function (basicAuthUsername, basicAuthPassword, body, create, username, options) { + NakamaApi.prototype.authenticateGoogle = function (basicAuthUsername, basicAuthPassword, account, create, username, options) { var _this = this; if (options === void 0) { options = {}; } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } var urlPath = "/v2/account/authenticate/google"; var queryParams = new Map(); queryParams.set("create", create); queryParams.set("username", username); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then(function (response) { if (response.status == 204) { @@ -1327,11 +1374,11 @@ ]); }; /** Authenticate a user with Steam against the server. */ - NakamaApi.prototype.authenticateSteam = function (basicAuthUsername, basicAuthPassword, body, create, username, sync, options) { + NakamaApi.prototype.authenticateSteam = function (basicAuthUsername, basicAuthPassword, account, create, username, sync, options) { var _this = this; if (options === void 0) { options = {}; } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } var urlPath = "/v2/account/authenticate/steam"; var queryParams = new Map(); @@ -1339,10 +1386,12 @@ queryParams.set("username", username); queryParams.set("sync", sync); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then(function (response) { if (response.status == 204) { @@ -1493,17 +1542,17 @@ ]); }; /** Add Facebook to the social profiles on the current user's account. */ - NakamaApi.prototype.linkFacebook = function (bearerToken, body, sync, options) { + NakamaApi.prototype.linkFacebook = function (bearerToken, account, sync, options) { var _this = this; if (options === void 0) { options = {}; } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } var urlPath = "/v2/account/link/facebook"; var queryParams = new Map(); queryParams.set("sync", sync); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -1671,7 +1720,9 @@ bodyJson = JSON.stringify(body || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); - fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + if (basicAuthUsername) { + fetchOptions.headers["Authorization"] = "Basic " + encode$1(basicAuthUsername + ":" + basicAuthPassword); + } return Promise.race([ fetch(fullUrl, fetchOptions).then(function (response) { if (response.status == 204) { @@ -2181,17 +2232,17 @@ ]); }; /** Import Facebook friends and add them to a user's account. */ - NakamaApi.prototype.importFacebookFriends = function (bearerToken, body, reset, options) { + NakamaApi.prototype.importFacebookFriends = function (bearerToken, account, reset, options) { var _this = this; if (options === void 0) { options = {}; } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } var urlPath = "/v2/friend/facebook"; var queryParams = new Map(); queryParams.set("reset", reset); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -2214,18 +2265,49 @@ }), ]); }; + /** List friends of friends for the current user. */ + NakamaApi.prototype.listFriendsOfFriends = function (bearerToken, limit, cursor, options) { + var _this = this; + if (options === void 0) { options = {}; } + var urlPath = "/v2/friend/friends"; + var queryParams = new Map(); + queryParams.set("limit", limit); + queryParams.set("cursor", cursor); + var bodyJson = ""; + var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + var fetchOptions = buildFetchOptions("GET", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then(function (response) { + if (response.status == 204) { + return response; + } + else if (response.status >= 200 && response.status < 300) { + return response.json(); + } + else { + throw response; + } + }), + new Promise(function (_, reject) { + return setTimeout(reject, _this.timeoutMs, "Request timed out."); + }), + ]); + }; /** Import Steam friends and add them to a user's account. */ - NakamaApi.prototype.importSteamFriends = function (bearerToken, body, reset, options) { + NakamaApi.prototype.importSteamFriends = function (bearerToken, account, reset, options) { var _this = this; if (options === void 0) { options = {}; } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (account === null || account === undefined) { + throw new Error("'account' is a required parameter but is null or undefined."); } var urlPath = "/v2/friend/steam"; var queryParams = new Map(); queryParams.set("reset", reset); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(account || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -2461,9 +2543,6 @@ if (groupId === null || groupId === undefined) { throw new Error("'groupId' is a required parameter but is null or undefined."); } - if (userIds === null || userIds === undefined) { - throw new Error("'userIds' is a required parameter but is null or undefined."); - } var urlPath = "/v2/group/{groupId}/demote" .replace("{groupId}", encodeURIComponent(String(groupId))); var queryParams = new Map(); @@ -2694,6 +2773,39 @@ }), ]); }; + /** Validate FB Instant IAP Receipt */ + NakamaApi.prototype.validatePurchaseFacebookInstant = function (bearerToken, body, options) { + var _this = this; + if (options === void 0) { options = {}; } + if (body === null || body === undefined) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + var urlPath = "/v2/iap/purchase/facebookinstant"; + var queryParams = new Map(); + var bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + var fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then(function (response) { + if (response.status == 204) { + return response; + } + else if (response.status >= 200 && response.status < 300) { + return response.json(); + } + else { + throw response; + } + }), + new Promise(function (_, reject) { + return setTimeout(reject, _this.timeoutMs, "Request timed out."); + }), + ]); + }; /** Validate Google IAP Receipt */ NakamaApi.prototype.validatePurchaseGoogle = function (bearerToken, body, options) { var _this = this; @@ -2760,6 +2872,138 @@ }), ]); }; + /** List user's subscriptions. */ + NakamaApi.prototype.listSubscriptions = function (bearerToken, body, options) { + var _this = this; + if (options === void 0) { options = {}; } + if (body === null || body === undefined) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + var urlPath = "/v2/iap/subscription"; + var queryParams = new Map(); + var bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + var fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then(function (response) { + if (response.status == 204) { + return response; + } + else if (response.status >= 200 && response.status < 300) { + return response.json(); + } + else { + throw response; + } + }), + new Promise(function (_, reject) { + return setTimeout(reject, _this.timeoutMs, "Request timed out."); + }), + ]); + }; + /** Validate Apple Subscription Receipt */ + NakamaApi.prototype.validateSubscriptionApple = function (bearerToken, body, options) { + var _this = this; + if (options === void 0) { options = {}; } + if (body === null || body === undefined) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + var urlPath = "/v2/iap/subscription/apple"; + var queryParams = new Map(); + var bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + var fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then(function (response) { + if (response.status == 204) { + return response; + } + else if (response.status >= 200 && response.status < 300) { + return response.json(); + } + else { + throw response; + } + }), + new Promise(function (_, reject) { + return setTimeout(reject, _this.timeoutMs, "Request timed out."); + }), + ]); + }; + /** Validate Google Subscription Receipt */ + NakamaApi.prototype.validateSubscriptionGoogle = function (bearerToken, body, options) { + var _this = this; + if (options === void 0) { options = {}; } + if (body === null || body === undefined) { + throw new Error("'body' is a required parameter but is null or undefined."); + } + var urlPath = "/v2/iap/subscription/google"; + var queryParams = new Map(); + var bodyJson = ""; + bodyJson = JSON.stringify(body || {}); + var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + var fetchOptions = buildFetchOptions("POST", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then(function (response) { + if (response.status == 204) { + return response; + } + else if (response.status >= 200 && response.status < 300) { + return response.json(); + } + else { + throw response; + } + }), + new Promise(function (_, reject) { + return setTimeout(reject, _this.timeoutMs, "Request timed out."); + }), + ]); + }; + /** Get subscription by product id. */ + NakamaApi.prototype.getSubscription = function (bearerToken, productId, options) { + var _this = this; + if (options === void 0) { options = {}; } + if (productId === null || productId === undefined) { + throw new Error("'productId' is a required parameter but is null or undefined."); + } + var urlPath = "/v2/iap/subscription/{productId}" + .replace("{productId}", encodeURIComponent(String(productId))); + var queryParams = new Map(); + var bodyJson = ""; + var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + var fetchOptions = buildFetchOptions("GET", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then(function (response) { + if (response.status == 204) { + return response; + } + else if (response.status >= 200 && response.status < 300) { + return response.json(); + } + else { + throw response; + } + }), + new Promise(function (_, reject) { + return setTimeout(reject, _this.timeoutMs, "Request timed out."); + }), + ]); + }; /** Delete a leaderboard record. */ NakamaApi.prototype.deleteLeaderboardRecord = function (bearerToken, leaderboardId, options) { var _this = this; @@ -2831,20 +3075,20 @@ ]); }; /** Write a record to a leaderboard. */ - NakamaApi.prototype.writeLeaderboardRecord = function (bearerToken, leaderboardId, body, options) { + NakamaApi.prototype.writeLeaderboardRecord = function (bearerToken, leaderboardId, record, options) { var _this = this; if (options === void 0) { options = {}; } if (leaderboardId === null || leaderboardId === undefined) { throw new Error("'leaderboardId' is a required parameter but is null or undefined."); } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === undefined) { + throw new Error("'record' is a required parameter but is null or undefined."); } var urlPath = "/v2/leaderboard/{leaderboardId}" .replace("{leaderboardId}", encodeURIComponent(String(leaderboardId))); var queryParams = new Map(); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -2868,7 +3112,7 @@ ]); }; /** List leaderboard records that belong to a user. */ - NakamaApi.prototype.listLeaderboardRecordsAroundOwner = function (bearerToken, leaderboardId, ownerId, limit, expiry, options) { + NakamaApi.prototype.listLeaderboardRecordsAroundOwner = function (bearerToken, leaderboardId, ownerId, limit, expiry, cursor, options) { var _this = this; if (options === void 0) { options = {}; } if (leaderboardId === null || leaderboardId === undefined) { @@ -2883,6 +3127,7 @@ var queryParams = new Map(); queryParams.set("limit", limit); queryParams.set("expiry", expiry); + queryParams.set("cursor", cursor); var bodyJson = ""; var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("GET", options, bodyJson); @@ -3317,6 +3562,39 @@ }), ]); }; + /** Delete a tournament record. */ + NakamaApi.prototype.deleteTournamentRecord = function (bearerToken, tournamentId, options) { + var _this = this; + if (options === void 0) { options = {}; } + if (tournamentId === null || tournamentId === undefined) { + throw new Error("'tournamentId' is a required parameter but is null or undefined."); + } + var urlPath = "/v2/tournament/{tournamentId}" + .replace("{tournamentId}", encodeURIComponent(String(tournamentId))); + var queryParams = new Map(); + var bodyJson = ""; + var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); + var fetchOptions = buildFetchOptions("DELETE", options, bodyJson); + if (bearerToken) { + fetchOptions.headers["Authorization"] = "Bearer " + bearerToken; + } + return Promise.race([ + fetch(fullUrl, fetchOptions).then(function (response) { + if (response.status == 204) { + return response; + } + else if (response.status >= 200 && response.status < 300) { + return response.json(); + } + else { + throw response; + } + }), + new Promise(function (_, reject) { + return setTimeout(reject, _this.timeoutMs, "Request timed out."); + }), + ]); + }; /** List tournament records. */ NakamaApi.prototype.listTournamentRecords = function (bearerToken, tournamentId, ownerIds, limit, cursor, expiry, options) { var _this = this; @@ -3355,20 +3633,20 @@ ]); }; /** Write a record to a tournament. */ - NakamaApi.prototype.writeTournamentRecord2 = function (bearerToken, tournamentId, body, options) { + NakamaApi.prototype.writeTournamentRecord2 = function (bearerToken, tournamentId, record, options) { var _this = this; if (options === void 0) { options = {}; } if (tournamentId === null || tournamentId === undefined) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === undefined) { + throw new Error("'record' is a required parameter but is null or undefined."); } var urlPath = "/v2/tournament/{tournamentId}" .replace("{tournamentId}", encodeURIComponent(String(tournamentId))); var queryParams = new Map(); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("POST", options, bodyJson); if (bearerToken) { @@ -3392,20 +3670,20 @@ ]); }; /** Write a record to a tournament. */ - NakamaApi.prototype.writeTournamentRecord = function (bearerToken, tournamentId, body, options) { + NakamaApi.prototype.writeTournamentRecord = function (bearerToken, tournamentId, record, options) { var _this = this; if (options === void 0) { options = {}; } if (tournamentId === null || tournamentId === undefined) { throw new Error("'tournamentId' is a required parameter but is null or undefined."); } - if (body === null || body === undefined) { - throw new Error("'body' is a required parameter but is null or undefined."); + if (record === null || record === undefined) { + throw new Error("'record' is a required parameter but is null or undefined."); } var urlPath = "/v2/tournament/{tournamentId}" .replace("{tournamentId}", encodeURIComponent(String(tournamentId))); var queryParams = new Map(); var bodyJson = ""; - bodyJson = JSON.stringify(body || {}); + bodyJson = JSON.stringify(record || {}); var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("PUT", options, bodyJson); if (bearerToken) { @@ -3462,7 +3740,7 @@ ]); }; /** List tournament records for a given owner. */ - NakamaApi.prototype.listTournamentRecordsAroundOwner = function (bearerToken, tournamentId, ownerId, limit, expiry, options) { + NakamaApi.prototype.listTournamentRecordsAroundOwner = function (bearerToken, tournamentId, ownerId, limit, expiry, cursor, options) { var _this = this; if (options === void 0) { options = {}; } if (tournamentId === null || tournamentId === undefined) { @@ -3477,6 +3755,7 @@ var queryParams = new Map(); queryParams.set("limit", limit); queryParams.set("expiry", expiry); + queryParams.set("cursor", cursor); var bodyJson = ""; var fullUrl = this.buildFullUrl(this.basePath, urlPath, queryParams); var fetchOptions = buildFetchOptions("GET", options, bodyJson); @@ -4761,6 +5040,25 @@ if (sendTimeoutMs === void 0) { sendTimeoutMs = DefaultSocket.DefaultSendTimeoutMs; } return new DefaultSocket(this.host, this.port, useSSL, verbose, adapter, sendTimeoutMs); }; + /** Delete the current user's account. */ + Client.prototype.deleteAccount = function (session) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2]; + return [4 /*yield*/, this.sessionRefresh(session)]; + case 1: + _a.sent(); + _a.label = 2; + case 2: return [2 /*return*/, this.apiClient.deleteAccount(session.token).then(function (response) { + return response !== undefined; + })]; + } + }); + }); + }; /** Delete one or more users by ID or username. */ Client.prototype.deleteFriends = function (session, ids, usernames) { return __awaiter(this, void 0, void 0, function () { @@ -4837,6 +5135,14 @@ }); }); }; + /** Delete a tournament record. */ + Client.prototype.deleteTournamentRecord = function (session, tournamentId) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + return [2 /*return*/, this.apiClient.deleteTournamentRecord(session.token, tournamentId)]; + }); + }); + }; /** Demote a set of users in a group to the next role down. */ Client.prototype.demoteGroupUsers = function (session, groupId, ids) { return __awaiter(this, void 0, void 0, function () { @@ -4892,6 +5198,23 @@ }); }); }; + /** Get subscription by product id. */ + Client.prototype.getSubscription = function (session, productId) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2]; + return [4 /*yield*/, this.sessionRefresh(session)]; + case 1: + _a.sent(); + _a.label = 2; + case 2: return [2 /*return*/, this.apiClient.getSubscription(session.token, productId)]; + } + }); + }); + }; /** Import Facebook friends and add them to a user's account. */ Client.prototype.importFacebookFriends = function (session, request) { return __awaiter(this, void 0, void 0, function () { @@ -5452,6 +5775,56 @@ }); }); }; + /** List friends of friends for the current user. */ + Client.prototype.listFriendsOfFriends = function (session, limit, cursor) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2]; + return [4 /*yield*/, this.sessionRefresh(session)]; + case 1: + _a.sent(); + _a.label = 2; + case 2: return [2 /*return*/, this.apiClient.listFriendsOfFriends(session.token, limit, cursor).then(function (response) { + var result = { + friends_of_friends: [], + cursor: response.cursor + }; + if (response.friends_of_friends == null) { + return Promise.resolve(result); + } + response.friends_of_friends.forEach(function (f) { + result.friends_of_friends.push({ + referrer: f.referrer, + user: { + avatar_url: f.user.avatar_url, + create_time: f.user.create_time, + display_name: f.user.display_name, + edge_count: f.user.edge_count ? Number(f.user.edge_count) : 0, + facebook_id: f.user.facebook_id, + gamecenter_id: f.user.gamecenter_id, + google_id: f.user.google_id, + id: f.user.id, + lang_tag: f.user.lang_tag, + location: f.user.location, + online: f.user.online, + steam_id: f.user.steam_id, + timezone: f.user.timezone, + update_time: f.user.update_time, + username: f.user.username, + metadata: f.user.metadata ? JSON.parse(f.user.metadata) : undefined, + facebook_instant_game_id: f.user.facebook_instant_game_id + } + }); + }); + return Promise.resolve(result); + })]; + } + }); + }); + }; /** List leaderboard records */ Client.prototype.listLeaderboardRecords = function (session, leaderboardId, ownerIds, limit, cursor, expiry) { return __awaiter(this, void 0, void 0, function () { @@ -5468,6 +5841,7 @@ var list = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, + rank_count: response.rank_count ? Number(response.rank_count) : 0, owner_records: [], records: [] }; @@ -5511,7 +5885,7 @@ }); }); }; - Client.prototype.listLeaderboardRecordsAroundOwner = function (session, leaderboardId, ownerId, limit, expiry) { + Client.prototype.listLeaderboardRecordsAroundOwner = function (session, leaderboardId, ownerId, limit, expiry, cursor) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { @@ -5522,10 +5896,11 @@ case 1: _a.sent(); _a.label = 2; - case 2: return [2 /*return*/, this.apiClient.listLeaderboardRecordsAroundOwner(session.token, leaderboardId, ownerId, limit, expiry).then(function (response) { + case 2: return [2 /*return*/, this.apiClient.listLeaderboardRecordsAroundOwner(session.token, leaderboardId, ownerId, limit, expiry, cursor).then(function (response) { var list = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, + rank_count: response.rank_count ? Number(response.rank_count) : 0, owner_records: [], records: [] }; @@ -5699,6 +6074,7 @@ start_time: o.start_time, end_time: o.end_time, start_active: o.start_active, + authoritative: o.authoritative }); }); } @@ -5708,6 +6084,26 @@ }); }); }; + /** List user subscriptions. */ + Client.prototype.listSubscriptions = function (session, cursor, limit) { + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2]; + return [4 /*yield*/, this.sessionRefresh(session)]; + case 1: + _a.sent(); + _a.label = 2; + case 2: return [2 /*return*/, this.apiClient.listSubscriptions(session.token, { + cursor: cursor, + limit: limit + })]; + } + }); + }); + }; /** List tournament records from a given tournament. */ Client.prototype.listTournamentRecords = function (session, tournamentId, ownerIds, limit, cursor, expiry) { return __awaiter(this, void 0, void 0, function () { @@ -5768,7 +6164,7 @@ }); }; /** List tournament records from a given tournament around the owner. */ - Client.prototype.listTournamentRecordsAroundOwner = function (session, tournamentId, ownerId, limit, expiry) { + Client.prototype.listTournamentRecordsAroundOwner = function (session, tournamentId, ownerId, limit, expiry, cursor) { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { @@ -5779,7 +6175,7 @@ case 1: _a.sent(); _a.label = 2; - case 2: return [2 /*return*/, this.apiClient.listTournamentRecordsAroundOwner(session.token, tournamentId, ownerId, limit, expiry).then(function (response) { + case 2: return [2 /*return*/, this.apiClient.listTournamentRecordsAroundOwner(session.token, tournamentId, ownerId, limit, expiry, cursor).then(function (response) { var list = { next_cursor: response.next_cursor, prev_cursor: response.prev_cursor, @@ -6173,7 +6569,26 @@ }); }; /** Validate an Apple IAP receipt. */ - Client.prototype.validatePurchaseApple = function (session, receipt) { + Client.prototype.validatePurchaseApple = function (session, receipt, persist) { + if (persist === void 0) { persist = true; } + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2]; + return [4 /*yield*/, this.sessionRefresh(session)]; + case 1: + _a.sent(); + _a.label = 2; + case 2: return [2 /*return*/, this.apiClient.validatePurchaseApple(session.token, { receipt: receipt, persist: persist })]; + } + }); + }); + }; + /** Validate a FB Instant IAP receipt. */ + Client.prototype.validatePurchaseFacebookInstant = function (session, signedRequest, persist) { + if (persist === void 0) { persist = true; } return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { @@ -6184,13 +6599,14 @@ case 1: _a.sent(); _a.label = 2; - case 2: return [2 /*return*/, this.apiClient.validatePurchaseApple(session.token, { receipt: receipt })]; + case 2: return [2 /*return*/, this.apiClient.validatePurchaseFacebookInstant(session.token, { signed_request: signedRequest, persist: persist })]; } }); }); }; /** Validate a Google IAP receipt. */ - Client.prototype.validatePurchaseGoogle = function (session, purchase) { + Client.prototype.validatePurchaseGoogle = function (session, purchase, persist) { + if (persist === void 0) { persist = true; } return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { @@ -6201,13 +6617,50 @@ case 1: _a.sent(); _a.label = 2; - case 2: return [2 /*return*/, this.apiClient.validatePurchaseGoogle(session.token, { purchase: purchase })]; + case 2: return [2 /*return*/, this.apiClient.validatePurchaseGoogle(session.token, { purchase: purchase, persist: persist })]; } }); }); }; /** Validate a Huawei IAP receipt. */ - Client.prototype.validatePurchaseHuawei = function (session, purchase, signature) { + Client.prototype.validatePurchaseHuawei = function (session, purchase, signature, persist) { + if (persist === void 0) { persist = true; } + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2]; + return [4 /*yield*/, this.sessionRefresh(session)]; + case 1: + _a.sent(); + _a.label = 2; + case 2: return [2 /*return*/, this.apiClient.validatePurchaseHuawei(session.token, { purchase: purchase, signature: signature, persist: persist })]; + } + }); + }); + }; + /** Validate Apple Subscription Receipt */ + Client.prototype.validateSubscriptionApple = function (session, receipt, persist) { + if (persist === void 0) { persist = true; } + return __awaiter(this, void 0, void 0, function () { + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!(this.autoRefreshSession && session.refresh_token && + session.isexpired((Date.now() + this.expiredTimespanMs) / 1000))) return [3 /*break*/, 2]; + return [4 /*yield*/, this.sessionRefresh(session)]; + case 1: + _a.sent(); + _a.label = 2; + case 2: return [2 /*return*/, this.apiClient.validateSubscriptionApple(session.token, { receipt: receipt, persist: persist })]; + } + }); + }); + }; + /** Validate Google Subscription Receipt */ + Client.prototype.validateSubscriptionGoogle = function (session, receipt, persist) { + if (persist === void 0) { persist = true; } return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { switch (_a.label) { @@ -6218,7 +6671,7 @@ case 1: _a.sent(); _a.label = 2; - case 2: return [2 /*return*/, this.apiClient.validatePurchaseHuawei(session.token, { purchase: purchase, signature: signature })]; + case 2: return [2 /*return*/, this.apiClient.validateSubscriptionGoogle(session.token, { receipt: receipt, persist: persist })]; } }); }); diff --git a/packages/nakama-js/dist/socket.d.ts b/packages/nakama-js/dist/socket.d.ts index 319a8be..a68eeaf 100644 --- a/packages/nakama-js/dist/socket.d.ts +++ b/packages/nakama-js/dist/socket.d.ts @@ -148,7 +148,7 @@ export interface StreamId { /** The primary stream subject, usually a user id. */ subject: string; /** A secondary stream subject, for example for a direct chat. */ - descriptor: string; + subcontext: string; /** Meta-information (e.g. chat room name). */ label: string; } diff --git a/packages/nakama-js/package.json b/packages/nakama-js/package.json index d3f2bae..e9588ad 100644 --- a/packages/nakama-js/package.json +++ b/packages/nakama-js/package.json @@ -1,6 +1,6 @@ { "name": "@heroiclabs/nakama-js", - "version": "2.7.1", + "version": "2.8.0", "scripts": { "build": "npx tsc && npx rollup -c --bundleConfigAsCjs && node build.mjs" },