@spawnco/sdk-types 0.0.23 → 0.0.25

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/dist/index.d.mts CHANGED
@@ -12,11 +12,11 @@ interface SpawnClientSDK__V1<TConfig = any> {
12
12
  upgradeGuest(): Promise<void>;
13
13
  };
14
14
  room: {
15
- connect(options: {
15
+ connect<T extends Record<string, any>>(options: {
16
16
  roomId: string;
17
17
  query?: Record<string, string>;
18
18
  headers?: Record<string, string>;
19
- }): Promise<Room>;
19
+ }): Promise<Room<T>>;
20
20
  };
21
21
  config: {
22
22
  get(): Promise<TConfig>;
@@ -185,10 +185,10 @@ interface User {
185
185
  avatarUrl?: string;
186
186
  isGuest: boolean;
187
187
  }
188
- interface Room {
188
+ interface Room<T extends Record<string, any>> {
189
189
  id: string;
190
- send(type: string, data: any): void;
191
- on(event: string, handler: (data: any) => void): void;
190
+ send<K extends keyof T>(type: K, data: T[K]): void;
191
+ on<K extends keyof T>(event: K, handler: (data: T[K]) => void): void;
192
192
  on(event: 'disconnect', handler: () => void): void;
193
193
  leave(): void;
194
194
  }
@@ -219,7 +219,7 @@ interface LeaderboardEntry {
219
219
  isMe?: boolean;
220
220
  timestamp: number;
221
221
  }
222
- type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy' | 'inventory'>;
223
- type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | 'inventory' | 'room'>;
222
+ type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy'>;
223
+ type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | 'room'>;
224
224
 
225
225
  export type { InventoryItem, Item, LeaderboardEntry, Room, RoomInfo, RoomVisibility, SpawnClientSDK__V0, SpawnClientSDK__V1, SpawnServerSDK__V0, SpawnServerSDK__V1, TokenPayload, User };
package/dist/index.d.ts CHANGED
@@ -12,11 +12,11 @@ interface SpawnClientSDK__V1<TConfig = any> {
12
12
  upgradeGuest(): Promise<void>;
13
13
  };
14
14
  room: {
15
- connect(options: {
15
+ connect<T extends Record<string, any>>(options: {
16
16
  roomId: string;
17
17
  query?: Record<string, string>;
18
18
  headers?: Record<string, string>;
19
- }): Promise<Room>;
19
+ }): Promise<Room<T>>;
20
20
  };
21
21
  config: {
22
22
  get(): Promise<TConfig>;
@@ -185,10 +185,10 @@ interface User {
185
185
  avatarUrl?: string;
186
186
  isGuest: boolean;
187
187
  }
188
- interface Room {
188
+ interface Room<T extends Record<string, any>> {
189
189
  id: string;
190
- send(type: string, data: any): void;
191
- on(event: string, handler: (data: any) => void): void;
190
+ send<K extends keyof T>(type: K, data: T[K]): void;
191
+ on<K extends keyof T>(event: K, handler: (data: T[K]) => void): void;
192
192
  on(event: 'disconnect', handler: () => void): void;
193
193
  leave(): void;
194
194
  }
@@ -219,7 +219,7 @@ interface LeaderboardEntry {
219
219
  isMe?: boolean;
220
220
  timestamp: number;
221
221
  }
222
- type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy' | 'inventory'>;
223
- type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | 'inventory' | 'room'>;
222
+ type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy'>;
223
+ type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | 'room'>;
224
224
 
225
225
  export type { InventoryItem, Item, LeaderboardEntry, Room, RoomInfo, RoomVisibility, SpawnClientSDK__V0, SpawnClientSDK__V1, SpawnServerSDK__V0, SpawnServerSDK__V1, TokenPayload, User };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spawnco/sdk-types",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "TypeScript type definitions for Spawn SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
package/src/v1.ts CHANGED
@@ -17,7 +17,7 @@ export interface SpawnClientSDK__V1<TConfig = any> {
17
17
 
18
18
  room: {
19
19
  // only one room per game for v1
20
- connect(options: { roomId: string; query?: Record<string, string>; headers?: Record<string, string> }): Promise<Room>;
20
+ connect<T extends Record<string, any>>(options: { roomId: string; query?: Record<string, string>; headers?: Record<string, string> }): Promise<Room<T>>;
21
21
  };
22
22
 
23
23
  config: {
@@ -118,46 +118,68 @@ export interface SpawnServerSDK__V1<TConfig = any> {
118
118
  inventory: {
119
119
  currencies: {
120
120
  // Credit currency (creates if doesn't exist)
121
- credit(userId: string, currency: string, amount: number, options?: {
122
- idempotencyKey?: string;
123
- reason?: string;
124
- }): Promise<{ newBalance: number }>;
125
-
121
+ credit(
122
+ userId: string,
123
+ currency: string,
124
+ amount: number,
125
+ options?: {
126
+ idempotencyKey?: string;
127
+ reason?: string;
128
+ }
129
+ ): Promise<{ newBalance: number }>;
130
+
126
131
  // Debit currency (returns false if insufficient)
127
- debit(userId: string, currency: string, amount: number, options?: {
128
- idempotencyKey?: string;
129
- reason?: string;
130
- }): Promise<{ success: boolean; newBalance?: number }>;
131
-
132
+ debit(
133
+ userId: string,
134
+ currency: string,
135
+ amount: number,
136
+ options?: {
137
+ idempotencyKey?: string;
138
+ reason?: string;
139
+ }
140
+ ): Promise<{ success: boolean; newBalance?: number }>;
141
+
132
142
  // Atomic multi-currency exchange
133
- exchange(userId: string, tx: {
134
- debit: Record<string, number>;
135
- credit: Record<string, number>;
136
- }, options?: {
137
- idempotencyKey?: string;
138
- reason?: string;
139
- }): Promise<{ success: boolean; balances?: Record<string, number> }>;
140
-
143
+ exchange(
144
+ userId: string,
145
+ tx: {
146
+ debit: Record<string, number>;
147
+ credit: Record<string, number>;
148
+ },
149
+ options?: {
150
+ idempotencyKey?: string;
151
+ reason?: string;
152
+ }
153
+ ): Promise<{ success: boolean; balances?: Record<string, number> }>;
154
+
141
155
  // Get user's balances
142
156
  get(userId: string): Promise<Record<string, number>>;
143
157
  };
144
158
 
145
159
  items: {
146
160
  // Grant items to user (returns instance IDs)
147
- grant(userId: string, items: Array<{
148
- itemId: string;
149
- data?: any;
150
- }>, options?: {
151
- idempotencyKey?: string;
152
- reason?: string;
153
- }): Promise<string[]>;
154
-
161
+ grant(
162
+ userId: string,
163
+ items: Array<{
164
+ itemId: string;
165
+ data?: any;
166
+ }>,
167
+ options?: {
168
+ idempotencyKey?: string;
169
+ reason?: string;
170
+ }
171
+ ): Promise<string[]>;
172
+
155
173
  // Consume an item by instance ID
156
- consume(userId: string, instanceId: string, options?: {
157
- idempotencyKey?: string;
158
- reason?: string;
159
- }): Promise<boolean>;
160
-
174
+ consume(
175
+ userId: string,
176
+ instanceId: string,
177
+ options?: {
178
+ idempotencyKey?: string;
179
+ reason?: string;
180
+ }
181
+ ): Promise<boolean>;
182
+
161
183
  // Get user's inventory
162
184
  list(userId: string): Promise<InventoryItem[]>;
163
185
  };
@@ -215,10 +237,10 @@ export interface User {
215
237
  isGuest: boolean;
216
238
  }
217
239
 
218
- export interface Room {
240
+ export interface Room<T extends Record<string, any>> {
219
241
  id: string;
220
- send(type: string, data: any): void;
221
- on(event: string, handler: (data: any) => void): void;
242
+ send<K extends keyof T>(type: K, data: T[K]): void;
243
+ on<K extends keyof T>(event: K, handler: (data: T[K]) => void): void;
222
244
  on(event: 'disconnect', handler: () => void): void;
223
245
  leave(): void;
224
246
  }
@@ -256,5 +278,5 @@ export interface LeaderboardEntry {
256
278
 
257
279
  // v0 sdk types for testing
258
280
 
259
- export type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy' | 'inventory'>;
260
- export type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | 'inventory' | 'room'>;
281
+ export type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy'>;
282
+ export type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | 'room'>;