@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,418 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+ import { ScaleMuleClient } from './client.js';
4
+ export { ClientConfig, RequestOptions, createClient } from './client.js';
5
+ import { S as ScaleMuleConfig, U as User, L as LoginResponse, A as ApiError, a as UseAuthReturn, b as UseBillingReturn, c as ListFilesParams, d as UseContentReturn, e as UseUserReturn, f as UseAnalyticsOptions, g as UseAnalyticsReturn } from './index-BkacIKdu.js';
6
+ export { a1 as AccountBalance, a8 as AnalyticsEvent, j as ApiResponse, ae as BatchTrackRequest, a2 as BillingPayment, a4 as BillingPayout, a3 as BillingRefund, a6 as BillingTransaction, q as ChangeEmailRequest, C as ChangePasswordRequest, _ as ClientContext, a0 as ConnectedAccount, D as DeviceFingerprint, ab as DeviceInfo, ac as EnhancedAnalyticsEvent, F as ForgotPasswordRequest, w as LinkedAccount, Q as ListFilesResponse, m as LoginDeviceInfo, k as LoginRequest, l as LoginResponseWithMFA, n as LoginRiskInfo, E as MFAChallengeResponse, M as MFAMethod, z as MFASMSSetupResponse, x as MFASetupRequest, G as MFAStatus, y as MFATOTPSetupResponse, B as MFAVerifyRequest, u as OAuthCallbackRequest, v as OAuthCallbackResponse, s as OAuthConfig, O as OAuthProvider, t as OAuthStartResponse, a9 as PageViewData, a5 as PayoutSchedule, J as PhoneLoginRequest, H as PhoneSendCodeRequest, I as PhoneVerifyRequest, P as Profile, o as RefreshResponse, R as RegisterRequest, p as ResetPasswordRequest, h as ScaleMuleEnvironment, r as Session, Z as SignedUploadCompleteRequest, X as SignedUploadRequest, Y as SignedUploadResponse, W as SignedUploadUrl, i as StorageAdapter, K as StorageFile, ad as TrackEventResponse, a7 as TransactionSummary, aa as UTMParams, $ as UpdateProfileRequest, N as UploadOptions, T as UploadResponse, V as VerifyEmailRequest } from './index-BkacIKdu.js';
7
+
8
+ interface ScaleMuleContextValue {
9
+ /** The API client instance */
10
+ client: ScaleMuleClient;
11
+ /** Current authenticated user */
12
+ user: User | null;
13
+ /** Set the current user */
14
+ setUser: (user: User | null) => void;
15
+ /** Whether the SDK is initializing */
16
+ initializing: boolean;
17
+ /** Last error */
18
+ error: ApiError | null;
19
+ /** Set error */
20
+ setError: (error: ApiError | null) => void;
21
+ /** Analytics proxy URL (when set, SDK sends events here instead of ScaleMule) */
22
+ analyticsProxyUrl?: string;
23
+ /** Auth proxy URL (when set, auth operations route through this proxy) */
24
+ authProxyUrl?: string;
25
+ /** Publishable key for browser-safe operations (analytics) */
26
+ publishableKey?: string;
27
+ /** Gateway URL for direct API calls */
28
+ gatewayUrl?: string;
29
+ }
30
+ interface ScaleMuleProviderProps extends ScaleMuleConfig {
31
+ children: ReactNode;
32
+ /** Called when user logs in */
33
+ onLogin?: (user: User, response: LoginResponse) => void;
34
+ /** Called when user logs out */
35
+ onLogout?: () => void;
36
+ /** Called on authentication error */
37
+ onAuthError?: (error: ApiError) => void;
38
+ }
39
+ declare function ScaleMuleProvider({ apiKey, applicationId, environment, gatewayUrl, debug, storage, analyticsProxyUrl, authProxyUrl, publishableKey, children, onLogin, onLogout, onAuthError, }: ScaleMuleProviderProps): react_jsx_runtime.JSX.Element;
40
+ declare function useScaleMule(): ScaleMuleContextValue;
41
+ declare function useScaleMuleClient(): ScaleMuleClient;
42
+
43
+ declare function useAuth(): UseAuthReturn;
44
+
45
+ /**
46
+ * Billing hook for ScaleMule marketplace payments
47
+ *
48
+ * Provides connected accounts, payments, refunds, payouts, and ledger queries.
49
+ *
50
+ * @example
51
+ * ```tsx
52
+ * function CreatorDashboard() {
53
+ * const {
54
+ * getMyConnectedAccount,
55
+ * getAccountBalance,
56
+ * getTransactionSummary,
57
+ * loading,
58
+ * } = useBilling()
59
+ *
60
+ * useEffect(() => {
61
+ * async function load() {
62
+ * const account = await getMyConnectedAccount()
63
+ * if (account) {
64
+ * const balance = await getAccountBalance(account.id)
65
+ * const summary = await getTransactionSummary()
66
+ * }
67
+ * }
68
+ * load()
69
+ * }, [])
70
+ * }
71
+ * ```
72
+ */
73
+ declare function useBilling(): UseBillingReturn;
74
+
75
+ interface UseContentOptions {
76
+ /** Auto-fetch files on mount */
77
+ autoFetch?: boolean;
78
+ /** Initial list params */
79
+ initialParams?: ListFilesParams;
80
+ }
81
+ /**
82
+ * Content/Storage hook for ScaleMule
83
+ *
84
+ * Provides file upload, listing, and deletion functionality.
85
+ * Automatically includes user ID for proper multi-tenancy.
86
+ *
87
+ * @example
88
+ * ```tsx
89
+ * function Gallery() {
90
+ * const { files, upload, uploadProgress, loading } = useContent({ autoFetch: true })
91
+ *
92
+ * const handleUpload = async (e) => {
93
+ * const file = e.target.files[0]
94
+ * await upload(file, {
95
+ * onProgress: (progress) => console.log(`${progress}%`)
96
+ * })
97
+ * // Files list is automatically refreshed
98
+ * }
99
+ *
100
+ * // For large files, use signed upload
101
+ * const handleLargeUpload = async (file) => {
102
+ * const signedUrl = await getSignedUploadUrl({
103
+ * filename: file.name,
104
+ * content_type: file.type,
105
+ * size_bytes: file.size,
106
+ * })
107
+ * await uploadToSignedUrl(signedUrl.upload_url, file, signedUrl.required_headers)
108
+ * const result = await completeSignedUpload(signedUrl.file_id)
109
+ * }
110
+ *
111
+ * return (
112
+ * <div>
113
+ * <input type="file" onChange={handleUpload} />
114
+ * {uploadProgress !== null && <progress value={uploadProgress} max={100} />}
115
+ * {files.map(file => (
116
+ * <img key={file.id} src={file.url} alt={file.filename} />
117
+ * ))}
118
+ * </div>
119
+ * )
120
+ * }
121
+ * ```
122
+ */
123
+ declare function useContent(options?: UseContentOptions): UseContentReturn;
124
+
125
+ /**
126
+ * User profile hook for ScaleMule
127
+ *
128
+ * Provides profile management, password changes, and account operations.
129
+ *
130
+ * @example
131
+ * ```tsx
132
+ * function ProfilePage() {
133
+ * const { profile, update, changePassword } = useUser()
134
+ *
135
+ * const handleUpdate = async () => {
136
+ * await update({ full_name: 'New Name' })
137
+ * }
138
+ * }
139
+ * ```
140
+ */
141
+ declare function useUser(): UseUserReturn;
142
+
143
+ type RealtimeEvent = 'user.updated' | 'user.deleted' | 'session.expired' | 'file.uploaded' | 'file.deleted' | 'file.scanned' | 'notification' | string;
144
+ interface RealtimeMessage<T = unknown> {
145
+ event: RealtimeEvent;
146
+ data: T;
147
+ timestamp: string;
148
+ }
149
+ type RealtimeStatus = 'disconnected' | 'connecting' | 'connected' | 'reconnecting';
150
+ interface UseRealtimeOptions {
151
+ /** Auto-connect on mount (default: true) */
152
+ autoConnect?: boolean;
153
+ /** Events to subscribe to (default: all) */
154
+ events?: RealtimeEvent[];
155
+ /** Reconnect on disconnect (default: true) */
156
+ autoReconnect?: boolean;
157
+ /** Max reconnect attempts (default: 5) */
158
+ maxReconnectAttempts?: number;
159
+ /** Reconnect delay in ms (default: 1000, doubles each attempt) */
160
+ reconnectDelay?: number;
161
+ }
162
+ interface UseRealtimeReturn {
163
+ /** Current connection status */
164
+ status: RealtimeStatus;
165
+ /** Last error */
166
+ error: ApiError | null;
167
+ /** Connect to realtime */
168
+ connect: () => void;
169
+ /** Disconnect from realtime */
170
+ disconnect: () => void;
171
+ /** Subscribe to an event */
172
+ subscribe: <T>(event: RealtimeEvent, callback: (data: T) => void) => () => void;
173
+ /** Send a message (if supported) */
174
+ send: (event: string, data: unknown) => void;
175
+ /** Last received message */
176
+ lastMessage: RealtimeMessage | null;
177
+ }
178
+ /**
179
+ * Real-time updates hook via WebSocket
180
+ *
181
+ * Provides live updates for user state, files, and notifications.
182
+ *
183
+ * @example
184
+ * ```tsx
185
+ * function Dashboard() {
186
+ * const { status, subscribe } = useRealtime()
187
+ *
188
+ * useEffect(() => {
189
+ * // Subscribe to file uploads
190
+ * const unsubscribe = subscribe('file.uploaded', (data) => {
191
+ * console.log('New file uploaded:', data)
192
+ * refreshFiles()
193
+ * })
194
+ *
195
+ * return () => unsubscribe()
196
+ * }, [subscribe])
197
+ *
198
+ * return (
199
+ * <div>
200
+ * <span>Status: {status}</span>
201
+ * </div>
202
+ * )
203
+ * }
204
+ * ```
205
+ */
206
+ declare function useRealtime(options?: UseRealtimeOptions): UseRealtimeReturn;
207
+
208
+ /**
209
+ * Analytics hook for ScaleMule
210
+ *
211
+ * Provides event tracking, page views, and user identification.
212
+ * Automatically handles session management, UTM capture, and device detection.
213
+ *
214
+ * @example
215
+ * ```tsx
216
+ * function App() {
217
+ * const { trackEvent, trackPageView } = useAnalytics()
218
+ *
219
+ * // Track page views automatically on mount
220
+ * useEffect(() => {
221
+ * trackPageView()
222
+ * }, [trackPageView])
223
+ *
224
+ * // Track custom events
225
+ * const handleClick = async () => {
226
+ * await trackEvent({
227
+ * event_name: 'button_clicked',
228
+ * event_category: 'engagement',
229
+ * properties: { button_id: 'cta_signup' }
230
+ * })
231
+ * }
232
+ *
233
+ * return <button onClick={handleClick}>Sign Up</button>
234
+ * }
235
+ * ```
236
+ *
237
+ * @example
238
+ * ```tsx
239
+ * // Full tracking with user identification
240
+ * function App() {
241
+ * const { trackEvent, identify, reset } = useAnalytics()
242
+ * const { user, login, logout } = useAuth()
243
+ *
244
+ * // Identify user after login
245
+ * const handleLogin = async (credentials) => {
246
+ * const result = await login(credentials)
247
+ * await identify(result.user.id, { email: result.user.email })
248
+ * }
249
+ *
250
+ * // Reset on logout
251
+ * const handleLogout = async () => {
252
+ * await logout()
253
+ * reset()
254
+ * }
255
+ * }
256
+ * ```
257
+ */
258
+ declare function useAnalytics(options?: UseAnalyticsOptions): UseAnalyticsReturn;
259
+
260
+ /**
261
+ * Client-side validation helpers
262
+ *
263
+ * These validators match ScaleMule backend validation rules exactly.
264
+ * Use them for instant user feedback - the backend still validates all input.
265
+ *
266
+ * @example
267
+ * ```tsx
268
+ * import { validators } from '@scalemule/nextjs'
269
+ *
270
+ * function RegisterForm() {
271
+ * const [email, setEmail] = useState('')
272
+ * const [password, setPassword] = useState('')
273
+ *
274
+ * const emailValid = validators.email(email)
275
+ * const passwordResult = validators.password(password)
276
+ *
277
+ * return (
278
+ * <form>
279
+ * <input
280
+ * type="email"
281
+ * value={email}
282
+ * onChange={(e) => setEmail(e.target.value)}
283
+ * className={emailValid ? 'valid' : 'invalid'}
284
+ * />
285
+ * <input
286
+ * type="password"
287
+ * value={password}
288
+ * onChange={(e) => setPassword(e.target.value)}
289
+ * />
290
+ * {passwordResult.errors.map((err) => (
291
+ * <span key={err} className="error">{err}</span>
292
+ * ))}
293
+ * </form>
294
+ * )
295
+ * }
296
+ * ```
297
+ */
298
+ interface PasswordValidationResult {
299
+ valid: boolean;
300
+ errors: string[];
301
+ strength: 'weak' | 'fair' | 'good' | 'strong';
302
+ }
303
+ interface PhoneValidationResult {
304
+ valid: boolean;
305
+ formatted: string | null;
306
+ error: string | null;
307
+ }
308
+ interface PhoneCountry {
309
+ code: string;
310
+ name: string;
311
+ dialCode: string;
312
+ }
313
+ declare const phoneCountries: PhoneCountry[];
314
+ interface UsernameValidationResult {
315
+ valid: boolean;
316
+ error: string | null;
317
+ }
318
+ declare function normalizePhone(input: string): string;
319
+ declare function composePhone(countryDialCode: string, localNumber: string): string;
320
+ /**
321
+ * Validation helpers matching ScaleMule backend rules.
322
+ * These provide instant feedback - backend is always the source of truth.
323
+ */
324
+ declare const validators: {
325
+ /**
326
+ * Validate email address format.
327
+ * Matches RFC 5322 simplified pattern used by ScaleMule backend.
328
+ */
329
+ email: (email: string) => boolean;
330
+ /**
331
+ * Validate password strength.
332
+ * Returns detailed result with errors and strength indicator.
333
+ */
334
+ password: (password: string) => PasswordValidationResult;
335
+ /**
336
+ * Validate phone number in E.164 format.
337
+ * ScaleMule requires E.164 format: +[country code][number]
338
+ */
339
+ phone: (phone: string) => PhoneValidationResult;
340
+ /**
341
+ * Validate username format.
342
+ * Alphanumeric with underscores, 3-30 characters.
343
+ */
344
+ username: (username: string) => UsernameValidationResult;
345
+ /**
346
+ * Validate UUID format.
347
+ * Accepts UUIDv1, v4, v7 formats.
348
+ */
349
+ uuid: (uuid: string) => boolean;
350
+ /**
351
+ * Validate URL format.
352
+ */
353
+ url: (url: string) => boolean;
354
+ /**
355
+ * Validate file size against ScaleMule limits.
356
+ * Default max is 100MB, can be customized per application.
357
+ */
358
+ fileSize: (bytes: number, maxMB?: number) => {
359
+ valid: boolean;
360
+ error: string | null;
361
+ };
362
+ /**
363
+ * Validate file type against allowed MIME types.
364
+ */
365
+ fileType: (mimeType: string, allowed?: string[]) => {
366
+ valid: boolean;
367
+ error: string | null;
368
+ };
369
+ /**
370
+ * Sanitize and validate a display name.
371
+ */
372
+ displayName: (name: string) => {
373
+ valid: boolean;
374
+ sanitized: string;
375
+ error: string | null;
376
+ };
377
+ };
378
+ /**
379
+ * Validate multiple fields at once.
380
+ * Returns a map of field names to error messages.
381
+ */
382
+ declare function validateForm<T extends Record<string, unknown>>(data: T, rules: Partial<Record<keyof T, (value: unknown) => boolean | {
383
+ valid: boolean;
384
+ error?: string | null;
385
+ }>>): {
386
+ valid: boolean;
387
+ errors: Partial<Record<keyof T, string>>;
388
+ };
389
+ /**
390
+ * Sanitize an object for safe logging.
391
+ * Redacts values of keys that may contain sensitive data.
392
+ *
393
+ * @example
394
+ * ```typescript
395
+ * const data = { email: 'user@example.com', password: 'secret123' }
396
+ * console.log(sanitizeForLog(data))
397
+ * // { email: 'user@example.com', password: '[REDACTED]' }
398
+ * ```
399
+ */
400
+ declare function sanitizeForLog(data: unknown): unknown;
401
+ /**
402
+ * Create a safe logger that automatically sanitizes data.
403
+ *
404
+ * @example
405
+ * ```typescript
406
+ * const log = createSafeLogger('[MyApp]')
407
+ * log.info('User login', { email: 'user@example.com', password: 'secret' })
408
+ * // [MyApp] User login { email: 'user@example.com', password: '[REDACTED]' }
409
+ * ```
410
+ */
411
+ declare function createSafeLogger(prefix: string): {
412
+ log: (message: string, data?: unknown) => void;
413
+ info: (message: string, data?: unknown) => void;
414
+ warn: (message: string, data?: unknown) => void;
415
+ error: (message: string, data?: unknown) => void;
416
+ };
417
+
418
+ export { ApiError, ListFilesParams, LoginResponse, type PasswordValidationResult, type PhoneCountry, type PhoneValidationResult, type RealtimeEvent, type RealtimeMessage, type RealtimeStatus, ScaleMuleClient, ScaleMuleConfig, ScaleMuleProvider, type ScaleMuleProviderProps, UseAnalyticsOptions, UseAnalyticsReturn, UseAuthReturn, UseBillingReturn, UseContentReturn, type UseRealtimeOptions, type UseRealtimeReturn, UseUserReturn, User, type UsernameValidationResult, composePhone, createSafeLogger, normalizePhone, phoneCountries, sanitizeForLog, useAnalytics, useAuth, useBilling, useContent, useRealtime, useScaleMule, useScaleMuleClient, useUser, validateForm, validators };