@spawnco/sdk-types 0.0.22 → 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 +42 -9
- package/dist/index.d.ts +42 -9
- package/package.json +1 -1
- package/src/v1.ts +49 -15
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;
|
@@ -189,4 +222,4 @@ interface LeaderboardEntry {
|
|
189
222
|
type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy' | 'inventory'>;
|
190
223
|
type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | 'inventory' | '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;
|
@@ -189,4 +222,4 @@ interface LeaderboardEntry {
|
|
189
222
|
type SpawnClientSDK__V0<TConfig = any> = Omit<SpawnClientSDK__V1<TConfig>, 'economy' | 'inventory'>;
|
190
223
|
type SpawnServerSDK__V0<TConfig = any> = Omit<SpawnServerSDK__V1<TConfig>, 'economy' | 'inventory' | '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,50 @@ export interface SpawnServerSDK__V1<TConfig = any> {
|
|
116
116
|
};
|
117
117
|
|
118
118
|
inventory: {
|
119
|
-
// Game currencies only (not SBX)
|
120
119
|
currencies: {
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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>>;
|
130
143
|
};
|
131
144
|
|
132
145
|
items: {
|
133
|
-
|
134
|
-
|
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[]>;
|
135
163
|
};
|
136
164
|
};
|
137
165
|
|
@@ -211,6 +239,12 @@ export interface Item {
|
|
211
239
|
data?: Record<string, any>;
|
212
240
|
}
|
213
241
|
|
242
|
+
export interface InventoryItem {
|
243
|
+
id: string; // Instance ID
|
244
|
+
itemId: string; // Item type
|
245
|
+
data?: any; // Item-specific data
|
246
|
+
}
|
247
|
+
|
214
248
|
export interface LeaderboardEntry {
|
215
249
|
rank: number;
|
216
250
|
username: string;
|