Class: TorqueUserClient
@torque-labs/torque-ts-sdk • Docs
@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): TorqueUserClientCreate a new instance of the TorqueUserClient class with the publisher's handle, if provided.
Parameters
Returns
Throws
Throws an error if the user's wallet is not provided.
Defined in
Properties
apiUrl
string
appUrl
string
client
connection
Connection
initialized
boolean
publicKey
string
publisherHandle
string
signer
Adapter | Keypair
user
undefined | ApiUser
PUBLISHER_ACCOUNT_SIZE
number
Methods
acceptCampaign()
acceptCampaign(campaignId, publisherHandle?): Promise<ApiUserJourney>Initiate a user journey to accept a campaign for the current user.
Parameters
campaignId
string
The ID of the campaign to accept.
publisherHandle?
string
The handle of the publisher to accept the campaign for.
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
authTelegram()
authTelegram(user): Promise<ApiTelegramAuth>Links user's telegram account to their Torque account.
Parameters
user
object
user.auth_date
number
user.first_name
string
user.hash
string
user.id
number
user.photo_url
string
user.username
string
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
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
campaignId
string
The ID of the campaign/offer to confirm the signature for.
index
number
The index of the offer requirement within the campaign.
encodedMessage
string
-
Returns
Promise<ActionPostResponse>
A Solana action response that contains the next requirement.
Defined in
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
customEvent
object
The configuration of the custom event.
customEvent.config
Record<string, CustomEventFieldType>
-
customEvent.name
string
-
Returns
Promise<{ id: string; }>
A Promise that resolves to the id of the new custom event.
id
string
Defined in
getAllUserShareLinks()
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.
links
{ campaignId: string; url: string; }[]
Throws
An error if the link fetch fails.
Defined in
getBountyStepAction()
getBountyStepAction(
campaignId,
actionIndex,
data): Promise<ActionPostResponse>Get the Solana action for a specific bounty/requirement step.
Parameters
campaignId
string
The ID of the campaign to retrieve the journey for.
actionIndex
number
The index of the offer requirement to retrieve the transaction for.
data
Record<string, string>
Additional data to be sent with the request.
Returns
Promise<ActionPostResponse>
The Solana Action response which contains the transaction.
Defined in
getCampaignJourney()
getCampaignJourney(campaignId): Promise<undefined | ApiCampaignJourney>Retrieves the user's campaign journey for the specified campaign.
Parameters
campaignId
string
The ID of the campaign to retrieve the journey for.
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
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
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
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
getMaxTransferableSpl()
getMaxTransferableSpl(token): Promise<number>Parameters
token
PublicKey
Returns
Promise<number>
Defined in
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
profileSlug?
string
Returns
Promise<{ campaigns: ApiCampaign[]; }>
A Promise resolving to an array of ApiCampaign objects representing the active campaigns.
campaigns
Throws
An error if the fetch operation fails, or if the API returns a status other than "SUCCESS".
Defined in
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
getPublisherPda()
getPublisherPda(): undefined | PublicKeyGet the publisher PDA for the current user.
Returns
undefined | PublicKey
The publisher PDA for the current user.
Defined in
getSharedLinkData()
getSharedLinkData(campaignId, handle): Promise<ApiShare>Retrieves the data for an offer link for a specific campaign and handle.
Parameters
campaignId
string
The unique identifier for the campaign.
handle
string
The specific handle associated with the shared link.
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
getUserHandle()
getUserHandle(): undefined | stringRetrieves the user's handle.
Returns
undefined | string
The user's handle or undefined if no handle is available.
Defined in
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
getUserShareLink()
getUserShareLink(campaignId): stringGenerates a URL for a user's shared link for a specific campaign.
Parameters
campaignId
string
The unique identifier for the campaign.
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
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
isPublisher()
isPublisher(): booleanChecks 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
login()
private login(loginOptions): Promise<ApiUser>Authenticate the user with the torque API with the provided user signature object.
Parameters
loginOptions
The verification object that is required to authenticate a user with Torque.
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
logout()
logout(): Promise<{
cleared: boolean;
}>Logout the user from the Torque API.
Returns
Promise<{ cleared: boolean; }>
cleared
boolean
Throws
Throws an error if the client is not initialized or if there is an error logging out the user.
Defined in
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
setUserPublisher()
setUserPublisher(): voidReturns
void
Defined in
updateCustomEvent()
updateCustomEvent(customEvent): Promise<{
id: string;
}>Updates an existing custom event for the user's account.
Parameters
customEvent
object
The updated configuration of the custom event.
customEvent.config
Record<string, CustomEventFieldType>
-
customEvent.id
string
-
customEvent.name
string
-
Returns
Promise<{ id: string; }>
A Promise that resolves to the id of the updated custom event.
id
string
Defined in
verifyCampaignAudience()
verifyCampaignAudience(campaignId): Promise<boolean>Verifies that the user is part of the audience for a specific campaign.
Parameters
campaignId
string
The ID of the campaign to verify the audience for.
Returns
Promise<boolean>
A Promise that resolves to true if the user is part of the audience for the campaign, false otherwise.
Defined in
Last updated