@canva/intents 2.0.0 → 2.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/asset/beta.d.ts +1 -0
  2. package/asset/index.d.ts +1 -1
  3. package/beta.d.ts +1309 -0
  4. package/content/beta.d.ts +1246 -0
  5. package/content/index.d.ts +1 -0
  6. package/data/beta.d.ts +1242 -0
  7. package/data/index.d.ts +1 -1242
  8. package/design/beta.d.ts +43 -0
  9. package/design/index.d.ts +1 -43
  10. package/index.d.ts +1 -1309
  11. package/lib/cjs/sdk/intents/asset/beta.js +4 -0
  12. package/lib/cjs/sdk/intents/asset/index.js +15 -1
  13. package/lib/cjs/sdk/intents/beta.js +20 -0
  14. package/lib/cjs/sdk/intents/content/beta.js +13 -0
  15. package/lib/cjs/sdk/intents/content/index.js +18 -0
  16. package/lib/cjs/sdk/intents/data/beta.js +19 -0
  17. package/lib/cjs/sdk/intents/data/index.js +1 -2
  18. package/lib/cjs/sdk/intents/design/beta.js +19 -0
  19. package/lib/cjs/sdk/intents/design/index.js +1 -2
  20. package/lib/cjs/sdk/intents/fake/create.js +24 -0
  21. package/lib/cjs/sdk/intents/index.js +2 -4
  22. package/lib/cjs/sdk/intents/public.js +3 -3
  23. package/lib/cjs/sdk/intents/test/beta.js +18 -0
  24. package/lib/cjs/sdk/intents/test/index.js +19 -0
  25. package/lib/cjs/sdk/intents/version.js +11 -0
  26. package/lib/cjs/sdk/utils/canva_sdk.js +63 -0
  27. package/lib/esm/sdk/intents/asset/beta.js +1 -0
  28. package/lib/esm/sdk/intents/asset/index.js +1 -1
  29. package/lib/esm/sdk/intents/beta.js +3 -0
  30. package/lib/esm/sdk/intents/content/beta.js +3 -0
  31. package/lib/esm/sdk/intents/content/index.js +1 -0
  32. package/lib/esm/sdk/intents/data/beta.js +2 -0
  33. package/lib/esm/sdk/intents/data/index.js +1 -2
  34. package/lib/esm/sdk/intents/design/beta.js +2 -0
  35. package/lib/esm/sdk/intents/design/index.js +1 -2
  36. package/lib/esm/sdk/intents/fake/create.js +14 -0
  37. package/lib/esm/sdk/intents/index.js +1 -3
  38. package/lib/esm/sdk/intents/test/beta.js +1 -0
  39. package/lib/esm/sdk/intents/test/index.js +9 -0
  40. package/lib/esm/sdk/intents/version.js +1 -0
  41. package/lib/esm/sdk/utils/canva_sdk.js +39 -0
  42. package/package.json +26 -16
  43. package/test/beta.d.ts +11 -0
  44. package/test/index.d.ts +1 -0
