@rooguys/sdk 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,311 @@
1
+ "use strict";
2
+ /**
3
+ * Mock API response fixtures for testing
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.mockErrors = exports.mockResponses = void 0;
7
+ exports.mockResponses = {
8
+ userProfile: {
9
+ user_id: 'user123',
10
+ points: 100,
11
+ persona: 'Achiever',
12
+ level: {
13
+ id: 'level1',
14
+ name: 'Bronze',
15
+ level_number: 1,
16
+ points_required: 0,
17
+ },
18
+ next_level: {
19
+ id: 'level2',
20
+ name: 'Silver',
21
+ level_number: 2,
22
+ points_required: 500,
23
+ points_needed: 400,
24
+ },
25
+ metrics: {
26
+ logins: 10,
27
+ purchases: 2,
28
+ },
29
+ badges: [
30
+ {
31
+ id: 'badge1',
32
+ name: 'First Steps',
33
+ description: 'Completed first action',
34
+ icon_url: 'https://example.com/badge1.png',
35
+ earned_at: '2024-01-01T00:00:00Z',
36
+ },
37
+ ],
38
+ },
39
+ trackEventResponse: {
40
+ status: 'queued',
41
+ message: 'Event accepted for processing',
42
+ },
43
+ trackEventWithProfileResponse: {
44
+ status: 'queued',
45
+ message: 'Event accepted for processing',
46
+ profile: {
47
+ user_id: 'user123',
48
+ points: 110,
49
+ persona: 'Achiever',
50
+ level: {
51
+ id: 'level1',
52
+ name: 'Bronze',
53
+ level_number: 1,
54
+ points_required: 0,
55
+ },
56
+ next_level: {
57
+ id: 'level2',
58
+ name: 'Silver',
59
+ level_number: 2,
60
+ points_required: 500,
61
+ points_needed: 390,
62
+ },
63
+ metrics: {},
64
+ badges: [],
65
+ },
66
+ },
67
+ leaderboardResponse: {
68
+ timeframe: 'all-time',
69
+ page: 1,
70
+ limit: 50,
71
+ total: 100,
72
+ rankings: [
73
+ {
74
+ rank: 1,
75
+ user_id: 'user1',
76
+ points: 1000,
77
+ level: {
78
+ id: 'level3',
79
+ name: 'Gold',
80
+ level_number: 3,
81
+ },
82
+ },
83
+ {
84
+ rank: 2,
85
+ user_id: 'user2',
86
+ points: 900,
87
+ level: {
88
+ id: 'level2',
89
+ name: 'Silver',
90
+ level_number: 2,
91
+ },
92
+ },
93
+ ],
94
+ },
95
+ userRankResponse: {
96
+ user_id: 'user123',
97
+ rank: 42,
98
+ points: 850,
99
+ total_users: 1000,
100
+ },
101
+ badgesListResponse: {
102
+ badges: [
103
+ {
104
+ id: 'badge1',
105
+ name: 'First Steps',
106
+ description: 'Completed first action',
107
+ icon_url: 'https://example.com/badge1.png',
108
+ is_active: true,
109
+ unlock_criteria: {
110
+ metric: 'actions',
111
+ value: 1,
112
+ },
113
+ },
114
+ ],
115
+ pagination: {
116
+ page: 1,
117
+ limit: 50,
118
+ total: 10,
119
+ totalPages: 1,
120
+ },
121
+ },
122
+ levelsListResponse: {
123
+ levels: [
124
+ {
125
+ id: 'level1',
126
+ name: 'Bronze',
127
+ level_number: 1,
128
+ points_required: 0,
129
+ description: 'Starting level',
130
+ icon_url: 'https://example.com/bronze.png',
131
+ },
132
+ {
133
+ id: 'level2',
134
+ name: 'Silver',
135
+ level_number: 2,
136
+ points_required: 500,
137
+ description: 'Intermediate level',
138
+ icon_url: 'https://example.com/silver.png',
139
+ },
140
+ ],
141
+ pagination: {
142
+ page: 1,
143
+ limit: 50,
144
+ total: 5,
145
+ totalPages: 1,
146
+ },
147
+ },
148
+ questionnaireResponse: {
149
+ id: 'questionnaire1',
150
+ slug: 'user-persona',
151
+ title: 'User Persona Quiz',
152
+ description: 'Determine your user persona',
153
+ is_active: true,
154
+ questions: [
155
+ {
156
+ id: 'q1',
157
+ text: 'What motivates you?',
158
+ order: 1,
159
+ answer_options: [
160
+ {
161
+ id: 'a1',
162
+ text: 'Competition',
163
+ persona_weights: { Competitor: 1 },
164
+ },
165
+ {
166
+ id: 'a2',
167
+ text: 'Exploration',
168
+ persona_weights: { Explorer: 1 },
169
+ },
170
+ ],
171
+ },
172
+ ],
173
+ },
174
+ bulkUsersResponse: {
175
+ users: [
176
+ {
177
+ user_id: 'user1',
178
+ points: 100,
179
+ persona: null,
180
+ level: null,
181
+ next_level: null,
182
+ metrics: {},
183
+ badges: [],
184
+ },
185
+ {
186
+ user_id: 'user2',
187
+ points: 200,
188
+ persona: 'Achiever',
189
+ level: {
190
+ id: 'level1',
191
+ name: 'Bronze',
192
+ level_number: 1,
193
+ points_required: 0,
194
+ },
195
+ next_level: null,
196
+ metrics: {},
197
+ badges: [],
198
+ },
199
+ ],
200
+ },
201
+ ahaScoreResponse: {
202
+ success: true,
203
+ data: {
204
+ user_id: 'user123',
205
+ current_score: 75,
206
+ declarative_score: 80,
207
+ inferred_score: 70,
208
+ status: 'activated',
209
+ history: {
210
+ initial: 50,
211
+ initial_date: '2024-01-01T00:00:00Z',
212
+ previous: 70,
213
+ },
214
+ },
215
+ },
216
+ ahaDeclarationResponse: {
217
+ success: true,
218
+ message: 'Declarative score recorded. Calculation in progress.',
219
+ },
220
+ answerSubmissionResponse: {
221
+ status: 'accepted',
222
+ message: 'Answers queued for processing',
223
+ },
224
+ leaderboardsListResponse: {
225
+ leaderboards: [
226
+ {
227
+ id: 'lb1',
228
+ name: 'Top Players',
229
+ description: 'Overall top players',
230
+ type: 'POINTS',
231
+ timeframe: 'all-time',
232
+ is_active: true,
233
+ created_at: '2024-01-01T00:00:00Z',
234
+ },
235
+ ],
236
+ pagination: {
237
+ page: 1,
238
+ limit: 50,
239
+ total: 5,
240
+ totalPages: 1,
241
+ },
242
+ },
243
+ customLeaderboardResponse: {
244
+ leaderboard: {
245
+ id: 'lb1',
246
+ name: 'Top Players',
247
+ description: 'Overall top players',
248
+ type: 'POINTS',
249
+ timeframe: 'all-time',
250
+ is_active: true,
251
+ created_at: '2024-01-01T00:00:00Z',
252
+ },
253
+ rankings: [
254
+ {
255
+ rank: 1,
256
+ user_id: 'user1',
257
+ points: 1000,
258
+ level: null,
259
+ },
260
+ ],
261
+ pagination: {
262
+ page: 1,
263
+ limit: 50,
264
+ total: 10,
265
+ totalPages: 1,
266
+ },
267
+ },
268
+ };
269
+ exports.mockErrors = {
270
+ validationError: {
271
+ error: 'Validation failed',
272
+ details: [
273
+ {
274
+ field: 'user_id',
275
+ message: 'User ID is required',
276
+ },
277
+ ],
278
+ },
279
+ notFoundError: {
280
+ error: 'User not found',
281
+ message: "User 'user123' does not exist in this project",
282
+ },
283
+ serverError: {
284
+ error: 'Internal server error',
285
+ },
286
+ queueFullError: {
287
+ error: 'Service unavailable',
288
+ message: 'Event queue is full. Please retry later.',
289
+ },
290
+ unauthorizedError: {
291
+ error: 'Unauthorized',
292
+ message: 'Invalid or missing API key',
293
+ },
294
+ invalidTimeframeError: {
295
+ error: 'Invalid timeframe',
296
+ message: "Timeframe must be one of: all-time, weekly, monthly",
297
+ },
298
+ invalidPaginationError: {
299
+ error: 'Invalid limit parameter',
300
+ message: 'Limit must be between 1 and 100',
301
+ },
302
+ ahaValueError: {
303
+ error: 'Validation failed',
304
+ details: [
305
+ {
306
+ field: 'value',
307
+ message: 'value must be an integer between 1 and 5',
308
+ },
309
+ ],
310
+ },
311
+ };
@@ -0,0 +1,28 @@
1
+ import fc from 'fast-check';
2
+ /**
3
+ * Property-based testing generators for SDK inputs
4
+ */
5
+ export declare const arbitraries: {
6
+ userId: () => fc.Arbitrary<string>;
7
+ eventName: () => fc.Arbitrary<string>;
8
+ properties: () => fc.Arbitrary<Record<string, string | number | boolean | null>>;
9
+ timeframe: () => fc.Arbitrary<string>;
10
+ pagination: () => fc.Arbitrary<{
11
+ page: number;
12
+ limit: number;
13
+ }>;
14
+ ahaValue: () => fc.Arbitrary<number>;
15
+ invalidAhaValue: () => fc.Arbitrary<number>;
16
+ uuid: () => fc.Arbitrary<string>;
17
+ slug: () => fc.Arbitrary<string>;
18
+ userIds: () => fc.Arbitrary<string[]>;
19
+ activeOnly: () => fc.Arbitrary<boolean>;
20
+ searchQuery: () => fc.Arbitrary<string | null>;
21
+ baseUrl: () => fc.Arbitrary<string>;
22
+ timeout: () => fc.Arbitrary<number>;
23
+ apiKey: () => fc.Arbitrary<string>;
24
+ questionnaireAnswers: () => fc.Arbitrary<{
25
+ question_id: string;
26
+ answer_option_id: string;
27
+ }[]>;
28
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.arbitraries = void 0;
7
+ const fast_check_1 = __importDefault(require("fast-check"));
8
+ /**
9
+ * Property-based testing generators for SDK inputs
10
+ */
11
+ exports.arbitraries = {
12
+ // User ID: 1-255 characters, alphanumeric with some special chars
13
+ userId: () => fast_check_1.default.string({ minLength: 1, maxLength: 255 }).filter(s => s.trim().length > 0),
14
+ // Event name: 1-100 characters
15
+ eventName: () => fast_check_1.default.string({ minLength: 1, maxLength: 100 }).filter(s => s.trim().length > 0),
16
+ // Properties: any JSON-serializable object
17
+ properties: () => fast_check_1.default.dictionary(fast_check_1.default.string({ minLength: 1, maxLength: 50 }), fast_check_1.default.oneof(fast_check_1.default.string(), fast_check_1.default.integer(), fast_check_1.default.double().filter(n => Number.isFinite(n)), // Exclude Infinity and NaN
18
+ fast_check_1.default.boolean(), fast_check_1.default.constant(null))),
19
+ // Timeframe: one of the valid values
20
+ timeframe: () => fast_check_1.default.constantFrom('all-time', 'weekly', 'monthly'),
21
+ // Pagination parameters
22
+ pagination: () => fast_check_1.default.record({
23
+ page: fast_check_1.default.integer({ min: 1, max: 1000 }),
24
+ limit: fast_check_1.default.integer({ min: 1, max: 100 }),
25
+ }),
26
+ // Aha score value: 1-5
27
+ ahaValue: () => fast_check_1.default.integer({ min: 1, max: 5 }),
28
+ // Invalid Aha score value: outside 1-5 range
29
+ invalidAhaValue: () => fast_check_1.default.oneof(fast_check_1.default.integer({ max: 0 }), fast_check_1.default.integer({ min: 6 })),
30
+ // UUID for leaderboard IDs
31
+ uuid: () => fast_check_1.default.uuid(),
32
+ // Slug for questionnaires
33
+ slug: () => fast_check_1.default.string({ minLength: 1, maxLength: 100 })
34
+ .filter(s => /^[a-z0-9-]+$/.test(s)),
35
+ // Array of user IDs for bulk operations
36
+ userIds: () => fast_check_1.default.array(fast_check_1.default.string({ minLength: 1, maxLength: 255 }), { minLength: 1, maxLength: 100 }),
37
+ // Boolean for active_only filter
38
+ activeOnly: () => fast_check_1.default.boolean(),
39
+ // Search query
40
+ searchQuery: () => fast_check_1.default.option(fast_check_1.default.string({ maxLength: 100 }), { nil: null }),
41
+ // Base URL
42
+ baseUrl: () => fast_check_1.default.webUrl(),
43
+ // Timeout in milliseconds
44
+ timeout: () => fast_check_1.default.integer({ min: 1000, max: 60000 }),
45
+ // API key
46
+ apiKey: () => fast_check_1.default.string({ minLength: 10, maxLength: 100 }),
47
+ // Questionnaire answers
48
+ questionnaireAnswers: () => fast_check_1.default.array(fast_check_1.default.record({
49
+ question_id: fast_check_1.default.uuid(),
50
+ answer_option_id: fast_check_1.default.uuid(),
51
+ }), { minLength: 1, maxLength: 20 }),
52
+ };
@@ -0,0 +1,22 @@
1
+ export interface MockAxiosInstance {
2
+ get: jest.Mock;
3
+ post: jest.Mock;
4
+ defaults: {
5
+ headers: {
6
+ common: Record<string, string>;
7
+ };
8
+ };
9
+ interceptors: {
10
+ request: {
11
+ use: jest.Mock;
12
+ };
13
+ response: {
14
+ use: jest.Mock;
15
+ };
16
+ };
17
+ }
18
+ export declare function createMockAxiosInstance(): MockAxiosInstance;
19
+ export declare function mockSuccessResponse<T>(data: T): {
20
+ data: T;
21
+ };
22
+ export declare function mockErrorResponse(status: number, message: string, details?: any): any;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createMockAxiosInstance = createMockAxiosInstance;
4
+ exports.mockSuccessResponse = mockSuccessResponse;
5
+ exports.mockErrorResponse = mockErrorResponse;
6
+ function createMockAxiosInstance() {
7
+ return {
8
+ get: jest.fn(),
9
+ post: jest.fn(),
10
+ defaults: {
11
+ headers: {
12
+ common: {},
13
+ },
14
+ },
15
+ interceptors: {
16
+ request: { use: jest.fn() },
17
+ response: { use: jest.fn() },
18
+ },
19
+ };
20
+ }
21
+ function mockSuccessResponse(data) {
22
+ return { data };
23
+ }
24
+ function mockErrorResponse(status, message, details) {
25
+ const error = new Error(message);
26
+ error.response = {
27
+ status,
28
+ data: {
29
+ error: message,
30
+ details,
31
+ },
32
+ };
33
+ error.isAxiosError = true;
34
+ return error;
35
+ }
@@ -0,0 +1,47 @@
1
+ import { RooguysOptions, TrackEventResponse, UserProfile, UserBadge, UserRank, LeaderboardResult, AnswerSubmission, AhaDeclarationResult, AhaScoreResult, BadgeListResult, LevelListResult, Questionnaire, LeaderboardListResult } from './types';
2
+ export declare class Rooguys {
3
+ private apiKey;
4
+ private client;
5
+ constructor(apiKey: string, options?: RooguysOptions);
6
+ events: {
7
+ track: (eventName: string, userId: string, properties?: Record<string, any>, options?: {
8
+ includeProfile?: boolean;
9
+ }) => Promise<TrackEventResponse>;
10
+ };
11
+ users: {
12
+ get: (userId: string) => Promise<UserProfile>;
13
+ getBulk: (userIds: string[]) => Promise<{
14
+ users: UserProfile[];
15
+ }>;
16
+ getBadges: (userId: string) => Promise<{
17
+ badges: UserBadge[];
18
+ }>;
19
+ getRank: (userId: string, timeframe?: "all-time" | "weekly" | "monthly") => Promise<UserRank>;
20
+ submitAnswers: (userId: string, questionnaireId: string, answers: AnswerSubmission[]) => Promise<{
21
+ status: string;
22
+ message: string;
23
+ }>;
24
+ };
25
+ leaderboards: {
26
+ getGlobal: (timeframe?: "all-time" | "weekly" | "monthly", page?: number, limit?: number) => Promise<LeaderboardResult>;
27
+ list: (page?: number, limit?: number, search?: string) => Promise<LeaderboardListResult>;
28
+ getCustom: (leaderboardId: string, page?: number, limit?: number, search?: string) => Promise<LeaderboardResult>;
29
+ getUserRank: (leaderboardId: string, userId: string) => Promise<UserRank>;
30
+ };
31
+ badges: {
32
+ list: (page?: number, limit?: number, activeOnly?: boolean) => Promise<BadgeListResult>;
33
+ };
34
+ levels: {
35
+ list: (page?: number, limit?: number) => Promise<LevelListResult>;
36
+ };
37
+ questionnaires: {
38
+ get: (slug: string) => Promise<Questionnaire>;
39
+ getActive: () => Promise<Questionnaire>;
40
+ };
41
+ aha: {
42
+ declare: (userId: string, value: number) => Promise<AhaDeclarationResult>;
43
+ getUserScore: (userId: string) => Promise<AhaScoreResult>;
44
+ };
45
+ private handleError;
46
+ }
47
+ export default Rooguys;