@looplay/sdk 0.7.0 → 0.8.2
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.
- package/README.md +101 -21
- package/dist/looplay-sdk-realtime.cjs.js +73 -0
- package/dist/looplay-sdk-realtime.cjs.js.map +1 -0
- package/dist/looplay-sdk-realtime.esm.js +71 -0
- package/dist/looplay-sdk-realtime.esm.js.map +1 -0
- package/dist/looplay-sdk-realtime.min.js +3 -0
- package/dist/looplay-sdk-realtime.min.js.map +1 -0
- package/dist/looplay-sdk.cjs.js +84 -8
- package/dist/looplay-sdk.cjs.js.map +1 -1
- package/dist/looplay-sdk.esm.js +84 -8
- package/dist/looplay-sdk.esm.js.map +1 -1
- package/dist/looplay-sdk.min.js +2 -2
- package/dist/looplay-sdk.min.js.map +1 -1
- package/dist/types/apps/LooplaySDK.types.d.ts +60 -0
- package/dist/types/apps/api-client.d.ts +11 -0
- package/dist/types/apps/service-client.d.ts +20 -1
- package/dist/types/apps/ws-client.d.ts +35 -0
- package/dist/types/realtime.d.ts +9 -0
- package/package.json +17 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type HttpClientOptions } from './http';
|
|
2
|
-
import type { AuthResultDto, CompleteGameplayAttemptRequest, CompleteGameplayMatchRequest, EmitGameEventResponse, GameAssetDto, GameOwnedAssetDto, GameplayAttemptSessionDto, GameStoreDto, GameStoreOfferPurchaseResultDto, GameTrackingSessionDto, PagingResponse, RecordGameplayActionRequest, StartGameplayAttemptRequest, TaskListQuery } from './LooplaySDK.types';
|
|
2
|
+
import type { AuthResultDto, CompleteGameplayAttemptRequest, CompleteGameplayMatchRequest, EmitGameEventResponse, GameAssetDto, GameOwnedAssetDto, GameplayAttemptSessionDto, GameStoreCheckoutIntentDto, GameStoreDto, GameStoreOfferPurchaseResultDto, GameTrackingSessionDto, PagingResponse, RecordGameplayActionRequest, SdkCreateGameStoreCheckoutIntentRequest, SdkPurchaseGameStoreOfferRuntimeRequest, StartGameplayAttemptRequest, TaskListQuery } from './LooplaySDK.types';
|
|
3
3
|
export interface ServiceClientOptions extends HttpClientOptions {
|
|
4
4
|
}
|
|
5
5
|
/**
|
|
@@ -17,6 +17,19 @@ export interface TrackingAuth {
|
|
|
17
17
|
trackingSessionId?: string;
|
|
18
18
|
anonTrackingToken?: string;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Auth for the creator-secret tier (`createGameStoreCheckoutIntent`/
|
|
22
|
+
* `purchaseGameStoreOffer`) — moves real coin balance. `creatorKey`/
|
|
23
|
+
* `gameSecret` identify your integration (never embed these in
|
|
24
|
+
* client/browser code); `bearerToken` identifies the player you're
|
|
25
|
+
* purchasing on behalf of, same as any other authenticated call.
|
|
26
|
+
*/
|
|
27
|
+
export interface SdkKeyPairAuth {
|
|
28
|
+
creatorKey: string;
|
|
29
|
+
gameSecret: string;
|
|
30
|
+
bearerToken: string;
|
|
31
|
+
trackingSessionId?: string;
|
|
32
|
+
}
|
|
20
33
|
/**
|
|
21
34
|
* Low-level HTTP client that maps 1:1 to backend routes.
|
|
22
35
|
* Methods requiring user auth accept `bearerToken` explicitly.
|
|
@@ -48,6 +61,12 @@ export declare class ServiceClient {
|
|
|
48
61
|
listMyGameAssets(bearerToken: string, gameKey: string): Promise<GameOwnedAssetDto[]>;
|
|
49
62
|
/** The authenticated player's past store purchases for this game. */
|
|
50
63
|
listMyStorePurchases(bearerToken: string, gameKey: string): Promise<GameStoreOfferPurchaseResultDto[]>;
|
|
64
|
+
/** Signs a `checkoutToken` for one purchase — required by `purchaseMyStoreOffer`. */
|
|
65
|
+
createMyStoreCheckoutIntent(gameKey: string, bearerToken: string, body: SdkCreateGameStoreCheckoutIntentRequest, trackingSessionId?: string): Promise<GameStoreCheckoutIntentDto>;
|
|
66
|
+
purchaseMyStoreOffer(gameKey: string, bearerToken: string, body: SdkPurchaseGameStoreOfferRuntimeRequest, trackingSessionId?: string): Promise<GameStoreOfferPurchaseResultDto>;
|
|
67
|
+
/** Signs a `checkoutToken` for one purchase — required by `purchaseGameStoreOffer`. */
|
|
68
|
+
createGameStoreCheckoutIntent(auth: SdkKeyPairAuth, body: SdkCreateGameStoreCheckoutIntentRequest): Promise<GameStoreCheckoutIntentDto>;
|
|
69
|
+
purchaseGameStoreOffer(auth: SdkKeyPairAuth, body: SdkPurchaseGameStoreOfferRuntimeRequest): Promise<GameStoreOfferPurchaseResultDto>;
|
|
51
70
|
getBalances(bearerToken: string, query?: Record<string, any>): Promise<any>;
|
|
52
71
|
getBalanceHistory(bearerToken: string, query?: Record<string, any>): Promise<PagingResponse<any>>;
|
|
53
72
|
getMyProfile(bearerToken: string): Promise<any>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { BalanceChangeEvent, StorePurchaseCompletedEvent } from './LooplaySDK.types';
|
|
2
|
+
export interface WsClientOptions {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
/** Resolves the current player's access token — re-checked on every (re)connect. */
|
|
5
|
+
getAccessToken: () => Promise<string | undefined>;
|
|
6
|
+
}
|
|
7
|
+
type Listener<T> = (payload: T) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Lazy-connecting Socket.IO client mirroring gbs-service's AppGateway.
|
|
10
|
+
* Both events it exposes (`balance_change`, `store_purchase_completed`) are
|
|
11
|
+
* pushed only to the authenticated player's own room — there is nothing to
|
|
12
|
+
* receive without an access token, so `subscribe*` is a no-op until one is
|
|
13
|
+
* available.
|
|
14
|
+
*
|
|
15
|
+
* The connection is opened on the first subscription and closed once the
|
|
16
|
+
* last listener unsubscribes — a game that never calls `onBalanceChange`/
|
|
17
|
+
* `onStorePurchase` never opens a socket at all.
|
|
18
|
+
*/
|
|
19
|
+
export declare class WsClient {
|
|
20
|
+
private readonly options;
|
|
21
|
+
private socket?;
|
|
22
|
+
private connectPromise?;
|
|
23
|
+
private readonly balanceListeners;
|
|
24
|
+
private readonly purchaseListeners;
|
|
25
|
+
constructor(options: WsClientOptions);
|
|
26
|
+
/** Fires on every balance change — purchases, quest rewards, referral payouts, etc. */
|
|
27
|
+
onBalanceChange(listener: Listener<BalanceChangeEvent>): () => void;
|
|
28
|
+
/** Fires once a store purchase finishes — see `StorePurchaseCompletedEvent`. */
|
|
29
|
+
onStorePurchase(listener: Listener<StorePurchaseCompletedEvent>): () => void;
|
|
30
|
+
/** Closes the socket immediately, regardless of active listeners. */
|
|
31
|
+
disconnect(): void;
|
|
32
|
+
private ensureConnected;
|
|
33
|
+
private disconnectIfIdle;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Optional real-time subpath — `import { WsClient } from '@looplay/sdk/realtime'`.
|
|
3
|
+
* Kept out of the main `@looplay/sdk` entry point (and its browser IIFE
|
|
4
|
+
* bundle) because it pulls in `socket.io-client`, which most integrations
|
|
5
|
+
* — tracking-only or store-browsing-only — don't need.
|
|
6
|
+
*/
|
|
7
|
+
export { WsClient } from './apps/ws-client';
|
|
8
|
+
export type { WsClientOptions } from './apps/ws-client';
|
|
9
|
+
export type { BalanceChangeEvent, StorePurchaseCompletedEvent } from './apps/LooplaySDK.types';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@looplay/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "LooplaySDK (auth + points) for game integrations",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -17,6 +17,14 @@
|
|
|
17
17
|
},
|
|
18
18
|
"./browser": {
|
|
19
19
|
"default": "./dist/looplay-sdk.min.js"
|
|
20
|
+
},
|
|
21
|
+
"./realtime": {
|
|
22
|
+
"types": "./dist/types/realtime.d.ts",
|
|
23
|
+
"import": "./dist/looplay-sdk-realtime.esm.js",
|
|
24
|
+
"require": "./dist/looplay-sdk-realtime.cjs.js"
|
|
25
|
+
},
|
|
26
|
+
"./realtime/browser": {
|
|
27
|
+
"default": "./dist/looplay-sdk-realtime.min.js"
|
|
20
28
|
}
|
|
21
29
|
},
|
|
22
30
|
"files": [
|
|
@@ -30,6 +38,14 @@
|
|
|
30
38
|
"dependencies": {
|
|
31
39
|
"@looplay/types": "^0.1.0"
|
|
32
40
|
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"socket.io-client": "^4.8.3"
|
|
43
|
+
},
|
|
44
|
+
"peerDependenciesMeta": {
|
|
45
|
+
"socket.io-client": {
|
|
46
|
+
"optional": true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
33
49
|
"scripts": {
|
|
34
50
|
"build": "npm run build:js && npm run build:types",
|
|
35
51
|
"build:js": "tsup",
|