@renderingvideo/sdk 1.0.0

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,559 @@
1
+ /**
2
+ * RenderingVideo Node.js SDK - Type Definitions
3
+ */
4
+ interface VideoMeta {
5
+ version: string;
6
+ width: number;
7
+ height: number;
8
+ fps?: number;
9
+ background?: string;
10
+ }
11
+ interface VideoConfig {
12
+ meta: VideoMeta;
13
+ tracks: Track[];
14
+ assets?: Record<string, Asset>;
15
+ }
16
+ interface Track {
17
+ clips: Clip[];
18
+ }
19
+ interface Clip {
20
+ type: string;
21
+ start: number;
22
+ duration: number;
23
+ [key: string]: unknown;
24
+ }
25
+ interface Asset {
26
+ type: 'image' | 'video' | 'audio' | 'font';
27
+ src: string;
28
+ [key: string]: unknown;
29
+ }
30
+ type TaskStatus = 'created' | 'rendering' | 'completed' | 'failed';
31
+ interface Task {
32
+ success: boolean;
33
+ taskId: string;
34
+ videoTaskId?: string;
35
+ renderTaskId?: string;
36
+ previewUrl?: string;
37
+ viewerUrl?: string;
38
+ configUrl?: string;
39
+ videoUrl?: string;
40
+ status: TaskStatus;
41
+ quality?: string;
42
+ costCredits?: number;
43
+ cost?: number;
44
+ remainingCredits?: number;
45
+ width?: number;
46
+ height?: number;
47
+ duration?: number;
48
+ createdAt?: string;
49
+ completedAt?: string;
50
+ metadata?: Record<string, unknown>;
51
+ message?: string;
52
+ alreadyRendered?: boolean;
53
+ }
54
+ interface TaskList {
55
+ success: boolean;
56
+ tasks: Task[];
57
+ pagination: {
58
+ page: number;
59
+ limit: number;
60
+ total: number;
61
+ };
62
+ }
63
+ type FileType = 'image' | 'video' | 'audio';
64
+ interface UploadedFile {
65
+ id: string;
66
+ name: string;
67
+ url: string;
68
+ type: FileType;
69
+ mimeType: string;
70
+ size: number;
71
+ createdAt: string;
72
+ }
73
+ interface UploadResult {
74
+ success: boolean;
75
+ message: string;
76
+ count: number;
77
+ assets: UploadedFile[];
78
+ }
79
+ interface FileList {
80
+ success: boolean;
81
+ files: UploadedFile[];
82
+ pagination: {
83
+ page: number;
84
+ limit: number;
85
+ total: number;
86
+ };
87
+ }
88
+ interface DeleteFileResult {
89
+ success: boolean;
90
+ fileId: string;
91
+ deleted: boolean;
92
+ message: string;
93
+ }
94
+ interface Credits {
95
+ success: boolean;
96
+ credits: number;
97
+ currency: string;
98
+ }
99
+ interface PreviewResult {
100
+ success: boolean;
101
+ tempId: string;
102
+ previewUrl: string;
103
+ viewerUrl?: string;
104
+ expiresIn: string;
105
+ note?: string;
106
+ }
107
+ interface PreviewConfig {
108
+ success: boolean;
109
+ tempId: string;
110
+ config: VideoConfig;
111
+ }
112
+ interface DeletePreviewResult {
113
+ success: boolean;
114
+ tempId: string;
115
+ deleted: boolean;
116
+ message: string;
117
+ }
118
+ interface ConvertPreviewResult {
119
+ success: boolean;
120
+ tempId: string;
121
+ converted: boolean;
122
+ taskId: string;
123
+ videoTaskId?: string;
124
+ previewUrl?: string;
125
+ viewerUrl?: string;
126
+ configUrl?: string;
127
+ message: string;
128
+ }
129
+ interface RenderPreviewResult {
130
+ success: boolean;
131
+ tempId: string;
132
+ converted: boolean;
133
+ convertMessage?: string;
134
+ configUrl?: string;
135
+ taskId: string;
136
+ renderTaskId?: string;
137
+ status: TaskStatus;
138
+ quality?: string;
139
+ width?: number;
140
+ height?: number;
141
+ cost?: number;
142
+ remainingCredits?: number;
143
+ message?: string;
144
+ previewUrl?: string;
145
+ viewerUrl?: string;
146
+ }
147
+ interface DeleteTaskResult {
148
+ success: boolean;
149
+ taskId: string;
150
+ videoTaskId?: string;
151
+ deleted: boolean;
152
+ remoteDeleted: boolean;
153
+ message: string;
154
+ }
155
+ interface ClientOptions {
156
+ apiKey: string;
157
+ baseUrl?: string;
158
+ timeout?: number;
159
+ }
160
+ interface CreateVideoOptions {
161
+ config: VideoConfig;
162
+ metadata?: Record<string, unknown>;
163
+ }
164
+ interface ListTasksOptions {
165
+ page?: number;
166
+ limit?: number;
167
+ status?: TaskStatus;
168
+ }
169
+ interface RenderOptions {
170
+ webhookUrl?: string;
171
+ numWorkers?: number;
172
+ }
173
+ interface ListFilesOptions {
174
+ page?: number;
175
+ limit?: number;
176
+ type?: FileType;
177
+ }
178
+ interface UploadOptions {
179
+ file?: Blob | File;
180
+ files?: (Blob | File)[];
181
+ }
182
+ interface ConvertPreviewOptions {
183
+ category?: string;
184
+ }
185
+ interface RenderPreviewOptions {
186
+ category?: string;
187
+ webhookUrl?: string;
188
+ numWorkers?: number;
189
+ }
190
+ interface ApiResponse<T = unknown> {
191
+ success: boolean;
192
+ data?: T;
193
+ error?: string;
194
+ code?: string;
195
+ details?: Record<string, unknown>;
196
+ }
197
+ interface WebhookPayload {
198
+ taskId: string;
199
+ renderTaskId: string;
200
+ status: 'completed' | 'failed';
201
+ videoUrl?: string;
202
+ error?: string | null;
203
+ timestamp: string;
204
+ }
205
+
206
+ /**
207
+ * RenderingVideo Node.js SDK - Main Client
208
+ */
209
+
210
+ /**
211
+ * Video API Client
212
+ */
213
+ declare class VideoClient {
214
+ private readonly baseUrl;
215
+ private readonly apiKey;
216
+ private readonly timeout;
217
+ constructor(baseUrl: string, apiKey: string, timeout: number);
218
+ private request;
219
+ /**
220
+ * Create a new video task (does not start rendering)
221
+ * @example
222
+ * ```typescript
223
+ * const task = await client.video.create({
224
+ * config: {
225
+ * meta: { version: '2.0.0', width: 1920, height: 1080, fps: 30 },
226
+ * tracks: [{ clips: [{ type: 'text', text: 'Hello World', start: 0, duration: 5 }] }]
227
+ * },
228
+ * metadata: { projectId: 'proj_123' }
229
+ * });
230
+ * ```
231
+ */
232
+ create(options: CreateVideoOptions): Promise<Task>;
233
+ /**
234
+ * List video tasks
235
+ * @example
236
+ * ```typescript
237
+ * const { tasks, pagination } = await client.video.list({ page: 1, limit: 20, status: 'completed' });
238
+ * ```
239
+ */
240
+ list(options?: ListTasksOptions): Promise<TaskList>;
241
+ /**
242
+ * Get task details by ID
243
+ * @example
244
+ * ```typescript
245
+ * const task = await client.video.get('abc123def456');
246
+ * console.log(task.status, task.videoUrl);
247
+ * ```
248
+ */
249
+ get(taskId: string): Promise<Task>;
250
+ /**
251
+ * Delete a video task permanently
252
+ * @example
253
+ * ```typescript
254
+ * const result = await client.video.delete('abc123def456');
255
+ * console.log(result.deleted, result.remoteDeleted);
256
+ * ```
257
+ */
258
+ delete(taskId: string): Promise<DeleteTaskResult>;
259
+ /**
260
+ * Trigger rendering for a task
261
+ * @example
262
+ * ```typescript
263
+ * const result = await client.video.render('abc123def456', {
264
+ * webhookUrl: 'https://example.com/webhook',
265
+ * numWorkers: 5
266
+ * });
267
+ * ```
268
+ */
269
+ render(taskId: string, options?: RenderOptions): Promise<Task>;
270
+ /**
271
+ * Create task and immediately start rendering (convenience method)
272
+ * @example
273
+ * ```typescript
274
+ * const task = await client.video.createAndRender({
275
+ * config: { ... },
276
+ * webhookUrl: 'https://example.com/webhook'
277
+ * });
278
+ * ```
279
+ */
280
+ createAndRender(options: CreateVideoOptions & RenderOptions): Promise<Task>;
281
+ }
282
+ /**
283
+ * File API Client
284
+ */
285
+ declare class FileClient {
286
+ private readonly baseUrl;
287
+ private readonly apiKey;
288
+ private readonly timeout;
289
+ constructor(baseUrl: string, apiKey: string, timeout: number);
290
+ private request;
291
+ /**
292
+ * Upload files (images, videos, audio)
293
+ * @example
294
+ * ```typescript
295
+ * // In Node.js with FormData
296
+ * const formData = new FormData();
297
+ * formData.append('file', fileBlob, 'image.png');
298
+ * const result = await client.files.upload(formData);
299
+ *
300
+ * // Multiple files
301
+ * formData.append('files', file1Blob, 'video.mp4');
302
+ * formData.append('files', file2Blob, 'audio.mp3');
303
+ * const result = await client.files.upload(formData);
304
+ * ```
305
+ */
306
+ upload(formData: FormData): Promise<UploadResult>;
307
+ /**
308
+ * Upload a single file from buffer (Node.js)
309
+ * @example
310
+ * ```typescript
311
+ * const buffer = fs.readFileSync('./image.png');
312
+ * const result = await client.files.uploadBuffer(buffer, 'image.png', 'image/png');
313
+ * ```
314
+ */
315
+ uploadBuffer(buffer: Buffer, filename: string, mimeType: string): Promise<UploadResult>;
316
+ /**
317
+ * Upload a single file from Blob/File
318
+ * @example
319
+ * ```typescript
320
+ * const blob = new Blob([data], { type: 'image/png' });
321
+ * const result = await client.files.uploadFile(blob, 'image.png');
322
+ * ```
323
+ */
324
+ uploadFile(file: Blob | File, filename?: string): Promise<UploadResult>;
325
+ /**
326
+ * List uploaded files
327
+ * @example
328
+ * ```typescript
329
+ * const { files, pagination } = await client.files.list({ type: 'image', limit: 50 });
330
+ * ```
331
+ */
332
+ list(options?: ListFilesOptions): Promise<FileList>;
333
+ /**
334
+ * Delete a file
335
+ * @example
336
+ * ```typescript
337
+ * const result = await client.files.delete('asset_001');
338
+ * ```
339
+ */
340
+ delete(fileId: string): Promise<DeleteFileResult>;
341
+ /**
342
+ * Get file by ID (convenience method - searches through list)
343
+ * @example
344
+ * ```typescript
345
+ * const file = await client.files.get('asset_001');
346
+ * ```
347
+ */
348
+ get(fileId: string): Promise<UploadedFile | null>;
349
+ }
350
+ /**
351
+ * Preview API Client
352
+ */
353
+ declare class PreviewClient {
354
+ private readonly baseUrl;
355
+ private readonly apiKey;
356
+ private readonly timeout;
357
+ constructor(baseUrl: string, apiKey: string, timeout: number);
358
+ private request;
359
+ /**
360
+ * Create a temporary preview link (7 days validity, no credits consumed)
361
+ * @example
362
+ * ```typescript
363
+ * const preview = await client.preview.create({
364
+ * meta: { version: '2.0.0', width: 1920, height: 1080 },
365
+ * tracks: [{ clips: [{ type: 'text', text: 'Preview', start: 0, duration: 5 }] }]
366
+ * });
367
+ * console.log(preview.previewUrl, preview.tempId);
368
+ * ```
369
+ */
370
+ create(config: VideoConfig): Promise<PreviewResult>;
371
+ /**
372
+ * Get preview configuration
373
+ * @example
374
+ * ```typescript
375
+ * const { config } = await client.preview.get('temp_abc123');
376
+ * ```
377
+ */
378
+ get(tempId: string): Promise<PreviewConfig>;
379
+ /**
380
+ * Delete a preview link
381
+ * @example
382
+ * ```typescript
383
+ * const result = await client.preview.delete('temp_abc123');
384
+ * ```
385
+ */
386
+ delete(tempId: string): Promise<DeletePreviewResult>;
387
+ /**
388
+ * Convert preview to permanent task (does not start rendering)
389
+ * @example
390
+ * ```typescript
391
+ * const result = await client.preview.convert('temp_abc123', { category: 'marketing' });
392
+ * console.log(result.taskId);
393
+ * ```
394
+ */
395
+ convert(tempId: string, options?: ConvertPreviewOptions): Promise<ConvertPreviewResult>;
396
+ /**
397
+ * Convert preview to permanent task and immediately start rendering
398
+ * @example
399
+ * ```typescript
400
+ * const result = await client.preview.render('temp_abc123', {
401
+ * webhookUrl: 'https://example.com/webhook'
402
+ * });
403
+ * console.log(result.taskId, result.status);
404
+ * ```
405
+ */
406
+ render(tempId: string, options?: RenderPreviewOptions): Promise<RenderPreviewResult>;
407
+ }
408
+ /**
409
+ * Main RenderingVideo SDK Client
410
+ *
411
+ * @example
412
+ * ```typescript
413
+ * import { RenderingVideo } from '@renderingvideo/sdk';
414
+ *
415
+ * const client = new RenderingVideo({ apiKey: 'sk-xxx' });
416
+ *
417
+ * // Create and render a video
418
+ * const task = await client.video.create({ config: { ... } });
419
+ * await client.video.render(task.taskId);
420
+ *
421
+ * // Check credits
422
+ * const { credits } = await client.credits.get();
423
+ *
424
+ * // Upload files
425
+ * const { assets } = await client.files.uploadFile(imageBlob);
426
+ * ```
427
+ */
428
+ declare class RenderingVideo {
429
+ private readonly apiKey;
430
+ private readonly baseUrl;
431
+ private readonly timeout;
432
+ private _video;
433
+ private _files;
434
+ private _preview;
435
+ constructor(options: ClientOptions);
436
+ constructor(apiKey: string, options?: Partial<Omit<ClientOptions, 'apiKey'>>);
437
+ /**
438
+ * Video API operations
439
+ */
440
+ get video(): VideoClient;
441
+ /**
442
+ * File API operations (upload, list, delete)
443
+ */
444
+ get files(): FileClient;
445
+ /**
446
+ * Preview API operations
447
+ */
448
+ get preview(): PreviewClient;
449
+ /**
450
+ * Credits API operations
451
+ */
452
+ get credits(): CreditsClient;
453
+ /**
454
+ * Get masked API key for logging
455
+ */
456
+ get apiKeyPreview(): string;
457
+ /**
458
+ * Get the base URL being used
459
+ */
460
+ get baseURL(): string;
461
+ }
462
+ /**
463
+ * Credits API Client
464
+ */
465
+ declare class CreditsClient {
466
+ private readonly baseUrl;
467
+ private readonly apiKey;
468
+ private readonly timeout;
469
+ constructor(baseUrl: string, apiKey: string, timeout: number);
470
+ /**
471
+ * Get current credit balance
472
+ * @example
473
+ * ```typescript
474
+ * const { credits } = await client.credits.get();
475
+ * console.log(`You have ${credits} credits remaining`);
476
+ * ```
477
+ */
478
+ get(): Promise<Credits>;
479
+ /**
480
+ * Check if user has enough credits for a render
481
+ * @example
482
+ * ```typescript
483
+ * const hasCredits = await client.credits.hasEnough(100);
484
+ * ```
485
+ */
486
+ hasEnough(required: number): Promise<boolean>;
487
+ }
488
+
489
+ /**
490
+ * RenderingVideo Node.js SDK - Error Classes
491
+ */
492
+ declare class RenderingVideoError extends Error {
493
+ readonly code: string;
494
+ readonly details: Record<string, unknown>;
495
+ constructor(message: string, code: string, details?: Record<string, unknown>);
496
+ }
497
+ declare class AuthenticationError extends RenderingVideoError {
498
+ constructor(message: string, details?: Record<string, unknown>);
499
+ }
500
+ declare class InvalidApiKeyError extends RenderingVideoError {
501
+ constructor(message: string, details?: Record<string, unknown>);
502
+ }
503
+ declare class InsufficientCreditsError extends RenderingVideoError {
504
+ constructor(message: string, details?: Record<string, unknown>);
505
+ }
506
+ declare class ValidationError extends RenderingVideoError {
507
+ constructor(message: string, details?: Record<string, unknown>);
508
+ }
509
+ declare class NotFoundError extends RenderingVideoError {
510
+ constructor(message: string, details?: Record<string, unknown>);
511
+ }
512
+ declare class RateLimitError extends RenderingVideoError {
513
+ constructor(message: string, details?: Record<string, unknown>);
514
+ }
515
+ declare class AlreadyRenderingError extends RenderingVideoError {
516
+ constructor(message: string, details?: Record<string, unknown>);
517
+ }
518
+ declare class UploadError extends RenderingVideoError {
519
+ constructor(message: string, details?: Record<string, unknown>);
520
+ }
521
+ declare class StorageLimitError extends RenderingVideoError {
522
+ constructor(message: string, details?: Record<string, unknown>);
523
+ }
524
+ declare class RemoteError extends RenderingVideoError {
525
+ constructor(message: string, details?: Record<string, unknown>);
526
+ }
527
+
528
+ /**
529
+ * RenderingVideo Node.js SDK
530
+ *
531
+ * Official Node.js SDK for the RenderingVideo API
532
+ *
533
+ * @packageDocumentation
534
+ *
535
+ * @example
536
+ * ```typescript
537
+ * import { RenderingVideo } from '@renderingvideo/sdk';
538
+ *
539
+ * const client = new RenderingVideo({ apiKey: 'sk-xxx' });
540
+ *
541
+ * // Create a video task
542
+ * const task = await client.video.create({
543
+ * config: {
544
+ * meta: { version: '2.0.0', width: 1920, height: 1080, fps: 30 },
545
+ * tracks: [{ clips: [{ type: 'text', text: 'Hello World', start: 0, duration: 5 }] }]
546
+ * }
547
+ * });
548
+ *
549
+ * // Start rendering
550
+ * await client.video.render(task.taskId, {
551
+ * webhookUrl: 'https://example.com/webhook'
552
+ * });
553
+ *
554
+ * // Check credits
555
+ * const { credits } = await client.credits.get();
556
+ * ```
557
+ */
558
+
559
+ export { AlreadyRenderingError, type ApiResponse, type Asset, AuthenticationError, type ClientOptions, type Clip, type ConvertPreviewOptions, type ConvertPreviewResult, type CreateVideoOptions, type Credits, CreditsClient, type DeleteFileResult, type DeletePreviewResult, type DeleteTaskResult, FileClient, type FileList, type FileType, InsufficientCreditsError, InvalidApiKeyError, type ListFilesOptions, type ListTasksOptions, NotFoundError, PreviewClient, type PreviewConfig, type PreviewResult, RateLimitError, RemoteError, type RenderOptions, type RenderPreviewOptions, type RenderPreviewResult, RenderingVideo, RenderingVideoError, StorageLimitError, type Task, type TaskList, type TaskStatus, type Track, UploadError, type UploadOptions, type UploadResult, type UploadedFile, ValidationError, VideoClient, type VideoConfig, type VideoMeta, type WebhookPayload, RenderingVideo as default };