Migrate from the legacy Hathora Cloud SDK to the TypeScript SDK.
Apply with the Grit CLI
grit apply hathora_ts
Instantiates API Resources
BEFORE
import { AuthV1Api } from '@hathora/hathora-cloud-sdk'; const authClient = new AuthV1Api();
AFTER
import { HathoraCloud } from '@hathora/cloud-sdk-typescript'; const authClient = new HathoraCloud().authV1;
Reorders method arguments
BEFORE
import { LobbyV2Api } from '@hathora/hathora-cloud-sdk'; const lobbyClient = new LobbyV2Api(); lobbyClient.setLobbyState('my-app', 'my-room', { some: 'data' }, { request: 'ops' });
AFTER
import { HathoraCloud } from '@hathora/cloud-sdk-typescript'; const lobbyClient = new HathoraCloud().lobbyV2; lobbyClient.setLobbyState({ some: 'data' }, 'my-app', 'my-room', { request: 'ops', });
Renames types
BEFORE
import { LobbyV2Api } from '@hathora/hathora-cloud-sdk'; const lobbyClient: LobbyV2Api = new LobbyV2Api();
AFTER
import { LobbyV2, HathoraCloud } from '@hathora/cloud-sdk-typescript'; const lobbyClient: LobbyV2 = new HathoraCloud().lobbyV2;
Renames deprecated methods
BEFORE
import { RoomV1Api, LobbyV1Api, LobbyV2Api } from "@hathora/hathora-cloud-sdk"; const roomClient = new RoomV1Api(); const lobbyV1Client = new LobbyV1Api(); const lobbyV2Client = new LobbyV2Api(); roomClient.destroyRoom(process.env.HATHORA_APP_ID!, roomId, { headers: { Authorization: `Bearer ${getDeveloperToken()}`, "Content-Type": "application/json" } } ); roomClient.suspendRoom(appId, roomId, config); await roomClient.suspendRoom(appId, roomId, config); const lobby = await lobbyv2Client.createPrivateLobby(appId); // Some functions were already deprecated const roomId = await lobbyV1Client.createPrivateLobbyDeprecated(appId); lobbyV2client.createPrivateLobby(appId); lobbyV1Client.createPrivateLobbyDeprecated(appId);
AFTER
import { HathoraCloud } from "@hathora/cloud-sdk-typescript"; const roomClient = new HathoraCloud().roomV1; const lobbyV1Client = new HathoraCloud().lobbyV1; const lobbyV2Client = new HathoraCloud().lobbyV2; roomClient.destroyRoomDeprecated(process.env.HATHORA_APP_ID!, roomId, { headers: { Authorization: `Bearer ${getDeveloperToken()}`, "Content-Type": "application/json" } } ); roomClient.suspendRoomDeprecated(appId, roomId, config); await roomClient.suspendRoomDeprecated(appId, roomId, config); const lobby = (await lobbyv2Client.createPrivateLobbyDeprecated(appId)).lobby; // Some functions were already deprecated const roomId = (await lobbyV1Client.createPrivateLobbyDeprecated(appId)).roomId; lobbyV2client.createPrivateLobbyDeprecated(appId); lobbyV1Client.createPrivateLobbyDeprecated(appId);
Unwraps responses in-place
Responses often have a new intervening wrapper key for the response data. For instance, setLobbyState
returns data under .lobby
.
BEFORE
import { LobbyV2Api } from '@hathora/hathora-cloud-sdk'; const lobbyClient = new LobbyV2Api(); const { state } = await lobbyClient.setLobbyState( 'my-app', 'my-room', { some: 'data' }, { request: 'ops' }, );
AFTER
import { HathoraCloud } from '@hathora/cloud-sdk-typescript'; const lobbyClient = new HathoraCloud().lobbyV2; const { state } = ( await lobbyClient.setLobbyState({ some: 'data' }, 'my-app', 'my-room', { request: 'ops', }) ).lobby;