@dubsdotapp/node 0.1.2 → 0.2.0
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/README.md +141 -9
- package/dist/index.d.mts +238 -1
- package/dist/index.d.ts +238 -1
- package/dist/index.js +153 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +147 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +28 -1
- package/src/index.ts +56 -0
- package/src/resources/auth.ts +40 -0
- package/src/resources/base.ts +14 -0
- package/src/resources/events.ts +35 -0
- package/src/resources/games.ts +71 -0
- package/src/resources/index.ts +7 -0
- package/src/resources/transactions.ts +8 -0
- package/src/resources/users.ts +16 -0
- package/src/types.ts +231 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type RequestFn = <T>(
|
|
2
|
+
method: string,
|
|
3
|
+
path: string,
|
|
4
|
+
body?: string,
|
|
5
|
+
extraHeaders?: Record<string, string>,
|
|
6
|
+
) => Promise<T>;
|
|
7
|
+
|
|
8
|
+
export class BaseResource {
|
|
9
|
+
protected request: RequestFn;
|
|
10
|
+
|
|
11
|
+
constructor(request: RequestFn) {
|
|
12
|
+
this.request = request;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { BaseResource } from './base';
|
|
2
|
+
import type {
|
|
3
|
+
EsportsMatchResponse,
|
|
4
|
+
EsportsParams,
|
|
5
|
+
EventsResponse,
|
|
6
|
+
UpcomingEventsParams,
|
|
7
|
+
} from '../types';
|
|
8
|
+
|
|
9
|
+
export class EventsResource extends BaseResource {
|
|
10
|
+
async upcoming(params?: UpcomingEventsParams): Promise<EventsResponse> {
|
|
11
|
+
const query = new URLSearchParams();
|
|
12
|
+
if (params?.type) query.set('type', params.type);
|
|
13
|
+
if (params?.page != null) query.set('page', String(params.page));
|
|
14
|
+
if (params?.limit != null) query.set('limit', String(params.limit));
|
|
15
|
+
const qs = query.toString();
|
|
16
|
+
return this.request<EventsResponse>('GET', `/events/upcoming${qs ? `?${qs}` : ''}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async sports(league: string): Promise<EventsResponse> {
|
|
20
|
+
return this.request<EventsResponse>('GET', `/events/sports/${encodeURIComponent(league)}`);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async esports(params?: EsportsParams): Promise<EventsResponse> {
|
|
24
|
+
const query = new URLSearchParams();
|
|
25
|
+
if (params?.videogame) query.set('videogame', params.videogame);
|
|
26
|
+
if (params?.page != null) query.set('page', String(params.page));
|
|
27
|
+
if (params?.limit != null) query.set('limit', String(params.limit));
|
|
28
|
+
const qs = query.toString();
|
|
29
|
+
return this.request<EventsResponse>('GET', `/events/esports${qs ? `?${qs}` : ''}`);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async esportsMatch(matchId: string): Promise<EsportsMatchResponse> {
|
|
33
|
+
return this.request<EsportsMatchResponse>('GET', `/events/esports/match/${encodeURIComponent(matchId)}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { BaseResource } from './base';
|
|
2
|
+
import type {
|
|
3
|
+
CustomGameConfirmParams,
|
|
4
|
+
CustomGameConfirmResponse,
|
|
5
|
+
CustomGameCreateParams,
|
|
6
|
+
CustomGameCreateResponse,
|
|
7
|
+
Game,
|
|
8
|
+
GameConfirmParams,
|
|
9
|
+
GameConfirmResponse,
|
|
10
|
+
GameCreateParams,
|
|
11
|
+
GameCreateResponse,
|
|
12
|
+
GameJoinParams,
|
|
13
|
+
GameJoinResponse,
|
|
14
|
+
GameListParams,
|
|
15
|
+
GameListResponse,
|
|
16
|
+
LiveScoreResponse,
|
|
17
|
+
NetworkGamesParams,
|
|
18
|
+
NetworkGamesResponse,
|
|
19
|
+
ValidateResponse,
|
|
20
|
+
} from '../types';
|
|
21
|
+
|
|
22
|
+
export class GamesResource extends BaseResource {
|
|
23
|
+
async validate(eventId: string): Promise<ValidateResponse> {
|
|
24
|
+
return this.request<ValidateResponse>('GET', `/games/validate?eventId=${encodeURIComponent(eventId)}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async create(params: GameCreateParams): Promise<GameCreateResponse> {
|
|
28
|
+
return this.request<GameCreateResponse>('POST', '/games/create', JSON.stringify(params));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async join(params: GameJoinParams): Promise<GameJoinResponse> {
|
|
32
|
+
return this.request<GameJoinResponse>('POST', '/games/join', JSON.stringify(params));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async confirm(params: GameConfirmParams): Promise<GameConfirmResponse> {
|
|
36
|
+
return this.request<GameConfirmResponse>('POST', '/games/confirm', JSON.stringify(params));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async get(gameId: string): Promise<{ game: Game }> {
|
|
40
|
+
return this.request<{ game: Game }>('GET', `/games/${encodeURIComponent(gameId)}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async list(params?: GameListParams): Promise<GameListResponse> {
|
|
44
|
+
const query = new URLSearchParams();
|
|
45
|
+
if (params?.status) query.set('status', params.status);
|
|
46
|
+
if (params?.limit != null) query.set('limit', String(params.limit));
|
|
47
|
+
if (params?.offset != null) query.set('offset', String(params.offset));
|
|
48
|
+
const qs = query.toString();
|
|
49
|
+
return this.request<GameListResponse>('GET', `/games${qs ? `?${qs}` : ''}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async network(params?: NetworkGamesParams): Promise<NetworkGamesResponse> {
|
|
53
|
+
const query = new URLSearchParams();
|
|
54
|
+
if (params?.limit != null) query.set('limit', String(params.limit));
|
|
55
|
+
if (params?.offset != null) query.set('offset', String(params.offset));
|
|
56
|
+
const qs = query.toString();
|
|
57
|
+
return this.request<NetworkGamesResponse>('GET', `/games/network${qs ? `?${qs}` : ''}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async liveScore(gameId: string): Promise<LiveScoreResponse> {
|
|
61
|
+
return this.request<LiveScoreResponse>('GET', `/games/${encodeURIComponent(gameId)}/live-score`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async customCreate(params: CustomGameCreateParams): Promise<CustomGameCreateResponse> {
|
|
65
|
+
return this.request<CustomGameCreateResponse>('POST', '/games/custom/create', JSON.stringify(params));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async customConfirm(params: CustomGameConfirmParams): Promise<CustomGameConfirmResponse> {
|
|
69
|
+
return this.request<CustomGameConfirmResponse>('POST', '/games/custom/confirm', JSON.stringify(params));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { BaseResource } from './base';
|
|
2
|
+
export type { RequestFn } from './base';
|
|
3
|
+
export { AuthResource } from './auth';
|
|
4
|
+
export { UsersResource } from './users';
|
|
5
|
+
export { EventsResource } from './events';
|
|
6
|
+
export { GamesResource } from './games';
|
|
7
|
+
export { TransactionsResource } from './transactions';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseResource } from './base';
|
|
2
|
+
import type { BuildClaimParams, BuildClaimResponse } from '../types';
|
|
3
|
+
|
|
4
|
+
export class TransactionsResource extends BaseResource {
|
|
5
|
+
async buildClaim(params: BuildClaimParams): Promise<BuildClaimResponse> {
|
|
6
|
+
return this.request<BuildClaimResponse>('POST', '/transactions/build-claim', JSON.stringify(params));
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BaseResource } from './base';
|
|
2
|
+
import type { UserResponse, UsersListParams, UsersListResponse } from '../types';
|
|
3
|
+
|
|
4
|
+
export class UsersResource extends BaseResource {
|
|
5
|
+
async get(walletAddress: string): Promise<UserResponse> {
|
|
6
|
+
return this.request<UserResponse>('GET', `/users/${encodeURIComponent(walletAddress)}`);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async list(params?: UsersListParams): Promise<UsersListResponse> {
|
|
10
|
+
const query = new URLSearchParams();
|
|
11
|
+
if (params?.limit != null) query.set('limit', String(params.limit));
|
|
12
|
+
if (params?.offset != null) query.set('offset', String(params.offset));
|
|
13
|
+
const qs = query.toString();
|
|
14
|
+
return this.request<UsersListResponse>('GET', `/users${qs ? `?${qs}` : ''}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -35,3 +35,234 @@ export interface WebhookEvent {
|
|
|
35
35
|
timestamp: string;
|
|
36
36
|
data: Record<string, unknown>;
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
// ── Shared shapes ──
|
|
40
|
+
|
|
41
|
+
export interface User {
|
|
42
|
+
walletAddress: string;
|
|
43
|
+
username: string;
|
|
44
|
+
avatar?: string;
|
|
45
|
+
createdAt: string;
|
|
46
|
+
updatedAt: string;
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface Game {
|
|
51
|
+
id: string;
|
|
52
|
+
status: string;
|
|
53
|
+
gameMode: number;
|
|
54
|
+
eventId?: string;
|
|
55
|
+
wagerAmount: number;
|
|
56
|
+
players: Record<string, unknown>[];
|
|
57
|
+
winner?: string | null;
|
|
58
|
+
createdAt: string;
|
|
59
|
+
updatedAt: string;
|
|
60
|
+
[key: string]: unknown;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface Event {
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
type: string;
|
|
67
|
+
league?: string;
|
|
68
|
+
startTime: string;
|
|
69
|
+
status: string;
|
|
70
|
+
teams: { home: string; away: string };
|
|
71
|
+
[key: string]: unknown;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ── Auth types ──
|
|
75
|
+
|
|
76
|
+
export interface NonceParams {
|
|
77
|
+
walletAddress: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface NonceResponse {
|
|
81
|
+
nonce: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface AuthenticateParams {
|
|
85
|
+
walletAddress: string;
|
|
86
|
+
signature: string;
|
|
87
|
+
nonce: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export interface AuthenticateResponse {
|
|
91
|
+
token: string;
|
|
92
|
+
user: User;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface RegisterParams {
|
|
96
|
+
walletAddress: string;
|
|
97
|
+
signature: string;
|
|
98
|
+
nonce: string;
|
|
99
|
+
username: string;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface RegisterResponse {
|
|
103
|
+
token: string;
|
|
104
|
+
user: User;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface MeResponse {
|
|
108
|
+
user: User;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface CheckUsernameResponse {
|
|
112
|
+
available: boolean;
|
|
113
|
+
username: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ── Users types ──
|
|
117
|
+
|
|
118
|
+
export interface UserResponse {
|
|
119
|
+
user: User;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface UsersListParams {
|
|
123
|
+
limit?: number;
|
|
124
|
+
offset?: number;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export interface UsersListResponse {
|
|
128
|
+
users: User[];
|
|
129
|
+
total: number;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ── Events types ──
|
|
133
|
+
|
|
134
|
+
export interface UpcomingEventsParams {
|
|
135
|
+
type?: string;
|
|
136
|
+
page?: number;
|
|
137
|
+
limit?: number;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export interface EventsResponse {
|
|
141
|
+
events: Event[];
|
|
142
|
+
total?: number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface EsportsParams {
|
|
146
|
+
videogame?: string;
|
|
147
|
+
page?: number;
|
|
148
|
+
limit?: number;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface EsportsMatchResponse {
|
|
152
|
+
match: Record<string, unknown>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ── Games types ──
|
|
156
|
+
|
|
157
|
+
export interface ValidateParams {
|
|
158
|
+
eventId: string;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export interface ValidateResponse {
|
|
162
|
+
valid: boolean;
|
|
163
|
+
event: Event;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface GameCreateParams {
|
|
167
|
+
id: string;
|
|
168
|
+
playerWallet: string;
|
|
169
|
+
teamChoice: string;
|
|
170
|
+
wagerAmount: number;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export interface GameCreateResponse {
|
|
174
|
+
game: Game;
|
|
175
|
+
transaction: string;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface GameJoinParams {
|
|
179
|
+
playerWallet: string;
|
|
180
|
+
gameId: string;
|
|
181
|
+
teamChoice: string;
|
|
182
|
+
amount: number;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface GameJoinResponse {
|
|
186
|
+
game: Game;
|
|
187
|
+
transaction: string;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export interface GameConfirmParams {
|
|
191
|
+
gameId: string;
|
|
192
|
+
playerWallet: string;
|
|
193
|
+
signature: string;
|
|
194
|
+
[key: string]: unknown;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export interface GameConfirmResponse {
|
|
198
|
+
game: Game;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface GameListParams {
|
|
202
|
+
status?: string;
|
|
203
|
+
limit?: number;
|
|
204
|
+
offset?: number;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export interface GameListResponse {
|
|
208
|
+
games: Game[];
|
|
209
|
+
total: number;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export interface NetworkGamesParams {
|
|
213
|
+
limit?: number;
|
|
214
|
+
offset?: number;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface NetworkGamesResponse {
|
|
218
|
+
games: Game[];
|
|
219
|
+
total: number;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface LiveScoreResponse {
|
|
223
|
+
gameId: string;
|
|
224
|
+
score: Record<string, unknown>;
|
|
225
|
+
status: string;
|
|
226
|
+
[key: string]: unknown;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface CustomGameCreateParams {
|
|
230
|
+
playerWallet: string;
|
|
231
|
+
teamChoice: string;
|
|
232
|
+
wagerAmount: number;
|
|
233
|
+
[key: string]: unknown;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface CustomGameCreateResponse {
|
|
237
|
+
game: Game;
|
|
238
|
+
transaction: string;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export interface CustomGameConfirmParams {
|
|
242
|
+
gameId: string;
|
|
243
|
+
playerWallet: string;
|
|
244
|
+
signature: string;
|
|
245
|
+
[key: string]: unknown;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export interface CustomGameConfirmResponse {
|
|
249
|
+
game: Game;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ── Transactions types ──
|
|
253
|
+
|
|
254
|
+
export interface BuildClaimParams {
|
|
255
|
+
playerWallet: string;
|
|
256
|
+
gameId: string;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export interface BuildClaimResponse {
|
|
260
|
+
transaction: string;
|
|
261
|
+
[key: string]: unknown;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// ── Config types ──
|
|
265
|
+
|
|
266
|
+
export interface AppConfigResponse {
|
|
267
|
+
[key: string]: unknown;
|
|
268
|
+
}
|