@scalemule/nextjs 0.1.60 → 0.1.61

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