# QuestSdk

QuestSdk is a javascript development kit which utilizes the quest protocol core apis and provide simple and easy to use methods.

## Installation

If this is a brand new project, make sure to create a `package.json` first with
the [`npm init` command](https://docs.npmjs.com/creating-a-package-json-file).

Installation is done using the
[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):

```console
$ npm install @questlabs/core
```

Once the package is installed, you can import the sdk using `import` or `require` approach:

Using the import approach for web or mobile projects:

```js
import QuestSdk from "@questlabs/core";
```

Using the require approach for node.js projects:

```js
const QuestSdk = require("@questlabs/core").default;
```

## Initialization in production environment

```ts
// types

interface IConstructor {
    apiKey: string;
    apiSecret: string;
    stagingEnvironment?: boolean;
    userAgent?: UserAgent;
    entityAuthenticationToken?: string;
    entityId?: string;
    platform?: string;
}

export type UserAgent = "MOBILE" | "BROWSER" | "SERVER";

// example usage

const questSdk = new QuestSdk({
    apiKey: "YOUR_API_KEY",
    apiSecret: "YOUR_API_SECRET",
    entityId: "YOUR_ENTITY_ID",
});
```

## Initialization in staging environment

```ts
const questSdk = new QuestSdk({
    apiKey: "YOUR_API_KEY",
    apiSecret: "YOUR_API_SECRET",
    entityId: "YOUR_ENTITY_ID",
    stagingEnvironment: true,
});
```

## Base class getters and setters

```ts
  QuestSdk.setEntityId({ entityId }: ISetEntity): void

  QuestSdk.getEntityId(): string | undefined

  QuestSdk.setUser({ userId, token }: ISetUser): void

  QuestSdk.getUser(): {
    userId: string | undefined;
    token: string | undefined;
  }

  QuestSdk.setEnvironment({ stagingEnvironment }: ISetEnvironment): void

  QuestSdk.getEnvironment(): {
    stagingEnvironment: boolean;
  }

  QuestSdk.isStagingEnvironment(): boolean

  QuestSdk.setUserAgent({ userAgent }: ISetUserAgent): void

  QuestSdk.getUserAgent(): UserAgent

  QuestSdk.setEntityAuthenticationToken({ token }: ISetEntityAuthenticationToken): void

  QuestSdk.getEntityAuthenticationToken(): string | undefined

  QuestSdk.setApiKeys({ apiKey, apiSecret }: ISetApiKeys): void

  QuestSdk.getApiKeys(): {
    apiKey: string;
    apiSecret: string;
  }

  QuestSdk.getBaseUrl(): string
```

## Core Modules

[Entity](#entity), [User](#user), [Badge](#badge), [DappMetric](#dappmetric), [DynamicNFT](#dynamicnft), [EntityTag](#entitytag), [MembershipTier](#membershiptier), [Skill](#skill), [Quest](#quest), [EntityCreditTier](#entitycredittier), [EntityAuthenticationToken](#entityauthenticationtoken) <sup style="color: yellow">New</sup>, [EntityDataContract](#entitydatacontract) <sup style="color: yellow">New</sup>, [EntityFeatureFlag](#entityfeatureflag) <sup style="color: yellow">New</sup>, [EntityPrompt](#entityprompt) <sup style="color: yellow">New</sup>, [GPT](#gpt) <sup style="color: yellow">New</sup>.

## Social Modules

[Twitter](#twitter), [Discord](#discord), [Instagram](#instagram) <sup style="color: yellow">New</sup>

## Abstract Modules

[Xp](#xp) <sup style="color: yellow">New</sup>, [EligibilityCriteria](#eligibilitycriteria), [Reward](#reward)

### Entity

#### Initialization

```ts
import { Entity } from "@questlabs/core/modules/core";
// OR
import { Core } from "@questlabs/core";

const entity = new Entity(questSdk);
// OR
const entity = new Core.Entity(questSdk);
```

#### Methods

1.  Create new entity

    Used to create a new entity with various details such as name, contracts, description, social media handles, website, and images.

    ```js
    const { entityId, success, error } = await entity.createNewEntity({
        name: "Acme Corporation",
        contracts: ["0xContract123", "0xContract456"],
        openseaSlug: "acme-corp",
        description: "A leading technology company.",
        chainSource: "ON_CHAIN",
        isPrivate: false,
        decreaseCreditsAt: 50,
        decreaseCreditsFrom: "User567",
        website: "https://www.acmecorp.com",
        imageUrl: "https://www.acmecorp.com/logo.png",
        bannerUrl: "https://www.acmecorp.com/banner.png",
        entityURLAlias: "acme",
        parentEntityId: "ParentEntity789",
        category: "Technology",
    });
    ```

2.  Add new custom entity ID

    Adds a new custom entity ID by an admin.

    ```js
    const { success, error } = await entity.addNewCustomEntityId({
        customPlatformName: "Twitter",
        customPlatformId: "123456789",
        entityId: "Entity123",
        name: "John Doe",
        username: "johndoe",
        link: "https://twitter.com/johndoe",
        accessToken: "your-access-token",
        refreshToken: "your-refresh-token",
        expiresIn: "3600",
    });
    ```

3.  Get all entities

    Returns all entities.

    ```js
    const { data, success, error } = await entity.getAllEntities({
        page: 1,
        limit: 10,
    });
    ```

4.  Get entity information

    Used to fetch information about a specific entity based on its ID.

    ```js
    const { data, success, error } = await entity.getEntityInfo({
        entityId: "entity-123",
    });
    ```

5.  Get entity ID for alias:

    Retrieves the entity ID for the given alias.

    ```js
    const { data, success, error } = entity.getEntityIdForAlias({
        alias: "alias-123",
    });
    ```

6.  Get entity ID for custom ID:

    Retrieves the entity ID for the given custom ID, platform, and record type.

    ```js
    const { data, success, error } = entity.getEntityIdForCustomId({
        customId: "c-123",
        platform: "twitter",
        recordType: "TWITTER",
    });
    ```

7.  Update entity

    Used to update an existing entity with new information such as name, description, social media handles, website, and images.

    ```js
    const { success, error } = await entity.updateEntity({
        entityId: "Entity123",
        name: "Updated Entity Name",
        description: "This is the updated description for the entity.",
        isPrivate: "false",
        decreaseCreditsAt: "50",
        decreaseCreditsFrom: "User567",
        website: "https://updated-entity.com",
        imageUrl: "https://updated-entity.com/image.png",
        bannerUrl: "https://updated-entity.com/banner.png",
        entityURLAlias: "updated-entity",
    });
    ```

8.  Update Entity theme

    Updates the current theme of an entity.

    ```js
    const { success, message, error } = await entity.updateEntityTheme({
        theme: {
            backgroundColor: "blue",
            fontFamily: "Hanken Grotesk",
            accentColor: "sky-blue",
        },
        entityId: "e-123",
    });
    ```

9.  Get Entity theme

    Retrieves the current theme of an entity.

    ```js
    const { theme, success, error } = await entity.getEntityTheme({
        entityId: "e-123",
    });
    ```

10. Update Entity plan

    Updates the current plan of an entity.

    ```js
    const { success, error } = await entity.updateEntityPlan({
        entityId: "e-123",
        product: {
            name: "FREE",
        },
    });
    ```

11. Get users of an entity

    Retrieves the users associated with a specific entity for a given user.

    ```js
    const { users, success, error } = await entity.getUsersForEntityForUser({
        entityId: "entity-123",
    });
    ```

12. Get all admins

    Retrieves all the admins of an entity.

    ```js
    const { data, message, success, error } = await entity.getAllAdmins({
        entityId: "e-123",
    });
    ```

13. Remove admin

    Removes admin of an entity.

    ```js
    const { message, success, error } = await entity.removeAdmin({
        userId: "u-123",
        entityId: "e-123",
    });
    ```

14. Add or update social tokens

    This function adds or updates social tokens for a specified entity using provided authentication and API credentials.

    ```js
    const { message, success, error } = await entity.addOrUpdateSocialTokens({
        recordType: EntityTokenRecordType.TWITTER,
        entityId: "Entity123",
        authClientId: "your-auth-client-id",
        authClientSecret: "your-auth-client-secret",
        apiKey: "your-api-key",
        apiSecret: "your-api-secret",
        authorizationToken: "your-authorization-token",
        apiHost: "api.twitter.com",
    });
    ```

15. Get social tokens

    This async function retrieves the social tokens of a particulay record type for an entity.

    ```js
    const { data, success, error } = await entity.getSocialTokens({
        recordType: "TWITTER",
        entityId: "e-1234",
    });
    ```

16. Approve entity creation

    Approves the creation of an entity with the specified entity data. Only admins can perform this action.

    ```js
    const { success, error } = await entity.approveEntityCreation({
        entityId: "entity-123",
        baseName: "Mybase",
        baseSymbol: "MEN",
    });
    ```

17. Get all pending entities

    Retrieves all pending entities that are yet to be created. Only admins can perform this action.

    ```js
    const { data, success, error } = await entity.getAllPendingEntities();
    ```

18. Add admin

    Adds admin for an entity.

    ```js
    const { message, success, error } = await entity.addAdminToEntity({
        email: "test@email.com",
        role: "ADMIN",
        name: "Jonny",
        entityId: "e-1212",
    });
    ```

19. Get api keys

    Get or generate new api and secret keys for an entity.

    ```js
    const { data, success, error } = await entity.getOrGenerateNewAPIKey({
        entityId: "e-123",
    });
    ```

20. Manually add users to entity

    Adds users to an entity.

    ```js
    const { success, error } = await entity.manuallyAddUsersToEntity({
        entityId: "entity-123",
        userIds: ["user-456", "user-789"],
    });
    ```

21. Get users of an entity

    Get users of an entity

    ```js
    const { users, success, error } = await entity.getUsersOfEntity({ entityId: "e-1212" });
    ```

22. Delete Entity

    Allows to delete an entity, can only be performed by the owner.

    ```js
    const response = await entity.deleteEntity({
        userId: "u-123",
        token: "login-token",
        entityId: "e-123",
    });
    ```

### User

Here are the methods of User module and their use cases:

1.  Login with wallet

    Logs in the user or creates one if it doesn't exist using wallet information.

    ```js
    const { userId, token, newUser, success, error } = await user.loginWithWallet({
        entityId: "entity-123",
        walletAddress: "0x1234567890abcdef",
        signature: "0xabcdef1234567890",
        token: "Super secret message",
    });
    ```

2.  Login with Google

    Logs in the user or creates one if it doesn't exist using Google authentication.

    ```js
    const { userId, token, newUser, success, error } = await user.loginWithGoogle({
        code: "google-auth-code",
        redirectUri: "https://example.com/callback",
        entityId: "entity-123",
    });
    ```

3.  Get user details for a given user ID:

    Retrieves user details for a given user ID.

    ```js
    const { data, isAdmin, success, error } = await user.getUserDetailsForUserId({
        forUserId: "user-123",
    });
    ```

4.  Set user information

    updates user information for a given user ID.

    ```js
    const { success, error } = await user.setUserInfo({
        name: "John Doe",
        imageUrl: "https://example.com/johndoe.jpg",
        bannerUrl: "https://example.com/johndoe-banner.jpg",
        location: "New York City, NY",
        expertise: "Web Development",
        goals: ["Become a Full Stack Developer", "Learn Machine Learning"],
        interests: ["Programming", "Gaming", "Travel"],
        about: "I'm a passionate web developer with a love for coding and technology.",
        currentWork: "Software Engineer at XYZ Inc.",
        funFacts: ["I can solve a Rubik's Cube in under a minute!", "I've visited 10 countries so far."],
        role: "Software Engineer",
        sector: "Technology",
    });
    ```

5.  Create new custom user.

    Creates a new custom user with custom user information.

    ```js
    const { userId, newUser, success, error } = await user.createNewCustomUser({
        customUserId: "custom-123",
        customPlatform: "MyCustomPlatform",
        entityId: "entity-123",
    });
    ```

6.  Get user details for a given email

    Retrieves user details for a given email address.

    ```js
    const { data, isAdmin, success, error } = await user.getUserDetailsForEmail({
        email: "user@example.com",
    });
    ```

7.  Get user details for a given wallet address

    Retrieves user details for a given wallet address.

    ```js
    const { data, isAdmin, success, error } = await user.getUserDetailsForWalletAddress({
        walletAddress: "0x1234567890abcdef",
    });
    ```

8.  Get user's connected socials:

    Retrieves social connections for a given user.

    ```js
    const { data, success, error } = await user.getConnectedUserSocials({
        entityId: "entity-123",
    });
    ```

9.  Get entities for a user

    Retrieves entities associated with a given user.

    ```js
    const { success, error, data, loginAgain, userTokenExpired } = await user.entitesForUser({
        page: 1,
        limit: 10,
    });
    ```

10. Get admin entities for a user

    Retrieves admin entities associated with a given user.

    ```js
    const { data, success, errror } = await user.getAdminEntitiesForUser();
    ```

11. Set selected admin entity

    Updates current admin entity.

    ```js
    const { success, error } = await user.setSelectedAdminEntityId({
        entityId: "entity-123",
    });
    ```

12. Send OTP email

    Sends an OTP to a given email for login to a particular entity

    ```js
    const { data, success, error } = await user.sendOtpEmail({
        email: "testmail@email.com",
        entity: "e-12123",
    });
    ```

13. Verify OTP email

    Verifies the OTP sent to an email for login to a particular entity

    ```js
    const { userId, token, newUser , success, error } = await user.verifyOtpEmail({
        email: "testmail@email.com",
        entity: "e-12123"
        otp: 112435,
        name: "Jon Doe",
    });
    ```

14. Connect wallet

    Connects a user's wallet address

    ```js
    const {} = await user.connectWallet({
        entityId: "e-1212",
        walletAddress: "0x1212331211",
        signature: "12121bax1243",
        token: "secret message",
        userId: "u-121243",
    });
    ```

### Badge

Here are the methods of Badge module and their use cases:

1. Retrieve all badges for a given user

    Retrieves all badges for a given user.

    ```js
    const { data, success, error } = await badge.getAllBadgesForUser();
    ```

2. Get all badges of an entity

    Retrieves all badges of a specific entity.

    ```js
    const { data, success, error } = await badge.getAllBadgesForEntity({
        entityId: "entity-123",
    });
    ```

3. Get badge information of an entity

    Retrieve the badge information for a specific badge associated with an entity.

    ```js
    const { success, error, data, loginAgain, userTokenExpired } = await badge.getBadgeInfoForEntity({
        entityId: "entity123",
        badgeId: "badge123",
    });
    ```

4. Update badge for a specific entity

    Update badge for a specific entity.

    ```js
    const { success, error } = await badge.updateBadgesForEntity({
        name: "Achievement Badge",
        imageIPFS: "ipfs://your-badge-image-hash",
        description: "This badge signifies a major achievement.",
        entityId: "Entity123",
        skills: "Programming",
        userIds: "User456",
        endsAt: "2023-12-31",
        xp: 100,
        airdropEnabled: false,
        typeData: "Some type data",
        type: "Achievement",
        totalCount: "1",
        visibility: "Public",
        proofType: "Evidence",
    });
    ```

5. Claim a badge for an entity

    Claim a badge for an entity.

    ```js
    const { success, error, calculatedDynamicNFT, nftMinted, loginAgain, userTokenExpired } = await badge.claimBadgeForEntity({
        entityId: "entity123",
        badgeId: "badge123",
        addToDynamicNFT: true,
    });
    ```

6. Add users to a badge

    Add users to a badge.

    ```js
    const { success, error } = await badge.addUsersToBadge({
        entityId: "entity123",
        badgeId: "badge123",
        userIds: ["user456", "user789"],
    });
    ```

7. Get my created badges

    Retrieve the badges created by a specific user

    ```js
    const createdBadges = await badge.getMyCreatedBadges({
        userId: "user123",
        token: "login-token",
    });
    ```

8. Get user created badges

    Get badges created by the user

    ```js
    const { data, success, error } = await badge.getUserCreatedBadges();
    ```

9. Add badge for entity

    Add badge for a specific entity

    ```js
    const { success, error, badgeId, loginAgain, userTokenExpired } = await badge.addBadgeForEntity({
        name: "Achievement Badge",
        imageIPFS: "ipfs://your-badge-image-hash",
        description: "This badge signifies a major achievement.",
        entityId: "Entity123",
        skills: "Programming",
        userIds: "User456",
        endsAt: "2023-12-31",
        xp: 100,
        airdropEnabled: false,
        typeData: "Some type data",
        type: "Achievement",
        totalCount: "1",
        visibility: "Public",
        proofType: "Evidence",
    });
    ```

10. Get number of badges earned

    Get the number of badges a user ha earned for an entity

    ```js
    const { success, error, data, loginAgain, userTokenExpired } = await badge.getNumberOfBadgesEarned();
    ```

11. Get user earned badges

    Get the badges a user has earned for an entity

    ```js
    const { success, error, data, page, totalCount, totalPages, loginAgain, userTokenExpired } = await badge.getUserEarnedBadgesForEntity();
    ```

11. Add users to badge

    Add users to badge

    ```js
    const { success, error, loginAgain, userTokenExpired } = await badge.addUsersToBadge({
        badgeId: "b-59f3a52d-92ee-4dae-944e-b271d6135b91",
        userIds: ["u-cfd286e2-6bd3-4c8b-a404-ef8b0f5cbc8e"],
    });
    ```

### DappMetric

Here are the methods of DappMetric module and their use cases:

1. Get all dapp metrics

    Retrieve all Dapp metrics for a specific entity.

    ```js
    const allDappMetrics = await SDK.meta.dappMetric.getAllDappMetrics({
        entityId: "entity123",
        userId: "user123",
        token: "login-token",
    });
    ```

2. Get dapp metric for a user

    Retrieves a specific Dapp metric for a user of an entity.

    ```js
    const dappMetric = await SDK.meta.dappMetric.getDappMetricForUser({
        entityId: "entity123",
        userId: "user123",
        metricId: "metric123",
        adminId: "admin123",
        token: "login-token",
    });
    ```

3. Increment dapp metric for a user

    Increment the value of a specific Dapp metric for a user of an entity.

    ```js
    const incrementedMetric = await SDK.meta.dappMetric.incrementDappMetricForUser({
        entityId: "entity123",
        userId: "user123",
        metricId: "metric123",
        count: 5,
        adminId: "admin123",
        token: "login-token",
    });
    ```

4. Get all dapp metrics of a user

    Retrieve all Dapp metrics for a user of an entity.

    ```js
    const allUserDappMetrics =
      await SDK.meta.dappMetric.getAllDappMetricsForUser(
        entityId: "entity123",
        userId: "user123",
        adminId: "admin123",
        token: "login-token",
      );
    ```

5. Increment multiple dapp metrics for a user

    Increment multiple Dapp metrics for a user of an entity.

    ```js
    const incrementedMetrics = await SDK.meta.dappMetric.incrementMultipleMetricsForUser({
        entityId: "entity123",
        userId: "user123",
        metrics: [
            { metricId: "metric1", count: 2 },
            { metricId: "metric2", count: 3 },
        ],
        adminId: "admin123",
        token: "login-token",
    });
    ```

### DynamicNFT

Here are the methods of DynamicNFT module and their use cases:

1. Mint dynamic NFT

    Mint a dynamic NFT for a specific user of an entity

    ```js
    const { data, success, error } = await dynamicNFT.mintDynamicNFT({
        entityId: "entity123",
        type: "type1",
        forUserId: "forUser123",
    });
    ```

2. Add running xp for a user

    Add running XP to the dynamic NFT created for the user of a specific entity

    ```js
    const { success, error, loginAgain, userTokenExpired } = await dynamicNft.addRunningXP({
        xp: 10000,
        title: "TITLE_FOR_INCREMENTING",
    });
    ```

3. Get my dynamic NFTs

    Retrieve the dynamic NFTs owned by a user

    ```js
    const { data, success, error } = await dynamicNFT.getMyDynamicNFTs();
    ```

4. Get my dynamic NFT details for an entity

    Retrieve the dynamic NFT details for a specific entity owned by a user.

    ```js
    const { data, entity_data, success, error } = await dynamicNFT.getMyDynamicNFTDetailsForEntity({
        entityId: "entity123",
    });
    ```

5. Get XP for user

    Get XP for a user of an entity

    ```js
    const { data, success, error } = await dynamicNft.getXpForUser({ entityId: "e-1212", userId: "u-12121" });
    ```

6. Get XP for users

    Get XP for multiple users of an entity

    ```js
    const { data, success, error } = await dynamicNft.getXpForUsers({
        entityId: "e-1212",
        userIds: ["u-12121", "u-9090"],
    });
    ```

7. Get XP for entity

    Get XP for an entity

    ```js
    const { data, success, error } = await dynamicNft.getXpForEntity({
        entityId: "e-1212",
    });
    ```

8. Get XP for entities

    Get XP for multiple entities

    ```js
    const { data, success, error } = await dynamicNft.getXpForEntities({
        entityIds: ["e-1212", "e-9090"],
    });
    ```

9. Recalculate user's dynamic NFT

    Recalculate the dynamic NFT for a specific entity owned by a user.

    ```js
    const { data, success, error } = await dynamicNFT.recalculateUsersDynamicNFT({
        entityId: "entity123",
        userId: "user123",
    });
    ```

10. Get all themes for an entity

    Retrieve all themes for a specific entity.

    ```js
    const { data, success, error } = await dynamicNFT.getAllThemesForEntity({
        entityId: "entity123",
    });
    ```

11. Add new dynamic theme for an entity

    Add a new dynamic theme for a specific entity.

    ```js
    const { themeId, success, error } = await dynamicNFT.addNewThemeForEntity({
        membershipTier: 2,
        title: "Gold Membership",
        price: "49.99 USD",
        entityId: "Entity123",
        backgroundImageIPFS: "your-background-image-hash",
        horizontalLogoImageIPFS: "your-horizontal-logo-image-hash",
        squareLogoImageIPFS: "your-square-logo-image-hash",
        backgroundColor: "#F0F0F0",
        accentColor1: "#FFA500",
        accentColor2: "#008000",
        metadataIPFS: "your-metadata-hash",
    });
    ```

12. Get theme details for an entity

    Retrieve the details of a specific theme for a given entity.

    ```js
    const { data, success, error } = await dynamicNFT.getThemeDetailsForEntity({
        entityId: "entity123",
        themeId: "theme123",
    });
    ```

13. Update theme for an entity

    Update the details of a specific theme for a given entity.

    ```js
    const { success, error } = await dynamicNFT.updateThemeForEntity({
        themeId: "t-1212",
        membershipTier: 2,
        title: "Gold Membership",
        price: "49.99 USD",
        entityId: "Entity123",
        backgroundImageIPFS: "your-background-image-hash",
        horizontalLogoImageIPFS: "your-horizontal-logo-image-hash",
        squareLogoImageIPFS: "your-square-logo-image-hash",
        backgroundColor: "#F0F0F0",
        accentColor1: "#FFA500",
        accentColor2: "#008000",
        metadataIPFS: "your-metadata-hash",
    });
    ```

14. Delete theme for an entity

    Delete a specific theme for a given entity.

    ```js
    const { success, error } = await dynamicNFT.deleteThemeForEntity({
        entityId: "entity123",
        themeId: "theme123",
    });
    ```

15. Set default theme for an entity

    Set the default theme for a given entity.

    ```js
    const { success, error } = await dynamicNFT.setDefaultThemeForEntity({
        entityId: "entity123",
        themeId: "theme123",
    });
    ```

16. Get user user xp leaderboard rank

    Retrives the user's rank from the xp leaderboard

    ```js
    const { success, error, data, loginAgain, userTokenExpired } = await dynamicNft.getUserXpLeaderboardRank();
    ```

19. Get user user xp leaderboard

    Retrives the xp leaderboard

    ```js
    const { success, error, data, page ,totalCount, totalPages, loginAgain, userTokenExpired } = await dynamicNft.getUserXpLeaderboard();
    ```

18. Get user user xp history

    Retrives the history of xp increments for a user

    ```js
    const { success, error, data, page, totalCount, totalPages, loginAgain, userTokenExpired } = await dynamicNft.getUserXpHistory();
    ```

### EntityTag

Here are the methods of EntityTag module and their use cases:

1. Get all tags for an entity

    Retrieve all tags for a specific entity.

    ```js
    const { data, success, error } = await entityTag.getAllTagsForEntity({
        entityId: "entity123",
    });
    ```

2. Add tag for an entity

    Add a tag for a specific entity.

    ```js
    const { data, success, error } = await entityTag.addTagForEntity({
        entityId: "entity123",
        tagName: "Tag 1",
        description: "This is tag 1",
    });
    ```

3. Update tag of an entity

    Update a tag for a specific entity.

    ```js
    const { data, success, error } = await entityTag.updateTagForEntity({
        tagId: "tag123",
        tagName: "Updated Tag 1",
        description: "This is the updated tag 1",
        entityId: "entity123",
    });
    ```

4. Delete tag of an entity

    Delete a tag for a specific entity.

    ```js
    const { success, error } = await entityTag.deleteTagForEntity({
        entityId: "entity123",
        tagId: "tag123",
    });
    ```

5. Get entity tags for a user

    Retrieve tags associated with a specific entity for a given user, on behalf of another user.

    ```js
    const { data, success, error } = await entityTag.getEntityTagsForUser({
        entityId: "entity123",
        forUserId: "forUser123",
    });
    ```

6. Add entity tag for a user

    Add a user to an entity tag.

    ```js
    const { data, success, error } = await entityTag.addEntityTagForUser({
        entityId: "entity123",
        forUserId: "forUser123",
        tagId: "tag123",
    });
    ```

7. Remove entity tag for a user

    Remove a user from an array of users associated with an entity tag.

    ```js
    const { success, error } = await entityTag.removeEntityTagForUser({
        entityId: "entity123",
        tagId: "tag123",
        forUserId: "forUser123",
    });
    ```

### MembershipTier

Here are the methods of MembershipTier module and their use cases:

1. Get all membership tiers of entity

    Retrieve all membership tiers of an entity.

    ```js
    const { data, success, error } = await membershipTier.getAllMembershipTiersOfEntity({
        entityId: "entity123",
        page: 1,
        limit: 10,
    });
    ```

2. Get membership tier details for an entity

    Retrieve membership tier details of an entity.

    ```js
    const { data, success, error } = await membershipTier.getMembershipTierDetailsForEntity({
        entityId: "entity123",
        memberhipTier: 1,
    });
    ```

3. Add new membership tier for an entity

    Add a new membership tier for an entity.

    ```js
    const { success, error } = await membershipTier.addNewMembershipTierForEntity({
        xpThreshold: 5000,
        membershipTier: 2,
        imageIPFS: "your-membership-tier-image-hash",
        description: "Unlock exclusive benefits with our Gold Membership.",
        entityId: "Entity123",
    });
    ```

4. Update membership tier for an entity

    Update the xpThreshold requirements of a specific membership tier for an entity.

    ```js
    const { success, error } = await membershipTier.updateMembershipTierForEntity({
        membershipTier: 2,
        xpThreshold: 1000,
        entityId: "Entity123",
    });
    ```

5. Delete membership tier for entity

    Delete a specific membership tier for an entity.

    ```js
    const { success, error } = await membershipTier.deleteMembershipTierForEntity({
        entityId: "entity123",
        membershipTier: 1,
    });
    ```

### Skill

Here are the methods of Skill module and their use cases:

1. Get all skills

    Retrieve all skills associated with an entity.

    ```js
    const { data, success, error } = await skill.getAllSkills({
        entityId: "entity123",
    });
    ```

2. Get skill details

    Retrieve the details of a specific skill.

    ```js
    const { data, success, error } = await skill.getSkillDetails({
        skillId: "skill123",
    });
    ```

3. Add new skill

    Add a new skill for an entity.

    ```js
    const { skillId, success, error } = await skill.addNewSkill({
        name: "New Skill",
        description: "This is a new skill",
        entityId: "entity123",
    });
    ```

4. Add multiple new skills

    Add multiple new skills for an entity.

    ```js
    const { skillIds, success, error } = await skill.addMultipleNewSkills({
        skills: [
            { name: "Skill 1", description: "This is skill 1" },
            { name: "Skill 2", description: "This is skill 2" },
        ],
        entityId: "entity123",
    });
    ```

### Quest

Here are the methods of Quest module and their use cases:

1.  Get all Quests

    Fetches all the quests with optional params for pagination.

    ```js
    const { data, success, error } = await quest.getAllQuests({
        page: 1,
        limit: 10,
    });
    ```

2.  Get all quests of an entity

    Fetches all the quests of a specific entity with optional pagination.

    ```js
    const { data, success, error } = await quest.getAllQuestsForEntity({
        entityId: "e-101",
        page: 1,
        limit: 10,
    });
    ```

3.  Get quest details.

    Fetches the details of a quest with stats of the user retrieving it, userId is optional.

    ```js
    const {
        success,
        error,
        data,
        allCriteriasCompleted,
        claimStatus,
        completedCriteriasPercentage,
        eligibilityData,
        rewards,
        session,
        totalCriteriasCompleted,
        referralCode,
        totalClaimed,
        loginAgain,
        userTokenExpired,
    } = await quest.getQuestDetails({
        entityId: "e-010",
        questId: "q-202",
    });
    ```

4.  Create Quest.

    Creates a quest for users of an entity to complete and get rewards.

    ```ts
    const eligibilityCirterias: ICreateQuestEligibilityCriteria = [];

    eligibilityCirterias.push(eligibilityCriteria.createUserInputText({
        title: "ENter your name",
        xp: 10,
        frequency: EligibilityCriteriaFrequencyConst.ONCE,
        effort: EligibilityCriteriaEffortConst.E1,
        importance: EligibilityCriteriaImportanceConst.I1,
    }));

    const rewards: ICreateQuestReward = [];

    rewards.push(reward.createXp({
        xp: 10,
    }))

    const { id, success, error, loginAgain, userTokenExpired } = await quest.createQuest({
        title: "Epic Adventure Quest",
        entityId: "Entity123",
        description: "Embark on a journey filled with challenges and rewards!",
        imageURL: "https://example.com/quest-image.jpg",
        endsAt: new Date("2023-12-31T23:59:59Z"),
        hasReferral: true,
        referralXP: 50,
        theme: {
            background: "#F0F0F0",
            textColor: "#333333"
        },
        isPrivate: false
        eligibilityCirterias: eligibilityCirterias,
        rewards: rewards,
    });
    ```

5.  Update Quest

    Updates a quest of an entity.

    ```js
    const { success, error } = await quest.updateQuest({
        entityId: "e-123",
        questId: "q-123",
        title: "Updated quest title",
    });
    ```

6.  Delete quest

    Deletes a quest.

    ```js
    const { success, error, message } = await quest.deleteQuest({
        entityId: "e-123",
        questId: "q-123",
    });
    ```

7.  Verify quest criteria for user

    Verifies a criteria for a user whether they have completed or not.

    ```js
    const { success, error, loginAgin, status } = await quest.verifyQuestCriteriaForAUser({
        entityId: "e-123",
        questId: "q-123",
        criteriaId: "c-1212",
        answer: ["My name is Jon"],
    });
    ```

8.  Verify multiple quest criterias for user

    Verifies multiple criteria for a user whether they have completed or not.

    ```js
    const { success, error, loginAgin, status } = await quest.verifyMultipleQuestCriteriaForAUser({
        entityId: "e-123",
        questId: "q-123",
        criterias: [
            {
                criteriaId: "c-1212",
                answer: ["My name is Jon"],
            },
            {
                criteriaId: "c-090",
                answer: [20],
            },
        ],
    });
    ```

9.  Claim quest rewards

    Allows user to claim the rewards of a quest if they have completed all the eligibility criterias.

    ```js
    const { success, error } = await quest.claimQuestRewards({
        questId: "q-123",
        entityId: "e-123",
    });
    ```

10. Get Quest Summary

    Get quest summary details.

    ```js
    const { summary, success, error } = await quest.getQuestSummary({
        entityId: "e-123",
        questId: "q-123",
    });
    ```

11. Get referral code of user for quest.

    Get referral code for the user for a particular quest, which can be used to share with others.

    ```js
    const { referralCode, success, error } = await quest.getOrSetNewReferralCodeForQuestAndUser({
        entityId: "e-123",
        questId: "q-123",
    });
    ```

12. Get referral leaderboard.

    Get leaderboard for all the referrals.

    ```js
    const { data, success, error } = await quest.getReferralLeaderboard({
        entityId: "e-123",
        questId: "q-123",
    });
    ```

13. Get quest submissions

    Get quest user submission details with referrals

    ```js
    const { data, success, error } = await quest.getQuestSubmissions({ questId: "q-121", entityId: "e-1212" });
    ```

14. Create metric quest

    Create metric quest which doesn't have any criterias other than metric

    ```js
    const { success, error, questId, loginAgain, userTokenExpired } = await quest.createMetricQuest({
            metric: {
                metricId: "daily_login",
                metricType: "threshold",
                threshold: 30
            },
            autoClaimRewards: true,
            repeatRewardsBasedOnMetricCount: false,
            title: "30 days login",
            rewards: [
                {
                    type: "REWARD_XP",
                    xp: 10,
                }
            ],
            description: "Login for 30 days",
        });
    ```

15. Get metric quest details

    Get metric quest details

    ```js
    const { success, error, data, loginAgain, userTokenExpired } = await quest.getMetricQuestDetails({
        questId: "q-893aa9ae-d479-4e89-80f0-7a99a8c50b96",
        entityId: "e-9946bedf-3c65-4111-b296-ca6fd2a3a738"
    });
    ```

### EntityCreditTier

Here are the methods of EntityCreditTier module and their use cases:

1. Add Credit Tier for Entity

    Add a new credit tier for an entity.

    ```js
    const { data, success, error } = await entityCreditTier.addCreditTierForEntity({
        creditsTierId: "tier123",
        creditsTierName: "New Tier",
        price: 10,
        creditsAmount: 100,
        extraCreditsAmount: 50,
        recurringTimePeriod: "MONTHLY",
        entityId: "entity123",
    });
    ```

2. Update Credit Tier for Entity

    Update an existing credit tier for an entity.

    ```js
    const { data, success, error } = await entityCreditTier.updateCreditTierForEntity({
        creditsTierId: "tier123",
        price: 15,
        entityId: "entity123",
    });
    ```

3. Get credit tiers for entity

    Fetches the credit tiers info of an entity.

    ```js
    const { data, success, error } = await entityCreditTier.getCreditTiersForEntity({
        entityId: "entity123",
    });
    ```

4. Get credit info for a user

    Fetches the credit info for a user of an entity.

    ```js
    const { data, success, error } = await entityCreditTier.getCreditInfoForUser({
        entityId: "entity123",
        forUserId: "user123",
    });
    ```

5. Buy credit for entity

    Purchase credits for an entity.

    ```js
    const { success, error } = await entityCreditTier.buyCreditsForEntity({
        creditsTierId: "tier123",
        intentId: "intent123",
        entityId: "entity123",
    });
    ```

6. Buy Credits for User

    Purchase credits for a user.

    ```js
    const { success, error } = await entityCreditTier.buyCreditsForUser({
        creditsTierId: "tier123",
        intentId: "intent123",
        entityId: "entity123",
        forUserId: "user123",
    });
    ```

7. Decrement credits for a user

    Decrements credits of a user.

    ```js
    const { success, error } = await entityCreditTier.decrementCreditsForUser({
        creditsAmount: 50,
        entityId: "entity123",
        forUserId: "user123",
    });
    ```

8. Decrement credits for a Entity

    Decrements credits of a Entity.

    ```js
    const { success, error } = await entityCreditTier.decrementCreditsForEntity({
        creditsAmount: 50,
        entityId: "entity123",
    });
    ```

9. Create Payment Intent for Entity

    Create a payment intent for an entity.

    ```js
    const { data, success, error } = await entityCreditTier.createPaymentIntentForEntity({
        entityId: "entity123",
        cardData: {
            email: "user@example.com",
            name: "John Doe",
            address: {
                country: "US",
                postal_code: 12345,
                city: "New York",
                state: "NY",
                line1: "123 Main St",
                line2: "Apt 4B",
            },
        },
        intentData: {
            paymentMethodId: "paymentMethod123",
            amount: 100,
            currency: "USD",
        },
    });
    ```

10. Approve payment for entity

    Approves a stripe payment using intentId created by createPaymentIntentForEntity

    ```js
    const { sucess, error } = await entityCreditTier.approvePaymentForEntity({
        entityId: "e-121",
        intentId: "e-121iklj",
    });
    ```

### EntityAuthenticationToken

Here are the methods of EntityAuthenticationToken module and their use cases:

1. Create Token

    Create a new authentication token for a user associated with an entity.

    ```js
    const { data, success, error } = await entityAuthenticationToken.createToken({
        entityId: "entity123",
    });
    ```

2. Update Token

    Update the authentication token for a user associated with an entity.

    ```js
    const { data, success, error } = await entityAuthenticationToken.updateToken({
        entityId: "entity123",
        expiry: "2023-12-31T23:59:59Z",
    });
    ```

3. Refresh Token

    Refresh the authentication token for a user associated with an entity.

    ```js
    const { data, success, error } = await entityAuthenticationToken.refreshToken({
        entityId: "entity123",
        authenticationToken: "your_existing_token_here",
    });
    ```

4. Delete Token

    Delete the authentication token for a user associated with an entity.

    ```js
    const { data, success, error } = await entityAuthenticationToken.deleteToken({
        entityId: "entity123",
    });
    ```

5. Get Token

    Get the authentication token for a user associated with an entity.

    ```js
    const { data, success, error } = await entityAuthenticationToken.getToken({
        entityId: "entity123",
        requestOrigin: "https://yourapp.com",
    });
    ```

### EntityDataContract

Here are the methods of Twitter module and their use cases:

1. Add new data contract for entity

    Add a new data contract for an entity.

    ```js
    const { datasetId, success, error } = await entityDataContract.addNewDataContractForEntity({
        name: "New Data Contract",
        description: "This is a new data contract",
        entityId: "entity123",
        source: "Source Name",
        fields: [
            {
                name: "Field 1",
                description: "Description for Field 1",
                validationRules: {
                    type: "string",
                    required: true,
                    minLength: 2,
                    maxLength: 50,
                },
            },
        ],
        tags: ["tag1", "tag2"],
    });
    ```

2. Get data contract by ID

    Get a data contract by ID for an entity.

    ```js
    const { data, success, error } = await entityDataContract.getDataContractByIdForAnEntity({
        entityId: "entity123",
        dataContractId: "dataContract123",
    });
    ```

3. Get all data contracts for an entity

    Get all data contracts associated with an entity.

    ```js
    const { data, success, error } = await entityDataContract.getAllDataContractsForAnEntity({
        entityId: "entity123",
    });
    ```

4. Update data contract for an entity

    Update a data contract for an entity.

    ```js
    const { success, error } = await entityDataContract.updateDataContractForEntity({
        entityId: "entity123",
        name: "Updated Data Contract",
        description: "This is an updated data contract",
        source: "Updated Source",
    });
    ```

5. Delete data contract for entity

    Delete a data contract for an entity.

    ```js
    const { success, error } = await entityDataContract.deleteDataContractForEntity({
        entityId: "entity123",
        dataContractId: "dataContract123",
    });
    ```

6. Chat with data contract

    Chat with a data contract for an entity.

    ```js
    const { data, success, error } = await entityDataContract.chatWithDataContractForEntity({
        entityId: "entity123",
        dataContractId: "dataContract123",
        userInput: "User input text",
        isInternal: true,
    });
    ```

7. Fetch fields from google sheets

    Fetch fields from a Google Sheets link for a data contract.

    ```js
    const { datasetId, success, error } = await entityDataContract.fetchFieldsFromGoogleSheets({
        entityId: "entity123",
        googleSheetLink: "https://docs.google.com/spreadsheets/d/your-sheet-id",
    });
    ```

8. Auto generate description

    Auto-generate a description for a data contract based on fields.

    ```js
    const { res, success, error } = await entityDataContract.autoGenerateDescription({
        entityId: "entity123",
        dataContractId: "dataContract123",
        fields: [
            {
                name: "Field 1",
                description: "Description for Field 1",
                validationRules: {
                    type: "string",
                    required: true,
                },
            },
        ],
    });
    ```

### EntityFeatureFlags

Here are the methods of EntityFeatureFlags module and their use cases:

1. Get all feature flags for an entity

    Retrieve all feature flags associated with an entity.

    ```js
    const { data, success, error } = await entityFeatureFlag.getAllFeatureFlagsForEntity({
        entityId: "entity123",
    });
    ```

2. Add new feature flag for entity

    Add a new feature flag for an entity.

    ```js
    const { success, error } = await entityFeatureFlag.addNewFeatureFlagForEntity({
        entityId: "entity123",
        flagName: "NewFeatureFlag",
        description: "This is a new feature flag",
        isEnabled: true,
    });
    ```

3. Toggle feature flag for entity

    Toggle the status of a feature flag for an entity.

    ```js
    const { success, error } = await entityFeatureFlag.toggleFeatureFlagForEntity({
        entityId: "entity123",
        flagName: "FeatureFlagName",
    });
    ```

4. Terminate feature flag

    Terminate a feature flag for an entity.

    ```js
    const { success, error } = await entityFeatureFlag.terminateFeatureFlagForEntity({
        entityId: "entity123",
        flagName: "FeatureFlagName",
    });
    ```

5. Get all feature flags stream

    Get a stream of all feature flags for an entity.

    ```js
    const eventSource = entityFeatureFlag.getAllFeatureFlagsStream({
        entityId: "entity123",
    });
    ```

### EntityPrompt

Here are the methods of EntityPrompt module and their use cases:

1. Add entity prompt

    Add a new entity prompt for a specific use case.

    ```js
    const { success, error, usecase } = await entityPrompt.addEntityPrompt({
        entityId: "entity123",
        usecase: "Usecase1",
        actualPrompt: "Please provide your name.",
    });
    ```

2. Generate prompt response by usecase

    Generate a prompt response for a specific use case.

    ```js
    const { success, error, data } = await entityPrompt.generatePromptResponseByUsecase({
        entityId: "entity123",
        usecase: "Usecase1",
        message: "John Doe",
    });
    ```

3. Update entity prompt

    Update an existing entity prompt for a specific use case.

    ```js
    const { success, error, usecase } = await entityPrompt.updateEntityPrompt({
        entityId: "entity123",
        usecase: "Usecase1",
        actualPrompt: "Please provide your updated name.",
    });
    ```

### GPT

Here are the methods of GPT module and their use cases:

1. Create Text Embedding for Entity

    Create text embeddings for an entity.

    ```js
    const { embedding, success, error } = await gpt.createTextEmbeddingForEntity({
        embeddingText: "This is a sample text for embedding",
        entityId: "entity123",
    });
    ```

2. Make Prompt Request with Embedding

    Make a prompt request with text embedding for an entity.

    ```js
    const { data, success, error } = await gpt.makePromptRequestWithEmbedding({
        input: "Generate a response based on this input.",
        entityId: "entity123",
    });
    ```

### Twitter

Here are the methods of Twitter module and their use cases:

1. Connect twitter

    Allows a user to connect their twitter account to an entity.

    ```js
    const response = await SDK.social.twitter.connect({
        twitterRedirectCode: "redirect-code-124",
        redirectUri: "http://localhost:3000/profile/twitter",
        entityId: "e-123",
        userId: "u-124",
        token: "login-token-123",
    });
    ```

2. Disconnect twitter

    Disconnects the user's twitter account from an entity.

    ```js
    const response = await SDK.social.twitter.disconnect("e-123", "u-124", "login-token-123");
    ```

### Discord

Here are the methods of Discord module and their use cases:

1. Connect discord

    Allows a user to connect their discord account to an entity.

    ```js
    const response = await SDK.social.discord.connect({
        discordRedirectCode: "redirect-code-124",
        redirectUri: "http://localhost:3000/profile/discord",
        entityId: "e-123",
        userId: "u-124",
        token: "login-token-123",
    });
    ```

2. Disconnect discord

    Disconnects the user's discord account from an entity.

    ```js
    const response = await SDK.social.discord.disconnect("e-123", "u-124", "login-token-123");
    ```

3. Fetch my guilds

    Fetches all the guilds/servers the user is a part of.

    ```js
    const response = await SDK.social.discord.fetchMyGuilds({
        entityId: "e-123",
        userId: "u-124",
        token: "login-token-123",
    });
    ```
