# JS SDK to TS SDK Migration Guide

## Migration Guide from JavaScript SDK to TypeScript SDK

Welcome to the migration guide designed to assist you in transitioning from our JavaScript SDK to the TypeScript SDK.  This migration involves not only method name changes but also a shift towards a more type-safe and structured approach, leveraging TypeScript's capabilities for better code quality and maintainability. For each method or property that has been changed, ensure to review the new signature or structure carefully and adjust your code accordingly. The aim is to take advantage of TypeScript's features to enhance your application's robustness and developer experience.

Remember to test thoroughly after making these changes to ensure that your application continues to function as expected. If you encounter any issues or need further assistance, our support team is here to help.

Please check the installation guide for TS SDK here - [Installation and Authentication](/getting-started/installation-and-authentication.md#typescript).

***

## Importing the SDK

When migrating from the JavaScript SDK to the TypeScript SDK, update the import statements in your project to reflect the new package name.

#### JavaScript SDK:

```javascript
import { MessageRepository } from '@amityco/js-sdk';
```

#### TypeScript SDK:

```typescript
import { MessageRepository } from '@amityco/ts-sdk';
```

This change is crucial for accessing the updated SDK functionalities and types provided by the TypeScript version. Ensure all import statements in your project are updated accordingly.

***

## ChannelRepository Changes

* `createChannel`: Enhanced with `avatarFileId`, `displayName`, `tags`, and `metadata`. `channelId` removed. `channelType` now strictly `'broadcast'`, `'conversation'`, `'community'`, or `'live'` - [Create Channel](/social-plus-sdk/chat/channels/create-channel.md).
* `channelType`: Now uses string literals `'broadcast'`, `'conversation'`, `'community'`, `'live'` instead of `ChannelType`.
* `queryChannels` → `getChannels`: Method name updated; parameters for filtering and sorting channels have changed - [Get Channels](/social-plus-sdk/chat/channels/get-channels.md).
* `joinChannel` and `leaveChannel`: Simplified method signature from `joinChannel({ channelId: '<channelId>'})` to `joinChannel('<channelId>')` - [Join/Leave Channel](/social-plus-sdk/chat/channels/join-leave-channel.md).
* `updateChannel`: Updated to a more concise signature - [Update Channel](/social-plus-sdk/chat/channels/update-channel.md).
* `banMembers` → `Moderation.banMembers`: Moved under `Moderation` with an updated method signature - [Ban/Unban a List of Channel Members](/social-plus-sdk/chat/moderation/ban-unban-a-list-of-channel-members.md).
* `unbanMembers` → `Moderation.unbanMembers`: Now under `Moderation` with changes in parameters - [Ban/Unban a List of Channel Members](/social-plus-sdk/chat/moderation/ban-unban-a-list-of-channel-members.md).

### Removed Methods

* `muteMembers`
* `unmuteMembers`
* `removeRateLimit`
* `setRateLimit`

***

## MessageRepository Changes

* `addReaction` & `removeReaction`: Moved to `ReactionRepository` with updated functionality - [Add / Remove Reaction](/social-plus-sdk/social/reactions/add-remove-reaction.md).
* `flag`, `unflag`, `isFlaggedByMe`: Replaced with `flagMessage`, `unflagMessage`, `isMessageFlaggedByMe` - [Flag/Unflag a Message](/social-plus-sdk/chat/messaging/flag-unflag-a-message.md).
* `createTextMessage`, `createImageMessage`, `createFileMessage` consolidated into `createMessage` for unified message creation -  [Send a Message](/social-plus-sdk/chat/messaging/send-a-message.md).
* `updateMessage` to `editMessage`: Signature updated for direct editing.
* `deleteMessage` to `softDeleteMessage` & `queryMessages` to `getMessages`: Updated for clarity and functionality.

### Removed Methods

* `MessageTools`

***

## CommunityRepository Changes

* Membership and moderation-related methods have been restructured under `Membership` and `Moderation` respectively, with updated signatures for adding, banning, and removing members and roles - [Community Moderation](/social-plus-sdk/social/communities/community-moderation.md).

### Removed Methods

* `categoriesForIds`

***

## FileRepository and LiveStreamPlayer Changes

* Introduction of `uploadFile` and `uploadVideo` methods replacing `createFile` and `createVideo`  in `FileRepository`. - [Files, Images, and Videos](/social-plus-sdk/core-concepts/files-images-and-videos.md).
* `LiveStreamPlayer` remains unchanged with the `getPlayer` method - [View & Play Live Stream](/social-plus-sdk/video/web/view-and-play-live-stream.md).

***

## PostRepository Changes

* Transition from specific post creation methods to a unified `createPost` method, accommodating different types of content through parameters - [Create Post](/social-plus-sdk/social/posts/create-post.md).
* `updatePost` → `editPost`: Aligned with new content structuring and tagging - [Edit Post](/social-plus-sdk/social/posts/edit-post.md).

### Removed Methods

* `hardDeletePost`- please use `PostRepository.deletePost` instead - [Delete Post](/social-plus-sdk/social/posts/delete-post.md).

***

## UserRepository Changes

The UserRepository has seen several method updates to align with the new TypeScript SDK, specifically transitioning to the `Relationship` namespace for managing user relationships. These updates facilitate a more structured approach to handling followers and followings within applications - [Follow/Unfollow](/social-plus-sdk/social/follow-unfollow.md).

* **getFollowInfo → Relationship.getFollowInfo**
* **followAccept → Relationship.acceptMyFollower**
* **follow → Relationship.follow**
* **followDecline → Relationship.declineMyFollower**
* **getFollowers → Relationship.getFollowers**
  * Changed from `getFollowers('<userId>', '<status>')` to `Relationship.getFollowers({ userId: '<userId>', status: '<status>' })`.
* **getFollowings → Relationship.getFollowings**
  * Updated from `getFollowings('<userId>')` to `Relationship.getFollowings({ userId: '<userId>' })`.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.social.plus/developers/migration-guides/js-sdk-to-ts-sdk-migration-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
