@spawnco/sdk-types 0.0.21 → 0.0.23

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
@@ -41,11 +41,11 @@ interface SpawnClientSDK__V1<TConfig = any> {
41
41
  inventory: {
42
42
  currencies: {
43
43
  get(): Promise<Record<string, number>>;
44
- on(event: 'update', handler: (balances: Record<string, number>) => void): void;
44
+ on(event: 'update', handler: (balances: Record<string, number>) => void): () => void;
45
45
  };
46
46
  items: {
47
- list(): Promise<Item[]>;
48
- on(event: 'update', handler: (items: Item[]) => void): void;
47
+ list(): Promise<InventoryItem[]>;
48
+ on(event: 'update', handler: (items: InventoryItem[]) => void): () => void;
49
49
  };
50
50
  };
51
51
  storage: {
@@ -58,6 +58,23 @@ interface SpawnClientSDK__V1<TConfig = any> {
58
58
  analytics: {
59
59
  track(event: string, data: Record<string, any>): Promise<void>;
60
60
  };
61
+ leaderboard: {
62
+ submit(leaderboardId: string, score: number): Promise<{
63
+ rank: number;
64
+ improved: boolean;
65
+ }>;
66
+ top(leaderboardId: string, options?: {
67
+ period?: 'today' | 'week' | 'month' | 'all';
68
+ limit?: number;
69
+ }): Promise<LeaderboardEntry[]>;
70
+ around(leaderboardId: string, options?: {
71
+ period?: 'today' | 'week' | 'month' | 'all';
72
+ range?: number;
73
+ }): Promise<{
74
+ entries: LeaderboardEntry[];
75
+ myRank: number;
76
+ }>;
77
+ };
61
78
  }
62
79
  interface SpawnServerSDK__V1<TConfig = any> {
63
80
  user: {
@@ -87,16 +104,44 @@ interface SpawnServerSDK__V1<TConfig = any> {
87
104
  };
88
105
  inventory: {
89
106
  currencies: {
90
- credit(userId: string, currency: string, amount: number): Promise<void>;
91
- debit(userId: string, currency: string, amount: number): Promise<boolean>;
107
+ credit(userId: string, currency: string, amount: number, options?: {
108
+ idempotencyKey?: string;
109
+ reason?: string;
110
+ }): Promise<{
111
+ newBalance: number;
112
+ }>;
113
+ debit(userId: string, currency: string, amount: number, options?: {
114
+ idempotencyKey?: string;
115
+ reason?: string;
116
+ }): Promise<{
117
+ success: boolean;
118
+ newBalance?: number;
119
+ }>;
92
120
  exchange(userId: string, tx: {
93
121
  debit: Record<string, number>;
94
122
  credit: Record<string, number>;
95
- }): Promise<boolean>;
123
+ }, options?: {
124
+ idempotencyKey?: string;
125
+ reason?: string;
126
+ }): Promise<{
127
+ success: boolean;
128
+ balances?: Record<string, number>;
129
+ }>;
130
+ get(userId: string): Promise<Record<string, number>>;
96
131
  };
97
132
  items: {
98
- grant(userId: string, items: Item[]): Promise<void>;
99
- consume(userId: string, itemId: string): Promise<boolean>;
133
+ grant(userId: string, items: Array<{
134
+ itemId: string;
135
+ data?: any;
136
+ }>, options?: {
137
+ idempotencyKey?: string;
138
+ reason?: string;
139
+ }): Promise<string[]>;
140
+ consume(userId: string, instanceId: string, options?: {
141
+ idempotencyKey?: string;
142
+ reason?: string;
143
+ }): Promise<boolean>;
144
+ list(userId: string): Promise<InventoryItem[]>;
100
145
  };
101
146
  };
102
147
  storage: {
@@ -116,6 +161,13 @@ interface SpawnServerSDK__V1<TConfig = any> {
116
161
  delete(key: string): Promise<void>;
117
162
  };
118
163
  };
164
+ leaderboard: {
165
+ submit(userId: string, leaderboardId: string, score: number): Promise<void>;
166
+ getMultiple(leaderboardIds: string[], options?: {
167
+ period?: 'today' | 'week' | 'month' | 'all';
168
+ limit?: number;
169
+ }): Promise<Record<string, LeaderboardEntry[]>>;
170
+ };
119
171
  }
120
172
  interface TokenPayload {
121
173
  sub: string;
@@ -154,7 +206,20 @@ interface Item {
154
206
  id: string;
155
207
  data?: Record<string, any>;
156
208
  }
209
+ interface InventoryItem {
210
+ id: string;
211
+ itemId: string;
212
+ data?: any;
213
+ }
214
+ interface LeaderboardEntry {
215
+ rank: number;
216
+ username: string;
217
+ avatarUrl?: string;
218
+ score: number;
219
+ isMe?: boolean;
220
+ timestamp: number;
221
+ }
157
222
  type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy' | 'inventory'>;
158
223
  type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | 'inventory' | 'room'>;
159
224
 
160
- export type { Item, Room, RoomInfo, RoomVisibility, SpawnClientSDK__V0, SpawnClientSDK__V1, SpawnServerSDK__V0, SpawnServerSDK__V1, TokenPayload, User };
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
@@ -41,11 +41,11 @@ interface SpawnClientSDK__V1<TConfig = any> {
41
41
  inventory: {
42
42
  currencies: {
43
43
  get(): Promise<Record<string, number>>;
44
- on(event: 'update', handler: (balances: Record<string, number>) => void): void;
44
+ on(event: 'update', handler: (balances: Record<string, number>) => void): () => void;
45
45
  };
46
46
  items: {
47
- list(): Promise<Item[]>;
48
- on(event: 'update', handler: (items: Item[]) => void): void;
47
+ list(): Promise<InventoryItem[]>;
48
+ on(event: 'update', handler: (items: InventoryItem[]) => void): () => void;
49
49
  };
50
50
  };
51
51
  storage: {
@@ -58,6 +58,23 @@ interface SpawnClientSDK__V1<TConfig = any> {
58
58
  analytics: {
59
59
  track(event: string, data: Record<string, any>): Promise<void>;
60
60
  };
61
+ leaderboard: {
62
+ submit(leaderboardId: string, score: number): Promise<{
63
+ rank: number;
64
+ improved: boolean;
65
+ }>;
66
+ top(leaderboardId: string, options?: {
67
+ period?: 'today' | 'week' | 'month' | 'all';
68
+ limit?: number;
69
+ }): Promise<LeaderboardEntry[]>;
70
+ around(leaderboardId: string, options?: {
71
+ period?: 'today' | 'week' | 'month' | 'all';
72
+ range?: number;
73
+ }): Promise<{
74
+ entries: LeaderboardEntry[];
75
+ myRank: number;
76
+ }>;
77
+ };
61
78
  }
62
79
  interface SpawnServerSDK__V1<TConfig = any> {
63
80
  user: {
@@ -87,16 +104,44 @@ interface SpawnServerSDK__V1<TConfig = any> {
87
104
  };
88
105
  inventory: {
89
106
  currencies: {
90
- credit(userId: string, currency: string, amount: number): Promise<void>;
91
- debit(userId: string, currency: string, amount: number): Promise<boolean>;
107
+ credit(userId: string, currency: string, amount: number, options?: {
108
+ idempotencyKey?: string;
109
+ reason?: string;
110
+ }): Promise<{
111
+ newBalance: number;
112
+ }>;
113
+ debit(userId: string, currency: string, amount: number, options?: {
114
+ idempotencyKey?: string;
115
+ reason?: string;
116
+ }): Promise<{
117
+ success: boolean;
118
+ newBalance?: number;
119
+ }>;
92
120
  exchange(userId: string, tx: {
93
121
  debit: Record<string, number>;
94
122
  credit: Record<string, number>;
95
- }): Promise<boolean>;
123
+ }, options?: {
124
+ idempotencyKey?: string;
125
+ reason?: string;
126
+ }): Promise<{
127
+ success: boolean;
128
+ balances?: Record<string, number>;
129
+ }>;
130
+ get(userId: string): Promise<Record<string, number>>;
96
131
  };
97
132
  items: {
98
- grant(userId: string, items: Item[]): Promise<void>;
99
- consume(userId: string, itemId: string): Promise<boolean>;
133
+ grant(userId: string, items: Array<{
134
+ itemId: string;
135
+ data?: any;
136
+ }>, options?: {
137
+ idempotencyKey?: string;
138
+ reason?: string;
139
+ }): Promise<string[]>;
140
+ consume(userId: string, instanceId: string, options?: {
141
+ idempotencyKey?: string;
142
+ reason?: string;
143
+ }): Promise<boolean>;
144
+ list(userId: string): Promise<InventoryItem[]>;
100
145
  };
101
146
  };
102
147
  storage: {
@@ -116,6 +161,13 @@ interface SpawnServerSDK__V1<TConfig = any> {
116
161
  delete(key: string): Promise<void>;
117
162
  };
118
163
  };
164
+ leaderboard: {
165
+ submit(userId: string, leaderboardId: string, score: number): Promise<void>;
166
+ getMultiple(leaderboardIds: string[], options?: {
167
+ period?: 'today' | 'week' | 'month' | 'all';
168
+ limit?: number;
169
+ }): Promise<Record<string, LeaderboardEntry[]>>;
170
+ };
119
171
  }
120
172
  interface TokenPayload {
121
173
  sub: string;
@@ -154,7 +206,20 @@ interface Item {
154
206
  id: string;
155
207
  data?: Record<string, any>;
156
208
  }
209
+ interface InventoryItem {
210
+ id: string;
211
+ itemId: string;
212
+ data?: any;
213
+ }
214
+ interface LeaderboardEntry {
215
+ rank: number;
216
+ username: string;
217
+ avatarUrl?: string;
218
+ score: number;
219
+ isMe?: boolean;
220
+ timestamp: number;
221
+ }
157
222
  type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy' | 'inventory'>;
158
223
  type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | 'inventory' | 'room'>;
159
224
 
160
- export type { Item, Room, RoomInfo, RoomVisibility, SpawnClientSDK__V0, SpawnClientSDK__V1, SpawnServerSDK__V0, SpawnServerSDK__V1, TokenPayload, User };
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.21",
3
+ "version": "0.0.23",
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
@@ -40,12 +40,12 @@ export interface SpawnClientSDK__V1<TConfig = any> {
40
40
  inventory: {
41
41
  currencies: {
42
42
  get(): Promise<Record<string, number>>;
43
- on(event: 'update', handler: (balances: Record<string, number>) => void): void;
43
+ on(event: 'update', handler: (balances: Record<string, number>) => void): () => void;
44
44
  };
45
45
 
46
46
  items: {
47
- list(): Promise<Item[]>;
48
- on(event: 'update', handler: (items: Item[]) => void): void;
47
+ list(): Promise<InventoryItem[]>;
48
+ on(event: 'update', handler: (items: InventoryItem[]) => void): () => void;
49
49
  };
50
50
  };
51
51
 
@@ -60,6 +60,35 @@ export interface SpawnClientSDK__V1<TConfig = any> {
60
60
  analytics: {
61
61
  track(event: string, data: Record<string, any>): Promise<void>;
62
62
  };
63
+
64
+ leaderboard: {
65
+ submit(
66
+ leaderboardId: string,
67
+ score: number
68
+ ): Promise<{
69
+ rank: number;
70
+ improved: boolean;
71
+ }>;
72
+
73
+ top(
74
+ leaderboardId: string,
75
+ options?: {
76
+ period?: 'today' | 'week' | 'month' | 'all';
77
+ limit?: number;
78
+ }
79
+ ): Promise<LeaderboardEntry[]>;
80
+
81
+ around(
82
+ leaderboardId: string,
83
+ options?: {
84
+ period?: 'today' | 'week' | 'month' | 'all';
85
+ range?: number;
86
+ }
87
+ ): Promise<{
88
+ entries: LeaderboardEntry[];
89
+ myRank: number;
90
+ }>;
91
+ };
63
92
  }
64
93
 
65
94
  // Server SDK - available in Durable Objects
@@ -87,22 +116,50 @@ export interface SpawnServerSDK__V1<TConfig = any> {
87
116
  };
88
117
 
89
118
  inventory: {
90
- // Game currencies only (not SBX)
91
119
  currencies: {
92
- credit(userId: string, currency: string, amount: number): Promise<void>;
93
- debit(userId: string, currency: string, amount: number): Promise<boolean>;
94
- exchange(
95
- userId: string,
96
- tx: {
97
- debit: Record<string, number>;
98
- credit: Record<string, number>;
99
- }
100
- ): Promise<boolean>;
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
+
126
+ // 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
+ // 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
+
141
+ // Get user's balances
142
+ get(userId: string): Promise<Record<string, number>>;
101
143
  };
102
144
 
103
145
  items: {
104
- grant(userId: string, items: Item[]): Promise<void>;
105
- consume(userId: string, itemId: string): Promise<boolean>;
146
+ // 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
+
155
+ // Consume an item by instance ID
156
+ consume(userId: string, instanceId: string, options?: {
157
+ idempotencyKey?: string;
158
+ reason?: string;
159
+ }): Promise<boolean>;
160
+
161
+ // Get user's inventory
162
+ list(userId: string): Promise<InventoryItem[]>;
106
163
  };
107
164
  };
108
165
 
@@ -123,6 +180,18 @@ export interface SpawnServerSDK__V1<TConfig = any> {
123
180
  delete(key: string): Promise<void>;
124
181
  };
125
182
  };
183
+
184
+ leaderboard: {
185
+ submit(userId: string, leaderboardId: string, score: number): Promise<void>;
186
+
187
+ getMultiple(
188
+ leaderboardIds: string[],
189
+ options?: {
190
+ period?: 'today' | 'week' | 'month' | 'all';
191
+ limit?: number;
192
+ }
193
+ ): Promise<Record<string, LeaderboardEntry[]>>;
194
+ };
126
195
  }
127
196
 
128
197
  // Token types
@@ -170,6 +239,21 @@ export interface Item {
170
239
  data?: Record<string, any>;
171
240
  }
172
241
 
242
+ export interface InventoryItem {
243
+ id: string; // Instance ID
244
+ itemId: string; // Item type
245
+ data?: any; // Item-specific data
246
+ }
247
+
248
+ export interface LeaderboardEntry {
249
+ rank: number;
250
+ username: string;
251
+ avatarUrl?: string;
252
+ score: number;
253
+ isMe?: boolean;
254
+ timestamp: number;
255
+ }
256
+
173
257
  // v0 sdk types for testing
174
258
 
175
259
  export type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy' | 'inventory'>;