@spawnco/sdk-types 0.0.7 → 0.0.9

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
@@ -49,9 +49,17 @@ interface SpawnClientSDK__V1 {
49
49
  };
50
50
  }
51
51
  interface SpawnServerSDK__V1 {
52
- room: {
53
- broadcast(type: string, data: any, exclude?: string[]): void;
54
- kick(userId: string): void;
52
+ user: {
53
+ token: {
54
+ verify(token: string): Promise<{
55
+ valid: false;
56
+ } | {
57
+ valid: true;
58
+ user: User;
59
+ expires: Date;
60
+ payload: TokenPayload;
61
+ }>;
62
+ };
55
63
  };
56
64
  economy: {
57
65
  redeemPurchase(token: string): Promise<{
@@ -82,6 +90,15 @@ interface SpawnServerSDK__V1 {
82
90
  };
83
91
  };
84
92
  }
93
+ interface TokenPayload {
94
+ sub: string;
95
+ variantId: string;
96
+ email?: string;
97
+ username?: string;
98
+ isGuest: boolean;
99
+ iat: number;
100
+ exp: number;
101
+ }
85
102
  type RoomVisibility = "public" | "private" | "friends";
86
103
  interface User {
87
104
  id: string;
@@ -110,7 +127,7 @@ interface Item {
110
127
  id: string;
111
128
  data?: Record<string, any>;
112
129
  }
113
- type SpawnClientSDK__V0 = Pick<SpawnClientSDK__V1, "user" | "ready" | "room">;
114
- type SpawnServerSDK__V0 = Pick<SpawnServerSDK__V1, "room">;
130
+ type SpawnClientSDK__V0 = Omit<SpawnClientSDK__V1, "economy" | "inventory" | "storage">;
131
+ type SpawnServerSDK__V0 = Omit<SpawnServerSDK__V1, "economy" | "inventory" | "storage" | "room">;
115
132
 
116
- export type { Item, Room, RoomInfo, RoomVisibility, SpawnClientSDK__V0, SpawnClientSDK__V1, SpawnServerSDK__V0, SpawnServerSDK__V1, User };
133
+ export type { Item, Room, RoomInfo, RoomVisibility, SpawnClientSDK__V0, SpawnClientSDK__V1, SpawnServerSDK__V0, SpawnServerSDK__V1, TokenPayload, User };
package/dist/index.d.ts CHANGED
@@ -5,112 +5,156 @@
5
5
  * Future modules: friends, achievements, chat, ai, leaderboards, tournaments
6
6
  */
7
7
  interface SpawnClientSDK__V1 {
8
- ready(): Promise<void>;
9
- user: {
10
- me(): Promise<User>;
11
- upgradeGuest(): Promise<void>;
12
- };
13
- room: {
14
- connect(options?: {
15
- query?: Record<string, string>;
16
- headers?: Record<string, string>;
17
- }): Promise<Room>;
18
- };
19
- economy: {
20
- balance(): Promise<{
21
- amount: number;
22
- }>;
23
- purchase(options: {
24
- sku: string;
25
- price: number;
26
- description: string;
27
- data?: Record<string, any>;
28
- }): Promise<{
29
- success: boolean;
30
- token?: string;
31
- }>;
32
- on(event: "update", handler: (balance: number) => void): void;
8
+ ready(): Promise<void>;
9
+ user: {
10
+ me(): Promise<User>;
11
+ upgradeGuest(): Promise<void>;
12
+ };
13
+ room: {
14
+ connect(options?: {
15
+ roomId: string;
16
+ query?: Record<string, string>;
17
+ headers?: Record<string, string>;
18
+ }): Promise<Room>;
19
+ };
20
+ economy: {
21
+ balance(): Promise<{
22
+ amount: number;
23
+ }>;
24
+ purchase(options: {
25
+ sku: string;
26
+ price: number;
27
+ description: string;
28
+ data?: Record<string, any>;
29
+ }): Promise<{
30
+ success: boolean;
31
+ token?: string;
32
+ }>;
33
+ on(event: "update", handler: (balance: number) => void): void;
34
+ };
35
+ inventory: {
36
+ currencies: {
37
+ get(): Promise<Record<string, number>>;
38
+ on(
39
+ event: "update",
40
+ handler: (balances: Record<string, number>) => void
41
+ ): void;
33
42
  };
34
- inventory: {
35
- currencies: {
36
- get(): Promise<Record<string, number>>;
37
- on(event: "update", handler: (balances: Record<string, number>) => void): void;
38
- };
39
- items: {
40
- list(): Promise<Item[]>;
41
- on(event: "update", handler: (items: Item[]) => void): void;
42
- };
43
+ items: {
44
+ list(): Promise<Item[]>;
45
+ on(event: "update", handler: (items: Item[]) => void): void;
43
46
  };
44
- storage: {
45
- user: {
46
- get(key: string): Promise<any>;
47
- set(key: string, value: any): Promise<void>;
48
- };
47
+ };
48
+ storage: {
49
+ user: {
50
+ get(key: string): Promise<any>;
51
+ set(key: string, value: any): Promise<void>;
49
52
  };
53
+ };
50
54
  }
51
55
  interface SpawnServerSDK__V1 {
52
- room: {
53
- broadcast(type: string, data: any, exclude?: string[]): void;
54
- kick(userId: string): void;
56
+ user: {
57
+ token: {
58
+ verify(token: string): Promise<
59
+ | {
60
+ valid: false;
61
+ }
62
+ | {
63
+ valid: true;
64
+ user: User;
65
+ expires: Date;
66
+ payload: TokenPayload;
67
+ }
68
+ >;
55
69
  };
56
- economy: {
57
- redeemPurchase(token: string): Promise<{
58
- success: boolean;
59
- sku: string;
60
- data?: Record<string, any>;
61
- userId: string;
62
- }>;
70
+ };
71
+ economy: {
72
+ redeemPurchase(token: string): Promise<{
73
+ success: boolean;
74
+ sku: string;
75
+ data?: Record<string, any>;
76
+ userId: string;
77
+ }>;
78
+ };
79
+ inventory: {
80
+ currencies: {
81
+ credit(userId: string, currency: string, amount: number): Promise<void>;
82
+ debit(userId: string, currency: string, amount: number): Promise<boolean>;
83
+ exchange(
84
+ userId: string,
85
+ tx: {
86
+ debit: Record<string, number>;
87
+ credit: Record<string, number>;
88
+ }
89
+ ): Promise<boolean>;
63
90
  };
64
- inventory: {
65
- currencies: {
66
- credit(userId: string, currency: string, amount: number): Promise<void>;
67
- debit(userId: string, currency: string, amount: number): Promise<boolean>;
68
- exchange(userId: string, tx: {
69
- debit: Record<string, number>;
70
- credit: Record<string, number>;
71
- }): Promise<boolean>;
72
- };
73
- items: {
74
- grant(userId: string, items: Item[]): Promise<void>;
75
- consume(userId: string, itemId: string): Promise<boolean>;
76
- };
91
+ items: {
92
+ grant(userId: string, items: Item[]): Promise<void>;
93
+ consume(userId: string, itemId: string): Promise<boolean>;
77
94
  };
78
- storage: {
79
- room: {
80
- get(key: string): Promise<any>;
81
- set(key: string, value: any): Promise<void>;
82
- };
95
+ };
96
+ storage: {
97
+ room: {
98
+ get(key: string): Promise<any>;
99
+ set(key: string, value: any): Promise<void>;
83
100
  };
101
+ };
102
+ }
103
+ interface TokenPayload {
104
+ sub: string;
105
+ variantId: string;
106
+ email?: string;
107
+ username?: string;
108
+ isGuest: boolean;
109
+ iat: number;
110
+ exp: number;
84
111
  }
85
112
  type RoomVisibility = "public" | "private" | "friends";
86
113
  interface User {
87
- id: string;
88
- username: string;
89
- avatarUrl?: string;
90
- isGuest: boolean;
114
+ id: string;
115
+ username: string;
116
+ avatarUrl?: string;
117
+ isGuest: boolean;
91
118
  }
92
119
  interface Room {
93
- id: string;
94
- send(type: string, data: any): void;
95
- on(event: string, handler: (data: any) => void): void;
96
- on(event: "disconnect", handler: () => void): void;
97
- leave(): void;
120
+ id: string;
121
+ send(type: string, data: any): void;
122
+ on(event: string, handler: (data: any) => void): void;
123
+ on(event: "disconnect", handler: () => void): void;
124
+ leave(): void;
98
125
  }
99
126
  interface RoomInfo {
100
- roomId: string;
101
- gameMode?: string;
102
- visibility: RoomVisibility;
103
- playerCount: number;
104
- maxPlayers: number;
105
- isFull: boolean;
106
- lastActive: Date;
107
- activeFriends: User[];
127
+ roomId: string;
128
+ gameMode?: string;
129
+ visibility: RoomVisibility;
130
+ playerCount: number;
131
+ maxPlayers: number;
132
+ isFull: boolean;
133
+ lastActive: Date;
134
+ activeFriends: User[];
108
135
  }
109
136
  interface Item {
110
- id: string;
111
- data?: Record<string, any>;
137
+ id: string;
138
+ data?: Record<string, any>;
112
139
  }
113
- type SpawnClientSDK__V0 = Pick<SpawnClientSDK__V1, "user" | "ready" | "room">;
114
- type SpawnServerSDK__V0 = Pick<SpawnServerSDK__V1, "room">;
140
+ type SpawnClientSDK__V0 = Omit<
141
+ SpawnClientSDK__V1,
142
+ "economy" | "inventory" | "storage"
143
+ >;
144
+ type SpawnServerSDK__V0 = Omit<
145
+ SpawnServerSDK__V1,
146
+ "economy" | "inventory" | "storage" | "room"
147
+ >;
115
148
 
116
- export type { Item, Room, RoomInfo, RoomVisibility, SpawnClientSDK__V0, SpawnClientSDK__V1, SpawnServerSDK__V0, SpawnServerSDK__V1, User };
149
+ export type {
150
+ Item,
151
+ Room,
152
+ RoomInfo,
153
+ RoomVisibility,
154
+ SpawnClientSDK__V0,
155
+ SpawnClientSDK__V1,
156
+ SpawnServerSDK__V0,
157
+ SpawnServerSDK__V1,
158
+ TokenPayload,
159
+ User,
160
+ };
package/dist/index.js CHANGED
@@ -16,4 +16,3 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
16
16
  // src/index.ts
17
17
  var index_exports = {};
18
18
  module.exports = __toCommonJS(index_exports);
19
- //# sourceMappingURL=index.js.map
package/dist/index.mjs CHANGED
@@ -1 +0,0 @@
1
- //# sourceMappingURL=index.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spawnco/sdk-types",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "TypeScript type definitions for Spawn SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -17,8 +17,8 @@
17
17
  "src"
18
18
  ],
19
19
  "scripts": {
20
- "build": "tsup",
21
- "dev": "tsup --watch"
20
+ "build": "tsup src/index.ts --dts --format cjs,esm --clean",
21
+ "dev": "tsup src/index.ts --dts --format cjs,esm --watch"
22
22
  },
23
23
  "keywords": [
24
24
  "spawn",
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- export * from './v1';
1
+ export * from './v1';
package/src/v1.ts CHANGED
@@ -16,40 +16,29 @@ export interface SpawnClientSDK__V1 {
16
16
 
17
17
  room: {
18
18
  // only one room per game for v1
19
- connect(options?: {
20
- query?: Record<string, string>;
21
- headers?: Record<string, string>;
22
- }): Promise<Room>;
19
+ connect(options?: { roomId: string; query?: Record<string, string>; headers?: Record<string, string> }): Promise<Room>;
23
20
  };
24
21
 
25
22
  economy: {
26
23
  balance(): Promise<{ amount: number }>;
27
24
 
28
- purchase(options: {
29
- sku: string;
30
- price: number;
31
- description: string;
32
- data?: Record<string, any>;
33
- }): Promise<{
25
+ purchase(options: { sku: string; price: number; description: string; data?: Record<string, any> }): Promise<{
34
26
  success: boolean;
35
27
  token?: string; // Contains signed purchase details
36
28
  }>;
37
29
 
38
- on(event: "update", handler: (balance: number) => void): void;
30
+ on(event: 'update', handler: (balance: number) => void): void;
39
31
  };
40
32
 
41
33
  inventory: {
42
34
  currencies: {
43
35
  get(): Promise<Record<string, number>>;
44
- on(
45
- event: "update",
46
- handler: (balances: Record<string, number>) => void
47
- ): void;
36
+ on(event: 'update', handler: (balances: Record<string, number>) => void): void;
48
37
  };
49
38
 
50
39
  items: {
51
40
  list(): Promise<Item[]>;
52
- on(event: "update", handler: (items: Item[]) => void): void;
41
+ on(event: 'update', handler: (items: Item[]) => void): void;
53
42
  };
54
43
  };
55
44
 
@@ -63,9 +52,10 @@ export interface SpawnClientSDK__V1 {
63
52
 
64
53
  // Server SDK - available in Durable Objects
65
54
  export interface SpawnServerSDK__V1 {
66
- room: {
67
- broadcast(type: string, data: any, exclude?: string[]): void;
68
- kick(userId: string): void;
55
+ user: {
56
+ token: {
57
+ verify(token: string): Promise<{ valid: false } | { valid: true; user: User; expires: Date; payload: TokenPayload }>;
58
+ };
69
59
  };
70
60
 
71
61
  economy: {
@@ -106,8 +96,19 @@ export interface SpawnServerSDK__V1 {
106
96
  };
107
97
  }
108
98
 
99
+ // Token types
100
+ export interface TokenPayload {
101
+ sub: string; // user ID
102
+ variantId: string;
103
+ email?: string;
104
+ username?: string;
105
+ isGuest: boolean;
106
+ iat: number;
107
+ exp: number;
108
+ }
109
+
109
110
  // Supporting types
110
- export type RoomVisibility = "public" | "private" | "friends";
111
+ export type RoomVisibility = 'public' | 'private' | 'friends';
111
112
 
112
113
  export interface User {
113
114
  id: string;
@@ -120,7 +121,7 @@ export interface Room {
120
121
  id: string;
121
122
  send(type: string, data: any): void;
122
123
  on(event: string, handler: (data: any) => void): void;
123
- on(event: "disconnect", handler: () => void): void;
124
+ on(event: 'disconnect', handler: () => void): void;
124
125
  leave(): void;
125
126
  }
126
127
 
@@ -142,8 +143,5 @@ export interface Item {
142
143
 
143
144
  // v0 sdk types for testing
144
145
 
145
- export type SpawnClientSDK__V0 = Pick<
146
- SpawnClientSDK__V1,
147
- "user" | "ready" | "room"
148
- >;
149
- export type SpawnServerSDK__V0 = Pick<SpawnServerSDK__V1, "room">;
146
+ export type SpawnClientSDK__V0 = Omit<SpawnClientSDK__V1, 'economy' | 'inventory' | 'storage'>;
147
+ export type SpawnServerSDK__V0 = Omit<SpawnServerSDK__V1, 'economy' | 'inventory' | 'storage' | 'room'>;
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './v1';"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}