Class: TorqueUserClient

@torque-labs/torque-ts-sdkDocs


@torque-labs/torque-ts-sdk / TorqueUserClient

Class: TorqueUserClient

The TorqueUserClient class is used to authenticate a user with the Torque API. The user client allows publishers to fetch campaigns and offers that are savailable for the current user.

Example

const client = new TorqueUserClient(TorqueUserClientOptions);

// Check if the user is already logged in with API
const currentUser = await client.getCurrentUser();

const user = currentUser
  ? currentUser
  : await this.initializeUser(ApiInputLogin);

Constructors

new TorqueUserClient()

new TorqueUserClient(options): TorqueUserClient

Create a new instance of the TorqueUserClient class with the publisher's handle, if provided.

Parameters

Returns

TorqueUserClient

Throws

Throws an error if the user's wallet is not provided.

Defined in

src/classes/user.ts:93

Properties

Methods

acceptCampaign()

acceptCampaign(campaignId, publisherHandle?): Promise<ApiUserJourney>

Initiate a user journey to accept a campaign for the current user.

Parameters

Returns

Promise<ApiUserJourney>

A Promise that resolves to the journey data for the campaign.

Throws

Throws an error if the client is not initialized or if there is an error accepting the campaign.

Defined in

src/classes/user.ts:420


authTelegram()

authTelegram(user): Promise<ApiTelegramAuth>

Links user's telegram account to their Torque account.

Parameters

Returns

Promise<ApiTelegramAuth>

The data associated with the shared link if the request is successful.

Throws

Throws an error there was an error getting the shared link data.

Defined in

src/classes/user.ts:939


confirmActionSignature()

confirmActionSignature(
   campaignId, 
   index, 
encodedMessage): Promise<ActionPostResponse>

Sends a signed message to the Torque API to confirm the user's signature for a requirement.

Parameters

Returns

Promise<ActionPostResponse>

A Solana action response that contains the next requirement.

Defined in

src/classes/user.ts:692


createCustomEvent()

createCustomEvent(customEvent): Promise<{
  id: string;
}>

Creates a new a custom event for the user's account which can be used for custom event requirements during a campaign.

Parameters

Returns

Promise<{ id: string; }>

A Promise that resolves to the id of the new custom event.

Defined in

src/classes/user.ts:584


getAllUserShareLinks(): Promise<{
  links: {
     campaignId: string;
     url: string;
    }[];
}>

Fetches all of the user's share links that they have previously created.

Returns

Promise<{ links: { campaignId: string; url: string; }[]; }>

A Promise resolving to the URLs of the user's share links.

Throws

An error if the link fetch fails.

Defined in

src/classes/user.ts:828


getBountyStepAction()

getBountyStepAction(
   campaignId, 
   actionIndex, 
data): Promise<ActionPostResponse>

Get the Solana action for a specific bounty/requirement step.

Parameters

Returns

Promise<ActionPostResponse>

The Solana Action response which contains the transaction.

Defined in

src/classes/user.ts:648


getCampaignJourney()

getCampaignJourney(campaignId): Promise<undefined | ApiCampaignJourney>

Retrieves the user's campaign journey for the specified campaign.

Parameters

Returns

Promise<undefined | ApiCampaignJourney>

A Promise that resolves to the user's campaign journey.

Throws

Throws an error if the client is not initialized or if there is an error getting the journey.

Defined in

src/classes/user.ts:454


getCurrentUser()

getCurrentUser(): Promise<undefined | ApiUser>

Checks to see if the user is already logged into the Torque API.

Returns

Promise<undefined | ApiUser>

A promise that resolves to the user if they are signed in, otherwise undefined.

Throws

Throws an error if checking the user's login status fails.

Defined in

src/classes/user.ts:321


getCustomEvents()

getCustomEvents(): Promise<{
  config: Record<string, CustomEventFieldType>;
  id: string;
  name: string;
}[]>

Fetches the user's custom events

Returns

Promise<{ config: Record<string, CustomEventFieldType>; id: string; name: string; }[]>

A Promise that resolves to an array of custom events.

Throws

If the client is not initialized or there was an error fetching the custom events.

Defined in

src/classes/user.ts:556


getJourneys()

getJourneys(): Promise<undefined | ApiCampaignJourney[]>

Retrieves the user's campaign journeys

Returns

Promise<undefined | ApiCampaignJourney[]>

A Promise that resolves to the user's campaign journey.

Throws

