@dubsdotapp/node 0.1.1 → 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/dist/index.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ type RequestFn = <T>(method: string, path: string, body?: string, extraHeaders?: Record<string, string>) => Promise<T>;
2
+ declare class BaseResource {
3
+ protected request: RequestFn;
4
+ constructor(request: RequestFn);
5
+ }
6
+
1
7
  declare const DEFAULT_BASE_URL = "https://dubs-server-prod-9c91d3f01199.herokuapp.com/api/developer/v1";
2
8
  type DubsNetwork = 'devnet' | 'mainnet-beta';
3
9
  declare const NETWORK_CONFIG: Record<DubsNetwork, {
@@ -36,12 +42,243 @@ interface WebhookEvent {
36
42
  timestamp: string;
37
43
  data: Record<string, unknown>;
38
44
  }
45
+ interface User {
46
+ walletAddress: string;
47
+ username: string;
48
+ avatar?: string;
49
+ createdAt: string;
50
+ updatedAt: string;
51
+ [key: string]: unknown;
52
+ }
53
+ interface Game {
54
+ id: string;
55
+ status: string;
56
+ gameMode: number;
57
+ eventId?: string;
58
+ wagerAmount: number;
59
+ players: Record<string, unknown>[];
60
+ winner?: string | null;
61
+ createdAt: string;
62
+ updatedAt: string;
63
+ [key: string]: unknown;
64
+ }
65
+ interface Event {
66
+ id: string;
67
+ name: string;
68
+ type: string;
69
+ league?: string;
70
+ startTime: string;
71
+ status: string;
72
+ teams: {
73
+ home: string;
74
+ away: string;
75
+ };
76
+ [key: string]: unknown;
77
+ }
78
+ interface NonceParams {
79
+ walletAddress: string;
80
+ }
81
+ interface NonceResponse {
82
+ nonce: string;
83
+ }
84
+ interface AuthenticateParams {
85
+ walletAddress: string;
86
+ signature: string;
87
+ nonce: string;
88
+ }
89
+ interface AuthenticateResponse {
90
+ token: string;
91
+ user: User;
92
+ }
93
+ interface RegisterParams {
94
+ walletAddress: string;
95
+ signature: string;
96
+ nonce: string;
97
+ username: string;
98
+ }
99
+ interface RegisterResponse {
100
+ token: string;
101
+ user: User;
102
+ }
103
+ interface MeResponse {
104
+ user: User;
105
+ }
106
+ interface CheckUsernameResponse {
107
+ available: boolean;
108
+ username: string;
109
+ }
110
+ interface UserResponse {
111
+ user: User;
112
+ }
113
+ interface UsersListParams {
114
+ limit?: number;
115
+ offset?: number;
116
+ }
117
+ interface UsersListResponse {
118
+ users: User[];
119
+ total: number;
120
+ }
121
+ interface UpcomingEventsParams {
122
+ type?: string;
123
+ page?: number;
124
+ limit?: number;
125
+ }
126
+ interface EventsResponse {
127
+ events: Event[];
128
+ total?: number;
129
+ }
130
+ interface EsportsParams {
131
+ videogame?: string;
132
+ page?: number;
133
+ limit?: number;
134
+ }
135
+ interface EsportsMatchResponse {
136
+ match: Record<string, unknown>;
137
+ }
138
+ interface ValidateParams {
139
+ eventId: string;
140
+ }
141
+ interface ValidateResponse {
142
+ valid: boolean;
143
+ event: Event;
144
+ }
145
+ interface GameCreateParams {
146
+ id: string;
147
+ playerWallet: string;
148
+ teamChoice: string;
149
+ wagerAmount: number;
150
+ }
151
+ interface GameCreateResponse {
152
+ game: Game;
153
+ transaction: string;
154
+ }
155
+ interface GameJoinParams {
156
+ playerWallet: string;
157
+ gameId: string;
158
+ teamChoice: string;
159
+ amount: number;
160
+ }
161
+ interface GameJoinResponse {
162
+ game: Game;
163
+ transaction: string;
164
+ }
165
+ interface GameConfirmParams {
166
+ gameId: string;
167
+ playerWallet: string;
168
+ signature: string;
169
+ [key: string]: unknown;
170
+ }
171
+ interface GameConfirmResponse {
172
+ game: Game;
173
+ }
174
+ interface GameListParams {
175
+ status?: string;
176
+ limit?: number;
177
+ offset?: number;
178
+ }
179
+ interface GameListResponse {
180
+ games: Game[];
181
+ total: number;
182
+ }
183
+ interface NetworkGamesParams {
184
+ limit?: number;
185
+ offset?: number;
186
+ }
187
+ interface NetworkGamesResponse {
188
+ games: Game[];
189
+ total: number;
190
+ }
191
+ interface LiveScoreResponse {
192
+ gameId: string;
193
+ score: Record<string, unknown>;
194
+ status: string;
195
+ [key: string]: unknown;
196
+ }
197
+ interface CustomGameCreateParams {
198
+ playerWallet: string;
199
+ teamChoice: string;
200
+ wagerAmount: number;
201
+ [key: string]: unknown;
202
+ }
203
+ interface CustomGameCreateResponse {
204
+ game: Game;
205
+ transaction: string;
206
+ }
207
+ interface CustomGameConfirmParams {
208
+ gameId: string;
209
+ playerWallet: string;
210
+ signature: string;
211
+ [key: string]: unknown;
212
+ }
213
+ interface CustomGameConfirmResponse {
214
+ game: Game;
215
+ }
216
+ interface BuildClaimParams {
217
+ playerWallet: string;
218
+ gameId: string;
219
+ }
220
+ interface BuildClaimResponse {
221
+ transaction: string;
222
+ [key: string]: unknown;
223
+ }
224
+ interface AppConfigResponse {
225
+ [key: string]: unknown;
226
+ }
227
+
228
+ declare class AuthResource extends BaseResource {
229
+ getNonce(walletAddress: string): Promise<NonceResponse>;
230
+ authenticate(params: AuthenticateParams): Promise<AuthenticateResponse>;
231
+ register(params: RegisterParams): Promise<RegisterResponse>;
232
+ me(userToken: string): Promise<MeResponse>;
233
+ logout(userToken: string): Promise<void>;
234
+ checkUsername(username: string): Promise<CheckUsernameResponse>;
235
+ }
236
+
237
+ declare class UsersResource extends BaseResource {
238
+ get(walletAddress: string): Promise<UserResponse>;
239
+ list(params?: UsersListParams): Promise<UsersListResponse>;
240
+ }
241
+
242
+ declare class EventsResource extends BaseResource {
243
+ upcoming(params?: UpcomingEventsParams): Promise<EventsResponse>;
244
+ sports(league: string): Promise<EventsResponse>;
245
+ esports(params?: EsportsParams): Promise<EventsResponse>;
246
+ esportsMatch(matchId: string): Promise<EsportsMatchResponse>;
247
+ }
248
+
249
+ declare class GamesResource extends BaseResource {
250
+ validate(eventId: string): Promise<ValidateResponse>;
251
+ create(params: GameCreateParams): Promise<GameCreateResponse>;
252
+ join(params: GameJoinParams): Promise<GameJoinResponse>;
253
+ confirm(params: GameConfirmParams): Promise<GameConfirmResponse>;
254
+ get(gameId: string): Promise<{
255
+ game: Game;
256
+ }>;
257
+ list(params?: GameListParams): Promise<GameListResponse>;
258
+ network(params?: NetworkGamesParams): Promise<NetworkGamesResponse>;
259
+ liveScore(gameId: string): Promise<LiveScoreResponse>;
260
+ customCreate(params: CustomGameCreateParams): Promise<CustomGameCreateResponse>;
261
+ customConfirm(params: CustomGameConfirmParams): Promise<CustomGameConfirmResponse>;
262
+ }
263
+
264
+ declare class TransactionsResource extends BaseResource {
265
+ buildClaim(params: BuildClaimParams): Promise<BuildClaimResponse>;
266
+ }
39
267
 
40
268
  declare class Dubs {
41
269
  private readonly apiKey;
42
270
  private readonly resolutionSecret?;
43
271
  private readonly baseUrl;
272
+ readonly auth: AuthResource;
273
+ readonly users: UsersResource;
274
+ readonly events: EventsResource;
275
+ readonly games: GamesResource;
276
+ readonly transactions: TransactionsResource;
44
277
  constructor(config: DubsConfig);
278
+ /**
279
+ * Fetch the platform configuration.
280
+ */
281
+ config(): Promise<AppConfigResponse>;
45
282
  /**
46
283
  * Resolve a custom game (game_mode=6).
47
284
  *
@@ -67,4 +304,4 @@ declare class DubsApiError extends Error {
67
304
  constructor(code: string, message: string, httpStatus: number);
68
305
  }
69
306
 
70
- export { DEFAULT_BASE_URL, Dubs, DubsApiError, type DubsConfig, type DubsNetwork, NETWORK_CONFIG, type ResolveGameParams, type ResolveGameResult, type WebhookEvent };
307
+ export { type AppConfigResponse, AuthResource, type AuthenticateParams, type AuthenticateResponse, type BuildClaimParams, type BuildClaimResponse, type CheckUsernameResponse, type CustomGameConfirmParams, type CustomGameConfirmResponse, type CustomGameCreateParams, type CustomGameCreateResponse, DEFAULT_BASE_URL, Dubs, DubsApiError, type DubsConfig, type DubsNetwork, type EsportsMatchResponse, type EsportsParams, type Event, EventsResource, type EventsResponse, type Game, type GameConfirmParams, type GameConfirmResponse, type GameCreateParams, type GameCreateResponse, type GameJoinParams, type GameJoinResponse, type GameListParams, type GameListResponse, GamesResource, type LiveScoreResponse, type MeResponse, NETWORK_CONFIG, type NetworkGamesParams, type NetworkGamesResponse, type NonceParams, type NonceResponse, type RegisterParams, type RegisterResponse, type RequestFn, type ResolveGameParams, type ResolveGameResult, TransactionsResource, type UpcomingEventsParams, type User, type UserResponse, type UsersListParams, type UsersListResponse, UsersResource, type ValidateParams, type ValidateResponse, type WebhookEvent };
package/dist/index.js CHANGED
@@ -30,10 +30,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ AuthResource: () => AuthResource,
33
34
  DEFAULT_BASE_URL: () => DEFAULT_BASE_URL,
34
35
  Dubs: () => Dubs,
35
36
  DubsApiError: () => DubsApiError,
36
- NETWORK_CONFIG: () => NETWORK_CONFIG
37
+ EventsResource: () => EventsResource,
38
+ GamesResource: () => GamesResource,
39
+ NETWORK_CONFIG: () => NETWORK_CONFIG,
40
+ TransactionsResource: () => TransactionsResource,
41
+ UsersResource: () => UsersResource
37
42
  });
38
43
  module.exports = __toCommonJS(index_exports);
39
44
 
@@ -63,11 +68,140 @@ var DubsApiError = class extends Error {
63
68
  }
64
69
  };
65
70
 
71
+ // src/resources/base.ts
72
+ var BaseResource = class {
73
+ request;
74
+ constructor(request) {
75
+ this.request = request;
76
+ }
77
+ };
78
+
79
+ // src/resources/auth.ts
80
+ var AuthResource = class extends BaseResource {
81
+ async getNonce(walletAddress) {
82
+ return this.request("GET", `/auth/nonce?walletAddress=${encodeURIComponent(walletAddress)}`);
83
+ }
84
+ async authenticate(params) {
85
+ return this.request("POST", "/auth/authenticate", JSON.stringify(params));
86
+ }
87
+ async register(params) {
88
+ return this.request("POST", "/auth/register", JSON.stringify(params));
89
+ }
90
+ async me(userToken) {
91
+ return this.request("GET", "/auth/me", void 0, {
92
+ Authorization: `Bearer ${userToken}`
93
+ });
94
+ }
95
+ async logout(userToken) {
96
+ await this.request("POST", "/auth/logout", void 0, {
97
+ Authorization: `Bearer ${userToken}`
98
+ });
99
+ }
100
+ async checkUsername(username) {
101
+ return this.request("GET", `/auth/check-username?username=${encodeURIComponent(username)}`);
102
+ }
103
+ };
104
+
105
+ // src/resources/users.ts
106
+ var UsersResource = class extends BaseResource {
107
+ async get(walletAddress) {
108
+ return this.request("GET", `/users/${encodeURIComponent(walletAddress)}`);
109
+ }
110
+ async list(params) {
111
+ const query = new URLSearchParams();
112
+ if (params?.limit != null) query.set("limit", String(params.limit));
113
+ if (params?.offset != null) query.set("offset", String(params.offset));
114
+ const qs = query.toString();
115
+ return this.request("GET", `/users${qs ? `?${qs}` : ""}`);
116
+ }
117
+ };
118
+
119
+ // src/resources/events.ts
120
+ var EventsResource = class extends BaseResource {
121
+ async upcoming(params) {
122
+ const query = new URLSearchParams();
123
+ if (params?.type) query.set("type", params.type);
124
+ if (params?.page != null) query.set("page", String(params.page));
125
+ if (params?.limit != null) query.set("limit", String(params.limit));
126
+ const qs = query.toString();
127
+ return this.request("GET", `/events/upcoming${qs ? `?${qs}` : ""}`);
128
+ }
129
+ async sports(league) {
130
+ return this.request("GET", `/events/sports/${encodeURIComponent(league)}`);
131
+ }
132
+ async esports(params) {
133
+ const query = new URLSearchParams();
134
+ if (params?.videogame) query.set("videogame", params.videogame);
135
+ if (params?.page != null) query.set("page", String(params.page));
136
+ if (params?.limit != null) query.set("limit", String(params.limit));
137
+ const qs = query.toString();
138
+ return this.request("GET", `/events/esports${qs ? `?${qs}` : ""}`);
139
+ }
140
+ async esportsMatch(matchId) {
141
+ return this.request("GET", `/events/esports/match/${encodeURIComponent(matchId)}`);
142
+ }
143
+ };
144
+
145
+ // src/resources/games.ts
146
+ var GamesResource = class extends BaseResource {
147
+ async validate(eventId) {
148
+ return this.request("GET", `/games/validate?eventId=${encodeURIComponent(eventId)}`);
149
+ }
150
+ async create(params) {
151
+ return this.request("POST", "/games/create", JSON.stringify(params));
152
+ }
153
+ async join(params) {
154
+ return this.request("POST", "/games/join", JSON.stringify(params));
155
+ }
156
+ async confirm(params) {
157
+ return this.request("POST", "/games/confirm", JSON.stringify(params));
158
+ }
159
+ async get(gameId) {
160
+ return this.request("GET", `/games/${encodeURIComponent(gameId)}`);
161
+ }
162
+ async list(params) {
163
+ const query = new URLSearchParams();
164
+ if (params?.status) query.set("status", params.status);
165
+ if (params?.limit != null) query.set("limit", String(params.limit));
166
+ if (params?.offset != null) query.set("offset", String(params.offset));
167
+ const qs = query.toString();
168
+ return this.request("GET", `/games${qs ? `?${qs}` : ""}`);
169
+ }
170
+ async network(params) {
171
+ const query = new URLSearchParams();
172
+ if (params?.limit != null) query.set("limit", String(params.limit));
173
+ if (params?.offset != null) query.set("offset", String(params.offset));
174
+ const qs = query.toString();
175
+ return this.request("GET", `/games/network${qs ? `?${qs}` : ""}`);
176
+ }
177
+ async liveScore(gameId) {
178
+ return this.request("GET", `/games/${encodeURIComponent(gameId)}/live-score`);
179
+ }
180
+ async customCreate(params) {
181
+ return this.request("POST", "/games/custom/create", JSON.stringify(params));
182
+ }
183
+ async customConfirm(params) {
184
+ return this.request("POST", "/games/custom/confirm", JSON.stringify(params));
185
+ }
186
+ };
187
+
188
+ // src/resources/transactions.ts
189
+ var TransactionsResource = class extends BaseResource {
190
+ async buildClaim(params) {
191
+ return this.request("POST", "/transactions/build-claim", JSON.stringify(params));
192
+ }
193
+ };
194
+
66
195
  // src/client.ts
67
196
  var Dubs = class {
68
197
  apiKey;
69
198
  resolutionSecret;
70
199
  baseUrl;
200
+ auth;
201
+ users;
202
+ events;
203
+ games;
204
+ transactions;
71
205
  constructor(config) {
72
206
  this.apiKey = config.apiKey;
73
207
  this.resolutionSecret = config.resolutionSecret;
@@ -78,6 +212,18 @@ var Dubs = class {
78
212
  } else {
79
213
  this.baseUrl = DEFAULT_BASE_URL;
80
214
  }
215
+ const boundRequest = this.request.bind(this);
216
+ this.auth = new AuthResource(boundRequest);
217
+ this.users = new UsersResource(boundRequest);
218
+ this.events = new EventsResource(boundRequest);
219
+ this.games = new GamesResource(boundRequest);
220
+ this.transactions = new TransactionsResource(boundRequest);
221
+ }
222
+ /**
223
+ * Fetch the platform configuration.
224
+ */
225
+ async config() {
226
+ return this.request("GET", "/config");
81
227
  }
82
228
  /**
83
229
  * Resolve a custom game (game_mode=6).
@@ -145,9 +291,14 @@ var Dubs = class {
145
291
  };
146
292
  // Annotate the CommonJS export names for ESM import in node:
147
293
  0 && (module.exports = {
294
+ AuthResource,
148
295
  DEFAULT_BASE_URL,
149
296
  Dubs,
150
297
  DubsApiError,
151
- NETWORK_CONFIG
298
+ EventsResource,
299
+ GamesResource,
300
+ NETWORK_CONFIG,
301
+ TransactionsResource,
302
+ UsersResource
152
303
  });
153
304
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/client.ts","../src/constants.ts","../src/errors.ts"],"sourcesContent":["export { Dubs } from './client';\nexport { DubsApiError } from './errors';\nexport type { DubsConfig, ResolveGameParams, ResolveGameResult, WebhookEvent } from './types';\nexport { DEFAULT_BASE_URL, NETWORK_CONFIG } from './constants';\nexport type { DubsNetwork } from './constants';\n","import crypto from 'crypto';\nimport { DEFAULT_BASE_URL, NETWORK_CONFIG } from './constants';\nimport { DubsApiError } from './errors';\nimport type { DubsConfig, ResolveGameParams, ResolveGameResult, WebhookEvent } from './types';\n\nexport class Dubs {\n private readonly apiKey: string;\n private readonly resolutionSecret?: string;\n private readonly baseUrl: string;\n\n constructor(config: DubsConfig) {\n this.apiKey = config.apiKey;\n this.resolutionSecret = config.resolutionSecret;\n\n if (config.baseUrl) {\n this.baseUrl = config.baseUrl;\n } else if (config.network) {\n this.baseUrl = NETWORK_CONFIG[config.network].baseUrl;\n } else {\n this.baseUrl = DEFAULT_BASE_URL;\n }\n }\n\n /**\n * Resolve a custom game (game_mode=6).\n *\n * Automatically computes the HMAC-SHA256 signature using your resolution secret.\n */\n async resolveGame(gameId: string, params: ResolveGameParams): Promise<ResolveGameResult> {\n if (!this.resolutionSecret) {\n throw new DubsApiError(\n 'missing_resolution_secret',\n 'resolutionSecret is required for resolveGame(). Pass it in the Dubs constructor.',\n 0,\n );\n }\n\n const body = JSON.stringify({\n winner: params.winner,\n ...(params.metadata && { metadata: params.metadata }),\n });\n\n const hmac = crypto.createHmac('sha256', this.resolutionSecret).update(body).digest('hex');\n\n return this.request<ResolveGameResult>('POST', `/games/${gameId}/resolve`, body, {\n 'x-dubs-signature': `sha256=${hmac}`,\n });\n }\n\n /**\n * Verify an incoming Dubs webhook request.\n *\n * @param rawBody - The raw request body (string or Buffer)\n * @param signature - The X-Dubs-Signature header value\n * @param secret - Your webhook secret (from the developer portal)\n * @returns The parsed webhook event\n * @throws DubsApiError if the signature is invalid\n */\n static verifyWebhook(rawBody: string | Buffer, signature: string, secret: string): WebhookEvent {\n const body = typeof rawBody === 'string' ? rawBody : rawBody.toString('utf-8');\n const expected = crypto.createHmac('sha256', secret).update(body).digest('hex');\n\n if (\n signature.length !== expected.length ||\n !crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))\n ) {\n throw new DubsApiError('invalid_signature', 'Webhook signature verification failed', 401);\n }\n\n return JSON.parse(body) as WebhookEvent;\n }\n\n // ── Private ──\n\n private async request<T>(\n method: string,\n path: string,\n body?: string,\n extraHeaders?: Record<string, string>,\n ): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n\n const headers: Record<string, string> = {\n 'x-api-key': this.apiKey,\n 'Content-Type': 'application/json',\n ...extraHeaders,\n };\n\n const res = await fetch(url, {\n method,\n headers,\n ...(body && { body }),\n });\n\n const json = (await res.json()) as Record<string, unknown>;\n\n if (!res.ok) {\n const msg = typeof json.message === 'string' ? json.message\n : typeof json.error === 'string' ? json.error\n : `Request failed with status ${res.status}: ${JSON.stringify(json)}`;\n throw new DubsApiError(\n (json.code as string) || 'api_error',\n msg,\n res.status,\n );\n }\n\n return json as T;\n }\n}\n","export const DEFAULT_BASE_URL = 'https://dubs-server-prod-9c91d3f01199.herokuapp.com/api/developer/v1';\n\nexport type DubsNetwork = 'devnet' | 'mainnet-beta';\n\nexport const NETWORK_CONFIG: Record<DubsNetwork, { baseUrl: string }> = {\n 'mainnet-beta': {\n baseUrl: 'https://dubs-server-prod-9c91d3f01199.herokuapp.com/api/developer/v1',\n },\n devnet: {\n baseUrl: 'https://dubs-server-dev-55d1fba09a97.herokuapp.com/api/developer/v1',\n },\n};\n","export class DubsApiError extends Error {\n public readonly code: string;\n public readonly httpStatus: number;\n\n constructor(code: string, message: string, httpStatus: number) {\n super(message);\n this.name = 'DubsApiError';\n this.code = code;\n this.httpStatus = httpStatus;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAmB;;;ACAZ,IAAM,mBAAmB;AAIzB,IAAM,iBAA2D;AAAA,EACtE,gBAAgB;AAAA,IACd,SAAS;AAAA,EACX;AAAA,EACA,QAAQ;AAAA,IACN,SAAS;AAAA,EACX;AACF;;;ACXO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtB;AAAA,EACA;AAAA,EAEhB,YAAY,MAAc,SAAiB,YAAoB;AAC7D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,aAAa;AAAA,EACpB;AACF;;;AFLO,IAAM,OAAN,MAAW;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,YAAY,QAAoB;AAC9B,SAAK,SAAS,OAAO;AACrB,SAAK,mBAAmB,OAAO;AAE/B,QAAI,OAAO,SAAS;AAClB,WAAK,UAAU,OAAO;AAAA,IACxB,WAAW,OAAO,SAAS;AACzB,WAAK,UAAU,eAAe,OAAO,OAAO,EAAE;AAAA,IAChD,OAAO;AACL,WAAK,UAAU;AAAA,IACjB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,YAAY,QAAgB,QAAuD;AACvF,QAAI,CAAC,KAAK,kBAAkB;AAC1B,YAAM,IAAI;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA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Y,WAAW,KAAK,UAChD,OAAO,KAAK,UAAU,WAAW,KAAK,QACtC,8BAA8B,IAAI,MAAM,KAAK,KAAK,UAAU,IAAI,CAAC;AACrE,YAAM,IAAI;AAAA,QACP,KAAK,QAAmB;AAAA,QACzB;AAAA,QACA,IAAI;AAAA,MACN;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":["crypto"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/client.ts","../src/constants.ts","../src/errors.ts","../src/resources/base.ts","../src/resources/auth.ts","../src/resources/users.ts","../src/resources/events.ts","../src/resources/games.ts","../src/resources/transactions.ts"],"sourcesContent":["export { Dubs } from './client';\nexport { DubsApiError } from './errors';\nexport type { DubsConfig, ResolveGameParams, ResolveGameResult, WebhookEvent } from './types';\nexport { DEFAULT_BASE_URL, NETWORK_CONFIG } from './constants';\nexport type { DubsNetwork } from './constants';\n\n// Resource classes\nexport { AuthResource, UsersResource, EventsResource, GamesResource, TransactionsResource } from './resources';\nexport type { RequestFn } from './resources';\n\n// Auth types\nexport type {\n NonceParams,\n NonceResponse,\n AuthenticateParams,\n AuthenticateResponse,\n RegisterParams,\n RegisterResponse,\n MeResponse,\n CheckUsernameResponse,\n} from './types';\n\n// Users types\nexport type { User, UserResponse, UsersListParams, UsersListResponse } from './types';\n\n// Events types\nexport type {\n Event,\n UpcomingEventsParams,\n EventsResponse,\n EsportsParams,\n EsportsMatchResponse,\n} from './types';\n\n// Games types\nexport type {\n Game,\n ValidateParams,\n ValidateResponse,\n GameCreateParams,\n GameCreateResponse,\n GameJoinParams,\n GameJoinResponse,\n GameConfirmParams,\n GameConfirmResponse,\n GameListParams,\n GameListResponse,\n NetworkGamesParams,\n NetworkGamesResponse,\n LiveScoreResponse,\n CustomGameCreateParams,\n CustomGameCreateResponse,\n CustomGameConfirmParams,\n CustomGameConfirmResponse,\n} from './types';\n\n// Transactions types\nexport type { BuildClaimParams, BuildClaimResponse } from './types';\n\n// Config types\nexport type { AppConfigResponse } from './types';\n","import crypto from 'crypto';\nimport { DEFAULT_BASE_URL, NETWORK_CONFIG } from './constants';\nimport { DubsApiError } from './errors';\nimport {\n AuthResource,\n EventsResource,\n GamesResource,\n TransactionsResource,\n UsersResource,\n} from './resources';\nimport type { AppConfigResponse, DubsConfig, ResolveGameParams, ResolveGameResult, WebhookEvent } from './types';\n\nexport class Dubs {\n private readonly apiKey: string;\n private readonly resolutionSecret?: string;\n private readonly baseUrl: string;\n\n readonly auth: AuthResource;\n readonly users: UsersResource;\n readonly events: EventsResource;\n readonly games: GamesResource;\n readonly transactions: TransactionsResource;\n\n constructor(config: DubsConfig) {\n this.apiKey = config.apiKey;\n this.resolutionSecret = config.resolutionSecret;\n\n if (config.baseUrl) {\n this.baseUrl = config.baseUrl;\n } else if (config.network) {\n this.baseUrl = NETWORK_CONFIG[config.network].baseUrl;\n } else {\n this.baseUrl = DEFAULT_BASE_URL;\n }\n\n const boundRequest = this.request.bind(this);\n this.auth = new AuthResource(boundRequest);\n this.users = new UsersResource(boundRequest);\n this.events = new EventsResource(boundRequest);\n this.games = new GamesResource(boundRequest);\n this.transactions = new TransactionsResource(boundRequest);\n }\n\n /**\n * Fetch the platform configuration.\n */\n async config(): Promise<AppConfigResponse> {\n return this.request<AppConfigResponse>('GET', '/config');\n }\n\n /**\n * Resolve a custom game (game_mode=6).\n *\n * Automatically computes the HMAC-SHA256 signature using your resolution secret.\n */\n async resolveGame(gameId: string, params: ResolveGameParams): Promise<ResolveGameResult> {\n if (!this.resolutionSecret) {\n throw new DubsApiError(\n 'missing_resolution_secret',\n 'resolutionSecret is required for resolveGame(). Pass it in the Dubs constructor.',\n 0,\n );\n }\n\n const body = JSON.stringify({\n winner: params.winner,\n ...(params.metadata && { metadata: params.metadata }),\n });\n\n const hmac = crypto.createHmac('sha256', this.resolutionSecret).update(body).digest('hex');\n\n return this.request<ResolveGameResult>('POST', `/games/${gameId}/resolve`, body, {\n 'x-dubs-signature': `sha256=${hmac}`,\n });\n }\n\n /**\n * Verify an incoming Dubs webhook request.\n *\n * @param rawBody - The raw request body (string or Buffer)\n * @param signature - The X-Dubs-Signature header value\n * @param secret - Your webhook secret (from the developer portal)\n * @returns The parsed webhook event\n * @throws DubsApiError if the signature is invalid\n */\n static verifyWebhook(rawBody: string | Buffer, signature: string, secret: string): WebhookEvent {\n const body = typeof rawBody === 'string' ? rawBody : rawBody.toString('utf-8');\n const expected = crypto.createHmac('sha256', secret).update(body).digest('hex');\n\n if (\n signature.length !== expected.length ||\n !crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))\n ) {\n throw new DubsApiError('invalid_signature', 'Webhook signature verification failed', 401);\n }\n\n return JSON.parse(body) as WebhookEvent;\n }\n\n // ── Private ──\n\n private async request<T>(\n method: string,\n path: string,\n body?: string,\n extraHeaders?: Record<string, string>,\n ): Promise<T> {\n const url = `${this.baseUrl}${path}`;\n\n const headers: Record<string, string> = {\n 'x-api-key': this.apiKey,\n 'Content-Type': 'application/json',\n ...extraHeaders,\n };\n\n const res = await fetch(url, {\n method,\n headers,\n ...(body && { body }),\n });\n\n const json = (await res.json()) as Record<string, unknown>;\n\n if (!res.ok) {\n const msg = typeof json.message === 'string' ? json.message\n : typeof json.error === 'string' ? json.error\n : `Request failed with status ${res.status}: ${JSON.stringify(json)}`;\n throw new DubsApiError(\n (json.code as string) || 'api_error',\n msg,\n res.status,\n );\n }\n\n return json as T;\n }\n}\n","export const DEFAULT_BASE_URL = 'https://dubs-server-prod-9c91d3f01199.herokuapp.com/api/developer/v1';\n\nexport type DubsNetwork = 'devnet' | 'mainnet-beta';\n\nexport const NETWORK_CONFIG: Record<DubsNetwork, { baseUrl: string }> = {\n 'mainnet-beta': {\n baseUrl: 'https://dubs-server-prod-9c91d3f01199.herokuapp.com/api/developer/v1',\n },\n devnet: {\n baseUrl: 'https://dubs-server-dev-55d1fba09a97.herokuapp.com/api/developer/v1',\n },\n};\n","export class DubsApiError extends Error {\n public readonly code: string;\n public readonly httpStatus: number;\n\n constructor(code: string, message: string, httpStatus: number) {\n super(message);\n this.name = 'DubsApiError';\n this.code = code;\n this.httpStatus = httpStatus;\n }\n}\n","export type RequestFn = <T>(\n method: string,\n path: string,\n body?: string,\n extraHeaders?: Record<string, string>,\n) => Promise<T>;\n\nexport class BaseResource {\n protected request: RequestFn;\n\n constructor(request: RequestFn) {\n this.request = request;\n }\n}\n","import { BaseResource } from './base';\nimport type {\n AuthenticateParams,\n AuthenticateResponse,\n CheckUsernameResponse,\n MeResponse,\n NonceResponse,\n RegisterParams,\n RegisterResponse,\n} from '../types';\n\nexport class AuthResource extends BaseResource {\n async getNonce(walletAddress: string): Promise<NonceResponse> {\n return this.request<NonceResponse>('GET', `/auth/nonce?walletAddress=${encodeURIComponent(walletAddress)}`);\n }\n\n async authenticate(params: AuthenticateParams): Promise<AuthenticateResponse> {\n return this.request<AuthenticateResponse>('POST', '/auth/authenticate', JSON.stringify(params));\n }\n\n async register(params: RegisterParams): Promise<RegisterResponse> {\n return this.request<RegisterResponse>('POST', '/auth/register', JSON.stringify(params));\n }\n\n async me(userToken: string): Promise<MeResponse> {\n return this.request<MeResponse>('GET', '/auth/me', undefined, {\n Authorization: `Bearer ${userToken}`,\n });\n }\n\n async logout(userToken: string): Promise<void> {\n await this.request<Record<string, unknown>>('POST', '/auth/logout', undefined, {\n Authorization: `Bearer ${userToken}`,\n });\n }\n\n async checkUsername(username: string): Promise<CheckUsernameResponse> {\n return this.request<CheckUsernameResponse>('GET', `/auth/check-username?username=${encodeURIComponent(username)}`);\n }\n}\n","import { BaseResource } from './base';\nimport type { UserResponse, UsersListParams, UsersListResponse } from '../types';\n\nexport class UsersResource extends BaseResource {\n async get(walletAddress: string): Promise<UserResponse> {\n return this.request<UserResponse>('GET', `/users/${encodeURIComponent(walletAddress)}`);\n }\n\n async list(params?: UsersListParams): Promise<UsersListResponse> {\n const query = new URLSearchParams();\n if (params?.limit != null) query.set('limit', String(params.limit));\n if (params?.offset != null) query.set('offset', String(params.offset));\n const qs = query.toString();\n return this.request<UsersListResponse>('GET', `/users${qs ? `?${qs}` : ''}`);\n }\n}\n","import { BaseResource } from './base';\nimport type {\n EsportsMatchResponse,\n EsportsParams,\n EventsResponse,\n UpcomingEventsParams,\n} from '../types';\n\nexport class EventsResource extends BaseResource {\n async upcoming(params?: UpcomingEventsParams): Promise<EventsResponse> {\n const query = new URLSearchParams();\n if (params?.type) query.set('type', params.type);\n if (params?.page != null) query.set('page', String(params.page));\n if (params?.limit != null) query.set('limit', String(params.limit));\n const qs = query.toString();\n return this.request<EventsResponse>('GET', `/events/upcoming${qs ? `?${qs}` : ''}`);\n }\n\n async sports(league: string): Promise<EventsResponse> {\n return this.request<EventsResponse>('GET', `/events/sports/${encodeURIComponent(league)}`);\n }\n\n async esports(params?: EsportsParams): Promise<EventsResponse> {\n const query = new URLSearchParams();\n if (params?.videogame) query.set('videogame', params.videogame);\n if (params?.page != null) query.set('page', String(params.page));\n if (params?.limit != null) query.set('limit', String(params.limit));\n const qs = query.toString();\n return this.request<EventsResponse>('GET', `/events/esports${qs ? `?${qs}` : ''}`);\n }\n\n async esportsMatch(matchId: string): Promise<EsportsMatchResponse> {\n return this.request<EsportsMatchResponse>('GET', `/events/esports/match/${encodeURIComponent(matchId)}`);\n }\n}\n","import { BaseResource } from './base';\nimport type {\n CustomGameConfirmParams,\n CustomGameConfirmResponse,\n CustomGameCreateParams,\n CustomGameCreateResponse,\n Game,\n GameConfirmParams,\n GameConfirmResponse,\n GameCreateParams,\n GameCreateResponse,\n GameJoinParams,\n GameJoinResponse,\n GameListParams,\n GameListResponse,\n LiveScoreResponse,\n NetworkGamesParams,\n NetworkGamesResponse,\n ValidateResponse,\n} from '../types';\n\nexport class GamesResource extends BaseResource {\n async validate(eventId: string): Promise<ValidateResponse> {\n return this.request<ValidateResponse>('GET', `/games/validate?eventId=${encodeURIComponent(eventId)}`);\n }\n\n async create(params: GameCreateParams): Promise<GameCreateResponse> {\n return this.request<GameCreateResponse>('POST', '/games/create', JSON.stringify(params));\n }\n\n async join(params: GameJoinParams): Promise<GameJoinResponse> {\n return this.request<GameJoinResponse>('POST', '/games/join', JSON.stringify(params));\n }\n\n async confirm(params: GameConfirmParams): Promise<GameConfirmResponse> {\n return this.request<GameConfirmResponse>('POST', '/games/confirm', JSON.stringify(params));\n }\n\n async get(gameId: string): Promise<{ game: Game }> {\n return this.request<{ game: Game }>('GET', `/games/${encodeURIComponent(gameId)}`);\n }\n\n async list(params?: GameListParams): Promise<GameListResponse> {\n const query = new URLSearchParams();\n if (params?.status) query.set('status', params.status);\n if (params?.limit != null) query.set('limit', String(params.limit));\n if (params?.offset != null) query.set('offset', String(params.offset));\n const qs = query.toString();\n return this.request<GameListResponse>('GET', `/games${qs ? `?${qs}` : ''}`);\n }\n\n async network(params?: NetworkGamesParams): Promise<NetworkGamesResponse> {\n const query = new URLSearchParams();\n if (params?.limit != null) query.set('limit', String(params.limit));\n if (params?.offset != null) query.set('offset', String(params.offset));\n const qs = query.toString();\n return this.request<NetworkGamesResponse>('GET', `/games/network${qs ? `?${qs}` : ''}`);\n }\n\n async liveScore(gameId: string): Promise<LiveScoreResponse> {\n return this.request<LiveScoreResponse>('GET', `/games/${encodeURIComponent(gameId)}/live-score`);\n }\n\n async customCreate(params: CustomGameCreateParams): Promise<CustomGameCreateResponse> {\n return this.request<CustomGameCreateResponse>('POST', '/games/custom/create', JSON.stringify(params));\n }\n\n async customConfirm(params: CustomGameConfirmParams): Promise<CustomGameConfirmResponse> {\n return this.request<CustomGameConfirmResponse>('POST', '/games/custom/confirm', JSON.stringify(params));\n }\n}\n","import { BaseResource } from './base';\nimport type { BuildClaimParams, BuildClaimResponse } from '../types';\n\nexport class TransactionsResource extends BaseResource {\n async buildClaim(params: BuildClaimParams): Promise<BuildClaimResponse> {\n return this.request<BuildClaimResponse>('POST', '/transactions/build-claim', JSON.stringify(params));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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GAAG;AAAA,IAC1F;AAEA,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB;AAAA;AAAA,EAIA,MAAc,QACZ,QACA,MACA,MACA,cACY;AACZ,UAAM,MAAM,GAAG,KAAK,OAAO,GAAG,IAAI;AAElC,UAAM,UAAkC;AAAA,MACtC,aAAa,KAAK;AAAA,MAClB,gBAAgB;AAAA,MAChB,GAAG;AAAA,IACL;AAEA,UAAM,MAAM,MAAM,MAAM,KAAK;AAAA,MAC3B;AAAA,MACA;AAAA,MACA,GAAI,QAAQ,EAAE,KAAK;AAAA,IACrB,CAAC;AAED,UAAM,OAAQ,MAAM,IAAI,KAAK;AAE7B,QAAI,CAAC,IAAI,IAAI;AACX,YAAM,MAAM,OAAO,KAAK,YAAY,WAAW,KAAK,UAChD,OAAO,KAAK,UAAU,WAAW,KAAK,QACtC,8BAA8B,IAAI,MAAM,KAAK,KAAK,UAAU,IAAI,CAAC;AACrE,YAAM,IAAI;AAAA,QACP,KAAK,QAAmB;AAAA,QACzB;AAAA,QACA,IAAI;AAAA,MACN;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;","names":["crypto"]}
package/dist/index.mjs CHANGED
@@ -24,11 +24,140 @@ var DubsApiError = class extends Error {
24
24
  }
