Session SDK
The Session SDK provides methods to manage user sessions and retrieve session analytics for your games on the GetJar platform.
Initialization
import { Configuration, Session } from '@eightpointio/getjar-iap-sdk';
const config = new Configuration({
basePath: 'url',
headers: { 'x-api-key': 'key' }
});
const sessionClient = new Session(config);
Methods
createSession
Creates a new user session for an game.
Parameters:
payload(ICreateSessionRequest): Session datagameId(string, optional): Game IDgameId(number, optional): Game IDcognitoUserId(string): User's Cognito IDplatform(Platform): Platform being usedgameVersion(string): Game versionmetadata(Record, optional): Additional session datagameName(string, optional): Game name
Returns: Promise<ISession>
const session = await sessionClient.createSession({
gameId: 'game-123',
cognitoUserId: 'user-456',
platform: Platform.WEB,
gameVersion: '1.0.0',
metadata: {
deviceType: 'desktop',
browser: 'Chrome'
}
});
getSessionById
Retrieves a specific session by its ID.
Parameters:
sessionId(string): Session ID
Returns: Promise<ISession>
const session = await sessionClient.getSessionById('session-789');
getGameSessions
Retrieves all sessions for a specific game with optional filtering and pagination.
Parameters:
gameId(string): Game IDprops(IQuerySessionsRequest, optional): Query parameterslimit(number): Items per pagepage(number): Page numbersortOrder(SortOrderEnum): Sort orderstartDate(string): Filter from dateendDate(string): Filter to dategameId(string): Additional game filterplatform(Platform): Filter by platform
Returns: Promise<PaginatedResponse<ISession>>
const sessions = await sessionClient.getGameSessions('game-123', {
limit: 50,
page: 1,
platform: Platform.WEB,
startDate: '2025-01-01',
endDate: '2025-01-31'
});
terminateSession
Manually terminates an active session.
Parameters:
sessionId(string): Session IDpayload(object): Termination datareason(string, optional): Reason for terminationendedAt(string, optional): Custom end timestamp
Returns: Promise<void>
await sessionClient.terminateSession('session-789', {
reason: 'User logged out',
endedAt: new Date().toISOString()
});
Types
Platform
enum Platform {
IOS = 'ios',
ANDROID = 'android',
WEB = 'web',
WINDOWS = 'windows',
MACOS = 'macos',
LINUX = 'linux',
OTHER = 'other'
}
ISession
interface ISession {
sessionId: string;
cognitoUserId: string;
gameId: string;
gameName?: string;
platform: Platform;
gameVersion: string;
metadata?: Record;
createdAt: Date;
duration?: number;
updatedAt: Date;
deletedAt?: Date;
}
PaginatedResponse
interface PaginatedResponse<T> {
items: T[];
pagination: {
total: number;
page: number;
limit: number;
totalPages: number;
hasNextPage: boolean;
hasPreviousPage: boolean;
};
}