Skip to main content

User SDK

The User SDK provides methods to manage user accounts, virtual currency, and retrieve user summaries on the GetJar platform.

Initialization

import { Configuration, User } from '@eightpointio/getjar-iap-sdk';

const config = new Configuration({
basePath: 'url',
headers: { 'x-api-key': 'key' }
});

const userClient = new User(config);

Methods

findOne

Retrieves a specific user by their ID with optional field filtering.

Parameters:

  • userId (string): User ID (Cognito User ID)
  • fields (string[], optional): Specific fields to retrieve

Returns: Promise<IUser>

const user = await userClient.findOne('user-123');

const userWithFields = await userClient.findOne('user-123', ['email', 'username', 'currency']);

addCurrency

Adds virtual currency to a user's account.

Parameters:

  • userId (string): User ID
  • payload (IAddCurrencyRequest): Currency data
    • amount (number): Amount to add

Returns: Promise<ICurrencyResponse>

const result = await userClient.addCurrency('user-123', {
amount: 100
});

console.log(result.success);
console.log(result.currency);

spendCurrency

Deducts virtual currency from a user's account.

Parameters:

  • userId (string): User ID
  • payload (ISpendCurrencyRequest): Currency data
    • amount (number): Amount to spend

Returns: Promise<ICurrencyResponse>

const result = await userClient.spendCurrency('user-123', {
amount: 50
});

console.log(result.success);
console.log(result.currency);

giveCoinsBasedOnLastActivity

Awards coins to a user based on their last activity in an application (e.g., daily login bonus).

Parameters:

  • userId (string): User ID
  • appId (string): Application ID

Returns: Promise<IGiveCoinsResponse>

const result = await userClient.giveCoinsBasedOnLastActivity('user-123', 'app-456');

console.log(result.success);
console.log(result.coinsGiven);
console.log(result.newCurrency);

Types

UserRoles

enum UserRoles {
END_USER = 'END_USER',
DEVELOPER = 'DEVELOPER',
ADMIN = 'ADMIN',
SUPPORT = 'SUPPORT',
BETA_TESTER = 'BETA_TESTER'
}

AccountTier

enum AccountTier {
FREE = 'free',
PREMIUM = 'premium',
FAMILY = 'family',
UNLIMITED = 'unlimited'
}

IUser

interface IUser {
cognitoUserId: string;
email: string;
emailVerified: boolean;
name?: string;
firstName?: string;
lastName?: string;
username: string;
dateOfBirth?: Date;
country?: string;
city?: string;
language?: string;
role: UserRoles[];
currency: number;
accountTier: AccountTier;
lastLoginAt?: Date;
lastActivityAt?: Date;
lastPasswordChangeAt?: Date;
developerId?: string;
isProfileCompleted: boolean;
avatarUrl?: string;
avatarKey?: string;
createdAt: Date;
updatedAt: Date;
deletedAt?: Date;
}

ICurrencyResponse

interface ICurrencyResponse {
success: boolean;
currency: number;
}

IGiveCoinsResponse

interface IGiveCoinsResponse {
success: boolean;
newCurrency: number;
coinsGiven: number;
}

IAddCurrencyRequest

interface IAddCurrencyRequest {
amount: number;
}

ISpendCurrencyRequest

interface ISpendCurrencyRequest {
amount: number;
}