@rooguys/sdk 0.1.0 → 1.0.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/src/types.ts CHANGED
@@ -1,29 +1,77 @@
1
+ /**
2
+ * Rooguys Node.js SDK Type Definitions
3
+ */
4
+
5
+ // Re-export error types
6
+ export {
7
+ RooguysError,
8
+ ValidationError,
9
+ AuthenticationError,
10
+ ForbiddenError,
11
+ NotFoundError,
12
+ ConflictError,
13
+ RateLimitError,
14
+ ServerError,
15
+ FieldError,
16
+ RooguysErrorOptions,
17
+ ValidationErrorOptions,
18
+ RateLimitErrorOptions,
19
+ mapStatusToError,
20
+ } from './errors';
21
+
22
+ // Re-export HTTP client types
23
+ export {
24
+ RateLimitInfo,
25
+ CacheMetadata,
26
+ Pagination,
27
+ ApiResponse,
28
+ RequestConfig,
29
+ HttpClientOptions,
30
+ HttpClient,
31
+ extractRateLimitInfo,
32
+ extractRequestId,
33
+ parseResponseBody,
34
+ } from './http-client';
35
+
36
+ /**
37
+ * SDK initialization options
38
+ */
1
39
  export interface RooguysOptions {
40
+ /** Base URL for API (default: https://api.rooguys.com/v1) */
2
41
  baseUrl?: string;
42
+ /** Request timeout in ms (default: 10000) */
3
43
  timeout?: number;
44
+ /** Callback when rate limit is 80% consumed */
45
+ onRateLimitWarning?: ((rateLimit: import('./http-client').RateLimitInfo) => void) | null;
46
+ /** Enable auto-retry for rate-limited requests (default: false) */
47
+ autoRetry?: boolean;
48
+ /** Maximum retry attempts for rate limits (default: 3) */
49
+ maxRetries?: number;
4
50
  }
5
51
 