Throws an error if the client is not initialized or if there is an error getting the journey.

Defined in

src/classes/user.ts:490


getMaxTransferableSpl()

getMaxTransferableSpl(token): Promise<number>

Parameters

Returns

Promise<number>

Defined in

src/classes/user.ts:782


getOffers()

getOffers(profileSlug?): Promise<{
  campaigns: ApiCampaign[];
}>

Retrieves a list of active campaigns from the Torque API that the user is eligible to participate in.

Parameters

Returns

Promise<{ campaigns: ApiCampaign[]; }>

A Promise resolving to an array of ApiCampaign objects representing the active campaigns.

Throws

An error if the fetch operation fails, or if the API returns a status other than "SUCCESS".

Defined in

src/classes/user.ts:385


getPublisherBalance()

getPublisherBalance(): Promise<number>

Get the balance of the publisher PDA for the current user.

Returns

Promise<number>

The balance of the publisher PDA for the current user in lamports.

Defined in

src/classes/user.ts:805


getPublisherPda()

getPublisherPda(): undefined | PublicKey

Get the publisher PDA for the current user.

Returns

undefined | PublicKey

The publisher PDA for the current user.

Defined in

src/classes/user.ts:769


getSharedLinkData()

getSharedLinkData(campaignId, handle): Promise<ApiShare>

Retrieves the data for an offer link for a specific campaign and handle.

Parameters

Returns

Promise<ApiShare>

The data associated with the shared link if the request is successful.

Throws

Throws an error there was an error getting the shared link data.

Defined in

src/classes/user.ts:870


getUserHandle()

getUserHandle(): undefined | string

Retrieves the user's handle.

Returns

undefined | string

The user's handle or undefined if no handle is available.

Defined in

src/classes/user.ts:359


getUserPayout()

getUserPayout(): Promise<ApiUserPayout>

Retrieves user's payout history from conversions.

Returns

Promise<ApiUserPayout>

The data associated with the shared link if the request is successful.

Throws

Throws an error there was an error getting the shared link data.

Defined in

src/classes/user.ts:906


getUserShareLink(campaignId): string

Generates a URL for a user's shared link for a specific campaign.

Parameters

Returns

string

A promise that resolves to the URL string of the user's shared link for the campaign.

Throws

Throws an error if the user is not a publisher or does not have a handle.

Defined in

src/classes/user.ts:751


initializeUser()

initializeUser(userAuth?): Promise<ApiUser>

Initializes the TorqueUserClient with the provided options.

Parameters

Returns

Promise<ApiUser>

A Promise that resolves when the initialization is complete.

Throws

If user was not verified.

Defined in

src/classes/user.ts:133


isPublisher()

isPublisher(): boolean

Checks to see if the user is a publisher.

Returns

boolean

True if the user is a publisher, false otherwise.

Throws

Throws an error if the user is not signed in.

Defined in

src/classes/user.ts:734


login()

private login(loginOptions): Promise<ApiUser>

Authenticate the user with the torque API with the provided user signature object.

Parameters

Returns

Promise<ApiUser>

A Promise that resolves to an object containing the user information.

Throws

Throws an error if there is an error authenticating the user.

Defined in

src/classes/user.ts:222


logout()

logout(): Promise<{
  cleared: boolean;
}>

Logout the user from the Torque API.

Returns

Promise<{ cleared: boolean; }>

Throws

Throws an error if the client is not initialized or if there is an error logging out the user.

Defined in

src/classes/user.ts:247


refreshUser()

refreshUser(): Promise<undefined | ApiUser>

Rereshes the user's information from the Torque API.

Returns

Promise<undefined | ApiUser>

A promise that resolves to the user if they are signed in, otherwise undefined.

Defined in

src/classes/user.ts:283


setUserPublisher()

setUserPublisher(): void

Returns

void

Defined in

src/classes/user.ts:852


updateCustomEvent()

updateCustomEvent(customEvent): Promise<{
  id: string;
}>

Updates an existing custom event for the user's account.

Parameters

Returns

Promise<{ id: string; }>

A Promise that resolves to the id of the updated custom event.

Defined in

src/classes/user.ts:615


verifyCampaignAudience()

verifyCampaignAudience(campaignId): Promise<boolean>

Verifies that the user is part of the audience for a specific campaign.

Parameters

Returns

Promise<boolean>

A Promise that resolves to true if the user is part of the audience for the campaign, false otherwise.

Defined in

src/classes/user.ts:524

Last updated