@@ -0,0 +1,1246 @@
1
+ /**
2
+ * @beta
3
+ * {@link PublishContentError} indicating a custom error occurred in your app's implementation.
4
+ *
5
+ * Return this for application-specific errors such as:
6
+ *
7
+ * - Validation failures
8
+ * - Authentication errors
9
+ * - Rate limiting
10
+ * - Platform-specific restrictions
11
+ *
12
+ * @example Returning custom error with message
13
+ * ```ts
14
+ * if (userQuotaExceeded) {
15
+ * return {
16
+ * status: 'app_error',
17
+ * message: 'You have reached your monthly publish limit. Please upgrade your plan.'
18
+ * };
19
+ * }
20
+ * ```
21
+ */
22
+ export declare type AppError = {
23
+ status: "app_error";
24
+ /**
25
+ * User-friendly message explaining the error.
26
+ */
27
+ message?: string;
28
+ };
29
+
30
+ /**
31
+ * @beta
32
+ * Base file requirement interface.
33
+ */
34
+ declare interface BaseFileRequirement {
35
+ /**
36
+ * File format for this requirement.
37
+ */
38
+ format: PublishFileFormat;
39
+ /**
40
+ * Maximum file size in megabytes.
41
+ *
42
+ * Example: `10` for 10 MB maximum
43
+ */
44
+ maxFileSizeMb?: number;
45
+ }
46
+
47
+ /**
48
+ * @beta
49
+ * Base interface for exported files.
50
+ */
51
+ export declare interface BaseOutputFile {
52
+ /**
53
+ * File format.
54
+ */
55
+ format: PublishFileFormat;
56
+ /**
57
+ * URL to download the exported file.
58
+ *
59
+ * Your app should download from this URL and upload to your platform.
60
+ */
61
+ url: string;
62
+ }
63
+
64
+ /**
65
+ * @beta
66
+ * Base interface for all preview types.
67
+ *
68
+ * Contains common properties shared by image and video previews.
69
+ */
70
+ export declare interface BasePreview {
71
+ /**
72
+ * Unique identifier for this preview.
73
+ *
74
+ * Use this ID with `requestPreviewUpgrade` to upgrade video thumbnails.
75
+ */
76
+ id: string;
77
+ /**
78
+ * Type of media in this preview.
79
+ */
80
+ kind: PreviewKind;
81
+ /**
82
+ * Current state of the preview.
83
+ */
84
+ status: PreviewStatus;
85
+ /**
86
+ * Width of the preview in pixels.
87
+ */
88
+ widthPx: number;
89
+ /**
90
+ * Height of the preview in pixels.
91
+ */
92
+ heightPx: number;
93
+ }
94
+
95
+ /**
96
+ * @beta
97
+ * Main interface for implementing the ContentPublisher intent.
98
+ *
99
+ * Implementing the ContentPublisher intent enables apps to publish contents to external platforms.
100
+ * This allows users to configure publish settings, preview their designs, and share with others.
101
+ *
102
+ * The publishing flow follows this process:
103
+ *
104
+ * 1. User initiates publish action
105
+ * 2. Your app provides publish configuration via `getPublishConfiguration`
106
+ * 3. User selects an output type
107
+ * 4. Your app renders settings UI via `renderSettingsUi`
108
+ * 5. Your app renders preview UI via `renderPreviewUi`
109
+ * 6. User reviews settings and preview
110
+ * 7. Your app publishes the content via `publishContent`
111
+ */
112
+ export declare type ContentPublisherIntent = {
113
+ /**
114
+ * Provides the configuration for the publishing platform.
115
+ *
116
+ * This action is called when the user initiates the publish flow and needs to
117
+ * select an output type for the target platform.
118
+ *
119
+ * Use this to define different publishing configurations for your platform,
120
+ * such as social media posts, videos, or other output types.
121
+ *
122
+ * @returns A promise resolving to the publish configuration or an error
123
+ *
124
+ * @example Defining publish configuration for a social media platform
125
+ * ```ts
126
+ * import type { GetPublishConfigurationResponse } from '@canva/intents/content';
127
+ *
128
+ * async function getPublishConfiguration(): Promise<GetPublishConfigurationResponse> {
129
+ * return {
130
+ * status: 'completed',
131
+ * outputTypes: [
132
+ * {
133
+ * id: 'instagram_post',
134
+ * displayName: 'Instagram Post',
135
+ * mediaSlots: [
136
+ * {
137
+ * id: 'main_image',
138
+ * displayName: 'Post Image',
139
+ * fileCount: { min: 1, max: 10 },
140
+ * accepts: {
141
+ * image: { format: 'jpg', aspectRatio: { min: 0.8, max: 1.91 } }
142
+ * }
143
+ * }
144
+ * ]
145
+ * }
146
+ * ]
147
+ * };
148
+ * }
149
+ * ```
150
+ */
151
+ getPublishConfiguration: () => Promise<GetPublishConfigurationResponse>;
152
+
153
+ /**
154
+ * Renders a user interface for configuring publish settings.
155
+ *
156
+ * This action is called after the user selects an output type. Your UI should
157
+ * allow users to configure platform-specific settings such as captions, tags,
158
+ * privacy settings, or publishing destinations.
159
+ *
160
+ * Use the `updatePublishSettings` callback to save user settings and validate them.
161
+ * Settings are stored in the `publishRef` string (maximum 5KB).
162
+ *
163
+ * @param request - Configuration and callbacks for the publish settings UI.
164
+ *
165
+ * @example Rendering a settings UI with publish configuration
166
+ * ```ts
167
+ * import { createRoot } from 'react-dom/client';
168
+ * import type { RenderSettingsUiRequest } from '@canva/intents/content';
169
+ *
170
+ * function renderSettingsUi(request: RenderSettingsUiRequest): void {
171
+ * const SettingsUiApp = () => (
172
+ * <AppUiProvider>
173
+ * <SettingsUi request={request} />
174
+ * </AppUiProvider>
175
+ * );
176
+ *
177
+ * createRoot().render(<SettingsUiApp />)
178
+ * }
179
+ * ```
180
+ */
181
+ renderSettingsUi: (request: RenderSettingsUiRequest) => void;
182
+ /**
183
+ * Renders a user interface for previewing the content.
184
+ *
185
+ * This action is called after the settings UI is rendered. Your UI should display
186
+ * a preview of how the content will appear on the target platform.
187
+ *
188
+ * Previews update dynamically as users modify their content or settings. For videos,
189
+ * start with lightweight thumbnails and use `requestPreviewUpgrade` to load full
190
+ * video previews on demand to optimize performance.
191
+ *
192
+ * @param request - Configuration and callbacks for the preview UI.
193
+ *
194
+ * @example Rendering a preview UI with video optimization
195
+ * ```ts
196
+ * import { createRoot } from 'react-dom/client';
197
+ * import type { RenderPreviewUiRequest } from '@canva/intents/content';
198
+ *
199
+ * function renderPreviewUi(request: RenderPreviewUiRequest): void {
200
+ * const PreviewUiApp = () => (
201
+ * <AppUiProvider>
202
+ * <PreviewUi request={request} />
203
+ * </AppUiProvider>
204
+ * );
205
+ *
206
+ * createRoot().render(<PreviewUiApp />)
207
+ * }
208
+ * ```
209
+ */
210
+ renderPreviewUi: (request: RenderPreviewUiRequest) => void;
211
+ /**
212
+ * Publishes the content to the external platform.
213
+ *
214
+ * This action is called when the user confirms the publish action after reviewing
215
+ * settings and preview. Your implementation should send the exported files
216
+ * to your platform's API.
217
+ *
218
+ * The `outputMedia` contains production-ready files that match the requirements
219
+ * specified in your output types. The `publishRef` contains the user's settings
220
+ * from the settings UI.
221
+ *
222
+ * @param request - Parameters for the publish operation.
223
+ * @returns A promise resolving to either a successful result with the published content details or an error.
224
+ *
225
+ * @example Publishing content to an external platform
226
+ * ```ts
227
+ * import type { PublishContentRequest, PublishContentResponse } from '@canva/intents/content';
228
+ *
229
+ * async function publishContent(request: PublishContentRequest): Promise<PublishContentResponse> {
230
+ * const { publishRef, outputType, outputMedia } = request;
231
+ *
232
+ * try {
233
+ * // Parse settings from publishRef
234
+ * const settings = publishRef ? JSON.parse(publishRef) : {};
235
+ *
236
+ * // Upload files to your platform
237
+ * const uploadedFiles = await Promise.all(
238
+ * outputMedia.flatMap(media =>
239
+ * media.files.map(file => uploadFile(file.url))
240
+ * )
241
+ * );
242
+ *
243
+ * // Create post on your platform
244
+ * const result = await createPost({
245
+ * files: uploadedFiles,
246
+ * caption: settings.caption
247
+ * });
248
+ *
249
+ * return {
250
+ * status: 'completed',
251
+ * externalId: result.id,
252
+ * externalUrl: result.url
253
+ * };
254
+ * } catch (error) {
255
+ * return {
256
+ * status: 'remote_request_failed'
257
+ * };
258
+ * }
259
+ * }
260
+ * ```
261
+ */
262
+ publishContent: (
263
+ request: PublishContentRequest,
264
+ ) => Promise<PublishContentResponse>;
265
+ };
266
+
267
+ /**
268
+ * @beta
269
+ * A function that can be called to dispose of a callback.
270
+ */
271
+ export declare type Disposer = () => void;
272
+
273
+ /**
274
+ * @beta
275
+ * Exact value range constraint.
276
+ * @example Exact value range
277
+ * ```ts
278
+ * const exactValue: ValueRange = { exact: 1 }; // Must be exactly 1
279
+ * ```
280
+ */
281
+ export declare type ExactValueRange = {
282
+ exact: number;
283
+ };
284
+
285
+ /**
286
+ * @beta
287
+ * Successful response from getting publish configuration.
288
+ */
289
+ export declare type GetPublishConfigurationCompleted = {
290
+ status: "completed";
291
+ /**
292
+ * Array of available output types for your platform.
293
+ *
294
+ * Define different output types for various content formats that
295
+ * your platform supports (e.g., posts, stories, videos).
296
+ */
297
+ outputTypes: OutputType[];
298
+ };
299
+
300
+ /**
301
+ * @beta
302
+ * {@link GetPublishConfigurationError} error indicating a custom error occurred.
303
+ */
304
+ export declare type GetPublishConfigurationError = AppError;
305
+
306
+ /**
307
+ * @beta
308
+ * Response from getting publish configuration.
309
+ */
310
+ export declare type GetPublishConfigurationResponse =
311
+ | GetPublishConfigurationCompleted
312
+ | GetPublishConfigurationError;
313
+
314
+ /**
315
+ * @beta
316
+ * Exported image file ready for publishing.
317
+ */
318
+ export declare interface ImageOutputFile extends BaseOutputFile {
319
+ /**
320
+ * Width of the image in pixels.
321
+ */
322
+ widthPx: number;
323
+ /**
324
+ * Height of the image in pixels.
325
+ */
326
+ heightPx: number;
327
+ }
328
+
329
+ /**
330
+ * @beta
331
+ * Image preview in various states.
332
+ */
333
+ export declare type ImagePreview =
334
+ | ImagePreviewLoading
335
+ | ImagePreviewReady
336
+ | ImagePreviewError;
337
+
338
+ /**
339
+ * @beta
340
+ * Image preview that failed to generate.
341
+ *
342
+ * Display an error state to the user.
343
+ */
344
+ export declare interface ImagePreviewError extends BasePreview {
345
+ kind: "image";
346
+ status: "error";
347
+ /**
348
+ * Optional, user-facing error message to display in the preview UI.
349
+ */
350
+ userFacingErrorMessage?: string;
351
+ }
352
+
353
+ /**
354
+ * @beta
355
+ * Image preview that is currently being generated.
356
+ *
357
+ * Display a loading state until the preview transitions to `"ready"` or `"error"`.
358
+ */
359
+ export declare interface ImagePreviewLoading extends BasePreview {
360
+ kind: "image";
361
+ status: "loading";
362
+ }
363
+
364
+ /**
365
+ * @beta
366
+ * Image preview that is ready to display.
367
+ *
368
+ * Contains the URL to the preview image.
369
+ */
370
+ export declare interface ImagePreviewReady extends BasePreview {
371
+ kind: "image";
372
+ status: "ready";
373
+ /**
374
+ * Image format of the preview.
375
+ */
376
+ format: "png" | "jpg";
377
+ /**
378
+ * URL to the preview image.
379
+ *
380
+ * Use this URL to display the preview to users.
381
+ */
382
+ url: string;
383
+ }
384
+
385
+ /**
386
+ * @beta
387
+ * Image file requirements for a media slot.
388
+ *
389
+ * Specifies format, aspect ratio, and size constraints for images.
390
+ *
391
+ * @example Image requirements for social media post
392
+ * ```ts
393
+ * const imageReq: ImageRequirement = {
394
+ * format: 'jpg',
395
+ * aspectRatio: { min: 0.8, max: 1.91 },
396
+ * maxFileSizeMb: 8
397
+ * };
398
+ * ```
399
+ */
400
+ export declare interface ImageRequirement extends BaseFileRequirement {
401
+ /**
402
+ * Supported image format.
403
+ */
404
+ format: "png" | "jpg";
405
+ /**
406
+ * Aspect ratio constraint (width / height).
407
+ *
408
+ * Examples:
409
+ * - `{ exact: 16/9 }`: Widescreen (16:9)
410
+ * - `{ min: 0.8, max: 1.91 }`: Instagram range
411
+ */
412
+ aspectRatio?: ValueRange;
413
+ }
414
+
415
+ /**
416
+ * @beta
417
+ * Maximum value range constraint.
418
+ * @example Maximum value range
419
+ * ```ts
420
+ * const maxValue: ValueRange = { max: 10 }; // At most 10
421
+ * ```
422
+ */
423
+ export declare type MaxValueRange = {
424
+ max: number;
425
+ };
426
+
427
+ /**
428
+ * @beta
429
+ * Configuration for a media slot within an output type.
430
+ *
431
+ * Defines what type of media is accepted, requirements, and constraints.
432
+ *
433
+ * @example Image slot with aspect ratio requirements
434
+ * ```ts
435
+ * const thumbnailSlot: MediaSlot = {
436
+ * id: 'thumbnail',
437
+ * displayName: 'Video Thumbnail',
438
+ * fileCount: { exact: 1 },
439
+ * accepts: {
440
+ * image: {
441
+ * format: 'jpg',
442
+ * aspectRatio: { exact: 16/9 },
443
+ * maxFileSizeMb: 2
444
+ * }
445
+ * }
446
+ * };
447
+ * ```
448
+ */
449
+ export declare type MediaSlot = {
450
+ /**
451
+ * Unique identifier for this media slot within the output type.
452
+ */
453
+ id: string;
454
+ /**
455
+ * User-facing name for this media slot.
456
+ *
457
+ * Examples: `"Post Image"`, `"Video Thumbnail"`, `"Main Video"`.
458
+ */
459
+ displayName: string;
460
+ /**
461
+ * Number of files accepted in this slot.
462
+ *
463
+ * Use this to specify single or multiple file requirements.
464
+ * Examples:
465
+ * - `{ exact: 1 }`: Exactly one file
466
+ * - `{ min: 1, max: 10 }`: Between 1 and 10 files
467
+ * - undefined: Any number of files
468
+ */
469
+ fileCount?: ValueRange;
470
+ /**
471
+ * File type requirements for this slot.
472
+ *
473
+ * Note the following behavior:
474
+ *
475
+ * - Provide at least one of `image` or `video`
476
+ * - If both are provided, files for this slot may be either images or videos; each file
477
+ * must satisfy the corresponding requirement for its media type
478
+ * - To restrict the slot to a single media type, provide only that requirement
479
+ * - `fileCount` applies across all files accepted by the slot regardless of media type
480
+ */
481
+ accepts: {
482
+ image?: ImageRequirement;
483
+ video?: VideoRequirement;
484
+ };
485
+ };
486
+
487
+ /**
488
+ * @beta
489
+ * Minimum and maximum value range constraint.
490
+ * Ranges are inclusive `(min ≤ value ≤ max)`.
491
+ * @example Minimum and maximum value range
492
+ * ```ts
493
+ * const minMaxValue: ValueRange = { min: 1, max: 10 }; // Between 1 and 10
494
+ * ```
495
+ */
496
+ export declare type MinMaxValueRange = {
497
+ min: number;
498
+ max: number;
499
+ };
500
+
501
+ /**
502
+ * @beta
503
+ * Minimum value range constraint.
504
+ * @example Minimum value range
505
+ * ```ts
506
+ * const minValue: ValueRange = { min: 3 }; // At least 3
507
+ * ```
508
+ */
509
+ export declare type MinValueRange = {
510
+ min: number;
511
+ };
512
+
513
+ /**
514
+ * @beta
515
+ * Exported file ready for publishing.
516
+ */
517
+ export declare type OutputFile = ImageOutputFile | VideoOutputFile;
518
+
519
+ /**
520
+ * @beta
521
+ * Production-ready exported files for a specific media slot.
522
+ *
523
+ * These are the final files that should be uploaded to your platform.
524
+ */
525
+ export declare type OutputMedia = {
526
+ /**
527
+ * ID of the media slot these files belong to.
528
+ *
529
+ * Matches a media slot ID from your output type definition.
530
+ */
531
+ mediaSlotId: string;
532
+ /**
533
+ * Array of exported files for this media slot.
534
+ *
535
+ * Files match the requirements specified in your media slot configuration.
536
+ */
537
+ files: OutputFile[];
538
+ };
539
+
540
+ /**
541
+ * @beta
542
+ * Configuration for an output type.
543
+ *
544
+ * Defines a specific publishing format your platform supports,
545
+ * including what media is required and accepted file types.
546
+ *
547
+ * @example Defining an Instagram post output type
548
+ * ```ts
549
+ * const instagramPost: OutputType = {
550
+ * id: 'instagram_post',
551
+ * displayName: 'Instagram Post',
552
+ * mediaSlots: [
553
+ * {
554
+ * id: 'main_image',
555
+ * displayName: 'Post Image',
556
+ * fileCount: { min: 1, max: 10 },
557
+ * accepts: {
558
+ * image: {
559
+ * format: 'jpg',
560
+ * aspectRatio: { min: 0.8, max: 1.91 },
561
+ * maxFileSizeMb: 8
562
+ * }
563
+ * }
564
+ * }
565
+ * ]
566
+ * };
567
+ * ```
568
+ */
569
+ export declare type OutputType = {
570
+ /**
571
+ * Unique identifier for this output type.
572
+ *
573
+ * Use descriptive IDs like `"instagram_post"` or `"youtube_video"`.
574
+ */
575
+ id: string;
576
+ /**
577
+ * User-facing name for this output type.
578
+ *
579
+ * This is displayed to users when selecting where to publish.
580
+ * Examples: `"Instagram Post"`, `"YouTube Video"`, `"Twitter Post"`.
581
+ */
582
+ displayName: string;
583
+ /**
584
+ * Array of media slots defining what content is needed.
585
+ *
586
+ * Each slot represents a piece of media required for publishing,
587
+ * such as a main image, thumbnail, or video.
588
+ */
589
+ mediaSlots: MediaSlot[];
590
+ };
591
+
592
+ /**
593
+ * @beta
594
+ * Action to be taken after publishing completes successfully.
595
+ */
596
+ export declare type PostPublishAction = PostPublishActionRedirect;
597
+
598
+ /**
599
+ * @beta
600
+ * Redirect action to navigate the user to a URL after publishing.
601
+ *
602
+ * @example Redirecting to content editor
603
+ * ```ts
604
+ * const postPublishAction: PostPublishActionRedirect = {
605
+ * type: 'redirect',
606
+ * url: 'https://example.com/posts/12345/edit'
607
+ * };
608
+ * ```
609
+ */
610
+ export declare type PostPublishActionRedirect = {
611
+ type: "redirect";
612
+ /**
613
+ * The URL to redirect the user to after publishing.
614
+ */
615
+ url: string;
616
+ };
617
+
618
+ /**
619
+ * @beta
620
+ *
621
+ * Prepares a {@link ContentPublisherIntent|Content Publisher Intent}.
622
+ *
623
+ * @example
624
+ * ```tsx
625
+ * import { prepareContentPublisher } from "@canva/intents/content";
626
+ *
627
+ * prepareContentPublisher({
628
+ * getPublishConfiguration: async (params) => {
629
+ * // Implement the logic to get the publish configuration
630
+ * },
631
+ * renderSettingsUi: (params) => {
632
+ * // Implement the UI for settings view
633
+ * },
634
+ * renderPreviewUi: (params) => {
635
+ * // Implement the UI for preview view
636
+ * },
637
+ * publishContent: async (params) => {
638
+ * // Implement the logic to publish the content
639
+ * },
640
+ * });
641
+ * ```
642
+ */
643
+ export declare const prepareContentPublisher: (
644
+ implementation: ContentPublisherIntent,
645
+ ) => void;
646
+
647
+ /**
648
+ * @beta
649
+ * Preview item for an image or video.
650
+ *
651
+ * Check the `kind` and `status` properties to determine the type and state.
652
+ */
653
+ export declare type Preview = ImagePreview | VideoPreview;
654
+
655
+ /**
656
+ * @beta
657
+ * Type of preview media.
658
+ */
659
+ export declare type PreviewKind = "image" | "video";
660
+
661
+ /**
662
+ * @beta
663
+ * Preview media for a specific media slot.
664
+ *
665
+ * Contains preview URLs and metadata for images or videos in the design.
666
+ */
667
+ export declare type PreviewMedia = {
668
+ /**
669
+ * ID of the media slot this preview belongs to.
670
+ *
671
+ * Matches a media slot ID from your output type definition.
672
+ */
673
+ mediaSlotId: string;
674
+ /**
675
+ * Array of preview items for this media slot.
676
+ *
677
+ * May contain multiple previews if the media slot accepts multiple files.
678
+ */
679
+ previews: Preview[];
680
+ };
681
+
682
+ /**
683
+ * @beta
684
+ * State of a preview item.
685
+ */
686
+ export declare type PreviewStatus =
687
+ | "loading"
688
+ | "thumbnail"
689
+ | "upgrading"
690
+ | "ready"
691
+ | "error";
692
+
693
+ /**
694
+ * @beta
695
+ * Successful response from publishing a content.
696
+ *
697
+ * @example Basic successful publish
698
+ * ```ts
699
+ * return {
700
+ * status: 'completed',
701
+ * externalId: 'post_12345',
702
+ * externalUrl: 'https://example.com/posts/12345'
703
+ * };
704
+ * ```
705
+ *
706
+ * @example Successful publish with redirect
707
+ * ```ts
708
+ * return {
709
+ * status: 'completed',
710
+ * externalId: 'video_67890',
711
+ * externalUrl: 'https://example.com/videos/67890',
712
+ * postPublishAction: {
713
+ * type: 'redirect',
714
+ * url: 'https://example.com/videos/67890/edit'
715
+ * }
716
+ * };
717
+ * ```
718
+ */
719
+ export declare type PublishContentCompleted = {
720
+ status: "completed";
721
+ /**
722
+ * Unique identifier returned from your external platform. You can use this for:
723
+ *
724
+ * - Tracking published content
725
+ * - Fetching insights data for the published content
726
+ * - Linking back to the content in future operations
727
+ */
728
+ externalId?: string;
729
+ /**
730
+ * Direct URL to the published content on your platform.
731
+ *
732
+ * Users can visit this URL to view their published content.
733
+ * This may be displayed to users or used for sharing.
734
+ */
735
+ externalUrl?: string;
736
+ /**
737
+ * Optional action to perform after publishing completes.
738
+ *
739
+ * Currently supports redirecting users to a specific URL after publishing.
740
+ */
741
+ postPublishAction?: PostPublishAction;
742
+ };
743
+
744
+ /**
745
+ * @beta
746
+ * Error response from publishing a content.
747
+ *
748
+ * Return the appropriate error type based on the failure:
749
+ *
750
+ * - `"remote_request_failed"`: Network or API errors with your platform
751
+ * - `"app_error"`: Custom application errors with optional message
752
+ */
753
+ export declare type PublishContentError = RemoteRequestFailedError | AppError;
754
+
755
+ /**
756
+ * @beta
757
+ * Parameters required for publishing the content.
758
+ * Contains all the information needed to send the content to your external platform.
759
+ */
760
+ export declare type PublishContentRequest = {
761
+ /**
762
+ * Platform-specific settings reference containing user configurations.
763
+ *
764
+ * This is the same reference you saved via `updatePublishSettings` in the settings UI.
765
+ * Parse this string to retrieve the user's publish settings (e.g., captions, tags, privacy).
766
+ *
767
+ * Maximum size: 5KB
768
+ */
769
+ publishRef?: string;
770
+ /**
771
+ * The output type selected by the user for this publish operation.
772
+ *
773
+ * This matches one of the output types you provided in `getPublishConfiguration`.
774
+ */
775
+ outputType: OutputType;
776
+ /**
777
+ * Production-ready exported files matching the requirements from your output type.
778
+ *
779
+ * These files are ready to upload to your platform and match the format, size,
780
+ * and aspect ratio requirements specified in your media slots.
781
+ */
782
+ outputMedia: OutputMedia[];
783
+ };
784
+
785
+ /**
786
+ * @beta
787
+ * Response from a publish content operation.
788
+ *
789
+ * This can be either a successful completion or an error response.
790
+ */
791
+ export declare type PublishContentResponse =
792
+ | PublishContentCompleted
793
+ | PublishContentError;
794
+
795
+ /**
796
+ * @beta
797
+ * Supported file formats for publishing.
798
+ */
799
+ export declare type PublishFileFormat = "png" | "jpg" | "mp4";
800
+
801
+ /**
802
+ * @beta
803
+ * Validation state indicating whether publish settings are complete and valid.
804
+ */
805
+ export declare type PublishRefValidityState =
806
+ | "valid"
807
+ | "invalid_missing_required_fields"
808
+ | "invalid_authentication_required";
809
+
810
+ /**
811
+ * @beta
812
+ * Configuration for publish settings.
813
+ *
814
+ * Contains the user's settings and their validation state. Use this to
815
+ * control whether the publish button is enabled.
816
+ */
817
+ export declare type PublishSettings = {
818
+ /**
819
+ * Serialized platform-specific settings for publishing.
820
+ *
821
+ * Store all information your app needs to publish the content in this string.
822
+ * This might include:
823
+ *
824
+ * - Captions or descriptions
825
+ * - Tags or hashtags
826
+ * - Privacy settings
827
+ * - Publishing destination (account, page, etc.)
828
+ * - Scheduling information
829
+ *
830
+ * This reference will be provided to your `publishContent` method when publishing.
831
+ *
832
+ * Maximum size: 5KB
833
+ *
834
+ * @example Serializing settings
835
+ * ```ts
836
+ * const settings = {
837
+ * caption: 'Check out my design!',
838
+ * tags: ['design', 'creative'],
839
+ * privacy: 'public'
840
+ * };
841
+ * const publishRef = JSON.stringify(settings);
842
+ * ```
843
+ */
844
+ publishRef?: string;
845
+ /**
846
+ * Validation state of the publish settings.
847
+ *
848
+ * Controls whether the publish button is enabled:
849
+ *
850
+ * - `"valid"`: Settings are complete and valid, publish button is enabled
851
+ * - `"invalid_missing_required_fields"`: Required settings are missing, publish button is disabled
852
+ * - `"invalid_authentication_required"`: User must authenticate before publishing can proceed
853
+ */
854
+ validityState: PublishRefValidityState;
855
+ };
856
+
857
+ /**
858
+ * @beta
859
+ * {@link PublishContentError} indicating failure of the remote request to the external platform.
860
+ *
861
+ * Return this error for:
862
+ *
863
+ * - Network connectivity issues
864
+ * - API endpoint failures
865
+ * - HTTP errors from your platform
866
+ * - Timeout errors
867
+ *
868
+ * @example Handling network errors
869
+ * ```ts
870
+ * try {
871
+ * await uploadToExternalPlatform(file);
872
+ * } catch (error) {
873
+ * return { status: 'remote_request_failed' };
874
+ * }
875
+ * ```
876
+ */
877
+ export declare type RemoteRequestFailedError = {
878
+ status: "remote_request_failed";
879
+ };
880
+
881
+ /**
882
+ * @beta
883
+ * Configuration required for rendering the preview UI.
884
+ *
885
+ * Provides callbacks for managing preview media and responding to preview updates.
886
+ */
887
+ export declare type RenderPreviewUiRequest = {
888
+ /**
889
+ * Callback to upgrade video thumbnail previews to full video media.
890
+ *
891
+ * Call this function when you need full video previews instead of lightweight thumbnails.
892
+ * This helps optimize performance by deferring full video loading until needed.
893
+ *
894
+ * Upgrades may complete asynchronously; listen to `registerOnPreviewChange` for updates
895
+ * to receive the upgraded video previews.
896
+ *
897
+ * @param previewIds - Array of preview IDs to upgrade from thumbnail to full video
898
+ *
899
+ * @example Upgrading video previews on user interaction
900
+ * ```ts
901
+ * // When user clicks on a video thumbnail, upgrade to full video
902
+ * if (preview.kind === 'video' && preview.status === 'thumbnail') {
903
+ * requestPreviewUpgrade([preview.id]);
904
+ * }
905
+ * ```
906
+ */
907
+ requestPreviewUpgrade: (previewIds: string[]) => void;
908
+ /**
909
+ * Registers a callback to be invoked when preview data changes.
910
+ *
911
+ * This callback is triggered when:
912
+ *
913
+ * - The design content changes
914
+ * - The output type changes
915
+ * - Preview media is upgraded from thumbnail to full video
916
+ * - Export settings are modified
917
+ *
918
+ * Use this to update your preview UI in real-time as users modify their design.
919
+ *
920
+ * @param callback - The callback invoked when preview data is updated
921
+ * @returns A disposer function that cleans up the registered callback
922
+ *
923
+ * @example Handling preview updates
924
+ * ```ts
925
+ * const disposer = registerOnPreviewChange(({ previewMedia, outputType, publishRef }) => {
926
+ * // Update your preview UI with the new preview media
927
+ * previewMedia.forEach((media) => {
928
+ * media.previews.forEach((preview) => {
929
+ * if (preview.status === 'ready') {
930
+ * displayPreview(preview);
931
+ * }
932
+ * });
933
+ * });
934
+ * });
935
+ *
936
+ * // Clean up when preview UI is unmounted
937
+ * onUnmount(() => disposer());
938
+ * ```
939
+ */
940
+ registerOnPreviewChange: (
941
+ callback: (opts: {
942
+ previewMedia: PreviewMedia[];
943
+ /** The output type that the preview data is for */
944
+ outputType: OutputType;
945
+ /** The current publish settings reference, if available */
946
+ publishRef?: string;
947
+ }) => void,
948
+ ) => Disposer;
949
+ };
950
+
951
+ /**
952
+ * @beta
953
+ * Configuration for the publish settings UI.
954
+ *
955
+ * This type provides the necessary callbacks and configuration for rendering
956
+ * a custom publish settings interface where users configure platform-specific options.
957
+ */
958
+ export declare type RenderSettingsUiRequest = {
959
+ /**
960
+ * Callback to save and validate the user's publish settings.
961
+ *
962
+ * Call this function whenever the user modifies their settings to:
963
+ *
964
+ * - Save the settings for later use in `publishContent`
965
+ * - Validate that required fields are filled
966
+ * - Enable or disable the publish button based on validity
967
+ *
968
+ * Store all necessary publishing information in the `publishRef` string.
969
+ * This will be provided to your `publishContent` method when the user publishes.
970
+ *
971
+ * @param settings - The new publish settings to save
972
+ * @returns A promise that resolves when the settings are successfully saved
973
+ * @throws Will throw `CanvaError('bad_request')` if {@link PublishSettings.publishRef} exceeds 5KB.
974
+ *
975
+ * @example Updating settings as user types
976
+ * ```ts
977
+ * // As user fills in form fields, update settings
978
+ * function handleCaptionChange(caption: string) {
979
+ * const settings = { caption, tags: currentTags };
980
+ * const publishRef = JSON.stringify(settings);
981
+ *
982
+ * updatePublishSettings({
983
+ * publishRef,
984
+ * validityState: caption ? 'valid' : 'invalid_missing_required_fields'
985
+ * });
986
+ * }
987
+ * ```
988
+ */
989
+ updatePublishSettings: (
990
+ publishSettings: PublishSettings,
991
+ ) => Promise<UpdatePublishSettingsResponse>;
992
+ /**
993
+ * Registers a callback to be invoked when the settings UI context changes.
994
+ *
995
+ * This callback is triggered when the user changes the output type in the publish flow.
996
+ * Use this to update your settings UI to match the requirements of the new output type.
997
+ *
998
+ * @param callback - The callback invoked when settings context is updated.
999
+ * @returns A disposer function that cleans up the registered callback.
1000
+ *
1001
+ * @example Adapting UI for different output types
1002
+ * ```ts
1003
+ * registerOnSettingsUiContextChange((context) => {
1004
+ * if (context.outputType.id === 'instagram_post') {
1005
+ * // Show Instagram-specific settings
1006
+ * showHashtagField();
1007
+ * } else if (context.outputType.id === 'instagram_story') {
1008
+ * // Show instagram_story settings
1009
+ * showCaptionField();
1010
+ * }
1011
+ * });
1012
+ * ```
1013
+ */
1014
+ registerOnSettingsUiContextChange: (
1015
+ callback: (context: SettingsUiContext) => void,
1016
+ ) => Disposer;
1017
+ };
1018
+
1019
+ /**
1020
+ * @beta
1021
+ * Context information for the publish settings UI.
1022
+ *
1023
+ * Provides information about the current state of the settings UI to help
1024
+ * you adapt the interface based on the selected output type.
1025
+ */
1026
+ export declare type SettingsUiContext = {
1027
+ /**
1028
+ * The currently selected output type.
1029
+ *
1030
+ * Use this to customize your settings UI based on the requirements
1031
+ * of different output types.
1032
+ */
1033
+ outputType: OutputType;
1034
+ };
1035
+
1036
+ /**
1037
+ * @beta
1038
+ * Successful response from updating the publish settings.
1039
+ */
1040
+ export declare type UpdatePublishSettingsCompleted = {
1041
+ status: "completed";
1042
+ };
1043
+
1044
+ /**
1045
+ * @beta
1046
+ * Response from updating the publish settings.
1047
+ */
1048
+ export declare type UpdatePublishSettingsResponse =
1049
+ UpdatePublishSettingsCompleted;
1050
+
1051
+ /**
1052
+ * @beta
1053
+ * Numeric value range constraint.
1054
+ * Used to specify requirements for aspect ratios, durations, file counts, etc.
1055
+ */
1056
+ export declare type ValueRange =
1057
+ | ExactValueRange
1058
+ | MinValueRange
1059
+ | MaxValueRange
1060
+ | MinMaxValueRange;
1061
+
1062
+ /**
1063
+ * @beta
1064
+ * Exported video file ready for publishing.
1065
+ */
1066
+ export declare interface VideoOutputFile extends BaseOutputFile {
1067
+ /**
1068
+ * Width of the video in pixels.
1069
+ */
1070
+ widthPx: number;
1071
+ /**
1072
+ * Height of the video in pixels.
1073
+ */
1074
+ heightPx: number;
1075
+ }
1076
+
1077
+ /**
1078
+ * @beta
1079
+ * Video preview in various states.
1080
+ *
1081
+ * Videos transition through states: `"loading"` → `"thumbnail"` → `"upgrading"` → `"ready"`.
1082
+ * Start with thumbnails for better performance, then upgrade to full video using `requestPreviewUpgrade`.
1083
+ */
1084
+ export declare type VideoPreview =
1085
+ | VideoPreviewLoading
1086
+ | VideoPreviewThumbnail
1087
+ | VideoPreviewUpgrading
1088
+ | VideoPreviewReady
1089
+ | VideoPreviewError;
1090
+
1091
+ /**
1092
+ * @beta
1093
+ * Video preview that failed to generate.
1094
+ *
1095
+ * Display an error state to the user.
1096
+ */
1097
+ export declare interface VideoPreviewError extends BasePreview {
1098
+ kind: "video";
1099
+ status: "error";
1100
+ /**
1101
+ * Optional, user-facing error message to display in the preview UI.
1102
+ */
1103
+ userFacingErrorMessage?: string;
1104
+ }
1105
+
1106
+ /**
1107
+ * @beta
1108
+ * Video preview that is currently being generated.
1109
+ *
1110
+ * Display a loading state until the preview transitions to `"thumbnail"` or `"error"`.
1111
+ */
1112
+ export declare interface VideoPreviewLoading extends BasePreview {
1113
+ kind: "video";
1114
+ status: "loading";
1115
+ }
1116
+
1117
+ /**
1118
+ * @beta
1119
+ * Video preview with full video ready to play.
1120
+ *
1121
+ * Contains URLs for both the video and thumbnail.
1122
+ */
1123
+ export declare interface VideoPreviewReady extends BasePreview {
1124
+ kind: "video";
1125
+ status: "ready";
1126
+ /**
1127
+ * Video format.
1128
+ */
1129
+ format: "mp4";
1130
+ /**
1131
+ * URL to the full video.
1132
+ *
1133
+ * Use this URL in a video player.
1134
+ */
1135
+ url: string;
1136
+ /**
1137
+ * Format of the thumbnail image.
1138
+ */
1139
+ thumbnailFormat: "png" | "jpg";
1140
+ /**
1141
+ * URL to the thumbnail image.
1142
+ *
1143
+ * Can be used as a poster image for the video player.
1144
+ */
1145
+ thumbnailUrl: string;
1146
+ /**
1147
+ * Video duration in milliseconds.
1148
+ */
1149
+ durationMs?: number;
1150
+ }
1151
+
1152
+ /**
1153
+ * @beta
1154
+ * Video preview with lightweight thumbnail available.
1155
+ *
1156
+ * This is the initial state for video previews. Show the thumbnail image
1157
+ * and call `requestPreviewUpgrade` when the user needs the full video.
1158
+ */
1159
+ export declare interface VideoPreviewThumbnail extends BasePreview {
1160
+ kind: "video";
1161
+ status: "thumbnail";
1162
+ /**
1163
+ * Format of the thumbnail image.
1164
+ */
1165
+ thumbnailFormat: "png" | "jpg";
1166
+ /**
1167
+ * URL to the thumbnail image.
1168
+ *
1169
+ * Display this lightweight image until full video is needed.
1170
+ */
1171
+ thumbnailUrl: string;
1172
+ /**
1173
+ * Video duration in milliseconds.
1174
+ */
1175
+ durationMs?: number;
1176
+ }
1177
+
1178
+ /**
1179
+ * @beta
1180
+ * Video preview that is being upgraded from thumbnail to full video.
1181
+ *
1182
+ * Display the thumbnail with a loading indicator until the video is ready.
1183
+ */
1184
+ export declare interface VideoPreviewUpgrading extends BasePreview {
1185
+ kind: "video";
1186
+ status: "upgrading";
1187
+ /**
1188
+ * Format of the thumbnail image.
1189
+ */
1190
+ thumbnailFormat: "png" | "jpg";
1191
+ /**
1192
+ * URL to the thumbnail image.
1193
+ *
1194
+ * Continue showing the thumbnail while the full video loads.
1195
+ */
1196
+ thumbnailUrl: string;
1197
+ /**
1198
+ * Video duration in milliseconds.
1199
+ */
1200
+ durationMs?: number;
1201
+ }
1202
+
1203
+ /**
1204
+ * @beta
1205
+ * Video file requirements for a media slot.
1206
+ *
1207
+ * Specifies format, aspect ratio, duration, and size constraints for videos.
1208
+ *
1209
+ * @example Video requirements for YouTube
1210
+ * ```ts
1211
+ * const videoReq: VideoRequirement = {
1212
+ * format: 'mp4',
1213
+ * aspectRatio: { exact: 16/9 },
1214
+ * durationMs: { min: 1000, max: 600000 },
1215
+ * maxFileSizeMb: 100
1216
+ * };
1217
+ * ```
1218
+ */
1219
+ export declare interface VideoRequirement extends BaseFileRequirement {
1220
+ /**
1221
+ * Supported video format.
1222
+ */
1223
+ format: "mp4";
1224
+ /**
1225
+ * Aspect ratio constraint (width / height).
1226
+ *
1227
+ * Examples:
1228
+ * - `{ exact: 16/9 }`: Widescreen
1229
+ * - `{ exact: 9/16 }`: Vertical/Story format
1230
+ */
1231
+ aspectRatio?: ValueRange;
1232
+ /**
1233
+ * Duration constraint in milliseconds.
1234
+ *
1235
+ * Examples:
1236
+ * - `{ max: 60000 }`: Maximum 60 seconds
1237
+ * - `{ min: 3000, max: 600000 }`: Between 3 seconds and 10 minutes
1238
+ */
1239
+ durationMs?: ValueRange;
1240
+ /**
1241
+ * @deprecated use durationMs instead.
1242
+ */
1243
+ duration?: ValueRange;
1244
+ }
1245
+
1246
+ export {};