6
- export interface UserProfile {
7
- user_id: string;
8
- points: number;
9
- persona: string | null;
10
- level: {
11
- id: string;
12
- name: string;
13
- level_number: number;
14
- points_required: number;
15
- } | null;
16
- next_level: {
17
- id: string;
18
- name: string;
19
- level_number: number;
20
- points_required: number;
21
- points_needed: number;
22
- } | null;
23
- metrics: Record<string, any>;
24
- badges: UserBadge[];
52
+ /**
53
+ * Level information
54
+ */
55
+ export interface Level {
56
+ id: string;
57
+ name: string;
58
+ level_number: number;
59
+ points_required: number;
60
+ description?: string | null;
61
+ icon_url?: string | null;
62
+ created_at?: string;
63
+ }
64
+
65
+ /**
66
+ * Next level information with points needed
67
+ */
68
+ export interface NextLevel extends Level {
69
+ points_needed: number;
25
70
  }
26
71
 
72
+ /**
73
+ * User badge information
74
+ */
27
75
  export interface UserBadge {
28
76
  id: string;
29
77
  name: string;
@@ -32,109 +80,405 @@ export interface UserBadge {
32
80
  earned_at: string;
33
81
  }
34
82
 
83
+ /**
84
+ * Activity summary for user profile
85
+ */
86
+ export interface ActivitySummary {
87
+ lastEventAt: Date | null;
88
+ eventCount: number;
89
+ daysActive: number;
90
+ }
91
+
92
+ /**
93
+ * Streak information for user profile
94
+ */
95
+ export interface StreakInfo {
96
+ currentStreak: number;
97
+ longestStreak: number;
98
+ lastActivityAt: Date | null;
99
+ streakStartedAt: Date | null;
100
+ }
101
+
102
+ /**
103
+ * Inventory summary for user profile
104
+ */
105
+ export interface InventorySummary {
106
+ itemCount: number;
107
+ activeEffects: string[];
108
+ }
109
+
110
+ /**
111
+ * User profile data
112
+ */
113
+ export interface UserProfile {
114
+ user_id: string;
115
+ display_name?: string;
116
+ email?: string;
117
+ first_name?: string;
118
+ last_name?: string;
119
+ points: number;
120
+ persona: string | null;
121
+ persona_assigned_at?: string | null;
122
+ level: Level | null;
123
+ next_level: NextLevel | null;
124
+ metrics: Record<string, number>;
125
+ badges: UserBadge[];
126
+ metadata?: Record<string, unknown>;
127
+ /** Activity summary (parsed from activity_summary) */
128
+ activitySummary?: ActivitySummary;
129
+ /** Streak information (parsed from streak) */
130
+ streak?: StreakInfo;
131
+ /** Inventory summary (parsed from inventory) */
132
+ inventory?: InventorySummary;
133
+ created_at?: string;
134
+ updated_at?: string;
135
+ }
136
+
137
+ /**
138
+ * User rank information
139
+ */
35
140
  export interface UserRank {
36
141
  user_id: string;
37
142
  rank: number;
38
143
  points: number;
39
144
  total_users: number;
145
+ percentile?: number | null;
40
146
  }
41
147
 
148
+ /**
149
+ * Leaderboard entry
150
+ */
42
151
  export interface LeaderboardEntry {
43
152
  rank: number;
44
153
  user_id: string;
45
154
  points: number;
46
- level: {
155
+ level_name?: string;
156
+ level_number?: number;
157
+ level?: {
47
158
  id: string;
48
159
  name: string;
49
160
  level_number: number;
50
161
  } | null;
162
+ percentile?: number | null;
163
+ }
164
+
165
+ /**
166
+ * Leaderboard statistics
167
+ */
168
+ export interface LeaderboardStats {
169
+ total_participants: number;
170
+ average_score: number;
171
+ highest_score: number;
172
+ lowest_score: number;
51
173
  }
52
174
 
175
+ /**
176
+ * Leaderboard metadata
177
+ */
178
+ export interface LeaderboardMetadata {
179
+ id?: string;
180
+ name?: string;
181
+ description?: string;
182
+ type?: string;
183
+ timeframe?: string;
184
+ is_active?: boolean;
185
+ created_at?: string;
186
+ }
187
+
188
+ /**
189
+ * Cache metadata from leaderboard responses
190
+ */
191
+ export interface LeaderboardCacheMetadata {
192
+ cachedAt: Date | null;
193
+ ttl: number;
194
+ }
195
+
196
+ /**
197
+ * Leaderboard result
198
+ */
53
199
  export interface LeaderboardResult {
54
- timeframe: string;
200
+ timeframe?: string;
55
201
  page: number;
56
202
  limit: number;
57
203
  total: number;
58
204
  rankings: LeaderboardEntry[];
205
+ stats?: LeaderboardStats;
206
+ metadata?: LeaderboardMetadata;
207
+ cacheMetadata?: LeaderboardCacheMetadata;
208
+ }
209
+
210
+ /**
211
+ * Leaderboard filter options
212
+ */
213
+ export interface LeaderboardFilterOptions {
214
+ /** Page number */
215
+ page?: number;
216
+ /** Items per page */
217
+ limit?: number;
218
+ /** Search query */
219
+ search?: string;
220
+ /** Timeframe (all-time, weekly, monthly) */
221
+ timeframe?: 'all-time' | 'weekly' | 'monthly';
222
+ /** Filter by persona */
223
+ persona?: string;
224
+ /** Minimum level filter */
225
+ minLevel?: number;
226
+ /** Maximum level filter */
227
+ maxLevel?: number;
228
+ /** Start date filter (ISO 8601) */
229
+ startDate?: Date | string;
230
+ /** End date filter (ISO 8601) */
231
+ endDate?: Date | string;
59
232
  }
60
233
 
234
+ /**
235
+ * Around user response
236
+ */
237
+ export interface AroundUserResponse extends LeaderboardResult {
238
+ user_rank?: UserRank;
239
+ }
240
+
241
+ /**
242
+ * Track event response
243
+ */
61
244
  export interface TrackEventResponse {
62
245
  status: string;
63
246
  message: string;
64
247
  profile?: UserProfile;
65
248
  }
66
249
 
250
+ /**
251
+ * Track options
252
+ */
253
+ export interface TrackOptions {
254
+ /** Include user profile in response */
255
+ includeProfile?: boolean;
256
+ /** Custom timestamp for historical events (max 7 days old) */
257
+ timestamp?: Date | string;
258
+ /** Idempotency key to prevent duplicate processing */
259
+ idempotencyKey?: string;
260
+ }
261
+
262
+ /**
263
+ * Batch event item
264
+ */
265
+ export interface BatchEvent {
266
+ /** Event name */
267
+ eventName: string;
268
+ /** User ID */
269
+ userId: string;
270
+ /** Event properties */
271
+ properties?: Record<string, unknown>;
272
+ /** Custom timestamp for historical events */
273
+ timestamp?: Date | string;
274
+ }
275
+
276
+ /**
277
+ * Batch event result
278
+ */
279
+ export interface BatchEventResult {
280
+ index: number;
281
+ status: 'queued' | 'error';
282
+ error?: string;
283
+ }
284
+
285
+ /**
286
+ * Batch track response
287
+ */
288
+ export interface BatchTrackResponse {
289
+ results: BatchEventResult[];
290
+ requestId?: string;
291
+ }
292
+
293
+ /**
294
+ * Batch options
295
+ */
296
+ export interface BatchOptions {
297
+ /** Idempotency key for the batch */
298
+ idempotencyKey?: string;
299
+ }
300
+
301
+ /**
302
+ * Create user data
303
+ */
304
+ export interface CreateUserData {
305
+ /** Unique user ID */
306
+ userId: string;
307
+ /** Display name */
308
+ displayName?: string;
309
+ /** Email address */
310
+ email?: string;
311
+ /** First name */
312
+ firstName?: string;
313
+ /** Last name */
314
+ lastName?: string;
315
+ /** Custom metadata */
316
+ metadata?: Record<string, unknown>;
317
+ }
318
+
319
+ /**
320
+ * Update user data (partial update supported)
321
+ */
322
+ export interface UpdateUserData {
323
+ /** Display name */
324
+ displayName?: string;
325
+ /** Email address */
326
+ email?: string;
327
+ /** First name */
328
+ firstName?: string;
329
+ /** Last name */
330
+ lastName?: string;
331
+ /** Custom metadata */
332
+ metadata?: Record<string, unknown>;
333
+ }
334
+
335
+ /**
336
+ * Batch create user result
337
+ */
338
+ export interface BatchCreateUserResult {
339
+ index: number;
340
+ status: 'created' | 'error';
341
+ user_id?: string;
342
+ error?: string;
343
+ }
344
+
345
+ /**
346
+ * Batch create response
347
+ */
348
+ export interface BatchCreateResponse {
349
+ results: BatchCreateUserResult[];
350
+ }
351
+
352
+ /**
353
+ * Get user options
354
+ */
355
+ export interface GetUserOptions {
356
+ /** Fields to include in response */
357
+ fields?: string[];
358
+ }
359
+
360
+ /**
361
+ * Search options
362
+ */
363
+ export interface SearchOptions {
364
+ /** Page number */
365
+ page?: number;
366
+ /** Items per page */
367
+ limit?: number;
368
+ /** Fields to include in response */
369
+ fields?: string[];
370
+ }
371
+
372
+ /**
373
+ * Paginated response
374
+ */
375
+ export interface PaginatedResponse<T> {
376
+ page: number;
377
+ limit: number;
378
+ total: number;
379
+ totalPages?: number;
380
+ users?: T[];
381
+ items?: T[];
382
+ }
383
+
384
+ /**
385
+ * Answer submission
386
+ */
67
387
  export interface AnswerSubmission {
68
388
  question_id: string;
69
389
  answer_option_id: string;
70
390
  }
71
391
 
392
+ /**
393
+ * Aha declaration result
394
+ */
72
395
  export interface AhaDeclarationResult {
73
396
  success: boolean;
74
397
  message: string;
75
398
  }
76
399
 
400
+ /**
401
+ * Aha score history
402
+ */
403
+ export interface AhaScoreHistory {
404
+ initial: number | null;
405
+ initial_date: string | null;
406
+ previous: number | null;
407
+ }
408
+
409
+ /**
410
+ * Aha score data
411
+ */
412
+ export interface AhaScoreData {
413
+ user_id: string;
414
+ current_score: number;
415
+ declarative_score: number | null;
416
+ inferred_score: number | null;
417
+ status: 'not_started' | 'progressing' | 'activated';
418
+ history: AhaScoreHistory;
419
+ }
420
+
421
+ /**
422
+ * Aha score result
423
+ */
77
424
  export interface AhaScoreResult {
78
425
  success: boolean;
79
- data: {
80
- user_id: string;
81
- current_score: number;
82
- declarative_score: number | null;
83
- inferred_score: number | null;
84
- status: 'not_started' | 'progressing' | 'activated';
85
- history: {
86
- initial: number | null;
87
- initial_date: string | null;
88
- previous: number | null;
89
- };
90
- };
426
+ data: AhaScoreData;
91
427
  }
92
428
 
429
+ /**
430
+ * Badge definition
431
+ */
93
432
  export interface Badge {
94
433
  id: string;
95
434
  name: string;
96
435
  description: string;
97
436
  icon_url: string;
98
- points_required: number;
437
+ points_required?: number;
99
438
  is_active: boolean;
100
- unlock_criteria: string;
439
+ unlock_criteria?: string | Record<string, unknown>;
101
440
  created_at: string;
102
441
  }
103
442
 
443
+ /**
444
+ * Badge list result
445
+ */
104
446
  export interface BadgeListResult {
105
447
  badges: Badge[];
106
448
  pagination: {
107
449
  page: number;
108
450
  limit: number;
109
451
  total: number;
452
+ totalPages?: number;
110
453
  };
111
454
  }
112
455
 
113
- export interface Level {
114
- id: string;
115
- name: string;
116
- level_number: number;
117
- points_required: number;
118
- description: string | null;
119
- icon_url: string | null;
120
- created_at: string;
121
- }
122
-
456
+ /**
457
+ * Level list result
458
+ */
123
459
  export interface LevelListResult {
124
460
  levels: Level[];
125
461
  pagination: {
126
462
  page: number;
127
463
  limit: number;
128
464
  total: number;
465
+ totalPages?: number;
129
466
  };
130
467
  }
131
468
 
469
+ /**
470
+ * Question option
471
+ */
132
472
  export interface QuestionOption {
133
473
  id: string;
134
474
  text: string;
135
- persona_weight: Record<string, number>;
475
+ persona_weight?: Record<string, number>;
476
+ persona_weights?: Record<string, number>;
136
477
  }
137
478
 
479
+ /**
480
+ * Question
481
+ */
138
482
  export interface Question {
139
483
  id: string;
140
484
  text: string;
@@ -142,6 +486,9 @@ export interface Question {
142
486
  answer_options: QuestionOption[];
143
487
  }
144
488
 
489
+ /**
490
+ * Questionnaire
491
+ */
145
492
  export interface Questionnaire {
146
493
  id: string;
147
494
  slug: string;
@@ -152,14 +499,45 @@ export interface Questionnaire {
152
499
  created_at: string;
153
500
  }
154
501
 
502
+ /**
503
+ * Leaderboard definition
504
+ */
505
+ export interface LeaderboardDefinition {
506
+ id: string;
507
+ name: string;
508
+ description: string;
509
+ type?: string;
510
+ timeframe?: string;
511
+ is_active?: boolean;
512
+ created_at: string;
513
+ }
514
+
515
+ /**
516
+ * Leaderboard list result
517
+ */
155
518
  export interface LeaderboardListResult {
156
519
  page: number;
157
520
  limit: number;
158
521
  total: number;
159
- leaderboards: Array<{
160
- id: string;
161
- name: string;
162
- description: string;
163
- created_at: string;
522
+ leaderboards: LeaderboardDefinition[];
523
+ }
524
+
525
+ /**
526
+ * Health check response
527
+ */
528
+ export interface HealthCheckResponse {
529
+ status: string;
530
+ version?: string;
531
+ timestamp?: string;
532
+ services?: Record<string, {
533
+ status: string;
534
+ latency?: number;
164
535
  }>;
536
+ queue_depth?: number;
537
+ processing_lag?: number;
165
538
  }
539
+
540
+ /**
541
+ * Timeframe type
542
+ */
543
+ export type Timeframe = 'all-time' | 'weekly' | 'monthly';