@scalemule/nextjs 0.0.1

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,807 @@
1
+ /**
2
+ * ScaleMule SDK Types
3
+ *
4
+ * These types mirror the ScaleMule API responses and requests.
5
+ */
6
+ type ScaleMuleEnvironment = 'dev' | 'prod';
7
+ interface ScaleMuleConfig {
8
+ /** Your ScaleMule API key */
9
+ apiKey: string;
10
+ /** Your ScaleMule Application ID (required for realtime features) */
11
+ applicationId?: string;
12
+ /** Environment: 'dev' or 'prod' - automatically sets gateway URL */
13
+ environment?: ScaleMuleEnvironment;
14
+ /** Custom gateway URL (overrides environment preset) */
15
+ gatewayUrl?: string;
16
+ /** Enable debug logging */
17
+ debug?: boolean;
18
+ /** Custom storage for session persistence (defaults to localStorage) */
19
+ storage?: StorageAdapter;
20
+ /**
21
+ * Proxy URL for analytics events (e.g., '/api/analytics' or '/api/t/e')
22
+ *
23
+ * When set, the SDK sends analytics events to this URL instead of directly
24
+ * to ScaleMule. Use this when you don't want to expose your API key in the
25
+ * browser. Your server-side route should use createAnalyticsRoutes() from
26
+ * '@scalemule/nextjs/server' to forward events to ScaleMule.
27
+ *
28
+ * @example
29
+ * // In your provider config:
30
+ * analyticsProxyUrl: '/api/analytics'
31
+ *
32
+ * // In your server route (app/api/analytics/[...path]/route.ts):
33
+ * import { createAnalyticsRoutes } from '@scalemule/nextjs/server'
34
+ * export const { POST } = createAnalyticsRoutes()
35
+ */
36
+ analyticsProxyUrl?: string;
37
+ /**
38
+ * Proxy URL for authentication operations (e.g., '/api/auth')
39
+ *
40
+ * When set, the SDK routes all auth calls (login, register, logout, etc.)
41
+ * through this URL instead of making direct browser requests to ScaleMule.
42
+ * This keeps the secret API key on the server and uses httpOnly cookies
43
+ * for session management.
44
+ *
45
+ * Your server-side route should handle auth operations using
46
+ * createServerClient() from '@scalemule/nextjs/server'.
47
+ *
48
+ * @example
49
+ * // In your provider config:
50
+ * authProxyUrl: '/api/auth'
51
+ *
52
+ * // In your server route (app/api/auth/[...path]/route.ts):
53
+ * // Handle register, login, logout, etc. using ScaleMule server client
54
+ */
55
+ authProxyUrl?: string;
56
+ /**
57
+ * Publishable API key for browser-safe operations (e.g., analytics)
58
+ *
59
+ * Publishable keys (sm_pb_*) are origin-locked and safe to expose in
60
+ * browser code. They have restricted access compared to secret keys.
61
+ *
62
+ * When set, the analytics hook uses this key for direct browser-to-API
63
+ * calls instead of going through the analytics proxy.
64
+ *
65
+ * @example
66
+ * publishableKey: 'sm_pb_production_a1b2c3d4...'
67
+ */
68
+ publishableKey?: string;
69
+ }
70
+ interface StorageAdapter {
71
+ getItem(key: string): string | null | Promise<string | null>;
72
+ setItem(key: string, value: string): void | Promise<void>;
73
+ removeItem(key: string): void | Promise<void>;
74
+ }
75
+ interface ApiResponse<T> {
76
+ success: boolean;
77
+ data?: T;
78
+ error?: ApiError;
79
+ }
80
+ interface ApiError {
81
+ code: string;
82
+ message: string;
83
+ field?: string;
84
+ }
85
+ interface User {
86
+ id: string;
87
+ email: string;
88
+ email_verified: boolean;
89
+ phone: string | null;
90
+ phone_verified: boolean;
91
+ full_name: string | null;
92
+ username: string | null;
93
+ avatar_url: string | null;
94
+ status: 'active' | 'suspended' | 'pending_verification';
95
+ created_at: string;
96
+ }
97
+ interface RegisterRequest {
98
+ email: string;
99
+ password: string;
100
+ full_name?: string;
101
+ username?: string;
102
+ phone?: string;
103
+ }
104
+ interface LoginRequest {
105
+ email: string;
106
+ password: string;
107
+ remember_me?: boolean;
108
+ device_fingerprint?: DeviceFingerprint;
109
+ }
110
+ interface DeviceFingerprint {
111
+ screen?: string;
112
+ timezone?: string;
113
+ language?: string;
114
+ platform?: string;
115
+ cookie_enabled?: boolean;
116
+ do_not_track?: string;
117
+ }
118
+ interface LoginResponse {
119
+ session_token: string;
120
+ user: User;
121
+ expires_at: string;
122
+ absolute_expires_at: string;
123
+ access_token?: string;
124
+ refresh_token?: string;
125
+ access_token_expires_in?: number;
126
+ device?: LoginDeviceInfo;
127
+ risk?: LoginRiskInfo;
128
+ }
129
+ interface LoginDeviceInfo {
130
+ id: string;
131
+ name: string;
132
+ trust_level: string;
133
+ is_new: boolean;
134
+ }
135
+ interface LoginRiskInfo {
136
+ score: number;
137
+ action: string;
138
+ factors: string[];
139
+ action_required?: boolean;
140
+ }
141
+ interface RefreshResponse {
142
+ session_token: string;
143
+ expires_at: string;
144
+ }
145
+ interface ForgotPasswordRequest {
146
+ email: string;
147
+ }
148
+ interface ResetPasswordRequest {
149
+ token: string;
150
+ new_password: string;
151
+ }
152
+ interface VerifyEmailRequest {
153
+ token: string;
154
+ }
155
+ interface ChangePasswordRequest {
156
+ current_password: string;
157
+ new_password: string;
158
+ }
159
+ interface ChangeEmailRequest {
160
+ new_email: string;
161
+ password: string;
162
+ }
163
+ type OAuthProvider = 'google' | 'apple' | 'github' | 'facebook' | 'twitter' | 'linkedin';
164
+ interface OAuthConfig {
165
+ /** OAuth provider */
166
+ provider: OAuthProvider;
167
+ /** URL to redirect to after OAuth completes */
168
+ redirectUrl?: string;
169
+ /** Additional scopes to request */
170
+ scopes?: string[];
171
+ /** State parameter for CSRF protection */
172
+ state?: string;
173
+ }
174
+ interface OAuthStartResponse {
175
+ /** URL to redirect user to for OAuth flow */
176
+ authorization_url: string;
177
+ /** State token for verification */
178
+ state: string;
179
+ }
180
+ interface OAuthCallbackRequest {
181
+ /** OAuth provider */
182
+ provider: OAuthProvider;
183
+ /** Authorization code from OAuth provider */
184
+ code: string;
185
+ /** State token for verification */
186
+ state: string;
187
+ }
188
+ interface OAuthCallbackResponse {
189
+ /** Session token for the authenticated user */
190
+ session_token: string;
191
+ /** The authenticated user */
192
+ user: User;
193
+ /** When the session expires */
194
+ expires_at: string;
195
+ /** Whether this is a new user (just registered via OAuth) */
196
+ is_new_user: boolean;
197
+ }
198
+ interface LinkedAccount {
199
+ provider: string;
200
+ provider_user_id: string;
201
+ provider_email?: string;
202
+ linked_at: string;
203
+ }
204
+ type MFAMethod = 'totp' | 'sms' | 'email';
205
+ interface MFASetupRequest {
206
+ method: MFAMethod;
207
+ /** Phone number for SMS (required if method is 'sms') */
208
+ phone?: string;
209
+ }
210
+ interface MFATOTPSetupResponse {
211
+ /** Secret key for TOTP */
212
+ secret: string;
213
+ /** QR code URI for authenticator apps (otpauth:// format) */
214
+ qr_code_uri: string;
215
+ /** Issuer name shown in authenticator app */
216
+ issuer: string;
217
+ /** Account name shown in authenticator app */
218
+ account_name: string;
219
+ }
220
+ interface MFASMSSetupResponse {
221
+ /** Whether setup was successful */
222
+ success: boolean;
223
+ /** Status message */
224
+ message: string;
225
+ /** Last digits of the phone number for display */
226
+ phone_last_digits: string;
227
+ }
228
+ interface MFAVerifyRequest {
229
+ /** The MFA code entered by user */
230
+ code: string;
231
+ /** MFA method being verified */
232
+ method: MFAMethod;
233
+ /** Whether this is during login challenge */
234
+ is_login_challenge?: boolean;
235
+ }
236
+ interface MFAChallengeResponse {
237
+ /** Challenge token for completing MFA */
238
+ challenge_token: string;
239
+ /** Available MFA methods for this user */
240
+ available_methods: MFAMethod[];
241
+ /** Hint for the method (e.g., last 4 digits of phone) */
242
+ hint?: string;
243
+ }
244
+ interface MFAStatus {
245
+ mfa_enabled: boolean;
246
+ mfa_method?: string;
247
+ totp_configured: boolean;
248
+ sms_configured: boolean;
249
+ email_configured: boolean;
250
+ backup_codes_remaining: number;
251
+ allowed_methods: string[];
252
+ mfa_required: boolean;
253
+ requirement_source: string;
254
+ }
255
+ interface LoginResponseWithMFA extends Omit<LoginResponse, 'session_token'> {
256
+ /** Whether MFA challenge is required */
257
+ requires_mfa: boolean;
258
+ /** MFA challenge details (if requires_mfa is true) */
259
+ mfa_challenge?: MFAChallengeResponse;
260
+ /** Session token (only present if MFA not required or already completed) */
261
+ session_token?: string;
262
+ }
263
+ interface PhoneSendCodeRequest {
264
+ /** Phone number in E.164 format */
265
+ phone: string;
266
+ /** Purpose of the code */
267
+ purpose: 'login' | 'verify' | 'register';
268
+ }
269
+ interface PhoneVerifyRequest {
270
+ /** Phone number in E.164 format */
271
+ phone: string;
272
+ /** Verification code from SMS */
273
+ code: string;
274
+ }
275
+ interface PhoneLoginRequest {
276
+ /** Phone number in E.164 format */
277
+ phone: string;
278
+ /** Verification code from SMS */
279
+ code: string;
280
+ /** Full name (required for new users) */
281
+ full_name?: string;
282
+ }
283
+ interface Session {
284
+ token: string;
285
+ userId: string;
286
+ expiresAt: Date;
287
+ }
288
+ /**
289
+ * Client context information to forward when making server-to-server calls
290
+ * on behalf of end users. This ensures that ScaleMule captures the actual
291
+ * end user's information instead of the server's information.
292
+ *
293
+ * Used primarily for uploads where tracking the uploader's IP, user agent,
294
+ * and device fingerprint is important for security (e.g., identifying bad actors).
295
+ */
296
+ interface ClientContext {
297
+ /** End user's IP address (from X-Forwarded-For or X-Real-IP) */
298
+ ip?: string;
299
+ /** End user's browser user agent */
300
+ userAgent?: string;
301
+ /** End user's device fingerprint (if collected) */
302
+ deviceFingerprint?: string;
303
+ /** HTTP Referer header (the page that linked to this one) */
304
+ referrer?: string;
305
+ }
306
+ interface StorageFile {
307
+ id: string;
308
+ filename: string;
309
+ content_type: string;
310
+ size_bytes: number;
311
+ is_public: boolean;
312
+ created_at: string;
313
+ scan_status?: string;
314
+ url?: string;
315
+ checksum?: string;
316
+ scanned_at?: string;
317
+ }
318
+ interface UploadOptions {
319
+ /** Make file publicly accessible */
320
+ is_public?: boolean;
321
+ /** Custom filename (defaults to original) */
322
+ filename?: string;
323
+ /** File category for organization */
324
+ category?: string;
325
+ /** Progress callback (0-100) */
326
+ onProgress?: (progress: number) => void;
327
+ }
328
+ interface ListFilesParams {
329
+ /** Filter by content type prefix (e.g., 'image/', 'video/') */
330
+ content_type?: string;
331
+ /** Search in filename */
332
+ search?: string;
333
+ /** Number of results (max 100) */
334
+ limit?: number;
335
+ /** Offset for pagination */
336
+ offset?: number;
337
+ }
338
+ interface ListFilesResponse {
339
+ files: StorageFile[];
340
+ total: number;
341
+ limit: number;
342
+ offset: number;
343
+ }
344
+ interface UploadResponse {
345
+ id: string;
346
+ filename: string;
347
+ content_type: string;
348
+ size_bytes: number;
349
+ url: string;
350
+ }
351
+ interface SignedUploadUrl {
352
+ upload_url: string;
353
+ file_id: string;
354
+ expires_at: string;
355
+ }
356
+ interface SignedUploadRequest {
357
+ /** Original filename */
358
+ filename: string;
359
+ /** MIME content type */
360
+ content_type: string;
361
+ /** File size in bytes */
362
+ size_bytes: number;
363
+ /** Make file publicly accessible */
364
+ is_public?: boolean;
365
+ }
366
+ interface SignedUploadResponse {
367
+ /** Pre-signed URL for direct upload */
368
+ upload_url: string;
369
+ /** File ID for reference */
370
+ file_id: string;
371
+ /** When the signed URL expires */
372
+ expires_at: string;
373
+ /** Headers to include in the upload request */
374
+ required_headers: Record<string, string>;
375
+ }
376
+ interface SignedUploadCompleteRequest {
377
+ /** File ID from signed upload response */
378
+ file_id: string;
379
+ }
380
+ interface UpdateProfileRequest {
381
+ full_name?: string;
382
+ username?: string;
383
+ avatar_url?: string;
384
+ }
385
+ interface Profile extends User {
386
+ }
387
+ interface UseAuthReturn {
388
+ /** Current user or null if not logged in */
389
+ user: User | null;
390
+ /** True while loading initial auth state */
391
+ loading: boolean;
392
+ /** True if user is authenticated */
393
+ isAuthenticated: boolean;
394
+ /** Last auth error */
395
+ error: ApiError | null;
396
+ /** Register a new user */
397
+ register: (data: RegisterRequest) => Promise<User>;
398
+ /** Login with email/password (may return MFA challenge) */
399
+ login: (data: LoginRequest) => Promise<LoginResponse | LoginResponseWithMFA>;
400
+ /** Logout current user */
401
+ logout: () => Promise<void>;
402
+ /** Request password reset email */
403
+ forgotPassword: (email: string) => Promise<void>;
404
+ /** Reset password with token */
405
+ resetPassword: (token: string, newPassword: string) => Promise<void>;
406
+ /** Verify email with token */
407
+ verifyEmail: (token: string) => Promise<void>;
408
+ /** Resend verification email */
409
+ resendVerification: () => Promise<void>;
410
+ /** Refresh session token */
411
+ refreshSession: () => Promise<void>;
412
+ /** Start OAuth flow for a provider */
413
+ startOAuth: (config: OAuthConfig) => Promise<OAuthStartResponse>;
414
+ /** Complete OAuth flow after redirect */
415
+ completeOAuth: (request: OAuthCallbackRequest) => Promise<OAuthCallbackResponse>;
416
+ /** Get list of linked OAuth accounts */
417
+ getLinkedAccounts: () => Promise<LinkedAccount[]>;
418
+ /** Link a new OAuth account */
419
+ linkAccount: (config: OAuthConfig) => Promise<OAuthStartResponse>;
420
+ /** Unlink an OAuth account */
421
+ unlinkAccount: (provider: OAuthProvider) => Promise<void>;
422
+ /** Get current MFA status */
423
+ getMFAStatus: () => Promise<MFAStatus>;
424
+ /** Start MFA setup for a method */
425
+ setupMFA: (request: MFASetupRequest) => Promise<MFATOTPSetupResponse | MFASMSSetupResponse>;
426
+ /** Verify and enable MFA */
427
+ verifyMFA: (request: MFAVerifyRequest) => Promise<void>;
428
+ /** Complete MFA challenge during login */
429
+ completeMFAChallenge: (challengeToken: string, code: string, method: MFAMethod) => Promise<LoginResponse>;
430
+ /** Disable MFA */
431
+ disableMFA: (password: string) => Promise<void>;
432
+ /** Regenerate backup codes */
433
+ regenerateBackupCodes: (password: string) => Promise<string[]>;
434
+ /** Send verification code to phone */
435
+ sendPhoneCode: (request: PhoneSendCodeRequest) => Promise<void>;
436
+ /** Verify phone number */
437
+ verifyPhone: (request: PhoneVerifyRequest) => Promise<void>;
438
+ /** Login with phone number */
439
+ loginWithPhone: (request: PhoneLoginRequest) => Promise<LoginResponse>;
440
+ }
441
+ interface UseContentReturn {
442
+ /** User's files */
443
+ files: StorageFile[];
444
+ /** True while loading */
445
+ loading: boolean;
446
+ /** Upload progress (0-100) when upload is in progress */
447
+ uploadProgress: number | null;
448
+ /** Last error */
449
+ error: ApiError | null;
450
+ /** Upload a file (direct upload through SDK) */
451
+ upload: (file: File, options?: UploadOptions) => Promise<UploadResponse>;
452
+ /** List user's files */
453
+ list: (params?: ListFilesParams) => Promise<ListFilesResponse>;
454
+ /** Delete a file */
455
+ remove: (fileId: string) => Promise<void>;
456
+ /** Get a single file's info */
457
+ get: (fileId: string) => Promise<StorageFile>;
458
+ /** Refresh the file list */
459
+ refresh: () => Promise<void>;
460
+ /** Get a signed URL for direct upload (bypasses SDK, uploads directly to storage) */
461
+ getSignedUploadUrl: (request: SignedUploadRequest) => Promise<SignedUploadResponse>;
462
+ /** Upload file directly to signed URL (call this yourself with fetch/xhr) */
463
+ uploadToSignedUrl: (signedUrl: string, file: File, headers: Record<string, string>, onProgress?: (progress: number) => void) => Promise<void>;
464
+ /** Mark signed upload as complete */
465
+ completeSignedUpload: (fileId: string) => Promise<StorageFile>;
466
+ }
467
+ interface UseUserReturn {
468
+ /** Current user profile */
469
+ profile: Profile | null;
470
+ /** True while loading */
471
+ loading: boolean;
472
+ /** Last error */
473
+ error: ApiError | null;
474
+ /** Update profile */
475
+ update: (data: UpdateProfileRequest) => Promise<Profile>;
476
+ /** Change password */
477
+ changePassword: (currentPassword: string, newPassword: string) => Promise<void>;
478
+ /** Change email */
479
+ changeEmail: (newEmail: string, password: string) => Promise<void>;
480
+ /** Delete account */
481
+ deleteAccount: (password: string) => Promise<void>;
482
+ /** Request data export */
483
+ exportData: () => Promise<{
484
+ download_url: string;
485
+ }>;
486
+ }
487
+ /**
488
+ * Analytics event to track
489
+ */
490
+ interface AnalyticsEvent {
491
+ /** Event name (e.g., 'page_viewed', 'button_clicked', 'purchase_completed') */
492
+ event_name: string;
493
+ /** Event category for grouping (e.g., 'engagement', 'conversion', 'navigation') */
494
+ event_category?: string;
495
+ /** Additional event properties as key-value pairs */
496
+ properties?: Record<string, unknown>;
497
+ /** User ID to associate with event (auto-filled if user is logged in) */
498
+ user_id?: string;
499
+ /** Session ID for tracking user journey (auto-generated if not provided) */
500
+ session_id?: string;
501
+ /** Anonymous ID for tracking before login (auto-generated if not provided) */
502
+ anonymous_id?: string;
503
+ /** Client timestamp (auto-filled if not provided) */
504
+ client_timestamp?: string;
505
+ /** Session duration in seconds at event time (auto-filled) */
506
+ session_duration_seconds?: number;
507
+ }
508
+ /**
509
+ * Page view event data
510
+ */
511
+ interface PageViewData {
512
+ /** Page URL (auto-filled from window.location if not provided) */
513
+ page_url?: string;
514
+ /** Page title (auto-filled from document.title if not provided) */
515
+ page_title?: string;
516
+ /** Referrer URL (auto-filled from document.referrer if not provided) */
517
+ referrer?: string;
518
+ /** Additional properties */
519
+ properties?: Record<string, unknown>;
520
+ }
521
+ /**
522
+ * UTM parameters for campaign tracking
523
+ */
524
+ interface UTMParams {
525
+ /** Traffic source (e.g., 'google', 'newsletter', 'facebook') */
526
+ utm_source?: string;
527
+ /** Marketing medium (e.g., 'cpc', 'email', 'social') */
528
+ utm_medium?: string;
529
+ /** Campaign name */
530
+ utm_campaign?: string;
531
+ /** Search term for paid search */
532
+ utm_term?: string;
533
+ /** Content identifier for A/B testing */
534
+ utm_content?: string;
535
+ }
536
+ /**
537
+ * Device information for analytics
538
+ */
539
+ interface DeviceInfo {
540
+ /** Device type (mobile, tablet, desktop) */
541
+ device_type?: string;
542
+ /** Device brand (Apple, Samsung, etc.) */
543
+ device_brand?: string;
544
+ /** Device model */
545
+ device_model?: string;
546
+ /** Operating system */
547
+ os?: string;
548
+ /** OS version */
549
+ os_version?: string;
550
+ /** Browser name */
551
+ browser?: string;
552
+ /** Browser version */
553
+ browser_version?: string;
554
+ /** Screen resolution (e.g., '1920x1080') */
555
+ screen_resolution?: string;
556
+ /** Viewport size (e.g., '1200x800') */
557
+ viewport_size?: string;
558
+ }
559
+ /**
560
+ * Enhanced event with all tracking data
561
+ */
562
+ interface EnhancedAnalyticsEvent extends AnalyticsEvent {
563
+ /** UTM campaign parameters */
564
+ utm?: UTMParams;
565
+ /** Device information */
566
+ device?: DeviceInfo;
567
+ /** Page URL */
568
+ page_url?: string;
569
+ /** Page title */
570
+ page_title?: string;
571
+ /** Landing page URL (first page user visited) */
572
+ landing_page?: string;
573
+ }
574
+ /**
575
+ * Track event response
576
+ */
577
+ interface TrackEventResponse {
578
+ /** Number of events tracked */
579
+ tracked: number;
580
+ /** Event ID (for v2 events) */
581
+ event_id?: string;
582
+ /** Session ID */
583
+ session_id?: string;
584
+ }
585
+ /**
586
+ * Batch track request
587
+ */
588
+ interface BatchTrackRequest {
589
+ /** Array of events to track */
590
+ events: AnalyticsEvent[];
591
+ }
592
+ /**
593
+ * Options for analytics hook
594
+ */
595
+ interface UseAnalyticsOptions {
596
+ /** Auto-track page views on route changes (default: true) */
597
+ autoTrackPageViews?: boolean;
598
+ /** Auto-capture UTM params from URL (default: true) */
599
+ autoCaptureUtmParams?: boolean;
600
+ /** @deprecated Typo kept for backward compatibility. Use autoCaptureUtmParams. */
601
+ autoCapturUtmParams?: boolean;
602
+ /** Auto-generate session ID (default: true) */
603
+ autoGenerateSessionId?: boolean;
604
+ /** Session ID storage key (default: 'sm_session_id') */
605
+ sessionStorageKey?: string;
606
+ /** Anonymous ID storage key (default: 'sm_anonymous_id') */
607
+ anonymousStorageKey?: string;
608
+ /** Use v2 enhanced tracking (default: true) */
609
+ useV2?: boolean;
610
+ }
611
+ /**
612
+ * Analytics hook return type
613
+ */
614
+ interface UseAnalyticsReturn {
615
+ /** True while an analytics operation is in progress */
616
+ loading: boolean;
617
+ /** Last error from analytics operations */
618
+ error: ApiError | null;
619
+ /** Current session ID */
620
+ sessionId: string | null;
621
+ /** Current anonymous ID */
622
+ anonymousId: string | null;
623
+ /** Stored UTM parameters from URL */
624
+ utmParams: UTMParams | null;
625
+ /**
626
+ * Track a custom event
627
+ * @param event - Event data to track
628
+ * @returns Promise with track response
629
+ * @example
630
+ * ```tsx
631
+ * await trackEvent({
632
+ * event_name: 'button_clicked',
633
+ * event_category: 'engagement',
634
+ * properties: { button_id: 'signup', location: 'header' }
635
+ * })
636
+ * ```
637
+ */
638
+ trackEvent: (event: AnalyticsEvent) => Promise<TrackEventResponse>;
639
+ /**
640
+ * Track a page view
641
+ * @param data - Optional page view data (auto-filled from browser if not provided)
642
+ * @example
643
+ * ```tsx
644
+ * // Auto-detect page info
645
+ * await trackPageView()
646
+ *
647
+ * // Custom page info
648
+ * await trackPageView({
649
+ * page_url: '/checkout',
650
+ * page_title: 'Checkout',
651
+ * properties: { cart_value: 99.99 }
652
+ * })
653
+ * ```
654
+ */
655
+ trackPageView: (data?: PageViewData) => Promise<TrackEventResponse>;
656
+ /**
657
+ * Track multiple events in a batch
658
+ * @param events - Array of events to track
659
+ * @example
660
+ * ```tsx
661
+ * await trackBatch([
662
+ * { event_name: 'item_added', properties: { item_id: '123' } },
663
+ * { event_name: 'cart_updated', properties: { total: 49.99 } }
664
+ * ])
665
+ * ```
666
+ */
667
+ trackBatch: (events: AnalyticsEvent[]) => Promise<TrackEventResponse>;
668
+ /**
669
+ * Identify user for analytics (call after login)
670
+ * Merges anonymous activity with user profile
671
+ * @param userId - User ID to associate with events
672
+ * @param traits - Optional user traits
673
+ */
674
+ identify: (userId: string, traits?: Record<string, unknown>) => Promise<void>;
675
+ /**
676
+ * Reset analytics session (call on logout)
677
+ * Clears user association but keeps anonymous ID
678
+ */
679
+ reset: () => void;
680
+ /**
681
+ * Set UTM parameters manually (auto-captured from URL by default)
682
+ */
683
+ setUtmParams: (params: UTMParams) => void;
684
+ /**
685
+ * Get device info for current browser/device
686
+ */
687
+ getDeviceInfo: () => DeviceInfo;
688
+ }
689
+ interface ConnectedAccount {
690
+ id: string;
691
+ email: string;
692
+ country: string;
693
+ status: 'pending' | 'onboarding' | 'active' | 'restricted' | 'disabled';
694
+ charges_enabled: boolean;
695
+ payouts_enabled: boolean;
696
+ onboarding_complete: boolean;
697
+ details_submitted: boolean;
698
+ metadata?: Record<string, unknown>;
699
+ created_at: string;
700
+ updated_at: string;
701
+ }
702
+ interface AccountBalance {
703
+ currency: string;
704
+ available_cents: number;
705
+ pending_cents: number;
706
+ reserved_cents: number;
707
+ }
708
+ interface BillingPayment {
709
+ id: string;
710
+ customer_id: string;
711
+ connected_account_id?: string;
712
+ amount_cents: number;
713
+ currency: string;
714
+ platform_fee_cents: number;
715
+ provider_fee_cents: number;
716
+ creator_net_cents: number;
717
+ status: string;
718
+ payment_type?: string;
719
+ client_secret?: string;
720
+ metadata?: Record<string, unknown>;
721
+ created_at: string;
722
+ }
723
+ interface BillingRefund {
724
+ id: string;
725
+ payment_id: string;
726
+ amount_cents: number;
727
+ platform_fee_reversal_cents: number;
728
+ reason?: string;
729
+ status: string;
730
+ created_at: string;
731
+ }
732
+ interface BillingPayout {
733
+ id: string;
734
+ amount_cents: number;
735
+ currency: string;
736
+ status: string;
737
+ arrival_date?: string;
738
+ created_at: string;
739
+ }
740
+ interface PayoutSchedule {
741
+ schedule_interval: string;
742
+ minimum_amount_cents: number;
743
+ day_of_week?: number;
744
+ day_of_month?: number;
745
+ }
746
+ interface BillingTransaction {
747
+ id: string;
748
+ entry_type: string;
749
+ account_type: string;
750
+ amount_cents: number;
751
+ currency: string;
752
+ category: string;
753
+ reference_type: string;
754
+ description?: string;
755
+ created_at: string;
756
+ }
757
+ interface TransactionSummary {
758
+ gross_cents: number;
759
+ platform_fee_cents: number;
760
+ net_cents: number;
761
+ payout_cents: number;
762
+ refund_cents: number;
763
+ }
764
+ interface UseBillingReturn {
765
+ loading: boolean;
766
+ error: ApiError | null;
767
+ createConnectedAccount: (data: {
768
+ email: string;
769
+ country?: string;
770
+ }) => Promise<ConnectedAccount | null>;
771
+ getMyConnectedAccount: () => Promise<ConnectedAccount | null>;
772
+ getConnectedAccount: (id: string) => Promise<ConnectedAccount | null>;
773
+ createOnboardingLink: (id: string, data: {
774
+ return_url: string;
775
+ refresh_url: string;
776
+ }) => Promise<string | null>;
777
+ getAccountBalance: (id: string) => Promise<AccountBalance | null>;
778
+ createPayment: (data: {
779
+ amount_cents: number;
780
+ currency?: string;
781
+ connected_account_id?: string;
782
+ platform_fee_percent?: number;
783
+ platform_fee_cents?: number;
784
+ payment_type?: string;
785
+ metadata?: Record<string, unknown>;
786
+ }) => Promise<BillingPayment | null>;
787
+ getPayment: (id: string) => Promise<BillingPayment | null>;
788
+ listPayments: (params?: Record<string, unknown>) => Promise<BillingPayment[]>;
789
+ refundPayment: (id: string, data?: {
790
+ amount_cents?: number;
791
+ reason?: string;
792
+ }) => Promise<BillingRefund | null>;
793
+ getPayoutHistory: (accountId: string, params?: Record<string, unknown>) => Promise<BillingPayout[]>;
794
+ getPayoutSchedule: (accountId: string) => Promise<PayoutSchedule | null>;
795
+ setPayoutSchedule: (accountId: string, data: {
796
+ schedule_interval: string;
797
+ minimum_amount_cents?: number;
798
+ }) => Promise<PayoutSchedule | null>;
799
+ getTransactions: (params?: Record<string, unknown>) => Promise<BillingTransaction[]>;
800
+ getTransactionSummary: (params?: Record<string, unknown>) => Promise<TransactionSummary | null>;
801
+ createSetupSession: (data: {
802
+ return_url: string;
803
+ cancel_url: string;
804
+ }) => Promise<string | null>;
805
+ }
806
+
807
+ export type { UpdateProfileRequest as $, ApiError as A, MFAVerifyRequest as B, ChangePasswordRequest as C, DeviceFingerprint as D, MFAChallengeResponse as E, ForgotPasswordRequest as F, MFAStatus as G, PhoneSendCodeRequest as H, PhoneVerifyRequest as I, PhoneLoginRequest as J, StorageFile as K, LoginResponse as L, MFAMethod as M, UploadOptions as N, OAuthProvider as O, Profile as P, ListFilesResponse as Q, RegisterRequest as R, ScaleMuleConfig as S, UploadResponse as T, User as U, VerifyEmailRequest as V, SignedUploadUrl as W, SignedUploadRequest as X, SignedUploadResponse as Y, SignedUploadCompleteRequest as Z, ClientContext as _, UseAuthReturn as a, ConnectedAccount as a0, AccountBalance as a1, BillingPayment as a2, BillingRefund as a3, BillingPayout as a4, PayoutSchedule as a5, BillingTransaction as a6, TransactionSummary as a7, AnalyticsEvent as a8, PageViewData as a9, UTMParams as aa, DeviceInfo as ab, EnhancedAnalyticsEvent as ac, TrackEventResponse as ad, BatchTrackRequest as ae, UseBillingReturn as b, ListFilesParams as c, UseContentReturn as d, UseUserReturn as e, UseAnalyticsOptions as f, UseAnalyticsReturn as g, ScaleMuleEnvironment as h, StorageAdapter as i, ApiResponse as j, LoginRequest as k, LoginResponseWithMFA as l, LoginDeviceInfo as m, LoginRiskInfo as n, RefreshResponse as o, ResetPasswordRequest as p, ChangeEmailRequest as q, Session as r, OAuthConfig as s, OAuthStartResponse as t, OAuthCallbackRequest as u, OAuthCallbackResponse as v, LinkedAccount as w, MFASetupRequest as x, MFATOTPSetupResponse as y, MFASMSSetupResponse as z };