@blitzreels/sdk 0.1.4 → 0.1.6

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 (110) hide show
  1. package/README.md +52 -0
  2. package/dist/client.d.ts +190 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +72 -0
  5. package/dist/client.js.map +1 -0
  6. package/dist/index.d.ts +16 -1209
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +3 -1162
  9. package/dist/index.js.map +1 -1
  10. package/dist/resources/ai-edit.d.ts +23 -0
  11. package/dist/resources/ai-edit.d.ts.map +1 -0
  12. package/dist/resources/ai-edit.js +91 -0
  13. package/dist/resources/ai-edit.js.map +1 -0
  14. package/dist/resources/auth-projects.d.ts +24 -0
  15. package/dist/resources/auth-projects.d.ts.map +1 -0
  16. package/dist/resources/auth-projects.js +115 -0
  17. package/dist/resources/auth-projects.js.map +1 -0
  18. package/dist/resources/captions.d.ts +39 -0
  19. package/dist/resources/captions.d.ts.map +1 -0
  20. package/dist/resources/captions.js +194 -0
  21. package/dist/resources/captions.js.map +1 -0
  22. package/dist/resources/content-audio.d.ts +20 -0
  23. package/dist/resources/content-audio.d.ts.map +1 -0
  24. package/dist/resources/content-audio.js +98 -0
  25. package/dist/resources/content-audio.js.map +1 -0
  26. package/dist/resources/effects-workflows.d.ts +29 -0
  27. package/dist/resources/effects-workflows.d.ts.map +1 -0
  28. package/dist/resources/effects-workflows.js +154 -0
  29. package/dist/resources/effects-workflows.js.map +1 -0
  30. package/dist/resources/exports-jobs.d.ts +19 -0
  31. package/dist/resources/exports-jobs.d.ts.map +1 -0
  32. package/dist/resources/exports-jobs.js +88 -0
  33. package/dist/resources/exports-jobs.js.map +1 -0
  34. package/dist/resources/faceless.d.ts +18 -0
  35. package/dist/resources/faceless.d.ts.map +1 -0
  36. package/dist/resources/faceless.js +89 -0
  37. package/dist/resources/faceless.js.map +1 -0
  38. package/dist/resources/formats.d.ts +9 -0
  39. package/dist/resources/formats.d.ts.map +1 -0
  40. package/dist/resources/formats.js +21 -0
  41. package/dist/resources/formats.js.map +1 -0
  42. package/dist/resources/libraries.d.ts +19 -0
  43. package/dist/resources/libraries.d.ts.map +1 -0
  44. package/dist/resources/libraries.js +89 -0
  45. package/dist/resources/libraries.js.map +1 -0
  46. package/dist/resources/media-clips.d.ts +57 -0
  47. package/dist/resources/media-clips.d.ts.map +1 -0
  48. package/dist/resources/media-clips.js +346 -0
  49. package/dist/resources/media-clips.js.map +1 -0
  50. package/dist/resources/timeline.d.ts +30 -0
  51. package/dist/resources/timeline.d.ts.map +1 -0
  52. package/dist/resources/timeline.js +176 -0
  53. package/dist/resources/timeline.js.map +1 -0
  54. package/dist/resources/workspace-onboarding.d.ts +25 -0
  55. package/dist/resources/workspace-onboarding.d.ts.map +1 -0
  56. package/dist/resources/workspace-onboarding.js +99 -0
  57. package/dist/resources/workspace-onboarding.js.map +1 -0
  58. package/dist/transport.d.ts +22 -0
  59. package/dist/transport.d.ts.map +1 -0
  60. package/dist/transport.js +189 -0
  61. package/dist/transport.js.map +1 -0
  62. package/dist/types/ai-edit.d.ts +180 -0
  63. package/dist/types/ai-edit.d.ts.map +1 -0
  64. package/dist/types/ai-edit.js +2 -0
  65. package/dist/types/ai-edit.js.map +1 -0
  66. package/dist/types/captions.d.ts +181 -0
  67. package/dist/types/captions.d.ts.map +1 -0
  68. package/dist/types/captions.js +2 -0
  69. package/dist/types/captions.js.map +1 -0
  70. package/dist/types/clips.d.ts +124 -0
  71. package/dist/types/clips.d.ts.map +1 -0
  72. package/dist/types/clips.js +2 -0
  73. package/dist/types/clips.js.map +1 -0
  74. package/dist/types/common.d.ts +241 -0
  75. package/dist/types/common.d.ts.map +1 -0
  76. package/dist/types/common.js +2 -0
  77. package/dist/types/common.js.map +1 -0
  78. package/dist/types/exports.d.ts +62 -0
  79. package/dist/types/exports.d.ts.map +1 -0
  80. package/dist/types/exports.js +2 -0
  81. package/dist/types/exports.js.map +1 -0
  82. package/dist/types/faceless.d.ts +167 -0
  83. package/dist/types/faceless.d.ts.map +1 -0
  84. package/dist/types/faceless.js +2 -0
  85. package/dist/types/faceless.js.map +1 -0
  86. package/dist/types/formats.d.ts +40 -0
  87. package/dist/types/formats.d.ts.map +1 -0
  88. package/dist/types/formats.js +2 -0
  89. package/dist/types/formats.js.map +1 -0
  90. package/dist/types/libraries.d.ts +184 -0
  91. package/dist/types/libraries.d.ts.map +1 -0
  92. package/dist/types/libraries.js +2 -0
  93. package/dist/types/libraries.js.map +1 -0
  94. package/dist/types/media.d.ts +297 -0
  95. package/dist/types/media.d.ts.map +1 -0
  96. package/dist/types/media.js +2 -0
  97. package/dist/types/media.js.map +1 -0
  98. package/dist/types/projects.d.ts +185 -0
  99. package/dist/types/projects.d.ts.map +1 -0
  100. package/dist/types/projects.js +2 -0
  101. package/dist/types/projects.js.map +1 -0
  102. package/dist/types/timeline.d.ts +90 -0
  103. package/dist/types/timeline.d.ts.map +1 -0
  104. package/dist/types/timeline.js +2 -0
  105. package/dist/types/timeline.js.map +1 -0
  106. package/dist/types/workspace.d.ts +129 -0
  107. package/dist/types/workspace.d.ts.map +1 -0
  108. package/dist/types/workspace.js +2 -0
  109. package/dist/types/workspace.js.map +1 -0
  110. package/package.json +6 -1
