@spawnco/sdk-types 0.0.22 → 0.0.24
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 +44 -11
- package/dist/index.d.ts +44 -11
- package/package.json +1 -1
- package/src/v1.ts +67 -11
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<
|
48
|
-
on(event: 'update', handler: (items:
|
47
|
+
list(): Promise<InventoryItem[]>;
|
48
|
+
on(event: 'update', handler: (items: InventoryItem[]) => void): () => void;
|
49
49
|
};
|
50
50
|
};
|
51
51
|
storage: {
|
@@ -104,16 +104,44 @@ interface SpawnServerSDK__V1<TConfig = any> {
|
|
104
104
|
};
|
105
105
|
inventory: {
|
106
106
|
currencies: {
|
107
|
-
credit(userId: string, currency: string, amount: number
|
108
|
-
|
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
|
+
}>;
|
109
120
|
exchange(userId: string, tx: {
|
110
121
|
debit: Record<string, number>;
|
111
122
|
credit: Record<string, number>;
|
112
|
-
}
|
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>>;
|
113
131
|
};
|
114
132
|
items: {
|
115
|
-
grant(userId: string, items:
|
116
|
-
|
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[]>;
|
117
145
|
};
|
118
146
|
};
|
119
147
|
storage: {
|
@@ -178,6 +206,11 @@ interface Item {
|
|
178
206
|
id: string;
|
179
207
|
data?: Record<string, any>;
|
180
208
|
}
|
209
|
+
interface InventoryItem {
|
210
|
+
id: string;
|
211
|
+
itemId: string;
|
212
|
+
data?: any;
|
213
|
+
}
|
181
214
|
interface LeaderboardEntry {
|
182
215
|
rank: number;
|
183
216
|
username: string;
|
@@ -186,7 +219,7 @@ interface LeaderboardEntry {
|
|
186
219
|
isMe?: boolean;
|
187
220
|
timestamp: number;
|
188
221
|
}
|
189
|
-
type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy'
|
190
|
-
type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | '
|
222
|
+
type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy'>;
|
223
|
+
type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | 'room'>;
|
191
224
|
|
192
|
-
export type { Item, LeaderboardEntry, 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<
|
48
|
-
on(event: 'update', handler: (items:
|
47
|
+
list(): Promise<InventoryItem[]>;
|
48
|
+
on(event: 'update', handler: (items: InventoryItem[]) => void): () => void;
|
49
49
|
};
|
50
50
|
};
|
51
51
|
storage: {
|
@@ -104,16 +104,44 @@ interface SpawnServerSDK__V1<TConfig = any> {
|
|
104
104
|
};
|
105
105
|
inventory: {
|
106
106
|
currencies: {
|
107
|
-
credit(userId: string, currency: string, amount: number
|
108
|
-
|
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
|
+
}>;
|
109
120
|
exchange(userId: string, tx: {
|
110
121
|
debit: Record<string, number>;
|
111
122
|
credit: Record<string, number>;
|
112
|
-
}
|
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>>;
|
113
131
|
};
|
114
132
|
items: {
|
115
|
-
grant(userId: string, items:
|
116
|
-
|
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[]>;
|
117
145
|
};
|
118
146
|
};
|
119
147
|
storage: {
|
@@ -178,6 +206,11 @@ interface Item {
|
|
178
206
|
id: string;
|
179
207
|
data?: Record<string, any>;
|
180
208
|
}
|
209
|
+
interface InventoryItem {
|
210
|
+
id: string;
|
211
|
+
itemId: string;
|
212
|
+
data?: any;
|
213
|
+
}
|
181
214
|
interface LeaderboardEntry {
|
182
215
|
rank: number;
|
183
216
|
username: string;
|
@@ -186,7 +219,7 @@ interface LeaderboardEntry {
|
|
186
219
|
isMe?: boolean;
|
187
220
|
timestamp: number;
|
188
221
|
}
|
189
|
-
type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy'
|
190
|
-
type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | '
|
222
|
+
type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy'>;
|
223
|
+
type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | 'room'>;
|
191
224
|
|
192
|
-
export type { Item, LeaderboardEntry, 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
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<
|
48
|
-
on(event: 'update', handler: (items:
|
47
|
+
list(): Promise<InventoryItem[]>;
|
48
|
+
on(event: 'update', handler: (items: InventoryItem[]) => void): () => void;
|
49
49
|
};
|
50
50
|
};
|
51
51
|
|
@@ -116,22 +116,72 @@ export interface SpawnServerSDK__V1<TConfig = any> {
|
|
116
116
|
};
|
117
117
|
|
118
118
|
inventory: {
|
119
|
-
// Game currencies only (not SBX)
|
120
119
|
currencies: {
|
121
|
-
|
122
|
-
|
120
|
+
// Credit currency (creates if doesn't exist)
|
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
|
+
|
131
|
+
// Debit currency (returns false if insufficient)
|
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
|
+
|
142
|
+
// Atomic multi-currency exchange
|
123
143
|
exchange(
|
124
144
|
userId: string,
|
125
145
|
tx: {
|
126
146
|
debit: Record<string, number>;
|
127
147
|
credit: Record<string, number>;
|
148
|
+
},
|
149
|
+
options?: {
|
150
|
+
idempotencyKey?: string;
|
151
|
+
reason?: string;
|
128
152
|
}
|
129
|
-
): Promise<boolean>;
|
153
|
+
): Promise<{ success: boolean; balances?: Record<string, number> }>;
|
154
|
+
|
155
|
+
// Get user's balances
|
156
|
+
get(userId: string): Promise<Record<string, number>>;
|
130
157
|
};
|
131
158
|
|
132
159
|
items: {
|
133
|
-
|
134
|
-
|
160
|
+
// Grant items to user (returns instance IDs)
|
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
|
+
|
173
|
+
// Consume an item by instance ID
|
174
|
+
consume(
|
175
|
+
userId: string,
|
176
|
+
instanceId: string,
|
177
|
+
options?: {
|
178
|
+
idempotencyKey?: string;
|
179
|
+
reason?: string;
|
180
|
+
}
|
181
|
+
): Promise<boolean>;
|
182
|
+
|
183
|
+
// Get user's inventory
|
184
|
+
list(userId: string): Promise<InventoryItem[]>;
|
135
185
|
};
|
136
186
|
};
|
137
187
|
|
@@ -211,6 +261,12 @@ export interface Item {
|
|
211
261
|
data?: Record<string, any>;
|
212
262
|
}
|
213
263
|
|
264
|
+
export interface InventoryItem {
|
265
|
+
id: string; // Instance ID
|
266
|
+
itemId: string; // Item type
|
267
|
+
data?: any; // Item-specific data
|
268
|
+
}
|
269
|
+
|
214
270
|
export interface LeaderboardEntry {
|
215
271
|
rank: number;
|
216
272
|
username: string;
|
@@ -222,5 +278,5 @@ export interface LeaderboardEntry {
|
|
222
278
|
|
223
279
|
// v0 sdk types for testing
|
224
280
|
|
225
|
-
export type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy'
|
226
|
-
export type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | '
|
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'>;
|