@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,808 +0,0 @@
1
- import { MoneyClient } from '@scalemule/money';
2
- import { A as ApiError, $ as RegisterRequest, p as ClientContext, U as User, v as LoginRequest, L as LoginResponse, c as ListFilesParams, t as ListFilesResponse, a9 as StorageFile, af as UploadResponse } from './index-zQloSkpW.js';
3
-
4
- /**
5
- * Server-Side ScaleMule Client
6
- *
7
- * Stateless client for use in Next.js API routes.
8
- * Does not manage sessions - that's handled by cookies.
9
- */
10
-
11
- type ScaleMuleEnvironment = 'dev' | 'prod';
12
- interface ServerConfig {
13
- /** Your ScaleMule API key (use env var, never hardcode) */
14
- apiKey: string;
15
- /** Environment: 'dev' or 'prod' - automatically sets gateway URL */
16
- environment?: ScaleMuleEnvironment;
17
- /** Custom gateway URL (overrides environment preset) */
18
- gatewayUrl?: string;
19
- /** Enable debug logging */
20
- debug?: boolean;
21
- /** Callback when a 401 auto-refresh starts */
22
- onRefreshStart?: () => void;
23
- /** Callback when a 401 auto-refresh finishes */
24
- onRefreshEnd?: () => void;
25
- /** Callback when a 401 auto-refresh fails */
26
- onAutoRefreshFailed?: (error: ApiError) => void;
27
- }
28
- declare function resolveGatewayUrl(config: ServerConfig): string;
29
- declare class ScaleMuleServer {
30
- private apiKey;
31
- private gatewayUrl;
32
- private debug;
33
- private onRefreshStart?;
34
- private onRefreshEnd?;
35
- private onAutoRefreshFailed?;
36
- money: MoneyClient;
37
- constructor(config: ServerConfig);
38
- moneyWithSession(sessionToken: string): MoneyClient;
39
- /**
40
- * Make a request to the ScaleMule API
41
- *
42
- * @param method - HTTP method
43
- * @param path - API path (e.g., /v1/auth/login)
44
- * @param options - Request options
45
- * @param options.body - Request body (will be JSON stringified)
46
- * @param options.userId - User ID (passed through for storage operations)
47
- * @param options.sessionToken - Session token sent as Authorization: Bearer header
48
- * @param options.clientContext - End user context to forward (IP, user agent, etc.)
49
- */
50
- private request;
51
- auth: {
52
- /**
53
- * Register a new user
54
- */
55
- register: (data: RegisterRequest, options?: {
56
- clientContext?: ClientContext;
57
- }) => Promise<User>;
58
- /**
59
- * Login user - returns session token (store in HTTP-only cookie)
60
- */
61
- login: (data: LoginRequest, options?: {
62
- clientContext?: ClientContext;
63
- }) => Promise<LoginResponse>;
64
- /**
65
- * Logout user
66
- */
67
- logout: (sessionToken: string, options?: {
68
- onTokenRotated?: (newToken: string) => void;
69
- }) => Promise<void>;
70
- /**
71
- * Get current user from session token
72
- */
73
- me: (sessionToken: string, options?: {
74
- onTokenRotated?: (newToken: string) => void;
75
- }) => Promise<User>;
76
- /**
77
- * Refresh session token
78
- */
79
- refresh: (sessionToken: string, options?: {
80
- clientContext?: ClientContext;
81
- isAutoRefresh?: boolean;
82
- onTokenRotated?: (newToken: string) => void;
83
- }) => Promise<{
84
- session_token: string;
85
- expires_at: string;
86
- }>;
87
- /**
88
- * Request password reset email
89
- */
90
- forgotPassword: (email: string, options?: {
91
- clientContext?: ClientContext;
92
- }) => Promise<{
93
- message: string;
94
- }>;
95
- /**
96
- * Reset password with token
97
- */
98
- resetPassword: (token: string, newPassword: string, options?: {
99
- clientContext?: ClientContext;
100
- }) => Promise<{
101
- message: string;
102
- }>;
103
- /**
104
- * Verify email with token
105
- */
106
- verifyEmail: (token: string) => Promise<{
107
- message?: string;
108
- verified?: boolean;
109
- session_token?: string;
110
- user?: User;
111
- expires_at?: string;
112
- }>;
113
- /**
114
- * Resend verification email.
115
- * Can be called with a session token (authenticated) or email (unauthenticated).
116
- */
117
- resendVerification: (sessionTokenOrEmail: string, options?: {
118
- email?: string;
119
- onTokenRotated?: (newToken: string) => void;
120
- }) => Promise<{
121
- message: string;
122
- }>;
123
- };
124
- user: {
125
- /**
126
- * Update user profile
127
- */
128
- update: (sessionToken: string, data: {
129
- full_name?: string;
130
- avatar_url?: string;
131
- }, options?: {
132
- onTokenRotated?: (newToken: string) => void;
133
- }) => Promise<User>;
134
- /**
135
- * Change password
136
- */
137
- changePassword: (sessionToken: string, currentPassword: string, newPassword: string, options?: {
138
- onTokenRotated?: (newToken: string) => void;
139
- }) => Promise<{
140
- message: string;
141
- }>;
142
- /**
143
- * Change email
144
- */
145
- changeEmail: (sessionToken: string, newEmail: string, password: string, options?: {
146
- onTokenRotated?: (newToken: string) => void;
147
- }) => Promise<{
148
- message: string;
149
- }>;
150
- /**
151
- * Delete account
152
- */
153
- deleteAccount: (sessionToken: string, password: string, options?: {
154
- onTokenRotated?: (newToken: string) => void;
155
- }) => Promise<{
156
- message: string;
157
- }>;
158
- };
159
- secrets: {
160
- /**
161
- * Get a secret from the tenant vault
162
- *
163
- * @example
164
- * ```typescript
165
- * const result = await scalemule.secrets.get('ANONYMOUS_USER_SALT')
166
- * if (result.success) {
167
- * console.log('Salt:', result.data.value)
168
- * }
169
- * ```
170
- */
171
- get: (key: string) => Promise<{
172
- value: string;
173
- version: number;
174
- }>;
175
- /**
176
- * Set a secret in the tenant vault
177
- *
178
- * @example
179
- * ```typescript
180
- * await scalemule.secrets.set('ANONYMOUS_USER_SALT', 'my-secret-salt')
181
- * ```
182
- */
183
- set: (key: string, value: string) => Promise<{
184
- value: string;
185
- version: number;
186
- }>;
187
- /**
188
- * Delete a secret from the tenant vault
189
- */
190
- delete: (key: string) => Promise<void>;
191
- /**
192
- * List all secrets in the tenant vault
193
- */
194
- list: () => Promise<{
195
- secrets: Array<{
196
- path: string;
197
- version: number;
198
- }>;
199
- }>;
200
- /**
201
- * Get secret version history
202
- */
203
- versions: (key: string) => Promise<{
204
- versions: Array<{
205
- version: number;
206
- created_at: string;
207
- }>;
208
- }>;
209
- /**
210
- * Rollback to a specific version
211
- */
212
- rollback: (key: string, version: number) => Promise<{
213
- value: string;
214
- version: number;
215
- }>;
216
- /**
217
- * Rotate a secret (copy current version as new version)
218
- */
219
- rotate: (key: string, newValue: string) => Promise<{
220
- value: string;
221
- version: number;
222
- }>;
223
- };
224
- bundles: {
225
- /**
226
- * Get a bundle (structured secret like database credentials)
227
- *
228
- * @param key - Bundle key (e.g., 'database/prod')
229
- * @param resolve - Whether to resolve inheritance (default: true)
230
- *
231
- * @example
232
- * ```typescript
233
- * const result = await scalemule.bundles.get('database/prod')
234
- * if (result.success) {
235
- * console.log('DB Host:', result.data.data.host)
236
- * }
237
- * ```
238
- */
239
- get: <T = Record<string, unknown>>(key: string, resolve?: boolean) => Promise<{
240
- type: string;
241
- data: T;
242
- version: number;
243
- inherits_from?: string;
244
- }>;
245
- /**
246
- * Set a bundle (structured secret)
247
- *
248
- * @param key - Bundle key
249
- * @param type - Bundle type: 'mysql', 'postgres', 'redis', 's3', 'oauth', 'smtp', 'generic'
250
- * @param data - Bundle data (structure depends on type)
251
- * @param inheritsFrom - Optional parent bundle key for inheritance
252
- *
253
- * @example
254
- * ```typescript
255
- * // Create a MySQL bundle
256
- * await scalemule.bundles.set('database/prod', 'mysql', {
257
- * host: 'db.example.com',
258
- * port: 3306,
259
- * username: 'app',
260
- * password: 'secret',
261
- * database: 'myapp'
262
- * })
263
- *
264
- * // Create a bundle that inherits from another
265
- * await scalemule.bundles.set('database/staging', 'mysql', {
266
- * host: 'staging-db.example.com', // Override just the host
267
- * }, 'database/prod')
268
- * ```
269
- */
270
- set: <T = Record<string, unknown>>(key: string, type: string, data: T, inheritsFrom?: string) => Promise<{
271
- type: string;
272
- data: T;
273
- version: number;
274
- }>;
275
- /**
276
- * Delete a bundle
277
- */
278
- delete: (key: string) => Promise<void>;
279
- /**
280
- * List all bundles
281
- */
282
- list: () => Promise<{
283
- bundles: Array<{
284
- path: string;
285
- type: string;
286
- version: number;
287
- inherits_from?: string;
288
- }>;
289
- }>;
290
- /**
291
- * Get connection URL for a database bundle
292
- *
293
- * @example
294
- * ```typescript
295
- * const result = await scalemule.bundles.connectionUrl('database/prod')
296
- * if (result.success) {
297
- * const client = mysql.createConnection(result.data.url)
298
- * }
299
- * ```
300
- */
301
- connectionUrl: (key: string) => Promise<{
302
- url: string;
303
- }>;
304
- };
305
- vaultAudit: {
306
- /**
307
- * Query audit logs for your tenant's vault operations
308
- *
309
- * @example
310
- * ```typescript
311
- * const result = await scalemule.vaultAudit.query({
312
- * action: 'read',
313
- * path: 'database/*',
314
- * since: '2026-01-01'
315
- * })
316
- * ```
317
- */
318
- query: (options?: {
319
- action?: "read" | "write" | "delete" | "list";
320
- path?: string;
321
- since?: string;
322
- until?: string;
323
- limit?: number;
324
- }) => Promise<{
325
- logs: Array<{
326
- timestamp: string;
327
- action: string;
328
- resource_path: string;
329
- success: boolean;
330
- error_message?: string;
331
- }>;
332
- }>;
333
- };
334
- storage: {
335
- /**
336
- * List user's files
337
- */
338
- list: (userId: string, params?: ListFilesParams) => Promise<ListFilesResponse>;
339
- /**
340
- * Get file info
341
- */
342
- get: (fileId: string) => Promise<StorageFile>;
343
- /**
344
- * Delete file
345
- */
346
- delete: (userId: string, fileId: string) => Promise<void>;
347
- /**
348
- * Upload file (from server - use FormData)
349
- *
350
- * @param userId - The user ID who owns this file
351
- * @param file - File data to upload
352
- * @param options - Upload options
353
- * @param options.clientContext - End user context to forward (IP, user agent, etc.)
354
- *
355
- * @example
356
- * ```typescript
357
- * // Forward end user context for proper attribution
358
- * const result = await scalemule.storage.upload(
359
- * userId,
360
- * { buffer, filename, contentType },
361
- * { clientContext: extractClientContext(request) }
362
- * )
363
- * ```
364
- */
365
- upload: (userId: string, file: {
366
- buffer: BlobPart;
367
- filename: string;
368
- contentType: string;
369
- }, options?: {
370
- clientContext?: ClientContext;
371
- }) => Promise<UploadResponse>;
372
- };
373
- webhooks: {
374
- /**
375
- * Create a new webhook subscription
376
- *
377
- * @example
378
- * ```typescript
379
- * const result = await scalemule.webhooks.create({
380
- * webhook_name: 'Video Status Webhook',
381
- * url: 'https://myapp.com/api/webhooks/scalemule',
382
- * events: ['video.ready', 'video.failed']
383
- * })
384
- *
385
- * // Store the secret for signature verification
386
- * console.log('Webhook secret:', result.secret)
387
- * ```
388
- */
389
- create: (data: {
390
- webhook_name: string;
391
- url: string;
392
- events: string[];
393
- }) => Promise<{
394
- id: string;
395
- secret: string;
396
- url: string;
397
- events: string[];
398
- }>;
399
- /**
400
- * List all webhook subscriptions
401
- */
402
- list: () => Promise<{
403
- webhooks: Array<{
404
- id: string;
405
- webhook_name: string;
406
- url: string;
407
- events: string[];
408
- is_enabled: boolean;
409
- }>;
410
- }>;
411
- /**
412
- * Delete a webhook subscription
413
- */
414
- delete: (id: string) => Promise<void>;
415
- /**
416
- * Update a webhook subscription
417
- */
418
- update: (id: string, data: {
419
- url?: string;
420
- events?: string[];
421
- is_enabled?: boolean;
422
- }) => Promise<{
423
- id: string;
424
- url: string;
425
- events: string[];
426
- }>;
427
- /**
428
- * Get available webhook event types
429
- */
430
- eventTypes: () => Promise<{
431
- events: Array<{
432
- event_name: string;
433
- event_description: string;
434
- payload_schema: Record<string, unknown>;
435
- }>;
436
- }>;
437
- };
438
- analytics: {
439
- /**
440
- * Track an analytics event
441
- *
442
- * IMPORTANT: When calling from server-side code (API routes), always pass
443
- * clientContext to ensure the real end user's IP is recorded, not the server's IP.
444
- *
445
- * @example
446
- * ```typescript
447
- * // In an API route
448
- * import { extractClientContext, createServerClient } from '@scalemule/nextjs/server'
449
- *
450
- * export async function POST(request: NextRequest) {
451
- * const clientContext = extractClientContext(request)
452
- * const scalemule = createServerClient()
453
- *
454
- * await scalemule.analytics.trackEvent({
455
- * event_name: 'button_clicked',
456
- * properties: { button_id: 'signup' }
457
- * }, { clientContext })
458
- * }
459
- * ```
460
- */
461
- trackEvent: (event: {
462
- event_name: string;
463
- event_category?: string;
464
- properties?: Record<string, unknown>;
465
- user_id?: string;
466
- session_id?: string;
467
- anonymous_id?: string;
468
- session_duration_seconds?: number;
469
- page_url?: string;
470
- page_title?: string;
471
- referrer?: string;
472
- landing_page?: string;
473
- device_type?: string;
474
- device_brand?: string;
475
- device_model?: string;
476
- browser?: string;
477
- browser_version?: string;
478
- os?: string;
479
- os_version?: string;
480
- screen_resolution?: string;
481
- viewport_size?: string;
482
- utm_source?: string;
483
- utm_medium?: string;
484
- utm_campaign?: string;
485
- utm_term?: string;
486
- utm_content?: string;
487
- client_timestamp?: string;
488
- timestamp?: string;
489
- }, options?: {
490
- clientContext?: ClientContext;
491
- }) => Promise<{
492
- tracked: number;
493
- session_id?: string;
494
- }>;
495
- /**
496
- * Track a page view
497
- *
498
- * @example
499
- * ```typescript
500
- * await scalemule.analytics.trackPageView({
501
- * page_url: 'https://example.com/products',
502
- * page_title: 'Products',
503
- * referrer: 'https://google.com'
504
- * }, { clientContext })
505
- * ```
506
- */
507
- trackPageView: (data: {
508
- page_url: string;
509
- page_title?: string;
510
- referrer?: string;
511
- session_id?: string;
512
- user_id?: string;
513
- }, options?: {
514
- clientContext?: ClientContext;
515
- }) => Promise<{
516
- tracked: number;
517
- session_id?: string;
518
- }>;
519
- /**
520
- * Track multiple events in a batch (max 100)
521
- *
522
- * @example
523
- * ```typescript
524
- * await scalemule.analytics.trackBatch([
525
- * { event_name: 'item_viewed', properties: { item_id: '123' } },
526
- * { event_name: 'item_added_to_cart', properties: { item_id: '123' } }
527
- * ], { clientContext })
528
- * ```
529
- */
530
- trackBatch: (events: Array<{
531
- event_name: string;
532
- event_category?: string;
533
- properties?: Record<string, unknown>;
534
- user_id?: string;
535
- session_id?: string;
536
- anonymous_id?: string;
537
- session_duration_seconds?: number;
538
- page_url?: string;
539
- page_title?: string;
540
- referrer?: string;
541
- landing_page?: string;
542
- device_type?: string;
543
- browser?: string;
544
- os?: string;
545
- screen_resolution?: string;
546
- viewport_size?: string;
547
- utm_source?: string;
548
- utm_medium?: string;
549
- utm_campaign?: string;
550
- utm_term?: string;
551
- utm_content?: string;
552
- client_timestamp?: string;
553
- timestamp?: string;
554
- }>, options?: {
555
- clientContext?: ClientContext;
556
- }) => Promise<{
557
- tracked: number;
558
- }>;
559
- };
560
- flags: {
561
- evaluate: <T = unknown>(flagKey: string, context?: Record<string, unknown>, environment?: string, options?: {
562
- clientContext?: ClientContext;
563
- }) => Promise<{
564
- flag_id: string;
565
- flag_key: string;
566
- environment: string;
567
- value: T;
568
- reason: string;
569
- matched_rule_id?: string | null;
570
- variant_key?: string | null;
571
- bucket?: number | null;
572
- }>;
573
- evaluateBatch: (flagKeys: string[], context?: Record<string, unknown>, environment?: string, options?: {
574
- clientContext?: ClientContext;
575
- }) => Promise<Record<string, {
576
- flag_id: string;
577
- flag_key: string;
578
- environment: string;
579
- value: unknown;
580
- reason: string;
581
- matched_rule_id?: string | null;
582
- variant_key?: string | null;
583
- bucket?: number | null;
584
- }>>;
585
- evaluateAll: (context?: Record<string, unknown>, environment?: string, options?: {
586
- clientContext?: ClientContext;
587
- }) => Promise<Record<string, {
588
- flag_id: string;
589
- flag_key: string;
590
- environment: string;
591
- value: unknown;
592
- reason: string;
593
- matched_rule_id?: string | null;
594
- variant_key?: string | null;
595
- bucket?: number | null;
596
- }>>;
597
- };
598
- }
599
- /**
600
- * Create a server client with environment-based defaults
601
- */
602
- declare function createServerClient(config?: Partial<ServerConfig>): ScaleMuleServer;
603
-
604
- /**
605
- * ScaleMule Webhook Helpers
606
- *
607
- * Provides utilities for webhook signature verification and route handlers
608
- * for video processing events and other ScaleMule webhooks.
609
- *
610
- * @example
611
- * ```typescript
612
- * // app/api/webhooks/scalemule/route.ts
613
- * import { createWebhookRoutes } from '@scalemule/nextjs/server'
614
- *
615
- * export const { POST } = createWebhookRoutes({
616
- * secret: process.env.SCALEMULE_WEBHOOK_SECRET,
617
- * onVideoReady: async (event) => {
618
- * console.log('Video ready:', event.video_id)
619
- * await updateDocument('videos', event.video_id, { status: 'ready' })
620
- * },
621
- * onVideoFailed: async (event) => {
622
- * console.log('Video failed:', event.video_id, event.reason)
623
- * }
624
- * })
625
- * ```
626
- */
627
-
628
- interface WebhookEvent<T = Record<string, unknown>> {
629
- event: string;
630
- timestamp: number;
631
- data: T;
632
- }
633
- interface VideoReadyEvent {
634
- video_id: string;
635
- application_id: string;
636
- duration_seconds?: number;
637
- width?: number;
638
- height?: number;
639
- thumbnail_url?: string;
640
- playlist_url?: string;
641
- }
642
- interface VideoFailedEvent {
643
- video_id: string;
644
- application_id: string;
645
- reason: string;
646
- }
647
- interface VideoUploadedEvent {
648
- video_id: string;
649
- application_id: string;
650
- filename?: string;
651
- size_bytes?: number;
652
- }
653
- interface VideoTranscodedEvent {
654
- video_id: string;
655
- application_id: string;
656
- derivative_count: number;
657
- }
658
- interface WebhookRoutesConfig {
659
- /** ScaleMule client configuration (optional, uses env vars by default) */
660
- client?: Partial<ServerConfig>;
661
- /** Webhook secret for signature verification (recommended for security) */
662
- secret?: string;
663
- /** Handler for video.ready events */
664
- onVideoReady?: (event: VideoReadyEvent) => void | Promise<void>;
665
- /** Handler for video.failed events */
666
- onVideoFailed?: (event: VideoFailedEvent) => void | Promise<void>;
667
- /** Handler for video.uploaded events */
668
- onVideoUploaded?: (event: VideoUploadedEvent) => void | Promise<void>;
669
- /** Handler for video.transcoded events */
670
- onVideoTranscoded?: (event: VideoTranscodedEvent) => void | Promise<void>;
671
- /** Generic handler for any webhook event */
672
- onEvent?: (event: WebhookEvent) => void | Promise<void>;
673
- }
674
- /**
675
- * Verify webhook signature using HMAC-SHA256
676
- *
677
- * ScaleMule webhooks include a signature header in the format: sha256=<hex_signature>
678
- *
679
- * @param payload - Raw request body as string
680
- * @param signature - Value of X-Webhook-Signature header
681
- * @param secret - Your webhook secret
682
- * @returns true if signature is valid
683
- *
684
- * @example
685
- * ```typescript
686
- * const isValid = verifyWebhookSignature(body, signature, secret)
687
- * if (!isValid) {
688
- * return new Response('Invalid signature', { status: 401 })
689
- * }
690
- * ```
691
- */
692
- declare function verifyWebhookSignature(payload: string, signature: string, secret: string): boolean;
693
- /**
694
- * Parse a webhook event from the raw payload
695
- *
696
- * @param payload - Raw request body as string
697
- * @returns Parsed webhook event
698
- */
699
- declare function parseWebhookEvent<T = Record<string, unknown>>(payload: string): WebhookEvent<T>;
700
- /**
701
- * Register a webhook for video events
702
- *
703
- * @param url - The URL to receive webhook notifications
704
- * @param options - Registration options
705
- * @returns The webhook ID and secret for signature verification
706
- *
707
- * @example
708
- * ```typescript
709
- * const { id, secret } = await registerVideoWebhook(
710
- * 'https://myapp.com/api/webhooks/scalemule',
711
- * { events: ['video.ready', 'video.failed'] }
712
- * )
713
- *
714
- * // Store the secret securely for signature verification
715
- * await saveToEnv('SCALEMULE_WEBHOOK_SECRET', secret)
716
- * ```
717
- */
718
- declare function registerVideoWebhook(url: string, options?: {
719
- /** Events to subscribe to (defaults to video.ready and video.failed) */
720
- events?: ('video.ready' | 'video.failed' | 'video.uploaded' | 'video.transcoded')[];
721
- /** Human-readable webhook name */
722
- name?: string;
723
- /** Client configuration */
724
- clientConfig?: Partial<ServerConfig>;
725
- }): Promise<{
726
- id: string;
727
- secret: string;
728
- }>;
729
- type RouteHandler$1 = (request: Request, context: {
730
- params: Promise<{
731
- scalemule?: string[];
732
- }>;
733
- }) => Promise<Response>;
734
- /**
735
- * Create Next.js App Router route handlers for ScaleMule webhooks
736
- *
737
- * Returns a POST handler that:
738
- * - Verifies webhook signature (if secret provided)
739
- * - Parses the event payload
740
- * - Calls appropriate event handlers
741
- * - Returns proper responses
742
- *
743
- * @param config - Webhook routes configuration
744
- * @returns Object with POST handler for use in route.ts
745
- *
746
- * @example
747
- * ```typescript
748
- * // app/api/webhooks/scalemule/route.ts
749
- * import { createWebhookRoutes } from '@scalemule/nextjs/server'
750
- *
751
- * export const { POST } = createWebhookRoutes({
752
- * secret: process.env.SCALEMULE_WEBHOOK_SECRET,
753
- * onVideoReady: async (event) => {
754
- * // Update your database when video is ready
755
- * await db.videos.update({
756
- * where: { id: event.video_id },
757
- * data: {
758
- * status: 'ready',
759
- * duration: event.duration_seconds,
760
- * thumbnailUrl: event.thumbnail_url,
761
- * }
762
- * })
763
- * },
764
- * onVideoFailed: async (event) => {
765
- * // Handle failed video processing
766
- * await notifyUser(event.video_id, event.reason)
767
- * }
768
- * })
769
- * ```
770
- */
771
- declare function createWebhookRoutes(config?: WebhookRoutesConfig): {
772
- POST: RouteHandler$1;
773
- };
774
-
775
- /**
776
- * Simplified webhook handler for 1-line setup.
777
- *
778
- * Usage in your Next.js app:
779
- * ```ts
780
- * // app/api/webhooks/scalemule/route.ts
781
- * import { createWebhookHandler } from '@scalemule/nextjs/server/webhooks'
782
- *
783
- * export const POST = createWebhookHandler({
784
- * secret: process.env.SCALEMULE_WEBHOOK_SECRET,
785
- * onEvent: {
786
- * 'video.transcoding.completed': async (event) => { ... },
787
- * 'storage.file.uploaded': async (event) => { ... },
788
- * }
789
- * })
790
- * ```
791
- */
792
-
793
- interface WebhookHandlerConfig {
794
- /** Webhook secret for signature verification */
795
- secret?: string;
796
- /** Map of event name → handler function */
797
- onEvent?: Record<string, (event: WebhookEvent) => void | Promise<void>>;
798
- }
799
- type RouteHandler = (request: Request) => Promise<Response>;
800
- /**
801
- * Create a webhook handler for ScaleMule events.
802
- *
803
- * Simpler alternative to createWebhookRoutes() — uses an event map
804
- * instead of separate onVideoReady, onVideoFailed, etc. callbacks.
805
- */
806
- declare function createWebhookHandler(config?: WebhookHandlerConfig): RouteHandler;
807
-
808
- export { type ServerConfig as S, type VideoFailedEvent as V, type WebhookEvent as W, ScaleMuleServer as a, type VideoReadyEvent as b, type VideoTranscodedEvent as c, type VideoUploadedEvent as d, type WebhookRoutesConfig as e, createServerClient as f, createWebhookHandler as g, createWebhookRoutes as h, resolveGatewayUrl as i, parseWebhookEvent as p, registerVideoWebhook as r, verifyWebhookSignature as v };