@scalemule/nextjs 0.1.27 → 0.1.29

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.
@@ -1,923 +0,0 @@
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
- * Endpoint to ship SDK error logs to (fire-and-forget POST).
58
- *
59
- * When set, every non-2xx response from the auth proxy (and any other
60
- * SDK call that throws a ScaleMuleApiError) will be reported to this
61
- * URL as a structured log entry, alongside the regular setError() and
62
- * thrown ScaleMuleApiError. This makes API failures visible in your
63
- * platform's error logger even when the calling code catches the
64
- * error and surfaces a UI message — the case the global window.onerror
65
- * / unhandledrejection / React error-boundary collectors all miss by
66
- * design.
67
- *
68
- * Recommended value: '/api/telemetry/errors' (the same endpoint your
69
- * host-app's client-side error collector already POSTs to). The body
70
- * shape matches what `createTelemetryRoutes()` expects:
71
- * `{ logs: [{ message, metadata, timestamp }] }`.
72
- *
73
- * @example
74
- * telemetryEndpoint: '/api/telemetry/errors'
75
- */
76
- telemetryEndpoint?: string;
77
- /**
78
- * Publishable API key for browser-safe operations (e.g., analytics)
79
- *
80
- * Publishable keys (sm_pb_*) are origin-locked and safe to expose in
81
- * browser code. They have restricted access compared to secret keys.
82
- *
83
- * When set, the analytics hook uses this key for direct browser-to-API
84
- * calls instead of going through the analytics proxy.
85
- *
86
- * @example
87
- * publishableKey: 'sm_pb_production_a1b2c3d4...'
88
- */
89
- publishableKey?: string;
90
- /**
91
- * Enable the account switcher — remembers which accounts have logged in on
92
- * this device so users can pick an account and re-authenticate.
93
- *
94
- * Stores only display metadata (email, name, avatar) — no tokens.
95
- * Switching accounts always requires re-authentication.
96
- *
97
- * When using auth proxy mode, this works via a non-httpOnly cookie.
98
- * The server route config must also have `enableAccountSwitcher: true`.
99
- *
100
- * Default: false
101
- */
102
- enableAccountSwitcher?: boolean;
103
- /**
104
- * Privacy level for account switcher display metadata.
105
- *
106
- * - 'full': Store email, name, avatar as-is (default)
107
- * - 'masked': Mask email (j***@g***.com), truncate name to initial
108
- * - 'minimal': No PII at all — just a colored "Account" label
109
- *
110
- * Applies to both server-side cookie writes and client-side reads.
111
- */
112
- accountSwitcherPrivacy?: 'full' | 'masked' | 'minimal';
113
- }
114
- interface StorageAdapter {
115
- getItem(key: string): string | null | Promise<string | null>;
116
- setItem(key: string, value: string): void | Promise<void>;
117
- removeItem(key: string): void | Promise<void>;
118
- }
119
- declare class ScaleMuleApiError extends Error {
120
- code: string;
121
- status?: number;
122
- field?: string;
123
- details?: unknown;
124
- constructor(error: ApiError, status?: number);
125
- }
126
- interface ApiResponse<T> {
127
- success: boolean;
128
- data?: T;
129
- error?: ApiError;
130
- }
131
- interface ApiError {
132
- code: string;
133
- message: string;
134
- field?: string;
135
- }
136
- interface User {
137
- id: string;
138
- email: string;
139
- email_verified: boolean;
140
- phone: string | null;
141
- phone_verified: boolean;
142
- full_name: string | null;
143
- username: string | null;
144
- avatar_url: string | null;
145
- status: 'active' | 'suspended' | 'pending_verification';
146
- created_at: string;
147
- }
148
- interface RegisterRequest {
149
- email: string;
150
- password: string;
151
- full_name?: string;
152
- username?: string;
153
- phone?: string;
154
- }
155
- interface LoginRequest {
156
- email: string;
157
- password: string;
158
- remember_me?: boolean;
159
- device_fingerprint?: DeviceFingerprint;
160
- }
161
- interface DeviceFingerprint {
162
- screen?: string;
163
- timezone?: string;
164
- language?: string;
165
- platform?: string;
166
- cookie_enabled?: boolean;
167
- do_not_track?: string;
168
- }
169
- interface LoginResponse {
170
- session_token: string;
171
- user: User;
172
- expires_at: string;
173
- absolute_expires_at: string;
174
- access_token?: string;
175
- refresh_token?: string;
176
- access_token_expires_in?: number;
177
- device?: LoginDeviceInfo;
178
- risk?: LoginRiskInfo;
179
- }
180
- interface LoginDeviceInfo {
181
- id: string;
182
- name: string;
183
- trust_level: string;
184
- is_new: boolean;
185
- }
186
- interface LoginRiskInfo {
187
- score: number;
188
- action: string;
189
- factors: string[];
190
- action_required?: boolean;
191
- }
192
- interface RefreshResponse {
193
- session_token: string;
194
- expires_at: string;
195
- }
196
- interface ForgotPasswordRequest {
197
- email: string;
198
- }
199
- interface ResetPasswordRequest {
200
- token: string;
201
- new_password: string;
202
- }
203
- interface VerifyEmailRequest {
204
- token: string;
205
- }
206
- interface ChangePasswordRequest {
207
- current_password: string;
208
- new_password: string;
209
- }
210
- interface ChangeEmailRequest {
211
- new_email: string;
212
- password: string;
213
- }
214
- type OAuthProvider = 'google' | 'apple' | 'github' | 'facebook' | 'twitter' | 'linkedin';
215
- interface OAuthConfig {
216
- /** OAuth provider */
217
- provider: OAuthProvider;
218
- /** URL to redirect to after OAuth completes */
219
- redirectUrl?: string;
220
- /** Additional scopes to request */
221
- scopes?: string[];
222
- /** State parameter for CSRF protection */
223
- state?: string;
224
- }
225
- interface OAuthStartResponse {
226
- /** URL to redirect user to for OAuth flow */
227
- authorization_url: string;
228
- /** State token for verification */
229
- state: string;
230
- }
231
- interface OAuthCallbackRequest {
232
- /** OAuth provider */
233
- provider: OAuthProvider;
234
- /** Authorization code from OAuth provider */
235
- code: string;
236
- /** State token for verification */
237
- state: string;
238
- }
239
- interface OAuthCallbackResponse {
240
- /** Session token for the authenticated user */
241
- session_token: string;
242
- /** The authenticated user */
243
- user: User;
244
- /** When the session expires */
245
- expires_at: string;
246
- /** Whether this is a new user (just registered via OAuth) */
247
- is_new_user: boolean;
248
- }
249
- interface LinkedAccount {
250
- provider: string;
251
- /**
252
- * Not returned by GET /v1/auth/oauth/providers today. Reserved for a
253
- * future endpoint that exposes the external user id; treat as optional.
254
- */
255
- provider_user_id?: string;
256
- provider_email?: string;
257
- linked_at: string;
258
- }
259
- type MFAMethod = 'totp' | 'sms' | 'email';
260
- interface MFASetupRequest {
261
- method: MFAMethod;
262
- /** Phone number for SMS (required if method is 'sms') */
263
- phone?: string;
264
- }
265
- interface MFATOTPSetupResponse {
266
- /** Secret key for TOTP */
267
- secret: string;
268
- /** QR code URI for authenticator apps (otpauth:// format) */
269
- qr_code_uri: string;
270
- /** Issuer name shown in authenticator app */
271
- issuer: string;
272
- /** Account name shown in authenticator app */
273
- account_name: string;
274
- }
275
- interface MFASMSSetupResponse {
276
- /** Whether setup was successful */
277
- success: boolean;
278
- /** Status message */
279
- message: string;
280
- /** Last digits of the phone number for display */
281
- phone_last_digits: string;
282
- }
283
- interface MFAVerifyRequest {
284
- /** The MFA code entered by user */
285
- code: string;
286
- /** MFA method being verified */
287
- method: MFAMethod;
288
- /** Whether this is during login challenge */
289
- is_login_challenge?: boolean;
290
- }
291
- interface MFAChallengeResponse {
292
- /** Challenge token for completing MFA */
293
- challenge_token: string;
294
- /** Available MFA methods for this user */
295
- available_methods: MFAMethod[];
296
- /** Hint for the method (e.g., last 4 digits of phone) */
297
- hint?: string;
298
- }
299
- interface MFAStatus {
300
- mfa_enabled: boolean;
301
- mfa_method?: string;
302
- totp_configured: boolean;
303
- sms_configured: boolean;
304
- email_configured: boolean;
305
- backup_codes_remaining: number;
306
- allowed_methods: string[];
307
- mfa_required: boolean;
308
- requirement_source: string;
309
- }
310
- interface LoginResponseWithMFA extends Omit<LoginResponse, 'session_token'> {
311
- /** Whether MFA challenge is required */
312
- requires_mfa: boolean;
313
- /** MFA challenge details (if requires_mfa is true) */
314
- mfa_challenge?: MFAChallengeResponse;
315
- /** Session token (only present if MFA not required or already completed) */
316
- session_token?: string;
317
- }
318
- interface PhoneSendCodeRequest {
319
- /** Phone number in E.164 format */
320
- phone: string;
321
- /** Purpose of the code */
322
- purpose: 'login' | 'verify' | 'register';
323
- }
324
- interface PhoneVerifyRequest {
325
- /** Phone number in E.164 format */
326
- phone: string;
327
- /** Verification code from SMS */
328
- code: string;
329
- }
330
- interface PhoneLoginRequest {
331
- /** Phone number in E.164 format */
332
- phone: string;
333
- /** Verification code from SMS */
334
- code: string;
335
- /** Full name (required for new users) */
336
- full_name?: string;
337
- }
338
- interface Session {
339
- token: string;
340
- userId: string;
341
- expiresAt: Date;
342
- }
343
- /**
344
- * Client context information to forward when making server-to-server calls
345
- * on behalf of end users. This ensures that ScaleMule captures the actual
346
- * end user's information instead of the server's information.
347
- *
348
- * Used primarily for uploads where tracking the uploader's IP, user agent,
349
- * and device fingerprint is important for security (e.g., identifying bad actors).
350
- */
351
- interface ClientContext {
352
- /** End user's IP address (from X-Forwarded-For or X-Real-IP) */
353
- ip?: string;
354
- /** End user's browser user agent */
355
- userAgent?: string;
356
- /** End user's device fingerprint (if collected) */
357
- deviceFingerprint?: string;
358
- /** HTTP Referer header (the page that linked to this one) */
359
- referrer?: string;
360
- }
361
- interface StorageFile {
362
- id: string;
363
- filename: string;
364
- content_type: string;
365
- size_bytes: number;
366
- is_public: boolean;
367
- created_at: string;
368
- scan_status?: string;
369
- url?: string;
370
- checksum?: string;
371
- scanned_at?: string;
372
- }
373
- interface UploadOptions {
374
- /** Make file publicly accessible */
375
- is_public?: boolean;
376
- /** Custom filename (defaults to original) */
377
- filename?: string;
378
- /** File category for organization */
379
- category?: string;
380
- /** Progress callback (0-100) */
381
- onProgress?: (progress: number) => void;
382
- }
383
- interface ListFilesParams {
384
- /** Filter by content type prefix (e.g., 'image/', 'video/') */
385
- content_type?: string;
386
- /** Search in filename */
387
- search?: string;
388
- /** Number of results (max 100) */
389
- limit?: number;
390
- /** Offset for pagination */
391
- offset?: number;
392
- }
393
- interface ListFilesResponse {
394
- files: StorageFile[];
395
- total: number;
396
- limit: number;
397
- offset: number;
398
- }
399
- interface UploadResponse {
400
- id: string;
401
- filename: string;
402
- content_type: string;
403
- size_bytes: number;
404
- url: string;
405
- }
406
- interface SignedUploadUrl {
407
- upload_url: string;
408
- file_id: string;
409
- expires_at: string;
410
- }
411
- interface SignedUploadRequest {
412
- /** Original filename */
413
- filename: string;
414
- /** MIME content type */
415
- content_type: string;
416
- /** File size in bytes */
417
- size_bytes: number;
418
- /** Make file publicly accessible */
419
- is_public?: boolean;
420
- }
421
- interface SignedUploadResponse {
422
- /** Pre-signed URL for direct upload */
423
- upload_url: string;
424
- /** File ID for reference */
425
- file_id: string;
426
- /** When the signed URL expires */
427
- expires_at: string;
428
- /** Headers to include in the upload request */
429
- required_headers: Record<string, string>;
430
- }
431
- interface SignedUploadCompleteRequest {
432
- /** File ID from signed upload response */
433
- file_id: string;
434
- }
435
- interface UpdateProfileRequest {
436
- full_name?: string;
437
- username?: string;
438
- avatar_url?: string;
439
- }
440
- interface Profile extends User {
441
- }
442
- interface UseAuthReturn {
443
- /** Current user or null if not logged in */
444
- user: User | null;
445
- /** True while loading initial auth state */
446
- loading: boolean;
447
- /** True if user is authenticated */
448
- isAuthenticated: boolean;
449
- /** Last auth error */
450
- error: ApiError | null;
451
- /** Register a new user */
452
- register: (data: RegisterRequest) => Promise<User>;
453
- /** Login with email/password (may return MFA challenge) */
454
- login: (data: LoginRequest) => Promise<LoginResponse | LoginResponseWithMFA>;
455
- /** Logout current user */
456
- logout: () => Promise<void>;
457
- /** Request password reset email */
458
- forgotPassword: (email: string) => Promise<void>;
459
- /** Reset password with token */
460
- resetPassword: (token: string, newPassword: string) => Promise<void>;
461
- /** Verify email with token */
462
- verifyEmail: (token: string) => Promise<void>;
463
- /** Resend verification email (optional email for unauthenticated resend) */
464
- resendVerification: (email?: string) => Promise<void>;
465
- /** Refresh session token */
466
- refreshSession: () => Promise<void>;
467
- /** Start OAuth flow for a provider */
468
- startOAuth: (config: OAuthConfig) => Promise<OAuthStartResponse>;
469
- /** Complete OAuth flow after redirect */
470
- completeOAuth: (request: OAuthCallbackRequest) => Promise<OAuthCallbackResponse>;
471
- /** Get list of linked OAuth accounts */
472
- getLinkedAccounts: () => Promise<LinkedAccount[]>;
473
- /** Link a new OAuth account */
474
- linkAccount: (config: OAuthConfig) => Promise<OAuthStartResponse>;
475
- /** Unlink an OAuth account */
476
- unlinkAccount: (provider: OAuthProvider) => Promise<void>;
477
- /** Get current MFA status */
478
- getMFAStatus: () => Promise<MFAStatus>;
479
- /** Start MFA setup for a method */
480
- setupMFA: (request: MFASetupRequest) => Promise<MFATOTPSetupResponse | MFASMSSetupResponse>;
481
- /** Verify and enable MFA */
482
- verifyMFA: (request: MFAVerifyRequest) => Promise<void>;
483
- /** Complete MFA challenge during login */
484
- completeMFAChallenge: (challengeToken: string, code: string, method: MFAMethod) => Promise<LoginResponse>;
485
- /** Disable MFA */
486
- disableMFA: (password: string) => Promise<void>;
487
- /** Regenerate backup codes */
488
- regenerateBackupCodes: (password: string) => Promise<string[]>;
489
- /** Send verification code to phone */
490
- sendPhoneCode: (request: PhoneSendCodeRequest) => Promise<void>;
491
- /** Verify phone number */
492
- verifyPhone: (request: PhoneVerifyRequest) => Promise<void>;
493
- /** Login with phone number */
494
- loginWithPhone: (request: PhoneLoginRequest) => Promise<LoginResponse>;
495
- /**
496
- * All accounts that have previously logged in on this device.
497
- * Contains display metadata only — no tokens.
498
- * Requires `enableAccountSwitcher: true` in config.
499
- */
500
- knownAccounts: KnownAccountInfo[];
501
- /**
502
- * Switch to a different known account.
503
- * Logs out the current session and returns the target account's info
504
- * so the login form can be pre-filled. User must re-authenticate.
505
- */
506
- switchAccount: (userId: string) => Promise<KnownAccountInfo | null>;
507
- /** Remove a specific account from the known accounts list */
508
- removeKnownAccount: (userId: string) => Promise<void>;
509
- /** Clear all known accounts from this device */
510
- clearKnownAccounts: () => Promise<void>;
511
- }
512
- /**
513
- * Known account info — display metadata only, no tokens.
514
- * Used by the account switcher to show previously logged-in accounts.
515
- */
516
- interface KnownAccountInfo {
517
- userId: string;
518
- email?: string;
519
- fullName?: string;
520
- avatarUrl?: string;
521
- provider?: string;
522
- lastActiveAt: string;
523
- displayLabel?: string;
524
- colorIndex?: number;
525
- }
526
- interface UseContentReturn {
527
- /** User's files */
528
- files: StorageFile[];
529
- /** True while loading */
530
- loading: boolean;
531
- /** Upload progress (0-100) when upload is in progress */
532
- uploadProgress: number | null;
533
- /** Last error */
534
- error: ApiError | null;
535
- /** Upload a file (direct upload through SDK) */
536
- upload: (file: File, options?: UploadOptions) => Promise<UploadResponse>;
537
- /** List user's files */
538
- list: (params?: ListFilesParams) => Promise<ListFilesResponse>;
539
- /** Delete a file */
540
- remove: (fileId: string) => Promise<void>;
541
- /** Get a single file's info */
542
- get: (fileId: string) => Promise<StorageFile>;
543
- /** Refresh the file list */
544
- refresh: () => Promise<void>;
545
- /** Get a signed URL for direct upload (bypasses SDK, uploads directly to storage) */
546
- getSignedUploadUrl: (request: SignedUploadRequest) => Promise<SignedUploadResponse>;
547
- /** Upload file directly to signed URL (call this yourself with fetch/xhr) */
548
- uploadToSignedUrl: (signedUrl: string, file: File, headers: Record<string, string>, onProgress?: (progress: number) => void) => Promise<void>;
549
- /** Mark signed upload as complete */
550
- completeSignedUpload: (fileId: string) => Promise<StorageFile>;
551
- }
552
- interface UseUserReturn {
553
- /** Current user profile */
554
- profile: Profile | null;
555
- /** True while loading */
556
- loading: boolean;
557
- /** Last error */
558
- error: ApiError | null;
559
- /** Update profile */
560
- update: (data: UpdateProfileRequest) => Promise<Profile>;
561
- /** Change password */
562
- changePassword: (currentPassword: string, newPassword: string) => Promise<void>;
563
- /** Change email */
564
- changeEmail: (newEmail: string, password: string) => Promise<void>;
565
- /** Delete account */
566
- deleteAccount: (password: string) => Promise<void>;
567
- /** Request data export */
568
- exportData: () => Promise<{
569
- download_url: string;
570
- }>;
571
- }
572
- /**
573
- * Analytics event to track
574
- */
575
- interface AnalyticsEvent {
576
- /** Event name (e.g., 'page_viewed', 'button_clicked', 'purchase_completed') */
577
- event_name: string;
578
- /** Event category for grouping (e.g., 'engagement', 'conversion', 'navigation') */
579
- event_category?: string;
580
- /** Additional event properties as key-value pairs */
581
- properties?: Record<string, unknown>;
582
- /** User ID to associate with event (auto-filled if user is logged in) */
583
- user_id?: string;
584
- /** Session ID for tracking user journey (auto-generated if not provided) */
585
- session_id?: string;
586
- /** Anonymous ID for tracking before login (auto-generated if not provided) */
587
- anonymous_id?: string;
588
- /** Client timestamp (auto-filled if not provided) */
589
- client_timestamp?: string;
590
- /** Session duration in seconds at event time (auto-filled) */
591
- session_duration_seconds?: number;
592
- }
593
- /**
594
- * Page view event data
595
- */
596
- interface PageViewData {
597
- /** Page URL (auto-filled from window.location if not provided) */
598
- page_url?: string;
599
- /** Page title (auto-filled from document.title if not provided) */
600
- page_title?: string;
601
- /** Referrer URL (auto-filled from document.referrer if not provided) */
602
- referrer?: string;
603
- /** Additional properties */
604
- properties?: Record<string, unknown>;
605
- }
606
- /**
607
- * UTM parameters for campaign tracking
608
- */
609
- interface UTMParams {
610
- /** Traffic source (e.g., 'google', 'newsletter', 'facebook') */
611
- utm_source?: string;
612
- /** Marketing medium (e.g., 'cpc', 'email', 'social') */
613
- utm_medium?: string;
614
- /** Campaign name or ID */
615
- utm_campaign?: string;
616
- /** Search term for paid search */
617
- utm_term?: string;
618
- /** Content identifier for A/B testing */
619
- utm_content?: string;
620
- /** Ad group name or ID */
621
- utm_adgroup?: string;
622
- /** Google Ads click ID (auto-appended by Google) */
623
- gclid?: string;
624
- /** Google Ads click ID for iOS (app attribution) */
625
- gbraid?: string;
626
- /** Google Ads click ID for web (cross-domain) */
627
- wbraid?: string;
628
- /** Facebook/Meta click ID (auto-appended by Meta) */
629
- fbclid?: string;
630
- /** Google Ads campaign ID (via ValueTrack {campaignid}) */
631
- gad_campaignid?: string;
632
- /** Google Ads ad group ID (via ValueTrack {adgroupid}) */
633
- gad_adgroupid?: string;
634
- /** Google Ads network: g=search, d=display, y=youtube */
635
- gad_network?: string;
636
- /** Google Ads match type: b=broad, p=phrase, e=exact */
637
- gad_matchtype?: string;
638
- /** Google Ads device: m=mobile, c=desktop, t=tablet */
639
- gad_device?: string;
640
- /** Google Ads placement (display/youtube site) */
641
- gad_placement?: string;
642
- /** Google Ads source identifier */
643
- gad_source?: string;
644
- }
645
- /**
646
- * Device information for analytics
647
- */
648
- interface DeviceInfo {
649
- /** Device type (mobile, tablet, desktop) */
650
- device_type?: string;
651
- /** Device brand (Apple, Samsung, etc.) */
652
- device_brand?: string;
653
- /** Device model */
654
- device_model?: string;
655
- /** Operating system */
656
- os?: string;
657
- /** OS version */
658
- os_version?: string;
659
- /** Browser name */
660
- browser?: string;
661
- /** Browser version */
662
- browser_version?: string;
663
- /** Screen resolution (e.g., '1920x1080') */
664
- screen_resolution?: string;
665
- /** Viewport size (e.g., '1200x800') */
666
- viewport_size?: string;
667
- }
668
- /**
669
- * Enhanced event with all tracking data
670
- */
671
- interface EnhancedAnalyticsEvent extends AnalyticsEvent {
672
- /** UTM campaign parameters */
673
- utm?: UTMParams;
674
- /** Device information */
675
- device?: DeviceInfo;
676
- /** Page URL */
677
- page_url?: string;
678
- /** Page title */
679
- page_title?: string;
680
- /** Landing page URL (first page user visited) */
681
- landing_page?: string;
682
- }
683
- /**
684
- * Track event response
685
- */
686
- interface TrackEventResponse {
687
- /** Number of events tracked */
688
- tracked: number;
689
- /** Event ID (for v2 events) */
690
- event_id?: string;
691
- /** Session ID */
692
- session_id?: string;
693
- }
694
- /**
695
- * Batch track request
696
- */
697
- interface BatchTrackRequest {
698
- /** Array of events to track */
699
- events: AnalyticsEvent[];
700
- }
701
- /**
702
- * Options for analytics hook
703
- */
704
- interface UseAnalyticsOptions {
705
- /** Auto-track page views on route changes (default: true) */
706
- autoTrackPageViews?: boolean;
707
- /** Auto-capture UTM params from URL (default: true) */
708
- autoCaptureUtmParams?: boolean;
709
- /** @deprecated Typo kept for backward compatibility. Use autoCaptureUtmParams. */
710
- autoCapturUtmParams?: boolean;
711
- /** Auto-generate session ID (default: true) */
712
- autoGenerateSessionId?: boolean;
713
- /** Session ID storage key (default: 'sm_session_id') */
714
- sessionStorageKey?: string;
715
- /** Anonymous ID storage key (default: 'sm_anonymous_id') */
716
- anonymousStorageKey?: string;
717
- /** Use v2 enhanced tracking (default: true) */
718
- useV2?: boolean;
719
- /**
720
- * Minimum milliseconds between duplicate events with the same event_name.
721
- * Prevents inflated analytics from event bubbling, double-bound listeners,
722
- * or rapid-fire IntersectionObserver callbacks.
723
- * Set to 0 to disable dedup. Default: 300ms.
724
- */
725
- eventDedupMs?: number;
726
- }
727
- /**
728
- * Analytics hook return type
729
- */
730
- interface UseAnalyticsReturn {
731
- /** True while an analytics operation is in progress */
732
- loading: boolean;
733
- /** Last error from analytics operations */
734
- error: ApiError | null;
735
- /** Current session ID */
736
- sessionId: string | null;
737
- /** Current anonymous ID */
738
- anonymousId: string | null;
739
- /** Stored UTM parameters from URL */
740
- utmParams: UTMParams | null;
741
- /**
742
- * Track a custom event
743
- * @param event - Event data to track
744
- * @returns Promise with track response
745
- * @example
746
- * ```tsx
747
- * await trackEvent({
748
- * event_name: 'button_clicked',
749
- * event_category: 'engagement',
750
- * properties: { button_id: 'signup', location: 'header' }
751
- * })
752
- * ```
753
- */
754
- trackEvent: (event: AnalyticsEvent) => Promise<TrackEventResponse>;
755
- /**
756
- * Track a page view
757
- * @param data - Optional page view data (auto-filled from browser if not provided)
758
- * @example
759
- * ```tsx
760
- * // Auto-detect page info
761
- * await trackPageView()
762
- *
763
- * // Custom page info
764
- * await trackPageView({
765
- * page_url: '/checkout',
766
- * page_title: 'Checkout',
767
- * properties: { cart_value: 99.99 }
768
- * })
769
- * ```
770
- */
771
- trackPageView: (data?: PageViewData) => Promise<TrackEventResponse>;
772
- /**
773
- * Track multiple events in a batch
774
- * @param events - Array of events to track
775
- * @example
776
- * ```tsx
777
- * await trackBatch([
778
- * { event_name: 'item_added', properties: { item_id: '123' } },
779
- * { event_name: 'cart_updated', properties: { total: 49.99 } }
780
- * ])
781
- * ```
782
- */
783
- trackBatch: (events: AnalyticsEvent[]) => Promise<TrackEventResponse>;
784
- /**
785
- * Identify user for analytics (call after login)
786
- * Merges anonymous activity with user profile
787
- * @param userId - User ID to associate with events
788
- * @param traits - Optional user traits
789
- */
790
- identify: (userId: string, traits?: Record<string, unknown>) => Promise<void>;
791
- /**
792
- * Reset analytics session (call on logout)
793
- * Clears user association but keeps anonymous ID
794
- */
795
- reset: () => void;
796
- /**
797
- * Set UTM parameters manually (auto-captured from URL by default)
798
- */
799
- setUtmParams: (params: UTMParams) => void;
800
- /**
801
- * Get device info for current browser/device
802
- */
803
- getDeviceInfo: () => DeviceInfo;
804
- }
805
- interface ConnectedAccount {
806
- id: string;
807
- email: string;
808
- country: string;
809
- status: 'pending' | 'onboarding' | 'active' | 'restricted' | 'disabled';
810
- charges_enabled: boolean;
811
- payouts_enabled: boolean;
812
- onboarding_complete: boolean;
813
- details_submitted: boolean;
814
- metadata?: Record<string, unknown>;
815
- created_at: string;
816
- updated_at: string;
817
- }
818
- interface AccountBalance {
819
- currency: string;
820
- available_cents: number;
821
- pending_cents: number;
822
- reserved_cents: number;
823
- }
824
- interface BillingPayment {
825
- id: string;
826
- customer_id: string;
827
- connected_account_id?: string;
828
- amount_cents: number;
829
- currency: string;
830
- platform_fee_cents: number;
831
- provider_fee_cents: number;
832
- creator_net_cents: number;
833
- status: string;
834
- payment_type?: string;
835
- client_secret?: string;
836
- metadata?: Record<string, unknown>;
837
- created_at: string;
838
- }
839
- interface BillingRefund {
840
- id: string;
841
- payment_id: string;
842
- amount_cents: number;
843
- platform_fee_reversal_cents: number;
844
- reason?: string;
845
- status: string;
846
- created_at: string;
847
- }
848
- interface BillingPayout {
849
- id: string;
850
- amount_cents: number;
851
- currency: string;
852
- status: string;
853
- arrival_date?: string;
854
- created_at: string;
855
- }
856
- interface PayoutSchedule {
857
- schedule_interval: string;
858
- minimum_amount_cents: number;
859
- day_of_week?: number;
860
- day_of_month?: number;
861
- }
862
- interface BillingTransaction {
863
- id: string;
864
- entry_type: string;
865
- account_type: string;
866
- amount_cents: number;
867
- currency: string;
868
- category: string;
869
- reference_type: string;
870
- description?: string;
871
- created_at: string;
872
- }
873
- interface TransactionSummary {
874
- gross_cents: number;
875
- platform_fee_cents: number;
876
- net_cents: number;
877
- payout_cents: number;
878
- refund_cents: number;
879
- }
880
- interface UseBillingReturn {
881
- loading: boolean;
882
- error: ApiError | null;
883
- createConnectedAccount: (data: {
884
- email: string;
885
- country?: string;
886
- }) => Promise<ConnectedAccount | null>;
887
- getMyConnectedAccount: () => Promise<ConnectedAccount | null>;
888
- getConnectedAccount: (id: string) => Promise<ConnectedAccount | null>;
889
- createOnboardingLink: (id: string, data: {
890
- return_url: string;
891
- refresh_url: string;
892
- }) => Promise<string | null>;
893
- getAccountBalance: (id: string) => Promise<AccountBalance | null>;
894
- createPayment: (data: {
895
- amount_cents: number;
896
- currency?: string;
897
- connected_account_id?: string;
898
- platform_fee_percent?: number;
899
- platform_fee_cents?: number;
900
- payment_type?: string;
901
- metadata?: Record<string, unknown>;
902
- }) => Promise<BillingPayment | null>;
903
- getPayment: (id: string) => Promise<BillingPayment | null>;
904
- listPayments: (params?: Record<string, unknown>) => Promise<BillingPayment[]>;
905
- refundPayment: (id: string, data?: {
906
- amount_cents?: number;
907
- reason?: string;
908
- }) => Promise<BillingRefund | null>;
909
- getPayoutHistory: (accountId: string, params?: Record<string, unknown>) => Promise<BillingPayout[]>;
910
- getPayoutSchedule: (accountId: string) => Promise<PayoutSchedule | null>;
911
- setPayoutSchedule: (accountId: string, data: {
912
- schedule_interval: string;
913
- minimum_amount_cents?: number;
914
- }) => Promise<PayoutSchedule | null>;
915
- getTransactions: (params?: Record<string, unknown>) => Promise<BillingTransaction[]>;
916
- getTransactionSummary: (params?: Record<string, unknown>) => Promise<TransactionSummary | null>;
917
- createSetupSession: (data: {
918
- return_url: string;
919
- cancel_url: string;
920
- }) => Promise<string | null>;
921
- }
922
-
923
- export { type RegisterRequest as $, type ApiError as A, type BatchTrackRequest as B, type ChangeEmailRequest as C, type DeviceFingerprint as D, type EnhancedAnalyticsEvent as E, type ForgotPasswordRequest as F, type MFASetupRequest as G, type MFAStatus as H, type MFATOTPSetupResponse as I, type MFAVerifyRequest as J, type KnownAccountInfo as K, type LoginResponse as L, type MFAChallengeResponse as M, type OAuthCallbackResponse as N, type OAuthCallbackRequest as O, type OAuthConfig as P, type OAuthProvider as Q, type OAuthStartResponse as R, type ScaleMuleConfig as S, type PageViewData as T, type User as U, type PayoutSchedule as V, type PhoneLoginRequest as W, type PhoneSendCodeRequest as X, type PhoneVerifyRequest as Y, type Profile as Z, type RefreshResponse as _, type UseAuthReturn as a, type ResetPasswordRequest as a0, ScaleMuleApiError as a1, type ScaleMuleEnvironment as a2, type Session as a3, type SignedUploadCompleteRequest as a4, type SignedUploadRequest as a5, type SignedUploadResponse as a6, type SignedUploadUrl as a7, type StorageAdapter as a8, type StorageFile as a9, type TrackEventResponse as aa, type TransactionSummary as ab, type UTMParams as ac, type UpdateProfileRequest as ad, type UploadOptions as ae, type UploadResponse as af, type VerifyEmailRequest as ag, type UseBillingReturn as b, type ListFilesParams as c, type UseContentReturn as d, type UseUserReturn as e, type UseAnalyticsOptions as f, type UseAnalyticsReturn as g, type AccountBalance as h, type AnalyticsEvent as i, type ApiResponse as j, type BillingPayment as k, type BillingPayout as l, type BillingRefund as m, type BillingTransaction as n, type ChangePasswordRequest as o, type ClientContext as p, type ConnectedAccount as q, type DeviceInfo as r, type LinkedAccount as s, type ListFilesResponse as t, type LoginDeviceInfo as u, type LoginRequest as v, type LoginResponseWithMFA as w, type LoginRiskInfo as x, type MFAMethod as y, type MFASMSSetupResponse as z };