vairified 0.1.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.
@@ -0,0 +1,1015 @@
1
+ /**
2
+ * Vairified SDK Types
3
+ *
4
+ * @module
5
+ */
6
+ /**
7
+ * Options for initializing the Vairified client.
8
+ *
9
+ * @category Types
10
+ */
11
+ interface VairifiedOptions {
12
+ /** API key for authentication */
13
+ apiKey?: string;
14
+ /** Environment preset: "production" (default), "staging", "local" */
15
+ env?: 'production' | 'staging' | 'local';
16
+ /** Override API base URL. Takes precedence over env. */
17
+ baseUrl?: string;
18
+ /** Request timeout in milliseconds (default: 30000) */
19
+ timeout?: number;
20
+ }
21
+ /**
22
+ * A single rating split with metadata.
23
+ *
24
+ * @category Types
25
+ */
26
+ interface RatingSplitData {
27
+ /** The rating value (may be string from API) */
28
+ rating: string | number;
29
+ /** Abbreviation (e.g., "VG", "50+") */
30
+ abbr: string;
31
+ /** Date of last match in this category */
32
+ date_played?: string;
33
+ }
34
+ /**
35
+ * Rating splits from API - map of category to rating data.
36
+ *
37
+ * @category Types
38
+ */
39
+ type RatingSplitsData = Record<string, RatingSplitData | number>;
40
+ /**
41
+ * Player data from getMember endpoint (requires OAuth connection).
42
+ *
43
+ * @category Types
44
+ */
45
+ interface MemberData {
46
+ /** External player ID (vair_mem_xxx format) */
47
+ id: string;
48
+ firstName?: string;
49
+ lastName?: string;
50
+ /** Email (only if profile:email scope granted) */
51
+ email?: string;
52
+ rating?: number;
53
+ isVairified?: boolean;
54
+ ratingSplits?: RatingSplitsData;
55
+ city?: string;
56
+ state?: string;
57
+ country?: string;
58
+ /** Scopes the player granted to your app */
59
+ grantedScopes?: string[];
60
+ }
61
+ /**
62
+ * Player data from search endpoint (public, limited data).
63
+ *
64
+ * @category Types
65
+ */
66
+ interface PlayerSearchData {
67
+ /** External player ID (vair_mem_xxx format) */
68
+ id: string;
69
+ /** Display name (First Name + Last Initial for privacy) */
70
+ displayName: string;
71
+ city?: string;
72
+ state?: string;
73
+ country?: string;
74
+ rating?: number;
75
+ isVairified?: boolean;
76
+ /** Whether player has connected to your app */
77
+ isConnected?: boolean;
78
+ }
79
+ /**
80
+ * Filters for player search.
81
+ *
82
+ * @category Types
83
+ */
84
+ interface SearchFilters {
85
+ /** Name search (partial match) */
86
+ name?: string;
87
+ /** City filter */
88
+ city?: string;
89
+ /** State code (e.g., "TX") */
90
+ state?: string;
91
+ /** Country code (e.g., "US") */
92
+ country?: string;
93
+ /** ZIP/postal code */
94
+ zipCode?: string;
95
+ /** Minimum rating (2.0-8.0) */
96
+ ratingMin?: number;
97
+ /** Maximum rating (2.0-8.0) */
98
+ ratingMax?: number;
99
+ /** Gender filter */
100
+ gender?: 'MALE' | 'FEMALE';
101
+ /** Only verified players */
102
+ vairifiedOnly?: boolean;
103
+ /** Exact age */
104
+ age?: number;
105
+ /** Minimum age */
106
+ ageMin?: number;
107
+ /** Maximum age */
108
+ ageMax?: number;
109
+ /** Field to sort by */
110
+ sortBy?: string;
111
+ /** Sort direction */
112
+ sortOrder?: 'asc' | 'desc';
113
+ /** Page number (1-indexed) */
114
+ page?: number;
115
+ /** Results per page (max 100) */
116
+ limit?: number;
117
+ }
118
+ /**
119
+ * Match input for creating a Match.
120
+ *
121
+ * @category Types
122
+ */
123
+ interface MatchInput {
124
+ /** Event/tournament name */
125
+ event: string;
126
+ /** Bracket/division name */
127
+ bracket: string;
128
+ /** Match date and time */
129
+ date: Date | string;
130
+ /** Team 1 player IDs (1 for singles, 2 for doubles) */
131
+ team1: [string] | [string, string];
132
+ /** Team 2 player IDs (1 for singles, 2 for doubles) */
133
+ team2: [string] | [string, string];
134
+ /** Game scores as [team1Score, team2Score] tuples */
135
+ scores: [number, number][];
136
+ /** Match type (default: "SIDEOUT") */
137
+ matchType?: string;
138
+ /** Match source (default: "PARTNER") */
139
+ source?: string;
140
+ /** Location (optional) */
141
+ location?: string;
142
+ /** Unique identifier (auto-generated if not provided) */
143
+ identifier?: string;
144
+ }
145
+ /**
146
+ * Match data as sent to API.
147
+ *
148
+ * @category Types
149
+ */
150
+ interface MatchApiData {
151
+ identifier: string;
152
+ bracket: string;
153
+ event: string;
154
+ format: 'SINGLES' | 'DOUBLES';
155
+ matchDate: string;
156
+ matchSource: string;
157
+ matchType: string;
158
+ location?: string;
159
+ teamA: {
160
+ player1: string;
161
+ player2?: string;
162
+ game1?: number;
163
+ game2?: number;
164
+ game3?: number;
165
+ game4?: number;
166
+ game5?: number;
167
+ };
168
+ teamB: {
169
+ player1: string;
170
+ player2?: string;
171
+ game1?: number;
172
+ game2?: number;
173
+ game3?: number;
174
+ game4?: number;
175
+ game5?: number;
176
+ };
177
+ }
178
+ /**
179
+ * Response from match submission.
180
+ *
181
+ * @category Types
182
+ */
183
+ interface MatchResultData {
184
+ /** Whether submission succeeded */
185
+ success: boolean;
186
+ /** Number of matches processed */
187
+ numMatches: number;
188
+ /** Total number of games recorded */
189
+ numGames: number;
190
+ /** Whether this was a dry-run (validation only) */
191
+ dryRun?: boolean;
192
+ /** Human-readable result message */
193
+ message?: string;
194
+ /** List of validation/processing errors */
195
+ errors?: string[];
196
+ }
197
+ /**
198
+ * Rating update from API.
199
+ *
200
+ * @category Types
201
+ */
202
+ interface RatingUpdateData {
203
+ /** External player ID (vair_mem_xxx format) */
204
+ id: string;
205
+ memberName?: string;
206
+ previousRating?: number;
207
+ newRating?: number;
208
+ changedAt?: string;
209
+ ratingSplits?: RatingSplitsData;
210
+ }
211
+ /**
212
+ * Search results from API.
213
+ *
214
+ * @category Types
215
+ */
216
+ interface SearchResultsData {
217
+ players: PlayerSearchData[];
218
+ total: number;
219
+ page: number;
220
+ limit: number;
221
+ }
222
+
223
+ /**
224
+ * Vairified SDK Models
225
+ *
226
+ * Rich model classes with methods for easy API interaction.
227
+ *
228
+ * @module
229
+ */
230
+
231
+ /** Union type for player data from different endpoints */
232
+ type PlayerData = MemberData | PlayerSearchData;
233
+ /**
234
+ * A single rating split with metadata.
235
+ *
236
+ * @category Models
237
+ */
238
+ declare class RatingSplit {
239
+ /** The rating value */
240
+ readonly rating: number;
241
+ /** Abbreviation (e.g., "VG", "50+") */
242
+ readonly abbr: string;
243
+ /** Date of last match in this category */
244
+ readonly datePlayed?: string;
245
+ constructor(data: RatingSplitData | number);
246
+ }
247
+ /**
248
+ * Rating breakdown by category.
249
+ *
250
+ * Access ratings by category name or use convenience properties.
251
+ *
252
+ * @category Models
253
+ */
254
+ declare class RatingSplits {
255
+ /** Map of category names to rating splits */
256
+ readonly splits: Map<string, RatingSplit>;
257
+ constructor(data?: RatingSplitsData);
258
+ /** Get rating for a category */
259
+ get(category: string): number | undefined;
260
+ /** Open division rating */
261
+ get open(): number | undefined;
262
+ /** Gender-specific rating (same gender doubles) */
263
+ get gender(): number | undefined;
264
+ /** Mixed doubles rating */
265
+ get mixed(): number | undefined;
266
+ /** Recreational rating */
267
+ get recreational(): number | undefined;
268
+ /** Singles rating */
269
+ get singles(): number | undefined;
270
+ /** Best available verified rating */
271
+ get best(): number | undefined;
272
+ /** Convert to plain object */
273
+ toJSON(): Record<string, {
274
+ rating: number;
275
+ abbr: string;
276
+ }>;
277
+ }
278
+ /**
279
+ * A player in the Vairified system.
280
+ *
281
+ * From public search, only limited data is available (display name, location, rating).
282
+ * For full profile data, use getMember() with OAuth consent.
283
+ *
284
+ * @category Models
285
+ */
286
+ declare class Player {
287
+ /** External player ID (vair_mem_xxx format) */
288
+ readonly id: string;
289
+ /** Display name (First Name + Last Initial from search) */
290
+ readonly displayName?: string;
291
+ /** First name (only from connected member) */
292
+ readonly firstName?: string;
293
+ /** Last name (only from connected member) */
294
+ readonly lastName?: string;
295
+ /** Primary/overall rating (2.0-8.0) */
296
+ readonly rating: number;
297
+ /** Whether player is verified */
298
+ readonly isVairified: boolean;
299
+ /** Whether player has connected to your app */
300
+ readonly isConnected: boolean;
301
+ /** Ratings by category (only from connected member) */
302
+ readonly ratingSplits: RatingSplits;
303
+ /** City */
304
+ readonly city?: string;
305
+ /** State code */
306
+ readonly state?: string;
307
+ /** Country code */
308
+ readonly country?: string;
309
+ protected _client?: Vairified;
310
+ constructor(data: PlayerData, client?: Vairified);
311
+ /** Full name (or display name if full name not available) */
312
+ get name(): string;
313
+ /** Best verified rating */
314
+ get verifiedRating(): number | undefined;
315
+ toString(): string;
316
+ }
317
+ /**
318
+ * A member with full profile access (requires OAuth connection).
319
+ *
320
+ * Only accessible for players who have connected their account via OAuth.
321
+ *
322
+ * @category Models
323
+ */
324
+ declare class Member extends Player {
325
+ /** Email address (only if profile:email scope granted) */
326
+ readonly email?: string;
327
+ /** Scopes the player granted to your app */
328
+ readonly grantedScopes: string[];
329
+ constructor(data: MemberData, client?: Vairified);
330
+ /** Check if the player has granted a specific scope */
331
+ hasScope(scope: string): boolean;
332
+ /** Refresh member data from API */
333
+ refresh(): Promise<Member>;
334
+ }
335
+ /**
336
+ * A match to submit to the Vairified Partner API.
337
+ *
338
+ * @category Models
339
+ *
340
+ * @example
341
+ * ```ts
342
+ * // Doubles match: 11-9, 11-7
343
+ * const match = new Match({
344
+ * event: 'Weekly League',
345
+ * bracket: '4.0 Doubles',
346
+ * date: new Date(),
347
+ * team1: ['player1_id', 'player2_id'],
348
+ * team2: ['player3_id', 'player4_id'],
349
+ * scores: [[11, 9], [11, 7]],
350
+ * });
351
+ *
352
+ * // Singles match: 11-8, 9-11, 11-6
353
+ * const match = new Match({
354
+ * event: 'Club Singles',
355
+ * bracket: 'Open Singles',
356
+ * date: new Date(),
357
+ * team1: ['player1_id'],
358
+ * team2: ['player2_id'],
359
+ * scores: [[11, 8], [9, 11], [11, 6]],
360
+ * });
361
+ * ```
362
+ */
363
+ declare class Match {
364
+ /** Event/tournament name */
365
+ readonly event: string;
366
+ /** Bracket/division name */
367
+ readonly bracket: string;
368
+ /** Match date */
369
+ readonly date: Date;
370
+ /** Team 1 player IDs */
371
+ readonly team1: readonly string[];
372
+ /** Team 2 player IDs */
373
+ readonly team2: readonly string[];
374
+ /** Game scores */
375
+ readonly scores: readonly [number, number][];
376
+ /** Match type */
377
+ readonly matchType: string;
378
+ /** Match source */
379
+ readonly source: string;
380
+ /** Location */
381
+ readonly location?: string;
382
+ /** Unique identifier */
383
+ readonly identifier: string;
384
+ /** Match ID (set after submission) */
385
+ id?: string;
386
+ constructor(data: MatchInput);
387
+ /** Match format: SINGLES or DOUBLES */
388
+ get format(): 'SINGLES' | 'DOUBLES';
389
+ /** Team that won (1 or 2). Returns 0 if tie. */
390
+ get winner(): 0 | 1 | 2;
391
+ /** Score summary like "11-9, 11-7" */
392
+ get scoreSummary(): string;
393
+ /** Convert to API request format */
394
+ toJSON(): MatchApiData;
395
+ }
396
+ /**
397
+ * Result of a match submission.
398
+ *
399
+ * @category Models
400
+ */
401
+ declare class MatchResult {
402
+ /** Whether submission succeeded */
403
+ readonly success: boolean;
404
+ /** Number of matches processed */
405
+ readonly numMatches: number;
406
+ /** Number of games recorded */
407
+ readonly numGames: number;
408
+ /** Whether this was a dry-run (validation only) */
409
+ readonly dryRun: boolean;
410
+ /** Human-readable result message */
411
+ readonly message?: string;
412
+ /** List of validation/processing errors */
413
+ readonly errors: string[];
414
+ constructor(data: MatchResultData);
415
+ /** Alias for dryRun */
416
+ get isDryRun(): boolean;
417
+ /** Returns true if submission succeeded without errors */
418
+ get ok(): boolean;
419
+ }
420
+ /**
421
+ * A rating change notification.
422
+ *
423
+ * @category Models
424
+ */
425
+ declare class RatingUpdate {
426
+ /** External player ID (vair_mem_xxx format) */
427
+ readonly id: string;
428
+ /** Member name */
429
+ readonly memberName?: string;
430
+ /** Previous rating */
431
+ readonly previousRating: number;
432
+ /** New rating */
433
+ readonly newRating: number;
434
+ /** When the change occurred */
435
+ readonly changedAt: Date;
436
+ /** Updated rating splits */
437
+ readonly ratingSplits: RatingSplits;
438
+ private _client?;
439
+ constructor(data: RatingUpdateData, client?: Vairified);
440
+ /** Amount of rating change */
441
+ get change(): number;
442
+ /** Whether rating improved */
443
+ get improved(): boolean;
444
+ /** Fetch the member associated with this update */
445
+ getMember(): Promise<Member>;
446
+ toString(): string;
447
+ }
448
+ /**
449
+ * Paginated search results.
450
+ *
451
+ * @category Models
452
+ */
453
+ declare class SearchResults implements Iterable<Player> {
454
+ /** List of players */
455
+ readonly players: Player[];
456
+ /** Total matching players */
457
+ readonly total: number;
458
+ /** Current page */
459
+ readonly page: number;
460
+ /** Results per page */
461
+ readonly limit: number;
462
+ private _client?;
463
+ private _filters;
464
+ constructor(data: SearchResultsData, client?: Vairified, filters?: SearchFilters);
465
+ /** Whether more results are available */
466
+ get hasMore(): boolean;
467
+ /** Total number of pages */
468
+ get pages(): number;
469
+ /** Number of players in current page */
470
+ get length(): number;
471
+ /** Get player by index */
472
+ at(index: number): Player | undefined;
473
+ /** Iterate over players */
474
+ [Symbol.iterator](): Iterator<Player>;
475
+ /** Fetch next page of results */
476
+ nextPage(): Promise<SearchResults>;
477
+ }
478
+
479
+ /**
480
+ * Vairified OAuth Helpers
481
+ *
482
+ * Utilities for implementing the "Connect with Vairified" OAuth flow.
483
+ *
484
+ * @module
485
+ */
486
+ /**
487
+ * Available OAuth scopes with descriptions.
488
+ *
489
+ * @category OAuth
490
+ */
491
+ declare const SCOPES: {
492
+ readonly 'profile:read': "Access your name, location, and verification status";
493
+ readonly 'profile:email': "Access your email address";
494
+ readonly 'rating:read': "View your current rating and rating splits";
495
+ readonly 'rating:history': "View your complete rating history";
496
+ readonly 'match:submit': "Submit match results on your behalf";
497
+ readonly 'webhook:subscribe': "Receive notifications when your rating changes";
498
+ };
499
+ /**
500
+ * Available OAuth scope keys.
501
+ *
502
+ * @category OAuth
503
+ */
504
+ type OAuthScope = keyof typeof SCOPES;
505
+ /**
506
+ * Default scopes requested for new connections.
507
+ *
508
+ * @category OAuth
509
+ */
510
+ declare const DEFAULT_SCOPES: OAuthScope[];
511
+ /**
512
+ * OAuth configuration for a partner application.
513
+ *
514
+ * @category OAuth
515
+ */
516
+ interface OAuthConfig {
517
+ /** Partner API key */
518
+ apiKey: string;
519
+ /** Your application's callback URL */
520
+ redirectUri: string;
521
+ /** Vairified API base URL */
522
+ baseUrl?: string;
523
+ }
524
+ /**
525
+ * Response from starting an OAuth authorization.
526
+ *
527
+ * @category OAuth
528
+ */
529
+ interface AuthorizationResponse {
530
+ /** Full URL to redirect the user to */
531
+ authorizationUrl: string;
532
+ /** Authorization code (for internal tracking) */
533
+ code: string;
534
+ /** CSRF state parameter */
535
+ state?: string;
536
+ }
537
+ /**
538
+ * Response from exchanging an authorization code for tokens.
539
+ *
540
+ * @category OAuth
541
+ */
542
+ interface TokenResponse {
543
+ /** Access token for API requests */
544
+ accessToken: string;
545
+ /** Refresh token for obtaining new access tokens */
546
+ refreshToken?: string;
547
+ /** Token expiration in seconds */
548
+ expiresIn: number;
549
+ /** Granted scopes */
550
+ scope: string[];
551
+ /** Connected player's external ID */
552
+ playerId: string;
553
+ }
554
+ /**
555
+ * Build the URL to redirect users to for OAuth authorization.
556
+ *
557
+ * This is a helper for building the URL manually. In most cases,
558
+ * you should use the Vairified client's OAuth methods instead.
559
+ *
560
+ * @param config - OAuth configuration
561
+ * @param scopes - Permission scopes to request
562
+ * @param state - CSRF protection state parameter
563
+ * @returns URL to redirect the user to
564
+ *
565
+ * @example
566
+ * ```ts
567
+ * const url = getAuthorizationUrl(
568
+ * {
569
+ * apiKey: 'vair_pk_xxx',
570
+ * redirectUri: 'https://myapp.com/oauth/callback',
571
+ * },
572
+ * ['profile:read', 'rating:read'],
573
+ * );
574
+ * // Redirect user to this URL
575
+ * window.location.href = url;
576
+ * ```
577
+ *
578
+ * @category OAuth
579
+ */
580
+ declare function getAuthorizationUrl(config: OAuthConfig, scopes?: OAuthScope[], state?: string): string;
581
+ /**
582
+ * Check if a scope is valid.
583
+ *
584
+ * @param scope - Scope string to validate
585
+ * @returns True if scope is valid
586
+ *
587
+ * @category OAuth
588
+ */
589
+ declare function validateScope(scope: string): scope is OAuthScope;
590
+ /**
591
+ * Get a human-readable description of a scope.
592
+ *
593
+ * @param scope - Scope string
594
+ * @returns Description of what the scope grants access to
595
+ *
596
+ * @category OAuth
597
+ */
598
+ declare function describeScope(scope: OAuthScope): string;
599
+ /**
600
+ * Get descriptions for multiple scopes.
601
+ *
602
+ * @param scopes - List of scope strings
603
+ * @returns Array of objects with scope and description
604
+ *
605
+ * @category OAuth
606
+ */
607
+ declare function describeScopes(scopes: OAuthScope[]): Array<{
608
+ scope: OAuthScope;
609
+ description: string;
610
+ }>;
611
+ /**
612
+ * Generate a random state parameter for CSRF protection.
613
+ *
614
+ * @returns Random 32-character hexadecimal string
615
+ *
616
+ * @category OAuth
617
+ */
618
+ declare function generateState(): string;
619
+
620
+ /**
621
+ * Vairified SDK Client
622
+ *
623
+ * Main client for the Vairified Partner API.
624
+ *
625
+ * @module
626
+ */
627
+
628
+ declare const ENVIRONMENTS: {
629
+ readonly production: "https://api-next.vairified.com/api/v1";
630
+ readonly staging: "https://api-staging.vairified.com/api/v1";
631
+ readonly local: "http://localhost:3001/api/v1";
632
+ };
633
+ /**
634
+ * Available environment presets for the Vairified client.
635
+ *
636
+ * @category Client
637
+ */
638
+ type VairifiedEnvironment = keyof typeof ENVIRONMENTS;
639
+ /**
640
+ * Client for the Vairified Partner API.
641
+ *
642
+ * @category Client
643
+ *
644
+ * @example
645
+ * ```ts
646
+ * const client = new Vairified({ apiKey: 'vair_pk_xxx' });
647
+ *
648
+ * // Get a member
649
+ * const member = await client.getMember('user_123');
650
+ * console.log(member.name, member.rating);
651
+ *
652
+ * // Search for players
653
+ * const results = await client.search({ city: 'Austin', ratingMin: 4.0 });
654
+ * for (const player of results) {
655
+ * console.log(player.name, player.rating);
656
+ * }
657
+ *
658
+ * // Submit a match (doubles: 11-9, 11-7)
659
+ * const match = new Match({
660
+ * event: 'Weekly League',
661
+ * bracket: '4.0 Doubles',
662
+ * date: new Date(),
663
+ * team1: ['p1', 'p2'],
664
+ * team2: ['p3', 'p4'],
665
+ * scores: [[11, 9], [11, 7]],
666
+ * });
667
+ * const result = await client.submitMatch(match);
668
+ * if (result.ok) {
669
+ * console.log(`Submitted ${result.numGames} games`);
670
+ * }
671
+ * ```
672
+ *
673
+ * @remarks
674
+ * If your API key has the "dry-run" scope, match submissions will be
675
+ * validated but not persisted. This is useful for testing integrations.
676
+ */
677
+ declare class Vairified {
678
+ /** API key */
679
+ readonly apiKey: string;
680
+ /** Base URL */
681
+ readonly baseUrl: string;
682
+ /** Environment name */
683
+ readonly env: VairifiedEnvironment;
684
+ /** Request timeout in ms */
685
+ readonly timeout: number;
686
+ constructor(options?: VairifiedOptions);
687
+ private getEnvVar;
688
+ private getEnvApiKey;
689
+ private getHeaders;
690
+ private handleError;
691
+ private request;
692
+ /**
693
+ * Get a connected member by their external ID.
694
+ *
695
+ * **Requires OAuth Connection**: The player must have connected their
696
+ * account to your application via OAuth before you can access their data.
697
+ *
698
+ * @param playerId - External player ID (vair_mem_xxx format)
699
+ * @returns Member object with profile and rating data
700
+ * @throws NotFoundError if member is not found or invalid ID format
701
+ * @throws ForbiddenError if player has not connected to your app
702
+ *
703
+ * @example
704
+ * ```ts
705
+ * const member = await client.getMember('vair_mem_0ABC123def456GHI789jk');
706
+ * console.log(member.name, member.rating);
707
+ * console.log(member.ratingSplits.open); // Open division rating
708
+ * console.log(member.grantedScopes); // ['profile:read', 'rating:read']
709
+ * ```
710
+ */
711
+ getMember(playerId: string): Promise<Member>;
712
+ /**
713
+ * Search for players.
714
+ *
715
+ * @param filters - Search filters
716
+ * @returns SearchResults with players and pagination
717
+ *
718
+ * @example
719
+ * ```ts
720
+ * const results = await client.search({
721
+ * city: 'Austin',
722
+ * ratingMin: 4.0,
723
+ * vairifiedOnly: true,
724
+ * });
725
+ *
726
+ * for (const player of results) {
727
+ * console.log(player.name, player.rating);
728
+ * }
729
+ *
730
+ * // Pagination
731
+ * if (results.hasMore) {
732
+ * const nextPage = await results.nextPage();
733
+ * }
734
+ * ```
735
+ */
736
+ search(filters?: SearchFilters): Promise<SearchResults>;
737
+ /**
738
+ * Find a single player by name.
739
+ *
740
+ * @param name - Player name to search for
741
+ * @returns Player if found, undefined otherwise
742
+ *
743
+ * @example
744
+ * ```ts
745
+ * const player = await client.findPlayer('John Smith');
746
+ * if (player) {
747
+ * console.log(player.rating);
748
+ * }
749
+ * ```
750
+ */
751
+ findPlayer(name: string): Promise<Player | undefined>;
752
+ /**
753
+ * Submit a single match.
754
+ *
755
+ * @param match - Match object with teams and scores
756
+ * @returns MatchResult with submission status
757
+ *
758
+ * @example
759
+ * ```ts
760
+ * const match = new Match({
761
+ * event: 'Weekly League',
762
+ * bracket: '4.0 Doubles',
763
+ * date: new Date(),
764
+ * team1: ['p1', 'p2'],
765
+ * team2: ['p3', 'p4'],
766
+ * scores: [[11, 9], [11, 7]],
767
+ * });
768
+ *
769
+ * const result = await client.submitMatch(match);
770
+ * if (result.ok) {
771
+ * console.log(`Submitted ${result.numGames} games`);
772
+ * }
773
+ * ```
774
+ */
775
+ submitMatch(match: Match): Promise<MatchResult>;
776
+ /**
777
+ * Submit multiple matches in a batch.
778
+ *
779
+ * @param matches - List of Match objects
780
+ * @returns MatchResult with submission status
781
+ *
782
+ * @example
783
+ * ```ts
784
+ * const result = await client.submitMatches([match1, match2, match3]);
785
+ * console.log(`Submitted ${result.numGames} games from ${result.numMatches} matches`);
786
+ *
787
+ * if (result.dryRun) {
788
+ * console.log('This was a dry run - no data persisted');
789
+ * }
790
+ * ```
791
+ */
792
+ submitMatches(matches: Match[]): Promise<MatchResult>;
793
+ /**
794
+ * Get rating updates for subscribed members.
795
+ *
796
+ * Members are subscribed when you call getMember().
797
+ *
798
+ * @returns List of RatingUpdate objects
799
+ *
800
+ * @example
801
+ * ```ts
802
+ * const updates = await client.getRatingUpdates();
803
+ * for (const update of updates) {
804
+ * console.log(`${update.memberId}: ${update.previousRating} → ${update.newRating}`);
805
+ * if (update.improved) {
806
+ * const member = await update.getMember();
807
+ * console.log(`${member.name} improved!`);
808
+ * }
809
+ * }
810
+ * ```
811
+ */
812
+ getRatingUpdates(): Promise<RatingUpdate[]>;
813
+ /**
814
+ * Test webhook endpoint.
815
+ *
816
+ * @param webhookUrl - URL to send test webhook to
817
+ * @returns Test result
818
+ */
819
+ testWebhook(webhookUrl: string): Promise<Record<string, unknown>>;
820
+ /**
821
+ * Start an OAuth authorization flow.
822
+ *
823
+ * This creates a pending authorization and returns the URL where
824
+ * users should be redirected to approve access.
825
+ *
826
+ * @param redirectUri - Your application's callback URL
827
+ * @param scopes - Permission scopes to request (defaults to profile:read, rating:read)
828
+ * @param state - CSRF protection state parameter (recommended)
829
+ * @returns AuthorizationResponse with the URL to redirect users to
830
+ * @throws OAuthError if the authorization fails to start
831
+ *
832
+ * @example
833
+ * ```ts
834
+ * const auth = await client.startOAuth(
835
+ * 'https://myapp.com/callback',
836
+ * ['profile:read', 'rating:read', 'match:submit'],
837
+ * 'random_csrf_token',
838
+ * );
839
+ * // Redirect user to auth.authorizationUrl
840
+ * window.location.href = auth.authorizationUrl;
841
+ * ```
842
+ *
843
+ * @category OAuth
844
+ */
845
+ startOAuth(redirectUri: string, scopes?: OAuthScope[], state?: string): Promise<AuthorizationResponse>;
846
+ /**
847
+ * Exchange an authorization code for access and refresh tokens.
848
+ *
849
+ * Call this after the user approves access and is redirected back
850
+ * to your application with a code parameter.
851
+ *
852
+ * @param code - Authorization code from the callback URL
853
+ * @param redirectUri - Must match the redirectUri used in startOAuth
854
+ * @returns TokenResponse with access_token, refresh_token, and player_id
855
+ * @throws OAuthError if the code is invalid or expired
856
+ *
857
+ * @example
858
+ * ```ts
859
+ * // After user is redirected to: https://myapp.com/callback?code=xxx
860
+ * const tokens = await client.exchangeToken(
861
+ * new URL(window.location.href).searchParams.get('code')!,
862
+ * 'https://myapp.com/callback',
863
+ * );
864
+ * // Store tokens.accessToken and tokens.refreshToken securely
865
+ * // Use tokens.playerId to identify the connected player
866
+ * ```
867
+ *
868
+ * @category OAuth
869
+ */
870
+ exchangeToken(code: string, redirectUri: string): Promise<TokenResponse>;
871
+ /**
872
+ * Refresh an expired access token.
873
+ *
874
+ * Use this when an access token expires to obtain a new one
875
+ * without requiring the user to re-authorize.
876
+ *
877
+ * @param refreshToken - The refresh token from a previous token exchange
878
+ * @returns TokenResponse with new access_token and optionally a new refresh_token
879
+ * @throws OAuthError if the refresh token is invalid or revoked
880
+ *
881
+ * @example
882
+ * ```ts
883
+ * try {
884
+ * const newTokens = await client.refreshAccessToken(storedRefreshToken);
885
+ * // Update stored tokens
886
+ * } catch (e) {
887
+ * if (e instanceof OAuthError && e.errorCode === 'invalid_grant') {
888
+ * // Refresh token revoked, user needs to re-authorize
889
+ * }
890
+ * }
891
+ * ```
892
+ *
893
+ * @category OAuth
894
+ */
895
+ refreshAccessToken(refreshToken: string): Promise<TokenResponse>;
896
+ /**
897
+ * Revoke a player's OAuth connection.
898
+ *
899
+ * This disconnects the player from your application. You will no
900
+ * longer be able to access their data or submit matches on their behalf.
901
+ *
902
+ * @param playerId - The player's external ID (vair_mem_xxx format)
903
+ * @throws OAuthError if the revocation fails
904
+ *
905
+ * @example
906
+ * ```ts
907
+ * await client.revokeConnection('vair_mem_0ABC123def456GHI789jk');
908
+ * // Player is now disconnected
909
+ * ```
910
+ *
911
+ * @category OAuth
912
+ */
913
+ revokeConnection(playerId: string): Promise<void>;
914
+ /**
915
+ * Get a list of available OAuth scopes.
916
+ *
917
+ * @returns List of scope objects with id, name, and description
918
+ *
919
+ * @example
920
+ * ```ts
921
+ * const scopes = await client.getAvailableScopes();
922
+ * for (const scope of scopes) {
923
+ * console.log(`${scope.id}: ${scope.description}`);
924
+ * }
925
+ * ```
926
+ *
927
+ * @category OAuth
928
+ */
929
+ getAvailableScopes(): Promise<Array<{
930
+ id: string;
931
+ name: string;
932
+ description: string;
933
+ }>>;
934
+ /**
935
+ * Get API usage statistics for your partner account.
936
+ *
937
+ * @returns Usage statistics (requests, limits, etc.)
938
+ *
939
+ * @example
940
+ * ```ts
941
+ * const usage = await client.getUsage();
942
+ * console.log(`Requests today: ${usage.requestsToday}`);
943
+ * console.log(`Rate limit: ${usage.rateLimit}/hour`);
944
+ * ```
945
+ *
946
+ * @category Client
947
+ */
948
+ getUsage(): Promise<Record<string, unknown>>;
949
+ }
950
+
951
+ /**
952
+ * Vairified SDK Errors
953
+ *
954
+ * @module
955
+ */
956
+ /**
957
+ * Base error class for Vairified SDK errors.
958
+ *
959
+ * @category Errors
960
+ */
961
+ declare class VairifiedError extends Error {
962
+ /** HTTP status code */
963
+ statusCode?: number;
964
+ /** Response body */
965
+ response?: unknown;
966
+ constructor(message: string, statusCode?: number, response?: unknown);
967
+ }
968
+ /**
969
+ * Error thrown when API rate limit is exceeded.
970
+ *
971
+ * @category Errors
972
+ */
973
+ declare class RateLimitError extends VairifiedError {
974
+ /** Seconds to wait before retrying */
975
+ retryAfter?: number;
976
+ constructor(message?: string, retryAfter?: number, response?: unknown);
977
+ }
978
+ /**
979
+ * Error thrown when API key is invalid or missing.
980
+ *
981
+ * @category Errors
982
+ */
983
+ declare class AuthenticationError extends VairifiedError {
984
+ constructor(message?: string, response?: unknown);
985
+ }
986
+ /**
987
+ * Error thrown when a requested resource is not found.
988
+ *
989
+ * @category Errors
990
+ */
991
+ declare class NotFoundError extends VairifiedError {
992
+ constructor(message?: string, response?: unknown);
993
+ }
994
+ /**
995
+ * Error thrown when request validation fails.
996
+ *
997
+ * @category Errors
998
+ */
999
+ declare class ValidationError extends VairifiedError {
1000
+ constructor(message?: string, response?: unknown);
1001
+ }
1002
+ /**
1003
+ * Error thrown when an OAuth operation fails.
1004
+ *
1005
+ * This can occur during authorization, token exchange, refresh, or revocation.
1006
+ *
1007
+ * @category Errors
1008
+ */
1009
+ declare class OAuthError extends VairifiedError {
1010
+ /** OAuth error code (e.g., 'invalid_grant', 'expired_token') */
1011
+ errorCode?: string;
1012
+ constructor(message?: string, errorCode?: string, response?: unknown);
1013
+ }
1014
+
1015
+ export { AuthenticationError, type AuthorizationResponse, DEFAULT_SCOPES, Match, type MatchApiData, type MatchInput, MatchResult, type MatchResultData, Member, type MemberData, NotFoundError, type OAuthConfig, OAuthError, type OAuthScope, Player, type PlayerSearchData, RateLimitError, RatingSplit, type RatingSplitData, RatingSplits, type RatingSplitsData, RatingUpdate, type RatingUpdateData, SCOPES, type SearchFilters, SearchResults, type SearchResultsData, type TokenResponse, Vairified, type VairifiedEnvironment, VairifiedError, type VairifiedOptions, ValidationError, describeScope, describeScopes, generateState, getAuthorizationUrl, validateScope };