package/dist/index.js CHANGED
@@ -1,1163 +1,4 @@
1
- const DEFAULT_BASE_URL = "https://www.blitzreels.com/api/v1";
2
- export class BlitzReelsError extends Error {
3
- status;
4
- requestId;
5
- body;
6
- constructor(options) {
7
- super(options.message);
8
- this.name = "BlitzReelsError";
9
- this.status = options.status;
10
- this.requestId = options.requestId;
11
- this.body = options.body;
12
- }
13
- }
14
- function buildCaptionTrackSelectorBody({ options, }) {
15
- return {
16
- all: options.all,
17
- caption_id: options.captionId,
18
- timeline_item_id: options.timelineItemId,
19
- from_seconds: options.fromSeconds,
20
- to_seconds: options.toSeconds,
21
- };
22
- }
23
- function normalizeBaseUrl({ baseUrl, }) {
24
- const value = String(baseUrl ?? DEFAULT_BASE_URL).trim();
25
- return value.replace(/\/+$/, "");
26
- }
27
- function appendQuery({ url, query, }) {
28
- if (query === undefined) {
29
- return;
30
- }
31
- for (const [key, value] of Object.entries(query)) {
32
- const values = Array.isArray(value) ? value : [value];
33
- for (const item of values) {
34
- if (item === undefined || item === null) {
35
- continue;
36
- }
37
- url.searchParams.append(key, String(item));
38
- }
39
- }
40
- }
41
- function extractErrorMessage({ body }) {
42
- if (body === null || typeof body !== "object") {
43
- return null;
44
- }
45
- const record = body;
46
- const message = record.message ?? record.error;
47
- return typeof message === "string" ? message : null;
48
- }
49
- function normalizeMediaPositionPreset({ value, }) {
50
- if (value === "full-screen") {
51
- return "fullscreen";
52
- }
53
- if (value === "top-left") {
54
- return "pip-top-left";
55
- }
56
- if (value === "top-right") {
57
- return "pip-top-right";
58
- }
59
- if (value === "bottom-left") {
60
- return "pip-bottom-left";
61
- }
62
- if (value === "bottom-right") {
63
- return "pip-bottom-right";
64
- }
65
- return value;
66
- }
67
- function normalizeMediaAnimationPreset({ value, }) {
68
- return value === "slideIn" ? "slideUp" : value;
69
- }
70
- function sleep({ ms }) {
71
- return new Promise((resolve) => setTimeout(resolve, ms));
72
- }
73
- function deepCloneJson({ value }) {
74
- return JSON.parse(JSON.stringify(value));
75
- }
76
- function replaceFirstTextContent({ value, text, }) {
77
- if (!value || typeof value !== "object") {
78
- return false;
79
- }
80
- if (Array.isArray(value)) {
81
- for (const item of value) {
82
- if (replaceFirstTextContent({ value: item, text })) {
83
- return true;
84
- }
85
- }
86
- return false;
87
- }
88
- const record = value;
89
- if (record.type === "text" && typeof record.content === "string") {
90
- record.content = text;
91
- return true;
92
- }
93
- for (const childKey of ["children", "elements"]) {
94
- if (replaceFirstTextContent({ value: record[childKey], text })) {
95
- return true;
96
- }
97
- }
98
- return false;
99
- }
100
- function updateTextSpecContent({ spec, text, }) {
101
- const next = deepCloneJson({ value: spec });
102
- if (!replaceFirstTextContent({ value: next, text })) {
103
- throw new BlitzReelsError({
104
- message: "Content item spec does not contain editable text content.",
105
- status: 422,
106
- requestId: null,
107
- body: { spec },
108
- });
109
- }
110
- return next;
111
- }
112
- export class BlitzReelsClient {
113
- apiKey;
114
- baseUrl;
115
- fetchFn;
116
- userAgent;
117
- auth;
118
- projects;
119
- timeline;
120
- effects;
121
- workspace;
122
- media;
123
- clips;
124
- text;
125
- audio;
126
- audioLibrary;
127
- stockMedia;
128
- library;
129
- silence;
130
- mistakes;
131
- captions;
132
- exports;
133
- jobs;
134
- constructor(config) {
135
- this.apiKey = config.apiKey;
136
- this.baseUrl = normalizeBaseUrl({ baseUrl: config.baseUrl });
137
- this.fetchFn = config.fetchFn ?? fetch;
138
- this.userAgent = config.userAgent ?? "blitzreels-sdk/0.0.0";
139
- this.auth = {
140
- validate: () => this.request({
141
- method: "GET",
142
- path: "/auth/validate",
143
- query: undefined,
144
- body: undefined,
145
- }),
146
- };
147
- this.projects = {
148
- list: (options) => this.request({
149
- method: "GET",
150
- path: "/projects",
151
- query: {
152
- limit: options.limit,
153
- cursor: options.cursor,
154
- offset: options.offset,
155
- search: options.search,
156
- status: options.status,
157
- },
158
- body: undefined,
159
- }),
160
- create: (options) => this.request({
161
- method: "POST",
162
- path: "/projects",
163
- query: undefined,
164
- body: {
165
- name: options.name,
166
- description: options.description,
167
- aspect_ratio: options.aspectRatio,
168
- project_type: options.projectType,
169
- carousel_settings: options.carouselSettings,
170
- },
171
- }),
172
- get: (options) => this.request({
173
- method: "GET",
174
- path: `/projects/${encodeURIComponent(options.projectId)}`,
175
- query: undefined,
176
- body: undefined,
177
- }),
178
- update: (options) => this.request({
179
- method: "PATCH",
180
- path: `/projects/${encodeURIComponent(options.projectId)}`,
181
- query: undefined,
182
- body: {
183
- name: options.name,
184
- description: options.description,
185
- },
186
- }),
187
- delete: (options) => this.request({
188
- method: "DELETE",
189
- path: `/projects/${encodeURIComponent(options.projectId)}`,
190
- query: undefined,
191
- body: undefined,
192
- }),
193
- inspect: (options) => this.request({
194
- method: "GET",
195
- path: `/projects/${encodeURIComponent(options.projectId)}/context`,
196
- query: { mode: options.mode },
197
- body: undefined,
198
- }),
199
- timeline: (options) => this.request({
200
- method: "GET",
201
- path: `/projects/${encodeURIComponent(options.projectId)}/context`,
202
- query: { mode: "timeline" },
203
- body: undefined,
204
- }),
205
- renderSnapshot: (options) => this.request({
206
- method: "POST",
207
- path: `/projects/${encodeURIComponent(options.projectId)}/preview-frame`,
208
- query: undefined,
209
- body: {
210
- time_seconds: options.atSeconds,
211
- target_width: options.targetWidth,
212
- image_format: options.imageFormat,
213
- },
214
- }),
215
- renderSnapshots: (options) => this.request({
216
- method: "POST",
217
- path: `/projects/${encodeURIComponent(options.projectId)}/preview-frames`,
218
- query: undefined,
219
- body: {
220
- times_seconds: options.atSeconds,
221
- target_width: options.targetWidth,
222
- image_format: options.imageFormat,
223
- },
224
- }),
225
- };
226
- this.timeline = {
227
- transform: (options) => this.request({
228
- method: "POST",
229
- path: `/projects/${encodeURIComponent(options.projectId)}/timeline/edits`,
230
- query: undefined,
231
- body: {
232
- action: "transform",
233
- timeline_item_id: options.timelineItemId,
234
- position_x: options.positionX,
235
- position_y: options.positionY,
236
- width_px: options.widthPx,
237
- height_px: options.heightPx,
238
- keep_aspect_ratio: options.keepAspectRatio,
239
- },
240
- }),
241
- move: (options) => this.request({
242
- method: "POST",
243
- path: `/projects/${encodeURIComponent(options.projectId)}/timeline/edits`,
244
- query: undefined,
245
- body: {
246
- action: "move",
247
- timeline_item_id: options.timelineItemId,
248
- new_start_seconds: options.newStartSeconds,
249
- new_layer_index: options.newLayerIndex,
250
- },
251
- }),
252
- delete: (options) => this.request({
253
- method: "POST",
254
- path: `/projects/${encodeURIComponent(options.projectId)}/timeline/edits`,
255
- query: undefined,
256
- body: {
257
- action: "delete",
258
- timeline_item_ids: options.timelineItemIds,
259
- auto_pack: options.autoPack,
260
- },
261
- }),
262
- deleteItem: (options) => this.request({
263
- method: "DELETE",
264
- path: `/projects/${encodeURIComponent(options.projectId)}/timeline/items/${encodeURIComponent(options.timelineItemId)}`,
265
- query: undefined,
266
- body: undefined,
267
- }),
268
- };
269
- this.effects = {
270
- zoom: {
271
- add: (options) => this.request({
272
- method: "POST",
273
- path: `/projects/${encodeURIComponent(options.projectId)}/effects/zoom`,
274
- query: undefined,
275
- body: {
276
- timeline_item_id: options.timelineItemId,
277
- content_item_id: options.contentItemId,
278
- effect_id: options.effectId,
279
- name: options.name,
280
- start_time_seconds: options.startTimeSeconds,
281
- duration_seconds: options.durationSeconds,
282
- easing: options.easing,
283
- layer_index: options.layerIndex,
284
- order_index: options.orderIndex,
285
- settings: options.settings,
286
- },
287
- }),
288
- update: (options) => this.request({
289
- method: "PATCH",
290
- path: `/projects/${encodeURIComponent(options.projectId)}/effects/zoom/${encodeURIComponent(options.timelineItemId)}`,
291
- query: undefined,
292
- body: {
293
- duration_seconds: options.durationSeconds,
294
- easing: options.easing,
295
- settings: options.settings,
296
- },
297
- }),
298
- },
299
- mask: {
300
- add: (options) => this.request({
301
- method: "POST",
302
- path: `/projects/${encodeURIComponent(options.projectId)}/effects/mask`,
303
- query: undefined,
304
- body: {
305
- timeline_item_id: options.timelineItemId,
306
- content_item_id: options.contentItemId,
307
- effect_id: options.effectId,
308
- name: options.name,
309
- start_time_seconds: options.startTimeSeconds,
310
- duration_seconds: options.durationSeconds,
311
- easing: options.easing,
312
- layer_index: options.layerIndex,
313
- order_index: options.orderIndex,
314
- settings: options.settings,
315
- },
316
- }),
317
- update: (options) => this.request({
318
- method: "PATCH",
319
- path: `/projects/${encodeURIComponent(options.projectId)}/effects/mask/${encodeURIComponent(options.timelineItemId)}`,
320
- query: undefined,
321
- body: {
322
- duration_seconds: options.durationSeconds,
323
- easing: options.easing,
324
- settings: options.settings,
325
- },
326
- }),
327
- },
328
- colorgrade: {
329
- add: (options) => this.request({
330
- method: "POST",
331
- path: `/projects/${encodeURIComponent(options.projectId)}/effects/colorgrade`,
332
- query: undefined,
333
- body: {
334
- timeline_item_id: options.timelineItemId,
335
- content_item_id: options.contentItemId,
336
- effect_id: options.effectId,
337
- name: options.name,
338
- start_time_seconds: options.startTimeSeconds,
339
- duration_seconds: options.durationSeconds,
340
- easing: options.easing,
341
- layer_index: options.layerIndex,
342
- order_index: options.orderIndex,
343
- settings: options.settings,
344
- },
345
- }),
346
- update: (options) => this.request({
347
- method: "PATCH",
348
- path: `/projects/${encodeURIComponent(options.projectId)}/effects/colorgrade/${encodeURIComponent(options.timelineItemId)}`,
349
- query: undefined,
350
- body: {
351
- duration_seconds: options.durationSeconds,
352
- easing: options.easing,
353
- settings: options.settings,
354
- },
355
- }),
356
- },
357
- };
358
- this.workspace = {
359
- getSettings: () => this.request({
360
- method: "GET",
361
- path: "/workspace/settings",
362
- query: undefined,
363
- body: undefined,
364
- }),
365
- updateSettings: (options) => this.request({
366
- method: "PATCH",
367
- path: "/workspace/settings",
368
- query: undefined,
369
- body: {
370
- name: options.name,
371
- description: options.description,
372
- protected_words: options.protectedWords,
373
- icon_storage_key: options.iconStorageKey,
374
- defaults: options.defaults === undefined
375
- ? undefined
376
- : {
377
- aspect_ratio: options.defaults.aspectRatio,
378
- orientation: options.defaults.orientation,
379
- resolution: options.defaults.resolution,
380
- frame_rate: options.defaults.frameRate,
381
- auto_manage_broll: options.defaults.autoManageBroll,
382
- caption_theme_id: options.defaults.captionThemeId,
383
- },
384
- },
385
- }),
386
- };
387
- this.media = {
388
- list: (options) => this.request({
389
- method: "GET",
390
- path: "/workspace/media/assets",
391
- query: {
392
- folder_id: options.folderId,
393
- asset_type: options.assetType,
394
- search: options.search,
395
- limit: options.limit,
396
- offset: options.offset,
397
- },
398
- body: undefined,
399
- }),
400
- get: (options) => this.request({
401
- method: "GET",
402
- path: `/workspace/media/assets/${encodeURIComponent(options.assetId)}`,
403
- query: undefined,
404
- body: undefined,
405
- }),
406
- clippingStatus: (options) => this.request({
407
- method: "GET",
408
- path: `/workspace/media/assets/${encodeURIComponent(options.assetId)}/clipping-status`,
409
- query: { project_id: options.projectId },
410
- body: undefined,
411
- }),
412
- delete: (options) => this.request({
413
- method: "POST",
414
- path: `/workspace/media/assets/${encodeURIComponent(options.assetId)}/delete`,
415
- query: undefined,
416
- body: {},
417
- }),
418
- initUpload: (options) => this.request({
419
- method: "POST",
420
- path: "/workspace/media/upload/init",
421
- query: undefined,
422
- body: {
423
- file_name: options.fileName,
424
- content_type: options.contentType,
425
- },
426
- }),
427
- finalizeUpload: (options) => this.request({
428
- method: "POST",
429
- path: "/workspace/media/upload/finalize",
430
- query: undefined,
431
- body: {
432
- storage_key: options.storageKey,
433
- file_name: options.fileName,
434
- content_type: options.contentType,
435
- file_size_bytes: options.fileSizeBytes,
436
- auto_process_enabled: options.autoProcessEnabled,
437
- auto_transcribe: options.autoTranscribe,
438
- auto_describe_after_transcribe: options.autoDescribeAfterTranscribe,
439
- auto_suggest_shorts: options.autoSuggestShorts,
440
- },
441
- }),
442
- importYoutube: (options) => this.request({
443
- method: "POST",
444
- path: "/workspace/media/import/youtube",
445
- query: undefined,
446
- body: {
447
- url: options.url,
448
- folder_id: options.folderId,
449
- quality: options.quality,
450
- fps: options.fps,
451
- audio_language: options.audioLanguage,
452
- },
453
- }),
454
- update: (options) => this.request({
455
- method: "PATCH",
456
- path: `/workspace/media/assets/${encodeURIComponent(options.assetId)}`,
457
- query: undefined,
458
- body: {
459
- name: options.name,
460
- description: options.description,
461
- folder_id: options.folderId,
462
- allow_using_as_broll: options.allowUsingAsBroll,
463
- },
464
- }),
465
- move: (options) => this.request({
466
- method: "POST",
467
- path: "/workspace/media/assets/move",
468
- query: undefined,
469
- body: {
470
- asset_ids: options.assetIds,
471
- target_folder_id: options.targetFolderId,
472
- },
473
- }),
474
- attachToProject: (options) => this.request({
475
- method: "POST",
476
- path: `/projects/${encodeURIComponent(options.projectId)}/timeline/media`,
477
- query: undefined,
478
- body: {
479
- items: [
480
- {
481
- asset_id: options.assetId,
482
- start_seconds: options.startSeconds ?? 0,
483
- duration_seconds: options.durationSeconds,
484
- position_preset: normalizeMediaPositionPreset({
485
- value: options.positionPreset,
486
- }),
487
- position_x: options.positionX,
488
- position_y: options.positionY,
489
- width_px: options.widthPx,
490
- height_px: options.heightPx,
491
- scale: options.scale,
492
- opacity: options.opacity,
493
- animation_preset: normalizeMediaAnimationPreset({
494
- value: options.animationPreset,
495
- }),
496
- layer_index: options.layerIndex,
497
- },
498
- ],
499
- allow_duplicate: options.allowDuplicate,
500
- },
501
- }),
502
- updateOverlay: (options) => this.request({
503
- method: "PATCH",
504
- path: `/projects/${encodeURIComponent(options.projectId)}/timeline/media/${encodeURIComponent(options.timelineItemId)}`,
505
- query: undefined,
506
- body: {
507
- position_preset: normalizeMediaPositionPreset({
508
- value: options.positionPreset,
509
- }),
510
- position_x: options.positionX,
511
- position_y: options.positionY,
512
- width_px: options.widthPx,
513
- height_px: options.heightPx,
514
- scale: options.scale,
515
- animation_preset: normalizeMediaAnimationPreset({
516
- value: options.animationPreset,
517
- }),
518
- remove_animations: options.removeAnimations,
519
- blurred_background: options.blurredBackground,
520
- },
521
- }),
522
- shorts: {
523
- list: (options) => this.request({
524
- method: "GET",
525
- path: `/workspace/media/assets/${encodeURIComponent(options.assetId)}/short-suggestions`,
526
- query: undefined,
527
- body: undefined,
528
- }),
529
- generate: (options) => this.request({
530
- method: "POST",
531
- path: `/workspace/media/assets/${encodeURIComponent(options.assetId)}/short-suggestions`,
532
- query: undefined,
533
- body: {
534
- content_profile: options.contentProfile,
535
- auto_trim_silence: options.autoTrimSilence,
536
- },
537
- }),
538
- apply: (options) => this.request({
539
- method: "POST",
540
- path: `/workspace/media/assets/${encodeURIComponent(options.assetId)}/short-suggestions/${encodeURIComponent(options.suggestionId)}/apply`,
541
- query: undefined,
542
- body: {
543
- project_id: options.projectId,
544
- caption_style_id: options.captionStyleId,
545
- mark_saved: options.markSaved,
546
- allow_unverified_export: options.allowUnverifiedExport,
547
- automatic_layout: options.automaticLayout,
548
- },
549
- }),
550
- },
551
- folders: {
552
- list: (options) => this.request({
553
- method: "GET",
554
- path: "/workspace/media/folders",
555
- query: { parent_folder_id: options.parentFolderId },
556
- body: undefined,
557
- }),
558
- create: (options) => this.request({
559
- method: "POST",
560
- path: "/workspace/media/folders",
561
- query: undefined,
562
- body: {
563
- name: options.name,
564
- parent_folder_id: options.parentFolderId,
565
- description: options.description,
566
- icon_type: options.iconType,
567
- },
568
- }),
569
- update: (options) => this.request({
570
- method: "PATCH",
571
- path: `/workspace/media/folders/${encodeURIComponent(options.folderId)}`,
572
- query: undefined,
573
- body: {
574
- name: options.name,
575
- parent_folder_id: options.parentFolderId,
576
- description: options.description,
577
- icon_type: options.iconType,
578
- },
579
- }),
580
- delete: (options) => this.request({
581
- method: "DELETE",
582
- path: `/workspace/media/folders/${encodeURIComponent(options.folderId)}`,
583
- query: { cascade: options.cascade },
584
- body: undefined,
585
- }),
586
- },
587
- };
588
- this.clips = {
589
- create: (options) => this.request({
590
- method: "POST",
591
- path: "/clips",
592
- query: undefined,
593
- body: {
594
- project_name: options.projectName,
595
- source: {
596
- source_type: options.source.sourceType,
597
- asset_id: options.source.assetId,
598
- youtube_url: options.source.youtubeUrl,
599
- },
600
- selection: {
601
- selection_mode: options.selection.mode,
602
- suggestion_id: options.selection.suggestionId,
603
- start_seconds: options.selection.startSeconds,
604
- end_seconds: options.selection.endSeconds,
605
- },
606
- target: {
607
- aspect_ratio: options.target.aspectRatio,
608
- min_duration_seconds: options.target.minDurationSeconds,
609
- max_duration_seconds: options.target.maxDurationSeconds,
610
- },
611
- layout: {
612
- layout_mode: options.layout.mode,
613
- content_type_hint: options.layout.contentTypeHint,
614
- },
615
- captions: {
616
- enabled: options.captions.enabled,
617
- style_id: options.captions.styleId,
618
- },
619
- qa: {
620
- qa_mode: options.qa.mode,
621
- },
622
- export: {
623
- auto_export: options.export.autoExport,
624
- },
625
- },
626
- }),
627
- get: (options) => this.request({
628
- method: "GET",
629
- path: `/clips/${encodeURIComponent(options.clipId)}`,
630
- query: undefined,
631
- body: undefined,
632
- }),
633
- reselect: (options) => this.request({
634
- method: "POST",
635
- path: `/clips/${encodeURIComponent(options.clipId)}/reselect`,
636
- query: undefined,
637
- body: {
638
- selection: {
639
- selection_mode: options.selection.mode,
640
- suggestion_id: options.selection.suggestionId,
641
- start_seconds: options.selection.startSeconds,
642
- end_seconds: options.selection.endSeconds,
643
- },
644
- target: options.target === null || options.target === undefined
645
- ? null
646
- : {
647
- min_duration_seconds: options.target.minDurationSeconds,
648
- max_duration_seconds: options.target.maxDurationSeconds,
649
- },
650
- },
651
- }),
652
- repair: (options) => this.request({
653
- method: "POST",
654
- path: `/clips/${encodeURIComponent(options.clipId)}/repair`,
655
- query: undefined,
656
- body: {
657
- repair_mode: options.repairMode,
658
- },
659
- }),
660
- export: (options) => this.request({
661
- method: "POST",
662
- path: `/clips/${encodeURIComponent(options.clipId)}/export`,
663
- query: undefined,
664
- body: {
665
- resolution: options.resolution,
666
- format: options.format,
667
- allow_blocking_qa_bypass: options.allowBlockingQaBypass,
668
- },
669
- }),
670
- };
671
- this.text = {
672
- add: (options) => this.request({
673
- method: "POST",
674
- path: `/projects/${encodeURIComponent(options.projectId)}/content-items`,
675
- query: undefined,
676
- body: {
677
- kind: "overlay",
678
- text: options.text,
679
- name: options.name,
680
- spec: options.spec,
681
- start_seconds: options.startSeconds,
682
- duration_seconds: options.durationSeconds,
683
- layer_index: options.layerIndex,
684
- },
685
- }),
686
- list: (options) => this.request({
687
- method: "GET",
688
- path: `/projects/${encodeURIComponent(options.projectId)}/content-items`,
689
- query: undefined,
690
- body: undefined,
691
- }),
692
- update: (options) => this.updateTextContentItem({
693
- projectId: options.projectId,
694
- contentItemId: options.contentItemId,
695
- text: options.text,
696
- name: options.name,
697
- spec: options.spec,
698
- durationSeconds: options.durationSeconds,
699
- }),
700
- remove: (options) => this.request({
701
- method: "DELETE",
702
- path: `/projects/${encodeURIComponent(options.projectId)}/content-items/${encodeURIComponent(options.contentItemId)}`,
703
- query: undefined,
704
- body: undefined,
705
- }),
706
- };
707
- this.audio = {
708
- add: (options) => this.request({
709
- method: "POST",
710
- path: `/projects/${encodeURIComponent(options.projectId)}/timeline/audio`,
711
- query: undefined,
712
- body: {
713
- items: [
714
- {
715
- asset_id: options.assetId,
716
- start_seconds: options.startSeconds,
717
- duration_seconds: options.durationSeconds,
718
- volume: options.volume,
719
- fade_in_seconds: options.fadeInSeconds,
720
- fade_out_seconds: options.fadeOutSeconds,
721
- loop: options.loop,
722
- },
723
- ],
724
- },
725
- }),
726
- update: (options) => this.request({
727
- method: "PATCH",
728
- path: `/projects/${encodeURIComponent(options.projectId)}/timeline/audio/${encodeURIComponent(options.timelineItemId)}`,
729
- query: undefined,
730
- body: {
731
- duration_seconds: options.durationSeconds,
732
- volume: options.volume,
733
- fade_in_seconds: options.fadeInSeconds,
734
- fade_out_seconds: options.fadeOutSeconds,
735
- },
736
- }),
737
- };
738
- this.audioLibrary = {
739
- search: (options) => this.request({
740
- method: "GET",
741
- path: "/audio-library/search",
742
- query: {
743
- query: options.query,
744
- provider: options.provider,
745
- license: options.license,
746
- audio_type: options.audioType,
747
- min_duration_seconds: options.minDurationSeconds,
748
- max_duration_seconds: options.maxDurationSeconds,
749
- limit: options.limit,
750
- page: options.page,
751
- },
752
- body: undefined,
753
- }),
754
- importAsset: (options) => this.request({
755
- method: "POST",
756
- path: "/audio-library/import",
757
- query: undefined,
758
- body: {
759
- provider: options.provider,
760
- external_id: options.externalId,
761
- folder_id: options.folderId,
762
- project_id: options.projectId,
763
- start_seconds: options.startSeconds,
764
- duration_seconds: options.durationSeconds,
765
- volume: options.volume,
766
- fade_in_seconds: options.fadeInSeconds,
767
- fade_out_seconds: options.fadeOutSeconds,
768
- loop: options.loop,
769
- audio_type: options.audioType,
770
- },
771
- }),
772
- };
773
- this.stockMedia = {
774
- search: (options) => this.request({
775
- method: "GET",
776
- path: "/workspace/stock-media/search",
777
- query: {
778
- query: options.query,
779
- asset_type: options.assetType,
780
- provider: options.provider,
781
- orientation: options.orientation,
782
- page: options.page,
783
- limit: options.limit,
784
- },
785
- body: undefined,
786
- }),
787
- importAsset: (options) => this.request({
788
- method: "POST",
789
- path: "/workspace/stock-media/import",
790
- query: undefined,
791
- body: {
792
- provider: options.provider,
793
- provider_asset_id: options.providerAssetId,
794
- asset_type: options.assetType,
795
- variant_id: options.variantId,
796
- folder_id: options.folderId,
797
- audio_type: options.audioType,
798
- },
799
- }),
800
- };
801
- this.library = {
802
- search: (options) => this.request({
803
- method: "GET",
804
- path: "/library/broll/search",
805
- query: {
806
- query: options.query,
807
- asset_type: options.assetType,
808
- audio_type: options.audioType,
809
- limit: options.limit,
810
- offset: options.offset,
811
- },
812
- body: undefined,
813
- }),
814
- importAsset: (options) => this.request({
815
- method: "POST",
816
- path: `/library/broll/${encodeURIComponent(options.libraryAssetId)}/import`,
817
- query: undefined,
818
- body: {
819
- folder_id: options.folderId,
820
- },
821
- }),
822
- };
823
- this.silence = {
824
- plan: (options) => this.request({
825
- method: "POST",
826
- path: `/projects/${encodeURIComponent(options.projectId)}/silence/plan`,
827
- query: undefined,
828
- body: {
829
- timeline_item_id: options.timelineItemId,
830
- all_media_items: options.allMediaItems,
831
- padding_ms: options.paddingMs,
832
- silence_threshold_db: options.silenceThresholdDb,
833
- min_silence_duration_seconds: options.minSilenceDurationSeconds,
834
- remove_blips_max_duration_seconds: options.removeBlipsMaxDurationSeconds,
835
- use_caption_validation: options.useCaptionValidation,
836
- },
837
- }),
838
- apply: (options) => this.request({
839
- method: "POST",
840
- path: `/projects/${encodeURIComponent(options.projectId)}/silence/apply`,
841
- query: undefined,
842
- body: {
843
- timeline_item_id: options.timelineItemId,
844
- all_media_items: options.allMediaItems,
845
- padding_ms: options.paddingMs,
846
- silence_threshold_db: options.silenceThresholdDb,
847
- min_silence_duration_seconds: options.minSilenceDurationSeconds,
848
- remove_blips_max_duration_seconds: options.removeBlipsMaxDurationSeconds,
849
- use_caption_validation: options.useCaptionValidation,
850
- delete_silent_clips: options.deleteSilentClips,
851
- manual_segment_overrides: options.manualSegmentOverrides,
852
- preview_confirmed: options.previewConfirmed,
853
- },
854
- }),
855
- };
856
- this.mistakes = {
857
- plan: (options) => this.request({
858
- method: "POST",
859
- path: `/projects/${encodeURIComponent(options.projectId)}/mistakes/plan`,
860
- query: undefined,
861
- body: {
862
- timeline_item_id: options.timelineItemId,
863
- },
864
- }),
865
- apply: (options) => this.request({
866
- method: "POST",
867
- path: `/projects/${encodeURIComponent(options.projectId)}/mistakes/apply`,
868
- query: undefined,
869
- body: {
870
- timeline_item_id: options.timelineItemId,
871
- plan: options.plan,
872
- manual_verdicts: options.manualVerdicts,
873
- delete_mistakes: options.deleteMistakes,
874
- preview_confirmed: options.previewConfirmed,
875
- },
876
- }),
877
- };
878
- this.captions = {
879
- listWords: (options) => this.request({
880
- method: "GET",
881
- path: `/projects/${encodeURIComponent(options.projectId)}/captions/words`,
882
- query: {
883
- timeline_item_id: options.timelineItemId,
884
- match_text: options.matchText,
885
- limit: options.limit,
886
- offset: options.offset,
887
- },
888
- body: undefined,
889
- }),
890
- updateWordText: (options) => this.request({
891
- method: "POST",
892
- path: `/projects/${encodeURIComponent(options.projectId)}/captions/words/text`,
893
- query: undefined,
894
- body: {
895
- word_id: options.wordId,
896
- new_text: options.newText,
897
- },
898
- }),
899
- batchUpdateWordText: (options) => this.request({
900
- method: "POST",
901
- path: `/projects/${encodeURIComponent(options.projectId)}/captions/words/batch-text`,
902
- query: undefined,
903
- body: {
904
- updates: options.updates,
905
- },
906
- }),
907
- setWordStyle: (options) => this.request({
908
- method: "POST",
909
- path: `/projects/${encodeURIComponent(options.projectId)}/captions/words/style`,
910
- query: undefined,
911
- body: {
912
- style: options.style,
913
- clear_existing: options.clearExisting,
914
- word_ids: options.wordIds,
915
- match_text: options.matchText,
916
- match_pattern: options.matchPattern,
917
- timeline_item_id: options.timelineItemId,
918
- all: options.all,
919
- from_seconds: options.fromSeconds,
920
- to_seconds: options.toSeconds,
921
- },
922
- }),
923
- setWordEmphasis: (options) => this.request({
924
- method: "POST",
925
- path: `/projects/${encodeURIComponent(options.projectId)}/captions/words/emphasis`,
926
- query: undefined,
927
- body: {
928
- emphasis: options.emphasis,
929
- word_ids: options.wordIds,
930
- match_text: options.matchText,
931
- match_pattern: options.matchPattern,
932
- timeline_item_id: options.timelineItemId,
933
- all: options.all,
934
- from_seconds: options.fromSeconds,
935
- to_seconds: options.toSeconds,
936
- },
937
- }),
938
- deleteWords: (options) => this.request({
939
- method: "POST",
940
- path: `/projects/${encodeURIComponent(options.projectId)}/captions/words/delete`,
941
- query: undefined,
942
- body: { word_ids: options.wordIds },
943
- }),
944
- delete: (options) => this.request({
945
- method: "POST",
946
- path: `/projects/${encodeURIComponent(options.projectId)}/captions/delete`,
947
- query: undefined,
948
- body: buildCaptionTrackSelectorBody({ options }),
949
- }),
950
- hide: (options) => this.request({
951
- method: "POST",
952
- path: `/projects/${encodeURIComponent(options.projectId)}/captions/hide`,
953
- query: undefined,
954
- body: buildCaptionTrackSelectorBody({ options }),
955
- }),
956
- show: (options) => this.request({
957
- method: "POST",
958
- path: `/projects/${encodeURIComponent(options.projectId)}/captions/show`,
959
- query: undefined,
960
- body: buildCaptionTrackSelectorBody({ options }),
961
- }),
962
- mergeWords: (options) => this.request({
963
- method: "POST",
964
- path: `/projects/${encodeURIComponent(options.projectId)}/captions/words/merge`,
965
- query: undefined,
966
- body: { word_ids: options.wordIds, text: options.text },
967
- }),
968
- splitWord: (options) => this.request({
969
- method: "POST",
970
- path: `/projects/${encodeURIComponent(options.projectId)}/captions/words/split`,
971
- query: undefined,
972
- body: { word_id: options.wordId, words: options.words },
973
- }),
974
- listThemes: () => this.request({
975
- method: "GET",
976
- path: "/caption-themes",
977
- query: undefined,
978
- body: undefined,
979
- }),
980
- updateTheme: (options) => this.request({
981
- method: "PATCH",
982
- path: `/caption-themes/${encodeURIComponent(options.themeId)}`,
983
- query: undefined,
984
- body: {
985
- name: options.name,
986
- description: options.description,
987
- settings: options.settings,
988
- },
989
- }),
990
- setDefaultTheme: (options) => this.request({
991
- method: "POST",
992
- path: `/caption-themes/${encodeURIComponent(options.themeId)}/set-default`,
993
- query: undefined,
994
- body: {},
995
- }),
996
- setProjectTheme: (options) => this.request({
997
- method: "POST",
998
- path: `/projects/${encodeURIComponent(options.projectId)}/caption-theme`,
999
- query: undefined,
1000
- body: {
1001
- theme_id: options.themeId,
1002
- },
1003
- }),
1004
- previewTheme: (options) => this.request({
1005
- method: "POST",
1006
- path: "/caption-themes/preview",
1007
- query: undefined,
1008
- body: {
1009
- settings: options.settings,
1010
- sample_text: options.sampleText,
1011
- aspect_ratio: options.aspectRatio,
1012
- target_width: options.targetWidth,
1013
- image_format: options.imageFormat,
1014
- },
1015
- }),
1016
- };
1017
- this.exports = {
1018
- start: (options) => this.request({
1019
- method: "POST",
1020
- path: `/projects/${encodeURIComponent(options.projectId)}/export`,
1021
- query: undefined,
1022
- body: {
1023
- resolution: options.resolution,
1024
- format: options.format,
1025
- },
1026
- }),
1027
- get: (options) => this.request({
1028
- method: "GET",
1029
- path: `/exports/${encodeURIComponent(options.exportId)}`,
1030
- query: undefined,
1031
- body: undefined,
1032
- }),
1033
- wait: (options) => this.waitForExport(options),
1034
- download: (options) => this.downloadExport(options),
1035
- };
1036
- this.jobs = {
1037
- get: (options) => this.request({
1038
- method: "GET",
1039
- path: `/jobs/${encodeURIComponent(options.jobId)}`,
1040
- query: undefined,
1041
- body: undefined,
1042
- }),
1043
- };
1044
- }
1045
- async request(options) {
1046
- const url = new URL(`${this.baseUrl}${options.path}`);
1047
- appendQuery({ url, query: options.query });
1048
- const headers = {
1049
- Authorization: `Bearer ${this.apiKey}`,
1050
- Accept: "application/json",
1051
- "X-BlitzReels-Client": this.userAgent,
1052
- };
1053
- let body;
1054
- if (options.body !== undefined) {
1055
- headers["Content-Type"] = "application/json";
1056
- body = JSON.stringify(options.body);
1057
- }
1058
- const response = await this.fetchFn(url, {
1059
- method: options.method,
1060
- headers,
1061
- body,
1062
- });
1063
- const requestId = response.headers.get("x-request-id") ??
1064
- response.headers.get("x-vercel-id") ??
1065
- null;
1066
- const text = await response.text();
1067
- const parsed = text.length > 0 ? parseJson({ text }) : null;
1068
- if (!response.ok) {
1069
- throw new BlitzReelsError({
1070
- message: extractErrorMessage({ body: parsed }) ??
1071
- `BlitzReels API request failed with ${response.status}`,
1072
- status: response.status,
1073
- requestId,
1074
- body: parsed,
1075
- });
1076
- }
1077
- return parsed;
1078
- }
1079
- async waitForExport(options) {
1080
- const startedAt = Date.now();
1081
- while (Date.now() - startedAt <= options.timeoutMs) {
1082
- const status = await this.exports.get({ exportId: options.exportId });
1083
- if (status.status === "completed") {
1084
- return status;
1085
- }
1086
- if (status.status === "failed" || status.status === "canceled") {
1087
- throw new BlitzReelsError({
1088
- message: `Export ${options.exportId} ended with status ${status.status}`,
1089
- status: 422,
1090
- requestId: null,
1091
- body: status,
1092
- });
1093
- }
1094
- await sleep({ ms: options.intervalMs });
1095
- }
1096
- throw new BlitzReelsError({
1097
- message: `Timed out waiting for export ${options.exportId}`,
1098
- status: 408,
1099
- requestId: null,
1100
- body: { export_id: options.exportId },
1101
- });
1102
- }
1103
- async updateTextContentItem(options) {
1104
- let spec = options.spec;
1105
- if (options.text !== undefined) {
1106
- if (spec === undefined) {
1107
- const items = await this.text.list({ projectId: options.projectId });
1108
- const item = items.data.find((candidate) => candidate.content_item_id === options.contentItemId);
1109
- if (!item?.spec) {
1110
- throw new BlitzReelsError({
1111
- message: `Content item ${options.contentItemId} has no editable text spec.`,
1112
- status: 422,
1113
- requestId: null,
1114
- body: item ?? null,
1115
- });
1116
- }
1117
- spec = item.spec;
1118
- }
1119
- spec = updateTextSpecContent({ spec, text: options.text });
1120
- }
1121
- return this.request({
1122
- method: "PATCH",
1123
- path: `/projects/${encodeURIComponent(options.projectId)}/content-items/${encodeURIComponent(options.contentItemId)}`,
1124
- query: undefined,
1125
- body: {
1126
- name: options.name,
1127
- spec,
1128
- duration_seconds: options.durationSeconds,
1129
- },
1130
- });
1131
- }
1132
- async downloadExport(options) {
1133
- const status = await this.exports.get({ exportId: options.exportId });
1134
- const downloadUrl = status.download_url ?? status.short_download_url;
1135
- if (downloadUrl === null) {
1136
- throw new BlitzReelsError({
1137
- message: `Export ${options.exportId} is not ready for download`,
1138
- status: 409,
1139
- requestId: null,
1140
- body: status,
1141
- });
1142
- }
1143
- const response = await this.fetchFn(downloadUrl);
1144
- if (!response.ok) {
1145
- throw new BlitzReelsError({
1146
- message: `Failed to download export ${options.exportId}`,
1147
- status: response.status,
1148
- requestId: response.headers.get("x-request-id"),
1149
- body: null,
1150
- });
1151
- }
1152
- return response.arrayBuffer();
1153
- }
1154
- }
1155
- function parseJson({ text }) {
1156
- try {
1157
- return JSON.parse(text);
1158
- }
1159
- catch {
1160
- return text;
1161
- }
1162
- }
1
+ export { getBlitzReelsErrorCliExitCode, getBlitzReelsErrorDefaultRetryable, getSequenceOperationDefinition, getSequenceOperationErrorDefinition, isBlitzReelsErrorCode, isSequenceOperationErrorCode, isSequenceOperationId, SEQUENCE_OPERATION_DEFINITIONS, SEQUENCE_OPERATION_ERROR_CODES, SEQUENCE_OPERATION_ERROR_DEFINITIONS, SEQUENCE_OPERATION_IDS, } from "@blitzreels/contracts";
2
+ export { BlitzReelsClient } from "./client.js";
3
+ export { BlitzReelsError } from "./transport.js";
1163
4
  //# sourceMappingURL=index.js.map