@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
package/index.d.ts CHANGED
@@ -1,1309 +1 @@
1
- /**
2
- * @public
3
- * A disclosure identifying if the app generated this asset using AI.
4
- *
5
- * @remarks
6
- * Helps users make informed decisions about the content they interact with.
7
- *
8
- * AI is generally defined as any machine system that, given an objective, infers how to generate an output from an input.
9
- * Some examples include "generative AI", "large language models", and "machine learning".
10
- *
11
- * **App Generated**
12
- *
13
- * 'app_generated' indicates when the app creates or significantly alters an asset using AI. Includes when
14
- * the app makes a request to a third-party service to do so.
15
- *
16
- * A significantly altered asset means the AI changes key information or details, such as
17
- * removing or replacing key components in the original content, which can include applying style transfer, or changing facial expressions.
18
- *
19
- * Label this asset as 'app_generated' under these conditions:
20
- *
21
- * The following is true:
22
- *
23
- * - The app generates the asset in response to a user's request (including past requests), for example, the asset is not from an asset library.
24
- *
25
- * And any of these conditions are also true:
26
- *
27
- * - The AI creates entirely new content from scratch.
28
- * - The AI introduces new multimedia, details, or creative elements not originally present.
29
- * - The AI removes and replaces the asset's key components.
30
- * - The AI alters the asset's appearance, meaning, or context in a way that conveys a different message than the original.
31
- *
32
- * **None**
33
- *
34
- * 'none' indicates when the asset wasn't generated by the app as a part of any user's specific request, for example, a third-party
35
- * request, or when the asset wasn't significantly altered by AI.
36
- */
37
- declare type AiDisclosure = "app_generated" | "none";
38
-
39
- declare type AllOrNone<T> = T | Never<T>;
40
-
41
- /**
42
- * @public
43
- * {@link GetDataTableError} indicating custom error occurred in the app's implementation.
44
- * This can be used to indicate specific issues that are not covered by other error types.
45
- */
46
- declare type AppError = {
47
- /**
48
- * A custom error occurred in your app.
49
- *
50
- * Return this for application-specific errors that don't fit
51
- * the other categories. Include a descriptive message explaining
52
- * the error to the user.
53
- */
54
- status: "app_error";
55
- /**
56
- * Optional message explaining the error.
57
- */
58
- message?: string;
59
- };
60
-
61
- /**
62
- * @public
63
- * {@link InvocationContext} indicating a custom error occurred during data refresh.
64
- * Triggered when getDataTable returned 'app_error' status.
65
- * UI should display the error message and help users recover.
66
- */
67
- declare type AppErrorInvocationContext = {
68
- /**
69
- * A custom error occurred during data refresh.
70
- *
71
- * This occurs when `getDataTable` returned 'app_error' during a refresh attempt.
72
- * Your UI should display the error message and help users recover from the specific
73
- * issue.
74
- */
75
- reason: "app_error";
76
- /**
77
- * The data source reference that caused the error during refresh.
78
- */
79
- dataSourceRef?: DataSourceRef;
80
- /**
81
- * The error message to display to the user.
82
- */
83
- message?: string;
84
- };
85
-
86
- /**
87
- * @public
88
- * Cell containing a boolean value.
89
- *
90
- * @example Creating a boolean cell
91
- * ```ts
92
- * import type { BooleanDataTableCell } from '@canva/intents/data';
93
- *
94
- * const isActiveCell: BooleanDataTableCell = {
95
- * type: 'boolean',
96
- * value: true
97
- * };
98
- * ```
99
- *
100
- * @example Creating a boolean cell with false value
101
- * ```ts
102
- * import type { BooleanDataTableCell } from '@canva/intents/data';
103
- *
104
- * const isCompleteCell: BooleanDataTableCell = {
105
- * type: 'boolean',
106
- * value: false
107
- * };
108
- * ```
109
- *
110
- * @example Creating an empty boolean cell
111
- * ```ts
112
- * import type { BooleanDataTableCell } from '@canva/intents/data';
113
- *
114
- * const emptyBooleanCell: BooleanDataTableCell = {
115
- * type: 'boolean',
116
- * value: undefined
117
- * };
118
- * ```
119
- */
120
- declare type BooleanDataTableCell = {
121
- /**
122
- * Indicates this cell contains a boolean value.
123
- */
124
- type: "boolean";
125
- /**
126
- * Boolean value (true or false).
127
- *
128
- * Use `undefined` for an empty cell.
129
- */
130
- value: boolean | undefined;
131
- };
132
-
133
- /**
134
- * @public
135
- * Configuration for a table column.
136
- */
137
- declare type ColumnConfig = {
138
- /**
139
- * Name for the column, displayed as header text.
140
- *
141
- * If `undefined`, the column will have no header text.
142
- */
143
- name: string | undefined;
144
- /**
145
- * Expected data type for cells in this column.
146
- *
147
- * Use a specific `DataType` for columns with consistent types,
148
- * or `'variant'` for columns that may contain mixed types.
149
- */
150
- type: DataType | "variant";
151
- };
152
-
153
- declare namespace data {
154
- export {
155
- prepareDataConnector,
156
- DataConnectorIntent,
157
- GetDataTableRequest,
158
- RenderSelectionUiRequest,
159
- InvocationContext,
160
- GetDataTableResponse,
161
- GetDataTableCompleted,
162
- DataTableMetadata,
163
- GetDataTableError,
164
- UpdateDataRefResponse,
165
- DataSourceRef,
166
- DataTableLimit,
167
- DataType,
168
- DataTable,
169
- ColumnConfig,
170
- DataTableRow,
171
- DataTableCell,
172
- DateDataTableCell,
173
- StringDataTableCell,
174
- NumberDataTableCell,
175
- NumberCellMetadata,
176
- BooleanDataTableCell,
177
- MediaCollectionDataTableCell,
178
- DataTableImageUpload,
179
- DataTableVideoUpload,
180
- };
181
- }
182
- export { data };
183
-
184
- /**
185
- * @public
186
- * Main interface for implementing the Data Connector intent.
187
- *
188
- * Implementing the Data Connector intent enables apps to import external data into Canva.
189
- * This allows users to select, preview, and refresh data from external sources.
190
- */
191
- declare type DataConnectorIntent = {
192
- /**
193
- * Gets structured data from an external source.
194
- *
195
- * This action is called in two scenarios:
196
- *
197
- * - During data selection to preview data before import (when {@link RenderSelectionUiRequest.updateDataRef} is called).
198
- * - When refreshing previously imported data (when the user requests an update).
199
- *
200
- * @param request - Parameters for the data fetching operation.
201
- * @returns A promise resolving to either a successful result with data or an error.
202
- *
203
- * @example Getting data from an external source
204
- * ```ts
205
- * import type { GetDataTableRequest, GetDataTableResponse } from '@canva/intents/data';
206
- *
207
- * async function getDataTable(request: GetDataTableRequest): Promise<GetDataTableResponse> {
208
- * const { dataSourceRef, limit, signal } = request;
209
- *
210
- * // Check if the operation has been aborted.
211
- * if (signal.aborted) {
212
- * return { status: 'app_error', message: 'The data fetch operation was cancelled.' };
213
- * }
214
- *
215
- * // ... data fetching logic using dataSourceRef, limit, and signal ...
216
- *
217
- * // Placeholder for a successful result.
218
- * return {
219
- * status: 'completed',
220
- * dataTable: { rows: [{ cells: [{ type: 'string', value: 'Fetched data' }] }] }
221
- * };
222
- * }
223
- * ```
224
- */
225
- getDataTable: (request: GetDataTableRequest) => Promise<GetDataTableResponse>;
226
-
227
- /**
228
- * Renders a user interface for selecting and configuring data from your external sources.
229
- *
230
- * @param request - Configuration and callbacks for the data selection UI.
231
- *
232
- * @example Rendering a data selection UI
233
- * ```ts
234
- * import type { RenderSelectionUiRequest } from '@canva/intents/data';
235
- *
236
- * async function renderSelectionUi(request: RenderSelectionUiRequest): Promise<void> {
237
- * // UI rendering logic.
238
- * // Example: if user selects data 'ref123'.
239
- * const selectedRef = { source: 'ref123', title: 'My Selected Table' };
240
- * try {
241
- * const result = await request.updateDataRef(selectedRef);
242
- * if (result.status === 'completed') {
243
- * console.log('Selection valid and preview updated.');
244
- * } else {
245
- * console.error('Selection error:', result.status);
246
- * }
247
- * } catch (error) {
248
- * console.error('An unexpected error occurred during data ref update:', error);
249
- * }
250
- * }
251
- * ```
252
- */
253
- renderSelectionUi: (request: RenderSelectionUiRequest) => void;
254
- };
255
-
256
- /**
257
- * @public
258
- * {@link InvocationContext} indicating initial data selection flow or edit of existing data.
259
- */
260
- declare type DataSelectionInvocationContext = {
261
- /**
262
- * Initial data selection or editing existing data.
263
- *
264
- * This is the standard flow when:
265
- *
266
- * - A user is selecting data for the first time
267
- * - A user is editing a previous selection
268
- *
269
- * If `dataSourceRef` is provided, this indicates an edit flow, and you should
270
- * pre-populate your UI with this selection.
271
- */
272
- reason: "data_selection";
273
- /**
274
- * If dataSourceRef is provided, this is an edit of existing data flow and UI should be pre-populated.
275
- */
276
- dataSourceRef?: DataSourceRef;
277
- };
278
-
279
- /**
280
- * @public
281
- * Reference to an external data source that can be used to fetch data.
282
- * Created by Data Connector apps and stored by Canva for data refresh operations.
283
- *
284
- * You create this object in your data selection UI and pass it to the
285
- * `updateDataRef` callback. Canva stores this reference and uses it for
286
- * future data refresh operations.
287
- *
288
- * Maximum size: 5KB
289
- *
290
- * @example Defining how to locate external data
291
- * ```ts
292
- * const dataSourceRef: DataSourceRef = {
293
- * source: JSON.stringify({
294
- * reportId: "monthly_sales_001",
295
- * filters: { year: 2023, region: "NA" }
296
- * }),
297
- * title: "Monthly Sales Report (NA, 2023)"
298
- * };
299
- * ```
300
- */
301
- declare type DataSourceRef = {
302
- /**
303
- * Information needed to identify and retrieve data from your source.
304
- *
305
- * This string should contain all the information your app needs to
306
- * fetch the exact data selection later. Typically, this is a serialized
307
- * object with query parameters, identifiers, or filters.
308
- *
309
- * You are responsible for encoding and decoding this value appropriately.
310
- *
311
- * Maximum size: 5KB
312
- */
313
- source: string;
314
- /**
315
- * A human-readable description of the data reference.
316
- *
317
- * This title may be displayed to users in the Canva interface to help
318
- * them identify the data source.
319
- *
320
- * Maximum length: 255 characters
321
- */
322
- title?: string;
323
- };
324
-
325
- /**
326
- * @public
327
- * Structured tabular data for import into Canva.
328
- *
329
- * This format allows you to provide typed data with proper formatting
330
- * to ensure it displays correctly in Canva designs.
331
- *
332
- * @example Creating a data table
333
- * ```ts
334
- * import type { ColumnConfig, DataTableCell, DataTable, DataTableRow } from '@canva/intents/data';
335
- *
336
- * const myTable: DataTable = {
337
- * columnConfigs: [
338
- * { name: 'Name', type: 'string' },
339
- * { name: 'Age', type: 'number' },
340
- * { name: 'Subscribed', type: 'boolean' },
341
- * { name: 'Join Date', type: 'date' }
342
- * ],
343
- * rows: [
344
- * {
345
- * cells: [
346
- * { type: 'string', value: 'Alice' },
347
- * { type: 'number', value: 30 },
348
- * { type: 'boolean', value: true },
349
- * { type: 'date', value: Math.floor(new Date('2023-01-15').getTime() / 1000) }
350
- * ]
351
- * },
352
- * {
353
- * cells: [
354
- * { type: 'string', value: 'Bob' },
355
- * { type: 'number', value: 24 },
356
- * { type: 'boolean', value: false },
357
- * { type: 'date', value: Math.floor(new Date('2022-07-20').getTime() / 1000) }
358
- * ]
359
- * }
360
- * ]
361
- * };
362
- * ```
363
- */
364
- declare type DataTable = {
365
- /**
366
- * Column definitions with names and data types.
367
- *
368
- * These help Canva interpret and display your data correctly.
369
- */
370
- columnConfigs?: ColumnConfig[];
371
- /**
372
- * The data rows containing the actual values.
373
- *
374
- * Each row contains an array of cells with typed data values.
375
- */
376
- rows: DataTableRow[];
377
- };
378
-
379
- /**
380
- * @public
381
- * Generic type for table cells that resolves to a specific cell type.
382
- */
383
- declare type DataTableCell<T extends DataType = DataType> = {
384
- date: DateDataTableCell;
385
- string: StringDataTableCell;
386
- number: NumberDataTableCell;
387
- boolean: BooleanDataTableCell;
388
- media: MediaCollectionDataTableCell;
389
- }[T];
390
-
391
- /**
392
- * @public
393
- * Options for uploading an image asset to the user's private media library.
394
- */
395
- declare type DataTableImageUpload = Omit<
396
- ImageUploadOptions,
397
- "type" | "parentRef"
398
- > & {
399
- /**
400
- * Indicates this value contains options for image uploading.
401
- */
402
- type: "image_upload";
403
- };
404
-
405
- /**
406
- * @public
407
- * Maximum dimensions for imported data tables.
408
- */
409
- declare type DataTableLimit = {
410
- /**
411
- * The maximum number of rows allowed.
412
- *
413
- * Your app should ensure data does not exceed this limit.
414
- */
415
- row: number;
416
- /**
417
- * The maximum number of columns allowed.
418
- *
419
- * Your app should ensure data does not exceed this limit.
420
- */
421
- column: number;
422
- };
423
-
424
- /**
425
- * @public
426
- * Metadata providing additional context about the imported data.
427
- */
428
- declare type DataTableMetadata = {
429
- /**
430
- * A human-readable description of the dataset.
431
- *
432
- * This description helps users understand what data they are importing.
433
- */
434
- description?: string;
435
- /**
436
- * Information about the data provider or source.
437
- */
438
- providerInfo?: {
439
- /**
440
- * Name of the data provider.
441
- */
442
- name: string;
443
- /**
444
- * URL to the provider's website or related resource.
445
- */
446
- url?: string;
447
- };
448
- };
449
-
450
- /**
451
- * @public
452
- * A row in the data table.
453
- *
454
- * @example Creating a single row of data cells
455
- * ```ts
456
- * import type { DataTableCell, DataTableRow } from '@canva/intents/data';
457
- *
458
- * const row: DataTableRow = {
459
- * cells: [
460
- * { type: 'string', value: 'Product Alpha' },
461
- * { type: 'number', value: 199.99 },
462
- * { type: 'boolean', value: true }
463
- * ]
464
- * };
465
- * ```
466
- */
467
- declare type DataTableRow = {
468
- /**
469
- * Array of cells containing the data values.
470
- *
471
- * Each cell must have a type that matches the corresponding column definition (if provided).
472
- */
473
- cells: DataTableCell<DataType>[];
474
- };
475
-
476
- /**
477
- * @public
478
- * Options for uploading a video asset to the user's private media library.
479
- */
480
- declare type DataTableVideoUpload = Omit<
481
- VideoUploadOptions,
482
- "type" | "parentRef"
483
- > & {
484
- /**
485
- * Indicates this value contains options for video uploading.
486
- */
487
- type: "video_upload";
488
- };
489
-
490
- /**
491
- * @public
492
- * Data types supported for table cells.
493
- */
494
- declare type DataType = "string" | "number" | "date" | "boolean" | "media";
495
-
496
- /**
497
- * @public
498
- * Cell containing a date value.
499
- *
500
- * @example Creating a date cell
501
- * ```ts
502
- * import type { DateDataTableCell } from '@canva/intents/data';
503
- *
504
- * const todayCell: DateDataTableCell = {
505
- * type: 'date',
506
- * value: Math.floor(Date.now() / 1000) // Unix timestamp in seconds
507
- * };
508
- *
509
- * const emptyDateCell: DateDataTableCell = {
510
- * type: 'date',
511
- * value: undefined
512
- * };
513
- * ```
514
- */
515
- declare type DateDataTableCell = {
516
- /**
517
- * Indicates this cell contains a date value.
518
- */
519
- type: "date";
520
- /**
521
- * Unix timestamp in seconds representing the date.
522
- *
523
- * Use `undefined` for an empty cell.
524
- */
525
- value: number | undefined;
526
- };
527
-
528
- declare namespace design {
529
- export { prepareDesignEditor, DesignEditorIntent };
530
- }
531
- export { design };
532
-
533
- /**
534
- * @public
535
- *
536
- * Main interface for implementing the DesignEditor intent.
537
- *
538
- * Implementing the DesignEditor Intent enables apps to assist users in editing designs,
539
- * by presenting interactive and creative tooling alongside the Canva design surface.
540
- */
541
- declare type DesignEditorIntent = {
542
- /**
543
- * Renders the UI containing the app’s functionality.
544
- *
545
- * @example
546
- * ```tsx
547
- * function render() {
548
- * // render your UI using your preferred framework
549
- * }
550
- * ```
551
- */
552
- render: () => void;
553
- };
554
-
555
- /**
556
- * @public
557
- * A set of dimensions.
558
- */
559
- declare type Dimensions = {
560
- /**
561
- * A width, in pixels.
562
- */
563
- width: number;
564
- /**
565
- * A height, in pixels.
566
- */
567
- height: number;
568
- };
569
-
570
- /**
571
- * @public
572
- * Successful result from `getDataTable` action.
573
- */
574
- declare type GetDataTableCompleted = {
575
- /**
576
- * Indicates the operation completed successfully
577
- */
578
- status: "completed";
579
- /**
580
- * The fetched data formatted as a data table.
581
- */
582
- dataTable: DataTable;
583
- /**
584
- * Optional metadata providing additional context about the data.
585
- */
586
- metadata?: DataTableMetadata;
587
- };
588
-
589
- /**
590
- * @public
591
- * Error results that can be returned from `getDataTable` method.
592
- */
593
- declare type GetDataTableError =
594
- | OutdatedSourceRefError
595
- | RemoteRequestFailedError
596
- | AppError;
597
-
598
- /**
599
- * @public
600
- * Parameters for the getDataTable action.
601
- */
602
- declare type GetDataTableRequest = {
603
- /**
604
- * Reference to the data source to fetch.
605
- *
606
- * This contains the information needed to identify and retrieve the specific data
607
- * that was previously selected by the user.
608
- *
609
- * Use this to query your external data service.
610
- */
611
- dataSourceRef: DataSourceRef;
612
- /**
613
- * Maximum row and column limits for the imported data.
614
- *
615
- * Your app must ensure the returned data does not exceed these limits.
616
- *
617
- * If the requested data would exceed these limits, either:
618
- *
619
- * - Truncate the data to fit within limits, or
620
- * - Return a 'data_table_limit_exceeded' error
621
- */
622
- limit: DataTableLimit;
623
- /**
624
- * Standard DOM AbortSignal for cancellation support.
625
- *
626
- * Your app should monitor this signal and abort any ongoing operations if it becomes aborted.
627
- */
628
- signal: AbortSignal;
629
- };
630
-
631
- /**
632
- * @public
633
- * Result returned from the `getDataTable` action.
634
- */
635
- declare type GetDataTableResponse = GetDataTableCompleted | GetDataTableError;
636
-
637
- /**
638
- * @public
639
- * The MIME type of an image file that's supported by Canva's backend.
640
- */
641
- declare type ImageMimeType =
642
- | "image/jpeg"
643
- | "image/heic"
644
- | "image/png"
645
- | "image/svg+xml"
646
- | "image/webp"
647
- | "image/tiff";
648
-
649
- /**
650
- * @public
651
- * A unique identifier that points to an image asset in Canva's backend.
652
- */
653
- declare type ImageRef = string & {
654
- __imageRef: never;
655
- };
656
-
657
- /**
658
- * @public
659
- * Options for uploading an image asset to the user's private media library.
660
- */
661
- declare type ImageUploadOptions = {
662
- /**
663
- * The type of asset.
664
- */
665
- type: "image";
666
- /**
667
- * The ref of the original asset from which this new asset was derived.
668
- *
669
- * @remarks
670
- * For example, if an app applies an effect to an image, `parentRef` should contain the ref of the original image.
671
- */
672
- parentRef?: ImageRef;
673
- /**
674
- * The URL of the image file to upload.
675
- * This can be an external URL or a data URL.
676
- *
677
- * @remarks
678
- * Requirements for external URLs:
679
- *
680
- * - Must use HTTPS
681
- * - Must return a `200` status code
682
- * - `Content-Type` must match the file's MIME type
683
- * - Must be publicly accessible (i.e. not a localhost URL)
684
- * - Must not redirect
685
- * - Must not contain an IP address
686
- * - Maximum length: 4096 characters
687
- * - Must not contain whitespace
688
- * - Must not contain these characters: `>`, `<`, `{`, `}`, `^`, backticks
689
- * - Maximum file size: 50MB
690
- *
691
- * Requirements for data URLs:
692
- *
693
- * - Must include `;base64` for base64-encoded data
694
- * - Maximum size: 10MB (10 × 1024 × 1024 characters)
695
- *
696
- * Requirements for SVGs:
697
- *
698
- * - Disallowed elements:
699
- * - `a`
700
- * - `altglyph`
701
- * - `altglyphdef`
702
- * - `altglyphitem`
703
- * - `animate`
704
- * - `animatemotion`
705
- * - `animatetransform`
706
- * - `cursor`
707
- * - `discard`
708
- * - `font`
709
- * - `font-face`
710
- * - `font-face-format`
711
- * - `font-face-name`
712
- * - `font-face-src`
713
- * - `font-face-uri`
714
- * - `foreignobject`
715
- * - `glyph`
716
- * - `glyphref`
717
- * - `missing-glyph`
718
- * - `mpath`
719
- * - `script`
720
- * - `set`
721
- * - `switch`
722
- * - `tref`
723
- * - Disallowed attributes:
724
- * - `crossorigin`
725
- * - `lang`
726
- * - `media`
727
- * - `onload`
728
- * - `ping`
729
- * - `referrerpolicy`
730
- * - `rel`
731
- * - `rendering-intent`
732
- * - `requiredextensions`
733
- * - `requiredfeatures`
734
- * - `systemlanguage`
735
- * - `tabindex`
736
- * - `transform-origin`
737
- * - `unicode`
738
- * - `vector-effect`
739
- * - The `href` attribute of an `image` element only supports data URLs for PNG and JPEG images.
740
- * - The URL in the `href` attribute must not point to a location outside of the SVG.
741
- * - The `style` attribute must not use the `mix-blend-mode` property.
742
- */
743
- url: string;
744
- /**
745
- * The MIME type of the image file.
746
- */
747
- mimeType: ImageMimeType;
748
- /**
749
- * The URL of a thumbnail image to display while the image is queued for upload.
750
- * This can be an external URL or a data URL.
751
- *
752
- * @remarks
753
- * Requirements for external URLs:
754
- *
755
- * - Must use HTTPS
756
- * - Must support [Cross-Origin Resource Sharing](https://www.canva.dev/docs/apps/cross-origin-resource-sharing/)
757
- * - Must be a PNG, JPEG, or SVG file
758
- * - Maximum length: 4096 characters
759
- *
760
- * Requirements for data URLs:
761
- *
762
- * - Must include `;base64` for base64-encoded data
763
- * - Maximum size: 10MB (10 × 1024 × 1024 characters)
764
- */
765
- thumbnailUrl: string;
766
- /**
767
- * A disclosure identifying if the app generated this image using AI
768
- *
769
- * @remarks
770
- * Helps users make informed decisions about the content they interact with.
771
- * See {@link AiDisclosure} for the full definition.
772
- *
773
- * **App Generated**
774
- *
775
- * 'app_generated' indicates when the app creates or significantly alters an asset using AI. Includes when
776
- * the app requests a third-party service to take similar action on an image using AI.
777
- *
778
- * Required for the following cases (this list is not exhaustive):
779
- * | Case | Reason |
780
- * | -- | -- |
781
- * | AI generates a new image from scratch | Creates new creative content |
782
- * | AI changes the style of the image e.g. makes it cartoon | Significantly alters the style |
783
- * | AI removes an object and replaces it with new content | Creates new creative content |
784
- * | AI changes the facial expression of a person in an image | Can alter content's original meaning |
785
- * | AI composites multiple images together | Significantly alters context |
786
- * | AI expands an image by generating new content to fill the edges | Creates new creative content |
787
- * | AI replaces background by generating new content | Creates new creative content |
788
- *
789
- * **None**
790
- *
791
- * 'none' indicates when the app doesn't create or significantly alter an asset using AI, or as a part of a request
792
- * to third-party hosted content.
793
- *
794
- * Required for the following cases (this list is not exhaustive):
795
- * | Case | Reason |
796
- * | -- | -- |
797
- * | Asset comes from an asset library | Didn't generate the asset itself |
798
- * | AI corrects red eyes | A minor correction |
799
- * | AI removes background without replacement | Doesn't change original meaning by itself |
800
- * | AI changes the color of an object in an image | Doesn't change original meaning by itself |
801
- * | AI detects image defects and suggests manual fixes | Didn't change the asset itself |
802
- * | AI adjusts brightness and contrast on an image | Doesn't change original meaning by itself |
803
- * | AI upscales an image | Doesn't change original meaning by itself |
804
- */
805
- aiDisclosure: AiDisclosure;
806
- } & AllOrNone<Dimensions>;
807
-
808
- /**
809
- * @public
810
- * Information explaining why the data selection UI was launched.
811
- */
812
- declare type InvocationContext =
813
- | DataSelectionInvocationContext
814
- | OutdatedSourceRefInvocationContext
815
- | AppErrorInvocationContext;
816
-
817
- /**
818
- * @public
819
- * Cell containing a media collection (images) value.
820
- *
821
- * @example Creating a media cell with an image
822
- * ```ts
823
- * import type { MediaCollectionDataTableCell } from '@canva/intents/data';
824
- *
825
- * const mediaCell: MediaCollectionDataTableCell = {
826
- * type: 'media',
827
- * value: [{
828
- * type: 'image_upload',
829
- * url: 'https://www.canva.dev/example-assets/image-import/image.jpg',
830
- * mimeType: 'image/jpeg',
831
- * thumbnailUrl: 'https://www.canva.dev/example-assets/image-import/thumbnail.jpg',
832
- * aiDisclosure: 'none'
833
- * }]
834
- * };
835
- * ```
836
- *
837
- * @example Creating an empty media cell
838
- * ```ts
839
- * import type { MediaCollectionDataTableCell } from '@canva/intents/data';
840
- *
841
- * const emptyMediaCell: MediaCollectionDataTableCell = {
842
- * type: 'media',
843
- * value: []
844
- * };
845
- * ```
846
- */
847
- declare type MediaCollectionDataTableCell = {
848
- /**
849
- * Indicates this cell contains a media collection.
850
- */
851
- type: "media";
852
- /**
853
- * Media collection values.
854
- *
855
- * Use empty array for an empty cell.
856
- */
857
- value: (DataTableImageUpload | DataTableVideoUpload)[];
858
- };
859
-
860
- declare type Never<T> = {
861
- [key in keyof T]?: never;
862
- };
863
-
864
- /**
865
- * @public
866
- * Formatting metadata for number cells.
867
- *
868
- * @example Formatting as currency
869
- * ```ts
870
- * import type { NumberDataTableCell } from '@canva/intents/data';
871
- *
872
- * const currencyCell: NumberDataTableCell = {
873
- * type: 'number',
874
- * value: 1234.57,
875
- * metadata: { formatting: '[$$]#,##0.00' }
876
- * };
877
- * ```
878
- *
879
- * @example Formatting as a percentage
880
- * ```ts
881
- * import type { NumberDataTableCell } from '@canva/intents/data';
882
- *
883
- * const percentCell: NumberDataTableCell = {
884
- * type: 'number',
885
- * value: 0.1234,
886
- * metadata: { formatting: '0.00%' }
887
- * };
888
- * ```
889
- *
890
- * @example Applying a thousands separator
891
- * ```ts
892
- * import type { NumberDataTableCell } from '@canva/intents/data';
893
- *
894
- * const largeNumberCell: NumberDataTableCell = {
895
- * type: 'number',
896
- * value: 1234567.89234,
897
- * metadata: { formatting: '#,##0.00' }
898
- * };
899
- * ```
900
- */
901
- declare type NumberCellMetadata = {
902
- /**
903
- * Formatting pattern using Office Open XML Format.
904
- *
905
- * These patterns control how numbers are displayed to users,
906
- * including currency symbols, decimal places, and separators.
907
- */
908
- formatting?: string;
909
- };
910
-
911
- /**
912
- * @public
913
- * Cell containing a numeric value.
914
- *
915
- * @example Creating a number cell
916
- * ```ts
917
- * import type { NumberCellMetadata, NumberDataTableCell } from '@canva/intents/data';
918
- *
919
- * const priceCell: NumberDataTableCell = {
920
- * type: 'number',
921
- * value: 29.99,
922
- * metadata: { formatting: '[$$]#,##0.00' }
923
- * };
924
- *
925
- * const quantityCell: NumberDataTableCell = {
926
- * type: 'number',
927
- * value: 150
928
- * };
929
- *
930
- * const emptyNumberCell: NumberDataTableCell = {
931
- * type: 'number',
932
- * value: undefined
933
- * };
934
- * ```
935
- */
936
- declare type NumberDataTableCell = {
937
- /**
938
- * Indicates this cell contains a number value.
939
- */
940
- type: "number";
941
- /**
942
- * Numeric value within safe integer range.
943
- *
944
- * Valid range: `Number.MIN_SAFE_INTEGER` to `Number.MAX_SAFE_INTEGER`
945
- *
946
- * Invalid values:
947
- *
948
- * - Infinity or -Infinity
949
- * - NaN
950
- * - Negative zero (-0)
951
- * - Denormalized numbers
952
- *
953
- * Use `undefined` for an empty cell.
954
- */
955
- value: number | undefined;
956
- /**
957
- * Optional formatting information for displaying the number.
958
- *
959
- * @example Applying display formatting to a number
960
- * ```ts
961
- * import type { NumberCellMetadata } from '@canva/intents/data';
962
- *
963
- * const currencyFormatting: NumberCellMetadata = { formatting: '[$USD]#,##0.00' };
964
- * const percentageFormatting: NumberCellMetadata = { formatting: '0.00%' };
965
- * ```
966
- */
967
- metadata?: NumberCellMetadata;
968
- };
969
-
970
- /**
971
- * @public
972
- * {@link GetDataTableError} indicating the data source reference is no longer valid.
973
- * This will trigger a re-selection flow for the user.
974
- */
975
- declare type OutdatedSourceRefError = {
976
- /**
977
- * The data source reference is no longer valid.
978
- *
979
- * Return this error when the DataSourceRef cannot be used to retrieve data,
980
- * for example:
981
- *
982
- * - The referenced dataset has been deleted
983
- * - Access permissions have changed
984
- * - The structure of the data has fundamentally changed
985
- *
986
- * This will trigger a re-selection flow, allowing the user to choose a new
987
- * data source.
988
- */
989
- status: "outdated_source_ref";
990
- };
991
-
992
- /**
993
- * @public
994
- * {@link InvocationContext} indicating an error occurred because the previously selected data source reference is no longer valid.
995
- * Triggered when getDataTable returned 'outdated_source_ref' during data refresh.
996
- * UI should guide the user to reselect or reconfigure their data.
997
- */
998
- declare type OutdatedSourceRefInvocationContext = {
999
- /**
1000
- * Previously selected data source reference is no longer valid.
1001
- *
1002
- * This occurs when `getDataTable` returned 'outdated_source_ref' during a
1003
- * refresh attempt. Your UI should guide the user to select a new data source
1004
- * or update their selection.
1005
- *
1006
- * The outdated reference is provided to help you suggest an appropriate replacement.
1007
- */
1008
- reason: "outdated_source_ref";
1009
- /**
1010
- * The outdated data source reference that caused the error during refresh.
1011
- */
1012
- dataSourceRef?: DataSourceRef;
1013
- };
1014
-
1015
- /**
1016
- * @public
1017
- *
1018
- * Prepares a {@link DataConnectorIntent|DataConnector Intent}.
1019
- *
1020
- * @example
1021
- * ```tsx
1022
- * import { prepareDataConnector } from "@canva/intents/data";
1023
- *
1024
- * prepareDataConnector({
1025
- * getDataTable: async (params) => {
1026
- * // Implement the logic to fetch the data table
1027
- * },
1028
- * renderSelectionUi: (params) => {
1029
- * // Implement the UI for the data table selection
1030
- * },
1031
- * });
1032
- * ```
1033
- */
1034
- declare const prepareDataConnector: (
1035
- implementation: DataConnectorIntent,
1036
- ) => void;
1037
-
1038
- /**
1039
- * @public
1040
- *
1041
- * Prepares a {@link DesignEditorIntent|DesignEditor Intent}.
1042
- *
1043
- * @example
1044
- * ```tsx
1045
- * import { prepareDesignEditor } from '@canva/intents/design';
1046
- *
1047
- * prepareDesignEditor({
1048
- * render: async () => {
1049
- * // TODO: Implement the logic to render your app's UI
1050
- * },
1051
- * });
1052
- * ```
1053
- */
1054
- declare const prepareDesignEditor: (implementation: DesignEditorIntent) => void;
1055
-
1056
- /**
1057
- * @public
1058
- * {@link GetDataTableError} indicating failure to fetch data from the external source.
1059
- * Typically due to network issues or API failures.
1060
- */
1061
- declare type RemoteRequestFailedError = {
1062
- /**
1063
- * Failed to fetch data from the external source.
1064
- *
1065
- * Return this error for network issues, API failures, or other
1066
- * connectivity problems that prevent data retrieval.
1067
- */
1068
- status: "remote_request_failed";
1069
- };
1070
-
1071
- /**
1072
- * @public
1073
- * Parameters for rendering the data selection UI.
1074
- */
1075
- declare type RenderSelectionUiRequest = {
1076
- /**
1077
- * Context information about why the data selection UI is being launched.
1078
- *
1079
- * Use this to adapt your UI for different scenarios:
1080
- *
1081
- * - 'data_selection': Initial data selection or editing existing data
1082
- * - 'outdated_source_ref': Previous reference is no longer valid, guide user to reselect
1083
- * - 'app_error': Custom error occurred, show error message and recovery options
1084
- *
1085
- * When `dataSourceRef` is provided, pre-populate your UI with this selection.
1086
- */
1087
- invocationContext: InvocationContext;
1088
- /**
1089
- * Maximum allowed rows and columns for the imported data.
1090
- *
1091
- * Your UI should inform users of these constraints and prevent or warn about
1092
- * selections that would exceed them. This helps users understand why certain
1093
- * data sets might not be available for selection.
1094
- */
1095
- limit: DataTableLimit;
1096
- /**
1097
- * Callback to preview selected data before finalizing import.
1098
- *
1099
- * Call this function when the user selects data to:
1100
- *
1101
- * 1. Show a preview of the selected data to the user
1102
- * 2. Validate that the selection meets system requirements
1103
- *
1104
- * Calling this function will trigger your `getDataTable` implementation.
1105
- * Wait for the promise to resolve to determine if the selection is valid.
1106
- *
1107
- * @param dataSourceRef - Reference object identifying the selected data
1108
- * @returns Promise resolving to success or an error result
1109
- * @throws Will throw CanvaError('bad_request') if
1110
- * 1. {@link DataSourceRef.source} exceeds 5kb.
1111
- * 2. {@link DataSourceRef.title} exceeds 255 characters.
1112
- * 3. {@link GetDataTableCompleted.dataTable} exceeds {@link DataTableLimit} or contains invalid data.
1113
- */
1114
- updateDataRef: (
1115
- dataSourceRef: DataSourceRef,
1116
- ) => Promise<UpdateDataRefResponse>;
1117
- };
1118
-
1119
- /**
1120
- * @public
1121
- * Cell containing a text value.
1122
- *
1123
- * @example Creating a string cell
1124
- * ```ts
1125
- * import type { StringDataTableCell } from '@canva/intents/data';
1126
- *
1127
- * const nameCell: StringDataTableCell = {
1128
- * type: 'string',
1129
- * value: 'John Doe'
1130
- * };
1131
- *
1132
- * const emptyStringCell: StringDataTableCell = {
1133
- * type: 'string',
1134
- * value: undefined
1135
- * };
1136
- * ```
1137
- */
1138
- declare type StringDataTableCell = {
1139
- /**
1140
- * Indicates this cell contains a string value.
1141
- */
1142
- type: "string";
1143
- /**
1144
- * Text content of the cell.
1145
- *
1146
- * Maximum length: 10,000 characters
1147
- *
1148
- * Use `undefined` for an empty cell.
1149
- */
1150
- value: string | undefined;
1151
- };
1152
-
1153
- /**
1154
- * @public
1155
- * Successful result from the {@link RenderSelectionUiRequest.updateDataRef} callback.
1156
- */
1157
- declare type UpdateDataRefCompleted = {
1158
- /**
1159
- * The data selection was successful and can be previewed.
1160
- */
1161
- status: "completed";
1162
- };
1163
-
1164
- /**
1165
- * @public
1166
- * Result returned from the {@link RenderSelectionUiRequest.updateDataRef} callback.
1167
- * Indicates whether {@link DataSourceRef} update succeeded or failed.
1168
- */
1169
- declare type UpdateDataRefResponse = UpdateDataRefCompleted | GetDataTableError;
1170
-
1171
- /**
1172
- * @public
1173
- * The MIME type of a video file that's supported by Canva's backend.
1174
- *
1175
- * @remarks
1176
- * - GIFs are treated as videos, not images.
1177
- * - `"application/json"` is only used for Lottie files.
1178
- */
1179
- declare type VideoMimeType =
1180
- | "video/avi"
1181
- | "video/x-msvideo"
1182
- | "image/gif"
1183
- | "video/x-m4v"
1184
- | "video/x-matroska"
1185
- | "video/quicktime"
1186
- | "video/mp4"
1187
- | "video/mpeg"
1188
- | "video/webm"
1189
- | "application/json";
1190
-
1191
- /**
1192
- * @public
1193
- * A unique identifier that points to a video asset in Canva's backend.
1194
- */
1195
- declare type VideoRef = string & {
1196
- __videoRef: never;
1197
- };
1198
-
1199
- /**
1200
- * @public
1201
- * Options for uploading a video asset to the user's private media library.
1202
- */
1203
- declare type VideoUploadOptions = {
1204
- /**
1205
- * The type of asset.
1206
- */
1207
- type: "video";
1208
- /**
1209
- * The ref of the original asset from which this new asset was derived.
1210
- *
1211
- * @remarks
1212
- * For example, if an app applies an effect to a video, `parentRef` should contain the ref of the original video.
1213
- */
1214
- parentRef?: VideoRef;
1215
- /**
1216
- * The URL of the video file to upload.
1217
- *
1218
- * @remarks
1219
- * Requirements:
1220
- *
1221
- * - Must use HTTPS
1222
- * - Must return a `200` status code
1223
- * - `Content-Type` must match the file's MIME type
1224
- * - Must be publicly accessible (i.e. not a localhost URL)
1225
- * - Must not redirect
1226
- * - Must not contain an IP address
1227
- * - Maximum length: 4096 characters
1228
- * - Must not contain whitespace
1229
- * - Must not contain these characters: `>`, `<`, `{`, `}`, `^`, backticks
1230
- * - Maximum file size: 100MB
1231
- */
1232
- url: string;
1233
- /**
1234
- * The MIME type of the video file.
1235
- */
1236
- mimeType: VideoMimeType;
1237
- /**
1238
- * The URL of a thumbnail video to display while the video is queued for upload.
1239
- *
1240
- * @remarks
1241
- * Requirements:
1242
- *
1243
- * - Must use HTTPS
1244
- * - Must support [Cross-Origin Resource Sharing](https://www.canva.dev/docs/apps/cross-origin-resource-sharing/)
1245
- * - Maximum length: 4096 characters
1246
- * - The dimensions of the thumbnail video must match the video's aspect ratio to prevent the thumbnail from appearing squashed or stretched
1247
- * - Must not be an AVI file. Although our APIs support uploading AVI videos, Canva can't preview them because of native support of browsers
1248
- */
1249
- thumbnailVideoUrl?: string;
1250
- /**
1251
- * The URL of a thumbnail image to use as a fallback if `thumbnailVideoUrl` isn't provided.
1252
- * This can be an external URL or a data URL.
1253
- *
1254
- * @remarks
1255
- * Requirements for external URLs:
1256
- *
1257
- * - Must use HTTPS
1258
- * - Must support [Cross-Origin Resource Sharing](https://www.canva.dev/docs/apps/cross-origin-resource-sharing/)
1259
- * - Must be a PNG, JPEG, or SVG file
1260
- * - Maximum length: 4096 characters
1261
- *
1262
- * Requirements for data URLs:
1263
- *
1264
- * - Must include `;base64` for base64-encoded data
1265
- * - Maximum size: 10MB (10 × 1024 × 1024 characters)
1266
- * - The dimensions of the thumbnail must match the video's aspect ratio to prevent the thumbnail from appearing squashed or stretched
1267
- */
1268
- thumbnailImageUrl: string;
1269
- /**
1270
- * A disclosure identifying if the app generated this video using AI.
1271
- *
1272
- * @remarks
1273
- * Helps users make informed decisions about the content they interact with.
1274
- * See {@link AiDisclosure} for the full definition.
1275
- *
1276
- * **App Generated**
1277
- *
1278
- * 'app_generated' indicates when the app creates or significantly alters an asset using AI. Includes when
1279
- * the app requests a third-party service to take similar action on a video using AI.
1280
- *
1281
- * Required for the following cases (this list is not exhaustive):
1282
- * | Case | Reason |
1283
- * | -- | -- |
1284
- * | AI generates a new video from scratch | Creates new creative content |
1285
- * | AI changes the style of the video e.g. makes it cartoon | Significantly alters the style |
1286
- * | AI adds subtitles that rely on subjective interpretation | Creates new creative content |
1287
- * | AI expands a video by generating new content to fill the edges | Creates new creative content |
1288
- * | AI animates an image | Creates new creative content |
1289
- * | AI fixes defects e.g. blur in a video by generating details | Creates new creative content |
1290
- * | AI generates a talking head presenter | Creates new creative content |
1291
- *
1292
- * **None**
1293
- *
1294
- * 'none' indicates when the app doesn't create or significantly alter an asset using AI, or as a part of
1295
- * a request to third-party hosted content.
1296
- *
1297
- * Required for the following cases (this list is not exhaustive):
1298
- * | Case | Reason |
1299
- * | -- | -- |
1300
- * | Asset comes from an asset library | Didn't generate the asset itself |
1301
- * | AI corrects red eyes | A minor correction |
1302
- * | AI adjusts brightness and contrast on a video | Doesn't change original meaning by itself |
1303
- * | AI creates a slow motion effect in a video | Doesn't change original meaning by itself |
1304
- * | AI adds AI word-by-word transcribed subtitles to a video | Doesn't change original meaning by itself |
1305
- */
1306
- aiDisclosure: AiDisclosure;
1307
- } & AllOrNone<Dimensions>;
1308
-
1309
- export {};
1
+ export * from "./beta";