@looplay/sdk 0.8.9 → 0.8.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,14 @@
1
- import type { EmitGameEventResponse, GameAssetDto, GameEventKey, GameOwnedAssetDto, GameStoreDto, GameStoreOfferPurchaseResultDto, PagingResponse } from './LooplaySDK.types';
1
+ import type { EmitGameEventResponse, GameAssetDto, GameEventKey, GameOwnedAssetDto, GameStoreDto, GameStoreOfferPurchaseResultDto, PagingResponse, PlaySessionDto, StartPlaySessionRequest } from './LooplaySDK.types';
2
2
  import { ServiceClient } from './service-client';
3
3
  import type { ServiceClientOptions } from './service-client';
4
+ /** Signed `playSessionToken` for the current play session — required on every play/match/action call. */
5
+ export interface CachedPlaySession {
6
+ cacheKey: string;
7
+ gameKey: string;
8
+ playSessionId: string;
9
+ playSessionToken: string;
10
+ expiresAtMs: number;
11
+ }
4
12
  export interface ApiClientOptions extends Omit<ServiceClientOptions, 'baseUrl'> {
5
13
  baseUrl?: string;
6
14
  getAccessToken?: () => Promise<string | undefined>;
@@ -21,11 +29,11 @@ export declare class ApiClient {
21
29
  private trackingSession?;
22
30
  private trackingSessionPromiseKey?;
23
31
  private trackingSessionPromise?;
24
- private currentPlaySessionId?;
25
- private playSession?;
32
+ currentPlaySessionId?: string;
33
+ playSession?: CachedPlaySession;
26
34
  private playSessionPromiseKey?;
27
35
  private playSessionPromise?;
28
- constructor(options: ApiClientOptions);
36
+ constructor(options?: ApiClientOptions);
29
37
  /** Expose the underlying route-level client (requires manual bearerToken/gameKey passing). */
30
38
  unsafeRaw(): ServiceClient;
31
39
  detectIntegration(gameKey: string): Promise<boolean>;
@@ -65,6 +73,21 @@ export declare class ApiClient {
65
73
  * `startPlaySession()`, auto-starting one on first use if none was started.
66
74
  */
67
75
  startPlaySession(): string;
76
+ /**
77
+ * Starts a new play session on the server and caches the signed immediately.
78
+ */
79
+ startPlaySessionAsync(gameKey: string, body?: StartPlaySessionRequest): Promise<PlaySessionDto>;
80
+ /**
81
+ * Explicitly sets or updates the active play session token cache.
82
+ */
83
+ setPlaySession(playSession: {
84
+ gameKey: string;
85
+ playSessionId: string;
86
+ playSessionToken: string;
87
+ expiresAtMs?: number;
88
+ }): void;
89
+ /** Returns the active cached play session, or undefined if none has been issued yet. */
90
+ getCurrentPlaySession(): CachedPlaySession | undefined;
68
91
  trackPlay(gameKey: string, playTimeSeconds?: number): Promise<boolean>;
69
92
  trackMatch(gameKey: string, body: {
70
93
  matchId: string;
@@ -1,6 +1,6 @@
1
1
  export type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
2
2
  export interface HttpClientOptions {
3
- baseUrl: string;
3
+ baseUrl?: string;
4
4
  fetch?: FetchLike;
5
5
  defaultHeaders?: Record<string, string>;
6
6
  }
@@ -13,7 +13,7 @@ export declare class HttpClient {
13
13
  private readonly baseUrl;
14
14
  private readonly fetchFn;
15
15
  private readonly defaultHeaders;
16
- constructor(options: HttpClientOptions);
16
+ constructor(options?: HttpClientOptions);
17
17
  request<T>(method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE', path: string, options?: {
18
18
  query?: Record<string, string | number | boolean | undefined>;
19
19
  headers?: Record<string, string | undefined>;
@@ -34,9 +34,17 @@ export interface SdkKeyPairAuth {
34
34
  * Low-level HTTP client that maps 1:1 to backend routes.
35
35
  * Methods requiring user auth accept `bearerToken` explicitly.
36
36
  */
37
+ export type PlaySessionIssuedListener = (dto: PlaySessionDto, gameKey: string, auth: TrackingAuth) => void;
37
38
  export declare class ServiceClient {
38
39
  private readonly http;
40
+ private readonly playSessionTokens;
41
+ private onPlaySessionIssuedListener?;
39
42
  constructor(options: ServiceClientOptions);
43
+ /**
44
+ * Internal hook for ApiClient to subscribe to issued/renewed play sessions.
45
+ * @internal
46
+ */
47
+ _setOnPlaySessionIssued(listener?: PlaySessionIssuedListener): void;
40
48
  telegramLogin(telegramInitData: string): Promise<AuthResultDto>;
41
49
  refresh(refreshToken: string): Promise<AuthResultDto>;
42
50
  logout(refreshToken: string): Promise<boolean>;
@@ -1,5 +1,6 @@
1
- import { ApiClient } from "../apps/api-client";
2
- import type { EmitGameEventResponse, GameEventKey } from "../apps/LooplaySDK.types";
1
+ import { ApiClient, type CachedPlaySession } from "../apps/api-client";
2
+ import type { EmitGameEventResponse, GameEventKey, PlaySessionDto, StartPlaySessionRequest } from "../apps/LooplaySDK.types";
3
+ import type { ServiceClient } from "../apps/service-client";
3
4
  import type { EmitGameEventOptions, LooplayIframeAuthListener, LooplayIframeAuthOptions, LooplayIframeAuthState, RequestAdsOptions, TrackMatchOptions } from "./types";
4
5
  /**
5
6
  * Handles auth for games that may run in two contexts:
@@ -37,7 +38,7 @@ export declare class LooplayIframeAuth {
37
38
  constructor(options?: LooplayIframeAuthOptions);
38
39
  getState(): LooplayIframeAuthState;
39
40
  getJwt(): string | null;
40
- getApiUrl(): string | null;
41
+ getApiUrl(): string;
41
42
  /** Resolves to the configured `appId`, falling back to whatever the parent pushed as `gameId`. */
42
43
  getGameId(): string | null;
43
44
  getAnonymousId(): string | null;
@@ -58,10 +59,18 @@ export declare class LooplayIframeAuth {
58
59
  dispose(): void;
59
60
  /** Lazily builds (and rebuilds on auth change) the `ApiClient` bound to the current auth mode. */
60
61
  getClient(): ApiClient;
62
+ get currentPlaySessionId(): string | undefined;
63
+ get playSession(): CachedPlaySession | undefined;
64
+ unsafeRaw(): ServiceClient;
61
65
  /** Call once when the game view opens, before any play/match tracking. */
62
66
  trackView(): Promise<boolean>;
63
67
  /** Starts a new play session; call when the user presses Play. Returns the play session id. */
64
68
  startPlaySession(): string;
69
+ /**
70
+ * Starts a new play session asynchronously on the backend; returns the issued PlaySessionDto
71
+ * (containing playSessionId and playSessionToken) or null if auth/tracking is not ready.
72
+ */
73
+ startPlaySessionAsync(body?: StartPlaySessionRequest): Promise<PlaySessionDto | null>;
65
74
  trackPlay(playTimeSeconds?: number): Promise<boolean>;
66
75
  trackMatch(matchId: string, opts: TrackMatchOptions): Promise<boolean>;
67
76
  emitGameEvent(actionCode: GameEventKey | string, opts?: EmitGameEventOptions): Promise<EmitGameEventResponse | null>;
@@ -1,7 +1,8 @@
1
1
  import type { LooplayInitParams, LooplaySDKCreateOptions } from './types';
2
2
  import { LooplayAuth } from './auth/looplay-auth';
3
- import { ApiClient } from './apps/api-client';
4
- import type { EmitGameEventResponse, GameEventKey } from './apps/LooplaySDK.types';
3
+ import { ApiClient, type CachedPlaySession } from './apps/api-client';
4
+ import type { EmitGameEventResponse, GameEventKey, PlaySessionDto, StartPlaySessionRequest } from './apps/LooplaySDK.types';
5
+ import type { ServiceClient } from './apps/service-client';
5
6
  export declare class LooplaySDK {
6
7
  readonly auth?: LooplayAuth;
7
8
  readonly api?: ApiClient;
@@ -11,11 +12,19 @@ export declare class LooplaySDK {
11
12
  init(params: LooplayInitParams): Promise<void>;
12
13
  getAccessToken(): Promise<string | undefined>;
13
14
  getGameId(): string | undefined;
15
+ get currentPlaySessionId(): string | undefined;
16
+ get playSession(): CachedPlaySession | undefined;
17
+ unsafeRaw(): ServiceClient | undefined;
14
18
  getMyProfile(): Promise<any>;
15
19
  /** Call once when the game view opens, before any play/match tracking. */
16
20
  trackView(): Promise<boolean>;
17
21
  /** Starts a new play session; call when the user presses Play. Returns the play session id. */
18
22
  startPlaySession(): string;
23
+ /**
24
+ * Starts a new play session asynchronously on the backend; returns the issued PlaySessionDto
25
+ * (containing playSessionId and playSessionToken).
26
+ */
27
+ startPlaySessionAsync(body?: StartPlaySessionRequest): Promise<PlaySessionDto>;
19
28
  trackPlay(playTimeSeconds?: number): Promise<boolean>;
20
29
  /**
21
30
  * Report that a match/round ended.
@@ -1 +1 @@
1
- export declare const LOOPLAY_SDK_VERSION = "0.8.5";
1
+ export declare const LOOPLAY_SDK_VERSION = "0.8.11";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@looplay/sdk",
3
- "version": "0.8.9",
3
+ "version": "0.8.11",
4
4
  "description": "LooplaySDK (auth + points) for game integrations",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",