25
25
  };
26
26
 
27
+ // src/resources/base.ts
28
+ var BaseResource = class {
29
+ request;
30
+ constructor(request) {
31
+ this.request = request;
32
+ }
33
+ };
34
+
35
+ // src/resources/auth.ts
36
+ var AuthResource = class extends BaseResource {
37
+ async getNonce(walletAddress) {
38
+ return this.request("GET", `/auth/nonce?walletAddress=${encodeURIComponent(walletAddress)}`);
39
+ }
40
+ async authenticate(params) {
41
+ return this.request("POST", "/auth/authenticate", JSON.stringify(params));
42
+ }
43
+ async register(params) {
44
+ return this.request("POST", "/auth/register", JSON.stringify(params));
45
+ }
46
+ async me(userToken) {
47
+ return this.request("GET", "/auth/me", void 0, {
48
+ Authorization: `Bearer ${userToken}`
49
+ });
50
+ }
51
+ async logout(userToken) {
52
+ await this.request("POST", "/auth/logout", void 0, {
53
+ Authorization: `Bearer ${userToken}`
54
+ });
55
+ }
56
+ async checkUsername(username) {
57
+ return this.request("GET", `/auth/check-username?username=${encodeURIComponent(username)}`);
58
+ }
59
+ };
60
+
61
+ // src/resources/users.ts
62
+ var UsersResource = class extends BaseResource {
63
+ async get(walletAddress) {
64
+ return this.request("GET", `/users/${encodeURIComponent(walletAddress)}`);
65
+ }
66
+ async list(params) {
67
+ const query = new URLSearchParams();
68
+ if (params?.limit != null) query.set("limit", String(params.limit));
69
+ if (params?.offset != null) query.set("offset", String(params.offset));
70
+ const qs = query.toString();
71
+ return this.request("GET", `/users${qs ? `?${qs}` : ""}`);
72
+ }
73
+ };
74
+
75
+ // src/resources/events.ts
76
+ var EventsResource = class extends BaseResource {
77
+ async upcoming(params) {
78
+ const query = new URLSearchParams();
79
+ if (params?.type) query.set("type", params.type);
80
+ if (params?.page != null) query.set("page", String(params.page));
81
+ if (params?.limit != null) query.set("limit", String(params.limit));
82
+ const qs = query.toString();
83
+ return this.request("GET", `/events/upcoming${qs ? `?${qs}` : ""}`);
84
+ }
85
+ async sports(league) {
86
+ return this.request("GET", `/events/sports/${encodeURIComponent(league)}`);
87
+ }
88
+ async esports(params) {
89
+ const query = new URLSearchParams();
90
+ if (params?.videogame) query.set("videogame", params.videogame);
91
+ if (params?.page != null) query.set("page", String(params.page));
92
+ if (params?.limit != null) query.set("limit", String(params.limit));
93
+ const qs = query.toString();
94
+ return this.request("GET", `/events/esports${qs ? `?${qs}` : ""}`);
95
+ }
96
+ async esportsMatch(matchId) {
97
+ return this.request("GET", `/events/esports/match/${encodeURIComponent(matchId)}`);
98
+ }
99
+ };
100
+
101
+ // src/resources/games.ts
102
+ var GamesResource = class extends BaseResource {
103
+ async validate(eventId) {
104
+ return this.request("GET", `/games/validate?eventId=${encodeURIComponent(eventId)}`);
105
+ }
106
+ async create(params) {
107
+ return this.request("POST", "/games/create", JSON.stringify(params));
108
+ }
109
+ async join(params) {
110
+ return this.request("POST", "/games/join", JSON.stringify(params));
111
+ }
112
+ async confirm(params) {
113
+ return this.request("POST", "/games/confirm", JSON.stringify(params));
114
+ }
115
+ async get(gameId) {
116
+ return this.request("GET", `/games/${encodeURIComponent(gameId)}`);
117
+ }
118
+ async list(params) {
119
+ const query = new URLSearchParams();
120
+ if (params?.status) query.set("status", params.status);
121
+ if (params?.limit != null) query.set("limit", String(params.limit));
122
+ if (params?.offset != null) query.set("offset", String(params.offset));
123
+ const qs = query.toString();
124
+ return this.request("GET", `/games${qs ? `?${qs}` : ""}`);
125
+ }
126
+ async network(params) {
127
+ const query = new URLSearchParams();
128
+ if (params?.limit != null) query.set("limit", String(params.limit));
129
+ if (params?.offset != null) query.set("offset", String(params.offset));
130
+ const qs = query.toString();
131
+ return this.request("GET", `/games/network${qs ? `?${qs}` : ""}`);
132
+ }
133
+ async liveScore(gameId) {
134
+ return this.request("GET", `/games/${encodeURIComponent(gameId)}/live-score`);
135
+ }
136
+ async customCreate(params) {
137
+ return this.request("POST", "/games/custom/create", JSON.stringify(params));
138
+ }
139
+ async customConfirm(params) {
140
+ return this.request("POST", "/games/custom/confirm", JSON.stringify(params));
141
+ }
142
+ };
143
+
144
+ // src/resources/transactions.ts
145
+ var TransactionsResource = class extends BaseResource {
146
+ async buildClaim(params) {
147
+ return this.request("POST", "/transactions/build-claim", JSON.stringify(params));
148
+ }
149
+ };
150
+
27
151
  // src/client.ts
28
152
  var Dubs = class {
29
153
  apiKey;
30
154
  resolutionSecret;
31
155
  baseUrl;
156
+ auth;
157
+ users;
158
+ events;
159
+ games;
160
+ transactions;
32
161
  constructor(config) {
33
162
  this.apiKey = config.apiKey;
34
163
  this.resolutionSecret = config.resolutionSecret;
@@ -39,6 +168,18 @@ var Dubs = class {
39
168
  } else {
40
169
  this.baseUrl = DEFAULT_BASE_URL;
41
170
  }
171
+ const boundRequest = this.request.bind(this);
172
+ this.auth = new AuthResource(boundRequest);
173
+ this.users = new UsersResource(boundRequest);
174
+ this.events = new EventsResource(boundRequest);
175
+ this.games = new GamesResource(boundRequest);
176
+ this.transactions = new TransactionsResource(boundRequest);
177
+ }
178
+ /**
179
+ * Fetch the platform configuration.
180
+ */
181
+ async config() {
182
+ return this.request("GET", "/config");
42
183
  }
43
184
  /**
44
185
  * Resolve a custom game (game_mode=6).
@@ -105,9 +246,14 @@ var Dubs = class {
105
246
  }
106
247
  };
107
248
  export {
249
+ AuthResource,
108
250
  DEFAULT_BASE_URL,
109
251
  Dubs,
110
252
  DubsApiError,
111
- NETWORK_CONFIG
253
+ EventsResource,
254
+ GamesResource,
255
+ NETWORK_CONFIG,
256
+ TransactionsResource,
257
+ UsersResource
112
258
  };
113
259
  //# sourceMappingURL=index.mjs.map